Event List - Version 0.4.4

Version Description

(2013-07-20) =

  • added support for sub-categories
  • moved category administration to seperate page
  • improved category sorting
Download this release

Release Info

Developer mibuthu
Plugin Icon 128x128 Event List
Version 0.4.4
Comparing to
See all releases

Code changes from version 0.4.3 to 0.4.4

admin/admin.php CHANGED
@@ -37,9 +37,13 @@ class EL_Admin {
37
  $page = add_submenu_page('el_admin_main', 'Add New Event', 'Add New', 'edit_posts', 'el_admin_new', array(&$this, 'show_new_page'));
38
  add_action('admin_print_scripts-'.$page, array(&$this, 'embed_new_scripts'));
39
 
 
 
 
 
40
  // Settings subpage
41
  $page = add_submenu_page('el_admin_main', 'Event List Settings', 'Settings', 'manage_options', 'el_admin_settings', array(&$this, 'show_settings_page'));
42
- add_action('admin_print_scripts-'.$page, array(&$this, 'embed_settings_scripts'));
43
 
44
  // About subpage
45
  $page = add_submenu_page('el_admin_main', 'About Event List', 'About', 'edit_posts', 'el_admin_about', array(&$this, 'show_about_page'));
@@ -71,16 +75,26 @@ class EL_Admin {
71
  EL_Admin_New::get_instance()->embed_new_scripts();
72
  }
73
 
 
 
 
 
 
 
 
 
 
 
74
  public function show_settings_page() {
75
  require_once(EL_PATH.'admin/includes/admin-settings.php');
76
  EL_Admin_Settings::get_instance()->show_settings();
77
  }
78
-
79
  public function embed_settings_scripts() {
80
  require_once(EL_PATH.'admin/includes/admin-settings.php');
81
  EL_Admin_Settings::get_instance()->embed_settings_scripts();
82
  }
83
-
84
  public function show_about_page() {
85
  require_once(EL_PATH.'admin/includes/admin-about.php');
86
  EL_Admin_About::get_instance()->show_about();
37
  $page = add_submenu_page('el_admin_main', 'Add New Event', 'Add New', 'edit_posts', 'el_admin_new', array(&$this, 'show_new_page'));
38
  add_action('admin_print_scripts-'.$page, array(&$this, 'embed_new_scripts'));
39
 
40
+ // Categories subpage
41
+ $page = add_submenu_page('el_admin_main', 'Event List Categories', 'Categories', 'manage_options', 'el_admin_categories', array(&$this, 'show_categories_page'));
42
+ add_action('admin_print_scripts-'.$page, array(&$this, 'embed_categories_scripts'));
43
+
44
  // Settings subpage
45
  $page = add_submenu_page('el_admin_main', 'Event List Settings', 'Settings', 'manage_options', 'el_admin_settings', array(&$this, 'show_settings_page'));
46
+ //add_action('admin_print_scripts-'.$page, array(&$this, 'embed_settings_scripts'));
47
 
48
  // About subpage
49
  $page = add_submenu_page('el_admin_main', 'About Event List', 'About', 'edit_posts', 'el_admin_about', array(&$this, 'show_about_page'));
75
  EL_Admin_New::get_instance()->embed_new_scripts();
76
  }
77
 
78
+ public function show_categories_page() {
79
+ require_once(EL_PATH.'admin/includes/admin-categories.php');
80
+ EL_Admin_Categories::get_instance()->show_categories();
81
+ }
82
+
83
+ public function embed_categories_scripts() {
84
+ require_once(EL_PATH.'admin/includes/admin-categories.php');
85
+ EL_Admin_Categories::get_instance()->embed_categories_scripts();
86
+ }
87
+
88
  public function show_settings_page() {
89
  require_once(EL_PATH.'admin/includes/admin-settings.php');
90
  EL_Admin_Settings::get_instance()->show_settings();
91
  }
92
+ /*
93
  public function embed_settings_scripts() {
94
  require_once(EL_PATH.'admin/includes/admin-settings.php');
95
  EL_Admin_Settings::get_instance()->embed_settings_scripts();
96
  }
97
+ */
98
  public function show_about_page() {
99
  require_once(EL_PATH.'admin/includes/admin-about.php');
100
  EL_Admin_About::get_instance()->show_about();
admin/includes/admin-about.php CHANGED
@@ -32,7 +32,7 @@ class EL_Admin_About {
32
  <ul class="el-show-event-options"><li>you can place the <strong>shortcode</strong> <code>[event-list]</code> on any page or post</li>
33
  <li>you can add the <strong>widget</strong> "Event List" in your sidebars</li></ul>
34
  The displayed events and their style can be modified with the available widget settings and the available attributes for the shortcode.<br />
35
- A list of all available shortcode attributes with their description is listed below.<br />
36
  The most available options of the widget should be clear by there description.<br />
37
  It is important to know that you have to insert an URL to the linked event-list page if you enable one of the links options ("Add links to the single events" or "Add a link to an event page").
38
  This is required because the widget didn´t know in which page or post you have insert the shortcode.<br />
@@ -40,7 +40,7 @@ class EL_Admin_About {
40
  So the standard value "1" is normally o.k., but you can check the ID if you have a look into the URL of an event link on your linked page or post.
41
  The ID is given behind the "_" (e.g. <i>http://www.your-homepage.com/?page_id=99&event_id_<strong>1</strong>=11</i>).
42
  </p>
43
- <p>Be sure to also check the <a href="admin.php?page=el_admin_settings">settings page</a> to get Event List behaving just the way you want.</p>
44
  </div>';
45
  $out .= $this->show_atts();
46
  echo $out;
@@ -52,7 +52,7 @@ class EL_Admin_About {
52
 
53
  private function show_atts() {
54
  $out = '
55
- <h3 class="el-headline">Available Shortcode Attributes</h3>
56
  <div>
57
  You have the possibility to modify the output if you add some of the following attributes to the shortcode.<br />
58
  You can combine as much attributes as you want. E.g.the shortcode including the attributes "num_events" and "show_nav" would looks like this:
32
  <ul class="el-show-event-options"><li>you can place the <strong>shortcode</strong> <code>[event-list]</code> on any page or post</li>
33
  <li>you can add the <strong>widget</strong> "Event List" in your sidebars</li></ul>
34
  The displayed events and their style can be modified with the available widget settings and the available attributes for the shortcode.<br />
35
+ A list of all available shortcode attributes with their description is available below.<br />
36
  The most available options of the widget should be clear by there description.<br />
37
  It is important to know that you have to insert an URL to the linked event-list page if you enable one of the links options ("Add links to the single events" or "Add a link to an event page").
38
  This is required because the widget didn´t know in which page or post you have insert the shortcode.<br />
40
  So the standard value "1" is normally o.k., but you can check the ID if you have a look into the URL of an event link on your linked page or post.
41
  The ID is given behind the "_" (e.g. <i>http://www.your-homepage.com/?page_id=99&event_id_<strong>1</strong>=11</i>).
42
  </p>
43
+ <p>Be sure to also check the <a href="admin.php?page=el_admin_settings">Settings page</a> to get Event List behaving just the way you want.</p>
44
  </div>';
45
  $out .= $this->show_atts();
46
  echo $out;
52
 
53
  private function show_atts() {
54
  $out = '
55
+ <h3 class="el-headline">AShortcode Attributes</h3>
56
  <div>
57
  You have the possibility to modify the output if you add some of the following attributes to the shortcode.<br />
58
  You can combine as much attributes as you want. E.g.the shortcode including the attributes "num_events" and "show_nav" would looks like this:
admin/includes/admin-categories.php ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if(!defined('ABSPATH')) {
3
+ exit;
4
+ }
5
+
6
+ require_once(EL_PATH.'includes/db.php');
7
+ require_once(EL_PATH.'includes/categories.php');
8
+ require_once(EL_PATH.'admin/includes/admin-functions.php');
9
+
10
+ // This class handles all data for the admin categories page
11
+ class EL_Admin_Categories {
12
+ private static $instance;
13
+ private $db;
14
+ private $categories;
15
+ private $functions;
16
+
17
+ public static function &get_instance() {
18
+ // Create class instance if required
19
+ if(!isset(self::$instance)) {
20
+ self::$instance = new EL_Admin_Categories();
21
+ }
22
+ // Return class instance
23
+ return self::$instance;
24
+ }
25
+
26
+ private function __construct() {
27
+ $this->db = &EL_Db::get_instance();
28
+ $this->categories = &EL_Categories::get_instance();
29
+ $this->functions = &EL_Admin_Functions::get_instance();
30
+ }
31
+
32
+ public function show_categories () {
33
+ if(!current_user_can('manage_options')) {
34
+ wp_die(__('You do not have sufficient permissions to access this page.'));
35
+ }
36
+ $out = '';
37
+
38
+ // get action
39
+ $action = '';
40
+ if(isset($_GET['action'])) {
41
+ $action = $_GET['action'];
42
+ }
43
+ $out .= $this->check_actions_and_show_messages($action);
44
+
45
+ // normal output
46
+ $out.= '<div class="wrap">
47
+ <div id="icon-edit-pages" class="icon32"><br /></div><h2>Event List Categories</h2>
48
+ <div id="posttype-page" class="posttypediv">';
49
+ if('edit' === $action && isset($_GET['id'])) {
50
+ $out .=$this->show_edit_category_form(__('Edit Category'), __('Update Category'), $this->categories->get_category_data($_GET['id']));
51
+ }
52
+ else {
53
+ // show category table
54
+ $out .= $this->show_category_table();
55
+ // show add category form
56
+ $out .= $this->show_edit_category_form(__('Add New Category'), __('Add New Category'));
57
+ }
58
+ $out .= '
59
+ </div>
60
+ </div>';
61
+ echo $out;
62
+ }
63
+
64
+ public function embed_categories_scripts() {
65
+ wp_enqueue_script('eventlist_admin_categories_js', EL_URL.'admin/js/admin_categories.js');
66
+ }
67
+
68
+ private function check_actions_and_show_messages($action) {
69
+ $out = '';
70
+ if('delete' === $action && isset($_GET['slug'])) {
71
+ // delete categories
72
+ $slug_array = explode(', ', $_GET['slug']);
73
+ $num_affected_events = $this->db->remove_category_in_events($slug_array);
74
+ require_once(EL_PATH.'admin/includes/category_table.php');
75
+ if($this->categories->remove_categories($slug_array)) {
76
+ $out .= '<div id="message" class="updated">
77
+ <p><strong>'.sprintf(__('Category "%s" deleted.'), $_GET['slug']);
78
+ if($num_affected_events > 0) {
79
+ $out .= '<br />'.sprintf(__('This Category was also removed from %d events.'), $num_affected_events);
80
+ }
81
+ $out .= '</strong></p>
82
+ </div>';
83
+ }
84
+ else {
85
+ $out .= '<div id="message" class="error below-h2"><p><strong>Error while deleting category "'.$_GET['slug'].'".</strong></p></div>';
86
+ }
87
+ }
88
+ else if(!empty($_POST)) {
89
+ if(!isset($_POST['id'])) {
90
+ // add new category
91
+ if($this->categories->add_category($_POST)) {
92
+ $out .= '<div id="message" class="updated below-h2"><p><strong>New Category "'.$_POST['name'].'" was added.</strong></p></div>';
93
+ }
94
+ else {
95
+ $out .= '<div id="message" class="error below-h2"><p><strong>Error: New Category "'.$_POST['name'].'" could not be added.</strong></p></div>';
96
+ }
97
+ }
98
+ else {
99
+ // edit category
100
+ if($this->categories->edit_category($_POST, $_POST['id'])) {
101
+ $this->db->change_category_slug_in_events($_POST['id'], $_POST['slug']);
102
+ $out .= '<div id="message" class="updated below-h2"><p><strong>Category "'.$_POST['id'].'" was modified.</strong></p></div>';
103
+ }
104
+ else {
105
+ $out .= '<div id="message" class="error below-h2"><p><strong>Error: Category "'.$_POST['id'].'" could not be modified.</strong></p></div>';
106
+ }
107
+ }
108
+ }
109
+ return $out;
110
+ }
111
+
112
+ private function show_edit_category_form($title, $button_text, $cat_data=null) {
113
+ $is_new_event = (null == $cat_data);
114
+ if($is_new_event) {
115
+ $cat_data['name'] = '';
116
+ $cat_data['slug'] = '';
117
+ $cat_data['desc'] = '';
118
+ }
119
+ $out = '
120
+ <div id="col-left">
121
+ <div class="col-wrap">
122
+ <div class="form-wrap">
123
+ <h3>'.$title.'</h3>
124
+ <form id="addtag" method="POST" action="?page=el_admin_categories&amp;tab=category">';
125
+ if(!$is_new_event) {
126
+ $out .= '
127
+ <input type="hidden" name="id" value="'.$cat_data['slug'].'">';
128
+ }
129
+ // Category Name
130
+ $out .= '
131
+ <div class="form-field form-required"><label for="name">Name: </label>';
132
+ $out .= $this->functions->show_text('name', $cat_data['name']);
133
+ $out .= '<p>'.__('The name is how it appears on your site.').'</p></div>';
134
+ // Category Slug
135
+ $out .= '
136
+ <div class="form-field"><label for="name">Slug: </label>';
137
+ $out .= $this->functions->show_text('slug', $cat_data['slug']);
138
+ $out .= '<p>'.__('The “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.').'</p></div>';
139
+ // Category Parent
140
+ $out .= '
141
+ <div class="form-field"><label for="parent">Parent: </label>';
142
+ $cat_array = $this->categories->get_cat_array('name', 'asc');
143
+ $option_array = array('' => __('None'));
144
+ $class_array = array();
145
+ foreach($cat_array as $cat) {
146
+ if($cat['slug'] != $cat_data['slug']) {
147
+ $option_array[$cat['slug']] = str_pad($cat['name'], 18*$cat['level'], '&nbsp;', STR_PAD_LEFT);
148
+ $class_array[$cat['slug']] = 'level-'.$cat['level'];
149
+ }
150
+ }
151
+ $selected = isset($cat_data['parent']) ? $cat_data['parent'] : null;
152
+ $out .= $this->functions->show_combobox('parent', $option_array, $selected, $class_array);
153
+ $out .= '<p>'.__('Categories can have a hierarchy. You might have a Jazz category, and under that have children categories for Bebop and Big Band. Totally optional.').'</p></div>';
154
+ // Category Description
155
+ $out .= '
156
+ <div class="form-field"><label for="name">Description: </label>';
157
+ $out .= $this->functions->show_textarea('desc', $cat_data['desc']);
158
+ $out .= '</div>
159
+ <p class="submit"><input type="submit" class="button-primary" name="add_cat" value="'.$button_text.'" id="submitbutton"></p>';
160
+ $out .= '
161
+ </form>
162
+ </div>
163
+ </div>
164
+ </div>
165
+ </div>';
166
+ return $out;
167
+ }
168
+
169
+ private function show_category_table() {
170
+ $out = '
171
+ <div id="col-container">
172
+ <div id="col-right">
173
+ <div class="col-wrap">
174
+ <form id="category-filter" method="get">
175
+ <input type="hidden" name="page" value="'.$_REQUEST['page'].'" />';
176
+ require_once(EL_PATH.'admin/includes/category_table.php');
177
+ $category_table = new EL_Category_Table();
178
+ $category_table->prepare_items();
179
+ ob_start();
180
+ $category_table->display();
181
+ $out .= ob_get_contents();
182
+ ob_end_clean();
183
+ $out .= '
184
+ </form>
185
+ </div>
186
+ </div>';
187
+ return $out;
188
+ }
189
+ }
190
+ ?>
admin/includes/admin-functions.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if(!defined('ABSPATH')) {
3
+ exit;
4
+ }
5
+
6
+ require_once(EL_PATH.'includes/options.php');
7
+
8
+ // This class handles general functions which can be used on different admin pages
9
+ class EL_Admin_Functions {
10
+ private static $instance;
11
+
12
+ public static function &get_instance() {
13
+ // Create class instance if required
14
+ if(!isset(self::$instance)) {
15
+ self::$instance = new EL_Admin_Functions();
16
+ }
17
+ // Return class instance
18
+ return self::$instance;
19
+ }
20
+
21
+ private function __construct() {
22
+
23
+ }
24
+
25
+ public function show_checkbox($name, $value, $caption) {
26
+ $out = '
27
+ <label for="'.$name.'">
28
+ <input name="'.$name.'" type="checkbox" id="'.$name.'" value="1"';
29
+ if($value == 1) {
30
+ $out .= ' checked="checked"';
31
+ }
32
+ $out .= ' />
33
+ '.$caption.'
34
+ </label>';
35
+ return $out;
36
+ }
37
+
38
+ public function show_combobox($name, $option_array, $selected=null, $class_array=null) {
39
+ $out = '
40
+ <select id="'.$name.'" name="'.$name.'">';
41
+ foreach($option_array as $key => $value) {
42
+ $class_text = isset($class_array[$key]) ? 'class="'.$class_array[$key].'" ' : '';
43
+ $selected_text = $selected===$key ? 'selected ' : '';
44
+ $out .= '
45
+ <option '.$class_text.$selected_text.'value="'.$key.'">'.$value.'</option>';
46
+ }
47
+ $out .= '
48
+ </select>';
49
+ return $out;
50
+ }
51
+
52
+ public function show_radio($name, $value, $caption) {
53
+ $out = '
54
+ <fieldset>';
55
+ foreach($caption as $okey => $ocaption) {
56
+ $checked = ($value === $okey) ? 'checked="checked" ' : '';
57
+ $out .= '
58
+ <label title="'.$ocaption.'">
59
+ <input type="radio" '.$checked.'value="'.$okey.'" name="'.$name.'">
60
+ <span>'.$ocaption.'</span>
61
+ </label>
62
+ <br />';
63
+ }
64
+ $out .= '
65
+ </fieldset>';
66
+ return $out;
67
+ }
68
+
69
+ public function show_text($name, $value) {
70
+ $out = '
71
+ <input name="'.$name.'" type="text" id="'.$name.'" value="'.$value.'" />';
72
+ return $out;
73
+ }
74
+
75
+ public function show_textarea($name, $value) {
76
+ $out = '
77
+ <textarea name="'.$name.'" id="'.$name.'" rows="5" class="large-text code">'.$value.'</textarea>';
78
+ return $out;
79
+ }
80
+ }
81
+ ?>
admin/includes/admin-new.php CHANGED
@@ -4,13 +4,13 @@ if(!defined('ABSPATH')) {
4
  }
5
 
6
  require_once(EL_PATH.'includes/db.php');
7
- require_once(EL_PATH.'includes/options.php');
8
 
9
  // This class handles all data for the admin new event page
10
  class EL_Admin_New {
11
  private static $instance;
12
  private $db;
13
- private $options;
14
 
15
  public static function &get_instance() {
16
  // Create class instance if required
@@ -23,7 +23,7 @@ class EL_Admin_New {
23
 
24
  private function __construct() {
25
  $this->db = &EL_Db::get_instance();
26
- $this->options = &EL_Options::get_instance();
27
  }
28
 
29
  public function show_new() {
@@ -145,15 +145,29 @@ class EL_Admin_New {
145
  $out = '
146
  <div id="taxonomy-category" class="categorydiv">
147
  <div id="category-all" class="tabs-panel">';
148
- $cat_array = (array) $this->options->get('el_categories');
149
  if(empty($cat_array)) {
150
  $out .= __('No categories available.');
151
  }
152
  else {
153
  $out .= '
154
  <ul id="categorychecklist" class="categorychecklist form-no-clear">';
 
155
  $event_cats = explode('|', substr($metabox['args']['event_cats'], 1, -1));
156
  foreach($cat_array as $cat) {
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  $checked = in_array($cat['slug'], $event_cats) ? 'checked="checked" ' : '';
158
  $out .= '
159
  <li id="'.$cat['slug'].'" class="popular-catergory">
4
  }
5
 
6
  require_once(EL_PATH.'includes/db.php');
7
+ require_once(EL_PATH.'includes/categories.php');
8
 
9
  // This class handles all data for the admin new event page
10
  class EL_Admin_New {
11
  private static $instance;
12
  private $db;
13
+ private $categories;
14
 
15
  public static function &get_instance() {
16
  // Create class instance if required
23
 
24
  private function __construct() {
25
  $this->db = &EL_Db::get_instance();
26
+ $this->categories = &EL_Categories::get_instance();
27
  }
28
 
29
  public function show_new() {
145
  $out = '
146
  <div id="taxonomy-category" class="categorydiv">
147
  <div id="category-all" class="tabs-panel">';
148
+ $cat_array = $this->categories->get_cat_array('name', 'asc');
149
  if(empty($cat_array)) {
150
  $out .= __('No categories available.');
151
  }
152
  else {
153
  $out .= '
154
  <ul id="categorychecklist" class="categorychecklist form-no-clear">';
155
+ $level = 0;
156
  $event_cats = explode('|', substr($metabox['args']['event_cats'], 1, -1));
157
  foreach($cat_array as $cat) {
158
+ if($cat['level'] > $level) {
159
+ //new sub level
160
+ $out .= '
161
+ <ul class="children">';
162
+ $level++;
163
+ }
164
+ while($cat['level'] < $level) {
165
+ // finish sub level
166
+ $out .= '
167
+ </ul>';
168
+ $level--;
169
+ }
170
+ $level = $cat['level'];
171
  $checked = in_array($cat['slug'], $event_cats) ? 'checked="checked" ' : '';
172
  $out .= '
173
  <li id="'.$cat['slug'].'" class="popular-catergory">
admin/includes/admin-settings.php CHANGED
@@ -3,16 +3,14 @@ if(!defined('ABSPATH')) {
3
  exit;
4
  }
5
 
6
- require_once(EL_PATH.'includes/db.php');
7
  require_once(EL_PATH.'includes/options.php');
8
- require_once(EL_PATH.'includes/categories.php');
9
 
10
  // This class handles all data for the admin settings page
11
  class EL_Admin_Settings {
12
  private static $instance;
13
- private $db;
14
  private $options;
15
- private $categories;
16
 
17
  public static function &get_instance() {
18
  // Create class instance if required
@@ -24,9 +22,8 @@ class EL_Admin_Settings {
24
  }
25
 
26
  private function __construct() {
27
- $this->db = &EL_Db::get_instance();
28
  $this->options = &EL_Options::get_instance();
29
- $this->categories = &EL_Categories::get_instance();
30
  }
31
 
32
  public function show_settings () {
@@ -40,39 +37,27 @@ class EL_Admin_Settings {
40
  </div>';
41
  }
42
 
43
- // get action
44
- $action = '';
45
- if(isset($_GET['action'])) {
46
- $action = $_GET['action'];
47
- }
48
- $out .= $this->check_for_actions_and_show_messages($action);
49
-
50
  // normal output
51
  $out.= '<div class="wrap">
52
  <div id="icon-edit-pages" class="icon32"><br /></div><h2>Event List Settings</h2>';
53
  if(!isset($_GET['tab'])) {
54
- $_GET['tab'] = 'category';
55
  }
56
  $out .= $this->show_tabs($_GET['tab']);
57
  $out .= '<div id="posttype-page" class="posttypediv">';
58
- if('category' === $_GET['tab']) {
59
- $out .= $this->show_category_tab($action);
60
- }
61
- else {
62
- $out .= $this->show_option_tab($_GET['tab']);
63
- }
64
  $out .= '
65
  </div>
66
  </div>';
67
  echo $out;
68
  }
69
-
70
  public function embed_settings_scripts() {
71
  wp_enqueue_script('eventlist_admin_settings_js', EL_URL.'admin/js/admin_settings.js');
72
  }
73
-
74
  private function show_tabs($current = 'category') {
75
- $tabs = array('category' => 'Categories', 'general' => 'General');
76
  $out = '<h3 class="nav-tab-wrapper">';
77
  foreach($tabs as $tab => $name){
78
  $class = ($tab == $current) ? ' nav-tab-active' : '';
@@ -82,127 +67,6 @@ class EL_Admin_Settings {
82
  return $out;
83
  }
84
 
85
- private function show_category_tab($action) {
86
- $out = '';
87
- if('edit' === $action && isset($_GET['id'])) {
88
- $out .=$this->show_edit_category_form(__('Edit Category'), __('Update Category'), $this->categories->get_category_data($_GET['id']));
89
- }
90
- else {
91
- // show category table
92
- $out .= $this->show_category_table();
93
- // show add category form
94
- $out .= $this->show_edit_category_form(__('Add New Category'), __('Add New Category'));
95
- }
96
- return $out;
97
- }
98
-
99
- private function check_for_actions_and_show_messages($action) {
100
- $out = '';
101
- if('delete' === $action && isset($_GET['slug'])) {
102
- // delete categories
103
- $slug_array = explode(', ', $_GET['slug']);
104
- $num_affected_events = $this->db->remove_category_in_events($slug_array);
105
- require_once(EL_PATH.'admin/includes/category_table.php');
106
- if($this->categories->remove_categories($slug_array)) {
107
- $out .= '<div id="message" class="updated">
108
- <p><strong>'.sprintf(__('Category "%s" deleted.'), $_GET['slug']);
109
- if($num_affected_events > 0) {
110
- $out .= '<br />'.sprintf(__('This Category was also removed from %d events.'), $num_affected_events);
111
- }
112
- $out .= '</strong></p>
113
- </div>';
114
- }
115
- else {
116
- $out .= '<div id="message" class="error below-h2"><p><strong>Error while deleting category "'.$_GET['slug'].'".</strong></p></div>';
117
- }
118
- }
119
- else if(!empty($_POST)) {
120
- if(!isset($_POST['id'])) {
121
- // add new category
122
- if($this->categories->add_category($_POST)) {
123
- $out .= '<div id="message" class="updated below-h2"><p><strong>New Category "'.$_POST['name'].'" was added.</strong></p></div>';
124
- }
125
- else {
126
- $out .= '<div id="message" class="error below-h2"><p><strong>Error: New Category "'.$_POST['name'].'" could not be added.</strong></p></div>';
127
- }
128
- }
129
- else {
130
- // edit category
131
- if($this->categories->edit_category($_POST, $_POST['id'])) {
132
- $this->db->change_category_slug_in_events($_POST['id'], $_POST['slug']);
133
- $out .= '<div id="message" class="updated below-h2"><p><strong>Category "'.$_POST['id'].'" was modified.</strong></p></div>';
134
- }
135
- else {
136
- $out .= '<div id="message" class="error below-h2"><p><strong>Error: Category "'.$_POST['id'].'" could not be modified.</strong></p></div>';
137
- }
138
- }
139
- }
140
- return $out;
141
- }
142
-
143
- private function show_edit_category_form($title, $button_text, $cat_data=null) {
144
- $is_new_event = (null == $cat_data);
145
- if($is_new_event) {
146
- $cat_data['name'] = '';
147
- $cat_data['slug'] = '';
148
- $cat_data['desc'] = '';
149
- }
150
- $out = '
151
- <div id="col-left">
152
- <div class="col-wrap">
153
- <div class="form-wrap">
154
- <h3>'.$title.'</h3>
155
- <form id="addtag" method="POST" action="?page=el_admin_settings&amp;tab=category">';
156
- if(!$is_new_event) {
157
- $out .= '
158
- <input type="hidden" name="id" value="'.$cat_data['slug'].'">';
159
- }
160
- // Category Name
161
- $out .= '
162
- <div class="form-field form-required"><label for="name">Name: </label>';
163
- $out .= $this->show_text('name', $cat_data['name']);
164
- $out .= '<p>'.__('The name is how it appears on your site.').'</p></div>';
165
- // Category Slug
166
- $out .= '
167
- <div class="form-field"><label for="name">Slug: </label>';
168
- $out .= $this->show_text('slug', $cat_data['slug']);
169
- $out .= '<p>'.__('The “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.').'</p></div>';
170
- // Category Description
171
- $out .= '
172
- <div class="form-field"><label for="name">Description: </label>';
173
- $out .= $this->show_textarea('desc', $cat_data['desc']);
174
- $out .= '</div>
175
- <p class="submit"><input type="submit" class="button-primary" name="add_cat" value="'.$button_text.'" id="submitbutton"></p>';
176
- $out .= '
177
- </form>
178
- </div>
179
- </div>
180
- </div>
181
- </div>';
182
- return $out;
183
- }
184
-
185
- private function show_category_table() {
186
- $out = '
187
- <div id="col-container">
188
- <div id="col-right">
189
- <div class="col-wrap">
190
- <form id="category-filter" method="get">
191
- <input type="hidden" name="page" value="'.$_REQUEST['page'].'" />';
192
- require_once(EL_PATH.'admin/includes/category_table.php');
193
- $category_table = new EL_Category_Table();
194
- $category_table->prepare_items();
195
- ob_start();
196
- $category_table->display();
197
- $out .= ob_get_contents();
198
- ob_end_clean();
199
- $out .= '
200
- </form>
201
- </div>
202
- </div>';
203
- return $out;
204
- }
205
-
206
  private function show_option_tab($section) {
207
  $out = '
208
  <form method="post" action="options.php">
@@ -226,16 +90,16 @@ class EL_Admin_Settings {
226
  <td>';
227
  switch($o['type']) {
228
  case 'checkbox':
229
- $out .= $this->show_checkbox($oname, $this->options->get($oname), $o['caption']);
230
  break;
231
  case 'radio':
232
- $out .= $this->show_radio($oname, $this->options->get($oname), $o['caption']);
233
  break;
234
  case 'text':
235
- $out .= $this->show_text($oname, $this->options->get($oname));
236
  break;
237
  case 'textarea':
238
- $out .= $this->show_textarea($oname, $this->options->get($oname));
239
  break;
240
  }
241
  $out .= '
@@ -255,47 +119,5 @@ class EL_Admin_Settings {
255
  </form>';
256
  return $out;
257
  }
258
-
259
- private function show_checkbox($name, $value, $caption) {
260
- $out = '
261
- <label for="'.$name.'">
262
- <input name="'.$name.'" type="checkbox" id="'.$name.'" value="1"';
263
- if($value == 1) {
264
- $out .= ' checked="checked"';
265
- }
266
- $out .= ' />
267
- '.$caption.'
268
- </label>';
269
- return $out;
270
- }
271
-
272
- private function show_radio($name, $value, $caption) {
273
- $out = '
274
- <fieldset>';
275
- foreach($caption as $okey => $ocaption) {
276
- $checked = ($value === $okey) ? 'checked="checked" ' : '';
277
- $out .= '
278
- <label title="'.$ocaption.'">
279
- <input type="radio" '.$checked.'value="'.$okey.'" name="'.$name.'">
280
- <span>'.$ocaption.'</span>
281
- </label>
282
- <br />';
283
- }
284
- $out .= '
285
- </fieldset>';
286
- return $out;
287
- }
288
-
289
- private function show_text($name, $value) {
290
- $out = '
291
- <input name="'.$name.'" type="text" id="'.$name.'" value="'.$value.'" />';
292
- return $out;
293
- }
294
-
295
- private function show_textarea($name, $value) {
296
- $out = '
297
- <textarea name="'.$name.'" id="'.$name.'" rows="5" class="large-text code">'.$value.'</textarea>';
298
- return $out;
299
- }
300
  }
301
  ?>
3
  exit;
4
  }
5
 
 
6
  require_once(EL_PATH.'includes/options.php');
7
+ require_once(EL_PATH.'admin/includes/admin-functions.php');
8
 
9
  // This class handles all data for the admin settings page
10
  class EL_Admin_Settings {
11
  private static $instance;
 
12
  private $options;
13
+ private $functions;
14
 
15
  public static function &get_instance() {
16
  // Create class instance if required
22
  }
23
 
24
  private function __construct() {
 
25
  $this->options = &EL_Options::get_instance();
26
+ $this->functions = &EL_Admin_Functions::get_instance();
27
  }
28
 
29
  public function show_settings () {
37
  </div>';
38
  }
39
 
 
 
 
 
 
 
 
40
  // normal output
41
  $out.= '<div class="wrap">
42
  <div id="icon-edit-pages" class="icon32"><br /></div><h2>Event List Settings</h2>';
43
  if(!isset($_GET['tab'])) {
44
+ $_GET['tab'] = 'general';
45
  }
46
  $out .= $this->show_tabs($_GET['tab']);
47
  $out .= '<div id="posttype-page" class="posttypediv">';
48
+ $out .= $this->show_option_tab($_GET['tab']);
 
 
 
 
 
49
  $out .= '
50
  </div>
51
  </div>';
52
  echo $out;
53
  }
54
+ /*
55
  public function embed_settings_scripts() {
56
  wp_enqueue_script('eventlist_admin_settings_js', EL_URL.'admin/js/admin_settings.js');
57
  }
58
+ */
59
  private function show_tabs($current = 'category') {
60
+ $tabs = array('general' => 'General');
61
  $out = '<h3 class="nav-tab-wrapper">';
62
  foreach($tabs as $tab => $name){
63
  $class = ($tab == $current) ? ' nav-tab-active' : '';
67
  return $out;
68
  }
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  private function show_option_tab($section) {
71
  $out = '
72
  <form method="post" action="options.php">
90
  <td>';
91
  switch($o['type']) {
92
  case 'checkbox':
93
+ $out .= $this->functions->show_checkbox($oname, $this->options->get($oname), $o['caption']);
94
  break;
95
  case 'radio':
96
+ $out .= $this->functions->show_radio($oname, $this->options->get($oname), $o['caption']);
97
  break;
98
  case 'text':
99
+ $out .= $this->functions->show_text($oname, $this->options->get($oname));
100
  break;
101
  case 'textarea':
102
+ $out .= $this->functions->show_textarea($oname, $this->options->get($oname));
103
  break;
104
  }
105
  $out .= '
119
  </form>';
120
  return $out;
121
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  }
123
  ?>
admin/includes/category_table.php CHANGED
@@ -39,8 +39,6 @@ class EL_Category_Table extends WP_List_Table {
39
  ***************************************************************************/
40
  protected function column_default($item, $column_name) {
41
  switch($column_name){
42
- case 'name' :
43
- return $item[$column_name];
44
  case 'desc' :
45
  return '<div>'.$item[$column_name].'</div>';
46
  case 'slug' :
@@ -62,13 +60,15 @@ class EL_Category_Table extends WP_List_Table {
62
  * @return string Text to be placed inside the column <td> (movie title only)
63
  ***************************************************************************/
64
  protected function column_name($item) {
65
- //Prepare Columns
66
  $actions = array(
67
  'edit' => '<a href="?page='.$_REQUEST['page'].'&amp;id='.$item['slug'].'&amp;action=edit">Edit</a>',
68
  'delete' => '<a href="#" onClick="eventlist_deleteCategory(\''.$item['slug'].'\');return false;">Delete</a>'
69
  );
 
 
70
  //Return the title contents
71
- return '<b>'.$item['name'].'</b>'.$this->row_actions( $actions );
72
  }
73
 
74
  /** ************************************************************************
39
  ***************************************************************************/
40
  protected function column_default($item, $column_name) {
41
  switch($column_name){
 
 
42
  case 'desc' :
43
  return '<div>'.$item[$column_name].'</div>';
44
  case 'slug' :
60
  * @return string Text to be placed inside the column <td> (movie title only)
61
  ***************************************************************************/
62
  protected function column_name($item) {
63
+ // prepare Actions
64
  $actions = array(
65
  'edit' => '<a href="?page='.$_REQUEST['page'].'&amp;id='.$item['slug'].'&amp;action=edit">Edit</a>',
66
  'delete' => '<a href="#" onClick="eventlist_deleteCategory(\''.$item['slug'].'\');return false;">Delete</a>'
67
  );
68
+ // create prefix with indenting according cat level
69
+ $prefix = str_pad('', 7*$item['level'], '&#8212;', STR_PAD_LEFT).' ';
70
  //Return the title contents
71
+ return '<b>'.$prefix.$item['name'].'</b>'.$this->row_actions($actions);
72
  }
73
 
74
  /** ************************************************************************
admin/js/{admin_settings.js → admin_categories.js} RENAMED
@@ -3,6 +3,6 @@
3
  // Confirmation for event deletion
4
  function eventlist_deleteCategory (id) {
5
  if (confirm("Are you sure you want to delete this event category? This is a permanent action.")) {
6
- document.location.href = "?page=el_admin_settings&slug=" + id + "&action=delete";
7
  }
8
  }
3
  // Confirmation for event deletion
4
  function eventlist_deleteCategory (id) {
5
  if (confirm("Are you sure you want to delete this event category? This is a permanent action.")) {
6
+ document.location.href = "?page=el_admin_categories&slug=" + id + "&action=delete";
7
  }
8
  }
event-list.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Event List
4
  Plugin URI: http://wordpress.org/extend/plugins/event-list/
5
  Description: Manage your events and show them in a list view on your site.
6
- Version: 0.4.3
7
  Author: Michael Burtscher
8
  Author URI: http://wordpress.org/extend/plugins/event-list/
9
  License: GPLv2
3
  Plugin Name: Event List
4
  Plugin URI: http://wordpress.org/extend/plugins/event-list/
5
  Description: Manage your events and show them in a list view on your site.
6
+ Version: 0.4.4
7
  Author: Michael Burtscher
8
  Author URI: http://wordpress.org/extend/plugins/event-list/
9
  License: GPLv2
includes/categories.php CHANGED
@@ -31,6 +31,12 @@ class EL_Categories {
31
  $cat_array = (array) $this->options->get( 'el_categories' );
32
  $this->cat_array = array();
33
  foreach( $cat_array as $cat ) {
 
 
 
 
 
 
34
  $this->cat_array[$cat['slug']] = $cat;
35
  }
36
  }
@@ -46,11 +52,13 @@ class EL_Categories {
46
  return false;
47
  }
48
  }
 
 
 
 
49
  if( !isset( $cat_data['slug'] ) || '' == $cat_data['slug'] ) {
50
  $cat_data['slug'] = $cat_data['name'];
51
  }
52
- $cat['name'] = trim( $cat_data['name'] );
53
- $cat['desc'] = isset( $cat_data['desc'] ) ? trim( $cat_data['desc'] ) : '';
54
  // make slug unique
55
  $cat['slug'] = $slug = sanitize_title( $cat_data['slug'] );
56
  $num = 1;
@@ -58,6 +66,20 @@ class EL_Categories {
58
  $num++;
59
  $cat['slug'] = $slug.'-'.$num;
60
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  $this->cat_array[$cat['slug']] = $cat;
62
  return $this->safe_categories();
63
  }
@@ -79,32 +101,82 @@ class EL_Categories {
79
  }
80
 
81
  private function safe_categories() {
82
- if( !sort( $this->cat_array ) ) {
 
83
  return false;
84
  }
85
- if( !$this->options->set( 'el_categories', $this->cat_array ) ) {
86
  return false;
87
  }
88
  return true;
89
  }
90
 
91
- public function get_cat_array() {
92
- return $this->cat_array;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  }
94
 
95
  public function get_category_data($slug) {
96
  return $this->cat_array[$slug];
97
  }
98
 
99
- public function get_category_string( $slugs ) {
100
- if( 2 >= strlen( $slugs ) ) {
101
  return '';
102
  }
103
- $slug_array = explode( '|', substr( $slugs, 1, -1 ) );
104
  $name_array = array();
105
- foreach( $slug_array as $slug ) {
106
  $name_array[] = $this->cat_array[$slug]['name'];
107
  }
108
- return implode( ', ', $name_array );
 
109
  }
110
  }
31
  $cat_array = (array) $this->options->get( 'el_categories' );
32
  $this->cat_array = array();
33
  foreach( $cat_array as $cat ) {
34
+ // check if "parent" field is available (required due to old version without parent field)
35
+ // this can be removed in a later version
36
+ if(!isset($cat['parent']) || !isset($cat['level'])) {
37
+ $cat['parent'] = '';
38
+ $cat['level'] = 0;
39
+ }
40
  $this->cat_array[$cat['slug']] = $cat;
41
  }
42
  }
52
  return false;
53
  }
54
  }
55
+ // set cat name
56
+ $cat['name'] = trim( $cat_data['name'] );
57
+ // set slug
58
+ // generate slug if no slug was given
59
  if( !isset( $cat_data['slug'] ) || '' == $cat_data['slug'] ) {
60
  $cat_data['slug'] = $cat_data['name'];
61
  }
 
 
62
  // make slug unique
63
  $cat['slug'] = $slug = sanitize_title( $cat_data['slug'] );
64
  $num = 1;
66
  $num++;
67
  $cat['slug'] = $slug.'-'.$num;
68
  }
69
+ // set parent and level
70
+ if(!isset($cat_data['parent'])) {
71
+ $cat_data['parent'] = '';
72
+ }
73
+ $cat['parent'] = $cat_data['parent'];
74
+ if('' == $cat['parent']) {
75
+ $cat['level'] = 0;
76
+ }
77
+ else {
78
+ $cat['level'] = $this->cat_array[$cat_data['parent']]['level'] + 1;
79
+ }
80
+ // set description
81
+ $cat['desc'] = isset( $cat_data['desc'] ) ? trim( $cat_data['desc'] ) : '';
82
+ // add category
83
  $this->cat_array[$cat['slug']] = $cat;
84
  return $this->safe_categories();
85
  }
101
  }
102
 
103
  private function safe_categories() {
104
+ $cat_array = $this->get_cat_array('slug', true);
105
+ if(!is_array($cat_array) || empty($cat_array)) {
106
  return false;
107
  }
108
+ if(!$this->options->set('el_categories', $cat_array)) {
109
  return false;
110
  }
111
  return true;
112
  }
113
 
114
+ public function get_cat_array($sort_key='name', $sort_order='asc') {
115
+ return $this->get_cat_child_array('', $sort_key, $sort_order);
116
+ }
117
+
118
+ private function get_cat_child_array($slug, $sort_key, $sort_order) {
119
+ $children = $this->get_children($slug, $sort_key, $sort_order);
120
+ if(empty($children)) {
121
+ return null;
122
+ }
123
+ $ret = array();
124
+ foreach($children as $child) {
125
+ $ret[] = $this->cat_array[$child];
126
+ $grandchilds = $this->get_cat_child_array($child, $sort_key, $sort_order);
127
+ if(is_array($grandchilds)) {
128
+ $ret = array_merge($ret, $grandchilds);
129
+ }
130
+ }
131
+ return $ret;
132
+ }
133
+
134
+ private function get_children($slug='', $sort_key='slug', $sort_order='asc') {
135
+ // create array with slugs
136
+ $ret = array();
137
+ foreach($this->cat_array as $cat) {
138
+ if($slug == $cat['parent']) {
139
+ $ret[] = $cat['slug'];
140
+ }
141
+ }
142
+ // sort array
143
+ if('slug' == $sort_key) {
144
+ if('desc' == $sort_order) {
145
+ rsort($ret);
146
+ }
147
+ else {
148
+ sort($ret);
149
+ }
150
+ return $ret;
151
+ }
152
+ else {
153
+ $sort_key_array = array();
154
+ foreach($ret as $cat_slug) {
155
+ $sort_key_array[] = strtolower($this->cat_array[$cat_slug][$sort_key]);
156
+ }
157
+ asort($sort_key_array);
158
+ $ret_sorted = array();
159
+ foreach($sort_key_array as $key => $value) {
160
+ $ret_sorted[] = $ret[$key];
161
+ }
162
+ return $ret_sorted;
163
+ }
164
  }
165
 
166
  public function get_category_data($slug) {
167
  return $this->cat_array[$slug];
168
  }
169
 
170
+ public function get_category_string($slug_text) {
171
+ if(2 >= strlen($slug_text)) {
172
  return '';
173
  }
174
+ $slug_array = explode('|', substr( $slug_text, 1, -1));
175
  $name_array = array();
176
+ foreach($slug_array as $slug) {
177
  $name_array[] = $this->cat_array[$slug]['name'];
178
  }
179
+ sort($name_array, SORT_STRING);
180
+ return implode(', ', $name_array);
181
  }
182
  }
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: event, events, list, listview, calendar, schedule, shortcode, page, category, categories, admin, attribute, widget, sidebar
5
  Requires at least: 3.3
6
  Tested up to: 3.5.2
7
- Stable tag: 0.4.3
8
  Plugin URI: http://wordpress.org/extend/plugins/event-list
9
  Licence: GPLv2
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -66,6 +66,12 @@ Yes, you can create an instance of the "SC_Event_List" class which located in "i
66
 
67
  == Changelog ==
68
 
 
 
 
 
 
 
69
  = 0.4.3 (2013-07-05) =
70
 
71
  * added possibility to edit existing categories
4
  Tags: event, events, list, listview, calendar, schedule, shortcode, page, category, categories, admin, attribute, widget, sidebar
5
  Requires at least: 3.3
6
  Tested up to: 3.5.2
7
+ Stable tag: 0.4.4
8
  Plugin URI: http://wordpress.org/extend/plugins/event-list
9
  Licence: GPLv2
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
66
 
67
  == Changelog ==
68
 
69
+ = 0.4.4 (2013-07-20) =
70
+
71
+ * added support for sub-categories
72
+ * moved category administration to seperate page
73
+ * improved category sorting
74
+
75
  = 0.4.3 (2013-07-05) =
76
 
77
  * added possibility to edit existing categories