AVH Extended Categories Widgets - Version 3.8.0

Version Description

Download this release

Release Info

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

Code changes from version 3.7.1 to 3.8.0

3.6/avh-ec.client.php ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Singleton Class
5
+ *
6
+ */
7
+ class AVH_EC_Singleton
8
+ {
9
+
10
+ /**
11
+ *
12
+ * @param string $class
13
+ * @param string $arg1
14
+ */
15
+ public static function &getInstance($class, $arg1 = null)
16
+ {
17
+ static $instances = array(); // array of instance names
18
+ if (array_key_exists($class, $instances)) {
19
+ $instance = & $instances[$class];
20
+ } else {
21
+ if (!class_exists($class)) {
22
+ switch ($class) {
23
+ case 'AVH_EC_Core':
24
+ require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.core.php');
25
+ break;
26
+ case 'AVH_EC_Category_Group':
27
+ require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.category-group.php');
28
+ break;
29
+ case 'AVH_EC_Widget_Helper_Class':
30
+ require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widget-helper.php');
31
+ break;
32
+ }
33
+ }
34
+ $instances[$class] = new $class($arg1);
35
+ $instance = & $instances[$class];
36
+ }
37
+
38
+ return $instance;
39
+ } // getInstance
40
+ } // singleton
41
+
42
+ /**
43
+ * Include the necessary files
44
+ */
45
+ require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/helpers/avh-forms.php');
46
+ require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widgets.php');
47
+
48
+ /**
49
+ * Initialize the plugin
50
+ */
51
+ function avhextendedcategories_init()
52
+ {
53
+ // Admin
54
+ if (is_admin()) {
55
+ require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.admin.php');
56
+ $avhec_admin = new AVH_EC_Admin();
57
+ }
58
+ AVH_EC_Singleton::getInstance('AVH_EC_Core');
59
+
60
+ add_action('widgets_init', 'avhextendedcategories_widgets_init');
61
+ } // End avhamazon_init()
62
+
63
+ /**
64
+ * Register the widget
65
+ *
66
+ * @WordPress Action widgets_init
67
+ *
68
+ * @since 3.0
69
+ *
70
+ */
71
+ function avhextendedcategories_widgets_init()
72
+ {
73
+ register_widget('WP_Widget_AVH_ExtendedCategories_Normal');
74
+ register_widget('WP_Widget_AVH_ExtendedCategories_Top');
75
+ register_widget('WP_Widget_AVH_ExtendedCategories_Category_Group');
76
+ }
77
+
78
+ add_action('plugins_loaded', 'avhextendedcategories_init');
3.6/class/avh-ec.admin.php ADDED
@@ -0,0 +1,1466 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class AVH_EC_Admin
4
+ {
5
+
6
+ /**
7
+ *
8
+ * @var AVH_EC_Core
9
+ */
10
+ public $core;
11
+
12
+ /**
13
+ *
14
+ * @var AVH_EC_Category_Group
15
+ */
16
+ public $catgrp;
17
+
18
+ public $hooks = array();
19
+
20
+ public $message;
21
+
22
+ /**
23
+ * PHP5 constructor
24
+ */
25
+ public function __construct()
26
+ {
27
+
28
+ // Initialize the plugin
29
+ $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core');
30
+ $this->catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
31
+
32
+ add_action('wp_ajax_delete-group', array(&$this, 'ajaxDeleteGroup'));
33
+
34
+ // Admin menu
35
+ add_action('admin_init', array(&$this, 'actionAdminInit'));
36
+ add_action('admin_menu', array(&$this, 'actionAdminMenu'));
37
+ add_filter('plugin_action_links_extended-categories-widget/widget_extended_categories.php', array(&$this, 'filterPluginActions'), 10, 2);
38
+
39
+ // Actions used for editing posts
40
+ add_action('load-post.php', array(&$this, 'actionLoadPostPage'));
41
+ add_action('load-page.php', array(&$this, 'actionLoadPostPage'));
42
+
43
+ // Actions related to adding and deletes categories
44
+ add_action("created_category", array($this, 'actionCreatedCategory'), 10, 2);
45
+ add_action("delete_category", array($this, 'actionDeleteCategory'), 10, 2);
46
+
47
+ add_filter('manage_categories_group_columns', array(&$this, 'filterManageCategoriesGroupColumns'));
48
+ add_filter('explain_nonce_delete-avhecgroup', array(&$this, 'filterExplainNonceDeleteGroup'), 10, 2);
49
+
50
+ return;
51
+ }
52
+
53
+ public function actionAdminInit()
54
+ {
55
+ if (is_admin() && isset($_GET['taxonomy']) && 'category' == $_GET['taxonomy']) {
56
+ add_action($_GET['taxonomy'] . '_edit_form', array(&$this, 'displayCategoryGroupForm'), 10, 2);
57
+ }
58
+ add_action('edit_term', array(&$this, 'handleEditTerm'), 10, 3);
59
+ }
60
+
61
+ /**
62
+ *
63
+ *
64
+ * Adds Category Group form
65
+ * @WordPress action category_edit_form
66
+ *
67
+ * @param unknown_type $term
68
+ * @param unknown_type $taxonomy
69
+ */
70
+ public function displayCategoryGroupForm($term, $taxonomy)
71
+ {
72
+ $current_selection = '';
73
+ $tax_meta = get_option($this->core->db_options_tax_meta);
74
+ if (isset($tax_meta[$taxonomy][$term->term_id])) {
75
+ $tax_meta = $tax_meta[$taxonomy][$term->term_id];
76
+ $current_selection = $tax_meta['category_group_term_id'];
77
+ }
78
+
79
+ if (empty($current_selection)) {
80
+ $current_group = $this->catgrp->getGroupByCategoryID($term->term_id);
81
+ $current_selection = $current_group->term_id;
82
+ }
83
+
84
+ $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => FALSE));
85
+ foreach ($cat_groups as $group) {
86
+ $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit');
87
+ $dropdown_value[] = $group->term_id;
88
+ $dropdown_text[] = $temp_cat->name;
89
+ }
90
+
91
+ $seldata ='';
92
+ foreach ($dropdown_value as $key => $sel) {
93
+ $seldata .= '<option value="' . esc_attr($sel) . '" ' . (($current_selection == $sel) ? 'selected="selected"' : '') . ' >' . esc_html(ucfirst($dropdown_text[$key])) . '</option>' . "\n";
94
+ }
95
+
96
+ echo '<h3>AVH Extended Categories - Category Group Widget</h3>';
97
+ echo '<table class="form-table"><tbody>';
98
+ echo '<tr class="form-field">';
99
+ echo '<th valign="top" scope="row">';
100
+ echo '<label for="avhec_categorygroup">Category Group</label></th>';
101
+ echo '<td>';
102
+ echo '<select id="avhec_categorygroup" name="avhec_categorygroup">';
103
+ echo $seldata;
104
+ echo '</select>';
105
+ echo '<p class="description">Select the category group to show on the archive page.</p>';
106
+ echo '</td>';
107
+ echo '</tr>';
108
+ echo '</tbody></table>';
109
+ }
110
+
111
+ /**
112
+ * Saves the association Category - Category Group fron the edit taxonomy page
113
+ * @WordPress action edit_form.
114
+ *
115
+ * @param unknown_type $term_id
116
+ * @param unknown_type $tt_id
117
+ * @param unknown_type $taxonomy
118
+ */
119
+ public function handleEditTerm($term_id, $tt_id, $taxonomy)
120
+ {
121
+ $tax_meta = get_option($this->core->db_options_tax_meta);
122
+ if (isset($_POST['avhec_categorygroup'])) {
123
+ if (!isset($tax_meta[$taxonomy][$term_id]['category_group_term_id']) || $tax_meta[$taxonomy][$term_id]['category_group_term_id'] != $_POST['avhec_categorygroup']) {
124
+ $tax_meta[$taxonomy][$term_id]['category_group_term_id'] = $_POST['avhec_categorygroup'];
125
+ update_option($this->core->db_options_tax_meta, $tax_meta);
126
+ }
127
+ }
128
+ }
129
+
130
+ /**
131
+ * When a category is created this function is called to add the new category to the group all
132
+ *
133
+ * @param
134
+ * $term_id
135
+ * @param
136
+ * $term_taxonomy_id
137
+ */
138
+ public function actionCreatedCategory($term_id, $term_taxonomy_id)
139
+ {
140
+ $group_id = $this->catgrp->getTermIDBy('slug', 'all');
141
+ $this->catgrp->setCategoriesForGroup($group_id, (array) $term_id);
142
+ }
143
+
144
+ /**
145
+ * When a category is deleted this function is called so the category is deleted from every group as well.
146
+ *
147
+ * @param object $term
148
+ * @param int $term_taxonomy_id
149
+ */
150
+ public function actionDeleteCategory($term_id, $term_taxonomy_id)
151
+ {
152
+ $this->catgrp->doDeleteCategoryFromGroup($term_id);
153
+ }
154
+
155
+ /**
156
+ * Enqueues the style on the post.php and page.php pages
157
+ * @WordPress Action load-$pagenow
158
+ */
159
+ public function actionLoadPostPage()
160
+ {
161
+ wp_enqueue_style('avhec-admin-css');
162
+ }
163
+
164
+ /**
165
+ * Add the Tools and Options to the Management and Options page repectively
166
+ *
167
+ * @WordPress Action admin_menu
168
+ */
169
+ public function actionAdminMenu()
170
+ {
171
+
172
+ // Register Style and Scripts
173
+ $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.closure';
174
+ wp_register_script('avhec-categorygroup-js', AVHEC_PLUGIN_URL . '/js/avh-ec.categorygroup' . $suffix . '.js', array('jquery'), $this->core->version, true);
175
+ wp_register_script('avhec-manualorder', AVHEC_PLUGIN_URL . '/js/avh-ec.admin.manualorder' . $suffix . '.js', array('jquery-ui-sortable'), $this->core->version, false);
176
+ wp_register_style('avhec-admin-css', AVHEC_PLUGIN_URL . '/css/avh-ec.admin.css', array('wp-admin'), $this->core->version, 'screen');
177
+
178
+ // Add menu system
179
+ $folder = $this->core->getBaseDirectory(AVHEC_PLUGIN_DIR);
180
+ add_menu_page('AVH Extended Categories', 'AVH Extended Categories', 'manage_options', $folder, array(&$this, 'doMenuOverview'));
181
+ $this->hooks['menu_overview'] = add_submenu_page($folder, 'AVH Extended Categories: ' . __('Overview', 'avh-ec'), __('Overview', 'avh-ec'), 'manage_options', $folder, array(&$this, 'doMenuOverview'));
182
+ $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'));
183
+ $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'));
184
+ $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'));
185
+ $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'));
186
+
187
+ // Add actions for menu pages
188
+ // Overview Menu
189
+ add_action('load-' . $this->hooks['menu_overview'], array(&$this, 'actionLoadPageHook_Overview'));
190
+
191
+ // General Options Menu
192
+ add_action('load-' . $this->hooks['menu_general'], array(&$this, 'actionLoadPageHook_General'));
193
+
194
+ // Category Groups Menu
195
+ add_action('load-' . $this->hooks['menu_category_groups'], array(&$this, 'actionLoadPageHook_CategoryGroup'));
196
+
197
+ // Manual Order Menu
198
+ add_action('load-' . $this->hooks['menu_manual_order'], array(&$this, 'actionLoadPageHook_ManualOrder'));
199
+
200
+ // FAQ Menu
201
+ add_action('load-' . $this->hooks['menu_faq'], array(&$this, 'actionLoadPageHook_faq'));
202
+ }
203
+
204
+ /**
205
+ * Setup everything needed for the Overview page
206
+ */
207
+ public function actionLoadPageHook_Overview()
208
+ {
209
+ // Add metaboxes
210
+ add_meta_box('avhecBoxCategoryGroupList', __('Group Overview', 'avh-ec'), array(&$this, 'metaboxCategoryGroupList'), $this->hooks['menu_overview'], 'normal', 'core');
211
+ add_meta_box('avhecBoxTranslation', __('Translation', 'avh-ec'), array(&$this, 'metaboxTranslation'), $this->hooks['menu_overview'], 'normal', 'core');
212
+
213
+ add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
214
+
215
+ // WordPress core Scripts
216
+ wp_enqueue_script('common');
217
+ wp_enqueue_script('wp-lists');
218
+ wp_enqueue_script('postbox');
219
+
220
+ // Plugin Scripts
221
+ wp_enqueue_script('avhec-categorygroup-js');
222
+
223
+ // Plugin Style
224
+ wp_enqueue_style('avhec-admin-css');
225
+ }
226
+
227
+ /**
228
+ * Menu Page Overview
229
+ *
230
+ * @return none
231
+ */
232
+ public function doMenuOverview()
233
+ {
234
+ global $screen_layout_columns;
235
+
236
+ // This box can't be unselectd in the the Screen Options
237
+ // add_meta_box('avhecBoxAnnouncements', __('Announcements', 'avh-ec'), array ( &$this, 'metaboxAnnouncements' ), $this->hooks['menu_overview'], 'side', '');
238
+ add_meta_box('avhecBoxDonations', __('Donations', 'avh-ec'), array(&$this, 'metaboxDonations'), $this->hooks['menu_overview'], 'side', '');
239
+
240
+ $hide2 = '';
241
+ switch ($screen_layout_columns) {
242
+ case 2:
243
+ $width = 'width:49%;';
244
+ break;
245
+ default:
246
+ $width = 'width:98%;';
247
+ $hide2 = 'display:none;';
248
+ }
249
+
250
+ echo '<div class="wrap avhec-metabox-wrap">';
251
+ echo $this->displayIcon('index');
252
+ echo '<h2>' . 'AVH Extended Categories - ' . __('Overview', 'avh-ec') . '</h2>';
253
+ echo ' <div id="dashboard-widgets-wrap">';
254
+ echo ' <div id="dashboard-widgets" class="metabox-holder">';
255
+ echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
256
+ do_meta_boxes($this->hooks['menu_overview'], 'normal', '');
257
+ echo " </div>";
258
+ echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n";
259
+ do_meta_boxes($this->hooks['menu_overview'], 'side', '');
260
+ echo ' </div>';
261
+ echo ' </div>';
262
+
263
+ echo '<br class="clear"/>';
264
+ echo ' </div>'; // dashboard-widgets-wrap
265
+ echo '</div>'; // wrap
266
+
267
+ $this->printMetaboxGeneralNonces();
268
+ $this->printMetaboxJS('overview');
269
+ $this->printAdminFooter();
270
+ }
271
+
272
+ /**
273
+ * Setup everything needed for the General Options page
274
+ */
275
+ public function actionLoadPageHook_General()
276
+ {
277
+ // Add metaboxes
278
+ add_meta_box('avhecBoxOptions', __('Options', 'avh-ec'), array(&$this, 'metaboxOptions'), $this->hooks['menu_general'], 'normal', 'core');
279
+
280
+ add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
281
+
282
+ // WordPress core Scripts
283
+ wp_enqueue_script('common');
284
+ wp_enqueue_script('wp-lists');
285
+ wp_enqueue_script('postbox');
286
+
287
+ // Plugin Style and Scripts
288
+ wp_enqueue_style('avhec-admin-css');
289
+ }
290
+
291
+ /**
292
+ * Menu Page General Options
293
+ *
294
+ * @return none
295
+ */
296
+ public function doMenuGeneral()
297
+ {
298
+ global $screen_layout_columns;
299
+
300
+ $groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => FALSE));
301
+ foreach ($groups as $group) {
302
+ $group_id[] = $group->term_id;
303
+ $groupname[] = $group->name;
304
+ }
305
+
306
+ $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'));
307
+ $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'));
308
+ $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'));
309
+ $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'));
310
+
311
+ if (isset($_POST['updateoptions'])) {
312
+ check_admin_referer('avh_ec_generaloptions');
313
+
314
+ $formoptions = $_POST['avhec'];
315
+ $options = $this->core->getOptions();
316
+
317
+ // $all_data = array_merge( $options_general );
318
+ $all_data = $options_general;
319
+ foreach ($all_data as $option) {
320
+ $section = substr($option[0], strpos($option[0], '[') + 1);
321
+ $section = substr($section, 0, strpos($section, ']['));
322
+ $option_key = rtrim($option[0], ']');
323
+ $option_key = substr($option_key, strpos($option_key, '][') + 2);
324
+
325
+ switch ($section) {
326
+ case 'general':
327
+ case 'cat_group':
328
+ $current_value = $options[$section][$option_key];
329
+ break;
330
+ }
331
+ // Every field in a form is set except unchecked checkboxes. Set an unchecked checkbox to 0.
332
+ $newval = (isset($formoptions[$section][$option_key]) ? esc_attr($formoptions[$section][$option_key]) : 0);
333
+ if ($newval != $current_value) { // Only process changed fields.
334
+ switch ($section) {
335
+ case 'general':
336
+ case 'cat_group':
337
+ $options[$section][$option_key] = $newval;
338
+ break;
339
+ }
340
+ }
341
+ }
342
+ $this->core->saveOptions($options);
343
+ $this->message = __('Options saved', 'avh-ec');
344
+ $this->status = 'updated fade';
345
+ }
346
+ $this->displayMessage();
347
+
348
+ $actual_options = $this->core->getOptions();
349
+ foreach ($actual_options['cat_group'] as $key => $value) {
350
+ if (!(in_array($value, (array) $group_id))) {
351
+ $actual_options['cat_group'][$key] = $this->catgrp->getTermIDBy('slug', 'none');
352
+ }
353
+ }
354
+
355
+ $hide2 = '';
356
+ switch ($screen_layout_columns) {
357
+ case 2:
358
+ $width = 'width:49%;';
359
+ break;
360
+ default:
361
+ $width = 'width:98%;';
362
+ $hide2 = 'display:none;';
363
+ }
364
+ $data['options_general'] = $options_general;
365
+ $data['actual_options'] = $actual_options;
366
+
367
+ // This box can't be unselectd in the the Screen Options
368
+ add_meta_box('avhecBoxDonations', __('Donations', 'avh-ec'), array(&$this, 'metaboxDonations'), $this->hooks['menu_general'], 'side', 'core');
369
+
370
+ $hide2 = '';
371
+ switch ($screen_layout_columns) {
372
+ case 2:
373
+ $width = 'width:49%;';
374
+ break;
375
+ default:
376
+ $width = 'width:98%;';
377
+ $hide2 = 'display:none;';
378
+ }
379
+
380
+ echo '<div class="wrap avhec-metabox-wrap">';
381
+ echo $this->displayIcon('index');
382
+ echo '<h2>' . 'AVH Extended Categories - ' . __('General Options', 'avh-ec') . '</h2>';
383
+ echo '<form name="avhec-generaloptions" id="avhec-generaloptions" method="POST" action="' . admin_url('admin.php?page=avhec-general') . '" accept-charset="utf-8" >';
384
+ wp_nonce_field('avh_ec_generaloptions');
385
+
386
+ echo ' <div id="dashboard-widgets-wrap">';
387
+ echo ' <div id="dashboard-widgets" class="metabox-holder">';
388
+ echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
389
+ do_meta_boxes($this->hooks['menu_general'], 'normal', $data);
390
+ echo " </div>";
391
+ echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n";
392
+ do_meta_boxes($this->hooks['menu_general'], 'side', $data);
393
+ echo ' </div>';
394
+ echo ' </div>';
395
+
396
+ echo '<br class="clear"/>';
397
+ echo ' </div>'; // dashboard-widgets-wrap
398
+ echo '<p class="submit"><input class="button" type="submit" name="updateoptions" value="' . __('Save Changes', 'avhf-ec') . '" /></p>';
399
+ echo '</form>';
400
+
401
+ echo '</div>'; // wrap
402
+
403
+ $this->printMetaboxGeneralNonces();
404
+ $this->printMetaboxJS('general');
405
+ $this->printAdminFooter();
406
+ }
407
+
408
+ /**
409
+ * Options Metabox
410
+ */
411
+ public function metaboxOptions($data)
412
+ {
413
+ echo $this->printOptions($data['options_general'], $data['actual_options']);
414
+ }
415
+
416
+ /**
417
+ * Setup everything needed for the Category Group page
418
+ */
419
+ public function actionLoadPageHook_CategoryGroup()
420
+ {
421
+
422
+ // Add metaboxes
423
+ add_meta_box('avhecBoxCategoryGroupAdd', __('Add Group', 'avh-ec'), array(&$this, 'metaboxCategoryGroupAdd'), $this->hooks['menu_category_groups'], 'normal', 'core');
424
+ add_meta_box('avhecBoxCategoryGroupList', __('Group Overview', 'avh-ec'), array(&$this, 'metaboxCategoryGroupList'), $this->hooks['menu_category_groups'], 'side', 'core');
425
+ add_meta_box('avhecBoxCategoryGroupSpecialPages', __('Special Pages', 'avh-ec'), array(&$this, 'metaboxCategoryGroupSpecialPages'), $this->hooks['menu_category_groups'], 'normal', 'core');
426
+
427
+ add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
428
+
429
+ // WordPress core Scripts
430
+ wp_enqueue_script('common');
431
+ wp_enqueue_script('wp-lists');
432
+ wp_enqueue_script('postbox');
433
+
434
+ // Plugin Scripts
435
+ wp_enqueue_script('avhec-categorygroup-js');
436
+
437
+ // Plugin Style
438
+ wp_enqueue_style('avhec-admin-css');
439
+ }
440
+
441
+ /**
442
+ * Menu Page Category Group
443
+ *
444
+ * @return none
445
+ */
446
+ public function doMenuCategoryGroup()
447
+ {
448
+ global $screen_layout_columns;
449
+
450
+ $data_add_group_default = array('name' => '', 'slug' => '', 'widget_title' => '', 'description' => '');
451
+ $data_add_group_new = $data_add_group_default;
452
+
453
+ $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'));
454
+ $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'));
455
+ $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'));
456
+ $options_add_group[] = array('avhec_add_group[add][description]', __('Description', 'avh-ec'), 'textarea', 40, __('Description is not prominent by default.', 'avh-ec'), 5);
457
+
458
+ $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'));
459
+ $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'));
460
+ $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'));
461
+ $options_edit_group[] = array('avhec_edit_group[edit][description]', __('Description', 'avh-ec'), 'textarea', 40, __('Description is not prominent by default.', 'avh-ec'), 5);
462
+ $options_edit_group[] = array('avhec_edit_group[edit][categories]', __('Categories', 'avh-ec'), 'catlist', 0, __('Select categories to be included in the group.', 'avh-ec'));
463
+
464
+ if (isset($_POST['addgroup'])) {
465
+ check_admin_referer('avh_ec_addgroup');
466
+
467
+ $formoptions = $_POST['avhec_add_group'];
468
+
469
+ $data_add_group_new['name'] = $formoptions['add']['name'];
470
+ $data_add_group_new['slug'] = empty($formoptions['add']['slug']) ? sanitize_title($data_add_group_new['name']) : sanitize_title($formoptions['add']['slug']);
471
+ $data_add_group_new['widget_title'] = $formoptions['add']['widget_title'];
472
+ $data_add_group_new['description'] = $formoptions['add']['description'];
473
+
474
+ $id = $this->catgrp->getTermIDBy('slug', $data_add_group_new['slug']);
475
+ if (!$id) {
476
+ $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']);
477
+ $this->catgrp->setCategoriesForGroup($group_id);
478
+ $this->message = __('Category group saved', 'avh-ec');
479
+ $this->status = 'updated fade';
480
+ $data_add_group_new = $data_add_group_default;
481
+ } else {
482
+ $group = $this->catgrp->getGroup($id);
483
+ $this->message = __('Category group conflicts with ', 'avh-ec') . $group->name;
484
+ $this->message .= '<br />' . __('Same slug is used. ', 'avh-ec');
485
+ $this->status = 'error';
486
+ }
487
+ $this->displayMessage();
488
+ }
489
+ $data_add_group['add'] = $data_add_group_new;
490
+ $data['add'] = array('form' => $options_add_group, 'data' => $data_add_group);
491
+
492
+ if (isset($_GET['action'])) {
493
+ $action = $_GET['action'];
494
+
495
+ switch ($action) {
496
+ case 'edit':
497
+ $group_id = (int) $_GET['group_ID'];
498
+ $group = $this->catgrp->getGroup($group_id);
499
+ $widget_title = $this->catgrp->getWidgetTitleForGroup($group_id);
500
+ $cats = $this->catgrp->getCategoriesFromGroup($group_id);
501
+
502
+ $data_edit_group['edit'] = array('group_id' => $group_id, 'name' => $group->name, 'slug' => $group->slug, 'widget_title' => $widget_title, 'description' => $group->description, 'categories' => $cats);
503
+ $data['edit'] = array('form' => $options_edit_group, 'data' => $data_edit_group);
504
+
505
+ add_meta_box('avhecBoxCategoryGroupEdit', __('Edit Group', 'avh-ec') . ': ' . $group->name, array(&$this, 'metaboxCategoryGroupEdit'), $this->hooks['menu_category_groups'], 'normal', 'low');
506
+ break;
507
+ case 'delete':
508
+ if (!isset($_GET['group_ID'])) {
509
+ wp_redirect($this->getBackLink());
510
+ exit();
511
+ }
512
+
513
+ $group_id = (int) $_GET['group_ID'];
514
+ check_admin_referer('delete-avhecgroup_' . $group_id);
515
+
516
+ if (!current_user_can('manage_categories')) {
517
+ wp_die(__('Cheatin&#8217; uh?'));
518
+ }
519
+ $this->catgrp->doDeleteGroup($group_id);
520
+ break;
521
+ default:
522
+ ;
523
+ break;
524
+ }
525
+ }
526
+
527
+ if (isset($_POST['editgroup'])) {
528
+ check_admin_referer('avh_ec_editgroup');
529
+
530
+ $formoptions = $_POST['avhec_edit_group'];
531
+ $selected_categories = $_POST['post_category'];
532
+
533
+ $group_id = (int) $_POST['avhec-group_id'];
534
+ $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']);
535
+ switch ($result) {
536
+ case 1:
537
+ $this->message = __('Category group updated', 'avh-ec');
538
+ $this->status = 'updated fade';
539
+ break;
540
+ case 0:
541
+ $this->message = __('Category group not updated', 'avh-ec');
542
+ $this->message .= '<br />' . __('Duplicate slug detected', 'avh-ec');
543
+ $this->status = 'error';
544
+ break;
545
+ case -1:
546
+ $this->message = __('Unknown category group', 'avh-ec');
547
+ $this->status = 'error';
548
+ break;
549
+ }
550
+ $this->displayMessage();
551
+ }
552
+
553
+ $hide2 = '';
554
+ switch ($screen_layout_columns) {
555
+ case 2:
556
+ $width = 'width:49%;';
557
+ break;
558
+ default:
559
+ $width = 'width:98%;';
560
+ $hide2 = 'display:none;';
561
+ }
562
+
563
+ $data_special_pages_old = $this->core->options['sp_cat_group'];
564
+ $data_special_pages_new = $data_special_pages_old;
565
+ if (isset($_POST['avhec_special_pages'])) {
566
+ check_admin_referer('avh_ec_specialpagesgroup');
567
+
568
+ $formoptions = $_POST['avhec_special_pages'];
569
+ $formdata = $formoptions['sp'];
570
+ foreach ($formdata as $key => $value) {
571
+ $data_special_pages_new[$key] = $value;
572
+ }
573
+ $this->core->options['sp_cat_group'] = $data_special_pages_new;
574
+ $this->core->saveOptions($this->core->options);
575
+ }
576
+ $data_special_pages['sp'] = $data_special_pages_new;
577
+ $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => FALSE));
578
+
579
+ foreach ($cat_groups as $group) {
580
+ $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit');
581
+ $dropdown_value[] = $group->term_id;
582
+ $dropdown_text[] = $temp_cat->name;
583
+ }
584
+ $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')));
585
+ // $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')));
586
+ $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')));
587
+ $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')));
588
+ $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')));
589
+ $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')));
590
+ $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')));
591
+
592
+ $data['sp'] = array('form' => $options_special_pages, 'data' => $data_special_pages);
593
+
594
+ // This box can't be unselectd in the the Screen Options
595
+ // add_meta_box( 'avhecBoxDonations', __( 'Donations', 'avh-ec' ), array (&$this, 'metaboxDonations' ), $this->hooks['menu_category_groups'], 'side', 'core' );
596
+
597
+ echo '<div class="wrap avhec-metabox-wrap">';
598
+ echo $this->displayIcon('index');
599
+ echo '<h2>' . 'AVH Extended Categories - ' . __('Category Groups', 'avh-ec') . '</h2>';
600
+
601
+ echo ' <div id="dashboard-widgets-wrap">';
602
+ echo ' <div id="dashboard-widgets" class="metabox-holder">';
603
+
604
+ echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
605
+ do_meta_boxes($this->hooks['menu_category_groups'], 'normal', $data);
606
+ echo " </div>";
607
+
608
+ echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n";
609
+ do_meta_boxes($this->hooks['menu_category_groups'], 'side', $data);
610
+ echo ' </div>';
611
+
612
+ echo ' </div>'; // dashboard-widgets
613
+ echo '<br class="clear" />';
614
+ echo ' </div>'; // dashboard-widgets-wrap
615
+ echo '</div>'; // wrap
616
+
617
+ $this->printMetaboxGeneralNonces();
618
+ $this->printMetaboxJS('grouped');
619
+ $this->printAdminFooter();
620
+ }
621
+
622
+ /**
623
+ * Metabox for Adding a group
624
+ *
625
+ * @param
626
+ * $data
627
+ */
628
+ public function metaboxCategoryGroupAdd($data)
629
+ {
630
+ echo '<form name="avhec-addgroup" id="avhec-addgroup" method="POST" action="' . $this->getBackLink() . '" accept-charset="utf-8" >';
631
+ wp_nonce_field('avh_ec_addgroup');
632
+ echo $this->printOptions($data['add']['form'], $data['add']['data']);
633
+ echo '<p class="submit"><input class="button" type="submit" name="addgroup" value="' . __('Add group', 'avh-ec') . '" /></p>';
634
+ echo '</form>';
635
+ }
636
+
637
+ /**
638
+ * Metabox for showing the groups as a list
639
+ *
640
+ * @param
641
+ * $data
642
+ */
643
+ public function metaboxCategoryGroupList($data)
644
+ {
645
+ echo '<form id="posts-filter" action="" method="get">';
646
+
647
+ echo '<div class="clear"></div>';
648
+
649
+ echo '<table class="widefat fixed" cellspacing="0">';
650
+ echo '<thead>';
651
+ echo '<tr>';
652
+ print_column_headers('categories_group');
653
+ echo '</tr>';
654
+ echo '</thead>';
655
+
656
+ echo '<tfoot>';
657
+ echo '<tr>';
658
+ print_column_headers('categories_group', false);
659
+ echo '</tr>';
660
+ echo '</tfoot>';
661
+
662
+ echo '<tbody id="the-list" class="list:group">';
663
+ $this->printCategoryGroupRows();
664
+ echo '</tbody>';
665
+ echo '</table>';
666
+
667
+ echo '<br class="clear" />';
668
+ echo '</form>';
669
+
670
+ // echo '</div>';
671
+ }
672
+
673
+ /**
674
+ * Metabox Category Group Edit
675
+ */
676
+ public function metaboxCategoryGroupEdit($data)
677
+ {
678
+ echo '<form name="avhec-editgroup" id="avhec-editgroup" method="POST" action="' . $this->getBackLink() . '" accept-charset="utf-8" >';
679
+ wp_nonce_field('avh_ec_editgroup');
680
+ echo $this->printOptions($data['edit']['form'], $data['edit']['data']);
681
+ echo '<input type="hidden" value="' . $data['edit']['data']['edit']['group_id'] . '" name="avhec-group_id" id="avhec-group_id">';
682
+ echo '<p class="submit"><input class="button" type="submit" name="editgroup" value="' . __('Update group', 'avh-ec') . '" /></p>';
683
+ echo '</form>';
684
+ }
685
+
686
+ /**
687
+ * Metabox Category Group Special pages
688
+ */
689
+ public function metaboxCategoryGroupSpecialPages($data)
690
+ {
691
+ echo '<form name="avhec-specialpagesgroup" id="avhec-specialpagesgroup" method="POST" action="' . $this->getBackLink() . '" accept-charset="utf-8" >';
692
+ wp_nonce_field('avh_ec_specialpagesgroup');
693
+ echo $this->printOptions($data['sp']['form'], $data['sp']['data']);
694
+ echo '<p class="submit"><input class="button" type="submit" name="spgroup" value="' . __('Save settings', 'avh-ec') . '" /></p>';
695
+ echo '</form>';
696
+ }
697
+
698
+ /**
699
+ * Setup everything needed for the Manul Order page
700
+ */
701
+ public function actionLoadPageHook_ManualOrder()
702
+ {
703
+ add_meta_box('avhecBoxManualOrder', __('Manually Order Categories', 'avh-ec'), array(&$this, 'metaboxManualOrder'), $this->hooks['menu_manual_order'], 'normal', 'core');
704
+
705
+ add_screen_option('layout_columns', array('max' => 1, 'default' => 1));
706
+
707
+ // WordPress core Styles and Scripts
708
+ wp_enqueue_script('common');
709
+ wp_enqueue_script('wp-lists');
710
+ wp_enqueue_script('postbox');
711
+ wp_enqueue_script('jquery-ui-sortable');
712
+ wp_enqueue_script('avhec-manualorder');
713
+
714
+ // Plugin Style
715
+ wp_enqueue_style('avhec-admin-css');
716
+ }
717
+
718
+ /**
719
+ * Menu Page Manual Order
720
+ *
721
+ * @return none
722
+ */
723
+ public function doMenuManualOrder()
724
+ {
725
+ global $screen_layout_columns;
726
+
727
+ $hide2 = '';
728
+ switch ($screen_layout_columns) {
729
+ case 2:
730
+ $width = 'width:49%;';
731
+ break;
732
+ default:
733
+ $width = 'width:98%;';
734
+ $hide2 = 'display:none;';
735
+ }
736
+
737
+ echo '<div class="wrap">';
738
+ echo $this->displayIcon('index');
739
+ echo '<h2>' . 'AVH Extended Categories - ' . __('Manually Order Categories', 'avh-ec') . '</h2>';
740
+
741
+ echo '<div class="metabox-holder">';
742
+ echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
743
+ do_meta_boxes($this->hooks['menu_manual_order'], 'normal', '');
744
+ echo ' </div>';
745
+ echo '</div>';
746
+ echo '</div>'; // wrap
747
+ echo '<div class="clear"></div>';
748
+
749
+ $this->printMetaboxGeneralNonces();
750
+ $this->printMetaboxJS('manual_order');
751
+ $this->printAdminFooter();
752
+ }
753
+
754
+ /**
755
+ *
756
+ *
757
+ * Displays the Manual Order metabox.
758
+ *
759
+ * @author Andrew Charlton - original
760
+ * @author Peter van der Does - modifications
761
+ */
762
+ public function metaboxManualOrder()
763
+ {
764
+ global $wpdb;
765
+
766
+ $parentID = 0;
767
+
768
+ if (isset($_POST['btnSubCats'])) {
769
+ $parentID = $_POST['cats'];
770
+ } elseif (isset($_POST['hdnParentID'])) {
771
+ $parentID = $_POST['hdnParentID'];
772
+ }
773
+
774
+ if (isset($_POST['btnReturnParent'])) {
775
+ $parentsParent = $wpdb->get_row($wpdb->prepare("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = %d", $_POST['hdnParentID']), ARRAY_N);
776
+ $parentID = $parentsParent[0];
777
+ }
778
+
779
+ $success = "";
780
+ if (isset($_POST['btnOrderCats'])) {
781
+ if (isset($_POST['hdnManualOrder']) && $_POST['hdnManualOrder'] != "") {
782
+
783
+ $manualOrder = $_POST['hdnManualOrder'];
784
+ $IDs = explode(",", $manualOrder);
785
+ $result = count($IDs);
786
+
787
+ for ($i = 0; $i < $result; $i ++) {
788
+ $str = str_replace("id_", "", $IDs[$i]);
789
+ $wpdb->query($wpdb->prepare("UPDATE $wpdb->terms SET avhec_term_order = %d WHERE term_id =%d", $i, $str));
790
+ }
791
+
792
+ $success = '<div id="message" class="updated fade"><p>' . __('Manual order of the categories successfully updated.', 'avh-ec') . '</p></div>';
793
+ } else {
794
+ $success = '<div id="message" class="updated fade"><p>' . __('An error occured, order has not been saved.', 'avh-ec') . '</p></div>';
795
+ }
796
+ }
797
+
798
+ $subCategories = "";
799
+ $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));
800
+ foreach ($results as $row) {
801
+ $subCategories .= "<option value='$row->term_id'>$row->name</option>";
802
+ }
803
+
804
+ echo '<div class="wrap">';
805
+ echo '<form name="frmMyCatOrder" method="post" action="">';
806
+ echo $success;
807
+
808
+ echo '<h4>';
809
+ _e('Order the categories', 'avh-ec');
810
+ if ($parentID == 0) {
811
+ echo ' at the Toplevel';
812
+ } else {
813
+ $categories = get_category_parents($parentID, false, ' » ');
814
+ echo ' in the category ' . trim($categories, ' » ');
815
+ }
816
+ echo '</h4>';
817
+ echo '<span class="description">';
818
+ _e('Order the categories on this level by dragging and dropping them into the desired order.', 'avh-ec');
819
+ echo '</span>';
820
+ echo '<ul id="avhecManualOrder">';
821
+ $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));
822
+ foreach ($results as $row)
823
+ echo "<li id='id_$row->term_id' class='lineitem menu-item-settings'>" . __($row->name) . "</li>";
824
+
825
+ echo '</ul>';
826
+ echo '<input type="submit" name="btnOrderCats" id="btnOrderCats" class="button-primary" value="' . __('Save Order', 'avh-ec') . '" onclick="javascript:orderCats(); return true;" />';
827
+
828
+ if ($parentID != 0) {
829
+ echo "<input type='submit' class='button' id='btnReturnParent' name='btnReturnParent' value='" . __('Return to parent category', 'avh-ec') . "' />";
830
+ }
831
+
832
+ echo '<strong id="updateText"></strong><br /><br />';
833
+ if ($subCategories != "") {
834
+
835
+ echo '<h4>';
836
+ _e('Select Subcategory', 'avh-ec');
837
+ echo '</h4>';
838
+ echo '<select id="cats" name="cats">';
839
+ echo $subCategories;
840
+
841
+ echo '</select><input type="submit" name="btnSubCats" class="button" id="btnSubCats" value="' . __('Select', 'avh-ec') . '" />';
842
+ echo '<span class="description">';
843
+ _e('Choose a category from the drop down to order the subcategories in that category.', 'avh-ec');
844
+ echo '</span>';
845
+ }
846
+
847
+ echo '<input type="hidden" id="hdnManualOrder" name="hdnManualOrder" />';
848
+ echo '<input type="hidden" id="hdnParentID" name="hdnParentID" value="' . $parentID . '" /></form>';
849
+ echo '</div>';
850
+ }
851
+
852
+ /**
853
+ * Setup everything needed for the FAQ page
854
+ */
855
+ public function actionLoadPageHook_faq()
856
+ {
857
+ add_meta_box('avhecBoxFAQ', __('F.A.Q.', 'avh-ec'), array(&$this, 'metaboxFAQ'), $this->hooks['menu_faq'], 'normal', 'core');
858
+ add_meta_box('avhecBoxTranslation', __('Translation', 'avh-ec'), array(&$this, 'metaboxTranslation'), $this->hooks['menu_faq'], 'normal', 'core');
859
+
860
+ add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
861
+
862
+ // WordPress core Styles and Scripts
863
+ wp_enqueue_script('common');
864
+ wp_enqueue_script('wp-lists');
865
+ wp_enqueue_script('postbox');
866
+
867
+ // Plugin Style
868
+ wp_enqueue_style('avhec-admin-css');
869
+ }
870
+
871
+ /**
872
+ * Menu Page FAQ
873
+ *
874
+ * @return none
875
+ */
876
+ public function doMenuFAQ()
877
+ {
878
+ global $screen_layout_columns;
879
+
880
+ // This box can't be unselectd in the the Screen Options
881
+ // add_meta_box('avhecBoxAnnouncements', __('Announcements', 'avh-ec'), array ( &$this, 'metaboxAnnouncements' ), $this->hooks['menu_faq'], 'side', 'core');
882
+ add_meta_box('avhecBoxDonations', __('Donations', 'avh-ec'), array(&$this, 'metaboxDonations'), $this->hooks['menu_faq'], 'side', 'core');
883
+
884
+ $hide2 = '';
885
+ switch ($screen_layout_columns) {
886
+ case 2:
887
+ $width = 'width:49%;';
888
+ break;
889
+ default:
890
+ $width = 'width:98%;';
891
+ $hide2 = 'display:none;';
892
+ }
893
+
894
+ echo '<div class="wrap avhec-metabox-wrap">';
895
+ echo $this->displayIcon('index');
896
+ echo '<h2>' . 'AVH Extended Categories - ' . __('F.A.Q', 'avh-ec') . '</h2>';
897
+ echo ' <div id="dashboard-widgets-wrap">';
898
+ echo ' <div id="dashboard-widgets" class="metabox-holder">';
899
+ echo ' <div class="postbox-container" style="' . $width . '">' . "\n";
900
+ do_meta_boxes($this->hooks['menu_faq'], 'normal', '');
901
+ echo ' </div>';
902
+ echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n";
903
+ do_meta_boxes($this->hooks['menu_faq'], 'side', '');
904
+ echo ' </div>';
905
+ echo ' </div>';
906
+ echo '<br class="clear"/>';
907
+ echo ' </div>'; // dashboard-widgets-wrap
908
+ echo '</div>'; // wrap
909
+
910
+ $this->printMetaboxGeneralNonces();
911
+ $this->printMetaboxJS('faq');
912
+ $this->printAdminFooter();
913
+ }
914
+
915
+ /**
916
+ * Translation Metabox
917
+ *
918
+ * @return unknown_type
919
+ */
920
+ public function metaboxTranslation()
921
+ {
922
+ $locale = apply_filters('plugin_locale', get_locale(), 'avh-ec');
923
+ $available_locale['cs_CZ'] = array('Czech - Čeština', 0);
924
+ $available_locale['nl_NL'] = array('Dutch - Nederlands', 0);
925
+ $available_locale['de_DE'] = array('German - Deutsch', 0);
926
+ $available_locale['el'] = array('Greek - Čeština', 0);
927
+ $available_locale['id_ID'] = array('Indonesian - Bahasa Indonesia - Čeština', 0);
928
+ $available_locale['it_IT'] = array('Italian - Italiano', 1);
929
+ $available_locale['ru_RU'] = array('Russian — Русский', 0);
930
+ $available_locale['es_ES'] = array('Spanish - Español', 0);
931
+ $available_locale['sv_SE'] = array('Swedish - Svenska', 0);
932
+ $available_locale['tr'] = array('Turkish - Türkçe', 0);
933
+
934
+ echo '<div class="p">';
935
+ 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 />';
936
+
937
+ echo '</div>';
938
+
939
+ echo '<div class="p">';
940
+ echo '<span class="b">' . __('Available Languages', 'avh-ec') . '</span>';
941
+ echo '<ul>';
942
+ foreach ($available_locale as $key => $value) {
943
+ echo '<li>';
944
+ $complete = ($value[1] == 1 ? 'Complete' : 'Incomplete');
945
+ echo $value[0] . ' (' . $key . ') - ' . $complete;
946
+ echo '</li>';
947
+ }
948
+ echo '</ul>';
949
+ echo '</div>';
950
+
951
+ echo '<div class="p">';
952
+ if ('en_US' != $locale & (!array_key_exists($locale, $available_locale))) {
953
+ 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.';
954
+ } else {
955
+ 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.';
956
+ }
957
+ echo '</div>';
958
+ }
959
+
960
+ /**
961
+ * Donation Metabox
962
+ *
963
+ * @return unknown_type
964
+ */
965
+ public function metaboxDonations()
966
+ {
967
+ echo '<div class="p">';
968
+ echo __('If you enjoy this plug-in please consider a donation. There are several ways you can show your appreciation.', 'avh-ec');
969
+ echo '</div>';
970
+
971
+ echo '<div class="p">';
972
+ echo '<span class="b">Amazon</span><br />';
973
+ echo __('If you decide to buy something from Amazon click the button.', 'avh-ec') . '</span><br />';
974
+ 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>';
975
+ echo '</div>';
976
+
977
+ echo '<div class="p">';
978
+ 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>';
979
+ echo '</div>';
980
+
981
+ echo '<div class="p">';
982
+ echo '<span class="b">' . __('Through Paypal.', 'avh-ec') . '</span><br />';
983
+ 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 />';
984
+ 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">';
985
+ echo '<img src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" alt="Donate"/></a>';
986
+ echo '</div>';
987
+ }
988
+
989
+ /**
990
+ * *
991
+ * F.A.Q Metabox
992
+ *
993
+ * @return none
994
+ */
995
+ public function metaboxFAQ()
996
+ {
997
+ echo '<div class="p">';
998
+ echo '<span class="b">' . __('What about support?', 'avh-ec') . '</span><br />';
999
+ 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 />';
1000
+ echo '</div>';
1001
+
1002
+ echo '<div class="p">';
1003
+ echo '<span class="b">' . __('What is depth selection?', 'avh-ec') . '</span><br />';
1004
+ 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 />';
1005
+ 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 />';
1006
+ 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 />';
1007
+ echo '</div>';
1008
+
1009
+ echo '<div class="p">';
1010
+ echo '<span class="b">' . __('Multiple Category Groups', 'avh-ec') . '</span><br />';
1011
+ echo __('The following is an explanation how assigning multiple groups to page/post works.', 'avh-ec') . '<br /><br />';
1012
+ echo __('Lets say you have the following groups:', 'avh-ec');
1013
+ echo '<ul>';
1014
+ echo '<li>' . __('Free Time', 'avh-ec') . '</li>';
1015
+ echo '<li>' . __('Theater', 'avh-ec') . '</li>';
1016
+ echo '<li>' . __('Movie', 'avh-ec') . '</li>';
1017
+ echo '<li>' . __('Music', 'avh-ec') . '</li>';
1018
+ echo '</ul>';
1019
+ echo __('Setup several Category Group widgets and associated each widget with one or more groups.', 'avh-ec') . '<br />';
1020
+ echo __('Widget 1 has association with Free Time', 'avh-ec') . '<br />';
1021
+ echo __('Widget 2 has association with Theater, Movie and Music', 'avh-ec') . '<br />';
1022
+ echo __('Widget 3 has association with Theater, Movie and Music', 'avh-ec') . '<br /><br />';
1023
+ echo __('Page has associations the groups Free Time and Theater', 'avh-ec');
1024
+ echo '<ul>';
1025
+ echo '<li>' . __('Widget 1: Shows categories of the Free Time group', 'avh-ec') . '</li>';
1026
+ echo '<li>' . __('Widget 2: Shows categories of the Theater group.', 'avh-ec') . '</li>';
1027
+ echo '<li>' . __('Widget 3: Not displayed', 'avh-ec') . '</li>';
1028
+ echo '</ul>';
1029
+ echo __('Page has associations the group Movie.', 'avh-ec');
1030
+ echo '<ul>';
1031
+ echo '<li>' . __('Widget 1: Not displayed', 'avh-ec') . '</li>';
1032
+ echo '<li>' . __('Widget 2: Shows categories of the Movie group.', 'avh-ec') . '</li>';
1033
+ echo '<li>' . __('Widget 3: Not displayed', 'avh-ec') . '</li>';
1034
+ echo '</ul>';
1035
+ echo __('Page has associations the groups Free Time, Movie and Music', 'avh-ec');
1036
+ echo '<ul>';
1037
+ echo '<li>' . __('Widget 1: Shows categories of the Free Time group', 'avh-ec') . '</li>';
1038
+ echo '<li>' . __('Widget 2: Shows categories of the Movie or Music group.', 'avh-ec') . '</li>';
1039
+ echo '<li>' . __('Widget 3: Shows categories of the Music or Movie group.', 'avh-ec') . '</li>';
1040
+ echo '</ul>';
1041
+ 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 />';
1042
+ echo '</div>';
1043
+ }
1044
+
1045
+ public function metaboxAnnouncements()
1046
+ {
1047
+ $php5 = version_compare('5.2', phpversion(), '<');
1048
+ echo '<div class="p">';
1049
+ echo '<span class="b">' . __('PHP4 Support', 'avh-ec') . '</span><br />';
1050
+ echo __('The next major release of the plugin will no longer support PHP4.', 'avh-ec') . '<br />';
1051
+ echo __('It will be written for PHP 5.2 and ', 'avh-ec');
1052
+ if ($php5) {
1053
+ echo __('your blog already runs the needed PHP version. When the new release comes out you can safely update.', 'avh-ec') . '<br />';
1054
+ } else {
1055
+ echo __('your blog still runs PHP4. When the new release comes out you can not use it.', 'avh-ec') . '<br />';
1056
+ 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 />';
1057
+ echo __('If your hosts doesn\'t offer PHP 5.2 you might want to consider switching hosts.', 'avh-ec') . '<br />';
1058
+ echo __('A host to consider is ', 'avh-ec') . '<a href="http://www.lunarpages.com/id/pdoes" target="_blank">Lunarpages</a>';
1059
+ 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');
1060
+ }
1061
+ echo '</div>';
1062
+ }
1063
+
1064
+ /**
1065
+ * Sets the amount of columns wanted for a particuler screen
1066
+ *
1067
+ * @WordPress filter screen_meta_screen
1068
+ *
1069
+ * @param
1070
+ * $screen
1071
+ * @return strings
1072
+ */
1073
+ public function filterScreenLayoutColumns($columns, $screen)
1074
+ {
1075
+ switch ($screen) {
1076
+ case $this->hooks['menu_overview']:
1077
+ $columns[$this->hooks['menu_overview']] = 2;
1078
+ break;
1079
+ case $this->hooks['menu_general']:
1080
+ $columns[$this->hooks['menu_general']] = 2;
1081
+ break;
1082
+ case $this->hooks['menu_category_groups']:
1083
+ $columns[$this->hooks['menu_category_groups']] = 2;
1084
+ break;
1085
+ case $this->hooks['menu_faq']:
1086
+ $columns[$this->hooks['menu_faq']] = 2;
1087
+ break;
1088
+ }
1089
+
1090
+ return $columns;
1091
+ }
1092
+
1093
+ /**
1094
+ * Adds Settings next to the plugin actions
1095
+ *
1096
+ * @WordPress Filter plugin_action_links_avh-amazon/avh-amazon.php
1097
+ */
1098
+ public function filterPluginActions($links, $file)
1099
+ {
1100
+ $settings_link = '<a href="admin.php?page=extended-categories-widget">' . __('Settings', 'avh-ec') . '</a>';
1101
+ array_unshift($links, $settings_link); // before other links
1102
+
1103
+ return $links;
1104
+ }
1105
+
1106
+ /**
1107
+ * Creates a new array for columns headers.
1108
+ * Used in print_column_headers. The filter is called from get_column_headers
1109
+ *
1110
+ * @param
1111
+ * $columns
1112
+ * @return Array
1113
+ * @see print_column_headers, get_column_headers
1114
+ */
1115
+ public function filterManageCategoriesGroupColumns($columns)
1116
+ {
1117
+ $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'));
1118
+
1119
+ return $categories_group_columns;
1120
+ }
1121
+
1122
+ /**
1123
+ * When not using AJAX, this function is called when the deletion fails.
1124
+ *
1125
+ * @param string $text
1126
+ * @param int $group_id
1127
+ * @return string @WordPress Filter explain_nonce_$verb-$noun
1128
+ * @see wp_explain_nonce
1129
+ */
1130
+ public function filterExplainNonceDeleteGroup($text, $group_id)
1131
+ {
1132
+ $group = get_term($group_id, $this->catgrp->taxonomy_name, OBJECT, 'display');
1133
+
1134
+ $return = sprintf(__('Your attempt to delete this group: &#8220;%s&#8221; has failed.'), $group->name);
1135
+
1136
+ return ($return);
1137
+ }
1138
+
1139
+ // ############ Admin WP Helper ##############
1140
+
1141
+ /**
1142
+ * Get the backlink for forms
1143
+ *
1144
+ * @return strings
1145
+ */
1146
+ public function getBackLink()
1147
+ {
1148
+ $page = basename(__FILE__);
1149
+ if (isset($_GET['page']) && !empty($_GET['page'])) {
1150
+ $page = preg_replace('[^a-zA-Z0-9\.\_\-]', '', $_GET['page']);
1151
+ }
1152
+
1153
+ if (function_exists("admin_url"))
1154
+ return admin_url(basename($_SERVER["PHP_SELF"])) . "?page=" . $page;
1155
+ else
1156
+ return $_SERVER['PHP_SELF'] . "?page=" . $page;
1157
+ }
1158
+
1159
+ /**
1160
+ * Print all Category Group rows
1161
+ *
1162
+ * @uses printCategoryGroupRow
1163
+ *
1164
+ */
1165
+ public function printCategoryGroupRows()
1166
+ {
1167
+ $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => FALSE));
1168
+
1169
+ foreach ($cat_groups as $group) {
1170
+ if ('none' != $group->slug) {
1171
+ echo $this->printCategoryGroupRow($group->term_id, $group->term_taxonomy_id);
1172
+ }
1173
+ }
1174
+ }
1175
+
1176
+ /**
1177
+ * Displays all the information of a group in a row
1178
+ * Adds inline link for delete and/or edit.
1179
+ *
1180
+ * @param int $group_term_id
1181
+ * @param int $group_term_taxonomy_id
1182
+ */
1183
+ public function printCategoryGroupRow($group_term_id, $group_term_taxonomy_id)
1184
+ {
1185
+ static $row_class = '';
1186
+
1187
+ $group = get_term($group_term_id, $this->catgrp->taxonomy_name, OBJECT, 'display');
1188
+
1189
+ $no_edit[$this->catgrp->getTermIDBy('slug', 'all')] = 0;
1190
+ $no_delete[$this->catgrp->getTermIDBy('slug', 'all')] = 0;
1191
+
1192
+ if (current_user_can('manage_categories')) {
1193
+ $actions = array();
1194
+ if (!array_key_exists($group->term_id, $no_edit)) {
1195
+ $edit_link = "admin.php?page=avhec-grouped&amp;action=edit&amp;group_ID=$group->term_id";
1196
+ $edit = "<a class='row-title' href='$edit_link' title='" . esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $group->name)) . "'>" . esc_attr($group->name) . '</a><br />';
1197
+
1198
+ $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
1199
+ } else {
1200
+ $edit = esc_attr($group->name);
1201
+ }
1202
+ if (!(array_key_exists($group->term_id, $no_delete))) {
1203
+ $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>";
1204
+ }
1205
+ $action_count = count($actions);
1206
+ $i = 0;
1207
+ $edit .= '<div class="row-actions">';
1208
+ foreach ($actions as $action => $link) {
1209
+ ++ $i;
1210
+ ($i == $action_count) ? $sep = '' : $sep = ' | ';
1211
+ $edit .= "<span class='$action'>$link$sep</span>";
1212
+ }
1213
+ $edit .= '</div>';
1214
+ } else {
1215
+ $edit = $group->name;
1216
+ }
1217
+
1218
+ $row_class = 'alternate' == $row_class ? '' : 'alternate';
1219
+ $qe_data = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit');
1220
+
1221
+ $output = "<tr id='group-$group->term_id' class='iedit $row_class'>";
1222
+
1223
+ $columns = get_column_headers('categories_group');
1224
+ $hidden = get_hidden_columns('categories_group');
1225
+ foreach ($columns as $column_name => $column_display_name) {
1226
+ $class = 'class="' . $column_name . ' column-' . $column_name . '"';
1227
+
1228
+ $style = '';
1229
+ if (in_array($column_name, $hidden))
1230
+ $style = ' style="display:none;"';
1231
+
1232
+ $attributes = $class . $style;
1233
+
1234
+ switch ($column_name) {
1235
+ case 'cb':
1236
+ $output .= '<th scope="row" class="check-column">';
1237
+ if (!(array_key_exists($group->term_id, $no_delete))) {
1238
+ $output .= '<input type="checkbox" name="delete[]" value="' . $group->term_id . '" />';
1239
+ } else {
1240
+ $output .= "&nbsp;";
1241
+ }
1242
+ $output .= '</th>';
1243
+ break;
1244
+ case 'name':
1245
+ $output .= '<td ' . $attributes . '>' . $edit;
1246
+ $output .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">';
1247
+ $output .= '<div class="name">' . $qe_data->name . '</div>';
1248
+ $output .= '<div class="slug">' . apply_filters('editable_slug', $qe_data->slug) . '</div>';
1249
+ $output .= '</div></td>';
1250
+ break;
1251
+ case 'widget-title':
1252
+ $title = $this->catgrp->getWidgetTitleForGroup($group->term_id);
1253
+ if (!$title) {
1254
+ $title = "&nbsp;";
1255
+ }
1256
+ $output .= '<td ' . $attributes . '>' . $title . '</td>';
1257
+ break;
1258
+
1259
+ case 'description':
1260
+ $output .= '<td ' . $attributes . '>' . $qe_data->description . '</td>';
1261
+ break;
1262
+ case 'slug':
1263
+ $output .= "<td $attributes>" . apply_filters('editable_slug', $qe_data->slug) . "</td>";
1264
+ break;
1265
+ case 'cat-in-group':
1266
+ $cats = $this->catgrp->getCategoriesFromGroup($group_term_id);
1267
+ $catname = array();
1268
+ foreach ($cats as $cat_id) {
1269
+ $catname[] = get_cat_name($cat_id);
1270
+ }
1271
+ natsort($catname);
1272
+ $cat = implode(', ', $catname);
1273
+ $output .= '<td ' . $attributes . '>' . $cat . '</td>';
1274
+ break;
1275
+ }
1276
+ }
1277
+ $output .= '</tr>';
1278
+
1279
+ return $output;
1280
+ }
1281
+
1282
+ /**
1283
+ * Prints the general nonces, used by the AJAX
1284
+ */
1285
+ public function printMetaboxGeneralNonces()
1286
+ {
1287
+ echo '<form style="display:none" method="get" action="">';
1288
+ echo '<p>';
1289
+ wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1290
+ wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1291
+ echo '</p>';
1292
+ echo '</form>';
1293
+ }
1294
+
1295
+ /**
1296
+ * Print the Metabox JS for toggling closed and open
1297
+ *
1298
+ * @param
1299
+ * $boxid
1300
+ */
1301
+ public function printMetaboxJS($boxid)
1302
+ {
1303
+ $a = $this->hooks['menu_' . $boxid];
1304
+ echo '<script type="text/javascript">' . "\n";
1305
+ echo ' //<![CDATA[' . "\n";
1306
+ echo ' jQuery(document).ready( function($) {' . "\n";
1307
+ echo ' $(\'.if-js-closed\').removeClass(\'if-js-closed\').addClass(\'closed\');' . "\n";
1308
+ echo ' // postboxes setup' . "\n";
1309
+ echo ' postboxes.add_postbox_toggles(\'' . $a . '\');' . "\n";
1310
+ echo ' });' . "\n";
1311
+ echo ' //]]>' . "\n";
1312
+ echo '</script>';
1313
+ }
1314
+
1315
+ /**
1316
+ * Display plugin Copyright
1317
+ */
1318
+ public function printAdminFooter()
1319
+ {
1320
+ echo '<p class="footer_avhec">';
1321
+ 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);
1322
+ echo '</p>';
1323
+ }
1324
+
1325
+ /**
1326
+ * Display WP alert
1327
+ */
1328
+ public function displayMessage()
1329
+ {
1330
+ if ($this->message != '') {
1331
+ $message = $this->message;
1332
+ $status = $this->status;
1333
+ $this->message = $this->status = ''; // Reset
1334
+ }
1335
+ if (isset($message)) {
1336
+ $status = ($status != '') ? $status : 'updated fade';
1337
+ echo '<div id="message" class="' . $status . '">';
1338
+ echo '<p><strong>' . $message . '</strong></p></div>';
1339
+ }
1340
+ }
1341
+
1342
+ /**
1343
+ * Ouput formatted options
1344
+ *
1345
+ * @param array $option_data
1346
+ * @return string
1347
+ */
1348
+ public function printOptions($option_data, $option_actual)
1349
+ {
1350
+ // Generate output
1351
+ $output = '';
1352
+ $output .= "\n" . '<table class="form-table avhec-options">' . "\n";
1353
+ foreach ($option_data as $option) {
1354
+ $section = substr($option[0], strpos($option[0], '[') + 1);
1355
+ $section = substr($section, 0, strpos($section, ']['));
1356
+ $option_key = rtrim($option[0], ']');
1357
+ $option_key = substr($option_key, strpos($option_key, '][') + 2);
1358
+ // Helper
1359
+ if ($option[2] == 'helper') {
1360
+ $output .= '<tr style="vertical-align: top;"><td class="helper" colspan="2">' . wp_filter_post_kses($option[4]) . '</td></tr>' . "\n";
1361
+ continue;
1362
+ }
1363
+ switch ($option[2]) {
1364
+ case 'checkbox':
1365
+ $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";
1366
+ $explanation = $option[4];
1367
+ break;
1368
+ case 'dropdown':
1369
+ $selvalue = $option[3];
1370
+ $seltext = $option[4];
1371
+ $seldata = '';
1372
+ foreach ((array) $selvalue as $key => $sel) {
1373
+ $seldata .= '<option value="' . esc_attr($sel) . '" ' . (($option_actual[$section][$option_key] == $sel) ? 'selected="selected"' : '') . ' >' . esc_html(ucfirst($seltext[$key])) . '</option>' . "\n";
1374
+ }
1375
+ $input_type = '<select id="' . esc_attr($option[0]) . '" name="' . esc_attr($option[0]) . '">' . $seldata . '</select>' . "\n";
1376
+ $explanation = $option[5];
1377
+ break;
1378
+ case 'text-color':
1379
+ $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";
1380
+ $explanation = $option[4];
1381
+ break;
1382
+ case 'textarea':
1383
+ $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>';
1384
+ $explanation = $option[4];
1385
+ break;
1386
+ case 'catlist':
1387
+ ob_start();
1388
+ echo '<div id="avhec-catlist">';
1389
+ echo '<ul>';
1390
+ wp_category_checklist(0, 0, $option_actual[$section][$option_key]);
1391
+ echo '</ul>';
1392
+ echo '</div>';
1393
+ $input_type = ob_get_contents();
1394
+ ob_end_clean();
1395
+ $explanation = $option[4];
1396
+ break;
1397
+ case 'text':
1398
+ default:
1399
+ $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";
1400
+ $explanation = $option[4];
1401
+ break;
1402
+ }
1403
+ // Additional Information
1404
+ $extra = '';
1405
+ if ($explanation) {
1406
+ $extra = '<br /><span class="description">' . wp_filter_kses($explanation) . '</span>' . "\n";
1407
+ }
1408
+ // Output
1409
+ $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";
1410
+ }
1411
+ $output .= '</table>' . "\n";
1412
+
1413
+ return $output;
1414
+ }
1415
+
1416
+ /**
1417
+ * Used in forms to set an option checked
1418
+ *
1419
+ * @param mixed $checked
1420
+ * @param mixed $current
1421
+ * @return strings
1422
+ */
1423
+ public function isChecked($checked, $current)
1424
+ {
1425
+ $return = '';
1426
+ if ($checked == $current) {
1427
+ $return = ' checked="checked"';
1428
+ }
1429
+
1430
+ return $return;
1431
+ }
1432
+
1433
+ /**
1434
+ * Displays the icon on the menu pages
1435
+ *
1436
+ * @param
1437
+ * $icon
1438
+ */
1439
+ public function displayIcon($icon)
1440
+ {
1441
+ return ('<div class="icon32" id="icon-' . $icon . '"><br/></div>');
1442
+ }
1443
+
1444
+ /**
1445
+ * Ajax Helper: inline delete of the groups
1446
+ */
1447
+ public function ajaxDeleteGroup()
1448
+ {
1449
+ $group_id = isset($_POST['id']) ? (int) $_POST['id'] : 0;
1450
+ check_ajax_referer('delete-avhecgroup_' . $group_id);
1451
+
1452
+ if (!current_user_can('manage_categories')) {
1453
+ die('-1');
1454
+ }
1455
+ $check = $this->catgrp->getGroup($group_id);
1456
+ if (false === $check) {
1457
+ die('1');
1458
+ }
1459
+
1460
+ if ($this->catgrp->doDeleteGroup($group_id)) {
1461
+ die('1');
1462
+ } else {
1463
+ die('0');
1464
+ }
1465
+ }
1466
+ }
3.6/class/avh-ec.category-group.php ADDED
@@ -0,0 +1,415 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * AVH Extended Categorie Category Group Class
5
+ *
6
+ * @author Peter van der Does
7
+ */
8
+ class AVH_EC_Category_Group
9
+ {
10
+
11
+ /**
12
+ * Taxonomy name
13
+ *
14
+ * @var string
15
+ */
16
+ public $taxonomy_name;
17
+
18
+ public $db_options_widget_titles;
19
+
20
+ public $options_widget_titles;
21
+
22
+ public $widget_done_catgroup;
23
+
24
+ /**
25
+ * PHP5 Constructor
26
+ * Init the Database Abstraction layer
27
+ */
28
+ public function __construct()
29
+ {
30
+ global $wpdb;
31
+
32
+ register_shutdown_function(array(&$this, '__destruct'));
33
+
34
+ /**
35
+ * Taxonomy name
36
+ *
37
+ * @var string
38
+ */
39
+ $this->taxonomy_name = 'avhec_catgroup';
40
+
41
+ $this->db_options_widget_titles = 'avhec_widget_titles';
42
+ // add DB pointer
43
+ $wpdb->avhec_cat_group = $wpdb->prefix . 'avhec_category_groups';
44
+
45
+ /**
46
+ * Create the table if it doesn't exist.
47
+ */
48
+ if ($wpdb->get_var('show tables like \'' . $wpdb->avhec_cat_group . '\'') != $wpdb->avhec_cat_group) {
49
+ add_action('init', array(&$this, 'doCreateTable'), 2); // Priority needs to be the same as the Register Taxonomy
50
+ }
51
+ add_action('init', array(&$this, 'doRegisterTaxonomy'), 2); // Priority for registering custom taxonomies is +1 over the creation of the initial taxonomies
52
+ add_action('init', array(&$this, 'doSetupOptions'));
53
+
54
+ add_action('admin_init', array(&$this, 'addMetaBoxes'));
55
+ }
56
+
57
+ /**
58
+ * PHP5 style destructor and will run when database object is destroyed.
59
+ *
60
+ * @return bool Always true
61
+ */
62
+ public function __destruct()
63
+ {
64
+ return true;
65
+ }
66
+
67
+ /**
68
+ * Create Table
69
+ * @WordPress action init
70
+ */
71
+ public function doCreateTable()
72
+ {
73
+ global $wpdb;
74
+
75
+ // Setup the DB Tables
76
+ $charset_collate = '';
77
+
78
+ if (!empty($wpdb->charset)) {
79
+ $charset_collate = 'DEFAULT CHARACTER SET ' . $wpdb->charset;
80
+ }
81
+ if (!empty($wpdb->collate)) {
82
+ $charset_collate .= ' COLLATE ' . $wpdb->collate;
83
+ }
84
+
85
+ $sql = 'CREATE TABLE `' . $wpdb->avhec_cat_group . '` ( `group_term_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, `term_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (`group_term_id`, `term_id`) )' . $charset_collate . ';';
86
+
87
+ $result = $wpdb->query($sql);
88
+ }
89
+
90
+ /**
91
+ * Setup Group Categories Taxonomy
92
+ * @WordPress action init
93
+ */
94
+ public function doRegisterTaxonomy()
95
+ {
96
+ /**
97
+ * As we don't want to see the Menu Item we have to disable show_ui.
98
+ * This also disables the metabox on the posts and pages, so we add thse manually instead.
99
+ * We remove the capabilities to manage, edit and delete the terms. We have written this part ourselves and don't use WordPress for these functions. The only one we use is the assign_terms.
100
+ */
101
+ $labels = array('name' => __('Category Groups', 'avh-ec'), 'singular_name' => __('Category Group', 'avh-ec'), 'search_items' => __('Search Category Groups', 'avh-ec'), 'popular_items' => __('Popular Category Groups'), 'all_items' => __('All Category Groups'), 'parent_item' => __('Parent Category Group'), 'parent_item_colon' => __('Parent Category Group:'), 'edit_item' => __('Edit Category Group'), 'update_item' => __('Update Category Group'), 'add_new_item' => __('Add New Category Group'), 'new_item_name' => __('New Category Group Name'));
102
+ $caps = array('manage_terms' => null, 'edit_terms' => null, 'delete_terms' => null, 'assign_terms' => 'edit_posts');
103
+ register_taxonomy($this->taxonomy_name, array('post', 'page'), array('hierarchical' => TRUE, 'labels' => $labels, 'query_var' => TRUE, 'rewrite' => TRUE, 'show_in_nav_menus' => FALSE, 'public' => TRUE, 'show_ui' => FALSE, 'capabilities' => $caps));
104
+ }
105
+
106
+ /**
107
+ * Setup the options for the widget titles
108
+ * @WordPress action init
109
+ */
110
+ public function doSetupOptions()
111
+ {
112
+ // Setup the standard groups if the none group does not exists.
113
+ $all_categories = $this->getAllCategoriesTermID();
114
+ if (false === $this->getTermIDBy('slug', 'none')) {
115
+ $none_group_id = wp_insert_term('none', $this->taxonomy_name, array('description' => __('This group will not show the widget.', 'avh-ec')));
116
+ $all_group_id = wp_insert_term('All', $this->taxonomy_name, array('description' => __('Holds all the categories.', 'avh-ec')));
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
+
119
+ // Fill the standard groups with all categories
120
+ $this->setCategoriesForGroup($home_group_id['term_id'], $all_categories);
121
+ $this->setWidgetTitleForGroup($all_group_id['term_id'], '');
122
+ $this->setWidgetTitleForGroup($home_group_id['term_id'], '');
123
+ }
124
+
125
+ $options = get_option($this->db_options_widget_titles);
126
+ if (!$options) {
127
+ $options = array();
128
+ $id = $this->getTermIDBy('slug', 'all');
129
+ $options[$id] = '';
130
+ $id = $this->getTermIDBy('slug', 'home');
131
+ $options[$id] = '';
132
+ update_option($this->db_options_widget_titles, $options);
133
+ }
134
+ $this->options_widget_titles = $options;
135
+ $this->setCategoriesForGroup($this->getTermIDBy('slug', 'all'), $all_categories);
136
+ }
137
+
138
+ /**
139
+ * Add the metaboxes for the pots and page pages.
140
+ * @WordPress action admin_init
141
+ */
142
+ public function addMetaBoxes()
143
+ {
144
+ add_meta_box($this->taxonomy_name . 'div', __('Category Groups', 'avh-ec'), 'post_categories_meta_box', 'post', 'side', 'core', array('taxonomy' => $this->taxonomy_name));
145
+ add_meta_box($this->taxonomy_name . 'div', __('Category Groups', 'avh-ec'), 'post_categories_meta_box', 'page', 'side', 'core', array('taxonomy' => $this->taxonomy_name));
146
+ }
147
+
148
+ /**
149
+ * Get all groups term_id
150
+ *
151
+ * @return array Term_id
152
+ */
153
+ public function getAllCategoriesTermID()
154
+ {
155
+ $all_cat_id = array();
156
+ $categories = get_categories();
157
+ if (!is_wp_error($categories)) {
158
+ foreach ($categories as $category) {
159
+ $all_cat_id[] = $category->term_id;
160
+ }
161
+ }
162
+
163
+ return ($all_cat_id);
164
+ }
165
+
166
+ /**
167
+ * Get the categories from the given group from the DB
168
+ *
169
+ * @param int $group_id
170
+ * The Taxonomy Term ID
171
+ * @return Array False Will return FALSE, if the row does not exists.
172
+ *
173
+ */
174
+ public function getCategoriesFromGroup($group_id)
175
+ {
176
+ global $wpdb;
177
+
178
+ // Query database
179
+ $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));
180
+
181
+ if (is_array($result)) { // Call succeeded
182
+ if (empty($result)) { // No rows found
183
+ $return = array();
184
+ } else {
185
+ foreach ($result as $row) {
186
+ $return[] = $row->term_id;
187
+ }
188
+ }
189
+ } else {
190
+ $return = false;
191
+ }
192
+
193
+ return ($return);
194
+ }
195
+
196
+ /**
197
+ * Set the categories for the given group from the DB.
198
+ * Insert the group if it doesn't exists.
199
+ *
200
+ * @param int $group_id
201
+ * The Taxonomy Term ID
202
+ * @param array $categories
203
+ * The categories
204
+ * @return Object (false if not found)
205
+ *
206
+ */
207
+ public function setCategoriesForGroup($group_id, $categories = array())
208
+ {
209
+ global $wpdb;
210
+
211
+ $old_categories = $this->getCategoriesFromGroup($group_id);
212
+
213
+ if (!is_array($categories)) {
214
+ $categories = array();
215
+ }
216
+ $new_categories = $categories;
217
+ sort($old_categories);
218
+ sort($new_categories);
219
+ // If the new and old values are the same, no need to update.
220
+ if ($new_categories === $old_categories) {
221
+ return false;
222
+ }
223
+
224
+ $new = array_diff($new_categories, $old_categories);
225
+ $removed = array_diff($old_categories, $new_categories);
226
+
227
+ if (!empty($new)) {
228
+ foreach ($new as $cat_term_id) {
229
+ $insert[] = '(' . $group_id . ',' . $cat_term_id . ')';
230
+ }
231
+ $value = implode(',', $insert);
232
+ $sql = 'INSERT INTO ' . $wpdb->avhec_cat_group . ' (group_term_id, term_id) VALUES ' . $value;
233
+ $result = $wpdb->query($sql);
234
+ }
235
+
236
+ if (!empty($removed)) {
237
+ $delete = implode(',', $removed);
238
+ $sql = $wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE group_term_id=%d and term_id IN (' . $delete . ')', $group_id);
239
+ $result = $wpdb->query($sql);
240
+ }
241
+
242
+ return $result;
243
+ }
244
+
245
+ /**
246
+ * Set the Widget Title for a Group
247
+ *
248
+ * @param int $group_id
249
+ * @param string $widget_title
250
+ *
251
+ */
252
+ public function setWidgetTitleForGroup($group_id, $widget_title = '')
253
+ {
254
+ $this->options_widget_titles[$group_id] = $widget_title;
255
+ update_option($this->db_options_widget_titles, $this->options_widget_titles);
256
+ }
257
+
258
+ /**
259
+ * Return the title for a group_id if exsist otherwise return false
260
+ *
261
+ * @param
262
+ * $group_id
263
+ *
264
+ */
265
+ public function getWidgetTitleForGroup($group_id)
266
+ {
267
+ if (isset($this->options_widget_titles[$group_id])) {
268
+ return ($this->options_widget_titles[$group_id]);
269
+ }
270
+
271
+ return false;
272
+ }
273
+
274
+ /**
275
+ * Delete the Widget Title for a group
276
+ *
277
+ * @param
278
+ * $group_id
279
+ */
280
+ public function doDeleteWidgetTitle($group_id)
281
+ {
282
+ if (isset($this->options_widget_titles[$group_id])) {
283
+ unset($this->options_widget_titles[$group_id]);
284
+ }
285
+ update_option($this->db_options_widget_titles, $this->options_widget_titles);
286
+ }
287
+
288
+ /**
289
+ * Same as get_term_by, but returns the ID only if found, else false
290
+ *
291
+ * @param string $field
292
+ * @param string $value
293
+ * @return int boolean
294
+ */
295
+ public function getTermIDBy($field, $value)
296
+ {
297
+ $row = get_term_by($field, $value, $this->taxonomy_name);
298
+ if (false === $row) {
299
+ $return = false;
300
+ } else {
301
+ $return = (int) $row->term_id;
302
+ }
303
+
304
+ return ($return);
305
+ }
306
+
307
+ /**
308
+ * Gets all information of a group
309
+ *
310
+ * @param
311
+ * $group_id
312
+ * @return Object False False when the group doesn't exists.
313
+ */
314
+ public function getGroup($group_id)
315
+ {
316
+ global $wpdb;
317
+
318
+ $result = get_term((int) $group_id, $this->taxonomy_name);
319
+ if (null === $result) {
320
+ $result = false;
321
+ }
322
+
323
+ return ($result);
324
+ }
325
+
326
+ public function getGroupByCategoryID($category_id)
327
+ {
328
+ $return = get_term_by('slug', 'none', $this->taxonomy_name);
329
+ $cat_groups = get_terms($this->taxonomy_name, array('hide_empty' => FALSE));
330
+
331
+ foreach ($cat_groups as $group) {
332
+ $cats = $this->getCategoriesFromGroup($group->term_id);
333
+ if ($group->slug != 'all' && in_array($category_id, $cats)) {
334
+ $return = $group;
335
+ break;
336
+ }
337
+ }
338
+
339
+ return $return;
340
+ }
341
+
342
+ /**
343
+ * Inserts a new group
344
+ *
345
+ * @param
346
+ * $term
347
+ * @param array $args
348
+ */
349
+ public function doInsertGroup($term, $args = array(), $widget_title = '')
350
+ {
351
+ $row = wp_insert_term($term, $this->taxonomy_name, $args);
352
+ $this->setWidgetTitleForGroup($term, $widget_title);
353
+
354
+ return ($row['term_id']);
355
+ }
356
+
357
+ /**
358
+ * Deletes a group
359
+ *
360
+ * @param
361
+ * $group_id
362
+ */
363
+ public function doDeleteGroup($group_id)
364
+ {
365
+ global $wpdb;
366
+
367
+ $group = $this->getGroup($group_id);
368
+ $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE group_term_id=%d', $group_id));
369
+ $this->doDeleteWidgetTitle($group_id);
370
+ $return = wp_delete_term($group->term_id, $this->taxonomy_name);
371
+
372
+ return ($return);
373
+ }
374
+
375
+ /**
376
+ * Update a group
377
+ *
378
+ * @param
379
+ * $group_id
380
+ * @param
381
+ * $selected_categories
382
+ * @param $widget_title return
383
+ * -1,0,1 Unknown Group, Duplicate Slug, Succesfull
384
+ */
385
+ public function doUpdateGroup($group_id, $args = array(), $selected_categories, $widget_title = '')
386
+ {
387
+ $group = $this->getGroup($group_id);
388
+ if (is_object($group)) {
389
+ $id = wp_update_term($group->term_id, $this->taxonomy_name, $args);
390
+ if (!is_wp_error($id)) {
391
+ $this->setWidgetTitleForGroup($group_id, $widget_title);
392
+ $this->setCategoriesForGroup($group_id, $selected_categories);
393
+ $return = 1; // Succesful
394
+ } else {
395
+ $return = 0; // Duplicate Slug
396
+ }
397
+ } else {
398
+ $return = -1; // Unknown group
399
+ }
400
+
401
+ return ($return);
402
+ }
403
+
404
+ /**
405
+ * Deletes the given category from all groups
406
+ *
407
+ * @param
408
+ * $category_id
409
+ */
410
+ public function doDeleteCategoryFromGroup($category_id)
411
+ {
412
+ global $wpdb;
413
+ $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE term_id=%d', $category_id));
414
+ }
415
+ }
3.6/class/avh-ec.core.php ADDED
@@ -0,0 +1,769 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.8.0';
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
+ * @return
112
+ *
113
+ *
114
+ */
115
+ public function handleTextdomain()
116
+ {
117
+ load_plugin_textdomain('avh-ec', false, AVHEC_RELATIVE_PLUGIN_DIR . '/lang');
118
+ }
119
+
120
+ /**
121
+ * Checks if running version is newer and do upgrades if necessary
122
+ *
123
+ * @since 1.2.3
124
+ *
125
+ */
126
+ public function doUpdateOptions($db_version)
127
+ {
128
+ $options = $this->getOptions();
129
+
130
+ // Add none existing sections and/or elements to the options
131
+ foreach ($this->default_options as $section => $default_data) {
132
+ if (!array_key_exists($section, $options)) {
133
+ $options[$section] = $default_data;
134
+ continue;
135
+ }
136
+ foreach ($default_data as $element => $default_value) {
137
+ if (!array_key_exists($element, $options[$section])) {
138
+ $options[$section][$element] = $default_value;
139
+ }
140
+ }
141
+ }
142
+
143
+ // Remove none existing sections and/or elements from the options
144
+ foreach ($options as $section => $data) {
145
+ if (!array_key_exists($section, $this->default_options)) {
146
+ unset($options[$section]);
147
+ continue;
148
+ }
149
+ foreach ($data as $element => $value) {
150
+ if (!array_key_exists($element, $this->default_options[$section])) {
151
+ unset($options[$section][$element]);
152
+ }
153
+ }
154
+ }
155
+ /**
156
+ * Update the options to the latests versions
157
+ */
158
+ $options['general']['version'] = $this->version;
159
+ $options['general']['dbversion'] = $db_version;
160
+ $this->saveOptions($options);
161
+ }
162
+
163
+ /**
164
+ * Used in forms to set the checked option.
165
+ *
166
+ * @param mixed $checked
167
+ * @param mixed_type $current
168
+ * @return string
169
+ *
170
+ * @since 2.0
171
+ */
172
+ public function isChecked($checked, $current)
173
+ {
174
+ if ($checked == $current) {
175
+ return (' checked="checked"');
176
+ }
177
+
178
+ return ('');
179
+ }
180
+
181
+ /**
182
+ * Used in forms to set the SELECTED option
183
+ *
184
+ * @param string $current
185
+ * @param string $field
186
+ * @return string
187
+ */
188
+ public function isSelected($current, $field)
189
+ {
190
+ if ($current == $field) {
191
+ return (' SELECTED');
192
+ }
193
+
194
+ return ('');
195
+ }
196
+
197
+ /**
198
+ * Get the base directory of a directory structure
199
+ *
200
+ * @param string $directory
201
+ * @return string
202
+ *
203
+ */
204
+ public function getBaseDirectory($directory)
205
+ {
206
+ $public_directory = dirname($directory);
207
+ // place each directory into array and get the last element
208
+ $directory_array = explode('/', $public_directory);
209
+ // get highest or top level in array of directory strings
210
+ $public_base = end($directory_array);
211
+
212
+ return $public_base;
213
+ }
214
+
215
+ /**
216
+ * *******************************
217
+ * *
218
+ * Methods for variable: options *
219
+ * *
220
+ * ******************************
221
+ */
222
+
223
+ /**
224
+ *
225
+ * @param array $data
226
+ */
227
+ public function setOptions($options)
228
+ {
229
+ $this->options = $options;
230
+ }
231
+
232
+ /**
233
+ * return array
234
+ */
235
+ public function getOptions()
236
+ {
237
+ return ($this->options);
238
+ }
239
+
240
+ /**
241
+ * Save all current options and set the options
242
+ */
243
+ public function saveOptions($options)
244
+ {
245
+ update_option($this->db_options_core, $options);
246
+ wp_cache_flush(); // Delete cache
247
+ $this->setOptions($options);
248
+ }
249
+
250
+ /**
251
+ * Retrieves the plugin options from the WordPress options table and assigns to class variable.
252
+ * If the options do not exists, like a new installation, the options are set to the default value.
253
+ *
254
+ * @return none
255
+ */
256
+ public function loadOptions()
257
+ {
258
+ $options = get_option($this->db_options_core);
259
+ if (false === $options) { // New installation
260
+ $this->resetToDefaultOptions();
261
+ } else {
262
+ $this->setOptions($options);
263
+ }
264
+ }
265
+
266
+ /**
267
+ * Get the value for an option element.
268
+ * If there's no option is set on the Admin page, return the default value.
269
+ *
270
+ * @param string $key
271
+ * @param string $option
272
+ * @return mixed
273
+ */
274
+ public function getOptionElement($option, $key)
275
+ {
276
+ if ($this->options[$option][$key]) {
277
+ $return = $this->options[$option][$key]; // From Admin Page
278
+ } else {
279
+ $return = $this->default_options[$option][$key]; // Default
280
+ }
281
+
282
+ return ($return);
283
+ }
284
+
285
+ /**
286
+ * Reset to default options and save in DB
287
+ */
288
+ public function resetToDefaultOptions()
289
+ {
290
+ $this->options = $this->default_options;
291
+ $this->saveOptions($this->default_options);
292
+ }
293
+
294
+ /**
295
+ * Display or retrieve the HTML dropdown list of categories.
296
+ *
297
+ * The list of arguments is below:
298
+ * 'show_option_all' (string) - Text to display for showing all categories.
299
+ * 'show_option_none' (string) - Text to display for showing no categories.
300
+ * 'orderby' (string) default is 'ID' - What column to use for ordering the
301
+ * categories.
302
+ * 'order' (string) default is 'ASC' - What direction to order categories.
303
+ * 'show_last_update' (bool|int) default is 0 - See {@link get_categories()}
304
+ * 'show_count' (bool|int) default is 0 - Whether to show how many posts are
305
+ * in the category.
306
+ * 'hide_empty' (bool|int) default is 1 - Whether to hide categories that
307
+ * don't have any posts attached to them.
308
+ * 'child_of' (int) default is 0 - See {@link get_categories()}.
309
+ * 'exclude' (string) - See {@link get_categories()}.
310
+ * 'echo' (bool|int) default is 1 - Whether to display or retrieve content.
311
+ * 'depth' (int) - The max depth.
312
+ * 'tab_index' (int) - Tab index for select element.
313
+ * 'name' (string) - The name attribute value for selected element.
314
+ * 'class' (string) - The class attribute value for selected element.
315
+ * 'selected' (int) - Which category ID is selected.
316
+ *
317
+ * The 'hierarchical' argument, which is disabled by default, will override the
318
+ * depth argument, unless it is true. When the argument is false, it will
319
+ * display all of the categories. When it is enabled it will use the value in
320
+ * the 'depth' argument.
321
+ *
322
+ * @since 2.1.0
323
+ *
324
+ * @param string|array $args
325
+ * Optional. Override default arguments.
326
+ * @return string HTML content only if 'echo' argument is 0.
327
+ */
328
+ public function avh_wp_dropdown_categories($args = '', $selectedonly)
329
+ {
330
+ $mywalker = new AVH_Walker_CategoryDropdown();
331
+
332
+ // @format_off
333
+ $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);
334
+ // @format_on
335
+ $defaults['selected'] = (is_category()) ? get_query_var('cat') : 0;
336
+
337
+ $r = wp_parse_args($args, $defaults);
338
+
339
+ if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
340
+ $r['pad_counts'] = true;
341
+ }
342
+
343
+ $r['include_last_update_time'] = $r['show_last_update'];
344
+ extract($r);
345
+
346
+ $tab_index_attribute = '';
347
+ if ((int) $tab_index > 0)
348
+ $tab_index_attribute = ' tabindex="' . $tab_index . '"';
349
+
350
+ $categories = get_terms($taxonomy, $r);
351
+ $name = esc_attr($name);
352
+ $class = esc_attr($class);
353
+ $id = $id ? esc_attr($id) : $name;
354
+
355
+ if (!$r['hide_if_empty'] || !empty($categories))
356
+ $output = "<select name='$name' id='$id' class='$class' $tab_index_attribute>\n";
357
+ else
358
+ $output = '';
359
+
360
+ if (empty($categories) && !$r['hide_if_empty'] && !empty($show_option_none)) {
361
+ $show_option_none = apply_filters('list_cats', $show_option_none);
362
+ $output .= "\t<option value='-1' selected='selected'>$show_option_none</option>\n";
363
+ }
364
+ if (!empty($categories)) {
365
+
366
+ if ($show_option_all) {
367
+ $show_option_all = apply_filters('list_cats', $show_option_all);
368
+ $selected = ('0' === strval($r['selected'])) ? " selected='selected'" : '';
369
+ $output .= "\t" . '<option value="0"' . $selected . '>' . $show_option_all . '</option>' . "\n";
370
+ }
371
+
372
+ if ($show_option_none) {
373
+ $show_option_none = apply_filters('list_cats', $show_option_none);
374
+ $selected = ('-1' === strval($r['selected'])) ? " selected='selected'" : '';
375
+ $output .= "\t" . '<option value="-1"' . $selected . '>' . $show_option_none . '</option>' . "\n";
376
+ }
377
+
378
+ if ($hierarchical) {
379
+ $depth = $r['depth']; // Walk the full depth.
380
+ } else {
381
+ $depth = -1; // Flat
382
+ }
383
+ $output .= walk_category_dropdown_tree($categories, $depth, $r);
384
+ }
385
+ if (!$r['hide_if_empty'] || !empty($categories))
386
+ $output .= "</select>\n";
387
+
388
+ $output = apply_filters('wp_dropdown_cats', $output);
389
+
390
+ if ($echo)
391
+ echo $output;
392
+
393
+ return $output;
394
+ }
395
+
396
+ /**
397
+ * Display or retrieve the HTML list of categories.
398
+ *
399
+ * The list of arguments is below:
400
+ * 'show_option_all' (string) - Text to display for showing all categories.
401
+ * 'orderby' (string) default is 'ID' - What column to use for ordering the
402
+ * categories.
403
+ * 'order' (string) default is 'ASC' - What direction to order categories.
404
+ * 'show_last_update' (bool|int) default is 0 - See {@link
405
+ * walk_category_dropdown_tree()}
406
+ * 'show_count' (bool|int) default is 0 - Whether to show how many posts are
407
+ * in the category.
408
+ * 'hide_empty' (bool|int) default is 1 - Whether to hide categories that
409
+ * don't have any posts attached to them.
410
+ * 'use_desc_for_title' (bool|int) default is 1 - Whether to use the
411
+ * description instead of the category title.
412
+ * 'feed' - See {@link get_categories()}.
413
+ * 'feed_type' - See {@link get_categories()}.
414
+ * 'feed_image' - See {@link get_categories()}.
415
+ * 'child_of' (int) default is 0 - See {@link get_categories()}.
416
+ * 'exclude' (string) - See {@link get_categories()}.
417
+ * 'exclude_tree' (string) - See {@link get_categories()}.
418
+ * 'echo' (bool|int) default is 1 - Whether to display or retrieve content.
419
+ * 'current_category' (int) - See {@link get_categories()}.
420
+ * 'hierarchical' (bool) - See {@link get_categories()}.
421
+ * 'title_li' (string) - See {@link get_categories()}.
422
+ * 'depth' (int) - The max depth.
423
+ *
424
+ * @since 2.1.0
425
+ *
426
+ * @param string|array $args
427
+ * Optional. Override default arguments.
428
+ * @return string HTML content only if 'echo' argument is 0.
429
+ */
430
+ public function avh_wp_list_categories($args = '', $selectedonly)
431
+ {
432
+ $mywalker = new AVHEC_Walker_Category();
433
+ $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);
434
+
435
+ $r = wp_parse_args($args, $defaults);
436
+
437
+ if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
438
+ $r['pad_counts'] = true;
439
+ }
440
+
441
+ if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
442
+ $r['pad_counts'] = true;
443
+ }
444
+
445
+ if (isset($r['show_date'])) {
446
+ $r['include_last_update_time'] = $r['show_date'];
447
+ }
448
+
449
+ if (true == $r['hierarchical']) {
450
+ $r['exclude_tree'] = $r['exclude'];
451
+ $r['exclude'] = '';
452
+ }
453
+
454
+ extract($r);
455
+
456
+ $categories = get_categories($r);
457
+
458
+ $output = '';
459
+ if ($title_li && 'list' == $style)
460
+ $output = '<li class="categories">' . $r['title_li'] . '<ul>';
461
+
462
+ if (empty($categories)) {
463
+ if ('list' == $style)
464
+ $output .= '<li>' . __("No categories") . '</li>';
465
+ else
466
+ $output .= __("No categories");
467
+ } else {
468
+ global $wp_query;
469
+
470
+ if (!empty($show_option_all))
471
+ if ('list' == $style)
472
+ $output .= '<li><a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a></li>';
473
+ else
474
+ $output .= '<a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a>';
475
+
476
+ if (empty($r['current_category']) && is_category())
477
+ $r['current_category'] = $wp_query->get_queried_object_id();
478
+
479
+ if ($hierarchical) {
480
+ $depth = $r['depth'];
481
+ } else {
482
+ $depth = -1; // Flat.
483
+ }
484
+
485
+ $output .= walk_category_tree($categories, $depth, $r);
486
+ }
487
+
488
+ if ($title_li && 'list' == $style)
489
+ $output .= '</ul></li>';
490
+
491
+ $output = apply_filters('wp_list_categories', $output);
492
+
493
+ if ($echo)
494
+ echo $output;
495
+ else
496
+ return $output;
497
+ }
498
+
499
+ public function getCategories()
500
+ {
501
+ static $_categories = NULL;
502
+ if (NULL === $_categories) {
503
+ $_categories = get_categories('get=all');
504
+ }
505
+
506
+ return $_categories;
507
+ }
508
+
509
+ public function getCategoriesId($categories)
510
+ {
511
+ static $_categories_id = NULL;
512
+ if (NULL == $_categories_id) {
513
+ foreach ($categories as $key => $category) {
514
+ $_categories_id[$category->term_id] = $key;
515
+ }
516
+ }
517
+
518
+ return $_categories_id;
519
+ }
520
+ }
521
+
522
+ /**
523
+ * Create HTML dropdown list of Categories.
524
+ *
525
+ * @uses Walker
526
+ */
527
+ class AVH_Walker_CategoryDropdown extends Walker_CategoryDropdown
528
+ {
529
+
530
+ public function walk($elements, $max_depth)
531
+ {
532
+ $args = array_slice(func_get_args(), 2);
533
+ $output = '';
534
+
535
+ if ($max_depth < -1) // invalid parameter
536
+ return $output;
537
+
538
+ if (empty($elements)) // nothing to walk
539
+ return $output;
540
+
541
+ $id_field = $this->db_fields['id'];
542
+ $parent_field = $this->db_fields['parent'];
543
+
544
+ // flat display
545
+ if (-1 == $max_depth) {
546
+ $empty_array = array();
547
+ foreach ($elements as $e)
548
+ $this->display_element($e, $empty_array, 1, 0, $args, $output);
549
+
550
+ return $output;
551
+ }
552
+
553
+ /*
554
+ * need to display in hierarchical order seperate elements into two buckets: top level and children elements children_elements is two dimensional array, eg. children_elements[10][] contains all sub-elements whose parent is 10.
555
+ */
556
+ $top_level_elements = array();
557
+ $children_elements = array();
558
+ foreach ($elements as $e) {
559
+ if (0 == $e->$parent_field)
560
+ $top_level_elements[] = $e;
561
+ else
562
+ $children_elements[$e->$parent_field][] = $e;
563
+ }
564
+
565
+ /*
566
+ * when none of the elements is top level assume the first one must be root of the sub elements
567
+ */
568
+ if (empty($top_level_elements)) {
569
+
570
+ $first = array_slice($elements, 0, 1);
571
+ $root = $first[0];
572
+
573
+ $top_level_elements = array();
574
+ $children_elements = array();
575
+ foreach ($elements as $e) {
576
+ if ($root->$parent_field == $e->$parent_field)
577
+ $top_level_elements[] = $e;
578
+ else
579
+ $children_elements[$e->$parent_field][] = $e;
580
+ }
581
+ }
582
+
583
+ foreach ($top_level_elements as $e) {
584
+ $this->display_element($e, $children_elements, $max_depth, 0, $args, $output);
585
+ }
586
+
587
+ /*
588
+ * if we are displaying all levels, and remaining children_elements is not empty, then we got orphans, which should be displayed regardless
589
+ */
590
+ if ((0 == $max_depth) && count($children_elements) > 0) {
591
+ $empty_array = array();
592
+ foreach ($children_elements as $orphans)
593
+ foreach ($orphans as $op)
594
+ $this->display_element($op, $empty_array, 1, 0, $args, $output);
595
+ }
596
+
597
+ return $output;
598
+ }
599
+ }
600
+
601
+ /**
602
+ * Create HTML list of categories.
603
+ *
604
+ * @uses Walker
605
+ */
606
+ class AVHEC_Walker_Category extends Walker
607
+ {
608
+
609
+ /**
610
+ *
611
+ * @see Walker::$tree_type
612
+ * @since 2.1.0
613
+ * @var string
614
+ */
615
+ public $tree_type = 'category';
616
+
617
+ /**
618
+ *
619
+ * @see Walker::$db_fields
620
+ * @since 2.1.0
621
+ * @todo Decouple this
622
+ * @var array
623
+ */
624
+ public $db_fields = array('parent' => 'parent', 'id' => 'term_id');
625
+
626
+ /**
627
+ *
628
+ * @see Walker::start_lvl()
629
+ * @since 2.1.0
630
+ *
631
+ * @param string $output
632
+ * Passed by reference. Used to append additional content.
633
+ * @param int $depth
634
+ * Depth of category. Used for tab indentation.
635
+ * @param array $args
636
+ * Will only append content if style argument value is 'list'.
637
+ */
638
+ public function start_lvl(&$output, $depth = 0, $args = array())
639
+ {
640
+ if ('list' != $args['style'])
641
+ return;
642
+
643
+ $indent = str_repeat("\t", $depth);
644
+ $output .= $indent . '<ul class="children">' . "\n";
645
+ }
646
+
647
+ /**
648
+ *
649
+ * @see Walker::end_lvl()
650
+ * @since 2.1.0
651
+ *
652
+ * @param string $output
653
+ * Passed by reference. Used to append additional content.
654
+ * @param int $depth
655
+ * Depth of category. Used for tab indentation.
656
+ * @param array $args
657
+ * Will only append content if style argument value is 'list'.
658
+ */
659
+ public function end_lvl(&$output, $depth = 0, $args = array())
660
+ {
661
+ if ('list' != $args['style'])
662
+ return;
663
+
664
+ $indent = str_repeat("\t", $depth);
665
+ $output .= $indent . '</ul>' . "\n";
666
+ }
667
+
668
+ /**
669
+ *
670
+ * @see Walker::start_el()
671
+ * @since 2.1.0
672
+ *
673
+ * @param string $output
674
+ * Passed by reference. Used to append additional content.
675
+ * @param object $category
676
+ * Category data object.
677
+ * @param int $depth
678
+ * Depth of category in reference to parents.
679
+ * @param array $args
680
+ */
681
+ public function start_el(&$output, $object, $depth = 0, $args = array(), $current_object_id = 0)
682
+ {
683
+ extract($args);
684
+
685
+ $cat_name = esc_attr($category->name);
686
+ $cat_name = apply_filters('list_cats', $cat_name, $category);
687
+ $link = '<div class="avhec-widget-line"><a href="' . get_category_link($category->term_id) . '" ';
688
+ if ($use_desc_for_title == 0 || empty($category->description))
689
+ $link .= 'title="' . sprintf(__('View all posts filed under %s'), $cat_name) . '"';
690
+ else
691
+ $link .= 'title="' . esc_attr(strip_tags(apply_filters('category_description', $category->description, $category))) . '"';
692
+ $link .= '>';
693
+ $link .= $cat_name . '</a>';
694
+
695
+ if ((!empty($feed_image)) || (!empty($feed))) {
696
+ $link .= '<div class="avhec-widget-rss"> ';
697
+
698
+ if (empty($feed_image))
699
+ $link .= '(';
700
+
701
+ $link .= '<a href="' . get_category_feed_link($category->term_id, $feed_type) . '"';
702
+
703
+ if (empty($feed))
704
+ $alt = ' alt="' . sprintf(__('Feed for all posts filed under %s'), $cat_name) . '"';
705
+ else {
706
+ $title = ' title="' . $feed . '"';
707
+ $alt = ' alt="' . $feed . '"';
708
+ $name = $feed;
709
+ $link .= $title;
710
+ }
711
+
712
+ $link .= '>';
713
+
714
+ if (empty($feed_image))
715
+ $link .= $name;
716
+ else
717
+ $link .= '<img src="' . $feed_image . '"' . $alt . $title . ' />';
718
+ $link .= '</a>';
719
+ if (empty($feed_image))
720
+ $link .= ')';
721
+ $link .= '</div>';
722
+ }
723
+
724
+ if (isset($show_count) && $show_count)
725
+ $link .= '<div class="avhec-widget-count"> (' . intval($category->count) . ')</div>';
726
+
727
+ if (isset($show_date) && $show_date) {
728
+ $link .= ' ' . gmdate('Y-m-d', $category->last_update_timestamp);
729
+ }
730
+
731
+ if (isset($current_category) && $current_category)
732
+ $_current_category = get_category($current_category);
733
+
734
+ if ('list' == $args['style']) {
735
+ $output .= "\t" . '<li';
736
+ $class = 'cat-item cat-item-' . $category->term_id;
737
+ if (isset($current_category) && $current_category && ($category->term_id == $current_category))
738
+ $class .= ' current-cat';
739
+ elseif (isset($_current_category) && $_current_category && ($category->term_id == $_current_category->parent))
740
+ $class .= ' current-cat-parent';
741
+ $output .= ' class="' . $class . '"';
742
+ $output .= '>' . $link . '</div>' . "\n";
743
+ } else {
744
+ $output .= "\t" . $link . '</div><br />' . "\n";
745
+ }
746
+ }
747
+
748
+ /**
749
+ *
750
+ * @see Walker::end_el()
751
+ * @since 2.1.0
752
+ *
753
+ * @param string $output
754
+ * Passed by reference. Used to append additional content.
755
+ * @param object $page
756
+ * Not used.
757
+ * @param int $depth
758
+ * Depth of category. Not used.
759
+ * @param array $args
760
+ * Only uses 'list' for whether should append to output.
761
+ */
762
+ public function end_el(&$output, $object, $depth = 0, $args = array())
763
+ {
764
+ if ('list' != $args['style'])
765
+ return;
766
+
767
+ $output .= '</li>' . "\n";
768
+ }
769
+ }
3.6/class/avh-ec.widgets.php ADDED
@@ -0,0 +1,988 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Widget Class for displaying categories. Extended version of the dfeault categories.
5
+ *
6
+ */
7
+ class WP_Widget_AVH_ExtendedCategories_Normal extends WP_Widget
8
+ {
9
+
10
+ /**
11
+ *
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'] ? TRUE : FALSE;
54
+ $c = $instance['count'] ? TRUE : FALSE;
55
+ $h = $instance['hierarchical'] ? TRUE : FALSE;
56
+ $d = $instance['depth'] ? $instance['depth'] : 0;
57
+ $e = $instance['hide_empty'] ? TRUE : FALSE;
58
+ $use_desc_for_title = $instance['use_desc_for_title'] ? TRUE : FALSE;
59
+ $s = $instance['sort_column'] ? $instance['sort_column'] : 'name';
60
+ $o = $instance['sort_order'] ? $instance['sort_order'] : 'asc';
61
+ $r = $instance['rssfeed'] ? 'RSS' : '';
62
+ $i = $instance['rssimage'] ? $instance['rssimage'] : '';
63
+ $invert = $instance['invert_included'] ? TRUE : FALSE;
64
+
65
+ if (empty($r)) {
66
+ $i = '';
67
+ }
68
+
69
+ if (empty($d)) {
70
+ $d = 0;
71
+ }
72
+
73
+ $title = apply_filters('widget_title', empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']);
74
+ $style = empty($instance['style']) ? 'list' : $instance['style'];
75
+
76
+ $included_cats = '';
77
+ if ($instance['post_category']) {
78
+ $post_category = unserialize($instance['post_category']);
79
+ $children = array();
80
+ if (!$instance['selectedonly']) {
81
+ foreach ($post_category as $cat_id) {
82
+ $children = array_merge($children, get_term_children($cat_id, 'category'));
83
+ }
84
+ }
85
+ $included_cats = implode(",", array_merge($post_category, $children));
86
+ }
87
+
88
+ if ($invert) {
89
+ $inc_exc = 'exclude';
90
+ } else {
91
+ $inc_exc = 'include';
92
+ }
93
+
94
+ $options = $this->core->getOptions();
95
+ $show_option_none = __('Select Category', 'avh-ec');
96
+ if ($options['general']['alternative_name_select_category']) {
97
+ $show_option_none = $options['general']['alternative_name_select_category'];
98
+ }
99
+
100
+ $cat_args = array($inc_exc => $included_cats, 'orderby' => $s, 'order' => $o, 'show_count' => $c, 'use_desc_for_title' => $use_desc_for_title, 'hide_empty' => $e, 'hierarchical' => $h, 'depth' => $d, 'title_li' => '', 'show_option_none' => $show_option_none, 'feed' => $r, 'feed_image' => $i, 'name' => 'extended-categories-select-' . $this->number);
101
+ echo $before_widget;
102
+ echo $this->core->comment;
103
+ echo $before_title . $title . $after_title;
104
+
105
+ if ($style == 'list') {
106
+ echo '<ul>';
107
+ $this->core->avh_wp_list_categories($cat_args, $selectedonly);
108
+ echo '</ul>';
109
+ } else {
110
+ $this->core->avh_wp_dropdown_categories($cat_args, $selectedonly);
111
+ echo '<script type=\'text/javascript\'>' . "\n";
112
+ echo '/* <![CDATA[ */' . "\n";
113
+ echo ' var ec_dropdown_' . $this->number . ' = document.getElementById("extended-categories-select-' . $this->number . '");' . "\n";
114
+ echo ' function ec_onCatChange_' . $this->number . '() {' . "\n";
115
+ echo ' if (ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value > 0) {' . "\n";
116
+ echo ' location.href = "' . home_url() . '/?cat="+ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value;' . "\n";
117
+ echo ' }' . "\n";
118
+ echo ' }' . "\n";
119
+ echo ' ec_dropdown_' . $this->number . '.onchange = ec_onCatChange_' . $this->number . ';' . "\n";
120
+ echo '/* ]]> */' . "\n";
121
+ echo '</script>' . "\n";
122
+ }
123
+ echo $after_widget;
124
+ }
125
+
126
+ /**
127
+ * When Widget Control Form Is Posted
128
+ *
129
+ * @param unknown_type $new_instance
130
+ * @param unknown_type $old_instance
131
+ * @return unknown
132
+ */
133
+ public function update($new_instance, $old_instance)
134
+ {
135
+ // update the instance's settings
136
+ if (!isset($new_instance['submit'])) {
137
+ return FALSE;
138
+ }
139
+
140
+ $instance = $old_instance;
141
+
142
+ $instance['title'] = strip_tags(stripslashes($new_instance['title']));
143
+ $instance['selectedonly'] = $new_instance['selectedonly'] ? TRUE : FALSE;
144
+ $instance['count'] = $new_instance['count'] ? TRUE : FALSE;
145
+ $instance['hierarchical'] = $new_instance['hierarchical'] ? TRUE : FALSE;
146
+ $instance['hide_empty'] = $new_instance['hide_empty'] ? TRUE : FALSE;
147
+ $instance['use_desc_for_title'] = $new_instance['use_desc_for_title'] ? TRUE : FALSE;
148
+ $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column']));
149
+ $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order']));
150
+ $instance['style'] = strip_tags(stripslashes($new_instance['style']));
151
+ $instance['rssfeed'] = $new_instance['rssfeed'] ? TRUE : FALSE;
152
+ $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage']));
153
+ if (array_key_exists('all', $new_instance['post_category'])) {
154
+ $instance['post_category'] = FALSE;
155
+ } else {
156
+ $instance['post_category'] = serialize($new_instance['post_category']);
157
+ }
158
+ $instance['depth'] = (int) $new_instance['depth'];
159
+ if ($instance['depth'] < 0 || 11 < $instance['depth']) {
160
+ $instance['depth'] = 0;
161
+ }
162
+ $instance['invert_included'] = $new_instance['invert_included'] ? TRUE : FALSE;
163
+
164
+ return $instance;
165
+ }
166
+
167
+ /**
168
+ * Display Widget Control Form
169
+ *
170
+ * @param unknown_type $instance
171
+ */
172
+ public function form($instance)
173
+ {
174
+ // displays the widget admin form
175
+ $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => '', 'depth' => 0));
176
+
177
+ // Prepare data for display
178
+ $depth = (int) $instance['depth'];
179
+ if ($depth < 0 || 11 < $depth) {
180
+ $depth = 0;
181
+ }
182
+ $selected_cats = ($instance['post_category'] != '') ? unserialize($instance['post_category']) : FALSE;
183
+
184
+ echo '<p>';
185
+ avh_doWidgetFormText($this->get_field_id('title'), $this->get_field_name('title'), __('Title', 'avh-ec'), $instance['title']);
186
+ echo '</p>';
187
+
188
+ echo '<p>';
189
+ avh_doWidgetFormCheckbox($this->get_field_id('selectedonly'), $this->get_field_name('selectedonly'), __('Show selected categories only', 'avh-ec'), (bool) $instance['selectedonly']);
190
+
191
+ avh_doWidgetFormCheckbox($this->get_field_id('count'), $this->get_field_name('count'), __('Show post counts', 'avh-ec'), (bool) $instance['count']);
192
+
193
+ avh_doWidgetFormCheckbox($this->get_field_id('hierarchical'), $this->get_field_name('hierarchical'), __('Show hierarchy', 'avh-ec'), (bool) $instance['hierarchical']);
194
+
195
+ $options = array(0 => __('All Levels', 'avh-ec'), 1 => __('Toplevel only', 'avh-ec'));
196
+ for ($i = 2; $i <= 11; $i ++) {
197
+ $options[$i] = __('Child ', 'avh-ec') . ($i - 1);
198
+ }
199
+ avh_doWidgetFormSelect($this->get_field_id('depth'), $this->get_field_name('depth'), __('How many levels to show', 'avh-ec'), $options, $depth);
200
+ unset($options);
201
+
202
+ avh_doWidgetFormCheckbox($this->get_field_id('hide_empty'), $this->get_field_name('hide_empty'), __('Hide empty categories', 'avh-ec'), (bool) $instance['hide_empty']);
203
+
204
+ avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'), $this->get_field_name('use_desc_for_title'), __('Use description for title', 'avh-ec'), (bool) $instance['use_desc_for_title']);
205
+ echo '</p>';
206
+
207
+ echo '<p>';
208
+ $options['ID'] = __('ID', 'avh-ec');
209
+ $options['name'] = __('Name', 'avh-ec');
210
+ $options['count'] = __('Count', 'avh-ec');
211
+ $options['slug'] = __('Slug', 'avh-ec');
212
+ $options['avhec_manualorder'] = 'AVH EC ' . __('Manual Order', 'avh-ec');
213
+ if (is_plugin_active('my-category-order/mycategoryorder.php')) {
214
+ $options['avhec_3rdparty_mycategoryorder'] = 'My Category Order';
215
+ }
216
+
217
+ avh_doWidgetFormSelect($this->get_field_id('sort_column'), $this->get_field_name('sort_column'), __('Sort by', 'avh-ec'), $options, $instance['sort_column']);
218
+ unset($options);
219
+
220
+ $options['asc'] = __('Ascending', 'avh-ec');
221
+ $options['desc'] = __('Descending', 'avh-ec');
222
+ avh_doWidgetFormSelect($this->get_field_id('sort_order'), $this->get_field_name('sort_order'), __('Sort order', 'avh-ec'), $options, $instance['sort_order']);
223
+ unset($options);
224
+
225
+ $options['list'] = __('List', 'avh-ec');
226
+ $options['drop'] = __('Drop down', 'avh-ec');
227
+ avh_doWidgetFormSelect($this->get_field_id('style'), $this->get_field_name('style'), __('Display style', 'avh-ec'), $options, $instance['style']);
228
+ unset($options);
229
+ echo '</p>';
230
+
231
+ echo '<p>';
232
+
233
+ avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), $this->get_field_name('rssfeed'), __('Show RSS Feed', 'avh-ec'), (bool) $instance['rssfeed']);
234
+
235
+ avh_doWidgetFormText($this->get_field_id('rssimage'), $this->get_field_name('rssimage'), __('Path (URI) to RSS image', 'avh-ec'), $instance['rssimage']);
236
+
237
+ echo '</p>';
238
+
239
+ echo '<p>';
240
+ echo '<b>' . __('Select categories', 'avh-ec') . '</b><hr />';
241
+ echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear" style="list-style-type: none; margin-left: 5px; padding-left: 0px; margin-bottom: 20px;">';
242
+ echo '<li id="' . $this->get_field_id('category--1') . '" class="popular-category">';
243
+ echo '<label for="' . $this->get_field_id('post_category') . '" class="selectit">';
244
+ echo '<input value="all" id="' . $this->get_field_id('post_category') . '" name="' . $this->get_field_name('post_category') . '[all]" type="checkbox" ' . (FALSE === $selected_cats ? ' CHECKED' : '') . '> ';
245
+ _e('All Categories', 'avh-ec');
246
+ echo '</label>';
247
+ echo '</li>';
248
+ ob_start();
249
+ $this->avh_wp_category_checklist($selected_cats, $this->number);
250
+ ob_end_flush();
251
+ echo '</ul>';
252
+ echo '</p>';
253
+
254
+ echo '<p>';
255
+ avh_doWidgetFormCheckbox($this->get_field_id('invert_included'), $this->get_field_name('invert_included'), __('Exclude the selected categories', 'avh-ec'), (bool) $instance['invert_included']);
256
+ echo '</p>';
257
+
258
+ echo '<input type="hidden" id="' . $this->get_field_id('submit') . '" name="' . $this->get_field_name('submit') . '" value="1" />';
259
+ }
260
+
261
+ /**
262
+ * Creates the categories checklist
263
+ *
264
+ * @param int $post_id
265
+ * @param int $descendants_and_self
266
+ * @param array $selected_cats
267
+ * @param array $popular_cats
268
+ * @param int $number
269
+ */
270
+ public function avh_wp_category_checklist($selected_cats, $number)
271
+ {
272
+ $walker = new AVH_Walker_Category_Checklist();
273
+ $walker->number = $number;
274
+ $walker->input_id = $this->get_field_id('post_category');
275
+ $walker->input_name = $this->get_field_name('post_category');
276
+ $walker->li_id = $this->get_field_id('category--1');
277
+
278
+ $args = array('taxonomy' => 'category', 'descendants_and_self' => 0, 'selected_cats' => $selected_cats, 'popular_cats' => array(), 'walker' => $walker, 'checked_ontop' => true, 'popular_cats' => array());
279
+
280
+ if (is_array($selected_cats))
281
+ $args['selected_cats'] = $selected_cats;
282
+ else
283
+ $args['selected_cats'] = array();
284
+
285
+ $categories = $this->core->getCategories();
286
+ $_categories_id = $this->core->getCategoriesId($categories);
287
+
288
+ // 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)
289
+ $checked_categories = array();
290
+ foreach ($args['selected_cats'] as $key => $value) {
291
+ if (isset($_categories_id[$key])) {
292
+ $category_key = $_categories_id[$key];
293
+ $checked_categories[] = $categories[$category_key];
294
+ unset($categories[$category_key]);
295
+ }
296
+ }
297
+
298
+ // Put checked cats on top
299
+ echo $walker->walk($checked_categories, 0, array($args));
300
+ // Then the rest of them
301
+ echo $walker->walk($categories, 0, array($args));
302
+ }
303
+ }
304
+
305
+ /**
306
+ * Widget Class for displaying the top categories
307
+ */
308
+ class WP_Widget_AVH_ExtendedCategories_Top extends WP_Widget
309
+ {
310
+
311
+ /**
312
+ *
313
+ * @var AVH_EC_Core
314
+ */
315
+ public $core;
316
+
317
+ /**
318
+ * PHP 5 Constructor
319
+ */
320
+ public function __construct()
321
+ {
322
+ $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core');
323
+
324
+ $widget_ops = array('description' => __("Shows the top categories.", 'avh-ec'));
325
+ WP_Widget::__construct(FALSE, 'AVH Extended Categories: ' . __('Top Categories'), $widget_ops);
326
+ add_action('wp_print_styles', array(&$this, 'actionWpPrintStyles'));
327
+ }
328
+
329
+ public function actionWpPrintStyles()
330
+ {
331
+ if (!(FALSE === is_active_widget(FALSE, FALSE, $this->id_base, TRUE))) {
332
+ wp_register_style('avhec-widget', AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', array(), $this->core->version);
333
+ wp_enqueue_style('avhec-widget');
334
+ }
335
+ }
336
+
337
+ /**
338
+ * Echo the widget content.
339
+ *
340
+ * Subclasses should over-ride this function to generate their widget code.
341
+ *
342
+ * @param array $args
343
+ * Display arguments including before_title, after_title, before_widget, and after_widget.
344
+ * @param array $instance
345
+ * The settings for the particular instance of the widget
346
+ */
347
+ public function widget($args, $instance)
348
+ {
349
+ extract($args);
350
+
351
+ $title = apply_filters('widget_title', empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']);
352
+ $style = empty($instance['style']) ? 'list' : $instance['style'];
353
+ if (!$a = (int) $instance['amount']) {
354
+ $a = 5;
355
+ } elseif ($a < 1) {
356
+ $a = 1;
357
+ }
358
+ $c = $instance['count'] ? TRUE : FALSE;
359
+ $use_desc_for_title = $instance['use_desc_for_title'] ? TRUE : FALSE;
360
+ $s = $instance['sort_column'] ? $instance['sort_column'] : 'name';
361
+ $o = $instance['sort_order'] ? $instance['sort_order'] : 'asc';
362
+ $r = $instance['rssfeed'] ? 'RSS' : '';
363
+ $i = $instance['rssimage'] ? $instance['rssimage'] : '';
364
+ if (empty($r)) {
365
+ $i = '';
366
+ }
367
+ if (!empty($i)) {
368
+ if (!file_exists(ABSPATH . '/' . $i)) {
369
+ $i = '';
370
+ }
371
+ }
372
+
373
+ $options = $this->core->getOptions();
374
+ $show_option_none = __('Select Category', 'avh-ec');
375
+ if ($options['general']['alternative_name_select_category']) {
376
+ $show_option_none = $options['general']['alternative_name_select_category'];
377
+ }
378
+
379
+ $top_cats = get_terms('category', array('fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => $a, 'hierarchical' => FALSE));
380
+ $included_cats = implode(",", $top_cats);
381
+
382
+ $cat_args = array('include' => $included_cats, 'orderby' => $s, 'order' => $o, 'show_count' => $c, 'use_desc_for_title' => $use_desc_for_title, 'hide_empty' => FALSE, 'hierarchical' => FALSE, 'depth' => -1, 'title_li' => '', 'show_option_none' => $show_option_none, 'feed' => $r, 'feed_image' => $i, 'name' => 'extended-categories-top-select-' . $this->number);
383
+ echo $before_widget;
384
+ echo $this->core->comment;
385
+ echo $before_title . $title . $after_title;
386
+ echo '<ul>';
387
+
388
+ if ($style == 'list') {
389
+ wp_list_categories($cat_args);
390
+ } else {
391
+ wp_dropdown_categories($cat_args);
392
+ echo '<script type=\'text/javascript\'>' . "\n";
393
+ echo '/* <![CDATA[ */' . "\n";
394
+ echo ' var ec_dropdown_top_' . $this->number . ' = document.getElementById("extended-categories-top-select-' . $this->number . '");' . "\n";
395
+ echo ' function ec_top_onCatChange_' . $this->number . '() {' . "\n";
396
+ echo ' if (ec_dropdown_top_' . $this->number . '.options[ec_dropdown_top_' . $this->number . '.selectedIndex].value > 0) {' . "\n";
397
+ echo ' location.href = "' . get_option('home') . '/?cat="+ec_dropdown_top_' . $this->number . '.options[ec_dropdown_top_' . $this->number . '.selectedIndex].value;' . "\n";
398
+ echo ' }' . "\n";
399
+ echo ' }' . "\n";
400
+ echo ' ec_dropdown_top_' . $this->number . '.onchange = ec_top_onCatChange_' . $this->number . ';' . "\n";
401
+ echo '/* ]]> */' . "\n";
402
+ echo '</script>' . "\n";
403
+ }
404
+ echo '</ul>';
405
+ echo $after_widget;
406
+ }
407
+
408
+ /**
409
+ * Update a particular instance.
410
+ *
411
+ * This function should check that $new_instance is set correctly.
412
+ * The newly calculated value of $instance should be returned.
413
+ * If "FALSE" is returned, the instance won't be saved/updated.
414
+ *
415
+ * @param array $new_instance
416
+ * New settings for this instance as input by the user via form()
417
+ * @param array $old_instance
418
+ * Old settings for this instance
419
+ * @return array Settings to save or bool FALSE to cancel saving
420
+ */
421
+ public function update($new_instance, $old_instance)
422
+ {
423
+ // update the instance's settings
424
+ if (!isset($new_instance['submit'])) {
425
+ return FALSE;
426
+ }
427
+
428
+ $instance = $old_instance;
429
+
430
+ $instance['title'] = strip_tags(stripslashes($new_instance['title']));
431
+ $instance['amount'] = (int) $new_instance['amount'];
432
+ $instance['count'] = $new_instance['count'] ? TRUE : FALSE;
433
+ $instance['use_desc_for_title'] = $new_instance['use_desc_for_title'] ? TRUE : FALSE;
434
+ $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column']));
435
+ $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order']));
436
+ $instance['style'] = strip_tags(stripslashes($new_instance['style']));
437
+ $instance['rssfeed'] = $new_instance['rssfeed'] ? TRUE : FALSE;
438
+ $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage']));
439
+
440
+ return $instance;
441
+ }
442
+
443
+ /**
444
+ * Echo the settings update form
445
+ *
446
+ * @param array $instance
447
+ * Current settings
448
+ */
449
+ public function form($instance)
450
+ {
451
+ // displays the widget admin form
452
+ $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => ''));
453
+
454
+ // Prepare data for display
455
+ if (!$amount = (int) $instance['amount']) {
456
+ $amount = 5;
457
+ }
458
+
459
+ if ($amount < 1) {
460
+ $amount = 1;
461
+ }
462
+ echo '<p>';
463
+ avh_doWidgetFormText($this->get_field_id('title'), $this->get_field_name('title'), __('Title', 'avh-ec'), $instance['title']);
464
+ echo '</p>';
465
+
466
+ echo '<p>';
467
+ avh_doWidgetFormText($this->get_field_id('amount'), $this->get_field_name('amount'), __('How many categories to show', 'avh-ec'), $amount);
468
+ echo '</p>';
469
+
470
+ echo '<p>';
471
+ avh_doWidgetFormCheckbox($this->get_field_id('count'), $this->get_field_name('count'), __('Show post counts', 'avh-ec'), (bool) $instance['count']);
472
+ echo '<br />';
473
+
474
+ avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'), $this->get_field_name('use_desc_for_title'), __('Use description for title', 'avh-ec'), (bool) $instance['use_desc_for_title']);
475
+ echo '</p>';
476
+
477
+ echo '<p>';
478
+ $options['ID'] = __('ID', 'avh-ec');
479
+ $options['name'] = __('Name', 'avh-ec');
480
+ $options['count'] = __('Count', 'avh-ec');
481
+ $options['slug'] = __('Slug', 'avh-ec');
482
+ avh_doWidgetFormSelect($this->get_field_id('sort_column'), $this->get_field_name('sort_column'), __('Sort by', 'avh-ec'), $options, $instance['sort_column']);
483
+ unset($options);
484
+
485
+ $options['asc'] = __('Ascending', 'avh-ec');
486
+ $options['desc'] = __('Descending', 'avh-ec');
487
+ avh_doWidgetFormSelect($this->get_field_id('sort_order'), $this->get_field_name('sort_order'), __('Sort order', 'avh-ec'), $options, $instance['sort_order']);
488
+ unset($options);
489
+
490
+ $options['list'] = __('List', 'avh-ec');
491
+ $options['drop'] = __('Drop down', 'avh-ec');
492
+ avh_doWidgetFormSelect($this->get_field_id('style'), $this->get_field_name('style'), __('Display style', 'avh-ec'), $options, $instance['style']);
493
+ unset($options);
494
+ echo '</p>';
495
+
496
+ echo '<p>';
497
+
498
+ avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), $this->get_field_name('rssfeed'), __('Show RSS Feed', 'avh-ec'), (bool) $instance['rssfeed']);
499
+
500
+ avh_doWidgetFormText($this->get_field_id('rssimage'), $this->get_field_name('rssimage'), __('Path (URI) to RSS image', 'avh-ec'), $instance['rssimage']);
501
+
502
+ echo '</p>';
503
+
504
+ echo '<input type="hidden" id="' . $this->get_field_id('submit') . '" name="' . $this->get_field_name('submit') . '" value="1" />';
505
+ }
506
+ }
507
+
508
+ /**
509
+ * Widget Class for displaying the grouped categories
510
+ */
511
+ class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget
512
+ {
513
+
514
+ /**
515
+ *
516
+ * @var AVH_EC_Core
517
+ */
518
+ public $core;
519
+
520
+ /**
521
+ *
522
+ * @var AVH_EC_Category_Group
523
+ */
524
+ public $catgrp;
525
+
526
+ /**
527
+ * PHP 5 Constructor
528
+ */
529
+ public function __construct()
530
+ {
531
+ $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core');
532
+ $this->catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
533
+
534
+ $widget_ops = array('description' => __("Shows grouped categories.", 'avh-ec'));
535
+ WP_Widget::__construct(FALSE, 'AVH Extended Categories: ' . __('Category Group'), $widget_ops);
536
+ add_action('wp_print_styles', array(&$this, 'actionWpPrintStyles'));
537
+ }
538
+
539
+ public function actionWpPrintStyles()
540
+ {
541
+ if (!(FALSE === is_active_widget(FALSE, FALSE, $this->id_base, TRUE))) {
542
+ wp_register_style('avhec-widget', AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', array(), $this->core->version);
543
+ wp_enqueue_style('avhec-widget');
544
+ }
545
+ }
546
+
547
+ /**
548
+ * Display the widget
549
+ *
550
+ * @param unknown_type $args
551
+ * @param unknown_type $instance
552
+ */
553
+ public function widget($args, $instance)
554
+ {
555
+ global $post, $wp_query;
556
+
557
+ $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
558
+ $options = $this->core->getOptions();
559
+
560
+ $row = array();
561
+
562
+ if (is_home()) {
563
+ $special_page = 'home_group';
564
+ } elseif (is_category()) {
565
+ $special_page = 'category_group';
566
+ } elseif (is_day()) {
567
+ $special_page = 'day_group';
568
+ } elseif (is_month()) {
569
+ $special_page = 'month_group';
570
+ } elseif (is_year()) {
571
+ $special_page = 'year_group';
572
+ } elseif (is_author()) {
573
+ $special_page = 'author_group';
574
+ } elseif (is_search()) {
575
+ $special_page = 'search_group';
576
+ } else {
577
+ $special_page = 'none';
578
+ }
579
+
580
+ $toDisplay = FALSE;
581
+ if ('none' == $special_page) {
582
+ $terms = wp_get_object_terms($post->ID, $catgrp->taxonomy_name);
583
+ if (!empty($terms)) {
584
+ $selected_catgroups = unserialize($instance['post_group_category']);
585
+ foreach ($terms as $key => $value) {
586
+ if ($selected_catgroups === FALSE || array_key_exists($value->term_id, $selected_catgroups)) {
587
+ if (!($this->getWidgetDoneCatGroup($value->term_id))) {
588
+ $row = $value;
589
+ $group_found = TRUE;
590
+ break;
591
+ }
592
+ }
593
+ }
594
+ } else {
595
+ $options = $this->core->options;
596
+ $no_cat_group = $options['cat_group']['no_group'];
597
+ $row = get_term_by('id', $no_cat_group, $catgrp->taxonomy_name);
598
+ $group_found = TRUE;
599
+ }
600
+ } else {
601
+ if ('category_group' == $special_page) {
602
+ $tax_meta = get_option($this->core->db_options_tax_meta);
603
+ $term = $wp_query->get_queried_object();
604
+ if (isset($tax_meta[$term->taxonomy][$term->term_id]['category_group_term_id'])) {
605
+ $sp_category_group_id = $tax_meta[$term->taxonomy][$term->term_id]['category_group_term_id'];
606
+ } else {
607
+ $sp_category_group = $this->catgrp->getGroupByCategoryID($term->term_id);
608
+ $sp_category_group_id = $sp_category_group->term_id;
609
+ }
610
+ } else {
611
+ $sp_category_group_id = $options['sp_cat_group'][$special_page];
612
+ }
613
+ $row = get_term_by('id', $sp_category_group_id, $catgrp->taxonomy_name); // Returns FALSE when non-existance. (empty(FALSE)=TRUE)
614
+ $group_found = TRUE;
615
+ }
616
+
617
+ if ($group_found) {
618
+ $toDisplay = TRUE;
619
+ $category_group_id_none = $this->catgrp->getTermIDBy('slug', 'none');
620
+ $selected_catgroups = unserialize($instance['post_group_category']);
621
+
622
+ if ($category_group_id_none == $row->term_id) {
623
+ $toDisplay = FALSE;
624
+ } elseif (!(FALSE == $selected_catgroups || array_key_exists($row->term_id, $selected_catgroups))) {
625
+ $toDisplay = FALSE;
626
+ } elseif ($special_page != 'none' && $this->getWidgetDoneCatGroup($sp_category_group_id)) {
627
+ $toDisplay = FALSE;
628
+ }
629
+ }
630
+
631
+ if ($toDisplay) {
632
+ extract($args);
633
+
634
+ $c = $instance['count'] ? TRUE : FALSE;
635
+ $e = $instance['hide_empty'] ? TRUE : FALSE;
636
+ $h = $instance['hierarchical'] ? TRUE : FALSE;
637
+ $use_desc_for_title = $instance['use_desc_for_title'] ? TRUE : FALSE;
638
+ $s = $instance['sort_column'] ? $instance['sort_column'] : 'name';
639
+ $o = $instance['sort_order'] ? $instance['sort_order'] : 'asc';
640
+ $r = $instance['rssfeed'] ? 'RSS' : '';
641
+ $i = $instance['rssimage'] ? $instance['rssimage'] : '';
642
+
643
+ if (empty($r)) {
644
+ $i = '';
645
+ }
646
+
647
+ $style = empty($instance['style']) ? 'list' : $instance['style'];
648
+ $group_id = $row->term_id;
649
+ $cats = $catgrp->getCategoriesFromGroup($group_id);
650
+ if (empty($instance['title'])) {
651
+ $title = $catgrp->getWidgetTitleForGroup($group_id);
652
+ if (!$title) {
653
+ $title = __('Categories', 'avh-ec');
654
+ }
655
+ } else {
656
+ $title = $instance['title'];
657
+ }
658
+ $title = apply_filters('widget_title', $title);
659
+
660
+ $included_cats = implode(',', $cats);
661
+
662
+ $show_option_none = __('Select Category', 'avh-ec');
663
+ if ($options['general']['alternative_name_select_category']) {
664
+ $show_option_none = $options['general']['alternative_name_select_category'];
665
+ }
666
+
667
+ $cat_args = array('include' => $included_cats, 'orderby' => $s, 'order' => $o, 'show_count' => $c, 'use_desc_for_title' => $use_desc_for_title, 'hide_empty' => $e, 'hierarchical' => $h, 'title_li' => '', 'show_option_none' => $show_option_none, 'feed' => $r, 'feed_image' => $i, 'name' => 'extended-categories-select-group-' . $this->number);
668
+ echo $before_widget;
669
+ echo $this->core->comment;
670
+ echo $before_title . $title . $after_title;
671
+
672
+ if ($style == 'list') {
673
+ echo '<ul>';
674
+ $this->core->avh_wp_list_categories($cat_args, TRUE);
675
+ echo '</ul>';
676
+ } else {
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
+ {
703
+ // update the instance's settings
704
+ if (!isset($new_instance['submit'])) {
705
+ return FALSE;
706
+ }
707
+
708
+ $instance = $old_instance;
709
+
710
+ $instance['title'] = strip_tags(stripslashes($new_instance['title']));
711
+ $instance['count'] = $new_instance['count'] ? TRUE : FALSE;
712
+ $instance['hierarchical'] = $new_instance['hierarchical'] ? TRUE : FALSE;
713
+ $instance['hide_empty'] = $new_instance['hide_empty'] ? TRUE : FALSE;
714
+ $instance['use_desc_for_title'] = $new_instance['use_desc_for_title'] ? TRUE : FALSE;
715
+ $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column']));
716
+ $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order']));
717
+ $instance['style'] = strip_tags(stripslashes($new_instance['style']));
718
+ $instance['rssfeed'] = $new_instance['rssfeed'] ? TRUE : FALSE;
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
+ // Prepare data for display
740
+ $title = esc_attr($instance['title']);
741
+ $count = (bool) $instance['count'];
742
+ $hierarchical = (bool) $instance['hierarchical'];
743
+ $hide_empty = (bool) $instance['hide_empty'];
744
+ $use_desc_for_title = (bool) $instance['use_desc_for_title'];
745
+ $sort_id = ($instance['sort_column'] == 'ID') ? ' SELECTED' : '';
746
+ $sort_name = ($instance['sort_column'] == 'name') ? ' SELECTED' : '';
747
+ $sort_count = ($instance['sort_column'] == 'count') ? ' SELECTED' : '';
748
+ $sort_order_a = ($instance['sort_order'] == 'asc') ? ' SELECTED' : '';
749
+ $sort_order_d = ($instance['sort_order'] == 'desc') ? ' SELECTED' : '';
750
+ $style_list = ($instance['style'] == 'list') ? ' SELECTED' : '';
751
+ $style_drop = ($instance['style'] == 'drop') ? ' SELECTED' : '';
752
+ $rssfeed = (bool) $instance['rssfeed'];
753
+ $rssimage = esc_attr($instance['rssimage']);
754
+
755
+ $selected_cats = ($instance['post_group_category'] != '') ? unserialize($instance['post_group_category']) : FALSE;
756
+ ob_start();
757
+ echo '<p>';
758
+ avh_doWidgetFormText($this->get_field_id('title'), $this->get_field_name('title'), __('Title', 'avh-ec'), $instance['title']);
759
+ echo '</p>';
760
+
761
+ echo '<p>';
762
+
763
+ avh_doWidgetFormCheckbox($this->get_field_id('count'), $this->get_field_name('count'), __('Show post counts', 'avh-ec'), (bool) $instance['count']);
764
+
765
+ avh_doWidgetFormCheckbox($this->get_field_id('hierarchical'), $this->get_field_name('hierarchical'), __('Show hierarchy', 'avh-ec'), (bool) $instance['hierarchical']);
766
+
767
+ avh_doWidgetFormCheckbox($this->get_field_id('hide_empty'), $this->get_field_name('hide_empty'), __('Hide empty categories', 'avh-ec'), (bool) $instance['hide_empty']);
768
+
769
+ avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'), $this->get_field_name('use_desc_for_title'), __('Use description for title', 'avh-ec'), (bool) $instance['use_desc_for_title']);
770
+ echo '</p>';
771
+
772
+ echo '<p>';
773
+ $options['ID'] = __('ID', 'avh-ec');
774
+ $options['name'] = __('Name', 'avh-ec');
775
+ $options['count'] = __('Count', 'avh-ec');
776
+ $options['slug'] = __('Slug', 'avh-ec');
777
+ avh_doWidgetFormSelect($this->get_field_id('sort_column'), $this->get_field_name('sort_column'), __('Sort by', 'avh-ec'), $options, $instance['sort_column']);
778
+ unset($options);
779
+
780
+ $options['asc'] = __('Ascending', 'avh-ec');
781
+ $options['desc'] = __('Descending', 'avh-ec');
782
+ avh_doWidgetFormSelect($this->get_field_id('sort_order'), $this->get_field_name('sort_order'), __('Sort order', 'avh-ec'), $options, $instance['sort_order']);
783
+ unset($options);
784
+
785
+ $options['list'] = __('List', 'avh-ec');
786
+ $options['drop'] = __('Drop down', 'avh-ec');
787
+ avh_doWidgetFormSelect($this->get_field_id('style'), $this->get_field_name('style'), __('Display style', 'avh-ec'), $options, $instance['style']);
788
+ unset($options);
789
+ echo '</p>';
790
+
791
+ echo '<p>';
792
+
793
+ avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), $this->get_field_name('rssfeed'), __('Show RSS Feed', 'avh-ec'), (bool) $instance['rssfeed']);
794
+
795
+ avh_doWidgetFormText($this->get_field_id('rssimage'), $this->get_field_name('rssimage'), __('Path (URI) to RSS image', 'avh-ec'), $instance['rssimage']);
796
+ echo '</p>';
797
+
798
+ echo '<p>';
799
+ echo '<b>' . __('Select Groups', 'avh-ec') . '</b><hr />';
800
+ 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;">';
801
+ echo '<li id="' . $this->get_field_id('group_category--1') . '" class="popular-group_category">';
802
+ echo '<label for="' . $this->get_field_id('group_post_category') . '" class="selectit">';
803
+ 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' : '') . '> ';
804
+ _e('Any Group', 'avh-ec');
805
+ echo '</label>';
806
+ echo '</li>';
807
+
808
+ $this->avh_wp_group_category_checklist($selected_cats, $this->number);
809
+
810
+ echo '</ul>';
811
+ echo '</p>';
812
+
813
+ echo '<input type="hidden" id="' . $this->get_field_id('submit') . '" name="' . $this->get_field_name('submit') . '" value="1" />';
814
+ ob_end_flush();
815
+ }
816
+
817
+ public function avh_wp_group_category_checklist($selected_cats, $number)
818
+ {
819
+ $walker = new AVH_Walker_Category_Checklist();
820
+ $walker->number = $number;
821
+ $walker->input_id = $this->get_field_id('post_group_category');
822
+ $walker->input_name = $this->get_field_name('post_group_category');
823
+ $walker->li_id = $this->get_field_id('group_category--1');
824
+
825
+ $args = array('taxonomy' => 'avhec_catgroup', 'descendants_and_self' => 0, 'selected_cats' => array(), 'popular_cats' => array(), 'walker' => $walker, 'checked_ontop' => true);
826
+
827
+ if (is_array($selected_cats))
828
+ $args['selected_cats'] = $selected_cats;
829
+ else
830
+ $args['selected_cats'] = array();
831
+
832
+ $categories = (array) get_terms($args['taxonomy'], array('get' => 'all'));
833
+
834
+ // 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)
835
+ $checked_categories = array();
836
+ $keys = array_keys($categories);
837
+
838
+ foreach ($keys as $k) {
839
+ if (in_array($categories[$k]->term_id, $args['selected_cats'])) {
840
+ $checked_categories[] = $categories[$k];
841
+ unset($categories[$k]);
842
+ }
843
+ }
844
+
845
+ // Put checked cats on top
846
+ echo $walker->walk($checked_categories, 0, array($args));
847
+ // Then the rest of them
848
+ echo $walker->walk($categories, 0, array($args));
849
+ }
850
+
851
+ public function getWidgetDoneCatGroup($id)
852
+ {
853
+ $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
854
+ if (is_array($catgrp->widget_done_catgroup) && array_key_exists($id, $catgrp->widget_done_catgroup)) {
855
+ return TRUE;
856
+ }
857
+ $catgrp->widget_done_catgroup[$id] = TRUE;
858
+
859
+ return FALSE;
860
+ }
861
+ }
862
+
863
+ /**
864
+ * Class that will display the categories
865
+ */
866
+ class AVH_Walker_Category_Checklist extends Walker
867
+ {
868
+
869
+ public $tree_type = 'category';
870
+
871
+ public $db_fields = array('parent' => 'parent', 'id' => 'term_id'); // TODO: decouple this
872
+ public $number;
873
+
874
+ public $input_id;
875
+
876
+ public $input_name;
877
+
878
+ public $li_id;
879
+
880
+ /**
881
+ * Display array of elements hierarchically.
882
+ *
883
+ * It is a generic function which does not assume any existing order of
884
+ * elements. max_depth = -1 means flatly display every element. max_depth =
885
+ * 0 means display all levels. max_depth > 0 specifies the number of
886
+ * display levels.
887
+ *
888
+ * @since 2.1.0
889
+ *
890
+ * @param array $elements
891
+ * @param int $max_depth
892
+ * @param array $args;
893
+ * @return string
894
+ */
895
+ public function walk($elements, $max_depth, $args)
896
+ {
897
+ $output = '';
898
+
899
+ if ($max_depth < -1) // invalid parameter
900
+ return $output;
901
+
902
+ if (empty($elements)) // nothing to walk
903
+ return $output;
904
+
905
+ $id_field = $this->db_fields['id'];
906
+ $parent_field = $this->db_fields['parent'];
907
+
908
+ // flat display
909
+ if (-1 == $max_depth) {
910
+ $empty_array = array();
911
+ foreach ($elements as $e)
912
+ $this->display_element($e, $empty_array, 1, 0, $args, $output);
913
+
914
+ return $output;
915
+ }
916
+
917
+ /*
918
+ * 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.
919
+ */
920
+ $top_level_elements = array();
921
+ $children_elements = array();
922
+ foreach ($elements as $e) {
923
+ if (0 == $e->$parent_field)
924
+ $top_level_elements[] = $e;
925
+ else
926
+ $children_elements[$e->$parent_field][] = $e;
927
+ }
928
+
929
+ /*
930
+ * when none of the elements is top level assume the first one must be root of the sub elements
931
+ */
932
+ if (empty($top_level_elements)) {
933
+
934
+ $first = array_slice($elements, 0, 1);
935
+ $root = $first[0];
936
+
937
+ $top_level_elements = array();
938
+ $children_elements = array();
939
+ foreach ($elements as $e) {
940
+ if ($root->$parent_field == $e->$parent_field)
941
+ $top_level_elements[] = $e;
942
+ else
943
+ $children_elements[$e->$parent_field][] = $e;
944
+ }
945
+ }
946
+
947
+ foreach ($top_level_elements as $e)
948
+ $this->display_element($e, $children_elements, $max_depth, 0, $args, $output);
949
+
950
+ /*
951
+ * if we are displaying all levels, and remaining children_elements is not empty, then we got orphans, which should be displayed regardless
952
+ */
953
+ if (($max_depth == 0) && count($children_elements) > 0) {
954
+ $empty_array = array();
955
+ foreach ($children_elements as $orphans)
956
+ foreach ($orphans as $op)
957
+ $this->display_element($op, $empty_array, 1, 0, $args, $output);
958
+ }
959
+
960
+ return $output;
961
+ }
962
+
963
+ public function start_lvl(&$output, $depth, $args)
964
+ {
965
+ $indent = str_repeat("\t", $depth);
966
+ $output .= $indent . '<ul class="children">' . "\n";
967
+ }
968
+
969
+ public function end_lvl(&$output, $depth, $args)
970
+ {
971
+ $indent = str_repeat("\t", $depth);
972
+ $output .= $indent . '</ul>' . "\n";
973
+ }
974
+
975
+ public function start_el(&$output, $category, $depth, $args)
976
+ {
977
+ extract($args);
978
+ $input_id = $this->input_id . '-' . $category->term_id;
979
+ $output .= "\n" . '<li id="' . $this->li_id . '">';
980
+ $output .= '<label for="' . $input_id . '" class="selectit">';
981
+ $output .= '<input value="' . $category->term_id . '" type="checkbox" name="' . $this->input_name . '[' . $category->term_id . ']" id="' . $input_id . '"' . (in_array($category->term_id, $selected_cats) ? ' checked="checked"' : "") . '/> ' . esc_html(apply_filters('the_category', $category->name)) . '</label>';
982
+ }
983
+
984
+ public function end_el(&$output, $category, $depth, $args)
985
+ {
986
+ $output .= "</li>\n";
987
+ }
988
+ }
3.6/css/avh-ec.admin.css ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .footer_avhec {
2
+ font-size: 0.8em;
3
+ text-align: center;
4
+ }
5
+
6
+ div.clearer {
7
+ clear: both;
8
+ line-height: 1px;
9
+ font-size: 1px;
10
+ height: 1px;
11
+ }
12
+
13
+ /* Metabox in General */
14
+ table.avhec-options {
15
+
16
+ }
17
+
18
+ .avhec-metabox-wrap {
19
+
20
+ }
21
+
22
+ .avhec-metabox-wrap .p {
23
+ line-height: 140%;
24
+ margin: 1em 0;
25
+ }
26
+
27
+ #avhecBoxOptions option {
28
+ padding: .5em;
29
+ }
30
+
31
+ .avhec-metabox-wrap span.description {
32
+
33
+ }
34
+
35
+ .avhec-metabox-wrap .b {
36
+ font-weight: bold;
37
+ }
38
+
39
+ .avhec-metabox-wrap ul {
40
+ margin-bottom: 1em;
41
+ }
42
+
43
+ .avhec-metabox-wrap ul li {
44
+ line-height: 120%;
45
+ list-style: disc inside none;
46
+ margin-bottom: 0;
47
+ }
48
+
49
+ #avhec-options input {
50
+
51
+ }
52
+
53
+ #avhec-generaloptions input {
54
+
55
+ }
56
+
57
+ /* Metabox FAQ */
58
+ #avhecBoxFAQ .inside ul {
59
+ margin-bottom: 6px;
60
+ }
61
+
62
+ #avhecBoxFAQ .inside ul li {
63
+ line-height: 120%;
64
+ list-style: disc inside none;
65
+ margin-bottom: 0;
66
+ }
67
+
68
+ /* Metabox Donations*/
69
+ #avhecBoxDonations .inside {
70
+
71
+ }
72
+
73
+ #avhecBoxDonations .versions {
74
+ padding: 6px 10px 12px;
75
+ }
76
+
77
+ /* Metabox Donations*/
78
+ #avhecBoxTranslation .inside {
79
+
80
+ }
81
+
82
+ /* Metabox in post and page */
83
+ #post_avhec_category_group {
84
+ width: 100%;
85
+ }
86
+
87
+ #avhec-catlist {
88
+ -moz-border-radius: 4px 4px 4px 4px;
89
+ background-color: #FFFFFF;
90
+ border: 1px solid #DFDFDF;
91
+ height: 20em;
92
+ margin-bottom: -1.8em;
93
+ overflow: auto;
94
+ width: 95%;
95
+ }
96
+
97
+ #avhec-catlist ul {
98
+ padding: 3px;
99
+ }
100
+
101
+ #avhec-catlist li ul {
102
+ padding: 0px;
103
+ }
104
+
105
+ #avhec-catlist li {
106
+ margin-bottom: 0px;
107
+ }
108
+
109
+ #avhecManualOrder {
110
+ width: 25%;
111
+ /* border: 1px solid #B2B2B2;*/
112
+ /* margin: 10px 10px 10px 0px;*/
113
+ /* padding: 5px 10px 5px 10px;*/
114
+ /* list-style: none;*/
115
+ /* background-color: #fff;*/
116
+ /* border-radius: 3px;*/
117
+ /* -webkit-border-radius: 3px;*/
118
+ }
119
+
120
+ #avhecManualOrder li.lineitem {
121
+ border: 1px solid #DFDFDF;
122
+ background-image: none;
123
+ border-radius: 3px;
124
+ -webkit-border-radius: 3px;
125
+ background-color: #FFFFFF;
126
+ color: #555555;
127
+ cursor: move;
128
+ margin-top: 5px;
129
+ margin-bottom: 5px;
130
+ padding: 2px 5px 2px 5px;
131
+ list-style: none outside none;
132
+ }
133
+
134
+ #avhecManualOrder .sortable-placeholder {
135
+ border: 1px dashed #B2B2B2;
136
+ margin-top: 5px;
137
+ margin-bottom: 5px;
138
+ padding: 2px 5px 2px 5px;
139
+ height: 1.5em;
140
+ line-height: 1.5em;
141
+ list-style: none outside none;
142
+ background-color: transparent;
143
+ /* IE10 */
144
+ background-image: -ms-linear-gradient(top, #f9f9f9, #f5f5f5);
145
+ /* Firefox */
146
+ background-image: -moz-linear-gradient(top, #f9f9f9, #f5f5f5);
147
+ /* Opera */
148
+ background-image: -o-linear-gradient(top, #f9f9f9, #f5f5f5);
149
+ /* old Webkit */
150
+ background-image: -webkit-gradient(linear, left top, left bottom, from(#f9f9f9), to(#f5f5f5) );
151
+ /* new Webkit */
152
+ background-image: -webkit-linear-gradient(top, #f9f9f9, #f5f5f5);
153
+ /* proposed W3C Markup */
154
+ background-image: linear-gradient(top, #f9f9f9, #f5f5f5);
155
+ }
3.6/css/avh-ec.widget.css ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* AVH Extended Categories Widget CSS */
2
+ .avhec-widget-line {
3
+ display: inline-block;
4
+ }
5
+
6
+ .avhec-widget-count {
7
+ display: inline;
8
+ }
9
+
10
+ .avhec-widget-rss {
11
+ display: inline;
12
+ }
3.6/helpers/avh-forms.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if (!function_exists('avh_doWidgetFormText')) {
3
+
4
+ function avh_doWidgetFormText($field_id, $field_name, $description, $value)
5
+ {
6
+ echo '<label for="' . $field_id . '">';
7
+ echo $description;
8
+ echo '<input class="widefat" id="' . $field_id . '" name="' . $field_name . '" type="text" value="' . esc_attr($value) . '" /> ';
9
+ echo '</label>';
10
+ echo '<br />';
11
+ }
12
+ }
13
+
14
+ if (!function_exists('avh_doWidgetFormCheckbox')) {
15
+
16
+ function avh_doWidgetFormCheckbox($field_id, $field_name, $description, $is_checked = FALSE)
17
+ {
18
+ echo '<label for="' . $field_id . '">';
19
+ echo '<input class="checkbox" type="checkbox" id="' . $field_id . '" name="' . $field_name . '"' . ($is_checked ? ' CHECKED' : '') . ' /> ';
20
+ echo $description;
21
+ echo '</label>';
22
+ echo '<br />';
23
+ }
24
+ }
25
+
26
+ if (!function_exists('avh_doWidgetFormSelect')) {
27
+
28
+ function avh_doWidgetFormSelect($field_id, $field_name, $description, $options, $selected_value)
29
+ {
30
+ echo '<label for="' . $field_id . '">';
31
+ echo $description . ' ';
32
+ echo '</label>';
33
+
34
+ $data = '';
35
+ foreach ($options as $value => $text) {
36
+ $data .= '<option value="' . $value . '" ' . ($value == $selected_value ? "SELECTED" : '') . '>' . $text . '</option>' . "/n";
37
+ }
38
+ echo '<select id="' . $field_id . '" name="' . $field_name . '"> ';
39
+ echo $data;
40
+ echo '</select>';
41
+ echo '<br />';
42
+ }
43
+ }
3.6/images/us_banner_logow_120x60.gif ADDED
Binary file
3.6/js/avh-ec.admin.manualorder.closure.js ADDED
@@ -0,0 +1 @@
 
1
+ function avhecManualOrder(){jQuery("#avhecManualOrder").sortable({placeholder:"sortable-placeholder",revert:false,items:".lineitem",opacity:0.65,cursor:"move",forcePlaceholderSize:true,tolerance:"pointer"})}addLoadEvent(avhecManualOrder);function orderCats(){jQuery("#updateText").html("Updating Category Order...");jQuery("#hdnManualOrder").val(jQuery("#avhecManualOrder").sortable("toArray"))};
3.6/js/avh-ec.admin.manualorder.js ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function avhecManualOrder() {
2
+ jQuery("#avhecManualOrder").sortable({
3
+ placeholder : "sortable-placeholder",
4
+ revert : false,
5
+ items : '.lineitem',
6
+ opacity: 0.65,
7
+ cursor: 'move',
8
+ forcePlaceholderSize: true,
9
+ tolerance : "pointer"
10
+ });
11
+ };
12
+
13
+ addLoadEvent(avhecManualOrder);
14
+
15
+ function orderCats() {
16
+ jQuery("#updateText").html("Updating Category Order...");
17
+ jQuery("#hdnManualOrder").val(
18
+ jQuery("#avhecManualOrder").sortable("toArray"));
19
+ }
3.6/js/avh-ec.categorygroup.closure.js ADDED
@@ -0,0 +1 @@
 
1
+ jQuery(document).ready(function(a){a("#the-list").wpList({delBefore:function(b){if("undefined"!=showNotice)return showNotice.warn()?b:false;return b}});a('.delete a[class^="delete"]').live("click",function(){return false})});
3.6/js/avh-ec.categorygroup.js ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(function($) {
2
+ var options = false, delBefore, delAfter;
3
+
4
+ delAfter = function( r, settings ) {
5
+ var id = $('cat', r).attr('id'), o;
6
+ for ( o = 0; o < options.length; o++ )
7
+ if ( id == options[o].value )
8
+ options[o] = null;
9
+ };
10
+
11
+ delBefore = function(s) {
12
+ if ( 'undefined' != showNotice )
13
+ return showNotice.warn() ? s : false;
14
+
15
+ return s;
16
+ };
17
+
18
+ $('#the-list').wpList({ delBefore: delBefore });
19
+
20
+ $('.delete a[class^="delete"]').live('click', function(){return false;});
21
+ });
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: 3.5
7
- Stable tag: 3.7.1
8
 
9
  The AVH Extended Categories Widgets gives you three widgets for displaying categories.
10
  == Description ==
@@ -135,6 +135,12 @@ Whether Widget 2 shows Movie or Music depends on the creation order of groups. I
135
  None
136
 
137
  == Changelog ==
 
 
 
 
 
 
138
  = Version 3.7.1 =
139
  * When updating a category a warning is can be shown.
140
 
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: 3.6.1
7
+ Stable tag: 3.8.0
8
 
9
  The AVH Extended Categories Widgets gives you three widgets for displaying categories.
10
  == Description ==
135
  None
136
 
137
  == Changelog ==
138
+ = Version 3.8.0 =
139
+ * Add support for WordPress 3.6
140
+ * Dropped support for PHP4, from this version on it PHP 5 or higher.
141
+ * Fixed PHP Strict errors
142
+ * Fixed undefined variables errors.
143
+
144
  = Version 3.7.1 =
145
  * When updating a category a warning is can be shown.
146
 
widget_extended_categories.php CHANGED
@@ -1,28 +1,29 @@
1
  <?php
2
- /*
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: 3.7.1
7
- Author: Peter van der Does
8
- Author URI: http://blog.avirtualhome.com/
 
 
9
 
10
- Copyright 2012 Peter van der Does (email : peter@avirtualhome.com)
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
- This program is free software; you can redistribute it and/or modify
13
- it under the terms of the GNU General Public License as published by
14
- the Free Software Foundation; either version 2 of the License, or
15
- (at your option) any later version.
16
-
17
- This program is distributed in the hope that it will be useful,
18
- but WITHOUT ANY WARRANTY; without even the implied warranty of
19
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
- GNU General Public License for more details.
21
-
22
- You should have received a copy of the GNU General Public License
23
- along with this program; if not, write to the Free Software
24
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
- */
26
  if (! defined('AVH_FRAMEWORK')) {
27
  define('AVH_FRAMEWORK', true);
28
  }
@@ -39,12 +40,16 @@ if ($_avhec_version >= 2.8) {
39
  require_once ($_avhec_abs_dir . '/libs/avh-db.php');
40
 
41
  switch ($_avhec_version) {
42
- case ($_avhec_version >= 2.8 && $_avhec_version < 3.3):
43
- $_avhec_version_dir = '/2.8';
44
- break;
45
  case ($_avhec_version >= 3.3):
46
  $_avhec_version_dir = '/3.3';
47
  break;
 
 
 
 
48
  }
49
 
50
  $_avhec_dir = basename($_avhec_abs_dir);
1
  <?php
2
+ /**
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: 3.8.0
7
+ * Author: Peter van der Does
8
+ * Author URI: http://blog.avirtualhome.com/
9
+ *
10
+ * Copyright 2012-2013 Peter van der Does (email : peter@avirtualhome.com)
11
 
12
+ * This program is free software; you can redistribute it and/or modify
13
+ * it under the terms of the GNU General Public License as published by
14
+ * the Free Software Foundation; either version 2 of the License, or
15
+ * (at your option) any later version.
16
+ *
17
+ * This program is distributed in the hope that it will be useful,
18
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
+ * GNU General Public License for more details.
21
+ *
22
+ * You should have received a copy of the GNU General Public License
23
+ * along with this program; if not, write to the Free Software
24
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
+ */
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  if (! defined('AVH_FRAMEWORK')) {
28
  define('AVH_FRAMEWORK', true);
29
  }
40
  require_once ($_avhec_abs_dir . '/libs/avh-db.php');
41
 
42
  switch ($_avhec_version) {
43
+ case ($_avhec_version >= 3.6):
44
+ $_avhec_version_dir = '/3.6';
45
+ break;
46
  case ($_avhec_version >= 3.3):
47
  $_avhec_version_dir = '/3.3';
48
  break;
49
+ case ($_avhec_version >= 2.8):
50
+ $_avhec_version_dir = '/2.8';
51
+ break;
52
+
53
  }
54
 
55
  $_avhec_dir = basename($_avhec_abs_dir);