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