AVH Extended Categories Widgets - Version 4.0.4

Version Description

Download this release

Release Info

Developer petervanderdoes
Plugin Icon wp plugin AVH Extended Categories Widgets
Version 4.0.4
Comparing to
See all releases

Code changes from version 4.0.2 to 4.0.4

Files changed (48) hide show
  1. 2.8/avh-ec.client.php +16 -28
  2. 2.8/class/avh-ec.admin.php +1211 -856
  3. 2.8/class/avh-ec.category-group.php +267 -210
  4. 2.8/class/avh-ec.core.php +576 -493
  5. 2.8/class/avh-ec.widgets.php +970 -711
  6. 2.8/css/avh-ec.admin.css +65 -64
  7. 2.8/css/avh-ec.widget.css +3 -3
  8. 2.8/helpers/avh-forms.php +30 -14
  9. 2.8/js/avh-ec.admin.manualorder.closure.js +0 -1
  10. 2.8/js/avh-ec.admin.manualorder.js +12 -12
  11. 2.8/js/avh-ec.admin.manualorder.min.js +1 -0
  12. 2.8/js/avh-ec.categorygroup.closure.js +0 -1
  13. 2.8/js/avh-ec.categorygroup.js +17 -15
  14. 2.8/js/avh-ec.categorygroup.js.closure.js +0 -1
  15. 2.8/js/avh-ec.categorygroup.min.js +1 -0
  16. 3.3/avh-ec.client.php +18 -30
  17. 3.3/class/avh-ec.admin.php +1223 -870
  18. 3.3/class/avh-ec.category-group.php +269 -216
  19. 3.3/class/avh-ec.core.php +566 -500
  20. 3.3/class/avh-ec.widgets.php +974 -717
  21. 3.3/css/avh-ec.admin.css +69 -69
  22. 3.3/css/avh-ec.widget.css +3 -3
  23. 3.3/helpers/avh-forms.php +30 -14
  24. 3.3/js/avh-ec.admin.manualorder.closure.js +0 -1
  25. 3.3/js/avh-ec.admin.manualorder.js +12 -12
  26. 3.3/js/avh-ec.admin.manualorder.min.js +1 -0
  27. 3.3/js/avh-ec.categorygroup.closure.js +0 -1
  28. 3.3/js/avh-ec.categorygroup.js +17 -15
  29. 3.3/js/avh-ec.categorygroup.min.js +1 -0
  30. 3.6/avh-ec.client.php +44 -53
  31. 3.6/class/avh-ec.admin.php +1837 -1461
  32. 3.6/class/avh-ec.category-group.php +463 -412
  33. 3.6/class/avh-ec.core.php +815 -784
  34. 3.6/class/avh-ec.widgets.php +1212 -965
  35. 3.6/css/avh-ec.admin.css +69 -69
  36. 3.6/css/avh-ec.widget.css +3 -3
  37. 3.6/helpers/avh-common.php +6 -6
  38. 3.6/helpers/avh-forms.php +49 -33
  39. 3.6/js/avh-ec.admin.manualorder.closure.js +0 -1
  40. 3.6/js/avh-ec.admin.manualorder.js +12 -12
  41. 3.6/js/avh-ec.admin.manualorder.min.js +1 -0
  42. 3.6/js/avh-ec.categorygroup.closure.js +0 -1
  43. 3.6/js/avh-ec.categorygroup.js +17 -15
  44. 3.6/js/avh-ec.categorygroup.min.js +1 -0
  45. 4.2/avh-ec.client.php +42 -45
  46. 4.2/class/avh-ec.admin.php +1845 -1983
  47. 4.2/class/avh-ec.category-group.php +474 -512
  48. 4.2/class/avh-ec.core.php +419 -753
2.8/avh-ec.client.php CHANGED
@@ -2,77 +2,65 @@
2
 
3
  /**
4
  * Singleton Class
5
- *
6
  */
7
- class AVH_EC_Singleton
8
- {
9
-
10
  /**
11
- *
12
  * @param $class
13
  * @param $arg1
14
  */
15
- function &getInstance ($class, $arg1 = null)
16
- {
17
  static $instances = array(); // array of instance names
18
  if (array_key_exists($class, $instances)) {
19
- $instance = & $instances[$class];
20
  } else {
21
- if (! class_exists($class)) {
22
  switch ($class) {
23
  case 'AVH_EC_Core':
24
- require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.core.php');
25
  break;
26
  case 'AVH_EC_Category_Group':
27
- require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.category-group.php');
28
  break;
29
  case 'AVH_EC_Widget_Helper_Class':
30
- require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widget-helper.php');
31
  break;
32
  }
33
  }
34
- $instances[$class] = new $class($arg1);
35
- $instance = & $instances[$class];
36
  }
 
37
  return $instance;
38
  } // getInstance
39
  } // singleton
40
 
41
-
42
  /**
43
  * Include the necessary files
44
- *
45
  */
46
- require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/helpers/avh-forms.php');
47
- require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widgets.php');
48
 
49
  /**
50
  * Initialize the plugin
51
- *
52
  */
53
- function avhextendedcategories_init ()
54
- {
55
  // Admin
56
  if (is_admin()) {
57
- require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.admin.php');
58
  $avhec_admin = new AVH_EC_Admin();
59
  }
60
  AVH_EC_Singleton::getInstance('AVH_EC_Core');
61
 
62
  add_action('widgets_init', 'avhextendedcategories_widgets_init');
63
-
64
  } // End avhamazon_init()
65
 
66
-
67
  /**
68
  * Register the widget
69
  *
70
  * @WordPress Action widgets_init
71
- * @since 3.0
72
- *
73
  */
74
- function avhextendedcategories_widgets_init ()
75
- {
76
  register_widget('WP_Widget_AVH_ExtendedCategories_Normal');
77
  register_widget('WP_Widget_AVH_ExtendedCategories_Top');
78
  register_widget('WP_Widget_AVH_ExtendedCategories_Category_Group');
2
 
3
  /**
4
  * Singleton Class
 
5
  */
6
+ class AVH_EC_Singleton {
 
 
7
  /**
 
8
  * @param $class
9
  * @param $arg1
10
  */
11
+ function &getInstance($class, $arg1 = null) {
 
12
  static $instances = array(); // array of instance names
13
  if (array_key_exists($class, $instances)) {
14
+ $instance = &$instances[ $class ];
15
  } else {
16
+ if ( ! class_exists($class)) {
17
  switch ($class) {
18
  case 'AVH_EC_Core':
19
+ require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.core.php');
20
  break;
21
  case 'AVH_EC_Category_Group':
22
+ require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.category-group.php');
23
  break;
24
  case 'AVH_EC_Widget_Helper_Class':
25
+ require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widget-helper.php');
26
  break;
27
  }
28
  }
29
+ $instances[ $class ] = new $class($arg1);
30
+ $instance = &$instances[ $class ];
31
  }
32
+
33
  return $instance;
34
  } // getInstance
35
  } // singleton
36
 
 
37
  /**
38
  * Include the necessary files
 
39
  */
40
+ require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/helpers/avh-forms.php');
41
+ require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widgets.php');
42
 
43
  /**
44
  * Initialize the plugin
 
45
  */
46
+ function avhextendedcategories_init() {
 
47
  // Admin
48
  if (is_admin()) {
49
+ require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.admin.php');
50
  $avhec_admin = new AVH_EC_Admin();
51
  }
52
  AVH_EC_Singleton::getInstance('AVH_EC_Core');
53
 
54
  add_action('widgets_init', 'avhextendedcategories_widgets_init');
 
55
  } // End avhamazon_init()
56
 
 
57
  /**
58
  * Register the widget
59
  *
60
  * @WordPress Action widgets_init
61
+ * @since 3.0
 
62
  */
63
+ function avhextendedcategories_widgets_init() {
 
64
  register_widget('WP_Widget_AVH_ExtendedCategories_Normal');
65
  register_widget('WP_Widget_AVH_ExtendedCategories_Top');
66
  register_widget('WP_Widget_AVH_ExtendedCategories_Category_Group');
2.8/class/avh-ec.admin.php CHANGED
@@ -1,39 +1,35 @@
1
  <?php
2
 
3
- class AVH_EC_Admin
4
- {
5
  /**
6
- *
7
- * @var AVH_EC_Core
8
- */
9
- var $core;
10
-
11
- /**
12
- *
13
  * @var AVH_EC_Category_Group
14
  */
15
  var $catgrp;
16
-
 
 
 
17
  var $hooks = array();
18
  var $message;
19
 
20
  /**
21
  * PHP5 constructor
22
- *
23
  */
24
- function __construct ()
25
- {
26
 
27
  // Initialize the plugin
28
- $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core');
29
- $this->catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
30
 
31
  add_action('wp_ajax_delete-group', array(&$this, 'ajaxDeleteGroup'));
32
 
33
  // Admin menu
34
- add_action('admin_init', array(&$this,'actionAdminInit'));
35
  add_action('admin_menu', array(&$this, 'actionAdminMenu'));
36
- add_filter('plugin_action_links_extended-categories-widget/widget_extended_categories.php', array(&$this, 'filterPluginActions'), 10, 2);
 
 
 
37
 
38
  // Actions used for editing posts
39
  add_action('load-post.php', array(&$this, 'actionLoadPostPage'));
@@ -51,92 +47,105 @@ class AVH_EC_Admin
51
 
52
  /**
53
  * PHP4 Constructor
54
- *
55
  */
56
- function AVH_EC_Admin ()
57
- {
58
  $this->__construct();
59
  }
60
 
61
  function actionAdminInit() {
62
  if (is_admin() && isset($_GET['taxonomy']) && 'category' == $_GET['taxonomy']) {
63
- add_action($_GET['taxonomy'] . '_edit_form', array(&$this,'displayCategoryGroupForm'), 10, 2 );
64
  }
65
- add_action('edit_term', array(&$this,'handleEditTerm'), 10, 3 );
66
-
67
  }
68
 
69
  /**
 
70
  *
71
- * Adds Category Group form
72
- * @WordPress action category_edit_form
73
- *
74
- * @param unknown_type $term
75
- * @param unknown_type $taxonomy
76
  */
77
- function displayCategoryGroupForm($term, $taxonomy){
78
 
79
- $current_selection = '';
80
- $tax_meta = get_option($this->core->db_options_tax_meta);
81
- if ( isset($tax_meta[$taxonomy][$term->term_id]) ) {
82
- $tax_meta = $tax_meta[$taxonomy][$term->term_id];
83
- $current_selection = $tax_meta['category_group_term_id'];
84
- }
 
 
 
 
 
 
 
 
 
 
 
85
 
86
- if (empty($current_selection)) {
87
- $current_group = $this->catgrp->getGroupByCategoryID($term->term_id);
88
- $current_selection= $current_group->term_id;
89
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
 
91
- $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty'=>FALSE));
92
- foreach ($cat_groups as $group) {
93
- $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit');
94
- $dropdown_value[] = $group->term_id;
95
- $dropdown_text[] = $temp_cat->name;
96
- }
97
 
98
- foreach ( $dropdown_value as $key => $sel) {
99
- $seldata .= '<option value="' . esc_attr($sel) . '" ' . (($current_selection == $sel) ? 'selected="selected"' : '') . ' >' . esc_html(ucfirst($dropdown_text[$key])) . '</option>' . "\n";
100
- }
101
 
102
- echo '<h3>AVH Extended Categories - Category Group Widget</h3>';
103
- echo '<table class="form-table"><tbody>';
104
- echo '<tr class="form-field">';
105
- echo '<th valign="top" scope="row">';
106
- echo '<label for="avhec_categorygroup">Category Group</label></th>';
107
- echo '<td>';
108
- echo '<select id="avhec_categorygroup" name="avhec_categorygroup">';
109
- echo $seldata;
110
- echo '</select>';
111
- echo '<p class="description">Select the category group to show on the archive page.</p>';
112
- echo '</td>';
113
- echo '</tr>';
114
- echo '</tbody></table>';
115
- }
116
 
117
- /**
118
- * Saves the association Category - Category Group fron the edit taxonomy page
119
- * @WordPress action edit_form.
120
- *
121
- * @param unknown_type $term_id
122
- * @param unknown_type $tt_id
123
- * @param unknown_type $taxonomy
124
- */
125
- function handleEditTerm( $term_id, $tt_id, $taxonomy ) {
126
- $tax_meta = get_option($this->core->db_options_tax_meta);
127
- if ( isset($_POST['avhec_categorygroup']) && $tax_meta[$taxonomy][$term_id]['category_group_term_id'] != $_POST['avhec_categorygroup']) {
128
- $tax_meta[$taxonomy][$term_id]['category_group_term_id'] = $_POST['avhec_categorygroup'];
129
- update_option($this->core->db_options_tax_meta, $tax_meta);
130
- }
131
  }
132
 
133
  /**
134
  * When a category is created this function is called to add the new category to the group all
 
135
  * @param $term_id
136
  * @param $term_taxonomy_id
137
  */
138
- function actionCreatedCategory ($term_id, $term_taxonomy_id)
139
- {
140
  $group_id = $this->catgrp->getTermIDBy('slug', 'all');
141
  $this->catgrp->setCategoriesForGroup($group_id, (array) $term_id);
142
  }
@@ -145,75 +154,74 @@ class AVH_EC_Admin
145
  * When a category is deleted this function is called so the category is deleted from every group as well.
146
  *
147
  * @param object $term
148
- * @param int $term_taxonomy_id
149
  */
150
- function actionDeleteCategory ($term_id, $term_taxonomy_id)
151
- {
152
  $this->catgrp->doDeleteCategoryFromGroup($term_id);
153
  }
154
 
155
  /**
156
- * Enqueues the style on the post.php and page.php pages
157
- * @WordPress Action load-$pagenow
158
- *
159
- */
160
- function actionLoadPostPage ()
161
- {
162
- wp_enqueue_style('avhec-admin-css');
163
- }
164
-
165
- /**
166
- * Add the Tools and Options to the Management and Options page repectively
167
- *
168
- * @WordPress Action admin_menu
169
- *
170
  */
171
- function actionAdminMenu ()
172
- {
173
-
174
- // Register Style and Scripts
175
- $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.closure';
176
- wp_register_script('avhec-categorygroup-js', AVHEC_PLUGIN_URL . '/js/avh-ec.categorygroup' . $suffix . '.js', array('jquery'), $this->core->version, true);
177
- wp_register_script('avhec-manualorder', AVHEC_PLUGIN_URL . '/js/avh-ec.admin.manualorder' . $suffix . '.js', array ( 'jquery-ui-sortable' ), $this->core->version, false);
178
- wp_register_style('avhec-admin-css', AVHEC_PLUGIN_URL . '/css/avh-ec.admin.css', array('wp-admin'), $this->core->version, 'screen');
179
 
180
- // Add menu system
181
- $folder = $this->core->getBaseDirectory(AVHEC_PLUGIN_DIR);
182
- add_menu_page('AVH Extended Categories', 'AVH Extended Categories', 'manage_options', $folder, array(&$this, 'doMenuOverview'));
183
- $this->hooks['menu_overview'] = add_submenu_page($folder, 'AVH Extended Categories: ' . __('Overview', 'avh-ec'), __('Overview', 'avh-ec'), 'manage_options', $folder, array(&$this, 'doMenuOverview'));
184
- $this->hooks['menu_general'] = add_submenu_page($folder, 'AVH Extended Categories: ' . __('General Options', 'avh-ec'), __('General Options', 'avh-ec'), 'manage_options', 'avhec-general', array(&$this, 'doMenuGeneral'));
185
- $this->hooks['menu_category_groups'] = add_submenu_page($folder, 'AVH Extended Categories: ' . __('Category Groups', 'avh-ec'), __('Category Groups', 'avh-ec'), 'manage_options', 'avhec-grouped', array(&$this, 'doMenuCategoryGroup'));
186
- $this->hooks['menu_manual_order'] = add_submenu_page($folder, 'AVH Extended Categories: ' . __('Manually Order', 'avh-ec'), __('Manually Order', 'avh-ec'), 'manage_options', 'avhec-manual-order', array(&$this, 'doMenuManualOrder'));
187
- $this->hooks['menu_faq'] = add_submenu_page($folder, 'AVH Extended Categories:' . __('F.A.Q', 'avh-ec'), __('F.A.Q', 'avh-ec'), 'manage_options', 'avhec-faq', array(&$this, 'doMenuFAQ'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
 
189
- // Add actions for menu pages
190
- // Overview Menu
191
- add_action('load-' . $this->hooks['menu_overview'], array(&$this, 'actionLoadPageHook_Overview'));
 
192
 
193
- // General Options Menu
194
- add_action('load-' . $this->hooks['menu_general'], array(&$this, 'actionLoadPageHook_General'));
195
 
196
- // Category Groups Menu
197
- add_action('load-' . $this->hooks['menu_category_groups'], array(&$this, 'actionLoadPageHook_CategoryGroup'));
198
 
199
- // FAQ Menu
200
- add_action('load-' . $this->hooks['menu_faq'], array(&$this, 'actionLoadPageHook_faq'));
201
  }
202
 
203
  /**
204
- * Setup everything needed for the Overview page
205
- *
206
  */
207
- function actionLoadPageHook_Overview ()
208
- {
209
  // Add metaboxes
210
- add_meta_box('avhecBoxCategoryGroupList', __('Group Overview', 'avh-ec'), array(&$this, 'metaboxCategoryGroupList'), $this->hooks['menu_overview'], 'normal', 'core');
211
- add_meta_box('avhecBoxTranslation', __('Translation', 'avh-ec'), array(&$this, 'metaboxTranslation'), $this->hooks['menu_overview'], 'normal', 'core');
212
-
213
- if (AVH_Common::getWordpressVersion() >= 3.1 ) {
214
- add_screen_option('layout_columns', array('max' => 2, 'default' => 2) );
 
 
 
 
215
  } else {
216
- add_filter('screen_layout_columns', array ( &$this, 'filterScreenLayoutColumns' ), 10, 2);
217
  }
218
 
219
  // WordPress core Scripts
@@ -221,75 +229,67 @@ class AVH_EC_Admin
221
  wp_enqueue_script('wp-lists');
222
  wp_enqueue_script('postbox');
223
 
224
- // Plugin Scripts
225
- wp_enqueue_script('avhec-categorygroup-js');
226
-
227
  // WordPress core Styles
228
  wp_admin_css('css/dashboard');
229
 
230
- // Plugin Style
231
  wp_enqueue_style('avhec-admin-css');
232
  }
233
 
234
  /**
235
- * Menu Page Overview
236
- *
237
- * @return none
238
  */
239
- function doMenuOverview ()
240
- {
241
- global $screen_layout_columns;
242
 
243
- // This box can't be unselectd in the the Screen Options
244
- add_meta_box('avhecBoxAnnouncements', __('Announcements', 'avh-ec'), array(&$this, 'metaboxAnnouncements'), $this->hooks['menu_overview'], 'side', '');
245
- add_meta_box('avhecBoxDonations', __('Donations', 'avh-ec'), array(&$this, 'metaboxDonations'), $this->hooks['menu_overview'], 'side', '');
 
 
 
246
 
247
- $hide2 = '';
248
- switch ($screen_layout_columns) {
249
- case 2:
250
- $width = 'width:49%;';
251
- break;
252
- default:
253
- $width = 'width:98%;';
254
- $hide2 = 'display:none;';
255
  }
256
 
257
- echo '<div class="wrap avhec-metabox-wrap">';
258
- echo $this->displayIcon('index');
259
- echo '<h2>' . 'AVH Extended Categories - ' . __('Overview', 'avh-ec') . '</h2>';
260
- echo ' <div id="dashboard-widgets-wrap">';
261
- echo ' <div id="dashboard-widgets" class="metabox-holder">';
262
- echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
263
- do_meta_boxes($this->hooks['menu_overview'], 'normal', '');
264
- echo " </div>";
265
- echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n";
266
- do_meta_boxes($this->hooks['menu_overview'], 'side', '');
267
- echo ' </div>';
268
- echo ' </div>';
269
-
270
- echo '<br class="clear"/>';
271
- echo ' </div>'; //dashboard-widgets-wrap
272
- echo '</div>'; // wrap
273
 
 
 
274
 
275
- $this->printMetaboxGeneralNonces();
276
- $this->printMetaboxJS('overview');
277
- $this->printAdminFooter();
278
  }
279
 
280
  /**
281
- * Setup everything needed for the General Options page
282
- *
283
  */
284
- function actionLoadPageHook_General ()
285
- {
286
  // Add metaboxes
287
- add_meta_box('avhecBoxOptions', __('Options', 'avh-ec'), array(&$this, 'metaboxOptions'), $this->hooks['menu_general'], 'normal', 'core');
288
-
289
- if (AVH_Common::getWordpressVersion() >= 3.1 ) {
290
- add_screen_option('layout_columns', array('max' => 2, 'default' => 2) );
 
 
 
 
 
 
 
 
 
 
 
291
  } else {
292
- add_filter('screen_layout_columns', array ( &$this, 'filterScreenLayoutColumns' ), 10, 2);
293
  }
294
 
295
  // WordPress core Scripts
@@ -297,174 +297,161 @@ class AVH_EC_Admin
297
  wp_enqueue_script('wp-lists');
298
  wp_enqueue_script('postbox');
299
 
 
 
 
300
  // WordPress core Styles
301
  wp_admin_css('css/dashboard');
302
 
303
- // Plugin Style and Scripts
304
  wp_enqueue_style('avhec-admin-css');
305
-
306
  }
307
 
308
  /**
309
- * Menu Page General Options
310
- *
311
- * @return none
312
  */
313
- function doMenuGeneral ()
314
- {
315
- global $screen_layout_columns;
316
-
317
- $groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty'=>FALSE));
318
- foreach ($groups as $group) {
319
- $group_id[] = $group->term_id;
320
- $groupname[] = $group->name;
 
 
 
 
 
 
 
 
 
 
 
321
  }
322
 
323
- $options_general[] = array('avhec[general][alternative_name_select_category]', __('<em>Select Category</em> Alternative', 'avh-ec'), 'text', 20, __('Alternative text for Select Category.', 'avh-ec'));
324
- $options_general[] = array('avhec[cat_group][home_group]', 'Home Group', 'dropdown', $group_id, $groupname, __('Select which group to show on the home page.', 'avh-ec') . '<br />' . __('Selecting the group \'none\' will not show the widget on the page.', 'avh-ec'));
325
- $options_general[] = array('avhec[cat_group][no_group]', 'Nonexistence Group', 'dropdown', $group_id, $groupname, __('Select which group to show when there is no group associated with the post.', 'avh-ec') . '<br />' . __('Selecting the group \'none\' will not show the widget on the page.', 'avh-ec'));
326
- $options_general[] = array('avhec[cat_group][default_group]', 'Default Group', 'dropdown', $group_id, $groupname, __('Select which group will be the default group when editing a post.', 'avh-ec') . '<br />' . __('Selecting the group \'none\' will not show the widget on the page.', 'avh-ec'));
327
 
328
- if (isset($_POST['updateoptions'])) {
329
- check_admin_referer('avh_ec_generaloptions');
330
 
331
- $formoptions = $_POST['avhec'];
332
- $options = $this->core->getOptions();
 
333
 
334
- //$all_data = array_merge( $options_general );
335
- $all_data = $options_general;
336
- foreach ($all_data as $option) {
337
- $section = substr($option[0], strpos($option[0], '[') + 1);
338
- $section = substr($section, 0, strpos($section, ']['));
339
- $option_key = rtrim($option[0], ']');
340
- $option_key = substr($option_key, strpos($option_key, '][') + 2);
 
341
 
342
- switch ($section) {
343
- case 'general':
344
- case 'cat_group':
345
- $current_value = $options[$section][$option_key];
346
- break;
347
- }
348
- // Every field in a form is set except unchecked checkboxes. Set an unchecked checkbox to 0.
349
- $newval = (isset($formoptions[$section][$option_key]) ? attribute_escape($formoptions[$section][$option_key]) : 0);
350
- if ($newval != $current_value) { // Only process changed fields.
351
- switch ($section) {
352
- case 'general':
353
- case 'cat_group':
354
- $options[$section][$option_key] = $newval;
355
- break;
356
- }
357
- }
358
- }
359
- $this->core->saveOptions($options);
360
- $this->message = __('Options saved', 'avh-ec');
361
- $this->status = 'updated fade';
362
 
 
 
363
  }
364
- $this->displayMessage();
365
-
366
- $actual_options = $this->core->getOptions();
367
- foreach ($actual_options['cat_group'] as $key => $value) {
368
- if (! (in_array($value, (array) $group_id))) {
369
- $actual_options['cat_group'][$key] = $this->catgrp->getTermIDBy('slug', 'none');
370
- }
371
  }
372
 
373
- $hide2 = '';
374
- switch ($screen_layout_columns) {
375
- case 2:
376
- $width = 'width:49%;';
377
- break;
378
- default:
379
- $width = 'width:98%;';
380
- $hide2 = 'display:none;';
381
  }
382
- $data['options_general'] = $options_general;
383
- $data['actual_options'] = $actual_options;
384
-
385
- // This box can't be unselectd in the the Screen Options
386
- add_meta_box('avhecBoxDonations', __('Donations', 'avh-ec'), array(&$this, 'metaboxDonations'), $this->hooks['menu_general'], 'side', 'core');
387
 
388
- $hide2 = '';
389
- switch ($screen_layout_columns) {
390
- case 2:
391
- $width = 'width:49%;';
392
- break;
393
- default:
394
- $width = 'width:98%;';
395
- $hide2 = 'display:none;';
396
- }
397
-
398
- echo '<div class="wrap avhec-metabox-wrap">';
399
- echo $this->displayIcon('index');
400
- echo '<h2>' . 'AVH Extended Categories - ' . __('General Options', 'avh-ec') . '</h2>';
401
- echo '<form name="avhec-generaloptions" id="avhec-generaloptions" method="POST" action="' . admin_url('admin.php?page=avhec-general') . '" accept-charset="utf-8" >';
402
- wp_nonce_field('avh_ec_generaloptions');
403
 
404
- echo ' <div id="dashboard-widgets-wrap">';
405
- echo ' <div id="dashboard-widgets" class="metabox-holder">';
406
- echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
407
- do_meta_boxes($this->hooks['menu_general'], 'normal', $data);
408
- echo " </div>";
409
- echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n";
410
- do_meta_boxes($this->hooks['menu_general'], 'side', $data);
411
- echo ' </div>';
412
- echo ' </div>';
413
 
414
- echo '<br class="clear"/>';
415
- echo ' </div>'; //dashboard-widgets-wrap
416
- echo '<p class="submit"><input class="button" type="submit" name="updateoptions" value="' . __('Save Changes', 'avhf-ec') . '" /></p>';
417
- echo '</form>';
418
 
419
- echo '</div>'; // wrap
 
 
 
 
 
420
 
 
 
 
 
 
 
 
 
 
 
421
 
422
- $this->printMetaboxGeneralNonces();
423
- $this->printMetaboxJS('general');
424
- $this->printAdminFooter();
 
 
 
 
 
 
 
 
 
 
425
  }
426
 
427
  /**
428
- * Options Metabox
429
  *
 
430
  */
431
- function metaboxOptions ($data)
432
- {
433
- echo $this->printOptions($data['options_general'], $data['actual_options']);
434
  }
435
 
436
  /**
437
- * Setup everything needed for the Category Group page
438
- *
439
  */
440
- function actionLoadPageHook_CategoryGroup ()
441
- {
442
-
443
- // Add metaboxes
444
- add_meta_box('avhecBoxCategoryGroupAdd', __('Add Group', 'avh-ec'), array(&$this, 'metaboxCategoryGroupAdd'), $this->hooks['menu_category_groups'], 'normal', 'core');
445
- add_meta_box('avhecBoxCategoryGroupList', __('Group Overview', 'avh-ec'), array(&$this, 'metaboxCategoryGroupList'), $this->hooks['menu_category_groups'], 'side', 'core');
446
- add_meta_box('avhecBoxCategoryGroupSpecialPages', __('Special Pages', 'avh-ec'), array(&$this, 'metaboxCategoryGroupSpecialPages'), $this->hooks['menu_category_groups'], 'normal', 'core');
447
-
448
- if (AVH_Common::getWordpressVersion() >= 3.1 ) {
449
- add_screen_option('layout_columns', array('max' => 2, 'default' => 2) );
450
- } else {
451
- add_filter('screen_layout_columns', array ( &$this, 'filterScreenLayoutColumns' ), 10, 2);
452
  }
453
-
454
- // WordPress core Scripts
455
- wp_enqueue_script('common');
456
- wp_enqueue_script('wp-lists');
457
- wp_enqueue_script('postbox');
458
-
459
- // Plugin Scripts
460
- wp_enqueue_script('avhec-categorygroup-js');
461
-
462
- // WordPress core Styles
463
- wp_admin_css('css/dashboard');
464
-
465
- // Plugin Style
466
- wp_enqueue_style('avhec-admin-css');
467
-
468
  }
469
 
470
  /**
@@ -472,71 +459,145 @@ class AVH_EC_Admin
472
  *
473
  * @return none
474
  */
475
- function doMenuCategoryGroup ()
476
- {
477
  global $screen_layout_columns;
478
 
479
- $data_add_group_default = array('name'=>'', 'slug'=>'', 'widget_title'=>'', 'description'=>'');
480
- $data_add_group_new = $data_add_group_default;
481
-
482
- $options_add_group[] = array('avhec_add_group[add][name]', __('Group Name', 'avh-ec'), 'text', 20, __('The name is used to identify the group.', 'avh-ec'));
483
- $options_add_group[] = array('avhec_add_group[add][slug]', __('Slug Group', 'avh-ec'), 'text', 20, __('The “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.', 'avh-ec'));
484
- $options_add_group[] = array('avhec_add_group[add][widget_title]', __('Widget Title', 'avh-ec'), 'text', 20, __('When no title is given in the widget options, this will used as the title of the widget when this group is shown.', 'avh-ec'));
485
- $options_add_group[] = array('avhec_add_group[add][description]', __('Description', 'avh-ec'), 'textarea', 40, __('Description is not prominent by default.', 'avh-ec'), 5);
486
-
487
- $options_edit_group[] = array('avhec_edit_group[edit][name]', __('Group Name', 'avh-ec'), 'text', 20, __('The name is used to identify the group.', 'avh-ec'));
488
- $options_edit_group[] = array('avhec_edit_group[edit][slug]', __('Slug Group', 'avh-ec'), 'text', 20, __('The “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.', 'avh-ec'));
489
- $options_edit_group[] = array('avhec_edit_group[edit][widget_title]', __('Widget Title', 'avh-ec'), 'text', 20, __('When no title is given in the widget options, this will used as the title of the widget when this group is shown.', 'avh-ec'));
490
- $options_edit_group[] = array('avhec_edit_group[edit][description]', __('Description', 'avh-ec'), 'textarea', 40, __('Description is not prominent by default.', 'avh-ec'), 5);
491
- $options_edit_group[] = array('avhec_edit_group[edit][categories]', __('Categories', 'avh-ec'), 'catlist', 0, __('Select categories to be included in the group.', 'avh-ec'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
492
 
493
  if (isset($_POST['addgroup'])) {
494
  check_admin_referer('avh_ec_addgroup');
495
 
496
  $formoptions = $_POST['avhec_add_group'];
497
 
498
- $data_add_group_new['name'] = $formoptions['add']['name'];
499
- $data_add_group_new['slug'] = empty($formoptions['add']['slug']) ? sanitize_title($data_add_group_new['name']) : sanitize_title($formoptions['add']['slug']);
500
  $data_add_group_new['widget_title'] = $formoptions['add']['widget_title'];
501
- $data_add_group_new['description'] = $formoptions['add']['description'];
502
 
503
  $id = $this->catgrp->getTermIDBy('slug', $data_add_group_new['slug']);
504
- if (! $id) {
505
- $group_id = $this->catgrp->doInsertGroup($data_add_group_new['name'], array('description'=>$data_add_group_new['description'], 'slug'=>$data_add_group_new['slug']), $data_add_group_new['widget_title']);
 
 
 
 
 
506
  $this->catgrp->setCategoriesForGroup($group_id);
507
- $this->message = __('Category group saved', 'avh-ec');
508
- $this->status = 'updated fade';
509
  $data_add_group_new = $data_add_group_default;
510
-
511
  } else {
512
- $group = $this->catgrp->getGroup($id);
513
  $this->message = __('Category group conflicts with ', 'avh-ec') . $group->name;
514
  $this->message .= '<br />' . __('Same slug is used. ', 'avh-ec');
515
  $this->status = 'error';
516
-
517
  }
518
  $this->displayMessage();
519
  }
520
  $data_add_group['add'] = $data_add_group_new;
521
- $data['add'] = array('form'=>$options_add_group, 'data'=>$data_add_group);
522
 
523
  if (isset($_GET['action'])) {
524
  $action = $_GET['action'];
525
 
526
  switch ($action) {
527
  case 'edit':
528
- $group_id = (int) $_GET['group_ID'];
529
- $group = $this->catgrp->getGroup($group_id);
530
  $widget_title = $this->catgrp->getWidgetTitleForGroup($group_id);
531
- $cats = $this->catgrp->getCategoriesFromGroup($group_id);
532
-
533
- $data_edit_group['edit'] = array('group_id'=>$group_id, 'name'=>$group->name, 'slug'=>$group->slug, 'widget_title'=>$widget_title, 'description'=>$group->description, 'categories'=>$cats);
534
- $data['edit'] = array('form'=>$options_edit_group, 'data'=>$data_edit_group);
535
-
536
- add_meta_box('avhecBoxCategoryGroupEdit', __('Edit Group', 'avh-ec') . ': ' . $group->name, array(&$this, 'metaboxCategoryGroupEdit'), $this->hooks['menu_category_groups'], 'normal', 'low');
 
 
 
 
 
 
 
 
 
 
 
 
537
  break;
538
  case 'delete':
539
- if (! isset($_GET['group_ID'])) {
540
  wp_redirect($this->getBackLink());
541
  exit();
542
  }
@@ -544,7 +605,7 @@ class AVH_EC_Admin
544
  $group_id = (int) $_GET['group_ID'];
545
  check_admin_referer('delete-avhecgroup_' . $group_id);
546
 
547
- if (! current_user_can('manage_categories')) {
548
  wp_die(__('Cheatin&#8217; uh?'));
549
  }
550
  $this->catgrp->doDeleteGroup($group_id);
@@ -558,15 +619,22 @@ class AVH_EC_Admin
558
  if (isset($_POST['editgroup'])) {
559
  check_admin_referer('avh_ec_editgroup');
560
 
561
- $formoptions = $_POST['avhec_edit_group'];
562
  $selected_categories = $_POST['post_category'];
563
 
564
  $group_id = (int) $_POST['avhec-group_id'];
565
- $result = $this->catgrp->doUpdateGroup($group_id, array('name'=>$formoptions['edit']['name'], 'slug'=>$formoptions['edit']['slug'], 'description'=>$formoptions['edit']['description']), $selected_categories, $formoptions['edit']['widget_title']);
 
 
 
 
 
 
 
566
  switch ($result) {
567
  case 1:
568
  $this->message = __('Category group updated', 'avh-ec');
569
- $this->status = 'updated fade';
570
  break;
571
  case 0:
572
  $this->message = __('Category group not updated', 'avh-ec');
@@ -575,7 +643,7 @@ class AVH_EC_Admin
575
  break;
576
  case - 1:
577
  $this->message = __('Unknown category group', 'avh-ec');
578
- $this->status = 'error';
579
  break;
580
  }
581
  $this->displayMessage();
@@ -597,36 +665,76 @@ class AVH_EC_Admin
597
  check_admin_referer('avh_ec_specialpagesgroup');
598
 
599
  $formoptions = $_POST['avhec_special_pages'];
600
- $formdata = $formoptions['sp'];
601
  foreach ($formdata as $key => $value) {
602
- $data_special_pages_new[$key] = $value;
603
  }
604
  $this->core->options['sp_cat_group'] = $data_special_pages_new;
605
  $this->core->saveOptions($this->core->options);
606
-
607
  }
608
  $data_special_pages['sp'] = $data_special_pages_new;
609
- $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty'=>FALSE));
610
 
611
  foreach ($cat_groups as $group) {
612
- $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit');
613
  $dropdown_value[] = $group->term_id;
614
- $dropdown_text[] = $temp_cat->name;
615
  }
616
- $options_special_pages[] = array('avhec_special_pages[sp][home_group]', __('Home page', 'avh-ec'), 'dropdown', $dropdown_value, $dropdown_text, sprintf(__('Select which category to show on the %s page.','avh-ec'),__('home','avhec')));
 
 
 
 
 
 
 
617
  //$options_special_pages[] = array('avhec_special_pages[sp][category_group]', __('Category Archive', 'avh-ec'), 'dropdown', $dropdown_value, $dropdown_text, sprintf(__('Select which category to show on the %s page.','avh-ec'),__('category archive','avhec')));
618
- $options_special_pages[] = array('avhec_special_pages[sp][day_group]', __('Daily Archive', 'avh-ec'), 'dropdown', $dropdown_value, $dropdown_text, sprintf(__('Select which category to show on the %s page.','avh-ec'),__('daily archive','avhec')));
619
- $options_special_pages[] = array('avhec_special_pages[sp][month_group]', __('Monthly Archive', 'avh-ec'), 'dropdown', $dropdown_value, $dropdown_text, sprintf(__('Select which category to show on the %s page.','avh-ec'),__('monthly archive','avhec')));
620
- $options_special_pages[] = array('avhec_special_pages[sp][year_group]', __('Yearly Archive', 'avh-ec'), 'dropdown', $dropdown_value, $dropdown_text, sprintf(__('Select which category to show on the %s page.','avh-ec'),__('yearly archive','avhec')));
621
- $options_special_pages[] = array('avhec_special_pages[sp][author_group]', __('Author Archive', 'avh-ec'), 'dropdown', $dropdown_value, $dropdown_text, sprintf(__('Select which category to show on the %s page.','avh-ec'),__('author archive','avhec')));
622
- $options_special_pages[] = array('avhec_special_pages[sp][search_group]', __('Search Page', 'avh-ec'), 'dropdown', $dropdown_value, $dropdown_text, sprintf(__('Select which category to show on the %s page.','avh-ec'),__('search','avhec')));
623
-
624
- $data['sp'] = array('form'=>$options_special_pages, 'data'=>$data_special_pages);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
625
 
626
  // This box can't be unselectd in the the Screen Options
627
  //add_meta_box( 'avhecBoxDonations', __( 'Donations', 'avh-ec' ), array (&$this, 'metaboxDonations' ), $this->hooks['menu_category_groups'], 'side', 'core' );
628
 
629
-
630
  echo '<div class="wrap avhec-metabox-wrap">';
631
  echo $this->displayIcon('index');
632
  echo '<h2>' . 'AVH Extended Categories - ' . __('Category Groups', 'avh-ec') . '</h2>';
@@ -647,128 +755,33 @@ class AVH_EC_Admin
647
  echo ' </div>'; //dashboard-widgets-wrap
648
  echo '</div>'; // wrap
649
 
650
-
651
  $this->printMetaboxGeneralNonces();
652
  $this->printMetaboxJS('grouped');
653
  $this->printAdminFooter();
654
  }
655
 
656
  /**
657
- * Metabox for Adding a group
658
- * @param $data
659
- */
660
- function metaboxCategoryGroupAdd ($data)
661
- {
662
- echo '<form name="avhec-addgroup" id="avhec-addgroup" method="POST" action="' . $this->getBackLink() . '" accept-charset="utf-8" >';
663
- wp_nonce_field('avh_ec_addgroup');
664
- echo $this->printOptions($data['add']['form'], $data['add']['data']);
665
- echo '<p class="submit"><input class="button" type="submit" name="addgroup" value="' . __('Add group', 'avh-ec') . '" /></p>';
666
- echo '</form>';
667
- }
668
-
669
- /**
670
- * Metabox for showing the groups as a list
671
- *
672
- * @param $data
673
- */
674
- function metaboxCategoryGroupList ($data)
675
- {
676
- echo '<form id="posts-filter" action="" method="get">';
677
-
678
- echo '<div class="clear"></div>';
679
-
680
- echo '<table class="widefat fixed" cellspacing="0">';
681
- echo '<thead>';
682
- echo '<tr>';
683
- print_column_headers('categories_group');
684
- echo '</tr>';
685
- echo '</thead>';
686
-
687
- echo '<tfoot>';
688
- echo '<tr>';
689
- print_column_headers('categories_group', false);
690
- echo '</tr>';
691
- echo '</tfoot>';
692
-
693
- echo '<tbody id="the-list" class="list:group">';
694
- $this->printCategoryGroupRows();
695
- echo '</tbody>';
696
- echo '</table>';
697
-
698
- echo '<br class="clear" />';
699
- echo '</form>';
700
-
701
- //echo '</div>';
702
- }
703
-
704
- /**
705
- * Metabox Category Group Edit
706
- *
707
- */
708
- function metaboxCategoryGroupEdit ($data)
709
- {
710
- echo '<form name="avhec-editgroup" id="avhec-editgroup" method="POST" action="' . $this->getBackLink() . '" accept-charset="utf-8" >';
711
- wp_nonce_field('avh_ec_editgroup');
712
- echo $this->printOptions($data['edit']['form'], $data['edit']['data']);
713
- echo '<input type="hidden" value="' . $data['edit']['data']['edit']['group_id'] . '" name="avhec-group_id" id="avhec-group_id">';
714
- echo '<p class="submit"><input class="button" type="submit" name="editgroup" value="' . __('Update group', 'avh-ec') . '" /></p>';
715
- echo '</form>';
716
- }
717
-
718
- /**
719
- * Metabox Category Group Special pages
720
- *
721
- */
722
- function metaboxCategoryGroupSpecialPages ($data)
723
- {
724
- echo '<form name="avhec-specialpagesgroup" id="avhec-specialpagesgroup" method="POST" action="' . $this->getBackLink() . '" accept-charset="utf-8" >';
725
- wp_nonce_field('avh_ec_specialpagesgroup');
726
- echo $this->printOptions($data['sp']['form'], $data['sp']['data']);
727
- echo '<p class="submit"><input class="button" type="submit" name="spgroup" value="' . __('Save settings', 'avh-ec') . '" /></p>';
728
- echo '</form>';
729
- }
730
-
731
-
732
- /**
733
- * Setup everything needed for the Manul Order page
734
- *
735
- */
736
- function actionLoadPageHook_ManualOrder ()
737
- {
738
-
739
- add_meta_box('avhecBoxManualOrder', __('Manually Order Categories', 'avh-ec'), array(&$this, 'metaboxManualOrder'), $this->hooks['menu_manual_order'], 'normal', 'core');
740
-
741
-
742
- if (AVH_Common::getWordpressVersion() >= 3.1 ) {
743
- add_screen_option('layout_columns', array('max' => 1, 'default' => 1) );
744
- } else {
745
- add_filter('screen_layout_columns', array ( &$this, 'filterScreenLayoutColumns' ), 10, 2);
746
- }
747
-
748
- // WordPress core Styles and Scripts
749
- wp_enqueue_script('common');
750
- wp_enqueue_script('wp-lists');
751
- wp_enqueue_script('postbox');
752
- wp_enqueue_script('jquery-ui-sortable');
753
- wp_enqueue_script('avhec-manualorder');
754
-
755
- // WordPress core Styles
756
- wp_admin_css('css/dashboard');
757
-
758
- // Plugin Style
759
- wp_enqueue_style('avhec-admin-css');
760
-
761
- }
762
-
763
- /**
764
- * Menu Page Manual Order
765
  *
766
  * @return none
767
  */
768
- function doMenuManualOrder ()
769
- {
770
  global $screen_layout_columns;
771
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
772
  $hide2 = '';
773
  switch ($screen_layout_columns) {
774
  case 2:
@@ -779,165 +792,241 @@ class AVH_EC_Admin
779
  $hide2 = 'display:none;';
780
  }
781
 
782
- echo '<div class="wrap">';
783
  echo $this->displayIcon('index');
784
- echo '<h2>' . 'AVH Extended Categories - ' . __('Manually Order Categories', 'avh-ec') . '</h2>';
785
-
786
- echo '<div class="metabox-holder">';
787
  echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
788
- do_meta_boxes($this->hooks['menu_manual_order'], 'normal', '');
789
  echo ' </div>';
790
- echo '</div>';
 
 
 
 
 
791
  echo '</div>'; // wrap
792
- echo '<div class="clear"></div>';
793
 
794
  $this->printMetaboxGeneralNonces();
795
- $this->printMetaboxJS('manual_order');
796
  $this->printAdminFooter();
797
  }
798
 
799
  /**
 
800
  *
801
- * @return unknown_type
802
  */
803
- function metaboxManualOrder ()
804
- {
805
- global $wpdb;
806
-
807
- $parentID = 0;
808
 
809
- if (isset($_POST['btnSubCats'])) {
810
- $parentID = $_POST['cats'];
811
- } elseif (isset($_POST['hdnParentID'])) {
812
- $parentID = $_POST['hdnParentID'];
813
  }
814
 
815
- if (isset($_POST['btnReturnParent'])) {
816
- $parentsParent = $wpdb->get_row(
817
- $wpdb->prepare('SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = %d', $_POST['hdnParentID']),
818
- ARRAY_N
819
- )
820
- ;
821
- $parentID = $parentsParent[0];
822
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
823
 
824
- $success = "";
825
- if (isset($_POST['btnOrderCats'])) {
826
- if (isset($_POST['hdnManualOrder']) && $_POST['hdnManualOrder'] != "") {
827
 
828
- $hdnManualOrder = $_POST['hdnManualOrder'];
829
- $IDs = explode(",", $hdnManualOrder);
830
- $result = count($IDs);
831
 
832
- for ($i = 0; $i < $result; $i ++) {
833
- $str = str_replace("id_", "", $IDs[$i]);
834
- $wpdb->query($wpdb->prepare("UPDATE $wpdb->terms SET avhec_term_order = '$i' WHERE term_id ='$str'"));
835
- }
 
 
 
836
 
837
- $success = '<div id="message" class="updated fade"><p>' . __('Categories updated successfully.', 'avh-ec') . '</p></div>';
838
- } else {
839
- $success = '<div id="message" class="updated fade"><p>' . __('An error occured, order has not been saved.', 'avh-ec') . '</p></div>';
 
 
 
 
 
 
 
 
 
 
 
 
 
840
  }
841
-
 
 
842
  }
 
843
 
844
- $_SubCategories = "";
845
- $results = $wpdb->get_results($wpdb->prepare("SELECT t.term_id, t.name FROM $wpdb->term_taxonomy tt, $wpdb->terms t, $wpdb->term_taxonomy tt2 WHERE tt.parent = $parentID AND tt.taxonomy = 'category' AND t.term_id = tt.term_id AND tt2.parent = tt.term_id GROUP BY t.term_id, t.name HAVING COUNT(*) > 0 ORDER BY t.avhec_term_order ASC"));
846
- foreach ($results as $row) {
847
- $_SubCategories .= "<option value='$row->term_id'>$row->name</option>";
 
848
  }
849
 
850
- echo '<div class="wrap">';
851
- echo '<form name="frmMyCatOrder" method="post" action="">';
852
- echo $success;
853
-
854
-
855
-
856
- echo '<h4>';
857
- _e('Order the categories', 'avh-ec');
858
- if ($parentID == 0) {
859
- echo ' at the Toplevel';
860
- } else {
861
- $_cats = get_category_parents($parentID, false, ' » ');
862
- echo ' in the category ' . trim($_cats, ' » ');
863
  }
864
- echo '</h4>';
865
- echo '<span class="description">';
866
- _e('Order the categories on this level by dragging and dropping them into the desired order.', 'avh-ec');
867
- echo '</span>';
868
- echo '<ul id="avhecManualOrder">';
869
- $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->terms t inner join $wpdb->term_taxonomy tt on t.term_id = tt.term_id WHERE taxonomy = 'category' and parent = $parentID ORDER BY avhec_term_order ASC"));
870
- foreach ($results as $row)
871
- echo "<li id='id_$row->term_id' class='lineitem menu-item-settings'>" . __($row->name) . "</li>";
872
 
873
- echo '</ul>';
874
- echo '<input type="submit" name="btnOrderCats" id="btnOrderCats" class="button-primary" value="' . __('Save Order', 'avh-ec') . '" onclick="javascript:orderCats(); return true;" />';
 
 
 
 
 
875
 
876
- if ($parentID != 0) {
877
- echo "<input type='submit' class='button' id='btnReturnParent' name='btnReturnParent' value='" . __('Return to parent category', 'avh-ec') . "' />";
 
 
 
 
 
 
878
  }
879
 
880
- echo '<strong id="updateText"></strong><br /><br />';
881
- if ($_SubCategories != "") {
 
 
 
 
 
882
 
883
- echo '<h4>';
884
- _e('Select Subcategory', 'avh-ec');
885
- echo '</h4>';
886
- echo '<select id="cats" name="cats">';
887
- echo $_SubCategories;
 
 
 
 
888
 
889
- echo '</select><input type="submit" name="btnSubCats" class="button" id="btnSubCats" value="' . __('Select', 'avh-ec') . '" />';
890
- echo '<span class="description">';
891
- _e('Choose a category from the drop down to order the subcategories in that category.', 'avh-ec');
892
- echo '</span>';
893
- }
 
894
 
895
- echo '<input type="hidden" id="hdnManualOrder" name="hdnManualOrder" />';
896
- echo '<input type="hidden" id="hdnParentID" name="hdnParentID" value="' . $parentID . '" /></form>';
897
- echo '</div>';
 
 
898
  }
899
 
900
  /**
901
- * Setup everything needed for the FAQ page
902
  *
 
903
  */
904
- function actionLoadPageHook_faq ()
905
- {
906
-
907
- add_meta_box('avhecBoxFAQ', __('F.A.Q.', 'avh-ec'), array(&$this, 'metaboxFAQ'), $this->hooks['menu_faq'], 'normal', 'core');
908
- add_meta_box('avhecBoxTranslation', __('Translation', 'avh-ec'), array(&$this, 'metaboxTranslation'), $this->hooks['menu_faq'], 'normal', 'core');
909
 
910
- if (AVH_Common::getWordpressVersion() >= 3.1 ) {
911
- add_screen_option('layout_columns', array('max' => 2, 'default' => 2) );
912
- } else {
913
- add_filter('screen_layout_columns', array ( &$this, 'filterScreenLayoutColumns' ), 10, 2);
 
 
 
 
914
  }
915
 
916
- // WordPress core Styles and Scripts
917
- wp_enqueue_script('common');
918
- wp_enqueue_script('wp-lists');
919
- wp_enqueue_script('postbox');
920
-
921
- // WordPress core Styles
922
- wp_admin_css('css/dashboard');
923
 
924
- // Plugin Style
925
- wp_enqueue_style('avhec-admin-css');
 
 
 
 
 
926
 
 
 
 
927
  }
928
 
929
  /**
930
- * Menu Page FAQ
931
  *
932
  * @return none
933
  */
934
- function doMenuFAQ ()
935
- {
936
  global $screen_layout_columns;
937
 
938
  // This box can't be unselectd in the the Screen Options
939
- add_meta_box('avhecBoxAnnouncements', __('Announcements', 'avh-ec'), array(&$this, 'metaboxAnnouncements'), $this->hooks['menu_faq'], 'side', 'core');
940
- add_meta_box('avhecBoxDonations', __('Donations', 'avh-ec'), array(&$this, 'metaboxDonations'), $this->hooks['menu_faq'], 'side', 'core');
 
 
 
 
 
 
 
 
 
 
941
 
942
  $hide2 = '';
943
  switch ($screen_layout_columns) {
@@ -951,121 +1040,329 @@ class AVH_EC_Admin
951
 
952
  echo '<div class="wrap avhec-metabox-wrap">';
953
  echo $this->displayIcon('index');
954
- echo '<h2>' . 'AVH Extended Categories - ' . __('F.A.Q', 'avh-ec') . '</h2>';
955
  echo ' <div id="dashboard-widgets-wrap">';
956
  echo ' <div id="dashboard-widgets" class="metabox-holder">';
957
  echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
958
- do_meta_boxes($this->hooks['menu_faq'], 'normal', '');
959
- echo ' </div>';
960
  echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n";
961
- do_meta_boxes($this->hooks['menu_faq'], 'side', '');
962
  echo ' </div>';
963
  echo ' </div>';
 
964
  echo '<br class="clear"/>';
965
  echo ' </div>'; //dashboard-widgets-wrap
966
  echo '</div>'; // wrap
967
 
968
-
969
  $this->printMetaboxGeneralNonces();
970
- $this->printMetaboxJS('faq');
971
  $this->printAdminFooter();
972
  }
973
 
974
  /**
975
- * Translation Metabox
976
- * @return unknown_type
 
 
 
 
 
 
977
  */
978
- function metaboxTranslation ()
979
- {
980
- $locale = apply_filters( 'plugin_locale', get_locale(), 'avh-ec' );
981
- $available_locale['cs_CZ'] = array('Czech - Čeština',0);
982
- $available_locale['nl_NL'] = array('Dutch - Nederlands',0);
983
- $available_locale['de_DE'] = array('German - Deutsch', 0);
984
- $available_locale['el'] = array('Greek - Čeština',0);
985
- $available_locale['id_ID'] = array('Indonesian - Bahasa Indonesia - Čeština',0);
986
- $available_locale['it_IT'] = array('Italian - Italiano',1);
987
- $available_locale['ru_RU'] = array('Russian — Русский',0);
988
- $available_locale['es_ES'] = array('Spanish - Español',0);
989
- $available_locale['sv_SE'] = array('Swedish - Svenska',0);
990
- $available_locale['tr'] = array('Turkish - Türkçe',0);
991
 
992
- echo '<div class="p">';
993
- echo __('This plugin is translated in several languages. Some of the languages might be incomplete. Please help to complete these translations or add a new language.', 'avh-ec') . '<br />';
994
 
995
- echo '</div>';
 
996
 
997
- echo '<div class="p">';
998
- echo '<span class="b">' . __('Available Languages', 'avh-ec') . '</span>';
999
- echo '<ul>';
1000
- foreach ($available_locale as $key => $value) {
1001
- echo '<li>';
1002
- $complete = ($value[1] == 1 ? 'Complete' : 'Incomplete');
1003
- echo $value[0] . ' (' . $key . ') - ' . $complete;
1004
- echo '</li>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1005
  }
1006
- echo '</ul>';
1007
- echo '</div>';
1008
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1009
  echo '<div class="p">';
1010
- if ('en_US' != $locale & (!array_key_exists($locale, $available_locale))){
1011
- echo 'Currently the plugin is not available in your language ('.$locale.'). Why not help out and translate the plugin in your language. You can help by visiting <a href="https://translations.launchpad.net/avhextendedcategories/trunk" target="_blank">Launchpad</a>.';
 
 
 
 
1012
  } else {
1013
- echo __('You can visit ', 'avh-ec') . '<a href="https://translations.launchpad.net/avhextendedcategories/trunk" target="_blank">Launchpad</a> ' . __('to help complete these translations or add a new language.', 'avh-ec');
 
 
 
 
 
 
 
 
 
1014
  }
1015
  echo '</div>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1016
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1017
  }
1018
 
 
 
1019
  /**
1020
  * Donation Metabox
 
1021
  * @return unknown_type
1022
  */
1023
- function metaboxDonations ()
1024
- {
1025
  echo '<div class="p">';
1026
- echo __('If you enjoy this plug-in please consider a donation. There are several ways you can show your appreciation.', 'avh-ec');
 
1027
  echo '</div>';
1028
 
1029
  echo '<div class="p">';
1030
  echo '<span class="b">Amazon</span><br />';
1031
  echo __('If you decide to buy something from Amazon click the button.', 'avh-ec') . '</span><br />';
1032
- echo '<a href="https://www.amazon.com/?tag=avh-donation-20" target="_blank" title="Amazon Homepage"><img alt="Amazon Button" src="' . $this->core->info['graphics_url'] . '/us_banner_logow_120x60.gif" /></a>';
 
 
1033
  echo '</div>';
1034
 
1035
  echo '<div class="p">';
1036
- echo __('You can send me something from my ', 'avh-ec') . '<a href="http://www.amazon.com/registry/wishlist/1U3DTWZ72PI7W?tag=avh-donation-20">' . __('Amazon Wish List', 'avh-ec') . '</a>';
 
 
 
1037
  echo '</div>';
1038
 
1039
  echo '<div class="p">';
1040
  echo '<span class="b">' . __('Through Paypal.', 'avh-ec') . '</span><br />';
1041
- echo __('Click on the Donate button and you will be directed to Paypal where you can make your donation and you don\'t need to have a Paypal account to make a donation.', 'avh-ec') . '<br />';
 
1042
  echo '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=S85FXJ9EBHAF2&lc=US&item_name=AVH%20Plugins&item_number=fdas&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted" target="_blank" title="Donate">';
1043
  echo '<img src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" alt="Donate"/></a>';
1044
  echo '</div>';
1045
-
1046
  }
1047
 
1048
  /***
1049
  * F.A.Q Metabox
 
1050
  * @return none
1051
  */
1052
- function metaboxFAQ ()
1053
- {
1054
  echo '<div class="p">';
1055
  echo '<span class="b">' . __('What about support?', 'avh-ec') . '</span><br />';
1056
- echo __('I created a support site at http://forums.avirtualhome.com where you can ask questions or request features.', 'avh-ec') . '<br />';
 
1057
  echo '</div>';
1058
 
1059
  echo '<div class="p">';
1060
  echo '<span class="b">' . __('What is depth selection?', 'avh-ec') . '</span><br />';
1061
- echo __('Starting with version 2.0 and WordPress 2.8 you can select how many levels deep you want to show your categories. This option only works when you select Show Hierarchy as well.', 'avh-ec') . '<br /><br />';
1062
- echo __('Here is how it works: Say you have 5 top level categories and each top level has a number of children. You could manually select all the Top Level categories you want to show but now you can do the following:', 'avh-ec') . '<br />';
1063
- echo __('You select to display all categories, select to Show hierarchy and select how many levels you want to show, in this case Toplevel only.', 'avh-ec') . '<br />';
 
 
 
1064
  echo '</div>';
1065
 
1066
  echo '<div class="p">';
1067
  echo '<span class="b">' . __('Multiple Category Groups', 'avh-ec') . '</span><br />';
1068
- echo __('The following is an explanation how assigning multiple groups to page/post works.', 'avh-ec') . '<br /><br />';
 
1069
  echo __('Lets say you have the following groups:', 'avh-ec');
1070
  echo '<ul>';
1071
  echo '<li>' . __('Free Time', 'avh-ec') . '</li>';
@@ -1073,7 +1370,8 @@ class AVH_EC_Admin
1073
  echo '<li>' . __('Movie', 'avh-ec') . '</li>';
1074
  echo '<li>' . __('Music', 'avh-ec') . '</li>';
1075
  echo '</ul>';
1076
- echo __('Setup several Category Group widgets and associated each widget with one or more groups.', 'avh-ec') . '<br />';
 
1077
  echo __('Widget 1 has association with Free Time', 'avh-ec') . '<br />';
1078
  echo __('Widget 2 has association with Theater, Movie and Music', 'avh-ec') . '<br />';
1079
  echo __('Widget 3 has association with Theater, Movie and Music', 'avh-ec') . '<br /><br />';
@@ -1095,138 +1393,181 @@ class AVH_EC_Admin
1095
  echo '<li>' . __('Widget 2: Shows categories of the Movie or Music group.', 'avh-ec') . '</li>';
1096
  echo '<li>' . __('Widget 3: Shows categories of the Music or Movie group.', 'avh-ec') . '</li>';
1097
  echo '</ul>';
1098
- echo __('Whether Widget 2 shows Movie or Music depends on the creation order of groups. If Widget 2 shows Movie, Widget 3 will show Music but if Widget 2 shows Music, Widget 3 will show Movie.', 'avh-ec') . '<br />';
 
1099
  echo '</div>';
1100
  }
1101
 
1102
- function metaboxAnnouncements ()
1103
- {
1104
- $php5 = version_compare('5.2', phpversion(), '<');
1105
- echo '<div class="p">';
1106
- echo '<span class="b">' . __('PHP4 Support', 'avh-ec') . '</span><br />';
1107
- echo __('The next major release of the plugin will no longer support PHP4.', 'avh-ec') . '<br />';
1108
- echo __('It will be written for PHP 5.2 and ', 'avh-ec');
1109
- if ($php5) {
1110
- echo __('your blog already runs the needed PHP version. When the new release comes out you can safely update.', 'avh-ec') . '<br />';
1111
- } else {
1112
- echo __('your blog still runs PHP4. When the new release comes out you can not use it.', 'avh-ec') . '<br />';
1113
- echo __('I don\'t have a timeline for the next version but consider contacting your host if PHP 5.2 is available.', 'avh-ec') . '<br />';
1114
- echo __('If your hosts doesn\'t offer PHP 5.2 you might want to consider switching hosts.', 'avh-ec') . '<br />';
1115
- echo __('A host to consider is ', 'avh-ec') . '<a href="http://www.lunarpages.com/id/pdoes" target="_blank">Lunarpages</a>';
1116
- echo __('I run my personal blog there and I am very happy with their services. You can get an account with unlimited bandwidth, storage and much more for a low price.', 'avh-ec');
1117
  }
1118
- echo '</div>';
1119
 
1120
- }
 
 
 
 
 
1121
 
1122
- /**
1123
- * Sets the amount of columns wanted for a particuler screen
1124
- *
1125
- * @WordPress filter screen_meta_screen
1126
- * @param $screen
1127
- * @return strings
1128
- */
1129
 
1130
- function filterScreenLayoutColumns ($columns, $screen)
1131
- {
1132
- switch ($screen) {
1133
- case $this->hooks['menu_overview']:
1134
- $columns[$this->hooks['menu_overview']] = 2;
1135
- break;
1136
- case $this->hooks['menu_general']:
1137
- $columns[$this->hooks['menu_general']] = 2;
1138
- break;
1139
- case $this->hooks['menu_category_groups']:
1140
- $columns[$this->hooks['menu_category_groups']] = 2;
1141
- break;
1142
- case $this->hooks['menu_faq']:
1143
- $columns[$this->hooks['menu_faq']] = 2;
1144
- break;
1145
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1146
  }
1147
- return $columns;
1148
- }
1149
 
1150
- /**
1151
- * Adds Settings next to the plugin actions
1152
- *
1153
- * @WordPress Filter plugin_action_links_avh-amazon/avh-amazon.php
1154
- *
1155
- */
1156
- function filterPluginActions ($links, $file)
1157
- {
1158
- $settings_link = '<a href="admin.php?page=extended-categories-widget">' . __('Settings', 'avh-ec') . '</a>';
1159
- array_unshift($links, $settings_link); // before other links
1160
- return $links;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1161
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1162
  }
1163
 
1164
  /**
1165
- * Creates a new array for columns headers. Used in print_column_headers. The filter is called from get_column_headers
1166
- *
1167
- * @param $columns
1168
- * @return Array
1169
- * @see print_column_headers, get_column_headers
1170
  */
1171
- function filterManageCategoriesGroupColumns ($columns)
1172
- {
1173
- $categories_group_columns = array('name'=>__('Name', 'avh-ec'), 'slug'=>'Slug', 'widget-title'=>__('Widget Title', 'avh-ec'), 'description'=>__('Description', 'avh-ec'), 'cat-in-group'=>__('Categories in the group', 'avh-ec'));
1174
- return $categories_group_columns;
1175
  }
1176
 
1177
  /**
1178
- * When not using AJAX, this function is called when the deletion fails.
1179
  *
1180
- * @param string $text
1181
- * @param int $group_id
1182
- * @return string
1183
- * @WordPress Filter explain_nonce_$verb-$noun
1184
- * @see wp_explain_nonce
1185
  */
1186
- function filterExplainNonceDeleteGroup ($text, $group_id)
1187
- {
1188
- $group = get_term($group_id, $this->catgrp->taxonomy_name, OBJECT, 'display');
1189
-
1190
- $return = sprintf(__('Your attempt to delete this group: &#8220;%s&#8221; has failed.'), $group->name);
1191
- return ($return);
1192
- }
 
 
 
 
 
1193
 
1194
- ############## Admin WP Helper ##############
 
 
1195
 
 
1196
 
1197
- /**
1198
- * Get the backlink for forms
1199
- *
1200
- * @return strings
1201
- */
1202
- function getBackLink ()
1203
- {
1204
- $page = basename(__FILE__);
1205
- if (isset($_GET['page']) && ! empty($_GET['page'])) {
1206
- $page = preg_replace('[^a-zA-Z0-9\.\_\-]', '', $_GET['page']);
1207
  }
 
 
1208
 
1209
- if (function_exists("admin_url"))
1210
- return admin_url(basename($_SERVER["PHP_SELF"])) . "?page=" . $page;
1211
- else
1212
- return $_SERVER['PHP_SELF'] . "?page=" . $page;
 
 
 
 
 
 
 
1213
  }
1214
 
1215
  /**
1216
- * Print all Category Group rows
1217
- *
1218
- * @uses printCategoryGroupRow
1219
- *
1220
  */
1221
- function printCategoryGroupRows ()
1222
- {
1223
- $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty'=>FALSE));
1224
-
1225
- foreach ($cat_groups as $group) {
1226
- if ('none' != $group->slug) {
1227
- echo $this->printCategoryGroupRow($group->term_id, $group->term_taxonomy_id);
1228
- }
1229
- }
1230
  }
1231
 
1232
  /**
@@ -1236,30 +1577,38 @@ class AVH_EC_Admin
1236
  * @param int $group_term_id
1237
  * @param int $group_term_taxonomy_id
1238
  */
1239
- function printCategoryGroupRow ($group_term_id, $group_term_taxonomy_id)
1240
- {
1241
  static $row_class = '';
1242
 
1243
  $group = get_term($group_term_id, $this->catgrp->taxonomy_name, OBJECT, 'display');
1244
 
1245
- $no_edit[$this->catgrp->getTermIDBy('slug', 'all')] = 0;
1246
- $no_delete[$this->catgrp->getTermIDBy('slug', 'all')] = 0;
1247
 
1248
  if (current_user_can('manage_categories')) {
1249
  $actions = array();
1250
- if (! array_key_exists($group->term_id, $no_edit)) {
1251
  $edit_link = "admin.php?page=avhec-grouped&amp;action=edit&amp;group_ID=$group->term_id";
1252
- $edit = "<a class='row-title' href='$edit_link' title='" . esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $group->name)) . "'>" . esc_attr($group->name) . '</a><br />';
 
 
 
 
1253
 
1254
  $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
1255
  } else {
1256
  $edit = esc_attr($group->name);
1257
  }
1258
- if (! (array_key_exists($group->term_id, $no_delete))) {
1259
- $actions['delete'] = "<a class='delete:the-list:group-$group->term_id submitdelete' href='" . wp_nonce_url("admin.php?page=avhec-grouped&amp;action=delete&amp;group_ID=$group->term_id", 'delete-avhecgroup_' . $group->term_id) . "'>" . __('Delete') . "</a>";
 
 
 
 
 
1260
  }
1261
  $action_count = count($actions);
1262
- $i = 0;
1263
  $edit .= '<div class="row-actions">';
1264
  foreach ($actions as $action => $link) {
1265
  ++ $i;
@@ -1272,25 +1621,26 @@ class AVH_EC_Admin
1272
  }
1273
 
1274
  $row_class = 'alternate' == $row_class ? '' : 'alternate';
1275
- $qe_data = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit');
1276
 
1277
  $output = "<tr id='group-$group->term_id' class='iedit $row_class'>";
1278
 
1279
  $columns = get_column_headers('categories_group');
1280
- $hidden = get_hidden_columns('categories_group');
1281
  foreach ($columns as $column_name => $column_display_name) {
1282
  $class = 'class="' . $column_name . ' column-' . $column_name . '"';
1283
 
1284
  $style = '';
1285
- if (in_array($column_name, $hidden))
1286
  $style = ' style="display:none;"';
 
1287
 
1288
  $attributes = $class . $style;
1289
 
1290
  switch ($column_name) {
1291
  case 'cb':
1292
  $output .= '<th scope="row" class="check-column">';
1293
- if (! (array_key_exists($group->term_id, $no_delete))) {
1294
  $output .= '<input type="checkbox" name="delete[]" value="' . $group->term_id . '" />';
1295
  } else {
1296
  $output .= "&nbsp;";
@@ -1316,7 +1666,7 @@ class AVH_EC_Admin
1316
  $output .= "<td $attributes>" . apply_filters('editable_slug', $qe_data->slug) . "</td>";
1317
  break;
1318
  case 'cat-in-group':
1319
- $cats = $this->catgrp->getCategoriesFromGroup($group_term_id);
1320
  $catname = array();
1321
  foreach ($cats as $cat_id) {
1322
  $catname[] = get_cat_name($cat_id);
@@ -1325,7 +1675,6 @@ class AVH_EC_Admin
1325
  $cat = implode(', ', $catname);
1326
  $output .= '<td ' . $attributes . '>' . $cat . '</td>';
1327
  break;
1328
-
1329
  }
1330
  }
1331
  $output .= '</tr>';
@@ -1333,18 +1682,31 @@ class AVH_EC_Admin
1333
  return $output;
1334
  }
1335
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1336
  /**
1337
  * Prints the general nonces, used by the AJAX
1338
  */
1339
- function printMetaboxGeneralNonces ()
1340
- {
1341
  echo '<form style="display:none" method="get" action="">';
1342
  echo '<p>';
1343
  wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1344
  wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1345
  echo '</p>';
1346
  echo '</form>';
1347
-
1348
  }
1349
 
1350
  /**
@@ -1352,9 +1714,8 @@ class AVH_EC_Admin
1352
  *
1353
  * @param $boxid
1354
  */
1355
- function printMetaboxJS ($boxid)
1356
- {
1357
- $a = $this->hooks['menu_' . $boxid];
1358
  echo '<script type="text/javascript">' . "\n";
1359
  echo ' //<![CDATA[' . "\n";
1360
  echo ' jQuery(document).ready( function($) {' . "\n";
@@ -1364,87 +1725,108 @@ class AVH_EC_Admin
1364
  echo ' });' . "\n";
1365
  echo ' //]]>' . "\n";
1366
  echo '</script>';
1367
-
1368
- }
1369
-
1370
- /**
1371
- * Display plugin Copyright
1372
- *
1373
- */
1374
- function printAdminFooter ()
1375
- {
1376
- echo '<p class="footer_avhec">';
1377
- printf('&copy; Copyright %d <a href="http://blog.avirtualhome.com/" title="My Thoughts">Peter van der Does</a> | AVH Extended Categories Version %s', date('Y'), $this->core->version);
1378
- echo '</p>';
1379
- }
1380
-
1381
- /**
1382
- * Display WP alert
1383
- *
1384
- */
1385
- function displayMessage ()
1386
- {
1387
- if ($this->message != '') {
1388
- $message = $this->message;
1389
- $status = $this->status;
1390
- $this->message = $this->status = ''; // Reset
1391
- }
1392
- if (isset($message)) {
1393
- $status = ($status != '') ? $status : 'updated fade';
1394
- echo '<div id="message" class="' . $status . '">';
1395
- echo '<p><strong>' . $message . '</strong></p></div>';
1396
- }
1397
  }
1398
 
1399
  /**
1400
  * Ouput formatted options
1401
  *
1402
  * @param array $option_data
 
1403
  * @return string
1404
  */
1405
- function printOptions ($option_data, $option_actual)
1406
- {
1407
  // Generate output
1408
  $output = '';
1409
  $output .= "\n" . '<table class="form-table avhec-options">' . "\n";
1410
  foreach ($option_data as $option) {
1411
- $section = substr($option[0], strpos($option[0], '[') + 1);
1412
- $section = substr($section, 0, strpos($section, ']['));
1413
  $option_key = rtrim($option[0], ']');
1414
  $option_key = substr($option_key, strpos($option_key, '][') + 2);
1415
  // Helper
1416
  if ($option[2] == 'helper') {
1417
- $output .= '<tr style="vertical-align: top;"><td class="helper" colspan="2">' . wp_filter_post_kses($option[4]) . '</td></tr>' . "\n";
 
 
 
1418
  continue;
1419
  }
1420
  switch ($option[2]) {
1421
  case 'checkbox':
1422
- $input_type = '<input type="checkbox" id="' . esc_attr($option[0]) . '" name="' . esc_attr($option[0]) . '" value="' . esc_attr($option[3]) . '" ' . $this->isChecked('1', $option_actual[$section][$option_key]) . ' />' . "\n";
 
 
 
 
 
 
 
 
 
1423
  $explanation = $option[4];
1424
  break;
1425
  case 'dropdown':
1426
  $selvalue = $option[3];
1427
- $seltext = $option[4];
1428
- $seldata = '';
1429
  foreach ((array) $selvalue as $key => $sel) {
1430
- $seldata .= '<option value="' . esc_attr($sel) . '" ' . (($option_actual[$section][$option_key] == $sel) ? 'selected="selected"' : '') . ' >' . esc_html(ucfirst($seltext[$key])) . '</option>' . "\n";
 
 
 
 
 
 
 
1431
  }
1432
- $input_type = '<select id="' . esc_attr($option[0]) . '" name="' . esc_attr($option[0]) . '">' . $seldata . '</select>' . "\n";
 
 
 
 
 
 
 
1433
  $explanation = $option[5];
1434
  break;
1435
  case 'text-color':
1436
- $input_type = '<input type="text" ' . (($option[3] > 1) ? ' style="width: 95%" ' : '') . 'id="' . esc_attr($option[0]) . '" name="' . esc_attr($option[0]) . '" value="' . esc_attr($option_actual[$section][$option_key]) . '" size="' . esc_attr($option[3]) . '" /><div class="box_color ' . esc_attr($option[0]) . '"></div>' . "\n";
 
 
 
 
 
 
 
 
 
 
 
 
 
1437
  $explanation = $option[4];
1438
  break;
1439
  case 'textarea':
1440
- $input_type = '<textarea rows="' . esc_attr($option[5]) . '" ' . (($option[3] > 1) ? ' style="width: 95%" ' : '') . 'id="' . esc_attr($option[0]) . '" name="' . esc_attr($option[0]) . '" size="' . esc_attr($option[3]) . '" />' . $option_actual[$section][$option_key] . '</textarea>';
 
 
 
 
 
 
 
 
 
 
 
 
1441
  $explanation = $option[4];
1442
  break;
1443
  case 'catlist':
1444
  ob_start();
1445
  echo '<div id="avhec-catlist">';
1446
  echo '<ul>';
1447
- wp_category_checklist(0, 0, $option_actual[$section][$option_key]);
1448
  echo '</ul>';
1449
  echo '</div>';
1450
  $input_type = ob_get_contents();
@@ -1453,7 +1835,18 @@ class AVH_EC_Admin
1453
  break;
1454
  case 'text':
1455
  default:
1456
- $input_type = '<input type="text" ' . (($option[3] > 1) ? ' style="width: 95%" ' : '') . 'id="' . esc_attr($option[0]) . '" name="' . esc_attr($option[0]) . '" value="' . esc_attr($option_actual[$section][$option_key]) . '" size="' . esc_attr($option[3]) . '" />' . "\n";
 
 
 
 
 
 
 
 
 
 
 
1457
  $explanation = $option[4];
1458
  break;
1459
  }
@@ -1463,59 +1856,21 @@ class AVH_EC_Admin
1463
  $extra = '<br /><span class="description">' . wp_filter_kses($explanation) . '</span>' . "\n";
1464
  }
1465
  // Output
1466
- $output .= '<tr style="vertical-align: top;"><th align="left" scope="row"><label for="' . esc_attr($option[0]) . '">' . wp_filter_kses($option[1]) . '</label></th><td>' . $input_type . ' ' . $extra . '</td></tr>' . "\n";
 
 
 
 
 
 
 
 
 
1467
  }
1468
  $output .= '</table>' . "\n";
1469
- return $output;
1470
- }
1471
-
1472
- /**
1473
- * Used in forms to set an option checked
1474
- *
1475
- * @param mixed $checked
1476
- * @param mixed $current
1477
- * @return strings
1478
- */
1479
- function isChecked ($checked, $current)
1480
- {
1481
- $return = '';
1482
- if ($checked == $current) {
1483
- $return = ' checked="checked"';
1484
- }
1485
- return $return;
1486
- }
1487
-
1488
- /**
1489
- * Displays the icon on the menu pages
1490
- *
1491
- * @param $icon
1492
- */
1493
- function displayIcon ($icon)
1494
- {
1495
- return ('<div class="icon32" id="icon-' . $icon . '"><br/></div>');
1496
- }
1497
-
1498
- /**
1499
- * Ajax Helper: inline delete of the groups
1500
- */
1501
- function ajaxDeleteGroup ()
1502
- {
1503
- $group_id = isset($_POST['id']) ? (int) $_POST['id'] : 0;
1504
- check_ajax_referer('delete-avhecgroup_' . $group_id);
1505
-
1506
- if (! current_user_can('manage_categories')) {
1507
- die('-1');
1508
- }
1509
- $check = $this->catgrp->getGroup($group_id);
1510
- if (false === $check) {
1511
- die('1');
1512
- }
1513
 
1514
- if ($this->catgrp->doDeleteGroup($group_id)) {
1515
- die('1');
1516
- } else {
1517
- die('0');
1518
- }
1519
  }
1520
  }
 
1521
  ?>
1
  <?php
2
 
3
+ class AVH_EC_Admin {
 
4
  /**
 
 
 
 
 
 
 
5
  * @var AVH_EC_Category_Group
6
  */
7
  var $catgrp;
8
+ /**
9
+ * @var AVH_EC_Core
10
+ */
11
+ var $core;
12
  var $hooks = array();
13
  var $message;
14
 
15
  /**
16
  * PHP5 constructor
 
17
  */
18
+ function __construct() {
 
19
 
20
  // Initialize the plugin
21
+ $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core');
22
+ $this->catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
23
 
24
  add_action('wp_ajax_delete-group', array(&$this, 'ajaxDeleteGroup'));
25
 
26
  // Admin menu
27
+ add_action('admin_init', array(&$this, 'actionAdminInit'));
28
  add_action('admin_menu', array(&$this, 'actionAdminMenu'));
29
+ add_filter('plugin_action_links_extended-categories-widget/widget_extended_categories.php',
30
+ array(&$this, 'filterPluginActions'),
31
+ 10,
32
+ 2);
33
 
34
  // Actions used for editing posts
35
  add_action('load-post.php', array(&$this, 'actionLoadPostPage'));
47
 
48
  /**
49
  * PHP4 Constructor
 
50
  */
51
+ function AVH_EC_Admin() {
 
52
  $this->__construct();
53
  }
54
 
55
  function actionAdminInit() {
56
  if (is_admin() && isset($_GET['taxonomy']) && 'category' == $_GET['taxonomy']) {
57
+ add_action($_GET['taxonomy'] . '_edit_form', array(&$this, 'displayCategoryGroupForm'), 10, 2);
58
  }
59
+ add_action('edit_term', array(&$this, 'handleEditTerm'), 10, 3);
 
60
  }
61
 
62
  /**
63
+ * Add the Tools and Options to the Management and Options page repectively
64
  *
65
+ * @WordPress Action admin_menu
 
 
 
 
66
  */
67
+ function actionAdminMenu() {
68
 
69
+ // Register Style and Scripts
70
+ $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
71
+ wp_register_script('avhec-categorygroup-js',
72
+ AVHEC_PLUGIN_URL . '/js/avh-ec.categorygroup' . $suffix . '.js',
73
+ array('jquery'),
74
+ $this->core->version,
75
+ true);
76
+ wp_register_script('avhec-manualorder',
77
+ AVHEC_PLUGIN_URL . '/js/avh-ec.admin.manualorder' . $suffix . '.js',
78
+ array('jquery-ui-sortable'),
79
+ $this->core->version,
80
+ false);
81
+ wp_register_style('avhec-admin-css',
82
+ AVHEC_PLUGIN_URL . '/css/avh-ec.admin.css',
83
+ array('wp-admin'),
84
+ $this->core->version,
85
+ 'screen');
86
 
87
+ // Add menu system
88
+ $folder = $this->core->getBaseDirectory(AVHEC_PLUGIN_DIR);
89
+ add_menu_page('AVH Extended Categories',
90
+ 'AVH Extended Categories',
91
+ 'manage_options',
92
+ $folder,
93
+ array(&$this, 'doMenuOverview'));
94
+ $this->hooks['menu_overview'] = add_submenu_page($folder,
95
+ 'AVH Extended Categories: ' . __('Overview', 'avh-ec'),
96
+ __('Overview', 'avh-ec'),
97
+ 'manage_options',
98
+ $folder,
99
+ array(&$this, 'doMenuOverview'));
100
+ $this->hooks['menu_general'] = add_submenu_page($folder,
101
+ 'AVH Extended Categories: ' .
102
+ __('General Options', 'avh-ec'),
103
+ __('General Options', 'avh-ec'),
104
+ 'manage_options',
105
+ 'avhec-general',
106
+ array(&$this, 'doMenuGeneral'));
107
+ $this->hooks['menu_category_groups'] = add_submenu_page($folder,
108
+ 'AVH Extended Categories: ' .
109
+ __('Category Groups', 'avh-ec'),
110
+ __('Category Groups', 'avh-ec'),
111
+ 'manage_options',
112
+ 'avhec-grouped',
113
+ array(&$this, 'doMenuCategoryGroup'));
114
+ $this->hooks['menu_manual_order'] = add_submenu_page($folder,
115
+ 'AVH Extended Categories: ' .
116
+ __('Manually Order', 'avh-ec'),
117
+ __('Manually Order', 'avh-ec'),
118
+ 'manage_options',
119
+ 'avhec-manual-order',
120
+ array(&$this, 'doMenuManualOrder'));
121
+ $this->hooks['menu_faq'] = add_submenu_page($folder,
122
+ 'AVH Extended Categories:' . __('F.A.Q', 'avh-ec'),
123
+ __('F.A.Q', 'avh-ec'),
124
+ 'manage_options',
125
+ 'avhec-faq',
126
+ array(&$this, 'doMenuFAQ'));
127
 
128
+ // Add actions for menu pages
129
+ // Overview Menu
130
+ add_action('load-' . $this->hooks['menu_overview'], array(&$this, 'actionLoadPageHook_Overview'));
 
 
 
131
 
132
+ // General Options Menu
133
+ add_action('load-' . $this->hooks['menu_general'], array(&$this, 'actionLoadPageHook_General'));
 
134
 
135
+ // Category Groups Menu
136
+ add_action('load-' . $this->hooks['menu_category_groups'], array(&$this, 'actionLoadPageHook_CategoryGroup'));
 
 
 
 
 
 
 
 
 
 
 
 
137
 
138
+ // FAQ Menu
139
+ add_action('load-' . $this->hooks['menu_faq'], array(&$this, 'actionLoadPageHook_faq'));
 
 
 
 
 
 
 
 
 
 
 
 
140
  }
141
 
142
  /**
143
  * When a category is created this function is called to add the new category to the group all
144
+ *
145
  * @param $term_id
146
  * @param $term_taxonomy_id
147
  */
148
+ function actionCreatedCategory($term_id, $term_taxonomy_id) {
 
149
  $group_id = $this->catgrp->getTermIDBy('slug', 'all');
150
  $this->catgrp->setCategoriesForGroup($group_id, (array) $term_id);
151
  }
154
  * When a category is deleted this function is called so the category is deleted from every group as well.
155
  *
156
  * @param object $term
157
+ * @param int $term_taxonomy_id
158
  */
159
+ function actionDeleteCategory($term_id, $term_taxonomy_id) {
 
160
  $this->catgrp->doDeleteCategoryFromGroup($term_id);
161
  }
162
 
163
  /**
164
+ * Setup everything needed for the Category Group page
 
 
 
 
 
 
 
 
 
 
 
 
 
165
  */
166
+ function actionLoadPageHook_CategoryGroup() {
 
 
 
 
 
 
 
167
 
168
+ // Add metaboxes
169
+ add_meta_box('avhecBoxCategoryGroupAdd',
170
+ __('Add Group', 'avh-ec'),
171
+ array(&$this, 'metaboxCategoryGroupAdd'),
172
+ $this->hooks['menu_category_groups'],
173
+ 'normal',
174
+ 'core');
175
+ add_meta_box('avhecBoxCategoryGroupList',
176
+ __('Group Overview', 'avh-ec'),
177
+ array(&$this, 'metaboxCategoryGroupList'),
178
+ $this->hooks['menu_category_groups'],
179
+ 'side',
180
+ 'core');
181
+ add_meta_box('avhecBoxCategoryGroupSpecialPages',
182
+ __('Special Pages', 'avh-ec'),
183
+ array(&$this, 'metaboxCategoryGroupSpecialPages'),
184
+ $this->hooks['menu_category_groups'],
185
+ 'normal',
186
+ 'core');
187
+
188
+ if (AVH_Common::getWordpressVersion() >= 3.1) {
189
+ add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
190
+ } else {
191
+ add_filter('screen_layout_columns', array(&$this, 'filterScreenLayoutColumns'), 10, 2);
192
+ }
193
 
194
+ // WordPress core Scripts
195
+ wp_enqueue_script('common');
196
+ wp_enqueue_script('wp-lists');
197
+ wp_enqueue_script('postbox');
198
 
199
+ // Plugin Scripts
200
+ wp_enqueue_script('avhec-categorygroup-js');
201
 
202
+ // WordPress core Styles
203
+ wp_admin_css('css/dashboard');
204
 
205
+ // Plugin Style
206
+ wp_enqueue_style('avhec-admin-css');
207
  }
208
 
209
  /**
210
+ * Setup everything needed for the General Options page
 
211
  */
212
+ function actionLoadPageHook_General() {
 
213
  // Add metaboxes
214
+ add_meta_box('avhecBoxOptions',
215
+ __('Options', 'avh-ec'),
216
+ array(&$this, 'metaboxOptions'),
217
+ $this->hooks['menu_general'],
218
+ 'normal',
219
+ 'core');
220
+
221
+ if (AVH_Common::getWordpressVersion() >= 3.1) {
222
+ add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
223
  } else {
224
+ add_filter('screen_layout_columns', array(&$this, 'filterScreenLayoutColumns'), 10, 2);
225
  }
226
 
227
  // WordPress core Scripts
229
  wp_enqueue_script('wp-lists');
230
  wp_enqueue_script('postbox');
231
 
 
 
 
232
  // WordPress core Styles
233
  wp_admin_css('css/dashboard');
234
 
235
+ // Plugin Style and Scripts
236
  wp_enqueue_style('avhec-admin-css');
237
  }
238
 
239
  /**
240
+ * Setup everything needed for the Manul Order page
 
 
241
  */
242
+ function actionLoadPageHook_ManualOrder() {
 
 
243
 
244
+ add_meta_box('avhecBoxManualOrder',
245
+ __('Manually Order Categories', 'avh-ec'),
246
+ array(&$this, 'metaboxManualOrder'),
247
+ $this->hooks['menu_manual_order'],
248
+ 'normal',
249
+ 'core');
250
 
251
+ if (AVH_Common::getWordpressVersion() >= 3.1) {
252
+ add_screen_option('layout_columns', array('max' => 1, 'default' => 1));
253
+ } else {
254
+ add_filter('screen_layout_columns', array(&$this, 'filterScreenLayoutColumns'), 10, 2);
 
 
 
 
255
  }
256
 
257
+ // WordPress core Styles and Scripts
258
+ wp_enqueue_script('common');
259
+ wp_enqueue_script('wp-lists');
260
+ wp_enqueue_script('postbox');
261
+ wp_enqueue_script('jquery-ui-sortable');
262
+ wp_enqueue_script('avhec-manualorder');
 
 
 
 
 
 
 
 
 
 
263
 
264
+ // WordPress core Styles
265
+ wp_admin_css('css/dashboard');
266
 
267
+ // Plugin Style
268
+ wp_enqueue_style('avhec-admin-css');
 
269
  }
270
 
271
  /**
272
+ * Setup everything needed for the Overview page
 
273
  */
274
+ function actionLoadPageHook_Overview() {
 
275
  // Add metaboxes
276
+ add_meta_box('avhecBoxCategoryGroupList',
277
+ __('Group Overview', 'avh-ec'),
278
+ array(&$this, 'metaboxCategoryGroupList'),
279
+ $this->hooks['menu_overview'],
280
+ 'normal',
281
+ 'core');
282
+ add_meta_box('avhecBoxTranslation',
283
+ __('Translation', 'avh-ec'),
284
+ array(&$this, 'metaboxTranslation'),
285
+ $this->hooks['menu_overview'],
286
+ 'normal',
287
+ 'core');
288
+
289
+ if (AVH_Common::getWordpressVersion() >= 3.1) {
290
+ add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
291
  } else {
292
+ add_filter('screen_layout_columns', array(&$this, 'filterScreenLayoutColumns'), 10, 2);
293
  }
294
 
295
  // WordPress core Scripts
297
  wp_enqueue_script('wp-lists');
298
  wp_enqueue_script('postbox');
299
 
300
+ // Plugin Scripts
301
+ wp_enqueue_script('avhec-categorygroup-js');
302
+
303
  // WordPress core Styles
304
  wp_admin_css('css/dashboard');
305
 
306
+ // Plugin Style
307
  wp_enqueue_style('avhec-admin-css');
 
308
  }
309
 
310
  /**
311
+ * Setup everything needed for the FAQ page
 
 
312
  */
313
+ function actionLoadPageHook_faq() {
314
+
315
+ add_meta_box('avhecBoxFAQ',
316
+ __('F.A.Q.', 'avh-ec'),
317
+ array(&$this, 'metaboxFAQ'),
318
+ $this->hooks['menu_faq'],
319
+ 'normal',
320
+ 'core');
321
+ add_meta_box('avhecBoxTranslation',
322
+ __('Translation', 'avh-ec'),
323
+ array(&$this, 'metaboxTranslation'),
324
+ $this->hooks['menu_faq'],
325
+ 'normal',
326
+ 'core');
327
+
328
+ if (AVH_Common::getWordpressVersion() >= 3.1) {
329
+ add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
330
+ } else {
331
+ add_filter('screen_layout_columns', array(&$this, 'filterScreenLayoutColumns'), 10, 2);
332
  }
333
 
334
+ // WordPress core Styles and Scripts
335
+ wp_enqueue_script('common');
336
+ wp_enqueue_script('wp-lists');
337
+ wp_enqueue_script('postbox');
338
 
339
+ // WordPress core Styles
340
+ wp_admin_css('css/dashboard');
341
 
342
+ // Plugin Style
343
+ wp_enqueue_style('avhec-admin-css');
344
+ }
345
 
346
+ /**
347
+ * Enqueues the style on the post.php and page.php pages
348
+ *
349
+ * @WordPress Action load-$pagenow
350
+ */
351
+ function actionLoadPostPage() {
352
+ wp_enqueue_style('avhec-admin-css');
353
+ }
354
 
355
+ /**
356
+ * Ajax Helper: inline delete of the groups
357
+ */
358
+ function ajaxDeleteGroup() {
359
+ $group_id = isset($_POST['id']) ? (int) $_POST['id'] : 0;
360
+ check_ajax_referer('delete-avhecgroup_' . $group_id);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
361
 
362
+ if ( ! current_user_can('manage_categories')) {
363
+ die('-1');
364
  }
365
+ $check = $this->catgrp->getGroup($group_id);
366
+ if (false === $check) {
367
+ die('1');
 
 
 
 
368
  }
369
 
370
+ if ($this->catgrp->doDeleteGroup($group_id)) {
371
+ die('1');
372
+ } else {
373
+ die('0');
 
 
 
 
374
  }
375
+ }
 
 
 
 
376
 
377
+ /**
378
+ * Adds Category Group form
379
+ *
380
+ * @WordPress action category_edit_form
381
+ *
382
+ * @param unknown_type $term
383
+ * @param unknown_type $taxonomy
384
+ */
385
+ function displayCategoryGroupForm($term, $taxonomy) {
 
 
 
 
 
 
386
 
387
+ $current_selection = '';
388
+ $tax_meta = get_option($this->core->db_options_tax_meta);
389
+ if (isset($tax_meta[ $taxonomy ][ $term->term_id ])) {
390
+ $tax_meta = $tax_meta[ $taxonomy ][ $term->term_id ];
391
+ $current_selection = $tax_meta['category_group_term_id'];
392
+ }
 
 
 
393
 
394
+ if (empty($current_selection)) {
395
+ $current_group = $this->catgrp->getGroupByCategoryID($term->term_id);
396
+ $current_selection = $current_group->term_id;
397
+ }
398
 
399
+ $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false));
400
+ foreach ($cat_groups as $group) {
401
+ $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit');
402
+ $dropdown_value[] = $group->term_id;
403
+ $dropdown_text[] = $temp_cat->name;
404
+ }
405
 
406
+ foreach ($dropdown_value as $key => $sel) {
407
+ $seldata .= '<option value="' .
408
+ esc_attr($sel) .
409
+ '" ' .
410
+ (($current_selection == $sel) ? 'selected="selected"' : '') .
411
+ ' >' .
412
+ esc_html(ucfirst($dropdown_text[ $key ])) .
413
+ '</option>' .
414
+ "\n";
415
+ }
416
 
417
+ echo '<h3>AVH Extended Categories - Category Group Widget</h3>';
418
+ echo '<table class="form-table"><tbody>';
419
+ echo '<tr class="form-field">';
420
+ echo '<th valign="top" scope="row">';
421
+ echo '<label for="avhec_categorygroup">Category Group</label></th>';
422
+ echo '<td>';
423
+ echo '<select id="avhec_categorygroup" name="avhec_categorygroup">';
424
+ echo $seldata;
425
+ echo '</select>';
426
+ echo '<p class="description">Select the category group to show on the archive page.</p>';
427
+ echo '</td>';
428
+ echo '</tr>';
429
+ echo '</tbody></table>';
430
  }
431
 
432
  /**
433
+ * Displays the icon on the menu pages
434
  *
435
+ * @param $icon
436
  */
437
+ function displayIcon($icon) {
438
+ return ('<div class="icon32" id="icon-' . $icon . '"><br/></div>');
 
439
  }
440
 
441
  /**
442
+ * Display WP alert
 
443
  */
444
+ function displayMessage() {
445
+ if ($this->message != '') {
446
+ $message = $this->message;
447
+ $status = $this->status;
448
+ $this->message = $this->status = ''; // Reset
449
+ }
450
+ if (isset($message)) {
451
+ $status = ($status != '') ? $status : 'updated fade';
452
+ echo '<div id="message" class="' . $status . '">';
453
+ echo '<p><strong>' . $message . '</strong></p></div>';
 
 
454
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
455
  }
456
 
457
  /**
459
  *
460
  * @return none
461
  */
462
+ function doMenuCategoryGroup() {
 
463
  global $screen_layout_columns;
464
 
465
+ $data_add_group_default = array('name' => '', 'slug' => '', 'widget_title' => '', 'description' => '');
466
+ $data_add_group_new = $data_add_group_default;
467
+
468
+ $options_add_group[] = array(
469
+ 'avhec_add_group[add][name]',
470
+ __('Group Name', 'avh-ec'),
471
+ 'text',
472
+ 20,
473
+ __('The name is used to identify the group.', 'avh-ec')
474
+ );
475
+ $options_add_group[] = array(
476
+ 'avhec_add_group[add][slug]',
477
+ __('Slug Group', 'avh-ec'),
478
+ 'text',
479
+ 20,
480
+ __('The “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.',
481
+ 'avh-ec')
482
+ );
483
+ $options_add_group[] = array(
484
+ 'avhec_add_group[add][widget_title]',
485
+ __('Widget Title', 'avh-ec'),
486
+ 'text',
487
+ 20,
488
+ __('When no title is given in the widget options, this will used as the title of the widget when this group is shown.',
489
+ 'avh-ec')
490
+ );
491
+ $options_add_group[] = array(
492
+ 'avhec_add_group[add][description]',
493
+ __('Description', 'avh-ec'),
494
+ 'textarea',
495
+ 40,
496
+ __('Description is not prominent by default.', 'avh-ec'),
497
+ 5
498
+ );
499
+
500
+ $options_edit_group[] = array(
501
+ 'avhec_edit_group[edit][name]',
502
+ __('Group Name', 'avh-ec'),
503
+ 'text',
504
+ 20,
505
+ __('The name is used to identify the group.', 'avh-ec')
506
+ );
507
+ $options_edit_group[] = array(
508
+ 'avhec_edit_group[edit][slug]',
509
+ __('Slug Group', 'avh-ec'),
510
+ 'text',
511
+ 20,
512
+ __('The “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.',
513
+ 'avh-ec')
514
+ );
515
+ $options_edit_group[] = array(
516
+ 'avhec_edit_group[edit][widget_title]',
517
+ __('Widget Title', 'avh-ec'),
518
+ 'text',
519
+ 20,
520
+ __('When no title is given in the widget options, this will used as the title of the widget when this group is shown.',
521
+ 'avh-ec')
522
+ );
523
+ $options_edit_group[] = array(
524
+ 'avhec_edit_group[edit][description]',
525
+ __('Description', 'avh-ec'),
526
+ 'textarea',
527
+ 40,
528
+ __('Description is not prominent by default.', 'avh-ec'),
529
+ 5
530
+ );
531
+ $options_edit_group[] = array(
532
+ 'avhec_edit_group[edit][categories]',
533
+ __('Categories', 'avh-ec'),
534
+ 'catlist',
535
+ 0,
536
+ __('Select categories to be included in the group.', 'avh-ec')
537
+ );
538
 
539
  if (isset($_POST['addgroup'])) {
540
  check_admin_referer('avh_ec_addgroup');
541
 
542
  $formoptions = $_POST['avhec_add_group'];
543
 
544
+ $data_add_group_new['name'] = $formoptions['add']['name'];
545
+ $data_add_group_new['slug'] = empty($formoptions['add']['slug']) ? sanitize_title($data_add_group_new['name']) : sanitize_title($formoptions['add']['slug']);
546
  $data_add_group_new['widget_title'] = $formoptions['add']['widget_title'];
547
+ $data_add_group_new['description'] = $formoptions['add']['description'];
548
 
549
  $id = $this->catgrp->getTermIDBy('slug', $data_add_group_new['slug']);
550
+ if ( ! $id) {
551
+ $group_id = $this->catgrp->doInsertGroup($data_add_group_new['name'],
552
+ array(
553
+ 'description' => $data_add_group_new['description'],
554
+ 'slug' => $data_add_group_new['slug']
555
+ ),
556
+ $data_add_group_new['widget_title']);
557
  $this->catgrp->setCategoriesForGroup($group_id);
558
+ $this->message = __('Category group saved', 'avh-ec');
559
+ $this->status = 'updated fade';
560
  $data_add_group_new = $data_add_group_default;
 
561
  } else {
562
+ $group = $this->catgrp->getGroup($id);
563
  $this->message = __('Category group conflicts with ', 'avh-ec') . $group->name;
564
  $this->message .= '<br />' . __('Same slug is used. ', 'avh-ec');
565
  $this->status = 'error';
 
566
  }
567
  $this->displayMessage();
568
  }
569
  $data_add_group['add'] = $data_add_group_new;
570
+ $data['add'] = array('form' => $options_add_group, 'data' => $data_add_group);
571
 
572
  if (isset($_GET['action'])) {
573
  $action = $_GET['action'];
574
 
575
  switch ($action) {
576
  case 'edit':
577
+ $group_id = (int) $_GET['group_ID'];
578
+ $group = $this->catgrp->getGroup($group_id);
579
  $widget_title = $this->catgrp->getWidgetTitleForGroup($group_id);
580
+ $cats = $this->catgrp->getCategoriesFromGroup($group_id);
581
+
582
+ $data_edit_group['edit'] = array(
583
+ 'group_id' => $group_id,
584
+ 'name' => $group->name,
585
+ 'slug' => $group->slug,
586
+ 'widget_title' => $widget_title,
587
+ 'description' => $group->description,
588
+ 'categories' => $cats
589
+ );
590
+ $data['edit'] = array('form' => $options_edit_group, 'data' => $data_edit_group);
591
+
592
+ add_meta_box('avhecBoxCategoryGroupEdit',
593
+ __('Edit Group', 'avh-ec') . ': ' . $group->name,
594
+ array(&$this, 'metaboxCategoryGroupEdit'),
595
+ $this->hooks['menu_category_groups'],
596
+ 'normal',
597
+ 'low');
598
  break;
599
  case 'delete':
600
+ if ( ! isset($_GET['group_ID'])) {
601
  wp_redirect($this->getBackLink());
602
  exit();
603
  }
605
  $group_id = (int) $_GET['group_ID'];
606
  check_admin_referer('delete-avhecgroup_' . $group_id);
607
 
608
+ if ( ! current_user_can('manage_categories')) {
609
  wp_die(__('Cheatin&#8217; uh?'));
610
  }
611
  $this->catgrp->doDeleteGroup($group_id);
619
  if (isset($_POST['editgroup'])) {
620
  check_admin_referer('avh_ec_editgroup');
621
 
622
+ $formoptions = $_POST['avhec_edit_group'];
623
  $selected_categories = $_POST['post_category'];
624
 
625
  $group_id = (int) $_POST['avhec-group_id'];
626
+ $result = $this->catgrp->doUpdateGroup($group_id,
627
+ array(
628
+ 'name' => $formoptions['edit']['name'],
629
+ 'slug' => $formoptions['edit']['slug'],
630
+ 'description' => $formoptions['edit']['description']
631
+ ),
632
+ $selected_categories,
633
+ $formoptions['edit']['widget_title']);
634
  switch ($result) {
635
  case 1:
636
  $this->message = __('Category group updated', 'avh-ec');
637
+ $this->status = 'updated fade';
638
  break;
639
  case 0:
640
  $this->message = __('Category group not updated', 'avh-ec');
643
  break;
644
  case - 1:
645
  $this->message = __('Unknown category group', 'avh-ec');
646
+ $this->status = 'error';
647
  break;
648
  }
649
  $this->displayMessage();
665
  check_admin_referer('avh_ec_specialpagesgroup');
666
 
667
  $formoptions = $_POST['avhec_special_pages'];
668
+ $formdata = $formoptions['sp'];
669
  foreach ($formdata as $key => $value) {
670
+ $data_special_pages_new[ $key ] = $value;
671
  }
672
  $this->core->options['sp_cat_group'] = $data_special_pages_new;
673
  $this->core->saveOptions($this->core->options);
 
674
  }
675
  $data_special_pages['sp'] = $data_special_pages_new;
676
+ $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false));
677
 
678
  foreach ($cat_groups as $group) {
679
+ $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit');
680
  $dropdown_value[] = $group->term_id;
681
+ $dropdown_text[] = $temp_cat->name;
682
  }
683
+ $options_special_pages[] = array(
684
+ 'avhec_special_pages[sp][home_group]',
685
+ __('Home page', 'avh-ec'),
686
+ 'dropdown',
687
+ $dropdown_value,
688
+ $dropdown_text,
689
+ sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('home', 'avhec'))
690
+ );
691
  //$options_special_pages[] = array('avhec_special_pages[sp][category_group]', __('Category Archive', 'avh-ec'), 'dropdown', $dropdown_value, $dropdown_text, sprintf(__('Select which category to show on the %s page.','avh-ec'),__('category archive','avhec')));
692
+ $options_special_pages[] = array(
693
+ 'avhec_special_pages[sp][day_group]',
694
+ __('Daily Archive', 'avh-ec'),
695
+ 'dropdown',
696
+ $dropdown_value,
697
+ $dropdown_text,
698
+ sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('daily archive', 'avhec'))
699
+ );
700
+ $options_special_pages[] = array(
701
+ 'avhec_special_pages[sp][month_group]',
702
+ __('Monthly Archive', 'avh-ec'),
703
+ 'dropdown',
704
+ $dropdown_value,
705
+ $dropdown_text,
706
+ sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('monthly archive', 'avhec'))
707
+ );
708
+ $options_special_pages[] = array(
709
+ 'avhec_special_pages[sp][year_group]',
710
+ __('Yearly Archive', 'avh-ec'),
711
+ 'dropdown',
712
+ $dropdown_value,
713
+ $dropdown_text,
714
+ sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('yearly archive', 'avhec'))
715
+ );
716
+ $options_special_pages[] = array(
717
+ 'avhec_special_pages[sp][author_group]',
718
+ __('Author Archive', 'avh-ec'),
719
+ 'dropdown',
720
+ $dropdown_value,
721
+ $dropdown_text,
722
+ sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('author archive', 'avhec'))
723
+ );
724
+ $options_special_pages[] = array(
725
+ 'avhec_special_pages[sp][search_group]',
726
+ __('Search Page', 'avh-ec'),
727
+ 'dropdown',
728
+ $dropdown_value,
729
+ $dropdown_text,
730
+ sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('search', 'avhec'))
731
+ );
732
+
733
+ $data['sp'] = array('form' => $options_special_pages, 'data' => $data_special_pages);
734
 
735
  // This box can't be unselectd in the the Screen Options
736
  //add_meta_box( 'avhecBoxDonations', __( 'Donations', 'avh-ec' ), array (&$this, 'metaboxDonations' ), $this->hooks['menu_category_groups'], 'side', 'core' );
737
 
 
738
  echo '<div class="wrap avhec-metabox-wrap">';
739
  echo $this->displayIcon('index');
740
  echo '<h2>' . 'AVH Extended Categories - ' . __('Category Groups', 'avh-ec') . '</h2>';
755
  echo ' </div>'; //dashboard-widgets-wrap
756
  echo '</div>'; // wrap
757
 
 
758
  $this->printMetaboxGeneralNonces();
759
  $this->printMetaboxJS('grouped');
760
  $this->printAdminFooter();
761
  }
762
 
763
  /**
764
+ * Menu Page FAQ
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
765
  *
766
  * @return none
767
  */
768
+ function doMenuFAQ() {
 
769
  global $screen_layout_columns;
770
 
771
+ // This box can't be unselectd in the the Screen Options
772
+ add_meta_box('avhecBoxAnnouncements',
773
+ __('Announcements', 'avh-ec'),
774
+ array(&$this, 'metaboxAnnouncements'),
775
+ $this->hooks['menu_faq'],
776
+ 'side',
777
+ 'core');
778
+ add_meta_box('avhecBoxDonations',
779
+ __('Donations', 'avh-ec'),
780
+ array(&$this, 'metaboxDonations'),
781
+ $this->hooks['menu_faq'],
782
+ 'side',
783
+ 'core');
784
+
785
  $hide2 = '';
786
  switch ($screen_layout_columns) {
787
  case 2:
792
  $hide2 = 'display:none;';
793
  }
794
 
795
+ echo '<div class="wrap avhec-metabox-wrap">';
796
  echo $this->displayIcon('index');
797
+ echo '<h2>' . 'AVH Extended Categories - ' . __('F.A.Q', 'avh-ec') . '</h2>';
798
+ echo ' <div id="dashboard-widgets-wrap">';
799
+ echo ' <div id="dashboard-widgets" class="metabox-holder">';
800
  echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
801
+ do_meta_boxes($this->hooks['menu_faq'], 'normal', '');
802
  echo ' </div>';
803
+ echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n";
804
+ do_meta_boxes($this->hooks['menu_faq'], 'side', '');
805
+ echo ' </div>';
806
+ echo ' </div>';
807
+ echo '<br class="clear"/>';
808
+ echo ' </div>'; //dashboard-widgets-wrap
809
  echo '</div>'; // wrap
 
810
 
811
  $this->printMetaboxGeneralNonces();
812
+ $this->printMetaboxJS('faq');
813
  $this->printAdminFooter();
814
  }
815
 
816
  /**
817
+ * Menu Page General Options
818
  *
819
+ * @return none
820
  */
821
+ function doMenuGeneral() {
822
+ global $screen_layout_columns;
 
 
 
823
 
824
+ $groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false));
825
+ foreach ($groups as $group) {
826
+ $group_id[] = $group->term_id;
827
+ $groupname[] = $group->name;
828
  }
829
 
830
+ $options_general[] = array(
831
+ 'avhec[general][alternative_name_select_category]',
832
+ __('<em>Select Category</em> Alternative', 'avh-ec'),
833
+ 'text',
834
+ 20,
835
+ __('Alternative text for Select Category.', 'avh-ec')
836
+ );
837
+ $options_general[] = array(
838
+ 'avhec[cat_group][home_group]',
839
+ 'Home Group',
840
+ 'dropdown',
841
+ $group_id,
842
+ $groupname,
843
+ __('Select which group to show on the home page.', 'avh-ec') .
844
+ '<br />' .
845
+ __('Selecting the group \'none\' will not show the widget on the page.', 'avh-ec')
846
+ );
847
+ $options_general[] = array(
848
+ 'avhec[cat_group][no_group]',
849
+ 'Nonexistence Group',
850
+ 'dropdown',
851
+ $group_id,
852
+ $groupname,
853
+ __('Select which group to show when there is no group associated with the post.', 'avh-ec') .
854
+ '<br />' .
855
+ __('Selecting the group \'none\' will not show the widget on the page.', 'avh-ec')
856
+ );
857
+ $options_general[] = array(
858
+ 'avhec[cat_group][default_group]',
859
+ 'Default Group',
860
+ 'dropdown',
861
+ $group_id,
862
+ $groupname,
863
+ __('Select which group will be the default group when editing a post.', 'avh-ec') .
864
+ '<br />' .
865
+ __('Selecting the group \'none\' will not show the widget on the page.', 'avh-ec')
866
+ );
867
 
868
+ if (isset($_POST['updateoptions'])) {
869
+ check_admin_referer('avh_ec_generaloptions');
 
870
 
871
+ $formoptions = $_POST['avhec'];
872
+ $options = $this->core->getOptions();
 
873
 
874
+ //$all_data = array_merge( $options_general );
875
+ $all_data = $options_general;
876
+ foreach ($all_data as $option) {
877
+ $section = substr($option[0], strpos($option[0], '[') + 1);
878
+ $section = substr($section, 0, strpos($section, ']['));
879
+ $option_key = rtrim($option[0], ']');
880
+ $option_key = substr($option_key, strpos($option_key, '][') + 2);
881
 
882
+ switch ($section) {
883
+ case 'general':
884
+ case 'cat_group':
885
+ $current_value = $options[ $section ][ $option_key ];
886
+ break;
887
+ }
888
+ // Every field in a form is set except unchecked checkboxes. Set an unchecked checkbox to 0.
889
+ $newval = (isset($formoptions[ $section ][ $option_key ]) ? attribute_escape($formoptions[ $section ][ $option_key ]) : 0);
890
+ if ($newval != $current_value) { // Only process changed fields.
891
+ switch ($section) {
892
+ case 'general':
893
+ case 'cat_group':
894
+ $options[ $section ][ $option_key ] = $newval;
895
+ break;
896
+ }
897
+ }
898
  }
899
+ $this->core->saveOptions($options);
900
+ $this->message = __('Options saved', 'avh-ec');
901
+ $this->status = 'updated fade';
902
  }
903
+ $this->displayMessage();
904
 
905
+ $actual_options = $this->core->getOptions();
906
+ foreach ($actual_options['cat_group'] as $key => $value) {
907
+ if ( ! (in_array($value, (array) $group_id))) {
908
+ $actual_options['cat_group'][ $key ] = $this->catgrp->getTermIDBy('slug', 'none');
909
+ }
910
  }
911
 
912
+ $hide2 = '';
913
+ switch ($screen_layout_columns) {
914
+ case 2:
915
+ $width = 'width:49%;';
916
+ break;
917
+ default:
918
+ $width = 'width:98%;';
919
+ $hide2 = 'display:none;';
 
 
 
 
 
920
  }
921
+ $data['options_general'] = $options_general;
922
+ $data['actual_options'] = $actual_options;
 
 
 
 
 
 
923
 
924
+ // This box can't be unselectd in the the Screen Options
925
+ add_meta_box('avhecBoxDonations',
926
+ __('Donations', 'avh-ec'),
927
+ array(&$this, 'metaboxDonations'),
928
+ $this->hooks['menu_general'],
929
+ 'side',
930
+ 'core');
931
 
932
+ $hide2 = '';
933
+ switch ($screen_layout_columns) {
934
+ case 2:
935
+ $width = 'width:49%;';
936
+ break;
937
+ default:
938
+ $width = 'width:98%;';
939
+ $hide2 = 'display:none;';
940
  }
941
 
942
+ echo '<div class="wrap avhec-metabox-wrap">';
943
+ echo $this->displayIcon('index');
944
+ echo '<h2>' . 'AVH Extended Categories - ' . __('General Options', 'avh-ec') . '</h2>';
945
+ echo '<form name="avhec-generaloptions" id="avhec-generaloptions" method="POST" action="' .
946
+ admin_url('admin.php?page=avhec-general') .
947
+ '" accept-charset="utf-8" >';
948
+ wp_nonce_field('avh_ec_generaloptions');
949
 
950
+ echo ' <div id="dashboard-widgets-wrap">';
951
+ echo ' <div id="dashboard-widgets" class="metabox-holder">';
952
+ echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
953
+ do_meta_boxes($this->hooks['menu_general'], 'normal', $data);
954
+ echo " </div>";
955
+ echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n";
956
+ do_meta_boxes($this->hooks['menu_general'], 'side', $data);
957
+ echo ' </div>';
958
+ echo ' </div>';
959
 
960
+ echo '<br class="clear"/>';
961
+ echo ' </div>'; //dashboard-widgets-wrap
962
+ echo '<p class="submit"><input class="button" type="submit" name="updateoptions" value="' .
963
+ __('Save Changes', 'avhf-ec') .
964
+ '" /></p>';
965
+ echo '</form>';
966
 
967
+ echo '</div>'; // wrap
968
+
969
+ $this->printMetaboxGeneralNonces();
970
+ $this->printMetaboxJS('general');
971
+ $this->printAdminFooter();
972
  }
973
 
974
  /**
975
+ * Menu Page Manual Order
976
  *
977
+ * @return none
978
  */
979
+ function doMenuManualOrder() {
980
+ global $screen_layout_columns;
 
 
 
981
 
982
+ $hide2 = '';
983
+ switch ($screen_layout_columns) {
984
+ case 2:
985
+ $width = 'width:49%;';
986
+ break;
987
+ default:
988
+ $width = 'width:98%;';
989
+ $hide2 = 'display:none;';
990
  }
991
 
992
+ echo '<div class="wrap">';
993
+ echo $this->displayIcon('index');
994
+ echo '<h2>' . 'AVH Extended Categories - ' . __('Manually Order Categories', 'avh-ec') . '</h2>';
 
 
 
 
995
 
996
+ echo '<div class="metabox-holder">';
997
+ echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
998
+ do_meta_boxes($this->hooks['menu_manual_order'], 'normal', '');
999
+ echo ' </div>';
1000
+ echo '</div>';
1001
+ echo '</div>'; // wrap
1002
+ echo '<div class="clear"></div>';
1003
 
1004
+ $this->printMetaboxGeneralNonces();
1005
+ $this->printMetaboxJS('manual_order');
1006
+ $this->printAdminFooter();
1007
  }
1008
 
1009
  /**
1010
+ * Menu Page Overview
1011
  *
1012
  * @return none
1013
  */
1014
+ function doMenuOverview() {
 
1015
  global $screen_layout_columns;
1016
 
1017
  // This box can't be unselectd in the the Screen Options
1018
+ add_meta_box('avhecBoxAnnouncements',
1019
+ __('Announcements', 'avh-ec'),
1020
+ array(&$this, 'metaboxAnnouncements'),
1021
+ $this->hooks['menu_overview'],
1022
+ 'side',
1023
+ '');
1024
+ add_meta_box('avhecBoxDonations',
1025
+ __('Donations', 'avh-ec'),
1026
+ array(&$this, 'metaboxDonations'),
1027
+ $this->hooks['menu_overview'],
1028
+ 'side',
1029
+ '');
1030
 
1031
  $hide2 = '';
1032
  switch ($screen_layout_columns) {
1040
 
1041
  echo '<div class="wrap avhec-metabox-wrap">';
1042
  echo $this->displayIcon('index');
1043
+ echo '<h2>' . 'AVH Extended Categories - ' . __('Overview', 'avh-ec') . '</h2>';
1044
  echo ' <div id="dashboard-widgets-wrap">';
1045
  echo ' <div id="dashboard-widgets" class="metabox-holder">';
1046
  echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
1047
+ do_meta_boxes($this->hooks['menu_overview'], 'normal', '');
1048
+ echo " </div>";
1049
  echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n";
1050
+ do_meta_boxes($this->hooks['menu_overview'], 'side', '');
1051
  echo ' </div>';
1052
  echo ' </div>';
1053
+
1054
  echo '<br class="clear"/>';
1055
  echo ' </div>'; //dashboard-widgets-wrap
1056
  echo '</div>'; // wrap
1057
 
 
1058
  $this->printMetaboxGeneralNonces();
1059
+ $this->printMetaboxJS('overview');
1060
  $this->printAdminFooter();
1061
  }
1062
 
1063
  /**
1064
+ * When not using AJAX, this function is called when the deletion fails.
1065
+ *
1066
+ * @param string $text
1067
+ * @param int $group_id
1068
+ *
1069
+ * @return string
1070
+ * @WordPress Filter explain_nonce_$verb-$noun
1071
+ * @see wp_explain_nonce
1072
  */
1073
+ function filterExplainNonceDeleteGroup($text, $group_id) {
1074
+ $group = get_term($group_id, $this->catgrp->taxonomy_name, OBJECT, 'display');
 
 
 
 
 
 
 
 
 
 
 
1075
 
1076
+ $return = sprintf(__('Your attempt to delete this group: &#8220;%s&#8221; has failed.'), $group->name);
 
1077
 
1078
+ return ($return);
1079
+ }
1080
 
1081
+ /**
1082
+ * Creates a new array for columns headers. Used in print_column_headers. The filter is called from
1083
+ * get_column_headers
1084
+ *
1085
+ * @param $columns
1086
+ *
1087
+ * @return Array
1088
+ * @see print_column_headers, get_column_headers
1089
+ */
1090
+ function filterManageCategoriesGroupColumns($columns) {
1091
+ $categories_group_columns = array(
1092
+ 'name' => __('Name', 'avh-ec'),
1093
+ 'slug' => 'Slug',
1094
+ 'widget-title' => __('Widget Title', 'avh-ec'),
1095
+ 'description' => __('Description', 'avh-ec'),
1096
+ 'cat-in-group' => __('Categories in the group', 'avh-ec')
1097
+ );
1098
+
1099
+ return $categories_group_columns;
1100
+ }
1101
+
1102
+ /**
1103
+ * Adds Settings next to the plugin actions
1104
+ *
1105
+ * @WordPress Filter plugin_action_links_avh-amazon/avh-amazon.php
1106
+ */
1107
+ function filterPluginActions($links, $file) {
1108
+ $settings_link = '<a href="admin.php?page=extended-categories-widget">' . __('Settings', 'avh-ec') . '</a>';
1109
+ array_unshift($links, $settings_link); // before other links
1110
+ return $links;
1111
+ }
1112
+
1113
+ /**
1114
+ * Sets the amount of columns wanted for a particuler screen
1115
+ *
1116
+ * @WordPress filter screen_meta_screen
1117
+ *
1118
+ * @param $screen
1119
+ *
1120
+ * @return strings
1121
+ */
1122
+
1123
+ function filterScreenLayoutColumns($columns, $screen) {
1124
+ switch ($screen) {
1125
+ case $this->hooks['menu_overview']:
1126
+ $columns[ $this->hooks['menu_overview'] ] = 2;
1127
+ break;
1128
+ case $this->hooks['menu_general']:
1129
+ $columns[ $this->hooks['menu_general'] ] = 2;
1130
+ break;
1131
+ case $this->hooks['menu_category_groups']:
1132
+ $columns[ $this->hooks['menu_category_groups'] ] = 2;
1133
+ break;
1134
+ case $this->hooks['menu_faq']:
1135
+ $columns[ $this->hooks['menu_faq'] ] = 2;
1136
+ break;
1137
  }
 
 
1138
 
1139
+ return $columns;
1140
+ }
1141
+
1142
+ /**
1143
+ * Get the backlink for forms
1144
+ *
1145
+ * @return string
1146
+ */
1147
+ function getBackLink() {
1148
+ $page = basename(__FILE__);
1149
+ if (isset($_GET['page']) && ! empty($_GET['page'])) {
1150
+ $page = preg_replace('[^a-zA-Z0-9\.\_\-]', '', $_GET['page']);
1151
+ }
1152
+
1153
+ if (function_exists("admin_url")) {
1154
+ return admin_url(basename($_SERVER["PHP_SELF"])) . "?page=" . $page;
1155
+ } else {
1156
+ return $_SERVER['PHP_SELF'] . "?page=" . $page;
1157
+ }
1158
+ }
1159
+
1160
+ /**
1161
+ * Saves the association Category - Category Group fron the edit taxonomy page
1162
+ *
1163
+ * @WordPress action edit_form.
1164
+ *
1165
+ * @param unknown_type $term_id
1166
+ * @param unknown_type $tt_id
1167
+ * @param unknown_type $taxonomy
1168
+ */
1169
+ function handleEditTerm($term_id, $tt_id, $taxonomy) {
1170
+ $tax_meta = get_option($this->core->db_options_tax_meta);
1171
+ if (isset($_POST['avhec_categorygroup']) &&
1172
+ $tax_meta[ $taxonomy ][ $term_id ]['category_group_term_id'] != $_POST['avhec_categorygroup']
1173
+ ) {
1174
+ $tax_meta[ $taxonomy ][ $term_id ]['category_group_term_id'] = $_POST['avhec_categorygroup'];
1175
+ update_option($this->core->db_options_tax_meta, $tax_meta);
1176
+ }
1177
+ }
1178
+
1179
+ /**
1180
+ * Used in forms to set an option checked
1181
+ *
1182
+ * @param mixed $checked
1183
+ * @param mixed $current
1184
+ *
1185
+ * @return string
1186
+ */
1187
+ function isChecked($checked, $current) {
1188
+ $return = '';
1189
+ if ($checked == $current) {
1190
+ $return = ' checked="checked"';
1191
+ }
1192
+
1193
+ return $return;
1194
+ }
1195
+
1196
+ function metaboxAnnouncements() {
1197
+ $php5 = version_compare('5.2', phpversion(), '<');
1198
  echo '<div class="p">';
1199
+ echo '<span class="b">' . __('PHP4 Support', 'avh-ec') . '</span><br />';
1200
+ echo __('The next major release of the plugin will no longer support PHP4.', 'avh-ec') . '<br />';
1201
+ echo __('It will be written for PHP 5.2 and ', 'avh-ec');
1202
+ if ($php5) {
1203
+ echo __('your blog already runs the needed PHP version. When the new release comes out you can safely update.',
1204
+ 'avh-ec') . '<br />';
1205
  } else {
1206
+ echo __('your blog still runs PHP4. When the new release comes out you can not use it.', 'avh-ec') .
1207
+ '<br />';
1208
+ echo __('I don\'t have a timeline for the next version but consider contacting your host if PHP 5.2 is available.',
1209
+ 'avh-ec') . '<br />';
1210
+ echo __('If your hosts doesn\'t offer PHP 5.2 you might want to consider switching hosts.', 'avh-ec') .
1211
+ '<br />';
1212
+ echo __('A host to consider is ', 'avh-ec') .
1213
+ '<a href="http://www.lunarpages.com/id/pdoes" target="_blank">Lunarpages</a>';
1214
+ echo __('I run my personal blog there and I am very happy with their services. You can get an account with unlimited bandwidth, storage and much more for a low price.',
1215
+ 'avh-ec');
1216
  }
1217
  echo '</div>';
1218
+ }
1219
+
1220
+ /**
1221
+ * Metabox for Adding a group
1222
+ *
1223
+ * @param $data
1224
+ */
1225
+ function metaboxCategoryGroupAdd($data) {
1226
+ echo '<form name="avhec-addgroup" id="avhec-addgroup" method="POST" action="' .
1227
+ $this->getBackLink() .
1228
+ '" accept-charset="utf-8" >';
1229
+ wp_nonce_field('avh_ec_addgroup');
1230
+ echo $this->printOptions($data['add']['form'], $data['add']['data']);
1231
+ echo '<p class="submit"><input class="button" type="submit" name="addgroup" value="' .
1232
+ __('Add group', 'avh-ec') .
1233
+ '" /></p>';
1234
+ echo '</form>';
1235
+ }
1236
+
1237
+ /**
1238
+ * Metabox Category Group Edit
1239
+ */
1240
+ function metaboxCategoryGroupEdit($data) {
1241
+ echo '<form name="avhec-editgroup" id="avhec-editgroup" method="POST" action="' .
1242
+ $this->getBackLink() .
1243
+ '" accept-charset="utf-8" >';
1244
+ wp_nonce_field('avh_ec_editgroup');
1245
+ echo $this->printOptions($data['edit']['form'], $data['edit']['data']);
1246
+ echo '<input type="hidden" value="' .
1247
+ $data['edit']['data']['edit']['group_id'] .
1248
+ '" name="avhec-group_id" id="avhec-group_id">';
1249
+ echo '<p class="submit"><input class="button" type="submit" name="editgroup" value="' .
1250
+ __('Update group', 'avh-ec') .
1251
+ '" /></p>';
1252
+ echo '</form>';
1253
+ }
1254
+
1255
+ /**
1256
+ * Metabox for showing the groups as a list
1257
+ *
1258
+ * @param $data
1259
+ */
1260
+ function metaboxCategoryGroupList($data) {
1261
+ echo '<form id="posts-filter" action="" method="get">';
1262
+
1263
+ echo '<div class="clear"></div>';
1264
+
1265
+ echo '<table class="widefat fixed" cellspacing="0">';
1266
+ echo '<thead>';
1267
+ echo '<tr>';
1268
+ print_column_headers('categories_group');
1269
+ echo '</tr>';
1270
+ echo '</thead>';
1271
+
1272
+ echo '<tfoot>';
1273
+ echo '<tr>';
1274
+ print_column_headers('categories_group', false);
1275
+ echo '</tr>';
1276
+ echo '</tfoot>';
1277
+
1278
+ echo '<tbody id="the-list" class="list:group">';
1279
+ $this->printCategoryGroupRows();
1280
+ echo '</tbody>';
1281
+ echo '</table>';
1282
 
1283
+ echo '<br class="clear" />';
1284
+ echo '</form>';
1285
+ //echo '</div>';
1286
+ }
1287
+
1288
+ /**
1289
+ * Metabox Category Group Special pages
1290
+ */
1291
+ function metaboxCategoryGroupSpecialPages($data) {
1292
+ echo '<form name="avhec-specialpagesgroup" id="avhec-specialpagesgroup" method="POST" action="' .
1293
+ $this->getBackLink() .
1294
+ '" accept-charset="utf-8" >';
1295
+ wp_nonce_field('avh_ec_specialpagesgroup');
1296
+ echo $this->printOptions($data['sp']['form'], $data['sp']['data']);
1297
+ echo '<p class="submit"><input class="button" type="submit" name="spgroup" value="' .
1298
+ __('Save settings', 'avh-ec') .
1299
+ '" /></p>';
1300
+ echo '</form>';
1301
  }
1302
 
1303
+ ############## Admin WP Helper ##############
1304
+
1305
  /**
1306
  * Donation Metabox
1307
+ *
1308
  * @return unknown_type
1309
  */
1310
+ function metaboxDonations() {
 
1311
  echo '<div class="p">';
1312
+ echo __('If you enjoy this plug-in please consider a donation. There are several ways you can show your appreciation.',
1313
+ 'avh-ec');
1314
  echo '</div>';
1315
 
1316
  echo '<div class="p">';
1317
  echo '<span class="b">Amazon</span><br />';
1318
  echo __('If you decide to buy something from Amazon click the button.', 'avh-ec') . '</span><br />';
1319
+ echo '<a href="https://www.amazon.com/?tag=petervanderdoes-20" target="_blank" title="Amazon Homepage"><img alt="Amazon Button" src="' .
1320
+ $this->core->info['graphics_url'] .
1321
+ '/us_banner_logow_120x60.gif" /></a>';
1322
  echo '</div>';
1323
 
1324
  echo '<div class="p">';
1325
+ echo __('You can send me something from my ', 'avh-ec') .
1326
+ '<a href="http://www.amazon.com/registry/wishlist/1U3DTWZ72PI7W?tag=petervanderdoes-20">' .
1327
+ __('Amazon Wish List', 'avh-ec') .
1328
+ '</a>';
1329
  echo '</div>';
1330
 
1331
  echo '<div class="p">';
1332
  echo '<span class="b">' . __('Through Paypal.', 'avh-ec') . '</span><br />';
1333
+ echo __('Click on the Donate button and you will be directed to Paypal where you can make your donation and you don\'t need to have a Paypal account to make a donation.',
1334
+ 'avh-ec') . '<br />';
1335
  echo '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=S85FXJ9EBHAF2&lc=US&item_name=AVH%20Plugins&item_number=fdas&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted" target="_blank" title="Donate">';
1336
  echo '<img src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" alt="Donate"/></a>';
1337
  echo '</div>';
 
1338
  }
1339
 
1340
  /***
1341
  * F.A.Q Metabox
1342
+ *
1343
  * @return none
1344
  */
1345
+ function metaboxFAQ() {
 
1346
  echo '<div class="p">';
1347
  echo '<span class="b">' . __('What about support?', 'avh-ec') . '</span><br />';
1348
+ echo __('I created a support site at http://forums.avirtualhome.com where you can ask questions or request features.',
1349
+ 'avh-ec') . '<br />';
1350
  echo '</div>';
1351
 
1352
  echo '<div class="p">';
1353
  echo '<span class="b">' . __('What is depth selection?', 'avh-ec') . '</span><br />';
1354
+ echo __('Starting with version 2.0 and WordPress 2.8 you can select how many levels deep you want to show your categories. This option only works when you select Show Hierarchy as well.',
1355
+ 'avh-ec') . '<br /><br />';
1356
+ echo __('Here is how it works: Say you have 5 top level categories and each top level has a number of children. You could manually select all the Top Level categories you want to show but now you can do the following:',
1357
+ 'avh-ec') . '<br />';
1358
+ echo __('You select to display all categories, select to Show hierarchy and select how many levels you want to show, in this case Toplevel only.',
1359
+ 'avh-ec') . '<br />';
1360
  echo '</div>';
1361
 
1362
  echo '<div class="p">';
1363
  echo '<span class="b">' . __('Multiple Category Groups', 'avh-ec') . '</span><br />';
1364
+ echo __('The following is an explanation how assigning multiple groups to page/post works.', 'avh-ec') .
1365
+ '<br /><br />';
1366
  echo __('Lets say you have the following groups:', 'avh-ec');
1367
  echo '<ul>';
1368
  echo '<li>' . __('Free Time', 'avh-ec') . '</li>';
1370
  echo '<li>' . __('Movie', 'avh-ec') . '</li>';
1371
  echo '<li>' . __('Music', 'avh-ec') . '</li>';
1372
  echo '</ul>';
1373
+ echo __('Setup several Category Group widgets and associated each widget with one or more groups.', 'avh-ec') .
1374
+ '<br />';
1375
  echo __('Widget 1 has association with Free Time', 'avh-ec') . '<br />';
1376
  echo __('Widget 2 has association with Theater, Movie and Music', 'avh-ec') . '<br />';
1377
  echo __('Widget 3 has association with Theater, Movie and Music', 'avh-ec') . '<br /><br />';
1393
  echo '<li>' . __('Widget 2: Shows categories of the Movie or Music group.', 'avh-ec') . '</li>';
1394
  echo '<li>' . __('Widget 3: Shows categories of the Music or Movie group.', 'avh-ec') . '</li>';
1395
  echo '</ul>';
1396
+ echo __('Whether Widget 2 shows Movie or Music depends on the creation order of groups. If Widget 2 shows Movie, Widget 3 will show Music but if Widget 2 shows Music, Widget 3 will show Movie.',
1397
+ 'avh-ec') . '<br />';
1398
  echo '</div>';
1399
  }
1400
 
1401
+ /**
1402
+ * @return unknown_type
1403
+ */
1404
+ function metaboxManualOrder() {
1405
+ global $wpdb;
1406
+
1407
+ $parentID = 0;
1408
+
1409
+ if (isset($_POST['btnSubCats'])) {
1410
+ $parentID = $_POST['cats'];
1411
+ } elseif (isset($_POST['hdnParentID'])) {
1412
+ $parentID = $_POST['hdnParentID'];
 
 
 
1413
  }
 
1414
 
1415
+ if (isset($_POST['btnReturnParent'])) {
1416
+ $parentsParent = $wpdb->get_row($wpdb->prepare('SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = %d',
1417
+ $_POST['hdnParentID']),
1418
+ ARRAY_N);
1419
+ $parentID = $parentsParent[0];
1420
+ }
1421
 
1422
+ $success = "";
1423
+ if (isset($_POST['btnOrderCats'])) {
1424
+ if (isset($_POST['hdnManualOrder']) && $_POST['hdnManualOrder'] != "") {
 
 
 
 
1425
 
1426
+ $hdnManualOrder = $_POST['hdnManualOrder'];
1427
+ $IDs = explode(",", $hdnManualOrder);
1428
+ $result = count($IDs);
 
 
 
 
 
 
 
 
 
 
 
 
1429
 
1430
+ for ($i = 0; $i < $result; $i ++) {
1431
+ $str = str_replace("id_", "", $IDs[ $i ]);
1432
+ $wpdb->query($wpdb->prepare("UPDATE $wpdb->terms SET avhec_term_order = '$i' WHERE term_id ='$str'"));
1433
+ }
1434
+
1435
+ $success = '<div id="message" class="updated fade"><p>' .
1436
+ __('Categories updated successfully.', 'avh-ec') .
1437
+ '</p></div>';
1438
+ } else {
1439
+ $success = '<div id="message" class="updated fade"><p>' .
1440
+ __('An error occured, order has not been saved.', 'avh-ec') .
1441
+ '</p></div>';
1442
+ }
1443
  }
 
 
1444
 
1445
+ $_SubCategories = "";
1446
+ $results = $wpdb->get_results($wpdb->prepare("SELECT t.term_id, t.name FROM $wpdb->term_taxonomy tt, $wpdb->terms t, $wpdb->term_taxonomy tt2 WHERE tt.parent = $parentID AND tt.taxonomy = 'category' AND t.term_id = tt.term_id AND tt2.parent = tt.term_id GROUP BY t.term_id, t.name HAVING COUNT(*) > 0 ORDER BY t.avhec_term_order ASC"));
1447
+ foreach ($results as $row) {
1448
+ $_SubCategories .= "<option value='$row->term_id'>$row->name</option>";
1449
+ }
1450
+
1451
+ echo '<div class="wrap">';
1452
+ echo '<form name="frmMyCatOrder" method="post" action="">';
1453
+ echo $success;
1454
+
1455
+ echo '<h4>';
1456
+ _e('Order the categories', 'avh-ec');
1457
+ if ($parentID == 0) {
1458
+ echo ' at the Toplevel';
1459
+ } else {
1460
+ $_cats = get_category_parents($parentID, false, ' » ');
1461
+ echo ' in the category ' . trim($_cats, ' » ');
1462
+ }
1463
+ echo '</h4>';
1464
+ echo '<span class="description">';
1465
+ _e('Order the categories on this level by dragging and dropping them into the desired order.', 'avh-ec');
1466
+ echo '</span>';
1467
+ echo '<ul id="avhecManualOrder">';
1468
+ $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->terms t inner join $wpdb->term_taxonomy tt on t.term_id = tt.term_id WHERE taxonomy = 'category' and parent = $parentID ORDER BY avhec_term_order ASC"));
1469
+ foreach ($results as $row) {
1470
+ echo "<li id='id_$row->term_id' class='lineitem menu-item-settings'>" . __($row->name) . "</li>";
1471
+ }
1472
+
1473
+ echo '</ul>';
1474
+ echo '<input type="submit" name="btnOrderCats" id="btnOrderCats" class="button-primary" value="' .
1475
+ __('Save Order', 'avh-ec') .
1476
+ '" onclick="javascript:orderCats(); return true;" />';
1477
+
1478
+ if ($parentID != 0) {
1479
+ echo "<input type='submit' class='button' id='btnReturnParent' name='btnReturnParent' value='" .
1480
+ __('Return to parent category', 'avh-ec') .
1481
+ "' />";
1482
+ }
1483
 
1484
+ echo '<strong id="updateText"></strong><br /><br />';
1485
+ if ($_SubCategories != "") {
1486
+
1487
+ echo '<h4>';
1488
+ _e('Select Subcategory', 'avh-ec');
1489
+ echo '</h4>';
1490
+ echo '<select id="cats" name="cats">';
1491
+ echo $_SubCategories;
1492
+
1493
+ echo '</select><input type="submit" name="btnSubCats" class="button" id="btnSubCats" value="' .
1494
+ __('Select', 'avh-ec') .
1495
+ '" />';
1496
+ echo '<span class="description">';
1497
+ _e('Choose a category from the drop down to order the subcategories in that category.', 'avh-ec');
1498
+ echo '</span>';
1499
+ }
1500
+
1501
+ echo '<input type="hidden" id="hdnManualOrder" name="hdnManualOrder" />';
1502
+ echo '<input type="hidden" id="hdnParentID" name="hdnParentID" value="' . $parentID . '" /></form>';
1503
+ echo '</div>';
1504
  }
1505
 
1506
  /**
1507
+ * Options Metabox
 
 
 
 
1508
  */
1509
+ function metaboxOptions($data) {
1510
+ echo $this->printOptions($data['options_general'], $data['actual_options']);
 
 
1511
  }
1512
 
1513
  /**
1514
+ * Translation Metabox
1515
  *
1516
+ * @return unknown_type
 
 
 
 
1517
  */
1518
+ function metaboxTranslation() {
1519
+ $locale = apply_filters('plugin_locale', get_locale(), 'avh-ec');
1520
+ $available_locale['cs_CZ'] = array('Czech - Čeština', 0);
1521
+ $available_locale['nl_NL'] = array('Dutch - Nederlands', 0);
1522
+ $available_locale['de_DE'] = array('German - Deutsch', 0);
1523
+ $available_locale['el'] = array('Greek - Čeština', 0);
1524
+ $available_locale['id_ID'] = array('Indonesian - Bahasa Indonesia - Čeština', 0);
1525
+ $available_locale['it_IT'] = array('Italian - Italiano', 1);
1526
+ $available_locale['ru_RU'] = array('Russian — Русский', 0);
1527
+ $available_locale['es_ES'] = array('Spanish - Español', 0);
1528
+ $available_locale['sv_SE'] = array('Swedish - Svenska', 0);
1529
+ $available_locale['tr'] = array('Turkish - Türkçe', 0);
1530
 
1531
+ echo '<div class="p">';
1532
+ echo __('This plugin is translated in several languages. Some of the languages might be incomplete. Please help to complete these translations or add a new language.',
1533
+ 'avh-ec') . '<br />';
1534
 
1535
+ echo '</div>';
1536
 
1537
+ echo '<div class="p">';
1538
+ echo '<span class="b">' . __('Available Languages', 'avh-ec') . '</span>';
1539
+ echo '<ul>';
1540
+ foreach ($available_locale as $key => $value) {
1541
+ echo '<li>';
1542
+ $complete = ($value[1] == 1 ? 'Complete' : 'Incomplete');
1543
+ echo $value[0] . ' (' . $key . ') - ' . $complete;
1544
+ echo '</li>';
 
 
1545
  }
1546
+ echo '</ul>';
1547
+ echo '</div>';
1548
 
1549
+ echo '<div class="p">';
1550
+ if ('en_US' != $locale & ( ! array_key_exists($locale, $available_locale))) {
1551
+ echo 'Currently the plugin is not available in your language (' .
1552
+ $locale .
1553
+ '). Why not help out and translate the plugin in your language. You can help by visiting <a href="https://translations.launchpad.net/avhextendedcategories/trunk" target="_blank">Launchpad</a>.';
1554
+ } else {
1555
+ echo __('You can visit ', 'avh-ec') .
1556
+ '<a href="https://translations.launchpad.net/avhextendedcategories/trunk" target="_blank">Launchpad</a> ' .
1557
+ __('to help complete these translations or add a new language.', 'avh-ec');
1558
+ }
1559
+ echo '</div>';
1560
  }
1561
 
1562
  /**
1563
+ * Display plugin Copyright
 
 
 
1564
  */
1565
+ function printAdminFooter() {
1566
+ echo '<p class="footer_avhec">';
1567
+ printf('&copy; Copyright %d <a href="http://blog.avirtualhome.com/" title="My Thoughts">Peter van der Does</a> | AVH Extended Categories Version %s',
1568
+ date('Y'),
1569
+ $this->core->version);
1570
+ echo '</p>';
 
 
 
1571
  }
1572
 
1573
  /**
1577
  * @param int $group_term_id
1578
  * @param int $group_term_taxonomy_id
1579
  */
1580
+ function printCategoryGroupRow($group_term_id, $group_term_taxonomy_id) {
 
1581
  static $row_class = '';
1582
 
1583
  $group = get_term($group_term_id, $this->catgrp->taxonomy_name, OBJECT, 'display');
1584
 
1585
+ $no_edit[ $this->catgrp->getTermIDBy('slug', 'all') ] = 0;
1586
+ $no_delete[ $this->catgrp->getTermIDBy('slug', 'all') ] = 0;
1587
 
1588
  if (current_user_can('manage_categories')) {
1589
  $actions = array();
1590
+ if ( ! array_key_exists($group->term_id, $no_edit)) {
1591
  $edit_link = "admin.php?page=avhec-grouped&amp;action=edit&amp;group_ID=$group->term_id";
1592
+ $edit = "<a class='row-title' href='$edit_link' title='" .
1593
+ esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $group->name)) .
1594
+ "'>" .
1595
+ esc_attr($group->name) .
1596
+ '</a><br />';
1597
 
1598
  $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
1599
  } else {
1600
  $edit = esc_attr($group->name);
1601
  }
1602
+ if ( ! (array_key_exists($group->term_id, $no_delete))) {
1603
+ $actions['delete'] = "<a class='delete:the-list:group-$group->term_id submitdelete' href='" .
1604
+ wp_nonce_url("admin.php?page=avhec-grouped&amp;action=delete&amp;group_ID=$group->term_id",
1605
+ 'delete-avhecgroup_' . $group->term_id) .
1606
+ "'>" .
1607
+ __('Delete') .
1608
+ "</a>";
1609
  }
1610
  $action_count = count($actions);
1611
+ $i = 0;
1612
  $edit .= '<div class="row-actions">';
1613
  foreach ($actions as $action => $link) {
1614
  ++ $i;
1621
  }
1622
 
1623
  $row_class = 'alternate' == $row_class ? '' : 'alternate';
1624
+ $qe_data = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit');
1625
 
1626
  $output = "<tr id='group-$group->term_id' class='iedit $row_class'>";
1627
 
1628
  $columns = get_column_headers('categories_group');
1629
+ $hidden = get_hidden_columns('categories_group');
1630
  foreach ($columns as $column_name => $column_display_name) {
1631
  $class = 'class="' . $column_name . ' column-' . $column_name . '"';
1632
 
1633
  $style = '';
1634
+ if (in_array($column_name, $hidden)) {
1635
  $style = ' style="display:none;"';
1636
+ }
1637
 
1638
  $attributes = $class . $style;
1639
 
1640
  switch ($column_name) {
1641
  case 'cb':
1642
  $output .= '<th scope="row" class="check-column">';
1643
+ if ( ! (array_key_exists($group->term_id, $no_delete))) {
1644
  $output .= '<input type="checkbox" name="delete[]" value="' . $group->term_id . '" />';
1645
  } else {
1646
  $output .= "&nbsp;";
1666
  $output .= "<td $attributes>" . apply_filters('editable_slug', $qe_data->slug) . "</td>";
1667
  break;
1668
  case 'cat-in-group':
1669
+ $cats = $this->catgrp->getCategoriesFromGroup($group_term_id);
1670
  $catname = array();
1671
  foreach ($cats as $cat_id) {
1672
  $catname[] = get_cat_name($cat_id);
1675
  $cat = implode(', ', $catname);
1676
  $output .= '<td ' . $attributes . '>' . $cat . '</td>';
1677
  break;
 
1678
  }
1679
  }
1680
  $output .= '</tr>';
1682
  return $output;
1683
  }
1684
 
1685
+ /**
1686
+ * Print all Category Group rows
1687
+ *
1688
+ * @uses printCategoryGroupRow
1689
+ */
1690
+ function printCategoryGroupRows() {
1691
+ $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false));
1692
+
1693
+ foreach ($cat_groups as $group) {
1694
+ if ('none' != $group->slug) {
1695
+ echo $this->printCategoryGroupRow($group->term_id, $group->term_taxonomy_id);
1696
+ }
1697
+ }
1698
+ }
1699
+
1700
  /**
1701
  * Prints the general nonces, used by the AJAX
1702
  */
1703
+ function printMetaboxGeneralNonces() {
 
1704
  echo '<form style="display:none" method="get" action="">';
1705
  echo '<p>';
1706
  wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1707
  wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1708
  echo '</p>';
1709
  echo '</form>';
 
1710
  }
1711
 
1712
  /**
1714
  *
1715
  * @param $boxid
1716
  */
1717
+ function printMetaboxJS($boxid) {
1718
+ $a = $this->hooks[ 'menu_' . $boxid ];
 
1719
  echo '<script type="text/javascript">' . "\n";
1720
  echo ' //<![CDATA[' . "\n";
1721
  echo ' jQuery(document).ready( function($) {' . "\n";
1725
  echo ' });' . "\n";
1726
  echo ' //]]>' . "\n";
1727
  echo '</script>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1728
  }
1729
 
1730
  /**
1731
  * Ouput formatted options
1732
  *
1733
  * @param array $option_data
1734
+ *
1735
  * @return string
1736
  */
1737
+ function printOptions($option_data, $option_actual) {
 
1738
  // Generate output
1739
  $output = '';
1740
  $output .= "\n" . '<table class="form-table avhec-options">' . "\n";
1741
  foreach ($option_data as $option) {
1742
+ $section = substr($option[0], strpos($option[0], '[') + 1);
1743
+ $section = substr($section, 0, strpos($section, ']['));
1744
  $option_key = rtrim($option[0], ']');
1745
  $option_key = substr($option_key, strpos($option_key, '][') + 2);
1746
  // Helper
1747
  if ($option[2] == 'helper') {
1748
+ $output .= '<tr style="vertical-align: top;"><td class="helper" colspan="2">' .
1749
+ wp_filter_post_kses($option[4]) .
1750
+ '</td></tr>' .
1751
+ "\n";
1752
  continue;
1753
  }
1754
  switch ($option[2]) {
1755
  case 'checkbox':
1756
+ $input_type = '<input type="checkbox" id="' .
1757
+ esc_attr($option[0]) .
1758
+ '" name="' .
1759
+ esc_attr($option[0]) .
1760
+ '" value="' .
1761
+ esc_attr($option[3]) .
1762
+ '" ' .
1763
+ $this->isChecked('1', $option_actual[ $section ][ $option_key ]) .
1764
+ ' />' .
1765
+ "\n";
1766
  $explanation = $option[4];
1767
  break;
1768
  case 'dropdown':
1769
  $selvalue = $option[3];
1770
+ $seltext = $option[4];
1771
+ $seldata = '';
1772
  foreach ((array) $selvalue as $key => $sel) {
1773
+ $seldata .= '<option value="' .
1774
+ esc_attr($sel) .
1775
+ '" ' .
1776
+ (($option_actual[ $section ][ $option_key ] == $sel) ? 'selected="selected"' : '') .
1777
+ ' >' .
1778
+ esc_html(ucfirst($seltext[ $key ])) .
1779
+ '</option>' .
1780
+ "\n";
1781
  }
1782
+ $input_type = '<select id="' .
1783
+ esc_attr($option[0]) .
1784
+ '" name="' .
1785
+ esc_attr($option[0]) .
1786
+ '">' .
1787
+ $seldata .
1788
+ '</select>' .
1789
+ "\n";
1790
  $explanation = $option[5];
1791
  break;
1792
  case 'text-color':
1793
+ $input_type = '<input type="text" ' .
1794
+ (($option[3] > 1) ? ' style="width: 95%" ' : '') .
1795
+ 'id="' .
1796
+ esc_attr($option[0]) .
1797
+ '" name="' .
1798
+ esc_attr($option[0]) .
1799
+ '" value="' .
1800
+ esc_attr($option_actual[ $section ][ $option_key ]) .
1801
+ '" size="' .
1802
+ esc_attr($option[3]) .
1803
+ '" /><div class="box_color ' .
1804
+ esc_attr($option[0]) .
1805
+ '"></div>' .
1806
+ "\n";
1807
  $explanation = $option[4];
1808
  break;
1809
  case 'textarea':
1810
+ $input_type = '<textarea rows="' .
1811
+ esc_attr($option[5]) .
1812
+ '" ' .
1813
+ (($option[3] > 1) ? ' style="width: 95%" ' : '') .
1814
+ 'id="' .
1815
+ esc_attr($option[0]) .
1816
+ '" name="' .
1817
+ esc_attr($option[0]) .
1818
+ '" size="' .
1819
+ esc_attr($option[3]) .
1820
+ '" />' .
1821
+ $option_actual[ $section ][ $option_key ] .
1822
+ '</textarea>';
1823
  $explanation = $option[4];
1824
  break;
1825
  case 'catlist':
1826
  ob_start();
1827
  echo '<div id="avhec-catlist">';
1828
  echo '<ul>';
1829
+ wp_category_checklist(0, 0, $option_actual[ $section ][ $option_key ]);
1830
  echo '</ul>';
1831
  echo '</div>';
1832
  $input_type = ob_get_contents();
1835
  break;
1836
  case 'text':
1837
  default:
1838
+ $input_type = '<input type="text" ' .
1839
+ (($option[3] > 1) ? ' style="width: 95%" ' : '') .
1840
+ 'id="' .
1841
+ esc_attr($option[0]) .
1842
+ '" name="' .
1843
+ esc_attr($option[0]) .
1844
+ '" value="' .
1845
+ esc_attr($option_actual[ $section ][ $option_key ]) .
1846
+ '" size="' .
1847
+ esc_attr($option[3]) .
1848
+ '" />' .
1849
+ "\n";
1850
  $explanation = $option[4];
1851
  break;
1852
  }
1856
  $extra = '<br /><span class="description">' . wp_filter_kses($explanation) . '</span>' . "\n";
1857
  }
1858
  // Output
1859
+ $output .= '<tr style="vertical-align: top;"><th align="left" scope="row"><label for="' .
1860
+ esc_attr($option[0]) .
1861
+ '">' .
1862
+ wp_filter_kses($option[1]) .
1863
+ '</label></th><td>' .
1864
+ $input_type .
1865
+ ' ' .
1866
+ $extra .
1867
+ '</td></tr>' .
1868
+ "\n";
1869
  }
1870
  $output .= '</table>' . "\n";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1871
 
1872
+ return $output;
 
 
 
 
1873
  }
1874
  }
1875
+
1876
  ?>
2.8/class/avh-ec.category-group.php CHANGED
@@ -5,42 +5,29 @@
5
  *
6
  * @author Peter van der Does
7
  */
8
- class AVH_EC_Category_Group
9
- {
 
10
  /**
11
  * Taxonomy name
 
12
  * @var string
13
  */
14
  var $taxonomy_name;
15
-
16
- var $db_options_widget_titles;
17
-
18
- var $options_widget_titles;
19
-
20
  var $widget_done_catgroup;
21
 
22
- /**
23
- * PHP4 constructor.
24
- *
25
- */
26
- function AVH_EC_Category_Group ()
27
- {
28
- return $this->__construct();
29
- }
30
-
31
  /**
32
  * PHP5 Constructor
33
  * Init the Database Abstraction layer
34
- *
35
  */
36
- function __construct ()
37
- {
38
  global $wpdb;
39
 
40
  register_shutdown_function(array(&$this, '__destruct'));
41
 
42
  /**
43
  * Taxonomy name
 
44
  * @var string
45
  */
46
  $this->taxonomy_name = 'avhec_catgroup';
@@ -51,16 +38,25 @@ class AVH_EC_Category_Group
51
 
52
  /**
53
  * Create the table if it doesn't exist.
54
- *
55
  */
56
  if ($wpdb->get_var('show tables like \'' . $wpdb->avhec_cat_group . '\'') != $wpdb->avhec_cat_group) {
57
- add_action('init', array(&$this, 'doCreateTable'), 2); // Priority needs to be the same as the Register Taxonomy
 
 
58
  }
59
- add_action('init', array(&$this, 'doRegisterTaxonomy'), 2); // Priority for registering custom taxonomies is +1 over the creation of the initial taxonomies
 
 
60
  add_action('init', array(&$this, 'doSetupOptions'));
61
 
62
  add_action('admin_init', array(&$this, 'addMetaBoxes'));
 
63
 
 
 
 
 
 
64
  }
65
 
66
  /**
@@ -68,65 +64,181 @@ class AVH_EC_Category_Group
68
  *
69
  * @return bool Always true
70
  */
71
- function __destruct ()
72
- {
73
  return true;
74
  }
75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  /**
77
  * Create Table
78
- * @WordPress action init
79
  *
 
80
  */
81
- function doCreateTable ()
82
- {
83
  global $wpdb;
84
 
85
  // Setup the DB Tables
86
  $charset_collate = '';
87
 
88
  if (version_compare(mysql_get_server_info(), '4.1.0', '>=')) {
89
- if (! empty($wpdb->charset))
90
  $charset_collate = 'DEFAULT CHARACTER SET ' . $wpdb->charset;
91
- if (! empty($wpdb->collate))
 
92
  $charset_collate .= ' COLLATE ' . $wpdb->collate;
 
93
  }
94
 
95
- $sql = 'CREATE TABLE `' . $wpdb->avhec_cat_group . '` ( `group_term_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, `term_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (`group_term_id`, `term_id`) )' . $charset_collate . ';';
 
 
 
 
96
 
97
  $result = $wpdb->query($sql);
98
  }
99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  /**
101
  * Setup Group Categories Taxonomy
102
- * @WordPress action init
103
  *
 
104
  */
105
- function doRegisterTaxonomy ()
106
- {
107
  /**
108
  * As we don't want to see the Menu Item we have to disable show_ui. This also disables the metabox on the posts and pages, so we add thse manually instead.
109
  * We remove the capabilities to manage, edit and delete the terms. We have written this part ourselves and don't use WordPress for these functions. The only one we use is the assign_terms.
110
  */
111
- $labels = array('name'=>__('Category Groups', 'avh-ec'), 'singular_name'=>__('Category Group', 'avh-ec'), 'search_items'=>__('Search Category Groups', 'avh-ec'), 'popular_items'=>__('Popular Category Groups'), 'all_items'=>__('All Category Groups'), 'parent_item'=>__('Parent Category Group'), 'parent_item_colon'=>__('Parent Category Group:'), 'edit_item'=>__('Edit Category Group'), 'update_item'=>__('Update Category Group'), 'add_new_item'=>__('Add New Category Group'), 'new_item_name'=>__('New Category Group Name'));
112
- $caps = array('manage_terms'=>null, 'edit_terms'=>null, 'delete_terms'=>null, 'assign_terms'=>'edit_posts');
113
- register_taxonomy($this->taxonomy_name, array('post', 'page'), array('hierarchical'=>TRUE, 'labels'=>$labels, 'query_var'=>TRUE, 'rewrite'=>TRUE, 'show_in_nav_menus'=>FALSE, 'public'=>TRUE, 'show_ui'=>FALSE, 'capabilities'=>$caps));
114
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  }
116
 
117
  /**
118
  * Setup the options for the widget titles
119
- * @WordPress action init
120
  *
 
121
  */
122
- function doSetupOptions ()
123
- {
124
  // Setup the standard groups if the none group does not exists.
125
  $all_categories = $this->getAllCategoriesTermID();
126
  if (false === $this->getTermIDBy('slug', 'none')) {
127
- $none_group_id = wp_insert_term('none', $this->taxonomy_name, array('description'=>__('This group will not show the widget.', 'avh-ec')));
128
- $all_group_id = wp_insert_term('All', $this->taxonomy_name, array('description'=>__('Holds all the categories.', 'avh-ec')));
129
- $home_group_id = wp_insert_term('Home', $this->taxonomy_name, array('description'=>__('This group will be shown on the front page.', 'avh-ec')));
 
 
 
 
 
 
 
 
 
 
 
130
 
131
  // Fill the standard groups with all categories
132
  $this->setCategoriesForGroup($home_group_id['term_id'], $all_categories);
@@ -135,12 +247,12 @@ class AVH_EC_Category_Group
135
  }
136
 
137
  $options = get_option($this->db_options_widget_titles);
138
- if (! $options) {
139
- $options = array();
140
- $id = $this->getTermIDBy('slug', 'all');
141
- $options[$id] = '';
142
- $id = $this->getTermIDBy('slug', 'home');
143
- $options[$id] = '';
144
  update_option($this->db_options_widget_titles, $options);
145
  }
146
  $this->options_widget_titles = $options;
@@ -148,14 +260,30 @@ class AVH_EC_Category_Group
148
  }
149
 
150
  /**
151
- * Add the metaboxes for the pots and page pages.
152
- * @WordPress action admin_init
153
  *
 
 
 
 
154
  */
155
- function addMetaBoxes ()
156
- {
157
- add_meta_box($this->taxonomy_name . 'div', __('Category Groups', 'avh-ec'), 'post_categories_meta_box', 'post', 'side', 'core', array('taxonomy'=>$this->taxonomy_name));
158
- add_meta_box($this->taxonomy_name . 'div', __('Category Groups', 'avh-ec'), 'post_categories_meta_box', 'page', 'side', 'core', array('taxonomy'=>$this->taxonomy_name));
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  }
160
 
161
  /**
@@ -163,15 +291,15 @@ class AVH_EC_Category_Group
163
  *
164
  * @return array Term_id
165
  */
166
- function getAllCategoriesTermID ()
167
- {
168
  $all_cat_id = array();
169
  $categories = get_categories();
170
- if (! is_wp_error($categories)) {
171
  foreach ($categories as $category) {
172
  $all_cat_id[] = $category->term_id;
173
  }
174
  }
 
175
  return ($all_cat_id);
176
  }
177
 
@@ -179,15 +307,19 @@ class AVH_EC_Category_Group
179
  * Get the categories from the given group from the DB
180
  *
181
  * @param int $group_id The Taxonomy Term ID
182
- * @return Array|False categories. Will return FALSE, if the row does not exists.
183
  *
 
184
  */
185
- function getCategoriesFromGroup ($group_id)
186
- {
187
  global $wpdb;
188
 
189
  // Query database
190
- $result = $wpdb->get_results($wpdb->prepare('SELECT * FROM ' . $wpdb->terms . ' t, ' . $wpdb->avhec_cat_group . ' cg WHERE t.term_id = cg.term_id AND cg.group_term_id = %d', $group_id));
 
 
 
 
 
191
 
192
  if (is_array($result)) { // Call succeeded
193
  if (empty($result)) { // No rows found
@@ -200,210 +332,135 @@ class AVH_EC_Category_Group
200
  } else {
201
  $return = false;
202
  }
 
203
  return ($return);
204
  }
205
 
206
  /**
207
- * Set the categories for the given group from the DB. Insert the group if it doesn't exists.
208
  *
209
- * @param int $group_id The Taxonomy Term ID
210
- * @param array $categories The categories
211
- * @return Object (false if not found)
212
  *
 
213
  */
214
- function setCategoriesForGroup ($group_id, $categories = array())
215
- {
216
  global $wpdb;
217
 
218
- $old_categories = $this->getCategoriesFromGroup($group_id);
219
-
220
- if (! is_array($categories)) {
221
- $categories = array();
222
- }
223
- $new_categories = $categories;
224
- sort($old_categories);
225
- sort($new_categories);
226
- // If the new and old values are the same, no need to update.
227
- if ($new_categories === $old_categories) {
228
- return false;
229
- }
230
-
231
- $new = array_diff($new_categories, $old_categories);
232
- $removed = array_diff($old_categories, $new_categories);
233
-
234
- if (! empty($new)) {
235
- foreach ($new as $cat_term_id) {
236
- $insert[] = '(' . $group_id . ',' . $cat_term_id . ')';
237
- }
238
- $value = implode(',', $insert);
239
- $sql = 'INSERT INTO ' . $wpdb->avhec_cat_group . ' (group_term_id, term_id) VALUES ' . $value;
240
- $result = $wpdb->query($sql);
241
-
242
- }
243
-
244
- if (! empty($removed)) {
245
- $delete = implode(',', $removed);
246
- $sql = $wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE group_term_id=%d and term_id IN (' . $delete . ')', $group_id);
247
- $result = $wpdb->query($sql);
248
-
249
  }
250
 
251
- return $result;
252
  }
253
 
254
- /**
255
- * Set the Widget Title for a Group
256
- * @param int $group_id
257
- * @param string $widget_title
258
- *
259
- */
260
- function setWidgetTitleForGroup ($group_id, $widget_title = '')
261
- {
262
- $this->options_widget_titles[$group_id] = $widget_title;
263
- update_option($this->db_options_widget_titles, $this->options_widget_titles);
264
- }
265
 
266
- /**
267
- * Return the title for a group_id if exsist otherwise return false
268
- * @param $group_id
269
- *
270
- */
271
- function getWidgetTitleForGroup ($group_id)
272
- {
273
- if (isset($this->options_widget_titles[$group_id])) {
274
- return ($this->options_widget_titles[$group_id]);
275
  }
276
- return false;
277
- }
278
 
279
- /**
280
- * Delete the Widget Title for a group
281
- *
282
- * @param $group_id
283
- */
284
- function doDeleteWidgetTitle ($group_id)
285
- {
286
- if (isset($this->db_options_widget_titles[$group_id])) {
287
- unset($this->db_options_widget_titles[$group_id]);
288
- }
289
- update_option($this->db_options_widget_titles, $this->options_widget_titles);
290
  }
291
 
292
  /**
293
  * Same as get_term_by, but returns the ID only if found, else false
 
294
  * @param string $field
295
  * @param string $value
 
296
  * @return int|boolean
297
  */
298
- function getTermIDBy ($field, $value)
299
- {
300
  $row = get_term_by($field, $value, $this->taxonomy_name);
301
  if (false === $row) {
302
  $return = false;
303
  } else {
304
  $return = (int) $row->term_id;
305
  }
 
306
  return ($return);
307
  }
308
 
309
  /**
310
- * Gets all information of a group
311
  *
312
  * @param $group_id
313
- * @return Object|False Returns False when the group doesn't exists.
314
  */
315
- function getGroup ($group_id)
316
- {
317
- global $wpdb;
318
-
319
- $result = get_term((int) $group_id, $this->taxonomy_name);
320
- if (null === $result) {
321
- $result = false;
322
  }
323
- return ($result);
324
- }
325
 
326
- function getGroupByCategoryID($category_id){
327
- $return = get_term_by('slug', 'none', $this->taxonomy_name);
328
- $cat_groups = get_terms($this->taxonomy_name, array('hide_empty'=>FALSE));
329
-
330
- foreach ($cat_groups as $group) {
331
- $cats = $this->getCategoriesFromGroup($group->term_id);
332
- if ($group->slug != 'all' && in_array($category_id,$cats)) {
333
- $return = $group;
334
- break;
335
- }
336
- }
337
- return $return;
338
- }
339
- /**
340
- * Inserts a new group
341
- *
342
- * @param $term
343
- * @param array $args
344
- */
345
- function doInsertGroup ($term, $args = array(), $widget_title = '')
346
- {
347
- $row = wp_insert_term($term, $this->taxonomy_name, $args);
348
- $this->setWidgetTitleForGroup($term, $widget_title);
349
- return ($row['term_id']);
350
  }
351
 
352
  /**
353
- * Deletes a group
354
  *
355
- * @param $group_id
 
 
 
356
  */
357
- function doDeleteGroup ($group_id)
358
- {
359
-
360
  global $wpdb;
361
 
362
- $group = $this->getGroup($group_id);
363
- $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE group_term_id=%d', $group_id));
364
- $this->doDeleteWidgetTitle($group_id);
365
- $return = wp_delete_term($group->term_id, $this->taxonomy_name);
366
 
367
- return ($return);
368
- }
 
 
 
 
 
 
 
 
369
 
370
- /**
371
- * Update a group
372
- *
373
- * @param $group_id
374
- * @param $selected_categories
375
- * @param $widget_title
376
- *
377
- * return -1,0,1 Unknown Group, Duplicate Slug, Succesfull
378
- */
379
- function doUpdateGroup ($group_id, $args = array(), $selected_categories, $widget_title = '')
380
- {
381
 
382
- $group = $this->getGroup($group_id);
383
- if (is_object($group)) {
384
- $id = wp_update_term($group->term_id, $this->taxonomy_name, $args);
385
- if (! is_wp_error($id)) {
386
- $this->setWidgetTitleForGroup($group_id, $widget_title);
387
- $this->setCategoriesForGroup($group_id, $selected_categories);
388
- $return = 1; // Succesful
389
- } else {
390
- $return = 0; // Duplicate Slug
391
  }
392
- } else {
393
- $return = - 1; // Unknown group
 
394
  }
395
- return ($return);
 
 
 
 
 
 
 
 
 
 
 
 
396
  }
397
 
398
  /**
399
- * Deletes the given category from all groups
400
  *
401
- * @param $category_id
 
402
  */
403
- function doDeleteCategoryFromGroup ($category_id)
404
- {
405
- global $wpdb;
406
- $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE term_id=%d', $category_id));
407
  }
408
  }
 
409
  ?>
5
  *
6
  * @author Peter van der Does
7
  */
8
+ class AVH_EC_Category_Group {
9
+ var $db_options_widget_titles;
10
+ var $options_widget_titles;
11
  /**
12
  * Taxonomy name
13
+ *
14
  * @var string
15
  */
16
  var $taxonomy_name;
 
 
 
 
 
17
  var $widget_done_catgroup;
18
 
 
 
 
 
 
 
 
 
 
19
  /**
20
  * PHP5 Constructor
21
  * Init the Database Abstraction layer
 
22
  */
23
+ function __construct() {
 
24
  global $wpdb;
25
 
26
  register_shutdown_function(array(&$this, '__destruct'));
27
 
28
  /**
29
  * Taxonomy name
30
+ *
31
  * @var string
32
  */
33
  $this->taxonomy_name = 'avhec_catgroup';
38
 
39
  /**
40
  * Create the table if it doesn't exist.
 
41
  */
42
  if ($wpdb->get_var('show tables like \'' . $wpdb->avhec_cat_group . '\'') != $wpdb->avhec_cat_group) {
43
+ add_action('init',
44
+ array(&$this, 'doCreateTable'),
45
+ 2); // Priority needs to be the same as the Register Taxonomy
46
  }
47
+ add_action('init',
48
+ array(&$this, 'doRegisterTaxonomy'),
49
+ 2); // Priority for registering custom taxonomies is +1 over the creation of the initial taxonomies
50
  add_action('init', array(&$this, 'doSetupOptions'));
51
 
52
  add_action('admin_init', array(&$this, 'addMetaBoxes'));
53
+ }
54
 
55
+ /**
56
+ * PHP4 constructor.
57
+ */
58
+ function AVH_EC_Category_Group() {
59
+ return $this->__construct();
60
  }
61
 
62
  /**
64
  *
65
  * @return bool Always true
66
  */
67
+ function __destruct() {
 
68
  return true;
69
  }
70
 
71
+ /**
72
+ * Add the metaboxes for the pots and page pages.
73
+ *
74
+ * @WordPress action admin_init
75
+ */
76
+ function addMetaBoxes() {
77
+ add_meta_box($this->taxonomy_name . 'div',
78
+ __('Category Groups', 'avh-ec'),
79
+ 'post_categories_meta_box',
80
+ 'post',
81
+ 'side',
82
+ 'core',
83
+ array('taxonomy' => $this->taxonomy_name));
84
+ add_meta_box($this->taxonomy_name . 'div',
85
+ __('Category Groups', 'avh-ec'),
86
+ 'post_categories_meta_box',
87
+ 'page',
88
+ 'side',
89
+ 'core',
90
+ array('taxonomy' => $this->taxonomy_name));
91
+ }
92
+
93
  /**
94
  * Create Table
 
95
  *
96
+ * @WordPress action init
97
  */
98
+ function doCreateTable() {
 
99
  global $wpdb;
100
 
101
  // Setup the DB Tables
102
  $charset_collate = '';
103
 
104
  if (version_compare(mysql_get_server_info(), '4.1.0', '>=')) {
105
+ if ( ! empty($wpdb->charset)) {
106
  $charset_collate = 'DEFAULT CHARACTER SET ' . $wpdb->charset;
107
+ }
108
+ if ( ! empty($wpdb->collate)) {
109
  $charset_collate .= ' COLLATE ' . $wpdb->collate;
110
+ }
111
  }
112
 
113
+ $sql = 'CREATE TABLE `' .
114
+ $wpdb->avhec_cat_group .
115
+ '` ( `group_term_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, `term_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (`group_term_id`, `term_id`) )' .
116
+ $charset_collate .
117
+ ';';
118
 
119
  $result = $wpdb->query($sql);
120
  }
121
 
122
+ /**
123
+ * Deletes the given category from all groups
124
+ *
125
+ * @param $category_id
126
+ */
127
+ function doDeleteCategoryFromGroup($category_id) {
128
+ global $wpdb;
129
+ $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE term_id=%d',
130
+ $category_id));
131
+ }
132
+
133
+ /**
134
+ * Deletes a group
135
+ *
136
+ * @param $group_id
137
+ */
138
+ function doDeleteGroup($group_id) {
139
+
140
+ global $wpdb;
141
+
142
+ $group = $this->getGroup($group_id);
143
+ $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE group_term_id=%d',
144
+ $group_id));
145
+ $this->doDeleteWidgetTitle($group_id);
146
+ $return = wp_delete_term($group->term_id, $this->taxonomy_name);
147
+
148
+ return ($return);
149
+ }
150
+
151
+ /**
152
+ * Delete the Widget Title for a group
153
+ *
154
+ * @param $group_id
155
+ */
156
+ function doDeleteWidgetTitle($group_id) {
157
+ if (isset($this->db_options_widget_titles[ $group_id ])) {
158
+ unset($this->db_options_widget_titles[ $group_id ]);
159
+ }
160
+ update_option($this->db_options_widget_titles, $this->options_widget_titles);
161
+ }
162
+
163
+ /**
164
+ * Inserts a new group
165
+ *
166
+ * @param $term
167
+ * @param array $args
168
+ */
169
+ function doInsertGroup($term, $args = array(), $widget_title = '') {
170
+ $row = wp_insert_term($term, $this->taxonomy_name, $args);
171
+ $this->setWidgetTitleForGroup($term, $widget_title);
172
+
173
+ return ($row['term_id']);
174
+ }
175
+
176
  /**
177
  * Setup Group Categories Taxonomy
 
178
  *
179
+ * @WordPress action init
180
  */
181
+ function doRegisterTaxonomy() {
 
182
  /**
183
  * As we don't want to see the Menu Item we have to disable show_ui. This also disables the metabox on the posts and pages, so we add thse manually instead.
184
  * We remove the capabilities to manage, edit and delete the terms. We have written this part ourselves and don't use WordPress for these functions. The only one we use is the assign_terms.
185
  */
186
+ $labels = array(
187
+ 'name' => __('Category Groups', 'avh-ec'),
188
+ 'singular_name' => __('Category Group', 'avh-ec'),
189
+ 'search_items' => __('Search Category Groups', 'avh-ec'),
190
+ 'popular_items' => __('Popular Category Groups'),
191
+ 'all_items' => __('All Category Groups'),
192
+ 'parent_item' => __('Parent Category Group'),
193
+ 'parent_item_colon' => __('Parent Category Group:'),
194
+ 'edit_item' => __('Edit Category Group'),
195
+ 'update_item' => __('Update Category Group'),
196
+ 'add_new_item' => __('Add New Category Group'),
197
+ 'new_item_name' => __('New Category Group Name')
198
+ );
199
+ $caps = array(
200
+ 'manage_terms' => null,
201
+ 'edit_terms' => null,
202
+ 'delete_terms' => null,
203
+ 'assign_terms' => 'edit_posts'
204
+ );
205
+ register_taxonomy($this->taxonomy_name,
206
+ array('post', 'page'),
207
+ array(
208
+ 'hierarchical' => true,
209
+ 'labels' => $labels,
210
+ 'query_var' => true,
211
+ 'rewrite' => true,
212
+ 'show_in_nav_menus' => false,
213
+ 'public' => true,
214
+ 'show_ui' => false,
215
+ 'capabilities' => $caps
216
+ ));
217
  }
218
 
219
  /**
220
  * Setup the options for the widget titles
 
221
  *
222
+ * @WordPress action init
223
  */
224
+ function doSetupOptions() {
 
225
  // Setup the standard groups if the none group does not exists.
226
  $all_categories = $this->getAllCategoriesTermID();
227
  if (false === $this->getTermIDBy('slug', 'none')) {
228
+ $none_group_id = wp_insert_term('none',
229
+ $this->taxonomy_name,
230
+ array(
231
+ 'description' => __('This group will not show the widget.', 'avh-ec')
232
+ ));
233
+ $all_group_id = wp_insert_term('All',
234
+ $this->taxonomy_name,
235
+ array('description' => __('Holds all the categories.', 'avh-ec')));
236
+ $home_group_id = wp_insert_term('Home',
237
+ $this->taxonomy_name,
238
+ array(
239
+ 'description' => __('This group will be shown on the front page.',
240
+ 'avh-ec')
241
+ ));
242
 
243
  // Fill the standard groups with all categories
244
  $this->setCategoriesForGroup($home_group_id['term_id'], $all_categories);
247
  }
248
 
249
  $options = get_option($this->db_options_widget_titles);
250
+ if ( ! $options) {
251
+ $options = array();
252
+ $id = $this->getTermIDBy('slug', 'all');
253
+ $options[ $id ] = '';
254
+ $id = $this->getTermIDBy('slug', 'home');
255
+ $options[ $id ] = '';
256
  update_option($this->db_options_widget_titles, $options);
257
  }
258
  $this->options_widget_titles = $options;
260
  }
261
 
262
  /**
263
+ * Update a group
 
264
  *
265
+ * @param $group_id
266
+ * @param $selected_categories
267
+ * @param $widget_title
268
+ * return -1,0,1 Unknown Group, Duplicate Slug, Succesfull
269
  */
270
+ function doUpdateGroup($group_id, $args = array(), $selected_categories, $widget_title = '') {
271
+
272
+ $group = $this->getGroup($group_id);
273
+ if (is_object($group)) {
274
+ $id = wp_update_term($group->term_id, $this->taxonomy_name, $args);
275
+ if ( ! is_wp_error($id)) {
276
+ $this->setWidgetTitleForGroup($group_id, $widget_title);
277
+ $this->setCategoriesForGroup($group_id, $selected_categories);
278
+ $return = 1; // Succesful
279
+ } else {
280
+ $return = 0; // Duplicate Slug
281
+ }
282
+ } else {
283
+ $return = - 1; // Unknown group
284
+ }
285
+
286
+ return ($return);
287
  }
288
 
289
  /**
291
  *
292
  * @return array Term_id
293
  */
294
+ function getAllCategoriesTermID() {
 
295
  $all_cat_id = array();
296
  $categories = get_categories();
297
+ if ( ! is_wp_error($categories)) {
298
  foreach ($categories as $category) {
299
  $all_cat_id[] = $category->term_id;
300
  }
301
  }
302
+
303
  return ($all_cat_id);
304
  }
305
 
307
  * Get the categories from the given group from the DB
308
  *
309
  * @param int $group_id The Taxonomy Term ID
 
310
  *
311
+ * @return Array|False categories. Will return FALSE, if the row does not exists.
312
  */
313
+ function getCategoriesFromGroup($group_id) {
 
314
  global $wpdb;
315
 
316
  // Query database
317
+ $result = $wpdb->get_results($wpdb->prepare('SELECT * FROM ' .
318
+ $wpdb->terms .
319
+ ' t, ' .
320
+ $wpdb->avhec_cat_group .
321
+ ' cg WHERE t.term_id = cg.term_id AND cg.group_term_id = %d',
322
+ $group_id));
323
 
324
  if (is_array($result)) { // Call succeeded
325
  if (empty($result)) { // No rows found
332
  } else {
333
  $return = false;
334
  }
335
+
336
  return ($return);
337
  }
338
 
339
  /**
340
+ * Gets all information of a group
341
  *
342
+ * @param $group_id
 
 
343
  *
344
+ * @return Object|False Returns False when the group doesn't exists.
345
  */
346
+ function getGroup($group_id) {
 
347
  global $wpdb;
348
 
349
+ $result = get_term((int) $group_id, $this->taxonomy_name);
350
+ if (null === $result) {
351
+ $result = false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
352
  }
353
 
354
+ return ($result);
355
  }
356
 
357
+ function getGroupByCategoryID($category_id) {
358
+ $return = get_term_by('slug', 'none', $this->taxonomy_name);
359
+ $cat_groups = get_terms($this->taxonomy_name, array('hide_empty' => false));
 
 
 
 
 
 
 
 
360
 
361
+ foreach ($cat_groups as $group) {
362
+ $cats = $this->getCategoriesFromGroup($group->term_id);
363
+ if ($group->slug != 'all' && in_array($category_id, $cats)) {
364
+ $return = $group;
365
+ break;
366
+ }
 
 
 
367
  }
 
 
368
 
369
+ return $return;
 
 
 
 
 
 
 
 
 
 
370
  }
371
 
372
  /**
373
  * Same as get_term_by, but returns the ID only if found, else false
374
+ *
375
  * @param string $field
376
  * @param string $value
377
+ *
378
  * @return int|boolean
379
  */
380
+ function getTermIDBy($field, $value) {
 
381
  $row = get_term_by($field, $value, $this->taxonomy_name);
382
  if (false === $row) {
383
  $return = false;
384
  } else {
385
  $return = (int) $row->term_id;
386
  }
387
+
388
  return ($return);
389
  }
390
 
391
  /**
392
+ * Return the title for a group_id if exsist otherwise return false
393
  *
394
  * @param $group_id
 
395
  */
396
+ function getWidgetTitleForGroup($group_id) {
397
+ if (isset($this->options_widget_titles[ $group_id ])) {
398
+ return ($this->options_widget_titles[ $group_id ]);
 
 
 
 
399
  }
 
 
400
 
401
+ return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
402
  }
403
 
404
  /**
405
+ * Set the categories for the given group from the DB. Insert the group if it doesn't exists.
406
  *
407
+ * @param int $group_id The Taxonomy Term ID
408
+ * @param array $categories The categories
409
+ *
410
+ * @return Object (false if not found)
411
  */
412
+ function setCategoriesForGroup($group_id, $categories = array()) {
 
 
413
  global $wpdb;
414
 
415
+ $old_categories = $this->getCategoriesFromGroup($group_id);
 
 
 
416
 
417
+ if ( ! is_array($categories)) {
418
+ $categories = array();
419
+ }
420
+ $new_categories = $categories;
421
+ sort($old_categories);
422
+ sort($new_categories);
423
+ // If the new and old values are the same, no need to update.
424
+ if ($new_categories === $old_categories) {
425
+ return false;
426
+ }
427
 
428
+ $new = array_diff($new_categories, $old_categories);
429
+ $removed = array_diff($old_categories, $new_categories);
 
 
 
 
 
 
 
 
 
430
 
431
+ if ( ! empty($new)) {
432
+ foreach ($new as $cat_term_id) {
433
+ $insert[] = '(' . $group_id . ',' . $cat_term_id . ')';
 
 
 
 
 
 
434
  }
435
+ $value = implode(',', $insert);
436
+ $sql = 'INSERT INTO ' . $wpdb->avhec_cat_group . ' (group_term_id, term_id) VALUES ' . $value;
437
+ $result = $wpdb->query($sql);
438
  }
439
+
440
+ if ( ! empty($removed)) {
441
+ $delete = implode(',', $removed);
442
+ $sql = $wpdb->prepare('DELETE FROM ' .
443
+ $wpdb->avhec_cat_group .
444
+ ' WHERE group_term_id=%d and term_id IN (' .
445
+ $delete .
446
+ ')',
447
+ $group_id);
448
+ $result = $wpdb->query($sql);
449
+ }
450
+
451
+ return $result;
452
  }
453
 
454
  /**
455
+ * Set the Widget Title for a Group
456
  *
457
+ * @param int $group_id
458
+ * @param string $widget_title
459
  */
460
+ function setWidgetTitleForGroup($group_id, $widget_title = '') {
461
+ $this->options_widget_titles[ $group_id ] = $widget_title;
462
+ update_option($this->db_options_widget_titles, $this->options_widget_titles);
 
463
  }
464
  }
465
+
466
  ?>
2.8/class/avh-ec.core.php CHANGED
@@ -1,295 +1,222 @@
1
  <?php
2
 
3
- class AVH_EC_Core
4
- {
5
- var $version;
6
- var $comment;
7
- var $info;
8
- var $db_options_core;
9
- var $default_options;
10
- var $default_options_general;
11
- var $default_options_category_group;
12
- var $default_options_sp_category_group;
13
-
14
- var $db_options_tax_meta;
15
-
16
- var $options;
17
-
18
  /**
19
- * PHP5 constructor
20
- *
 
 
21
  */
22
- function __construct ()
23
- {
24
- /**
25
- *
26
- * @var AVH_EC_Category_Group
27
- */
28
- $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
29
-
30
- $this->version = '4.0.2';
31
- $this->comment = '<!-- AVH Extended Categories version ' . $this->version . ' | http://blog.avirtualhome.com/wordpress-plugins/ -->';
32
- $this->db_options_core = 'avhec';
33
- $this->db_options_tax_meta = 'avhec-tax_meta';
34
-
35
- add_action('init', array ( &$this, 'handleInitializePlugin' ), 10);
36
- }
37
 
38
  /**
39
- * PHP4 Constructor
 
40
  *
41
- * @return AVHExtendedCategoriesCore
 
 
 
42
  */
43
- function AVH_EC_Core ()
44
- {
45
- $this->__construct();
46
- }
47
-
48
- function handleInitializePlugin ()
49
- {
50
- global $wpdb;
51
-
52
- $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
53
- $db_version = 4;
54
-
55
- $info['siteurl'] = get_option('siteurl');
56
- $info['plugin_dir'] = AVHEC_PLUGIN_DIR;
57
- $info['graphics_url'] = AVHEC_PLUGIN_URL . '/images';
58
-
59
- // Set class property for info
60
- $this->info = array ( 'home' => get_option('home'), 'siteurl' => $info['siteurl'], 'plugin_dir' => $info['plugin_dir'], 'js_dir' => $info['plugin_dir'] . '/js', 'graphics_url' => $info['graphics_url'] );
61
-
62
- // Set the default options
63
- $this->default_options_general = array ( 'version' => $this->version, 'dbversion' => $db_version, 'alternative_name_select_category' => '' );
64
-
65
- // Set the default category group options
66
- $no_group_id = $catgrp->getTermIDBy('slug', 'none');
67
- $home_group_id = $catgrp->getTermIDBy('slug', 'home');
68
- $default_group_id = $catgrp->getTermIDBy('slug', 'all');
69
- $this->default_options_category_group = array ( 'no_group' => $no_group_id, 'home_group' => $home_group_id, 'default_group' => $default_group_id );
70
-
71
- $this->default_options_sp_category_group = array ( 'home_group' => $home_group_id, 'category_group' => $default_group_id, 'day_group' => $default_group_id, 'month_group' => $default_group_id, 'year_group' => $default_group_id, 'author_group' => $default_group_id, 'search_group' => $default_group_id );
72
-
73
- $this->default_options = array ( 'general' => $this->default_options_general, 'cat_group' => $this->default_options_category_group, 'widget_titles' => array (), 'sp_cat_group' => $this->default_options_sp_category_group );
74
-
75
- /**
76
- * Set the options for the program
77
- *
78
- */
79
- $this->loadOptions();
80
-
81
- // Check if we have to do updates
82
- if ((! isset($this->options['general']['dbversion'])) || $this->options['general']['dbversion'] < $db_version) {
83
- $this->doUpdateOptions($db_version);
84
- }
85
-
86
- $db = new AVH_DB();
87
- if (! $db->field_exists('avhec_term_order', $wpdb->terms)) {
88
- $wpdb->query("ALTER TABLE $wpdb->terms ADD `avhec_term_order` INT( 4 ) NULL DEFAULT '0'");
89
  }
90
 
91
- $this->handleTextdomain();
92
- add_filter('get_terms_orderby', array ( &$this, 'applyOrderFilter' ), 10, 2);
93
-
94
- }
95
-
96
- function applyOrderFilter ($orderby, $args)
97
- {
98
- switch ($args['orderby']) {
99
- case 'avhec_manualorder':
100
- $new_orderby = 't.avhec_term_order';
101
- break;
102
- case 'avhec_3rdparty_mycategoryorder':
103
- $new_orderby = 't.term_order';
104
- break;
105
- default:
106
- $new_orderby = $orderby;
107
- break;
108
- }
109
- return $new_orderby;
110
  }
111
 
112
  /**
113
- * Loads the i18n
 
114
  *
115
- * @return
 
 
116
  */
117
- function handleTextdomain ()
118
- {
119
-
120
- load_plugin_textdomain('avh-ec', false, AVHEC_RELATIVE_PLUGIN_DIR . '/lang');
121
 
 
 
122
  }
123
 
124
  /**
125
- * Checks if running version is newer and do upgrades if necessary
126
- *
127
- * @since 1.2.3
128
  *
 
 
 
 
129
  */
130
- function doUpdateOptions ($db_version)
131
- {
132
- $options = $this->getOptions();
133
 
134
- // Add none existing sections and/or elements to the options
135
- foreach ($this->default_options as $section => $default_data) {
136
- if (! array_key_exists($section, $options)) {
137
- $options[$section] = $default_data;
138
- continue;
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  }
140
- foreach ($default_data as $element => $default_value) {
141
- if (! array_key_exists($element, $options[$section])) {
142
- $options[$section][$element] = $default_value;
143
- }
 
 
 
 
 
 
144
  }
145
- }
146
 
147
- // Remove none existing sections and/or elements from the options
148
- foreach ($options as $section => $data) {
149
- if (! array_key_exists($section, $this->default_options)) {
150
- unset($options[$section]);
151
- continue;
 
152
  }
153
- foreach ($data as $element => $value) {
154
- if (! array_key_exists($element, $this->default_options[$section])) {
155
- unset($options[$section][$element]);
156
- }
157
  }
 
158
  }
159
- /**
160
- * Update the options to the latests versions
161
- */
162
- $options['general']['version'] = $this->version;
163
- $options['general']['dbversion'] = $db_version;
164
- $this->saveOptions($options);
165
- }
166
 
167
- /**
168
- * Used in forms to set the checked option.
169
- *
170
- * @param mixed $checked
171
- * @param mixed_type $current
172
- * @return string
173
- *
174
- * @since 2.0
175
- */
176
- function isChecked ($checked, $current)
177
- {
178
- if ($checked == $current) {
179
- return (' checked="checked"');
180
  }
181
- return ('');
182
- }
183
 
184
- /**
185
- * Used in forms to set the SELECTED option
186
- *
187
- * @param string $current
188
- * @param string $field
189
- * @return string
190
- */
191
- function isSelected ($current, $field)
192
- {
193
- if ($current == $field) {
194
- return (' SELECTED');
 
 
 
 
 
 
 
 
 
 
 
 
195
  }
196
- return ('');
197
  }
198
 
199
  /**
200
- * Get the base directory of a directory structure
201
- *
202
- * @param string $directory
203
- * @return string
204
  *
 
 
 
205
  */
206
- function getBaseDirectory ($directory)
207
- {
208
- //place each directory into array and get the last element
209
- $return = end(explode('/', $directory));
210
 
211
- return $return;
 
212
  }
 
213
 
214
- /*********************************
215
- * *
216
- * Methods for variable: options *
217
- * *
218
- ********************************/
 
 
 
 
 
 
219
 
220
  /**
221
- * @param array $data
222
  */
223
- function setOptions ($options)
224
- {
225
- $this->options = $options;
226
- }
 
227
 
228
- /**
229
- * return array
230
- */
231
- function getOptions ()
232
- {
233
- return ($this->options);
234
- }
235
 
236
- /**
237
- * Save all current options and set the options
238
- *
239
- */
240
- function saveOptions ($options)
241
- {
242
- update_option($this->db_options_core, $options);
243
- wp_cache_flush(); // Delete cache
244
- $this->setOptions($options);
245
  }
246
 
247
  /**
248
- * Retrieves the plugin options from the WordPress options table and assigns to class variable.
249
- * If the options do not exists, like a new installation, the options are set to the default value.
250
  *
251
- * @return none
252
  */
253
- function loadOptions ()
254
- {
255
- $options = get_option($this->db_options_core);
256
- if (false === $options) { // New installation
257
- $this->resetToDefaultOptions();
258
- } else {
259
- $this->setOptions($options);
260
- }
261
  }
262
 
263
- /**
264
- * Get the value for an option element. If there's no option is set on the Admin page, return the default value.
265
- *
266
- * @param string $key
267
- * @param string $option
268
- * @return mixed
269
- */
270
- function getOptionElement ($option, $key)
271
- {
272
- if ($this->options[$option][$key]) {
273
- $return = $this->options[$option][$key]; // From Admin Page
274
- } else {
275
- $return = $this->default_options[$option][$key]; // Default
276
  }
277
- return ($return);
278
- }
279
 
280
- /**
281
- * Reset to default options and save in DB
282
- *
283
- */
284
- function resetToDefaultOptions ()
285
- {
286
- $this->options = $this->default_options;
287
- $this->saveOptions($this->default_options);
288
  }
289
 
290
  /**
291
  * Display or retrieve the HTML dropdown list of categories.
292
- *
293
  * The list of arguments is below:
294
  * 'show_option_all' (string) - Text to display for showing all categories.
295
  * 'show_option_none' (string) - Text to display for showing no categories.
@@ -309,7 +236,6 @@ class AVH_EC_Core
309
  * 'name' (string) - The name attribute value for selected element.
310
  * 'class' (string) - The class attribute value for selected element.
311
  * 'selected' (int) - Which category ID is selected.
312
- *
313
  * The 'hierarchical' argument, which is disabled by default, will override the
314
  * depth argument, unless it is true. When the argument is false, it will
315
  * display all of the categories. When it is enabled it will use the value in
@@ -318,19 +244,37 @@ class AVH_EC_Core
318
  * @since 2.1.0
319
  *
320
  * @param string|array $args Optional. Override default arguments.
 
321
  * @return string HTML content only if 'echo' argument is 0.
322
  */
323
- function avh_wp_dropdown_categories ($args = '', $selectedonly)
324
- {
325
  $mywalker = new AVH_Walker_CategoryDropdown();
326
 
327
- $defaults = array ( 'show_option_all' => '', 'show_option_none' => '', 'orderby' => 'id', 'order' => 'ASC', 'show_last_update' => 0, 'show_count' => 0, 'hide_empty' => 1, 'child_of' => 0, 'exclude' => '', 'echo' => 1, 'selected' => 0, 'hierarchical' => 0, 'name' => 'cat', 'class' => 'postform', 'depth' => 0, 'tab_index' => 0, 'walker' => $mywalker );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
328
 
329
  $defaults['selected'] = (is_category()) ? get_query_var('cat') : 0;
330
 
331
  $r = wp_parse_args($args, $defaults);
332
 
333
- if (! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
334
  $r['pad_counts'] = true;
335
  }
336
 
@@ -338,26 +282,36 @@ class AVH_EC_Core
338
  extract($r);
339
 
340
  $tab_index_attribute = '';
341
- if ((int) $tab_index > 0)
342
  $tab_index_attribute = ' tabindex="' . $tab_index . '"';
 
343
 
344
  $categories = get_categories($r);
345
- $name = esc_attr($name);
346
- $class = esc_attr($class);
347
 
348
  $output = '';
349
- if (! empty($categories)) {
350
- $output = '<select name="' . $name . '" id="' . $name . '" class="' . $class . '" ' . $tab_index_attribute . '>' . "\n";
 
 
 
 
 
 
 
 
 
351
 
352
  if ($show_option_all) {
353
  $show_option_all = apply_filters('list_cats', $show_option_all);
354
- $selected = ('0' === strval($r['selected'])) ? " selected='selected'" : '';
355
  $output .= "\t" . '<option value="0"' . $selected . '>' . $show_option_all . '</option>' . "\n";
356
  }
357
 
358
  if ($show_option_none) {
359
  $show_option_none = apply_filters('list_cats', $show_option_none);
360
- $selected = ('-1' === strval($r['selected'])) ? " selected='selected'" : '';
361
  $output .= "\t" . '<option value="-1"' . $selected . '>' . $show_option_none . '</option>' . "\n";
362
  }
363
 
@@ -372,15 +326,15 @@ class AVH_EC_Core
372
 
373
  $output = apply_filters('wp_dropdown_cats', $output);
374
 
375
- if ($echo)
376
  echo $output;
 
377
 
378
  return $output;
379
  }
380
 
381
  /**
382
  * Display or retrieve the HTML list of categories.
383
- *
384
  * The list of arguments is below:
385
  * 'show_option_all' (string) - Text to display for showing all categories.
386
  * 'orderby' (string) default is 'ID' - What column to use for ordering the
@@ -406,98 +360,368 @@ class AVH_EC_Core
406
  * 'title_li' (string) - See {@link get_categories()}.
407
  * 'depth' (int) - The max depth.
408
  *
409
- * @since 2.1.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
410
  *
411
- * @param string|array $args Optional. Override default arguments.
412
- * @return string HTML content only if 'echo' argument is 0.
413
  */
414
- function avh_wp_list_categories ($args = '', $selectedonly)
415
- {
416
- $mywalker = new AVHEC_Walker_Category();
417
- $defaults = array ( 'show_option_all' => '', 'orderby' => 'name', 'order' => 'ASC', 'show_last_update' => 0, 'style' => 'list', 'show_count' => 0, 'hide_empty' => 1, 'use_desc_for_title' => 1, 'child_of' => 0, 'feed' => '', 'feed_type' => '', 'feed_image' => '', 'exclude' => '', 'exclude_tree' => '', 'current_category' => 0, 'hierarchical' => true, 'title_li' => __('Categories'), 'echo' => 1, 'depth' => 0, 'walker' => $mywalker );
418
-
419
- $r = wp_parse_args($args, $defaults);
420
-
421
- if (! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
422
- $r['pad_counts'] = true;
423
  }
424
 
425
- if (! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
426
- $r['pad_counts'] = true;
427
- }
428
 
429
- if (isset($r['show_date'])) {
430
- $r['include_last_update_time'] = $r['show_date'];
431
- }
 
 
 
432
 
433
- if (true == $r['hierarchical']) {
434
- $r['exclude_tree'] = $r['exclude'];
435
- $r['exclude'] = '';
436
- }
 
 
437
 
438
- extract($r);
 
439
 
440
- $categories = get_categories($r);
 
441
 
442
- $output = '';
443
- if ($title_li && 'list' == $style)
444
- $output = '<li class="categories">' . $r['title_li'] . '<ul>';
445
 
446
- if (empty($categories)) {
447
- if ('list' == $style)
448
- $output .= '<li>' . __("No categories") . '</li>';
449
- else
450
- $output .= __("No categories");
451
- } else {
452
- global $wp_query;
 
453
 
454
- if (! empty($show_option_all))
455
- if ('list' == $style)
456
- $output .= '<li><a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a></li>';
457
- else
458
- $output .= '<a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a>';
 
459
 
460
- if (empty($r['current_category']) && is_category())
461
- $r['current_category'] = $wp_query->get_queried_object_id();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
462
 
463
- if ($hierarchical) {
464
- $depth = $r['depth'];
465
- } else {
466
- $depth = - 1; // Flat.
467
- }
468
 
469
- $output .= walk_category_tree($categories, $depth, $r);
 
 
 
 
470
  }
471
 
472
- if ($title_li && 'list' == $style)
473
- $output .= '</ul></li>';
 
 
474
 
475
- $output = apply_filters('wp_list_categories', $output);
 
 
476
 
477
- if ($echo)
478
- echo $output;
479
- else
480
- return $output;
 
 
 
 
481
  }
482
 
483
- function getCategories ()
484
- {
485
- static $_categories = NULL;
486
- if (NULL === $_categories) {
487
- $_categories = get_categories('get=all');
 
 
 
 
 
 
 
488
  }
489
- return $_categories;
 
490
  }
491
 
492
- function getCategoriesId ($categories)
493
- {
494
- static $_categories_id = NULL;
495
- if (NULL == $_categories_id) {
496
- foreach ($categories as $key => $category) {
497
- $_categories_id[$category->term_id] = $key;
498
- }
 
 
 
 
499
  }
500
- return $_categories_id;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
501
  }
502
  }
503
 
@@ -506,29 +730,32 @@ class AVH_EC_Core
506
  *
507
  * @uses Walker
508
  */
509
- class AVH_Walker_CategoryDropdown extends Walker_CategoryDropdown
510
- {
511
-
512
- function walk ($elements, $max_depth)
513
- {
514
 
515
- $args = array_slice(func_get_args(), 2);
516
  $output = '';
517
 
518
  if ($max_depth < - 1) //invalid parameter
 
519
  return $output;
 
520
 
521
  if (empty($elements)) //nothing to walk
 
522
  return $output;
 
523
 
524
- $id_field = $this->db_fields['id'];
525
  $parent_field = $this->db_fields['parent'];
526
 
527
  // flat display
528
  if (- 1 == $max_depth) {
529
- $empty_array = array ();
530
- foreach ($elements as $e)
531
  $this->display_element($e, $empty_array, 1, 0, $args, $output);
 
 
532
  return $output;
533
  }
534
 
@@ -538,13 +765,14 @@ class AVH_Walker_CategoryDropdown extends Walker_CategoryDropdown
538
  * children_elements is two dimensional array, eg.
539
  * children_elements[10][] contains all sub-elements whose parent is 10.
540
  */
541
- $top_level_elements = array ();
542
- $children_elements = array ();
543
  foreach ($elements as $e) {
544
- if (0 == $e->$parent_field)
545
  $top_level_elements[] = $e;
546
- else
547
- $children_elements[$e->$parent_field][] = $e;
 
548
  }
549
 
550
  /*
@@ -554,183 +782,38 @@ class AVH_Walker_CategoryDropdown extends Walker_CategoryDropdown
554
  if (empty($top_level_elements)) {
555
 
556
  $first = array_slice($elements, 0, 1);
557
- $root = $first[0];
558
 
559
- $top_level_elements = array ();
560
- $children_elements = array ();
561
  foreach ($elements as $e) {
562
- if ($root->$parent_field == $e->$parent_field)
563
  $top_level_elements[] = $e;
564
- else
565
- $children_elements[$e->$parent_field][] = $e;
 
566
  }
567
  }
568
 
569
- foreach ($top_level_elements as $e)
570
  $this->display_element($e, $children_elements, $max_depth, 0, $args, $output);
 
571
 
572
- /*
573
- * if we are displaying all levels, and remaining children_elements is not empty,
574
- * then we got orphans, which should be displayed regardless
575
- */
576
  if ((0 == $max_depth) && count($children_elements) > 0) {
577
- $empty_array = array ();
578
- foreach ($children_elements as $orphans)
579
- foreach ($orphans as $op)
580
  $this->display_element($op, $empty_array, 1, 0, $args, $output);
 
 
581
  }
582
 
583
  return $output;
584
  }
585
  }
586
 
587
- /**
588
- * Create HTML list of categories.
589
- *
590
- * @uses Walker
591
- */
592
- class AVHEC_Walker_Category extends Walker
593
- {
594
- /**
595
- * @see Walker::$tree_type
596
- * @since 2.1.0
597
- * @var string
598
- */
599
- var $tree_type = 'category';
600
-
601
- /**
602
- * @see Walker::$db_fields
603
- * @since 2.1.0
604
- * @todo Decouple this
605
- * @var array
606
- */
607
- var $db_fields = array ( 'parent' => 'parent', 'id' => 'term_id' );
608
-
609
- /**
610
- * @see Walker::start_lvl()
611
- * @since 2.1.0
612
- *
613
- * @param string $output Passed by reference. Used to append additional content.
614
- * @param int $depth Depth of category. Used for tab indentation.
615
- * @param array $args Will only append content if style argument value is 'list'.
616
- */
617
- function start_lvl (&$output, $depth, $args)
618
- {
619
- if ('list' != $args['style'])
620
- return;
621
-
622
- $indent = str_repeat("\t", $depth);
623
- $output .= $indent . '<ul class="children">' . "\n";
624
- }
625
-
626
- /**
627
- * @see Walker::end_lvl()
628
- * @since 2.1.0
629
- *
630
- * @param string $output Passed by reference. Used to append additional content.
631
- * @param int $depth Depth of category. Used for tab indentation.
632
- * @param array $args Will only append content if style argument value is 'list'.
633
- */
634
- function end_lvl (&$output, $depth, $args)
635
- {
636
- if ('list' != $args['style'])
637
- return;
638
-
639
- $indent = str_repeat("\t", $depth);
640
- $output .= $indent . '</ul>' . "\n";
641
- }
642
-
643
- /**
644
- * @see Walker::start_el()
645
- * @since 2.1.0
646
- *
647
- * @param string $output Passed by reference. Used to append additional content.
648
- * @param object $category Category data object.
649
- * @param int $depth Depth of category in reference to parents.
650
- * @param array $args
651
- */
652
- function start_el (&$output, $category, $depth, $args)
653
- {
654
- extract($args);
655
-
656
- $cat_name = esc_attr($category->name);
657
- $cat_name = apply_filters('list_cats', $cat_name, $category);
658
- $link = '<div class="avhec-widget-line"><a href="' . get_category_link($category->term_id) . '" ';
659
- if ($use_desc_for_title == 0 || empty($category->description))
660
- $link .= 'title="' . sprintf(__('View all posts filed under %s'), $cat_name) . '"';
661
- else
662
- $link .= 'title="' . esc_attr(strip_tags(apply_filters('category_description', $category->description, $category))) . '"';
663
- $link .= '>';
664
- $link .= $cat_name . '</a>';
665
-
666
- if ((! empty($feed_image)) || (! empty($feed))) {
667
- $link .= '<div class="avhec-widget-rss"> ';
668
-
669
- if (empty($feed_image))
670
- $link .= '(';
671
-
672
- $link .= '<a href="' . get_category_feed_link($category->term_id, $feed_type) . '"';
673
-
674
- if (empty($feed))
675
- $alt = ' alt="' . sprintf(__('Feed for all posts filed under %s'), $cat_name) . '"';
676
- else {
677
- $title = ' title="' . $feed . '"';
678
- $alt = ' alt="' . $feed . '"';
679
- $name = $feed;
680
- $link .= $title;
681
- }
682
-
683
- $link .= '>';
684
-
685
- if (empty($feed_image))
686
- $link .= $name;
687
- else
688
- $link .= '<img src="' . $feed_image . '"' . $alt . $title . ' />';
689
- $link .= '</a>';
690
- if (empty($feed_image))
691
- $link .= ')';
692
- $link .= '</div>';
693
- }
694
-
695
- if (isset($show_count) && $show_count)
696
- $link .= '<div class="avhec-widget-count"> (' . intval($category->count) . ')</div>';
697
-
698
- if (isset($show_date) && $show_date) {
699
- $link .= ' ' . gmdate('Y-m-d', $category->last_update_timestamp);
700
- }
701
-
702
- if (isset($current_category) && $current_category)
703
- $_current_category = get_category($current_category);
704
-
705
- if ('list' == $args['style']) {
706
- $output .= "\t" . '<li';
707
- $class = 'cat-item cat-item-' . $category->term_id;
708
- if (isset($current_category) && $current_category && ($category->term_id == $current_category))
709
- $class .= ' current-cat';
710
- elseif (isset($_current_category) && $_current_category && ($category->term_id == $_current_category->parent))
711
- $class .= ' current-cat-parent';
712
- $output .= ' class="' . $class . '"';
713
- $output .= '>' . $link . '</div>' . "\n";
714
- } else {
715
- $output .= "\t" . $link . '</div><br />' . "\n";
716
- }
717
- }
718
-
719
- /**
720
- * @see Walker::end_el()
721
- * @since 2.1.0
722
- *
723
- * @param string $output Passed by reference. Used to append additional content.
724
- * @param object $page Not used.
725
- * @param int $depth Depth of category. Not used.
726
- * @param array $args Only uses 'list' for whether should append to output.
727
- */
728
- function end_el (&$output, $page, $depth, $args)
729
- {
730
- if ('list' != $args['style'])
731
- return;
732
-
733
- $output .= '</li>' . "\n";
734
- }
735
- }
736
  ?>
1
  <?php
2
 
3
+ /**
4
+ * Create HTML list of categories.
5
+ *
6
+ * @uses Walker
7
+ */
8
+ class AVHEC_Walker_Category extends Walker {
 
 
 
 
 
 
 
 
 
9
  /**
10
+ * @see Walker::$db_fields
11
+ * @since 2.1.0
12
+ * @todo Decouple this
13
+ * @var array
14
  */
15
+ var $db_fields = array('parent' => 'parent', 'id' => 'term_id');
16
+ /**
17
+ * @see Walker::$tree_type
18
+ * @since 2.1.0
19
+ * @var string
20
+ */
21
+ var $tree_type = 'category';
 
 
 
 
 
 
 
 
22
 
23
  /**
24
+ * @see Walker::end_el()
25
+ * @since 2.1.0
26
  *
27
+ * @param string $output Passed by reference. Used to append additional content.
28
+ * @param object $page Not used.
29
+ * @param int $depth Depth of category. Not used.
30
+ * @param array $args Only uses 'list' for whether should append to output.
31
  */
32
+ function end_el(&$output, $page, $depth, $args) {
33
+ if ('list' != $args['style']) {
34
+ return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  }
36
 
37
+ $output .= '</li>' . "\n";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  }
39
 
40
  /**
41
+ * @see Walker::end_lvl()
42
+ * @since 2.1.0
43
  *
44
+ * @param string $output Passed by reference. Used to append additional content.
45
+ * @param int $depth Depth of category. Used for tab indentation.
46
+ * @param array $args Will only append content if style argument value is 'list'.
47
  */
48
+ function end_lvl(&$output, $depth, $args) {
49
+ if ('list' != $args['style']) {
50
+ return;
51
+ }
52
 
53
+ $indent = str_repeat("\t", $depth);
54
+ $output .= $indent . '</ul>' . "\n";
55
  }
56
 
57
  /**
58
+ * @see Walker::start_el()
59
+ * @since 2.1.0
 
60
  *
61
+ * @param string $output Passed by reference. Used to append additional content.
62
+ * @param object $category Category data object.
63
+ * @param int $depth Depth of category in reference to parents.
64
+ * @param array $args
65
  */
66
+ function start_el(&$output, $category, $depth, $args) {
67
+ extract($args);
 
68
 
69
+ $cat_name = esc_attr($category->name);
70
+ $cat_name = apply_filters('list_cats', $cat_name, $category);
71
+ $link = '<div class="avhec-widget-line"><a href="' . get_category_link($category->term_id) . '" ';
72
+ if ($use_desc_for_title == 0 || empty($category->description)) {
73
+ $link .= 'title="' . sprintf(__('View all posts filed under %s'), $cat_name) . '"';
74
+ } else {
75
+ $link .= 'title="' .
76
+ esc_attr(strip_tags(apply_filters('category_description', $category->description, $category))) .
77
+ '"';
78
+ }
79
+ $link .= '>';
80
+ $link .= $cat_name . '</a>';
81
+
82
+ if (( ! empty($feed_image)) || ( ! empty($feed))) {
83
+ $link .= '<div class="avhec-widget-rss"> ';
84
+
85
+ if (empty($feed_image)) {
86
+ $link .= '(';
87
  }
88
+
89
+ $link .= '<a href="' . get_category_feed_link($category->term_id, $feed_type) . '"';
90
+
91
+ if (empty($feed)) {
92
+ $alt = ' alt="' . sprintf(__('Feed for all posts filed under %s'), $cat_name) . '"';
93
+ } else {
94
+ $title = ' title="' . $feed . '"';
95
+ $alt = ' alt="' . $feed . '"';
96
+ $name = $feed;
97
+ $link .= $title;
98
  }
 
99
 
100
+ $link .= '>';
101
+
102
+ if (empty($feed_image)) {
103
+ $link .= $name;
104
+ } else {
105
+ $link .= '<img src="' . $feed_image . '"' . $alt . $title . ' />';
106
  }
107
+ $link .= '</a>';
108
+ if (empty($feed_image)) {
109
+ $link .= ')';
 
110
  }
111
+ $link .= '</div>';
112
  }
 
 
 
 
 
 
 
113
 
114
+ if (isset($show_count) && $show_count) {
115
+ $link .= '<div class="avhec-widget-count"> (' . intval($category->count) . ')</div>';
 
 
 
 
 
 
 
 
 
 
 
116
  }
 
 
117
 
118
+ if (isset($show_date) && $show_date) {
119
+ $link .= ' ' . gmdate('Y-m-d', $category->last_update_timestamp);
120
+ }
121
+
122
+ if (isset($current_category) && $current_category) {
123
+ $_current_category = get_category($current_category);
124
+ }
125
+
126
+ if ('list' == $args['style']) {
127
+ $output .= "\t" . '<li';
128
+ $class = 'cat-item cat-item-' . $category->term_id;
129
+ if (isset($current_category) && $current_category && ($category->term_id == $current_category)) {
130
+ $class .= ' current-cat';
131
+ } elseif (isset($_current_category) &&
132
+ $_current_category &&
133
+ ($category->term_id == $_current_category->parent)
134
+ ) {
135
+ $class .= ' current-cat-parent';
136
+ }
137
+ $output .= ' class="' . $class . '"';
138
+ $output .= '>' . $link . '</div>' . "\n";
139
+ } else {
140
+ $output .= "\t" . $link . '</div><br />' . "\n";
141
  }
 
142
  }
143
 
144
  /**
145
+ * @see Walker::start_lvl()
146
+ * @since 2.1.0
 
 
147
  *
148
+ * @param string $output Passed by reference. Used to append additional content.
149
+ * @param int $depth Depth of category. Used for tab indentation.
150
+ * @param array $args Will only append content if style argument value is 'list'.
151
  */
152
+ function start_lvl(&$output, $depth, $args) {
153
+ if ('list' != $args['style']) {
154
+ return;
155
+ }
156
 
157
+ $indent = str_repeat("\t", $depth);
158
+ $output .= $indent . '<ul class="children">' . "\n";
159
  }
160
+ }
161
 
162
+ class AVH_EC_Core {
163
+ var $comment;
164
+ var $db_options_core;
165
+ var $db_options_tax_meta;
166
+ var $default_options;
167
+ var $default_options_category_group;
168
+ var $default_options_general;
169
+ var $default_options_sp_category_group;
170
+ var $info;
171
+ var $options;
172
+ var $version;
173
 
174
  /**
175
+ * PHP5 constructor
176
  */
177
+ function __construct() {
178
+ /**
179
+ * @var AVH_EC_Category_Group
180
+ */
181
+ $catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
182
 
183
+ $this->version = '4.0.3-dev.1';
184
+ $this->comment = '<!-- AVH Extended Categories version ' .
185
+ $this->version .
186
+ ' | http://blog.avirtualhome.com/wordpress-plugins/ -->';
187
+ $this->db_options_core = 'avhec';
188
+ $this->db_options_tax_meta = 'avhec-tax_meta';
 
189
 
190
+ add_action('init', array(&$this, 'handleInitializePlugin'), 10);
 
 
 
 
 
 
 
 
191
  }
192
 
193
  /**
194
+ * PHP4 Constructor
 
195
  *
196
+ * @return AVHExtendedCategoriesCore
197
  */
198
+ function AVH_EC_Core() {
199
+ $this->__construct();
 
 
 
 
 
 
200
  }
201
 
202
+ function applyOrderFilter($orderby, $args) {
203
+ switch ($args['orderby']) {
204
+ case 'avhec_manualorder':
205
+ $new_orderby = 't.avhec_term_order';
206
+ break;
207
+ case 'avhec_3rdparty_mycategoryorder':
208
+ $new_orderby = 't.term_order';
209
+ break;
210
+ default:
211
+ $new_orderby = $orderby;
212
+ break;
 
 
213
  }
 
 
214
 
215
+ return $new_orderby;
 
 
 
 
 
 
 
216
  }
217
 
218
  /**
219
  * Display or retrieve the HTML dropdown list of categories.
 
220
  * The list of arguments is below:
221
  * 'show_option_all' (string) - Text to display for showing all categories.
222
  * 'show_option_none' (string) - Text to display for showing no categories.
236
  * 'name' (string) - The name attribute value for selected element.
237
  * 'class' (string) - The class attribute value for selected element.
238
  * 'selected' (int) - Which category ID is selected.
 
239
  * The 'hierarchical' argument, which is disabled by default, will override the
240
  * depth argument, unless it is true. When the argument is false, it will
241
  * display all of the categories. When it is enabled it will use the value in
244
  * @since 2.1.0
245
  *
246
  * @param string|array $args Optional. Override default arguments.
247
+ *
248
  * @return string HTML content only if 'echo' argument is 0.
249
  */
250
+ function avh_wp_dropdown_categories($args = '', $selectedonly) {
 
251
  $mywalker = new AVH_Walker_CategoryDropdown();
252
 
253
+ $defaults = array(
254
+ 'show_option_all' => '',
255
+ 'show_option_none' => '',
256
+ 'orderby' => 'id',
257
+ 'order' => 'ASC',
258
+ 'show_last_update' => 0,
259
+ 'show_count' => 0,
260
+ 'hide_empty' => 1,
261
+ 'child_of' => 0,
262
+ 'exclude' => '',
263
+ 'echo' => 1,
264
+ 'selected' => 0,
265
+ 'hierarchical' => 0,
266
+ 'name' => 'cat',
267
+ 'class' => 'postform',
268
+ 'depth' => 0,
269
+ 'tab_index' => 0,
270
+ 'walker' => $mywalker
271
+ );
272
 
273
  $defaults['selected'] = (is_category()) ? get_query_var('cat') : 0;
274
 
275
  $r = wp_parse_args($args, $defaults);
276
 
277
+ if ( ! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
278
  $r['pad_counts'] = true;
279
  }
280
 
282
  extract($r);
283
 
284
  $tab_index_attribute = '';
285
+ if ((int) $tab_index > 0) {
286
  $tab_index_attribute = ' tabindex="' . $tab_index . '"';
287
+ }
288
 
289
  $categories = get_categories($r);
290
+ $name = esc_attr($name);
291
+ $class = esc_attr($class);
292
 
293
  $output = '';
294
+ if ( ! empty($categories)) {
295
+ $output = '<select name="' .
296
+ $name .
297
+ '" id="' .
298
+ $name .
299
+ '" class="' .
300
+ $class .
301
+ '" ' .
302
+ $tab_index_attribute .
303
+ '>' .
304
+ "\n";
305
 
306
  if ($show_option_all) {
307
  $show_option_all = apply_filters('list_cats', $show_option_all);
308
+ $selected = ('0' === strval($r['selected'])) ? " selected='selected'" : '';
309
  $output .= "\t" . '<option value="0"' . $selected . '>' . $show_option_all . '</option>' . "\n";
310
  }
311
 
312
  if ($show_option_none) {
313
  $show_option_none = apply_filters('list_cats', $show_option_none);
314
+ $selected = ('-1' === strval($r['selected'])) ? " selected='selected'" : '';
315
  $output .= "\t" . '<option value="-1"' . $selected . '>' . $show_option_none . '</option>' . "\n";
316
  }
317
 
326
 
327
  $output = apply_filters('wp_dropdown_cats', $output);
328
 
329
+ if ($echo) {
330
  echo $output;
331
+ }
332
 
333
  return $output;
334
  }
335
 
336
  /**
337
  * Display or retrieve the HTML list of categories.
 
338
  * The list of arguments is below:
339
  * 'show_option_all' (string) - Text to display for showing all categories.
340
  * 'orderby' (string) default is 'ID' - What column to use for ordering the
360
  * 'title_li' (string) - See {@link get_categories()}.
361
  * 'depth' (int) - The max depth.
362
  *
363
+ * @since 2.1.0
364
+ *
365
+ * @param string|array $args Optional. Override default arguments.
366
+ *
367
+ * @return string HTML content only if 'echo' argument is 0.
368
+ */
369
+ function avh_wp_list_categories($args = '', $selectedonly) {
370
+ $mywalker = new AVHEC_Walker_Category();
371
+ $defaults = array(
372
+ 'show_option_all' => '',
373
+ 'orderby' => 'name',
374
+ 'order' => 'ASC',
375
+ 'show_last_update' => 0,
376
+ 'style' => 'list',
377
+ 'show_count' => 0,
378
+ 'hide_empty' => 1,
379
+ 'use_desc_for_title' => 1,
380
+ 'child_of' => 0,
381
+ 'feed' => '',
382
+ 'feed_type' => '',
383
+ 'feed_image' => '',
384
+ 'exclude' => '',
385
+ 'exclude_tree' => '',
386
+ 'current_category' => 0,
387
+ 'hierarchical' => true,
388
+ 'title_li' => __('Categories'),
389
+ 'echo' => 1,
390
+ 'depth' => 0,
391
+ 'walker' => $mywalker
392
+ );
393
+
394
+ $r = wp_parse_args($args, $defaults);
395
+
396
+ if ( ! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
397
+ $r['pad_counts'] = true;
398
+ }
399
+
400
+ if ( ! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
401
+ $r['pad_counts'] = true;
402
+ }
403
+
404
+ if (isset($r['show_date'])) {
405
+ $r['include_last_update_time'] = $r['show_date'];
406
+ }
407
+
408
+ if (true == $r['hierarchical']) {
409
+ $r['exclude_tree'] = $r['exclude'];
410
+ $r['exclude'] = '';
411
+ }
412
+
413
+ extract($r);
414
+
415
+ $categories = get_categories($r);
416
+
417
+ $output = '';
418
+ if ($title_li && 'list' == $style) {
419
+ $output = '<li class="categories">' . $r['title_li'] . '<ul>';
420
+ }
421
+
422
+ if (empty($categories)) {
423
+ if ('list' == $style) {
424
+ $output .= '<li>' . __("No categories") . '</li>';
425
+ } else {
426
+ $output .= __("No categories");
427
+ }
428
+ } else {
429
+ global $wp_query;
430
+
431
+ if ( ! empty($show_option_all)) {
432
+ if ('list' == $style) {
433
+ $output .= '<li><a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a></li>';
434
+ } else {
435
+ $output .= '<a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a>';
436
+ }
437
+ }
438
+
439
+ if (empty($r['current_category']) && is_category()) {
440
+ $r['current_category'] = $wp_query->get_queried_object_id();
441
+ }
442
+
443
+ if ($hierarchical) {
444
+ $depth = $r['depth'];
445
+ } else {
446
+ $depth = - 1; // Flat.
447
+ }
448
+
449
+ $output .= walk_category_tree($categories, $depth, $r);
450
+ }
451
+
452
+ if ($title_li && 'list' == $style) {
453
+ $output .= '</ul></li>';
454
+ }
455
+
456
+ $output = apply_filters('wp_list_categories', $output);
457
+
458
+ if ($echo) {
459
+ echo $output;
460
+ } else {
461
+ return $output;
462
+ }
463
+ }
464
+
465
+ /**
466
+ * Checks if running version is newer and do upgrades if necessary
467
+ *
468
+ * @since 1.2.3
469
+ */
470
+ function doUpdateOptions($db_version) {
471
+ $options = $this->getOptions();
472
+
473
+ // Add none existing sections and/or elements to the options
474
+ foreach ($this->default_options as $section => $default_data) {
475
+ if ( ! array_key_exists($section, $options)) {
476
+ $options[ $section ] = $default_data;
477
+ continue;
478
+ }
479
+ foreach ($default_data as $element => $default_value) {
480
+ if ( ! array_key_exists($element, $options[ $section ])) {
481
+ $options[ $section ][ $element ] = $default_value;
482
+ }
483
+ }
484
+ }
485
+
486
+ // Remove none existing sections and/or elements from the options
487
+ foreach ($options as $section => $data) {
488
+ if ( ! array_key_exists($section, $this->default_options)) {
489
+ unset($options[ $section ]);
490
+ continue;
491
+ }
492
+ foreach ($data as $element => $value) {
493
+ if ( ! array_key_exists($element, $this->default_options[ $section ])) {
494
+ unset($options[ $section ][ $element ]);
495
+ }
496
+ }
497
+ }
498
+ /**
499
+ * Update the options to the latests versions
500
+ */
501
+ $options['general']['version'] = $this->version;
502
+ $options['general']['dbversion'] = $db_version;
503
+ $this->saveOptions($options);
504
+ }
505
+
506
+ /**
507
+ * Get the base directory of a directory structure
508
+ *
509
+ * @param string $directory
510
+ *
511
+ * @return string
512
+ */
513
+ function getBaseDirectory($directory) {
514
+ //place each directory into array and get the last element
515
+ $return = end(explode('/', $directory));
516
+
517
+ return $return;
518
+ }
519
+
520
+ function getCategories() {
521
+ static $_categories = null;
522
+ if (null === $_categories) {
523
+ $_categories = get_categories('get=all');
524
+ }
525
+
526
+ return $_categories;
527
+ }
528
+
529
+ function getCategoriesId($categories) {
530
+ static $_categories_id = null;
531
+ if (null == $_categories_id) {
532
+ foreach ($categories as $key => $category) {
533
+ $_categories_id[ $category->term_id ] = $key;
534
+ }
535
+ }
536
+
537
+ return $_categories_id;
538
+ }
539
+
540
+ /*********************************
541
+ * *
542
+ * Methods for variable: options *
543
+ * *
544
+ ********************************/
545
+
546
+ /**
547
+ * Get the value for an option element. If there's no option is set on the Admin page, return the default value.
548
+ *
549
+ * @param string $key
550
+ * @param string $option
551
  *
552
+ * @return mixed
 
553
  */
554
+ function getOptionElement($option, $key) {
555
+ if ($this->options[ $option ][ $key ]) {
556
+ $return = $this->options[ $option ][ $key ]; // From Admin Page
557
+ } else {
558
+ $return = $this->default_options[ $option ][ $key ]; // Default
 
 
 
 
559
  }
560
 
561
+ return ($return);
562
+ }
 
563
 
564
+ /**
565
+ * return array
566
+ */
567
+ function getOptions() {
568
+ return ($this->options);
569
+ }
570
 
571
+ /**
572
+ * @param array $data
573
+ */
574
+ function setOptions($options) {
575
+ $this->options = $options;
576
+ }
577
 
578
+ function handleInitializePlugin() {
579
+ global $wpdb;
580
 
581
+ $catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
582
+ $db_version = 4;
583
 
584
+ $info['siteurl'] = get_option('siteurl');
585
+ $info['plugin_dir'] = AVHEC_PLUGIN_DIR;
586
+ $info['graphics_url'] = AVHEC_PLUGIN_URL . '/images';
587
 
588
+ // Set class property for info
589
+ $this->info = array(
590
+ 'home' => get_option('home'),
591
+ 'siteurl' => $info['siteurl'],
592
+ 'plugin_dir' => $info['plugin_dir'],
593
+ 'js_dir' => $info['plugin_dir'] . '/js',
594
+ 'graphics_url' => $info['graphics_url']
595
+ );
596
 
597
+ // Set the default options
598
+ $this->default_options_general = array(
599
+ 'version' => $this->version,
600
+ 'dbversion' => $db_version,
601
+ 'alternative_name_select_category' => ''
602
+ );
603
 
604
+ // Set the default category group options
605
+ $no_group_id = $catgrp->getTermIDBy('slug', 'none');
606
+ $home_group_id = $catgrp->getTermIDBy('slug', 'home');
607
+ $default_group_id = $catgrp->getTermIDBy('slug', 'all');
608
+ $this->default_options_category_group = array(
609
+ 'no_group' => $no_group_id,
610
+ 'home_group' => $home_group_id,
611
+ 'default_group' => $default_group_id
612
+ );
613
+
614
+ $this->default_options_sp_category_group = array(
615
+ 'home_group' => $home_group_id,
616
+ 'category_group' => $default_group_id,
617
+ 'day_group' => $default_group_id,
618
+ 'month_group' => $default_group_id,
619
+ 'year_group' => $default_group_id,
620
+ 'author_group' => $default_group_id,
621
+ 'search_group' => $default_group_id
622
+ );
623
+
624
+ $this->default_options = array(
625
+ 'general' => $this->default_options_general,
626
+ 'cat_group' => $this->default_options_category_group,
627
+ 'widget_titles' => array(),
628
+ 'sp_cat_group' => $this->default_options_sp_category_group
629
+ );
630
 
631
+ /**
632
+ * Set the options for the program
633
+ */
634
+ $this->loadOptions();
 
635
 
636
+ // Check if we have to do updates
637
+ if (( ! isset($this->options['general']['dbversion'])) ||
638
+ $this->options['general']['dbversion'] < $db_version
639
+ ) {
640
+ $this->doUpdateOptions($db_version);
641
  }
642
 
643
+ $db = new AVH_DB();
644
+ if ( ! $db->field_exists('avhec_term_order', $wpdb->terms)) {
645
+ $wpdb->query("ALTER TABLE $wpdb->terms ADD `avhec_term_order` INT( 4 ) NULL DEFAULT '0'");
646
+ }
647
 
648
+ $this->handleTextdomain();
649
+ add_filter('get_terms_orderby', array(&$this, 'applyOrderFilter'), 10, 2);
650
+ }
651
 
652
+ /**
653
+ * Loads the i18n
654
+ *
655
+ * @return
656
+ */
657
+ function handleTextdomain() {
658
+
659
+ load_plugin_textdomain('avh-ec', false, AVHEC_RELATIVE_PLUGIN_DIR . '/lang');
660
  }
661
 
662
+ /**
663
+ * Used in forms to set the checked option.
664
+ *
665
+ * @param mixed $checked
666
+ * @param mixed_type $current
667
+ *
668
+ * @return string
669
+ * @since 2.0
670
+ */
671
+ function isChecked($checked, $current) {
672
+ if ($checked == $current) {
673
+ return (' checked="checked"');
674
  }
675
+
676
+ return ('');
677
  }
678
 
679
+ /**
680
+ * Used in forms to set the SELECTED option
681
+ *
682
+ * @param string $current
683
+ * @param string $field
684
+ *
685
+ * @return string
686
+ */
687
+ function isSelected($current, $field) {
688
+ if ($current == $field) {
689
+ return (' SELECTED');
690
  }
691
+
692
+ return ('');
693
+ }
694
+
695
+ /**
696
+ * Retrieves the plugin options from the WordPress options table and assigns to class variable.
697
+ * If the options do not exists, like a new installation, the options are set to the default value.
698
+ *
699
+ * @return none
700
+ */
701
+ function loadOptions() {
702
+ $options = get_option($this->db_options_core);
703
+ if (false === $options) { // New installation
704
+ $this->resetToDefaultOptions();
705
+ } else {
706
+ $this->setOptions($options);
707
+ }
708
+ }
709
+
710
+ /**
711
+ * Reset to default options and save in DB
712
+ */
713
+ function resetToDefaultOptions() {
714
+ $this->options = $this->default_options;
715
+ $this->saveOptions($this->default_options);
716
+ }
717
+
718
+ /**
719
+ * Save all current options and set the options
720
+ */
721
+ function saveOptions($options) {
722
+ update_option($this->db_options_core, $options);
723
+ wp_cache_flush(); // Delete cache
724
+ $this->setOptions($options);
725
  }
726
  }
727
 
730
  *
731
  * @uses Walker
732
  */
733
+ class AVH_Walker_CategoryDropdown extends Walker_CategoryDropdown {
734
+ function walk($elements, $max_depth) {
 
 
 
735
 
736
+ $args = array_slice(func_get_args(), 2);
737
  $output = '';
738
 
739
  if ($max_depth < - 1) //invalid parameter
740
+ {
741
  return $output;
742
+ }
743
 
744
  if (empty($elements)) //nothing to walk
745
+ {
746
  return $output;
747
+ }
748
 
749
+ $id_field = $this->db_fields['id'];
750
  $parent_field = $this->db_fields['parent'];
751
 
752
  // flat display
753
  if (- 1 == $max_depth) {
754
+ $empty_array = array();
755
+ foreach ($elements as $e) {
756
  $this->display_element($e, $empty_array, 1, 0, $args, $output);
757
+ }
758
+
759
  return $output;
760
  }
761
 
765
  * children_elements is two dimensional array, eg.
766
  * children_elements[10][] contains all sub-elements whose parent is 10.
767
  */
768
+ $top_level_elements = array();
769
+ $children_elements = array();
770
  foreach ($elements as $e) {
771
+ if (0 == $e->$parent_field) {
772
  $top_level_elements[] = $e;
773
+ } else {
774
+ $children_elements[ $e->$parent_field ][] = $e;
775
+ }
776
  }
777
 
778
  /*
782
  if (empty($top_level_elements)) {
783
 
784
  $first = array_slice($elements, 0, 1);
785
+ $root = $first[0];
786
 
787
+ $top_level_elements = array();
788
+ $children_elements = array();
789
  foreach ($elements as $e) {
790
+ if ($root->$parent_field == $e->$parent_field) {
791
  $top_level_elements[] = $e;
792
+ } else {
793
+ $children_elements[ $e->$parent_field ][] = $e;
794
+ }
795
  }
796
  }
797
 
798
+ foreach ($top_level_elements as $e) {
799
  $this->display_element($e, $children_elements, $max_depth, 0, $args, $output);
800
+ }
801
 
802
+ /*
803
+ * if we are displaying all levels, and remaining children_elements is not empty,
804
+ * then we got orphans, which should be displayed regardless
805
+ */
806
  if ((0 == $max_depth) && count($children_elements) > 0) {
807
+ $empty_array = array();
808
+ foreach ($children_elements as $orphans) {
809
+ foreach ($orphans as $op) {
810
  $this->display_element($op, $empty_array, 1, 0, $args, $output);
811
+ }
812
+ }
813
  }
814
 
815
  return $output;
816
  }
817
  }
818
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
819
  ?>
2.8/class/avh-ec.widgets.php CHANGED
@@ -1,175 +1,228 @@
1
  <?php
2
 
3
  /**
4
- * Widget Class for displaying categories. Extended version of the dfeault categories.
5
- *
6
  */
7
- class WP_Widget_AVH_ExtendedCategories_Normal extends WP_Widget
8
- {
9
- /**
10
- *
11
- * @var AVH_EC_Core
12
- */
13
- var $core;
14
-
15
- /**
16
- * PHP 5 Constructor
17
- *
18
- */
19
- function __construct ()
20
- {
21
- $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core');
22
-
23
- //Convert the old option widget_extended_categories to widget_extended-categories
24
- $old = get_option('widget_extended_categories');
25
- if (! (FALSE === $old)) {
26
- update_option('widget_extended-categories', $old);
27
- delete_option('widget_extended_categories');
28
- }
29
- $widget_ops = array('description'=>__("An extended version of the default Categories widget.", 'avh-ec'));
30
- WP_Widget::__construct('extended-categories', 'AVH Extended Categories', $widget_ops);
31
-
32
- add_action('wp_print_styles', array(&$this, 'actionWpPrintStyles'));
33
 
 
 
34
  }
35
 
36
- function WP_Widget_AVH_ExtendedCategories_Normal ()
37
- {
38
- $this->__construct();
39
  }
40
 
41
- function actionWpPrintStyles ()
42
- {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
- if (! (FALSE === is_active_widget(FALSE, FALSE, $this->id_base, TRUE))) {
45
- wp_register_style('avhec-widget', AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', array(), $this->core->version);
46
- wp_enqueue_style('avhec-widget');
47
- }
48
  }
49
 
50
  /**
51
- * Display the widget
 
 
 
 
52
  *
53
- * @param unknown_type $args
54
- * @param unknown_type $instance
 
 
 
 
 
55
  */
56
- function widget ($args, $instance)
57
- {
58
-
59
- extract($args);
60
 
61
- $selectedonly = $instance['selectedonly'] ? TRUE : FALSE;
62
- $c = $instance['count'] ? TRUE : FALSE;
63
- $h = $instance['hierarchical'] ? TRUE : FALSE;
64
- $d = $instance['depth'] ? $instance['depth'] : 0;
65
- $e = $instance['hide_empty'] ? TRUE : FALSE;
66
- $use_desc_for_title = $instance['use_desc_for_title'] ? TRUE : FALSE;
67
- $s = $instance['sort_column'] ? $instance['sort_column'] : 'name';
68
- $o = $instance['sort_order'] ? $instance['sort_order'] : 'asc';
69
- $r = $instance['rssfeed'] ? 'RSS' : '';
70
- $i = $instance['rssimage'] ? $instance['rssimage'] : '';
71
- $invert = $instance['invert_included'] ? TRUE : FALSE;
72
 
73
- if (empty($r)) {
74
- $i = '';
 
75
  }
76
 
77
- if (empty($d)) {
78
- $d = 0;
 
79
  }
80
 
81
- $title = apply_filters('widget_title', empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']);
82
- $style = empty($instance['style']) ? 'list' : $instance['style'];
83
 
84
- $included_cats = '';
85
- if ($instance['post_category']) {
86
- $post_category = unserialize($instance['post_category']);
87
- $children = array();
88
- if (! $instance['selectedonly']) {
89
- foreach ($post_category as $cat_id) {
90
- $children = array_merge($children, get_term_children($cat_id, 'category'));
91
- }
92
  }
93
- $included_cats = implode(",", array_merge($post_category, $children));
 
94
  }
95
 
96
- if ($invert) {
97
- $inc_exc = 'exclude';
98
- } else {
99
- $inc_exc = 'include';
 
 
 
 
 
 
 
 
 
 
100
  }
101
 
102
- $options = $this->core->getOptions();
103
- $show_option_none = __('Select Category', 'avh-ec');
104
- if ($options['general']['alternative_name_select_category']) {
105
- $show_option_none = $options['general']['alternative_name_select_category'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  }
107
 
108
- $cat_args = array($inc_exc=>$included_cats, 'orderby'=>$s, 'order'=>$o, 'show_count'=>$c, 'use_desc_for_title'=>$use_desc_for_title, 'hide_empty'=>$e, 'hierarchical'=>$h, 'depth'=>$d, 'title_li'=>'', 'show_option_none'=>$show_option_none, 'feed'=>$r, 'feed_image'=>$i, 'name'=>'extended-categories-select-' . $this->number);
109
- echo $before_widget;
110
- echo $this->core->comment;
111
- echo $before_title . $title . $after_title;
112
 
113
- if ($style == 'list') {
114
- echo '<ul>';
115
- $this->core->avh_wp_list_categories($cat_args, $selectedonly);
116
- echo '</ul>';
117
- } else {
118
- $this->core->avh_wp_dropdown_categories($cat_args, $selectedonly);
119
- echo '<script type=\'text/javascript\'>' . "\n";
120
- echo '/* <![CDATA[ */' . "\n";
121
- echo ' var ec_dropdown_' . $this->number . ' = document.getElementById("extended-categories-select-' . $this->number . '");' . "\n";
122
- echo ' function ec_onCatChange_' . $this->number . '() {' . "\n";
123
- echo ' if ( ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value > 0 ) {' . "\n";
124
- echo ' location.href = "' . get_option('home') . '/?cat="+ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value;' . "\n";
125
- echo ' }' . "\n";
126
- echo ' }' . "\n";
127
- echo ' ec_dropdown_' . $this->number . '.onchange = ec_onCatChange_' . $this->number . ';' . "\n";
128
- echo '/* ]]> */' . "\n";
129
- echo '</script>' . "\n";
130
  }
131
- echo $after_widget;
 
132
  }
 
133
 
 
 
 
 
134
  /**
135
- * When Widget Control Form Is Posted
136
- *
137
- * @param unknown_type $new_instance
138
- * @param unknown_type $old_instance
139
- * @return unknown
140
  */
141
- function update ($new_instance, $old_instance)
142
- {
143
- // update the instance's settings
144
- if (! isset($new_instance['submit'])) {
145
- return FALSE;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
  }
 
147
 
148
- $instance = $old_instance;
149
 
150
- $instance['title'] = strip_tags(stripslashes($new_instance['title']));
151
- $instance['selectedonly'] = $new_instance['selectedonly'] ? TRUE : FALSE;
152
- $instance['count'] = $new_instance['count'] ? TRUE : FALSE;
153
- $instance['hierarchical'] = $new_instance['hierarchical'] ? TRUE : FALSE;
154
- $instance['hide_empty'] = $new_instance['hide_empty'] ? TRUE : FALSE;
155
- $instance['use_desc_for_title'] = $new_instance['use_desc_for_title'] ? TRUE : FALSE;
156
- $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column']));
157
- $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order']));
158
- $instance['style'] = strip_tags(stripslashes($new_instance['style']));
159
- $instance['rssfeed'] = $new_instance['rssfeed'] ? TRUE : FALSE;
160
- $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage']));
161
- if (array_key_exists('all', $new_instance['post_category'])) {
162
- $instance['post_category'] = FALSE;
 
 
 
 
163
  } else {
164
- $instance['post_category'] = serialize($new_instance['post_category']);
165
  }
166
- $instance['depth'] = (int) $new_instance['depth'];
167
- if ($instance['depth'] < 0 || 11 < $instance['depth']) {
168
- $instance['depth'] = 0;
 
 
 
 
 
 
 
 
 
169
  }
170
- $instance['invert_included'] = $new_instance['invert_included'] ? TRUE : FALSE;
171
 
172
- return $instance;
 
 
 
173
  }
174
 
175
  /**
@@ -177,398 +230,187 @@ class WP_Widget_AVH_ExtendedCategories_Normal extends WP_Widget
177
  *
178
  * @param unknown_type $instance
179
  */
180
- function form ($instance)
181
- {
182
  // displays the widget admin form
183
- $instance = wp_parse_args((array) $instance, array('title'=>'', 'rssimage'=>'', 'depth'=>0));
184
 
185
  // Prepare data for display
186
- $depth = (int) $instance['depth'];
187
- if ($depth < 0 || 11 < $depth) {
188
- $depth = 0;
189
- }
190
- $selected_cats = ($instance['post_category'] != '') ? unserialize($instance['post_category']) : FALSE;
191
-
 
 
 
 
 
 
 
 
 
 
 
 
192
  echo '<p>';
193
- avh_doWidgetFormText($this->get_field_id('title'), $this->get_field_name('title'), __('Title', 'avh-ec'), $instance['title']);
 
 
 
194
  echo '</p>';
195
 
196
  echo '<p>';
197
- avh_doWidgetFormCheckbox($this->get_field_id('selectedonly'), $this->get_field_name('selectedonly'), __('Show selected categories only', 'avh-ec'), (bool) $instance['selectedonly']);
198
-
199
- avh_doWidgetFormCheckbox($this->get_field_id('count'), $this->get_field_name('count'), __('Show post counts', 'avh-ec'), (bool) $instance['count']);
200
-
201
- avh_doWidgetFormCheckbox($this->get_field_id('hierarchical'), $this->get_field_name('hierarchical'), __('Show hierarchy', 'avh-ec'), (bool) $instance['hierarchical']);
202
-
203
- $options = array(0=>__('All Levels', 'avh-ec'), 1=>__('Toplevel only', 'avh-ec'));
204
- for ($i = 2; $i <= 11; $i ++) {
205
- $options[$i] = __('Child ', 'avh-ec') . ($i - 1);
206
- }
207
- avh_doWidgetFormSelect($this->get_field_id('depth'), $this->get_field_name('depth'), __('How many levels to show', 'avh-ec'), $options, $depth);
208
- unset($options);
209
 
210
- avh_doWidgetFormCheckbox($this->get_field_id('hide_empty'), $this->get_field_name('hide_empty'), __('Hide empty categories', 'avh-ec'), (bool) $instance['hide_empty']);
211
-
212
- avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'), $this->get_field_name('use_desc_for_title'), __('Use description for title', 'avh-ec'), (bool) $instance['use_desc_for_title']);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
  echo '</p>';
214
 
215
  echo '<p>';
216
- $options['ID'] = __('ID', 'avh-ec');
217
- $options['name'] = __('Name', 'avh-ec');
218
  $options['count'] = __('Count', 'avh-ec');
219
- $options['slug'] = __('Slug', 'avh-ec');
220
- if (is_plugin_active('my-category-order/mycategoryorder.php')) {
221
- $options['avhec_3rdparty_mycategoryorder'] = 'My Category Order';
222
- }
223
-
224
- avh_doWidgetFormSelect($this->get_field_id('sort_column'), $this->get_field_name('sort_column'), __('Sort by', 'avh-ec'), $options, $instance['sort_column']);
225
  unset($options);
226
 
227
- $options['asc'] = __('Ascending', 'avh-ec');
228
  $options['desc'] = __('Descending', 'avh-ec');
229
- avh_doWidgetFormSelect($this->get_field_id('sort_order'), $this->get_field_name('sort_order'), __('Sort order', 'avh-ec'), $options, $instance['sort_order']);
 
 
 
 
230
  unset($options);
231
 
232
  $options['list'] = __('List', 'avh-ec');
233
  $options['drop'] = __('Drop down', 'avh-ec');
234
- avh_doWidgetFormSelect($this->get_field_id('style'), $this->get_field_name('style'), __('Display style', 'avh-ec'), $options, $instance['style']);
 
 
 
 
235
  unset($options);
236
  echo '</p>';
237
 
238
  echo '<p>';
239
 
240
- avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), $this->get_field_name('rssfeed'), __('Show RSS Feed', 'avh-ec'), (bool) $instance['rssfeed']);
241
-
242
- avh_doWidgetFormText($this->get_field_id('rssimage'), $this->get_field_name('rssimage'), __('Path (URI) to RSS image', 'avh-ec'), $instance['rssimage']);
 
243
 
 
 
 
 
244
  echo '</p>';
245
 
246
  echo '<p>';
247
- echo '<b>' . __('Select categories', 'avh-ec') . '</b><hr />';
248
  echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear" style="list-style-type: none; margin-left: 5px; padding-left: 0px; margin-bottom: 20px;">';
249
- echo '<li id="' . $this->get_field_id('category--1') . '" class="popular-category">';
250
- echo '<label for="' . $this->get_field_id('post_category') . '" class="selectit">';
251
- echo '<input value="all" id="' . $this->get_field_id('post_category') . '" name="' . $this->get_field_name('post_category') . '[all]" type="checkbox" ' . (FALSE === $selected_cats ? ' CHECKED' : '') . '> ';
252
- _e('All Categories', 'avh-ec');
 
 
 
 
 
 
253
  echo '</label>';
254
  echo '</li>';
255
- ob_start();
256
- $this->avh_wp_category_checklist($selected_cats, $this->number);
257
- ob_end_flush();
258
  echo '</ul>';
259
  echo '</p>';
260
 
261
- echo '<p>';
262
- avh_doWidgetFormCheckbox($this->get_field_id('invert_included'), $this->get_field_name('invert_included'), __('Exclude the selected categories', 'avh-ec'), (bool) $instance['invert_included']);
263
- echo '</p>';
 
 
 
 
 
 
 
 
 
 
 
264
 
265
- echo '<input type="hidden" id="' . $this->get_field_id('submit') . '" name="' . $this->get_field_name('submit') . '" value="1" />';
266
  }
267
 
268
  /**
269
- * Creates the categories checklist
270
  *
271
- * @param int $post_id
272
- * @param int $descendants_and_self
273
- * @param array $selected_cats
274
- * @param array $popular_cats
275
- * @param int $number
276
  */
277
- function avh_wp_category_checklist ($selected_cats, $number)
278
- {
279
-
280
- $walker = new AVH_Walker_Category_Checklist();
281
- $walker->number = $number;
282
- $walker->input_id = $this->get_field_id('post_category');
283
- $walker->input_name = $this->get_field_name('post_category');
284
- $walker->li_id = $this->get_field_id('category--1');
285
-
286
- $args = array('taxonomy'=>'category', 'descendants_and_self'=>0, 'selected_cats'=>$selected_cats, 'popular_cats'=>array(), 'walker'=>$walker, 'checked_ontop'=>true, 'popular_cats'=>array());
287
-
288
- if (is_array($selected_cats))
289
- $args['selected_cats'] = $selected_cats;
290
- else
291
- $args['selected_cats'] = array();
292
 
293
- $categories = $this->core->getCategories();
294
- $_categories_id = $this->core->getCategoriesId($categories);
295
 
296
- // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache)
297
- $checked_categories = array();
298
- foreach ($args['selected_cats'] as $key => $value) {
299
- if (isset($_categories_id[$key])) {
300
- $category_key = $_categories_id[$key];
301
- $checked_categories[] = $categories[$category_key];
302
- unset($categories[$category_key]);
303
- }
 
 
 
 
 
 
304
  }
305
 
306
- // Put checked cats on top
307
- echo $walker->walk($checked_categories, 0, array ( $args ));
308
- // Then the rest of them
309
- echo $walker->walk($categories, 0, array ( $args ));
310
  }
311
- }
312
 
313
- /**
314
- * Widget Class for displaying the top categories
315
- *
316
- */
317
- class WP_Widget_AVH_ExtendedCategories_Top extends WP_Widget
318
- {
319
  /**
320
- *
321
- * @var AVH_EC_Core
322
- */
323
- var $core;
324
-
325
- /**
326
- * PHP 5 Constructor
327
- *
328
- */
329
- function __construct ()
330
- {
331
- $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core');
332
-
333
- $widget_ops = array('description'=>__("Shows the top categories.", 'avh-ec'));
334
- WP_Widget::__construct(FALSE, 'AVH Extended Categories: '.__('Top Categories'), $widget_ops);
335
- add_action('wp_print_styles', array(&$this, 'actionWpPrintStyles'));
336
-
337
- }
338
-
339
- function WP_Widget_AVH_ExtendedCategories_Top ()
340
- {
341
- $this->__construct();
342
- }
343
-
344
- function actionWpPrintStyles ()
345
- {
346
- if (! (FALSE === is_active_widget(FALSE, FALSE, $this->id_base, TRUE))) {
347
- wp_register_style('avhec-widget', AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', array(), $this->core->version);
348
- wp_enqueue_style('avhec-widget');
349
- }
350
- }
351
-
352
- /** Echo the widget content.
353
- *
354
- * Subclasses should over-ride this function to generate their widget code.
355
- *
356
- * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
357
- * @param array $instance The settings for the particular instance of the widget
358
- */
359
- function widget ($args, $instance)
360
- {
361
- extract($args);
362
-
363
- $title = apply_filters('widget_title', empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']);
364
- $style = empty($instance['style']) ? 'list' : $instance['style'];
365
- if (! $a = (int) $instance['amount']) {
366
- $a = 5;
367
- } elseif ($a < 1) {
368
- $a = 1;
369
- }
370
- $c = $instance['count'] ? TRUE : FALSE;
371
- $use_desc_for_title = $instance['use_desc_for_title'] ? TRUE : FALSE;
372
- $s = $instance['sort_column'] ? $instance['sort_column'] : 'name';
373
- $o = $instance['sort_order'] ? $instance['sort_order'] : 'asc';
374
- $r = $instance['rssfeed'] ? 'RSS' : '';
375
- $i = $instance['rssimage'] ? $instance['rssimage'] : '';
376
- if (empty($r)) {
377
- $i = '';
378
- }
379
- if (! empty($i)) {
380
- if (! file_exists(ABSPATH . '/' . $i)) {
381
- $i = '';
382
- }
383
- }
384
-
385
- $options = $this->core->getOptions();
386
- $show_option_none = __('Select Category', 'avh-ec');
387
- if ($options['general']['alternative_name_select_category']) {
388
- $show_option_none = $options['general']['alternative_name_select_category'];
389
- }
390
-
391
- $top_cats = get_terms('category', array('fields'=>'ids', 'orderby'=>'count', 'order'=>'DESC', 'number'=>$a, 'hierarchical'=>FALSE));
392
- $included_cats = implode(",", $top_cats);
393
-
394
- $cat_args = array('include'=>$included_cats, 'orderby'=>$s, 'order'=>$o, 'show_count'=>$c, 'use_desc_for_title'=>$use_desc_for_title, 'hide_empty'=>FALSE, 'hierarchical'=>FALSE, 'depth'=>- 1, 'title_li'=>'', 'show_option_none'=>$show_option_none, 'feed'=>$r, 'feed_image'=>$i, 'name'=>'extended-categories-top-select-' . $this->number);
395
- echo $before_widget;
396
- echo $this->core->comment;
397
- echo $before_title . $title . $after_title;
398
- echo '<ul>';
399
-
400
- if ($style == 'list') {
401
- wp_list_categories($cat_args);
402
- } else {
403
- wp_dropdown_categories($cat_args);
404
- echo '<script type=\'text/javascript\'>' . "\n";
405
- echo '/* <![CDATA[ */' . "\n";
406
- echo ' var ec_dropdown_top_' . $this->number . ' = document.getElementById("extended-categories-top-select-' . $this->number . '");' . "\n";
407
- echo ' function ec_top_onCatChange_' . $this->number . '() {' . "\n";
408
- echo ' if ( ec_dropdown_top_' . $this->number . '.options[ec_dropdown_top_' . $this->number . '.selectedIndex].value > 0 ) {' . "\n";
409
- echo ' location.href = "' . get_option('home') . '/?cat="+ec_dropdown_top_' . $this->number . '.options[ec_dropdown_top_' . $this->number . '.selectedIndex].value;' . "\n";
410
- echo ' }' . "\n";
411
- echo ' }' . "\n";
412
- echo ' ec_dropdown_top_' . $this->number . '.onchange = ec_top_onCatChange_' . $this->number . ';' . "\n";
413
- echo '/* ]]> */' . "\n";
414
- echo '</script>' . "\n";
415
- }
416
- echo '</ul>';
417
- echo $after_widget;
418
- }
419
-
420
- /** Update a particular instance.
421
- *
422
- * This function should check that $new_instance is set correctly.
423
- * The newly calculated value of $instance should be returned.
424
- * If "FALSE" is returned, the instance won't be saved/updated.
425
- *
426
- * @param array $new_instance New settings for this instance as input by the user via form()
427
- * @param array $old_instance Old settings for this instance
428
- * @return array Settings to save or bool FALSE to cancel saving
429
- */
430
- function update ($new_instance, $old_instance)
431
- {
432
- // update the instance's settings
433
- if (! isset($new_instance['submit'])) {
434
- return FALSE;
435
- }
436
-
437
- $instance = $old_instance;
438
-
439
- $instance['title'] = strip_tags(stripslashes($new_instance['title']));
440
- $instance['amount'] = (int) $new_instance['amount'];
441
- $instance['count'] = $new_instance['count'] ? TRUE : FALSE;
442
- $instance['use_desc_for_title'] = $new_instance['use_desc_for_title'] ? TRUE : FALSE;
443
- $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column']));
444
- $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order']));
445
- $instance['style'] = strip_tags(stripslashes($new_instance['style']));
446
- $instance['rssfeed'] = $new_instance['rssfeed'] ? TRUE : FALSE;
447
- $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage']));
448
-
449
- return $instance;
450
- }
451
-
452
- /** Echo the settings update form
453
- *
454
- * @param array $instance Current settings
455
- */
456
- function form ($instance)
457
- {
458
- // displays the widget admin form
459
- $instance = wp_parse_args((array) $instance, array('title'=>'', 'rssimage'=>''));
460
-
461
- // Prepare data for display
462
- if (! $amount = (int) $instance['amount']) {
463
- $amount = 5;
464
- }
465
-
466
- if ($amount < 1) {
467
- $amount = 1;
468
- }
469
- echo '<p>';
470
- avh_doWidgetFormText($this->get_field_id('title'), $this->get_field_name('title'), __('Title', 'avh-ec'), $instance['title']);
471
- echo '</p>';
472
-
473
- echo '<p>';
474
- avh_doWidgetFormText($this->get_field_id('amount'), $this->get_field_name('amount'), __('How many categories to show', 'avh-ec'), $amount);
475
- echo '</p>';
476
-
477
- echo '<p>';
478
- avh_doWidgetFormCheckbox($this->get_field_id('count'), $this->get_field_name('count'), __('Show post counts', 'avh-ec'), (bool) $instance['count']);
479
- echo '<br />';
480
-
481
- avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'), $this->get_field_name('use_desc_for_title'), __('Use description for title', 'avh-ec'), (bool) $instance['use_desc_for_title']);
482
- echo '</p>';
483
-
484
- echo '<p>';
485
- $options['ID'] = __('ID', 'avh-ec');
486
- $options['name'] = __('Name', 'avh-ec');
487
- $options['count'] = __('Count', 'avh-ec');
488
- $options['slug'] = __('Slug', 'avh-ec');
489
- avh_doWidgetFormSelect($this->get_field_id('sort_column'), $this->get_field_name('sort_column'), __('Sort by', 'avh-ec'), $options, $instance['sort_column']);
490
- unset($options);
491
-
492
- $options['asc'] = __('Ascending', 'avh-ec');
493
- $options['desc'] = __('Descending', 'avh-ec');
494
- avh_doWidgetFormSelect($this->get_field_id('sort_order'), $this->get_field_name('sort_order'), __('Sort order', 'avh-ec'), $options, $instance['sort_order']);
495
- unset($options);
496
-
497
- $options['list'] = __('List', 'avh-ec');
498
- $options['drop'] = __('Drop down', 'avh-ec');
499
- avh_doWidgetFormSelect($this->get_field_id('style'), $this->get_field_name('style'), __('Display style', 'avh-ec'), $options, $instance['style']);
500
- unset($options);
501
- echo '</p>';
502
-
503
- echo '<p>';
504
-
505
- avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), $this->get_field_name('rssfeed'), __('Show RSS Feed', 'avh-ec'), (bool) $instance['rssfeed']);
506
-
507
- avh_doWidgetFormText($this->get_field_id('rssimage'), $this->get_field_name('rssimage'), __('Path (URI) to RSS image', 'avh-ec'), $instance['rssimage']);
508
-
509
- echo '</p>';
510
-
511
- echo '<input type="hidden" id="' . $this->get_field_id('submit') . '" name="' . $this->get_field_name('submit') . '" value="1" />';
512
- }
513
- }
514
-
515
- /**
516
- * Widget Class for displaying the grouped categories
517
- *
518
- */
519
- class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget
520
- {
521
- /**
522
- *
523
- * @var AVH_EC_Core
524
- */
525
- var $core;
526
-
527
- /**
528
- *
529
- * @var AVH_EC_Category_Group
530
- */
531
- var $catgrp;
532
-
533
- /**
534
- * PHP 5 Constructor
535
- *
536
- */
537
- function __construct ()
538
- {
539
- $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core');
540
- $this->catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
541
-
542
- $widget_ops = array('description'=>__("Shows grouped categories.", 'avh-ec'));
543
- WP_Widget::__construct(FALSE, 'AVH Extended Categories: '.__('Category Group'), $widget_ops);
544
- add_action('wp_print_styles', array(&$this, 'actionWpPrintStyles'));
545
-
546
- }
547
-
548
- function WP_Widget_AVH_ExtendedCategories_Category_Group ()
549
- {
550
- $this->__construct();
551
- }
552
-
553
- function actionWpPrintStyles ()
554
- {
555
- if (! (FALSE === is_active_widget(FALSE, FALSE, $this->id_base, TRUE))) {
556
- wp_register_style('avhec-widget', AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', array(), $this->core->version);
557
- wp_enqueue_style('avhec-widget');
558
- }
559
- }
560
-
561
- /**
562
- * Display the widget
563
  *
564
  * @param unknown_type $args
565
  * @param unknown_type $instance
566
  */
567
- function widget ($args, $instance)
568
- {
569
  global $post, $wp_query;
570
 
571
- $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
572
  $options = $this->core->getOptions();
573
 
574
  $row = array();
@@ -591,79 +433,81 @@ class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget
591
  $special_page = 'none';
592
  }
593
 
594
- $toDisplay = FALSE;
595
  if ('none' == $special_page) {
596
  $terms = wp_get_object_terms($post->ID, $catgrp->taxonomy_name);
597
- if (! empty($terms)) {
598
  $selected_catgroups = unserialize($instance['post_group_category']);
599
  foreach ($terms as $key => $value) {
600
- if ($selected_catgroups === FALSE || array_key_exists($value->term_id, $selected_catgroups)) {
601
- if (! ($this->getWidgetDoneCatGroup($value->term_id))) {
602
- $row = $value;
603
- $group_found = TRUE;
604
  break;
605
  }
606
  }
607
  }
608
  } else {
609
- $options = $this->core->options;
610
  $no_cat_group = $options['cat_group']['no_group'];
611
- $row = get_term_by('id', $no_cat_group, $catgrp->taxonomy_name);
612
- $group_found = TRUE;
613
  }
614
  } else {
615
  if ('category_group' == $special_page) {
616
  $tax_meta = get_option($this->core->db_options_tax_meta);
617
- $term = $wp_query->get_queried_object();
618
- if (isset($tax_meta[$term->taxonomy][$term->term_id]['category_group_term_id'])) {
619
- $sp_category_group_id = $tax_meta[$term->taxonomy][$term->term_id]['category_group_term_id'];
620
  } else {
621
- $sp_category_group = $this->catgrp->getGroupByCategoryID($term->term_id);
622
  $sp_category_group_id = $sp_category_group->term_id;
623
  }
624
  } else {
625
- $sp_category_group_id = $options['sp_cat_group'][$special_page];
626
  }
627
- $row = get_term_by('id', $sp_category_group_id, $catgrp->taxonomy_name); // Returns FALSE when non-existance. (empty(FALSE)=TRUE)
628
- $group_found = TRUE;
 
 
629
  }
630
 
631
  if ($group_found) {
632
- $toDisplay = TRUE;
633
  $category_group_id_none = $this->catgrp->getTermIDBy('slug', 'none');
634
- $selected_catgroups = unserialize($instance['post_group_category']);
635
 
636
- if ($category_group_id_none == $row->term_id ) {
637
- $toDisplay = FALSE;
638
- } elseif (! (FALSE == $selected_catgroups || array_key_exists($row->term_id, $selected_catgroups))) {
639
- $toDisplay = FALSE;
640
  } elseif ($special_page != 'none' && $this->getWidgetDoneCatGroup($sp_category_group_id)) {
641
- $toDisplay = FALSE;
642
  }
643
  }
644
 
645
  if ($toDisplay) {
646
  extract($args);
647
 
648
- $c = $instance['count'] ? TRUE : FALSE;
649
- $e = $instance['hide_empty'] ? TRUE : FALSE;
650
- $h = $instance['hierarchical'] ? TRUE : FALSE;
651
- $use_desc_for_title = $instance['use_desc_for_title'] ? TRUE : FALSE;
652
- $s = $instance['sort_column'] ? $instance['sort_column'] : 'name';
653
- $o = $instance['sort_order'] ? $instance['sort_order'] : 'asc';
654
- $r = $instance['rssfeed'] ? 'RSS' : '';
655
- $i = $instance['rssimage'] ? $instance['rssimage'] : '';
656
 
657
  if (empty($r)) {
658
  $i = '';
659
  }
660
 
661
- $style = empty($instance['style']) ? 'list' : $instance['style'];
662
  $group_id = $row->term_id;
663
- $cats = $catgrp->getCategoriesFromGroup($group_id);
664
  if (empty($instance['title'])) {
665
  $title = $catgrp->getWidgetTitleForGroup($group_id);
666
- if (! $title) {
667
  $title = __('Categories', 'avh-ec');
668
  }
669
  } else {
@@ -678,65 +522,161 @@ class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget
678
  $show_option_none = $options['general']['alternative_name_select_category'];
679
  }
680
 
681
- $cat_args = array('include'=>$included_cats, 'orderby'=>$s, 'order'=>$o, 'show_count'=>$c, 'use_desc_for_title'=>$use_desc_for_title, 'hide_empty'=>$e, 'hierarchical'=>$h, 'title_li'=>'', 'show_option_none'=>$show_option_none, 'feed'=>$r, 'feed_image'=>$i, 'name'=>'extended-categories-select-group-' . $this->number);
 
 
 
 
 
 
 
 
 
 
 
 
 
682
  echo $before_widget;
683
  echo $this->core->comment;
684
  echo $before_title . $title . $after_title;
685
 
686
  if ($style == 'list') {
687
  echo '<ul>';
688
- $this->core->avh_wp_list_categories($cat_args, TRUE);
689
  echo '</ul>';
690
  } else {
691
- $this->core->avh_wp_dropdown_categories($cat_args, TRUE);
692
  echo '<script type=\'text/javascript\'>' . "\n";
693
  echo '/* <![CDATA[ */' . "\n";
694
- echo ' var ec_dropdown_' . $this->number . ' = document.getElementById("extended-categories-select-group-' . $this->number . '");' . "\n";
 
 
 
 
 
695
  echo ' function ec_onCatChange_' . $this->number . '() {' . "\n";
696
- echo ' if ( ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value > 0 ) {' . "\n";
697
- echo ' location.href = "' . get_option('home') . '/?cat="+ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value;' . "\n";
 
 
 
 
 
 
 
 
 
 
 
 
698
  echo ' }' . "\n";
699
  echo ' }' . "\n";
700
- echo ' ec_dropdown_' . $this->number . '.onchange = ec_onCatChange_' . $this->number . ';' . "\n";
 
 
 
 
 
701
  echo '/* ]]> */' . "\n";
702
  echo '</script>' . "\n";
703
  }
704
  echo $after_widget;
705
  }
706
  }
 
707
 
 
 
 
 
708
  /**
709
- * When Widget Control Form Is Posted
710
- *
711
- * @param unknown_type $new_instance
712
- * @param unknown_type $old_instance
713
- * @return unknown
714
  */
715
- function update ($new_instance, $old_instance)
716
- {
717
- // update the instance's settings
718
- if (! isset($new_instance['submit'])) {
719
- return FALSE;
 
 
 
 
 
 
 
 
720
  }
 
 
721
 
722
- $instance = $old_instance;
 
723
 
724
- $instance['title'] = strip_tags(stripslashes($new_instance['title']));
725
- $instance['count'] = $new_instance['count'] ? TRUE : FALSE;
726
- $instance['hierarchical'] = $new_instance['hierarchical'] ? TRUE : FALSE;
727
- $instance['hide_empty'] = $new_instance['hide_empty'] ? TRUE : FALSE;
728
- $instance['use_desc_for_title'] = $new_instance['use_desc_for_title'] ? TRUE : FALSE;
729
- $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column']));
730
- $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order']));
731
- $instance['style'] = strip_tags(stripslashes($new_instance['style']));
732
- $instance['rssfeed'] = $new_instance['rssfeed'] ? TRUE : FALSE;
733
- $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage']));
734
- if (array_key_exists('all', $new_instance['post_group_category'])) {
735
- $instance['post_group_category'] = FALSE;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
736
  } else {
737
- $instance['post_group_category'] = serialize($new_instance['post_group_category']);
738
  }
739
- return $instance;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
740
  }
741
 
742
  /**
@@ -744,258 +684,577 @@ class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget
744
  *
745
  * @param unknown_type $instance
746
  */
747
- function form ($instance)
748
- {
749
  // displays the widget admin form
750
- $instance = wp_parse_args((array) $instance, array('title'=>'', 'rssimage'=>''));
751
 
752
  // Prepare data for display
753
- $title = esc_attr($instance['title']);
754
- $count = (bool) $instance['count'];
755
- $hierarchical = (bool) $instance['hierarchical'];
756
- $hide_empty = (bool) $instance['hide_empty'];
757
- $use_desc_for_title = (bool) $instance['use_desc_for_title'];
758
- $sort_id = ($instance['sort_column'] == 'ID') ? ' SELECTED' : '';
759
- $sort_name = ($instance['sort_column'] == 'name') ? ' SELECTED' : '';
760
- $sort_count = ($instance['sort_column'] == 'count') ? ' SELECTED' : '';
761
- $sort_order_a = ($instance['sort_order'] == 'asc') ? ' SELECTED' : '';
762
- $sort_order_d = ($instance['sort_order'] == 'desc') ? ' SELECTED' : '';
763
- $style_list = ($instance['style'] == 'list') ? ' SELECTED' : '';
764
- $style_drop = ($instance['style'] == 'drop') ? ' SELECTED' : '';
765
- $rssfeed = (bool) $instance['rssfeed'];
766
- $rssimage = esc_attr($instance['rssimage']);
767
-
768
- $selected_cats = ($instance['post_group_category'] != '') ? unserialize($instance['post_group_category']) : FALSE;
769
- ob_start();
770
  echo '<p>';
771
- avh_doWidgetFormText($this->get_field_id('title'), $this->get_field_name('title'), __('Title', 'avh-ec'), $instance['title']);
 
 
 
772
  echo '</p>';
773
 
774
  echo '<p>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
775
 
776
- avh_doWidgetFormCheckbox($this->get_field_id('count'), $this->get_field_name('count'), __('Show post counts', 'avh-ec'), (bool) $instance['count']);
777
-
778
- avh_doWidgetFormCheckbox($this->get_field_id('hierarchical'), $this->get_field_name('hierarchical'), __('Show hierarchy', 'avh-ec'), (bool) $instance['hierarchical']);
779
-
780
- avh_doWidgetFormCheckbox($this->get_field_id('hide_empty'), $this->get_field_name('hide_empty'), __('Hide empty categories', 'avh-ec'), (bool) $instance['hide_empty']);
781
 
782
- avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'), $this->get_field_name('use_desc_for_title'), __('Use description for title', 'avh-ec'), (bool) $instance['use_desc_for_title']);
 
 
 
783
  echo '</p>';
784
 
785
  echo '<p>';
786
- $options['ID'] = __('ID', 'avh-ec');
787
- $options['name'] = __('Name', 'avh-ec');
788
  $options['count'] = __('Count', 'avh-ec');
789
- $options['slug'] = __('Slug', 'avh-ec');
790
- avh_doWidgetFormSelect($this->get_field_id('sort_column'), $this->get_field_name('sort_column'), __('Sort by', 'avh-ec'), $options, $instance['sort_column']);
 
 
 
 
 
 
 
 
791
  unset($options);
792
 
793
- $options['asc'] = __('Ascending', 'avh-ec');
794
  $options['desc'] = __('Descending', 'avh-ec');
795
- avh_doWidgetFormSelect($this->get_field_id('sort_order'), $this->get_field_name('sort_order'), __('Sort order', 'avh-ec'), $options, $instance['sort_order']);
 
 
 
 
796
  unset($options);
797
 
798
  $options['list'] = __('List', 'avh-ec');
799
  $options['drop'] = __('Drop down', 'avh-ec');
800
- avh_doWidgetFormSelect($this->get_field_id('style'), $this->get_field_name('style'), __('Display style', 'avh-ec'), $options, $instance['style']);
 
 
 
 
801
  unset($options);
802
  echo '</p>';
803
 
804
  echo '<p>';
805
 
806
- avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), $this->get_field_name('rssfeed'), __('Show RSS Feed', 'avh-ec'), (bool) $instance['rssfeed']);
 
 
 
 
 
 
 
 
807
 
808
- avh_doWidgetFormText($this->get_field_id('rssimage'), $this->get_field_name('rssimage'), __('Path (URI) to RSS image', 'avh-ec'), $instance['rssimage']);
809
  echo '</p>';
810
 
811
  echo '<p>';
812
- echo '<b>' . __('Select Groups', 'avh-ec') . '</b><hr />';
813
  echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear" style="list-style-type: none; margin-left: 5px; padding-left: 0px; margin-bottom: 20px;">';
814
- echo '<li id="' . $this->get_field_id('group_category--1') . '" class="popular-group_category">';
815
- echo '<label for="' . $this->get_field_id('group_post_category') . '" class="selectit">';
816
- echo '<input value="all" id="' . $this->get_field_id('group_post_category') . '" name="' . $this->get_field_name('post_group_category') . '[all]" type="checkbox" ' . (FALSE === $selected_cats ? ' CHECKED' : '') . '> ';
817
- _e('Any Group', 'avh-ec');
 
 
 
 
 
 
818
  echo '</label>';
819
  echo '</li>';
820
-
821
- $this->avh_wp_group_category_checklist($selected_cats, $this->number);
822
-
823
  echo '</ul>';
824
  echo '</p>';
825
 
826
- echo '<input type="hidden" id="' . $this->get_field_id('submit') . '" name="' . $this->get_field_name('submit') . '" value="1" />';
827
- ob_end_flush();
 
 
 
 
 
 
 
 
 
 
828
  }
829
 
830
- function avh_wp_group_category_checklist ($selected_cats, $number)
831
- {
 
 
 
 
 
 
 
 
 
 
 
832
 
833
- $walker = new AVH_Walker_Category_Checklist();
834
- $walker->number = $number;
835
- $walker->input_id = $this->get_field_id('post_group_category');
836
- $walker->input_name = $this->get_field_name('post_group_category');
837
- $walker->li_id = $this->get_field_id('group_category--1');
838
 
839
- $args = array('taxonomy'=>'avhec_catgroup', 'descendants_and_self'=>0, 'selected_cats'=>array(), 'popular_cats'=>array(), 'walker'=>$walker, 'checked_ontop'=>true);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
840
 
841
- if (is_array($selected_cats))
842
- $args['selected_cats'] = $selected_cats;
843
- else
844
- $args['selected_cats'] = array();
 
 
 
 
 
 
845
 
846
- $categories = (array) get_terms($args['taxonomy'], array('get'=>'all'));
847
 
848
- // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache)
849
- $checked_categories = array();
850
- $keys = array_keys($categories);
 
 
 
 
 
 
 
 
851
 
852
- foreach ($keys as $k) {
853
- if (in_array($categories[$k]->term_id, $args['selected_cats'])) {
854
- $checked_categories[] = $categories[$k];
855
- unset($categories[$k]);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
856
  }
 
857
  }
858
 
859
- // Put checked cats on top
860
- echo $walker->walk($checked_categories, 0, array ( $args ));
861
- // Then the rest of them
862
- echo $walker->walk($categories, 0, array ( $args ));
863
- }
864
 
865
- function getWidgetDoneCatGroup ($id)
866
- {
867
- $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
868
- if (is_array($catgrp->widget_done_catgroup) && array_key_exists($id, $catgrp->widget_done_catgroup)) {
869
- return TRUE;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
870
  }
871
- $catgrp->widget_done_catgroup[$id] = TRUE;
872
- return FALSE;
873
  }
874
  }
875
 
876
  /**
877
- * Class that will display the categories
878
- *
879
  */
880
- class AVH_Walker_Category_Checklist extends Walker
881
- {
882
- var $tree_type = 'category';
883
- var $db_fields = array('parent'=>'parent', 'id'=>'term_id'); //TODO: decouple this
884
- var $number;
885
- var $input_id;
886
- var $input_name;
887
- var $li_id;
888
 
889
  /**
890
- * Display array of elements hierarchically.
891
- *
892
- * It is a generic function which does not assume any existing order of
893
- * elements. max_depth = -1 means flatly display every element. max_depth =
894
- * 0 means display all levels. max_depth > 0 specifies the number of
895
- * display levels.
896
- *
897
- * @since 2.1.0
898
- *
899
- * @param array $elements
900
- * @param int $max_depth
901
- * @param array $args;
902
- * @return string
903
  */
904
- function walk( $elements, $max_depth, $args) {
 
905
 
906
- $output = '';
 
 
 
907
 
908
- if ($max_depth < -1) //invalid parameter
909
- return $output;
 
910
 
911
- if (empty($elements)) //nothing to walk
912
- return $output;
 
 
 
 
 
 
 
913
 
914
- $id_field = $this->db_fields['id'];
915
- $parent_field = $this->db_fields['parent'];
 
 
 
 
 
916
 
917
- // flat display
918
- if ( -1 == $max_depth ) {
919
- $empty_array = array();
920
- foreach ( $elements as $e )
921
- $this->display_element( $e, $empty_array, 1, 0, $args, $output );
922
- return $output;
923
  }
924
 
925
- /*
926
- * need to display in hierarchical order
927
- * separate elements into two buckets: top level and children elements
928
- * children_elements is two dimensional array, eg.
929
- * children_elements[10][] contains all sub-elements whose parent is 10.
930
- */
931
- $top_level_elements = array();
932
- $children_elements = array();
933
- foreach ( $elements as $e) {
934
- if ( 0 == $e->$parent_field )
935
- $top_level_elements[] = $e;
936
- else
937
- $children_elements[ $e->$parent_field ][] = $e;
938
  }
 
 
 
 
 
 
939
 
940
- /*
941
- * when none of the elements is top level
942
- * assume the first one must be root of the sub elements
943
- */
944
- if ( empty($top_level_elements) ) {
 
945
 
946
- $first = array_slice( $elements, 0, 1 );
947
- $root = $first[0];
 
 
 
 
948
 
949
- $top_level_elements = array();
950
- $children_elements = array();
951
- foreach ( $elements as $e) {
952
- if ( $root->$parent_field == $e->$parent_field )
953
- $top_level_elements[] = $e;
954
- else
955
- $children_elements[ $e->$parent_field ][] = $e;
956
- }
957
- }
958
 
959
- foreach ( $top_level_elements as $e )
960
- $this->display_element( $e, $children_elements, $max_depth, 0, $args, $output );
 
 
 
 
 
 
 
 
 
961
 
962
- /*
963
- * if we are displaying all levels, and remaining children_elements is not empty,
964
- * then we got orphans, which should be displayed regardless
965
- */
966
- if ( ( $max_depth == 0 ) && count( $children_elements ) > 0 ) {
967
- $empty_array = array();
968
- foreach ( $children_elements as $orphans )
969
- foreach( $orphans as $op )
970
- $this->display_element( $op, $empty_array, 1, 0, $args, $output );
971
- }
972
 
973
- return $output;
974
- }
975
- function start_lvl (&$output, $depth, $args)
976
- {
977
- $indent = str_repeat("\t", $depth);
978
- $output .= $indent . '<ul class="children">' . "\n";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
979
  }
980
 
981
- function end_lvl (&$output, $depth, $args)
982
- {
983
- $indent = str_repeat("\t", $depth);
984
- $output .= $indent . '</ul>' . "\n";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
985
  }
986
 
987
- function start_el (&$output, $category, $depth, $args)
988
- {
 
 
 
 
 
989
  extract($args);
990
- $input_id = $this->input_id . '-' . $category->term_id;
991
- $output .= "\n" . '<li id="' . $this->li_id . '">';
992
- $output .= '<label for="' . $input_id . '" class="selectit">';
993
- $output .= '<input value="' . $category->term_id . '" type="checkbox" name="' . $this->input_name . '[' . $category->term_id . ']" id="' . $input_id . '"' . (in_array($category->term_id, $selected_cats) ? ' checked="checked"' : "") . '/> ' . wp_specialchars(apply_filters('the_category', $category->name)) . '</label>';
994
- }
995
 
996
- function end_el (&$output, $category, $depth, $args)
997
- {
998
- $output .= "</li>\n";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
999
  }
1000
  }
 
1001
  ?>
1
  <?php
2
 
3
  /**
4
+ * Class that will display the categories
 
5
  */
6
+ class AVH_Walker_Category_Checklist extends Walker {
7
+ var $db_fields = array('parent' => 'parent', 'id' => 'term_id');
8
+ var $input_id; //TODO: decouple this
9
+ var $input_name;
10
+ var $li_id;
11
+ var $number;
12
+ var $tree_type = 'category';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
+ function end_el(&$output, $category, $depth, $args) {
15
+ $output .= "</li>\n";
16
  }
17
 
18
+ function end_lvl(&$output, $depth, $args) {
19
+ $indent = str_repeat("\t", $depth);
20
+ $output .= $indent . '</ul>' . "\n";
21
  }
22
 
23
+ function start_el(&$output, $category, $depth, $args) {
24
+ extract($args);
25
+ $input_id = $this->input_id . '-' . $category->term_id;
26
+ $output .= "\n" . '<li id="' . $this->li_id . '">';
27
+ $output .= '<label for="' . $input_id . '" class="selectit">';
28
+ $output .= '<input value="' .
29
+ $category->term_id .
30
+ '" type="checkbox" name="' .
31
+ $this->input_name .
32
+ '[' .
33
+ $category->term_id .
34
+ ']" id="' .
35
+ $input_id .
36
+ '"' .
37
+ (in_array($category->term_id, $selected_cats) ? ' checked="checked"' : "") .
38
+ '/> ' .
39
+ wp_specialchars(apply_filters('the_category', $category->name)) .
40
+ '</label>';
41
+ }
42
 
43
+ function start_lvl(&$output, $depth, $args) {
44
+ $indent = str_repeat("\t", $depth);
45
+ $output .= $indent . '<ul class="children">' . "\n";
 
46
  }
47
 
48
  /**
49
+ * Display array of elements hierarchically.
50
+ * It is a generic function which does not assume any existing order of
51
+ * elements. max_depth = -1 means flatly display every element. max_depth =
52
+ * 0 means display all levels. max_depth > 0 specifies the number of
53
+ * display levels.
54
  *
55
+ * @since 2.1.0
56
+ *
57
+ * @param array $elements
58
+ * @param int $max_depth
59
+ * @param array $args ;
60
+ *
61
+ * @return string
62
  */
63
+ function walk($elements, $max_depth, $args) {
 
 
 
64
 
65
+ $output = '';
 
 
 
 
 
 
 
 
 
 
66
 
67
+ if ($max_depth < - 1) //invalid parameter
68
+ {
69
+ return $output;
70
  }
71
 
72
+ if (empty($elements)) //nothing to walk
73
+ {
74
+ return $output;
75
  }
76
 
77
+ $id_field = $this->db_fields['id'];
78
+ $parent_field = $this->db_fields['parent'];
79
 
80
+ // flat display
81
+ if (- 1 == $max_depth) {
82
+ $empty_array = array();
83
+ foreach ($elements as $e) {
84
+ $this->display_element($e, $empty_array, 1, 0, $args, $output);
 
 
 
85
  }
86
+
87
+ return $output;
88
  }
89
 
90
+ /*
91
+ * need to display in hierarchical order
92
+ * separate elements into two buckets: top level and children elements
93
+ * children_elements is two dimensional array, eg.
94
+ * children_elements[10][] contains all sub-elements whose parent is 10.
95
+ */
96
+ $top_level_elements = array();
97
+ $children_elements = array();
98
+ foreach ($elements as $e) {
99
+ if (0 == $e->$parent_field) {
100
+ $top_level_elements[] = $e;
101
+ } else {
102
+ $children_elements[ $e->$parent_field ][] = $e;
103
+ }
104
  }
105
 
106
+ /*
107
+ * when none of the elements is top level
108
+ * assume the first one must be root of the sub elements
109
+ */
110
+ if (empty($top_level_elements)) {
111
+
112
+ $first = array_slice($elements, 0, 1);
113
+ $root = $first[0];
114
+
115
+ $top_level_elements = array();
116
+ $children_elements = array();
117
+ foreach ($elements as $e) {
118
+ if ($root->$parent_field == $e->$parent_field) {
119
+ $top_level_elements[] = $e;
120
+ } else {
121
+ $children_elements[ $e->$parent_field ][] = $e;
122
+ }
123
+ }
124
  }
125
 
126
+ foreach ($top_level_elements as $e) {
127
+ $this->display_element($e, $children_elements, $max_depth, 0, $args, $output);
128
+ }
 
129
 
130
+ /*
131
+ * if we are displaying all levels, and remaining children_elements is not empty,
132
+ * then we got orphans, which should be displayed regardless
133
+ */
134
+ if (($max_depth == 0) && count($children_elements) > 0) {
135
+ $empty_array = array();
136
+ foreach ($children_elements as $orphans) {
137
+ foreach ($orphans as $op) {
138
+ $this->display_element($op, $empty_array, 1, 0, $args, $output);
139
+ }
140
+ }
 
 
 
 
 
 
141
  }
142
+
143
+ return $output;
144
  }
145
+ }
146
 
147
+ /**
148
+ * Widget Class for displaying the grouped categories
149
+ */
150
+ class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget {
151
  /**
152
+ * @var AVH_EC_Category_Group
 
 
 
 
153
  */
154
+ var $catgrp;
155
+ /**
156
+ * @var AVH_EC_Core
157
+ */
158
+ var $core;
159
+
160
+ /**
161
+ * PHP 5 Constructor
162
+ */
163
+ function __construct() {
164
+ $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core');
165
+ $this->catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
166
+
167
+ $widget_ops = array('description' => __("Shows grouped categories.", 'avh-ec'));
168
+ WP_Widget::__construct(false, 'AVH Extended Categories: ' . __('Category Group'), $widget_ops);
169
+ add_action('wp_print_styles', array(&$this, 'actionWpPrintStyles'));
170
+ }
171
+
172
+ function WP_Widget_AVH_ExtendedCategories_Category_Group() {
173
+ $this->__construct();
174
+ }
175
+
176
+ function actionWpPrintStyles() {
177
+ if ( ! (false === is_active_widget(false, false, $this->id_base, true))) {
178
+ wp_register_style('avhec-widget',
179
+ AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css',
180
+ array(),
181
+ $this->core->version);
182
+ wp_enqueue_style('avhec-widget');
183
  }
184
+ }
185
 
186
+ function avh_wp_group_category_checklist($selected_cats, $number) {
187
 
188
+ $walker = new AVH_Walker_Category_Checklist();
189
+ $walker->number = $number;
190
+ $walker->input_id = $this->get_field_id('post_group_category');
191
+ $walker->input_name = $this->get_field_name('post_group_category');
192
+ $walker->li_id = $this->get_field_id('group_category--1');
193
+
194
+ $args = array(
195
+ 'taxonomy' => 'avhec_catgroup',
196
+ 'descendants_and_self' => 0,
197
+ 'selected_cats' => array(),
198
+ 'popular_cats' => array(),
199
+ 'walker' => $walker,
200
+ 'checked_ontop' => true
201
+ );
202
+
203
+ if (is_array($selected_cats)) {
204
+ $args['selected_cats'] = $selected_cats;
205
  } else {
206
+ $args['selected_cats'] = array();
207
  }
208
+
209
+ $categories = (array) get_terms($args['taxonomy'], array('get' => 'all'));
210
+
211
+ // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache)
212
+ $checked_categories = array();
213
+ $keys = array_keys($categories);
214
+
215
+ foreach ($keys as $k) {
216
+ if (in_array($categories[ $k ]->term_id, $args['selected_cats'])) {
217
+ $checked_categories[] = $categories[ $k ];
218
+ unset($categories[ $k ]);
219
+ }
220
  }
 
221
 
222
+ // Put checked cats on top
223
+ echo $walker->walk($checked_categories, 0, array($args));
224
+ // Then the rest of them
225
+ echo $walker->walk($categories, 0, array($args));
226
  }
227
 
228
  /**
230
  *
231
  * @param unknown_type $instance
232
  */
233
+ function form($instance) {
 
234
  // displays the widget admin form
235
+ $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => ''));
236
 
237
  // Prepare data for display
238
+ $title = esc_attr($instance['title']);
239
+ $count = (bool) $instance['count'];
240
+ $hierarchical = (bool) $instance['hierarchical'];
241
+ $hide_empty = (bool) $instance['hide_empty'];
242
+ $use_desc_for_title = (bool) $instance['use_desc_for_title'];
243
+ $sort_id = ($instance['sort_column'] == 'ID') ? ' SELECTED' : '';
244
+ $sort_name = ($instance['sort_column'] == 'name') ? ' SELECTED' : '';
245
+ $sort_count = ($instance['sort_column'] == 'count') ? ' SELECTED' : '';
246
+ $sort_order_a = ($instance['sort_order'] == 'asc') ? ' SELECTED' : '';
247
+ $sort_order_d = ($instance['sort_order'] == 'desc') ? ' SELECTED' : '';
248
+ $style_list = ($instance['style'] == 'list') ? ' SELECTED' : '';
249
+ $style_drop = ($instance['style'] == 'drop') ? ' SELECTED' : '';
250
+ $rssfeed = (bool) $instance['rssfeed'];
251
+ $rssimage = esc_attr($instance['rssimage']);
252
+
253
+ $selected_cats = ($instance['post_group_category'] !=
254
+ '') ? unserialize($instance['post_group_category']) : false;
255
+ ob_start();
256
  echo '<p>';
257
+ avh_doWidgetFormText($this->get_field_id('title'),
258
+ $this->get_field_name('title'),
259
+ __('Title', 'avh-ec'),
260
+ $instance['title']);
261
  echo '</p>';
262
 
263
  echo '<p>';
 
 
 
 
 
 
 
 
 
 
 
 
264
 
265
+ avh_doWidgetFormCheckbox($this->get_field_id('count'),
266
+ $this->get_field_name('count'),
267
+ __('Show post counts', 'avh-ec'),
268
+ (bool) $instance['count']);
269
+
270
+ avh_doWidgetFormCheckbox($this->get_field_id('hierarchical'),
271
+ $this->get_field_name('hierarchical'),
272
+ __('Show hierarchy', 'avh-ec'),
273
+ (bool) $instance['hierarchical']);
274
+
275
+ avh_doWidgetFormCheckbox($this->get_field_id('hide_empty'),
276
+ $this->get_field_name('hide_empty'),
277
+ __('Hide empty categories', 'avh-ec'),
278
+ (bool) $instance['hide_empty']);
279
+
280
+ avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'),
281
+ $this->get_field_name('use_desc_for_title'),
282
+ __('Use description for title', 'avh-ec'),
283
+ (bool) $instance['use_desc_for_title']);
284
  echo '</p>';
285
 
286
  echo '<p>';
287
+ $options['ID'] = __('ID', 'avh-ec');
288
+ $options['name'] = __('Name', 'avh-ec');
289
  $options['count'] = __('Count', 'avh-ec');
290
+ $options['slug'] = __('Slug', 'avh-ec');
291
+ avh_doWidgetFormSelect($this->get_field_id('sort_column'),
292
+ $this->get_field_name('sort_column'),
293
+ __('Sort by', 'avh-ec'),
294
+ $options,
295
+ $instance['sort_column']);
296
  unset($options);
297
 
298
+ $options['asc'] = __('Ascending', 'avh-ec');
299
  $options['desc'] = __('Descending', 'avh-ec');
300
+ avh_doWidgetFormSelect($this->get_field_id('sort_order'),
301
+ $this->get_field_name('sort_order'),
302
+ __('Sort order', 'avh-ec'),
303
+ $options,
304
+ $instance['sort_order']);
305
  unset($options);
306
 
307
  $options['list'] = __('List', 'avh-ec');
308
  $options['drop'] = __('Drop down', 'avh-ec');
309
+ avh_doWidgetFormSelect($this->get_field_id('style'),
310
+ $this->get_field_name('style'),
311
+ __('Display style', 'avh-ec'),
312
+ $options,
313
+ $instance['style']);
314
  unset($options);
315
  echo '</p>';
316
 
317
  echo '<p>';
318
 
319
+ avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'),
320
+ $this->get_field_name('rssfeed'),
321
+ __('Show RSS Feed', 'avh-ec'),
322
+ (bool) $instance['rssfeed']);
323
 
324
+ avh_doWidgetFormText($this->get_field_id('rssimage'),
325
+ $this->get_field_name('rssimage'),
326
+ __('Path (URI) to RSS image', 'avh-ec'),
327
+ $instance['rssimage']);
328
  echo '</p>';
329
 
330
  echo '<p>';
331
+ echo '<b>' . __('Select Groups', 'avh-ec') . '</b><hr />';
332
  echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear" style="list-style-type: none; margin-left: 5px; padding-left: 0px; margin-bottom: 20px;">';
333
+ echo '<li id="' . $this->get_field_id('group_category--1') . '" class="popular-group_category">';
334
+ echo '<label for="' . $this->get_field_id('group_post_category') . '" class="selectit">';
335
+ echo '<input value="all" id="' .
336
+ $this->get_field_id('group_post_category') .
337
+ '" name="' .
338
+ $this->get_field_name('post_group_category') .
339
+ '[all]" type="checkbox" ' .
340
+ (false === $selected_cats ? ' CHECKED' : '') .
341
+ '> ';
342
+ _e('Any Group', 'avh-ec');
343
  echo '</label>';
344
  echo '</li>';
345
+
346
+ $this->avh_wp_group_category_checklist($selected_cats, $this->number);
347
+
348
  echo '</ul>';
349
  echo '</p>';
350
 
351
+ echo '<input type="hidden" id="' .
352
+ $this->get_field_id('submit') .
353
+ '" name="' .
354
+ $this->get_field_name('submit') .
355
+ '" value="1" />';
356
+ ob_end_flush();
357
+ }
358
+
359
+ function getWidgetDoneCatGroup($id) {
360
+ $catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
361
+ if (is_array($catgrp->widget_done_catgroup) && array_key_exists($id, $catgrp->widget_done_catgroup)) {
362
+ return true;
363
+ }
364
+ $catgrp->widget_done_catgroup[ $id ] = true;
365
 
366
+ return false;
367
  }
368
 
369
  /**
370
+ * When Widget Control Form Is Posted
371
  *
372
+ * @param unknown_type $new_instance
373
+ * @param unknown_type $old_instance
374
+ *
375
+ * @return unknown
 
376
  */
377
+ function update($new_instance, $old_instance) {
378
+ // update the instance's settings
379
+ if ( ! isset($new_instance['submit'])) {
380
+ return false;
381
+ }
 
 
 
 
 
 
 
 
 
 
382
 
383
+ $instance = $old_instance;
 
384
 
385
+ $instance['title'] = strip_tags(stripslashes($new_instance['title']));
386
+ $instance['count'] = $new_instance['count'] ? true : false;
387
+ $instance['hierarchical'] = $new_instance['hierarchical'] ? true : false;
388
+ $instance['hide_empty'] = $new_instance['hide_empty'] ? true : false;
389
+ $instance['use_desc_for_title'] = $new_instance['use_desc_for_title'] ? true : false;
390
+ $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column']));
391
+ $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order']));
392
+ $instance['style'] = strip_tags(stripslashes($new_instance['style']));
393
+ $instance['rssfeed'] = $new_instance['rssfeed'] ? true : false;
394
+ $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage']));
395
+ if (array_key_exists('all', $new_instance['post_group_category'])) {
396
+ $instance['post_group_category'] = false;
397
+ } else {
398
+ $instance['post_group_category'] = serialize($new_instance['post_group_category']);
399
  }
400
 
401
+ return $instance;
 
 
 
402
  }
 
403
 
 
 
 
 
 
 
404
  /**
405
+ * Display the widget
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
406
  *
407
  * @param unknown_type $args
408
  * @param unknown_type $instance
409
  */
410
+ function widget($args, $instance) {
 
411
  global $post, $wp_query;
412
 
413
+ $catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
414
  $options = $this->core->getOptions();
415
 
416
  $row = array();
433
  $special_page = 'none';
434
  }
435
 
436
+ $toDisplay = false;
437
  if ('none' == $special_page) {
438
  $terms = wp_get_object_terms($post->ID, $catgrp->taxonomy_name);
439
+ if ( ! empty($terms)) {
440
  $selected_catgroups = unserialize($instance['post_group_category']);
441
  foreach ($terms as $key => $value) {
442
+ if ($selected_catgroups === false || array_key_exists($value->term_id, $selected_catgroups)) {
443
+ if ( ! ($this->getWidgetDoneCatGroup($value->term_id))) {
444
+ $row = $value;
445
+ $group_found = true;
446
  break;
447
  }
448
  }
449
  }
450
  } else {
451
+ $options = $this->core->options;
452
  $no_cat_group = $options['cat_group']['no_group'];
453
+ $row = get_term_by('id', $no_cat_group, $catgrp->taxonomy_name);
454
+ $group_found = true;
455
  }
456
  } else {
457
  if ('category_group' == $special_page) {
458
  $tax_meta = get_option($this->core->db_options_tax_meta);
459
+ $term = $wp_query->get_queried_object();
460
+ if (isset($tax_meta[ $term->taxonomy ][ $term->term_id ]['category_group_term_id'])) {
461
+ $sp_category_group_id = $tax_meta[ $term->taxonomy ][ $term->term_id ]['category_group_term_id'];
462
  } else {
463
+ $sp_category_group = $this->catgrp->getGroupByCategoryID($term->term_id);
464
  $sp_category_group_id = $sp_category_group->term_id;
465
  }
466
  } else {
467
+ $sp_category_group_id = $options['sp_cat_group'][ $special_page ];
468
  }
469
+ $row = get_term_by('id',
470
+ $sp_category_group_id,
471
+ $catgrp->taxonomy_name); // Returns FALSE when non-existance. (empty(FALSE)=TRUE)
472
+ $group_found = true;
473
  }
474
 
475
  if ($group_found) {
476
+ $toDisplay = true;
477
  $category_group_id_none = $this->catgrp->getTermIDBy('slug', 'none');
478
+ $selected_catgroups = unserialize($instance['post_group_category']);
479
 
480
+ if ($category_group_id_none == $row->term_id) {
481
+ $toDisplay = false;
482
+ } elseif ( ! (false == $selected_catgroups || array_key_exists($row->term_id, $selected_catgroups))) {
483
+ $toDisplay = false;
484
  } elseif ($special_page != 'none' && $this->getWidgetDoneCatGroup($sp_category_group_id)) {
485
+ $toDisplay = false;
486
  }
487
  }
488
 
489
  if ($toDisplay) {
490
  extract($args);
491
 
492
+ $c = $instance['count'] ? true : false;
493
+ $e = $instance['hide_empty'] ? true : false;
494
+ $h = $instance['hierarchical'] ? true : false;
495
+ $use_desc_for_title = $instance['use_desc_for_title'] ? true : false;
496
+ $s = $instance['sort_column'] ? $instance['sort_column'] : 'name';
497
+ $o = $instance['sort_order'] ? $instance['sort_order'] : 'asc';
498
+ $r = $instance['rssfeed'] ? 'RSS' : '';
499
+ $i = $instance['rssimage'] ? $instance['rssimage'] : '';
500
 
501
  if (empty($r)) {
502
  $i = '';
503
  }
504
 
505
+ $style = empty($instance['style']) ? 'list' : $instance['style'];
506
  $group_id = $row->term_id;
507
+ $cats = $catgrp->getCategoriesFromGroup($group_id);
508
  if (empty($instance['title'])) {
509
  $title = $catgrp->getWidgetTitleForGroup($group_id);
510
+ if ( ! $title) {
511
  $title = __('Categories', 'avh-ec');
512
  }
513
  } else {
522
  $show_option_none = $options['general']['alternative_name_select_category'];
523
  }
524
 
525
+ $cat_args = array(
526
+ 'include' => $included_cats,
527
+ 'orderby' => $s,
528
+ 'order' => $o,
529
+ 'show_count' => $c,
530
+ 'use_desc_for_title' => $use_desc_for_title,
531
+ 'hide_empty' => $e,
532
+ 'hierarchical' => $h,
533
+ 'title_li' => '',
534
+ 'show_option_none' => $show_option_none,
535
+ 'feed' => $r,
536
+ 'feed_image' => $i,
537
+ 'name' => 'extended-categories-select-group-' . $this->number
538
+ );
539
  echo $before_widget;
540
  echo $this->core->comment;
541
  echo $before_title . $title . $after_title;
542
 
543
  if ($style == 'list') {
544
  echo '<ul>';
545
+ $this->core->avh_wp_list_categories($cat_args, true);
546
  echo '</ul>';
547
  } else {
548
+ $this->core->avh_wp_dropdown_categories($cat_args, true);
549
  echo '<script type=\'text/javascript\'>' . "\n";
550
  echo '/* <![CDATA[ */' . "\n";
551
+ echo ' var ec_dropdown_' .
552
+ $this->number .
553
+ ' = document.getElementById("extended-categories-select-group-' .
554
+ $this->number .
555
+ '");' .
556
+ "\n";
557
  echo ' function ec_onCatChange_' . $this->number . '() {' . "\n";
558
+ echo ' if ( ec_dropdown_' .
559
+ $this->number .
560
+ '.options[ec_dropdown_' .
561
+ $this->number .
562
+ '.selectedIndex].value > 0 ) {' .
563
+ "\n";
564
+ echo ' location.href = "' .
565
+ get_option('home') .
566
+ '/?cat="+ec_dropdown_' .
567
+ $this->number .
568
+ '.options[ec_dropdown_' .
569
+ $this->number .
570
+ '.selectedIndex].value;' .
571
+ "\n";
572
  echo ' }' . "\n";
573
  echo ' }' . "\n";
574
+ echo ' ec_dropdown_' .
575
+ $this->number .
576
+ '.onchange = ec_onCatChange_' .
577
+ $this->number .
578
+ ';' .
579
+ "\n";
580
  echo '/* ]]> */' . "\n";
581
  echo '</script>' . "\n";
582
  }
583
  echo $after_widget;
584
  }
585
  }
586
+ }
587
 
588
+ /**
589
+ * Widget Class for displaying categories. Extended version of the dfeault categories.
590
+ */
591
+ class WP_Widget_AVH_ExtendedCategories_Normal extends WP_Widget {
592
  /**
593
+ * @var AVH_EC_Core
 
 
 
 
594
  */
595
+ var $core;
596
+
597
+ /**
598
+ * PHP 5 Constructor
599
+ */
600
+ function __construct() {
601
+ $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core');
602
+
603
+ //Convert the old option widget_extended_categories to widget_extended-categories
604
+ $old = get_option('widget_extended_categories');
605
+ if ( ! (false === $old)) {
606
+ update_option('widget_extended-categories', $old);
607
+ delete_option('widget_extended_categories');
608
  }
609
+ $widget_ops = array('description' => __("An extended version of the default Categories widget.", 'avh-ec'));
610
+ WP_Widget::__construct('extended-categories', 'AVH Extended Categories', $widget_ops);
611
 
612
+ add_action('wp_print_styles', array(&$this, 'actionWpPrintStyles'));
613
+ }
614
 
615
+ function WP_Widget_AVH_ExtendedCategories_Normal() {
616
+ $this->__construct();
617
+ }
618
+
619
+ function actionWpPrintStyles() {
620
+
621
+ if ( ! (false === is_active_widget(false, false, $this->id_base, true))) {
622
+ wp_register_style('avhec-widget',
623
+ AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css',
624
+ array(),
625
+ $this->core->version);
626
+ wp_enqueue_style('avhec-widget');
627
+ }
628
+ }
629
+
630
+ /**
631
+ * Creates the categories checklist
632
+ *
633
+ * @param int $post_id
634
+ * @param int $descendants_and_self
635
+ * @param array $selected_cats
636
+ * @param array $popular_cats
637
+ * @param int $number
638
+ */
639
+ function avh_wp_category_checklist($selected_cats, $number) {
640
+
641
+ $walker = new AVH_Walker_Category_Checklist();
642
+ $walker->number = $number;
643
+ $walker->input_id = $this->get_field_id('post_category');
644
+ $walker->input_name = $this->get_field_name('post_category');
645
+ $walker->li_id = $this->get_field_id('category--1');
646
+
647
+ $args = array(
648
+ 'taxonomy' => 'category',
649
+ 'descendants_and_self' => 0,
650
+ 'selected_cats' => $selected_cats,
651
+ 'popular_cats' => array(),
652
+ 'walker' => $walker,
653
+ 'checked_ontop' => true,
654
+ 'popular_cats' => array()
655
+ );
656
+
657
+ if (is_array($selected_cats)) {
658
+ $args['selected_cats'] = $selected_cats;
659
  } else {
660
+ $args['selected_cats'] = array();
661
  }
662
+
663
+ $categories = $this->core->getCategories();
664
+ $_categories_id = $this->core->getCategoriesId($categories);
665
+
666
+ // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache)
667
+ $checked_categories = array();
668
+ foreach ($args['selected_cats'] as $key => $value) {
669
+ if (isset($_categories_id[ $key ])) {
670
+ $category_key = $_categories_id[ $key ];
671
+ $checked_categories[] = $categories[ $category_key ];
672
+ unset($categories[ $category_key ]);
673
+ }
674
+ }
675
+
676
+ // Put checked cats on top
677
+ echo $walker->walk($checked_categories, 0, array($args));
678
+ // Then the rest of them
679
+ echo $walker->walk($categories, 0, array($args));
680
  }
681
 
682
  /**
684
  *
685
  * @param unknown_type $instance
686
  */
687
+ function form($instance) {
 
688
  // displays the widget admin form
689
+ $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => '', 'depth' => 0));
690
 
691
  // Prepare data for display
692
+ $depth = (int) $instance['depth'];
693
+ if ($depth < 0 || 11 < $depth) {
694
+ $depth = 0;
695
+ }
696
+ $selected_cats = ($instance['post_category'] != '') ? unserialize($instance['post_category']) : false;
697
+
 
 
 
 
 
 
 
 
 
 
 
698
  echo '<p>';
699
+ avh_doWidgetFormText($this->get_field_id('title'),
700
+ $this->get_field_name('title'),
701
+ __('Title', 'avh-ec'),
702
+ $instance['title']);
703
  echo '</p>';
704
 
705
  echo '<p>';
706
+ avh_doWidgetFormCheckbox($this->get_field_id('selectedonly'),
707
+ $this->get_field_name('selectedonly'),
708
+ __('Show selected categories only', 'avh-ec'),
709
+ (bool) $instance['selectedonly']);
710
+
711
+ avh_doWidgetFormCheckbox($this->get_field_id('count'),
712
+ $this->get_field_name('count'),
713
+ __('Show post counts', 'avh-ec'),
714
+ (bool) $instance['count']);
715
+
716
+ avh_doWidgetFormCheckbox($this->get_field_id('hierarchical'),
717
+ $this->get_field_name('hierarchical'),
718
+ __('Show hierarchy', 'avh-ec'),
719
+ (bool) $instance['hierarchical']);
720
+
721
+ $options = array(0 => __('All Levels', 'avh-ec'), 1 => __('Toplevel only', 'avh-ec'));
722
+ for ($i = 2; $i <= 11; $i ++) {
723
+ $options[ $i ] = __('Child ', 'avh-ec') . ($i - 1);
724
+ }
725
+ avh_doWidgetFormSelect($this->get_field_id('depth'),
726
+ $this->get_field_name('depth'),
727
+ __('How many levels to show', 'avh-ec'),
728
+ $options,
729
+ $depth);
730
+ unset($options);
731
 
732
+ avh_doWidgetFormCheckbox($this->get_field_id('hide_empty'),
733
+ $this->get_field_name('hide_empty'),
734
+ __('Hide empty categories', 'avh-ec'),
735
+ (bool) $instance['hide_empty']);
 
736
 
737
+ avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'),
738
+ $this->get_field_name('use_desc_for_title'),
739
+ __('Use description for title', 'avh-ec'),
740
+ (bool) $instance['use_desc_for_title']);
741
  echo '</p>';
742
 
743
  echo '<p>';
744
+ $options['ID'] = __('ID', 'avh-ec');
745
+ $options['name'] = __('Name', 'avh-ec');
746
  $options['count'] = __('Count', 'avh-ec');
747
+ $options['slug'] = __('Slug', 'avh-ec');
748
+ if (is_plugin_active('my-category-order/mycategoryorder.php')) {
749
+ $options['avhec_3rdparty_mycategoryorder'] = 'My Category Order';
750
+ }
751
+
752
+ avh_doWidgetFormSelect($this->get_field_id('sort_column'),
753
+ $this->get_field_name('sort_column'),
754
+ __('Sort by', 'avh-ec'),
755
+ $options,
756
+ $instance['sort_column']);
757
  unset($options);
758
 
759
+ $options['asc'] = __('Ascending', 'avh-ec');
760
  $options['desc'] = __('Descending', 'avh-ec');
761
+ avh_doWidgetFormSelect($this->get_field_id('sort_order'),
762
+ $this->get_field_name('sort_order'),
763
+ __('Sort order', 'avh-ec'),
764
+ $options,
765
+ $instance['sort_order']);
766
  unset($options);
767
 
768
  $options['list'] = __('List', 'avh-ec');
769
  $options['drop'] = __('Drop down', 'avh-ec');
770
+ avh_doWidgetFormSelect($this->get_field_id('style'),
771
+ $this->get_field_name('style'),
772
+ __('Display style', 'avh-ec'),
773
+ $options,
774
+ $instance['style']);
775
  unset($options);
776
  echo '</p>';
777
 
778
  echo '<p>';
779
 
780
+ avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'),
781
+ $this->get_field_name('rssfeed'),
782
+ __('Show RSS Feed', 'avh-ec'),
783
+ (bool) $instance['rssfeed']);
784
+
785
+ avh_doWidgetFormText($this->get_field_id('rssimage'),
786
+ $this->get_field_name('rssimage'),
787
+ __('Path (URI) to RSS image', 'avh-ec'),
788
+ $instance['rssimage']);
789
 
 
790
  echo '</p>';
791
 
792
  echo '<p>';
793
+ echo '<b>' . __('Select categories', 'avh-ec') . '</b><hr />';
794
  echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear" style="list-style-type: none; margin-left: 5px; padding-left: 0px; margin-bottom: 20px;">';
795
+ echo '<li id="' . $this->get_field_id('category--1') . '" class="popular-category">';
796
+ echo '<label for="' . $this->get_field_id('post_category') . '" class="selectit">';
797
+ echo '<input value="all" id="' .
798
+ $this->get_field_id('post_category') .
799
+ '" name="' .
800
+ $this->get_field_name('post_category') .
801
+ '[all]" type="checkbox" ' .
802
+ (false === $selected_cats ? ' CHECKED' : '') .
803
+ '> ';
804
+ _e('All Categories', 'avh-ec');
805
  echo '</label>';
806
  echo '</li>';
807
+ ob_start();
808
+ $this->avh_wp_category_checklist($selected_cats, $this->number);
809
+ ob_end_flush();
810
  echo '</ul>';
811
  echo '</p>';
812
 
813
+ echo '<p>';
814
+ avh_doWidgetFormCheckbox($this->get_field_id('invert_included'),
815
+ $this->get_field_name('invert_included'),
816
+ __('Exclude the selected categories', 'avh-ec'),
817
+ (bool) $instance['invert_included']);
818
+ echo '</p>';
819
+
820
+ echo '<input type="hidden" id="' .
821
+ $this->get_field_id('submit') .
822
+ '" name="' .
823
+ $this->get_field_name('submit') .
824
+ '" value="1" />';
825
  }
826
 
827
+ /**
828
+ * When Widget Control Form Is Posted
829
+ *
830
+ * @param unknown_type $new_instance
831
+ * @param unknown_type $old_instance
832
+ *
833
+ * @return unknown
834
+ */
835
+ function update($new_instance, $old_instance) {
836
+ // update the instance's settings
837
+ if ( ! isset($new_instance['submit'])) {
838
+ return false;
839
+ }
840
 
841
+ $instance = $old_instance;
 
 
 
 
842
 
843
+ $instance['title'] = strip_tags(stripslashes($new_instance['title']));
844
+ $instance['selectedonly'] = $new_instance['selectedonly'] ? true : false;
845
+ $instance['count'] = $new_instance['count'] ? true : false;
846
+ $instance['hierarchical'] = $new_instance['hierarchical'] ? true : false;
847
+ $instance['hide_empty'] = $new_instance['hide_empty'] ? true : false;
848
+ $instance['use_desc_for_title'] = $new_instance['use_desc_for_title'] ? true : false;
849
+ $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column']));
850
+ $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order']));
851
+ $instance['style'] = strip_tags(stripslashes($new_instance['style']));
852
+ $instance['rssfeed'] = $new_instance['rssfeed'] ? true : false;
853
+ $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage']));
854
+ if (array_key_exists('all', $new_instance['post_category'])) {
855
+ $instance['post_category'] = false;
856
+ } else {
857
+ $instance['post_category'] = serialize($new_instance['post_category']);
858
+ }
859
+ $instance['depth'] = (int) $new_instance['depth'];
860
+ if ($instance['depth'] < 0 || 11 < $instance['depth']) {
861
+ $instance['depth'] = 0;
862
+ }
863
+ $instance['invert_included'] = $new_instance['invert_included'] ? true : false;
864
 
865
+ return $instance;
866
+ }
867
+
868
+ /**
869
+ * Display the widget
870
+ *
871
+ * @param unknown_type $args
872
+ * @param unknown_type $instance
873
+ */
874
+ function widget($args, $instance) {
875
 
876
+ extract($args);
877
 
878
+ $selectedonly = $instance['selectedonly'] ? true : false;
879
+ $c = $instance['count'] ? true : false;
880
+ $h = $instance['hierarchical'] ? true : false;
881
+ $d = $instance['depth'] ? $instance['depth'] : 0;
882
+ $e = $instance['hide_empty'] ? true : false;
883
+ $use_desc_for_title = $instance['use_desc_for_title'] ? true : false;
884
+ $s = $instance['sort_column'] ? $instance['sort_column'] : 'name';
885
+ $o = $instance['sort_order'] ? $instance['sort_order'] : 'asc';
886
+ $r = $instance['rssfeed'] ? 'RSS' : '';
887
+ $i = $instance['rssimage'] ? $instance['rssimage'] : '';
888
+ $invert = $instance['invert_included'] ? true : false;
889
 
890
+ if (empty($r)) {
891
+ $i = '';
892
+ }
893
+
894
+ if (empty($d)) {
895
+ $d = 0;
896
+ }
897
+
898
+ $title = apply_filters('widget_title',
899
+ empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']);
900
+ $style = empty($instance['style']) ? 'list' : $instance['style'];
901
+
902
+ $included_cats = '';
903
+ if ($instance['post_category']) {
904
+ $post_category = unserialize($instance['post_category']);
905
+ $children = array();
906
+ if ( ! $instance['selectedonly']) {
907
+ foreach ($post_category as $cat_id) {
908
+ $children = array_merge($children, get_term_children($cat_id, 'category'));
909
+ }
910
  }
911
+ $included_cats = implode(",", array_merge($post_category, $children));
912
  }
913
 
914
+ if ($invert) {
915
+ $inc_exc = 'exclude';
916
+ } else {
917
+ $inc_exc = 'include';
918
+ }
919
 
920
+ $options = $this->core->getOptions();
921
+ $show_option_none = __('Select Category', 'avh-ec');
922
+ if ($options['general']['alternative_name_select_category']) {
923
+ $show_option_none = $options['general']['alternative_name_select_category'];
924
+ }
925
+
926
+ $cat_args = array(
927
+ $inc_exc => $included_cats,
928
+ 'orderby' => $s,
929
+ 'order' => $o,
930
+ 'show_count' => $c,
931
+ 'use_desc_for_title' => $use_desc_for_title,
932
+ 'hide_empty' => $e,
933
+ 'hierarchical' => $h,
934
+ 'depth' => $d,
935
+ 'title_li' => '',
936
+ 'show_option_none' => $show_option_none,
937
+ 'feed' => $r,
938
+ 'feed_image' => $i,
939
+ 'name' => 'extended-categories-select-' . $this->number
940
+ );
941
+ echo $before_widget;
942
+ echo $this->core->comment;
943
+ echo $before_title . $title . $after_title;
944
+
945
+ if ($style == 'list') {
946
+ echo '<ul>';
947
+ $this->core->avh_wp_list_categories($cat_args, $selectedonly);
948
+ echo '</ul>';
949
+ } else {
950
+ $this->core->avh_wp_dropdown_categories($cat_args, $selectedonly);
951
+ echo '<script type=\'text/javascript\'>' . "\n";
952
+ echo '/* <![CDATA[ */' . "\n";
953
+ echo ' var ec_dropdown_' .
954
+ $this->number .
955
+ ' = document.getElementById("extended-categories-select-' .
956
+ $this->number .
957
+ '");' .
958
+ "\n";
959
+ echo ' function ec_onCatChange_' . $this->number . '() {' . "\n";
960
+ echo ' if ( ec_dropdown_' .
961
+ $this->number .
962
+ '.options[ec_dropdown_' .
963
+ $this->number .
964
+ '.selectedIndex].value > 0 ) {' .
965
+ "\n";
966
+ echo ' location.href = "' .
967
+ get_option('home') .
968
+ '/?cat="+ec_dropdown_' .
969
+ $this->number .
970
+ '.options[ec_dropdown_' .
971
+ $this->number .
972
+ '.selectedIndex].value;' .
973
+ "\n";
974
+ echo ' }' . "\n";
975
+ echo ' }' . "\n";
976
+ echo ' ec_dropdown_' .
977
+ $this->number .
978
+ '.onchange = ec_onCatChange_' .
979
+ $this->number .
980
+ ';' .
981
+ "\n";
982
+ echo '/* ]]> */' . "\n";
983
+ echo '</script>' . "\n";
984
  }
985
+ echo $after_widget;
 
986
  }
987
  }
988
 
989
  /**
990
+ * Widget Class for displaying the top categories
 
991
  */
992
+ class WP_Widget_AVH_ExtendedCategories_Top extends WP_Widget {
993
+ /**
994
+ * @var AVH_EC_Core
995
+ */
996
+ var $core;
 
 
 
997
 
998
  /**
999
+ * PHP 5 Constructor
 
 
 
 
 
 
 
 
 
 
 
 
1000
  */
1001
+ function __construct() {
1002
+ $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core');
1003
 
1004
+ $widget_ops = array('description' => __("Shows the top categories.", 'avh-ec'));
1005
+ WP_Widget::__construct(false, 'AVH Extended Categories: ' . __('Top Categories'), $widget_ops);
1006
+ add_action('wp_print_styles', array(&$this, 'actionWpPrintStyles'));
1007
+ }
1008
 
1009
+ function WP_Widget_AVH_ExtendedCategories_Top() {
1010
+ $this->__construct();
1011
+ }
1012
 
1013
+ function actionWpPrintStyles() {
1014
+ if ( ! (false === is_active_widget(false, false, $this->id_base, true))) {
1015
+ wp_register_style('avhec-widget',
1016
+ AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css',
1017
+ array(),
1018
+ $this->core->version);
1019
+ wp_enqueue_style('avhec-widget');
1020
+ }
1021
+ }
1022
 
1023
+ /** Echo the settings update form
1024
+ *
1025
+ * @param array $instance Current settings
1026
+ */
1027
+ function form($instance) {
1028
+ // displays the widget admin form
1029
+ $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => ''));
1030
 
1031
+ // Prepare data for display
1032
+ if ( ! $amount = (int) $instance['amount']) {
1033
+ $amount = 5;
 
 
 
1034
  }
1035
 
1036
+ if ($amount < 1) {
1037
+ $amount = 1;
 
 
 
 
 
 
 
 
 
 
 
1038
  }
1039
+ echo '<p>';
1040
+ avh_doWidgetFormText($this->get_field_id('title'),
1041
+ $this->get_field_name('title'),
1042
+ __('Title', 'avh-ec'),
1043
+ $instance['title']);
1044
+ echo '</p>';
1045
 
1046
+ echo '<p>';
1047
+ avh_doWidgetFormText($this->get_field_id('amount'),
1048
+ $this->get_field_name('amount'),
1049
+ __('How many categories to show', 'avh-ec'),
1050
+ $amount);
1051
+ echo '</p>';
1052
 
1053
+ echo '<p>';
1054
+ avh_doWidgetFormCheckbox($this->get_field_id('count'),
1055
+ $this->get_field_name('count'),
1056
+ __('Show post counts', 'avh-ec'),
1057
+ (bool) $instance['count']);
1058
+ echo '<br />';
1059
 
1060
+ avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'),
1061
+ $this->get_field_name('use_desc_for_title'),
1062
+ __('Use description for title', 'avh-ec'),
1063
+ (bool) $instance['use_desc_for_title']);
1064
+ echo '</p>';
 
 
 
 
1065
 
1066
+ echo '<p>';
1067
+ $options['ID'] = __('ID', 'avh-ec');
1068
+ $options['name'] = __('Name', 'avh-ec');
1069
+ $options['count'] = __('Count', 'avh-ec');
1070
+ $options['slug'] = __('Slug', 'avh-ec');
1071
+ avh_doWidgetFormSelect($this->get_field_id('sort_column'),
1072
+ $this->get_field_name('sort_column'),
1073
+ __('Sort by', 'avh-ec'),
1074
+ $options,
1075
+ $instance['sort_column']);
1076
+ unset($options);
1077
 
1078
+ $options['asc'] = __('Ascending', 'avh-ec');
1079
+ $options['desc'] = __('Descending', 'avh-ec');
1080
+ avh_doWidgetFormSelect($this->get_field_id('sort_order'),
1081
+ $this->get_field_name('sort_order'),
1082
+ __('Sort order', 'avh-ec'),
1083
+ $options,
1084
+ $instance['sort_order']);
1085
+ unset($options);
 
 
1086
 
1087
+ $options['list'] = __('List', 'avh-ec');
1088
+ $options['drop'] = __('Drop down', 'avh-ec');
1089
+ avh_doWidgetFormSelect($this->get_field_id('style'),
1090
+ $this->get_field_name('style'),
1091
+ __('Display style', 'avh-ec'),
1092
+ $options,
1093
+ $instance['style']);
1094
+ unset($options);
1095
+ echo '</p>';
1096
+
1097
+ echo '<p>';
1098
+
1099
+ avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'),
1100
+ $this->get_field_name('rssfeed'),
1101
+ __('Show RSS Feed', 'avh-ec'),
1102
+ (bool) $instance['rssfeed']);
1103
+
1104
+ avh_doWidgetFormText($this->get_field_id('rssimage'),
1105
+ $this->get_field_name('rssimage'),
1106
+ __('Path (URI) to RSS image', 'avh-ec'),
1107
+ $instance['rssimage']);
1108
+
1109
+ echo '</p>';
1110
+
1111
+ echo '<input type="hidden" id="' .
1112
+ $this->get_field_id('submit') .
1113
+ '" name="' .
1114
+ $this->get_field_name('submit') .
1115
+ '" value="1" />';
1116
  }
1117
 
1118
+ /** Update a particular instance.
1119
+ * This function should check that $new_instance is set correctly.
1120
+ * The newly calculated value of $instance should be returned.
1121
+ * If "FALSE" is returned, the instance won't be saved/updated.
1122
+ *
1123
+ * @param array $new_instance New settings for this instance as input by the user via form()
1124
+ * @param array $old_instance Old settings for this instance
1125
+ *
1126
+ * @return array Settings to save or bool FALSE to cancel saving
1127
+ */
1128
+ function update($new_instance, $old_instance) {
1129
+ // update the instance's settings
1130
+ if ( ! isset($new_instance['submit'])) {
1131
+ return false;
1132
+ }
1133
+
1134
+ $instance = $old_instance;
1135
+
1136
+ $instance['title'] = strip_tags(stripslashes($new_instance['title']));
1137
+ $instance['amount'] = (int) $new_instance['amount'];
1138
+ $instance['count'] = $new_instance['count'] ? true : false;
1139
+ $instance['use_desc_for_title'] = $new_instance['use_desc_for_title'] ? true : false;
1140
+ $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column']));
1141
+ $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order']));
1142
+ $instance['style'] = strip_tags(stripslashes($new_instance['style']));
1143
+ $instance['rssfeed'] = $new_instance['rssfeed'] ? true : false;
1144
+ $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage']));
1145
+
1146
+ return $instance;
1147
  }
1148
 
1149
+ /** Echo the widget content.
1150
+ * Subclasses should over-ride this function to generate their widget code.
1151
+ *
1152
+ * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
1153
+ * @param array $instance The settings for the particular instance of the widget
1154
+ */
1155
+ function widget($args, $instance) {
1156
  extract($args);
 
 
 
 
 
1157
 
1158
+ $title = apply_filters('widget_title',
1159
+ empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']);
1160
+ $style = empty($instance['style']) ? 'list' : $instance['style'];
1161
+ if ( ! $a = (int) $instance['amount']) {
1162
+ $a = 5;
1163
+ } elseif ($a < 1) {
1164
+ $a = 1;
1165
+ }
1166
+ $c = $instance['count'] ? true : false;
1167
+ $use_desc_for_title = $instance['use_desc_for_title'] ? true : false;
1168
+ $s = $instance['sort_column'] ? $instance['sort_column'] : 'name';
1169
+ $o = $instance['sort_order'] ? $instance['sort_order'] : 'asc';
1170
+ $r = $instance['rssfeed'] ? 'RSS' : '';
1171
+ $i = $instance['rssimage'] ? $instance['rssimage'] : '';
1172
+ if (empty($r)) {
1173
+ $i = '';
1174
+ }
1175
+ if ( ! empty($i)) {
1176
+ if ( ! file_exists(ABSPATH . '/' . $i)) {
1177
+ $i = '';
1178
+ }
1179
+ }
1180
+
1181
+ $options = $this->core->getOptions();
1182
+ $show_option_none = __('Select Category', 'avh-ec');
1183
+ if ($options['general']['alternative_name_select_category']) {
1184
+ $show_option_none = $options['general']['alternative_name_select_category'];
1185
+ }
1186
+
1187
+ $top_cats = get_terms('category',
1188
+ array(
1189
+ 'fields' => 'ids',
1190
+ 'orderby' => 'count',
1191
+ 'order' => 'DESC',
1192
+ 'number' => $a,
1193
+ 'hierarchical' => false
1194
+ ));
1195
+ $included_cats = implode(",", $top_cats);
1196
+
1197
+ $cat_args = array(
1198
+ 'include' => $included_cats,
1199
+ 'orderby' => $s,
1200
+ 'order' => $o,
1201
+ 'show_count' => $c,
1202
+ 'use_desc_for_title' => $use_desc_for_title,
1203
+ 'hide_empty' => false,
1204
+ 'hierarchical' => false,
1205
+ 'depth' => - 1,
1206
+ 'title_li' => '',
1207
+ 'show_option_none' => $show_option_none,
1208
+ 'feed' => $r,
1209
+ 'feed_image' => $i,
1210
+ 'name' => 'extended-categories-top-select-' . $this->number
1211
+ );
1212
+ echo $before_widget;
1213
+ echo $this->core->comment;
1214
+ echo $before_title . $title . $after_title;
1215
+ echo '<ul>';
1216
+
1217
+ if ($style == 'list') {
1218
+ wp_list_categories($cat_args);
1219
+ } else {
1220
+ wp_dropdown_categories($cat_args);
1221
+ echo '<script type=\'text/javascript\'>' . "\n";
1222
+ echo '/* <![CDATA[ */' . "\n";
1223
+ echo ' var ec_dropdown_top_' .
1224
+ $this->number .
1225
+ ' = document.getElementById("extended-categories-top-select-' .
1226
+ $this->number .
1227
+ '");' .
1228
+ "\n";
1229
+ echo ' function ec_top_onCatChange_' . $this->number . '() {' . "\n";
1230
+ echo ' if ( ec_dropdown_top_' .
1231
+ $this->number .
1232
+ '.options[ec_dropdown_top_' .
1233
+ $this->number .
1234
+ '.selectedIndex].value > 0 ) {' .
1235
+ "\n";
1236
+ echo ' location.href = "' .
1237
+ get_option('home') .
1238
+ '/?cat="+ec_dropdown_top_' .
1239
+ $this->number .
1240
+ '.options[ec_dropdown_top_' .
1241
+ $this->number .
1242
+ '.selectedIndex].value;' .
1243
+ "\n";
1244
+ echo ' }' . "\n";
1245
+ echo ' }' . "\n";
1246
+ echo ' ec_dropdown_top_' .
1247
+ $this->number .
1248
+ '.onchange = ec_top_onCatChange_' .
1249
+ $this->number .
1250
+ ';' .
1251
+ "\n";
1252
+ echo '/* ]]> */' . "\n";
1253
+ echo '</script>' . "\n";
1254
+ }
1255
+ echo '</ul>';
1256
+ echo $after_widget;
1257
  }
1258
  }
1259
+
1260
  ?>
2.8/css/avh-ec.admin.css CHANGED
@@ -1,13 +1,13 @@
1
  .footer_avhec {
2
- font-size: 0.8em;
3
- text-align: center;
4
  }
5
 
6
  div.clearer {
7
- clear: both;
8
- line-height: 1px;
9
- font-size: 1px;
10
- height: 1px;
11
  }
12
 
13
  /* Metabox in General */
@@ -21,12 +21,12 @@ table.avhec-options {
21
 
22
  .avhec-metabox-wrap .p {
23
 
24
- line-height: 140%;
25
- margin: 1em 0;
26
  }
27
 
28
  #avhecBoxOptions option {
29
- padding: .5em;
30
  }
31
 
32
  .avhec-metabox-wrap span.description {
@@ -34,17 +34,17 @@ table.avhec-options {
34
  }
35
 
36
  .avhec-metabox-wrap .b {
37
- font-weight: bold;
38
  }
39
 
40
  .avhec-metabox-wrap ul {
41
- margin-bottom: 1em;
42
  }
43
 
44
  .avhec-metabox-wrap ul li {
45
- line-height: 120%;
46
- list-style: disc inside none;
47
- margin-bottom: 0;
48
  }
49
 
50
  #avhec-options input {
@@ -58,12 +58,13 @@ table.avhec-options {
58
  /* Metabox FAQ */
59
  #avhecBoxFAQ .inside ul {
60
 
61
- margin-bottom: 6px;
62
  }
63
- #avhecBoxFAQ .inside ul li{
64
- line-height: 120%;
65
- list-style: disc inside none;
66
- margin-bottom: 0;
 
67
  }
68
 
69
  /* Metabox Donations*/
@@ -72,7 +73,7 @@ table.avhec-options {
72
  }
73
 
74
  #avhecBoxDonations .versions {
75
- padding: 6px 10px 12px;
76
  }
77
 
78
  /* Metabox Donations*/
@@ -82,69 +83,69 @@ table.avhec-options {
82
 
83
  /* Metabox in post and page */
84
  #post_avhec_category_group {
85
- width: 100%;
86
  }
87
 
88
  #avhec-catlist {
89
- -moz-border-radius: 4px 4px 4px 4px;
90
- background-color: #FFFFFF;
91
- border: 1px solid #DFDFDF;
92
- height: 20em;
93
- margin-bottom: -1.8em;
94
- overflow: auto;
95
- width: 95%;
96
  }
97
 
98
  #avhec-catlist ul {
99
- padding: 3px;
100
  }
101
 
102
  #avhec-catlist li ul {
103
- padding: 0px;
104
  }
105
 
106
  #avhec-catlist li {
107
- margin-bottom: 0px;
108
  }
109
 
110
  #avhecManualOrder {
111
- width: 25%;
112
- /* border: 1px solid #B2B2B2;*/
113
- /* margin: 10px 10px 10px 0px;*/
114
- /* padding: 5px 10px 5px 10px;*/
115
- /* list-style: none;*/
116
- /* background-color: #fff;*/
117
- /* border-radius: 3px;*/
118
- /* -webkit-border-radius: 3px;*/
119
  }
120
 
121
  #avhecManualOrder li.lineitem {
122
- border: 1px solid #DFDFDF;
123
- background-image: none;
124
- border-radius: 3px;
125
- -webkit-border-radius: 3px;
126
- background-color: #FFFFFF;
127
- color: #555555;
128
- cursor: move;
129
- margin-top: 5px;
130
- margin-bottom: 5px;
131
- padding: 2px 5px 2px 5px;
132
- list-style: none outside none;
133
  }
134
 
135
  #avhecManualOrder .sortable-placeholder {
136
- border: 1px dashed #B2B2B2;
137
- margin-top: 5px;
138
- margin-bottom: 5px;
139
- padding: 2px 5px 2px 5px;
140
- height: 1.5em;
141
- line-height: 1.5em;
142
- list-style: none outside none;
143
- background-color: transparent;
144
- background-image: -ms-linear-gradient(top, #f9f9f9, #f5f5f5); /* IE10 */
145
- background-image: -moz-linear-gradient(top, #f9f9f9, #f5f5f5); /* Firefox */
146
- background-image: -o-linear-gradient(top, #f9f9f9, #f5f5f5); /* Opera */
147
- background-image: -webkit-gradient(linear, left top, left bottom, from(#f9f9f9), to(#f5f5f5)); /* old Webkit */
148
- background-image: -webkit-linear-gradient(top, #f9f9f9, #f5f5f5); /* new Webkit */
149
- background-image: linear-gradient(top, #f9f9f9, #f5f5f5); /* proposed W3C Markup */
150
  }
1
  .footer_avhec {
2
+ font-size : 0.8em;
3
+ text-align : center;
4
  }
5
 
6
  div.clearer {
7
+ clear : both;
8
+ line-height : 1px;
9
+ font-size : 1px;
10
+ height : 1px;
11
  }
12
 
13
  /* Metabox in General */
21
 
22
  .avhec-metabox-wrap .p {
23
 
24
+ line-height : 140%;
25
+ margin : 1em 0;
26
  }
27
 
28
  #avhecBoxOptions option {
29
+ padding : .5em;
30
  }
31
 
32
  .avhec-metabox-wrap span.description {
34
  }
35
 
36
  .avhec-metabox-wrap .b {
37
+ font-weight : bold;
38
  }
39
 
40
  .avhec-metabox-wrap ul {
41
+ margin-bottom : 1em;
42
  }
43
 
44
  .avhec-metabox-wrap ul li {
45
+ line-height : 120%;
46
+ list-style : disc inside none;
47
+ margin-bottom : 0;
48
  }
49
 
50
  #avhec-options input {
58
  /* Metabox FAQ */
59
  #avhecBoxFAQ .inside ul {
60
 
61
+ margin-bottom : 6px;
62
  }
63
+
64
+ #avhecBoxFAQ .inside ul li {
65
+ line-height : 120%;
66
+ list-style : disc inside none;
67
+ margin-bottom : 0;
68
  }
69
 
70
  /* Metabox Donations*/
73
  }
74
 
75
  #avhecBoxDonations .versions {
76
+ padding : 6px 10px 12px;
77
  }
78
 
79
  /* Metabox Donations*/
83
 
84
  /* Metabox in post and page */
85
  #post_avhec_category_group {
86
+ width : 100%;
87
  }
88
 
89
  #avhec-catlist {
90
+ -moz-border-radius : 4px 4px 4px 4px;
91
+ background-color : #FFFFFF;
92
+ border : 1px solid #DFDFDF;
93
+ height : 20em;
94
+ margin-bottom : -1.8em;
95
+ overflow : auto;
96
+ width : 95%;
97
  }
98
 
99
  #avhec-catlist ul {
100
+ padding : 3px;
101
  }
102
 
103
  #avhec-catlist li ul {
104
+ padding : 0px;
105
  }
106
 
107
  #avhec-catlist li {
108
+ margin-bottom : 0px;
109
  }
110
 
111
  #avhecManualOrder {
112
+ width : 25%;
113
+ /* border: 1px solid #B2B2B2;*/
114
+ /* margin: 10px 10px 10px 0px;*/
115
+ /* padding: 5px 10px 5px 10px;*/
116
+ /* list-style: none;*/
117
+ /* background-color: #fff;*/
118
+ /* border-radius: 3px;*/
119
+ /* -webkit-border-radius: 3px;*/
120
  }
121
 
122
  #avhecManualOrder li.lineitem {
123
+ border : 1px solid #DFDFDF;
124
+ background-image : none;
125
+ border-radius : 3px;
126
+ -webkit-border-radius : 3px;
127
+ background-color : #FFFFFF;
128
+ color : #555555;
129
+ cursor : move;
130
+ margin-top : 5px;
131
+ margin-bottom : 5px;
132
+ padding : 2px 5px 2px 5px;
133
+ list-style : none outside none;
134
  }
135
 
136
  #avhecManualOrder .sortable-placeholder {
137
+ border : 1px dashed #B2B2B2;
138
+ margin-top : 5px;
139
+ margin-bottom : 5px;
140
+ padding : 2px 5px 2px 5px;
141
+ height : 1.5em;
142
+ line-height : 1.5em;
143
+ list-style : none outside none;
144
+ background-color : transparent;
145
+ background-image : -ms-linear-gradient(top, #f9f9f9, #f5f5f5); /* IE10 */
146
+ background-image : -moz-linear-gradient(top, #f9f9f9, #f5f5f5); /* Firefox */
147
+ background-image : -o-linear-gradient(top, #f9f9f9, #f5f5f5); /* Opera */
148
+ background-image : -webkit-gradient(linear, left top, left bottom, from(#f9f9f9), to(#f5f5f5)); /* old Webkit */
149
+ background-image : -webkit-linear-gradient(top, #f9f9f9, #f5f5f5); /* new Webkit */
150
+ background-image : linear-gradient(top, #f9f9f9, #f5f5f5); /* proposed W3C Markup */
151
  }
2.8/css/avh-ec.widget.css CHANGED
@@ -1,12 +1,12 @@
1
  /* AVH Extended Categories Widget CSS */
2
  .avhec-widget-line {
3
- display: inline-block;
4
  }
5
 
6
  .avhec-widget-count {
7
- display: inline;
8
  }
9
 
10
  .avhec-widget-rss {
11
- display: inline;
12
  }
1
  /* AVH Extended Categories Widget CSS */
2
  .avhec-widget-line {
3
+ display : inline-block;
4
  }
5
 
6
  .avhec-widget-count {
7
+ display : inline;
8
  }
9
 
10
  .avhec-widget-rss {
11
+ display : inline;
12
  }
2.8/helpers/avh-forms.php CHANGED
@@ -1,40 +1,56 @@
1
  <?php
2
- if (! function_exists('avh_doWidgetFormText')) {
3
 
4
- function avh_doWidgetFormText ($field_id, $field_name, $description, $value)
5
- {
6
  echo '<label for="' . $field_id . '">';
7
  echo $description;
8
- echo '<input class="widefat" id="' . $field_id . '" name="' . $field_name . '" type="text" value="' . esc_attr($value) . '" /> ';
 
 
 
 
 
 
9
  echo '</label>';
10
  echo '<br />';
11
  }
12
  }
13
 
14
- if (! function_exists('avh_doWidgetFormCheckbox')) {
 
 
15
 
16
- function avh_doWidgetFormCheckbox ($field_id, $field_name, $description, $is_checked = FALSE)
17
- {
18
-
19
  echo '<label for="' . $field_id . '">';
20
- echo '<input class="checkbox" type="checkbox" id="' . $field_id . '" name="' . $field_name . '"' . ($is_checked ? ' CHECKED' : '') . ' /> ';
 
 
 
 
 
 
21
  echo $description;
22
  echo '</label>';
23
  echo '<br />';
24
  }
25
  }
26
 
27
- if (! function_exists('avh_doWidgetFormSelect')) {
28
 
29
- function avh_doWidgetFormSelect ($field_id, $field_name, $description, $options, $selected_value)
30
- {
31
  echo '<label for="' . $field_id . '">';
32
  echo $description . ' ';
33
  echo '</label>';
34
-
35
  $data = '';
36
  foreach ($options as $value => $text) {
37
- $data .= '<option value="' . $value . '" ' . ($value == $selected_value ? "SELECTED" : '') . '>' . $text . '</option>' . "/n";
 
 
 
 
 
 
 
38
  }
39
  echo '<select id="' . $field_id . '" name="' . $field_name . '"> ';
40
  echo $data;
1
  <?php
2
+ if ( ! function_exists('avh_doWidgetFormText')) {
3
 
4
+ function avh_doWidgetFormText($field_id, $field_name, $description, $value) {
 
5
  echo '<label for="' . $field_id . '">';
6
  echo $description;
7
+ echo '<input class="widefat" id="' .
8
+ $field_id .
9
+ '" name="' .
10
+ $field_name .
11
+ '" type="text" value="' .
12
+ esc_attr($value) .
13
+ '" /> ';
14
  echo '</label>';
15
  echo '<br />';
16
  }
17
  }
18
 
19
+ if ( ! function_exists('avh_doWidgetFormCheckbox')) {
20
+
21
+ function avh_doWidgetFormCheckbox($field_id, $field_name, $description, $is_checked = false) {
22
 
 
 
 
23
  echo '<label for="' . $field_id . '">';
24
+ echo '<input class="checkbox" type="checkbox" id="' .
25
+ $field_id .
26
+ '" name="' .
27
+ $field_name .
28
+ '"' .
29
+ ($is_checked ? ' CHECKED' : '') .
30
+ ' /> ';
31
  echo $description;
32
  echo '</label>';
33
  echo '<br />';
34
  }
35
  }
36
 
37
+ if ( ! function_exists('avh_doWidgetFormSelect')) {
38
 
39
+ function avh_doWidgetFormSelect($field_id, $field_name, $description, $options, $selected_value) {
 
40
  echo '<label for="' . $field_id . '">';
41
  echo $description . ' ';
42
  echo '</label>';
43
+
44
  $data = '';
45
  foreach ($options as $value => $text) {
46
+ $data .= '<option value="' .
47
+ $value .
48
+ '" ' .
49
+ ($value == $selected_value ? "SELECTED" : '') .
50
+ '>' .
51
+ $text .
52
+ '</option>' .
53
+ "/n";
54
  }
55
  echo '<select id="' . $field_id . '" name="' . $field_name . '"> ';
56
  echo $data;
2.8/js/avh-ec.admin.manualorder.closure.js DELETED
@@ -1 +0,0 @@
1
- function avhecManualOrder(){jQuery("#avhecManualOrder").sortable({placeholder:"sortable-placeholder",revert:false,items:".lineitem",opacity:0.65,cursor:"move",forcePlaceholderSize:true,tolerance:"pointer"})}addLoadEvent(avhecManualOrder);function orderCats(){jQuery("#updateText").html("Updating Category Order...");jQuery("#hdnManualOrder").val(jQuery("#avhecManualOrder").sortable("toArray"))};
 
2.8/js/avh-ec.admin.manualorder.js CHANGED
@@ -1,19 +1,19 @@
1
  function avhecManualOrder() {
2
- jQuery("#avhecManualOrder").sortable({
3
- placeholder : "sortable-placeholder",
4
- revert : false,
5
- items : '.lineitem',
6
- opacity: 0.65,
7
- cursor: 'move',
8
- forcePlaceholderSize: true,
9
- tolerance : "pointer"
10
- });
11
  };
12
 
13
  addLoadEvent(avhecManualOrder);
14
 
15
  function orderCats() {
16
- jQuery("#updateText").html("Updating Category Order...");
17
- jQuery("#hdnManualOrder").val(
18
- jQuery("#avhecManualOrder").sortable("toArray"));
19
  }
1
  function avhecManualOrder() {
2
+ jQuery("#avhecManualOrder").sortable({
3
+ placeholder: "sortable-placeholder",
4
+ revert: false,
5
+ items: '.lineitem',
6
+ opacity: 0.65,
7
+ cursor: 'move',
8
+ forcePlaceholderSize: true,
9
+ tolerance: "pointer"
10
+ });
11
  };
12
 
13
  addLoadEvent(avhecManualOrder);
14
 
15
  function orderCats() {
16
+ jQuery("#updateText").html("Updating Category Order...");
17
+ jQuery("#hdnManualOrder").val(
18
+ jQuery("#avhecManualOrder").sortable("toArray"));
19
  }
2.8/js/avh-ec.admin.manualorder.min.js ADDED
@@ -0,0 +1 @@
 
1
+ function avhecManualOrder(){jQuery("#avhecManualOrder").sortable({placeholder:"sortable-placeholder",revert:false,items:".lineitem",opacity:.65,cursor:"move",forcePlaceholderSize:true,tolerance:"pointer"})}addLoadEvent(avhecManualOrder);function orderCats(){jQuery("#updateText").html("Updating Category Order...");jQuery("#hdnManualOrder").val(jQuery("#avhecManualOrder").sortable("toArray"))}
2.8/js/avh-ec.categorygroup.closure.js DELETED
@@ -1 +0,0 @@
1
- jQuery(document).ready(function(a){a("#the-list").wpList({delBefore:function(b){if("undefined"!=showNotice)return showNotice.warn()?b:false;return b}});a('.delete a[class^="delete"]').live("click",function(){return false})});
 
2.8/js/avh-ec.categorygroup.js CHANGED
@@ -1,21 +1,23 @@
1
- jQuery(document).ready(function($) {
2
- var options = false, delBefore, delAfter;
3
 
4
- delAfter = function( r, settings ) {
5
- var id = $('cat', r).attr('id'), o;
6
- for ( o = 0; o < options.length; o++ )
7
- if ( id == options[o].value )
8
- options[o] = null;
9
- };
10
 
11
- delBefore = function(s) {
12
- if ( 'undefined' != showNotice )
13
- return showNotice.warn() ? s : false;
14
 
15
- return s;
16
- };
17
 
18
- $('#the-list').wpList({ delBefore: delBefore });
19
 
20
- $('.delete a[class^="delete"]').live('click', function(){return false;});
 
 
21
  });
1
+ jQuery(document).ready(function ($) {
2
+ var options = false, delBefore, delAfter;
3
 
4
+ delAfter = function (r, settings) {
5
+ var id = $('cat', r).attr('id'), o;
6
+ for (o = 0; o < options.length; o++)
7
+ if (id == options[o].value)
8
+ options[o] = null;
9
+ };
10
 
11
+ delBefore = function (s) {
12
+ if ('undefined' != showNotice)
13
+ return showNotice.warn() ? s : false;
14
 
15
+ return s;
16
+ };
17
 
18
+ $('#the-list').wpList({delBefore: delBefore});
19
 
20
+ $('.delete a[class^="delete"]').live('click', function () {
21
+ return false;
22
+ });
23
  });
2.8/js/avh-ec.categorygroup.js.closure.js DELETED
@@ -1 +0,0 @@
1
- jQuery(document).ready(function(a){a("#the-list").wpList({delBefore:function(b){if("undefined"!=showNotice)return showNotice.warn()?b:false;return b}});a('.delete a[class^="delete"]').live("click",function(){return false})});
 
2.8/js/avh-ec.categorygroup.min.js ADDED
@@ -0,0 +1 @@
 
1
+ jQuery(document).ready(function($){var options=false,delBefore,delAfter;delAfter=function(r,settings){var id=$("cat",r).attr("id"),o;for(o=0;o<options.length;o++)if(id==options[o].value)options[o]=null};delBefore=function(s){if("undefined"!=showNotice)return showNotice.warn()?s:false;return s};$("#the-list").wpList({delBefore:delBefore});$('.delete a[class^="delete"]').live("click",function(){return false})});
3.3/avh-ec.client.php CHANGED
@@ -2,77 +2,65 @@
2
 
3
  /**
4
  * Singleton Class
5
- *
6
  */
7
- class AVH_EC_Singleton
8
- {
9
-
10
  /**
11
- *
12
  * @param $class
13
  * @param $arg1
14
  */
15
- function &getInstance ($class, $arg1 = null)
16
- {
17
- static $instances = array (); // array of instance names
18
  if (array_key_exists($class, $instances)) {
19
- $instance = & $instances[$class];
20
  } else {
21
- if (! class_exists($class)) {
22
  switch ($class) {
23
  case 'AVH_EC_Core':
24
- require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.core.php');
25
  break;
26
  case 'AVH_EC_Category_Group':
27
- require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.category-group.php');
28
  break;
29
  case 'AVH_EC_Widget_Helper_Class':
30
- require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widget-helper.php');
31
  break;
32
  }
33
  }
34
- $instances[$class] = new $class($arg1);
35
- $instance = & $instances[$class];
36
  }
 
37
  return $instance;
38
  } // getInstance
39
  } // singleton
40
 
41
-
42
  /**
43
  * Include the necessary files
44
- *
45
  */
46
- require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/helpers/avh-forms.php');
47
- require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widgets.php');
48
 
49
  /**
50
  * Initialize the plugin
51
- *
52
  */
53
- function avhextendedcategories_init ()
54
- {
55
  // Admin
56
  if (is_admin()) {
57
- require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.admin.php');
58
  $avhec_admin = new AVH_EC_Admin();
59
  }
60
  AVH_EC_Singleton::getInstance('AVH_EC_Core');
61
-
62
- add_action('widgets_init', 'avhextendedcategories_widgets_init');
63
 
 
64
  } // End avhamazon_init()
65
 
66
-
67
  /**
68
  * Register the widget
69
  *
70
  * @WordPress Action widgets_init
71
- * @since 3.0
72
- *
73
  */
74
- function avhextendedcategories_widgets_init ()
75
- {
76
  register_widget('WP_Widget_AVH_ExtendedCategories_Normal');
77
  register_widget('WP_Widget_AVH_ExtendedCategories_Top');
78
  register_widget('WP_Widget_AVH_ExtendedCategories_Category_Group');
2
 
3
  /**
4
  * Singleton Class
 
5
  */
6
+ class AVH_EC_Singleton {
 
 
7
  /**
 
8
  * @param $class
9
  * @param $arg1
10
  */
11
+ function &getInstance($class, $arg1 = null) {
12
+ static $instances = array(); // array of instance names
 
13
  if (array_key_exists($class, $instances)) {
14
+ $instance = &$instances[ $class ];
15
  } else {
16
+ if ( ! class_exists($class)) {
17
  switch ($class) {
18
  case 'AVH_EC_Core':
19
+ require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.core.php');
20
  break;
21
  case 'AVH_EC_Category_Group':
22
+ require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.category-group.php');
23
  break;
24
  case 'AVH_EC_Widget_Helper_Class':
25
+ require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widget-helper.php');
26
  break;
27
  }
28
  }
29
+ $instances[ $class ] = new $class($arg1);
30
+ $instance = &$instances[ $class ];
31
  }
32
+
33
  return $instance;
34
  } // getInstance
35
  } // singleton
36
 
 
37
  /**
38
  * Include the necessary files
 
39
  */
40
+ require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/helpers/avh-forms.php');
41
+ require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widgets.php');
42
 
43
  /**
44
  * Initialize the plugin
 
45
  */
46
+ function avhextendedcategories_init() {
 
47
  // Admin
48
  if (is_admin()) {
49
+ require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.admin.php');
50
  $avhec_admin = new AVH_EC_Admin();
51
  }
52
  AVH_EC_Singleton::getInstance('AVH_EC_Core');
 
 
53
 
54
+ add_action('widgets_init', 'avhextendedcategories_widgets_init');
55
  } // End avhamazon_init()
56
 
 
57
  /**
58
  * Register the widget
59
  *
60
  * @WordPress Action widgets_init
61
+ * @since 3.0
 
62
  */
63
+ function avhextendedcategories_widgets_init() {
 
64
  register_widget('WP_Widget_AVH_ExtendedCategories_Normal');
65
  register_widget('WP_Widget_AVH_ExtendedCategories_Top');
66
  register_widget('WP_Widget_AVH_ExtendedCategories_Category_Group');
3.3/class/avh-ec.admin.php CHANGED
@@ -1,145 +1,154 @@
1
  <?php
2
 
3
- class AVH_EC_Admin
4
- {
5
  /**
6
- *
7
- * @var AVH_EC_Core
8
- */
9
- var $core;
10
-
11
- /**
12
- *
13
  * @var AVH_EC_Category_Group
14
  */
15
  var $catgrp;
16
-
17
- var $hooks = array ();
 
 
 
18
  var $message;
19
 
20
  /**
21
  * PHP5 constructor
22
- *
23
  */
24
- function __construct ()
25
- {
26
 
27
  // Initialize the plugin
28
- $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core');
29
- $this->catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
30
 
31
- add_action('wp_ajax_delete-group', array ( &$this, 'ajaxDeleteGroup' ));
32
 
33
  // Admin menu
34
- add_action('admin_init', array ( &$this, 'actionAdminInit' ));
35
- add_action('admin_menu', array ( &$this, 'actionAdminMenu' ));
36
- add_filter('plugin_action_links_extended-categories-widget/widget_extended_categories.php', array ( &$this, 'filterPluginActions' ), 10, 2);
 
 
 
37
 
38
  // Actions used for editing posts
39
- add_action('load-post.php', array ( &$this, 'actionLoadPostPage' ));
40
- add_action('load-page.php', array ( &$this, 'actionLoadPostPage' ));
41
 
42
  // Actions related to adding and deletes categories
43
- add_action("created_category", array ( $this, 'actionCreatedCategory' ), 10, 2);
44
- add_action("delete_category", array ( $this, 'actionDeleteCategory' ), 10, 2);
45
 
46
- add_filter('manage_categories_group_columns', array ( &$this, 'filterManageCategoriesGroupColumns' ));
47
- add_filter('explain_nonce_delete-avhecgroup', array ( &$this, 'filterExplainNonceDeleteGroup' ), 10, 2);
48
 
49
  return;
50
  }
51
 
52
  /**
53
  * PHP4 Constructor
54
- *
55
  */
56
- function AVH_EC_Admin ()
57
- {
58
  $this->__construct();
59
  }
60
 
61
- function actionAdminInit ()
62
- {
63
  if (is_admin() && isset($_GET['taxonomy']) && 'category' == $_GET['taxonomy']) {
64
- add_action($_GET['taxonomy'] . '_edit_form', array ( &$this, 'displayCategoryGroupForm' ), 10, 2);
65
  }
66
- add_action('edit_term', array ( &$this, 'handleEditTerm' ), 10, 3);
67
-
68
  }
69
 
70
  /**
 
71
  *
72
- * Adds Category Group form
73
- * @WordPress action category_edit_form
74
- *
75
- * @param unknown_type $term
76
- * @param unknown_type $taxonomy
77
  */
78
- function displayCategoryGroupForm ($term, $taxonomy)
79
- {
80
 
81
- $current_selection = '';
82
- $tax_meta = get_option($this->core->db_options_tax_meta);
83
- if (isset($tax_meta[$taxonomy][$term->term_id])) {
84
- $tax_meta = $tax_meta[$taxonomy][$term->term_id];
85
- $current_selection = $tax_meta['category_group_term_id'];
86
- }
 
 
 
 
 
 
 
 
 
 
 
87
 
88
- if (empty($current_selection)) {
89
- $current_group = $this->catgrp->getGroupByCategoryID($term->term_id);
90
- $current_selection = $current_group->term_id;
91
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
 
93
- $cat_groups = get_terms($this->catgrp->taxonomy_name, array ( 'hide_empty' => FALSE ));
94
- foreach ($cat_groups as $group) {
95
- $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit');
96
- $dropdown_value[] = $group->term_id;
97
- $dropdown_text[] = $temp_cat->name;
98
- }
99
 
100
- foreach ($dropdown_value as $key => $sel) {
101
- $seldata .= '<option value="' . esc_attr($sel) . '" ' . (($current_selection == $sel) ? 'selected="selected"' : '') . ' >' . esc_html(ucfirst($dropdown_text[$key])) . '</option>' . "\n";
102
- }
103
 
104
- echo '<h3>AVH Extended Categories - Category Group Widget</h3>';
105
- echo '<table class="form-table"><tbody>';
106
- echo '<tr class="form-field">';
107
- echo '<th valign="top" scope="row">';
108
- echo '<label for="avhec_categorygroup">Category Group</label></th>';
109
- echo '<td>';
110
- echo '<select id="avhec_categorygroup" name="avhec_categorygroup">';
111
- echo $seldata;
112
- echo '</select>';
113
- echo '<p class="description">Select the category group to show on the archive page.</p>';
114
- echo '</td>';
115
- echo '</tr>';
116
- echo '</tbody></table>';
117
- }
118
 
119
- /**
120
- * Saves the association Category - Category Group fron the edit taxonomy page
121
- * @WordPress action edit_form.
122
- *
123
- * @param unknown_type $term_id
124
- * @param unknown_type $tt_id
125
- * @param unknown_type $taxonomy
126
- */
127
- function handleEditTerm ($term_id, $tt_id, $taxonomy)
128
- {
129
- $tax_meta = get_option($this->core->db_options_tax_meta);
130
- if (isset($_POST['avhec_categorygroup']) && isset($tax_meta[$taxonomy][$term_id]['category_group_term_id']) && $tax_meta[$taxonomy][$term_id]['category_group_term_id'] != $_POST['avhec_categorygroup']) {
131
- $tax_meta[$taxonomy][$term_id]['category_group_term_id'] = $_POST['avhec_categorygroup'];
132
- update_option($this->core->db_options_tax_meta, $tax_meta);
133
- }
134
  }
135
 
136
  /**
137
  * When a category is created this function is called to add the new category to the group all
 
138
  * @param $term_id
139
  * @param $term_taxonomy_id
140
  */
141
- function actionCreatedCategory ($term_id, $term_taxonomy_id)
142
- {
143
  $group_id = $this->catgrp->getTermIDBy('slug', 'all');
144
  $this->catgrp->setCategoriesForGroup($group_id, (array) $term_id);
145
  }
@@ -148,75 +157,118 @@ class AVH_EC_Admin
148
  * When a category is deleted this function is called so the category is deleted from every group as well.
149
  *
150
  * @param object $term
151
- * @param int $term_taxonomy_id
152
  */
153
- function actionDeleteCategory ($term_id, $term_taxonomy_id)
154
- {
155
  $this->catgrp->doDeleteCategoryFromGroup($term_id);
156
  }
157
 
158
  /**
159
- * Enqueues the style on the post.php and page.php pages
160
- * @WordPress Action load-$pagenow
161
- *
162
  */
163
- function actionLoadPostPage ()
164
- {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
  wp_enqueue_style('avhec-admin-css');
166
  }
167
 
168
  /**
169
- * Add the Tools and Options to the Management and Options page repectively
170
- *
171
- * @WordPress Action admin_menu
172
- *
173
  */
174
- function actionAdminMenu ()
175
- {
 
 
 
 
 
 
176
 
177
- // Register Style and Scripts
178
- $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.closure';
179
- wp_register_script('avhec-categorygroup-js', AVHEC_PLUGIN_URL . '/js/avh-ec.categorygroup' . $suffix . '.js', array ( 'jquery' ), $this->core->version, true);
180
- wp_register_script('avhec-manualorder', AVHEC_PLUGIN_URL . '/js/avh-ec.admin.manualorder' . $suffix . '.js', array ( 'jquery-ui-sortable' ), $this->core->version, false);
181
- wp_register_style('avhec-admin-css', AVHEC_PLUGIN_URL . '/css/avh-ec.admin.css', array ( 'wp-admin' ), $this->core->version, 'screen');
182
 
183
- // Add menu system
184
- $folder = $this->core->getBaseDirectory(AVHEC_PLUGIN_DIR);
185
- add_menu_page('AVH Extended Categories', 'AVH Extended Categories', 'manage_options', $folder, array ( &$this, 'doMenuOverview' ));
186
- $this->hooks['menu_overview'] = add_submenu_page($folder, 'AVH Extended Categories: ' . __('Overview', 'avh-ec'), __('Overview', 'avh-ec'), 'manage_options', $folder, array ( &$this, 'doMenuOverview' ));
187
- $this->hooks['menu_general'] = add_submenu_page($folder, 'AVH Extended Categories: ' . __('General Options', 'avh-ec'), __('General Options', 'avh-ec'), 'manage_options', 'avhec-general', array ( &$this, 'doMenuGeneral' ));
188
- $this->hooks['menu_category_groups'] = add_submenu_page($folder, 'AVH Extended Categories: ' . __('Category Groups', 'avh-ec'), __('Category Groups', 'avh-ec'), 'manage_options', 'avhec-grouped', array ( &$this, 'doMenuCategoryGroup' ));
189
- $this->hooks['menu_manual_order'] = add_submenu_page($folder, 'AVH Extended Categories: ' . __('Manually Order', 'avh-ec'), __('Manually Order', 'avh-ec'), 'manage_options', 'avhec-manual-order', array ( &$this, 'doMenuManualOrder' ));
190
- $this->hooks['menu_faq'] = add_submenu_page($folder, 'AVH Extended Categories:' . __('F.A.Q', 'avh-ec'), __('F.A.Q', 'avh-ec'), 'manage_options', 'avhec-faq', array ( &$this, 'doMenuFAQ' ));
191
 
192
- // Add actions for menu pages
193
- // Overview Menu
194
- add_action('load-' . $this->hooks['menu_overview'], array ( &$this, 'actionLoadPageHook_Overview' ));
195
 
196
- // General Options Menu
197
- add_action('load-' . $this->hooks['menu_general'], array ( &$this, 'actionLoadPageHook_General' ));
 
 
198
 
199
- // Category Groups Menu
200
- add_action('load-' . $this->hooks['menu_category_groups'], array ( &$this, 'actionLoadPageHook_CategoryGroup' ));
 
 
 
 
201
 
202
- // Manual Order Menu
203
- add_action('load-' . $this->hooks['menu_manual_order'], array ( &$this, 'actionLoadPageHook_ManualOrder' ));
204
 
205
- // FAQ Menu
206
- add_action('load-' . $this->hooks['menu_faq'], array ( &$this, 'actionLoadPageHook_faq' ));
 
 
 
 
 
 
 
207
  }
208
 
209
  /**
210
  * Setup everything needed for the Overview page
211
- *
212
  */
213
- function actionLoadPageHook_Overview ()
214
- {
215
  // Add metaboxes
216
- add_meta_box('avhecBoxCategoryGroupList', __('Group Overview', 'avh-ec'), array ( &$this, 'metaboxCategoryGroupList' ), $this->hooks['menu_overview'], 'normal', 'core');
217
- add_meta_box('avhecBoxTranslation', __('Translation', 'avh-ec'), array ( &$this, 'metaboxTranslation' ), $this->hooks['menu_overview'], 'normal', 'core');
218
-
219
- add_screen_option('layout_columns', array ( 'max' => 2, 'default' => 2 ));
 
 
 
 
 
 
 
 
 
 
220
 
221
  // WordPress core Scripts
222
  wp_enqueue_script('common');
@@ -231,297 +283,289 @@ class AVH_EC_Admin
231
  }
232
 
233
  /**
234
- * Menu Page Overview
235
- *
236
- * @return none
237
  */
238
- function doMenuOverview ()
239
- {
240
- global $screen_layout_columns;
 
 
 
 
 
 
 
 
 
 
 
 
 
241
 
242
- // This box can't be unselectd in the the Screen Options
243
- //add_meta_box('avhecBoxAnnouncements', __('Announcements', 'avh-ec'), array ( &$this, 'metaboxAnnouncements' ), $this->hooks['menu_overview'], 'side', '');
244
- add_meta_box('avhecBoxDonations', __('Donations', 'avh-ec'), array ( &$this, 'metaboxDonations' ), $this->hooks['menu_overview'], 'side', '');
 
245
 
246
- $hide2 = '';
247
- switch ($screen_layout_columns) {
248
- case 2:
249
- $width = 'width:49%;';
250
- break;
251
- default:
252
- $width = 'width:98%;';
253
- $hide2 = 'display:none;';
254
- }
255
 
256
- echo '<div class="wrap avhec-metabox-wrap">';
257
- echo $this->displayIcon('index');
258
- echo '<h2>' . 'AVH Extended Categories - ' . __('Overview', 'avh-ec') . '</h2>';
259
- echo ' <div id="dashboard-widgets-wrap">';
260
- echo ' <div id="dashboard-widgets" class="metabox-holder">';
261
- echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
262
- do_meta_boxes($this->hooks['menu_overview'], 'normal', '');
263
- echo " </div>";
264
- echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n";
265
- do_meta_boxes($this->hooks['menu_overview'], 'side', '');
266
- echo ' </div>';
267
- echo ' </div>';
268
 
269
- echo '<br class="clear"/>';
270
- echo ' </div>'; //dashboard-widgets-wrap
271
- echo '</div>'; // wrap
 
 
 
272
 
 
 
 
 
 
 
 
273
 
274
- $this->printMetaboxGeneralNonces();
275
- $this->printMetaboxJS('overview');
276
- $this->printAdminFooter();
 
 
277
  }
278
 
279
  /**
280
- * Setup everything needed for the General Options page
281
  *
 
 
 
 
282
  */
283
- function actionLoadPageHook_General ()
284
- {
285
- // Add metaboxes
286
- add_meta_box('avhecBoxOptions', __('Options', 'avh-ec'), array ( &$this, 'metaboxOptions' ), $this->hooks['menu_general'], 'normal', 'core');
287
 
288
- add_screen_option('layout_columns', array ( 'max' => 2, 'default' => 2 ));
 
 
 
 
 
289
 
290
- // WordPress core Scripts
291
- wp_enqueue_script('common');
292
- wp_enqueue_script('wp-lists');
293
- wp_enqueue_script('postbox');
294
 
295
- // Plugin Style and Scripts
296
- wp_enqueue_style('avhec-admin-css');
 
 
 
 
297
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
298
  }
299
 
300
  /**
301
- * Menu Page General Options
302
  *
303
- * @return none
304
  */
305
- function doMenuGeneral ()
306
- {
307
- global $screen_layout_columns;
308
 
309
- $groups = get_terms($this->catgrp->taxonomy_name, array ( 'hide_empty' => FALSE ));
310
- foreach ($groups as $group) {
311
- $group_id[] = $group->term_id;
312
- $groupname[] = $group->name;
 
 
 
 
 
 
 
 
 
313
  }
 
314
 
315
- $options_general[] = array ( 'avhec[general][alternative_name_select_category]', __('<em>Select Category</em> Alternative', 'avh-ec'), 'text', 20, __('Alternative text for Select Category.', 'avh-ec') );
316
- $options_general[] = array ( 'avhec[cat_group][home_group]', 'Home Group', 'dropdown', $group_id, $groupname, __('Select which group to show on the home page.', 'avh-ec') . '<br />' . __('Selecting the group \'none\' will not show the widget on the page.', 'avh-ec') );
317
- $options_general[] = array ( 'avhec[cat_group][no_group]', 'Nonexistence Group', 'dropdown', $group_id, $groupname, __('Select which group to show when there is no group associated with the post.', 'avh-ec') . '<br />' . __('Selecting the group \'none\' will not show the widget on the page.', 'avh-ec') );
318
- $options_general[] = array ( 'avhec[cat_group][default_group]', 'Default Group', 'dropdown', $group_id, $groupname, __('Select which group will be the default group when editing a post.', 'avh-ec') . '<br />' . __('Selecting the group \'none\' will not show the widget on the page.', 'avh-ec') );
 
 
 
319
 
320
- if (isset($_POST['updateoptions'])) {
321
- check_admin_referer('avh_ec_generaloptions');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
322
 
323
- $formoptions = $_POST['avhec'];
324
- $options = $this->core->getOptions();
325
-
326
- //$all_data = array_merge( $options_general );
327
- $all_data = $options_general;
328
- foreach ($all_data as $option) {
329
- $section = substr($option[0], strpos($option[0], '[') + 1);
330
- $section = substr($section, 0, strpos($section, ']['));
331
- $option_key = rtrim($option[0], ']');
332
- $option_key = substr($option_key, strpos($option_key, '][') + 2);
333
-
334
- switch ($section) {
335
- case 'general':
336
- case 'cat_group':
337
- $current_value = $options[$section][$option_key];
338
- break;
339
- }
340
- // Every field in a form is set except unchecked checkboxes. Set an unchecked checkbox to 0.
341
- $newval = (isset($formoptions[$section][$option_key]) ? esc_attr($formoptions[$section][$option_key]) : 0);
342
- if ($newval != $current_value) { // Only process changed fields.
343
- switch ($section) {
344
- case 'general':
345
- case 'cat_group':
346
- $options[$section][$option_key] = $newval;
347
- break;
348
- }
349
- }
350
- }
351
- $this->core->saveOptions($options);
352
- $this->message = __('Options saved', 'avh-ec');
353
- $this->status = 'updated fade';
354
-
355
- }
356
- $this->displayMessage();
357
-
358
- $actual_options = $this->core->getOptions();
359
- foreach ($actual_options['cat_group'] as $key => $value) {
360
- if (! (in_array($value, (array) $group_id))) {
361
- $actual_options['cat_group'][$key] = $this->catgrp->getTermIDBy('slug', 'none');
362
- }
363
- }
364
-
365
- $hide2 = '';
366
- switch ($screen_layout_columns) {
367
- case 2:
368
- $width = 'width:49%;';
369
- break;
370
- default:
371
- $width = 'width:98%;';
372
- $hide2 = 'display:none;';
373
- }
374
- $data['options_general'] = $options_general;
375
- $data['actual_options'] = $actual_options;
376
-
377
- // This box can't be unselectd in the the Screen Options
378
- add_meta_box('avhecBoxDonations', __('Donations', 'avh-ec'), array ( &$this, 'metaboxDonations' ), $this->hooks['menu_general'], 'side', 'core');
379
-
380
- $hide2 = '';
381
- switch ($screen_layout_columns) {
382
- case 2:
383
- $width = 'width:49%;';
384
- break;
385
- default:
386
- $width = 'width:98%;';
387
- $hide2 = 'display:none;';
388
- }
389
-
390
- echo '<div class="wrap avhec-metabox-wrap">';
391
- echo $this->displayIcon('index');
392
- echo '<h2>' . 'AVH Extended Categories - ' . __('General Options', 'avh-ec') . '</h2>';
393
- echo '<form name="avhec-generaloptions" id="avhec-generaloptions" method="POST" action="' . admin_url('admin.php?page=avhec-general') . '" accept-charset="utf-8" >';
394
- wp_nonce_field('avh_ec_generaloptions');
395
-
396
- echo ' <div id="dashboard-widgets-wrap">';
397
- echo ' <div id="dashboard-widgets" class="metabox-holder">';
398
- echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
399
- do_meta_boxes($this->hooks['menu_general'], 'normal', $data);
400
- echo " </div>";
401
- echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n";
402
- do_meta_boxes($this->hooks['menu_general'], 'side', $data);
403
- echo ' </div>';
404
- echo ' </div>';
405
-
406
- echo '<br class="clear"/>';
407
- echo ' </div>'; //dashboard-widgets-wrap
408
- echo '<p class="submit"><input class="button" type="submit" name="updateoptions" value="' . __('Save Changes', 'avhf-ec') . '" /></p>';
409
- echo '</form>';
410
-
411
- echo '</div>'; // wrap
412
-
413
-
414
- $this->printMetaboxGeneralNonces();
415
- $this->printMetaboxJS('general');
416
- $this->printAdminFooter();
417
- }
418
-
419
- /**
420
- * Options Metabox
421
- *
422
- */
423
- function metaboxOptions ($data)
424
- {
425
- echo $this->printOptions($data['options_general'], $data['actual_options']);
426
- }
427
-
428
- /**
429
- * Setup everything needed for the Category Group page
430
- *
431
- */
432
- function actionLoadPageHook_CategoryGroup ()
433
- {
434
-
435
- // Add metaboxes
436
- add_meta_box('avhecBoxCategoryGroupAdd', __('Add Group', 'avh-ec'), array ( &$this, 'metaboxCategoryGroupAdd' ), $this->hooks['menu_category_groups'], 'normal', 'core');
437
- add_meta_box('avhecBoxCategoryGroupList', __('Group Overview', 'avh-ec'), array ( &$this, 'metaboxCategoryGroupList' ), $this->hooks['menu_category_groups'], 'side', 'core');
438
- add_meta_box('avhecBoxCategoryGroupSpecialPages', __('Special Pages', 'avh-ec'), array ( &$this, 'metaboxCategoryGroupSpecialPages' ), $this->hooks['menu_category_groups'], 'normal', 'core');
439
-
440
- add_screen_option('layout_columns', array ( 'max' => 2, 'default' => 2 ));
441
-
442
- // WordPress core Scripts
443
- wp_enqueue_script('common');
444
- wp_enqueue_script('wp-lists');
445
- wp_enqueue_script('postbox');
446
-
447
- // Plugin Scripts
448
- wp_enqueue_script('avhec-categorygroup-js');
449
-
450
- // Plugin Style
451
- wp_enqueue_style('avhec-admin-css');
452
-
453
- }
454
-
455
- /**
456
- * Menu Page Category Group
457
- *
458
- * @return none
459
- */
460
- function doMenuCategoryGroup ()
461
- {
462
- global $screen_layout_columns;
463
-
464
- $data_add_group_default = array ( 'name' => '', 'slug' => '', 'widget_title' => '', 'description' => '' );
465
- $data_add_group_new = $data_add_group_default;
466
-
467
- $options_add_group[] = array ( 'avhec_add_group[add][name]', __('Group Name', 'avh-ec'), 'text', 20, __('The name is used to identify the group.', 'avh-ec') );
468
- $options_add_group[] = array ( 'avhec_add_group[add][slug]', __('Slug Group', 'avh-ec'), 'text', 20, __('The “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.', 'avh-ec') );
469
- $options_add_group[] = array ( 'avhec_add_group[add][widget_title]', __('Widget Title', 'avh-ec'), 'text', 20, __('When no title is given in the widget options, this will used as the title of the widget when this group is shown.', 'avh-ec') );
470
- $options_add_group[] = array ( 'avhec_add_group[add][description]', __('Description', 'avh-ec'), 'textarea', 40, __('Description is not prominent by default.', 'avh-ec'), 5 );
471
-
472
- $options_edit_group[] = array ( 'avhec_edit_group[edit][name]', __('Group Name', 'avh-ec'), 'text', 20, __('The name is used to identify the group.', 'avh-ec') );
473
- $options_edit_group[] = array ( 'avhec_edit_group[edit][slug]', __('Slug Group', 'avh-ec'), 'text', 20, __('The “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.', 'avh-ec') );
474
- $options_edit_group[] = array ( 'avhec_edit_group[edit][widget_title]', __('Widget Title', 'avh-ec'), 'text', 20, __('When no title is given in the widget options, this will used as the title of the widget when this group is shown.', 'avh-ec') );
475
- $options_edit_group[] = array ( 'avhec_edit_group[edit][description]', __('Description', 'avh-ec'), 'textarea', 40, __('Description is not prominent by default.', 'avh-ec'), 5 );
476
- $options_edit_group[] = array ( 'avhec_edit_group[edit][categories]', __('Categories', 'avh-ec'), 'catlist', 0, __('Select categories to be included in the group.', 'avh-ec') );
477
-
478
- if (isset($_POST['addgroup'])) {
479
- check_admin_referer('avh_ec_addgroup');
480
 
481
  $formoptions = $_POST['avhec_add_group'];
482
 
483
- $data_add_group_new['name'] = $formoptions['add']['name'];
484
- $data_add_group_new['slug'] = empty($formoptions['add']['slug']) ? sanitize_title($data_add_group_new['name']) : sanitize_title($formoptions['add']['slug']);
485
  $data_add_group_new['widget_title'] = $formoptions['add']['widget_title'];
486
- $data_add_group_new['description'] = $formoptions['add']['description'];
487
 
488
  $id = $this->catgrp->getTermIDBy('slug', $data_add_group_new['slug']);
489
- if (! $id) {
490
- $group_id = $this->catgrp->doInsertGroup($data_add_group_new['name'], array ( 'description' => $data_add_group_new['description'], 'slug' => $data_add_group_new['slug'] ), $data_add_group_new['widget_title']);
 
 
 
 
 
491
  $this->catgrp->setCategoriesForGroup($group_id);
492
- $this->message = __('Category group saved', 'avh-ec');
493
- $this->status = 'updated fade';
494
  $data_add_group_new = $data_add_group_default;
495
-
496
  } else {
497
- $group = $this->catgrp->getGroup($id);
498
  $this->message = __('Category group conflicts with ', 'avh-ec') . $group->name;
499
  $this->message .= '<br />' . __('Same slug is used. ', 'avh-ec');
500
  $this->status = 'error';
501
-
502
  }
503
  $this->displayMessage();
504
  }
505
  $data_add_group['add'] = $data_add_group_new;
506
- $data['add'] = array ( 'form' => $options_add_group, 'data' => $data_add_group );
507
 
508
  if (isset($_GET['action'])) {
509
  $action = $_GET['action'];
510
 
511
  switch ($action) {
512
  case 'edit':
513
- $group_id = (int) $_GET['group_ID'];
514
- $group = $this->catgrp->getGroup($group_id);
515
  $widget_title = $this->catgrp->getWidgetTitleForGroup($group_id);
516
- $cats = $this->catgrp->getCategoriesFromGroup($group_id);
517
-
518
- $data_edit_group['edit'] = array ( 'group_id' => $group_id, 'name' => $group->name, 'slug' => $group->slug, 'widget_title' => $widget_title, 'description' => $group->description, 'categories' => $cats );
519
- $data['edit'] = array ( 'form' => $options_edit_group, 'data' => $data_edit_group );
520
-
521
- add_meta_box('avhecBoxCategoryGroupEdit', __('Edit Group', 'avh-ec') . ': ' . $group->name, array ( &$this, 'metaboxCategoryGroupEdit' ), $this->hooks['menu_category_groups'], 'normal', 'low');
 
 
 
 
 
 
 
 
 
 
 
 
522
  break;
523
  case 'delete':
524
- if (! isset($_GET['group_ID'])) {
525
  wp_redirect($this->getBackLink());
526
  exit();
527
  }
@@ -529,7 +573,7 @@ class AVH_EC_Admin
529
  $group_id = (int) $_GET['group_ID'];
530
  check_admin_referer('delete-avhecgroup_' . $group_id);
531
 
532
- if (! current_user_can('manage_categories')) {
533
  wp_die(__('Cheatin&#8217; uh?'));
534
  }
535
  $this->catgrp->doDeleteGroup($group_id);
@@ -543,15 +587,22 @@ class AVH_EC_Admin
543
  if (isset($_POST['editgroup'])) {
544
  check_admin_referer('avh_ec_editgroup');
545
 
546
- $formoptions = $_POST['avhec_edit_group'];
547
  $selected_categories = $_POST['post_category'];
548
 
549
  $group_id = (int) $_POST['avhec-group_id'];
550
- $result = $this->catgrp->doUpdateGroup($group_id, array ( 'name' => $formoptions['edit']['name'], 'slug' => $formoptions['edit']['slug'], 'description' => $formoptions['edit']['description'] ), $selected_categories, $formoptions['edit']['widget_title']);
 
 
 
 
 
 
 
551
  switch ($result) {
552
  case 1:
553
  $this->message = __('Category group updated', 'avh-ec');
554
- $this->status = 'updated fade';
555
  break;
556
  case 0:
557
  $this->message = __('Category group not updated', 'avh-ec');
@@ -560,7 +611,7 @@ class AVH_EC_Admin
560
  break;
561
  case - 1:
562
  $this->message = __('Unknown category group', 'avh-ec');
563
- $this->status = 'error';
564
  break;
565
  }
566
  $this->displayMessage();
@@ -582,36 +633,76 @@ class AVH_EC_Admin
582
  check_admin_referer('avh_ec_specialpagesgroup');
583
 
584
  $formoptions = $_POST['avhec_special_pages'];
585
- $formdata = $formoptions['sp'];
586
  foreach ($formdata as $key => $value) {
587
- $data_special_pages_new[$key] = $value;
588
  }
589
  $this->core->options['sp_cat_group'] = $data_special_pages_new;
590
  $this->core->saveOptions($this->core->options);
591
-
592
  }
593
  $data_special_pages['sp'] = $data_special_pages_new;
594
- $cat_groups = get_terms($this->catgrp->taxonomy_name, array ( 'hide_empty' => FALSE ));
595
 
596
  foreach ($cat_groups as $group) {
597
- $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit');
598
  $dropdown_value[] = $group->term_id;
599
- $dropdown_text[] = $temp_cat->name;
600
  }
601
- $options_special_pages[] = array ( 'avhec_special_pages[sp][home_group]', __('Home page', 'avh-ec'), 'dropdown', $dropdown_value, $dropdown_text, sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('home', 'avhec')) );
 
 
 
 
 
 
 
602
  //$options_special_pages[] = array('avhec_special_pages[sp][category_group]', __('Category Archive', 'avh-ec'), 'dropdown', $dropdown_value, $dropdown_text, sprintf(__('Select which category to show on the %s page.','avh-ec'),__('category archive','avhec')));
603
- $options_special_pages[] = array ( 'avhec_special_pages[sp][day_group]', __('Daily Archive', 'avh-ec'), 'dropdown', $dropdown_value, $dropdown_text, sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('daily archive', 'avhec')) );
604
- $options_special_pages[] = array ( 'avhec_special_pages[sp][month_group]', __('Monthly Archive', 'avh-ec'), 'dropdown', $dropdown_value, $dropdown_text, sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('monthly archive', 'avhec')) );
605
- $options_special_pages[] = array ( 'avhec_special_pages[sp][year_group]', __('Yearly Archive', 'avh-ec'), 'dropdown', $dropdown_value, $dropdown_text, sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('yearly archive', 'avhec')) );
606
- $options_special_pages[] = array ( 'avhec_special_pages[sp][author_group]', __('Author Archive', 'avh-ec'), 'dropdown', $dropdown_value, $dropdown_text, sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('author archive', 'avhec')) );
607
- $options_special_pages[] = array ( 'avhec_special_pages[sp][search_group]', __('Search Page', 'avh-ec'), 'dropdown', $dropdown_value, $dropdown_text, sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('search', 'avhec')) );
608
-
609
- $data['sp'] = array ( 'form' => $options_special_pages, 'data' => $data_special_pages );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
610
 
611
  // This box can't be unselectd in the the Screen Options
612
  //add_meta_box( 'avhecBoxDonations', __( 'Donations', 'avh-ec' ), array (&$this, 'metaboxDonations' ), $this->hooks['menu_category_groups'], 'side', 'core' );
613
 
614
-
615
  echo '<div class="wrap avhec-metabox-wrap">';
616
  echo $this->displayIcon('index');
617
  echo '<h2>' . 'AVH Extended Categories - ' . __('Category Groups', 'avh-ec') . '</h2>';
@@ -632,119 +723,28 @@ class AVH_EC_Admin
632
  echo ' </div>'; //dashboard-widgets-wrap
633
  echo '</div>'; // wrap
634
 
635
-
636
  $this->printMetaboxGeneralNonces();
637
  $this->printMetaboxJS('grouped');
638
  $this->printAdminFooter();
639
  }
640
 
641
  /**
642
- * Metabox for Adding a group
643
- * @param $data
644
- */
645
- function metaboxCategoryGroupAdd ($data)
646
- {
647
- echo '<form name="avhec-addgroup" id="avhec-addgroup" method="POST" action="' . $this->getBackLink() . '" accept-charset="utf-8" >';
648
- wp_nonce_field('avh_ec_addgroup');
649
- echo $this->printOptions($data['add']['form'], $data['add']['data']);
650
- echo '<p class="submit"><input class="button" type="submit" name="addgroup" value="' . __('Add group', 'avh-ec') . '" /></p>';
651
- echo '</form>';
652
- }
653
-
654
- /**
655
- * Metabox for showing the groups as a list
656
- *
657
- * @param $data
658
- */
659
- function metaboxCategoryGroupList ($data)
660
- {
661
- echo '<form id="posts-filter" action="" method="get">';
662
-
663
- echo '<div class="clear"></div>';
664
-
665
- echo '<table class="widefat fixed" cellspacing="0">';
666
- echo '<thead>';
667
- echo '<tr>';
668
- print_column_headers('categories_group');
669
- echo '</tr>';
670
- echo '</thead>';
671
-
672
- echo '<tfoot>';
673
- echo '<tr>';
674
- print_column_headers('categories_group', false);
675
- echo '</tr>';
676
- echo '</tfoot>';
677
-
678
- echo '<tbody id="the-list" class="list:group">';
679
- $this->printCategoryGroupRows();
680
- echo '</tbody>';
681
- echo '</table>';
682
-
683
- echo '<br class="clear" />';
684
- echo '</form>';
685
-
686
- //echo '</div>';
687
- }
688
-
689
- /**
690
- * Metabox Category Group Edit
691
- *
692
- */
693
- function metaboxCategoryGroupEdit ($data)
694
- {
695
- echo '<form name="avhec-editgroup" id="avhec-editgroup" method="POST" action="' . $this->getBackLink() . '" accept-charset="utf-8" >';
696
- wp_nonce_field('avh_ec_editgroup');
697
- echo $this->printOptions($data['edit']['form'], $data['edit']['data']);
698
- echo '<input type="hidden" value="' . $data['edit']['data']['edit']['group_id'] . '" name="avhec-group_id" id="avhec-group_id">';
699
- echo '<p class="submit"><input class="button" type="submit" name="editgroup" value="' . __('Update group', 'avh-ec') . '" /></p>';
700
- echo '</form>';
701
- }
702
-
703
- /**
704
- * Metabox Category Group Special pages
705
- *
706
- */
707
- function metaboxCategoryGroupSpecialPages ($data)
708
- {
709
- echo '<form name="avhec-specialpagesgroup" id="avhec-specialpagesgroup" method="POST" action="' . $this->getBackLink() . '" accept-charset="utf-8" >';
710
- wp_nonce_field('avh_ec_specialpagesgroup');
711
- echo $this->printOptions($data['sp']['form'], $data['sp']['data']);
712
- echo '<p class="submit"><input class="button" type="submit" name="spgroup" value="' . __('Save settings', 'avh-ec') . '" /></p>';
713
- echo '</form>';
714
- }
715
-
716
- /**
717
- * Setup everything needed for the Manul Order page
718
- *
719
- */
720
- function actionLoadPageHook_ManualOrder ()
721
- {
722
-
723
- add_meta_box('avhecBoxManualOrder', __('Manually Order Categories', 'avh-ec'), array ( &$this, 'metaboxManualOrder' ), $this->hooks['menu_manual_order'], 'normal', 'core');
724
-
725
- add_screen_option('layout_columns', array ( 'max' => 1, 'default' => 1 ));
726
-
727
- // WordPress core Styles and Scripts
728
- wp_enqueue_script('common');
729
- wp_enqueue_script('wp-lists');
730
- wp_enqueue_script('postbox');
731
- wp_enqueue_script('jquery-ui-sortable');
732
- wp_enqueue_script('avhec-manualorder');
733
-
734
- // Plugin Style
735
- wp_enqueue_style('avhec-admin-css');
736
-
737
- }
738
-
739
- /**
740
- * Menu Page Manual Order
741
  *
742
  * @return none
743
  */
744
- function doMenuManualOrder ()
745
- {
746
  global $screen_layout_columns;
747
 
 
 
 
 
 
 
 
 
 
748
  $hide2 = '';
749
  switch ($screen_layout_columns) {
750
  case 2:
@@ -755,155 +755,236 @@ class AVH_EC_Admin
755
  $hide2 = 'display:none;';
756
  }
757
 
758
- echo '<div class="wrap">';
759
  echo $this->displayIcon('index');
760
- echo '<h2>' . 'AVH Extended Categories - ' . __('Manually Order Categories', 'avh-ec') . '</h2>';
761
-
762
- echo '<div class="metabox-holder">';
763
  echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
764
- do_meta_boxes($this->hooks['menu_manual_order'], 'normal', '');
765
  echo ' </div>';
766
- echo '</div>';
 
 
 
 
 
767
  echo '</div>'; // wrap
768
- echo '<div class="clear"></div>';
769
 
770
  $this->printMetaboxGeneralNonces();
771
- $this->printMetaboxJS('manual_order');
772
  $this->printAdminFooter();
773
  }
774
 
775
  /**
 
776
  *
777
- * Displays the Manual Order metabox.
778
- *
779
- * @author Andrew Charlton - original
780
- * @author Peter van der Does - modifications
781
  */
782
- function metaboxManualOrder ()
783
- {
784
- global $wpdb;
785
-
786
- $parentID = 0;
787
 
788
- if (isset($_POST['btnSubCats'])) {
789
- $parentID = $_POST['cats'];
790
- } elseif (isset($_POST['hdnParentID'])) {
791
- $parentID = $_POST['hdnParentID'];
792
  }
793
 
794
- if (isset($_POST['btnReturnParent'])) {
795
- $parentsParent = $wpdb->get_row($wpdb->prepare("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = %d", $_POST['hdnParentID']), ARRAY_N);
796
- $parentID = $parentsParent[0];
797
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
798
 
799
- $success = "";
800
- if (isset($_POST['btnOrderCats'])) {
801
- if (isset($_POST['hdnManualOrder']) && $_POST['hdnManualOrder'] != "") {
802
 
803
- $manualOrder = $_POST['hdnManualOrder'];
804
- $IDs = explode(",", $manualOrder);
805
- $result = count($IDs);
806
 
807
- for ($i = 0; $i < $result; $i ++) {
808
- $str = str_replace("id_", "", $IDs[$i]);
809
- $wpdb->query($wpdb->prepare("UPDATE $wpdb->terms SET avhec_term_order = %d WHERE term_id =%d", $i, $str));
810
- }
 
 
 
811
 
812
- $success = '<div id="message" class="updated fade"><p>' . __('Manual order of the categories successfully updated.', 'avh-ec') . '</p></div>';
813
- } else {
814
- $success = '<div id="message" class="updated fade"><p>' . __('An error occured, order has not been saved.', 'avh-ec') . '</p></div>';
 
 
 
 
 
 
 
 
 
 
 
 
 
815
  }
816
-
 
 
817
  }
 
818
 
819
- $subCategories = "";
820
- $results = $wpdb->get_results($wpdb->prepare("SELECT t.term_id, t.name FROM $wpdb->term_taxonomy tt, $wpdb->terms t, $wpdb->term_taxonomy tt2 WHERE tt.parent = %d AND tt.taxonomy = 'category' AND t.term_id = tt.term_id AND tt2.parent = tt.term_id GROUP BY t.term_id, t.name HAVING COUNT(*) > 0 ORDER BY t.avhec_term_order ASC", $parentID));
821
- foreach ($results as $row) {
822
- $subCategories .= "<option value='$row->term_id'>$row->name</option>";
 
823
  }
824
 
825
- echo '<div class="wrap">';
826
- echo '<form name="frmMyCatOrder" method="post" action="">';
827
- echo $success;
828
-
829
- echo '<h4>';
830
- _e('Order the categories', 'avh-ec');
831
- if ($parentID == 0) {
832
- echo ' at the Toplevel';
833
- } else {
834
- $categories = get_category_parents($parentID, false, ' » ');
835
- echo ' in the category ' . trim($categories, ' » ');
836
  }
837
- echo '</h4>';
838
- echo '<span class="description">';
839
- _e('Order the categories on this level by dragging and dropping them into the desired order.', 'avh-ec');
840
- echo '</span>';
841
- echo '<ul id="avhecManualOrder">';
842
- $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->terms t inner join $wpdb->term_taxonomy tt on t.term_id = tt.term_id WHERE taxonomy = 'category' and parent = %d ORDER BY avhec_term_order ASC", $parentID));
843
- foreach ($results as $row)
844
- echo "<li id='id_$row->term_id' class='lineitem menu-item-settings'>" . __($row->name) . "</li>";
845
 
846
- echo '</ul>';
847
- echo '<input type="submit" name="btnOrderCats" id="btnOrderCats" class="button-primary" value="' . __('Save Order', 'avh-ec') . '" onclick="javascript:orderCats(); return true;" />';
 
 
 
 
 
848
 
849
- if ($parentID != 0) {
850
- echo "<input type='submit' class='button' id='btnReturnParent' name='btnReturnParent' value='" . __('Return to parent category', 'avh-ec') . "' />";
 
 
 
 
 
 
851
  }
852
 
853
- echo '<strong id="updateText"></strong><br /><br />';
854
- if ($subCategories != "") {
 
 
 
 
 
855
 
856
- echo '<h4>';
857
- _e('Select Subcategory', 'avh-ec');
858
- echo '</h4>';
859
- echo '<select id="cats" name="cats">';
860
- echo $subCategories;
 
 
 
 
861
 
862
- echo '</select><input type="submit" name="btnSubCats" class="button" id="btnSubCats" value="' . __('Select', 'avh-ec') . '" />';
863
- echo '<span class="description">';
864
- _e('Choose a category from the drop down to order the subcategories in that category.', 'avh-ec');
865
- echo '</span>';
866
- }
 
867
 
868
- echo '<input type="hidden" id="hdnManualOrder" name="hdnManualOrder" />';
869
- echo '<input type="hidden" id="hdnParentID" name="hdnParentID" value="' . $parentID . '" /></form>';
870
- echo '</div>';
 
 
871
  }
872
 
873
  /**
874
- * Setup everything needed for the FAQ page
875
  *
 
876
  */
877
- function actionLoadPageHook_faq ()
878
- {
879
-
880
- add_meta_box('avhecBoxFAQ', __('F.A.Q.', 'avh-ec'), array ( &$this, 'metaboxFAQ' ), $this->hooks['menu_faq'], 'normal', 'core');
881
- add_meta_box('avhecBoxTranslation', __('Translation', 'avh-ec'), array ( &$this, 'metaboxTranslation' ), $this->hooks['menu_faq'], 'normal', 'core');
882
 
883
- add_screen_option('layout_columns', array ( 'max' => 2, 'default' => 2 ));
 
 
 
 
 
 
 
 
884
 
885
- // WordPress core Styles and Scripts
886
- wp_enqueue_script('common');
887
- wp_enqueue_script('wp-lists');
888
- wp_enqueue_script('postbox');
889
 
890
- // Plugin Style
891
- wp_enqueue_style('avhec-admin-css');
 
 
 
 
 
892
 
 
 
 
893
  }
894
 
895
  /**
896
- * Menu Page FAQ
897
  *
898
  * @return none
899
  */
900
- function doMenuFAQ ()
901
- {
902
  global $screen_layout_columns;
903
 
904
  // This box can't be unselectd in the the Screen Options
905
- // add_meta_box('avhecBoxAnnouncements', __('Announcements', 'avh-ec'), array ( &$this, 'metaboxAnnouncements' ), $this->hooks['menu_faq'], 'side', 'core');
906
- add_meta_box('avhecBoxDonations', __('Donations', 'avh-ec'), array ( &$this, 'metaboxDonations' ), $this->hooks['menu_faq'], 'side', 'core');
 
 
 
 
 
907
 
908
  $hide2 = '';
909
  switch ($screen_layout_columns) {
@@ -917,121 +998,330 @@ class AVH_EC_Admin
917
 
918
  echo '<div class="wrap avhec-metabox-wrap">';
919
  echo $this->displayIcon('index');
920
- echo '<h2>' . 'AVH Extended Categories - ' . __('F.A.Q', 'avh-ec') . '</h2>';
921
  echo ' <div id="dashboard-widgets-wrap">';
922
  echo ' <div id="dashboard-widgets" class="metabox-holder">';
923
  echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
924
- do_meta_boxes($this->hooks['menu_faq'], 'normal', '');
925
- echo ' </div>';
926
  echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n";
927
- do_meta_boxes($this->hooks['menu_faq'], 'side', '');
928
  echo ' </div>';
929
  echo ' </div>';
 
930
  echo '<br class="clear"/>';
931
  echo ' </div>'; //dashboard-widgets-wrap
932
  echo '</div>'; // wrap
933
 
934
-
935
  $this->printMetaboxGeneralNonces();
936
- $this->printMetaboxJS('faq');
937
  $this->printAdminFooter();
938
  }
939
 
940
  /**
941
- * Translation Metabox
942
- * @return unknown_type
 
 
 
 
 
 
943
  */
944
- function metaboxTranslation ()
945
- {
946
- $locale = apply_filters('plugin_locale', get_locale(), 'avh-ec');
947
- $available_locale['cs_CZ'] = array ( 'Czech - Čeština', 0 );
948
- $available_locale['nl_NL'] = array ( 'Dutch - Nederlands', 0 );
949
- $available_locale['de_DE'] = array ( 'German - Deutsch', 0 );
950
- $available_locale['el'] = array ( 'Greek - Čeština', 0 );
951
- $available_locale['id_ID'] = array ( 'Indonesian - Bahasa Indonesia - Čeština', 0 );
952
- $available_locale['it_IT'] = array ( 'Italian - Italiano', 1 );
953
- $available_locale['ru_RU'] = array ( 'Russian — Русский', 0 );
954
- $available_locale['es_ES'] = array ( 'Spanish - Español', 0 );
955
- $available_locale['sv_SE'] = array ( 'Swedish - Svenska', 0 );
956
- $available_locale['tr'] = array ( 'Turkish - Türkçe', 0 );
957
 
958
- echo '<div class="p">';
959
- echo __('This plugin is translated in several languages. Some of the languages might be incomplete. Please help to complete these translations or add a new language.', 'avh-ec') . '<br />';
960
 
961
- echo '</div>';
 
962
 
963
- echo '<div class="p">';
964
- echo '<span class="b">' . __('Available Languages', 'avh-ec') . '</span>';
965
- echo '<ul>';
966
- foreach ($available_locale as $key => $value) {
967
- echo '<li>';
968
- $complete = ($value[1] == 1 ? 'Complete' : 'Incomplete');
969
- echo $value[0] . ' (' . $key . ') - ' . $complete;
970
- echo '</li>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
971
  }
972
- echo '</ul>';
973
- echo '</div>';
974
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
975
  echo '<div class="p">';
976
- if ('en_US' != $locale & (! array_key_exists($locale, $available_locale))) {
977
- echo 'Currently the plugin is not available in your language (' . $locale . '). We\'re in the middle of changing the way you can help with translations. Keep an eye on the <a href="http:///blog.avirtualhome.com">website</a> for the announcement.';
 
 
 
 
978
  } else {
979
- echo 'We\'re in the middle of changing the way you can help with translations. Keep an eye on the <a href="http:///blog.avirtualhome.com">website</a> for the announcement.';
 
 
 
 
 
 
 
 
 
980
  }
981
  echo '</div>';
 
982
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
983
  }
984
 
 
 
985
  /**
986
  * Donation Metabox
 
987
  * @return unknown_type
988
  */
989
- function metaboxDonations ()
990
- {
991
  echo '<div class="p">';
992
- echo __('If you enjoy this plug-in please consider a donation. There are several ways you can show your appreciation.', 'avh-ec');
 
993
  echo '</div>';
994
 
995
  echo '<div class="p">';
996
  echo '<span class="b">Amazon</span><br />';
997
  echo __('If you decide to buy something from Amazon click the button.', 'avh-ec') . '</span><br />';
998
- echo '<a href="https://www.amazon.com/?tag=avh-donation-20" target="_blank" title="Amazon Homepage"><img alt="Amazon Button" src="' . $this->core->info['graphics_url'] . '/us_banner_logow_120x60.gif" /></a>';
 
 
999
  echo '</div>';
1000
 
1001
  echo '<div class="p">';
1002
- echo __('You can send me something from my ', 'avh-ec') . '<a href="http://www.amazon.com/registry/wishlist/1U3DTWZ72PI7W?tag=avh-donation-20">' . __('Amazon Wish List', 'avh-ec') . '</a>';
 
 
 
1003
  echo '</div>';
1004
 
1005
  echo '<div class="p">';
1006
  echo '<span class="b">' . __('Through Paypal.', 'avh-ec') . '</span><br />';
1007
- echo __('Click on the Donate button and you will be directed to Paypal where you can make your donation and you don\'t need to have a Paypal account to make a donation.', 'avh-ec') . '<br />';
 
1008
  echo '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=S85FXJ9EBHAF2&lc=US&item_name=AVH%20Plugins&item_number=fdas&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted" target="_blank" title="Donate">';
1009
  echo '<img src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" alt="Donate"/></a>';
1010
  echo '</div>';
1011
-
1012
  }
1013
 
1014
  /***
1015
  * F.A.Q Metabox
 
1016
  * @return none
1017
  */
1018
- function metaboxFAQ ()
1019
- {
1020
  echo '<div class="p">';
1021
  echo '<span class="b">' . __('What about support?', 'avh-ec') . '</span><br />';
1022
- echo __('I created a <a href="http://forums.avirtualhome.com" target="_blank">support site</a> where you can ask questions or request features.', 'avh-ec') . '<br />';
 
1023
  echo '</div>';
1024
 
1025
  echo '<div class="p">';
1026
  echo '<span class="b">' . __('What is depth selection?', 'avh-ec') . '</span><br />';
1027
- echo __('Starting with version 2.0 and WordPress 2.8 you can select how many levels deep you want to show your categories. This option only works when you select Show Hierarchy as well.', 'avh-ec') . '<br /><br />';
1028
- echo __('Here is how it works: Say you have 5 top level categories and each top level has a number of children. You could manually select all the Top Level categories you want to show but now you can do the following:', 'avh-ec') . '<br />';
1029
- echo __('You select to display all categories, select to Show hierarchy and select how many levels you want to show, in this case Toplevel only.', 'avh-ec') . '<br />';
 
 
 
1030
  echo '</div>';
1031
 
1032
  echo '<div class="p">';
1033
  echo '<span class="b">' . __('Multiple Category Groups', 'avh-ec') . '</span><br />';
1034
- echo __('The following is an explanation how assigning multiple groups to page/post works.', 'avh-ec') . '<br /><br />';
 
1035
  echo __('Lets say you have the following groups:', 'avh-ec');
1036
  echo '<ul>';
1037
  echo '<li>' . __('Free Time', 'avh-ec') . '</li>';
@@ -1039,7 +1329,8 @@ class AVH_EC_Admin
1039
  echo '<li>' . __('Movie', 'avh-ec') . '</li>';
1040
  echo '<li>' . __('Music', 'avh-ec') . '</li>';
1041
  echo '</ul>';
1042
- echo __('Setup several Category Group widgets and associated each widget with one or more groups.', 'avh-ec') . '<br />';
 
1043
  echo __('Widget 1 has association with Free Time', 'avh-ec') . '<br />';
1044
  echo __('Widget 2 has association with Theater, Movie and Music', 'avh-ec') . '<br />';
1045
  echo __('Widget 3 has association with Theater, Movie and Music', 'avh-ec') . '<br /><br />';
@@ -1061,138 +1352,186 @@ class AVH_EC_Admin
1061
  echo '<li>' . __('Widget 2: Shows categories of the Movie or Music group.', 'avh-ec') . '</li>';
1062
  echo '<li>' . __('Widget 3: Shows categories of the Music or Movie group.', 'avh-ec') . '</li>';
1063
  echo '</ul>';
1064
- echo __('Whether Widget 2 shows Movie or Music depends on the creation order of groups. If Widget 2 shows Movie, Widget 3 will show Music but if Widget 2 shows Music, Widget 3 will show Movie.', 'avh-ec') . '<br />';
1065
- echo '</div>';
1066
- }
1067
-
1068
- function metaboxAnnouncements ()
1069
- {
1070
- $php5 = version_compare('5.2', phpversion(), '<');
1071
- echo '<div class="p">';
1072
- echo '<span class="b">' . __('PHP4 Support', 'avh-ec') . '</span><br />';
1073
- echo __('The next major release of the plugin will no longer support PHP4.', 'avh-ec') . '<br />';
1074
- echo __('It will be written for PHP 5.2 and ', 'avh-ec');
1075
- if ($php5) {
1076
- echo __('your blog already runs the needed PHP version. When the new release comes out you can safely update.', 'avh-ec') . '<br />';
1077
- } else {
1078
- echo __('your blog still runs PHP4. When the new release comes out you can not use it.', 'avh-ec') . '<br />';
1079
- echo __('I don\'t have a timeline for the next version but consider contacting your host if PHP 5.2 is available.', 'avh-ec') . '<br />';
1080
- echo __('If your hosts doesn\'t offer PHP 5.2 you might want to consider switching hosts.', 'avh-ec') . '<br />';
1081
- echo __('A host to consider is ', 'avh-ec') . '<a href="http://www.lunarpages.com/id/pdoes" target="_blank">Lunarpages</a>';
1082
- echo __('I run my personal blog there and I am very happy with their services. You can get an account with unlimited bandwidth, storage and much more for a low price.', 'avh-ec');
1083
- }
1084
  echo '</div>';
1085
-
1086
  }
1087
 
1088
  /**
1089
- * Sets the amount of columns wanted for a particuler screen
1090
  *
1091
- * @WordPress filter screen_meta_screen
1092
- * @param $screen
1093
- * @return strings
1094
  */
 
 
1095
 
1096
- function filterScreenLayoutColumns ($columns, $screen)
1097
- {
1098
- switch ($screen) {
1099
- case $this->hooks['menu_overview']:
1100
- $columns[$this->hooks['menu_overview']] = 2;
1101
- break;
1102
- case $this->hooks['menu_general']:
1103
- $columns[$this->hooks['menu_general']] = 2;
1104
- break;
1105
- case $this->hooks['menu_category_groups']:
1106
- $columns[$this->hooks['menu_category_groups']] = 2;
1107
- break;
1108
- case $this->hooks['menu_faq']:
1109
- $columns[$this->hooks['menu_faq']] = 2;
1110
- break;
1111
 
 
 
 
 
1112
  }
1113
- return $columns;
1114
- }
1115
 
1116
- /**
1117
- * Adds Settings next to the plugin actions
1118
- *
1119
- * @WordPress Filter plugin_action_links_avh-amazon/avh-amazon.php
1120
- *
1121
- */
1122
- function filterPluginActions ($links, $file)
1123
- {
1124
- $settings_link = '<a href="admin.php?page=extended-categories-widget">' . __('Settings', 'avh-ec') . '</a>';
1125
- array_unshift($links, $settings_link); // before other links
1126
- return $links;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1127
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1128
  }
1129
 
1130
  /**
1131
- * Creates a new array for columns headers. Used in print_column_headers. The filter is called from get_column_headers
1132
- *
1133
- * @param $columns
1134
- * @return Array
1135
- * @see print_column_headers, get_column_headers
1136
  */
1137
- function filterManageCategoriesGroupColumns ($columns)
1138
- {
1139
- $categories_group_columns = array ( 'name' => __('Name', 'avh-ec'), 'slug' => __('Slug', 'avh-ec'), 'widget-title' => __('Widget Title', 'avh-ec'), 'description' => __('Description', 'avh-ec'), 'cat-in-group' => __('Categories in the group', 'avh-ec') );
1140
- return $categories_group_columns;
1141
  }
1142
 
1143
  /**
1144
- * When not using AJAX, this function is called when the deletion fails.
1145
  *
1146
- * @param string $text
1147
- * @param int $group_id
1148
- * @return string
1149
- * @WordPress Filter explain_nonce_$verb-$noun
1150
- * @see wp_explain_nonce
1151
  */
1152
- function filterExplainNonceDeleteGroup ($text, $group_id)
1153
- {
1154
- $group = get_term($group_id, $this->catgrp->taxonomy_name, OBJECT, 'display');
1155
-
1156
- $return = sprintf(__('Your attempt to delete this group: &#8220;%s&#8221; has failed.'), $group->name);
1157
- return ($return);
1158
- }
 
 
 
 
 
1159
 
1160
- ############## Admin WP Helper ##############
 
 
1161
 
 
1162
 
1163
- /**
1164
- * Get the backlink for forms
1165
- *
1166
- * @return strings
1167
- */
1168
- function getBackLink ()
1169
- {
1170
- $page = basename(__FILE__);
1171
- if (isset($_GET['page']) && ! empty($_GET['page'])) {
1172
- $page = preg_replace('[^a-zA-Z0-9\.\_\-]', '', $_GET['page']);
1173
  }
 
 
1174
 
1175
- if (function_exists("admin_url"))
1176
- return admin_url(basename($_SERVER["PHP_SELF"])) . "?page=" . $page;
1177
- else
1178
- return $_SERVER['PHP_SELF'] . "?page=" . $page;
 
 
 
 
 
1179
  }
1180
 
1181
  /**
1182
- * Print all Category Group rows
1183
- *
1184
- * @uses printCategoryGroupRow
1185
- *
1186
  */
1187
- function printCategoryGroupRows ()
1188
- {
1189
- $cat_groups = get_terms($this->catgrp->taxonomy_name, array ( 'hide_empty' => FALSE ));
1190
-
1191
- foreach ($cat_groups as $group) {
1192
- if ('none' != $group->slug) {
1193
- echo $this->printCategoryGroupRow($group->term_id, $group->term_taxonomy_id);
1194
- }
1195
- }
1196
  }
1197
 
1198
  /**
@@ -1202,30 +1541,38 @@ class AVH_EC_Admin
1202
  * @param int $group_term_id
1203
  * @param int $group_term_taxonomy_id
1204
  */
1205
- function printCategoryGroupRow ($group_term_id, $group_term_taxonomy_id)
1206
- {
1207
  static $row_class = '';
1208
 
1209
  $group = get_term($group_term_id, $this->catgrp->taxonomy_name, OBJECT, 'display');
1210
 
1211
- $no_edit[$this->catgrp->getTermIDBy('slug', 'all')] = 0;
1212
- $no_delete[$this->catgrp->getTermIDBy('slug', 'all')] = 0;
1213
 
1214
  if (current_user_can('manage_categories')) {
1215
- $actions = array ();
1216
- if (! array_key_exists($group->term_id, $no_edit)) {
1217
  $edit_link = "admin.php?page=avhec-grouped&amp;action=edit&amp;group_ID=$group->term_id";
1218
- $edit = "<a class='row-title' href='$edit_link' title='" . esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $group->name)) . "'>" . esc_attr($group->name) . '</a><br />';
 
 
 
 
1219
 
1220
  $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
1221
  } else {
1222
  $edit = esc_attr($group->name);
1223
  }
1224
- if (! (array_key_exists($group->term_id, $no_delete))) {
1225
- $actions['delete'] = "<a class='delete:the-list:group-$group->term_id submitdelete' href='" . wp_nonce_url("admin.php?page=avhec-grouped&amp;action=delete&amp;group_ID=$group->term_id", 'delete-avhecgroup_' . $group->term_id) . "'>" . __('Delete') . "</a>";
 
 
 
 
 
1226
  }
1227
  $action_count = count($actions);
1228
- $i = 0;
1229
  $edit .= '<div class="row-actions">';
1230
  foreach ($actions as $action => $link) {
1231
  ++ $i;
@@ -1238,25 +1585,26 @@ class AVH_EC_Admin
1238
  }
1239
 
1240
  $row_class = 'alternate' == $row_class ? '' : 'alternate';
1241
- $qe_data = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit');
1242
 
1243
  $output = "<tr id='group-$group->term_id' class='iedit $row_class'>";
1244
 
1245
  $columns = get_column_headers('categories_group');
1246
- $hidden = get_hidden_columns('categories_group');
1247
  foreach ($columns as $column_name => $column_display_name) {
1248
  $class = 'class="' . $column_name . ' column-' . $column_name . '"';
1249
 
1250
  $style = '';
1251
- if (in_array($column_name, $hidden))
1252
  $style = ' style="display:none;"';
 
1253
 
1254
  $attributes = $class . $style;
1255
 
1256
  switch ($column_name) {
1257
  case 'cb':
1258
  $output .= '<th scope="row" class="check-column">';
1259
- if (! (array_key_exists($group->term_id, $no_delete))) {
1260
  $output .= '<input type="checkbox" name="delete[]" value="' . $group->term_id . '" />';
1261
  } else {
1262
  $output .= "&nbsp;";
@@ -1272,7 +1620,7 @@ class AVH_EC_Admin
1272
  break;
1273
  case 'widget-title':
1274
  $title = $this->catgrp->getWidgetTitleForGroup($group->term_id);
1275
- if (! $title) {
1276
  $title = "&nbsp;";
1277
  }
1278
  $output .= '<td ' . $attributes . '>' . $title . '</td>';
@@ -1285,8 +1633,8 @@ class AVH_EC_Admin
1285
  $output .= "<td $attributes>" . apply_filters('editable_slug', $qe_data->slug) . "</td>";
1286
  break;
1287
  case 'cat-in-group':
1288
- $cats = $this->catgrp->getCategoriesFromGroup($group_term_id);
1289
- $catname = array ();
1290
  foreach ($cats as $cat_id) {
1291
  $catname[] = get_cat_name($cat_id);
1292
  }
@@ -1294,7 +1642,6 @@ class AVH_EC_Admin
1294
  $cat = implode(', ', $catname);
1295
  $output .= '<td ' . $attributes . '>' . $cat . '</td>';
1296
  break;
1297
-
1298
  }
1299
  }
1300
  $output .= '</tr>';
@@ -1302,18 +1649,31 @@ class AVH_EC_Admin
1302
  return $output;
1303
  }
1304
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1305
  /**
1306
  * Prints the general nonces, used by the AJAX
1307
  */
1308
- function printMetaboxGeneralNonces ()
1309
- {
1310
  echo '<form style="display:none" method="get" action="">';
1311
  echo '<p>';
1312
  wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1313
  wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1314
  echo '</p>';
1315
  echo '</form>';
1316
-
1317
  }
1318
 
1319
  /**
@@ -1321,9 +1681,8 @@ class AVH_EC_Admin
1321
  *
1322
  * @param $boxid
1323
  */
1324
- function printMetaboxJS ($boxid)
1325
- {
1326
- $a = $this->hooks['menu_' . $boxid];
1327
  echo '<script type="text/javascript">' . "\n";
1328
  echo ' //<![CDATA[' . "\n";
1329
  echo ' jQuery(document).ready( function($) {' . "\n";
@@ -1333,87 +1692,108 @@ class AVH_EC_Admin
1333
  echo ' });' . "\n";
1334
  echo ' //]]>' . "\n";
1335
  echo '</script>';
1336
-
1337
- }
1338
-
1339
- /**
1340
- * Display plugin Copyright
1341
- *
1342
- */
1343
- function printAdminFooter ()
1344
- {
1345
- echo '<p class="footer_avhec">';
1346
- printf('&copy; Copyright %d <a href="http://blog.avirtualhome.com/" title="My Thoughts">Peter van der Does</a> | AVH Extended Categories Version %s', date('Y'), $this->core->version);
1347
- echo '</p>';
1348
- }
1349
-
1350
- /**
1351
- * Display WP alert
1352
- *
1353
- */
1354
- function displayMessage ()
1355
- {
1356
- if ($this->message != '') {
1357
- $message = $this->message;
1358
- $status = $this->status;
1359
- $this->message = $this->status = ''; // Reset
1360
- }
1361
- if (isset($message)) {
1362
- $status = ($status != '') ? $status : 'updated fade';
1363
- echo '<div id="message" class="' . $status . '">';
1364
- echo '<p><strong>' . $message . '</strong></p></div>';
1365
- }
1366
  }
1367
 
1368
  /**
1369
  * Ouput formatted options
1370
  *
1371
  * @param array $option_data
 
1372
  * @return string
1373
  */
1374
- function printOptions ($option_data, $option_actual)
1375
- {
1376
  // Generate output
1377
  $output = '';
1378
  $output .= "\n" . '<table class="form-table avhec-options">' . "\n";
1379
  foreach ($option_data as $option) {
1380
- $section = substr($option[0], strpos($option[0], '[') + 1);
1381
- $section = substr($section, 0, strpos($section, ']['));
1382
  $option_key = rtrim($option[0], ']');
1383
  $option_key = substr($option_key, strpos($option_key, '][') + 2);
1384
  // Helper
1385
  if ($option[2] == 'helper') {
1386
- $output .= '<tr style="vertical-align: top;"><td class="helper" colspan="2">' . wp_filter_post_kses($option[4]) . '</td></tr>' . "\n";
 
 
 
1387
  continue;
1388
  }
1389
  switch ($option[2]) {
1390
  case 'checkbox':
1391
- $input_type = '<input type="checkbox" id="' . esc_attr($option[0]) . '" name="' . esc_attr($option[0]) . '" value="' . esc_attr($option[3]) . '" ' . $this->isChecked('1', $option_actual[$section][$option_key]) . ' />' . "\n";
 
 
 
 
 
 
 
 
 
1392
  $explanation = $option[4];
1393
  break;
1394
  case 'dropdown':
1395
  $selvalue = $option[3];
1396
- $seltext = $option[4];
1397
- $seldata = '';
1398
  foreach ((array) $selvalue as $key => $sel) {
1399
- $seldata .= '<option value="' . esc_attr($sel) . '" ' . (($option_actual[$section][$option_key] == $sel) ? 'selected="selected"' : '') . ' >' . esc_html(ucfirst($seltext[$key])) . '</option>' . "\n";
 
 
 
 
 
 
 
1400
  }
1401
- $input_type = '<select id="' . esc_attr($option[0]) . '" name="' . esc_attr($option[0]) . '">' . $seldata . '</select>' . "\n";
 
 
 
 
 
 
 
1402
  $explanation = $option[5];
1403
  break;
1404
  case 'text-color':
1405
- $input_type = '<input type="text" ' . (($option[3] > 1) ? ' style="width: 95%" ' : '') . 'id="' . esc_attr($option[0]) . '" name="' . esc_attr($option[0]) . '" value="' . esc_attr($option_actual[$section][$option_key]) . '" size="' . esc_attr($option[3]) . '" /><div class="box_color ' . esc_attr($option[0]) . '"></div>' . "\n";
 
 
 
 
 
 
 
 
 
 
 
 
 
1406
  $explanation = $option[4];
1407
  break;
1408
  case 'textarea':
1409
- $input_type = '<textarea rows="' . esc_attr($option[5]) . '" ' . (($option[3] > 1) ? ' style="width: 95%" ' : '') . 'id="' . esc_attr($option[0]) . '" name="' . esc_attr($option[0]) . '" size="' . esc_attr($option[3]) . '" />' . $option_actual[$section][$option_key] . '</textarea>';
 
 
 
 
 
 
 
 
 
 
 
 
1410
  $explanation = $option[4];
1411
  break;
1412
  case 'catlist':
1413
  ob_start();
1414
  echo '<div id="avhec-catlist">';
1415
  echo '<ul>';
1416
- wp_category_checklist(0, 0, $option_actual[$section][$option_key]);
1417
  echo '</ul>';
1418
  echo '</div>';
1419
  $input_type = ob_get_contents();
@@ -1422,7 +1802,18 @@ class AVH_EC_Admin
1422
  break;
1423
  case 'text':
1424
  default:
1425
- $input_type = '<input type="text" ' . (($option[3] > 1) ? ' style="width: 95%" ' : '') . 'id="' . esc_attr($option[0]) . '" name="' . esc_attr($option[0]) . '" value="' . esc_attr($option_actual[$section][$option_key]) . '" size="' . esc_attr($option[3]) . '" />' . "\n";
 
 
 
 
 
 
 
 
 
 
 
1426
  $explanation = $option[4];
1427
  break;
1428
  }
@@ -1432,59 +1823,21 @@ class AVH_EC_Admin
1432
  $extra = '<br /><span class="description">' . wp_filter_kses($explanation) . '</span>' . "\n";
1433
  }
1434
  // Output
1435
- $output .= '<tr style="vertical-align: top;"><th align="left" scope="row"><label for="' . esc_attr($option[0]) . '">' . wp_filter_kses($option[1]) . '</label></th><td>' . $input_type . ' ' . $extra . '</td></tr>' . "\n";
 
 
 
 
 
 
 
 
 
1436
  }
1437
  $output .= '</table>' . "\n";
1438
- return $output;
1439
- }
1440
-
1441
- /**
1442
- * Used in forms to set an option checked
1443
- *
1444
- * @param mixed $checked
1445
- * @param mixed $current
1446
- * @return strings
1447
- */
1448
- function isChecked ($checked, $current)
1449
- {
1450
- $return = '';
1451
- if ($checked == $current) {
1452
- $return = ' checked="checked"';
1453
- }
1454
- return $return;
1455
- }
1456
-
1457
- /**
1458
- * Displays the icon on the menu pages
1459
- *
1460
- * @param $icon
1461
- */
1462
- function displayIcon ($icon)
1463
- {
1464
- return ('<div class="icon32" id="icon-' . $icon . '"><br/></div>');
1465
- }
1466
-
1467
- /**
1468
- * Ajax Helper: inline delete of the groups
1469
- */
1470
- function ajaxDeleteGroup ()
1471
- {
1472
- $group_id = isset($_POST['id']) ? (int) $_POST['id'] : 0;
1473
- check_ajax_referer('delete-avhecgroup_' . $group_id);
1474
-
1475
- if (! current_user_can('manage_categories')) {
1476
- die('-1');
1477
- }
1478
- $check = $this->catgrp->getGroup($group_id);
1479
- if (false === $check) {
1480
- die('1');
1481
- }
1482
 
1483
- if ($this->catgrp->doDeleteGroup($group_id)) {
1484
- die('1');
1485
- } else {
1486
- die('0');
1487
- }
1488
  }
1489
  }
 
1490
  ?>
1
  <?php
2
 
3
+ class AVH_EC_Admin {
 
4
  /**
 
 
 
 
 
 
 
5
  * @var AVH_EC_Category_Group
6
  */
7
  var $catgrp;
8
+ /**
9
+ * @var AVH_EC_Core
10
+ */
11
+ var $core;
12
+ var $hooks = array();
13
  var $message;
14
 
15
  /**
16
  * PHP5 constructor
 
17
  */
18
+ function __construct() {
 
19
 
20
  // Initialize the plugin
21
+ $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core');
22
+ $this->catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
23
 
24
+ add_action('wp_ajax_delete-group', array(&$this, 'ajaxDeleteGroup'));
25
 
26
  // Admin menu
27
+ add_action('admin_init', array(&$this, 'actionAdminInit'));
28
+ add_action('admin_menu', array(&$this, 'actionAdminMenu'));
29
+ add_filter('plugin_action_links_extended-categories-widget/widget_extended_categories.php',
30
+ array(&$this, 'filterPluginActions'),
31
+ 10,
32
+ 2);
33
 
34
  // Actions used for editing posts
35
+ add_action('load-post.php', array(&$this, 'actionLoadPostPage'));
36
+ add_action('load-page.php', array(&$this, 'actionLoadPostPage'));
37
 
38
  // Actions related to adding and deletes categories
39
+ add_action("created_category", array($this, 'actionCreatedCategory'), 10, 2);
40
+ add_action("delete_category", array($this, 'actionDeleteCategory'), 10, 2);
41
 
42
+ add_filter('manage_categories_group_columns', array(&$this, 'filterManageCategoriesGroupColumns'));
43
+ add_filter('explain_nonce_delete-avhecgroup', array(&$this, 'filterExplainNonceDeleteGroup'), 10, 2);
44
 
45
  return;
46
  }
47
 
48
  /**
49
  * PHP4 Constructor
 
50
  */
51
+ function AVH_EC_Admin() {
 
52
  $this->__construct();
53
  }
54
 
55
+ function actionAdminInit() {
 
56
  if (is_admin() && isset($_GET['taxonomy']) && 'category' == $_GET['taxonomy']) {
57
+ add_action($_GET['taxonomy'] . '_edit_form', array(&$this, 'displayCategoryGroupForm'), 10, 2);
58
  }
59
+ add_action('edit_term', array(&$this, 'handleEditTerm'), 10, 3);
 
60
  }
61
 
62
  /**
63
+ * Add the Tools and Options to the Management and Options page repectively
64
  *
65
+ * @WordPress Action admin_menu
 
 
 
 
66
  */
67
+ function actionAdminMenu() {
 
68
 
69
+ // Register Style and Scripts
70
+ $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
71
+ wp_register_script('avhec-categorygroup-js',
72
+ AVHEC_PLUGIN_URL . '/js/avh-ec.categorygroup' . $suffix . '.js',
73
+ array('jquery'),
74
+ $this->core->version,
75
+ true);
76
+ wp_register_script('avhec-manualorder',
77
+ AVHEC_PLUGIN_URL . '/js/avh-ec.admin.manualorder' . $suffix . '.js',
78
+ array('jquery-ui-sortable'),
79
+ $this->core->version,
80
+ false);
81
+ wp_register_style('avhec-admin-css',
82
+ AVHEC_PLUGIN_URL . '/css/avh-ec.admin.css',
83
+ array('wp-admin'),
84
+ $this->core->version,
85
+ 'screen');
86
 
87
+ // Add menu system
88
+ $folder = $this->core->getBaseDirectory(AVHEC_PLUGIN_DIR);
89
+ add_menu_page('AVH Extended Categories',
90
+ 'AVH Extended Categories',
91
+ 'manage_options',
92
+ $folder,
93
+ array(&$this, 'doMenuOverview'));
94
+ $this->hooks['menu_overview'] = add_submenu_page($folder,
95
+ 'AVH Extended Categories: ' . __('Overview', 'avh-ec'),
96
+ __('Overview', 'avh-ec'),
97
+ 'manage_options',
98
+ $folder,
99
+ array(&$this, 'doMenuOverview'));
100
+ $this->hooks['menu_general'] = add_submenu_page($folder,
101
+ 'AVH Extended Categories: ' .
102
+ __('General Options', 'avh-ec'),
103
+ __('General Options', 'avh-ec'),
104
+ 'manage_options',
105
+ 'avhec-general',
106
+ array(&$this, 'doMenuGeneral'));
107
+ $this->hooks['menu_category_groups'] = add_submenu_page($folder,
108
+ 'AVH Extended Categories: ' .
109
+ __('Category Groups', 'avh-ec'),
110
+ __('Category Groups', 'avh-ec'),
111
+ 'manage_options',
112
+ 'avhec-grouped',
113
+ array(&$this, 'doMenuCategoryGroup'));
114
+ $this->hooks['menu_manual_order'] = add_submenu_page($folder,
115
+ 'AVH Extended Categories: ' .
116
+ __('Manually Order', 'avh-ec'),
117
+ __('Manually Order', 'avh-ec'),
118
+ 'manage_options',
119
+ 'avhec-manual-order',
120
+ array(&$this, 'doMenuManualOrder'));
121
+ $this->hooks['menu_faq'] = add_submenu_page($folder,
122
+ 'AVH Extended Categories:' . __('F.A.Q', 'avh-ec'),
123
+ __('F.A.Q', 'avh-ec'),
124
+ 'manage_options',
125
+ 'avhec-faq',
126
+ array(&$this, 'doMenuFAQ'));
127
 
128
+ // Add actions for menu pages
129
+ // Overview Menu
130
+ add_action('load-' . $this->hooks['menu_overview'], array(&$this, 'actionLoadPageHook_Overview'));
 
 
 
131
 
132
+ // General Options Menu
133
+ add_action('load-' . $this->hooks['menu_general'], array(&$this, 'actionLoadPageHook_General'));
 
134
 
135
+ // Category Groups Menu
136
+ add_action('load-' . $this->hooks['menu_category_groups'], array(&$this, 'actionLoadPageHook_CategoryGroup'));
 
 
 
 
 
 
 
 
 
 
 
 
137
 
138
+ // Manual Order Menu
139
+ add_action('load-' . $this->hooks['menu_manual_order'], array(&$this, 'actionLoadPageHook_ManualOrder'));
140
+
141
+ // FAQ Menu
142
+ add_action('load-' . $this->hooks['menu_faq'], array(&$this, 'actionLoadPageHook_faq'));
 
 
 
 
 
 
 
 
 
 
143
  }
144
 
145
  /**
146
  * When a category is created this function is called to add the new category to the group all
147
+ *
148
  * @param $term_id
149
  * @param $term_taxonomy_id
150
  */
151
+ function actionCreatedCategory($term_id, $term_taxonomy_id) {
 
152
  $group_id = $this->catgrp->getTermIDBy('slug', 'all');
153
  $this->catgrp->setCategoriesForGroup($group_id, (array) $term_id);
154
  }
157
  * When a category is deleted this function is called so the category is deleted from every group as well.
158
  *
159
  * @param object $term
160
+ * @param int $term_taxonomy_id
161
  */
162
+ function actionDeleteCategory($term_id, $term_taxonomy_id) {
 
163
  $this->catgrp->doDeleteCategoryFromGroup($term_id);
164
  }
165
 
166
  /**
167
+ * Setup everything needed for the Category Group page
 
 
168
  */
169
+ function actionLoadPageHook_CategoryGroup() {
170
+
171
+ // Add metaboxes
172
+ add_meta_box('avhecBoxCategoryGroupAdd',
173
+ __('Add Group', 'avh-ec'),
174
+ array(&$this, 'metaboxCategoryGroupAdd'),
175
+ $this->hooks['menu_category_groups'],
176
+ 'normal',
177
+ 'core');
178
+ add_meta_box('avhecBoxCategoryGroupList',
179
+ __('Group Overview', 'avh-ec'),
180
+ array(&$this, 'metaboxCategoryGroupList'),
181
+ $this->hooks['menu_category_groups'],
182
+ 'side',
183
+ 'core');
184
+ add_meta_box('avhecBoxCategoryGroupSpecialPages',
185
+ __('Special Pages', 'avh-ec'),
186
+ array(&$this, 'metaboxCategoryGroupSpecialPages'),
187
+ $this->hooks['menu_category_groups'],
188
+ 'normal',
189
+ 'core');
190
+
191
+ add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
192
+
193
+ // WordPress core Scripts
194
+ wp_enqueue_script('common');
195
+ wp_enqueue_script('wp-lists');
196
+ wp_enqueue_script('postbox');
197
+
198
+ // Plugin Scripts
199
+ wp_enqueue_script('avhec-categorygroup-js');
200
+
201
+ // Plugin Style
202
  wp_enqueue_style('avhec-admin-css');
203
  }
204
 
205
  /**
206
+ * Setup everything needed for the General Options page
 
 
 
207
  */
208
+ function actionLoadPageHook_General() {
209
+ // Add metaboxes
210
+ add_meta_box('avhecBoxOptions',
211
+ __('Options', 'avh-ec'),
212
+ array(&$this, 'metaboxOptions'),
213
+ $this->hooks['menu_general'],
214
+ 'normal',
215
+ 'core');
216
 
217
+ add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
 
 
 
 
218
 
219
+ // WordPress core Scripts
220
+ wp_enqueue_script('common');
221
+ wp_enqueue_script('wp-lists');
222
+ wp_enqueue_script('postbox');
 
 
 
 
223
 
224
+ // Plugin Style and Scripts
225
+ wp_enqueue_style('avhec-admin-css');
226
+ }
227
 
228
+ /**
229
+ * Setup everything needed for the Manul Order page
230
+ */
231
+ function actionLoadPageHook_ManualOrder() {
232
 
233
+ add_meta_box('avhecBoxManualOrder',
234
+ __('Manually Order Categories', 'avh-ec'),
235
+ array(&$this, 'metaboxManualOrder'),
236
+ $this->hooks['menu_manual_order'],
237
+ 'normal',
238
+ 'core');
239
 
240
+ add_screen_option('layout_columns', array('max' => 1, 'default' => 1));
 
241
 
242
+ // WordPress core Styles and Scripts
243
+ wp_enqueue_script('common');
244
+ wp_enqueue_script('wp-lists');
245
+ wp_enqueue_script('postbox');
246
+ wp_enqueue_script('jquery-ui-sortable');
247
+ wp_enqueue_script('avhec-manualorder');
248
+
249
+ // Plugin Style
250
+ wp_enqueue_style('avhec-admin-css');
251
  }
252
 
253
  /**
254
  * Setup everything needed for the Overview page
 
255
  */
256
+ function actionLoadPageHook_Overview() {
 
257
  // Add metaboxes
258
+ add_meta_box('avhecBoxCategoryGroupList',
259
+ __('Group Overview', 'avh-ec'),
260
+ array(&$this, 'metaboxCategoryGroupList'),
261
+ $this->hooks['menu_overview'],
262
+ 'normal',
263
+ 'core');
264
+ add_meta_box('avhecBoxTranslation',
265
+ __('Translation', 'avh-ec'),
266
+ array(&$this, 'metaboxTranslation'),
267
+ $this->hooks['menu_overview'],
268
+ 'normal',
269
+ 'core');
270
+
271
+ add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
272
 
273
  // WordPress core Scripts
274
  wp_enqueue_script('common');
283
  }
284
 
285
  /**
286
+ * Setup everything needed for the FAQ page
 
 
287
  */
288
+ function actionLoadPageHook_faq() {
289
+
290
+ add_meta_box('avhecBoxFAQ',
291
+ __('F.A.Q.', 'avh-ec'),
292
+ array(&$this, 'metaboxFAQ'),
293
+ $this->hooks['menu_faq'],
294
+ 'normal',
295
+ 'core');
296
+ add_meta_box('avhecBoxTranslation',
297
+ __('Translation', 'avh-ec'),
298
+ array(&$this, 'metaboxTranslation'),
299
+ $this->hooks['menu_faq'],
300
+ 'normal',
301
+ 'core');
302
+
303
+ add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
304
 
305
+ // WordPress core Styles and Scripts
306
+ wp_enqueue_script('common');
307
+ wp_enqueue_script('wp-lists');
308
+ wp_enqueue_script('postbox');
309
 
310
+ // Plugin Style
311
+ wp_enqueue_style('avhec-admin-css');
312
+ }
 
 
 
 
 
 
313
 
314
+ /**
315
+ * Enqueues the style on the post.php and page.php pages
316
+ *
317
+ * @WordPress Action load-$pagenow
318
+ */
319
+ function actionLoadPostPage() {
320
+ wp_enqueue_style('avhec-admin-css');
321
+ }
 
 
 
 
322
 
323
+ /**
324
+ * Ajax Helper: inline delete of the groups
325
+ */
326
+ function ajaxDeleteGroup() {
327
+ $group_id = isset($_POST['id']) ? (int) $_POST['id'] : 0;
328
+ check_ajax_referer('delete-avhecgroup_' . $group_id);
329
 
330
+ if ( ! current_user_can('manage_categories')) {
331
+ die('-1');
332
+ }
333
+ $check = $this->catgrp->getGroup($group_id);
334
+ if (false === $check) {
335
+ die('1');
336
+ }
337
 
338
+ if ($this->catgrp->doDeleteGroup($group_id)) {
339
+ die('1');
340
+ } else {
341
+ die('0');
342
+ }
343
  }
344
 
345
  /**
346
+ * Adds Category Group form
347
  *
348
+ * @WordPress action category_edit_form
349
+ *
350
+ * @param unknown_type $term
351
+ * @param unknown_type $taxonomy
352
  */
353
+ function displayCategoryGroupForm($term, $taxonomy) {
 
 
 
354
 
355
+ $current_selection = '';
356
+ $tax_meta = get_option($this->core->db_options_tax_meta);
357
+ if (isset($tax_meta[ $taxonomy ][ $term->term_id ])) {
358
+ $tax_meta = $tax_meta[ $taxonomy ][ $term->term_id ];
359
+ $current_selection = $tax_meta['category_group_term_id'];
360
+ }
361
 
362
+ if (empty($current_selection)) {
363
+ $current_group = $this->catgrp->getGroupByCategoryID($term->term_id);
364
+ $current_selection = $current_group->term_id;
365
+ }
366
 
367
+ $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false));
368
+ foreach ($cat_groups as $group) {
369
+ $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit');
370
+ $dropdown_value[] = $group->term_id;
371
+ $dropdown_text[] = $temp_cat->name;
372
+ }
373
 
374
+ foreach ($dropdown_value as $key => $sel) {
375
+ $seldata .= '<option value="' .
376
+ esc_attr($sel) .
377
+ '" ' .
378
+ (($current_selection == $sel) ? 'selected="selected"' : '') .
379
+ ' >' .
380
+ esc_html(ucfirst($dropdown_text[ $key ])) .
381
+ '</option>' .
382
+ "\n";
383
+ }
384
+
385
+ echo '<h3>AVH Extended Categories - Category Group Widget</h3>';
386
+ echo '<table class="form-table"><tbody>';
387
+ echo '<tr class="form-field">';
388
+ echo '<th valign="top" scope="row">';
389
+ echo '<label for="avhec_categorygroup">Category Group</label></th>';
390
+ echo '<td>';
391
+ echo '<select id="avhec_categorygroup" name="avhec_categorygroup">';
392
+ echo $seldata;
393
+ echo '</select>';
394
+ echo '<p class="description">Select the category group to show on the archive page.</p>';
395
+ echo '</td>';
396
+ echo '</tr>';
397
+ echo '</tbody></table>';
398
  }
399
 
400
  /**
401
+ * Displays the icon on the menu pages
402
  *
403
+ * @param $icon
404
  */
405
+ function displayIcon($icon) {
406
+ return ('<div class="icon32" id="icon-' . $icon . '"><br/></div>');
407
+ }
408
 
409
+ /**
410
+ * Display WP alert
411
+ */
412
+ function displayMessage() {
413
+ if ($this->message != '') {
414
+ $message = $this->message;
415
+ $status = $this->status;
416
+ $this->message = $this->status = ''; // Reset
417
+ }
418
+ if (isset($message)) {
419
+ $status = ($status != '') ? $status : 'updated fade';
420
+ echo '<div id="message" class="' . $status . '">';
421
+ echo '<p><strong>' . $message . '</strong></p></div>';
422
  }
423
+ }
424
 
425
+ /**
426
+ * Menu Page Category Group
427
+ *
428
+ * @return none
429
+ */
430
+ function doMenuCategoryGroup() {
431
+ global $screen_layout_columns;
432
 
433
+ $data_add_group_default = array('name' => '', 'slug' => '', 'widget_title' => '', 'description' => '');
434
+ $data_add_group_new = $data_add_group_default;
435
+
436
+ $options_add_group[] = array(
437
+ 'avhec_add_group[add][name]',
438
+ __('Group Name', 'avh-ec'),
439
+ 'text',
440
+ 20,
441
+ __('The name is used to identify the group.', 'avh-ec')
442
+ );
443
+ $options_add_group[] = array(
444
+ 'avhec_add_group[add][slug]',
445
+ __('Slug Group', 'avh-ec'),
446
+ 'text',
447
+ 20,
448
+ __('The “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.',
449
+ 'avh-ec')
450
+ );
451
+ $options_add_group[] = array(
452
+ 'avhec_add_group[add][widget_title]',
453
+ __('Widget Title', 'avh-ec'),
454
+ 'text',
455
+ 20,
456
+ __('When no title is given in the widget options, this will used as the title of the widget when this group is shown.',
457
+ 'avh-ec')
458
+ );
459
+ $options_add_group[] = array(
460
+ 'avhec_add_group[add][description]',
461
+ __('Description', 'avh-ec'),
462
+ 'textarea',
463
+ 40,
464
+ __('Description is not prominent by default.', 'avh-ec'),
465
+ 5
466
+ );
467
+
468
+ $options_edit_group[] = array(
469
+ 'avhec_edit_group[edit][name]',
470
+ __('Group Name', 'avh-ec'),
471
+ 'text',
472
+ 20,
473
+ __('The name is used to identify the group.', 'avh-ec')
474
+ );
475
+ $options_edit_group[] = array(
476
+ 'avhec_edit_group[edit][slug]',
477
+ __('Slug Group', 'avh-ec'),
478
+ 'text',
479
+ 20,
480
+ __('The “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.',
481
+ 'avh-ec')
482
+ );
483
+ $options_edit_group[] = array(
484
+ 'avhec_edit_group[edit][widget_title]',
485
+ __('Widget Title', 'avh-ec'),
486
+ 'text',
487
+ 20,
488
+ __('When no title is given in the widget options, this will used as the title of the widget when this group is shown.',
489
+ 'avh-ec')
490
+ );
491
+ $options_edit_group[] = array(
492
+ 'avhec_edit_group[edit][description]',
493
+ __('Description', 'avh-ec'),
494
+ 'textarea',
495
+ 40,
496
+ __('Description is not prominent by default.', 'avh-ec'),
497
+ 5
498
+ );
499
+ $options_edit_group[] = array(
500
+ 'avhec_edit_group[edit][categories]',
501
+ __('Categories', 'avh-ec'),
502
+ 'catlist',
503
+ 0,
504
+ __('Select categories to be included in the group.', 'avh-ec')
505
+ );
506
 
507
+ if (isset($_POST['addgroup'])) {
508
+ check_admin_referer('avh_ec_addgroup');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
509
 
510
  $formoptions = $_POST['avhec_add_group'];
511
 
512
+ $data_add_group_new['name'] = $formoptions['add']['name'];
513
+ $data_add_group_new['slug'] = empty($formoptions['add']['slug']) ? sanitize_title($data_add_group_new['name']) : sanitize_title($formoptions['add']['slug']);
514
  $data_add_group_new['widget_title'] = $formoptions['add']['widget_title'];
515
+ $data_add_group_new['description'] = $formoptions['add']['description'];
516
 
517
  $id = $this->catgrp->getTermIDBy('slug', $data_add_group_new['slug']);
518
+ if ( ! $id) {
519
+ $group_id = $this->catgrp->doInsertGroup($data_add_group_new['name'],
520
+ array(
521
+ 'description' => $data_add_group_new['description'],
522
+ 'slug' => $data_add_group_new['slug']
523
+ ),
524
+ $data_add_group_new['widget_title']);
525
  $this->catgrp->setCategoriesForGroup($group_id);
526
+ $this->message = __('Category group saved', 'avh-ec');
527
+ $this->status = 'updated fade';
528
  $data_add_group_new = $data_add_group_default;
 
529
  } else {
530
+ $group = $this->catgrp->getGroup($id);
531
  $this->message = __('Category group conflicts with ', 'avh-ec') . $group->name;
532
  $this->message .= '<br />' . __('Same slug is used. ', 'avh-ec');
533
  $this->status = 'error';
 
534
  }
535
  $this->displayMessage();
536
  }
537
  $data_add_group['add'] = $data_add_group_new;
538
+ $data['add'] = array('form' => $options_add_group, 'data' => $data_add_group);
539
 
540
  if (isset($_GET['action'])) {
541
  $action = $_GET['action'];
542
 
543
  switch ($action) {
544
  case 'edit':
545
+ $group_id = (int) $_GET['group_ID'];
546
+ $group = $this->catgrp->getGroup($group_id);
547
  $widget_title = $this->catgrp->getWidgetTitleForGroup($group_id);
548
+ $cats = $this->catgrp->getCategoriesFromGroup($group_id);
549
+
550
+ $data_edit_group['edit'] = array(
551
+ 'group_id' => $group_id,
552
+ 'name' => $group->name,
553
+ 'slug' => $group->slug,
554
+ 'widget_title' => $widget_title,
555
+ 'description' => $group->description,
556
+ 'categories' => $cats
557
+ );
558
+ $data['edit'] = array('form' => $options_edit_group, 'data' => $data_edit_group);
559
+
560
+ add_meta_box('avhecBoxCategoryGroupEdit',
561
+ __('Edit Group', 'avh-ec') . ': ' . $group->name,
562
+ array(&$this, 'metaboxCategoryGroupEdit'),
563
+ $this->hooks['menu_category_groups'],
564
+ 'normal',
565
+ 'low');
566
  break;
567
  case 'delete':
568
+ if ( ! isset($_GET['group_ID'])) {
569
  wp_redirect($this->getBackLink());
570
  exit();
571
  }
573
  $group_id = (int) $_GET['group_ID'];
574
  check_admin_referer('delete-avhecgroup_' . $group_id);
575
 
576
+ if ( ! current_user_can('manage_categories')) {
577
  wp_die(__('Cheatin&#8217; uh?'));
578
  }
579
  $this->catgrp->doDeleteGroup($group_id);
587
  if (isset($_POST['editgroup'])) {
588
  check_admin_referer('avh_ec_editgroup');
589
 
590
+ $formoptions = $_POST['avhec_edit_group'];
591
  $selected_categories = $_POST['post_category'];
592
 
593
  $group_id = (int) $_POST['avhec-group_id'];
594
+ $result = $this->catgrp->doUpdateGroup($group_id,
595
+ array(
596
+ 'name' => $formoptions['edit']['name'],
597
+ 'slug' => $formoptions['edit']['slug'],
598
+ 'description' => $formoptions['edit']['description']
599
+ ),
600
+ $selected_categories,
601
+ $formoptions['edit']['widget_title']);
602
  switch ($result) {
603
  case 1:
604
  $this->message = __('Category group updated', 'avh-ec');
605
+ $this->status = 'updated fade';
606
  break;
607
  case 0:
608
  $this->message = __('Category group not updated', 'avh-ec');
611
  break;
612
  case - 1:
613
  $this->message = __('Unknown category group', 'avh-ec');
614
+ $this->status = 'error';
615
  break;
616
  }
617
  $this->displayMessage();
633
  check_admin_referer('avh_ec_specialpagesgroup');
634
 
635
  $formoptions = $_POST['avhec_special_pages'];
636
+ $formdata = $formoptions['sp'];
637
  foreach ($formdata as $key => $value) {
638
+ $data_special_pages_new[ $key ] = $value;
639
  }
640
  $this->core->options['sp_cat_group'] = $data_special_pages_new;
641
  $this->core->saveOptions($this->core->options);
 
642
  }
643
  $data_special_pages['sp'] = $data_special_pages_new;
644
+ $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false));
645
 
646
  foreach ($cat_groups as $group) {
647
+ $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit');
648
  $dropdown_value[] = $group->term_id;
649
+ $dropdown_text[] = $temp_cat->name;
650
  }
651
+ $options_special_pages[] = array(
652
+ 'avhec_special_pages[sp][home_group]',
653
+ __('Home page', 'avh-ec'),
654
+ 'dropdown',
655
+ $dropdown_value,
656
+ $dropdown_text,
657
+ sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('home', 'avhec'))
658
+ );
659
  //$options_special_pages[] = array('avhec_special_pages[sp][category_group]', __('Category Archive', 'avh-ec'), 'dropdown', $dropdown_value, $dropdown_text, sprintf(__('Select which category to show on the %s page.','avh-ec'),__('category archive','avhec')));
660
+ $options_special_pages[] = array(
661
+ 'avhec_special_pages[sp][day_group]',
662
+ __('Daily Archive', 'avh-ec'),
663
+ 'dropdown',
664
+ $dropdown_value,
665
+ $dropdown_text,
666
+ sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('daily archive', 'avhec'))
667
+ );
668
+ $options_special_pages[] = array(
669
+ 'avhec_special_pages[sp][month_group]',
670
+ __('Monthly Archive', 'avh-ec'),
671
+ 'dropdown',
672
+ $dropdown_value,
673
+ $dropdown_text,
674
+ sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('monthly archive', 'avhec'))
675
+ );
676
+ $options_special_pages[] = array(
677
+ 'avhec_special_pages[sp][year_group]',
678
+ __('Yearly Archive', 'avh-ec'),
679
+ 'dropdown',
680
+ $dropdown_value,
681
+ $dropdown_text,
682
+ sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('yearly archive', 'avhec'))
683
+ );
684
+ $options_special_pages[] = array(
685
+ 'avhec_special_pages[sp][author_group]',
686
+ __('Author Archive', 'avh-ec'),
687
+ 'dropdown',
688
+ $dropdown_value,
689
+ $dropdown_text,
690
+ sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('author archive', 'avhec'))
691
+ );
692
+ $options_special_pages[] = array(
693
+ 'avhec_special_pages[sp][search_group]',
694
+ __('Search Page', 'avh-ec'),
695
+ 'dropdown',
696
+ $dropdown_value,
697
+ $dropdown_text,
698
+ sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('search', 'avhec'))
699
+ );
700
+
701
+ $data['sp'] = array('form' => $options_special_pages, 'data' => $data_special_pages);
702
 
703
  // This box can't be unselectd in the the Screen Options
704
  //add_meta_box( 'avhecBoxDonations', __( 'Donations', 'avh-ec' ), array (&$this, 'metaboxDonations' ), $this->hooks['menu_category_groups'], 'side', 'core' );
705
 
 
706
  echo '<div class="wrap avhec-metabox-wrap">';
707
  echo $this->displayIcon('index');
708
  echo '<h2>' . 'AVH Extended Categories - ' . __('Category Groups', 'avh-ec') . '</h2>';
723
  echo ' </div>'; //dashboard-widgets-wrap
724
  echo '</div>'; // wrap
725
 
 
726
  $this->printMetaboxGeneralNonces();
727
  $this->printMetaboxJS('grouped');
728
  $this->printAdminFooter();
729
  }
730
 
731
  /**
732
+ * Menu Page FAQ
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
733
  *
734
  * @return none
735
  */
736
+ function doMenuFAQ() {
 
737
  global $screen_layout_columns;
738
 
739
+ // This box can't be unselectd in the the Screen Options
740
+ // add_meta_box('avhecBoxAnnouncements', __('Announcements', 'avh-ec'), array ( &$this, 'metaboxAnnouncements' ), $this->hooks['menu_faq'], 'side', 'core');
741
+ add_meta_box('avhecBoxDonations',
742
+ __('Donations', 'avh-ec'),
743
+ array(&$this, 'metaboxDonations'),
744
+ $this->hooks['menu_faq'],
745
+ 'side',
746
+ 'core');
747
+
748
  $hide2 = '';
749
  switch ($screen_layout_columns) {
750
  case 2:
755
  $hide2 = 'display:none;';
756
  }
757
 
758
+ echo '<div class="wrap avhec-metabox-wrap">';
759
  echo $this->displayIcon('index');
760
+ echo '<h2>' . 'AVH Extended Categories - ' . __('F.A.Q', 'avh-ec') . '</h2>';
761
+ echo ' <div id="dashboard-widgets-wrap">';
762
+ echo ' <div id="dashboard-widgets" class="metabox-holder">';
763
  echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
764
+ do_meta_boxes($this->hooks['menu_faq'], 'normal', '');
765
  echo ' </div>';
766
+ echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n";
767
+ do_meta_boxes($this->hooks['menu_faq'], 'side', '');
768
+ echo ' </div>';
769
+ echo ' </div>';
770
+ echo '<br class="clear"/>';
771
+ echo ' </div>'; //dashboard-widgets-wrap
772
  echo '</div>'; // wrap
 
773
 
774
  $this->printMetaboxGeneralNonces();
775
+ $this->printMetaboxJS('faq');
776
  $this->printAdminFooter();
777
  }
778
 
779
  /**
780
+ * Menu Page General Options
781
  *
782
+ * @return none
 
 
 
783
  */
784
+ function doMenuGeneral() {
785
+ global $screen_layout_columns;
 
 
 
786
 
787
+ $groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false));
788
+ foreach ($groups as $group) {
789
+ $group_id[] = $group->term_id;
790
+ $groupname[] = $group->name;
791
  }
792
 
793
+ $options_general[] = array(
794
+ 'avhec[general][alternative_name_select_category]',
795
+ __('<em>Select Category</em> Alternative', 'avh-ec'),
796
+ 'text',
797
+ 20,
798
+ __('Alternative text for Select Category.', 'avh-ec')
799
+ );
800
+ $options_general[] = array(
801
+ 'avhec[cat_group][home_group]',
802
+ 'Home Group',
803
+ 'dropdown',
804
+ $group_id,
805
+ $groupname,
806
+ __('Select which group to show on the home page.', 'avh-ec') .
807
+ '<br />' .
808
+ __('Selecting the group \'none\' will not show the widget on the page.', 'avh-ec')
809
+ );
810
+ $options_general[] = array(
811
+ 'avhec[cat_group][no_group]',
812
+ 'Nonexistence Group',
813
+ 'dropdown',
814
+ $group_id,
815
+ $groupname,
816
+ __('Select which group to show when there is no group associated with the post.', 'avh-ec') .
817
+ '<br />' .
818
+ __('Selecting the group \'none\' will not show the widget on the page.', 'avh-ec')
819
+ );
820
+ $options_general[] = array(
821
+ 'avhec[cat_group][default_group]',
822
+ 'Default Group',
823
+ 'dropdown',
824
+ $group_id,
825
+ $groupname,
826
+ __('Select which group will be the default group when editing a post.', 'avh-ec') .
827
+ '<br />' .
828
+ __('Selecting the group \'none\' will not show the widget on the page.', 'avh-ec')
829
+ );
830
 
831
+ if (isset($_POST['updateoptions'])) {
832
+ check_admin_referer('avh_ec_generaloptions');
 
833
 
834
+ $formoptions = $_POST['avhec'];
835
+ $options = $this->core->getOptions();
 
836
 
837
+ //$all_data = array_merge( $options_general );
838
+ $all_data = $options_general;
839
+ foreach ($all_data as $option) {
840
+ $section = substr($option[0], strpos($option[0], '[') + 1);
841
+ $section = substr($section, 0, strpos($section, ']['));
842
+ $option_key = rtrim($option[0], ']');
843
+ $option_key = substr($option_key, strpos($option_key, '][') + 2);
844
 
845
+ switch ($section) {
846
+ case 'general':
847
+ case 'cat_group':
848
+ $current_value = $options[ $section ][ $option_key ];
849
+ break;
850
+ }
851
+ // Every field in a form is set except unchecked checkboxes. Set an unchecked checkbox to 0.
852
+ $newval = (isset($formoptions[ $section ][ $option_key ]) ? esc_attr($formoptions[ $section ][ $option_key ]) : 0);
853
+ if ($newval != $current_value) { // Only process changed fields.
854
+ switch ($section) {
855
+ case 'general':
856
+ case 'cat_group':
857
+ $options[ $section ][ $option_key ] = $newval;
858
+ break;
859
+ }
860
+ }
861
  }
862
+ $this->core->saveOptions($options);
863
+ $this->message = __('Options saved', 'avh-ec');
864
+ $this->status = 'updated fade';
865
  }
866
+ $this->displayMessage();
867
 
868
+ $actual_options = $this->core->getOptions();
869
+ foreach ($actual_options['cat_group'] as $key => $value) {
870
+ if ( ! (in_array($value, (array) $group_id))) {
871
+ $actual_options['cat_group'][ $key ] = $this->catgrp->getTermIDBy('slug', 'none');
872
+ }
873
  }
874
 
875
+ $hide2 = '';
876
+ switch ($screen_layout_columns) {
877
+ case 2:
878
+ $width = 'width:49%;';
879
+ break;
880
+ default:
881
+ $width = 'width:98%;';
882
+ $hide2 = 'display:none;';
 
 
 
883
  }
884
+ $data['options_general'] = $options_general;
885
+ $data['actual_options'] = $actual_options;
 
 
 
 
 
 
886
 
887
+ // This box can't be unselectd in the the Screen Options
888
+ add_meta_box('avhecBoxDonations',
889
+ __('Donations', 'avh-ec'),
890
+ array(&$this, 'metaboxDonations'),
891
+ $this->hooks['menu_general'],
892
+ 'side',
893
+ 'core');
894
 
895
+ $hide2 = '';
896
+ switch ($screen_layout_columns) {
897
+ case 2:
898
+ $width = 'width:49%;';
899
+ break;
900
+ default:
901
+ $width = 'width:98%;';
902
+ $hide2 = 'display:none;';
903
  }
904
 
905
+ echo '<div class="wrap avhec-metabox-wrap">';
906
+ echo $this->displayIcon('index');
907
+ echo '<h2>' . 'AVH Extended Categories - ' . __('General Options', 'avh-ec') . '</h2>';
908
+ echo '<form name="avhec-generaloptions" id="avhec-generaloptions" method="POST" action="' .
909
+ admin_url('admin.php?page=avhec-general') .
910
+ '" accept-charset="utf-8" >';
911
+ wp_nonce_field('avh_ec_generaloptions');
912
 
913
+ echo ' <div id="dashboard-widgets-wrap">';
914
+ echo ' <div id="dashboard-widgets" class="metabox-holder">';
915
+ echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
916
+ do_meta_boxes($this->hooks['menu_general'], 'normal', $data);
917
+ echo " </div>";
918
+ echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n";
919
+ do_meta_boxes($this->hooks['menu_general'], 'side', $data);
920
+ echo ' </div>';
921
+ echo ' </div>';
922
 
923
+ echo '<br class="clear"/>';
924
+ echo ' </div>'; //dashboard-widgets-wrap
925
+ echo '<p class="submit"><input class="button" type="submit" name="updateoptions" value="' .
926
+ __('Save Changes', 'avhf-ec') .
927
+ '" /></p>';
928
+ echo '</form>';
929
 
930
+ echo '</div>'; // wrap
931
+
932
+ $this->printMetaboxGeneralNonces();
933
+ $this->printMetaboxJS('general');
934
+ $this->printAdminFooter();
935
  }
936
 
937
  /**
938
+ * Menu Page Manual Order
939
  *
940
+ * @return none
941
  */
942
+ function doMenuManualOrder() {
943
+ global $screen_layout_columns;
 
 
 
944
 
945
+ $hide2 = '';
946
+ switch ($screen_layout_columns) {
947
+ case 2:
948
+ $width = 'width:49%;';
949
+ break;
950
+ default:
951
+ $width = 'width:98%;';
952
+ $hide2 = 'display:none;';
953
+ }
954
 
955
+ echo '<div class="wrap">';
956
+ echo $this->displayIcon('index');
957
+ echo '<h2>' . 'AVH Extended Categories - ' . __('Manually Order Categories', 'avh-ec') . '</h2>';
 
958
 
959
+ echo '<div class="metabox-holder">';
960
+ echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
961
+ do_meta_boxes($this->hooks['menu_manual_order'], 'normal', '');
962
+ echo ' </div>';
963
+ echo '</div>';
964
+ echo '</div>'; // wrap
965
+ echo '<div class="clear"></div>';
966
 
967
+ $this->printMetaboxGeneralNonces();
968
+ $this->printMetaboxJS('manual_order');
969
+ $this->printAdminFooter();
970
  }
971
 
972
  /**
973
+ * Menu Page Overview
974
  *
975
  * @return none
976
  */
977
+ function doMenuOverview() {
 
978
  global $screen_layout_columns;
979
 
980
  // This box can't be unselectd in the the Screen Options
981
+ //add_meta_box('avhecBoxAnnouncements', __('Announcements', 'avh-ec'), array ( &$this, 'metaboxAnnouncements' ), $this->hooks['menu_overview'], 'side', '');
982
+ add_meta_box('avhecBoxDonations',
983
+ __('Donations', 'avh-ec'),
984
+ array(&$this, 'metaboxDonations'),
985
+ $this->hooks['menu_overview'],
986
+ 'side',
987
+ '');
988
 
989
  $hide2 = '';
990
  switch ($screen_layout_columns) {
998
 
999
  echo '<div class="wrap avhec-metabox-wrap">';
1000
  echo $this->displayIcon('index');
1001
+ echo '<h2>' . 'AVH Extended Categories - ' . __('Overview', 'avh-ec') . '</h2>';
1002
  echo ' <div id="dashboard-widgets-wrap">';
1003
  echo ' <div id="dashboard-widgets" class="metabox-holder">';
1004
  echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
1005
+ do_meta_boxes($this->hooks['menu_overview'], 'normal', '');
1006
+ echo " </div>";
1007
  echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n";
1008
+ do_meta_boxes($this->hooks['menu_overview'], 'side', '');
1009
  echo ' </div>';
1010
  echo ' </div>';
1011
+
1012
  echo '<br class="clear"/>';
1013
  echo ' </div>'; //dashboard-widgets-wrap
1014
  echo '</div>'; // wrap
1015
 
 
1016
  $this->printMetaboxGeneralNonces();
1017
+ $this->printMetaboxJS('overview');
1018
  $this->printAdminFooter();
1019
  }
1020
 
1021
  /**
1022
+ * When not using AJAX, this function is called when the deletion fails.
1023
+ *
1024
+ * @param string $text
1025
+ * @param int $group_id
1026
+ *
1027
+ * @return string
1028
+ * @WordPress Filter explain_nonce_$verb-$noun
1029
+ * @see wp_explain_nonce
1030
  */
1031
+ function filterExplainNonceDeleteGroup($text, $group_id) {
1032
+ $group = get_term($group_id, $this->catgrp->taxonomy_name, OBJECT, 'display');
 
 
 
 
 
 
 
 
 
 
 
1033
 
1034
+ $return = sprintf(__('Your attempt to delete this group: &#8220;%s&#8221; has failed.'), $group->name);
 
1035
 
1036
+ return ($return);
1037
+ }
1038
 
1039
+ /**
1040
+ * Creates a new array for columns headers. Used in print_column_headers. The filter is called from
1041
+ * get_column_headers
1042
+ *
1043
+ * @param $columns
1044
+ *
1045
+ * @return Array
1046
+ * @see print_column_headers, get_column_headers
1047
+ */
1048
+ function filterManageCategoriesGroupColumns($columns) {
1049
+ $categories_group_columns = array(
1050
+ 'name' => __('Name', 'avh-ec'),
1051
+ 'slug' => __('Slug', 'avh-ec'),
1052
+ 'widget-title' => __('Widget Title', 'avh-ec'),
1053
+ 'description' => __('Description', 'avh-ec'),
1054
+ 'cat-in-group' => __('Categories in the group', 'avh-ec')
1055
+ );
1056
+
1057
+ return $categories_group_columns;
1058
+ }
1059
+
1060
+ /**
1061
+ * Adds Settings next to the plugin actions
1062
+ *
1063
+ * @WordPress Filter plugin_action_links_avh-amazon/avh-amazon.php
1064
+ */
1065
+ function filterPluginActions($links, $file) {
1066
+ $settings_link = '<a href="admin.php?page=extended-categories-widget">' . __('Settings', 'avh-ec') . '</a>';
1067
+ array_unshift($links, $settings_link); // before other links
1068
+ return $links;
1069
+ }
1070
+
1071
+ /**
1072
+ * Sets the amount of columns wanted for a particuler screen
1073
+ *
1074
+ * @WordPress filter screen_meta_screen
1075
+ *
1076
+ * @param $screen
1077
+ *
1078
+ * @return strings
1079
+ */
1080
+
1081
+ function filterScreenLayoutColumns($columns, $screen) {
1082
+ switch ($screen) {
1083
+ case $this->hooks['menu_overview']:
1084
+ $columns[ $this->hooks['menu_overview'] ] = 2;
1085
+ break;
1086
+ case $this->hooks['menu_general']:
1087
+ $columns[ $this->hooks['menu_general'] ] = 2;
1088
+ break;
1089
+ case $this->hooks['menu_category_groups']:
1090
+ $columns[ $this->hooks['menu_category_groups'] ] = 2;
1091
+ break;
1092
+ case $this->hooks['menu_faq']:
1093
+ $columns[ $this->hooks['menu_faq'] ] = 2;
1094
+ break;
1095
  }
 
 
1096
 
1097
+ return $columns;
1098
+ }
1099
+
1100
+ /**
1101
+ * Get the backlink for forms
1102
+ *
1103
+ * @return string
1104
+ */
1105
+ function getBackLink() {
1106
+ $page = basename(__FILE__);
1107
+ if (isset($_GET['page']) && ! empty($_GET['page'])) {
1108
+ $page = preg_replace('[^a-zA-Z0-9\.\_\-]', '', $_GET['page']);
1109
+ }
1110
+
1111
+ if (function_exists("admin_url")) {
1112
+ return admin_url(basename($_SERVER["PHP_SELF"])) . "?page=" . $page;
1113
+ } else {
1114
+ return $_SERVER['PHP_SELF'] . "?page=" . $page;
1115
+ }
1116
+ }
1117
+
1118
+ /**
1119
+ * Saves the association Category - Category Group fron the edit taxonomy page
1120
+ *
1121
+ * @WordPress action edit_form.
1122
+ *
1123
+ * @param unknown_type $term_id
1124
+ * @param unknown_type $tt_id
1125
+ * @param unknown_type $taxonomy
1126
+ */
1127
+ function handleEditTerm($term_id, $tt_id, $taxonomy) {
1128
+ $tax_meta = get_option($this->core->db_options_tax_meta);
1129
+ if (isset($_POST['avhec_categorygroup']) &&
1130
+ isset($tax_meta[ $taxonomy ][ $term_id ]['category_group_term_id']) &&
1131
+ $tax_meta[ $taxonomy ][ $term_id ]['category_group_term_id'] != $_POST['avhec_categorygroup']
1132
+ ) {
1133
+ $tax_meta[ $taxonomy ][ $term_id ]['category_group_term_id'] = $_POST['avhec_categorygroup'];
1134
+ update_option($this->core->db_options_tax_meta, $tax_meta);
1135
+ }
1136
+ }
1137
+
1138
+ /**
1139
+ * Used in forms to set an option checked
1140
+ *
1141
+ * @param mixed $checked
1142
+ * @param mixed $current
1143
+ *
1144
+ * @return string
1145
+ */
1146
+ function isChecked($checked, $current) {
1147
+ $return = '';
1148
+ if ($checked == $current) {
1149
+ $return = ' checked="checked"';
1150
+ }
1151
+
1152
+ return $return;
1153
+ }
1154
+
1155
+ function metaboxAnnouncements() {
1156
+ $php5 = version_compare('5.2', phpversion(), '<');
1157
  echo '<div class="p">';
1158
+ echo '<span class="b">' . __('PHP4 Support', 'avh-ec') . '</span><br />';
1159
+ echo __('The next major release of the plugin will no longer support PHP4.', 'avh-ec') . '<br />';
1160
+ echo __('It will be written for PHP 5.2 and ', 'avh-ec');
1161
+ if ($php5) {
1162
+ echo __('your blog already runs the needed PHP version. When the new release comes out you can safely update.',
1163
+ 'avh-ec') . '<br />';
1164
  } else {
1165
+ echo __('your blog still runs PHP4. When the new release comes out you can not use it.', 'avh-ec') .
1166
+ '<br />';
1167
+ echo __('I don\'t have a timeline for the next version but consider contacting your host if PHP 5.2 is available.',
1168
+ 'avh-ec') . '<br />';
1169
+ echo __('If your hosts doesn\'t offer PHP 5.2 you might want to consider switching hosts.', 'avh-ec') .
1170
+ '<br />';
1171
+ echo __('A host to consider is ', 'avh-ec') .
1172
+ '<a href="http://www.lunarpages.com/id/pdoes" target="_blank">Lunarpages</a>';
1173
+ echo __('I run my personal blog there and I am very happy with their services. You can get an account with unlimited bandwidth, storage and much more for a low price.',
1174
+ 'avh-ec');
1175
  }
1176
  echo '</div>';
1177
+ }
1178
 
1179
+ /**
1180
+ * Metabox for Adding a group
1181
+ *
1182
+ * @param $data
1183
+ */
1184
+ function metaboxCategoryGroupAdd($data) {
1185
+ echo '<form name="avhec-addgroup" id="avhec-addgroup" method="POST" action="' .
1186
+ $this->getBackLink() .
1187
+ '" accept-charset="utf-8" >';
1188
+ wp_nonce_field('avh_ec_addgroup');
1189
+ echo $this->printOptions($data['add']['form'], $data['add']['data']);
1190
+ echo '<p class="submit"><input class="button" type="submit" name="addgroup" value="' .
1191
+ __('Add group', 'avh-ec') .
1192
+ '" /></p>';
1193
+ echo '</form>';
1194
+ }
1195
+
1196
+ /**
1197
+ * Metabox Category Group Edit
1198
+ */
1199
+ function metaboxCategoryGroupEdit($data) {
1200
+ echo '<form name="avhec-editgroup" id="avhec-editgroup" method="POST" action="' .
1201
+ $this->getBackLink() .
1202
+ '" accept-charset="utf-8" >';
1203
+ wp_nonce_field('avh_ec_editgroup');
1204
+ echo $this->printOptions($data['edit']['form'], $data['edit']['data']);
1205
+ echo '<input type="hidden" value="' .
1206
+ $data['edit']['data']['edit']['group_id'] .
1207
+ '" name="avhec-group_id" id="avhec-group_id">';
1208
+ echo '<p class="submit"><input class="button" type="submit" name="editgroup" value="' .
1209
+ __('Update group', 'avh-ec') .
1210
+ '" /></p>';
1211
+ echo '</form>';
1212
+ }
1213
+
1214
+ /**
1215
+ * Metabox for showing the groups as a list
1216
+ *
1217
+ * @param $data
1218
+ */
1219
+ function metaboxCategoryGroupList($data) {
1220
+ echo '<form id="posts-filter" action="" method="get">';
1221
+
1222
+ echo '<div class="clear"></div>';
1223
+
1224
+ echo '<table class="widefat fixed" cellspacing="0">';
1225
+ echo '<thead>';
1226
+ echo '<tr>';
1227
+ print_column_headers('categories_group');
1228
+ echo '</tr>';
1229
+ echo '</thead>';
1230
+
1231
+ echo '<tfoot>';
1232
+ echo '<tr>';
1233
+ print_column_headers('categories_group', false);
1234
+ echo '</tr>';
1235
+ echo '</tfoot>';
1236
+
1237
+ echo '<tbody id="the-list" class="list:group">';
1238
+ $this->printCategoryGroupRows();
1239
+ echo '</tbody>';
1240
+ echo '</table>';
1241
+
1242
+ echo '<br class="clear" />';
1243
+ echo '</form>';
1244
+ //echo '</div>';
1245
+ }
1246
+
1247
+ /**
1248
+ * Metabox Category Group Special pages
1249
+ */
1250
+ function metaboxCategoryGroupSpecialPages($data) {
1251
+ echo '<form name="avhec-specialpagesgroup" id="avhec-specialpagesgroup" method="POST" action="' .
1252
+ $this->getBackLink() .
1253
+ '" accept-charset="utf-8" >';
1254
+ wp_nonce_field('avh_ec_specialpagesgroup');
1255
+ echo $this->printOptions($data['sp']['form'], $data['sp']['data']);
1256
+ echo '<p class="submit"><input class="button" type="submit" name="spgroup" value="' .
1257
+ __('Save settings', 'avh-ec') .
1258
+ '" /></p>';
1259
+ echo '</form>';
1260
  }
1261
 
1262
+ ############## Admin WP Helper ##############
1263
+
1264
  /**
1265
  * Donation Metabox
1266
+ *
1267
  * @return unknown_type
1268
  */
1269
+ function metaboxDonations() {
 
1270
  echo '<div class="p">';
1271
+ echo __('If you enjoy this plug-in please consider a donation. There are several ways you can show your appreciation.',
1272
+ 'avh-ec');
1273
  echo '</div>';
1274
 
1275
  echo '<div class="p">';
1276
  echo '<span class="b">Amazon</span><br />';
1277
  echo __('If you decide to buy something from Amazon click the button.', 'avh-ec') . '</span><br />';
1278
+ echo '<a href="https://www.amazon.com/?tag=petervanderdoes-20" target="_blank" title="Amazon Homepage"><img alt="Amazon Button" src="' .
1279
+ $this->core->info['graphics_url'] .
1280
+ '/us_banner_logow_120x60.gif" /></a>';
1281
  echo '</div>';
1282
 
1283
  echo '<div class="p">';
1284
+ echo __('You can send me something from my ', 'avh-ec') .
1285
+ '<a href="http://www.amazon.com/registry/wishlist/1U3DTWZ72PI7W?tag=petervanderdoes-20">' .
1286
+ __('Amazon Wish List', 'avh-ec') .
1287
+ '</a>';
1288
  echo '</div>';
1289
 
1290
  echo '<div class="p">';
1291
  echo '<span class="b">' . __('Through Paypal.', 'avh-ec') . '</span><br />';
1292
+ echo __('Click on the Donate button and you will be directed to Paypal where you can make your donation and you don\'t need to have a Paypal account to make a donation.',
1293
+ 'avh-ec') . '<br />';
1294
  echo '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=S85FXJ9EBHAF2&lc=US&item_name=AVH%20Plugins&item_number=fdas&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted" target="_blank" title="Donate">';
1295
  echo '<img src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" alt="Donate"/></a>';
1296
  echo '</div>';
 
1297
  }
1298
 
1299
  /***
1300
  * F.A.Q Metabox
1301
+ *
1302
  * @return none
1303
  */
1304
+ function metaboxFAQ() {
 
1305
  echo '<div class="p">';
1306
  echo '<span class="b">' . __('What about support?', 'avh-ec') . '</span><br />';
1307
+ echo __('I created a <a href="http://forums.avirtualhome.com" target="_blank">support site</a> where you can ask questions or request features.',
1308
+ 'avh-ec') . '<br />';
1309
  echo '</div>';
1310
 
1311
  echo '<div class="p">';
1312
  echo '<span class="b">' . __('What is depth selection?', 'avh-ec') . '</span><br />';
1313
+ echo __('Starting with version 2.0 and WordPress 2.8 you can select how many levels deep you want to show your categories. This option only works when you select Show Hierarchy as well.',
1314
+ 'avh-ec') . '<br /><br />';
1315
+ echo __('Here is how it works: Say you have 5 top level categories and each top level has a number of children. You could manually select all the Top Level categories you want to show but now you can do the following:',
1316
+ 'avh-ec') . '<br />';
1317
+ echo __('You select to display all categories, select to Show hierarchy and select how many levels you want to show, in this case Toplevel only.',
1318
+ 'avh-ec') . '<br />';
1319
  echo '</div>';
1320
 
1321
  echo '<div class="p">';
1322
  echo '<span class="b">' . __('Multiple Category Groups', 'avh-ec') . '</span><br />';
1323
+ echo __('The following is an explanation how assigning multiple groups to page/post works.', 'avh-ec') .
1324
+ '<br /><br />';
1325
  echo __('Lets say you have the following groups:', 'avh-ec');
1326
  echo '<ul>';
1327
  echo '<li>' . __('Free Time', 'avh-ec') . '</li>';
1329
  echo '<li>' . __('Movie', 'avh-ec') . '</li>';
1330
  echo '<li>' . __('Music', 'avh-ec') . '</li>';
1331
  echo '</ul>';
1332
+ echo __('Setup several Category Group widgets and associated each widget with one or more groups.', 'avh-ec') .
1333
+ '<br />';
1334
  echo __('Widget 1 has association with Free Time', 'avh-ec') . '<br />';
1335
  echo __('Widget 2 has association with Theater, Movie and Music', 'avh-ec') . '<br />';
1336
  echo __('Widget 3 has association with Theater, Movie and Music', 'avh-ec') . '<br /><br />';
1352
  echo '<li>' . __('Widget 2: Shows categories of the Movie or Music group.', 'avh-ec') . '</li>';
1353
  echo '<li>' . __('Widget 3: Shows categories of the Music or Movie group.', 'avh-ec') . '</li>';
1354
  echo '</ul>';
1355
+ echo __('Whether Widget 2 shows Movie or Music depends on the creation order of groups. If Widget 2 shows Movie, Widget 3 will show Music but if Widget 2 shows Music, Widget 3 will show Movie.',
1356
+ 'avh-ec') . '<br />';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1357
  echo '</div>';
 
1358
  }
1359
 
1360
  /**
1361
+ * Displays the Manual Order metabox.
1362
  *
1363
+ * @author Andrew Charlton - original
1364
+ * @author Peter van der Does - modifications
 
1365
  */
1366
+ function metaboxManualOrder() {
1367
+ global $wpdb;
1368
 
1369
+ $parentID = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1370
 
1371
+ if (isset($_POST['btnSubCats'])) {
1372
+ $parentID = $_POST['cats'];
1373
+ } elseif (isset($_POST['hdnParentID'])) {
1374
+ $parentID = $_POST['hdnParentID'];
1375
  }
 
 
1376
 
1377
+ if (isset($_POST['btnReturnParent'])) {
1378
+ $parentsParent = $wpdb->get_row($wpdb->prepare("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = %d",
1379
+ $_POST['hdnParentID']),
1380
+ ARRAY_N);
1381
+ $parentID = $parentsParent[0];
1382
+ }
1383
+
1384
+ $success = "";
1385
+ if (isset($_POST['btnOrderCats'])) {
1386
+ if (isset($_POST['hdnManualOrder']) && $_POST['hdnManualOrder'] != "") {
1387
+
1388
+ $manualOrder = $_POST['hdnManualOrder'];
1389
+ $IDs = explode(",", $manualOrder);
1390
+ $result = count($IDs);
1391
+
1392
+ for ($i = 0; $i < $result; $i ++) {
1393
+ $str = str_replace("id_", "", $IDs[ $i ]);
1394
+ $wpdb->query($wpdb->prepare("UPDATE $wpdb->terms SET avhec_term_order = %d WHERE term_id =%d",
1395
+ $i,
1396
+ $str));
1397
+ }
1398
+
1399
+ $success = '<div id="message" class="updated fade"><p>' .
1400
+ __('Manual order of the categories successfully updated.', 'avh-ec') .
1401
+ '</p></div>';
1402
+ } else {
1403
+ $success = '<div id="message" class="updated fade"><p>' .
1404
+ __('An error occured, order has not been saved.', 'avh-ec') .
1405
+ '</p></div>';
1406
+ }
1407
+ }
1408
+
1409
+ $subCategories = "";
1410
+ $results = $wpdb->get_results($wpdb->prepare("SELECT t.term_id, t.name FROM $wpdb->term_taxonomy tt, $wpdb->terms t, $wpdb->term_taxonomy tt2 WHERE tt.parent = %d AND tt.taxonomy = 'category' AND t.term_id = tt.term_id AND tt2.parent = tt.term_id GROUP BY t.term_id, t.name HAVING COUNT(*) > 0 ORDER BY t.avhec_term_order ASC",
1411
+ $parentID));
1412
+ foreach ($results as $row) {
1413
+ $subCategories .= "<option value='$row->term_id'>$row->name</option>";
1414
+ }
1415
+
1416
+ echo '<div class="wrap">';
1417
+ echo '<form name="frmMyCatOrder" method="post" action="">';
1418
+ echo $success;
1419
+
1420
+ echo '<h4>';
1421
+ _e('Order the categories', 'avh-ec');
1422
+ if ($parentID == 0) {
1423
+ echo ' at the Toplevel';
1424
+ } else {
1425
+ $categories = get_category_parents($parentID, false, ' » ');
1426
+ echo ' in the category ' . trim($categories, ' » ');
1427
+ }
1428
+ echo '</h4>';
1429
+ echo '<span class="description">';
1430
+ _e('Order the categories on this level by dragging and dropping them into the desired order.', 'avh-ec');
1431
+ echo '</span>';
1432
+ echo '<ul id="avhecManualOrder">';
1433
+ $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->terms t inner join $wpdb->term_taxonomy tt on t.term_id = tt.term_id WHERE taxonomy = 'category' and parent = %d ORDER BY avhec_term_order ASC",
1434
+ $parentID));
1435
+ foreach ($results as $row) {
1436
+ echo "<li id='id_$row->term_id' class='lineitem menu-item-settings'>" . __($row->name) . "</li>";
1437
+ }
1438
+
1439
+ echo '</ul>';
1440
+ echo '<input type="submit" name="btnOrderCats" id="btnOrderCats" class="button-primary" value="' .
1441
+ __('Save Order', 'avh-ec') .
1442
+ '" onclick="javascript:orderCats(); return true;" />';
1443
+
1444
+ if ($parentID != 0) {
1445
+ echo "<input type='submit' class='button' id='btnReturnParent' name='btnReturnParent' value='" .
1446
+ __('Return to parent category', 'avh-ec') .
1447
+ "' />";
1448
+ }
1449
 
1450
+ echo '<strong id="updateText"></strong><br /><br />';
1451
+ if ($subCategories != "") {
1452
+
1453
+ echo '<h4>';
1454
+ _e('Select Subcategory', 'avh-ec');
1455
+ echo '</h4>';
1456
+ echo '<select id="cats" name="cats">';
1457
+ echo $subCategories;
1458
+
1459
+ echo '</select><input type="submit" name="btnSubCats" class="button" id="btnSubCats" value="' .
1460
+ __('Select', 'avh-ec') .
1461
+ '" />';
1462
+ echo '<span class="description">';
1463
+ _e('Choose a category from the drop down to order the subcategories in that category.', 'avh-ec');
1464
+ echo '</span>';
1465
+ }
1466
+
1467
+ echo '<input type="hidden" id="hdnManualOrder" name="hdnManualOrder" />';
1468
+ echo '<input type="hidden" id="hdnParentID" name="hdnParentID" value="' . $parentID . '" /></form>';
1469
+ echo '</div>';
1470
  }
1471
 
1472
  /**
1473
+ * Options Metabox
 
 
 
 
1474
  */
1475
+ function metaboxOptions($data) {
1476
+ echo $this->printOptions($data['options_general'], $data['actual_options']);
 
 
1477
  }
1478
 
1479
  /**
1480
+ * Translation Metabox
1481
  *
1482
+ * @return unknown_type
 
 
 
 
1483
  */
1484
+ function metaboxTranslation() {
1485
+ $locale = apply_filters('plugin_locale', get_locale(), 'avh-ec');
1486
+ $available_locale['cs_CZ'] = array('Czech - Čeština', 0);
1487
+ $available_locale['nl_NL'] = array('Dutch - Nederlands', 0);
1488
+ $available_locale['de_DE'] = array('German - Deutsch', 0);
1489
+ $available_locale['el'] = array('Greek - Čeština', 0);
1490
+ $available_locale['id_ID'] = array('Indonesian - Bahasa Indonesia - Čeština', 0);
1491
+ $available_locale['it_IT'] = array('Italian - Italiano', 1);
1492
+ $available_locale['ru_RU'] = array('Russian — Русский', 0);
1493
+ $available_locale['es_ES'] = array('Spanish - Español', 0);
1494
+ $available_locale['sv_SE'] = array('Swedish - Svenska', 0);
1495
+ $available_locale['tr'] = array('Turkish - Türkçe', 0);
1496
 
1497
+ echo '<div class="p">';
1498
+ echo __('This plugin is translated in several languages. Some of the languages might be incomplete. Please help to complete these translations or add a new language.',
1499
+ 'avh-ec') . '<br />';
1500
 
1501
+ echo '</div>';
1502
 
1503
+ echo '<div class="p">';
1504
+ echo '<span class="b">' . __('Available Languages', 'avh-ec') . '</span>';
1505
+ echo '<ul>';
1506
+ foreach ($available_locale as $key => $value) {
1507
+ echo '<li>';
1508
+ $complete = ($value[1] == 1 ? 'Complete' : 'Incomplete');
1509
+ echo $value[0] . ' (' . $key . ') - ' . $complete;
1510
+ echo '</li>';
 
 
1511
  }
1512
+ echo '</ul>';
1513
+ echo '</div>';
1514
 
1515
+ echo '<div class="p">';
1516
+ if ('en_US' != $locale & ( ! array_key_exists($locale, $available_locale))) {
1517
+ echo 'Currently the plugin is not available in your language (' .
1518
+ $locale .
1519
+ '). We\'re in the middle of changing the way you can help with translations. Keep an eye on the <a href="http:///blog.avirtualhome.com">website</a> for the announcement.';
1520
+ } else {
1521
+ echo 'We\'re in the middle of changing the way you can help with translations. Keep an eye on the <a href="http:///blog.avirtualhome.com">website</a> for the announcement.';
1522
+ }
1523
+ echo '</div>';
1524
  }
1525
 
1526
  /**
1527
+ * Display plugin Copyright
 
 
 
1528
  */
1529
+ function printAdminFooter() {
1530
+ echo '<p class="footer_avhec">';
1531
+ printf('&copy; Copyright %d <a href="http://blog.avirtualhome.com/" title="My Thoughts">Peter van der Does</a> | AVH Extended Categories Version %s',
1532
+ date('Y'),
1533
+ $this->core->version);
1534
+ echo '</p>';
 
 
 
1535
  }
1536
 
1537
  /**
1541
  * @param int $group_term_id
1542
  * @param int $group_term_taxonomy_id
1543
  */
1544
+ function printCategoryGroupRow($group_term_id, $group_term_taxonomy_id) {
 
1545
  static $row_class = '';
1546
 
1547
  $group = get_term($group_term_id, $this->catgrp->taxonomy_name, OBJECT, 'display');
1548
 
1549
+ $no_edit[ $this->catgrp->getTermIDBy('slug', 'all') ] = 0;
1550
+ $no_delete[ $this->catgrp->getTermIDBy('slug', 'all') ] = 0;
1551
 
1552
  if (current_user_can('manage_categories')) {
1553
+ $actions = array();
1554
+ if ( ! array_key_exists($group->term_id, $no_edit)) {
1555
  $edit_link = "admin.php?page=avhec-grouped&amp;action=edit&amp;group_ID=$group->term_id";
1556
+ $edit = "<a class='row-title' href='$edit_link' title='" .
1557
+ esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $group->name)) .
1558
+ "'>" .
1559
+ esc_attr($group->name) .
1560
+ '</a><br />';
1561
 
1562
  $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
1563
  } else {
1564
  $edit = esc_attr($group->name);
1565
  }
1566
+ if ( ! (array_key_exists($group->term_id, $no_delete))) {
1567
+ $actions['delete'] = "<a class='delete:the-list:group-$group->term_id submitdelete' href='" .
1568
+ wp_nonce_url("admin.php?page=avhec-grouped&amp;action=delete&amp;group_ID=$group->term_id",
1569
+ 'delete-avhecgroup_' . $group->term_id) .
1570
+ "'>" .
1571
+ __('Delete') .
1572
+ "</a>";
1573
  }
1574
  $action_count = count($actions);
1575
+ $i = 0;
1576
  $edit .= '<div class="row-actions">';
1577
  foreach ($actions as $action => $link) {
1578
  ++ $i;
1585
  }
1586
 
1587
  $row_class = 'alternate' == $row_class ? '' : 'alternate';
1588
+ $qe_data = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit');
1589
 
1590
  $output = "<tr id='group-$group->term_id' class='iedit $row_class'>";
1591
 
1592
  $columns = get_column_headers('categories_group');
1593
+ $hidden = get_hidden_columns('categories_group');
1594
  foreach ($columns as $column_name => $column_display_name) {
1595
  $class = 'class="' . $column_name . ' column-' . $column_name . '"';
1596
 
1597
  $style = '';
1598
+ if (in_array($column_name, $hidden)) {
1599
  $style = ' style="display:none;"';
1600
+ }
1601
 
1602
  $attributes = $class . $style;
1603
 
1604
  switch ($column_name) {
1605
  case 'cb':
1606
  $output .= '<th scope="row" class="check-column">';
1607
+ if ( ! (array_key_exists($group->term_id, $no_delete))) {
1608
  $output .= '<input type="checkbox" name="delete[]" value="' . $group->term_id . '" />';
1609
  } else {
1610
  $output .= "&nbsp;";
1620
  break;
1621
  case 'widget-title':
1622
  $title = $this->catgrp->getWidgetTitleForGroup($group->term_id);
1623
+ if ( ! $title) {
1624
  $title = "&nbsp;";
1625
  }
1626
  $output .= '<td ' . $attributes . '>' . $title . '</td>';
1633
  $output .= "<td $attributes>" . apply_filters('editable_slug', $qe_data->slug) . "</td>";
1634
  break;
1635
  case 'cat-in-group':
1636
+ $cats = $this->catgrp->getCategoriesFromGroup($group_term_id);
1637
+ $catname = array();
1638
  foreach ($cats as $cat_id) {
1639
  $catname[] = get_cat_name($cat_id);
1640
  }
1642
  $cat = implode(', ', $catname);
1643
  $output .= '<td ' . $attributes . '>' . $cat . '</td>';
1644
  break;
 
1645
  }
1646
  }
1647
  $output .= '</tr>';
1649
  return $output;
1650
  }
1651
 
1652
+ /**
1653
+ * Print all Category Group rows
1654
+ *
1655
+ * @uses printCategoryGroupRow
1656
+ */
1657
+ function printCategoryGroupRows() {
1658
+ $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false));
1659
+
1660
+ foreach ($cat_groups as $group) {
1661
+ if ('none' != $group->slug) {
1662
+ echo $this->printCategoryGroupRow($group->term_id, $group->term_taxonomy_id);
1663
+ }
1664
+ }
1665
+ }
1666
+
1667
  /**
1668
  * Prints the general nonces, used by the AJAX
1669
  */
1670
+ function printMetaboxGeneralNonces() {
 
1671
  echo '<form style="display:none" method="get" action="">';
1672
  echo '<p>';
1673
  wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1674
  wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1675
  echo '</p>';
1676
  echo '</form>';
 
1677
  }
1678
 
1679
  /**
1681
  *
1682
  * @param $boxid
1683
  */
1684
+ function printMetaboxJS($boxid) {
1685
+ $a = $this->hooks[ 'menu_' . $boxid ];
 
1686
  echo '<script type="text/javascript">' . "\n";
1687
  echo ' //<![CDATA[' . "\n";
1688
  echo ' jQuery(document).ready( function($) {' . "\n";
1692
  echo ' });' . "\n";
1693
  echo ' //]]>' . "\n";
1694
  echo '</script>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1695
  }
1696
 
1697
  /**
1698
  * Ouput formatted options
1699
  *
1700
  * @param array $option_data
1701
+ *
1702
  * @return string
1703
  */
1704
+ function printOptions($option_data, $option_actual) {
 
1705
  // Generate output
1706
  $output = '';
1707
  $output .= "\n" . '<table class="form-table avhec-options">' . "\n";
1708
  foreach ($option_data as $option) {
1709
+ $section = substr($option[0], strpos($option[0], '[') + 1);
1710
+ $section = substr($section, 0, strpos($section, ']['));
1711
  $option_key = rtrim($option[0], ']');
1712
  $option_key = substr($option_key, strpos($option_key, '][') + 2);
1713
  // Helper
1714
  if ($option[2] == 'helper') {
1715
+ $output .= '<tr style="vertical-align: top;"><td class="helper" colspan="2">' .
1716
+ wp_filter_post_kses($option[4]) .
1717
+ '</td></tr>' .
1718
+ "\n";
1719
  continue;
1720
  }
1721
  switch ($option[2]) {
1722
  case 'checkbox':
1723
+ $input_type = '<input type="checkbox" id="' .
1724
+ esc_attr($option[0]) .
1725
+ '" name="' .
1726
+ esc_attr($option[0]) .
1727
+ '" value="' .
1728
+ esc_attr($option[3]) .
1729
+ '" ' .
1730
+ $this->isChecked('1', $option_actual[ $section ][ $option_key ]) .
1731
+ ' />' .
1732
+ "\n";
1733
  $explanation = $option[4];
1734
  break;
1735
  case 'dropdown':
1736
  $selvalue = $option[3];
1737
+ $seltext = $option[4];
1738
+ $seldata = '';
1739
  foreach ((array) $selvalue as $key => $sel) {
1740
+ $seldata .= '<option value="' .
1741
+ esc_attr($sel) .
1742
+ '" ' .
1743
+ (($option_actual[ $section ][ $option_key ] == $sel) ? 'selected="selected"' : '') .
1744
+ ' >' .
1745
+ esc_html(ucfirst($seltext[ $key ])) .
1746
+ '</option>' .
1747
+ "\n";
1748
  }
1749
+ $input_type = '<select id="' .
1750
+ esc_attr($option[0]) .
1751
+ '" name="' .
1752
+ esc_attr($option[0]) .
1753
+ '">' .
1754
+ $seldata .
1755
+ '</select>' .
1756
+ "\n";
1757
  $explanation = $option[5];
1758
  break;
1759
  case 'text-color':
1760
+ $input_type = '<input type="text" ' .
1761
+ (($option[3] > 1) ? ' style="width: 95%" ' : '') .
1762
+ 'id="' .
1763
+ esc_attr($option[0]) .
1764
+ '" name="' .
1765
+ esc_attr($option[0]) .
1766
+ '" value="' .
1767
+ esc_attr($option_actual[ $section ][ $option_key ]) .
1768
+ '" size="' .
1769
+ esc_attr($option[3]) .
1770
+ '" /><div class="box_color ' .
1771
+ esc_attr($option[0]) .
1772
+ '"></div>' .
1773
+ "\n";
1774
  $explanation = $option[4];
1775
  break;
1776
  case 'textarea':
1777
+ $input_type = '<textarea rows="' .
1778
+ esc_attr($option[5]) .
1779
+ '" ' .
1780
+ (($option[3] > 1) ? ' style="width: 95%" ' : '') .
1781
+ 'id="' .
1782
+ esc_attr($option[0]) .
1783
+ '" name="' .
1784
+ esc_attr($option[0]) .
1785
+ '" size="' .
1786
+ esc_attr($option[3]) .
1787
+ '" />' .
1788
+ $option_actual[ $section ][ $option_key ] .
1789
+ '</textarea>';
1790
  $explanation = $option[4];
1791
  break;
1792
  case 'catlist':
1793
  ob_start();
1794
  echo '<div id="avhec-catlist">';
1795
  echo '<ul>';
1796
+ wp_category_checklist(0, 0, $option_actual[ $section ][ $option_key ]);
1797
  echo '</ul>';
1798
  echo '</div>';
1799
  $input_type = ob_get_contents();
1802
  break;
1803
  case 'text':
1804
  default:
1805
+ $input_type = '<input type="text" ' .
1806
+ (($option[3] > 1) ? ' style="width: 95%" ' : '') .
1807
+ 'id="' .
1808
+ esc_attr($option[0]) .
1809
+ '" name="' .
1810
+ esc_attr($option[0]) .
1811
+ '" value="' .
1812
+ esc_attr($option_actual[ $section ][ $option_key ]) .
1813
+ '" size="' .
1814
+ esc_attr($option[3]) .
1815
+ '" />' .
1816
+ "\n";
1817
  $explanation = $option[4];
1818
  break;
1819
  }
1823
  $extra = '<br /><span class="description">' . wp_filter_kses($explanation) . '</span>' . "\n";
1824
  }
1825
  // Output
1826
+ $output .= '<tr style="vertical-align: top;"><th align="left" scope="row"><label for="' .
1827
+ esc_attr($option[0]) .
1828
+ '">' .
1829
+ wp_filter_kses($option[1]) .
1830
+ '</label></th><td>' .
1831
+ $input_type .
1832
+ ' ' .
1833
+ $extra .
1834
+ '</td></tr>' .
1835
+ "\n";
1836
  }
1837
  $output .= '</table>' . "\n";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1838
 
1839
+ return $output;
 
 
 
 
1840
  }
1841
  }
1842
+
1843
  ?>
3.3/class/avh-ec.category-group.php CHANGED
@@ -5,42 +5,29 @@
5
  *
6
  * @author Peter van der Does
7
  */
8
- class AVH_EC_Category_Group
9
- {
 
10
  /**
11
  * Taxonomy name
 
12
  * @var string
13
  */
14
  var $taxonomy_name;
15
-
16
- var $db_options_widget_titles;
17
-
18
- var $options_widget_titles;
19
-
20
  var $widget_done_catgroup;
21
 
22
- /**
23
- * PHP4 constructor.
24
- *
25
- */
26
- function AVH_EC_Category_Group ()
27
- {
28
- return $this->__construct();
29
- }
30
-
31
  /**
32
  * PHP5 Constructor
33
  * Init the Database Abstraction layer
34
- *
35
  */
36
- function __construct ()
37
- {
38
  global $wpdb;
39
 
40
- register_shutdown_function(array ( &$this, '__destruct' ));
41
 
42
  /**
43
  * Taxonomy name
 
44
  * @var string
45
  */
46
  $this->taxonomy_name = 'avhec_catgroup';
@@ -51,16 +38,25 @@ class AVH_EC_Category_Group
51
 
52
  /**
53
  * Create the table if it doesn't exist.
54
- *
55
  */
56
  if ($wpdb->get_var('show tables like \'' . $wpdb->avhec_cat_group . '\'') != $wpdb->avhec_cat_group) {
57
- add_action('init', array ( &$this, 'doCreateTable' ), 2); // Priority needs to be the same as the Register Taxonomy
 
 
58
  }
59
- add_action('init', array ( &$this, 'doRegisterTaxonomy' ), 2); // Priority for registering custom taxonomies is +1 over the creation of the initial taxonomies
60
- add_action('init', array ( &$this, 'doSetupOptions' ));
 
 
61
 
62
- add_action('admin_init', array ( &$this, 'addMetaBoxes' ));
 
63
 
 
 
 
 
 
64
  }
65
 
66
  /**
@@ -68,65 +64,179 @@ class AVH_EC_Category_Group
68
  *
69
  * @return bool Always true
70
  */
71
- function __destruct ()
72
- {
73
  return true;
74
  }
75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  /**
77
  * Create Table
78
- * @WordPress action init
79
  *
 
80
  */
81
- function doCreateTable ()
82
- {
83
  global $wpdb;
84
 
85
  // Setup the DB Tables
86
  $charset_collate = '';
87
 
88
- if (! empty($wpdb->charset)) {
89
  $charset_collate = 'DEFAULT CHARACTER SET ' . $wpdb->charset;
90
  }
91
- if (! empty($wpdb->collate)) {
92
  $charset_collate .= ' COLLATE ' . $wpdb->collate;
93
  }
94
 
95
- $sql = 'CREATE TABLE `' . $wpdb->avhec_cat_group . '` ( `group_term_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, `term_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (`group_term_id`, `term_id`) )' . $charset_collate . ';';
 
 
 
 
96
 
97
  $result = $wpdb->query($sql);
98
  }
99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  /**
101
  * Setup Group Categories Taxonomy
102
- * @WordPress action init
103
  *
 
104
  */
105
- function doRegisterTaxonomy ()
106
- {
107
  /**
108
  * As we don't want to see the Menu Item we have to disable show_ui. This also disables the metabox on the posts and pages, so we add thse manually instead.
109
  * We remove the capabilities to manage, edit and delete the terms. We have written this part ourselves and don't use WordPress for these functions. The only one we use is the assign_terms.
110
  */
111
- $labels = array ( 'name' => __('Category Groups', 'avh-ec'), 'singular_name' => __('Category Group', 'avh-ec'), 'search_items' => __('Search Category Groups', 'avh-ec'), 'popular_items' => __('Popular Category Groups'), 'all_items' => __('All Category Groups'), 'parent_item' => __('Parent Category Group'), 'parent_item_colon' => __('Parent Category Group:'), 'edit_item' => __('Edit Category Group'), 'update_item' => __('Update Category Group'), 'add_new_item' => __('Add New Category Group'), 'new_item_name' => __('New Category Group Name') );
112
- $caps = array ( 'manage_terms' => null, 'edit_terms' => null, 'delete_terms' => null, 'assign_terms' => 'edit_posts' );
113
- register_taxonomy($this->taxonomy_name, array ( 'post', 'page' ), array ( 'hierarchical' => TRUE, 'labels' => $labels, 'query_var' => TRUE, 'rewrite' => TRUE, 'show_in_nav_menus' => FALSE, 'public' => TRUE, 'show_ui' => FALSE, 'capabilities' => $caps ));
114
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  }
116
 
117
  /**
118
  * Setup the options for the widget titles
119
- * @WordPress action init
120
  *
 
121
  */
122
- function doSetupOptions ()
123
- {
124
  // Setup the standard groups if the none group does not exists.
125
  $all_categories = $this->getAllCategoriesTermID();
126
  if (false === $this->getTermIDBy('slug', 'none')) {
127
- $none_group_id = wp_insert_term('none', $this->taxonomy_name, array ( 'description' => __('This group will not show the widget.', 'avh-ec') ));
128
- $all_group_id = wp_insert_term('All', $this->taxonomy_name, array ( 'description' => __('Holds all the categories.', 'avh-ec') ));
129
- $home_group_id = wp_insert_term('Home', $this->taxonomy_name, array ( 'description' => __('This group will be shown on the front page.', 'avh-ec') ));
 
 
 
 
 
 
 
 
 
 
 
130
 
131
  // Fill the standard groups with all categories
132
  $this->setCategoriesForGroup($home_group_id['term_id'], $all_categories);
@@ -135,12 +245,12 @@ class AVH_EC_Category_Group
135
  }
136
 
137
  $options = get_option($this->db_options_widget_titles);
138
- if (! $options) {
139
- $options = array ();
140
- $id = $this->getTermIDBy('slug', 'all');
141
- $options[$id] = '';
142
- $id = $this->getTermIDBy('slug', 'home');
143
- $options[$id] = '';
144
  update_option($this->db_options_widget_titles, $options);
145
  }
146
  $this->options_widget_titles = $options;
@@ -148,14 +258,30 @@ class AVH_EC_Category_Group
148
  }
149
 
150
  /**
151
- * Add the metaboxes for the pots and page pages.
152
- * @WordPress action admin_init
153
  *
 
 
 
 
154
  */
155
- function addMetaBoxes ()
156
- {
157
- add_meta_box($this->taxonomy_name . 'div', __('Category Groups', 'avh-ec'), 'post_categories_meta_box', 'post', 'side', 'core', array ( 'taxonomy' => $this->taxonomy_name ));
158
- add_meta_box($this->taxonomy_name . 'div', __('Category Groups', 'avh-ec'), 'post_categories_meta_box', 'page', 'side', 'core', array ( 'taxonomy' => $this->taxonomy_name ));
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  }
160
 
161
  /**
@@ -163,15 +289,15 @@ class AVH_EC_Category_Group
163
  *
164
  * @return array Term_id
165
  */
166
- function getAllCategoriesTermID ()
167
- {
168
- $all_cat_id = array ();
169
  $categories = get_categories();
170
- if (! is_wp_error($categories)) {
171
  foreach ($categories as $category) {
172
  $all_cat_id[] = $category->term_id;
173
  }
174
  }
 
175
  return ($all_cat_id);
176
  }
177
 
@@ -179,19 +305,23 @@ class AVH_EC_Category_Group
179
  * Get the categories from the given group from the DB
180
  *
181
  * @param int $group_id The Taxonomy Term ID
182
- * @return Array|False categories. Will return FALSE, if the row does not exists.
183
  *
 
184
  */
185
- function getCategoriesFromGroup ($group_id)
186
- {
187
  global $wpdb;
188
 
189
  // Query database
190
- $result = $wpdb->get_results($wpdb->prepare('SELECT * FROM ' . $wpdb->terms . ' t, ' . $wpdb->avhec_cat_group . ' cg WHERE t.term_id = cg.term_id AND cg.group_term_id = %d', $group_id));
 
 
 
 
 
191
 
192
  if (is_array($result)) { // Call succeeded
193
  if (empty($result)) { // No rows found
194
- $return = array ();
195
  } else {
196
  foreach ($result as $row) {
197
  $return[] = $row->term_id;
@@ -200,212 +330,135 @@ class AVH_EC_Category_Group
200
  } else {
201
  $return = false;
202
  }
 
203
  return ($return);
204
  }
205
 
206
  /**
207
- * Set the categories for the given group from the DB. Insert the group if it doesn't exists.
208
  *
209
- * @param int $group_id The Taxonomy Term ID
210
- * @param array $categories The categories
211
- * @return Object (false if not found)
212
  *
 
213
  */
214
- function setCategoriesForGroup ($group_id, $categories = array())
215
- {
216
  global $wpdb;
217
 
218
- $old_categories = $this->getCategoriesFromGroup($group_id);
219
-
220
- if (! is_array($categories)) {
221
- $categories = array ();
222
- }
223
- $new_categories = $categories;
224
- sort($old_categories);
225
- sort($new_categories);
226
- // If the new and old values are the same, no need to update.
227
- if ($new_categories === $old_categories) {
228
- return false;
229
- }
230
-
231
- $new = array_diff($new_categories, $old_categories);
232
- $removed = array_diff($old_categories, $new_categories);
233
-
234
- if (! empty($new)) {
235
- foreach ($new as $cat_term_id) {
236
- $insert[] = '(' . $group_id . ',' . $cat_term_id . ')';
237
- }
238
- $value = implode(',', $insert);
239
- $sql = 'INSERT INTO ' . $wpdb->avhec_cat_group . ' (group_term_id, term_id) VALUES ' . $value;
240
- $result = $wpdb->query($sql);
241
-
242
- }
243
-
244
- if (! empty($removed)) {
245
- $delete = implode(',', $removed);
246
- $sql = $wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE group_term_id=%d and term_id IN (' . $delete . ')', $group_id);
247
- $result = $wpdb->query($sql);
248
-
249
  }
250
 
251
- return $result;
252
  }
253
 
254
- /**
255
- * Set the Widget Title for a Group
256
- * @param int $group_id
257
- * @param string $widget_title
258
- *
259
- */
260
- function setWidgetTitleForGroup ($group_id, $widget_title = '')
261
- {
262
- $this->options_widget_titles[$group_id] = $widget_title;
263
- update_option($this->db_options_widget_titles, $this->options_widget_titles);
264
- }
265
 
266
- /**
267
- * Return the title for a group_id if exsist otherwise return false
268
- * @param $group_id
269
- *
270
- */
271
- function getWidgetTitleForGroup ($group_id)
272
- {
273
- if (isset($this->options_widget_titles[$group_id])) {
274
- return ($this->options_widget_titles[$group_id]);
275
  }
276
- return false;
277
- }
278
 
279
- /**
280
- * Delete the Widget Title for a group
281
- *
282
- * @param $group_id
283
- */
284
- function doDeleteWidgetTitle ($group_id)
285
- {
286
- if (isset($this->options_widget_titles[$group_id])) {
287
- unset($this->options_widget_titles[$group_id]);
288
- }
289
- update_option($this->db_options_widget_titles, $this->options_widget_titles);
290
  }
291
 
292
  /**
293
  * Same as get_term_by, but returns the ID only if found, else false
 
294
  * @param string $field
295
  * @param string $value
 
296
  * @return int|boolean
297
  */
298
- function getTermIDBy ($field, $value)
299
- {
300
  $row = get_term_by($field, $value, $this->taxonomy_name);
301
  if (false === $row) {
302
  $return = false;
303
  } else {
304
  $return = (int) $row->term_id;
305
  }
 
306
  return ($return);
307
  }
308
 
309
  /**
310
- * Gets all information of a group
311
  *
312
  * @param $group_id
313
- * @return Object|False Returns False when the group doesn't exists.
314
  */
315
- function getGroup ($group_id)
316
- {
317
- global $wpdb;
318
-
319
- $result = get_term((int) $group_id, $this->taxonomy_name);
320
- if (null === $result) {
321
- $result = false;
322
  }
323
- return ($result);
324
- }
325
 
326
- function getGroupByCategoryID ($category_id)
327
- {
328
- $return = get_term_by('slug', 'none', $this->taxonomy_name);
329
- $cat_groups = get_terms($this->taxonomy_name, array ( 'hide_empty' => FALSE ));
330
-
331
- foreach ($cat_groups as $group) {
332
- $cats = $this->getCategoriesFromGroup($group->term_id);
333
- if ($group->slug != 'all' && in_array($category_id, $cats)) {
334
- $return = $group;
335
- break;
336
- }
337
- }
338
- return $return;
339
  }
340
 
341
  /**
342
- * Inserts a new group
343
  *
344
- * @param $term
345
- * @param array $args
346
- */
347
- function doInsertGroup ($term, $args = array(), $widget_title = '')
348
- {
349
- $row = wp_insert_term($term, $this->taxonomy_name, $args);
350
- $this->setWidgetTitleForGroup($term, $widget_title);
351
- return ($row['term_id']);
352
- }
353
-
354
- /**
355
- * Deletes a group
356
  *
357
- * @param $group_id
358
  */
359
- function doDeleteGroup ($group_id)
360
- {
361
-
362
  global $wpdb;
363
 
364
- $group = $this->getGroup($group_id);
365
- $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE group_term_id=%d', $group_id));
366
- $this->doDeleteWidgetTitle($group_id);
367
- $return = wp_delete_term($group->term_id, $this->taxonomy_name);
368
 
369
- return ($return);
370
- }
 
 
 
 
 
 
 
 
371
 
372
- /**
373
- * Update a group
374
- *
375
- * @param $group_id
376
- * @param $selected_categories
377
- * @param $widget_title
378
- *
379
- * return -1,0,1 Unknown Group, Duplicate Slug, Succesfull
380
- */
381
- function doUpdateGroup ($group_id, $args = array(), $selected_categories, $widget_title = '')
382
- {
383
 
384
- $group = $this->getGroup($group_id);
385
- if (is_object($group)) {
386
- $id = wp_update_term($group->term_id, $this->taxonomy_name, $args);
387
- if (! is_wp_error($id)) {
388
- $this->setWidgetTitleForGroup($group_id, $widget_title);
389
- $this->setCategoriesForGroup($group_id, $selected_categories);
390
- $return = 1; // Succesful
391
- } else {
392
- $return = 0; // Duplicate Slug
393
  }
394
- } else {
395
- $return = - 1; // Unknown group
 
396
  }
397
- return ($return);
 
 
 
 
 
 
 
 
 
 
 
 
398
  }
399
 
400
  /**
401
- * Deletes the given category from all groups
402
  *
403
- * @param $category_id
 
404
  */
405
- function doDeleteCategoryFromGroup ($category_id)
406
- {
407
- global $wpdb;
408
- $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE term_id=%d', $category_id));
409
  }
410
  }
 
411
  ?>
5
  *
6
  * @author Peter van der Does
7
  */
8
+ class AVH_EC_Category_Group {
9
+ var $db_options_widget_titles;
10
+ var $options_widget_titles;
11
  /**
12
  * Taxonomy name
13
+ *
14
  * @var string
15
  */
16
  var $taxonomy_name;
 
 
 
 
 
17
  var $widget_done_catgroup;
18
 
 
 
 
 
 
 
 
 
 
19
  /**
20
  * PHP5 Constructor
21
  * Init the Database Abstraction layer
 
22
  */
23
+ function __construct() {
 
24
  global $wpdb;
25
 
26
+ register_shutdown_function(array(&$this, '__destruct'));
27
 
28
  /**
29
  * Taxonomy name
30
+ *
31
  * @var string
32
  */
33
  $this->taxonomy_name = 'avhec_catgroup';
38
 
39
  /**
40
  * Create the table if it doesn't exist.
 
41
  */
42
  if ($wpdb->get_var('show tables like \'' . $wpdb->avhec_cat_group . '\'') != $wpdb->avhec_cat_group) {
43
+ add_action('init',
44
+ array(&$this, 'doCreateTable'),
45
+ 2); // Priority needs to be the same as the Register Taxonomy
46
  }
47
+ add_action('init',
48
+ array(&$this, 'doRegisterTaxonomy'),
49
+ 2); // Priority for registering custom taxonomies is +1 over the creation of the initial taxonomies
50
+ add_action('init', array(&$this, 'doSetupOptions'));
51
 
52
+ add_action('admin_init', array(&$this, 'addMetaBoxes'));
53
+ }
54
 
55
+ /**
56
+ * PHP4 constructor.
57
+ */
58
+ function AVH_EC_Category_Group() {
59
+ return $this->__construct();
60
  }
61
 
62
  /**
64
  *
65
  * @return bool Always true
66
  */
67
+ function __destruct() {
 
68
  return true;
69
  }
70
 
71
+ /**
72
+ * Add the metaboxes for the pots and page pages.
73
+ *
74
+ * @WordPress action admin_init
75
+ */
76
+ function addMetaBoxes() {
77
+ add_meta_box($this->taxonomy_name . 'div',
78
+ __('Category Groups', 'avh-ec'),
79
+ 'post_categories_meta_box',
80
+ 'post',
81
+ 'side',
82
+ 'core',
83
+ array('taxonomy' => $this->taxonomy_name));
84
+ add_meta_box($this->taxonomy_name . 'div',
85
+ __('Category Groups', 'avh-ec'),
86
+ 'post_categories_meta_box',
87
+ 'page',
88
+ 'side',
89
+ 'core',
90
+ array('taxonomy' => $this->taxonomy_name));
91
+ }
92
+
93
  /**
94
  * Create Table
 
95
  *
96
+ * @WordPress action init
97
  */
98
+ function doCreateTable() {
 
99
  global $wpdb;
100
 
101
  // Setup the DB Tables
102
  $charset_collate = '';
103
 
104
+ if ( ! empty($wpdb->charset)) {
105
  $charset_collate = 'DEFAULT CHARACTER SET ' . $wpdb->charset;
106
  }
107
+ if ( ! empty($wpdb->collate)) {
108
  $charset_collate .= ' COLLATE ' . $wpdb->collate;
109
  }
110
 
111
+ $sql = 'CREATE TABLE `' .
112
+ $wpdb->avhec_cat_group .
113
+ '` ( `group_term_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, `term_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (`group_term_id`, `term_id`) )' .
114
+ $charset_collate .
115
+ ';';
116
 
117
  $result = $wpdb->query($sql);
118
  }
119
 
120
+ /**
121
+ * Deletes the given category from all groups
122
+ *
123
+ * @param $category_id
124
+ */
125
+ function doDeleteCategoryFromGroup($category_id) {
126
+ global $wpdb;
127
+ $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE term_id=%d',
128
+ $category_id));
129
+ }
130
+
131
+ /**
132
+ * Deletes a group
133
+ *
134
+ * @param $group_id
135
+ */
136
+ function doDeleteGroup($group_id) {
137
+
138
+ global $wpdb;
139
+
140
+ $group = $this->getGroup($group_id);
141
+ $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE group_term_id=%d',
142
+ $group_id));
143
+ $this->doDeleteWidgetTitle($group_id);
144
+ $return = wp_delete_term($group->term_id, $this->taxonomy_name);
145
+
146
+ return ($return);
147
+ }
148
+
149
+ /**
150
+ * Delete the Widget Title for a group
151
+ *
152
+ * @param $group_id
153
+ */
154
+ function doDeleteWidgetTitle($group_id) {
155
+ if (isset($this->options_widget_titles[ $group_id ])) {
156
+ unset($this->options_widget_titles[ $group_id ]);
157
+ }
158
+ update_option($this->db_options_widget_titles, $this->options_widget_titles);
159
+ }
160
+
161
+ /**
162
+ * Inserts a new group
163
+ *
164
+ * @param $term
165
+ * @param array $args
166
+ */
167
+ function doInsertGroup($term, $args = array(), $widget_title = '') {
168
+ $row = wp_insert_term($term, $this->taxonomy_name, $args);
169
+ $this->setWidgetTitleForGroup($term, $widget_title);
170
+
171
+ return ($row['term_id']);
172
+ }
173
+
174
  /**
175
  * Setup Group Categories Taxonomy
 
176
  *
177
+ * @WordPress action init
178
  */
179
+ function doRegisterTaxonomy() {
 
180
  /**
181
  * As we don't want to see the Menu Item we have to disable show_ui. This also disables the metabox on the posts and pages, so we add thse manually instead.
182
  * We remove the capabilities to manage, edit and delete the terms. We have written this part ourselves and don't use WordPress for these functions. The only one we use is the assign_terms.
183
  */
184
+ $labels = array(
185
+ 'name' => __('Category Groups', 'avh-ec'),
186
+ 'singular_name' => __('Category Group', 'avh-ec'),
187
+ 'search_items' => __('Search Category Groups', 'avh-ec'),
188
+ 'popular_items' => __('Popular Category Groups'),
189
+ 'all_items' => __('All Category Groups'),
190
+ 'parent_item' => __('Parent Category Group'),
191
+ 'parent_item_colon' => __('Parent Category Group:'),
192
+ 'edit_item' => __('Edit Category Group'),
193
+ 'update_item' => __('Update Category Group'),
194
+ 'add_new_item' => __('Add New Category Group'),
195
+ 'new_item_name' => __('New Category Group Name')
196
+ );
197
+ $caps = array(
198
+ 'manage_terms' => null,
199
+ 'edit_terms' => null,
200
+ 'delete_terms' => null,
201
+ 'assign_terms' => 'edit_posts'
202
+ );
203
+ register_taxonomy($this->taxonomy_name,
204
+ array('post', 'page'),
205
+ array(
206
+ 'hierarchical' => true,
207
+ 'labels' => $labels,
208
+ 'query_var' => true,
209
+ 'rewrite' => true,
210
+ 'show_in_nav_menus' => false,
211
+ 'public' => true,
212
+ 'show_ui' => false,
213
+ 'capabilities' => $caps
214
+ ));
215
  }
216
 
217
  /**
218
  * Setup the options for the widget titles
 
219
  *
220
+ * @WordPress action init
221
  */
222
+ function doSetupOptions() {
 
223
  // Setup the standard groups if the none group does not exists.
224
  $all_categories = $this->getAllCategoriesTermID();
225
  if (false === $this->getTermIDBy('slug', 'none')) {
226
+ $none_group_id = wp_insert_term('none',
227
+ $this->taxonomy_name,
228
+ array(
229
+ 'description' => __('This group will not show the widget.', 'avh-ec')
230
+ ));
231
+ $all_group_id = wp_insert_term('All',
232
+ $this->taxonomy_name,
233
+ array('description' => __('Holds all the categories.', 'avh-ec')));
234
+ $home_group_id = wp_insert_term('Home',
235
+ $this->taxonomy_name,
236
+ array(
237
+ 'description' => __('This group will be shown on the front page.',
238
+ 'avh-ec')
239
+ ));
240
 
241
  // Fill the standard groups with all categories
242
  $this->setCategoriesForGroup($home_group_id['term_id'], $all_categories);
245
  }
246
 
247
  $options = get_option($this->db_options_widget_titles);
248
+ if ( ! $options) {
249
+ $options = array();
250
+ $id = $this->getTermIDBy('slug', 'all');
251
+ $options[ $id ] = '';
252
+ $id = $this->getTermIDBy('slug', 'home');
253
+ $options[ $id ] = '';
254
  update_option($this->db_options_widget_titles, $options);
255
  }
256
  $this->options_widget_titles = $options;
258
  }
259
 
260
  /**
261
+ * Update a group
 
262
  *
263
+ * @param $group_id
264
+ * @param $selected_categories
265
+ * @param $widget_title
266
+ * return -1,0,1 Unknown Group, Duplicate Slug, Succesfull
267
  */
268
+ function doUpdateGroup($group_id, $args = array(), $selected_categories, $widget_title = '') {
269
+
270
+ $group = $this->getGroup($group_id);
271
+ if (is_object($group)) {
272
+ $id = wp_update_term($group->term_id, $this->taxonomy_name, $args);
273
+ if ( ! is_wp_error($id)) {
274
+ $this->setWidgetTitleForGroup($group_id, $widget_title);
275
+ $this->setCategoriesForGroup($group_id, $selected_categories);
276
+ $return = 1; // Succesful
277
+ } else {
278
+ $return = 0; // Duplicate Slug
279
+ }
280
+ } else {
281
+ $return = - 1; // Unknown group
282
+ }
283
+
284
+ return ($return);
285
  }
286
 
287
  /**
289
  *
290
  * @return array Term_id
291
  */
292
+ function getAllCategoriesTermID() {
293
+ $all_cat_id = array();
 
294
  $categories = get_categories();
295
+ if ( ! is_wp_error($categories)) {
296
  foreach ($categories as $category) {
297
  $all_cat_id[] = $category->term_id;
298
  }
299
  }
300
+
301
  return ($all_cat_id);
302
  }
303
 
305
  * Get the categories from the given group from the DB
306
  *
307
  * @param int $group_id The Taxonomy Term ID
 
308
  *
309
+ * @return Array|False categories. Will return FALSE, if the row does not exists.
310
  */
311
+ function getCategoriesFromGroup($group_id) {
 
312
  global $wpdb;
313
 
314
  // Query database
315
+ $result = $wpdb->get_results($wpdb->prepare('SELECT * FROM ' .
316
+ $wpdb->terms .
317
+ ' t, ' .
318
+ $wpdb->avhec_cat_group .
319
+ ' cg WHERE t.term_id = cg.term_id AND cg.group_term_id = %d',
320
+ $group_id));
321
 
322
  if (is_array($result)) { // Call succeeded
323
  if (empty($result)) { // No rows found
324
+ $return = array();
325
  } else {
326
  foreach ($result as $row) {
327
  $return[] = $row->term_id;
330
  } else {
331
  $return = false;
332
  }
333
+
334
  return ($return);
335
  }
336
 
337
  /**
338
+ * Gets all information of a group
339
  *
340
+ * @param $group_id
 
 
341
  *
342
+ * @return Object|False Returns False when the group doesn't exists.
343
  */
344
+ function getGroup($group_id) {
 
345
  global $wpdb;
346
 
347
+ $result = get_term((int) $group_id, $this->taxonomy_name);
348
+ if (null === $result) {
349
+ $result = false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
350
  }
351
 
352
+ return ($result);
353
  }
354
 
355
+ function getGroupByCategoryID($category_id) {
356
+ $return = get_term_by('slug', 'none', $this->taxonomy_name);
357
+ $cat_groups = get_terms($this->taxonomy_name, array('hide_empty' => false));
 
 
 
 
 
 
 
 
358
 
359
+ foreach ($cat_groups as $group) {
360
+ $cats = $this->getCategoriesFromGroup($group->term_id);
361
+ if ($group->slug != 'all' && in_array($category_id, $cats)) {
362
+ $return = $group;
363
+ break;
364
+ }
 
 
 
365
  }
 
 
366
 
367
+ return $return;
 
 
 
 
 
 
 
 
 
 
368
  }
369
 
370
  /**
371
  * Same as get_term_by, but returns the ID only if found, else false
372
+ *
373
  * @param string $field
374
  * @param string $value
375
+ *
376
  * @return int|boolean
377
  */
378
+ function getTermIDBy($field, $value) {
 
379
  $row = get_term_by($field, $value, $this->taxonomy_name);
380
  if (false === $row) {
381
  $return = false;
382
  } else {
383
  $return = (int) $row->term_id;
384
  }
385
+
386
  return ($return);
387
  }
388
 
389
  /**
390
+ * Return the title for a group_id if exsist otherwise return false
391
  *
392
  * @param $group_id
 
393
  */
394
+ function getWidgetTitleForGroup($group_id) {
395
+ if (isset($this->options_widget_titles[ $group_id ])) {
396
+ return ($this->options_widget_titles[ $group_id ]);
 
 
 
 
397
  }
 
 
398
 
399
+ return false;
 
 
 
 
 
 
 
 
 
 
 
 
400
  }
401
 
402
  /**
403
+ * Set the categories for the given group from the DB. Insert the group if it doesn't exists.
404
  *
405
+ * @param int $group_id The Taxonomy Term ID
406
+ * @param array $categories The categories
 
 
 
 
 
 
 
 
 
 
407
  *
408
+ * @return Object (false if not found)
409
  */
410
+ function setCategoriesForGroup($group_id, $categories = array()) {
 
 
411
  global $wpdb;
412
 
413
+ $old_categories = $this->getCategoriesFromGroup($group_id);
 
 
 
414
 
415
+ if ( ! is_array($categories)) {
416
+ $categories = array();
417
+ }
418
+ $new_categories = $categories;
419
+ sort($old_categories);
420
+ sort($new_categories);
421
+ // If the new and old values are the same, no need to update.
422
+ if ($new_categories === $old_categories) {
423
+ return false;
424
+ }
425
 
426
+ $new = array_diff($new_categories, $old_categories);
427
+ $removed = array_diff($old_categories, $new_categories);
 
 
 
 
 
 
 
 
 
428
 
429
+ if ( ! empty($new)) {
430
+ foreach ($new as $cat_term_id) {
431
+ $insert[] = '(' . $group_id . ',' . $cat_term_id . ')';
 
 
 
 
 
 
432
  }
433
+ $value = implode(',', $insert);
434
+ $sql = 'INSERT INTO ' . $wpdb->avhec_cat_group . ' (group_term_id, term_id) VALUES ' . $value;
435
+ $result = $wpdb->query($sql);
436
  }
437
+
438
+ if ( ! empty($removed)) {
439
+ $delete = implode(',', $removed);
440
+ $sql = $wpdb->prepare('DELETE FROM ' .
441
+ $wpdb->avhec_cat_group .
442
+ ' WHERE group_term_id=%d and term_id IN (' .
443
+ $delete .
444
+ ')',
445
+ $group_id);
446
+ $result = $wpdb->query($sql);
447
+ }
448
+
449
+ return $result;
450
  }
451
 
452
  /**
453
+ * Set the Widget Title for a Group
454
  *
455
+ * @param int $group_id
456
+ * @param string $widget_title
457
  */
458
+ function setWidgetTitleForGroup($group_id, $widget_title = '') {
459
+ $this->options_widget_titles[ $group_id ] = $widget_title;
460
+ update_option($this->db_options_widget_titles, $this->options_widget_titles);
 
461
  }
462
  }
463
+
464
  ?>
3.3/class/avh-ec.core.php CHANGED
@@ -1,295 +1,222 @@
1
  <?php
2
 
3
- class AVH_EC_Core
4
- {
5
- var $version;
6
- var $comment;
7
- var $info;
8
- var $db_options_core;
9
- var $default_options;
10
- var $default_options_general;
11
- var $default_options_category_group;
12
- var $default_options_sp_category_group;
13
-
14
- var $db_options_tax_meta;
15
-
16
- var $options;
17
-
18
  /**
19
- * PHP5 constructor
20
- *
 
 
21
  */
22
- function __construct ()
23
- {
24
- /**
25
- *
26
- * @var AVH_EC_Category_Group
27
- */
28
- $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
29
-
30
- $this->version = '4.0.2';
31
- $this->comment = '<!-- AVH Extended Categories version ' . $this->version . ' | http://blog.avirtualhome.com/wordpress-plugins/ -->';
32
- $this->db_options_core = 'avhec';
33
- $this->db_options_tax_meta = 'avhec-tax_meta';
34
-
35
- add_action('init', array ( &$this, 'handleInitializePlugin' ), 10);
36
- }
37
 
38
  /**
39
- * PHP4 Constructor
 
40
  *
41
- * @return AVHExtendedCategoriesCore
 
 
 
42
  */
43
- function AVH_EC_Core ()
44
- {
45
- $this->__construct();
46
- }
47
-
48
- function handleInitializePlugin ()
49
- {
50
- global $wpdb;
51
-
52
- $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
53
- $db_version = 4;
54
-
55
- $info['siteurl'] = get_option('siteurl');
56
- $info['plugin_dir'] = AVHEC_PLUGIN_DIR;
57
- $info['graphics_url'] = AVHEC_PLUGIN_URL . '/images';
58
-
59
- // Set class property for info
60
- $this->info = array ( 'home' => get_option('home'), 'siteurl' => $info['siteurl'], 'plugin_dir' => $info['plugin_dir'], 'js_dir' => $info['plugin_dir'] . '/js', 'graphics_url' => $info['graphics_url'] );
61
-
62
- // Set the default options
63
- $this->default_options_general = array ( 'version' => $this->version, 'dbversion' => $db_version, 'alternative_name_select_category' => '' );
64
-
65
- // Set the default category group options
66
- $no_group_id = $catgrp->getTermIDBy('slug', 'none');
67
- $home_group_id = $catgrp->getTermIDBy('slug', 'home');
68
- $default_group_id = $catgrp->getTermIDBy('slug', 'all');
69
- $this->default_options_category_group = array ( 'no_group' => $no_group_id, 'home_group' => $home_group_id, 'default_group' => $default_group_id );
70
-
71
- $this->default_options_sp_category_group = array ( 'home_group' => $home_group_id, 'category_group' => $default_group_id, 'day_group' => $default_group_id, 'month_group' => $default_group_id, 'year_group' => $default_group_id, 'author_group' => $default_group_id, 'search_group' => $default_group_id );
72
-
73
- $this->default_options = array ( 'general' => $this->default_options_general, 'cat_group' => $this->default_options_category_group, 'widget_titles' => array (), 'sp_cat_group' => $this->default_options_sp_category_group );
74
-
75
- /**
76
- * Set the options for the program
77
- *
78
- */
79
- $this->loadOptions();
80
-
81
- // Check if we have to do updates
82
- if ((! isset($this->options['general']['dbversion'])) || $this->options['general']['dbversion'] < $db_version) {
83
- $this->doUpdateOptions($db_version);
84
- }
85
-
86
- $db = new AVH_DB();
87
- if (! $db->field_exists('avhec_term_order', $wpdb->terms)) {
88
- $wpdb->query("ALTER TABLE $wpdb->terms ADD `avhec_term_order` INT( 4 ) NULL DEFAULT '0'");
89
  }
90
 
91
- $this->handleTextdomain();
92
- add_filter('get_terms_orderby', array ( &$this, 'applyOrderFilter' ), 10, 2);
93
-
94
- }
95
-
96
- function applyOrderFilter ($orderby, $args)
97
- {
98
- switch ($args['orderby']) {
99
- case 'avhec_manualorder':
100
- $new_orderby = 't.avhec_term_order';
101
- break;
102
- case 'avhec_3rdparty_mycategoryorder':
103
- $new_orderby = 't.term_order';
104
- break;
105
- default:
106
- $new_orderby = $orderby;
107
- break;
108
- }
109
- return $new_orderby;
110
  }
111
 
112
  /**
113
- * Loads the i18n
 
114
  *
115
- * @return
 
 
116
  */
117
- function handleTextdomain ()
118
- {
119
-
120
- load_plugin_textdomain('avh-ec', false, AVHEC_RELATIVE_PLUGIN_DIR . '/lang');
121
 
 
 
122
  }
123
 
124
  /**
125
- * Checks if running version is newer and do upgrades if necessary
126
- *
127
- * @since 1.2.3
128
  *
 
 
 
 
129
  */
130
- function doUpdateOptions ($db_version)
131
- {
132
- $options = $this->getOptions();
133
 
134
- // Add none existing sections and/or elements to the options
135
- foreach ($this->default_options as $section => $default_data) {
136
- if (! array_key_exists($section, $options)) {
137
- $options[$section] = $default_data;
138
- continue;
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  }
140
- foreach ($default_data as $element => $default_value) {
141
- if (! array_key_exists($element, $options[$section])) {
142
- $options[$section][$element] = $default_value;
143
- }
 
 
 
 
 
 
144
  }
145
- }
146
 
147
- // Remove none existing sections and/or elements from the options
148
- foreach ($options as $section => $data) {
149
- if (! array_key_exists($section, $this->default_options)) {
150
- unset($options[$section]);
151
- continue;
 
152
  }
153
- foreach ($data as $element => $value) {
154
- if (! array_key_exists($element, $this->default_options[$section])) {
155
- unset($options[$section][$element]);
156
- }
157
  }
 
158
  }
159
- /**
160
- * Update the options to the latests versions
161
- */
162
- $options['general']['version'] = $this->version;
163
- $options['general']['dbversion'] = $db_version;
164
- $this->saveOptions($options);
165
- }
166
 
167
- /**
168
- * Used in forms to set the checked option.
169
- *
170
- * @param mixed $checked
171
- * @param mixed_type $current
172
- * @return string
173
- *
174
- * @since 2.0
175
- */
176
- function isChecked ($checked, $current)
177
- {
178
- if ($checked == $current) {
179
- return (' checked="checked"');
180
  }
181
- return ('');
182
- }
183
 
184
- /**
185
- * Used in forms to set the SELECTED option
186
- *
187
- * @param string $current
188
- * @param string $field
189
- * @return string
190
- */
191
- function isSelected ($current, $field)
192
- {
193
- if ($current == $field) {
194
- return (' SELECTED');
 
 
 
 
 
 
 
 
 
 
 
 
195
  }
196
- return ('');
197
  }
198
 
199
  /**
200
- * Get the base directory of a directory structure
201
- *
202
- * @param string $directory
203
- * @return string
204
  *
 
 
 
205
  */
206
- function getBaseDirectory ($directory)
207
- {
208
- //place each directory into array and get the last element
209
- $return = end(explode('/', $directory));
210
 
211
- return $return;
 
212
  }
 
213
 
214
- /*********************************
215
- * *
216
- * Methods for variable: options *
217
- * *
218
- ********************************/
 
 
 
 
 
 
219
 
220
  /**
221
- * @param array $data
222
  */
223
- function setOptions ($options)
224
- {
225
- $this->options = $options;
226
- }
 
227
 
228
- /**
229
- * return array
230
- */
231
- function getOptions ()
232
- {
233
- return ($this->options);
234
- }
235
 
236
- /**
237
- * Save all current options and set the options
238
- *
239
- */
240
- function saveOptions ($options)
241
- {
242
- update_option($this->db_options_core, $options);
243
- wp_cache_flush(); // Delete cache
244
- $this->setOptions($options);
245
  }
246
 
247
  /**
248
- * Retrieves the plugin options from the WordPress options table and assigns to class variable.
249
- * If the options do not exists, like a new installation, the options are set to the default value.
250
  *
251
- * @return none
252
  */
253
- function loadOptions ()
254
- {
255
- $options = get_option($this->db_options_core);
256
- if (false === $options) { // New installation
257
- $this->resetToDefaultOptions();
258
- } else {
259
- $this->setOptions($options);
260
- }
261
  }
262
 
263
- /**
264
- * Get the value for an option element. If there's no option is set on the Admin page, return the default value.
265
- *
266
- * @param string $key
267
- * @param string $option
268
- * @return mixed
269
- */
270
- function getOptionElement ($option, $key)
271
- {
272
- if ($this->options[$option][$key]) {
273
- $return = $this->options[$option][$key]; // From Admin Page
274
- } else {
275
- $return = $this->default_options[$option][$key]; // Default
276
  }
277
- return ($return);
278
- }
279
 
280
- /**
281
- * Reset to default options and save in DB
282
- *
283
- */
284
- function resetToDefaultOptions ()
285
- {
286
- $this->options = $this->default_options;
287
- $this->saveOptions($this->default_options);
288
  }
289
 
290
  /**
291
  * Display or retrieve the HTML dropdown list of categories.
292
- *
293
  * The list of arguments is below:
294
  * 'show_option_all' (string) - Text to display for showing all categories.
295
  * 'show_option_none' (string) - Text to display for showing no categories.
@@ -309,7 +236,6 @@ class AVH_EC_Core
309
  * 'name' (string) - The name attribute value for selected element.
310
  * 'class' (string) - The class attribute value for selected element.
311
  * 'selected' (int) - Which category ID is selected.
312
- *
313
  * The 'hierarchical' argument, which is disabled by default, will override the
314
  * depth argument, unless it is true. When the argument is false, it will
315
  * display all of the categories. When it is enabled it will use the value in
@@ -318,32 +244,41 @@ class AVH_EC_Core
318
  * @since 2.1.0
319
  *
320
  * @param string|array $args Optional. Override default arguments.
 
321
  * @return string HTML content only if 'echo' argument is 0.
322
  */
323
- function avh_wp_dropdown_categories ($args = '', $selectedonly)
324
- {
325
  $mywalker = new AVH_Walker_CategoryDropdown();
326
 
327
  // @format_off
328
  $defaults = array(
329
- 'show_option_all' => '', 'show_option_none' => '',
330
- 'orderby' => 'id', 'order' => 'ASC',
331
- 'show_last_update' => 0, 'show_count' => 0,
332
- 'hide_empty' => 1, 'child_of' => 0,
333
- 'exclude' => '', 'echo' => 1,
334
- 'selected' => 0, 'hierarchical' => 0,
335
- 'name' => 'cat', 'id' => '',
336
- 'class' => 'postform', 'depth' => 0,
337
- 'tab_index' => 0, 'taxonomy' => 'category',
338
- 'walker' => $mywalker,
339
- 'hide_if_empty' => false
 
 
 
 
 
 
 
 
 
340
  );
341
  // @format_on
342
  $defaults['selected'] = (is_category()) ? get_query_var('cat') : 0;
343
 
344
  $r = wp_parse_args($args, $defaults);
345
 
346
- if (! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
347
  $r['pad_counts'] = true;
348
  }
349
 
@@ -351,34 +286,36 @@ class AVH_EC_Core
351
  extract($r);
352
 
353
  $tab_index_attribute = '';
354
- if ((int) $tab_index > 0)
355
  $tab_index_attribute = ' tabindex="' . $tab_index . '"';
 
356
 
357
  $categories = get_terms($taxonomy, $r);
358
- $name = esc_attr($name);
359
- $class = esc_attr($class);
360
- $id = $id ? esc_attr($id) : $name;
361
 
362
- if (! $r['hide_if_empty'] || ! empty($categories))
363
  $output = "<select name='$name' id='$id' class='$class' $tab_index_attribute>\n";
364
- else
365
  $output = '';
 
366
 
367
  if (empty($categories) && ! $r['hide_if_empty'] && ! empty($show_option_none)) {
368
  $show_option_none = apply_filters('list_cats', $show_option_none);
369
  $output .= "\t<option value='-1' selected='selected'>$show_option_none</option>\n";
370
  }
371
- if (! empty($categories)) {
372
 
373
  if ($show_option_all) {
374
  $show_option_all = apply_filters('list_cats', $show_option_all);
375
- $selected = ('0' === strval($r['selected'])) ? " selected='selected'" : '';
376
  $output .= "\t" . '<option value="0"' . $selected . '>' . $show_option_all . '</option>' . "\n";
377
  }
378
 
379
  if ($show_option_none) {
380
  $show_option_none = apply_filters('list_cats', $show_option_none);
381
- $selected = ('-1' === strval($r['selected'])) ? " selected='selected'" : '';
382
  $output .= "\t" . '<option value="-1"' . $selected . '>' . $show_option_none . '</option>' . "\n";
383
  }
384
 
@@ -389,20 +326,21 @@ class AVH_EC_Core
389
  }
390
  $output .= walk_category_dropdown_tree($categories, $depth, $r);
391
  }
392
- if (! $r['hide_if_empty'] || ! empty($categories))
393
  $output .= "</select>\n";
 
394
 
395
  $output = apply_filters('wp_dropdown_cats', $output);
396
 
397
- if ($echo)
398
  echo $output;
 
399
 
400
  return $output;
401
  }
402
 
403
  /**
404
  * Display or retrieve the HTML list of categories.
405
- *
406
  * The list of arguments is below:
407
  * 'show_option_all' (string) - Text to display for showing all categories.
408
  * 'orderby' (string) default is 'ID' - What column to use for ordering the
@@ -428,98 +366,368 @@ class AVH_EC_Core
428
  * 'title_li' (string) - See {@link get_categories()}.
429
  * 'depth' (int) - The max depth.
430
  *
431
- * @since 2.1.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
432
  *
433
- * @param string|array $args Optional. Override default arguments.
434
- * @return string HTML content only if 'echo' argument is 0.
435
  */
436
- function avh_wp_list_categories ($args = '', $selectedonly)
437
- {
438
- $mywalker = new AVHEC_Walker_Category();
439
- $defaults = array ( 'show_option_all' => '', 'orderby' => 'name', 'order' => 'ASC', 'show_last_update' => 0, 'style' => 'list', 'show_count' => 0, 'hide_empty' => 1, 'use_desc_for_title' => 1, 'child_of' => 0, 'feed' => '', 'feed_type' => '', 'feed_image' => '', 'exclude' => '', 'exclude_tree' => '', 'current_category' => 0, 'hierarchical' => true, 'title_li' => __('Categories'), 'echo' => 1, 'depth' => 0, 'walker' => $mywalker );
 
 
440
 
441
- $r = wp_parse_args($args, $defaults);
 
442
 
443
- if (! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
444
- $r['pad_counts'] = true;
445
- }
 
 
 
446
 
447
- if (! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
448
- $r['pad_counts'] = true;
449
- }
 
 
 
450
 
451
- if (isset($r['show_date'])) {
452
- $r['include_last_update_time'] = $r['show_date'];
453
- }
454
 
455
- if (true == $r['hierarchical']) {
456
- $r['exclude_tree'] = $r['exclude'];
457
- $r['exclude'] = '';
458
- }
459
 
460
- extract($r);
 
 
461
 
462
- $categories = get_categories($r);
 
 
 
 
 
 
 
463
 
464
- $output = '';
465
- if ($title_li && 'list' == $style)
466
- $output = '<li class="categories">' . $r['title_li'] . '<ul>';
 
 
 
467
 
468
- if (empty($categories)) {
469
- if ('list' == $style)
470
- $output .= '<li>' . __("No categories") . '</li>';
471
- else
472
- $output .= __("No categories");
473
- } else {
474
- global $wp_query;
 
 
475
 
476
- if (! empty($show_option_all))
477
- if ('list' == $style)
478
- $output .= '<li><a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a></li>';
479
- else
480
- $output .= '<a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a>';
 
 
 
 
481
 
482
- if (empty($r['current_category']) && is_category())
483
- $r['current_category'] = $wp_query->get_queried_object_id();
 
 
 
 
484
 
485
- if ($hierarchical) {
486
- $depth = $r['depth'];
487
- } else {
488
- $depth = - 1; // Flat.
489
- }
490
 
491
- $output .= walk_category_tree($categories, $depth, $r);
 
 
 
 
492
  }
493
 
494
- if ($title_li && 'list' == $style)
495
- $output .= '</ul></li>';
 
 
496
 
497
- $output = apply_filters('wp_list_categories', $output);
 
 
498
 
499
- if ($echo)
500
- echo $output;
501
- else
502
- return $output;
 
 
 
 
503
  }
504
 
505
- function getCategories ()
506
- {
507
- static $_categories = NULL;
508
- if (NULL === $_categories) {
509
- $_categories = get_categories('get=all');
 
 
 
 
 
 
 
510
  }
511
- return $_categories;
 
512
  }
513
 
514
- function getCategoriesId ($categories)
515
- {
516
- static $_categories_id = NULL;
517
- if (NULL == $_categories_id) {
518
- foreach ($categories as $key => $category) {
519
- $_categories_id[$category->term_id] = $key;
520
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
521
  }
522
- return $_categories_id;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
523
  }
524
  }
525
 
@@ -528,29 +736,32 @@ class AVH_EC_Core
528
  *
529
  * @uses Walker
530
  */
531
- class AVH_Walker_CategoryDropdown extends Walker_CategoryDropdown
532
- {
533
-
534
- function walk ($elements, $max_depth)
535
- {
536
 
537
- $args = array_slice(func_get_args(), 2);
538
  $output = '';
539
 
540
  if ($max_depth < - 1) //invalid parameter
 
541
  return $output;
 
542
 
543
  if (empty($elements)) //nothing to walk
 
544
  return $output;
 
545
 
546
- $id_field = $this->db_fields['id'];
547
  $parent_field = $this->db_fields['parent'];
548
 
549
  // flat display
550
  if (- 1 == $max_depth) {
551
- $empty_array = array ();
552
- foreach ($elements as $e)
553
  $this->display_element($e, $empty_array, 1, 0, $args, $output);
 
 
554
  return $output;
555
  }
556
 
@@ -560,13 +771,14 @@ class AVH_Walker_CategoryDropdown extends Walker_CategoryDropdown
560
  * children_elements is two dimensional array, eg.
561
  * children_elements[10][] contains all sub-elements whose parent is 10.
562
  */
563
- $top_level_elements = array ();
564
- $children_elements = array ();
565
  foreach ($elements as $e) {
566
- if (0 == $e->$parent_field)
567
  $top_level_elements[] = $e;
568
- else
569
- $children_elements[$e->$parent_field][] = $e;
 
570
  }
571
 
572
  /*
@@ -576,15 +788,16 @@ class AVH_Walker_CategoryDropdown extends Walker_CategoryDropdown
576
  if (empty($top_level_elements)) {
577
 
578
  $first = array_slice($elements, 0, 1);
579
- $root = $first[0];
580
 
581
- $top_level_elements = array ();
582
- $children_elements = array ();
583
  foreach ($elements as $e) {
584
- if ($root->$parent_field == $e->$parent_field)
585
  $top_level_elements[] = $e;
586
- else
587
- $children_elements[$e->$parent_field][] = $e;
 
588
  }
589
  }
590
 
@@ -597,163 +810,16 @@ class AVH_Walker_CategoryDropdown extends Walker_CategoryDropdown
597
  * then we got orphans, which should be displayed regardless
598
  */
599
  if ((0 == $max_depth) && count($children_elements) > 0) {
600
- $empty_array = array ();
601
- foreach ($children_elements as $orphans)
602
- foreach ($orphans as $op)
603
  $this->display_element($op, $empty_array, 1, 0, $args, $output);
 
 
604
  }
605
 
606
  return $output;
607
  }
608
  }
609
 
610
- /**
611
- * Create HTML list of categories.
612
- *
613
- * @uses Walker
614
- */
615
- class AVHEC_Walker_Category extends Walker
616
- {
617
- /**
618
- * @see Walker::$tree_type
619
- * @since 2.1.0
620
- * @var string
621
- */
622
- var $tree_type = 'category';
623
-
624
- /**
625
- * @see Walker::$db_fields
626
- * @since 2.1.0
627
- * @todo Decouple this
628
- * @var array
629
- */
630
- var $db_fields = array ( 'parent' => 'parent', 'id' => 'term_id' );
631
-
632
- /**
633
- * @see Walker::start_lvl()
634
- * @since 2.1.0
635
- *
636
- * @param string $output Passed by reference. Used to append additional content.
637
- * @param int $depth Depth of category. Used for tab indentation.
638
- * @param array $args Will only append content if style argument value is 'list'.
639
- */
640
- function start_lvl (&$output, $depth, $args)
641
- {
642
- if ('list' != $args['style'])
643
- return;
644
-
645
- $indent = str_repeat("\t", $depth);
646
- $output .= $indent . '<ul class="children">' . "\n";
647
- }
648
-
649
- /**
650
- * @see Walker::end_lvl()
651
- * @since 2.1.0
652
- *
653
- * @param string $output Passed by reference. Used to append additional content.
654
- * @param int $depth Depth of category. Used for tab indentation.
655
- * @param array $args Will only append content if style argument value is 'list'.
656
- */
657
- function end_lvl (&$output, $depth, $args)
658
- {
659
- if ('list' != $args['style'])
660
- return;
661
-
662
- $indent = str_repeat("\t", $depth);
663
- $output .= $indent . '</ul>' . "\n";
664
- }
665
-
666
- /**
667
- * @see Walker::start_el()
668
- * @since 2.1.0
669
- *
670
- * @param string $output Passed by reference. Used to append additional content.
671
- * @param object $category Category data object.
672
- * @param int $depth Depth of category in reference to parents.
673
- * @param array $args
674
- */
675
- function start_el (&$output, $category, $depth, $args)
676
- {
677
- extract($args);
678
-
679
- $cat_name = esc_attr($category->name);
680
- $cat_name = apply_filters('list_cats', $cat_name, $category);
681
- $link = '<div class="avhec-widget-line"><a href="' . get_category_link($category->term_id) . '" ';
682
- if ($use_desc_for_title == 0 || empty($category->description))
683
- $link .= 'title="' . sprintf(__('View all posts filed under %s'), $cat_name) . '"';
684
- else
685
- $link .= 'title="' . esc_attr(strip_tags(apply_filters('category_description', $category->description, $category))) . '"';
686
- $link .= '>';
687
- $link .= $cat_name . '</a>';
688
-
689
- if ((! empty($feed_image)) || (! empty($feed))) {
690
- $link .= '<div class="avhec-widget-rss"> ';
691
-
692
- if (empty($feed_image))
693
- $link .= '(';
694
-
695
- $link .= '<a href="' . get_category_feed_link($category->term_id, $feed_type) . '"';
696
-
697
- if (empty($feed))
698
- $alt = ' alt="' . sprintf(__('Feed for all posts filed under %s'), $cat_name) . '"';
699
- else {
700
- $title = ' title="' . $feed . '"';
701
- $alt = ' alt="' . $feed . '"';
702
- $name = $feed;
703
- $link .= $title;
704
- }
705
-
706
- $link .= '>';
707
-
708
- if (empty($feed_image))
709
- $link .= $name;
710
- else
711
- $link .= '<img src="' . $feed_image . '"' . $alt . $title . ' />';
712
- $link .= '</a>';
713
- if (empty($feed_image))
714
- $link .= ')';
715
- $link .= '</div>';
716
- }
717
-
718
- if (isset($show_count) && $show_count)
719
- $link .= '<div class="avhec-widget-count"> (' . intval($category->count) . ')</div>';
720
-
721
- if (isset($show_date) && $show_date) {
722
- $link .= ' ' . gmdate('Y-m-d', $category->last_update_timestamp);
723
- }
724
-
725
- if (isset($current_category) && $current_category)
726
- $_current_category = get_category($current_category);
727
-
728
- if ('list' == $args['style']) {
729
- $output .= "\t" . '<li';
730
- $class = 'cat-item cat-item-' . $category->term_id;
731
- if (isset($current_category) && $current_category && ($category->term_id == $current_category))
732
- $class .= ' current-cat';
733
- elseif (isset($_current_category) && $_current_category && ($category->term_id == $_current_category->parent))
734
- $class .= ' current-cat-parent';
735
- $output .= ' class="' . $class . '"';
736
- $output .= '>' . $link . '</div>' . "\n";
737
- } else {
738
- $output .= "\t" . $link . '</div><br />' . "\n";
739
- }
740
- }
741
-
742
- /**
743
- * @see Walker::end_el()
744
- * @since 2.1.0
745
- *
746
- * @param string $output Passed by reference. Used to append additional content.
747
- * @param object $page Not used.
748
- * @param int $depth Depth of category. Not used.
749
- * @param array $args Only uses 'list' for whether should append to output.
750
- */
751
- function end_el (&$output, $page, $depth, $args)
752
- {
753
- if ('list' != $args['style'])
754
- return;
755
-
756
- $output .= '</li>' . "\n";
757
- }
758
- }
759
  ?>
1
  <?php
2
 
3
+ /**
4
+ * Create HTML list of categories.
5
+ *
6
+ * @uses Walker
7
+ */
8
+ class AVHEC_Walker_Category extends Walker {
 
 
 
 
 
 
 
 
 
9
  /**
10
+ * @see Walker::$db_fields
11
+ * @since 2.1.0
12
+ * @todo Decouple this
13
+ * @var array
14
  */
15
+ var $db_fields = array('parent' => 'parent', 'id' => 'term_id');
16
+ /**
17
+ * @see Walker::$tree_type
18
+ * @since 2.1.0
19
+ * @var string
20
+ */
21
+ var $tree_type = 'category';
 
 
 
 
 
 
 
 
22
 
23
  /**
24
+ * @see Walker::end_el()
25
+ * @since 2.1.0
26
  *
27
+ * @param string $output Passed by reference. Used to append additional content.
28
+ * @param object $page Not used.
29
+ * @param int $depth Depth of category. Not used.
30
+ * @param array $args Only uses 'list' for whether should append to output.
31
  */
32
+ function end_el(&$output, $page, $depth, $args) {
33
+ if ('list' != $args['style']) {
34
+ return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  }
36
 
37
+ $output .= '</li>' . "\n";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  }
39
 
40
  /**
41
+ * @see Walker::end_lvl()
42
+ * @since 2.1.0
43
  *
44
+ * @param string $output Passed by reference. Used to append additional content.
45
+ * @param int $depth Depth of category. Used for tab indentation.
46
+ * @param array $args Will only append content if style argument value is 'list'.
47
  */
48
+ function end_lvl(&$output, $depth, $args) {
49
+ if ('list' != $args['style']) {
50
+ return;
51
+ }
52
 
53
+ $indent = str_repeat("\t", $depth);
54
+ $output .= $indent . '</ul>' . "\n";
55
  }
56
 
57
  /**
58
+ * @see Walker::start_el()
59
+ * @since 2.1.0
 
60
  *
61
+ * @param string $output Passed by reference. Used to append additional content.
62
+ * @param object $category Category data object.
63
+ * @param int $depth Depth of category in reference to parents.
64
+ * @param array $args
65
  */
66
+ function start_el(&$output, $category, $depth, $args) {
67
+ extract($args);
 
68
 
69
+ $cat_name = esc_attr($category->name);
70
+ $cat_name = apply_filters('list_cats', $cat_name, $category);
71
+ $link = '<div class="avhec-widget-line"><a href="' . get_category_link($category->term_id) . '" ';
72
+ if ($use_desc_for_title == 0 || empty($category->description)) {
73
+ $link .= 'title="' . sprintf(__('View all posts filed under %s'), $cat_name) . '"';
74
+ } else {
75
+ $link .= 'title="' .
76
+ esc_attr(strip_tags(apply_filters('category_description', $category->description, $category))) .
77
+ '"';
78
+ }
79
+ $link .= '>';
80
+ $link .= $cat_name . '</a>';
81
+
82
+ if (( ! empty($feed_image)) || ( ! empty($feed))) {
83
+ $link .= '<div class="avhec-widget-rss"> ';
84
+
85
+ if (empty($feed_image)) {
86
+ $link .= '(';
87
  }
88
+
89
+ $link .= '<a href="' . get_category_feed_link($category->term_id, $feed_type) . '"';
90
+
91
+ if (empty($feed)) {
92
+ $alt = ' alt="' . sprintf(__('Feed for all posts filed under %s'), $cat_name) . '"';
93
+ } else {
94
+ $title = ' title="' . $feed . '"';
95
+ $alt = ' alt="' . $feed . '"';
96
+ $name = $feed;
97
+ $link .= $title;
98
  }
 
99
 
100
+ $link .= '>';
101
+
102
+ if (empty($feed_image)) {
103
+ $link .= $name;
104
+ } else {
105
+ $link .= '<img src="' . $feed_image . '"' . $alt . $title . ' />';
106
  }
107
+ $link .= '</a>';
108
+ if (empty($feed_image)) {
109
+ $link .= ')';
 
110
  }
111
+ $link .= '</div>';
112
  }
 
 
 
 
 
 
 
113
 
114
+ if (isset($show_count) && $show_count) {
115
+ $link .= '<div class="avhec-widget-count"> (' . intval($category->count) . ')</div>';
 
 
 
 
 
 
 
 
 
 
 
116
  }
 
 
117
 
118
+ if (isset($show_date) && $show_date) {
119
+ $link .= ' ' . gmdate('Y-m-d', $category->last_update_timestamp);
120
+ }
121
+
122
+ if (isset($current_category) && $current_category) {
123
+ $_current_category = get_category($current_category);
124
+ }
125
+
126
+ if ('list' == $args['style']) {
127
+ $output .= "\t" . '<li';
128
+ $class = 'cat-item cat-item-' . $category->term_id;
129
+ if (isset($current_category) && $current_category && ($category->term_id == $current_category)) {
130
+ $class .= ' current-cat';
131
+ } elseif (isset($_current_category) &&
132
+ $_current_category &&
133
+ ($category->term_id == $_current_category->parent)
134
+ ) {
135
+ $class .= ' current-cat-parent';
136
+ }
137
+ $output .= ' class="' . $class . '"';
138
+ $output .= '>' . $link . '</div>' . "\n";
139
+ } else {
140
+ $output .= "\t" . $link . '</div><br />' . "\n";
141
  }
 
142
  }
143
 
144
  /**
145
+ * @see Walker::start_lvl()
146
+ * @since 2.1.0
 
 
147
  *
148
+ * @param string $output Passed by reference. Used to append additional content.
149
+ * @param int $depth Depth of category. Used for tab indentation.
150
+ * @param array $args Will only append content if style argument value is 'list'.
151
  */
152
+ function start_lvl(&$output, $depth, $args) {
153
+ if ('list' != $args['style']) {
154
+ return;
155
+ }
156
 
157
+ $indent = str_repeat("\t", $depth);
158
+ $output .= $indent . '<ul class="children">' . "\n";
159
  }
160
+ }
161
 
162
+ class AVH_EC_Core {
163
+ var $comment;
164
+ var $db_options_core;
165
+ var $db_options_tax_meta;
166
+ var $default_options;
167
+ var $default_options_category_group;
168
+ var $default_options_general;
169
+ var $default_options_sp_category_group;
170
+ var $info;
171
+ var $options;
172
+ var $version;
173
 
174
  /**
175
+ * PHP5 constructor
176
  */
177
+ function __construct() {
178
+ /**
179
+ * @var AVH_EC_Category_Group
180
+ */
181
+ $catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
182
 
183
+ $this->version = '4.0.3-dev.1';
184
+ $this->comment = '<!-- AVH Extended Categories version ' .
185
+ $this->version .
186
+ ' | http://blog.avirtualhome.com/wordpress-plugins/ -->';
187
+ $this->db_options_core = 'avhec';
188
+ $this->db_options_tax_meta = 'avhec-tax_meta';
 
189
 
190
+ add_action('init', array(&$this, 'handleInitializePlugin'), 10);
 
 
 
 
 
 
 
 
191
  }
192
 
193
  /**
194
+ * PHP4 Constructor
 
195
  *
196
+ * @return AVHExtendedCategoriesCore
197
  */
198
+ function AVH_EC_Core() {
199
+ $this->__construct();
 
 
 
 
 
 
200
  }
201
 
202
+ function applyOrderFilter($orderby, $args) {
203
+ switch ($args['orderby']) {
204
+ case 'avhec_manualorder':
205
+ $new_orderby = 't.avhec_term_order';
206
+ break;
207
+ case 'avhec_3rdparty_mycategoryorder':
208
+ $new_orderby = 't.term_order';
209
+ break;
210
+ default:
211
+ $new_orderby = $orderby;
212
+ break;
 
 
213
  }
 
 
214
 
215
+ return $new_orderby;
 
 
 
 
 
 
 
216
  }
217
 
218
  /**
219
  * Display or retrieve the HTML dropdown list of categories.
 
220
  * The list of arguments is below:
221
  * 'show_option_all' (string) - Text to display for showing all categories.
222
  * 'show_option_none' (string) - Text to display for showing no categories.
236
  * 'name' (string) - The name attribute value for selected element.
237
  * 'class' (string) - The class attribute value for selected element.
238
  * 'selected' (int) - Which category ID is selected.
 
239
  * The 'hierarchical' argument, which is disabled by default, will override the
240
  * depth argument, unless it is true. When the argument is false, it will
241
  * display all of the categories. When it is enabled it will use the value in
244
  * @since 2.1.0
245
  *
246
  * @param string|array $args Optional. Override default arguments.
247
+ *
248
  * @return string HTML content only if 'echo' argument is 0.
249
  */
250
+ function avh_wp_dropdown_categories($args = '', $selectedonly) {
 
251
  $mywalker = new AVH_Walker_CategoryDropdown();
252
 
253
  // @format_off
254
  $defaults = array(
255
+ 'show_option_all' => '',
256
+ 'show_option_none' => '',
257
+ 'orderby' => 'id',
258
+ 'order' => 'ASC',
259
+ 'show_last_update' => 0,
260
+ 'show_count' => 0,
261
+ 'hide_empty' => 1,
262
+ 'child_of' => 0,
263
+ 'exclude' => '',
264
+ 'echo' => 1,
265
+ 'selected' => 0,
266
+ 'hierarchical' => 0,
267
+ 'name' => 'cat',
268
+ 'id' => '',
269
+ 'class' => 'postform',
270
+ 'depth' => 0,
271
+ 'tab_index' => 0,
272
+ 'taxonomy' => 'category',
273
+ 'walker' => $mywalker,
274
+ 'hide_if_empty' => false
275
  );
276
  // @format_on
277
  $defaults['selected'] = (is_category()) ? get_query_var('cat') : 0;
278
 
279
  $r = wp_parse_args($args, $defaults);
280
 
281
+ if ( ! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
282
  $r['pad_counts'] = true;
283
  }
284
 
286
  extract($r);
287
 
288
  $tab_index_attribute = '';
289
+ if ((int) $tab_index > 0) {
290
  $tab_index_attribute = ' tabindex="' . $tab_index . '"';
291
+ }
292
 
293
  $categories = get_terms($taxonomy, $r);
294
+ $name = esc_attr($name);
295
+ $class = esc_attr($class);
296
+ $id = $id ? esc_attr($id) : $name;
297
 
298
+ if ( ! $r['hide_if_empty'] || ! empty($categories)) {
299
  $output = "<select name='$name' id='$id' class='$class' $tab_index_attribute>\n";
300
+ } else {
301
  $output = '';
302
+ }
303
 
304
  if (empty($categories) && ! $r['hide_if_empty'] && ! empty($show_option_none)) {
305
  $show_option_none = apply_filters('list_cats', $show_option_none);
306
  $output .= "\t<option value='-1' selected='selected'>$show_option_none</option>\n";
307
  }
308
+ if ( ! empty($categories)) {
309
 
310
  if ($show_option_all) {
311
  $show_option_all = apply_filters('list_cats', $show_option_all);
312
+ $selected = ('0' === strval($r['selected'])) ? " selected='selected'" : '';
313
  $output .= "\t" . '<option value="0"' . $selected . '>' . $show_option_all . '</option>' . "\n";
314
  }
315
 
316
  if ($show_option_none) {
317
  $show_option_none = apply_filters('list_cats', $show_option_none);
318
+ $selected = ('-1' === strval($r['selected'])) ? " selected='selected'" : '';
319
  $output .= "\t" . '<option value="-1"' . $selected . '>' . $show_option_none . '</option>' . "\n";
320
  }
321
 
326
  }
327
  $output .= walk_category_dropdown_tree($categories, $depth, $r);
328
  }
329
+ if ( ! $r['hide_if_empty'] || ! empty($categories)) {
330
  $output .= "</select>\n";
331
+ }
332
 
333
  $output = apply_filters('wp_dropdown_cats', $output);
334
 
335
+ if ($echo) {
336
  echo $output;
337
+ }
338
 
339
  return $output;
340
  }
341
 
342
  /**
343
  * Display or retrieve the HTML list of categories.
 
344
  * The list of arguments is below:
345
  * 'show_option_all' (string) - Text to display for showing all categories.
346
  * 'orderby' (string) default is 'ID' - What column to use for ordering the
366
  * 'title_li' (string) - See {@link get_categories()}.
367
  * 'depth' (int) - The max depth.
368
  *
369
+ * @since 2.1.0
370
+ *
371
+ * @param string|array $args Optional. Override default arguments.
372
+ *
373
+ * @return string HTML content only if 'echo' argument is 0.
374
+ */
375
+ function avh_wp_list_categories($args = '', $selectedonly) {
376
+ $mywalker = new AVHEC_Walker_Category();
377
+ $defaults = array(
378
+ 'show_option_all' => '',
379
+ 'orderby' => 'name',
380
+ 'order' => 'ASC',
381
+ 'show_last_update' => 0,
382
+ 'style' => 'list',
383
+ 'show_count' => 0,
384
+ 'hide_empty' => 1,
385
+ 'use_desc_for_title' => 1,
386
+ 'child_of' => 0,
387
+ 'feed' => '',
388
+ 'feed_type' => '',
389
+ 'feed_image' => '',
390
+ 'exclude' => '',
391
+ 'exclude_tree' => '',
392
+ 'current_category' => 0,
393
+ 'hierarchical' => true,
394
+ 'title_li' => __('Categories'),
395
+ 'echo' => 1,
396
+ 'depth' => 0,
397
+ 'walker' => $mywalker
398
+ );
399
+
400
+ $r = wp_parse_args($args, $defaults);
401
+
402
+ if ( ! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
403
+ $r['pad_counts'] = true;
404
+ }
405
+
406
+ if ( ! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
407
+ $r['pad_counts'] = true;
408
+ }
409
+
410
+ if (isset($r['show_date'])) {
411
+ $r['include_last_update_time'] = $r['show_date'];
412
+ }
413
+
414
+ if (true == $r['hierarchical']) {
415
+ $r['exclude_tree'] = $r['exclude'];
416
+ $r['exclude'] = '';
417
+ }
418
+
419
+ extract($r);
420
+
421
+ $categories = get_categories($r);
422
+
423
+ $output = '';
424
+ if ($title_li && 'list' == $style) {
425
+ $output = '<li class="categories">' . $r['title_li'] . '<ul>';
426
+ }
427
+
428
+ if (empty($categories)) {
429
+ if ('list' == $style) {
430
+ $output .= '<li>' . __("No categories") . '</li>';
431
+ } else {
432
+ $output .= __("No categories");
433
+ }
434
+ } else {
435
+ global $wp_query;
436
+
437
+ if ( ! empty($show_option_all)) {
438
+ if ('list' == $style) {
439
+ $output .= '<li><a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a></li>';
440
+ } else {
441
+ $output .= '<a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a>';
442
+ }
443
+ }
444
+
445
+ if (empty($r['current_category']) && is_category()) {
446
+ $r['current_category'] = $wp_query->get_queried_object_id();
447
+ }
448
+
449
+ if ($hierarchical) {
450
+ $depth = $r['depth'];
451
+ } else {
452
+ $depth = - 1; // Flat.
453
+ }
454
+
455
+ $output .= walk_category_tree($categories, $depth, $r);
456
+ }
457
+
458
+ if ($title_li && 'list' == $style) {
459
+ $output .= '</ul></li>';
460
+ }
461
+
462
+ $output = apply_filters('wp_list_categories', $output);
463
+
464
+ if ($echo) {
465
+ echo $output;
466
+ } else {
467
+ return $output;
468
+ }
469
+ }
470
+
471
+ /**
472
+ * Checks if running version is newer and do upgrades if necessary
473
+ *
474
+ * @since 1.2.3
475
+ */
476
+ function doUpdateOptions($db_version) {
477
+ $options = $this->getOptions();
478
+
479
+ // Add none existing sections and/or elements to the options
480
+ foreach ($this->default_options as $section => $default_data) {
481
+ if ( ! array_key_exists($section, $options)) {
482
+ $options[ $section ] = $default_data;
483
+ continue;
484
+ }
485
+ foreach ($default_data as $element => $default_value) {
486
+ if ( ! array_key_exists($element, $options[ $section ])) {
487
+ $options[ $section ][ $element ] = $default_value;
488
+ }
489
+ }
490
+ }
491
+
492
+ // Remove none existing sections and/or elements from the options
493
+ foreach ($options as $section => $data) {
494
+ if ( ! array_key_exists($section, $this->default_options)) {
495
+ unset($options[ $section ]);
496
+ continue;
497
+ }
498
+ foreach ($data as $element => $value) {
499
+ if ( ! array_key_exists($element, $this->default_options[ $section ])) {
500
+ unset($options[ $section ][ $element ]);
501
+ }
502
+ }
503
+ }
504
+ /**
505
+ * Update the options to the latests versions
506
+ */
507
+ $options['general']['version'] = $this->version;
508
+ $options['general']['dbversion'] = $db_version;
509
+ $this->saveOptions($options);
510
+ }
511
+
512
+ /**
513
+ * Get the base directory of a directory structure
514
+ *
515
+ * @param string $directory
516
+ *
517
+ * @return string
518
+ */
519
+ function getBaseDirectory($directory) {
520
+ //place each directory into array and get the last element
521
+ $return = end(explode('/', $directory));
522
+
523
+ return $return;
524
+ }
525
+
526
+ function getCategories() {
527
+ static $_categories = null;
528
+ if (null === $_categories) {
529
+ $_categories = get_categories('get=all');
530
+ }
531
+
532
+ return $_categories;
533
+ }
534
+
535
+ function getCategoriesId($categories) {
536
+ static $_categories_id = null;
537
+ if (null == $_categories_id) {
538
+ foreach ($categories as $key => $category) {
539
+ $_categories_id[ $category->term_id ] = $key;
540
+ }
541
+ }
542
+
543
+ return $_categories_id;
544
+ }
545
+
546
+ /*********************************
547
+ * *
548
+ * Methods for variable: options *
549
+ * *
550
+ ********************************/
551
+
552
+ /**
553
+ * Get the value for an option element. If there's no option is set on the Admin page, return the default value.
554
+ *
555
+ * @param string $key
556
+ * @param string $option
557
  *
558
+ * @return mixed
 
559
  */
560
+ function getOptionElement($option, $key) {
561
+ if ($this->options[ $option ][ $key ]) {
562
+ $return = $this->options[ $option ][ $key ]; // From Admin Page
563
+ } else {
564
+ $return = $this->default_options[ $option ][ $key ]; // Default
565
+ }
566
 
567
+ return ($return);
568
+ }
569
 
570
+ /**
571
+ * return array
572
+ */
573
+ function getOptions() {
574
+ return ($this->options);
575
+ }
576
 
577
+ /**
578
+ * @param array $data
579
+ */
580
+ function setOptions($options) {
581
+ $this->options = $options;
582
+ }
583
 
584
+ function handleInitializePlugin() {
585
+ global $wpdb;
 
586
 
587
+ $catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
588
+ $db_version = 4;
 
 
589
 
590
+ $info['siteurl'] = get_option('siteurl');
591
+ $info['plugin_dir'] = AVHEC_PLUGIN_DIR;
592
+ $info['graphics_url'] = AVHEC_PLUGIN_URL . '/images';
593
 
594
+ // Set class property for info
595
+ $this->info = array(
596
+ 'home' => get_option('home'),
597
+ 'siteurl' => $info['siteurl'],
598
+ 'plugin_dir' => $info['plugin_dir'],
599
+ 'js_dir' => $info['plugin_dir'] . '/js',
600
+ 'graphics_url' => $info['graphics_url']
601
+ );
602
 
603
+ // Set the default options
604
+ $this->default_options_general = array(
605
+ 'version' => $this->version,
606
+ 'dbversion' => $db_version,
607
+ 'alternative_name_select_category' => ''
608
+ );
609
 
610
+ // Set the default category group options
611
+ $no_group_id = $catgrp->getTermIDBy('slug', 'none');
612
+ $home_group_id = $catgrp->getTermIDBy('slug', 'home');
613
+ $default_group_id = $catgrp->getTermIDBy('slug', 'all');
614
+ $this->default_options_category_group = array(
615
+ 'no_group' => $no_group_id,
616
+ 'home_group' => $home_group_id,
617
+ 'default_group' => $default_group_id
618
+ );
619
 
620
+ $this->default_options_sp_category_group = array(
621
+ 'home_group' => $home_group_id,
622
+ 'category_group' => $default_group_id,
623
+ 'day_group' => $default_group_id,
624
+ 'month_group' => $default_group_id,
625
+ 'year_group' => $default_group_id,
626
+ 'author_group' => $default_group_id,
627
+ 'search_group' => $default_group_id
628
+ );
629
 
630
+ $this->default_options = array(
631
+ 'general' => $this->default_options_general,
632
+ 'cat_group' => $this->default_options_category_group,
633
+ 'widget_titles' => array(),
634
+ 'sp_cat_group' => $this->default_options_sp_category_group
635
+ );
636
 
637
+ /**
638
+ * Set the options for the program
639
+ */
640
+ $this->loadOptions();
 
641
 
642
+ // Check if we have to do updates
643
+ if (( ! isset($this->options['general']['dbversion'])) ||
644
+ $this->options['general']['dbversion'] < $db_version
645
+ ) {
646
+ $this->doUpdateOptions($db_version);
647
  }
648
 
649
+ $db = new AVH_DB();
650
+ if ( ! $db->field_exists('avhec_term_order', $wpdb->terms)) {
651
+ $wpdb->query("ALTER TABLE $wpdb->terms ADD `avhec_term_order` INT( 4 ) NULL DEFAULT '0'");
652
+ }
653
 
654
+ $this->handleTextdomain();
655
+ add_filter('get_terms_orderby', array(&$this, 'applyOrderFilter'), 10, 2);
656
+ }
657
 
658
+ /**
659
+ * Loads the i18n
660
+ *
661
+ * @return
662
+ */
663
+ function handleTextdomain() {
664
+
665
+ load_plugin_textdomain('avh-ec', false, AVHEC_RELATIVE_PLUGIN_DIR . '/lang');
666
  }
667
 
668
+ /**
669
+ * Used in forms to set the checked option.
670
+ *
671
+ * @param mixed $checked
672
+ * @param mixed_type $current
673
+ *
674
+ * @return string
675
+ * @since 2.0
676
+ */
677
+ function isChecked($checked, $current) {
678
+ if ($checked == $current) {
679
+ return (' checked="checked"');
680
  }
681
+
682
+ return ('');
683
  }
684
 
685
+ /**
686
+ * Used in forms to set the SELECTED option
687
+ *
688
+ * @param string $current
689
+ * @param string $field
690
+ *
691
+ * @return string
692
+ */
693
+ function isSelected($current, $field) {
694
+ if ($current == $field) {
695
+ return (' SELECTED');
696
+ }
697
+
698
+ return ('');
699
+ }
700
+
701
+ /**
702
+ * Retrieves the plugin options from the WordPress options table and assigns to class variable.
703
+ * If the options do not exists, like a new installation, the options are set to the default value.
704
+ *
705
+ * @return none
706
+ */
707
+ function loadOptions() {
708
+ $options = get_option($this->db_options_core);
709
+ if (false === $options) { // New installation
710
+ $this->resetToDefaultOptions();
711
+ } else {
712
+ $this->setOptions($options);
713
  }
714
+ }
715
+
716
+ /**
717
+ * Reset to default options and save in DB
718
+ */
719
+ function resetToDefaultOptions() {
720
+ $this->options = $this->default_options;
721
+ $this->saveOptions($this->default_options);
722
+ }
723
+
724
+ /**
725
+ * Save all current options and set the options
726
+ */
727
+ function saveOptions($options) {
728
+ update_option($this->db_options_core, $options);
729
+ wp_cache_flush(); // Delete cache
730
+ $this->setOptions($options);
731
  }
732
  }
733
 
736
  *
737
  * @uses Walker
738
  */
739
+ class AVH_Walker_CategoryDropdown extends Walker_CategoryDropdown {
740
+ function walk($elements, $max_depth) {
 
 
 
741
 
742
+ $args = array_slice(func_get_args(), 2);
743
  $output = '';
744
 
745
  if ($max_depth < - 1) //invalid parameter
746
+ {
747
  return $output;
748
+ }
749
 
750
  if (empty($elements)) //nothing to walk
751
+ {
752
  return $output;
753
+ }
754
 
755
+ $id_field = $this->db_fields['id'];
756
  $parent_field = $this->db_fields['parent'];
757
 
758
  // flat display
759
  if (- 1 == $max_depth) {
760
+ $empty_array = array();
761
+ foreach ($elements as $e) {
762
  $this->display_element($e, $empty_array, 1, 0, $args, $output);
763
+ }
764
+
765
  return $output;
766
  }
767
 
771
  * children_elements is two dimensional array, eg.
772
  * children_elements[10][] contains all sub-elements whose parent is 10.
773
  */
774
+ $top_level_elements = array();
775
+ $children_elements = array();
776
  foreach ($elements as $e) {
777
+ if (0 == $e->$parent_field) {
778
  $top_level_elements[] = $e;
779
+ } else {
780
+ $children_elements[ $e->$parent_field ][] = $e;
781
+ }
782
  }
783
 
784
  /*
788
  if (empty($top_level_elements)) {
789
 
790
  $first = array_slice($elements, 0, 1);
791
+ $root = $first[0];
792
 
793
+ $top_level_elements = array();
794
+ $children_elements = array();
795
  foreach ($elements as $e) {
796
+ if ($root->$parent_field == $e->$parent_field) {
797
  $top_level_elements[] = $e;
798
+ } else {
799
+ $children_elements[ $e->$parent_field ][] = $e;
800
+ }
801
  }
802
  }
803
 
810
  * then we got orphans, which should be displayed regardless
811
  */
812
  if ((0 == $max_depth) && count($children_elements) > 0) {
813
+ $empty_array = array();
814
+ foreach ($children_elements as $orphans) {
815
+ foreach ($orphans as $op) {
816
  $this->display_element($op, $empty_array, 1, 0, $args, $output);
817
+ }
818
+ }
819
  }
820
 
821
  return $output;
822
  }
823
  }
824
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
825
  ?>
3.3/class/avh-ec.widgets.php CHANGED
@@ -1,175 +1,228 @@
1
  <?php
2
 
3
  /**
4
- * Widget Class for displaying categories. Extended version of the dfeault categories.
5
- *
6
  */
7
- class WP_Widget_AVH_ExtendedCategories_Normal extends WP_Widget
8
- {
9
- /**
10
- *
11
- * @var AVH_EC_Core
12
- */
13
- var $core;
14
-
15
- /**
16
- * PHP 5 Constructor
17
- *
18
- */
19
- function __construct ()
20
- {
21
- $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core');
22
-
23
- //Convert the old option widget_extended_categories to widget_extended-categories
24
- $old = get_option('widget_extended_categories');
25
- if (! (FALSE === $old)) {
26
- update_option('widget_extended-categories', $old);
27
- delete_option('widget_extended_categories');
28
- }
29
- $widget_ops = array ( 'description' => __("An extended version of the default Categories widget.", 'avh-ec') );
30
- WP_Widget::__construct('extended-categories', 'AVH Extended Categories', $widget_ops);
31
-
32
- add_action('wp_print_styles', array ( &$this, 'actionWpPrintStyles' ));
33
 
 
 
34
  }
35
 
36
- function WP_Widget_AVH_ExtendedCategories_Normal ()
37
- {
38
- $this->__construct();
39
  }
40
 
41
- function actionWpPrintStyles ()
42
- {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
- if (! (FALSE === is_active_widget(FALSE, FALSE, $this->id_base, TRUE))) {
45
- wp_register_style('avhec-widget', AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', array (), $this->core->version);
46
- wp_enqueue_style('avhec-widget');
47
- }
48
  }
49
 
50
  /**
51
- * Display the widget
 
 
 
 
52
  *
53
- * @param unknown_type $args
54
- * @param unknown_type $instance
 
 
 
 
 
55
  */
56
- function widget ($args, $instance)
57
- {
58
-
59
- extract($args);
60
 
61
- $selectedonly = $instance['selectedonly'] ? TRUE : FALSE;
62
- $c = $instance['count'] ? TRUE : FALSE;
63
- $h = $instance['hierarchical'] ? TRUE : FALSE;
64
- $d = $instance['depth'] ? $instance['depth'] : 0;
65
- $e = $instance['hide_empty'] ? TRUE : FALSE;
66
- $use_desc_for_title = $instance['use_desc_for_title'] ? TRUE : FALSE;
67
- $s = $instance['sort_column'] ? $instance['sort_column'] : 'name';
68
- $o = $instance['sort_order'] ? $instance['sort_order'] : 'asc';
69
- $r = $instance['rssfeed'] ? 'RSS' : '';
70
- $i = $instance['rssimage'] ? $instance['rssimage'] : '';
71
- $invert = $instance['invert_included'] ? TRUE : FALSE;
72
 
73
- if (empty($r)) {
74
- $i = '';
 
75
  }
76
 
77
- if (empty($d)) {
78
- $d = 0;
 
79
  }
80
 
81
- $title = apply_filters('widget_title', empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']);
82
- $style = empty($instance['style']) ? 'list' : $instance['style'];
83
 
84
- $included_cats = '';
85
- if ($instance['post_category']) {
86
- $post_category = unserialize($instance['post_category']);
87
- $children = array ();
88
- if (! $instance['selectedonly']) {
89
- foreach ($post_category as $cat_id) {
90
- $children = array_merge($children, get_term_children($cat_id, 'category'));
91
- }
92
  }
93
- $included_cats = implode(",", array_merge($post_category, $children));
 
94
  }
95
 
96
- if ($invert) {
97
- $inc_exc = 'exclude';
98
- } else {
99
- $inc_exc = 'include';
 
 
 
 
 
 
 
 
 
 
100
  }
101
 
102
- $options = $this->core->getOptions();
103
- $show_option_none = __('Select Category', 'avh-ec');
104
- if ($options['general']['alternative_name_select_category']) {
105
- $show_option_none = $options['general']['alternative_name_select_category'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  }
107
 
108
- $cat_args = array ( $inc_exc => $included_cats, 'orderby' => $s, 'order' => $o, 'show_count' => $c, 'use_desc_for_title' => $use_desc_for_title, 'hide_empty' => $e, 'hierarchical' => $h, 'depth' => $d, 'title_li' => '', 'show_option_none' => $show_option_none, 'feed' => $r, 'feed_image' => $i, 'name' => 'extended-categories-select-' . $this->number );
109
- echo $before_widget;
110
- echo $this->core->comment;
111
- echo $before_title . $title . $after_title;
112
 
113
- if ($style == 'list') {
114
- echo '<ul>';
115
- $this->core->avh_wp_list_categories($cat_args, $selectedonly);
116
- echo '</ul>';
117
- } else {
118
- $this->core->avh_wp_dropdown_categories($cat_args, $selectedonly);
119
- echo '<script type=\'text/javascript\'>' . "\n";
120
- echo '/* <![CDATA[ */' . "\n";
121
- echo ' var ec_dropdown_' . $this->number . ' = document.getElementById("extended-categories-select-' . $this->number . '");' . "\n";
122
- echo ' function ec_onCatChange_' . $this->number . '() {' . "\n";
123
- echo ' if ( ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value > 0 ) {' . "\n";
124
- echo ' location.href = "' .home_url() . '/?cat="+ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value;' . "\n";
125
- echo ' }' . "\n";
126
- echo ' }' . "\n";
127
- echo ' ec_dropdown_' . $this->number . '.onchange = ec_onCatChange_' . $this->number . ';' . "\n";
128
- echo '/* ]]> */' . "\n";
129
- echo '</script>' . "\n";
130
  }
131
- echo $after_widget;
 
132
  }
 
133
 
 
 
 
 
134
  /**
135
- * When Widget Control Form Is Posted
136
- *
137
- * @param unknown_type $new_instance
138
- * @param unknown_type $old_instance
139
- * @return unknown
140
  */
141
- function update ($new_instance, $old_instance)
142
- {
143
- // update the instance's settings
144
- if (! isset($new_instance['submit'])) {
145
- return FALSE;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
  }
 
147
 
148
- $instance = $old_instance;
149
 
150
- $instance['title'] = strip_tags(stripslashes($new_instance['title']));
151
- $instance['selectedonly'] = $new_instance['selectedonly'] ? TRUE : FALSE;
152
- $instance['count'] = $new_instance['count'] ? TRUE : FALSE;
153
- $instance['hierarchical'] = $new_instance['hierarchical'] ? TRUE : FALSE;
154
- $instance['hide_empty'] = $new_instance['hide_empty'] ? TRUE : FALSE;
155
- $instance['use_desc_for_title'] = $new_instance['use_desc_for_title'] ? TRUE : FALSE;
156
- $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column']));
157
- $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order']));
158
- $instance['style'] = strip_tags(stripslashes($new_instance['style']));
159
- $instance['rssfeed'] = $new_instance['rssfeed'] ? TRUE : FALSE;
160
- $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage']));
161
- if (array_key_exists('all', $new_instance['post_category'])) {
162
- $instance['post_category'] = FALSE;
 
 
 
 
163
  } else {
164
- $instance['post_category'] = serialize($new_instance['post_category']);
165
  }
166
- $instance['depth'] = (int) $new_instance['depth'];
167
- if ($instance['depth'] < 0 || 11 < $instance['depth']) {
168
- $instance['depth'] = 0;
 
 
 
 
 
 
 
 
 
169
  }
170
- $instance['invert_included'] = $new_instance['invert_included'] ? TRUE : FALSE;
171
 
172
- return $instance;
 
 
 
173
  }
174
 
175
  /**
@@ -177,402 +230,190 @@ class WP_Widget_AVH_ExtendedCategories_Normal extends WP_Widget
177
  *
178
  * @param unknown_type $instance
179
  */
180
- function form ($instance)
181
- {
182
  // displays the widget admin form
183
- $instance = wp_parse_args((array) $instance, array ( 'title' => '', 'rssimage' => '', 'depth' => 0 ));
184
 
185
  // Prepare data for display
186
- $depth = (int) $instance['depth'];
187
- if ($depth < 0 || 11 < $depth) {
188
- $depth = 0;
189
- }
190
- $selected_cats = ($instance['post_category'] != '') ? unserialize($instance['post_category']) : FALSE;
191
-
 
 
 
 
 
 
 
 
 
 
 
 
192
  echo '<p>';
193
- avh_doWidgetFormText($this->get_field_id('title'), $this->get_field_name('title'), __('Title', 'avh-ec'), $instance['title']);
 
 
 
194
  echo '</p>';
195
 
196
  echo '<p>';
197
- avh_doWidgetFormCheckbox($this->get_field_id('selectedonly'), $this->get_field_name('selectedonly'), __('Show selected categories only', 'avh-ec'), (bool) $instance['selectedonly']);
198
-
199
- avh_doWidgetFormCheckbox($this->get_field_id('count'), $this->get_field_name('count'), __('Show post counts', 'avh-ec'), (bool) $instance['count']);
200
-
201
- avh_doWidgetFormCheckbox($this->get_field_id('hierarchical'), $this->get_field_name('hierarchical'), __('Show hierarchy', 'avh-ec'), (bool) $instance['hierarchical']);
202
-
203
- $options = array ( 0 => __('All Levels', 'avh-ec'), 1 => __('Toplevel only', 'avh-ec') );
204
- for ($i = 2; $i <= 11; $i ++) {
205
- $options[$i] = __('Child ', 'avh-ec') . ($i - 1);
206
- }
207
- avh_doWidgetFormSelect($this->get_field_id('depth'), $this->get_field_name('depth'), __('How many levels to show', 'avh-ec'), $options, $depth);
208
- unset($options);
209
 
210
- avh_doWidgetFormCheckbox($this->get_field_id('hide_empty'), $this->get_field_name('hide_empty'), __('Hide empty categories', 'avh-ec'), (bool) $instance['hide_empty']);
211
-
212
- avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'), $this->get_field_name('use_desc_for_title'), __('Use description for title', 'avh-ec'), (bool) $instance['use_desc_for_title']);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
  echo '</p>';
214
 
215
  echo '<p>';
216
- $options['ID'] = __('ID', 'avh-ec');
217
- $options['name'] = __('Name', 'avh-ec');
218
  $options['count'] = __('Count', 'avh-ec');
219
- $options['slug'] = __('Slug', 'avh-ec');
220
- $options['avhec_manualorder'] = 'AVH EC ' . __('Manual Order', 'avh-ec');
221
- if (is_plugin_active('my-category-order/mycategoryorder.php')) {
222
- $options['avhec_3rdparty_mycategoryorder'] = 'My Category Order';
223
- }
224
-
225
- avh_doWidgetFormSelect($this->get_field_id('sort_column'), $this->get_field_name('sort_column'), __('Sort by', 'avh-ec'), $options, $instance['sort_column']);
226
  unset($options);
227
 
228
- $options['asc'] = __('Ascending', 'avh-ec');
229
  $options['desc'] = __('Descending', 'avh-ec');
230
- avh_doWidgetFormSelect($this->get_field_id('sort_order'), $this->get_field_name('sort_order'), __('Sort order', 'avh-ec'), $options, $instance['sort_order']);
 
 
 
 
231
  unset($options);
232
 
233
  $options['list'] = __('List', 'avh-ec');
234
  $options['drop'] = __('Drop down', 'avh-ec');
235
- avh_doWidgetFormSelect($this->get_field_id('style'), $this->get_field_name('style'), __('Display style', 'avh-ec'), $options, $instance['style']);
 
 
 
 
236
  unset($options);
237
  echo '</p>';
238
 
239
  echo '<p>';
240
 
241
- avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), $this->get_field_name('rssfeed'), __('Show RSS Feed', 'avh-ec'), (bool) $instance['rssfeed']);
242
-
243
- avh_doWidgetFormText($this->get_field_id('rssimage'), $this->get_field_name('rssimage'), __('Path (URI) to RSS image', 'avh-ec'), $instance['rssimage']);
 
244
 
 
 
 
 
245
  echo '</p>';
246
 
247
  echo '<p>';
248
- echo '<b>' . __('Select categories', 'avh-ec') . '</b><hr />';
249
  echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear" style="list-style-type: none; margin-left: 5px; padding-left: 0px; margin-bottom: 20px;">';
250
- echo '<li id="' . $this->get_field_id('category--1') . '" class="popular-category">';
251
- echo '<label for="' . $this->get_field_id('post_category') . '" class="selectit">';
252
- echo '<input value="all" id="' . $this->get_field_id('post_category') . '" name="' . $this->get_field_name('post_category') . '[all]" type="checkbox" ' . (FALSE === $selected_cats ? ' CHECKED' : '') . '> ';
253
- _e('All Categories', 'avh-ec');
 
 
 
 
 
 
254
  echo '</label>';
255
  echo '</li>';
256
- ob_start();
257
- $this->avh_wp_category_checklist($selected_cats, $this->number);
258
- ob_end_flush();
259
  echo '</ul>';
260
  echo '</p>';
261
 
262
- echo '<p>';
263
- avh_doWidgetFormCheckbox($this->get_field_id('invert_included'), $this->get_field_name('invert_included'), __('Exclude the selected categories', 'avh-ec'), (bool) $instance['invert_included']);
264
- echo '</p>';
 
 
 
 
 
 
 
 
 
 
 
265
 
266
- echo '<input type="hidden" id="' . $this->get_field_id('submit') . '" name="' . $this->get_field_name('submit') . '" value="1" />';
267
  }
268
 
269
  /**
270
- * Creates the categories checklist
271
  *
272
- * @param int $post_id
273
- * @param int $descendants_and_self
274
- * @param array $selected_cats
275
- * @param array $popular_cats
276
- * @param int $number
277
  */
278
- function avh_wp_category_checklist ($selected_cats, $number)
279
- {
280
-
281
- $walker = new AVH_Walker_Category_Checklist();
282
- $walker->number = $number;
283
- $walker->input_id = $this->get_field_id('post_category');
284
- $walker->input_name = $this->get_field_name('post_category');
285
- $walker->li_id = $this->get_field_id('category--1');
286
-
287
- $args = array ( 'taxonomy' => 'category', 'descendants_and_self' => 0, 'selected_cats' => $selected_cats, 'popular_cats' => array (), 'walker' => $walker, 'checked_ontop' => true, 'popular_cats' => array () );
288
-
289
- if (is_array($selected_cats))
290
- $args['selected_cats'] = $selected_cats;
291
- else
292
- $args['selected_cats'] = array ();
293
 
294
- $categories = $this->core->getCategories();
295
- $_categories_id = $this->core->getCategoriesId($categories);
296
 
297
- // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache)
298
- $checked_categories = array ();
299
- foreach ($args['selected_cats'] as $key => $value) {
300
- if (isset($_categories_id[$key])) {
301
- $category_key = $_categories_id[$key];
302
- $checked_categories[] = $categories[$category_key];
303
- unset($categories[$category_key]);
304
- }
 
 
 
 
 
 
305
  }
306
 
307
- // Put checked cats on top
308
- echo $walker->walk($checked_categories, 0, array ( $args ));
309
- // Then the rest of them
310
- echo $walker->walk($categories, 0, array ( $args ));
311
  }
312
- }
313
 
314
- /**
315
- * Widget Class for displaying the top categories
316
- *
317
- */
318
- class WP_Widget_AVH_ExtendedCategories_Top extends WP_Widget
319
- {
320
  /**
 
321
  *
322
- * @var AVH_EC_Core
 
323
  */
324
- var $core;
 
325
 
326
- /**
327
- * PHP 5 Constructor
328
- *
329
- */
330
- function __construct ()
331
- {
332
- $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core');
333
-
334
- $widget_ops = array ( 'description' => __("Shows the top categories.", 'avh-ec') );
335
- WP_Widget::__construct(FALSE, 'AVH Extended Categories: ' . __('Top Categories'), $widget_ops);
336
- add_action('wp_print_styles', array ( &$this, 'actionWpPrintStyles' ));
337
-
338
- }
339
-
340
- function WP_Widget_AVH_ExtendedCategories_Top ()
341
- {
342
- $this->__construct();
343
- }
344
-
345
- function actionWpPrintStyles ()
346
- {
347
- if (! (FALSE === is_active_widget(FALSE, FALSE, $this->id_base, TRUE))) {
348
- wp_register_style('avhec-widget', AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', array (), $this->core->version);
349
- wp_enqueue_style('avhec-widget');
350
- }
351
- }
352
-
353
- /** Echo the widget content.
354
- *
355
- * Subclasses should over-ride this function to generate their widget code.
356
- *
357
- * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
358
- * @param array $instance The settings for the particular instance of the widget
359
- */
360
- function widget ($args, $instance)
361
- {
362
- extract($args);
363
-
364
- $title = apply_filters('widget_title', empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']);
365
- $style = empty($instance['style']) ? 'list' : $instance['style'];
366
- if (! $a = (int) $instance['amount']) {
367
- $a = 5;
368
- } elseif ($a < 1) {
369
- $a = 1;
370
- }
371
- $c = $instance['count'] ? TRUE : FALSE;
372
- $use_desc_for_title = $instance['use_desc_for_title'] ? TRUE : FALSE;
373
- $s = $instance['sort_column'] ? $instance['sort_column'] : 'name';
374
- $o = $instance['sort_order'] ? $instance['sort_order'] : 'asc';
375
- $r = $instance['rssfeed'] ? 'RSS' : '';
376
- $i = $instance['rssimage'] ? $instance['rssimage'] : '';
377
- if (empty($r)) {
378
- $i = '';
379
- }
380
- if (! empty($i)) {
381
- if (! file_exists(ABSPATH . '/' . $i)) {
382
- $i = '';
383
- }
384
- }
385
-
386
- $options = $this->core->getOptions();
387
- $show_option_none = __('Select Category', 'avh-ec');
388
- if ($options['general']['alternative_name_select_category']) {
389
- $show_option_none = $options['general']['alternative_name_select_category'];
390
- }
391
-
392
- $top_cats = get_terms('category', array ( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => $a, 'hierarchical' => FALSE ));
393
- $included_cats = implode(",", $top_cats);
394
-
395
- $cat_args = array ( 'include' => $included_cats, 'orderby' => $s, 'order' => $o, 'show_count' => $c, 'use_desc_for_title' => $use_desc_for_title, 'hide_empty' => FALSE, 'hierarchical' => FALSE, 'depth' => - 1, 'title_li' => '', 'show_option_none' => $show_option_none, 'feed' => $r, 'feed_image' => $i, 'name' => 'extended-categories-top-select-' . $this->number );
396
- echo $before_widget;
397
- echo $this->core->comment;
398
- echo $before_title . $title . $after_title;
399
- echo '<ul>';
400
-
401
- if ($style == 'list') {
402
- wp_list_categories($cat_args);
403
- } else {
404
- wp_dropdown_categories($cat_args);
405
- echo '<script type=\'text/javascript\'>' . "\n";
406
- echo '/* <![CDATA[ */' . "\n";
407
- echo ' var ec_dropdown_top_' . $this->number . ' = document.getElementById("extended-categories-top-select-' . $this->number . '");' . "\n";
408
- echo ' function ec_top_onCatChange_' . $this->number . '() {' . "\n";
409
- echo ' if ( ec_dropdown_top_' . $this->number . '.options[ec_dropdown_top_' . $this->number . '.selectedIndex].value > 0 ) {' . "\n";
410
- echo ' location.href = "' . get_option('home') . '/?cat="+ec_dropdown_top_' . $this->number . '.options[ec_dropdown_top_' . $this->number . '.selectedIndex].value;' . "\n";
411
- echo ' }' . "\n";
412
- echo ' }' . "\n";
413
- echo ' ec_dropdown_top_' . $this->number . '.onchange = ec_top_onCatChange_' . $this->number . ';' . "\n";
414
- echo '/* ]]> */' . "\n";
415
- echo '</script>' . "\n";
416
- }
417
- echo '</ul>';
418
- echo $after_widget;
419
- }
420
-
421
- /** Update a particular instance.
422
- *
423
- * This function should check that $new_instance is set correctly.
424
- * The newly calculated value of $instance should be returned.
425
- * If "FALSE" is returned, the instance won't be saved/updated.
426
- *
427
- * @param array $new_instance New settings for this instance as input by the user via form()
428
- * @param array $old_instance Old settings for this instance
429
- * @return array Settings to save or bool FALSE to cancel saving
430
- */
431
- function update ($new_instance, $old_instance)
432
- {
433
- // update the instance's settings
434
- if (! isset($new_instance['submit'])) {
435
- return FALSE;
436
- }
437
-
438
- $instance = $old_instance;
439
-
440
- $instance['title'] = strip_tags(stripslashes($new_instance['title']));
441
- $instance['amount'] = (int) $new_instance['amount'];
442
- $instance['count'] = $new_instance['count'] ? TRUE : FALSE;
443
- $instance['use_desc_for_title'] = $new_instance['use_desc_for_title'] ? TRUE : FALSE;
444
- $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column']));
445
- $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order']));
446
- $instance['style'] = strip_tags(stripslashes($new_instance['style']));
447
- $instance['rssfeed'] = $new_instance['rssfeed'] ? TRUE : FALSE;
448
- $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage']));
449
-
450
- return $instance;
451
- }
452
-
453
- /** Echo the settings update form
454
- *
455
- * @param array $instance Current settings
456
- */
457
- function form ($instance)
458
- {
459
- // displays the widget admin form
460
- $instance = wp_parse_args((array) $instance, array ( 'title' => '', 'rssimage' => '' ));
461
-
462
- // Prepare data for display
463
- if (! $amount = (int) $instance['amount']) {
464
- $amount = 5;
465
- }
466
-
467
- if ($amount < 1) {
468
- $amount = 1;
469
- }
470
- echo '<p>';
471
- avh_doWidgetFormText($this->get_field_id('title'), $this->get_field_name('title'), __('Title', 'avh-ec'), $instance['title']);
472
- echo '</p>';
473
-
474
- echo '<p>';
475
- avh_doWidgetFormText($this->get_field_id('amount'), $this->get_field_name('amount'), __('How many categories to show', 'avh-ec'), $amount);
476
- echo '</p>';
477
-
478
- echo '<p>';
479
- avh_doWidgetFormCheckbox($this->get_field_id('count'), $this->get_field_name('count'), __('Show post counts', 'avh-ec'), (bool) $instance['count']);
480
- echo '<br />';
481
-
482
- avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'), $this->get_field_name('use_desc_for_title'), __('Use description for title', 'avh-ec'), (bool) $instance['use_desc_for_title']);
483
- echo '</p>';
484
-
485
- echo '<p>';
486
- $options['ID'] = __('ID', 'avh-ec');
487
- $options['name'] = __('Name', 'avh-ec');
488
- $options['count'] = __('Count', 'avh-ec');
489
- $options['slug'] = __('Slug', 'avh-ec');
490
- avh_doWidgetFormSelect($this->get_field_id('sort_column'), $this->get_field_name('sort_column'), __('Sort by', 'avh-ec'), $options, $instance['sort_column']);
491
- unset($options);
492
-
493
- $options['asc'] = __('Ascending', 'avh-ec');
494
- $options['desc'] = __('Descending', 'avh-ec');
495
- avh_doWidgetFormSelect($this->get_field_id('sort_order'), $this->get_field_name('sort_order'), __('Sort order', 'avh-ec'), $options, $instance['sort_order']);
496
- unset($options);
497
-
498
- $options['list'] = __('List', 'avh-ec');
499
- $options['drop'] = __('Drop down', 'avh-ec');
500
- avh_doWidgetFormSelect($this->get_field_id('style'), $this->get_field_name('style'), __('Display style', 'avh-ec'), $options, $instance['style']);
501
- unset($options);
502
- echo '</p>';
503
-
504
- echo '<p>';
505
-
506
- avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), $this->get_field_name('rssfeed'), __('Show RSS Feed', 'avh-ec'), (bool) $instance['rssfeed']);
507
-
508
- avh_doWidgetFormText($this->get_field_id('rssimage'), $this->get_field_name('rssimage'), __('Path (URI) to RSS image', 'avh-ec'), $instance['rssimage']);
509
-
510
- echo '</p>';
511
-
512
- echo '<input type="hidden" id="' . $this->get_field_id('submit') . '" name="' . $this->get_field_name('submit') . '" value="1" />';
513
- }
514
- }
515
-
516
- /**
517
- * Widget Class for displaying the grouped categories
518
- *
519
- */
520
- class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget
521
- {
522
- /**
523
- *
524
- * @var AVH_EC_Core
525
- */
526
- var $core;
527
-
528
- /**
529
- *
530
- * @var AVH_EC_Category_Group
531
- */
532
- var $catgrp;
533
-
534
- /**
535
- * PHP 5 Constructor
536
- *
537
- */
538
- function __construct ()
539
- {
540
- $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core');
541
- $this->catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
542
-
543
- $widget_ops = array ( 'description' => __("Shows grouped categories.", 'avh-ec') );
544
- WP_Widget::__construct(FALSE, 'AVH Extended Categories: ' . __('Category Group'), $widget_ops);
545
- add_action('wp_print_styles', array ( &$this, 'actionWpPrintStyles' ));
546
-
547
- }
548
-
549
- function WP_Widget_AVH_ExtendedCategories_Category_Group ()
550
- {
551
- $this->__construct();
552
- }
553
-
554
- function actionWpPrintStyles ()
555
- {
556
- if (! (FALSE === is_active_widget(FALSE, FALSE, $this->id_base, TRUE))) {
557
- wp_register_style('avhec-widget', AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', array (), $this->core->version);
558
- wp_enqueue_style('avhec-widget');
559
- }
560
- }
561
-
562
- /**
563
- * Display the widget
564
- *
565
- * @param unknown_type $args
566
- * @param unknown_type $instance
567
- */
568
- function widget ($args, $instance)
569
- {
570
- global $post, $wp_query;
571
-
572
- $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
573
  $options = $this->core->getOptions();
574
 
575
- $row = array ();
576
 
577
  if (is_home()) {
578
  $special_page = 'home_group';
@@ -592,79 +433,81 @@ class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget
592
  $special_page = 'none';
593
  }
594
 
595
- $toDisplay = FALSE;
596
  if ('none' == $special_page) {
597
  $terms = wp_get_object_terms($post->ID, $catgrp->taxonomy_name);
598
- if (! empty($terms)) {
599
  $selected_catgroups = unserialize($instance['post_group_category']);
600
  foreach ($terms as $key => $value) {
601
- if ($selected_catgroups === FALSE || array_key_exists($value->term_id, $selected_catgroups)) {
602
- if (! ($this->getWidgetDoneCatGroup($value->term_id))) {
603
- $row = $value;
604
- $group_found = TRUE;
605
  break;
606
  }
607
  }
608
  }
609
  } else {
610
- $options = $this->core->options;
611
  $no_cat_group = $options['cat_group']['no_group'];
612
- $row = get_term_by('id', $no_cat_group, $catgrp->taxonomy_name);
613
- $group_found = TRUE;
614
  }
615
  } else {
616
  if ('category_group' == $special_page) {
617
  $tax_meta = get_option($this->core->db_options_tax_meta);
618
- $term = $wp_query->get_queried_object();
619
- if (isset($tax_meta[$term->taxonomy][$term->term_id]['category_group_term_id'])) {
620
- $sp_category_group_id = $tax_meta[$term->taxonomy][$term->term_id]['category_group_term_id'];
621
  } else {
622
- $sp_category_group = $this->catgrp->getGroupByCategoryID($term->term_id);
623
  $sp_category_group_id = $sp_category_group->term_id;
624
  }
625
  } else {
626
- $sp_category_group_id = $options['sp_cat_group'][$special_page];
627
  }
628
- $row = get_term_by('id', $sp_category_group_id, $catgrp->taxonomy_name); // Returns FALSE when non-existance. (empty(FALSE)=TRUE)
629
- $group_found = TRUE;
 
 
630
  }
631
 
632
  if ($group_found) {
633
- $toDisplay = TRUE;
634
  $category_group_id_none = $this->catgrp->getTermIDBy('slug', 'none');
635
- $selected_catgroups = unserialize($instance['post_group_category']);
636
 
637
  if ($category_group_id_none == $row->term_id) {
638
- $toDisplay = FALSE;
639
- } elseif (! (FALSE == $selected_catgroups || array_key_exists($row->term_id, $selected_catgroups))) {
640
- $toDisplay = FALSE;
641
  } elseif ($special_page != 'none' && $this->getWidgetDoneCatGroup($sp_category_group_id)) {
642
- $toDisplay = FALSE;
643
  }
644
  }
645
 
646
  if ($toDisplay) {
647
  extract($args);
648
 
649
- $c = $instance['count'] ? TRUE : FALSE;
650
- $e = $instance['hide_empty'] ? TRUE : FALSE;
651
- $h = $instance['hierarchical'] ? TRUE : FALSE;
652
- $use_desc_for_title = $instance['use_desc_for_title'] ? TRUE : FALSE;
653
- $s = $instance['sort_column'] ? $instance['sort_column'] : 'name';
654
- $o = $instance['sort_order'] ? $instance['sort_order'] : 'asc';
655
- $r = $instance['rssfeed'] ? 'RSS' : '';
656
- $i = $instance['rssimage'] ? $instance['rssimage'] : '';
657
 
658
  if (empty($r)) {
659
  $i = '';
660
  }
661
 
662
- $style = empty($instance['style']) ? 'list' : $instance['style'];
663
  $group_id = $row->term_id;
664
- $cats = $catgrp->getCategoriesFromGroup($group_id);
665
  if (empty($instance['title'])) {
666
  $title = $catgrp->getWidgetTitleForGroup($group_id);
667
- if (! $title) {
668
  $title = __('Categories', 'avh-ec');
669
  }
670
  } else {
@@ -679,65 +522,161 @@ class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget
679
  $show_option_none = $options['general']['alternative_name_select_category'];
680
  }
681
 
682
- $cat_args = array ( 'include' => $included_cats, 'orderby' => $s, 'order' => $o, 'show_count' => $c, 'use_desc_for_title' => $use_desc_for_title, 'hide_empty' => $e, 'hierarchical' => $h, 'title_li' => '', 'show_option_none' => $show_option_none, 'feed' => $r, 'feed_image' => $i, 'name' => 'extended-categories-select-group-' . $this->number );
 
 
 
 
 
 
 
 
 
 
 
 
 
683
  echo $before_widget;
684
  echo $this->core->comment;
685
  echo $before_title . $title . $after_title;
686
 
687
  if ($style == 'list') {
688
  echo '<ul>';
689
- $this->core->avh_wp_list_categories($cat_args, TRUE);
690
  echo '</ul>';
691
  } else {
692
- $this->core->avh_wp_dropdown_categories($cat_args, TRUE);
693
  echo '<script type=\'text/javascript\'>' . "\n";
694
  echo '/* <![CDATA[ */' . "\n";
695
- echo ' var ec_dropdown_' . $this->number . ' = document.getElementById("extended-categories-select-group-' . $this->number . '");' . "\n";
 
 
 
 
 
696
  echo ' function ec_onCatChange_' . $this->number . '() {' . "\n";
697
- echo ' if ( ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value > 0 ) {' . "\n";
698
- echo ' location.href = "' . get_option('home') . '/?cat="+ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value;' . "\n";
 
 
 
 
 
 
 
 
 
 
 
 
699
  echo ' }' . "\n";
700
  echo ' }' . "\n";
701
- echo ' ec_dropdown_' . $this->number . '.onchange = ec_onCatChange_' . $this->number . ';' . "\n";
 
 
 
 
 
702
  echo '/* ]]> */' . "\n";
703
  echo '</script>' . "\n";
704
  }
705
  echo $after_widget;
706
  }
707
  }
 
708
 
 
 
 
 
709
  /**
710
- * When Widget Control Form Is Posted
711
- *
712
- * @param unknown_type $new_instance
713
- * @param unknown_type $old_instance
714
- * @return unknown
715
  */
716
- function update ($new_instance, $old_instance)
717
- {
718
- // update the instance's settings
719
- if (! isset($new_instance['submit'])) {
720
- return FALSE;
 
 
 
 
 
 
 
 
721
  }
 
 
722
 
723
- $instance = $old_instance;
 
724
 
725
- $instance['title'] = strip_tags(stripslashes($new_instance['title']));
726
- $instance['count'] = $new_instance['count'] ? TRUE : FALSE;
727
- $instance['hierarchical'] = $new_instance['hierarchical'] ? TRUE : FALSE;
728
- $instance['hide_empty'] = $new_instance['hide_empty'] ? TRUE : FALSE;
729
- $instance['use_desc_for_title'] = $new_instance['use_desc_for_title'] ? TRUE : FALSE;
730
- $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column']));
731
- $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order']));
732
- $instance['style'] = strip_tags(stripslashes($new_instance['style']));
733
- $instance['rssfeed'] = $new_instance['rssfeed'] ? TRUE : FALSE;
734
- $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage']));
735
- if (array_key_exists('all', $new_instance['post_group_category'])) {
736
- $instance['post_group_category'] = FALSE;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
737
  } else {
738
- $instance['post_group_category'] = serialize($new_instance['post_group_category']);
739
  }
740
- return $instance;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
741
  }
742
 
743
  /**
@@ -745,260 +684,578 @@ class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget
745
  *
746
  * @param unknown_type $instance
747
  */
748
- function form ($instance)
749
- {
750
  // displays the widget admin form
751
- $instance = wp_parse_args((array) $instance, array ( 'title' => '', 'rssimage' => '' ));
752
 
753
  // Prepare data for display
754
- $title = esc_attr($instance['title']);
755
- $count = (bool) $instance['count'];
756
- $hierarchical = (bool) $instance['hierarchical'];
757
- $hide_empty = (bool) $instance['hide_empty'];
758
- $use_desc_for_title = (bool) $instance['use_desc_for_title'];
759
- $sort_id = ($instance['sort_column'] == 'ID') ? ' SELECTED' : '';
760
- $sort_name = ($instance['sort_column'] == 'name') ? ' SELECTED' : '';
761
- $sort_count = ($instance['sort_column'] == 'count') ? ' SELECTED' : '';
762
- $sort_order_a = ($instance['sort_order'] == 'asc') ? ' SELECTED' : '';
763
- $sort_order_d = ($instance['sort_order'] == 'desc') ? ' SELECTED' : '';
764
- $style_list = ($instance['style'] == 'list') ? ' SELECTED' : '';
765
- $style_drop = ($instance['style'] == 'drop') ? ' SELECTED' : '';
766
- $rssfeed = (bool) $instance['rssfeed'];
767
- $rssimage = esc_attr($instance['rssimage']);
768
-
769
- $selected_cats = ($instance['post_group_category'] != '') ? unserialize($instance['post_group_category']) : FALSE;
770
- ob_start();
771
  echo '<p>';
772
- avh_doWidgetFormText($this->get_field_id('title'), $this->get_field_name('title'), __('Title', 'avh-ec'), $instance['title']);
 
 
 
773
  echo '</p>';
774
 
775
  echo '<p>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
776
 
777
- avh_doWidgetFormCheckbox($this->get_field_id('count'), $this->get_field_name('count'), __('Show post counts', 'avh-ec'), (bool) $instance['count']);
778
-
779
- avh_doWidgetFormCheckbox($this->get_field_id('hierarchical'), $this->get_field_name('hierarchical'), __('Show hierarchy', 'avh-ec'), (bool) $instance['hierarchical']);
780
-
781
- avh_doWidgetFormCheckbox($this->get_field_id('hide_empty'), $this->get_field_name('hide_empty'), __('Hide empty categories', 'avh-ec'), (bool) $instance['hide_empty']);
782
 
783
- avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'), $this->get_field_name('use_desc_for_title'), __('Use description for title', 'avh-ec'), (bool) $instance['use_desc_for_title']);
 
 
 
784
  echo '</p>';
785
 
786
  echo '<p>';
787
- $options['ID'] = __('ID', 'avh-ec');
788
- $options['name'] = __('Name', 'avh-ec');
789
- $options['count'] = __('Count', 'avh-ec');
790
- $options['slug'] = __('Slug', 'avh-ec');
791
- avh_doWidgetFormSelect($this->get_field_id('sort_column'), $this->get_field_name('sort_column'), __('Sort by', 'avh-ec'), $options, $instance['sort_column']);
 
 
 
 
 
 
 
 
 
792
  unset($options);
793
 
794
- $options['asc'] = __('Ascending', 'avh-ec');
795
  $options['desc'] = __('Descending', 'avh-ec');
796
- avh_doWidgetFormSelect($this->get_field_id('sort_order'), $this->get_field_name('sort_order'), __('Sort order', 'avh-ec'), $options, $instance['sort_order']);
 
 
 
 
797
  unset($options);
798
 
799
  $options['list'] = __('List', 'avh-ec');
800
  $options['drop'] = __('Drop down', 'avh-ec');
801
- avh_doWidgetFormSelect($this->get_field_id('style'), $this->get_field_name('style'), __('Display style', 'avh-ec'), $options, $instance['style']);
 
 
 
 
802
  unset($options);
803
  echo '</p>';
804
 
805
  echo '<p>';
806
 
807
- avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), $this->get_field_name('rssfeed'), __('Show RSS Feed', 'avh-ec'), (bool) $instance['rssfeed']);
 
 
 
 
 
 
 
 
808
 
809
- avh_doWidgetFormText($this->get_field_id('rssimage'), $this->get_field_name('rssimage'), __('Path (URI) to RSS image', 'avh-ec'), $instance['rssimage']);
810
  echo '</p>';
811
 
812
  echo '<p>';
813
- echo '<b>' . __('Select Groups', 'avh-ec') . '</b><hr />';
814
  echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear" style="list-style-type: none; margin-left: 5px; padding-left: 0px; margin-bottom: 20px;">';
815
- echo '<li id="' . $this->get_field_id('group_category--1') . '" class="popular-group_category">';
816
- echo '<label for="' . $this->get_field_id('group_post_category') . '" class="selectit">';
817
- echo '<input value="all" id="' . $this->get_field_id('group_post_category') . '" name="' . $this->get_field_name('post_group_category') . '[all]" type="checkbox" ' . (FALSE === $selected_cats ? ' CHECKED' : '') . '> ';
818
- _e('Any Group', 'avh-ec');
 
 
 
 
 
 
819
  echo '</label>';
820
  echo '</li>';
821
-
822
- $this->avh_wp_group_category_checklist($selected_cats, $this->number);
823
-
824
  echo '</ul>';
825
  echo '</p>';
826
 
827
- echo '<input type="hidden" id="' . $this->get_field_id('submit') . '" name="' . $this->get_field_name('submit') . '" value="1" />';
828
- ob_end_flush();
 
 
 
 
 
 
 
 
 
 
829
  }
830
 
831
- function avh_wp_group_category_checklist ($selected_cats, $number)
832
- {
 
 
 
 
 
 
 
 
 
 
 
833
 
834
- $walker = new AVH_Walker_Category_Checklist();
835
- $walker->number = $number;
836
- $walker->input_id = $this->get_field_id('post_group_category');
837
- $walker->input_name = $this->get_field_name('post_group_category');
838
- $walker->li_id = $this->get_field_id('group_category--1');
839
 
840
- $args = array ( 'taxonomy' => 'avhec_catgroup', 'descendants_and_self' => 0, 'selected_cats' => array (), 'popular_cats' => array (), 'walker' => $walker, 'checked_ontop' => true );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
841
 
842
- if (is_array($selected_cats))
843
- $args['selected_cats'] = $selected_cats;
844
- else
845
- $args['selected_cats'] = array ();
846
 
847
- $categories = (array) get_terms($args['taxonomy'], array ( 'get' => 'all' ));
 
 
 
 
 
 
848
 
849
- // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache)
850
- $checked_categories = array ();
851
- $keys = array_keys($categories);
852
 
853
- foreach ($keys as $k) {
854
- if (in_array($categories[$k]->term_id, $args['selected_cats'])) {
855
- $checked_categories[] = $categories[$k];
856
- unset($categories[$k]);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
857
  }
 
858
  }
859
 
860
- // Put checked cats on top
861
- echo $walker->walk($checked_categories, 0, array ( $args ));
862
- // Then the rest of them
863
- echo $walker->walk($categories, 0, array ( $args ));
864
- }
865
 
866
- function getWidgetDoneCatGroup ($id)
867
- {
868
- $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
869
- if (is_array($catgrp->widget_done_catgroup) && array_key_exists($id, $catgrp->widget_done_catgroup)) {
870
- return TRUE;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
871
  }
872
- $catgrp->widget_done_catgroup[$id] = TRUE;
873
- return FALSE;
874
  }
875
  }
876
 
877
  /**
878
- * Class that will display the categories
879
- *
880
  */
881
- class AVH_Walker_Category_Checklist extends Walker
882
- {
883
- var $tree_type = 'category';
884
- var $db_fields = array ( 'parent' => 'parent', 'id' => 'term_id' ); //TODO: decouple this
885
- var $number;
886
- var $input_id;
887
- var $input_name;
888
- var $li_id;
889
 
890
  /**
891
- * Display array of elements hierarchically.
892
- *
893
- * It is a generic function which does not assume any existing order of
894
- * elements. max_depth = -1 means flatly display every element. max_depth =
895
- * 0 means display all levels. max_depth > 0 specifies the number of
896
- * display levels.
897
- *
898
- * @since 2.1.0
899
- *
900
- * @param array $elements
901
- * @param int $max_depth
902
- * @param array $args;
903
- * @return string
904
  */
905
- function walk ($elements, $max_depth, $args)
906
- {
907
 
908
- $output = '';
 
 
 
909
 
910
- if ($max_depth < - 1) //invalid parameter
911
- return $output;
 
912
 
913
- if (empty($elements)) //nothing to walk
914
- return $output;
 
 
 
 
 
 
 
915
 
916
- $id_field = $this->db_fields['id'];
917
- $parent_field = $this->db_fields['parent'];
 
 
 
 
 
918
 
919
- // flat display
920
- if (- 1 == $max_depth) {
921
- $empty_array = array ();
922
- foreach ($elements as $e)
923
- $this->display_element($e, $empty_array, 1, 0, $args, $output);
924
- return $output;
925
  }
926
 
927
- /*
928
- * need to display in hierarchical order
929
- * separate elements into two buckets: top level and children elements
930
- * children_elements is two dimensional array, eg.
931
- * children_elements[10][] contains all sub-elements whose parent is 10.
932
- */
933
- $top_level_elements = array ();
934
- $children_elements = array ();
935
- foreach ($elements as $e) {
936
- if (0 == $e->$parent_field)
937
- $top_level_elements[] = $e;
938
- else
939
- $children_elements[$e->$parent_field][] = $e;
940
  }
 
 
 
 
 
 
941
 
942
- /*
943
- * when none of the elements is top level
944
- * assume the first one must be root of the sub elements
945
- */
946
- if (empty($top_level_elements)) {
 
947
 
948
- $first = array_slice($elements, 0, 1);
949
- $root = $first[0];
 
 
 
 
950
 
951
- $top_level_elements = array ();
952
- $children_elements = array ();
953
- foreach ($elements as $e) {
954
- if ($root->$parent_field == $e->$parent_field)
955
- $top_level_elements[] = $e;
956
- else
957
- $children_elements[$e->$parent_field][] = $e;
958
- }
959
- }
960
 
961
- foreach ($top_level_elements as $e)
962
- $this->display_element($e, $children_elements, $max_depth, 0, $args, $output);
 
 
 
 
 
 
 
 
 
963
 
964
- /*
965
- * if we are displaying all levels, and remaining children_elements is not empty,
966
- * then we got orphans, which should be displayed regardless
967
- */
968
- if (($max_depth == 0) && count($children_elements) > 0) {
969
- $empty_array = array ();
970
- foreach ($children_elements as $orphans)
971
- foreach ($orphans as $op)
972
- $this->display_element($op, $empty_array, 1, 0, $args, $output);
973
- }
974
 
975
- return $output;
976
- }
 
 
 
 
 
 
 
977
 
978
- function start_lvl (&$output, $depth, $args)
979
- {
980
- $indent = str_repeat("\t", $depth);
981
- $output .= $indent . '<ul class="children">' . "\n";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
982
  }
983
 
984
- function end_lvl (&$output, $depth, $args)
985
- {
986
- $indent = str_repeat("\t", $depth);
987
- $output .= $indent . '</ul>' . "\n";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
988
  }
989
 
990
- function start_el (&$output, $category, $depth, $args)
991
- {
 
 
 
 
 
992
  extract($args);
993
- $input_id = $this->input_id . '-' . $category->term_id;
994
- $output .= "\n" . '<li id="' . $this->li_id . '">';
995
- $output .= '<label for="' . $input_id . '" class="selectit">';
996
- $output .= '<input value="' . $category->term_id . '" type="checkbox" name="' . $this->input_name . '[' . $category->term_id . ']" id="' . $input_id . '"' . (in_array($category->term_id, $selected_cats) ? ' checked="checked"' : "") . '/> ' . esc_html(apply_filters('the_category', $category->name)) . '</label>';
997
- }
998
 
999
- function end_el (&$output, $category, $depth, $args)
1000
- {
1001
- $output .= "</li>\n";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1002
  }
1003
  }
 
1004
  ?>
1
  <?php
2
 
3
  /**
4
+ * Class that will display the categories
 
5
  */
6
+ class AVH_Walker_Category_Checklist extends Walker {
7
+ var $db_fields = array('parent' => 'parent', 'id' => 'term_id');
8
+ var $input_id; //TODO: decouple this
9
+ var $input_name;
10
+ var $li_id;
11
+ var $number;
12
+ var $tree_type = 'category';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
+ function end_el(&$output, $category, $depth, $args) {
15
+ $output .= "</li>\n";
16
  }
17
 
18
+ function end_lvl(&$output, $depth, $args) {
19
+ $indent = str_repeat("\t", $depth);
20
+ $output .= $indent . '</ul>' . "\n";
21
  }
22
 
23
+ function start_el(&$output, $category, $depth, $args) {
24
+ extract($args);
25
+ $input_id = $this->input_id . '-' . $category->term_id;
26
+ $output .= "\n" . '<li id="' . $this->li_id . '">';
27
+ $output .= '<label for="' . $input_id . '" class="selectit">';
28
+ $output .= '<input value="' .
29
+ $category->term_id .
30
+ '" type="checkbox" name="' .
31
+ $this->input_name .
32
+ '[' .
33
+ $category->term_id .
34
+ ']" id="' .
35
+ $input_id .
36
+ '"' .
37
+ (in_array($category->term_id, $selected_cats) ? ' checked="checked"' : "") .
38
+ '/> ' .
39
+ esc_html(apply_filters('the_category', $category->name)) .
40
+ '</label>';
41
+ }
42
 
43
+ function start_lvl(&$output, $depth, $args) {
44
+ $indent = str_repeat("\t", $depth);
45
+ $output .= $indent . '<ul class="children">' . "\n";
 
46
  }
47
 
48
  /**
49
+ * Display array of elements hierarchically.
50
+ * It is a generic function which does not assume any existing order of
51
+ * elements. max_depth = -1 means flatly display every element. max_depth =
52
+ * 0 means display all levels. max_depth > 0 specifies the number of
53
+ * display levels.
54
  *
55
+ * @since 2.1.0
56
+ *
57
+ * @param array $elements
58
+ * @param int $max_depth
59
+ * @param array $args ;
60
+ *
61
+ * @return string
62
  */
63
+ function walk($elements, $max_depth, $args) {
 
 
 
64
 
65
+ $output = '';
 
 
 
 
 
 
 
 
 
 
66
 
67
+ if ($max_depth < - 1) //invalid parameter
68
+ {
69
+ return $output;
70
  }
71
 
72
+ if (empty($elements)) //nothing to walk
73
+ {
74
+ return $output;
75
  }
76
 
77
+ $id_field = $this->db_fields['id'];
78
+ $parent_field = $this->db_fields['parent'];
79
 
80
+ // flat display
81
+ if (- 1 == $max_depth) {
82
+ $empty_array = array();
83
+ foreach ($elements as $e) {
84
+ $this->display_element($e, $empty_array, 1, 0, $args, $output);
 
 
 
85
  }
86
+
87
+ return $output;
88
  }
89
 
90
+ /*
91
+ * need to display in hierarchical order
92
+ * separate elements into two buckets: top level and children elements
93
+ * children_elements is two dimensional array, eg.
94
+ * children_elements[10][] contains all sub-elements whose parent is 10.
95
+ */
96
+ $top_level_elements = array();
97
+ $children_elements = array();
98
+ foreach ($elements as $e) {
99
+ if (0 == $e->$parent_field) {
100
+ $top_level_elements[] = $e;
101
+ } else {
102
+ $children_elements[ $e->$parent_field ][] = $e;
103
+ }
104
  }
105
 
106
+ /*
107
+ * when none of the elements is top level
108
+ * assume the first one must be root of the sub elements
109
+ */
110
+ if (empty($top_level_elements)) {
111
+
112
+ $first = array_slice($elements, 0, 1);
113
+ $root = $first[0];
114
+
115
+ $top_level_elements = array();
116
+ $children_elements = array();
117
+ foreach ($elements as $e) {
118
+ if ($root->$parent_field == $e->$parent_field) {
119
+ $top_level_elements[] = $e;
120
+ } else {
121
+ $children_elements[ $e->$parent_field ][] = $e;
122
+ }
123
+ }
124
  }
125
 
126
+ foreach ($top_level_elements as $e) {
127
+ $this->display_element($e, $children_elements, $max_depth, 0, $args, $output);
128
+ }
 
129
 
130
+ /*
131
+ * if we are displaying all levels, and remaining children_elements is not empty,
132
+ * then we got orphans, which should be displayed regardless
133
+ */
134
+ if (($max_depth == 0) && count($children_elements) > 0) {
135
+ $empty_array = array();
136
+ foreach ($children_elements as $orphans) {
137
+ foreach ($orphans as $op) {
138
+ $this->display_element($op, $empty_array, 1, 0, $args, $output);
139
+ }
140
+ }
 
 
 
 
 
 
141
  }
142
+
143
+ return $output;
144
  }
145
+ }
146
 
147
+ /**
148
+ * Widget Class for displaying the grouped categories
149
+ */
150
+ class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget {
151
  /**
152
+ * @var AVH_EC_Category_Group
 
 
 
 
153
  */
154
+ var $catgrp;
155
+ /**
156
+ * @var AVH_EC_Core
157
+ */
158
+ var $core;
159
+
160
+ /**
161
+ * PHP 5 Constructor
162
+ */
163
+ function __construct() {
164
+ $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core');
165
+ $this->catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
166
+
167
+ $widget_ops = array('description' => __("Shows grouped categories.", 'avh-ec'));
168
+ WP_Widget::__construct(false, 'AVH Extended Categories: ' . __('Category Group'), $widget_ops);
169
+ add_action('wp_print_styles', array(&$this, 'actionWpPrintStyles'));
170
+ }
171
+
172
+ function WP_Widget_AVH_ExtendedCategories_Category_Group() {
173
+ $this->__construct();
174
+ }
175
+
176
+ function actionWpPrintStyles() {
177
+ if ( ! (false === is_active_widget(false, false, $this->id_base, true))) {
178
+ wp_register_style('avhec-widget',
179
+ AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css',
180
+ array(),
181
+ $this->core->version);
182
+ wp_enqueue_style('avhec-widget');
183
  }
184
+ }
185
 
186
+ function avh_wp_group_category_checklist($selected_cats, $number) {
187
 
188
+ $walker = new AVH_Walker_Category_Checklist();
189
+ $walker->number = $number;
190
+ $walker->input_id = $this->get_field_id('post_group_category');
191
+ $walker->input_name = $this->get_field_name('post_group_category');
192
+ $walker->li_id = $this->get_field_id('group_category--1');
193
+
194
+ $args = array(
195
+ 'taxonomy' => 'avhec_catgroup',
196
+ 'descendants_and_self' => 0,
197
+ 'selected_cats' => array(),
198
+ 'popular_cats' => array(),
199
+ 'walker' => $walker,
200
+ 'checked_ontop' => true
201
+ );
202
+
203
+ if (is_array($selected_cats)) {
204
+ $args['selected_cats'] = $selected_cats;
205
  } else {
206
+ $args['selected_cats'] = array();
207
  }
208
+
209
+ $categories = (array) get_terms($args['taxonomy'], array('get' => 'all'));
210
+
211
+ // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache)
212
+ $checked_categories = array();
213
+ $keys = array_keys($categories);
214
+
215
+ foreach ($keys as $k) {
216
+ if (in_array($categories[ $k ]->term_id, $args['selected_cats'])) {
217
+ $checked_categories[] = $categories[ $k ];
218
+ unset($categories[ $k ]);
219
+ }
220
  }
 
221
 
222
+ // Put checked cats on top
223
+ echo $walker->walk($checked_categories, 0, array($args));
224
+ // Then the rest of them
225
+ echo $walker->walk($categories, 0, array($args));
226
  }
227
 
228
  /**
230
  *
231
  * @param unknown_type $instance
232
  */
233
+ function form($instance) {
 
234
  // displays the widget admin form
235
+ $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => ''));
236
 
237
  // Prepare data for display
238
+ $title = esc_attr($instance['title']);
239
+ $count = (bool) $instance['count'];
240
+ $hierarchical = (bool) $instance['hierarchical'];
241
+ $hide_empty = (bool) $instance['hide_empty'];
242
+ $use_desc_for_title = (bool) $instance['use_desc_for_title'];
243
+ $sort_id = ($instance['sort_column'] == 'ID') ? ' SELECTED' : '';
244
+ $sort_name = ($instance['sort_column'] == 'name') ? ' SELECTED' : '';
245
+ $sort_count = ($instance['sort_column'] == 'count') ? ' SELECTED' : '';
246
+ $sort_order_a = ($instance['sort_order'] == 'asc') ? ' SELECTED' : '';
247
+ $sort_order_d = ($instance['sort_order'] == 'desc') ? ' SELECTED' : '';
248
+ $style_list = ($instance['style'] == 'list') ? ' SELECTED' : '';
249
+ $style_drop = ($instance['style'] == 'drop') ? ' SELECTED' : '';
250
+ $rssfeed = (bool) $instance['rssfeed'];
251
+ $rssimage = esc_attr($instance['rssimage']);
252
+
253
+ $selected_cats = ($instance['post_group_category'] !=
254
+ '') ? unserialize($instance['post_group_category']) : false;
255
+ ob_start();
256
  echo '<p>';
257
+ avh_doWidgetFormText($this->get_field_id('title'),
258
+ $this->get_field_name('title'),
259
+ __('Title', 'avh-ec'),
260
+ $instance['title']);
261
  echo '</p>';
262
 
263
  echo '<p>';
 
 
 
 
 
 
 
 
 
 
 
 
264
 
265
+ avh_doWidgetFormCheckbox($this->get_field_id('count'),
266
+ $this->get_field_name('count'),
267
+ __('Show post counts', 'avh-ec'),
268
+ (bool) $instance['count']);
269
+
270
+ avh_doWidgetFormCheckbox($this->get_field_id('hierarchical'),
271
+ $this->get_field_name('hierarchical'),
272
+ __('Show hierarchy', 'avh-ec'),
273
+ (bool) $instance['hierarchical']);
274
+
275
+ avh_doWidgetFormCheckbox($this->get_field_id('hide_empty'),
276
+ $this->get_field_name('hide_empty'),
277
+ __('Hide empty categories', 'avh-ec'),
278
+ (bool) $instance['hide_empty']);
279
+
280
+ avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'),
281
+ $this->get_field_name('use_desc_for_title'),
282
+ __('Use description for title', 'avh-ec'),
283
+ (bool) $instance['use_desc_for_title']);
284
  echo '</p>';
285
 
286
  echo '<p>';
287
+ $options['ID'] = __('ID', 'avh-ec');
288
+ $options['name'] = __('Name', 'avh-ec');
289
  $options['count'] = __('Count', 'avh-ec');
290
+ $options['slug'] = __('Slug', 'avh-ec');
291
+ avh_doWidgetFormSelect($this->get_field_id('sort_column'),
292
+ $this->get_field_name('sort_column'),
293
+ __('Sort by', 'avh-ec'),
294
+ $options,
295
+ $instance['sort_column']);
 
296
  unset($options);
297
 
298
+ $options['asc'] = __('Ascending', 'avh-ec');
299
  $options['desc'] = __('Descending', 'avh-ec');
300
+ avh_doWidgetFormSelect($this->get_field_id('sort_order'),
301
+ $this->get_field_name('sort_order'),
302
+ __('Sort order', 'avh-ec'),
303
+ $options,
304
+ $instance['sort_order']);
305
  unset($options);
306
 
307
  $options['list'] = __('List', 'avh-ec');
308
  $options['drop'] = __('Drop down', 'avh-ec');
309
+ avh_doWidgetFormSelect($this->get_field_id('style'),
310
+ $this->get_field_name('style'),
311
+ __('Display style', 'avh-ec'),
312
+ $options,
313
+ $instance['style']);
314
  unset($options);
315
  echo '</p>';
316
 
317
  echo '<p>';
318
 
319
+ avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'),
320
+ $this->get_field_name('rssfeed'),
321
+ __('Show RSS Feed', 'avh-ec'),
322
+ (bool) $instance['rssfeed']);
323
 
324
+ avh_doWidgetFormText($this->get_field_id('rssimage'),
325
+ $this->get_field_name('rssimage'),
326
+ __('Path (URI) to RSS image', 'avh-ec'),
327
+ $instance['rssimage']);
328
  echo '</p>';
329
 
330
  echo '<p>';
331
+ echo '<b>' . __('Select Groups', 'avh-ec') . '</b><hr />';
332
  echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear" style="list-style-type: none; margin-left: 5px; padding-left: 0px; margin-bottom: 20px;">';
333
+ echo '<li id="' . $this->get_field_id('group_category--1') . '" class="popular-group_category">';
334
+ echo '<label for="' . $this->get_field_id('group_post_category') . '" class="selectit">';
335
+ echo '<input value="all" id="' .
336
+ $this->get_field_id('group_post_category') .
337
+ '" name="' .
338
+ $this->get_field_name('post_group_category') .
339
+ '[all]" type="checkbox" ' .
340
+ (false === $selected_cats ? ' CHECKED' : '') .
341
+ '> ';
342
+ _e('Any Group', 'avh-ec');
343
  echo '</label>';
344
  echo '</li>';
345
+
346
+ $this->avh_wp_group_category_checklist($selected_cats, $this->number);
347
+
348
  echo '</ul>';
349
  echo '</p>';
350
 
351
+ echo '<input type="hidden" id="' .
352
+ $this->get_field_id('submit') .
353
+ '" name="' .
354
+ $this->get_field_name('submit') .
355
+ '" value="1" />';
356
+ ob_end_flush();
357
+ }
358
+
359
+ function getWidgetDoneCatGroup($id) {
360
+ $catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
361
+ if (is_array($catgrp->widget_done_catgroup) && array_key_exists($id, $catgrp->widget_done_catgroup)) {
362
+ return true;
363
+ }
364
+ $catgrp->widget_done_catgroup[ $id ] = true;
365
 
366
+ return false;
367
  }
368
 
369
  /**
370
+ * When Widget Control Form Is Posted
371
  *
372
+ * @param unknown_type $new_instance
373
+ * @param unknown_type $old_instance
374
+ *
375
+ * @return unknown
 
376
  */
377
+ function update($new_instance, $old_instance) {
378
+ // update the instance's settings
379
+ if ( ! isset($new_instance['submit'])) {
380
+ return false;
381
+ }
 
 
 
 
 
 
 
 
 
 
382
 
383
+ $instance = $old_instance;
 
384
 
385
+ $instance['title'] = strip_tags(stripslashes($new_instance['title']));
386
+ $instance['count'] = $new_instance['count'] ? true : false;
387
+ $instance['hierarchical'] = $new_instance['hierarchical'] ? true : false;
388
+ $instance['hide_empty'] = $new_instance['hide_empty'] ? true : false;
389
+ $instance['use_desc_for_title'] = $new_instance['use_desc_for_title'] ? true : false;
390
+ $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column']));
391
+ $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order']));
392
+ $instance['style'] = strip_tags(stripslashes($new_instance['style']));
393
+ $instance['rssfeed'] = $new_instance['rssfeed'] ? true : false;
394
+ $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage']));
395
+ if (array_key_exists('all', $new_instance['post_group_category'])) {
396
+ $instance['post_group_category'] = false;
397
+ } else {
398
+ $instance['post_group_category'] = serialize($new_instance['post_group_category']);
399
  }
400
 
401
+ return $instance;
 
 
 
402
  }
 
403
 
 
 
 
 
 
 
404
  /**
405
+ * Display the widget
406
  *
407
+ * @param unknown_type $args
408
+ * @param unknown_type $instance
409
  */
410
+ function widget($args, $instance) {
411
+ global $post, $wp_query;
412
 
413
+ $catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
414
  $options = $this->core->getOptions();
415
 
416
+ $row = array();
417
 
418
  if (is_home()) {
419
  $special_page = 'home_group';
433
  $special_page = 'none';
434
  }
435
 
436
+ $toDisplay = false;
437
  if ('none' == $special_page) {
438
  $terms = wp_get_object_terms($post->ID, $catgrp->taxonomy_name);
439
+ if ( ! empty($terms)) {
440
  $selected_catgroups = unserialize($instance['post_group_category']);
441
  foreach ($terms as $key => $value) {
442
+ if ($selected_catgroups === false || array_key_exists($value->term_id, $selected_catgroups)) {
443
+ if ( ! ($this->getWidgetDoneCatGroup($value->term_id))) {
444
+ $row = $value;
445
+ $group_found = true;
446
  break;
447
  }
448
  }
449
  }
450
  } else {
451
+ $options = $this->core->options;
452
  $no_cat_group = $options['cat_group']['no_group'];
453
+ $row = get_term_by('id', $no_cat_group, $catgrp->taxonomy_name);
454
+ $group_found = true;
455
  }
456
  } else {
457
  if ('category_group' == $special_page) {
458
  $tax_meta = get_option($this->core->db_options_tax_meta);
459
+ $term = $wp_query->get_queried_object();
460
+ if (isset($tax_meta[ $term->taxonomy ][ $term->term_id ]['category_group_term_id'])) {
461
+ $sp_category_group_id = $tax_meta[ $term->taxonomy ][ $term->term_id ]['category_group_term_id'];
462
  } else {
463
+ $sp_category_group = $this->catgrp->getGroupByCategoryID($term->term_id);
464
  $sp_category_group_id = $sp_category_group->term_id;
465
  }
466
  } else {
467
+ $sp_category_group_id = $options['sp_cat_group'][ $special_page ];
468
  }
469
+ $row = get_term_by('id',
470
+ $sp_category_group_id,
471
+ $catgrp->taxonomy_name); // Returns FALSE when non-existance. (empty(FALSE)=TRUE)
472
+ $group_found = true;
473
  }
474
 
475
  if ($group_found) {
476
+ $toDisplay = true;
477
  $category_group_id_none = $this->catgrp->getTermIDBy('slug', 'none');
478
+ $selected_catgroups = unserialize($instance['post_group_category']);
479
 
480
  if ($category_group_id_none == $row->term_id) {
481
+ $toDisplay = false;
482
+ } elseif ( ! (false == $selected_catgroups || array_key_exists($row->term_id, $selected_catgroups))) {
483
+ $toDisplay = false;
484
  } elseif ($special_page != 'none' && $this->getWidgetDoneCatGroup($sp_category_group_id)) {
485
+ $toDisplay = false;
486
  }
487
  }
488
 
489
  if ($toDisplay) {
490
  extract($args);
491
 
492
+ $c = $instance['count'] ? true : false;
493
+ $e = $instance['hide_empty'] ? true : false;
494
+ $h = $instance['hierarchical'] ? true : false;
495
+ $use_desc_for_title = $instance['use_desc_for_title'] ? true : false;
496
+ $s = $instance['sort_column'] ? $instance['sort_column'] : 'name';
497
+ $o = $instance['sort_order'] ? $instance['sort_order'] : 'asc';
498
+ $r = $instance['rssfeed'] ? 'RSS' : '';
499
+ $i = $instance['rssimage'] ? $instance['rssimage'] : '';
500
 
501
  if (empty($r)) {
502
  $i = '';
503
  }
504
 
505
+ $style = empty($instance['style']) ? 'list' : $instance['style'];
506
  $group_id = $row->term_id;
507
+ $cats = $catgrp->getCategoriesFromGroup($group_id);
508
  if (empty($instance['title'])) {
509
  $title = $catgrp->getWidgetTitleForGroup($group_id);
510
+ if ( ! $title) {
511
  $title = __('Categories', 'avh-ec');
512
  }
513
  } else {
522
  $show_option_none = $options['general']['alternative_name_select_category'];
523
  }
524
 
525
+ $cat_args = array(
526
+ 'include' => $included_cats,
527
+ 'orderby' => $s,
528
+ 'order' => $o,
529
+ 'show_count' => $c,
530
+ 'use_desc_for_title' => $use_desc_for_title,
531
+ 'hide_empty' => $e,
532
+ 'hierarchical' => $h,
533
+ 'title_li' => '',
534
+ 'show_option_none' => $show_option_none,
535
+ 'feed' => $r,
536
+ 'feed_image' => $i,
537
+ 'name' => 'extended-categories-select-group-' . $this->number
538
+ );
539
  echo $before_widget;
540
  echo $this->core->comment;
541
  echo $before_title . $title . $after_title;
542
 
543
  if ($style == 'list') {
544
  echo '<ul>';
545
+ $this->core->avh_wp_list_categories($cat_args, true);
546
  echo '</ul>';
547
  } else {
548
+ $this->core->avh_wp_dropdown_categories($cat_args, true);
549
  echo '<script type=\'text/javascript\'>' . "\n";
550
  echo '/* <![CDATA[ */' . "\n";
551
+ echo ' var ec_dropdown_' .
552
+ $this->number .
553
+ ' = document.getElementById("extended-categories-select-group-' .
554
+ $this->number .
555
+ '");' .
556
+ "\n";
557
  echo ' function ec_onCatChange_' . $this->number . '() {' . "\n";
558
+ echo ' if ( ec_dropdown_' .
559
+ $this->number .
560
+ '.options[ec_dropdown_' .
561
+ $this->number .
562
+ '.selectedIndex].value > 0 ) {' .
563
+ "\n";
564
+ echo ' location.href = "' .
565
+ get_option('home') .
566
+ '/?cat="+ec_dropdown_' .
567
+ $this->number .
568
+ '.options[ec_dropdown_' .
569
+ $this->number .
570
+ '.selectedIndex].value;' .
571
+ "\n";
572
  echo ' }' . "\n";
573
  echo ' }' . "\n";
574
+ echo ' ec_dropdown_' .
575
+ $this->number .
576
+ '.onchange = ec_onCatChange_' .
577
+ $this->number .
578
+ ';' .
579
+ "\n";
580
  echo '/* ]]> */' . "\n";
581
  echo '</script>' . "\n";
582
  }
583
  echo $after_widget;
584
  }
585
  }
586
+ }
587
 
588
+ /**
589
+ * Widget Class for displaying categories. Extended version of the dfeault categories.
590
+ */
591
+ class WP_Widget_AVH_ExtendedCategories_Normal extends WP_Widget {
592
  /**
593
+ * @var AVH_EC_Core
 
 
 
 
594
  */
595
+ var $core;
596
+
597
+ /**
598
+ * PHP 5 Constructor
599
+ */
600
+ function __construct() {
601
+ $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core');
602
+
603
+ //Convert the old option widget_extended_categories to widget_extended-categories
604
+ $old = get_option('widget_extended_categories');
605
+ if ( ! (false === $old)) {
606
+ update_option('widget_extended-categories', $old);
607
+ delete_option('widget_extended_categories');
608
  }
609
+ $widget_ops = array('description' => __("An extended version of the default Categories widget.", 'avh-ec'));
610
+ WP_Widget::__construct('extended-categories', 'AVH Extended Categories', $widget_ops);
611
 
612
+ add_action('wp_print_styles', array(&$this, 'actionWpPrintStyles'));
613
+ }
614
 
615
+ function WP_Widget_AVH_ExtendedCategories_Normal() {
616
+ $this->__construct();
617
+ }
618
+
619
+ function actionWpPrintStyles() {
620
+
621
+ if ( ! (false === is_active_widget(false, false, $this->id_base, true))) {
622
+ wp_register_style('avhec-widget',
623
+ AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css',
624
+ array(),
625
+ $this->core->version);
626
+ wp_enqueue_style('avhec-widget');
627
+ }
628
+ }
629
+
630
+ /**
631
+ * Creates the categories checklist
632
+ *
633
+ * @param int $post_id
634
+ * @param int $descendants_and_self
635
+ * @param array $selected_cats
636
+ * @param array $popular_cats
637
+ * @param int $number
638
+ */
639
+ function avh_wp_category_checklist($selected_cats, $number) {
640
+
641
+ $walker = new AVH_Walker_Category_Checklist();
642
+ $walker->number = $number;
643
+ $walker->input_id = $this->get_field_id('post_category');
644
+ $walker->input_name = $this->get_field_name('post_category');
645
+ $walker->li_id = $this->get_field_id('category--1');
646
+
647
+ $args = array(
648
+ 'taxonomy' => 'category',
649
+ 'descendants_and_self' => 0,
650
+ 'selected_cats' => $selected_cats,
651
+ 'popular_cats' => array(),
652
+ 'walker' => $walker,
653
+ 'checked_ontop' => true,
654
+ 'popular_cats' => array()
655
+ );
656
+
657
+ if (is_array($selected_cats)) {
658
+ $args['selected_cats'] = $selected_cats;
659
  } else {
660
+ $args['selected_cats'] = array();
661
  }
662
+
663
+ $categories = $this->core->getCategories();
664
+ $_categories_id = $this->core->getCategoriesId($categories);
665
+
666
+ // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache)
667
+ $checked_categories = array();
668
+ foreach ($args['selected_cats'] as $key => $value) {
669
+ if (isset($_categories_id[ $key ])) {
670
+ $category_key = $_categories_id[ $key ];
671
+ $checked_categories[] = $categories[ $category_key ];
672
+ unset($categories[ $category_key ]);
673
+ }
674
+ }
675
+
676
+ // Put checked cats on top
677
+ echo $walker->walk($checked_categories, 0, array($args));
678
+ // Then the rest of them
679
+ echo $walker->walk($categories, 0, array($args));
680
  }
681
 
682
  /**
684
  *
685
  * @param unknown_type $instance
686
  */
687
+ function form($instance) {
 
688
  // displays the widget admin form
689
+ $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => '', 'depth' => 0));
690
 
691
  // Prepare data for display
692
+ $depth = (int) $instance['depth'];
693
+ if ($depth < 0 || 11 < $depth) {
694
+ $depth = 0;
695
+ }
696
+ $selected_cats = ($instance['post_category'] != '') ? unserialize($instance['post_category']) : false;
697
+
 
 
 
 
 
 
 
 
 
 
 
698
  echo '<p>';
699
+ avh_doWidgetFormText($this->get_field_id('title'),
700
+ $this->get_field_name('title'),
701
+ __('Title', 'avh-ec'),
702
+ $instance['title']);
703
  echo '</p>';
704
 
705
  echo '<p>';
706
+ avh_doWidgetFormCheckbox($this->get_field_id('selectedonly'),
707
+ $this->get_field_name('selectedonly'),
708
+ __('Show selected categories only', 'avh-ec'),
709
+ (bool) $instance['selectedonly']);
710
+
711
+ avh_doWidgetFormCheckbox($this->get_field_id('count'),
712
+ $this->get_field_name('count'),
713
+ __('Show post counts', 'avh-ec'),
714
+ (bool) $instance['count']);
715
+
716
+ avh_doWidgetFormCheckbox($this->get_field_id('hierarchical'),
717
+ $this->get_field_name('hierarchical'),
718
+ __('Show hierarchy', 'avh-ec'),
719
+ (bool) $instance['hierarchical']);
720
+
721
+ $options = array(0 => __('All Levels', 'avh-ec'), 1 => __('Toplevel only', 'avh-ec'));
722
+ for ($i = 2; $i <= 11; $i ++) {
723
+ $options[ $i ] = __('Child ', 'avh-ec') . ($i - 1);
724
+ }
725
+ avh_doWidgetFormSelect($this->get_field_id('depth'),
726
+ $this->get_field_name('depth'),
727
+ __('How many levels to show', 'avh-ec'),
728
+ $options,
729
+ $depth);
730
+ unset($options);
731
 
732
+ avh_doWidgetFormCheckbox($this->get_field_id('hide_empty'),
733
+ $this->get_field_name('hide_empty'),
734
+ __('Hide empty categories', 'avh-ec'),
735
+ (bool) $instance['hide_empty']);
 
736
 
737
+ avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'),
738
+ $this->get_field_name('use_desc_for_title'),
739
+ __('Use description for title', 'avh-ec'),
740
+ (bool) $instance['use_desc_for_title']);
741
  echo '</p>';
742
 
743
  echo '<p>';
744
+ $options['ID'] = __('ID', 'avh-ec');
745
+ $options['name'] = __('Name', 'avh-ec');
746
+ $options['count'] = __('Count', 'avh-ec');
747
+ $options['slug'] = __('Slug', 'avh-ec');
748
+ $options['avhec_manualorder'] = 'AVH EC ' . __('Manual Order', 'avh-ec');
749
+ if (is_plugin_active('my-category-order/mycategoryorder.php')) {
750
+ $options['avhec_3rdparty_mycategoryorder'] = 'My Category Order';
751
+ }
752
+
753
+ avh_doWidgetFormSelect($this->get_field_id('sort_column'),
754
+ $this->get_field_name('sort_column'),
755
+ __('Sort by', 'avh-ec'),
756
+ $options,
757
+ $instance['sort_column']);
758
  unset($options);
759
 
760
+ $options['asc'] = __('Ascending', 'avh-ec');
761
  $options['desc'] = __('Descending', 'avh-ec');
762
+ avh_doWidgetFormSelect($this->get_field_id('sort_order'),
763
+ $this->get_field_name('sort_order'),
764
+ __('Sort order', 'avh-ec'),
765
+ $options,
766
+ $instance['sort_order']);
767
  unset($options);
768
 
769
  $options['list'] = __('List', 'avh-ec');
770
  $options['drop'] = __('Drop down', 'avh-ec');
771
+ avh_doWidgetFormSelect($this->get_field_id('style'),
772
+ $this->get_field_name('style'),
773
+ __('Display style', 'avh-ec'),
774
+ $options,
775
+ $instance['style']);
776
  unset($options);
777
  echo '</p>';
778
 
779
  echo '<p>';
780
 
781
+ avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'),
782
+ $this->get_field_name('rssfeed'),
783
+ __('Show RSS Feed', 'avh-ec'),
784
+ (bool) $instance['rssfeed']);
785
+
786
+ avh_doWidgetFormText($this->get_field_id('rssimage'),
787
+ $this->get_field_name('rssimage'),
788
+ __('Path (URI) to RSS image', 'avh-ec'),
789
+ $instance['rssimage']);
790
 
 
791
  echo '</p>';
792
 
793
  echo '<p>';
794
+ echo '<b>' . __('Select categories', 'avh-ec') . '</b><hr />';
795
  echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear" style="list-style-type: none; margin-left: 5px; padding-left: 0px; margin-bottom: 20px;">';
796
+ echo '<li id="' . $this->get_field_id('category--1') . '" class="popular-category">';
797
+ echo '<label for="' . $this->get_field_id('post_category') . '" class="selectit">';
798
+ echo '<input value="all" id="' .
799
+ $this->get_field_id('post_category') .
800
+ '" name="' .
801
+ $this->get_field_name('post_category') .
802
+ '[all]" type="checkbox" ' .
803
+ (false === $selected_cats ? ' CHECKED' : '') .
804
+ '> ';
805
+ _e('All Categories', 'avh-ec');
806
  echo '</label>';
807
  echo '</li>';
808
+ ob_start();
809
+ $this->avh_wp_category_checklist($selected_cats, $this->number);
810
+ ob_end_flush();
811
  echo '</ul>';
812
  echo '</p>';
813
 
814
+ echo '<p>';
815
+ avh_doWidgetFormCheckbox($this->get_field_id('invert_included'),
816
+ $this->get_field_name('invert_included'),
817
+ __('Exclude the selected categories', 'avh-ec'),
818
+ (bool) $instance['invert_included']);
819
+ echo '</p>';
820
+
821
+ echo '<input type="hidden" id="' .
822
+ $this->get_field_id('submit') .
823
+ '" name="' .
824
+ $this->get_field_name('submit') .
825
+ '" value="1" />';
826
  }
827
 
828
+ /**
829
+ * When Widget Control Form Is Posted
830
+ *
831
+ * @param unknown_type $new_instance
832
+ * @param unknown_type $old_instance
833
+ *
834
+ * @return unknown
835
+ */
836
+ function update($new_instance, $old_instance) {
837
+ // update the instance's settings
838
+ if ( ! isset($new_instance['submit'])) {
839
+ return false;
840
+ }
841
 
842
+ $instance = $old_instance;
 
 
 
 
843
 
844
+ $instance['title'] = strip_tags(stripslashes($new_instance['title']));
845
+ $instance['selectedonly'] = $new_instance['selectedonly'] ? true : false;
846
+ $instance['count'] = $new_instance['count'] ? true : false;
847
+ $instance['hierarchical'] = $new_instance['hierarchical'] ? true : false;
848
+ $instance['hide_empty'] = $new_instance['hide_empty'] ? true : false;
849
+ $instance['use_desc_for_title'] = $new_instance['use_desc_for_title'] ? true : false;
850
+ $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column']));
851
+ $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order']));
852
+ $instance['style'] = strip_tags(stripslashes($new_instance['style']));
853
+ $instance['rssfeed'] = $new_instance['rssfeed'] ? true : false;
854
+ $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage']));
855
+ if (array_key_exists('all', $new_instance['post_category'])) {
856
+ $instance['post_category'] = false;
857
+ } else {
858
+ $instance['post_category'] = serialize($new_instance['post_category']);
859
+ }
860
+ $instance['depth'] = (int) $new_instance['depth'];
861
+ if ($instance['depth'] < 0 || 11 < $instance['depth']) {
862
+ $instance['depth'] = 0;
863
+ }
864
+ $instance['invert_included'] = $new_instance['invert_included'] ? true : false;
865
 
866
+ return $instance;
867
+ }
 
 
868
 
869
+ /**
870
+ * Display the widget
871
+ *
872
+ * @param unknown_type $args
873
+ * @param unknown_type $instance
874
+ */
875
+ function widget($args, $instance) {
876
 
877
+ extract($args);
 
 
878
 
879
+ $selectedonly = $instance['selectedonly'] ? true : false;
880
+ $c = $instance['count'] ? true : false;
881
+ $h = $instance['hierarchical'] ? true : false;
882
+ $d = $instance['depth'] ? $instance['depth'] : 0;
883
+ $e = $instance['hide_empty'] ? true : false;
884
+ $use_desc_for_title = $instance['use_desc_for_title'] ? true : false;
885
+ $s = $instance['sort_column'] ? $instance['sort_column'] : 'name';
886
+ $o = $instance['sort_order'] ? $instance['sort_order'] : 'asc';
887
+ $r = $instance['rssfeed'] ? 'RSS' : '';
888
+ $i = $instance['rssimage'] ? $instance['rssimage'] : '';
889
+ $invert = $instance['invert_included'] ? true : false;
890
+
891
+ if (empty($r)) {
892
+ $i = '';
893
+ }
894
+
895
+ if (empty($d)) {
896
+ $d = 0;
897
+ }
898
+
899
+ $title = apply_filters('widget_title',
900
+ empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']);
901
+ $style = empty($instance['style']) ? 'list' : $instance['style'];
902
+
903
+ $included_cats = '';
904
+ if ($instance['post_category']) {
905
+ $post_category = unserialize($instance['post_category']);
906
+ $children = array();
907
+ if ( ! $instance['selectedonly']) {
908
+ foreach ($post_category as $cat_id) {
909
+ $children = array_merge($children, get_term_children($cat_id, 'category'));
910
+ }
911
  }
912
+ $included_cats = implode(",", array_merge($post_category, $children));
913
  }
914
 
915
+ if ($invert) {
916
+ $inc_exc = 'exclude';
917
+ } else {
918
+ $inc_exc = 'include';
919
+ }
920
 
921
+ $options = $this->core->getOptions();
922
+ $show_option_none = __('Select Category', 'avh-ec');
923
+ if ($options['general']['alternative_name_select_category']) {
924
+ $show_option_none = $options['general']['alternative_name_select_category'];
925
+ }
926
+
927
+ $cat_args = array(
928
+ $inc_exc => $included_cats,
929
+ 'orderby' => $s,
930
+ 'order' => $o,
931
+ 'show_count' => $c,
932
+ 'use_desc_for_title' => $use_desc_for_title,
933
+ 'hide_empty' => $e,
934
+ 'hierarchical' => $h,
935
+ 'depth' => $d,
936
+ 'title_li' => '',
937
+ 'show_option_none' => $show_option_none,
938
+ 'feed' => $r,
939
+ 'feed_image' => $i,
940
+ 'name' => 'extended-categories-select-' . $this->number
941
+ );
942
+ echo $before_widget;
943
+ echo $this->core->comment;
944
+ echo $before_title . $title . $after_title;
945
+
946
+ if ($style == 'list') {
947
+ echo '<ul>';
948
+ $this->core->avh_wp_list_categories($cat_args, $selectedonly);
949
+ echo '</ul>';
950
+ } else {
951
+ $this->core->avh_wp_dropdown_categories($cat_args, $selectedonly);
952
+ echo '<script type=\'text/javascript\'>' . "\n";
953
+ echo '/* <![CDATA[ */' . "\n";
954
+ echo ' var ec_dropdown_' .
955
+ $this->number .
956
+ ' = document.getElementById("extended-categories-select-' .
957
+ $this->number .
958
+ '");' .
959
+ "\n";
960
+ echo ' function ec_onCatChange_' . $this->number . '() {' . "\n";
961
+ echo ' if ( ec_dropdown_' .
962
+ $this->number .
963
+ '.options[ec_dropdown_' .
964
+ $this->number .
965
+ '.selectedIndex].value > 0 ) {' .
966
+ "\n";
967
+ echo ' location.href = "' .
968
+ home_url() .
969
+ '/?cat="+ec_dropdown_' .
970
+ $this->number .
971
+ '.options[ec_dropdown_' .
972
+ $this->number .
973
+ '.selectedIndex].value;' .
974
+ "\n";
975
+ echo ' }' . "\n";
976
+ echo ' }' . "\n";
977
+ echo ' ec_dropdown_' .
978
+ $this->number .
979
+ '.onchange = ec_onCatChange_' .
980
+ $this->number .
981
+ ';' .
982
+ "\n";
983
+ echo '/* ]]> */' . "\n";
984
+ echo '</script>' . "\n";
985
  }
986
+ echo $after_widget;
 
987
  }
988
  }
989
 
990
  /**
991
+ * Widget Class for displaying the top categories
 
992
  */
993
+ class WP_Widget_AVH_ExtendedCategories_Top extends WP_Widget {
994
+ /**
995
+ * @var AVH_EC_Core
996
+ */
997
+ var $core;
 
 
 
998
 
999
  /**
1000
+ * PHP 5 Constructor
 
 
 
 
 
 
 
 
 
 
 
 
1001
  */
1002
+ function __construct() {
1003
+ $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core');
1004
 
1005
+ $widget_ops = array('description' => __("Shows the top categories.", 'avh-ec'));
1006
+ WP_Widget::__construct(false, 'AVH Extended Categories: ' . __('Top Categories'), $widget_ops);
1007
+ add_action('wp_print_styles', array(&$this, 'actionWpPrintStyles'));
1008
+ }
1009
 
1010
+ function WP_Widget_AVH_ExtendedCategories_Top() {
1011
+ $this->__construct();
1012
+ }
1013
 
1014
+ function actionWpPrintStyles() {
1015
+ if ( ! (false === is_active_widget(false, false, $this->id_base, true))) {
1016
+ wp_register_style('avhec-widget',
1017
+ AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css',
1018
+ array(),
1019
+ $this->core->version);
1020
+ wp_enqueue_style('avhec-widget');
1021
+ }
1022
+ }
1023
 
1024
+ /** Echo the settings update form
1025
+ *
1026
+ * @param array $instance Current settings
1027
+ */
1028
+ function form($instance) {
1029
+ // displays the widget admin form
1030
+ $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => ''));
1031
 
1032
+ // Prepare data for display
1033
+ if ( ! $amount = (int) $instance['amount']) {
1034
+ $amount = 5;
 
 
 
1035
  }
1036
 
1037
+ if ($amount < 1) {
1038
+ $amount = 1;
 
 
 
 
 
 
 
 
 
 
 
1039
  }
1040
+ echo '<p>';
1041
+ avh_doWidgetFormText($this->get_field_id('title'),
1042
+ $this->get_field_name('title'),
1043
+ __('Title', 'avh-ec'),
1044
+ $instance['title']);
1045
+ echo '</p>';
1046
 
1047
+ echo '<p>';
1048
+ avh_doWidgetFormText($this->get_field_id('amount'),
1049
+ $this->get_field_name('amount'),
1050
+ __('How many categories to show', 'avh-ec'),
1051
+ $amount);
1052
+ echo '</p>';
1053
 
1054
+ echo '<p>';
1055
+ avh_doWidgetFormCheckbox($this->get_field_id('count'),
1056
+ $this->get_field_name('count'),
1057
+ __('Show post counts', 'avh-ec'),
1058
+ (bool) $instance['count']);
1059
+ echo '<br />';
1060
 
1061
+ avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'),
1062
+ $this->get_field_name('use_desc_for_title'),
1063
+ __('Use description for title', 'avh-ec'),
1064
+ (bool) $instance['use_desc_for_title']);
1065
+ echo '</p>';
 
 
 
 
1066
 
1067
+ echo '<p>';
1068
+ $options['ID'] = __('ID', 'avh-ec');
1069
+ $options['name'] = __('Name', 'avh-ec');
1070
+ $options['count'] = __('Count', 'avh-ec');
1071
+ $options['slug'] = __('Slug', 'avh-ec');
1072
+ avh_doWidgetFormSelect($this->get_field_id('sort_column'),
1073
+ $this->get_field_name('sort_column'),
1074
+ __('Sort by', 'avh-ec'),
1075
+ $options,
1076
+ $instance['sort_column']);
1077
+ unset($options);
1078
 
1079
+ $options['asc'] = __('Ascending', 'avh-ec');
1080
+ $options['desc'] = __('Descending', 'avh-ec');
1081
+ avh_doWidgetFormSelect($this->get_field_id('sort_order'),
1082
+ $this->get_field_name('sort_order'),
1083
+ __('Sort order', 'avh-ec'),
1084
+ $options,
1085
+ $instance['sort_order']);
1086
+ unset($options);
 
 
1087
 
1088
+ $options['list'] = __('List', 'avh-ec');
1089
+ $options['drop'] = __('Drop down', 'avh-ec');
1090
+ avh_doWidgetFormSelect($this->get_field_id('style'),
1091
+ $this->get_field_name('style'),
1092
+ __('Display style', 'avh-ec'),
1093
+ $options,
1094
+ $instance['style']);
1095
+ unset($options);
1096
+ echo '</p>';
1097
 
1098
+ echo '<p>';
1099
+
1100
+ avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'),
1101
+ $this->get_field_name('rssfeed'),
1102
+ __('Show RSS Feed', 'avh-ec'),
1103
+ (bool) $instance['rssfeed']);
1104
+
1105
+ avh_doWidgetFormText($this->get_field_id('rssimage'),
1106
+ $this->get_field_name('rssimage'),
1107
+ __('Path (URI) to RSS image', 'avh-ec'),
1108
+ $instance['rssimage']);
1109
+
1110
+ echo '</p>';
1111
+
1112
+ echo '<input type="hidden" id="' .
1113
+ $this->get_field_id('submit') .
1114
+ '" name="' .
1115
+ $this->get_field_name('submit') .
1116
+ '" value="1" />';
1117
  }
1118
 
1119
+ /** Update a particular instance.
1120
+ * This function should check that $new_instance is set correctly.
1121
+ * The newly calculated value of $instance should be returned.
1122
+ * If "FALSE" is returned, the instance won't be saved/updated.
1123
+ *
1124
+ * @param array $new_instance New settings for this instance as input by the user via form()
1125
+ * @param array $old_instance Old settings for this instance
1126
+ *
1127
+ * @return array Settings to save or bool FALSE to cancel saving
1128
+ */
1129
+ function update($new_instance, $old_instance) {
1130
+ // update the instance's settings
1131
+ if ( ! isset($new_instance['submit'])) {
1132
+ return false;
1133
+ }
1134
+
1135
+ $instance = $old_instance;
1136
+
1137
+ $instance['title'] = strip_tags(stripslashes($new_instance['title']));
1138
+ $instance['amount'] = (int) $new_instance['amount'];
1139
+ $instance['count'] = $new_instance['count'] ? true : false;
1140
+ $instance['use_desc_for_title'] = $new_instance['use_desc_for_title'] ? true : false;
1141
+ $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column']));
1142
+ $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order']));
1143
+ $instance['style'] = strip_tags(stripslashes($new_instance['style']));
1144
+ $instance['rssfeed'] = $new_instance['rssfeed'] ? true : false;
1145
+ $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage']));
1146
+
1147
+ return $instance;
1148
  }
1149
 
1150
+ /** Echo the widget content.
1151
+ * Subclasses should over-ride this function to generate their widget code.
1152
+ *
1153
+ * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
1154
+ * @param array $instance The settings for the particular instance of the widget
1155
+ */
1156
+ function widget($args, $instance) {
1157
  extract($args);
 
 
 
 
 
1158
 
1159
+ $title = apply_filters('widget_title',
1160
+ empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']);
1161
+ $style = empty($instance['style']) ? 'list' : $instance['style'];
1162
+ if ( ! $a = (int) $instance['amount']) {
1163
+ $a = 5;
1164
+ } elseif ($a < 1) {
1165
+ $a = 1;
1166
+ }
1167
+ $c = $instance['count'] ? true : false;
1168
+ $use_desc_for_title = $instance['use_desc_for_title'] ? true : false;
1169
+ $s = $instance['sort_column'] ? $instance['sort_column'] : 'name';
1170
+ $o = $instance['sort_order'] ? $instance['sort_order'] : 'asc';
1171
+ $r = $instance['rssfeed'] ? 'RSS' : '';
1172
+ $i = $instance['rssimage'] ? $instance['rssimage'] : '';
1173
+ if (empty($r)) {
1174
+ $i = '';
1175
+ }
1176
+ if ( ! empty($i)) {
1177
+ if ( ! file_exists(ABSPATH . '/' . $i)) {
1178
+ $i = '';
1179
+ }
1180
+ }
1181
+
1182
+ $options = $this->core->getOptions();
1183
+ $show_option_none = __('Select Category', 'avh-ec');
1184
+ if ($options['general']['alternative_name_select_category']) {
1185
+ $show_option_none = $options['general']['alternative_name_select_category'];
1186
+ }
1187
+
1188
+ $top_cats = get_terms('category',
1189
+ array(
1190
+ 'fields' => 'ids',
1191
+ 'orderby' => 'count',
1192
+ 'order' => 'DESC',
1193
+ 'number' => $a,
1194
+ 'hierarchical' => false
1195
+ ));
1196
+ $included_cats = implode(",", $top_cats);
1197
+
1198
+ $cat_args = array(
1199
+ 'include' => $included_cats,
1200
+ 'orderby' => $s,
1201
+ 'order' => $o,
1202
+ 'show_count' => $c,
1203
+ 'use_desc_for_title' => $use_desc_for_title,
1204
+ 'hide_empty' => false,
1205
+ 'hierarchical' => false,
1206
+ 'depth' => - 1,
1207
+ 'title_li' => '',
1208
+ 'show_option_none' => $show_option_none,
1209
+ 'feed' => $r,
1210
+ 'feed_image' => $i,
1211
+ 'name' => 'extended-categories-top-select-' . $this->number
1212
+ );
1213
+ echo $before_widget;
1214
+ echo $this->core->comment;
1215
+ echo $before_title . $title . $after_title;
1216
+ echo '<ul>';
1217
+
1218
+ if ($style == 'list') {
1219
+ wp_list_categories($cat_args);
1220
+ } else {
1221
+ wp_dropdown_categories($cat_args);
1222
+ echo '<script type=\'text/javascript\'>' . "\n";
1223
+ echo '/* <![CDATA[ */' . "\n";
1224
+ echo ' var ec_dropdown_top_' .
1225
+ $this->number .
1226
+ ' = document.getElementById("extended-categories-top-select-' .
1227
+ $this->number .
1228
+ '");' .
1229
+ "\n";
1230
+ echo ' function ec_top_onCatChange_' . $this->number . '() {' . "\n";
1231
+ echo ' if ( ec_dropdown_top_' .
1232
+ $this->number .
1233
+ '.options[ec_dropdown_top_' .
1234
+ $this->number .
1235
+ '.selectedIndex].value > 0 ) {' .
1236
+ "\n";
1237
+ echo ' location.href = "' .
1238
+ get_option('home') .
1239
+ '/?cat="+ec_dropdown_top_' .
1240
+ $this->number .
1241
+ '.options[ec_dropdown_top_' .
1242
+ $this->number .
1243
+ '.selectedIndex].value;' .
1244
+ "\n";
1245
+ echo ' }' . "\n";
1246
+ echo ' }' . "\n";
1247
+ echo ' ec_dropdown_top_' .
1248
+ $this->number .
1249
+ '.onchange = ec_top_onCatChange_' .
1250
+ $this->number .
1251
+ ';' .
1252
+ "\n";
1253
+ echo '/* ]]> */' . "\n";
1254
+ echo '</script>' . "\n";
1255
+ }
1256
+ echo '</ul>';
1257
+ echo $after_widget;
1258
  }
1259
  }
1260
+
1261
  ?>
3.3/css/avh-ec.admin.css CHANGED
@@ -1,13 +1,13 @@
1
  .footer_avhec {
2
- font-size: 0.8em;
3
- text-align: center;
4
  }
5
 
6
  div.clearer {
7
- clear: both;
8
- line-height: 1px;
9
- font-size: 1px;
10
- height: 1px;
11
  }
12
 
13
  /* Metabox in General */
@@ -20,12 +20,12 @@ table.avhec-options {
20
  }
21
 
22
  .avhec-metabox-wrap .p {
23
- line-height: 140%;
24
- margin: 1em 0;
25
  }
26
 
27
  #avhecBoxOptions option {
28
- padding: .5em;
29
  }
30
 
31
  .avhec-metabox-wrap span.description {
@@ -33,17 +33,17 @@ table.avhec-options {
33
  }
34
 
35
  .avhec-metabox-wrap .b {
36
- font-weight: bold;
37
  }
38
 
39
  .avhec-metabox-wrap ul {
40
- margin-bottom: 1em;
41
  }
42
 
43
  .avhec-metabox-wrap ul li {
44
- line-height: 120%;
45
- list-style: disc inside none;
46
- margin-bottom: 0;
47
  }
48
 
49
  #avhec-options input {
@@ -56,13 +56,13 @@ table.avhec-options {
56
 
57
  /* Metabox FAQ */
58
  #avhecBoxFAQ .inside ul {
59
- margin-bottom: 6px;
60
  }
61
 
62
  #avhecBoxFAQ .inside ul li {
63
- line-height: 120%;
64
- list-style: disc inside none;
65
- margin-bottom: 0;
66
  }
67
 
68
  /* Metabox Donations*/
@@ -71,7 +71,7 @@ table.avhec-options {
71
  }
72
 
73
  #avhecBoxDonations .versions {
74
- padding: 6px 10px 12px;
75
  }
76
 
77
  /* Metabox Donations*/
@@ -81,75 +81,75 @@ table.avhec-options {
81
 
82
  /* Metabox in post and page */
83
  #post_avhec_category_group {
84
- width: 100%;
85
  }
86
 
87
  #avhec-catlist {
88
- -moz-border-radius: 4px 4px 4px 4px;
89
- background-color: #FFFFFF;
90
- border: 1px solid #DFDFDF;
91
- height: 20em;
92
- margin-bottom: -1.8em;
93
- overflow: auto;
94
- width: 95%;
95
  }
96
 
97
  #avhec-catlist ul {
98
- padding: 3px;
99
  }
100
 
101
  #avhec-catlist li ul {
102
- padding: 0px;
103
  }
104
 
105
  #avhec-catlist li {
106
- margin-bottom: 0px;
107
  }
108
 
109
  #avhecManualOrder {
110
- width: 25%;
111
- /* border: 1px solid #B2B2B2;*/
112
- /* margin: 10px 10px 10px 0px;*/
113
- /* padding: 5px 10px 5px 10px;*/
114
- /* list-style: none;*/
115
- /* background-color: #fff;*/
116
- /* border-radius: 3px;*/
117
- /* -webkit-border-radius: 3px;*/
118
  }
119
 
120
  #avhecManualOrder li.lineitem {
121
- border: 1px solid #DFDFDF;
122
- background-image: none;
123
- border-radius: 3px;
124
- -webkit-border-radius: 3px;
125
- background-color: #FFFFFF;
126
- color: #555555;
127
- cursor: move;
128
- margin-top: 5px;
129
- margin-bottom: 5px;
130
- padding: 2px 5px 2px 5px;
131
- list-style: none outside none;
132
  }
133
 
134
  #avhecManualOrder .sortable-placeholder {
135
- border: 1px dashed #B2B2B2;
136
- margin-top: 5px;
137
- margin-bottom: 5px;
138
- padding: 2px 5px 2px 5px;
139
- height: 1.5em;
140
- line-height: 1.5em;
141
- list-style: none outside none;
142
- background-color: transparent;
143
- /* IE10 */
144
- background-image: -ms-linear-gradient(top, #f9f9f9, #f5f5f5);
145
- /* Firefox */
146
- background-image: -moz-linear-gradient(top, #f9f9f9, #f5f5f5);
147
- /* Opera */
148
- background-image: -o-linear-gradient(top, #f9f9f9, #f5f5f5);
149
- /* old Webkit */
150
- background-image: -webkit-gradient(linear, left top, left bottom, from(#f9f9f9), to(#f5f5f5) );
151
- /* new Webkit */
152
- background-image: -webkit-linear-gradient(top, #f9f9f9, #f5f5f5);
153
- /* proposed W3C Markup */
154
- background-image: linear-gradient(top, #f9f9f9, #f5f5f5);
155
  }
1
  .footer_avhec {
2
+ font-size : 0.8em;
3
+ text-align : center;
4
  }
5
 
6
  div.clearer {
7
+ clear : both;
8
+ line-height : 1px;
9
+ font-size : 1px;
10
+ height : 1px;
11
  }
12
 
13
  /* Metabox in General */
20
  }
21
 
22
  .avhec-metabox-wrap .p {
23
+ line-height : 140%;
24
+ margin : 1em 0;
25
  }
26
 
27
  #avhecBoxOptions option {
28
+ padding : .5em;
29
  }
30
 
31
  .avhec-metabox-wrap span.description {
33
  }
34
 
35
  .avhec-metabox-wrap .b {
36
+ font-weight : bold;
37
  }
38
 
39
  .avhec-metabox-wrap ul {
40
+ margin-bottom : 1em;
41
  }
42
 
43
  .avhec-metabox-wrap ul li {
44
+ line-height : 120%;
45
+ list-style : disc inside none;
46
+ margin-bottom : 0;
47
  }
48
 
49
  #avhec-options input {
56
 
57
  /* Metabox FAQ */
58
  #avhecBoxFAQ .inside ul {
59
+ margin-bottom : 6px;
60
  }
61
 
62
  #avhecBoxFAQ .inside ul li {
63
+ line-height : 120%;
64
+ list-style : disc inside none;
65
+ margin-bottom : 0;
66
  }
67
 
68
  /* Metabox Donations*/
71
  }
72
 
73
  #avhecBoxDonations .versions {
74
+ padding : 6px 10px 12px;
75
  }
76
 
77
  /* Metabox Donations*/
81
 
82
  /* Metabox in post and page */
83
  #post_avhec_category_group {
84
+ width : 100%;
85
  }
86
 
87
  #avhec-catlist {
88
+ -moz-border-radius : 4px 4px 4px 4px;
89
+ background-color : #FFFFFF;
90
+ border : 1px solid #DFDFDF;
91
+ height : 20em;
92
+ margin-bottom : -1.8em;
93
+ overflow : auto;
94
+ width : 95%;
95
  }
96
 
97
  #avhec-catlist ul {
98
+ padding : 3px;
99
  }
100
 
101
  #avhec-catlist li ul {
102
+ padding : 0px;
103
  }
104
 
105
  #avhec-catlist li {
106
+ margin-bottom : 0px;
107
  }
108
 
109
  #avhecManualOrder {
110
+ width : 25%;
111
+ /* border: 1px solid #B2B2B2;*/
112
+ /* margin: 10px 10px 10px 0px;*/
113
+ /* padding: 5px 10px 5px 10px;*/
114
+ /* list-style: none;*/
115
+ /* background-color: #fff;*/
116
+ /* border-radius: 3px;*/
117
+ /* -webkit-border-radius: 3px;*/
118
  }
119
 
120
  #avhecManualOrder li.lineitem {
121
+ border : 1px solid #DFDFDF;
122
+ background-image : none;
123
+ border-radius : 3px;
124
+ -webkit-border-radius : 3px;
125
+ background-color : #FFFFFF;
126
+ color : #555555;
127
+ cursor : move;
128
+ margin-top : 5px;
129
+ margin-bottom : 5px;
130
+ padding : 2px 5px 2px 5px;
131
+ list-style : none outside none;
132
  }
133
 
134
  #avhecManualOrder .sortable-placeholder {
135
+ border : 1px dashed #B2B2B2;
136
+ margin-top : 5px;
137
+ margin-bottom : 5px;
138
+ padding : 2px 5px 2px 5px;
139
+ height : 1.5em;
140
+ line-height : 1.5em;
141
+ list-style : none outside none;
142
+ background-color : transparent;
143
+ /* IE10 */
144
+ background-image : -ms-linear-gradient(top, #f9f9f9, #f5f5f5);
145
+ /* Firefox */
146
+ background-image : -moz-linear-gradient(top, #f9f9f9, #f5f5f5);
147
+ /* Opera */
148
+ background-image : -o-linear-gradient(top, #f9f9f9, #f5f5f5);
149
+ /* old Webkit */
150
+ background-image : -webkit-gradient(linear, left top, left bottom, from(#f9f9f9), to(#f5f5f5));
151
+ /* new Webkit */
152
+ background-image : -webkit-linear-gradient(top, #f9f9f9, #f5f5f5);
153
+ /* proposed W3C Markup */
154
+ background-image : linear-gradient(top, #f9f9f9, #f5f5f5);
155
  }
3.3/css/avh-ec.widget.css CHANGED
@@ -1,12 +1,12 @@
1
  /* AVH Extended Categories Widget CSS */
2
  .avhec-widget-line {
3
- display: inline-block;
4
  }
5
 
6
  .avhec-widget-count {
7
- display: inline;
8
  }
9
 
10
  .avhec-widget-rss {
11
- display: inline;
12
  }
1
  /* AVH Extended Categories Widget CSS */
2
  .avhec-widget-line {
3
+ display : inline-block;
4
  }
5
 
6
  .avhec-widget-count {
7
+ display : inline;
8
  }
9
 
10
  .avhec-widget-rss {
11
+ display : inline;
12
  }
3.3/helpers/avh-forms.php CHANGED
@@ -1,40 +1,56 @@
1
  <?php
2
- if (! function_exists('avh_doWidgetFormText')) {
3
 
4
- function avh_doWidgetFormText ($field_id, $field_name, $description, $value)
5
- {
6
  echo '<label for="' . $field_id . '">';
7
  echo $description;
8
- echo '<input class="widefat" id="' . $field_id . '" name="' . $field_name . '" type="text" value="' . esc_attr($value) . '" /> ';
 
 
 
 
 
 
9
  echo '</label>';
10
  echo '<br />';
11
  }
12
  }
13
 
14
- if (! function_exists('avh_doWidgetFormCheckbox')) {
 
 
15
 
16
- function avh_doWidgetFormCheckbox ($field_id, $field_name, $description, $is_checked = FALSE)
17
- {
18
-
19
  echo '<label for="' . $field_id . '">';
20
- echo '<input class="checkbox" type="checkbox" id="' . $field_id . '" name="' . $field_name . '"' . ($is_checked ? ' CHECKED' : '') . ' /> ';
 
 
 
 
 
 
21
  echo $description;
22
  echo '</label>';
23
  echo '<br />';
24
  }
25
  }
26
 
27
- if (! function_exists('avh_doWidgetFormSelect')) {
28
 
29
- function avh_doWidgetFormSelect ($field_id, $field_name, $description, $options, $selected_value)
30
- {
31
  echo '<label for="' . $field_id . '">';
32
  echo $description . ' ';
33
  echo '</label>';
34
-
35
  $data = '';
36
  foreach ($options as $value => $text) {
37
- $data .= '<option value="' . $value . '" ' . ($value == $selected_value ? "SELECTED" : '') . '>' . $text . '</option>' . "/n";
 
 
 
 
 
 
 
38
  }
39
  echo '<select id="' . $field_id . '" name="' . $field_name . '"> ';
40
  echo $data;
1
  <?php
2
+ if ( ! function_exists('avh_doWidgetFormText')) {
3
 
4
+ function avh_doWidgetFormText($field_id, $field_name, $description, $value) {
 
5
  echo '<label for="' . $field_id . '">';
6
  echo $description;
7
+ echo '<input class="widefat" id="' .
8
+ $field_id .
9
+ '" name="' .
10
+ $field_name .
11
+ '" type="text" value="' .
12
+ esc_attr($value) .
13
+ '" /> ';
14
  echo '</label>';
15
  echo '<br />';
16
  }
17
  }
18
 
19
+ if ( ! function_exists('avh_doWidgetFormCheckbox')) {
20
+
21
+ function avh_doWidgetFormCheckbox($field_id, $field_name, $description, $is_checked = false) {
22
 
 
 
 
23
  echo '<label for="' . $field_id . '">';
24
+ echo '<input class="checkbox" type="checkbox" id="' .
25
+ $field_id .
26
+ '" name="' .
27
+ $field_name .
28
+ '"' .
29
+ ($is_checked ? ' CHECKED' : '') .
30
+ ' /> ';
31
  echo $description;
32
  echo '</label>';
33
  echo '<br />';
34
  }
35
  }
36
 
37
+ if ( ! function_exists('avh_doWidgetFormSelect')) {
38
 
39
+ function avh_doWidgetFormSelect($field_id, $field_name, $description, $options, $selected_value) {
 
40
  echo '<label for="' . $field_id . '">';
41
  echo $description . ' ';
42
  echo '</label>';
43
+
44
  $data = '';
45
  foreach ($options as $value => $text) {
46
+ $data .= '<option value="' .
47
+ $value .
48
+ '" ' .
49
+ ($value == $selected_value ? "SELECTED" : '') .
50
+ '>' .
51
+ $text .
52
+ '</option>' .
53
+ "/n";
54
  }
55
  echo '<select id="' . $field_id . '" name="' . $field_name . '"> ';
56
  echo $data;
3.3/js/avh-ec.admin.manualorder.closure.js DELETED
@@ -1 +0,0 @@
1
- function avhecManualOrder(){jQuery("#avhecManualOrder").sortable({placeholder:"sortable-placeholder",revert:false,items:".lineitem",opacity:0.65,cursor:"move",forcePlaceholderSize:true,tolerance:"pointer"})}addLoadEvent(avhecManualOrder);function orderCats(){jQuery("#updateText").html("Updating Category Order...");jQuery("#hdnManualOrder").val(jQuery("#avhecManualOrder").sortable("toArray"))};
 
3.3/js/avh-ec.admin.manualorder.js CHANGED
@@ -1,19 +1,19 @@
1
  function avhecManualOrder() {
2
- jQuery("#avhecManualOrder").sortable({
3
- placeholder : "sortable-placeholder",
4
- revert : false,
5
- items : '.lineitem',
6
- opacity: 0.65,
7
- cursor: 'move',
8
- forcePlaceholderSize: true,
9
- tolerance : "pointer"
10
- });
11
  };
12
 
13
  addLoadEvent(avhecManualOrder);
14
 
15
  function orderCats() {
16
- jQuery("#updateText").html("Updating Category Order...");
17
- jQuery("#hdnManualOrder").val(
18
- jQuery("#avhecManualOrder").sortable("toArray"));
19
  }
1
  function avhecManualOrder() {
2
+ jQuery("#avhecManualOrder").sortable({
3
+ placeholder: "sortable-placeholder",
4
+ revert: false,
5
+ items: '.lineitem',
6
+ opacity: 0.65,
7
+ cursor: 'move',
8
+ forcePlaceholderSize: true,
9
+ tolerance: "pointer"
10
+ });
11
  };
12
 
13
  addLoadEvent(avhecManualOrder);
14
 
15
  function orderCats() {
16
+ jQuery("#updateText").html("Updating Category Order...");
17
+ jQuery("#hdnManualOrder").val(
18
+ jQuery("#avhecManualOrder").sortable("toArray"));
19
  }
3.3/js/avh-ec.admin.manualorder.min.js ADDED
@@ -0,0 +1 @@
 
1
+ function avhecManualOrder(){jQuery("#avhecManualOrder").sortable({placeholder:"sortable-placeholder",revert:false,items:".lineitem",opacity:.65,cursor:"move",forcePlaceholderSize:true,tolerance:"pointer"})}addLoadEvent(avhecManualOrder);function orderCats(){jQuery("#updateText").html("Updating Category Order...");jQuery("#hdnManualOrder").val(jQuery("#avhecManualOrder").sortable("toArray"))}
3.3/js/avh-ec.categorygroup.closure.js DELETED
@@ -1 +0,0 @@
1
- jQuery(document).ready(function(a){a("#the-list").wpList({delBefore:function(b){if("undefined"!=showNotice)return showNotice.warn()?b:false;return b}});a('.delete a[class^="delete"]').live("click",function(){return false})});
 
3.3/js/avh-ec.categorygroup.js CHANGED
@@ -1,21 +1,23 @@
1
- jQuery(document).ready(function($) {
2
- var options = false, delBefore, delAfter;
3
 
4
- delAfter = function( r, settings ) {
5
- var id = $('cat', r).attr('id'), o;
6
- for ( o = 0; o < options.length; o++ )
7
- if ( id == options[o].value )
8
- options[o] = null;
9
- };
10
 
11
- delBefore = function(s) {
12
- if ( 'undefined' != showNotice )
13
- return showNotice.warn() ? s : false;
14
 
15
- return s;
16
- };
17
 
18
- $('#the-list').wpList({ delBefore: delBefore });
19
 
20
- $('.delete a[class^="delete"]').live('click', function(){return false;});
 
 
21
  });
1
+ jQuery(document).ready(function ($) {
2
+ var options = false, delBefore, delAfter;
3
 
4
+ delAfter = function (r, settings) {
5
+ var id = $('cat', r).attr('id'), o;
6
+ for (o = 0; o < options.length; o++)
7
+ if (id == options[o].value)
8
+ options[o] = null;
9
+ };
10
 
11
+ delBefore = function (s) {
12
+ if ('undefined' != showNotice)
13
+ return showNotice.warn() ? s : false;
14
 
15
+ return s;
16
+ };
17
 
18
+ $('#the-list').wpList({delBefore: delBefore});
19
 
20
+ $('.delete a[class^="delete"]').live('click', function () {
21
+ return false;
22
+ });
23
  });
3.3/js/avh-ec.categorygroup.min.js ADDED
@@ -0,0 +1 @@
 
1
+ jQuery(document).ready(function($){var options=false,delBefore,delAfter;delAfter=function(r,settings){var id=$("cat",r).attr("id"),o;for(o=0;o<options.length;o++)if(id==options[o].value)options[o]=null};delBefore=function(s){if("undefined"!=showNotice)return showNotice.warn()?s:false;return s};$("#the-list").wpList({delBefore:delBefore});$('.delete a[class^="delete"]').live("click",function(){return false})});
3.6/avh-ec.client.php CHANGED
@@ -2,78 +2,69 @@
2
 
3
  /**
4
  * Singleton Class
5
- *
6
  */
7
- class AVH_EC_Singleton
8
- {
9
-
10
- /**
11
- *
12
- * @param string $class
13
- * @param string $arg1
14
- */
15
- public static function &getInstance($class, $arg1 = null)
16
- {
17
- static $instances = array(); // array of instance names
18
- if (array_key_exists($class, $instances)) {
19
- $instance = & $instances[$class];
20
- } else {
21
- if (!class_exists($class)) {
22
- switch ($class) {
23
- case 'AVH_EC_Core':
24
- require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.core.php');
25
- break;
26
- case 'AVH_EC_Category_Group':
27
- require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.category-group.php');
28
- break;
29
- case 'AVH_EC_Widget_Helper_Class':
30
- require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widget-helper.php');
31
- break;
32
- }
33
- }
34
- $instances[$class] = new $class($arg1);
35
- $instance = & $instances[$class];
36
- }
37
 
38
- return $instance;
39
- }
40
  }
41
 
42
  /**
43
  * Include the necessary files
44
  */
45
- require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/helpers/avh-forms.php');
46
- require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/helpers/avh-common.php');
47
- require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widgets.php');
48
 
49
  /**
50
  * Initialize the plugin
51
  */
52
- function avhextendedcategories_init()
53
- {
54
- // Admin
55
- if (is_admin()) {
56
- require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.admin.php');
57
- $avhec_admin = new AVH_EC_Admin();
58
- }
59
- AVH_EC_Singleton::getInstance('AVH_EC_Core');
60
 
61
- add_action('widgets_init', 'avhextendedcategories_widgets_init');
62
  } // End avhamazon_init()
63
 
64
  /**
65
  * Register the widget
66
  *
67
  * @WordPress Action widgets_init
68
- *
69
- * @since 3.0
70
- *
71
  */
72
- function avhextendedcategories_widgets_init()
73
- {
74
- register_widget('WP_Widget_AVH_ExtendedCategories_Normal');
75
- register_widget('WP_Widget_AVH_ExtendedCategories_Top');
76
- register_widget('WP_Widget_AVH_ExtendedCategories_Category_Group');
77
  }
78
 
79
  add_action('plugins_loaded', 'avhextendedcategories_init');
2
 
3
  /**
4
  * Singleton Class
 
5
  */
6
+ class AVH_EC_Singleton {
7
+ /**
8
+ * @param string $class
9
+ * @param string $arg1
10
+ */
11
+ public static function &getInstance($class, $arg1 = null) {
12
+ static $instances = array(); // array of instance names
13
+ if (array_key_exists($class, $instances)) {
14
+ $instance = &$instances[ $class ];
15
+ } else {
16
+ if ( ! class_exists($class)) {
17
+ switch ($class) {
18
+ case 'AVH_EC_Core':
19
+ require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.core.php');
20
+ break;
21
+ case 'AVH_EC_Category_Group':
22
+ require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.category-group.php');
23
+ break;
24
+ case 'AVH_EC_Widget_Helper_Class':
25
+ require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widget-helper.php');
26
+ break;
27
+ }
28
+ }
29
+ $instances[ $class ] = new $class($arg1);
30
+ $instance = &$instances[ $class ];
31
+ }
 
 
 
 
32
 
33
+ return $instance;
34
+ }
35
  }
36
 
37
  /**
38
  * Include the necessary files
39
  */
40
+ require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/helpers/avh-forms.php');
41
+ require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/helpers/avh-common.php');
42
+ require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widgets.php');
43
 
44
  /**
45
  * Initialize the plugin
46
  */
47
+ function avhextendedcategories_init() {
48
+ // Admin
49
+ if (is_admin()) {
50
+ require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.admin.php');
51
+ $avhec_admin = new AVH_EC_Admin();
52
+ }
53
+ AVH_EC_Singleton::getInstance('AVH_EC_Core');
 
54
 
55
+ add_action('widgets_init', 'avhextendedcategories_widgets_init');
56
  } // End avhamazon_init()
57
 
58
  /**
59
  * Register the widget
60
  *
61
  * @WordPress Action widgets_init
62
+ * @since 3.0
 
 
63
  */
64
+ function avhextendedcategories_widgets_init() {
65
+ register_widget('WP_Widget_AVH_ExtendedCategories_Normal');
66
+ register_widget('WP_Widget_AVH_ExtendedCategories_Top');
67
+ register_widget('WP_Widget_AVH_ExtendedCategories_Category_Group');
 
68
  }
69
 
70
  add_action('plugins_loaded', 'avhextendedcategories_init');
3.6/class/avh-ec.admin.php CHANGED
@@ -1,1464 +1,1840 @@
1
  <?php
2
 
3
- class AVH_EC_Admin
4
- {
5
-
6
- /**
7
- *
8
- * @var AVH_EC_Core
9
- */
10
- public $core;
11
-
12
- /**
13
- *
14
- * @var AVH_EC_Category_Group
15
- */
16
- public $catgrp;
17
-
18
- public $hooks = array();
19
-
20
- public $message;
21
-
22
- /**
23
- * PHP5 constructor
24
- */
25
- public function __construct()
26
- {
27
-
28
- // Initialize the plugin
29
- $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core');
30
- $this->catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
31
-
32
- add_action('wp_ajax_delete-group', array($this, 'ajaxDeleteGroup'));
33
-
34
- // Admin menu
35
- add_action('admin_init', array($this, 'actionAdminInit'));
36
- add_action('admin_menu', array($this, 'actionAdminMenu'));
37
- add_filter('plugin_action_links_extended-categories-widget/widget_extended_categories.php', array($this, 'filterPluginActions'), 10, 2);
38
-
39
- // Actions used for editing posts
40
- add_action('load-post.php', array($this, 'actionLoadPostPage'));
41
- add_action('load-page.php', array($this, 'actionLoadPostPage'));
42
-
43
- // Actions related to adding and deletes categories
44
- add_action("created_category", array($this, 'actionCreatedCategory'), 10, 2);
45
- add_action("delete_category", array($this, 'actionDeleteCategory'), 10, 2);
46
-
47
- add_filter('manage_categories_group_columns', array($this, 'filterManageCategoriesGroupColumns'));
48
- add_filter('explain_nonce_delete-avhecgroup', array($this, 'filterExplainNonceDeleteGroup'), 10, 2);
49
-
50
- return;
51
- }
52
-
53
- public function actionAdminInit()
54
- {
55
- if (is_admin() && isset($_GET['taxonomy']) && 'category' == $_GET['taxonomy']) {
56
- add_action($_GET['taxonomy'] . '_edit_form', array($this, 'displayCategoryGroupForm'), 10, 2);
57
- }
58
- add_action('edit_term', array($this, 'handleEditTerm'), 10, 3);
59
- }
60
-
61
- /**
62
- * Adds Category Group form
63
- * @WordPress action category_edit_form
64
- *
65
- * @param unknown_type $term
66
- * @param unknown_type $taxonomy
67
- */
68
- public function displayCategoryGroupForm($term, $taxonomy)
69
- {
70
- $current_selection = '';
71
- $tax_meta = get_option($this->core->db_options_tax_meta);
72
- if (isset($tax_meta[$taxonomy][$term->term_id])) {
73
- $tax_meta = $tax_meta[$taxonomy][$term->term_id];
74
- $current_selection = $tax_meta['category_group_term_id'];
75
- }
76
-
77
- if (empty($current_selection)) {
78
- $current_group = $this->catgrp->getGroupByCategoryID($term->term_id);
79
- $current_selection = $current_group->term_id;
80
- }
81
-
82
- $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false));
83
- foreach ($cat_groups as $group) {
84
- $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit');
85
- $dropdown_value[] = $group->term_id;
86
- $dropdown_text[] = $temp_cat->name;
87
- }
88
-
89
- $seldata = '';
90
- foreach ($dropdown_value as $key => $sel) {
91
- $seldata .= '<option value="' . esc_attr($sel) . '" ' . (($current_selection == $sel) ? 'selected="selected"' : '') . ' >' . esc_html(ucfirst($dropdown_text[$key])) . '</option>' . "\n";
92
- }
93
-
94
- echo '<h3>AVH Extended Categories - Category Group Widget</h3>';
95
- echo '<table class="form-table"><tbody>';
96
- echo '<tr class="form-field">';
97
- echo '<th valign="top" scope="row">';
98
- echo '<label for="avhec_categorygroup">Category Group</label></th>';
99
- echo '<td>';
100
- echo '<select id="avhec_categorygroup" name="avhec_categorygroup">';
101
- echo $seldata;
102
- echo '</select>';
103
- echo '<p class="description">Select the category group to show on the archive page.</p>';
104
- echo '</td>';
105
- echo '</tr>';
106
- echo '</tbody></table>';
107
- }
108
-
109
- /**
110
- * Saves the association Category - Category Group fron the edit taxonomy page
111
- * @WordPress action edit_form.
112
- *
113
- * @param unknown_type $term_id
114
- * @param unknown_type $tt_id
115
- * @param unknown_type $taxonomy
116
- */
117
- public function handleEditTerm($term_id, $tt_id, $taxonomy)
118
- {
119
- $tax_meta = get_option($this->core->db_options_tax_meta);
120
- if (isset($_POST['avhec_categorygroup'])) {
121
- if (!isset($tax_meta[$taxonomy][$term_id]['category_group_term_id']) || $tax_meta[$taxonomy][$term_id]['category_group_term_id'] != $_POST['avhec_categorygroup']) {
122
- $tax_meta[$taxonomy][$term_id]['category_group_term_id'] = $_POST['avhec_categorygroup'];
123
- update_option($this->core->db_options_tax_meta, $tax_meta);
124
- }
125
- }
126
- }
127
-
128
- /**
129
- * When a category is created this function is called to add the new category to the group all
130
- *
131
- * @param
132
- * $term_id
133
- * @param
134
- * $term_taxonomy_id
135
- */
136
- public function actionCreatedCategory($term_id, $term_taxonomy_id)
137
- {
138
- $group_id = $this->catgrp->getTermIDBy('slug', 'all');
139
- $this->catgrp->setCategoriesForGroup($group_id, (array) $term_id);
140
- }
141
-
142
- /**
143
- * When a category is deleted this function is called so the category is deleted from every group as well.
144
- *
145
- * @param object $term
146
- * @param int $term_taxonomy_id
147
- */
148
- public function actionDeleteCategory($term_id, $term_taxonomy_id)
149
- {
150
- $this->catgrp->doDeleteCategoryFromGroup($term_id);
151
- }
152
-
153
- /**
154
- * Enqueues the style on the post.php and page.php pages
155
- * @WordPress Action load-$pagenow
156
- */
157
- public function actionLoadPostPage()
158
- {
159
- wp_enqueue_style('avhec-admin-css');
160
- }
161
-
162
- /**
163
- * Add the Tools and Options to the Management and Options page repectively
164
- *
165
- * @WordPress Action admin_menu
166
- */
167
- public function actionAdminMenu()
168
- {
169
-
170
- // Register Style and Scripts
171
- $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.closure';
172
- wp_register_script('avhec-categorygroup-js', AVHEC_PLUGIN_URL . '/js/avh-ec.categorygroup' . $suffix . '.js', array('jquery'), $this->core->version, true);
173
- wp_register_script('avhec-manualorder', AVHEC_PLUGIN_URL . '/js/avh-ec.admin.manualorder' . $suffix . '.js', array('jquery-ui-sortable'), $this->core->version, false);
174
- wp_register_style('avhec-admin-css', AVHEC_PLUGIN_URL . '/css/avh-ec.admin.css', array('wp-admin'), $this->core->version, 'screen');
175
-
176
- // Add menu system
177
- $folder = $this->core->getBaseDirectory(AVHEC_PLUGIN_DIR);
178
- add_menu_page('AVH Extended Categories', 'AVH Extended Categories', 'manage_options', $folder, array($this, 'doMenuOverview'));
179
- $this->hooks['menu_overview'] = add_submenu_page($folder, 'AVH Extended Categories: ' . __('Overview', 'avh-ec'), __('Overview', 'avh-ec'), 'manage_options', $folder, array($this, 'doMenuOverview'));
180
- $this->hooks['menu_general'] = add_submenu_page($folder, 'AVH Extended Categories: ' . __('General Options', 'avh-ec'), __('General Options', 'avh-ec'), 'manage_options', 'avhec-general', array($this, 'doMenuGeneral'));
181
- $this->hooks['menu_category_groups'] = add_submenu_page($folder, 'AVH Extended Categories: ' . __('Category Groups', 'avh-ec'), __('Category Groups', 'avh-ec'), 'manage_options', 'avhec-grouped', array($this, 'doMenuCategoryGroup'));
182
- $this->hooks['menu_manual_order'] = add_submenu_page($folder, 'AVH Extended Categories: ' . __('Manually Order', 'avh-ec'), __('Manually Order', 'avh-ec'), 'manage_options', 'avhec-manual-order', array($this, 'doMenuManualOrder'));
183
- $this->hooks['menu_faq'] = add_submenu_page($folder, 'AVH Extended Categories:' . __('F.A.Q', 'avh-ec'), __('F.A.Q', 'avh-ec'), 'manage_options', 'avhec-faq', array($this, 'doMenuFAQ'));
184
-
185
- // Add actions for menu pages
186
- // Overview Menu
187
- add_action('load-' . $this->hooks['menu_overview'], array($this, 'actionLoadPageHook_Overview'));
188
-
189
- // General Options Menu
190
- add_action('load-' . $this->hooks['menu_general'], array($this, 'actionLoadPageHook_General'));
191
-
192
- // Category Groups Menu
193
- add_action('load-' . $this->hooks['menu_category_groups'], array($this, 'actionLoadPageHook_CategoryGroup'));
194
-
195
- // Manual Order Menu
196
- add_action('load-' . $this->hooks['menu_manual_order'], array($this, 'actionLoadPageHook_ManualOrder'));
197
-
198
- // FAQ Menu
199
- add_action('load-' . $this->hooks['menu_faq'], array($this, 'actionLoadPageHook_faq'));
200
- }
201
-
202
- /**
203
- * Setup everything needed for the Overview page
204
- */
205
- public function actionLoadPageHook_Overview()
206
- {
207
- // Add metaboxes
208
- add_meta_box('avhecBoxCategoryGroupList', __('Group Overview', 'avh-ec'), array($this, 'metaboxCategoryGroupList'), $this->hooks['menu_overview'], 'normal', 'core');
209
- add_meta_box('avhecBoxTranslation', __('Translation', 'avh-ec'), array($this, 'metaboxTranslation'), $this->hooks['menu_overview'], 'normal', 'core');
210
-
211
- add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
212
-
213
- // WordPress core Scripts
214
- wp_enqueue_script('common');
215
- wp_enqueue_script('wp-lists');
216
- wp_enqueue_script('postbox');
217
-
218
- // Plugin Scripts
219
- wp_enqueue_script('avhec-categorygroup-js');
220
-
221
- // Plugin Style
222
- wp_enqueue_style('avhec-admin-css');
223
- }
224
-
225
- /**
226
- * Menu Page Overview
227
- *
228
- * @return none
229
- */
230
- public function doMenuOverview()
231
- {
232
- global $screen_layout_columns;
233
-
234
- // This box can't be unselectd in the the Screen Options
235
- // add_meta_box('avhecBoxAnnouncements', __('Announcements', 'avh-ec'), array ( $this, 'metaboxAnnouncements' ), $this->hooks['menu_overview'], 'side', '');
236
- add_meta_box('avhecBoxDonations', __('Donations', 'avh-ec'), array($this, 'metaboxDonations'), $this->hooks['menu_overview'], 'side', '');
237
-
238
- $hide2 = '';
239
- switch ($screen_layout_columns) {
240
- case 2:
241
- $width = 'width:49%;';
242
- break;
243
- default:
244
- $width = 'width:98%;';
245
- $hide2 = 'display:none;';
246
- }
247
-
248
- echo '<div class="wrap avhec-metabox-wrap">';
249
- echo $this->displayIcon('index');
250
- echo '<h2>' . 'AVH Extended Categories - ' . __('Overview', 'avh-ec') . '</h2>';
251
- echo ' <div id="dashboard-widgets-wrap">';
252
- echo ' <div id="dashboard-widgets" class="metabox-holder">';
253
- echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
254
- do_meta_boxes($this->hooks['menu_overview'], 'normal', '');
255
- echo " </div>";
256
- echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n";
257
- do_meta_boxes($this->hooks['menu_overview'], 'side', '');
258
- echo ' </div>';
259
- echo ' </div>';
260
-
261
- echo '<br class="clear"/>';
262
- echo ' </div>'; // dashboard-widgets-wrap
263
- echo '</div>'; // wrap
264
-
265
- $this->printMetaboxGeneralNonces();
266
- $this->printMetaboxJS('overview');
267
- $this->printAdminFooter();
268
- }
269
-
270
- /**
271
- * Setup everything needed for the General Options page
272
- */
273
- public function actionLoadPageHook_General()
274
- {
275
- // Add metaboxes
276
- add_meta_box('avhecBoxOptions', __('Options', 'avh-ec'), array($this, 'metaboxOptions'), $this->hooks['menu_general'], 'normal', 'core');
277
-
278
- add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
279
-
280
- // WordPress core Scripts
281
- wp_enqueue_script('common');
282
- wp_enqueue_script('wp-lists');
283
- wp_enqueue_script('postbox');
284
-
285
- // Plugin Style and Scripts
286
- wp_enqueue_style('avhec-admin-css');
287
- }
288
-
289
- /**
290
- * Menu Page General Options
291
- *
292
- * @return none
293
- */
294
- public function doMenuGeneral()
295
- {
296
- global $screen_layout_columns;
297
-
298
- $groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false));
299
- foreach ($groups as $group) {
300
- $group_id[] = $group->term_id;
301
- $groupname[] = $group->name;
302
- }
303
-
304
- $options_general[] = array('avhec[general][alternative_name_select_category]', __('<em>Select Category</em> Alternative', 'avh-ec'), 'text', 20, __('Alternative text for Select Category.', 'avh-ec'));
305
- $options_general[] = array('avhec[cat_group][home_group]', 'Home Group', 'dropdown', $group_id, $groupname, __('Select which group to show on the home page.', 'avh-ec') . '<br />' . __('Selecting the group \'none\' will not show the widget on the page.', 'avh-ec'));
306
- $options_general[] = array('avhec[cat_group][no_group]', 'Nonexistence Group', 'dropdown', $group_id, $groupname, __('Select which group to show when there is no group associated with the post.', 'avh-ec') . '<br />' . __('Selecting the group \'none\' will not show the widget on the page.', 'avh-ec'));
307
- $options_general[] = array('avhec[cat_group][default_group]', 'Default Group', 'dropdown', $group_id, $groupname, __('Select which group will be the default group when editing a post.', 'avh-ec') . '<br />' . __('Selecting the group \'none\' will not show the widget on the page.', 'avh-ec'));
308
-
309
- if (isset($_POST['updateoptions'])) {
310
- check_admin_referer('avh_ec_generaloptions');
311
-
312
- $formoptions = $_POST['avhec'];
313
- $options = $this->core->getOptions();
314
-
315
- // $all_data = array_merge( $options_general );
316
- $all_data = $options_general;
317
- foreach ($all_data as $option) {
318
- $section = substr($option[0], strpos($option[0], '[') + 1);
319
- $section = substr($section, 0, strpos($section, ']['));
320
- $option_key = rtrim($option[0], ']');
321
- $option_key = substr($option_key, strpos($option_key, '][') + 2);
322
-
323
- switch ($section) {
324
- case 'general':
325
- case 'cat_group':
326
- $current_value = $options[$section][$option_key];
327
- break;
328
- }
329
- // Every field in a form is set except unchecked checkboxes. Set an unchecked checkbox to 0.
330
- $newval = (isset($formoptions[$section][$option_key]) ? esc_attr($formoptions[$section][$option_key]) : 0);
331
- if ($newval != $current_value) { // Only process changed fields.
332
- switch ($section) {
333
- case 'general':
334
- case 'cat_group':
335
- $options[$section][$option_key] = $newval;
336
- break;
337
- }
338
- }
339
- }
340
- $this->core->saveOptions($options);
341
- $this->message = __('Options saved', 'avh-ec');
342
- $this->status = 'updated fade';
343
- }
344
- $this->displayMessage();
345
-
346
- $actual_options = $this->core->getOptions();
347
- foreach ($actual_options['cat_group'] as $key => $value) {
348
- if (!(in_array($value, (array) $group_id))) {
349
- $actual_options['cat_group'][$key] = $this->catgrp->getTermIDBy('slug', 'none');
350
- }
351
- }
352
-
353
- $hide2 = '';
354
- switch ($screen_layout_columns) {
355
- case 2:
356
- $width = 'width:49%;';
357
- break;
358
- default:
359
- $width = 'width:98%;';
360
- $hide2 = 'display:none;';
361
- }
362
- $data['options_general'] = $options_general;
363
- $data['actual_options'] = $actual_options;
364
-
365
- // This box can't be unselectd in the the Screen Options
366
- add_meta_box('avhecBoxDonations', __('Donations', 'avh-ec'), array($this, 'metaboxDonations'), $this->hooks['menu_general'], 'side', 'core');
367
-
368
- $hide2 = '';
369
- switch ($screen_layout_columns) {
370
- case 2:
371
- $width = 'width:49%;';
372
- break;
373
- default:
374
- $width = 'width:98%;';
375
- $hide2 = 'display:none;';
376
- }
377
-
378
- echo '<div class="wrap avhec-metabox-wrap">';
379
- echo $this->displayIcon('index');
380
- echo '<h2>' . 'AVH Extended Categories - ' . __('General Options', 'avh-ec') . '</h2>';
381
- echo '<form name="avhec-generaloptions" id="avhec-generaloptions" method="POST" action="' . admin_url('admin.php?page=avhec-general') . '" accept-charset="utf-8" >';
382
- wp_nonce_field('avh_ec_generaloptions');
383
-
384
- echo ' <div id="dashboard-widgets-wrap">';
385
- echo ' <div id="dashboard-widgets" class="metabox-holder">';
386
- echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
387
- do_meta_boxes($this->hooks['menu_general'], 'normal', $data);
388
- echo " </div>";
389
- echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n";
390
- do_meta_boxes($this->hooks['menu_general'], 'side', $data);
391
- echo ' </div>';
392
- echo ' </div>';
393
-
394
- echo '<br class="clear"/>';
395
- echo ' </div>'; // dashboard-widgets-wrap
396
- echo '<p class="submit"><input class="button" type="submit" name="updateoptions" value="' . __('Save Changes', 'avhf-ec') . '" /></p>';
397
- echo '</form>';
398
-
399
- echo '</div>'; // wrap
400
-
401
- $this->printMetaboxGeneralNonces();
402
- $this->printMetaboxJS('general');
403
- $this->printAdminFooter();
404
- }
405
-
406
- /**
407
- * Options Metabox
408
- */
409
- public function metaboxOptions($data)
410
- {
411
- echo $this->printOptions($data['options_general'], $data['actual_options']);
412
- }
413
-
414
- /**
415
- * Setup everything needed for the Category Group page
416
- */
417
- public function actionLoadPageHook_CategoryGroup()
418
- {
419
-
420
- // Add metaboxes
421
- add_meta_box('avhecBoxCategoryGroupAdd', __('Add Group', 'avh-ec'), array($this, 'metaboxCategoryGroupAdd'), $this->hooks['menu_category_groups'], 'normal', 'core');
422
- add_meta_box('avhecBoxCategoryGroupList', __('Group Overview', 'avh-ec'), array($this, 'metaboxCategoryGroupList'), $this->hooks['menu_category_groups'], 'side', 'core');
423
- add_meta_box('avhecBoxCategoryGroupSpecialPages', __('Special Pages', 'avh-ec'), array($this, 'metaboxCategoryGroupSpecialPages'), $this->hooks['menu_category_groups'], 'normal', 'core');
424
-
425
- add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
426
-
427
- // WordPress core Scripts
428
- wp_enqueue_script('common');
429
- wp_enqueue_script('wp-lists');
430
- wp_enqueue_script('postbox');
431
-
432
- // Plugin Scripts
433
- wp_enqueue_script('avhec-categorygroup-js');
434
-
435
- // Plugin Style
436
- wp_enqueue_style('avhec-admin-css');
437
- }
438
-
439
- /**
440
- * Menu Page Category Group
441
- *
442
- * @return none
443
- */
444
- public function doMenuCategoryGroup()
445
- {
446
- global $screen_layout_columns;
447
-
448
- $data_add_group_default = array('name' => '', 'slug' => '', 'widget_title' => '', 'description' => '');
449
- $data_add_group_new = $data_add_group_default;
450
-
451
- $options_add_group[] = array('avhec_add_group[add][name]', __('Group Name', 'avh-ec'), 'text', 20, __('The name is used to identify the group.', 'avh-ec'));
452
- $options_add_group[] = array('avhec_add_group[add][slug]', __('Slug Group', 'avh-ec'), 'text', 20, __('The “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.', 'avh-ec'));
453
- $options_add_group[] = array('avhec_add_group[add][widget_title]', __('Widget Title', 'avh-ec'), 'text', 20, __('When no title is given in the widget options, this will used as the title of the widget when this group is shown.', 'avh-ec'));
454
- $options_add_group[] = array('avhec_add_group[add][description]', __('Description', 'avh-ec'), 'textarea', 40, __('Description is not prominent by default.', 'avh-ec'), 5);
455
-
456
- $options_edit_group[] = array('avhec_edit_group[edit][name]', __('Group Name', 'avh-ec'), 'text', 20, __('The name is used to identify the group.', 'avh-ec'));
457
- $options_edit_group[] = array('avhec_edit_group[edit][slug]', __('Slug Group', 'avh-ec'), 'text', 20, __('The “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.', 'avh-ec'));
458
- $options_edit_group[] = array('avhec_edit_group[edit][widget_title]', __('Widget Title', 'avh-ec'), 'text', 20, __('When no title is given in the widget options, this will used as the title of the widget when this group is shown.', 'avh-ec'));
459
- $options_edit_group[] = array('avhec_edit_group[edit][description]', __('Description', 'avh-ec'), 'textarea', 40, __('Description is not prominent by default.', 'avh-ec'), 5);
460
- $options_edit_group[] = array('avhec_edit_group[edit][categories]', __('Categories', 'avh-ec'), 'catlist', 0, __('Select categories to be included in the group.', 'avh-ec'));
461
-
462
- if (isset($_POST['addgroup'])) {
463
- check_admin_referer('avh_ec_addgroup');
464
-
465
- $formoptions = $_POST['avhec_add_group'];
466
-
467
- $data_add_group_new['name'] = $formoptions['add']['name'];
468
- $data_add_group_new['slug'] = empty($formoptions['add']['slug']) ? sanitize_title($data_add_group_new['name']) : sanitize_title($formoptions['add']['slug']);
469
- $data_add_group_new['widget_title'] = $formoptions['add']['widget_title'];
470
- $data_add_group_new['description'] = $formoptions['add']['description'];
471
-
472
- $id = $this->catgrp->getTermIDBy('slug', $data_add_group_new['slug']);
473
- if (!$id) {
474
- $group_id = $this->catgrp->doInsertGroup($data_add_group_new['name'], array('description' => $data_add_group_new['description'], 'slug' => $data_add_group_new['slug']), $data_add_group_new['widget_title']);
475
- $this->catgrp->setCategoriesForGroup($group_id);
476
- $this->message = __('Category group saved', 'avh-ec');
477
- $this->status = 'updated fade';
478
- $data_add_group_new = $data_add_group_default;
479
- } else {
480
- $group = $this->catgrp->getGroup($id);
481
- $this->message = __('Category group conflicts with ', 'avh-ec') . $group->name;
482
- $this->message .= '<br />' . __('Same slug is used. ', 'avh-ec');
483
- $this->status = 'error';
484
- }
485
- $this->displayMessage();
486
- }
487
- $data_add_group['add'] = $data_add_group_new;
488
- $data['add'] = array('form' => $options_add_group, 'data' => $data_add_group);
489
-
490
- if (isset($_GET['action'])) {
491
- $action = $_GET['action'];
492
-
493
- switch ($action) {
494
- case 'edit':
495
- $group_id = (int) $_GET['group_ID'];
496
- $group = $this->catgrp->getGroup($group_id);
497
- $widget_title = $this->catgrp->getWidgetTitleForGroup($group_id);
498
- $cats = $this->catgrp->getCategoriesFromGroup($group_id);
499
-
500
- $data_edit_group['edit'] = array('group_id' => $group_id, 'name' => $group->name, 'slug' => $group->slug, 'widget_title' => $widget_title, 'description' => $group->description, 'categories' => $cats);
501
- $data['edit'] = array('form' => $options_edit_group, 'data' => $data_edit_group);
502
-
503
- add_meta_box('avhecBoxCategoryGroupEdit', __('Edit Group', 'avh-ec') . ': ' . $group->name, array($this, 'metaboxCategoryGroupEdit'), $this->hooks['menu_category_groups'], 'normal', 'low');
504
- break;
505
- case 'delete':
506
- if (!isset($_GET['group_ID'])) {
507
- wp_redirect($this->getBackLink());
508
- exit();
509
- }
510
-
511
- $group_id = (int) $_GET['group_ID'];
512
- check_admin_referer('delete-avhecgroup_' . $group_id);
513
-
514
- if (!current_user_can('manage_categories')) {
515
- wp_die(__('Cheatin&#8217; uh?'));
516
- }
517
- $this->catgrp->doDeleteGroup($group_id);
518
- break;
519
- default:
520
- ;
521
- break;
522
- }
523
- }
524
-
525
- if (isset($_POST['editgroup'])) {
526
- check_admin_referer('avh_ec_editgroup');
527
-
528
- $formoptions = $_POST['avhec_edit_group'];
529
- $selected_categories = $_POST['post_category'];
530
-
531
- $group_id = (int) $_POST['avhec-group_id'];
532
- $result = $this->catgrp->doUpdateGroup($group_id, array('name' => $formoptions['edit']['name'], 'slug' => $formoptions['edit']['slug'], 'description' => $formoptions['edit']['description']), $selected_categories, $formoptions['edit']['widget_title']);
533
- switch ($result) {
534
- case 1:
535
- $this->message = __('Category group updated', 'avh-ec');
536
- $this->status = 'updated fade';
537
- break;
538
- case 0:
539
- $this->message = __('Category group not updated', 'avh-ec');
540
- $this->message .= '<br />' . __('Duplicate slug detected', 'avh-ec');
541
- $this->status = 'error';
542
- break;
543
- case -1:
544
- $this->message = __('Unknown category group', 'avh-ec');
545
- $this->status = 'error';
546
- break;
547
- }
548
- $this->displayMessage();
549
- }
550
-
551
- $hide2 = '';
552
- switch ($screen_layout_columns) {
553
- case 2:
554
- $width = 'width:49%;';
555
- break;
556
- default:
557
- $width = 'width:98%;';
558
- $hide2 = 'display:none;';
559
- }
560
-
561
- $data_special_pages_old = $this->core->options['sp_cat_group'];
562
- $data_special_pages_new = $data_special_pages_old;
563
- if (isset($_POST['avhec_special_pages'])) {
564
- check_admin_referer('avh_ec_specialpagesgroup');
565
-
566
- $formoptions = $_POST['avhec_special_pages'];
567
- $formdata = $formoptions['sp'];
568
- foreach ($formdata as $key => $value) {
569
- $data_special_pages_new[$key] = $value;
570
- }
571
- $this->core->options['sp_cat_group'] = $data_special_pages_new;
572
- $this->core->saveOptions($this->core->options);
573
- }
574
- $data_special_pages['sp'] = $data_special_pages_new;
575
- $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false));
576
-
577
- foreach ($cat_groups as $group) {
578
- $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit');
579
- $dropdown_value[] = $group->term_id;
580
- $dropdown_text[] = $temp_cat->name;
581
- }
582
- $options_special_pages[] = array('avhec_special_pages[sp][home_group]', __('Home page', 'avh-ec'), 'dropdown', $dropdown_value, $dropdown_text, sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('home', 'avhec')));
583
- // $options_special_pages[] = array('avhec_special_pages[sp][category_group]', __('Category Archive', 'avh-ec'), 'dropdown', $dropdown_value, $dropdown_text, sprintf(__('Select which category to show on the %s page.','avh-ec'),__('category archive','avhec')));
584
- $options_special_pages[] = array('avhec_special_pages[sp][day_group]', __('Daily Archive', 'avh-ec'), 'dropdown', $dropdown_value, $dropdown_text, sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('daily archive', 'avhec')));
585
- $options_special_pages[] = array('avhec_special_pages[sp][month_group]', __('Monthly Archive', 'avh-ec'), 'dropdown', $dropdown_value, $dropdown_text, sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('monthly archive', 'avhec')));
586
- $options_special_pages[] = array('avhec_special_pages[sp][year_group]', __('Yearly Archive', 'avh-ec'), 'dropdown', $dropdown_value, $dropdown_text, sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('yearly archive', 'avhec')));
587
- $options_special_pages[] = array('avhec_special_pages[sp][author_group]', __('Author Archive', 'avh-ec'), 'dropdown', $dropdown_value, $dropdown_text, sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('author archive', 'avhec')));
588
- $options_special_pages[] = array('avhec_special_pages[sp][search_group]', __('Search Page', 'avh-ec'), 'dropdown', $dropdown_value, $dropdown_text, sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('search', 'avhec')));
589
-
590
- $data['sp'] = array('form' => $options_special_pages, 'data' => $data_special_pages);
591
-
592
- // This box can't be unselectd in the the Screen Options
593
- // add_meta_box( 'avhecBoxDonations', __( 'Donations', 'avh-ec' ), array ($this, 'metaboxDonations' ), $this->hooks['menu_category_groups'], 'side', 'core' );
594
-
595
- echo '<div class="wrap avhec-metabox-wrap">';
596
- echo $this->displayIcon('index');
597
- echo '<h2>' . 'AVH Extended Categories - ' . __('Category Groups', 'avh-ec') . '</h2>';
598
-
599
- echo ' <div id="dashboard-widgets-wrap">';
600
- echo ' <div id="dashboard-widgets" class="metabox-holder">';
601
-
602
- echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
603
- do_meta_boxes($this->hooks['menu_category_groups'], 'normal', $data);
604
- echo " </div>";
605
-
606
- echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n";
607
- do_meta_boxes($this->hooks['menu_category_groups'], 'side', $data);
608
- echo ' </div>';
609
-
610
- echo ' </div>'; // dashboard-widgets
611
- echo '<br class="clear" />';
612
- echo ' </div>'; // dashboard-widgets-wrap
613
- echo '</div>'; // wrap
614
-
615
- $this->printMetaboxGeneralNonces();
616
- $this->printMetaboxJS('grouped');
617
- $this->printAdminFooter();
618
- }
619
-
620
- /**
621
- * Metabox for Adding a group
622
- *
623
- * @param
624
- * $data
625
- */
626
- public function metaboxCategoryGroupAdd($data)
627
- {
628
- echo '<form name="avhec-addgroup" id="avhec-addgroup" method="POST" action="' . $this->getBackLink() . '" accept-charset="utf-8" >';
629
- wp_nonce_field('avh_ec_addgroup');
630
- echo $this->printOptions($data['add']['form'], $data['add']['data']);
631
- echo '<p class="submit"><input class="button" type="submit" name="addgroup" value="' . __('Add group', 'avh-ec') . '" /></p>';
632
- echo '</form>';
633
- }
634
-
635
- /**
636
- * Metabox for showing the groups as a list
637
- *
638
- * @param
639
- * $data
640
- */
641
- public function metaboxCategoryGroupList($data)
642
- {
643
- echo '<form id="posts-filter" action="" method="get">';
644
-
645
- echo '<div class="clear"></div>';
646
-
647
- echo '<table class="widefat fixed" cellspacing="0">';
648
- echo '<thead>';
649
- echo '<tr>';
650
- print_column_headers('categories_group');
651
- echo '</tr>';
652
- echo '</thead>';
653
-
654
- echo '<tfoot>';
655
- echo '<tr>';
656
- print_column_headers('categories_group', false);
657
- echo '</tr>';
658
- echo '</tfoot>';
659
-
660
- echo '<tbody id="the-list" class="list:group">';
661
- $this->printCategoryGroupRows();
662
- echo '</tbody>';
663
- echo '</table>';
664
-
665
- echo '<br class="clear" />';
666
- echo '</form>';
667
-
668
- // echo '</div>';
669
- }
670
-
671
- /**
672
- * Metabox Category Group Edit
673
- */
674
- public function metaboxCategoryGroupEdit($data)
675
- {
676
- echo '<form name="avhec-editgroup" id="avhec-editgroup" method="POST" action="' . $this->getBackLink() . '" accept-charset="utf-8" >';
677
- wp_nonce_field('avh_ec_editgroup');
678
- echo $this->printOptions($data['edit']['form'], $data['edit']['data']);
679
- echo '<input type="hidden" value="' . $data['edit']['data']['edit']['group_id'] . '" name="avhec-group_id" id="avhec-group_id">';
680
- echo '<p class="submit"><input class="button" type="submit" name="editgroup" value="' . __('Update group', 'avh-ec') . '" /></p>';
681
- echo '</form>';
682
- }
683
-
684
- /**
685
- * Metabox Category Group Special pages
686
- */
687
- public function metaboxCategoryGroupSpecialPages($data)
688
- {
689
- echo '<form name="avhec-specialpagesgroup" id="avhec-specialpagesgroup" method="POST" action="' . $this->getBackLink() . '" accept-charset="utf-8" >';
690
- wp_nonce_field('avh_ec_specialpagesgroup');
691
- echo $this->printOptions($data['sp']['form'], $data['sp']['data']);
692
- echo '<p class="submit"><input class="button" type="submit" name="spgroup" value="' . __('Save settings', 'avh-ec') . '" /></p>';
693
- echo '</form>';
694
- }
695
-
696
- /**
697
- * Setup everything needed for the Manul Order page
698
- */
699
- public function actionLoadPageHook_ManualOrder()
700
- {
701
- add_meta_box('avhecBoxManualOrder', __('Manually Order Categories', 'avh-ec'), array($this, 'metaboxManualOrder'), $this->hooks['menu_manual_order'], 'normal', 'core');
702
-
703
- add_screen_option('layout_columns', array('max' => 1, 'default' => 1));
704
-
705
- // WordPress core Styles and Scripts
706
- wp_enqueue_script('common');
707
- wp_enqueue_script('wp-lists');
708
- wp_enqueue_script('postbox');
709
- wp_enqueue_script('jquery-ui-sortable');
710
- wp_enqueue_script('avhec-manualorder');
711
-
712
- // Plugin Style
713
- wp_enqueue_style('avhec-admin-css');
714
- }
715
-
716
- /**
717
- * Menu Page Manual Order
718
- *
719
- * @return none
720
- */
721
- public function doMenuManualOrder()
722
- {
723
- global $screen_layout_columns;
724
-
725
- $hide2 = '';
726
- switch ($screen_layout_columns) {
727
- case 2:
728
- $width = 'width:49%;';
729
- break;
730
- default:
731
- $width = 'width:98%;';
732
- $hide2 = 'display:none;';
733
- }
734
-
735
- echo '<div class="wrap">';
736
- echo $this->displayIcon('index');
737
- echo '<h2>' . 'AVH Extended Categories - ' . __('Manually Order Categories', 'avh-ec') . '</h2>';
738
-
739
- echo '<div class="metabox-holder">';
740
- echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
741
- do_meta_boxes($this->hooks['menu_manual_order'], 'normal', '');
742
- echo ' </div>';
743
- echo '</div>';
744
- echo '</div>'; // wrap
745
- echo '<div class="clear"></div>';
746
-
747
- $this->printMetaboxGeneralNonces();
748
- $this->printMetaboxJS('manual_order');
749
- $this->printAdminFooter();
750
- }
751
-
752
- /**
753
- * Displays the Manual Order metabox.
754
- *
755
- * @author Andrew Charlton - original
756
- * @author Peter van der Does - modifications
757
- */
758
- public function metaboxManualOrder()
759
- {
760
- global $wpdb;
761
-
762
- $parentID = 0;
763
-
764
- if (isset($_POST['btnSubCats'])) {
765
- $parentID = $_POST['cats'];
766
- } elseif (isset($_POST['hdnParentID'])) {
767
- $parentID = $_POST['hdnParentID'];
768
- }
769
-
770
- if (isset($_POST['btnReturnParent'])) {
771
- $parentsParent = $wpdb->get_row($wpdb->prepare("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = %d", $_POST['hdnParentID']), ARRAY_N);
772
- $parentID = $parentsParent[0];
773
- }
774
-
775
- $success = "";
776
- if (isset($_POST['btnOrderCats'])) {
777
- if (isset($_POST['hdnManualOrder']) && $_POST['hdnManualOrder'] != "") {
778
-
779
- $manualOrder = $_POST['hdnManualOrder'];
780
- $IDs = explode(",", $manualOrder);
781
- $result = count($IDs);
782
-
783
- for ($i = 0; $i < $result; $i ++) {
784
- $str = str_replace("id_", "", $IDs[$i]);
785
- $wpdb->query($wpdb->prepare("UPDATE $wpdb->terms SET avhec_term_order = %d WHERE term_id =%d", $i, $str));
786
- }
787
-
788
- $success = '<div id="message" class="updated fade"><p>' . __('Manual order of the categories successfully updated.', 'avh-ec') . '</p></div>';
789
- } else {
790
- $success = '<div id="message" class="updated fade"><p>' . __('An error occured, order has not been saved.', 'avh-ec') . '</p></div>';
791
- }
792
- }
793
-
794
- $subCategories = "";
795
- $results = $wpdb->get_results($wpdb->prepare("SELECT t.term_id, t.name FROM $wpdb->term_taxonomy tt, $wpdb->terms t, $wpdb->term_taxonomy tt2 WHERE tt.parent = %d AND tt.taxonomy = 'category' AND t.term_id = tt.term_id AND tt2.parent = tt.term_id GROUP BY t.term_id, t.name HAVING COUNT(*) > 0 ORDER BY t.avhec_term_order ASC", $parentID));
796
- foreach ($results as $row) {
797
- $subCategories .= "<option value='$row->term_id'>$row->name</option>";
798
- }
799
-
800
- echo '<div class="wrap">';
801
- echo '<form name="frmMyCatOrder" method="post" action="">';
802
- echo $success;
803
-
804
- echo '<h4>';
805
- _e('Order the categories', 'avh-ec');
806
- if ($parentID == 0) {
807
- echo ' at the Toplevel';
808
- } else {
809
- $categories = get_category_parents($parentID, false, ' » ');
810
- echo ' in the category ' . trim($categories, ' » ');
811
- }
812
- echo '</h4>';
813
- echo '<span class="description">';
814
- _e('Order the categories on this level by dragging and dropping them into the desired order.', 'avh-ec');
815
- echo '</span>';
816
- echo '<ul id="avhecManualOrder">';
817
- $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->terms t inner join $wpdb->term_taxonomy tt on t.term_id = tt.term_id WHERE taxonomy = 'category' and parent = %d ORDER BY avhec_term_order ASC", $parentID));
818
- foreach ($results as $row) {
819
- echo "<li id='id_$row->term_id' class='lineitem menu-item-settings'>" . __($row->name) . "</li>";
820
- }
821
- echo '</ul>';
822
- echo '<input type="submit" name="btnOrderCats" id="btnOrderCats" class="button-primary" value="' . __('Save Order', 'avh-ec') . '" onclick="javascript:orderCats(); return true;" />';
823
-
824
- if ($parentID != 0) {
825
- echo "<input type='submit' class='button' id='btnReturnParent' name='btnReturnParent' value='" . __('Return to parent category', 'avh-ec') . "' />";
826
- }
827
-
828
- echo '<strong id="updateText"></strong><br /><br />';
829
- if ($subCategories != "") {
830
-
831
- echo '<h4>';
832
- _e('Select Subcategory', 'avh-ec');
833
- echo '</h4>';
834
- echo '<select id="cats" name="cats">';
835
- echo $subCategories;
836
-
837
- echo '</select><input type="submit" name="btnSubCats" class="button" id="btnSubCats" value="' . __('Select', 'avh-ec') . '" />';
838
- echo '<span class="description">';
839
- _e('Choose a category from the drop down to order the subcategories in that category.', 'avh-ec');
840
- echo '</span>';
841
- }
842
-
843
- echo '<input type="hidden" id="hdnManualOrder" name="hdnManualOrder" />';
844
- echo '<input type="hidden" id="hdnParentID" name="hdnParentID" value="' . $parentID . '" /></form>';
845
- echo '</div>';
846
- }
847
-
848
- /**
849
- * Setup everything needed for the FAQ page
850
- */
851
- public function actionLoadPageHook_faq()
852
- {
853
- add_meta_box('avhecBoxFAQ', __('F.A.Q.', 'avh-ec'), array($this, 'metaboxFAQ'), $this->hooks['menu_faq'], 'normal', 'core');
854
- add_meta_box('avhecBoxTranslation', __('Translation', 'avh-ec'), array($this, 'metaboxTranslation'), $this->hooks['menu_faq'], 'normal', 'core');
855
-
856
- add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
857
-
858
- // WordPress core Styles and Scripts
859
- wp_enqueue_script('common');
860
- wp_enqueue_script('wp-lists');
861
- wp_enqueue_script('postbox');
862
-
863
- // Plugin Style
864
- wp_enqueue_style('avhec-admin-css');
865
- }
866
-
867
- /**
868
- * Menu Page FAQ
869
- *
870
- * @return none
871
- */
872
- public function doMenuFAQ()
873
- {
874
- global $screen_layout_columns;
875
-
876
- // This box can't be unselectd in the the Screen Options
877
- // add_meta_box('avhecBoxAnnouncements', __('Announcements', 'avh-ec'), array ( $this, 'metaboxAnnouncements' ), $this->hooks['menu_faq'], 'side', 'core');
878
- add_meta_box('avhecBoxDonations', __('Donations', 'avh-ec'), array($this, 'metaboxDonations'), $this->hooks['menu_faq'], 'side', 'core');
879
-
880
- $hide2 = '';
881
- switch ($screen_layout_columns) {
882
- case 2:
883
- $width = 'width:49%;';
884
- break;
885
- default:
886
- $width = 'width:98%;';
887
- $hide2 = 'display:none;';
888
- }
889
-
890
- echo '<div class="wrap avhec-metabox-wrap">';
891
- echo $this->displayIcon('index');
892
- echo '<h2>' . 'AVH Extended Categories - ' . __('F.A.Q', 'avh-ec') . '</h2>';
893
- echo ' <div id="dashboard-widgets-wrap">';
894
- echo ' <div id="dashboard-widgets" class="metabox-holder">';
895
- echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
896
- do_meta_boxes($this->hooks['menu_faq'], 'normal', '');
897
- echo ' </div>';
898
- echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n";
899
- do_meta_boxes($this->hooks['menu_faq'], 'side', '');
900
- echo ' </div>';
901
- echo ' </div>';
902
- echo '<br class="clear"/>';
903
- echo ' </div>'; // dashboard-widgets-wrap
904
- echo '</div>'; // wrap
905
-
906
- $this->printMetaboxGeneralNonces();
907
- $this->printMetaboxJS('faq');
908
- $this->printAdminFooter();
909
- }
910
-
911
- /**
912
- * Translation Metabox
913
- *
914
- * @return unknown_type
915
- */
916
- public function metaboxTranslation()
917
- {
918
- $locale = apply_filters('plugin_locale', get_locale(), 'avh-ec');
919
- $available_locale['cs_CZ'] = array('Czech - Čeština', 0);
920
- $available_locale['nl_NL'] = array('Dutch - Nederlands', 0);
921
- $available_locale['de_DE'] = array('German - Deutsch', 0);
922
- $available_locale['el'] = array('Greek - Čeština', 0);
923
- $available_locale['id_ID'] = array('Indonesian - Bahasa Indonesia - Čeština', 0);
924
- $available_locale['it_IT'] = array('Italian - Italiano', 1);
925
- $available_locale['ru_RU'] = array('Russian — Русский', 0);
926
- $available_locale['es_ES'] = array('Spanish - Español', 0);
927
- $available_locale['sv_SE'] = array('Swedish - Svenska', 0);
928
- $available_locale['tr'] = array('Turkish - Türkçe', 0);
929
-
930
- echo '<div class="p">';
931
- echo __('This plugin is translated in several languages. Some of the languages might be incomplete. Please help to complete these translations or add a new language.', 'avh-ec') . '<br />';
932
-
933
- echo '</div>';
934
-
935
- echo '<div class="p">';
936
- echo '<span class="b">' . __('Available Languages', 'avh-ec') . '</span>';
937
- echo '<ul>';
938
- foreach ($available_locale as $key => $value) {
939
- echo '<li>';
940
- $complete = ($value[1] == 1 ? 'Complete' : 'Incomplete');
941
- echo $value[0] . ' (' . $key . ') - ' . $complete;
942
- echo '</li>';
943
- }
944
- echo '</ul>';
945
- echo '</div>';
946
-
947
- echo '<div class="p">';
948
- if ('en_US' != $locale & (!array_key_exists($locale, $available_locale))) {
949
- echo 'Currently the plugin is not available in your language (' . $locale . '). We\'re in the middle of changing the way you can help with translations. Keep an eye on the <a href="http:///blog.avirtualhome.com">website</a> for the announcement.';
950
- } else {
951
- echo 'We\'re in the middle of changing the way you can help with translations. Keep an eye on the <a href="http:///blog.avirtualhome.com">website</a> for the announcement.';
952
- }
953
- echo '</div>';
954
- }
955
-
956
- /**
957
- * Donation Metabox
958
- *
959
- * @return unknown_type
960
- */
961
- public function metaboxDonations()
962
- {
963
- echo '<div class="p">';
964
- echo __('If you enjoy this plug-in please consider a donation. There are several ways you can show your appreciation.', 'avh-ec');
965
- echo '</div>';
966
-
967
- echo '<div class="p">';
968
- echo '<span class="b">Amazon</span><br />';
969
- echo __('If you decide to buy something from Amazon click the button.', 'avh-ec') . '</span><br />';
970
- echo '<a href="https://www.amazon.com/?tag=avh-donation-20" target="_blank" title="Amazon Homepage"><img alt="Amazon Button" src="' . $this->core->info['graphics_url'] . '/us_banner_logow_120x60.gif" /></a>';
971
- echo '</div>';
972
-
973
- echo '<div class="p">';
974
- echo __('You can send me something from my ', 'avh-ec') . '<a href="http://www.amazon.com/registry/wishlist/1U3DTWZ72PI7W?tag=avh-donation-20">' . __('Amazon Wish List', 'avh-ec') . '</a>';
975
- echo '</div>';
976
-
977
- echo '<div class="p">';
978
- echo '<span class="b">' . __('Through Paypal.', 'avh-ec') . '</span><br />';
979
- echo __('Click on the Donate button and you will be directed to Paypal where you can make your donation and you don\'t need to have a Paypal account to make a donation.', 'avh-ec') . '<br />';
980
- echo '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=S85FXJ9EBHAF2&lc=US&item_name=AVH%20Plugins&item_number=fdas&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted" target="_blank" title="Donate">';
981
- echo '<img src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" alt="Donate"/></a>';
982
- echo '</div>';
983
- }
984
-
985
- /**
986
- * *
987
- * F.A.Q Metabox
988
- *
989
- * @return none
990
- */
991
- public function metaboxFAQ()
992
- {
993
- echo '<div class="p">';
994
- echo '<span class="b">' . __('What about support?', 'avh-ec') . '</span><br />';
995
- echo __('I created a <a href="http://forums.avirtualhome.com" target="_blank">support site</a> where you can ask questions or request features.', 'avh-ec') . '<br />';
996
- echo '</div>';
997
-
998
- echo '<div class="p">';
999
- echo '<span class="b">' . __('What is depth selection?', 'avh-ec') . '</span><br />';
1000
- echo __('Starting with version 2.0 and WordPress 2.8 you can select how many levels deep you want to show your categories. This option only works when you select Show Hierarchy as well.', 'avh-ec') . '<br /><br />';
1001
- echo __('Here is how it works: Say you have 5 top level categories and each top level has a number of children. You could manually select all the Top Level categories you want to show but now you can do the following:', 'avh-ec') . '<br />';
1002
- echo __('You select to display all categories, select to Show hierarchy and select how many levels you want to show, in this case Toplevel only.', 'avh-ec') . '<br />';
1003
- echo '</div>';
1004
-
1005
- echo '<div class="p">';
1006
- echo '<span class="b">' . __('Multiple Category Groups', 'avh-ec') . '</span><br />';
1007
- echo __('The following is an explanation how assigning multiple groups to page/post works.', 'avh-ec') . '<br /><br />';
1008
- echo __('Lets say you have the following groups:', 'avh-ec');
1009
- echo '<ul>';
1010
- echo '<li>' . __('Free Time', 'avh-ec') . '</li>';
1011
- echo '<li>' . __('Theater', 'avh-ec') . '</li>';
1012
- echo '<li>' . __('Movie', 'avh-ec') . '</li>';
1013
- echo '<li>' . __('Music', 'avh-ec') . '</li>';
1014
- echo '</ul>';
1015
- echo __('Setup several Category Group widgets and associated each widget with one or more groups.', 'avh-ec') . '<br />';
1016
- echo __('Widget 1 has association with Free Time', 'avh-ec') . '<br />';
1017
- echo __('Widget 2 has association with Theater, Movie and Music', 'avh-ec') . '<br />';
1018
- echo __('Widget 3 has association with Theater, Movie and Music', 'avh-ec') . '<br /><br />';
1019
- echo __('Page has associations the groups Free Time and Theater', 'avh-ec');
1020
- echo '<ul>';
1021
- echo '<li>' . __('Widget 1: Shows categories of the Free Time group', 'avh-ec') . '</li>';
1022
- echo '<li>' . __('Widget 2: Shows categories of the Theater group.', 'avh-ec') . '</li>';
1023
- echo '<li>' . __('Widget 3: Not displayed', 'avh-ec') . '</li>';
1024
- echo '</ul>';
1025
- echo __('Page has associations the group Movie.', 'avh-ec');
1026
- echo '<ul>';
1027
- echo '<li>' . __('Widget 1: Not displayed', 'avh-ec') . '</li>';
1028
- echo '<li>' . __('Widget 2: Shows categories of the Movie group.', 'avh-ec') . '</li>';
1029
- echo '<li>' . __('Widget 3: Not displayed', 'avh-ec') . '</li>';
1030
- echo '</ul>';
1031
- echo __('Page has associations the groups Free Time, Movie and Music', 'avh-ec');
1032
- echo '<ul>';
1033
- echo '<li>' . __('Widget 1: Shows categories of the Free Time group', 'avh-ec') . '</li>';
1034
- echo '<li>' . __('Widget 2: Shows categories of the Movie or Music group.', 'avh-ec') . '</li>';
1035
- echo '<li>' . __('Widget 3: Shows categories of the Music or Movie group.', 'avh-ec') . '</li>';
1036
- echo '</ul>';
1037
- echo __('Whether Widget 2 shows Movie or Music depends on the creation order of groups. If Widget 2 shows Movie, Widget 3 will show Music but if Widget 2 shows Music, Widget 3 will show Movie.', 'avh-ec') . '<br />';
1038
- echo '</div>';
1039
- }
1040
-
1041
- public function metaboxAnnouncements()
1042
- {
1043
- $php5 = version_compare('5.2', phpversion(), '<');
1044
- echo '<div class="p">';
1045
- echo '<span class="b">' . __('PHP4 Support', 'avh-ec') . '</span><br />';
1046
- echo __('The next major release of the plugin will no longer support PHP4.', 'avh-ec') . '<br />';
1047
- echo __('It will be written for PHP 5.2 and ', 'avh-ec');
1048
- if ($php5) {
1049
- echo __('your blog already runs the needed PHP version. When the new release comes out you can safely update.', 'avh-ec') . '<br />';
1050
- } else {
1051
- echo __('your blog still runs PHP4. When the new release comes out you can not use it.', 'avh-ec') . '<br />';
1052
- echo __('I don\'t have a timeline for the next version but consider contacting your host if PHP 5.2 is available.', 'avh-ec') . '<br />';
1053
- echo __('If your hosts doesn\'t offer PHP 5.2 you might want to consider switching hosts.', 'avh-ec') . '<br />';
1054
- echo __('A host to consider is ', 'avh-ec') . '<a href="http://www.lunarpages.com/id/pdoes" target="_blank">Lunarpages</a>';
1055
- echo __('I run my personal blog there and I am very happy with their services. You can get an account with unlimited bandwidth, storage and much more for a low price.', 'avh-ec');
1056
- }
1057
- echo '</div>';
1058
- }
1059
-
1060
- /**
1061
- * Sets the amount of columns wanted for a particuler screen
1062
- *
1063
- * @WordPress filter screen_meta_screen
1064
- *
1065
- * @param
1066
- * $screen
1067
- * @return strings
1068
- */
1069
- public function filterScreenLayoutColumns($columns, $screen)
1070
- {
1071
- switch ($screen) {
1072
- case $this->hooks['menu_overview']:
1073
- $columns[$this->hooks['menu_overview']] = 2;
1074
- break;
1075
- case $this->hooks['menu_general']:
1076
- $columns[$this->hooks['menu_general']] = 2;
1077
- break;
1078
- case $this->hooks['menu_category_groups']:
1079
- $columns[$this->hooks['menu_category_groups']] = 2;
1080
- break;
1081
- case $this->hooks['menu_faq']:
1082
- $columns[$this->hooks['menu_faq']] = 2;
1083
- break;
1084
- }
1085
-
1086
- return $columns;
1087
- }
1088
-
1089
- /**
1090
- * Adds Settings next to the plugin actions
1091
- *
1092
- * @WordPress Filter plugin_action_links_avh-amazon/avh-amazon.php
1093
- */
1094
- public function filterPluginActions($links, $file)
1095
- {
1096
- $settings_link = '<a href="admin.php?page=extended-categories-widget">' . __('Settings', 'avh-ec') . '</a>';
1097
- array_unshift($links, $settings_link); // before other links
1098
-
1099
- return $links;
1100
- }
1101
-
1102
- /**
1103
- * Creates a new array for columns headers.
1104
- * Used in print_column_headers. The filter is called from get_column_headers
1105
- *
1106
- * @param
1107
- * $columns
1108
- * @return Array
1109
- * @see print_column_headers, get_column_headers
1110
- */
1111
- public function filterManageCategoriesGroupColumns($columns)
1112
- {
1113
- $categories_group_columns = array('name' => __('Name', 'avh-ec'), 'slug' => __('Slug', 'avh-ec'), 'widget-title' => __('Widget Title', 'avh-ec'), 'description' => __('Description', 'avh-ec'), 'cat-in-group' => __('Categories in the group', 'avh-ec'));
1114
-
1115
- return $categories_group_columns;
1116
- }
1117
-
1118
- /**
1119
- * When not using AJAX, this function is called when the deletion fails.
1120
- *
1121
- * @param string $text
1122
- * @param int $group_id
1123
- * @return string @WordPress Filter explain_nonce_$verb-$noun
1124
- * @see wp_explain_nonce
1125
- */
1126
- public function filterExplainNonceDeleteGroup($text, $group_id)
1127
- {
1128
- $group = get_term($group_id, $this->catgrp->taxonomy_name, OBJECT, 'display');
1129
-
1130
- $return = sprintf(__('Your attempt to delete this group: &#8220;%s&#8221; has failed.'), $group->name);
1131
-
1132
- return ($return);
1133
- }
1134
-
1135
- // ############ Admin WP Helper ##############
1136
-
1137
- /**
1138
- * Get the backlink for forms
1139
- *
1140
- * @return strings
1141
- */
1142
- public function getBackLink()
1143
- {
1144
- $page = basename(__FILE__);
1145
- if (isset($_GET['page']) && !empty($_GET['page'])) {
1146
- $page = preg_replace('[^a-zA-Z0-9\.\_\-]', '', $_GET['page']);
1147
- }
1148
-
1149
- if (function_exists("admin_url")) {
1150
- return admin_url(basename($_SERVER["PHP_SELF"])) . "?page=" . $page;
1151
- } else {
1152
- return $_SERVER['PHP_SELF'] . "?page=" . $page;
1153
- }
1154
- }
1155
-
1156
- /**
1157
- * Print all Category Group rows
1158
- *
1159
- * @uses printCategoryGroupRow
1160
- *
1161
- */
1162
- public function printCategoryGroupRows()
1163
- {
1164
- $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false));
1165
-
1166
- foreach ($cat_groups as $group) {
1167
- if ('none' != $group->slug) {
1168
- echo $this->printCategoryGroupRow($group->term_id, $group->term_taxonomy_id);
1169
- }
1170
- }
1171
- }
1172
-
1173
- /**
1174
- * Displays all the information of a group in a row
1175
- * Adds inline link for delete and/or edit.
1176
- *
1177
- * @param int $group_term_id
1178
- * @param int $group_term_taxonomy_id
1179
- */
1180
- public function printCategoryGroupRow($group_term_id, $group_term_taxonomy_id)
1181
- {
1182
- static $row_class = '';
1183
-
1184
- $group = get_term($group_term_id, $this->catgrp->taxonomy_name, OBJECT, 'display');
1185
-
1186
- $no_edit[$this->catgrp->getTermIDBy('slug', 'all')] = 0;
1187
- $no_delete[$this->catgrp->getTermIDBy('slug', 'all')] = 0;
1188
-
1189
- if (current_user_can('manage_categories')) {
1190
- $actions = array();
1191
- if (!array_key_exists($group->term_id, $no_edit)) {
1192
- $edit_link = "admin.php?page=avhec-grouped&amp;action=edit&amp;group_ID=$group->term_id";
1193
- $edit = "<a class='row-title' href='$edit_link' title='" . esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $group->name)) . "'>" . esc_attr($group->name) . '</a><br />';
1194
-
1195
- $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
1196
- } else {
1197
- $edit = esc_attr($group->name);
1198
- }
1199
- if (!(array_key_exists($group->term_id, $no_delete))) {
1200
- $actions['delete'] = "<a class='delete:the-list:group-$group->term_id submitdelete' href='" . wp_nonce_url("admin.php?page=avhec-grouped&amp;action=delete&amp;group_ID=$group->term_id", 'delete-avhecgroup_' . $group->term_id) . "'>" . __('Delete') . "</a>";
1201
- }
1202
- $action_count = count($actions);
1203
- $i = 0;
1204
- $edit .= '<div class="row-actions">';
1205
- foreach ($actions as $action => $link) {
1206
- ++ $i;
1207
- ($i == $action_count) ? $sep = '' : $sep = ' | ';
1208
- $edit .= "<span class='$action'>$link$sep</span>";
1209
- }
1210
- $edit .= '</div>';
1211
- } else {
1212
- $edit = $group->name;
1213
- }
1214
-
1215
- $row_class = 'alternate' == $row_class ? '' : 'alternate';
1216
- $qe_data = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit');
1217
-
1218
- $output = "<tr id='group-$group->term_id' class='iedit $row_class'>";
1219
-
1220
- $columns = get_column_headers('categories_group');
1221
- $hidden = get_hidden_columns('categories_group');
1222
- foreach ($columns as $column_name => $column_display_name) {
1223
- $class = 'class="' . $column_name . ' column-' . $column_name . '"';
1224
-
1225
- $style = '';
1226
- if (in_array($column_name, $hidden)) {
1227
- $style = ' style="display:none;"';
1228
- }
1229
-
1230
- $attributes = $class . $style;
1231
-
1232
- switch ($column_name) {
1233
- case 'cb':
1234
- $output .= '<th scope="row" class="check-column">';
1235
- if (!(array_key_exists($group->term_id, $no_delete))) {
1236
- $output .= '<input type="checkbox" name="delete[]" value="' . $group->term_id . '" />';
1237
- } else {
1238
- $output .= "&nbsp;";
1239
- }
1240
- $output .= '</th>';
1241
- break;
1242
- case 'name':
1243
- $output .= '<td ' . $attributes . '>' . $edit;
1244
- $output .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">';
1245
- $output .= '<div class="name">' . $qe_data->name . '</div>';
1246
- $output .= '<div class="slug">' . apply_filters('editable_slug', $qe_data->slug) . '</div>';
1247
- $output .= '</div></td>';
1248
- break;
1249
- case 'widget-title':
1250
- $title = $this->catgrp->getWidgetTitleForGroup($group->term_id);
1251
- if (!$title) {
1252
- $title = "&nbsp;";
1253
- }
1254
- $output .= '<td ' . $attributes . '>' . $title . '</td>';
1255
- break;
1256
-
1257
- case 'description':
1258
- $output .= '<td ' . $attributes . '>' . $qe_data->description . '</td>';
1259
- break;
1260
- case 'slug':
1261
- $output .= "<td $attributes>" . apply_filters('editable_slug', $qe_data->slug) . "</td>";
1262
- break;
1263
- case 'cat-in-group':
1264
- $cats = $this->catgrp->getCategoriesFromGroup($group_term_id);
1265
- $catname = array();
1266
- foreach ($cats as $cat_id) {
1267
- $catname[] = get_cat_name($cat_id);
1268
- }
1269
- natsort($catname);
1270
- $cat = implode(', ', $catname);
1271
- $output .= '<td ' . $attributes . '>' . $cat . '</td>';
1272
- break;
1273
- }
1274
- }
1275
- $output .= '</tr>';
1276
-
1277
- return $output;
1278
- }
1279
-
1280
- /**
1281
- * Prints the general nonces, used by the AJAX
1282
- */
1283
- public function printMetaboxGeneralNonces()
1284
- {
1285
- echo '<form style="display:none" method="get" action="">';
1286
- echo '<p>';
1287
- wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1288
- wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1289
- echo '</p>';
1290
- echo '</form>';
1291
- }
1292
-
1293
- /**
1294
- * Print the Metabox JS for toggling closed and open
1295
- *
1296
- * @param
1297
- * $boxid
1298
- */
1299
- public function printMetaboxJS($boxid)
1300
- {
1301
- $a = $this->hooks['menu_' . $boxid];
1302
- echo '<script type="text/javascript">' . "\n";
1303
- echo ' //<![CDATA[' . "\n";
1304
- echo ' jQuery(document).ready( function($) {' . "\n";
1305
- echo ' $(\'.if-js-closed\').removeClass(\'if-js-closed\').addClass(\'closed\');' . "\n";
1306
- echo ' // postboxes setup' . "\n";
1307
- echo ' postboxes.add_postbox_toggles(\'' . $a . '\');' . "\n";
1308
- echo ' });' . "\n";
1309
- echo ' //]]>' . "\n";
1310
- echo '</script>';
1311
- }
1312
-
1313
- /**
1314
- * Display plugin Copyright
1315
- */
1316
- public function printAdminFooter()
1317
- {
1318
- echo '<p class="footer_avhec">';
1319
- printf('&copy; Copyright %d <a href="http://blog.avirtualhome.com/" title="My Thoughts">Peter van der Does</a> | AVH Extended Categories Version %s', date('Y'), $this->core->version);
1320
- echo '</p>';
1321
- }
1322
-
1323
- /**
1324
- * Display WP alert
1325
- */
1326
- public function displayMessage()
1327
- {
1328
- if ($this->message != '') {
1329
- $message = $this->message;
1330
- $status = $this->status;
1331
- $this->message = $this->status = ''; // Reset
1332
- }
1333
- if (isset($message)) {
1334
- $status = ($status != '') ? $status : 'updated fade';
1335
- echo '<div id="message" class="' . $status . '">';
1336
- echo '<p><strong>' . $message . '</strong></p></div>';
1337
- }
1338
- }
1339
-
1340
- /**
1341
- * Ouput formatted options
1342
- *
1343
- * @param array $option_data
1344
- * @return string
1345
- */
1346
- public function printOptions($option_data, $option_actual)
1347
- {
1348
- // Generate output
1349
- $output = '';
1350
- $output .= "\n" . '<table class="form-table avhec-options">' . "\n";
1351
- foreach ($option_data as $option) {
1352
- $section = substr($option[0], strpos($option[0], '[') + 1);
1353
- $section = substr($section, 0, strpos($section, ']['));
1354
- $option_key = rtrim($option[0], ']');
1355
- $option_key = substr($option_key, strpos($option_key, '][') + 2);
1356
- // Helper
1357
- if ($option[2] == 'helper') {
1358
- $output .= '<tr style="vertical-align: top;"><td class="helper" colspan="2">' . wp_filter_post_kses($option[4]) . '</td></tr>' . "\n";
1359
- continue;
1360
- }
1361
- switch ($option[2]) {
1362
- case 'checkbox':
1363
- $input_type = '<input type="checkbox" id="' . esc_attr($option[0]) . '" name="' . esc_attr($option[0]) . '" value="' . esc_attr($option[3]) . '" ' . $this->isChecked('1', $option_actual[$section][$option_key]) . ' />' . "\n";
1364
- $explanation = $option[4];
1365
- break;
1366
- case 'dropdown':
1367
- $selvalue = $option[3];
1368
- $seltext = $option[4];
1369
- $seldata = '';
1370
- foreach ((array) $selvalue as $key => $sel) {
1371
- $seldata .= '<option value="' . esc_attr($sel) . '" ' . (($option_actual[$section][$option_key] == $sel) ? 'selected="selected"' : '') . ' >' . esc_html(ucfirst($seltext[$key])) . '</option>' . "\n";
1372
- }
1373
- $input_type = '<select id="' . esc_attr($option[0]) . '" name="' . esc_attr($option[0]) . '">' . $seldata . '</select>' . "\n";
1374
- $explanation = $option[5];
1375
- break;
1376
- case 'text-color':
1377
- $input_type = '<input type="text" ' . (($option[3] > 1) ? ' style="width: 95%" ' : '') . 'id="' . esc_attr($option[0]) . '" name="' . esc_attr($option[0]) . '" value="' . esc_attr($option_actual[$section][$option_key]) . '" size="' . esc_attr($option[3]) . '" /><div class="box_color ' . esc_attr($option[0]) . '"></div>' . "\n";
1378
- $explanation = $option[4];
1379
- break;
1380
- case 'textarea':
1381
- $input_type = '<textarea rows="' . esc_attr($option[5]) . '" ' . (($option[3] > 1) ? ' style="width: 95%" ' : '') . 'id="' . esc_attr($option[0]) . '" name="' . esc_attr($option[0]) . '" size="' . esc_attr($option[3]) . '" />' . $option_actual[$section][$option_key] . '</textarea>';
1382
- $explanation = $option[4];
1383
- break;
1384
- case 'catlist':
1385
- ob_start();
1386
- echo '<div id="avhec-catlist">';
1387
- echo '<ul>';
1388
- wp_category_checklist(0, 0, $option_actual[$section][$option_key]);
1389
- echo '</ul>';
1390
- echo '</div>';
1391
- $input_type = ob_get_contents();
1392
- ob_end_clean();
1393
- $explanation = $option[4];
1394
- break;
1395
- case 'text':
1396
- default:
1397
- $input_type = '<input type="text" ' . (($option[3] > 1) ? ' style="width: 95%" ' : '') . 'id="' . esc_attr($option[0]) . '" name="' . esc_attr($option[0]) . '" value="' . esc_attr($option_actual[$section][$option_key]) . '" size="' . esc_attr($option[3]) . '" />' . "\n";
1398
- $explanation = $option[4];
1399
- break;
1400
- }
1401
- // Additional Information
1402
- $extra = '';
1403
- if ($explanation) {
1404
- $extra = '<br /><span class="description">' . wp_filter_kses($explanation) . '</span>' . "\n";
1405
- }
1406
- // Output
1407
- $output .= '<tr style="vertical-align: top;"><th align="left" scope="row"><label for="' . esc_attr($option[0]) . '">' . wp_filter_kses($option[1]) . '</label></th><td>' . $input_type . ' ' . $extra . '</td></tr>' . "\n";
1408
- }
1409
- $output .= '</table>' . "\n";
1410
-
1411
- return $output;
1412
- }
1413
-
1414
- /**
1415
- * Used in forms to set an option checked
1416
- *
1417
- * @param mixed $checked
1418
- * @param mixed $current
1419
- * @return strings
1420
- */
1421
- public function isChecked($checked, $current)
1422
- {
1423
- $return = '';
1424
- if ($checked == $current) {
1425
- $return = ' checked="checked"';
1426
- }
1427
-
1428
- return $return;
1429
- }
1430
-
1431
- /**
1432
- * Displays the icon on the menu pages
1433
- *
1434
- * @param
1435
- * $icon
1436
- */
1437
- public function displayIcon($icon)
1438
- {
1439
- return ('<div class="icon32" id="icon-' . $icon . '"><br/></div>');
1440
- }
1441
-
1442
- /**
1443
- * Ajax Helper: inline delete of the groups
1444
- */
1445
- public function ajaxDeleteGroup()
1446
- {
1447
- $group_id = isset($_POST['id']) ? (int) $_POST['id'] : 0;
1448
- check_ajax_referer('delete-avhecgroup_' . $group_id);
1449
-
1450
- if (!current_user_can('manage_categories')) {
1451
- die('-1');
1452
- }
1453
- $check = $this->catgrp->getGroup($group_id);
1454
- if (false === $check) {
1455
- die('1');
1456
- }
1457
-
1458
- if ($this->catgrp->doDeleteGroup($group_id)) {
1459
- die('1');
1460
- } else {
1461
- die('0');
1462
- }
1463
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1464
  }
1
  <?php
2
 
3
+ class AVH_EC_Admin {
4
+ /**
5
+ * @var AVH_EC_Category_Group
6
+ */
7
+ public $catgrp;
8
+ /**
9
+ * @var AVH_EC_Core
10
+ */
11
+ public $core;
12
+ public $hooks = array();
13
+ public $message;
14
+
15
+ /**
16
+ * PHP5 constructor
17
+ */
18
+ public function __construct() {
19
+
20
+ // Initialize the plugin
21
+ $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core');
22
+ $this->catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
23
+
24
+ add_action('wp_ajax_delete-group', array($this, 'ajaxDeleteGroup'));
25
+
26
+ // Admin menu
27
+ add_action('admin_init', array($this, 'actionAdminInit'));
28
+ add_action('admin_menu', array($this, 'actionAdminMenu'));
29
+ add_filter('plugin_action_links_extended-categories-widget/widget_extended_categories.php',
30
+ array($this, 'filterPluginActions'),
31
+ 10,
32
+ 2);
33
+
34
+ // Actions used for editing posts
35
+ add_action('load-post.php', array($this, 'actionLoadPostPage'));
36
+ add_action('load-page.php', array($this, 'actionLoadPostPage'));
37
+
38
+ // Actions related to adding and deletes categories
39
+ add_action("created_category", array($this, 'actionCreatedCategory'), 10, 2);
40
+ add_action("delete_category", array($this, 'actionDeleteCategory'), 10, 2);
41
+
42
+ add_filter('manage_categories_group_columns', array($this, 'filterManageCategoriesGroupColumns'));
43
+ add_filter('explain_nonce_delete-avhecgroup', array($this, 'filterExplainNonceDeleteGroup'), 10, 2);
44
+
45
+ return;
46
+ }
47
+
48
+ public function actionAdminInit() {
49
+ if (is_admin() && isset($_GET['taxonomy']) && 'category' == $_GET['taxonomy']) {
50
+ add_action($_GET['taxonomy'] . '_edit_form', array($this, 'displayCategoryGroupForm'), 10, 2);
51
+ }
52
+ add_action('edit_term', array($this, 'handleEditTerm'), 10, 3);
53
+ }
54
+
55
+ /**
56
+ * Add the Tools and Options to the Management and Options page repectively
57
+ *
58
+ * @WordPress Action admin_menu
59
+ */
60
+ public function actionAdminMenu() {
61
+
62
+ // Register Style and Scripts
63
+ $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
64
+ wp_register_script('avhec-categorygroup-js',
65
+ AVHEC_PLUGIN_URL . '/js/avh-ec.categorygroup' . $suffix . '.js',
66
+ array('jquery'),
67
+ $this->core->version,
68
+ true);
69
+ wp_register_script('avhec-manualorder',
70
+ AVHEC_PLUGIN_URL . '/js/avh-ec.admin.manualorder' . $suffix . '.js',
71
+ array('jquery-ui-sortable'),
72
+ $this->core->version,
73
+ false);
74
+ wp_register_style('avhec-admin-css',
75
+ AVHEC_PLUGIN_URL . '/css/avh-ec.admin.css',
76
+ array('wp-admin'),
77
+ $this->core->version,
78
+ 'screen');
79
+
80
+ // Add menu system
81
+ $folder = $this->core->getBaseDirectory(AVHEC_PLUGIN_DIR);
82
+ add_menu_page('AVH Extended Categories',
83
+ 'AVH Extended Categories',
84
+ 'manage_options',
85
+ $folder,
86
+ array($this, 'doMenuOverview'));
87
+ $this->hooks['menu_overview'] = add_submenu_page($folder,
88
+ 'AVH Extended Categories: ' . __('Overview', 'avh-ec'),
89
+ __('Overview', 'avh-ec'),
90
+ 'manage_options',
91
+ $folder,
92
+ array($this, 'doMenuOverview'));
93
+ $this->hooks['menu_general'] = add_submenu_page($folder,
94
+ 'AVH Extended Categories: ' .
95
+ __('General Options', 'avh-ec'),
96
+ __('General Options', 'avh-ec'),
97
+ 'manage_options',
98
+ 'avhec-general',
99
+ array($this, 'doMenuGeneral'));
100
+ $this->hooks['menu_category_groups'] = add_submenu_page($folder,
101
+ 'AVH Extended Categories: ' .
102
+ __('Category Groups', 'avh-ec'),
103
+ __('Category Groups', 'avh-ec'),
104
+ 'manage_options',
105
+ 'avhec-grouped',
106
+ array($this, 'doMenuCategoryGroup'));
107
+ $this->hooks['menu_manual_order'] = add_submenu_page($folder,
108
+ 'AVH Extended Categories: ' .
109
+ __('Manually Order', 'avh-ec'),
110
+ __('Manually Order', 'avh-ec'),
111
+ 'manage_options',
112
+ 'avhec-manual-order',
113
+ array($this, 'doMenuManualOrder'));
114
+ $this->hooks['menu_faq'] = add_submenu_page($folder,
115
+ 'AVH Extended Categories:' . __('F.A.Q', 'avh-ec'),
116
+ __('F.A.Q', 'avh-ec'),
117
+ 'manage_options',
118
+ 'avhec-faq',
119
+ array($this, 'doMenuFAQ'));
120
+
121
+ // Add actions for menu pages
122
+ // Overview Menu
123
+ add_action('load-' . $this->hooks['menu_overview'], array($this, 'actionLoadPageHook_Overview'));
124
+
125
+ // General Options Menu
126
+ add_action('load-' . $this->hooks['menu_general'], array($this, 'actionLoadPageHook_General'));
127
+
128
+ // Category Groups Menu
129
+ add_action('load-' . $this->hooks['menu_category_groups'], array($this, 'actionLoadPageHook_CategoryGroup'));
130
+
131
+ // Manual Order Menu
132
+ add_action('load-' . $this->hooks['menu_manual_order'], array($this, 'actionLoadPageHook_ManualOrder'));
133
+
134
+ // FAQ Menu
135
+ add_action('load-' . $this->hooks['menu_faq'], array($this, 'actionLoadPageHook_faq'));
136
+ }
137
+
138
+ /**
139
+ * When a category is created this function is called to add the new category to the group all
140
+ *
141
+ * @param
142
+ * $term_id
143
+ * @param
144
+ * $term_taxonomy_id
145
+ */
146
+ public function actionCreatedCategory($term_id, $term_taxonomy_id) {
147
+ $group_id = $this->catgrp->getTermIDBy('slug', 'all');
148
+ $this->catgrp->setCategoriesForGroup($group_id, (array) $term_id);
149
+ }
150
+
151
+ /**
152
+ * When a category is deleted this function is called so the category is deleted from every group as well.
153
+ *
154
+ * @param object $term
155
+ * @param int $term_taxonomy_id
156
+ */
157
+ public function actionDeleteCategory($term_id, $term_taxonomy_id) {
158
+ $this->catgrp->doDeleteCategoryFromGroup($term_id);
159
+ }
160
+
161
+ /**
162
+ * Setup everything needed for the Category Group page
163
+ */
164
+ public function actionLoadPageHook_CategoryGroup() {
165
+
166
+ // Add metaboxes
167
+ add_meta_box('avhecBoxCategoryGroupAdd',
168
+ __('Add Group', 'avh-ec'),
169
+ array($this, 'metaboxCategoryGroupAdd'),
170
+ $this->hooks['menu_category_groups'],
171
+ 'normal',
172
+ 'core');
173
+ add_meta_box('avhecBoxCategoryGroupList',
174
+ __('Group Overview', 'avh-ec'),
175
+ array($this, 'metaboxCategoryGroupList'),
176
+ $this->hooks['menu_category_groups'],
177
+ 'side',
178
+ 'core');
179
+ add_meta_box('avhecBoxCategoryGroupSpecialPages',
180
+ __('Special Pages', 'avh-ec'),
181
+ array($this, 'metaboxCategoryGroupSpecialPages'),
182
+ $this->hooks['menu_category_groups'],
183
+ 'normal',
184
+ 'core');
185
+
186
+ add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
187
+
188
+ // WordPress core Scripts
189
+ wp_enqueue_script('common');
190
+ wp_enqueue_script('wp-lists');
191
+ wp_enqueue_script('postbox');
192
+
193
+ // Plugin Scripts
194
+ wp_enqueue_script('avhec-categorygroup-js');
195
+
196
+ // Plugin Style
197
+ wp_enqueue_style('avhec-admin-css');
198
+ }
199
+
200
+ /**
201
+ * Setup everything needed for the General Options page
202
+ */
203
+ public function actionLoadPageHook_General() {
204
+ // Add metaboxes
205
+ add_meta_box('avhecBoxOptions',
206
+ __('Options', 'avh-ec'),
207
+ array($this, 'metaboxOptions'),
208
+ $this->hooks['menu_general'],
209
+ 'normal',
210
+ 'core');
211
+
212
+ add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
213
+
214
+ // WordPress core Scripts
215
+ wp_enqueue_script('common');
216
+ wp_enqueue_script('wp-lists');
217
+ wp_enqueue_script('postbox');
218
+
219
+ // Plugin Style and Scripts
220
+ wp_enqueue_style('avhec-admin-css');
221
+ }
222
+
223
+ /**
224
+ * Setup everything needed for the Manul Order page
225
+ */
226
+ public function actionLoadPageHook_ManualOrder() {
227
+ add_meta_box('avhecBoxManualOrder',
228
+ __('Manually Order Categories', 'avh-ec'),
229
+ array($this, 'metaboxManualOrder'),
230
+ $this->hooks['menu_manual_order'],
231
+ 'normal',
232
+ 'core');
233
+
234
+ add_screen_option('layout_columns', array('max' => 1, 'default' => 1));
235
+
236
+ // WordPress core Styles and Scripts
237
+ wp_enqueue_script('common');
238
+ wp_enqueue_script('wp-lists');
239
+ wp_enqueue_script('postbox');
240
+ wp_enqueue_script('jquery-ui-sortable');
241
+ wp_enqueue_script('avhec-manualorder');
242
+
243
+ // Plugin Style
244
+ wp_enqueue_style('avhec-admin-css');
245
+ }
246
+
247
+ /**
248
+ * Setup everything needed for the Overview page
249
+ */
250
+ public function actionLoadPageHook_Overview() {
251
+ // Add metaboxes
252
+ add_meta_box('avhecBoxCategoryGroupList',
253
+ __('Group Overview', 'avh-ec'),
254
+ array($this, 'metaboxCategoryGroupList'),
255
+ $this->hooks['menu_overview'],
256
+ 'normal',
257
+ 'core');
258
+ add_meta_box('avhecBoxTranslation',
259
+ __('Translation', 'avh-ec'),
260
+ array($this, 'metaboxTranslation'),
261
+ $this->hooks['menu_overview'],
262
+ 'normal',
263
+ 'core');
264
+
265
+ add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
266
+
267
+ // WordPress core Scripts
268
+ wp_enqueue_script('common');
269
+ wp_enqueue_script('wp-lists');
270
+ wp_enqueue_script('postbox');
271
+
272
+ // Plugin Scripts
273
+ wp_enqueue_script('avhec-categorygroup-js');
274
+
275
+ // Plugin Style
276
+ wp_enqueue_style('avhec-admin-css');
277
+ }
278
+
279
+ /**
280
+ * Setup everything needed for the FAQ page
281
+ */
282
+ public function actionLoadPageHook_faq() {
283
+ add_meta_box('avhecBoxFAQ',
284
+ __('F.A.Q.', 'avh-ec'),
285
+ array($this, 'metaboxFAQ'),
286
+ $this->hooks['menu_faq'],
287
+ 'normal',
288
+ 'core');
289
+ add_meta_box('avhecBoxTranslation',
290
+ __('Translation', 'avh-ec'),
291
+ array($this, 'metaboxTranslation'),
292
+ $this->hooks['menu_faq'],
293
+ 'normal',
294
+ 'core');
295
+
296
+ add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
297
+
298
+ // WordPress core Styles and Scripts
299
+ wp_enqueue_script('common');
300
+ wp_enqueue_script('wp-lists');
301
+ wp_enqueue_script('postbox');
302
+
303
+ // Plugin Style
304
+ wp_enqueue_style('avhec-admin-css');
305
+ }
306
+
307
+ /**
308
+ * Enqueues the style on the post.php and page.php pages
309
+ *
310
+ * @WordPress Action load-$pagenow
311
+ */
312
+ public function actionLoadPostPage() {
313
+ wp_enqueue_style('avhec-admin-css');
314
+ }
315
+
316
+ /**
317
+ * Ajax Helper: inline delete of the groups
318
+ */
319
+ public function ajaxDeleteGroup() {
320
+ $group_id = isset($_POST['id']) ? (int) $_POST['id'] : 0;
321
+ check_ajax_referer('delete-avhecgroup_' . $group_id);
322
+
323
+ if ( ! current_user_can('manage_categories')) {
324
+ die('-1');
325
+ }
326
+ $check = $this->catgrp->getGroup($group_id);
327
+ if (false === $check) {
328
+ die('1');
329
+ }
330
+
331
+ if ($this->catgrp->doDeleteGroup($group_id)) {
332
+ die('1');
333
+ } else {
334
+ die('0');
335
+ }
336
+ }
337
+
338
+ /**
339
+ * Adds Category Group form
340
+ *
341
+ * @WordPress action category_edit_form
342
+ *
343
+ * @param unknown_type $term
344
+ * @param unknown_type $taxonomy
345
+ */
346
+ public function displayCategoryGroupForm($term, $taxonomy) {
347
+ $current_selection = '';
348
+ $tax_meta = get_option($this->core->db_options_tax_meta);
349
+ if (isset($tax_meta[ $taxonomy ][ $term->term_id ])) {
350
+ $tax_meta = $tax_meta[ $taxonomy ][ $term->term_id ];
351
+ $current_selection = $tax_meta['category_group_term_id'];
352
+ }
353
+
354
+ if (empty($current_selection)) {
355
+ $current_group = $this->catgrp->getGroupByCategoryID($term->term_id);
356
+ $current_selection = $current_group->term_id;
357
+ }
358
+
359
+ $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false));
360
+ foreach ($cat_groups as $group) {
361
+ $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit');
362
+ $dropdown_value[] = $group->term_id;
363
+ $dropdown_text[] = $temp_cat->name;
364
+ }
365
+
366
+ $seldata = '';
367
+ foreach ($dropdown_value as $key => $sel) {
368
+ $seldata .= '<option value="' .
369
+ esc_attr($sel) .
370
+ '" ' .
371
+ (($current_selection == $sel) ? 'selected="selected"' : '') .
372
+ ' >' .
373
+ esc_html(ucfirst($dropdown_text[ $key ])) .
374
+ '</option>' .
375
+ "\n";
376
+ }
377
+
378
+ echo '<h3>AVH Extended Categories - Category Group Widget</h3>';
379
+ echo '<table class="form-table"><tbody>';
380
+ echo '<tr class="form-field">';
381
+ echo '<th valign="top" scope="row">';
382
+ echo '<label for="avhec_categorygroup">Category Group</label></th>';
383
+ echo '<td>';
384
+ echo '<select id="avhec_categorygroup" name="avhec_categorygroup">';
385
+ echo $seldata;
386
+ echo '</select>';
387
+ echo '<p class="description">Select the category group to show on the archive page.</p>';
388
+ echo '</td>';
389
+ echo '</tr>';
390
+ echo '</tbody></table>';
391
+ }
392
+
393
+ /**
394
+ * Displays the icon on the menu pages
395
+ *
396
+ * @param
397
+ * $icon
398
+ */
399
+ public function displayIcon($icon) {
400
+ return ('<div class="icon32" id="icon-' . $icon . '"><br/></div>');
401
+ }
402
+
403
+ /**
404
+ * Display WP alert
405
+ */
406
+ public function displayMessage() {
407
+ if ($this->message != '') {
408
+ $message = $this->message;
409
+ $status = $this->status;
410
+ $this->message = $this->status = ''; // Reset
411
+ }
412
+ if (isset($message)) {
413
+ $status = ($status != '') ? $status : 'updated fade';
414
+ echo '<div id="message" class="' . $status . '">';
415
+ echo '<p><strong>' . $message . '</strong></p></div>';
416
+ }
417
+ }
418
+
419
+ /**
420
+ * Menu Page Category Group
421
+ *
422
+ * @return none
423
+ */
424
+ public function doMenuCategoryGroup() {
425
+ global $screen_layout_columns;
426
+
427
+ $data_add_group_default = array('name' => '', 'slug' => '', 'widget_title' => '', 'description' => '');
428
+ $data_add_group_new = $data_add_group_default;
429
+
430
+ $options_add_group[] = array(
431
+ 'avhec_add_group[add][name]',
432
+ __('Group Name', 'avh-ec'),
433
+ 'text',
434
+ 20,
435
+ __('The name is used to identify the group.', 'avh-ec')
436
+ );
437
+ $options_add_group[] = array(
438
+ 'avhec_add_group[add][slug]',
439
+ __('Slug Group', 'avh-ec'),
440
+ 'text',
441
+ 20,
442
+ __('The “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.',
443
+ 'avh-ec')
444
+ );
445
+ $options_add_group[] = array(
446
+ 'avhec_add_group[add][widget_title]',
447
+ __('Widget Title', 'avh-ec'),
448
+ 'text',
449
+ 20,
450
+ __('When no title is given in the widget options, this will used as the title of the widget when this group is shown.',
451
+ 'avh-ec')
452
+ );
453
+ $options_add_group[] = array(
454
+ 'avhec_add_group[add][description]',
455
+ __('Description', 'avh-ec'),
456
+ 'textarea',
457
+ 40,
458
+ __('Description is not prominent by default.', 'avh-ec'),
459
+ 5
460
+ );
461
+
462
+ $options_edit_group[] = array(
463
+ 'avhec_edit_group[edit][name]',
464
+ __('Group Name', 'avh-ec'),
465
+ 'text',
466
+ 20,
467
+ __('The name is used to identify the group.', 'avh-ec')
468
+ );
469
+ $options_edit_group[] = array(
470
+ 'avhec_edit_group[edit][slug]',
471
+ __('Slug Group', 'avh-ec'),
472
+ 'text',
473
+ 20,
474
+ __('The “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.',
475
+ 'avh-ec')
476
+ );
477
+ $options_edit_group[] = array(
478
+ 'avhec_edit_group[edit][widget_title]',
479
+ __('Widget Title', 'avh-ec'),
480
+ 'text',
481
+ 20,
482
+ __('When no title is given in the widget options, this will used as the title of the widget when this group is shown.',
483
+ 'avh-ec')
484
+ );
485
+ $options_edit_group[] = array(
486
+ 'avhec_edit_group[edit][description]',
487
+ __('Description', 'avh-ec'),
488
+ 'textarea',
489
+ 40,
490
+ __('Description is not prominent by default.', 'avh-ec'),
491
+ 5
492
+ );
493
+ $options_edit_group[] = array(
494
+ 'avhec_edit_group[edit][categories]',
495
+ __('Categories', 'avh-ec'),
496
+ 'catlist',
497
+ 0,
498
+ __('Select categories to be included in the group.', 'avh-ec')
499
+ );
500
+
501
+ if (isset($_POST['addgroup'])) {
502
+ check_admin_referer('avh_ec_addgroup');
503
+
504
+ $formoptions = $_POST['avhec_add_group'];
505
+
506
+ $data_add_group_new['name'] = $formoptions['add']['name'];
507
+ $data_add_group_new['slug'] = empty($formoptions['add']['slug']) ? sanitize_title($data_add_group_new['name']) : sanitize_title($formoptions['add']['slug']);
508
+ $data_add_group_new['widget_title'] = $formoptions['add']['widget_title'];
509
+ $data_add_group_new['description'] = $formoptions['add']['description'];
510
+
511
+ $id = $this->catgrp->getTermIDBy('slug', $data_add_group_new['slug']);
512
+ if ( ! $id) {
513
+ $group_id = $this->catgrp->doInsertGroup($data_add_group_new['name'],
514
+ array(
515
+ 'description' => $data_add_group_new['description'],
516
+ 'slug' => $data_add_group_new['slug']
517
+ ),
518
+ $data_add_group_new['widget_title']);
519
+ $this->catgrp->setCategoriesForGroup($group_id);
520
+ $this->message = __('Category group saved', 'avh-ec');
521
+ $this->status = 'updated fade';
522
+ $data_add_group_new = $data_add_group_default;
523
+ } else {
524
+ $group = $this->catgrp->getGroup($id);
525
+ $this->message = __('Category group conflicts with ', 'avh-ec') . $group->name;
526
+ $this->message .= '<br />' . __('Same slug is used. ', 'avh-ec');
527
+ $this->status = 'error';
528
+ }
529
+ $this->displayMessage();
530
+ }
531
+ $data_add_group['add'] = $data_add_group_new;
532
+ $data['add'] = array('form' => $options_add_group, 'data' => $data_add_group);
533
+
534
+ if (isset($_GET['action'])) {
535
+ $action = $_GET['action'];
536
+
537
+ switch ($action) {
538
+ case 'edit':
539
+ $group_id = (int) $_GET['group_ID'];
540
+ $group = $this->catgrp->getGroup($group_id);
541
+ $widget_title = $this->catgrp->getWidgetTitleForGroup($group_id);
542
+ $cats = $this->catgrp->getCategoriesFromGroup($group_id);
543
+
544
+ $data_edit_group['edit'] = array(
545
+ 'group_id' => $group_id,
546
+ 'name' => $group->name,
547
+ 'slug' => $group->slug,
548
+ 'widget_title' => $widget_title,
549
+ 'description' => $group->description,
550
+ 'categories' => $cats
551
+ );
552
+ $data['edit'] = array('form' => $options_edit_group, 'data' => $data_edit_group);
553
+
554
+ add_meta_box('avhecBoxCategoryGroupEdit',
555
+ __('Edit Group', 'avh-ec') . ': ' . $group->name,
556
+ array($this, 'metaboxCategoryGroupEdit'),
557
+ $this->hooks['menu_category_groups'],
558
+ 'normal',
559
+ 'low');
560
+ break;
561
+ case 'delete':
562
+ if ( ! isset($_GET['group_ID'])) {
563
+ wp_redirect($this->getBackLink());
564
+ exit();
565
+ }
566
+
567
+ $group_id = (int) $_GET['group_ID'];
568
+ check_admin_referer('delete-avhecgroup_' . $group_id);
569
+
570
+ if ( ! current_user_can('manage_categories')) {
571
+ wp_die(__('Cheatin&#8217; uh?'));
572
+ }
573
+ $this->catgrp->doDeleteGroup($group_id);
574
+ break;
575
+ default:
576
+ ;
577
+ break;
578
+ }
579
+ }
580
+
581
+ if (isset($_POST['editgroup'])) {
582
+ check_admin_referer('avh_ec_editgroup');
583
+
584
+ $formoptions = $_POST['avhec_edit_group'];
585
+ $selected_categories = $_POST['post_category'];
586
+
587
+ $group_id = (int) $_POST['avhec-group_id'];
588
+ $result = $this->catgrp->doUpdateGroup($group_id,
589
+ array(
590
+ 'name' => $formoptions['edit']['name'],
591
+ 'slug' => $formoptions['edit']['slug'],
592
+ 'description' => $formoptions['edit']['description']
593
+ ),
594
+ $selected_categories,
595
+ $formoptions['edit']['widget_title']);
596
+ switch ($result) {
597
+ case 1:
598
+ $this->message = __('Category group updated', 'avh-ec');
599
+ $this->status = 'updated fade';
600
+ break;
601
+ case 0:
602
+ $this->message = __('Category group not updated', 'avh-ec');
603
+ $this->message .= '<br />' . __('Duplicate slug detected', 'avh-ec');
604
+ $this->status = 'error';
605
+ break;
606
+ case - 1:
607
+ $this->message = __('Unknown category group', 'avh-ec');
608
+ $this->status = 'error';
609
+ break;
610
+ }
611
+ $this->displayMessage();
612
+ }
613
+
614
+ $hide2 = '';
615
+ switch ($screen_layout_columns) {
616
+ case 2:
617
+ $width = 'width:49%;';
618
+ break;
619
+ default:
620
+ $width = 'width:98%;';
621
+ $hide2 = 'display:none;';
622
+ }
623
+
624
+ $data_special_pages_old = $this->core->options['sp_cat_group'];
625
+ $data_special_pages_new = $data_special_pages_old;
626
+ if (isset($_POST['avhec_special_pages'])) {
627
+ check_admin_referer('avh_ec_specialpagesgroup');
628
+
629
+ $formoptions = $_POST['avhec_special_pages'];
630
+ $formdata = $formoptions['sp'];
631
+ foreach ($formdata as $key => $value) {
632
+ $data_special_pages_new[ $key ] = $value;
633
+ }
634
+ $this->core->options['sp_cat_group'] = $data_special_pages_new;
635
+ $this->core->saveOptions($this->core->options);
636
+ }
637
+ $data_special_pages['sp'] = $data_special_pages_new;
638
+ $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false));
639
+
640
+ foreach ($cat_groups as $group) {
641
+ $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit');
642
+ $dropdown_value[] = $group->term_id;
643
+ $dropdown_text[] = $temp_cat->name;
644
+ }
645
+ $options_special_pages[] = array(
646
+ 'avhec_special_pages[sp][home_group]',
647
+ __('Home page', 'avh-ec'),
648
+ 'dropdown',
649
+ $dropdown_value,
650
+ $dropdown_text,
651
+ sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('home', 'avhec'))
652
+ );
653
+ // $options_special_pages[] = array('avhec_special_pages[sp][category_group]', __('Category Archive', 'avh-ec'), 'dropdown', $dropdown_value, $dropdown_text, sprintf(__('Select which category to show on the %s page.','avh-ec'),__('category archive','avhec')));
654
+ $options_special_pages[] = array(
655
+ 'avhec_special_pages[sp][day_group]',
656
+ __('Daily Archive', 'avh-ec'),
657
+ 'dropdown',
658
+ $dropdown_value,
659
+ $dropdown_text,
660
+ sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('daily archive', 'avhec'))
661
+ );
662
+ $options_special_pages[] = array(
663
+ 'avhec_special_pages[sp][month_group]',
664
+ __('Monthly Archive', 'avh-ec'),
665
+ 'dropdown',
666
+ $dropdown_value,
667
+ $dropdown_text,
668
+ sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('monthly archive', 'avhec'))
669
+ );
670
+ $options_special_pages[] = array(
671
+ 'avhec_special_pages[sp][year_group]',
672
+ __('Yearly Archive', 'avh-ec'),
673
+ 'dropdown',
674
+ $dropdown_value,
675
+ $dropdown_text,
676
+ sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('yearly archive', 'avhec'))
677
+ );
678
+ $options_special_pages[] = array(
679
+ 'avhec_special_pages[sp][author_group]',
680
+ __('Author Archive', 'avh-ec'),
681
+ 'dropdown',
682
+ $dropdown_value,
683
+ $dropdown_text,
684
+ sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('author archive', 'avhec'))
685
+ );
686
+ $options_special_pages[] = array(
687
+ 'avhec_special_pages[sp][search_group]',
688
+ __('Search Page', 'avh-ec'),
689
+ 'dropdown',
690
+ $dropdown_value,
691
+ $dropdown_text,
692
+ sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('search', 'avhec'))
693
+ );
694
+
695
+ $data['sp'] = array('form' => $options_special_pages, 'data' => $data_special_pages);
696
+
697
+ // This box can't be unselectd in the the Screen Options
698
+ // add_meta_box( 'avhecBoxDonations', __( 'Donations', 'avh-ec' ), array ($this, 'metaboxDonations' ), $this->hooks['menu_category_groups'], 'side', 'core' );
699
+
700
+ echo '<div class="wrap avhec-metabox-wrap">';
701
+ echo $this->displayIcon('index');
702
+ echo '<h2>' . 'AVH Extended Categories - ' . __('Category Groups', 'avh-ec') . '</h2>';
703
+
704
+ echo ' <div id="dashboard-widgets-wrap">';
705
+ echo ' <div id="dashboard-widgets" class="metabox-holder">';
706
+
707
+ echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
708
+ do_meta_boxes($this->hooks['menu_category_groups'], 'normal', $data);
709
+ echo " </div>";
710
+
711
+ echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n";
712
+ do_meta_boxes($this->hooks['menu_category_groups'], 'side', $data);
713
+ echo ' </div>';
714
+
715
+ echo ' </div>'; // dashboard-widgets
716
+ echo '<br class="clear" />';
717
+ echo ' </div>'; // dashboard-widgets-wrap
718
+ echo '</div>'; // wrap
719
+
720
+ $this->printMetaboxGeneralNonces();
721
+ $this->printMetaboxJS('grouped');
722
+ $this->printAdminFooter();
723
+ }
724
+
725
+ /**
726
+ * Menu Page FAQ
727
+ *
728
+ * @return none
729
+ */
730
+ public function doMenuFAQ() {
731
+ global $screen_layout_columns;
732
+
733
+ // This box can't be unselectd in the the Screen Options
734
+ // add_meta_box('avhecBoxAnnouncements', __('Announcements', 'avh-ec'), array ( $this, 'metaboxAnnouncements' ), $this->hooks['menu_faq'], 'side', 'core');
735
+ add_meta_box('avhecBoxDonations',
736
+ __('Donations', 'avh-ec'),
737
+ array($this, 'metaboxDonations'),
738
+ $this->hooks['menu_faq'],
739
+ 'side',
740
+ 'core');
741
+
742
+ $hide2 = '';
743
+ switch ($screen_layout_columns) {
744
+ case 2:
745
+ $width = 'width:49%;';
746
+ break;
747
+ default:
748
+ $width = 'width:98%;';
749
+ $hide2 = 'display:none;';
750
+ }
751
+
752
+ echo '<div class="wrap avhec-metabox-wrap">';
753
+ echo $this->displayIcon('index');
754
+ echo '<h2>' . 'AVH Extended Categories - ' . __('F.A.Q', 'avh-ec') . '</h2>';
755
+ echo ' <div id="dashboard-widgets-wrap">';
756
+ echo ' <div id="dashboard-widgets" class="metabox-holder">';
757
+ echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
758
+ do_meta_boxes($this->hooks['menu_faq'], 'normal', '');
759
+ echo ' </div>';
760
+ echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n";
761
+ do_meta_boxes($this->hooks['menu_faq'], 'side', '');
762
+ echo ' </div>';
763
+ echo ' </div>';
764
+ echo '<br class="clear"/>';
765
+ echo ' </div>'; // dashboard-widgets-wrap
766
+ echo '</div>'; // wrap
767
+
768
+ $this->printMetaboxGeneralNonces();
769
+ $this->printMetaboxJS('faq');
770
+ $this->printAdminFooter();
771
+ }
772
+
773
+ /**
774
+ * Menu Page General Options
775
+ *
776
+ * @return none
777
+ */
778
+ public function doMenuGeneral() {
779
+ global $screen_layout_columns;
780
+
781
+ $groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false));
782
+ foreach ($groups as $group) {
783
+ $group_id[] = $group->term_id;
784
+ $groupname[] = $group->name;
785
+ }
786
+
787
+ $options_general[] = array(
788
+ 'avhec[general][alternative_name_select_category]',
789
+ __('<em>Select Category</em> Alternative', 'avh-ec'),
790
+ 'text',
791
+ 20,
792
+ __('Alternative text for Select Category.', 'avh-ec')
793
+ );
794
+ $options_general[] = array(
795
+ 'avhec[cat_group][home_group]',
796
+ 'Home Group',
797
+ 'dropdown',
798
+ $group_id,
799
+ $groupname,
800
+ __('Select which group to show on the home page.', 'avh-ec') .
801
+ '<br />' .
802
+ __('Selecting the group \'none\' will not show the widget on the page.', 'avh-ec')
803
+ );
804
+ $options_general[] = array(
805
+ 'avhec[cat_group][no_group]',
806
+ 'Nonexistence Group',
807
+ 'dropdown',
808
+ $group_id,
809
+ $groupname,
810
+ __('Select which group to show when there is no group associated with the post.', 'avh-ec') .
811
+ '<br />' .
812
+ __('Selecting the group \'none\' will not show the widget on the page.', 'avh-ec')
813
+ );
814
+ $options_general[] = array(
815
+ 'avhec[cat_group][default_group]',
816
+ 'Default Group',
817
+ 'dropdown',
818
+ $group_id,
819
+ $groupname,
820
+ __('Select which group will be the default group when editing a post.', 'avh-ec') .
821
+ '<br />' .
822
+ __('Selecting the group \'none\' will not show the widget on the page.', 'avh-ec')
823
+ );
824
+
825
+ if (isset($_POST['updateoptions'])) {
826
+ check_admin_referer('avh_ec_generaloptions');
827
+
828
+ $formoptions = $_POST['avhec'];
829
+ $options = $this->core->getOptions();
830
+
831
+ // $all_data = array_merge( $options_general );
832
+ $all_data = $options_general;
833
+ foreach ($all_data as $option) {
834
+ $section = substr($option[0], strpos($option[0], '[') + 1);
835
+ $section = substr($section, 0, strpos($section, ']['));
836
+ $option_key = rtrim($option[0], ']');
837
+ $option_key = substr($option_key, strpos($option_key, '][') + 2);
838
+
839
+ switch ($section) {
840
+ case 'general':
841
+ case 'cat_group':
842
+ $current_value = $options[ $section ][ $option_key ];
843
+ break;
844
+ }
845
+ // Every field in a form is set except unchecked checkboxes. Set an unchecked checkbox to 0.
846
+ $newval = (isset($formoptions[ $section ][ $option_key ]) ? esc_attr($formoptions[ $section ][ $option_key ]) : 0);
847
+ if ($newval != $current_value) { // Only process changed fields.
848
+ switch ($section) {
849
+ case 'general':
850
+ case 'cat_group':
851
+ $options[ $section ][ $option_key ] = $newval;
852
+ break;
853
+ }
854
+ }
855
+ }
856
+ $this->core->saveOptions($options);
857
+ $this->message = __('Options saved', 'avh-ec');
858
+ $this->status = 'updated fade';
859
+ }
860
+ $this->displayMessage();
861
+
862
+ $actual_options = $this->core->getOptions();
863
+ foreach ($actual_options['cat_group'] as $key => $value) {
864
+ if ( ! (in_array($value, (array) $group_id))) {
865
+ $actual_options['cat_group'][ $key ] = $this->catgrp->getTermIDBy('slug', 'none');
866
+ }
867
+ }
868
+
869
+ $hide2 = '';
870
+ switch ($screen_layout_columns) {
871
+ case 2:
872
+ $width = 'width:49%;';
873
+ break;
874
+ default:
875
+ $width = 'width:98%;';
876
+ $hide2 = 'display:none;';
877
+ }
878
+ $data['options_general'] = $options_general;
879
+ $data['actual_options'] = $actual_options;
880
+
881
+ // This box can't be unselectd in the the Screen Options
882
+ add_meta_box('avhecBoxDonations',
883
+ __('Donations', 'avh-ec'),
884
+ array($this, 'metaboxDonations'),
885
+ $this->hooks['menu_general'],
886
+ 'side',
887
+ 'core');
888
+
889
+ $hide2 = '';
890
+ switch ($screen_layout_columns) {
891
+ case 2:
892
+ $width = 'width:49%;';
893
+ break;
894
+ default:
895
+ $width = 'width:98%;';
896
+ $hide2 = 'display:none;';
897
+ }
898
+
899
+ echo '<div class="wrap avhec-metabox-wrap">';
900
+ echo $this->displayIcon('index');
901
+ echo '<h2>' . 'AVH Extended Categories - ' . __('General Options', 'avh-ec') . '</h2>';
902
+ echo '<form name="avhec-generaloptions" id="avhec-generaloptions" method="POST" action="' .
903
+ admin_url('admin.php?page=avhec-general') .
904
+ '" accept-charset="utf-8" >';
905
+ wp_nonce_field('avh_ec_generaloptions');
906
+
907
+ echo ' <div id="dashboard-widgets-wrap">';
908
+ echo ' <div id="dashboard-widgets" class="metabox-holder">';
909
+ echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
910
+ do_meta_boxes($this->hooks['menu_general'], 'normal', $data);
911
+ echo " </div>";
912
+ echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n";
913
+ do_meta_boxes($this->hooks['menu_general'], 'side', $data);
914
+ echo ' </div>';
915
+ echo ' </div>';
916
+
917
+ echo '<br class="clear"/>';
918
+ echo ' </div>'; // dashboard-widgets-wrap
919
+ echo '<p class="submit"><input class="button" type="submit" name="updateoptions" value="' .
920
+ __('Save Changes', 'avhf-ec') .
921
+ '" /></p>';
922
+ echo '</form>';
923
+
924
+ echo '</div>'; // wrap
925
+
926
+ $this->printMetaboxGeneralNonces();
927
+ $this->printMetaboxJS('general');
928
+ $this->printAdminFooter();
929
+ }
930
+
931
+ /**
932
+ * Menu Page Manual Order
933
+ *
934
+ * @return none
935
+ */
936
+ public function doMenuManualOrder() {
937
+ global $screen_layout_columns;
938
+
939
+ $hide2 = '';
940
+ switch ($screen_layout_columns) {
941
+ case 2:
942
+ $width = 'width:49%;';
943
+ break;
944
+ default:
945
+ $width = 'width:98%;';
946
+ $hide2 = 'display:none;';
947
+ }
948
+
949
+ echo '<div class="wrap">';
950
+ echo $this->displayIcon('index');
951
+ echo '<h2>' . 'AVH Extended Categories - ' . __('Manually Order Categories', 'avh-ec') . '</h2>';
952
+
953
+ echo '<div class="metabox-holder">';
954
+ echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
955
+ do_meta_boxes($this->hooks['menu_manual_order'], 'normal', '');
956
+ echo ' </div>';
957
+ echo '</div>';
958
+ echo '</div>'; // wrap
959
+ echo '<div class="clear"></div>';
960
+
961
+ $this->printMetaboxGeneralNonces();
962
+ $this->printMetaboxJS('manual_order');
963
+ $this->printAdminFooter();
964
+ }
965
+
966
+ /**
967
+ * Menu Page Overview
968
+ *
969
+ * @return none
970
+ */
971
+ public function doMenuOverview() {
972
+ global $screen_layout_columns;
973
+
974
+ // This box can't be unselectd in the the Screen Options
975
+ // add_meta_box('avhecBoxAnnouncements', __('Announcements', 'avh-ec'), array ( $this, 'metaboxAnnouncements' ), $this->hooks['menu_overview'], 'side', '');
976
+ add_meta_box('avhecBoxDonations',
977
+ __('Donations', 'avh-ec'),
978
+ array($this, 'metaboxDonations'),
979
+ $this->hooks['menu_overview'],
980
+ 'side',
981
+ '');
982
+
983
+ $hide2 = '';
984
+ switch ($screen_layout_columns) {
985
+ case 2:
986
+ $width = 'width:49%;';
987
+ break;
988
+ default:
989
+ $width = 'width:98%;';
990
+ $hide2 = 'display:none;';
991
+ }
992
+
993
+ echo '<div class="wrap avhec-metabox-wrap">';
994
+ echo $this->displayIcon('index');
995
+ echo '<h2>' . 'AVH Extended Categories - ' . __('Overview', 'avh-ec') . '</h2>';
996
+ echo ' <div id="dashboard-widgets-wrap">';
997
+ echo ' <div id="dashboard-widgets" class="metabox-holder">';
998
+ echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
999
+ do_meta_boxes($this->hooks['menu_overview'], 'normal', '');
1000
+ echo " </div>";
1001
+ echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n";
1002
+ do_meta_boxes($this->hooks['menu_overview'], 'side', '');
1003
+ echo ' </div>';
1004
+ echo ' </div>';
1005
+
1006
+ echo '<br class="clear"/>';
1007
+ echo ' </div>'; // dashboard-widgets-wrap
1008
+ echo '</div>'; // wrap
1009
+
1010
+ $this->printMetaboxGeneralNonces();
1011
+ $this->printMetaboxJS('overview');
1012
+ $this->printAdminFooter();
1013
+ }
1014
+
1015
+ /**
1016
+ * When not using AJAX, this function is called when the deletion fails.
1017
+ *
1018
+ * @param string $text
1019
+ * @param int $group_id
1020
+ *
1021
+ * @return string @WordPress Filter explain_nonce_$verb-$noun
1022
+ * @see wp_explain_nonce
1023
+ */
1024
+ public function filterExplainNonceDeleteGroup($text, $group_id) {
1025
+ $group = get_term($group_id, $this->catgrp->taxonomy_name, OBJECT, 'display');
1026
+
1027
+ $return = sprintf(__('Your attempt to delete this group: &#8220;%s&#8221; has failed.'), $group->name);
1028
+
1029
+ return ($return);
1030
+ }
1031
+
1032
+ /**
1033
+ * Creates a new array for columns headers.
1034
+ * Used in print_column_headers. The filter is called from get_column_headers
1035
+ *
1036
+ * @param
1037
+ * $columns
1038
+ *
1039
+ * @return Array
1040
+ * @see print_column_headers, get_column_headers
1041
+ */
1042
+ public function filterManageCategoriesGroupColumns($columns) {
1043
+ $categories_group_columns = array(
1044
+ 'name' => __('Name', 'avh-ec'),
1045
+ 'slug' => __('Slug', 'avh-ec'),
1046
+ 'widget-title' => __('Widget Title', 'avh-ec'),
1047
+ 'description' => __('Description', 'avh-ec'),
1048
+ 'cat-in-group' => __('Categories in the group', 'avh-ec')
1049
+ );
1050
+
1051
+ return $categories_group_columns;
1052
+ }
1053
+
1054
+ /**
1055
+ * Adds Settings next to the plugin actions
1056
+ *
1057
+ * @WordPress Filter plugin_action_links_avh-amazon/avh-amazon.php
1058
+ */
1059
+ public function filterPluginActions($links, $file) {
1060
+ $settings_link = '<a href="admin.php?page=extended-categories-widget">' . __('Settings', 'avh-ec') . '</a>';
1061
+ array_unshift($links, $settings_link); // before other links
1062
+
1063
+ return $links;
1064
+ }
1065
+
1066
+ /**
1067
+ * Sets the amount of columns wanted for a particuler screen
1068
+ *
1069
+ * @WordPress filter screen_meta_screen
1070
+ *
1071
+ * @param
1072
+ * $screen
1073
+ *
1074
+ * @return strings
1075
+ */
1076
+ public function filterScreenLayoutColumns($columns, $screen) {
1077
+ switch ($screen) {
1078
+ case $this->hooks['menu_overview']:
1079
+ $columns[ $this->hooks['menu_overview'] ] = 2;
1080
+ break;
1081
+ case $this->hooks['menu_general']:
1082
+ $columns[ $this->hooks['menu_general'] ] = 2;
1083
+ break;
1084
+ case $this->hooks['menu_category_groups']:
1085
+ $columns[ $this->hooks['menu_category_groups'] ] = 2;
1086
+ break;
1087
+ case $this->hooks['menu_faq']:
1088
+ $columns[ $this->hooks['menu_faq'] ] = 2;
1089
+ break;
1090
+ }
1091
+
1092
+ return $columns;
1093
+ }
1094
+
1095
+ /**
1096
+ * Get the backlink for forms
1097
+ *
1098
+ * @return string
1099
+ */
1100
+ public function getBackLink() {
1101
+ $page = basename(__FILE__);
1102
+ if (isset($_GET['page']) && ! empty($_GET['page'])) {
1103
+ $page = preg_replace('[^a-zA-Z0-9\.\_\-]', '', $_GET['page']);
1104
+ }
1105
+
1106
+ if (function_exists("admin_url")) {
1107
+ return admin_url(basename($_SERVER["PHP_SELF"])) . "?page=" . $page;
1108
+ } else {
1109
+ return $_SERVER['PHP_SELF'] . "?page=" . $page;
1110
+ }
1111
+ }
1112
+
1113
+ /**
1114
+ * Saves the association Category - Category Group fron the edit taxonomy page
1115
+ *
1116
+ * @WordPress action edit_form.
1117
+ *
1118
+ * @param unknown_type $term_id
1119
+ * @param unknown_type $tt_id
1120
+ * @param unknown_type $taxonomy
1121
+ */
1122
+ public function handleEditTerm($term_id, $tt_id, $taxonomy) {
1123
+ $tax_meta = get_option($this->core->db_options_tax_meta);
1124
+ if (isset($_POST['avhec_categorygroup'])) {
1125
+ if ( ! isset($tax_meta[ $taxonomy ][ $term_id ]['category_group_term_id']) ||
1126
+ $tax_meta[ $taxonomy ][ $term_id ]['category_group_term_id'] != $_POST['avhec_categorygroup']
1127
+ ) {
1128
+ $tax_meta[ $taxonomy ][ $term_id ]['category_group_term_id'] = $_POST['avhec_categorygroup'];
1129
+ update_option($this->core->db_options_tax_meta, $tax_meta);
1130
+ }
1131
+ }
1132
+ }
1133
+
1134
+ /**
1135
+ * Used in forms to set an option checked
1136
+ *
1137
+ * @param mixed $checked
1138
+ * @param mixed $current
1139
+ *
1140
+ * @return string
1141
+ */
1142
+ public function isChecked($checked, $current) {
1143
+ $return = '';
1144
+ if ($checked == $current) {
1145
+ $return = ' checked="checked"';
1146
+ }
1147
+
1148
+ return $return;
1149
+ }
1150
+
1151
+ public function metaboxAnnouncements() {
1152
+ $php5 = version_compare('5.2', phpversion(), '<');
1153
+ echo '<div class="p">';
1154
+ echo '<span class="b">' . __('PHP4 Support', 'avh-ec') . '</span><br />';
1155
+ echo __('The next major release of the plugin will no longer support PHP4.', 'avh-ec') . '<br />';
1156
+ echo __('It will be written for PHP 5.2 and ', 'avh-ec');
1157
+ if ($php5) {
1158
+ echo __('your blog already runs the needed PHP version. When the new release comes out you can safely update.',
1159
+ 'avh-ec') . '<br />';
1160
+ } else {
1161
+ echo __('your blog still runs PHP4. When the new release comes out you can not use it.', 'avh-ec') .
1162
+ '<br />';
1163
+ echo __('I don\'t have a timeline for the next version but consider contacting your host if PHP 5.2 is available.',
1164
+ 'avh-ec') . '<br />';
1165
+ echo __('If your hosts doesn\'t offer PHP 5.2 you might want to consider switching hosts.', 'avh-ec') .
1166
+ '<br />';
1167
+ echo __('A host to consider is ', 'avh-ec') .
1168
+ '<a href="http://www.lunarpages.com/id/pdoes" target="_blank">Lunarpages</a>';
1169
+ echo __('I run my personal blog there and I am very happy with their services. You can get an account with unlimited bandwidth, storage and much more for a low price.',
1170
+ 'avh-ec');
1171
+ }
1172
+ echo '</div>';
1173
+ }
1174
+
1175
+ /**
1176
+ * Metabox for Adding a group
1177
+ *
1178
+ * @param
1179
+ * $data
1180
+ */
1181
+ public function metaboxCategoryGroupAdd($data) {
1182
+ echo '<form name="avhec-addgroup" id="avhec-addgroup" method="POST" action="' .
1183
+ $this->getBackLink() .
1184
+ '" accept-charset="utf-8" >';
1185
+ wp_nonce_field('avh_ec_addgroup');
1186
+ echo $this->printOptions($data['add']['form'], $data['add']['data']);
1187
+ echo '<p class="submit"><input class="button" type="submit" name="addgroup" value="' .
1188
+ __('Add group', 'avh-ec') .
1189
+ '" /></p>';
1190
+ echo '</form>';
1191
+ }
1192
+
1193
+ /**
1194
+ * Metabox Category Group Edit
1195
+ */
1196
+ public function metaboxCategoryGroupEdit($data) {
1197
+ echo '<form name="avhec-editgroup" id="avhec-editgroup" method="POST" action="' .
1198
+ $this->getBackLink() .
1199
+ '" accept-charset="utf-8" >';
1200
+ wp_nonce_field('avh_ec_editgroup');
1201
+ echo $this->printOptions($data['edit']['form'], $data['edit']['data']);
1202
+ echo '<input type="hidden" value="' .
1203
+ $data['edit']['data']['edit']['group_id'] .
1204
+ '" name="avhec-group_id" id="avhec-group_id">';
1205
+ echo '<p class="submit"><input class="button" type="submit" name="editgroup" value="' .
1206
+ __('Update group', 'avh-ec') .
1207
+ '" /></p>';
1208
+ echo '</form>';
1209
+ }
1210
+
1211
+ /**
1212
+ * Metabox for showing the groups as a list
1213
+ *
1214
+ * @param
1215
+ * $data
1216
+ */
1217
+ public function metaboxCategoryGroupList($data) {
1218
+ echo '<form id="posts-filter" action="" method="get">';
1219
+
1220
+ echo '<div class="clear"></div>';
1221
+
1222
+ echo '<table class="widefat fixed" cellspacing="0">';
1223
+ echo '<thead>';
1224
+ echo '<tr>';
1225
+ print_column_headers('categories_group');
1226
+ echo '</tr>';
1227
+ echo '</thead>';
1228
+
1229
+ echo '<tfoot>';
1230
+ echo '<tr>';
1231
+ print_column_headers('categories_group', false);
1232
+ echo '</tr>';
1233
+ echo '</tfoot>';
1234
+
1235
+ echo '<tbody id="the-list" class="list:group">';
1236
+ $this->printCategoryGroupRows();
1237
+ echo '</tbody>';
1238
+ echo '</table>';
1239
+
1240
+ echo '<br class="clear" />';
1241
+ echo '</form>';
1242
+ // echo '</div>';
1243
+ }
1244
+
1245
+ /**
1246
+ * Metabox Category Group Special pages
1247
+ */
1248
+ public function metaboxCategoryGroupSpecialPages($data) {
1249
+ echo '<form name="avhec-specialpagesgroup" id="avhec-specialpagesgroup" method="POST" action="' .
1250
+ $this->getBackLink() .
1251
+ '" accept-charset="utf-8" >';
1252
+ wp_nonce_field('avh_ec_specialpagesgroup');
1253
+ echo $this->printOptions($data['sp']['form'], $data['sp']['data']);
1254
+ echo '<p class="submit"><input class="button" type="submit" name="spgroup" value="' .
1255
+ __('Save settings', 'avh-ec') .
1256
+ '" /></p>';
1257
+ echo '</form>';
1258
+ }
1259
+
1260
+ // ############ Admin WP Helper ##############
1261
+
1262
+ /**
1263
+ * Donation Metabox
1264
+ *
1265
+ * @return unknown_type
1266
+ */
1267
+ public function metaboxDonations() {
1268
+ echo '<div class="p">';
1269
+ echo __('If you enjoy this plug-in please consider a donation. There are several ways you can show your appreciation.',
1270
+ 'avh-ec');
1271
+ echo '</div>';
1272
+
1273
+ echo '<div class="p">';
1274
+ echo '<span class="b">Amazon</span><br />';
1275
+ echo __('If you decide to buy something from Amazon click the button.', 'avh-ec') . '</span><br />';
1276
+ echo '<a href="https://www.amazon.com/?tag=petervanderdoes-20" target="_blank" title="Amazon Homepage"><img alt="Amazon Button" src="' .
1277
+ $this->core->info['graphics_url'] .
1278
+ '/us_banner_logow_120x60.gif" /></a>';
1279
+ echo '</div>';
1280
+
1281
+ echo '<div class="p">';
1282
+ echo __('You can send me something from my ', 'avh-ec') .
1283
+ '<a href="http://www.amazon.com/registry/wishlist/1U3DTWZ72PI7W?tag=petervanderdoes-20">' .
1284
+ __('Amazon Wish List', 'avh-ec') .
1285
+ '</a>';
1286
+ echo '</div>';
1287
+
1288
+ echo '<div class="p">';
1289
+ echo '<span class="b">' . __('Through Paypal.', 'avh-ec') . '</span><br />';
1290
+ echo __('Click on the Donate button and you will be directed to Paypal where you can make your donation and you don\'t need to have a Paypal account to make a donation.',
1291
+ 'avh-ec') . '<br />';
1292
+ echo '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=S85FXJ9EBHAF2&lc=US&item_name=AVH%20Plugins&item_number=fdas&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted" target="_blank" title="Donate">';
1293
+ echo '<img src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" alt="Donate"/></a>';
1294
+ echo '</div>';
1295
+ }
1296
+
1297
+ /**
1298
+ * *
1299
+ * F.A.Q Metabox
1300
+ *
1301
+ * @return none
1302
+ */
1303
+ public function metaboxFAQ() {
1304
+ echo '<div class="p">';
1305
+ echo '<span class="b">' . __('What about support?', 'avh-ec') . '</span><br />';
1306
+ echo __('I created a <a href="http://forums.avirtualhome.com" target="_blank">support site</a> where you can ask questions or request features.',
1307
+ 'avh-ec') . '<br />';
1308
+ echo '</div>';
1309
+
1310
+ echo '<div class="p">';
1311
+ echo '<span class="b">' . __('What is depth selection?', 'avh-ec') . '</span><br />';
1312
+ echo __('Starting with version 2.0 and WordPress 2.8 you can select how many levels deep you want to show your categories. This option only works when you select Show Hierarchy as well.',
1313
+ 'avh-ec') . '<br /><br />';
1314
+ echo __('Here is how it works: Say you have 5 top level categories and each top level has a number of children. You could manually select all the Top Level categories you want to show but now you can do the following:',
1315
+ 'avh-ec') . '<br />';
1316
+ echo __('You select to display all categories, select to Show hierarchy and select how many levels you want to show, in this case Toplevel only.',
1317
+ 'avh-ec') . '<br />';
1318
+ echo '</div>';
1319
+
1320
+ echo '<div class="p">';
1321
+ echo '<span class="b">' . __('Multiple Category Groups', 'avh-ec') . '</span><br />';
1322
+ echo __('The following is an explanation how assigning multiple groups to page/post works.', 'avh-ec') .
1323
+ '<br /><br />';
1324
+ echo __('Lets say you have the following groups:', 'avh-ec');
1325
+ echo '<ul>';
1326
+ echo '<li>' . __('Free Time', 'avh-ec') . '</li>';
1327
+ echo '<li>' . __('Theater', 'avh-ec') . '</li>';
1328
+ echo '<li>' . __('Movie', 'avh-ec') . '</li>';
1329
+ echo '<li>' . __('Music', 'avh-ec') . '</li>';
1330
+ echo '</ul>';
1331
+ echo __('Setup several Category Group widgets and associated each widget with one or more groups.', 'avh-ec') .
1332
+ '<br />';
1333
+ echo __('Widget 1 has association with Free Time', 'avh-ec') . '<br />';
1334
+ echo __('Widget 2 has association with Theater, Movie and Music', 'avh-ec') . '<br />';
1335
+ echo __('Widget 3 has association with Theater, Movie and Music', 'avh-ec') . '<br /><br />';
1336
+ echo __('Page has associations the groups Free Time and Theater', 'avh-ec');
1337
+ echo '<ul>';
1338
+ echo '<li>' . __('Widget 1: Shows categories of the Free Time group', 'avh-ec') . '</li>';
1339
+ echo '<li>' . __('Widget 2: Shows categories of the Theater group.', 'avh-ec') . '</li>';
1340
+ echo '<li>' . __('Widget 3: Not displayed', 'avh-ec') . '</li>';
1341
+ echo '</ul>';
1342
+ echo __('Page has associations the group Movie.', 'avh-ec');
1343
+ echo '<ul>';
1344
+ echo '<li>' . __('Widget 1: Not displayed', 'avh-ec') . '</li>';
1345
+ echo '<li>' . __('Widget 2: Shows categories of the Movie group.', 'avh-ec') . '</li>';
1346
+ echo '<li>' . __('Widget 3: Not displayed', 'avh-ec') . '</li>';
1347
+ echo '</ul>';
1348
+ echo __('Page has associations the groups Free Time, Movie and Music', 'avh-ec');
1349
+ echo '<ul>';
1350
+ echo '<li>' . __('Widget 1: Shows categories of the Free Time group', 'avh-ec') . '</li>';
1351
+ echo '<li>' . __('Widget 2: Shows categories of the Movie or Music group.', 'avh-ec') . '</li>';
1352
+ echo '<li>' . __('Widget 3: Shows categories of the Music or Movie group.', 'avh-ec') . '</li>';
1353
+ echo '</ul>';
1354
+ echo __('Whether Widget 2 shows Movie or Music depends on the creation order of groups. If Widget 2 shows Movie, Widget 3 will show Music but if Widget 2 shows Music, Widget 3 will show Movie.',
1355
+ 'avh-ec') . '<br />';
1356
+ echo '</div>';
1357
+ }
1358
+
1359
+ /**
1360
+ * Displays the Manual Order metabox.
1361
+ *
1362
+ * @author Andrew Charlton - original
1363
+ * @author Peter van der Does - modifications
1364
+ */
1365
+ public function metaboxManualOrder() {
1366
+ global $wpdb;
1367
+
1368
+ $parentID = 0;
1369
+
1370
+ if (isset($_POST['btnSubCats'])) {
1371
+ $parentID = $_POST['cats'];
1372
+ } elseif (isset($_POST['hdnParentID'])) {
1373
+ $parentID = $_POST['hdnParentID'];
1374
+ }
1375
+
1376
+ if (isset($_POST['btnReturnParent'])) {
1377
+ $parentsParent = $wpdb->get_row($wpdb->prepare("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = %d",
1378
+ $_POST['hdnParentID']),
1379
+ ARRAY_N);
1380
+ $parentID = $parentsParent[0];
1381
+ }
1382
+
1383
+ $success = "";
1384
+ if (isset($_POST['btnOrderCats'])) {
1385
+ if (isset($_POST['hdnManualOrder']) && $_POST['hdnManualOrder'] != "") {
1386
+
1387
+ $manualOrder = $_POST['hdnManualOrder'];
1388
+ $IDs = explode(",", $manualOrder);
1389
+ $result = count($IDs);
1390
+
1391
+ for ($i = 0; $i < $result; $i ++) {
1392
+ $str = str_replace("id_", "", $IDs[ $i ]);
1393
+ $wpdb->query($wpdb->prepare("UPDATE $wpdb->terms SET avhec_term_order = %d WHERE term_id =%d",
1394
+ $i,
1395
+ $str));
1396
+ }
1397
+
1398
+ $success = '<div id="message" class="updated fade"><p>' .
1399
+ __('Manual order of the categories successfully updated.', 'avh-ec') .
1400
+ '</p></div>';
1401
+ } else {
1402
+ $success = '<div id="message" class="updated fade"><p>' .
1403
+ __('An error occured, order has not been saved.', 'avh-ec') .
1404
+ '</p></div>';
1405
+ }
1406
+ }
1407
+
1408
+ $subCategories = "";
1409
+ $results = $wpdb->get_results($wpdb->prepare("SELECT t.term_id, t.name FROM $wpdb->term_taxonomy tt, $wpdb->terms t, $wpdb->term_taxonomy tt2 WHERE tt.parent = %d AND tt.taxonomy = 'category' AND t.term_id = tt.term_id AND tt2.parent = tt.term_id GROUP BY t.term_id, t.name HAVING COUNT(*) > 0 ORDER BY t.avhec_term_order ASC",
1410
+ $parentID));
1411
+ foreach ($results as $row) {
1412
+ $subCategories .= "<option value='$row->term_id'>$row->name</option>";
1413
+ }
1414
+
1415
+ echo '<div class="wrap">';
1416
+ echo '<form name="frmMyCatOrder" method="post" action="">';
1417
+ echo $success;
1418
+
1419
+ echo '<h4>';
1420
+ _e('Order the categories', 'avh-ec');
1421
+ if ($parentID == 0) {
1422
+ echo ' at the Toplevel';
1423
+ } else {
1424
+ $categories = get_category_parents($parentID, false, ' » ');
1425
+ echo ' in the category ' . trim($categories, ' » ');
1426
+ }
1427
+ echo '</h4>';
1428
+ echo '<span class="description">';
1429
+ _e('Order the categories on this level by dragging and dropping them into the desired order.', 'avh-ec');
1430
+ echo '</span>';
1431
+ echo '<ul id="avhecManualOrder">';
1432
+ $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->terms t inner join $wpdb->term_taxonomy tt on t.term_id = tt.term_id WHERE taxonomy = 'category' and parent = %d ORDER BY avhec_term_order ASC",
1433
+ $parentID));
1434
+ foreach ($results as $row) {
1435
+ echo "<li id='id_$row->term_id' class='lineitem menu-item-settings'>" . __($row->name) . "</li>";
1436
+ }
1437
+ echo '</ul>';
1438
+ echo '<input type="submit" name="btnOrderCats" id="btnOrderCats" class="button-primary" value="' .
1439
+ __('Save Order', 'avh-ec') .
1440
+ '" onclick="javascript:orderCats(); return true;" />';
1441
+
1442
+ if ($parentID != 0) {
1443
+ echo "<input type='submit' class='button' id='btnReturnParent' name='btnReturnParent' value='" .
1444
+ __('Return to parent category', 'avh-ec') .
1445
+ "' />";
1446
+ }
1447
+
1448
+ echo '<strong id="updateText"></strong><br /><br />';
1449
+ if ($subCategories != "") {
1450
+
1451
+ echo '<h4>';
1452
+ _e('Select Subcategory', 'avh-ec');
1453
+ echo '</h4>';
1454
+ echo '<select id="cats" name="cats">';
1455
+ echo $subCategories;
1456
+
1457
+ echo '</select><input type="submit" name="btnSubCats" class="button" id="btnSubCats" value="' .
1458
+ __('Select', 'avh-ec') .
1459
+ '" />';
1460
+ echo '<span class="description">';
1461
+ _e('Choose a category from the drop down to order the subcategories in that category.', 'avh-ec');
1462
+ echo '</span>';
1463
+ }
1464
+
1465
+ echo '<input type="hidden" id="hdnManualOrder" name="hdnManualOrder" />';
1466
+ echo '<input type="hidden" id="hdnParentID" name="hdnParentID" value="' . $parentID . '" /></form>';
1467
+ echo '</div>';
1468
+ }
1469
+
1470
+ /**
1471
+ * Options Metabox
1472
+ */
1473
+ public function metaboxOptions($data) {
1474
+ echo $this->printOptions($data['options_general'], $data['actual_options']);
1475
+ }
1476
+
1477
+ /**
1478
+ * Translation Metabox
1479
+ *
1480
+ * @return unknown_type
1481
+ */
1482
+ public function metaboxTranslation() {
1483
+ $locale = apply_filters('plugin_locale', get_locale(), 'avh-ec');
1484
+ $available_locale['cs_CZ'] = array('Czech - Čeština', 0);
1485
+ $available_locale['nl_NL'] = array('Dutch - Nederlands', 0);
1486
+ $available_locale['de_DE'] = array('German - Deutsch', 0);
1487
+ $available_locale['el'] = array('Greek - Čeština', 0);
1488
+ $available_locale['id_ID'] = array('Indonesian - Bahasa Indonesia - Čeština', 0);
1489
+ $available_locale['it_IT'] = array('Italian - Italiano', 1);
1490
+ $available_locale['ru_RU'] = array('Russian — Русский', 0);
1491
+ $available_locale['es_ES'] = array('Spanish - Español', 0);
1492
+ $available_locale['sv_SE'] = array('Swedish - Svenska', 0);
1493
+ $available_locale['tr'] = array('Turkish - Türkçe', 0);
1494
+
1495
+ echo '<div class="p">';
1496
+ echo __('This plugin is translated in several languages. Some of the languages might be incomplete. Please help to complete these translations or add a new language.',
1497
+ 'avh-ec') . '<br />';
1498
+
1499
+ echo '</div>';
1500
+
1501
+ echo '<div class="p">';
1502
+ echo '<span class="b">' . __('Available Languages', 'avh-ec') . '</span>';
1503
+ echo '<ul>';
1504
+ foreach ($available_locale as $key => $value) {
1505
+ echo '<li>';
1506
+ $complete = ($value[1] == 1 ? 'Complete' : 'Incomplete');
1507
+ echo $value[0] . ' (' . $key . ') - ' . $complete;
1508
+ echo '</li>';
1509
+ }
1510
+ echo '</ul>';
1511
+ echo '</div>';
1512
+
1513
+ echo '<div class="p">';
1514
+ if ('en_US' != $locale & ( ! array_key_exists($locale, $available_locale))) {
1515
+ echo 'Currently the plugin is not available in your language (' .
1516
+ $locale .
1517
+ '). We\'re in the middle of changing the way you can help with translations. Keep an eye on the <a href="http:///blog.avirtualhome.com">website</a> for the announcement.';
1518
+ } else {
1519
+ echo 'We\'re in the middle of changing the way you can help with translations. Keep an eye on the <a href="http:///blog.avirtualhome.com">website</a> for the announcement.';
1520
+ }
1521
+ echo '</div>';
1522
+ }
1523
+
1524
+ /**
1525
+ * Display plugin Copyright
1526
+ */
1527
+ public function printAdminFooter() {
1528
+ echo '<p class="footer_avhec">';
1529
+ printf('&copy; Copyright %d <a href="http://blog.avirtualhome.com/" title="My Thoughts">Peter van der Does</a> | AVH Extended Categories Version %s',
1530
+ date('Y'),
1531
+ $this->core->version);
1532
+ echo '</p>';
1533
+ }
1534
+
1535
+ /**
1536
+ * Displays all the information of a group in a row
1537
+ * Adds inline link for delete and/or edit.
1538
+ *
1539
+ * @param int $group_term_id
1540
+ * @param int $group_term_taxonomy_id
1541
+ */
1542
+ public function printCategoryGroupRow($group_term_id, $group_term_taxonomy_id) {
1543
+ static $row_class = '';
1544
+
1545
+ $group = get_term($group_term_id, $this->catgrp->taxonomy_name, OBJECT, 'display');
1546
+
1547
+ $no_edit[ $this->catgrp->getTermIDBy('slug', 'all') ] = 0;
1548
+ $no_delete[ $this->catgrp->getTermIDBy('slug', 'all') ] = 0;
1549
+
1550
+ if (current_user_can('manage_categories')) {
1551
+ $actions = array();
1552
+ if ( ! array_key_exists($group->term_id, $no_edit)) {
1553
+ $edit_link = "admin.php?page=avhec-grouped&amp;action=edit&amp;group_ID=$group->term_id";
1554
+ $edit = "<a class='row-title' href='$edit_link' title='" .
1555
+ esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $group->name)) .
1556
+ "'>" .
1557
+ esc_attr($group->name) .
1558
+ '</a><br />';
1559
+
1560
+ $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
1561
+ } else {
1562
+ $edit = esc_attr($group->name);
1563
+ }
1564
+ if ( ! (array_key_exists($group->term_id, $no_delete))) {
1565
+ $actions['delete'] = "<a class='delete:the-list:group-$group->term_id submitdelete' href='" .
1566
+ wp_nonce_url("admin.php?page=avhec-grouped&amp;action=delete&amp;group_ID=$group->term_id",
1567
+ 'delete-avhecgroup_' . $group->term_id) .
1568
+ "'>" .
1569
+ __('Delete') .
1570
+ "</a>";
1571
+ }
1572
+ $action_count = count($actions);
1573
+ $i = 0;
1574
+ $edit .= '<div class="row-actions">';
1575
+ foreach ($actions as $action => $link) {
1576
+ ++ $i;
1577
+ ($i == $action_count) ? $sep = '' : $sep = ' | ';
1578
+ $edit .= "<span class='$action'>$link$sep</span>";
1579
+ }
1580
+ $edit .= '</div>';
1581
+ } else {
1582
+ $edit = $group->name;
1583
+ }
1584
+
1585
+ $row_class = 'alternate' == $row_class ? '' : 'alternate';
1586
+ $qe_data = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit');
1587
+
1588
+ $output = "<tr id='group-$group->term_id' class='iedit $row_class'>";
1589
+
1590
+ $columns = get_column_headers('categories_group');
1591
+ $hidden = get_hidden_columns('categories_group');
1592
+ foreach ($columns as $column_name => $column_display_name) {
1593
+ $class = 'class="' . $column_name . ' column-' . $column_name . '"';
1594
+
1595
+ $style = '';
1596
+ if (in_array($column_name, $hidden)) {
1597
+ $style = ' style="display:none;"';
1598
+ }
1599
+
1600
+ $attributes = $class . $style;
1601
+
1602
+ switch ($column_name) {
1603
+ case 'cb':
1604
+ $output .= '<th scope="row" class="check-column">';
1605
+ if ( ! (array_key_exists($group->term_id, $no_delete))) {
1606
+ $output .= '<input type="checkbox" name="delete[]" value="' . $group->term_id . '" />';
1607
+ } else {
1608
+ $output .= "&nbsp;";
1609
+ }
1610
+ $output .= '</th>';
1611
+ break;
1612
+ case 'name':
1613
+ $output .= '<td ' . $attributes . '>' . $edit;
1614
+ $output .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">';
1615
+ $output .= '<div class="name">' . $qe_data->name . '</div>';
1616
+ $output .= '<div class="slug">' . apply_filters('editable_slug', $qe_data->slug) . '</div>';
1617
+ $output .= '</div></td>';
1618
+ break;
1619
+ case 'widget-title':
1620
+ $title = $this->catgrp->getWidgetTitleForGroup($group->term_id);
1621
+ if ( ! $title) {
1622
+ $title = "&nbsp;";
1623
+ }
1624
+ $output .= '<td ' . $attributes . '>' . $title . '</td>';
1625
+ break;
1626
+
1627
+ case 'description':
1628
+ $output .= '<td ' . $attributes . '>' . $qe_data->description . '</td>';
1629
+ break;
1630
+ case 'slug':
1631
+ $output .= "<td $attributes>" . apply_filters('editable_slug', $qe_data->slug) . "</td>";
1632
+ break;
1633
+ case 'cat-in-group':
1634
+ $cats = $this->catgrp->getCategoriesFromGroup($group_term_id);
1635
+ $catname = array();
1636
+ foreach ($cats as $cat_id) {
1637
+ $catname[] = get_cat_name($cat_id);
1638
+ }
1639
+ natsort($catname);
1640
+ $cat = implode(', ', $catname);
1641
+ $output .= '<td ' . $attributes . '>' . $cat . '</td>';
1642
+ break;
1643
+ }
1644
+ }
1645
+ $output .= '</tr>';
1646
+
1647
+ return $output;
1648
+ }
1649
+
1650
+ /**
1651
+ * Print all Category Group rows
1652
+ *
1653
+ * @uses printCategoryGroupRow
1654
+ */
1655
+ public function printCategoryGroupRows() {
1656
+ $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false));
1657
+
1658
+ foreach ($cat_groups as $group) {
1659
+ if ('none' != $group->slug) {
1660
+ echo $this->printCategoryGroupRow($group->term_id, $group->term_taxonomy_id);
1661
+ }
1662
+ }
1663
+ }
1664
+
1665
+ /**
1666
+ * Prints the general nonces, used by the AJAX
1667
+ */
1668
+ public function printMetaboxGeneralNonces() {
1669
+ echo '<form style="display:none" method="get" action="">';
1670
+ echo '<p>';
1671
+ wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1672
+ wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1673
+ echo '</p>';
1674
+ echo '</form>';
1675
+ }
1676
+
1677
+ /**
1678
+ * Print the Metabox JS for toggling closed and open
1679
+ *
1680
+ * @param
1681
+ * $boxid
1682
+ */
1683
+ public function printMetaboxJS($boxid) {
1684
+ $a = $this->hooks[ 'menu_' . $boxid ];
1685
+ echo '<script type="text/javascript">' . "\n";
1686
+ echo ' //<![CDATA[' . "\n";
1687
+ echo ' jQuery(document).ready( function($) {' . "\n";
1688
+ echo ' $(\'.if-js-closed\').removeClass(\'if-js-closed\').addClass(\'closed\');' . "\n";
1689
+ echo ' // postboxes setup' . "\n";
1690
+ echo ' postboxes.add_postbox_toggles(\'' . $a . '\');' . "\n";
1691
+ echo ' });' . "\n";
1692
+ echo ' //]]>' . "\n";
1693
+ echo '</script>';
1694
+ }
1695
+
1696
+ /**
1697
+ * Ouput formatted options
1698
+ *
1699
+ * @param array $option_data
1700
+ *
1701
+ * @return string
1702
+ */
1703
+ public function printOptions($option_data, $option_actual) {
1704
+ // Generate output
1705
+ $output = '';
1706
+ $output .= "\n" . '<table class="form-table avhec-options">' . "\n";
1707
+ foreach ($option_data as $option) {
1708
+ $section = substr($option[0], strpos($option[0], '[') + 1);
1709
+ $section = substr($section, 0, strpos($section, ']['));
1710
+ $option_key = rtrim($option[0], ']');
1711
+ $option_key = substr($option_key, strpos($option_key, '][') + 2);
1712
+ // Helper
1713
+ if ($option[2] == 'helper') {
1714
+ $output .= '<tr style="vertical-align: top;"><td class="helper" colspan="2">' .
1715
+ wp_filter_post_kses($option[4]) .
1716
+ '</td></tr>' .
1717
+ "\n";
1718
+ continue;
1719
+ }
1720
+ switch ($option[2]) {
1721
+ case 'checkbox':
1722
+ $input_type = '<input type="checkbox" id="' .
1723
+ esc_attr($option[0]) .
1724
+ '" name="' .
1725
+ esc_attr($option[0]) .
1726
+ '" value="' .
1727
+ esc_attr($option[3]) .
1728
+ '" ' .
1729
+ $this->isChecked('1', $option_actual[ $section ][ $option_key ]) .
1730
+ ' />' .
1731
+ "\n";
1732
+ $explanation = $option[4];
1733
+ break;
1734
+ case 'dropdown':
1735
+ $selvalue = $option[3];
1736
+ $seltext = $option[4];
1737
+ $seldata = '';
1738
+ foreach ((array) $selvalue as $key => $sel) {
1739
+ $seldata .= '<option value="' .
1740
+ esc_attr($sel) .
1741
+ '" ' .
1742
+ (($option_actual[ $section ][ $option_key ] == $sel) ? 'selected="selected"' : '') .
1743
+ ' >' .
1744
+ esc_html(ucfirst($seltext[ $key ])) .
1745
+ '</option>' .
1746
+ "\n";
1747
+ }
1748
+ $input_type = '<select id="' .
1749
+ esc_attr($option[0]) .
1750
+ '" name="' .
1751
+ esc_attr($option[0]) .
1752
+ '">' .
1753
+ $seldata .
1754
+ '</select>' .
1755
+ "\n";
1756
+ $explanation = $option[5];
1757
+ break;
1758
+ case 'text-color':
1759
+ $input_type = '<input type="text" ' .
1760
+ (($option[3] > 1) ? ' style="width: 95%" ' : '') .
1761
+ 'id="' .
1762
+ esc_attr($option[0]) .
1763
+ '" name="' .
1764
+ esc_attr($option[0]) .
1765
+ '" value="' .
1766
+ esc_attr($option_actual[ $section ][ $option_key ]) .
1767
+ '" size="' .
1768
+ esc_attr($option[3]) .
1769
+ '" /><div class="box_color ' .
1770
+ esc_attr($option[0]) .
1771
+ '"></div>' .
1772
+ "\n";
1773
+ $explanation = $option[4];
1774
+ break;
1775
+ case 'textarea':
1776
+ $input_type = '<textarea rows="' .
1777
+ esc_attr($option[5]) .
1778
+ '" ' .
1779
+ (($option[3] > 1) ? ' style="width: 95%" ' : '') .
1780
+ 'id="' .
1781
+ esc_attr($option[0]) .
1782
+ '" name="' .
1783
+ esc_attr($option[0]) .
1784
+ '" size="' .
1785
+ esc_attr($option[3]) .
1786
+ '" />' .
1787
+ $option_actual[ $section ][ $option_key ] .
1788
+ '</textarea>';
1789
+ $explanation = $option[4];
1790
+ break;
1791
+ case 'catlist':
1792
+ ob_start();
1793
+ echo '<div id="avhec-catlist">';
1794
+ echo '<ul>';
1795
+ wp_category_checklist(0, 0, $option_actual[ $section ][ $option_key ]);
1796
+ echo '</ul>';
1797
+ echo '</div>';
1798
+ $input_type = ob_get_contents();
1799
+ ob_end_clean();
1800
+ $explanation = $option[4];
1801
+ break;
1802
+ case 'text':
1803
+ default:
1804
+ $input_type = '<input type="text" ' .
1805
+ (($option[3] > 1) ? ' style="width: 95%" ' : '') .
1806
+ 'id="' .
1807
+ esc_attr($option[0]) .
1808
+ '" name="' .
1809
+ esc_attr($option[0]) .
1810
+ '" value="' .
1811
+ esc_attr($option_actual[ $section ][ $option_key ]) .
1812
+ '" size="' .
1813
+ esc_attr($option[3]) .
1814
+ '" />' .
1815
+ "\n";
1816
+ $explanation = $option[4];
1817
+ break;
1818
+ }
1819
+ // Additional Information
1820
+ $extra = '';
1821
+ if ($explanation) {
1822
+ $extra = '<br /><span class="description">' . wp_filter_kses($explanation) . '</span>' . "\n";
1823
+ }
1824
+ // Output
1825
+ $output .= '<tr style="vertical-align: top;"><th align="left" scope="row"><label for="' .
1826
+ esc_attr($option[0]) .
1827
+ '">' .
1828
+ wp_filter_kses($option[1]) .
1829
+ '</label></th><td>' .
1830
+ $input_type .
1831
+ ' ' .
1832
+ $extra .
1833
+ '</td></tr>' .
1834
+ "\n";
1835
+ }
1836
+ $output .= '</table>' . "\n";
1837
+
1838
+ return $output;
1839
+ }
1840
  }
3.6/class/avh-ec.category-group.php CHANGED
@@ -5,416 +5,467 @@
5
  *
6
  * @author Peter van der Does
7
  */
8
- class AVH_EC_Category_Group
9
- {
10
-
11
- /**
12
- * Taxonomy name
13
- *
14
- * @var string
15
- */
16
- public $taxonomy_name;
17
-
18
- public $db_options_widget_titles;
19
-
20
- public $options_widget_titles;
21
-
22
- public $widget_done_catgroup;
23
-
24
- /**
25
- * PHP5 Constructor
26
- * Init the Database Abstraction layer
27
- */
28
- public function __construct()
29
- {
30
- global $wpdb;
31
-
32
- register_shutdown_function(array($this, '__destruct'));
33
-
34
- /**
35
- * Taxonomy name
36
- *
37
- * @var string
38
- */
39
- $this->taxonomy_name = 'avhec_catgroup';
40
-
41
- $this->db_options_widget_titles = 'avhec_widget_titles';
42
- // add DB pointer
43
- $wpdb->avhec_cat_group = $wpdb->prefix . 'avhec_category_groups';
44
-
45
- /**
46
- * Create the table if it doesn't exist.
47
- */
48
- if ($wpdb->get_var('show tables like \'' . $wpdb->avhec_cat_group . '\'') != $wpdb->avhec_cat_group) {
49
- add_action('init', array($this, 'doCreateTable'), 2); // Priority needs to be the same as the Register Taxonomy
50
- }
51
- add_action('init', array($this, 'doRegisterTaxonomy'), 2); // Priority for registering custom taxonomies is +1 over the creation of the initial taxonomies
52
- add_action('init', array($this, 'doSetupOptions'));
53
-
54
- add_action('admin_init', array($this, 'addMetaBoxes'));
55
- }
56
-
57
- /**
58
- * PHP5 style destructor and will run when database object is destroyed.
59
- *
60
- * @return bool Always true
61
- */
62
- public function __destruct()
63
- {
64
- return true;
65
- }
66
-
67
- /**
68
- * Create Table
69
- * @WordPress action init
70
- */
71
- public function doCreateTable()
72
- {
73
- global $wpdb;
74
-
75
- // Setup the DB Tables
76
- $charset_collate = '';
77
-
78
- if (!empty($wpdb->charset)) {
79
- $charset_collate = 'DEFAULT CHARACTER SET ' . $wpdb->charset;
80
- }
81
- if (!empty($wpdb->collate)) {
82
- $charset_collate .= ' COLLATE ' . $wpdb->collate;
83
- }
84
-
85
- $sql = 'CREATE TABLE `' . $wpdb->avhec_cat_group . '` ( `group_term_id` BIGINT(20) UNSIGNED NOT null DEFAULT 0, `term_id` BIGINT(20) UNSIGNED NOT null DEFAULT 0, PRIMARY KEY (`group_term_id`, `term_id`) )' . $charset_collate . ';';
86
-
87
- $result = $wpdb->query($sql);
88
- }
89
-
90
- /**
91
- * Setup Group Categories Taxonomy
92
- * @WordPress action init
93
- */
94
- public function doRegisterTaxonomy()
95
- {
96
- /**
97
- * As we don't want to see the Menu Item we have to disable show_ui.
98
- * This also disables the metabox on the posts and pages, so we add thse manually instead.
99
- * We remove the capabilities to manage, edit and delete the terms. We have written this part ourselves and don't use WordPress for these functions. The only one we use is the assign_terms.
100
- */
101
- $labels = array('name' => __('Category Groups', 'avh-ec'), 'singular_name' => __('Category Group', 'avh-ec'), 'search_items' => __('Search Category Groups', 'avh-ec'), 'popular_items' => __('Popular Category Groups'), 'all_items' => __('All Category Groups'), 'parent_item' => __('Parent Category Group'), 'parent_item_colon' => __('Parent Category Group:'), 'edit_item' => __('Edit Category Group'), 'update_item' => __('Update Category Group'), 'add_new_item' => __('Add New Category Group'), 'new_item_name' => __('New Category Group Name'));
102
- $caps = array('manage_terms' => null, 'edit_terms' => null, 'delete_terms' => null, 'assign_terms' => 'edit_posts');
103
- register_taxonomy($this->taxonomy_name, array('post', 'page'), array('hierarchical' => true, 'labels' => $labels, 'query_var' => true, 'rewrite' => true, 'show_in_nav_menus' => false, 'public' => true, 'show_ui' => false, 'capabilities' => $caps));
104
- }
105
-
106
- /**
107
- * Setup the options for the widget titles
108
- * @WordPress action init
109
- */
110
- public function doSetupOptions()
111
- {
112
- // Setup the standard groups if the none group does not exists.
113
- $all_categories = $this->getAllCategoriesTermID();
114
- if (false === $this->getTermIDBy('slug', 'none')) {
115
- $none_group_id = wp_insert_term('none', $this->taxonomy_name, array('description' => __('This group will not show the widget.', 'avh-ec')));
116
-
117
- $home_group_id = wp_insert_term('Home', $this->taxonomy_name, array('description' => __('This group will be shown on the front page.', 'avh-ec')));
118
- $this->setCategoriesForGroup($home_group_id['term_id'], $all_categories);
119
- $this->setWidgetTitleForGroup($home_group_id['term_id'], '');
120
- }
121
- if (false === $this->getTermIDBy('slug', 'all')) {
122
- $all_group_id = wp_insert_term('All', $this->taxonomy_name, array('description' => __('Holds all the categories.', 'avh-ec')));
123
- if (! is_wp_error($all_group_id)) {
124
- $this->setWidgetTitleForGroup($all_group_id['term_id'], '');
125
- } else {
126
- trigger_error($all_group_id->get_error_message(), E_USER_NOTICE);
127
- }
128
- }
129
-
130
- $options = get_option($this->db_options_widget_titles);
131
- if (!$options) {
132
- $options = array();
133
- $id = $this->getTermIDBy('slug', 'all');
134
- $options[$id] = '';
135
- $id = $this->getTermIDBy('slug', 'home');
136
- $options[$id] = '';
137
- update_option($this->db_options_widget_titles, $options);
138
- }
139
- $this->options_widget_titles = $options;
140
- $this->setCategoriesForGroup($this->getTermIDBy('slug', 'all'), $all_categories);
141
- }
142
-
143
- /**
144
- * Add the metaboxes for the pots and page pages.
145
- * @WordPress action admin_init
146
- */
147
- public function addMetaBoxes()
148
- {
149
- add_meta_box($this->taxonomy_name . 'div', __('Category Groups', 'avh-ec'), 'post_categories_meta_box', 'post', 'side', 'core', array('taxonomy' => $this->taxonomy_name));
150
- add_meta_box($this->taxonomy_name . 'div', __('Category Groups', 'avh-ec'), 'post_categories_meta_box', 'page', 'side', 'core', array('taxonomy' => $this->taxonomy_name));
151
- }
152
-
153
- /**
154
- * Get all groups term_id
155
- *
156
- * @return array Term_id
157
- */
158
- public function getAllCategoriesTermID()
159
- {
160
- $all_cat_id = array();
161
- $categories = get_categories();
162
- if (!is_wp_error($categories)) {
163
- foreach ($categories as $category) {
164
- $all_cat_id[] = $category->term_id;
165
- }
166
- }
167
-
168
- return ($all_cat_id);
169
- }
170
-
171
- /**
172
- * Get the categories from the given group from the DB
173
- *
174
- * @param int $group_id
175
- * The Taxonomy Term ID
176
- * @return Array false Will return false, if the row does not exists.
177
- *
178
- */
179
- public function getCategoriesFromGroup($group_id)
180
- {
181
- global $wpdb;
182
-
183
- // Query database
184
- $result = $wpdb->get_results($wpdb->prepare('SELECT * FROM ' . $wpdb->terms . ' t, ' . $wpdb->avhec_cat_group . ' cg WHERE t.term_id = cg.term_id AND cg.group_term_id = %d', $group_id));
185
-
186
- if (is_array($result)) { // Call succeeded
187
- if (empty($result)) { // No rows found
188
- $return = array();
189
- } else {
190
- foreach ($result as $row) {
191
- $return[] = $row->term_id;
192
- }
193
- }
194
- } else {
195
- $return = false;
196
- }
197
-
198
- return ($return);
199
- }
200
-
201
- /**
202
- * Set the categories for the given group from the DB.
203
- * Insert the group if it doesn't exists.
204
- *
205
- * @param int $group_id
206
- * The Taxonomy Term ID
207
- * @param array $categories
208
- * The categories
209
- * @return Object (false if not found)
210
- *
211
- */
212
- public function setCategoriesForGroup($group_id, $categories = array())
213
- {
214
- global $wpdb;
215
-
216
- $old_categories = $this->getCategoriesFromGroup($group_id);
217
-
218
- if (!is_array($categories)) {
219
- $categories = array();
220
- }
221
- $new_categories = $categories;
222
- sort($old_categories);
223
- sort($new_categories);
224
- // If the new and old values are the same, no need to update.
225
- if ($new_categories === $old_categories) {
226
- return false;
227
- }
228
-
229
- $new = array_diff($new_categories, $old_categories);
230
- $removed = array_diff($old_categories, $new_categories);
231
-
232
- if (!empty($new)) {
233
- foreach ($new as $cat_term_id) {
234
- $insert[] = '(' . $group_id . ',' . $cat_term_id . ')';
235
- }
236
- $value = implode(',', $insert);
237
- $sql = 'INSERT INTO ' . $wpdb->avhec_cat_group . ' (group_term_id, term_id) VALUES ' . $value;
238
- $result = $wpdb->query($sql);
239
- }
240
-
241
- if (!empty($removed)) {
242
- $delete = implode(',', $removed);
243
- $sql = $wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE group_term_id=%d and term_id IN (' . $delete . ')', $group_id);
244
- $result = $wpdb->query($sql);
245
- }
246
-
247
- return $result;
248
- }
249
-
250
- /**
251
- * Set the Widget Title for a Group
252
- *
253
- * @param int $group_id
254
- * @param string $widget_title
255
- *
256
- */
257
- public function setWidgetTitleForGroup($group_id, $widget_title = '')
258
- {
259
- $this->options_widget_titles[$group_id] = $widget_title;
260
- update_option($this->db_options_widget_titles, $this->options_widget_titles);
261
- }
262
-
263
- /**
264
- * Return the title for a group_id if exsist otherwise return false
265
- *
266
- * @param
267
- * $group_id
268
- *
269
- */
270
- public function getWidgetTitleForGroup($group_id)
271
- {
272
- if (isset($this->options_widget_titles[$group_id])) {
273
- return ($this->options_widget_titles[$group_id]);
274
- }
275
-
276
- return false;
277
- }
278
-
279
- /**
280
- * Delete the Widget Title for a group
281
- *
282
- * @param
283
- * $group_id
284
- */
285
- public function doDeleteWidgetTitle($group_id)
286
- {
287
- if (isset($this->options_widget_titles[$group_id])) {
288
- unset($this->options_widget_titles[$group_id]);
289
- }
290
- update_option($this->db_options_widget_titles, $this->options_widget_titles);
291
- }
292
-
293
- /**
294
- * Same as get_term_by, but returns the ID only if found, else false
295
- *
296
- * @param string $field
297
- * @param string $value
298
- * @return int boolean
299
- */
300
- public function getTermIDBy($field, $value)
301
- {
302
- $row = get_term_by($field, $value, $this->taxonomy_name);
303
- if (false === $row) {
304
- $return = false;
305
- } else {
306
- $return = (int) $row->term_id;
307
- }
308
-
309
- return ($return);
310
- }
311
-
312
- /**
313
- * Gets all information of a group
314
- *
315
- * @param
316
- * $group_id
317
- * @return Object false false when the group doesn't exists.
318
- */
319
- public function getGroup($group_id)
320
- {
321
- global $wpdb;
322
-
323
- $result = get_term((int) $group_id, $this->taxonomy_name);
324
- if (null === $result) {
325
- $result = false;
326
- }
327
-
328
- return ($result);
329
- }
330
-
331
- public function getGroupByCategoryID($category_id)
332
- {
333
- $return = get_term_by('slug', 'none', $this->taxonomy_name);
334
- $cat_groups = get_terms($this->taxonomy_name, array('hide_empty' => false));
335
-
336
- foreach ($cat_groups as $group) {
337
- $cats = $this->getCategoriesFromGroup($group->term_id);
338
- if ($group->slug != 'all' && in_array($category_id, $cats)) {
339
- $return = $group;
340
- break;
341
- }
342
- }
343
-
344
- return $return;
345
- }
346
-
347
- /**
348
- * Inserts a new group
349
- *
350
- * @param
351
- * $term
352
- * @param array $args
353
- */
354
- public function doInsertGroup($term, $args = array(), $widget_title = '')
355
- {
356
- $row = wp_insert_term($term, $this->taxonomy_name, $args);
357
- $this->setWidgetTitleForGroup($term, $widget_title);
358
-
359
- return ($row['term_id']);
360
- }
361
-
362
- /**
363
- * Deletes a group
364
- *
365
- * @param
366
- * $group_id
367
- */
368
- public function doDeleteGroup($group_id)
369
- {
370
- global $wpdb;
371
-
372
- $group = $this->getGroup($group_id);
373
- $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE group_term_id=%d', $group_id));
374
- $this->doDeleteWidgetTitle($group_id);
375
- $return = wp_delete_term($group->term_id, $this->taxonomy_name);
376
-
377
- return ($return);
378
- }
379
-
380
- /**
381
- * Update a group
382
- *
383
- * @param
384
- * $group_id
385
- * @param
386
- * $selected_categories
387
- * @param $widget_title return
388
- * -1,0,1 Unknown Group, Duplicate Slug, Succesfull
389
- */
390
- public function doUpdateGroup($group_id, $args = array(), $selected_categories = array(), $widget_title = '')
391
- {
392
- $group = $this->getGroup($group_id);
393
- if (is_object($group)) {
394
- $id = wp_update_term($group->term_id, $this->taxonomy_name, $args);
395
- if (!is_wp_error($id)) {
396
- $this->setWidgetTitleForGroup($group_id, $widget_title);
397
- $this->setCategoriesForGroup($group_id, $selected_categories);
398
- $return = 1; // Succesful
399
- } else {
400
- $return = 0; // Duplicate Slug
401
- }
402
- } else {
403
- $return = -1; // Unknown group
404
- }
405
-
406
- return ($return);
407
- }
408
-
409
- /**
410
- * Deletes the given category from all groups
411
- *
412
- * @param
413
- * $category_id
414
- */
415
- public function doDeleteCategoryFromGroup($category_id)
416
- {
417
- global $wpdb;
418
- $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE term_id=%d', $category_id));
419
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
420
  }
5
  *
6
  * @author Peter van der Does
7
  */
8
+ class AVH_EC_Category_Group {
9
+ public $db_options_widget_titles;
10
+ public $options_widget_titles;
11
+ /**
12
+ * Taxonomy name
13
+ *
14
+ * @var string
15
+ */
16
+ public $taxonomy_name;
17
+ public $widget_done_catgroup;
18
+
19
+ /**
20
+ * PHP5 Constructor
21
+ * Init the Database Abstraction layer
22
+ */
23
+ public function __construct() {
24
+ global $wpdb;
25
+
26
+ register_shutdown_function(array($this, '__destruct'));
27
+
28
+ /**
29
+ * Taxonomy name
30
+ *
31
+ * @var string
32
+ */
33
+ $this->taxonomy_name = 'avhec_catgroup';
34
+
35
+ $this->db_options_widget_titles = 'avhec_widget_titles';
36
+ // add DB pointer
37
+ $wpdb->avhec_cat_group = $wpdb->prefix . 'avhec_category_groups';
38
+
39
+ /**
40
+ * Create the table if it doesn't exist.
41
+ */
42
+ if ($wpdb->get_var('show tables like \'' . $wpdb->avhec_cat_group . '\'') != $wpdb->avhec_cat_group) {
43
+ add_action('init',
44
+ array($this, 'doCreateTable'),
45
+ 2); // Priority needs to be the same as the Register Taxonomy
46
+ }
47
+ add_action('init',
48
+ array($this, 'doRegisterTaxonomy'),
49
+ 2); // Priority for registering custom taxonomies is +1 over the creation of the initial taxonomies
50
+ add_action('init', array($this, 'doSetupOptions'));
51
+
52
+ add_action('admin_init', array($this, 'addMetaBoxes'));
53
+ }
54
+
55
+ /**
56
+ * PHP5 style destructor and will run when database object is destroyed.
57
+ *
58
+ * @return bool Always true
59
+ */
60
+ public function __destruct() {
61
+ return true;
62
+ }
63
+
64
+ /**
65
+ * Add the metaboxes for the pots and page pages.
66
+ *
67
+ * @WordPress action admin_init
68
+ */
69
+ public function addMetaBoxes() {
70
+ add_meta_box($this->taxonomy_name . 'div',
71
+ __('Category Groups', 'avh-ec'),
72
+ 'post_categories_meta_box',
73
+ 'post',
74
+ 'side',
75
+ 'core',
76
+ array('taxonomy' => $this->taxonomy_name));
77
+ add_meta_box($this->taxonomy_name . 'div',
78
+ __('Category Groups', 'avh-ec'),
79
+ 'post_categories_meta_box',
80
+ 'page',
81
+ 'side',
82
+ 'core',
83
+ array('taxonomy' => $this->taxonomy_name));
84
+ }
85
+
86
+ /**
87
+ * Create Table
88
+ *
89
+ * @WordPress action init
90
+ */
91
+ public function doCreateTable() {
92
+ global $wpdb;
93
+
94
+ // Setup the DB Tables
95
+ $charset_collate = '';
96
+
97
+ if ( ! empty($wpdb->charset)) {
98
+ $charset_collate = 'DEFAULT CHARACTER SET ' . $wpdb->charset;
99
+ }
100
+ if ( ! empty($wpdb->collate)) {
101
+ $charset_collate .= ' COLLATE ' . $wpdb->collate;
102
+ }
103
+
104
+ $sql = 'CREATE TABLE `' .
105
+ $wpdb->avhec_cat_group .
106
+ '` ( `group_term_id` BIGINT(20) UNSIGNED NOT null DEFAULT 0, `term_id` BIGINT(20) UNSIGNED NOT null DEFAULT 0, PRIMARY KEY (`group_term_id`, `term_id`) )' .
107
+ $charset_collate .
108
+ ';';
109
+
110
+ $result = $wpdb->query($sql);
111
+ }
112
+
113
+ /**
114
+ * Deletes the given category from all groups
115
+ *
116
+ * @param
117
+ * $category_id
118
+ */
119
+ public function doDeleteCategoryFromGroup($category_id) {
120
+ global $wpdb;
121
+ $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE term_id=%d',
122
+ $category_id));
123
+ }
124
+
125
+ /**
126
+ * Deletes a group
127
+ *
128
+ * @param
129
+ * $group_id
130
+ */
131
+ public function doDeleteGroup($group_id) {
132
+ global $wpdb;
133
+
134
+ $group = $this->getGroup($group_id);
135
+ $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE group_term_id=%d',
136
+ $group_id));
137
+ $this->doDeleteWidgetTitle($group_id);
138
+ $return = wp_delete_term($group->term_id, $this->taxonomy_name);
139
+
140
+ return ($return);
141
+ }
142
+
143
+ /**
144
+ * Delete the Widget Title for a group
145
+ *
146
+ * @param
147
+ * $group_id
148
+ */
149
+ public function doDeleteWidgetTitle($group_id) {
150
+ if (isset($this->options_widget_titles[ $group_id ])) {
151
+ unset($this->options_widget_titles[ $group_id ]);
152
+ }
153
+ update_option($this->db_options_widget_titles, $this->options_widget_titles);
154
+ }
155
+
156
+ /**
157
+ * Inserts a new group
158
+ *
159
+ * @param
160
+ * $term
161
+ * @param array $args
162
+ */
163
+ public function doInsertGroup($term, $args = array(), $widget_title = '') {
164
+ $row = wp_insert_term($term, $this->taxonomy_name, $args);
165
+ $this->setWidgetTitleForGroup($term, $widget_title);
166
+
167
+ return ($row['term_id']);
168
+ }
169
+
170
+ /**
171
+ * Setup Group Categories Taxonomy
172
+ *
173
+ * @WordPress action init
174
+ */
175
+ public function doRegisterTaxonomy() {
176
+ /**
177
+ * As we don't want to see the Menu Item we have to disable show_ui.
178
+ * This also disables the metabox on the posts and pages, so we add thse manually instead.
179
+ * We remove the capabilities to manage, edit and delete the terms. We have written this part ourselves and don't use WordPress for these functions. The only one we use is the assign_terms.
180
+ */
181
+ $labels = array(
182
+ 'name' => __('Category Groups', 'avh-ec'),
183
+ 'singular_name' => __('Category Group', 'avh-ec'),
184
+ 'search_items' => __('Search Category Groups', 'avh-ec'),
185
+ 'popular_items' => __('Popular Category Groups'),
186
+ 'all_items' => __('All Category Groups'),
187
+ 'parent_item' => __('Parent Category Group'),
188
+ 'parent_item_colon' => __('Parent Category Group:'),
189
+ 'edit_item' => __('Edit Category Group'),
190
+ 'update_item' => __('Update Category Group'),
191
+ 'add_new_item' => __('Add New Category Group'),
192
+ 'new_item_name' => __('New Category Group Name')
193
+ );
194
+ $caps = array(
195
+ 'manage_terms' => null,
196
+ 'edit_terms' => null,
197
+ 'delete_terms' => null,
198
+ 'assign_terms' => 'edit_posts'
199
+ );
200
+ register_taxonomy($this->taxonomy_name,
201
+ array('post', 'page'),
202
+ array(
203
+ 'hierarchical' => true,
204
+ 'labels' => $labels,
205
+ 'query_var' => true,
206
+ 'rewrite' => true,
207
+ 'show_in_nav_menus' => false,
208
+ 'public' => true,
209
+ 'show_ui' => false,
210
+ 'capabilities' => $caps
211
+ ));
212
+ }
213
+
214
+ /**
215
+ * Setup the options for the widget titles
216
+ *
217
+ * @WordPress action init
218
+ */
219
+ public function doSetupOptions() {
220
+ // Setup the standard groups if the none group does not exists.
221
+ $all_categories = $this->getAllCategoriesTermID();
222
+ if (false === $this->getTermIDBy('slug', 'none')) {
223
+ $none_group_id = wp_insert_term('none',
224
+ $this->taxonomy_name,
225
+ array(
226
+ 'description' => __('This group will not show the widget.', 'avh-ec')
227
+ ));
228
+
229
+ $home_group_id = wp_insert_term('Home',
230
+ $this->taxonomy_name,
231
+ array(
232
+ 'description' => __('This group will be shown on the front page.',
233
+ 'avh-ec')
234
+ ));
235
+ $this->setCategoriesForGroup($home_group_id['term_id'], $all_categories);
236
+ $this->setWidgetTitleForGroup($home_group_id['term_id'], '');
237
+ }
238
+ if (false === $this->getTermIDBy('slug', 'all')) {
239
+ $all_group_id = wp_insert_term('All',
240
+ $this->taxonomy_name,
241
+ array('description' => __('Holds all the categories.', 'avh-ec')));
242
+ if ( ! is_wp_error($all_group_id)) {
243
+ $this->setWidgetTitleForGroup($all_group_id['term_id'], '');
244
+ } else {
245
+ trigger_error($all_group_id->get_error_message(), E_USER_NOTICE);
246
+ }
247
+ }
248
+
249
+ $options = get_option($this->db_options_widget_titles);
250
+ if ( ! $options) {
251
+ $options = array();
252
+ $id = $this->getTermIDBy('slug', 'all');
253
+ $options[ $id ] = '';
254
+ $id = $this->getTermIDBy('slug', 'home');
255
+ $options[ $id ] = '';
256
+ update_option($this->db_options_widget_titles, $options);
257
+ }
258
+ $this->options_widget_titles = $options;
259
+ $this->setCategoriesForGroup($this->getTermIDBy('slug', 'all'), $all_categories);
260
+ }
261
+
262
+ /**
263
+ * Update a group
264
+ *
265
+ * @param
266
+ * $group_id
267
+ * @param
268
+ * $selected_categories
269
+ * @param $widget_title return
270
+ * -1,0,1 Unknown Group, Duplicate Slug, Succesfull
271
+ */
272
+ public function doUpdateGroup($group_id, $args = array(), $selected_categories = array(), $widget_title = '') {
273
+ $group = $this->getGroup($group_id);
274
+ if (is_object($group)) {
275
+ $id = wp_update_term($group->term_id, $this->taxonomy_name, $args);
276
+ if ( ! is_wp_error($id)) {
277
+ $this->setWidgetTitleForGroup($group_id, $widget_title);
278
+ $this->setCategoriesForGroup($group_id, $selected_categories);
279
+ $return = 1; // Succesful
280
+ } else {
281
+ $return = 0; // Duplicate Slug
282
+ }
283
+ } else {
284
+ $return = - 1; // Unknown group
285
+ }
286
+
287
+ return ($return);
288
+ }
289
+
290
+ /**
291
+ * Get all groups term_id
292
+ *
293
+ * @return array Term_id
294
+ */
295
+ public function getAllCategoriesTermID() {
296
+ $all_cat_id = array();
297
+ $categories = get_categories();
298
+ if ( ! is_wp_error($categories)) {
299
+ foreach ($categories as $category) {
300
+ $all_cat_id[] = $category->term_id;
301
+ }
302
+ }
303
+
304
+ return ($all_cat_id);
305
+ }
306
+
307
+ /**
308
+ * Get the categories from the given group from the DB
309
+ *
310
+ * @param int $group_id
311
+ * The Taxonomy Term ID
312
+ *
313
+ * @return Array false Will return false, if the row does not exists.
314
+ */
315
+ public function getCategoriesFromGroup($group_id) {
316
+ global $wpdb;
317
+
318
+ // Query database
319
+ $result = $wpdb->get_results($wpdb->prepare('SELECT * FROM ' .
320
+ $wpdb->terms .
321
+ ' t, ' .
322
+ $wpdb->avhec_cat_group .
323
+ ' cg WHERE t.term_id = cg.term_id AND cg.group_term_id = %d',
324
+ $group_id));
325
+
326
+ if (is_array($result)) { // Call succeeded
327
+ if (empty($result)) { // No rows found
328
+ $return = array();
329
+ } else {
330
+ foreach ($result as $row) {
331
+ $return[] = $row->term_id;
332
+ }
333
+ }
334
+ } else {
335
+ $return = false;
336
+ }
337
+
338
+ return ($return);
339
+ }
340
+
341
+ /**
342
+ * Gets all information of a group
343
+ *
344
+ * @param
345
+ * $group_id
346
+ *
347
+ * @return Object false false when the group doesn't exists.
348
+ */
349
+ public function getGroup($group_id) {
350
+ global $wpdb;
351
+
352
+ $result = get_term((int) $group_id, $this->taxonomy_name);
353
+ if (null === $result) {
354
+ $result = false;
355
+ }
356
+
357
+ return ($result);
358
+ }
359
+
360
+ public function getGroupByCategoryID($category_id) {
361
+ $return = get_term_by('slug', 'none', $this->taxonomy_name);
362
+ $cat_groups = get_terms($this->taxonomy_name, array('hide_empty' => false));
363
+
364
+ foreach ($cat_groups as $group) {
365
+ $cats = $this->getCategoriesFromGroup($group->term_id);
366
+ if ($group->slug != 'all' && in_array($category_id, $cats)) {
367
+ $return = $group;
368
+ break;
369
+ }
370
+ }
371
+
372
+ return $return;
373
+ }
374
+
375
+ /**
376
+ * Same as get_term_by, but returns the ID only if found, else false
377
+ *
378
+ * @param string $field
379
+ * @param string $value
380
+ *
381
+ * @return int boolean
382
+ */
383
+ public function getTermIDBy($field, $value) {
384
+ $row = get_term_by($field, $value, $this->taxonomy_name);
385
+ if (false === $row) {
386
+ $return = false;
387
+ } else {
388
+ $return = (int) $row->term_id;
389
+ }
390
+
391
+ return ($return);
392
+ }
393
+
394
+ /**
395
+ * Return the title for a group_id if exsist otherwise return false
396
+ *
397
+ * @param
398
+ * $group_id
399
+ */
400
+ public function getWidgetTitleForGroup($group_id) {
401
+ if (isset($this->options_widget_titles[ $group_id ])) {
402
+ return ($this->options_widget_titles[ $group_id ]);
403
+ }
404
+
405
+ return false;
406
+ }
407
+
408
+ /**
409
+ * Set the categories for the given group from the DB.
410
+ * Insert the group if it doesn't exists.
411
+ *
412
+ * @param int $group_id
413
+ * The Taxonomy Term ID
414
+ * @param array $categories
415
+ * The categories
416
+ *
417
+ * @return Object (false if not found)
418
+ */
419
+ public function setCategoriesForGroup($group_id, $categories = array()) {
420
+ global $wpdb;
421
+
422
+ $old_categories = $this->getCategoriesFromGroup($group_id);
423
+
424
+ if ( ! is_array($categories)) {
425
+ $categories = array();
426
+ }
427
+ $new_categories = $categories;
428
+ sort($old_categories);
429
+ sort($new_categories);
430
+ // If the new and old values are the same, no need to update.
431
+ if ($new_categories === $old_categories) {
432
+ return false;
433
+ }
434
+
435
+ $new = array_diff($new_categories, $old_categories);
436
+ $removed = array_diff($old_categories, $new_categories);
437
+
438
+ if ( ! empty($new)) {
439
+ foreach ($new as $cat_term_id) {
440
+ $insert[] = '(' . $group_id . ',' . $cat_term_id . ')';
441
+ }
442
+ $value = implode(',', $insert);
443
+ $sql = 'INSERT INTO ' . $wpdb->avhec_cat_group . ' (group_term_id, term_id) VALUES ' . $value;
444
+ $result = $wpdb->query($sql);
445
+ }
446
+
447
+ if ( ! empty($removed)) {
448
+ $delete = implode(',', $removed);
449
+ $sql = $wpdb->prepare('DELETE FROM ' .
450
+ $wpdb->avhec_cat_group .
451
+ ' WHERE group_term_id=%d and term_id IN (' .
452
+ $delete .
453
+ ')',
454
+ $group_id);
455
+ $result = $wpdb->query($sql);
456
+ }
457
+
458
+ return $result;
459
+ }
460
+
461
+ /**
462
+ * Set the Widget Title for a Group
463
+ *
464
+ * @param int $group_id
465
+ * @param string $widget_title
466
+ */
467
+ public function setWidgetTitleForGroup($group_id, $widget_title = '') {
468
+ $this->options_widget_titles[ $group_id ] = $widget_title;
469
+ update_option($this->db_options_widget_titles, $this->options_widget_titles);
470
+ }
471
  }
3.6/class/avh-ec.core.php CHANGED
@@ -1,797 +1,828 @@
1
  <?php
2
 
3
- class AVH_EC_Core
4
- {
5
-
6
- public $version;
7
-
8
- public $comment;
9
-
10
- public $info;
11
-
12
- public $db_options_core;
13
-
14
- public $default_options;
15
-
16
- public $default_options_general;
17
-
18
- public $default_options_category_group;
19
-
20
- public $default_options_sp_category_group;
21
-
22
- public $db_options_tax_meta;
23
-
24
- public $options;
25
-
26
- /**
27
- * PHP5 constructor
28
- */
29
- public function __construct()
30
- {
31
- /**
32
- *
33
- * @var AVH_EC_Category_Group
34
- */
35
- $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
36
-
37
- $this->version = '4.0.2';
38
- $this->comment = '<!-- AVH Extended Categories version ' . $this->version . ' | http://blog.avirtualhome.com/wordpress-plugins/ -->';
39
- $this->db_options_core = 'avhec';
40
- $this->db_options_tax_meta = 'avhec-tax_meta';
41
-
42
- add_action('init', array($this, 'handleInitializePlugin'), 10);
43
- }
44
-
45
- public function handleInitializePlugin()
46
- {
47
- global $wpdb;
48
-
49
- $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
50
- $db_version = 4;
51
-
52
- $info['siteurl'] = get_option('siteurl');
53
- $info['plugin_dir'] = AVHEC_PLUGIN_DIR;
54
- $info['graphics_url'] = AVHEC_PLUGIN_URL . '/images';
55
-
56
- // Set class property for info
57
- $this->info = array('home' => get_option('home'), 'siteurl' => $info['siteurl'], 'plugin_dir' => $info['plugin_dir'], 'js_dir' => $info['plugin_dir'] . '/js', 'graphics_url' => $info['graphics_url']);
58
-
59
- // Set the default options
60
- $this->default_options_general = array('version' => $this->version, 'dbversion' => $db_version, 'alternative_name_select_category' => '');
61
-
62
- // Set the default category group options
63
- $no_group_id = $catgrp->getTermIDBy('slug', 'none');
64
- $home_group_id = $catgrp->getTermIDBy('slug', 'home');
65
- $default_group_id = $catgrp->getTermIDBy('slug', 'all');
66
- $this->default_options_category_group = array('no_group' => $no_group_id, 'home_group' => $home_group_id, 'default_group' => $default_group_id);
67
-
68
- $this->default_options_sp_category_group = array('home_group' => $home_group_id, 'category_group' => $default_group_id, 'day_group' => $default_group_id, 'month_group' => $default_group_id, 'year_group' => $default_group_id, 'author_group' => $default_group_id, 'search_group' => $default_group_id);
69
-
70
- $this->default_options = array('general' => $this->default_options_general, 'cat_group' => $this->default_options_category_group, 'widget_titles' => array(), 'sp_cat_group' => $this->default_options_sp_category_group);
71
-
72
- /**
73
- * Set the options for the program
74
- */
75
- $this->loadOptions();
76
-
77
- // Check if we have to do updates
78
- if ((!isset($this->options['general']['dbversion'])) || $this->options['general']['dbversion'] < $db_version) {
79
- $this->doUpdateOptions($db_version);
80
- }
81
-
82
- $db = new AVH_DB();
83
- if (!$db->field_exists('avhec_term_order', $wpdb->terms)) {
84
- $wpdb->query("ALTER TABLE $wpdb->terms ADD `avhec_term_order` INT( 4 ) null DEFAULT '0'");
85
- }
86
-
87
- $this->handleTextdomain();
88
- add_filter('get_terms_orderby', array($this, 'applyOrderFilter'), 10, 2);
89
- }
90
-
91
- public function applyOrderFilter($orderby, $args)
92
- {
93
- switch ($args['orderby']) {
94
- case 'avhec_manualorder':
95
- $new_orderby = 't.avhec_term_order';
96
- break;
97
- case 'avhec_3rdparty_mycategoryorder':
98
- $new_orderby = 't.term_order';
99
- break;
100
- default:
101
- $new_orderby = $orderby;
102
- break;
103
- }
104
-
105
- return $new_orderby;
106
- }
107
-
108
- /**
109
- * Loads the i18n
110
- */
111
- public function handleTextdomain()
112
- {
113
- load_plugin_textdomain('avh-ec', false, AVHEC_RELATIVE_PLUGIN_DIR . '/lang');
114
- }
115
-
116
- /**
117
- * Checks if running version is newer and do upgrades if necessary
118
- *
119
- * @since 1.2.3
120
- *
121
- */
122
- public function doUpdateOptions($db_version)
123
- {
124
- $options = $this->getOptions();
125
-
126
- // Add none existing sections and/or elements to the options
127
- foreach ($this->default_options as $section => $default_data) {
128
- if (!array_key_exists($section, $options)) {
129
- $options[$section] = $default_data;
130
- continue;
131
- }
132
- foreach ($default_data as $element => $default_value) {
133
- if (!array_key_exists($element, $options[$section])) {
134
- $options[$section][$element] = $default_value;
135
- }
136
- }
137
- }
138
-
139
- // Remove none existing sections and/or elements from the options
140
- foreach ($options as $section => $data) {
141
- if (!array_key_exists($section, $this->default_options)) {
142
- unset($options[$section]);
143
- continue;
144
- }
145
- foreach ($data as $element => $value) {
146
- if (!array_key_exists($element, $this->default_options[$section])) {
147
- unset($options[$section][$element]);
148
- }
149
- }
150
- }
151
- /**
152
- * Update the options to the latests versions
153
- */
154
- $options['general']['version'] = $this->version;
155
- $options['general']['dbversion'] = $db_version;
156
- $this->saveOptions($options);
157
- }
158
-
159
- /**
160
- * Used in forms to set the checked option.
161
- *
162
- * @param mixed $checked
163
- * @param mixed_type $current
164
- * @return string
165
- *
166
- * @since 2.0
167
- */
168
- public function isChecked($checked, $current)
169
- {
170
- if ($checked == $current) {
171
- return (' checked="checked"');
172
- }
173
-
174
- return ('');
175
- }
176
-
177
- /**
178
- * Used in forms to set the SELECTED option
179
- *
180
- * @param string $current
181
- * @param string $field
182
- * @return string
183
- */
184
- public function isSelected($current, $field)
185
- {
186
- if ($current == $field) {
187
- return (' SELECTED');
188
- }
189
-
190
- return ('');
191
- }
192
-
193
- /**
194
- * Get the base directory of a directory structure
195
- *
196
- * @param string $directory
197
- * @return string
198
- *
199
- */
200
- public function getBaseDirectory($directory)
201
- {
202
- // place each directory into array and get the last element
203
- $directory_array = explode('/', $directory);
204
- // get highest or top level in array of directory strings
205
- $public_base = end($directory_array);
206
-
207
- return $public_base;
208
- }
209
-
210
- /**
211
- * *******************************
212
- * *
213
- * Methods for variable: options *
214
- * *
215
- * ******************************
216
- */
217
-
218
- /**
219
- *
220
- * @param array $data
221
- */
222
- public function setOptions($options)
223
- {
224
- $this->options = $options;
225
- }
226
-
227
- /**
228
- * return array
229
- */
230
- public function getOptions()
231
- {
232
- return ($this->options);
233
- }
234
-
235
- /**
236
- * Save all current options and set the options
237
- */
238
- public function saveOptions($options)
239
- {
240
- update_option($this->db_options_core, $options);
241
- wp_cache_flush(); // Delete cache
242
- $this->setOptions($options);
243
- }
244
-
245
- /**
246
- * Retrieves the plugin options from the WordPress options table and assigns to class variable.
247
- * If the options do not exists, like a new installation, the options are set to the default value.
248
- *
249
- * @return none
250
- */
251
- public function loadOptions()
252
- {
253
- $options = get_option($this->db_options_core);
254
- if (false === $options) { // New installation
255
- $this->resetToDefaultOptions();
256
- } else {
257
- $this->setOptions($options);
258
- }
259
- }
260
-
261
- /**
262
- * Get the value for an option element.
263
- * If there's no option is set on the Admin page, return the default value.
264
- *
265
- * @param string $key
266
- * @param string $option
267
- * @return mixed
268
- */
269
- public function getOptionElement($option, $key)
270
- {
271
- if ($this->options[$option][$key]) {
272
- $return = $this->options[$option][$key]; // From Admin Page
273
- } else {
274
- $return = $this->default_options[$option][$key]; // Default
275
- }
276
-
277
- return ($return);
278
- }
279
-
280
- /**
281
- * Reset to default options and save in DB
282
- */
283
- public function resetToDefaultOptions()
284
- {
285
- $this->options = $this->default_options;
286
- $this->saveOptions($this->default_options);
287
- }
288
-
289
- /**
290
- * Display or retrieve the HTML dropdown list of categories.
291
- *
292
- * The list of arguments is below:
293
- * 'show_option_all' (string) - Text to display for showing all categories.
294
- * 'show_option_none' (string) - Text to display for showing no categories.
295
- * 'orderby' (string) default is 'ID' - What column to use for ordering the
296
- * categories.
297
- * 'order' (string) default is 'ASC' - What direction to order categories.
298
- * 'show_last_update' (bool|int) default is 0 - See {@link get_categories()}
299
- * 'show_count' (bool|int) default is 0 - Whether to show how many posts are
300
- * in the category.
301
- * 'hide_empty' (bool|int) default is 1 - Whether to hide categories that
302
- * don't have any posts attached to them.
303
- * 'child_of' (int) default is 0 - See {@link get_categories()}.
304
- * 'exclude' (string) - See {@link get_categories()}.
305
- * 'echo' (bool|int) default is 1 - Whether to display or retrieve content.
306
- * 'depth' (int) - The max depth.
307
- * 'tab_index' (int) - Tab index for select element.
308
- * 'name' (string) - The name attribute value for selected element.
309
- * 'class' (string) - The class attribute value for selected element.
310
- * 'selected' (int) - Which category ID is selected.
311
- *
312
- * The 'hierarchical' argument, which is disabled by default, will override the
313
- * depth argument, unless it is true. When the argument is false, it will
314
- * display all of the categories. When it is enabled it will use the value in
315
- * the 'depth' argument.
316
- *
317
- * @since 2.1.0
318
- *
319
- * @param string|array $args
320
- * Optional. Override default arguments.
321
- * @return string HTML content only if 'echo' argument is 0.
322
- */
323
- public function avh_wp_dropdown_categories($args = array())
324
- {
325
- $mywalker = new AVH_Walker_CategoryDropdown();
326
-
327
- // @format_off
328
- $defaults = array('show_option_all' => '', 'show_option_none' => '', 'orderby' => 'id', 'order' => 'ASC', 'show_last_update' => 0, 'show_count' => 0, 'hide_empty' => 1, 'child_of' => 0, 'exclude' => '', 'echo' => 1, 'selected' => 0, 'hierarchical' => 0, 'name' => 'cat', 'id' => '', 'class' => 'postform', 'depth' => 0, 'tab_index' => 0, 'taxonomy' => 'category', 'walker' => $mywalker, 'hide_if_empty' => false);
329
- // @format_on
330
- $defaults['selected'] = (is_category()) ? get_query_var('cat') : 0;
331
-
332
- $r = wp_parse_args($args, $defaults);
333
-
334
- if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
335
- $r['pad_counts'] = true;
336
- }
337
-
338
- $r['include_last_update_time'] = $r['show_last_update'];
339
- extract($r);
340
-
341
- $tab_index_attribute = '';
342
- if ((int) $tab_index > 0) {
343
- $tab_index_attribute = ' tabindex="' . $tab_index . '"';
344
- }
345
-
346
- $categories = get_terms($taxonomy, $r);
347
- $name = esc_attr($name);
348
- $class = esc_attr($class);
349
- $id = $id ? esc_attr($id) : $name;
350
-
351
- if (!$r['hide_if_empty'] || !empty($categories)) {
352
- $output = "<select name='$name' id='$id' class='$class' $tab_index_attribute>\n";
353
- } else {
354
- $output = '';
355
- }
356
-
357
- if (empty($categories) && !$r['hide_if_empty'] && !empty($show_option_none)) {
358
- $show_option_none = apply_filters('list_cats', $show_option_none);
359
- $output .= "\t<option value='-1' selected='selected'>$show_option_none</option>\n";
360
- }
361
- if (!empty($categories)) {
362
-
363
- if ($show_option_all) {
364
- $show_option_all = apply_filters('list_cats', $show_option_all);
365
- $selected = ('0' === strval($r['selected'])) ? " selected='selected'" : '';
366
- $output .= "\t" . '<option value="0"' . $selected . '>' . $show_option_all . '</option>' . "\n";
367
- }
368
-
369
- if ($show_option_none) {
370
- $show_option_none = apply_filters('list_cats', $show_option_none);
371
- $selected = ('-1' === strval($r['selected'])) ? " selected='selected'" : '';
372
- $output .= "\t" . '<option value="-1"' . $selected . '>' . $show_option_none . '</option>' . "\n";
373
- }
374
-
375
- if ($hierarchical) {
376
- $depth = $r['depth']; // Walk the full depth.
377
- } else {
378
- $depth = -1; // Flat
379
- }
380
- $output .= walk_category_dropdown_tree($categories, $depth, $r);
381
- }
382
- if (!$r['hide_if_empty'] || !empty($categories)) {
383
- $output .= "</select>\n";
384
- }
385
-
386
- $output = apply_filters('wp_dropdown_cats', $output);
387
-
388
- if ($echo) {
389
- echo $output;
390
- }
391
-
392
- return $output;
393
- }
394
-
395
- /**
396
- * Display or retrieve the HTML list of categories.
397
- *
398
- * The list of arguments is below:
399
- * 'show_option_all' (string) - Text to display for showing all categories.
400
- * 'orderby' (string) default is 'ID' - What column to use for ordering the
401
- * categories.
402
- * 'order' (string) default is 'ASC' - What direction to order categories.
403
- * 'show_last_update' (bool|int) default is 0 - See {@link
404
- * walk_category_dropdown_tree()}
405
- * 'show_count' (bool|int) default is 0 - Whether to show how many posts are
406
- * in the category.
407
- * 'hide_empty' (bool|int) default is 1 - Whether to hide categories that
408
- * don't have any posts attached to them.
409
- * 'use_desc_for_title' (bool|int) default is 1 - Whether to use the
410
- * description instead of the category title.
411
- * 'feed' - See {@link get_categories()}.
412
- * 'feed_type' - See {@link get_categories()}.
413
- * 'feed_image' - See {@link get_categories()}.
414
- * 'child_of' (int) default is 0 - See {@link get_categories()}.
415
- * 'exclude' (string) - See {@link get_categories()}.
416
- * 'exclude_tree' (string) - See {@link get_categories()}.
417
- * 'echo' (bool|int) default is 1 - Whether to display or retrieve content.
418
- * 'current_category' (int) - See {@link get_categories()}.
419
- * 'hierarchical' (bool) - See {@link get_categories()}.
420
- * 'title_li' (string) - See {@link get_categories()}.
421
- * 'depth' (int) - The max depth.
422
- *
423
- * @since 2.1.0
424
- *
425
- * @param string|array $args
426
- * Optional. Override default arguments.
427
- * @return string HTML content only if 'echo' argument is 0.
428
- */
429
- public function avh_wp_list_categories($args = array())
430
- {
431
- $mywalker = new AVHEC_Walker_Category();
432
- $defaults = array('show_option_all' => '', 'orderby' => 'name', 'order' => 'ASC', 'show_last_update' => 0, 'style' => 'list', 'show_count' => 0, 'hide_empty' => 1, 'use_desc_for_title' => 1, 'child_of' => 0, 'feed' => '', 'feed_type' => '', 'feed_image' => '', 'exclude' => '', 'exclude_tree' => '', 'current_category' => 0, 'hierarchical' => true, 'title_li' => __('Categories'), 'echo' => 1, 'depth' => 0, 'walker' => $mywalker);
433
-
434
- $r = wp_parse_args($args, $defaults);
435
-
436
- if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
437
- $r['pad_counts'] = true;
438
- }
439
-
440
- if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
441
- $r['pad_counts'] = true;
442
- }
443
-
444
- if (isset($r['show_date'])) {
445
- $r['include_last_update_time'] = $r['show_date'];
446
- }
447
-
448
- if (true == $r['hierarchical']) {
449
- $r['exclude_tree'] = $r['exclude'];
450
- $r['exclude'] = '';
451
- }
452
-
453
- extract($r);
454
-
455
- $categories = get_categories($r);
456
-
457
- $output = '';
458
- if ($title_li && 'list' == $style) {
459
- $output = '<li class="categories">' . $r['title_li'] . '<ul>';
460
- }
461
-
462
- if (empty($categories)) {
463
- if ('list' == $style) {
464
- $output .= '<li>' . __("No categories") . '</li>';
465
- } else {
466
- $output .= __("No categories");
467
- }
468
- } else {
469
- global $wp_query;
470
-
471
- if (!empty($show_option_all)) {
472
- if ('list' == $style) {
473
- $output .= '<li><a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a></li>';
474
- } else {
475
- $output .= '<a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a>';
476
- }
477
- }
478
- if (empty($r['current_category']) && is_category()) {
479
- $r['current_category'] = $wp_query->get_queried_object_id();
480
- }
481
-
482
- if ($hierarchical) {
483
- $depth = $r['depth'];
484
- } else {
485
- $depth = -1; // Flat.
486
- }
487
-
488
- $output .= walk_category_tree($categories, $depth, $r);
489
- }
490
-
491
- if ($title_li && 'list' == $style) {
492
- $output .= '</ul></li>';
493
- }
494
-
495
- $output = apply_filters('wp_list_categories', $output);
496
-
497
- if ($echo) {
498
- echo $output;
499
- } else {
500
- return $output;
501
- }
502
- }
503
-
504
- public function getCategories()
505
- {
506
- static $_categories = null;
507
- if (null === $_categories) {
508
- $_categories = get_categories('get=all');
509
- }
510
-
511
- return $_categories;
512
- }
513
-
514
- public function getCategoriesId($categories)
515
- {
516
- static $_categories_id = null;
517
- if (null == $_categories_id) {
518
- foreach ($categories as $key => $category) {
519
- $_categories_id[$category->term_id] = $key;
520
- }
521
- }
522
-
523
- return $_categories_id;
524
- }
525
- }
526
-
527
  /**
528
- * Create HTML dropdown list of Categories.
529
  *
530
  * @uses Walker
531
  */
532
- class AVH_Walker_CategoryDropdown extends Walker_CategoryDropdown
533
- {
534
-
535
- public function walk($elements, $max_depth)
536
- {
537
- $args = array_slice(func_get_args(), 2);
538
- $output = '';
539
-
540
- if ($max_depth < -1) {
541
- return $output;
542
- }
543
-
544
- if (empty($elements)) {
545
- return $output;
546
- }
547
-
548
- $id_field = $this->db_fields['id'];
549
- $parent_field = $this->db_fields['parent'];
550
-
551
- // flat display
552
- if (-1 == $max_depth) {
553
- $empty_array = array();
554
- foreach ($elements as $e) {
555
- $this->display_element($e, $empty_array, 1, 0, $args, $output);
556
- }
557
-
558
- return $output;
559
- }
560
-
561
- /*
562
- * need to display in hierarchical order seperate elements into two buckets: top level and children elements children_elements is two dimensional array, eg. children_elements[10][] contains all sub-elements whose parent is 10.
563
- */
564
- $top_level_elements = array();
565
- $children_elements = array();
566
- foreach ($elements as $e) {
567
- if (0 == $e->$parent_field) {
568
- $top_level_elements[] = $e;
569
- } else {
570
- $children_elements[$e->$parent_field][] = $e;
571
- }
572
- }
573
-
574
- /*
575
- * when none of the elements is top level assume the first one must be root of the sub elements
576
- */
577
- if (empty($top_level_elements)) {
578
-
579
- $first = array_slice($elements, 0, 1);
580
- $root = $first[0];
581
-
582
- $top_level_elements = array();
583
- $children_elements = array();
584
- foreach ($elements as $e) {
585
- if ($root->$parent_field == $e->$parent_field) {
586
- $top_level_elements[] = $e;
587
- } else {
588
- $children_elements[$e->$parent_field][] = $e;
589
- }
590
- }
591
- }
592
-
593
- foreach ($top_level_elements as $e) {
594
- $this->display_element($e, $children_elements, $max_depth, 0, $args, $output);
595
- }
596
-
597
- /*
598
- * if we are displaying all levels, and remaining children_elements is not empty, then we got orphans, which should be displayed regardless
599
- */
600
- if ((0 == $max_depth) && count($children_elements) > 0) {
601
- $empty_array = array();
602
- foreach ($children_elements as $orphans) {
603
- foreach ($orphans as $op) {
604
- $this->display_element($op, $empty_array, 1, 0, $args, $output);
605
- }
606
- }
607
- }
608
-
609
- return $output;
610
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
611
  }
612
 
613
  /**
614
- * Create HTML list of categories.
615
  *
616
  * @uses Walker
617
  */
618
- class AVHEC_Walker_Category extends Walker
619
- {
620
-
621
- /**
622
- *
623
- * @see Walker::$tree_type
624
- * @since 2.1.0
625
- * @var string
626
- */
627
- public $tree_type = 'category';
628
-
629
- /**
630
- *
631
- * @see Walker::$db_fields
632
- * @since 2.1.0
633
- * @todo Decouple this
634
- * @var array
635
- */
636
- public $db_fields = array('parent' => 'parent', 'id' => 'term_id');
637
-
638
- /**
639
- *
640
- * @see Walker::start_lvl()
641
- * @since 2.1.0
642
- *
643
- * @param string $output
644
- * Passed by reference. Used to append additional content.
645
- * @param int $depth
646
- * Depth of category. Used for tab indentation.
647
- * @param array $args
648
- * Will only append content if style argument value is 'list'.
649
- */
650
- public function start_lvl(&$output, $depth = 0, $args = array())
651
- {
652
- if ('list' != $args['style']) {
653
- return;
654
- }
655
-
656
- $indent = str_repeat("\t", $depth);
657
- $output .= $indent . '<ul class="children">' . "\n";
658
- }
659
-
660
- /**
661
- *
662
- * @see Walker::end_lvl()
663
- * @since 2.1.0
664
- *
665
- * @param string $output
666
- * Passed by reference. Used to append additional content.
667
- * @param int $depth
668
- * Depth of category. Used for tab indentation.
669
- * @param array $args
670
- * Will only append content if style argument value is 'list'.
671
- */
672
- public function end_lvl(&$output, $depth = 0, $args = array())
673
- {
674
- if ('list' != $args['style']) {
675
- return;
676
- }
677
-
678
- $indent = str_repeat("\t", $depth);
679
- $output .= $indent . '</ul>' . "\n";
680
- }
681
-
682
- /**
683
- *
684
- * @see Walker::start_el()
685
- * @since 2.1.0
686
- *
687
- * @param string $output
688
- * Passed by reference. Used to append additional content.
689
- * @param object $object
690
- * Category data object.
691
- * @param int $depth
692
- * Depth of category in reference to parents.
693
- * @param array $args
694
- */
695
- public function start_el(&$output, $object, $depth = 0, $args = array(), $current_object_id = 0)
696
- {
697
- extract($args);
698
-
699
- $cat_name = esc_attr($object->name);
700
- $cat_name = apply_filters('list_cats', $cat_name, $object);
701
- $link = '<div class="avhec-widget-line"><a href="' . get_category_link($object->term_id) . '" ';
702
- if ($use_desc_for_title == 0 || empty($object->description)) {
703
- $link .= 'title="' . sprintf(__('View all posts filed under %s'), $cat_name) . '"';
704
- } else {
705
- $link .= 'title="' . esc_attr(strip_tags(apply_filters('category_description', $object->description, $object))) . '"';
706
- }
707
- $link .= '>';
708
- $link .= $cat_name . '</a>';
709
-
710
- if ((!empty($feed_image)) || (!empty($feed))) {
711
- $link .= '<div class="avhec-widget-rss"> ';
712
-
713
- if (empty($feed_image)) {
714
- $link .= '(';
715
- }
716
-
717
- $link .= '<a href="' . get_category_feed_link($object->term_id, $feed_type) . '"';
718
-
719
- if (empty($feed)) {
720
- $alt = ' alt="' . sprintf(__('Feed for all posts filed under %s'), $cat_name) . '"';
721
- } else {
722
- $title = ' title="' . $feed . '"';
723
- $alt = ' alt="' . $feed . '"';
724
- $name = $feed;
725
- $link .= $title;
726
- }
727
-
728
- $link .= '>';
729
-
730
- if (empty($feed_image)) {
731
- $link .= $name;
732
- } else {
733
- $link .= '<img src="' . $feed_image . '"' . $alt . $title . ' />';
734
- }
735
- $link .= '</a>';
736
- if (empty($feed_image)) {
737
- $link .= ')';
738
- }
739
- $link .= '</div>';
740
- }
741
-
742
- if (isset($show_count) && $show_count) {
743
- $link .= '<div class="avhec-widget-count"> (' . intval($object->count) . ')</div>';
744
- }
745
-
746
- if (isset($show_date) && $show_date) {
747
- $link .= ' ' . gmdate('Y-m-d', $object->last_update_timestamp);
748
- }
749
-
750
- // When on a single post get the post's category. This ensures that that category will be given the CSS style of "current category".
751
- if (is_single()) {
752
- $post_cats = get_the_category();
753
- $current_category = $post_cats[0]->term_id;
754
- }
755
-
756
- if (isset($current_category) && $current_category) {
757
- $_current_category = get_category($current_category);
758
- }
759
-
760
- if ('list' == $args['style']) {
761
- $output .= "\t" . '<li';
762
- $class = 'cat-item cat-item-' . $object->term_id;
763
- if (isset($current_category) && $current_category && ($object->term_id == $current_category)) {
764
- $class .= ' current-cat';
765
- } elseif (isset($_current_category) && $_current_category && ($object->term_id == $_current_category->parent)) {
766
- $class .= ' current-cat-parent';
767
- }
768
- $output .= ' class="' . $class . '"';
769
- $output .= '>' . $link . '</div>' . "\n";
770
- } else {
771
- $output .= "\t" . $link . '</div><br />' . "\n";
772
- }
773
- }
774
-
775
- /**
776
- *
777
- * @see Walker::end_el()
778
- * @since 2.1.0
779
- *
780
- * @param string $output
781
- * Passed by reference. Used to append additional content.
782
- * @param object $page
783
- * Not used.
784
- * @param int $depth
785
- * Depth of category. Not used.
786
- * @param array $args
787
- * Only uses 'list' for whether should append to output.
788
- */
789
- public function end_el(&$output, $object, $depth = 0, $args = array())
790
- {
791
- if ('list' != $args['style']) {
792
- return;
793
- }
794
-
795
- $output .= '</li>' . "\n";
796
- }
797
  }
1
  <?php
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  /**
4
+ * Create HTML list of categories.
5
  *
6
  * @uses Walker
7
  */
8
+ class AVHEC_Walker_Category extends Walker {
9
+ /**
10
+ * @see Walker::$db_fields
11
+ * @since 2.1.0
12
+ * @todo Decouple this
13
+ * @var array
14
+ */
15
+ public $db_fields = array('parent' => 'parent', 'id' => 'term_id');
16
+ /**
17
+ * @see Walker::$tree_type
18
+ * @since 2.1.0
19
+ * @var string
20
+ */
21
+ public $tree_type = 'category';
22
+
23
+ /**
24
+ * @see Walker::end_el()
25
+ * @since 2.1.0
26
+ *
27
+ * @param string $output
28
+ * Passed by reference. Used to append additional content.
29
+ * @param object $page
30
+ * Not used.
31
+ * @param int $depth
32
+ * Depth of category. Not used.
33
+ * @param array $args
34
+ * Only uses 'list' for whether should append to output.
35
+ */
36
+ public function end_el(&$output, $object, $depth = 0, $args = array()) {
37
+ if ('list' != $args['style']) {
38
+ return;
39
+ }
40
+
41
+ $output .= '</li>' . "\n";
42
+ }
43
+
44
+ /**
45
+ * @see Walker::end_lvl()
46
+ * @since 2.1.0
47
+ *
48
+ * @param string $output
49
+ * Passed by reference. Used to append additional content.
50
+ * @param int $depth
51
+ * Depth of category. Used for tab indentation.
52
+ * @param array $args
53
+ * Will only append content if style argument value is 'list'.
54
+ */
55
+ public function end_lvl(&$output, $depth = 0, $args = array()) {
56
+ if ('list' != $args['style']) {
57
+ return;
58
+ }
59
+
60
+ $indent = str_repeat("\t", $depth);
61
+ $output .= $indent . '</ul>' . "\n";
62
+ }
63
+
64
+ /**
65
+ * @see Walker::start_el()
66
+ * @since 2.1.0
67
+ *
68
+ * @param string $output
69
+ * Passed by reference. Used to append additional content.
70
+ * @param object $object
71
+ * Category data object.
72
+ * @param int $depth
73
+ * Depth of category in reference to parents.
74
+ * @param array $args
75
+ */
76
+ public function start_el(&$output, $object, $depth = 0, $args = array(), $current_object_id = 0) {
77
+ extract($args);
78
+
79
+ $cat_name = esc_attr($object->name);
80
+ $cat_name = apply_filters('list_cats', $cat_name, $object);
81
+ $link = '<div class="avhec-widget-line"><a href="' . get_category_link($object->term_id) . '" ';
82
+ if ($use_desc_for_title == 0 || empty($object->description)) {
83
+ $link .= 'title="' . sprintf(__('View all posts filed under %s'), $cat_name) . '"';
84
+ } else {
85
+ $link .= 'title="' .
86
+ esc_attr(strip_tags(apply_filters('category_description', $object->description, $object))) .
87
+ '"';
88
+ }
89
+ $link .= '>';
90
+ $link .= $cat_name . '</a>';
91
+
92
+ if (( ! empty($feed_image)) || ( ! empty($feed))) {
93
+ $link .= '<div class="avhec-widget-rss"> ';
94
+
95
+ if (empty($feed_image)) {
96
+ $link .= '(';
97
+ }
98
+
99
+ $link .= '<a href="' . get_category_feed_link($object->term_id, $feed_type) . '"';
100
+
101
+ if (empty($feed)) {
102
+ $alt = ' alt="' . sprintf(__('Feed for all posts filed under %s'), $cat_name) . '"';
103
+ } else {
104
+ $title = ' title="' . $feed . '"';
105
+ $alt = ' alt="' . $feed . '"';
106
+ $name = $feed;
107
+ $link .= $title;
108
+ }
109
+
110
+ $link .= '>';
111
+
112
+ if (empty($feed_image)) {
113
+ $link .= $name;
114
+ } else {
115
+ $link .= '<img src="' . $feed_image . '"' . $alt . $title . ' />';
116
+ }
117
+ $link .= '</a>';
118
+ if (empty($feed_image)) {
119
+ $link .= ')';
120
+ }
121
+ $link .= '</div>';
122
+ }
123
+
124
+ if (isset($show_count) && $show_count) {
125
+ $link .= '<div class="avhec-widget-count"> (' . intval($object->count) . ')</div>';
126
+ }
127
+
128
+ if (isset($show_date) && $show_date) {
129
+ $link .= ' ' . gmdate('Y-m-d', $object->last_update_timestamp);
130
+ }
131
+
132
+ // When on a single post get the post's category. This ensures that that category will be given the CSS style of "current category".
133
+ if (is_single()) {
134
+ $post_cats = get_the_category();
135
+ $current_category = $post_cats[0]->term_id;
136
+ }
137
+
138
+ if (isset($current_category) && $current_category) {
139
+ $_current_category = get_category($current_category);
140
+ }
141
+
142
+ if ('list' == $args['style']) {
143
+ $output .= "\t" . '<li';
144
+ $class = 'cat-item cat-item-' . $object->term_id;
145
+ if (isset($current_category) && $current_category && ($object->term_id == $current_category)) {
146
+ $class .= ' current-cat';
147
+ } elseif (isset($_current_category) &&
148
+ $_current_category &&
149
+ ($object->term_id == $_current_category->parent)
150
+ ) {
151
+ $class .= ' current-cat-parent';
152
+ }
153
+ $output .= ' class="' . $class . '"';
154
+ $output .= '>' . $link . '</div>' . "\n";
155
+ } else {
156
+ $output .= "\t" . $link . '</div><br />' . "\n";
157
+ }
158
+ }
159
+
160
+ /**
161
+ * @see Walker::start_lvl()
162
+ * @since 2.1.0
163
+ *
164
+ * @param string $output
165
+ * Passed by reference. Used to append additional content.
166
+ * @param int $depth
167
+ * Depth of category. Used for tab indentation.
168
+ * @param array $args
169
+ * Will only append content if style argument value is 'list'.
170
+ */
171
+ public function start_lvl(&$output, $depth = 0, $args = array()) {
172
+ if ('list' != $args['style']) {
173
+ return;
174
+ }
175
+
176
+ $indent = str_repeat("\t", $depth);
177
+ $output .= $indent . '<ul class="children">' . "\n";
178
+ }
179
+ }
180
+
181
+ class AVH_EC_Core {
182
+ public $comment;
183
+ public $db_options_core;
184
+ public $db_options_tax_meta;
185
+ public $default_options;
186
+ public $default_options_category_group;
187
+ public $default_options_general;
188
+ public $default_options_sp_category_group;
189
+ public $info;
190
+ public $options;
191
+ public $version;
192
+
193
+ /**
194
+ * PHP5 constructor
195
+ */
196
+ public function __construct() {
197
+ /**
198
+ * @var AVH_EC_Category_Group
199
+ */
200
+ $catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
201
+
202
+ $this->version = '4.0.3-dev.1';
203
+ $this->comment = '<!-- AVH Extended Categories version ' .
204
+ $this->version .
205
+ ' | http://blog.avirtualhome.com/wordpress-plugins/ -->';
206
+ $this->db_options_core = 'avhec';
207
+ $this->db_options_tax_meta = 'avhec-tax_meta';
208
+
209
+ add_action('init', array($this, 'handleInitializePlugin'), 10);
210
+ }
211
+
212
+ public function applyOrderFilter($orderby, $args) {
213
+ switch ($args['orderby']) {
214
+ case 'avhec_manualorder':
215
+ $new_orderby = 't.avhec_term_order';
216
+ break;
217
+ case 'avhec_3rdparty_mycategoryorder':
218
+ $new_orderby = 't.term_order';
219
+ break;
220
+ default:
221
+ $new_orderby = $orderby;
222
+ break;
223
+ }
224
+
225
+ return $new_orderby;
226
+ }
227
+
228
+ /**
229
+ * Display or retrieve the HTML dropdown list of categories.
230
+ * The list of arguments is below:
231
+ * 'show_option_all' (string) - Text to display for showing all categories.
232
+ * 'show_option_none' (string) - Text to display for showing no categories.
233
+ * 'orderby' (string) default is 'ID' - What column to use for ordering the
234
+ * categories.
235
+ * 'order' (string) default is 'ASC' - What direction to order categories.
236
+ * 'show_last_update' (bool|int) default is 0 - See {@link get_categories()}
237
+ * 'show_count' (bool|int) default is 0 - Whether to show how many posts are
238
+ * in the category.
239
+ * 'hide_empty' (bool|int) default is 1 - Whether to hide categories that
240
+ * don't have any posts attached to them.
241
+ * 'child_of' (int) default is 0 - See {@link get_categories()}.
242
+ * 'exclude' (string) - See {@link get_categories()}.
243
+ * 'echo' (bool|int) default is 1 - Whether to display or retrieve content.
244
+ * 'depth' (int) - The max depth.
245
+ * 'tab_index' (int) - Tab index for select element.
246
+ * 'name' (string) - The name attribute value for selected element.
247
+ * 'class' (string) - The class attribute value for selected element.
248
+ * 'selected' (int) - Which category ID is selected.
249
+ * The 'hierarchical' argument, which is disabled by default, will override the
250
+ * depth argument, unless it is true. When the argument is false, it will
251
+ * display all of the categories. When it is enabled it will use the value in
252
+ * the 'depth' argument.
253
+ *
254
+ * @since 2.1.0
255
+ *
256
+ * @param string|array $args
257
+ * Optional. Override default arguments.
258
+ *
259
+ * @return string HTML content only if 'echo' argument is 0.
260
+ */
261
+ public function avh_wp_dropdown_categories($args = array()) {
262
+ $mywalker = new AVH_Walker_CategoryDropdown();
263
+
264
+ // @format_off
265
+ $defaults = array(
266
+ 'show_option_all' => '',
267
+ 'show_option_none' => '',
268
+ 'orderby' => 'id',
269
+ 'order' => 'ASC',
270
+ 'show_last_update' => 0,
271
+ 'show_count' => 0,
272
+ 'hide_empty' => 1,
273
+ 'child_of' => 0,
274
+ 'exclude' => '',
275
+ 'echo' => 1,
276
+ 'selected' => 0,
277
+ 'hierarchical' => 0,
278
+ 'name' => 'cat',
279
+ 'id' => '',
280
+ 'class' => 'postform',
281
+ 'depth' => 0,
282
+ 'tab_index' => 0,
283
+ 'taxonomy' => 'category',
284
+ 'walker' => $mywalker,
285
+ 'hide_if_empty' => false
286
+ );
287
+ // @format_on
288
+ $defaults['selected'] = (is_category()) ? get_query_var('cat') : 0;
289
+
290
+ $r = wp_parse_args($args, $defaults);
291
+
292
+ if ( ! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
293
+ $r['pad_counts'] = true;
294
+ }
295
+
296
+ $r['include_last_update_time'] = $r['show_last_update'];
297
+ extract($r);
298
+
299
+ $tab_index_attribute = '';
300
+ if ((int) $tab_index > 0) {
301
+ $tab_index_attribute = ' tabindex="' . $tab_index . '"';
302
+ }
303
+
304
+ $categories = get_terms($taxonomy, $r);
305
+ $name = esc_attr($name);
306
+ $class = esc_attr($class);
307
+ $id = $id ? esc_attr($id) : $name;
308
+
309
+ if ( ! $r['hide_if_empty'] || ! empty($categories)) {
310
+ $output = "<select name='$name' id='$id' class='$class' $tab_index_attribute>\n";
311
+ } else {
312
+ $output = '';
313
+ }
314
+
315
+ if (empty($categories) && ! $r['hide_if_empty'] && ! empty($show_option_none)) {
316
+ $show_option_none = apply_filters('list_cats', $show_option_none);
317
+ $output .= "\t<option value='-1' selected='selected'>$show_option_none</option>\n";
318
+ }
319
+ if ( ! empty($categories)) {
320
+
321
+ if ($show_option_all) {
322
+ $show_option_all = apply_filters('list_cats', $show_option_all);
323
+ $selected = ('0' === strval($r['selected'])) ? " selected='selected'" : '';
324
+ $output .= "\t" . '<option value="0"' . $selected . '>' . $show_option_all . '</option>' . "\n";
325
+ }
326
+
327
+ if ($show_option_none) {
328
+ $show_option_none = apply_filters('list_cats', $show_option_none);
329
+ $selected = ('-1' === strval($r['selected'])) ? " selected='selected'" : '';
330
+ $output .= "\t" . '<option value="-1"' . $selected . '>' . $show_option_none . '</option>' . "\n";
331
+ }
332
+
333
+ if ($hierarchical) {
334
+ $depth = $r['depth']; // Walk the full depth.
335
+ } else {
336
+ $depth = - 1; // Flat
337
+ }
338
+ $output .= walk_category_dropdown_tree($categories, $depth, $r);
339
+ }
340
+ if ( ! $r['hide_if_empty'] || ! empty($categories)) {
341
+ $output .= "</select>\n";
342
+ }
343
+
344
+ $output = apply_filters('wp_dropdown_cats', $output);
345
+
346
+ if ($echo) {
347
+ echo $output;
348
+ }
349
+
350
+ return $output;
351
+ }
352
+
353
+ /**
354
+ * Display or retrieve the HTML list of categories.
355
+ * The list of arguments is below:
356
+ * 'show_option_all' (string) - Text to display for showing all categories.
357
+ * 'orderby' (string) default is 'ID' - What column to use for ordering the
358
+ * categories.
359
+ * 'order' (string) default is 'ASC' - What direction to order categories.
360
+ * 'show_last_update' (bool|int) default is 0 - See {@link
361
+ * walk_category_dropdown_tree()}
362
+ * 'show_count' (bool|int) default is 0 - Whether to show how many posts are
363
+ * in the category.
364
+ * 'hide_empty' (bool|int) default is 1 - Whether to hide categories that
365
+ * don't have any posts attached to them.
366
+ * 'use_desc_for_title' (bool|int) default is 1 - Whether to use the
367
+ * description instead of the category title.
368
+ * 'feed' - See {@link get_categories()}.
369
+ * 'feed_type' - See {@link get_categories()}.
370
+ * 'feed_image' - See {@link get_categories()}.
371
+ * 'child_of' (int) default is 0 - See {@link get_categories()}.
372
+ * 'exclude' (string) - See {@link get_categories()}.
373
+ * 'exclude_tree' (string) - See {@link get_categories()}.
374
+ * 'echo' (bool|int) default is 1 - Whether to display or retrieve content.
375
+ * 'current_category' (int) - See {@link get_categories()}.
376
+ * 'hierarchical' (bool) - See {@link get_categories()}.
377
+ * 'title_li' (string) - See {@link get_categories()}.
378
+ * 'depth' (int) - The max depth.
379
+ *
380
+ * @since 2.1.0
381
+ *
382
+ * @param string|array $args
383
+ * Optional. Override default arguments.
384
+ *
385
+ * @return string HTML content only if 'echo' argument is 0.
386
+ */
387
+ public function avh_wp_list_categories($args = array()) {
388
+ $mywalker = new AVHEC_Walker_Category();
389
+ $defaults = array(
390
+ 'show_option_all' => '',
391
+ 'orderby' => 'name',
392
+ 'order' => 'ASC',
393
+ 'show_last_update' => 0,
394
+ 'style' => 'list',
395
+ 'show_count' => 0,
396
+ 'hide_empty' => 1,
397
+ 'use_desc_for_title' => 1,
398
+ 'child_of' => 0,
399
+ 'feed' => '',
400
+ 'feed_type' => '',
401
+ 'feed_image' => '',
402
+ 'exclude' => '',
403
+ 'exclude_tree' => '',
404
+ 'current_category' => 0,
405
+ 'hierarchical' => true,
406
+ 'title_li' => __('Categories'),
407
+ 'echo' => 1,
408
+ 'depth' => 0,
409
+ 'walker' => $mywalker
410
+ );
411
+
412
+ $r = wp_parse_args($args, $defaults);
413
+
414
+ if ( ! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
415
+ $r['pad_counts'] = true;
416
+ }
417
+
418
+ if ( ! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
419
+ $r['pad_counts'] = true;
420
+ }
421
+
422
+ if (isset($r['show_date'])) {
423
+ $r['include_last_update_time'] = $r['show_date'];
424
+ }
425
+
426
+ if (true == $r['hierarchical']) {
427
+ $r['exclude_tree'] = $r['exclude'];
428
+ $r['exclude'] = '';
429
+ }
430
+
431
+ extract($r);
432
+
433
+ $categories = get_categories($r);
434
+
435
+ $output = '';
436
+ if ($title_li && 'list' == $style) {
437
+ $output = '<li class="categories">' . $r['title_li'] . '<ul>';
438
+ }
439
+
440
+ if (empty($categories)) {
441
+ if ('list' == $style) {
442
+ $output .= '<li>' . __("No categories") . '</li>';
443
+ } else {
444
+ $output .= __("No categories");
445
+ }
446
+ } else {
447
+ global $wp_query;
448
+
449
+ if ( ! empty($show_option_all)) {
450
+ if ('list' == $style) {
451
+ $output .= '<li><a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a></li>';
452
+ } else {
453
+ $output .= '<a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a>';
454
+ }
455
+ }
456
+ if (empty($r['current_category']) && is_category()) {
457
+ $r['current_category'] = $wp_query->get_queried_object_id();
458
+ }
459
+
460
+ if ($hierarchical) {
461
+ $depth = $r['depth'];
462
+ } else {
463
+ $depth = - 1; // Flat.
464
+ }
465
+
466
+ $output .= walk_category_tree($categories, $depth, $r);
467
+ }
468
+
469
+ if ($title_li && 'list' == $style) {
470
+ $output .= '</ul></li>';
471
+ }
472
+
473
+ $output = apply_filters('wp_list_categories', $output);
474
+
475
+ if ($echo) {
476
+ echo $output;
477
+ } else {
478
+ return $output;
479
+ }
480
+ }
481
+
482
+ /**
483
+ * Checks if running version is newer and do upgrades if necessary
484
+ *
485
+ * @since 1.2.3
486
+ */
487
+ public function doUpdateOptions($db_version) {
488
+ $options = $this->getOptions();
489
+
490
+ // Add none existing sections and/or elements to the options
491
+ foreach ($this->default_options as $section => $default_data) {
492
+ if ( ! array_key_exists($section, $options)) {
493
+ $options[ $section ] = $default_data;
494
+ continue;
495
+ }
496
+ foreach ($default_data as $element => $default_value) {
497
+ if ( ! array_key_exists($element, $options[ $section ])) {
498
+ $options[ $section ][ $element ] = $default_value;
499
+ }
500
+ }
501
+ }
502
+
503
+ // Remove none existing sections and/or elements from the options
504
+ foreach ($options as $section => $data) {
505
+ if ( ! array_key_exists($section, $this->default_options)) {
506
+ unset($options[ $section ]);
507
+ continue;
508
+ }
509
+ foreach ($data as $element => $value) {
510
+ if ( ! array_key_exists($element, $this->default_options[ $section ])) {
511
+ unset($options[ $section ][ $element ]);
512
+ }
513
+ }
514
+ }
515
+ /**
516
+ * Update the options to the latests versions
517
+ */
518
+ $options['general']['version'] = $this->version;
519
+ $options['general']['dbversion'] = $db_version;
520
+ $this->saveOptions($options);
521
+ }
522
+
523
+ /**
524
+ * Get the base directory of a directory structure
525
+ *
526
+ * @param string $directory
527
+ *
528
+ * @return string
529
+ */
530
+ public function getBaseDirectory($directory) {
531
+ // place each directory into array and get the last element
532
+ $directory_array = explode('/', $directory);
533
+ // get highest or top level in array of directory strings
534
+ $public_base = end($directory_array);
535
+
536
+ return $public_base;
537
+ }
538
+
539
+ public function getCategories() {
540
+ static $_categories = null;
541
+ if (null === $_categories) {
542
+ $_categories = get_categories('get=all');
543
+ }
544
+
545
+ return $_categories;
546
+ }
547
+
548
+ public function getCategoriesId($categories) {
549
+ static $_categories_id = null;
550
+ if (null == $_categories_id) {
551
+ foreach ($categories as $key => $category) {
552
+ $_categories_id[ $category->term_id ] = $key;
553
+ }
554
+ }
555
+
556
+ return $_categories_id;
557
+ }
558
+
559
+ /**
560
+ * *******************************
561
+ * *
562
+ * Methods for variable: options *
563
+ * *
564
+ * ******************************
565
+ */
566
+
567
+ /**
568
+ * Get the value for an option element.
569
+ * If there's no option is set on the Admin page, return the default value.
570
+ *
571
+ * @param string $key
572
+ * @param string $option
573
+ *
574
+ * @return mixed
575
+ */
576
+ public function getOptionElement($option, $key) {
577
+ if ($this->options[ $option ][ $key ]) {
578
+ $return = $this->options[ $option ][ $key ]; // From Admin Page
579
+ } else {
580
+ $return = $this->default_options[ $option ][ $key ]; // Default
581
+ }
582
+
583
+ return ($return);
584
+ }
585
+
586
+ /**
587
+ * return array
588
+ */
589
+ public function getOptions() {
590
+ return ($this->options);
591
+ }
592
+
593
+ /**
594
+ * @param array $data
595
+ */
596
+ public function setOptions($options) {
597
+ $this->options = $options;
598
+ }
599
+
600
+ public function handleInitializePlugin() {
601
+ global $wpdb;
602
+
603
+ $catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
604
+ $db_version = 4;
605
+
606
+ $info['siteurl'] = get_option('siteurl');
607
+ $info['plugin_dir'] = AVHEC_PLUGIN_DIR;
608
+ $info['graphics_url'] = AVHEC_PLUGIN_URL . '/images';
609
+
610
+ // Set class property for info
611
+ $this->info = array(
612
+ 'home' => get_option('home'),
613
+ 'siteurl' => $info['siteurl'],
614
+ 'plugin_dir' => $info['plugin_dir'],
615
+ 'js_dir' => $info['plugin_dir'] . '/js',
616
+ 'graphics_url' => $info['graphics_url']
617
+ );
618
+
619
+ // Set the default options
620
+ $this->default_options_general = array(
621
+ 'version' => $this->version,
622
+ 'dbversion' => $db_version,
623
+ 'alternative_name_select_category' => ''
624
+ );
625
+
626
+ // Set the default category group options
627
+ $no_group_id = $catgrp->getTermIDBy('slug', 'none');
628
+ $home_group_id = $catgrp->getTermIDBy('slug', 'home');
629
+ $default_group_id = $catgrp->getTermIDBy('slug', 'all');
630
+ $this->default_options_category_group = array(
631
+ 'no_group' => $no_group_id,
632
+ 'home_group' => $home_group_id,
633
+ 'default_group' => $default_group_id
634
+ );
635
+
636
+ $this->default_options_sp_category_group = array(
637
+ 'home_group' => $home_group_id,
638
+ 'category_group' => $default_group_id,
639
+ 'day_group' => $default_group_id,
640
+ 'month_group' => $default_group_id,
641
+ 'year_group' => $default_group_id,
642
+ 'author_group' => $default_group_id,
643
+ 'search_group' => $default_group_id
644
+ );
645
+
646
+ $this->default_options = array(
647
+ 'general' => $this->default_options_general,
648
+ 'cat_group' => $this->default_options_category_group,
649
+ 'widget_titles' => array(),
650
+ 'sp_cat_group' => $this->default_options_sp_category_group
651
+ );
652
+
653
+ /**
654
+ * Set the options for the program
655
+ */
656
+ $this->loadOptions();
657
+
658
+ // Check if we have to do updates
659
+ if (( ! isset($this->options['general']['dbversion'])) ||
660
+ $this->options['general']['dbversion'] < $db_version
661
+ ) {
662
+ $this->doUpdateOptions($db_version);
663
+ }
664
+
665
+ $db = new AVH_DB();
666
+ if ( ! $db->field_exists('avhec_term_order', $wpdb->terms)) {
667
+ $wpdb->query("ALTER TABLE $wpdb->terms ADD `avhec_term_order` INT( 4 ) null DEFAULT '0'");
668
+ }
669
+
670
+ $this->handleTextdomain();
671
+ add_filter('get_terms_orderby', array($this, 'applyOrderFilter'), 10, 2);
672
+ }
673
+
674
+ /**
675
+ * Loads the i18n
676
+ */
677
+ public function handleTextdomain() {
678
+ load_plugin_textdomain('avh-ec', false, AVHEC_RELATIVE_PLUGIN_DIR . '/lang');
679
+ }
680
+
681
+ /**
682
+ * Used in forms to set the checked option.
683
+ *
684
+ * @param mixed $checked
685
+ * @param mixed_type $current
686
+ *
687
+ * @return string
688
+ * @since 2.0
689
+ */
690
+ public function isChecked($checked, $current) {
691
+ if ($checked == $current) {
692
+ return (' checked="checked"');
693
+ }
694
+
695
+ return ('');
696
+ }
697
+
698
+ /**
699
+ * Used in forms to set the SELECTED option
700
+ *
701
+ * @param string $current
702
+ * @param string $field
703
+ *
704
+ * @return string
705
+ */
706
+ public function isSelected($current, $field) {
707
+ if ($current == $field) {
708
+ return (' SELECTED');
709
+ }
710
+
711
+ return ('');
712
+ }
713
+
714
+ /**
715
+ * Retrieves the plugin options from the WordPress options table and assigns to class variable.
716
+ * If the options do not exists, like a new installation, the options are set to the default value.
717
+ *
718
+ * @return none
719
+ */
720
+ public function loadOptions() {
721
+ $options = get_option($this->db_options_core);
722
+ if (false === $options) { // New installation
723
+ $this->resetToDefaultOptions();
724
+ } else {
725
+ $this->setOptions($options);
726
+ }
727
+ }
728
+
729
+ /**
730
+ * Reset to default options and save in DB
731
+ */
732
+ public function resetToDefaultOptions() {
733
+ $this->options = $this->default_options;
734
+ $this->saveOptions($this->default_options);
735
+ }
736
+
737
+ /**
738
+ * Save all current options and set the options
739
+ */
740
+ public function saveOptions($options) {
741
+ update_option($this->db_options_core, $options);
742
+ wp_cache_flush(); // Delete cache
743
+ $this->setOptions($options);
744
+ }
745
  }
746
 
747
  /**
748
+ * Create HTML dropdown list of Categories.
749
  *
750
  * @uses Walker
751
  */
752
+ class AVH_Walker_CategoryDropdown extends Walker_CategoryDropdown {
753
+ public function walk($elements, $max_depth) {
754
+ $args = array_slice(func_get_args(), 2);
755
+ $output = '';
756
+
757
+ if ($max_depth < - 1) {
758
+ return $output;
759
+ }
760
+
761
+ if (empty($elements)) {
762
+ return $output;
763
+ }
764
+
765
+ $id_field = $this->db_fields['id'];
766
+ $parent_field = $this->db_fields['parent'];
767
+
768
+ // flat display
769
+ if (- 1 == $max_depth) {
770
+ $empty_array = array();
771
+ foreach ($elements as $e) {
772
+ $this->display_element($e, $empty_array, 1, 0, $args, $output);
773
+ }
774
+
775
+ return $output;
776
+ }
777
+
778
+ /*
779
+ * need to display in hierarchical order seperate elements into two buckets: top level and children elements children_elements is two dimensional array, eg. children_elements[10][] contains all sub-elements whose parent is 10.
780
+ */
781
+ $top_level_elements = array();
782
+ $children_elements = array();
783
+ foreach ($elements as $e) {
784
+ if (0 == $e->$parent_field) {
785
+ $top_level_elements[] = $e;
786
+ } else {
787
+ $children_elements[ $e->$parent_field ][] = $e;
788
+ }
789
+ }
790
+
791
+ /*
792
+ * when none of the elements is top level assume the first one must be root of the sub elements
793
+ */
794
+ if (empty($top_level_elements)) {
795
+
796
+ $first = array_slice($elements, 0, 1);
797
+ $root = $first[0];
798
+
799
+ $top_level_elements = array();
800
+ $children_elements = array();
801
+ foreach ($elements as $e) {
802
+ if ($root->$parent_field == $e->$parent_field) {
803
+ $top_level_elements[] = $e;
804
+ } else {
805
+ $children_elements[ $e->$parent_field ][] = $e;
806
+ }
807
+ }
808
+ }
809
+
810
+ foreach ($top_level_elements as $e) {
811
+ $this->display_element($e, $children_elements, $max_depth, 0, $args, $output);
812
+ }
813
+
814
+ /*
815
+ * if we are displaying all levels, and remaining children_elements is not empty, then we got orphans, which should be displayed regardless
816
+ */
817
+ if ((0 == $max_depth) && count($children_elements) > 0) {
818
+ $empty_array = array();
819
+ foreach ($children_elements as $orphans) {
820
+ foreach ($orphans as $op) {
821
+ $this->display_element($op, $empty_array, 1, 0, $args, $output);
822
+ }
823
+ }
824
+ }
825
+
826
+ return $output;
827
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
828
  }
3.6/class/avh-ec.widgets.php CHANGED
@@ -1,982 +1,1229 @@
1
  <?php
2
 
3
  /**
4
- * Widget Class for displaying categories.
5
- * Extended version of the default categories.
6
  */
7
- class WP_Widget_AVH_ExtendedCategories_Normal extends WP_Widget
8
- {
9
-
10
- /**
11
- *
12
- * @var AVH_EC_Core
13
- */
14
- public $core;
15
-
16
- /**
17
- * PHP 5 Constructor
18
- */
19
- public function __construct()
20
- {
21
- $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core');
22
-
23
- // Convert the old option widget_extended_categories to widget_extended-categories
24
- $old = get_option('widget_extended_categories');
25
- if (!(false === $old)) {
26
- update_option('widget_extended-categories', $old);
27
- delete_option('widget_extended_categories');
28
- }
29
- $widget_ops = array('description' => __("An extended version of the default Categories widget.", 'avh-ec'));
30
- WP_Widget::__construct('extended-categories', 'AVH Extended Categories', $widget_ops);
31
-
32
- add_action('wp_print_styles', array($this, 'actionWpPrintStyles'));
33
- }
34
-
35
- public function actionWpPrintStyles()
36
- {
37
- if (!(false === is_active_widget(false, false, $this->id_base, true))) {
38
- wp_register_style('avhec-widget', AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', array(), $this->core->version);
39
- wp_enqueue_style('avhec-widget');
40
- }
41
- }
42
-
43
- /**
44
- * Display the widget
45
- *
46
- * @param unknown_type $args
47
- * @param unknown_type $instance
48
- */
49
- public function widget($args, $instance)
50
- {
51
- extract($args);
52
-
53
- $selectedonly = $instance['selectedonly'];
54
- $c = $instance['count'];
55
- $h = $instance['hierarchical'];
56
- $d = $instance['depth'];
57
- $e = $instance['hide_empty'];
58
- $use_desc_for_title = $instance['use_desc_for_title'];
59
- $s = isset($instance['sort_column']) ? $instance['sort_column'] : 'name';
60
- $o = isset($instance['sort_order']) ? $instance['sort_order'] : 'asc';
61
- $r = ($instance['rssfeed'] == true) ? 'RSS' : '';
62
- $i = isset($instance['rssimage']) ? $instance['rssimage'] : '';
63
- $invert = $instance['invert_included'];
64
-
65
- if (empty($r)) {
66
- $i = '';
67
- }
68
-
69
- if (empty($d)) {
70
- $d = 0;
71
- }
72
-
73
- $title = apply_filters('widget_title', empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']);
74
- $style = empty($instance['style']) ? 'list' : $instance['style'];
75
-
76
- $included_cats = '';
77
- if ($instance['post_category']) {
78
- $post_category = unserialize($instance['post_category']);
79
- $children = array();
80
- if (!$instance['selectedonly']) {
81
- foreach ($post_category as $cat_id) {
82
- $children = array_merge($children, get_term_children($cat_id, 'category'));
83
- }
84
- }
85
- $included_cats = implode(",", array_merge($post_category, $children));
86
- }
87
-
88
- if ($invert) {
89
- $inc_exc = 'exclude';
90
- } else {
91
- $inc_exc = 'include';
92
- }
93
-
94
- $options = $this->core->getOptions();
95
- $show_option_none = __('Select Category', 'avh-ec');
96
- if ($options['general']['alternative_name_select_category']) {
97
- $show_option_none = $options['general']['alternative_name_select_category'];
98
- }
99
-
100
- $cat_args = array($inc_exc => $included_cats, 'orderby' => $s, 'order' => $o, 'show_count' => $c, 'use_desc_for_title' => $use_desc_for_title, 'hide_empty' => $e, 'hierarchical' => $h, 'depth' => $d, 'title_li' => '', 'show_option_none' => $show_option_none, 'feed' => $r, 'feed_image' => $i, 'name' => 'extended-categories-select-' . $this->number);
101
- echo $before_widget;
102
- echo $this->core->comment;
103
- echo $before_title . $title . $after_title;
104
-
105
- if ($style == 'list') {
106
- echo '<ul>';
107
- $this->core->avh_wp_list_categories($cat_args);
108
- echo '</ul>';
109
- } else {
110
- $this->core->avh_wp_dropdown_categories($cat_args);
111
- echo '<script type=\'text/javascript\'>' . "\n";
112
- echo '/* <![CDATA[ */' . "\n";
113
- echo ' var ec_dropdown_' . $this->number . ' = document.getElementById("extended-categories-select-' . $this->number . '");' . "\n";
114
- echo ' function ec_onCatChange_' . $this->number . '() {' . "\n";
115
- echo ' if (ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value > 0) {' . "\n";
116
- echo ' location.href = "' . home_url() . '/?cat="+ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value;' . "\n";
117
- echo ' }' . "\n";
118
- echo ' }' . "\n";
119
- echo ' ec_dropdown_' . $this->number . '.onchange = ec_onCatChange_' . $this->number . ';' . "\n";
120
- echo '/* ]]> */' . "\n";
121
- echo '</script>' . "\n";
122
- }
123
- echo $after_widget;
124
- }
125
-
126
- /**
127
- * When Widget Control Form Is Posted
128
- *
129
- * @param unknown_type $new_instance
130
- * @param unknown_type $old_instance
131
- * @return unknown
132
- */
133
- public function update($new_instance, $old_instance)
134
- {
135
- // update the instance's settings
136
- if (!isset($new_instance['submit'])) {
137
- return false;
138
- }
139
-
140
- $instance = $old_instance;
141
-
142
- $instance['title'] = strip_tags(stripslashes($new_instance['title']));
143
- $instance['selectedonly'] = isset($new_instance['selectedonly']);
144
- $instance['count'] = isset($new_instance['count']);
145
- $instance['hierarchical'] = isset($new_instance['hierarchical']);
146
- $instance['hide_empty'] = isset($new_instance['hide_empty']);
147
- $instance['use_desc_for_title'] = isset($new_instance['use_desc_for_title']);
148
- $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column']));
149
- $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order']));
150
- $instance['style'] = strip_tags(stripslashes($new_instance['style']));
151
- $instance['rssfeed'] = isset($new_instance['rssfeed']);
152
- $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage']));
153
- if (array_key_exists('all', $new_instance['post_category'])) {
154
- $instance['post_category'] = false;
155
- } else {
156
- $instance['post_category'] = serialize($new_instance['post_category']);
157
- }
158
- $instance['depth'] = (int) $new_instance['depth'];
159
- if ($instance['depth'] < 0 || 11 < $instance['depth']) {
160
- $instance['depth'] = 0;
161
- }
162
- $instance['invert_included'] = isset($new_instance['invert_included']);
163
-
164
- return $instance;
165
- }
166
-
167
- /**
168
- * Display Widget Control Form
169
- *
170
- * @param unknown_type $instance
171
- */
172
- public function form($instance)
173
- {
174
- // displays the widget admin form
175
- $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => '', 'depth' => 0));
176
-
177
- // Prepare data for display
178
- $depth = (int) $instance['depth'];
179
- if ($depth < 0 || 11 < $depth) {
180
- $depth = 0;
181
- }
182
- $selected_cats = (avhGetArrayValue($instance, 'post_category') !== '') ? unserialize($instance['post_category']) : false;
183
-
184
- echo '<p>';
185
- avh_doWidgetFormText($this->get_field_id('title'), $this->get_field_name('title'), __('Title', 'avh-ec'), avhGetArrayValue($instance, 'title'));
186
- echo '</p>';
187
-
188
- echo '<p>';
189
- avh_doWidgetFormCheckbox($this->get_field_id('selectedonly'), $this->get_field_name('selectedonly'), __('Show selected categories only', 'avh-ec'), (bool) avhGetArrayValue($instance, 'selectedonly'));
190
-
191
- avh_doWidgetFormCheckbox($this->get_field_id('count'), $this->get_field_name('count'), __('Show post counts', 'avh-ec'), (bool) avhGetArrayValue($instance, 'count'));
192
-
193
- avh_doWidgetFormCheckbox($this->get_field_id('hierarchical'), $this->get_field_name('hierarchical'), __('Show hierarchy', 'avh-ec'), (bool) avhGetArrayValue($instance, 'hierarchical'));
194
-
195
- $options = array(0 => __('All Levels', 'avh-ec'), 1 => __('Toplevel only', 'avh-ec'));
196
- for ($i = 2; $i <= 11; $i++) {
197
- $options[$i] = __('Child ', 'avh-ec') . ($i - 1);
198
- }
199
- avh_doWidgetFormSelect($this->get_field_id('depth'), $this->get_field_name('depth'), __('How many levels to show', 'avh-ec'), $options, $depth);
200
- unset($options);
201
-
202
- avh_doWidgetFormCheckbox($this->get_field_id('hide_empty'), $this->get_field_name('hide_empty'), __('Hide empty categories', 'avh-ec'), (bool) avhGetArrayValue($instance, 'hide_empty'));
203
-
204
- avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'), $this->get_field_name('use_desc_for_title'), __('Use description for title', 'avh-ec'), (bool) avhGetArrayValue($instance, 'use_desc_for_title'));
205
- echo '</p>';
206
-
207
- echo '<p>';
208
- $options['ID'] = __('ID', 'avh-ec');
209
- $options['name'] = __('Name', 'avh-ec');
210
- $options['count'] = __('Count', 'avh-ec');
211
- $options['slug'] = __('Slug', 'avh-ec');
212
- $options['avhec_manualorder'] = 'AVH EC ' . __('Manual Order', 'avh-ec');
213
- if (is_plugin_active('my-category-order/mycategoryorder.php')) {
214
- $options['avhec_3rdparty_mycategoryorder'] = 'My Category Order';
215
- }
216
-
217
- avh_doWidgetFormSelect($this->get_field_id('sort_column'), $this->get_field_name('sort_column'), __('Sort by', 'avh-ec'), $options, avhGetArrayValue($instance, 'sort_column'));
218
- unset($options);
219
-
220
- $options['asc'] = __('Ascending', 'avh-ec');
221
- $options['desc'] = __('Descending', 'avh-ec');
222
- avh_doWidgetFormSelect($this->get_field_id('sort_order'), $this->get_field_name('sort_order'), __('Sort order', 'avh-ec'), $options, avhGetArrayValue($instance, 'sort_order'));
223
- unset($options);
224
-
225
- $options['list'] = __('List', 'avh-ec');
226
- $options['drop'] = __('Drop down', 'avh-ec');
227
- avh_doWidgetFormSelect($this->get_field_id('style'), $this->get_field_name('style'), __('Display style', 'avh-ec'), $options, avhGetArrayValue($instance, 'style'));
228
- unset($options);
229
- echo '</p>';
230
-
231
- echo '<p>';
232
-
233
- avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), $this->get_field_name('rssfeed'), __('Show RSS Feed', 'avh-ec'), (bool) avhGetArrayValue($instance, 'rssfeed'));
234
-
235
- avh_doWidgetFormText($this->get_field_id('rssimage'), $this->get_field_name('rssimage'), __('Path (URI) to RSS image', 'avh-ec'), avhGetArrayValue($instance, 'rssimage'));
236
-
237
- echo '</p>';
238
-
239
- echo '<p>';
240
- echo '<b>' . __('Select categories', 'avh-ec') . '</b><hr />';
241
- echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear" style="list-style-type: none; margin-left: 5px; padding-left: 0px; margin-bottom: 20px;">';
242
- echo '<li id="' . $this->get_field_id('category--1') . '" class="popular-category">';
243
- echo '<label for="' . $this->get_field_id('post_category') . '" class="selectit">';
244
- echo '<input value="all" id="' . $this->get_field_id('post_category') . '" name="' . $this->get_field_name('post_category') . '[all]" type="checkbox" ' . (false === $selected_cats ? ' CHECKED' : '') . '> ';
245
- _e('All Categories', 'avh-ec');
246
- echo '</label>';
247
- echo '</li>';
248
- ob_start();
249
- $this->avh_wp_category_checklist($selected_cats, $this->number);
250
- ob_end_flush();
251
- echo '</ul>';
252
- echo '</p>';
253
-
254
- echo '<p>';
255
- avh_doWidgetFormCheckbox($this->get_field_id('invert_included'), $this->get_field_name('invert_included'), __('Exclude the selected categories', 'avh-ec'), (bool) avhGetArrayValue($instance, 'invert_included'));
256
- echo '</p>';
257
-
258
- echo '<input type="hidden" id="' . $this->get_field_id('submit') . '" name="' . $this->get_field_name('submit') . '" value="1" />';
259
- }
260
-
261
- /**
262
- * Creates the categories checklist
263
- *
264
- * @param int $post_id
265
- * @param int $descendants_and_self
266
- * @param array $selected_cats
267
- * @param array $popular_cats
268
- * @param int $number
269
- */
270
- public function avh_wp_category_checklist($selected_cats, $number)
271
- {
272
- $walker = new AVH_Walker_Category_Checklist();
273
- $walker->number = $number;
274
- $walker->input_id = $this->get_field_id('post_category');
275
- $walker->input_name = $this->get_field_name('post_category');
276
- $walker->li_id = $this->get_field_id('category--1');
277
-
278
- $args = array('taxonomy' => 'category', 'descendants_and_self' => 0, 'selected_cats' => $selected_cats, 'popular_cats' => array(), 'walker' => $walker, 'checked_ontop' => true, 'popular_cats' => array());
279
-
280
- if (is_array($selected_cats)) {
281
- $args['selected_cats'] = $selected_cats;
282
- } else {
283
- $args['selected_cats'] = array();
284
- }
285
-
286
- $categories = $this->core->getCategories();
287
- $_categories_id = $this->core->getCategoriesId($categories);
288
-
289
- // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache)
290
- $checked_categories = array();
291
- foreach ($args['selected_cats'] as $key => $value) {
292
- if (isset($_categories_id[$key])) {
293
- $category_key = $_categories_id[$key];
294
- $checked_categories[] = $categories[$category_key];
295
- unset($categories[$category_key]);
296
- }
297
- }
298
-
299
- // Put checked cats on top
300
- echo $walker->walk($checked_categories, 0, $args);
301
- // Then the rest of them
302
- echo $walker->walk($categories, 0, $args);
303
- }
304
  }
305
 
306
  /**
307
- * Widget Class for displaying the top categories
308
  */
309
- class WP_Widget_AVH_ExtendedCategories_Top extends WP_Widget
310
- {
311
-
312
- /**
313
- *
314
- * @var AVH_EC_Core
315
- */
316
- public $core;
317
-
318
- /**
319
- * PHP 5 Constructor
320
- */
321
- public function __construct()
322
- {
323
- $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core');
324
-
325
- $widget_ops = array('description' => __("Shows the top categories.", 'avh-ec'));
326
- WP_Widget::__construct(false, 'AVH Extended Categories: ' . __('Top Categories'), $widget_ops);
327
- add_action('wp_print_styles', array($this, 'actionWpPrintStyles'));
328
- }
329
-
330
- public function actionWpPrintStyles()
331
- {
332
- if (!(false === is_active_widget(false, false, $this->id_base, true))) {
333
- wp_register_style('avhec-widget', AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', array(), $this->core->version);
334
- wp_enqueue_style('avhec-widget');
335
- }
336
- }
337
-
338
- /**
339
- * Echo the widget content.
340
- *
341
- * Subclasses should over-ride this function to generate their widget code.
342
- *
343
- * @param array $args
344
- * Display arguments including before_title, after_title, before_widget, and after_widget.
345
- * @param array $instance
346
- * The settings for the particular instance of the widget
347
- */
348
- public function widget($args, $instance)
349
- {
350
- extract($args);
351
-
352
- $title = apply_filters('widget_title', empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']);
353
- $style = empty($instance['style']) ? 'list' : $instance['style'];
354
- if (!$a = (int) $instance['amount']) {
355
- $a = 5;
356
- } elseif ($a < 1) {
357
- $a = 1;
358
- }
359
- $c = $instance['count'];
360
- $use_desc_for_title = $instance['use_desc_for_title'];
361
- $s = isset($instance['sort_column']) ? $instance['sort_column'] : 'name';
362
- $o = isset($instance['sort_order']) ? $instance['sort_order'] : 'asc';
363
- $r = ($instance['rssfeed'] === true) ? 'RSS' : '';
364
- $i = isset($instance['rssimage']) ? $instance['rssimage'] : '';
365
- if (empty($r)) {
366
- $i = '';
367
- }
368
- if (!empty($i)) {
369
- if (!file_exists(ABSPATH . '/' . $i)) {
370
- $i = '';
371
- }
372
- }
373
-
374
- $options = $this->core->getOptions();
375
- $show_option_none = __('Select Category', 'avh-ec');
376
- if ($options['general']['alternative_name_select_category']) {
377
- $show_option_none = $options['general']['alternative_name_select_category'];
378
- }
379
-
380
- $top_cats = get_terms('category', array('fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => $a, 'hierarchical' => false));
381
- $included_cats = implode(",", $top_cats);
382
-
383
- $cat_args = array('include' => $included_cats, 'orderby' => $s, 'order' => $o, 'show_count' => $c, 'use_desc_for_title' => $use_desc_for_title, 'hide_empty' => false, 'hierarchical' => false, 'depth' => -1, 'title_li' => '', 'show_option_none' => $show_option_none, 'feed' => $r, 'feed_image' => $i, 'name' => 'extended-categories-top-select-' . $this->number);
384
- echo $before_widget;
385
- echo $this->core->comment;
386
- echo $before_title . $title . $after_title;
387
- echo '<ul>';
388
-
389
- if ($style == 'list') {
390
- wp_list_categories($cat_args);
391
- } else {
392
- wp_dropdown_categories($cat_args);
393
- echo '<script type=\'text/javascript\'>' . "\n";
394
- echo '/* <![CDATA[ */' . "\n";
395
- echo ' var ec_dropdown_top_' . $this->number . ' = document.getElementById("extended-categories-top-select-' . $this->number . '");' . "\n";
396
- echo ' function ec_top_onCatChange_' . $this->number . '() {' . "\n";
397
- echo ' if (ec_dropdown_top_' . $this->number . '.options[ec_dropdown_top_' . $this->number . '.selectedIndex].value > 0) {' . "\n";
398
- echo ' location.href = "' . get_option('home') . '/?cat="+ec_dropdown_top_' . $this->number . '.options[ec_dropdown_top_' . $this->number . '.selectedIndex].value;' . "\n";
399
- echo ' }' . "\n";
400
- echo ' }' . "\n";
401
- echo ' ec_dropdown_top_' . $this->number . '.onchange = ec_top_onCatChange_' . $this->number . ';' . "\n";
402
- echo '/* ]]> */' . "\n";
403
- echo '</script>' . "\n";
404
- }
405
- echo '</ul>';
406
- echo $after_widget;
407
- }
408
-
409
- /**
410
- * Update a particular instance.
411
- *
412
- * This function should check that $new_instance is set correctly.
413
- * The newly calculated value of $instance should be returned.
414
- * If "false" is returned, the instance won't be saved/updated.
415
- *
416
- * @param array $new_instance
417
- * New settings for this instance as input by the user via form()
418
- * @param array $old_instance
419
- * Old settings for this instance
420
- * @return array Settings to save or bool false to cancel saving
421
- */
422
- public function update($new_instance, $old_instance)
423
- {
424
- // update the instance's settings
425
- if (!isset($new_instance['submit'])) {
426
- return false;
427
- }
428
-
429
- $instance = $old_instance;
430
-
431
- $instance['title'] = strip_tags(stripslashes($new_instance['title']));
432
- $instance['amount'] = (int) $new_instance['amount'];
433
- $instance['count'] = isset($new_instance['count']);
434
- $instance['use_desc_for_title'] = isset($new_instance['use_desc_for_title']);
435
- $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column']));
436
- $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order']));
437
- $instance['style'] = strip_tags(stripslashes($new_instance['style']));
438
- $instance['rssfeed'] = isset($new_instance['rssfeed']);
439
- $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage']));
440
-
441
- return $instance;
442
- }
443
-
444
- /**
445
- * Echo the settings update form
446
- *
447
- * @param array $instance
448
- * Current settings
449
- */
450
- public function form($instance)
451
- {
452
- // displays the widget admin form
453
- $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => '', 'amount' => '5'));
454
-
455
- $amount = (int) avhGetArrayValue($instance, 'amount');
456
- if ($amount < 1) {
457
- $amount = 1;
458
- }
459
- echo '<p>';
460
- avh_doWidgetFormText($this->get_field_id('title'), $this->get_field_name('title'), __('Title', 'avh-ec'), avhGetArrayValue($instance, 'title'));
461
- echo '</p>';
462
-
463
- echo '<p>';
464
- avh_doWidgetFormText($this->get_field_id('amount'), $this->get_field_name('amount'), __('How many categories to show', 'avh-ec'), $amount);
465
- echo '</p>';
466
-
467
- echo '<p>';
468
- avh_doWidgetFormCheckbox($this->get_field_id('count'), $this->get_field_name('count'), __('Show post counts', 'avh-ec'), (bool) avhGetArrayValue($instance, 'count'));
469
- echo '<br />';
470
-
471
- avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'), $this->get_field_name('use_desc_for_title'), __('Use description for title', 'avh-ec'), (bool) avhGetArrayValue($instance, 'use_desc_for_title'));
472
- echo '</p>';
473
-
474
- echo '<p>';
475
- $options['ID'] = __('ID', 'avh-ec');
476
- $options['name'] = __('Name', 'avh-ec');
477
- $options['count'] = __('Count', 'avh-ec');
478
- $options['slug'] = __('Slug', 'avh-ec');
479
- avh_doWidgetFormSelect($this->get_field_id('sort_column'), $this->get_field_name('sort_column'), __('Sort by', 'avh-ec'), $options, avhGetArrayValue($instance, 'sort_column'));
480
- unset($options);
481
-
482
- $options['asc'] = __('Ascending', 'avh-ec');
483
- $options['desc'] = __('Descending', 'avh-ec');
484
- avh_doWidgetFormSelect($this->get_field_id('sort_order'), $this->get_field_name('sort_order'), __('Sort order', 'avh-ec'), $options, avhGetArrayValue($instance, 'sort_order'));
485
- unset($options);
486
-
487
- $options['list'] = __('List', 'avh-ec');
488
- $options['drop'] = __('Drop down', 'avh-ec');
489
- avh_doWidgetFormSelect($this->get_field_id('style'), $this->get_field_name('style'), __('Display style', 'avh-ec'), $options, avhGetArrayValue($instance, 'style'));
490
- unset($options);
491
- echo '</p>';
492
-
493
- echo '<p>';
494
-
495
- avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), $this->get_field_name('rssfeed'), __('Show RSS Feed', 'avh-ec'), (bool) avhGetArrayValue($instance, 'rssfeed'));
496
-
497
- avh_doWidgetFormText($this->get_field_id('rssimage'), $this->get_field_name('rssimage'), __('Path (URI) to RSS image', 'avh-ec'), avhGetArrayValue($instance, 'rssimage'));
498
-
499
- echo '</p>';
500
-
501
- echo '<input type="hidden" id="' . $this->get_field_id('submit') . '" name="' . $this->get_field_name('submit') . '" value="1" />';
502
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
503
  }
504
 
505
  /**
506
- * Widget Class for displaying the grouped categories
 
507
  */
508
- class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget
509
- {
510
-
511
- /**
512
- *
513
- * @var AVH_EC_Core
514
- */
515
- public $core;
516
-
517
- /**
518
- *
519
- * @var AVH_EC_Category_Group
520
- */
521
- public $catgrp;
522
-
523
- /**
524
- * PHP 5 Constructor
525
- */
526
- public function __construct()
527
- {
528
- $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core');
529
- $this->catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
530
-
531
- $widget_ops = array('description' => __("Shows grouped categories.", 'avh-ec'));
532
- WP_Widget::__construct(false, 'AVH Extended Categories: ' . __('Category Group'), $widget_ops);
533
- add_action('wp_print_styles', array($this, 'actionWpPrintStyles'));
534
- }
535
-
536
- public function actionWpPrintStyles()
537
- {
538
- if (!(false === is_active_widget(false, false, $this->id_base, true))) {
539
- wp_register_style('avhec-widget', AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', array(), $this->core->version);
540
- wp_enqueue_style('avhec-widget');
541
- }
542
- }
543
-
544
- /**
545
- * Display the widget
546
- *
547
- * @param unknown_type $args
548
- * @param unknown_type $instance
549
- */
550
- public function widget($args, $instance)
551
- {
552
- global $post, $wp_query;
553
-
554
- $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
555
- $options = $this->core->getOptions();
556
-
557
- $row = array();
558
-
559
- if (is_home()) {
560
- $special_page = 'home_group';
561
- } elseif (is_category()) {
562
- $special_page = 'category_group';
563
- } elseif (is_day()) {
564
- $special_page = 'day_group';
565
- } elseif (is_month()) {
566
- $special_page = 'month_group';
567
- } elseif (is_year()) {
568
- $special_page = 'year_group';
569
- } elseif (is_author()) {
570
- $special_page = 'author_group';
571
- } elseif (is_search()) {
572
- $special_page = 'search_group';
573
- } else {
574
- $special_page = 'none';
575
- }
576
-
577
- $toDisplay = false;
578
- if ('none' == $special_page) {
579
- $terms = wp_get_object_terms($post->ID, $catgrp->taxonomy_name);
580
- if (!empty($terms)) {
581
- $selected_catgroups = unserialize($instance['post_group_category']);
582
- foreach ($terms as $key => $value) {
583
- if ($selected_catgroups === false || array_key_exists($value->term_id, $selected_catgroups)) {
584
- if (!($this->getWidgetDoneCatGroup($value->term_id))) {
585
- $row = $value;
586
- $group_found = true;
587
- break;
588
- }
589
- }
590
- }
591
- } else {
592
- $options = $this->core->options;
593
- $no_cat_group = $options['cat_group']['no_group'];
594
- $row = get_term_by('id', $no_cat_group, $catgrp->taxonomy_name);
595
- $group_found = true;
596
- }
597
- } else {
598
- if ('category_group' == $special_page) {
599
- $tax_meta = get_option($this->core->db_options_tax_meta);
600
- $term = $wp_query->get_queried_object();
601
- if (isset($tax_meta[$term->taxonomy][$term->term_id]['category_group_term_id'])) {
602
- $sp_category_group_id = $tax_meta[$term->taxonomy][$term->term_id]['category_group_term_id'];
603
- } else {
604
- $sp_category_group = $this->catgrp->getGroupByCategoryID($term->term_id);
605
- $sp_category_group_id = $sp_category_group->term_id;
606
- }
607
- } else {
608
- $sp_category_group_id = $options['sp_cat_group'][$special_page];
609
- }
610
- $row = get_term_by('id', $sp_category_group_id, $catgrp->taxonomy_name); // Returns false when non-existance. (empty(false)=true)
611
- $group_found = true;
612
- }
613
-
614
- if ($group_found) {
615
- $toDisplay = true;
616
- $category_group_id_none = $this->catgrp->getTermIDBy('slug', 'none');
617
- $selected_catgroups = unserialize($instance['post_group_category']);
618
-
619
- if ($category_group_id_none == $row->term_id) {
620
- $toDisplay = false;
621
- } elseif (!(false == $selected_catgroups || array_key_exists($row->term_id, $selected_catgroups))) {
622
- $toDisplay = false;
623
- } elseif ($special_page != 'none' && $this->getWidgetDoneCatGroup($sp_category_group_id)) {
624
- $toDisplay = false;
625
- }
626
- }
627
-
628
- if ($toDisplay) {
629
- extract($args);
630
-
631
- $c = $instance['count'];
632
- $e = $instance['hide_empty'];
633
- $h = $instance['hierarchical'];
634
- $use_desc_for_title = $instance['use_desc_for_title'];
635
- $s = isset($instance['sort_column']) ? $instance['sort_column'] : 'name';
636
- $o = isset($instance['sort_order']) ? $instance['sort_order'] : 'asc';
637
- $r = $instance['rssfeed'] ? 'RSS' : '';
638
- $i = $instance['rssimage'] ? $instance['rssimage'] : '';
639
-
640
- if (empty($r)) {
641
- $i = '';
642
- }
643
-
644
- $style = empty($instance['style']) ? 'list' : $instance['style'];
645
- $group_id = $row->term_id;
646
- $cats = $catgrp->getCategoriesFromGroup($group_id);
647
- if (empty($instance['title'])) {
648
- $title = $catgrp->getWidgetTitleForGroup($group_id);
649
- if (!$title) {
650
- $title = __('Categories', 'avh-ec');
651
- }
652
- } else {
653
- $title = $instance['title'];
654
- }
655
- $title = apply_filters('widget_title', $title);
656
-
657
- $included_cats = implode(',', $cats);
658
-
659
- $show_option_none = __('Select Category', 'avh-ec');
660
- if ($options['general']['alternative_name_select_category']) {
661
- $show_option_none = $options['general']['alternative_name_select_category'];
662
- }
663
-
664
- $cat_args = array('include' => $included_cats, 'orderby' => $s, 'order' => $o, 'show_count' => $c, 'use_desc_for_title' => $use_desc_for_title, 'hide_empty' => $e, 'hierarchical' => $h, 'title_li' => '', 'show_option_none' => $show_option_none, 'feed' => $r, 'feed_image' => $i, 'name' => 'extended-categories-select-group-' . $this->number);
665
- echo $before_widget;
666
- echo $this->core->comment;
667
- echo $before_title . $title . $after_title;
668
-
669
- if ($style == 'list') {
670
- echo '<ul>';
671
- $this->core->avh_wp_list_categories($cat_args, true);
672
- echo '</ul>';
673
- } else {
674
- $this->core->avh_wp_dropdown_categories($cat_args, true);
675
- echo '<script type=\'text/javascript\'>' . "\n";
676
- echo '/* <![CDATA[ */' . "\n";
677
- echo ' var ec_dropdown_' . $this->number . ' = document.getElementById("extended-categories-select-group-' . $this->number . '");' . "\n";
678
- echo ' function ec_onCatChange_' . $this->number . '() {' . "\n";
679
- echo ' if (ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value > 0) {' . "\n";
680
- echo ' location.href = "' . get_option('home') . '/?cat="+ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value;' . "\n";
681
- echo ' }' . "\n";
682
- echo ' }' . "\n";
683
- echo ' ec_dropdown_' . $this->number . '.onchange = ec_onCatChange_' . $this->number . ';' . "\n";
684
- echo '/* ]]> */' . "\n";
685
- echo '</script>' . "\n";
686
- }
687
- echo $after_widget;
688
- }
689
- }
690
-
691
- /**
692
- * When Widget Control Form Is Posted
693
- *
694
- * @param unknown_type $new_instance
695
- * @param unknown_type $old_instance
696
- * @return unknown
697
- */
698
- public function update($new_instance, $old_instance)
699
- {
700
- // update the instance's settings
701
- if (!isset($new_instance['submit'])) {
702
- return false;
703
- }
704
-
705
- $instance = $old_instance;
706
-
707
- $instance['title'] = strip_tags(stripslashes($new_instance['title']));
708
- $instance['count'] = isset($new_instance['count']);
709
- $instance['hierarchical'] = isset($new_instance['hierarchical']);
710
- $instance['hide_empty'] = isset($new_instance['hide_empty']);
711
- $instance['use_desc_for_title'] = isset($new_instance['use_desc_for_title']);
712
- $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column']));
713
- $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order']));
714
- $instance['style'] = strip_tags(stripslashes($new_instance['style']));
715
- $instance['rssfeed'] = isset($new_instance['rssfeed']);
716
- $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage']));
717
- if (array_key_exists('all', $new_instance['post_group_category'])) {
718
- $instance['post_group_category'] = false;
719
- } else {
720
- $instance['post_group_category'] = serialize($new_instance['post_group_category']);
721
- }
722
-
723
- return $instance;
724
- }
725
-
726
- /**
727
- * Display Widget Control Form
728
- *
729
- * @param unknown_type $instance
730
- */
731
- public function form($instance)
732
- {
733
- // displays the widget admin form
734
- $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => ''));
735
-
736
- $selected_cats = (avhGetArrayValue($instance, 'post_group_category') !== '') ? unserialize($instance['post_group_category']) : false;
737
- ob_start();
738
- echo '<p>';
739
- avh_doWidgetFormText($this->get_field_id('title'), $this->get_field_name('title'), __('Title', 'avh-ec'), $instance['title']);
740
- echo '</p>';
741
-
742
- echo '<p>';
743
-
744
- avh_doWidgetFormCheckbox($this->get_field_id('count'), $this->get_field_name('count'), __('Show post counts', 'avh-ec'), (bool) avhGetArrayValue($instance, 'count'));
745
-
746
- avh_doWidgetFormCheckbox($this->get_field_id('hierarchical'), $this->get_field_name('hierarchical'), __('Show hierarchy', 'avh-ec'), (bool) avhGetArrayValue($instance, 'hierarchical'));
747
-
748
- avh_doWidgetFormCheckbox($this->get_field_id('hide_empty'), $this->get_field_name('hide_empty'), __('Hide empty categories', 'avh-ec'), (bool) avhGetArrayValue($instance, 'hide_empty'));
749
-
750
- avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'), $this->get_field_name('use_desc_for_title'), __('Use description for title', 'avh-ec'), (bool) avhGetArrayValue($instance, 'use_desc_for_title'));
751
- echo '</p>';
752
-
753
- echo '<p>';
754
- $options['ID'] = __('ID', 'avh-ec');
755
- $options['name'] = __('Name', 'avh-ec');
756
- $options['count'] = __('Count', 'avh-ec');
757
- $options['slug'] = __('Slug', 'avh-ec');
758
- avh_doWidgetFormSelect($this->get_field_id('sort_column'), $this->get_field_name('sort_column'), __('Sort by', 'avh-ec'), $options, avhGetArrayValue($instance, 'sort_column'));
759
- unset($options);
760
-
761
- $options['asc'] = __('Ascending', 'avh-ec');
762
- $options['desc'] = __('Descending', 'avh-ec');
763
- avh_doWidgetFormSelect($this->get_field_id('sort_order'), $this->get_field_name('sort_order'), __('Sort order', 'avh-ec'), $options, avhGetArrayValue($instance, 'sort_order'));
764
- unset($options);
765
-
766
- $options['list'] = __('List', 'avh-ec');
767
- $options['drop'] = __('Drop down', 'avh-ec');
768
- avh_doWidgetFormSelect($this->get_field_id('style'), $this->get_field_name('style'), __('Display style', 'avh-ec'), $options, avhGetArrayValue($instance, 'style'));
769
- unset($options);
770
- echo '</p>';
771
-
772
- echo '<p>';
773
-
774
- avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), $this->get_field_name('rssfeed'), __('Show RSS Feed', 'avh-ec'), (bool) avhGetArrayValue($instance, 'rssfeed'));
775
-
776
- avh_doWidgetFormText($this->get_field_id('rssimage'), $this->get_field_name('rssimage'), __('Path (URI) to RSS image', 'avh-ec'), avhGetArrayValue($instance, 'rssimage'));
777
- echo '</p>';
778
-
779
- echo '<p>';
780
- echo '<b>' . __('Select Groups', 'avh-ec') . '</b><hr />';
781
- echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear" style="list-style-type: none; margin-left: 5px; padding-left: 0px; margin-bottom: 20px;">';
782
- echo '<li id="' . $this->get_field_id('group_category--1') . '" class="popular-group_category">';
783
- echo '<label for="' . $this->get_field_id('group_post_category') . '" class="selectit">';
784
- echo '<input value="all" id="' . $this->get_field_id('group_post_category') . '" name="' . $this->get_field_name('post_group_category') . '[all]" type="checkbox" ' . (false === $selected_cats ? ' CHECKED' : '') . '> ';
785
- _e('Any Group', 'avh-ec');
786
- echo '</label>';
787
- echo '</li>';
788
-
789
- $this->avh_wp_group_category_checklist($selected_cats, $this->number);
790
-
791
- echo '</ul>';
792
- echo '</p>';
793
-
794
- echo '<input type="hidden" id="' . $this->get_field_id('submit') . '" name="' . $this->get_field_name('submit') . '" value="1" />';
795
- ob_end_flush();
796
- }
797
-
798
- public function avh_wp_group_category_checklist($selected_cats, $number)
799
- {
800
- $walker = new AVH_Walker_Category_Checklist();
801
- $walker->number = $number;
802
- $walker->input_id = $this->get_field_id('post_group_category');
803
- $walker->input_name = $this->get_field_name('post_group_category');
804
- $walker->li_id = $this->get_field_id('group_category--1');
805
-
806
- $args = array('taxonomy' => 'avhec_catgroup', 'descendants_and_self' => 0, 'selected_cats' => array(), 'popular_cats' => array(), 'walker' => $walker, 'checked_ontop' => true);
807
-
808
- if (is_array($selected_cats)) {
809
- $args['selected_cats'] = $selected_cats;
810
- } else {
811
- $args['selected_cats'] = array();
812
- }
813
-
814
- $categories = (array) get_terms($args['taxonomy'], array('get' => 'all'));
815
-
816
- // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache)
817
- $checked_categories = array();
818
- $keys = array_keys($categories);
819
-
820
- foreach ($keys as $k) {
821
- if (in_array($categories[$k]->term_id, $args['selected_cats'])) {
822
- $checked_categories[] = $categories[$k];
823
- unset($categories[$k]);
824
- }
825
- }
826
-
827
- // Put checked cats on top
828
- echo $walker->walk($checked_categories, 0, $args);
829
- // Then the rest of them
830
- echo $walker->walk($categories, 0, $args);
831
- }
832
-
833
- public function getWidgetDoneCatGroup($id)
834
- {
835
- $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
836
- if (is_array($catgrp->widget_done_catgroup) && array_key_exists($id, $catgrp->widget_done_catgroup)) {
837
- return true;
838
- }
839
- $catgrp->widget_done_catgroup[$id] = true;
840
-
841
- return false;
842
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
843
  }
844
 
845
  /**
846
- * Class that will display the categories
847
  */
848
- class AVH_Walker_Category_Checklist extends Walker
849
- {
850
-
851
- public $tree_type = 'category';
852
-
853
- public $db_fields = array('parent' => 'parent', 'id' => 'term_id'); // TODO: decouple this
854
- public $number;
855
-
856
- public $input_id;
857
-
858
- public $input_name;
859
-
860
- public $li_id;
861
-
862
- /**
863
- * Display array of elements hierarchically.
864
- *
865
- * It is a generic function which does not assume any existing order of
866
- * elements. max_depth = -1 means flatly display every element. max_depth =
867
- * 0 means display all levels. max_depth > 0 specifies the number of
868
- * display levels.
869
- *
870
- * @since 2.1.0
871
- *
872
- * @param array $elements
873
- * @param int $max_depth
874
- * @param array $args;
875
- * @return string
876
- */
877
- public function walk($elements, $max_depth)
878
- {
879
- $args = array_slice(func_get_args(), 2);
880
- $output = '';
881
-
882
- if ($max_depth < -1) {
883
- return $output;
884
- }
885
-
886
- if (empty($elements)) { // nothing to walk
887
- return $output;
888
- }
889
-
890
- $id_field = $this->db_fields['id'];
891
- $parent_field = $this->db_fields['parent'];
892
-
893
- // flat display
894
- if (-1 == $max_depth) {
895
- $empty_array = array();
896
- foreach ($elements as $e) {
897
- $this->display_element($e, $empty_array, 1, 0, $args, $output);
898
- }
899
-
900
- return $output;
901
- }
902
-
903
- /*
904
- * need to display in hierarchical order separate elements into two buckets: top level and children elements children_elements is two dimensional array, eg. children_elements[10][] contains all sub-elements whose parent is 10.
905
- */
906
- $top_level_elements = array();
907
- $children_elements = array();
908
- foreach ($elements as $e) {
909
- if (0 == $e->$parent_field) {
910
- $top_level_elements[] = $e;
911
- } else {
912
- $children_elements[$e->$parent_field][] = $e;
913
- }
914
- }
915
-
916
- /*
917
- * when none of the elements is top level assume the first one must be root of the sub elements
918
- */
919
- if (empty($top_level_elements)) {
920
-
921
- $first = array_slice($elements, 0, 1);
922
- $root = $first[0];
923
-
924
- $top_level_elements = array();
925
- $children_elements = array();
926
- foreach ($elements as $e) {
927
- if ($root->$parent_field == $e->$parent_field) {
928
- $top_level_elements[] = $e;
929
- } else {
930
- $children_elements[$e->$parent_field][] = $e;
931
- }
932
- }
933
- }
934
-
935
- foreach ($top_level_elements as $e) {
936
- $this->display_element($e, $children_elements, $max_depth, 0, $args, $output);
937
- }
938
-
939
- /*
940
- * if we are displaying all levels, and remaining children_elements is not empty, then we got orphans, which should be displayed regardless
941
- */
942
- if (($max_depth == 0) && count($children_elements) > 0) {
943
- $empty_array = array();
944
- foreach ($children_elements as $orphans) {
945
- foreach ($orphans as $op) {
946
- $this->display_element($op, $empty_array, 1, 0, $args, $output);
947
- }
948
- }
949
- }
950
-
951
- return $output;
952
- }
953
-
954
- public function start_lvl(&$output, $depth = 0, $args = array())
955
- {
956
- $indent = str_repeat("\t", $depth);
957
- $output .= $indent . '<ul class="children">' . "\n";
958
- }
959
-
960
- public function end_lvl(&$output, $depth = 0, $args = array())
961
- {
962
- $indent = str_repeat("\t", $depth);
963
- $output .= $indent . '</ul>' . "\n";
964
- }
965
-
966
- public function start_el(&$output, $object, $depth = 0, $args = array(), $current_object_id = 0)
967
- {
968
- extract($args);
969
- if (!isset($selected_cats)) {
970
- $selected_cats = array();
971
- }
972
- $input_id = $this->input_id . '-' . $object->term_id;
973
- $output .= "\n" . '<li id="' . $this->li_id . '">';
974
- $output .= '<label for="' . $input_id . '" class="selectit">';
975
- $output .= '<input value="' . $object->term_id . '" type="checkbox" name="' . $this->input_name . '[' . $object->term_id . ']" id="' . $input_id . '"' . (in_array($object->term_id, $selected_cats) ? ' checked="checked"' : "") . '/> ' . esc_html(apply_filters('the_category', $object->name)) . '</label>';
976
- }
977
-
978
- public function end_el(&$output, $object, $depth = 0, $args = array())
979
- {
980
- $output .= "</li>\n";
981
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
982
  }
1
  <?php
2
 
3
  /**
4
+ * Class that will display the categories
 
5
  */
6
+ class AVH_Walker_Category_Checklist extends Walker {
7
+ public $db_fields = array('parent' => 'parent', 'id' => 'term_id');
8
+ public $input_id; // TODO: decouple this
9
+ public $input_name;
10
+ public $li_id;
11
+ public $number;
12
+ public $tree_type = 'category';
13
+
14
+ public function end_el(&$output, $object, $depth = 0, $args = array()) {
15
+ $output .= "</li>\n";
16
+ }
17
+
18
+ public function end_lvl(&$output, $depth = 0, $args = array()) {
19
+ $indent = str_repeat("\t", $depth);
20
+ $output .= $indent . '</ul>' . "\n";
21
+ }
22
+
23
+ public function start_el(&$output, $object, $depth = 0, $args = array(), $current_object_id = 0) {
24
+ extract($args);
25
+ if ( ! isset($selected_cats)) {
26
+ $selected_cats = array();
27
+ }
28
+ $input_id = $this->input_id . '-' . $object->term_id;
29
+ $output .= "\n" . '<li id="' . $this->li_id . '">';
30
+ $output .= '<label for="' . $input_id . '" class="selectit">';
31
+ $output .= '<input value="' .
32
+ $object->term_id .
33
+ '" type="checkbox" name="' .
34
+ $this->input_name .
35
+ '[' .
36
+ $object->term_id .
37
+ ']" id="' .
38
+ $input_id .
39
+ '"' .
40
+ (in_array($object->term_id, $selected_cats) ? ' checked="checked"' : "") .
41
+ '/> ' .
42
+ esc_html(apply_filters('the_category', $object->name)) .
43
+ '</label>';
44
+ }
45
+
46
+ public function start_lvl(&$output, $depth = 0, $args = array()) {
47
+ $indent = str_repeat("\t", $depth);
48
+ $output .= $indent . '<ul class="children">' . "\n";
49
+ }
50
+
51
+ /**
52
+ * Display array of elements hierarchically.
53
+ * It is a generic function which does not assume any existing order of
54
+ * elements. max_depth = -1 means flatly display every element. max_depth =
55
+ * 0 means display all levels. max_depth > 0 specifies the number of
56
+ * display levels.
57
+ *
58
+ * @since 2.1.0
59
+ *
60
+ * @param array $elements
61
+ * @param int $max_depth
62
+ * @param array $args ;
63
+ *
64
+ * @return string
65
+ */
66
+ public function walk($elements, $max_depth) {
67
+ $args = array_slice(func_get_args(), 2);
68
+ $output = '';
69
+
70
+ if ($max_depth < - 1) {
71
+ return $output;
72
+ }
73
+
74
+ if (empty($elements)) { // nothing to walk
75
+ return $output;
76
+ }
77
+
78
+ $id_field = $this->db_fields['id'];
79
+ $parent_field = $this->db_fields['parent'];
80
+
81
+ // flat display
82
+ if (- 1 == $max_depth) {
83
+ $empty_array = array();
84
+ foreach ($elements as $e) {
85
+ $this->display_element($e, $empty_array, 1, 0, $args, $output);
86
+ }
87
+
88
+ return $output;
89
+ }
90
+
91
+ /*
92
+ * need to display in hierarchical order separate elements into two buckets: top level and children elements children_elements is two dimensional array, eg. children_elements[10][] contains all sub-elements whose parent is 10.
93
+ */
94
+ $top_level_elements = array();
95
+ $children_elements = array();
96
+ foreach ($elements as $e) {
97
+ if (0 == $e->$parent_field) {
98
+ $top_level_elements[] = $e;
99
+ } else {
100
+ $children_elements[ $e->$parent_field ][] = $e;
101
+ }
102
+ }
103
+
104
+ /*
105
+ * when none of the elements is top level assume the first one must be root of the sub elements
106
+ */
107
+ if (empty($top_level_elements)) {
108
+
109
+ $first = array_slice($elements, 0, 1);
110
+ $root = $first[0];
111
+
112
+ $top_level_elements = array();
113
+ $children_elements = array();
114
+ foreach ($elements as $e) {
115
+ if ($root->$parent_field == $e->$parent_field) {
116
+ $top_level_elements[] = $e;
117
+ } else {
118
+ $children_elements[ $e->$parent_field ][] = $e;
119
+ }
120
+ }
121
+ }
122
+
123
+ foreach ($top_level_elements as $e) {
124
+ $this->display_element($e, $children_elements, $max_depth, 0, $args, $output);
125
+ }
126
+
127
+ /*
128
+ * if we are displaying all levels, and remaining children_elements is not empty, then we got orphans, which should be displayed regardless
129
+ */
130
+ if (($max_depth == 0) && count($children_elements) > 0) {
131
+ $empty_array = array();
132
+ foreach ($children_elements as $orphans) {
133
+ foreach ($orphans as $op) {
134
+ $this->display_element($op, $empty_array, 1, 0, $args, $output);
135
+ }
136
+ }
137
+ }
138
+
139
+ return $output;
140
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  }
142
 
143
  /**
144
+ * Widget Class for displaying the grouped categories
145
  */
146
+ class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget {
147
+ /**
148
+ * @var AVH_EC_Category_Group
149
+ */
150
+ public $catgrp;
151
+ /**
152
+ * @var AVH_EC_Core
153
+ */
154
+ public $core;
155
+
156
+ /**
157
+ * PHP 5 Constructor
158
+ */
159
+ public function __construct() {
160
+ $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core');
161
+ $this->catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
162
+
163
+ $widget_ops = array('description' => __("Shows grouped categories.", 'avh-ec'));
164
+ WP_Widget::__construct(false, 'AVH Extended Categories: ' . __('Category Group'), $widget_ops);
165
+ add_action('wp_print_styles', array($this, 'actionWpPrintStyles'));
166
+ }
167
+
168
+ public function actionWpPrintStyles() {
169
+ if ( ! (false === is_active_widget(false, false, $this->id_base, true))) {
170
+ wp_register_style('avhec-widget',
171
+ AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css',
172
+ array(),
173
+ $this->core->version);
174
+ wp_enqueue_style('avhec-widget');
175
+ }
176
+ }
177
+
178
+ public function avh_wp_group_category_checklist($selected_cats, $number) {
179
+ $walker = new AVH_Walker_Category_Checklist();
180
+ $walker->number = $number;
181
+ $walker->input_id = $this->get_field_id('post_group_category');
182
+ $walker->input_name = $this->get_field_name('post_group_category');
183
+ $walker->li_id = $this->get_field_id('group_category--1');
184
+
185
+ $args = array(
186
+ 'taxonomy' => 'avhec_catgroup',
187
+ 'descendants_and_self' => 0,
188
+ 'selected_cats' => array(),
189
+ 'popular_cats' => array(),
190
+ 'walker' => $walker,
191
+ 'checked_ontop' => true
192
+ );
193
+
194
+ if (is_array($selected_cats)) {
195
+ $args['selected_cats'] = $selected_cats;
196
+ } else {
197
+ $args['selected_cats'] = array();
198
+ }
199
+
200
+ $categories = (array) get_terms($args['taxonomy'], array('get' => 'all'));
201
+
202
+ // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache)
203
+ $checked_categories = array();
204
+ $keys = array_keys($categories);
205
+
206
+ foreach ($keys as $k) {
207
+ if (in_array($categories[ $k ]->term_id, $args['selected_cats'])) {
208
+ $checked_categories[] = $categories[ $k ];
209
+ unset($categories[ $k ]);
210
+ }
211
+ }
212
+
213
+ // Put checked cats on top
214
+ echo $walker->walk($checked_categories, 0, $args);
215
+ // Then the rest of them
216
+ echo $walker->walk($categories, 0, $args);
217
+ }
218
+
219
+ /**
220
+ * Display Widget Control Form
221
+ *
222
+ * @param unknown_type $instance
223
+ */
224
+ public function form($instance) {
225
+ // displays the widget admin form
226
+ $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => ''));
227
+
228
+ $selected_cats = (avhGetArrayValue($instance, 'post_group_category') !==
229
+ '') ? unserialize($instance['post_group_category']) : false;
230
+ ob_start();
231
+ echo '<p>';
232
+ avh_doWidgetFormText($this->get_field_id('title'),
233
+ $this->get_field_name('title'),
234
+ __('Title', 'avh-ec'),
235
+ $instance['title']);
236
+ echo '</p>';
237
+
238
+ echo '<p>';
239
+
240
+ avh_doWidgetFormCheckbox($this->get_field_id('count'),
241
+ $this->get_field_name('count'),
242
+ __('Show post counts', 'avh-ec'),
243
+ (bool) avhGetArrayValue($instance, 'count'));
244
+
245
+ avh_doWidgetFormCheckbox($this->get_field_id('hierarchical'),
246
+ $this->get_field_name('hierarchical'),
247
+ __('Show hierarchy', 'avh-ec'),
248
+ (bool) avhGetArrayValue($instance, 'hierarchical'));
249
+
250
+ avh_doWidgetFormCheckbox($this->get_field_id('hide_empty'),
251
+ $this->get_field_name('hide_empty'),
252
+ __('Hide empty categories', 'avh-ec'),
253
+ (bool) avhGetArrayValue($instance, 'hide_empty'));
254
+
255
+ avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'),
256
+ $this->get_field_name('use_desc_for_title'),
257
+ __('Use description for title', 'avh-ec'),
258
+ (bool) avhGetArrayValue($instance, 'use_desc_for_title'));
259
+ echo '</p>';
260
+
261
+ echo '<p>';
262
+ $options['ID'] = __('ID', 'avh-ec');
263
+ $options['name'] = __('Name', 'avh-ec');
264
+ $options['count'] = __('Count', 'avh-ec');
265
+ $options['slug'] = __('Slug', 'avh-ec');
266
+ avh_doWidgetFormSelect($this->get_field_id('sort_column'),
267
+ $this->get_field_name('sort_column'),
268
+ __('Sort by', 'avh-ec'),
269
+ $options,
270
+ avhGetArrayValue($instance, 'sort_column'));
271
+ unset($options);
272
+
273
+ $options['asc'] = __('Ascending', 'avh-ec');
274
+ $options['desc'] = __('Descending', 'avh-ec');
275
+ avh_doWidgetFormSelect($this->get_field_id('sort_order'),
276
+ $this->get_field_name('sort_order'),
277
+ __('Sort order', 'avh-ec'),
278
+ $options,
279
+ avhGetArrayValue($instance, 'sort_order'));
280
+ unset($options);
281
+
282
+ $options['list'] = __('List', 'avh-ec');
283
+ $options['drop'] = __('Drop down', 'avh-ec');
284
+ avh_doWidgetFormSelect($this->get_field_id('style'),
285
+ $this->get_field_name('style'),
286
+ __('Display style', 'avh-ec'),
287
+ $options,
288
+ avhGetArrayValue($instance, 'style'));
289
+ unset($options);
290
+ echo '</p>';
291
+
292
+ echo '<p>';
293
+
294
+ avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'),
295
+ $this->get_field_name('rssfeed'),
296
+ __('Show RSS Feed', 'avh-ec'),
297
+ (bool) avhGetArrayValue($instance, 'rssfeed'));
298
+
299
+ avh_doWidgetFormText($this->get_field_id('rssimage'),
300
+ $this->get_field_name('rssimage'),
301
+ __('Path (URI) to RSS image', 'avh-ec'),
302
+ avhGetArrayValue($instance, 'rssimage'));
303
+ echo '</p>';
304
+
305
+ echo '<p>';
306
+ echo '<b>' . __('Select Groups', 'avh-ec') . '</b><hr />';
307
+ echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear" style="list-style-type: none; margin-left: 5px; padding-left: 0px; margin-bottom: 20px;">';
308
+ echo '<li id="' . $this->get_field_id('group_category--1') . '" class="popular-group_category">';
309
+ echo '<label for="' . $this->get_field_id('group_post_category') . '" class="selectit">';
310
+ echo '<input value="all" id="' .
311
+ $this->get_field_id('group_post_category') .
312
+ '" name="' .
313
+ $this->get_field_name('post_group_category') .
314
+ '[all]" type="checkbox" ' .
315
+ (false === $selected_cats ? ' CHECKED' : '') .
316
+ '> ';
317
+ _e('Any Group', 'avh-ec');
318
+ echo '</label>';
319
+ echo '</li>';
320
+
321
+ $this->avh_wp_group_category_checklist($selected_cats, $this->number);
322
+
323
+ echo '</ul>';
324
+ echo '</p>';
325
+
326
+ echo '<input type="hidden" id="' .
327
+ $this->get_field_id('submit') .
328
+ '" name="' .
329
+ $this->get_field_name('submit') .
330
+ '" value="1" />';
331
+ ob_end_flush();
332
+ }
333
+
334
+ public function getWidgetDoneCatGroup($id) {
335
+ $catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
336
+ if (is_array($catgrp->widget_done_catgroup) && array_key_exists($id, $catgrp->widget_done_catgroup)) {
337
+ return true;
338
+ }
339
+ $catgrp->widget_done_catgroup[ $id ] = true;
340
+
341
+ return false;
342
+ }
343
+
344
+ /**
345
+ * When Widget Control Form Is Posted
346
+ *
347
+ * @param unknown_type $new_instance
348
+ * @param unknown_type $old_instance
349
+ *
350
+ * @return unknown
351
+ */
352
+ public function update($new_instance, $old_instance) {
353
+ // update the instance's settings
354
+ if ( ! isset($new_instance['submit'])) {
355
+ return false;
356
+ }
357
+
358
+ $instance = $old_instance;
359
+
360
+ $instance['title'] = strip_tags(stripslashes($new_instance['title']));
361
+ $instance['count'] = isset($new_instance['count']);
362
+ $instance['hierarchical'] = isset($new_instance['hierarchical']);
363
+ $instance['hide_empty'] = isset($new_instance['hide_empty']);
364
+ $instance['use_desc_for_title'] = isset($new_instance['use_desc_for_title']);
365
+ $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column']));
366
+ $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order']));
367
+ $instance['style'] = strip_tags(stripslashes($new_instance['style']));
368
+ $instance['rssfeed'] = isset($new_instance['rssfeed']);
369
+ $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage']));
370
+ if (array_key_exists('all', $new_instance['post_group_category'])) {
371
+ $instance['post_group_category'] = false;
372
+ } else {
373
+ $instance['post_group_category'] = serialize($new_instance['post_group_category']);
374
+ }
375
+
376
+ return $instance;
377
+ }
378
+
379
+ /**
380
+ * Display the widget
381
+ *
382
+ * @param unknown_type $args
383
+ * @param unknown_type $instance
384
+ */
385
+ public function widget($args, $instance) {
386
+ global $post, $wp_query;
387
+
388
+ $catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
389
+ $options = $this->core->getOptions();
390
+
391
+ $row = array();
392
+
393
+ if (is_home()) {
394
+ $special_page = 'home_group';
395
+ } elseif (is_category()) {
396
+ $special_page = 'category_group';
397
+ } elseif (is_day()) {
398
+ $special_page = 'day_group';
399
+ } elseif (is_month()) {
400
+ $special_page = 'month_group';
401
+ } elseif (is_year()) {
402
+ $special_page = 'year_group';
403
+ } elseif (is_author()) {
404
+ $special_page = 'author_group';
405
+ } elseif (is_search()) {
406
+ $special_page = 'search_group';
407
+ } else {
408
+ $special_page = 'none';
409
+ }
410
+
411
+ $toDisplay = false;
412
+ if ('none' == $special_page) {
413
+ $terms = wp_get_object_terms($post->ID, $catgrp->taxonomy_name);
414
+ if ( ! empty($terms)) {
415
+ $selected_catgroups = unserialize($instance['post_group_category']);
416
+ foreach ($terms as $key => $value) {
417
+ if ($selected_catgroups === false || array_key_exists($value->term_id, $selected_catgroups)) {
418
+ if ( ! ($this->getWidgetDoneCatGroup($value->term_id))) {
419
+ $row = $value;
420
+ $group_found = true;
421
+ break;
422
+ }
423
+ }
424
+ }
425
+ } else {
426
+ $options = $this->core->options;
427
+ $no_cat_group = $options['cat_group']['no_group'];
428
+ $row = get_term_by('id', $no_cat_group, $catgrp->taxonomy_name);
429
+ $group_found = true;
430
+ }
431
+ } else {
432
+ if ('category_group' == $special_page) {
433
+ $tax_meta = get_option($this->core->db_options_tax_meta);
434
+ $term = $wp_query->get_queried_object();
435
+ if (isset($tax_meta[ $term->taxonomy ][ $term->term_id ]['category_group_term_id'])) {
436
+ $sp_category_group_id = $tax_meta[ $term->taxonomy ][ $term->term_id ]['category_group_term_id'];
437
+ } else {
438
+ $sp_category_group = $this->catgrp->getGroupByCategoryID($term->term_id);
439
+ $sp_category_group_id = $sp_category_group->term_id;
440
+ }
441
+ } else {
442
+ $sp_category_group_id = $options['sp_cat_group'][ $special_page ];
443
+ }
444
+ $row = get_term_by('id',
445
+ $sp_category_group_id,
446
+ $catgrp->taxonomy_name); // Returns false when non-existance. (empty(false)=true)
447
+ $group_found = true;
448
+ }
449
+
450
+ if ($group_found) {
451
+ $toDisplay = true;
452
+ $category_group_id_none = $this->catgrp->getTermIDBy('slug', 'none');
453
+ $selected_catgroups = unserialize($instance['post_group_category']);
454
+
455
+ if ($category_group_id_none == $row->term_id) {
456
+ $toDisplay = false;
457
+ } elseif ( ! (false == $selected_catgroups || array_key_exists($row->term_id, $selected_catgroups))) {
458
+ $toDisplay = false;
459
+ } elseif ($special_page != 'none' && $this->getWidgetDoneCatGroup($sp_category_group_id)) {
460
+ $toDisplay = false;
461
+ }
462
+ }
463
+
464
+ if ($toDisplay) {
465
+ extract($args);
466
+
467
+ $c = $instance['count'];
468
+ $e = $instance['hide_empty'];
469
+ $h = $instance['hierarchical'];
470
+ $use_desc_for_title = $instance['use_desc_for_title'];
471
+ $s = isset($instance['sort_column']) ? $instance['sort_column'] : 'name';
472
+ $o = isset($instance['sort_order']) ? $instance['sort_order'] : 'asc';
473
+ $r = $instance['rssfeed'] ? 'RSS' : '';
474
+ $i = $instance['rssimage'] ? $instance['rssimage'] : '';
475
+
476
+ if (empty($r)) {
477
+ $i = '';
478
+ }
479
+
480
+ $style = empty($instance['style']) ? 'list' : $instance['style'];
481
+ $group_id = $row->term_id;
482
+ $cats = $catgrp->getCategoriesFromGroup($group_id);
483
+ if (empty($instance['title'])) {
484
+ $title = $catgrp->getWidgetTitleForGroup($group_id);
485
+ if ( ! $title) {
486
+ $title = __('Categories', 'avh-ec');
487
+ }
488
+ } else {
489
+ $title = $instance['title'];
490
+ }
491
+ $title = apply_filters('widget_title', $title);
492
+
493
+ $included_cats = implode(',', $cats);
494
+
495
+ $show_option_none = __('Select Category', 'avh-ec');
496
+ if ($options['general']['alternative_name_select_category']) {
497
+ $show_option_none = $options['general']['alternative_name_select_category'];
498
+ }
499
+
500
+ $cat_args = array(
501
+ 'include' => $included_cats,
502
+ 'orderby' => $s,
503
+ 'order' => $o,
504
+ 'show_count' => $c,
505
+ 'use_desc_for_title' => $use_desc_for_title,
506
+ 'hide_empty' => $e,
507
+ 'hierarchical' => $h,
508
+ 'title_li' => '',
509
+ 'show_option_none' => $show_option_none,
510
+ 'feed' => $r,
511
+ 'feed_image' => $i,
512
+ 'name' => 'extended-categories-select-group-' . $this->number
513
+ );
514
+ echo $before_widget;
515
+ echo $this->core->comment;
516
+ echo $before_title . $title . $after_title;
517
+
518
+ if ($style == 'list') {
519
+ echo '<ul>';
520
+ $this->core->avh_wp_list_categories($cat_args, true);
521
+ echo '</ul>';
522
+ } else {
523
+ $this->core->avh_wp_dropdown_categories($cat_args, true);
524
+ echo '<script type=\'text/javascript\'>' . "\n";
525
+ echo '/* <![CDATA[ */' . "\n";
526
+ echo ' var ec_dropdown_' .
527
+ $this->number .
528
+ ' = document.getElementById("extended-categories-select-group-' .
529
+ $this->number .
530
+ '");' .
531
+ "\n";
532
+ echo ' function ec_onCatChange_' . $this->number . '() {' . "\n";
533
+ echo ' if (ec_dropdown_' .
534
+ $this->number .
535
+ '.options[ec_dropdown_' .
536
+ $this->number .
537
+ '.selectedIndex].value > 0) {' .
538
+ "\n";
539
+ echo ' location.href = "' .
540
+ get_option('home') .
541
+ '/?cat="+ec_dropdown_' .
542
+ $this->number .
543
+ '.options[ec_dropdown_' .
544
+ $this->number .
545
+ '.selectedIndex].value;' .
546
+ "\n";
547
+ echo ' }' . "\n";
548
+ echo ' }' . "\n";
549
+ echo ' ec_dropdown_' .
550
+ $this->number .
551
+ '.onchange = ec_onCatChange_' .
552
+ $this->number .
553
+ ';' .
554
+ "\n";
555
+ echo '/* ]]> */' . "\n";
556
+ echo '</script>' . "\n";
557
+ }
558
+ echo $after_widget;
559
+ }
560
+ }
561
  }
562
 
563
  /**
564
+ * Widget Class for displaying categories.
565
+ * Extended version of the default categories.
566
  */
567
+ class WP_Widget_AVH_ExtendedCategories_Normal extends WP_Widget {
568
+ /**
569
+ * @var AVH_EC_Core
570
+ */
571
+ public $core;
572
+
573
+ /**
574
+ * PHP 5 Constructor
575
+ */
576
+ public function __construct() {
577
+ $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core');
578
+
579
+ // Convert the old option widget_extended_categories to widget_extended-categories
580
+ $old = get_option('widget_extended_categories');
581
+ if ( ! (false === $old)) {
582
+ update_option('widget_extended-categories', $old);
583
+ delete_option('widget_extended_categories');
584
+ }
585
+ $widget_ops = array('description' => __("An extended version of the default Categories widget.", 'avh-ec'));
586
+ WP_Widget::__construct('extended-categories', 'AVH Extended Categories', $widget_ops);
587
+
588
+ add_action('wp_print_styles', array($this, 'actionWpPrintStyles'));
589
+ }
590
+
591
+ public function actionWpPrintStyles() {
592
+ if ( ! (false === is_active_widget(false, false, $this->id_base, true))) {
593
+ wp_register_style('avhec-widget',
594
+ AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css',
595
+ array(),
596
+ $this->core->version);
597
+ wp_enqueue_style('avhec-widget');
598
+ }
599
+ }
600
+
601
+ /**
602
+ * Creates the categories checklist
603
+ *
604
+ * @param int $post_id
605
+ * @param int $descendants_and_self
606
+ * @param array $selected_cats
607
+ * @param array $popular_cats
608
+ * @param int $number
609
+ */
610
+ public function avh_wp_category_checklist($selected_cats, $number) {
611
+ $walker = new AVH_Walker_Category_Checklist();
612
+ $walker->number = $number;
613
+ $walker->input_id = $this->get_field_id('post_category');
614
+ $walker->input_name = $this->get_field_name('post_category');
615
+ $walker->li_id = $this->get_field_id('category--1');
616
+
617
+ $args = array(
618
+ 'taxonomy' => 'category',
619
+ 'descendants_and_self' => 0,
620
+ 'selected_cats' => $selected_cats,
621
+ 'popular_cats' => array(),
622
+ 'walker' => $walker,
623
+ 'checked_ontop' => true,
624
+ 'popular_cats' => array()
625
+ );
626
+
627
+ if (is_array($selected_cats)) {
628
+ $args['selected_cats'] = $selected_cats;
629
+ } else {
630
+ $args['selected_cats'] = array();
631
+ }
632
+
633
+ $categories = $this->core->getCategories();
634
+ $_categories_id = $this->core->getCategoriesId($categories);
635
+
636
+ // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache)
637
+ $checked_categories = array();
638
+ foreach ($args['selected_cats'] as $key => $value) {
639
+ if (isset($_categories_id[ $key ])) {
640
+ $category_key = $_categories_id[ $key ];
641
+ $checked_categories[] = $categories[ $category_key ];
642
+ unset($categories[ $category_key ]);
643
+ }
644
+ }
645
+
646
+ // Put checked cats on top
647
+ echo $walker->walk($checked_categories, 0, $args);
648
+ // Then the rest of them
649
+ echo $walker->walk($categories, 0, $args);
650
+ }
651
+
652
+ /**
653
+ * Display Widget Control Form
654
+ *
655
+ * @param unknown_type $instance
656
+ */
657
+ public function form($instance) {
658
+ // displays the widget admin form
659
+ $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => '', 'depth' => 0));
660
+
661
+ // Prepare data for display
662
+ $depth = (int) $instance['depth'];
663
+ if ($depth < 0 || 11 < $depth) {
664
+ $depth = 0;
665
+ }
666
+ $selected_cats = (avhGetArrayValue($instance, 'post_category') !==
667
+ '') ? unserialize($instance['post_category']) : false;
668
+
669
+ echo '<p>';
670
+ avh_doWidgetFormText($this->get_field_id('title'),
671
+ $this->get_field_name('title'),
672
+ __('Title', 'avh-ec'),
673
+ avhGetArrayValue($instance, 'title'));
674
+ echo '</p>';
675
+
676
+ echo '<p>';
677
+ avh_doWidgetFormCheckbox($this->get_field_id('selectedonly'),
678
+ $this->get_field_name('selectedonly'),
679
+ __('Show selected categories only', 'avh-ec'),
680
+ (bool) avhGetArrayValue($instance, 'selectedonly'));
681
+
682
+ avh_doWidgetFormCheckbox($this->get_field_id('count'),
683
+ $this->get_field_name('count'),
684
+ __('Show post counts', 'avh-ec'),
685
+ (bool) avhGetArrayValue($instance, 'count'));
686
+
687
+ avh_doWidgetFormCheckbox($this->get_field_id('hierarchical'),
688
+ $this->get_field_name('hierarchical'),
689
+ __('Show hierarchy', 'avh-ec'),
690
+ (bool) avhGetArrayValue($instance, 'hierarchical'));
691
+
692
+ $options = array(0 => __('All Levels', 'avh-ec'), 1 => __('Toplevel only', 'avh-ec'));
693
+ for ($i = 2; $i <= 11; $i ++) {
694
+ $options[ $i ] = __('Child ', 'avh-ec') . ($i - 1);
695
+ }
696
+ avh_doWidgetFormSelect($this->get_field_id('depth'),
697
+ $this->get_field_name('depth'),
698
+ __('How many levels to show', 'avh-ec'),
699
+ $options,
700
+ $depth);
701
+ unset($options);
702
+
703
+ avh_doWidgetFormCheckbox($this->get_field_id('hide_empty'),
704
+ $this->get_field_name('hide_empty'),
705
+ __('Hide empty categories', 'avh-ec'),
706
+ (bool) avhGetArrayValue($instance, 'hide_empty'));
707
+
708
+ avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'),
709
+ $this->get_field_name('use_desc_for_title'),
710
+ __('Use description for title', 'avh-ec'),
711
+ (bool) avhGetArrayValue($instance, 'use_desc_for_title'));
712
+ echo '</p>';
713
+
714
+ echo '<p>';
715
+ $options['ID'] = __('ID', 'avh-ec');
716
+ $options['name'] = __('Name', 'avh-ec');
717
+ $options['count'] = __('Count', 'avh-ec');
718
+ $options['slug'] = __('Slug', 'avh-ec');
719
+ $options['avhec_manualorder'] = 'AVH EC ' . __('Manual Order', 'avh-ec');
720
+ if (is_plugin_active('my-category-order/mycategoryorder.php')) {
721
+ $options['avhec_3rdparty_mycategoryorder'] = 'My Category Order';
722
+ }
723
+
724
+ avh_doWidgetFormSelect($this->get_field_id('sort_column'),
725
+ $this->get_field_name('sort_column'),
726
+ __('Sort by', 'avh-ec'),
727
+ $options,
728
+ avhGetArrayValue($instance, 'sort_column'));
729
+ unset($options);
730
+
731
+ $options['asc'] = __('Ascending', 'avh-ec');
732
+ $options['desc'] = __('Descending', 'avh-ec');
733
+ avh_doWidgetFormSelect($this->get_field_id('sort_order'),
734
+ $this->get_field_name('sort_order'),
735
+ __('Sort order', 'avh-ec'),
736
+ $options,
737
+ avhGetArrayValue($instance, 'sort_order'));
738
+ unset($options);
739
+
740
+ $options['list'] = __('List', 'avh-ec');
741
+ $options['drop'] = __('Drop down', 'avh-ec');
742
+ avh_doWidgetFormSelect($this->get_field_id('style'),
743
+ $this->get_field_name('style'),
744
+ __('Display style', 'avh-ec'),
745
+ $options,
746
+ avhGetArrayValue($instance, 'style'));
747
+ unset($options);
748
+ echo '</p>';
749
+
750
+ echo '<p>';
751
+
752
+ avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'),
753
+ $this->get_field_name('rssfeed'),
754
+ __('Show RSS Feed', 'avh-ec'),
755
+ (bool) avhGetArrayValue($instance, 'rssfeed'));
756
+
757
+ avh_doWidgetFormText($this->get_field_id('rssimage'),
758
+ $this->get_field_name('rssimage'),
759
+ __('Path (URI) to RSS image', 'avh-ec'),
760
+ avhGetArrayValue($instance, 'rssimage'));
761
+
762
+ echo '</p>';
763
+
764
+ echo '<p>';
765
+ echo '<b>' . __('Select categories', 'avh-ec') . '</b><hr />';
766
+ echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear" style="list-style-type: none; margin-left: 5px; padding-left: 0px; margin-bottom: 20px;">';
767
+ echo '<li id="' . $this->get_field_id('category--1') . '" class="popular-category">';
768
+ echo '<label for="' . $this->get_field_id('post_category') . '" class="selectit">';
769
+ echo '<input value="all" id="' .
770
+ $this->get_field_id('post_category') .
771
+ '" name="' .
772
+ $this->get_field_name('post_category') .
773
+ '[all]" type="checkbox" ' .
774
+ (false === $selected_cats ? ' CHECKED' : '') .
775
+ '> ';
776
+ _e('All Categories', 'avh-ec');
777
+ echo '</label>';
778
+ echo '</li>';
779
+ ob_start();
780
+ $this->avh_wp_category_checklist($selected_cats, $this->number);
781
+ ob_end_flush();
782
+ echo '</ul>';
783
+ echo '</p>';
784
+
785
+ echo '<p>';
786
+ avh_doWidgetFormCheckbox($this->get_field_id('invert_included'),
787
+ $this->get_field_name('invert_included'),
788
+ __('Exclude the selected categories', 'avh-ec'),
789
+ (bool) avhGetArrayValue($instance, 'invert_included'));
790
+ echo '</p>';
791
+
792
+ echo '<input type="hidden" id="' .
793
+ $this->get_field_id('submit') .
794
+ '" name="' .
795
+ $this->get_field_name('submit') .
796
+ '" value="1" />';
797
+ }
798
+
799
+ /**
800
+ * When Widget Control Form Is Posted
801
+ *
802
+ * @param unknown_type $new_instance
803
+ * @param unknown_type $old_instance
804
+ *
805
+ * @return unknown
806
+ */
807
+ public function update($new_instance, $old_instance) {
808
+ // update the instance's settings
809
+ if ( ! isset($new_instance['submit'])) {
810
+ return false;
811
+ }
812
+
813
+ $instance = $old_instance;
814
+
815
+ $instance['title'] = strip_tags(stripslashes($new_instance['title']));
816
+ $instance['selectedonly'] = isset($new_instance['selectedonly']);
817
+ $instance['count'] = isset($new_instance['count']);
818
+ $instance['hierarchical'] = isset($new_instance['hierarchical']);
819
+ $instance['hide_empty'] = isset($new_instance['hide_empty']);
820
+ $instance['use_desc_for_title'] = isset($new_instance['use_desc_for_title']);
821
+ $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column']));
822
+ $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order']));
823
+ $instance['style'] = strip_tags(stripslashes($new_instance['style']));
824
+ $instance['rssfeed'] = isset($new_instance['rssfeed']);
825
+ $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage']));
826
+ if (array_key_exists('all', $new_instance['post_category'])) {
827
+ $instance['post_category'] = false;
828
+ } else {
829
+ $instance['post_category'] = serialize($new_instance['post_category']);
830
+ }
831
+ $instance['depth'] = (int) $new_instance['depth'];
832
+ if ($instance['depth'] < 0 || 11 < $instance['depth']) {
833
+ $instance['depth'] = 0;
834
+ }
835
+ $instance['invert_included'] = isset($new_instance['invert_included']);
836
+
837
+ return $instance;
838
+ }
839
+
840
+ /**
841
+ * Display the widget
842
+ *
843
+ * @param unknown_type $args
844
+ * @param unknown_type $instance
845
+ */
846
+ public function widget($args, $instance) {
847
+ extract($args);
848
+
849
+ $selectedonly = $instance['selectedonly'];
850
+ $c = $instance['count'];
851
+ $h = $instance['hierarchical'];
852
+ $d = $instance['depth'];
853
+ $e = $instance['hide_empty'];
854
+ $use_desc_for_title = $instance['use_desc_for_title'];
855
+ $s = isset($instance['sort_column']) ? $instance['sort_column'] : 'name';
856
+ $o = isset($instance['sort_order']) ? $instance['sort_order'] : 'asc';
857
+ $r = ($instance['rssfeed'] == true) ? 'RSS' : '';
858
+ $i = isset($instance['rssimage']) ? $instance['rssimage'] : '';
859
+ $invert = $instance['invert_included'];
860
+
861
+ if (empty($r)) {
862
+ $i = '';
863
+ }
864
+
865
+ if (empty($d)) {
866
+ $d = 0;
867
+ }
868
+
869
+ $title = apply_filters('widget_title',
870
+ empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']);
871
+ $style = empty($instance['style']) ? 'list' : $instance['style'];
872
+
873
+ $included_cats = '';
874
+ if ($instance['post_category']) {
875
+ $post_category = unserialize($instance['post_category']);
876
+ $children = array();
877
+ if ( ! $instance['selectedonly']) {
878
+ foreach ($post_category as $cat_id) {
879
+ $children = array_merge($children, get_term_children($cat_id, 'category'));
880
+ }
881
+ }
882
+ $included_cats = implode(",", array_merge($post_category, $children));
883
+ }
884
+
885
+ if ($invert) {
886
+ $inc_exc = 'exclude';
887
+ } else {
888
+ $inc_exc = 'include';
889
+ }
890
+
891
+ $options = $this->core->getOptions();
892
+ $show_option_none = __('Select Category', 'avh-ec');
893
+ if ($options['general']['alternative_name_select_category']) {
894
+ $show_option_none = $options['general']['alternative_name_select_category'];
895
+ }
896
+
897
+ $cat_args = array(
898
+ $inc_exc => $included_cats,
899
+ 'orderby' => $s,
900
+ 'order' => $o,
901
+ 'show_count' => $c,
902
+ 'use_desc_for_title' => $use_desc_for_title,
903
+ 'hide_empty' => $e,
904
+ 'hierarchical' => $h,
905
+ 'depth' => $d,
906
+ 'title_li' => '',
907
+ 'show_option_none' => $show_option_none,
908
+ 'feed' => $r,
909
+ 'feed_image' => $i,
910
+ 'name' => 'extended-categories-select-' . $this->number
911
+ );
912
+ echo $before_widget;
913
+ echo $this->core->comment;
914
+ echo $before_title . $title . $after_title;
915
+
916
+ if ($style == 'list') {
917
+ echo '<ul>';
918
+ $this->core->avh_wp_list_categories($cat_args);
919
+ echo '</ul>';
920
+ } else {
921
+ $this->core->avh_wp_dropdown_categories($cat_args);
922
+ echo '<script type=\'text/javascript\'>' . "\n";
923
+ echo '/* <![CDATA[ */' . "\n";
924
+ echo ' var ec_dropdown_' .
925
+ $this->number .
926
+ ' = document.getElementById("extended-categories-select-' .
927
+ $this->number .
928
+ '");' .
929
+ "\n";
930
+ echo ' function ec_onCatChange_' . $this->number . '() {' . "\n";
931
+ echo ' if (ec_dropdown_' .
932
+ $this->number .
933
+ '.options[ec_dropdown_' .
934
+ $this->number .
935
+ '.selectedIndex].value > 0) {' .
936
+ "\n";
937
+ echo ' location.href = "' .
938
+ home_url() .
939
+ '/?cat="+ec_dropdown_' .
940
+ $this->number .
941
+ '.options[ec_dropdown_' .
942
+ $this->number .
943
+ '.selectedIndex].value;' .
944
+ "\n";
945
+ echo ' }' . "\n";
946
+ echo ' }' . "\n";
947
+ echo ' ec_dropdown_' .
948
+ $this->number .
949
+ '.onchange = ec_onCatChange_' .
950
+ $this->number .
951
+ ';' .
952
+ "\n";
953
+ echo '/* ]]> */' . "\n";
954
+ echo '</script>' . "\n";
955
+ }
956
+ echo $after_widget;
957
+ }
958
  }
959
 
960
  /**
961
+ * Widget Class for displaying the top categories
962
  */
963
+ class WP_Widget_AVH_ExtendedCategories_Top extends WP_Widget {
964
+ /**
965
+ * @var AVH_EC_Core
966
+ */
967
+ public $core;
968
+
969
+ /**
970
+ * PHP 5 Constructor
971
+ */
972
+ public function __construct() {
973
+ $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core');
974
+
975
+ $widget_ops = array('description' => __("Shows the top categories.", 'avh-ec'));
976
+ WP_Widget::__construct(false, 'AVH Extended Categories: ' . __('Top Categories'), $widget_ops);
977
+ add_action('wp_print_styles', array($this, 'actionWpPrintStyles'));
978
+ }
979
+
980
+ public function actionWpPrintStyles() {
981
+ if ( ! (false === is_active_widget(false, false, $this->id_base, true))) {
982
+ wp_register_style('avhec-widget',
983
+ AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css',
984
+ array(),
985
+ $this->core->version);
986
+ wp_enqueue_style('avhec-widget');
987
+ }
988
+ }
989
+
990
+ /**
991
+ * Echo the settings update form
992
+ *
993
+ * @param array $instance
994
+ * Current settings
995
+ */
996
+ public function form($instance) {
997
+ // displays the widget admin form
998
+ $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => '', 'amount' => '5'));
999
+
1000
+ $amount = (int) avhGetArrayValue($instance, 'amount');
1001
+ if ($amount < 1) {
1002
+ $amount = 1;
1003
+ }
1004
+ echo '<p>';
1005
+ avh_doWidgetFormText($this->get_field_id('title'),
1006
+ $this->get_field_name('title'),
1007
+ __('Title', 'avh-ec'),
1008
+ avhGetArrayValue($instance, 'title'));
1009
+ echo '</p>';
1010
+
1011
+ echo '<p>';
1012
+ avh_doWidgetFormText($this->get_field_id('amount'),
1013
+ $this->get_field_name('amount'),
1014
+ __('How many categories to show', 'avh-ec'),
1015
+ $amount);
1016
+ echo '</p>';
1017
+
1018
+ echo '<p>';
1019
+ avh_doWidgetFormCheckbox($this->get_field_id('count'),
1020
+ $this->get_field_name('count'),
1021
+ __('Show post counts', 'avh-ec'),
1022
+ (bool) avhGetArrayValue($instance, 'count'));
1023
+ echo '<br />';
1024
+
1025
+ avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'),
1026
+ $this->get_field_name('use_desc_for_title'),
1027
+ __('Use description for title', 'avh-ec'),
1028
+ (bool) avhGetArrayValue($instance, 'use_desc_for_title'));
1029
+ echo '</p>';
1030
+
1031
+ echo '<p>';
1032
+ $options['ID'] = __('ID', 'avh-ec');
1033
+ $options['name'] = __('Name', 'avh-ec');
1034
+ $options['count'] = __('Count', 'avh-ec');
1035
+ $options['slug'] = __('Slug', 'avh-ec');
1036
+ avh_doWidgetFormSelect($this->get_field_id('sort_column'),
1037
+ $this->get_field_name('sort_column'),
1038
+ __('Sort by', 'avh-ec'),
1039
+ $options,
1040
+ avhGetArrayValue($instance, 'sort_column'));
1041
+ unset($options);
1042
+
1043
+ $options['asc'] = __('Ascending', 'avh-ec');
1044
+ $options['desc'] = __('Descending', 'avh-ec');
1045
+ avh_doWidgetFormSelect($this->get_field_id('sort_order'),
1046
+ $this->get_field_name('sort_order'),
1047
+ __('Sort order', 'avh-ec'),
1048
+ $options,
1049
+ avhGetArrayValue($instance, 'sort_order'));
1050
+ unset($options);
1051
+
1052
+ $options['list'] = __('List', 'avh-ec');
1053
+ $options['drop'] = __('Drop down', 'avh-ec');
1054
+ avh_doWidgetFormSelect($this->get_field_id('style'),
1055
+ $this->get_field_name('style'),
1056
+ __('Display style', 'avh-ec'),
1057
+ $options,
1058
+ avhGetArrayValue($instance, 'style'));
1059
+ unset($options);
1060
+ echo '</p>';
1061
+
1062
+ echo '<p>';
1063
+
1064
+ avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'),
1065
+ $this->get_field_name('rssfeed'),
1066
+ __('Show RSS Feed', 'avh-ec'),
1067
+ (bool) avhGetArrayValue($instance, 'rssfeed'));
1068
+
1069
+ avh_doWidgetFormText($this->get_field_id('rssimage'),
1070
+ $this->get_field_name('rssimage'),
1071
+ __('Path (URI) to RSS image', 'avh-ec'),
1072
+ avhGetArrayValue($instance, 'rssimage'));
1073
+
1074
+ echo '</p>';
1075
+
1076
+ echo '<input type="hidden" id="' .
1077
+ $this->get_field_id('submit') .
1078
+ '" name="' .
1079
+ $this->get_field_name('submit') .
1080
+ '" value="1" />';
1081
+ }
1082
+
1083
+ /**
1084
+ * Update a particular instance.
1085
+ * This function should check that $new_instance is set correctly.
1086
+ * The newly calculated value of $instance should be returned.
1087
+ * If "false" is returned, the instance won't be saved/updated.
1088
+ *
1089
+ * @param array $new_instance
1090
+ * New settings for this instance as input by the user via form()
1091
+ * @param array $old_instance
1092
+ * Old settings for this instance
1093
+ *
1094
+ * @return array Settings to save or bool false to cancel saving
1095
+ */
1096
+ public function update($new_instance, $old_instance) {
1097
+ // update the instance's settings
1098
+ if ( ! isset($new_instance['submit'])) {
1099
+ return false;
1100
+ }
1101
+
1102
+ $instance = $old_instance;
1103
+
1104
+ $instance['title'] = strip_tags(stripslashes($new_instance['title']));
1105
+ $instance['amount'] = (int) $new_instance['amount'];
1106
+ $instance['count'] = isset($new_instance['count']);
1107
+ $instance['use_desc_for_title'] = isset($new_instance['use_desc_for_title']);
1108
+ $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column']));
1109
+ $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order']));
1110
+ $instance['style'] = strip_tags(stripslashes($new_instance['style']));
1111
+ $instance['rssfeed'] = isset($new_instance['rssfeed']);
1112
+ $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage']));
1113
+
1114
+ return $instance;
1115
+ }
1116
+
1117
+ /**
1118
+ * Echo the widget content.
1119
+ * Subclasses should over-ride this function to generate their widget code.
1120
+ *
1121
+ * @param array $args
1122
+ * Display arguments including before_title, after_title, before_widget, and after_widget.
1123
+ * @param array $instance
1124
+ * The settings for the particular instance of the widget
1125
+ */
1126
+ public function widget($args, $instance) {
1127
+ extract($args);
1128
+
1129
+ $title = apply_filters('widget_title',
1130
+ empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']);
1131
+ $style = empty($instance['style']) ? 'list' : $instance['style'];
1132
+ if ( ! $a = (int) $instance['amount']) {
1133
+ $a = 5;
1134
+ } elseif ($a < 1) {
1135
+ $a = 1;
1136
+ }
1137
+ $c = $instance['count'];
1138
+ $use_desc_for_title = $instance['use_desc_for_title'];
1139
+ $s = isset($instance['sort_column']) ? $instance['sort_column'] : 'name';
1140
+ $o = isset($instance['sort_order']) ? $instance['sort_order'] : 'asc';
1141
+ $r = ($instance['rssfeed'] === true) ? 'RSS' : '';
1142
+ $i = isset($instance['rssimage']) ? $instance['rssimage'] : '';
1143
+ if (empty($r)) {
1144
+ $i = '';
1145
+ }
1146
+ if ( ! empty($i)) {
1147
+ if ( ! file_exists(ABSPATH . '/' . $i)) {
1148
+ $i = '';
1149
+ }
1150
+ }
1151
+
1152
+ $options = $this->core->getOptions();
1153
+ $show_option_none = __('Select Category', 'avh-ec');
1154
+ if ($options['general']['alternative_name_select_category']) {
1155
+ $show_option_none = $options['general']['alternative_name_select_category'];
1156
+ }
1157
+
1158
+ $top_cats = get_terms('category',
1159
+ array(
1160
+ 'fields' => 'ids',
1161
+ 'orderby' => 'count',
1162
+ 'order' => 'DESC',
1163
+ 'number' => $a,
1164
+ 'hierarchical' => false
1165
+ ));
1166
+ $included_cats = implode(",", $top_cats);
1167
+
1168
+ $cat_args = array(
1169
+ 'include' => $included_cats,
1170
+ 'orderby' => $s,
1171
+ 'order' => $o,
1172
+ 'show_count' => $c,
1173
+ 'use_desc_for_title' => $use_desc_for_title,
1174
+ 'hide_empty' => false,
1175
+ 'hierarchical' => false,
1176
+ 'depth' => - 1,
1177
+ 'title_li' => '',
1178
+ 'show_option_none' => $show_option_none,
1179
+ 'feed' => $r,
1180
+ 'feed_image' => $i,
1181
+ 'name' => 'extended-categories-top-select-' . $this->number
1182
+ );
1183
+ echo $before_widget;
1184
+ echo $this->core->comment;
1185
+ echo $before_title . $title . $after_title;
1186
+ echo '<ul>';
1187
+
1188
+ if ($style == 'list') {
1189
+ wp_list_categories($cat_args);
1190
+ } else {
1191
+ wp_dropdown_categories($cat_args);
1192
+ echo '<script type=\'text/javascript\'>' . "\n";
1193
+ echo '/* <![CDATA[ */' . "\n";
1194
+ echo ' var ec_dropdown_top_' .
1195
+ $this->number .
1196
+ ' = document.getElementById("extended-categories-top-select-' .
1197
+ $this->number .
1198
+ '");' .
1199
+ "\n";
1200
+ echo ' function ec_top_onCatChange_' . $this->number . '() {' . "\n";
1201
+ echo ' if (ec_dropdown_top_' .
1202
+ $this->number .
1203
+ '.options[ec_dropdown_top_' .
1204
+ $this->number .
1205
+ '.selectedIndex].value > 0) {' .
1206
+ "\n";
1207
+ echo ' location.href = "' .
1208
+ get_option('home') .
1209
+ '/?cat="+ec_dropdown_top_' .
1210
+ $this->number .
1211
+ '.options[ec_dropdown_top_' .
1212
+ $this->number .
1213
+ '.selectedIndex].value;' .
1214
+ "\n";
1215
+ echo ' }' . "\n";
1216
+ echo ' }' . "\n";
1217
+ echo ' ec_dropdown_top_' .
1218
+ $this->number .
1219
+ '.onchange = ec_top_onCatChange_' .
1220
+ $this->number .
1221
+ ';' .
1222
+ "\n";
1223
+ echo '/* ]]> */' . "\n";
1224
+ echo '</script>' . "\n";
1225
+ }
1226
+ echo '</ul>';
1227
+ echo $after_widget;
1228
+ }
1229
  }
3.6/css/avh-ec.admin.css CHANGED
@@ -1,13 +1,13 @@
1
  .footer_avhec {
2
- font-size: 0.8em;
3
- text-align: center;
4
  }
5
 
6
  div.clearer {
7
- clear: both;
8
- line-height: 1px;
9
- font-size: 1px;
10
- height: 1px;
11
  }
12
 
13
  /* Metabox in General */
@@ -20,12 +20,12 @@ table.avhec-options {
20
  }
21
 
22
  .avhec-metabox-wrap .p {
23
- line-height: 140%;
24
- margin: 1em 0;
25
  }
26
 
27
  #avhecBoxOptions option {
28
- padding: .5em;
29
  }
30
 
31
  .avhec-metabox-wrap span.description {
@@ -33,17 +33,17 @@ table.avhec-options {
33
  }
34
 
35
  .avhec-metabox-wrap .b {
36
- font-weight: bold;
37
  }
38
 
39
  .avhec-metabox-wrap ul {
40
- margin-bottom: 1em;
41
  }
42
 
43
  .avhec-metabox-wrap ul li {
44
- line-height: 120%;
45
- list-style: disc inside none;
46
- margin-bottom: 0;
47
  }
48
 
49
  #avhec-options input {
@@ -56,13 +56,13 @@ table.avhec-options {
56
 
57
  /* Metabox FAQ */
58
  #avhecBoxFAQ .inside ul {
59
- margin-bottom: 6px;
60
  }
61
 
62
  #avhecBoxFAQ .inside ul li {
63
- line-height: 120%;
64
- list-style: disc inside none;
65
- margin-bottom: 0;
66
  }
67
 
68
  /* Metabox Donations*/
@@ -71,7 +71,7 @@ table.avhec-options {
71
  }
72
 
73
  #avhecBoxDonations .versions {
74
- padding: 6px 10px 12px;
75
  }
76
 
77
  /* Metabox Donations*/
@@ -81,75 +81,75 @@ table.avhec-options {
81
 
82
  /* Metabox in post and page */
83
  #post_avhec_category_group {
84
- width: 100%;
85
  }
86
 
87
  #avhec-catlist {
88
- -moz-border-radius: 4px 4px 4px 4px;
89
- background-color: #FFFFFF;
90
- border: 1px solid #DFDFDF;
91
- height: 20em;
92
- margin-bottom: -1.8em;
93
- overflow: auto;
94
- width: 95%;
95
  }
96
 
97
  #avhec-catlist ul {
98
- padding: 3px;
99
  }
100
 
101
  #avhec-catlist li ul {
102
- padding: 0px;
103
  }
104
 
105
  #avhec-catlist li {
106
- margin-bottom: 0px;
107
  }
108
 
109
  #avhecManualOrder {
110
- width: 25%;
111
- /* border: 1px solid #B2B2B2;*/
112
- /* margin: 10px 10px 10px 0px;*/
113
- /* padding: 5px 10px 5px 10px;*/
114
- /* list-style: none;*/
115
- /* background-color: #fff;*/
116
- /* border-radius: 3px;*/
117
- /* -webkit-border-radius: 3px;*/
118
  }
119
 
120
  #avhecManualOrder li.lineitem {
121
- border: 1px solid #DFDFDF;
122
- background-image: none;
123
- border-radius: 3px;
124
- -webkit-border-radius: 3px;
125
- background-color: #FFFFFF;
126
- color: #555555;
127
- cursor: move;
128
- margin-top: 5px;
129
- margin-bottom: 5px;
130
- padding: 2px 5px 2px 5px;
131
- list-style: none outside none;
132
  }
133
 
134
  #avhecManualOrder .sortable-placeholder {
135
- border: 1px dashed #B2B2B2;
136
- margin-top: 5px;
137
- margin-bottom: 5px;
138
- padding: 2px 5px 2px 5px;
139
- height: 1.5em;
140
- line-height: 1.5em;
141
- list-style: none outside none;
142
- background-color: transparent;
143
- /* IE10 */
144
- background-image: -ms-linear-gradient(top, #f9f9f9, #f5f5f5);
145
- /* Firefox */
146
- background-image: -moz-linear-gradient(top, #f9f9f9, #f5f5f5);
147
- /* Opera */
148
- background-image: -o-linear-gradient(top, #f9f9f9, #f5f5f5);
149
- /* old Webkit */
150
- background-image: -webkit-gradient(linear, left top, left bottom, from(#f9f9f9), to(#f5f5f5) );
151
- /* new Webkit */
152
- background-image: -webkit-linear-gradient(top, #f9f9f9, #f5f5f5);
153
- /* proposed W3C Markup */
154
- background-image: linear-gradient(top, #f9f9f9, #f5f5f5);
155
  }
1
  .footer_avhec {
2
+ font-size : 0.8em;
3
+ text-align : center;
4
  }
5
 
6
  div.clearer {
7
+ clear : both;
8
+ line-height : 1px;
9
+ font-size : 1px;
10
+ height : 1px;
11
  }
12
 
13
  /* Metabox in General */
20
  }
21
 
22
  .avhec-metabox-wrap .p {
23
+ line-height : 140%;
24
+ margin : 1em 0;
25
  }
26
 
27
  #avhecBoxOptions option {
28
+ padding : .5em;
29
  }
30
 
31
  .avhec-metabox-wrap span.description {
33
  }
34
 
35
  .avhec-metabox-wrap .b {
36
+ font-weight : bold;
37
  }
38
 
39
  .avhec-metabox-wrap ul {
40
+ margin-bottom : 1em;
41
  }
42
 
43
  .avhec-metabox-wrap ul li {
44
+ line-height : 120%;
45
+ list-style : disc inside none;
46
+ margin-bottom : 0;
47
  }
48
 
49
  #avhec-options input {
56
 
57
  /* Metabox FAQ */
58
  #avhecBoxFAQ .inside ul {
59
+ margin-bottom : 6px;
60
  }
61
 
62
  #avhecBoxFAQ .inside ul li {
63
+ line-height : 120%;
64
+ list-style : disc inside none;
65
+ margin-bottom : 0;
66
  }
67
 
68
  /* Metabox Donations*/
71
  }
72
 
73
  #avhecBoxDonations .versions {
74
+ padding : 6px 10px 12px;
75
  }
76
 
77
  /* Metabox Donations*/
81
 
82
  /* Metabox in post and page */
83
  #post_avhec_category_group {
84
+ width : 100%;
85
  }
86
 
87
  #avhec-catlist {
88
+ -moz-border-radius : 4px 4px 4px 4px;
89
+ background-color : #FFFFFF;
90
+ border : 1px solid #DFDFDF;
91
+ height : 20em;
92
+ margin-bottom : -1.8em;
93
+ overflow : auto;
94
+ width : 95%;
95
  }
96
 
97
  #avhec-catlist ul {
98
+ padding : 3px;
99
  }
100
 
101
  #avhec-catlist li ul {
102
+ padding : 0px;
103
  }
104
 
105
  #avhec-catlist li {
106
+ margin-bottom : 0px;
107
  }
108
 
109
  #avhecManualOrder {
110
+ width : 25%;
111
+ /* border: 1px solid #B2B2B2;*/
112
+ /* margin: 10px 10px 10px 0px;*/
113
+ /* padding: 5px 10px 5px 10px;*/
114
+ /* list-style: none;*/
115
+ /* background-color: #fff;*/
116
+ /* border-radius: 3px;*/
117
+ /* -webkit-border-radius: 3px;*/
118
  }
119
 
120
  #avhecManualOrder li.lineitem {
121
+ border : 1px solid #DFDFDF;
122
+ background-image : none;
123
+ border-radius : 3px;
124
+ -webkit-border-radius : 3px;
125
+ background-color : #FFFFFF;
126
+ color : #555555;
127
+ cursor : move;
128
+ margin-top : 5px;
129
+ margin-bottom : 5px;
130
+ padding : 2px 5px 2px 5px;
131
+ list-style : none outside none;
132
  }
133
 
134
  #avhecManualOrder .sortable-placeholder {
135
+ border : 1px dashed #B2B2B2;
136
+ margin-top : 5px;
137
+ margin-bottom : 5px;
138
+ padding : 2px 5px 2px 5px;
139
+ height : 1.5em;
140
+ line-height : 1.5em;
141
+ list-style : none outside none;
142
+ background-color : transparent;
143
+ /* IE10 */
144
+ background-image : -ms-linear-gradient(top, #f9f9f9, #f5f5f5);
145
+ /* Firefox */
146
+ background-image : -moz-linear-gradient(top, #f9f9f9, #f5f5f5);
147
+ /* Opera */
148
+ background-image : -o-linear-gradient(top, #f9f9f9, #f5f5f5);
149
+ /* old Webkit */
150
+ background-image : -webkit-gradient(linear, left top, left bottom, from(#f9f9f9), to(#f5f5f5));
151
+ /* new Webkit */
152
+ background-image : -webkit-linear-gradient(top, #f9f9f9, #f5f5f5);
153
+ /* proposed W3C Markup */
154
+ background-image : linear-gradient(top, #f9f9f9, #f5f5f5);
155
  }
3.6/css/avh-ec.widget.css CHANGED
@@ -1,12 +1,12 @@
1
  /* AVH Extended Categories Widget CSS */
2
  .avhec-widget-line {
3
- display: inline-block;
4
  }
5
 
6
  .avhec-widget-count {
7
- display: inline;
8
  }
9
 
10
  .avhec-widget-rss {
11
- display: inline;
12
  }
1
  /* AVH Extended Categories Widget CSS */
2
  .avhec-widget-line {
3
+ display : inline-block;
4
  }
5
 
6
  .avhec-widget-count {
7
+ display : inline;
8
  }
9
 
10
  .avhec-widget-rss {
11
+ display : inline;
12
  }
3.6/helpers/avh-common.php CHANGED
@@ -1,18 +1,18 @@
1
  <?php
2
- if ( !function_exists('avhGetArrayValue') ) {
3
 
4
  /**
5
  * Get the value of $array[$name]
6
  *
7
- * @param array $array
8
  * @param string $name
9
  *
10
  * @return mixed An empty string when the $array[$name] does not exists
11
  */
12
- function avhGetArrayValue ($array, $name)
13
- {
14
- if ( isset($array[$name]) )
15
- return $array[$name];
16
 
17
  return '';
18
  }
1
  <?php
2
+ if ( ! function_exists('avhGetArrayValue')) {
3
 
4
  /**
5
  * Get the value of $array[$name]
6
  *
7
+ * @param array $array
8
  * @param string $name
9
  *
10
  * @return mixed An empty string when the $array[$name] does not exists
11
  */
12
+ function avhGetArrayValue($array, $name) {
13
+ if (isset($array[ $name ])) {
14
+ return $array[ $name ];
15
+ }
16
 
17
  return '';
18
  }
3.6/helpers/avh-forms.php CHANGED
@@ -1,43 +1,59 @@
1
  <?php
2
- if (!function_exists('avh_doWidgetFormText')) {
3
 
4
- function avh_doWidgetFormText($field_id, $field_name, $description, $value)
5
- {
6
- echo '<label for="' . $field_id . '">';
7
- echo $description;
8
- echo '<input class="widefat" id="' . $field_id . '" name="' . $field_name . '" type="text" value="' . esc_attr($value) . '" /> ';
9
- echo '</label>';
10
- echo '<br />';
11
- }
 
 
 
 
 
12
  }
13
 
14
- if (!function_exists('avh_doWidgetFormCheckbox')) {
15
 
16
- function avh_doWidgetFormCheckbox($field_id, $field_name, $description, $is_checked = false)
17
- {
18
- echo '<label for="' . $field_id . '">';
19
- echo '<input class="checkbox" type="checkbox" id="' . $field_id . '" name="' . $field_name . '"' . ($is_checked ? ' CHECKED' : '') . ' /> ';
20
- echo $description;
21
- echo '</label>';
22
- echo '<br />';
23
- }
 
 
 
 
 
24
  }
25
 
26
- if (!function_exists('avh_doWidgetFormSelect')) {
27
 
28
- function avh_doWidgetFormSelect($field_id, $field_name, $description, $options, $selected_value)
29
- {
30
- echo '<label for="' . $field_id . '">';
31
- echo $description . ' ';
32
- echo '</label>';
33
 
34
- $data = '';
35
- foreach ($options as $value => $text) {
36
- $data .= '<option value="' . $value . '" ' . ($value == $selected_value ? "SELECTED" : '') . '>' . $text . '</option>' . "/n";
37
- }
38
- echo '<select id="' . $field_id . '" name="' . $field_name . '"> ';
39
- echo $data;
40
- echo '</select>';
41
- echo '<br />';
42
- }
 
 
 
 
 
 
 
43
  }
1
  <?php
2
+ if ( ! function_exists('avh_doWidgetFormText')) {
3
 
4
+ function avh_doWidgetFormText($field_id, $field_name, $description, $value) {
5
+ echo '<label for="' . $field_id . '">';
6
+ echo $description;
7
+ echo '<input class="widefat" id="' .
8
+ $field_id .
9
+ '" name="' .
10
+ $field_name .
11
+ '" type="text" value="' .
12
+ esc_attr($value) .
13
+ '" /> ';
14
+ echo '</label>';
15
+ echo '<br />';
16
+ }
17
  }
18
 
19
+ if ( ! function_exists('avh_doWidgetFormCheckbox')) {
20
 
21
+ function avh_doWidgetFormCheckbox($field_id, $field_name, $description, $is_checked = false) {
22
+ echo '<label for="' . $field_id . '">';
23
+ echo '<input class="checkbox" type="checkbox" id="' .
24
+ $field_id .
25
+ '" name="' .
26
+ $field_name .
27
+ '"' .
28
+ ($is_checked ? ' CHECKED' : '') .
29
+ ' /> ';
30
+ echo $description;
31
+ echo '</label>';
32
+ echo '<br />';
33
+ }
34
  }
35
 
36
+ if ( ! function_exists('avh_doWidgetFormSelect')) {
37
 
38
+ function avh_doWidgetFormSelect($field_id, $field_name, $description, $options, $selected_value) {
39
+ echo '<label for="' . $field_id . '">';
40
+ echo $description . ' ';
41
+ echo '</label>';
 
42
 
43
+ $data = '';
44
+ foreach ($options as $value => $text) {
45
+ $data .= '<option value="' .
46
+ $value .
47
+ '" ' .
48
+ ($value == $selected_value ? "SELECTED" : '') .
49
+ '>' .
50
+ $text .
51
+ '</option>' .
52
+ "/n";
53
+ }
54
+ echo '<select id="' . $field_id . '" name="' . $field_name . '"> ';
55
+ echo $data;
56
+ echo '</select>';
57
+ echo '<br />';
58
+ }
59
  }
3.6/js/avh-ec.admin.manualorder.closure.js DELETED
@@ -1 +0,0 @@
1
- function avhecManualOrder(){jQuery("#avhecManualOrder").sortable({placeholder:"sortable-placeholder",revert:false,items:".lineitem",opacity:0.65,cursor:"move",forcePlaceholderSize:true,tolerance:"pointer"})}addLoadEvent(avhecManualOrder);function orderCats(){jQuery("#updateText").html("Updating Category Order...");jQuery("#hdnManualOrder").val(jQuery("#avhecManualOrder").sortable("toArray"))};
 
3.6/js/avh-ec.admin.manualorder.js CHANGED
@@ -1,19 +1,19 @@
1
  function avhecManualOrder() {
2
- jQuery("#avhecManualOrder").sortable({
3
- placeholder : "sortable-placeholder",
4
- revert : false,
5
- items : '.lineitem',
6
- opacity: 0.65,
7
- cursor: 'move',
8
- forcePlaceholderSize: true,
9
- tolerance : "pointer"
10
- });
11
  };
12
 
13
  addLoadEvent(avhecManualOrder);
14
 
15
  function orderCats() {
16
- jQuery("#updateText").html("Updating Category Order...");
17
- jQuery("#hdnManualOrder").val(
18
- jQuery("#avhecManualOrder").sortable("toArray"));
19
  }
1
  function avhecManualOrder() {
2
+ jQuery("#avhecManualOrder").sortable({
3
+ placeholder: "sortable-placeholder",
4
+ revert: false,
5
+ items: '.lineitem',
6
+ opacity: 0.65,
7
+ cursor: 'move',
8
+ forcePlaceholderSize: true,
9
+ tolerance: "pointer"
10
+ });
11
  };
12
 
13
  addLoadEvent(avhecManualOrder);
14
 
15
  function orderCats() {
16
+ jQuery("#updateText").html("Updating Category Order...");
17
+ jQuery("#hdnManualOrder").val(
18
+ jQuery("#avhecManualOrder").sortable("toArray"));
19
  }
3.6/js/avh-ec.admin.manualorder.min.js ADDED
@@ -0,0 +1 @@
 
1
+ function avhecManualOrder(){jQuery("#avhecManualOrder").sortable({placeholder:"sortable-placeholder",revert:false,items:".lineitem",opacity:.65,cursor:"move",forcePlaceholderSize:true,tolerance:"pointer"})}addLoadEvent(avhecManualOrder);function orderCats(){jQuery("#updateText").html("Updating Category Order...");jQuery("#hdnManualOrder").val(jQuery("#avhecManualOrder").sortable("toArray"))}
3.6/js/avh-ec.categorygroup.closure.js DELETED
@@ -1 +0,0 @@
1
- jQuery(document).ready(function(a){a("#the-list").wpList({delBefore:function(b){if("undefined"!=showNotice)return showNotice.warn()?b:false;return b}});a('.delete a[class^="delete"]').live("click",function(){return false})});
 
3.6/js/avh-ec.categorygroup.js CHANGED
@@ -1,21 +1,23 @@
1
- jQuery(document).ready(function($) {
2
- var options = false, delBefore, delAfter;
3
 
4
- delAfter = function( r, settings ) {
5
- var id = $('cat', r).attr('id'), o;
6
- for ( o = 0; o < options.length; o++ )
7
- if ( id == options[o].value )
8
- options[o] = null;
9
- };
10
 
11
- delBefore = function(s) {
12
- if ( 'undefined' != showNotice )
13
- return showNotice.warn() ? s : false;
14
 
15
- return s;
16
- };
17
 
18
- $('#the-list').wpList({ delBefore: delBefore });
19
 
20
- $('.delete a[class^="delete"]').live('click', function(){return false;});
 
 
21
  });
1
+ jQuery(document).ready(function ($) {
2
+ var options = false, delBefore, delAfter;
3
 
4
+ delAfter = function (r, settings) {
5
+ var id = $('cat', r).attr('id'), o;
6
+ for (o = 0; o < options.length; o++)
7
+ if (id == options[o].value)
8
+ options[o] = null;
9
+ };
10
 
11
+ delBefore = function (s) {
12
+ if ('undefined' != showNotice)
13
+ return showNotice.warn() ? s : false;
14
 
15
+ return s;
16
+ };
17
 
18
+ $('#the-list').wpList({delBefore: delBefore});
19
 
20
+ $('.delete a[class^="delete"]').live('click', function () {
21
+ return false;
22
+ });
23
  });
3.6/js/avh-ec.categorygroup.min.js ADDED
@@ -0,0 +1 @@
 
1
+ jQuery(document).ready(function($){var options=false,delBefore,delAfter;delAfter=function(r,settings){var id=$("cat",r).attr("id"),o;for(o=0;o<options.length;o++)if(id==options[o].value)options[o]=null};delBefore=function(s){if("undefined"!=showNotice)return showNotice.warn()?s:false;return s};$("#the-list").wpList({delBefore:delBefore});$('.delete a[class^="delete"]').live("click",function(){return false})});
4.2/avh-ec.client.php CHANGED
@@ -2,39 +2,38 @@
2
 
3
  /**
4
  * Singleton Class
5
-
6
  */
7
- class AVH_EC_Singleton
8
- {
9
- /**
10
- * @param string $class
11
- * @param string $arg1
12
- */
13
- public static function &getInstance($class, $arg1 = null)
14
- {
15
- static $instances = array(); // array of instance names
16
- if (array_key_exists($class, $instances)) {
17
- $instance = &$instances[$class];
18
- } else {
19
- if (!class_exists($class)) {
20
- switch ($class) {
21
- case 'AVH_EC_Core':
22
- require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.core.php');
23
- break;
24
- case 'AVH_EC_Category_Group':
25
- require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.category-group.php');
26
- break;
27
- case 'AVH_EC_Widget_Helper_Class':
28
- require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widget-helper.php');
29
- break;
30
- }
31
- }
32
- $instances[$class] = new $class($arg1);
33
- $instance = &$instances[$class];
34
- }
35
 
36
- return $instance;
37
- }
38
  }
39
 
40
  /**
@@ -47,16 +46,15 @@ require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widgets.php');
47
  /**
48
  * Initialize the plugin
49
  */
50
- function avhextendedcategories_init()
51
- {
52
- // Admin
53
- if (is_admin()) {
54
- require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.admin.php');
55
- $avhec_admin = new AVH_EC_Admin();
56
- }
57
- AVH_EC_Singleton::getInstance('AVH_EC_Core');
58
 
59
- add_action('widgets_init', 'avhextendedcategories_widgets_init');
60
  } // End avhamazon_init()
61
 
62
  /**
@@ -65,11 +63,10 @@ function avhextendedcategories_init()
65
  * @WordPress Action widgets_init
66
  * @since 3.0
67
  */
68
- function avhextendedcategories_widgets_init()
69
- {
70
- register_widget('WP_Widget_AVH_ExtendedCategories_Normal');
71
- register_widget('WP_Widget_AVH_ExtendedCategories_Top');
72
- register_widget('WP_Widget_AVH_ExtendedCategories_Category_Group');
73
  }
74
 
75
  add_action('plugins_loaded', 'avhextendedcategories_init');
2
 
3
  /**
4
  * Singleton Class
 
5
  */
6
+ class AVH_EC_Singleton {
7
+ /**
8
+ * @param string $class
9
+ * @param string $arg1
10
+ *
11
+ * @return object
12
+ */
13
+ public static function &getInstance($class, $arg1 = null) {
14
+ static $instances = array(); // array of instance names
15
+ if (array_key_exists($class, $instances)) {
16
+ $instance = &$instances[ $class ];
17
+ } else {
18
+ if ( ! class_exists($class)) {
19
+ switch ($class) {
20
+ case 'AVH_EC_Core':
21
+ require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.core.php');
22
+ break;
23
+ case 'AVH_EC_Category_Group':
24
+ require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.category-group.php');
25
+ break;
26
+ case 'AVH_EC_Widget_Helper_Class':
27
+ require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widget-helper.php');
28
+ break;
29
+ }
30
+ }
31
+ $instances[ $class ] = new $class($arg1);
32
+ $instance = &$instances[ $class ];
33
+ }
34
 
35
+ return $instance;
36
+ }
37
  }
38
 
39
  /**
46
  /**
47
  * Initialize the plugin
48
  */
49
+ function avhextendedcategories_init() {
50
+ // Admin
51
+ if (is_admin()) {
52
+ require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.admin.php');
53
+ new AVH_EC_Admin();
54
+ }
55
+ AVH_EC_Singleton::getInstance('AVH_EC_Core');
 
56
 
57
+ add_action('widgets_init', 'avhextendedcategories_widgets_init');
58
  } // End avhamazon_init()
59
 
60
  /**
63
  * @WordPress Action widgets_init
64
  * @since 3.0
65
  */
66
+ function avhextendedcategories_widgets_init() {
67
+ register_widget('WP_Widget_AVH_ExtendedCategories_Normal');
68
+ register_widget('WP_Widget_AVH_ExtendedCategories_Top');
69
+ register_widget('WP_Widget_AVH_ExtendedCategories_Category_Group');
 
70
  }
71
 
72
  add_action('plugins_loaded', 'avhextendedcategories_init');
4.2/class/avh-ec.admin.php CHANGED
@@ -1,1986 +1,1848 @@
1
  <?php
2
 
3
- class AVH_EC_Admin
4
- {
5
- /**
6
- * @var AVH_EC_Category_Group
7
- */
8
- public $catgrp;
9
- /**
10
- * @var AVH_EC_Core
11
- */
12
- public $core;
13
- public $hooks = array();
14
- public $message;
15
-
16
- /**
17
- * PHP5 constructor
18
- */
19
- public function __construct()
20
- {
21
-
22
- // Initialize the plugin
23
- $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core');
24
- $this->catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
25
-
26
- add_action('wp_ajax_delete-group', array($this, 'ajaxDeleteGroup'));
27
-
28
- // Admin menu
29
- add_action('admin_init', array($this, 'actionAdminInit'));
30
- add_action('admin_menu', array($this, 'actionAdminMenu'));
31
- add_filter(
32
- 'plugin_action_links_extended-categories-widget/widget_extended_categories.php',
33
- array($this, 'filterPluginActions'),
34
- 10,
35
- 2
36
- );
37
-
38
- // Actions used for editing posts
39
- add_action('load-post.php', array($this, 'actionLoadPostPage'));
40
- add_action('load-page.php', array($this, 'actionLoadPostPage'));
41
-
42
- // Actions related to adding and deletes categories
43
- add_action('created_category', array($this, 'actionCreatedCategory'), 10, 2);
44
- add_action('delete_category', array($this, 'actionDeleteCategory'), 10, 2);
45
-
46
- add_filter('manage_categories_group_columns', array($this, 'filterManageCategoriesGroupColumns'));
47
- add_filter('explain_nonce_delete-avhecgroup', array($this, 'filterExplainNonceDeleteGroup'), 10, 2);
48
-
49
- return;
50
- }
51
-
52
- public function actionAdminInit()
53
- {
54
- if (is_admin() && isset($_GET['taxonomy']) && 'category' == $_GET['taxonomy']) {
55
- add_action($_GET['taxonomy'] . '_edit_form', array($this, 'displayCategoryGroupForm'), 10, 2);
56
- }
57
- add_action('edit_term', array($this, 'handleEditTerm'), 10, 3);
58
- }
59
-
60
- /**
61
- * Add the Tools and Options to the Management and Options page repectively
62
- *
63
- * @WordPress Action admin_menu
64
- */
65
- public function actionAdminMenu()
66
- {
67
-
68
- // Register Style and Scripts
69
- $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.closure';
70
- wp_register_script(
71
- 'avhec-categorygroup-js',
72
- AVHEC_PLUGIN_URL . '/js/avh-ec.categorygroup' . $suffix . '.js',
73
- array('jquery'),
74
- $this->core->version,
75
- true
76
- );
77
- wp_register_script(
78
- 'avhec-manualorder',
79
- AVHEC_PLUGIN_URL . '/js/avh-ec.admin.manualorder' . $suffix . '.js',
80
- array('jquery-ui-sortable'),
81
- $this->core->version,
82
- false
83
- );
84
- wp_register_style(
85
- 'avhec-admin-css',
86
- AVHEC_PLUGIN_URL . '/css/avh-ec.admin.css',
87
- array('wp-admin'),
88
- $this->core->version,
89
- 'screen'
90
- );
91
-
92
- // Add menu system
93
- $folder = $this->core->getBaseDirectory(AVHEC_PLUGIN_DIR);
94
- add_menu_page(
95
- 'AVH Extended Categories',
96
- 'AVH Extended Categories',
97
- 'manage_options',
98
- $folder,
99
- array($this, 'doMenuOverview')
100
- );
101
- $this->hooks['menu_overview'] = add_submenu_page(
102
- $folder,
103
- 'AVH Extended Categories: ' . __('Overview', 'avh-ec'),
104
- __('Overview', 'avh-ec'),
105
- 'manage_options',
106
- $folder,
107
- array($this, 'doMenuOverview')
108
- );
109
- $this->hooks['menu_general'] = add_submenu_page(
110
- $folder,
111
- 'AVH Extended Categories: ' . __('General Options', 'avh-ec'),
112
- __('General Options', 'avh-ec'),
113
- 'manage_options',
114
- 'avhec-general',
115
- array($this, 'doMenuGeneral')
116
- );
117
- $this->hooks['menu_category_groups'] = add_submenu_page(
118
- $folder,
119
- 'AVH Extended Categories: ' . __('Category Groups', 'avh-ec'),
120
- __('Category Groups', 'avh-ec'),
121
- 'manage_options',
122
- 'avhec-grouped',
123
- array($this, 'doMenuCategoryGroup')
124
- );
125
- $this->hooks['menu_manual_order'] = add_submenu_page(
126
- $folder,
127
- 'AVH Extended Categories: ' . __('Manually Order', 'avh-ec'),
128
- __('Manually Order', 'avh-ec'),
129
- 'manage_options',
130
- 'avhec-manual-order',
131
- array($this, 'doMenuManualOrder')
132
- );
133
- $this->hooks['menu_faq'] = add_submenu_page(
134
- $folder,
135
- 'AVH Extended Categories:' . __('F.A.Q', 'avh-ec'),
136
- __('F.A.Q', 'avh-ec'),
137
- 'manage_options',
138
- 'avhec-faq',
139
- array($this, 'doMenuFAQ')
140
- );
141
-
142
- // Add actions for menu pages
143
- // Overview Menu
144
- add_action('load-' . $this->hooks['menu_overview'], array($this, 'actionLoadPageHook_Overview'));
145
-
146
- // General Options Menu
147
- add_action('load-' . $this->hooks['menu_general'], array($this, 'actionLoadPageHook_General'));
148
-
149
- // Category Groups Menu
150
- add_action('load-' . $this->hooks['menu_category_groups'], array($this, 'actionLoadPageHook_CategoryGroup'));
151
-
152
- // Manual Order Menu
153
- add_action('load-' . $this->hooks['menu_manual_order'], array($this, 'actionLoadPageHook_ManualOrder'));
154
-
155
- // FAQ Menu
156
- add_action('load-' . $this->hooks['menu_faq'], array($this, 'actionLoadPageHook_faq'));
157
- }
158
-
159
- /**
160
- * When a category is created this function is called to add the new category to the group all
161
- *
162
- * @param int $term_id
163
- * @param int $term_taxonomy_id
164
- */
165
- public function actionCreatedCategory($term_id, $term_taxonomy_id)
166
- {
167
- $group_id = $this->catgrp->getTermIDBy('slug', 'all');
168
- $this->catgrp->setCategoriesForGroup($group_id, (array) $term_id);
169
- }
170
-
171
- /**
172
- * When a category is deleted this function is called so the category is deleted from every group as well.
173
- *
174
- * @param int $term_id
175
- * @param int $term_taxonomy_id
176
- *
177
- * @internal param object $term
178
- */
179
- public function actionDeleteCategory($term_id, $term_taxonomy_id)
180
- {
181
- $this->catgrp->doDeleteCategoryFromGroup($term_id);
182
- }
183
-
184
- /**
185
- * Setup everything needed for the Category Group page
186
- */
187
- public function actionLoadPageHook_CategoryGroup()
188
- {
189
-
190
- // Add metaboxes
191
- add_meta_box(
192
- 'avhecBoxCategoryGroupAdd',
193
- __('Add Group', 'avh-ec'),
194
- array($this, 'metaboxCategoryGroupAdd'),
195
- $this->hooks['menu_category_groups'],
196
- 'normal',
197
- 'core'
198
- );
199
- add_meta_box(
200
- 'avhecBoxCategoryGroupList',
201
- __('Group Overview', 'avh-ec'),
202
- array($this, 'metaboxCategoryGroupList'),
203
- $this->hooks['menu_category_groups'],
204
- 'side',
205
- 'core'
206
- );
207
- add_meta_box(
208
- 'avhecBoxCategoryGroupSpecialPages',
209
- __('Special Pages', 'avh-ec'),
210
- array($this, 'metaboxCategoryGroupSpecialPages'),
211
- $this->hooks['menu_category_groups'],
212
- 'normal',
213
- 'core'
214
- );
215
-
216
- add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
217
-
218
- // WordPress core Scripts
219
- wp_enqueue_script('common');
220
- wp_enqueue_script('wp-lists');
221
- wp_enqueue_script('postbox');
222
-
223
- // Plugin Scripts
224
- wp_enqueue_script('avhec-categorygroup-js');
225
-
226
- // Plugin Style
227
- wp_enqueue_style('avhec-admin-css');
228
- }
229
-
230
- /**
231
- * Setup everything needed for the General Options page
232
- */
233
- public function actionLoadPageHook_General()
234
- {
235
- // Add metaboxes
236
- add_meta_box(
237
- 'avhecBoxOptions',
238
- __('Options', 'avh-ec'),
239
- array($this, 'metaboxOptions'),
240
- $this->hooks['menu_general'],
241
- 'normal',
242
- 'core'
243
- );
244
-
245
- add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
246
-
247
- // WordPress core Scripts
248
- wp_enqueue_script('common');
249
- wp_enqueue_script('wp-lists');
250
- wp_enqueue_script('postbox');
251
-
252
- // Plugin Style and Scripts
253
- wp_enqueue_style('avhec-admin-css');
254
- }
255
-
256
- /**
257
- * Setup everything needed for the Manul Order page
258
- */
259
- public function actionLoadPageHook_ManualOrder()
260
- {
261
- add_meta_box(
262
- 'avhecBoxManualOrder',
263
- __('Manually Order Categories', 'avh-ec'),
264
- array($this, 'metaboxManualOrder'),
265
- $this->hooks['menu_manual_order'],
266
- 'normal',
267
- 'core'
268
- );
269
-
270
- add_screen_option('layout_columns', array('max' => 1, 'default' => 1));
271
-
272
- // WordPress core Styles and Scripts
273
- wp_enqueue_script('common');
274
- wp_enqueue_script('wp-lists');
275
- wp_enqueue_script('postbox');
276
- wp_enqueue_script('jquery-ui-sortable');
277
- wp_enqueue_script('avhec-manualorder');
278
-
279
- // Plugin Style
280
- wp_enqueue_style('avhec-admin-css');
281
- }
282
-
283
- /**
284
- * Setup everything needed for the Overview page
285
- */
286
- public function actionLoadPageHook_Overview()
287
- {
288
- // Add metaboxes
289
- add_meta_box(
290
- 'avhecBoxCategoryGroupList',
291
- __('Group Overview', 'avh-ec'),
292
- array($this, 'metaboxCategoryGroupList'),
293
- $this->hooks['menu_overview'],
294
- 'normal',
295
- 'core'
296
- );
297
- add_meta_box(
298
- 'avhecBoxTranslation',
299
- __('Translation', 'avh-ec'),
300
- array($this, 'metaboxTranslation'),
301
- $this->hooks['menu_overview'],
302
- 'normal',
303
- 'core'
304
- );
305
-
306
- add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
307
-
308
- // WordPress core Scripts
309
- wp_enqueue_script('common');
310
- wp_enqueue_script('wp-lists');
311
- wp_enqueue_script('postbox');
312
-
313
- // Plugin Scripts
314
- wp_enqueue_script('avhec-categorygroup-js');
315
-
316
- // Plugin Style
317
- wp_enqueue_style('avhec-admin-css');
318
- }
319
-
320
- /**
321
- * Setup everything needed for the FAQ page
322
- */
323
- public function actionLoadPageHook_faq()
324
- {
325
- add_meta_box(
326
- 'avhecBoxFAQ',
327
- __('F.A.Q.', 'avh-ec'),
328
- array($this, 'metaboxFAQ'),
329
- $this->hooks['menu_faq'],
330
- 'normal',
331
- 'core'
332
- );
333
- add_meta_box(
334
- 'avhecBoxTranslation',
335
- __('Translation', 'avh-ec'),
336
- array($this, 'metaboxTranslation'),
337
- $this->hooks['menu_faq'],
338
- 'normal',
339
- 'core'
340
- );
341
-
342
- add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
343
-
344
- // WordPress core Styles and Scripts
345
- wp_enqueue_script('common');
346
- wp_enqueue_script('wp-lists');
347
- wp_enqueue_script('postbox');
348
-
349
- // Plugin Style
350
- wp_enqueue_style('avhec-admin-css');
351
- }
352
-
353
- /**
354
- * Enqueues the style on the post.php and page.php pages
355
- *
356
- * @WordPress Action load-$pagenow
357
- */
358
- public function actionLoadPostPage()
359
- {
360
- wp_enqueue_style('avhec-admin-css');
361
- }
362
-
363
- /**
364
- * Ajax Helper: inline delete of the groups
365
- */
366
- public function ajaxDeleteGroup()
367
- {
368
- $group_id = isset($_POST['id']) ? (int) $_POST['id'] : 0;
369
- check_ajax_referer('delete-avhecgroup_' . $group_id);
370
-
371
- if (!current_user_can('manage_categories')) {
372
- die('-1');
373
- }
374
- $check = $this->catgrp->getGroup($group_id);
375
- if (false === $check) {
376
- die('1');
377
- }
378
-
379
- if ($this->catgrp->doDeleteGroup($group_id)) {
380
- die('1');
381
- } else {
382
- die('0');
383
- }
384
- }
385
-
386
- /**
387
- * Adds Category Group form
388
- *
389
- * @WordPress action category_edit_form
390
- *
391
- * @param object $term
392
- * @param string $taxonomy
393
- */
394
- public function displayCategoryGroupForm($term, $taxonomy)
395
- {
396
- $current_selection = '';
397
- $tax_meta = get_option($this->core->db_options_tax_meta);
398
- if (isset($tax_meta[$taxonomy][$term->term_id])) {
399
- $tax_meta = $tax_meta[$taxonomy][$term->term_id];
400
- $current_selection = $tax_meta['category_group_term_id'];
401
- }
402
-
403
- if (empty($current_selection)) {
404
- $current_group = $this->catgrp->getGroupByCategoryID($term->term_id);
405
- $current_selection = $current_group->term_id;
406
- }
407
-
408
- $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false));
409
- foreach ($cat_groups as $group) {
410
- $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit');
411
- $dropdown_value[] = $group->term_id;
412
- $dropdown_text[] = $temp_cat->name;
413
- }
414
-
415
- $seldata = '';
416
- foreach ($dropdown_value as $key => $sel) {
417
- $seldata .= '<option value="' .
418
- esc_attr($sel) .
419
- '" ' .
420
- (($current_selection == $sel) ? 'selected="selected"' : '') .
421
- ' >' .
422
- esc_html(ucfirst($dropdown_text[$key])) .
423
- '</option>' .
424
- "\n";
425
- }
426
-
427
- echo '<h3>AVH Extended Categories - Category Group Widget</h3>';
428
- echo '<table class="form-table"><tbody>';
429
- echo '<tr class="form-field">';
430
- echo '<th valign="top" scope="row">';
431
- echo '<label for="avhec_categorygroup">Category Group</label></th>';
432
- echo '<td>';
433
- echo '<select id="avhec_categorygroup" name="avhec_categorygroup">';
434
- echo $seldata;
435
- echo '</select>';
436
- echo '<p class="description">Select the category group to show on the archive page.</p>';
437
- echo '</td>';
438
- echo '</tr>';
439
- echo '</tbody></table>';
440
- }
441
-
442
- /**
443
- * Displays the icon on the menu pages
444
- *
445
- * @param string $icon
446
- *
447
- * @return string
448
- */
449
- public function displayIcon($icon)
450
- {
451
- return ('<div class="icon32" id="icon-' . $icon . '"><br/></div>');
452
- }
453
-
454
- /**
455
- * Display WP alert
456
- */
457
- public function displayMessage()
458
- {
459
- if ($this->message != '') {
460
- $message = $this->message;
461
- $status = $this->status;
462
- $this->message = $this->status = ''; // Reset
463
- }
464
- if (isset($message)) {
465
- $status = ($status != '') ? $status : 'updated fade';
466
- echo '<div id="message" class="' . $status . '">';
467
- echo '<p><strong>' . $message . '</strong></p></div>';
468
- }
469
- }
470
-
471
- /**
472
- * Menu Page Category Group
473
- *
474
- * @return void
475
- */
476
- public function doMenuCategoryGroup()
477
- {
478
- global $screen_layout_columns;
479
-
480
- $data_add_group_default = array('name' => '', 'slug' => '', 'widget_title' => '', 'description' => '');
481
- $data_add_group_new = $data_add_group_default;
482
-
483
- $options_add_group[] = array(
484
- 'avhec_add_group[add][name]',
485
- __('Group Name', 'avh-ec'),
486
- 'text',
487
- 20,
488
- __('The name is used to identify the group.', 'avh-ec')
489
- );
490
- $options_add_group[] = array(
491
- 'avhec_add_group[add][slug]',
492
- __('Slug Group', 'avh-ec'),
493
- 'text',
494
- 20,
495
- __(
496
- 'The “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.',
497
- 'avh-ec'
498
- )
499
- );
500
- $options_add_group[] = array(
501
- 'avhec_add_group[add][widget_title]',
502
- __('Widget Title', 'avh-ec'),
503
- 'text',
504
- 20,
505
- __(
506
- 'When no title is given in the widget options, this will used as the title of the widget when this group is shown.',
507
- 'avh-ec'
508
- )
509
- );
510
- $options_add_group[] = array(
511
- 'avhec_add_group[add][description]',
512
- __('Description', 'avh-ec'),
513
- 'textarea',
514
- 40,
515
- __('Description is not prominent by default.', 'avh-ec'),
516
- 5
517
- );
518
-
519
- $options_edit_group[] = array(
520
- 'avhec_edit_group[edit][name]',
521
- __('Group Name', 'avh-ec'),
522
- 'text',
523
- 20,
524
- __('The name is used to identify the group.', 'avh-ec')
525
- );
526
- $options_edit_group[] = array(
527
- 'avhec_edit_group[edit][slug]',
528
- __('Slug Group', 'avh-ec'),
529
- 'text',
530
- 20,
531
- __(
532
- 'The “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.',
533
- 'avh-ec'
534
- )
535
- );
536
- $options_edit_group[] = array(
537
- 'avhec_edit_group[edit][widget_title]',
538
- __('Widget Title', 'avh-ec'),
539
- 'text',
540
- 20,
541
- __(
542
- 'When no title is given in the widget options, this will used as the title of the widget when this group is shown.',
543
- 'avh-ec'
544
- )
545
- );
546
- $options_edit_group[] = array(
547
- 'avhec_edit_group[edit][description]',
548
- __('Description', 'avh-ec'),
549
- 'textarea',
550
- 40,
551
- __('Description is not prominent by default.', 'avh-ec'),
552
- 5
553
- );
554
- $options_edit_group[] = array(
555
- 'avhec_edit_group[edit][categories]',
556
- __('Categories', 'avh-ec'),
557
- 'catlist',
558
- 0,
559
- __('Select categories to be included in the group.', 'avh-ec')
560
- );
561
-
562
- if (isset($_POST['addgroup'])) {
563
- check_admin_referer('avh_ec_addgroup');
564
-
565
- $formoptions = $_POST['avhec_add_group'];
566
-
567
- $data_add_group_new['name'] = $formoptions['add']['name'];
568
- $data_add_group_new['slug'] = empty($formoptions['add']['slug']) ? sanitize_title(
569
- $data_add_group_new['name']
570
- ) : sanitize_title($formoptions['add']['slug']);
571
- $data_add_group_new['widget_title'] = $formoptions['add']['widget_title'];
572
- $data_add_group_new['description'] = $formoptions['add']['description'];
573
-
574
- $id = $this->catgrp->getTermIDBy('slug', $data_add_group_new['slug']);
575
- if (!$id) {
576
- $group_id = $this->catgrp->doInsertGroup(
577
- $data_add_group_new['name'],
578
- array(
579
- 'description' => $data_add_group_new['description'],
580
- 'slug' => $data_add_group_new['slug']
581
- ),
582
- $data_add_group_new['widget_title']
583
- );
584
- $this->catgrp->setCategoriesForGroup($group_id);
585
- $this->message = __('Category group saved', 'avh-ec');
586
- $this->status = 'updated fade';
587
- $data_add_group_new = $data_add_group_default;
588
- } else {
589
- $group = $this->catgrp->getGroup($id);
590
- $this->message = __('Category group conflicts with ', 'avh-ec') . $group->name;
591
- $this->message .= '<br />' . __('Same slug is used. ', 'avh-ec');
592
- $this->status = 'error';
593
- }
594
- $this->displayMessage();
595
- }
596
- $data_add_group['add'] = $data_add_group_new;
597
- $data['add'] = array('form' => $options_add_group, 'data' => $data_add_group);
598
-
599
- if (isset($_GET['action'])) {
600
- $action = $_GET['action'];
601
-
602
- switch ($action) {
603
- case 'edit':
604
- $group_id = (int) $_GET['group_ID'];
605
- $group = $this->catgrp->getGroup($group_id);
606
- $widget_title = $this->catgrp->getWidgetTitleForGroup($group_id);
607
- $cats = $this->catgrp->getCategoriesFromGroup($group_id);
608
-
609
- $data_edit_group['edit'] = array(
610
- 'group_id' => $group_id,
611
- 'name' => $group->name,
612
- 'slug' => $group->slug,
613
- 'widget_title' => $widget_title,
614
- 'description' => $group->description,
615
- 'categories' => $cats
616
- );
617
- $data['edit'] = array('form' => $options_edit_group, 'data' => $data_edit_group);
618
-
619
- add_meta_box(
620
- 'avhecBoxCategoryGroupEdit',
621
- __('Edit Group', 'avh-ec') . ': ' . $group->name,
622
- array($this, 'metaboxCategoryGroupEdit'),
623
- $this->hooks['menu_category_groups'],
624
- 'normal',
625
- 'low'
626
- );
627
- break;
628
- case 'delete':
629
- if (!isset($_GET['group_ID'])) {
630
- wp_redirect($this->getBackLink());
631
- exit();
632
- }
633
-
634
- $group_id = (int) $_GET['group_ID'];
635
- check_admin_referer('delete-avhecgroup_' . $group_id);
636
-
637
- if (!current_user_can('manage_categories')) {
638
- wp_die(__('Cheatin&#8217; uh?'));
639
- }
640
- $this->catgrp->doDeleteGroup($group_id);
641
- break;
642
- default:
643
- ;
644
- break;
645
- }
646
- }
647
-
648
- if (isset($_POST['editgroup'])) {
649
- check_admin_referer('avh_ec_editgroup');
650
-
651
- $formoptions = $_POST['avhec_edit_group'];
652
- $selected_categories = $_POST['post_category'];
653
-
654
- $group_id = (int) $_POST['avhec-group_id'];
655
- $result = $this->catgrp->doUpdateGroup(
656
- $group_id,
657
- array(
658
- 'name' => $formoptions['edit']['name'],
659
- 'slug' => $formoptions['edit']['slug'],
660
- 'description' => $formoptions['edit']['description']
661
- ),
662
- $selected_categories,
663
- $formoptions['edit']['widget_title']
664
- );
665
- switch ($result) {
666
- case 1:
667
- $this->message = __('Category group updated', 'avh-ec');
668
- $this->status = 'updated fade';
669
- break;
670
- case 0:
671
- $this->message = __('Category group not updated', 'avh-ec');
672
- $this->message .= '<br />' . __('Duplicate slug detected', 'avh-ec');
673
- $this->status = 'error';
674
- break;
675
- case -1:
676
- $this->message = __('Unknown category group', 'avh-ec');
677
- $this->status = 'error';
678
- break;
679
- }
680
- $this->displayMessage();
681
- }
682
-
683
- $hide2 = '';
684
- switch ($screen_layout_columns) {
685
- case 2:
686
- $width = 'width:49%;';
687
- break;
688
- default:
689
- $width = 'width:98%;';
690
- $hide2 = 'display:none;';
691
- }
692
-
693
- $data_special_pages_old = $this->core->options['sp_cat_group'];
694
- $data_special_pages_new = $data_special_pages_old;
695
- if (isset($_POST['avhec_special_pages'])) {
696
- check_admin_referer('avh_ec_specialpagesgroup');
697
-
698
- $formoptions = $_POST['avhec_special_pages'];
699
- $formdata = $formoptions['sp'];
700
- foreach ($formdata as $key => $value) {
701
- $data_special_pages_new[$key] = $value;
702
- }
703
- $this->core->options['sp_cat_group'] = $data_special_pages_new;
704
- $this->core->saveOptions($this->core->options);
705
- }
706
- $data_special_pages['sp'] = $data_special_pages_new;
707
- $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false));
708
-
709
- foreach ($cat_groups as $group) {
710
- $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit');
711
- $dropdown_value[] = $group->term_id;
712
- $dropdown_text[] = $temp_cat->name;
713
- }
714
- $options_special_pages[] = array(
715
- 'avhec_special_pages[sp][home_group]',
716
- __('Home page', 'avh-ec'),
717
- 'dropdown',
718
- $dropdown_value,
719
- $dropdown_text,
720
- sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('home', 'avhec'))
721
- );
722
- // $options_special_pages[] = array('avhec_special_pages[sp][category_group]', __('Category Archive', 'avh-ec'), 'dropdown', $dropdown_value, $dropdown_text, sprintf(__('Select which category to show on the %s page.','avh-ec'),__('category archive','avhec')));
723
- $options_special_pages[] = array(
724
- 'avhec_special_pages[sp][day_group]',
725
- __('Daily Archive', 'avh-ec'),
726
- 'dropdown',
727
- $dropdown_value,
728
- $dropdown_text,
729
- sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('daily archive', 'avhec'))
730
- );
731
- $options_special_pages[] = array(
732
- 'avhec_special_pages[sp][month_group]',
733
- __('Monthly Archive', 'avh-ec'),
734
- 'dropdown',
735
- $dropdown_value,
736
- $dropdown_text,
737
- sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('monthly archive', 'avhec'))
738
- );
739
- $options_special_pages[] = array(
740
- 'avhec_special_pages[sp][year_group]',
741
- __('Yearly Archive', 'avh-ec'),
742
- 'dropdown',
743
- $dropdown_value,
744
- $dropdown_text,
745
- sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('yearly archive', 'avhec'))
746
- );
747
- $options_special_pages[] = array(
748
- 'avhec_special_pages[sp][author_group]',
749
- __('Author Archive', 'avh-ec'),
750
- 'dropdown',
751
- $dropdown_value,
752
- $dropdown_text,
753
- sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('author archive', 'avhec'))
754
- );
755
- $options_special_pages[] = array(
756
- 'avhec_special_pages[sp][search_group]',
757
- __('Search Page', 'avh-ec'),
758
- 'dropdown',
759
- $dropdown_value,
760
- $dropdown_text,
761
- sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('search', 'avhec'))
762
- );
763
-
764
- $data['sp'] = array('form' => $options_special_pages, 'data' => $data_special_pages);
765
-
766
- // This box can't be unselectd in the the Screen Options
767
- // add_meta_box( 'avhecBoxDonations', __( 'Donations', 'avh-ec' ), array ($this, 'metaboxDonations' ), $this->hooks['menu_category_groups'], 'side', 'core' );
768
-
769
- echo '<div class="wrap avhec-metabox-wrap">';
770
- echo $this->displayIcon('index');
771
- echo '<h2>' . 'AVH Extended Categories - ' . __('Category Groups', 'avh-ec') . '</h2>';
772
-
773
- echo ' <div id="dashboard-widgets-wrap">';
774
- echo ' <div id="dashboard-widgets" class="metabox-holder">';
775
-
776
- echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
777
- do_meta_boxes($this->hooks['menu_category_groups'], 'normal', $data);
778
- echo " </div>";
779
-
780
- echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n";
781
- do_meta_boxes($this->hooks['menu_category_groups'], 'side', $data);
782
- echo ' </div>';
783
-
784
- echo ' </div>'; // dashboard-widgets
785
- echo '<br class="clear" />';
786
- echo ' </div>'; // dashboard-widgets-wrap
787
- echo '</div>'; // wrap
788
-
789
- $this->printMetaboxGeneralNonces();
790
- $this->printMetaboxJS('grouped');
791
- $this->printAdminFooter();
792
- }
793
-
794
- /**
795
- * Menu Page FAQ
796
- *
797
- * @return none
798
- */
799
- public function doMenuFAQ()
800
- {
801
- global $screen_layout_columns;
802
-
803
- // This box can't be unselectd in the the Screen Options
804
- // add_meta_box('avhecBoxAnnouncements', __('Announcements', 'avh-ec'), array ( $this, 'metaboxAnnouncements' ), $this->hooks['menu_faq'], 'side', 'core');
805
- add_meta_box(
806
- 'avhecBoxDonations',
807
- __('Donations', 'avh-ec'),
808
- array($this, 'metaboxDonations'),
809
- $this->hooks['menu_faq'],
810
- 'side',
811
- 'core'
812
- );
813
-
814
- $hide2 = '';
815
- switch ($screen_layout_columns) {
816
- case 2:
817
- $width = 'width:49%;';
818
- break;
819
- default:
820
- $width = 'width:98%;';
821
- $hide2 = 'display:none;';
822
- }
823
-
824
- echo '<div class="wrap avhec-metabox-wrap">';
825
- echo $this->displayIcon('index');
826
- echo '<h2>' . 'AVH Extended Categories - ' . __('F.A.Q', 'avh-ec') . '</h2>';
827
- echo ' <div id="dashboard-widgets-wrap">';
828
- echo ' <div id="dashboard-widgets" class="metabox-holder">';
829
- echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
830
- do_meta_boxes($this->hooks['menu_faq'], 'normal', '');
831
- echo ' </div>';
832
- echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n";
833
- do_meta_boxes($this->hooks['menu_faq'], 'side', '');
834
- echo ' </div>';
835
- echo ' </div>';
836
- echo '<br class="clear"/>';
837
- echo ' </div>'; // dashboard-widgets-wrap
838
- echo '</div>'; // wrap
839
-
840
- $this->printMetaboxGeneralNonces();
841
- $this->printMetaboxJS('faq');
842
- $this->printAdminFooter();
843
- }
844
-
845
- /**
846
- * Menu Page General Options
847
- *
848
- * @return void
849
- */
850
- public function doMenuGeneral()
851
- {
852
- global $screen_layout_columns;
853
-
854
- $groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false));
855
- foreach ($groups as $group) {
856
- $group_id[] = $group->term_id;
857
- $groupname[] = $group->name;
858
- }
859
-
860
- $options_general[] = array(
861
- 'avhec[general][alternative_name_select_category]',
862
- __('<em>Select Category</em> Alternative', 'avh-ec'),
863
- 'text',
864
- 20,
865
- __('Alternative text for Select Category.', 'avh-ec')
866
- );
867
- $options_general[] = array(
868
- 'avhec[cat_group][home_group]',
869
- 'Home Group',
870
- 'dropdown',
871
- $group_id,
872
- $groupname,
873
- __('Select which group to show on the home page.', 'avh-ec') .
874
- '<br />' .
875
- __('Selecting the group \'none\' will not show the widget on the page.', 'avh-ec')
876
- );
877
- $options_general[] = array(
878
- 'avhec[cat_group][no_group]',
879
- 'Nonexistence Group',
880
- 'dropdown',
881
- $group_id,
882
- $groupname,
883
- __('Select which group to show when there is no group associated with the post.', 'avh-ec') .
884
- '<br />' .
885
- __('Selecting the group \'none\' will not show the widget on the page.', 'avh-ec')
886
- );
887
- $options_general[] = array(
888
- 'avhec[cat_group][default_group]',
889
- 'Default Group',
890
- 'dropdown',
891
- $group_id,
892
- $groupname,
893
- __('Select which group will be the default group when editing a post.', 'avh-ec') .
894
- '<br />' .
895
- __('Selecting the group \'none\' will not show the widget on the page.', 'avh-ec')
896
- );
897
-
898
- if (isset($_POST['updateoptions'])) {
899
- check_admin_referer('avh_ec_generaloptions');
900
-
901
- $formoptions = $_POST['avhec'];
902
- $options = $this->core->getOptions();
903
-
904
- // $all_data = array_merge( $options_general );
905
- $all_data = $options_general;
906
- foreach ($all_data as $option) {
907
- $section = substr($option[0], strpos($option[0], '[') + 1);
908
- $section = substr($section, 0, strpos($section, ']['));
909
- $option_key = rtrim($option[0], ']');
910
- $option_key = substr($option_key, strpos($option_key, '][') + 2);
911
-
912
- switch ($section) {
913
- case 'general':
914
- case 'cat_group':
915
- $current_value = $options[$section][$option_key];
916
- break;
917
- }
918
- // Every field in a form is set except unchecked checkboxes. Set an unchecked checkbox to 0.
919
- $newval = (isset($formoptions[$section][$option_key]) ? esc_attr(
920
- $formoptions[$section][$option_key]
921
- ) : 0);
922
- if ($newval != $current_value) { // Only process changed fields.
923
- switch ($section) {
924
- case 'general':
925
- case 'cat_group':
926
- $options[$section][$option_key] = $newval;
927
- break;
928
- }
929
- }
930
- }
931
- $this->core->saveOptions($options);
932
- $this->message = __('Options saved', 'avh-ec');
933
- $this->status = 'updated fade';
934
- }
935
- $this->displayMessage();
936
-
937
- $actual_options = $this->core->getOptions();
938
- foreach ($actual_options['cat_group'] as $key => $value) {
939
- if (!(in_array($value, (array) $group_id))) {
940
- $actual_options['cat_group'][$key] = $this->catgrp->getTermIDBy('slug', 'none');
941
- }
942
- }
943
-
944
- $hide2 = '';
945
- switch ($screen_layout_columns) {
946
- case 2:
947
- $width = 'width:49%;';
948
- break;
949
- default:
950
- $width = 'width:98%;';
951
- $hide2 = 'display:none;';
952
- }
953
- $data['options_general'] = $options_general;
954
- $data['actual_options'] = $actual_options;
955
-
956
- // This box can't be unselectd in the the Screen Options
957
- add_meta_box(
958
- 'avhecBoxDonations',
959
- __('Donations', 'avh-ec'),
960
- array($this, 'metaboxDonations'),
961
- $this->hooks['menu_general'],
962
- 'side',
963
- 'core'
964
- );
965
-
966
- $hide2 = '';
967
- switch ($screen_layout_columns) {
968
- case 2:
969
- $width = 'width:49%;';
970
- break;
971
- default:
972
- $width = 'width:98%;';
973
- $hide2 = 'display:none;';
974
- }
975
-
976
- echo '<div class="wrap avhec-metabox-wrap">';
977
- echo $this->displayIcon('index');
978
- echo '<h2>' . 'AVH Extended Categories - ' . __('General Options', 'avh-ec') . '</h2>';
979
- echo '<form name="avhec-generaloptions" id="avhec-generaloptions" method="POST" action="' .
980
- admin_url('admin.php?page=avhec-general') .
981
- '" accept-charset="utf-8" >';
982
- wp_nonce_field('avh_ec_generaloptions');
983
-
984
- echo ' <div id="dashboard-widgets-wrap">';
985
- echo ' <div id="dashboard-widgets" class="metabox-holder">';
986
- echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
987
- do_meta_boxes($this->hooks['menu_general'], 'normal', $data);
988
- echo " </div>";
989
- echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n";
990
- do_meta_boxes($this->hooks['menu_general'], 'side', $data);
991
- echo ' </div>';
992
- echo ' </div>';
993
-
994
- echo '<br class="clear"/>';
995
- echo ' </div>'; // dashboard-widgets-wrap
996
- echo '<p class="submit"><input class="button" type="submit" name="updateoptions" value="' .
997
- __('Save Changes', 'avhf-ec') .
998
- '" /></p>';
999
- echo '</form>';
1000
-
1001
- echo '</div>'; // wrap
1002
-
1003
- $this->printMetaboxGeneralNonces();
1004
- $this->printMetaboxJS('general');
1005
- $this->printAdminFooter();
1006
- }
1007
-
1008
- /**
1009
- * Menu Page Manual Order
1010
- *
1011
- * @return void
1012
- */
1013
- public function doMenuManualOrder()
1014
- {
1015
- global $screen_layout_columns;
1016
-
1017
- $hide2 = '';
1018
- switch ($screen_layout_columns) {
1019
- case 2:
1020
- $width = 'width:49%;';
1021
- break;
1022
- default:
1023
- $width = 'width:98%;';
1024
- $hide2 = 'display:none;';
1025
- }
1026
-
1027
- echo '<div class="wrap">';
1028
- echo $this->displayIcon('index');
1029
- echo '<h2>' . 'AVH Extended Categories - ' . __('Manually Order Categories', 'avh-ec') . '</h2>';
1030
-
1031
- echo '<div class="metabox-holder">';
1032
- echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
1033
- do_meta_boxes($this->hooks['menu_manual_order'], 'normal', '');
1034
- echo ' </div>';
1035
- echo '</div>';
1036
- echo '</div>'; // wrap
1037
- echo '<div class="clear"></div>';
1038
-
1039
- $this->printMetaboxGeneralNonces();
1040
- $this->printMetaboxJS('manual_order');
1041
- $this->printAdminFooter();
1042
- }
1043
-
1044
- /**
1045
- * Menu Page Overview
1046
- *
1047
- * @return void
1048
- */
1049
- public function doMenuOverview()
1050
- {
1051
- global $screen_layout_columns;
1052
-
1053
- // This box can't be unselectd in the the Screen Options
1054
- // add_meta_box('avhecBoxAnnouncements', __('Announcements', 'avh-ec'), array ( $this, 'metaboxAnnouncements' ), $this->hooks['menu_overview'], 'side', '');
1055
- add_meta_box(
1056
- 'avhecBoxDonations',
1057
- __('Donations', 'avh-ec'),
1058
- array($this, 'metaboxDonations'),
1059
- $this->hooks['menu_overview'],
1060
- 'side',
1061
- ''
1062
- );
1063
-
1064
- $hide2 = '';
1065
- switch ($screen_layout_columns) {
1066
- case 2:
1067
- $width = 'width:49%;';
1068
- break;
1069
- default:
1070
- $width = 'width:98%;';
1071
- $hide2 = 'display:none;';
1072
- }
1073
-
1074
- echo '<div class="wrap avhec-metabox-wrap">';
1075
- echo $this->displayIcon('index');
1076
- echo '<h2>' . 'AVH Extended Categories - ' . __('Overview', 'avh-ec') . '</h2>';
1077
- echo ' <div id="dashboard-widgets-wrap">';
1078
- echo ' <div id="dashboard-widgets" class="metabox-holder">';
1079
- echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
1080
- do_meta_boxes($this->hooks['menu_overview'], 'normal', '');
1081
- echo " </div>";
1082
- echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n";
1083
- do_meta_boxes($this->hooks['menu_overview'], 'side', '');
1084
- echo ' </div>';
1085
- echo ' </div>';
1086
-
1087
- echo '<br class="clear"/>';
1088
- echo ' </div>'; // dashboard-widgets-wrap
1089
- echo '</div>'; // wrap
1090
-
1091
- $this->printMetaboxGeneralNonces();
1092
- $this->printMetaboxJS('overview');
1093
- $this->printAdminFooter();
1094
- }
1095
-
1096
- /**
1097
- * When not using AJAX, this function is called when the deletion fails.
1098
- *
1099
- * @param string $text
1100
- * @param int $group_id
1101
- *
1102
- * @return string
1103
- * @WordPress Filter explain_nonce_$verb-$noun
1104
- * @see wp_explain_nonce
1105
- */
1106
- public function filterExplainNonceDeleteGroup($text, $group_id)
1107
- {
1108
- $group = get_term($group_id, $this->catgrp->taxonomy_name, OBJECT, 'display');
1109
-
1110
- $return = sprintf(__('Your attempt to delete this group: &#8220;%s&#8221; has failed.'), $group->name);
1111
-
1112
- return ($return);
1113
- }
1114
-
1115
- /**
1116
- * Creates a new array for columns headers.
1117
- * Used in print_column_headers. The filter is called from get_column_headers
1118
- *
1119
- * @param array $columns
1120
- *
1121
- * @return Array
1122
- * @see print_column_headers, get_column_headers
1123
- */
1124
- public function filterManageCategoriesGroupColumns($columns)
1125
- {
1126
- $categories_group_columns = array(
1127
- 'name' => __('Name', 'avh-ec'),
1128
- 'slug' => __('Slug', 'avh-ec'),
1129
- 'widget-title' => __('Widget Title', 'avh-ec'),
1130
- 'description' => __('Description', 'avh-ec'),
1131
- 'cat-in-group' => __('Categories in the group', 'avh-ec')
1132
- );
1133
-
1134
- return $categories_group_columns;
1135
- }
1136
-
1137
- /**
1138
- * Adds Settings next to the plugin actions
1139
- *
1140
- * @WordPress Filter plugin_action_links_avh-amazon/avh-amazon.php
1141
- *
1142
- * @param array $links
1143
- * @param string $file
1144
- *
1145
- * @return array
1146
- */
1147
- public function filterPluginActions($links, $file)
1148
- {
1149
- $settings_link = '<a href="admin.php?page=extended-categories-widget">' . __('Settings', 'avh-ec') . '</a>';
1150
- array_unshift($links, $settings_link); // before other links
1151
-
1152
- return $links;
1153
- }
1154
-
1155
- /**
1156
- * Sets the amount of columns wanted for a particular screen
1157
- *
1158
- * @WordPress filter screen_meta_screen
1159
- *
1160
- * @param array $columns
1161
- * @param string $screen
1162
- *
1163
- * @return array
1164
- */
1165
- public function filterScreenLayoutColumns($columns, $screen)
1166
- {
1167
- switch ($screen) {
1168
- case $this->hooks['menu_overview']:
1169
- $columns[$this->hooks['menu_overview']] = 2;
1170
- break;
1171
- case $this->hooks['menu_general']:
1172
- $columns[$this->hooks['menu_general']] = 2;
1173
- break;
1174
- case $this->hooks['menu_category_groups']:
1175
- $columns[$this->hooks['menu_category_groups']] = 2;
1176
- break;
1177
- case $this->hooks['menu_faq']:
1178
- $columns[$this->hooks['menu_faq']] = 2;
1179
- break;
1180
- }
1181
-
1182
- return $columns;
1183
- }
1184
-
1185
- /**
1186
- * Get the backlink for forms
1187
- *
1188
- * @return string
1189
- */
1190
- public function getBackLink()
1191
- {
1192
- $page = basename(__FILE__);
1193
- if (isset($_GET['page']) && !empty($_GET['page'])) {
1194
- $page = preg_replace('[^a-zA-Z0-9\.\_\-]', '', $_GET['page']);
1195
- }
1196
-
1197
- if (function_exists("admin_url")) {
1198
- return admin_url(basename($_SERVER["PHP_SELF"])) . "?page=" . $page;
1199
- } else {
1200
- return $_SERVER['PHP_SELF'] . "?page=" . $page;
1201
- }
1202
- }
1203
-
1204
- /**
1205
- * Saves the association Category - Category Group fron the edit taxonomy page
1206
- *
1207
- * @WordPress action edit_form.
1208
- *
1209
- * @param int $term_id
1210
- * @param int $tt_id
1211
- * @param string $taxonomy
1212
- */
1213
- public function handleEditTerm($term_id, $tt_id, $taxonomy)
1214
- {
1215
- $tax_meta = get_option($this->core->db_options_tax_meta);
1216
- if (isset($_POST['avhec_categorygroup'])) {
1217
- if (!isset($tax_meta[$taxonomy][$term_id]['category_group_term_id']) ||
1218
- $tax_meta[$taxonomy][$term_id]['category_group_term_id'] != $_POST['avhec_categorygroup']
1219
- ) {
1220
- $tax_meta[$taxonomy][$term_id]['category_group_term_id'] = $_POST['avhec_categorygroup'];
1221
- update_option($this->core->db_options_tax_meta, $tax_meta);
1222
- }
1223
- }
1224
- }
1225
-
1226
- /**
1227
- * Used in forms to set an option checked
1228
- *
1229
- * @param string $checked
1230
- * @param string $current
1231
- *
1232
- * @return strings
1233
- */
1234
- public function isChecked($checked, $current)
1235
- {
1236
- $return = '';
1237
- if ($checked == $current) {
1238
- $return = ' checked="checked"';
1239
- }
1240
-
1241
- return $return;
1242
- }
1243
-
1244
- public function metaboxAnnouncements()
1245
- {
1246
- $php5 = version_compare('5.2', phpversion(), '<');
1247
- echo '<div class="p">';
1248
- echo '<span class="b">' . __('PHP4 Support', 'avh-ec') . '</span><br />';
1249
- echo __('The next major release of the plugin will no longer support PHP4.', 'avh-ec') . '<br />';
1250
- echo __('It will be written for PHP 5.2 and ', 'avh-ec');
1251
- if ($php5) {
1252
- echo __(
1253
- 'your blog already runs the needed PHP version. When the new release comes out you can safely update.',
1254
- 'avh-ec'
1255
- ) . '<br />';
1256
- } else {
1257
- echo __('your blog still runs PHP4. When the new release comes out you can not use it.', 'avh-ec') .
1258
- '<br />';
1259
- echo __(
1260
- 'I don\'t have a timeline for the next version but consider contacting your host if PHP 5.2 is available.',
1261
- 'avh-ec'
1262
- ) . '<br />';
1263
- echo __('If your hosts doesn\'t offer PHP 5.2 you might want to consider switching hosts.', 'avh-ec') .
1264
- '<br />';
1265
- echo __('A host to consider is ', 'avh-ec') .
1266
- '<a href="http://www.lunarpages.com/id/pdoes" target="_blank">Lunarpages</a>';
1267
- echo __(
1268
- 'I run my personal blog there and I am very happy with their services. You can get an account with unlimited bandwidth, storage and much more for a low price.',
1269
- 'avh-ec'
1270
- );
1271
- }
1272
- echo '</div>';
1273
- }
1274
-
1275
- /**
1276
- * Metabox for Adding a group
1277
- *
1278
- * @param array $data
1279
- */
1280
- public function metaboxCategoryGroupAdd($data)
1281
- {
1282
- echo '<form name="avhec-addgroup" id="avhec-addgroup" method="POST" action="' .
1283
- $this->getBackLink() .
1284
- '" accept-charset="utf-8" >';
1285
- wp_nonce_field('avh_ec_addgroup');
1286
- echo $this->printOptions($data['add']['form'], $data['add']['data']);
1287
- echo '<p class="submit"><input class="button" type="submit" name="addgroup" value="' .
1288
- __('Add group', 'avh-ec') .
1289
- '" /></p>';
1290
- echo '</form>';
1291
- }
1292
-
1293
- /**
1294
- * Metabox Category Group Edit
1295
- *
1296
- * @param array $data
1297
- */
1298
- public function metaboxCategoryGroupEdit($data)
1299
- {
1300
- echo '<form name="avhec-editgroup" id="avhec-editgroup" method="POST" action="' .
1301
- $this->getBackLink() .
1302
- '" accept-charset="utf-8" >';
1303
- wp_nonce_field('avh_ec_editgroup');
1304
- echo $this->printOptions($data['edit']['form'], $data['edit']['data']);
1305
- echo '<input type="hidden" value="' .
1306
- $data['edit']['data']['edit']['group_id'] .
1307
- '" name="avhec-group_id" id="avhec-group_id">';
1308
- echo '<p class="submit"><input class="button" type="submit" name="editgroup" value="' .
1309
- __('Update group', 'avh-ec') .
1310
- '" /></p>';
1311
- echo '</form>';
1312
- }
1313
-
1314
- /**
1315
- * Metabox for showing the groups as a list
1316
- *
1317
- * @param array $data
1318
- */
1319
- public function metaboxCategoryGroupList($data)
1320
- {
1321
- echo '<form id="posts-filter" action="" method="get">';
1322
-
1323
- echo '<div class="clear"></div>';
1324
-
1325
- echo '<table class="widefat fixed" cellspacing="0">';
1326
- echo '<thead>';
1327
- echo '<tr>';
1328
- print_column_headers('categories_group');
1329
- echo '</tr>';
1330
- echo '</thead>';
1331
-
1332
- echo '<tfoot>';
1333
- echo '<tr>';
1334
- print_column_headers('categories_group', false);
1335
- echo '</tr>';
1336
- echo '</tfoot>';
1337
-
1338
- echo '<tbody id="the-list" class="list:group">';
1339
- $this->printCategoryGroupRows();
1340
- echo '</tbody>';
1341
- echo '</table>';
1342
-
1343
- echo '<br class="clear" />';
1344
- echo '</form>';
1345
- // echo '</div>';
1346
- }
1347
-
1348
- /**
1349
- * Metabox Category Group Special pages
1350
- *
1351
- * @param array $data
1352
- */
1353
- public function metaboxCategoryGroupSpecialPages($data)
1354
- {
1355
- echo '<form name="avhec-specialpagesgroup" id="avhec-specialpagesgroup" method="POST" action="' .
1356
- $this->getBackLink() .
1357
- '" accept-charset="utf-8" >';
1358
- wp_nonce_field('avh_ec_specialpagesgroup');
1359
- echo $this->printOptions($data['sp']['form'], $data['sp']['data']);
1360
- echo '<p class="submit"><input class="button" type="submit" name="spgroup" value="' .
1361
- __('Save settings', 'avh-ec') .
1362
- '" /></p>';
1363
- echo '</form>';
1364
- }
1365
-
1366
- // ############ Admin WP Helper ##############
1367
-
1368
- /**
1369
- * Donation Metabox
1370
- */
1371
- public function metaboxDonations()
1372
- {
1373
- echo '<div class="p">';
1374
- echo __(
1375
- 'If you enjoy this plug-in please consider a donation. There are several ways you can show your appreciation.',
1376
- 'avh-ec'
1377
- );
1378
- echo '</div>';
1379
-
1380
- echo '<div class="p">';
1381
- echo '<span class="b">Amazon</span><br />';
1382
- echo __('If you decide to buy something from Amazon click the button.', 'avh-ec') . '</span><br />';
1383
- echo '<a href="https://www.amazon.com/?tag=avh-donation-20" target="_blank" title="Amazon Homepage"><img alt="Amazon Button" src="' .
1384
- $this->core->info['graphics_url'] .
1385
- '/us_banner_logow_120x60.gif" /></a>';
1386
- echo '</div>';
1387
-
1388
- echo '<div class="p">';
1389
- echo __('You can send me something from my ', 'avh-ec') .
1390
- '<a href="http://www.amazon.com/registry/wishlist/1U3DTWZ72PI7W?tag=avh-donation-20">' .
1391
- __('Amazon Wish List', 'avh-ec') .
1392
- '</a>';
1393
- echo '</div>';
1394
-
1395
- echo '<div class="p">';
1396
- echo '<span class="b">' . __('Through Paypal.', 'avh-ec') . '</span><br />';
1397
- echo __(
1398
- 'Click on the Donate button and you will be directed to Paypal where you can make your donation and you don\'t need to have a Paypal account to make a donation.',
1399
- 'avh-ec'
1400
- ) . '<br />';
1401
- echo '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=S85FXJ9EBHAF2&lc=US&item_name=AVH%20Plugins&item_number=fdas&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted" target="_blank" title="Donate">';
1402
- echo '<img src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" alt="Donate"/></a>';
1403
- echo '</div>';
1404
- }
1405
-
1406
- /**
1407
- * *
1408
- * F.A.Q Metabox
1409
-
1410
- */
1411
- public function metaboxFAQ()
1412
- {
1413
- echo '<div class="p">';
1414
- echo '<span class="b">' . __('What about support?', 'avh-ec') . '</span><br />';
1415
- echo __(
1416
- 'I created a <a href="http://forums.avirtualhome.com" target="_blank">support site</a> where you can ask questions or request features.',
1417
- 'avh-ec'
1418
- ) . '<br />';
1419
- echo '</div>';
1420
-
1421
- echo '<div class="p">';
1422
- echo '<span class="b">' . __('What is depth selection?', 'avh-ec') . '</span><br />';
1423
- echo __(
1424
- 'Starting with version 2.0 and WordPress 2.8 you can select how many levels deep you want to show your categories. This option only works when you select Show Hierarchy as well.',
1425
- 'avh-ec'
1426
- ) . '<br /><br />';
1427
- echo __(
1428
- 'Here is how it works: Say you have 5 top level categories and each top level has a number of children. You could manually select all the Top Level categories you want to show but now you can do the following:',
1429
- 'avh-ec'
1430
- ) . '<br />';
1431
- echo __(
1432
- 'You select to display all categories, select to Show hierarchy and select how many levels you want to show, in this case Toplevel only.',
1433
- 'avh-ec'
1434
- ) . '<br />';
1435
- echo '</div>';
1436
-
1437
- echo '<div class="p">';
1438
- echo '<span class="b">' . __('Multiple Category Groups', 'avh-ec') . '</span><br />';
1439
- echo __('The following is an explanation how assigning multiple groups to page/post works.', 'avh-ec') .
1440
- '<br /><br />';
1441
- echo __('Lets say you have the following groups:', 'avh-ec');
1442
- echo '<ul>';
1443
- echo '<li>' . __('Free Time', 'avh-ec') . '</li>';
1444
- echo '<li>' . __('Theater', 'avh-ec') . '</li>';
1445
- echo '<li>' . __('Movie', 'avh-ec') . '</li>';
1446
- echo '<li>' . __('Music', 'avh-ec') . '</li>';
1447
- echo '</ul>';
1448
- echo __('Setup several Category Group widgets and associated each widget with one or more groups.', 'avh-ec') .
1449
- '<br />';
1450
- echo __('Widget 1 has association with Free Time', 'avh-ec') . '<br />';
1451
- echo __('Widget 2 has association with Theater, Movie and Music', 'avh-ec') . '<br />';
1452
- echo __('Widget 3 has association with Theater, Movie and Music', 'avh-ec') . '<br /><br />';
1453
- echo __('Page has associations the groups Free Time and Theater', 'avh-ec');
1454
- echo '<ul>';
1455
- echo '<li>' . __('Widget 1: Shows categories of the Free Time group', 'avh-ec') . '</li>';
1456
- echo '<li>' . __('Widget 2: Shows categories of the Theater group.', 'avh-ec') . '</li>';
1457
- echo '<li>' . __('Widget 3: Not displayed', 'avh-ec') . '</li>';
1458
- echo '</ul>';
1459
- echo __('Page has associations the group Movie.', 'avh-ec');
1460
- echo '<ul>';
1461
- echo '<li>' . __('Widget 1: Not displayed', 'avh-ec') . '</li>';
1462
- echo '<li>' . __('Widget 2: Shows categories of the Movie group.', 'avh-ec') . '</li>';
1463
- echo '<li>' . __('Widget 3: Not displayed', 'avh-ec') . '</li>';
1464
- echo '</ul>';
1465
- echo __('Page has associations the groups Free Time, Movie and Music', 'avh-ec');
1466
- echo '<ul>';
1467
- echo '<li>' . __('Widget 1: Shows categories of the Free Time group', 'avh-ec') . '</li>';
1468
- echo '<li>' . __('Widget 2: Shows categories of the Movie or Music group.', 'avh-ec') . '</li>';
1469
- echo '<li>' . __('Widget 3: Shows categories of the Music or Movie group.', 'avh-ec') . '</li>';
1470
- echo '</ul>';
1471
- echo __(
1472
- 'Whether Widget 2 shows Movie or Music depends on the creation order of groups. If Widget 2 shows Movie, Widget 3 will show Music but if Widget 2 shows Music, Widget 3 will show Movie.',
1473
- 'avh-ec'
1474
- ) . '<br />';
1475
- echo '</div>';
1476
- }
1477
-
1478
- /**
1479
- * Displays the Manual Order metabox.
1480
- *
1481
- * @author Andrew Charlton - original
1482
- * @author Peter van der Does - modifications
1483
- */
1484
- public function metaboxManualOrder()
1485
- {
1486
- global $wpdb;
1487
-
1488
- $parentID = 0;
1489
-
1490
- if (isset($_POST['btnSubCats'])) {
1491
- $parentID = $_POST['cats'];
1492
- } elseif (isset($_POST['hdnParentID'])) {
1493
- $parentID = $_POST['hdnParentID'];
1494
- }
1495
-
1496
- if (isset($_POST['btnReturnParent'])) {
1497
- $parentsParent = $wpdb->get_row(
1498
- $wpdb->prepare("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = %d", $_POST['hdnParentID']),
1499
- ARRAY_N
1500
- );
1501
- $parentID = $parentsParent[0];
1502
- }
1503
-
1504
- $success = "";
1505
- if (isset($_POST['btnOrderCats'])) {
1506
- if (isset($_POST['hdnManualOrder']) && $_POST['hdnManualOrder'] != "") {
1507
-
1508
- $manualOrder = $_POST['hdnManualOrder'];
1509
- $IDs = explode(",", $manualOrder);
1510
- $result = count($IDs);
1511
-
1512
- for ($i = 0; $i < $result; $i++) {
1513
- $str = str_replace("id_", "", $IDs[$i]);
1514
- $wpdb->query(
1515
- $wpdb->prepare("UPDATE $wpdb->terms SET avhec_term_order = %d WHERE term_id =%d", $i, $str)
1516
- );
1517
- }
1518
-
1519
- $success = '<div id="message" class="updated fade"><p>' .
1520
- __('Manual order of the categories successfully updated.', 'avh-ec') .
1521
- '</p></div>';
1522
- } else {
1523
- $success = '<div id="message" class="updated fade"><p>' .
1524
- __('An error occured, order has not been saved.', 'avh-ec') .
1525
- '</p></div>';
1526
- }
1527
- }
1528
-
1529
- $subCategories = "";
1530
- $results = $wpdb->get_results(
1531
- $wpdb->prepare(
1532
- "SELECT t.term_id, t.name FROM $wpdb->term_taxonomy tt, $wpdb->terms t, $wpdb->term_taxonomy tt2 WHERE tt.parent = %d AND tt.taxonomy = 'category' AND t.term_id = tt.term_id AND tt2.parent = tt.term_id GROUP BY t.term_id, t.name HAVING COUNT(*) > 0 ORDER BY t.avhec_term_order ASC",
1533
- $parentID
1534
- )
1535
- );
1536
- foreach ($results as $row) {
1537
- $subCategories .= "<option value='$row->term_id'>$row->name</option>";
1538
- }
1539
-
1540
- echo '<div class="wrap">';
1541
- echo '<form name="frmMyCatOrder" method="post" action="">';
1542
- echo $success;
1543
-
1544
- echo '<h4>';
1545
- _e('Order the categories', 'avh-ec');
1546
- if ($parentID == 0) {
1547
- echo ' at the Toplevel';
1548
- } else {
1549
- $categories = get_category_parents($parentID, false, ' » ');
1550
- echo ' in the category ' . trim($categories, ' » ');
1551
- }
1552
- echo '</h4>';
1553
- echo '<span class="description">';
1554
- _e('Order the categories on this level by dragging and dropping them into the desired order.', 'avh-ec');
1555
- echo '</span>';
1556
- echo '<ul id="avhecManualOrder">';
1557
- $results = $wpdb->get_results(
1558
- $wpdb->prepare(
1559
- "SELECT * FROM $wpdb->terms t inner join $wpdb->term_taxonomy tt on t.term_id = tt.term_id WHERE taxonomy = 'category' and parent = %d ORDER BY avhec_term_order ASC",
1560
- $parentID
1561
- )
1562
- );
1563
- foreach ($results as $row) {
1564
- echo "<li id='id_$row->term_id' class='lineitem menu-item-settings'>" . __($row->name) . "</li>";
1565
- }
1566
- echo '</ul>';
1567
- echo '<input type="submit" name="btnOrderCats" id="btnOrderCats" class="button-primary" value="' .
1568
- __('Save Order', 'avh-ec') .
1569
- '" onclick="javascript:orderCats(); return true;" />';
1570
-
1571
- if ($parentID != 0) {
1572
- echo "<input type='submit' class='button' id='btnReturnParent' name='btnReturnParent' value='" .
1573
- __('Return to parent category', 'avh-ec') .
1574
- "' />";
1575
- }
1576
-
1577
- echo '<strong id="updateText"></strong><br /><br />';
1578
- if ($subCategories != "") {
1579
-
1580
- echo '<h4>';
1581
- _e('Select Subcategory', 'avh-ec');
1582
- echo '</h4>';
1583
- echo '<select id="cats" name="cats">';
1584
- echo $subCategories;
1585
-
1586
- echo '</select><input type="submit" name="btnSubCats" class="button" id="btnSubCats" value="' .
1587
- __('Select', 'avh-ec') .
1588
- '" />';
1589
- echo '<span class="description">';
1590
- _e('Choose a category from the drop down to order the subcategories in that category.', 'avh-ec');
1591
- echo '</span>';
1592
- }
1593
-
1594
- echo '<input type="hidden" id="hdnManualOrder" name="hdnManualOrder" />';
1595
- echo '<input type="hidden" id="hdnParentID" name="hdnParentID" value="' . $parentID . '" /></form>';
1596
- echo '</div>';
1597
- }
1598
-
1599
- /**
1600
- * Options Metabox
1601
- *
1602
- * @param array $data
1603
- */
1604
- public function metaboxOptions($data)
1605
- {
1606
- echo $this->printOptions($data['options_general'], $data['actual_options']);
1607
- }
1608
-
1609
- /**
1610
- * Translation Metabox
1611
-
1612
- */
1613
- public function metaboxTranslation()
1614
- {
1615
- $locale = apply_filters('plugin_locale', get_locale(), 'avh-ec');
1616
- $available_locale['cs_CZ'] = array('Czech - Čeština', 0);
1617
- $available_locale['nl_NL'] = array('Dutch - Nederlands', 0);
1618
- $available_locale['de_DE'] = array('German - Deutsch', 0);
1619
- $available_locale['el'] = array('Greek - Čeština', 0);
1620
- $available_locale['id_ID'] = array('Indonesian - Bahasa Indonesia - Čeština', 0);
1621
- $available_locale['it_IT'] = array('Italian - Italiano', 1);
1622
- $available_locale['ru_RU'] = array('Russian Русский', 0);
1623
- $available_locale['es_ES'] = array('Spanish - Español', 0);
1624
- $available_locale['sv_SE'] = array('Swedish - Svenska', 0);
1625
- $available_locale['tr'] = array('Turkish - Türkçe', 0);
1626
-
1627
- echo '<div class="p">';
1628
- echo __(
1629
- 'This plugin is translated in several languages. Some of the languages might be incomplete. Please help to complete these translations or add a new language.',
1630
- 'avh-ec'
1631
- ) . '<br />';
1632
-
1633
- echo '</div>';
1634
-
1635
- echo '<div class="p">';
1636
- echo '<span class="b">' . __('Available Languages', 'avh-ec') . '</span>';
1637
- echo '<ul>';
1638
- foreach ($available_locale as $key => $value) {
1639
- echo '<li>';
1640
- $complete = ($value[1] == 1 ? 'Complete' : 'Incomplete');
1641
- echo $value[0] . ' (' . $key . ') - ' . $complete;
1642
- echo '</li>';
1643
- }
1644
- echo '</ul>';
1645
- echo '</div>';
1646
-
1647
- echo '<div class="p">';
1648
- if ('en_US' != $locale & (!array_key_exists($locale, $available_locale))) {
1649
- echo 'Currently the plugin is not available in your language (' .
1650
- $locale .
1651
- '). We\'re in the middle of changing the way you can help with translations. Keep an eye on the <a href="http:///blog.avirtualhome.com">website</a> for the announcement.';
1652
- } else {
1653
- echo 'We\'re in the middle of changing the way you can help with translations. Keep an eye on the <a href="http:///blog.avirtualhome.com">website</a> for the announcement.';
1654
- }
1655
- echo '</div>';
1656
- }
1657
-
1658
- /**
1659
- * Display plugin Copyright
1660
- */
1661
- public function printAdminFooter()
1662
- {
1663
- echo '<p class="footer_avhec">';
1664
- printf(
1665
- '&copy; Copyright %d <a href="http://blog.avirtualhome.com/" title="My Thoughts">Peter van der Does</a> | AVH Extended Categories Version %s',
1666
- date('Y'),
1667
- $this->core->version
1668
- );
1669
- echo '</p>';
1670
- }
1671
-
1672
- /**
1673
- * Displays all the information of a group in a row
1674
- * Adds inline link for delete and/or edit.
1675
- *
1676
- * @param int $group_term_id
1677
- * @param int $group_term_taxonomy_id
1678
- *
1679
- * @return string
1680
- */
1681
- public function printCategoryGroupRow($group_term_id, $group_term_taxonomy_id)
1682
- {
1683
- static $row_class = '';
1684
-
1685
- $group = get_term($group_term_id, $this->catgrp->taxonomy_name, OBJECT, 'display');
1686
-
1687
- $no_edit[$this->catgrp->getTermIDBy('slug', 'all')] = 0;
1688
- $no_delete[$this->catgrp->getTermIDBy('slug', 'all')] = 0;
1689
-
1690
- if (current_user_can('manage_categories')) {
1691
- $actions = array();
1692
- if (!array_key_exists($group->term_id, $no_edit)) {
1693
- $edit_link = "admin.php?page=avhec-grouped&amp;action=edit&amp;group_ID=$group->term_id";
1694
- $edit = "<a class='row-title' href='$edit_link' title='" .
1695
- esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $group->name)) .
1696
- "'>" .
1697
- esc_attr($group->name) .
1698
- '</a><br />';
1699
-
1700
- $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
1701
- } else {
1702
- $edit = esc_attr($group->name);
1703
- }
1704
- if (!(array_key_exists($group->term_id, $no_delete))) {
1705
- $actions['delete'] = "<a class='delete:the-list:group-$group->term_id submitdelete' href='" .
1706
- wp_nonce_url(
1707
- "admin.php?page=avhec-grouped&amp;action=delete&amp;group_ID=$group->term_id",
1708
- 'delete-avhecgroup_' . $group->term_id
1709
- ) .
1710
- "'>" .
1711
- __('Delete') .
1712
- "</a>";
1713
- }
1714
- $action_count = count($actions);
1715
- $i = 0;
1716
- $edit .= '<div class="row-actions">';
1717
- foreach ($actions as $action => $link) {
1718
- ++$i;
1719
- ($i == $action_count) ? $sep = '' : $sep = ' | ';
1720
- $edit .= "<span class='$action'>$link$sep</span>";
1721
- }
1722
- $edit .= '</div>';
1723
- } else {
1724
- $edit = $group->name;
1725
- }
1726
-
1727
- $row_class = 'alternate' == $row_class ? '' : 'alternate';
1728
- $qe_data = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit');
1729
-
1730
- $output = "<tr id='group-$group->term_id' class='iedit $row_class'>";
1731
-
1732
- $columns = get_column_headers('categories_group');
1733
- $hidden = get_hidden_columns('categories_group');
1734
- foreach ($columns as $column_name => $column_display_name) {
1735
- $class = 'class="' . $column_name . ' column-' . $column_name . '"';
1736
-
1737
- $style = '';
1738
- if (in_array($column_name, $hidden)) {
1739
- $style = ' style="display:none;"';
1740
- }
1741
-
1742
- $attributes = $class . $style;
1743
-
1744
- switch ($column_name) {
1745
- case 'cb':
1746
- $output .= '<th scope="row" class="check-column">';
1747
- if (!(array_key_exists($group->term_id, $no_delete))) {
1748
- $output .= '<input type="checkbox" name="delete[]" value="' . $group->term_id . '" />';
1749
- } else {
1750
- $output .= "&nbsp;";
1751
- }
1752
- $output .= '</th>';
1753
- break;
1754
- case 'name':
1755
- $output .= '<td ' . $attributes . '>' . $edit;
1756
- $output .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">';
1757
- $output .= '<div class="name">' . $qe_data->name . '</div>';
1758
- $output .= '<div class="slug">' . apply_filters('editable_slug', $qe_data->slug) . '</div>';
1759
- $output .= '</div></td>';
1760
- break;
1761
- case 'widget-title':
1762
- $title = $this->catgrp->getWidgetTitleForGroup($group->term_id);
1763
- if (!$title) {
1764
- $title = "&nbsp;";
1765
- }
1766
- $output .= '<td ' . $attributes . '>' . $title . '</td>';
1767
- break;
1768
-
1769
- case 'description':
1770
- $output .= '<td ' . $attributes . '>' . $qe_data->description . '</td>';
1771
- break;
1772
- case 'slug':
1773
- $output .= "<td $attributes>" . apply_filters('editable_slug', $qe_data->slug) . "</td>";
1774
- break;
1775
- case 'cat-in-group':
1776
- $cats = $this->catgrp->getCategoriesFromGroup($group_term_id);
1777
- $catname = array();
1778
- foreach ($cats as $cat_id) {
1779
- $catname[] = get_cat_name($cat_id);
1780
- }
1781
- natsort($catname);
1782
- $cat = implode(', ', $catname);
1783
- $output .= '<td ' . $attributes . '>' . $cat . '</td>';
1784
- break;
1785
- }
1786
- }
1787
- $output .= '</tr>';
1788
-
1789
- return $output;
1790
- }
1791
-
1792
- /**
1793
- * Print all Category Group rows
1794
- *
1795
- * @uses printCategoryGroupRow
1796
- */
1797
- public function printCategoryGroupRows()
1798
- {
1799
- $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false));
1800
-
1801
- foreach ($cat_groups as $group) {
1802
- if ('none' != $group->slug) {
1803
- echo $this->printCategoryGroupRow($group->term_id, $group->term_taxonomy_id);
1804
- }
1805
- }
1806
- }
1807
-
1808
- /**
1809
- * Prints the general nonces, used by the AJAX
1810
- */
1811
- public function printMetaboxGeneralNonces()
1812
- {
1813
- echo '<form style="display:none" method="get" action="">';
1814
- echo '<p>';
1815
- wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1816
- wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1817
- echo '</p>';
1818
- echo '</form>';
1819
- }
1820
-
1821
- /**
1822
- * Print the Metabox JS for toggling closed and open
1823
- *
1824
- * @param int $boxid
1825
- */
1826
- public function printMetaboxJS($boxid)
1827
- {
1828
- $a = $this->hooks['menu_' . $boxid];
1829
- echo '<script type="text/javascript">' . "\n";
1830
- echo ' //<![CDATA[' . "\n";
1831
- echo ' jQuery(document).ready( function($) {' . "\n";
1832
- echo ' $(\'.if-js-closed\').removeClass(\'if-js-closed\').addClass(\'closed\');' . "\n";
1833
- echo ' // postboxes setup' . "\n";
1834
- echo ' postboxes.add_postbox_toggles(\'' . $a . '\');' . "\n";
1835
- echo ' });' . "\n";
1836
- echo ' //]]>' . "\n";
1837
- echo '</script>';
1838
- }
1839
-
1840
- /**
1841
- * Ouput formatted options
1842
- *
1843
- * @param array $option_data
1844
- * @param array $option_actual
1845
- *
1846
- * @return string
1847
- */
1848
- public function printOptions($option_data, $option_actual)
1849
- {
1850
- // Generate output
1851
- $output = '';
1852
- $output .= "\n" . '<table class="form-table avhec-options">' . "\n";
1853
- foreach ($option_data as $option) {
1854
- $section = substr($option[0], strpos($option[0], '[') + 1);
1855
- $section = substr($section, 0, strpos($section, ']['));
1856
- $option_key = rtrim($option[0], ']');
1857
- $option_key = substr($option_key, strpos($option_key, '][') + 2);
1858
- // Helper
1859
- if ($option[2] == 'helper') {
1860
- $output .= '<tr style="vertical-align: top;"><td class="helper" colspan="2">' .
1861
- wp_filter_post_kses($option[4]) .
1862
- '</td></tr>' .
1863
- "\n";
1864
- continue;
1865
- }
1866
- switch ($option[2]) {
1867
- case 'checkbox':
1868
- $input_type = '<input type="checkbox" id="' .
1869
- esc_attr($option[0]) .
1870
- '" name="' .
1871
- esc_attr($option[0]) .
1872
- '" value="' .
1873
- esc_attr($option[3]) .
1874
- '" ' .
1875
- $this->isChecked('1', $option_actual[$section][$option_key]) .
1876
- ' />' .
1877
- "\n";
1878
- $explanation = $option[4];
1879
- break;
1880
- case 'dropdown':
1881
- $selvalue = $option[3];
1882
- $seltext = $option[4];
1883
- $seldata = '';
1884
- foreach ((array) $selvalue as $key => $sel) {
1885
- $seldata .= '<option value="' .
1886
- esc_attr($sel) .
1887
- '" ' .
1888
- (($option_actual[$section][$option_key] == $sel) ? 'selected="selected"' : '') .
1889
- ' >' .
1890
- esc_html(ucfirst($seltext[$key])) .
1891
- '</option>' .
1892
- "\n";
1893
- }
1894
- $input_type = '<select id="' .
1895
- esc_attr($option[0]) .
1896
- '" name="' .
1897
- esc_attr($option[0]) .
1898
- '">' .
1899
- $seldata .
1900
- '</select>' .
1901
- "\n";
1902
- $explanation = $option[5];
1903
- break;
1904
- case 'text-color':
1905
- $input_type = '<input type="text" ' .
1906
- (($option[3] > 1) ? ' style="width: 95%" ' : '') .
1907
- 'id="' .
1908
- esc_attr($option[0]) .
1909
- '" name="' .
1910
- esc_attr($option[0]) .
1911
- '" value="' .
1912
- esc_attr($option_actual[$section][$option_key]) .
1913
- '" size="' .
1914
- esc_attr($option[3]) .
1915
- '" /><div class="box_color ' .
1916
- esc_attr($option[0]) .
1917
- '"></div>' .
1918
- "\n";
1919
- $explanation = $option[4];
1920
- break;
1921
- case 'textarea':
1922
- $input_type = '<textarea rows="' .
1923
- esc_attr($option[5]) .
1924
- '" ' .
1925
- (($option[3] > 1) ? ' style="width: 95%" ' : '') .
1926
- 'id="' .
1927
- esc_attr($option[0]) .
1928
- '" name="' .
1929
- esc_attr($option[0]) .
1930
- '" size="' .
1931
- esc_attr($option[3]) .
1932
- '" />' .
1933
- $option_actual[$section][$option_key] .
1934
- '</textarea>';
1935
- $explanation = $option[4];
1936
- break;
1937
- case 'catlist':
1938
- ob_start();
1939
- echo '<div id="avhec-catlist">';
1940
- echo '<ul>';
1941
- wp_category_checklist(0, 0, $option_actual[$section][$option_key]);
1942
- echo '</ul>';
1943
- echo '</div>';
1944
- $input_type = ob_get_contents();
1945
- ob_end_clean();
1946
- $explanation = $option[4];
1947
- break;
1948
- case 'text':
1949
- default:
1950
- $input_type = '<input type="text" ' .
1951
- (($option[3] > 1) ? ' style="width: 95%" ' : '') .
1952
- 'id="' .
1953
- esc_attr($option[0]) .
1954
- '" name="' .
1955
- esc_attr($option[0]) .
1956
- '" value="' .
1957
- esc_attr($option_actual[$section][$option_key]) .
1958
- '" size="' .
1959
- esc_attr($option[3]) .
1960
- '" />' .
1961
- "\n";
1962
- $explanation = $option[4];
1963
- break;
1964
- }
1965
- // Additional Information
1966
- $extra = '';
1967
- if ($explanation) {
1968
- $extra = '<br /><span class="description">' . wp_filter_kses($explanation) . '</span>' . "\n";
1969
- }
1970
- // Output
1971
- $output .= '<tr style="vertical-align: top;"><th align="left" scope="row"><label for="' .
1972
- esc_attr($option[0]) .
1973
- '">' .
1974
- wp_filter_kses($option[1]) .
1975
- '</label></th><td>' .
1976
- $input_type .
1977
- ' ' .
1978
- $extra .
1979
- '</td></tr>' .
1980
- "\n";
1981
- }
1982
- $output .= '</table>' . "\n";
1983
-
1984
- return $output;
1985
- }
1986
  }
1
  <?php
2
 
3
+ class AVH_EC_Admin {
4
+ /**
5
+ * @var AVH_EC_Category_Group
6
+ */
7
+ public $catgrp;
8
+ /**
9
+ * @var AVH_EC_Core
10
+ */
11
+ public $core;
12
+ public $hooks = array();
13
+ public $message;
14
+
15
+ /**
16
+ * PHP5 constructor
17
+ */
18
+ public function __construct() {
19
+
20
+ // Initialize the plugin
21
+ $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core');
22
+ $this->catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
23
+
24
+ add_action('wp_ajax_delete-group', array($this, 'ajaxDeleteGroup'));
25
+
26
+ // Admin menu
27
+ add_action('admin_init', array($this, 'actionAdminInit'));
28
+ add_action('admin_menu', array($this, 'actionAdminMenu'));
29
+ add_filter('plugin_action_links_extended-categories-widget/widget_extended_categories.php',
30
+ array($this, 'filterPluginActions'),
31
+ 10,
32
+ 2);
33
+
34
+ // Actions used for editing posts
35
+ add_action('load-post.php', array($this, 'actionLoadPostPage'));
36
+ add_action('load-page.php', array($this, 'actionLoadPostPage'));
37
+
38
+ // Actions related to adding and deletes categories
39
+ add_action('created_category', array($this, 'actionCreatedCategory'), 10, 2);
40
+ add_action('delete_category', array($this, 'actionDeleteCategory'), 10, 2);
41
+
42
+ add_filter('manage_categories_group_columns', array($this, 'filterManageCategoriesGroupColumns'));
43
+ add_filter('explain_nonce_delete-avhecgroup', array($this, 'filterExplainNonceDeleteGroup'), 10, 2);
44
+
45
+ return;
46
+ }
47
+
48
+ public function actionAdminInit() {
49
+ if (is_admin() && isset($_GET['taxonomy']) && 'category' == $_GET['taxonomy']) {
50
+ add_action($_GET['taxonomy'] . '_edit_form', array($this, 'displayCategoryGroupForm'), 10, 2);
51
+ }
52
+ add_action('edit_term', array($this, 'handleEditTerm'), 10, 3);
53
+ }
54
+
55
+ /**
56
+ * Add the Tools and Options to the Management and Options page repectively
57
+ *
58
+ * @WordPress Action admin_menu
59
+ */
60
+ public function actionAdminMenu() {
61
+
62
+ // Register Style and Scripts
63
+ $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
64
+ wp_register_script('avhec-categorygroup-js',
65
+ AVHEC_PLUGIN_URL . '/js/avh-ec.categorygroup' . $suffix . '.js',
66
+ array('jquery'),
67
+ $this->core->version,
68
+ true);
69
+ wp_register_script('avhec-manualorder',
70
+ AVHEC_PLUGIN_URL . '/js/avh-ec.admin.manualorder' . $suffix . '.js',
71
+ array('jquery-ui-sortable'),
72
+ $this->core->version,
73
+ false);
74
+ wp_register_style('avhec-admin-css',
75
+ AVHEC_PLUGIN_URL . '/css/avh-ec.admin.css',
76
+ array('wp-admin'),
77
+ $this->core->version,
78
+ 'screen');
79
+
80
+ // Add menu system
81
+ $folder = $this->core->getBaseDirectory(AVHEC_PLUGIN_DIR);
82
+ add_menu_page('AVH Extended Categories',
83
+ 'AVH Extended Categories',
84
+ 'manage_options',
85
+ $folder,
86
+ array($this, 'doMenuOverview'));
87
+ $this->hooks['menu_overview'] = add_submenu_page($folder,
88
+ 'AVH Extended Categories: ' . __('Overview', 'avh-ec'),
89
+ __('Overview', 'avh-ec'),
90
+ 'manage_options',
91
+ $folder,
92
+ array($this, 'doMenuOverview'));
93
+ $this->hooks['menu_general'] = add_submenu_page($folder,
94
+ 'AVH Extended Categories: ' .
95
+ __('General Options', 'avh-ec'),
96
+ __('General Options', 'avh-ec'),
97
+ 'manage_options',
98
+ 'avhec-general',
99
+ array($this, 'doMenuGeneral'));
100
+ $this->hooks['menu_category_groups'] = add_submenu_page($folder,
101
+ 'AVH Extended Categories: ' .
102
+ __('Category Groups', 'avh-ec'),
103
+ __('Category Groups', 'avh-ec'),
104
+ 'manage_options',
105
+ 'avhec-grouped',
106
+ array($this, 'doMenuCategoryGroup'));
107
+ $this->hooks['menu_manual_order'] = add_submenu_page($folder,
108
+ 'AVH Extended Categories: ' .
109
+ __('Manually Order', 'avh-ec'),
110
+ __('Manually Order', 'avh-ec'),
111
+ 'manage_options',
112
+ 'avhec-manual-order',
113
+ array($this, 'doMenuManualOrder'));
114
+ $this->hooks['menu_faq'] = add_submenu_page($folder,
115
+ 'AVH Extended Categories:' . __('F.A.Q', 'avh-ec'),
116
+ __('F.A.Q', 'avh-ec'),
117
+ 'manage_options',
118
+ 'avhec-faq',
119
+ array($this, 'doMenuFAQ'));
120
+
121
+ // Add actions for menu pages
122
+ // Overview Menu
123
+ add_action('load-' . $this->hooks['menu_overview'], array($this, 'actionLoadPageHook_Overview'));
124
+
125
+ // General Options Menu
126
+ add_action('load-' . $this->hooks['menu_general'], array($this, 'actionLoadPageHook_General'));
127
+
128
+ // Category Groups Menu
129
+ add_action('load-' . $this->hooks['menu_category_groups'], array($this, 'actionLoadPageHook_CategoryGroup'));
130
+
131
+ // Manual Order Menu
132
+ add_action('load-' . $this->hooks['menu_manual_order'], array($this, 'actionLoadPageHook_ManualOrder'));
133
+
134
+ // FAQ Menu
135
+ add_action('load-' . $this->hooks['menu_faq'], array($this, 'actionLoadPageHook_faq'));
136
+ }
137
+
138
+ /**
139
+ * When a category is created this function is called to add the new category to the group all
140
+ *
141
+ * @param int $term_id
142
+ * @param int $term_taxonomy_id
143
+ */
144
+ public function actionCreatedCategory($term_id, $term_taxonomy_id) {
145
+ $group_id = $this->catgrp->getTermIDBy('slug', 'all');
146
+ $this->catgrp->setCategoriesForGroup($group_id, (array) $term_id);
147
+ }
148
+
149
+ /**
150
+ * When a category is deleted this function is called so the category is deleted from every group as well.
151
+ *
152
+ * @param int $term_id
153
+ * @param int $term_taxonomy_id
154
+ *
155
+ * @internal param object $term
156
+ */
157
+ public function actionDeleteCategory($term_id, $term_taxonomy_id) {
158
+ $this->catgrp->doDeleteCategoryFromGroup($term_id);
159
+ }
160
+
161
+ /**
162
+ * Setup everything needed for the Category Group page
163
+ */
164
+ public function actionLoadPageHook_CategoryGroup() {
165
+
166
+ // Add metaboxes
167
+ add_meta_box('avhecBoxCategoryGroupAdd',
168
+ __('Add Group', 'avh-ec'),
169
+ array($this, 'metaboxCategoryGroupAdd'),
170
+ $this->hooks['menu_category_groups'],
171
+ 'normal',
172
+ 'core');
173
+ add_meta_box('avhecBoxCategoryGroupList',
174
+ __('Group Overview', 'avh-ec'),
175
+ array($this, 'metaboxCategoryGroupList'),
176
+ $this->hooks['menu_category_groups'],
177
+ 'side',
178
+ 'core');
179
+ add_meta_box('avhecBoxCategoryGroupSpecialPages',
180
+ __('Special Pages', 'avh-ec'),
181
+ array($this, 'metaboxCategoryGroupSpecialPages'),
182
+ $this->hooks['menu_category_groups'],
183
+ 'normal',
184
+ 'core');
185
+
186
+ add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
187
+
188
+ // WordPress core Scripts
189
+ wp_enqueue_script('common');
190
+ wp_enqueue_script('wp-lists');
191
+ wp_enqueue_script('postbox');
192
+
193
+ // Plugin Scripts
194
+ wp_enqueue_script('avhec-categorygroup-js');
195
+
196
+ // Plugin Style
197
+ wp_enqueue_style('avhec-admin-css');
198
+ }
199
+
200
+ /**
201
+ * Setup everything needed for the General Options page
202
+ */
203
+ public function actionLoadPageHook_General() {
204
+ // Add metaboxes
205
+ add_meta_box('avhecBoxOptions',
206
+ __('Options', 'avh-ec'),
207
+ array($this, 'metaboxOptions'),
208
+ $this->hooks['menu_general'],
209
+ 'normal',
210
+ 'core');
211
+
212
+ add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
213
+
214
+ // WordPress core Scripts
215
+ wp_enqueue_script('common');
216
+ wp_enqueue_script('wp-lists');
217
+ wp_enqueue_script('postbox');
218
+
219
+ // Plugin Style and Scripts
220
+ wp_enqueue_style('avhec-admin-css');
221
+ }
222
+
223
+ /**
224
+ * Setup everything needed for the Manul Order page
225
+ */
226
+ public function actionLoadPageHook_ManualOrder() {
227
+ add_meta_box('avhecBoxManualOrder',
228
+ __('Manually Order Categories', 'avh-ec'),
229
+ array($this, 'metaboxManualOrder'),
230
+ $this->hooks['menu_manual_order'],
231
+ 'normal',
232
+ 'core');
233
+
234
+ add_screen_option('layout_columns', array('max' => 1, 'default' => 1));
235
+
236
+ // WordPress core Styles and Scripts
237
+ wp_enqueue_script('common');
238
+ wp_enqueue_script('wp-lists');
239
+ wp_enqueue_script('postbox');
240
+ wp_enqueue_script('jquery-ui-sortable');
241
+ wp_enqueue_script('avhec-manualorder');
242
+
243
+ // Plugin Style
244
+ wp_enqueue_style('avhec-admin-css');
245
+ }
246
+
247
+ /**
248
+ * Setup everything needed for the Overview page
249
+ */
250
+ public function actionLoadPageHook_Overview() {
251
+ // Add metaboxes
252
+ add_meta_box('avhecBoxCategoryGroupList',
253
+ __('Group Overview', 'avh-ec'),
254
+ array($this, 'metaboxCategoryGroupList'),
255
+ $this->hooks['menu_overview'],
256
+ 'normal',
257
+ 'core');
258
+ add_meta_box('avhecBoxTranslation',
259
+ __('Translation', 'avh-ec'),
260
+ array($this, 'metaboxTranslation'),
261
+ $this->hooks['menu_overview'],
262
+ 'normal',
263
+ 'core');
264
+
265
+ add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
266
+
267
+ // WordPress core Scripts
268
+ wp_enqueue_script('common');
269
+ wp_enqueue_script('wp-lists');
270
+ wp_enqueue_script('postbox');
271
+
272
+ // Plugin Scripts
273
+ wp_enqueue_script('avhec-categorygroup-js');
274
+
275
+ // Plugin Style
276
+ wp_enqueue_style('avhec-admin-css');
277
+ }
278
+
279
+ /**
280
+ * Setup everything needed for the FAQ page
281
+ */
282
+ public function actionLoadPageHook_faq() {
283
+ add_meta_box('avhecBoxFAQ',
284
+ __('F.A.Q.', 'avh-ec'),
285
+ array($this, 'metaboxFAQ'),
286
+ $this->hooks['menu_faq'],
287
+ 'normal',
288
+ 'core');
289
+ add_meta_box('avhecBoxTranslation',
290
+ __('Translation', 'avh-ec'),
291
+ array($this, 'metaboxTranslation'),
292
+ $this->hooks['menu_faq'],
293
+ 'normal',
294
+ 'core');
295
+
296
+ add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
297
+
298
+ // WordPress core Styles and Scripts
299
+ wp_enqueue_script('common');
300
+ wp_enqueue_script('wp-lists');
301
+ wp_enqueue_script('postbox');
302
+
303
+ // Plugin Style
304
+ wp_enqueue_style('avhec-admin-css');
305
+ }
306
+
307
+ /**
308
+ * Enqueues the style on the post.php and page.php pages
309
+ *
310
+ * @WordPress Action load-$pagenow
311
+ */
312
+ public function actionLoadPostPage() {
313
+ wp_enqueue_style('avhec-admin-css');
314
+ }
315
+
316
+ /**
317
+ * Ajax Helper: inline delete of the groups
318
+ */
319
+ public function ajaxDeleteGroup() {
320
+ $group_id = isset($_POST['id']) ? (int) $_POST['id'] : 0;
321
+ check_ajax_referer('delete-avhecgroup_' . $group_id);
322
+
323
+ if ( ! current_user_can('manage_categories')) {
324
+ die('-1');
325
+ }
326
+ $check = $this->catgrp->getGroup($group_id);
327
+ if (false === $check) {
328
+ die('1');
329
+ }
330
+
331
+ if ($this->catgrp->doDeleteGroup($group_id)) {
332
+ die('1');
333
+ } else {
334
+ die('0');
335
+ }
336
+ }
337
+
338
+ /**
339
+ * Adds Category Group form
340
+ *
341
+ * @WordPress action category_edit_form
342
+ *
343
+ * @param object $term
344
+ * @param string $taxonomy
345
+ */
346
+ public function displayCategoryGroupForm($term, $taxonomy) {
347
+ $current_selection = '';
348
+ $tax_meta = get_option($this->core->db_options_tax_meta);
349
+ if (isset($tax_meta[ $taxonomy ][ $term->term_id ])) {
350
+ $tax_meta = $tax_meta[ $taxonomy ][ $term->term_id ];
351
+ $current_selection = $tax_meta['category_group_term_id'];
352
+ }
353
+
354
+ if (empty($current_selection)) {
355
+ $current_group = $this->catgrp->getGroupByCategoryID($term->term_id);
356
+ $current_selection = $current_group->term_id;
357
+ }
358
+
359
+ $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false));
360
+ foreach ($cat_groups as $group) {
361
+ $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit');
362
+ $dropdown_value[] = $group->term_id;
363
+ $dropdown_text[] = $temp_cat->name;
364
+ }
365
+
366
+ $seldata = '';
367
+ foreach ($dropdown_value as $key => $sel) {
368
+ $seldata .= '<option value="' .
369
+ esc_attr($sel) .
370
+ '" ' .
371
+ (($current_selection == $sel) ? 'selected="selected"' : '') .
372
+ ' >' .
373
+ esc_html(ucfirst($dropdown_text[ $key ])) .
374
+ '</option>' .
375
+ "\n";
376
+ }
377
+
378
+ echo '<h3>AVH Extended Categories - Category Group Widget</h3>';
379
+ echo '<table class="form-table"><tbody>';
380
+ echo '<tr class="form-field">';
381
+ echo '<th valign="top" scope="row">';
382
+ echo '<label for="avhec_categorygroup">Category Group</label></th>';
383
+ echo '<td>';
384
+ echo '<select id="avhec_categorygroup" name="avhec_categorygroup">';
385
+ echo $seldata;
386
+ echo '</select>';
387
+ echo '<p class="description">Select the category group to show on the archive page.</p>';
388
+ echo '</td>';
389
+ echo '</tr>';
390
+ echo '</tbody></table>';
391
+ }
392
+
393
+ /**
394
+ * Displays the icon on the menu pages
395
+ *
396
+ * @param string $icon
397
+ *
398
+ * @return string
399
+ */
400
+ public function displayIcon($icon) {
401
+ return ('<div class="icon32" id="icon-' . $icon . '"><br/></div>');
402
+ }
403
+
404
+ /**
405
+ * Display WP alert
406
+ */
407
+ public function displayMessage() {
408
+ if ($this->message != '') {
409
+ $message = $this->message;
410
+ $status = $this->status;
411
+ $this->message = $this->status = ''; // Reset
412
+ }
413
+ if (isset($message)) {
414
+ $status = ($status != '') ? $status : 'updated fade';
415
+ echo '<div id="message" class="' . $status . '">';
416
+ echo '<p><strong>' . $message . '</strong></p></div>';
417
+ }
418
+ }
419
+
420
+ /**
421
+ * Menu Page Category Group
422
+ *
423
+ * @return void
424
+ */
425
+ public function doMenuCategoryGroup() {
426
+ global $screen_layout_columns;
427
+
428
+ $data_add_group_default = array('name' => '', 'slug' => '', 'widget_title' => '', 'description' => '');
429
+ $data_add_group_new = $data_add_group_default;
430
+
431
+ $options_add_group[] = array(
432
+ 'avhec_add_group[add][name]',
433
+ __('Group Name', 'avh-ec'),
434
+ 'text',
435
+ 20,
436
+ __('The name is used to identify the group.', 'avh-ec')
437
+ );
438
+ $options_add_group[] = array(
439
+ 'avhec_add_group[add][slug]',
440
+ __('Slug Group', 'avh-ec'),
441
+ 'text',
442
+ 20,
443
+ __('The “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.',
444
+ 'avh-ec')
445
+ );
446
+ $options_add_group[] = array(
447
+ 'avhec_add_group[add][widget_title]',
448
+ __('Widget Title', 'avh-ec'),
449
+ 'text',
450
+ 20,
451
+ __('When no title is given in the widget options, this will used as the title of the widget when this group is shown.',
452
+ 'avh-ec')
453
+ );
454
+ $options_add_group[] = array(
455
+ 'avhec_add_group[add][description]',
456
+ __('Description', 'avh-ec'),
457
+ 'textarea',
458
+ 40,
459
+ __('Description is not prominent by default.', 'avh-ec'),
460
+ 5
461
+ );
462
+
463
+ $options_edit_group[] = array(
464
+ 'avhec_edit_group[edit][name]',
465
+ __('Group Name', 'avh-ec'),
466
+ 'text',
467
+ 20,
468
+ __('The name is used to identify the group.', 'avh-ec')
469
+ );
470
+ $options_edit_group[] = array(
471
+ 'avhec_edit_group[edit][slug]',
472
+ __('Slug Group', 'avh-ec'),
473
+ 'text',
474
+ 20,
475
+ __('The “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.',
476
+ 'avh-ec')
477
+ );
478
+ $options_edit_group[] = array(
479
+ 'avhec_edit_group[edit][widget_title]',
480
+ __('Widget Title', 'avh-ec'),
481
+ 'text',
482
+ 20,
483
+ __('When no title is given in the widget options, this will used as the title of the widget when this group is shown.',
484
+ 'avh-ec')
485
+ );
486
+ $options_edit_group[] = array(
487
+ 'avhec_edit_group[edit][description]',
488
+ __('Description', 'avh-ec'),
489
+ 'textarea',
490
+ 40,
491
+ __('Description is not prominent by default.', 'avh-ec'),
492
+ 5
493
+ );
494
+ $options_edit_group[] = array(
495
+ 'avhec_edit_group[edit][categories]',
496
+ __('Categories', 'avh-ec'),
497
+ 'catlist',
498
+ 0,
499
+ __('Select categories to be included in the group.', 'avh-ec')
500
+ );
501
+
502
+ if (isset($_POST['addgroup'])) {
503
+ check_admin_referer('avh_ec_addgroup');
504
+
505
+ $formoptions = $_POST['avhec_add_group'];
506
+
507
+ $data_add_group_new['name'] = $formoptions['add']['name'];
508
+ $data_add_group_new['slug'] = empty($formoptions['add']['slug']) ? sanitize_title($data_add_group_new['name']) : sanitize_title($formoptions['add']['slug']);
509
+ $data_add_group_new['widget_title'] = $formoptions['add']['widget_title'];
510
+ $data_add_group_new['description'] = $formoptions['add']['description'];
511
+
512
+ $id = $this->catgrp->getTermIDBy('slug', $data_add_group_new['slug']);
513
+ if ( ! $id) {
514
+ $group_id = $this->catgrp->doInsertGroup($data_add_group_new['name'],
515
+ array(
516
+ 'description' => $data_add_group_new['description'],
517
+ 'slug' => $data_add_group_new['slug']
518
+ ),
519
+ $data_add_group_new['widget_title']);
520
+ $this->catgrp->setCategoriesForGroup($group_id);
521
+ $this->message = __('Category group saved', 'avh-ec');
522
+ $this->status = 'updated fade';
523
+ $data_add_group_new = $data_add_group_default;
524
+ } else {
525
+ $group = $this->catgrp->getGroup($id);
526
+ $this->message = __('Category group conflicts with ', 'avh-ec') . $group->name;
527
+ $this->message .= '<br />' . __('Same slug is used. ', 'avh-ec');
528
+ $this->status = 'error';
529
+ }
530
+ $this->displayMessage();
531
+ }
532
+ $data_add_group['add'] = $data_add_group_new;
533
+ $data['add'] = array('form' => $options_add_group, 'data' => $data_add_group);
534
+
535
+ if (isset($_GET['action'])) {
536
+ $action = $_GET['action'];
537
+
538
+ switch ($action) {
539
+ case 'edit':
540
+ $group_id = (int) $_GET['group_ID'];
541
+ $group = $this->catgrp->getGroup($group_id);
542
+ $widget_title = $this->catgrp->getWidgetTitleForGroup($group_id);
543
+ $cats = $this->catgrp->getCategoriesFromGroup($group_id);
544
+
545
+ $data_edit_group['edit'] = array(
546
+ 'group_id' => $group_id,
547
+ 'name' => $group->name,
548
+ 'slug' => $group->slug,
549
+ 'widget_title' => $widget_title,
550
+ 'description' => $group->description,
551
+ 'categories' => $cats
552
+ );
553
+ $data['edit'] = array('form' => $options_edit_group, 'data' => $data_edit_group);
554
+
555
+ add_meta_box('avhecBoxCategoryGroupEdit',
556
+ __('Edit Group', 'avh-ec') . ': ' . $group->name,
557
+ array($this, 'metaboxCategoryGroupEdit'),
558
+ $this->hooks['menu_category_groups'],
559
+ 'normal',
560
+ 'low');
561
+ break;
562
+ case 'delete':
563
+ if ( ! isset($_GET['group_ID'])) {
564
+ wp_redirect($this->getBackLink());
565
+ exit();
566
+ }
567
+
568
+ $group_id = (int) $_GET['group_ID'];
569
+ check_admin_referer('delete-avhecgroup_' . $group_id);
570
+
571
+ if ( ! current_user_can('manage_categories')) {
572
+ wp_die(__('Cheatin&#8217; uh?'));
573
+ }
574
+ $this->catgrp->doDeleteGroup($group_id);
575
+ break;
576
+ default:
577
+ ;
578
+ break;
579
+ }
580
+ }
581
+
582
+ if (isset($_POST['editgroup'])) {
583
+ check_admin_referer('avh_ec_editgroup');
584
+
585
+ $formoptions = $_POST['avhec_edit_group'];
586
+ $selected_categories = $_POST['post_category'];
587
+
588
+ $group_id = (int) $_POST['avhec-group_id'];
589
+ $result = $this->catgrp->doUpdateGroup($group_id,
590
+ array(
591
+ 'name' => $formoptions['edit']['name'],
592
+ 'slug' => $formoptions['edit']['slug'],
593
+ 'description' => $formoptions['edit']['description']
594
+ ),
595
+ $selected_categories,
596
+ $formoptions['edit']['widget_title']);
597
+ switch ($result) {
598
+ case 1:
599
+ $this->message = __('Category group updated', 'avh-ec');
600
+ $this->status = 'updated fade';
601
+ break;
602
+ case 0:
603
+ $this->message = __('Category group not updated', 'avh-ec');
604
+ $this->message .= '<br />' . __('Duplicate slug detected', 'avh-ec');
605
+ $this->status = 'error';
606
+ break;
607
+ case - 1:
608
+ $this->message = __('Unknown category group', 'avh-ec');
609
+ $this->status = 'error';
610
+ break;
611
+ }
612
+ $this->displayMessage();
613
+ }
614
+
615
+ $hide2 = '';
616
+ switch ($screen_layout_columns) {
617
+ case 2:
618
+ $width = 'width:49%;';
619
+ break;
620
+ default:
621
+ $width = 'width:98%;';
622
+ $hide2 = 'display:none;';
623
+ }
624
+
625
+ $data_special_pages_old = $this->core->options['sp_cat_group'];
626
+ $data_special_pages_new = $data_special_pages_old;
627
+ if (isset($_POST['avhec_special_pages'])) {
628
+ check_admin_referer('avh_ec_specialpagesgroup');
629
+
630
+ $formoptions = $_POST['avhec_special_pages'];
631
+ $formdata = $formoptions['sp'];
632
+ foreach ($formdata as $key => $value) {
633
+ $data_special_pages_new[ $key ] = $value;
634
+ }
635
+ $this->core->options['sp_cat_group'] = $data_special_pages_new;
636
+ $this->core->saveOptions($this->core->options);
637
+ }
638
+ $data_special_pages['sp'] = $data_special_pages_new;
639
+ $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false));
640
+
641
+ foreach ($cat_groups as $group) {
642
+ $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit');
643
+ $dropdown_value[] = $group->term_id;
644
+ $dropdown_text[] = $temp_cat->name;
645
+ }
646
+ $options_special_pages[] = array(
647
+ 'avhec_special_pages[sp][home_group]',
648
+ __('Home page', 'avh-ec'),
649
+ 'dropdown',
650
+ $dropdown_value,
651
+ $dropdown_text,
652
+ sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('home', 'avhec'))
653
+ );
654
+ // $options_special_pages[] = array('avhec_special_pages[sp][category_group]', __('Category Archive', 'avh-ec'), 'dropdown', $dropdown_value, $dropdown_text, sprintf(__('Select which category to show on the %s page.','avh-ec'),__('category archive','avhec')));
655
+ $options_special_pages[] = array(
656
+ 'avhec_special_pages[sp][day_group]',
657
+ __('Daily Archive', 'avh-ec'),
658
+ 'dropdown',
659
+ $dropdown_value,
660
+ $dropdown_text,
661
+ sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('daily archive', 'avhec'))
662
+ );
663
+ $options_special_pages[] = array(
664
+ 'avhec_special_pages[sp][month_group]',
665
+ __('Monthly Archive', 'avh-ec'),
666
+ 'dropdown',
667
+ $dropdown_value,
668
+ $dropdown_text,
669
+ sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('monthly archive', 'avhec'))
670
+ );
671
+ $options_special_pages[] = array(
672
+ 'avhec_special_pages[sp][year_group]',
673
+ __('Yearly Archive', 'avh-ec'),
674
+ 'dropdown',
675
+ $dropdown_value,
676
+ $dropdown_text,
677
+ sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('yearly archive', 'avhec'))
678
+ );
679
+ $options_special_pages[] = array(
680
+ 'avhec_special_pages[sp][author_group]',
681
+ __('Author Archive', 'avh-ec'),
682
+ 'dropdown',
683
+ $dropdown_value,
684
+ $dropdown_text,
685
+ sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('author archive', 'avhec'))
686
+ );
687
+ $options_special_pages[] = array(
688
+ 'avhec_special_pages[sp][search_group]',
689
+ __('Search Page', 'avh-ec'),
690
+ 'dropdown',
691
+ $dropdown_value,
692
+ $dropdown_text,
693
+ sprintf(__('Select which category to show on the %s page.', 'avh-ec'), __('search', 'avhec'))
694
+ );
695
+
696
+ $data['sp'] = array('form' => $options_special_pages, 'data' => $data_special_pages);
697
+
698
+ // This box can't be unselectd in the the Screen Options
699
+ // add_meta_box( 'avhecBoxDonations', __( 'Donations', 'avh-ec' ), array ($this, 'metaboxDonations' ), $this->hooks['menu_category_groups'], 'side', 'core' );
700
+
701
+ echo '<div class="wrap avhec-metabox-wrap">';
702
+ echo $this->displayIcon('index');
703
+ echo '<h2>' . 'AVH Extended Categories - ' . __('Category Groups', 'avh-ec') . '</h2>';
704
+
705
+ echo ' <div id="dashboard-widgets-wrap">';
706
+ echo ' <div id="dashboard-widgets" class="metabox-holder">';
707
+
708
+ echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
709
+ do_meta_boxes($this->hooks['menu_category_groups'], 'normal', $data);
710
+ echo " </div>";
711
+
712
+ echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n";
713
+ do_meta_boxes($this->hooks['menu_category_groups'], 'side', $data);
714
+ echo ' </div>';
715
+
716
+ echo ' </div>'; // dashboard-widgets
717
+ echo '<br class="clear" />';
718
+ echo ' </div>'; // dashboard-widgets-wrap
719
+ echo '</div>'; // wrap
720
+
721
+ $this->printMetaboxGeneralNonces();
722
+ $this->printMetaboxJS('grouped');
723
+ $this->printAdminFooter();
724
+ }
725
+
726
+ /**
727
+ * Menu Page FAQ
728
+ *
729
+ * @return none
730
+ */
731
+ public function doMenuFAQ() {
732
+ global $screen_layout_columns;
733
+
734
+ // This box can't be unselectd in the the Screen Options
735
+ // add_meta_box('avhecBoxAnnouncements', __('Announcements', 'avh-ec'), array ( $this, 'metaboxAnnouncements' ), $this->hooks['menu_faq'], 'side', 'core');
736
+ add_meta_box('avhecBoxDonations',
737
+ __('Donations', 'avh-ec'),
738
+ array($this, 'metaboxDonations'),
739
+ $this->hooks['menu_faq'],
740
+ 'side',
741
+ 'core');
742
+
743
+ $hide2 = '';
744
+ switch ($screen_layout_columns) {
745
+ case 2:
746
+ $width = 'width:49%;';
747
+ break;
748
+ default:
749
+ $width = 'width:98%;';
750
+ $hide2 = 'display:none;';
751
+ }
752
+
753
+ echo '<div class="wrap avhec-metabox-wrap">';
754
+ echo $this->displayIcon('index');
755
+ echo '<h2>' . 'AVH Extended Categories - ' . __('F.A.Q', 'avh-ec') . '</h2>';
756
+ echo ' <div id="dashboard-widgets-wrap">';
757
+ echo ' <div id="dashboard-widgets" class="metabox-holder">';
758
+ echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
759
+ do_meta_boxes($this->hooks['menu_faq'], 'normal', '');
760
+ echo ' </div>';
761
+ echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n";
762
+ do_meta_boxes($this->hooks['menu_faq'], 'side', '');
763
+ echo ' </div>';
764
+ echo ' </div>';
765
+ echo '<br class="clear"/>';
766
+ echo ' </div>'; // dashboard-widgets-wrap
767
+ echo '</div>'; // wrap
768
+
769
+ $this->printMetaboxGeneralNonces();
770
+ $this->printMetaboxJS('faq');
771
+ $this->printAdminFooter();
772
+ }
773
+
774
+ /**
775
+ * Menu Page General Options
776
+ *
777
+ * @return void
778
+ */
779
+ public function doMenuGeneral() {
780
+ global $screen_layout_columns;
781
+
782
+ $groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false));
783
+ foreach ($groups as $group) {
784
+ $group_id[] = $group->term_id;
785
+ $groupname[] = $group->name;
786
+ }
787
+
788
+ $options_general[] = array(
789
+ 'avhec[general][alternative_name_select_category]',
790
+ __('<em>Select Category</em> Alternative', 'avh-ec'),
791
+ 'text',
792
+ 20,
793
+ __('Alternative text for Select Category.', 'avh-ec')
794
+ );
795
+ $options_general[] = array(
796
+ 'avhec[cat_group][home_group]',
797
+ 'Home Group',
798
+ 'dropdown',
799
+ $group_id,
800
+ $groupname,
801
+ __('Select which group to show on the home page.', 'avh-ec') .
802
+ '<br />' .
803
+ __('Selecting the group \'none\' will not show the widget on the page.', 'avh-ec')
804
+ );
805
+ $options_general[] = array(
806
+ 'avhec[cat_group][no_group]',
807
+ 'Nonexistence Group',
808
+ 'dropdown',
809
+ $group_id,
810
+ $groupname,
811
+ __('Select which group to show when there is no group associated with the post.', 'avh-ec') .
812
+ '<br />' .
813
+ __('Selecting the group \'none\' will not show the widget on the page.', 'avh-ec')
814
+ );
815
+ $options_general[] = array(
816
+ 'avhec[cat_group][default_group]',
817
+ 'Default Group',
818
+ 'dropdown',
819
+ $group_id,
820
+ $groupname,
821
+ __('Select which group will be the default group when editing a post.', 'avh-ec') .
822
+ '<br />' .
823
+ __('Selecting the group \'none\' will not show the widget on the page.', 'avh-ec')
824
+ );
825
+
826
+ if (isset($_POST['updateoptions'])) {
827
+ check_admin_referer('avh_ec_generaloptions');
828
+
829
+ $formoptions = $_POST['avhec'];
830
+ $options = $this->core->getOptions();
831
+
832
+ // $all_data = array_merge( $options_general );
833
+ $all_data = $options_general;
834
+ foreach ($all_data as $option) {
835
+ $section = substr($option[0], strpos($option[0], '[') + 1);
836
+ $section = substr($section, 0, strpos($section, ']['));
837
+ $option_key = rtrim($option[0], ']');
838
+ $option_key = substr($option_key, strpos($option_key, '][') + 2);
839
+
840
+ switch ($section) {
841
+ case 'general':
842
+ case 'cat_group':
843
+ $current_value = $options[ $section ][ $option_key ];
844
+ break;
845
+ }
846
+ // Every field in a form is set except unchecked checkboxes. Set an unchecked checkbox to 0.
847
+ $newval = (isset($formoptions[ $section ][ $option_key ]) ? esc_attr($formoptions[ $section ][ $option_key ]) : 0);
848
+ if ($newval != $current_value) { // Only process changed fields.
849
+ switch ($section) {
850
+ case 'general':
851
+ case 'cat_group':
852
+ $options[ $section ][ $option_key ] = $newval;
853
+ break;
854
+ }
855
+ }
856
+ }
857
+ $this->core->saveOptions($options);
858
+ $this->message = __('Options saved', 'avh-ec');
859
+ $this->status = 'updated fade';
860
+ }
861
+ $this->displayMessage();
862
+
863
+ $actual_options = $this->core->getOptions();
864
+ foreach ($actual_options['cat_group'] as $key => $value) {
865
+ if ( ! (in_array($value, (array) $group_id))) {
866
+ $actual_options['cat_group'][ $key ] = $this->catgrp->getTermIDBy('slug', 'none');
867
+ }
868
+ }
869
+
870
+ $hide2 = '';
871
+ switch ($screen_layout_columns) {
872
+ case 2:
873
+ $width = 'width:49%;';
874
+ break;
875
+ default:
876
+ $width = 'width:98%;';
877
+ $hide2 = 'display:none;';
878
+ }
879
+ $data['options_general'] = $options_general;
880
+ $data['actual_options'] = $actual_options;
881
+
882
+ // This box can't be unselectd in the the Screen Options
883
+ add_meta_box('avhecBoxDonations',
884
+ __('Donations', 'avh-ec'),
885
+ array($this, 'metaboxDonations'),
886
+ $this->hooks['menu_general'],
887
+ 'side',
888
+ 'core');
889
+
890
+ $hide2 = '';
891
+ switch ($screen_layout_columns) {
892
+ case 2:
893
+ $width = 'width:49%;';
894
+ break;
895
+ default:
896
+ $width = 'width:98%;';
897
+ $hide2 = 'display:none;';
898
+ }
899
+
900
+ echo '<div class="wrap avhec-metabox-wrap">';
901
+ echo $this->displayIcon('index');
902
+ echo '<h2>' . 'AVH Extended Categories - ' . __('General Options', 'avh-ec') . '</h2>';
903
+ echo '<form name="avhec-generaloptions" id="avhec-generaloptions" method="POST" action="' .
904
+ admin_url('admin.php?page=avhec-general') .
905
+ '" accept-charset="utf-8" >';
906
+ wp_nonce_field('avh_ec_generaloptions');
907
+
908
+ echo ' <div id="dashboard-widgets-wrap">';
909
+ echo ' <div id="dashboard-widgets" class="metabox-holder">';
910
+ echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
911
+ do_meta_boxes($this->hooks['menu_general'], 'normal', $data);
912
+ echo " </div>";
913
+ echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n";
914
+ do_meta_boxes($this->hooks['menu_general'], 'side', $data);
915
+ echo ' </div>';
916
+ echo ' </div>';
917
+
918
+ echo '<br class="clear"/>';
919
+ echo ' </div>'; // dashboard-widgets-wrap
920
+ echo '<p class="submit"><input class="button" type="submit" name="updateoptions" value="' .
921
+ __('Save Changes', 'avhf-ec') .
922
+ '" /></p>';
923
+ echo '</form>';
924
+
925
+ echo '</div>'; // wrap
926
+
927
+ $this->printMetaboxGeneralNonces();
928
+ $this->printMetaboxJS('general');
929
+ $this->printAdminFooter();
930
+ }
931
+
932
+ /**
933
+ * Menu Page Manual Order
934
+ *
935
+ * @return void
936
+ */
937
+ public function doMenuManualOrder() {
938
+ global $screen_layout_columns;
939
+
940
+ $hide2 = '';
941
+ switch ($screen_layout_columns) {
942
+ case 2:
943
+ $width = 'width:49%;';
944
+ break;
945
+ default:
946
+ $width = 'width:98%;';
947
+ $hide2 = 'display:none;';
948
+ }
949
+
950
+ echo '<div class="wrap">';
951
+ echo $this->displayIcon('index');
952
+ echo '<h2>' . 'AVH Extended Categories - ' . __('Manually Order Categories', 'avh-ec') . '</h2>';
953
+
954
+ echo '<div class="metabox-holder">';
955
+ echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
956
+ do_meta_boxes($this->hooks['menu_manual_order'], 'normal', '');
957
+ echo ' </div>';
958
+ echo '</div>';
959
+ echo '</div>'; // wrap
960
+ echo '<div class="clear"></div>';
961
+
962
+ $this->printMetaboxGeneralNonces();
963
+ $this->printMetaboxJS('manual_order');
964
+ $this->printAdminFooter();
965
+ }
966
+
967
+ /**
968
+ * Menu Page Overview
969
+ *
970
+ * @return void
971
+ */
972
+ public function doMenuOverview() {
973
+ global $screen_layout_columns;
974
+
975
+ // This box can't be unselectd in the the Screen Options
976
+ // add_meta_box('avhecBoxAnnouncements', __('Announcements', 'avh-ec'), array ( $this, 'metaboxAnnouncements' ), $this->hooks['menu_overview'], 'side', '');
977
+ add_meta_box('avhecBoxDonations',
978
+ __('Donations', 'avh-ec'),
979
+ array($this, 'metaboxDonations'),
980
+ $this->hooks['menu_overview'],
981
+ 'side',
982
+ '');
983
+
984
+ $hide2 = '';
985
+ switch ($screen_layout_columns) {
986
+ case 2:
987
+ $width = 'width:49%;';
988
+ break;
989
+ default:
990
+ $width = 'width:98%;';
991
+ $hide2 = 'display:none;';
992
+ }
993
+
994
+ echo '<div class="wrap avhec-metabox-wrap">';
995
+ echo $this->displayIcon('index');
996
+ echo '<h2>' . 'AVH Extended Categories - ' . __('Overview', 'avh-ec') . '</h2>';
997
+ echo ' <div id="dashboard-widgets-wrap">';
998
+ echo ' <div id="dashboard-widgets" class="metabox-holder">';
999
+ echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
1000
+ do_meta_boxes($this->hooks['menu_overview'], 'normal', '');
1001
+ echo " </div>";
1002
+ echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n";
1003
+ do_meta_boxes($this->hooks['menu_overview'], 'side', '');
1004
+ echo ' </div>';
1005
+ echo ' </div>';
1006
+
1007
+ echo '<br class="clear"/>';
1008
+ echo ' </div>'; // dashboard-widgets-wrap
1009
+ echo '</div>'; // wrap
1010
+
1011
+ $this->printMetaboxGeneralNonces();
1012
+ $this->printMetaboxJS('overview');
1013
+ $this->printAdminFooter();
1014
+ }
1015
+
1016
+ /**
1017
+ * When not using AJAX, this function is called when the deletion fails.
1018
+ *
1019
+ * @param string $text
1020
+ * @param int $group_id
1021
+ *
1022
+ * @return string
1023
+ * @WordPress Filter explain_nonce_$verb-$noun
1024
+ * @see wp_explain_nonce
1025
+ */
1026
+ public function filterExplainNonceDeleteGroup($text, $group_id) {
1027
+ $group = get_term($group_id, $this->catgrp->taxonomy_name, OBJECT, 'display');
1028
+
1029
+ $return = sprintf(__('Your attempt to delete this group: &#8220;%s&#8221; has failed.'), $group->name);
1030
+
1031
+ return ($return);
1032
+ }
1033
+
1034
+ /**
1035
+ * Creates a new array for columns headers.
1036
+ * Used in print_column_headers. The filter is called from get_column_headers
1037
+ *
1038
+ * @param array $columns
1039
+ *
1040
+ * @return Array
1041
+ * @see print_column_headers, get_column_headers
1042
+ */
1043
+ public function filterManageCategoriesGroupColumns($columns) {
1044
+ $categories_group_columns = array(
1045
+ 'name' => __('Name', 'avh-ec'),
1046
+ 'slug' => __('Slug', 'avh-ec'),
1047
+ 'widget-title' => __('Widget Title', 'avh-ec'),
1048
+ 'description' => __('Description', 'avh-ec'),
1049
+ 'cat-in-group' => __('Categories in the group', 'avh-ec')
1050
+ );
1051
+
1052
+ return $categories_group_columns;
1053
+ }
1054
+
1055
+ /**
1056
+ * Adds Settings next to the plugin actions
1057
+ *
1058
+ * @WordPress Filter plugin_action_links_avh-amazon/avh-amazon.php
1059
+ *
1060
+ * @param array $links
1061
+ * @param string $file
1062
+ *
1063
+ * @return array
1064
+ */
1065
+ public function filterPluginActions($links, $file) {
1066
+ $settings_link = '<a href="admin.php?page=extended-categories-widget">' . __('Settings', 'avh-ec') . '</a>';
1067
+ array_unshift($links, $settings_link); // before other links
1068
+
1069
+ return $links;
1070
+ }
1071
+
1072
+ /**
1073
+ * Sets the amount of columns wanted for a particular screen
1074
+ *
1075
+ * @WordPress filter screen_meta_screen
1076
+ *
1077
+ * @param array $columns
1078
+ * @param string $screen
1079
+ *
1080
+ * @return array
1081
+ */
1082
+ public function filterScreenLayoutColumns($columns, $screen) {
1083
+ switch ($screen) {
1084
+ case $this->hooks['menu_overview']:
1085
+ $columns[ $this->hooks['menu_overview'] ] = 2;
1086
+ break;
1087
+ case $this->hooks['menu_general']:
1088
+ $columns[ $this->hooks['menu_general'] ] = 2;
1089
+ break;
1090
+ case $this->hooks['menu_category_groups']:
1091
+ $columns[ $this->hooks['menu_category_groups'] ] = 2;
1092
+ break;
1093
+ case $this->hooks['menu_faq']:
1094
+ $columns[ $this->hooks['menu_faq'] ] = 2;
1095
+ break;
1096
+ }
1097
+
1098
+ return $columns;
1099
+ }
1100
+
1101
+ /**
1102
+ * Get the backlink for forms
1103
+ *
1104
+ * @return string
1105
+ */
1106
+ public function getBackLink() {
1107
+ $page = basename(__FILE__);
1108
+ if (isset($_GET['page']) && ! empty($_GET['page'])) {
1109
+ $page = preg_replace('[^a-zA-Z0-9\.\_\-]', '', $_GET['page']);
1110
+ }
1111
+
1112
+ if (function_exists("admin_url")) {
1113
+ return admin_url(basename($_SERVER["PHP_SELF"])) . "?page=" . $page;
1114
+ } else {
1115
+ return $_SERVER['PHP_SELF'] . "?page=" . $page;
1116
+ }
1117
+ }
1118
+
1119
+ /**
1120
+ * Saves the association Category - Category Group fron the edit taxonomy page
1121
+ *
1122
+ * @WordPress action edit_form.
1123
+ *
1124
+ * @param int $term_id
1125
+ * @param int $tt_id
1126
+ * @param string $taxonomy
1127
+ */
1128
+ public function handleEditTerm($term_id, $tt_id, $taxonomy) {
1129
+ $tax_meta = get_option($this->core->db_options_tax_meta);
1130
+ if (isset($_POST['avhec_categorygroup'])) {
1131
+ if (term_exists($_POST['avhec_categorygroup'], $this->catgrp->taxonomy_name) !== null) {
1132
+ if ( ! isset($tax_meta[ $taxonomy ][ $term_id ]['category_group_term_id']) ||
1133
+ $tax_meta[ $taxonomy ][ $term_id ]['category_group_term_id'] != $_POST['avhec_categorygroup']
1134
+ ) {
1135
+ $tax_meta[ $taxonomy ][ $term_id ]['category_group_term_id'] = $_POST['avhec_categorygroup'];
1136
+ update_option($this->core->db_options_tax_meta, $tax_meta);
1137
+ }
1138
+ }
1139
+ }
1140
+ }
1141
+
1142
+ /**
1143
+ * Used in forms to set an option checked
1144
+ *
1145
+ * @param string $checked
1146
+ * @param string $current
1147
+ *
1148
+ * @return string
1149
+ */
1150
+ public function isChecked($checked, $current) {
1151
+ $return = '';
1152
+ if ($checked == $current) {
1153
+ $return = ' checked="checked"';
1154
+ }
1155
+
1156
+ return $return;
1157
+ }
1158
+
1159
+ public function metaboxAnnouncements() {
1160
+ $php5 = version_compare('5.2', phpversion(), '<');
1161
+ echo '<div class="p">';
1162
+ echo '<span class="b">' . __('PHP4 Support', 'avh-ec') . '</span><br />';
1163
+ echo __('The next major release of the plugin will no longer support PHP4.', 'avh-ec') . '<br />';
1164
+ echo __('It will be written for PHP 5.2 and ', 'avh-ec');
1165
+ if ($php5) {
1166
+ echo __('your blog already runs the needed PHP version. When the new release comes out you can safely update.',
1167
+ 'avh-ec') . '<br />';
1168
+ } else {
1169
+ echo __('your blog still runs PHP4. When the new release comes out you can not use it.', 'avh-ec') .
1170
+ '<br />';
1171
+ echo __('I don\'t have a timeline for the next version but consider contacting your host if PHP 5.2 is available.',
1172
+ 'avh-ec') . '<br />';
1173
+ echo __('If your hosts doesn\'t offer PHP 5.2 you might want to consider switching hosts.', 'avh-ec') .
1174
+ '<br />';
1175
+ echo __('A host to consider is ', 'avh-ec') .
1176
+ '<a href="http://www.lunarpages.com/id/pdoes" target="_blank">Lunarpages</a>';
1177
+ echo __('I run my personal blog there and I am very happy with their services. You can get an account with unlimited bandwidth, storage and much more for a low price.',
1178
+ 'avh-ec');
1179
+ }
1180
+ echo '</div>';
1181
+ }
1182
+
1183
+ /**
1184
+ * Metabox for Adding a group
1185
+ *
1186
+ * @param array $data
1187
+ */
1188
+ public function metaboxCategoryGroupAdd($data) {
1189
+ echo '<form name="avhec-addgroup" id="avhec-addgroup" method="POST" action="' .
1190
+ $this->getBackLink() .
1191
+ '" accept-charset="utf-8" >';
1192
+ wp_nonce_field('avh_ec_addgroup');
1193
+ echo $this->printOptions($data['add']['form'], $data['add']['data']);
1194
+ echo '<p class="submit"><input class="button" type="submit" name="addgroup" value="' .
1195
+ __('Add group', 'avh-ec') .
1196
+ '" /></p>';
1197
+ echo '</form>';
1198
+ }
1199
+
1200
+ /**
1201
+ * Metabox Category Group Edit
1202
+ *
1203
+ * @param array $data
1204
+ */
1205
+ public function metaboxCategoryGroupEdit($data) {
1206
+ echo '<form name="avhec-editgroup" id="avhec-editgroup" method="POST" action="' .
1207
+ $this->getBackLink() .
1208
+ '" accept-charset="utf-8" >';
1209
+ wp_nonce_field('avh_ec_editgroup');
1210
+ echo $this->printOptions($data['edit']['form'], $data['edit']['data']);
1211
+ echo '<input type="hidden" value="' .
1212
+ $data['edit']['data']['edit']['group_id'] .
1213
+ '" name="avhec-group_id" id="avhec-group_id">';
1214
+ echo '<p class="submit"><input class="button" type="submit" name="editgroup" value="' .
1215
+ __('Update group', 'avh-ec') .
1216
+ '" /></p>';
1217
+ echo '</form>';
1218
+ }
1219
+
1220
+ /**
1221
+ * Metabox for showing the groups as a list
1222
+ *
1223
+ * @param array $data
1224
+ */
1225
+ public function metaboxCategoryGroupList($data) {
1226
+ echo '<form id="posts-filter" action="" method="get">';
1227
+
1228
+ echo '<div class="clear"></div>';
1229
+
1230
+ echo '<table class="widefat fixed" cellspacing="0">';
1231
+ echo '<thead>';
1232
+ echo '<tr>';
1233
+ print_column_headers('categories_group');
1234
+ echo '</tr>';
1235
+ echo '</thead>';
1236
+
1237
+ echo '<tfoot>';
1238
+ echo '<tr>';
1239
+ print_column_headers('categories_group', false);
1240
+ echo '</tr>';
1241
+ echo '</tfoot>';
1242
+
1243
+ echo '<tbody id="the-list" class="list:group">';
1244
+ $this->printCategoryGroupRows();
1245
+ echo '</tbody>';
1246
+ echo '</table>';
1247
+
1248
+ echo '<br class="clear" />';
1249
+ echo '</form>';
1250
+ // echo '</div>';
1251
+ }
1252
+
1253
+ /**
1254
+ * Metabox Category Group Special pages
1255
+ *
1256
+ * @param array $data
1257
+ */
1258
+ public function metaboxCategoryGroupSpecialPages($data) {
1259
+ echo '<form name="avhec-specialpagesgroup" id="avhec-specialpagesgroup" method="POST" action="' .
1260
+ $this->getBackLink() .
1261
+ '" accept-charset="utf-8" >';
1262
+ wp_nonce_field('avh_ec_specialpagesgroup');
1263
+ echo $this->printOptions($data['sp']['form'], $data['sp']['data']);
1264
+ echo '<p class="submit"><input class="button" type="submit" name="spgroup" value="' .
1265
+ __('Save settings', 'avh-ec') .
1266
+ '" /></p>';
1267
+ echo '</form>';
1268
+ }
1269
+
1270
+ // ############ Admin WP Helper ##############
1271
+
1272
+ /**
1273
+ * Donation Metabox
1274
+ */
1275
+ public function metaboxDonations() {
1276
+ echo '<div class="p">';
1277
+ echo __('If you enjoy this plug-in please consider a donation. There are several ways you can show your appreciation.',
1278
+ 'avh-ec');
1279
+ echo '</div>';
1280
+
1281
+ echo '<div class="p">';
1282
+ echo '<span class="b">Amazon</span><br />';
1283
+ echo __('If you decide to buy something from Amazon click the button.', 'avh-ec') . '</span><br />';
1284
+ echo '<a href="https://www.amazon.com/?tag=petervanderdoes-20" target="_blank" title="Amazon Homepage"><img alt="Amazon Button" src="' .
1285
+ $this->core->info['graphics_url'] .
1286
+ '/us_banner_logow_120x60.gif" /></a>';
1287
+ echo '</div>';
1288
+
1289
+ echo '<div class="p">';
1290
+ echo __('You can send me something from my ', 'avh-ec') .
1291
+ '<a href="http://www.amazon.com/registry/wishlist/1U3DTWZ72PI7W?tag=petervanderdoes-20">' .
1292
+ __('Amazon Wish List', 'avh-ec') .
1293
+ '</a>';
1294
+ echo '</div>';
1295
+
1296
+ echo '<div class="p">';
1297
+ echo '<span class="b">' . __('Through Paypal.', 'avh-ec') . '</span><br />';
1298
+ echo __('Click on the Donate button and you will be directed to Paypal where you can make your donation and you don\'t need to have a Paypal account to make a donation.',
1299
+ 'avh-ec') . '<br />';
1300
+ echo '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=S85FXJ9EBHAF2&lc=US&item_name=AVH%20Plugins&item_number=fdas&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted" target="_blank" title="Donate">';
1301
+ echo '<img src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" alt="Donate"/></a>';
1302
+ echo '</div>';
1303
+ }
1304
+
1305
+ /**
1306
+ * *
1307
+ * F.A.Q Metabox
1308
+ */
1309
+ public function metaboxFAQ() {
1310
+ echo '<div class="p">';
1311
+ echo '<span class="b">' . __('What about support?', 'avh-ec') . '</span><br />';
1312
+ echo __('I created a <a href="http://forums.avirtualhome.com" target="_blank">support site</a> where you can ask questions or request features.',
1313
+ 'avh-ec') . '<br />';
1314
+ echo '</div>';
1315
+
1316
+ echo '<div class="p">';
1317
+ echo '<span class="b">' . __('What is depth selection?', 'avh-ec') . '</span><br />';
1318
+ echo __('Starting with version 2.0 and WordPress 2.8 you can select how many levels deep you want to show your categories. This option only works when you select Show Hierarchy as well.',
1319
+ 'avh-ec') . '<br /><br />';
1320
+ echo __('Here is how it works: Say you have 5 top level categories and each top level has a number of children. You could manually select all the Top Level categories you want to show but now you can do the following:',
1321
+ 'avh-ec') . '<br />';
1322
+ echo __('You select to display all categories, select to Show hierarchy and select how many levels you want to show, in this case Toplevel only.',
1323
+ 'avh-ec') . '<br />';
1324
+ echo '</div>';
1325
+
1326
+ echo '<div class="p">';
1327
+ echo '<span class="b">' . __('Multiple Category Groups', 'avh-ec') . '</span><br />';
1328
+ echo __('The following is an explanation how assigning multiple groups to page/post works.', 'avh-ec') .
1329
+ '<br /><br />';
1330
+ echo __('Lets say you have the following groups:', 'avh-ec');
1331
+ echo '<ul>';
1332
+ echo '<li>' . __('Free Time', 'avh-ec') . '</li>';
1333
+ echo '<li>' . __('Theater', 'avh-ec') . '</li>';
1334
+ echo '<li>' . __('Movie', 'avh-ec') . '</li>';
1335
+ echo '<li>' . __('Music', 'avh-ec') . '</li>';
1336
+ echo '</ul>';
1337
+ echo __('Setup several Category Group widgets and associated each widget with one or more groups.', 'avh-ec') .
1338
+ '<br />';
1339
+ echo __('Widget 1 has association with Free Time', 'avh-ec') . '<br />';
1340
+ echo __('Widget 2 has association with Theater, Movie and Music', 'avh-ec') . '<br />';
1341
+ echo __('Widget 3 has association with Theater, Movie and Music', 'avh-ec') . '<br /><br />';
1342
+ echo __('Page has associations the groups Free Time and Theater', 'avh-ec');
1343
+ echo '<ul>';
1344
+ echo '<li>' . __('Widget 1: Shows categories of the Free Time group', 'avh-ec') . '</li>';
1345
+ echo '<li>' . __('Widget 2: Shows categories of the Theater group.', 'avh-ec') . '</li>';
1346
+ echo '<li>' . __('Widget 3: Not displayed', 'avh-ec') . '</li>';
1347
+ echo '</ul>';
1348
+ echo __('Page has associations the group Movie.', 'avh-ec');
1349
+ echo '<ul>';
1350
+ echo '<li>' . __('Widget 1: Not displayed', 'avh-ec') . '</li>';
1351
+ echo '<li>' . __('Widget 2: Shows categories of the Movie group.', 'avh-ec') . '</li>';
1352
+ echo '<li>' . __('Widget 3: Not displayed', 'avh-ec') . '</li>';
1353
+ echo '</ul>';
1354
+ echo __('Page has associations the groups Free Time, Movie and Music', 'avh-ec');
1355
+ echo '<ul>';
1356
+ echo '<li>' . __('Widget 1: Shows categories of the Free Time group', 'avh-ec') . '</li>';
1357
+ echo '<li>' . __('Widget 2: Shows categories of the Movie or Music group.', 'avh-ec') . '</li>';
1358
+ echo '<li>' . __('Widget 3: Shows categories of the Music or Movie group.', 'avh-ec') . '</li>';
1359
+ echo '</ul>';
1360
+ echo __('Whether Widget 2 shows Movie or Music depends on the creation order of groups. If Widget 2 shows Movie, Widget 3 will show Music but if Widget 2 shows Music, Widget 3 will show Movie.',
1361
+ 'avh-ec') . '<br />';
1362
+ echo '</div>';
1363
+ }
1364
+
1365
+ /**
1366
+ * Displays the Manual Order metabox.
1367
+ *
1368
+ * @author Andrew Charlton - original
1369
+ * @author Peter van der Does - modifications
1370
+ */
1371
+ public function metaboxManualOrder() {
1372
+ global $wpdb;
1373
+
1374
+ $parentID = 0;
1375
+
1376
+ if (isset($_POST['btnSubCats'])) {
1377
+ $parentID = $_POST['cats'];
1378
+ } elseif (isset($_POST['hdnParentID'])) {
1379
+ $parentID = $_POST['hdnParentID'];
1380
+ }
1381
+
1382
+ if (isset($_POST['btnReturnParent'])) {
1383
+ $parentsParent = $wpdb->get_row($wpdb->prepare("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = %d",
1384
+ $_POST['hdnParentID']),
1385
+ ARRAY_N);
1386
+ $parentID = $parentsParent[0];
1387
+ }
1388
+
1389
+ $success = "";
1390
+ if (isset($_POST['btnOrderCats'])) {
1391
+ if (isset($_POST['hdnManualOrder']) && $_POST['hdnManualOrder'] != "") {
1392
+
1393
+ $manualOrder = $_POST['hdnManualOrder'];
1394
+ $IDs = explode(",", $manualOrder);
1395
+ $result = count($IDs);
1396
+
1397
+ for ($i = 0; $i < $result; $i ++) {
1398
+ $str = str_replace("id_", "", $IDs[ $i ]);
1399
+ $wpdb->query($wpdb->prepare("UPDATE $wpdb->terms SET avhec_term_order = %d WHERE term_id =%d",
1400
+ $i,
1401
+ $str));
1402
+ }
1403
+
1404
+ $success = '<div id="message" class="updated fade"><p>' .
1405
+ __('Manual order of the categories successfully updated.', 'avh-ec') .
1406
+ '</p></div>';
1407
+ } else {
1408
+ $success = '<div id="message" class="updated fade"><p>' .
1409
+ __('An error occured, order has not been saved.', 'avh-ec') .
1410
+ '</p></div>';
1411
+ }
1412
+ }
1413
+
1414
+ $subCategories = "";
1415
+ $results = $wpdb->get_results($wpdb->prepare("SELECT t.term_id, t.name FROM $wpdb->term_taxonomy tt, $wpdb->terms t, $wpdb->term_taxonomy tt2 WHERE tt.parent = %d AND tt.taxonomy = 'category' AND t.term_id = tt.term_id AND tt2.parent = tt.term_id GROUP BY t.term_id, t.name HAVING COUNT(*) > 0 ORDER BY t.avhec_term_order ASC",
1416
+ $parentID));
1417
+ foreach ($results as $row) {
1418
+ $subCategories .= "<option value='$row->term_id'>$row->name</option>";
1419
+ }
1420
+
1421
+ echo '<div class="wrap">';
1422
+ echo '<form name="frmMyCatOrder" method="post" action="">';
1423
+ echo $success;
1424
+
1425
+ echo '<h4>';
1426
+ _e('Order the categories', 'avh-ec');
1427
+ if ($parentID == 0) {
1428
+ echo ' at the Toplevel';
1429
+ } else {
1430
+ $categories = get_category_parents($parentID, false, ' » ');
1431
+ echo ' in the category ' . trim($categories, ' » ');
1432
+ }
1433
+ echo '</h4>';
1434
+ echo '<span class="description">';
1435
+ _e('Order the categories on this level by dragging and dropping them into the desired order.', 'avh-ec');
1436
+ echo '</span>';
1437
+ echo '<ul id="avhecManualOrder">';
1438
+ $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->terms t inner join $wpdb->term_taxonomy tt on t.term_id = tt.term_id WHERE taxonomy = 'category' and parent = %d ORDER BY avhec_term_order ASC",
1439
+ $parentID));
1440
+ foreach ($results as $row) {
1441
+ echo "<li id='id_$row->term_id' class='lineitem menu-item-settings'>" . __($row->name) . "</li>";
1442
+ }
1443
+ echo '</ul>';
1444
+ echo '<input type="submit" name="btnOrderCats" id="btnOrderCats" class="button-primary" value="' .
1445
+ __('Save Order', 'avh-ec') .
1446
+ '" onclick="javascript:orderCats(); return true;" />';
1447
+
1448
+ if ($parentID != 0) {
1449
+ echo "<input type='submit' class='button' id='btnReturnParent' name='btnReturnParent' value='" .
1450
+ __('Return to parent category', 'avh-ec') .
1451
+ "' />";
1452
+ }
1453
+
1454
+ echo '<strong id="updateText"></strong><br /><br />';
1455
+ if ($subCategories != "") {
1456
+
1457
+ echo '<h4>';
1458
+ _e('Select Subcategory', 'avh-ec');
1459
+ echo '</h4>';
1460
+ echo '<select id="cats" name="cats">';
1461
+ echo $subCategories;
1462
+
1463
+ echo '</select><input type="submit" name="btnSubCats" class="button" id="btnSubCats" value="' .
1464
+ __('Select', 'avh-ec') .
1465
+ '" />';
1466
+ echo '<span class="description">';
1467
+ _e('Choose a category from the drop down to order the subcategories in that category.', 'avh-ec');
1468
+ echo '</span>';
1469
+ }
1470
+
1471
+ echo '<input type="hidden" id="hdnManualOrder" name="hdnManualOrder" />';
1472
+ echo '<input type="hidden" id="hdnParentID" name="hdnParentID" value="' . $parentID . '" /></form>';
1473
+ echo '</div>';
1474
+ }
1475
+
1476
+ /**
1477
+ * Options Metabox
1478
+ *
1479
+ * @param array $data
1480
+ */
1481
+ public function metaboxOptions($data) {
1482
+ echo $this->printOptions($data['options_general'], $data['actual_options']);
1483
+ }
1484
+
1485
+ /**
1486
+ * Translation Metabox
1487
+ */
1488
+ public function metaboxTranslation() {
1489
+ $locale = apply_filters('plugin_locale', get_locale(), 'avh-ec');
1490
+ $available_locale['cs_CZ'] = array('Czech - Čeština', 0);
1491
+ $available_locale['nl_NL'] = array('Dutch - Nederlands', 0);
1492
+ $available_locale['de_DE'] = array('German - Deutsch', 0);
1493
+ $available_locale['el'] = array('Greek - Čeština', 0);
1494
+ $available_locale['id_ID'] = array('Indonesian - Bahasa Indonesia - Čeština', 0);
1495
+ $available_locale['it_IT'] = array('Italian - Italiano', 1);
1496
+ $available_locale['ru_RU'] = array('Russian — Русский', 0);
1497
+ $available_locale['es_ES'] = array('Spanish - Español', 0);
1498
+ $available_locale['sv_SE'] = array('Swedish - Svenska', 0);
1499
+ $available_locale['tr'] = array('Turkish - Türkçe', 0);
1500
+
1501
+ echo '<div class="p">';
1502
+ echo __('This plugin is translated in several languages. Some of the languages might be incomplete. Please help to complete these translations or add a new language.',
1503
+ 'avh-ec') . '<br />';
1504
+
1505
+ echo '</div>';
1506
+
1507
+ echo '<div class="p">';
1508
+ echo '<span class="b">' . __('Available Languages', 'avh-ec') . '</span>';
1509
+ echo '<ul>';
1510
+ foreach ($available_locale as $key => $value) {
1511
+ echo '<li>';
1512
+ $complete = ($value[1] == 1 ? 'Complete' : 'Incomplete');
1513
+ echo $value[0] . ' (' . $key . ') - ' . $complete;
1514
+ echo '</li>';
1515
+ }
1516
+ echo '</ul>';
1517
+ echo '</div>';
1518
+
1519
+ echo '<div class="p">';
1520
+ if ('en_US' != $locale & ( ! array_key_exists($locale, $available_locale))) {
1521
+ echo 'Currently the plugin is not available in your language (' .
1522
+ $locale .
1523
+ '). We\'re in the middle of changing the way you can help with translations. Keep an eye on the <a href="http:///blog.avirtualhome.com">website</a> for the announcement.';
1524
+ } else {
1525
+ echo 'We\'re in the middle of changing the way you can help with translations. Keep an eye on the <a href="http:///blog.avirtualhome.com">website</a> for the announcement.';
1526
+ }
1527
+ echo '</div>';
1528
+ }
1529
+
1530
+ /**
1531
+ * Display plugin Copyright
1532
+ */
1533
+ public function printAdminFooter() {
1534
+ echo '<p class="footer_avhec">';
1535
+ printf('&copy; Copyright %d <a href="http://blog.avirtualhome.com/" title="My Thoughts">Peter van der Does</a> | AVH Extended Categories Version %s',
1536
+ date('Y'),
1537
+ $this->core->version);
1538
+ echo '</p>';
1539
+ }
1540
+
1541
+ /**
1542
+ * Displays all the information of a group in a row
1543
+ * Adds inline link for delete and/or edit.
1544
+ *
1545
+ * @param int $group_term_id
1546
+ * @param int $group_term_taxonomy_id
1547
+ *
1548
+ * @return string
1549
+ */
1550
+ public function printCategoryGroupRow($group_term_id, $group_term_taxonomy_id) {
1551
+ static $row_class = '';
1552
+
1553
+ $group = get_term($group_term_id, $this->catgrp->taxonomy_name, OBJECT, 'display');
1554
+
1555
+ $no_edit[ $this->catgrp->getTermIDBy('slug', 'all') ] = 0;
1556
+ $no_delete[ $this->catgrp->getTermIDBy('slug', 'all') ] = 0;
1557
+
1558
+ if (current_user_can('manage_categories')) {
1559
+ $actions = array();
1560
+ if ( ! array_key_exists($group->term_id, $no_edit)) {
1561
+ $edit_link = "admin.php?page=avhec-grouped&amp;action=edit&amp;group_ID=$group->term_id";
1562
+ $edit = "<a class='row-title' href='$edit_link' title='" .
1563
+ esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $group->name)) .
1564
+ "'>" .
1565
+ esc_attr($group->name) .
1566
+ '</a><br />';
1567
+
1568
+ $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
1569
+ } else {
1570
+ $edit = esc_attr($group->name);
1571
+ }
1572
+ if ( ! (array_key_exists($group->term_id, $no_delete))) {
1573
+ $actions['delete'] = "<a class='delete:the-list:group-$group->term_id submitdelete' href='" .
1574
+ wp_nonce_url("admin.php?page=avhec-grouped&amp;action=delete&amp;group_ID=$group->term_id",
1575
+ 'delete-avhecgroup_' . $group->term_id) .
1576
+ "'>" .
1577
+ __('Delete') .
1578
+ "</a>";
1579
+ }
1580
+ $action_count = count($actions);
1581
+ $i = 0;
1582
+ $edit .= '<div class="row-actions">';
1583
+ foreach ($actions as $action => $link) {
1584
+ ++ $i;
1585
+ ($i == $action_count) ? $sep = '' : $sep = ' | ';
1586
+ $edit .= "<span class='$action'>$link$sep</span>";
1587
+ }
1588
+ $edit .= '</div>';
1589
+ } else {
1590
+ $edit = $group->name;
1591
+ }
1592
+
1593
+ $row_class = 'alternate' == $row_class ? '' : 'alternate';
1594
+ $qe_data = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit');
1595
+
1596
+ $output = "<tr id='group-$group->term_id' class='iedit $row_class'>";
1597
+
1598
+ $columns = get_column_headers('categories_group');
1599
+ $hidden = get_hidden_columns('categories_group');
1600
+ foreach ($columns as $column_name => $column_display_name) {
1601
+ $class = 'class="' . $column_name . ' column-' . $column_name . '"';
1602
+
1603
+ $style = '';
1604
+ if (in_array($column_name, $hidden)) {
1605
+ $style = ' style="display:none;"';
1606
+ }
1607
+
1608
+ $attributes = $class . $style;
1609
+
1610
+ switch ($column_name) {
1611
+ case 'cb':
1612
+ $output .= '<th scope="row" class="check-column">';
1613
+ if ( ! (array_key_exists($group->term_id, $no_delete))) {
1614
+ $output .= '<input type="checkbox" name="delete[]" value="' . $group->term_id . '" />';
1615
+ } else {
1616
+ $output .= "&nbsp;";
1617
+ }
1618
+ $output .= '</th>';
1619
+ break;
1620
+ case 'name':
1621
+ $output .= '<td ' . $attributes . '>' . $edit;
1622
+ $output .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">';
1623
+ $output .= '<div class="name">' . $qe_data->name . '</div>';
1624
+ $output .= '<div class="slug">' . apply_filters('editable_slug', $qe_data->slug) . '</div>';
1625
+ $output .= '</div></td>';
1626
+ break;
1627
+ case 'widget-title':
1628
+ $title = $this->catgrp->getWidgetTitleForGroup($group->term_id);
1629
+ if ( ! $title) {
1630
+ $title = "&nbsp;";
1631
+ }
1632
+ $output .= '<td ' . $attributes . '>' . $title . '</td>';
1633
+ break;
1634
+
1635
+ case 'description':
1636
+ $output .= '<td ' . $attributes . '>' . $qe_data->description . '</td>';
1637
+ break;
1638
+ case 'slug':
1639
+ $output .= "<td $attributes>" . apply_filters('editable_slug', $qe_data->slug) . "</td>";
1640
+ break;
1641
+ case 'cat-in-group':
1642
+ $cats = $this->catgrp->getCategoriesFromGroup($group_term_id);
1643
+ $catname = array();
1644
+ foreach ($cats as $cat_id) {
1645
+ $catname[] = get_cat_name($cat_id);
1646
+ }
1647
+ natsort($catname);
1648
+ $cat = implode(', ', $catname);
1649
+ $output .= '<td ' . $attributes . '>' . $cat . '</td>';
1650
+ break;
1651
+ }
1652
+ }
1653
+ $output .= '</tr>';
1654
+
1655
+ return $output;
1656
+ }
1657
+
1658
+ /**
1659
+ * Print all Category Group rows
1660
+ *
1661
+ * @uses printCategoryGroupRow
1662
+ */
1663
+ public function printCategoryGroupRows() {
1664
+ $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false));
1665
+
1666
+ foreach ($cat_groups as $group) {
1667
+ if ('none' != $group->slug) {
1668
+ echo $this->printCategoryGroupRow($group->term_id, $group->term_taxonomy_id);
1669
+ }
1670
+ }
1671
+ }
1672
+
1673
+ /**
1674
+ * Prints the general nonces, used by the AJAX
1675
+ */
1676
+ public function printMetaboxGeneralNonces() {
1677
+ echo '<form style="display:none" method="get" action="">';
1678
+ echo '<p>';
1679
+ wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1680
+ wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1681
+ echo '</p>';
1682
+ echo '</form>';
1683
+ }
1684
+
1685
+ /**
1686
+ * Print the Metabox JS for toggling closed and open
1687
+ *
1688
+ * @param int $boxid
1689
+ */
1690
+ public function printMetaboxJS($boxid) {
1691
+ $a = $this->hooks[ 'menu_' . $boxid ];
1692
+ echo '<script type="text/javascript">' . "\n";
1693
+ echo ' //<![CDATA[' . "\n";
1694
+ echo ' jQuery(document).ready( function($) {' . "\n";
1695
+ echo ' $(\'.if-js-closed\').removeClass(\'if-js-closed\').addClass(\'closed\');' . "\n";
1696
+ echo ' // postboxes setup' . "\n";
1697
+ echo ' postboxes.add_postbox_toggles(\'' . $a . '\');' . "\n";
1698
+ echo ' });' . "\n";
1699
+ echo ' //]]>' . "\n";
1700
+ echo '</script>';
1701
+ }
1702
+
1703
+ /**
1704
+ * Ouput formatted options
1705
+ *
1706
+ * @param array $option_data
1707
+ * @param array $option_actual
1708
+ *
1709
+ * @return string
1710
+ */
1711
+ public function printOptions($option_data, $option_actual) {
1712
+ // Generate output
1713
+ $output = '';
1714
+ $output .= "\n" . '<table class="form-table avhec-options">' . "\n";
1715
+ foreach ($option_data as $option) {
1716
+ $section = substr($option[0], strpos($option[0], '[') + 1);
1717
+ $section = substr($section, 0, strpos($section, ']['));
1718
+ $option_key = rtrim($option[0], ']');
1719
+ $option_key = substr($option_key, strpos($option_key, '][') + 2);
1720
+ // Helper
1721
+ if ($option[2] == 'helper') {
1722
+ $output .= '<tr style="vertical-align: top;"><td class="helper" colspan="2">' .
1723
+ wp_filter_post_kses($option[4]) .
1724
+ '</td></tr>' .
1725
+ "\n";
1726
+ continue;
1727
+ }
1728
+ switch ($option[2]) {
1729
+ case 'checkbox':
1730
+ $input_type = '<input type="checkbox" id="' .
1731
+ esc_attr($option[0]) .
1732
+ '" name="' .
1733
+ esc_attr($option[0]) .
1734
+ '" value="' .
1735
+ esc_attr($option[3]) .
1736
+ '" ' .
1737
+ $this->isChecked('1', $option_actual[ $section ][ $option_key ]) .
1738
+ ' />' .
1739
+ "\n";
1740
+ $explanation = $option[4];
1741
+ break;
1742
+ case 'dropdown':
1743
+ $selvalue = $option[3];
1744
+ $seltext = $option[4];
1745
+ $seldata = '';
1746
+ foreach ((array) $selvalue as $key => $sel) {
1747
+ $seldata .= '<option value="' .
1748
+ esc_attr($sel) .
1749
+ '" ' .
1750
+ (($option_actual[ $section ][ $option_key ] == $sel) ? 'selected="selected"' : '') .
1751
+ ' >' .
1752
+ esc_html(ucfirst($seltext[ $key ])) .
1753
+ '</option>' .
1754
+ "\n";
1755
+ }
1756
+ $input_type = '<select id="' .
1757
+ esc_attr($option[0]) .
1758
+ '" name="' .
1759
+ esc_attr($option[0]) .
1760
+ '">' .
1761
+ $seldata .
1762
+ '</select>' .
1763
+ "\n";
1764
+ $explanation = $option[5];
1765
+ break;
1766
+ case 'text-color':
1767
+ $input_type = '<input type="text" ' .
1768
+ (($option[3] > 1) ? ' style="width: 95%" ' : '') .
1769
+ 'id="' .
1770
+ esc_attr($option[0]) .
1771
+ '" name="' .
1772
+ esc_attr($option[0]) .
1773
+ '" value="' .
1774
+ esc_attr($option_actual[ $section ][ $option_key ]) .
1775
+ '" size="' .
1776
+ esc_attr($option[3]) .
1777
+ '" /><div class="box_color ' .
1778
+ esc_attr($option[0]) .
1779
+ '"></div>' .
1780
+ "\n";
1781
+ $explanation = $option[4];
1782
+ break;
1783
+ case 'textarea':
1784
+ $input_type = '<textarea rows="' .
1785
+ esc_attr($option[5]) .
1786
+ '" ' .
1787
+ (($option[3] > 1) ? ' style="width: 95%" ' : '') .
1788
+ 'id="' .
1789
+ esc_attr($option[0]) .
1790
+ '" name="' .
1791
+ esc_attr($option[0]) .
1792
+ '" size="' .
1793
+ esc_attr($option[3]) .
1794
+ '" />' .
1795
+ $option_actual[ $section ][ $option_key ] .
1796
+ '</textarea>';
1797
+ $explanation = $option[4];
1798
+ break;
1799
+ case 'catlist':
1800
+ ob_start();
1801
+ echo '<div id="avhec-catlist">';
1802
+ echo '<ul>';
1803
+ wp_category_checklist(0, 0, $option_actual[ $section ][ $option_key ]);
1804
+ echo '</ul>';
1805
+ echo '</div>';
1806
+ $input_type = ob_get_contents();
1807
+ ob_end_clean();
1808
+ $explanation = $option[4];
1809
+ break;
1810
+ case 'text':
1811
+ default:
1812
+ $input_type = '<input type="text" ' .
1813
+ (($option[3] > 1) ? ' style="width: 95%" ' : '') .
1814
+ 'id="' .
1815
+ esc_attr($option[0]) .
1816
+ '" name="' .
1817
+ esc_attr($option[0]) .
1818
+ '" value="' .
1819
+ esc_attr($option_actual[ $section ][ $option_key ]) .
1820
+ '" size="' .
1821
+ esc_attr($option[3]) .
1822
+ '" />' .
1823
+ "\n";
1824
+ $explanation = $option[4];
1825
+ break;
1826
+ }
1827
+ // Additional Information
1828
+ $extra = '';
1829
+ if ($explanation) {
1830
+ $extra = '<br /><span class="description">' . wp_filter_kses($explanation) . '</span>' . "\n";
1831
+ }
1832
+ // Output
1833
+ $output .= '<tr style="vertical-align: top;"><th align="left" scope="row"><label for="' .
1834
+ esc_attr($option[0]) .
1835
+ '">' .
1836
+ wp_filter_kses($option[1]) .
1837
+ '</label></th><td>' .
1838
+ $input_type .
1839
+ ' ' .
1840
+ $extra .
1841
+ '</td></tr>' .
1842
+ "\n";
1843
+ }
1844
+ $output .= '</table>' . "\n";
1845
+
1846
+ return $output;
1847
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1848
  }
4.2/class/avh-ec.category-group.php CHANGED
@@ -5,516 +5,478 @@
5
  *
6
  * @author Peter van der Does
7
  */
8
- class AVH_EC_Category_Group
9
- {
10
- public $db_options_widget_titles;
11
- public $options_widget_titles;
12
- /**
13
- * Taxonomy name
14
- *
15
- * @var string
16
- */
17
- public $taxonomy_name;
18
- public $widget_done_catgroup;
19
-
20
- /**
21
- * PHP5 Constructor
22
- * Init the Database Abstraction layer
23
- */
24
- public function __construct()
25
- {
26
- global $wpdb;
27
-
28
- register_shutdown_function(array($this, '__destruct'));
29
-
30
- /**
31
- * Taxonomy name
32
- *
33
- * @var string
34
- */
35
- $this->taxonomy_name = 'avhec_catgroup';
36
-
37
- $this->db_options_widget_titles = 'avhec_widget_titles';
38
- // add DB pointer
39
- $wpdb->avhec_cat_group = $wpdb->prefix . 'avhec_category_groups';
40
-
41
- /**
42
- * Create the table if it doesn't exist.
43
- */
44
- if ($wpdb->get_var('show tables like \'' . $wpdb->avhec_cat_group . '\'') != $wpdb->avhec_cat_group) {
45
- add_action(
46
- 'init',
47
- array($this, 'doCreateTable'),
48
- 2
49
- ); // Priority needs to be the same as the Register Taxonomy
50
- }
51
- add_action(
52
- 'init',
53
- array($this, 'doRegisterTaxonomy'),
54
- 2
55
- ); // Priority for registering custom taxonomies is +1 over the creation of the initial taxonomies
56
- add_action('init', array($this, 'doSetupOptions'));
57
-
58
- add_action('admin_init', array($this, 'addMetaBoxes'));
59
- }
60
-
61
- /**
62
- * PHP5 style destructor and will run when database object is destroyed.
63
- *
64
- * @return bool Always true
65
- */
66
- public function __destruct()
67
- {
68
- return true;
69
- }
70
-
71
- /**
72
- * Add the metaboxes for the pots and page pages.
73
- *
74
- * @WordPress action admin_init
75
- */
76
- public function addMetaBoxes()
77
- {
78
- add_meta_box(
79
- $this->taxonomy_name . 'div',
80
- __('Category Groups', 'avh-ec'),
81
- 'post_categories_meta_box',
82
- 'post',
83
- 'side',
84
- 'core',
85
- array('taxonomy' => $this->taxonomy_name)
86
- );
87
- add_meta_box(
88
- $this->taxonomy_name . 'div',
89
- __('Category Groups', 'avh-ec'),
90
- 'post_categories_meta_box',
91
- 'page',
92
- 'side',
93
- 'core',
94
- array('taxonomy' => $this->taxonomy_name)
95
- );
96
- }
97
-
98
- /**
99
- * Create Table
100
- *
101
- * @WordPress action init
102
- */
103
- public function doCreateTable()
104
- {
105
- global $wpdb;
106
-
107
- // Setup the DB Tables
108
- $charset_collate = '';
109
-
110
- if (!empty($wpdb->charset)) {
111
- $charset_collate = 'DEFAULT CHARACTER SET ' . $wpdb->charset;
112
- }
113
- if (!empty($wpdb->collate)) {
114
- $charset_collate .= ' COLLATE ' . $wpdb->collate;
115
- }
116
-
117
- $sql = 'CREATE TABLE `' .
118
- $wpdb->avhec_cat_group .
119
- '` ( `group_term_id` BIGINT(20) UNSIGNED NOT null DEFAULT 0, `term_id` BIGINT(20) UNSIGNED NOT null DEFAULT 0, PRIMARY KEY (`group_term_id`, `term_id`) )' .
120
- $charset_collate .
121
- ';';
122
-
123
- $result = $wpdb->query($sql);
124
- }
125
-
126
- /**
127
- * Deletes the given category from all groups
128
- *
129
- * @param int $category_id
130
- */
131
- public function doDeleteCategoryFromGroup($category_id)
132
- {
133
- global $wpdb;
134
- $result = $wpdb->query(
135
- $wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE term_id=%d', $category_id)
136
- );
137
- }
138
-
139
- /**
140
- * Deletes a group
141
- *
142
- * @param int $group_id
143
- *
144
- * @return bool|\WP_Error
145
- */
146
- public function doDeleteGroup($group_id)
147
- {
148
- global $wpdb;
149
-
150
- $group = $this->getGroup($group_id);
151
- $result = $wpdb->query(
152
- $wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE group_term_id=%d', $group_id)
153
- );
154
- $this->doDeleteWidgetTitle($group_id);
155
- $return = wp_delete_term($group->term_id, $this->taxonomy_name);
156
-
157
- return ($return);
158
- }
159
-
160
- /**
161
- * Delete the Widget Title for a group
162
- *
163
- * @param int $group_id
164
- */
165
- public function doDeleteWidgetTitle($group_id)
166
- {
167
- if (isset($this->options_widget_titles[$group_id])) {
168
- unset($this->options_widget_titles[$group_id]);
169
- }
170
- update_option($this->db_options_widget_titles, $this->options_widget_titles);
171
- }
172
-
173
- /**
174
- * Inserts a new group
175
- *
176
- * @param string $term
177
- * @param array $args
178
- * @param string $widget_title
179
- *
180
- * @return int
181
- */
182
- public function doInsertGroup($term, $args = array(), $widget_title = '')
183
- {
184
- $row = wp_insert_term($term, $this->taxonomy_name, $args);
185
- $this->setWidgetTitleForGroup($term, $widget_title);
186
-
187
- return ($row['term_id']);
188
- }
189
-
190
- /**
191
- * Setup Group Categories Taxonomy
192
- *
193
- * @WordPress action init
194
- */
195
- public function doRegisterTaxonomy()
196
- {
197
- /**
198
- * As we don't want to see the Menu Item we have to disable show_ui.
199
- * This also disables the metabox on the posts and pages, so we add thse manually instead.
200
- * We remove the capabilities to manage, edit and delete the terms. We have written this part ourselves and don't use WordPress for these functions. The only one we use is the assign_terms.
201
- */
202
- $labels = array(
203
- 'name' => __('Category Groups', 'avh-ec'),
204
- 'singular_name' => __('Category Group', 'avh-ec'),
205
- 'search_items' => __('Search Category Groups', 'avh-ec'),
206
- 'popular_items' => __('Popular Category Groups'),
207
- 'all_items' => __('All Category Groups'),
208
- 'parent_item' => __('Parent Category Group'),
209
- 'parent_item_colon' => __('Parent Category Group:'),
210
- 'edit_item' => __('Edit Category Group'),
211
- 'update_item' => __('Update Category Group'),
212
- 'add_new_item' => __('Add New Category Group'),
213
- 'new_item_name' => __('New Category Group Name')
214
- );
215
- $caps = array(
216
- 'manage_terms' => null,
217
- 'edit_terms' => null,
218
- 'delete_terms' => null,
219
- 'assign_terms' => 'edit_posts'
220
- );
221
- register_taxonomy(
222
- $this->taxonomy_name,
223
- array('post', 'page'),
224
- array(
225
- 'hierarchical' => true,
226
- 'labels' => $labels,
227
- 'query_var' => true,
228
- 'rewrite' => true,
229
- 'show_in_nav_menus' => false,
230
- 'public' => true,
231
- 'show_ui' => false,
232
- 'capabilities' => $caps
233
- )
234
- );
235
- }
236
-
237
- /**
238
- * Setup the options for the widget titles
239
- *
240
- * @WordPress action init
241
- */
242
- public function doSetupOptions()
243
- {
244
- // Setup the standard groups if the none group does not exists.
245
- $all_categories = $this->getAllCategoriesTermID();
246
- if (false === $this->getTermIDBy('slug', 'none')) {
247
- $none_group_id = wp_insert_term(
248
- 'none',
249
- $this->taxonomy_name,
250
- array('description' => __('This group will not show the widget.', 'avh-ec'))
251
- );
252
-
253
- $home_group_id = wp_insert_term(
254
- 'Home',
255
- $this->taxonomy_name,
256
- array(
257
- 'description' => __(
258
- 'This group will be shown on the front page.',
259
- 'avh-ec'
260
- )
261
- )
262
- );
263
- $this->setCategoriesForGroup($home_group_id['term_id'], $all_categories);
264
- $this->setWidgetTitleForGroup($home_group_id['term_id'], '');
265
- }
266
- if (false === $this->getTermIDBy('slug', 'all')) {
267
- $all_group_id = wp_insert_term(
268
- 'All',
269
- $this->taxonomy_name,
270
- array('description' => __('Holds all the categories.', 'avh-ec'))
271
- );
272
- if (!is_wp_error($all_group_id)) {
273
- $this->setWidgetTitleForGroup($all_group_id['term_id'], '');
274
- } else {
275
- trigger_error($all_group_id->get_error_message(), E_USER_NOTICE);
276
- }
277
- }
278
-
279
- $options = get_option($this->db_options_widget_titles);
280
- if (!$options) {
281
- $options = array();
282
- $id = $this->getTermIDBy('slug', 'all');
283
- $options[$id] = '';
284
- $id = $this->getTermIDBy('slug', 'home');
285
- $options[$id] = '';
286
- update_option($this->db_options_widget_titles, $options);
287
- }
288
- $this->options_widget_titles = $options;
289
- $this->setCategoriesForGroup($this->getTermIDBy('slug', 'all'), $all_categories);
290
- }
291
-
292
- /**
293
- * Update a group
294
- *
295
- * @param int $group_id
296
- * @param array $args
297
- * @param array $selected_categories
298
- * @param string $widget_title
299
- *
300
- * @return int
301
- */
302
- public function doUpdateGroup($group_id, $args = array(), $selected_categories = array(), $widget_title = '')
303
- {
304
- $group = $this->getGroup($group_id);
305
- if (is_object($group)) {
306
- $id = wp_update_term($group->term_id, $this->taxonomy_name, $args);
307
- if (!is_wp_error($id)) {
308
- $this->setWidgetTitleForGroup($group_id, $widget_title);
309
- $this->setCategoriesForGroup($group_id, $selected_categories);
310
- $return = 1; // Succesful
311
- } else {
312
- $return = 0; // Duplicate Slug
313
- }
314
- } else {
315
- $return = -1; // Unknown group
316
- }
317
-
318
- return ($return);
319
- }
320
-
321
- /**
322
- * Get all groups term_id
323
- *
324
- * @return array Term_id
325
- */
326
- public function getAllCategoriesTermID()
327
- {
328
- $all_cat_id = array();
329
- $categories = get_categories();
330
- if (!is_wp_error($categories)) {
331
- foreach ($categories as $category) {
332
- $all_cat_id[] = $category->term_id;
333
- }
334
- }
335
-
336
- return ($all_cat_id);
337
- }
338
-
339
- /**
340
- * Get the categories from the given group from the DB
341
- *
342
- * @param int $group_id The Taxonomy Term ID
343
- *
344
- * @return array false Will return false, if the row does not exists.
345
- */
346
- public function getCategoriesFromGroup($group_id)
347
- {
348
- global $wpdb;
349
-
350
- $return = array();
351
- // Query database
352
- $result = $wpdb->get_results(
353
- $wpdb->prepare(
354
- 'SELECT * FROM ' .
355
- $wpdb->terms .
356
- ' t, ' .
357
- $wpdb->avhec_cat_group .
358
- ' cg WHERE t.term_id = cg.term_id AND cg.group_term_id = %d',
359
- $group_id
360
- )
361
- );
362
-
363
- if (is_array($result)) { // Call succeeded
364
- if (empty($result)) { // No rows found
365
- $return = array();
366
- } else {
367
- foreach ($result as $row) {
368
- $return[] = $row->term_id;
369
- }
370
- }
371
- } else {
372
- $return = false;
373
- }
374
-
375
- return ($return);
376
- }
377
-
378
- /**
379
- * Gets all information of a group
380
- *
381
- * @param int $group_id
382
- *
383
- * @return object|false false when the group doesn't exists.
384
- */
385
- public function getGroup($group_id)
386
- {
387
- global $wpdb;
388
-
389
- $result = get_term((int) $group_id, $this->taxonomy_name);
390
- if (null === $result) {
391
- $result = false;
392
- }
393
-
394
- return ($result);
395
- }
396
-
397
- /**
398
- * @param int $category_id
399
- *
400
- * @return mixed
401
- */
402
- public function getGroupByCategoryID($category_id)
403
- {
404
- $return = get_term_by('slug', 'none', $this->taxonomy_name);
405
- $cat_groups = get_terms($this->taxonomy_name, array('hide_empty' => false));
406
-
407
- foreach ($cat_groups as $group) {
408
- $cats = $this->getCategoriesFromGroup($group->term_id);
409
- if ($group->slug != 'all' && in_array($category_id, $cats)) {
410
- $return = $group;
411
- break;
412
- }
413
- }
414
-
415
- return $return;
416
- }
417
-
418
- /**
419
- * Same as get_term_by, but returns the ID only if found, else false
420
- *
421
- * @param string $field
422
- * @param string $value
423
- *
424
- * @return int boolean
425
- */
426
- public function getTermIDBy($field, $value)
427
- {
428
- $row = get_term_by($field, $value, $this->taxonomy_name);
429
- if (false === $row) {
430
- $return = false;
431
- } else {
432
- $return = (int) $row->term_id;
433
- }
434
-
435
- return ($return);
436
- }
437
-
438
- /**
439
- * Return the title for a group_id if exsist otherwise return false
440
- *
441
- * @param int $group_id
442
- *
443
- * @return bool
444
- */
445
- public function getWidgetTitleForGroup($group_id)
446
- {
447
- if (isset($this->options_widget_titles[$group_id])) {
448
- return ($this->options_widget_titles[$group_id]);
449
- }
450
-
451
- return false;
452
- }
453
-
454
- /**
455
- * Set the categories for the given group from the DB.
456
- * Insert the group if it doesn't exists.
457
- *
458
- * @param int $group_id The Taxonomy Term ID
459
- * @param array $categories The categories
460
- *
461
- * @return object|false
462
- */
463
- public function setCategoriesForGroup($group_id, $categories = array())
464
- {
465
- global $wpdb;
466
- $result = false;
467
-
468
- if (false === $group_id) {
469
- return $result;
470
- }
471
- $old_categories = $this->getCategoriesFromGroup($group_id);
472
-
473
- if (!is_array($categories)) {
474
- $categories = array();
475
- }
476
- $new_categories = $categories;
477
- sort($old_categories);
478
- sort($new_categories);
479
- // If the new and old values are the same, no need to update.
480
- if ($new_categories === $old_categories) {
481
- return $result;
482
- }
483
-
484
- $new = array_diff($new_categories, $old_categories);
485
- $removed = array_diff($old_categories, $new_categories);
486
-
487
- if (!empty($new)) {
488
- $insert = array();
489
- foreach ($new as $cat_term_id) {
490
- $insert[] = '(' . $group_id . ',' . $cat_term_id . ')';
491
- }
492
- $value = implode(',', $insert);
493
- $sql = 'INSERT INTO ' . $wpdb->avhec_cat_group . ' (group_term_id, term_id) VALUES ' . $value;
494
- $result = $wpdb->query($sql);
495
- }
496
-
497
- if (!empty($removed)) {
498
- $delete = implode(',', $removed);
499
- $sql = $wpdb->prepare(
500
- 'DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE group_term_id=%d and term_id IN (' . $delete . ')',
501
- $group_id
502
- );
503
- $result = $wpdb->query($sql);
504
- }
505
-
506
- return $result;
507
- }
508
-
509
- /**
510
- * Set the Widget Title for a Group
511
- *
512
- * @param int $group_id
513
- * @param string $widget_title
514
- */
515
- public function setWidgetTitleForGroup($group_id, $widget_title = '')
516
- {
517
- $this->options_widget_titles[$group_id] = $widget_title;
518
- update_option($this->db_options_widget_titles, $this->options_widget_titles);
519
- }
520
  }
5
  *
6
  * @author Peter van der Does
7
  */
8
+ class AVH_EC_Category_Group {
9
+ public $db_options_widget_titles;
10
+ public $options_widget_titles;
11
+ /**
12
+ * Taxonomy name
13
+ *
14
+ * @var string
15
+ */
16
+ public $taxonomy_name;
17
+ public $widget_done_catgroup;
18
+
19
+ /**
20
+ * PHP5 Constructor
21
+ * Init the Database Abstraction layer
22
+ */
23
+ public function __construct() {
24
+ global $wpdb;
25
+
26
+ register_shutdown_function(array($this, '__destruct'));
27
+
28
+ /**
29
+ * Taxonomy name
30
+ *
31
+ * @var string
32
+ */
33
+ $this->taxonomy_name = 'avhec_catgroup';
34
+
35
+ $this->db_options_widget_titles = 'avhec_widget_titles';
36
+ // add DB pointer
37
+ $wpdb->avhec_cat_group = $wpdb->prefix . 'avhec_category_groups';
38
+
39
+ /**
40
+ * Create the table if it doesn't exist.
41
+ */
42
+ if ($wpdb->get_var('show tables like \'' . $wpdb->avhec_cat_group . '\'') != $wpdb->avhec_cat_group) {
43
+ add_action('init',
44
+ array($this, 'doCreateTable'),
45
+ 2); // Priority needs to be the same as the Register Taxonomy
46
+ }
47
+ add_action('init',
48
+ array($this, 'doRegisterTaxonomy'),
49
+ 2); // Priority for registering custom taxonomies is +1 over the creation of the initial taxonomies
50
+ add_action('init', array($this, 'doSetupOptions'));
51
+
52
+ add_action('admin_init', array($this, 'addMetaBoxes'));
53
+ }
54
+
55
+ /**
56
+ * PHP5 style destructor and will run when database object is destroyed.
57
+ *
58
+ * @return bool Always true
59
+ */
60
+ public function __destruct() {
61
+ return true;
62
+ }
63
+
64
+ /**
65
+ * Add the metaboxes for the pots and page pages.
66
+ *
67
+ * @WordPress action admin_init
68
+ */
69
+ public function addMetaBoxes() {
70
+ add_meta_box($this->taxonomy_name . 'div',
71
+ __('Category Groups', 'avh-ec'),
72
+ 'post_categories_meta_box',
73
+ 'post',
74
+ 'side',
75
+ 'core',
76
+ array('taxonomy' => $this->taxonomy_name));
77
+ add_meta_box($this->taxonomy_name . 'div',
78
+ __('Category Groups', 'avh-ec'),
79
+ 'post_categories_meta_box',
80
+ 'page',
81
+ 'side',
82
+ 'core',
83
+ array('taxonomy' => $this->taxonomy_name));
84
+ }
85
+
86
+ /**
87
+ * Create Table
88
+ *
89
+ * @WordPress action init
90
+ */
91
+ public function doCreateTable() {
92
+ global $wpdb;
93
+
94
+ // Setup the DB Tables
95
+ $charset_collate = '';
96
+
97
+ if ( ! empty($wpdb->charset)) {
98
+ $charset_collate = 'DEFAULT CHARACTER SET ' . $wpdb->charset;
99
+ }
100
+ if ( ! empty($wpdb->collate)) {
101
+ $charset_collate .= ' COLLATE ' . $wpdb->collate;
102
+ }
103
+
104
+ $sql = 'CREATE TABLE `' .
105
+ $wpdb->avhec_cat_group .
106
+ '` ( `group_term_id` BIGINT(20) UNSIGNED NOT null DEFAULT 0, `term_id` BIGINT(20) UNSIGNED NOT null DEFAULT 0, PRIMARY KEY (`group_term_id`, `term_id`) )' .
107
+ $charset_collate .
108
+ ';';
109
+
110
+ $result = $wpdb->query($sql);
111
+ }
112
+
113
+ /**
114
+ * Deletes the given category from all groups
115
+ *
116
+ * @param int $category_id
117
+ */
118
+ public function doDeleteCategoryFromGroup($category_id) {
119
+ global $wpdb;
120
+ $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE term_id=%d',
121
+ $category_id));
122
+ }
123
+
124
+ /**
125
+ * Deletes a group
126
+ *
127
+ * @param int $group_id
128
+ *
129
+ * @return bool|\WP_Error
130
+ */
131
+ public function doDeleteGroup($group_id) {
132
+ global $wpdb;
133
+
134
+ $group = $this->getGroup($group_id);
135
+ $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE group_term_id=%d',
136
+ $group_id));
137
+ $this->doDeleteWidgetTitle($group_id);
138
+ $return = wp_delete_term($group->term_id, $this->taxonomy_name);
139
+
140
+ return ($return);
141
+ }
142
+
143
+ /**
144
+ * Delete the Widget Title for a group
145
+ *
146
+ * @param int $group_id
147
+ */
148
+ public function doDeleteWidgetTitle($group_id) {
149
+ if (isset($this->options_widget_titles[ $group_id ])) {
150
+ unset($this->options_widget_titles[ $group_id ]);
151
+ }
152
+ update_option($this->db_options_widget_titles, $this->options_widget_titles);
153
+ }
154
+
155
+ /**
156
+ * Inserts a new group
157
+ *
158
+ * @param string $term
159
+ * @param array $args
160
+ * @param string $widget_title
161
+ *
162
+ * @return int
163
+ */
164
+ public function doInsertGroup($term, $args = array(), $widget_title = '') {
165
+ $row = wp_insert_term($term, $this->taxonomy_name, $args);
166
+ $this->setWidgetTitleForGroup($term, $widget_title);
167
+
168
+ return ($row['term_id']);
169
+ }
170
+
171
+ /**
172
+ * Setup Group Categories Taxonomy
173
+ *
174
+ * @WordPress action init
175
+ */
176
+ public function doRegisterTaxonomy() {
177
+ /**
178
+ * As we don't want to see the Menu Item we have to disable show_ui.
179
+ * This also disables the metabox on the posts and pages, so we add thse manually instead.
180
+ * We remove the capabilities to manage, edit and delete the terms. We have written this part ourselves and don't use WordPress for these functions. The only one we use is the assign_terms.
181
+ */
182
+ $labels = array(
183
+ 'name' => __('Category Groups', 'avh-ec'),
184
+ 'singular_name' => __('Category Group', 'avh-ec'),
185
+ 'search_items' => __('Search Category Groups', 'avh-ec'),
186
+ 'popular_items' => __('Popular Category Groups'),
187
+ 'all_items' => __('All Category Groups'),
188
+ 'parent_item' => __('Parent Category Group'),
189
+ 'parent_item_colon' => __('Parent Category Group:'),
190
+ 'edit_item' => __('Edit Category Group'),
191
+ 'update_item' => __('Update Category Group'),
192
+ 'add_new_item' => __('Add New Category Group'),
193
+ 'new_item_name' => __('New Category Group Name')
194
+ );
195
+ $caps = array(
196
+ 'manage_terms' => null,
197
+ 'edit_terms' => null,
198
+ 'delete_terms' => null,
199
+ 'assign_terms' => 'edit_posts'
200
+ );
201
+ register_taxonomy($this->taxonomy_name,
202
+ array('post', 'page'),
203
+ array(
204
+ 'hierarchical' => true,
205
+ 'labels' => $labels,
206
+ 'query_var' => true,
207
+ 'rewrite' => true,
208
+ 'show_in_nav_menus' => false,
209
+ 'public' => true,
210
+ 'show_ui' => false,
211
+ 'capabilities' => $caps
212
+ ));
213
+ }
214
+
215
+ /**
216
+ * Setup the options for the widget titles
217
+ *
218
+ * @WordPress action init
219
+ */
220
+ public function doSetupOptions() {
221
+ // Setup the standard groups if the none group does not exists.
222
+ $all_categories = $this->getAllCategoriesTermID();
223
+ if (false === $this->getTermIDBy('slug', 'none')) {
224
+ $none_group_id = wp_insert_term('none',
225
+ $this->taxonomy_name,
226
+ array(
227
+ 'description' => __('This group will not show the widget.', 'avh-ec')
228
+ ));
229
+
230
+ $home_group_id = wp_insert_term('Home',
231
+ $this->taxonomy_name,
232
+ array(
233
+ 'description' => __('This group will be shown on the front page.',
234
+ 'avh-ec')
235
+ ));
236
+ if ( ! is_wp_error($home_group_id)) {
237
+ $this->setCategoriesForGroup($home_group_id['term_id'], $all_categories);
238
+ $this->setWidgetTitleForGroup($home_group_id['term_id'], '');
239
+ } else {
240
+ trigger_error($home_group_id->get_error_message(), E_USER_NOTICE);
241
+ }
242
+ }
243
+ if (false === $this->getTermIDBy('slug', 'all')) {
244
+ $all_group_id = wp_insert_term('All',
245
+ $this->taxonomy_name,
246
+ array('description' => __('Holds all the categories.', 'avh-ec')));
247
+ if ( ! is_wp_error($all_group_id)) {
248
+ $this->setWidgetTitleForGroup($all_group_id['term_id'], '');
249
+ } else {
250
+ trigger_error($all_group_id->get_error_message(), E_USER_NOTICE);
251
+ }
252
+ }
253
+
254
+ $options = get_option($this->db_options_widget_titles);
255
+ if ( ! $options) {
256
+ $options = array();
257
+ $id = $this->getTermIDBy('slug', 'all');
258
+ $options[ $id ] = '';
259
+ $id = $this->getTermIDBy('slug', 'home');
260
+ $options[ $id ] = '';
261
+ update_option($this->db_options_widget_titles, $options);
262
+ }
263
+ $this->options_widget_titles = $options;
264
+ $this->setCategoriesForGroup($this->getTermIDBy('slug', 'all'), $all_categories);
265
+ }
266
+
267
+ /**
268
+ * Update a group
269
+ *
270
+ * @param int $group_id
271
+ * @param array $args
272
+ * @param array $selected_categories
273
+ * @param string $widget_title
274
+ *
275
+ * @return int
276
+ */
277
+ public function doUpdateGroup($group_id, $args = array(), $selected_categories = array(), $widget_title = '') {
278
+ $group = $this->getGroup($group_id);
279
+ if (is_object($group)) {
280
+ $id = wp_update_term($group->term_id, $this->taxonomy_name, $args);
281
+ if ( ! is_wp_error($id)) {
282
+ $this->setWidgetTitleForGroup($group_id, $widget_title);
283
+ $this->setCategoriesForGroup($group_id, $selected_categories);
284
+ $return = 1; // Succesful
285
+ } else {
286
+ $return = 0; // Duplicate Slug
287
+ }
288
+ } else {
289
+ $return = - 1; // Unknown group
290
+ }
291
+
292
+ return ($return);
293
+ }
294
+
295
+ /**
296
+ * Get all groups term_id
297
+ *
298
+ * @return array Term_id
299
+ */
300
+ public function getAllCategoriesTermID() {
301
+ $all_cat_id = array();
302
+ $categories = get_categories();
303
+ if ( ! is_wp_error($categories)) {
304
+ foreach ($categories as $category) {
305
+ $all_cat_id[] = $category->term_id;
306
+ }
307
+ }
308
+
309
+ return ($all_cat_id);
310
+ }
311
+
312
+ /**
313
+ * Get the categories from the given group from the DB
314
+ *
315
+ * @param int $group_id The Taxonomy Term ID
316
+ *
317
+ * @return array false Will return false, if the row does not exists.
318
+ */
319
+ public function getCategoriesFromGroup($group_id) {
320
+ global $wpdb;
321
+
322
+ $return = array();
323
+ // Query database
324
+ $result = $wpdb->get_results($wpdb->prepare('SELECT * FROM ' .
325
+ $wpdb->terms .
326
+ ' t, ' .
327
+ $wpdb->avhec_cat_group .
328
+ ' cg WHERE t.term_id = cg.term_id AND cg.group_term_id = %d',
329
+ $group_id));
330
+
331
+ if (is_array($result)) { // Call succeeded
332
+ if (empty($result)) { // No rows found
333
+ $return = array();
334
+ } else {
335
+ foreach ($result as $row) {
336
+ $return[] = $row->term_id;
337
+ }
338
+ }
339
+ } else {
340
+ $return = false;
341
+ }
342
+
343
+ return ($return);
344
+ }
345
+
346
+ /**
347
+ * Gets all information of a group
348
+ *
349
+ * @param int $group_id
350
+ *
351
+ * @return object|false false when the group doesn't exists.
352
+ */
353
+ public function getGroup($group_id) {
354
+ $result = get_term((int) $group_id, $this->taxonomy_name);
355
+ if (null === $result) {
356
+ $result = false;
357
+ }
358
+
359
+ return ($result);
360
+ }
361
+
362
+ /**
363
+ * @param int $category_id
364
+ *
365
+ * @return mixed
366
+ */
367
+ public function getGroupByCategoryID($category_id) {
368
+ $return = get_term_by('slug', 'none', $this->taxonomy_name);
369
+ $cat_groups = get_terms($this->taxonomy_name, array('hide_empty' => false));
370
+
371
+ foreach ($cat_groups as $group) {
372
+ $cats = $this->getCategoriesFromGroup($group->term_id);
373
+ if ($group->slug != 'all' && in_array($category_id, $cats)) {
374
+ $return = $group;
375
+ break;
376
+ }
377
+ }
378
+
379
+ return $return;
380
+ }
381
+
382
+ /**
383
+ * Same as get_term_by, but returns the ID only if found, else false
384
+ *
385
+ * @param string $field
386
+ * @param string $value
387
+ *
388
+ * @return int boolean
389
+ */
390
+ public function getTermIDBy($field, $value) {
391
+ $row = get_term_by($field, $value, $this->taxonomy_name);
392
+ if (false === $row) {
393
+ $return = false;
394
+ } else {
395
+ $return = (int) $row->term_id;
396
+ }
397
+
398
+ return ($return);
399
+ }
400
+
401
+ /**
402
+ * Return the title for a group_id if exsist otherwise return false
403
+ *
404
+ * @param int $group_id
405
+ *
406
+ * @return bool
407
+ */
408
+ public function getWidgetTitleForGroup($group_id) {
409
+ if (isset($this->options_widget_titles[ $group_id ])) {
410
+ return ($this->options_widget_titles[ $group_id ]);
411
+ }
412
+
413
+ return false;
414
+ }
415
+
416
+ /**
417
+ * Set the categories for the given group from the DB.
418
+ * Insert the group if it doesn't exists.
419
+ *
420
+ * @param int $group_id The Taxonomy Term ID
421
+ * @param array $categories The categories
422
+ *
423
+ * @return object|false
424
+ */
425
+ public function setCategoriesForGroup($group_id, $categories = array()) {
426
+ global $wpdb;
427
+ $result = false;
428
+
429
+ if (false === $group_id) {
430
+ return $result;
431
+ }
432
+ $old_categories = $this->getCategoriesFromGroup($group_id);
433
+
434
+ if ( ! is_array($categories)) {
435
+ $categories = array();
436
+ }
437
+ $new_categories = $categories;
438
+ sort($old_categories);
439
+ sort($new_categories);
440
+ // If the new and old values are the same, no need to update.
441
+ if ($new_categories === $old_categories) {
442
+ return $result;
443
+ }
444
+
445
+ $new = array_diff($new_categories, $old_categories);
446
+ $removed = array_diff($old_categories, $new_categories);
447
+
448
+ if ( ! empty($new)) {
449
+ $insert = array();
450
+ foreach ($new as $cat_term_id) {
451
+ $insert[] = '(' . $group_id . ',' . $cat_term_id . ')';
452
+ }
453
+ $value = implode(',', $insert);
454
+ $sql = 'INSERT INTO ' . $wpdb->avhec_cat_group . ' (group_term_id, term_id) VALUES ' . $value;
455
+ $result = $wpdb->query($sql);
456
+ }
457
+
458
+ if ( ! empty($removed)) {
459
+ $delete = implode(',', $removed);
460
+ $sql = $wpdb->prepare('DELETE FROM ' .
461
+ $wpdb->avhec_cat_group .
462
+ ' WHERE group_term_id=%d and term_id IN (' .
463
+ $delete .
464
+ ')',
465
+ $group_id);
466
+ $result = $wpdb->query($sql);
467
+ }
468
+
469
+ return $result;
470
+ }
471
+
472
+ /**
473
+ * Set the Widget Title for a Group
474
+ *
475
+ * @param int $group_id
476
+ * @param string $widget_title
477
+ */
478
+ public function setWidgetTitleForGroup($group_id, $widget_title = '') {
479
+ $this->options_widget_titles[ $group_id ] = $widget_title;
480
+ update_option($this->db_options_widget_titles, $this->options_widget_titles);
481
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
482
  }
4.2/class/avh-ec.core.php CHANGED
@@ -5,761 +5,864 @@
5
  *
6
  * @uses Walker
7
  */
8
- class AVHEC_Walker_Category extends Walker
9
- {
10
- /**
11
- * @see Walker::$db_fields
12
- * @since 2.1.0
13
- * @todo Decouple this
14
- * @var array
15
- */
16
- public $db_fields = array('parent' => 'parent', 'id' => 'term_id');
17
- /**
18
- * @see Walker::$tree_type
19
- * @since 2.1.0
20
- * @var string
21
- */
22
- public $tree_type = 'category';
23
-
24
- /**
25
- * @see Walker::end_el()
26
- * @since 2.1.0
27
- *
28
- * @param string $output Passed by reference. Used to append additional content.
29
- * @param object $object
30
- * @param int $depth Depth of category. Not used.
31
- * @param array $args Only uses 'list' for whether should append to output.
32
- */
33
- public function end_el(&$output, $object, $depth = 0, $args = array())
34
- {
35
- if ('list' != $args['style']) {
36
- return;
37
- }
38
-
39
- $output .= '</li>' . "\n";
40
- }
41
-
42
- /**
43
- * @see Walker::end_lvl()
44
- * @since 2.1.0
45
- *
46
- * @param string $output Passed by reference. Used to append additional content.
47
- * @param int $depth Depth of category. Used for tab indentation.
48
- * @param array $args Will only append content if style argument value is 'list'.
49
- */
50
- public function end_lvl(&$output, $depth = 0, $args = array())
51
- {
52
- if ('list' != $args['style']) {
53
- return;
54
- }
55
-
56
- $indent = str_repeat("\t", $depth);
57
- $output .= $indent . '</ul>' . "\n";
58
- }
59
-
60
- /**
61
- * @see Walker::start_el()
62
- * @since 2.1.0
63
- *
64
- * @param string $output Passed by reference. Used to append additional content.
65
- * @param object $object Category data object.
66
- * @param int $depth Depth of category in reference to parents.
67
- * @param array $args
68
- * @param int $current_object_id
69
- */
70
- public function start_el(&$output, $object, $depth = 0, $args = array(), $current_object_id = 0)
71
- {
72
- extract($args);
73
-
74
- $cat_name = esc_attr($object->name);
75
- $cat_name = apply_filters('list_cats', $cat_name, $object);
76
- $link = '<div class="avhec-widget-line"><a href="' . get_category_link($object->term_id) . '" ';
77
- if ($use_desc_for_title == 0 || empty($object->description)) {
78
- $link .= 'title="' . sprintf(__('View all posts filed under %s'), $cat_name) . '"';
79
- } else {
80
- $link .= 'title="' .
81
- esc_attr(strip_tags(apply_filters('category_description', $object->description, $object))) .
82
- '"';
83
- }
84
- $link .= '>';
85
- $link .= $cat_name . '</a>';
86
-
87
- if ((!empty($feed_image)) || (!empty($feed))) {
88
- $link .= '<div class="avhec-widget-rss"> ';
89
-
90
- if (empty($feed_image)) {
91
- $link .= '(';
92
- }
93
-
94
- $link .= '<a href="' . get_category_feed_link($object->term_id, $feed_type) . '"';
95
-
96
- if (empty($feed)) {
97
- $alt = ' alt="' . sprintf(__('Feed for all posts filed under %s'), $cat_name) . '"';
98
- } else {
99
- $title = ' title="' . $feed . '"';
100
- $alt = ' alt="' . $feed . '"';
101
- $name = $feed;
102
- $link .= $title;
103
- }
104
-
105
- $link .= '>';
106
-
107
- if (empty($feed_image)) {
108
- $link .= $name;
109
- } else {
110
- $link .= '<img src="' . $feed_image . '"' . $alt . $title . ' />';
111
- }
112
- $link .= '</a>';
113
- if (empty($feed_image)) {
114
- $link .= ')';
115
- }
116
- $link .= '</div>';
117
- }
118
-
119
- if (isset($show_count) && $show_count) {
120
- $link .= '<div class="avhec-widget-count"> (' . intval($object->count) . ')</div>';
121
- }
122
-
123
- if (isset($show_date) && $show_date) {
124
- $link .= ' ' . gmdate('Y-m-d', $object->last_update_timestamp);
125
- }
126
-
127
- // When on a single post get the post's category. This ensures that that category will be given the CSS style of "current category".
128
- if (is_single()) {
129
- $post_cats = get_the_category();
130
- $current_category = $post_cats[0]->term_id;
131
- }
132
-
133
- if (isset($current_category) && $current_category) {
134
- $_current_category = get_category($current_category);
135
- }
136
-
137
- if ('list' == $args['style']) {
138
- $output .= "\t" . '<li';
139
- $class = 'cat-item cat-item-' . $object->term_id;
140
- if (isset($current_category) && $current_category && ($object->term_id == $current_category)) {
141
- $class .= ' current-cat';
142
- } elseif (isset($_current_category) &&
143
- $_current_category &&
144
- ($object->term_id == $_current_category->parent)
145
- ) {
146
- $class .= ' current-cat-parent';
147
- }
148
- $output .= ' class="' . $class . '"';
149
- $output .= '>' . $link . '</div>' . "\n";
150
- } else {
151
- $output .= "\t" . $link . '</div><br />' . "\n";
152
- }
153
- }
154
-
155
- /**
156
- * @see Walker::start_lvl()
157
- * @since 2.1.0
158
- *
159
- * @param string $output Passed by reference. Used to append additional content.
160
- * @param int $depth Depth of category. Used for tab indentation.
161
- * @param array $args Will only append content if style argument value is 'list'.
162
- */
163
- public function start_lvl(&$output, $depth = 0, $args = array())
164
- {
165
- if ('list' != $args['style']) {
166
- return;
167
- }
168
-
169
- $indent = str_repeat("\t", $depth);
170
- $output .= $indent . '<ul class="children">' . "\n";
171
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
  }
173
 
174
- class AVH_EC_Core
175
- {
176
- public $comment;
177
- public $db_options_core;
178
- public $db_options_tax_meta;
179
- public $default_options;
180
- public $default_options_category_group;
181
- public $default_options_general;
182
- public $default_options_sp_category_group;
183
- public $info;
184
- public $options;
185
- public $version;
186
-
187
- /**
188
- * PHP5 constructor
189
- */
190
- public function __construct()
191
- {
192
- /**
193
- * @var AVH_EC_Category_Group
194
- */
195
- $catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
196
-
197
- $this->version = '3.10.0-dev.1';
198
- $this->comment = '<!-- AVH Extended Categories version ' .
199
- $this->version .
200
- ' | http://blog.avirtualhome.com/wordpress-plugins/ -->';
201
- $this->db_options_core = 'avhec';
202
- $this->db_options_tax_meta = 'avhec-tax_meta';
203
-
204
- add_action('init', array($this, 'handleInitializePlugin'), 10);
205
- }
206
-
207
- public function applyOrderFilter($orderby, $args)
208
- {
209
- switch ($args['orderby']) {
210
- case 'avhec_manualorder':
211
- $new_orderby = 't.avhec_term_order';
212
- break;
213
- case 'avhec_3rdparty_mycategoryorder':
214
- $new_orderby = 't.term_order';
215
- break;
216
- default:
217
- $new_orderby = $orderby;
218
- break;
219
- }
220
-
221
- return $new_orderby;
222
- }
223
-
224
- /**
225
- * Display or retrieve the HTML dropdown list of categories.
226
- * The list of arguments is below:
227
- * 'show_option_all' (string) - Text to display for showing all categories.
228
- * 'show_option_none' (string) - Text to display for showing no categories.
229
- * 'orderby' (string) default is 'ID' - What column to use for ordering the
230
- * categories.
231
- * 'order' (string) default is 'ASC' - What direction to order categories.
232
- * 'show_last_update' (bool|int) default is 0 - See {@link get_categories()}
233
- * 'show_count' (bool|int) default is 0 - Whether to show how many posts are
234
- * in the category.
235
- * 'hide_empty' (bool|int) default is 1 - Whether to hide categories that
236
- * don't have any posts attached to them.
237
- * 'child_of' (int) default is 0 - See {@link get_categories()}.
238
- * 'exclude' (string) - See {@link get_categories()}.
239
- * 'echo' (bool|int) default is 1 - Whether to display or retrieve content.
240
- * 'depth' (int) - The max depth.
241
- * 'tab_index' (int) - Tab index for select element.
242
- * 'name' (string) - The name attribute value for selected element.
243
- * 'class' (string) - The class attribute value for selected element.
244
- * 'selected' (int) - Which category ID is selected.
245
- * The 'hierarchical' argument, which is disabled by default, will override the
246
- * depth argument, unless it is true. When the argument is false, it will
247
- * display all of the categories. When it is enabled it will use the value in
248
- * the 'depth' argument.
249
- *
250
- * @since 2.1.0
251
- *
252
- * @param string|array $args Optional. Override default arguments.
253
- *
254
- * @return string HTML content only if 'echo' argument is 0.
255
- */
256
- public function avh_wp_dropdown_categories($args = array())
257
- {
258
- $mywalker = new AVH_Walker_CategoryDropdown();
259
-
260
- // @format_off
261
- $defaults = array(
262
- 'show_option_all' => '',
263
- 'show_option_none' => '',
264
- 'orderby' => 'id',
265
- 'order' => 'ASC',
266
- 'show_last_update' => 0,
267
- 'show_count' => 0,
268
- 'hide_empty' => 1,
269
- 'child_of' => 0,
270
- 'exclude' => '',
271
- 'echo' => 1,
272
- 'selected' => 0,
273
- 'hierarchical' => 0,
274
- 'name' => 'cat',
275
- 'id' => '',
276
- 'class' => 'postform',
277
- 'depth' => 0,
278
- 'tab_index' => 0,
279
- 'taxonomy' => 'category',
280
- 'walker' => $mywalker,
281
- 'hide_if_empty' => false
282
- );
283
- // @format_on
284
- $defaults['selected'] = (is_category()) ? get_query_var('cat') : 0;
285
-
286
- $r = wp_parse_args($args, $defaults);
287
-
288
- if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
289
- $r['pad_counts'] = true;
290
- }
291
-
292
- $r['include_last_update_time'] = $r['show_last_update'];
293
- extract($r);
294
-
295
- $tab_index_attribute = '';
296
- if ((int) $tab_index > 0) {
297
- $tab_index_attribute = ' tabindex="' . $tab_index . '"';
298
- }
299
-
300
- // Avoid clashes with the 'name' param of get_terms().
301
- $get_terms_args = $r;
302
- unset($get_terms_args['name']);
303
- $categories = get_terms($r['taxonomy'], $get_terms_args);
304
-
305
- $name = esc_attr($r['name']);
306
- $class = esc_attr($r['class']);
307
- $id = $r['id'] ? esc_attr($r['id']) : $name;
308
-
309
- if (!$r['hide_if_empty'] || !empty($categories)) {
310
- $output = "<select name='$name' id='$id' class='$class' $tab_index_attribute>\n";
311
- } else {
312
- $output = '';
313
- }
314
-
315
- if (empty($categories) && !$r['hide_if_empty'] && !empty($show_option_none)) {
316
- $show_option_none = apply_filters('list_cats', $show_option_none);
317
- $output .= "\t<option value='-1' selected='selected'>$show_option_none</option>\n";
318
- }
319
- if (!empty($categories)) {
320
-
321
- if ($show_option_all) {
322
- $show_option_all = apply_filters('list_cats', $show_option_all);
323
- $selected = ('0' === strval($r['selected'])) ? " selected='selected'" : '';
324
- $output .= "\t" . '<option value="0"' . $selected . '>' . $show_option_all . '</option>' . "\n";
325
- }
326
-
327
- if ($show_option_none) {
328
- $show_option_none = apply_filters('list_cats', $show_option_none);
329
- $selected = ('-1' === strval($r['selected'])) ? " selected='selected'" : '';
330
- $output .= "\t" . '<option value="-1"' . $selected . '>' . $show_option_none . '</option>' . "\n";
331
- }
332
-
333
- if ($hierarchical) {
334
- $depth = $r['depth']; // Walk the full depth.
335
- } else {
336
- $depth = -1; // Flat
337
- }
338
- $output .= walk_category_dropdown_tree($categories, $depth, $r);
339
- }
340
- if (!$r['hide_if_empty'] || !empty($categories)) {
341
- $output .= "</select>\n";
342
- }
343
-
344
- $output = apply_filters('wp_dropdown_cats', $output);
345
-
346
- if ($echo) {
347
- echo $output;
348
- }
349
-
350
- return $output;
351
- }
352
-
353
- /**
354
- * Display or retrieve the HTML list of categories.
355
- * The list of arguments is below:
356
- * 'show_option_all' (string) - Text to display for showing all categories.
357
- * 'orderby' (string) default is 'ID' - What column to use for ordering the
358
- * categories.
359
- * 'order' (string) default is 'ASC' - What direction to order categories.
360
- * 'show_last_update' (bool|int) default is 0 - See {@link
361
- * walk_category_dropdown_tree()}
362
- * 'show_count' (bool|int) default is 0 - Whether to show how many posts are
363
- * in the category.
364
- * 'hide_empty' (bool|int) default is 1 - Whether to hide categories that
365
- * don't have any posts attached to them.
366
- * 'use_desc_for_title' (bool|int) default is 1 - Whether to use the
367
- * description instead of the category title.
368
- * 'feed' - See {@link get_categories()}.
369
- * 'feed_type' - See {@link get_categories()}.
370
- * 'feed_image' - See {@link get_categories()}.
371
- * 'child_of' (int) default is 0 - See {@link get_categories()}.
372
- * 'exclude' (string) - See {@link get_categories()}.
373
- * 'exclude_tree' (string) - See {@link get_categories()}.
374
- * 'echo' (bool|int) default is 1 - Whether to display or retrieve content.
375
- * 'current_category' (int) - See {@link get_categories()}.
376
- * 'hierarchical' (bool) - See {@link get_categories()}.
377
- * 'title_li' (string) - See {@link get_categories()}.
378
- * 'depth' (int) - The max depth.
379
- *
380
- * @since 2.1.0
381
- *
382
- * @param string|array $args Optional. Override default arguments.
383
- *
384
- * @return void|string HTML content only if 'echo' argument is 0.
385
- */
386
- public function avh_wp_list_categories($args = array())
387
- {
388
- $mywalker = new AVHEC_Walker_Category();
389
- $defaults = array(
390
- 'show_option_all' => '',
391
- 'orderby' => 'name',
392
- 'order' => 'ASC',
393
- 'show_last_update' => 0,
394
- 'style' => 'list',
395
- 'show_count' => 0,
396
- 'hide_empty' => 1,
397
- 'use_desc_for_title' => 1,
398
- 'child_of' => 0,
399
- 'feed' => '',
400
- 'feed_type' => '',
401
- 'feed_image' => '',
402
- 'exclude' => '',
403
- 'exclude_tree' => '',
404
- 'current_category' => 0,
405
- 'hierarchical' => true,
406
- 'title_li' => __('Categories'),
407
- 'echo' => 1,
408
- 'depth' => 0,
409
- 'walker' => $mywalker
410
- );
411
-
412
- $r = wp_parse_args($args, $defaults);
413
-
414
- if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
415
- $r['pad_counts'] = true;
416
- }
417
-
418
- if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
419
- $r['pad_counts'] = true;
420
- }
421
-
422
- if (isset($r['show_date'])) {
423
- $r['include_last_update_time'] = $r['show_date'];
424
- }
425
-
426
- if (true == $r['hierarchical']) {
427
- $r['exclude_tree'] = $r['exclude'];
428
- $r['exclude'] = '';
429
- }
430
-
431
- extract($r);
432
-
433
- $categories = get_categories($r);
434
-
435
- $output = '';
436
- if ($title_li && 'list' == $style) {
437
- $output = '<li class="categories">' . $r['title_li'] . '<ul>';
438
- }
439
-
440
- if (empty($categories)) {
441
- if ('list' == $style) {
442
- $output .= '<li>' . __("No categories") . '</li>';
443
- } else {
444
- $output .= __("No categories");
445
- }
446
- } else {
447
- global $wp_query;
448
-
449
- if (!empty($show_option_all)) {
450
- if ('list' == $style) {
451
- $output .= '<li><a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a></li>';
452
- } else {
453
- $output .= '<a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a>';
454
- }
455
- }
456
- if (empty($r['current_category']) && is_category()) {
457
- $r['current_category'] = $wp_query->get_queried_object_id();
458
- }
459
-
460
- if ($hierarchical) {
461
- $depth = $r['depth'];
462
- } else {
463
- $depth = -1; // Flat.
464
- }
465
-
466
- $output .= walk_category_tree($categories, $depth, $r);
467
- }
468
-
469
- if ($title_li && 'list' == $style) {
470
- $output .= '</ul></li>';
471
- }
472
-
473
- $output = apply_filters('wp_list_categories', $output);
474
-
475
- if ($echo) {
476
- echo $output;
477
- } else {
478
- return $output;
479
- }
480
-
481
- return;
482
- }
483
-
484
- /**
485
- * Checks if running version is newer and do upgrades if necessary
486
- *
487
- * @since 1.2.3
488
- *
489
- * @param string $db_version
490
- */
491
- public function doUpdateOptions($db_version)
492
- {
493
- $options = $this->getOptions();
494
-
495
- // Add none existing sections and/or elements to the options
496
- foreach ($this->default_options as $section => $default_data) {
497
- if (!array_key_exists($section, $options)) {
498
- $options[$section] = $default_data;
499
- continue;
500
- }
501
- foreach ($default_data as $element => $default_value) {
502
- if (!array_key_exists($element, $options[$section])) {
503
- $options[$section][$element] = $default_value;
504
- }
505
- }
506
- }
507
-
508
- // Remove none existing sections and/or elements from the options
509
- foreach ($options as $section => $data) {
510
- if (!array_key_exists($section, $this->default_options)) {
511
- unset($options[$section]);
512
- continue;
513
- }
514
- foreach ($data as $element => $value) {
515
- if (!array_key_exists($element, $this->default_options[$section])) {
516
- unset($options[$section][$element]);
517
- }
518
- }
519
- }
520
- /**
521
- * Update the options to the latests versions
522
- */
523
- $options['general']['version'] = $this->version;
524
- $options['general']['dbversion'] = $db_version;
525
- $this->saveOptions($options);
526
- }
527
-
528
- /**
529
- * Get the base directory of a directory structure
530
- *
531
- * @param string $directory
532
- *
533
- * @return string
534
- */
535
- public function getBaseDirectory($directory)
536
- {
537
- // place each directory into array and get the last element
538
- $directory_array = explode('/', $directory);
539
- // get highest or top level in array of directory strings
540
- $public_base = end($directory_array);
541
-
542
- return $public_base;
543
- }
544
-
545
- public function getCategories()
546
- {
547
- static $_categories = null;
548
- if (null === $_categories) {
549
- $_categories = get_categories('get=all');
550
- }
551
-
552
- return $_categories;
553
- }
554
-
555
- public function getCategoriesId($categories)
556
- {
557
- static $_categories_id = null;
558
- if (null == $_categories_id) {
559
- foreach ($categories as $key => $category) {
560
- $_categories_id[$category->term_id] = $key;
561
- }
562
- }
563
-
564
- return $_categories_id;
565
- }
566
-
567
- /**
568
- * *******************************
569
- * *
570
- * Methods for variable: options *
571
- * *
572
- * ******************************
573
- */
574
-
575
- /**
576
- * Get the value for an option element.
577
- * If there's no option is set on the Admin page, return the default value.
578
- *
579
- * @param string $key
580
- * @param string $option
581
- *
582
- * @return mixed
583
- */
584
- public function getOptionElement($option, $key)
585
- {
586
- if ($this->options[$option][$key]) {
587
- $return = $this->options[$option][$key]; // From Admin Page
588
- } else {
589
- $return = $this->default_options[$option][$key]; // Default
590
- }
591
-
592
- return ($return);
593
- }
594
-
595
- /**
596
- * return array
597
- */
598
- public function getOptions()
599
- {
600
- return ($this->options);
601
- }
602
-
603
- /**
604
- * @param array $options
605
- */
606
- public function setOptions($options)
607
- {
608
- $this->options = $options;
609
- }
610
-
611
- public function handleInitializePlugin()
612
- {
613
- global $wpdb;
614
-
615
- $catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
616
- $db_version = 4;
617
-
618
- $info['siteurl'] = get_option('siteurl');
619
- $info['plugin_dir'] = AVHEC_PLUGIN_DIR;
620
- $info['graphics_url'] = AVHEC_PLUGIN_URL . '/images';
621
-
622
- // Set class property for info
623
- $this->info = array(
624
- 'home' => get_option('home'),
625
- 'siteurl' => $info['siteurl'],
626
- 'plugin_dir' => $info['plugin_dir'],
627
- 'js_dir' => $info['plugin_dir'] . '/js',
628
- 'graphics_url' => $info['graphics_url']
629
- );
630
-
631
- // Set the default options
632
- $this->default_options_general = array(
633
- 'version' => $this->version,
634
- 'dbversion' => $db_version,
635
- 'alternative_name_select_category' => ''
636
- );
637
-
638
- // Set the default category group options
639
- $no_group_id = $catgrp->getTermIDBy('slug', 'none');
640
- $home_group_id = $catgrp->getTermIDBy('slug', 'home');
641
- $default_group_id = $catgrp->getTermIDBy('slug', 'all');
642
- $this->default_options_category_group = array(
643
- 'no_group' => $no_group_id,
644
- 'home_group' => $home_group_id,
645
- 'default_group' => $default_group_id
646
- );
647
-
648
- $this->default_options_sp_category_group = array(
649
- 'home_group' => $home_group_id,
650
- 'category_group' => $default_group_id,
651
- 'day_group' => $default_group_id,
652
- 'month_group' => $default_group_id,
653
- 'year_group' => $default_group_id,
654
- 'author_group' => $default_group_id,
655
- 'search_group' => $default_group_id
656
- );
657
-
658
- $this->default_options = array(
659
- 'general' => $this->default_options_general,
660
- 'cat_group' => $this->default_options_category_group,
661
- 'widget_titles' => array(),
662
- 'sp_cat_group' => $this->default_options_sp_category_group
663
- );
664
-
665
- /**
666
- * Set the options for the program
667
- */
668
- $this->loadOptions();
669
-
670
- // Check if we have to do updates
671
- if ((!isset($this->options['general']['dbversion'])) || $this->options['general']['dbversion'] < $db_version) {
672
- $this->doUpdateOptions($db_version);
673
- }
674
-
675
- $db = new AVH_DB();
676
- if (!$db->field_exists('avhec_term_order', $wpdb->terms)) {
677
- $wpdb->query("ALTER TABLE $wpdb->terms ADD `avhec_term_order` INT( 4 ) null DEFAULT '0'");
678
- }
679
-
680
- $this->handleTextdomain();
681
- add_filter('get_terms_orderby', array($this, 'applyOrderFilter'), 10, 2);
682
- }
683
-
684
- /**
685
- * Loads the i18n
686
- */
687
- public function handleTextdomain()
688
- {
689
- load_plugin_textdomain('avh-ec', false, AVHEC_RELATIVE_PLUGIN_DIR . '/lang');
690
- }
691
-
692
- /**
693
- * Used in forms to set the checked option.
694
- *
695
- * @param mixed $checked
696
- * @param mixed_type $current
697
- *
698
- * @return string
699
- * @since 2.0
700
- */
701
- public function isChecked($checked, $current)
702
- {
703
- if ($checked == $current) {
704
- return (' checked="checked"');
705
- }
706
-
707
- return ('');
708
- }
709
-
710
- /**
711
- * Used in forms to set the SELECTED option
712
- *
713
- * @param string $current
714
- * @param string $field
715
- *
716
- * @return string
717
- */
718
- public function isSelected($current, $field)
719
- {
720
- if ($current == $field) {
721
- return (' SELECTED');
722
- }
723
-
724
- return ('');
725
- }
726
-
727
- /**
728
- * Retrieves the plugin options from the WordPress options table and assigns to class variable.
729
- * If the options do not exists, like a new installation, the options are set to the default value.
730
- *
731
- * @return none
732
- */
733
- public function loadOptions()
734
- {
735
- $options = get_option($this->db_options_core);
736
- if (false === $options) { // New installation
737
- $this->resetToDefaultOptions();
738
- } else {
739
- $this->setOptions($options);
740
- }
741
- }
742
-
743
- /**
744
- * Reset to default options and save in DB
745
- */
746
- public function resetToDefaultOptions()
747
- {
748
- $this->options = $this->default_options;
749
- $this->saveOptions($this->default_options);
750
- }
751
-
752
- /**
753
- * Save all current options and set the options
754
- *
755
- * @param array $options
756
- */
757
- public function saveOptions($options)
758
- {
759
- update_option($this->db_options_core, $options);
760
- wp_cache_flush(); // Delete cache
761
- $this->setOptions($options);
762
- }
5
  *
6
  * @uses Walker
7
  */
8
+ class AVHEC_Walker_Category extends Walker {
9
+ /**
10
+ * @see Walker::$db_fields
11
+ * @since 2.1.0
12
+ * @todo Decouple this
13
+ * @var array
14
+ */
15
+ public $db_fields = array('parent' => 'parent', 'id' => 'term_id');
16
+ /**
17
+ * @see Walker::$tree_type
18
+ * @since 2.1.0
19
+ * @var string
20
+ */
21
+ public $tree_type = 'category';
22
+
23
+ /**
24
+ * @see Walker::end_el()
25
+ * @since 2.1.0
26
+ *
27
+ * @param string $output Passed by reference. Used to append additional content.
28
+ * @param object $object
29
+ * @param int $depth Depth of category. Not used.
30
+ * @param array $args Only uses 'list' for whether should append to output.
31
+ */
32
+ public function end_el(&$output, $object, $depth = 0, $args = array()) {
33
+ if ('list' != $args['style']) {
34
+ return;
35
+ }
36
+
37
+ $output .= '</li>' . "\n";
38
+ }
39
+
40
+ /**
41
+ * @see Walker::end_lvl()
42
+ * @since 2.1.0
43
+ *
44
+ * @param string $output Passed by reference. Used to append additional content.
45
+ * @param int $depth Depth of category. Used for tab indentation.
46
+ * @param array $args Will only append content if style argument value is 'list'.
47
+ */
48
+ public function end_lvl(&$output, $depth = 0, $args = array()) {
49
+ if ('list' != $args['style']) {
50
+ return;
51
+ }
52
+
53
+ $indent = str_repeat("\t", $depth);
54
+ $output .= $indent . '</ul>' . "\n";
55
+ }
56
+
57
+ /**
58
+ * @see Walker::start_el()
59
+ * @since 2.1.0
60
+ *
61
+ * @param string $output Passed by reference. Used to append additional content.
62
+ * @param object $category Category data object.
63
+ * @param int $depth Depth of category in reference to parents.
64
+ * @param array $args
65
+ * @param int $current_object_id
66
+ */
67
+ public function start_el(&$output, $category, $depth = 0, $args = array(), $current_object_id = 0) {
68
+ $cat_name = apply_filters('list_cats', esc_attr($category->name), $category);
69
+ // Don't generate an element if the category name is empty.
70
+ if ( ! $cat_name) {
71
+ return;
72
+ }
73
+
74
+ $link = '<div class="avhec-widget-line"><a href="' . get_category_link($category->term_id) . '" ';
75
+ if ($args['use_desc_for_title'] && ! empty($category->description)) {
76
+ /**
77
+ * Filter the category description for display.
78
+ *
79
+ * @since 1.2.0
80
+ *
81
+ * @param string $description Category description.
82
+ * @param object $category Category object.
83
+ */
84
+ $link .= 'title="' .
85
+ esc_attr(strip_tags(apply_filters('category_description', $category->description, $category))) .
86
+ '"';
87
+ } else {
88
+ $link .= 'title="' . sprintf(__('View all posts filed under %s'), $cat_name) . '"';
89
+ }
90
+ $link .= '>';
91
+ $link .= $cat_name . '</a>';
92
+
93
+ if ( ! empty($args['feed_image']) || ! empty($args['feed'])) {
94
+ $link .= '<div class="avhec-widget-rss"> ';
95
+
96
+ if (empty($args['feed_image'])) {
97
+ $link .= '(';
98
+ }
99
+
100
+ $link .= '<a href="' . get_category_feed_link($category->term_id, $args['feed_type']) . '"';
101
+
102
+ if (empty($args['feed'])) {
103
+ $alt = ' alt="' . sprintf(__('Feed for all posts filed under %s'), $cat_name) . '"';
104
+ } else {
105
+ $alt = ' alt="' . $args['feed'] . '"';
106
+ $name = $args['feed'];
107
+ $link .= ' title="';
108
+ $link .= empty($args['title']) ? $args['feed'] : $args['title'];
109
+ $link .= '"';
110
+ }
111
+
112
+ $link .= '>';
113
+
114
+ if (empty($args['feed_image'])) {
115
+ $link .= $name;
116
+ } else {
117
+ $link .= '<img src="' . $args['feed_image'] . '"' . $alt . '" />';
118
+ }
119
+ $link .= '</a>';
120
+
121
+ if (empty($args['feed_image'])) {
122
+ $link .= ')';
123
+ }
124
+
125
+ $link .= '</div>';
126
+ }
127
+
128
+ if ( ! empty($args['show_count'])) {
129
+ $link .= '<div class="avhec-widget-count"> (' . number_format_i18n($category->count) . ')</div>';
130
+ }
131
+
132
+ if ( ! empty($args['$show_date'])) {
133
+ $link .= ' ' . gmdate('Y-m-d', $category->last_update_timestamp);
134
+ }
135
+
136
+ if ('list' == $args['style']) {
137
+ // When on a single post get the post's category. This ensures that that category will be given the CSS style of "current category".
138
+ if (is_single()) {
139
+ $post_cats = get_the_category();
140
+ $args['current_category'] = $post_cats[0]->term_id;
141
+ }
142
+
143
+ $output .= "\t" . '<li';
144
+ $css_classes = array(
145
+ 'cat-item',
146
+ 'cat-item-' . $category->term_id,
147
+ );
148
+
149
+ if ( ! empty($args['current_category'])) {
150
+ $_current_category = get_term($args['current_category'], $category->taxonomy);
151
+ if ($category->term_id == $args['current_category']) {
152
+ $css_classes[] = 'current-cat';
153
+ } elseif ($category->term_id == $_current_category->parent) {
154
+ $css_classes[] = 'current-cat-parent';
155
+ }
156
+ }
157
+
158
+ /**
159
+ * Filter the list of CSS classes to include with each category in the list.
160
+ *
161
+ * @since 4.2.0
162
+ * @see wp_list_categories()
163
+ *
164
+ * @param array $css_classes An array of CSS classes to be applied to each list item.
165
+ * @param object $category Category data object.
166
+ * @param int $depth Depth of page, used for padding.
167
+ * @param array $args An array of wp_list_categories() arguments.
168
+ */
169
+ $css_classes = implode(' ', apply_filters('category_css_class', $css_classes, $category, $depth, $args));
170
+
171
+ $output .= ' class="' . $css_classes . '"';
172
+ $output .= '>' . $link . '</div>' . "\n";
173
+ } else {
174
+ $output .= "\t" . $link . '</div><br />' . "\n";
175
+ }
176
+ }
177
+
178
+ /**
179
+ * @see Walker::start_lvl()
180
+ * @since 2.1.0
181
+ *
182
+ * @param string $output Passed by reference. Used to append additional content.
183
+ * @param int $depth Depth of category. Used for tab indentation.
184
+ * @param array $args Will only append content if style argument value is 'list'.
185
+ */
186
+ public function start_lvl(&$output, $depth = 0, $args = array()) {
187
+ if ('list' != $args['style']) {
188
+ return;
189
+ }
190
+
191
+ $indent = str_repeat("\t", $depth);
192
+ $output .= $indent . '<ul class="children">' . "\n";
193
+ }
194
  }
195
 
196
+ class AVH_EC_Core {
197
+ public $comment;
198
+ public $db_options_core;
199
+ public $db_options_tax_meta;
200
+ public $default_options;
201
+ public $default_options_category_group;
202
+ public $default_options_general;
203
+ public $default_options_sp_category_group;
204
+ public $info;
205
+ public $options;
206
+ public $version;
207
+
208
+ /**
209
+ * AVH_EC_Core constructor.
210
+ */
211
+ public function __construct() {
212
+ $this->version = '3.10.0-dev.1';
213
+ $this->comment = '<!-- AVH Extended Categories version ' .
214
+ $this->version .
215
+ ' | http://blog.avirtualhome.com/wordpress-plugins/ -->';
216
+ $this->db_options_core = 'avhec';
217
+ $this->db_options_tax_meta = 'avhec-tax_meta';
218
+
219
+ add_action('init', array($this, 'handleInitializePlugin'), 10);
220
+ }
221
+
222
+ public function applyOrderFilter($orderby, $args) {
223
+ switch ($args['orderby']) {
224
+ case 'avhec_manualorder':
225
+ $new_orderby = 't.avhec_term_order';
226
+ break;
227
+ case 'avhec_3rdparty_mycategoryorder':
228
+ $new_orderby = 't.term_order';
229
+ break;
230
+ default:
231
+ $new_orderby = $orderby;
232
+ break;
233
+ }
234
+
235
+ return $new_orderby;
236
+ }
237
+
238
+ /**
239
+ * Display or retrieve the HTML dropdown list of categories.
240
+ *
241
+ * The 'hierarchical' argument, which is disabled by default, will override the
242
+ * depth argument, unless it is true. When the argument is false, it will
243
+ * display all of the categories. When it is enabled it will use the value in
244
+ * the 'depth' argument.
245
+ *
246
+ * @since 2.1.0
247
+ * @since 4.2.0 Introduced the `value_field` argument.
248
+ *
249
+ * @param string|array $args {
250
+ * Optional. Array or string of arguments to generate a categories drop-down
251
+ * element.
252
+ *
253
+ * @type string $show_option_all Text to display for showing all categories. Default empty.
254
+ * @type string $show_option_none Text to display for showing no categories. Default empty.
255
+ * @type string $option_none_value Value to use when no category is selected. Default empty.
256
+ * @type string $orderby Which column to use for ordering categories. See get_terms() for a list
257
+ * of accepted values. Default 'id' (term_id).
258
+ * @type string $order Whether to order terms in ascending or descending order. Accepts 'ASC'
259
+ * or 'DESC'. Default 'ASC'.
260
+ * @type bool $pad_counts See get_terms() for an argument description. Default false.
261
+ * @type bool|int $show_count Whether to include post counts. Accepts 0, 1, or their bool equivalents.
262
+ * Default 0.
263
+ * @type bool|int $hide_empty Whether to hide categories that don't have any posts. Accepts 0, 1, or
264
+ * their bool equivalents. Default 1.
265
+ * @type int $child_of Term ID to retrieve child terms of. See get_terms(). Default 0.
266
+ * @type array|string $exclude Array or comma/space-separated string of term ids to exclude.
267
+ * If `$include` is non-empty, `$exclude` is ignored. Default empty
268
+ * array.
269
+ * @type bool|int $echo Whether to echo or return the generated markup. Accepts 0, 1, or their
270
+ * bool equivalents. Default 1.
271
+ * @type bool|int $hierarchical Whether to traverse the taxonomy hierarchy. Accepts 0, 1, or their bool
272
+ * equivalents. Default 0.
273
+ * @type int $depth Maximum depth. Default 0.
274
+ * @type int $tab_index Tab index for the select element. Default 0 (no tabindex).
275
+ * @type string $name Value for the 'name' attribute of the select element. Default 'cat'.
276
+ * @type string $id Value for the 'id' attribute of the select element. Defaults to the value
277
+ * of `$name`.
278
+ * @type string $class Value for the 'class' attribute of the select element. Default
279
+ * 'postform'.
280
+ * @type int|string $selected Value of the option that should be selected. Default 0.
281
+ * @type string $value_field Term field that should be used to populate the 'value' attribute
282
+ * of the option elements. Accepts any valid term field: 'term_id',
283
+ * 'name',
284
+ * 'slug', 'term_group', 'term_taxonomy_id', 'taxonomy', 'description',
285
+ * 'parent', 'count'. Default 'term_id'.
286
+ * @type string|array $taxonomy Name of the category or categories to retrieve. Default 'category'.
287
+ * @type bool $hide_if_empty True to skip generating markup if no categories are found.
288
+ * Default false (create select element even if no categories are found).
289
+ * }
290
+ * @return string HTML content only if 'echo' argument is 0.
291
+ */
292
+ public function avh_wp_dropdown_categories($args = '') {
293
+ $mywalker = new AVH_Walker_CategoryDropdown();
294
+
295
+ // @format_off
296
+ $defaults = array(
297
+ 'show_option_all' => '',
298
+ 'show_option_none' => '',
299
+ 'orderby' => 'id',
300
+ 'order' => 'ASC',
301
+ 'show_last_update' => 0,
302
+ 'show_count' => 0,
303
+ 'hide_empty' => 1,
304
+ 'child_of' => 0,
305
+ 'exclude' => '',
306
+ 'echo' => 1,
307
+ 'selected' => 0,
308
+ 'hierarchical' => 0,
309
+ 'name' => 'cat',
310
+ 'id' => '',
311
+ 'class' => 'postform',
312
+ 'depth' => 0,
313
+ 'tab_index' => 0,
314
+ 'taxonomy' => 'category',
315
+ 'walker' => $mywalker,
316
+ 'hide_if_empty' => false,
317
+ 'option_none_value' => - 1,
318
+ 'value_field' => 'term_id',
319
+ );
320
+ // @format_on
321
+ $defaults['selected'] = (is_category()) ? get_query_var('cat') : 0;
322
+
323
+ $r = wp_parse_args($args, $defaults);
324
+ $option_none_value = $r['option_none_value'];
325
+
326
+ if ( ! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
327
+ $r['pad_counts'] = true;
328
+ }
329
+
330
+ $r['include_last_update_time'] = $r['show_last_update'];
331
+ $tab_index = $r['tab_index'];
332
+
333
+ $tab_index_attribute = '';
334
+ if ((int) $tab_index > 0) {
335
+ $tab_index_attribute = ' tabindex="' . $tab_index . '"';
336
+ }
337
+
338
+ // Avoid clashes with the 'name' param of get_terms().
339
+ $get_terms_args = $r;
340
+ unset($get_terms_args['name']);
341
+ $categories = get_terms($r['taxonomy'], $get_terms_args);
342
+
343
+ $name = esc_attr($r['name']);
344
+ $class = esc_attr($r['class']);
345
+ $id = $r['id'] ? esc_attr($r['id']) : $name;
346
+
347
+ if ( ! $r['hide_if_empty'] || ! empty($categories)) {
348
+ $output = "<select name='$name' id='$id' class='$class' $tab_index_attribute>\n";
349
+ } else {
350
+ $output = '';
351
+ }
352
+
353
+ if (empty($categories) && ! $r['hide_if_empty'] && ! empty($r['show_option_none'])) {
354
+ $show_option_none = apply_filters('list_cats', $r['show_option_none']);
355
+ $output .= "\t<option value='-1' selected='selected'>$show_option_none</option>\n";
356
+ }
357
+ if ( ! empty($categories)) {
358
+
359
+ if ($r['show_option_all']) {
360
+ $show_option_all = apply_filters('list_cats', $$r['show_option_all']);
361
+ $selected = ('0' === strval($r['selected'])) ? " selected='selected'" : '';
362
+ $output .= "\t" . '<option value="0"' . $selected . '>' . $show_option_all . '</option>' . "\n";
363
+ }
364
+
365
+ if ($r['show_option_none']) {
366
+ $show_option_none = apply_filters('list_cats', $r['show_option_none']);
367
+ $selected = selected($option_none_value, $r['selected'], false);
368
+ $output .= "\t" .
369
+ '<option value="' .
370
+ esc_attr($option_none_value) .
371
+ '"' .
372
+ $selected .
373
+ '>' .
374
+ $show_option_none .
375
+ '</option>' .
376
+ "\n";
377
+ }
378
+
379
+ if ($r['hierarchical']) {
380
+ $depth = $r['depth']; // Walk the full depth.
381
+ } else {
382
+ $depth = - 1; // Flat
383
+ }
384
+ $output .= walk_category_dropdown_tree($categories, $depth, $r);
385
+ }
386
+ if ( ! $r['hide_if_empty'] || ! empty($categories)) {
387
+ $output .= "</select>\n";
388
+ }
389
+
390
+ $output = apply_filters('wp_dropdown_cats', $output, $r);
391
+
392
+ if ($r['echo']) {
393
+ echo $output;
394
+ }
395
+
396
+ return $output;
397
+ }
398
+
399
+ /**
400
+ * Display or retrieve the HTML list of categories.
401
+ *
402
+ * @since 2.1.0
403
+ * @since 4.4.0 Introduced the `hide_title_if_empty` and `separator` arguments. The `current_category` argument was
404
+ * modified to optionally accept an array of values.
405
+ *
406
+ * @param string|array $args {
407
+ * Array of optional arguments.
408
+ *
409
+ * @type string $show_option_all Text to display for showing all categories. Default empty string.
410
+ * @type string $show_option_none Text to display for the 'no categories' option.
411
+ * Default 'No categories'.
412
+ * @type string $orderby The column to use for ordering categories. Default 'ID'.
413
+ * @type string $order Which direction to order categories. Accepts 'ASC' or 'DESC'.
414
+ * Default 'ASC'.
415
+ * @type bool|int $show_count Whether to show how many posts are in the category. Default 0.
416
+ * @type bool|int $hide_empty Whether to hide categories that don't have any posts attached to them.
417
+ * Default 1.
418
+ * @type bool|int $use_desc_for_title Whether to use the category description as the title attribute.
419
+ * Default 1.
420
+ * @type string $feed Text to use for the feed link. Default 'Feed for all posts filed
421
+ * under [cat name]'.
422
+ * @type string $feed_type Feed type. Used to build feed link. See {@link get_term_feed_link()}.
423
+ * Default empty string (default feed).
424
+ * @type string $feed_image URL of an image to use for the feed link. Default empty string.
425
+ * @type int $child_of Term ID to retrieve child terms of. See {@link get_terms()}. Default 0.
426
+ * @type array|string $exclude Array or comma/space-separated string of term IDs to exclude.
427
+ * If `$hierarchical` is true, descendants of `$exclude` terms will
428
+ *