Commit 13a0faed authored by lucha's avatar lucha

[auto] plugin: event-list 0.7.12

parent e5f69afb
......@@ -10,10 +10,6 @@ class EL_Admin {
private static $instance;
private $options;
private function __construct() {
$this->options = &EL_Options::get_instance();
}
public static function &get_instance() {
// Create class instance if required
if(!isset(self::$instance)) {
......@@ -23,13 +19,20 @@ class EL_Admin {
return self::$instance;
}
public function init_admin_page() {
private function __construct() {
$this->options = &EL_Options::get_instance();
// Register actions
add_action('admin_init', array(&$this, 'sync_post_categories'), 11);
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_action('right_now_content_table_end', array(&$this, 'add_events_to_right_now'));
add_filter('dashboard_glance_items', array($this, 'add_events_to_glance')
);;;
}
// Register syncing if required
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'));
......@@ -70,16 +73,20 @@ class EL_Admin {
EL_Db::get_instance()->upgrade_check();
}
public function add_events_to_right_now() {
require_once(EL_PATH.'includes/db.php');
$num_events = EL_Db::get_instance()->get_num_events();
$event_link = 'admin.php?page=el_admin_main';
$out = '
<tr>
<td class="first b b-events"><a href="'.$event_link.'">'.$num_events.'</a></td>
<td class="t events"><a href="'.$event_link.'">'.__('Events','event-list').'</a></td>
</tr>';
echo $out;
public function add_dashboard_styles() {
if(current_user_can('edit_posts') && 'dashboard' === get_current_screen()->base) {
echo '<style>#dashboard_right_now .el-events-count:before {content: "\f508"}</style>';
}
}
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() {
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="82"
height="21"
id="svg2"
version="1.1"
inkscape:version="0.91 r13725"
sodipodi:docname="liberapay-donate.svg">
<metadata
id="metadata19">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs17" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="3840"
inkscape:window-height="2064"
id="namedview15"
showgrid="false"
inkscape:zoom="13.759036"
inkscape:cx="10.62332"
inkscape:cy="17.012519"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="svg2"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0" />
<rect
id="back"
x="0.072679512"
y="0.067426629"
width="81.927322"
height="20.932573"
rx="3.9964547"
style="fill:#f6c915" />
<text
font-weight="700"
font-size="14"
x="48.927322"
y="15.424694"
id="text13"
style="font-weight:700;font-size:14px;font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;text-anchor:middle;fill:#1a171b">Donate</text>
<g
style="fill:#1a171b"
transform="matrix(0.19986501,0,0,0.19986501,-9.2609948,-39.153911)"
id="g3379">
<path
inkscape:connector-curvature="0"
d="m 104.28,271.1 c -3.571,0 -6.373,-0.466 -8.41,-1.396 -2.037,-0.93 -3.495,-2.199 -4.375,-3.809 -0.88,-1.609 -1.308,-3.457 -1.282,-5.544 0.025,-2.086 0.313,-4.311 0.868,-6.675 l 9.579,-40.05 11.69,-1.81 -10.484,43.44 c -0.202,0.905 -0.314,1.735 -0.339,2.489 -0.026,0.754 0.113,1.421 0.415,1.999 0.302,0.579 0.817,1.044 1.546,1.395 0.729,0.353 1.747,0.579 3.055,0.679 l -2.263,9.278"
id="path3381" />
<path
inkscape:connector-curvature="0"
d="m 146.52,246.14 c 0,3.671 -0.604,7.03 -1.811,10.07 -1.207,3.043 -2.879,5.669 -5.01,7.881 -2.138,2.213 -4.702,3.935 -7.693,5.167 -2.992,1.231 -6.248,1.848 -9.767,1.848 -1.71,0 -3.42,-0.151 -5.129,-0.453 l -3.394,13.651 -11.162,0 12.52,-52.19 c 2.01,-0.603 4.311,-1.143 6.901,-1.622 2.589,-0.477 5.393,-0.716 8.41,-0.716 2.815,0 5.242,0.428 7.278,1.282 2.037,0.855 3.708,2.024 5.02,3.507 1.307,1.484 2.274,3.219 2.904,5.205 0.627,1.987 0.942,4.11 0.942,6.373 m -27.378,15.461 c 0.854,0.202 1.91,0.302 3.167,0.302 1.961,0 3.746,-0.364 5.355,-1.094 1.609,-0.728 2.979,-1.747 4.111,-3.055 1.131,-1.307 2.01,-2.877 2.64,-4.714 0.628,-1.835 0.943,-3.858 0.943,-6.071 0,-2.161 -0.479,-3.998 -1.433,-5.506 -0.956,-1.508 -2.615,-2.263 -4.978,-2.263 -1.61,0 -3.118,0.151 -4.525,0.453 l -5.28,21.948"
id="path3383" />
</g>
</svg>
......@@ -30,13 +30,13 @@ class EL_Admin_About {
if(!current_user_can('edit_posts')) {
wp_die(__('You do not have sufficient permissions to access this page.'));
}
if(!isset($_GET['tab'])) {
$_GET['tab'] = 'general';
}
// check used get parameters
$tab = isset($_GET['tab']) ? sanitize_key($_GET['tab']) : 'general';
echo '<div class="wrap">
<div id="icon-edit-pages" class="icon32"><br /></div><h2>'.__('About Event List','event-list').'</h2>';
echo $this->show_tabs($_GET['tab']);
if('atts' == $_GET['tab']) {
echo $this->show_tabs($tab);
if('atts' == $tab) {
$this->show_atts();
$this->show_filter_syntax();
$this->show_date_syntax();
......@@ -54,7 +54,7 @@ class EL_Admin_About {
wp_enqueue_style('eventlist_admin_about', EL_URL.'admin/css/admin_about.css');
}
private function show_tabs($current = 'about') {
private function show_tabs($current = 'general') {
$tabs = array('general' => __('General','event-list'),
'atts' => __('Shortcode Attributes','event-list'));
$out = '<h3 class="nav-tab-wrapper">';
......@@ -69,12 +69,12 @@ 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.php?page=el_admin_main">', '</a>').'.</p>
<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>'.__('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>
<p>'.__('The displayed events and their style can be modified with the available widget settings and the available attributes for the shortcode.','event-list').'<br />
'.sprintf(__('A list of all available shortcode attributes with their descriptions is available in the %1$s tab.','event-list'), '<a href="admin.php?page=el_admin_about&tab=atts">'.__('Shortcode Attributes','event-list').'</a>').'<br />
'.sprintf(__('A list of all available shortcode attributes with their descriptions is available in the %1$s tab.','event-list'), '<a href="'.admin_url('admin.php?page=el_admin_about&tab=atts').'">'.__('Shortcode Attributes','event-list').'</a>').'<br />
'.__('The available widget options are described in their tooltip text.','event-list').'<br />
'.sprintf(__('If you enable one of the links options (%1$s or %2$s) in the widget you have to insert an URL to the linked event-list page.','event-list'), '"'.__('Add links to the single events','event-list').'"', '"'.__('Add a link to the Event List page','event-list').'"')
.__('This is required because the widget does not know in which page or post the shortcode was included.','event-list').'<br />
......@@ -82,7 +82,7 @@ class EL_Admin_About {
.sprintf(__('The default value %1$s is normally o.k. (for pages with 1 shortcode only), but if required you can check the id by looking into the URL of an event link on your linked page or post.','event-list'), '[1]')
.sprintf(__('The id is available at the end of the URL parameters (e.g. %1$s).','event-list'), '<i>https://www.your-homepage.com/?page_id=99&amp;event_id<strong>1</strong>=11</i>').'
</p>
<p>'.sprintf(__('Be sure to also check the %1$s to get the plugin behaving just the way you want.','event-list'), '<a href="admin.php?page=el_admin_settings">'.__('Settings page','event-list').'</a>').'</p>';
<p>'.sprintf(__('Be sure to also check the %1$s to get the plugin behaving just the way you want.','event-list'), '<a href="'.admin_url('admin.php?page=el_admin_settings').'">'.__('Settings page','event-list').'</a>').'</p>';
}
private function show_author() {
......@@ -93,8 +93,9 @@ class EL_Admin_About {
<p>'.sprintf(__('This plugin is developed by %1$s, you can find more information about the plugin on the %2$s.','event-list'), 'mibuthu', '<a href="http://wordpress.org/plugins/event-list" target="_blank" rel="noopener">'.__('wordpress plugin site','event-list').'</a>').'</p>
<p>'.sprintf(__('If you like the plugin please rate it on the %1$s.','event-list'), '<a href="http://wordpress.org/support/view/plugin-reviews/event-list" target="_blank" rel="noopener">'.__('wordpress plugin review site','event-list').'</a>').'<br />
<p>'.__('If you want to support the plugin I would be happy to get a small donation','event-list').':<br />
<a class="donate" href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=W54LNZMWF9KW2" target="_blank" rel="noopener"><img src="'.EL_URL.'admin/images/paypal_btn_donate.gif" alt="PayPal Donation" title="Donate with PayPal" border="0"></a>
<a class="donate" href="https://flattr.com/submit/auto?user_id=mibuthu&url=https%3A%2F%2Fwordpress.org%2Fplugins%2Fevent-list" target="_blank" rel="noopener"><img src="'.EL_URL.'admin/images/flattr-badge-large.png" alt="Flattr this" title="Flattr this" border="0"></a></p>
<a class="donate" href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=W54LNZMWF9KW2" target="_blank" rel="noopener"><img src="'.EL_URL.'admin/images/paypal_btn_donate.gif" alt="PayPal Donation" title="'.sprintf(__('Donate with %1$s','event-list'), 'PayPal').'" border="0"></a>
<a class="donate" href="https://liberapay.com/mibuthu/donate" target="_blank" rel="noopener"><img src="'.EL_URL.'admin/images/liberapay-donate.svg" alt="Liberapay Donation" title="'.sprintf(__('Donate with %1$s','event-list'), 'Liberapay').'" border="0"></a>
<a class="donate" href="https://flattr.com/submit/auto?user_id=mibuthu&url=https%3A%2F%2Fwordpress.org%2Fplugins%2Fevent-list" target="_blank" rel="noopener"><img src="'.EL_URL.'admin/images/flattr-badge-large.png" alt="Flattr this" title="'.sprintf(__('Donate with %1$s','event-list'), 'Flattr').'" border="0"></a></p>
</div>';
}
......@@ -128,7 +129,7 @@ class EL_Admin_About {
$out .= '
<tr>
<td>'.$aname.'</td>
<td>'.$a['val'].'</td>
<td>'.implode('<br />', $a['val']).'</td>
<td>'.$a['std_val'].'</td>
<td>'.$a['desc'].'</td>
</tr>';
......
......@@ -36,21 +36,19 @@ class EL_Admin_Categories {
if(!current_user_can('manage_categories')) {
wp_die(__('You do not have sufficient permissions to access this page.'));
}
$out = '';
// check used get parameters
$action = isset($_GET['action']) ? sanitize_key($_GET['action']) : '';
$slug = isset($_GET['id']) ? sanitize_key($_GET['id']) : 0;
// get action
$action = '';
if(isset($_GET['action'])) {
$action = $_GET['action'];
}
$out .= $this->check_actions_and_show_messages($action);
// 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 && isset($_GET['id'])) {
$out .=$this->show_edit_category_form(__('Edit Category','event-list'), __('Update Category','event-list'), $this->categories->get_category_data($_GET['id']));
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
......@@ -72,30 +70,32 @@ class EL_Admin_Categories {
}
private function check_actions_and_show_messages($action) {
// check used get parameters
$slugs = isset($_GET['slug']) ? preg_replace('/[^a-z0-9,_\-]/', '', $_GET['slug']) : '';
$is_disabled = '1' == $this->options->get('el_sync_cats');
$out = '';
if('delete' === $action && isset($_GET['slug'])) {
if(!$is_disabled) {
// delete categories
$slug_array = explode(', ', $_GET['slug']);
$slug_array = array_map('sanitize_title_for_query', $slug_array);
$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($num_affected_events > 0) {
$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>';
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>';
}
}
else if('setcatsync' === $action) {
$el_sync_cats = isset($_POST['el_sync_cats']) ? '1' : '';
// 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) {
......@@ -114,22 +114,27 @@ class EL_Admin_Categories {
}
else if('editcat' === $action && !empty($_POST)) {
if(!$is_disabled) {
if(!isset($_POST['id'])) {
// 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'), $_POST['name']).'.</strong></p></div>';
$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'), $_POST['name']).'.</strong></p></div>';
$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, $_POST['id'])) {
$out .= '<div id="message" class="updated below-h2"><p><strong>'.sprintf(__('Category "%s" was modified','event-list'), $_POST['id']).'.</strong></p></div>';
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'), $_POST['id']).'.</strong></p></div>';
$out .= '<div id="message" class="error below-h2"><p><strong>'.sprintf(__('Error: Category "%s" could not be modified','event-list'), $oldslug).'.</strong></p></div>';
}
}
}
......@@ -159,7 +164,7 @@ class EL_Admin_Categories {
<form id="addtag" method="POST" action="?page=el_admin_categories&amp;action=editcat">';
if(!$is_new_event) {
$out .= '
<input type="hidden" name="id" value="'.$cat_data['slug'].'">';
<input type="hidden" name="oldslug" value="'.$cat_data['slug'].'">';
}
// Category Name
$out .= '
......@@ -199,12 +204,15 @@ class EL_Admin_Categories {
}
private function show_category_table() {
// check used parameters
$page = isset($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : '';
$out = '
<div id="col-container">
<div id="col-right">
<div class="col-wrap">
<form id="category-filter" method="get">
<input type="hidden" name="page" value="'.$_REQUEST['page'].'" />';
<input type="hidden" name="page" value="'.$page.'" />';
$is_disabled = '1' == $this->options->get('el_sync_cats');
require_once(EL_PATH.'admin/includes/category_table.php');
$category_table = new EL_Category_Table($is_disabled);
......
......@@ -103,8 +103,6 @@ class EL_Admin_Import {
return;
}
$serialized = serialize($this->import_data);
// Check categories
$not_available_cats = array();
foreach($this->import_data as $event) {
......@@ -152,7 +150,7 @@ class EL_Admin_Import {
</div>
</div>
</div>
<input type="hidden" name="reviewed_events" id="reviewed_events" value="'.esc_html($serialized).'" />
<input type="hidden" name="reviewed_events" id="reviewed_events" value="'.esc_html(json_encode($this->import_data)).'" />
</form>';
}
......@@ -160,7 +158,7 @@ class EL_Admin_Import {
if(!$with_error) {
echo '
<h3>'.__('Import with errors!','event-list').'</h3>
'.sprintf(__('An error occurred during import! Please send your import file to %1$sthe administrator%2$s for analysis.','event-list'), '<a href="mailto:'.get_option('admin_email').'">', '</a>');
'.__('Sorry, an error occurred during import!','event-list');
}
else {
echo '
......@@ -205,7 +203,7 @@ class EL_Admin_Import {
continue;
}
// check header
if($lineNum === 0) {
if(empty($lineNum)) {
// check optional separator line
if($line === $separator) {
$emptyLines += 1;
......@@ -239,8 +237,11 @@ class EL_Admin_Import {
private function safe_import_settings() {
foreach($this->options->options as $oname => $o) {
if('import' == $o['section'] && isset($_POST[$oname])) {
$this->options->set($oname, $_POST[$oname]);
// check used post parameters
$ovalue = isset($_POST[$oname]) ? sanitize_text_field($_POST[$oname]) : '';
if('import' == $o['section'] && !empty($ovalue)) {
$this->options->set($oname, $ovalue);
}
}
}
......@@ -298,17 +299,24 @@ class EL_Admin_Import {
}
private function import_events() {
$reviewed_events = unserialize(stripslashes($_POST['reviewed_events']));
// check used post parameters
$reviewed_events = json_decode(stripslashes($_POST['reviewed_events']), true);
if(empty($reviewed_events)) {
return false;
}
$additional_cat_array = isset($_POST['categories']) && is_array($_POST['categories']) ? array_map('sanitize_key', $_POST['categories']) : array();
// Category handling
$additional_cats = isset($_POST['categories']) ? $_POST['categories'] : array();
foreach($reviewed_events as &$event) {
// Remove not available categories of import file
$event['categories'] = array_filter($event['categories'], function($e) {
return $this->categories->is_set($e);
});
foreach($event['categories'] as $cat) {
if(!$this->categories->is_set($cat)) {
unset($event['categories'][$cat]);
}
}
// Add the additionally specified categories to the event
if(!empty($additional_cats)) {
$event['categories'] = array_unique(array_merge($event['categories'], $additional_cats));
if(!empty($additional_cat_array)) {
$event['categories'] = array_unique(array_merge($event['categories'], $additional_cat_array));
}
}
$ret = array();
......@@ -316,7 +324,7 @@ class EL_Admin_Import {
// check if dates have correct formats
$start_date = DateTime::createFromFormat($this->options->get('el_import_date_format'), $event['start_date']);
$end_date = DateTime::createFromFormat($this->options->get('el_import_date_format'), $event['end_date']);
if($start_date) {
if($start_date instanceof DateTime) {
$event['start_date'] = $start_date->format('Y-m-d');
if($end_date) {
$event['end_date'] = $end_date->format('Y-m-d');
......
......@@ -29,30 +29,33 @@ class EL_Admin_Main {
$this->filterbar = &EL_Filterbar::get_instance();
$this->event_table = new EL_Event_Table();
$this->action = $this->event_table->current_action();
// check for real actions
if($this->action) {
// check used post parameters
$title = isset($_POST['title']) ? sanitize_text_field($_POST['title']) : '';
switch($this->action) {
// real actions (redirect when finished)
case 'new':
if(!empty($_POST)) {
$id = $this->update_event($_POST);
$id = $this->update_event();
$error = !$id;
$this->redirect('added', $error, array('title' => urlencode($_POST['title']), 'id' => $id));
$this->redirect('added', $error, array('title' => urlencode($title), 'id' => $id));
}
break;
case 'edited':
if(!empty($_POST)) {
$error = !$this->update_event($_POST);
$this->redirect('modified', $error, array('title' => urlencode($_POST['title']), 'id' => $_POST['id']));
$id = isset($_POST['id']) ? intval($_POST['id']) : 0;
$error = !$this->update_event();
$this->redirect('modified', $error, array('title' => urlencode($title), 'id' => $id));
}
break;
case 'delete':
if(isset($_GET['id'])) {
$id_array = explode(',', $_GET['id']);
$id_array = array_map('absint', $id_array);
$error = !$this->db->delete_events($id_array);
$this->redirect('deleted', $error, array('id' => implode(',', $id_array)));
}
$ids_string = isset($_GET['id']) ? preg_replace('/[^0-9,]/', '', $_GET['id']) : '';
$id_array = explode(',', $ids_string);
$error = !$this->db->delete_events($id_array);
$this->redirect('deleted', $error, array('id' => implode(',', $id_array)));
break;
// proceed with header if a bulk action was triggered (required due to "noheader" attribute for all action above)
case 'delete_bulk':
......@@ -60,12 +63,12 @@ class EL_Admin_Main {
break;
}
}
// check used get parameters
$action1 = isset($_REQUEST['action']) ? intval($_REQUEST['action']) : 0;
$action2 = isset($_REQUEST['action2']) ? intval($_REQUEST['action2']) : 0;
// cleanup query args if the button for bulk action was clicked, but no bulk action was selected
if(isset($_REQUEST['action']) && '-1' == $_REQUEST['action'] && isset($_REQUEST['action2']) && '-1' == $_REQUEST['action2']) {
$this->redirect();
}
// cleanup query args if filter button was pressed
if(isset($_GET['filter'])) {
if(-1 == $action1 && -1 == $action2) {
$this->redirect();
}
}
......@@ -99,12 +102,6 @@ class EL_Admin_Main {
}
}
// proceed with normal event list page
if(!isset($_GET['orderby'])) {
// set initial sorting
$_GET['orderby'] = 'date';
$_GET['order'] = 'asc';
}
$this->show_page_header($this->action);
echo $this->show_event_table();
echo '</div>';
......@@ -112,7 +109,10 @@ class EL_Admin_Main {
private function show_page_header($action, $editview=false) {
if($editview) {
$duplicate_link = add_query_arg(array('id'=>absint($_GET['id']), 'action'=>'copy'), '?page=el_admin_new');
// check used get parameters
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$duplicate_link = add_query_arg(array('id'=>$id, 'action'=>'copy'), '?page=el_admin_new');
$header = __('Edit Event','event-list').' <a href="'.$duplicate_link.'" class="add-new-h2">'.__('Duplicate','event-list').'</a>';
}
else {
......@@ -155,12 +155,13 @@ class EL_Admin_Main {
}
private function show_event_table() {
// show filterbar
$out = '';
// check used parameters
$page = isset($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : '';
// show event table
// the form is required for bulk actions, the page field is required for plugins to ensure that the form posts back to the current page
$out .= '<form id="event-filter" method="get">
<input type="hidden" name="page" value="'.$_REQUEST['page'].'" />';
$out = '<form id="event-filter" method="get">
<input type="hidden" name="page" value="'.$page.'" />';
// show table
$this->event_table->prepare_items();
ob_start();
......@@ -172,27 +173,40 @@ class EL_Admin_Main {
}
private function show_message($action) {
$error = isset($_GET['error']);
if(empty($action)) {
return;
}