AVH Extended Categories Widgets - Version 4.0.2

Version Description

Download this release

Release Info

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

Code changes from version 4.0.1 to 4.0.2

2.8/class/avh-ec.core.php CHANGED
@@ -27,7 +27,7 @@ class AVH_EC_Core
27
  */
28
  $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
29
 
30
- $this->version = '4.0.1';
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';
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';
3.3/class/avh-ec.core.php CHANGED
@@ -27,7 +27,7 @@ class AVH_EC_Core
27
  */
28
  $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
29
 
30
- $this->version = '4.0.1';
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';
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';
3.6/class/avh-ec.core.php CHANGED
@@ -34,7 +34,7 @@ class AVH_EC_Core
34
  */
35
  $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
36
 
37
- $this->version = '4.0.1';
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';
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';
4.2/avh-ec.client.php CHANGED
@@ -2,13 +2,11 @@
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
  */
@@ -16,23 +14,23 @@ class AVH_EC_Singleton
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;
@@ -42,9 +40,9 @@ class AVH_EC_Singleton
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
@@ -53,7 +51,7 @@ 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');
@@ -65,9 +63,7 @@ function avhextendedcategories_init()
65
  * Register the widget
66
  *
67
  * @WordPress Action widgets_init
68
- *
69
- * @since 3.0
70
- *
71
  */
72
  function avhextendedcategories_widgets_init()
73
  {
2
 
3
  /**
4
  * Singleton Class
5
+
6
  */
7
  class AVH_EC_Singleton
8
  {
 
9
  /**
 
10
  * @param string $class
11
  * @param string $arg1
12
  */
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;
40
  /**
41
  * Include the necessary files
42
  */
43
+ require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/helpers/avh-forms.php');
44
+ require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/helpers/avh-common.php');
45
+ require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widgets.php');
46
 
47
  /**
48
  * Initialize the plugin
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');
63
  * Register the widget
64
  *
65
  * @WordPress Action widgets_init
66
+ * @since 3.0
 
 
67
  */
68
  function avhextendedcategories_widgets_init()
69
  {
4.2/class/avh-ec.admin.php CHANGED
@@ -2,21 +2,15 @@
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
  /**
@@ -26,23 +20,28 @@ class AVH_EC_Admin
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);
@@ -59,79 +58,109 @@ class AVH_EC_Admin
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
  {
@@ -142,8 +171,10 @@ class AVH_EC_Admin
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
  {
@@ -151,52 +182,102 @@ class AVH_EC_Admin
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
  /**
@@ -205,8 +286,22 @@ class AVH_EC_Admin
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
 
@@ -223,223 +318,160 @@ class AVH_EC_Admin
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
  {
@@ -448,16 +480,84 @@ class AVH_EC_Admin
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');
@@ -465,13 +565,22 @@ class AVH_EC_Admin
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';
@@ -497,10 +606,24 @@ class AVH_EC_Admin
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'])) {
@@ -529,7 +652,16 @@ class AVH_EC_Admin
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');
@@ -579,13 +711,55 @@ class AVH_EC_Admin
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
 
@@ -618,110 +792,25 @@ class AVH_EC_Admin
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:
@@ -732,150 +821,245 @@ class AVH_EC_Admin
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) {
@@ -889,94 +1073,331 @@ class AVH_EC_Admin
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>';
@@ -985,26 +1406,38 @@ class AVH_EC_Admin
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>';
@@ -1012,7 +1445,8 @@ class AVH_EC_Admin
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 />';
@@ -1034,140 +1468,205 @@ class AVH_EC_Admin
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
  /**
@@ -1176,6 +1675,8 @@ class AVH_EC_Admin
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
  {
@@ -1190,20 +1691,31 @@ class AVH_EC_Admin
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
  }
@@ -1277,6 +1789,22 @@ class AVH_EC_Admin
1277
  return $output;
1278
  }
1279
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1280
  /**
1281
  * Prints the general nonces, used by the AJAX
1282
  */
@@ -1293,8 +1821,7 @@ class AVH_EC_Admin
1293
  /**
1294
  * Print the Metabox JS for toggling closed and open
1295
  *
1296
- * @param
1297
- * $boxid
1298
  */
1299
  public function printMetaboxJS($boxid)
1300
  {
@@ -1310,37 +1837,12 @@ class AVH_EC_Admin
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)
@@ -1355,12 +1857,24 @@ class AVH_EC_Admin
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':
@@ -1368,17 +1882,56 @@ class AVH_EC_Admin
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':
@@ -1394,7 +1947,18 @@ class AVH_EC_Admin
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
  }
@@ -1404,61 +1968,19 @@ class AVH_EC_Admin
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
  }
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
  /**
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);
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
  {
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
  {
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
  /**
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
 
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
  {
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');
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';
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'])) {
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');
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
 
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:
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) {
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>';
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>';
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 />';
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
  /**
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
  {
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
  }
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
  */
1821
  /**
1822
  * Print the Metabox JS for toggling closed and open
1823
  *
1824
+ * @param int $boxid
 
1825
  */
1826
  public function printMetaboxJS($boxid)
1827
  {
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)
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':
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':
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
  }
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
  }
4.2/class/avh-ec.category-group.php CHANGED
@@ -7,18 +7,14 @@
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
  /**
@@ -46,9 +42,17 @@ class AVH_EC_Category_Group
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'));
@@ -64,8 +68,36 @@ class AVH_EC_Category_Group
64
  return true;
65
  }
66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  /**
68
  * Create Table
 
69
  * @WordPress action init
70
  */
71
  public function doCreateTable()
@@ -82,13 +114,82 @@ class AVH_EC_Category_Group
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()
@@ -98,13 +199,44 @@ class AVH_EC_Category_Group
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()
@@ -112,14 +244,31 @@ class AVH_EC_Category_Group
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 {
@@ -141,13 +290,32 @@ class AVH_EC_Category_Group
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
  /**
@@ -171,17 +339,26 @@ class AVH_EC_Category_Group
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
@@ -199,98 +376,43 @@ class AVH_EC_Category_Group
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
- if (false === $group_id) {
217
- return;
218
- }
219
- $old_categories = $this->getCategoriesFromGroup($group_id);
220
-
221
- if (!is_array($categories)) {
222
- $categories = array();
223
- }
224
- $new_categories = $categories;
225
- sort($old_categories);
226
- sort($new_categories);
227
- // If the new and old values are the same, no need to update.
228
- if ($new_categories === $old_categories) {
229
- return false;
230
- }
231
-
232
- $new = array_diff($new_categories, $old_categories);
233
- $removed = array_diff($old_categories, $new_categories);
234
-
235
- if (!empty($new)) {
236
- foreach ($new as $cat_term_id) {
237
- $insert[] = '(' . $group_id . ',' . $cat_term_id . ')';
238
- }
239
- $value = implode(',', $insert);
240
- $sql = 'INSERT INTO ' . $wpdb->avhec_cat_group . ' (group_term_id, term_id) VALUES ' . $value;
241
- $result = $wpdb->query($sql);
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
- return $result;
251
  }
252
 
253
  /**
254
- * Set the Widget Title for a Group
255
- *
256
- * @param int $group_id
257
- * @param string $widget_title
258
  *
 
259
  */
260
- public 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
- *
269
- * @param
270
- * $group_id
271
- *
272
- */
273
- public function getWidgetTitleForGroup($group_id)
274
- {
275
- if (isset($this->options_widget_titles[$group_id])) {
276
- return ($this->options_widget_titles[$group_id]);
277
  }
278
 
279
- return false;
280
- }
281
-
282
- /**
283
- * Delete the Widget Title for a group
284
- *
285
- * @param
286
- * $group_id
287
- */
288
- public function doDeleteWidgetTitle($group_id)
289
- {
290
- if (isset($this->options_widget_titles[$group_id])) {
291
- unset($this->options_widget_titles[$group_id]);
292
- }
293
- update_option($this->db_options_widget_titles, $this->options_widget_titles);
294
  }
295
 
296
  /**
@@ -298,6 +420,7 @@ class AVH_EC_Category_Group
298
  *
299
  * @param string $field
300
  * @param string $value
 
301
  * @return int boolean
302
  */
303
  public function getTermIDBy($field, $value)
@@ -313,111 +436,85 @@ class AVH_EC_Category_Group
313
  }
314
 
315
  /**
316
- * Gets all information of a group
317
  *
318
- * @param
319
- * $group_id
320
- * @return Object false false when the group doesn't exists.
321
  */
322
- public function getGroup($group_id)
323
- {
324
- global $wpdb;
325
-
326
- $result = get_term((int) $group_id, $this->taxonomy_name);
327
- if (null === $result) {
328
- $result = false;
329
- }
330
-
331
- return ($result);
332
- }
333
-
334
- public function getGroupByCategoryID($category_id)
335
  {
336
- $return = get_term_by('slug', 'none', $this->taxonomy_name);
337
- $cat_groups = get_terms($this->taxonomy_name, array('hide_empty' => false));
338
-
339
- foreach ($cat_groups as $group) {
340
- $cats = $this->getCategoriesFromGroup($group->term_id);
341
- if ($group->slug != 'all' && in_array($category_id, $cats)) {
342
- $return = $group;
343
- break;
344
- }
345
  }
346
 
347
- return $return;
348
  }
349
 
350
  /**
351
- * Inserts a new group
 
352
  *
353
- * @param
354
- * $term
355
- * @param array $args
356
- */
357
- public function doInsertGroup($term, $args = array(), $widget_title = '')
358
- {
359
- $row = wp_insert_term($term, $this->taxonomy_name, $args);
360
- $this->setWidgetTitleForGroup($term, $widget_title);
361
-
362
- return ($row['term_id']);
363
- }
364
-
365
- /**
366
- * Deletes a group
367
  *
368
- * @param
369
- * $group_id
370
  */
371
- public function doDeleteGroup($group_id)
372
  {
373
  global $wpdb;
 
374
 
375
- $group = $this->getGroup($group_id);
376
- $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE group_term_id=%d', $group_id));
377
- $this->doDeleteWidgetTitle($group_id);
378
- $return = wp_delete_term($group->term_id, $this->taxonomy_name);
379
 
380
- return ($return);
381
- }
 
 
 
 
 
 
 
 
382
 
383
- /**
384
- * Update a group
385
- *
386
- * @param
387
- * $group_id
388
- * @param
389
- * $selected_categories
390
- * @param $widget_title return
391
- * -1,0,1 Unknown Group, Duplicate Slug, Succesfull
392
- */
393
- public function doUpdateGroup($group_id, $args = array(), $selected_categories = array(), $widget_title = '')
394
- {
395
- $group = $this->getGroup($group_id);
396
- if (is_object($group)) {
397
- $id = wp_update_term($group->term_id, $this->taxonomy_name, $args);
398
- if (!is_wp_error($id)) {
399
- $this->setWidgetTitleForGroup($group_id, $widget_title);
400
- $this->setCategoriesForGroup($group_id, $selected_categories);
401
- $return = 1; // Succesful
402
- } else {
403
- $return = 0; // Duplicate Slug
404
  }
405
- } else {
406
- $return = -1; // Unknown group
 
407
  }
408
 
409
- return ($return);
 
 
 
 
 
 
 
 
 
410
  }
411
 
412
  /**
413
- * Deletes the given category from all groups
414
  *
415
- * @param
416
- * $category_id
417
  */
418
- public function doDeleteCategoryFromGroup($category_id)
419
  {
420
- global $wpdb;
421
- $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE term_id=%d', $category_id));
422
  }
423
  }
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
  /**
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'));
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()
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()
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()
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 {
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
  /**
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
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
  /**
420
  *
421
  * @param string $field
422
  * @param string $value
423
+ *
424
  * @return int boolean
425
  */
426
  public function getTermIDBy($field, $value)
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
  }
4.2/class/avh-ec.core.php CHANGED
@@ -1,294 +1,228 @@
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 = '3.10.0-dev.1';
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.
@@ -308,7 +242,6 @@ class AVH_EC_Core
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
@@ -316,8 +249,8 @@ class AVH_EC_Core
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())
@@ -325,7 +258,28 @@ class AVH_EC_Core
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
 
@@ -345,9 +299,9 @@ class AVH_EC_Core
345
 
346
  // Avoid clashes with the 'name' param of get_terms().
347
  $get_terms_args = $r;
348
- unset( $get_terms_args['name'] );
349
- $categories = get_terms( $r['taxonomy'], $get_terms_args );
350
-
351
  $name = esc_attr($r['name']);
352
  $class = esc_attr($r['class']);
353
  $id = $r['id'] ? esc_attr($r['id']) : $name;
@@ -398,7 +352,6 @@ class AVH_EC_Core
398
 
399
  /**
400
  * Display or retrieve the HTML list of categories.
401
- *
402
  * The list of arguments is below:
403
  * 'show_option_all' (string) - Text to display for showing all categories.
404
  * 'orderby' (string) default is 'ID' - What column to use for ordering the
@@ -426,14 +379,35 @@ class AVH_EC_Core
426
  *
427
  * @since 2.1.0
428
  *
429
- * @param string|array $args
430
- * Optional. Override default arguments.
431
- * @return string HTML content only if 'echo' argument is 0.
432
  */
433
  public function avh_wp_list_categories($args = array())
434
  {
435
  $mywalker = new AVHEC_Walker_Category();
436
- $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);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
437
 
438
  $r = wp_parse_args($args, $defaults);
439
 
@@ -483,48 +457,308 @@ class AVH_EC_Core
483
  $r['current_category'] = $wp_query->get_queried_object_id();
484
  }
485
 
486
- if ($hierarchical) {
487
- $depth = $r['depth'];
488
- } else {
489
- $depth = -1; // Flat.
490
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
491
 
492
- $output .= walk_category_tree($categories, $depth, $r);
 
 
493
  }
494
 
495
- if ($title_li && 'list' == $style) {
496
- $output .= '</ul></li>';
 
497
  }
498
 
499
- $output = apply_filters('wp_list_categories', $output);
 
 
500
 
501
- if ($echo) {
502
- echo $output;
503
- } else {
504
- return $output;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
505
  }
 
 
506
  }
507
 
508
- public function getCategories()
 
 
 
 
 
 
 
 
509
  {
510
- static $_categories = null;
511
- if (null === $_categories) {
512
- $_categories = get_categories('get=all');
513
  }
514
 
515
- return $_categories;
516
  }
517
 
518
- public function getCategoriesId($categories)
 
 
 
 
 
 
519
  {
520
- static $_categories_id = null;
521
- if (null == $_categories_id) {
522
- foreach ($categories as $key => $category) {
523
- $_categories_id[$category->term_id] = $key;
524
- }
525
  }
 
526
 
527
- return $_categories_id;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
528
  }
529
  }
530
 
@@ -535,7 +769,6 @@ class AVH_EC_Core
535
  */
536
  class AVH_Walker_CategoryDropdown extends Walker_CategoryDropdown
537
  {
538
-
539
  public function walk($elements, $max_depth)
540
  {
541
  $args = array_slice(func_get_args(), 2);
@@ -613,189 +846,3 @@ class AVH_Walker_CategoryDropdown extends Walker_CategoryDropdown
613
  return $output;
614
  }
615
  }
616
-
617
- /**
618
- * Create HTML list of categories.
619
- *
620
- * @uses Walker
621
- */
622
- class AVHEC_Walker_Category extends Walker
623
- {
624
-
625
- /**
626
- *
627
- * @see Walker::$tree_type
628
- * @since 2.1.0
629
- * @var string
630
- */
631
- public $tree_type = 'category';
632
-
633
- /**
634
- *
635
- * @see Walker::$db_fields
636
- * @since 2.1.0
637
- * @todo Decouple this
638
- * @var array
639
- */
640
- public $db_fields = array('parent' => 'parent', 'id' => 'term_id');
641
-
642
- /**
643
- *
644
- * @see Walker::start_lvl()
645
- * @since 2.1.0
646
- *
647
- * @param string $output
648
- * Passed by reference. Used to append additional content.
649
- * @param int $depth
650
- * Depth of category. Used for tab indentation.
651
- * @param array $args
652
- * Will only append content if style argument value is 'list'.
653
- */
654
- public function start_lvl(&$output, $depth = 0, $args = array())
655
- {
656
- if ('list' != $args['style']) {
657
- return;
658
- }
659
-
660
- $indent = str_repeat("\t", $depth);
661
- $output .= $indent . '<ul class="children">' . "\n";
662
- }
663
-
664
- /**
665
- *
666
- * @see Walker::end_lvl()
667
- * @since 2.1.0
668
- *
669
- * @param string $output
670
- * Passed by reference. Used to append additional content.
671
- * @param int $depth
672
- * Depth of category. Used for tab indentation.
673
- * @param array $args
674
- * Will only append content if style argument value is 'list'.
675
- */
676
- public function end_lvl(&$output, $depth = 0, $args = array())
677
- {
678
- if ('list' != $args['style']) {
679
- return;
680
- }
681
-
682
- $indent = str_repeat("\t", $depth);
683
- $output .= $indent . '</ul>' . "\n";
684
- }
685
-
686
- /**
687
- *
688
- * @see Walker::start_el()
689
- * @since 2.1.0
690
- *
691
- * @param string $output
692
- * Passed by reference. Used to append additional content.
693
- * @param object $object
694
- * Category data object.
695
- * @param int $depth
696
- * Depth of category in reference to parents.
697
- * @param array $args
698
- */
699
- public function start_el(&$output, $object, $depth = 0, $args = array(), $current_object_id = 0)
700
- {
701
- extract($args);
702
-
703
- $cat_name = esc_attr($object->name);
704
- $cat_name = apply_filters('list_cats', $cat_name, $object);
705
- $link = '<div class="avhec-widget-line"><a href="' . get_category_link($object->term_id) . '" ';
706
- if ($use_desc_for_title == 0 || empty($object->description)) {
707
- $link .= 'title="' . sprintf(__('View all posts filed under %s'), $cat_name) . '"';
708
- } else {
709
- $link .= 'title="' . esc_attr(strip_tags(apply_filters('category_description', $object->description, $object))) . '"';
710
- }
711
- $link .= '>';
712
- $link .= $cat_name . '</a>';
713
-
714
- if ((!empty($feed_image)) || (!empty($feed))) {
715
- $link .= '<div class="avhec-widget-rss"> ';
716
-
717
- if (empty($feed_image)) {
718
- $link .= '(';
719
- }
720
-
721
- $link .= '<a href="' . get_category_feed_link($object->term_id, $feed_type) . '"';
722
-
723
- if (empty($feed)) {
724
- $alt = ' alt="' . sprintf(__('Feed for all posts filed under %s'), $cat_name) . '"';
725
- } else {
726
- $title = ' title="' . $feed . '"';
727
- $alt = ' alt="' . $feed . '"';
728
- $name = $feed;
729
- $link .= $title;
730
- }
731
-
732
- $link .= '>';
733
-
734
- if (empty($feed_image)) {
735
- $link .= $name;
736
- } else {
737
- $link .= '<img src="' . $feed_image . '"' . $alt . $title . ' />';
738
- }
739
- $link .= '</a>';
740
- if (empty($feed_image)) {
741
- $link .= ')';
742
- }
743
- $link .= '</div>';
744
- }
745
-
746
- if (isset($show_count) && $show_count) {
747
- $link .= '<div class="avhec-widget-count"> (' . intval($object->count) . ')</div>';
748
- }
749
-
750
- if (isset($show_date) && $show_date) {
751
- $link .= ' ' . gmdate('Y-m-d', $object->last_update_timestamp);
752
- }
753
-
754
- // When on a single post get the post's category. This ensures that that category will be given the CSS style of "current category".
755
- if (is_single()) {
756
- $post_cats = get_the_category();
757
- $current_category = $post_cats[0]->term_id;
758
- }
759
-
760
- if (isset($current_category) && $current_category) {
761
- $_current_category = get_category($current_category);
762
- }
763
-
764
- if ('list' == $args['style']) {
765
- $output .= "\t" . '<li';
766
- $class = 'cat-item cat-item-' . $object->term_id;
767
- if (isset($current_category) && $current_category && ($object->term_id == $current_category)) {
768
- $class .= ' current-cat';
769
- } elseif (isset($_current_category) && $_current_category && ($object->term_id == $_current_category->parent)) {
770
- $class .= ' current-cat-parent';
771
- }
772
- $output .= ' class="' . $class . '"';
773
- $output .= '>' . $link . '</div>' . "\n";
774
- } else {
775
- $output .= "\t" . $link . '</div><br />' . "\n";
776
- }
777
- }
778
-
779
- /**
780
- *
781
- * @see Walker::end_el()
782
- * @since 2.1.0
783
- *
784
- * @param string $output
785
- * Passed by reference. Used to append additional content.
786
- * @param object $page
787
- * Not used.
788
- * @param int $depth
789
- * Depth of category. Not used.
790
- * @param array $args
791
- * Only uses 'list' for whether should append to output.
792
- */
793
- public function end_el(&$output, $object, $depth = 0, $args = array())
794
- {
795
- if ('list' != $args['style']) {
796
- return;
797
- }
798
-
799
- $output .= '</li>' . "\n";
800
- }
801
- }
1
  <?php
2
 
3
+ /**
4
+ * Create HTML list of categories.
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.
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
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())
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
 
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;
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
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
 
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
  }
763
  }
764
 
769
  */
770
  class AVH_Walker_CategoryDropdown extends Walker_CategoryDropdown
771
  {
 
772
  public function walk($elements, $max_depth)
773
  {
774
  $args = array_slice(func_get_args(), 2);
846
  return $output;
847
  }
848
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4.2/class/avh-ec.widgets.php CHANGED
@@ -1,208 +1,286 @@
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);
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
- $cat_args['name'] = 'extended-categories-select-' . $this->number;
111
- $this->core->avh_wp_dropdown_categories($cat_args);
112
- echo '<script type=\'text/javascript\'>' . "\n";
113
- echo '/* <![CDATA[ */' . "\n";
114
- echo ' var ec_dropdown_' . $this->number . ' = document.getElementById("extended-categories-select-' . $this->number . '");' . "\n";
115
- echo ' function ec_onCatChange_' . $this->number . '() {' . "\n";
116
- echo ' if (ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value > 0) {' . "\n";
117
- echo ' location.href = "' . home_url() . '/?cat="+ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value;' . "\n";
118
- echo ' }' . "\n";
119
- echo ' }' . "\n";
120
- echo ' ec_dropdown_' . $this->number . '.onchange = ec_onCatChange_' . $this->number . ';' . "\n";
121
- echo '/* ]]> */' . "\n";
122
- echo '</script>' . "\n";
123
  }
124
- echo $after_widget;
 
125
  }
 
126
 
 
 
 
 
 
127
  /**
128
- * When Widget Control Form Is Posted
129
- *
130
- * @param unknown_type $new_instance
131
- * @param unknown_type $old_instance
132
- * @return unknown
133
  */
134
- public function update($new_instance, $old_instance)
 
 
 
 
 
 
 
 
 
135
  {
136
- // update the instance's settings
137
- if (!isset($new_instance['submit'])) {
138
- return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  }
 
140
 
141
- $instance = $old_instance;
 
 
 
 
 
 
142
 
143
- $instance['title'] = strip_tags(stripslashes($new_instance['title']));
144
- $instance['selectedonly'] = isset($new_instance['selectedonly']);
145
- $instance['count'] = isset($new_instance['count']);
146
- $instance['hierarchical'] = isset($new_instance['hierarchical']);
147
- $instance['hide_empty'] = isset($new_instance['hide_empty']);
148
- $instance['use_desc_for_title'] = isset($new_instance['use_desc_for_title']);
149
- $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column']));
150
- $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order']));
151
- $instance['style'] = strip_tags(stripslashes($new_instance['style']));
152
- $instance['rssfeed'] = isset($new_instance['rssfeed']);
153
- $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage']));
154
- if (array_key_exists('all', $new_instance['post_category'])) {
155
- $instance['post_category'] = false;
156
  } else {
157
- $instance['post_category'] = serialize($new_instance['post_category']);
158
  }
159
- $instance['depth'] = (int) $new_instance['depth'];
160
- if ($instance['depth'] < 0 || 11 < $instance['depth']) {
161
- $instance['depth'] = 0;
 
 
 
 
 
 
 
 
 
162
  }
163
- $instance['invert_included'] = isset($new_instance['invert_included']);
164
 
165
- return $instance;
 
 
 
166
  }
167
 
168
  /**
169
  * Display Widget Control Form
170
  *
171
- * @param unknown_type $instance
172
- */
 
 
173
  public function form($instance)
174
  {
175
  // displays the widget admin form
176
- $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => '', 'depth' => 0));
177
-
178
- // Prepare data for display
179
- $depth = (int) $instance['depth'];
180
- if ($depth < 0 || 11 < $depth) {
181
- $depth = 0;
182
- }
183
- $selected_cats = (avhGetArrayValue($instance, 'post_category') !== '') ? unserialize($instance['post_category']) : false;
184
 
 
 
 
 
185
  echo '<p>';
186
- avh_doWidgetFormText($this->get_field_id('title'), $this->get_field_name('title'), __('Title', 'avh-ec'), avhGetArrayValue($instance, 'title'));
 
 
 
 
 
187
  echo '</p>';
188
 
189
  echo '<p>';
190
- avh_doWidgetFormCheckbox($this->get_field_id('selectedonly'), $this->get_field_name('selectedonly'), __('Show selected categories only', 'avh-ec'), (bool) avhGetArrayValue($instance, 'selectedonly'));
191
-
192
- avh_doWidgetFormCheckbox($this->get_field_id('count'), $this->get_field_name('count'), __('Show post counts', 'avh-ec'), (bool) avhGetArrayValue($instance, 'count'));
193
-
194
- avh_doWidgetFormCheckbox($this->get_field_id('hierarchical'), $this->get_field_name('hierarchical'), __('Show hierarchy', 'avh-ec'), (bool) avhGetArrayValue($instance, 'hierarchical'));
195
-
196
- $options = array(0 => __('All Levels', 'avh-ec'), 1 => __('Toplevel only', 'avh-ec'));
197
- for ($i = 2; $i <= 11; $i++) {
198
- $options[$i] = __('Child ', 'avh-ec') . ($i - 1);
199
- }
200
- avh_doWidgetFormSelect($this->get_field_id('depth'), $this->get_field_name('depth'), __('How many levels to show', 'avh-ec'), $options, $depth);
201
- unset($options);
202
 
203
- avh_doWidgetFormCheckbox($this->get_field_id('hide_empty'), $this->get_field_name('hide_empty'), __('Hide empty categories', 'avh-ec'), (bool) avhGetArrayValue($instance, 'hide_empty'));
204
-
205
- 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'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
206
  echo '</p>';
207
 
208
  echo '<p>';
@@ -210,216 +288,102 @@ class WP_Widget_AVH_ExtendedCategories_Normal extends WP_Widget
210
  $options['name'] = __('Name', 'avh-ec');
211
  $options['count'] = __('Count', 'avh-ec');
212
  $options['slug'] = __('Slug', 'avh-ec');
213
- $options['avhec_manualorder'] = 'AVH EC ' . __('Manual Order', 'avh-ec');
214
- if (is_plugin_active('my-category-order/mycategoryorder.php')) {
215
- $options['avhec_3rdparty_mycategoryorder'] = 'My Category Order';
216
- }
217
-
218
- avh_doWidgetFormSelect($this->get_field_id('sort_column'), $this->get_field_name('sort_column'), __('Sort by', 'avh-ec'), $options, avhGetArrayValue($instance, 'sort_column'));
 
219
  unset($options);
220
 
221
  $options['asc'] = __('Ascending', 'avh-ec');
222
  $options['desc'] = __('Descending', 'avh-ec');
223
- avh_doWidgetFormSelect($this->get_field_id('sort_order'), $this->get_field_name('sort_order'), __('Sort order', 'avh-ec'), $options, avhGetArrayValue($instance, 'sort_order'));
 
 
 
 
 
 
224
  unset($options);
225
 
226
  $options['list'] = __('List', 'avh-ec');
227
  $options['drop'] = __('Drop down', 'avh-ec');
228
- avh_doWidgetFormSelect($this->get_field_id('style'), $this->get_field_name('style'), __('Display style', 'avh-ec'), $options, avhGetArrayValue($instance, 'style'));
 
 
 
 
 
 
229
  unset($options);
230
  echo '</p>';
231
 
232
  echo '<p>';
233
 
234
- avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), $this->get_field_name('rssfeed'), __('Show RSS Feed', 'avh-ec'), (bool) avhGetArrayValue($instance, 'rssfeed'));
235
-
236
- avh_doWidgetFormText($this->get_field_id('rssimage'), $this->get_field_name('rssimage'), __('Path (URI) to RSS image', 'avh-ec'), avhGetArrayValue($instance, 'rssimage'));
237
-
 
 
 
 
 
 
 
 
 
238
  echo '</p>';
239
 
240
  echo '<p>';
241
- echo '<b>' . __('Select categories', 'avh-ec') . '</b><hr />';
242
- 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;">';
243
- echo '<li id="' . $this->get_field_id('category--1') . '" class="popular-category">';
244
- echo '<label for="' . $this->get_field_id('post_category') . '" class="selectit">';
245
- 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' : '') . '> ';
246
- _e('All Categories', 'avh-ec');
 
 
 
 
 
 
247
  echo '</label>';
248
  echo '</li>';
249
- ob_start();
250
- $this->avh_wp_category_checklist($selected_cats, $this->number);
251
- ob_end_flush();
252
- echo '</ul>';
253
- echo '</p>';
254
-
255
- echo '<p>';
256
- 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'));
257
- echo '</p>';
258
-
259
- echo '<input type="hidden" id="' . $this->get_field_id('submit') . '" name="' . $this->get_field_name('submit') . '" value="1" />';
260
- }
261
-
262
- /**
263
- * Creates the categories checklist
264
- *
265
- * @param int $post_id
266
- * @param int $descendants_and_self
267
- * @param array $selected_cats
268
- * @param array $popular_cats
269
- * @param int $number
270
- */
271
- public function avh_wp_category_checklist($selected_cats, $number)
272
- {
273
- $walker = new AVH_Walker_Category_Checklist();
274
- $walker->number = $number;
275
- $walker->input_id = $this->get_field_id('post_category');
276
- $walker->input_name = $this->get_field_name('post_category');
277
- $walker->li_id = $this->get_field_id('category--1');
278
-
279
- $args = array('taxonomy' => 'category', 'descendants_and_self' => 0, 'selected_cats' => $selected_cats, 'popular_cats' => array(), 'walker' => $walker, 'checked_ontop' => true, 'popular_cats' => array());
280
-
281
- if (is_array($selected_cats)) {
282
- $args['selected_cats'] = $selected_cats;
283
- } else {
284
- $args['selected_cats'] = array();
285
- }
286
-
287
- $categories = $this->core->getCategories();
288
- $_categories_id = $this->core->getCategoriesId($categories);
289
-
290
- // 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)
291
- $checked_categories = array();
292
- foreach ($args['selected_cats'] as $key => $value) {
293
- if (isset($_categories_id[$key])) {
294
- $category_key = $_categories_id[$key];
295
- $checked_categories[] = $categories[$category_key];
296
- unset($categories[$category_key]);
297
- }
298
- }
299
-
300
- // Put checked cats on top
301
- echo $walker->walk($checked_categories, 0, $args);
302
- // Then the rest of them
303
- echo $walker->walk($categories, 0, $args);
304
- }
305
- }
306
-
307
- /**
308
- * Widget Class for displaying the top categories
309
- */
310
- class WP_Widget_AVH_ExtendedCategories_Top extends WP_Widget
311
- {
312
-
313
- /**
314
- *
315
- * @var AVH_EC_Core
316
- */
317
- public $core;
318
 
319
- /**
320
- * PHP 5 Constructor
321
- */
322
- public function __construct()
323
- {
324
- $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core');
325
 
326
- $widget_ops = array('description' => __("Shows the top categories.", 'avh-ec'));
327
- WP_Widget::__construct(false, 'AVH Extended Categories: ' . __('Top Categories'), $widget_ops);
328
- add_action('wp_print_styles', array($this, 'actionWpPrintStyles'));
329
- }
330
 
331
- public function actionWpPrintStyles()
332
- {
333
- if (!(false === is_active_widget(false, false, $this->id_base, true))) {
334
- wp_register_style('avhec-widget', AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', array(), $this->core->version);
335
- wp_enqueue_style('avhec-widget');
336
- }
337
  }
338
 
339
- /**
340
- * Echo the widget content.
341
- *
342
- * Subclasses should over-ride this function to generate their widget code.
343
- *
344
- * @param array $args
345
- * Display arguments including before_title, after_title, before_widget, and after_widget.
346
- * @param array $instance
347
- * The settings for the particular instance of the widget
348
- */
349
- public function widget($args, $instance)
350
  {
351
- extract($args);
352
-
353
- $title = apply_filters('widget_title', empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']);
354
- $style = empty($instance['style']) ? 'list' : $instance['style'];
355
- if (!$a = (int) $instance['amount']) {
356
- $a = 5;
357
- } elseif ($a < 1) {
358
- $a = 1;
359
- }
360
- $c = $instance['count'];
361
- $use_desc_for_title = $instance['use_desc_for_title'];
362
- $s = isset($instance['sort_column']) ? $instance['sort_column'] : 'name';
363
- $o = isset($instance['sort_order']) ? $instance['sort_order'] : 'asc';
364
- $r = ($instance['rssfeed'] === true) ? 'RSS' : '';
365
- $i = isset($instance['rssimage']) ? $instance['rssimage'] : '';
366
- if (empty($r)) {
367
- $i = '';
368
- }
369
- if (!empty($i)) {
370
- if (!file_exists(ABSPATH . '/' . $i)) {
371
- $i = '';
372
- }
373
- }
374
-
375
- $options = $this->core->getOptions();
376
- $show_option_none = __('Select Category', 'avh-ec');
377
- if ($options['general']['alternative_name_select_category']) {
378
- $show_option_none = $options['general']['alternative_name_select_category'];
379
  }
 
380
 
381
- $top_cats = get_terms('category', array('fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => $a, 'hierarchical' => false));
382
- $included_cats = implode(",", $top_cats);
383
-
384
- $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);
385
- echo $before_widget;
386
- echo $this->core->comment;
387
- echo $before_title . $title . $after_title;
388
- echo '<ul>';
389
-
390
- if ($style == 'list') {
391
- wp_list_categories($cat_args);
392
- } else {
393
- $cat_args['name'] = 'extended-categories-top-select-' . $this->number;
394
- wp_dropdown_categories($cat_args);
395
- echo '<script type=\'text/javascript\'>' . "\n";
396
- echo '/* <![CDATA[ */' . "\n";
397
- echo ' var ec_dropdown_top_' . $this->number . ' = document.getElementById("extended-categories-top-select-' . $this->number . '");' . "\n";
398
- echo ' function ec_top_onCatChange_' . $this->number . '() {' . "\n";
399
- echo ' if (ec_dropdown_top_' . $this->number . '.options[ec_dropdown_top_' . $this->number . '.selectedIndex].value > 0) {' . "\n";
400
- echo ' location.href = "' . get_option('home') . '/?cat="+ec_dropdown_top_' . $this->number . '.options[ec_dropdown_top_' . $this->number . '.selectedIndex].value;' . "\n";
401
- echo ' }' . "\n";
402
- echo ' }' . "\n";
403
- echo ' ec_dropdown_top_' . $this->number . '.onchange = ec_top_onCatChange_' . $this->number . ';' . "\n";
404
- echo '/* ]]> */' . "\n";
405
- echo '</script>' . "\n";
406
- }
407
- echo '</ul>';
408
- echo $after_widget;
409
  }
410
 
411
  /**
412
- * Update a particular instance.
413
- *
414
- * This function should check that $new_instance is set correctly.
415
- * The newly calculated value of $instance should be returned.
416
- * If "false" is returned, the instance won't be saved/updated.
417
  *
418
  * @param array $new_instance
419
- * New settings for this instance as input by the user via form()
420
  * @param array $old_instance
421
- * Old settings for this instance
422
- * @return array Settings to save or bool false to cancel saving
423
  */
424
  public function update($new_instance, $old_instance)
425
  {
@@ -431,150 +395,56 @@ class WP_Widget_AVH_ExtendedCategories_Top extends WP_Widget
431
  $instance = $old_instance;
432
 
433
  $instance['title'] = strip_tags(stripslashes($new_instance['title']));
434
- $instance['amount'] = (int) $new_instance['amount'];
435
  $instance['count'] = isset($new_instance['count']);
 
 
436
  $instance['use_desc_for_title'] = isset($new_instance['use_desc_for_title']);
437
  $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column']));
438
  $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order']));
439
  $instance['style'] = strip_tags(stripslashes($new_instance['style']));
440
  $instance['rssfeed'] = isset($new_instance['rssfeed']);
441
  $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage']));
 
 
 
 
 
442
 
443
  return $instance;
444
  }
445
 
446
  /**
447
- * Echo the settings update form
448
  *
 
449
  * @param array $instance
450
- * Current settings
451
  */
452
- public function form($instance)
453
  {
454
- // displays the widget admin form
455
- $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => '', 'amount' => '5'));
456
-
457
- $amount = (int) avhGetArrayValue($instance, 'amount');
458
- if ($amount < 1) {
459
- $amount = 1;
460
- }
461
- echo '<p>';
462
- avh_doWidgetFormText($this->get_field_id('title'), $this->get_field_name('title'), __('Title', 'avh-ec'), avhGetArrayValue($instance, 'title'));
463
- echo '</p>';
464
-
465
- echo '<p>';
466
- avh_doWidgetFormText($this->get_field_id('amount'), $this->get_field_name('amount'), __('How many categories to show', 'avh-ec'), $amount);
467
- echo '</p>';
468
-
469
- echo '<p>';
470
- avh_doWidgetFormCheckbox($this->get_field_id('count'), $this->get_field_name('count'), __('Show post counts', 'avh-ec'), (bool) avhGetArrayValue($instance, 'count'));
471
- echo '<br />';
472
-
473
- 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'));
474
- echo '</p>';
475
-
476
- echo '<p>';
477
- $options['ID'] = __('ID', 'avh-ec');
478
- $options['name'] = __('Name', 'avh-ec');
479
- $options['count'] = __('Count', 'avh-ec');
480
- $options['slug'] = __('Slug', 'avh-ec');
481
- avh_doWidgetFormSelect($this->get_field_id('sort_column'), $this->get_field_name('sort_column'), __('Sort by', 'avh-ec'), $options, avhGetArrayValue($instance, 'sort_column'));
482
- unset($options);
483
-
484
- $options['asc'] = __('Ascending', 'avh-ec');
485
- $options['desc'] = __('Descending', 'avh-ec');
486
- avh_doWidgetFormSelect($this->get_field_id('sort_order'), $this->get_field_name('sort_order'), __('Sort order', 'avh-ec'), $options, avhGetArrayValue($instance, 'sort_order'));
487
- unset($options);
488
-
489
- $options['list'] = __('List', 'avh-ec');
490
- $options['drop'] = __('Drop down', 'avh-ec');
491
- avh_doWidgetFormSelect($this->get_field_id('style'), $this->get_field_name('style'), __('Display style', 'avh-ec'), $options, avhGetArrayValue($instance, 'style'));
492
- unset($options);
493
- echo '</p>';
494
-
495
- echo '<p>';
496
 
497
- avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), $this->get_field_name('rssfeed'), __('Show RSS Feed', 'avh-ec'), (bool) avhGetArrayValue($instance, 'rssfeed'));
 
498
 
499
- avh_doWidgetFormText($this->get_field_id('rssimage'), $this->get_field_name('rssimage'), __('Path (URI) to RSS image', 'avh-ec'), avhGetArrayValue($instance, 'rssimage'));
500
 
501
- echo '</p>';
502
-
503
- echo '<input type="hidden" id="' . $this->get_field_id('submit') . '" name="' . $this->get_field_name('submit') . '" value="1" />';
504
- }
505
- }
506
-
507
- /**
508
- * Widget Class for displaying the grouped categories
509
- */
510
- class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget
511
- {
512
-
513
- /**
514
- *
515
- * @var AVH_EC_Core
516
- */
517
- public $core;
518
-
519
- /**
520
- *
521
- * @var AVH_EC_Category_Group
522
- */
523
- public $catgrp;
524
-
525
- /**
526
- * PHP 5 Constructor
527
- */
528
- public function __construct()
529
- {
530
- $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core');
531
- $this->catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
532
-
533
- $widget_ops = array('description' => __("Shows grouped categories.", 'avh-ec'));
534
- WP_Widget::__construct(false, 'AVH Extended Categories: ' . __('Category Group'), $widget_ops);
535
- add_action('wp_print_styles', array($this, 'actionWpPrintStyles'));
536
- }
537
-
538
- public function actionWpPrintStyles()
539
- {
540
- if (!(false === is_active_widget(false, false, $this->id_base, true))) {
541
- wp_register_style('avhec-widget', AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', array(), $this->core->version);
542
- wp_enqueue_style('avhec-widget');
543
- }
544
- }
545
-
546
- /**
547
- * Display the widget
548
- *
549
- * @param unknown_type $args
550
- * @param unknown_type $instance
551
- */
552
- public function widget($args, $instance)
553
- {
554
- global $post, $wp_query;
555
-
556
- $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
557
- $options = $this->core->getOptions();
558
-
559
- $row = array();
560
-
561
- if (is_home()) {
562
- $special_page = 'home_group';
563
- } elseif (is_category()) {
564
- $special_page = 'category_group';
565
- } elseif (is_day()) {
566
- $special_page = 'day_group';
567
- } elseif (is_month()) {
568
- $special_page = 'month_group';
569
- } elseif (is_year()) {
570
- $special_page = 'year_group';
571
- } elseif (is_author()) {
572
- $special_page = 'author_group';
573
- } elseif (is_search()) {
574
- $special_page = 'search_group';
575
- } else {
576
- $special_page = 'none';
577
- }
578
 
579
  $toDisplay = false;
580
  if ('none' == $special_page) {
@@ -609,7 +479,11 @@ class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget
609
  } else {
610
  $sp_category_group_id = $options['sp_cat_group'][$special_page];
611
  }
612
- $row = get_term_by('id', $sp_category_group_id, $catgrp->taxonomy_name); // Returns false when non-existance. (empty(false)=true)
 
 
 
 
613
  $group_found = true;
614
  }
615
 
@@ -663,7 +537,19 @@ class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget
663
  $show_option_none = $options['general']['alternative_name_select_category'];
664
  }
665
 
666
- $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);
 
 
 
 
 
 
 
 
 
 
 
 
667
  echo $before_widget;
668
  echo $this->core->comment;
669
  echo $before_title . $title . $after_title;
@@ -677,26 +563,318 @@ class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget
677
  $this->core->avh_wp_dropdown_categories($cat_args, true);
678
  echo '<script type=\'text/javascript\'>' . "\n";
679
  echo '/* <![CDATA[ */' . "\n";
680
- echo ' var ec_dropdown_' . $this->number . ' = document.getElementById("extended-categories-select-group-' . $this->number . '");' . "\n";
 
 
 
 
 
681
  echo ' function ec_onCatChange_' . $this->number . '() {' . "\n";
682
- echo ' if (ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value > 0) {' . "\n";
683
- echo ' location.href = "' . get_option('home') . '/?cat="+ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value;' . "\n";
 
 
 
 
 
 
 
 
 
 
 
 
684
  echo ' }' . "\n";
685
  echo ' }' . "\n";
686
- echo ' ec_dropdown_' . $this->number . '.onchange = ec_onCatChange_' . $this->number . ';' . "\n";
 
 
 
 
 
687
  echo '/* ]]> */' . "\n";
688
  echo '</script>' . "\n";
689
  }
690
  echo $after_widget;
691
  }
692
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
693
 
694
  /**
695
  * When Widget Control Form Is Posted
696
  *
697
- * @param unknown_type $new_instance
698
- * @param unknown_type $old_instance
699
- * @return unknown
 
700
  */
701
  public function update($new_instance, $old_instance)
702
  {
@@ -708,6 +886,7 @@ class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget
708
  $instance = $old_instance;
709
 
710
  $instance['title'] = strip_tags(stripslashes($new_instance['title']));
 
711
  $instance['count'] = isset($new_instance['count']);
712
  $instance['hierarchical'] = isset($new_instance['hierarchical']);
713
  $instance['hide_empty'] = isset($new_instance['hide_empty']);
@@ -717,40 +896,227 @@ class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget
717
  $instance['style'] = strip_tags(stripslashes($new_instance['style']));
718
  $instance['rssfeed'] = isset($new_instance['rssfeed']);
719
  $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage']));
720
- if (array_key_exists('all', $new_instance['post_group_category'])) {
721
- $instance['post_group_category'] = false;
722
  } else {
723
- $instance['post_group_category'] = serialize($new_instance['post_group_category']);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
724
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
725
 
726
- return $instance;
 
 
 
 
 
 
 
 
 
 
727
  }
728
 
729
  /**
730
- * Display Widget Control Form
 
 
731
  *
732
- * @param unknown_type $instance
733
  */
734
  public function form($instance)
735
  {
736
  // displays the widget admin form
737
- $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => ''));
738
 
739
- $selected_cats = (avhGetArrayValue($instance, 'post_group_category') !== '') ? unserialize($instance['post_group_category']) : false;
740
- ob_start();
 
 
741
  echo '<p>';
742
- avh_doWidgetFormText($this->get_field_id('title'), $this->get_field_name('title'), __('Title', 'avh-ec'), $instance['title']);
 
 
 
 
 
743
  echo '</p>';
744
 
745
  echo '<p>';
 
 
 
 
 
 
 
746
 
747
- avh_doWidgetFormCheckbox($this->get_field_id('count'), $this->get_field_name('count'), __('Show post counts', 'avh-ec'), (bool) avhGetArrayValue($instance, 'count'));
748
-
749
- avh_doWidgetFormCheckbox($this->get_field_id('hierarchical'), $this->get_field_name('hierarchical'), __('Show hierarchy', 'avh-ec'), (bool) avhGetArrayValue($instance, 'hierarchical'));
750
-
751
- avh_doWidgetFormCheckbox($this->get_field_id('hide_empty'), $this->get_field_name('hide_empty'), __('Hide empty categories', 'avh-ec'), (bool) avhGetArrayValue($instance, 'hide_empty'));
 
 
 
752
 
753
- 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'));
 
 
 
 
 
754
  echo '</p>';
755
 
756
  echo '<p>';
@@ -758,228 +1124,209 @@ class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget
758
  $options['name'] = __('Name', 'avh-ec');
759
  $options['count'] = __('Count', 'avh-ec');
760
  $options['slug'] = __('Slug', 'avh-ec');
761
- avh_doWidgetFormSelect($this->get_field_id('sort_column'), $this->get_field_name('sort_column'), __('Sort by', 'avh-ec'), $options, avhGetArrayValue($instance, 'sort_column'));
 
 
 
 
 
 
762
  unset($options);
763
 
764
  $options['asc'] = __('Ascending', 'avh-ec');
765
  $options['desc'] = __('Descending', 'avh-ec');
766
- avh_doWidgetFormSelect($this->get_field_id('sort_order'), $this->get_field_name('sort_order'), __('Sort order', 'avh-ec'), $options, avhGetArrayValue($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'), $this->get_field_name('style'), __('Display style', 'avh-ec'), $options, avhGetArrayValue($instance, 'style'));
 
 
 
 
 
 
772
  unset($options);
773
  echo '</p>';
774
 
775
  echo '<p>';
776
 
777
- avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), $this->get_field_name('rssfeed'), __('Show RSS Feed', 'avh-ec'), (bool) avhGetArrayValue($instance, 'rssfeed'));
778
-
779
- avh_doWidgetFormText($this->get_field_id('rssimage'), $this->get_field_name('rssimage'), __('Path (URI) to RSS image', 'avh-ec'), avhGetArrayValue($instance, 'rssimage'));
780
- echo '</p>';
781
-
782
- echo '<p>';
783
- echo '<b>' . __('Select Groups', 'avh-ec') . '</b><hr />';
784
- 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;">';
785
- echo '<li id="' . $this->get_field_id('group_category--1') . '" class="popular-group_category">';
786
- echo '<label for="' . $this->get_field_id('group_post_category') . '" class="selectit">';
787
- 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' : '') . '> ';
788
- _e('Any Group', 'avh-ec');
789
- echo '</label>';
790
- echo '</li>';
791
 
792
- $this->avh_wp_group_category_checklist($selected_cats, $this->number);
 
 
 
 
 
793
 
794
- echo '</ul>';
795
  echo '</p>';
796
 
797
- echo '<input type="hidden" id="' . $this->get_field_id('submit') . '" name="' . $this->get_field_name('submit') . '" value="1" />';
798
- ob_end_flush();
 
 
 
799
  }
800
 
801
- public function avh_wp_group_category_checklist($selected_cats, $number)
 
 
 
 
 
 
 
 
 
 
 
802
  {
803
- $walker = new AVH_Walker_Category_Checklist();
804
- $walker->number = $number;
805
- $walker->input_id = $this->get_field_id('post_group_category');
806
- $walker->input_name = $this->get_field_name('post_group_category');
807
- $walker->li_id = $this->get_field_id('group_category--1');
808
-
809
- $args = array('taxonomy' => 'avhec_catgroup', 'descendants_and_self' => 0, 'selected_cats' => array(), 'popular_cats' => array(), 'walker' => $walker, 'checked_ontop' => true);
810
-
811
- if (is_array($selected_cats)) {
812
- $args['selected_cats'] = $selected_cats;
813
- } else {
814
- $args['selected_cats'] = array();
815
- }
816
-
817
- $categories = (array) get_terms($args['taxonomy'], array('get' => 'all'));
818
-
819
- // 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)
820
- $checked_categories = array();
821
- $keys = array_keys($categories);
822
-
823
- foreach ($keys as $k) {
824
- if (in_array($categories[$k]->term_id, $args['selected_cats'])) {
825
- $checked_categories[] = $categories[$k];
826
- unset($categories[$k]);
827
- }
828
  }
829
 
830
- // Put checked cats on top
831
- echo $walker->walk($checked_categories, 0, $args);
832
- // Then the rest of them
833
- echo $walker->walk($categories, 0, $args);
834
- }
835
 
836
- public function getWidgetDoneCatGroup($id)
837
- {
838
- $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
839
- if (is_array($catgrp->widget_done_catgroup) && array_key_exists($id, $catgrp->widget_done_catgroup)) {
840
- return true;
841
- }
842
- $catgrp->widget_done_catgroup[$id] = true;
 
 
843
 
844
- return false;
845
  }
846
- }
847
-
848
- /**
849
- * Class that will display the categories
850
- */
851
- class AVH_Walker_Category_Checklist extends Walker
852
- {
853
-
854
- public $tree_type = 'category';
855
-
856
- public $db_fields = array('parent' => 'parent', 'id' => 'term_id'); // TODO: decouple this
857
- public $number;
858
-
859
- public $input_id;
860
-
861
- public $input_name;
862
-
863
- public $li_id;
864
 
865
  /**
866
- * Display array of elements hierarchically.
867
- *
868
- * It is a generic function which does not assume any existing order of
869
- * elements. max_depth = -1 means flatly display every element. max_depth =
870
- * 0 means display all levels. max_depth > 0 specifies the number of
871
- * display levels.
872
- *
873
- * @since 2.1.0
874
  *
875
- * @param array $elements
876
- * @param int $max_depth
877
- * @param array $args;
878
- * @return string
879
  */
880
- public function walk($elements, $max_depth)
881
  {
882
- $args = array_slice(func_get_args(), 2);
883
- $output = '';
884
-
885
- if ($max_depth < -1) {
886
- return $output;
887
- }
888
-
889
- if (empty($elements)) { // nothing to walk
890
- return $output;
891
- }
892
-
893
- $id_field = $this->db_fields['id'];
894
- $parent_field = $this->db_fields['parent'];
895
-
896
- // flat display
897
- if (-1 == $max_depth) {
898
- $empty_array = array();
899
- foreach ($elements as $e) {
900
- $this->display_element($e, $empty_array, 1, 0, $args, $output);
901
- }
902
 
903
- return $output;
 
 
 
 
 
 
 
 
904
  }
905
-
906
- /*
907
- * 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.
908
- */
909
- $top_level_elements = array();
910
- $children_elements = array();
911
- foreach ($elements as $e) {
912
- if (0 == $e->$parent_field) {
913
- $top_level_elements[] = $e;
914
- } else {
915
- $children_elements[$e->$parent_field][] = $e;
916
- }
917
  }
918
-
919
- /*
920
- * when none of the elements is top level assume the first one must be root of the sub elements
921
- */
922
- if (empty($top_level_elements)) {
923
-
924
- $first = array_slice($elements, 0, 1);
925
- $root = $first[0];
926
-
927
- $top_level_elements = array();
928
- $children_elements = array();
929
- foreach ($elements as $e) {
930
- if ($root->$parent_field == $e->$parent_field) {
931
- $top_level_elements[] = $e;
932
- } else {
933
- $children_elements[$e->$parent_field][] = $e;
934
- }
935
  }
936
  }
937
 
938
- foreach ($top_level_elements as $e) {
939
- $this->display_element($e, $children_elements, $max_depth, 0, $args, $output);
940
- }
941
-
942
- /*
943
- * if we are displaying all levels, and remaining children_elements is not empty, then we got orphans, which should be displayed regardless
944
- */
945
- if (($max_depth == 0) && count($children_elements) > 0) {
946
- $empty_array = array();
947
- foreach ($children_elements as $orphans) {
948
- foreach ($orphans as $op) {
949
- $this->display_element($op, $empty_array, 1, 0, $args, $output);
950
- }
951
- }
952
  }
953
 
954
- return $output;
955
- }
956
-
957
- public function start_lvl(&$output, $depth = 0, $args = array())
958
- {
959
- $indent = str_repeat("\t", $depth);
960
- $output .= $indent . '<ul class="children">' . "\n";
961
- }
 
 
 
962
 
963
- public function end_lvl(&$output, $depth = 0, $args = array())
964
- {
965
- $indent = str_repeat("\t", $depth);
966
- $output .= $indent . '</ul>' . "\n";
967
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
968
 
969
- public function start_el(&$output, $object, $depth = 0, $args = array(), $current_object_id = 0)
970
- {
971
- extract($args);
972
- if (!isset($selected_cats)) {
973
- $selected_cats = array();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
974
  }
975
- $input_id = $this->input_id . '-' . $object->term_id;
976
- $output .= "\n" . '<li id="' . $this->li_id . '">';
977
- $output .= '<label for="' . $input_id . '" class="selectit">';
978
- $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>';
979
- }
980
-
981
- public function end_el(&$output, $object, $depth = 0, $args = array())
982
- {
983
- $output .= "</li>\n";
984
  }
985
  }
1
  <?php
2
 
3
  /**
4
+ * Class that will display the categories
 
5
  */
6
+ class AVH_Walker_Category_Checklist extends Walker
7
  {
8
+ public $db_fields = array('parent' => 'parent', 'id' => 'term_id');
9
+ public $input_id; // TODO: decouple this
10
+ public $input_name;
11
+ public $li_id;
12
+ public $number;
13
+ public $tree_type = 'category';
14
 
15
+ public function end_el(&$output, $object, $depth = 0, $args = array())
16
+ {
17
+ $output .= "</li>\n";
18
+ }
 
19
 
20
+ public function end_lvl(&$output, $depth = 0, $args = array())
 
 
 
21
  {
22
+ $indent = str_repeat("\t", $depth);
23
+ $output .= $indent . '</ul>' . "\n";
24
+ }
25
 
26
+ public function start_el(&$output, $object, $depth = 0, $args = array(), $current_object_id = 0)
27
+ {
28
+ extract($args);
29
+ if (!isset($selected_cats)) {
30
+ $selected_cats = array();
31
  }
32
+ $input_id = $this->input_id . '-' . $object->term_id;
33
+ $output .= "\n" . '<li id="' . $this->li_id . '">';
34
+ $output .= '<label for="' . $input_id . '" class="selectit">';
35
+ $output .= '<input value="' .
36
+ $object->term_id .
37
+ '" type="checkbox" name="' .
38
+ $this->input_name .
39
+ '[' .
40
+ $object->term_id .
41
+ ']" id="' .
42
+ $input_id .
43
+ '"' .
44
+ (in_array($object->term_id, $selected_cats) ? ' checked="checked"' : "") .
45
+ '/> ' .
46
+ esc_html(apply_filters('the_category', $object->name)) .
47
+ '</label>';
48
  }
49
 
50
+ public function start_lvl(&$output, $depth = 0, $args = array())
51
  {
52
+ $indent = str_repeat("\t", $depth);
53
+ $output .= $indent . '<ul class="children">' . "\n";
 
 
54
  }
55
 
56
  /**
57
+ * Display array of elements hierarchically.
58
+ * It is a generic function which does not assume any existing order of
59
+ * elements. max_depth = -1 means flatly display every element. max_depth =
60
+ * 0 means display all levels. max_depth > 0 specifies the number of
61
+ * display levels.
62
  *
63
+ * @since 2.1.0
64
+ *
65
+ * @param array $elements
66
+ * @param int $max_depth
67
+ *
68
+ * @return string
69
  */
70
+ public function walk($elements, $max_depth)
71
  {
72
+ $args = array_slice(func_get_args(), 2);
73
+ $output = '';
 
 
 
 
 
 
 
 
 
 
 
74
 
75
+ if ($max_depth < -1) {
76
+ return $output;
77
  }
78
 
79
+ if (empty($elements)) { // nothing to walk
80
+ return $output;
81
  }
82
 
83
+ $id_field = $this->db_fields['id'];
84
+ $parent_field = $this->db_fields['parent'];
85
 
86
+ // flat display
87
+ if (-1 == $max_depth) {
88
+ $empty_array = array();
89
+ foreach ($elements as $e) {
90
+ $this->display_element($e, $empty_array, 1, 0, $args, $output);
 
 
 
91
  }
92
+
93
+ return $output;
94
  }
95
 
96
+ /*
97
+ * 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.
98
+ */
99
+ $top_level_elements = array();
100
+ $children_elements = array();
101
+ foreach ($elements as $e) {
102
+ if (0 == $e->$parent_field) {
103
+ $top_level_elements[] = $e;
104
+ } else {
105
+ $children_elements[$e->$parent_field][] = $e;
106
+ }
107
  }
108
 
109
+ /*
110
+ * when none of the elements is top level assume the first one must be root of the sub elements
111
+ */
112
+ if (empty($top_level_elements)) {
113
+
114
+ $first = array_slice($elements, 0, 1);
115
+ $root = $first[0];
116
+
117
+ $top_level_elements = array();
118
+ $children_elements = array();
119
+ foreach ($elements as $e) {
120
+ if ($root->$parent_field == $e->$parent_field) {
121
+ $top_level_elements[] = $e;
122
+ } else {
123
+ $children_elements[$e->$parent_field][] = $e;
124
+ }
125
+ }
126
  }
127
 
128
+ foreach ($top_level_elements as $e) {
129
+ $this->display_element($e, $children_elements, $max_depth, 0, $args, $output);
130
+ }
 
131
 
132
+ /*
133
+ * if we are displaying all levels, and remaining children_elements is not empty, then we got orphans, which should be displayed regardless
134
+ */
135
+ if (($max_depth == 0) && count($children_elements) > 0) {
136
+ $empty_array = array();
137
+ foreach ($children_elements as $orphans) {
138
+ foreach ($orphans as $op) {
139
+ $this->display_element($op, $empty_array, 1, 0, $args, $output);
140
+ }
141
+ }
 
 
 
 
 
 
 
 
142
  }
143
+
144
+ return $output;
145
  }
146
+ }
147
 
148
+ /**
149
+ * Widget Class for displaying the grouped categories
150
+ */
151
+ class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget
152
+ {
153
  /**
154
+ * @var AVH_EC_Category_Group
 
 
 
 
155
  */
156
+ public $catgrp;
157
+ /**
158
+ * @var AVH_EC_Core
159
+ */
160
+ public $core;
161
+
162
+ /**
163
+ * PHP 5 Constructor
164
+ */
165
+ public function __construct()
166
  {
167
+ $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core');
168
+ $this->catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
169
+
170
+ $widget_ops = array('description' => __("Shows grouped categories.", 'avh-ec'));
171
+ WP_Widget::__construct(false, 'AVH Extended Categories: ' . __('Category Group'), $widget_ops);
172
+ add_action('wp_print_styles', array($this, 'actionWpPrintStyles'));
173
+ }
174
+
175
+ public function actionWpPrintStyles()
176
+ {
177
+ if (!(false === is_active_widget(false, false, $this->id_base, true))) {
178
+ wp_register_style(
179
+ 'avhec-widget',
180
+ AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css',
181
+ array(),
182
+ $this->core->version
183
+ );
184
+ wp_enqueue_style('avhec-widget');
185
  }
186
+ }
187
 
188
+ public function avh_wp_group_category_checklist($selected_cats, $number)
189
+ {
190
+ $walker = new AVH_Walker_Category_Checklist();
191
+ $walker->number = $number;
192
+ $walker->input_id = $this->get_field_id('post_group_category');
193
+ $walker->input_name = $this->get_field_name('post_group_category');
194
+ $walker->li_id = $this->get_field_id('group_category--1');
195
 
196
+ $args = array(
197
+ 'taxonomy' => 'avhec_catgroup',
198
+ 'descendants_and_self' => 0,
199
+ 'selected_cats' => array(),
200
+ 'popular_cats' => array(),
201
+ 'walker' => $walker,
202
+ 'checked_ontop' => true
203
+ );
204
+
205
+ if (is_array($selected_cats)) {
206
+ $args['selected_cats'] = $selected_cats;
 
 
207
  } else {
208
+ $args['selected_cats'] = array();
209
  }
210
+
211
+ $categories = (array) get_terms($args['taxonomy'], array('get' => 'all'));
212
+
213
+ // 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)
214
+ $checked_categories = array();
215
+ $keys = array_keys($categories);
216
+
217
+ foreach ($keys as $k) {
218
+ if (in_array($categories[$k]->term_id, $args['selected_cats'])) {
219
+ $checked_categories[] = $categories[$k];
220
+ unset($categories[$k]);
221
+ }
222
  }
 
223
 
224
+ // Put checked cats on top
225
+ echo $walker->walk($checked_categories, 0, $args);
226
+ // Then the rest of them
227
+ echo $walker->walk($categories, 0, $args);
228
  }
229
 
230
  /**
231
  * Display Widget Control Form
232
  *
233
+ * @param array $instance
234
+ *
235
+ * @return string|void
236
+ */
237
  public function form($instance)
238
  {
239
  // displays the widget admin form
240
+ $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => ''));
 
 
 
 
 
 
 
241
 
242
+ $selected_cats = (avhGetArrayValue($instance, 'post_group_category') !== '') ? unserialize(
243
+ $instance['post_group_category']
244
+ ) : false;
245
+ ob_start();
246
  echo '<p>';
247
+ avh_doWidgetFormText(
248
+ $this->get_field_id('title'),
249
+ $this->get_field_name('title'),
250
+ __('Title', 'avh-ec'),
251
+ $instance['title']
252
+ );
253
  echo '</p>';
254
 
255
  echo '<p>';
 
 
 
 
 
 
 
 
 
 
 
 
256
 
257
+ avh_doWidgetFormCheckbox(
258
+ $this->get_field_id('count'),
259
+ $this->get_field_name('count'),
260
+ __('Show post counts', 'avh-ec'),
261
+ (bool) avhGetArrayValue($instance, 'count')
262
+ );
263
+
264
+ avh_doWidgetFormCheckbox(
265
+ $this->get_field_id('hierarchical'),
266
+ $this->get_field_name('hierarchical'),
267
+ __('Show hierarchy', 'avh-ec'),
268
+ (bool) avhGetArrayValue($instance, 'hierarchical')
269
+ );
270
+
271
+ avh_doWidgetFormCheckbox(
272
+ $this->get_field_id('hide_empty'),
273
+ $this->get_field_name('hide_empty'),
274
+ __('Hide empty categories', 'avh-ec'),
275
+ (bool) avhGetArrayValue($instance, 'hide_empty')
276
+ );
277
+
278
+ avh_doWidgetFormCheckbox(
279
+ $this->get_field_id('use_desc_for_title'),
280
+ $this->get_field_name('use_desc_for_title'),
281
+ __('Use description for title', 'avh-ec'),
282
+ (bool) avhGetArrayValue($instance, 'use_desc_for_title')
283
+ );
284
  echo '</p>';
285
 
286
  echo '<p>';
288
  $options['name'] = __('Name', 'avh-ec');
289
  $options['count'] = __('Count', 'avh-ec');
290
  $options['slug'] = __('Slug', 'avh-ec');
291
+ avh_doWidgetFormSelect(
292
+ $this->get_field_id('sort_column'),
293
+ $this->get_field_name('sort_column'),
294
+ __('Sort by', 'avh-ec'),
295
+ $options,
296
+ avhGetArrayValue($instance, 'sort_column')
297
+ );
298
  unset($options);
299
 
300
  $options['asc'] = __('Ascending', 'avh-ec');
301
  $options['desc'] = __('Descending', 'avh-ec');
302
+ avh_doWidgetFormSelect(
303
+ $this->get_field_id('sort_order'),
304
+ $this->get_field_name('sort_order'),
305
+ __('Sort order', 'avh-ec'),
306
+ $options,
307
+ avhGetArrayValue($instance, 'sort_order')
308
+ );
309
  unset($options);
310
 
311
  $options['list'] = __('List', 'avh-ec');
312
  $options['drop'] = __('Drop down', 'avh-ec');
313
+ avh_doWidgetFormSelect(
314
+ $this->get_field_id('style'),
315
+ $this->get_field_name('style'),
316
+ __('Display style', 'avh-ec'),
317
+ $options,
318
+ avhGetArrayValue($instance, 'style')
319
+ );
320
  unset($options);
321
  echo '</p>';
322
 
323
  echo '<p>';
324
 
325
+ avh_doWidgetFormCheckbox(
326
+ $this->get_field_id('rssfeed'),
327
+ $this->get_field_name('rssfeed'),
328
+ __('Show RSS Feed', 'avh-ec'),
329
+ (bool) avhGetArrayValue($instance, 'rssfeed')
330
+ );
331
+
332
+ avh_doWidgetFormText(
333
+ $this->get_field_id('rssimage'),
334
+ $this->get_field_name('rssimage'),
335
+ __('Path (URI) to RSS image', 'avh-ec'),
336
+ avhGetArrayValue($instance, 'rssimage')
337
+ );
338
  echo '</p>';
339
 
340
  echo '<p>';
341
+ echo '<b>' . __('Select Groups', 'avh-ec') . '</b><hr />';
342
+ echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear" style="list-style-type: none; margin-left: 5px; padding-left: 0; margin-bottom: 20px;">';
343
+ echo '<li id="' . $this->get_field_id('group_category--1') . '" class="popular-group_category">';
344
+ echo '<label for="' . $this->get_field_id('group_post_category') . '" class="selectit">';
345
+ echo '<input value="all" id="' .
346
+ $this->get_field_id('group_post_category') .
347
+ '" name="' .
348
+ $this->get_field_name('post_group_category') .
349
+ '[all]" type="checkbox" ' .
350
+ (false === $selected_cats ? ' CHECKED' : '') .
351
+ '> ';
352
+ _e('Any Group', 'avh-ec');
353
  echo '</label>';
354
  echo '</li>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
355
 
356
+ $this->avh_wp_group_category_checklist($selected_cats, $this->number);
 
 
 
 
 
357
 
358
+ echo '</ul>';
359
+ echo '</p>';
 
 
360
 
361
+ echo '<input type="hidden" id="' .
362
+ $this->get_field_id('submit') .
363
+ '" name="' .
364
+ $this->get_field_name('submit') .
365
+ '" value="1" />';
366
+ ob_end_flush();
367
  }
368
 
369
+ public function getWidgetDoneCatGroup($id)
 
 
 
 
 
 
 
 
 
 
370
  {
371
+ $catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
372
+ if (is_array($catgrp->widget_done_catgroup) && array_key_exists($id, $catgrp->widget_done_catgroup)) {
373
+ return true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
374
  }
375
+ $catgrp->widget_done_catgroup[$id] = true;
376
 
377
+ return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
378
  }
379
 
380
  /**
381
+ * When Widget Control Form Is Posted
 
 
 
 
382
  *
383
  * @param array $new_instance
 
384
  * @param array $old_instance
385
+ *
386
+ * @return array|bool
387
  */
388
  public function update($new_instance, $old_instance)
389
  {
395
  $instance = $old_instance;
396
 
397
  $instance['title'] = strip_tags(stripslashes($new_instance['title']));
 
398
  $instance['count'] = isset($new_instance['count']);
399
+ $instance['hierarchical'] = isset($new_instance['hierarchical']);
400
+ $instance['hide_empty'] = isset($new_instance['hide_empty']);
401
  $instance['use_desc_for_title'] = isset($new_instance['use_desc_for_title']);
402
  $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column']));
403
  $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order']));
404
  $instance['style'] = strip_tags(stripslashes($new_instance['style']));
405
  $instance['rssfeed'] = isset($new_instance['rssfeed']);
406
  $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage']));
407
+ if (array_key_exists('all', $new_instance['post_group_category'])) {
408
+ $instance['post_group_category'] = false;
409
+ } else {
410
+ $instance['post_group_category'] = serialize($new_instance['post_group_category']);
411
+ }
412
 
413
  return $instance;
414
  }
415
 
416
  /**
417
+ * Display the widget
418
  *
419
+ * @param array $args
420
  * @param array $instance
 
421
  */
422
+ public function widget($args, $instance)
423
  {
424
+ global $post, $wp_query;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
425
 
426
+ $catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
427
+ $options = $this->core->getOptions();
428
 
429
+ $row = array();
430
 
431
+ if (is_home()) {
432
+ $special_page = 'home_group';
433
+ } elseif (is_category()) {
434
+ $special_page = 'category_group';
435
+ } elseif (is_day()) {
436
+ $special_page = 'day_group';
437
+ } elseif (is_month()) {
438
+ $special_page = 'month_group';
439
+ } elseif (is_year()) {
440
+ $special_page = 'year_group';
441
+ } elseif (is_author()) {
442
+ $special_page = 'author_group';
443
+ } elseif (is_search()) {
444
+ $special_page = 'search_group';
445
+ } else {
446
+ $special_page = 'none';
447
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
448
 
449
  $toDisplay = false;
450
  if ('none' == $special_page) {
479
  } else {
480
  $sp_category_group_id = $options['sp_cat_group'][$special_page];
481
  }
482
+ $row = get_term_by(
483
+ 'id',
484
+ $sp_category_group_id,
485
+ $catgrp->taxonomy_name
486
+ ); // Returns false when non-existance. (empty(false)=true)
487
  $group_found = true;
488
  }
489
 
537
  $show_option_none = $options['general']['alternative_name_select_category'];
538
  }
539
 
540
+ $cat_args = array(
541
+ 'include' => $included_cats,
542
+ 'orderby' => $s,
543
+ 'order' => $o,
544
+ 'show_count' => $c,
545
+ 'use_desc_for_title' => $use_desc_for_title,
546
+ 'hide_empty' => $e,
547
+ 'hierarchical' => $h,
548
+ 'title_li' => '',
549
+ 'show_option_none' => $show_option_none,
550
+ 'feed' => $r,
551
+ 'feed_image' => $i
552
+ );
553
  echo $before_widget;
554
  echo $this->core->comment;
555
  echo $before_title . $title . $after_title;
563
  $this->core->avh_wp_dropdown_categories($cat_args, true);
564
  echo '<script type=\'text/javascript\'>' . "\n";
565
  echo '/* <![CDATA[ */' . "\n";
566
+ echo ' var ec_dropdown_' .
567
+ $this->number .
568
+ ' = document.getElementById("extended-categories-select-group-' .
569
+ $this->number .
570
+ '");' .
571
+ "\n";
572
  echo ' function ec_onCatChange_' . $this->number . '() {' . "\n";
573
+ echo ' if (ec_dropdown_' .
574
+ $this->number .
575
+ '.options[ec_dropdown_' .
576
+ $this->number .
577
+ '.selectedIndex].value > 0) {' .
578
+ "\n";
579
+ echo ' location.href = "' .
580
+ get_option('home') .
581
+ '/?cat="+ec_dropdown_' .
582
+ $this->number .
583
+ '.options[ec_dropdown_' .
584
+ $this->number .
585
+ '.selectedIndex].value;' .
586
+ "\n";
587
  echo ' }' . "\n";
588
  echo ' }' . "\n";
589
+ echo ' ec_dropdown_' .
590
+ $this->number .
591
+ '.onchange = ec_onCatChange_' .
592
+ $this->number .
593
+ ';' .
594
+ "\n";
595
  echo '/* ]]> */' . "\n";
596
  echo '</script>' . "\n";
597
  }
598
  echo $after_widget;
599
  }
600
  }
601
+ }
602
+
603
+ /**
604
+ * Widget Class for displaying categories.
605
+ * Extended version of the default categories.
606
+ */
607
+ class WP_Widget_AVH_ExtendedCategories_Normal extends WP_Widget
608
+ {
609
+ /**
610
+ * @var AVH_EC_Core
611
+ */
612
+ public $core;
613
+
614
+ /**
615
+ * PHP 5 Constructor
616
+ */
617
+ public function __construct()
618
+ {
619
+ $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core');
620
+
621
+ // Convert the old option widget_extended_categories to widget_extended-categories
622
+ $old = get_option('widget_extended_categories');
623
+ if (!(false === $old)) {
624
+ update_option('widget_extended-categories', $old);
625
+ delete_option('widget_extended_categories');
626
+ }
627
+ $widget_ops = array('description' => __("An extended version of the default Categories widget.", 'avh-ec'));
628
+ WP_Widget::__construct('extended-categories', 'AVH Extended Categories', $widget_ops);
629
+
630
+ add_action('wp_print_styles', array($this, 'actionWpPrintStyles'));
631
+ }
632
+
633
+ public function actionWpPrintStyles()
634
+ {
635
+ if (!(false === is_active_widget(false, false, $this->id_base, true))) {
636
+ wp_register_style(
637
+ 'avhec-widget',
638
+ AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css',
639
+ array(),
640
+ $this->core->version
641
+ );
642
+ wp_enqueue_style('avhec-widget');
643
+ }
644
+ }
645
+
646
+ /**
647
+ * Creates the categories checklist
648
+ *
649
+ * @param array $selected_cats
650
+ * @param int $number
651
+ */
652
+ public function avh_wp_category_checklist($selected_cats, $number)
653
+ {
654
+ $walker = new AVH_Walker_Category_Checklist();
655
+ $walker->number = $number;
656
+ $walker->input_id = $this->get_field_id('post_category');
657
+ $walker->input_name = $this->get_field_name('post_category');
658
+ $walker->li_id = $this->get_field_id('category--1');
659
+
660
+ $args = array(
661
+ 'taxonomy' => 'category',
662
+ 'descendants_and_self' => 0,
663
+ 'selected_cats' => $selected_cats,
664
+ 'popular_cats' => array(),
665
+ 'walker' => $walker,
666
+ 'checked_ontop' => true
667
+ );
668
+
669
+ if (is_array($selected_cats)) {
670
+ $args['selected_cats'] = $selected_cats;
671
+ } else {
672
+ $args['selected_cats'] = array();
673
+ }
674
+
675
+ $categories = $this->core->getCategories();
676
+ $_categories_id = $this->core->getCategoriesId($categories);
677
+
678
+ // 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)
679
+ $checked_categories = array();
680
+ foreach ($args['selected_cats'] as $key => $value) {
681
+ if (isset($_categories_id[$key])) {
682
+ $category_key = $_categories_id[$key];
683
+ $checked_categories[] = $categories[$category_key];
684
+ unset($categories[$category_key]);
685
+ }
686
+ }
687
+
688
+ // Put checked cats on top
689
+ echo $walker->walk($checked_categories, 0, $args);
690
+ // Then the rest of them
691
+ echo $walker->walk($categories, 0, $args);
692
+ }
693
+
694
+ /**
695
+ * Display Widget Control Form
696
+ *
697
+ * @param array $instance
698
+ *
699
+ * @return string|void
700
+ */
701
+ public function form($instance)
702
+ {
703
+ // displays the widget admin form
704
+ $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => '', 'depth' => 0));
705
+
706
+ // Prepare data for display
707
+ $depth = (int) $instance['depth'];
708
+ if ($depth < 0 || 11 < $depth) {
709
+ $depth = 0;
710
+ }
711
+ $selected_cats = (avhGetArrayValue($instance, 'post_category') !== '') ? unserialize(
712
+ $instance['post_category']
713
+ ) : false;
714
+
715
+ echo '<p>';
716
+ avh_doWidgetFormText(
717
+ $this->get_field_id('title'),
718
+ $this->get_field_name('title'),
719
+ __('Title', 'avh-ec'),
720
+ avhGetArrayValue($instance, 'title')
721
+ );
722
+ echo '</p>';
723
+
724
+ echo '<p>';
725
+ avh_doWidgetFormCheckbox(
726
+ $this->get_field_id('selectedonly'),
727
+ $this->get_field_name('selectedonly'),
728
+ __('Show selected categories only', 'avh-ec'),
729
+ (bool) avhGetArrayValue($instance, 'selectedonly')
730
+ );
731
+
732
+ avh_doWidgetFormCheckbox(
733
+ $this->get_field_id('count'),
734
+ $this->get_field_name('count'),
735
+ __('Show post counts', 'avh-ec'),
736
+ (bool) avhGetArrayValue($instance, 'count')
737
+ );
738
+
739
+ avh_doWidgetFormCheckbox(
740
+ $this->get_field_id('hierarchical'),
741
+ $this->get_field_name('hierarchical'),
742
+ __('Show hierarchy', 'avh-ec'),
743
+ (bool) avhGetArrayValue($instance, 'hierarchical')
744
+ );
745
+
746
+ $options = array(0 => __('All Levels', 'avh-ec'), 1 => __('Toplevel only', 'avh-ec'));
747
+ for ($i = 2; $i <= 11; $i++) {
748
+ $options[$i] = __('Child ', 'avh-ec') . ($i - 1);
749
+ }
750
+ avh_doWidgetFormSelect(
751
+ $this->get_field_id('depth'),
752
+ $this->get_field_name('depth'),
753
+ __('How many levels to show', 'avh-ec'),
754
+ $options,
755
+ $depth
756
+ );
757
+ unset($options);
758
+
759
+ avh_doWidgetFormCheckbox(
760
+ $this->get_field_id('hide_empty'),
761
+ $this->get_field_name('hide_empty'),
762
+ __('Hide empty categories', 'avh-ec'),
763
+ (bool) avhGetArrayValue($instance, 'hide_empty')
764
+ );
765
+
766
+ avh_doWidgetFormCheckbox(
767
+ $this->get_field_id('use_desc_for_title'),
768
+ $this->get_field_name('use_desc_for_title'),
769
+ __('Use description for title', 'avh-ec'),
770
+ (bool) avhGetArrayValue($instance, 'use_desc_for_title')
771
+ );
772
+ echo '</p>';
773
+
774
+ echo '<p>';
775
+ $options['ID'] = __('ID', 'avh-ec');
776
+ $options['name'] = __('Name', 'avh-ec');
777
+ $options['count'] = __('Count', 'avh-ec');
778
+ $options['slug'] = __('Slug', 'avh-ec');
779
+ $options['avhec_manualorder'] = 'AVH EC ' . __('Manual Order', 'avh-ec');
780
+ if (is_plugin_active('my-category-order/mycategoryorder.php')) {
781
+ $options['avhec_3rdparty_mycategoryorder'] = 'My Category Order';
782
+ }
783
+
784
+ avh_doWidgetFormSelect(
785
+ $this->get_field_id('sort_column'),
786
+ $this->get_field_name('sort_column'),
787
+ __('Sort by', 'avh-ec'),
788
+ $options,
789
+ avhGetArrayValue($instance, 'sort_column')
790
+ );
791
+ unset($options);
792
+
793
+ $options['asc'] = __('Ascending', 'avh-ec');
794
+ $options['desc'] = __('Descending', 'avh-ec');
795
+ avh_doWidgetFormSelect(
796
+ $this->get_field_id('sort_order'),
797
+ $this->get_field_name('sort_order'),
798
+ __('Sort order', 'avh-ec'),
799
+ $options,
800
+ avhGetArrayValue($instance, 'sort_order')
801
+ );
802
+ unset($options);
803
+
804
+ $options['list'] = __('List', 'avh-ec');
805
+ $options['drop'] = __('Drop down', 'avh-ec');
806
+ avh_doWidgetFormSelect(
807
+ $this->get_field_id('style'),
808
+ $this->get_field_name('style'),
809
+ __('Display style', 'avh-ec'),
810
+ $options,
811
+ avhGetArrayValue($instance, 'style')
812
+ );
813
+ unset($options);
814
+ echo '</p>';
815
+
816
+ echo '<p>';
817
+
818
+ avh_doWidgetFormCheckbox(
819
+ $this->get_field_id('rssfeed'),
820
+ $this->get_field_name('rssfeed'),
821
+ __('Show RSS Feed', 'avh-ec'),
822
+ (bool) avhGetArrayValue($instance, 'rssfeed')
823
+ );
824
+
825
+ avh_doWidgetFormText(
826
+ $this->get_field_id('rssimage'),
827
+ $this->get_field_name('rssimage'),
828
+ __('Path (URI) to RSS image', 'avh-ec'),
829
+ avhGetArrayValue($instance, 'rssimage')
830
+ );
831
+
832
+ echo '</p>';
833
+
834
+ echo '<p>';
835
+ echo '<b>' . __('Select categories', 'avh-ec') . '</b><hr />';
836
+ echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear" style="list-style-type: none; margin-left: 5px; padding-left: 0; margin-bottom: 20px;">';
837
+ echo '<li id="' . $this->get_field_id('category--1') . '" class="popular-category">';
838
+ echo '<label for="' . $this->get_field_id('post_category') . '" class="selectit">';
839
+ echo '<input value="all" id="' .
840
+ $this->get_field_id('post_category') .
841
+ '" name="' .
842
+ $this->get_field_name('post_category') .
843
+ '[all]" type="checkbox" ' .
844
+ (false === $selected_cats ? ' CHECKED' : '') .
845
+ '> ';
846
+ _e('All Categories', 'avh-ec');
847
+ echo '</label>';
848
+ echo '</li>';
849
+ ob_start();
850
+ $this->avh_wp_category_checklist($selected_cats, $this->number);
851
+ ob_end_flush();
852
+ echo '</ul>';
853
+ echo '</p>';
854
+
855
+ echo '<p>';
856
+ avh_doWidgetFormCheckbox(
857
+ $this->get_field_id('invert_included'),
858
+ $this->get_field_name('invert_included'),
859
+ __('Exclude the selected categories', 'avh-ec'),
860
+ (bool) avhGetArrayValue($instance, 'invert_included')
861
+ );
862
+ echo '</p>';
863
+
864
+ echo '<input type="hidden" id="' .
865
+ $this->get_field_id('submit') .
866
+ '" name="' .
867
+ $this->get_field_name('submit') .
868
+ '" value="1" />';
869
+ }
870
 
871
  /**
872
  * When Widget Control Form Is Posted
873
  *
874
+ * @param array $new_instance
875
+ * @param array $old_instance
876
+ *
877
+ * @return array|bool
878
  */
879
  public function update($new_instance, $old_instance)
880
  {
886
  $instance = $old_instance;
887
 
888
  $instance['title'] = strip_tags(stripslashes($new_instance['title']));
889
+ $instance['selectedonly'] = isset($new_instance['selectedonly']);
890
  $instance['count'] = isset($new_instance['count']);
891
  $instance['hierarchical'] = isset($new_instance['hierarchical']);
892
  $instance['hide_empty'] = isset($new_instance['hide_empty']);
896
  $instance['style'] = strip_tags(stripslashes($new_instance['style']));
897
  $instance['rssfeed'] = isset($new_instance['rssfeed']);
898
  $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage']));
899
+ if (array_key_exists('all', $new_instance['post_category'])) {
900
+ $instance['post_category'] = false;
901
  } else {
902
+ $instance['post_category'] = serialize($new_instance['post_category']);
903
+ }
904
+ $instance['depth'] = (int) $new_instance['depth'];
905
+ if ($instance['depth'] < 0 || 11 < $instance['depth']) {
906
+ $instance['depth'] = 0;
907
+ }
908
+ $instance['invert_included'] = isset($new_instance['invert_included']);
909
+
910
+ return $instance;
911
+ }
912
+
913
+ /**
914
+ * Display the widget
915
+ *
916
+ * @param array $args
917
+ * @param array $instance
918
+ */
919
+ public function widget($args, $instance)
920
+ {
921
+ extract($args);
922
+
923
+ $selectedonly = $instance['selectedonly'];
924
+ $c = $instance['count'];
925
+ $h = $instance['hierarchical'];
926
+ $d = $instance['depth'];
927
+ $e = $instance['hide_empty'];
928
+ $use_desc_for_title = $instance['use_desc_for_title'];
929
+ $s = isset($instance['sort_column']) ? $instance['sort_column'] : 'name';
930
+ $o = isset($instance['sort_order']) ? $instance['sort_order'] : 'asc';
931
+ $r = ($instance['rssfeed'] == true) ? 'RSS' : '';
932
+ $i = isset($instance['rssimage']) ? $instance['rssimage'] : '';
933
+ $invert = $instance['invert_included'];
934
+
935
+ if (empty($r)) {
936
+ $i = '';
937
+ }
938
+
939
+ if (empty($d)) {
940
+ $d = 0;
941
+ }
942
+
943
+ $title = apply_filters(
944
+ 'widget_title',
945
+ empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']
946
+ );
947
+ $style = empty($instance['style']) ? 'list' : $instance['style'];
948
+
949
+ $included_cats = '';
950
+ if ($instance['post_category']) {
951
+ $post_category = unserialize($instance['post_category']);
952
+ $children = array();
953
+ if (!$instance['selectedonly']) {
954
+ foreach ($post_category as $cat_id) {
955
+ $children = array_merge($children, get_term_children($cat_id, 'category'));
956
+ }
957
+ }
958
+ $included_cats = implode(",", array_merge($post_category, $children));
959
+ }
960
+
961
+ if ($invert) {
962
+ $inc_exc = 'exclude';
963
+ } else {
964
+ $inc_exc = 'include';
965
+ }
966
+
967
+ $options = $this->core->getOptions();
968
+ $show_option_none = __('Select Category', 'avh-ec');
969
+ if ($options['general']['alternative_name_select_category']) {
970
+ $show_option_none = $options['general']['alternative_name_select_category'];
971
+ }
972
+
973
+ $cat_args = array(
974
+ $inc_exc => $included_cats,
975
+ 'orderby' => $s,
976
+ 'order' => $o,
977
+ 'show_count' => $c,
978
+ 'use_desc_for_title' => $use_desc_for_title,
979
+ 'hide_empty' => $e,
980
+ 'hierarchical' => $h,
981
+ 'depth' => $d,
982
+ 'title_li' => '',
983
+ 'show_option_none' => $show_option_none,
984
+ 'feed' => $r,
985
+ 'feed_image' => $i
986
+ );
987
+ echo $before_widget;
988
+ echo $this->core->comment;
989
+ echo $before_title . $title . $after_title;
990
+
991
+ if ($style == 'list') {
992
+ echo '<ul>';
993
+ $this->core->avh_wp_list_categories($cat_args);
994
+ echo '</ul>';
995
+ } else {
996
+ $cat_args['name'] = 'extended-categories-select-' . $this->number;
997
+ $this->core->avh_wp_dropdown_categories($cat_args);
998
+ echo '<script type=\'text/javascript\'>' . "\n";
999
+ echo '/* <![CDATA[ */' . "\n";
1000
+ echo ' var ec_dropdown_' .
1001
+ $this->number .
1002
+ ' = document.getElementById("extended-categories-select-' .
1003
+ $this->number .
1004
+ '");' .
1005
+ "\n";
1006
+ echo ' function ec_onCatChange_' . $this->number . '() {' . "\n";
1007
+ echo ' if (ec_dropdown_' .
1008
+ $this->number .
1009
+ '.options[ec_dropdown_' .
1010
+ $this->number .
1011
+ '.selectedIndex].value > 0) {' .
1012
+ "\n";
1013
+ echo ' location.href = "' .
1014
+ home_url() .
1015
+ '/?cat="+ec_dropdown_' .
1016
+ $this->number .
1017
+ '.options[ec_dropdown_' .
1018
+ $this->number .
1019
+ '.selectedIndex].value;' .
1020
+ "\n";
1021
+ echo ' }' . "\n";
1022
+ echo ' }' . "\n";
1023
+ echo ' ec_dropdown_' .
1024
+ $this->number .
1025
+ '.onchange = ec_onCatChange_' .
1026
+ $this->number .
1027
+ ';' .
1028
+ "\n";
1029
+ echo '/* ]]> */' . "\n";
1030
+ echo '</script>' . "\n";
1031
  }
1032
+ echo $after_widget;
1033
+ }
1034
+ }
1035
+
1036
+ /**
1037
+ * Widget Class for displaying the top categories
1038
+ */
1039
+ class WP_Widget_AVH_ExtendedCategories_Top extends WP_Widget
1040
+ {
1041
+ /**
1042
+ * @var AVH_EC_Core
1043
+ */
1044
+ public $core;
1045
+
1046
+ /**
1047
+ * PHP 5 Constructor
1048
+ */
1049
+ public function __construct()
1050
+ {
1051
+ $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core');
1052
+
1053
+ $widget_ops = array('description' => __("Shows the top categories.", 'avh-ec'));
1054
+ WP_Widget::__construct(false, 'AVH Extended Categories: ' . __('Top Categories'), $widget_ops);
1055
+ add_action('wp_print_styles', array($this, 'actionWpPrintStyles'));
1056
+ }
1057
 
1058
+ public function actionWpPrintStyles()
1059
+ {
1060
+ if (!(false === is_active_widget(false, false, $this->id_base, true))) {
1061
+ wp_register_style(
1062
+ 'avhec-widget',
1063
+ AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css',
1064
+ array(),
1065
+ $this->core->version
1066
+ );
1067
+ wp_enqueue_style('avhec-widget');
1068
+ }
1069
  }
1070
 
1071
  /**
1072
+ * Echo the settings update form
1073
+ *
1074
+ * @param array $instance Current settings
1075
  *
1076
+ * @return string|void
1077
  */
1078
  public function form($instance)
1079
  {
1080
  // displays the widget admin form
1081
+ $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => '', 'amount' => '5'));
1082
 
1083
+ $amount = (int) avhGetArrayValue($instance, 'amount');
1084
+ if ($amount < 1) {
1085
+ $amount = 1;
1086
+ }
1087
  echo '<p>';
1088
+ avh_doWidgetFormText(
1089
+ $this->get_field_id('title'),
1090
+ $this->get_field_name('title'),
1091
+ __('Title', 'avh-ec'),
1092
+ avhGetArrayValue($instance, 'title')
1093
+ );
1094
  echo '</p>';
1095
 
1096
  echo '<p>';
1097
+ avh_doWidgetFormText(
1098
+ $this->get_field_id('amount'),
1099
+ $this->get_field_name('amount'),
1100
+ __('How many categories to show', 'avh-ec'),
1101
+ $amount
1102
+ );
1103
+ echo '</p>';
1104
 
1105
+ echo '<p>';
1106
+ avh_doWidgetFormCheckbox(
1107
+ $this->get_field_id('count'),
1108
+ $this->get_field_name('count'),
1109
+ __('Show post counts', 'avh-ec'),
1110
+ (bool) avhGetArrayValue($instance, 'count')
1111
+ );
1112
+ echo '<br />';
1113
 
1114
+ avh_doWidgetFormCheckbox(
1115
+ $this->get_field_id('use_desc_for_title'),
1116
+ $this->get_field_name('use_desc_for_title'),
1117
+ __('Use description for title', 'avh-ec'),
1118
+ (bool) avhGetArrayValue($instance, 'use_desc_for_title')
1119
+ );
1120
  echo '</p>';
1121
 
1122
  echo '<p>';
1124
  $options['name'] = __('Name', 'avh-ec');
1125
  $options['count'] = __('Count', 'avh-ec');
1126
  $options['slug'] = __('Slug', 'avh-ec');
1127
+ avh_doWidgetFormSelect(
1128
+ $this->get_field_id('sort_column'),
1129
+ $this->get_field_name('sort_column'),
1130
+ __('Sort by', 'avh-ec'),
1131
+ $options,
1132
+ avhGetArrayValue($instance, 'sort_column')
1133
+ );
1134
  unset($options);
1135
 
1136
  $options['asc'] = __('Ascending', 'avh-ec');
1137
  $options['desc'] = __('Descending', 'avh-ec');
1138
+ avh_doWidgetFormSelect(
1139
+ $this->get_field_id('sort_order'),
1140
+ $this->get_field_name('sort_order'),
1141
+ __('Sort order', 'avh-ec'),
1142
+ $options,
1143
+ avhGetArrayValue($instance, 'sort_order')
1144
+ );
1145
  unset($options);
1146
 
1147
  $options['list'] = __('List', 'avh-ec');
1148
  $options['drop'] = __('Drop down', 'avh-ec');
1149
+ avh_doWidgetFormSelect(
1150
+ $this->get_field_id('style'),
1151
+ $this->get_field_name('style'),
1152
+ __('Display style', 'avh-ec'),
1153
+ $options,
1154
+ avhGetArrayValue($instance, 'style')
1155
+ );
1156
  unset($options);
1157
  echo '</p>';
1158
 
1159
  echo '<p>';
1160
 
1161
+ avh_doWidgetFormCheckbox(
1162
+ $this->get_field_id('rssfeed'),
1163
+ $this->get_field_name('rssfeed'),
1164
+ __('Show RSS Feed', 'avh-ec'),
1165
+ (bool) avhGetArrayValue($instance, 'rssfeed')
1166
+ );
 
 
 
 
 
 
 
 
1167
 
1168
+ avh_doWidgetFormText(
1169
+ $this->get_field_id('rssimage'),
1170
+ $this->get_field_name('rssimage'),
1171
+ __('Path (URI) to RSS image', 'avh-ec'),
1172
+ avhGetArrayValue($instance, 'rssimage')
1173
+ );
1174
 
 
1175
  echo '</p>';
1176
 
1177
+ echo '<input type="hidden" id="' .
1178
+ $this->get_field_id('submit') .
1179
+ '" name="' .
1180
+ $this->get_field_name('submit') .
1181
+ '" value="1" />';
1182
  }
1183
 
1184
+ /**
1185
+ * Update a particular instance.
1186
+ * This function should check that $new_instance is set correctly.
1187
+ * The newly calculated value of $instance should be returned.
1188
+ * If "false" is returned, the instance won't be saved/updated.
1189
+ *
1190
+ * @param array $new_instance New settings for this instance as input by the user via form()
1191
+ * @param array $old_instance Old settings for this instance
1192
+ *
1193
+ * @return array Settings to save or bool false to cancel saving
1194
+ */
1195
+ public function update($new_instance, $old_instance)
1196
  {
1197
+ // update the instance's settings
1198
+ if (!isset($new_instance['submit'])) {
1199
+ return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1200
  }
1201
 
1202
+ $instance = $old_instance;
 
 
 
 
1203
 
1204
+ $instance['title'] = strip_tags(stripslashes($new_instance['title']));
1205
+ $instance['amount'] = (int) $new_instance['amount'];
1206
+ $instance['count'] = isset($new_instance['count']);
1207
+ $instance['use_desc_for_title'] = isset($new_instance['use_desc_for_title']);
1208
+ $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column']));
1209
+ $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order']));
1210
+ $instance['style'] = strip_tags(stripslashes($new_instance['style']));
1211
+ $instance['rssfeed'] = isset($new_instance['rssfeed']);
1212
+ $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage']));
1213
 
1214
+ return $instance;
1215
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1216
 
1217
  /**
1218
+ * Echo the widget content.
1219
+ * Subclasses should over-ride this function to generate their widget code.
 
 
 
 
 
 
1220
  *
1221
+ * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
1222
+ * @param array $instance The settings for the particular instance of the widget
 
 
1223
  */
1224
+ public function widget($args, $instance)
1225
  {
1226
+ extract($args);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1227
 
1228
+ $title = apply_filters(
1229
+ 'widget_title',
1230
+ empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']
1231
+ );
1232
+ $style = empty($instance['style']) ? 'list' : $instance['style'];
1233
+ if (!$a = (int) $instance['amount']) {
1234
+ $a = 5;
1235
+ } elseif ($a < 1) {
1236
+ $a = 1;
1237
  }
1238
+ $c = $instance['count'];
1239
+ $use_desc_for_title = $instance['use_desc_for_title'];
1240
+ $s = isset($instance['sort_column']) ? $instance['sort_column'] : 'name';
1241
+ $o = isset($instance['sort_order']) ? $instance['sort_order'] : 'asc';
1242
+ $r = ($instance['rssfeed'] === true) ? 'RSS' : '';
1243
+ $i = isset($instance['rssimage']) ? $instance['rssimage'] : '';
1244
+ if (empty($r)) {
1245
+ $i = '';
 
 
 
 
1246
  }
1247
+ if (!empty($i)) {
1248
+ if (!file_exists(ABSPATH . '/' . $i)) {
1249
+ $i = '';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1250
  }
1251
  }
1252
 
1253
+ $options = $this->core->getOptions();
1254
+ $show_option_none = __('Select Category', 'avh-ec');
1255
+ if ($options['general']['alternative_name_select_category']) {
1256
+ $show_option_none = $options['general']['alternative_name_select_category'];
 
 
 
 
 
 
 
 
 
 
1257
  }
1258
 
1259
+ $top_cats = get_terms(
1260
+ 'category',
1261
+ array(
1262
+ 'fields' => 'ids',
1263
+ 'orderby' => 'count',
1264
+ 'order' => 'DESC',
1265
+ 'number' => $a,
1266
+ 'hierarchical' => false
1267
+ )
1268
+ );
1269
+ $included_cats = implode(",", $top_cats);
1270
 
1271
+ $cat_args = array(
1272
+ 'include' => $included_cats,
1273
+ 'orderby' => $s,
1274
+ 'order' => $o,
1275
+ 'show_count' => $c,
1276
+ 'use_desc_for_title' => $use_desc_for_title,
1277
+ 'hide_empty' => false,
1278
+ 'hierarchical' => false,
1279
+ 'depth' => -1,
1280
+ 'title_li' => '',
1281
+ 'show_option_none' => $show_option_none,
1282
+ 'feed' => $r,
1283
+ 'feed_image' => $i
1284
+ );
1285
+ echo $before_widget;
1286
+ echo $this->core->comment;
1287
+ echo $before_title . $title . $after_title;
1288
+ echo '<ul>';
1289
 
1290
+ if ($style == 'list') {
1291
+ wp_list_categories($cat_args);
1292
+ } else {
1293
+ $cat_args['name'] = 'extended-categories-top-select-' . $this->number;
1294
+ wp_dropdown_categories($cat_args);
1295
+ echo '<script type=\'text/javascript\'>' . "\n";
1296
+ echo '/* <![CDATA[ */' . "\n";
1297
+ echo ' var ec_dropdown_top_' .
1298
+ $this->number .
1299
+ ' = document.getElementById("extended-categories-top-select-' .
1300
+ $this->number .
1301
+ '");' .
1302
+ "\n";
1303
+ echo ' function ec_top_onCatChange_' . $this->number . '() {' . "\n";
1304
+ echo ' if (ec_dropdown_top_' .
1305
+ $this->number .
1306
+ '.options[ec_dropdown_top_' .
1307
+ $this->number .
1308
+ '.selectedIndex].value > 0) {' .
1309
+ "\n";
1310
+ echo ' location.href = "' .
1311
+ get_option('home') .
1312
+ '/?cat="+ec_dropdown_top_' .
1313
+ $this->number .
1314
+ '.options[ec_dropdown_top_' .
1315
+ $this->number .
1316
+ '.selectedIndex].value;' .
1317
+ "\n";
1318
+ echo ' }' . "\n";
1319
+ echo ' }' . "\n";
1320
+ echo ' ec_dropdown_top_' .
1321
+ $this->number .
1322
+ '.onchange = ec_top_onCatChange_' .
1323
+ $this->number .
1324
+ ';' .
1325
+ "\n";
1326
+ echo '/* ]]> */' . "\n";
1327
+ echo '</script>' . "\n";
1328
  }
1329
+ echo '</ul>';
1330
+ echo $after_widget;
 
 
 
 
 
 
 
1331
  }
1332
  }
4.2/helpers/avh-common.php CHANGED
@@ -1,19 +1,20 @@
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
- }
19
  }
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
 
18
+ return '';
19
+ }
20
  }
4.2/helpers/avh-forms.php CHANGED
@@ -5,7 +5,13 @@ if (!function_exists('avh_doWidgetFormText')) {
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
  }
@@ -16,7 +22,13 @@ if (!function_exists('avh_doWidgetFormCheckbox')) {
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 />';
@@ -33,7 +45,14 @@ if (!function_exists('avh_doWidgetFormSelect')) {
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;
5
  {
6
  echo '<label for="' . $field_id . '">';
7
  echo $description;
8
+ echo '<input class="widefat" id="' .
9
+ $field_id .
10
+ '" name="' .
11
+ $field_name .
12
+ '" type="text" value="' .
13
+ esc_attr($value) .
14
+ '" /> ';
15
  echo '</label>';
16
  echo '<br />';
17
  }
22
  function avh_doWidgetFormCheckbox($field_id, $field_name, $description, $is_checked = false)
23
  {
24
  echo '<label for="' . $field_id . '">';
25
+ echo '<input class="checkbox" type="checkbox" id="' .
26
+ $field_id .
27
+ '" name="' .
28
+ $field_name .
29
+ '"' .
30
+ ($is_checked ? ' CHECKED' : '') .
31
+ ' /> ';
32
  echo $description;
33
  echo '</label>';
34
  echo '<br />';
45
 
46
  $data = '';
47
  foreach ($options as $value => $text) {
48
+ $data .= '<option value="' .
49
+ $value .
50
+ '" ' .
51
+ ($value == $selected_value ? "SELECTED" : '') .
52
+ '>' .
53
+ $text .
54
+ '</option>' .
55
+ "/n";
56
  }
57
  echo '<select id="' . $field_id . '" name="' . $field_name . '"> ';
58
  echo $data;
AUTHORS CHANGED
@@ -1,5 +1,17 @@
1
- AVH Extended Categories Authors This software consists of voluntary contributions made by many individuals. For exact contribution history, see the revision history (readme.txt) and the git logs, available at https://github.com/petervanderdoes/AVH-Extended-Categories
 
 
 
 
 
 
 
2
  Peter van der Does
3
  Stephan
4
  flynsarmy
5
- Portions of the project are derived from other open source works are clearly marked. This file is auto generated, any changes will be lost.
 
 
 
 
 
1
+ AVH Extended Categories Authors
2
+
3
+ This software consists of voluntary contributions made by many
4
+ individuals. For exact contribution history, see the revision history
5
+ (readme.txt) and the git logs, available at
6
+ https://github.com/petervanderdoes/AVH-Extended-Categories
7
+
8
+
9
  Peter van der Does
10
  Stephan
11
  flynsarmy
12
+
13
+
14
+ Portions of the project are derived from other open source works are clearly
15
+ marked.
16
+
17
+ This file is auto generated, any changes will be lost.
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: petervanderdoes
3
  Donate link: http://blog.avirtualhome.com/wordpress-plugins/
4
  Tags: extended, categories, widget, top categories
5
  Requires at least: 2.3
6
- Tested up to: 4.2
7
- Stable tag: 4.0.1
8
 
9
  The AVH Extended Categories Widgets gives you three widgets for displaying categories.
10
  == Description ==
@@ -139,6 +139,9 @@ Whether Widget 2 shows Movie or Music depends on the creation order of groups. I
139
  None
140
 
141
  == Changelog ==
 
 
 
142
  = Version 4.0.1 =
143
  * Post-Auth SQL Injection Vulnerability
144
  Only occurs for WordPress versions lower than 3.3
3
  Donate link: http://blog.avirtualhome.com/wordpress-plugins/
4
  Tags: extended, categories, widget, top categories
5
  Requires at least: 2.3
6
+ Tested up to: 4.4
7
+ Stable tag: 4.0.2
8
 
9
  The AVH Extended Categories Widgets gives you three widgets for displaying categories.
10
  == Description ==
139
  None
140
 
141
  == Changelog ==
142
+ = Version 4.0.2 =
143
+ * Certain methods show notice of undefined variables.
144
+
145
  = Version 4.0.1 =
146
  * Post-Auth SQL Injection Vulnerability
147
  Only occurs for WordPress versions lower than 3.3
widget_extended_categories.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: AVH Extended Categories Widgets
4
  * Plugin URI: http://blog.avirtualhome.com/wordpress-plugins
5
  * Description: Replacement of the category widget to allow for greater customization of the category widget.
6
- * Version: 4.0.1
7
  * Author: Peter van der Does
8
  * Author URI: http://blog.avirtualhome.com/
9
  *
3
  * Plugin Name: AVH Extended Categories Widgets
4
  * Plugin URI: http://blog.avirtualhome.com/wordpress-plugins
5
  * Description: Replacement of the category widget to allow for greater customization of the category widget.
6
+ * Version: 4.0.2
7
  * Author: Peter van der Does
8
  * Author URI: http://blog.avirtualhome.com/
9
  *