Commit 6b9716c1 authored by lucha's avatar lucha
Browse files

[auto] plugin: event-list 0.8.3

parent 5c860df1
<?php
if(!defined('WPINC')) {
if(!defined('WP_ADMIN')) {
exit;
}
require_once( EL_PATH.'includes/options.php' );
require_once(EL_PATH.'includes/options.php');
require_once(EL_PATH.'includes/events_post_type.php');
// This class handles all available admin pages
class EL_Admin {
private static $instance;
private $options;
private $events_post_type;
private $show_upgr_message = false;
public static function &get_instance() {
// Create class instance if required
......@@ -21,56 +24,99 @@ class EL_Admin {
private function __construct() {
$this->options = &EL_Options::get_instance();
$this->events_post_type = &EL_Events_Post_Type::get_instance();
// Register actions
add_action('admin_init', array(&$this, 'sync_post_categories'), 11);
add_action('init', array(&$this, 'plugin_upgrade_check'), 5);
add_action('admin_notices', array(&$this, 'show_plugin_upgrade_message'));
add_action('current_screen', array(&$this, 'register_events_post_type_mods'));
add_action('admin_head', array(&$this, 'add_dashboard_styles'));
add_action('admin_menu', array(&$this, 'register_pages'));
add_action('plugins_loaded', array(&$this, 'db_upgrade_check'));
add_filter('dashboard_glance_items', array($this, 'add_events_to_glance')
);;;
}
public function sync_post_categories() {
// Register syncing actions if enabled.
// Has to be done after Options::register_options, so that $this->options->get returns the correct value.
if(1 == $this->options->get('el_sync_cats')) {
add_action('create_category', array(&$this, 'action_add_category'));
add_action('edit_category', array(&$this, 'action_edit_category'));
add_action('delete_category', array(&$this, 'action_delete_category'));
add_filter('dashboard_glance_items', array(&$this, 'add_events_to_glance'));
add_filter('removable_query_args', array(&$this, 'remove_upgrade_args'));
}
public function plugin_upgrade_check() {
// Upgrade check
$file_data = get_file_data(EL_PATH.'event-list.php', array('version'=>'Version'));
$last_upgr_version = get_option('el_last_upgr_version', '');
if($file_data['version'] != $last_upgr_version || isset($_GET['resume-el-upgr'])) {
// load upgrade class
require_once(EL_PATH.'admin/includes/upgrade.php');
EL_Upgrade::get_instance()->upgrade();
}
}
/**
* Add and register all admin pages in the admin menu
*/
public function register_pages() {
// Main Menu page
add_menu_page(__('Event List','event-list'), __('Event List','event-list'), 'edit_posts', 'el_admin_main', array(&$this, 'show_main_page'), 'dashicons-calendar-alt', '22.2');
public function show_plugin_upgrade_message() {
if($this->show_upgr_message) {
// load upgrade class
require_once(EL_PATH.'admin/includes/upgrade.php');
$logfile = str_replace(EL_PATH, EL_URL, EL_Upgrade::get_instance()->logfile);
$error = 2 == $this->show_upgr_message;
$class = $error ? 'error' : 'updated fade';
$title = sprintf($error ? __('Errors during upgrade of plugin %1$s','event-list') : __('Upgrade of plugin %1$s successful','event-list'), '"Event List"');
$logfile = ' (<a href="'.$logfile.'">upgrade log</a>)';
echo '<div id="message" class="'.$class.'"><p><strong>'.$title.'</strong>'.$logfile.'</p></div>';
}
}
// All Events subpage
$page = add_submenu_page('el_admin_main', __('Events','event-list'), __('All Events','event-list'), 'edit_posts', 'el_admin_main', array(&$this, 'show_main_page'));
add_action('admin_print_scripts-'.$page, array(&$this, 'embed_main_scripts'));
public function remove_upgrade_args($args) {
// check required get parameters
$this->show_upgr_message = isset($_GET['el-upgr-finished']) ? intval($_GET['el-upgr-finished']) : false;
// New Event subpage
$page = add_submenu_page('el_admin_main', __('Add New Event','event-list'), __('Add New','event-list'), 'edit_posts', 'el_admin_new', array(&$this, 'show_new_page'));
add_action('admin_print_scripts-'.$page, array(&$this, 'embed_new_scripts'));
array_push($args, 'el-upgr-finished', 'resume-el-upgr');
return $args;
}
// Categories subpage
$page = add_submenu_page('el_admin_main', __('Event List Categories','event-list'), __('Categories','event-list'), 'manage_categories', 'el_admin_categories', array(&$this, 'show_categories_page'));
add_action('admin_print_scripts-'.$page, array(&$this, 'embed_categories_scripts'));
public function register_events_post_type_mods($current_screen) {
// load file depending on current screen
if(current_user_can('edit_posts')) {
switch($current_screen->id) {
// Main/all events page
case 'edit-el_events':
require_once(EL_PATH.'admin/includes/admin-main.php');
EL_Admin_Main::get_instance();
break;
// New/edit event page
case 'el_events':
// Additional required checks (only for add or edit action, and not for e.g. move event to trash)
$get_action = isset($_GET['action']) ? sanitize_key($_GET['action']) : '';
$post_action = isset($_POST['action']) ? sanitize_key($_POST['action']) : '';
if('add' === $current_screen->action || 'edit' === $get_action || 'editpost' === $post_action) {
require_once(EL_PATH.'admin/includes/admin-new.php');
EL_Admin_New::get_instance();
}
break;
// Event category page
case 'edit-'.$this->events_post_type->taxonomy:
if('1' !== $this->options->get('el_use_post_cats')) {
require_once(EL_PATH.'admin/includes/admin-categories.php');
EL_Admin_Categories::get_instance();
}
break;
}
}
}
/**
* Add and register all admin pages in the admin menu
*/
public function register_pages() {
// Settings subpage
$page = add_submenu_page('el_admin_main', __('Event List Settings','event-list'), __('Settings','event-list'), 'manage_options', 'el_admin_settings', array(&$this, 'show_settings_page'));
$page = add_submenu_page('edit.php?post_type=el_events', __('Event List Settings','event-list'), __('Settings','event-list'), 'manage_options', 'el_admin_settings', array(&$this, 'show_settings_page'));
add_action('admin_print_scripts-'.$page, array(&$this, 'embed_settings_scripts'));
// About subpage
$page = add_submenu_page('el_admin_main', __('About Event List','event-list'), __('About','event-list'), 'edit_posts', 'el_admin_about', array(&$this, 'show_about_page'));
$page = add_submenu_page('edit.php?post_type=el_events', __('About Event List','event-list'), __('About','event-list'), 'edit_posts', 'el_admin_about', array(&$this, 'show_about_page'));
add_action('admin_print_scripts-'.$page, array(&$this, 'embed_about_scripts'));
}
public function db_upgrade_check() {
require_once(EL_PATH.'includes/db.php');
EL_Db::get_instance()->upgrade_check();
// Import page (invisible in menu, but callable by import button on admin main page)
$page = add_submenu_page(null, null, null, 'edit_posts', 'el_admin_import', array(&$this, 'show_import_page'));
add_action('admin_print_scripts-'.$page, array(&$this, 'embed_import_scripts'));
// Sync Post Categories page (invisible in menu, but callable by sync button on admin categories page)
$page = add_submenu_page(null, null, null, 'manage_categories', 'el_admin_cat_sync', array(&$this, 'show_cat_sync_page'));
add_action('load-'.$page, array(&$this, 'handle_cat_sync_actions'));
}
public function add_dashboard_styles() {
......@@ -81,42 +127,17 @@ class EL_Admin {
public function add_events_to_glance() {
if(current_user_can('edit_posts')) {
require_once(EL_PATH.'includes/db.php');
$num = EL_Db::get_instance()->get_num_events();
$url = admin_url('admin.php?page=el_admin_main');
$text = sprintf(_n('%s Event','%s Events',$num,'event-list'), number_format_i18n($num));
return array('<a class="el-events-count" href="'.$url.'">'.$text.'</a>');
}
}
public function show_main_page() {
require_once(EL_PATH.'admin/includes/admin-main.php');
EL_Admin_Main::get_instance()->show_main();
}
public function embed_main_scripts() {
require_once(EL_PATH.'admin/includes/admin-main.php');
EL_Admin_Main::get_instance()->embed_main_scripts();
}
public function show_new_page() {
require_once(EL_PATH.'admin/includes/admin-new.php');
EL_Admin_New::get_instance()->show_new();
}
public function embed_new_scripts() {
require_once(EL_PATH.'admin/includes/admin-new.php');
EL_Admin_New::get_instance()->embed_new_scripts();
}
public function show_categories_page() {
require_once(EL_PATH.'admin/includes/admin-categories.php');
EL_Admin_Categories::get_instance()->show_categories();
}
require_once(EL_PATH.'includes/events.php');
$num_events = EL_Events::get_instance()->get_num_events();
$text = sprintf(_n('%s Event','%s Events',$num_events,'event-list'), number_format_i18n($num_events));
if(current_user_can(get_post_type_object('el_events')->cap->edit_posts)) {
return array('<a class="el-events-count" href="'.admin_url('edit.php?post_type=el_events').'">'.$text.'</a>');
}
else {
return array($text);
}
public function embed_categories_scripts() {
require_once(EL_PATH.'admin/includes/admin-categories.php');
EL_Admin_Categories::get_instance()->embed_categories_scripts();
}
}
public function show_settings_page() {
......@@ -139,19 +160,24 @@ class EL_Admin {
EL_Admin_About::get_instance()->embed_about_scripts();
}
public function action_add_category($cat_id) {
require_once(EL_PATH.'includes/categories.php');
EL_Categories::get_instance()->add_post_category($cat_id);
public function show_import_page() {
require_once(EL_PATH.'admin/includes/admin-import.php');
EL_Admin_Import::get_instance()->show_import();
}
public function embed_import_scripts() {
require_once(EL_PATH.'admin/includes/admin-import.php');
EL_Admin_Import::get_instance()->embed_import_scripts();
}
public function action_edit_category($cat_id) {
require_once(EL_PATH.'includes/categories.php');
EL_Categories::get_instance()->edit_post_category($cat_id);
public function show_cat_sync_page() {
require_once(EL_PATH.'admin/includes/admin-category-sync.php');
EL_Admin_Category_Sync::get_instance()->show_cat_sync();
}
public function action_delete_category($cat_id) {
require_once(EL_PATH.'includes/categories.php');
EL_Categories::get_instance()->delete_post_category($cat_id);
public function handle_cat_sync_actions() {
require_once(EL_PATH.'admin/includes/admin-category-sync.php');
EL_Admin_Category_Sync::get_instance()->handle_actions();
}
}
?>
.el-warning {
.el-warning, .el-success {
background: #fff;
border-left: 4px solid #dc3232;
margin: 5px 0 15px;
padding: 1px 12px;
border-left: 4px solid;
}
.el-warning {
border-left-color: #dc3232;
}
ul.el-categories {
.el-success {
border-left-color: #46b450;
}
ul.el-categories, ul.el-event-errors, td ul {
list-style: circle inside;
margin: 8px 0;
}
......@@ -17,3 +25,7 @@ ul.el-categories {
.el-event-data {
font-style: italic;
}
.form-table td {
vertical-align: top;
}
.wp-list-table .column-date {
width: 105px;
}
.wp-list-table .column-title {
width: 35%;
}
.wp-list-table .column-location {
width: 25%
}
.wp-list-table .column-details {
width: 40%;
}
.wp-list-table .column-pub_user {
width: 105px;
}
.wp-list-table .column-pub_date {
width: 115px;
.wp-list-table .column-eventdate {
width: 130px;
}
span.time {
span.starttime {
font-style: italic;
}
\ No newline at end of file
}
#title, #location {
width: 400px;
label.event-option {
font-size: 14px;
font-weight: 600;
padding-left: 0.4em;
padding-top: 1.3em;
display: inline-block;
}
span.date-wrapper, #start_date, #end_date, #time {
width: 130px;
.inside label.event-option {
padding-bottom: 0.3em;
}
p.note {
margin: 2px;
font-style: italic;
#startdate, #enddate, #starttime, #location {
padding: 0.5em;
z-index: 1000;
}
div#postbox-container-1 {
width: 260px !important;
span.date-wrapper, #startdate, #enddate, #starttime {
width: 150px;
}
#location {
width: 400px;
}
span.date-wrapper {
position: relative;
display: inline-table;
display: inline-block;
}
span.date-wrapper i.dashicons {
display: inline-block;
position: absolute;
padding-top: 3px;
padding-right: 4px;
padding-top: 0.3em;
padding-right: 0.1em;
pointer-events: none;
right: 0px;
z-index: 1;
z-index: 1001;
}
span.date-wrapper input {
padding-right: 24px;
position: relative;
}
.el-inline-checkbox {
padding-left: 1em;
padding-bottom: 0.1em;
}
#postbox-container-0 #primary-sortables {
min-height: 10px;
}
<?php
if(!defined('WPINC')) {
if(!defined('WP_ADMIN')) {
exit;
}
......@@ -37,6 +37,7 @@ class EL_Admin_About {
<div id="icon-edit-pages" class="icon32"><br /></div><h2>'.__('About Event List','event-list').'</h2>';
echo $this->show_tabs($tab);
if('atts' == $tab) {
$this->daterange->load_formats_helptexts();
$this->show_atts();
$this->show_filter_syntax();
$this->show_date_syntax();
......@@ -60,7 +61,7 @@ class EL_Admin_About {
$out = '<h3 class="nav-tab-wrapper">';
foreach($tabs as $tab => $name){
$class = ($tab == $current) ? ' nav-tab-active' : '';
$out .= '<a class="nav-tab'.$class.'" href="?page=el_admin_about&amp;tab='.$tab.'">'.$name.'</a>';
$out .= '<a class="nav-tab'.$class.'" href="'.add_query_arg('tab', $tab, add_query_arg(array())).'">'.$name.'</a>';
}
$out .= '</h3>';
return $out;
......@@ -69,7 +70,7 @@ class EL_Admin_About {
private function show_help() {
echo '
<h3 class="el-headline">'.__('Help and Instructions','event-list').'</h3>
<p>'.sprintf(__('You can manage the events %1$shere%2$s','event-list'), '<a href="'.admin_url('admin.php?page=el_admin_main').'">', '</a>').'.</p>
<p>'.sprintf(__('You can manage the events %1$shere%2$s','event-list'), '<a href="'.admin_url('edit.php?post_type=el_events').'">', '</a>').'.</p>
<p>'.__('To show the events on your site you have 2 possibilities','event-list').':</p>
<ul class="el-show-event-options"><li>'.sprintf(__('you can place the <strong>shortcode</strong> %1$s on any page or post','event-list'), '<code>[event-list]</code>').'</li>
<li>'.sprintf(__('you can add the <strong>widget</strong> %1$s in your sidebars','event-list'), '"Event List"').'</li></ul>
......
<?php
if(!defined('ABSPATH')) {
if(!defined('WP_ADMIN')) {
exit;
}
require_once(EL_PATH.'includes/db.php');
require_once(EL_PATH.'includes/categories.php');
require_once(EL_PATH.'includes/options.php');
require_once(EL_PATH.'admin/includes/admin-functions.php');
require_once(EL_PATH.'includes/events_post_type.php');
// This class handles all data for the admin categories page
class EL_Admin_Categories {
private static $instance;
private $db;
private $categories;
private $options;
private $functions;
private $events_post_type;
public static function &get_instance() {
// Create class instance if required
if(!isset(self::$instance)) {
self::$instance = new EL_Admin_Categories();
self::$instance = new self();
}
// Return class instance
return self::$instance;
}
private function __construct() {
$this->db = &EL_Db::get_instance();
$this->categories = &EL_Categories::get_instance();
$this->options = &EL_Options::get_instance();
$this->functions = &EL_Admin_Functions::get_instance();
}
public function show_categories () {
if(!current_user_can('manage_categories')) {
wp_die(__('You do not have sufficient permissions to access this page.'));
}
// check used get parameters
$action = isset($_GET['action']) ? sanitize_key($_GET['action']) : '';
$slug = isset($_GET['id']) ? sanitize_key($_GET['id']) : 0;
// check actions
$out = $this->check_actions_and_show_messages($action);
// normal output
$out.= '<div class="wrap">
<div id="icon-edit-pages" class="icon32"><br /></div><h2>'.__('Event List Categories','event-list').'</h2>
<div id="posttype-page" class="posttypediv">';
if('edit' === $action && !empty($slug)) {
$out .= $this->show_edit_category_form(__('Edit Category','event-list'), __('Update Category','event-list'), $this->categories->get_category_data($slug));
}
else {
// show category table
$out .= $this->show_category_table();
// show add category form
$out .= $this->show_edit_category_form(__('Add New Category','event-list'), __('Add New Category','event-list'));
// show cat sync option form
$out .= $this->show_cat_sync_form();
}
$out .= '
</div>
</div>';
echo $out;
$this->events_post_type = &EL_Events_Post_Type::get_instance();
add_action('admin_print_scripts', array(&$this, 'embed_categories_scripts'));
add_action('after-'.$this->events_post_type->taxonomy.'-table', array(&$this, 'sync_cats_button'));
add_filter('term_updated_messages', array(&$this, 'prepare_syncdone_message'));
add_filter('removable_query_args', array(&$this, 'remove_message_args'));
}
public function embed_categories_scripts() {
......@@ -69,191 +33,55 @@ class EL_Admin_Categories {
wp_enqueue_script('eventlist_admin_categories_js', EL_URL.'admin/js/admin_categories.js');
}
private function check_actions_and_show_messages($action) {
// check used get parameters
$slugs = isset($_GET['slug']) ? preg_replace('/[^a-z0-9,_\-]/', '', $_GET['slug']) : '';
public function sync_cats_button() {
$url = esc_url(admin_url(add_query_arg(array('page' => 'el_admin_cat_sync', '_wp_http_referer' => $_SERVER['REQUEST_URI']), 'edit.php?post_type=el_events')));
echo '<button type="button" id="sync-cats" class="button action" onclick="el_show_syncform(\''.$url.'\')" style="margin-top: 3px">'.__('Synchronize with post categories', 'event-list').'</button>';
}
$is_disabled = '1' == $this->options->get('el_sync_cats');
$out = '';
if('delete' === $action && !empty($slugs) && !$is_disabled) {
// delete categories
$slug_array = array_map('sanitize_key', explode(',', $slugs));
$num_affected_events = $this->db->remove_category_in_events($slug_array);
if($this->categories->remove_categories($slug_array, false)) {
$out .= '<div id="message" class="updated">
<p><strong>'.sprintf(__('Category "%s" deleted.','event-list'), implode(', ', $slug_array));
if(0 < $num_affected_events) {
$out .= '<br />'.sprintf(__('This Category was also removed from %d events.','event-list'), $num_affected_events);
}
$out .= '</strong></p>
</div>';
}
else {
$out .= '<div id="message" class="error below-h2"><p><strong>'.sprintf(__('Error while deleting category "%s"','event-list'), implode(', ', $slug_array)).'.</strong></p></div>';
}
public function prepare_syncdone_message($messages) {
// prepare used get parameters
$msgdata = isset($_GET['msgdata']) ? $_GET['msgdata'] : array();
$error = isset($_GET['error']);
$items['mod_ok'] = __('%1$s categories modified (%2$s)','event-list');
$items['add_ok'] = __('%1$s categories added (%2$s)','event-list');
$items['del_ok'] = __('%1$s categories deleted (%2$s)','event-list');
if($error) {
$items['mod_error'] = __('%1$s categories not modified (%2$s)','event-list');
$items['add_error'] = __('%1$s categories not added (%2$s)','event-list');
$items['del_error'] = __('%1$s categories not deleted (%2$s)','event-list');
}
else if('setcatsync' === $action) {
// check used post parameters
$el_sync_cats = isset($_POST['el_sync_cats']) && intval($_POST['el_sync_cats']) ? '1' : '';
$this->options->set('el_sync_cats', $el_sync_cats);
$is_disabled = '1' == $this->options->get('el_sync_cats');
if($is_disabled) {
$this->categories->sync_with_post_cats();
$out .= '<div id="message" class="updated"><p><strong>'.__('Sync with post categories enabled.','event-list').'</strong></p></div>';
}
else {
$out .= '<div id="message" class="updated"><p><strong>'.__('Sync with post categories disabled.','event-list').'</strong></p></div>';
}
if($error) {
$msgtext = __('An Error occured during the category sync','event-list').':<br />';
$msgnum = 22;
}
else if('manualcatsync' === $action) {
if(!$is_disabled) {
$this->categories->sync_with_post_cats();
$out .= '<div id="message" class="updated"><p><strong>'.__('Manual sync with post categories sucessfully finished.','event-list').'</strong></p></div>';
}
else {
$msgtext = __('Category sync finished','event-list').':<br />';
$msgnum = 21;
}
else if('editcat' === $action && !empty($_POST)) {
if(!$is_disabled) {
// check used post parameters
$oldslug = isset($_POST['oldslug']) ? sanitize_key($_POST['oldslug']) : 0;
$slug = isset($_POST['slug']) ? sanitize_key($_POST['slug']) : 0;
$name = isset($_POST['name']) ? sanitize_text_field($_POST['name']) : 'No name available!';
if(empty($oldslug)) {
// add new category
if($this->categories->add_category($_POST)) {
$out .= '<div id="message" class="updated below-h2"><p><strong>'.sprintf(__('New Category "%s" was added','event-list'), $name).'.</strong></p></div>';
}
else {
$out .= '<div id="message" class="error below-h2"><p><strong>'.sprintf(__('Error: New Category "%s" could not be added','event-list'), $name).'.</strong></p></div>';
}
}
else {
// edit category
if($this->categories->edit_category($_POST, $oldslug)) {
$out .= '<div id="message" class="updated below-h2"><p><strong>'.sprintf(__('Category "%s" was modified','event-list'), $oldslug).'.</strong></p></div>';
}
else {
$out .= '<div id="message" class="error below-h2"><p><strong>'.sprintf(__('Error: Category "%s" could not be modified','event-list'), $oldslug).'.</strong></p></div>';
}
}
$msgtext .= '<ul style="list-style:inside">';
foreach($items as $name => $text) {
if(isset($msgdata[$name]) && is_array($msgdata[$name])) {
$items = array_map('sanitize_key', $msgdata[$name]);
$msgtext .= $this->show_sync_items($item