diff --git a/wp-content/plugins/extended-categories-widget/2.8/avh-ec.client.php b/wp-content/plugins/extended-categories-widget/2.8/avh-ec.client.php index 3acf5bce8f7865d2f66818a4dd27cd554cd0fd3e..ab2e9c0d1c7e11bafb2d501f07a4d4a70870d7ce 100644 --- a/wp-content/plugins/extended-categories-widget/2.8/avh-ec.client.php +++ b/wp-content/plugins/extended-categories-widget/2.8/avh-ec.client.php @@ -2,77 +2,65 @@ /** * Singleton Class - * */ -class AVH_EC_Singleton -{ - +class AVH_EC_Singleton { /** - * * @param $class * @param $arg1 */ - function &getInstance ($class, $arg1 = null) - { + function &getInstance($class, $arg1 = null) { static $instances = array(); // array of instance names if (array_key_exists($class, $instances)) { - $instance = & $instances[$class]; + $instance = &$instances[ $class ]; } else { - if (! class_exists($class)) { + if ( ! class_exists($class)) { switch ($class) { case 'AVH_EC_Core': - require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.core.php'); + require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.core.php'); break; case 'AVH_EC_Category_Group': - require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.category-group.php'); + require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.category-group.php'); break; case 'AVH_EC_Widget_Helper_Class': - require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widget-helper.php'); + require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widget-helper.php'); break; } } - $instances[$class] = new $class($arg1); - $instance = & $instances[$class]; + $instances[ $class ] = new $class($arg1); + $instance = &$instances[ $class ]; } + return $instance; } // getInstance } // singleton - /** * Include the necessary files - * */ -require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/helpers/avh-forms.php'); -require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widgets.php'); +require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/helpers/avh-forms.php'); +require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widgets.php'); /** * Initialize the plugin - * */ -function avhextendedcategories_init () -{ +function avhextendedcategories_init() { // Admin if (is_admin()) { - require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.admin.php'); + require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.admin.php'); $avhec_admin = new AVH_EC_Admin(); } AVH_EC_Singleton::getInstance('AVH_EC_Core'); add_action('widgets_init', 'avhextendedcategories_widgets_init'); - } // End avhamazon_init() - /** * Register the widget * * @WordPress Action widgets_init - * @since 3.0 - * + * @since 3.0 */ -function avhextendedcategories_widgets_init () -{ +function avhextendedcategories_widgets_init() { register_widget('WP_Widget_AVH_ExtendedCategories_Normal'); register_widget('WP_Widget_AVH_ExtendedCategories_Top'); register_widget('WP_Widget_AVH_ExtendedCategories_Category_Group'); diff --git a/wp-content/plugins/extended-categories-widget/2.8/class/avh-ec.admin.php b/wp-content/plugins/extended-categories-widget/2.8/class/avh-ec.admin.php index 9a033caf85f6b5c404d7b24d52497a004de98565..67b121dc35940a211e9d277b858c25663bc0eb6f 100644 --- a/wp-content/plugins/extended-categories-widget/2.8/class/avh-ec.admin.php +++ b/wp-content/plugins/extended-categories-widget/2.8/class/avh-ec.admin.php @@ -1,39 +1,35 @@ <?php -class AVH_EC_Admin -{ +class AVH_EC_Admin { /** - * - * @var AVH_EC_Core - */ - var $core; - - /** - * * @var AVH_EC_Category_Group */ var $catgrp; - + /** + * @var AVH_EC_Core + */ + var $core; var $hooks = array(); var $message; /** * PHP5 constructor - * */ - function __construct () - { + function __construct() { // Initialize the plugin - $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core'); - $this->catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); + $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core'); + $this->catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); add_action('wp_ajax_delete-group', array(&$this, 'ajaxDeleteGroup')); // Admin menu - add_action('admin_init', array(&$this,'actionAdminInit')); + add_action('admin_init', array(&$this, 'actionAdminInit')); add_action('admin_menu', array(&$this, 'actionAdminMenu')); - add_filter('plugin_action_links_extended-categories-widget/widget_extended_categories.php', array(&$this, 'filterPluginActions'), 10, 2); + add_filter('plugin_action_links_extended-categories-widget/widget_extended_categories.php', + array(&$this, 'filterPluginActions'), + 10, + 2); // Actions used for editing posts add_action('load-post.php', array(&$this, 'actionLoadPostPage')); @@ -51,92 +47,105 @@ class AVH_EC_Admin /** * PHP4 Constructor - * */ - function AVH_EC_Admin () - { + function AVH_EC_Admin() { $this->__construct(); } function actionAdminInit() { if (is_admin() && isset($_GET['taxonomy']) && 'category' == $_GET['taxonomy']) { - add_action($_GET['taxonomy'] . '_edit_form', array(&$this,'displayCategoryGroupForm'), 10, 2 ); + add_action($_GET['taxonomy'] . '_edit_form', array(&$this, 'displayCategoryGroupForm'), 10, 2); } - add_action('edit_term', array(&$this,'handleEditTerm'), 10, 3 ); - + add_action('edit_term', array(&$this, 'handleEditTerm'), 10, 3); } /** + * Add the Tools and Options to the Management and Options page repectively * - * Adds Category Group form - * @WordPress action category_edit_form - * - * @param unknown_type $term - * @param unknown_type $taxonomy + * @WordPress Action admin_menu */ - function displayCategoryGroupForm($term, $taxonomy){ + function actionAdminMenu() { - $current_selection = ''; - $tax_meta = get_option($this->core->db_options_tax_meta); - if ( isset($tax_meta[$taxonomy][$term->term_id]) ) { - $tax_meta = $tax_meta[$taxonomy][$term->term_id]; - $current_selection = $tax_meta['category_group_term_id']; - } + // Register Style and Scripts + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; + wp_register_script('avhec-categorygroup-js', + AVHEC_PLUGIN_URL . '/js/avh-ec.categorygroup' . $suffix . '.js', + array('jquery'), + $this->core->version, + true); + wp_register_script('avhec-manualorder', + AVHEC_PLUGIN_URL . '/js/avh-ec.admin.manualorder' . $suffix . '.js', + array('jquery-ui-sortable'), + $this->core->version, + false); + wp_register_style('avhec-admin-css', + AVHEC_PLUGIN_URL . '/css/avh-ec.admin.css', + array('wp-admin'), + $this->core->version, + 'screen'); - if (empty($current_selection)) { - $current_group = $this->catgrp->getGroupByCategoryID($term->term_id); - $current_selection= $current_group->term_id; - } + // Add menu system + $folder = $this->core->getBaseDirectory(AVHEC_PLUGIN_DIR); + add_menu_page('AVH Extended Categories', + 'AVH Extended Categories', + 'manage_options', + $folder, + array(&$this, 'doMenuOverview')); + $this->hooks['menu_overview'] = add_submenu_page($folder, + 'AVH Extended Categories: ' . __('Overview', 'avh-ec'), + __('Overview', 'avh-ec'), + 'manage_options', + $folder, + array(&$this, 'doMenuOverview')); + $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')); + $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')); + $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')); + $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')); - $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty'=>FALSE)); - foreach ($cat_groups as $group) { - $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit'); - $dropdown_value[] = $group->term_id; - $dropdown_text[] = $temp_cat->name; - } + // Add actions for menu pages + // Overview Menu + add_action('load-' . $this->hooks['menu_overview'], array(&$this, 'actionLoadPageHook_Overview')); - foreach ( $dropdown_value as $key => $sel) { - $seldata .= '<option value="' . esc_attr($sel) . '" ' . (($current_selection == $sel) ? 'selected="selected"' : '') . ' >' . esc_html(ucfirst($dropdown_text[$key])) . '</option>' . "\n"; - } + // General Options Menu + add_action('load-' . $this->hooks['menu_general'], array(&$this, 'actionLoadPageHook_General')); - echo '<h3>AVH Extended Categories - Category Group Widget</h3>'; - echo '<table class="form-table"><tbody>'; - echo '<tr class="form-field">'; - echo '<th valign="top" scope="row">'; - echo '<label for="avhec_categorygroup">Category Group</label></th>'; - echo '<td>'; - echo '<select id="avhec_categorygroup" name="avhec_categorygroup">'; - echo $seldata; - echo '</select>'; - echo '<p class="description">Select the category group to show on the archive page.</p>'; - echo '</td>'; - echo '</tr>'; - echo '</tbody></table>'; - } + // Category Groups Menu + add_action('load-' . $this->hooks['menu_category_groups'], array(&$this, 'actionLoadPageHook_CategoryGroup')); - /** - * Saves the association Category - Category Group fron the edit taxonomy page - * @WordPress action edit_form. - * - * @param unknown_type $term_id - * @param unknown_type $tt_id - * @param unknown_type $taxonomy - */ - function handleEditTerm( $term_id, $tt_id, $taxonomy ) { - $tax_meta = get_option($this->core->db_options_tax_meta); - if ( isset($_POST['avhec_categorygroup']) && $tax_meta[$taxonomy][$term_id]['category_group_term_id'] != $_POST['avhec_categorygroup']) { - $tax_meta[$taxonomy][$term_id]['category_group_term_id'] = $_POST['avhec_categorygroup']; - update_option($this->core->db_options_tax_meta, $tax_meta); - } + // FAQ Menu + add_action('load-' . $this->hooks['menu_faq'], array(&$this, 'actionLoadPageHook_faq')); } /** * When a category is created this function is called to add the new category to the group all + * * @param $term_id * @param $term_taxonomy_id */ - function actionCreatedCategory ($term_id, $term_taxonomy_id) - { + function actionCreatedCategory($term_id, $term_taxonomy_id) { $group_id = $this->catgrp->getTermIDBy('slug', 'all'); $this->catgrp->setCategoriesForGroup($group_id, (array) $term_id); } @@ -145,75 +154,74 @@ class AVH_EC_Admin * When a category is deleted this function is called so the category is deleted from every group as well. * * @param object $term - * @param int $term_taxonomy_id + * @param int $term_taxonomy_id */ - function actionDeleteCategory ($term_id, $term_taxonomy_id) - { + function actionDeleteCategory($term_id, $term_taxonomy_id) { $this->catgrp->doDeleteCategoryFromGroup($term_id); } /** - * Enqueues the style on the post.php and page.php pages - * @WordPress Action load-$pagenow - * - */ - function actionLoadPostPage () - { - wp_enqueue_style('avhec-admin-css'); - } - - /** - * Add the Tools and Options to the Management and Options page repectively - * - * @WordPress Action admin_menu - * + * Setup everything needed for the Category Group page */ - function actionAdminMenu () - { - - // Register Style and Scripts - $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.closure'; - wp_register_script('avhec-categorygroup-js', AVHEC_PLUGIN_URL . '/js/avh-ec.categorygroup' . $suffix . '.js', array('jquery'), $this->core->version, true); - wp_register_script('avhec-manualorder', AVHEC_PLUGIN_URL . '/js/avh-ec.admin.manualorder' . $suffix . '.js', array ( 'jquery-ui-sortable' ), $this->core->version, false); - wp_register_style('avhec-admin-css', AVHEC_PLUGIN_URL . '/css/avh-ec.admin.css', array('wp-admin'), $this->core->version, 'screen'); + function actionLoadPageHook_CategoryGroup() { - // Add menu system - $folder = $this->core->getBaseDirectory(AVHEC_PLUGIN_DIR); - add_menu_page('AVH Extended Categories', 'AVH Extended Categories', 'manage_options', $folder, array(&$this, 'doMenuOverview')); - $this->hooks['menu_overview'] = add_submenu_page($folder, 'AVH Extended Categories: ' . __('Overview', 'avh-ec'), __('Overview', 'avh-ec'), 'manage_options', $folder, array(&$this, 'doMenuOverview')); - $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')); - $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')); - $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')); - $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')); + // Add metaboxes + add_meta_box('avhecBoxCategoryGroupAdd', + __('Add Group', 'avh-ec'), + array(&$this, 'metaboxCategoryGroupAdd'), + $this->hooks['menu_category_groups'], + 'normal', + 'core'); + add_meta_box('avhecBoxCategoryGroupList', + __('Group Overview', 'avh-ec'), + array(&$this, 'metaboxCategoryGroupList'), + $this->hooks['menu_category_groups'], + 'side', + 'core'); + add_meta_box('avhecBoxCategoryGroupSpecialPages', + __('Special Pages', 'avh-ec'), + array(&$this, 'metaboxCategoryGroupSpecialPages'), + $this->hooks['menu_category_groups'], + 'normal', + 'core'); + + if (AVH_Common::getWordpressVersion() >= 3.1) { + add_screen_option('layout_columns', array('max' => 2, 'default' => 2)); + } else { + add_filter('screen_layout_columns', array(&$this, 'filterScreenLayoutColumns'), 10, 2); + } - // Add actions for menu pages - // Overview Menu - add_action('load-' . $this->hooks['menu_overview'], array(&$this, 'actionLoadPageHook_Overview')); + // WordPress core Scripts + wp_enqueue_script('common'); + wp_enqueue_script('wp-lists'); + wp_enqueue_script('postbox'); - // General Options Menu - add_action('load-' . $this->hooks['menu_general'], array(&$this, 'actionLoadPageHook_General')); + // Plugin Scripts + wp_enqueue_script('avhec-categorygroup-js'); - // Category Groups Menu - add_action('load-' . $this->hooks['menu_category_groups'], array(&$this, 'actionLoadPageHook_CategoryGroup')); + // WordPress core Styles + wp_admin_css('css/dashboard'); - // FAQ Menu - add_action('load-' . $this->hooks['menu_faq'], array(&$this, 'actionLoadPageHook_faq')); + // Plugin Style + wp_enqueue_style('avhec-admin-css'); } /** - * Setup everything needed for the Overview page - * + * Setup everything needed for the General Options page */ - function actionLoadPageHook_Overview () - { + function actionLoadPageHook_General() { // Add metaboxes - add_meta_box('avhecBoxCategoryGroupList', __('Group Overview', 'avh-ec'), array(&$this, 'metaboxCategoryGroupList'), $this->hooks['menu_overview'], 'normal', 'core'); - add_meta_box('avhecBoxTranslation', __('Translation', 'avh-ec'), array(&$this, 'metaboxTranslation'), $this->hooks['menu_overview'], 'normal', 'core'); - - if (AVH_Common::getWordpressVersion() >= 3.1 ) { - add_screen_option('layout_columns', array('max' => 2, 'default' => 2) ); + add_meta_box('avhecBoxOptions', + __('Options', 'avh-ec'), + array(&$this, 'metaboxOptions'), + $this->hooks['menu_general'], + 'normal', + 'core'); + + if (AVH_Common::getWordpressVersion() >= 3.1) { + add_screen_option('layout_columns', array('max' => 2, 'default' => 2)); } else { - add_filter('screen_layout_columns', array ( &$this, 'filterScreenLayoutColumns' ), 10, 2); + add_filter('screen_layout_columns', array(&$this, 'filterScreenLayoutColumns'), 10, 2); } // WordPress core Scripts @@ -221,75 +229,67 @@ class AVH_EC_Admin wp_enqueue_script('wp-lists'); wp_enqueue_script('postbox'); - // Plugin Scripts - wp_enqueue_script('avhec-categorygroup-js'); - // WordPress core Styles wp_admin_css('css/dashboard'); - // Plugin Style + // Plugin Style and Scripts wp_enqueue_style('avhec-admin-css'); } /** - * Menu Page Overview - * - * @return none + * Setup everything needed for the Manul Order page */ - function doMenuOverview () - { - global $screen_layout_columns; + function actionLoadPageHook_ManualOrder() { - // This box can't be unselectd in the the Screen Options - add_meta_box('avhecBoxAnnouncements', __('Announcements', 'avh-ec'), array(&$this, 'metaboxAnnouncements'), $this->hooks['menu_overview'], 'side', ''); - add_meta_box('avhecBoxDonations', __('Donations', 'avh-ec'), array(&$this, 'metaboxDonations'), $this->hooks['menu_overview'], 'side', ''); + add_meta_box('avhecBoxManualOrder', + __('Manually Order Categories', 'avh-ec'), + array(&$this, 'metaboxManualOrder'), + $this->hooks['menu_manual_order'], + 'normal', + 'core'); - $hide2 = ''; - switch ($screen_layout_columns) { - case 2: - $width = 'width:49%;'; - break; - default: - $width = 'width:98%;'; - $hide2 = 'display:none;'; + if (AVH_Common::getWordpressVersion() >= 3.1) { + add_screen_option('layout_columns', array('max' => 1, 'default' => 1)); + } else { + add_filter('screen_layout_columns', array(&$this, 'filterScreenLayoutColumns'), 10, 2); } - echo '<div class="wrap avhec-metabox-wrap">'; - echo $this->displayIcon('index'); - echo '<h2>' . 'AVH Extended Categories - ' . __('Overview', 'avh-ec') . '</h2>'; - echo ' <div id="dashboard-widgets-wrap">'; - echo ' <div id="dashboard-widgets" class="metabox-holder">'; - echo ' <div class="postbox-container" style="' . $width . '">' . "\n"; - do_meta_boxes($this->hooks['menu_overview'], 'normal', ''); - echo " </div>"; - echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n"; - do_meta_boxes($this->hooks['menu_overview'], 'side', ''); - echo ' </div>'; - echo ' </div>'; - - echo '<br class="clear"/>'; - echo ' </div>'; //dashboard-widgets-wrap - echo '</div>'; // wrap + // WordPress core Styles and Scripts + wp_enqueue_script('common'); + wp_enqueue_script('wp-lists'); + wp_enqueue_script('postbox'); + wp_enqueue_script('jquery-ui-sortable'); + wp_enqueue_script('avhec-manualorder'); + // WordPress core Styles + wp_admin_css('css/dashboard'); - $this->printMetaboxGeneralNonces(); - $this->printMetaboxJS('overview'); - $this->printAdminFooter(); + // Plugin Style + wp_enqueue_style('avhec-admin-css'); } /** - * Setup everything needed for the General Options page - * + * Setup everything needed for the Overview page */ - function actionLoadPageHook_General () - { + function actionLoadPageHook_Overview() { // Add metaboxes - add_meta_box('avhecBoxOptions', __('Options', 'avh-ec'), array(&$this, 'metaboxOptions'), $this->hooks['menu_general'], 'normal', 'core'); - - if (AVH_Common::getWordpressVersion() >= 3.1 ) { - add_screen_option('layout_columns', array('max' => 2, 'default' => 2) ); + add_meta_box('avhecBoxCategoryGroupList', + __('Group Overview', 'avh-ec'), + array(&$this, 'metaboxCategoryGroupList'), + $this->hooks['menu_overview'], + 'normal', + 'core'); + add_meta_box('avhecBoxTranslation', + __('Translation', 'avh-ec'), + array(&$this, 'metaboxTranslation'), + $this->hooks['menu_overview'], + 'normal', + 'core'); + + if (AVH_Common::getWordpressVersion() >= 3.1) { + add_screen_option('layout_columns', array('max' => 2, 'default' => 2)); } else { - add_filter('screen_layout_columns', array ( &$this, 'filterScreenLayoutColumns' ), 10, 2); + add_filter('screen_layout_columns', array(&$this, 'filterScreenLayoutColumns'), 10, 2); } // WordPress core Scripts @@ -297,174 +297,161 @@ class AVH_EC_Admin wp_enqueue_script('wp-lists'); wp_enqueue_script('postbox'); + // Plugin Scripts + wp_enqueue_script('avhec-categorygroup-js'); + // WordPress core Styles wp_admin_css('css/dashboard'); - // Plugin Style and Scripts + // Plugin Style wp_enqueue_style('avhec-admin-css'); - } /** - * Menu Page General Options - * - * @return none + * Setup everything needed for the FAQ page */ - function doMenuGeneral () - { - global $screen_layout_columns; - - $groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty'=>FALSE)); - foreach ($groups as $group) { - $group_id[] = $group->term_id; - $groupname[] = $group->name; + function actionLoadPageHook_faq() { + + add_meta_box('avhecBoxFAQ', + __('F.A.Q.', 'avh-ec'), + array(&$this, 'metaboxFAQ'), + $this->hooks['menu_faq'], + 'normal', + 'core'); + add_meta_box('avhecBoxTranslation', + __('Translation', 'avh-ec'), + array(&$this, 'metaboxTranslation'), + $this->hooks['menu_faq'], + 'normal', + 'core'); + + if (AVH_Common::getWordpressVersion() >= 3.1) { + add_screen_option('layout_columns', array('max' => 2, 'default' => 2)); + } else { + add_filter('screen_layout_columns', array(&$this, 'filterScreenLayoutColumns'), 10, 2); } - $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')); - $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')); - $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')); - $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')); + // WordPress core Styles and Scripts + wp_enqueue_script('common'); + wp_enqueue_script('wp-lists'); + wp_enqueue_script('postbox'); - if (isset($_POST['updateoptions'])) { - check_admin_referer('avh_ec_generaloptions'); + // WordPress core Styles + wp_admin_css('css/dashboard'); - $formoptions = $_POST['avhec']; - $options = $this->core->getOptions(); + // Plugin Style + wp_enqueue_style('avhec-admin-css'); + } - //$all_data = array_merge( $options_general ); - $all_data = $options_general; - foreach ($all_data as $option) { - $section = substr($option[0], strpos($option[0], '[') + 1); - $section = substr($section, 0, strpos($section, '][')); - $option_key = rtrim($option[0], ']'); - $option_key = substr($option_key, strpos($option_key, '][') + 2); + /** + * Enqueues the style on the post.php and page.php pages + * + * @WordPress Action load-$pagenow + */ + function actionLoadPostPage() { + wp_enqueue_style('avhec-admin-css'); + } - switch ($section) { - case 'general': - case 'cat_group': - $current_value = $options[$section][$option_key]; - break; - } - // Every field in a form is set except unchecked checkboxes. Set an unchecked checkbox to 0. - $newval = (isset($formoptions[$section][$option_key]) ? attribute_escape($formoptions[$section][$option_key]) : 0); - if ($newval != $current_value) { // Only process changed fields. - switch ($section) { - case 'general': - case 'cat_group': - $options[$section][$option_key] = $newval; - break; - } - } - } - $this->core->saveOptions($options); - $this->message = __('Options saved', 'avh-ec'); - $this->status = 'updated fade'; + /** + * Ajax Helper: inline delete of the groups + */ + function ajaxDeleteGroup() { + $group_id = isset($_POST['id']) ? (int) $_POST['id'] : 0; + check_ajax_referer('delete-avhecgroup_' . $group_id); + if ( ! current_user_can('manage_categories')) { + die('-1'); } - $this->displayMessage(); - - $actual_options = $this->core->getOptions(); - foreach ($actual_options['cat_group'] as $key => $value) { - if (! (in_array($value, (array) $group_id))) { - $actual_options['cat_group'][$key] = $this->catgrp->getTermIDBy('slug', 'none'); - } + $check = $this->catgrp->getGroup($group_id); + if (false === $check) { + die('1'); } - $hide2 = ''; - switch ($screen_layout_columns) { - case 2: - $width = 'width:49%;'; - break; - default: - $width = 'width:98%;'; - $hide2 = 'display:none;'; + if ($this->catgrp->doDeleteGroup($group_id)) { + die('1'); + } else { + die('0'); } - $data['options_general'] = $options_general; - $data['actual_options'] = $actual_options; - - // This box can't be unselectd in the the Screen Options - add_meta_box('avhecBoxDonations', __('Donations', 'avh-ec'), array(&$this, 'metaboxDonations'), $this->hooks['menu_general'], 'side', 'core'); + } - $hide2 = ''; - switch ($screen_layout_columns) { - case 2: - $width = 'width:49%;'; - break; - default: - $width = 'width:98%;'; - $hide2 = 'display:none;'; - } - - echo '<div class="wrap avhec-metabox-wrap">'; - echo $this->displayIcon('index'); - echo '<h2>' . 'AVH Extended Categories - ' . __('General Options', 'avh-ec') . '</h2>'; - echo '<form name="avhec-generaloptions" id="avhec-generaloptions" method="POST" action="' . admin_url('admin.php?page=avhec-general') . '" accept-charset="utf-8" >'; - wp_nonce_field('avh_ec_generaloptions'); + /** + * Adds Category Group form + * + * @WordPress action category_edit_form + * + * @param unknown_type $term + * @param unknown_type $taxonomy + */ + function displayCategoryGroupForm($term, $taxonomy) { - echo ' <div id="dashboard-widgets-wrap">'; - echo ' <div id="dashboard-widgets" class="metabox-holder">'; - echo ' <div class="postbox-container" style="' . $width . '">' . "\n"; - do_meta_boxes($this->hooks['menu_general'], 'normal', $data); - echo " </div>"; - echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n"; - do_meta_boxes($this->hooks['menu_general'], 'side', $data); - echo ' </div>'; - echo ' </div>'; + $current_selection = ''; + $tax_meta = get_option($this->core->db_options_tax_meta); + if (isset($tax_meta[ $taxonomy ][ $term->term_id ])) { + $tax_meta = $tax_meta[ $taxonomy ][ $term->term_id ]; + $current_selection = $tax_meta['category_group_term_id']; + } - echo '<br class="clear"/>'; - echo ' </div>'; //dashboard-widgets-wrap - echo '<p class="submit"><input class="button" type="submit" name="updateoptions" value="' . __('Save Changes', 'avhf-ec') . '" /></p>'; - echo '</form>'; + if (empty($current_selection)) { + $current_group = $this->catgrp->getGroupByCategoryID($term->term_id); + $current_selection = $current_group->term_id; + } - echo '</div>'; // wrap + $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false)); + foreach ($cat_groups as $group) { + $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit'); + $dropdown_value[] = $group->term_id; + $dropdown_text[] = $temp_cat->name; + } + foreach ($dropdown_value as $key => $sel) { + $seldata .= '<option value="' . + esc_attr($sel) . + '" ' . + (($current_selection == $sel) ? 'selected="selected"' : '') . + ' >' . + esc_html(ucfirst($dropdown_text[ $key ])) . + '</option>' . + "\n"; + } - $this->printMetaboxGeneralNonces(); - $this->printMetaboxJS('general'); - $this->printAdminFooter(); + echo '<h3>AVH Extended Categories - Category Group Widget</h3>'; + echo '<table class="form-table"><tbody>'; + echo '<tr class="form-field">'; + echo '<th valign="top" scope="row">'; + echo '<label for="avhec_categorygroup">Category Group</label></th>'; + echo '<td>'; + echo '<select id="avhec_categorygroup" name="avhec_categorygroup">'; + echo $seldata; + echo '</select>'; + echo '<p class="description">Select the category group to show on the archive page.</p>'; + echo '</td>'; + echo '</tr>'; + echo '</tbody></table>'; } /** - * Options Metabox + * Displays the icon on the menu pages * + * @param $icon */ - function metaboxOptions ($data) - { - echo $this->printOptions($data['options_general'], $data['actual_options']); + function displayIcon($icon) { + return ('<div class="icon32" id="icon-' . $icon . '"><br/></div>'); } /** - * Setup everything needed for the Category Group page - * + * Display WP alert */ - function actionLoadPageHook_CategoryGroup () - { - - // Add metaboxes - add_meta_box('avhecBoxCategoryGroupAdd', __('Add Group', 'avh-ec'), array(&$this, 'metaboxCategoryGroupAdd'), $this->hooks['menu_category_groups'], 'normal', 'core'); - add_meta_box('avhecBoxCategoryGroupList', __('Group Overview', 'avh-ec'), array(&$this, 'metaboxCategoryGroupList'), $this->hooks['menu_category_groups'], 'side', 'core'); - add_meta_box('avhecBoxCategoryGroupSpecialPages', __('Special Pages', 'avh-ec'), array(&$this, 'metaboxCategoryGroupSpecialPages'), $this->hooks['menu_category_groups'], 'normal', 'core'); - - if (AVH_Common::getWordpressVersion() >= 3.1 ) { - add_screen_option('layout_columns', array('max' => 2, 'default' => 2) ); - } else { - add_filter('screen_layout_columns', array ( &$this, 'filterScreenLayoutColumns' ), 10, 2); + function displayMessage() { + if ($this->message != '') { + $message = $this->message; + $status = $this->status; + $this->message = $this->status = ''; // Reset + } + if (isset($message)) { + $status = ($status != '') ? $status : 'updated fade'; + echo '<div id="message" class="' . $status . '">'; + echo '<p><strong>' . $message . '</strong></p></div>'; } - - // WordPress core Scripts - wp_enqueue_script('common'); - wp_enqueue_script('wp-lists'); - wp_enqueue_script('postbox'); - - // Plugin Scripts - wp_enqueue_script('avhec-categorygroup-js'); - - // WordPress core Styles - wp_admin_css('css/dashboard'); - - // Plugin Style - wp_enqueue_style('avhec-admin-css'); - } /** @@ -472,71 +459,145 @@ class AVH_EC_Admin * * @return none */ - function doMenuCategoryGroup () - { + function doMenuCategoryGroup() { global $screen_layout_columns; - $data_add_group_default = array('name'=>'', 'slug'=>'', 'widget_title'=>'', 'description'=>''); - $data_add_group_new = $data_add_group_default; - - $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')); - $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')); - $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')); - $options_add_group[] = array('avhec_add_group[add][description]', __('Description', 'avh-ec'), 'textarea', 40, __('Description is not prominent by default.', 'avh-ec'), 5); - - $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')); - $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')); - $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')); - $options_edit_group[] = array('avhec_edit_group[edit][description]', __('Description', 'avh-ec'), 'textarea', 40, __('Description is not prominent by default.', 'avh-ec'), 5); - $options_edit_group[] = array('avhec_edit_group[edit][categories]', __('Categories', 'avh-ec'), 'catlist', 0, __('Select categories to be included in the group.', 'avh-ec')); + $data_add_group_default = array('name' => '', 'slug' => '', 'widget_title' => '', 'description' => ''); + $data_add_group_new = $data_add_group_default; + + $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') + ); + $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') + ); + $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') + ); + $options_add_group[] = array( + 'avhec_add_group[add][description]', + __('Description', 'avh-ec'), + 'textarea', + 40, + __('Description is not prominent by default.', 'avh-ec'), + 5 + ); + + $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') + ); + $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') + ); + $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') + ); + $options_edit_group[] = array( + 'avhec_edit_group[edit][description]', + __('Description', 'avh-ec'), + 'textarea', + 40, + __('Description is not prominent by default.', 'avh-ec'), + 5 + ); + $options_edit_group[] = array( + 'avhec_edit_group[edit][categories]', + __('Categories', 'avh-ec'), + 'catlist', + 0, + __('Select categories to be included in the group.', 'avh-ec') + ); if (isset($_POST['addgroup'])) { check_admin_referer('avh_ec_addgroup'); $formoptions = $_POST['avhec_add_group']; - $data_add_group_new['name'] = $formoptions['add']['name']; - $data_add_group_new['slug'] = empty($formoptions['add']['slug']) ? sanitize_title($data_add_group_new['name']) : sanitize_title($formoptions['add']['slug']); + $data_add_group_new['name'] = $formoptions['add']['name']; + $data_add_group_new['slug'] = empty($formoptions['add']['slug']) ? sanitize_title($data_add_group_new['name']) : sanitize_title($formoptions['add']['slug']); $data_add_group_new['widget_title'] = $formoptions['add']['widget_title']; - $data_add_group_new['description'] = $formoptions['add']['description']; + $data_add_group_new['description'] = $formoptions['add']['description']; $id = $this->catgrp->getTermIDBy('slug', $data_add_group_new['slug']); - if (! $id) { - $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']); + if ( ! $id) { + $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']); $this->catgrp->setCategoriesForGroup($group_id); - $this->message = __('Category group saved', 'avh-ec'); - $this->status = 'updated fade'; + $this->message = __('Category group saved', 'avh-ec'); + $this->status = 'updated fade'; $data_add_group_new = $data_add_group_default; - } else { - $group = $this->catgrp->getGroup($id); + $group = $this->catgrp->getGroup($id); $this->message = __('Category group conflicts with ', 'avh-ec') . $group->name; $this->message .= '<br />' . __('Same slug is used. ', 'avh-ec'); $this->status = 'error'; - } $this->displayMessage(); } $data_add_group['add'] = $data_add_group_new; - $data['add'] = array('form'=>$options_add_group, 'data'=>$data_add_group); + $data['add'] = array('form' => $options_add_group, 'data' => $data_add_group); if (isset($_GET['action'])) { $action = $_GET['action']; switch ($action) { case 'edit': - $group_id = (int) $_GET['group_ID']; - $group = $this->catgrp->getGroup($group_id); + $group_id = (int) $_GET['group_ID']; + $group = $this->catgrp->getGroup($group_id); $widget_title = $this->catgrp->getWidgetTitleForGroup($group_id); - $cats = $this->catgrp->getCategoriesFromGroup($group_id); - - $data_edit_group['edit'] = array('group_id'=>$group_id, 'name'=>$group->name, 'slug'=>$group->slug, 'widget_title'=>$widget_title, 'description'=>$group->description, 'categories'=>$cats); - $data['edit'] = array('form'=>$options_edit_group, 'data'=>$data_edit_group); - - add_meta_box('avhecBoxCategoryGroupEdit', __('Edit Group', 'avh-ec') . ': ' . $group->name, array(&$this, 'metaboxCategoryGroupEdit'), $this->hooks['menu_category_groups'], 'normal', 'low'); + $cats = $this->catgrp->getCategoriesFromGroup($group_id); + + $data_edit_group['edit'] = array( + 'group_id' => $group_id, + 'name' => $group->name, + 'slug' => $group->slug, + 'widget_title' => $widget_title, + 'description' => $group->description, + 'categories' => $cats + ); + $data['edit'] = array('form' => $options_edit_group, 'data' => $data_edit_group); + + add_meta_box('avhecBoxCategoryGroupEdit', + __('Edit Group', 'avh-ec') . ': ' . $group->name, + array(&$this, 'metaboxCategoryGroupEdit'), + $this->hooks['menu_category_groups'], + 'normal', + 'low'); break; case 'delete': - if (! isset($_GET['group_ID'])) { + if ( ! isset($_GET['group_ID'])) { wp_redirect($this->getBackLink()); exit(); } @@ -544,7 +605,7 @@ class AVH_EC_Admin $group_id = (int) $_GET['group_ID']; check_admin_referer('delete-avhecgroup_' . $group_id); - if (! current_user_can('manage_categories')) { + if ( ! current_user_can('manage_categories')) { wp_die(__('Cheatin’ uh?')); } $this->catgrp->doDeleteGroup($group_id); @@ -558,15 +619,22 @@ class AVH_EC_Admin if (isset($_POST['editgroup'])) { check_admin_referer('avh_ec_editgroup'); - $formoptions = $_POST['avhec_edit_group']; + $formoptions = $_POST['avhec_edit_group']; $selected_categories = $_POST['post_category']; $group_id = (int) $_POST['avhec-group_id']; - $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']); + $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']); switch ($result) { case 1: $this->message = __('Category group updated', 'avh-ec'); - $this->status = 'updated fade'; + $this->status = 'updated fade'; break; case 0: $this->message = __('Category group not updated', 'avh-ec'); @@ -575,7 +643,7 @@ class AVH_EC_Admin break; case - 1: $this->message = __('Unknown category group', 'avh-ec'); - $this->status = 'error'; + $this->status = 'error'; break; } $this->displayMessage(); @@ -597,36 +665,76 @@ class AVH_EC_Admin check_admin_referer('avh_ec_specialpagesgroup'); $formoptions = $_POST['avhec_special_pages']; - $formdata = $formoptions['sp']; + $formdata = $formoptions['sp']; foreach ($formdata as $key => $value) { - $data_special_pages_new[$key] = $value; + $data_special_pages_new[ $key ] = $value; } $this->core->options['sp_cat_group'] = $data_special_pages_new; $this->core->saveOptions($this->core->options); - } $data_special_pages['sp'] = $data_special_pages_new; - $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty'=>FALSE)); + $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false)); foreach ($cat_groups as $group) { - $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit'); + $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit'); $dropdown_value[] = $group->term_id; - $dropdown_text[] = $temp_cat->name; + $dropdown_text[] = $temp_cat->name; } - $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'))); + $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')) + ); //$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'))); - $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'))); - $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'))); - $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'))); - $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'))); - $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'))); - - $data['sp'] = array('form'=>$options_special_pages, 'data'=>$data_special_pages); + $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')) + ); + $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')) + ); + $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')) + ); + $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')) + ); + $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')) + ); + + $data['sp'] = array('form' => $options_special_pages, 'data' => $data_special_pages); // This box can't be unselectd in the the Screen Options //add_meta_box( 'avhecBoxDonations', __( 'Donations', 'avh-ec' ), array (&$this, 'metaboxDonations' ), $this->hooks['menu_category_groups'], 'side', 'core' ); - echo '<div class="wrap avhec-metabox-wrap">'; echo $this->displayIcon('index'); echo '<h2>' . 'AVH Extended Categories - ' . __('Category Groups', 'avh-ec') . '</h2>'; @@ -647,128 +755,33 @@ class AVH_EC_Admin echo ' </div>'; //dashboard-widgets-wrap echo '</div>'; // wrap - $this->printMetaboxGeneralNonces(); $this->printMetaboxJS('grouped'); $this->printAdminFooter(); } /** - * Metabox for Adding a group - * @param $data - */ - function metaboxCategoryGroupAdd ($data) - { - echo '<form name="avhec-addgroup" id="avhec-addgroup" method="POST" action="' . $this->getBackLink() . '" accept-charset="utf-8" >'; - wp_nonce_field('avh_ec_addgroup'); - echo $this->printOptions($data['add']['form'], $data['add']['data']); - echo '<p class="submit"><input class="button" type="submit" name="addgroup" value="' . __('Add group', 'avh-ec') . '" /></p>'; - echo '</form>'; - } - - /** - * Metabox for showing the groups as a list - * - * @param $data - */ - function metaboxCategoryGroupList ($data) - { - echo '<form id="posts-filter" action="" method="get">'; - - echo '<div class="clear"></div>'; - - echo '<table class="widefat fixed" cellspacing="0">'; - echo '<thead>'; - echo '<tr>'; - print_column_headers('categories_group'); - echo '</tr>'; - echo '</thead>'; - - echo '<tfoot>'; - echo '<tr>'; - print_column_headers('categories_group', false); - echo '</tr>'; - echo '</tfoot>'; - - echo '<tbody id="the-list" class="list:group">'; - $this->printCategoryGroupRows(); - echo '</tbody>'; - echo '</table>'; - - echo '<br class="clear" />'; - echo '</form>'; - - //echo '</div>'; - } - - /** - * Metabox Category Group Edit - * - */ - function metaboxCategoryGroupEdit ($data) - { - echo '<form name="avhec-editgroup" id="avhec-editgroup" method="POST" action="' . $this->getBackLink() . '" accept-charset="utf-8" >'; - wp_nonce_field('avh_ec_editgroup'); - echo $this->printOptions($data['edit']['form'], $data['edit']['data']); - echo '<input type="hidden" value="' . $data['edit']['data']['edit']['group_id'] . '" name="avhec-group_id" id="avhec-group_id">'; - echo '<p class="submit"><input class="button" type="submit" name="editgroup" value="' . __('Update group', 'avh-ec') . '" /></p>'; - echo '</form>'; - } - - /** - * Metabox Category Group Special pages - * - */ - function metaboxCategoryGroupSpecialPages ($data) - { - echo '<form name="avhec-specialpagesgroup" id="avhec-specialpagesgroup" method="POST" action="' . $this->getBackLink() . '" accept-charset="utf-8" >'; - wp_nonce_field('avh_ec_specialpagesgroup'); - echo $this->printOptions($data['sp']['form'], $data['sp']['data']); - echo '<p class="submit"><input class="button" type="submit" name="spgroup" value="' . __('Save settings', 'avh-ec') . '" /></p>'; - echo '</form>'; - } - - - /** - * Setup everything needed for the Manul Order page - * - */ - function actionLoadPageHook_ManualOrder () - { - - add_meta_box('avhecBoxManualOrder', __('Manually Order Categories', 'avh-ec'), array(&$this, 'metaboxManualOrder'), $this->hooks['menu_manual_order'], 'normal', 'core'); - - - if (AVH_Common::getWordpressVersion() >= 3.1 ) { - add_screen_option('layout_columns', array('max' => 1, 'default' => 1) ); - } else { - add_filter('screen_layout_columns', array ( &$this, 'filterScreenLayoutColumns' ), 10, 2); - } - - // WordPress core Styles and Scripts - wp_enqueue_script('common'); - wp_enqueue_script('wp-lists'); - wp_enqueue_script('postbox'); - wp_enqueue_script('jquery-ui-sortable'); - wp_enqueue_script('avhec-manualorder'); - - // WordPress core Styles - wp_admin_css('css/dashboard'); - - // Plugin Style - wp_enqueue_style('avhec-admin-css'); - - } - - /** - * Menu Page Manual Order + * Menu Page FAQ * * @return none */ - function doMenuManualOrder () - { + function doMenuFAQ() { global $screen_layout_columns; + // This box can't be unselectd in the the Screen Options + add_meta_box('avhecBoxAnnouncements', + __('Announcements', 'avh-ec'), + array(&$this, 'metaboxAnnouncements'), + $this->hooks['menu_faq'], + 'side', + 'core'); + add_meta_box('avhecBoxDonations', + __('Donations', 'avh-ec'), + array(&$this, 'metaboxDonations'), + $this->hooks['menu_faq'], + 'side', + 'core'); + $hide2 = ''; switch ($screen_layout_columns) { case 2: @@ -779,165 +792,241 @@ class AVH_EC_Admin $hide2 = 'display:none;'; } - echo '<div class="wrap">'; + echo '<div class="wrap avhec-metabox-wrap">'; echo $this->displayIcon('index'); - echo '<h2>' . 'AVH Extended Categories - ' . __('Manually Order Categories', 'avh-ec') . '</h2>'; - - echo '<div class="metabox-holder">'; + echo '<h2>' . 'AVH Extended Categories - ' . __('F.A.Q', 'avh-ec') . '</h2>'; + echo ' <div id="dashboard-widgets-wrap">'; + echo ' <div id="dashboard-widgets" class="metabox-holder">'; echo ' <div class="postbox-container" style="' . $width . '">' . "\n"; - do_meta_boxes($this->hooks['menu_manual_order'], 'normal', ''); + do_meta_boxes($this->hooks['menu_faq'], 'normal', ''); echo ' </div>'; - echo '</div>'; + echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n"; + do_meta_boxes($this->hooks['menu_faq'], 'side', ''); + echo ' </div>'; + echo ' </div>'; + echo '<br class="clear"/>'; + echo ' </div>'; //dashboard-widgets-wrap echo '</div>'; // wrap - echo '<div class="clear"></div>'; $this->printMetaboxGeneralNonces(); - $this->printMetaboxJS('manual_order'); + $this->printMetaboxJS('faq'); $this->printAdminFooter(); } /** + * Menu Page General Options * - * @return unknown_type + * @return none */ - function metaboxManualOrder () - { - global $wpdb; - - $parentID = 0; + function doMenuGeneral() { + global $screen_layout_columns; - if (isset($_POST['btnSubCats'])) { - $parentID = $_POST['cats']; - } elseif (isset($_POST['hdnParentID'])) { - $parentID = $_POST['hdnParentID']; + $groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false)); + foreach ($groups as $group) { + $group_id[] = $group->term_id; + $groupname[] = $group->name; } - if (isset($_POST['btnReturnParent'])) { - $parentsParent = $wpdb->get_row( - $wpdb->prepare('SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = %d', $_POST['hdnParentID']), - ARRAY_N - ) - ; - $parentID = $parentsParent[0]; - } + $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') + ); + $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') + ); + $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') + ); + $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') + ); - $success = ""; - if (isset($_POST['btnOrderCats'])) { - if (isset($_POST['hdnManualOrder']) && $_POST['hdnManualOrder'] != "") { + if (isset($_POST['updateoptions'])) { + check_admin_referer('avh_ec_generaloptions'); - $hdnManualOrder = $_POST['hdnManualOrder']; - $IDs = explode(",", $hdnManualOrder); - $result = count($IDs); + $formoptions = $_POST['avhec']; + $options = $this->core->getOptions(); - for ($i = 0; $i < $result; $i ++) { - $str = str_replace("id_", "", $IDs[$i]); - $wpdb->query($wpdb->prepare("UPDATE $wpdb->terms SET avhec_term_order = '$i' WHERE term_id ='$str'")); - } + //$all_data = array_merge( $options_general ); + $all_data = $options_general; + foreach ($all_data as $option) { + $section = substr($option[0], strpos($option[0], '[') + 1); + $section = substr($section, 0, strpos($section, '][')); + $option_key = rtrim($option[0], ']'); + $option_key = substr($option_key, strpos($option_key, '][') + 2); - $success = '<div id="message" class="updated fade"><p>' . __('Categories updated successfully.', 'avh-ec') . '</p></div>'; - } else { - $success = '<div id="message" class="updated fade"><p>' . __('An error occured, order has not been saved.', 'avh-ec') . '</p></div>'; + switch ($section) { + case 'general': + case 'cat_group': + $current_value = $options[ $section ][ $option_key ]; + break; + } + // Every field in a form is set except unchecked checkboxes. Set an unchecked checkbox to 0. + $newval = (isset($formoptions[ $section ][ $option_key ]) ? attribute_escape($formoptions[ $section ][ $option_key ]) : 0); + if ($newval != $current_value) { // Only process changed fields. + switch ($section) { + case 'general': + case 'cat_group': + $options[ $section ][ $option_key ] = $newval; + break; + } + } } - + $this->core->saveOptions($options); + $this->message = __('Options saved', 'avh-ec'); + $this->status = 'updated fade'; } + $this->displayMessage(); - $_SubCategories = ""; - $results = $wpdb->get_results($wpdb->prepare("SELECT t.term_id, t.name FROM $wpdb->term_taxonomy tt, $wpdb->terms t, $wpdb->term_taxonomy tt2 WHERE tt.parent = $parentID AND tt.taxonomy = 'category' AND t.term_id = tt.term_id AND tt2.parent = tt.term_id GROUP BY t.term_id, t.name HAVING COUNT(*) > 0 ORDER BY t.avhec_term_order ASC")); - foreach ($results as $row) { - $_SubCategories .= "<option value='$row->term_id'>$row->name</option>"; + $actual_options = $this->core->getOptions(); + foreach ($actual_options['cat_group'] as $key => $value) { + if ( ! (in_array($value, (array) $group_id))) { + $actual_options['cat_group'][ $key ] = $this->catgrp->getTermIDBy('slug', 'none'); + } } - echo '<div class="wrap">'; - echo '<form name="frmMyCatOrder" method="post" action="">'; - echo $success; - - - - echo '<h4>'; - _e('Order the categories', 'avh-ec'); - if ($parentID == 0) { - echo ' at the Toplevel'; - } else { - $_cats = get_category_parents($parentID, false, ' » '); - echo ' in the category ' . trim($_cats, ' » '); + $hide2 = ''; + switch ($screen_layout_columns) { + case 2: + $width = 'width:49%;'; + break; + default: + $width = 'width:98%;'; + $hide2 = 'display:none;'; } - echo '</h4>'; - echo '<span class="description">'; - _e('Order the categories on this level by dragging and dropping them into the desired order.', 'avh-ec'); - echo '</span>'; - echo '<ul id="avhecManualOrder">'; - $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->terms t inner join $wpdb->term_taxonomy tt on t.term_id = tt.term_id WHERE taxonomy = 'category' and parent = $parentID ORDER BY avhec_term_order ASC")); - foreach ($results as $row) - echo "<li id='id_$row->term_id' class='lineitem menu-item-settings'>" . __($row->name) . "</li>"; + $data['options_general'] = $options_general; + $data['actual_options'] = $actual_options; - echo '</ul>'; - echo '<input type="submit" name="btnOrderCats" id="btnOrderCats" class="button-primary" value="' . __('Save Order', 'avh-ec') . '" onclick="javascript:orderCats(); return true;" />'; + // This box can't be unselectd in the the Screen Options + add_meta_box('avhecBoxDonations', + __('Donations', 'avh-ec'), + array(&$this, 'metaboxDonations'), + $this->hooks['menu_general'], + 'side', + 'core'); - if ($parentID != 0) { - echo "<input type='submit' class='button' id='btnReturnParent' name='btnReturnParent' value='" . __('Return to parent category', 'avh-ec') . "' />"; + $hide2 = ''; + switch ($screen_layout_columns) { + case 2: + $width = 'width:49%;'; + break; + default: + $width = 'width:98%;'; + $hide2 = 'display:none;'; } - echo '<strong id="updateText"></strong><br /><br />'; - if ($_SubCategories != "") { + echo '<div class="wrap avhec-metabox-wrap">'; + echo $this->displayIcon('index'); + echo '<h2>' . 'AVH Extended Categories - ' . __('General Options', 'avh-ec') . '</h2>'; + echo '<form name="avhec-generaloptions" id="avhec-generaloptions" method="POST" action="' . + admin_url('admin.php?page=avhec-general') . + '" accept-charset="utf-8" >'; + wp_nonce_field('avh_ec_generaloptions'); - echo '<h4>'; - _e('Select Subcategory', 'avh-ec'); - echo '</h4>'; - echo '<select id="cats" name="cats">'; - echo $_SubCategories; + echo ' <div id="dashboard-widgets-wrap">'; + echo ' <div id="dashboard-widgets" class="metabox-holder">'; + echo ' <div class="postbox-container" style="' . $width . '">' . "\n"; + do_meta_boxes($this->hooks['menu_general'], 'normal', $data); + echo " </div>"; + echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n"; + do_meta_boxes($this->hooks['menu_general'], 'side', $data); + echo ' </div>'; + echo ' </div>'; - echo '</select><input type="submit" name="btnSubCats" class="button" id="btnSubCats" value="' . __('Select', 'avh-ec') . '" />'; - echo '<span class="description">'; - _e('Choose a category from the drop down to order the subcategories in that category.', 'avh-ec'); - echo '</span>'; - } + echo '<br class="clear"/>'; + echo ' </div>'; //dashboard-widgets-wrap + echo '<p class="submit"><input class="button" type="submit" name="updateoptions" value="' . + __('Save Changes', 'avhf-ec') . + '" /></p>'; + echo '</form>'; - echo '<input type="hidden" id="hdnManualOrder" name="hdnManualOrder" />'; - echo '<input type="hidden" id="hdnParentID" name="hdnParentID" value="' . $parentID . '" /></form>'; - echo '</div>'; + echo '</div>'; // wrap + + $this->printMetaboxGeneralNonces(); + $this->printMetaboxJS('general'); + $this->printAdminFooter(); } /** - * Setup everything needed for the FAQ page + * Menu Page Manual Order * + * @return none */ - function actionLoadPageHook_faq () - { - - add_meta_box('avhecBoxFAQ', __('F.A.Q.', 'avh-ec'), array(&$this, 'metaboxFAQ'), $this->hooks['menu_faq'], 'normal', 'core'); - add_meta_box('avhecBoxTranslation', __('Translation', 'avh-ec'), array(&$this, 'metaboxTranslation'), $this->hooks['menu_faq'], 'normal', 'core'); + function doMenuManualOrder() { + global $screen_layout_columns; - if (AVH_Common::getWordpressVersion() >= 3.1 ) { - add_screen_option('layout_columns', array('max' => 2, 'default' => 2) ); - } else { - add_filter('screen_layout_columns', array ( &$this, 'filterScreenLayoutColumns' ), 10, 2); + $hide2 = ''; + switch ($screen_layout_columns) { + case 2: + $width = 'width:49%;'; + break; + default: + $width = 'width:98%;'; + $hide2 = 'display:none;'; } - // WordPress core Styles and Scripts - wp_enqueue_script('common'); - wp_enqueue_script('wp-lists'); - wp_enqueue_script('postbox'); - - // WordPress core Styles - wp_admin_css('css/dashboard'); + echo '<div class="wrap">'; + echo $this->displayIcon('index'); + echo '<h2>' . 'AVH Extended Categories - ' . __('Manually Order Categories', 'avh-ec') . '</h2>'; - // Plugin Style - wp_enqueue_style('avhec-admin-css'); + echo '<div class="metabox-holder">'; + echo ' <div class="postbox-container" style="' . $width . '">' . "\n"; + do_meta_boxes($this->hooks['menu_manual_order'], 'normal', ''); + echo ' </div>'; + echo '</div>'; + echo '</div>'; // wrap + echo '<div class="clear"></div>'; + $this->printMetaboxGeneralNonces(); + $this->printMetaboxJS('manual_order'); + $this->printAdminFooter(); } /** - * Menu Page FAQ + * Menu Page Overview * * @return none */ - function doMenuFAQ () - { + function doMenuOverview() { global $screen_layout_columns; // This box can't be unselectd in the the Screen Options - add_meta_box('avhecBoxAnnouncements', __('Announcements', 'avh-ec'), array(&$this, 'metaboxAnnouncements'), $this->hooks['menu_faq'], 'side', 'core'); - add_meta_box('avhecBoxDonations', __('Donations', 'avh-ec'), array(&$this, 'metaboxDonations'), $this->hooks['menu_faq'], 'side', 'core'); + add_meta_box('avhecBoxAnnouncements', + __('Announcements', 'avh-ec'), + array(&$this, 'metaboxAnnouncements'), + $this->hooks['menu_overview'], + 'side', + ''); + add_meta_box('avhecBoxDonations', + __('Donations', 'avh-ec'), + array(&$this, 'metaboxDonations'), + $this->hooks['menu_overview'], + 'side', + ''); $hide2 = ''; switch ($screen_layout_columns) { @@ -951,121 +1040,329 @@ class AVH_EC_Admin echo '<div class="wrap avhec-metabox-wrap">'; echo $this->displayIcon('index'); - echo '<h2>' . 'AVH Extended Categories - ' . __('F.A.Q', 'avh-ec') . '</h2>'; + echo '<h2>' . 'AVH Extended Categories - ' . __('Overview', 'avh-ec') . '</h2>'; echo ' <div id="dashboard-widgets-wrap">'; echo ' <div id="dashboard-widgets" class="metabox-holder">'; echo ' <div class="postbox-container" style="' . $width . '">' . "\n"; - do_meta_boxes($this->hooks['menu_faq'], 'normal', ''); - echo ' </div>'; + do_meta_boxes($this->hooks['menu_overview'], 'normal', ''); + echo " </div>"; echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n"; - do_meta_boxes($this->hooks['menu_faq'], 'side', ''); + do_meta_boxes($this->hooks['menu_overview'], 'side', ''); echo ' </div>'; echo ' </div>'; + echo '<br class="clear"/>'; echo ' </div>'; //dashboard-widgets-wrap echo '</div>'; // wrap - $this->printMetaboxGeneralNonces(); - $this->printMetaboxJS('faq'); + $this->printMetaboxJS('overview'); $this->printAdminFooter(); } /** - * Translation Metabox - * @return unknown_type + * When not using AJAX, this function is called when the deletion fails. + * + * @param string $text + * @param int $group_id + * + * @return string + * @WordPress Filter explain_nonce_$verb-$noun + * @see wp_explain_nonce */ - function metaboxTranslation () - { - $locale = apply_filters( 'plugin_locale', get_locale(), 'avh-ec' ); - $available_locale['cs_CZ'] = array('Czech - Čeština',0); - $available_locale['nl_NL'] = array('Dutch - Nederlands',0); - $available_locale['de_DE'] = array('German - Deutsch', 0); - $available_locale['el'] = array('Greek - Čeština',0); - $available_locale['id_ID'] = array('Indonesian - Bahasa Indonesia - Čeština',0); - $available_locale['it_IT'] = array('Italian - Italiano',1); - $available_locale['ru_RU'] = array('Russian — Русский',0); - $available_locale['es_ES'] = array('Spanish - Español',0); - $available_locale['sv_SE'] = array('Swedish - Svenska',0); - $available_locale['tr'] = array('Turkish - Türkçe',0); + function filterExplainNonceDeleteGroup($text, $group_id) { + $group = get_term($group_id, $this->catgrp->taxonomy_name, OBJECT, 'display'); - echo '<div class="p">'; - 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 />'; + $return = sprintf(__('Your attempt to delete this group: “%s” has failed.'), $group->name); - echo '</div>'; + return ($return); + } - echo '<div class="p">'; - echo '<span class="b">' . __('Available Languages', 'avh-ec') . '</span>'; - echo '<ul>'; - foreach ($available_locale as $key => $value) { - echo '<li>'; - $complete = ($value[1] == 1 ? 'Complete' : 'Incomplete'); - echo $value[0] . ' (' . $key . ') - ' . $complete; - echo '</li>'; + /** + * Creates a new array for columns headers. Used in print_column_headers. The filter is called from + * get_column_headers + * + * @param $columns + * + * @return Array + * @see print_column_headers, get_column_headers + */ + function filterManageCategoriesGroupColumns($columns) { + $categories_group_columns = array( + 'name' => __('Name', 'avh-ec'), + 'slug' => 'Slug', + 'widget-title' => __('Widget Title', 'avh-ec'), + 'description' => __('Description', 'avh-ec'), + 'cat-in-group' => __('Categories in the group', 'avh-ec') + ); + + return $categories_group_columns; + } + + /** + * Adds Settings next to the plugin actions + * + * @WordPress Filter plugin_action_links_avh-amazon/avh-amazon.php + */ + function filterPluginActions($links, $file) { + $settings_link = '<a href="admin.php?page=extended-categories-widget">' . __('Settings', 'avh-ec') . '</a>'; + array_unshift($links, $settings_link); // before other links + return $links; + } + + /** + * Sets the amount of columns wanted for a particuler screen + * + * @WordPress filter screen_meta_screen + * + * @param $screen + * + * @return strings + */ + + function filterScreenLayoutColumns($columns, $screen) { + switch ($screen) { + case $this->hooks['menu_overview']: + $columns[ $this->hooks['menu_overview'] ] = 2; + break; + case $this->hooks['menu_general']: + $columns[ $this->hooks['menu_general'] ] = 2; + break; + case $this->hooks['menu_category_groups']: + $columns[ $this->hooks['menu_category_groups'] ] = 2; + break; + case $this->hooks['menu_faq']: + $columns[ $this->hooks['menu_faq'] ] = 2; + break; } - echo '</ul>'; - echo '</div>'; + return $columns; + } + + /** + * Get the backlink for forms + * + * @return string + */ + function getBackLink() { + $page = basename(__FILE__); + if (isset($_GET['page']) && ! empty($_GET['page'])) { + $page = preg_replace('[^a-zA-Z0-9\.\_\-]', '', $_GET['page']); + } + + if (function_exists("admin_url")) { + return admin_url(basename($_SERVER["PHP_SELF"])) . "?page=" . $page; + } else { + return $_SERVER['PHP_SELF'] . "?page=" . $page; + } + } + + /** + * Saves the association Category - Category Group fron the edit taxonomy page + * + * @WordPress action edit_form. + * + * @param unknown_type $term_id + * @param unknown_type $tt_id + * @param unknown_type $taxonomy + */ + function handleEditTerm($term_id, $tt_id, $taxonomy) { + $tax_meta = get_option($this->core->db_options_tax_meta); + if (isset($_POST['avhec_categorygroup']) && + $tax_meta[ $taxonomy ][ $term_id ]['category_group_term_id'] != $_POST['avhec_categorygroup'] + ) { + $tax_meta[ $taxonomy ][ $term_id ]['category_group_term_id'] = $_POST['avhec_categorygroup']; + update_option($this->core->db_options_tax_meta, $tax_meta); + } + } + + /** + * Used in forms to set an option checked + * + * @param mixed $checked + * @param mixed $current + * + * @return string + */ + function isChecked($checked, $current) { + $return = ''; + if ($checked == $current) { + $return = ' checked="checked"'; + } + + return $return; + } + + function metaboxAnnouncements() { + $php5 = version_compare('5.2', phpversion(), '<'); echo '<div class="p">'; - if ('en_US' != $locale & (!array_key_exists($locale, $available_locale))){ - echo 'Currently the plugin is not available in your language ('.$locale.'). Why not help out and translate the plugin in your language. You can help by visiting <a href="https://translations.launchpad.net/avhextendedcategories/trunk" target="_blank">Launchpad</a>.'; + echo '<span class="b">' . __('PHP4 Support', 'avh-ec') . '</span><br />'; + echo __('The next major release of the plugin will no longer support PHP4.', 'avh-ec') . '<br />'; + echo __('It will be written for PHP 5.2 and ', 'avh-ec'); + if ($php5) { + echo __('your blog already runs the needed PHP version. When the new release comes out you can safely update.', + 'avh-ec') . '<br />'; } else { - echo __('You can visit ', 'avh-ec') . '<a href="https://translations.launchpad.net/avhextendedcategories/trunk" target="_blank">Launchpad</a> ' . __('to help complete these translations or add a new language.', 'avh-ec'); + echo __('your blog still runs PHP4. When the new release comes out you can not use it.', 'avh-ec') . + '<br />'; + 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 />'; + echo __('If your hosts doesn\'t offer PHP 5.2 you might want to consider switching hosts.', 'avh-ec') . + '<br />'; + echo __('A host to consider is ', 'avh-ec') . + '<a href="http://www.lunarpages.com/id/pdoes" target="_blank">Lunarpages</a>'; + 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'); } echo '</div>'; + } + + /** + * Metabox for Adding a group + * + * @param $data + */ + function metaboxCategoryGroupAdd($data) { + echo '<form name="avhec-addgroup" id="avhec-addgroup" method="POST" action="' . + $this->getBackLink() . + '" accept-charset="utf-8" >'; + wp_nonce_field('avh_ec_addgroup'); + echo $this->printOptions($data['add']['form'], $data['add']['data']); + echo '<p class="submit"><input class="button" type="submit" name="addgroup" value="' . + __('Add group', 'avh-ec') . + '" /></p>'; + echo '</form>'; + } + + /** + * Metabox Category Group Edit + */ + function metaboxCategoryGroupEdit($data) { + echo '<form name="avhec-editgroup" id="avhec-editgroup" method="POST" action="' . + $this->getBackLink() . + '" accept-charset="utf-8" >'; + wp_nonce_field('avh_ec_editgroup'); + echo $this->printOptions($data['edit']['form'], $data['edit']['data']); + echo '<input type="hidden" value="' . + $data['edit']['data']['edit']['group_id'] . + '" name="avhec-group_id" id="avhec-group_id">'; + echo '<p class="submit"><input class="button" type="submit" name="editgroup" value="' . + __('Update group', 'avh-ec') . + '" /></p>'; + echo '</form>'; + } + + /** + * Metabox for showing the groups as a list + * + * @param $data + */ + function metaboxCategoryGroupList($data) { + echo '<form id="posts-filter" action="" method="get">'; + + echo '<div class="clear"></div>'; + + echo '<table class="widefat fixed" cellspacing="0">'; + echo '<thead>'; + echo '<tr>'; + print_column_headers('categories_group'); + echo '</tr>'; + echo '</thead>'; + + echo '<tfoot>'; + echo '<tr>'; + print_column_headers('categories_group', false); + echo '</tr>'; + echo '</tfoot>'; + + echo '<tbody id="the-list" class="list:group">'; + $this->printCategoryGroupRows(); + echo '</tbody>'; + echo '</table>'; + echo '<br class="clear" />'; + echo '</form>'; + //echo '</div>'; + } + + /** + * Metabox Category Group Special pages + */ + function metaboxCategoryGroupSpecialPages($data) { + echo '<form name="avhec-specialpagesgroup" id="avhec-specialpagesgroup" method="POST" action="' . + $this->getBackLink() . + '" accept-charset="utf-8" >'; + wp_nonce_field('avh_ec_specialpagesgroup'); + echo $this->printOptions($data['sp']['form'], $data['sp']['data']); + echo '<p class="submit"><input class="button" type="submit" name="spgroup" value="' . + __('Save settings', 'avh-ec') . + '" /></p>'; + echo '</form>'; } + ############## Admin WP Helper ############## + /** * Donation Metabox + * * @return unknown_type */ - function metaboxDonations () - { + function metaboxDonations() { echo '<div class="p">'; - echo __('If you enjoy this plug-in please consider a donation. There are several ways you can show your appreciation.', 'avh-ec'); + echo __('If you enjoy this plug-in please consider a donation. There are several ways you can show your appreciation.', + 'avh-ec'); echo '</div>'; echo '<div class="p">'; echo '<span class="b">Amazon</span><br />'; echo __('If you decide to buy something from Amazon click the button.', 'avh-ec') . '</span><br />'; - 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>'; + echo '<a href="https://www.amazon.com/?tag=petervanderdoes-20" target="_blank" title="Amazon Homepage"><img alt="Amazon Button" src="' . + $this->core->info['graphics_url'] . + '/us_banner_logow_120x60.gif" /></a>'; echo '</div>'; echo '<div class="p">'; - 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>'; + echo __('You can send me something from my ', 'avh-ec') . + '<a href="http://www.amazon.com/registry/wishlist/1U3DTWZ72PI7W?tag=petervanderdoes-20">' . + __('Amazon Wish List', 'avh-ec') . + '</a>'; echo '</div>'; echo '<div class="p">'; echo '<span class="b">' . __('Through Paypal.', 'avh-ec') . '</span><br />'; - 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 />'; + 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 />'; 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">'; echo '<img src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" alt="Donate"/></a>'; echo '</div>'; - } /*** * F.A.Q Metabox + * * @return none */ - function metaboxFAQ () - { + function metaboxFAQ() { echo '<div class="p">'; echo '<span class="b">' . __('What about support?', 'avh-ec') . '</span><br />'; - echo __('I created a support site at http://forums.avirtualhome.com where you can ask questions or request features.', 'avh-ec') . '<br />'; + echo __('I created a support site at http://forums.avirtualhome.com where you can ask questions or request features.', + 'avh-ec') . '<br />'; echo '</div>'; echo '<div class="p">'; echo '<span class="b">' . __('What is depth selection?', 'avh-ec') . '</span><br />'; - 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 />'; - 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 />'; - 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 />'; + 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 />'; + 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 />'; + 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 />'; echo '</div>'; echo '<div class="p">'; echo '<span class="b">' . __('Multiple Category Groups', 'avh-ec') . '</span><br />'; - echo __('The following is an explanation how assigning multiple groups to page/post works.', 'avh-ec') . '<br /><br />'; + echo __('The following is an explanation how assigning multiple groups to page/post works.', 'avh-ec') . + '<br /><br />'; echo __('Lets say you have the following groups:', 'avh-ec'); echo '<ul>'; echo '<li>' . __('Free Time', 'avh-ec') . '</li>'; @@ -1073,7 +1370,8 @@ class AVH_EC_Admin echo '<li>' . __('Movie', 'avh-ec') . '</li>'; echo '<li>' . __('Music', 'avh-ec') . '</li>'; echo '</ul>'; - echo __('Setup several Category Group widgets and associated each widget with one or more groups.', 'avh-ec') . '<br />'; + echo __('Setup several Category Group widgets and associated each widget with one or more groups.', 'avh-ec') . + '<br />'; echo __('Widget 1 has association with Free Time', 'avh-ec') . '<br />'; echo __('Widget 2 has association with Theater, Movie and Music', 'avh-ec') . '<br />'; echo __('Widget 3 has association with Theater, Movie and Music', 'avh-ec') . '<br /><br />'; @@ -1095,138 +1393,181 @@ class AVH_EC_Admin echo '<li>' . __('Widget 2: Shows categories of the Movie or Music group.', 'avh-ec') . '</li>'; echo '<li>' . __('Widget 3: Shows categories of the Music or Movie group.', 'avh-ec') . '</li>'; echo '</ul>'; - 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 />'; + 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 />'; echo '</div>'; } - function metaboxAnnouncements () - { - $php5 = version_compare('5.2', phpversion(), '<'); - echo '<div class="p">'; - echo '<span class="b">' . __('PHP4 Support', 'avh-ec') . '</span><br />'; - echo __('The next major release of the plugin will no longer support PHP4.', 'avh-ec') . '<br />'; - echo __('It will be written for PHP 5.2 and ', 'avh-ec'); - if ($php5) { - echo __('your blog already runs the needed PHP version. When the new release comes out you can safely update.', 'avh-ec') . '<br />'; - } else { - echo __('your blog still runs PHP4. When the new release comes out you can not use it.', 'avh-ec') . '<br />'; - 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 />'; - echo __('If your hosts doesn\'t offer PHP 5.2 you might want to consider switching hosts.', 'avh-ec') . '<br />'; - echo __('A host to consider is ', 'avh-ec') . '<a href="http://www.lunarpages.com/id/pdoes" target="_blank">Lunarpages</a>'; - 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'); + /** + * @return unknown_type + */ + function metaboxManualOrder() { + global $wpdb; + + $parentID = 0; + + if (isset($_POST['btnSubCats'])) { + $parentID = $_POST['cats']; + } elseif (isset($_POST['hdnParentID'])) { + $parentID = $_POST['hdnParentID']; } - echo '</div>'; - } + if (isset($_POST['btnReturnParent'])) { + $parentsParent = $wpdb->get_row($wpdb->prepare('SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = %d', + $_POST['hdnParentID']), + ARRAY_N); + $parentID = $parentsParent[0]; + } - /** - * Sets the amount of columns wanted for a particuler screen - * - * @WordPress filter screen_meta_screen - * @param $screen - * @return strings - */ + $success = ""; + if (isset($_POST['btnOrderCats'])) { + if (isset($_POST['hdnManualOrder']) && $_POST['hdnManualOrder'] != "") { - function filterScreenLayoutColumns ($columns, $screen) - { - switch ($screen) { - case $this->hooks['menu_overview']: - $columns[$this->hooks['menu_overview']] = 2; - break; - case $this->hooks['menu_general']: - $columns[$this->hooks['menu_general']] = 2; - break; - case $this->hooks['menu_category_groups']: - $columns[$this->hooks['menu_category_groups']] = 2; - break; - case $this->hooks['menu_faq']: - $columns[$this->hooks['menu_faq']] = 2; - break; + $hdnManualOrder = $_POST['hdnManualOrder']; + $IDs = explode(",", $hdnManualOrder); + $result = count($IDs); + for ($i = 0; $i < $result; $i ++) { + $str = str_replace("id_", "", $IDs[ $i ]); + $wpdb->query($wpdb->prepare("UPDATE $wpdb->terms SET avhec_term_order = '$i' WHERE term_id ='$str'")); + } + + $success = '<div id="message" class="updated fade"><p>' . + __('Categories updated successfully.', 'avh-ec') . + '</p></div>'; + } else { + $success = '<div id="message" class="updated fade"><p>' . + __('An error occured, order has not been saved.', 'avh-ec') . + '</p></div>'; + } } - return $columns; - } - /** - * Adds Settings next to the plugin actions - * - * @WordPress Filter plugin_action_links_avh-amazon/avh-amazon.php - * - */ - function filterPluginActions ($links, $file) - { - $settings_link = '<a href="admin.php?page=extended-categories-widget">' . __('Settings', 'avh-ec') . '</a>'; - array_unshift($links, $settings_link); // before other links - return $links; + $_SubCategories = ""; + $results = $wpdb->get_results($wpdb->prepare("SELECT t.term_id, t.name FROM $wpdb->term_taxonomy tt, $wpdb->terms t, $wpdb->term_taxonomy tt2 WHERE tt.parent = $parentID AND tt.taxonomy = 'category' AND t.term_id = tt.term_id AND tt2.parent = tt.term_id GROUP BY t.term_id, t.name HAVING COUNT(*) > 0 ORDER BY t.avhec_term_order ASC")); + foreach ($results as $row) { + $_SubCategories .= "<option value='$row->term_id'>$row->name</option>"; + } + + echo '<div class="wrap">'; + echo '<form name="frmMyCatOrder" method="post" action="">'; + echo $success; + + echo '<h4>'; + _e('Order the categories', 'avh-ec'); + if ($parentID == 0) { + echo ' at the Toplevel'; + } else { + $_cats = get_category_parents($parentID, false, ' » '); + echo ' in the category ' . trim($_cats, ' » '); + } + echo '</h4>'; + echo '<span class="description">'; + _e('Order the categories on this level by dragging and dropping them into the desired order.', 'avh-ec'); + echo '</span>'; + echo '<ul id="avhecManualOrder">'; + $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->terms t inner join $wpdb->term_taxonomy tt on t.term_id = tt.term_id WHERE taxonomy = 'category' and parent = $parentID ORDER BY avhec_term_order ASC")); + foreach ($results as $row) { + echo "<li id='id_$row->term_id' class='lineitem menu-item-settings'>" . __($row->name) . "</li>"; + } + + echo '</ul>'; + echo '<input type="submit" name="btnOrderCats" id="btnOrderCats" class="button-primary" value="' . + __('Save Order', 'avh-ec') . + '" onclick="javascript:orderCats(); return true;" />'; + + if ($parentID != 0) { + echo "<input type='submit' class='button' id='btnReturnParent' name='btnReturnParent' value='" . + __('Return to parent category', 'avh-ec') . + "' />"; + } + echo '<strong id="updateText"></strong><br /><br />'; + if ($_SubCategories != "") { + + echo '<h4>'; + _e('Select Subcategory', 'avh-ec'); + echo '</h4>'; + echo '<select id="cats" name="cats">'; + echo $_SubCategories; + + echo '</select><input type="submit" name="btnSubCats" class="button" id="btnSubCats" value="' . + __('Select', 'avh-ec') . + '" />'; + echo '<span class="description">'; + _e('Choose a category from the drop down to order the subcategories in that category.', 'avh-ec'); + echo '</span>'; + } + + echo '<input type="hidden" id="hdnManualOrder" name="hdnManualOrder" />'; + echo '<input type="hidden" id="hdnParentID" name="hdnParentID" value="' . $parentID . '" /></form>'; + echo '</div>'; } /** - * Creates a new array for columns headers. Used in print_column_headers. The filter is called from get_column_headers - * - * @param $columns - * @return Array - * @see print_column_headers, get_column_headers + * Options Metabox */ - function filterManageCategoriesGroupColumns ($columns) - { - $categories_group_columns = array('name'=>__('Name', 'avh-ec'), 'slug'=>'Slug', 'widget-title'=>__('Widget Title', 'avh-ec'), 'description'=>__('Description', 'avh-ec'), 'cat-in-group'=>__('Categories in the group', 'avh-ec')); - return $categories_group_columns; + function metaboxOptions($data) { + echo $this->printOptions($data['options_general'], $data['actual_options']); } /** - * When not using AJAX, this function is called when the deletion fails. + * Translation Metabox * - * @param string $text - * @param int $group_id - * @return string - * @WordPress Filter explain_nonce_$verb-$noun - * @see wp_explain_nonce + * @return unknown_type */ - function filterExplainNonceDeleteGroup ($text, $group_id) - { - $group = get_term($group_id, $this->catgrp->taxonomy_name, OBJECT, 'display'); - - $return = sprintf(__('Your attempt to delete this group: “%s” has failed.'), $group->name); - return ($return); - } + function metaboxTranslation() { + $locale = apply_filters('plugin_locale', get_locale(), 'avh-ec'); + $available_locale['cs_CZ'] = array('Czech - Čeština', 0); + $available_locale['nl_NL'] = array('Dutch - Nederlands', 0); + $available_locale['de_DE'] = array('German - Deutsch', 0); + $available_locale['el'] = array('Greek - Čeština', 0); + $available_locale['id_ID'] = array('Indonesian - Bahasa Indonesia - Čeština', 0); + $available_locale['it_IT'] = array('Italian - Italiano', 1); + $available_locale['ru_RU'] = array('Russian — Русский', 0); + $available_locale['es_ES'] = array('Spanish - Español', 0); + $available_locale['sv_SE'] = array('Swedish - Svenska', 0); + $available_locale['tr'] = array('Turkish - Türkçe', 0); - ############## Admin WP Helper ############## + echo '<div class="p">'; + 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 />'; + echo '</div>'; - /** - * Get the backlink for forms - * - * @return strings - */ - function getBackLink () - { - $page = basename(__FILE__); - if (isset($_GET['page']) && ! empty($_GET['page'])) { - $page = preg_replace('[^a-zA-Z0-9\.\_\-]', '', $_GET['page']); + echo '<div class="p">'; + echo '<span class="b">' . __('Available Languages', 'avh-ec') . '</span>'; + echo '<ul>'; + foreach ($available_locale as $key => $value) { + echo '<li>'; + $complete = ($value[1] == 1 ? 'Complete' : 'Incomplete'); + echo $value[0] . ' (' . $key . ') - ' . $complete; + echo '</li>'; } + echo '</ul>'; + echo '</div>'; - if (function_exists("admin_url")) - return admin_url(basename($_SERVER["PHP_SELF"])) . "?page=" . $page; - else - return $_SERVER['PHP_SELF'] . "?page=" . $page; + echo '<div class="p">'; + if ('en_US' != $locale & ( ! array_key_exists($locale, $available_locale))) { + echo 'Currently the plugin is not available in your language (' . + $locale . + '). Why not help out and translate the plugin in your language. You can help by visiting <a href="https://translations.launchpad.net/avhextendedcategories/trunk" target="_blank">Launchpad</a>.'; + } else { + echo __('You can visit ', 'avh-ec') . + '<a href="https://translations.launchpad.net/avhextendedcategories/trunk" target="_blank">Launchpad</a> ' . + __('to help complete these translations or add a new language.', 'avh-ec'); + } + echo '</div>'; } /** - * Print all Category Group rows - * - * @uses printCategoryGroupRow - * + * Display plugin Copyright */ - function printCategoryGroupRows () - { - $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty'=>FALSE)); - - foreach ($cat_groups as $group) { - if ('none' != $group->slug) { - echo $this->printCategoryGroupRow($group->term_id, $group->term_taxonomy_id); - } - } + function printAdminFooter() { + echo '<p class="footer_avhec">'; + 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); + echo '</p>'; } /** @@ -1236,30 +1577,38 @@ class AVH_EC_Admin * @param int $group_term_id * @param int $group_term_taxonomy_id */ - function printCategoryGroupRow ($group_term_id, $group_term_taxonomy_id) - { + function printCategoryGroupRow($group_term_id, $group_term_taxonomy_id) { static $row_class = ''; $group = get_term($group_term_id, $this->catgrp->taxonomy_name, OBJECT, 'display'); - $no_edit[$this->catgrp->getTermIDBy('slug', 'all')] = 0; - $no_delete[$this->catgrp->getTermIDBy('slug', 'all')] = 0; + $no_edit[ $this->catgrp->getTermIDBy('slug', 'all') ] = 0; + $no_delete[ $this->catgrp->getTermIDBy('slug', 'all') ] = 0; if (current_user_can('manage_categories')) { $actions = array(); - if (! array_key_exists($group->term_id, $no_edit)) { + if ( ! array_key_exists($group->term_id, $no_edit)) { $edit_link = "admin.php?page=avhec-grouped&action=edit&group_ID=$group->term_id"; - $edit = "<a class='row-title' href='$edit_link' title='" . esc_attr(sprintf(__('Edit “%s”'), $group->name)) . "'>" . esc_attr($group->name) . '</a><br />'; + $edit = "<a class='row-title' href='$edit_link' title='" . + esc_attr(sprintf(__('Edit “%s”'), $group->name)) . + "'>" . + esc_attr($group->name) . + '</a><br />'; $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>'; } else { $edit = esc_attr($group->name); } - if (! (array_key_exists($group->term_id, $no_delete))) { - $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>"; + if ( ! (array_key_exists($group->term_id, $no_delete))) { + $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>"; } $action_count = count($actions); - $i = 0; + $i = 0; $edit .= '<div class="row-actions">'; foreach ($actions as $action => $link) { ++ $i; @@ -1272,25 +1621,26 @@ class AVH_EC_Admin } $row_class = 'alternate' == $row_class ? '' : 'alternate'; - $qe_data = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit'); + $qe_data = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit'); $output = "<tr id='group-$group->term_id' class='iedit $row_class'>"; $columns = get_column_headers('categories_group'); - $hidden = get_hidden_columns('categories_group'); + $hidden = get_hidden_columns('categories_group'); foreach ($columns as $column_name => $column_display_name) { $class = 'class="' . $column_name . ' column-' . $column_name . '"'; $style = ''; - if (in_array($column_name, $hidden)) + if (in_array($column_name, $hidden)) { $style = ' style="display:none;"'; + } $attributes = $class . $style; switch ($column_name) { case 'cb': $output .= '<th scope="row" class="check-column">'; - if (! (array_key_exists($group->term_id, $no_delete))) { + if ( ! (array_key_exists($group->term_id, $no_delete))) { $output .= '<input type="checkbox" name="delete[]" value="' . $group->term_id . '" />'; } else { $output .= " "; @@ -1316,7 +1666,7 @@ class AVH_EC_Admin $output .= "<td $attributes>" . apply_filters('editable_slug', $qe_data->slug) . "</td>"; break; case 'cat-in-group': - $cats = $this->catgrp->getCategoriesFromGroup($group_term_id); + $cats = $this->catgrp->getCategoriesFromGroup($group_term_id); $catname = array(); foreach ($cats as $cat_id) { $catname[] = get_cat_name($cat_id); @@ -1325,7 +1675,6 @@ class AVH_EC_Admin $cat = implode(', ', $catname); $output .= '<td ' . $attributes . '>' . $cat . '</td>'; break; - } } $output .= '</tr>'; @@ -1333,18 +1682,31 @@ class AVH_EC_Admin return $output; } + /** + * Print all Category Group rows + * + * @uses printCategoryGroupRow + */ + function printCategoryGroupRows() { + $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false)); + + foreach ($cat_groups as $group) { + if ('none' != $group->slug) { + echo $this->printCategoryGroupRow($group->term_id, $group->term_taxonomy_id); + } + } + } + /** * Prints the general nonces, used by the AJAX */ - function printMetaboxGeneralNonces () - { + function printMetaboxGeneralNonces() { echo '<form style="display:none" method="get" action="">'; echo '<p>'; wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); echo '</p>'; echo '</form>'; - } /** @@ -1352,9 +1714,8 @@ class AVH_EC_Admin * * @param $boxid */ - function printMetaboxJS ($boxid) - { - $a = $this->hooks['menu_' . $boxid]; + function printMetaboxJS($boxid) { + $a = $this->hooks[ 'menu_' . $boxid ]; echo '<script type="text/javascript">' . "\n"; echo ' //<![CDATA[' . "\n"; echo ' jQuery(document).ready( function($) {' . "\n"; @@ -1364,87 +1725,108 @@ class AVH_EC_Admin echo ' });' . "\n"; echo ' //]]>' . "\n"; echo '</script>'; - - } - - /** - * Display plugin Copyright - * - */ - function printAdminFooter () - { - echo '<p class="footer_avhec">'; - 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); - echo '</p>'; - } - - /** - * Display WP alert - * - */ - function displayMessage () - { - if ($this->message != '') { - $message = $this->message; - $status = $this->status; - $this->message = $this->status = ''; // Reset - } - if (isset($message)) { - $status = ($status != '') ? $status : 'updated fade'; - echo '<div id="message" class="' . $status . '">'; - echo '<p><strong>' . $message . '</strong></p></div>'; - } } /** * Ouput formatted options * * @param array $option_data + * * @return string */ - function printOptions ($option_data, $option_actual) - { + function printOptions($option_data, $option_actual) { // Generate output $output = ''; $output .= "\n" . '<table class="form-table avhec-options">' . "\n"; foreach ($option_data as $option) { - $section = substr($option[0], strpos($option[0], '[') + 1); - $section = substr($section, 0, strpos($section, '][')); + $section = substr($option[0], strpos($option[0], '[') + 1); + $section = substr($section, 0, strpos($section, '][')); $option_key = rtrim($option[0], ']'); $option_key = substr($option_key, strpos($option_key, '][') + 2); // Helper if ($option[2] == 'helper') { - $output .= '<tr style="vertical-align: top;"><td class="helper" colspan="2">' . wp_filter_post_kses($option[4]) . '</td></tr>' . "\n"; + $output .= '<tr style="vertical-align: top;"><td class="helper" colspan="2">' . + wp_filter_post_kses($option[4]) . + '</td></tr>' . + "\n"; continue; } switch ($option[2]) { case 'checkbox': - $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"; + $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"; $explanation = $option[4]; break; case 'dropdown': $selvalue = $option[3]; - $seltext = $option[4]; - $seldata = ''; + $seltext = $option[4]; + $seldata = ''; foreach ((array) $selvalue as $key => $sel) { - $seldata .= '<option value="' . esc_attr($sel) . '" ' . (($option_actual[$section][$option_key] == $sel) ? 'selected="selected"' : '') . ' >' . esc_html(ucfirst($seltext[$key])) . '</option>' . "\n"; + $seldata .= '<option value="' . + esc_attr($sel) . + '" ' . + (($option_actual[ $section ][ $option_key ] == $sel) ? 'selected="selected"' : '') . + ' >' . + esc_html(ucfirst($seltext[ $key ])) . + '</option>' . + "\n"; } - $input_type = '<select id="' . esc_attr($option[0]) . '" name="' . esc_attr($option[0]) . '">' . $seldata . '</select>' . "\n"; + $input_type = '<select id="' . + esc_attr($option[0]) . + '" name="' . + esc_attr($option[0]) . + '">' . + $seldata . + '</select>' . + "\n"; $explanation = $option[5]; break; case 'text-color': - $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"; + $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"; $explanation = $option[4]; break; case 'textarea': - $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>'; + $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>'; $explanation = $option[4]; break; case 'catlist': ob_start(); echo '<div id="avhec-catlist">'; echo '<ul>'; - wp_category_checklist(0, 0, $option_actual[$section][$option_key]); + wp_category_checklist(0, 0, $option_actual[ $section ][ $option_key ]); echo '</ul>'; echo '</div>'; $input_type = ob_get_contents(); @@ -1453,7 +1835,18 @@ class AVH_EC_Admin break; case 'text': default: - $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"; + $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"; $explanation = $option[4]; break; } @@ -1463,59 +1856,21 @@ class AVH_EC_Admin $extra = '<br /><span class="description">' . wp_filter_kses($explanation) . '</span>' . "\n"; } // Output - $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"; + $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"; } $output .= '</table>' . "\n"; - return $output; - } - - /** - * Used in forms to set an option checked - * - * @param mixed $checked - * @param mixed $current - * @return strings - */ - function isChecked ($checked, $current) - { - $return = ''; - if ($checked == $current) { - $return = ' checked="checked"'; - } - return $return; - } - - /** - * Displays the icon on the menu pages - * - * @param $icon - */ - function displayIcon ($icon) - { - return ('<div class="icon32" id="icon-' . $icon . '"><br/></div>'); - } - - /** - * Ajax Helper: inline delete of the groups - */ - function ajaxDeleteGroup () - { - $group_id = isset($_POST['id']) ? (int) $_POST['id'] : 0; - check_ajax_referer('delete-avhecgroup_' . $group_id); - - if (! current_user_can('manage_categories')) { - die('-1'); - } - $check = $this->catgrp->getGroup($group_id); - if (false === $check) { - die('1'); - } - if ($this->catgrp->doDeleteGroup($group_id)) { - die('1'); - } else { - die('0'); - } + return $output; } } + ?> diff --git a/wp-content/plugins/extended-categories-widget/2.8/class/avh-ec.category-group.php b/wp-content/plugins/extended-categories-widget/2.8/class/avh-ec.category-group.php index decf622d29f8cb64f9f2176fea8d203916551200..cdcd71ae944a87814455faeaeb5c4a66da448beb 100644 --- a/wp-content/plugins/extended-categories-widget/2.8/class/avh-ec.category-group.php +++ b/wp-content/plugins/extended-categories-widget/2.8/class/avh-ec.category-group.php @@ -5,42 +5,29 @@ * * @author Peter van der Does */ -class AVH_EC_Category_Group -{ +class AVH_EC_Category_Group { + var $db_options_widget_titles; + var $options_widget_titles; /** * Taxonomy name + * * @var string */ var $taxonomy_name; - - var $db_options_widget_titles; - - var $options_widget_titles; - var $widget_done_catgroup; - /** - * PHP4 constructor. - * - */ - function AVH_EC_Category_Group () - { - return $this->__construct(); - } - /** * PHP5 Constructor * Init the Database Abstraction layer - * */ - function __construct () - { + function __construct() { global $wpdb; register_shutdown_function(array(&$this, '__destruct')); /** * Taxonomy name + * * @var string */ $this->taxonomy_name = 'avhec_catgroup'; @@ -51,16 +38,25 @@ class AVH_EC_Category_Group /** * Create the table if it doesn't exist. - * */ if ($wpdb->get_var('show tables like \'' . $wpdb->avhec_cat_group . '\'') != $wpdb->avhec_cat_group) { - add_action('init', array(&$this, 'doCreateTable'), 2); // Priority needs to be the same as the Register Taxonomy + add_action('init', + array(&$this, 'doCreateTable'), + 2); // Priority needs to be the same as the Register Taxonomy } - add_action('init', array(&$this, 'doRegisterTaxonomy'), 2); // Priority for registering custom taxonomies is +1 over the creation of the initial taxonomies + add_action('init', + array(&$this, 'doRegisterTaxonomy'), + 2); // Priority for registering custom taxonomies is +1 over the creation of the initial taxonomies add_action('init', array(&$this, 'doSetupOptions')); add_action('admin_init', array(&$this, 'addMetaBoxes')); + } + /** + * PHP4 constructor. + */ + function AVH_EC_Category_Group() { + return $this->__construct(); } /** @@ -68,65 +64,181 @@ class AVH_EC_Category_Group * * @return bool Always true */ - function __destruct () - { + function __destruct() { return true; } + /** + * Add the metaboxes for the pots and page pages. + * + * @WordPress action admin_init + */ + function addMetaBoxes() { + add_meta_box($this->taxonomy_name . 'div', + __('Category Groups', 'avh-ec'), + 'post_categories_meta_box', + 'post', + 'side', + 'core', + array('taxonomy' => $this->taxonomy_name)); + add_meta_box($this->taxonomy_name . 'div', + __('Category Groups', 'avh-ec'), + 'post_categories_meta_box', + 'page', + 'side', + 'core', + array('taxonomy' => $this->taxonomy_name)); + } + /** * Create Table - * @WordPress action init * + * @WordPress action init */ - function doCreateTable () - { + function doCreateTable() { global $wpdb; // Setup the DB Tables $charset_collate = ''; if (version_compare(mysql_get_server_info(), '4.1.0', '>=')) { - if (! empty($wpdb->charset)) + if ( ! empty($wpdb->charset)) { $charset_collate = 'DEFAULT CHARACTER SET ' . $wpdb->charset; - if (! empty($wpdb->collate)) + } + if ( ! empty($wpdb->collate)) { $charset_collate .= ' COLLATE ' . $wpdb->collate; + } } - $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 . ';'; + $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 . + ';'; $result = $wpdb->query($sql); } + /** + * Deletes the given category from all groups + * + * @param $category_id + */ + function doDeleteCategoryFromGroup($category_id) { + global $wpdb; + $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE term_id=%d', + $category_id)); + } + + /** + * Deletes a group + * + * @param $group_id + */ + function doDeleteGroup($group_id) { + + global $wpdb; + + $group = $this->getGroup($group_id); + $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE group_term_id=%d', + $group_id)); + $this->doDeleteWidgetTitle($group_id); + $return = wp_delete_term($group->term_id, $this->taxonomy_name); + + return ($return); + } + + /** + * Delete the Widget Title for a group + * + * @param $group_id + */ + function doDeleteWidgetTitle($group_id) { + if (isset($this->db_options_widget_titles[ $group_id ])) { + unset($this->db_options_widget_titles[ $group_id ]); + } + update_option($this->db_options_widget_titles, $this->options_widget_titles); + } + + /** + * Inserts a new group + * + * @param $term + * @param array $args + */ + function doInsertGroup($term, $args = array(), $widget_title = '') { + $row = wp_insert_term($term, $this->taxonomy_name, $args); + $this->setWidgetTitleForGroup($term, $widget_title); + + return ($row['term_id']); + } + /** * Setup Group Categories Taxonomy - * @WordPress action init * + * @WordPress action init */ - function doRegisterTaxonomy () - { + function doRegisterTaxonomy() { /** * As we don't want to see the Menu Item we have to disable show_ui. This also disables the metabox on the posts and pages, so we add thse manually instead. * 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. */ - $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')); - $caps = array('manage_terms'=>null, 'edit_terms'=>null, 'delete_terms'=>null, 'assign_terms'=>'edit_posts'); - 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)); - + $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') + ); + $caps = array( + 'manage_terms' => null, + 'edit_terms' => null, + 'delete_terms' => null, + 'assign_terms' => 'edit_posts' + ); + 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 + )); } /** * Setup the options for the widget titles - * @WordPress action init * + * @WordPress action init */ - function doSetupOptions () - { + function doSetupOptions() { // Setup the standard groups if the none group does not exists. $all_categories = $this->getAllCategoriesTermID(); if (false === $this->getTermIDBy('slug', 'none')) { - $none_group_id = wp_insert_term('none', $this->taxonomy_name, array('description'=>__('This group will not show the widget.', 'avh-ec'))); - $all_group_id = wp_insert_term('All', $this->taxonomy_name, array('description'=>__('Holds all the categories.', 'avh-ec'))); - $home_group_id = wp_insert_term('Home', $this->taxonomy_name, array('description'=>__('This group will be shown on the front page.', 'avh-ec'))); + $none_group_id = wp_insert_term('none', + $this->taxonomy_name, + array( + 'description' => __('This group will not show the widget.', 'avh-ec') + )); + $all_group_id = wp_insert_term('All', + $this->taxonomy_name, + array('description' => __('Holds all the categories.', 'avh-ec'))); + $home_group_id = wp_insert_term('Home', + $this->taxonomy_name, + array( + 'description' => __('This group will be shown on the front page.', + 'avh-ec') + )); // Fill the standard groups with all categories $this->setCategoriesForGroup($home_group_id['term_id'], $all_categories); @@ -135,12 +247,12 @@ class AVH_EC_Category_Group } $options = get_option($this->db_options_widget_titles); - if (! $options) { - $options = array(); - $id = $this->getTermIDBy('slug', 'all'); - $options[$id] = ''; - $id = $this->getTermIDBy('slug', 'home'); - $options[$id] = ''; + if ( ! $options) { + $options = array(); + $id = $this->getTermIDBy('slug', 'all'); + $options[ $id ] = ''; + $id = $this->getTermIDBy('slug', 'home'); + $options[ $id ] = ''; update_option($this->db_options_widget_titles, $options); } $this->options_widget_titles = $options; @@ -148,14 +260,30 @@ class AVH_EC_Category_Group } /** - * Add the metaboxes for the pots and page pages. - * @WordPress action admin_init + * Update a group * + * @param $group_id + * @param $selected_categories + * @param $widget_title + * return -1,0,1 Unknown Group, Duplicate Slug, Succesfull */ - function addMetaBoxes () - { - add_meta_box($this->taxonomy_name . 'div', __('Category Groups', 'avh-ec'), 'post_categories_meta_box', 'post', 'side', 'core', array('taxonomy'=>$this->taxonomy_name)); - add_meta_box($this->taxonomy_name . 'div', __('Category Groups', 'avh-ec'), 'post_categories_meta_box', 'page', 'side', 'core', array('taxonomy'=>$this->taxonomy_name)); + function doUpdateGroup($group_id, $args = array(), $selected_categories, $widget_title = '') { + + $group = $this->getGroup($group_id); + if (is_object($group)) { + $id = wp_update_term($group->term_id, $this->taxonomy_name, $args); + if ( ! is_wp_error($id)) { + $this->setWidgetTitleForGroup($group_id, $widget_title); + $this->setCategoriesForGroup($group_id, $selected_categories); + $return = 1; // Succesful + } else { + $return = 0; // Duplicate Slug + } + } else { + $return = - 1; // Unknown group + } + + return ($return); } /** @@ -163,15 +291,15 @@ class AVH_EC_Category_Group * * @return array Term_id */ - function getAllCategoriesTermID () - { + function getAllCategoriesTermID() { $all_cat_id = array(); $categories = get_categories(); - if (! is_wp_error($categories)) { + if ( ! is_wp_error($categories)) { foreach ($categories as $category) { $all_cat_id[] = $category->term_id; } } + return ($all_cat_id); } @@ -179,15 +307,19 @@ class AVH_EC_Category_Group * Get the categories from the given group from the DB * * @param int $group_id The Taxonomy Term ID - * @return Array|False categories. Will return FALSE, if the row does not exists. * + * @return Array|False categories. Will return FALSE, if the row does not exists. */ - function getCategoriesFromGroup ($group_id) - { + function getCategoriesFromGroup($group_id) { global $wpdb; // Query database - $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)); + $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)); if (is_array($result)) { // Call succeeded if (empty($result)) { // No rows found @@ -200,210 +332,135 @@ class AVH_EC_Category_Group } else { $return = false; } + return ($return); } /** - * Set the categories for the given group from the DB. Insert the group if it doesn't exists. + * Gets all information of a group * - * @param int $group_id The Taxonomy Term ID - * @param array $categories The categories - * @return Object (false if not found) + * @param $group_id * + * @return Object|False Returns False when the group doesn't exists. */ - function setCategoriesForGroup ($group_id, $categories = array()) - { + function getGroup($group_id) { global $wpdb; - $old_categories = $this->getCategoriesFromGroup($group_id); - - if (! is_array($categories)) { - $categories = array(); - } - $new_categories = $categories; - sort($old_categories); - sort($new_categories); - // If the new and old values are the same, no need to update. - if ($new_categories === $old_categories) { - return false; - } - - $new = array_diff($new_categories, $old_categories); - $removed = array_diff($old_categories, $new_categories); - - if (! empty($new)) { - foreach ($new as $cat_term_id) { - $insert[] = '(' . $group_id . ',' . $cat_term_id . ')'; - } - $value = implode(',', $insert); - $sql = 'INSERT INTO ' . $wpdb->avhec_cat_group . ' (group_term_id, term_id) VALUES ' . $value; - $result = $wpdb->query($sql); - - } - - if (! empty($removed)) { - $delete = implode(',', $removed); - $sql = $wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE group_term_id=%d and term_id IN (' . $delete . ')', $group_id); - $result = $wpdb->query($sql); - + $result = get_term((int) $group_id, $this->taxonomy_name); + if (null === $result) { + $result = false; } - return $result; + return ($result); } - /** - * Set the Widget Title for a Group - * @param int $group_id - * @param string $widget_title - * - */ - function setWidgetTitleForGroup ($group_id, $widget_title = '') - { - $this->options_widget_titles[$group_id] = $widget_title; - update_option($this->db_options_widget_titles, $this->options_widget_titles); - } + function getGroupByCategoryID($category_id) { + $return = get_term_by('slug', 'none', $this->taxonomy_name); + $cat_groups = get_terms($this->taxonomy_name, array('hide_empty' => false)); - /** - * Return the title for a group_id if exsist otherwise return false - * @param $group_id - * - */ - function getWidgetTitleForGroup ($group_id) - { - if (isset($this->options_widget_titles[$group_id])) { - return ($this->options_widget_titles[$group_id]); + foreach ($cat_groups as $group) { + $cats = $this->getCategoriesFromGroup($group->term_id); + if ($group->slug != 'all' && in_array($category_id, $cats)) { + $return = $group; + break; + } } - return false; - } - /** - * Delete the Widget Title for a group - * - * @param $group_id - */ - function doDeleteWidgetTitle ($group_id) - { - if (isset($this->db_options_widget_titles[$group_id])) { - unset($this->db_options_widget_titles[$group_id]); - } - update_option($this->db_options_widget_titles, $this->options_widget_titles); + return $return; } /** * Same as get_term_by, but returns the ID only if found, else false + * * @param string $field * @param string $value + * * @return int|boolean */ - function getTermIDBy ($field, $value) - { + function getTermIDBy($field, $value) { $row = get_term_by($field, $value, $this->taxonomy_name); if (false === $row) { $return = false; } else { $return = (int) $row->term_id; } + return ($return); } /** - * Gets all information of a group + * Return the title for a group_id if exsist otherwise return false * * @param $group_id - * @return Object|False Returns False when the group doesn't exists. */ - function getGroup ($group_id) - { - global $wpdb; - - $result = get_term((int) $group_id, $this->taxonomy_name); - if (null === $result) { - $result = false; + function getWidgetTitleForGroup($group_id) { + if (isset($this->options_widget_titles[ $group_id ])) { + return ($this->options_widget_titles[ $group_id ]); } - return ($result); - } - function getGroupByCategoryID($category_id){ - $return = get_term_by('slug', 'none', $this->taxonomy_name); - $cat_groups = get_terms($this->taxonomy_name, array('hide_empty'=>FALSE)); - - foreach ($cat_groups as $group) { - $cats = $this->getCategoriesFromGroup($group->term_id); - if ($group->slug != 'all' && in_array($category_id,$cats)) { - $return = $group; - break; - } - } - return $return; - } - /** - * Inserts a new group - * - * @param $term - * @param array $args - */ - function doInsertGroup ($term, $args = array(), $widget_title = '') - { - $row = wp_insert_term($term, $this->taxonomy_name, $args); - $this->setWidgetTitleForGroup($term, $widget_title); - return ($row['term_id']); + return false; } /** - * Deletes a group + * Set the categories for the given group from the DB. Insert the group if it doesn't exists. * - * @param $group_id + * @param int $group_id The Taxonomy Term ID + * @param array $categories The categories + * + * @return Object (false if not found) */ - function doDeleteGroup ($group_id) - { - + function setCategoriesForGroup($group_id, $categories = array()) { global $wpdb; - $group = $this->getGroup($group_id); - $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE group_term_id=%d', $group_id)); - $this->doDeleteWidgetTitle($group_id); - $return = wp_delete_term($group->term_id, $this->taxonomy_name); + $old_categories = $this->getCategoriesFromGroup($group_id); - return ($return); - } + if ( ! is_array($categories)) { + $categories = array(); + } + $new_categories = $categories; + sort($old_categories); + sort($new_categories); + // If the new and old values are the same, no need to update. + if ($new_categories === $old_categories) { + return false; + } - /** - * Update a group - * - * @param $group_id - * @param $selected_categories - * @param $widget_title - * - * return -1,0,1 Unknown Group, Duplicate Slug, Succesfull - */ - function doUpdateGroup ($group_id, $args = array(), $selected_categories, $widget_title = '') - { + $new = array_diff($new_categories, $old_categories); + $removed = array_diff($old_categories, $new_categories); - $group = $this->getGroup($group_id); - if (is_object($group)) { - $id = wp_update_term($group->term_id, $this->taxonomy_name, $args); - if (! is_wp_error($id)) { - $this->setWidgetTitleForGroup($group_id, $widget_title); - $this->setCategoriesForGroup($group_id, $selected_categories); - $return = 1; // Succesful - } else { - $return = 0; // Duplicate Slug + if ( ! empty($new)) { + foreach ($new as $cat_term_id) { + $insert[] = '(' . $group_id . ',' . $cat_term_id . ')'; } - } else { - $return = - 1; // Unknown group + $value = implode(',', $insert); + $sql = 'INSERT INTO ' . $wpdb->avhec_cat_group . ' (group_term_id, term_id) VALUES ' . $value; + $result = $wpdb->query($sql); } - return ($return); + + if ( ! empty($removed)) { + $delete = implode(',', $removed); + $sql = $wpdb->prepare('DELETE FROM ' . + $wpdb->avhec_cat_group . + ' WHERE group_term_id=%d and term_id IN (' . + $delete . + ')', + $group_id); + $result = $wpdb->query($sql); + } + + return $result; } /** - * Deletes the given category from all groups + * Set the Widget Title for a Group * - * @param $category_id + * @param int $group_id + * @param string $widget_title */ - function doDeleteCategoryFromGroup ($category_id) - { - global $wpdb; - $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE term_id=%d', $category_id)); + function setWidgetTitleForGroup($group_id, $widget_title = '') { + $this->options_widget_titles[ $group_id ] = $widget_title; + update_option($this->db_options_widget_titles, $this->options_widget_titles); } } + ?> \ No newline at end of file diff --git a/wp-content/plugins/extended-categories-widget/2.8/class/avh-ec.core.php b/wp-content/plugins/extended-categories-widget/2.8/class/avh-ec.core.php index ebf255b7d7fe2facff00cda6f077bb8483a0cc17..798df954b0c1c3bc9ca9e8247ae46cfda5da176d 100644 --- a/wp-content/plugins/extended-categories-widget/2.8/class/avh-ec.core.php +++ b/wp-content/plugins/extended-categories-widget/2.8/class/avh-ec.core.php @@ -1,295 +1,222 @@ <?php -class AVH_EC_Core -{ - var $version; - var $comment; - var $info; - var $db_options_core; - var $default_options; - var $default_options_general; - var $default_options_category_group; - var $default_options_sp_category_group; - - var $db_options_tax_meta; - - var $options; - +/** + * Create HTML list of categories. + * + * @uses Walker + */ +class AVHEC_Walker_Category extends Walker { /** - * PHP5 constructor - * + * @see Walker::$db_fields + * @since 2.1.0 + * @todo Decouple this + * @var array */ - function __construct () - { - /** - * - * @var AVH_EC_Category_Group - */ - $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); - - $this->version = '4.0.1'; - $this->comment = '<!-- AVH Extended Categories version ' . $this->version . ' | http://blog.avirtualhome.com/wordpress-plugins/ -->'; - $this->db_options_core = 'avhec'; - $this->db_options_tax_meta = 'avhec-tax_meta'; - - add_action('init', array ( &$this, 'handleInitializePlugin' ), 10); - } + var $db_fields = array('parent' => 'parent', 'id' => 'term_id'); + /** + * @see Walker::$tree_type + * @since 2.1.0 + * @var string + */ + var $tree_type = 'category'; /** - * PHP4 Constructor + * @see Walker::end_el() + * @since 2.1.0 * - * @return AVHExtendedCategoriesCore + * @param string $output Passed by reference. Used to append additional content. + * @param object $page Not used. + * @param int $depth Depth of category. Not used. + * @param array $args Only uses 'list' for whether should append to output. */ - function AVH_EC_Core () - { - $this->__construct(); - } - - function handleInitializePlugin () - { - global $wpdb; - - $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); - $db_version = 4; - - $info['siteurl'] = get_option('siteurl'); - $info['plugin_dir'] = AVHEC_PLUGIN_DIR; - $info['graphics_url'] = AVHEC_PLUGIN_URL . '/images'; - - // Set class property for info - $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'] ); - - // Set the default options - $this->default_options_general = array ( 'version' => $this->version, 'dbversion' => $db_version, 'alternative_name_select_category' => '' ); - - // Set the default category group options - $no_group_id = $catgrp->getTermIDBy('slug', 'none'); - $home_group_id = $catgrp->getTermIDBy('slug', 'home'); - $default_group_id = $catgrp->getTermIDBy('slug', 'all'); - $this->default_options_category_group = array ( 'no_group' => $no_group_id, 'home_group' => $home_group_id, 'default_group' => $default_group_id ); - - $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 ); - - $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 ); - - /** - * Set the options for the program - * - */ - $this->loadOptions(); - - // Check if we have to do updates - if ((! isset($this->options['general']['dbversion'])) || $this->options['general']['dbversion'] < $db_version) { - $this->doUpdateOptions($db_version); - } - - $db = new AVH_DB(); - if (! $db->field_exists('avhec_term_order', $wpdb->terms)) { - $wpdb->query("ALTER TABLE $wpdb->terms ADD `avhec_term_order` INT( 4 ) NULL DEFAULT '0'"); + function end_el(&$output, $page, $depth, $args) { + if ('list' != $args['style']) { + return; } - $this->handleTextdomain(); - add_filter('get_terms_orderby', array ( &$this, 'applyOrderFilter' ), 10, 2); - - } - - function applyOrderFilter ($orderby, $args) - { - switch ($args['orderby']) { - case 'avhec_manualorder': - $new_orderby = 't.avhec_term_order'; - break; - case 'avhec_3rdparty_mycategoryorder': - $new_orderby = 't.term_order'; - break; - default: - $new_orderby = $orderby; - break; - } - return $new_orderby; + $output .= '</li>' . "\n"; } /** - * Loads the i18n + * @see Walker::end_lvl() + * @since 2.1.0 * - * @return + * @param string $output Passed by reference. Used to append additional content. + * @param int $depth Depth of category. Used for tab indentation. + * @param array $args Will only append content if style argument value is 'list'. */ - function handleTextdomain () - { - - load_plugin_textdomain('avh-ec', false, AVHEC_RELATIVE_PLUGIN_DIR . '/lang'); + function end_lvl(&$output, $depth, $args) { + if ('list' != $args['style']) { + return; + } + $indent = str_repeat("\t", $depth); + $output .= $indent . '</ul>' . "\n"; } /** - * Checks if running version is newer and do upgrades if necessary - * - * @since 1.2.3 + * @see Walker::start_el() + * @since 2.1.0 * + * @param string $output Passed by reference. Used to append additional content. + * @param object $category Category data object. + * @param int $depth Depth of category in reference to parents. + * @param array $args */ - function doUpdateOptions ($db_version) - { - $options = $this->getOptions(); + function start_el(&$output, $category, $depth, $args) { + extract($args); - // Add none existing sections and/or elements to the options - foreach ($this->default_options as $section => $default_data) { - if (! array_key_exists($section, $options)) { - $options[$section] = $default_data; - continue; + $cat_name = esc_attr($category->name); + $cat_name = apply_filters('list_cats', $cat_name, $category); + $link = '<div class="avhec-widget-line"><a href="' . get_category_link($category->term_id) . '" '; + if ($use_desc_for_title == 0 || empty($category->description)) { + $link .= 'title="' . sprintf(__('View all posts filed under %s'), $cat_name) . '"'; + } else { + $link .= 'title="' . + esc_attr(strip_tags(apply_filters('category_description', $category->description, $category))) . + '"'; + } + $link .= '>'; + $link .= $cat_name . '</a>'; + + if (( ! empty($feed_image)) || ( ! empty($feed))) { + $link .= '<div class="avhec-widget-rss"> '; + + if (empty($feed_image)) { + $link .= '('; } - foreach ($default_data as $element => $default_value) { - if (! array_key_exists($element, $options[$section])) { - $options[$section][$element] = $default_value; - } + + $link .= '<a href="' . get_category_feed_link($category->term_id, $feed_type) . '"'; + + if (empty($feed)) { + $alt = ' alt="' . sprintf(__('Feed for all posts filed under %s'), $cat_name) . '"'; + } else { + $title = ' title="' . $feed . '"'; + $alt = ' alt="' . $feed . '"'; + $name = $feed; + $link .= $title; } - } - // Remove none existing sections and/or elements from the options - foreach ($options as $section => $data) { - if (! array_key_exists($section, $this->default_options)) { - unset($options[$section]); - continue; + $link .= '>'; + + if (empty($feed_image)) { + $link .= $name; + } else { + $link .= '<img src="' . $feed_image . '"' . $alt . $title . ' />'; } - foreach ($data as $element => $value) { - if (! array_key_exists($element, $this->default_options[$section])) { - unset($options[$section][$element]); - } + $link .= '</a>'; + if (empty($feed_image)) { + $link .= ')'; } + $link .= '</div>'; } - /** - * Update the options to the latests versions - */ - $options['general']['version'] = $this->version; - $options['general']['dbversion'] = $db_version; - $this->saveOptions($options); - } - /** - * Used in forms to set the checked option. - * - * @param mixed $checked - * @param mixed_type $current - * @return string - * - * @since 2.0 - */ - function isChecked ($checked, $current) - { - if ($checked == $current) { - return (' checked="checked"'); + if (isset($show_count) && $show_count) { + $link .= '<div class="avhec-widget-count"> (' . intval($category->count) . ')</div>'; } - return (''); - } - /** - * Used in forms to set the SELECTED option - * - * @param string $current - * @param string $field - * @return string - */ - function isSelected ($current, $field) - { - if ($current == $field) { - return (' SELECTED'); + if (isset($show_date) && $show_date) { + $link .= ' ' . gmdate('Y-m-d', $category->last_update_timestamp); + } + + if (isset($current_category) && $current_category) { + $_current_category = get_category($current_category); + } + + if ('list' == $args['style']) { + $output .= "\t" . '<li'; + $class = 'cat-item cat-item-' . $category->term_id; + if (isset($current_category) && $current_category && ($category->term_id == $current_category)) { + $class .= ' current-cat'; + } elseif (isset($_current_category) && + $_current_category && + ($category->term_id == $_current_category->parent) + ) { + $class .= ' current-cat-parent'; + } + $output .= ' class="' . $class . '"'; + $output .= '>' . $link . '</div>' . "\n"; + } else { + $output .= "\t" . $link . '</div><br />' . "\n"; } - return (''); } /** - * Get the base directory of a directory structure - * - * @param string $directory - * @return string + * @see Walker::start_lvl() + * @since 2.1.0 * + * @param string $output Passed by reference. Used to append additional content. + * @param int $depth Depth of category. Used for tab indentation. + * @param array $args Will only append content if style argument value is 'list'. */ - function getBaseDirectory ($directory) - { - //place each directory into array and get the last element - $return = end(explode('/', $directory)); + function start_lvl(&$output, $depth, $args) { + if ('list' != $args['style']) { + return; + } - return $return; + $indent = str_repeat("\t", $depth); + $output .= $indent . '<ul class="children">' . "\n"; } +} - /********************************* - * * - * Methods for variable: options * - * * - ********************************/ +class AVH_EC_Core { + var $comment; + var $db_options_core; + var $db_options_tax_meta; + var $default_options; + var $default_options_category_group; + var $default_options_general; + var $default_options_sp_category_group; + var $info; + var $options; + var $version; /** - * @param array $data + * PHP5 constructor */ - function setOptions ($options) - { - $this->options = $options; - } + function __construct() { + /** + * @var AVH_EC_Category_Group + */ + $catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); - /** - * return array - */ - function getOptions () - { - return ($this->options); - } + $this->version = '4.0.3-dev.1'; + $this->comment = '<!-- AVH Extended Categories version ' . + $this->version . + ' | http://blog.avirtualhome.com/wordpress-plugins/ -->'; + $this->db_options_core = 'avhec'; + $this->db_options_tax_meta = 'avhec-tax_meta'; - /** - * Save all current options and set the options - * - */ - function saveOptions ($options) - { - update_option($this->db_options_core, $options); - wp_cache_flush(); // Delete cache - $this->setOptions($options); + add_action('init', array(&$this, 'handleInitializePlugin'), 10); } /** - * Retrieves the plugin options from the WordPress options table and assigns to class variable. - * If the options do not exists, like a new installation, the options are set to the default value. + * PHP4 Constructor * - * @return none + * @return AVHExtendedCategoriesCore */ - function loadOptions () - { - $options = get_option($this->db_options_core); - if (false === $options) { // New installation - $this->resetToDefaultOptions(); - } else { - $this->setOptions($options); - } + function AVH_EC_Core() { + $this->__construct(); } - /** - * Get the value for an option element. If there's no option is set on the Admin page, return the default value. - * - * @param string $key - * @param string $option - * @return mixed - */ - function getOptionElement ($option, $key) - { - if ($this->options[$option][$key]) { - $return = $this->options[$option][$key]; // From Admin Page - } else { - $return = $this->default_options[$option][$key]; // Default + function applyOrderFilter($orderby, $args) { + switch ($args['orderby']) { + case 'avhec_manualorder': + $new_orderby = 't.avhec_term_order'; + break; + case 'avhec_3rdparty_mycategoryorder': + $new_orderby = 't.term_order'; + break; + default: + $new_orderby = $orderby; + break; } - return ($return); - } - /** - * Reset to default options and save in DB - * - */ - function resetToDefaultOptions () - { - $this->options = $this->default_options; - $this->saveOptions($this->default_options); + return $new_orderby; } /** * Display or retrieve the HTML dropdown list of categories. - * * The list of arguments is below: * 'show_option_all' (string) - Text to display for showing all categories. * 'show_option_none' (string) - Text to display for showing no categories. @@ -309,7 +236,6 @@ class AVH_EC_Core * 'name' (string) - The name attribute value for selected element. * 'class' (string) - The class attribute value for selected element. * 'selected' (int) - Which category ID is selected. - * * The 'hierarchical' argument, which is disabled by default, will override the * depth argument, unless it is true. When the argument is false, it will * display all of the categories. When it is enabled it will use the value in @@ -318,19 +244,37 @@ class AVH_EC_Core * @since 2.1.0 * * @param string|array $args Optional. Override default arguments. + * * @return string HTML content only if 'echo' argument is 0. */ - function avh_wp_dropdown_categories ($args = '', $selectedonly) - { + function avh_wp_dropdown_categories($args = '', $selectedonly) { $mywalker = new AVH_Walker_CategoryDropdown(); - $defaults = array ( 'show_option_all' => '', 'show_option_none' => '', 'orderby' => 'id', 'order' => 'ASC', 'show_last_update' => 0, 'show_count' => 0, 'hide_empty' => 1, 'child_of' => 0, 'exclude' => '', 'echo' => 1, 'selected' => 0, 'hierarchical' => 0, 'name' => 'cat', 'class' => 'postform', 'depth' => 0, 'tab_index' => 0, 'walker' => $mywalker ); + $defaults = array( + 'show_option_all' => '', + 'show_option_none' => '', + 'orderby' => 'id', + 'order' => 'ASC', + 'show_last_update' => 0, + 'show_count' => 0, + 'hide_empty' => 1, + 'child_of' => 0, + 'exclude' => '', + 'echo' => 1, + 'selected' => 0, + 'hierarchical' => 0, + 'name' => 'cat', + 'class' => 'postform', + 'depth' => 0, + 'tab_index' => 0, + 'walker' => $mywalker + ); $defaults['selected'] = (is_category()) ? get_query_var('cat') : 0; $r = wp_parse_args($args, $defaults); - if (! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) { + if ( ! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) { $r['pad_counts'] = true; } @@ -338,26 +282,36 @@ class AVH_EC_Core extract($r); $tab_index_attribute = ''; - if ((int) $tab_index > 0) + if ((int) $tab_index > 0) { $tab_index_attribute = ' tabindex="' . $tab_index . '"'; + } $categories = get_categories($r); - $name = esc_attr($name); - $class = esc_attr($class); + $name = esc_attr($name); + $class = esc_attr($class); $output = ''; - if (! empty($categories)) { - $output = '<select name="' . $name . '" id="' . $name . '" class="' . $class . '" ' . $tab_index_attribute . '>' . "\n"; + if ( ! empty($categories)) { + $output = '<select name="' . + $name . + '" id="' . + $name . + '" class="' . + $class . + '" ' . + $tab_index_attribute . + '>' . + "\n"; if ($show_option_all) { $show_option_all = apply_filters('list_cats', $show_option_all); - $selected = ('0' === strval($r['selected'])) ? " selected='selected'" : ''; + $selected = ('0' === strval($r['selected'])) ? " selected='selected'" : ''; $output .= "\t" . '<option value="0"' . $selected . '>' . $show_option_all . '</option>' . "\n"; } if ($show_option_none) { $show_option_none = apply_filters('list_cats', $show_option_none); - $selected = ('-1' === strval($r['selected'])) ? " selected='selected'" : ''; + $selected = ('-1' === strval($r['selected'])) ? " selected='selected'" : ''; $output .= "\t" . '<option value="-1"' . $selected . '>' . $show_option_none . '</option>' . "\n"; } @@ -372,15 +326,15 @@ class AVH_EC_Core $output = apply_filters('wp_dropdown_cats', $output); - if ($echo) + if ($echo) { echo $output; + } return $output; } /** * Display or retrieve the HTML list of categories. - * * The list of arguments is below: * 'show_option_all' (string) - Text to display for showing all categories. * 'orderby' (string) default is 'ID' - What column to use for ordering the @@ -406,98 +360,368 @@ class AVH_EC_Core * 'title_li' (string) - See {@link get_categories()}. * 'depth' (int) - The max depth. * - * @since 2.1.0 + * @since 2.1.0 + * + * @param string|array $args Optional. Override default arguments. + * + * @return string HTML content only if 'echo' argument is 0. + */ + function avh_wp_list_categories($args = '', $selectedonly) { + $mywalker = new AVHEC_Walker_Category(); + $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 + ); + + $r = wp_parse_args($args, $defaults); + + if ( ! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) { + $r['pad_counts'] = true; + } + + if ( ! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) { + $r['pad_counts'] = true; + } + + if (isset($r['show_date'])) { + $r['include_last_update_time'] = $r['show_date']; + } + + if (true == $r['hierarchical']) { + $r['exclude_tree'] = $r['exclude']; + $r['exclude'] = ''; + } + + extract($r); + + $categories = get_categories($r); + + $output = ''; + if ($title_li && 'list' == $style) { + $output = '<li class="categories">' . $r['title_li'] . '<ul>'; + } + + if (empty($categories)) { + if ('list' == $style) { + $output .= '<li>' . __("No categories") . '</li>'; + } else { + $output .= __("No categories"); + } + } else { + global $wp_query; + + if ( ! empty($show_option_all)) { + if ('list' == $style) { + $output .= '<li><a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a></li>'; + } else { + $output .= '<a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a>'; + } + } + + if (empty($r['current_category']) && is_category()) { + $r['current_category'] = $wp_query->get_queried_object_id(); + } + + if ($hierarchical) { + $depth = $r['depth']; + } else { + $depth = - 1; // Flat. + } + + $output .= walk_category_tree($categories, $depth, $r); + } + + if ($title_li && 'list' == $style) { + $output .= '</ul></li>'; + } + + $output = apply_filters('wp_list_categories', $output); + + if ($echo) { + echo $output; + } else { + return $output; + } + } + + /** + * Checks if running version is newer and do upgrades if necessary + * + * @since 1.2.3 + */ + function doUpdateOptions($db_version) { + $options = $this->getOptions(); + + // Add none existing sections and/or elements to the options + foreach ($this->default_options as $section => $default_data) { + if ( ! array_key_exists($section, $options)) { + $options[ $section ] = $default_data; + continue; + } + foreach ($default_data as $element => $default_value) { + if ( ! array_key_exists($element, $options[ $section ])) { + $options[ $section ][ $element ] = $default_value; + } + } + } + + // Remove none existing sections and/or elements from the options + foreach ($options as $section => $data) { + if ( ! array_key_exists($section, $this->default_options)) { + unset($options[ $section ]); + continue; + } + foreach ($data as $element => $value) { + if ( ! array_key_exists($element, $this->default_options[ $section ])) { + unset($options[ $section ][ $element ]); + } + } + } + /** + * Update the options to the latests versions + */ + $options['general']['version'] = $this->version; + $options['general']['dbversion'] = $db_version; + $this->saveOptions($options); + } + + /** + * Get the base directory of a directory structure + * + * @param string $directory + * + * @return string + */ + function getBaseDirectory($directory) { + //place each directory into array and get the last element + $return = end(explode('/', $directory)); + + return $return; + } + + function getCategories() { + static $_categories = null; + if (null === $_categories) { + $_categories = get_categories('get=all'); + } + + return $_categories; + } + + function getCategoriesId($categories) { + static $_categories_id = null; + if (null == $_categories_id) { + foreach ($categories as $key => $category) { + $_categories_id[ $category->term_id ] = $key; + } + } + + return $_categories_id; + } + + /********************************* + * * + * Methods for variable: options * + * * + ********************************/ + + /** + * Get the value for an option element. If there's no option is set on the Admin page, return the default value. + * + * @param string $key + * @param string $option * - * @param string|array $args Optional. Override default arguments. - * @return string HTML content only if 'echo' argument is 0. + * @return mixed */ - function avh_wp_list_categories ($args = '', $selectedonly) - { - $mywalker = new AVHEC_Walker_Category(); - $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 ); - - $r = wp_parse_args($args, $defaults); - - if (! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) { - $r['pad_counts'] = true; + function getOptionElement($option, $key) { + if ($this->options[ $option ][ $key ]) { + $return = $this->options[ $option ][ $key ]; // From Admin Page + } else { + $return = $this->default_options[ $option ][ $key ]; // Default } - if (! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) { - $r['pad_counts'] = true; - } + return ($return); + } - if (isset($r['show_date'])) { - $r['include_last_update_time'] = $r['show_date']; - } + /** + * return array + */ + function getOptions() { + return ($this->options); + } - if (true == $r['hierarchical']) { - $r['exclude_tree'] = $r['exclude']; - $r['exclude'] = ''; - } + /** + * @param array $data + */ + function setOptions($options) { + $this->options = $options; + } - extract($r); + function handleInitializePlugin() { + global $wpdb; - $categories = get_categories($r); + $catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); + $db_version = 4; - $output = ''; - if ($title_li && 'list' == $style) - $output = '<li class="categories">' . $r['title_li'] . '<ul>'; + $info['siteurl'] = get_option('siteurl'); + $info['plugin_dir'] = AVHEC_PLUGIN_DIR; + $info['graphics_url'] = AVHEC_PLUGIN_URL . '/images'; - if (empty($categories)) { - if ('list' == $style) - $output .= '<li>' . __("No categories") . '</li>'; - else - $output .= __("No categories"); - } else { - global $wp_query; + // Set class property for info + $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'] + ); - if (! empty($show_option_all)) - if ('list' == $style) - $output .= '<li><a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a></li>'; - else - $output .= '<a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a>'; + // Set the default options + $this->default_options_general = array( + 'version' => $this->version, + 'dbversion' => $db_version, + 'alternative_name_select_category' => '' + ); - if (empty($r['current_category']) && is_category()) - $r['current_category'] = $wp_query->get_queried_object_id(); + // Set the default category group options + $no_group_id = $catgrp->getTermIDBy('slug', 'none'); + $home_group_id = $catgrp->getTermIDBy('slug', 'home'); + $default_group_id = $catgrp->getTermIDBy('slug', 'all'); + $this->default_options_category_group = array( + 'no_group' => $no_group_id, + 'home_group' => $home_group_id, + 'default_group' => $default_group_id + ); + + $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 + ); + + $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 + ); - if ($hierarchical) { - $depth = $r['depth']; - } else { - $depth = - 1; // Flat. - } + /** + * Set the options for the program + */ + $this->loadOptions(); - $output .= walk_category_tree($categories, $depth, $r); + // Check if we have to do updates + if (( ! isset($this->options['general']['dbversion'])) || + $this->options['general']['dbversion'] < $db_version + ) { + $this->doUpdateOptions($db_version); } - if ($title_li && 'list' == $style) - $output .= '</ul></li>'; + $db = new AVH_DB(); + if ( ! $db->field_exists('avhec_term_order', $wpdb->terms)) { + $wpdb->query("ALTER TABLE $wpdb->terms ADD `avhec_term_order` INT( 4 ) NULL DEFAULT '0'"); + } - $output = apply_filters('wp_list_categories', $output); + $this->handleTextdomain(); + add_filter('get_terms_orderby', array(&$this, 'applyOrderFilter'), 10, 2); + } - if ($echo) - echo $output; - else - return $output; + /** + * Loads the i18n + * + * @return + */ + function handleTextdomain() { + + load_plugin_textdomain('avh-ec', false, AVHEC_RELATIVE_PLUGIN_DIR . '/lang'); } - function getCategories () - { - static $_categories = NULL; - if (NULL === $_categories) { - $_categories = get_categories('get=all'); + /** + * Used in forms to set the checked option. + * + * @param mixed $checked + * @param mixed_type $current + * + * @return string + * @since 2.0 + */ + function isChecked($checked, $current) { + if ($checked == $current) { + return (' checked="checked"'); } - return $_categories; + + return (''); } - function getCategoriesId ($categories) - { - static $_categories_id = NULL; - if (NULL == $_categories_id) { - foreach ($categories as $key => $category) { - $_categories_id[$category->term_id] = $key; - } + /** + * Used in forms to set the SELECTED option + * + * @param string $current + * @param string $field + * + * @return string + */ + function isSelected($current, $field) { + if ($current == $field) { + return (' SELECTED'); } - return $_categories_id; + + return (''); + } + + /** + * Retrieves the plugin options from the WordPress options table and assigns to class variable. + * If the options do not exists, like a new installation, the options are set to the default value. + * + * @return none + */ + function loadOptions() { + $options = get_option($this->db_options_core); + if (false === $options) { // New installation + $this->resetToDefaultOptions(); + } else { + $this->setOptions($options); + } + } + + /** + * Reset to default options and save in DB + */ + function resetToDefaultOptions() { + $this->options = $this->default_options; + $this->saveOptions($this->default_options); + } + + /** + * Save all current options and set the options + */ + function saveOptions($options) { + update_option($this->db_options_core, $options); + wp_cache_flush(); // Delete cache + $this->setOptions($options); } } @@ -506,29 +730,32 @@ class AVH_EC_Core * * @uses Walker */ -class AVH_Walker_CategoryDropdown extends Walker_CategoryDropdown -{ - - function walk ($elements, $max_depth) - { +class AVH_Walker_CategoryDropdown extends Walker_CategoryDropdown { + function walk($elements, $max_depth) { - $args = array_slice(func_get_args(), 2); + $args = array_slice(func_get_args(), 2); $output = ''; if ($max_depth < - 1) //invalid parameter + { return $output; + } if (empty($elements)) //nothing to walk + { return $output; + } - $id_field = $this->db_fields['id']; + $id_field = $this->db_fields['id']; $parent_field = $this->db_fields['parent']; // flat display if (- 1 == $max_depth) { - $empty_array = array (); - foreach ($elements as $e) + $empty_array = array(); + foreach ($elements as $e) { $this->display_element($e, $empty_array, 1, 0, $args, $output); + } + return $output; } @@ -538,13 +765,14 @@ class AVH_Walker_CategoryDropdown extends Walker_CategoryDropdown * children_elements is two dimensional array, eg. * children_elements[10][] contains all sub-elements whose parent is 10. */ - $top_level_elements = array (); - $children_elements = array (); + $top_level_elements = array(); + $children_elements = array(); foreach ($elements as $e) { - if (0 == $e->$parent_field) + if (0 == $e->$parent_field) { $top_level_elements[] = $e; - else - $children_elements[$e->$parent_field][] = $e; + } else { + $children_elements[ $e->$parent_field ][] = $e; + } } /* @@ -554,183 +782,38 @@ class AVH_Walker_CategoryDropdown extends Walker_CategoryDropdown if (empty($top_level_elements)) { $first = array_slice($elements, 0, 1); - $root = $first[0]; + $root = $first[0]; - $top_level_elements = array (); - $children_elements = array (); + $top_level_elements = array(); + $children_elements = array(); foreach ($elements as $e) { - if ($root->$parent_field == $e->$parent_field) + if ($root->$parent_field == $e->$parent_field) { $top_level_elements[] = $e; - else - $children_elements[$e->$parent_field][] = $e; + } else { + $children_elements[ $e->$parent_field ][] = $e; + } } } - foreach ($top_level_elements as $e) + foreach ($top_level_elements as $e) { $this->display_element($e, $children_elements, $max_depth, 0, $args, $output); + } - /* - * if we are displaying all levels, and remaining children_elements is not empty, - * then we got orphans, which should be displayed regardless - */ + /* + * if we are displaying all levels, and remaining children_elements is not empty, + * then we got orphans, which should be displayed regardless + */ if ((0 == $max_depth) && count($children_elements) > 0) { - $empty_array = array (); - foreach ($children_elements as $orphans) - foreach ($orphans as $op) + $empty_array = array(); + foreach ($children_elements as $orphans) { + foreach ($orphans as $op) { $this->display_element($op, $empty_array, 1, 0, $args, $output); + } + } } return $output; } } -/** - * Create HTML list of categories. - * - * @uses Walker - */ -class AVHEC_Walker_Category extends Walker -{ - /** - * @see Walker::$tree_type - * @since 2.1.0 - * @var string - */ - var $tree_type = 'category'; - - /** - * @see Walker::$db_fields - * @since 2.1.0 - * @todo Decouple this - * @var array - */ - var $db_fields = array ( 'parent' => 'parent', 'id' => 'term_id' ); - - /** - * @see Walker::start_lvl() - * @since 2.1.0 - * - * @param string $output Passed by reference. Used to append additional content. - * @param int $depth Depth of category. Used for tab indentation. - * @param array $args Will only append content if style argument value is 'list'. - */ - function start_lvl (&$output, $depth, $args) - { - if ('list' != $args['style']) - return; - - $indent = str_repeat("\t", $depth); - $output .= $indent . '<ul class="children">' . "\n"; - } - - /** - * @see Walker::end_lvl() - * @since 2.1.0 - * - * @param string $output Passed by reference. Used to append additional content. - * @param int $depth Depth of category. Used for tab indentation. - * @param array $args Will only append content if style argument value is 'list'. - */ - function end_lvl (&$output, $depth, $args) - { - if ('list' != $args['style']) - return; - - $indent = str_repeat("\t", $depth); - $output .= $indent . '</ul>' . "\n"; - } - - /** - * @see Walker::start_el() - * @since 2.1.0 - * - * @param string $output Passed by reference. Used to append additional content. - * @param object $category Category data object. - * @param int $depth Depth of category in reference to parents. - * @param array $args - */ - function start_el (&$output, $category, $depth, $args) - { - extract($args); - - $cat_name = esc_attr($category->name); - $cat_name = apply_filters('list_cats', $cat_name, $category); - $link = '<div class="avhec-widget-line"><a href="' . get_category_link($category->term_id) . '" '; - if ($use_desc_for_title == 0 || empty($category->description)) - $link .= 'title="' . sprintf(__('View all posts filed under %s'), $cat_name) . '"'; - else - $link .= 'title="' . esc_attr(strip_tags(apply_filters('category_description', $category->description, $category))) . '"'; - $link .= '>'; - $link .= $cat_name . '</a>'; - - if ((! empty($feed_image)) || (! empty($feed))) { - $link .= '<div class="avhec-widget-rss"> '; - - if (empty($feed_image)) - $link .= '('; - - $link .= '<a href="' . get_category_feed_link($category->term_id, $feed_type) . '"'; - - if (empty($feed)) - $alt = ' alt="' . sprintf(__('Feed for all posts filed under %s'), $cat_name) . '"'; - else { - $title = ' title="' . $feed . '"'; - $alt = ' alt="' . $feed . '"'; - $name = $feed; - $link .= $title; - } - - $link .= '>'; - - if (empty($feed_image)) - $link .= $name; - else - $link .= '<img src="' . $feed_image . '"' . $alt . $title . ' />'; - $link .= '</a>'; - if (empty($feed_image)) - $link .= ')'; - $link .= '</div>'; - } - - if (isset($show_count) && $show_count) - $link .= '<div class="avhec-widget-count"> (' . intval($category->count) . ')</div>'; - - if (isset($show_date) && $show_date) { - $link .= ' ' . gmdate('Y-m-d', $category->last_update_timestamp); - } - - if (isset($current_category) && $current_category) - $_current_category = get_category($current_category); - - if ('list' == $args['style']) { - $output .= "\t" . '<li'; - $class = 'cat-item cat-item-' . $category->term_id; - if (isset($current_category) && $current_category && ($category->term_id == $current_category)) - $class .= ' current-cat'; - elseif (isset($_current_category) && $_current_category && ($category->term_id == $_current_category->parent)) - $class .= ' current-cat-parent'; - $output .= ' class="' . $class . '"'; - $output .= '>' . $link . '</div>' . "\n"; - } else { - $output .= "\t" . $link . '</div><br />' . "\n"; - } - } - - /** - * @see Walker::end_el() - * @since 2.1.0 - * - * @param string $output Passed by reference. Used to append additional content. - * @param object $page Not used. - * @param int $depth Depth of category. Not used. - * @param array $args Only uses 'list' for whether should append to output. - */ - function end_el (&$output, $page, $depth, $args) - { - if ('list' != $args['style']) - return; - - $output .= '</li>' . "\n"; - } -} ?> diff --git a/wp-content/plugins/extended-categories-widget/2.8/class/avh-ec.widgets.php b/wp-content/plugins/extended-categories-widget/2.8/class/avh-ec.widgets.php index c7824f5c0088e18831bc6c41355f1fc265ee5d81..29cd43f43dd693f99f8bf81da3f71c26772b99e0 100644 --- a/wp-content/plugins/extended-categories-widget/2.8/class/avh-ec.widgets.php +++ b/wp-content/plugins/extended-categories-widget/2.8/class/avh-ec.widgets.php @@ -1,175 +1,228 @@ <?php /** - * Widget Class for displaying categories. Extended version of the dfeault categories. - * + * Class that will display the categories */ -class WP_Widget_AVH_ExtendedCategories_Normal extends WP_Widget -{ - /** - * - * @var AVH_EC_Core - */ - var $core; - - /** - * PHP 5 Constructor - * - */ - function __construct () - { - $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core'); - - //Convert the old option widget_extended_categories to widget_extended-categories - $old = get_option('widget_extended_categories'); - if (! (FALSE === $old)) { - update_option('widget_extended-categories', $old); - delete_option('widget_extended_categories'); - } - $widget_ops = array('description'=>__("An extended version of the default Categories widget.", 'avh-ec')); - WP_Widget::__construct('extended-categories', 'AVH Extended Categories', $widget_ops); - - add_action('wp_print_styles', array(&$this, 'actionWpPrintStyles')); +class AVH_Walker_Category_Checklist extends Walker { + var $db_fields = array('parent' => 'parent', 'id' => 'term_id'); + var $input_id; //TODO: decouple this + var $input_name; + var $li_id; + var $number; + var $tree_type = 'category'; + function end_el(&$output, $category, $depth, $args) { + $output .= "</li>\n"; } - function WP_Widget_AVH_ExtendedCategories_Normal () - { - $this->__construct(); + function end_lvl(&$output, $depth, $args) { + $indent = str_repeat("\t", $depth); + $output .= $indent . '</ul>' . "\n"; } - function actionWpPrintStyles () - { + function start_el(&$output, $category, $depth, $args) { + extract($args); + $input_id = $this->input_id . '-' . $category->term_id; + $output .= "\n" . '<li id="' . $this->li_id . '">'; + $output .= '<label for="' . $input_id . '" class="selectit">'; + $output .= '<input value="' . + $category->term_id . + '" type="checkbox" name="' . + $this->input_name . + '[' . + $category->term_id . + ']" id="' . + $input_id . + '"' . + (in_array($category->term_id, $selected_cats) ? ' checked="checked"' : "") . + '/> ' . + wp_specialchars(apply_filters('the_category', $category->name)) . + '</label>'; + } - if (! (FALSE === is_active_widget(FALSE, FALSE, $this->id_base, TRUE))) { - wp_register_style('avhec-widget', AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', array(), $this->core->version); - wp_enqueue_style('avhec-widget'); - } + function start_lvl(&$output, $depth, $args) { + $indent = str_repeat("\t", $depth); + $output .= $indent . '<ul class="children">' . "\n"; } /** - * Display the widget + * Display array of elements hierarchically. + * It is a generic function which does not assume any existing order of + * elements. max_depth = -1 means flatly display every element. max_depth = + * 0 means display all levels. max_depth > 0 specifies the number of + * display levels. * - * @param unknown_type $args - * @param unknown_type $instance + * @since 2.1.0 + * + * @param array $elements + * @param int $max_depth + * @param array $args ; + * + * @return string */ - function widget ($args, $instance) - { - - extract($args); + function walk($elements, $max_depth, $args) { - $selectedonly = $instance['selectedonly'] ? TRUE : FALSE; - $c = $instance['count'] ? TRUE : FALSE; - $h = $instance['hierarchical'] ? TRUE : FALSE; - $d = $instance['depth'] ? $instance['depth'] : 0; - $e = $instance['hide_empty'] ? TRUE : FALSE; - $use_desc_for_title = $instance['use_desc_for_title'] ? TRUE : FALSE; - $s = $instance['sort_column'] ? $instance['sort_column'] : 'name'; - $o = $instance['sort_order'] ? $instance['sort_order'] : 'asc'; - $r = $instance['rssfeed'] ? 'RSS' : ''; - $i = $instance['rssimage'] ? $instance['rssimage'] : ''; - $invert = $instance['invert_included'] ? TRUE : FALSE; + $output = ''; - if (empty($r)) { - $i = ''; + if ($max_depth < - 1) //invalid parameter + { + return $output; } - if (empty($d)) { - $d = 0; + if (empty($elements)) //nothing to walk + { + return $output; } - $title = apply_filters('widget_title', empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']); - $style = empty($instance['style']) ? 'list' : $instance['style']; + $id_field = $this->db_fields['id']; + $parent_field = $this->db_fields['parent']; - $included_cats = ''; - if ($instance['post_category']) { - $post_category = unserialize($instance['post_category']); - $children = array(); - if (! $instance['selectedonly']) { - foreach ($post_category as $cat_id) { - $children = array_merge($children, get_term_children($cat_id, 'category')); - } + // flat display + if (- 1 == $max_depth) { + $empty_array = array(); + foreach ($elements as $e) { + $this->display_element($e, $empty_array, 1, 0, $args, $output); } - $included_cats = implode(",", array_merge($post_category, $children)); + + return $output; } - if ($invert) { - $inc_exc = 'exclude'; - } else { - $inc_exc = 'include'; + /* + * 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. + */ + $top_level_elements = array(); + $children_elements = array(); + foreach ($elements as $e) { + if (0 == $e->$parent_field) { + $top_level_elements[] = $e; + } else { + $children_elements[ $e->$parent_field ][] = $e; + } } - $options = $this->core->getOptions(); - $show_option_none = __('Select Category', 'avh-ec'); - if ($options['general']['alternative_name_select_category']) { - $show_option_none = $options['general']['alternative_name_select_category']; + /* + * when none of the elements is top level + * assume the first one must be root of the sub elements + */ + if (empty($top_level_elements)) { + + $first = array_slice($elements, 0, 1); + $root = $first[0]; + + $top_level_elements = array(); + $children_elements = array(); + foreach ($elements as $e) { + if ($root->$parent_field == $e->$parent_field) { + $top_level_elements[] = $e; + } else { + $children_elements[ $e->$parent_field ][] = $e; + } + } } - $cat_args = array($inc_exc=>$included_cats, 'orderby'=>$s, 'order'=>$o, 'show_count'=>$c, 'use_desc_for_title'=>$use_desc_for_title, 'hide_empty'=>$e, 'hierarchical'=>$h, 'depth'=>$d, 'title_li'=>'', 'show_option_none'=>$show_option_none, 'feed'=>$r, 'feed_image'=>$i, 'name'=>'extended-categories-select-' . $this->number); - echo $before_widget; - echo $this->core->comment; - echo $before_title . $title . $after_title; + foreach ($top_level_elements as $e) { + $this->display_element($e, $children_elements, $max_depth, 0, $args, $output); + } - if ($style == 'list') { - echo '<ul>'; - $this->core->avh_wp_list_categories($cat_args, $selectedonly); - echo '</ul>'; - } else { - $this->core->avh_wp_dropdown_categories($cat_args, $selectedonly); - echo '<script type=\'text/javascript\'>' . "\n"; - echo '/* <![CDATA[ */' . "\n"; - echo ' var ec_dropdown_' . $this->number . ' = document.getElementById("extended-categories-select-' . $this->number . '");' . "\n"; - echo ' function ec_onCatChange_' . $this->number . '() {' . "\n"; - echo ' if ( ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value > 0 ) {' . "\n"; - echo ' location.href = "' . get_option('home') . '/?cat="+ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value;' . "\n"; - echo ' }' . "\n"; - echo ' }' . "\n"; - echo ' ec_dropdown_' . $this->number . '.onchange = ec_onCatChange_' . $this->number . ';' . "\n"; - echo '/* ]]> */' . "\n"; - echo '</script>' . "\n"; + /* + * if we are displaying all levels, and remaining children_elements is not empty, + * then we got orphans, which should be displayed regardless + */ + if (($max_depth == 0) && count($children_elements) > 0) { + $empty_array = array(); + foreach ($children_elements as $orphans) { + foreach ($orphans as $op) { + $this->display_element($op, $empty_array, 1, 0, $args, $output); + } + } } - echo $after_widget; + + return $output; } +} +/** + * Widget Class for displaying the grouped categories + */ +class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget { /** - * When Widget Control Form Is Posted - * - * @param unknown_type $new_instance - * @param unknown_type $old_instance - * @return unknown + * @var AVH_EC_Category_Group */ - function update ($new_instance, $old_instance) - { - // update the instance's settings - if (! isset($new_instance['submit'])) { - return FALSE; + var $catgrp; + /** + * @var AVH_EC_Core + */ + var $core; + + /** + * PHP 5 Constructor + */ + function __construct() { + $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core'); + $this->catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); + + $widget_ops = array('description' => __("Shows grouped categories.", 'avh-ec')); + WP_Widget::__construct(false, 'AVH Extended Categories: ' . __('Category Group'), $widget_ops); + add_action('wp_print_styles', array(&$this, 'actionWpPrintStyles')); + } + + function WP_Widget_AVH_ExtendedCategories_Category_Group() { + $this->__construct(); + } + + function actionWpPrintStyles() { + if ( ! (false === is_active_widget(false, false, $this->id_base, true))) { + wp_register_style('avhec-widget', + AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', + array(), + $this->core->version); + wp_enqueue_style('avhec-widget'); } + } - $instance = $old_instance; + function avh_wp_group_category_checklist($selected_cats, $number) { - $instance['title'] = strip_tags(stripslashes($new_instance['title'])); - $instance['selectedonly'] = $new_instance['selectedonly'] ? TRUE : FALSE; - $instance['count'] = $new_instance['count'] ? TRUE : FALSE; - $instance['hierarchical'] = $new_instance['hierarchical'] ? TRUE : FALSE; - $instance['hide_empty'] = $new_instance['hide_empty'] ? TRUE : FALSE; - $instance['use_desc_for_title'] = $new_instance['use_desc_for_title'] ? TRUE : FALSE; - $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column'])); - $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order'])); - $instance['style'] = strip_tags(stripslashes($new_instance['style'])); - $instance['rssfeed'] = $new_instance['rssfeed'] ? TRUE : FALSE; - $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage'])); - if (array_key_exists('all', $new_instance['post_category'])) { - $instance['post_category'] = FALSE; + $walker = new AVH_Walker_Category_Checklist(); + $walker->number = $number; + $walker->input_id = $this->get_field_id('post_group_category'); + $walker->input_name = $this->get_field_name('post_group_category'); + $walker->li_id = $this->get_field_id('group_category--1'); + + $args = array( + 'taxonomy' => 'avhec_catgroup', + 'descendants_and_self' => 0, + 'selected_cats' => array(), + 'popular_cats' => array(), + 'walker' => $walker, + 'checked_ontop' => true + ); + + if (is_array($selected_cats)) { + $args['selected_cats'] = $selected_cats; } else { - $instance['post_category'] = serialize($new_instance['post_category']); + $args['selected_cats'] = array(); } - $instance['depth'] = (int) $new_instance['depth']; - if ($instance['depth'] < 0 || 11 < $instance['depth']) { - $instance['depth'] = 0; + + $categories = (array) get_terms($args['taxonomy'], array('get' => 'all')); + + // 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) + $checked_categories = array(); + $keys = array_keys($categories); + + foreach ($keys as $k) { + if (in_array($categories[ $k ]->term_id, $args['selected_cats'])) { + $checked_categories[] = $categories[ $k ]; + unset($categories[ $k ]); + } } - $instance['invert_included'] = $new_instance['invert_included'] ? TRUE : FALSE; - return $instance; + // Put checked cats on top + echo $walker->walk($checked_categories, 0, array($args)); + // Then the rest of them + echo $walker->walk($categories, 0, array($args)); } /** @@ -177,398 +230,187 @@ class WP_Widget_AVH_ExtendedCategories_Normal extends WP_Widget * * @param unknown_type $instance */ - function form ($instance) - { + function form($instance) { // displays the widget admin form - $instance = wp_parse_args((array) $instance, array('title'=>'', 'rssimage'=>'', 'depth'=>0)); + $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => '')); // Prepare data for display - $depth = (int) $instance['depth']; - if ($depth < 0 || 11 < $depth) { - $depth = 0; - } - $selected_cats = ($instance['post_category'] != '') ? unserialize($instance['post_category']) : FALSE; - + $title = esc_attr($instance['title']); + $count = (bool) $instance['count']; + $hierarchical = (bool) $instance['hierarchical']; + $hide_empty = (bool) $instance['hide_empty']; + $use_desc_for_title = (bool) $instance['use_desc_for_title']; + $sort_id = ($instance['sort_column'] == 'ID') ? ' SELECTED' : ''; + $sort_name = ($instance['sort_column'] == 'name') ? ' SELECTED' : ''; + $sort_count = ($instance['sort_column'] == 'count') ? ' SELECTED' : ''; + $sort_order_a = ($instance['sort_order'] == 'asc') ? ' SELECTED' : ''; + $sort_order_d = ($instance['sort_order'] == 'desc') ? ' SELECTED' : ''; + $style_list = ($instance['style'] == 'list') ? ' SELECTED' : ''; + $style_drop = ($instance['style'] == 'drop') ? ' SELECTED' : ''; + $rssfeed = (bool) $instance['rssfeed']; + $rssimage = esc_attr($instance['rssimage']); + + $selected_cats = ($instance['post_group_category'] != + '') ? unserialize($instance['post_group_category']) : false; + ob_start(); echo '<p>'; - avh_doWidgetFormText($this->get_field_id('title'), $this->get_field_name('title'), __('Title', 'avh-ec'), $instance['title']); + avh_doWidgetFormText($this->get_field_id('title'), + $this->get_field_name('title'), + __('Title', 'avh-ec'), + $instance['title']); echo '</p>'; echo '<p>'; - avh_doWidgetFormCheckbox($this->get_field_id('selectedonly'), $this->get_field_name('selectedonly'), __('Show selected categories only', 'avh-ec'), (bool) $instance['selectedonly']); - - avh_doWidgetFormCheckbox($this->get_field_id('count'), $this->get_field_name('count'), __('Show post counts', 'avh-ec'), (bool) $instance['count']); - - avh_doWidgetFormCheckbox($this->get_field_id('hierarchical'), $this->get_field_name('hierarchical'), __('Show hierarchy', 'avh-ec'), (bool) $instance['hierarchical']); - - $options = array(0=>__('All Levels', 'avh-ec'), 1=>__('Toplevel only', 'avh-ec')); - for ($i = 2; $i <= 11; $i ++) { - $options[$i] = __('Child ', 'avh-ec') . ($i - 1); - } - avh_doWidgetFormSelect($this->get_field_id('depth'), $this->get_field_name('depth'), __('How many levels to show', 'avh-ec'), $options, $depth); - unset($options); - avh_doWidgetFormCheckbox($this->get_field_id('hide_empty'), $this->get_field_name('hide_empty'), __('Hide empty categories', 'avh-ec'), (bool) $instance['hide_empty']); - - avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'), $this->get_field_name('use_desc_for_title'), __('Use description for title', 'avh-ec'), (bool) $instance['use_desc_for_title']); + avh_doWidgetFormCheckbox($this->get_field_id('count'), + $this->get_field_name('count'), + __('Show post counts', 'avh-ec'), + (bool) $instance['count']); + + avh_doWidgetFormCheckbox($this->get_field_id('hierarchical'), + $this->get_field_name('hierarchical'), + __('Show hierarchy', 'avh-ec'), + (bool) $instance['hierarchical']); + + avh_doWidgetFormCheckbox($this->get_field_id('hide_empty'), + $this->get_field_name('hide_empty'), + __('Hide empty categories', 'avh-ec'), + (bool) $instance['hide_empty']); + + avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'), + $this->get_field_name('use_desc_for_title'), + __('Use description for title', 'avh-ec'), + (bool) $instance['use_desc_for_title']); echo '</p>'; echo '<p>'; - $options['ID'] = __('ID', 'avh-ec'); - $options['name'] = __('Name', 'avh-ec'); + $options['ID'] = __('ID', 'avh-ec'); + $options['name'] = __('Name', 'avh-ec'); $options['count'] = __('Count', 'avh-ec'); - $options['slug'] = __('Slug', 'avh-ec'); - if (is_plugin_active('my-category-order/mycategoryorder.php')) { - $options['avhec_3rdparty_mycategoryorder'] = 'My Category Order'; - } - - avh_doWidgetFormSelect($this->get_field_id('sort_column'), $this->get_field_name('sort_column'), __('Sort by', 'avh-ec'), $options, $instance['sort_column']); + $options['slug'] = __('Slug', 'avh-ec'); + avh_doWidgetFormSelect($this->get_field_id('sort_column'), + $this->get_field_name('sort_column'), + __('Sort by', 'avh-ec'), + $options, + $instance['sort_column']); unset($options); - $options['asc'] = __('Ascending', 'avh-ec'); + $options['asc'] = __('Ascending', 'avh-ec'); $options['desc'] = __('Descending', 'avh-ec'); - avh_doWidgetFormSelect($this->get_field_id('sort_order'), $this->get_field_name('sort_order'), __('Sort order', 'avh-ec'), $options, $instance['sort_order']); + avh_doWidgetFormSelect($this->get_field_id('sort_order'), + $this->get_field_name('sort_order'), + __('Sort order', 'avh-ec'), + $options, + $instance['sort_order']); unset($options); $options['list'] = __('List', 'avh-ec'); $options['drop'] = __('Drop down', 'avh-ec'); - avh_doWidgetFormSelect($this->get_field_id('style'), $this->get_field_name('style'), __('Display style', 'avh-ec'), $options, $instance['style']); + avh_doWidgetFormSelect($this->get_field_id('style'), + $this->get_field_name('style'), + __('Display style', 'avh-ec'), + $options, + $instance['style']); unset($options); echo '</p>'; echo '<p>'; - avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), $this->get_field_name('rssfeed'), __('Show RSS Feed', 'avh-ec'), (bool) $instance['rssfeed']); - - avh_doWidgetFormText($this->get_field_id('rssimage'), $this->get_field_name('rssimage'), __('Path (URI) to RSS image', 'avh-ec'), $instance['rssimage']); + avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), + $this->get_field_name('rssfeed'), + __('Show RSS Feed', 'avh-ec'), + (bool) $instance['rssfeed']); + avh_doWidgetFormText($this->get_field_id('rssimage'), + $this->get_field_name('rssimage'), + __('Path (URI) to RSS image', 'avh-ec'), + $instance['rssimage']); echo '</p>'; echo '<p>'; - echo '<b>' . __('Select categories', 'avh-ec') . '</b><hr />'; + echo '<b>' . __('Select Groups', 'avh-ec') . '</b><hr />'; 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;">'; - echo '<li id="' . $this->get_field_id('category--1') . '" class="popular-category">'; - echo '<label for="' . $this->get_field_id('post_category') . '" class="selectit">'; - 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' : '') . '> '; - _e('All Categories', 'avh-ec'); + echo '<li id="' . $this->get_field_id('group_category--1') . '" class="popular-group_category">'; + echo '<label for="' . $this->get_field_id('group_post_category') . '" class="selectit">'; + 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' : '') . + '> '; + _e('Any Group', 'avh-ec'); echo '</label>'; echo '</li>'; - ob_start(); - $this->avh_wp_category_checklist($selected_cats, $this->number); - ob_end_flush(); + + $this->avh_wp_group_category_checklist($selected_cats, $this->number); + echo '</ul>'; echo '</p>'; - echo '<p>'; - avh_doWidgetFormCheckbox($this->get_field_id('invert_included'), $this->get_field_name('invert_included'), __('Exclude the selected categories', 'avh-ec'), (bool) $instance['invert_included']); - echo '</p>'; + echo '<input type="hidden" id="' . + $this->get_field_id('submit') . + '" name="' . + $this->get_field_name('submit') . + '" value="1" />'; + ob_end_flush(); + } + + function getWidgetDoneCatGroup($id) { + $catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); + if (is_array($catgrp->widget_done_catgroup) && array_key_exists($id, $catgrp->widget_done_catgroup)) { + return true; + } + $catgrp->widget_done_catgroup[ $id ] = true; - echo '<input type="hidden" id="' . $this->get_field_id('submit') . '" name="' . $this->get_field_name('submit') . '" value="1" />'; + return false; } /** - * Creates the categories checklist + * When Widget Control Form Is Posted * - * @param int $post_id - * @param int $descendants_and_self - * @param array $selected_cats - * @param array $popular_cats - * @param int $number + * @param unknown_type $new_instance + * @param unknown_type $old_instance + * + * @return unknown */ - function avh_wp_category_checklist ($selected_cats, $number) - { - - $walker = new AVH_Walker_Category_Checklist(); - $walker->number = $number; - $walker->input_id = $this->get_field_id('post_category'); - $walker->input_name = $this->get_field_name('post_category'); - $walker->li_id = $this->get_field_id('category--1'); - - $args = array('taxonomy'=>'category', 'descendants_and_self'=>0, 'selected_cats'=>$selected_cats, 'popular_cats'=>array(), 'walker'=>$walker, 'checked_ontop'=>true, 'popular_cats'=>array()); - - if (is_array($selected_cats)) - $args['selected_cats'] = $selected_cats; - else - $args['selected_cats'] = array(); + function update($new_instance, $old_instance) { + // update the instance's settings + if ( ! isset($new_instance['submit'])) { + return false; + } - $categories = $this->core->getCategories(); - $_categories_id = $this->core->getCategoriesId($categories); + $instance = $old_instance; - // 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) - $checked_categories = array(); - foreach ($args['selected_cats'] as $key => $value) { - if (isset($_categories_id[$key])) { - $category_key = $_categories_id[$key]; - $checked_categories[] = $categories[$category_key]; - unset($categories[$category_key]); - } + $instance['title'] = strip_tags(stripslashes($new_instance['title'])); + $instance['count'] = $new_instance['count'] ? true : false; + $instance['hierarchical'] = $new_instance['hierarchical'] ? true : false; + $instance['hide_empty'] = $new_instance['hide_empty'] ? true : false; + $instance['use_desc_for_title'] = $new_instance['use_desc_for_title'] ? true : false; + $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column'])); + $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order'])); + $instance['style'] = strip_tags(stripslashes($new_instance['style'])); + $instance['rssfeed'] = $new_instance['rssfeed'] ? true : false; + $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage'])); + if (array_key_exists('all', $new_instance['post_group_category'])) { + $instance['post_group_category'] = false; + } else { + $instance['post_group_category'] = serialize($new_instance['post_group_category']); } - // Put checked cats on top - echo $walker->walk($checked_categories, 0, array ( $args )); - // Then the rest of them - echo $walker->walk($categories, 0, array ( $args )); + return $instance; } -} -/** - * Widget Class for displaying the top categories - * - */ -class WP_Widget_AVH_ExtendedCategories_Top extends WP_Widget -{ /** - * - * @var AVH_EC_Core - */ - var $core; - - /** - * PHP 5 Constructor - * - */ - function __construct () - { - $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core'); - - $widget_ops = array('description'=>__("Shows the top categories.", 'avh-ec')); - WP_Widget::__construct(FALSE, 'AVH Extended Categories: '.__('Top Categories'), $widget_ops); - add_action('wp_print_styles', array(&$this, 'actionWpPrintStyles')); - - } - - function WP_Widget_AVH_ExtendedCategories_Top () - { - $this->__construct(); - } - - function actionWpPrintStyles () - { - if (! (FALSE === is_active_widget(FALSE, FALSE, $this->id_base, TRUE))) { - wp_register_style('avhec-widget', AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', array(), $this->core->version); - wp_enqueue_style('avhec-widget'); - } - } - - /** Echo the widget content. - * - * Subclasses should over-ride this function to generate their widget code. - * - * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget. - * @param array $instance The settings for the particular instance of the widget - */ - function widget ($args, $instance) - { - extract($args); - - $title = apply_filters('widget_title', empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']); - $style = empty($instance['style']) ? 'list' : $instance['style']; - if (! $a = (int) $instance['amount']) { - $a = 5; - } elseif ($a < 1) { - $a = 1; - } - $c = $instance['count'] ? TRUE : FALSE; - $use_desc_for_title = $instance['use_desc_for_title'] ? TRUE : FALSE; - $s = $instance['sort_column'] ? $instance['sort_column'] : 'name'; - $o = $instance['sort_order'] ? $instance['sort_order'] : 'asc'; - $r = $instance['rssfeed'] ? 'RSS' : ''; - $i = $instance['rssimage'] ? $instance['rssimage'] : ''; - if (empty($r)) { - $i = ''; - } - if (! empty($i)) { - if (! file_exists(ABSPATH . '/' . $i)) { - $i = ''; - } - } - - $options = $this->core->getOptions(); - $show_option_none = __('Select Category', 'avh-ec'); - if ($options['general']['alternative_name_select_category']) { - $show_option_none = $options['general']['alternative_name_select_category']; - } - - $top_cats = get_terms('category', array('fields'=>'ids', 'orderby'=>'count', 'order'=>'DESC', 'number'=>$a, 'hierarchical'=>FALSE)); - $included_cats = implode(",", $top_cats); - - $cat_args = array('include'=>$included_cats, 'orderby'=>$s, 'order'=>$o, 'show_count'=>$c, 'use_desc_for_title'=>$use_desc_for_title, 'hide_empty'=>FALSE, 'hierarchical'=>FALSE, 'depth'=>- 1, 'title_li'=>'', 'show_option_none'=>$show_option_none, 'feed'=>$r, 'feed_image'=>$i, 'name'=>'extended-categories-top-select-' . $this->number); - echo $before_widget; - echo $this->core->comment; - echo $before_title . $title . $after_title; - echo '<ul>'; - - if ($style == 'list') { - wp_list_categories($cat_args); - } else { - wp_dropdown_categories($cat_args); - echo '<script type=\'text/javascript\'>' . "\n"; - echo '/* <![CDATA[ */' . "\n"; - echo ' var ec_dropdown_top_' . $this->number . ' = document.getElementById("extended-categories-top-select-' . $this->number . '");' . "\n"; - echo ' function ec_top_onCatChange_' . $this->number . '() {' . "\n"; - echo ' if ( ec_dropdown_top_' . $this->number . '.options[ec_dropdown_top_' . $this->number . '.selectedIndex].value > 0 ) {' . "\n"; - echo ' location.href = "' . get_option('home') . '/?cat="+ec_dropdown_top_' . $this->number . '.options[ec_dropdown_top_' . $this->number . '.selectedIndex].value;' . "\n"; - echo ' }' . "\n"; - echo ' }' . "\n"; - echo ' ec_dropdown_top_' . $this->number . '.onchange = ec_top_onCatChange_' . $this->number . ';' . "\n"; - echo '/* ]]> */' . "\n"; - echo '</script>' . "\n"; - } - echo '</ul>'; - echo $after_widget; - } - - /** Update a particular instance. - * - * This function should check that $new_instance is set correctly. - * The newly calculated value of $instance should be returned. - * If "FALSE" is returned, the instance won't be saved/updated. - * - * @param array $new_instance New settings for this instance as input by the user via form() - * @param array $old_instance Old settings for this instance - * @return array Settings to save or bool FALSE to cancel saving - */ - function update ($new_instance, $old_instance) - { - // update the instance's settings - if (! isset($new_instance['submit'])) { - return FALSE; - } - - $instance = $old_instance; - - $instance['title'] = strip_tags(stripslashes($new_instance['title'])); - $instance['amount'] = (int) $new_instance['amount']; - $instance['count'] = $new_instance['count'] ? TRUE : FALSE; - $instance['use_desc_for_title'] = $new_instance['use_desc_for_title'] ? TRUE : FALSE; - $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column'])); - $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order'])); - $instance['style'] = strip_tags(stripslashes($new_instance['style'])); - $instance['rssfeed'] = $new_instance['rssfeed'] ? TRUE : FALSE; - $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage'])); - - return $instance; - } - - /** Echo the settings update form - * - * @param array $instance Current settings - */ - function form ($instance) - { - // displays the widget admin form - $instance = wp_parse_args((array) $instance, array('title'=>'', 'rssimage'=>'')); - - // Prepare data for display - if (! $amount = (int) $instance['amount']) { - $amount = 5; - } - - if ($amount < 1) { - $amount = 1; - } - echo '<p>'; - avh_doWidgetFormText($this->get_field_id('title'), $this->get_field_name('title'), __('Title', 'avh-ec'), $instance['title']); - echo '</p>'; - - echo '<p>'; - avh_doWidgetFormText($this->get_field_id('amount'), $this->get_field_name('amount'), __('How many categories to show', 'avh-ec'), $amount); - echo '</p>'; - - echo '<p>'; - avh_doWidgetFormCheckbox($this->get_field_id('count'), $this->get_field_name('count'), __('Show post counts', 'avh-ec'), (bool) $instance['count']); - echo '<br />'; - - avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'), $this->get_field_name('use_desc_for_title'), __('Use description for title', 'avh-ec'), (bool) $instance['use_desc_for_title']); - echo '</p>'; - - echo '<p>'; - $options['ID'] = __('ID', 'avh-ec'); - $options['name'] = __('Name', 'avh-ec'); - $options['count'] = __('Count', 'avh-ec'); - $options['slug'] = __('Slug', 'avh-ec'); - avh_doWidgetFormSelect($this->get_field_id('sort_column'), $this->get_field_name('sort_column'), __('Sort by', 'avh-ec'), $options, $instance['sort_column']); - unset($options); - - $options['asc'] = __('Ascending', 'avh-ec'); - $options['desc'] = __('Descending', 'avh-ec'); - avh_doWidgetFormSelect($this->get_field_id('sort_order'), $this->get_field_name('sort_order'), __('Sort order', 'avh-ec'), $options, $instance['sort_order']); - unset($options); - - $options['list'] = __('List', 'avh-ec'); - $options['drop'] = __('Drop down', 'avh-ec'); - avh_doWidgetFormSelect($this->get_field_id('style'), $this->get_field_name('style'), __('Display style', 'avh-ec'), $options, $instance['style']); - unset($options); - echo '</p>'; - - echo '<p>'; - - avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), $this->get_field_name('rssfeed'), __('Show RSS Feed', 'avh-ec'), (bool) $instance['rssfeed']); - - avh_doWidgetFormText($this->get_field_id('rssimage'), $this->get_field_name('rssimage'), __('Path (URI) to RSS image', 'avh-ec'), $instance['rssimage']); - - echo '</p>'; - - echo '<input type="hidden" id="' . $this->get_field_id('submit') . '" name="' . $this->get_field_name('submit') . '" value="1" />'; - } -} - -/** - * Widget Class for displaying the grouped categories - * - */ -class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget -{ - /** - * - * @var AVH_EC_Core - */ - var $core; - - /** - * - * @var AVH_EC_Category_Group - */ - var $catgrp; - - /** - * PHP 5 Constructor - * - */ - function __construct () - { - $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core'); - $this->catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); - - $widget_ops = array('description'=>__("Shows grouped categories.", 'avh-ec')); - WP_Widget::__construct(FALSE, 'AVH Extended Categories: '.__('Category Group'), $widget_ops); - add_action('wp_print_styles', array(&$this, 'actionWpPrintStyles')); - - } - - function WP_Widget_AVH_ExtendedCategories_Category_Group () - { - $this->__construct(); - } - - function actionWpPrintStyles () - { - if (! (FALSE === is_active_widget(FALSE, FALSE, $this->id_base, TRUE))) { - wp_register_style('avhec-widget', AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', array(), $this->core->version); - wp_enqueue_style('avhec-widget'); - } - } - - /** - * Display the widget + * Display the widget * * @param unknown_type $args * @param unknown_type $instance */ - function widget ($args, $instance) - { + function widget($args, $instance) { global $post, $wp_query; - $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); + $catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); $options = $this->core->getOptions(); $row = array(); @@ -591,79 +433,81 @@ class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget $special_page = 'none'; } - $toDisplay = FALSE; + $toDisplay = false; if ('none' == $special_page) { $terms = wp_get_object_terms($post->ID, $catgrp->taxonomy_name); - if (! empty($terms)) { + if ( ! empty($terms)) { $selected_catgroups = unserialize($instance['post_group_category']); foreach ($terms as $key => $value) { - if ($selected_catgroups === FALSE || array_key_exists($value->term_id, $selected_catgroups)) { - if (! ($this->getWidgetDoneCatGroup($value->term_id))) { - $row = $value; - $group_found = TRUE; + if ($selected_catgroups === false || array_key_exists($value->term_id, $selected_catgroups)) { + if ( ! ($this->getWidgetDoneCatGroup($value->term_id))) { + $row = $value; + $group_found = true; break; } } } } else { - $options = $this->core->options; + $options = $this->core->options; $no_cat_group = $options['cat_group']['no_group']; - $row = get_term_by('id', $no_cat_group, $catgrp->taxonomy_name); - $group_found = TRUE; + $row = get_term_by('id', $no_cat_group, $catgrp->taxonomy_name); + $group_found = true; } } else { if ('category_group' == $special_page) { $tax_meta = get_option($this->core->db_options_tax_meta); - $term = $wp_query->get_queried_object(); - if (isset($tax_meta[$term->taxonomy][$term->term_id]['category_group_term_id'])) { - $sp_category_group_id = $tax_meta[$term->taxonomy][$term->term_id]['category_group_term_id']; + $term = $wp_query->get_queried_object(); + if (isset($tax_meta[ $term->taxonomy ][ $term->term_id ]['category_group_term_id'])) { + $sp_category_group_id = $tax_meta[ $term->taxonomy ][ $term->term_id ]['category_group_term_id']; } else { - $sp_category_group = $this->catgrp->getGroupByCategoryID($term->term_id); + $sp_category_group = $this->catgrp->getGroupByCategoryID($term->term_id); $sp_category_group_id = $sp_category_group->term_id; } } else { - $sp_category_group_id = $options['sp_cat_group'][$special_page]; + $sp_category_group_id = $options['sp_cat_group'][ $special_page ]; } - $row = get_term_by('id', $sp_category_group_id, $catgrp->taxonomy_name); // Returns FALSE when non-existance. (empty(FALSE)=TRUE) - $group_found = TRUE; + $row = get_term_by('id', + $sp_category_group_id, + $catgrp->taxonomy_name); // Returns FALSE when non-existance. (empty(FALSE)=TRUE) + $group_found = true; } if ($group_found) { - $toDisplay = TRUE; + $toDisplay = true; $category_group_id_none = $this->catgrp->getTermIDBy('slug', 'none'); - $selected_catgroups = unserialize($instance['post_group_category']); + $selected_catgroups = unserialize($instance['post_group_category']); - if ($category_group_id_none == $row->term_id ) { - $toDisplay = FALSE; - } elseif (! (FALSE == $selected_catgroups || array_key_exists($row->term_id, $selected_catgroups))) { - $toDisplay = FALSE; + if ($category_group_id_none == $row->term_id) { + $toDisplay = false; + } elseif ( ! (false == $selected_catgroups || array_key_exists($row->term_id, $selected_catgroups))) { + $toDisplay = false; } elseif ($special_page != 'none' && $this->getWidgetDoneCatGroup($sp_category_group_id)) { - $toDisplay = FALSE; + $toDisplay = false; } } if ($toDisplay) { extract($args); - $c = $instance['count'] ? TRUE : FALSE; - $e = $instance['hide_empty'] ? TRUE : FALSE; - $h = $instance['hierarchical'] ? TRUE : FALSE; - $use_desc_for_title = $instance['use_desc_for_title'] ? TRUE : FALSE; - $s = $instance['sort_column'] ? $instance['sort_column'] : 'name'; - $o = $instance['sort_order'] ? $instance['sort_order'] : 'asc'; - $r = $instance['rssfeed'] ? 'RSS' : ''; - $i = $instance['rssimage'] ? $instance['rssimage'] : ''; + $c = $instance['count'] ? true : false; + $e = $instance['hide_empty'] ? true : false; + $h = $instance['hierarchical'] ? true : false; + $use_desc_for_title = $instance['use_desc_for_title'] ? true : false; + $s = $instance['sort_column'] ? $instance['sort_column'] : 'name'; + $o = $instance['sort_order'] ? $instance['sort_order'] : 'asc'; + $r = $instance['rssfeed'] ? 'RSS' : ''; + $i = $instance['rssimage'] ? $instance['rssimage'] : ''; if (empty($r)) { $i = ''; } - $style = empty($instance['style']) ? 'list' : $instance['style']; + $style = empty($instance['style']) ? 'list' : $instance['style']; $group_id = $row->term_id; - $cats = $catgrp->getCategoriesFromGroup($group_id); + $cats = $catgrp->getCategoriesFromGroup($group_id); if (empty($instance['title'])) { $title = $catgrp->getWidgetTitleForGroup($group_id); - if (! $title) { + if ( ! $title) { $title = __('Categories', 'avh-ec'); } } else { @@ -678,65 +522,161 @@ class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget $show_option_none = $options['general']['alternative_name_select_category']; } - $cat_args = array('include'=>$included_cats, 'orderby'=>$s, 'order'=>$o, 'show_count'=>$c, 'use_desc_for_title'=>$use_desc_for_title, 'hide_empty'=>$e, 'hierarchical'=>$h, 'title_li'=>'', 'show_option_none'=>$show_option_none, 'feed'=>$r, 'feed_image'=>$i, 'name'=>'extended-categories-select-group-' . $this->number); + $cat_args = array( + 'include' => $included_cats, + 'orderby' => $s, + 'order' => $o, + 'show_count' => $c, + 'use_desc_for_title' => $use_desc_for_title, + 'hide_empty' => $e, + 'hierarchical' => $h, + 'title_li' => '', + 'show_option_none' => $show_option_none, + 'feed' => $r, + 'feed_image' => $i, + 'name' => 'extended-categories-select-group-' . $this->number + ); echo $before_widget; echo $this->core->comment; echo $before_title . $title . $after_title; if ($style == 'list') { echo '<ul>'; - $this->core->avh_wp_list_categories($cat_args, TRUE); + $this->core->avh_wp_list_categories($cat_args, true); echo '</ul>'; } else { - $this->core->avh_wp_dropdown_categories($cat_args, TRUE); + $this->core->avh_wp_dropdown_categories($cat_args, true); echo '<script type=\'text/javascript\'>' . "\n"; echo '/* <![CDATA[ */' . "\n"; - echo ' var ec_dropdown_' . $this->number . ' = document.getElementById("extended-categories-select-group-' . $this->number . '");' . "\n"; + echo ' var ec_dropdown_' . + $this->number . + ' = document.getElementById("extended-categories-select-group-' . + $this->number . + '");' . + "\n"; echo ' function ec_onCatChange_' . $this->number . '() {' . "\n"; - echo ' if ( ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value > 0 ) {' . "\n"; - echo ' location.href = "' . get_option('home') . '/?cat="+ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value;' . "\n"; + echo ' if ( ec_dropdown_' . + $this->number . + '.options[ec_dropdown_' . + $this->number . + '.selectedIndex].value > 0 ) {' . + "\n"; + echo ' location.href = "' . + get_option('home') . + '/?cat="+ec_dropdown_' . + $this->number . + '.options[ec_dropdown_' . + $this->number . + '.selectedIndex].value;' . + "\n"; echo ' }' . "\n"; echo ' }' . "\n"; - echo ' ec_dropdown_' . $this->number . '.onchange = ec_onCatChange_' . $this->number . ';' . "\n"; + echo ' ec_dropdown_' . + $this->number . + '.onchange = ec_onCatChange_' . + $this->number . + ';' . + "\n"; echo '/* ]]> */' . "\n"; echo '</script>' . "\n"; } echo $after_widget; } } +} +/** + * Widget Class for displaying categories. Extended version of the dfeault categories. + */ +class WP_Widget_AVH_ExtendedCategories_Normal extends WP_Widget { /** - * When Widget Control Form Is Posted - * - * @param unknown_type $new_instance - * @param unknown_type $old_instance - * @return unknown + * @var AVH_EC_Core */ - function update ($new_instance, $old_instance) - { - // update the instance's settings - if (! isset($new_instance['submit'])) { - return FALSE; + var $core; + + /** + * PHP 5 Constructor + */ + function __construct() { + $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core'); + + //Convert the old option widget_extended_categories to widget_extended-categories + $old = get_option('widget_extended_categories'); + if ( ! (false === $old)) { + update_option('widget_extended-categories', $old); + delete_option('widget_extended_categories'); } + $widget_ops = array('description' => __("An extended version of the default Categories widget.", 'avh-ec')); + WP_Widget::__construct('extended-categories', 'AVH Extended Categories', $widget_ops); - $instance = $old_instance; + add_action('wp_print_styles', array(&$this, 'actionWpPrintStyles')); + } - $instance['title'] = strip_tags(stripslashes($new_instance['title'])); - $instance['count'] = $new_instance['count'] ? TRUE : FALSE; - $instance['hierarchical'] = $new_instance['hierarchical'] ? TRUE : FALSE; - $instance['hide_empty'] = $new_instance['hide_empty'] ? TRUE : FALSE; - $instance['use_desc_for_title'] = $new_instance['use_desc_for_title'] ? TRUE : FALSE; - $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column'])); - $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order'])); - $instance['style'] = strip_tags(stripslashes($new_instance['style'])); - $instance['rssfeed'] = $new_instance['rssfeed'] ? TRUE : FALSE; - $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage'])); - if (array_key_exists('all', $new_instance['post_group_category'])) { - $instance['post_group_category'] = FALSE; + function WP_Widget_AVH_ExtendedCategories_Normal() { + $this->__construct(); + } + + function actionWpPrintStyles() { + + if ( ! (false === is_active_widget(false, false, $this->id_base, true))) { + wp_register_style('avhec-widget', + AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', + array(), + $this->core->version); + wp_enqueue_style('avhec-widget'); + } + } + + /** + * Creates the categories checklist + * + * @param int $post_id + * @param int $descendants_and_self + * @param array $selected_cats + * @param array $popular_cats + * @param int $number + */ + function avh_wp_category_checklist($selected_cats, $number) { + + $walker = new AVH_Walker_Category_Checklist(); + $walker->number = $number; + $walker->input_id = $this->get_field_id('post_category'); + $walker->input_name = $this->get_field_name('post_category'); + $walker->li_id = $this->get_field_id('category--1'); + + $args = array( + 'taxonomy' => 'category', + 'descendants_and_self' => 0, + 'selected_cats' => $selected_cats, + 'popular_cats' => array(), + 'walker' => $walker, + 'checked_ontop' => true, + 'popular_cats' => array() + ); + + if (is_array($selected_cats)) { + $args['selected_cats'] = $selected_cats; } else { - $instance['post_group_category'] = serialize($new_instance['post_group_category']); + $args['selected_cats'] = array(); } - return $instance; + + $categories = $this->core->getCategories(); + $_categories_id = $this->core->getCategoriesId($categories); + + // 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) + $checked_categories = array(); + foreach ($args['selected_cats'] as $key => $value) { + if (isset($_categories_id[ $key ])) { + $category_key = $_categories_id[ $key ]; + $checked_categories[] = $categories[ $category_key ]; + unset($categories[ $category_key ]); + } + } + + // Put checked cats on top + echo $walker->walk($checked_categories, 0, array($args)); + // Then the rest of them + echo $walker->walk($categories, 0, array($args)); } /** @@ -744,258 +684,577 @@ class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget * * @param unknown_type $instance */ - function form ($instance) - { + function form($instance) { // displays the widget admin form - $instance = wp_parse_args((array) $instance, array('title'=>'', 'rssimage'=>'')); + $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => '', 'depth' => 0)); // Prepare data for display - $title = esc_attr($instance['title']); - $count = (bool) $instance['count']; - $hierarchical = (bool) $instance['hierarchical']; - $hide_empty = (bool) $instance['hide_empty']; - $use_desc_for_title = (bool) $instance['use_desc_for_title']; - $sort_id = ($instance['sort_column'] == 'ID') ? ' SELECTED' : ''; - $sort_name = ($instance['sort_column'] == 'name') ? ' SELECTED' : ''; - $sort_count = ($instance['sort_column'] == 'count') ? ' SELECTED' : ''; - $sort_order_a = ($instance['sort_order'] == 'asc') ? ' SELECTED' : ''; - $sort_order_d = ($instance['sort_order'] == 'desc') ? ' SELECTED' : ''; - $style_list = ($instance['style'] == 'list') ? ' SELECTED' : ''; - $style_drop = ($instance['style'] == 'drop') ? ' SELECTED' : ''; - $rssfeed = (bool) $instance['rssfeed']; - $rssimage = esc_attr($instance['rssimage']); - - $selected_cats = ($instance['post_group_category'] != '') ? unserialize($instance['post_group_category']) : FALSE; - ob_start(); + $depth = (int) $instance['depth']; + if ($depth < 0 || 11 < $depth) { + $depth = 0; + } + $selected_cats = ($instance['post_category'] != '') ? unserialize($instance['post_category']) : false; + echo '<p>'; - avh_doWidgetFormText($this->get_field_id('title'), $this->get_field_name('title'), __('Title', 'avh-ec'), $instance['title']); + avh_doWidgetFormText($this->get_field_id('title'), + $this->get_field_name('title'), + __('Title', 'avh-ec'), + $instance['title']); echo '</p>'; echo '<p>'; + avh_doWidgetFormCheckbox($this->get_field_id('selectedonly'), + $this->get_field_name('selectedonly'), + __('Show selected categories only', 'avh-ec'), + (bool) $instance['selectedonly']); + + avh_doWidgetFormCheckbox($this->get_field_id('count'), + $this->get_field_name('count'), + __('Show post counts', 'avh-ec'), + (bool) $instance['count']); + + avh_doWidgetFormCheckbox($this->get_field_id('hierarchical'), + $this->get_field_name('hierarchical'), + __('Show hierarchy', 'avh-ec'), + (bool) $instance['hierarchical']); + + $options = array(0 => __('All Levels', 'avh-ec'), 1 => __('Toplevel only', 'avh-ec')); + for ($i = 2; $i <= 11; $i ++) { + $options[ $i ] = __('Child ', 'avh-ec') . ($i - 1); + } + avh_doWidgetFormSelect($this->get_field_id('depth'), + $this->get_field_name('depth'), + __('How many levels to show', 'avh-ec'), + $options, + $depth); + unset($options); - avh_doWidgetFormCheckbox($this->get_field_id('count'), $this->get_field_name('count'), __('Show post counts', 'avh-ec'), (bool) $instance['count']); - - avh_doWidgetFormCheckbox($this->get_field_id('hierarchical'), $this->get_field_name('hierarchical'), __('Show hierarchy', 'avh-ec'), (bool) $instance['hierarchical']); - - avh_doWidgetFormCheckbox($this->get_field_id('hide_empty'), $this->get_field_name('hide_empty'), __('Hide empty categories', 'avh-ec'), (bool) $instance['hide_empty']); + avh_doWidgetFormCheckbox($this->get_field_id('hide_empty'), + $this->get_field_name('hide_empty'), + __('Hide empty categories', 'avh-ec'), + (bool) $instance['hide_empty']); - avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'), $this->get_field_name('use_desc_for_title'), __('Use description for title', 'avh-ec'), (bool) $instance['use_desc_for_title']); + avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'), + $this->get_field_name('use_desc_for_title'), + __('Use description for title', 'avh-ec'), + (bool) $instance['use_desc_for_title']); echo '</p>'; echo '<p>'; - $options['ID'] = __('ID', 'avh-ec'); - $options['name'] = __('Name', 'avh-ec'); + $options['ID'] = __('ID', 'avh-ec'); + $options['name'] = __('Name', 'avh-ec'); $options['count'] = __('Count', 'avh-ec'); - $options['slug'] = __('Slug', 'avh-ec'); - avh_doWidgetFormSelect($this->get_field_id('sort_column'), $this->get_field_name('sort_column'), __('Sort by', 'avh-ec'), $options, $instance['sort_column']); + $options['slug'] = __('Slug', 'avh-ec'); + if (is_plugin_active('my-category-order/mycategoryorder.php')) { + $options['avhec_3rdparty_mycategoryorder'] = 'My Category Order'; + } + + avh_doWidgetFormSelect($this->get_field_id('sort_column'), + $this->get_field_name('sort_column'), + __('Sort by', 'avh-ec'), + $options, + $instance['sort_column']); unset($options); - $options['asc'] = __('Ascending', 'avh-ec'); + $options['asc'] = __('Ascending', 'avh-ec'); $options['desc'] = __('Descending', 'avh-ec'); - avh_doWidgetFormSelect($this->get_field_id('sort_order'), $this->get_field_name('sort_order'), __('Sort order', 'avh-ec'), $options, $instance['sort_order']); + avh_doWidgetFormSelect($this->get_field_id('sort_order'), + $this->get_field_name('sort_order'), + __('Sort order', 'avh-ec'), + $options, + $instance['sort_order']); unset($options); $options['list'] = __('List', 'avh-ec'); $options['drop'] = __('Drop down', 'avh-ec'); - avh_doWidgetFormSelect($this->get_field_id('style'), $this->get_field_name('style'), __('Display style', 'avh-ec'), $options, $instance['style']); + avh_doWidgetFormSelect($this->get_field_id('style'), + $this->get_field_name('style'), + __('Display style', 'avh-ec'), + $options, + $instance['style']); unset($options); echo '</p>'; echo '<p>'; - avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), $this->get_field_name('rssfeed'), __('Show RSS Feed', 'avh-ec'), (bool) $instance['rssfeed']); + avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), + $this->get_field_name('rssfeed'), + __('Show RSS Feed', 'avh-ec'), + (bool) $instance['rssfeed']); + + avh_doWidgetFormText($this->get_field_id('rssimage'), + $this->get_field_name('rssimage'), + __('Path (URI) to RSS image', 'avh-ec'), + $instance['rssimage']); - avh_doWidgetFormText($this->get_field_id('rssimage'), $this->get_field_name('rssimage'), __('Path (URI) to RSS image', 'avh-ec'), $instance['rssimage']); echo '</p>'; echo '<p>'; - echo '<b>' . __('Select Groups', 'avh-ec') . '</b><hr />'; + echo '<b>' . __('Select categories', 'avh-ec') . '</b><hr />'; 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;">'; - echo '<li id="' . $this->get_field_id('group_category--1') . '" class="popular-group_category">'; - echo '<label for="' . $this->get_field_id('group_post_category') . '" class="selectit">'; - 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' : '') . '> '; - _e('Any Group', 'avh-ec'); + echo '<li id="' . $this->get_field_id('category--1') . '" class="popular-category">'; + echo '<label for="' . $this->get_field_id('post_category') . '" class="selectit">'; + 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' : '') . + '> '; + _e('All Categories', 'avh-ec'); echo '</label>'; echo '</li>'; - - $this->avh_wp_group_category_checklist($selected_cats, $this->number); - + ob_start(); + $this->avh_wp_category_checklist($selected_cats, $this->number); + ob_end_flush(); echo '</ul>'; echo '</p>'; - echo '<input type="hidden" id="' . $this->get_field_id('submit') . '" name="' . $this->get_field_name('submit') . '" value="1" />'; - ob_end_flush(); + echo '<p>'; + avh_doWidgetFormCheckbox($this->get_field_id('invert_included'), + $this->get_field_name('invert_included'), + __('Exclude the selected categories', 'avh-ec'), + (bool) $instance['invert_included']); + echo '</p>'; + + echo '<input type="hidden" id="' . + $this->get_field_id('submit') . + '" name="' . + $this->get_field_name('submit') . + '" value="1" />'; } - function avh_wp_group_category_checklist ($selected_cats, $number) - { + /** + * When Widget Control Form Is Posted + * + * @param unknown_type $new_instance + * @param unknown_type $old_instance + * + * @return unknown + */ + function update($new_instance, $old_instance) { + // update the instance's settings + if ( ! isset($new_instance['submit'])) { + return false; + } - $walker = new AVH_Walker_Category_Checklist(); - $walker->number = $number; - $walker->input_id = $this->get_field_id('post_group_category'); - $walker->input_name = $this->get_field_name('post_group_category'); - $walker->li_id = $this->get_field_id('group_category--1'); + $instance = $old_instance; - $args = array('taxonomy'=>'avhec_catgroup', 'descendants_and_self'=>0, 'selected_cats'=>array(), 'popular_cats'=>array(), 'walker'=>$walker, 'checked_ontop'=>true); + $instance['title'] = strip_tags(stripslashes($new_instance['title'])); + $instance['selectedonly'] = $new_instance['selectedonly'] ? true : false; + $instance['count'] = $new_instance['count'] ? true : false; + $instance['hierarchical'] = $new_instance['hierarchical'] ? true : false; + $instance['hide_empty'] = $new_instance['hide_empty'] ? true : false; + $instance['use_desc_for_title'] = $new_instance['use_desc_for_title'] ? true : false; + $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column'])); + $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order'])); + $instance['style'] = strip_tags(stripslashes($new_instance['style'])); + $instance['rssfeed'] = $new_instance['rssfeed'] ? true : false; + $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage'])); + if (array_key_exists('all', $new_instance['post_category'])) { + $instance['post_category'] = false; + } else { + $instance['post_category'] = serialize($new_instance['post_category']); + } + $instance['depth'] = (int) $new_instance['depth']; + if ($instance['depth'] < 0 || 11 < $instance['depth']) { + $instance['depth'] = 0; + } + $instance['invert_included'] = $new_instance['invert_included'] ? true : false; - if (is_array($selected_cats)) - $args['selected_cats'] = $selected_cats; - else - $args['selected_cats'] = array(); + return $instance; + } + + /** + * Display the widget + * + * @param unknown_type $args + * @param unknown_type $instance + */ + function widget($args, $instance) { - $categories = (array) get_terms($args['taxonomy'], array('get'=>'all')); + extract($args); - // 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) - $checked_categories = array(); - $keys = array_keys($categories); + $selectedonly = $instance['selectedonly'] ? true : false; + $c = $instance['count'] ? true : false; + $h = $instance['hierarchical'] ? true : false; + $d = $instance['depth'] ? $instance['depth'] : 0; + $e = $instance['hide_empty'] ? true : false; + $use_desc_for_title = $instance['use_desc_for_title'] ? true : false; + $s = $instance['sort_column'] ? $instance['sort_column'] : 'name'; + $o = $instance['sort_order'] ? $instance['sort_order'] : 'asc'; + $r = $instance['rssfeed'] ? 'RSS' : ''; + $i = $instance['rssimage'] ? $instance['rssimage'] : ''; + $invert = $instance['invert_included'] ? true : false; - foreach ($keys as $k) { - if (in_array($categories[$k]->term_id, $args['selected_cats'])) { - $checked_categories[] = $categories[$k]; - unset($categories[$k]); + if (empty($r)) { + $i = ''; + } + + if (empty($d)) { + $d = 0; + } + + $title = apply_filters('widget_title', + empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']); + $style = empty($instance['style']) ? 'list' : $instance['style']; + + $included_cats = ''; + if ($instance['post_category']) { + $post_category = unserialize($instance['post_category']); + $children = array(); + if ( ! $instance['selectedonly']) { + foreach ($post_category as $cat_id) { + $children = array_merge($children, get_term_children($cat_id, 'category')); + } } + $included_cats = implode(",", array_merge($post_category, $children)); } - // Put checked cats on top - echo $walker->walk($checked_categories, 0, array ( $args )); - // Then the rest of them - echo $walker->walk($categories, 0, array ( $args )); - } + if ($invert) { + $inc_exc = 'exclude'; + } else { + $inc_exc = 'include'; + } - function getWidgetDoneCatGroup ($id) - { - $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); - if (is_array($catgrp->widget_done_catgroup) && array_key_exists($id, $catgrp->widget_done_catgroup)) { - return TRUE; + $options = $this->core->getOptions(); + $show_option_none = __('Select Category', 'avh-ec'); + if ($options['general']['alternative_name_select_category']) { + $show_option_none = $options['general']['alternative_name_select_category']; + } + + $cat_args = array( + $inc_exc => $included_cats, + 'orderby' => $s, + 'order' => $o, + 'show_count' => $c, + 'use_desc_for_title' => $use_desc_for_title, + 'hide_empty' => $e, + 'hierarchical' => $h, + 'depth' => $d, + 'title_li' => '', + 'show_option_none' => $show_option_none, + 'feed' => $r, + 'feed_image' => $i, + 'name' => 'extended-categories-select-' . $this->number + ); + echo $before_widget; + echo $this->core->comment; + echo $before_title . $title . $after_title; + + if ($style == 'list') { + echo '<ul>'; + $this->core->avh_wp_list_categories($cat_args, $selectedonly); + echo '</ul>'; + } else { + $this->core->avh_wp_dropdown_categories($cat_args, $selectedonly); + echo '<script type=\'text/javascript\'>' . "\n"; + echo '/* <![CDATA[ */' . "\n"; + echo ' var ec_dropdown_' . + $this->number . + ' = document.getElementById("extended-categories-select-' . + $this->number . + '");' . + "\n"; + echo ' function ec_onCatChange_' . $this->number . '() {' . "\n"; + echo ' if ( ec_dropdown_' . + $this->number . + '.options[ec_dropdown_' . + $this->number . + '.selectedIndex].value > 0 ) {' . + "\n"; + echo ' location.href = "' . + get_option('home') . + '/?cat="+ec_dropdown_' . + $this->number . + '.options[ec_dropdown_' . + $this->number . + '.selectedIndex].value;' . + "\n"; + echo ' }' . "\n"; + echo ' }' . "\n"; + echo ' ec_dropdown_' . + $this->number . + '.onchange = ec_onCatChange_' . + $this->number . + ';' . + "\n"; + echo '/* ]]> */' . "\n"; + echo '</script>' . "\n"; } - $catgrp->widget_done_catgroup[$id] = TRUE; - return FALSE; + echo $after_widget; } } /** - * Class that will display the categories - * + * Widget Class for displaying the top categories */ -class AVH_Walker_Category_Checklist extends Walker -{ - var $tree_type = 'category'; - var $db_fields = array('parent'=>'parent', 'id'=>'term_id'); //TODO: decouple this - var $number; - var $input_id; - var $input_name; - var $li_id; +class WP_Widget_AVH_ExtendedCategories_Top extends WP_Widget { + /** + * @var AVH_EC_Core + */ + var $core; /** - * Display array of elements hierarchically. - * - * It is a generic function which does not assume any existing order of - * elements. max_depth = -1 means flatly display every element. max_depth = - * 0 means display all levels. max_depth > 0 specifies the number of - * display levels. - * - * @since 2.1.0 - * - * @param array $elements - * @param int $max_depth - * @param array $args; - * @return string + * PHP 5 Constructor */ - function walk( $elements, $max_depth, $args) { + function __construct() { + $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core'); - $output = ''; + $widget_ops = array('description' => __("Shows the top categories.", 'avh-ec')); + WP_Widget::__construct(false, 'AVH Extended Categories: ' . __('Top Categories'), $widget_ops); + add_action('wp_print_styles', array(&$this, 'actionWpPrintStyles')); + } - if ($max_depth < -1) //invalid parameter - return $output; + function WP_Widget_AVH_ExtendedCategories_Top() { + $this->__construct(); + } - if (empty($elements)) //nothing to walk - return $output; + function actionWpPrintStyles() { + if ( ! (false === is_active_widget(false, false, $this->id_base, true))) { + wp_register_style('avhec-widget', + AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', + array(), + $this->core->version); + wp_enqueue_style('avhec-widget'); + } + } - $id_field = $this->db_fields['id']; - $parent_field = $this->db_fields['parent']; + /** Echo the settings update form + * + * @param array $instance Current settings + */ + function form($instance) { + // displays the widget admin form + $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => '')); - // flat display - if ( -1 == $max_depth ) { - $empty_array = array(); - foreach ( $elements as $e ) - $this->display_element( $e, $empty_array, 1, 0, $args, $output ); - return $output; + // Prepare data for display + if ( ! $amount = (int) $instance['amount']) { + $amount = 5; } - /* - * 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. - */ - $top_level_elements = array(); - $children_elements = array(); - foreach ( $elements as $e) { - if ( 0 == $e->$parent_field ) - $top_level_elements[] = $e; - else - $children_elements[ $e->$parent_field ][] = $e; + if ($amount < 1) { + $amount = 1; } + echo '<p>'; + avh_doWidgetFormText($this->get_field_id('title'), + $this->get_field_name('title'), + __('Title', 'avh-ec'), + $instance['title']); + echo '</p>'; - /* - * when none of the elements is top level - * assume the first one must be root of the sub elements - */ - if ( empty($top_level_elements) ) { + echo '<p>'; + avh_doWidgetFormText($this->get_field_id('amount'), + $this->get_field_name('amount'), + __('How many categories to show', 'avh-ec'), + $amount); + echo '</p>'; - $first = array_slice( $elements, 0, 1 ); - $root = $first[0]; + echo '<p>'; + avh_doWidgetFormCheckbox($this->get_field_id('count'), + $this->get_field_name('count'), + __('Show post counts', 'avh-ec'), + (bool) $instance['count']); + echo '<br />'; - $top_level_elements = array(); - $children_elements = array(); - foreach ( $elements as $e) { - if ( $root->$parent_field == $e->$parent_field ) - $top_level_elements[] = $e; - else - $children_elements[ $e->$parent_field ][] = $e; - } - } + avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'), + $this->get_field_name('use_desc_for_title'), + __('Use description for title', 'avh-ec'), + (bool) $instance['use_desc_for_title']); + echo '</p>'; - foreach ( $top_level_elements as $e ) - $this->display_element( $e, $children_elements, $max_depth, 0, $args, $output ); + echo '<p>'; + $options['ID'] = __('ID', 'avh-ec'); + $options['name'] = __('Name', 'avh-ec'); + $options['count'] = __('Count', 'avh-ec'); + $options['slug'] = __('Slug', 'avh-ec'); + avh_doWidgetFormSelect($this->get_field_id('sort_column'), + $this->get_field_name('sort_column'), + __('Sort by', 'avh-ec'), + $options, + $instance['sort_column']); + unset($options); - /* - * if we are displaying all levels, and remaining children_elements is not empty, - * then we got orphans, which should be displayed regardless - */ - if ( ( $max_depth == 0 ) && count( $children_elements ) > 0 ) { - $empty_array = array(); - foreach ( $children_elements as $orphans ) - foreach( $orphans as $op ) - $this->display_element( $op, $empty_array, 1, 0, $args, $output ); - } + $options['asc'] = __('Ascending', 'avh-ec'); + $options['desc'] = __('Descending', 'avh-ec'); + avh_doWidgetFormSelect($this->get_field_id('sort_order'), + $this->get_field_name('sort_order'), + __('Sort order', 'avh-ec'), + $options, + $instance['sort_order']); + unset($options); - return $output; - } - function start_lvl (&$output, $depth, $args) - { - $indent = str_repeat("\t", $depth); - $output .= $indent . '<ul class="children">' . "\n"; + $options['list'] = __('List', 'avh-ec'); + $options['drop'] = __('Drop down', 'avh-ec'); + avh_doWidgetFormSelect($this->get_field_id('style'), + $this->get_field_name('style'), + __('Display style', 'avh-ec'), + $options, + $instance['style']); + unset($options); + echo '</p>'; + + echo '<p>'; + + avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), + $this->get_field_name('rssfeed'), + __('Show RSS Feed', 'avh-ec'), + (bool) $instance['rssfeed']); + + avh_doWidgetFormText($this->get_field_id('rssimage'), + $this->get_field_name('rssimage'), + __('Path (URI) to RSS image', 'avh-ec'), + $instance['rssimage']); + + echo '</p>'; + + echo '<input type="hidden" id="' . + $this->get_field_id('submit') . + '" name="' . + $this->get_field_name('submit') . + '" value="1" />'; } - function end_lvl (&$output, $depth, $args) - { - $indent = str_repeat("\t", $depth); - $output .= $indent . '</ul>' . "\n"; + /** Update a particular instance. + * This function should check that $new_instance is set correctly. + * The newly calculated value of $instance should be returned. + * If "FALSE" is returned, the instance won't be saved/updated. + * + * @param array $new_instance New settings for this instance as input by the user via form() + * @param array $old_instance Old settings for this instance + * + * @return array Settings to save or bool FALSE to cancel saving + */ + function update($new_instance, $old_instance) { + // update the instance's settings + if ( ! isset($new_instance['submit'])) { + return false; + } + + $instance = $old_instance; + + $instance['title'] = strip_tags(stripslashes($new_instance['title'])); + $instance['amount'] = (int) $new_instance['amount']; + $instance['count'] = $new_instance['count'] ? true : false; + $instance['use_desc_for_title'] = $new_instance['use_desc_for_title'] ? true : false; + $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column'])); + $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order'])); + $instance['style'] = strip_tags(stripslashes($new_instance['style'])); + $instance['rssfeed'] = $new_instance['rssfeed'] ? true : false; + $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage'])); + + return $instance; } - function start_el (&$output, $category, $depth, $args) - { + /** Echo the widget content. + * Subclasses should over-ride this function to generate their widget code. + * + * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget. + * @param array $instance The settings for the particular instance of the widget + */ + function widget($args, $instance) { extract($args); - $input_id = $this->input_id . '-' . $category->term_id; - $output .= "\n" . '<li id="' . $this->li_id . '">'; - $output .= '<label for="' . $input_id . '" class="selectit">'; - $output .= '<input value="' . $category->term_id . '" type="checkbox" name="' . $this->input_name . '[' . $category->term_id . ']" id="' . $input_id . '"' . (in_array($category->term_id, $selected_cats) ? ' checked="checked"' : "") . '/> ' . wp_specialchars(apply_filters('the_category', $category->name)) . '</label>'; - } - function end_el (&$output, $category, $depth, $args) - { - $output .= "</li>\n"; + $title = apply_filters('widget_title', + empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']); + $style = empty($instance['style']) ? 'list' : $instance['style']; + if ( ! $a = (int) $instance['amount']) { + $a = 5; + } elseif ($a < 1) { + $a = 1; + } + $c = $instance['count'] ? true : false; + $use_desc_for_title = $instance['use_desc_for_title'] ? true : false; + $s = $instance['sort_column'] ? $instance['sort_column'] : 'name'; + $o = $instance['sort_order'] ? $instance['sort_order'] : 'asc'; + $r = $instance['rssfeed'] ? 'RSS' : ''; + $i = $instance['rssimage'] ? $instance['rssimage'] : ''; + if (empty($r)) { + $i = ''; + } + if ( ! empty($i)) { + if ( ! file_exists(ABSPATH . '/' . $i)) { + $i = ''; + } + } + + $options = $this->core->getOptions(); + $show_option_none = __('Select Category', 'avh-ec'); + if ($options['general']['alternative_name_select_category']) { + $show_option_none = $options['general']['alternative_name_select_category']; + } + + $top_cats = get_terms('category', + array( + 'fields' => 'ids', + 'orderby' => 'count', + 'order' => 'DESC', + 'number' => $a, + 'hierarchical' => false + )); + $included_cats = implode(",", $top_cats); + + $cat_args = array( + 'include' => $included_cats, + 'orderby' => $s, + 'order' => $o, + 'show_count' => $c, + 'use_desc_for_title' => $use_desc_for_title, + 'hide_empty' => false, + 'hierarchical' => false, + 'depth' => - 1, + 'title_li' => '', + 'show_option_none' => $show_option_none, + 'feed' => $r, + 'feed_image' => $i, + 'name' => 'extended-categories-top-select-' . $this->number + ); + echo $before_widget; + echo $this->core->comment; + echo $before_title . $title . $after_title; + echo '<ul>'; + + if ($style == 'list') { + wp_list_categories($cat_args); + } else { + wp_dropdown_categories($cat_args); + echo '<script type=\'text/javascript\'>' . "\n"; + echo '/* <![CDATA[ */' . "\n"; + echo ' var ec_dropdown_top_' . + $this->number . + ' = document.getElementById("extended-categories-top-select-' . + $this->number . + '");' . + "\n"; + echo ' function ec_top_onCatChange_' . $this->number . '() {' . "\n"; + echo ' if ( ec_dropdown_top_' . + $this->number . + '.options[ec_dropdown_top_' . + $this->number . + '.selectedIndex].value > 0 ) {' . + "\n"; + echo ' location.href = "' . + get_option('home') . + '/?cat="+ec_dropdown_top_' . + $this->number . + '.options[ec_dropdown_top_' . + $this->number . + '.selectedIndex].value;' . + "\n"; + echo ' }' . "\n"; + echo ' }' . "\n"; + echo ' ec_dropdown_top_' . + $this->number . + '.onchange = ec_top_onCatChange_' . + $this->number . + ';' . + "\n"; + echo '/* ]]> */' . "\n"; + echo '</script>' . "\n"; + } + echo '</ul>'; + echo $after_widget; } } + ?> \ No newline at end of file diff --git a/wp-content/plugins/extended-categories-widget/2.8/css/avh-ec.admin.css b/wp-content/plugins/extended-categories-widget/2.8/css/avh-ec.admin.css index d810bc877f4dbd6be6f90c20348fcc9f57a42443..15631611324509fcb8d91d1a8d307ab7c629655a 100644 --- a/wp-content/plugins/extended-categories-widget/2.8/css/avh-ec.admin.css +++ b/wp-content/plugins/extended-categories-widget/2.8/css/avh-ec.admin.css @@ -1,13 +1,13 @@ .footer_avhec { - font-size: 0.8em; - text-align: center; + font-size : 0.8em; + text-align : center; } div.clearer { - clear: both; - line-height: 1px; - font-size: 1px; - height: 1px; + clear : both; + line-height : 1px; + font-size : 1px; + height : 1px; } /* Metabox in General */ @@ -21,12 +21,12 @@ table.avhec-options { .avhec-metabox-wrap .p { - line-height: 140%; - margin: 1em 0; + line-height : 140%; + margin : 1em 0; } #avhecBoxOptions option { - padding: .5em; + padding : .5em; } .avhec-metabox-wrap span.description { @@ -34,17 +34,17 @@ table.avhec-options { } .avhec-metabox-wrap .b { - font-weight: bold; + font-weight : bold; } .avhec-metabox-wrap ul { - margin-bottom: 1em; + margin-bottom : 1em; } .avhec-metabox-wrap ul li { - line-height: 120%; - list-style: disc inside none; - margin-bottom: 0; + line-height : 120%; + list-style : disc inside none; + margin-bottom : 0; } #avhec-options input { @@ -58,12 +58,13 @@ table.avhec-options { /* Metabox FAQ */ #avhecBoxFAQ .inside ul { - margin-bottom: 6px; + margin-bottom : 6px; } -#avhecBoxFAQ .inside ul li{ - line-height: 120%; - list-style: disc inside none; - margin-bottom: 0; + +#avhecBoxFAQ .inside ul li { + line-height : 120%; + list-style : disc inside none; + margin-bottom : 0; } /* Metabox Donations*/ @@ -72,7 +73,7 @@ table.avhec-options { } #avhecBoxDonations .versions { - padding: 6px 10px 12px; + padding : 6px 10px 12px; } /* Metabox Donations*/ @@ -82,69 +83,69 @@ table.avhec-options { /* Metabox in post and page */ #post_avhec_category_group { - width: 100%; + width : 100%; } #avhec-catlist { - -moz-border-radius: 4px 4px 4px 4px; - background-color: #FFFFFF; - border: 1px solid #DFDFDF; - height: 20em; - margin-bottom: -1.8em; - overflow: auto; - width: 95%; + -moz-border-radius : 4px 4px 4px 4px; + background-color : #FFFFFF; + border : 1px solid #DFDFDF; + height : 20em; + margin-bottom : -1.8em; + overflow : auto; + width : 95%; } #avhec-catlist ul { - padding: 3px; + padding : 3px; } #avhec-catlist li ul { - padding: 0px; + padding : 0px; } #avhec-catlist li { - margin-bottom: 0px; + margin-bottom : 0px; } #avhecManualOrder { - width: 25%; -/* border: 1px solid #B2B2B2;*/ -/* margin: 10px 10px 10px 0px;*/ -/* padding: 5px 10px 5px 10px;*/ -/* list-style: none;*/ -/* background-color: #fff;*/ -/* border-radius: 3px;*/ -/* -webkit-border-radius: 3px;*/ + width : 25%; + /* border: 1px solid #B2B2B2;*/ + /* margin: 10px 10px 10px 0px;*/ + /* padding: 5px 10px 5px 10px;*/ + /* list-style: none;*/ + /* background-color: #fff;*/ + /* border-radius: 3px;*/ + /* -webkit-border-radius: 3px;*/ } #avhecManualOrder li.lineitem { - border: 1px solid #DFDFDF; - background-image: none; - border-radius: 3px; - -webkit-border-radius: 3px; - background-color: #FFFFFF; - color: #555555; - cursor: move; - margin-top: 5px; - margin-bottom: 5px; - padding: 2px 5px 2px 5px; - list-style: none outside none; + border : 1px solid #DFDFDF; + background-image : none; + border-radius : 3px; + -webkit-border-radius : 3px; + background-color : #FFFFFF; + color : #555555; + cursor : move; + margin-top : 5px; + margin-bottom : 5px; + padding : 2px 5px 2px 5px; + list-style : none outside none; } #avhecManualOrder .sortable-placeholder { - border: 1px dashed #B2B2B2; - margin-top: 5px; - margin-bottom: 5px; - padding: 2px 5px 2px 5px; - height: 1.5em; - line-height: 1.5em; - list-style: none outside none; - background-color: transparent; - background-image: -ms-linear-gradient(top, #f9f9f9, #f5f5f5); /* IE10 */ - background-image: -moz-linear-gradient(top, #f9f9f9, #f5f5f5); /* Firefox */ - background-image: -o-linear-gradient(top, #f9f9f9, #f5f5f5); /* Opera */ - background-image: -webkit-gradient(linear, left top, left bottom, from(#f9f9f9), to(#f5f5f5)); /* old Webkit */ - background-image: -webkit-linear-gradient(top, #f9f9f9, #f5f5f5); /* new Webkit */ - background-image: linear-gradient(top, #f9f9f9, #f5f5f5); /* proposed W3C Markup */ + border : 1px dashed #B2B2B2; + margin-top : 5px; + margin-bottom : 5px; + padding : 2px 5px 2px 5px; + height : 1.5em; + line-height : 1.5em; + list-style : none outside none; + background-color : transparent; + background-image : -ms-linear-gradient(top, #f9f9f9, #f5f5f5); /* IE10 */ + background-image : -moz-linear-gradient(top, #f9f9f9, #f5f5f5); /* Firefox */ + background-image : -o-linear-gradient(top, #f9f9f9, #f5f5f5); /* Opera */ + background-image : -webkit-gradient(linear, left top, left bottom, from(#f9f9f9), to(#f5f5f5)); /* old Webkit */ + background-image : -webkit-linear-gradient(top, #f9f9f9, #f5f5f5); /* new Webkit */ + background-image : linear-gradient(top, #f9f9f9, #f5f5f5); /* proposed W3C Markup */ } \ No newline at end of file diff --git a/wp-content/plugins/extended-categories-widget/2.8/css/avh-ec.widget.css b/wp-content/plugins/extended-categories-widget/2.8/css/avh-ec.widget.css index 25a86492027158e2aee27e65b763b3f122d7d27d..fbb382083b1a92d03aa554a7e75d3191d561ee44 100644 --- a/wp-content/plugins/extended-categories-widget/2.8/css/avh-ec.widget.css +++ b/wp-content/plugins/extended-categories-widget/2.8/css/avh-ec.widget.css @@ -1,12 +1,12 @@ /* AVH Extended Categories Widget CSS */ .avhec-widget-line { - display: inline-block; + display : inline-block; } .avhec-widget-count { - display: inline; + display : inline; } .avhec-widget-rss { - display: inline; + display : inline; } \ No newline at end of file diff --git a/wp-content/plugins/extended-categories-widget/2.8/helpers/avh-forms.php b/wp-content/plugins/extended-categories-widget/2.8/helpers/avh-forms.php index ff3b54e434fe8a2a3e9d482c78bccefdf46750c4..55194fcd5fc0c07c99dd8ae644603d3548a83b4f 100644 --- a/wp-content/plugins/extended-categories-widget/2.8/helpers/avh-forms.php +++ b/wp-content/plugins/extended-categories-widget/2.8/helpers/avh-forms.php @@ -1,40 +1,56 @@ <?php -if (! function_exists('avh_doWidgetFormText')) { +if ( ! function_exists('avh_doWidgetFormText')) { - function avh_doWidgetFormText ($field_id, $field_name, $description, $value) - { + function avh_doWidgetFormText($field_id, $field_name, $description, $value) { echo '<label for="' . $field_id . '">'; echo $description; - echo '<input class="widefat" id="' . $field_id . '" name="' . $field_name . '" type="text" value="' . esc_attr($value) . '" /> '; + echo '<input class="widefat" id="' . + $field_id . + '" name="' . + $field_name . + '" type="text" value="' . + esc_attr($value) . + '" /> '; echo '</label>'; echo '<br />'; } } -if (! function_exists('avh_doWidgetFormCheckbox')) { +if ( ! function_exists('avh_doWidgetFormCheckbox')) { + + function avh_doWidgetFormCheckbox($field_id, $field_name, $description, $is_checked = false) { - function avh_doWidgetFormCheckbox ($field_id, $field_name, $description, $is_checked = FALSE) - { - echo '<label for="' . $field_id . '">'; - echo '<input class="checkbox" type="checkbox" id="' . $field_id . '" name="' . $field_name . '"' . ($is_checked ? ' CHECKED' : '') . ' /> '; + echo '<input class="checkbox" type="checkbox" id="' . + $field_id . + '" name="' . + $field_name . + '"' . + ($is_checked ? ' CHECKED' : '') . + ' /> '; echo $description; echo '</label>'; echo '<br />'; } } -if (! function_exists('avh_doWidgetFormSelect')) { +if ( ! function_exists('avh_doWidgetFormSelect')) { - function avh_doWidgetFormSelect ($field_id, $field_name, $description, $options, $selected_value) - { + function avh_doWidgetFormSelect($field_id, $field_name, $description, $options, $selected_value) { echo '<label for="' . $field_id . '">'; echo $description . ' '; echo '</label>'; - + $data = ''; foreach ($options as $value => $text) { - $data .= '<option value="' . $value . '" ' . ($value == $selected_value ? "SELECTED" : '') . '>' . $text . '</option>' . "/n"; + $data .= '<option value="' . + $value . + '" ' . + ($value == $selected_value ? "SELECTED" : '') . + '>' . + $text . + '</option>' . + "/n"; } echo '<select id="' . $field_id . '" name="' . $field_name . '"> '; echo $data; diff --git a/wp-content/plugins/extended-categories-widget/2.8/js/avh-ec.admin.manualorder.js b/wp-content/plugins/extended-categories-widget/2.8/js/avh-ec.admin.manualorder.js index 34b4ae16827d893ba3be2b4a275c04af1cab68d7..e5a9c066d70187d4ac410f22e1328940212e8ff9 100644 --- a/wp-content/plugins/extended-categories-widget/2.8/js/avh-ec.admin.manualorder.js +++ b/wp-content/plugins/extended-categories-widget/2.8/js/avh-ec.admin.manualorder.js @@ -1,19 +1,19 @@ function avhecManualOrder() { - jQuery("#avhecManualOrder").sortable({ - placeholder : "sortable-placeholder", - revert : false, - items : '.lineitem', - opacity: 0.65, - cursor: 'move', - forcePlaceholderSize: true, - tolerance : "pointer" - }); + 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")); + jQuery("#updateText").html("Updating Category Order..."); + jQuery("#hdnManualOrder").val( + jQuery("#avhecManualOrder").sortable("toArray")); } \ No newline at end of file diff --git a/wp-content/plugins/extended-categories-widget/2.8/js/avh-ec.admin.manualorder.min.js b/wp-content/plugins/extended-categories-widget/2.8/js/avh-ec.admin.manualorder.min.js new file mode 100644 index 0000000000000000000000000000000000000000..f9ff1e235ba43f64e84475f07f8a067ef81681b1 --- /dev/null +++ b/wp-content/plugins/extended-categories-widget/2.8/js/avh-ec.admin.manualorder.min.js @@ -0,0 +1 @@ +function avhecManualOrder(){jQuery("#avhecManualOrder").sortable({placeholder:"sortable-placeholder",revert:false,items:".lineitem",opacity:.65,cursor:"move",forcePlaceholderSize:true,tolerance:"pointer"})}addLoadEvent(avhecManualOrder);function orderCats(){jQuery("#updateText").html("Updating Category Order...");jQuery("#hdnManualOrder").val(jQuery("#avhecManualOrder").sortable("toArray"))} \ No newline at end of file diff --git a/wp-content/plugins/extended-categories-widget/2.8/js/avh-ec.categorygroup.js b/wp-content/plugins/extended-categories-widget/2.8/js/avh-ec.categorygroup.js index 62365c3c2d146ed6a26b71ca448be85aa5277416..b6ab3b07e4a3b8ce395641d0542fa1f8722d7267 100644 --- a/wp-content/plugins/extended-categories-widget/2.8/js/avh-ec.categorygroup.js +++ b/wp-content/plugins/extended-categories-widget/2.8/js/avh-ec.categorygroup.js @@ -1,21 +1,23 @@ -jQuery(document).ready(function($) { - var options = false, delBefore, delAfter; +jQuery(document).ready(function ($) { + var options = false, delBefore, delAfter; - delAfter = function( r, settings ) { - var id = $('cat', r).attr('id'), o; - for ( o = 0; o < options.length; o++ ) - if ( id == options[o].value ) - options[o] = null; - }; + delAfter = function (r, settings) { + var id = $('cat', r).attr('id'), o; + for (o = 0; o < options.length; o++) + if (id == options[o].value) + options[o] = null; + }; - delBefore = function(s) { - if ( 'undefined' != showNotice ) - return showNotice.warn() ? s : false; + delBefore = function (s) { + if ('undefined' != showNotice) + return showNotice.warn() ? s : false; - return s; - }; + return s; + }; - $('#the-list').wpList({ delBefore: delBefore }); + $('#the-list').wpList({delBefore: delBefore}); - $('.delete a[class^="delete"]').live('click', function(){return false;}); + $('.delete a[class^="delete"]').live('click', function () { + return false; + }); }); \ No newline at end of file diff --git a/wp-content/plugins/extended-categories-widget/2.8/js/avh-ec.categorygroup.min.js b/wp-content/plugins/extended-categories-widget/2.8/js/avh-ec.categorygroup.min.js new file mode 100644 index 0000000000000000000000000000000000000000..5b7e6ba1ef13853ad0490ef9983fe341a6d6d955 --- /dev/null +++ b/wp-content/plugins/extended-categories-widget/2.8/js/avh-ec.categorygroup.min.js @@ -0,0 +1 @@ +jQuery(document).ready(function($){var options=false,delBefore,delAfter;delAfter=function(r,settings){var id=$("cat",r).attr("id"),o;for(o=0;o<options.length;o++)if(id==options[o].value)options[o]=null};delBefore=function(s){if("undefined"!=showNotice)return showNotice.warn()?s:false;return s};$("#the-list").wpList({delBefore:delBefore});$('.delete a[class^="delete"]').live("click",function(){return false})}); \ No newline at end of file diff --git a/wp-content/plugins/extended-categories-widget/3.3/avh-ec.client.php b/wp-content/plugins/extended-categories-widget/3.3/avh-ec.client.php index d29fd0ce5e46f7e0cbd8b56ecf8dc439be585274..ab2e9c0d1c7e11bafb2d501f07a4d4a70870d7ce 100644 --- a/wp-content/plugins/extended-categories-widget/3.3/avh-ec.client.php +++ b/wp-content/plugins/extended-categories-widget/3.3/avh-ec.client.php @@ -2,77 +2,65 @@ /** * Singleton Class - * */ -class AVH_EC_Singleton -{ - +class AVH_EC_Singleton { /** - * * @param $class * @param $arg1 */ - function &getInstance ($class, $arg1 = null) - { - static $instances = array (); // array of instance names + function &getInstance($class, $arg1 = null) { + static $instances = array(); // array of instance names if (array_key_exists($class, $instances)) { - $instance = & $instances[$class]; + $instance = &$instances[ $class ]; } else { - if (! class_exists($class)) { + if ( ! class_exists($class)) { switch ($class) { case 'AVH_EC_Core': - require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.core.php'); + require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.core.php'); break; case 'AVH_EC_Category_Group': - require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.category-group.php'); + require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.category-group.php'); break; case 'AVH_EC_Widget_Helper_Class': - require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widget-helper.php'); + require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widget-helper.php'); break; } } - $instances[$class] = new $class($arg1); - $instance = & $instances[$class]; + $instances[ $class ] = new $class($arg1); + $instance = &$instances[ $class ]; } + return $instance; } // getInstance } // singleton - /** * Include the necessary files - * */ -require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/helpers/avh-forms.php'); -require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widgets.php'); +require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/helpers/avh-forms.php'); +require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widgets.php'); /** * Initialize the plugin - * */ -function avhextendedcategories_init () -{ +function avhextendedcategories_init() { // Admin if (is_admin()) { - require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.admin.php'); + require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.admin.php'); $avhec_admin = new AVH_EC_Admin(); } AVH_EC_Singleton::getInstance('AVH_EC_Core'); - - add_action('widgets_init', 'avhextendedcategories_widgets_init'); + add_action('widgets_init', 'avhextendedcategories_widgets_init'); } // End avhamazon_init() - /** * Register the widget * * @WordPress Action widgets_init - * @since 3.0 - * + * @since 3.0 */ -function avhextendedcategories_widgets_init () -{ +function avhextendedcategories_widgets_init() { register_widget('WP_Widget_AVH_ExtendedCategories_Normal'); register_widget('WP_Widget_AVH_ExtendedCategories_Top'); register_widget('WP_Widget_AVH_ExtendedCategories_Category_Group'); diff --git a/wp-content/plugins/extended-categories-widget/3.3/class/avh-ec.admin.php b/wp-content/plugins/extended-categories-widget/3.3/class/avh-ec.admin.php index ba431b99a35cdb10e9de42c4f53c572cfa289395..42c758ea3b433e7d46bc3516b56fbc78c40904e1 100644 --- a/wp-content/plugins/extended-categories-widget/3.3/class/avh-ec.admin.php +++ b/wp-content/plugins/extended-categories-widget/3.3/class/avh-ec.admin.php @@ -1,145 +1,154 @@ <?php -class AVH_EC_Admin -{ +class AVH_EC_Admin { /** - * - * @var AVH_EC_Core - */ - var $core; - - /** - * * @var AVH_EC_Category_Group */ var $catgrp; - - var $hooks = array (); + /** + * @var AVH_EC_Core + */ + var $core; + var $hooks = array(); var $message; /** * PHP5 constructor - * */ - function __construct () - { + function __construct() { // Initialize the plugin - $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core'); - $this->catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); + $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core'); + $this->catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); - add_action('wp_ajax_delete-group', array ( &$this, 'ajaxDeleteGroup' )); + add_action('wp_ajax_delete-group', array(&$this, 'ajaxDeleteGroup')); // Admin menu - add_action('admin_init', array ( &$this, 'actionAdminInit' )); - add_action('admin_menu', array ( &$this, 'actionAdminMenu' )); - add_filter('plugin_action_links_extended-categories-widget/widget_extended_categories.php', array ( &$this, 'filterPluginActions' ), 10, 2); + add_action('admin_init', array(&$this, 'actionAdminInit')); + add_action('admin_menu', array(&$this, 'actionAdminMenu')); + add_filter('plugin_action_links_extended-categories-widget/widget_extended_categories.php', + array(&$this, 'filterPluginActions'), + 10, + 2); // Actions used for editing posts - add_action('load-post.php', array ( &$this, 'actionLoadPostPage' )); - add_action('load-page.php', array ( &$this, 'actionLoadPostPage' )); + add_action('load-post.php', array(&$this, 'actionLoadPostPage')); + add_action('load-page.php', array(&$this, 'actionLoadPostPage')); // Actions related to adding and deletes categories - add_action("created_category", array ( $this, 'actionCreatedCategory' ), 10, 2); - add_action("delete_category", array ( $this, 'actionDeleteCategory' ), 10, 2); + add_action("created_category", array($this, 'actionCreatedCategory'), 10, 2); + add_action("delete_category", array($this, 'actionDeleteCategory'), 10, 2); - add_filter('manage_categories_group_columns', array ( &$this, 'filterManageCategoriesGroupColumns' )); - add_filter('explain_nonce_delete-avhecgroup', array ( &$this, 'filterExplainNonceDeleteGroup' ), 10, 2); + add_filter('manage_categories_group_columns', array(&$this, 'filterManageCategoriesGroupColumns')); + add_filter('explain_nonce_delete-avhecgroup', array(&$this, 'filterExplainNonceDeleteGroup'), 10, 2); return; } /** * PHP4 Constructor - * */ - function AVH_EC_Admin () - { + function AVH_EC_Admin() { $this->__construct(); } - function actionAdminInit () - { + function actionAdminInit() { if (is_admin() && isset($_GET['taxonomy']) && 'category' == $_GET['taxonomy']) { - add_action($_GET['taxonomy'] . '_edit_form', array ( &$this, 'displayCategoryGroupForm' ), 10, 2); + add_action($_GET['taxonomy'] . '_edit_form', array(&$this, 'displayCategoryGroupForm'), 10, 2); } - add_action('edit_term', array ( &$this, 'handleEditTerm' ), 10, 3); - + add_action('edit_term', array(&$this, 'handleEditTerm'), 10, 3); } /** + * Add the Tools and Options to the Management and Options page repectively * - * Adds Category Group form - * @WordPress action category_edit_form - * - * @param unknown_type $term - * @param unknown_type $taxonomy + * @WordPress Action admin_menu */ - function displayCategoryGroupForm ($term, $taxonomy) - { + function actionAdminMenu() { - $current_selection = ''; - $tax_meta = get_option($this->core->db_options_tax_meta); - if (isset($tax_meta[$taxonomy][$term->term_id])) { - $tax_meta = $tax_meta[$taxonomy][$term->term_id]; - $current_selection = $tax_meta['category_group_term_id']; - } + // Register Style and Scripts + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; + wp_register_script('avhec-categorygroup-js', + AVHEC_PLUGIN_URL . '/js/avh-ec.categorygroup' . $suffix . '.js', + array('jquery'), + $this->core->version, + true); + wp_register_script('avhec-manualorder', + AVHEC_PLUGIN_URL . '/js/avh-ec.admin.manualorder' . $suffix . '.js', + array('jquery-ui-sortable'), + $this->core->version, + false); + wp_register_style('avhec-admin-css', + AVHEC_PLUGIN_URL . '/css/avh-ec.admin.css', + array('wp-admin'), + $this->core->version, + 'screen'); - if (empty($current_selection)) { - $current_group = $this->catgrp->getGroupByCategoryID($term->term_id); - $current_selection = $current_group->term_id; - } + // Add menu system + $folder = $this->core->getBaseDirectory(AVHEC_PLUGIN_DIR); + add_menu_page('AVH Extended Categories', + 'AVH Extended Categories', + 'manage_options', + $folder, + array(&$this, 'doMenuOverview')); + $this->hooks['menu_overview'] = add_submenu_page($folder, + 'AVH Extended Categories: ' . __('Overview', 'avh-ec'), + __('Overview', 'avh-ec'), + 'manage_options', + $folder, + array(&$this, 'doMenuOverview')); + $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')); + $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')); + $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')); + $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')); - $cat_groups = get_terms($this->catgrp->taxonomy_name, array ( 'hide_empty' => FALSE )); - foreach ($cat_groups as $group) { - $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit'); - $dropdown_value[] = $group->term_id; - $dropdown_text[] = $temp_cat->name; - } + // Add actions for menu pages + // Overview Menu + add_action('load-' . $this->hooks['menu_overview'], array(&$this, 'actionLoadPageHook_Overview')); - foreach ($dropdown_value as $key => $sel) { - $seldata .= '<option value="' . esc_attr($sel) . '" ' . (($current_selection == $sel) ? 'selected="selected"' : '') . ' >' . esc_html(ucfirst($dropdown_text[$key])) . '</option>' . "\n"; - } + // General Options Menu + add_action('load-' . $this->hooks['menu_general'], array(&$this, 'actionLoadPageHook_General')); - echo '<h3>AVH Extended Categories - Category Group Widget</h3>'; - echo '<table class="form-table"><tbody>'; - echo '<tr class="form-field">'; - echo '<th valign="top" scope="row">'; - echo '<label for="avhec_categorygroup">Category Group</label></th>'; - echo '<td>'; - echo '<select id="avhec_categorygroup" name="avhec_categorygroup">'; - echo $seldata; - echo '</select>'; - echo '<p class="description">Select the category group to show on the archive page.</p>'; - echo '</td>'; - echo '</tr>'; - echo '</tbody></table>'; - } + // Category Groups Menu + add_action('load-' . $this->hooks['menu_category_groups'], array(&$this, 'actionLoadPageHook_CategoryGroup')); - /** - * Saves the association Category - Category Group fron the edit taxonomy page - * @WordPress action edit_form. - * - * @param unknown_type $term_id - * @param unknown_type $tt_id - * @param unknown_type $taxonomy - */ - function handleEditTerm ($term_id, $tt_id, $taxonomy) - { - $tax_meta = get_option($this->core->db_options_tax_meta); - if (isset($_POST['avhec_categorygroup']) && isset($tax_meta[$taxonomy][$term_id]['category_group_term_id']) && $tax_meta[$taxonomy][$term_id]['category_group_term_id'] != $_POST['avhec_categorygroup']) { - $tax_meta[$taxonomy][$term_id]['category_group_term_id'] = $_POST['avhec_categorygroup']; - update_option($this->core->db_options_tax_meta, $tax_meta); - } + // Manual Order Menu + add_action('load-' . $this->hooks['menu_manual_order'], array(&$this, 'actionLoadPageHook_ManualOrder')); + + // FAQ Menu + add_action('load-' . $this->hooks['menu_faq'], array(&$this, 'actionLoadPageHook_faq')); } /** * When a category is created this function is called to add the new category to the group all + * * @param $term_id * @param $term_taxonomy_id */ - function actionCreatedCategory ($term_id, $term_taxonomy_id) - { + function actionCreatedCategory($term_id, $term_taxonomy_id) { $group_id = $this->catgrp->getTermIDBy('slug', 'all'); $this->catgrp->setCategoriesForGroup($group_id, (array) $term_id); } @@ -148,75 +157,118 @@ class AVH_EC_Admin * When a category is deleted this function is called so the category is deleted from every group as well. * * @param object $term - * @param int $term_taxonomy_id + * @param int $term_taxonomy_id */ - function actionDeleteCategory ($term_id, $term_taxonomy_id) - { + function actionDeleteCategory($term_id, $term_taxonomy_id) { $this->catgrp->doDeleteCategoryFromGroup($term_id); } /** - * Enqueues the style on the post.php and page.php pages - * @WordPress Action load-$pagenow - * + * Setup everything needed for the Category Group page */ - function actionLoadPostPage () - { + function actionLoadPageHook_CategoryGroup() { + + // Add metaboxes + add_meta_box('avhecBoxCategoryGroupAdd', + __('Add Group', 'avh-ec'), + array(&$this, 'metaboxCategoryGroupAdd'), + $this->hooks['menu_category_groups'], + 'normal', + 'core'); + add_meta_box('avhecBoxCategoryGroupList', + __('Group Overview', 'avh-ec'), + array(&$this, 'metaboxCategoryGroupList'), + $this->hooks['menu_category_groups'], + 'side', + 'core'); + add_meta_box('avhecBoxCategoryGroupSpecialPages', + __('Special Pages', 'avh-ec'), + array(&$this, 'metaboxCategoryGroupSpecialPages'), + $this->hooks['menu_category_groups'], + 'normal', + 'core'); + + add_screen_option('layout_columns', array('max' => 2, 'default' => 2)); + + // WordPress core Scripts + wp_enqueue_script('common'); + wp_enqueue_script('wp-lists'); + wp_enqueue_script('postbox'); + + // Plugin Scripts + wp_enqueue_script('avhec-categorygroup-js'); + + // Plugin Style wp_enqueue_style('avhec-admin-css'); } /** - * Add the Tools and Options to the Management and Options page repectively - * - * @WordPress Action admin_menu - * + * Setup everything needed for the General Options page */ - function actionAdminMenu () - { + function actionLoadPageHook_General() { + // Add metaboxes + add_meta_box('avhecBoxOptions', + __('Options', 'avh-ec'), + array(&$this, 'metaboxOptions'), + $this->hooks['menu_general'], + 'normal', + 'core'); - // Register Style and Scripts - $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.closure'; - wp_register_script('avhec-categorygroup-js', AVHEC_PLUGIN_URL . '/js/avh-ec.categorygroup' . $suffix . '.js', array ( 'jquery' ), $this->core->version, true); - wp_register_script('avhec-manualorder', AVHEC_PLUGIN_URL . '/js/avh-ec.admin.manualorder' . $suffix . '.js', array ( 'jquery-ui-sortable' ), $this->core->version, false); - wp_register_style('avhec-admin-css', AVHEC_PLUGIN_URL . '/css/avh-ec.admin.css', array ( 'wp-admin' ), $this->core->version, 'screen'); + add_screen_option('layout_columns', array('max' => 2, 'default' => 2)); - // Add menu system - $folder = $this->core->getBaseDirectory(AVHEC_PLUGIN_DIR); - add_menu_page('AVH Extended Categories', 'AVH Extended Categories', 'manage_options', $folder, array ( &$this, 'doMenuOverview' )); - $this->hooks['menu_overview'] = add_submenu_page($folder, 'AVH Extended Categories: ' . __('Overview', 'avh-ec'), __('Overview', 'avh-ec'), 'manage_options', $folder, array ( &$this, 'doMenuOverview' )); - $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' )); - $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' )); - $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' )); - $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' )); + // WordPress core Scripts + wp_enqueue_script('common'); + wp_enqueue_script('wp-lists'); + wp_enqueue_script('postbox'); - // Add actions for menu pages - // Overview Menu - add_action('load-' . $this->hooks['menu_overview'], array ( &$this, 'actionLoadPageHook_Overview' )); + // Plugin Style and Scripts + wp_enqueue_style('avhec-admin-css'); + } - // General Options Menu - add_action('load-' . $this->hooks['menu_general'], array ( &$this, 'actionLoadPageHook_General' )); + /** + * Setup everything needed for the Manul Order page + */ + function actionLoadPageHook_ManualOrder() { - // Category Groups Menu - add_action('load-' . $this->hooks['menu_category_groups'], array ( &$this, 'actionLoadPageHook_CategoryGroup' )); + add_meta_box('avhecBoxManualOrder', + __('Manually Order Categories', 'avh-ec'), + array(&$this, 'metaboxManualOrder'), + $this->hooks['menu_manual_order'], + 'normal', + 'core'); - // Manual Order Menu - add_action('load-' . $this->hooks['menu_manual_order'], array ( &$this, 'actionLoadPageHook_ManualOrder' )); + add_screen_option('layout_columns', array('max' => 1, 'default' => 1)); - // FAQ Menu - add_action('load-' . $this->hooks['menu_faq'], array ( &$this, 'actionLoadPageHook_faq' )); + // WordPress core Styles and Scripts + wp_enqueue_script('common'); + wp_enqueue_script('wp-lists'); + wp_enqueue_script('postbox'); + wp_enqueue_script('jquery-ui-sortable'); + wp_enqueue_script('avhec-manualorder'); + + // Plugin Style + wp_enqueue_style('avhec-admin-css'); } /** * Setup everything needed for the Overview page - * */ - function actionLoadPageHook_Overview () - { + function actionLoadPageHook_Overview() { // Add metaboxes - add_meta_box('avhecBoxCategoryGroupList', __('Group Overview', 'avh-ec'), array ( &$this, 'metaboxCategoryGroupList' ), $this->hooks['menu_overview'], 'normal', 'core'); - add_meta_box('avhecBoxTranslation', __('Translation', 'avh-ec'), array ( &$this, 'metaboxTranslation' ), $this->hooks['menu_overview'], 'normal', 'core'); - - add_screen_option('layout_columns', array ( 'max' => 2, 'default' => 2 )); + add_meta_box('avhecBoxCategoryGroupList', + __('Group Overview', 'avh-ec'), + array(&$this, 'metaboxCategoryGroupList'), + $this->hooks['menu_overview'], + 'normal', + 'core'); + add_meta_box('avhecBoxTranslation', + __('Translation', 'avh-ec'), + array(&$this, 'metaboxTranslation'), + $this->hooks['menu_overview'], + 'normal', + 'core'); + + add_screen_option('layout_columns', array('max' => 2, 'default' => 2)); // WordPress core Scripts wp_enqueue_script('common'); @@ -231,297 +283,289 @@ class AVH_EC_Admin } /** - * Menu Page Overview - * - * @return none + * Setup everything needed for the FAQ page */ - function doMenuOverview () - { - global $screen_layout_columns; + function actionLoadPageHook_faq() { + + add_meta_box('avhecBoxFAQ', + __('F.A.Q.', 'avh-ec'), + array(&$this, 'metaboxFAQ'), + $this->hooks['menu_faq'], + 'normal', + 'core'); + add_meta_box('avhecBoxTranslation', + __('Translation', 'avh-ec'), + array(&$this, 'metaboxTranslation'), + $this->hooks['menu_faq'], + 'normal', + 'core'); + + add_screen_option('layout_columns', array('max' => 2, 'default' => 2)); - // This box can't be unselectd in the the Screen Options - //add_meta_box('avhecBoxAnnouncements', __('Announcements', 'avh-ec'), array ( &$this, 'metaboxAnnouncements' ), $this->hooks['menu_overview'], 'side', ''); - add_meta_box('avhecBoxDonations', __('Donations', 'avh-ec'), array ( &$this, 'metaboxDonations' ), $this->hooks['menu_overview'], 'side', ''); + // WordPress core Styles and Scripts + wp_enqueue_script('common'); + wp_enqueue_script('wp-lists'); + wp_enqueue_script('postbox'); - $hide2 = ''; - switch ($screen_layout_columns) { - case 2: - $width = 'width:49%;'; - break; - default: - $width = 'width:98%;'; - $hide2 = 'display:none;'; - } + // Plugin Style + wp_enqueue_style('avhec-admin-css'); + } - echo '<div class="wrap avhec-metabox-wrap">'; - echo $this->displayIcon('index'); - echo '<h2>' . 'AVH Extended Categories - ' . __('Overview', 'avh-ec') . '</h2>'; - echo ' <div id="dashboard-widgets-wrap">'; - echo ' <div id="dashboard-widgets" class="metabox-holder">'; - echo ' <div class="postbox-container" style="' . $width . '">' . "\n"; - do_meta_boxes($this->hooks['menu_overview'], 'normal', ''); - echo " </div>"; - echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n"; - do_meta_boxes($this->hooks['menu_overview'], 'side', ''); - echo ' </div>'; - echo ' </div>'; + /** + * Enqueues the style on the post.php and page.php pages + * + * @WordPress Action load-$pagenow + */ + function actionLoadPostPage() { + wp_enqueue_style('avhec-admin-css'); + } - echo '<br class="clear"/>'; - echo ' </div>'; //dashboard-widgets-wrap - echo '</div>'; // wrap + /** + * Ajax Helper: inline delete of the groups + */ + function ajaxDeleteGroup() { + $group_id = isset($_POST['id']) ? (int) $_POST['id'] : 0; + check_ajax_referer('delete-avhecgroup_' . $group_id); + if ( ! current_user_can('manage_categories')) { + die('-1'); + } + $check = $this->catgrp->getGroup($group_id); + if (false === $check) { + die('1'); + } - $this->printMetaboxGeneralNonces(); - $this->printMetaboxJS('overview'); - $this->printAdminFooter(); + if ($this->catgrp->doDeleteGroup($group_id)) { + die('1'); + } else { + die('0'); + } } /** - * Setup everything needed for the General Options page + * Adds Category Group form * + * @WordPress action category_edit_form + * + * @param unknown_type $term + * @param unknown_type $taxonomy */ - function actionLoadPageHook_General () - { - // Add metaboxes - add_meta_box('avhecBoxOptions', __('Options', 'avh-ec'), array ( &$this, 'metaboxOptions' ), $this->hooks['menu_general'], 'normal', 'core'); + function displayCategoryGroupForm($term, $taxonomy) { - add_screen_option('layout_columns', array ( 'max' => 2, 'default' => 2 )); + $current_selection = ''; + $tax_meta = get_option($this->core->db_options_tax_meta); + if (isset($tax_meta[ $taxonomy ][ $term->term_id ])) { + $tax_meta = $tax_meta[ $taxonomy ][ $term->term_id ]; + $current_selection = $tax_meta['category_group_term_id']; + } - // WordPress core Scripts - wp_enqueue_script('common'); - wp_enqueue_script('wp-lists'); - wp_enqueue_script('postbox'); + if (empty($current_selection)) { + $current_group = $this->catgrp->getGroupByCategoryID($term->term_id); + $current_selection = $current_group->term_id; + } - // Plugin Style and Scripts - wp_enqueue_style('avhec-admin-css'); + $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false)); + foreach ($cat_groups as $group) { + $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit'); + $dropdown_value[] = $group->term_id; + $dropdown_text[] = $temp_cat->name; + } + foreach ($dropdown_value as $key => $sel) { + $seldata .= '<option value="' . + esc_attr($sel) . + '" ' . + (($current_selection == $sel) ? 'selected="selected"' : '') . + ' >' . + esc_html(ucfirst($dropdown_text[ $key ])) . + '</option>' . + "\n"; + } + + echo '<h3>AVH Extended Categories - Category Group Widget</h3>'; + echo '<table class="form-table"><tbody>'; + echo '<tr class="form-field">'; + echo '<th valign="top" scope="row">'; + echo '<label for="avhec_categorygroup">Category Group</label></th>'; + echo '<td>'; + echo '<select id="avhec_categorygroup" name="avhec_categorygroup">'; + echo $seldata; + echo '</select>'; + echo '<p class="description">Select the category group to show on the archive page.</p>'; + echo '</td>'; + echo '</tr>'; + echo '</tbody></table>'; } /** - * Menu Page General Options + * Displays the icon on the menu pages * - * @return none + * @param $icon */ - function doMenuGeneral () - { - global $screen_layout_columns; + function displayIcon($icon) { + return ('<div class="icon32" id="icon-' . $icon . '"><br/></div>'); + } - $groups = get_terms($this->catgrp->taxonomy_name, array ( 'hide_empty' => FALSE )); - foreach ($groups as $group) { - $group_id[] = $group->term_id; - $groupname[] = $group->name; + /** + * Display WP alert + */ + function displayMessage() { + if ($this->message != '') { + $message = $this->message; + $status = $this->status; + $this->message = $this->status = ''; // Reset + } + if (isset($message)) { + $status = ($status != '') ? $status : 'updated fade'; + echo '<div id="message" class="' . $status . '">'; + echo '<p><strong>' . $message . '</strong></p></div>'; } + } - $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') ); - $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') ); - $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') ); - $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') ); + /** + * Menu Page Category Group + * + * @return none + */ + function doMenuCategoryGroup() { + global $screen_layout_columns; - if (isset($_POST['updateoptions'])) { - check_admin_referer('avh_ec_generaloptions'); + $data_add_group_default = array('name' => '', 'slug' => '', 'widget_title' => '', 'description' => ''); + $data_add_group_new = $data_add_group_default; + + $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') + ); + $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') + ); + $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') + ); + $options_add_group[] = array( + 'avhec_add_group[add][description]', + __('Description', 'avh-ec'), + 'textarea', + 40, + __('Description is not prominent by default.', 'avh-ec'), + 5 + ); + + $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') + ); + $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') + ); + $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') + ); + $options_edit_group[] = array( + 'avhec_edit_group[edit][description]', + __('Description', 'avh-ec'), + 'textarea', + 40, + __('Description is not prominent by default.', 'avh-ec'), + 5 + ); + $options_edit_group[] = array( + 'avhec_edit_group[edit][categories]', + __('Categories', 'avh-ec'), + 'catlist', + 0, + __('Select categories to be included in the group.', 'avh-ec') + ); - $formoptions = $_POST['avhec']; - $options = $this->core->getOptions(); - - //$all_data = array_merge( $options_general ); - $all_data = $options_general; - foreach ($all_data as $option) { - $section = substr($option[0], strpos($option[0], '[') + 1); - $section = substr($section, 0, strpos($section, '][')); - $option_key = rtrim($option[0], ']'); - $option_key = substr($option_key, strpos($option_key, '][') + 2); - - switch ($section) { - case 'general': - case 'cat_group': - $current_value = $options[$section][$option_key]; - break; - } - // Every field in a form is set except unchecked checkboxes. Set an unchecked checkbox to 0. - $newval = (isset($formoptions[$section][$option_key]) ? esc_attr($formoptions[$section][$option_key]) : 0); - if ($newval != $current_value) { // Only process changed fields. - switch ($section) { - case 'general': - case 'cat_group': - $options[$section][$option_key] = $newval; - break; - } - } - } - $this->core->saveOptions($options); - $this->message = __('Options saved', 'avh-ec'); - $this->status = 'updated fade'; - - } - $this->displayMessage(); - - $actual_options = $this->core->getOptions(); - foreach ($actual_options['cat_group'] as $key => $value) { - if (! (in_array($value, (array) $group_id))) { - $actual_options['cat_group'][$key] = $this->catgrp->getTermIDBy('slug', 'none'); - } - } - - $hide2 = ''; - switch ($screen_layout_columns) { - case 2: - $width = 'width:49%;'; - break; - default: - $width = 'width:98%;'; - $hide2 = 'display:none;'; - } - $data['options_general'] = $options_general; - $data['actual_options'] = $actual_options; - - // This box can't be unselectd in the the Screen Options - add_meta_box('avhecBoxDonations', __('Donations', 'avh-ec'), array ( &$this, 'metaboxDonations' ), $this->hooks['menu_general'], 'side', 'core'); - - $hide2 = ''; - switch ($screen_layout_columns) { - case 2: - $width = 'width:49%;'; - break; - default: - $width = 'width:98%;'; - $hide2 = 'display:none;'; - } - - echo '<div class="wrap avhec-metabox-wrap">'; - echo $this->displayIcon('index'); - echo '<h2>' . 'AVH Extended Categories - ' . __('General Options', 'avh-ec') . '</h2>'; - echo '<form name="avhec-generaloptions" id="avhec-generaloptions" method="POST" action="' . admin_url('admin.php?page=avhec-general') . '" accept-charset="utf-8" >'; - wp_nonce_field('avh_ec_generaloptions'); - - echo ' <div id="dashboard-widgets-wrap">'; - echo ' <div id="dashboard-widgets" class="metabox-holder">'; - echo ' <div class="postbox-container" style="' . $width . '">' . "\n"; - do_meta_boxes($this->hooks['menu_general'], 'normal', $data); - echo " </div>"; - echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n"; - do_meta_boxes($this->hooks['menu_general'], 'side', $data); - echo ' </div>'; - echo ' </div>'; - - echo '<br class="clear"/>'; - echo ' </div>'; //dashboard-widgets-wrap - echo '<p class="submit"><input class="button" type="submit" name="updateoptions" value="' . __('Save Changes', 'avhf-ec') . '" /></p>'; - echo '</form>'; - - echo '</div>'; // wrap - - - $this->printMetaboxGeneralNonces(); - $this->printMetaboxJS('general'); - $this->printAdminFooter(); - } - - /** - * Options Metabox - * - */ - function metaboxOptions ($data) - { - echo $this->printOptions($data['options_general'], $data['actual_options']); - } - - /** - * Setup everything needed for the Category Group page - * - */ - function actionLoadPageHook_CategoryGroup () - { - - // Add metaboxes - add_meta_box('avhecBoxCategoryGroupAdd', __('Add Group', 'avh-ec'), array ( &$this, 'metaboxCategoryGroupAdd' ), $this->hooks['menu_category_groups'], 'normal', 'core'); - add_meta_box('avhecBoxCategoryGroupList', __('Group Overview', 'avh-ec'), array ( &$this, 'metaboxCategoryGroupList' ), $this->hooks['menu_category_groups'], 'side', 'core'); - add_meta_box('avhecBoxCategoryGroupSpecialPages', __('Special Pages', 'avh-ec'), array ( &$this, 'metaboxCategoryGroupSpecialPages' ), $this->hooks['menu_category_groups'], 'normal', 'core'); - - add_screen_option('layout_columns', array ( 'max' => 2, 'default' => 2 )); - - // WordPress core Scripts - wp_enqueue_script('common'); - wp_enqueue_script('wp-lists'); - wp_enqueue_script('postbox'); - - // Plugin Scripts - wp_enqueue_script('avhec-categorygroup-js'); - - // Plugin Style - wp_enqueue_style('avhec-admin-css'); - - } - - /** - * Menu Page Category Group - * - * @return none - */ - function doMenuCategoryGroup () - { - global $screen_layout_columns; - - $data_add_group_default = array ( 'name' => '', 'slug' => '', 'widget_title' => '', 'description' => '' ); - $data_add_group_new = $data_add_group_default; - - $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') ); - $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') ); - $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') ); - $options_add_group[] = array ( 'avhec_add_group[add][description]', __('Description', 'avh-ec'), 'textarea', 40, __('Description is not prominent by default.', 'avh-ec'), 5 ); - - $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') ); - $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') ); - $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') ); - $options_edit_group[] = array ( 'avhec_edit_group[edit][description]', __('Description', 'avh-ec'), 'textarea', 40, __('Description is not prominent by default.', 'avh-ec'), 5 ); - $options_edit_group[] = array ( 'avhec_edit_group[edit][categories]', __('Categories', 'avh-ec'), 'catlist', 0, __('Select categories to be included in the group.', 'avh-ec') ); - - if (isset($_POST['addgroup'])) { - check_admin_referer('avh_ec_addgroup'); + if (isset($_POST['addgroup'])) { + check_admin_referer('avh_ec_addgroup'); $formoptions = $_POST['avhec_add_group']; - $data_add_group_new['name'] = $formoptions['add']['name']; - $data_add_group_new['slug'] = empty($formoptions['add']['slug']) ? sanitize_title($data_add_group_new['name']) : sanitize_title($formoptions['add']['slug']); + $data_add_group_new['name'] = $formoptions['add']['name']; + $data_add_group_new['slug'] = empty($formoptions['add']['slug']) ? sanitize_title($data_add_group_new['name']) : sanitize_title($formoptions['add']['slug']); $data_add_group_new['widget_title'] = $formoptions['add']['widget_title']; - $data_add_group_new['description'] = $formoptions['add']['description']; + $data_add_group_new['description'] = $formoptions['add']['description']; $id = $this->catgrp->getTermIDBy('slug', $data_add_group_new['slug']); - if (! $id) { - $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']); + if ( ! $id) { + $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']); $this->catgrp->setCategoriesForGroup($group_id); - $this->message = __('Category group saved', 'avh-ec'); - $this->status = 'updated fade'; + $this->message = __('Category group saved', 'avh-ec'); + $this->status = 'updated fade'; $data_add_group_new = $data_add_group_default; - } else { - $group = $this->catgrp->getGroup($id); + $group = $this->catgrp->getGroup($id); $this->message = __('Category group conflicts with ', 'avh-ec') . $group->name; $this->message .= '<br />' . __('Same slug is used. ', 'avh-ec'); $this->status = 'error'; - } $this->displayMessage(); } $data_add_group['add'] = $data_add_group_new; - $data['add'] = array ( 'form' => $options_add_group, 'data' => $data_add_group ); + $data['add'] = array('form' => $options_add_group, 'data' => $data_add_group); if (isset($_GET['action'])) { $action = $_GET['action']; switch ($action) { case 'edit': - $group_id = (int) $_GET['group_ID']; - $group = $this->catgrp->getGroup($group_id); + $group_id = (int) $_GET['group_ID']; + $group = $this->catgrp->getGroup($group_id); $widget_title = $this->catgrp->getWidgetTitleForGroup($group_id); - $cats = $this->catgrp->getCategoriesFromGroup($group_id); - - $data_edit_group['edit'] = array ( 'group_id' => $group_id, 'name' => $group->name, 'slug' => $group->slug, 'widget_title' => $widget_title, 'description' => $group->description, 'categories' => $cats ); - $data['edit'] = array ( 'form' => $options_edit_group, 'data' => $data_edit_group ); - - add_meta_box('avhecBoxCategoryGroupEdit', __('Edit Group', 'avh-ec') . ': ' . $group->name, array ( &$this, 'metaboxCategoryGroupEdit' ), $this->hooks['menu_category_groups'], 'normal', 'low'); + $cats = $this->catgrp->getCategoriesFromGroup($group_id); + + $data_edit_group['edit'] = array( + 'group_id' => $group_id, + 'name' => $group->name, + 'slug' => $group->slug, + 'widget_title' => $widget_title, + 'description' => $group->description, + 'categories' => $cats + ); + $data['edit'] = array('form' => $options_edit_group, 'data' => $data_edit_group); + + add_meta_box('avhecBoxCategoryGroupEdit', + __('Edit Group', 'avh-ec') . ': ' . $group->name, + array(&$this, 'metaboxCategoryGroupEdit'), + $this->hooks['menu_category_groups'], + 'normal', + 'low'); break; case 'delete': - if (! isset($_GET['group_ID'])) { + if ( ! isset($_GET['group_ID'])) { wp_redirect($this->getBackLink()); exit(); } @@ -529,7 +573,7 @@ class AVH_EC_Admin $group_id = (int) $_GET['group_ID']; check_admin_referer('delete-avhecgroup_' . $group_id); - if (! current_user_can('manage_categories')) { + if ( ! current_user_can('manage_categories')) { wp_die(__('Cheatin’ uh?')); } $this->catgrp->doDeleteGroup($group_id); @@ -543,15 +587,22 @@ class AVH_EC_Admin if (isset($_POST['editgroup'])) { check_admin_referer('avh_ec_editgroup'); - $formoptions = $_POST['avhec_edit_group']; + $formoptions = $_POST['avhec_edit_group']; $selected_categories = $_POST['post_category']; $group_id = (int) $_POST['avhec-group_id']; - $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']); + $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']); switch ($result) { case 1: $this->message = __('Category group updated', 'avh-ec'); - $this->status = 'updated fade'; + $this->status = 'updated fade'; break; case 0: $this->message = __('Category group not updated', 'avh-ec'); @@ -560,7 +611,7 @@ class AVH_EC_Admin break; case - 1: $this->message = __('Unknown category group', 'avh-ec'); - $this->status = 'error'; + $this->status = 'error'; break; } $this->displayMessage(); @@ -582,36 +633,76 @@ class AVH_EC_Admin check_admin_referer('avh_ec_specialpagesgroup'); $formoptions = $_POST['avhec_special_pages']; - $formdata = $formoptions['sp']; + $formdata = $formoptions['sp']; foreach ($formdata as $key => $value) { - $data_special_pages_new[$key] = $value; + $data_special_pages_new[ $key ] = $value; } $this->core->options['sp_cat_group'] = $data_special_pages_new; $this->core->saveOptions($this->core->options); - } $data_special_pages['sp'] = $data_special_pages_new; - $cat_groups = get_terms($this->catgrp->taxonomy_name, array ( 'hide_empty' => FALSE )); + $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false)); foreach ($cat_groups as $group) { - $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit'); + $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit'); $dropdown_value[] = $group->term_id; - $dropdown_text[] = $temp_cat->name; + $dropdown_text[] = $temp_cat->name; } - $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')) ); + $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')) + ); //$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'))); - $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')) ); - $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')) ); - $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')) ); - $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')) ); - $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')) ); - - $data['sp'] = array ( 'form' => $options_special_pages, 'data' => $data_special_pages ); + $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')) + ); + $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')) + ); + $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')) + ); + $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')) + ); + $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')) + ); + + $data['sp'] = array('form' => $options_special_pages, 'data' => $data_special_pages); // This box can't be unselectd in the the Screen Options //add_meta_box( 'avhecBoxDonations', __( 'Donations', 'avh-ec' ), array (&$this, 'metaboxDonations' ), $this->hooks['menu_category_groups'], 'side', 'core' ); - echo '<div class="wrap avhec-metabox-wrap">'; echo $this->displayIcon('index'); echo '<h2>' . 'AVH Extended Categories - ' . __('Category Groups', 'avh-ec') . '</h2>'; @@ -632,119 +723,28 @@ class AVH_EC_Admin echo ' </div>'; //dashboard-widgets-wrap echo '</div>'; // wrap - $this->printMetaboxGeneralNonces(); $this->printMetaboxJS('grouped'); $this->printAdminFooter(); } /** - * Metabox for Adding a group - * @param $data - */ - function metaboxCategoryGroupAdd ($data) - { - echo '<form name="avhec-addgroup" id="avhec-addgroup" method="POST" action="' . $this->getBackLink() . '" accept-charset="utf-8" >'; - wp_nonce_field('avh_ec_addgroup'); - echo $this->printOptions($data['add']['form'], $data['add']['data']); - echo '<p class="submit"><input class="button" type="submit" name="addgroup" value="' . __('Add group', 'avh-ec') . '" /></p>'; - echo '</form>'; - } - - /** - * Metabox for showing the groups as a list - * - * @param $data - */ - function metaboxCategoryGroupList ($data) - { - echo '<form id="posts-filter" action="" method="get">'; - - echo '<div class="clear"></div>'; - - echo '<table class="widefat fixed" cellspacing="0">'; - echo '<thead>'; - echo '<tr>'; - print_column_headers('categories_group'); - echo '</tr>'; - echo '</thead>'; - - echo '<tfoot>'; - echo '<tr>'; - print_column_headers('categories_group', false); - echo '</tr>'; - echo '</tfoot>'; - - echo '<tbody id="the-list" class="list:group">'; - $this->printCategoryGroupRows(); - echo '</tbody>'; - echo '</table>'; - - echo '<br class="clear" />'; - echo '</form>'; - - //echo '</div>'; - } - - /** - * Metabox Category Group Edit - * - */ - function metaboxCategoryGroupEdit ($data) - { - echo '<form name="avhec-editgroup" id="avhec-editgroup" method="POST" action="' . $this->getBackLink() . '" accept-charset="utf-8" >'; - wp_nonce_field('avh_ec_editgroup'); - echo $this->printOptions($data['edit']['form'], $data['edit']['data']); - echo '<input type="hidden" value="' . $data['edit']['data']['edit']['group_id'] . '" name="avhec-group_id" id="avhec-group_id">'; - echo '<p class="submit"><input class="button" type="submit" name="editgroup" value="' . __('Update group', 'avh-ec') . '" /></p>'; - echo '</form>'; - } - - /** - * Metabox Category Group Special pages - * - */ - function metaboxCategoryGroupSpecialPages ($data) - { - echo '<form name="avhec-specialpagesgroup" id="avhec-specialpagesgroup" method="POST" action="' . $this->getBackLink() . '" accept-charset="utf-8" >'; - wp_nonce_field('avh_ec_specialpagesgroup'); - echo $this->printOptions($data['sp']['form'], $data['sp']['data']); - echo '<p class="submit"><input class="button" type="submit" name="spgroup" value="' . __('Save settings', 'avh-ec') . '" /></p>'; - echo '</form>'; - } - - /** - * Setup everything needed for the Manul Order page - * - */ - function actionLoadPageHook_ManualOrder () - { - - add_meta_box('avhecBoxManualOrder', __('Manually Order Categories', 'avh-ec'), array ( &$this, 'metaboxManualOrder' ), $this->hooks['menu_manual_order'], 'normal', 'core'); - - add_screen_option('layout_columns', array ( 'max' => 1, 'default' => 1 )); - - // WordPress core Styles and Scripts - wp_enqueue_script('common'); - wp_enqueue_script('wp-lists'); - wp_enqueue_script('postbox'); - wp_enqueue_script('jquery-ui-sortable'); - wp_enqueue_script('avhec-manualorder'); - - // Plugin Style - wp_enqueue_style('avhec-admin-css'); - - } - - /** - * Menu Page Manual Order + * Menu Page FAQ * * @return none */ - function doMenuManualOrder () - { + function doMenuFAQ() { global $screen_layout_columns; + // This box can't be unselectd in the the Screen Options + // add_meta_box('avhecBoxAnnouncements', __('Announcements', 'avh-ec'), array ( &$this, 'metaboxAnnouncements' ), $this->hooks['menu_faq'], 'side', 'core'); + add_meta_box('avhecBoxDonations', + __('Donations', 'avh-ec'), + array(&$this, 'metaboxDonations'), + $this->hooks['menu_faq'], + 'side', + 'core'); + $hide2 = ''; switch ($screen_layout_columns) { case 2: @@ -755,155 +755,236 @@ class AVH_EC_Admin $hide2 = 'display:none;'; } - echo '<div class="wrap">'; + echo '<div class="wrap avhec-metabox-wrap">'; echo $this->displayIcon('index'); - echo '<h2>' . 'AVH Extended Categories - ' . __('Manually Order Categories', 'avh-ec') . '</h2>'; - - echo '<div class="metabox-holder">'; + echo '<h2>' . 'AVH Extended Categories - ' . __('F.A.Q', 'avh-ec') . '</h2>'; + echo ' <div id="dashboard-widgets-wrap">'; + echo ' <div id="dashboard-widgets" class="metabox-holder">'; echo ' <div class="postbox-container" style="' . $width . '">' . "\n"; - do_meta_boxes($this->hooks['menu_manual_order'], 'normal', ''); + do_meta_boxes($this->hooks['menu_faq'], 'normal', ''); echo ' </div>'; - echo '</div>'; + echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n"; + do_meta_boxes($this->hooks['menu_faq'], 'side', ''); + echo ' </div>'; + echo ' </div>'; + echo '<br class="clear"/>'; + echo ' </div>'; //dashboard-widgets-wrap echo '</div>'; // wrap - echo '<div class="clear"></div>'; $this->printMetaboxGeneralNonces(); - $this->printMetaboxJS('manual_order'); + $this->printMetaboxJS('faq'); $this->printAdminFooter(); } /** + * Menu Page General Options * - * Displays the Manual Order metabox. - * - * @author Andrew Charlton - original - * @author Peter van der Does - modifications + * @return none */ - function metaboxManualOrder () - { - global $wpdb; - - $parentID = 0; + function doMenuGeneral() { + global $screen_layout_columns; - if (isset($_POST['btnSubCats'])) { - $parentID = $_POST['cats']; - } elseif (isset($_POST['hdnParentID'])) { - $parentID = $_POST['hdnParentID']; + $groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false)); + foreach ($groups as $group) { + $group_id[] = $group->term_id; + $groupname[] = $group->name; } - if (isset($_POST['btnReturnParent'])) { - $parentsParent = $wpdb->get_row($wpdb->prepare("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = %d", $_POST['hdnParentID']), ARRAY_N); - $parentID = $parentsParent[0]; - } + $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') + ); + $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') + ); + $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') + ); + $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') + ); - $success = ""; - if (isset($_POST['btnOrderCats'])) { - if (isset($_POST['hdnManualOrder']) && $_POST['hdnManualOrder'] != "") { + if (isset($_POST['updateoptions'])) { + check_admin_referer('avh_ec_generaloptions'); - $manualOrder = $_POST['hdnManualOrder']; - $IDs = explode(",", $manualOrder); - $result = count($IDs); + $formoptions = $_POST['avhec']; + $options = $this->core->getOptions(); - for ($i = 0; $i < $result; $i ++) { - $str = str_replace("id_", "", $IDs[$i]); - $wpdb->query($wpdb->prepare("UPDATE $wpdb->terms SET avhec_term_order = %d WHERE term_id =%d", $i, $str)); - } + //$all_data = array_merge( $options_general ); + $all_data = $options_general; + foreach ($all_data as $option) { + $section = substr($option[0], strpos($option[0], '[') + 1); + $section = substr($section, 0, strpos($section, '][')); + $option_key = rtrim($option[0], ']'); + $option_key = substr($option_key, strpos($option_key, '][') + 2); - $success = '<div id="message" class="updated fade"><p>' . __('Manual order of the categories successfully updated.', 'avh-ec') . '</p></div>'; - } else { - $success = '<div id="message" class="updated fade"><p>' . __('An error occured, order has not been saved.', 'avh-ec') . '</p></div>'; + switch ($section) { + case 'general': + case 'cat_group': + $current_value = $options[ $section ][ $option_key ]; + break; + } + // Every field in a form is set except unchecked checkboxes. Set an unchecked checkbox to 0. + $newval = (isset($formoptions[ $section ][ $option_key ]) ? esc_attr($formoptions[ $section ][ $option_key ]) : 0); + if ($newval != $current_value) { // Only process changed fields. + switch ($section) { + case 'general': + case 'cat_group': + $options[ $section ][ $option_key ] = $newval; + break; + } + } } - + $this->core->saveOptions($options); + $this->message = __('Options saved', 'avh-ec'); + $this->status = 'updated fade'; } + $this->displayMessage(); - $subCategories = ""; - $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)); - foreach ($results as $row) { - $subCategories .= "<option value='$row->term_id'>$row->name</option>"; + $actual_options = $this->core->getOptions(); + foreach ($actual_options['cat_group'] as $key => $value) { + if ( ! (in_array($value, (array) $group_id))) { + $actual_options['cat_group'][ $key ] = $this->catgrp->getTermIDBy('slug', 'none'); + } } - echo '<div class="wrap">'; - echo '<form name="frmMyCatOrder" method="post" action="">'; - echo $success; - - echo '<h4>'; - _e('Order the categories', 'avh-ec'); - if ($parentID == 0) { - echo ' at the Toplevel'; - } else { - $categories = get_category_parents($parentID, false, ' » '); - echo ' in the category ' . trim($categories, ' » '); + $hide2 = ''; + switch ($screen_layout_columns) { + case 2: + $width = 'width:49%;'; + break; + default: + $width = 'width:98%;'; + $hide2 = 'display:none;'; } - echo '</h4>'; - echo '<span class="description">'; - _e('Order the categories on this level by dragging and dropping them into the desired order.', 'avh-ec'); - echo '</span>'; - echo '<ul id="avhecManualOrder">'; - $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)); - foreach ($results as $row) - echo "<li id='id_$row->term_id' class='lineitem menu-item-settings'>" . __($row->name) . "</li>"; + $data['options_general'] = $options_general; + $data['actual_options'] = $actual_options; - echo '</ul>'; - echo '<input type="submit" name="btnOrderCats" id="btnOrderCats" class="button-primary" value="' . __('Save Order', 'avh-ec') . '" onclick="javascript:orderCats(); return true;" />'; + // This box can't be unselectd in the the Screen Options + add_meta_box('avhecBoxDonations', + __('Donations', 'avh-ec'), + array(&$this, 'metaboxDonations'), + $this->hooks['menu_general'], + 'side', + 'core'); - if ($parentID != 0) { - echo "<input type='submit' class='button' id='btnReturnParent' name='btnReturnParent' value='" . __('Return to parent category', 'avh-ec') . "' />"; + $hide2 = ''; + switch ($screen_layout_columns) { + case 2: + $width = 'width:49%;'; + break; + default: + $width = 'width:98%;'; + $hide2 = 'display:none;'; } - echo '<strong id="updateText"></strong><br /><br />'; - if ($subCategories != "") { + echo '<div class="wrap avhec-metabox-wrap">'; + echo $this->displayIcon('index'); + echo '<h2>' . 'AVH Extended Categories - ' . __('General Options', 'avh-ec') . '</h2>'; + echo '<form name="avhec-generaloptions" id="avhec-generaloptions" method="POST" action="' . + admin_url('admin.php?page=avhec-general') . + '" accept-charset="utf-8" >'; + wp_nonce_field('avh_ec_generaloptions'); - echo '<h4>'; - _e('Select Subcategory', 'avh-ec'); - echo '</h4>'; - echo '<select id="cats" name="cats">'; - echo $subCategories; + echo ' <div id="dashboard-widgets-wrap">'; + echo ' <div id="dashboard-widgets" class="metabox-holder">'; + echo ' <div class="postbox-container" style="' . $width . '">' . "\n"; + do_meta_boxes($this->hooks['menu_general'], 'normal', $data); + echo " </div>"; + echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n"; + do_meta_boxes($this->hooks['menu_general'], 'side', $data); + echo ' </div>'; + echo ' </div>'; - echo '</select><input type="submit" name="btnSubCats" class="button" id="btnSubCats" value="' . __('Select', 'avh-ec') . '" />'; - echo '<span class="description">'; - _e('Choose a category from the drop down to order the subcategories in that category.', 'avh-ec'); - echo '</span>'; - } + echo '<br class="clear"/>'; + echo ' </div>'; //dashboard-widgets-wrap + echo '<p class="submit"><input class="button" type="submit" name="updateoptions" value="' . + __('Save Changes', 'avhf-ec') . + '" /></p>'; + echo '</form>'; - echo '<input type="hidden" id="hdnManualOrder" name="hdnManualOrder" />'; - echo '<input type="hidden" id="hdnParentID" name="hdnParentID" value="' . $parentID . '" /></form>'; - echo '</div>'; + echo '</div>'; // wrap + + $this->printMetaboxGeneralNonces(); + $this->printMetaboxJS('general'); + $this->printAdminFooter(); } /** - * Setup everything needed for the FAQ page + * Menu Page Manual Order * + * @return none */ - function actionLoadPageHook_faq () - { - - add_meta_box('avhecBoxFAQ', __('F.A.Q.', 'avh-ec'), array ( &$this, 'metaboxFAQ' ), $this->hooks['menu_faq'], 'normal', 'core'); - add_meta_box('avhecBoxTranslation', __('Translation', 'avh-ec'), array ( &$this, 'metaboxTranslation' ), $this->hooks['menu_faq'], 'normal', 'core'); + function doMenuManualOrder() { + global $screen_layout_columns; - add_screen_option('layout_columns', array ( 'max' => 2, 'default' => 2 )); + $hide2 = ''; + switch ($screen_layout_columns) { + case 2: + $width = 'width:49%;'; + break; + default: + $width = 'width:98%;'; + $hide2 = 'display:none;'; + } - // WordPress core Styles and Scripts - wp_enqueue_script('common'); - wp_enqueue_script('wp-lists'); - wp_enqueue_script('postbox'); + echo '<div class="wrap">'; + echo $this->displayIcon('index'); + echo '<h2>' . 'AVH Extended Categories - ' . __('Manually Order Categories', 'avh-ec') . '</h2>'; - // Plugin Style - wp_enqueue_style('avhec-admin-css'); + echo '<div class="metabox-holder">'; + echo ' <div class="postbox-container" style="' . $width . '">' . "\n"; + do_meta_boxes($this->hooks['menu_manual_order'], 'normal', ''); + echo ' </div>'; + echo '</div>'; + echo '</div>'; // wrap + echo '<div class="clear"></div>'; + $this->printMetaboxGeneralNonces(); + $this->printMetaboxJS('manual_order'); + $this->printAdminFooter(); } /** - * Menu Page FAQ + * Menu Page Overview * * @return none */ - function doMenuFAQ () - { + function doMenuOverview() { global $screen_layout_columns; // This box can't be unselectd in the the Screen Options - // add_meta_box('avhecBoxAnnouncements', __('Announcements', 'avh-ec'), array ( &$this, 'metaboxAnnouncements' ), $this->hooks['menu_faq'], 'side', 'core'); - add_meta_box('avhecBoxDonations', __('Donations', 'avh-ec'), array ( &$this, 'metaboxDonations' ), $this->hooks['menu_faq'], 'side', 'core'); + //add_meta_box('avhecBoxAnnouncements', __('Announcements', 'avh-ec'), array ( &$this, 'metaboxAnnouncements' ), $this->hooks['menu_overview'], 'side', ''); + add_meta_box('avhecBoxDonations', + __('Donations', 'avh-ec'), + array(&$this, 'metaboxDonations'), + $this->hooks['menu_overview'], + 'side', + ''); $hide2 = ''; switch ($screen_layout_columns) { @@ -917,121 +998,330 @@ class AVH_EC_Admin echo '<div class="wrap avhec-metabox-wrap">'; echo $this->displayIcon('index'); - echo '<h2>' . 'AVH Extended Categories - ' . __('F.A.Q', 'avh-ec') . '</h2>'; + echo '<h2>' . 'AVH Extended Categories - ' . __('Overview', 'avh-ec') . '</h2>'; echo ' <div id="dashboard-widgets-wrap">'; echo ' <div id="dashboard-widgets" class="metabox-holder">'; echo ' <div class="postbox-container" style="' . $width . '">' . "\n"; - do_meta_boxes($this->hooks['menu_faq'], 'normal', ''); - echo ' </div>'; + do_meta_boxes($this->hooks['menu_overview'], 'normal', ''); + echo " </div>"; echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n"; - do_meta_boxes($this->hooks['menu_faq'], 'side', ''); + do_meta_boxes($this->hooks['menu_overview'], 'side', ''); echo ' </div>'; echo ' </div>'; + echo '<br class="clear"/>'; echo ' </div>'; //dashboard-widgets-wrap echo '</div>'; // wrap - $this->printMetaboxGeneralNonces(); - $this->printMetaboxJS('faq'); + $this->printMetaboxJS('overview'); $this->printAdminFooter(); } /** - * Translation Metabox - * @return unknown_type + * When not using AJAX, this function is called when the deletion fails. + * + * @param string $text + * @param int $group_id + * + * @return string + * @WordPress Filter explain_nonce_$verb-$noun + * @see wp_explain_nonce */ - function metaboxTranslation () - { - $locale = apply_filters('plugin_locale', get_locale(), 'avh-ec'); - $available_locale['cs_CZ'] = array ( 'Czech - Čeština', 0 ); - $available_locale['nl_NL'] = array ( 'Dutch - Nederlands', 0 ); - $available_locale['de_DE'] = array ( 'German - Deutsch', 0 ); - $available_locale['el'] = array ( 'Greek - Čeština', 0 ); - $available_locale['id_ID'] = array ( 'Indonesian - Bahasa Indonesia - Čeština', 0 ); - $available_locale['it_IT'] = array ( 'Italian - Italiano', 1 ); - $available_locale['ru_RU'] = array ( 'Russian — Русский', 0 ); - $available_locale['es_ES'] = array ( 'Spanish - Español', 0 ); - $available_locale['sv_SE'] = array ( 'Swedish - Svenska', 0 ); - $available_locale['tr'] = array ( 'Turkish - Türkçe', 0 ); + function filterExplainNonceDeleteGroup($text, $group_id) { + $group = get_term($group_id, $this->catgrp->taxonomy_name, OBJECT, 'display'); - echo '<div class="p">'; - 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 />'; + $return = sprintf(__('Your attempt to delete this group: “%s” has failed.'), $group->name); - echo '</div>'; + return ($return); + } - echo '<div class="p">'; - echo '<span class="b">' . __('Available Languages', 'avh-ec') . '</span>'; - echo '<ul>'; - foreach ($available_locale as $key => $value) { - echo '<li>'; - $complete = ($value[1] == 1 ? 'Complete' : 'Incomplete'); - echo $value[0] . ' (' . $key . ') - ' . $complete; - echo '</li>'; + /** + * Creates a new array for columns headers. Used in print_column_headers. The filter is called from + * get_column_headers + * + * @param $columns + * + * @return Array + * @see print_column_headers, get_column_headers + */ + function filterManageCategoriesGroupColumns($columns) { + $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') + ); + + return $categories_group_columns; + } + + /** + * Adds Settings next to the plugin actions + * + * @WordPress Filter plugin_action_links_avh-amazon/avh-amazon.php + */ + function filterPluginActions($links, $file) { + $settings_link = '<a href="admin.php?page=extended-categories-widget">' . __('Settings', 'avh-ec') . '</a>'; + array_unshift($links, $settings_link); // before other links + return $links; + } + + /** + * Sets the amount of columns wanted for a particuler screen + * + * @WordPress filter screen_meta_screen + * + * @param $screen + * + * @return strings + */ + + function filterScreenLayoutColumns($columns, $screen) { + switch ($screen) { + case $this->hooks['menu_overview']: + $columns[ $this->hooks['menu_overview'] ] = 2; + break; + case $this->hooks['menu_general']: + $columns[ $this->hooks['menu_general'] ] = 2; + break; + case $this->hooks['menu_category_groups']: + $columns[ $this->hooks['menu_category_groups'] ] = 2; + break; + case $this->hooks['menu_faq']: + $columns[ $this->hooks['menu_faq'] ] = 2; + break; } - echo '</ul>'; - echo '</div>'; + return $columns; + } + + /** + * Get the backlink for forms + * + * @return string + */ + function getBackLink() { + $page = basename(__FILE__); + if (isset($_GET['page']) && ! empty($_GET['page'])) { + $page = preg_replace('[^a-zA-Z0-9\.\_\-]', '', $_GET['page']); + } + + if (function_exists("admin_url")) { + return admin_url(basename($_SERVER["PHP_SELF"])) . "?page=" . $page; + } else { + return $_SERVER['PHP_SELF'] . "?page=" . $page; + } + } + + /** + * Saves the association Category - Category Group fron the edit taxonomy page + * + * @WordPress action edit_form. + * + * @param unknown_type $term_id + * @param unknown_type $tt_id + * @param unknown_type $taxonomy + */ + function handleEditTerm($term_id, $tt_id, $taxonomy) { + $tax_meta = get_option($this->core->db_options_tax_meta); + if (isset($_POST['avhec_categorygroup']) && + isset($tax_meta[ $taxonomy ][ $term_id ]['category_group_term_id']) && + $tax_meta[ $taxonomy ][ $term_id ]['category_group_term_id'] != $_POST['avhec_categorygroup'] + ) { + $tax_meta[ $taxonomy ][ $term_id ]['category_group_term_id'] = $_POST['avhec_categorygroup']; + update_option($this->core->db_options_tax_meta, $tax_meta); + } + } + + /** + * Used in forms to set an option checked + * + * @param mixed $checked + * @param mixed $current + * + * @return string + */ + function isChecked($checked, $current) { + $return = ''; + if ($checked == $current) { + $return = ' checked="checked"'; + } + + return $return; + } + + function metaboxAnnouncements() { + $php5 = version_compare('5.2', phpversion(), '<'); echo '<div class="p">'; - if ('en_US' != $locale & (! array_key_exists($locale, $available_locale))) { - 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.'; + echo '<span class="b">' . __('PHP4 Support', 'avh-ec') . '</span><br />'; + echo __('The next major release of the plugin will no longer support PHP4.', 'avh-ec') . '<br />'; + echo __('It will be written for PHP 5.2 and ', 'avh-ec'); + if ($php5) { + echo __('your blog already runs the needed PHP version. When the new release comes out you can safely update.', + 'avh-ec') . '<br />'; } else { - 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.'; + echo __('your blog still runs PHP4. When the new release comes out you can not use it.', 'avh-ec') . + '<br />'; + 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 />'; + echo __('If your hosts doesn\'t offer PHP 5.2 you might want to consider switching hosts.', 'avh-ec') . + '<br />'; + echo __('A host to consider is ', 'avh-ec') . + '<a href="http://www.lunarpages.com/id/pdoes" target="_blank">Lunarpages</a>'; + 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'); } echo '</div>'; + } + /** + * Metabox for Adding a group + * + * @param $data + */ + function metaboxCategoryGroupAdd($data) { + echo '<form name="avhec-addgroup" id="avhec-addgroup" method="POST" action="' . + $this->getBackLink() . + '" accept-charset="utf-8" >'; + wp_nonce_field('avh_ec_addgroup'); + echo $this->printOptions($data['add']['form'], $data['add']['data']); + echo '<p class="submit"><input class="button" type="submit" name="addgroup" value="' . + __('Add group', 'avh-ec') . + '" /></p>'; + echo '</form>'; + } + + /** + * Metabox Category Group Edit + */ + function metaboxCategoryGroupEdit($data) { + echo '<form name="avhec-editgroup" id="avhec-editgroup" method="POST" action="' . + $this->getBackLink() . + '" accept-charset="utf-8" >'; + wp_nonce_field('avh_ec_editgroup'); + echo $this->printOptions($data['edit']['form'], $data['edit']['data']); + echo '<input type="hidden" value="' . + $data['edit']['data']['edit']['group_id'] . + '" name="avhec-group_id" id="avhec-group_id">'; + echo '<p class="submit"><input class="button" type="submit" name="editgroup" value="' . + __('Update group', 'avh-ec') . + '" /></p>'; + echo '</form>'; + } + + /** + * Metabox for showing the groups as a list + * + * @param $data + */ + function metaboxCategoryGroupList($data) { + echo '<form id="posts-filter" action="" method="get">'; + + echo '<div class="clear"></div>'; + + echo '<table class="widefat fixed" cellspacing="0">'; + echo '<thead>'; + echo '<tr>'; + print_column_headers('categories_group'); + echo '</tr>'; + echo '</thead>'; + + echo '<tfoot>'; + echo '<tr>'; + print_column_headers('categories_group', false); + echo '</tr>'; + echo '</tfoot>'; + + echo '<tbody id="the-list" class="list:group">'; + $this->printCategoryGroupRows(); + echo '</tbody>'; + echo '</table>'; + + echo '<br class="clear" />'; + echo '</form>'; + //echo '</div>'; + } + + /** + * Metabox Category Group Special pages + */ + function metaboxCategoryGroupSpecialPages($data) { + echo '<form name="avhec-specialpagesgroup" id="avhec-specialpagesgroup" method="POST" action="' . + $this->getBackLink() . + '" accept-charset="utf-8" >'; + wp_nonce_field('avh_ec_specialpagesgroup'); + echo $this->printOptions($data['sp']['form'], $data['sp']['data']); + echo '<p class="submit"><input class="button" type="submit" name="spgroup" value="' . + __('Save settings', 'avh-ec') . + '" /></p>'; + echo '</form>'; } + ############## Admin WP Helper ############## + /** * Donation Metabox + * * @return unknown_type */ - function metaboxDonations () - { + function metaboxDonations() { echo '<div class="p">'; - echo __('If you enjoy this plug-in please consider a donation. There are several ways you can show your appreciation.', 'avh-ec'); + echo __('If you enjoy this plug-in please consider a donation. There are several ways you can show your appreciation.', + 'avh-ec'); echo '</div>'; echo '<div class="p">'; echo '<span class="b">Amazon</span><br />'; echo __('If you decide to buy something from Amazon click the button.', 'avh-ec') . '</span><br />'; - 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>'; + echo '<a href="https://www.amazon.com/?tag=petervanderdoes-20" target="_blank" title="Amazon Homepage"><img alt="Amazon Button" src="' . + $this->core->info['graphics_url'] . + '/us_banner_logow_120x60.gif" /></a>'; echo '</div>'; echo '<div class="p">'; - 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>'; + echo __('You can send me something from my ', 'avh-ec') . + '<a href="http://www.amazon.com/registry/wishlist/1U3DTWZ72PI7W?tag=petervanderdoes-20">' . + __('Amazon Wish List', 'avh-ec') . + '</a>'; echo '</div>'; echo '<div class="p">'; echo '<span class="b">' . __('Through Paypal.', 'avh-ec') . '</span><br />'; - 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 />'; + 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 />'; 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">'; echo '<img src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" alt="Donate"/></a>'; echo '</div>'; - } /*** * F.A.Q Metabox + * * @return none */ - function metaboxFAQ () - { + function metaboxFAQ() { echo '<div class="p">'; echo '<span class="b">' . __('What about support?', 'avh-ec') . '</span><br />'; - 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 />'; + 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 />'; echo '</div>'; echo '<div class="p">'; echo '<span class="b">' . __('What is depth selection?', 'avh-ec') . '</span><br />'; - 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 />'; - 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 />'; - 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 />'; + 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 />'; + 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 />'; + 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 />'; echo '</div>'; echo '<div class="p">'; echo '<span class="b">' . __('Multiple Category Groups', 'avh-ec') . '</span><br />'; - echo __('The following is an explanation how assigning multiple groups to page/post works.', 'avh-ec') . '<br /><br />'; + echo __('The following is an explanation how assigning multiple groups to page/post works.', 'avh-ec') . + '<br /><br />'; echo __('Lets say you have the following groups:', 'avh-ec'); echo '<ul>'; echo '<li>' . __('Free Time', 'avh-ec') . '</li>'; @@ -1039,7 +1329,8 @@ class AVH_EC_Admin echo '<li>' . __('Movie', 'avh-ec') . '</li>'; echo '<li>' . __('Music', 'avh-ec') . '</li>'; echo '</ul>'; - echo __('Setup several Category Group widgets and associated each widget with one or more groups.', 'avh-ec') . '<br />'; + echo __('Setup several Category Group widgets and associated each widget with one or more groups.', 'avh-ec') . + '<br />'; echo __('Widget 1 has association with Free Time', 'avh-ec') . '<br />'; echo __('Widget 2 has association with Theater, Movie and Music', 'avh-ec') . '<br />'; echo __('Widget 3 has association with Theater, Movie and Music', 'avh-ec') . '<br /><br />'; @@ -1061,138 +1352,186 @@ class AVH_EC_Admin echo '<li>' . __('Widget 2: Shows categories of the Movie or Music group.', 'avh-ec') . '</li>'; echo '<li>' . __('Widget 3: Shows categories of the Music or Movie group.', 'avh-ec') . '</li>'; echo '</ul>'; - 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 />'; - echo '</div>'; - } - - function metaboxAnnouncements () - { - $php5 = version_compare('5.2', phpversion(), '<'); - echo '<div class="p">'; - echo '<span class="b">' . __('PHP4 Support', 'avh-ec') . '</span><br />'; - echo __('The next major release of the plugin will no longer support PHP4.', 'avh-ec') . '<br />'; - echo __('It will be written for PHP 5.2 and ', 'avh-ec'); - if ($php5) { - echo __('your blog already runs the needed PHP version. When the new release comes out you can safely update.', 'avh-ec') . '<br />'; - } else { - echo __('your blog still runs PHP4. When the new release comes out you can not use it.', 'avh-ec') . '<br />'; - 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 />'; - echo __('If your hosts doesn\'t offer PHP 5.2 you might want to consider switching hosts.', 'avh-ec') . '<br />'; - echo __('A host to consider is ', 'avh-ec') . '<a href="http://www.lunarpages.com/id/pdoes" target="_blank">Lunarpages</a>'; - 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'); - } + 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 />'; echo '</div>'; - } /** - * Sets the amount of columns wanted for a particuler screen + * Displays the Manual Order metabox. * - * @WordPress filter screen_meta_screen - * @param $screen - * @return strings + * @author Andrew Charlton - original + * @author Peter van der Does - modifications */ + function metaboxManualOrder() { + global $wpdb; - function filterScreenLayoutColumns ($columns, $screen) - { - switch ($screen) { - case $this->hooks['menu_overview']: - $columns[$this->hooks['menu_overview']] = 2; - break; - case $this->hooks['menu_general']: - $columns[$this->hooks['menu_general']] = 2; - break; - case $this->hooks['menu_category_groups']: - $columns[$this->hooks['menu_category_groups']] = 2; - break; - case $this->hooks['menu_faq']: - $columns[$this->hooks['menu_faq']] = 2; - break; + $parentID = 0; + if (isset($_POST['btnSubCats'])) { + $parentID = $_POST['cats']; + } elseif (isset($_POST['hdnParentID'])) { + $parentID = $_POST['hdnParentID']; } - return $columns; - } - /** - * Adds Settings next to the plugin actions - * - * @WordPress Filter plugin_action_links_avh-amazon/avh-amazon.php - * - */ - function filterPluginActions ($links, $file) - { - $settings_link = '<a href="admin.php?page=extended-categories-widget">' . __('Settings', 'avh-ec') . '</a>'; - array_unshift($links, $settings_link); // before other links - return $links; + if (isset($_POST['btnReturnParent'])) { + $parentsParent = $wpdb->get_row($wpdb->prepare("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = %d", + $_POST['hdnParentID']), + ARRAY_N); + $parentID = $parentsParent[0]; + } + + $success = ""; + if (isset($_POST['btnOrderCats'])) { + if (isset($_POST['hdnManualOrder']) && $_POST['hdnManualOrder'] != "") { + + $manualOrder = $_POST['hdnManualOrder']; + $IDs = explode(",", $manualOrder); + $result = count($IDs); + + for ($i = 0; $i < $result; $i ++) { + $str = str_replace("id_", "", $IDs[ $i ]); + $wpdb->query($wpdb->prepare("UPDATE $wpdb->terms SET avhec_term_order = %d WHERE term_id =%d", + $i, + $str)); + } + + $success = '<div id="message" class="updated fade"><p>' . + __('Manual order of the categories successfully updated.', 'avh-ec') . + '</p></div>'; + } else { + $success = '<div id="message" class="updated fade"><p>' . + __('An error occured, order has not been saved.', 'avh-ec') . + '</p></div>'; + } + } + + $subCategories = ""; + $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)); + foreach ($results as $row) { + $subCategories .= "<option value='$row->term_id'>$row->name</option>"; + } + + echo '<div class="wrap">'; + echo '<form name="frmMyCatOrder" method="post" action="">'; + echo $success; + + echo '<h4>'; + _e('Order the categories', 'avh-ec'); + if ($parentID == 0) { + echo ' at the Toplevel'; + } else { + $categories = get_category_parents($parentID, false, ' » '); + echo ' in the category ' . trim($categories, ' » '); + } + echo '</h4>'; + echo '<span class="description">'; + _e('Order the categories on this level by dragging and dropping them into the desired order.', 'avh-ec'); + echo '</span>'; + echo '<ul id="avhecManualOrder">'; + $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)); + foreach ($results as $row) { + echo "<li id='id_$row->term_id' class='lineitem menu-item-settings'>" . __($row->name) . "</li>"; + } + + echo '</ul>'; + echo '<input type="submit" name="btnOrderCats" id="btnOrderCats" class="button-primary" value="' . + __('Save Order', 'avh-ec') . + '" onclick="javascript:orderCats(); return true;" />'; + + if ($parentID != 0) { + echo "<input type='submit' class='button' id='btnReturnParent' name='btnReturnParent' value='" . + __('Return to parent category', 'avh-ec') . + "' />"; + } + echo '<strong id="updateText"></strong><br /><br />'; + if ($subCategories != "") { + + echo '<h4>'; + _e('Select Subcategory', 'avh-ec'); + echo '</h4>'; + echo '<select id="cats" name="cats">'; + echo $subCategories; + + echo '</select><input type="submit" name="btnSubCats" class="button" id="btnSubCats" value="' . + __('Select', 'avh-ec') . + '" />'; + echo '<span class="description">'; + _e('Choose a category from the drop down to order the subcategories in that category.', 'avh-ec'); + echo '</span>'; + } + + echo '<input type="hidden" id="hdnManualOrder" name="hdnManualOrder" />'; + echo '<input type="hidden" id="hdnParentID" name="hdnParentID" value="' . $parentID . '" /></form>'; + echo '</div>'; } /** - * Creates a new array for columns headers. Used in print_column_headers. The filter is called from get_column_headers - * - * @param $columns - * @return Array - * @see print_column_headers, get_column_headers + * Options Metabox */ - function filterManageCategoriesGroupColumns ($columns) - { - $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') ); - return $categories_group_columns; + function metaboxOptions($data) { + echo $this->printOptions($data['options_general'], $data['actual_options']); } /** - * When not using AJAX, this function is called when the deletion fails. + * Translation Metabox * - * @param string $text - * @param int $group_id - * @return string - * @WordPress Filter explain_nonce_$verb-$noun - * @see wp_explain_nonce + * @return unknown_type */ - function filterExplainNonceDeleteGroup ($text, $group_id) - { - $group = get_term($group_id, $this->catgrp->taxonomy_name, OBJECT, 'display'); - - $return = sprintf(__('Your attempt to delete this group: “%s” has failed.'), $group->name); - return ($return); - } + function metaboxTranslation() { + $locale = apply_filters('plugin_locale', get_locale(), 'avh-ec'); + $available_locale['cs_CZ'] = array('Czech - Čeština', 0); + $available_locale['nl_NL'] = array('Dutch - Nederlands', 0); + $available_locale['de_DE'] = array('German - Deutsch', 0); + $available_locale['el'] = array('Greek - Čeština', 0); + $available_locale['id_ID'] = array('Indonesian - Bahasa Indonesia - Čeština', 0); + $available_locale['it_IT'] = array('Italian - Italiano', 1); + $available_locale['ru_RU'] = array('Russian — Русский', 0); + $available_locale['es_ES'] = array('Spanish - Español', 0); + $available_locale['sv_SE'] = array('Swedish - Svenska', 0); + $available_locale['tr'] = array('Turkish - Türkçe', 0); - ############## Admin WP Helper ############## + echo '<div class="p">'; + 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 />'; + echo '</div>'; - /** - * Get the backlink for forms - * - * @return strings - */ - function getBackLink () - { - $page = basename(__FILE__); - if (isset($_GET['page']) && ! empty($_GET['page'])) { - $page = preg_replace('[^a-zA-Z0-9\.\_\-]', '', $_GET['page']); + echo '<div class="p">'; + echo '<span class="b">' . __('Available Languages', 'avh-ec') . '</span>'; + echo '<ul>'; + foreach ($available_locale as $key => $value) { + echo '<li>'; + $complete = ($value[1] == 1 ? 'Complete' : 'Incomplete'); + echo $value[0] . ' (' . $key . ') - ' . $complete; + echo '</li>'; } + echo '</ul>'; + echo '</div>'; - if (function_exists("admin_url")) - return admin_url(basename($_SERVER["PHP_SELF"])) . "?page=" . $page; - else - return $_SERVER['PHP_SELF'] . "?page=" . $page; + echo '<div class="p">'; + if ('en_US' != $locale & ( ! array_key_exists($locale, $available_locale))) { + 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.'; + } else { + 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.'; + } + echo '</div>'; } /** - * Print all Category Group rows - * - * @uses printCategoryGroupRow - * + * Display plugin Copyright */ - function printCategoryGroupRows () - { - $cat_groups = get_terms($this->catgrp->taxonomy_name, array ( 'hide_empty' => FALSE )); - - foreach ($cat_groups as $group) { - if ('none' != $group->slug) { - echo $this->printCategoryGroupRow($group->term_id, $group->term_taxonomy_id); - } - } + function printAdminFooter() { + echo '<p class="footer_avhec">'; + 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); + echo '</p>'; } /** @@ -1202,30 +1541,38 @@ class AVH_EC_Admin * @param int $group_term_id * @param int $group_term_taxonomy_id */ - function printCategoryGroupRow ($group_term_id, $group_term_taxonomy_id) - { + function printCategoryGroupRow($group_term_id, $group_term_taxonomy_id) { static $row_class = ''; $group = get_term($group_term_id, $this->catgrp->taxonomy_name, OBJECT, 'display'); - $no_edit[$this->catgrp->getTermIDBy('slug', 'all')] = 0; - $no_delete[$this->catgrp->getTermIDBy('slug', 'all')] = 0; + $no_edit[ $this->catgrp->getTermIDBy('slug', 'all') ] = 0; + $no_delete[ $this->catgrp->getTermIDBy('slug', 'all') ] = 0; if (current_user_can('manage_categories')) { - $actions = array (); - if (! array_key_exists($group->term_id, $no_edit)) { + $actions = array(); + if ( ! array_key_exists($group->term_id, $no_edit)) { $edit_link = "admin.php?page=avhec-grouped&action=edit&group_ID=$group->term_id"; - $edit = "<a class='row-title' href='$edit_link' title='" . esc_attr(sprintf(__('Edit “%s”'), $group->name)) . "'>" . esc_attr($group->name) . '</a><br />'; + $edit = "<a class='row-title' href='$edit_link' title='" . + esc_attr(sprintf(__('Edit “%s”'), $group->name)) . + "'>" . + esc_attr($group->name) . + '</a><br />'; $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>'; } else { $edit = esc_attr($group->name); } - if (! (array_key_exists($group->term_id, $no_delete))) { - $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>"; + if ( ! (array_key_exists($group->term_id, $no_delete))) { + $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>"; } $action_count = count($actions); - $i = 0; + $i = 0; $edit .= '<div class="row-actions">'; foreach ($actions as $action => $link) { ++ $i; @@ -1238,25 +1585,26 @@ class AVH_EC_Admin } $row_class = 'alternate' == $row_class ? '' : 'alternate'; - $qe_data = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit'); + $qe_data = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit'); $output = "<tr id='group-$group->term_id' class='iedit $row_class'>"; $columns = get_column_headers('categories_group'); - $hidden = get_hidden_columns('categories_group'); + $hidden = get_hidden_columns('categories_group'); foreach ($columns as $column_name => $column_display_name) { $class = 'class="' . $column_name . ' column-' . $column_name . '"'; $style = ''; - if (in_array($column_name, $hidden)) + if (in_array($column_name, $hidden)) { $style = ' style="display:none;"'; + } $attributes = $class . $style; switch ($column_name) { case 'cb': $output .= '<th scope="row" class="check-column">'; - if (! (array_key_exists($group->term_id, $no_delete))) { + if ( ! (array_key_exists($group->term_id, $no_delete))) { $output .= '<input type="checkbox" name="delete[]" value="' . $group->term_id . '" />'; } else { $output .= " "; @@ -1272,7 +1620,7 @@ class AVH_EC_Admin break; case 'widget-title': $title = $this->catgrp->getWidgetTitleForGroup($group->term_id); - if (! $title) { + if ( ! $title) { $title = " "; } $output .= '<td ' . $attributes . '>' . $title . '</td>'; @@ -1285,8 +1633,8 @@ class AVH_EC_Admin $output .= "<td $attributes>" . apply_filters('editable_slug', $qe_data->slug) . "</td>"; break; case 'cat-in-group': - $cats = $this->catgrp->getCategoriesFromGroup($group_term_id); - $catname = array (); + $cats = $this->catgrp->getCategoriesFromGroup($group_term_id); + $catname = array(); foreach ($cats as $cat_id) { $catname[] = get_cat_name($cat_id); } @@ -1294,7 +1642,6 @@ class AVH_EC_Admin $cat = implode(', ', $catname); $output .= '<td ' . $attributes . '>' . $cat . '</td>'; break; - } } $output .= '</tr>'; @@ -1302,18 +1649,31 @@ class AVH_EC_Admin return $output; } + /** + * Print all Category Group rows + * + * @uses printCategoryGroupRow + */ + function printCategoryGroupRows() { + $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false)); + + foreach ($cat_groups as $group) { + if ('none' != $group->slug) { + echo $this->printCategoryGroupRow($group->term_id, $group->term_taxonomy_id); + } + } + } + /** * Prints the general nonces, used by the AJAX */ - function printMetaboxGeneralNonces () - { + function printMetaboxGeneralNonces() { echo '<form style="display:none" method="get" action="">'; echo '<p>'; wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); echo '</p>'; echo '</form>'; - } /** @@ -1321,9 +1681,8 @@ class AVH_EC_Admin * * @param $boxid */ - function printMetaboxJS ($boxid) - { - $a = $this->hooks['menu_' . $boxid]; + function printMetaboxJS($boxid) { + $a = $this->hooks[ 'menu_' . $boxid ]; echo '<script type="text/javascript">' . "\n"; echo ' //<![CDATA[' . "\n"; echo ' jQuery(document).ready( function($) {' . "\n"; @@ -1333,87 +1692,108 @@ class AVH_EC_Admin echo ' });' . "\n"; echo ' //]]>' . "\n"; echo '</script>'; - - } - - /** - * Display plugin Copyright - * - */ - function printAdminFooter () - { - echo '<p class="footer_avhec">'; - 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); - echo '</p>'; - } - - /** - * Display WP alert - * - */ - function displayMessage () - { - if ($this->message != '') { - $message = $this->message; - $status = $this->status; - $this->message = $this->status = ''; // Reset - } - if (isset($message)) { - $status = ($status != '') ? $status : 'updated fade'; - echo '<div id="message" class="' . $status . '">'; - echo '<p><strong>' . $message . '</strong></p></div>'; - } } /** * Ouput formatted options * * @param array $option_data + * * @return string */ - function printOptions ($option_data, $option_actual) - { + function printOptions($option_data, $option_actual) { // Generate output $output = ''; $output .= "\n" . '<table class="form-table avhec-options">' . "\n"; foreach ($option_data as $option) { - $section = substr($option[0], strpos($option[0], '[') + 1); - $section = substr($section, 0, strpos($section, '][')); + $section = substr($option[0], strpos($option[0], '[') + 1); + $section = substr($section, 0, strpos($section, '][')); $option_key = rtrim($option[0], ']'); $option_key = substr($option_key, strpos($option_key, '][') + 2); // Helper if ($option[2] == 'helper') { - $output .= '<tr style="vertical-align: top;"><td class="helper" colspan="2">' . wp_filter_post_kses($option[4]) . '</td></tr>' . "\n"; + $output .= '<tr style="vertical-align: top;"><td class="helper" colspan="2">' . + wp_filter_post_kses($option[4]) . + '</td></tr>' . + "\n"; continue; } switch ($option[2]) { case 'checkbox': - $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"; + $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"; $explanation = $option[4]; break; case 'dropdown': $selvalue = $option[3]; - $seltext = $option[4]; - $seldata = ''; + $seltext = $option[4]; + $seldata = ''; foreach ((array) $selvalue as $key => $sel) { - $seldata .= '<option value="' . esc_attr($sel) . '" ' . (($option_actual[$section][$option_key] == $sel) ? 'selected="selected"' : '') . ' >' . esc_html(ucfirst($seltext[$key])) . '</option>' . "\n"; + $seldata .= '<option value="' . + esc_attr($sel) . + '" ' . + (($option_actual[ $section ][ $option_key ] == $sel) ? 'selected="selected"' : '') . + ' >' . + esc_html(ucfirst($seltext[ $key ])) . + '</option>' . + "\n"; } - $input_type = '<select id="' . esc_attr($option[0]) . '" name="' . esc_attr($option[0]) . '">' . $seldata . '</select>' . "\n"; + $input_type = '<select id="' . + esc_attr($option[0]) . + '" name="' . + esc_attr($option[0]) . + '">' . + $seldata . + '</select>' . + "\n"; $explanation = $option[5]; break; case 'text-color': - $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"; + $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"; $explanation = $option[4]; break; case 'textarea': - $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>'; + $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>'; $explanation = $option[4]; break; case 'catlist': ob_start(); echo '<div id="avhec-catlist">'; echo '<ul>'; - wp_category_checklist(0, 0, $option_actual[$section][$option_key]); + wp_category_checklist(0, 0, $option_actual[ $section ][ $option_key ]); echo '</ul>'; echo '</div>'; $input_type = ob_get_contents(); @@ -1422,7 +1802,18 @@ class AVH_EC_Admin break; case 'text': default: - $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"; + $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"; $explanation = $option[4]; break; } @@ -1432,59 +1823,21 @@ class AVH_EC_Admin $extra = '<br /><span class="description">' . wp_filter_kses($explanation) . '</span>' . "\n"; } // Output - $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"; + $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"; } $output .= '</table>' . "\n"; - return $output; - } - - /** - * Used in forms to set an option checked - * - * @param mixed $checked - * @param mixed $current - * @return strings - */ - function isChecked ($checked, $current) - { - $return = ''; - if ($checked == $current) { - $return = ' checked="checked"'; - } - return $return; - } - - /** - * Displays the icon on the menu pages - * - * @param $icon - */ - function displayIcon ($icon) - { - return ('<div class="icon32" id="icon-' . $icon . '"><br/></div>'); - } - - /** - * Ajax Helper: inline delete of the groups - */ - function ajaxDeleteGroup () - { - $group_id = isset($_POST['id']) ? (int) $_POST['id'] : 0; - check_ajax_referer('delete-avhecgroup_' . $group_id); - - if (! current_user_can('manage_categories')) { - die('-1'); - } - $check = $this->catgrp->getGroup($group_id); - if (false === $check) { - die('1'); - } - if ($this->catgrp->doDeleteGroup($group_id)) { - die('1'); - } else { - die('0'); - } + return $output; } } + ?> diff --git a/wp-content/plugins/extended-categories-widget/3.3/class/avh-ec.category-group.php b/wp-content/plugins/extended-categories-widget/3.3/class/avh-ec.category-group.php index c3c01f6948ffd0170a52ac5189733a7d1543519e..7774150cc4f46cd6d8da07e03ce1d136877845ef 100644 --- a/wp-content/plugins/extended-categories-widget/3.3/class/avh-ec.category-group.php +++ b/wp-content/plugins/extended-categories-widget/3.3/class/avh-ec.category-group.php @@ -5,42 +5,29 @@ * * @author Peter van der Does */ -class AVH_EC_Category_Group -{ +class AVH_EC_Category_Group { + var $db_options_widget_titles; + var $options_widget_titles; /** * Taxonomy name + * * @var string */ var $taxonomy_name; - - var $db_options_widget_titles; - - var $options_widget_titles; - var $widget_done_catgroup; - /** - * PHP4 constructor. - * - */ - function AVH_EC_Category_Group () - { - return $this->__construct(); - } - /** * PHP5 Constructor * Init the Database Abstraction layer - * */ - function __construct () - { + function __construct() { global $wpdb; - register_shutdown_function(array ( &$this, '__destruct' )); + register_shutdown_function(array(&$this, '__destruct')); /** * Taxonomy name + * * @var string */ $this->taxonomy_name = 'avhec_catgroup'; @@ -51,16 +38,25 @@ class AVH_EC_Category_Group /** * Create the table if it doesn't exist. - * */ if ($wpdb->get_var('show tables like \'' . $wpdb->avhec_cat_group . '\'') != $wpdb->avhec_cat_group) { - add_action('init', array ( &$this, 'doCreateTable' ), 2); // Priority needs to be the same as the Register Taxonomy + add_action('init', + array(&$this, 'doCreateTable'), + 2); // Priority needs to be the same as the Register Taxonomy } - add_action('init', array ( &$this, 'doRegisterTaxonomy' ), 2); // Priority for registering custom taxonomies is +1 over the creation of the initial taxonomies - add_action('init', array ( &$this, 'doSetupOptions' )); + add_action('init', + array(&$this, 'doRegisterTaxonomy'), + 2); // Priority for registering custom taxonomies is +1 over the creation of the initial taxonomies + add_action('init', array(&$this, 'doSetupOptions')); - add_action('admin_init', array ( &$this, 'addMetaBoxes' )); + add_action('admin_init', array(&$this, 'addMetaBoxes')); + } + /** + * PHP4 constructor. + */ + function AVH_EC_Category_Group() { + return $this->__construct(); } /** @@ -68,65 +64,179 @@ class AVH_EC_Category_Group * * @return bool Always true */ - function __destruct () - { + function __destruct() { return true; } + /** + * Add the metaboxes for the pots and page pages. + * + * @WordPress action admin_init + */ + function addMetaBoxes() { + add_meta_box($this->taxonomy_name . 'div', + __('Category Groups', 'avh-ec'), + 'post_categories_meta_box', + 'post', + 'side', + 'core', + array('taxonomy' => $this->taxonomy_name)); + add_meta_box($this->taxonomy_name . 'div', + __('Category Groups', 'avh-ec'), + 'post_categories_meta_box', + 'page', + 'side', + 'core', + array('taxonomy' => $this->taxonomy_name)); + } + /** * Create Table - * @WordPress action init * + * @WordPress action init */ - function doCreateTable () - { + function doCreateTable() { global $wpdb; // Setup the DB Tables $charset_collate = ''; - if (! empty($wpdb->charset)) { + if ( ! empty($wpdb->charset)) { $charset_collate = 'DEFAULT CHARACTER SET ' . $wpdb->charset; } - if (! empty($wpdb->collate)) { + if ( ! empty($wpdb->collate)) { $charset_collate .= ' COLLATE ' . $wpdb->collate; } - $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 . ';'; + $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 . + ';'; $result = $wpdb->query($sql); } + /** + * Deletes the given category from all groups + * + * @param $category_id + */ + function doDeleteCategoryFromGroup($category_id) { + global $wpdb; + $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE term_id=%d', + $category_id)); + } + + /** + * Deletes a group + * + * @param $group_id + */ + function doDeleteGroup($group_id) { + + global $wpdb; + + $group = $this->getGroup($group_id); + $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE group_term_id=%d', + $group_id)); + $this->doDeleteWidgetTitle($group_id); + $return = wp_delete_term($group->term_id, $this->taxonomy_name); + + return ($return); + } + + /** + * Delete the Widget Title for a group + * + * @param $group_id + */ + function doDeleteWidgetTitle($group_id) { + if (isset($this->options_widget_titles[ $group_id ])) { + unset($this->options_widget_titles[ $group_id ]); + } + update_option($this->db_options_widget_titles, $this->options_widget_titles); + } + + /** + * Inserts a new group + * + * @param $term + * @param array $args + */ + function doInsertGroup($term, $args = array(), $widget_title = '') { + $row = wp_insert_term($term, $this->taxonomy_name, $args); + $this->setWidgetTitleForGroup($term, $widget_title); + + return ($row['term_id']); + } + /** * Setup Group Categories Taxonomy - * @WordPress action init * + * @WordPress action init */ - function doRegisterTaxonomy () - { + function doRegisterTaxonomy() { /** * As we don't want to see the Menu Item we have to disable show_ui. This also disables the metabox on the posts and pages, so we add thse manually instead. * 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. */ - $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') ); - $caps = array ( 'manage_terms' => null, 'edit_terms' => null, 'delete_terms' => null, 'assign_terms' => 'edit_posts' ); - 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 )); - + $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') + ); + $caps = array( + 'manage_terms' => null, + 'edit_terms' => null, + 'delete_terms' => null, + 'assign_terms' => 'edit_posts' + ); + 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 + )); } /** * Setup the options for the widget titles - * @WordPress action init * + * @WordPress action init */ - function doSetupOptions () - { + function doSetupOptions() { // Setup the standard groups if the none group does not exists. $all_categories = $this->getAllCategoriesTermID(); if (false === $this->getTermIDBy('slug', 'none')) { - $none_group_id = wp_insert_term('none', $this->taxonomy_name, array ( 'description' => __('This group will not show the widget.', 'avh-ec') )); - $all_group_id = wp_insert_term('All', $this->taxonomy_name, array ( 'description' => __('Holds all the categories.', 'avh-ec') )); - $home_group_id = wp_insert_term('Home', $this->taxonomy_name, array ( 'description' => __('This group will be shown on the front page.', 'avh-ec') )); + $none_group_id = wp_insert_term('none', + $this->taxonomy_name, + array( + 'description' => __('This group will not show the widget.', 'avh-ec') + )); + $all_group_id = wp_insert_term('All', + $this->taxonomy_name, + array('description' => __('Holds all the categories.', 'avh-ec'))); + $home_group_id = wp_insert_term('Home', + $this->taxonomy_name, + array( + 'description' => __('This group will be shown on the front page.', + 'avh-ec') + )); // Fill the standard groups with all categories $this->setCategoriesForGroup($home_group_id['term_id'], $all_categories); @@ -135,12 +245,12 @@ class AVH_EC_Category_Group } $options = get_option($this->db_options_widget_titles); - if (! $options) { - $options = array (); - $id = $this->getTermIDBy('slug', 'all'); - $options[$id] = ''; - $id = $this->getTermIDBy('slug', 'home'); - $options[$id] = ''; + if ( ! $options) { + $options = array(); + $id = $this->getTermIDBy('slug', 'all'); + $options[ $id ] = ''; + $id = $this->getTermIDBy('slug', 'home'); + $options[ $id ] = ''; update_option($this->db_options_widget_titles, $options); } $this->options_widget_titles = $options; @@ -148,14 +258,30 @@ class AVH_EC_Category_Group } /** - * Add the metaboxes for the pots and page pages. - * @WordPress action admin_init + * Update a group * + * @param $group_id + * @param $selected_categories + * @param $widget_title + * return -1,0,1 Unknown Group, Duplicate Slug, Succesfull */ - function addMetaBoxes () - { - add_meta_box($this->taxonomy_name . 'div', __('Category Groups', 'avh-ec'), 'post_categories_meta_box', 'post', 'side', 'core', array ( 'taxonomy' => $this->taxonomy_name )); - add_meta_box($this->taxonomy_name . 'div', __('Category Groups', 'avh-ec'), 'post_categories_meta_box', 'page', 'side', 'core', array ( 'taxonomy' => $this->taxonomy_name )); + function doUpdateGroup($group_id, $args = array(), $selected_categories, $widget_title = '') { + + $group = $this->getGroup($group_id); + if (is_object($group)) { + $id = wp_update_term($group->term_id, $this->taxonomy_name, $args); + if ( ! is_wp_error($id)) { + $this->setWidgetTitleForGroup($group_id, $widget_title); + $this->setCategoriesForGroup($group_id, $selected_categories); + $return = 1; // Succesful + } else { + $return = 0; // Duplicate Slug + } + } else { + $return = - 1; // Unknown group + } + + return ($return); } /** @@ -163,15 +289,15 @@ class AVH_EC_Category_Group * * @return array Term_id */ - function getAllCategoriesTermID () - { - $all_cat_id = array (); + function getAllCategoriesTermID() { + $all_cat_id = array(); $categories = get_categories(); - if (! is_wp_error($categories)) { + if ( ! is_wp_error($categories)) { foreach ($categories as $category) { $all_cat_id[] = $category->term_id; } } + return ($all_cat_id); } @@ -179,19 +305,23 @@ class AVH_EC_Category_Group * Get the categories from the given group from the DB * * @param int $group_id The Taxonomy Term ID - * @return Array|False categories. Will return FALSE, if the row does not exists. * + * @return Array|False categories. Will return FALSE, if the row does not exists. */ - function getCategoriesFromGroup ($group_id) - { + function getCategoriesFromGroup($group_id) { global $wpdb; // Query database - $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)); + $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)); if (is_array($result)) { // Call succeeded if (empty($result)) { // No rows found - $return = array (); + $return = array(); } else { foreach ($result as $row) { $return[] = $row->term_id; @@ -200,212 +330,135 @@ class AVH_EC_Category_Group } else { $return = false; } + return ($return); } /** - * Set the categories for the given group from the DB. Insert the group if it doesn't exists. + * Gets all information of a group * - * @param int $group_id The Taxonomy Term ID - * @param array $categories The categories - * @return Object (false if not found) + * @param $group_id * + * @return Object|False Returns False when the group doesn't exists. */ - function setCategoriesForGroup ($group_id, $categories = array()) - { + function getGroup($group_id) { global $wpdb; - $old_categories = $this->getCategoriesFromGroup($group_id); - - if (! is_array($categories)) { - $categories = array (); - } - $new_categories = $categories; - sort($old_categories); - sort($new_categories); - // If the new and old values are the same, no need to update. - if ($new_categories === $old_categories) { - return false; - } - - $new = array_diff($new_categories, $old_categories); - $removed = array_diff($old_categories, $new_categories); - - if (! empty($new)) { - foreach ($new as $cat_term_id) { - $insert[] = '(' . $group_id . ',' . $cat_term_id . ')'; - } - $value = implode(',', $insert); - $sql = 'INSERT INTO ' . $wpdb->avhec_cat_group . ' (group_term_id, term_id) VALUES ' . $value; - $result = $wpdb->query($sql); - - } - - if (! empty($removed)) { - $delete = implode(',', $removed); - $sql = $wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE group_term_id=%d and term_id IN (' . $delete . ')', $group_id); - $result = $wpdb->query($sql); - + $result = get_term((int) $group_id, $this->taxonomy_name); + if (null === $result) { + $result = false; } - return $result; + return ($result); } - /** - * Set the Widget Title for a Group - * @param int $group_id - * @param string $widget_title - * - */ - function setWidgetTitleForGroup ($group_id, $widget_title = '') - { - $this->options_widget_titles[$group_id] = $widget_title; - update_option($this->db_options_widget_titles, $this->options_widget_titles); - } + function getGroupByCategoryID($category_id) { + $return = get_term_by('slug', 'none', $this->taxonomy_name); + $cat_groups = get_terms($this->taxonomy_name, array('hide_empty' => false)); - /** - * Return the title for a group_id if exsist otherwise return false - * @param $group_id - * - */ - function getWidgetTitleForGroup ($group_id) - { - if (isset($this->options_widget_titles[$group_id])) { - return ($this->options_widget_titles[$group_id]); + foreach ($cat_groups as $group) { + $cats = $this->getCategoriesFromGroup($group->term_id); + if ($group->slug != 'all' && in_array($category_id, $cats)) { + $return = $group; + break; + } } - return false; - } - /** - * Delete the Widget Title for a group - * - * @param $group_id - */ - function doDeleteWidgetTitle ($group_id) - { - if (isset($this->options_widget_titles[$group_id])) { - unset($this->options_widget_titles[$group_id]); - } - update_option($this->db_options_widget_titles, $this->options_widget_titles); + return $return; } /** * Same as get_term_by, but returns the ID only if found, else false + * * @param string $field * @param string $value + * * @return int|boolean */ - function getTermIDBy ($field, $value) - { + function getTermIDBy($field, $value) { $row = get_term_by($field, $value, $this->taxonomy_name); if (false === $row) { $return = false; } else { $return = (int) $row->term_id; } + return ($return); } /** - * Gets all information of a group + * Return the title for a group_id if exsist otherwise return false * * @param $group_id - * @return Object|False Returns False when the group doesn't exists. */ - function getGroup ($group_id) - { - global $wpdb; - - $result = get_term((int) $group_id, $this->taxonomy_name); - if (null === $result) { - $result = false; + function getWidgetTitleForGroup($group_id) { + if (isset($this->options_widget_titles[ $group_id ])) { + return ($this->options_widget_titles[ $group_id ]); } - return ($result); - } - function getGroupByCategoryID ($category_id) - { - $return = get_term_by('slug', 'none', $this->taxonomy_name); - $cat_groups = get_terms($this->taxonomy_name, array ( 'hide_empty' => FALSE )); - - foreach ($cat_groups as $group) { - $cats = $this->getCategoriesFromGroup($group->term_id); - if ($group->slug != 'all' && in_array($category_id, $cats)) { - $return = $group; - break; - } - } - return $return; + return false; } /** - * Inserts a new group + * Set the categories for the given group from the DB. Insert the group if it doesn't exists. * - * @param $term - * @param array $args - */ - function doInsertGroup ($term, $args = array(), $widget_title = '') - { - $row = wp_insert_term($term, $this->taxonomy_name, $args); - $this->setWidgetTitleForGroup($term, $widget_title); - return ($row['term_id']); - } - - /** - * Deletes a group + * @param int $group_id The Taxonomy Term ID + * @param array $categories The categories * - * @param $group_id + * @return Object (false if not found) */ - function doDeleteGroup ($group_id) - { - + function setCategoriesForGroup($group_id, $categories = array()) { global $wpdb; - $group = $this->getGroup($group_id); - $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE group_term_id=%d', $group_id)); - $this->doDeleteWidgetTitle($group_id); - $return = wp_delete_term($group->term_id, $this->taxonomy_name); + $old_categories = $this->getCategoriesFromGroup($group_id); - return ($return); - } + if ( ! is_array($categories)) { + $categories = array(); + } + $new_categories = $categories; + sort($old_categories); + sort($new_categories); + // If the new and old values are the same, no need to update. + if ($new_categories === $old_categories) { + return false; + } - /** - * Update a group - * - * @param $group_id - * @param $selected_categories - * @param $widget_title - * - * return -1,0,1 Unknown Group, Duplicate Slug, Succesfull - */ - function doUpdateGroup ($group_id, $args = array(), $selected_categories, $widget_title = '') - { + $new = array_diff($new_categories, $old_categories); + $removed = array_diff($old_categories, $new_categories); - $group = $this->getGroup($group_id); - if (is_object($group)) { - $id = wp_update_term($group->term_id, $this->taxonomy_name, $args); - if (! is_wp_error($id)) { - $this->setWidgetTitleForGroup($group_id, $widget_title); - $this->setCategoriesForGroup($group_id, $selected_categories); - $return = 1; // Succesful - } else { - $return = 0; // Duplicate Slug + if ( ! empty($new)) { + foreach ($new as $cat_term_id) { + $insert[] = '(' . $group_id . ',' . $cat_term_id . ')'; } - } else { - $return = - 1; // Unknown group + $value = implode(',', $insert); + $sql = 'INSERT INTO ' . $wpdb->avhec_cat_group . ' (group_term_id, term_id) VALUES ' . $value; + $result = $wpdb->query($sql); } - return ($return); + + if ( ! empty($removed)) { + $delete = implode(',', $removed); + $sql = $wpdb->prepare('DELETE FROM ' . + $wpdb->avhec_cat_group . + ' WHERE group_term_id=%d and term_id IN (' . + $delete . + ')', + $group_id); + $result = $wpdb->query($sql); + } + + return $result; } /** - * Deletes the given category from all groups + * Set the Widget Title for a Group * - * @param $category_id + * @param int $group_id + * @param string $widget_title */ - function doDeleteCategoryFromGroup ($category_id) - { - global $wpdb; - $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE term_id=%d', $category_id)); + function setWidgetTitleForGroup($group_id, $widget_title = '') { + $this->options_widget_titles[ $group_id ] = $widget_title; + update_option($this->db_options_widget_titles, $this->options_widget_titles); } } + ?> diff --git a/wp-content/plugins/extended-categories-widget/3.3/class/avh-ec.core.php b/wp-content/plugins/extended-categories-widget/3.3/class/avh-ec.core.php index f16191c0ef0721069aff70689784791f9c06428d..d15f8e358f96a49bafa2a1d0a2ff841f48eb4258 100644 --- a/wp-content/plugins/extended-categories-widget/3.3/class/avh-ec.core.php +++ b/wp-content/plugins/extended-categories-widget/3.3/class/avh-ec.core.php @@ -1,295 +1,222 @@ <?php -class AVH_EC_Core -{ - var $version; - var $comment; - var $info; - var $db_options_core; - var $default_options; - var $default_options_general; - var $default_options_category_group; - var $default_options_sp_category_group; - - var $db_options_tax_meta; - - var $options; - +/** + * Create HTML list of categories. + * + * @uses Walker + */ +class AVHEC_Walker_Category extends Walker { /** - * PHP5 constructor - * + * @see Walker::$db_fields + * @since 2.1.0 + * @todo Decouple this + * @var array */ - function __construct () - { - /** - * - * @var AVH_EC_Category_Group - */ - $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); - - $this->version = '4.0.1'; - $this->comment = '<!-- AVH Extended Categories version ' . $this->version . ' | http://blog.avirtualhome.com/wordpress-plugins/ -->'; - $this->db_options_core = 'avhec'; - $this->db_options_tax_meta = 'avhec-tax_meta'; - - add_action('init', array ( &$this, 'handleInitializePlugin' ), 10); - } + var $db_fields = array('parent' => 'parent', 'id' => 'term_id'); + /** + * @see Walker::$tree_type + * @since 2.1.0 + * @var string + */ + var $tree_type = 'category'; /** - * PHP4 Constructor + * @see Walker::end_el() + * @since 2.1.0 * - * @return AVHExtendedCategoriesCore + * @param string $output Passed by reference. Used to append additional content. + * @param object $page Not used. + * @param int $depth Depth of category. Not used. + * @param array $args Only uses 'list' for whether should append to output. */ - function AVH_EC_Core () - { - $this->__construct(); - } - - function handleInitializePlugin () - { - global $wpdb; - - $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); - $db_version = 4; - - $info['siteurl'] = get_option('siteurl'); - $info['plugin_dir'] = AVHEC_PLUGIN_DIR; - $info['graphics_url'] = AVHEC_PLUGIN_URL . '/images'; - - // Set class property for info - $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'] ); - - // Set the default options - $this->default_options_general = array ( 'version' => $this->version, 'dbversion' => $db_version, 'alternative_name_select_category' => '' ); - - // Set the default category group options - $no_group_id = $catgrp->getTermIDBy('slug', 'none'); - $home_group_id = $catgrp->getTermIDBy('slug', 'home'); - $default_group_id = $catgrp->getTermIDBy('slug', 'all'); - $this->default_options_category_group = array ( 'no_group' => $no_group_id, 'home_group' => $home_group_id, 'default_group' => $default_group_id ); - - $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 ); - - $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 ); - - /** - * Set the options for the program - * - */ - $this->loadOptions(); - - // Check if we have to do updates - if ((! isset($this->options['general']['dbversion'])) || $this->options['general']['dbversion'] < $db_version) { - $this->doUpdateOptions($db_version); - } - - $db = new AVH_DB(); - if (! $db->field_exists('avhec_term_order', $wpdb->terms)) { - $wpdb->query("ALTER TABLE $wpdb->terms ADD `avhec_term_order` INT( 4 ) NULL DEFAULT '0'"); + function end_el(&$output, $page, $depth, $args) { + if ('list' != $args['style']) { + return; } - $this->handleTextdomain(); - add_filter('get_terms_orderby', array ( &$this, 'applyOrderFilter' ), 10, 2); - - } - - function applyOrderFilter ($orderby, $args) - { - switch ($args['orderby']) { - case 'avhec_manualorder': - $new_orderby = 't.avhec_term_order'; - break; - case 'avhec_3rdparty_mycategoryorder': - $new_orderby = 't.term_order'; - break; - default: - $new_orderby = $orderby; - break; - } - return $new_orderby; + $output .= '</li>' . "\n"; } /** - * Loads the i18n + * @see Walker::end_lvl() + * @since 2.1.0 * - * @return + * @param string $output Passed by reference. Used to append additional content. + * @param int $depth Depth of category. Used for tab indentation. + * @param array $args Will only append content if style argument value is 'list'. */ - function handleTextdomain () - { - - load_plugin_textdomain('avh-ec', false, AVHEC_RELATIVE_PLUGIN_DIR . '/lang'); + function end_lvl(&$output, $depth, $args) { + if ('list' != $args['style']) { + return; + } + $indent = str_repeat("\t", $depth); + $output .= $indent . '</ul>' . "\n"; } /** - * Checks if running version is newer and do upgrades if necessary - * - * @since 1.2.3 + * @see Walker::start_el() + * @since 2.1.0 * + * @param string $output Passed by reference. Used to append additional content. + * @param object $category Category data object. + * @param int $depth Depth of category in reference to parents. + * @param array $args */ - function doUpdateOptions ($db_version) - { - $options = $this->getOptions(); + function start_el(&$output, $category, $depth, $args) { + extract($args); - // Add none existing sections and/or elements to the options - foreach ($this->default_options as $section => $default_data) { - if (! array_key_exists($section, $options)) { - $options[$section] = $default_data; - continue; + $cat_name = esc_attr($category->name); + $cat_name = apply_filters('list_cats', $cat_name, $category); + $link = '<div class="avhec-widget-line"><a href="' . get_category_link($category->term_id) . '" '; + if ($use_desc_for_title == 0 || empty($category->description)) { + $link .= 'title="' . sprintf(__('View all posts filed under %s'), $cat_name) . '"'; + } else { + $link .= 'title="' . + esc_attr(strip_tags(apply_filters('category_description', $category->description, $category))) . + '"'; + } + $link .= '>'; + $link .= $cat_name . '</a>'; + + if (( ! empty($feed_image)) || ( ! empty($feed))) { + $link .= '<div class="avhec-widget-rss"> '; + + if (empty($feed_image)) { + $link .= '('; } - foreach ($default_data as $element => $default_value) { - if (! array_key_exists($element, $options[$section])) { - $options[$section][$element] = $default_value; - } + + $link .= '<a href="' . get_category_feed_link($category->term_id, $feed_type) . '"'; + + if (empty($feed)) { + $alt = ' alt="' . sprintf(__('Feed for all posts filed under %s'), $cat_name) . '"'; + } else { + $title = ' title="' . $feed . '"'; + $alt = ' alt="' . $feed . '"'; + $name = $feed; + $link .= $title; } - } - // Remove none existing sections and/or elements from the options - foreach ($options as $section => $data) { - if (! array_key_exists($section, $this->default_options)) { - unset($options[$section]); - continue; + $link .= '>'; + + if (empty($feed_image)) { + $link .= $name; + } else { + $link .= '<img src="' . $feed_image . '"' . $alt . $title . ' />'; } - foreach ($data as $element => $value) { - if (! array_key_exists($element, $this->default_options[$section])) { - unset($options[$section][$element]); - } + $link .= '</a>'; + if (empty($feed_image)) { + $link .= ')'; } + $link .= '</div>'; } - /** - * Update the options to the latests versions - */ - $options['general']['version'] = $this->version; - $options['general']['dbversion'] = $db_version; - $this->saveOptions($options); - } - /** - * Used in forms to set the checked option. - * - * @param mixed $checked - * @param mixed_type $current - * @return string - * - * @since 2.0 - */ - function isChecked ($checked, $current) - { - if ($checked == $current) { - return (' checked="checked"'); + if (isset($show_count) && $show_count) { + $link .= '<div class="avhec-widget-count"> (' . intval($category->count) . ')</div>'; } - return (''); - } - /** - * Used in forms to set the SELECTED option - * - * @param string $current - * @param string $field - * @return string - */ - function isSelected ($current, $field) - { - if ($current == $field) { - return (' SELECTED'); + if (isset($show_date) && $show_date) { + $link .= ' ' . gmdate('Y-m-d', $category->last_update_timestamp); + } + + if (isset($current_category) && $current_category) { + $_current_category = get_category($current_category); + } + + if ('list' == $args['style']) { + $output .= "\t" . '<li'; + $class = 'cat-item cat-item-' . $category->term_id; + if (isset($current_category) && $current_category && ($category->term_id == $current_category)) { + $class .= ' current-cat'; + } elseif (isset($_current_category) && + $_current_category && + ($category->term_id == $_current_category->parent) + ) { + $class .= ' current-cat-parent'; + } + $output .= ' class="' . $class . '"'; + $output .= '>' . $link . '</div>' . "\n"; + } else { + $output .= "\t" . $link . '</div><br />' . "\n"; } - return (''); } /** - * Get the base directory of a directory structure - * - * @param string $directory - * @return string + * @see Walker::start_lvl() + * @since 2.1.0 * + * @param string $output Passed by reference. Used to append additional content. + * @param int $depth Depth of category. Used for tab indentation. + * @param array $args Will only append content if style argument value is 'list'. */ - function getBaseDirectory ($directory) - { - //place each directory into array and get the last element - $return = end(explode('/', $directory)); + function start_lvl(&$output, $depth, $args) { + if ('list' != $args['style']) { + return; + } - return $return; + $indent = str_repeat("\t", $depth); + $output .= $indent . '<ul class="children">' . "\n"; } +} - /********************************* - * * - * Methods for variable: options * - * * - ********************************/ +class AVH_EC_Core { + var $comment; + var $db_options_core; + var $db_options_tax_meta; + var $default_options; + var $default_options_category_group; + var $default_options_general; + var $default_options_sp_category_group; + var $info; + var $options; + var $version; /** - * @param array $data + * PHP5 constructor */ - function setOptions ($options) - { - $this->options = $options; - } + function __construct() { + /** + * @var AVH_EC_Category_Group + */ + $catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); - /** - * return array - */ - function getOptions () - { - return ($this->options); - } + $this->version = '4.0.3-dev.1'; + $this->comment = '<!-- AVH Extended Categories version ' . + $this->version . + ' | http://blog.avirtualhome.com/wordpress-plugins/ -->'; + $this->db_options_core = 'avhec'; + $this->db_options_tax_meta = 'avhec-tax_meta'; - /** - * Save all current options and set the options - * - */ - function saveOptions ($options) - { - update_option($this->db_options_core, $options); - wp_cache_flush(); // Delete cache - $this->setOptions($options); + add_action('init', array(&$this, 'handleInitializePlugin'), 10); } /** - * Retrieves the plugin options from the WordPress options table and assigns to class variable. - * If the options do not exists, like a new installation, the options are set to the default value. + * PHP4 Constructor * - * @return none + * @return AVHExtendedCategoriesCore */ - function loadOptions () - { - $options = get_option($this->db_options_core); - if (false === $options) { // New installation - $this->resetToDefaultOptions(); - } else { - $this->setOptions($options); - } + function AVH_EC_Core() { + $this->__construct(); } - /** - * Get the value for an option element. If there's no option is set on the Admin page, return the default value. - * - * @param string $key - * @param string $option - * @return mixed - */ - function getOptionElement ($option, $key) - { - if ($this->options[$option][$key]) { - $return = $this->options[$option][$key]; // From Admin Page - } else { - $return = $this->default_options[$option][$key]; // Default + function applyOrderFilter($orderby, $args) { + switch ($args['orderby']) { + case 'avhec_manualorder': + $new_orderby = 't.avhec_term_order'; + break; + case 'avhec_3rdparty_mycategoryorder': + $new_orderby = 't.term_order'; + break; + default: + $new_orderby = $orderby; + break; } - return ($return); - } - /** - * Reset to default options and save in DB - * - */ - function resetToDefaultOptions () - { - $this->options = $this->default_options; - $this->saveOptions($this->default_options); + return $new_orderby; } /** * Display or retrieve the HTML dropdown list of categories. - * * The list of arguments is below: * 'show_option_all' (string) - Text to display for showing all categories. * 'show_option_none' (string) - Text to display for showing no categories. @@ -309,7 +236,6 @@ class AVH_EC_Core * 'name' (string) - The name attribute value for selected element. * 'class' (string) - The class attribute value for selected element. * 'selected' (int) - Which category ID is selected. - * * The 'hierarchical' argument, which is disabled by default, will override the * depth argument, unless it is true. When the argument is false, it will * display all of the categories. When it is enabled it will use the value in @@ -318,32 +244,41 @@ class AVH_EC_Core * @since 2.1.0 * * @param string|array $args Optional. Override default arguments. + * * @return string HTML content only if 'echo' argument is 0. */ - function avh_wp_dropdown_categories ($args = '', $selectedonly) - { + function avh_wp_dropdown_categories($args = '', $selectedonly) { $mywalker = new AVH_Walker_CategoryDropdown(); // @format_off $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 + '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 ); // @format_on $defaults['selected'] = (is_category()) ? get_query_var('cat') : 0; $r = wp_parse_args($args, $defaults); - if (! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) { + if ( ! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) { $r['pad_counts'] = true; } @@ -351,34 +286,36 @@ class AVH_EC_Core extract($r); $tab_index_attribute = ''; - if ((int) $tab_index > 0) + if ((int) $tab_index > 0) { $tab_index_attribute = ' tabindex="' . $tab_index . '"'; + } $categories = get_terms($taxonomy, $r); - $name = esc_attr($name); - $class = esc_attr($class); - $id = $id ? esc_attr($id) : $name; + $name = esc_attr($name); + $class = esc_attr($class); + $id = $id ? esc_attr($id) : $name; - if (! $r['hide_if_empty'] || ! empty($categories)) + if ( ! $r['hide_if_empty'] || ! empty($categories)) { $output = "<select name='$name' id='$id' class='$class' $tab_index_attribute>\n"; - else + } else { $output = ''; + } if (empty($categories) && ! $r['hide_if_empty'] && ! empty($show_option_none)) { $show_option_none = apply_filters('list_cats', $show_option_none); $output .= "\t<option value='-1' selected='selected'>$show_option_none</option>\n"; } - if (! empty($categories)) { + if ( ! empty($categories)) { if ($show_option_all) { $show_option_all = apply_filters('list_cats', $show_option_all); - $selected = ('0' === strval($r['selected'])) ? " selected='selected'" : ''; + $selected = ('0' === strval($r['selected'])) ? " selected='selected'" : ''; $output .= "\t" . '<option value="0"' . $selected . '>' . $show_option_all . '</option>' . "\n"; } if ($show_option_none) { $show_option_none = apply_filters('list_cats', $show_option_none); - $selected = ('-1' === strval($r['selected'])) ? " selected='selected'" : ''; + $selected = ('-1' === strval($r['selected'])) ? " selected='selected'" : ''; $output .= "\t" . '<option value="-1"' . $selected . '>' . $show_option_none . '</option>' . "\n"; } @@ -389,20 +326,21 @@ class AVH_EC_Core } $output .= walk_category_dropdown_tree($categories, $depth, $r); } - if (! $r['hide_if_empty'] || ! empty($categories)) + if ( ! $r['hide_if_empty'] || ! empty($categories)) { $output .= "</select>\n"; + } $output = apply_filters('wp_dropdown_cats', $output); - if ($echo) + if ($echo) { echo $output; + } return $output; } /** * Display or retrieve the HTML list of categories. - * * The list of arguments is below: * 'show_option_all' (string) - Text to display for showing all categories. * 'orderby' (string) default is 'ID' - What column to use for ordering the @@ -428,98 +366,368 @@ class AVH_EC_Core * 'title_li' (string) - See {@link get_categories()}. * 'depth' (int) - The max depth. * - * @since 2.1.0 + * @since 2.1.0 + * + * @param string|array $args Optional. Override default arguments. + * + * @return string HTML content only if 'echo' argument is 0. + */ + function avh_wp_list_categories($args = '', $selectedonly) { + $mywalker = new AVHEC_Walker_Category(); + $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 + ); + + $r = wp_parse_args($args, $defaults); + + if ( ! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) { + $r['pad_counts'] = true; + } + + if ( ! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) { + $r['pad_counts'] = true; + } + + if (isset($r['show_date'])) { + $r['include_last_update_time'] = $r['show_date']; + } + + if (true == $r['hierarchical']) { + $r['exclude_tree'] = $r['exclude']; + $r['exclude'] = ''; + } + + extract($r); + + $categories = get_categories($r); + + $output = ''; + if ($title_li && 'list' == $style) { + $output = '<li class="categories">' . $r['title_li'] . '<ul>'; + } + + if (empty($categories)) { + if ('list' == $style) { + $output .= '<li>' . __("No categories") . '</li>'; + } else { + $output .= __("No categories"); + } + } else { + global $wp_query; + + if ( ! empty($show_option_all)) { + if ('list' == $style) { + $output .= '<li><a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a></li>'; + } else { + $output .= '<a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a>'; + } + } + + if (empty($r['current_category']) && is_category()) { + $r['current_category'] = $wp_query->get_queried_object_id(); + } + + if ($hierarchical) { + $depth = $r['depth']; + } else { + $depth = - 1; // Flat. + } + + $output .= walk_category_tree($categories, $depth, $r); + } + + if ($title_li && 'list' == $style) { + $output .= '</ul></li>'; + } + + $output = apply_filters('wp_list_categories', $output); + + if ($echo) { + echo $output; + } else { + return $output; + } + } + + /** + * Checks if running version is newer and do upgrades if necessary + * + * @since 1.2.3 + */ + function doUpdateOptions($db_version) { + $options = $this->getOptions(); + + // Add none existing sections and/or elements to the options + foreach ($this->default_options as $section => $default_data) { + if ( ! array_key_exists($section, $options)) { + $options[ $section ] = $default_data; + continue; + } + foreach ($default_data as $element => $default_value) { + if ( ! array_key_exists($element, $options[ $section ])) { + $options[ $section ][ $element ] = $default_value; + } + } + } + + // Remove none existing sections and/or elements from the options + foreach ($options as $section => $data) { + if ( ! array_key_exists($section, $this->default_options)) { + unset($options[ $section ]); + continue; + } + foreach ($data as $element => $value) { + if ( ! array_key_exists($element, $this->default_options[ $section ])) { + unset($options[ $section ][ $element ]); + } + } + } + /** + * Update the options to the latests versions + */ + $options['general']['version'] = $this->version; + $options['general']['dbversion'] = $db_version; + $this->saveOptions($options); + } + + /** + * Get the base directory of a directory structure + * + * @param string $directory + * + * @return string + */ + function getBaseDirectory($directory) { + //place each directory into array and get the last element + $return = end(explode('/', $directory)); + + return $return; + } + + function getCategories() { + static $_categories = null; + if (null === $_categories) { + $_categories = get_categories('get=all'); + } + + return $_categories; + } + + function getCategoriesId($categories) { + static $_categories_id = null; + if (null == $_categories_id) { + foreach ($categories as $key => $category) { + $_categories_id[ $category->term_id ] = $key; + } + } + + return $_categories_id; + } + + /********************************* + * * + * Methods for variable: options * + * * + ********************************/ + + /** + * Get the value for an option element. If there's no option is set on the Admin page, return the default value. + * + * @param string $key + * @param string $option * - * @param string|array $args Optional. Override default arguments. - * @return string HTML content only if 'echo' argument is 0. + * @return mixed */ - function avh_wp_list_categories ($args = '', $selectedonly) - { - $mywalker = new AVHEC_Walker_Category(); - $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 ); + function getOptionElement($option, $key) { + if ($this->options[ $option ][ $key ]) { + $return = $this->options[ $option ][ $key ]; // From Admin Page + } else { + $return = $this->default_options[ $option ][ $key ]; // Default + } - $r = wp_parse_args($args, $defaults); + return ($return); + } - if (! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) { - $r['pad_counts'] = true; - } + /** + * return array + */ + function getOptions() { + return ($this->options); + } - if (! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) { - $r['pad_counts'] = true; - } + /** + * @param array $data + */ + function setOptions($options) { + $this->options = $options; + } - if (isset($r['show_date'])) { - $r['include_last_update_time'] = $r['show_date']; - } + function handleInitializePlugin() { + global $wpdb; - if (true == $r['hierarchical']) { - $r['exclude_tree'] = $r['exclude']; - $r['exclude'] = ''; - } + $catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); + $db_version = 4; - extract($r); + $info['siteurl'] = get_option('siteurl'); + $info['plugin_dir'] = AVHEC_PLUGIN_DIR; + $info['graphics_url'] = AVHEC_PLUGIN_URL . '/images'; - $categories = get_categories($r); + // Set class property for info + $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'] + ); - $output = ''; - if ($title_li && 'list' == $style) - $output = '<li class="categories">' . $r['title_li'] . '<ul>'; + // Set the default options + $this->default_options_general = array( + 'version' => $this->version, + 'dbversion' => $db_version, + 'alternative_name_select_category' => '' + ); - if (empty($categories)) { - if ('list' == $style) - $output .= '<li>' . __("No categories") . '</li>'; - else - $output .= __("No categories"); - } else { - global $wp_query; + // Set the default category group options + $no_group_id = $catgrp->getTermIDBy('slug', 'none'); + $home_group_id = $catgrp->getTermIDBy('slug', 'home'); + $default_group_id = $catgrp->getTermIDBy('slug', 'all'); + $this->default_options_category_group = array( + 'no_group' => $no_group_id, + 'home_group' => $home_group_id, + 'default_group' => $default_group_id + ); - if (! empty($show_option_all)) - if ('list' == $style) - $output .= '<li><a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a></li>'; - else - $output .= '<a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a>'; + $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 + ); - if (empty($r['current_category']) && is_category()) - $r['current_category'] = $wp_query->get_queried_object_id(); + $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 + ); - if ($hierarchical) { - $depth = $r['depth']; - } else { - $depth = - 1; // Flat. - } + /** + * Set the options for the program + */ + $this->loadOptions(); - $output .= walk_category_tree($categories, $depth, $r); + // Check if we have to do updates + if (( ! isset($this->options['general']['dbversion'])) || + $this->options['general']['dbversion'] < $db_version + ) { + $this->doUpdateOptions($db_version); } - if ($title_li && 'list' == $style) - $output .= '</ul></li>'; + $db = new AVH_DB(); + if ( ! $db->field_exists('avhec_term_order', $wpdb->terms)) { + $wpdb->query("ALTER TABLE $wpdb->terms ADD `avhec_term_order` INT( 4 ) NULL DEFAULT '0'"); + } - $output = apply_filters('wp_list_categories', $output); + $this->handleTextdomain(); + add_filter('get_terms_orderby', array(&$this, 'applyOrderFilter'), 10, 2); + } - if ($echo) - echo $output; - else - return $output; + /** + * Loads the i18n + * + * @return + */ + function handleTextdomain() { + + load_plugin_textdomain('avh-ec', false, AVHEC_RELATIVE_PLUGIN_DIR . '/lang'); } - function getCategories () - { - static $_categories = NULL; - if (NULL === $_categories) { - $_categories = get_categories('get=all'); + /** + * Used in forms to set the checked option. + * + * @param mixed $checked + * @param mixed_type $current + * + * @return string + * @since 2.0 + */ + function isChecked($checked, $current) { + if ($checked == $current) { + return (' checked="checked"'); } - return $_categories; + + return (''); } - function getCategoriesId ($categories) - { - static $_categories_id = NULL; - if (NULL == $_categories_id) { - foreach ($categories as $key => $category) { - $_categories_id[$category->term_id] = $key; - } + /** + * Used in forms to set the SELECTED option + * + * @param string $current + * @param string $field + * + * @return string + */ + function isSelected($current, $field) { + if ($current == $field) { + return (' SELECTED'); + } + + return (''); + } + + /** + * Retrieves the plugin options from the WordPress options table and assigns to class variable. + * If the options do not exists, like a new installation, the options are set to the default value. + * + * @return none + */ + function loadOptions() { + $options = get_option($this->db_options_core); + if (false === $options) { // New installation + $this->resetToDefaultOptions(); + } else { + $this->setOptions($options); } - return $_categories_id; + } + + /** + * Reset to default options and save in DB + */ + function resetToDefaultOptions() { + $this->options = $this->default_options; + $this->saveOptions($this->default_options); + } + + /** + * Save all current options and set the options + */ + function saveOptions($options) { + update_option($this->db_options_core, $options); + wp_cache_flush(); // Delete cache + $this->setOptions($options); } } @@ -528,29 +736,32 @@ class AVH_EC_Core * * @uses Walker */ -class AVH_Walker_CategoryDropdown extends Walker_CategoryDropdown -{ - - function walk ($elements, $max_depth) - { +class AVH_Walker_CategoryDropdown extends Walker_CategoryDropdown { + function walk($elements, $max_depth) { - $args = array_slice(func_get_args(), 2); + $args = array_slice(func_get_args(), 2); $output = ''; if ($max_depth < - 1) //invalid parameter + { return $output; + } if (empty($elements)) //nothing to walk + { return $output; + } - $id_field = $this->db_fields['id']; + $id_field = $this->db_fields['id']; $parent_field = $this->db_fields['parent']; // flat display if (- 1 == $max_depth) { - $empty_array = array (); - foreach ($elements as $e) + $empty_array = array(); + foreach ($elements as $e) { $this->display_element($e, $empty_array, 1, 0, $args, $output); + } + return $output; } @@ -560,13 +771,14 @@ class AVH_Walker_CategoryDropdown extends Walker_CategoryDropdown * children_elements is two dimensional array, eg. * children_elements[10][] contains all sub-elements whose parent is 10. */ - $top_level_elements = array (); - $children_elements = array (); + $top_level_elements = array(); + $children_elements = array(); foreach ($elements as $e) { - if (0 == $e->$parent_field) + if (0 == $e->$parent_field) { $top_level_elements[] = $e; - else - $children_elements[$e->$parent_field][] = $e; + } else { + $children_elements[ $e->$parent_field ][] = $e; + } } /* @@ -576,15 +788,16 @@ class AVH_Walker_CategoryDropdown extends Walker_CategoryDropdown if (empty($top_level_elements)) { $first = array_slice($elements, 0, 1); - $root = $first[0]; + $root = $first[0]; - $top_level_elements = array (); - $children_elements = array (); + $top_level_elements = array(); + $children_elements = array(); foreach ($elements as $e) { - if ($root->$parent_field == $e->$parent_field) + if ($root->$parent_field == $e->$parent_field) { $top_level_elements[] = $e; - else - $children_elements[$e->$parent_field][] = $e; + } else { + $children_elements[ $e->$parent_field ][] = $e; + } } } @@ -597,163 +810,16 @@ class AVH_Walker_CategoryDropdown extends Walker_CategoryDropdown * then we got orphans, which should be displayed regardless */ if ((0 == $max_depth) && count($children_elements) > 0) { - $empty_array = array (); - foreach ($children_elements as $orphans) - foreach ($orphans as $op) + $empty_array = array(); + foreach ($children_elements as $orphans) { + foreach ($orphans as $op) { $this->display_element($op, $empty_array, 1, 0, $args, $output); + } + } } return $output; } } -/** - * Create HTML list of categories. - * - * @uses Walker - */ -class AVHEC_Walker_Category extends Walker -{ - /** - * @see Walker::$tree_type - * @since 2.1.0 - * @var string - */ - var $tree_type = 'category'; - - /** - * @see Walker::$db_fields - * @since 2.1.0 - * @todo Decouple this - * @var array - */ - var $db_fields = array ( 'parent' => 'parent', 'id' => 'term_id' ); - - /** - * @see Walker::start_lvl() - * @since 2.1.0 - * - * @param string $output Passed by reference. Used to append additional content. - * @param int $depth Depth of category. Used for tab indentation. - * @param array $args Will only append content if style argument value is 'list'. - */ - function start_lvl (&$output, $depth, $args) - { - if ('list' != $args['style']) - return; - - $indent = str_repeat("\t", $depth); - $output .= $indent . '<ul class="children">' . "\n"; - } - - /** - * @see Walker::end_lvl() - * @since 2.1.0 - * - * @param string $output Passed by reference. Used to append additional content. - * @param int $depth Depth of category. Used for tab indentation. - * @param array $args Will only append content if style argument value is 'list'. - */ - function end_lvl (&$output, $depth, $args) - { - if ('list' != $args['style']) - return; - - $indent = str_repeat("\t", $depth); - $output .= $indent . '</ul>' . "\n"; - } - - /** - * @see Walker::start_el() - * @since 2.1.0 - * - * @param string $output Passed by reference. Used to append additional content. - * @param object $category Category data object. - * @param int $depth Depth of category in reference to parents. - * @param array $args - */ - function start_el (&$output, $category, $depth, $args) - { - extract($args); - - $cat_name = esc_attr($category->name); - $cat_name = apply_filters('list_cats', $cat_name, $category); - $link = '<div class="avhec-widget-line"><a href="' . get_category_link($category->term_id) . '" '; - if ($use_desc_for_title == 0 || empty($category->description)) - $link .= 'title="' . sprintf(__('View all posts filed under %s'), $cat_name) . '"'; - else - $link .= 'title="' . esc_attr(strip_tags(apply_filters('category_description', $category->description, $category))) . '"'; - $link .= '>'; - $link .= $cat_name . '</a>'; - - if ((! empty($feed_image)) || (! empty($feed))) { - $link .= '<div class="avhec-widget-rss"> '; - - if (empty($feed_image)) - $link .= '('; - - $link .= '<a href="' . get_category_feed_link($category->term_id, $feed_type) . '"'; - - if (empty($feed)) - $alt = ' alt="' . sprintf(__('Feed for all posts filed under %s'), $cat_name) . '"'; - else { - $title = ' title="' . $feed . '"'; - $alt = ' alt="' . $feed . '"'; - $name = $feed; - $link .= $title; - } - - $link .= '>'; - - if (empty($feed_image)) - $link .= $name; - else - $link .= '<img src="' . $feed_image . '"' . $alt . $title . ' />'; - $link .= '</a>'; - if (empty($feed_image)) - $link .= ')'; - $link .= '</div>'; - } - - if (isset($show_count) && $show_count) - $link .= '<div class="avhec-widget-count"> (' . intval($category->count) . ')</div>'; - - if (isset($show_date) && $show_date) { - $link .= ' ' . gmdate('Y-m-d', $category->last_update_timestamp); - } - - if (isset($current_category) && $current_category) - $_current_category = get_category($current_category); - - if ('list' == $args['style']) { - $output .= "\t" . '<li'; - $class = 'cat-item cat-item-' . $category->term_id; - if (isset($current_category) && $current_category && ($category->term_id == $current_category)) - $class .= ' current-cat'; - elseif (isset($_current_category) && $_current_category && ($category->term_id == $_current_category->parent)) - $class .= ' current-cat-parent'; - $output .= ' class="' . $class . '"'; - $output .= '>' . $link . '</div>' . "\n"; - } else { - $output .= "\t" . $link . '</div><br />' . "\n"; - } - } - - /** - * @see Walker::end_el() - * @since 2.1.0 - * - * @param string $output Passed by reference. Used to append additional content. - * @param object $page Not used. - * @param int $depth Depth of category. Not used. - * @param array $args Only uses 'list' for whether should append to output. - */ - function end_el (&$output, $page, $depth, $args) - { - if ('list' != $args['style']) - return; - - $output .= '</li>' . "\n"; - } -} ?> \ No newline at end of file diff --git a/wp-content/plugins/extended-categories-widget/3.3/class/avh-ec.widgets.php b/wp-content/plugins/extended-categories-widget/3.3/class/avh-ec.widgets.php index d48f6e53c406c7406d77b33be9ba1ce150c49dfb..75f365ba9537114925aa30e4742d03eb6a706fb3 100644 --- a/wp-content/plugins/extended-categories-widget/3.3/class/avh-ec.widgets.php +++ b/wp-content/plugins/extended-categories-widget/3.3/class/avh-ec.widgets.php @@ -1,175 +1,228 @@ <?php /** - * Widget Class for displaying categories. Extended version of the dfeault categories. - * + * Class that will display the categories */ -class WP_Widget_AVH_ExtendedCategories_Normal extends WP_Widget -{ - /** - * - * @var AVH_EC_Core - */ - var $core; - - /** - * PHP 5 Constructor - * - */ - function __construct () - { - $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core'); - - //Convert the old option widget_extended_categories to widget_extended-categories - $old = get_option('widget_extended_categories'); - if (! (FALSE === $old)) { - update_option('widget_extended-categories', $old); - delete_option('widget_extended_categories'); - } - $widget_ops = array ( 'description' => __("An extended version of the default Categories widget.", 'avh-ec') ); - WP_Widget::__construct('extended-categories', 'AVH Extended Categories', $widget_ops); - - add_action('wp_print_styles', array ( &$this, 'actionWpPrintStyles' )); +class AVH_Walker_Category_Checklist extends Walker { + var $db_fields = array('parent' => 'parent', 'id' => 'term_id'); + var $input_id; //TODO: decouple this + var $input_name; + var $li_id; + var $number; + var $tree_type = 'category'; + function end_el(&$output, $category, $depth, $args) { + $output .= "</li>\n"; } - function WP_Widget_AVH_ExtendedCategories_Normal () - { - $this->__construct(); + function end_lvl(&$output, $depth, $args) { + $indent = str_repeat("\t", $depth); + $output .= $indent . '</ul>' . "\n"; } - function actionWpPrintStyles () - { + function start_el(&$output, $category, $depth, $args) { + extract($args); + $input_id = $this->input_id . '-' . $category->term_id; + $output .= "\n" . '<li id="' . $this->li_id . '">'; + $output .= '<label for="' . $input_id . '" class="selectit">'; + $output .= '<input value="' . + $category->term_id . + '" type="checkbox" name="' . + $this->input_name . + '[' . + $category->term_id . + ']" id="' . + $input_id . + '"' . + (in_array($category->term_id, $selected_cats) ? ' checked="checked"' : "") . + '/> ' . + esc_html(apply_filters('the_category', $category->name)) . + '</label>'; + } - if (! (FALSE === is_active_widget(FALSE, FALSE, $this->id_base, TRUE))) { - wp_register_style('avhec-widget', AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', array (), $this->core->version); - wp_enqueue_style('avhec-widget'); - } + function start_lvl(&$output, $depth, $args) { + $indent = str_repeat("\t", $depth); + $output .= $indent . '<ul class="children">' . "\n"; } /** - * Display the widget + * Display array of elements hierarchically. + * It is a generic function which does not assume any existing order of + * elements. max_depth = -1 means flatly display every element. max_depth = + * 0 means display all levels. max_depth > 0 specifies the number of + * display levels. * - * @param unknown_type $args - * @param unknown_type $instance + * @since 2.1.0 + * + * @param array $elements + * @param int $max_depth + * @param array $args ; + * + * @return string */ - function widget ($args, $instance) - { - - extract($args); + function walk($elements, $max_depth, $args) { - $selectedonly = $instance['selectedonly'] ? TRUE : FALSE; - $c = $instance['count'] ? TRUE : FALSE; - $h = $instance['hierarchical'] ? TRUE : FALSE; - $d = $instance['depth'] ? $instance['depth'] : 0; - $e = $instance['hide_empty'] ? TRUE : FALSE; - $use_desc_for_title = $instance['use_desc_for_title'] ? TRUE : FALSE; - $s = $instance['sort_column'] ? $instance['sort_column'] : 'name'; - $o = $instance['sort_order'] ? $instance['sort_order'] : 'asc'; - $r = $instance['rssfeed'] ? 'RSS' : ''; - $i = $instance['rssimage'] ? $instance['rssimage'] : ''; - $invert = $instance['invert_included'] ? TRUE : FALSE; + $output = ''; - if (empty($r)) { - $i = ''; + if ($max_depth < - 1) //invalid parameter + { + return $output; } - if (empty($d)) { - $d = 0; + if (empty($elements)) //nothing to walk + { + return $output; } - $title = apply_filters('widget_title', empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']); - $style = empty($instance['style']) ? 'list' : $instance['style']; + $id_field = $this->db_fields['id']; + $parent_field = $this->db_fields['parent']; - $included_cats = ''; - if ($instance['post_category']) { - $post_category = unserialize($instance['post_category']); - $children = array (); - if (! $instance['selectedonly']) { - foreach ($post_category as $cat_id) { - $children = array_merge($children, get_term_children($cat_id, 'category')); - } + // flat display + if (- 1 == $max_depth) { + $empty_array = array(); + foreach ($elements as $e) { + $this->display_element($e, $empty_array, 1, 0, $args, $output); } - $included_cats = implode(",", array_merge($post_category, $children)); + + return $output; } - if ($invert) { - $inc_exc = 'exclude'; - } else { - $inc_exc = 'include'; + /* + * 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. + */ + $top_level_elements = array(); + $children_elements = array(); + foreach ($elements as $e) { + if (0 == $e->$parent_field) { + $top_level_elements[] = $e; + } else { + $children_elements[ $e->$parent_field ][] = $e; + } } - $options = $this->core->getOptions(); - $show_option_none = __('Select Category', 'avh-ec'); - if ($options['general']['alternative_name_select_category']) { - $show_option_none = $options['general']['alternative_name_select_category']; + /* + * when none of the elements is top level + * assume the first one must be root of the sub elements + */ + if (empty($top_level_elements)) { + + $first = array_slice($elements, 0, 1); + $root = $first[0]; + + $top_level_elements = array(); + $children_elements = array(); + foreach ($elements as $e) { + if ($root->$parent_field == $e->$parent_field) { + $top_level_elements[] = $e; + } else { + $children_elements[ $e->$parent_field ][] = $e; + } + } } - $cat_args = array ( $inc_exc => $included_cats, 'orderby' => $s, 'order' => $o, 'show_count' => $c, 'use_desc_for_title' => $use_desc_for_title, 'hide_empty' => $e, 'hierarchical' => $h, 'depth' => $d, 'title_li' => '', 'show_option_none' => $show_option_none, 'feed' => $r, 'feed_image' => $i, 'name' => 'extended-categories-select-' . $this->number ); - echo $before_widget; - echo $this->core->comment; - echo $before_title . $title . $after_title; + foreach ($top_level_elements as $e) { + $this->display_element($e, $children_elements, $max_depth, 0, $args, $output); + } - if ($style == 'list') { - echo '<ul>'; - $this->core->avh_wp_list_categories($cat_args, $selectedonly); - echo '</ul>'; - } else { - $this->core->avh_wp_dropdown_categories($cat_args, $selectedonly); - echo '<script type=\'text/javascript\'>' . "\n"; - echo '/* <![CDATA[ */' . "\n"; - echo ' var ec_dropdown_' . $this->number . ' = document.getElementById("extended-categories-select-' . $this->number . '");' . "\n"; - echo ' function ec_onCatChange_' . $this->number . '() {' . "\n"; - echo ' if ( ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value > 0 ) {' . "\n"; - echo ' location.href = "' .home_url() . '/?cat="+ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value;' . "\n"; - echo ' }' . "\n"; - echo ' }' . "\n"; - echo ' ec_dropdown_' . $this->number . '.onchange = ec_onCatChange_' . $this->number . ';' . "\n"; - echo '/* ]]> */' . "\n"; - echo '</script>' . "\n"; + /* + * if we are displaying all levels, and remaining children_elements is not empty, + * then we got orphans, which should be displayed regardless + */ + if (($max_depth == 0) && count($children_elements) > 0) { + $empty_array = array(); + foreach ($children_elements as $orphans) { + foreach ($orphans as $op) { + $this->display_element($op, $empty_array, 1, 0, $args, $output); + } + } } - echo $after_widget; + + return $output; } +} +/** + * Widget Class for displaying the grouped categories + */ +class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget { /** - * When Widget Control Form Is Posted - * - * @param unknown_type $new_instance - * @param unknown_type $old_instance - * @return unknown + * @var AVH_EC_Category_Group */ - function update ($new_instance, $old_instance) - { - // update the instance's settings - if (! isset($new_instance['submit'])) { - return FALSE; + var $catgrp; + /** + * @var AVH_EC_Core + */ + var $core; + + /** + * PHP 5 Constructor + */ + function __construct() { + $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core'); + $this->catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); + + $widget_ops = array('description' => __("Shows grouped categories.", 'avh-ec')); + WP_Widget::__construct(false, 'AVH Extended Categories: ' . __('Category Group'), $widget_ops); + add_action('wp_print_styles', array(&$this, 'actionWpPrintStyles')); + } + + function WP_Widget_AVH_ExtendedCategories_Category_Group() { + $this->__construct(); + } + + function actionWpPrintStyles() { + if ( ! (false === is_active_widget(false, false, $this->id_base, true))) { + wp_register_style('avhec-widget', + AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', + array(), + $this->core->version); + wp_enqueue_style('avhec-widget'); } + } - $instance = $old_instance; + function avh_wp_group_category_checklist($selected_cats, $number) { - $instance['title'] = strip_tags(stripslashes($new_instance['title'])); - $instance['selectedonly'] = $new_instance['selectedonly'] ? TRUE : FALSE; - $instance['count'] = $new_instance['count'] ? TRUE : FALSE; - $instance['hierarchical'] = $new_instance['hierarchical'] ? TRUE : FALSE; - $instance['hide_empty'] = $new_instance['hide_empty'] ? TRUE : FALSE; - $instance['use_desc_for_title'] = $new_instance['use_desc_for_title'] ? TRUE : FALSE; - $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column'])); - $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order'])); - $instance['style'] = strip_tags(stripslashes($new_instance['style'])); - $instance['rssfeed'] = $new_instance['rssfeed'] ? TRUE : FALSE; - $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage'])); - if (array_key_exists('all', $new_instance['post_category'])) { - $instance['post_category'] = FALSE; + $walker = new AVH_Walker_Category_Checklist(); + $walker->number = $number; + $walker->input_id = $this->get_field_id('post_group_category'); + $walker->input_name = $this->get_field_name('post_group_category'); + $walker->li_id = $this->get_field_id('group_category--1'); + + $args = array( + 'taxonomy' => 'avhec_catgroup', + 'descendants_and_self' => 0, + 'selected_cats' => array(), + 'popular_cats' => array(), + 'walker' => $walker, + 'checked_ontop' => true + ); + + if (is_array($selected_cats)) { + $args['selected_cats'] = $selected_cats; } else { - $instance['post_category'] = serialize($new_instance['post_category']); + $args['selected_cats'] = array(); } - $instance['depth'] = (int) $new_instance['depth']; - if ($instance['depth'] < 0 || 11 < $instance['depth']) { - $instance['depth'] = 0; + + $categories = (array) get_terms($args['taxonomy'], array('get' => 'all')); + + // 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) + $checked_categories = array(); + $keys = array_keys($categories); + + foreach ($keys as $k) { + if (in_array($categories[ $k ]->term_id, $args['selected_cats'])) { + $checked_categories[] = $categories[ $k ]; + unset($categories[ $k ]); + } } - $instance['invert_included'] = $new_instance['invert_included'] ? TRUE : FALSE; - return $instance; + // Put checked cats on top + echo $walker->walk($checked_categories, 0, array($args)); + // Then the rest of them + echo $walker->walk($categories, 0, array($args)); } /** @@ -177,402 +230,190 @@ class WP_Widget_AVH_ExtendedCategories_Normal extends WP_Widget * * @param unknown_type $instance */ - function form ($instance) - { + function form($instance) { // displays the widget admin form - $instance = wp_parse_args((array) $instance, array ( 'title' => '', 'rssimage' => '', 'depth' => 0 )); + $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => '')); // Prepare data for display - $depth = (int) $instance['depth']; - if ($depth < 0 || 11 < $depth) { - $depth = 0; - } - $selected_cats = ($instance['post_category'] != '') ? unserialize($instance['post_category']) : FALSE; - + $title = esc_attr($instance['title']); + $count = (bool) $instance['count']; + $hierarchical = (bool) $instance['hierarchical']; + $hide_empty = (bool) $instance['hide_empty']; + $use_desc_for_title = (bool) $instance['use_desc_for_title']; + $sort_id = ($instance['sort_column'] == 'ID') ? ' SELECTED' : ''; + $sort_name = ($instance['sort_column'] == 'name') ? ' SELECTED' : ''; + $sort_count = ($instance['sort_column'] == 'count') ? ' SELECTED' : ''; + $sort_order_a = ($instance['sort_order'] == 'asc') ? ' SELECTED' : ''; + $sort_order_d = ($instance['sort_order'] == 'desc') ? ' SELECTED' : ''; + $style_list = ($instance['style'] == 'list') ? ' SELECTED' : ''; + $style_drop = ($instance['style'] == 'drop') ? ' SELECTED' : ''; + $rssfeed = (bool) $instance['rssfeed']; + $rssimage = esc_attr($instance['rssimage']); + + $selected_cats = ($instance['post_group_category'] != + '') ? unserialize($instance['post_group_category']) : false; + ob_start(); echo '<p>'; - avh_doWidgetFormText($this->get_field_id('title'), $this->get_field_name('title'), __('Title', 'avh-ec'), $instance['title']); + avh_doWidgetFormText($this->get_field_id('title'), + $this->get_field_name('title'), + __('Title', 'avh-ec'), + $instance['title']); echo '</p>'; echo '<p>'; - avh_doWidgetFormCheckbox($this->get_field_id('selectedonly'), $this->get_field_name('selectedonly'), __('Show selected categories only', 'avh-ec'), (bool) $instance['selectedonly']); - - avh_doWidgetFormCheckbox($this->get_field_id('count'), $this->get_field_name('count'), __('Show post counts', 'avh-ec'), (bool) $instance['count']); - - avh_doWidgetFormCheckbox($this->get_field_id('hierarchical'), $this->get_field_name('hierarchical'), __('Show hierarchy', 'avh-ec'), (bool) $instance['hierarchical']); - - $options = array ( 0 => __('All Levels', 'avh-ec'), 1 => __('Toplevel only', 'avh-ec') ); - for ($i = 2; $i <= 11; $i ++) { - $options[$i] = __('Child ', 'avh-ec') . ($i - 1); - } - avh_doWidgetFormSelect($this->get_field_id('depth'), $this->get_field_name('depth'), __('How many levels to show', 'avh-ec'), $options, $depth); - unset($options); - avh_doWidgetFormCheckbox($this->get_field_id('hide_empty'), $this->get_field_name('hide_empty'), __('Hide empty categories', 'avh-ec'), (bool) $instance['hide_empty']); - - avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'), $this->get_field_name('use_desc_for_title'), __('Use description for title', 'avh-ec'), (bool) $instance['use_desc_for_title']); + avh_doWidgetFormCheckbox($this->get_field_id('count'), + $this->get_field_name('count'), + __('Show post counts', 'avh-ec'), + (bool) $instance['count']); + + avh_doWidgetFormCheckbox($this->get_field_id('hierarchical'), + $this->get_field_name('hierarchical'), + __('Show hierarchy', 'avh-ec'), + (bool) $instance['hierarchical']); + + avh_doWidgetFormCheckbox($this->get_field_id('hide_empty'), + $this->get_field_name('hide_empty'), + __('Hide empty categories', 'avh-ec'), + (bool) $instance['hide_empty']); + + avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'), + $this->get_field_name('use_desc_for_title'), + __('Use description for title', 'avh-ec'), + (bool) $instance['use_desc_for_title']); echo '</p>'; echo '<p>'; - $options['ID'] = __('ID', 'avh-ec'); - $options['name'] = __('Name', 'avh-ec'); + $options['ID'] = __('ID', 'avh-ec'); + $options['name'] = __('Name', 'avh-ec'); $options['count'] = __('Count', 'avh-ec'); - $options['slug'] = __('Slug', 'avh-ec'); - $options['avhec_manualorder'] = 'AVH EC ' . __('Manual Order', 'avh-ec'); - if (is_plugin_active('my-category-order/mycategoryorder.php')) { - $options['avhec_3rdparty_mycategoryorder'] = 'My Category Order'; - } - - avh_doWidgetFormSelect($this->get_field_id('sort_column'), $this->get_field_name('sort_column'), __('Sort by', 'avh-ec'), $options, $instance['sort_column']); + $options['slug'] = __('Slug', 'avh-ec'); + avh_doWidgetFormSelect($this->get_field_id('sort_column'), + $this->get_field_name('sort_column'), + __('Sort by', 'avh-ec'), + $options, + $instance['sort_column']); unset($options); - $options['asc'] = __('Ascending', 'avh-ec'); + $options['asc'] = __('Ascending', 'avh-ec'); $options['desc'] = __('Descending', 'avh-ec'); - avh_doWidgetFormSelect($this->get_field_id('sort_order'), $this->get_field_name('sort_order'), __('Sort order', 'avh-ec'), $options, $instance['sort_order']); + avh_doWidgetFormSelect($this->get_field_id('sort_order'), + $this->get_field_name('sort_order'), + __('Sort order', 'avh-ec'), + $options, + $instance['sort_order']); unset($options); $options['list'] = __('List', 'avh-ec'); $options['drop'] = __('Drop down', 'avh-ec'); - avh_doWidgetFormSelect($this->get_field_id('style'), $this->get_field_name('style'), __('Display style', 'avh-ec'), $options, $instance['style']); + avh_doWidgetFormSelect($this->get_field_id('style'), + $this->get_field_name('style'), + __('Display style', 'avh-ec'), + $options, + $instance['style']); unset($options); echo '</p>'; echo '<p>'; - avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), $this->get_field_name('rssfeed'), __('Show RSS Feed', 'avh-ec'), (bool) $instance['rssfeed']); - - avh_doWidgetFormText($this->get_field_id('rssimage'), $this->get_field_name('rssimage'), __('Path (URI) to RSS image', 'avh-ec'), $instance['rssimage']); + avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), + $this->get_field_name('rssfeed'), + __('Show RSS Feed', 'avh-ec'), + (bool) $instance['rssfeed']); + avh_doWidgetFormText($this->get_field_id('rssimage'), + $this->get_field_name('rssimage'), + __('Path (URI) to RSS image', 'avh-ec'), + $instance['rssimage']); echo '</p>'; echo '<p>'; - echo '<b>' . __('Select categories', 'avh-ec') . '</b><hr />'; + echo '<b>' . __('Select Groups', 'avh-ec') . '</b><hr />'; 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;">'; - echo '<li id="' . $this->get_field_id('category--1') . '" class="popular-category">'; - echo '<label for="' . $this->get_field_id('post_category') . '" class="selectit">'; - 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' : '') . '> '; - _e('All Categories', 'avh-ec'); + echo '<li id="' . $this->get_field_id('group_category--1') . '" class="popular-group_category">'; + echo '<label for="' . $this->get_field_id('group_post_category') . '" class="selectit">'; + 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' : '') . + '> '; + _e('Any Group', 'avh-ec'); echo '</label>'; echo '</li>'; - ob_start(); - $this->avh_wp_category_checklist($selected_cats, $this->number); - ob_end_flush(); + + $this->avh_wp_group_category_checklist($selected_cats, $this->number); + echo '</ul>'; echo '</p>'; - echo '<p>'; - avh_doWidgetFormCheckbox($this->get_field_id('invert_included'), $this->get_field_name('invert_included'), __('Exclude the selected categories', 'avh-ec'), (bool) $instance['invert_included']); - echo '</p>'; + echo '<input type="hidden" id="' . + $this->get_field_id('submit') . + '" name="' . + $this->get_field_name('submit') . + '" value="1" />'; + ob_end_flush(); + } + + function getWidgetDoneCatGroup($id) { + $catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); + if (is_array($catgrp->widget_done_catgroup) && array_key_exists($id, $catgrp->widget_done_catgroup)) { + return true; + } + $catgrp->widget_done_catgroup[ $id ] = true; - echo '<input type="hidden" id="' . $this->get_field_id('submit') . '" name="' . $this->get_field_name('submit') . '" value="1" />'; + return false; } /** - * Creates the categories checklist + * When Widget Control Form Is Posted * - * @param int $post_id - * @param int $descendants_and_self - * @param array $selected_cats - * @param array $popular_cats - * @param int $number + * @param unknown_type $new_instance + * @param unknown_type $old_instance + * + * @return unknown */ - function avh_wp_category_checklist ($selected_cats, $number) - { - - $walker = new AVH_Walker_Category_Checklist(); - $walker->number = $number; - $walker->input_id = $this->get_field_id('post_category'); - $walker->input_name = $this->get_field_name('post_category'); - $walker->li_id = $this->get_field_id('category--1'); - - $args = array ( 'taxonomy' => 'category', 'descendants_and_self' => 0, 'selected_cats' => $selected_cats, 'popular_cats' => array (), 'walker' => $walker, 'checked_ontop' => true, 'popular_cats' => array () ); - - if (is_array($selected_cats)) - $args['selected_cats'] = $selected_cats; - else - $args['selected_cats'] = array (); + function update($new_instance, $old_instance) { + // update the instance's settings + if ( ! isset($new_instance['submit'])) { + return false; + } - $categories = $this->core->getCategories(); - $_categories_id = $this->core->getCategoriesId($categories); + $instance = $old_instance; - // 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) - $checked_categories = array (); - foreach ($args['selected_cats'] as $key => $value) { - if (isset($_categories_id[$key])) { - $category_key = $_categories_id[$key]; - $checked_categories[] = $categories[$category_key]; - unset($categories[$category_key]); - } + $instance['title'] = strip_tags(stripslashes($new_instance['title'])); + $instance['count'] = $new_instance['count'] ? true : false; + $instance['hierarchical'] = $new_instance['hierarchical'] ? true : false; + $instance['hide_empty'] = $new_instance['hide_empty'] ? true : false; + $instance['use_desc_for_title'] = $new_instance['use_desc_for_title'] ? true : false; + $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column'])); + $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order'])); + $instance['style'] = strip_tags(stripslashes($new_instance['style'])); + $instance['rssfeed'] = $new_instance['rssfeed'] ? true : false; + $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage'])); + if (array_key_exists('all', $new_instance['post_group_category'])) { + $instance['post_group_category'] = false; + } else { + $instance['post_group_category'] = serialize($new_instance['post_group_category']); } - // Put checked cats on top - echo $walker->walk($checked_categories, 0, array ( $args )); - // Then the rest of them - echo $walker->walk($categories, 0, array ( $args )); + return $instance; } -} -/** - * Widget Class for displaying the top categories - * - */ -class WP_Widget_AVH_ExtendedCategories_Top extends WP_Widget -{ /** + * Display the widget * - * @var AVH_EC_Core + * @param unknown_type $args + * @param unknown_type $instance */ - var $core; + function widget($args, $instance) { + global $post, $wp_query; - /** - * PHP 5 Constructor - * - */ - function __construct () - { - $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core'); - - $widget_ops = array ( 'description' => __("Shows the top categories.", 'avh-ec') ); - WP_Widget::__construct(FALSE, 'AVH Extended Categories: ' . __('Top Categories'), $widget_ops); - add_action('wp_print_styles', array ( &$this, 'actionWpPrintStyles' )); - - } - - function WP_Widget_AVH_ExtendedCategories_Top () - { - $this->__construct(); - } - - function actionWpPrintStyles () - { - if (! (FALSE === is_active_widget(FALSE, FALSE, $this->id_base, TRUE))) { - wp_register_style('avhec-widget', AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', array (), $this->core->version); - wp_enqueue_style('avhec-widget'); - } - } - - /** Echo the widget content. - * - * Subclasses should over-ride this function to generate their widget code. - * - * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget. - * @param array $instance The settings for the particular instance of the widget - */ - function widget ($args, $instance) - { - extract($args); - - $title = apply_filters('widget_title', empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']); - $style = empty($instance['style']) ? 'list' : $instance['style']; - if (! $a = (int) $instance['amount']) { - $a = 5; - } elseif ($a < 1) { - $a = 1; - } - $c = $instance['count'] ? TRUE : FALSE; - $use_desc_for_title = $instance['use_desc_for_title'] ? TRUE : FALSE; - $s = $instance['sort_column'] ? $instance['sort_column'] : 'name'; - $o = $instance['sort_order'] ? $instance['sort_order'] : 'asc'; - $r = $instance['rssfeed'] ? 'RSS' : ''; - $i = $instance['rssimage'] ? $instance['rssimage'] : ''; - if (empty($r)) { - $i = ''; - } - if (! empty($i)) { - if (! file_exists(ABSPATH . '/' . $i)) { - $i = ''; - } - } - - $options = $this->core->getOptions(); - $show_option_none = __('Select Category', 'avh-ec'); - if ($options['general']['alternative_name_select_category']) { - $show_option_none = $options['general']['alternative_name_select_category']; - } - - $top_cats = get_terms('category', array ( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => $a, 'hierarchical' => FALSE )); - $included_cats = implode(",", $top_cats); - - $cat_args = array ( 'include' => $included_cats, 'orderby' => $s, 'order' => $o, 'show_count' => $c, 'use_desc_for_title' => $use_desc_for_title, 'hide_empty' => FALSE, 'hierarchical' => FALSE, 'depth' => - 1, 'title_li' => '', 'show_option_none' => $show_option_none, 'feed' => $r, 'feed_image' => $i, 'name' => 'extended-categories-top-select-' . $this->number ); - echo $before_widget; - echo $this->core->comment; - echo $before_title . $title . $after_title; - echo '<ul>'; - - if ($style == 'list') { - wp_list_categories($cat_args); - } else { - wp_dropdown_categories($cat_args); - echo '<script type=\'text/javascript\'>' . "\n"; - echo '/* <![CDATA[ */' . "\n"; - echo ' var ec_dropdown_top_' . $this->number . ' = document.getElementById("extended-categories-top-select-' . $this->number . '");' . "\n"; - echo ' function ec_top_onCatChange_' . $this->number . '() {' . "\n"; - echo ' if ( ec_dropdown_top_' . $this->number . '.options[ec_dropdown_top_' . $this->number . '.selectedIndex].value > 0 ) {' . "\n"; - echo ' location.href = "' . get_option('home') . '/?cat="+ec_dropdown_top_' . $this->number . '.options[ec_dropdown_top_' . $this->number . '.selectedIndex].value;' . "\n"; - echo ' }' . "\n"; - echo ' }' . "\n"; - echo ' ec_dropdown_top_' . $this->number . '.onchange = ec_top_onCatChange_' . $this->number . ';' . "\n"; - echo '/* ]]> */' . "\n"; - echo '</script>' . "\n"; - } - echo '</ul>'; - echo $after_widget; - } - - /** Update a particular instance. - * - * This function should check that $new_instance is set correctly. - * The newly calculated value of $instance should be returned. - * If "FALSE" is returned, the instance won't be saved/updated. - * - * @param array $new_instance New settings for this instance as input by the user via form() - * @param array $old_instance Old settings for this instance - * @return array Settings to save or bool FALSE to cancel saving - */ - function update ($new_instance, $old_instance) - { - // update the instance's settings - if (! isset($new_instance['submit'])) { - return FALSE; - } - - $instance = $old_instance; - - $instance['title'] = strip_tags(stripslashes($new_instance['title'])); - $instance['amount'] = (int) $new_instance['amount']; - $instance['count'] = $new_instance['count'] ? TRUE : FALSE; - $instance['use_desc_for_title'] = $new_instance['use_desc_for_title'] ? TRUE : FALSE; - $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column'])); - $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order'])); - $instance['style'] = strip_tags(stripslashes($new_instance['style'])); - $instance['rssfeed'] = $new_instance['rssfeed'] ? TRUE : FALSE; - $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage'])); - - return $instance; - } - - /** Echo the settings update form - * - * @param array $instance Current settings - */ - function form ($instance) - { - // displays the widget admin form - $instance = wp_parse_args((array) $instance, array ( 'title' => '', 'rssimage' => '' )); - - // Prepare data for display - if (! $amount = (int) $instance['amount']) { - $amount = 5; - } - - if ($amount < 1) { - $amount = 1; - } - echo '<p>'; - avh_doWidgetFormText($this->get_field_id('title'), $this->get_field_name('title'), __('Title', 'avh-ec'), $instance['title']); - echo '</p>'; - - echo '<p>'; - avh_doWidgetFormText($this->get_field_id('amount'), $this->get_field_name('amount'), __('How many categories to show', 'avh-ec'), $amount); - echo '</p>'; - - echo '<p>'; - avh_doWidgetFormCheckbox($this->get_field_id('count'), $this->get_field_name('count'), __('Show post counts', 'avh-ec'), (bool) $instance['count']); - echo '<br />'; - - avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'), $this->get_field_name('use_desc_for_title'), __('Use description for title', 'avh-ec'), (bool) $instance['use_desc_for_title']); - echo '</p>'; - - echo '<p>'; - $options['ID'] = __('ID', 'avh-ec'); - $options['name'] = __('Name', 'avh-ec'); - $options['count'] = __('Count', 'avh-ec'); - $options['slug'] = __('Slug', 'avh-ec'); - avh_doWidgetFormSelect($this->get_field_id('sort_column'), $this->get_field_name('sort_column'), __('Sort by', 'avh-ec'), $options, $instance['sort_column']); - unset($options); - - $options['asc'] = __('Ascending', 'avh-ec'); - $options['desc'] = __('Descending', 'avh-ec'); - avh_doWidgetFormSelect($this->get_field_id('sort_order'), $this->get_field_name('sort_order'), __('Sort order', 'avh-ec'), $options, $instance['sort_order']); - unset($options); - - $options['list'] = __('List', 'avh-ec'); - $options['drop'] = __('Drop down', 'avh-ec'); - avh_doWidgetFormSelect($this->get_field_id('style'), $this->get_field_name('style'), __('Display style', 'avh-ec'), $options, $instance['style']); - unset($options); - echo '</p>'; - - echo '<p>'; - - avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), $this->get_field_name('rssfeed'), __('Show RSS Feed', 'avh-ec'), (bool) $instance['rssfeed']); - - avh_doWidgetFormText($this->get_field_id('rssimage'), $this->get_field_name('rssimage'), __('Path (URI) to RSS image', 'avh-ec'), $instance['rssimage']); - - echo '</p>'; - - echo '<input type="hidden" id="' . $this->get_field_id('submit') . '" name="' . $this->get_field_name('submit') . '" value="1" />'; - } -} - -/** - * Widget Class for displaying the grouped categories - * - */ -class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget -{ - /** - * - * @var AVH_EC_Core - */ - var $core; - - /** - * - * @var AVH_EC_Category_Group - */ - var $catgrp; - - /** - * PHP 5 Constructor - * - */ - function __construct () - { - $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core'); - $this->catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); - - $widget_ops = array ( 'description' => __("Shows grouped categories.", 'avh-ec') ); - WP_Widget::__construct(FALSE, 'AVH Extended Categories: ' . __('Category Group'), $widget_ops); - add_action('wp_print_styles', array ( &$this, 'actionWpPrintStyles' )); - - } - - function WP_Widget_AVH_ExtendedCategories_Category_Group () - { - $this->__construct(); - } - - function actionWpPrintStyles () - { - if (! (FALSE === is_active_widget(FALSE, FALSE, $this->id_base, TRUE))) { - wp_register_style('avhec-widget', AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', array (), $this->core->version); - wp_enqueue_style('avhec-widget'); - } - } - - /** - * Display the widget - * - * @param unknown_type $args - * @param unknown_type $instance - */ - function widget ($args, $instance) - { - global $post, $wp_query; - - $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); + $catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); $options = $this->core->getOptions(); - $row = array (); + $row = array(); if (is_home()) { $special_page = 'home_group'; @@ -592,79 +433,81 @@ class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget $special_page = 'none'; } - $toDisplay = FALSE; + $toDisplay = false; if ('none' == $special_page) { $terms = wp_get_object_terms($post->ID, $catgrp->taxonomy_name); - if (! empty($terms)) { + if ( ! empty($terms)) { $selected_catgroups = unserialize($instance['post_group_category']); foreach ($terms as $key => $value) { - if ($selected_catgroups === FALSE || array_key_exists($value->term_id, $selected_catgroups)) { - if (! ($this->getWidgetDoneCatGroup($value->term_id))) { - $row = $value; - $group_found = TRUE; + if ($selected_catgroups === false || array_key_exists($value->term_id, $selected_catgroups)) { + if ( ! ($this->getWidgetDoneCatGroup($value->term_id))) { + $row = $value; + $group_found = true; break; } } } } else { - $options = $this->core->options; + $options = $this->core->options; $no_cat_group = $options['cat_group']['no_group']; - $row = get_term_by('id', $no_cat_group, $catgrp->taxonomy_name); - $group_found = TRUE; + $row = get_term_by('id', $no_cat_group, $catgrp->taxonomy_name); + $group_found = true; } } else { if ('category_group' == $special_page) { $tax_meta = get_option($this->core->db_options_tax_meta); - $term = $wp_query->get_queried_object(); - if (isset($tax_meta[$term->taxonomy][$term->term_id]['category_group_term_id'])) { - $sp_category_group_id = $tax_meta[$term->taxonomy][$term->term_id]['category_group_term_id']; + $term = $wp_query->get_queried_object(); + if (isset($tax_meta[ $term->taxonomy ][ $term->term_id ]['category_group_term_id'])) { + $sp_category_group_id = $tax_meta[ $term->taxonomy ][ $term->term_id ]['category_group_term_id']; } else { - $sp_category_group = $this->catgrp->getGroupByCategoryID($term->term_id); + $sp_category_group = $this->catgrp->getGroupByCategoryID($term->term_id); $sp_category_group_id = $sp_category_group->term_id; } } else { - $sp_category_group_id = $options['sp_cat_group'][$special_page]; + $sp_category_group_id = $options['sp_cat_group'][ $special_page ]; } - $row = get_term_by('id', $sp_category_group_id, $catgrp->taxonomy_name); // Returns FALSE when non-existance. (empty(FALSE)=TRUE) - $group_found = TRUE; + $row = get_term_by('id', + $sp_category_group_id, + $catgrp->taxonomy_name); // Returns FALSE when non-existance. (empty(FALSE)=TRUE) + $group_found = true; } if ($group_found) { - $toDisplay = TRUE; + $toDisplay = true; $category_group_id_none = $this->catgrp->getTermIDBy('slug', 'none'); - $selected_catgroups = unserialize($instance['post_group_category']); + $selected_catgroups = unserialize($instance['post_group_category']); if ($category_group_id_none == $row->term_id) { - $toDisplay = FALSE; - } elseif (! (FALSE == $selected_catgroups || array_key_exists($row->term_id, $selected_catgroups))) { - $toDisplay = FALSE; + $toDisplay = false; + } elseif ( ! (false == $selected_catgroups || array_key_exists($row->term_id, $selected_catgroups))) { + $toDisplay = false; } elseif ($special_page != 'none' && $this->getWidgetDoneCatGroup($sp_category_group_id)) { - $toDisplay = FALSE; + $toDisplay = false; } } if ($toDisplay) { extract($args); - $c = $instance['count'] ? TRUE : FALSE; - $e = $instance['hide_empty'] ? TRUE : FALSE; - $h = $instance['hierarchical'] ? TRUE : FALSE; - $use_desc_for_title = $instance['use_desc_for_title'] ? TRUE : FALSE; - $s = $instance['sort_column'] ? $instance['sort_column'] : 'name'; - $o = $instance['sort_order'] ? $instance['sort_order'] : 'asc'; - $r = $instance['rssfeed'] ? 'RSS' : ''; - $i = $instance['rssimage'] ? $instance['rssimage'] : ''; + $c = $instance['count'] ? true : false; + $e = $instance['hide_empty'] ? true : false; + $h = $instance['hierarchical'] ? true : false; + $use_desc_for_title = $instance['use_desc_for_title'] ? true : false; + $s = $instance['sort_column'] ? $instance['sort_column'] : 'name'; + $o = $instance['sort_order'] ? $instance['sort_order'] : 'asc'; + $r = $instance['rssfeed'] ? 'RSS' : ''; + $i = $instance['rssimage'] ? $instance['rssimage'] : ''; if (empty($r)) { $i = ''; } - $style = empty($instance['style']) ? 'list' : $instance['style']; + $style = empty($instance['style']) ? 'list' : $instance['style']; $group_id = $row->term_id; - $cats = $catgrp->getCategoriesFromGroup($group_id); + $cats = $catgrp->getCategoriesFromGroup($group_id); if (empty($instance['title'])) { $title = $catgrp->getWidgetTitleForGroup($group_id); - if (! $title) { + if ( ! $title) { $title = __('Categories', 'avh-ec'); } } else { @@ -679,65 +522,161 @@ class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget $show_option_none = $options['general']['alternative_name_select_category']; } - $cat_args = array ( 'include' => $included_cats, 'orderby' => $s, 'order' => $o, 'show_count' => $c, 'use_desc_for_title' => $use_desc_for_title, 'hide_empty' => $e, 'hierarchical' => $h, 'title_li' => '', 'show_option_none' => $show_option_none, 'feed' => $r, 'feed_image' => $i, 'name' => 'extended-categories-select-group-' . $this->number ); + $cat_args = array( + 'include' => $included_cats, + 'orderby' => $s, + 'order' => $o, + 'show_count' => $c, + 'use_desc_for_title' => $use_desc_for_title, + 'hide_empty' => $e, + 'hierarchical' => $h, + 'title_li' => '', + 'show_option_none' => $show_option_none, + 'feed' => $r, + 'feed_image' => $i, + 'name' => 'extended-categories-select-group-' . $this->number + ); echo $before_widget; echo $this->core->comment; echo $before_title . $title . $after_title; if ($style == 'list') { echo '<ul>'; - $this->core->avh_wp_list_categories($cat_args, TRUE); + $this->core->avh_wp_list_categories($cat_args, true); echo '</ul>'; } else { - $this->core->avh_wp_dropdown_categories($cat_args, TRUE); + $this->core->avh_wp_dropdown_categories($cat_args, true); echo '<script type=\'text/javascript\'>' . "\n"; echo '/* <![CDATA[ */' . "\n"; - echo ' var ec_dropdown_' . $this->number . ' = document.getElementById("extended-categories-select-group-' . $this->number . '");' . "\n"; + echo ' var ec_dropdown_' . + $this->number . + ' = document.getElementById("extended-categories-select-group-' . + $this->number . + '");' . + "\n"; echo ' function ec_onCatChange_' . $this->number . '() {' . "\n"; - echo ' if ( ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value > 0 ) {' . "\n"; - echo ' location.href = "' . get_option('home') . '/?cat="+ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value;' . "\n"; + echo ' if ( ec_dropdown_' . + $this->number . + '.options[ec_dropdown_' . + $this->number . + '.selectedIndex].value > 0 ) {' . + "\n"; + echo ' location.href = "' . + get_option('home') . + '/?cat="+ec_dropdown_' . + $this->number . + '.options[ec_dropdown_' . + $this->number . + '.selectedIndex].value;' . + "\n"; echo ' }' . "\n"; echo ' }' . "\n"; - echo ' ec_dropdown_' . $this->number . '.onchange = ec_onCatChange_' . $this->number . ';' . "\n"; + echo ' ec_dropdown_' . + $this->number . + '.onchange = ec_onCatChange_' . + $this->number . + ';' . + "\n"; echo '/* ]]> */' . "\n"; echo '</script>' . "\n"; } echo $after_widget; } } +} +/** + * Widget Class for displaying categories. Extended version of the dfeault categories. + */ +class WP_Widget_AVH_ExtendedCategories_Normal extends WP_Widget { /** - * When Widget Control Form Is Posted - * - * @param unknown_type $new_instance - * @param unknown_type $old_instance - * @return unknown + * @var AVH_EC_Core */ - function update ($new_instance, $old_instance) - { - // update the instance's settings - if (! isset($new_instance['submit'])) { - return FALSE; + var $core; + + /** + * PHP 5 Constructor + */ + function __construct() { + $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core'); + + //Convert the old option widget_extended_categories to widget_extended-categories + $old = get_option('widget_extended_categories'); + if ( ! (false === $old)) { + update_option('widget_extended-categories', $old); + delete_option('widget_extended_categories'); } + $widget_ops = array('description' => __("An extended version of the default Categories widget.", 'avh-ec')); + WP_Widget::__construct('extended-categories', 'AVH Extended Categories', $widget_ops); - $instance = $old_instance; + add_action('wp_print_styles', array(&$this, 'actionWpPrintStyles')); + } - $instance['title'] = strip_tags(stripslashes($new_instance['title'])); - $instance['count'] = $new_instance['count'] ? TRUE : FALSE; - $instance['hierarchical'] = $new_instance['hierarchical'] ? TRUE : FALSE; - $instance['hide_empty'] = $new_instance['hide_empty'] ? TRUE : FALSE; - $instance['use_desc_for_title'] = $new_instance['use_desc_for_title'] ? TRUE : FALSE; - $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column'])); - $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order'])); - $instance['style'] = strip_tags(stripslashes($new_instance['style'])); - $instance['rssfeed'] = $new_instance['rssfeed'] ? TRUE : FALSE; - $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage'])); - if (array_key_exists('all', $new_instance['post_group_category'])) { - $instance['post_group_category'] = FALSE; + function WP_Widget_AVH_ExtendedCategories_Normal() { + $this->__construct(); + } + + function actionWpPrintStyles() { + + if ( ! (false === is_active_widget(false, false, $this->id_base, true))) { + wp_register_style('avhec-widget', + AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', + array(), + $this->core->version); + wp_enqueue_style('avhec-widget'); + } + } + + /** + * Creates the categories checklist + * + * @param int $post_id + * @param int $descendants_and_self + * @param array $selected_cats + * @param array $popular_cats + * @param int $number + */ + function avh_wp_category_checklist($selected_cats, $number) { + + $walker = new AVH_Walker_Category_Checklist(); + $walker->number = $number; + $walker->input_id = $this->get_field_id('post_category'); + $walker->input_name = $this->get_field_name('post_category'); + $walker->li_id = $this->get_field_id('category--1'); + + $args = array( + 'taxonomy' => 'category', + 'descendants_and_self' => 0, + 'selected_cats' => $selected_cats, + 'popular_cats' => array(), + 'walker' => $walker, + 'checked_ontop' => true, + 'popular_cats' => array() + ); + + if (is_array($selected_cats)) { + $args['selected_cats'] = $selected_cats; } else { - $instance['post_group_category'] = serialize($new_instance['post_group_category']); + $args['selected_cats'] = array(); } - return $instance; + + $categories = $this->core->getCategories(); + $_categories_id = $this->core->getCategoriesId($categories); + + // 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) + $checked_categories = array(); + foreach ($args['selected_cats'] as $key => $value) { + if (isset($_categories_id[ $key ])) { + $category_key = $_categories_id[ $key ]; + $checked_categories[] = $categories[ $category_key ]; + unset($categories[ $category_key ]); + } + } + + // Put checked cats on top + echo $walker->walk($checked_categories, 0, array($args)); + // Then the rest of them + echo $walker->walk($categories, 0, array($args)); } /** @@ -745,260 +684,578 @@ class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget * * @param unknown_type $instance */ - function form ($instance) - { + function form($instance) { // displays the widget admin form - $instance = wp_parse_args((array) $instance, array ( 'title' => '', 'rssimage' => '' )); + $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => '', 'depth' => 0)); // Prepare data for display - $title = esc_attr($instance['title']); - $count = (bool) $instance['count']; - $hierarchical = (bool) $instance['hierarchical']; - $hide_empty = (bool) $instance['hide_empty']; - $use_desc_for_title = (bool) $instance['use_desc_for_title']; - $sort_id = ($instance['sort_column'] == 'ID') ? ' SELECTED' : ''; - $sort_name = ($instance['sort_column'] == 'name') ? ' SELECTED' : ''; - $sort_count = ($instance['sort_column'] == 'count') ? ' SELECTED' : ''; - $sort_order_a = ($instance['sort_order'] == 'asc') ? ' SELECTED' : ''; - $sort_order_d = ($instance['sort_order'] == 'desc') ? ' SELECTED' : ''; - $style_list = ($instance['style'] == 'list') ? ' SELECTED' : ''; - $style_drop = ($instance['style'] == 'drop') ? ' SELECTED' : ''; - $rssfeed = (bool) $instance['rssfeed']; - $rssimage = esc_attr($instance['rssimage']); - - $selected_cats = ($instance['post_group_category'] != '') ? unserialize($instance['post_group_category']) : FALSE; - ob_start(); + $depth = (int) $instance['depth']; + if ($depth < 0 || 11 < $depth) { + $depth = 0; + } + $selected_cats = ($instance['post_category'] != '') ? unserialize($instance['post_category']) : false; + echo '<p>'; - avh_doWidgetFormText($this->get_field_id('title'), $this->get_field_name('title'), __('Title', 'avh-ec'), $instance['title']); + avh_doWidgetFormText($this->get_field_id('title'), + $this->get_field_name('title'), + __('Title', 'avh-ec'), + $instance['title']); echo '</p>'; echo '<p>'; + avh_doWidgetFormCheckbox($this->get_field_id('selectedonly'), + $this->get_field_name('selectedonly'), + __('Show selected categories only', 'avh-ec'), + (bool) $instance['selectedonly']); + + avh_doWidgetFormCheckbox($this->get_field_id('count'), + $this->get_field_name('count'), + __('Show post counts', 'avh-ec'), + (bool) $instance['count']); + + avh_doWidgetFormCheckbox($this->get_field_id('hierarchical'), + $this->get_field_name('hierarchical'), + __('Show hierarchy', 'avh-ec'), + (bool) $instance['hierarchical']); + + $options = array(0 => __('All Levels', 'avh-ec'), 1 => __('Toplevel only', 'avh-ec')); + for ($i = 2; $i <= 11; $i ++) { + $options[ $i ] = __('Child ', 'avh-ec') . ($i - 1); + } + avh_doWidgetFormSelect($this->get_field_id('depth'), + $this->get_field_name('depth'), + __('How many levels to show', 'avh-ec'), + $options, + $depth); + unset($options); - avh_doWidgetFormCheckbox($this->get_field_id('count'), $this->get_field_name('count'), __('Show post counts', 'avh-ec'), (bool) $instance['count']); - - avh_doWidgetFormCheckbox($this->get_field_id('hierarchical'), $this->get_field_name('hierarchical'), __('Show hierarchy', 'avh-ec'), (bool) $instance['hierarchical']); - - avh_doWidgetFormCheckbox($this->get_field_id('hide_empty'), $this->get_field_name('hide_empty'), __('Hide empty categories', 'avh-ec'), (bool) $instance['hide_empty']); + avh_doWidgetFormCheckbox($this->get_field_id('hide_empty'), + $this->get_field_name('hide_empty'), + __('Hide empty categories', 'avh-ec'), + (bool) $instance['hide_empty']); - avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'), $this->get_field_name('use_desc_for_title'), __('Use description for title', 'avh-ec'), (bool) $instance['use_desc_for_title']); + avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'), + $this->get_field_name('use_desc_for_title'), + __('Use description for title', 'avh-ec'), + (bool) $instance['use_desc_for_title']); echo '</p>'; echo '<p>'; - $options['ID'] = __('ID', 'avh-ec'); - $options['name'] = __('Name', 'avh-ec'); - $options['count'] = __('Count', 'avh-ec'); - $options['slug'] = __('Slug', 'avh-ec'); - avh_doWidgetFormSelect($this->get_field_id('sort_column'), $this->get_field_name('sort_column'), __('Sort by', 'avh-ec'), $options, $instance['sort_column']); + $options['ID'] = __('ID', 'avh-ec'); + $options['name'] = __('Name', 'avh-ec'); + $options['count'] = __('Count', 'avh-ec'); + $options['slug'] = __('Slug', 'avh-ec'); + $options['avhec_manualorder'] = 'AVH EC ' . __('Manual Order', 'avh-ec'); + if (is_plugin_active('my-category-order/mycategoryorder.php')) { + $options['avhec_3rdparty_mycategoryorder'] = 'My Category Order'; + } + + avh_doWidgetFormSelect($this->get_field_id('sort_column'), + $this->get_field_name('sort_column'), + __('Sort by', 'avh-ec'), + $options, + $instance['sort_column']); unset($options); - $options['asc'] = __('Ascending', 'avh-ec'); + $options['asc'] = __('Ascending', 'avh-ec'); $options['desc'] = __('Descending', 'avh-ec'); - avh_doWidgetFormSelect($this->get_field_id('sort_order'), $this->get_field_name('sort_order'), __('Sort order', 'avh-ec'), $options, $instance['sort_order']); + avh_doWidgetFormSelect($this->get_field_id('sort_order'), + $this->get_field_name('sort_order'), + __('Sort order', 'avh-ec'), + $options, + $instance['sort_order']); unset($options); $options['list'] = __('List', 'avh-ec'); $options['drop'] = __('Drop down', 'avh-ec'); - avh_doWidgetFormSelect($this->get_field_id('style'), $this->get_field_name('style'), __('Display style', 'avh-ec'), $options, $instance['style']); + avh_doWidgetFormSelect($this->get_field_id('style'), + $this->get_field_name('style'), + __('Display style', 'avh-ec'), + $options, + $instance['style']); unset($options); echo '</p>'; echo '<p>'; - avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), $this->get_field_name('rssfeed'), __('Show RSS Feed', 'avh-ec'), (bool) $instance['rssfeed']); + avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), + $this->get_field_name('rssfeed'), + __('Show RSS Feed', 'avh-ec'), + (bool) $instance['rssfeed']); + + avh_doWidgetFormText($this->get_field_id('rssimage'), + $this->get_field_name('rssimage'), + __('Path (URI) to RSS image', 'avh-ec'), + $instance['rssimage']); - avh_doWidgetFormText($this->get_field_id('rssimage'), $this->get_field_name('rssimage'), __('Path (URI) to RSS image', 'avh-ec'), $instance['rssimage']); echo '</p>'; echo '<p>'; - echo '<b>' . __('Select Groups', 'avh-ec') . '</b><hr />'; + echo '<b>' . __('Select categories', 'avh-ec') . '</b><hr />'; 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;">'; - echo '<li id="' . $this->get_field_id('group_category--1') . '" class="popular-group_category">'; - echo '<label for="' . $this->get_field_id('group_post_category') . '" class="selectit">'; - 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' : '') . '> '; - _e('Any Group', 'avh-ec'); + echo '<li id="' . $this->get_field_id('category--1') . '" class="popular-category">'; + echo '<label for="' . $this->get_field_id('post_category') . '" class="selectit">'; + 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' : '') . + '> '; + _e('All Categories', 'avh-ec'); echo '</label>'; echo '</li>'; - - $this->avh_wp_group_category_checklist($selected_cats, $this->number); - + ob_start(); + $this->avh_wp_category_checklist($selected_cats, $this->number); + ob_end_flush(); echo '</ul>'; echo '</p>'; - echo '<input type="hidden" id="' . $this->get_field_id('submit') . '" name="' . $this->get_field_name('submit') . '" value="1" />'; - ob_end_flush(); + echo '<p>'; + avh_doWidgetFormCheckbox($this->get_field_id('invert_included'), + $this->get_field_name('invert_included'), + __('Exclude the selected categories', 'avh-ec'), + (bool) $instance['invert_included']); + echo '</p>'; + + echo '<input type="hidden" id="' . + $this->get_field_id('submit') . + '" name="' . + $this->get_field_name('submit') . + '" value="1" />'; } - function avh_wp_group_category_checklist ($selected_cats, $number) - { + /** + * When Widget Control Form Is Posted + * + * @param unknown_type $new_instance + * @param unknown_type $old_instance + * + * @return unknown + */ + function update($new_instance, $old_instance) { + // update the instance's settings + if ( ! isset($new_instance['submit'])) { + return false; + } - $walker = new AVH_Walker_Category_Checklist(); - $walker->number = $number; - $walker->input_id = $this->get_field_id('post_group_category'); - $walker->input_name = $this->get_field_name('post_group_category'); - $walker->li_id = $this->get_field_id('group_category--1'); + $instance = $old_instance; - $args = array ( 'taxonomy' => 'avhec_catgroup', 'descendants_and_self' => 0, 'selected_cats' => array (), 'popular_cats' => array (), 'walker' => $walker, 'checked_ontop' => true ); + $instance['title'] = strip_tags(stripslashes($new_instance['title'])); + $instance['selectedonly'] = $new_instance['selectedonly'] ? true : false; + $instance['count'] = $new_instance['count'] ? true : false; + $instance['hierarchical'] = $new_instance['hierarchical'] ? true : false; + $instance['hide_empty'] = $new_instance['hide_empty'] ? true : false; + $instance['use_desc_for_title'] = $new_instance['use_desc_for_title'] ? true : false; + $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column'])); + $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order'])); + $instance['style'] = strip_tags(stripslashes($new_instance['style'])); + $instance['rssfeed'] = $new_instance['rssfeed'] ? true : false; + $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage'])); + if (array_key_exists('all', $new_instance['post_category'])) { + $instance['post_category'] = false; + } else { + $instance['post_category'] = serialize($new_instance['post_category']); + } + $instance['depth'] = (int) $new_instance['depth']; + if ($instance['depth'] < 0 || 11 < $instance['depth']) { + $instance['depth'] = 0; + } + $instance['invert_included'] = $new_instance['invert_included'] ? true : false; - if (is_array($selected_cats)) - $args['selected_cats'] = $selected_cats; - else - $args['selected_cats'] = array (); + return $instance; + } - $categories = (array) get_terms($args['taxonomy'], array ( 'get' => 'all' )); + /** + * Display the widget + * + * @param unknown_type $args + * @param unknown_type $instance + */ + function widget($args, $instance) { - // 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) - $checked_categories = array (); - $keys = array_keys($categories); + extract($args); - foreach ($keys as $k) { - if (in_array($categories[$k]->term_id, $args['selected_cats'])) { - $checked_categories[] = $categories[$k]; - unset($categories[$k]); + $selectedonly = $instance['selectedonly'] ? true : false; + $c = $instance['count'] ? true : false; + $h = $instance['hierarchical'] ? true : false; + $d = $instance['depth'] ? $instance['depth'] : 0; + $e = $instance['hide_empty'] ? true : false; + $use_desc_for_title = $instance['use_desc_for_title'] ? true : false; + $s = $instance['sort_column'] ? $instance['sort_column'] : 'name'; + $o = $instance['sort_order'] ? $instance['sort_order'] : 'asc'; + $r = $instance['rssfeed'] ? 'RSS' : ''; + $i = $instance['rssimage'] ? $instance['rssimage'] : ''; + $invert = $instance['invert_included'] ? true : false; + + if (empty($r)) { + $i = ''; + } + + if (empty($d)) { + $d = 0; + } + + $title = apply_filters('widget_title', + empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']); + $style = empty($instance['style']) ? 'list' : $instance['style']; + + $included_cats = ''; + if ($instance['post_category']) { + $post_category = unserialize($instance['post_category']); + $children = array(); + if ( ! $instance['selectedonly']) { + foreach ($post_category as $cat_id) { + $children = array_merge($children, get_term_children($cat_id, 'category')); + } } + $included_cats = implode(",", array_merge($post_category, $children)); } - // Put checked cats on top - echo $walker->walk($checked_categories, 0, array ( $args )); - // Then the rest of them - echo $walker->walk($categories, 0, array ( $args )); - } + if ($invert) { + $inc_exc = 'exclude'; + } else { + $inc_exc = 'include'; + } - function getWidgetDoneCatGroup ($id) - { - $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); - if (is_array($catgrp->widget_done_catgroup) && array_key_exists($id, $catgrp->widget_done_catgroup)) { - return TRUE; + $options = $this->core->getOptions(); + $show_option_none = __('Select Category', 'avh-ec'); + if ($options['general']['alternative_name_select_category']) { + $show_option_none = $options['general']['alternative_name_select_category']; + } + + $cat_args = array( + $inc_exc => $included_cats, + 'orderby' => $s, + 'order' => $o, + 'show_count' => $c, + 'use_desc_for_title' => $use_desc_for_title, + 'hide_empty' => $e, + 'hierarchical' => $h, + 'depth' => $d, + 'title_li' => '', + 'show_option_none' => $show_option_none, + 'feed' => $r, + 'feed_image' => $i, + 'name' => 'extended-categories-select-' . $this->number + ); + echo $before_widget; + echo $this->core->comment; + echo $before_title . $title . $after_title; + + if ($style == 'list') { + echo '<ul>'; + $this->core->avh_wp_list_categories($cat_args, $selectedonly); + echo '</ul>'; + } else { + $this->core->avh_wp_dropdown_categories($cat_args, $selectedonly); + echo '<script type=\'text/javascript\'>' . "\n"; + echo '/* <![CDATA[ */' . "\n"; + echo ' var ec_dropdown_' . + $this->number . + ' = document.getElementById("extended-categories-select-' . + $this->number . + '");' . + "\n"; + echo ' function ec_onCatChange_' . $this->number . '() {' . "\n"; + echo ' if ( ec_dropdown_' . + $this->number . + '.options[ec_dropdown_' . + $this->number . + '.selectedIndex].value > 0 ) {' . + "\n"; + echo ' location.href = "' . + home_url() . + '/?cat="+ec_dropdown_' . + $this->number . + '.options[ec_dropdown_' . + $this->number . + '.selectedIndex].value;' . + "\n"; + echo ' }' . "\n"; + echo ' }' . "\n"; + echo ' ec_dropdown_' . + $this->number . + '.onchange = ec_onCatChange_' . + $this->number . + ';' . + "\n"; + echo '/* ]]> */' . "\n"; + echo '</script>' . "\n"; } - $catgrp->widget_done_catgroup[$id] = TRUE; - return FALSE; + echo $after_widget; } } /** - * Class that will display the categories - * + * Widget Class for displaying the top categories */ -class AVH_Walker_Category_Checklist extends Walker -{ - var $tree_type = 'category'; - var $db_fields = array ( 'parent' => 'parent', 'id' => 'term_id' ); //TODO: decouple this - var $number; - var $input_id; - var $input_name; - var $li_id; +class WP_Widget_AVH_ExtendedCategories_Top extends WP_Widget { + /** + * @var AVH_EC_Core + */ + var $core; /** - * Display array of elements hierarchically. - * - * It is a generic function which does not assume any existing order of - * elements. max_depth = -1 means flatly display every element. max_depth = - * 0 means display all levels. max_depth > 0 specifies the number of - * display levels. - * - * @since 2.1.0 - * - * @param array $elements - * @param int $max_depth - * @param array $args; - * @return string + * PHP 5 Constructor */ - function walk ($elements, $max_depth, $args) - { + function __construct() { + $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core'); - $output = ''; + $widget_ops = array('description' => __("Shows the top categories.", 'avh-ec')); + WP_Widget::__construct(false, 'AVH Extended Categories: ' . __('Top Categories'), $widget_ops); + add_action('wp_print_styles', array(&$this, 'actionWpPrintStyles')); + } - if ($max_depth < - 1) //invalid parameter - return $output; + function WP_Widget_AVH_ExtendedCategories_Top() { + $this->__construct(); + } - if (empty($elements)) //nothing to walk - return $output; + function actionWpPrintStyles() { + if ( ! (false === is_active_widget(false, false, $this->id_base, true))) { + wp_register_style('avhec-widget', + AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', + array(), + $this->core->version); + wp_enqueue_style('avhec-widget'); + } + } - $id_field = $this->db_fields['id']; - $parent_field = $this->db_fields['parent']; + /** Echo the settings update form + * + * @param array $instance Current settings + */ + function form($instance) { + // displays the widget admin form + $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => '')); - // flat display - if (- 1 == $max_depth) { - $empty_array = array (); - foreach ($elements as $e) - $this->display_element($e, $empty_array, 1, 0, $args, $output); - return $output; + // Prepare data for display + if ( ! $amount = (int) $instance['amount']) { + $amount = 5; } - /* - * 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. - */ - $top_level_elements = array (); - $children_elements = array (); - foreach ($elements as $e) { - if (0 == $e->$parent_field) - $top_level_elements[] = $e; - else - $children_elements[$e->$parent_field][] = $e; + if ($amount < 1) { + $amount = 1; } + echo '<p>'; + avh_doWidgetFormText($this->get_field_id('title'), + $this->get_field_name('title'), + __('Title', 'avh-ec'), + $instance['title']); + echo '</p>'; - /* - * when none of the elements is top level - * assume the first one must be root of the sub elements - */ - if (empty($top_level_elements)) { + echo '<p>'; + avh_doWidgetFormText($this->get_field_id('amount'), + $this->get_field_name('amount'), + __('How many categories to show', 'avh-ec'), + $amount); + echo '</p>'; - $first = array_slice($elements, 0, 1); - $root = $first[0]; + echo '<p>'; + avh_doWidgetFormCheckbox($this->get_field_id('count'), + $this->get_field_name('count'), + __('Show post counts', 'avh-ec'), + (bool) $instance['count']); + echo '<br />'; - $top_level_elements = array (); - $children_elements = array (); - foreach ($elements as $e) { - if ($root->$parent_field == $e->$parent_field) - $top_level_elements[] = $e; - else - $children_elements[$e->$parent_field][] = $e; - } - } + avh_doWidgetFormCheckbox($this->get_field_id('use_desc_for_title'), + $this->get_field_name('use_desc_for_title'), + __('Use description for title', 'avh-ec'), + (bool) $instance['use_desc_for_title']); + echo '</p>'; - foreach ($top_level_elements as $e) - $this->display_element($e, $children_elements, $max_depth, 0, $args, $output); + echo '<p>'; + $options['ID'] = __('ID', 'avh-ec'); + $options['name'] = __('Name', 'avh-ec'); + $options['count'] = __('Count', 'avh-ec'); + $options['slug'] = __('Slug', 'avh-ec'); + avh_doWidgetFormSelect($this->get_field_id('sort_column'), + $this->get_field_name('sort_column'), + __('Sort by', 'avh-ec'), + $options, + $instance['sort_column']); + unset($options); - /* - * if we are displaying all levels, and remaining children_elements is not empty, - * then we got orphans, which should be displayed regardless - */ - if (($max_depth == 0) && count($children_elements) > 0) { - $empty_array = array (); - foreach ($children_elements as $orphans) - foreach ($orphans as $op) - $this->display_element($op, $empty_array, 1, 0, $args, $output); - } + $options['asc'] = __('Ascending', 'avh-ec'); + $options['desc'] = __('Descending', 'avh-ec'); + avh_doWidgetFormSelect($this->get_field_id('sort_order'), + $this->get_field_name('sort_order'), + __('Sort order', 'avh-ec'), + $options, + $instance['sort_order']); + unset($options); - return $output; - } + $options['list'] = __('List', 'avh-ec'); + $options['drop'] = __('Drop down', 'avh-ec'); + avh_doWidgetFormSelect($this->get_field_id('style'), + $this->get_field_name('style'), + __('Display style', 'avh-ec'), + $options, + $instance['style']); + unset($options); + echo '</p>'; - function start_lvl (&$output, $depth, $args) - { - $indent = str_repeat("\t", $depth); - $output .= $indent . '<ul class="children">' . "\n"; + echo '<p>'; + + avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), + $this->get_field_name('rssfeed'), + __('Show RSS Feed', 'avh-ec'), + (bool) $instance['rssfeed']); + + avh_doWidgetFormText($this->get_field_id('rssimage'), + $this->get_field_name('rssimage'), + __('Path (URI) to RSS image', 'avh-ec'), + $instance['rssimage']); + + echo '</p>'; + + echo '<input type="hidden" id="' . + $this->get_field_id('submit') . + '" name="' . + $this->get_field_name('submit') . + '" value="1" />'; } - function end_lvl (&$output, $depth, $args) - { - $indent = str_repeat("\t", $depth); - $output .= $indent . '</ul>' . "\n"; + /** Update a particular instance. + * This function should check that $new_instance is set correctly. + * The newly calculated value of $instance should be returned. + * If "FALSE" is returned, the instance won't be saved/updated. + * + * @param array $new_instance New settings for this instance as input by the user via form() + * @param array $old_instance Old settings for this instance + * + * @return array Settings to save or bool FALSE to cancel saving + */ + function update($new_instance, $old_instance) { + // update the instance's settings + if ( ! isset($new_instance['submit'])) { + return false; + } + + $instance = $old_instance; + + $instance['title'] = strip_tags(stripslashes($new_instance['title'])); + $instance['amount'] = (int) $new_instance['amount']; + $instance['count'] = $new_instance['count'] ? true : false; + $instance['use_desc_for_title'] = $new_instance['use_desc_for_title'] ? true : false; + $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column'])); + $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order'])); + $instance['style'] = strip_tags(stripslashes($new_instance['style'])); + $instance['rssfeed'] = $new_instance['rssfeed'] ? true : false; + $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage'])); + + return $instance; } - function start_el (&$output, $category, $depth, $args) - { + /** Echo the widget content. + * Subclasses should over-ride this function to generate their widget code. + * + * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget. + * @param array $instance The settings for the particular instance of the widget + */ + function widget($args, $instance) { extract($args); - $input_id = $this->input_id . '-' . $category->term_id; - $output .= "\n" . '<li id="' . $this->li_id . '">'; - $output .= '<label for="' . $input_id . '" class="selectit">'; - $output .= '<input value="' . $category->term_id . '" type="checkbox" name="' . $this->input_name . '[' . $category->term_id . ']" id="' . $input_id . '"' . (in_array($category->term_id, $selected_cats) ? ' checked="checked"' : "") . '/> ' . esc_html(apply_filters('the_category', $category->name)) . '</label>'; - } - function end_el (&$output, $category, $depth, $args) - { - $output .= "</li>\n"; + $title = apply_filters('widget_title', + empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']); + $style = empty($instance['style']) ? 'list' : $instance['style']; + if ( ! $a = (int) $instance['amount']) { + $a = 5; + } elseif ($a < 1) { + $a = 1; + } + $c = $instance['count'] ? true : false; + $use_desc_for_title = $instance['use_desc_for_title'] ? true : false; + $s = $instance['sort_column'] ? $instance['sort_column'] : 'name'; + $o = $instance['sort_order'] ? $instance['sort_order'] : 'asc'; + $r = $instance['rssfeed'] ? 'RSS' : ''; + $i = $instance['rssimage'] ? $instance['rssimage'] : ''; + if (empty($r)) { + $i = ''; + } + if ( ! empty($i)) { + if ( ! file_exists(ABSPATH . '/' . $i)) { + $i = ''; + } + } + + $options = $this->core->getOptions(); + $show_option_none = __('Select Category', 'avh-ec'); + if ($options['general']['alternative_name_select_category']) { + $show_option_none = $options['general']['alternative_name_select_category']; + } + + $top_cats = get_terms('category', + array( + 'fields' => 'ids', + 'orderby' => 'count', + 'order' => 'DESC', + 'number' => $a, + 'hierarchical' => false + )); + $included_cats = implode(",", $top_cats); + + $cat_args = array( + 'include' => $included_cats, + 'orderby' => $s, + 'order' => $o, + 'show_count' => $c, + 'use_desc_for_title' => $use_desc_for_title, + 'hide_empty' => false, + 'hierarchical' => false, + 'depth' => - 1, + 'title_li' => '', + 'show_option_none' => $show_option_none, + 'feed' => $r, + 'feed_image' => $i, + 'name' => 'extended-categories-top-select-' . $this->number + ); + echo $before_widget; + echo $this->core->comment; + echo $before_title . $title . $after_title; + echo '<ul>'; + + if ($style == 'list') { + wp_list_categories($cat_args); + } else { + wp_dropdown_categories($cat_args); + echo '<script type=\'text/javascript\'>' . "\n"; + echo '/* <![CDATA[ */' . "\n"; + echo ' var ec_dropdown_top_' . + $this->number . + ' = document.getElementById("extended-categories-top-select-' . + $this->number . + '");' . + "\n"; + echo ' function ec_top_onCatChange_' . $this->number . '() {' . "\n"; + echo ' if ( ec_dropdown_top_' . + $this->number . + '.options[ec_dropdown_top_' . + $this->number . + '.selectedIndex].value > 0 ) {' . + "\n"; + echo ' location.href = "' . + get_option('home') . + '/?cat="+ec_dropdown_top_' . + $this->number . + '.options[ec_dropdown_top_' . + $this->number . + '.selectedIndex].value;' . + "\n"; + echo ' }' . "\n"; + echo ' }' . "\n"; + echo ' ec_dropdown_top_' . + $this->number . + '.onchange = ec_top_onCatChange_' . + $this->number . + ';' . + "\n"; + echo '/* ]]> */' . "\n"; + echo '</script>' . "\n"; + } + echo '</ul>'; + echo $after_widget; } } + ?> \ No newline at end of file diff --git a/wp-content/plugins/extended-categories-widget/3.3/css/avh-ec.admin.css b/wp-content/plugins/extended-categories-widget/3.3/css/avh-ec.admin.css index d7c05485be8dc186eefc41d1779362a695a6a318..0f7618c793f04d786a975d9776e200d1434cfaea 100644 --- a/wp-content/plugins/extended-categories-widget/3.3/css/avh-ec.admin.css +++ b/wp-content/plugins/extended-categories-widget/3.3/css/avh-ec.admin.css @@ -1,13 +1,13 @@ .footer_avhec { - font-size: 0.8em; - text-align: center; + font-size : 0.8em; + text-align : center; } div.clearer { - clear: both; - line-height: 1px; - font-size: 1px; - height: 1px; + clear : both; + line-height : 1px; + font-size : 1px; + height : 1px; } /* Metabox in General */ @@ -20,12 +20,12 @@ table.avhec-options { } .avhec-metabox-wrap .p { - line-height: 140%; - margin: 1em 0; + line-height : 140%; + margin : 1em 0; } #avhecBoxOptions option { - padding: .5em; + padding : .5em; } .avhec-metabox-wrap span.description { @@ -33,17 +33,17 @@ table.avhec-options { } .avhec-metabox-wrap .b { - font-weight: bold; + font-weight : bold; } .avhec-metabox-wrap ul { - margin-bottom: 1em; + margin-bottom : 1em; } .avhec-metabox-wrap ul li { - line-height: 120%; - list-style: disc inside none; - margin-bottom: 0; + line-height : 120%; + list-style : disc inside none; + margin-bottom : 0; } #avhec-options input { @@ -56,13 +56,13 @@ table.avhec-options { /* Metabox FAQ */ #avhecBoxFAQ .inside ul { - margin-bottom: 6px; + margin-bottom : 6px; } #avhecBoxFAQ .inside ul li { - line-height: 120%; - list-style: disc inside none; - margin-bottom: 0; + line-height : 120%; + list-style : disc inside none; + margin-bottom : 0; } /* Metabox Donations*/ @@ -71,7 +71,7 @@ table.avhec-options { } #avhecBoxDonations .versions { - padding: 6px 10px 12px; + padding : 6px 10px 12px; } /* Metabox Donations*/ @@ -81,75 +81,75 @@ table.avhec-options { /* Metabox in post and page */ #post_avhec_category_group { - width: 100%; + width : 100%; } #avhec-catlist { - -moz-border-radius: 4px 4px 4px 4px; - background-color: #FFFFFF; - border: 1px solid #DFDFDF; - height: 20em; - margin-bottom: -1.8em; - overflow: auto; - width: 95%; + -moz-border-radius : 4px 4px 4px 4px; + background-color : #FFFFFF; + border : 1px solid #DFDFDF; + height : 20em; + margin-bottom : -1.8em; + overflow : auto; + width : 95%; } #avhec-catlist ul { - padding: 3px; + padding : 3px; } #avhec-catlist li ul { - padding: 0px; + padding : 0px; } #avhec-catlist li { - margin-bottom: 0px; + margin-bottom : 0px; } #avhecManualOrder { - width: 25%; - /* border: 1px solid #B2B2B2;*/ - /* margin: 10px 10px 10px 0px;*/ - /* padding: 5px 10px 5px 10px;*/ - /* list-style: none;*/ - /* background-color: #fff;*/ - /* border-radius: 3px;*/ - /* -webkit-border-radius: 3px;*/ + width : 25%; + /* border: 1px solid #B2B2B2;*/ + /* margin: 10px 10px 10px 0px;*/ + /* padding: 5px 10px 5px 10px;*/ + /* list-style: none;*/ + /* background-color: #fff;*/ + /* border-radius: 3px;*/ + /* -webkit-border-radius: 3px;*/ } #avhecManualOrder li.lineitem { - border: 1px solid #DFDFDF; - background-image: none; - border-radius: 3px; - -webkit-border-radius: 3px; - background-color: #FFFFFF; - color: #555555; - cursor: move; - margin-top: 5px; - margin-bottom: 5px; - padding: 2px 5px 2px 5px; - list-style: none outside none; + border : 1px solid #DFDFDF; + background-image : none; + border-radius : 3px; + -webkit-border-radius : 3px; + background-color : #FFFFFF; + color : #555555; + cursor : move; + margin-top : 5px; + margin-bottom : 5px; + padding : 2px 5px 2px 5px; + list-style : none outside none; } #avhecManualOrder .sortable-placeholder { - border: 1px dashed #B2B2B2; - margin-top: 5px; - margin-bottom: 5px; - padding: 2px 5px 2px 5px; - height: 1.5em; - line-height: 1.5em; - list-style: none outside none; - background-color: transparent; - /* IE10 */ - background-image: -ms-linear-gradient(top, #f9f9f9, #f5f5f5); - /* Firefox */ - background-image: -moz-linear-gradient(top, #f9f9f9, #f5f5f5); - /* Opera */ - background-image: -o-linear-gradient(top, #f9f9f9, #f5f5f5); - /* old Webkit */ - background-image: -webkit-gradient(linear, left top, left bottom, from(#f9f9f9), to(#f5f5f5) ); - /* new Webkit */ - background-image: -webkit-linear-gradient(top, #f9f9f9, #f5f5f5); - /* proposed W3C Markup */ - background-image: linear-gradient(top, #f9f9f9, #f5f5f5); + border : 1px dashed #B2B2B2; + margin-top : 5px; + margin-bottom : 5px; + padding : 2px 5px 2px 5px; + height : 1.5em; + line-height : 1.5em; + list-style : none outside none; + background-color : transparent; + /* IE10 */ + background-image : -ms-linear-gradient(top, #f9f9f9, #f5f5f5); + /* Firefox */ + background-image : -moz-linear-gradient(top, #f9f9f9, #f5f5f5); + /* Opera */ + background-image : -o-linear-gradient(top, #f9f9f9, #f5f5f5); + /* old Webkit */ + background-image : -webkit-gradient(linear, left top, left bottom, from(#f9f9f9), to(#f5f5f5)); + /* new Webkit */ + background-image : -webkit-linear-gradient(top, #f9f9f9, #f5f5f5); + /* proposed W3C Markup */ + background-image : linear-gradient(top, #f9f9f9, #f5f5f5); } \ No newline at end of file diff --git a/wp-content/plugins/extended-categories-widget/3.3/css/avh-ec.widget.css b/wp-content/plugins/extended-categories-widget/3.3/css/avh-ec.widget.css index 25a86492027158e2aee27e65b763b3f122d7d27d..fbb382083b1a92d03aa554a7e75d3191d561ee44 100644 --- a/wp-content/plugins/extended-categories-widget/3.3/css/avh-ec.widget.css +++ b/wp-content/plugins/extended-categories-widget/3.3/css/avh-ec.widget.css @@ -1,12 +1,12 @@ /* AVH Extended Categories Widget CSS */ .avhec-widget-line { - display: inline-block; + display : inline-block; } .avhec-widget-count { - display: inline; + display : inline; } .avhec-widget-rss { - display: inline; + display : inline; } \ No newline at end of file diff --git a/wp-content/plugins/extended-categories-widget/3.3/helpers/avh-forms.php b/wp-content/plugins/extended-categories-widget/3.3/helpers/avh-forms.php index ff3b54e434fe8a2a3e9d482c78bccefdf46750c4..55194fcd5fc0c07c99dd8ae644603d3548a83b4f 100644 --- a/wp-content/plugins/extended-categories-widget/3.3/helpers/avh-forms.php +++ b/wp-content/plugins/extended-categories-widget/3.3/helpers/avh-forms.php @@ -1,40 +1,56 @@ <?php -if (! function_exists('avh_doWidgetFormText')) { +if ( ! function_exists('avh_doWidgetFormText')) { - function avh_doWidgetFormText ($field_id, $field_name, $description, $value) - { + function avh_doWidgetFormText($field_id, $field_name, $description, $value) { echo '<label for="' . $field_id . '">'; echo $description; - echo '<input class="widefat" id="' . $field_id . '" name="' . $field_name . '" type="text" value="' . esc_attr($value) . '" /> '; + echo '<input class="widefat" id="' . + $field_id . + '" name="' . + $field_name . + '" type="text" value="' . + esc_attr($value) . + '" /> '; echo '</label>'; echo '<br />'; } } -if (! function_exists('avh_doWidgetFormCheckbox')) { +if ( ! function_exists('avh_doWidgetFormCheckbox')) { + + function avh_doWidgetFormCheckbox($field_id, $field_name, $description, $is_checked = false) { - function avh_doWidgetFormCheckbox ($field_id, $field_name, $description, $is_checked = FALSE) - { - echo '<label for="' . $field_id . '">'; - echo '<input class="checkbox" type="checkbox" id="' . $field_id . '" name="' . $field_name . '"' . ($is_checked ? ' CHECKED' : '') . ' /> '; + echo '<input class="checkbox" type="checkbox" id="' . + $field_id . + '" name="' . + $field_name . + '"' . + ($is_checked ? ' CHECKED' : '') . + ' /> '; echo $description; echo '</label>'; echo '<br />'; } } -if (! function_exists('avh_doWidgetFormSelect')) { +if ( ! function_exists('avh_doWidgetFormSelect')) { - function avh_doWidgetFormSelect ($field_id, $field_name, $description, $options, $selected_value) - { + function avh_doWidgetFormSelect($field_id, $field_name, $description, $options, $selected_value) { echo '<label for="' . $field_id . '">'; echo $description . ' '; echo '</label>'; - + $data = ''; foreach ($options as $value => $text) { - $data .= '<option value="' . $value . '" ' . ($value == $selected_value ? "SELECTED" : '') . '>' . $text . '</option>' . "/n"; + $data .= '<option value="' . + $value . + '" ' . + ($value == $selected_value ? "SELECTED" : '') . + '>' . + $text . + '</option>' . + "/n"; } echo '<select id="' . $field_id . '" name="' . $field_name . '"> '; echo $data; diff --git a/wp-content/plugins/extended-categories-widget/3.3/js/avh-ec.admin.manualorder.js b/wp-content/plugins/extended-categories-widget/3.3/js/avh-ec.admin.manualorder.js index 34b4ae16827d893ba3be2b4a275c04af1cab68d7..e5a9c066d70187d4ac410f22e1328940212e8ff9 100644 --- a/wp-content/plugins/extended-categories-widget/3.3/js/avh-ec.admin.manualorder.js +++ b/wp-content/plugins/extended-categories-widget/3.3/js/avh-ec.admin.manualorder.js @@ -1,19 +1,19 @@ function avhecManualOrder() { - jQuery("#avhecManualOrder").sortable({ - placeholder : "sortable-placeholder", - revert : false, - items : '.lineitem', - opacity: 0.65, - cursor: 'move', - forcePlaceholderSize: true, - tolerance : "pointer" - }); + 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")); + jQuery("#updateText").html("Updating Category Order..."); + jQuery("#hdnManualOrder").val( + jQuery("#avhecManualOrder").sortable("toArray")); } \ No newline at end of file diff --git a/wp-content/plugins/extended-categories-widget/3.3/js/avh-ec.admin.manualorder.min.js b/wp-content/plugins/extended-categories-widget/3.3/js/avh-ec.admin.manualorder.min.js new file mode 100644 index 0000000000000000000000000000000000000000..f9ff1e235ba43f64e84475f07f8a067ef81681b1 --- /dev/null +++ b/wp-content/plugins/extended-categories-widget/3.3/js/avh-ec.admin.manualorder.min.js @@ -0,0 +1 @@ +function avhecManualOrder(){jQuery("#avhecManualOrder").sortable({placeholder:"sortable-placeholder",revert:false,items:".lineitem",opacity:.65,cursor:"move",forcePlaceholderSize:true,tolerance:"pointer"})}addLoadEvent(avhecManualOrder);function orderCats(){jQuery("#updateText").html("Updating Category Order...");jQuery("#hdnManualOrder").val(jQuery("#avhecManualOrder").sortable("toArray"))} \ No newline at end of file diff --git a/wp-content/plugins/extended-categories-widget/3.3/js/avh-ec.categorygroup.js b/wp-content/plugins/extended-categories-widget/3.3/js/avh-ec.categorygroup.js index 7221dfa75b4bd0d5c2f9dd3844834ca8d53316a2..0f7e70914cfd2ca8d6790affcaba3c728efc1541 100644 --- a/wp-content/plugins/extended-categories-widget/3.3/js/avh-ec.categorygroup.js +++ b/wp-content/plugins/extended-categories-widget/3.3/js/avh-ec.categorygroup.js @@ -1,21 +1,23 @@ -jQuery(document).ready(function($) { - var options = false, delBefore, delAfter; +jQuery(document).ready(function ($) { + var options = false, delBefore, delAfter; - delAfter = function( r, settings ) { - var id = $('cat', r).attr('id'), o; - for ( o = 0; o < options.length; o++ ) - if ( id == options[o].value ) - options[o] = null; - }; + delAfter = function (r, settings) { + var id = $('cat', r).attr('id'), o; + for (o = 0; o < options.length; o++) + if (id == options[o].value) + options[o] = null; + }; - delBefore = function(s) { - if ( 'undefined' != showNotice ) - return showNotice.warn() ? s : false; + delBefore = function (s) { + if ('undefined' != showNotice) + return showNotice.warn() ? s : false; - return s; - }; + return s; + }; - $('#the-list').wpList({ delBefore: delBefore }); + $('#the-list').wpList({delBefore: delBefore}); - $('.delete a[class^="delete"]').live('click', function(){return false;}); + $('.delete a[class^="delete"]').live('click', function () { + return false; + }); }); diff --git a/wp-content/plugins/extended-categories-widget/3.3/js/avh-ec.categorygroup.min.js b/wp-content/plugins/extended-categories-widget/3.3/js/avh-ec.categorygroup.min.js new file mode 100644 index 0000000000000000000000000000000000000000..5b7e6ba1ef13853ad0490ef9983fe341a6d6d955 --- /dev/null +++ b/wp-content/plugins/extended-categories-widget/3.3/js/avh-ec.categorygroup.min.js @@ -0,0 +1 @@ +jQuery(document).ready(function($){var options=false,delBefore,delAfter;delAfter=function(r,settings){var id=$("cat",r).attr("id"),o;for(o=0;o<options.length;o++)if(id==options[o].value)options[o]=null};delBefore=function(s){if("undefined"!=showNotice)return showNotice.warn()?s:false;return s};$("#the-list").wpList({delBefore:delBefore});$('.delete a[class^="delete"]').live("click",function(){return false})}); \ No newline at end of file diff --git a/wp-content/plugins/extended-categories-widget/3.6/avh-ec.client.php b/wp-content/plugins/extended-categories-widget/3.6/avh-ec.client.php index f21a19be2893647c83ed1dd7aaaef81a9036d07c..189b7042c926530e6fd3b9c9748cd134d701c372 100644 --- a/wp-content/plugins/extended-categories-widget/3.6/avh-ec.client.php +++ b/wp-content/plugins/extended-categories-widget/3.6/avh-ec.client.php @@ -2,78 +2,69 @@ /** * Singleton Class - * */ -class AVH_EC_Singleton -{ - - /** - * - * @param string $class - * @param string $arg1 - */ - public static function &getInstance($class, $arg1 = null) - { - static $instances = array(); // array of instance names - if (array_key_exists($class, $instances)) { - $instance = & $instances[$class]; - } else { - if (!class_exists($class)) { - switch ($class) { - case 'AVH_EC_Core': - require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.core.php'); - break; - case 'AVH_EC_Category_Group': - require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.category-group.php'); - break; - case 'AVH_EC_Widget_Helper_Class': - require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widget-helper.php'); - break; - } - } - $instances[$class] = new $class($arg1); - $instance = & $instances[$class]; - } +class AVH_EC_Singleton { + /** + * @param string $class + * @param string $arg1 + */ + public static function &getInstance($class, $arg1 = null) { + static $instances = array(); // array of instance names + if (array_key_exists($class, $instances)) { + $instance = &$instances[ $class ]; + } else { + if ( ! class_exists($class)) { + switch ($class) { + case 'AVH_EC_Core': + require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.core.php'); + break; + case 'AVH_EC_Category_Group': + require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.category-group.php'); + break; + case 'AVH_EC_Widget_Helper_Class': + require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widget-helper.php'); + break; + } + } + $instances[ $class ] = new $class($arg1); + $instance = &$instances[ $class ]; + } - return $instance; - } + return $instance; + } } /** * Include the necessary files */ -require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/helpers/avh-forms.php'); -require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/helpers/avh-common.php'); -require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widgets.php'); +require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/helpers/avh-forms.php'); +require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/helpers/avh-common.php'); +require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widgets.php'); /** * Initialize the plugin */ -function avhextendedcategories_init() -{ - // Admin - if (is_admin()) { - require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.admin.php'); - $avhec_admin = new AVH_EC_Admin(); - } - AVH_EC_Singleton::getInstance('AVH_EC_Core'); +function avhextendedcategories_init() { + // Admin + if (is_admin()) { + require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.admin.php'); + $avhec_admin = new AVH_EC_Admin(); + } + AVH_EC_Singleton::getInstance('AVH_EC_Core'); - add_action('widgets_init', 'avhextendedcategories_widgets_init'); + add_action('widgets_init', 'avhextendedcategories_widgets_init'); } // End avhamazon_init() /** * Register the widget * * @WordPress Action widgets_init - * - * @since 3.0 - * + * @since 3.0 */ -function avhextendedcategories_widgets_init() -{ - register_widget('WP_Widget_AVH_ExtendedCategories_Normal'); - register_widget('WP_Widget_AVH_ExtendedCategories_Top'); - register_widget('WP_Widget_AVH_ExtendedCategories_Category_Group'); +function avhextendedcategories_widgets_init() { + register_widget('WP_Widget_AVH_ExtendedCategories_Normal'); + register_widget('WP_Widget_AVH_ExtendedCategories_Top'); + register_widget('WP_Widget_AVH_ExtendedCategories_Category_Group'); } add_action('plugins_loaded', 'avhextendedcategories_init'); diff --git a/wp-content/plugins/extended-categories-widget/3.6/class/avh-ec.admin.php b/wp-content/plugins/extended-categories-widget/3.6/class/avh-ec.admin.php index 19c84eca92e88b05ccd7a2adac4adacfaef3a27a..76f4b8d39f7cd1a8922c3fddd27ed8fc8e6184ab 100644 --- a/wp-content/plugins/extended-categories-widget/3.6/class/avh-ec.admin.php +++ b/wp-content/plugins/extended-categories-widget/3.6/class/avh-ec.admin.php @@ -1,1464 +1,1840 @@ <?php -class AVH_EC_Admin -{ - - /** - * - * @var AVH_EC_Core - */ - public $core; - - /** - * - * @var AVH_EC_Category_Group - */ - public $catgrp; - - public $hooks = array(); - - public $message; - - /** - * PHP5 constructor - */ - public function __construct() - { - - // Initialize the plugin - $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core'); - $this->catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); - - add_action('wp_ajax_delete-group', array($this, 'ajaxDeleteGroup')); - - // Admin menu - add_action('admin_init', array($this, 'actionAdminInit')); - add_action('admin_menu', array($this, 'actionAdminMenu')); - add_filter('plugin_action_links_extended-categories-widget/widget_extended_categories.php', array($this, 'filterPluginActions'), 10, 2); - - // Actions used for editing posts - add_action('load-post.php', array($this, 'actionLoadPostPage')); - add_action('load-page.php', array($this, 'actionLoadPostPage')); - - // Actions related to adding and deletes categories - add_action("created_category", array($this, 'actionCreatedCategory'), 10, 2); - add_action("delete_category", array($this, 'actionDeleteCategory'), 10, 2); - - add_filter('manage_categories_group_columns', array($this, 'filterManageCategoriesGroupColumns')); - add_filter('explain_nonce_delete-avhecgroup', array($this, 'filterExplainNonceDeleteGroup'), 10, 2); - - return; - } - - public function actionAdminInit() - { - if (is_admin() && isset($_GET['taxonomy']) && 'category' == $_GET['taxonomy']) { - add_action($_GET['taxonomy'] . '_edit_form', array($this, 'displayCategoryGroupForm'), 10, 2); - } - add_action('edit_term', array($this, 'handleEditTerm'), 10, 3); - } - - /** - * Adds Category Group form - * @WordPress action category_edit_form - * - * @param unknown_type $term - * @param unknown_type $taxonomy - */ - public function displayCategoryGroupForm($term, $taxonomy) - { - $current_selection = ''; - $tax_meta = get_option($this->core->db_options_tax_meta); - if (isset($tax_meta[$taxonomy][$term->term_id])) { - $tax_meta = $tax_meta[$taxonomy][$term->term_id]; - $current_selection = $tax_meta['category_group_term_id']; - } - - if (empty($current_selection)) { - $current_group = $this->catgrp->getGroupByCategoryID($term->term_id); - $current_selection = $current_group->term_id; - } - - $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false)); - foreach ($cat_groups as $group) { - $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit'); - $dropdown_value[] = $group->term_id; - $dropdown_text[] = $temp_cat->name; - } - - $seldata = ''; - foreach ($dropdown_value as $key => $sel) { - $seldata .= '<option value="' . esc_attr($sel) . '" ' . (($current_selection == $sel) ? 'selected="selected"' : '') . ' >' . esc_html(ucfirst($dropdown_text[$key])) . '</option>' . "\n"; - } - - echo '<h3>AVH Extended Categories - Category Group Widget</h3>'; - echo '<table class="form-table"><tbody>'; - echo '<tr class="form-field">'; - echo '<th valign="top" scope="row">'; - echo '<label for="avhec_categorygroup">Category Group</label></th>'; - echo '<td>'; - echo '<select id="avhec_categorygroup" name="avhec_categorygroup">'; - echo $seldata; - echo '</select>'; - echo '<p class="description">Select the category group to show on the archive page.</p>'; - echo '</td>'; - echo '</tr>'; - echo '</tbody></table>'; - } - - /** - * Saves the association Category - Category Group fron the edit taxonomy page - * @WordPress action edit_form. - * - * @param unknown_type $term_id - * @param unknown_type $tt_id - * @param unknown_type $taxonomy - */ - public function handleEditTerm($term_id, $tt_id, $taxonomy) - { - $tax_meta = get_option($this->core->db_options_tax_meta); - if (isset($_POST['avhec_categorygroup'])) { - if (!isset($tax_meta[$taxonomy][$term_id]['category_group_term_id']) || $tax_meta[$taxonomy][$term_id]['category_group_term_id'] != $_POST['avhec_categorygroup']) { - $tax_meta[$taxonomy][$term_id]['category_group_term_id'] = $_POST['avhec_categorygroup']; - update_option($this->core->db_options_tax_meta, $tax_meta); - } - } - } - - /** - * When a category is created this function is called to add the new category to the group all - * - * @param - * $term_id - * @param - * $term_taxonomy_id - */ - public function actionCreatedCategory($term_id, $term_taxonomy_id) - { - $group_id = $this->catgrp->getTermIDBy('slug', 'all'); - $this->catgrp->setCategoriesForGroup($group_id, (array) $term_id); - } - - /** - * When a category is deleted this function is called so the category is deleted from every group as well. - * - * @param object $term - * @param int $term_taxonomy_id - */ - public function actionDeleteCategory($term_id, $term_taxonomy_id) - { - $this->catgrp->doDeleteCategoryFromGroup($term_id); - } - - /** - * Enqueues the style on the post.php and page.php pages - * @WordPress Action load-$pagenow - */ - public function actionLoadPostPage() - { - wp_enqueue_style('avhec-admin-css'); - } - - /** - * Add the Tools and Options to the Management and Options page repectively - * - * @WordPress Action admin_menu - */ - public function actionAdminMenu() - { - - // Register Style and Scripts - $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.closure'; - wp_register_script('avhec-categorygroup-js', AVHEC_PLUGIN_URL . '/js/avh-ec.categorygroup' . $suffix . '.js', array('jquery'), $this->core->version, true); - wp_register_script('avhec-manualorder', AVHEC_PLUGIN_URL . '/js/avh-ec.admin.manualorder' . $suffix . '.js', array('jquery-ui-sortable'), $this->core->version, false); - wp_register_style('avhec-admin-css', AVHEC_PLUGIN_URL . '/css/avh-ec.admin.css', array('wp-admin'), $this->core->version, 'screen'); - - // Add menu system - $folder = $this->core->getBaseDirectory(AVHEC_PLUGIN_DIR); - add_menu_page('AVH Extended Categories', 'AVH Extended Categories', 'manage_options', $folder, array($this, 'doMenuOverview')); - $this->hooks['menu_overview'] = add_submenu_page($folder, 'AVH Extended Categories: ' . __('Overview', 'avh-ec'), __('Overview', 'avh-ec'), 'manage_options', $folder, array($this, 'doMenuOverview')); - $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')); - $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')); - $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')); - $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')); - - // Add actions for menu pages - // Overview Menu - add_action('load-' . $this->hooks['menu_overview'], array($this, 'actionLoadPageHook_Overview')); - - // General Options Menu - add_action('load-' . $this->hooks['menu_general'], array($this, 'actionLoadPageHook_General')); - - // Category Groups Menu - add_action('load-' . $this->hooks['menu_category_groups'], array($this, 'actionLoadPageHook_CategoryGroup')); - - // Manual Order Menu - add_action('load-' . $this->hooks['menu_manual_order'], array($this, 'actionLoadPageHook_ManualOrder')); - - // FAQ Menu - add_action('load-' . $this->hooks['menu_faq'], array($this, 'actionLoadPageHook_faq')); - } - - /** - * Setup everything needed for the Overview page - */ - public function actionLoadPageHook_Overview() - { - // Add metaboxes - add_meta_box('avhecBoxCategoryGroupList', __('Group Overview', 'avh-ec'), array($this, 'metaboxCategoryGroupList'), $this->hooks['menu_overview'], 'normal', 'core'); - add_meta_box('avhecBoxTranslation', __('Translation', 'avh-ec'), array($this, 'metaboxTranslation'), $this->hooks['menu_overview'], 'normal', 'core'); - - add_screen_option('layout_columns', array('max' => 2, 'default' => 2)); - - // WordPress core Scripts - wp_enqueue_script('common'); - wp_enqueue_script('wp-lists'); - wp_enqueue_script('postbox'); - - // Plugin Scripts - wp_enqueue_script('avhec-categorygroup-js'); - - // Plugin Style - wp_enqueue_style('avhec-admin-css'); - } - - /** - * Menu Page Overview - * - * @return none - */ - public function doMenuOverview() - { - global $screen_layout_columns; - - // This box can't be unselectd in the the Screen Options - // add_meta_box('avhecBoxAnnouncements', __('Announcements', 'avh-ec'), array ( $this, 'metaboxAnnouncements' ), $this->hooks['menu_overview'], 'side', ''); - add_meta_box('avhecBoxDonations', __('Donations', 'avh-ec'), array($this, 'metaboxDonations'), $this->hooks['menu_overview'], 'side', ''); - - $hide2 = ''; - switch ($screen_layout_columns) { - case 2: - $width = 'width:49%;'; - break; - default: - $width = 'width:98%;'; - $hide2 = 'display:none;'; - } - - echo '<div class="wrap avhec-metabox-wrap">'; - echo $this->displayIcon('index'); - echo '<h2>' . 'AVH Extended Categories - ' . __('Overview', 'avh-ec') . '</h2>'; - echo ' <div id="dashboard-widgets-wrap">'; - echo ' <div id="dashboard-widgets" class="metabox-holder">'; - echo ' <div class="postbox-container" style="' . $width . '">' . "\n"; - do_meta_boxes($this->hooks['menu_overview'], 'normal', ''); - echo " </div>"; - echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n"; - do_meta_boxes($this->hooks['menu_overview'], 'side', ''); - echo ' </div>'; - echo ' </div>'; - - echo '<br class="clear"/>'; - echo ' </div>'; // dashboard-widgets-wrap - echo '</div>'; // wrap - - $this->printMetaboxGeneralNonces(); - $this->printMetaboxJS('overview'); - $this->printAdminFooter(); - } - - /** - * Setup everything needed for the General Options page - */ - public function actionLoadPageHook_General() - { - // Add metaboxes - add_meta_box('avhecBoxOptions', __('Options', 'avh-ec'), array($this, 'metaboxOptions'), $this->hooks['menu_general'], 'normal', 'core'); - - add_screen_option('layout_columns', array('max' => 2, 'default' => 2)); - - // WordPress core Scripts - wp_enqueue_script('common'); - wp_enqueue_script('wp-lists'); - wp_enqueue_script('postbox'); - - // Plugin Style and Scripts - wp_enqueue_style('avhec-admin-css'); - } - - /** - * Menu Page General Options - * - * @return none - */ - public function doMenuGeneral() - { - global $screen_layout_columns; - - $groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false)); - foreach ($groups as $group) { - $group_id[] = $group->term_id; - $groupname[] = $group->name; - } - - $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')); - $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')); - $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')); - $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')); - - if (isset($_POST['updateoptions'])) { - check_admin_referer('avh_ec_generaloptions'); - - $formoptions = $_POST['avhec']; - $options = $this->core->getOptions(); - - // $all_data = array_merge( $options_general ); - $all_data = $options_general; - foreach ($all_data as $option) { - $section = substr($option[0], strpos($option[0], '[') + 1); - $section = substr($section, 0, strpos($section, '][')); - $option_key = rtrim($option[0], ']'); - $option_key = substr($option_key, strpos($option_key, '][') + 2); - - switch ($section) { - case 'general': - case 'cat_group': - $current_value = $options[$section][$option_key]; - break; - } - // Every field in a form is set except unchecked checkboxes. Set an unchecked checkbox to 0. - $newval = (isset($formoptions[$section][$option_key]) ? esc_attr($formoptions[$section][$option_key]) : 0); - if ($newval != $current_value) { // Only process changed fields. - switch ($section) { - case 'general': - case 'cat_group': - $options[$section][$option_key] = $newval; - break; - } - } - } - $this->core->saveOptions($options); - $this->message = __('Options saved', 'avh-ec'); - $this->status = 'updated fade'; - } - $this->displayMessage(); - - $actual_options = $this->core->getOptions(); - foreach ($actual_options['cat_group'] as $key => $value) { - if (!(in_array($value, (array) $group_id))) { - $actual_options['cat_group'][$key] = $this->catgrp->getTermIDBy('slug', 'none'); - } - } - - $hide2 = ''; - switch ($screen_layout_columns) { - case 2: - $width = 'width:49%;'; - break; - default: - $width = 'width:98%;'; - $hide2 = 'display:none;'; - } - $data['options_general'] = $options_general; - $data['actual_options'] = $actual_options; - - // This box can't be unselectd in the the Screen Options - add_meta_box('avhecBoxDonations', __('Donations', 'avh-ec'), array($this, 'metaboxDonations'), $this->hooks['menu_general'], 'side', 'core'); - - $hide2 = ''; - switch ($screen_layout_columns) { - case 2: - $width = 'width:49%;'; - break; - default: - $width = 'width:98%;'; - $hide2 = 'display:none;'; - } - - echo '<div class="wrap avhec-metabox-wrap">'; - echo $this->displayIcon('index'); - echo '<h2>' . 'AVH Extended Categories - ' . __('General Options', 'avh-ec') . '</h2>'; - echo '<form name="avhec-generaloptions" id="avhec-generaloptions" method="POST" action="' . admin_url('admin.php?page=avhec-general') . '" accept-charset="utf-8" >'; - wp_nonce_field('avh_ec_generaloptions'); - - echo ' <div id="dashboard-widgets-wrap">'; - echo ' <div id="dashboard-widgets" class="metabox-holder">'; - echo ' <div class="postbox-container" style="' . $width . '">' . "\n"; - do_meta_boxes($this->hooks['menu_general'], 'normal', $data); - echo " </div>"; - echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n"; - do_meta_boxes($this->hooks['menu_general'], 'side', $data); - echo ' </div>'; - echo ' </div>'; - - echo '<br class="clear"/>'; - echo ' </div>'; // dashboard-widgets-wrap - echo '<p class="submit"><input class="button" type="submit" name="updateoptions" value="' . __('Save Changes', 'avhf-ec') . '" /></p>'; - echo '</form>'; - - echo '</div>'; // wrap - - $this->printMetaboxGeneralNonces(); - $this->printMetaboxJS('general'); - $this->printAdminFooter(); - } - - /** - * Options Metabox - */ - public function metaboxOptions($data) - { - echo $this->printOptions($data['options_general'], $data['actual_options']); - } - - /** - * Setup everything needed for the Category Group page - */ - public function actionLoadPageHook_CategoryGroup() - { - - // Add metaboxes - add_meta_box('avhecBoxCategoryGroupAdd', __('Add Group', 'avh-ec'), array($this, 'metaboxCategoryGroupAdd'), $this->hooks['menu_category_groups'], 'normal', 'core'); - add_meta_box('avhecBoxCategoryGroupList', __('Group Overview', 'avh-ec'), array($this, 'metaboxCategoryGroupList'), $this->hooks['menu_category_groups'], 'side', 'core'); - add_meta_box('avhecBoxCategoryGroupSpecialPages', __('Special Pages', 'avh-ec'), array($this, 'metaboxCategoryGroupSpecialPages'), $this->hooks['menu_category_groups'], 'normal', 'core'); - - add_screen_option('layout_columns', array('max' => 2, 'default' => 2)); - - // WordPress core Scripts - wp_enqueue_script('common'); - wp_enqueue_script('wp-lists'); - wp_enqueue_script('postbox'); - - // Plugin Scripts - wp_enqueue_script('avhec-categorygroup-js'); - - // Plugin Style - wp_enqueue_style('avhec-admin-css'); - } - - /** - * Menu Page Category Group - * - * @return none - */ - public function doMenuCategoryGroup() - { - global $screen_layout_columns; - - $data_add_group_default = array('name' => '', 'slug' => '', 'widget_title' => '', 'description' => ''); - $data_add_group_new = $data_add_group_default; - - $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')); - $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')); - $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')); - $options_add_group[] = array('avhec_add_group[add][description]', __('Description', 'avh-ec'), 'textarea', 40, __('Description is not prominent by default.', 'avh-ec'), 5); - - $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')); - $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')); - $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')); - $options_edit_group[] = array('avhec_edit_group[edit][description]', __('Description', 'avh-ec'), 'textarea', 40, __('Description is not prominent by default.', 'avh-ec'), 5); - $options_edit_group[] = array('avhec_edit_group[edit][categories]', __('Categories', 'avh-ec'), 'catlist', 0, __('Select categories to be included in the group.', 'avh-ec')); - - if (isset($_POST['addgroup'])) { - check_admin_referer('avh_ec_addgroup'); - - $formoptions = $_POST['avhec_add_group']; - - $data_add_group_new['name'] = $formoptions['add']['name']; - $data_add_group_new['slug'] = empty($formoptions['add']['slug']) ? sanitize_title($data_add_group_new['name']) : sanitize_title($formoptions['add']['slug']); - $data_add_group_new['widget_title'] = $formoptions['add']['widget_title']; - $data_add_group_new['description'] = $formoptions['add']['description']; - - $id = $this->catgrp->getTermIDBy('slug', $data_add_group_new['slug']); - if (!$id) { - $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']); - $this->catgrp->setCategoriesForGroup($group_id); - $this->message = __('Category group saved', 'avh-ec'); - $this->status = 'updated fade'; - $data_add_group_new = $data_add_group_default; - } else { - $group = $this->catgrp->getGroup($id); - $this->message = __('Category group conflicts with ', 'avh-ec') . $group->name; - $this->message .= '<br />' . __('Same slug is used. ', 'avh-ec'); - $this->status = 'error'; - } - $this->displayMessage(); - } - $data_add_group['add'] = $data_add_group_new; - $data['add'] = array('form' => $options_add_group, 'data' => $data_add_group); - - if (isset($_GET['action'])) { - $action = $_GET['action']; - - switch ($action) { - case 'edit': - $group_id = (int) $_GET['group_ID']; - $group = $this->catgrp->getGroup($group_id); - $widget_title = $this->catgrp->getWidgetTitleForGroup($group_id); - $cats = $this->catgrp->getCategoriesFromGroup($group_id); - - $data_edit_group['edit'] = array('group_id' => $group_id, 'name' => $group->name, 'slug' => $group->slug, 'widget_title' => $widget_title, 'description' => $group->description, 'categories' => $cats); - $data['edit'] = array('form' => $options_edit_group, 'data' => $data_edit_group); - - add_meta_box('avhecBoxCategoryGroupEdit', __('Edit Group', 'avh-ec') . ': ' . $group->name, array($this, 'metaboxCategoryGroupEdit'), $this->hooks['menu_category_groups'], 'normal', 'low'); - break; - case 'delete': - if (!isset($_GET['group_ID'])) { - wp_redirect($this->getBackLink()); - exit(); - } - - $group_id = (int) $_GET['group_ID']; - check_admin_referer('delete-avhecgroup_' . $group_id); - - if (!current_user_can('manage_categories')) { - wp_die(__('Cheatin’ uh?')); - } - $this->catgrp->doDeleteGroup($group_id); - break; - default: - ; - break; - } - } - - if (isset($_POST['editgroup'])) { - check_admin_referer('avh_ec_editgroup'); - - $formoptions = $_POST['avhec_edit_group']; - $selected_categories = $_POST['post_category']; - - $group_id = (int) $_POST['avhec-group_id']; - $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']); - switch ($result) { - case 1: - $this->message = __('Category group updated', 'avh-ec'); - $this->status = 'updated fade'; - break; - case 0: - $this->message = __('Category group not updated', 'avh-ec'); - $this->message .= '<br />' . __('Duplicate slug detected', 'avh-ec'); - $this->status = 'error'; - break; - case -1: - $this->message = __('Unknown category group', 'avh-ec'); - $this->status = 'error'; - break; - } - $this->displayMessage(); - } - - $hide2 = ''; - switch ($screen_layout_columns) { - case 2: - $width = 'width:49%;'; - break; - default: - $width = 'width:98%;'; - $hide2 = 'display:none;'; - } - - $data_special_pages_old = $this->core->options['sp_cat_group']; - $data_special_pages_new = $data_special_pages_old; - if (isset($_POST['avhec_special_pages'])) { - check_admin_referer('avh_ec_specialpagesgroup'); - - $formoptions = $_POST['avhec_special_pages']; - $formdata = $formoptions['sp']; - foreach ($formdata as $key => $value) { - $data_special_pages_new[$key] = $value; - } - $this->core->options['sp_cat_group'] = $data_special_pages_new; - $this->core->saveOptions($this->core->options); - } - $data_special_pages['sp'] = $data_special_pages_new; - $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false)); - - foreach ($cat_groups as $group) { - $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit'); - $dropdown_value[] = $group->term_id; - $dropdown_text[] = $temp_cat->name; - } - $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'))); - // $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'))); - $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'))); - $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'))); - $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'))); - $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'))); - $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'))); - - $data['sp'] = array('form' => $options_special_pages, 'data' => $data_special_pages); - - // This box can't be unselectd in the the Screen Options - // add_meta_box( 'avhecBoxDonations', __( 'Donations', 'avh-ec' ), array ($this, 'metaboxDonations' ), $this->hooks['menu_category_groups'], 'side', 'core' ); - - echo '<div class="wrap avhec-metabox-wrap">'; - echo $this->displayIcon('index'); - echo '<h2>' . 'AVH Extended Categories - ' . __('Category Groups', 'avh-ec') . '</h2>'; - - echo ' <div id="dashboard-widgets-wrap">'; - echo ' <div id="dashboard-widgets" class="metabox-holder">'; - - echo ' <div class="postbox-container" style="' . $width . '">' . "\n"; - do_meta_boxes($this->hooks['menu_category_groups'], 'normal', $data); - echo " </div>"; - - echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n"; - do_meta_boxes($this->hooks['menu_category_groups'], 'side', $data); - echo ' </div>'; - - echo ' </div>'; // dashboard-widgets - echo '<br class="clear" />'; - echo ' </div>'; // dashboard-widgets-wrap - echo '</div>'; // wrap - - $this->printMetaboxGeneralNonces(); - $this->printMetaboxJS('grouped'); - $this->printAdminFooter(); - } - - /** - * Metabox for Adding a group - * - * @param - * $data - */ - public function metaboxCategoryGroupAdd($data) - { - echo '<form name="avhec-addgroup" id="avhec-addgroup" method="POST" action="' . $this->getBackLink() . '" accept-charset="utf-8" >'; - wp_nonce_field('avh_ec_addgroup'); - echo $this->printOptions($data['add']['form'], $data['add']['data']); - echo '<p class="submit"><input class="button" type="submit" name="addgroup" value="' . __('Add group', 'avh-ec') . '" /></p>'; - echo '</form>'; - } - - /** - * Metabox for showing the groups as a list - * - * @param - * $data - */ - public function metaboxCategoryGroupList($data) - { - echo '<form id="posts-filter" action="" method="get">'; - - echo '<div class="clear"></div>'; - - echo '<table class="widefat fixed" cellspacing="0">'; - echo '<thead>'; - echo '<tr>'; - print_column_headers('categories_group'); - echo '</tr>'; - echo '</thead>'; - - echo '<tfoot>'; - echo '<tr>'; - print_column_headers('categories_group', false); - echo '</tr>'; - echo '</tfoot>'; - - echo '<tbody id="the-list" class="list:group">'; - $this->printCategoryGroupRows(); - echo '</tbody>'; - echo '</table>'; - - echo '<br class="clear" />'; - echo '</form>'; - - // echo '</div>'; - } - - /** - * Metabox Category Group Edit - */ - public function metaboxCategoryGroupEdit($data) - { - echo '<form name="avhec-editgroup" id="avhec-editgroup" method="POST" action="' . $this->getBackLink() . '" accept-charset="utf-8" >'; - wp_nonce_field('avh_ec_editgroup'); - echo $this->printOptions($data['edit']['form'], $data['edit']['data']); - echo '<input type="hidden" value="' . $data['edit']['data']['edit']['group_id'] . '" name="avhec-group_id" id="avhec-group_id">'; - echo '<p class="submit"><input class="button" type="submit" name="editgroup" value="' . __('Update group', 'avh-ec') . '" /></p>'; - echo '</form>'; - } - - /** - * Metabox Category Group Special pages - */ - public function metaboxCategoryGroupSpecialPages($data) - { - echo '<form name="avhec-specialpagesgroup" id="avhec-specialpagesgroup" method="POST" action="' . $this->getBackLink() . '" accept-charset="utf-8" >'; - wp_nonce_field('avh_ec_specialpagesgroup'); - echo $this->printOptions($data['sp']['form'], $data['sp']['data']); - echo '<p class="submit"><input class="button" type="submit" name="spgroup" value="' . __('Save settings', 'avh-ec') . '" /></p>'; - echo '</form>'; - } - - /** - * Setup everything needed for the Manul Order page - */ - public function actionLoadPageHook_ManualOrder() - { - add_meta_box('avhecBoxManualOrder', __('Manually Order Categories', 'avh-ec'), array($this, 'metaboxManualOrder'), $this->hooks['menu_manual_order'], 'normal', 'core'); - - add_screen_option('layout_columns', array('max' => 1, 'default' => 1)); - - // WordPress core Styles and Scripts - wp_enqueue_script('common'); - wp_enqueue_script('wp-lists'); - wp_enqueue_script('postbox'); - wp_enqueue_script('jquery-ui-sortable'); - wp_enqueue_script('avhec-manualorder'); - - // Plugin Style - wp_enqueue_style('avhec-admin-css'); - } - - /** - * Menu Page Manual Order - * - * @return none - */ - public function doMenuManualOrder() - { - global $screen_layout_columns; - - $hide2 = ''; - switch ($screen_layout_columns) { - case 2: - $width = 'width:49%;'; - break; - default: - $width = 'width:98%;'; - $hide2 = 'display:none;'; - } - - echo '<div class="wrap">'; - echo $this->displayIcon('index'); - echo '<h2>' . 'AVH Extended Categories - ' . __('Manually Order Categories', 'avh-ec') . '</h2>'; - - echo '<div class="metabox-holder">'; - echo ' <div class="postbox-container" style="' . $width . '">' . "\n"; - do_meta_boxes($this->hooks['menu_manual_order'], 'normal', ''); - echo ' </div>'; - echo '</div>'; - echo '</div>'; // wrap - echo '<div class="clear"></div>'; - - $this->printMetaboxGeneralNonces(); - $this->printMetaboxJS('manual_order'); - $this->printAdminFooter(); - } - - /** - * Displays the Manual Order metabox. - * - * @author Andrew Charlton - original - * @author Peter van der Does - modifications - */ - public function metaboxManualOrder() - { - global $wpdb; - - $parentID = 0; - - if (isset($_POST['btnSubCats'])) { - $parentID = $_POST['cats']; - } elseif (isset($_POST['hdnParentID'])) { - $parentID = $_POST['hdnParentID']; - } - - if (isset($_POST['btnReturnParent'])) { - $parentsParent = $wpdb->get_row($wpdb->prepare("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = %d", $_POST['hdnParentID']), ARRAY_N); - $parentID = $parentsParent[0]; - } - - $success = ""; - if (isset($_POST['btnOrderCats'])) { - if (isset($_POST['hdnManualOrder']) && $_POST['hdnManualOrder'] != "") { - - $manualOrder = $_POST['hdnManualOrder']; - $IDs = explode(",", $manualOrder); - $result = count($IDs); - - for ($i = 0; $i < $result; $i ++) { - $str = str_replace("id_", "", $IDs[$i]); - $wpdb->query($wpdb->prepare("UPDATE $wpdb->terms SET avhec_term_order = %d WHERE term_id =%d", $i, $str)); - } - - $success = '<div id="message" class="updated fade"><p>' . __('Manual order of the categories successfully updated.', 'avh-ec') . '</p></div>'; - } else { - $success = '<div id="message" class="updated fade"><p>' . __('An error occured, order has not been saved.', 'avh-ec') . '</p></div>'; - } - } - - $subCategories = ""; - $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)); - foreach ($results as $row) { - $subCategories .= "<option value='$row->term_id'>$row->name</option>"; - } - - echo '<div class="wrap">'; - echo '<form name="frmMyCatOrder" method="post" action="">'; - echo $success; - - echo '<h4>'; - _e('Order the categories', 'avh-ec'); - if ($parentID == 0) { - echo ' at the Toplevel'; - } else { - $categories = get_category_parents($parentID, false, ' » '); - echo ' in the category ' . trim($categories, ' » '); - } - echo '</h4>'; - echo '<span class="description">'; - _e('Order the categories on this level by dragging and dropping them into the desired order.', 'avh-ec'); - echo '</span>'; - echo '<ul id="avhecManualOrder">'; - $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)); - foreach ($results as $row) { - echo "<li id='id_$row->term_id' class='lineitem menu-item-settings'>" . __($row->name) . "</li>"; - } - echo '</ul>'; - echo '<input type="submit" name="btnOrderCats" id="btnOrderCats" class="button-primary" value="' . __('Save Order', 'avh-ec') . '" onclick="javascript:orderCats(); return true;" />'; - - if ($parentID != 0) { - echo "<input type='submit' class='button' id='btnReturnParent' name='btnReturnParent' value='" . __('Return to parent category', 'avh-ec') . "' />"; - } - - echo '<strong id="updateText"></strong><br /><br />'; - if ($subCategories != "") { - - echo '<h4>'; - _e('Select Subcategory', 'avh-ec'); - echo '</h4>'; - echo '<select id="cats" name="cats">'; - echo $subCategories; - - echo '</select><input type="submit" name="btnSubCats" class="button" id="btnSubCats" value="' . __('Select', 'avh-ec') . '" />'; - echo '<span class="description">'; - _e('Choose a category from the drop down to order the subcategories in that category.', 'avh-ec'); - echo '</span>'; - } - - echo '<input type="hidden" id="hdnManualOrder" name="hdnManualOrder" />'; - echo '<input type="hidden" id="hdnParentID" name="hdnParentID" value="' . $parentID . '" /></form>'; - echo '</div>'; - } - - /** - * Setup everything needed for the FAQ page - */ - public function actionLoadPageHook_faq() - { - add_meta_box('avhecBoxFAQ', __('F.A.Q.', 'avh-ec'), array($this, 'metaboxFAQ'), $this->hooks['menu_faq'], 'normal', 'core'); - add_meta_box('avhecBoxTranslation', __('Translation', 'avh-ec'), array($this, 'metaboxTranslation'), $this->hooks['menu_faq'], 'normal', 'core'); - - add_screen_option('layout_columns', array('max' => 2, 'default' => 2)); - - // WordPress core Styles and Scripts - wp_enqueue_script('common'); - wp_enqueue_script('wp-lists'); - wp_enqueue_script('postbox'); - - // Plugin Style - wp_enqueue_style('avhec-admin-css'); - } - - /** - * Menu Page FAQ - * - * @return none - */ - public function doMenuFAQ() - { - global $screen_layout_columns; - - // This box can't be unselectd in the the Screen Options - // add_meta_box('avhecBoxAnnouncements', __('Announcements', 'avh-ec'), array ( $this, 'metaboxAnnouncements' ), $this->hooks['menu_faq'], 'side', 'core'); - add_meta_box('avhecBoxDonations', __('Donations', 'avh-ec'), array($this, 'metaboxDonations'), $this->hooks['menu_faq'], 'side', 'core'); - - $hide2 = ''; - switch ($screen_layout_columns) { - case 2: - $width = 'width:49%;'; - break; - default: - $width = 'width:98%;'; - $hide2 = 'display:none;'; - } - - echo '<div class="wrap avhec-metabox-wrap">'; - echo $this->displayIcon('index'); - echo '<h2>' . 'AVH Extended Categories - ' . __('F.A.Q', 'avh-ec') . '</h2>'; - echo ' <div id="dashboard-widgets-wrap">'; - echo ' <div id="dashboard-widgets" class="metabox-holder">'; - echo ' <div class="postbox-container" style="' . $width . '">' . "\n"; - do_meta_boxes($this->hooks['menu_faq'], 'normal', ''); - echo ' </div>'; - echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n"; - do_meta_boxes($this->hooks['menu_faq'], 'side', ''); - echo ' </div>'; - echo ' </div>'; - echo '<br class="clear"/>'; - echo ' </div>'; // dashboard-widgets-wrap - echo '</div>'; // wrap - - $this->printMetaboxGeneralNonces(); - $this->printMetaboxJS('faq'); - $this->printAdminFooter(); - } - - /** - * Translation Metabox - * - * @return unknown_type - */ - public function metaboxTranslation() - { - $locale = apply_filters('plugin_locale', get_locale(), 'avh-ec'); - $available_locale['cs_CZ'] = array('Czech - Čeština', 0); - $available_locale['nl_NL'] = array('Dutch - Nederlands', 0); - $available_locale['de_DE'] = array('German - Deutsch', 0); - $available_locale['el'] = array('Greek - Čeština', 0); - $available_locale['id_ID'] = array('Indonesian - Bahasa Indonesia - Čeština', 0); - $available_locale['it_IT'] = array('Italian - Italiano', 1); - $available_locale['ru_RU'] = array('Russian — Русский', 0); - $available_locale['es_ES'] = array('Spanish - Español', 0); - $available_locale['sv_SE'] = array('Swedish - Svenska', 0); - $available_locale['tr'] = array('Turkish - Türkçe', 0); - - echo '<div class="p">'; - 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 />'; - - echo '</div>'; - - echo '<div class="p">'; - echo '<span class="b">' . __('Available Languages', 'avh-ec') . '</span>'; - echo '<ul>'; - foreach ($available_locale as $key => $value) { - echo '<li>'; - $complete = ($value[1] == 1 ? 'Complete' : 'Incomplete'); - echo $value[0] . ' (' . $key . ') - ' . $complete; - echo '</li>'; - } - echo '</ul>'; - echo '</div>'; - - echo '<div class="p">'; - if ('en_US' != $locale & (!array_key_exists($locale, $available_locale))) { - 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.'; - } else { - 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.'; - } - echo '</div>'; - } - - /** - * Donation Metabox - * - * @return unknown_type - */ - public function metaboxDonations() - { - echo '<div class="p">'; - echo __('If you enjoy this plug-in please consider a donation. There are several ways you can show your appreciation.', 'avh-ec'); - echo '</div>'; - - echo '<div class="p">'; - echo '<span class="b">Amazon</span><br />'; - echo __('If you decide to buy something from Amazon click the button.', 'avh-ec') . '</span><br />'; - 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>'; - echo '</div>'; - - echo '<div class="p">'; - 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>'; - echo '</div>'; - - echo '<div class="p">'; - echo '<span class="b">' . __('Through Paypal.', 'avh-ec') . '</span><br />'; - 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 />'; - 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">'; - echo '<img src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" alt="Donate"/></a>'; - echo '</div>'; - } - - /** - * * - * F.A.Q Metabox - * - * @return none - */ - public function metaboxFAQ() - { - echo '<div class="p">'; - echo '<span class="b">' . __('What about support?', 'avh-ec') . '</span><br />'; - 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 />'; - echo '</div>'; - - echo '<div class="p">'; - echo '<span class="b">' . __('What is depth selection?', 'avh-ec') . '</span><br />'; - 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 />'; - 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 />'; - 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 />'; - echo '</div>'; - - echo '<div class="p">'; - echo '<span class="b">' . __('Multiple Category Groups', 'avh-ec') . '</span><br />'; - echo __('The following is an explanation how assigning multiple groups to page/post works.', 'avh-ec') . '<br /><br />'; - echo __('Lets say you have the following groups:', 'avh-ec'); - echo '<ul>'; - echo '<li>' . __('Free Time', 'avh-ec') . '</li>'; - echo '<li>' . __('Theater', 'avh-ec') . '</li>'; - echo '<li>' . __('Movie', 'avh-ec') . '</li>'; - echo '<li>' . __('Music', 'avh-ec') . '</li>'; - echo '</ul>'; - echo __('Setup several Category Group widgets and associated each widget with one or more groups.', 'avh-ec') . '<br />'; - echo __('Widget 1 has association with Free Time', 'avh-ec') . '<br />'; - echo __('Widget 2 has association with Theater, Movie and Music', 'avh-ec') . '<br />'; - echo __('Widget 3 has association with Theater, Movie and Music', 'avh-ec') . '<br /><br />'; - echo __('Page has associations the groups Free Time and Theater', 'avh-ec'); - echo '<ul>'; - echo '<li>' . __('Widget 1: Shows categories of the Free Time group', 'avh-ec') . '</li>'; - echo '<li>' . __('Widget 2: Shows categories of the Theater group.', 'avh-ec') . '</li>'; - echo '<li>' . __('Widget 3: Not displayed', 'avh-ec') . '</li>'; - echo '</ul>'; - echo __('Page has associations the group Movie.', 'avh-ec'); - echo '<ul>'; - echo '<li>' . __('Widget 1: Not displayed', 'avh-ec') . '</li>'; - echo '<li>' . __('Widget 2: Shows categories of the Movie group.', 'avh-ec') . '</li>'; - echo '<li>' . __('Widget 3: Not displayed', 'avh-ec') . '</li>'; - echo '</ul>'; - echo __('Page has associations the groups Free Time, Movie and Music', 'avh-ec'); - echo '<ul>'; - echo '<li>' . __('Widget 1: Shows categories of the Free Time group', 'avh-ec') . '</li>'; - echo '<li>' . __('Widget 2: Shows categories of the Movie or Music group.', 'avh-ec') . '</li>'; - echo '<li>' . __('Widget 3: Shows categories of the Music or Movie group.', 'avh-ec') . '</li>'; - echo '</ul>'; - 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 />'; - echo '</div>'; - } - - public function metaboxAnnouncements() - { - $php5 = version_compare('5.2', phpversion(), '<'); - echo '<div class="p">'; - echo '<span class="b">' . __('PHP4 Support', 'avh-ec') . '</span><br />'; - echo __('The next major release of the plugin will no longer support PHP4.', 'avh-ec') . '<br />'; - echo __('It will be written for PHP 5.2 and ', 'avh-ec'); - if ($php5) { - echo __('your blog already runs the needed PHP version. When the new release comes out you can safely update.', 'avh-ec') . '<br />'; - } else { - echo __('your blog still runs PHP4. When the new release comes out you can not use it.', 'avh-ec') . '<br />'; - 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 />'; - echo __('If your hosts doesn\'t offer PHP 5.2 you might want to consider switching hosts.', 'avh-ec') . '<br />'; - echo __('A host to consider is ', 'avh-ec') . '<a href="http://www.lunarpages.com/id/pdoes" target="_blank">Lunarpages</a>'; - 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'); - } - echo '</div>'; - } - - /** - * Sets the amount of columns wanted for a particuler screen - * - * @WordPress filter screen_meta_screen - * - * @param - * $screen - * @return strings - */ - public function filterScreenLayoutColumns($columns, $screen) - { - switch ($screen) { - case $this->hooks['menu_overview']: - $columns[$this->hooks['menu_overview']] = 2; - break; - case $this->hooks['menu_general']: - $columns[$this->hooks['menu_general']] = 2; - break; - case $this->hooks['menu_category_groups']: - $columns[$this->hooks['menu_category_groups']] = 2; - break; - case $this->hooks['menu_faq']: - $columns[$this->hooks['menu_faq']] = 2; - break; - } - - return $columns; - } - - /** - * Adds Settings next to the plugin actions - * - * @WordPress Filter plugin_action_links_avh-amazon/avh-amazon.php - */ - public function filterPluginActions($links, $file) - { - $settings_link = '<a href="admin.php?page=extended-categories-widget">' . __('Settings', 'avh-ec') . '</a>'; - array_unshift($links, $settings_link); // before other links - - return $links; - } - - /** - * Creates a new array for columns headers. - * Used in print_column_headers. The filter is called from get_column_headers - * - * @param - * $columns - * @return Array - * @see print_column_headers, get_column_headers - */ - public function filterManageCategoriesGroupColumns($columns) - { - $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')); - - return $categories_group_columns; - } - - /** - * When not using AJAX, this function is called when the deletion fails. - * - * @param string $text - * @param int $group_id - * @return string @WordPress Filter explain_nonce_$verb-$noun - * @see wp_explain_nonce - */ - public function filterExplainNonceDeleteGroup($text, $group_id) - { - $group = get_term($group_id, $this->catgrp->taxonomy_name, OBJECT, 'display'); - - $return = sprintf(__('Your attempt to delete this group: “%s” has failed.'), $group->name); - - return ($return); - } - - // ############ Admin WP Helper ############## - - /** - * Get the backlink for forms - * - * @return strings - */ - public function getBackLink() - { - $page = basename(__FILE__); - if (isset($_GET['page']) && !empty($_GET['page'])) { - $page = preg_replace('[^a-zA-Z0-9\.\_\-]', '', $_GET['page']); - } - - if (function_exists("admin_url")) { - return admin_url(basename($_SERVER["PHP_SELF"])) . "?page=" . $page; - } else { - return $_SERVER['PHP_SELF'] . "?page=" . $page; - } - } - - /** - * Print all Category Group rows - * - * @uses printCategoryGroupRow - * - */ - public function printCategoryGroupRows() - { - $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false)); - - foreach ($cat_groups as $group) { - if ('none' != $group->slug) { - echo $this->printCategoryGroupRow($group->term_id, $group->term_taxonomy_id); - } - } - } - - /** - * Displays all the information of a group in a row - * Adds inline link for delete and/or edit. - * - * @param int $group_term_id - * @param int $group_term_taxonomy_id - */ - public function printCategoryGroupRow($group_term_id, $group_term_taxonomy_id) - { - static $row_class = ''; - - $group = get_term($group_term_id, $this->catgrp->taxonomy_name, OBJECT, 'display'); - - $no_edit[$this->catgrp->getTermIDBy('slug', 'all')] = 0; - $no_delete[$this->catgrp->getTermIDBy('slug', 'all')] = 0; - - if (current_user_can('manage_categories')) { - $actions = array(); - if (!array_key_exists($group->term_id, $no_edit)) { - $edit_link = "admin.php?page=avhec-grouped&action=edit&group_ID=$group->term_id"; - $edit = "<a class='row-title' href='$edit_link' title='" . esc_attr(sprintf(__('Edit “%s”'), $group->name)) . "'>" . esc_attr($group->name) . '</a><br />'; - - $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>'; - } else { - $edit = esc_attr($group->name); - } - if (!(array_key_exists($group->term_id, $no_delete))) { - $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>"; - } - $action_count = count($actions); - $i = 0; - $edit .= '<div class="row-actions">'; - foreach ($actions as $action => $link) { - ++ $i; - ($i == $action_count) ? $sep = '' : $sep = ' | '; - $edit .= "<span class='$action'>$link$sep</span>"; - } - $edit .= '</div>'; - } else { - $edit = $group->name; - } - - $row_class = 'alternate' == $row_class ? '' : 'alternate'; - $qe_data = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit'); - - $output = "<tr id='group-$group->term_id' class='iedit $row_class'>"; - - $columns = get_column_headers('categories_group'); - $hidden = get_hidden_columns('categories_group'); - foreach ($columns as $column_name => $column_display_name) { - $class = 'class="' . $column_name . ' column-' . $column_name . '"'; - - $style = ''; - if (in_array($column_name, $hidden)) { - $style = ' style="display:none;"'; - } - - $attributes = $class . $style; - - switch ($column_name) { - case 'cb': - $output .= '<th scope="row" class="check-column">'; - if (!(array_key_exists($group->term_id, $no_delete))) { - $output .= '<input type="checkbox" name="delete[]" value="' . $group->term_id . '" />'; - } else { - $output .= " "; - } - $output .= '</th>'; - break; - case 'name': - $output .= '<td ' . $attributes . '>' . $edit; - $output .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">'; - $output .= '<div class="name">' . $qe_data->name . '</div>'; - $output .= '<div class="slug">' . apply_filters('editable_slug', $qe_data->slug) . '</div>'; - $output .= '</div></td>'; - break; - case 'widget-title': - $title = $this->catgrp->getWidgetTitleForGroup($group->term_id); - if (!$title) { - $title = " "; - } - $output .= '<td ' . $attributes . '>' . $title . '</td>'; - break; - - case 'description': - $output .= '<td ' . $attributes . '>' . $qe_data->description . '</td>'; - break; - case 'slug': - $output .= "<td $attributes>" . apply_filters('editable_slug', $qe_data->slug) . "</td>"; - break; - case 'cat-in-group': - $cats = $this->catgrp->getCategoriesFromGroup($group_term_id); - $catname = array(); - foreach ($cats as $cat_id) { - $catname[] = get_cat_name($cat_id); - } - natsort($catname); - $cat = implode(', ', $catname); - $output .= '<td ' . $attributes . '>' . $cat . '</td>'; - break; - } - } - $output .= '</tr>'; - - return $output; - } - - /** - * Prints the general nonces, used by the AJAX - */ - public function printMetaboxGeneralNonces() - { - echo '<form style="display:none" method="get" action="">'; - echo '<p>'; - wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); - wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); - echo '</p>'; - echo '</form>'; - } - - /** - * Print the Metabox JS for toggling closed and open - * - * @param - * $boxid - */ - public function printMetaboxJS($boxid) - { - $a = $this->hooks['menu_' . $boxid]; - echo '<script type="text/javascript">' . "\n"; - echo ' //<![CDATA[' . "\n"; - echo ' jQuery(document).ready( function($) {' . "\n"; - echo ' $(\'.if-js-closed\').removeClass(\'if-js-closed\').addClass(\'closed\');' . "\n"; - echo ' // postboxes setup' . "\n"; - echo ' postboxes.add_postbox_toggles(\'' . $a . '\');' . "\n"; - echo ' });' . "\n"; - echo ' //]]>' . "\n"; - echo '</script>'; - } - - /** - * Display plugin Copyright - */ - public function printAdminFooter() - { - echo '<p class="footer_avhec">'; - 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); - echo '</p>'; - } - - /** - * Display WP alert - */ - public function displayMessage() - { - if ($this->message != '') { - $message = $this->message; - $status = $this->status; - $this->message = $this->status = ''; // Reset - } - if (isset($message)) { - $status = ($status != '') ? $status : 'updated fade'; - echo '<div id="message" class="' . $status . '">'; - echo '<p><strong>' . $message . '</strong></p></div>'; - } - } - - /** - * Ouput formatted options - * - * @param array $option_data - * @return string - */ - public function printOptions($option_data, $option_actual) - { - // Generate output - $output = ''; - $output .= "\n" . '<table class="form-table avhec-options">' . "\n"; - foreach ($option_data as $option) { - $section = substr($option[0], strpos($option[0], '[') + 1); - $section = substr($section, 0, strpos($section, '][')); - $option_key = rtrim($option[0], ']'); - $option_key = substr($option_key, strpos($option_key, '][') + 2); - // Helper - if ($option[2] == 'helper') { - $output .= '<tr style="vertical-align: top;"><td class="helper" colspan="2">' . wp_filter_post_kses($option[4]) . '</td></tr>' . "\n"; - continue; - } - switch ($option[2]) { - case 'checkbox': - $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"; - $explanation = $option[4]; - break; - case 'dropdown': - $selvalue = $option[3]; - $seltext = $option[4]; - $seldata = ''; - foreach ((array) $selvalue as $key => $sel) { - $seldata .= '<option value="' . esc_attr($sel) . '" ' . (($option_actual[$section][$option_key] == $sel) ? 'selected="selected"' : '') . ' >' . esc_html(ucfirst($seltext[$key])) . '</option>' . "\n"; - } - $input_type = '<select id="' . esc_attr($option[0]) . '" name="' . esc_attr($option[0]) . '">' . $seldata . '</select>' . "\n"; - $explanation = $option[5]; - break; - case 'text-color': - $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"; - $explanation = $option[4]; - break; - case 'textarea': - $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>'; - $explanation = $option[4]; - break; - case 'catlist': - ob_start(); - echo '<div id="avhec-catlist">'; - echo '<ul>'; - wp_category_checklist(0, 0, $option_actual[$section][$option_key]); - echo '</ul>'; - echo '</div>'; - $input_type = ob_get_contents(); - ob_end_clean(); - $explanation = $option[4]; - break; - case 'text': - default: - $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"; - $explanation = $option[4]; - break; - } - // Additional Information - $extra = ''; - if ($explanation) { - $extra = '<br /><span class="description">' . wp_filter_kses($explanation) . '</span>' . "\n"; - } - // Output - $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"; - } - $output .= '</table>' . "\n"; - - return $output; - } - - /** - * Used in forms to set an option checked - * - * @param mixed $checked - * @param mixed $current - * @return strings - */ - public function isChecked($checked, $current) - { - $return = ''; - if ($checked == $current) { - $return = ' checked="checked"'; - } - - return $return; - } - - /** - * Displays the icon on the menu pages - * - * @param - * $icon - */ - public function displayIcon($icon) - { - return ('<div class="icon32" id="icon-' . $icon . '"><br/></div>'); - } - - /** - * Ajax Helper: inline delete of the groups - */ - public function ajaxDeleteGroup() - { - $group_id = isset($_POST['id']) ? (int) $_POST['id'] : 0; - check_ajax_referer('delete-avhecgroup_' . $group_id); - - if (!current_user_can('manage_categories')) { - die('-1'); - } - $check = $this->catgrp->getGroup($group_id); - if (false === $check) { - die('1'); - } - - if ($this->catgrp->doDeleteGroup($group_id)) { - die('1'); - } else { - die('0'); - } - } +class AVH_EC_Admin { + /** + * @var AVH_EC_Category_Group + */ + public $catgrp; + /** + * @var AVH_EC_Core + */ + public $core; + public $hooks = array(); + public $message; + + /** + * PHP5 constructor + */ + public function __construct() { + + // Initialize the plugin + $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core'); + $this->catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); + + add_action('wp_ajax_delete-group', array($this, 'ajaxDeleteGroup')); + + // Admin menu + add_action('admin_init', array($this, 'actionAdminInit')); + add_action('admin_menu', array($this, 'actionAdminMenu')); + add_filter('plugin_action_links_extended-categories-widget/widget_extended_categories.php', + array($this, 'filterPluginActions'), + 10, + 2); + + // Actions used for editing posts + add_action('load-post.php', array($this, 'actionLoadPostPage')); + add_action('load-page.php', array($this, 'actionLoadPostPage')); + + // Actions related to adding and deletes categories + add_action("created_category", array($this, 'actionCreatedCategory'), 10, 2); + add_action("delete_category", array($this, 'actionDeleteCategory'), 10, 2); + + add_filter('manage_categories_group_columns', array($this, 'filterManageCategoriesGroupColumns')); + add_filter('explain_nonce_delete-avhecgroup', array($this, 'filterExplainNonceDeleteGroup'), 10, 2); + + return; + } + + public function actionAdminInit() { + if (is_admin() && isset($_GET['taxonomy']) && 'category' == $_GET['taxonomy']) { + add_action($_GET['taxonomy'] . '_edit_form', array($this, 'displayCategoryGroupForm'), 10, 2); + } + add_action('edit_term', array($this, 'handleEditTerm'), 10, 3); + } + + /** + * Add the Tools and Options to the Management and Options page repectively + * + * @WordPress Action admin_menu + */ + public function actionAdminMenu() { + + // Register Style and Scripts + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; + wp_register_script('avhec-categorygroup-js', + AVHEC_PLUGIN_URL . '/js/avh-ec.categorygroup' . $suffix . '.js', + array('jquery'), + $this->core->version, + true); + wp_register_script('avhec-manualorder', + AVHEC_PLUGIN_URL . '/js/avh-ec.admin.manualorder' . $suffix . '.js', + array('jquery-ui-sortable'), + $this->core->version, + false); + wp_register_style('avhec-admin-css', + AVHEC_PLUGIN_URL . '/css/avh-ec.admin.css', + array('wp-admin'), + $this->core->version, + 'screen'); + + // Add menu system + $folder = $this->core->getBaseDirectory(AVHEC_PLUGIN_DIR); + add_menu_page('AVH Extended Categories', + 'AVH Extended Categories', + 'manage_options', + $folder, + array($this, 'doMenuOverview')); + $this->hooks['menu_overview'] = add_submenu_page($folder, + 'AVH Extended Categories: ' . __('Overview', 'avh-ec'), + __('Overview', 'avh-ec'), + 'manage_options', + $folder, + array($this, 'doMenuOverview')); + $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')); + $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')); + $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')); + $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')); + + // Add actions for menu pages + // Overview Menu + add_action('load-' . $this->hooks['menu_overview'], array($this, 'actionLoadPageHook_Overview')); + + // General Options Menu + add_action('load-' . $this->hooks['menu_general'], array($this, 'actionLoadPageHook_General')); + + // Category Groups Menu + add_action('load-' . $this->hooks['menu_category_groups'], array($this, 'actionLoadPageHook_CategoryGroup')); + + // Manual Order Menu + add_action('load-' . $this->hooks['menu_manual_order'], array($this, 'actionLoadPageHook_ManualOrder')); + + // FAQ Menu + add_action('load-' . $this->hooks['menu_faq'], array($this, 'actionLoadPageHook_faq')); + } + + /** + * When a category is created this function is called to add the new category to the group all + * + * @param + * $term_id + * @param + * $term_taxonomy_id + */ + public function actionCreatedCategory($term_id, $term_taxonomy_id) { + $group_id = $this->catgrp->getTermIDBy('slug', 'all'); + $this->catgrp->setCategoriesForGroup($group_id, (array) $term_id); + } + + /** + * When a category is deleted this function is called so the category is deleted from every group as well. + * + * @param object $term + * @param int $term_taxonomy_id + */ + public function actionDeleteCategory($term_id, $term_taxonomy_id) { + $this->catgrp->doDeleteCategoryFromGroup($term_id); + } + + /** + * Setup everything needed for the Category Group page + */ + public function actionLoadPageHook_CategoryGroup() { + + // Add metaboxes + add_meta_box('avhecBoxCategoryGroupAdd', + __('Add Group', 'avh-ec'), + array($this, 'metaboxCategoryGroupAdd'), + $this->hooks['menu_category_groups'], + 'normal', + 'core'); + add_meta_box('avhecBoxCategoryGroupList', + __('Group Overview', 'avh-ec'), + array($this, 'metaboxCategoryGroupList'), + $this->hooks['menu_category_groups'], + 'side', + 'core'); + add_meta_box('avhecBoxCategoryGroupSpecialPages', + __('Special Pages', 'avh-ec'), + array($this, 'metaboxCategoryGroupSpecialPages'), + $this->hooks['menu_category_groups'], + 'normal', + 'core'); + + add_screen_option('layout_columns', array('max' => 2, 'default' => 2)); + + // WordPress core Scripts + wp_enqueue_script('common'); + wp_enqueue_script('wp-lists'); + wp_enqueue_script('postbox'); + + // Plugin Scripts + wp_enqueue_script('avhec-categorygroup-js'); + + // Plugin Style + wp_enqueue_style('avhec-admin-css'); + } + + /** + * Setup everything needed for the General Options page + */ + public function actionLoadPageHook_General() { + // Add metaboxes + add_meta_box('avhecBoxOptions', + __('Options', 'avh-ec'), + array($this, 'metaboxOptions'), + $this->hooks['menu_general'], + 'normal', + 'core'); + + add_screen_option('layout_columns', array('max' => 2, 'default' => 2)); + + // WordPress core Scripts + wp_enqueue_script('common'); + wp_enqueue_script('wp-lists'); + wp_enqueue_script('postbox'); + + // Plugin Style and Scripts + wp_enqueue_style('avhec-admin-css'); + } + + /** + * Setup everything needed for the Manul Order page + */ + public function actionLoadPageHook_ManualOrder() { + add_meta_box('avhecBoxManualOrder', + __('Manually Order Categories', 'avh-ec'), + array($this, 'metaboxManualOrder'), + $this->hooks['menu_manual_order'], + 'normal', + 'core'); + + add_screen_option('layout_columns', array('max' => 1, 'default' => 1)); + + // WordPress core Styles and Scripts + wp_enqueue_script('common'); + wp_enqueue_script('wp-lists'); + wp_enqueue_script('postbox'); + wp_enqueue_script('jquery-ui-sortable'); + wp_enqueue_script('avhec-manualorder'); + + // Plugin Style + wp_enqueue_style('avhec-admin-css'); + } + + /** + * Setup everything needed for the Overview page + */ + public function actionLoadPageHook_Overview() { + // Add metaboxes + add_meta_box('avhecBoxCategoryGroupList', + __('Group Overview', 'avh-ec'), + array($this, 'metaboxCategoryGroupList'), + $this->hooks['menu_overview'], + 'normal', + 'core'); + add_meta_box('avhecBoxTranslation', + __('Translation', 'avh-ec'), + array($this, 'metaboxTranslation'), + $this->hooks['menu_overview'], + 'normal', + 'core'); + + add_screen_option('layout_columns', array('max' => 2, 'default' => 2)); + + // WordPress core Scripts + wp_enqueue_script('common'); + wp_enqueue_script('wp-lists'); + wp_enqueue_script('postbox'); + + // Plugin Scripts + wp_enqueue_script('avhec-categorygroup-js'); + + // Plugin Style + wp_enqueue_style('avhec-admin-css'); + } + + /** + * Setup everything needed for the FAQ page + */ + public function actionLoadPageHook_faq() { + add_meta_box('avhecBoxFAQ', + __('F.A.Q.', 'avh-ec'), + array($this, 'metaboxFAQ'), + $this->hooks['menu_faq'], + 'normal', + 'core'); + add_meta_box('avhecBoxTranslation', + __('Translation', 'avh-ec'), + array($this, 'metaboxTranslation'), + $this->hooks['menu_faq'], + 'normal', + 'core'); + + add_screen_option('layout_columns', array('max' => 2, 'default' => 2)); + + // WordPress core Styles and Scripts + wp_enqueue_script('common'); + wp_enqueue_script('wp-lists'); + wp_enqueue_script('postbox'); + + // Plugin Style + wp_enqueue_style('avhec-admin-css'); + } + + /** + * Enqueues the style on the post.php and page.php pages + * + * @WordPress Action load-$pagenow + */ + public function actionLoadPostPage() { + wp_enqueue_style('avhec-admin-css'); + } + + /** + * Ajax Helper: inline delete of the groups + */ + public function ajaxDeleteGroup() { + $group_id = isset($_POST['id']) ? (int) $_POST['id'] : 0; + check_ajax_referer('delete-avhecgroup_' . $group_id); + + if ( ! current_user_can('manage_categories')) { + die('-1'); + } + $check = $this->catgrp->getGroup($group_id); + if (false === $check) { + die('1'); + } + + if ($this->catgrp->doDeleteGroup($group_id)) { + die('1'); + } else { + die('0'); + } + } + + /** + * Adds Category Group form + * + * @WordPress action category_edit_form + * + * @param unknown_type $term + * @param unknown_type $taxonomy + */ + public function displayCategoryGroupForm($term, $taxonomy) { + $current_selection = ''; + $tax_meta = get_option($this->core->db_options_tax_meta); + if (isset($tax_meta[ $taxonomy ][ $term->term_id ])) { + $tax_meta = $tax_meta[ $taxonomy ][ $term->term_id ]; + $current_selection = $tax_meta['category_group_term_id']; + } + + if (empty($current_selection)) { + $current_group = $this->catgrp->getGroupByCategoryID($term->term_id); + $current_selection = $current_group->term_id; + } + + $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false)); + foreach ($cat_groups as $group) { + $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit'); + $dropdown_value[] = $group->term_id; + $dropdown_text[] = $temp_cat->name; + } + + $seldata = ''; + foreach ($dropdown_value as $key => $sel) { + $seldata .= '<option value="' . + esc_attr($sel) . + '" ' . + (($current_selection == $sel) ? 'selected="selected"' : '') . + ' >' . + esc_html(ucfirst($dropdown_text[ $key ])) . + '</option>' . + "\n"; + } + + echo '<h3>AVH Extended Categories - Category Group Widget</h3>'; + echo '<table class="form-table"><tbody>'; + echo '<tr class="form-field">'; + echo '<th valign="top" scope="row">'; + echo '<label for="avhec_categorygroup">Category Group</label></th>'; + echo '<td>'; + echo '<select id="avhec_categorygroup" name="avhec_categorygroup">'; + echo $seldata; + echo '</select>'; + echo '<p class="description">Select the category group to show on the archive page.</p>'; + echo '</td>'; + echo '</tr>'; + echo '</tbody></table>'; + } + + /** + * Displays the icon on the menu pages + * + * @param + * $icon + */ + public function displayIcon($icon) { + return ('<div class="icon32" id="icon-' . $icon . '"><br/></div>'); + } + + /** + * Display WP alert + */ + public function displayMessage() { + if ($this->message != '') { + $message = $this->message; + $status = $this->status; + $this->message = $this->status = ''; // Reset + } + if (isset($message)) { + $status = ($status != '') ? $status : 'updated fade'; + echo '<div id="message" class="' . $status . '">'; + echo '<p><strong>' . $message . '</strong></p></div>'; + } + } + + /** + * Menu Page Category Group + * + * @return none + */ + public function doMenuCategoryGroup() { + global $screen_layout_columns; + + $data_add_group_default = array('name' => '', 'slug' => '', 'widget_title' => '', 'description' => ''); + $data_add_group_new = $data_add_group_default; + + $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') + ); + $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') + ); + $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') + ); + $options_add_group[] = array( + 'avhec_add_group[add][description]', + __('Description', 'avh-ec'), + 'textarea', + 40, + __('Description is not prominent by default.', 'avh-ec'), + 5 + ); + + $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') + ); + $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') + ); + $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') + ); + $options_edit_group[] = array( + 'avhec_edit_group[edit][description]', + __('Description', 'avh-ec'), + 'textarea', + 40, + __('Description is not prominent by default.', 'avh-ec'), + 5 + ); + $options_edit_group[] = array( + 'avhec_edit_group[edit][categories]', + __('Categories', 'avh-ec'), + 'catlist', + 0, + __('Select categories to be included in the group.', 'avh-ec') + ); + + if (isset($_POST['addgroup'])) { + check_admin_referer('avh_ec_addgroup'); + + $formoptions = $_POST['avhec_add_group']; + + $data_add_group_new['name'] = $formoptions['add']['name']; + $data_add_group_new['slug'] = empty($formoptions['add']['slug']) ? sanitize_title($data_add_group_new['name']) : sanitize_title($formoptions['add']['slug']); + $data_add_group_new['widget_title'] = $formoptions['add']['widget_title']; + $data_add_group_new['description'] = $formoptions['add']['description']; + + $id = $this->catgrp->getTermIDBy('slug', $data_add_group_new['slug']); + if ( ! $id) { + $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']); + $this->catgrp->setCategoriesForGroup($group_id); + $this->message = __('Category group saved', 'avh-ec'); + $this->status = 'updated fade'; + $data_add_group_new = $data_add_group_default; + } else { + $group = $this->catgrp->getGroup($id); + $this->message = __('Category group conflicts with ', 'avh-ec') . $group->name; + $this->message .= '<br />' . __('Same slug is used. ', 'avh-ec'); + $this->status = 'error'; + } + $this->displayMessage(); + } + $data_add_group['add'] = $data_add_group_new; + $data['add'] = array('form' => $options_add_group, 'data' => $data_add_group); + + if (isset($_GET['action'])) { + $action = $_GET['action']; + + switch ($action) { + case 'edit': + $group_id = (int) $_GET['group_ID']; + $group = $this->catgrp->getGroup($group_id); + $widget_title = $this->catgrp->getWidgetTitleForGroup($group_id); + $cats = $this->catgrp->getCategoriesFromGroup($group_id); + + $data_edit_group['edit'] = array( + 'group_id' => $group_id, + 'name' => $group->name, + 'slug' => $group->slug, + 'widget_title' => $widget_title, + 'description' => $group->description, + 'categories' => $cats + ); + $data['edit'] = array('form' => $options_edit_group, 'data' => $data_edit_group); + + add_meta_box('avhecBoxCategoryGroupEdit', + __('Edit Group', 'avh-ec') . ': ' . $group->name, + array($this, 'metaboxCategoryGroupEdit'), + $this->hooks['menu_category_groups'], + 'normal', + 'low'); + break; + case 'delete': + if ( ! isset($_GET['group_ID'])) { + wp_redirect($this->getBackLink()); + exit(); + } + + $group_id = (int) $_GET['group_ID']; + check_admin_referer('delete-avhecgroup_' . $group_id); + + if ( ! current_user_can('manage_categories')) { + wp_die(__('Cheatin’ uh?')); + } + $this->catgrp->doDeleteGroup($group_id); + break; + default: + ; + break; + } + } + + if (isset($_POST['editgroup'])) { + check_admin_referer('avh_ec_editgroup'); + + $formoptions = $_POST['avhec_edit_group']; + $selected_categories = $_POST['post_category']; + + $group_id = (int) $_POST['avhec-group_id']; + $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']); + switch ($result) { + case 1: + $this->message = __('Category group updated', 'avh-ec'); + $this->status = 'updated fade'; + break; + case 0: + $this->message = __('Category group not updated', 'avh-ec'); + $this->message .= '<br />' . __('Duplicate slug detected', 'avh-ec'); + $this->status = 'error'; + break; + case - 1: + $this->message = __('Unknown category group', 'avh-ec'); + $this->status = 'error'; + break; + } + $this->displayMessage(); + } + + $hide2 = ''; + switch ($screen_layout_columns) { + case 2: + $width = 'width:49%;'; + break; + default: + $width = 'width:98%;'; + $hide2 = 'display:none;'; + } + + $data_special_pages_old = $this->core->options['sp_cat_group']; + $data_special_pages_new = $data_special_pages_old; + if (isset($_POST['avhec_special_pages'])) { + check_admin_referer('avh_ec_specialpagesgroup'); + + $formoptions = $_POST['avhec_special_pages']; + $formdata = $formoptions['sp']; + foreach ($formdata as $key => $value) { + $data_special_pages_new[ $key ] = $value; + } + $this->core->options['sp_cat_group'] = $data_special_pages_new; + $this->core->saveOptions($this->core->options); + } + $data_special_pages['sp'] = $data_special_pages_new; + $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false)); + + foreach ($cat_groups as $group) { + $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit'); + $dropdown_value[] = $group->term_id; + $dropdown_text[] = $temp_cat->name; + } + $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')) + ); + // $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'))); + $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')) + ); + $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')) + ); + $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')) + ); + $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')) + ); + $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')) + ); + + $data['sp'] = array('form' => $options_special_pages, 'data' => $data_special_pages); + + // This box can't be unselectd in the the Screen Options + // add_meta_box( 'avhecBoxDonations', __( 'Donations', 'avh-ec' ), array ($this, 'metaboxDonations' ), $this->hooks['menu_category_groups'], 'side', 'core' ); + + echo '<div class="wrap avhec-metabox-wrap">'; + echo $this->displayIcon('index'); + echo '<h2>' . 'AVH Extended Categories - ' . __('Category Groups', 'avh-ec') . '</h2>'; + + echo ' <div id="dashboard-widgets-wrap">'; + echo ' <div id="dashboard-widgets" class="metabox-holder">'; + + echo ' <div class="postbox-container" style="' . $width . '">' . "\n"; + do_meta_boxes($this->hooks['menu_category_groups'], 'normal', $data); + echo " </div>"; + + echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n"; + do_meta_boxes($this->hooks['menu_category_groups'], 'side', $data); + echo ' </div>'; + + echo ' </div>'; // dashboard-widgets + echo '<br class="clear" />'; + echo ' </div>'; // dashboard-widgets-wrap + echo '</div>'; // wrap + + $this->printMetaboxGeneralNonces(); + $this->printMetaboxJS('grouped'); + $this->printAdminFooter(); + } + + /** + * Menu Page FAQ + * + * @return none + */ + public function doMenuFAQ() { + global $screen_layout_columns; + + // This box can't be unselectd in the the Screen Options + // add_meta_box('avhecBoxAnnouncements', __('Announcements', 'avh-ec'), array ( $this, 'metaboxAnnouncements' ), $this->hooks['menu_faq'], 'side', 'core'); + add_meta_box('avhecBoxDonations', + __('Donations', 'avh-ec'), + array($this, 'metaboxDonations'), + $this->hooks['menu_faq'], + 'side', + 'core'); + + $hide2 = ''; + switch ($screen_layout_columns) { + case 2: + $width = 'width:49%;'; + break; + default: + $width = 'width:98%;'; + $hide2 = 'display:none;'; + } + + echo '<div class="wrap avhec-metabox-wrap">'; + echo $this->displayIcon('index'); + echo '<h2>' . 'AVH Extended Categories - ' . __('F.A.Q', 'avh-ec') . '</h2>'; + echo ' <div id="dashboard-widgets-wrap">'; + echo ' <div id="dashboard-widgets" class="metabox-holder">'; + echo ' <div class="postbox-container" style="' . $width . '">' . "\n"; + do_meta_boxes($this->hooks['menu_faq'], 'normal', ''); + echo ' </div>'; + echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n"; + do_meta_boxes($this->hooks['menu_faq'], 'side', ''); + echo ' </div>'; + echo ' </div>'; + echo '<br class="clear"/>'; + echo ' </div>'; // dashboard-widgets-wrap + echo '</div>'; // wrap + + $this->printMetaboxGeneralNonces(); + $this->printMetaboxJS('faq'); + $this->printAdminFooter(); + } + + /** + * Menu Page General Options + * + * @return none + */ + public function doMenuGeneral() { + global $screen_layout_columns; + + $groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false)); + foreach ($groups as $group) { + $group_id[] = $group->term_id; + $groupname[] = $group->name; + } + + $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') + ); + $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') + ); + $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') + ); + $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') + ); + + if (isset($_POST['updateoptions'])) { + check_admin_referer('avh_ec_generaloptions'); + + $formoptions = $_POST['avhec']; + $options = $this->core->getOptions(); + + // $all_data = array_merge( $options_general ); + $all_data = $options_general; + foreach ($all_data as $option) { + $section = substr($option[0], strpos($option[0], '[') + 1); + $section = substr($section, 0, strpos($section, '][')); + $option_key = rtrim($option[0], ']'); + $option_key = substr($option_key, strpos($option_key, '][') + 2); + + switch ($section) { + case 'general': + case 'cat_group': + $current_value = $options[ $section ][ $option_key ]; + break; + } + // Every field in a form is set except unchecked checkboxes. Set an unchecked checkbox to 0. + $newval = (isset($formoptions[ $section ][ $option_key ]) ? esc_attr($formoptions[ $section ][ $option_key ]) : 0); + if ($newval != $current_value) { // Only process changed fields. + switch ($section) { + case 'general': + case 'cat_group': + $options[ $section ][ $option_key ] = $newval; + break; + } + } + } + $this->core->saveOptions($options); + $this->message = __('Options saved', 'avh-ec'); + $this->status = 'updated fade'; + } + $this->displayMessage(); + + $actual_options = $this->core->getOptions(); + foreach ($actual_options['cat_group'] as $key => $value) { + if ( ! (in_array($value, (array) $group_id))) { + $actual_options['cat_group'][ $key ] = $this->catgrp->getTermIDBy('slug', 'none'); + } + } + + $hide2 = ''; + switch ($screen_layout_columns) { + case 2: + $width = 'width:49%;'; + break; + default: + $width = 'width:98%;'; + $hide2 = 'display:none;'; + } + $data['options_general'] = $options_general; + $data['actual_options'] = $actual_options; + + // This box can't be unselectd in the the Screen Options + add_meta_box('avhecBoxDonations', + __('Donations', 'avh-ec'), + array($this, 'metaboxDonations'), + $this->hooks['menu_general'], + 'side', + 'core'); + + $hide2 = ''; + switch ($screen_layout_columns) { + case 2: + $width = 'width:49%;'; + break; + default: + $width = 'width:98%;'; + $hide2 = 'display:none;'; + } + + echo '<div class="wrap avhec-metabox-wrap">'; + echo $this->displayIcon('index'); + echo '<h2>' . 'AVH Extended Categories - ' . __('General Options', 'avh-ec') . '</h2>'; + echo '<form name="avhec-generaloptions" id="avhec-generaloptions" method="POST" action="' . + admin_url('admin.php?page=avhec-general') . + '" accept-charset="utf-8" >'; + wp_nonce_field('avh_ec_generaloptions'); + + echo ' <div id="dashboard-widgets-wrap">'; + echo ' <div id="dashboard-widgets" class="metabox-holder">'; + echo ' <div class="postbox-container" style="' . $width . '">' . "\n"; + do_meta_boxes($this->hooks['menu_general'], 'normal', $data); + echo " </div>"; + echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n"; + do_meta_boxes($this->hooks['menu_general'], 'side', $data); + echo ' </div>'; + echo ' </div>'; + + echo '<br class="clear"/>'; + echo ' </div>'; // dashboard-widgets-wrap + echo '<p class="submit"><input class="button" type="submit" name="updateoptions" value="' . + __('Save Changes', 'avhf-ec') . + '" /></p>'; + echo '</form>'; + + echo '</div>'; // wrap + + $this->printMetaboxGeneralNonces(); + $this->printMetaboxJS('general'); + $this->printAdminFooter(); + } + + /** + * Menu Page Manual Order + * + * @return none + */ + public function doMenuManualOrder() { + global $screen_layout_columns; + + $hide2 = ''; + switch ($screen_layout_columns) { + case 2: + $width = 'width:49%;'; + break; + default: + $width = 'width:98%;'; + $hide2 = 'display:none;'; + } + + echo '<div class="wrap">'; + echo $this->displayIcon('index'); + echo '<h2>' . 'AVH Extended Categories - ' . __('Manually Order Categories', 'avh-ec') . '</h2>'; + + echo '<div class="metabox-holder">'; + echo ' <div class="postbox-container" style="' . $width . '">' . "\n"; + do_meta_boxes($this->hooks['menu_manual_order'], 'normal', ''); + echo ' </div>'; + echo '</div>'; + echo '</div>'; // wrap + echo '<div class="clear"></div>'; + + $this->printMetaboxGeneralNonces(); + $this->printMetaboxJS('manual_order'); + $this->printAdminFooter(); + } + + /** + * Menu Page Overview + * + * @return none + */ + public function doMenuOverview() { + global $screen_layout_columns; + + // This box can't be unselectd in the the Screen Options + // add_meta_box('avhecBoxAnnouncements', __('Announcements', 'avh-ec'), array ( $this, 'metaboxAnnouncements' ), $this->hooks['menu_overview'], 'side', ''); + add_meta_box('avhecBoxDonations', + __('Donations', 'avh-ec'), + array($this, 'metaboxDonations'), + $this->hooks['menu_overview'], + 'side', + ''); + + $hide2 = ''; + switch ($screen_layout_columns) { + case 2: + $width = 'width:49%;'; + break; + default: + $width = 'width:98%;'; + $hide2 = 'display:none;'; + } + + echo '<div class="wrap avhec-metabox-wrap">'; + echo $this->displayIcon('index'); + echo '<h2>' . 'AVH Extended Categories - ' . __('Overview', 'avh-ec') . '</h2>'; + echo ' <div id="dashboard-widgets-wrap">'; + echo ' <div id="dashboard-widgets" class="metabox-holder">'; + echo ' <div class="postbox-container" style="' . $width . '">' . "\n"; + do_meta_boxes($this->hooks['menu_overview'], 'normal', ''); + echo " </div>"; + echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n"; + do_meta_boxes($this->hooks['menu_overview'], 'side', ''); + echo ' </div>'; + echo ' </div>'; + + echo '<br class="clear"/>'; + echo ' </div>'; // dashboard-widgets-wrap + echo '</div>'; // wrap + + $this->printMetaboxGeneralNonces(); + $this->printMetaboxJS('overview'); + $this->printAdminFooter(); + } + + /** + * When not using AJAX, this function is called when the deletion fails. + * + * @param string $text + * @param int $group_id + * + * @return string @WordPress Filter explain_nonce_$verb-$noun + * @see wp_explain_nonce + */ + public function filterExplainNonceDeleteGroup($text, $group_id) { + $group = get_term($group_id, $this->catgrp->taxonomy_name, OBJECT, 'display'); + + $return = sprintf(__('Your attempt to delete this group: “%s” has failed.'), $group->name); + + return ($return); + } + + /** + * Creates a new array for columns headers. + * Used in print_column_headers. The filter is called from get_column_headers + * + * @param + * $columns + * + * @return Array + * @see print_column_headers, get_column_headers + */ + public function filterManageCategoriesGroupColumns($columns) { + $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') + ); + + return $categories_group_columns; + } + + /** + * Adds Settings next to the plugin actions + * + * @WordPress Filter plugin_action_links_avh-amazon/avh-amazon.php + */ + public function filterPluginActions($links, $file) { + $settings_link = '<a href="admin.php?page=extended-categories-widget">' . __('Settings', 'avh-ec') . '</a>'; + array_unshift($links, $settings_link); // before other links + + return $links; + } + + /** + * Sets the amount of columns wanted for a particuler screen + * + * @WordPress filter screen_meta_screen + * + * @param + * $screen + * + * @return strings + */ + public function filterScreenLayoutColumns($columns, $screen) { + switch ($screen) { + case $this->hooks['menu_overview']: + $columns[ $this->hooks['menu_overview'] ] = 2; + break; + case $this->hooks['menu_general']: + $columns[ $this->hooks['menu_general'] ] = 2; + break; + case $this->hooks['menu_category_groups']: + $columns[ $this->hooks['menu_category_groups'] ] = 2; + break; + case $this->hooks['menu_faq']: + $columns[ $this->hooks['menu_faq'] ] = 2; + break; + } + + return $columns; + } + + /** + * Get the backlink for forms + * + * @return string + */ + public function getBackLink() { + $page = basename(__FILE__); + if (isset($_GET['page']) && ! empty($_GET['page'])) { + $page = preg_replace('[^a-zA-Z0-9\.\_\-]', '', $_GET['page']); + } + + if (function_exists("admin_url")) { + return admin_url(basename($_SERVER["PHP_SELF"])) . "?page=" . $page; + } else { + return $_SERVER['PHP_SELF'] . "?page=" . $page; + } + } + + /** + * Saves the association Category - Category Group fron the edit taxonomy page + * + * @WordPress action edit_form. + * + * @param unknown_type $term_id + * @param unknown_type $tt_id + * @param unknown_type $taxonomy + */ + public function handleEditTerm($term_id, $tt_id, $taxonomy) { + $tax_meta = get_option($this->core->db_options_tax_meta); + if (isset($_POST['avhec_categorygroup'])) { + if ( ! isset($tax_meta[ $taxonomy ][ $term_id ]['category_group_term_id']) || + $tax_meta[ $taxonomy ][ $term_id ]['category_group_term_id'] != $_POST['avhec_categorygroup'] + ) { + $tax_meta[ $taxonomy ][ $term_id ]['category_group_term_id'] = $_POST['avhec_categorygroup']; + update_option($this->core->db_options_tax_meta, $tax_meta); + } + } + } + + /** + * Used in forms to set an option checked + * + * @param mixed $checked + * @param mixed $current + * + * @return string + */ + public function isChecked($checked, $current) { + $return = ''; + if ($checked == $current) { + $return = ' checked="checked"'; + } + + return $return; + } + + public function metaboxAnnouncements() { + $php5 = version_compare('5.2', phpversion(), '<'); + echo '<div class="p">'; + echo '<span class="b">' . __('PHP4 Support', 'avh-ec') . '</span><br />'; + echo __('The next major release of the plugin will no longer support PHP4.', 'avh-ec') . '<br />'; + echo __('It will be written for PHP 5.2 and ', 'avh-ec'); + if ($php5) { + echo __('your blog already runs the needed PHP version. When the new release comes out you can safely update.', + 'avh-ec') . '<br />'; + } else { + echo __('your blog still runs PHP4. When the new release comes out you can not use it.', 'avh-ec') . + '<br />'; + 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 />'; + echo __('If your hosts doesn\'t offer PHP 5.2 you might want to consider switching hosts.', 'avh-ec') . + '<br />'; + echo __('A host to consider is ', 'avh-ec') . + '<a href="http://www.lunarpages.com/id/pdoes" target="_blank">Lunarpages</a>'; + 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'); + } + echo '</div>'; + } + + /** + * Metabox for Adding a group + * + * @param + * $data + */ + public function metaboxCategoryGroupAdd($data) { + echo '<form name="avhec-addgroup" id="avhec-addgroup" method="POST" action="' . + $this->getBackLink() . + '" accept-charset="utf-8" >'; + wp_nonce_field('avh_ec_addgroup'); + echo $this->printOptions($data['add']['form'], $data['add']['data']); + echo '<p class="submit"><input class="button" type="submit" name="addgroup" value="' . + __('Add group', 'avh-ec') . + '" /></p>'; + echo '</form>'; + } + + /** + * Metabox Category Group Edit + */ + public function metaboxCategoryGroupEdit($data) { + echo '<form name="avhec-editgroup" id="avhec-editgroup" method="POST" action="' . + $this->getBackLink() . + '" accept-charset="utf-8" >'; + wp_nonce_field('avh_ec_editgroup'); + echo $this->printOptions($data['edit']['form'], $data['edit']['data']); + echo '<input type="hidden" value="' . + $data['edit']['data']['edit']['group_id'] . + '" name="avhec-group_id" id="avhec-group_id">'; + echo '<p class="submit"><input class="button" type="submit" name="editgroup" value="' . + __('Update group', 'avh-ec') . + '" /></p>'; + echo '</form>'; + } + + /** + * Metabox for showing the groups as a list + * + * @param + * $data + */ + public function metaboxCategoryGroupList($data) { + echo '<form id="posts-filter" action="" method="get">'; + + echo '<div class="clear"></div>'; + + echo '<table class="widefat fixed" cellspacing="0">'; + echo '<thead>'; + echo '<tr>'; + print_column_headers('categories_group'); + echo '</tr>'; + echo '</thead>'; + + echo '<tfoot>'; + echo '<tr>'; + print_column_headers('categories_group', false); + echo '</tr>'; + echo '</tfoot>'; + + echo '<tbody id="the-list" class="list:group">'; + $this->printCategoryGroupRows(); + echo '</tbody>'; + echo '</table>'; + + echo '<br class="clear" />'; + echo '</form>'; + // echo '</div>'; + } + + /** + * Metabox Category Group Special pages + */ + public function metaboxCategoryGroupSpecialPages($data) { + echo '<form name="avhec-specialpagesgroup" id="avhec-specialpagesgroup" method="POST" action="' . + $this->getBackLink() . + '" accept-charset="utf-8" >'; + wp_nonce_field('avh_ec_specialpagesgroup'); + echo $this->printOptions($data['sp']['form'], $data['sp']['data']); + echo '<p class="submit"><input class="button" type="submit" name="spgroup" value="' . + __('Save settings', 'avh-ec') . + '" /></p>'; + echo '</form>'; + } + + // ############ Admin WP Helper ############## + + /** + * Donation Metabox + * + * @return unknown_type + */ + public function metaboxDonations() { + echo '<div class="p">'; + echo __('If you enjoy this plug-in please consider a donation. There are several ways you can show your appreciation.', + 'avh-ec'); + echo '</div>'; + + echo '<div class="p">'; + echo '<span class="b">Amazon</span><br />'; + echo __('If you decide to buy something from Amazon click the button.', 'avh-ec') . '</span><br />'; + echo '<a href="https://www.amazon.com/?tag=petervanderdoes-20" target="_blank" title="Amazon Homepage"><img alt="Amazon Button" src="' . + $this->core->info['graphics_url'] . + '/us_banner_logow_120x60.gif" /></a>'; + echo '</div>'; + + echo '<div class="p">'; + echo __('You can send me something from my ', 'avh-ec') . + '<a href="http://www.amazon.com/registry/wishlist/1U3DTWZ72PI7W?tag=petervanderdoes-20">' . + __('Amazon Wish List', 'avh-ec') . + '</a>'; + echo '</div>'; + + echo '<div class="p">'; + echo '<span class="b">' . __('Through Paypal.', 'avh-ec') . '</span><br />'; + 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 />'; + 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">'; + echo '<img src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" alt="Donate"/></a>'; + echo '</div>'; + } + + /** + * * + * F.A.Q Metabox + * + * @return none + */ + public function metaboxFAQ() { + echo '<div class="p">'; + echo '<span class="b">' . __('What about support?', 'avh-ec') . '</span><br />'; + 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 />'; + echo '</div>'; + + echo '<div class="p">'; + echo '<span class="b">' . __('What is depth selection?', 'avh-ec') . '</span><br />'; + 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 />'; + 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 />'; + 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 />'; + echo '</div>'; + + echo '<div class="p">'; + echo '<span class="b">' . __('Multiple Category Groups', 'avh-ec') . '</span><br />'; + echo __('The following is an explanation how assigning multiple groups to page/post works.', 'avh-ec') . + '<br /><br />'; + echo __('Lets say you have the following groups:', 'avh-ec'); + echo '<ul>'; + echo '<li>' . __('Free Time', 'avh-ec') . '</li>'; + echo '<li>' . __('Theater', 'avh-ec') . '</li>'; + echo '<li>' . __('Movie', 'avh-ec') . '</li>'; + echo '<li>' . __('Music', 'avh-ec') . '</li>'; + echo '</ul>'; + echo __('Setup several Category Group widgets and associated each widget with one or more groups.', 'avh-ec') . + '<br />'; + echo __('Widget 1 has association with Free Time', 'avh-ec') . '<br />'; + echo __('Widget 2 has association with Theater, Movie and Music', 'avh-ec') . '<br />'; + echo __('Widget 3 has association with Theater, Movie and Music', 'avh-ec') . '<br /><br />'; + echo __('Page has associations the groups Free Time and Theater', 'avh-ec'); + echo '<ul>'; + echo '<li>' . __('Widget 1: Shows categories of the Free Time group', 'avh-ec') . '</li>'; + echo '<li>' . __('Widget 2: Shows categories of the Theater group.', 'avh-ec') . '</li>'; + echo '<li>' . __('Widget 3: Not displayed', 'avh-ec') . '</li>'; + echo '</ul>'; + echo __('Page has associations the group Movie.', 'avh-ec'); + echo '<ul>'; + echo '<li>' . __('Widget 1: Not displayed', 'avh-ec') . '</li>'; + echo '<li>' . __('Widget 2: Shows categories of the Movie group.', 'avh-ec') . '</li>'; + echo '<li>' . __('Widget 3: Not displayed', 'avh-ec') . '</li>'; + echo '</ul>'; + echo __('Page has associations the groups Free Time, Movie and Music', 'avh-ec'); + echo '<ul>'; + echo '<li>' . __('Widget 1: Shows categories of the Free Time group', 'avh-ec') . '</li>'; + echo '<li>' . __('Widget 2: Shows categories of the Movie or Music group.', 'avh-ec') . '</li>'; + echo '<li>' . __('Widget 3: Shows categories of the Music or Movie group.', 'avh-ec') . '</li>'; + echo '</ul>'; + 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 />'; + echo '</div>'; + } + + /** + * Displays the Manual Order metabox. + * + * @author Andrew Charlton - original + * @author Peter van der Does - modifications + */ + public function metaboxManualOrder() { + global $wpdb; + + $parentID = 0; + + if (isset($_POST['btnSubCats'])) { + $parentID = $_POST['cats']; + } elseif (isset($_POST['hdnParentID'])) { + $parentID = $_POST['hdnParentID']; + } + + if (isset($_POST['btnReturnParent'])) { + $parentsParent = $wpdb->get_row($wpdb->prepare("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = %d", + $_POST['hdnParentID']), + ARRAY_N); + $parentID = $parentsParent[0]; + } + + $success = ""; + if (isset($_POST['btnOrderCats'])) { + if (isset($_POST['hdnManualOrder']) && $_POST['hdnManualOrder'] != "") { + + $manualOrder = $_POST['hdnManualOrder']; + $IDs = explode(",", $manualOrder); + $result = count($IDs); + + for ($i = 0; $i < $result; $i ++) { + $str = str_replace("id_", "", $IDs[ $i ]); + $wpdb->query($wpdb->prepare("UPDATE $wpdb->terms SET avhec_term_order = %d WHERE term_id =%d", + $i, + $str)); + } + + $success = '<div id="message" class="updated fade"><p>' . + __('Manual order of the categories successfully updated.', 'avh-ec') . + '</p></div>'; + } else { + $success = '<div id="message" class="updated fade"><p>' . + __('An error occured, order has not been saved.', 'avh-ec') . + '</p></div>'; + } + } + + $subCategories = ""; + $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)); + foreach ($results as $row) { + $subCategories .= "<option value='$row->term_id'>$row->name</option>"; + } + + echo '<div class="wrap">'; + echo '<form name="frmMyCatOrder" method="post" action="">'; + echo $success; + + echo '<h4>'; + _e('Order the categories', 'avh-ec'); + if ($parentID == 0) { + echo ' at the Toplevel'; + } else { + $categories = get_category_parents($parentID, false, ' » '); + echo ' in the category ' . trim($categories, ' » '); + } + echo '</h4>'; + echo '<span class="description">'; + _e('Order the categories on this level by dragging and dropping them into the desired order.', 'avh-ec'); + echo '</span>'; + echo '<ul id="avhecManualOrder">'; + $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)); + foreach ($results as $row) { + echo "<li id='id_$row->term_id' class='lineitem menu-item-settings'>" . __($row->name) . "</li>"; + } + echo '</ul>'; + echo '<input type="submit" name="btnOrderCats" id="btnOrderCats" class="button-primary" value="' . + __('Save Order', 'avh-ec') . + '" onclick="javascript:orderCats(); return true;" />'; + + if ($parentID != 0) { + echo "<input type='submit' class='button' id='btnReturnParent' name='btnReturnParent' value='" . + __('Return to parent category', 'avh-ec') . + "' />"; + } + + echo '<strong id="updateText"></strong><br /><br />'; + if ($subCategories != "") { + + echo '<h4>'; + _e('Select Subcategory', 'avh-ec'); + echo '</h4>'; + echo '<select id="cats" name="cats">'; + echo $subCategories; + + echo '</select><input type="submit" name="btnSubCats" class="button" id="btnSubCats" value="' . + __('Select', 'avh-ec') . + '" />'; + echo '<span class="description">'; + _e('Choose a category from the drop down to order the subcategories in that category.', 'avh-ec'); + echo '</span>'; + } + + echo '<input type="hidden" id="hdnManualOrder" name="hdnManualOrder" />'; + echo '<input type="hidden" id="hdnParentID" name="hdnParentID" value="' . $parentID . '" /></form>'; + echo '</div>'; + } + + /** + * Options Metabox + */ + public function metaboxOptions($data) { + echo $this->printOptions($data['options_general'], $data['actual_options']); + } + + /** + * Translation Metabox + * + * @return unknown_type + */ + public function metaboxTranslation() { + $locale = apply_filters('plugin_locale', get_locale(), 'avh-ec'); + $available_locale['cs_CZ'] = array('Czech - Čeština', 0); + $available_locale['nl_NL'] = array('Dutch - Nederlands', 0); + $available_locale['de_DE'] = array('German - Deutsch', 0); + $available_locale['el'] = array('Greek - Čeština', 0); + $available_locale['id_ID'] = array('Indonesian - Bahasa Indonesia - Čeština', 0); + $available_locale['it_IT'] = array('Italian - Italiano', 1); + $available_locale['ru_RU'] = array('Russian — Русский', 0); + $available_locale['es_ES'] = array('Spanish - Español', 0); + $available_locale['sv_SE'] = array('Swedish - Svenska', 0); + $available_locale['tr'] = array('Turkish - Türkçe', 0); + + echo '<div class="p">'; + 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 />'; + + echo '</div>'; + + echo '<div class="p">'; + echo '<span class="b">' . __('Available Languages', 'avh-ec') . '</span>'; + echo '<ul>'; + foreach ($available_locale as $key => $value) { + echo '<li>'; + $complete = ($value[1] == 1 ? 'Complete' : 'Incomplete'); + echo $value[0] . ' (' . $key . ') - ' . $complete; + echo '</li>'; + } + echo '</ul>'; + echo '</div>'; + + echo '<div class="p">'; + if ('en_US' != $locale & ( ! array_key_exists($locale, $available_locale))) { + 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.'; + } else { + 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.'; + } + echo '</div>'; + } + + /** + * Display plugin Copyright + */ + public function printAdminFooter() { + echo '<p class="footer_avhec">'; + 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); + echo '</p>'; + } + + /** + * Displays all the information of a group in a row + * Adds inline link for delete and/or edit. + * + * @param int $group_term_id + * @param int $group_term_taxonomy_id + */ + public function printCategoryGroupRow($group_term_id, $group_term_taxonomy_id) { + static $row_class = ''; + + $group = get_term($group_term_id, $this->catgrp->taxonomy_name, OBJECT, 'display'); + + $no_edit[ $this->catgrp->getTermIDBy('slug', 'all') ] = 0; + $no_delete[ $this->catgrp->getTermIDBy('slug', 'all') ] = 0; + + if (current_user_can('manage_categories')) { + $actions = array(); + if ( ! array_key_exists($group->term_id, $no_edit)) { + $edit_link = "admin.php?page=avhec-grouped&action=edit&group_ID=$group->term_id"; + $edit = "<a class='row-title' href='$edit_link' title='" . + esc_attr(sprintf(__('Edit “%s”'), $group->name)) . + "'>" . + esc_attr($group->name) . + '</a><br />'; + + $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>'; + } else { + $edit = esc_attr($group->name); + } + if ( ! (array_key_exists($group->term_id, $no_delete))) { + $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>"; + } + $action_count = count($actions); + $i = 0; + $edit .= '<div class="row-actions">'; + foreach ($actions as $action => $link) { + ++ $i; + ($i == $action_count) ? $sep = '' : $sep = ' | '; + $edit .= "<span class='$action'>$link$sep</span>"; + } + $edit .= '</div>'; + } else { + $edit = $group->name; + } + + $row_class = 'alternate' == $row_class ? '' : 'alternate'; + $qe_data = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit'); + + $output = "<tr id='group-$group->term_id' class='iedit $row_class'>"; + + $columns = get_column_headers('categories_group'); + $hidden = get_hidden_columns('categories_group'); + foreach ($columns as $column_name => $column_display_name) { + $class = 'class="' . $column_name . ' column-' . $column_name . '"'; + + $style = ''; + if (in_array($column_name, $hidden)) { + $style = ' style="display:none;"'; + } + + $attributes = $class . $style; + + switch ($column_name) { + case 'cb': + $output .= '<th scope="row" class="check-column">'; + if ( ! (array_key_exists($group->term_id, $no_delete))) { + $output .= '<input type="checkbox" name="delete[]" value="' . $group->term_id . '" />'; + } else { + $output .= " "; + } + $output .= '</th>'; + break; + case 'name': + $output .= '<td ' . $attributes . '>' . $edit; + $output .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">'; + $output .= '<div class="name">' . $qe_data->name . '</div>'; + $output .= '<div class="slug">' . apply_filters('editable_slug', $qe_data->slug) . '</div>'; + $output .= '</div></td>'; + break; + case 'widget-title': + $title = $this->catgrp->getWidgetTitleForGroup($group->term_id); + if ( ! $title) { + $title = " "; + } + $output .= '<td ' . $attributes . '>' . $title . '</td>'; + break; + + case 'description': + $output .= '<td ' . $attributes . '>' . $qe_data->description . '</td>'; + break; + case 'slug': + $output .= "<td $attributes>" . apply_filters('editable_slug', $qe_data->slug) . "</td>"; + break; + case 'cat-in-group': + $cats = $this->catgrp->getCategoriesFromGroup($group_term_id); + $catname = array(); + foreach ($cats as $cat_id) { + $catname[] = get_cat_name($cat_id); + } + natsort($catname); + $cat = implode(', ', $catname); + $output .= '<td ' . $attributes . '>' . $cat . '</td>'; + break; + } + } + $output .= '</tr>'; + + return $output; + } + + /** + * Print all Category Group rows + * + * @uses printCategoryGroupRow + */ + public function printCategoryGroupRows() { + $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false)); + + foreach ($cat_groups as $group) { + if ('none' != $group->slug) { + echo $this->printCategoryGroupRow($group->term_id, $group->term_taxonomy_id); + } + } + } + + /** + * Prints the general nonces, used by the AJAX + */ + public function printMetaboxGeneralNonces() { + echo '<form style="display:none" method="get" action="">'; + echo '<p>'; + wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); + wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); + echo '</p>'; + echo '</form>'; + } + + /** + * Print the Metabox JS for toggling closed and open + * + * @param + * $boxid + */ + public function printMetaboxJS($boxid) { + $a = $this->hooks[ 'menu_' . $boxid ]; + echo '<script type="text/javascript">' . "\n"; + echo ' //<![CDATA[' . "\n"; + echo ' jQuery(document).ready( function($) {' . "\n"; + echo ' $(\'.if-js-closed\').removeClass(\'if-js-closed\').addClass(\'closed\');' . "\n"; + echo ' // postboxes setup' . "\n"; + echo ' postboxes.add_postbox_toggles(\'' . $a . '\');' . "\n"; + echo ' });' . "\n"; + echo ' //]]>' . "\n"; + echo '</script>'; + } + + /** + * Ouput formatted options + * + * @param array $option_data + * + * @return string + */ + public function printOptions($option_data, $option_actual) { + // Generate output + $output = ''; + $output .= "\n" . '<table class="form-table avhec-options">' . "\n"; + foreach ($option_data as $option) { + $section = substr($option[0], strpos($option[0], '[') + 1); + $section = substr($section, 0, strpos($section, '][')); + $option_key = rtrim($option[0], ']'); + $option_key = substr($option_key, strpos($option_key, '][') + 2); + // Helper + if ($option[2] == 'helper') { + $output .= '<tr style="vertical-align: top;"><td class="helper" colspan="2">' . + wp_filter_post_kses($option[4]) . + '</td></tr>' . + "\n"; + continue; + } + switch ($option[2]) { + case 'checkbox': + $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"; + $explanation = $option[4]; + break; + case 'dropdown': + $selvalue = $option[3]; + $seltext = $option[4]; + $seldata = ''; + foreach ((array) $selvalue as $key => $sel) { + $seldata .= '<option value="' . + esc_attr($sel) . + '" ' . + (($option_actual[ $section ][ $option_key ] == $sel) ? 'selected="selected"' : '') . + ' >' . + esc_html(ucfirst($seltext[ $key ])) . + '</option>' . + "\n"; + } + $input_type = '<select id="' . + esc_attr($option[0]) . + '" name="' . + esc_attr($option[0]) . + '">' . + $seldata . + '</select>' . + "\n"; + $explanation = $option[5]; + break; + case 'text-color': + $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"; + $explanation = $option[4]; + break; + case 'textarea': + $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>'; + $explanation = $option[4]; + break; + case 'catlist': + ob_start(); + echo '<div id="avhec-catlist">'; + echo '<ul>'; + wp_category_checklist(0, 0, $option_actual[ $section ][ $option_key ]); + echo '</ul>'; + echo '</div>'; + $input_type = ob_get_contents(); + ob_end_clean(); + $explanation = $option[4]; + break; + case 'text': + default: + $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"; + $explanation = $option[4]; + break; + } + // Additional Information + $extra = ''; + if ($explanation) { + $extra = '<br /><span class="description">' . wp_filter_kses($explanation) . '</span>' . "\n"; + } + // Output + $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"; + } + $output .= '</table>' . "\n"; + + return $output; + } } diff --git a/wp-content/plugins/extended-categories-widget/3.6/class/avh-ec.category-group.php b/wp-content/plugins/extended-categories-widget/3.6/class/avh-ec.category-group.php index 88de5fd6b8ce09da5041392f5d8c5b6ac648607d..9a3245494b17d14f83cc2879e12e26531b6069e2 100644 --- a/wp-content/plugins/extended-categories-widget/3.6/class/avh-ec.category-group.php +++ b/wp-content/plugins/extended-categories-widget/3.6/class/avh-ec.category-group.php @@ -5,416 +5,467 @@ * * @author Peter van der Does */ -class AVH_EC_Category_Group -{ - - /** - * Taxonomy name - * - * @var string - */ - public $taxonomy_name; - - public $db_options_widget_titles; - - public $options_widget_titles; - - public $widget_done_catgroup; - - /** - * PHP5 Constructor - * Init the Database Abstraction layer - */ - public function __construct() - { - global $wpdb; - - register_shutdown_function(array($this, '__destruct')); - - /** - * Taxonomy name - * - * @var string - */ - $this->taxonomy_name = 'avhec_catgroup'; - - $this->db_options_widget_titles = 'avhec_widget_titles'; - // add DB pointer - $wpdb->avhec_cat_group = $wpdb->prefix . 'avhec_category_groups'; - - /** - * Create the table if it doesn't exist. - */ - if ($wpdb->get_var('show tables like \'' . $wpdb->avhec_cat_group . '\'') != $wpdb->avhec_cat_group) { - add_action('init', array($this, 'doCreateTable'), 2); // Priority needs to be the same as the Register Taxonomy - } - add_action('init', array($this, 'doRegisterTaxonomy'), 2); // Priority for registering custom taxonomies is +1 over the creation of the initial taxonomies - add_action('init', array($this, 'doSetupOptions')); - - add_action('admin_init', array($this, 'addMetaBoxes')); - } - - /** - * PHP5 style destructor and will run when database object is destroyed. - * - * @return bool Always true - */ - public function __destruct() - { - return true; - } - - /** - * Create Table - * @WordPress action init - */ - public function doCreateTable() - { - global $wpdb; - - // Setup the DB Tables - $charset_collate = ''; - - if (!empty($wpdb->charset)) { - $charset_collate = 'DEFAULT CHARACTER SET ' . $wpdb->charset; - } - if (!empty($wpdb->collate)) { - $charset_collate .= ' COLLATE ' . $wpdb->collate; - } - - $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 . ';'; - - $result = $wpdb->query($sql); - } - - /** - * Setup Group Categories Taxonomy - * @WordPress action init - */ - public function doRegisterTaxonomy() - { - /** - * As we don't want to see the Menu Item we have to disable show_ui. - * This also disables the metabox on the posts and pages, so we add thse manually instead. - * 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. - */ - $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')); - $caps = array('manage_terms' => null, 'edit_terms' => null, 'delete_terms' => null, 'assign_terms' => 'edit_posts'); - 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)); - } - - /** - * Setup the options for the widget titles - * @WordPress action init - */ - public function doSetupOptions() - { - // Setup the standard groups if the none group does not exists. - $all_categories = $this->getAllCategoriesTermID(); - if (false === $this->getTermIDBy('slug', 'none')) { - $none_group_id = wp_insert_term('none', $this->taxonomy_name, array('description' => __('This group will not show the widget.', 'avh-ec'))); - - $home_group_id = wp_insert_term('Home', $this->taxonomy_name, array('description' => __('This group will be shown on the front page.', 'avh-ec'))); - $this->setCategoriesForGroup($home_group_id['term_id'], $all_categories); - $this->setWidgetTitleForGroup($home_group_id['term_id'], ''); - } - if (false === $this->getTermIDBy('slug', 'all')) { - $all_group_id = wp_insert_term('All', $this->taxonomy_name, array('description' => __('Holds all the categories.', 'avh-ec'))); - if (! is_wp_error($all_group_id)) { - $this->setWidgetTitleForGroup($all_group_id['term_id'], ''); - } else { - trigger_error($all_group_id->get_error_message(), E_USER_NOTICE); - } - } - - $options = get_option($this->db_options_widget_titles); - if (!$options) { - $options = array(); - $id = $this->getTermIDBy('slug', 'all'); - $options[$id] = ''; - $id = $this->getTermIDBy('slug', 'home'); - $options[$id] = ''; - update_option($this->db_options_widget_titles, $options); - } - $this->options_widget_titles = $options; - $this->setCategoriesForGroup($this->getTermIDBy('slug', 'all'), $all_categories); - } - - /** - * Add the metaboxes for the pots and page pages. - * @WordPress action admin_init - */ - public function addMetaBoxes() - { - add_meta_box($this->taxonomy_name . 'div', __('Category Groups', 'avh-ec'), 'post_categories_meta_box', 'post', 'side', 'core', array('taxonomy' => $this->taxonomy_name)); - add_meta_box($this->taxonomy_name . 'div', __('Category Groups', 'avh-ec'), 'post_categories_meta_box', 'page', 'side', 'core', array('taxonomy' => $this->taxonomy_name)); - } - - /** - * Get all groups term_id - * - * @return array Term_id - */ - public function getAllCategoriesTermID() - { - $all_cat_id = array(); - $categories = get_categories(); - if (!is_wp_error($categories)) { - foreach ($categories as $category) { - $all_cat_id[] = $category->term_id; - } - } - - return ($all_cat_id); - } - - /** - * Get the categories from the given group from the DB - * - * @param int $group_id - * The Taxonomy Term ID - * @return Array false Will return false, if the row does not exists. - * - */ - public function getCategoriesFromGroup($group_id) - { - global $wpdb; - - // Query database - $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)); - - if (is_array($result)) { // Call succeeded - if (empty($result)) { // No rows found - $return = array(); - } else { - foreach ($result as $row) { - $return[] = $row->term_id; - } - } - } else { - $return = false; - } - - return ($return); - } - - /** - * Set the categories for the given group from the DB. - * Insert the group if it doesn't exists. - * - * @param int $group_id - * The Taxonomy Term ID - * @param array $categories - * The categories - * @return Object (false if not found) - * - */ - public function setCategoriesForGroup($group_id, $categories = array()) - { - global $wpdb; - - $old_categories = $this->getCategoriesFromGroup($group_id); - - if (!is_array($categories)) { - $categories = array(); - } - $new_categories = $categories; - sort($old_categories); - sort($new_categories); - // If the new and old values are the same, no need to update. - if ($new_categories === $old_categories) { - return false; - } - - $new = array_diff($new_categories, $old_categories); - $removed = array_diff($old_categories, $new_categories); - - if (!empty($new)) { - foreach ($new as $cat_term_id) { - $insert[] = '(' . $group_id . ',' . $cat_term_id . ')'; - } - $value = implode(',', $insert); - $sql = 'INSERT INTO ' . $wpdb->avhec_cat_group . ' (group_term_id, term_id) VALUES ' . $value; - $result = $wpdb->query($sql); - } - - if (!empty($removed)) { - $delete = implode(',', $removed); - $sql = $wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE group_term_id=%d and term_id IN (' . $delete . ')', $group_id); - $result = $wpdb->query($sql); - } - - return $result; - } - - /** - * Set the Widget Title for a Group - * - * @param int $group_id - * @param string $widget_title - * - */ - public function setWidgetTitleForGroup($group_id, $widget_title = '') - { - $this->options_widget_titles[$group_id] = $widget_title; - update_option($this->db_options_widget_titles, $this->options_widget_titles); - } - - /** - * Return the title for a group_id if exsist otherwise return false - * - * @param - * $group_id - * - */ - public function getWidgetTitleForGroup($group_id) - { - if (isset($this->options_widget_titles[$group_id])) { - return ($this->options_widget_titles[$group_id]); - } - - return false; - } - - /** - * Delete the Widget Title for a group - * - * @param - * $group_id - */ - public function doDeleteWidgetTitle($group_id) - { - if (isset($this->options_widget_titles[$group_id])) { - unset($this->options_widget_titles[$group_id]); - } - update_option($this->db_options_widget_titles, $this->options_widget_titles); - } - - /** - * Same as get_term_by, but returns the ID only if found, else false - * - * @param string $field - * @param string $value - * @return int boolean - */ - public function getTermIDBy($field, $value) - { - $row = get_term_by($field, $value, $this->taxonomy_name); - if (false === $row) { - $return = false; - } else { - $return = (int) $row->term_id; - } - - return ($return); - } - - /** - * Gets all information of a group - * - * @param - * $group_id - * @return Object false false when the group doesn't exists. - */ - public function getGroup($group_id) - { - global $wpdb; - - $result = get_term((int) $group_id, $this->taxonomy_name); - if (null === $result) { - $result = false; - } - - return ($result); - } - - public function getGroupByCategoryID($category_id) - { - $return = get_term_by('slug', 'none', $this->taxonomy_name); - $cat_groups = get_terms($this->taxonomy_name, array('hide_empty' => false)); - - foreach ($cat_groups as $group) { - $cats = $this->getCategoriesFromGroup($group->term_id); - if ($group->slug != 'all' && in_array($category_id, $cats)) { - $return = $group; - break; - } - } - - return $return; - } - - /** - * Inserts a new group - * - * @param - * $term - * @param array $args - */ - public function doInsertGroup($term, $args = array(), $widget_title = '') - { - $row = wp_insert_term($term, $this->taxonomy_name, $args); - $this->setWidgetTitleForGroup($term, $widget_title); - - return ($row['term_id']); - } - - /** - * Deletes a group - * - * @param - * $group_id - */ - public function doDeleteGroup($group_id) - { - global $wpdb; - - $group = $this->getGroup($group_id); - $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE group_term_id=%d', $group_id)); - $this->doDeleteWidgetTitle($group_id); - $return = wp_delete_term($group->term_id, $this->taxonomy_name); - - return ($return); - } - - /** - * Update a group - * - * @param - * $group_id - * @param - * $selected_categories - * @param $widget_title return - * -1,0,1 Unknown Group, Duplicate Slug, Succesfull - */ - public function doUpdateGroup($group_id, $args = array(), $selected_categories = array(), $widget_title = '') - { - $group = $this->getGroup($group_id); - if (is_object($group)) { - $id = wp_update_term($group->term_id, $this->taxonomy_name, $args); - if (!is_wp_error($id)) { - $this->setWidgetTitleForGroup($group_id, $widget_title); - $this->setCategoriesForGroup($group_id, $selected_categories); - $return = 1; // Succesful - } else { - $return = 0; // Duplicate Slug - } - } else { - $return = -1; // Unknown group - } - - return ($return); - } - - /** - * Deletes the given category from all groups - * - * @param - * $category_id - */ - public function doDeleteCategoryFromGroup($category_id) - { - global $wpdb; - $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE term_id=%d', $category_id)); - } +class AVH_EC_Category_Group { + public $db_options_widget_titles; + public $options_widget_titles; + /** + * Taxonomy name + * + * @var string + */ + public $taxonomy_name; + public $widget_done_catgroup; + + /** + * PHP5 Constructor + * Init the Database Abstraction layer + */ + public function __construct() { + global $wpdb; + + register_shutdown_function(array($this, '__destruct')); + + /** + * Taxonomy name + * + * @var string + */ + $this->taxonomy_name = 'avhec_catgroup'; + + $this->db_options_widget_titles = 'avhec_widget_titles'; + // add DB pointer + $wpdb->avhec_cat_group = $wpdb->prefix . 'avhec_category_groups'; + + /** + * Create the table if it doesn't exist. + */ + if ($wpdb->get_var('show tables like \'' . $wpdb->avhec_cat_group . '\'') != $wpdb->avhec_cat_group) { + add_action('init', + array($this, 'doCreateTable'), + 2); // Priority needs to be the same as the Register Taxonomy + } + add_action('init', + array($this, 'doRegisterTaxonomy'), + 2); // Priority for registering custom taxonomies is +1 over the creation of the initial taxonomies + add_action('init', array($this, 'doSetupOptions')); + + add_action('admin_init', array($this, 'addMetaBoxes')); + } + + /** + * PHP5 style destructor and will run when database object is destroyed. + * + * @return bool Always true + */ + public function __destruct() { + return true; + } + + /** + * Add the metaboxes for the pots and page pages. + * + * @WordPress action admin_init + */ + public function addMetaBoxes() { + add_meta_box($this->taxonomy_name . 'div', + __('Category Groups', 'avh-ec'), + 'post_categories_meta_box', + 'post', + 'side', + 'core', + array('taxonomy' => $this->taxonomy_name)); + add_meta_box($this->taxonomy_name . 'div', + __('Category Groups', 'avh-ec'), + 'post_categories_meta_box', + 'page', + 'side', + 'core', + array('taxonomy' => $this->taxonomy_name)); + } + + /** + * Create Table + * + * @WordPress action init + */ + public function doCreateTable() { + global $wpdb; + + // Setup the DB Tables + $charset_collate = ''; + + if ( ! empty($wpdb->charset)) { + $charset_collate = 'DEFAULT CHARACTER SET ' . $wpdb->charset; + } + if ( ! empty($wpdb->collate)) { + $charset_collate .= ' COLLATE ' . $wpdb->collate; + } + + $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 . + ';'; + + $result = $wpdb->query($sql); + } + + /** + * Deletes the given category from all groups + * + * @param + * $category_id + */ + public function doDeleteCategoryFromGroup($category_id) { + global $wpdb; + $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE term_id=%d', + $category_id)); + } + + /** + * Deletes a group + * + * @param + * $group_id + */ + public function doDeleteGroup($group_id) { + global $wpdb; + + $group = $this->getGroup($group_id); + $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE group_term_id=%d', + $group_id)); + $this->doDeleteWidgetTitle($group_id); + $return = wp_delete_term($group->term_id, $this->taxonomy_name); + + return ($return); + } + + /** + * Delete the Widget Title for a group + * + * @param + * $group_id + */ + public function doDeleteWidgetTitle($group_id) { + if (isset($this->options_widget_titles[ $group_id ])) { + unset($this->options_widget_titles[ $group_id ]); + } + update_option($this->db_options_widget_titles, $this->options_widget_titles); + } + + /** + * Inserts a new group + * + * @param + * $term + * @param array $args + */ + public function doInsertGroup($term, $args = array(), $widget_title = '') { + $row = wp_insert_term($term, $this->taxonomy_name, $args); + $this->setWidgetTitleForGroup($term, $widget_title); + + return ($row['term_id']); + } + + /** + * Setup Group Categories Taxonomy + * + * @WordPress action init + */ + public function doRegisterTaxonomy() { + /** + * As we don't want to see the Menu Item we have to disable show_ui. + * This also disables the metabox on the posts and pages, so we add thse manually instead. + * 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. + */ + $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') + ); + $caps = array( + 'manage_terms' => null, + 'edit_terms' => null, + 'delete_terms' => null, + 'assign_terms' => 'edit_posts' + ); + 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 + )); + } + + /** + * Setup the options for the widget titles + * + * @WordPress action init + */ + public function doSetupOptions() { + // Setup the standard groups if the none group does not exists. + $all_categories = $this->getAllCategoriesTermID(); + if (false === $this->getTermIDBy('slug', 'none')) { + $none_group_id = wp_insert_term('none', + $this->taxonomy_name, + array( + 'description' => __('This group will not show the widget.', 'avh-ec') + )); + + $home_group_id = wp_insert_term('Home', + $this->taxonomy_name, + array( + 'description' => __('This group will be shown on the front page.', + 'avh-ec') + )); + $this->setCategoriesForGroup($home_group_id['term_id'], $all_categories); + $this->setWidgetTitleForGroup($home_group_id['term_id'], ''); + } + if (false === $this->getTermIDBy('slug', 'all')) { + $all_group_id = wp_insert_term('All', + $this->taxonomy_name, + array('description' => __('Holds all the categories.', 'avh-ec'))); + if ( ! is_wp_error($all_group_id)) { + $this->setWidgetTitleForGroup($all_group_id['term_id'], ''); + } else { + trigger_error($all_group_id->get_error_message(), E_USER_NOTICE); + } + } + + $options = get_option($this->db_options_widget_titles); + if ( ! $options) { + $options = array(); + $id = $this->getTermIDBy('slug', 'all'); + $options[ $id ] = ''; + $id = $this->getTermIDBy('slug', 'home'); + $options[ $id ] = ''; + update_option($this->db_options_widget_titles, $options); + } + $this->options_widget_titles = $options; + $this->setCategoriesForGroup($this->getTermIDBy('slug', 'all'), $all_categories); + } + + /** + * Update a group + * + * @param + * $group_id + * @param + * $selected_categories + * @param $widget_title return + * -1,0,1 Unknown Group, Duplicate Slug, Succesfull + */ + public function doUpdateGroup($group_id, $args = array(), $selected_categories = array(), $widget_title = '') { + $group = $this->getGroup($group_id); + if (is_object($group)) { + $id = wp_update_term($group->term_id, $this->taxonomy_name, $args); + if ( ! is_wp_error($id)) { + $this->setWidgetTitleForGroup($group_id, $widget_title); + $this->setCategoriesForGroup($group_id, $selected_categories); + $return = 1; // Succesful + } else { + $return = 0; // Duplicate Slug + } + } else { + $return = - 1; // Unknown group + } + + return ($return); + } + + /** + * Get all groups term_id + * + * @return array Term_id + */ + public function getAllCategoriesTermID() { + $all_cat_id = array(); + $categories = get_categories(); + if ( ! is_wp_error($categories)) { + foreach ($categories as $category) { + $all_cat_id[] = $category->term_id; + } + } + + return ($all_cat_id); + } + + /** + * Get the categories from the given group from the DB + * + * @param int $group_id + * The Taxonomy Term ID + * + * @return Array false Will return false, if the row does not exists. + */ + public function getCategoriesFromGroup($group_id) { + global $wpdb; + + // Query database + $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)); + + if (is_array($result)) { // Call succeeded + if (empty($result)) { // No rows found + $return = array(); + } else { + foreach ($result as $row) { + $return[] = $row->term_id; + } + } + } else { + $return = false; + } + + return ($return); + } + + /** + * Gets all information of a group + * + * @param + * $group_id + * + * @return Object false false when the group doesn't exists. + */ + public function getGroup($group_id) { + global $wpdb; + + $result = get_term((int) $group_id, $this->taxonomy_name); + if (null === $result) { + $result = false; + } + + return ($result); + } + + public function getGroupByCategoryID($category_id) { + $return = get_term_by('slug', 'none', $this->taxonomy_name); + $cat_groups = get_terms($this->taxonomy_name, array('hide_empty' => false)); + + foreach ($cat_groups as $group) { + $cats = $this->getCategoriesFromGroup($group->term_id); + if ($group->slug != 'all' && in_array($category_id, $cats)) { + $return = $group; + break; + } + } + + return $return; + } + + /** + * Same as get_term_by, but returns the ID only if found, else false + * + * @param string $field + * @param string $value + * + * @return int boolean + */ + public function getTermIDBy($field, $value) { + $row = get_term_by($field, $value, $this->taxonomy_name); + if (false === $row) { + $return = false; + } else { + $return = (int) $row->term_id; + } + + return ($return); + } + + /** + * Return the title for a group_id if exsist otherwise return false + * + * @param + * $group_id + */ + public function getWidgetTitleForGroup($group_id) { + if (isset($this->options_widget_titles[ $group_id ])) { + return ($this->options_widget_titles[ $group_id ]); + } + + return false; + } + + /** + * Set the categories for the given group from the DB. + * Insert the group if it doesn't exists. + * + * @param int $group_id + * The Taxonomy Term ID + * @param array $categories + * The categories + * + * @return Object (false if not found) + */ + public function setCategoriesForGroup($group_id, $categories = array()) { + global $wpdb; + + $old_categories = $this->getCategoriesFromGroup($group_id); + + if ( ! is_array($categories)) { + $categories = array(); + } + $new_categories = $categories; + sort($old_categories); + sort($new_categories); + // If the new and old values are the same, no need to update. + if ($new_categories === $old_categories) { + return false; + } + + $new = array_diff($new_categories, $old_categories); + $removed = array_diff($old_categories, $new_categories); + + if ( ! empty($new)) { + foreach ($new as $cat_term_id) { + $insert[] = '(' . $group_id . ',' . $cat_term_id . ')'; + } + $value = implode(',', $insert); + $sql = 'INSERT INTO ' . $wpdb->avhec_cat_group . ' (group_term_id, term_id) VALUES ' . $value; + $result = $wpdb->query($sql); + } + + if ( ! empty($removed)) { + $delete = implode(',', $removed); + $sql = $wpdb->prepare('DELETE FROM ' . + $wpdb->avhec_cat_group . + ' WHERE group_term_id=%d and term_id IN (' . + $delete . + ')', + $group_id); + $result = $wpdb->query($sql); + } + + return $result; + } + + /** + * Set the Widget Title for a Group + * + * @param int $group_id + * @param string $widget_title + */ + public function setWidgetTitleForGroup($group_id, $widget_title = '') { + $this->options_widget_titles[ $group_id ] = $widget_title; + update_option($this->db_options_widget_titles, $this->options_widget_titles); + } } diff --git a/wp-content/plugins/extended-categories-widget/3.6/class/avh-ec.core.php b/wp-content/plugins/extended-categories-widget/3.6/class/avh-ec.core.php index b580f8cdddc87ecdf020caeafb4142dd661d8dd3..99000b98f1dd798df90ad143d3178c60f83d2bd1 100644 --- a/wp-content/plugins/extended-categories-widget/3.6/class/avh-ec.core.php +++ b/wp-content/plugins/extended-categories-widget/3.6/class/avh-ec.core.php @@ -1,797 +1,828 @@ <?php -class AVH_EC_Core -{ - - public $version; - - public $comment; - - public $info; - - public $db_options_core; - - public $default_options; - - public $default_options_general; - - public $default_options_category_group; - - public $default_options_sp_category_group; - - public $db_options_tax_meta; - - public $options; - - /** - * PHP5 constructor - */ - public function __construct() - { - /** - * - * @var AVH_EC_Category_Group - */ - $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); - - $this->version = '4.0.1'; - $this->comment = '<!-- AVH Extended Categories version ' . $this->version . ' | http://blog.avirtualhome.com/wordpress-plugins/ -->'; - $this->db_options_core = 'avhec'; - $this->db_options_tax_meta = 'avhec-tax_meta'; - - add_action('init', array($this, 'handleInitializePlugin'), 10); - } - - public function handleInitializePlugin() - { - global $wpdb; - - $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); - $db_version = 4; - - $info['siteurl'] = get_option('siteurl'); - $info['plugin_dir'] = AVHEC_PLUGIN_DIR; - $info['graphics_url'] = AVHEC_PLUGIN_URL . '/images'; - - // Set class property for info - $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']); - - // Set the default options - $this->default_options_general = array('version' => $this->version, 'dbversion' => $db_version, 'alternative_name_select_category' => ''); - - // Set the default category group options - $no_group_id = $catgrp->getTermIDBy('slug', 'none'); - $home_group_id = $catgrp->getTermIDBy('slug', 'home'); - $default_group_id = $catgrp->getTermIDBy('slug', 'all'); - $this->default_options_category_group = array('no_group' => $no_group_id, 'home_group' => $home_group_id, 'default_group' => $default_group_id); - - $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); - - $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); - - /** - * Set the options for the program - */ - $this->loadOptions(); - - // Check if we have to do updates - if ((!isset($this->options['general']['dbversion'])) || $this->options['general']['dbversion'] < $db_version) { - $this->doUpdateOptions($db_version); - } - - $db = new AVH_DB(); - if (!$db->field_exists('avhec_term_order', $wpdb->terms)) { - $wpdb->query("ALTER TABLE $wpdb->terms ADD `avhec_term_order` INT( 4 ) null DEFAULT '0'"); - } - - $this->handleTextdomain(); - add_filter('get_terms_orderby', array($this, 'applyOrderFilter'), 10, 2); - } - - public function applyOrderFilter($orderby, $args) - { - switch ($args['orderby']) { - case 'avhec_manualorder': - $new_orderby = 't.avhec_term_order'; - break; - case 'avhec_3rdparty_mycategoryorder': - $new_orderby = 't.term_order'; - break; - default: - $new_orderby = $orderby; - break; - } - - return $new_orderby; - } - - /** - * Loads the i18n - */ - public function handleTextdomain() - { - load_plugin_textdomain('avh-ec', false, AVHEC_RELATIVE_PLUGIN_DIR . '/lang'); - } - - /** - * Checks if running version is newer and do upgrades if necessary - * - * @since 1.2.3 - * - */ - public function doUpdateOptions($db_version) - { - $options = $this->getOptions(); - - // Add none existing sections and/or elements to the options - foreach ($this->default_options as $section => $default_data) { - if (!array_key_exists($section, $options)) { - $options[$section] = $default_data; - continue; - } - foreach ($default_data as $element => $default_value) { - if (!array_key_exists($element, $options[$section])) { - $options[$section][$element] = $default_value; - } - } - } - - // Remove none existing sections and/or elements from the options - foreach ($options as $section => $data) { - if (!array_key_exists($section, $this->default_options)) { - unset($options[$section]); - continue; - } - foreach ($data as $element => $value) { - if (!array_key_exists($element, $this->default_options[$section])) { - unset($options[$section][$element]); - } - } - } - /** - * Update the options to the latests versions - */ - $options['general']['version'] = $this->version; - $options['general']['dbversion'] = $db_version; - $this->saveOptions($options); - } - - /** - * Used in forms to set the checked option. - * - * @param mixed $checked - * @param mixed_type $current - * @return string - * - * @since 2.0 - */ - public function isChecked($checked, $current) - { - if ($checked == $current) { - return (' checked="checked"'); - } - - return (''); - } - - /** - * Used in forms to set the SELECTED option - * - * @param string $current - * @param string $field - * @return string - */ - public function isSelected($current, $field) - { - if ($current == $field) { - return (' SELECTED'); - } - - return (''); - } - - /** - * Get the base directory of a directory structure - * - * @param string $directory - * @return string - * - */ - public function getBaseDirectory($directory) - { - // place each directory into array and get the last element - $directory_array = explode('/', $directory); - // get highest or top level in array of directory strings - $public_base = end($directory_array); - - return $public_base; - } - - /** - * ******************************* - * * - * Methods for variable: options * - * * - * ****************************** - */ - - /** - * - * @param array $data - */ - public function setOptions($options) - { - $this->options = $options; - } - - /** - * return array - */ - public function getOptions() - { - return ($this->options); - } - - /** - * Save all current options and set the options - */ - public function saveOptions($options) - { - update_option($this->db_options_core, $options); - wp_cache_flush(); // Delete cache - $this->setOptions($options); - } - - /** - * Retrieves the plugin options from the WordPress options table and assigns to class variable. - * If the options do not exists, like a new installation, the options are set to the default value. - * - * @return none - */ - public function loadOptions() - { - $options = get_option($this->db_options_core); - if (false === $options) { // New installation - $this->resetToDefaultOptions(); - } else { - $this->setOptions($options); - } - } - - /** - * Get the value for an option element. - * If there's no option is set on the Admin page, return the default value. - * - * @param string $key - * @param string $option - * @return mixed - */ - public function getOptionElement($option, $key) - { - if ($this->options[$option][$key]) { - $return = $this->options[$option][$key]; // From Admin Page - } else { - $return = $this->default_options[$option][$key]; // Default - } - - return ($return); - } - - /** - * Reset to default options and save in DB - */ - public function resetToDefaultOptions() - { - $this->options = $this->default_options; - $this->saveOptions($this->default_options); - } - - /** - * Display or retrieve the HTML dropdown list of categories. - * - * The list of arguments is below: - * 'show_option_all' (string) - Text to display for showing all categories. - * 'show_option_none' (string) - Text to display for showing no categories. - * 'orderby' (string) default is 'ID' - What column to use for ordering the - * categories. - * 'order' (string) default is 'ASC' - What direction to order categories. - * 'show_last_update' (bool|int) default is 0 - See {@link get_categories()} - * 'show_count' (bool|int) default is 0 - Whether to show how many posts are - * in the category. - * 'hide_empty' (bool|int) default is 1 - Whether to hide categories that - * don't have any posts attached to them. - * 'child_of' (int) default is 0 - See {@link get_categories()}. - * 'exclude' (string) - See {@link get_categories()}. - * 'echo' (bool|int) default is 1 - Whether to display or retrieve content. - * 'depth' (int) - The max depth. - * 'tab_index' (int) - Tab index for select element. - * 'name' (string) - The name attribute value for selected element. - * 'class' (string) - The class attribute value for selected element. - * 'selected' (int) - Which category ID is selected. - * - * The 'hierarchical' argument, which is disabled by default, will override the - * depth argument, unless it is true. When the argument is false, it will - * display all of the categories. When it is enabled it will use the value in - * the 'depth' argument. - * - * @since 2.1.0 - * - * @param string|array $args - * Optional. Override default arguments. - * @return string HTML content only if 'echo' argument is 0. - */ - public function avh_wp_dropdown_categories($args = array()) - { - $mywalker = new AVH_Walker_CategoryDropdown(); - - // @format_off - $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); - // @format_on - $defaults['selected'] = (is_category()) ? get_query_var('cat') : 0; - - $r = wp_parse_args($args, $defaults); - - if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) { - $r['pad_counts'] = true; - } - - $r['include_last_update_time'] = $r['show_last_update']; - extract($r); - - $tab_index_attribute = ''; - if ((int) $tab_index > 0) { - $tab_index_attribute = ' tabindex="' . $tab_index . '"'; - } - - $categories = get_terms($taxonomy, $r); - $name = esc_attr($name); - $class = esc_attr($class); - $id = $id ? esc_attr($id) : $name; - - if (!$r['hide_if_empty'] || !empty($categories)) { - $output = "<select name='$name' id='$id' class='$class' $tab_index_attribute>\n"; - } else { - $output = ''; - } - - if (empty($categories) && !$r['hide_if_empty'] && !empty($show_option_none)) { - $show_option_none = apply_filters('list_cats', $show_option_none); - $output .= "\t<option value='-1' selected='selected'>$show_option_none</option>\n"; - } - if (!empty($categories)) { - - if ($show_option_all) { - $show_option_all = apply_filters('list_cats', $show_option_all); - $selected = ('0' === strval($r['selected'])) ? " selected='selected'" : ''; - $output .= "\t" . '<option value="0"' . $selected . '>' . $show_option_all . '</option>' . "\n"; - } - - if ($show_option_none) { - $show_option_none = apply_filters('list_cats', $show_option_none); - $selected = ('-1' === strval($r['selected'])) ? " selected='selected'" : ''; - $output .= "\t" . '<option value="-1"' . $selected . '>' . $show_option_none . '</option>' . "\n"; - } - - if ($hierarchical) { - $depth = $r['depth']; // Walk the full depth. - } else { - $depth = -1; // Flat - } - $output .= walk_category_dropdown_tree($categories, $depth, $r); - } - if (!$r['hide_if_empty'] || !empty($categories)) { - $output .= "</select>\n"; - } - - $output = apply_filters('wp_dropdown_cats', $output); - - if ($echo) { - echo $output; - } - - return $output; - } - - /** - * Display or retrieve the HTML list of categories. - * - * The list of arguments is below: - * 'show_option_all' (string) - Text to display for showing all categories. - * 'orderby' (string) default is 'ID' - What column to use for ordering the - * categories. - * 'order' (string) default is 'ASC' - What direction to order categories. - * 'show_last_update' (bool|int) default is 0 - See {@link - * walk_category_dropdown_tree()} - * 'show_count' (bool|int) default is 0 - Whether to show how many posts are - * in the category. - * 'hide_empty' (bool|int) default is 1 - Whether to hide categories that - * don't have any posts attached to them. - * 'use_desc_for_title' (bool|int) default is 1 - Whether to use the - * description instead of the category title. - * 'feed' - See {@link get_categories()}. - * 'feed_type' - See {@link get_categories()}. - * 'feed_image' - See {@link get_categories()}. - * 'child_of' (int) default is 0 - See {@link get_categories()}. - * 'exclude' (string) - See {@link get_categories()}. - * 'exclude_tree' (string) - See {@link get_categories()}. - * 'echo' (bool|int) default is 1 - Whether to display or retrieve content. - * 'current_category' (int) - See {@link get_categories()}. - * 'hierarchical' (bool) - See {@link get_categories()}. - * 'title_li' (string) - See {@link get_categories()}. - * 'depth' (int) - The max depth. - * - * @since 2.1.0 - * - * @param string|array $args - * Optional. Override default arguments. - * @return string HTML content only if 'echo' argument is 0. - */ - public function avh_wp_list_categories($args = array()) - { - $mywalker = new AVHEC_Walker_Category(); - $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); - - $r = wp_parse_args($args, $defaults); - - if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) { - $r['pad_counts'] = true; - } - - if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) { - $r['pad_counts'] = true; - } - - if (isset($r['show_date'])) { - $r['include_last_update_time'] = $r['show_date']; - } - - if (true == $r['hierarchical']) { - $r['exclude_tree'] = $r['exclude']; - $r['exclude'] = ''; - } - - extract($r); - - $categories = get_categories($r); - - $output = ''; - if ($title_li && 'list' == $style) { - $output = '<li class="categories">' . $r['title_li'] . '<ul>'; - } - - if (empty($categories)) { - if ('list' == $style) { - $output .= '<li>' . __("No categories") . '</li>'; - } else { - $output .= __("No categories"); - } - } else { - global $wp_query; - - if (!empty($show_option_all)) { - if ('list' == $style) { - $output .= '<li><a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a></li>'; - } else { - $output .= '<a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a>'; - } - } - if (empty($r['current_category']) && is_category()) { - $r['current_category'] = $wp_query->get_queried_object_id(); - } - - if ($hierarchical) { - $depth = $r['depth']; - } else { - $depth = -1; // Flat. - } - - $output .= walk_category_tree($categories, $depth, $r); - } - - if ($title_li && 'list' == $style) { - $output .= '</ul></li>'; - } - - $output = apply_filters('wp_list_categories', $output); - - if ($echo) { - echo $output; - } else { - return $output; - } - } - - public function getCategories() - { - static $_categories = null; - if (null === $_categories) { - $_categories = get_categories('get=all'); - } - - return $_categories; - } - - public function getCategoriesId($categories) - { - static $_categories_id = null; - if (null == $_categories_id) { - foreach ($categories as $key => $category) { - $_categories_id[$category->term_id] = $key; - } - } - - return $_categories_id; - } -} - /** - * Create HTML dropdown list of Categories. + * Create HTML list of categories. * * @uses Walker */ -class AVH_Walker_CategoryDropdown extends Walker_CategoryDropdown -{ - - public function walk($elements, $max_depth) - { - $args = array_slice(func_get_args(), 2); - $output = ''; - - if ($max_depth < -1) { - return $output; - } - - if (empty($elements)) { - return $output; - } - - $id_field = $this->db_fields['id']; - $parent_field = $this->db_fields['parent']; - - // flat display - if (-1 == $max_depth) { - $empty_array = array(); - foreach ($elements as $e) { - $this->display_element($e, $empty_array, 1, 0, $args, $output); - } - - return $output; - } - - /* - * 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. - */ - $top_level_elements = array(); - $children_elements = array(); - foreach ($elements as $e) { - if (0 == $e->$parent_field) { - $top_level_elements[] = $e; - } else { - $children_elements[$e->$parent_field][] = $e; - } - } - - /* - * when none of the elements is top level assume the first one must be root of the sub elements - */ - if (empty($top_level_elements)) { - - $first = array_slice($elements, 0, 1); - $root = $first[0]; - - $top_level_elements = array(); - $children_elements = array(); - foreach ($elements as $e) { - if ($root->$parent_field == $e->$parent_field) { - $top_level_elements[] = $e; - } else { - $children_elements[$e->$parent_field][] = $e; - } - } - } - - foreach ($top_level_elements as $e) { - $this->display_element($e, $children_elements, $max_depth, 0, $args, $output); - } - - /* - * if we are displaying all levels, and remaining children_elements is not empty, then we got orphans, which should be displayed regardless - */ - if ((0 == $max_depth) && count($children_elements) > 0) { - $empty_array = array(); - foreach ($children_elements as $orphans) { - foreach ($orphans as $op) { - $this->display_element($op, $empty_array, 1, 0, $args, $output); - } - } - } - - return $output; - } +class AVHEC_Walker_Category extends Walker { + /** + * @see Walker::$db_fields + * @since 2.1.0 + * @todo Decouple this + * @var array + */ + public $db_fields = array('parent' => 'parent', 'id' => 'term_id'); + /** + * @see Walker::$tree_type + * @since 2.1.0 + * @var string + */ + public $tree_type = 'category'; + + /** + * @see Walker::end_el() + * @since 2.1.0 + * + * @param string $output + * Passed by reference. Used to append additional content. + * @param object $page + * Not used. + * @param int $depth + * Depth of category. Not used. + * @param array $args + * Only uses 'list' for whether should append to output. + */ + public function end_el(&$output, $object, $depth = 0, $args = array()) { + if ('list' != $args['style']) { + return; + } + + $output .= '</li>' . "\n"; + } + + /** + * @see Walker::end_lvl() + * @since 2.1.0 + * + * @param string $output + * Passed by reference. Used to append additional content. + * @param int $depth + * Depth of category. Used for tab indentation. + * @param array $args + * Will only append content if style argument value is 'list'. + */ + public function end_lvl(&$output, $depth = 0, $args = array()) { + if ('list' != $args['style']) { + return; + } + + $indent = str_repeat("\t", $depth); + $output .= $indent . '</ul>' . "\n"; + } + + /** + * @see Walker::start_el() + * @since 2.1.0 + * + * @param string $output + * Passed by reference. Used to append additional content. + * @param object $object + * Category data object. + * @param int $depth + * Depth of category in reference to parents. + * @param array $args + */ + public function start_el(&$output, $object, $depth = 0, $args = array(), $current_object_id = 0) { + extract($args); + + $cat_name = esc_attr($object->name); + $cat_name = apply_filters('list_cats', $cat_name, $object); + $link = '<div class="avhec-widget-line"><a href="' . get_category_link($object->term_id) . '" '; + if ($use_desc_for_title == 0 || empty($object->description)) { + $link .= 'title="' . sprintf(__('View all posts filed under %s'), $cat_name) . '"'; + } else { + $link .= 'title="' . + esc_attr(strip_tags(apply_filters('category_description', $object->description, $object))) . + '"'; + } + $link .= '>'; + $link .= $cat_name . '</a>'; + + if (( ! empty($feed_image)) || ( ! empty($feed))) { + $link .= '<div class="avhec-widget-rss"> '; + + if (empty($feed_image)) { + $link .= '('; + } + + $link .= '<a href="' . get_category_feed_link($object->term_id, $feed_type) . '"'; + + if (empty($feed)) { + $alt = ' alt="' . sprintf(__('Feed for all posts filed under %s'), $cat_name) . '"'; + } else { + $title = ' title="' . $feed . '"'; + $alt = ' alt="' . $feed . '"'; + $name = $feed; + $link .= $title; + } + + $link .= '>'; + + if (empty($feed_image)) { + $link .= $name; + } else { + $link .= '<img src="' . $feed_image . '"' . $alt . $title . ' />'; + } + $link .= '</a>'; + if (empty($feed_image)) { + $link .= ')'; + } + $link .= '</div>'; + } + + if (isset($show_count) && $show_count) { + $link .= '<div class="avhec-widget-count"> (' . intval($object->count) . ')</div>'; + } + + if (isset($show_date) && $show_date) { + $link .= ' ' . gmdate('Y-m-d', $object->last_update_timestamp); + } + + // When on a single post get the post's category. This ensures that that category will be given the CSS style of "current category". + if (is_single()) { + $post_cats = get_the_category(); + $current_category = $post_cats[0]->term_id; + } + + if (isset($current_category) && $current_category) { + $_current_category = get_category($current_category); + } + + if ('list' == $args['style']) { + $output .= "\t" . '<li'; + $class = 'cat-item cat-item-' . $object->term_id; + if (isset($current_category) && $current_category && ($object->term_id == $current_category)) { + $class .= ' current-cat'; + } elseif (isset($_current_category) && + $_current_category && + ($object->term_id == $_current_category->parent) + ) { + $class .= ' current-cat-parent'; + } + $output .= ' class="' . $class . '"'; + $output .= '>' . $link . '</div>' . "\n"; + } else { + $output .= "\t" . $link . '</div><br />' . "\n"; + } + } + + /** + * @see Walker::start_lvl() + * @since 2.1.0 + * + * @param string $output + * Passed by reference. Used to append additional content. + * @param int $depth + * Depth of category. Used for tab indentation. + * @param array $args + * Will only append content if style argument value is 'list'. + */ + public function start_lvl(&$output, $depth = 0, $args = array()) { + if ('list' != $args['style']) { + return; + } + + $indent = str_repeat("\t", $depth); + $output .= $indent . '<ul class="children">' . "\n"; + } +} + +class AVH_EC_Core { + public $comment; + public $db_options_core; + public $db_options_tax_meta; + public $default_options; + public $default_options_category_group; + public $default_options_general; + public $default_options_sp_category_group; + public $info; + public $options; + public $version; + + /** + * PHP5 constructor + */ + public function __construct() { + /** + * @var AVH_EC_Category_Group + */ + $catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); + + $this->version = '4.0.3-dev.1'; + $this->comment = '<!-- AVH Extended Categories version ' . + $this->version . + ' | http://blog.avirtualhome.com/wordpress-plugins/ -->'; + $this->db_options_core = 'avhec'; + $this->db_options_tax_meta = 'avhec-tax_meta'; + + add_action('init', array($this, 'handleInitializePlugin'), 10); + } + + public function applyOrderFilter($orderby, $args) { + switch ($args['orderby']) { + case 'avhec_manualorder': + $new_orderby = 't.avhec_term_order'; + break; + case 'avhec_3rdparty_mycategoryorder': + $new_orderby = 't.term_order'; + break; + default: + $new_orderby = $orderby; + break; + } + + return $new_orderby; + } + + /** + * Display or retrieve the HTML dropdown list of categories. + * The list of arguments is below: + * 'show_option_all' (string) - Text to display for showing all categories. + * 'show_option_none' (string) - Text to display for showing no categories. + * 'orderby' (string) default is 'ID' - What column to use for ordering the + * categories. + * 'order' (string) default is 'ASC' - What direction to order categories. + * 'show_last_update' (bool|int) default is 0 - See {@link get_categories()} + * 'show_count' (bool|int) default is 0 - Whether to show how many posts are + * in the category. + * 'hide_empty' (bool|int) default is 1 - Whether to hide categories that + * don't have any posts attached to them. + * 'child_of' (int) default is 0 - See {@link get_categories()}. + * 'exclude' (string) - See {@link get_categories()}. + * 'echo' (bool|int) default is 1 - Whether to display or retrieve content. + * 'depth' (int) - The max depth. + * 'tab_index' (int) - Tab index for select element. + * 'name' (string) - The name attribute value for selected element. + * 'class' (string) - The class attribute value for selected element. + * 'selected' (int) - Which category ID is selected. + * The 'hierarchical' argument, which is disabled by default, will override the + * depth argument, unless it is true. When the argument is false, it will + * display all of the categories. When it is enabled it will use the value in + * the 'depth' argument. + * + * @since 2.1.0 + * + * @param string|array $args + * Optional. Override default arguments. + * + * @return string HTML content only if 'echo' argument is 0. + */ + public function avh_wp_dropdown_categories($args = array()) { + $mywalker = new AVH_Walker_CategoryDropdown(); + + // @format_off + $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 + ); + // @format_on + $defaults['selected'] = (is_category()) ? get_query_var('cat') : 0; + + $r = wp_parse_args($args, $defaults); + + if ( ! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) { + $r['pad_counts'] = true; + } + + $r['include_last_update_time'] = $r['show_last_update']; + extract($r); + + $tab_index_attribute = ''; + if ((int) $tab_index > 0) { + $tab_index_attribute = ' tabindex="' . $tab_index . '"'; + } + + $categories = get_terms($taxonomy, $r); + $name = esc_attr($name); + $class = esc_attr($class); + $id = $id ? esc_attr($id) : $name; + + if ( ! $r['hide_if_empty'] || ! empty($categories)) { + $output = "<select name='$name' id='$id' class='$class' $tab_index_attribute>\n"; + } else { + $output = ''; + } + + if (empty($categories) && ! $r['hide_if_empty'] && ! empty($show_option_none)) { + $show_option_none = apply_filters('list_cats', $show_option_none); + $output .= "\t<option value='-1' selected='selected'>$show_option_none</option>\n"; + } + if ( ! empty($categories)) { + + if ($show_option_all) { + $show_option_all = apply_filters('list_cats', $show_option_all); + $selected = ('0' === strval($r['selected'])) ? " selected='selected'" : ''; + $output .= "\t" . '<option value="0"' . $selected . '>' . $show_option_all . '</option>' . "\n"; + } + + if ($show_option_none) { + $show_option_none = apply_filters('list_cats', $show_option_none); + $selected = ('-1' === strval($r['selected'])) ? " selected='selected'" : ''; + $output .= "\t" . '<option value="-1"' . $selected . '>' . $show_option_none . '</option>' . "\n"; + } + + if ($hierarchical) { + $depth = $r['depth']; // Walk the full depth. + } else { + $depth = - 1; // Flat + } + $output .= walk_category_dropdown_tree($categories, $depth, $r); + } + if ( ! $r['hide_if_empty'] || ! empty($categories)) { + $output .= "</select>\n"; + } + + $output = apply_filters('wp_dropdown_cats', $output); + + if ($echo) { + echo $output; + } + + return $output; + } + + /** + * Display or retrieve the HTML list of categories. + * The list of arguments is below: + * 'show_option_all' (string) - Text to display for showing all categories. + * 'orderby' (string) default is 'ID' - What column to use for ordering the + * categories. + * 'order' (string) default is 'ASC' - What direction to order categories. + * 'show_last_update' (bool|int) default is 0 - See {@link + * walk_category_dropdown_tree()} + * 'show_count' (bool|int) default is 0 - Whether to show how many posts are + * in the category. + * 'hide_empty' (bool|int) default is 1 - Whether to hide categories that + * don't have any posts attached to them. + * 'use_desc_for_title' (bool|int) default is 1 - Whether to use the + * description instead of the category title. + * 'feed' - See {@link get_categories()}. + * 'feed_type' - See {@link get_categories()}. + * 'feed_image' - See {@link get_categories()}. + * 'child_of' (int) default is 0 - See {@link get_categories()}. + * 'exclude' (string) - See {@link get_categories()}. + * 'exclude_tree' (string) - See {@link get_categories()}. + * 'echo' (bool|int) default is 1 - Whether to display or retrieve content. + * 'current_category' (int) - See {@link get_categories()}. + * 'hierarchical' (bool) - See {@link get_categories()}. + * 'title_li' (string) - See {@link get_categories()}. + * 'depth' (int) - The max depth. + * + * @since 2.1.0 + * + * @param string|array $args + * Optional. Override default arguments. + * + * @return string HTML content only if 'echo' argument is 0. + */ + public function avh_wp_list_categories($args = array()) { + $mywalker = new AVHEC_Walker_Category(); + $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 + ); + + $r = wp_parse_args($args, $defaults); + + if ( ! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) { + $r['pad_counts'] = true; + } + + if ( ! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) { + $r['pad_counts'] = true; + } + + if (isset($r['show_date'])) { + $r['include_last_update_time'] = $r['show_date']; + } + + if (true == $r['hierarchical']) { + $r['exclude_tree'] = $r['exclude']; + $r['exclude'] = ''; + } + + extract($r); + + $categories = get_categories($r); + + $output = ''; + if ($title_li && 'list' == $style) { + $output = '<li class="categories">' . $r['title_li'] . '<ul>'; + } + + if (empty($categories)) { + if ('list' == $style) { + $output .= '<li>' . __("No categories") . '</li>'; + } else { + $output .= __("No categories"); + } + } else { + global $wp_query; + + if ( ! empty($show_option_all)) { + if ('list' == $style) { + $output .= '<li><a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a></li>'; + } else { + $output .= '<a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a>'; + } + } + if (empty($r['current_category']) && is_category()) { + $r['current_category'] = $wp_query->get_queried_object_id(); + } + + if ($hierarchical) { + $depth = $r['depth']; + } else { + $depth = - 1; // Flat. + } + + $output .= walk_category_tree($categories, $depth, $r); + } + + if ($title_li && 'list' == $style) { + $output .= '</ul></li>'; + } + + $output = apply_filters('wp_list_categories', $output); + + if ($echo) { + echo $output; + } else { + return $output; + } + } + + /** + * Checks if running version is newer and do upgrades if necessary + * + * @since 1.2.3 + */ + public function doUpdateOptions($db_version) { + $options = $this->getOptions(); + + // Add none existing sections and/or elements to the options + foreach ($this->default_options as $section => $default_data) { + if ( ! array_key_exists($section, $options)) { + $options[ $section ] = $default_data; + continue; + } + foreach ($default_data as $element => $default_value) { + if ( ! array_key_exists($element, $options[ $section ])) { + $options[ $section ][ $element ] = $default_value; + } + } + } + + // Remove none existing sections and/or elements from the options + foreach ($options as $section => $data) { + if ( ! array_key_exists($section, $this->default_options)) { + unset($options[ $section ]); + continue; + } + foreach ($data as $element => $value) { + if ( ! array_key_exists($element, $this->default_options[ $section ])) { + unset($options[ $section ][ $element ]); + } + } + } + /** + * Update the options to the latests versions + */ + $options['general']['version'] = $this->version; + $options['general']['dbversion'] = $db_version; + $this->saveOptions($options); + } + + /** + * Get the base directory of a directory structure + * + * @param string $directory + * + * @return string + */ + public function getBaseDirectory($directory) { + // place each directory into array and get the last element + $directory_array = explode('/', $directory); + // get highest or top level in array of directory strings + $public_base = end($directory_array); + + return $public_base; + } + + public function getCategories() { + static $_categories = null; + if (null === $_categories) { + $_categories = get_categories('get=all'); + } + + return $_categories; + } + + public function getCategoriesId($categories) { + static $_categories_id = null; + if (null == $_categories_id) { + foreach ($categories as $key => $category) { + $_categories_id[ $category->term_id ] = $key; + } + } + + return $_categories_id; + } + + /** + * ******************************* + * * + * Methods for variable: options * + * * + * ****************************** + */ + + /** + * Get the value for an option element. + * If there's no option is set on the Admin page, return the default value. + * + * @param string $key + * @param string $option + * + * @return mixed + */ + public function getOptionElement($option, $key) { + if ($this->options[ $option ][ $key ]) { + $return = $this->options[ $option ][ $key ]; // From Admin Page + } else { + $return = $this->default_options[ $option ][ $key ]; // Default + } + + return ($return); + } + + /** + * return array + */ + public function getOptions() { + return ($this->options); + } + + /** + * @param array $data + */ + public function setOptions($options) { + $this->options = $options; + } + + public function handleInitializePlugin() { + global $wpdb; + + $catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); + $db_version = 4; + + $info['siteurl'] = get_option('siteurl'); + $info['plugin_dir'] = AVHEC_PLUGIN_DIR; + $info['graphics_url'] = AVHEC_PLUGIN_URL . '/images'; + + // Set class property for info + $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'] + ); + + // Set the default options + $this->default_options_general = array( + 'version' => $this->version, + 'dbversion' => $db_version, + 'alternative_name_select_category' => '' + ); + + // Set the default category group options + $no_group_id = $catgrp->getTermIDBy('slug', 'none'); + $home_group_id = $catgrp->getTermIDBy('slug', 'home'); + $default_group_id = $catgrp->getTermIDBy('slug', 'all'); + $this->default_options_category_group = array( + 'no_group' => $no_group_id, + 'home_group' => $home_group_id, + 'default_group' => $default_group_id + ); + + $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 + ); + + $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 + ); + + /** + * Set the options for the program + */ + $this->loadOptions(); + + // Check if we have to do updates + if (( ! isset($this->options['general']['dbversion'])) || + $this->options['general']['dbversion'] < $db_version + ) { + $this->doUpdateOptions($db_version); + } + + $db = new AVH_DB(); + if ( ! $db->field_exists('avhec_term_order', $wpdb->terms)) { + $wpdb->query("ALTER TABLE $wpdb->terms ADD `avhec_term_order` INT( 4 ) null DEFAULT '0'"); + } + + $this->handleTextdomain(); + add_filter('get_terms_orderby', array($this, 'applyOrderFilter'), 10, 2); + } + + /** + * Loads the i18n + */ + public function handleTextdomain() { + load_plugin_textdomain('avh-ec', false, AVHEC_RELATIVE_PLUGIN_DIR . '/lang'); + } + + /** + * Used in forms to set the checked option. + * + * @param mixed $checked + * @param mixed_type $current + * + * @return string + * @since 2.0 + */ + public function isChecked($checked, $current) { + if ($checked == $current) { + return (' checked="checked"'); + } + + return (''); + } + + /** + * Used in forms to set the SELECTED option + * + * @param string $current + * @param string $field + * + * @return string + */ + public function isSelected($current, $field) { + if ($current == $field) { + return (' SELECTED'); + } + + return (''); + } + + /** + * Retrieves the plugin options from the WordPress options table and assigns to class variable. + * If the options do not exists, like a new installation, the options are set to the default value. + * + * @return none + */ + public function loadOptions() { + $options = get_option($this->db_options_core); + if (false === $options) { // New installation + $this->resetToDefaultOptions(); + } else { + $this->setOptions($options); + } + } + + /** + * Reset to default options and save in DB + */ + public function resetToDefaultOptions() { + $this->options = $this->default_options; + $this->saveOptions($this->default_options); + } + + /** + * Save all current options and set the options + */ + public function saveOptions($options) { + update_option($this->db_options_core, $options); + wp_cache_flush(); // Delete cache + $this->setOptions($options); + } } /** - * Create HTML list of categories. + * Create HTML dropdown list of Categories. * * @uses Walker */ -class AVHEC_Walker_Category extends Walker -{ - - /** - * - * @see Walker::$tree_type - * @since 2.1.0 - * @var string - */ - public $tree_type = 'category'; - - /** - * - * @see Walker::$db_fields - * @since 2.1.0 - * @todo Decouple this - * @var array - */ - public $db_fields = array('parent' => 'parent', 'id' => 'term_id'); - - /** - * - * @see Walker::start_lvl() - * @since 2.1.0 - * - * @param string $output - * Passed by reference. Used to append additional content. - * @param int $depth - * Depth of category. Used for tab indentation. - * @param array $args - * Will only append content if style argument value is 'list'. - */ - public function start_lvl(&$output, $depth = 0, $args = array()) - { - if ('list' != $args['style']) { - return; - } - - $indent = str_repeat("\t", $depth); - $output .= $indent . '<ul class="children">' . "\n"; - } - - /** - * - * @see Walker::end_lvl() - * @since 2.1.0 - * - * @param string $output - * Passed by reference. Used to append additional content. - * @param int $depth - * Depth of category. Used for tab indentation. - * @param array $args - * Will only append content if style argument value is 'list'. - */ - public function end_lvl(&$output, $depth = 0, $args = array()) - { - if ('list' != $args['style']) { - return; - } - - $indent = str_repeat("\t", $depth); - $output .= $indent . '</ul>' . "\n"; - } - - /** - * - * @see Walker::start_el() - * @since 2.1.0 - * - * @param string $output - * Passed by reference. Used to append additional content. - * @param object $object - * Category data object. - * @param int $depth - * Depth of category in reference to parents. - * @param array $args - */ - public function start_el(&$output, $object, $depth = 0, $args = array(), $current_object_id = 0) - { - extract($args); - - $cat_name = esc_attr($object->name); - $cat_name = apply_filters('list_cats', $cat_name, $object); - $link = '<div class="avhec-widget-line"><a href="' . get_category_link($object->term_id) . '" '; - if ($use_desc_for_title == 0 || empty($object->description)) { - $link .= 'title="' . sprintf(__('View all posts filed under %s'), $cat_name) . '"'; - } else { - $link .= 'title="' . esc_attr(strip_tags(apply_filters('category_description', $object->description, $object))) . '"'; - } - $link .= '>'; - $link .= $cat_name . '</a>'; - - if ((!empty($feed_image)) || (!empty($feed))) { - $link .= '<div class="avhec-widget-rss"> '; - - if (empty($feed_image)) { - $link .= '('; - } - - $link .= '<a href="' . get_category_feed_link($object->term_id, $feed_type) . '"'; - - if (empty($feed)) { - $alt = ' alt="' . sprintf(__('Feed for all posts filed under %s'), $cat_name) . '"'; - } else { - $title = ' title="' . $feed . '"'; - $alt = ' alt="' . $feed . '"'; - $name = $feed; - $link .= $title; - } - - $link .= '>'; - - if (empty($feed_image)) { - $link .= $name; - } else { - $link .= '<img src="' . $feed_image . '"' . $alt . $title . ' />'; - } - $link .= '</a>'; - if (empty($feed_image)) { - $link .= ')'; - } - $link .= '</div>'; - } - - if (isset($show_count) && $show_count) { - $link .= '<div class="avhec-widget-count"> (' . intval($object->count) . ')</div>'; - } - - if (isset($show_date) && $show_date) { - $link .= ' ' . gmdate('Y-m-d', $object->last_update_timestamp); - } - - // When on a single post get the post's category. This ensures that that category will be given the CSS style of "current category". - if (is_single()) { - $post_cats = get_the_category(); - $current_category = $post_cats[0]->term_id; - } - - if (isset($current_category) && $current_category) { - $_current_category = get_category($current_category); - } - - if ('list' == $args['style']) { - $output .= "\t" . '<li'; - $class = 'cat-item cat-item-' . $object->term_id; - if (isset($current_category) && $current_category && ($object->term_id == $current_category)) { - $class .= ' current-cat'; - } elseif (isset($_current_category) && $_current_category && ($object->term_id == $_current_category->parent)) { - $class .= ' current-cat-parent'; - } - $output .= ' class="' . $class . '"'; - $output .= '>' . $link . '</div>' . "\n"; - } else { - $output .= "\t" . $link . '</div><br />' . "\n"; - } - } - - /** - * - * @see Walker::end_el() - * @since 2.1.0 - * - * @param string $output - * Passed by reference. Used to append additional content. - * @param object $page - * Not used. - * @param int $depth - * Depth of category. Not used. - * @param array $args - * Only uses 'list' for whether should append to output. - */ - public function end_el(&$output, $object, $depth = 0, $args = array()) - { - if ('list' != $args['style']) { - return; - } - - $output .= '</li>' . "\n"; - } +class AVH_Walker_CategoryDropdown extends Walker_CategoryDropdown { + public function walk($elements, $max_depth) { + $args = array_slice(func_get_args(), 2); + $output = ''; + + if ($max_depth < - 1) { + return $output; + } + + if (empty($elements)) { + return $output; + } + + $id_field = $this->db_fields['id']; + $parent_field = $this->db_fields['parent']; + + // flat display + if (- 1 == $max_depth) { + $empty_array = array(); + foreach ($elements as $e) { + $this->display_element($e, $empty_array, 1, 0, $args, $output); + } + + return $output; + } + + /* + * 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. + */ + $top_level_elements = array(); + $children_elements = array(); + foreach ($elements as $e) { + if (0 == $e->$parent_field) { + $top_level_elements[] = $e; + } else { + $children_elements[ $e->$parent_field ][] = $e; + } + } + + /* + * when none of the elements is top level assume the first one must be root of the sub elements + */ + if (empty($top_level_elements)) { + + $first = array_slice($elements, 0, 1); + $root = $first[0]; + + $top_level_elements = array(); + $children_elements = array(); + foreach ($elements as $e) { + if ($root->$parent_field == $e->$parent_field) { + $top_level_elements[] = $e; + } else { + $children_elements[ $e->$parent_field ][] = $e; + } + } + } + + foreach ($top_level_elements as $e) { + $this->display_element($e, $children_elements, $max_depth, 0, $args, $output); + } + + /* + * if we are displaying all levels, and remaining children_elements is not empty, then we got orphans, which should be displayed regardless + */ + if ((0 == $max_depth) && count($children_elements) > 0) { + $empty_array = array(); + foreach ($children_elements as $orphans) { + foreach ($orphans as $op) { + $this->display_element($op, $empty_array, 1, 0, $args, $output); + } + } + } + + return $output; + } } diff --git a/wp-content/plugins/extended-categories-widget/3.6/class/avh-ec.widgets.php b/wp-content/plugins/extended-categories-widget/3.6/class/avh-ec.widgets.php index 02e0a0d9a0ff563f3e61e1d4f7b1ebd6773d1f9f..00aa97234e87d44b4c20ef6de4c8319c3730ca12 100644 --- a/wp-content/plugins/extended-categories-widget/3.6/class/avh-ec.widgets.php +++ b/wp-content/plugins/extended-categories-widget/3.6/class/avh-ec.widgets.php @@ -1,982 +1,1229 @@ <?php /** - * Widget Class for displaying categories. - * Extended version of the default categories. + * Class that will display the categories */ -class WP_Widget_AVH_ExtendedCategories_Normal extends WP_Widget -{ - - /** - * - * @var AVH_EC_Core - */ - public $core; - - /** - * PHP 5 Constructor - */ - public function __construct() - { - $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core'); - - // Convert the old option widget_extended_categories to widget_extended-categories - $old = get_option('widget_extended_categories'); - if (!(false === $old)) { - update_option('widget_extended-categories', $old); - delete_option('widget_extended_categories'); - } - $widget_ops = array('description' => __("An extended version of the default Categories widget.", 'avh-ec')); - WP_Widget::__construct('extended-categories', 'AVH Extended Categories', $widget_ops); - - add_action('wp_print_styles', array($this, 'actionWpPrintStyles')); - } - - public function actionWpPrintStyles() - { - if (!(false === is_active_widget(false, false, $this->id_base, true))) { - wp_register_style('avhec-widget', AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', array(), $this->core->version); - wp_enqueue_style('avhec-widget'); - } - } - - /** - * Display the widget - * - * @param unknown_type $args - * @param unknown_type $instance - */ - public function widget($args, $instance) - { - extract($args); - - $selectedonly = $instance['selectedonly']; - $c = $instance['count']; - $h = $instance['hierarchical']; - $d = $instance['depth']; - $e = $instance['hide_empty']; - $use_desc_for_title = $instance['use_desc_for_title']; - $s = isset($instance['sort_column']) ? $instance['sort_column'] : 'name'; - $o = isset($instance['sort_order']) ? $instance['sort_order'] : 'asc'; - $r = ($instance['rssfeed'] == true) ? 'RSS' : ''; - $i = isset($instance['rssimage']) ? $instance['rssimage'] : ''; - $invert = $instance['invert_included']; - - if (empty($r)) { - $i = ''; - } - - if (empty($d)) { - $d = 0; - } - - $title = apply_filters('widget_title', empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']); - $style = empty($instance['style']) ? 'list' : $instance['style']; - - $included_cats = ''; - if ($instance['post_category']) { - $post_category = unserialize($instance['post_category']); - $children = array(); - if (!$instance['selectedonly']) { - foreach ($post_category as $cat_id) { - $children = array_merge($children, get_term_children($cat_id, 'category')); - } - } - $included_cats = implode(",", array_merge($post_category, $children)); - } - - if ($invert) { - $inc_exc = 'exclude'; - } else { - $inc_exc = 'include'; - } - - $options = $this->core->getOptions(); - $show_option_none = __('Select Category', 'avh-ec'); - if ($options['general']['alternative_name_select_category']) { - $show_option_none = $options['general']['alternative_name_select_category']; - } - - $cat_args = array($inc_exc => $included_cats, 'orderby' => $s, 'order' => $o, 'show_count' => $c, 'use_desc_for_title' => $use_desc_for_title, 'hide_empty' => $e, 'hierarchical' => $h, 'depth' => $d, 'title_li' => '', 'show_option_none' => $show_option_none, 'feed' => $r, 'feed_image' => $i, 'name' => 'extended-categories-select-' . $this->number); - echo $before_widget; - echo $this->core->comment; - echo $before_title . $title . $after_title; - - if ($style == 'list') { - echo '<ul>'; - $this->core->avh_wp_list_categories($cat_args); - echo '</ul>'; - } else { - $this->core->avh_wp_dropdown_categories($cat_args); - echo '<script type=\'text/javascript\'>' . "\n"; - echo '/* <![CDATA[ */' . "\n"; - echo ' var ec_dropdown_' . $this->number . ' = document.getElementById("extended-categories-select-' . $this->number . '");' . "\n"; - echo ' function ec_onCatChange_' . $this->number . '() {' . "\n"; - echo ' if (ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value > 0) {' . "\n"; - echo ' location.href = "' . home_url() . '/?cat="+ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value;' . "\n"; - echo ' }' . "\n"; - echo ' }' . "\n"; - echo ' ec_dropdown_' . $this->number . '.onchange = ec_onCatChange_' . $this->number . ';' . "\n"; - echo '/* ]]> */' . "\n"; - echo '</script>' . "\n"; - } - echo $after_widget; - } - - /** - * When Widget Control Form Is Posted - * - * @param unknown_type $new_instance - * @param unknown_type $old_instance - * @return unknown - */ - public function update($new_instance, $old_instance) - { - // update the instance's settings - if (!isset($new_instance['submit'])) { - return false; - } - - $instance = $old_instance; - - $instance['title'] = strip_tags(stripslashes($new_instance['title'])); - $instance['selectedonly'] = isset($new_instance['selectedonly']); - $instance['count'] = isset($new_instance['count']); - $instance['hierarchical'] = isset($new_instance['hierarchical']); - $instance['hide_empty'] = isset($new_instance['hide_empty']); - $instance['use_desc_for_title'] = isset($new_instance['use_desc_for_title']); - $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column'])); - $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order'])); - $instance['style'] = strip_tags(stripslashes($new_instance['style'])); - $instance['rssfeed'] = isset($new_instance['rssfeed']); - $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage'])); - if (array_key_exists('all', $new_instance['post_category'])) { - $instance['post_category'] = false; - } else { - $instance['post_category'] = serialize($new_instance['post_category']); - } - $instance['depth'] = (int) $new_instance['depth']; - if ($instance['depth'] < 0 || 11 < $instance['depth']) { - $instance['depth'] = 0; - } - $instance['invert_included'] = isset($new_instance['invert_included']); - - return $instance; - } - - /** - * Display Widget Control Form - * - * @param unknown_type $instance - */ - public function form($instance) - { - // displays the widget admin form - $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => '', 'depth' => 0)); - - // Prepare data for display - $depth = (int) $instance['depth']; - if ($depth < 0 || 11 < $depth) { - $depth = 0; - } - $selected_cats = (avhGetArrayValue($instance, 'post_category') !== '') ? unserialize($instance['post_category']) : false; - - echo '<p>'; - avh_doWidgetFormText($this->get_field_id('title'), $this->get_field_name('title'), __('Title', 'avh-ec'), avhGetArrayValue($instance, 'title')); - echo '</p>'; - - echo '<p>'; - avh_doWidgetFormCheckbox($this->get_field_id('selectedonly'), $this->get_field_name('selectedonly'), __('Show selected categories only', 'avh-ec'), (bool) avhGetArrayValue($instance, 'selectedonly')); - - avh_doWidgetFormCheckbox($this->get_field_id('count'), $this->get_field_name('count'), __('Show post counts', 'avh-ec'), (bool) avhGetArrayValue($instance, 'count')); - - avh_doWidgetFormCheckbox($this->get_field_id('hierarchical'), $this->get_field_name('hierarchical'), __('Show hierarchy', 'avh-ec'), (bool) avhGetArrayValue($instance, 'hierarchical')); - - $options = array(0 => __('All Levels', 'avh-ec'), 1 => __('Toplevel only', 'avh-ec')); - for ($i = 2; $i <= 11; $i++) { - $options[$i] = __('Child ', 'avh-ec') . ($i - 1); - } - avh_doWidgetFormSelect($this->get_field_id('depth'), $this->get_field_name('depth'), __('How many levels to show', 'avh-ec'), $options, $depth); - unset($options); - - avh_doWidgetFormCheckbox($this->get_field_id('hide_empty'), $this->get_field_name('hide_empty'), __('Hide empty categories', 'avh-ec'), (bool) avhGetArrayValue($instance, 'hide_empty')); - - 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')); - echo '</p>'; - - echo '<p>'; - $options['ID'] = __('ID', 'avh-ec'); - $options['name'] = __('Name', 'avh-ec'); - $options['count'] = __('Count', 'avh-ec'); - $options['slug'] = __('Slug', 'avh-ec'); - $options['avhec_manualorder'] = 'AVH EC ' . __('Manual Order', 'avh-ec'); - if (is_plugin_active('my-category-order/mycategoryorder.php')) { - $options['avhec_3rdparty_mycategoryorder'] = 'My Category Order'; - } - - avh_doWidgetFormSelect($this->get_field_id('sort_column'), $this->get_field_name('sort_column'), __('Sort by', 'avh-ec'), $options, avhGetArrayValue($instance, 'sort_column')); - unset($options); - - $options['asc'] = __('Ascending', 'avh-ec'); - $options['desc'] = __('Descending', 'avh-ec'); - avh_doWidgetFormSelect($this->get_field_id('sort_order'), $this->get_field_name('sort_order'), __('Sort order', 'avh-ec'), $options, avhGetArrayValue($instance, 'sort_order')); - unset($options); - - $options['list'] = __('List', 'avh-ec'); - $options['drop'] = __('Drop down', 'avh-ec'); - avh_doWidgetFormSelect($this->get_field_id('style'), $this->get_field_name('style'), __('Display style', 'avh-ec'), $options, avhGetArrayValue($instance, 'style')); - unset($options); - echo '</p>'; - - echo '<p>'; - - avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), $this->get_field_name('rssfeed'), __('Show RSS Feed', 'avh-ec'), (bool) avhGetArrayValue($instance, 'rssfeed')); - - avh_doWidgetFormText($this->get_field_id('rssimage'), $this->get_field_name('rssimage'), __('Path (URI) to RSS image', 'avh-ec'), avhGetArrayValue($instance, 'rssimage')); - - echo '</p>'; - - echo '<p>'; - echo '<b>' . __('Select categories', 'avh-ec') . '</b><hr />'; - 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;">'; - echo '<li id="' . $this->get_field_id('category--1') . '" class="popular-category">'; - echo '<label for="' . $this->get_field_id('post_category') . '" class="selectit">'; - 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' : '') . '> '; - _e('All Categories', 'avh-ec'); - echo '</label>'; - echo '</li>'; - ob_start(); - $this->avh_wp_category_checklist($selected_cats, $this->number); - ob_end_flush(); - echo '</ul>'; - echo '</p>'; - - echo '<p>'; - 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')); - echo '</p>'; - - echo '<input type="hidden" id="' . $this->get_field_id('submit') . '" name="' . $this->get_field_name('submit') . '" value="1" />'; - } - - /** - * Creates the categories checklist - * - * @param int $post_id - * @param int $descendants_and_self - * @param array $selected_cats - * @param array $popular_cats - * @param int $number - */ - public function avh_wp_category_checklist($selected_cats, $number) - { - $walker = new AVH_Walker_Category_Checklist(); - $walker->number = $number; - $walker->input_id = $this->get_field_id('post_category'); - $walker->input_name = $this->get_field_name('post_category'); - $walker->li_id = $this->get_field_id('category--1'); - - $args = array('taxonomy' => 'category', 'descendants_and_self' => 0, 'selected_cats' => $selected_cats, 'popular_cats' => array(), 'walker' => $walker, 'checked_ontop' => true, 'popular_cats' => array()); - - if (is_array($selected_cats)) { - $args['selected_cats'] = $selected_cats; - } else { - $args['selected_cats'] = array(); - } - - $categories = $this->core->getCategories(); - $_categories_id = $this->core->getCategoriesId($categories); - - // 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) - $checked_categories = array(); - foreach ($args['selected_cats'] as $key => $value) { - if (isset($_categories_id[$key])) { - $category_key = $_categories_id[$key]; - $checked_categories[] = $categories[$category_key]; - unset($categories[$category_key]); - } - } - - // Put checked cats on top - echo $walker->walk($checked_categories, 0, $args); - // Then the rest of them - echo $walker->walk($categories, 0, $args); - } +class AVH_Walker_Category_Checklist extends Walker { + public $db_fields = array('parent' => 'parent', 'id' => 'term_id'); + public $input_id; // TODO: decouple this + public $input_name; + public $li_id; + public $number; + public $tree_type = 'category'; + + public function end_el(&$output, $object, $depth = 0, $args = array()) { + $output .= "</li>\n"; + } + + public function end_lvl(&$output, $depth = 0, $args = array()) { + $indent = str_repeat("\t", $depth); + $output .= $indent . '</ul>' . "\n"; + } + + public function start_el(&$output, $object, $depth = 0, $args = array(), $current_object_id = 0) { + extract($args); + if ( ! isset($selected_cats)) { + $selected_cats = array(); + } + $input_id = $this->input_id . '-' . $object->term_id; + $output .= "\n" . '<li id="' . $this->li_id . '">'; + $output .= '<label for="' . $input_id . '" class="selectit">'; + $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>'; + } + + public function start_lvl(&$output, $depth = 0, $args = array()) { + $indent = str_repeat("\t", $depth); + $output .= $indent . '<ul class="children">' . "\n"; + } + + /** + * Display array of elements hierarchically. + * It is a generic function which does not assume any existing order of + * elements. max_depth = -1 means flatly display every element. max_depth = + * 0 means display all levels. max_depth > 0 specifies the number of + * display levels. + * + * @since 2.1.0 + * + * @param array $elements + * @param int $max_depth + * @param array $args ; + * + * @return string + */ + public function walk($elements, $max_depth) { + $args = array_slice(func_get_args(), 2); + $output = ''; + + if ($max_depth < - 1) { + return $output; + } + + if (empty($elements)) { // nothing to walk + return $output; + } + + $id_field = $this->db_fields['id']; + $parent_field = $this->db_fields['parent']; + + // flat display + if (- 1 == $max_depth) { + $empty_array = array(); + foreach ($elements as $e) { + $this->display_element($e, $empty_array, 1, 0, $args, $output); + } + + return $output; + } + + /* + * 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. + */ + $top_level_elements = array(); + $children_elements = array(); + foreach ($elements as $e) { + if (0 == $e->$parent_field) { + $top_level_elements[] = $e; + } else { + $children_elements[ $e->$parent_field ][] = $e; + } + } + + /* + * when none of the elements is top level assume the first one must be root of the sub elements + */ + if (empty($top_level_elements)) { + + $first = array_slice($elements, 0, 1); + $root = $first[0]; + + $top_level_elements = array(); + $children_elements = array(); + foreach ($elements as $e) { + if ($root->$parent_field == $e->$parent_field) { + $top_level_elements[] = $e; + } else { + $children_elements[ $e->$parent_field ][] = $e; + } + } + } + + foreach ($top_level_elements as $e) { + $this->display_element($e, $children_elements, $max_depth, 0, $args, $output); + } + + /* + * if we are displaying all levels, and remaining children_elements is not empty, then we got orphans, which should be displayed regardless + */ + if (($max_depth == 0) && count($children_elements) > 0) { + $empty_array = array(); + foreach ($children_elements as $orphans) { + foreach ($orphans as $op) { + $this->display_element($op, $empty_array, 1, 0, $args, $output); + } + } + } + + return $output; + } } /** - * Widget Class for displaying the top categories + * Widget Class for displaying the grouped categories */ -class WP_Widget_AVH_ExtendedCategories_Top extends WP_Widget -{ - - /** - * - * @var AVH_EC_Core - */ - public $core; - - /** - * PHP 5 Constructor - */ - public function __construct() - { - $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core'); - - $widget_ops = array('description' => __("Shows the top categories.", 'avh-ec')); - WP_Widget::__construct(false, 'AVH Extended Categories: ' . __('Top Categories'), $widget_ops); - add_action('wp_print_styles', array($this, 'actionWpPrintStyles')); - } - - public function actionWpPrintStyles() - { - if (!(false === is_active_widget(false, false, $this->id_base, true))) { - wp_register_style('avhec-widget', AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', array(), $this->core->version); - wp_enqueue_style('avhec-widget'); - } - } - - /** - * Echo the widget content. - * - * Subclasses should over-ride this function to generate their widget code. - * - * @param array $args - * Display arguments including before_title, after_title, before_widget, and after_widget. - * @param array $instance - * The settings for the particular instance of the widget - */ - public function widget($args, $instance) - { - extract($args); - - $title = apply_filters('widget_title', empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']); - $style = empty($instance['style']) ? 'list' : $instance['style']; - if (!$a = (int) $instance['amount']) { - $a = 5; - } elseif ($a < 1) { - $a = 1; - } - $c = $instance['count']; - $use_desc_for_title = $instance['use_desc_for_title']; - $s = isset($instance['sort_column']) ? $instance['sort_column'] : 'name'; - $o = isset($instance['sort_order']) ? $instance['sort_order'] : 'asc'; - $r = ($instance['rssfeed'] === true) ? 'RSS' : ''; - $i = isset($instance['rssimage']) ? $instance['rssimage'] : ''; - if (empty($r)) { - $i = ''; - } - if (!empty($i)) { - if (!file_exists(ABSPATH . '/' . $i)) { - $i = ''; - } - } - - $options = $this->core->getOptions(); - $show_option_none = __('Select Category', 'avh-ec'); - if ($options['general']['alternative_name_select_category']) { - $show_option_none = $options['general']['alternative_name_select_category']; - } - - $top_cats = get_terms('category', array('fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => $a, 'hierarchical' => false)); - $included_cats = implode(",", $top_cats); - - $cat_args = array('include' => $included_cats, 'orderby' => $s, 'order' => $o, 'show_count' => $c, 'use_desc_for_title' => $use_desc_for_title, 'hide_empty' => false, 'hierarchical' => false, 'depth' => -1, 'title_li' => '', 'show_option_none' => $show_option_none, 'feed' => $r, 'feed_image' => $i, 'name' => 'extended-categories-top-select-' . $this->number); - echo $before_widget; - echo $this->core->comment; - echo $before_title . $title . $after_title; - echo '<ul>'; - - if ($style == 'list') { - wp_list_categories($cat_args); - } else { - wp_dropdown_categories($cat_args); - echo '<script type=\'text/javascript\'>' . "\n"; - echo '/* <![CDATA[ */' . "\n"; - echo ' var ec_dropdown_top_' . $this->number . ' = document.getElementById("extended-categories-top-select-' . $this->number . '");' . "\n"; - echo ' function ec_top_onCatChange_' . $this->number . '() {' . "\n"; - echo ' if (ec_dropdown_top_' . $this->number . '.options[ec_dropdown_top_' . $this->number . '.selectedIndex].value > 0) {' . "\n"; - echo ' location.href = "' . get_option('home') . '/?cat="+ec_dropdown_top_' . $this->number . '.options[ec_dropdown_top_' . $this->number . '.selectedIndex].value;' . "\n"; - echo ' }' . "\n"; - echo ' }' . "\n"; - echo ' ec_dropdown_top_' . $this->number . '.onchange = ec_top_onCatChange_' . $this->number . ';' . "\n"; - echo '/* ]]> */' . "\n"; - echo '</script>' . "\n"; - } - echo '</ul>'; - echo $after_widget; - } - - /** - * Update a particular instance. - * - * This function should check that $new_instance is set correctly. - * The newly calculated value of $instance should be returned. - * If "false" is returned, the instance won't be saved/updated. - * - * @param array $new_instance - * New settings for this instance as input by the user via form() - * @param array $old_instance - * Old settings for this instance - * @return array Settings to save or bool false to cancel saving - */ - public function update($new_instance, $old_instance) - { - // update the instance's settings - if (!isset($new_instance['submit'])) { - return false; - } - - $instance = $old_instance; - - $instance['title'] = strip_tags(stripslashes($new_instance['title'])); - $instance['amount'] = (int) $new_instance['amount']; - $instance['count'] = isset($new_instance['count']); - $instance['use_desc_for_title'] = isset($new_instance['use_desc_for_title']); - $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column'])); - $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order'])); - $instance['style'] = strip_tags(stripslashes($new_instance['style'])); - $instance['rssfeed'] = isset($new_instance['rssfeed']); - $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage'])); - - return $instance; - } - - /** - * Echo the settings update form - * - * @param array $instance - * Current settings - */ - public function form($instance) - { - // displays the widget admin form - $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => '', 'amount' => '5')); - - $amount = (int) avhGetArrayValue($instance, 'amount'); - if ($amount < 1) { - $amount = 1; - } - echo '<p>'; - avh_doWidgetFormText($this->get_field_id('title'), $this->get_field_name('title'), __('Title', 'avh-ec'), avhGetArrayValue($instance, 'title')); - echo '</p>'; - - echo '<p>'; - avh_doWidgetFormText($this->get_field_id('amount'), $this->get_field_name('amount'), __('How many categories to show', 'avh-ec'), $amount); - echo '</p>'; - - echo '<p>'; - avh_doWidgetFormCheckbox($this->get_field_id('count'), $this->get_field_name('count'), __('Show post counts', 'avh-ec'), (bool) avhGetArrayValue($instance, 'count')); - echo '<br />'; - - 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')); - echo '</p>'; - - echo '<p>'; - $options['ID'] = __('ID', 'avh-ec'); - $options['name'] = __('Name', 'avh-ec'); - $options['count'] = __('Count', 'avh-ec'); - $options['slug'] = __('Slug', 'avh-ec'); - avh_doWidgetFormSelect($this->get_field_id('sort_column'), $this->get_field_name('sort_column'), __('Sort by', 'avh-ec'), $options, avhGetArrayValue($instance, 'sort_column')); - unset($options); - - $options['asc'] = __('Ascending', 'avh-ec'); - $options['desc'] = __('Descending', 'avh-ec'); - avh_doWidgetFormSelect($this->get_field_id('sort_order'), $this->get_field_name('sort_order'), __('Sort order', 'avh-ec'), $options, avhGetArrayValue($instance, 'sort_order')); - unset($options); - - $options['list'] = __('List', 'avh-ec'); - $options['drop'] = __('Drop down', 'avh-ec'); - avh_doWidgetFormSelect($this->get_field_id('style'), $this->get_field_name('style'), __('Display style', 'avh-ec'), $options, avhGetArrayValue($instance, 'style')); - unset($options); - echo '</p>'; - - echo '<p>'; - - avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), $this->get_field_name('rssfeed'), __('Show RSS Feed', 'avh-ec'), (bool) avhGetArrayValue($instance, 'rssfeed')); - - avh_doWidgetFormText($this->get_field_id('rssimage'), $this->get_field_name('rssimage'), __('Path (URI) to RSS image', 'avh-ec'), avhGetArrayValue($instance, 'rssimage')); - - echo '</p>'; - - echo '<input type="hidden" id="' . $this->get_field_id('submit') . '" name="' . $this->get_field_name('submit') . '" value="1" />'; - } +class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget { + /** + * @var AVH_EC_Category_Group + */ + public $catgrp; + /** + * @var AVH_EC_Core + */ + public $core; + + /** + * PHP 5 Constructor + */ + public function __construct() { + $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core'); + $this->catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); + + $widget_ops = array('description' => __("Shows grouped categories.", 'avh-ec')); + WP_Widget::__construct(false, 'AVH Extended Categories: ' . __('Category Group'), $widget_ops); + add_action('wp_print_styles', array($this, 'actionWpPrintStyles')); + } + + public function actionWpPrintStyles() { + if ( ! (false === is_active_widget(false, false, $this->id_base, true))) { + wp_register_style('avhec-widget', + AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', + array(), + $this->core->version); + wp_enqueue_style('avhec-widget'); + } + } + + public function avh_wp_group_category_checklist($selected_cats, $number) { + $walker = new AVH_Walker_Category_Checklist(); + $walker->number = $number; + $walker->input_id = $this->get_field_id('post_group_category'); + $walker->input_name = $this->get_field_name('post_group_category'); + $walker->li_id = $this->get_field_id('group_category--1'); + + $args = array( + 'taxonomy' => 'avhec_catgroup', + 'descendants_and_self' => 0, + 'selected_cats' => array(), + 'popular_cats' => array(), + 'walker' => $walker, + 'checked_ontop' => true + ); + + if (is_array($selected_cats)) { + $args['selected_cats'] = $selected_cats; + } else { + $args['selected_cats'] = array(); + } + + $categories = (array) get_terms($args['taxonomy'], array('get' => 'all')); + + // 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) + $checked_categories = array(); + $keys = array_keys($categories); + + foreach ($keys as $k) { + if (in_array($categories[ $k ]->term_id, $args['selected_cats'])) { + $checked_categories[] = $categories[ $k ]; + unset($categories[ $k ]); + } + } + + // Put checked cats on top + echo $walker->walk($checked_categories, 0, $args); + // Then the rest of them + echo $walker->walk($categories, 0, $args); + } + + /** + * Display Widget Control Form + * + * @param unknown_type $instance + */ + public function form($instance) { + // displays the widget admin form + $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => '')); + + $selected_cats = (avhGetArrayValue($instance, 'post_group_category') !== + '') ? unserialize($instance['post_group_category']) : false; + ob_start(); + echo '<p>'; + avh_doWidgetFormText($this->get_field_id('title'), + $this->get_field_name('title'), + __('Title', 'avh-ec'), + $instance['title']); + echo '</p>'; + + echo '<p>'; + + avh_doWidgetFormCheckbox($this->get_field_id('count'), + $this->get_field_name('count'), + __('Show post counts', 'avh-ec'), + (bool) avhGetArrayValue($instance, 'count')); + + avh_doWidgetFormCheckbox($this->get_field_id('hierarchical'), + $this->get_field_name('hierarchical'), + __('Show hierarchy', 'avh-ec'), + (bool) avhGetArrayValue($instance, 'hierarchical')); + + avh_doWidgetFormCheckbox($this->get_field_id('hide_empty'), + $this->get_field_name('hide_empty'), + __('Hide empty categories', 'avh-ec'), + (bool) avhGetArrayValue($instance, 'hide_empty')); + + 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')); + echo '</p>'; + + echo '<p>'; + $options['ID'] = __('ID', 'avh-ec'); + $options['name'] = __('Name', 'avh-ec'); + $options['count'] = __('Count', 'avh-ec'); + $options['slug'] = __('Slug', 'avh-ec'); + avh_doWidgetFormSelect($this->get_field_id('sort_column'), + $this->get_field_name('sort_column'), + __('Sort by', 'avh-ec'), + $options, + avhGetArrayValue($instance, 'sort_column')); + unset($options); + + $options['asc'] = __('Ascending', 'avh-ec'); + $options['desc'] = __('Descending', 'avh-ec'); + avh_doWidgetFormSelect($this->get_field_id('sort_order'), + $this->get_field_name('sort_order'), + __('Sort order', 'avh-ec'), + $options, + avhGetArrayValue($instance, 'sort_order')); + unset($options); + + $options['list'] = __('List', 'avh-ec'); + $options['drop'] = __('Drop down', 'avh-ec'); + avh_doWidgetFormSelect($this->get_field_id('style'), + $this->get_field_name('style'), + __('Display style', 'avh-ec'), + $options, + avhGetArrayValue($instance, 'style')); + unset($options); + echo '</p>'; + + echo '<p>'; + + avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), + $this->get_field_name('rssfeed'), + __('Show RSS Feed', 'avh-ec'), + (bool) avhGetArrayValue($instance, 'rssfeed')); + + avh_doWidgetFormText($this->get_field_id('rssimage'), + $this->get_field_name('rssimage'), + __('Path (URI) to RSS image', 'avh-ec'), + avhGetArrayValue($instance, 'rssimage')); + echo '</p>'; + + echo '<p>'; + echo '<b>' . __('Select Groups', 'avh-ec') . '</b><hr />'; + 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;">'; + echo '<li id="' . $this->get_field_id('group_category--1') . '" class="popular-group_category">'; + echo '<label for="' . $this->get_field_id('group_post_category') . '" class="selectit">'; + 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' : '') . + '> '; + _e('Any Group', 'avh-ec'); + echo '</label>'; + echo '</li>'; + + $this->avh_wp_group_category_checklist($selected_cats, $this->number); + + echo '</ul>'; + echo '</p>'; + + echo '<input type="hidden" id="' . + $this->get_field_id('submit') . + '" name="' . + $this->get_field_name('submit') . + '" value="1" />'; + ob_end_flush(); + } + + public function getWidgetDoneCatGroup($id) { + $catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); + if (is_array($catgrp->widget_done_catgroup) && array_key_exists($id, $catgrp->widget_done_catgroup)) { + return true; + } + $catgrp->widget_done_catgroup[ $id ] = true; + + return false; + } + + /** + * When Widget Control Form Is Posted + * + * @param unknown_type $new_instance + * @param unknown_type $old_instance + * + * @return unknown + */ + public function update($new_instance, $old_instance) { + // update the instance's settings + if ( ! isset($new_instance['submit'])) { + return false; + } + + $instance = $old_instance; + + $instance['title'] = strip_tags(stripslashes($new_instance['title'])); + $instance['count'] = isset($new_instance['count']); + $instance['hierarchical'] = isset($new_instance['hierarchical']); + $instance['hide_empty'] = isset($new_instance['hide_empty']); + $instance['use_desc_for_title'] = isset($new_instance['use_desc_for_title']); + $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column'])); + $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order'])); + $instance['style'] = strip_tags(stripslashes($new_instance['style'])); + $instance['rssfeed'] = isset($new_instance['rssfeed']); + $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage'])); + if (array_key_exists('all', $new_instance['post_group_category'])) { + $instance['post_group_category'] = false; + } else { + $instance['post_group_category'] = serialize($new_instance['post_group_category']); + } + + return $instance; + } + + /** + * Display the widget + * + * @param unknown_type $args + * @param unknown_type $instance + */ + public function widget($args, $instance) { + global $post, $wp_query; + + $catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); + $options = $this->core->getOptions(); + + $row = array(); + + if (is_home()) { + $special_page = 'home_group'; + } elseif (is_category()) { + $special_page = 'category_group'; + } elseif (is_day()) { + $special_page = 'day_group'; + } elseif (is_month()) { + $special_page = 'month_group'; + } elseif (is_year()) { + $special_page = 'year_group'; + } elseif (is_author()) { + $special_page = 'author_group'; + } elseif (is_search()) { + $special_page = 'search_group'; + } else { + $special_page = 'none'; + } + + $toDisplay = false; + if ('none' == $special_page) { + $terms = wp_get_object_terms($post->ID, $catgrp->taxonomy_name); + if ( ! empty($terms)) { + $selected_catgroups = unserialize($instance['post_group_category']); + foreach ($terms as $key => $value) { + if ($selected_catgroups === false || array_key_exists($value->term_id, $selected_catgroups)) { + if ( ! ($this->getWidgetDoneCatGroup($value->term_id))) { + $row = $value; + $group_found = true; + break; + } + } + } + } else { + $options = $this->core->options; + $no_cat_group = $options['cat_group']['no_group']; + $row = get_term_by('id', $no_cat_group, $catgrp->taxonomy_name); + $group_found = true; + } + } else { + if ('category_group' == $special_page) { + $tax_meta = get_option($this->core->db_options_tax_meta); + $term = $wp_query->get_queried_object(); + if (isset($tax_meta[ $term->taxonomy ][ $term->term_id ]['category_group_term_id'])) { + $sp_category_group_id = $tax_meta[ $term->taxonomy ][ $term->term_id ]['category_group_term_id']; + } else { + $sp_category_group = $this->catgrp->getGroupByCategoryID($term->term_id); + $sp_category_group_id = $sp_category_group->term_id; + } + } else { + $sp_category_group_id = $options['sp_cat_group'][ $special_page ]; + } + $row = get_term_by('id', + $sp_category_group_id, + $catgrp->taxonomy_name); // Returns false when non-existance. (empty(false)=true) + $group_found = true; + } + + if ($group_found) { + $toDisplay = true; + $category_group_id_none = $this->catgrp->getTermIDBy('slug', 'none'); + $selected_catgroups = unserialize($instance['post_group_category']); + + if ($category_group_id_none == $row->term_id) { + $toDisplay = false; + } elseif ( ! (false == $selected_catgroups || array_key_exists($row->term_id, $selected_catgroups))) { + $toDisplay = false; + } elseif ($special_page != 'none' && $this->getWidgetDoneCatGroup($sp_category_group_id)) { + $toDisplay = false; + } + } + + if ($toDisplay) { + extract($args); + + $c = $instance['count']; + $e = $instance['hide_empty']; + $h = $instance['hierarchical']; + $use_desc_for_title = $instance['use_desc_for_title']; + $s = isset($instance['sort_column']) ? $instance['sort_column'] : 'name'; + $o = isset($instance['sort_order']) ? $instance['sort_order'] : 'asc'; + $r = $instance['rssfeed'] ? 'RSS' : ''; + $i = $instance['rssimage'] ? $instance['rssimage'] : ''; + + if (empty($r)) { + $i = ''; + } + + $style = empty($instance['style']) ? 'list' : $instance['style']; + $group_id = $row->term_id; + $cats = $catgrp->getCategoriesFromGroup($group_id); + if (empty($instance['title'])) { + $title = $catgrp->getWidgetTitleForGroup($group_id); + if ( ! $title) { + $title = __('Categories', 'avh-ec'); + } + } else { + $title = $instance['title']; + } + $title = apply_filters('widget_title', $title); + + $included_cats = implode(',', $cats); + + $show_option_none = __('Select Category', 'avh-ec'); + if ($options['general']['alternative_name_select_category']) { + $show_option_none = $options['general']['alternative_name_select_category']; + } + + $cat_args = array( + 'include' => $included_cats, + 'orderby' => $s, + 'order' => $o, + 'show_count' => $c, + 'use_desc_for_title' => $use_desc_for_title, + 'hide_empty' => $e, + 'hierarchical' => $h, + 'title_li' => '', + 'show_option_none' => $show_option_none, + 'feed' => $r, + 'feed_image' => $i, + 'name' => 'extended-categories-select-group-' . $this->number + ); + echo $before_widget; + echo $this->core->comment; + echo $before_title . $title . $after_title; + + if ($style == 'list') { + echo '<ul>'; + $this->core->avh_wp_list_categories($cat_args, true); + echo '</ul>'; + } else { + $this->core->avh_wp_dropdown_categories($cat_args, true); + echo '<script type=\'text/javascript\'>' . "\n"; + echo '/* <![CDATA[ */' . "\n"; + echo ' var ec_dropdown_' . + $this->number . + ' = document.getElementById("extended-categories-select-group-' . + $this->number . + '");' . + "\n"; + echo ' function ec_onCatChange_' . $this->number . '() {' . "\n"; + echo ' if (ec_dropdown_' . + $this->number . + '.options[ec_dropdown_' . + $this->number . + '.selectedIndex].value > 0) {' . + "\n"; + echo ' location.href = "' . + get_option('home') . + '/?cat="+ec_dropdown_' . + $this->number . + '.options[ec_dropdown_' . + $this->number . + '.selectedIndex].value;' . + "\n"; + echo ' }' . "\n"; + echo ' }' . "\n"; + echo ' ec_dropdown_' . + $this->number . + '.onchange = ec_onCatChange_' . + $this->number . + ';' . + "\n"; + echo '/* ]]> */' . "\n"; + echo '</script>' . "\n"; + } + echo $after_widget; + } + } } /** - * Widget Class for displaying the grouped categories + * Widget Class for displaying categories. + * Extended version of the default categories. */ -class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget -{ - - /** - * - * @var AVH_EC_Core - */ - public $core; - - /** - * - * @var AVH_EC_Category_Group - */ - public $catgrp; - - /** - * PHP 5 Constructor - */ - public function __construct() - { - $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core'); - $this->catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); - - $widget_ops = array('description' => __("Shows grouped categories.", 'avh-ec')); - WP_Widget::__construct(false, 'AVH Extended Categories: ' . __('Category Group'), $widget_ops); - add_action('wp_print_styles', array($this, 'actionWpPrintStyles')); - } - - public function actionWpPrintStyles() - { - if (!(false === is_active_widget(false, false, $this->id_base, true))) { - wp_register_style('avhec-widget', AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', array(), $this->core->version); - wp_enqueue_style('avhec-widget'); - } - } - - /** - * Display the widget - * - * @param unknown_type $args - * @param unknown_type $instance - */ - public function widget($args, $instance) - { - global $post, $wp_query; - - $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); - $options = $this->core->getOptions(); - - $row = array(); - - if (is_home()) { - $special_page = 'home_group'; - } elseif (is_category()) { - $special_page = 'category_group'; - } elseif (is_day()) { - $special_page = 'day_group'; - } elseif (is_month()) { - $special_page = 'month_group'; - } elseif (is_year()) { - $special_page = 'year_group'; - } elseif (is_author()) { - $special_page = 'author_group'; - } elseif (is_search()) { - $special_page = 'search_group'; - } else { - $special_page = 'none'; - } - - $toDisplay = false; - if ('none' == $special_page) { - $terms = wp_get_object_terms($post->ID, $catgrp->taxonomy_name); - if (!empty($terms)) { - $selected_catgroups = unserialize($instance['post_group_category']); - foreach ($terms as $key => $value) { - if ($selected_catgroups === false || array_key_exists($value->term_id, $selected_catgroups)) { - if (!($this->getWidgetDoneCatGroup($value->term_id))) { - $row = $value; - $group_found = true; - break; - } - } - } - } else { - $options = $this->core->options; - $no_cat_group = $options['cat_group']['no_group']; - $row = get_term_by('id', $no_cat_group, $catgrp->taxonomy_name); - $group_found = true; - } - } else { - if ('category_group' == $special_page) { - $tax_meta = get_option($this->core->db_options_tax_meta); - $term = $wp_query->get_queried_object(); - if (isset($tax_meta[$term->taxonomy][$term->term_id]['category_group_term_id'])) { - $sp_category_group_id = $tax_meta[$term->taxonomy][$term->term_id]['category_group_term_id']; - } else { - $sp_category_group = $this->catgrp->getGroupByCategoryID($term->term_id); - $sp_category_group_id = $sp_category_group->term_id; - } - } else { - $sp_category_group_id = $options['sp_cat_group'][$special_page]; - } - $row = get_term_by('id', $sp_category_group_id, $catgrp->taxonomy_name); // Returns false when non-existance. (empty(false)=true) - $group_found = true; - } - - if ($group_found) { - $toDisplay = true; - $category_group_id_none = $this->catgrp->getTermIDBy('slug', 'none'); - $selected_catgroups = unserialize($instance['post_group_category']); - - if ($category_group_id_none == $row->term_id) { - $toDisplay = false; - } elseif (!(false == $selected_catgroups || array_key_exists($row->term_id, $selected_catgroups))) { - $toDisplay = false; - } elseif ($special_page != 'none' && $this->getWidgetDoneCatGroup($sp_category_group_id)) { - $toDisplay = false; - } - } - - if ($toDisplay) { - extract($args); - - $c = $instance['count']; - $e = $instance['hide_empty']; - $h = $instance['hierarchical']; - $use_desc_for_title = $instance['use_desc_for_title']; - $s = isset($instance['sort_column']) ? $instance['sort_column'] : 'name'; - $o = isset($instance['sort_order']) ? $instance['sort_order'] : 'asc'; - $r = $instance['rssfeed'] ? 'RSS' : ''; - $i = $instance['rssimage'] ? $instance['rssimage'] : ''; - - if (empty($r)) { - $i = ''; - } - - $style = empty($instance['style']) ? 'list' : $instance['style']; - $group_id = $row->term_id; - $cats = $catgrp->getCategoriesFromGroup($group_id); - if (empty($instance['title'])) { - $title = $catgrp->getWidgetTitleForGroup($group_id); - if (!$title) { - $title = __('Categories', 'avh-ec'); - } - } else { - $title = $instance['title']; - } - $title = apply_filters('widget_title', $title); - - $included_cats = implode(',', $cats); - - $show_option_none = __('Select Category', 'avh-ec'); - if ($options['general']['alternative_name_select_category']) { - $show_option_none = $options['general']['alternative_name_select_category']; - } - - $cat_args = array('include' => $included_cats, 'orderby' => $s, 'order' => $o, 'show_count' => $c, 'use_desc_for_title' => $use_desc_for_title, 'hide_empty' => $e, 'hierarchical' => $h, 'title_li' => '', 'show_option_none' => $show_option_none, 'feed' => $r, 'feed_image' => $i, 'name' => 'extended-categories-select-group-' . $this->number); - echo $before_widget; - echo $this->core->comment; - echo $before_title . $title . $after_title; - - if ($style == 'list') { - echo '<ul>'; - $this->core->avh_wp_list_categories($cat_args, true); - echo '</ul>'; - } else { - $this->core->avh_wp_dropdown_categories($cat_args, true); - echo '<script type=\'text/javascript\'>' . "\n"; - echo '/* <![CDATA[ */' . "\n"; - echo ' var ec_dropdown_' . $this->number . ' = document.getElementById("extended-categories-select-group-' . $this->number . '");' . "\n"; - echo ' function ec_onCatChange_' . $this->number . '() {' . "\n"; - echo ' if (ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value > 0) {' . "\n"; - echo ' location.href = "' . get_option('home') . '/?cat="+ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value;' . "\n"; - echo ' }' . "\n"; - echo ' }' . "\n"; - echo ' ec_dropdown_' . $this->number . '.onchange = ec_onCatChange_' . $this->number . ';' . "\n"; - echo '/* ]]> */' . "\n"; - echo '</script>' . "\n"; - } - echo $after_widget; - } - } - - /** - * When Widget Control Form Is Posted - * - * @param unknown_type $new_instance - * @param unknown_type $old_instance - * @return unknown - */ - public function update($new_instance, $old_instance) - { - // update the instance's settings - if (!isset($new_instance['submit'])) { - return false; - } - - $instance = $old_instance; - - $instance['title'] = strip_tags(stripslashes($new_instance['title'])); - $instance['count'] = isset($new_instance['count']); - $instance['hierarchical'] = isset($new_instance['hierarchical']); - $instance['hide_empty'] = isset($new_instance['hide_empty']); - $instance['use_desc_for_title'] = isset($new_instance['use_desc_for_title']); - $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column'])); - $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order'])); - $instance['style'] = strip_tags(stripslashes($new_instance['style'])); - $instance['rssfeed'] = isset($new_instance['rssfeed']); - $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage'])); - if (array_key_exists('all', $new_instance['post_group_category'])) { - $instance['post_group_category'] = false; - } else { - $instance['post_group_category'] = serialize($new_instance['post_group_category']); - } - - return $instance; - } - - /** - * Display Widget Control Form - * - * @param unknown_type $instance - */ - public function form($instance) - { - // displays the widget admin form - $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => '')); - - $selected_cats = (avhGetArrayValue($instance, 'post_group_category') !== '') ? unserialize($instance['post_group_category']) : false; - ob_start(); - echo '<p>'; - avh_doWidgetFormText($this->get_field_id('title'), $this->get_field_name('title'), __('Title', 'avh-ec'), $instance['title']); - echo '</p>'; - - echo '<p>'; - - avh_doWidgetFormCheckbox($this->get_field_id('count'), $this->get_field_name('count'), __('Show post counts', 'avh-ec'), (bool) avhGetArrayValue($instance, 'count')); - - avh_doWidgetFormCheckbox($this->get_field_id('hierarchical'), $this->get_field_name('hierarchical'), __('Show hierarchy', 'avh-ec'), (bool) avhGetArrayValue($instance, 'hierarchical')); - - avh_doWidgetFormCheckbox($this->get_field_id('hide_empty'), $this->get_field_name('hide_empty'), __('Hide empty categories', 'avh-ec'), (bool) avhGetArrayValue($instance, 'hide_empty')); - - 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')); - echo '</p>'; - - echo '<p>'; - $options['ID'] = __('ID', 'avh-ec'); - $options['name'] = __('Name', 'avh-ec'); - $options['count'] = __('Count', 'avh-ec'); - $options['slug'] = __('Slug', 'avh-ec'); - avh_doWidgetFormSelect($this->get_field_id('sort_column'), $this->get_field_name('sort_column'), __('Sort by', 'avh-ec'), $options, avhGetArrayValue($instance, 'sort_column')); - unset($options); - - $options['asc'] = __('Ascending', 'avh-ec'); - $options['desc'] = __('Descending', 'avh-ec'); - avh_doWidgetFormSelect($this->get_field_id('sort_order'), $this->get_field_name('sort_order'), __('Sort order', 'avh-ec'), $options, avhGetArrayValue($instance, 'sort_order')); - unset($options); - - $options['list'] = __('List', 'avh-ec'); - $options['drop'] = __('Drop down', 'avh-ec'); - avh_doWidgetFormSelect($this->get_field_id('style'), $this->get_field_name('style'), __('Display style', 'avh-ec'), $options, avhGetArrayValue($instance, 'style')); - unset($options); - echo '</p>'; - - echo '<p>'; - - avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), $this->get_field_name('rssfeed'), __('Show RSS Feed', 'avh-ec'), (bool) avhGetArrayValue($instance, 'rssfeed')); - - avh_doWidgetFormText($this->get_field_id('rssimage'), $this->get_field_name('rssimage'), __('Path (URI) to RSS image', 'avh-ec'), avhGetArrayValue($instance, 'rssimage')); - echo '</p>'; - - echo '<p>'; - echo '<b>' . __('Select Groups', 'avh-ec') . '</b><hr />'; - 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;">'; - echo '<li id="' . $this->get_field_id('group_category--1') . '" class="popular-group_category">'; - echo '<label for="' . $this->get_field_id('group_post_category') . '" class="selectit">'; - 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' : '') . '> '; - _e('Any Group', 'avh-ec'); - echo '</label>'; - echo '</li>'; - - $this->avh_wp_group_category_checklist($selected_cats, $this->number); - - echo '</ul>'; - echo '</p>'; - - echo '<input type="hidden" id="' . $this->get_field_id('submit') . '" name="' . $this->get_field_name('submit') . '" value="1" />'; - ob_end_flush(); - } - - public function avh_wp_group_category_checklist($selected_cats, $number) - { - $walker = new AVH_Walker_Category_Checklist(); - $walker->number = $number; - $walker->input_id = $this->get_field_id('post_group_category'); - $walker->input_name = $this->get_field_name('post_group_category'); - $walker->li_id = $this->get_field_id('group_category--1'); - - $args = array('taxonomy' => 'avhec_catgroup', 'descendants_and_self' => 0, 'selected_cats' => array(), 'popular_cats' => array(), 'walker' => $walker, 'checked_ontop' => true); - - if (is_array($selected_cats)) { - $args['selected_cats'] = $selected_cats; - } else { - $args['selected_cats'] = array(); - } - - $categories = (array) get_terms($args['taxonomy'], array('get' => 'all')); - - // 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) - $checked_categories = array(); - $keys = array_keys($categories); - - foreach ($keys as $k) { - if (in_array($categories[$k]->term_id, $args['selected_cats'])) { - $checked_categories[] = $categories[$k]; - unset($categories[$k]); - } - } - - // Put checked cats on top - echo $walker->walk($checked_categories, 0, $args); - // Then the rest of them - echo $walker->walk($categories, 0, $args); - } - - public function getWidgetDoneCatGroup($id) - { - $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); - if (is_array($catgrp->widget_done_catgroup) && array_key_exists($id, $catgrp->widget_done_catgroup)) { - return true; - } - $catgrp->widget_done_catgroup[$id] = true; - - return false; - } +class WP_Widget_AVH_ExtendedCategories_Normal extends WP_Widget { + /** + * @var AVH_EC_Core + */ + public $core; + + /** + * PHP 5 Constructor + */ + public function __construct() { + $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core'); + + // Convert the old option widget_extended_categories to widget_extended-categories + $old = get_option('widget_extended_categories'); + if ( ! (false === $old)) { + update_option('widget_extended-categories', $old); + delete_option('widget_extended_categories'); + } + $widget_ops = array('description' => __("An extended version of the default Categories widget.", 'avh-ec')); + WP_Widget::__construct('extended-categories', 'AVH Extended Categories', $widget_ops); + + add_action('wp_print_styles', array($this, 'actionWpPrintStyles')); + } + + public function actionWpPrintStyles() { + if ( ! (false === is_active_widget(false, false, $this->id_base, true))) { + wp_register_style('avhec-widget', + AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', + array(), + $this->core->version); + wp_enqueue_style('avhec-widget'); + } + } + + /** + * Creates the categories checklist + * + * @param int $post_id + * @param int $descendants_and_self + * @param array $selected_cats + * @param array $popular_cats + * @param int $number + */ + public function avh_wp_category_checklist($selected_cats, $number) { + $walker = new AVH_Walker_Category_Checklist(); + $walker->number = $number; + $walker->input_id = $this->get_field_id('post_category'); + $walker->input_name = $this->get_field_name('post_category'); + $walker->li_id = $this->get_field_id('category--1'); + + $args = array( + 'taxonomy' => 'category', + 'descendants_and_self' => 0, + 'selected_cats' => $selected_cats, + 'popular_cats' => array(), + 'walker' => $walker, + 'checked_ontop' => true, + 'popular_cats' => array() + ); + + if (is_array($selected_cats)) { + $args['selected_cats'] = $selected_cats; + } else { + $args['selected_cats'] = array(); + } + + $categories = $this->core->getCategories(); + $_categories_id = $this->core->getCategoriesId($categories); + + // 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) + $checked_categories = array(); + foreach ($args['selected_cats'] as $key => $value) { + if (isset($_categories_id[ $key ])) { + $category_key = $_categories_id[ $key ]; + $checked_categories[] = $categories[ $category_key ]; + unset($categories[ $category_key ]); + } + } + + // Put checked cats on top + echo $walker->walk($checked_categories, 0, $args); + // Then the rest of them + echo $walker->walk($categories, 0, $args); + } + + /** + * Display Widget Control Form + * + * @param unknown_type $instance + */ + public function form($instance) { + // displays the widget admin form + $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => '', 'depth' => 0)); + + // Prepare data for display + $depth = (int) $instance['depth']; + if ($depth < 0 || 11 < $depth) { + $depth = 0; + } + $selected_cats = (avhGetArrayValue($instance, 'post_category') !== + '') ? unserialize($instance['post_category']) : false; + + echo '<p>'; + avh_doWidgetFormText($this->get_field_id('title'), + $this->get_field_name('title'), + __('Title', 'avh-ec'), + avhGetArrayValue($instance, 'title')); + echo '</p>'; + + echo '<p>'; + avh_doWidgetFormCheckbox($this->get_field_id('selectedonly'), + $this->get_field_name('selectedonly'), + __('Show selected categories only', 'avh-ec'), + (bool) avhGetArrayValue($instance, 'selectedonly')); + + avh_doWidgetFormCheckbox($this->get_field_id('count'), + $this->get_field_name('count'), + __('Show post counts', 'avh-ec'), + (bool) avhGetArrayValue($instance, 'count')); + + avh_doWidgetFormCheckbox($this->get_field_id('hierarchical'), + $this->get_field_name('hierarchical'), + __('Show hierarchy', 'avh-ec'), + (bool) avhGetArrayValue($instance, 'hierarchical')); + + $options = array(0 => __('All Levels', 'avh-ec'), 1 => __('Toplevel only', 'avh-ec')); + for ($i = 2; $i <= 11; $i ++) { + $options[ $i ] = __('Child ', 'avh-ec') . ($i - 1); + } + avh_doWidgetFormSelect($this->get_field_id('depth'), + $this->get_field_name('depth'), + __('How many levels to show', 'avh-ec'), + $options, + $depth); + unset($options); + + avh_doWidgetFormCheckbox($this->get_field_id('hide_empty'), + $this->get_field_name('hide_empty'), + __('Hide empty categories', 'avh-ec'), + (bool) avhGetArrayValue($instance, 'hide_empty')); + + 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')); + echo '</p>'; + + echo '<p>'; + $options['ID'] = __('ID', 'avh-ec'); + $options['name'] = __('Name', 'avh-ec'); + $options['count'] = __('Count', 'avh-ec'); + $options['slug'] = __('Slug', 'avh-ec'); + $options['avhec_manualorder'] = 'AVH EC ' . __('Manual Order', 'avh-ec'); + if (is_plugin_active('my-category-order/mycategoryorder.php')) { + $options['avhec_3rdparty_mycategoryorder'] = 'My Category Order'; + } + + avh_doWidgetFormSelect($this->get_field_id('sort_column'), + $this->get_field_name('sort_column'), + __('Sort by', 'avh-ec'), + $options, + avhGetArrayValue($instance, 'sort_column')); + unset($options); + + $options['asc'] = __('Ascending', 'avh-ec'); + $options['desc'] = __('Descending', 'avh-ec'); + avh_doWidgetFormSelect($this->get_field_id('sort_order'), + $this->get_field_name('sort_order'), + __('Sort order', 'avh-ec'), + $options, + avhGetArrayValue($instance, 'sort_order')); + unset($options); + + $options['list'] = __('List', 'avh-ec'); + $options['drop'] = __('Drop down', 'avh-ec'); + avh_doWidgetFormSelect($this->get_field_id('style'), + $this->get_field_name('style'), + __('Display style', 'avh-ec'), + $options, + avhGetArrayValue($instance, 'style')); + unset($options); + echo '</p>'; + + echo '<p>'; + + avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), + $this->get_field_name('rssfeed'), + __('Show RSS Feed', 'avh-ec'), + (bool) avhGetArrayValue($instance, 'rssfeed')); + + avh_doWidgetFormText($this->get_field_id('rssimage'), + $this->get_field_name('rssimage'), + __('Path (URI) to RSS image', 'avh-ec'), + avhGetArrayValue($instance, 'rssimage')); + + echo '</p>'; + + echo '<p>'; + echo '<b>' . __('Select categories', 'avh-ec') . '</b><hr />'; + 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;">'; + echo '<li id="' . $this->get_field_id('category--1') . '" class="popular-category">'; + echo '<label for="' . $this->get_field_id('post_category') . '" class="selectit">'; + 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' : '') . + '> '; + _e('All Categories', 'avh-ec'); + echo '</label>'; + echo '</li>'; + ob_start(); + $this->avh_wp_category_checklist($selected_cats, $this->number); + ob_end_flush(); + echo '</ul>'; + echo '</p>'; + + echo '<p>'; + 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')); + echo '</p>'; + + echo '<input type="hidden" id="' . + $this->get_field_id('submit') . + '" name="' . + $this->get_field_name('submit') . + '" value="1" />'; + } + + /** + * When Widget Control Form Is Posted + * + * @param unknown_type $new_instance + * @param unknown_type $old_instance + * + * @return unknown + */ + public function update($new_instance, $old_instance) { + // update the instance's settings + if ( ! isset($new_instance['submit'])) { + return false; + } + + $instance = $old_instance; + + $instance['title'] = strip_tags(stripslashes($new_instance['title'])); + $instance['selectedonly'] = isset($new_instance['selectedonly']); + $instance['count'] = isset($new_instance['count']); + $instance['hierarchical'] = isset($new_instance['hierarchical']); + $instance['hide_empty'] = isset($new_instance['hide_empty']); + $instance['use_desc_for_title'] = isset($new_instance['use_desc_for_title']); + $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column'])); + $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order'])); + $instance['style'] = strip_tags(stripslashes($new_instance['style'])); + $instance['rssfeed'] = isset($new_instance['rssfeed']); + $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage'])); + if (array_key_exists('all', $new_instance['post_category'])) { + $instance['post_category'] = false; + } else { + $instance['post_category'] = serialize($new_instance['post_category']); + } + $instance['depth'] = (int) $new_instance['depth']; + if ($instance['depth'] < 0 || 11 < $instance['depth']) { + $instance['depth'] = 0; + } + $instance['invert_included'] = isset($new_instance['invert_included']); + + return $instance; + } + + /** + * Display the widget + * + * @param unknown_type $args + * @param unknown_type $instance + */ + public function widget($args, $instance) { + extract($args); + + $selectedonly = $instance['selectedonly']; + $c = $instance['count']; + $h = $instance['hierarchical']; + $d = $instance['depth']; + $e = $instance['hide_empty']; + $use_desc_for_title = $instance['use_desc_for_title']; + $s = isset($instance['sort_column']) ? $instance['sort_column'] : 'name'; + $o = isset($instance['sort_order']) ? $instance['sort_order'] : 'asc'; + $r = ($instance['rssfeed'] == true) ? 'RSS' : ''; + $i = isset($instance['rssimage']) ? $instance['rssimage'] : ''; + $invert = $instance['invert_included']; + + if (empty($r)) { + $i = ''; + } + + if (empty($d)) { + $d = 0; + } + + $title = apply_filters('widget_title', + empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']); + $style = empty($instance['style']) ? 'list' : $instance['style']; + + $included_cats = ''; + if ($instance['post_category']) { + $post_category = unserialize($instance['post_category']); + $children = array(); + if ( ! $instance['selectedonly']) { + foreach ($post_category as $cat_id) { + $children = array_merge($children, get_term_children($cat_id, 'category')); + } + } + $included_cats = implode(",", array_merge($post_category, $children)); + } + + if ($invert) { + $inc_exc = 'exclude'; + } else { + $inc_exc = 'include'; + } + + $options = $this->core->getOptions(); + $show_option_none = __('Select Category', 'avh-ec'); + if ($options['general']['alternative_name_select_category']) { + $show_option_none = $options['general']['alternative_name_select_category']; + } + + $cat_args = array( + $inc_exc => $included_cats, + 'orderby' => $s, + 'order' => $o, + 'show_count' => $c, + 'use_desc_for_title' => $use_desc_for_title, + 'hide_empty' => $e, + 'hierarchical' => $h, + 'depth' => $d, + 'title_li' => '', + 'show_option_none' => $show_option_none, + 'feed' => $r, + 'feed_image' => $i, + 'name' => 'extended-categories-select-' . $this->number + ); + echo $before_widget; + echo $this->core->comment; + echo $before_title . $title . $after_title; + + if ($style == 'list') { + echo '<ul>'; + $this->core->avh_wp_list_categories($cat_args); + echo '</ul>'; + } else { + $this->core->avh_wp_dropdown_categories($cat_args); + echo '<script type=\'text/javascript\'>' . "\n"; + echo '/* <![CDATA[ */' . "\n"; + echo ' var ec_dropdown_' . + $this->number . + ' = document.getElementById("extended-categories-select-' . + $this->number . + '");' . + "\n"; + echo ' function ec_onCatChange_' . $this->number . '() {' . "\n"; + echo ' if (ec_dropdown_' . + $this->number . + '.options[ec_dropdown_' . + $this->number . + '.selectedIndex].value > 0) {' . + "\n"; + echo ' location.href = "' . + home_url() . + '/?cat="+ec_dropdown_' . + $this->number . + '.options[ec_dropdown_' . + $this->number . + '.selectedIndex].value;' . + "\n"; + echo ' }' . "\n"; + echo ' }' . "\n"; + echo ' ec_dropdown_' . + $this->number . + '.onchange = ec_onCatChange_' . + $this->number . + ';' . + "\n"; + echo '/* ]]> */' . "\n"; + echo '</script>' . "\n"; + } + echo $after_widget; + } } /** - * Class that will display the categories + * Widget Class for displaying the top categories */ -class AVH_Walker_Category_Checklist extends Walker -{ - - public $tree_type = 'category'; - - public $db_fields = array('parent' => 'parent', 'id' => 'term_id'); // TODO: decouple this - public $number; - - public $input_id; - - public $input_name; - - public $li_id; - - /** - * Display array of elements hierarchically. - * - * It is a generic function which does not assume any existing order of - * elements. max_depth = -1 means flatly display every element. max_depth = - * 0 means display all levels. max_depth > 0 specifies the number of - * display levels. - * - * @since 2.1.0 - * - * @param array $elements - * @param int $max_depth - * @param array $args; - * @return string - */ - public function walk($elements, $max_depth) - { - $args = array_slice(func_get_args(), 2); - $output = ''; - - if ($max_depth < -1) { - return $output; - } - - if (empty($elements)) { // nothing to walk - return $output; - } - - $id_field = $this->db_fields['id']; - $parent_field = $this->db_fields['parent']; - - // flat display - if (-1 == $max_depth) { - $empty_array = array(); - foreach ($elements as $e) { - $this->display_element($e, $empty_array, 1, 0, $args, $output); - } - - return $output; - } - - /* - * 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. - */ - $top_level_elements = array(); - $children_elements = array(); - foreach ($elements as $e) { - if (0 == $e->$parent_field) { - $top_level_elements[] = $e; - } else { - $children_elements[$e->$parent_field][] = $e; - } - } - - /* - * when none of the elements is top level assume the first one must be root of the sub elements - */ - if (empty($top_level_elements)) { - - $first = array_slice($elements, 0, 1); - $root = $first[0]; - - $top_level_elements = array(); - $children_elements = array(); - foreach ($elements as $e) { - if ($root->$parent_field == $e->$parent_field) { - $top_level_elements[] = $e; - } else { - $children_elements[$e->$parent_field][] = $e; - } - } - } - - foreach ($top_level_elements as $e) { - $this->display_element($e, $children_elements, $max_depth, 0, $args, $output); - } - - /* - * if we are displaying all levels, and remaining children_elements is not empty, then we got orphans, which should be displayed regardless - */ - if (($max_depth == 0) && count($children_elements) > 0) { - $empty_array = array(); - foreach ($children_elements as $orphans) { - foreach ($orphans as $op) { - $this->display_element($op, $empty_array, 1, 0, $args, $output); - } - } - } - - return $output; - } - - public function start_lvl(&$output, $depth = 0, $args = array()) - { - $indent = str_repeat("\t", $depth); - $output .= $indent . '<ul class="children">' . "\n"; - } - - public function end_lvl(&$output, $depth = 0, $args = array()) - { - $indent = str_repeat("\t", $depth); - $output .= $indent . '</ul>' . "\n"; - } - - public function start_el(&$output, $object, $depth = 0, $args = array(), $current_object_id = 0) - { - extract($args); - if (!isset($selected_cats)) { - $selected_cats = array(); - } - $input_id = $this->input_id . '-' . $object->term_id; - $output .= "\n" . '<li id="' . $this->li_id . '">'; - $output .= '<label for="' . $input_id . '" class="selectit">'; - $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>'; - } - - public function end_el(&$output, $object, $depth = 0, $args = array()) - { - $output .= "</li>\n"; - } +class WP_Widget_AVH_ExtendedCategories_Top extends WP_Widget { + /** + * @var AVH_EC_Core + */ + public $core; + + /** + * PHP 5 Constructor + */ + public function __construct() { + $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core'); + + $widget_ops = array('description' => __("Shows the top categories.", 'avh-ec')); + WP_Widget::__construct(false, 'AVH Extended Categories: ' . __('Top Categories'), $widget_ops); + add_action('wp_print_styles', array($this, 'actionWpPrintStyles')); + } + + public function actionWpPrintStyles() { + if ( ! (false === is_active_widget(false, false, $this->id_base, true))) { + wp_register_style('avhec-widget', + AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', + array(), + $this->core->version); + wp_enqueue_style('avhec-widget'); + } + } + + /** + * Echo the settings update form + * + * @param array $instance + * Current settings + */ + public function form($instance) { + // displays the widget admin form + $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => '', 'amount' => '5')); + + $amount = (int) avhGetArrayValue($instance, 'amount'); + if ($amount < 1) { + $amount = 1; + } + echo '<p>'; + avh_doWidgetFormText($this->get_field_id('title'), + $this->get_field_name('title'), + __('Title', 'avh-ec'), + avhGetArrayValue($instance, 'title')); + echo '</p>'; + + echo '<p>'; + avh_doWidgetFormText($this->get_field_id('amount'), + $this->get_field_name('amount'), + __('How many categories to show', 'avh-ec'), + $amount); + echo '</p>'; + + echo '<p>'; + avh_doWidgetFormCheckbox($this->get_field_id('count'), + $this->get_field_name('count'), + __('Show post counts', 'avh-ec'), + (bool) avhGetArrayValue($instance, 'count')); + echo '<br />'; + + 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')); + echo '</p>'; + + echo '<p>'; + $options['ID'] = __('ID', 'avh-ec'); + $options['name'] = __('Name', 'avh-ec'); + $options['count'] = __('Count', 'avh-ec'); + $options['slug'] = __('Slug', 'avh-ec'); + avh_doWidgetFormSelect($this->get_field_id('sort_column'), + $this->get_field_name('sort_column'), + __('Sort by', 'avh-ec'), + $options, + avhGetArrayValue($instance, 'sort_column')); + unset($options); + + $options['asc'] = __('Ascending', 'avh-ec'); + $options['desc'] = __('Descending', 'avh-ec'); + avh_doWidgetFormSelect($this->get_field_id('sort_order'), + $this->get_field_name('sort_order'), + __('Sort order', 'avh-ec'), + $options, + avhGetArrayValue($instance, 'sort_order')); + unset($options); + + $options['list'] = __('List', 'avh-ec'); + $options['drop'] = __('Drop down', 'avh-ec'); + avh_doWidgetFormSelect($this->get_field_id('style'), + $this->get_field_name('style'), + __('Display style', 'avh-ec'), + $options, + avhGetArrayValue($instance, 'style')); + unset($options); + echo '</p>'; + + echo '<p>'; + + avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), + $this->get_field_name('rssfeed'), + __('Show RSS Feed', 'avh-ec'), + (bool) avhGetArrayValue($instance, 'rssfeed')); + + avh_doWidgetFormText($this->get_field_id('rssimage'), + $this->get_field_name('rssimage'), + __('Path (URI) to RSS image', 'avh-ec'), + avhGetArrayValue($instance, 'rssimage')); + + echo '</p>'; + + echo '<input type="hidden" id="' . + $this->get_field_id('submit') . + '" name="' . + $this->get_field_name('submit') . + '" value="1" />'; + } + + /** + * Update a particular instance. + * This function should check that $new_instance is set correctly. + * The newly calculated value of $instance should be returned. + * If "false" is returned, the instance won't be saved/updated. + * + * @param array $new_instance + * New settings for this instance as input by the user via form() + * @param array $old_instance + * Old settings for this instance + * + * @return array Settings to save or bool false to cancel saving + */ + public function update($new_instance, $old_instance) { + // update the instance's settings + if ( ! isset($new_instance['submit'])) { + return false; + } + + $instance = $old_instance; + + $instance['title'] = strip_tags(stripslashes($new_instance['title'])); + $instance['amount'] = (int) $new_instance['amount']; + $instance['count'] = isset($new_instance['count']); + $instance['use_desc_for_title'] = isset($new_instance['use_desc_for_title']); + $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column'])); + $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order'])); + $instance['style'] = strip_tags(stripslashes($new_instance['style'])); + $instance['rssfeed'] = isset($new_instance['rssfeed']); + $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage'])); + + return $instance; + } + + /** + * Echo the widget content. + * Subclasses should over-ride this function to generate their widget code. + * + * @param array $args + * Display arguments including before_title, after_title, before_widget, and after_widget. + * @param array $instance + * The settings for the particular instance of the widget + */ + public function widget($args, $instance) { + extract($args); + + $title = apply_filters('widget_title', + empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']); + $style = empty($instance['style']) ? 'list' : $instance['style']; + if ( ! $a = (int) $instance['amount']) { + $a = 5; + } elseif ($a < 1) { + $a = 1; + } + $c = $instance['count']; + $use_desc_for_title = $instance['use_desc_for_title']; + $s = isset($instance['sort_column']) ? $instance['sort_column'] : 'name'; + $o = isset($instance['sort_order']) ? $instance['sort_order'] : 'asc'; + $r = ($instance['rssfeed'] === true) ? 'RSS' : ''; + $i = isset($instance['rssimage']) ? $instance['rssimage'] : ''; + if (empty($r)) { + $i = ''; + } + if ( ! empty($i)) { + if ( ! file_exists(ABSPATH . '/' . $i)) { + $i = ''; + } + } + + $options = $this->core->getOptions(); + $show_option_none = __('Select Category', 'avh-ec'); + if ($options['general']['alternative_name_select_category']) { + $show_option_none = $options['general']['alternative_name_select_category']; + } + + $top_cats = get_terms('category', + array( + 'fields' => 'ids', + 'orderby' => 'count', + 'order' => 'DESC', + 'number' => $a, + 'hierarchical' => false + )); + $included_cats = implode(",", $top_cats); + + $cat_args = array( + 'include' => $included_cats, + 'orderby' => $s, + 'order' => $o, + 'show_count' => $c, + 'use_desc_for_title' => $use_desc_for_title, + 'hide_empty' => false, + 'hierarchical' => false, + 'depth' => - 1, + 'title_li' => '', + 'show_option_none' => $show_option_none, + 'feed' => $r, + 'feed_image' => $i, + 'name' => 'extended-categories-top-select-' . $this->number + ); + echo $before_widget; + echo $this->core->comment; + echo $before_title . $title . $after_title; + echo '<ul>'; + + if ($style == 'list') { + wp_list_categories($cat_args); + } else { + wp_dropdown_categories($cat_args); + echo '<script type=\'text/javascript\'>' . "\n"; + echo '/* <![CDATA[ */' . "\n"; + echo ' var ec_dropdown_top_' . + $this->number . + ' = document.getElementById("extended-categories-top-select-' . + $this->number . + '");' . + "\n"; + echo ' function ec_top_onCatChange_' . $this->number . '() {' . "\n"; + echo ' if (ec_dropdown_top_' . + $this->number . + '.options[ec_dropdown_top_' . + $this->number . + '.selectedIndex].value > 0) {' . + "\n"; + echo ' location.href = "' . + get_option('home') . + '/?cat="+ec_dropdown_top_' . + $this->number . + '.options[ec_dropdown_top_' . + $this->number . + '.selectedIndex].value;' . + "\n"; + echo ' }' . "\n"; + echo ' }' . "\n"; + echo ' ec_dropdown_top_' . + $this->number . + '.onchange = ec_top_onCatChange_' . + $this->number . + ';' . + "\n"; + echo '/* ]]> */' . "\n"; + echo '</script>' . "\n"; + } + echo '</ul>'; + echo $after_widget; + } } diff --git a/wp-content/plugins/extended-categories-widget/3.6/css/avh-ec.admin.css b/wp-content/plugins/extended-categories-widget/3.6/css/avh-ec.admin.css index d7c05485be8dc186eefc41d1779362a695a6a318..0f7618c793f04d786a975d9776e200d1434cfaea 100644 --- a/wp-content/plugins/extended-categories-widget/3.6/css/avh-ec.admin.css +++ b/wp-content/plugins/extended-categories-widget/3.6/css/avh-ec.admin.css @@ -1,13 +1,13 @@ .footer_avhec { - font-size: 0.8em; - text-align: center; + font-size : 0.8em; + text-align : center; } div.clearer { - clear: both; - line-height: 1px; - font-size: 1px; - height: 1px; + clear : both; + line-height : 1px; + font-size : 1px; + height : 1px; } /* Metabox in General */ @@ -20,12 +20,12 @@ table.avhec-options { } .avhec-metabox-wrap .p { - line-height: 140%; - margin: 1em 0; + line-height : 140%; + margin : 1em 0; } #avhecBoxOptions option { - padding: .5em; + padding : .5em; } .avhec-metabox-wrap span.description { @@ -33,17 +33,17 @@ table.avhec-options { } .avhec-metabox-wrap .b { - font-weight: bold; + font-weight : bold; } .avhec-metabox-wrap ul { - margin-bottom: 1em; + margin-bottom : 1em; } .avhec-metabox-wrap ul li { - line-height: 120%; - list-style: disc inside none; - margin-bottom: 0; + line-height : 120%; + list-style : disc inside none; + margin-bottom : 0; } #avhec-options input { @@ -56,13 +56,13 @@ table.avhec-options { /* Metabox FAQ */ #avhecBoxFAQ .inside ul { - margin-bottom: 6px; + margin-bottom : 6px; } #avhecBoxFAQ .inside ul li { - line-height: 120%; - list-style: disc inside none; - margin-bottom: 0; + line-height : 120%; + list-style : disc inside none; + margin-bottom : 0; } /* Metabox Donations*/ @@ -71,7 +71,7 @@ table.avhec-options { } #avhecBoxDonations .versions { - padding: 6px 10px 12px; + padding : 6px 10px 12px; } /* Metabox Donations*/ @@ -81,75 +81,75 @@ table.avhec-options { /* Metabox in post and page */ #post_avhec_category_group { - width: 100%; + width : 100%; } #avhec-catlist { - -moz-border-radius: 4px 4px 4px 4px; - background-color: #FFFFFF; - border: 1px solid #DFDFDF; - height: 20em; - margin-bottom: -1.8em; - overflow: auto; - width: 95%; + -moz-border-radius : 4px 4px 4px 4px; + background-color : #FFFFFF; + border : 1px solid #DFDFDF; + height : 20em; + margin-bottom : -1.8em; + overflow : auto; + width : 95%; } #avhec-catlist ul { - padding: 3px; + padding : 3px; } #avhec-catlist li ul { - padding: 0px; + padding : 0px; } #avhec-catlist li { - margin-bottom: 0px; + margin-bottom : 0px; } #avhecManualOrder { - width: 25%; - /* border: 1px solid #B2B2B2;*/ - /* margin: 10px 10px 10px 0px;*/ - /* padding: 5px 10px 5px 10px;*/ - /* list-style: none;*/ - /* background-color: #fff;*/ - /* border-radius: 3px;*/ - /* -webkit-border-radius: 3px;*/ + width : 25%; + /* border: 1px solid #B2B2B2;*/ + /* margin: 10px 10px 10px 0px;*/ + /* padding: 5px 10px 5px 10px;*/ + /* list-style: none;*/ + /* background-color: #fff;*/ + /* border-radius: 3px;*/ + /* -webkit-border-radius: 3px;*/ } #avhecManualOrder li.lineitem { - border: 1px solid #DFDFDF; - background-image: none; - border-radius: 3px; - -webkit-border-radius: 3px; - background-color: #FFFFFF; - color: #555555; - cursor: move; - margin-top: 5px; - margin-bottom: 5px; - padding: 2px 5px 2px 5px; - list-style: none outside none; + border : 1px solid #DFDFDF; + background-image : none; + border-radius : 3px; + -webkit-border-radius : 3px; + background-color : #FFFFFF; + color : #555555; + cursor : move; + margin-top : 5px; + margin-bottom : 5px; + padding : 2px 5px 2px 5px; + list-style : none outside none; } #avhecManualOrder .sortable-placeholder { - border: 1px dashed #B2B2B2; - margin-top: 5px; - margin-bottom: 5px; - padding: 2px 5px 2px 5px; - height: 1.5em; - line-height: 1.5em; - list-style: none outside none; - background-color: transparent; - /* IE10 */ - background-image: -ms-linear-gradient(top, #f9f9f9, #f5f5f5); - /* Firefox */ - background-image: -moz-linear-gradient(top, #f9f9f9, #f5f5f5); - /* Opera */ - background-image: -o-linear-gradient(top, #f9f9f9, #f5f5f5); - /* old Webkit */ - background-image: -webkit-gradient(linear, left top, left bottom, from(#f9f9f9), to(#f5f5f5) ); - /* new Webkit */ - background-image: -webkit-linear-gradient(top, #f9f9f9, #f5f5f5); - /* proposed W3C Markup */ - background-image: linear-gradient(top, #f9f9f9, #f5f5f5); + border : 1px dashed #B2B2B2; + margin-top : 5px; + margin-bottom : 5px; + padding : 2px 5px 2px 5px; + height : 1.5em; + line-height : 1.5em; + list-style : none outside none; + background-color : transparent; + /* IE10 */ + background-image : -ms-linear-gradient(top, #f9f9f9, #f5f5f5); + /* Firefox */ + background-image : -moz-linear-gradient(top, #f9f9f9, #f5f5f5); + /* Opera */ + background-image : -o-linear-gradient(top, #f9f9f9, #f5f5f5); + /* old Webkit */ + background-image : -webkit-gradient(linear, left top, left bottom, from(#f9f9f9), to(#f5f5f5)); + /* new Webkit */ + background-image : -webkit-linear-gradient(top, #f9f9f9, #f5f5f5); + /* proposed W3C Markup */ + background-image : linear-gradient(top, #f9f9f9, #f5f5f5); } \ No newline at end of file diff --git a/wp-content/plugins/extended-categories-widget/3.6/css/avh-ec.widget.css b/wp-content/plugins/extended-categories-widget/3.6/css/avh-ec.widget.css index 25a86492027158e2aee27e65b763b3f122d7d27d..fbb382083b1a92d03aa554a7e75d3191d561ee44 100644 --- a/wp-content/plugins/extended-categories-widget/3.6/css/avh-ec.widget.css +++ b/wp-content/plugins/extended-categories-widget/3.6/css/avh-ec.widget.css @@ -1,12 +1,12 @@ /* AVH Extended Categories Widget CSS */ .avhec-widget-line { - display: inline-block; + display : inline-block; } .avhec-widget-count { - display: inline; + display : inline; } .avhec-widget-rss { - display: inline; + display : inline; } \ No newline at end of file diff --git a/wp-content/plugins/extended-categories-widget/3.6/helpers/avh-common.php b/wp-content/plugins/extended-categories-widget/3.6/helpers/avh-common.php index 667b269e22ca2aad0b968d019d91c8d2fb3d9434..dea8155904a10200ae1af140a6d05cea70a8b86f 100644 --- a/wp-content/plugins/extended-categories-widget/3.6/helpers/avh-common.php +++ b/wp-content/plugins/extended-categories-widget/3.6/helpers/avh-common.php @@ -1,18 +1,18 @@ <?php -if ( !function_exists('avhGetArrayValue') ) { +if ( ! function_exists('avhGetArrayValue')) { /** * Get the value of $array[$name] * - * @param array $array + * @param array $array * @param string $name * * @return mixed An empty string when the $array[$name] does not exists */ - function avhGetArrayValue ($array, $name) - { - if ( isset($array[$name]) ) - return $array[$name]; + function avhGetArrayValue($array, $name) { + if (isset($array[ $name ])) { + return $array[ $name ]; + } return ''; } diff --git a/wp-content/plugins/extended-categories-widget/3.6/helpers/avh-forms.php b/wp-content/plugins/extended-categories-widget/3.6/helpers/avh-forms.php index 03064a5993ad1606c1d66da1b6aa618b2701e935..fa8abe8ee9adfdbe8a5e3a18c4b9d2096c73bd3e 100644 --- a/wp-content/plugins/extended-categories-widget/3.6/helpers/avh-forms.php +++ b/wp-content/plugins/extended-categories-widget/3.6/helpers/avh-forms.php @@ -1,43 +1,59 @@ <?php -if (!function_exists('avh_doWidgetFormText')) { +if ( ! function_exists('avh_doWidgetFormText')) { - function avh_doWidgetFormText($field_id, $field_name, $description, $value) - { - echo '<label for="' . $field_id . '">'; - echo $description; - echo '<input class="widefat" id="' . $field_id . '" name="' . $field_name . '" type="text" value="' . esc_attr($value) . '" /> '; - echo '</label>'; - echo '<br />'; - } + function avh_doWidgetFormText($field_id, $field_name, $description, $value) { + echo '<label for="' . $field_id . '">'; + echo $description; + echo '<input class="widefat" id="' . + $field_id . + '" name="' . + $field_name . + '" type="text" value="' . + esc_attr($value) . + '" /> '; + echo '</label>'; + echo '<br />'; + } } -if (!function_exists('avh_doWidgetFormCheckbox')) { +if ( ! function_exists('avh_doWidgetFormCheckbox')) { - function avh_doWidgetFormCheckbox($field_id, $field_name, $description, $is_checked = false) - { - echo '<label for="' . $field_id . '">'; - echo '<input class="checkbox" type="checkbox" id="' . $field_id . '" name="' . $field_name . '"' . ($is_checked ? ' CHECKED' : '') . ' /> '; - echo $description; - echo '</label>'; - echo '<br />'; - } + function avh_doWidgetFormCheckbox($field_id, $field_name, $description, $is_checked = false) { + echo '<label for="' . $field_id . '">'; + echo '<input class="checkbox" type="checkbox" id="' . + $field_id . + '" name="' . + $field_name . + '"' . + ($is_checked ? ' CHECKED' : '') . + ' /> '; + echo $description; + echo '</label>'; + echo '<br />'; + } } -if (!function_exists('avh_doWidgetFormSelect')) { +if ( ! function_exists('avh_doWidgetFormSelect')) { - function avh_doWidgetFormSelect($field_id, $field_name, $description, $options, $selected_value) - { - echo '<label for="' . $field_id . '">'; - echo $description . ' '; - echo '</label>'; + function avh_doWidgetFormSelect($field_id, $field_name, $description, $options, $selected_value) { + echo '<label for="' . $field_id . '">'; + echo $description . ' '; + echo '</label>'; - $data = ''; - foreach ($options as $value => $text) { - $data .= '<option value="' . $value . '" ' . ($value == $selected_value ? "SELECTED" : '') . '>' . $text . '</option>' . "/n"; - } - echo '<select id="' . $field_id . '" name="' . $field_name . '"> '; - echo $data; - echo '</select>'; - echo '<br />'; - } + $data = ''; + foreach ($options as $value => $text) { + $data .= '<option value="' . + $value . + '" ' . + ($value == $selected_value ? "SELECTED" : '') . + '>' . + $text . + '</option>' . + "/n"; + } + echo '<select id="' . $field_id . '" name="' . $field_name . '"> '; + echo $data; + echo '</select>'; + echo '<br />'; + } } diff --git a/wp-content/plugins/extended-categories-widget/3.6/js/avh-ec.admin.manualorder.js b/wp-content/plugins/extended-categories-widget/3.6/js/avh-ec.admin.manualorder.js index 34b4ae16827d893ba3be2b4a275c04af1cab68d7..e5a9c066d70187d4ac410f22e1328940212e8ff9 100644 --- a/wp-content/plugins/extended-categories-widget/3.6/js/avh-ec.admin.manualorder.js +++ b/wp-content/plugins/extended-categories-widget/3.6/js/avh-ec.admin.manualorder.js @@ -1,19 +1,19 @@ function avhecManualOrder() { - jQuery("#avhecManualOrder").sortable({ - placeholder : "sortable-placeholder", - revert : false, - items : '.lineitem', - opacity: 0.65, - cursor: 'move', - forcePlaceholderSize: true, - tolerance : "pointer" - }); + 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")); + jQuery("#updateText").html("Updating Category Order..."); + jQuery("#hdnManualOrder").val( + jQuery("#avhecManualOrder").sortable("toArray")); } \ No newline at end of file diff --git a/wp-content/plugins/extended-categories-widget/3.6/js/avh-ec.admin.manualorder.min.js b/wp-content/plugins/extended-categories-widget/3.6/js/avh-ec.admin.manualorder.min.js new file mode 100644 index 0000000000000000000000000000000000000000..f9ff1e235ba43f64e84475f07f8a067ef81681b1 --- /dev/null +++ b/wp-content/plugins/extended-categories-widget/3.6/js/avh-ec.admin.manualorder.min.js @@ -0,0 +1 @@ +function avhecManualOrder(){jQuery("#avhecManualOrder").sortable({placeholder:"sortable-placeholder",revert:false,items:".lineitem",opacity:.65,cursor:"move",forcePlaceholderSize:true,tolerance:"pointer"})}addLoadEvent(avhecManualOrder);function orderCats(){jQuery("#updateText").html("Updating Category Order...");jQuery("#hdnManualOrder").val(jQuery("#avhecManualOrder").sortable("toArray"))} \ No newline at end of file diff --git a/wp-content/plugins/extended-categories-widget/3.6/js/avh-ec.categorygroup.js b/wp-content/plugins/extended-categories-widget/3.6/js/avh-ec.categorygroup.js index 7221dfa75b4bd0d5c2f9dd3844834ca8d53316a2..0f7e70914cfd2ca8d6790affcaba3c728efc1541 100644 --- a/wp-content/plugins/extended-categories-widget/3.6/js/avh-ec.categorygroup.js +++ b/wp-content/plugins/extended-categories-widget/3.6/js/avh-ec.categorygroup.js @@ -1,21 +1,23 @@ -jQuery(document).ready(function($) { - var options = false, delBefore, delAfter; +jQuery(document).ready(function ($) { + var options = false, delBefore, delAfter; - delAfter = function( r, settings ) { - var id = $('cat', r).attr('id'), o; - for ( o = 0; o < options.length; o++ ) - if ( id == options[o].value ) - options[o] = null; - }; + delAfter = function (r, settings) { + var id = $('cat', r).attr('id'), o; + for (o = 0; o < options.length; o++) + if (id == options[o].value) + options[o] = null; + }; - delBefore = function(s) { - if ( 'undefined' != showNotice ) - return showNotice.warn() ? s : false; + delBefore = function (s) { + if ('undefined' != showNotice) + return showNotice.warn() ? s : false; - return s; - }; + return s; + }; - $('#the-list').wpList({ delBefore: delBefore }); + $('#the-list').wpList({delBefore: delBefore}); - $('.delete a[class^="delete"]').live('click', function(){return false;}); + $('.delete a[class^="delete"]').live('click', function () { + return false; + }); }); diff --git a/wp-content/plugins/extended-categories-widget/3.6/js/avh-ec.categorygroup.min.js b/wp-content/plugins/extended-categories-widget/3.6/js/avh-ec.categorygroup.min.js new file mode 100644 index 0000000000000000000000000000000000000000..5b7e6ba1ef13853ad0490ef9983fe341a6d6d955 --- /dev/null +++ b/wp-content/plugins/extended-categories-widget/3.6/js/avh-ec.categorygroup.min.js @@ -0,0 +1 @@ +jQuery(document).ready(function($){var options=false,delBefore,delAfter;delAfter=function(r,settings){var id=$("cat",r).attr("id"),o;for(o=0;o<options.length;o++)if(id==options[o].value)options[o]=null};delBefore=function(s){if("undefined"!=showNotice)return showNotice.warn()?s:false;return s};$("#the-list").wpList({delBefore:delBefore});$('.delete a[class^="delete"]').live("click",function(){return false})}); \ No newline at end of file diff --git a/wp-content/plugins/extended-categories-widget/4.2/avh-ec.client.php b/wp-content/plugins/extended-categories-widget/4.2/avh-ec.client.php index f21a19be2893647c83ed1dd7aaaef81a9036d07c..371a24672e706fbc3fbcb0207750ee40749371b8 100644 --- a/wp-content/plugins/extended-categories-widget/4.2/avh-ec.client.php +++ b/wp-content/plugins/extended-categories-widget/4.2/avh-ec.client.php @@ -2,78 +2,71 @@ /** * Singleton Class - * */ -class AVH_EC_Singleton -{ - - /** - * - * @param string $class - * @param string $arg1 - */ - public static function &getInstance($class, $arg1 = null) - { - static $instances = array(); // array of instance names - if (array_key_exists($class, $instances)) { - $instance = & $instances[$class]; - } else { - if (!class_exists($class)) { - switch ($class) { - case 'AVH_EC_Core': - require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.core.php'); - break; - case 'AVH_EC_Category_Group': - require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.category-group.php'); - break; - case 'AVH_EC_Widget_Helper_Class': - require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widget-helper.php'); - break; - } - } - $instances[$class] = new $class($arg1); - $instance = & $instances[$class]; - } +class AVH_EC_Singleton { + /** + * @param string $class + * @param string $arg1 + * + * @return object + */ + public static function &getInstance($class, $arg1 = null) { + static $instances = array(); // array of instance names + if (array_key_exists($class, $instances)) { + $instance = &$instances[ $class ]; + } else { + if ( ! class_exists($class)) { + switch ($class) { + case 'AVH_EC_Core': + require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.core.php'); + break; + case 'AVH_EC_Category_Group': + require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.category-group.php'); + break; + case 'AVH_EC_Widget_Helper_Class': + require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widget-helper.php'); + break; + } + } + $instances[ $class ] = new $class($arg1); + $instance = &$instances[ $class ]; + } - return $instance; - } + return $instance; + } } /** * Include the necessary files */ -require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/helpers/avh-forms.php'); -require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/helpers/avh-common.php'); -require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widgets.php'); +require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/helpers/avh-forms.php'); +require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/helpers/avh-common.php'); +require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.widgets.php'); /** * Initialize the plugin */ -function avhextendedcategories_init() -{ - // Admin - if (is_admin()) { - require_once (AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.admin.php'); - $avhec_admin = new AVH_EC_Admin(); - } - AVH_EC_Singleton::getInstance('AVH_EC_Core'); +function avhextendedcategories_init() { + // Admin + if (is_admin()) { + require_once(AVHEC_ABSOLUTE_WORKING_DIR . '/class/avh-ec.admin.php'); + new AVH_EC_Admin(); + } + AVH_EC_Singleton::getInstance('AVH_EC_Core'); - add_action('widgets_init', 'avhextendedcategories_widgets_init'); + add_action('widgets_init', 'avhextendedcategories_widgets_init'); } // End avhamazon_init() /** * Register the widget * * @WordPress Action widgets_init - * - * @since 3.0 - * + * @since 3.0 */ -function avhextendedcategories_widgets_init() -{ - register_widget('WP_Widget_AVH_ExtendedCategories_Normal'); - register_widget('WP_Widget_AVH_ExtendedCategories_Top'); - register_widget('WP_Widget_AVH_ExtendedCategories_Category_Group'); +function avhextendedcategories_widgets_init() { + register_widget('WP_Widget_AVH_ExtendedCategories_Normal'); + register_widget('WP_Widget_AVH_ExtendedCategories_Top'); + register_widget('WP_Widget_AVH_ExtendedCategories_Category_Group'); } add_action('plugins_loaded', 'avhextendedcategories_init'); diff --git a/wp-content/plugins/extended-categories-widget/4.2/class/avh-ec.admin.php b/wp-content/plugins/extended-categories-widget/4.2/class/avh-ec.admin.php index 19c84eca92e88b05ccd7a2adac4adacfaef3a27a..e3657cadbeb8e68aa5d4977cc78fc274ab27d17d 100644 --- a/wp-content/plugins/extended-categories-widget/4.2/class/avh-ec.admin.php +++ b/wp-content/plugins/extended-categories-widget/4.2/class/avh-ec.admin.php @@ -1,1464 +1,1848 @@ <?php -class AVH_EC_Admin -{ - - /** - * - * @var AVH_EC_Core - */ - public $core; - - /** - * - * @var AVH_EC_Category_Group - */ - public $catgrp; - - public $hooks = array(); - - public $message; - - /** - * PHP5 constructor - */ - public function __construct() - { - - // Initialize the plugin - $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core'); - $this->catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); - - add_action('wp_ajax_delete-group', array($this, 'ajaxDeleteGroup')); - - // Admin menu - add_action('admin_init', array($this, 'actionAdminInit')); - add_action('admin_menu', array($this, 'actionAdminMenu')); - add_filter('plugin_action_links_extended-categories-widget/widget_extended_categories.php', array($this, 'filterPluginActions'), 10, 2); - - // Actions used for editing posts - add_action('load-post.php', array($this, 'actionLoadPostPage')); - add_action('load-page.php', array($this, 'actionLoadPostPage')); - - // Actions related to adding and deletes categories - add_action("created_category", array($this, 'actionCreatedCategory'), 10, 2); - add_action("delete_category", array($this, 'actionDeleteCategory'), 10, 2); - - add_filter('manage_categories_group_columns', array($this, 'filterManageCategoriesGroupColumns')); - add_filter('explain_nonce_delete-avhecgroup', array($this, 'filterExplainNonceDeleteGroup'), 10, 2); - - return; - } - - public function actionAdminInit() - { - if (is_admin() && isset($_GET['taxonomy']) && 'category' == $_GET['taxonomy']) { - add_action($_GET['taxonomy'] . '_edit_form', array($this, 'displayCategoryGroupForm'), 10, 2); - } - add_action('edit_term', array($this, 'handleEditTerm'), 10, 3); - } - - /** - * Adds Category Group form - * @WordPress action category_edit_form - * - * @param unknown_type $term - * @param unknown_type $taxonomy - */ - public function displayCategoryGroupForm($term, $taxonomy) - { - $current_selection = ''; - $tax_meta = get_option($this->core->db_options_tax_meta); - if (isset($tax_meta[$taxonomy][$term->term_id])) { - $tax_meta = $tax_meta[$taxonomy][$term->term_id]; - $current_selection = $tax_meta['category_group_term_id']; - } - - if (empty($current_selection)) { - $current_group = $this->catgrp->getGroupByCategoryID($term->term_id); - $current_selection = $current_group->term_id; - } - - $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false)); - foreach ($cat_groups as $group) { - $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit'); - $dropdown_value[] = $group->term_id; - $dropdown_text[] = $temp_cat->name; - } - - $seldata = ''; - foreach ($dropdown_value as $key => $sel) { - $seldata .= '<option value="' . esc_attr($sel) . '" ' . (($current_selection == $sel) ? 'selected="selected"' : '') . ' >' . esc_html(ucfirst($dropdown_text[$key])) . '</option>' . "\n"; - } - - echo '<h3>AVH Extended Categories - Category Group Widget</h3>'; - echo '<table class="form-table"><tbody>'; - echo '<tr class="form-field">'; - echo '<th valign="top" scope="row">'; - echo '<label for="avhec_categorygroup">Category Group</label></th>'; - echo '<td>'; - echo '<select id="avhec_categorygroup" name="avhec_categorygroup">'; - echo $seldata; - echo '</select>'; - echo '<p class="description">Select the category group to show on the archive page.</p>'; - echo '</td>'; - echo '</tr>'; - echo '</tbody></table>'; - } - - /** - * Saves the association Category - Category Group fron the edit taxonomy page - * @WordPress action edit_form. - * - * @param unknown_type $term_id - * @param unknown_type $tt_id - * @param unknown_type $taxonomy - */ - public function handleEditTerm($term_id, $tt_id, $taxonomy) - { - $tax_meta = get_option($this->core->db_options_tax_meta); - if (isset($_POST['avhec_categorygroup'])) { - if (!isset($tax_meta[$taxonomy][$term_id]['category_group_term_id']) || $tax_meta[$taxonomy][$term_id]['category_group_term_id'] != $_POST['avhec_categorygroup']) { - $tax_meta[$taxonomy][$term_id]['category_group_term_id'] = $_POST['avhec_categorygroup']; - update_option($this->core->db_options_tax_meta, $tax_meta); - } - } - } - - /** - * When a category is created this function is called to add the new category to the group all - * - * @param - * $term_id - * @param - * $term_taxonomy_id - */ - public function actionCreatedCategory($term_id, $term_taxonomy_id) - { - $group_id = $this->catgrp->getTermIDBy('slug', 'all'); - $this->catgrp->setCategoriesForGroup($group_id, (array) $term_id); - } - - /** - * When a category is deleted this function is called so the category is deleted from every group as well. - * - * @param object $term - * @param int $term_taxonomy_id - */ - public function actionDeleteCategory($term_id, $term_taxonomy_id) - { - $this->catgrp->doDeleteCategoryFromGroup($term_id); - } - - /** - * Enqueues the style on the post.php and page.php pages - * @WordPress Action load-$pagenow - */ - public function actionLoadPostPage() - { - wp_enqueue_style('avhec-admin-css'); - } - - /** - * Add the Tools and Options to the Management and Options page repectively - * - * @WordPress Action admin_menu - */ - public function actionAdminMenu() - { - - // Register Style and Scripts - $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.closure'; - wp_register_script('avhec-categorygroup-js', AVHEC_PLUGIN_URL . '/js/avh-ec.categorygroup' . $suffix . '.js', array('jquery'), $this->core->version, true); - wp_register_script('avhec-manualorder', AVHEC_PLUGIN_URL . '/js/avh-ec.admin.manualorder' . $suffix . '.js', array('jquery-ui-sortable'), $this->core->version, false); - wp_register_style('avhec-admin-css', AVHEC_PLUGIN_URL . '/css/avh-ec.admin.css', array('wp-admin'), $this->core->version, 'screen'); - - // Add menu system - $folder = $this->core->getBaseDirectory(AVHEC_PLUGIN_DIR); - add_menu_page('AVH Extended Categories', 'AVH Extended Categories', 'manage_options', $folder, array($this, 'doMenuOverview')); - $this->hooks['menu_overview'] = add_submenu_page($folder, 'AVH Extended Categories: ' . __('Overview', 'avh-ec'), __('Overview', 'avh-ec'), 'manage_options', $folder, array($this, 'doMenuOverview')); - $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')); - $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')); - $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')); - $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')); - - // Add actions for menu pages - // Overview Menu - add_action('load-' . $this->hooks['menu_overview'], array($this, 'actionLoadPageHook_Overview')); - - // General Options Menu - add_action('load-' . $this->hooks['menu_general'], array($this, 'actionLoadPageHook_General')); - - // Category Groups Menu - add_action('load-' . $this->hooks['menu_category_groups'], array($this, 'actionLoadPageHook_CategoryGroup')); - - // Manual Order Menu - add_action('load-' . $this->hooks['menu_manual_order'], array($this, 'actionLoadPageHook_ManualOrder')); - - // FAQ Menu - add_action('load-' . $this->hooks['menu_faq'], array($this, 'actionLoadPageHook_faq')); - } - - /** - * Setup everything needed for the Overview page - */ - public function actionLoadPageHook_Overview() - { - // Add metaboxes - add_meta_box('avhecBoxCategoryGroupList', __('Group Overview', 'avh-ec'), array($this, 'metaboxCategoryGroupList'), $this->hooks['menu_overview'], 'normal', 'core'); - add_meta_box('avhecBoxTranslation', __('Translation', 'avh-ec'), array($this, 'metaboxTranslation'), $this->hooks['menu_overview'], 'normal', 'core'); - - add_screen_option('layout_columns', array('max' => 2, 'default' => 2)); - - // WordPress core Scripts - wp_enqueue_script('common'); - wp_enqueue_script('wp-lists'); - wp_enqueue_script('postbox'); - - // Plugin Scripts - wp_enqueue_script('avhec-categorygroup-js'); - - // Plugin Style - wp_enqueue_style('avhec-admin-css'); - } - - /** - * Menu Page Overview - * - * @return none - */ - public function doMenuOverview() - { - global $screen_layout_columns; - - // This box can't be unselectd in the the Screen Options - // add_meta_box('avhecBoxAnnouncements', __('Announcements', 'avh-ec'), array ( $this, 'metaboxAnnouncements' ), $this->hooks['menu_overview'], 'side', ''); - add_meta_box('avhecBoxDonations', __('Donations', 'avh-ec'), array($this, 'metaboxDonations'), $this->hooks['menu_overview'], 'side', ''); - - $hide2 = ''; - switch ($screen_layout_columns) { - case 2: - $width = 'width:49%;'; - break; - default: - $width = 'width:98%;'; - $hide2 = 'display:none;'; - } - - echo '<div class="wrap avhec-metabox-wrap">'; - echo $this->displayIcon('index'); - echo '<h2>' . 'AVH Extended Categories - ' . __('Overview', 'avh-ec') . '</h2>'; - echo ' <div id="dashboard-widgets-wrap">'; - echo ' <div id="dashboard-widgets" class="metabox-holder">'; - echo ' <div class="postbox-container" style="' . $width . '">' . "\n"; - do_meta_boxes($this->hooks['menu_overview'], 'normal', ''); - echo " </div>"; - echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n"; - do_meta_boxes($this->hooks['menu_overview'], 'side', ''); - echo ' </div>'; - echo ' </div>'; - - echo '<br class="clear"/>'; - echo ' </div>'; // dashboard-widgets-wrap - echo '</div>'; // wrap - - $this->printMetaboxGeneralNonces(); - $this->printMetaboxJS('overview'); - $this->printAdminFooter(); - } - - /** - * Setup everything needed for the General Options page - */ - public function actionLoadPageHook_General() - { - // Add metaboxes - add_meta_box('avhecBoxOptions', __('Options', 'avh-ec'), array($this, 'metaboxOptions'), $this->hooks['menu_general'], 'normal', 'core'); - - add_screen_option('layout_columns', array('max' => 2, 'default' => 2)); - - // WordPress core Scripts - wp_enqueue_script('common'); - wp_enqueue_script('wp-lists'); - wp_enqueue_script('postbox'); - - // Plugin Style and Scripts - wp_enqueue_style('avhec-admin-css'); - } - - /** - * Menu Page General Options - * - * @return none - */ - public function doMenuGeneral() - { - global $screen_layout_columns; - - $groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false)); - foreach ($groups as $group) { - $group_id[] = $group->term_id; - $groupname[] = $group->name; - } - - $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')); - $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')); - $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')); - $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')); - - if (isset($_POST['updateoptions'])) { - check_admin_referer('avh_ec_generaloptions'); - - $formoptions = $_POST['avhec']; - $options = $this->core->getOptions(); - - // $all_data = array_merge( $options_general ); - $all_data = $options_general; - foreach ($all_data as $option) { - $section = substr($option[0], strpos($option[0], '[') + 1); - $section = substr($section, 0, strpos($section, '][')); - $option_key = rtrim($option[0], ']'); - $option_key = substr($option_key, strpos($option_key, '][') + 2); - - switch ($section) { - case 'general': - case 'cat_group': - $current_value = $options[$section][$option_key]; - break; - } - // Every field in a form is set except unchecked checkboxes. Set an unchecked checkbox to 0. - $newval = (isset($formoptions[$section][$option_key]) ? esc_attr($formoptions[$section][$option_key]) : 0); - if ($newval != $current_value) { // Only process changed fields. - switch ($section) { - case 'general': - case 'cat_group': - $options[$section][$option_key] = $newval; - break; - } - } - } - $this->core->saveOptions($options); - $this->message = __('Options saved', 'avh-ec'); - $this->status = 'updated fade'; - } - $this->displayMessage(); - - $actual_options = $this->core->getOptions(); - foreach ($actual_options['cat_group'] as $key => $value) { - if (!(in_array($value, (array) $group_id))) { - $actual_options['cat_group'][$key] = $this->catgrp->getTermIDBy('slug', 'none'); - } - } - - $hide2 = ''; - switch ($screen_layout_columns) { - case 2: - $width = 'width:49%;'; - break; - default: - $width = 'width:98%;'; - $hide2 = 'display:none;'; - } - $data['options_general'] = $options_general; - $data['actual_options'] = $actual_options; - - // This box can't be unselectd in the the Screen Options - add_meta_box('avhecBoxDonations', __('Donations', 'avh-ec'), array($this, 'metaboxDonations'), $this->hooks['menu_general'], 'side', 'core'); - - $hide2 = ''; - switch ($screen_layout_columns) { - case 2: - $width = 'width:49%;'; - break; - default: - $width = 'width:98%;'; - $hide2 = 'display:none;'; - } - - echo '<div class="wrap avhec-metabox-wrap">'; - echo $this->displayIcon('index'); - echo '<h2>' . 'AVH Extended Categories - ' . __('General Options', 'avh-ec') . '</h2>'; - echo '<form name="avhec-generaloptions" id="avhec-generaloptions" method="POST" action="' . admin_url('admin.php?page=avhec-general') . '" accept-charset="utf-8" >'; - wp_nonce_field('avh_ec_generaloptions'); - - echo ' <div id="dashboard-widgets-wrap">'; - echo ' <div id="dashboard-widgets" class="metabox-holder">'; - echo ' <div class="postbox-container" style="' . $width . '">' . "\n"; - do_meta_boxes($this->hooks['menu_general'], 'normal', $data); - echo " </div>"; - echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n"; - do_meta_boxes($this->hooks['menu_general'], 'side', $data); - echo ' </div>'; - echo ' </div>'; - - echo '<br class="clear"/>'; - echo ' </div>'; // dashboard-widgets-wrap - echo '<p class="submit"><input class="button" type="submit" name="updateoptions" value="' . __('Save Changes', 'avhf-ec') . '" /></p>'; - echo '</form>'; - - echo '</div>'; // wrap - - $this->printMetaboxGeneralNonces(); - $this->printMetaboxJS('general'); - $this->printAdminFooter(); - } - - /** - * Options Metabox - */ - public function metaboxOptions($data) - { - echo $this->printOptions($data['options_general'], $data['actual_options']); - } - - /** - * Setup everything needed for the Category Group page - */ - public function actionLoadPageHook_CategoryGroup() - { - - // Add metaboxes - add_meta_box('avhecBoxCategoryGroupAdd', __('Add Group', 'avh-ec'), array($this, 'metaboxCategoryGroupAdd'), $this->hooks['menu_category_groups'], 'normal', 'core'); - add_meta_box('avhecBoxCategoryGroupList', __('Group Overview', 'avh-ec'), array($this, 'metaboxCategoryGroupList'), $this->hooks['menu_category_groups'], 'side', 'core'); - add_meta_box('avhecBoxCategoryGroupSpecialPages', __('Special Pages', 'avh-ec'), array($this, 'metaboxCategoryGroupSpecialPages'), $this->hooks['menu_category_groups'], 'normal', 'core'); - - add_screen_option('layout_columns', array('max' => 2, 'default' => 2)); - - // WordPress core Scripts - wp_enqueue_script('common'); - wp_enqueue_script('wp-lists'); - wp_enqueue_script('postbox'); - - // Plugin Scripts - wp_enqueue_script('avhec-categorygroup-js'); - - // Plugin Style - wp_enqueue_style('avhec-admin-css'); - } - - /** - * Menu Page Category Group - * - * @return none - */ - public function doMenuCategoryGroup() - { - global $screen_layout_columns; - - $data_add_group_default = array('name' => '', 'slug' => '', 'widget_title' => '', 'description' => ''); - $data_add_group_new = $data_add_group_default; - - $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')); - $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')); - $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')); - $options_add_group[] = array('avhec_add_group[add][description]', __('Description', 'avh-ec'), 'textarea', 40, __('Description is not prominent by default.', 'avh-ec'), 5); - - $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')); - $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')); - $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')); - $options_edit_group[] = array('avhec_edit_group[edit][description]', __('Description', 'avh-ec'), 'textarea', 40, __('Description is not prominent by default.', 'avh-ec'), 5); - $options_edit_group[] = array('avhec_edit_group[edit][categories]', __('Categories', 'avh-ec'), 'catlist', 0, __('Select categories to be included in the group.', 'avh-ec')); - - if (isset($_POST['addgroup'])) { - check_admin_referer('avh_ec_addgroup'); - - $formoptions = $_POST['avhec_add_group']; - - $data_add_group_new['name'] = $formoptions['add']['name']; - $data_add_group_new['slug'] = empty($formoptions['add']['slug']) ? sanitize_title($data_add_group_new['name']) : sanitize_title($formoptions['add']['slug']); - $data_add_group_new['widget_title'] = $formoptions['add']['widget_title']; - $data_add_group_new['description'] = $formoptions['add']['description']; - - $id = $this->catgrp->getTermIDBy('slug', $data_add_group_new['slug']); - if (!$id) { - $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']); - $this->catgrp->setCategoriesForGroup($group_id); - $this->message = __('Category group saved', 'avh-ec'); - $this->status = 'updated fade'; - $data_add_group_new = $data_add_group_default; - } else { - $group = $this->catgrp->getGroup($id); - $this->message = __('Category group conflicts with ', 'avh-ec') . $group->name; - $this->message .= '<br />' . __('Same slug is used. ', 'avh-ec'); - $this->status = 'error'; - } - $this->displayMessage(); - } - $data_add_group['add'] = $data_add_group_new; - $data['add'] = array('form' => $options_add_group, 'data' => $data_add_group); - - if (isset($_GET['action'])) { - $action = $_GET['action']; - - switch ($action) { - case 'edit': - $group_id = (int) $_GET['group_ID']; - $group = $this->catgrp->getGroup($group_id); - $widget_title = $this->catgrp->getWidgetTitleForGroup($group_id); - $cats = $this->catgrp->getCategoriesFromGroup($group_id); - - $data_edit_group['edit'] = array('group_id' => $group_id, 'name' => $group->name, 'slug' => $group->slug, 'widget_title' => $widget_title, 'description' => $group->description, 'categories' => $cats); - $data['edit'] = array('form' => $options_edit_group, 'data' => $data_edit_group); - - add_meta_box('avhecBoxCategoryGroupEdit', __('Edit Group', 'avh-ec') . ': ' . $group->name, array($this, 'metaboxCategoryGroupEdit'), $this->hooks['menu_category_groups'], 'normal', 'low'); - break; - case 'delete': - if (!isset($_GET['group_ID'])) { - wp_redirect($this->getBackLink()); - exit(); - } - - $group_id = (int) $_GET['group_ID']; - check_admin_referer('delete-avhecgroup_' . $group_id); - - if (!current_user_can('manage_categories')) { - wp_die(__('Cheatin’ uh?')); - } - $this->catgrp->doDeleteGroup($group_id); - break; - default: - ; - break; - } - } - - if (isset($_POST['editgroup'])) { - check_admin_referer('avh_ec_editgroup'); - - $formoptions = $_POST['avhec_edit_group']; - $selected_categories = $_POST['post_category']; - - $group_id = (int) $_POST['avhec-group_id']; - $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']); - switch ($result) { - case 1: - $this->message = __('Category group updated', 'avh-ec'); - $this->status = 'updated fade'; - break; - case 0: - $this->message = __('Category group not updated', 'avh-ec'); - $this->message .= '<br />' . __('Duplicate slug detected', 'avh-ec'); - $this->status = 'error'; - break; - case -1: - $this->message = __('Unknown category group', 'avh-ec'); - $this->status = 'error'; - break; - } - $this->displayMessage(); - } - - $hide2 = ''; - switch ($screen_layout_columns) { - case 2: - $width = 'width:49%;'; - break; - default: - $width = 'width:98%;'; - $hide2 = 'display:none;'; - } - - $data_special_pages_old = $this->core->options['sp_cat_group']; - $data_special_pages_new = $data_special_pages_old; - if (isset($_POST['avhec_special_pages'])) { - check_admin_referer('avh_ec_specialpagesgroup'); - - $formoptions = $_POST['avhec_special_pages']; - $formdata = $formoptions['sp']; - foreach ($formdata as $key => $value) { - $data_special_pages_new[$key] = $value; - } - $this->core->options['sp_cat_group'] = $data_special_pages_new; - $this->core->saveOptions($this->core->options); - } - $data_special_pages['sp'] = $data_special_pages_new; - $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false)); - - foreach ($cat_groups as $group) { - $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit'); - $dropdown_value[] = $group->term_id; - $dropdown_text[] = $temp_cat->name; - } - $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'))); - // $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'))); - $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'))); - $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'))); - $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'))); - $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'))); - $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'))); - - $data['sp'] = array('form' => $options_special_pages, 'data' => $data_special_pages); - - // This box can't be unselectd in the the Screen Options - // add_meta_box( 'avhecBoxDonations', __( 'Donations', 'avh-ec' ), array ($this, 'metaboxDonations' ), $this->hooks['menu_category_groups'], 'side', 'core' ); - - echo '<div class="wrap avhec-metabox-wrap">'; - echo $this->displayIcon('index'); - echo '<h2>' . 'AVH Extended Categories - ' . __('Category Groups', 'avh-ec') . '</h2>'; - - echo ' <div id="dashboard-widgets-wrap">'; - echo ' <div id="dashboard-widgets" class="metabox-holder">'; - - echo ' <div class="postbox-container" style="' . $width . '">' . "\n"; - do_meta_boxes($this->hooks['menu_category_groups'], 'normal', $data); - echo " </div>"; - - echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n"; - do_meta_boxes($this->hooks['menu_category_groups'], 'side', $data); - echo ' </div>'; - - echo ' </div>'; // dashboard-widgets - echo '<br class="clear" />'; - echo ' </div>'; // dashboard-widgets-wrap - echo '</div>'; // wrap - - $this->printMetaboxGeneralNonces(); - $this->printMetaboxJS('grouped'); - $this->printAdminFooter(); - } - - /** - * Metabox for Adding a group - * - * @param - * $data - */ - public function metaboxCategoryGroupAdd($data) - { - echo '<form name="avhec-addgroup" id="avhec-addgroup" method="POST" action="' . $this->getBackLink() . '" accept-charset="utf-8" >'; - wp_nonce_field('avh_ec_addgroup'); - echo $this->printOptions($data['add']['form'], $data['add']['data']); - echo '<p class="submit"><input class="button" type="submit" name="addgroup" value="' . __('Add group', 'avh-ec') . '" /></p>'; - echo '</form>'; - } - - /** - * Metabox for showing the groups as a list - * - * @param - * $data - */ - public function metaboxCategoryGroupList($data) - { - echo '<form id="posts-filter" action="" method="get">'; - - echo '<div class="clear"></div>'; - - echo '<table class="widefat fixed" cellspacing="0">'; - echo '<thead>'; - echo '<tr>'; - print_column_headers('categories_group'); - echo '</tr>'; - echo '</thead>'; - - echo '<tfoot>'; - echo '<tr>'; - print_column_headers('categories_group', false); - echo '</tr>'; - echo '</tfoot>'; - - echo '<tbody id="the-list" class="list:group">'; - $this->printCategoryGroupRows(); - echo '</tbody>'; - echo '</table>'; - - echo '<br class="clear" />'; - echo '</form>'; - - // echo '</div>'; - } - - /** - * Metabox Category Group Edit - */ - public function metaboxCategoryGroupEdit($data) - { - echo '<form name="avhec-editgroup" id="avhec-editgroup" method="POST" action="' . $this->getBackLink() . '" accept-charset="utf-8" >'; - wp_nonce_field('avh_ec_editgroup'); - echo $this->printOptions($data['edit']['form'], $data['edit']['data']); - echo '<input type="hidden" value="' . $data['edit']['data']['edit']['group_id'] . '" name="avhec-group_id" id="avhec-group_id">'; - echo '<p class="submit"><input class="button" type="submit" name="editgroup" value="' . __('Update group', 'avh-ec') . '" /></p>'; - echo '</form>'; - } - - /** - * Metabox Category Group Special pages - */ - public function metaboxCategoryGroupSpecialPages($data) - { - echo '<form name="avhec-specialpagesgroup" id="avhec-specialpagesgroup" method="POST" action="' . $this->getBackLink() . '" accept-charset="utf-8" >'; - wp_nonce_field('avh_ec_specialpagesgroup'); - echo $this->printOptions($data['sp']['form'], $data['sp']['data']); - echo '<p class="submit"><input class="button" type="submit" name="spgroup" value="' . __('Save settings', 'avh-ec') . '" /></p>'; - echo '</form>'; - } - - /** - * Setup everything needed for the Manul Order page - */ - public function actionLoadPageHook_ManualOrder() - { - add_meta_box('avhecBoxManualOrder', __('Manually Order Categories', 'avh-ec'), array($this, 'metaboxManualOrder'), $this->hooks['menu_manual_order'], 'normal', 'core'); - - add_screen_option('layout_columns', array('max' => 1, 'default' => 1)); - - // WordPress core Styles and Scripts - wp_enqueue_script('common'); - wp_enqueue_script('wp-lists'); - wp_enqueue_script('postbox'); - wp_enqueue_script('jquery-ui-sortable'); - wp_enqueue_script('avhec-manualorder'); - - // Plugin Style - wp_enqueue_style('avhec-admin-css'); - } - - /** - * Menu Page Manual Order - * - * @return none - */ - public function doMenuManualOrder() - { - global $screen_layout_columns; - - $hide2 = ''; - switch ($screen_layout_columns) { - case 2: - $width = 'width:49%;'; - break; - default: - $width = 'width:98%;'; - $hide2 = 'display:none;'; - } - - echo '<div class="wrap">'; - echo $this->displayIcon('index'); - echo '<h2>' . 'AVH Extended Categories - ' . __('Manually Order Categories', 'avh-ec') . '</h2>'; - - echo '<div class="metabox-holder">'; - echo ' <div class="postbox-container" style="' . $width . '">' . "\n"; - do_meta_boxes($this->hooks['menu_manual_order'], 'normal', ''); - echo ' </div>'; - echo '</div>'; - echo '</div>'; // wrap - echo '<div class="clear"></div>'; - - $this->printMetaboxGeneralNonces(); - $this->printMetaboxJS('manual_order'); - $this->printAdminFooter(); - } - - /** - * Displays the Manual Order metabox. - * - * @author Andrew Charlton - original - * @author Peter van der Does - modifications - */ - public function metaboxManualOrder() - { - global $wpdb; - - $parentID = 0; - - if (isset($_POST['btnSubCats'])) { - $parentID = $_POST['cats']; - } elseif (isset($_POST['hdnParentID'])) { - $parentID = $_POST['hdnParentID']; - } - - if (isset($_POST['btnReturnParent'])) { - $parentsParent = $wpdb->get_row($wpdb->prepare("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = %d", $_POST['hdnParentID']), ARRAY_N); - $parentID = $parentsParent[0]; - } - - $success = ""; - if (isset($_POST['btnOrderCats'])) { - if (isset($_POST['hdnManualOrder']) && $_POST['hdnManualOrder'] != "") { - - $manualOrder = $_POST['hdnManualOrder']; - $IDs = explode(",", $manualOrder); - $result = count($IDs); - - for ($i = 0; $i < $result; $i ++) { - $str = str_replace("id_", "", $IDs[$i]); - $wpdb->query($wpdb->prepare("UPDATE $wpdb->terms SET avhec_term_order = %d WHERE term_id =%d", $i, $str)); - } - - $success = '<div id="message" class="updated fade"><p>' . __('Manual order of the categories successfully updated.', 'avh-ec') . '</p></div>'; - } else { - $success = '<div id="message" class="updated fade"><p>' . __('An error occured, order has not been saved.', 'avh-ec') . '</p></div>'; - } - } - - $subCategories = ""; - $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)); - foreach ($results as $row) { - $subCategories .= "<option value='$row->term_id'>$row->name</option>"; - } - - echo '<div class="wrap">'; - echo '<form name="frmMyCatOrder" method="post" action="">'; - echo $success; - - echo '<h4>'; - _e('Order the categories', 'avh-ec'); - if ($parentID == 0) { - echo ' at the Toplevel'; - } else { - $categories = get_category_parents($parentID, false, ' » '); - echo ' in the category ' . trim($categories, ' » '); - } - echo '</h4>'; - echo '<span class="description">'; - _e('Order the categories on this level by dragging and dropping them into the desired order.', 'avh-ec'); - echo '</span>'; - echo '<ul id="avhecManualOrder">'; - $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)); - foreach ($results as $row) { - echo "<li id='id_$row->term_id' class='lineitem menu-item-settings'>" . __($row->name) . "</li>"; - } - echo '</ul>'; - echo '<input type="submit" name="btnOrderCats" id="btnOrderCats" class="button-primary" value="' . __('Save Order', 'avh-ec') . '" onclick="javascript:orderCats(); return true;" />'; - - if ($parentID != 0) { - echo "<input type='submit' class='button' id='btnReturnParent' name='btnReturnParent' value='" . __('Return to parent category', 'avh-ec') . "' />"; - } - - echo '<strong id="updateText"></strong><br /><br />'; - if ($subCategories != "") { - - echo '<h4>'; - _e('Select Subcategory', 'avh-ec'); - echo '</h4>'; - echo '<select id="cats" name="cats">'; - echo $subCategories; - - echo '</select><input type="submit" name="btnSubCats" class="button" id="btnSubCats" value="' . __('Select', 'avh-ec') . '" />'; - echo '<span class="description">'; - _e('Choose a category from the drop down to order the subcategories in that category.', 'avh-ec'); - echo '</span>'; - } - - echo '<input type="hidden" id="hdnManualOrder" name="hdnManualOrder" />'; - echo '<input type="hidden" id="hdnParentID" name="hdnParentID" value="' . $parentID . '" /></form>'; - echo '</div>'; - } - - /** - * Setup everything needed for the FAQ page - */ - public function actionLoadPageHook_faq() - { - add_meta_box('avhecBoxFAQ', __('F.A.Q.', 'avh-ec'), array($this, 'metaboxFAQ'), $this->hooks['menu_faq'], 'normal', 'core'); - add_meta_box('avhecBoxTranslation', __('Translation', 'avh-ec'), array($this, 'metaboxTranslation'), $this->hooks['menu_faq'], 'normal', 'core'); - - add_screen_option('layout_columns', array('max' => 2, 'default' => 2)); - - // WordPress core Styles and Scripts - wp_enqueue_script('common'); - wp_enqueue_script('wp-lists'); - wp_enqueue_script('postbox'); - - // Plugin Style - wp_enqueue_style('avhec-admin-css'); - } - - /** - * Menu Page FAQ - * - * @return none - */ - public function doMenuFAQ() - { - global $screen_layout_columns; - - // This box can't be unselectd in the the Screen Options - // add_meta_box('avhecBoxAnnouncements', __('Announcements', 'avh-ec'), array ( $this, 'metaboxAnnouncements' ), $this->hooks['menu_faq'], 'side', 'core'); - add_meta_box('avhecBoxDonations', __('Donations', 'avh-ec'), array($this, 'metaboxDonations'), $this->hooks['menu_faq'], 'side', 'core'); - - $hide2 = ''; - switch ($screen_layout_columns) { - case 2: - $width = 'width:49%;'; - break; - default: - $width = 'width:98%;'; - $hide2 = 'display:none;'; - } - - echo '<div class="wrap avhec-metabox-wrap">'; - echo $this->displayIcon('index'); - echo '<h2>' . 'AVH Extended Categories - ' . __('F.A.Q', 'avh-ec') . '</h2>'; - echo ' <div id="dashboard-widgets-wrap">'; - echo ' <div id="dashboard-widgets" class="metabox-holder">'; - echo ' <div class="postbox-container" style="' . $width . '">' . "\n"; - do_meta_boxes($this->hooks['menu_faq'], 'normal', ''); - echo ' </div>'; - echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n"; - do_meta_boxes($this->hooks['menu_faq'], 'side', ''); - echo ' </div>'; - echo ' </div>'; - echo '<br class="clear"/>'; - echo ' </div>'; // dashboard-widgets-wrap - echo '</div>'; // wrap - - $this->printMetaboxGeneralNonces(); - $this->printMetaboxJS('faq'); - $this->printAdminFooter(); - } - - /** - * Translation Metabox - * - * @return unknown_type - */ - public function metaboxTranslation() - { - $locale = apply_filters('plugin_locale', get_locale(), 'avh-ec'); - $available_locale['cs_CZ'] = array('Czech - Čeština', 0); - $available_locale['nl_NL'] = array('Dutch - Nederlands', 0); - $available_locale['de_DE'] = array('German - Deutsch', 0); - $available_locale['el'] = array('Greek - Čeština', 0); - $available_locale['id_ID'] = array('Indonesian - Bahasa Indonesia - Čeština', 0); - $available_locale['it_IT'] = array('Italian - Italiano', 1); - $available_locale['ru_RU'] = array('Russian — Русский', 0); - $available_locale['es_ES'] = array('Spanish - Español', 0); - $available_locale['sv_SE'] = array('Swedish - Svenska', 0); - $available_locale['tr'] = array('Turkish - Türkçe', 0); - - echo '<div class="p">'; - 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 />'; - - echo '</div>'; - - echo '<div class="p">'; - echo '<span class="b">' . __('Available Languages', 'avh-ec') . '</span>'; - echo '<ul>'; - foreach ($available_locale as $key => $value) { - echo '<li>'; - $complete = ($value[1] == 1 ? 'Complete' : 'Incomplete'); - echo $value[0] . ' (' . $key . ') - ' . $complete; - echo '</li>'; - } - echo '</ul>'; - echo '</div>'; - - echo '<div class="p">'; - if ('en_US' != $locale & (!array_key_exists($locale, $available_locale))) { - 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.'; - } else { - 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.'; - } - echo '</div>'; - } - - /** - * Donation Metabox - * - * @return unknown_type - */ - public function metaboxDonations() - { - echo '<div class="p">'; - echo __('If you enjoy this plug-in please consider a donation. There are several ways you can show your appreciation.', 'avh-ec'); - echo '</div>'; - - echo '<div class="p">'; - echo '<span class="b">Amazon</span><br />'; - echo __('If you decide to buy something from Amazon click the button.', 'avh-ec') . '</span><br />'; - 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>'; - echo '</div>'; - - echo '<div class="p">'; - 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>'; - echo '</div>'; - - echo '<div class="p">'; - echo '<span class="b">' . __('Through Paypal.', 'avh-ec') . '</span><br />'; - 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 />'; - 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">'; - echo '<img src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" alt="Donate"/></a>'; - echo '</div>'; - } - - /** - * * - * F.A.Q Metabox - * - * @return none - */ - public function metaboxFAQ() - { - echo '<div class="p">'; - echo '<span class="b">' . __('What about support?', 'avh-ec') . '</span><br />'; - 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 />'; - echo '</div>'; - - echo '<div class="p">'; - echo '<span class="b">' . __('What is depth selection?', 'avh-ec') . '</span><br />'; - 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 />'; - 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 />'; - 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 />'; - echo '</div>'; - - echo '<div class="p">'; - echo '<span class="b">' . __('Multiple Category Groups', 'avh-ec') . '</span><br />'; - echo __('The following is an explanation how assigning multiple groups to page/post works.', 'avh-ec') . '<br /><br />'; - echo __('Lets say you have the following groups:', 'avh-ec'); - echo '<ul>'; - echo '<li>' . __('Free Time', 'avh-ec') . '</li>'; - echo '<li>' . __('Theater', 'avh-ec') . '</li>'; - echo '<li>' . __('Movie', 'avh-ec') . '</li>'; - echo '<li>' . __('Music', 'avh-ec') . '</li>'; - echo '</ul>'; - echo __('Setup several Category Group widgets and associated each widget with one or more groups.', 'avh-ec') . '<br />'; - echo __('Widget 1 has association with Free Time', 'avh-ec') . '<br />'; - echo __('Widget 2 has association with Theater, Movie and Music', 'avh-ec') . '<br />'; - echo __('Widget 3 has association with Theater, Movie and Music', 'avh-ec') . '<br /><br />'; - echo __('Page has associations the groups Free Time and Theater', 'avh-ec'); - echo '<ul>'; - echo '<li>' . __('Widget 1: Shows categories of the Free Time group', 'avh-ec') . '</li>'; - echo '<li>' . __('Widget 2: Shows categories of the Theater group.', 'avh-ec') . '</li>'; - echo '<li>' . __('Widget 3: Not displayed', 'avh-ec') . '</li>'; - echo '</ul>'; - echo __('Page has associations the group Movie.', 'avh-ec'); - echo '<ul>'; - echo '<li>' . __('Widget 1: Not displayed', 'avh-ec') . '</li>'; - echo '<li>' . __('Widget 2: Shows categories of the Movie group.', 'avh-ec') . '</li>'; - echo '<li>' . __('Widget 3: Not displayed', 'avh-ec') . '</li>'; - echo '</ul>'; - echo __('Page has associations the groups Free Time, Movie and Music', 'avh-ec'); - echo '<ul>'; - echo '<li>' . __('Widget 1: Shows categories of the Free Time group', 'avh-ec') . '</li>'; - echo '<li>' . __('Widget 2: Shows categories of the Movie or Music group.', 'avh-ec') . '</li>'; - echo '<li>' . __('Widget 3: Shows categories of the Music or Movie group.', 'avh-ec') . '</li>'; - echo '</ul>'; - 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 />'; - echo '</div>'; - } - - public function metaboxAnnouncements() - { - $php5 = version_compare('5.2', phpversion(), '<'); - echo '<div class="p">'; - echo '<span class="b">' . __('PHP4 Support', 'avh-ec') . '</span><br />'; - echo __('The next major release of the plugin will no longer support PHP4.', 'avh-ec') . '<br />'; - echo __('It will be written for PHP 5.2 and ', 'avh-ec'); - if ($php5) { - echo __('your blog already runs the needed PHP version. When the new release comes out you can safely update.', 'avh-ec') . '<br />'; - } else { - echo __('your blog still runs PHP4. When the new release comes out you can not use it.', 'avh-ec') . '<br />'; - 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 />'; - echo __('If your hosts doesn\'t offer PHP 5.2 you might want to consider switching hosts.', 'avh-ec') . '<br />'; - echo __('A host to consider is ', 'avh-ec') . '<a href="http://www.lunarpages.com/id/pdoes" target="_blank">Lunarpages</a>'; - 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'); - } - echo '</div>'; - } - - /** - * Sets the amount of columns wanted for a particuler screen - * - * @WordPress filter screen_meta_screen - * - * @param - * $screen - * @return strings - */ - public function filterScreenLayoutColumns($columns, $screen) - { - switch ($screen) { - case $this->hooks['menu_overview']: - $columns[$this->hooks['menu_overview']] = 2; - break; - case $this->hooks['menu_general']: - $columns[$this->hooks['menu_general']] = 2; - break; - case $this->hooks['menu_category_groups']: - $columns[$this->hooks['menu_category_groups']] = 2; - break; - case $this->hooks['menu_faq']: - $columns[$this->hooks['menu_faq']] = 2; - break; - } - - return $columns; - } - - /** - * Adds Settings next to the plugin actions - * - * @WordPress Filter plugin_action_links_avh-amazon/avh-amazon.php - */ - public function filterPluginActions($links, $file) - { - $settings_link = '<a href="admin.php?page=extended-categories-widget">' . __('Settings', 'avh-ec') . '</a>'; - array_unshift($links, $settings_link); // before other links - - return $links; - } - - /** - * Creates a new array for columns headers. - * Used in print_column_headers. The filter is called from get_column_headers - * - * @param - * $columns - * @return Array - * @see print_column_headers, get_column_headers - */ - public function filterManageCategoriesGroupColumns($columns) - { - $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')); - - return $categories_group_columns; - } - - /** - * When not using AJAX, this function is called when the deletion fails. - * - * @param string $text - * @param int $group_id - * @return string @WordPress Filter explain_nonce_$verb-$noun - * @see wp_explain_nonce - */ - public function filterExplainNonceDeleteGroup($text, $group_id) - { - $group = get_term($group_id, $this->catgrp->taxonomy_name, OBJECT, 'display'); - - $return = sprintf(__('Your attempt to delete this group: “%s” has failed.'), $group->name); - - return ($return); - } - - // ############ Admin WP Helper ############## - - /** - * Get the backlink for forms - * - * @return strings - */ - public function getBackLink() - { - $page = basename(__FILE__); - if (isset($_GET['page']) && !empty($_GET['page'])) { - $page = preg_replace('[^a-zA-Z0-9\.\_\-]', '', $_GET['page']); - } - - if (function_exists("admin_url")) { - return admin_url(basename($_SERVER["PHP_SELF"])) . "?page=" . $page; - } else { - return $_SERVER['PHP_SELF'] . "?page=" . $page; - } - } - - /** - * Print all Category Group rows - * - * @uses printCategoryGroupRow - * - */ - public function printCategoryGroupRows() - { - $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false)); - - foreach ($cat_groups as $group) { - if ('none' != $group->slug) { - echo $this->printCategoryGroupRow($group->term_id, $group->term_taxonomy_id); - } - } - } - - /** - * Displays all the information of a group in a row - * Adds inline link for delete and/or edit. - * - * @param int $group_term_id - * @param int $group_term_taxonomy_id - */ - public function printCategoryGroupRow($group_term_id, $group_term_taxonomy_id) - { - static $row_class = ''; - - $group = get_term($group_term_id, $this->catgrp->taxonomy_name, OBJECT, 'display'); - - $no_edit[$this->catgrp->getTermIDBy('slug', 'all')] = 0; - $no_delete[$this->catgrp->getTermIDBy('slug', 'all')] = 0; - - if (current_user_can('manage_categories')) { - $actions = array(); - if (!array_key_exists($group->term_id, $no_edit)) { - $edit_link = "admin.php?page=avhec-grouped&action=edit&group_ID=$group->term_id"; - $edit = "<a class='row-title' href='$edit_link' title='" . esc_attr(sprintf(__('Edit “%s”'), $group->name)) . "'>" . esc_attr($group->name) . '</a><br />'; - - $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>'; - } else { - $edit = esc_attr($group->name); - } - if (!(array_key_exists($group->term_id, $no_delete))) { - $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>"; - } - $action_count = count($actions); - $i = 0; - $edit .= '<div class="row-actions">'; - foreach ($actions as $action => $link) { - ++ $i; - ($i == $action_count) ? $sep = '' : $sep = ' | '; - $edit .= "<span class='$action'>$link$sep</span>"; - } - $edit .= '</div>'; - } else { - $edit = $group->name; - } - - $row_class = 'alternate' == $row_class ? '' : 'alternate'; - $qe_data = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit'); - - $output = "<tr id='group-$group->term_id' class='iedit $row_class'>"; - - $columns = get_column_headers('categories_group'); - $hidden = get_hidden_columns('categories_group'); - foreach ($columns as $column_name => $column_display_name) { - $class = 'class="' . $column_name . ' column-' . $column_name . '"'; - - $style = ''; - if (in_array($column_name, $hidden)) { - $style = ' style="display:none;"'; - } - - $attributes = $class . $style; - - switch ($column_name) { - case 'cb': - $output .= '<th scope="row" class="check-column">'; - if (!(array_key_exists($group->term_id, $no_delete))) { - $output .= '<input type="checkbox" name="delete[]" value="' . $group->term_id . '" />'; - } else { - $output .= " "; - } - $output .= '</th>'; - break; - case 'name': - $output .= '<td ' . $attributes . '>' . $edit; - $output .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">'; - $output .= '<div class="name">' . $qe_data->name . '</div>'; - $output .= '<div class="slug">' . apply_filters('editable_slug', $qe_data->slug) . '</div>'; - $output .= '</div></td>'; - break; - case 'widget-title': - $title = $this->catgrp->getWidgetTitleForGroup($group->term_id); - if (!$title) { - $title = " "; - } - $output .= '<td ' . $attributes . '>' . $title . '</td>'; - break; - - case 'description': - $output .= '<td ' . $attributes . '>' . $qe_data->description . '</td>'; - break; - case 'slug': - $output .= "<td $attributes>" . apply_filters('editable_slug', $qe_data->slug) . "</td>"; - break; - case 'cat-in-group': - $cats = $this->catgrp->getCategoriesFromGroup($group_term_id); - $catname = array(); - foreach ($cats as $cat_id) { - $catname[] = get_cat_name($cat_id); - } - natsort($catname); - $cat = implode(', ', $catname); - $output .= '<td ' . $attributes . '>' . $cat . '</td>'; - break; - } - } - $output .= '</tr>'; - - return $output; - } - - /** - * Prints the general nonces, used by the AJAX - */ - public function printMetaboxGeneralNonces() - { - echo '<form style="display:none" method="get" action="">'; - echo '<p>'; - wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); - wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); - echo '</p>'; - echo '</form>'; - } - - /** - * Print the Metabox JS for toggling closed and open - * - * @param - * $boxid - */ - public function printMetaboxJS($boxid) - { - $a = $this->hooks['menu_' . $boxid]; - echo '<script type="text/javascript">' . "\n"; - echo ' //<![CDATA[' . "\n"; - echo ' jQuery(document).ready( function($) {' . "\n"; - echo ' $(\'.if-js-closed\').removeClass(\'if-js-closed\').addClass(\'closed\');' . "\n"; - echo ' // postboxes setup' . "\n"; - echo ' postboxes.add_postbox_toggles(\'' . $a . '\');' . "\n"; - echo ' });' . "\n"; - echo ' //]]>' . "\n"; - echo '</script>'; - } - - /** - * Display plugin Copyright - */ - public function printAdminFooter() - { - echo '<p class="footer_avhec">'; - 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); - echo '</p>'; - } - - /** - * Display WP alert - */ - public function displayMessage() - { - if ($this->message != '') { - $message = $this->message; - $status = $this->status; - $this->message = $this->status = ''; // Reset - } - if (isset($message)) { - $status = ($status != '') ? $status : 'updated fade'; - echo '<div id="message" class="' . $status . '">'; - echo '<p><strong>' . $message . '</strong></p></div>'; - } - } - - /** - * Ouput formatted options - * - * @param array $option_data - * @return string - */ - public function printOptions($option_data, $option_actual) - { - // Generate output - $output = ''; - $output .= "\n" . '<table class="form-table avhec-options">' . "\n"; - foreach ($option_data as $option) { - $section = substr($option[0], strpos($option[0], '[') + 1); - $section = substr($section, 0, strpos($section, '][')); - $option_key = rtrim($option[0], ']'); - $option_key = substr($option_key, strpos($option_key, '][') + 2); - // Helper - if ($option[2] == 'helper') { - $output .= '<tr style="vertical-align: top;"><td class="helper" colspan="2">' . wp_filter_post_kses($option[4]) . '</td></tr>' . "\n"; - continue; - } - switch ($option[2]) { - case 'checkbox': - $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"; - $explanation = $option[4]; - break; - case 'dropdown': - $selvalue = $option[3]; - $seltext = $option[4]; - $seldata = ''; - foreach ((array) $selvalue as $key => $sel) { - $seldata .= '<option value="' . esc_attr($sel) . '" ' . (($option_actual[$section][$option_key] == $sel) ? 'selected="selected"' : '') . ' >' . esc_html(ucfirst($seltext[$key])) . '</option>' . "\n"; - } - $input_type = '<select id="' . esc_attr($option[0]) . '" name="' . esc_attr($option[0]) . '">' . $seldata . '</select>' . "\n"; - $explanation = $option[5]; - break; - case 'text-color': - $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"; - $explanation = $option[4]; - break; - case 'textarea': - $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>'; - $explanation = $option[4]; - break; - case 'catlist': - ob_start(); - echo '<div id="avhec-catlist">'; - echo '<ul>'; - wp_category_checklist(0, 0, $option_actual[$section][$option_key]); - echo '</ul>'; - echo '</div>'; - $input_type = ob_get_contents(); - ob_end_clean(); - $explanation = $option[4]; - break; - case 'text': - default: - $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"; - $explanation = $option[4]; - break; - } - // Additional Information - $extra = ''; - if ($explanation) { - $extra = '<br /><span class="description">' . wp_filter_kses($explanation) . '</span>' . "\n"; - } - // Output - $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"; - } - $output .= '</table>' . "\n"; - - return $output; - } - - /** - * Used in forms to set an option checked - * - * @param mixed $checked - * @param mixed $current - * @return strings - */ - public function isChecked($checked, $current) - { - $return = ''; - if ($checked == $current) { - $return = ' checked="checked"'; - } - - return $return; - } - - /** - * Displays the icon on the menu pages - * - * @param - * $icon - */ - public function displayIcon($icon) - { - return ('<div class="icon32" id="icon-' . $icon . '"><br/></div>'); - } - - /** - * Ajax Helper: inline delete of the groups - */ - public function ajaxDeleteGroup() - { - $group_id = isset($_POST['id']) ? (int) $_POST['id'] : 0; - check_ajax_referer('delete-avhecgroup_' . $group_id); - - if (!current_user_can('manage_categories')) { - die('-1'); - } - $check = $this->catgrp->getGroup($group_id); - if (false === $check) { - die('1'); - } - - if ($this->catgrp->doDeleteGroup($group_id)) { - die('1'); - } else { - die('0'); - } - } +class AVH_EC_Admin { + /** + * @var AVH_EC_Category_Group + */ + public $catgrp; + /** + * @var AVH_EC_Core + */ + public $core; + public $hooks = array(); + public $message; + + /** + * PHP5 constructor + */ + public function __construct() { + + // Initialize the plugin + $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core'); + $this->catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); + + add_action('wp_ajax_delete-group', array($this, 'ajaxDeleteGroup')); + + // Admin menu + add_action('admin_init', array($this, 'actionAdminInit')); + add_action('admin_menu', array($this, 'actionAdminMenu')); + add_filter('plugin_action_links_extended-categories-widget/widget_extended_categories.php', + array($this, 'filterPluginActions'), + 10, + 2); + + // Actions used for editing posts + add_action('load-post.php', array($this, 'actionLoadPostPage')); + add_action('load-page.php', array($this, 'actionLoadPostPage')); + + // Actions related to adding and deletes categories + add_action('created_category', array($this, 'actionCreatedCategory'), 10, 2); + add_action('delete_category', array($this, 'actionDeleteCategory'), 10, 2); + + add_filter('manage_categories_group_columns', array($this, 'filterManageCategoriesGroupColumns')); + add_filter('explain_nonce_delete-avhecgroup', array($this, 'filterExplainNonceDeleteGroup'), 10, 2); + + return; + } + + public function actionAdminInit() { + if (is_admin() && isset($_GET['taxonomy']) && 'category' == $_GET['taxonomy']) { + add_action($_GET['taxonomy'] . '_edit_form', array($this, 'displayCategoryGroupForm'), 10, 2); + } + add_action('edit_term', array($this, 'handleEditTerm'), 10, 3); + } + + /** + * Add the Tools and Options to the Management and Options page repectively + * + * @WordPress Action admin_menu + */ + public function actionAdminMenu() { + + // Register Style and Scripts + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; + wp_register_script('avhec-categorygroup-js', + AVHEC_PLUGIN_URL . '/js/avh-ec.categorygroup' . $suffix . '.js', + array('jquery'), + $this->core->version, + true); + wp_register_script('avhec-manualorder', + AVHEC_PLUGIN_URL . '/js/avh-ec.admin.manualorder' . $suffix . '.js', + array('jquery-ui-sortable'), + $this->core->version, + false); + wp_register_style('avhec-admin-css', + AVHEC_PLUGIN_URL . '/css/avh-ec.admin.css', + array('wp-admin'), + $this->core->version, + 'screen'); + + // Add menu system + $folder = $this->core->getBaseDirectory(AVHEC_PLUGIN_DIR); + add_menu_page('AVH Extended Categories', + 'AVH Extended Categories', + 'manage_options', + $folder, + array($this, 'doMenuOverview')); + $this->hooks['menu_overview'] = add_submenu_page($folder, + 'AVH Extended Categories: ' . __('Overview', 'avh-ec'), + __('Overview', 'avh-ec'), + 'manage_options', + $folder, + array($this, 'doMenuOverview')); + $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')); + $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')); + $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')); + $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')); + + // Add actions for menu pages + // Overview Menu + add_action('load-' . $this->hooks['menu_overview'], array($this, 'actionLoadPageHook_Overview')); + + // General Options Menu + add_action('load-' . $this->hooks['menu_general'], array($this, 'actionLoadPageHook_General')); + + // Category Groups Menu + add_action('load-' . $this->hooks['menu_category_groups'], array($this, 'actionLoadPageHook_CategoryGroup')); + + // Manual Order Menu + add_action('load-' . $this->hooks['menu_manual_order'], array($this, 'actionLoadPageHook_ManualOrder')); + + // FAQ Menu + add_action('load-' . $this->hooks['menu_faq'], array($this, 'actionLoadPageHook_faq')); + } + + /** + * When a category is created this function is called to add the new category to the group all + * + * @param int $term_id + * @param int $term_taxonomy_id + */ + public function actionCreatedCategory($term_id, $term_taxonomy_id) { + $group_id = $this->catgrp->getTermIDBy('slug', 'all'); + $this->catgrp->setCategoriesForGroup($group_id, (array) $term_id); + } + + /** + * When a category is deleted this function is called so the category is deleted from every group as well. + * + * @param int $term_id + * @param int $term_taxonomy_id + * + * @internal param object $term + */ + public function actionDeleteCategory($term_id, $term_taxonomy_id) { + $this->catgrp->doDeleteCategoryFromGroup($term_id); + } + + /** + * Setup everything needed for the Category Group page + */ + public function actionLoadPageHook_CategoryGroup() { + + // Add metaboxes + add_meta_box('avhecBoxCategoryGroupAdd', + __('Add Group', 'avh-ec'), + array($this, 'metaboxCategoryGroupAdd'), + $this->hooks['menu_category_groups'], + 'normal', + 'core'); + add_meta_box('avhecBoxCategoryGroupList', + __('Group Overview', 'avh-ec'), + array($this, 'metaboxCategoryGroupList'), + $this->hooks['menu_category_groups'], + 'side', + 'core'); + add_meta_box('avhecBoxCategoryGroupSpecialPages', + __('Special Pages', 'avh-ec'), + array($this, 'metaboxCategoryGroupSpecialPages'), + $this->hooks['menu_category_groups'], + 'normal', + 'core'); + + add_screen_option('layout_columns', array('max' => 2, 'default' => 2)); + + // WordPress core Scripts + wp_enqueue_script('common'); + wp_enqueue_script('wp-lists'); + wp_enqueue_script('postbox'); + + // Plugin Scripts + wp_enqueue_script('avhec-categorygroup-js'); + + // Plugin Style + wp_enqueue_style('avhec-admin-css'); + } + + /** + * Setup everything needed for the General Options page + */ + public function actionLoadPageHook_General() { + // Add metaboxes + add_meta_box('avhecBoxOptions', + __('Options', 'avh-ec'), + array($this, 'metaboxOptions'), + $this->hooks['menu_general'], + 'normal', + 'core'); + + add_screen_option('layout_columns', array('max' => 2, 'default' => 2)); + + // WordPress core Scripts + wp_enqueue_script('common'); + wp_enqueue_script('wp-lists'); + wp_enqueue_script('postbox'); + + // Plugin Style and Scripts + wp_enqueue_style('avhec-admin-css'); + } + + /** + * Setup everything needed for the Manul Order page + */ + public function actionLoadPageHook_ManualOrder() { + add_meta_box('avhecBoxManualOrder', + __('Manually Order Categories', 'avh-ec'), + array($this, 'metaboxManualOrder'), + $this->hooks['menu_manual_order'], + 'normal', + 'core'); + + add_screen_option('layout_columns', array('max' => 1, 'default' => 1)); + + // WordPress core Styles and Scripts + wp_enqueue_script('common'); + wp_enqueue_script('wp-lists'); + wp_enqueue_script('postbox'); + wp_enqueue_script('jquery-ui-sortable'); + wp_enqueue_script('avhec-manualorder'); + + // Plugin Style + wp_enqueue_style('avhec-admin-css'); + } + + /** + * Setup everything needed for the Overview page + */ + public function actionLoadPageHook_Overview() { + // Add metaboxes + add_meta_box('avhecBoxCategoryGroupList', + __('Group Overview', 'avh-ec'), + array($this, 'metaboxCategoryGroupList'), + $this->hooks['menu_overview'], + 'normal', + 'core'); + add_meta_box('avhecBoxTranslation', + __('Translation', 'avh-ec'), + array($this, 'metaboxTranslation'), + $this->hooks['menu_overview'], + 'normal', + 'core'); + + add_screen_option('layout_columns', array('max' => 2, 'default' => 2)); + + // WordPress core Scripts + wp_enqueue_script('common'); + wp_enqueue_script('wp-lists'); + wp_enqueue_script('postbox'); + + // Plugin Scripts + wp_enqueue_script('avhec-categorygroup-js'); + + // Plugin Style + wp_enqueue_style('avhec-admin-css'); + } + + /** + * Setup everything needed for the FAQ page + */ + public function actionLoadPageHook_faq() { + add_meta_box('avhecBoxFAQ', + __('F.A.Q.', 'avh-ec'), + array($this, 'metaboxFAQ'), + $this->hooks['menu_faq'], + 'normal', + 'core'); + add_meta_box('avhecBoxTranslation', + __('Translation', 'avh-ec'), + array($this, 'metaboxTranslation'), + $this->hooks['menu_faq'], + 'normal', + 'core'); + + add_screen_option('layout_columns', array('max' => 2, 'default' => 2)); + + // WordPress core Styles and Scripts + wp_enqueue_script('common'); + wp_enqueue_script('wp-lists'); + wp_enqueue_script('postbox'); + + // Plugin Style + wp_enqueue_style('avhec-admin-css'); + } + + /** + * Enqueues the style on the post.php and page.php pages + * + * @WordPress Action load-$pagenow + */ + public function actionLoadPostPage() { + wp_enqueue_style('avhec-admin-css'); + } + + /** + * Ajax Helper: inline delete of the groups + */ + public function ajaxDeleteGroup() { + $group_id = isset($_POST['id']) ? (int) $_POST['id'] : 0; + check_ajax_referer('delete-avhecgroup_' . $group_id); + + if ( ! current_user_can('manage_categories')) { + die('-1'); + } + $check = $this->catgrp->getGroup($group_id); + if (false === $check) { + die('1'); + } + + if ($this->catgrp->doDeleteGroup($group_id)) { + die('1'); + } else { + die('0'); + } + } + + /** + * Adds Category Group form + * + * @WordPress action category_edit_form + * + * @param object $term + * @param string $taxonomy + */ + public function displayCategoryGroupForm($term, $taxonomy) { + $current_selection = ''; + $tax_meta = get_option($this->core->db_options_tax_meta); + if (isset($tax_meta[ $taxonomy ][ $term->term_id ])) { + $tax_meta = $tax_meta[ $taxonomy ][ $term->term_id ]; + $current_selection = $tax_meta['category_group_term_id']; + } + + if (empty($current_selection)) { + $current_group = $this->catgrp->getGroupByCategoryID($term->term_id); + $current_selection = $current_group->term_id; + } + + $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false)); + foreach ($cat_groups as $group) { + $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit'); + $dropdown_value[] = $group->term_id; + $dropdown_text[] = $temp_cat->name; + } + + $seldata = ''; + foreach ($dropdown_value as $key => $sel) { + $seldata .= '<option value="' . + esc_attr($sel) . + '" ' . + (($current_selection == $sel) ? 'selected="selected"' : '') . + ' >' . + esc_html(ucfirst($dropdown_text[ $key ])) . + '</option>' . + "\n"; + } + + echo '<h3>AVH Extended Categories - Category Group Widget</h3>'; + echo '<table class="form-table"><tbody>'; + echo '<tr class="form-field">'; + echo '<th valign="top" scope="row">'; + echo '<label for="avhec_categorygroup">Category Group</label></th>'; + echo '<td>'; + echo '<select id="avhec_categorygroup" name="avhec_categorygroup">'; + echo $seldata; + echo '</select>'; + echo '<p class="description">Select the category group to show on the archive page.</p>'; + echo '</td>'; + echo '</tr>'; + echo '</tbody></table>'; + } + + /** + * Displays the icon on the menu pages + * + * @param string $icon + * + * @return string + */ + public function displayIcon($icon) { + return ('<div class="icon32" id="icon-' . $icon . '"><br/></div>'); + } + + /** + * Display WP alert + */ + public function displayMessage() { + if ($this->message != '') { + $message = $this->message; + $status = $this->status; + $this->message = $this->status = ''; // Reset + } + if (isset($message)) { + $status = ($status != '') ? $status : 'updated fade'; + echo '<div id="message" class="' . $status . '">'; + echo '<p><strong>' . $message . '</strong></p></div>'; + } + } + + /** + * Menu Page Category Group + * + * @return void + */ + public function doMenuCategoryGroup() { + global $screen_layout_columns; + + $data_add_group_default = array('name' => '', 'slug' => '', 'widget_title' => '', 'description' => ''); + $data_add_group_new = $data_add_group_default; + + $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') + ); + $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') + ); + $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') + ); + $options_add_group[] = array( + 'avhec_add_group[add][description]', + __('Description', 'avh-ec'), + 'textarea', + 40, + __('Description is not prominent by default.', 'avh-ec'), + 5 + ); + + $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') + ); + $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') + ); + $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') + ); + $options_edit_group[] = array( + 'avhec_edit_group[edit][description]', + __('Description', 'avh-ec'), + 'textarea', + 40, + __('Description is not prominent by default.', 'avh-ec'), + 5 + ); + $options_edit_group[] = array( + 'avhec_edit_group[edit][categories]', + __('Categories', 'avh-ec'), + 'catlist', + 0, + __('Select categories to be included in the group.', 'avh-ec') + ); + + if (isset($_POST['addgroup'])) { + check_admin_referer('avh_ec_addgroup'); + + $formoptions = $_POST['avhec_add_group']; + + $data_add_group_new['name'] = $formoptions['add']['name']; + $data_add_group_new['slug'] = empty($formoptions['add']['slug']) ? sanitize_title($data_add_group_new['name']) : sanitize_title($formoptions['add']['slug']); + $data_add_group_new['widget_title'] = $formoptions['add']['widget_title']; + $data_add_group_new['description'] = $formoptions['add']['description']; + + $id = $this->catgrp->getTermIDBy('slug', $data_add_group_new['slug']); + if ( ! $id) { + $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']); + $this->catgrp->setCategoriesForGroup($group_id); + $this->message = __('Category group saved', 'avh-ec'); + $this->status = 'updated fade'; + $data_add_group_new = $data_add_group_default; + } else { + $group = $this->catgrp->getGroup($id); + $this->message = __('Category group conflicts with ', 'avh-ec') . $group->name; + $this->message .= '<br />' . __('Same slug is used. ', 'avh-ec'); + $this->status = 'error'; + } + $this->displayMessage(); + } + $data_add_group['add'] = $data_add_group_new; + $data['add'] = array('form' => $options_add_group, 'data' => $data_add_group); + + if (isset($_GET['action'])) { + $action = $_GET['action']; + + switch ($action) { + case 'edit': + $group_id = (int) $_GET['group_ID']; + $group = $this->catgrp->getGroup($group_id); + $widget_title = $this->catgrp->getWidgetTitleForGroup($group_id); + $cats = $this->catgrp->getCategoriesFromGroup($group_id); + + $data_edit_group['edit'] = array( + 'group_id' => $group_id, + 'name' => $group->name, + 'slug' => $group->slug, + 'widget_title' => $widget_title, + 'description' => $group->description, + 'categories' => $cats + ); + $data['edit'] = array('form' => $options_edit_group, 'data' => $data_edit_group); + + add_meta_box('avhecBoxCategoryGroupEdit', + __('Edit Group', 'avh-ec') . ': ' . $group->name, + array($this, 'metaboxCategoryGroupEdit'), + $this->hooks['menu_category_groups'], + 'normal', + 'low'); + break; + case 'delete': + if ( ! isset($_GET['group_ID'])) { + wp_redirect($this->getBackLink()); + exit(); + } + + $group_id = (int) $_GET['group_ID']; + check_admin_referer('delete-avhecgroup_' . $group_id); + + if ( ! current_user_can('manage_categories')) { + wp_die(__('Cheatin’ uh?')); + } + $this->catgrp->doDeleteGroup($group_id); + break; + default: + ; + break; + } + } + + if (isset($_POST['editgroup'])) { + check_admin_referer('avh_ec_editgroup'); + + $formoptions = $_POST['avhec_edit_group']; + $selected_categories = $_POST['post_category']; + + $group_id = (int) $_POST['avhec-group_id']; + $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']); + switch ($result) { + case 1: + $this->message = __('Category group updated', 'avh-ec'); + $this->status = 'updated fade'; + break; + case 0: + $this->message = __('Category group not updated', 'avh-ec'); + $this->message .= '<br />' . __('Duplicate slug detected', 'avh-ec'); + $this->status = 'error'; + break; + case - 1: + $this->message = __('Unknown category group', 'avh-ec'); + $this->status = 'error'; + break; + } + $this->displayMessage(); + } + + $hide2 = ''; + switch ($screen_layout_columns) { + case 2: + $width = 'width:49%;'; + break; + default: + $width = 'width:98%;'; + $hide2 = 'display:none;'; + } + + $data_special_pages_old = $this->core->options['sp_cat_group']; + $data_special_pages_new = $data_special_pages_old; + if (isset($_POST['avhec_special_pages'])) { + check_admin_referer('avh_ec_specialpagesgroup'); + + $formoptions = $_POST['avhec_special_pages']; + $formdata = $formoptions['sp']; + foreach ($formdata as $key => $value) { + $data_special_pages_new[ $key ] = $value; + } + $this->core->options['sp_cat_group'] = $data_special_pages_new; + $this->core->saveOptions($this->core->options); + } + $data_special_pages['sp'] = $data_special_pages_new; + $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false)); + + foreach ($cat_groups as $group) { + $temp_cat = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit'); + $dropdown_value[] = $group->term_id; + $dropdown_text[] = $temp_cat->name; + } + $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')) + ); + // $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'))); + $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')) + ); + $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')) + ); + $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')) + ); + $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')) + ); + $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')) + ); + + $data['sp'] = array('form' => $options_special_pages, 'data' => $data_special_pages); + + // This box can't be unselectd in the the Screen Options + // add_meta_box( 'avhecBoxDonations', __( 'Donations', 'avh-ec' ), array ($this, 'metaboxDonations' ), $this->hooks['menu_category_groups'], 'side', 'core' ); + + echo '<div class="wrap avhec-metabox-wrap">'; + echo $this->displayIcon('index'); + echo '<h2>' . 'AVH Extended Categories - ' . __('Category Groups', 'avh-ec') . '</h2>'; + + echo ' <div id="dashboard-widgets-wrap">'; + echo ' <div id="dashboard-widgets" class="metabox-holder">'; + + echo ' <div class="postbox-container" style="' . $width . '">' . "\n"; + do_meta_boxes($this->hooks['menu_category_groups'], 'normal', $data); + echo " </div>"; + + echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n"; + do_meta_boxes($this->hooks['menu_category_groups'], 'side', $data); + echo ' </div>'; + + echo ' </div>'; // dashboard-widgets + echo '<br class="clear" />'; + echo ' </div>'; // dashboard-widgets-wrap + echo '</div>'; // wrap + + $this->printMetaboxGeneralNonces(); + $this->printMetaboxJS('grouped'); + $this->printAdminFooter(); + } + + /** + * Menu Page FAQ + * + * @return none + */ + public function doMenuFAQ() { + global $screen_layout_columns; + + // This box can't be unselectd in the the Screen Options + // add_meta_box('avhecBoxAnnouncements', __('Announcements', 'avh-ec'), array ( $this, 'metaboxAnnouncements' ), $this->hooks['menu_faq'], 'side', 'core'); + add_meta_box('avhecBoxDonations', + __('Donations', 'avh-ec'), + array($this, 'metaboxDonations'), + $this->hooks['menu_faq'], + 'side', + 'core'); + + $hide2 = ''; + switch ($screen_layout_columns) { + case 2: + $width = 'width:49%;'; + break; + default: + $width = 'width:98%;'; + $hide2 = 'display:none;'; + } + + echo '<div class="wrap avhec-metabox-wrap">'; + echo $this->displayIcon('index'); + echo '<h2>' . 'AVH Extended Categories - ' . __('F.A.Q', 'avh-ec') . '</h2>'; + echo ' <div id="dashboard-widgets-wrap">'; + echo ' <div id="dashboard-widgets" class="metabox-holder">'; + echo ' <div class="postbox-container" style="' . $width . '">' . "\n"; + do_meta_boxes($this->hooks['menu_faq'], 'normal', ''); + echo ' </div>'; + echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n"; + do_meta_boxes($this->hooks['menu_faq'], 'side', ''); + echo ' </div>'; + echo ' </div>'; + echo '<br class="clear"/>'; + echo ' </div>'; // dashboard-widgets-wrap + echo '</div>'; // wrap + + $this->printMetaboxGeneralNonces(); + $this->printMetaboxJS('faq'); + $this->printAdminFooter(); + } + + /** + * Menu Page General Options + * + * @return void + */ + public function doMenuGeneral() { + global $screen_layout_columns; + + $groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false)); + foreach ($groups as $group) { + $group_id[] = $group->term_id; + $groupname[] = $group->name; + } + + $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') + ); + $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') + ); + $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') + ); + $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') + ); + + if (isset($_POST['updateoptions'])) { + check_admin_referer('avh_ec_generaloptions'); + + $formoptions = $_POST['avhec']; + $options = $this->core->getOptions(); + + // $all_data = array_merge( $options_general ); + $all_data = $options_general; + foreach ($all_data as $option) { + $section = substr($option[0], strpos($option[0], '[') + 1); + $section = substr($section, 0, strpos($section, '][')); + $option_key = rtrim($option[0], ']'); + $option_key = substr($option_key, strpos($option_key, '][') + 2); + + switch ($section) { + case 'general': + case 'cat_group': + $current_value = $options[ $section ][ $option_key ]; + break; + } + // Every field in a form is set except unchecked checkboxes. Set an unchecked checkbox to 0. + $newval = (isset($formoptions[ $section ][ $option_key ]) ? esc_attr($formoptions[ $section ][ $option_key ]) : 0); + if ($newval != $current_value) { // Only process changed fields. + switch ($section) { + case 'general': + case 'cat_group': + $options[ $section ][ $option_key ] = $newval; + break; + } + } + } + $this->core->saveOptions($options); + $this->message = __('Options saved', 'avh-ec'); + $this->status = 'updated fade'; + } + $this->displayMessage(); + + $actual_options = $this->core->getOptions(); + foreach ($actual_options['cat_group'] as $key => $value) { + if ( ! (in_array($value, (array) $group_id))) { + $actual_options['cat_group'][ $key ] = $this->catgrp->getTermIDBy('slug', 'none'); + } + } + + $hide2 = ''; + switch ($screen_layout_columns) { + case 2: + $width = 'width:49%;'; + break; + default: + $width = 'width:98%;'; + $hide2 = 'display:none;'; + } + $data['options_general'] = $options_general; + $data['actual_options'] = $actual_options; + + // This box can't be unselectd in the the Screen Options + add_meta_box('avhecBoxDonations', + __('Donations', 'avh-ec'), + array($this, 'metaboxDonations'), + $this->hooks['menu_general'], + 'side', + 'core'); + + $hide2 = ''; + switch ($screen_layout_columns) { + case 2: + $width = 'width:49%;'; + break; + default: + $width = 'width:98%;'; + $hide2 = 'display:none;'; + } + + echo '<div class="wrap avhec-metabox-wrap">'; + echo $this->displayIcon('index'); + echo '<h2>' . 'AVH Extended Categories - ' . __('General Options', 'avh-ec') . '</h2>'; + echo '<form name="avhec-generaloptions" id="avhec-generaloptions" method="POST" action="' . + admin_url('admin.php?page=avhec-general') . + '" accept-charset="utf-8" >'; + wp_nonce_field('avh_ec_generaloptions'); + + echo ' <div id="dashboard-widgets-wrap">'; + echo ' <div id="dashboard-widgets" class="metabox-holder">'; + echo ' <div class="postbox-container" style="' . $width . '">' . "\n"; + do_meta_boxes($this->hooks['menu_general'], 'normal', $data); + echo " </div>"; + echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n"; + do_meta_boxes($this->hooks['menu_general'], 'side', $data); + echo ' </div>'; + echo ' </div>'; + + echo '<br class="clear"/>'; + echo ' </div>'; // dashboard-widgets-wrap + echo '<p class="submit"><input class="button" type="submit" name="updateoptions" value="' . + __('Save Changes', 'avhf-ec') . + '" /></p>'; + echo '</form>'; + + echo '</div>'; // wrap + + $this->printMetaboxGeneralNonces(); + $this->printMetaboxJS('general'); + $this->printAdminFooter(); + } + + /** + * Menu Page Manual Order + * + * @return void + */ + public function doMenuManualOrder() { + global $screen_layout_columns; + + $hide2 = ''; + switch ($screen_layout_columns) { + case 2: + $width = 'width:49%;'; + break; + default: + $width = 'width:98%;'; + $hide2 = 'display:none;'; + } + + echo '<div class="wrap">'; + echo $this->displayIcon('index'); + echo '<h2>' . 'AVH Extended Categories - ' . __('Manually Order Categories', 'avh-ec') . '</h2>'; + + echo '<div class="metabox-holder">'; + echo ' <div class="postbox-container" style="' . $width . '">' . "\n"; + do_meta_boxes($this->hooks['menu_manual_order'], 'normal', ''); + echo ' </div>'; + echo '</div>'; + echo '</div>'; // wrap + echo '<div class="clear"></div>'; + + $this->printMetaboxGeneralNonces(); + $this->printMetaboxJS('manual_order'); + $this->printAdminFooter(); + } + + /** + * Menu Page Overview + * + * @return void + */ + public function doMenuOverview() { + global $screen_layout_columns; + + // This box can't be unselectd in the the Screen Options + // add_meta_box('avhecBoxAnnouncements', __('Announcements', 'avh-ec'), array ( $this, 'metaboxAnnouncements' ), $this->hooks['menu_overview'], 'side', ''); + add_meta_box('avhecBoxDonations', + __('Donations', 'avh-ec'), + array($this, 'metaboxDonations'), + $this->hooks['menu_overview'], + 'side', + ''); + + $hide2 = ''; + switch ($screen_layout_columns) { + case 2: + $width = 'width:49%;'; + break; + default: + $width = 'width:98%;'; + $hide2 = 'display:none;'; + } + + echo '<div class="wrap avhec-metabox-wrap">'; + echo $this->displayIcon('index'); + echo '<h2>' . 'AVH Extended Categories - ' . __('Overview', 'avh-ec') . '</h2>'; + echo ' <div id="dashboard-widgets-wrap">'; + echo ' <div id="dashboard-widgets" class="metabox-holder">'; + echo ' <div class="postbox-container" style="' . $width . '">' . "\n"; + do_meta_boxes($this->hooks['menu_overview'], 'normal', ''); + echo " </div>"; + echo ' <div class="postbox-container" style="' . $hide2 . $width . '">' . "\n"; + do_meta_boxes($this->hooks['menu_overview'], 'side', ''); + echo ' </div>'; + echo ' </div>'; + + echo '<br class="clear"/>'; + echo ' </div>'; // dashboard-widgets-wrap + echo '</div>'; // wrap + + $this->printMetaboxGeneralNonces(); + $this->printMetaboxJS('overview'); + $this->printAdminFooter(); + } + + /** + * When not using AJAX, this function is called when the deletion fails. + * + * @param string $text + * @param int $group_id + * + * @return string + * @WordPress Filter explain_nonce_$verb-$noun + * @see wp_explain_nonce + */ + public function filterExplainNonceDeleteGroup($text, $group_id) { + $group = get_term($group_id, $this->catgrp->taxonomy_name, OBJECT, 'display'); + + $return = sprintf(__('Your attempt to delete this group: “%s” has failed.'), $group->name); + + return ($return); + } + + /** + * Creates a new array for columns headers. + * Used in print_column_headers. The filter is called from get_column_headers + * + * @param array $columns + * + * @return Array + * @see print_column_headers, get_column_headers + */ + public function filterManageCategoriesGroupColumns($columns) { + $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') + ); + + return $categories_group_columns; + } + + /** + * Adds Settings next to the plugin actions + * + * @WordPress Filter plugin_action_links_avh-amazon/avh-amazon.php + * + * @param array $links + * @param string $file + * + * @return array + */ + public function filterPluginActions($links, $file) { + $settings_link = '<a href="admin.php?page=extended-categories-widget">' . __('Settings', 'avh-ec') . '</a>'; + array_unshift($links, $settings_link); // before other links + + return $links; + } + + /** + * Sets the amount of columns wanted for a particular screen + * + * @WordPress filter screen_meta_screen + * + * @param array $columns + * @param string $screen + * + * @return array + */ + public function filterScreenLayoutColumns($columns, $screen) { + switch ($screen) { + case $this->hooks['menu_overview']: + $columns[ $this->hooks['menu_overview'] ] = 2; + break; + case $this->hooks['menu_general']: + $columns[ $this->hooks['menu_general'] ] = 2; + break; + case $this->hooks['menu_category_groups']: + $columns[ $this->hooks['menu_category_groups'] ] = 2; + break; + case $this->hooks['menu_faq']: + $columns[ $this->hooks['menu_faq'] ] = 2; + break; + } + + return $columns; + } + + /** + * Get the backlink for forms + * + * @return string + */ + public function getBackLink() { + $page = basename(__FILE__); + if (isset($_GET['page']) && ! empty($_GET['page'])) { + $page = preg_replace('[^a-zA-Z0-9\.\_\-]', '', $_GET['page']); + } + + if (function_exists("admin_url")) { + return admin_url(basename($_SERVER["PHP_SELF"])) . "?page=" . $page; + } else { + return $_SERVER['PHP_SELF'] . "?page=" . $page; + } + } + + /** + * Saves the association Category - Category Group fron the edit taxonomy page + * + * @WordPress action edit_form. + * + * @param int $term_id + * @param int $tt_id + * @param string $taxonomy + */ + public function handleEditTerm($term_id, $tt_id, $taxonomy) { + $tax_meta = get_option($this->core->db_options_tax_meta); + if (isset($_POST['avhec_categorygroup'])) { + if (term_exists($_POST['avhec_categorygroup'], $this->catgrp->taxonomy_name) !== null) { + if ( ! isset($tax_meta[ $taxonomy ][ $term_id ]['category_group_term_id']) || + $tax_meta[ $taxonomy ][ $term_id ]['category_group_term_id'] != $_POST['avhec_categorygroup'] + ) { + $tax_meta[ $taxonomy ][ $term_id ]['category_group_term_id'] = $_POST['avhec_categorygroup']; + update_option($this->core->db_options_tax_meta, $tax_meta); + } + } + } + } + + /** + * Used in forms to set an option checked + * + * @param string $checked + * @param string $current + * + * @return string + */ + public function isChecked($checked, $current) { + $return = ''; + if ($checked == $current) { + $return = ' checked="checked"'; + } + + return $return; + } + + public function metaboxAnnouncements() { + $php5 = version_compare('5.2', phpversion(), '<'); + echo '<div class="p">'; + echo '<span class="b">' . __('PHP4 Support', 'avh-ec') . '</span><br />'; + echo __('The next major release of the plugin will no longer support PHP4.', 'avh-ec') . '<br />'; + echo __('It will be written for PHP 5.2 and ', 'avh-ec'); + if ($php5) { + echo __('your blog already runs the needed PHP version. When the new release comes out you can safely update.', + 'avh-ec') . '<br />'; + } else { + echo __('your blog still runs PHP4. When the new release comes out you can not use it.', 'avh-ec') . + '<br />'; + 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 />'; + echo __('If your hosts doesn\'t offer PHP 5.2 you might want to consider switching hosts.', 'avh-ec') . + '<br />'; + echo __('A host to consider is ', 'avh-ec') . + '<a href="http://www.lunarpages.com/id/pdoes" target="_blank">Lunarpages</a>'; + 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'); + } + echo '</div>'; + } + + /** + * Metabox for Adding a group + * + * @param array $data + */ + public function metaboxCategoryGroupAdd($data) { + echo '<form name="avhec-addgroup" id="avhec-addgroup" method="POST" action="' . + $this->getBackLink() . + '" accept-charset="utf-8" >'; + wp_nonce_field('avh_ec_addgroup'); + echo $this->printOptions($data['add']['form'], $data['add']['data']); + echo '<p class="submit"><input class="button" type="submit" name="addgroup" value="' . + __('Add group', 'avh-ec') . + '" /></p>'; + echo '</form>'; + } + + /** + * Metabox Category Group Edit + * + * @param array $data + */ + public function metaboxCategoryGroupEdit($data) { + echo '<form name="avhec-editgroup" id="avhec-editgroup" method="POST" action="' . + $this->getBackLink() . + '" accept-charset="utf-8" >'; + wp_nonce_field('avh_ec_editgroup'); + echo $this->printOptions($data['edit']['form'], $data['edit']['data']); + echo '<input type="hidden" value="' . + $data['edit']['data']['edit']['group_id'] . + '" name="avhec-group_id" id="avhec-group_id">'; + echo '<p class="submit"><input class="button" type="submit" name="editgroup" value="' . + __('Update group', 'avh-ec') . + '" /></p>'; + echo '</form>'; + } + + /** + * Metabox for showing the groups as a list + * + * @param array $data + */ + public function metaboxCategoryGroupList($data) { + echo '<form id="posts-filter" action="" method="get">'; + + echo '<div class="clear"></div>'; + + echo '<table class="widefat fixed" cellspacing="0">'; + echo '<thead>'; + echo '<tr>'; + print_column_headers('categories_group'); + echo '</tr>'; + echo '</thead>'; + + echo '<tfoot>'; + echo '<tr>'; + print_column_headers('categories_group', false); + echo '</tr>'; + echo '</tfoot>'; + + echo '<tbody id="the-list" class="list:group">'; + $this->printCategoryGroupRows(); + echo '</tbody>'; + echo '</table>'; + + echo '<br class="clear" />'; + echo '</form>'; + // echo '</div>'; + } + + /** + * Metabox Category Group Special pages + * + * @param array $data + */ + public function metaboxCategoryGroupSpecialPages($data) { + echo '<form name="avhec-specialpagesgroup" id="avhec-specialpagesgroup" method="POST" action="' . + $this->getBackLink() . + '" accept-charset="utf-8" >'; + wp_nonce_field('avh_ec_specialpagesgroup'); + echo $this->printOptions($data['sp']['form'], $data['sp']['data']); + echo '<p class="submit"><input class="button" type="submit" name="spgroup" value="' . + __('Save settings', 'avh-ec') . + '" /></p>'; + echo '</form>'; + } + + // ############ Admin WP Helper ############## + + /** + * Donation Metabox + */ + public function metaboxDonations() { + echo '<div class="p">'; + echo __('If you enjoy this plug-in please consider a donation. There are several ways you can show your appreciation.', + 'avh-ec'); + echo '</div>'; + + echo '<div class="p">'; + echo '<span class="b">Amazon</span><br />'; + echo __('If you decide to buy something from Amazon click the button.', 'avh-ec') . '</span><br />'; + echo '<a href="https://www.amazon.com/?tag=petervanderdoes-20" target="_blank" title="Amazon Homepage"><img alt="Amazon Button" src="' . + $this->core->info['graphics_url'] . + '/us_banner_logow_120x60.gif" /></a>'; + echo '</div>'; + + echo '<div class="p">'; + echo __('You can send me something from my ', 'avh-ec') . + '<a href="http://www.amazon.com/registry/wishlist/1U3DTWZ72PI7W?tag=petervanderdoes-20">' . + __('Amazon Wish List', 'avh-ec') . + '</a>'; + echo '</div>'; + + echo '<div class="p">'; + echo '<span class="b">' . __('Through Paypal.', 'avh-ec') . '</span><br />'; + 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 />'; + 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">'; + echo '<img src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" alt="Donate"/></a>'; + echo '</div>'; + } + + /** + * * + * F.A.Q Metabox + */ + public function metaboxFAQ() { + echo '<div class="p">'; + echo '<span class="b">' . __('What about support?', 'avh-ec') . '</span><br />'; + 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 />'; + echo '</div>'; + + echo '<div class="p">'; + echo '<span class="b">' . __('What is depth selection?', 'avh-ec') . '</span><br />'; + 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 />'; + 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 />'; + 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 />'; + echo '</div>'; + + echo '<div class="p">'; + echo '<span class="b">' . __('Multiple Category Groups', 'avh-ec') . '</span><br />'; + echo __('The following is an explanation how assigning multiple groups to page/post works.', 'avh-ec') . + '<br /><br />'; + echo __('Lets say you have the following groups:', 'avh-ec'); + echo '<ul>'; + echo '<li>' . __('Free Time', 'avh-ec') . '</li>'; + echo '<li>' . __('Theater', 'avh-ec') . '</li>'; + echo '<li>' . __('Movie', 'avh-ec') . '</li>'; + echo '<li>' . __('Music', 'avh-ec') . '</li>'; + echo '</ul>'; + echo __('Setup several Category Group widgets and associated each widget with one or more groups.', 'avh-ec') . + '<br />'; + echo __('Widget 1 has association with Free Time', 'avh-ec') . '<br />'; + echo __('Widget 2 has association with Theater, Movie and Music', 'avh-ec') . '<br />'; + echo __('Widget 3 has association with Theater, Movie and Music', 'avh-ec') . '<br /><br />'; + echo __('Page has associations the groups Free Time and Theater', 'avh-ec'); + echo '<ul>'; + echo '<li>' . __('Widget 1: Shows categories of the Free Time group', 'avh-ec') . '</li>'; + echo '<li>' . __('Widget 2: Shows categories of the Theater group.', 'avh-ec') . '</li>'; + echo '<li>' . __('Widget 3: Not displayed', 'avh-ec') . '</li>'; + echo '</ul>'; + echo __('Page has associations the group Movie.', 'avh-ec'); + echo '<ul>'; + echo '<li>' . __('Widget 1: Not displayed', 'avh-ec') . '</li>'; + echo '<li>' . __('Widget 2: Shows categories of the Movie group.', 'avh-ec') . '</li>'; + echo '<li>' . __('Widget 3: Not displayed', 'avh-ec') . '</li>'; + echo '</ul>'; + echo __('Page has associations the groups Free Time, Movie and Music', 'avh-ec'); + echo '<ul>'; + echo '<li>' . __('Widget 1: Shows categories of the Free Time group', 'avh-ec') . '</li>'; + echo '<li>' . __('Widget 2: Shows categories of the Movie or Music group.', 'avh-ec') . '</li>'; + echo '<li>' . __('Widget 3: Shows categories of the Music or Movie group.', 'avh-ec') . '</li>'; + echo '</ul>'; + 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 />'; + echo '</div>'; + } + + /** + * Displays the Manual Order metabox. + * + * @author Andrew Charlton - original + * @author Peter van der Does - modifications + */ + public function metaboxManualOrder() { + global $wpdb; + + $parentID = 0; + + if (isset($_POST['btnSubCats'])) { + $parentID = $_POST['cats']; + } elseif (isset($_POST['hdnParentID'])) { + $parentID = $_POST['hdnParentID']; + } + + if (isset($_POST['btnReturnParent'])) { + $parentsParent = $wpdb->get_row($wpdb->prepare("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = %d", + $_POST['hdnParentID']), + ARRAY_N); + $parentID = $parentsParent[0]; + } + + $success = ""; + if (isset($_POST['btnOrderCats'])) { + if (isset($_POST['hdnManualOrder']) && $_POST['hdnManualOrder'] != "") { + + $manualOrder = $_POST['hdnManualOrder']; + $IDs = explode(",", $manualOrder); + $result = count($IDs); + + for ($i = 0; $i < $result; $i ++) { + $str = str_replace("id_", "", $IDs[ $i ]); + $wpdb->query($wpdb->prepare("UPDATE $wpdb->terms SET avhec_term_order = %d WHERE term_id =%d", + $i, + $str)); + } + + $success = '<div id="message" class="updated fade"><p>' . + __('Manual order of the categories successfully updated.', 'avh-ec') . + '</p></div>'; + } else { + $success = '<div id="message" class="updated fade"><p>' . + __('An error occured, order has not been saved.', 'avh-ec') . + '</p></div>'; + } + } + + $subCategories = ""; + $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)); + foreach ($results as $row) { + $subCategories .= "<option value='$row->term_id'>$row->name</option>"; + } + + echo '<div class="wrap">'; + echo '<form name="frmMyCatOrder" method="post" action="">'; + echo $success; + + echo '<h4>'; + _e('Order the categories', 'avh-ec'); + if ($parentID == 0) { + echo ' at the Toplevel'; + } else { + $categories = get_category_parents($parentID, false, ' » '); + echo ' in the category ' . trim($categories, ' » '); + } + echo '</h4>'; + echo '<span class="description">'; + _e('Order the categories on this level by dragging and dropping them into the desired order.', 'avh-ec'); + echo '</span>'; + echo '<ul id="avhecManualOrder">'; + $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)); + foreach ($results as $row) { + echo "<li id='id_$row->term_id' class='lineitem menu-item-settings'>" . __($row->name) . "</li>"; + } + echo '</ul>'; + echo '<input type="submit" name="btnOrderCats" id="btnOrderCats" class="button-primary" value="' . + __('Save Order', 'avh-ec') . + '" onclick="javascript:orderCats(); return true;" />'; + + if ($parentID != 0) { + echo "<input type='submit' class='button' id='btnReturnParent' name='btnReturnParent' value='" . + __('Return to parent category', 'avh-ec') . + "' />"; + } + + echo '<strong id="updateText"></strong><br /><br />'; + if ($subCategories != "") { + + echo '<h4>'; + _e('Select Subcategory', 'avh-ec'); + echo '</h4>'; + echo '<select id="cats" name="cats">'; + echo $subCategories; + + echo '</select><input type="submit" name="btnSubCats" class="button" id="btnSubCats" value="' . + __('Select', 'avh-ec') . + '" />'; + echo '<span class="description">'; + _e('Choose a category from the drop down to order the subcategories in that category.', 'avh-ec'); + echo '</span>'; + } + + echo '<input type="hidden" id="hdnManualOrder" name="hdnManualOrder" />'; + echo '<input type="hidden" id="hdnParentID" name="hdnParentID" value="' . $parentID . '" /></form>'; + echo '</div>'; + } + + /** + * Options Metabox + * + * @param array $data + */ + public function metaboxOptions($data) { + echo $this->printOptions($data['options_general'], $data['actual_options']); + } + + /** + * Translation Metabox + */ + public function metaboxTranslation() { + $locale = apply_filters('plugin_locale', get_locale(), 'avh-ec'); + $available_locale['cs_CZ'] = array('Czech - Čeština', 0); + $available_locale['nl_NL'] = array('Dutch - Nederlands', 0); + $available_locale['de_DE'] = array('German - Deutsch', 0); + $available_locale['el'] = array('Greek - Čeština', 0); + $available_locale['id_ID'] = array('Indonesian - Bahasa Indonesia - Čeština', 0); + $available_locale['it_IT'] = array('Italian - Italiano', 1); + $available_locale['ru_RU'] = array('Russian — Русский', 0); + $available_locale['es_ES'] = array('Spanish - Español', 0); + $available_locale['sv_SE'] = array('Swedish - Svenska', 0); + $available_locale['tr'] = array('Turkish - Türkçe', 0); + + echo '<div class="p">'; + 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 />'; + + echo '</div>'; + + echo '<div class="p">'; + echo '<span class="b">' . __('Available Languages', 'avh-ec') . '</span>'; + echo '<ul>'; + foreach ($available_locale as $key => $value) { + echo '<li>'; + $complete = ($value[1] == 1 ? 'Complete' : 'Incomplete'); + echo $value[0] . ' (' . $key . ') - ' . $complete; + echo '</li>'; + } + echo '</ul>'; + echo '</div>'; + + echo '<div class="p">'; + if ('en_US' != $locale & ( ! array_key_exists($locale, $available_locale))) { + 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.'; + } else { + 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.'; + } + echo '</div>'; + } + + /** + * Display plugin Copyright + */ + public function printAdminFooter() { + echo '<p class="footer_avhec">'; + 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); + echo '</p>'; + } + + /** + * Displays all the information of a group in a row + * Adds inline link for delete and/or edit. + * + * @param int $group_term_id + * @param int $group_term_taxonomy_id + * + * @return string + */ + public function printCategoryGroupRow($group_term_id, $group_term_taxonomy_id) { + static $row_class = ''; + + $group = get_term($group_term_id, $this->catgrp->taxonomy_name, OBJECT, 'display'); + + $no_edit[ $this->catgrp->getTermIDBy('slug', 'all') ] = 0; + $no_delete[ $this->catgrp->getTermIDBy('slug', 'all') ] = 0; + + if (current_user_can('manage_categories')) { + $actions = array(); + if ( ! array_key_exists($group->term_id, $no_edit)) { + $edit_link = "admin.php?page=avhec-grouped&action=edit&group_ID=$group->term_id"; + $edit = "<a class='row-title' href='$edit_link' title='" . + esc_attr(sprintf(__('Edit “%s”'), $group->name)) . + "'>" . + esc_attr($group->name) . + '</a><br />'; + + $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>'; + } else { + $edit = esc_attr($group->name); + } + if ( ! (array_key_exists($group->term_id, $no_delete))) { + $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>"; + } + $action_count = count($actions); + $i = 0; + $edit .= '<div class="row-actions">'; + foreach ($actions as $action => $link) { + ++ $i; + ($i == $action_count) ? $sep = '' : $sep = ' | '; + $edit .= "<span class='$action'>$link$sep</span>"; + } + $edit .= '</div>'; + } else { + $edit = $group->name; + } + + $row_class = 'alternate' == $row_class ? '' : 'alternate'; + $qe_data = get_term($group->term_id, $this->catgrp->taxonomy_name, OBJECT, 'edit'); + + $output = "<tr id='group-$group->term_id' class='iedit $row_class'>"; + + $columns = get_column_headers('categories_group'); + $hidden = get_hidden_columns('categories_group'); + foreach ($columns as $column_name => $column_display_name) { + $class = 'class="' . $column_name . ' column-' . $column_name . '"'; + + $style = ''; + if (in_array($column_name, $hidden)) { + $style = ' style="display:none;"'; + } + + $attributes = $class . $style; + + switch ($column_name) { + case 'cb': + $output .= '<th scope="row" class="check-column">'; + if ( ! (array_key_exists($group->term_id, $no_delete))) { + $output .= '<input type="checkbox" name="delete[]" value="' . $group->term_id . '" />'; + } else { + $output .= " "; + } + $output .= '</th>'; + break; + case 'name': + $output .= '<td ' . $attributes . '>' . $edit; + $output .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">'; + $output .= '<div class="name">' . $qe_data->name . '</div>'; + $output .= '<div class="slug">' . apply_filters('editable_slug', $qe_data->slug) . '</div>'; + $output .= '</div></td>'; + break; + case 'widget-title': + $title = $this->catgrp->getWidgetTitleForGroup($group->term_id); + if ( ! $title) { + $title = " "; + } + $output .= '<td ' . $attributes . '>' . $title . '</td>'; + break; + + case 'description': + $output .= '<td ' . $attributes . '>' . $qe_data->description . '</td>'; + break; + case 'slug': + $output .= "<td $attributes>" . apply_filters('editable_slug', $qe_data->slug) . "</td>"; + break; + case 'cat-in-group': + $cats = $this->catgrp->getCategoriesFromGroup($group_term_id); + $catname = array(); + foreach ($cats as $cat_id) { + $catname[] = get_cat_name($cat_id); + } + natsort($catname); + $cat = implode(', ', $catname); + $output .= '<td ' . $attributes . '>' . $cat . '</td>'; + break; + } + } + $output .= '</tr>'; + + return $output; + } + + /** + * Print all Category Group rows + * + * @uses printCategoryGroupRow + */ + public function printCategoryGroupRows() { + $cat_groups = get_terms($this->catgrp->taxonomy_name, array('hide_empty' => false)); + + foreach ($cat_groups as $group) { + if ('none' != $group->slug) { + echo $this->printCategoryGroupRow($group->term_id, $group->term_taxonomy_id); + } + } + } + + /** + * Prints the general nonces, used by the AJAX + */ + public function printMetaboxGeneralNonces() { + echo '<form style="display:none" method="get" action="">'; + echo '<p>'; + wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); + wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); + echo '</p>'; + echo '</form>'; + } + + /** + * Print the Metabox JS for toggling closed and open + * + * @param int $boxid + */ + public function printMetaboxJS($boxid) { + $a = $this->hooks[ 'menu_' . $boxid ]; + echo '<script type="text/javascript">' . "\n"; + echo ' //<![CDATA[' . "\n"; + echo ' jQuery(document).ready( function($) {' . "\n"; + echo ' $(\'.if-js-closed\').removeClass(\'if-js-closed\').addClass(\'closed\');' . "\n"; + echo ' // postboxes setup' . "\n"; + echo ' postboxes.add_postbox_toggles(\'' . $a . '\');' . "\n"; + echo ' });' . "\n"; + echo ' //]]>' . "\n"; + echo '</script>'; + } + + /** + * Ouput formatted options + * + * @param array $option_data + * @param array $option_actual + * + * @return string + */ + public function printOptions($option_data, $option_actual) { + // Generate output + $output = ''; + $output .= "\n" . '<table class="form-table avhec-options">' . "\n"; + foreach ($option_data as $option) { + $section = substr($option[0], strpos($option[0], '[') + 1); + $section = substr($section, 0, strpos($section, '][')); + $option_key = rtrim($option[0], ']'); + $option_key = substr($option_key, strpos($option_key, '][') + 2); + // Helper + if ($option[2] == 'helper') { + $output .= '<tr style="vertical-align: top;"><td class="helper" colspan="2">' . + wp_filter_post_kses($option[4]) . + '</td></tr>' . + "\n"; + continue; + } + switch ($option[2]) { + case 'checkbox': + $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"; + $explanation = $option[4]; + break; + case 'dropdown': + $selvalue = $option[3]; + $seltext = $option[4]; + $seldata = ''; + foreach ((array) $selvalue as $key => $sel) { + $seldata .= '<option value="' . + esc_attr($sel) . + '" ' . + (($option_actual[ $section ][ $option_key ] == $sel) ? 'selected="selected"' : '') . + ' >' . + esc_html(ucfirst($seltext[ $key ])) . + '</option>' . + "\n"; + } + $input_type = '<select id="' . + esc_attr($option[0]) . + '" name="' . + esc_attr($option[0]) . + '">' . + $seldata . + '</select>' . + "\n"; + $explanation = $option[5]; + break; + case 'text-color': + $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"; + $explanation = $option[4]; + break; + case 'textarea': + $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>'; + $explanation = $option[4]; + break; + case 'catlist': + ob_start(); + echo '<div id="avhec-catlist">'; + echo '<ul>'; + wp_category_checklist(0, 0, $option_actual[ $section ][ $option_key ]); + echo '</ul>'; + echo '</div>'; + $input_type = ob_get_contents(); + ob_end_clean(); + $explanation = $option[4]; + break; + case 'text': + default: + $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"; + $explanation = $option[4]; + break; + } + // Additional Information + $extra = ''; + if ($explanation) { + $extra = '<br /><span class="description">' . wp_filter_kses($explanation) . '</span>' . "\n"; + } + // Output + $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"; + } + $output .= '</table>' . "\n"; + + return $output; + } } diff --git a/wp-content/plugins/extended-categories-widget/4.2/class/avh-ec.category-group.php b/wp-content/plugins/extended-categories-widget/4.2/class/avh-ec.category-group.php index 29a885423ecaf4d415a461eecf14913f0afbb3d9..795eedb1659adef37394fa1dfa0e436c184a4c92 100644 --- a/wp-content/plugins/extended-categories-widget/4.2/class/avh-ec.category-group.php +++ b/wp-content/plugins/extended-categories-widget/4.2/class/avh-ec.category-group.php @@ -5,419 +5,480 @@ * * @author Peter van der Does */ -class AVH_EC_Category_Group -{ - - /** - * Taxonomy name - * - * @var string - */ - public $taxonomy_name; - - public $db_options_widget_titles; - - public $options_widget_titles; - - public $widget_done_catgroup; - - /** - * PHP5 Constructor - * Init the Database Abstraction layer - */ - public function __construct() - { - global $wpdb; - - register_shutdown_function(array($this, '__destruct')); - - /** - * Taxonomy name - * - * @var string - */ - $this->taxonomy_name = 'avhec_catgroup'; - - $this->db_options_widget_titles = 'avhec_widget_titles'; - // add DB pointer - $wpdb->avhec_cat_group = $wpdb->prefix . 'avhec_category_groups'; - - /** - * Create the table if it doesn't exist. - */ - if ($wpdb->get_var('show tables like \'' . $wpdb->avhec_cat_group . '\'') != $wpdb->avhec_cat_group) { - add_action('init', array($this, 'doCreateTable'), 2); // Priority needs to be the same as the Register Taxonomy - } - add_action('init', array($this, 'doRegisterTaxonomy'), 2); // Priority for registering custom taxonomies is +1 over the creation of the initial taxonomies - add_action('init', array($this, 'doSetupOptions')); - - add_action('admin_init', array($this, 'addMetaBoxes')); - } - - /** - * PHP5 style destructor and will run when database object is destroyed. - * - * @return bool Always true - */ - public function __destruct() - { - return true; - } - - /** - * Create Table - * @WordPress action init - */ - public function doCreateTable() - { - global $wpdb; - - // Setup the DB Tables - $charset_collate = ''; - - if (!empty($wpdb->charset)) { - $charset_collate = 'DEFAULT CHARACTER SET ' . $wpdb->charset; - } - if (!empty($wpdb->collate)) { - $charset_collate .= ' COLLATE ' . $wpdb->collate; - } - - $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 . ';'; - - $result = $wpdb->query($sql); - } - - /** - * Setup Group Categories Taxonomy - * @WordPress action init - */ - public function doRegisterTaxonomy() - { - /** - * As we don't want to see the Menu Item we have to disable show_ui. - * This also disables the metabox on the posts and pages, so we add thse manually instead. - * 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. - */ - $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')); - $caps = array('manage_terms' => null, 'edit_terms' => null, 'delete_terms' => null, 'assign_terms' => 'edit_posts'); - 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)); - } - - /** - * Setup the options for the widget titles - * @WordPress action init - */ - public function doSetupOptions() - { - // Setup the standard groups if the none group does not exists. - $all_categories = $this->getAllCategoriesTermID(); - if (false === $this->getTermIDBy('slug', 'none')) { - $none_group_id = wp_insert_term('none', $this->taxonomy_name, array('description' => __('This group will not show the widget.', 'avh-ec'))); - - $home_group_id = wp_insert_term('Home', $this->taxonomy_name, array('description' => __('This group will be shown on the front page.', 'avh-ec'))); - $this->setCategoriesForGroup($home_group_id['term_id'], $all_categories); - $this->setWidgetTitleForGroup($home_group_id['term_id'], ''); - } - if (false === $this->getTermIDBy('slug', 'all')) { - $all_group_id = wp_insert_term('All', $this->taxonomy_name, array('description' => __('Holds all the categories.', 'avh-ec'))); - if (!is_wp_error($all_group_id)) { - $this->setWidgetTitleForGroup($all_group_id['term_id'], ''); - } else { - trigger_error($all_group_id->get_error_message(), E_USER_NOTICE); - } - } - - $options = get_option($this->db_options_widget_titles); - if (!$options) { - $options = array(); - $id = $this->getTermIDBy('slug', 'all'); - $options[$id] = ''; - $id = $this->getTermIDBy('slug', 'home'); - $options[$id] = ''; - update_option($this->db_options_widget_titles, $options); - } - $this->options_widget_titles = $options; - $this->setCategoriesForGroup($this->getTermIDBy('slug', 'all'), $all_categories); - } - - /** - * Add the metaboxes for the pots and page pages. - * @WordPress action admin_init - */ - public function addMetaBoxes() - { - add_meta_box($this->taxonomy_name . 'div', __('Category Groups', 'avh-ec'), 'post_categories_meta_box', 'post', 'side', 'core', array('taxonomy' => $this->taxonomy_name)); - add_meta_box($this->taxonomy_name . 'div', __('Category Groups', 'avh-ec'), 'post_categories_meta_box', 'page', 'side', 'core', array('taxonomy' => $this->taxonomy_name)); - } - - /** - * Get all groups term_id - * - * @return array Term_id - */ - public function getAllCategoriesTermID() - { - $all_cat_id = array(); - $categories = get_categories(); - if (!is_wp_error($categories)) { - foreach ($categories as $category) { - $all_cat_id[] = $category->term_id; - } - } - - return ($all_cat_id); - } - - /** - * Get the categories from the given group from the DB - * - * @param int $group_id - * The Taxonomy Term ID - * @return Array false Will return false, if the row does not exists. - * - */ - public function getCategoriesFromGroup($group_id) - { - global $wpdb; - - // Query database - $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)); - - if (is_array($result)) { // Call succeeded - if (empty($result)) { // No rows found - $return = array(); - } else { - foreach ($result as $row) { - $return[] = $row->term_id; - } - } - } else { - $return = false; - } - - return ($return); - } - - /** - * Set the categories for the given group from the DB. - * Insert the group if it doesn't exists. - * - * @param int $group_id - * The Taxonomy Term ID - * @param array $categories - * The categories - * @return Object (false if not found) - * - */ - public function setCategoriesForGroup($group_id, $categories = array()) - { - global $wpdb; - - if (false === $group_id) { - return; - } - $old_categories = $this->getCategoriesFromGroup($group_id); - - if (!is_array($categories)) { - $categories = array(); - } - $new_categories = $categories; - sort($old_categories); - sort($new_categories); - // If the new and old values are the same, no need to update. - if ($new_categories === $old_categories) { - return false; - } - - $new = array_diff($new_categories, $old_categories); - $removed = array_diff($old_categories, $new_categories); - - if (!empty($new)) { - foreach ($new as $cat_term_id) { - $insert[] = '(' . $group_id . ',' . $cat_term_id . ')'; - } - $value = implode(',', $insert); - $sql = 'INSERT INTO ' . $wpdb->avhec_cat_group . ' (group_term_id, term_id) VALUES ' . $value; - $result = $wpdb->query($sql); - } - - if (!empty($removed)) { - $delete = implode(',', $removed); - $sql = $wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE group_term_id=%d and term_id IN (' . $delete . ')', $group_id); - $result = $wpdb->query($sql); - } - - return $result; - } - - /** - * Set the Widget Title for a Group - * - * @param int $group_id - * @param string $widget_title - * - */ - public function setWidgetTitleForGroup($group_id, $widget_title = '') - { - $this->options_widget_titles[$group_id] = $widget_title; - update_option($this->db_options_widget_titles, $this->options_widget_titles); - } - - /** - * Return the title for a group_id if exsist otherwise return false - * - * @param - * $group_id - * - */ - public function getWidgetTitleForGroup($group_id) - { - if (isset($this->options_widget_titles[$group_id])) { - return ($this->options_widget_titles[$group_id]); - } - - return false; - } - - /** - * Delete the Widget Title for a group - * - * @param - * $group_id - */ - public function doDeleteWidgetTitle($group_id) - { - if (isset($this->options_widget_titles[$group_id])) { - unset($this->options_widget_titles[$group_id]); - } - update_option($this->db_options_widget_titles, $this->options_widget_titles); - } - - /** - * Same as get_term_by, but returns the ID only if found, else false - * - * @param string $field - * @param string $value - * @return int boolean - */ - public function getTermIDBy($field, $value) - { - $row = get_term_by($field, $value, $this->taxonomy_name); - if (false === $row) { - $return = false; - } else { - $return = (int) $row->term_id; - } - - return ($return); - } - - /** - * Gets all information of a group - * - * @param - * $group_id - * @return Object false false when the group doesn't exists. - */ - public function getGroup($group_id) - { - global $wpdb; - - $result = get_term((int) $group_id, $this->taxonomy_name); - if (null === $result) { - $result = false; - } - - return ($result); - } - - public function getGroupByCategoryID($category_id) - { - $return = get_term_by('slug', 'none', $this->taxonomy_name); - $cat_groups = get_terms($this->taxonomy_name, array('hide_empty' => false)); - - foreach ($cat_groups as $group) { - $cats = $this->getCategoriesFromGroup($group->term_id); - if ($group->slug != 'all' && in_array($category_id, $cats)) { - $return = $group; - break; - } - } - - return $return; - } - - /** - * Inserts a new group - * - * @param - * $term - * @param array $args - */ - public function doInsertGroup($term, $args = array(), $widget_title = '') - { - $row = wp_insert_term($term, $this->taxonomy_name, $args); - $this->setWidgetTitleForGroup($term, $widget_title); - - return ($row['term_id']); - } - - /** - * Deletes a group - * - * @param - * $group_id - */ - public function doDeleteGroup($group_id) - { - global $wpdb; - - $group = $this->getGroup($group_id); - $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE group_term_id=%d', $group_id)); - $this->doDeleteWidgetTitle($group_id); - $return = wp_delete_term($group->term_id, $this->taxonomy_name); - - return ($return); - } - - /** - * Update a group - * - * @param - * $group_id - * @param - * $selected_categories - * @param $widget_title return - * -1,0,1 Unknown Group, Duplicate Slug, Succesfull - */ - public function doUpdateGroup($group_id, $args = array(), $selected_categories = array(), $widget_title = '') - { - $group = $this->getGroup($group_id); - if (is_object($group)) { - $id = wp_update_term($group->term_id, $this->taxonomy_name, $args); - if (!is_wp_error($id)) { - $this->setWidgetTitleForGroup($group_id, $widget_title); - $this->setCategoriesForGroup($group_id, $selected_categories); - $return = 1; // Succesful - } else { - $return = 0; // Duplicate Slug - } - } else { - $return = -1; // Unknown group - } - - return ($return); - } - - /** - * Deletes the given category from all groups - * - * @param - * $category_id - */ - public function doDeleteCategoryFromGroup($category_id) - { - global $wpdb; - $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE term_id=%d', $category_id)); - } +class AVH_EC_Category_Group { + public $db_options_widget_titles; + public $options_widget_titles; + /** + * Taxonomy name + * + * @var string + */ + public $taxonomy_name; + public $widget_done_catgroup; + + /** + * PHP5 Constructor + * Init the Database Abstraction layer + */ + public function __construct() { + global $wpdb; + + register_shutdown_function(array($this, '__destruct')); + + /** + * Taxonomy name + * + * @var string + */ + $this->taxonomy_name = 'avhec_catgroup'; + + $this->db_options_widget_titles = 'avhec_widget_titles'; + // add DB pointer + $wpdb->avhec_cat_group = $wpdb->prefix . 'avhec_category_groups'; + + /** + * Create the table if it doesn't exist. + */ + if ($wpdb->get_var('show tables like \'' . $wpdb->avhec_cat_group . '\'') != $wpdb->avhec_cat_group) { + add_action('init', array($this, 'doCreateTable'),0); + } + add_action('init', array($this, 'doRegisterTaxonomy'),0); + add_action('init', array($this, 'doSetupOptions')); + + add_action('admin_init', array($this, 'addMetaBoxes')); + } + + /** + * PHP5 style destructor and will run when database object is destroyed. + * + * @return bool Always true + */ + public function __destruct() { + return true; + } + + /** + * Add the metaboxes for the pots and page pages. + * + * @WordPress action admin_init + */ + public function addMetaBoxes() { + add_meta_box($this->taxonomy_name . 'div', + __('Category Groups', 'avh-ec'), + 'post_categories_meta_box', + 'post', + 'side', + 'core', + array('taxonomy' => $this->taxonomy_name)); + add_meta_box($this->taxonomy_name . 'div', + __('Category Groups', 'avh-ec'), + 'post_categories_meta_box', + 'page', + 'side', + 'core', + array('taxonomy' => $this->taxonomy_name)); + } + + /** + * Create Table + * + * @WordPress action init + */ + public function doCreateTable() { + global $wpdb; + + // Setup the DB Tables + $charset_collate = ''; + + if ( ! empty($wpdb->charset)) { + $charset_collate = 'DEFAULT CHARACTER SET ' . $wpdb->charset; + } + if ( ! empty($wpdb->collate)) { + $charset_collate .= ' COLLATE ' . $wpdb->collate; + } + + $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 . + ';'; + + $result = $wpdb->query($sql); + } + + /** + * Deletes the given category from all groups + * + * @param int $category_id + */ + public function doDeleteCategoryFromGroup($category_id) { + global $wpdb; + $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE term_id=%d', + $category_id)); + } + + /** + * Deletes a group + * + * @param int $group_id + * + * @return bool|\WP_Error + */ + public function doDeleteGroup($group_id) { + global $wpdb; + + $group = $this->getGroup($group_id); + $result = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->avhec_cat_group . ' WHERE group_term_id=%d', + $group_id)); + $this->doDeleteWidgetTitle($group_id); + $return = wp_delete_term($group->term_id, $this->taxonomy_name); + + return ($return); + } + + /** + * Delete the Widget Title for a group + * + * @param int $group_id + */ + public function doDeleteWidgetTitle($group_id) { + if (isset($this->options_widget_titles[ $group_id ])) { + unset($this->options_widget_titles[ $group_id ]); + } + update_option($this->db_options_widget_titles, $this->options_widget_titles); + } + + /** + * Inserts a new group + * + * @param string $term + * @param array $args + * @param string $widget_title + * + * @return int + */ + public function doInsertGroup($term, $args = array(), $widget_title = '') { + $row = wp_insert_term($term, $this->taxonomy_name, $args); + $this->setWidgetTitleForGroup($term, $widget_title); + + return ($row['term_id']); + } + + /** + * Setup Group Categories Taxonomy + * + * @WordPress action init + */ + public function doRegisterTaxonomy() { + /** + * As we don't want to see the Menu Item we have to disable show_ui. + * This also disables the metabox on the posts and pages, so we add thse manually instead. + * 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. + */ + $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') + ); + $caps = array( + 'manage_terms' => null, + 'edit_terms' => null, + 'delete_terms' => null, + 'assign_terms' => 'edit_posts' + ); + $result = 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 + )); + if (is_wp_error($result)) { + trigger_error($result->get_error_message(), E_USER_NOTICE); + } + } + + /** + * Setup the options for the widget titles + * + * @WordPress action init + */ + public function doSetupOptions() { + // Setup the standard groups if the none group does not exists. + $all_categories = $this->getAllCategoriesTermID(); + if (false === $this->getTermIDBy('slug', 'none')) { + $none_group_id = wp_insert_term('none', + $this->taxonomy_name, + array( + 'description' => __('This group will not show the widget.', 'avh-ec') + )); + if (is_wp_error($none_group_id)) { + trigger_error($none_group_id->get_error_message(),E_USER_NOTICE); + } + + $home_group_id = wp_insert_term('Home', + $this->taxonomy_name, + array( + 'description' => __('This group will be shown on the front page.', + 'avh-ec') + )); + if ( ! is_wp_error($home_group_id)) { + $this->setCategoriesForGroup($home_group_id['term_id'], $all_categories); + $this->setWidgetTitleForGroup($home_group_id['term_id'], ''); + } else { + trigger_error($home_group_id->get_error_message(), E_USER_NOTICE); + } + } + if (false === $this->getTermIDBy('slug', 'all')) { + $all_group_id = wp_insert_term('All', + $this->taxonomy_name, + array('description' => __('Holds all the categories.', 'avh-ec'))); + if ( ! is_wp_error($all_group_id)) { + $this->setWidgetTitleForGroup($all_group_id['term_id'], ''); + } else { + trigger_error($all_group_id->get_error_message(), E_USER_NOTICE); + } + } + + $options = get_option($this->db_options_widget_titles); + if ( ! $options) { + $options = array(); + $id = $this->getTermIDBy('slug', 'all'); + $options[ $id ] = ''; + $id = $this->getTermIDBy('slug', 'home'); + $options[ $id ] = ''; + update_option($this->db_options_widget_titles, $options); + } + $this->options_widget_titles = $options; + $this->setCategoriesForGroup($this->getTermIDBy('slug', 'all'), $all_categories); + } + + /** + * Update a group + * + * @param int $group_id + * @param array $args + * @param array $selected_categories + * @param string $widget_title + * + * @return int + */ + public function doUpdateGroup($group_id, $args = array(), $selected_categories = array(), $widget_title = '') { + $group = $this->getGroup($group_id); + if (is_object($group)) { + $id = wp_update_term($group->term_id, $this->taxonomy_name, $args); + if ( ! is_wp_error($id)) { + $this->setWidgetTitleForGroup($group_id, $widget_title); + $this->setCategoriesForGroup($group_id, $selected_categories); + $return = 1; // Succesful + } else { + $return = 0; // Duplicate Slug + } + } else { + $return = - 1; // Unknown group + } + + return ($return); + } + + /** + * Get all groups term_id + * + * @return array Term_id + */ + public function getAllCategoriesTermID() { + $all_cat_id = array(); + $categories = get_categories(); + if ( ! is_wp_error($categories)) { + foreach ($categories as $category) { + $all_cat_id[] = $category->term_id; + } + } + + return ($all_cat_id); + } + + /** + * Get the categories from the given group from the DB + * + * @param int $group_id The Taxonomy Term ID + * + * @return array false Will return false, if the row does not exists. + */ + public function getCategoriesFromGroup($group_id) { + global $wpdb; + + $return = array(); + // Query database + $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)); + + if (is_array($result)) { // Call succeeded + if (empty($result)) { // No rows found + $return = array(); + } else { + foreach ($result as $row) { + $return[] = $row->term_id; + } + } + } else { + $return = false; + } + + return ($return); + } + + /** + * Gets all information of a group + * + * @param int $group_id + * + * @return object|false false when the group doesn't exists. + */ + public function getGroup($group_id) { + $result = get_term((int) $group_id, $this->taxonomy_name); + if (null === $result) { + $result = false; + } + + return ($result); + } + + /** + * @param int $category_id + * + * @return mixed + */ + public function getGroupByCategoryID($category_id) { + $return = get_term_by('slug', 'none', $this->taxonomy_name); + $cat_groups = get_terms($this->taxonomy_name, array('hide_empty' => false)); + + foreach ($cat_groups as $group) { + $cats = $this->getCategoriesFromGroup($group->term_id); + if ($group->slug != 'all' && in_array($category_id, $cats)) { + $return = $group; + break; + } + } + + return $return; + } + + /** + * Same as get_term_by, but returns the ID only if found, else false + * + * @param string $field + * @param string $value + * + * @return int boolean + */ + public function getTermIDBy($field, $value) { + $row = get_term_by($field, $value, $this->taxonomy_name); + if (false === $row) { + $return = false; + } else { + $return = (int) $row->term_id; + } + + return ($return); + } + + /** + * Return the title for a group_id if exsist otherwise return false + * + * @param int $group_id + * + * @return bool + */ + public function getWidgetTitleForGroup($group_id) { + if (isset($this->options_widget_titles[ $group_id ])) { + return ($this->options_widget_titles[ $group_id ]); + } + + return false; + } + + /** + * Set the categories for the given group from the DB. + * Insert the group if it doesn't exists. + * + * @param int $group_id The Taxonomy Term ID + * @param array $categories The categories + * + * @return object|false + */ + public function setCategoriesForGroup($group_id, $categories = array()) { + global $wpdb; + $result = false; + + if (false === $group_id) { + return $result; + } + $old_categories = $this->getCategoriesFromGroup($group_id); + + if ( ! is_array($categories)) { + $categories = array(); + } + $new_categories = $categories; + sort($old_categories); + sort($new_categories); + // If the new and old values are the same, no need to update. + if ($new_categories === $old_categories) { + return $result; + } + + $new = array_diff($new_categories, $old_categories); + $removed = array_diff($old_categories, $new_categories); + + if ( ! empty($new)) { + $insert = array(); + foreach ($new as $cat_term_id) { + $insert[] = '(' . $group_id . ',' . $cat_term_id . ')'; + } + $value = implode(',', $insert); + $sql = 'INSERT INTO ' . $wpdb->avhec_cat_group . ' (group_term_id, term_id) VALUES ' . $value; + $result = $wpdb->query($sql); + } + + if ( ! empty($removed)) { + $delete = implode(',', $removed); + $sql = $wpdb->prepare('DELETE FROM ' . + $wpdb->avhec_cat_group . + ' WHERE group_term_id=%d and term_id IN (' . + $delete . + ')', + $group_id); + $result = $wpdb->query($sql); + } + + return $result; + } + + /** + * Set the Widget Title for a Group + * + * @param int $group_id + * @param string $widget_title + */ + public function setWidgetTitleForGroup($group_id, $widget_title = '') { + $this->options_widget_titles[ $group_id ] = $widget_title; + update_option($this->db_options_widget_titles, $this->options_widget_titles); + } } diff --git a/wp-content/plugins/extended-categories-widget/4.2/class/avh-ec.core.php b/wp-content/plugins/extended-categories-widget/4.2/class/avh-ec.core.php index 85caec6a365f56750a372a6ec3fe7ddf0e199fb0..21a146600724847b072f1ee7f56e9bf4fa7fce51 100644 --- a/wp-content/plugins/extended-categories-widget/4.2/class/avh-ec.core.php +++ b/wp-content/plugins/extended-categories-widget/4.2/class/avh-ec.core.php @@ -1,801 +1,950 @@ <?php -class AVH_EC_Core -{ - - public $version; - - public $comment; - - public $info; - - public $db_options_core; - - public $default_options; - - public $default_options_general; - - public $default_options_category_group; - - public $default_options_sp_category_group; - - public $db_options_tax_meta; - - public $options; - - /** - * PHP5 constructor - */ - public function __construct() - { - /** - * - * @var AVH_EC_Category_Group - */ - $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); - - $this->version = '3.10.0-dev.1'; - $this->comment = '<!-- AVH Extended Categories version ' . $this->version . ' | http://blog.avirtualhome.com/wordpress-plugins/ -->'; - $this->db_options_core = 'avhec'; - $this->db_options_tax_meta = 'avhec-tax_meta'; - - add_action('init', array($this, 'handleInitializePlugin'), 10); - } - - public function handleInitializePlugin() - { - global $wpdb; - - $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); - $db_version = 4; - - $info['siteurl'] = get_option('siteurl'); - $info['plugin_dir'] = AVHEC_PLUGIN_DIR; - $info['graphics_url'] = AVHEC_PLUGIN_URL . '/images'; - - // Set class property for info - $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']); - - // Set the default options - $this->default_options_general = array('version' => $this->version, 'dbversion' => $db_version, 'alternative_name_select_category' => ''); - - // Set the default category group options - $no_group_id = $catgrp->getTermIDBy('slug', 'none'); - $home_group_id = $catgrp->getTermIDBy('slug', 'home'); - $default_group_id = $catgrp->getTermIDBy('slug', 'all'); - $this->default_options_category_group = array('no_group' => $no_group_id, 'home_group' => $home_group_id, 'default_group' => $default_group_id); - - $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); - - $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); - - /** - * Set the options for the program - */ - $this->loadOptions(); - - // Check if we have to do updates - if ((!isset($this->options['general']['dbversion'])) || $this->options['general']['dbversion'] < $db_version) { - $this->doUpdateOptions($db_version); - } - - $db = new AVH_DB(); - if (!$db->field_exists('avhec_term_order', $wpdb->terms)) { - $wpdb->query("ALTER TABLE $wpdb->terms ADD `avhec_term_order` INT( 4 ) null DEFAULT '0'"); - } - - $this->handleTextdomain(); - add_filter('get_terms_orderby', array($this, 'applyOrderFilter'), 10, 2); - } - - public function applyOrderFilter($orderby, $args) - { - switch ($args['orderby']) { - case 'avhec_manualorder': - $new_orderby = 't.avhec_term_order'; - break; - case 'avhec_3rdparty_mycategoryorder': - $new_orderby = 't.term_order'; - break; - default: - $new_orderby = $orderby; - break; - } - - return $new_orderby; - } - - /** - * Loads the i18n - */ - public function handleTextdomain() - { - load_plugin_textdomain('avh-ec', false, AVHEC_RELATIVE_PLUGIN_DIR . '/lang'); - } - - /** - * Checks if running version is newer and do upgrades if necessary - * - * @since 1.2.3 - * - */ - public function doUpdateOptions($db_version) - { - $options = $this->getOptions(); - - // Add none existing sections and/or elements to the options - foreach ($this->default_options as $section => $default_data) { - if (!array_key_exists($section, $options)) { - $options[$section] = $default_data; - continue; - } - foreach ($default_data as $element => $default_value) { - if (!array_key_exists($element, $options[$section])) { - $options[$section][$element] = $default_value; - } - } - } - - // Remove none existing sections and/or elements from the options - foreach ($options as $section => $data) { - if (!array_key_exists($section, $this->default_options)) { - unset($options[$section]); - continue; - } - foreach ($data as $element => $value) { - if (!array_key_exists($element, $this->default_options[$section])) { - unset($options[$section][$element]); - } - } - } - /** - * Update the options to the latests versions - */ - $options['general']['version'] = $this->version; - $options['general']['dbversion'] = $db_version; - $this->saveOptions($options); - } - - /** - * Used in forms to set the checked option. - * - * @param mixed $checked - * @param mixed_type $current - * @return string - * - * @since 2.0 - */ - public function isChecked($checked, $current) - { - if ($checked == $current) { - return (' checked="checked"'); - } - - return (''); - } - - /** - * Used in forms to set the SELECTED option - * - * @param string $current - * @param string $field - * @return string - */ - public function isSelected($current, $field) - { - if ($current == $field) { - return (' SELECTED'); - } - - return (''); - } - - /** - * Get the base directory of a directory structure - * - * @param string $directory - * @return string - * - */ - public function getBaseDirectory($directory) - { - // place each directory into array and get the last element - $directory_array = explode('/', $directory); - // get highest or top level in array of directory strings - $public_base = end($directory_array); - - return $public_base; - } - - /** - * ******************************* - * * - * Methods for variable: options * - * * - * ****************************** - */ - - /** - * - * @param array $data - */ - public function setOptions($options) - { - $this->options = $options; - } - - /** - * return array - */ - public function getOptions() - { - return ($this->options); - } - - /** - * Save all current options and set the options - */ - public function saveOptions($options) - { - update_option($this->db_options_core, $options); - wp_cache_flush(); // Delete cache - $this->setOptions($options); - } - - /** - * Retrieves the plugin options from the WordPress options table and assigns to class variable. - * If the options do not exists, like a new installation, the options are set to the default value. - * - * @return none - */ - public function loadOptions() - { - $options = get_option($this->db_options_core); - if (false === $options) { // New installation - $this->resetToDefaultOptions(); - } else { - $this->setOptions($options); - } - } - - /** - * Get the value for an option element. - * If there's no option is set on the Admin page, return the default value. - * - * @param string $key - * @param string $option - * @return mixed - */ - public function getOptionElement($option, $key) - { - if ($this->options[$option][$key]) { - $return = $this->options[$option][$key]; // From Admin Page - } else { - $return = $this->default_options[$option][$key]; // Default - } - - return ($return); - } - - /** - * Reset to default options and save in DB - */ - public function resetToDefaultOptions() - { - $this->options = $this->default_options; - $this->saveOptions($this->default_options); - } - - /** - * Display or retrieve the HTML dropdown list of categories. - * - * The list of arguments is below: - * 'show_option_all' (string) - Text to display for showing all categories. - * 'show_option_none' (string) - Text to display for showing no categories. - * 'orderby' (string) default is 'ID' - What column to use for ordering the - * categories. - * 'order' (string) default is 'ASC' - What direction to order categories. - * 'show_last_update' (bool|int) default is 0 - See {@link get_categories()} - * 'show_count' (bool|int) default is 0 - Whether to show how many posts are - * in the category. - * 'hide_empty' (bool|int) default is 1 - Whether to hide categories that - * don't have any posts attached to them. - * 'child_of' (int) default is 0 - See {@link get_categories()}. - * 'exclude' (string) - See {@link get_categories()}. - * 'echo' (bool|int) default is 1 - Whether to display or retrieve content. - * 'depth' (int) - The max depth. - * 'tab_index' (int) - Tab index for select element. - * 'name' (string) - The name attribute value for selected element. - * 'class' (string) - The class attribute value for selected element. - * 'selected' (int) - Which category ID is selected. - * - * The 'hierarchical' argument, which is disabled by default, will override the - * depth argument, unless it is true. When the argument is false, it will - * display all of the categories. When it is enabled it will use the value in - * the 'depth' argument. - * - * @since 2.1.0 - * - * @param string|array $args - * Optional. Override default arguments. - * @return string HTML content only if 'echo' argument is 0. - */ - public function avh_wp_dropdown_categories($args = array()) - { - $mywalker = new AVH_Walker_CategoryDropdown(); - - // @format_off - $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); - // @format_on - $defaults['selected'] = (is_category()) ? get_query_var('cat') : 0; - - $r = wp_parse_args($args, $defaults); - - if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) { - $r['pad_counts'] = true; - } - - $r['include_last_update_time'] = $r['show_last_update']; - extract($r); - - $tab_index_attribute = ''; - if ((int) $tab_index > 0) { - $tab_index_attribute = ' tabindex="' . $tab_index . '"'; - } - - // Avoid clashes with the 'name' param of get_terms(). - $get_terms_args = $r; - unset( $get_terms_args['name'] ); - $categories = get_terms( $r['taxonomy'], $get_terms_args ); - - $name = esc_attr($r['name']); - $class = esc_attr($r['class']); - $id = $r['id'] ? esc_attr($r['id']) : $name; - - if (!$r['hide_if_empty'] || !empty($categories)) { - $output = "<select name='$name' id='$id' class='$class' $tab_index_attribute>\n"; - } else { - $output = ''; - } - - if (empty($categories) && !$r['hide_if_empty'] && !empty($show_option_none)) { - $show_option_none = apply_filters('list_cats', $show_option_none); - $output .= "\t<option value='-1' selected='selected'>$show_option_none</option>\n"; - } - if (!empty($categories)) { - - if ($show_option_all) { - $show_option_all = apply_filters('list_cats', $show_option_all); - $selected = ('0' === strval($r['selected'])) ? " selected='selected'" : ''; - $output .= "\t" . '<option value="0"' . $selected . '>' . $show_option_all . '</option>' . "\n"; - } - - if ($show_option_none) { - $show_option_none = apply_filters('list_cats', $show_option_none); - $selected = ('-1' === strval($r['selected'])) ? " selected='selected'" : ''; - $output .= "\t" . '<option value="-1"' . $selected . '>' . $show_option_none . '</option>' . "\n"; - } - - if ($hierarchical) { - $depth = $r['depth']; // Walk the full depth. - } else { - $depth = -1; // Flat - } - $output .= walk_category_dropdown_tree($categories, $depth, $r); - } - if (!$r['hide_if_empty'] || !empty($categories)) { - $output .= "</select>\n"; - } - - $output = apply_filters('wp_dropdown_cats', $output); - - if ($echo) { - echo $output; - } - - return $output; - } - - /** - * Display or retrieve the HTML list of categories. - * - * The list of arguments is below: - * 'show_option_all' (string) - Text to display for showing all categories. - * 'orderby' (string) default is 'ID' - What column to use for ordering the - * categories. - * 'order' (string) default is 'ASC' - What direction to order categories. - * 'show_last_update' (bool|int) default is 0 - See {@link - * walk_category_dropdown_tree()} - * 'show_count' (bool|int) default is 0 - Whether to show how many posts are - * in the category. - * 'hide_empty' (bool|int) default is 1 - Whether to hide categories that - * don't have any posts attached to them. - * 'use_desc_for_title' (bool|int) default is 1 - Whether to use the - * description instead of the category title. - * 'feed' - See {@link get_categories()}. - * 'feed_type' - See {@link get_categories()}. - * 'feed_image' - See {@link get_categories()}. - * 'child_of' (int) default is 0 - See {@link get_categories()}. - * 'exclude' (string) - See {@link get_categories()}. - * 'exclude_tree' (string) - See {@link get_categories()}. - * 'echo' (bool|int) default is 1 - Whether to display or retrieve content. - * 'current_category' (int) - See {@link get_categories()}. - * 'hierarchical' (bool) - See {@link get_categories()}. - * 'title_li' (string) - See {@link get_categories()}. - * 'depth' (int) - The max depth. - * - * @since 2.1.0 - * - * @param string|array $args - * Optional. Override default arguments. - * @return string HTML content only if 'echo' argument is 0. - */ - public function avh_wp_list_categories($args = array()) - { - $mywalker = new AVHEC_Walker_Category(); - $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); - - $r = wp_parse_args($args, $defaults); - - if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) { - $r['pad_counts'] = true; - } - - if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) { - $r['pad_counts'] = true; - } - - if (isset($r['show_date'])) { - $r['include_last_update_time'] = $r['show_date']; - } - - if (true == $r['hierarchical']) { - $r['exclude_tree'] = $r['exclude']; - $r['exclude'] = ''; - } - - extract($r); - - $categories = get_categories($r); - - $output = ''; - if ($title_li && 'list' == $style) { - $output = '<li class="categories">' . $r['title_li'] . '<ul>'; - } - - if (empty($categories)) { - if ('list' == $style) { - $output .= '<li>' . __("No categories") . '</li>'; - } else { - $output .= __("No categories"); - } - } else { - global $wp_query; - - if (!empty($show_option_all)) { - if ('list' == $style) { - $output .= '<li><a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a></li>'; - } else { - $output .= '<a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a>'; - } - } - if (empty($r['current_category']) && is_category()) { - $r['current_category'] = $wp_query->get_queried_object_id(); - } - - if ($hierarchical) { - $depth = $r['depth']; - } else { - $depth = -1; // Flat. - } - - $output .= walk_category_tree($categories, $depth, $r); - } - - if ($title_li && 'list' == $style) { - $output .= '</ul></li>'; - } - - $output = apply_filters('wp_list_categories', $output); - - if ($echo) { - echo $output; - } else { - return $output; - } - } - - public function getCategories() - { - static $_categories = null; - if (null === $_categories) { - $_categories = get_categories('get=all'); - } - - return $_categories; - } - - public function getCategoriesId($categories) - { - static $_categories_id = null; - if (null == $_categories_id) { - foreach ($categories as $key => $category) { - $_categories_id[$category->term_id] = $key; - } - } - - return $_categories_id; - } -} - /** - * Create HTML dropdown list of Categories. + * Create HTML list of categories. * * @uses Walker */ -class AVH_Walker_CategoryDropdown extends Walker_CategoryDropdown -{ - - public function walk($elements, $max_depth) - { - $args = array_slice(func_get_args(), 2); - $output = ''; - - if ($max_depth < -1) { - return $output; - } - - if (empty($elements)) { - return $output; - } - - $id_field = $this->db_fields['id']; - $parent_field = $this->db_fields['parent']; - - // flat display - if (-1 == $max_depth) { - $empty_array = array(); - foreach ($elements as $e) { - $this->display_element($e, $empty_array, 1, 0, $args, $output); - } - - return $output; - } - - /* - * 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. - */ - $top_level_elements = array(); - $children_elements = array(); - foreach ($elements as $e) { - if (0 == $e->$parent_field) { - $top_level_elements[] = $e; - } else { - $children_elements[$e->$parent_field][] = $e; - } - } - - /* - * when none of the elements is top level assume the first one must be root of the sub elements - */ - if (empty($top_level_elements)) { - - $first = array_slice($elements, 0, 1); - $root = $first[0]; - - $top_level_elements = array(); - $children_elements = array(); - foreach ($elements as $e) { - if ($root->$parent_field == $e->$parent_field) { - $top_level_elements[] = $e; - } else { - $children_elements[$e->$parent_field][] = $e; - } - } - } - - foreach ($top_level_elements as $e) { - $this->display_element($e, $children_elements, $max_depth, 0, $args, $output); - } - - /* - * if we are displaying all levels, and remaining children_elements is not empty, then we got orphans, which should be displayed regardless - */ - if ((0 == $max_depth) && count($children_elements) > 0) { - $empty_array = array(); - foreach ($children_elements as $orphans) { - foreach ($orphans as $op) { - $this->display_element($op, $empty_array, 1, 0, $args, $output); - } - } - } - - return $output; - } +class AVHEC_Walker_Category extends Walker { + /** + * @see Walker::$db_fields + * @since 2.1.0 + * @todo Decouple this + * @var array + */ + public $db_fields = array('parent' => 'parent', 'id' => 'term_id'); + /** + * @see Walker::$tree_type + * @since 2.1.0 + * @var string + */ + public $tree_type = 'category'; + + /** + * @see Walker::end_el() + * @since 2.1.0 + * + * @param string $output Passed by reference. Used to append additional content. + * @param object $object + * @param int $depth Depth of category. Not used. + * @param array $args Only uses 'list' for whether should append to output. + */ + public function end_el(&$output, $object, $depth = 0, $args = array()) { + if ('list' != $args['style']) { + return; + } + + $output .= '</li>' . "\n"; + } + + /** + * @see Walker::end_lvl() + * @since 2.1.0 + * + * @param string $output Passed by reference. Used to append additional content. + * @param int $depth Depth of category. Used for tab indentation. + * @param array $args Will only append content if style argument value is 'list'. + */ + public function end_lvl(&$output, $depth = 0, $args = array()) { + if ('list' != $args['style']) { + return; + } + + $indent = str_repeat("\t", $depth); + $output .= $indent . '</ul>' . "\n"; + } + + /** + * @see Walker::start_el() + * @since 2.1.0 + * + * @param string $output Passed by reference. Used to append additional content. + * @param object $category Category data object. + * @param int $depth Depth of category in reference to parents. + * @param array $args + * @param int $current_object_id + */ + public function start_el(&$output, $category, $depth = 0, $args = array(), $current_object_id = 0) { + $cat_name = apply_filters('list_cats', esc_attr($category->name), $category); + // Don't generate an element if the category name is empty. + if ( ! $cat_name) { + return; + } + + $link = '<div class="avhec-widget-line"><a href="' . get_category_link($category->term_id) . '" '; + if ($args['use_desc_for_title'] && ! empty($category->description)) { + /** + * Filter the category description for display. + * + * @since 1.2.0 + * + * @param string $description Category description. + * @param object $category Category object. + */ + $link .= 'title="' . + esc_attr(strip_tags(apply_filters('category_description', $category->description, $category))) . + '"'; + } else { + $link .= 'title="' . sprintf(__('View all posts filed under %s'), $cat_name) . '"'; + } + $link .= '>'; + $link .= $cat_name . '</a>'; + + if ( ! empty($args['feed_image']) || ! empty($args['feed'])) { + $link .= '<div class="avhec-widget-rss"> '; + + if (empty($args['feed_image'])) { + $link .= '('; + } + + $link .= '<a href="' . get_category_feed_link($category->term_id, $args['feed_type']) . '"'; + + if (empty($args['feed'])) { + $alt = ' alt="' . sprintf(__('Feed for all posts filed under %s'), $cat_name) . '"'; + } else { + $alt = ' alt="' . $args['feed'] . '"'; + $name = $args['feed']; + $link .= ' title="'; + $link .= empty($args['title']) ? $args['feed'] : $args['title']; + $link .= '"'; + } + + $link .= '>'; + + if (empty($args['feed_image'])) { + $link .= $name; + } else { + $link .= '<img src="' . $args['feed_image'] . '"' . $alt . '" />'; + } + $link .= '</a>'; + + if (empty($args['feed_image'])) { + $link .= ')'; + } + + $link .= '</div>'; + } + + if ( ! empty($args['show_count'])) { + $link .= '<div class="avhec-widget-count"> (' . number_format_i18n($category->count) . ')</div>'; + } + + if ( ! empty($args['$show_date'])) { + $link .= ' ' . gmdate('Y-m-d', $category->last_update_timestamp); + } + + if ('list' == $args['style']) { + // When on a single post get the post's category. This ensures that that category will be given the CSS style of "current category". + if (is_single()) { + $post_cats = get_the_category(); + $args['current_category'] = $post_cats[0]->term_id; + } + + $output .= "\t" . '<li'; + $css_classes = array( + 'cat-item', + 'cat-item-' . $category->term_id, + ); + + if ( ! empty($args['current_category'])) { + $_current_category = get_term($args['current_category'], $category->taxonomy); + if ($category->term_id == $args['current_category']) { + $css_classes[] = 'current-cat'; + } elseif ($category->term_id == $_current_category->parent) { + $css_classes[] = 'current-cat-parent'; + } + } + + /** + * Filter the list of CSS classes to include with each category in the list. + * + * @since 4.2.0 + * @see wp_list_categories() + * + * @param array $css_classes An array of CSS classes to be applied to each list item. + * @param object $category Category data object. + * @param int $depth Depth of page, used for padding. + * @param array $args An array of wp_list_categories() arguments. + */ + $css_classes = implode(' ', apply_filters('category_css_class', $css_classes, $category, $depth, $args)); + + $output .= ' class="' . $css_classes . '"'; + $output .= '>' . $link . '</div>' . "\n"; + } else { + $output .= "\t" . $link . '</div><br />' . "\n"; + } + } + + /** + * @see Walker::start_lvl() + * @since 2.1.0 + * + * @param string $output Passed by reference. Used to append additional content. + * @param int $depth Depth of category. Used for tab indentation. + * @param array $args Will only append content if style argument value is 'list'. + */ + public function start_lvl(&$output, $depth = 0, $args = array()) { + if ('list' != $args['style']) { + return; + } + + $indent = str_repeat("\t", $depth); + $output .= $indent . '<ul class="children">' . "\n"; + } +} + +class AVH_EC_Core { + public $comment; + public $db_options_core; + public $db_options_tax_meta; + public $default_options; + public $default_options_category_group; + public $default_options_general; + public $default_options_sp_category_group; + public $info; + public $options; + public $version; + + /** + * AVH_EC_Core constructor. + */ + public function __construct() { + $this->version = '3.10.0-dev.1'; + $this->comment = '<!-- AVH Extended Categories version ' . + $this->version . + ' | http://blog.avirtualhome.com/wordpress-plugins/ -->'; + $this->db_options_core = 'avhec'; + $this->db_options_tax_meta = 'avhec-tax_meta'; + + AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); + + add_action('init', array($this, 'handleInitializePlugin'), 10); + } + + public function applyOrderFilter($orderby, $args) { + switch ($args['orderby']) { + case 'avhec_manualorder': + $new_orderby = 't.avhec_term_order'; + break; + case 'avhec_3rdparty_mycategoryorder': + $new_orderby = 't.term_order'; + break; + default: + $new_orderby = $orderby; + break; + } + + return $new_orderby; + } + + /** + * Display or retrieve the HTML dropdown list of categories. + * + * The 'hierarchical' argument, which is disabled by default, will override the + * depth argument, unless it is true. When the argument is false, it will + * display all of the categories. When it is enabled it will use the value in + * the 'depth' argument. + * + * @since 2.1.0 + * @since 4.2.0 Introduced the `value_field` argument. + * + * @param string|array $args { + * Optional. Array or string of arguments to generate a categories drop-down + * element. + * + * @type string $show_option_all Text to display for showing all categories. Default empty. + * @type string $show_option_none Text to display for showing no categories. Default empty. + * @type string $option_none_value Value to use when no category is selected. Default empty. + * @type string $orderby Which column to use for ordering categories. See get_terms() for a list + * of accepted values. Default 'id' (term_id). + * @type string $order Whether to order terms in ascending or descending order. Accepts 'ASC' + * or 'DESC'. Default 'ASC'. + * @type bool $pad_counts See get_terms() for an argument description. Default false. + * @type bool|int $show_count Whether to include post counts. Accepts 0, 1, or their bool equivalents. + * Default 0. + * @type bool|int $hide_empty Whether to hide categories that don't have any posts. Accepts 0, 1, or + * their bool equivalents. Default 1. + * @type int $child_of Term ID to retrieve child terms of. See get_terms(). Default 0. + * @type array|string $exclude Array or comma/space-separated string of term ids to exclude. + * If `$include` is non-empty, `$exclude` is ignored. Default empty + * array. + * @type bool|int $echo Whether to echo or return the generated markup. Accepts 0, 1, or their + * bool equivalents. Default 1. + * @type bool|int $hierarchical Whether to traverse the taxonomy hierarchy. Accepts 0, 1, or their bool + * equivalents. Default 0. + * @type int $depth Maximum depth. Default 0. + * @type int $tab_index Tab index for the select element. Default 0 (no tabindex). + * @type string $name Value for the 'name' attribute of the select element. Default 'cat'. + * @type string $id Value for the 'id' attribute of the select element. Defaults to the value + * of `$name`. + * @type string $class Value for the 'class' attribute of the select element. Default + * 'postform'. + * @type int|string $selected Value of the option that should be selected. Default 0. + * @type string $value_field Term field that should be used to populate the 'value' attribute + * of the option elements. Accepts any valid term field: 'term_id', + * 'name', + * 'slug', 'term_group', 'term_taxonomy_id', 'taxonomy', 'description', + * 'parent', 'count'. Default 'term_id'. + * @type string|array $taxonomy Name of the category or categories to retrieve. Default 'category'. + * @type bool $hide_if_empty True to skip generating markup if no categories are found. + * Default false (create select element even if no categories are found). + * } + * @return string HTML content only if 'echo' argument is 0. + */ + public function avh_wp_dropdown_categories($args = '') { + $mywalker = new AVH_Walker_CategoryDropdown(); + + // @format_off + $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, + 'option_none_value' => - 1, + 'value_field' => 'term_id', + ); + // @format_on + $defaults['selected'] = (is_category()) ? get_query_var('cat') : 0; + + $r = wp_parse_args($args, $defaults); + $option_none_value = $r['option_none_value']; + + if ( ! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) { + $r['pad_counts'] = true; + } + + $r['include_last_update_time'] = $r['show_last_update']; + $tab_index = $r['tab_index']; + + $tab_index_attribute = ''; + if ((int) $tab_index > 0) { + $tab_index_attribute = ' tabindex="' . $tab_index . '"'; + } + + // Avoid clashes with the 'name' param of get_terms(). + $get_terms_args = $r; + unset($get_terms_args['name']); + $categories = get_terms($r['taxonomy'], $get_terms_args); + + $name = esc_attr($r['name']); + $class = esc_attr($r['class']); + $id = $r['id'] ? esc_attr($r['id']) : $name; + + if ( ! $r['hide_if_empty'] || ! empty($categories)) { + $output = "<select name='$name' id='$id' class='$class' $tab_index_attribute>\n"; + } else { + $output = ''; + } + + if (empty($categories) && ! $r['hide_if_empty'] && ! empty($r['show_option_none'])) { + $show_option_none = apply_filters('list_cats', $r['show_option_none']); + $output .= "\t<option value='-1' selected='selected'>$show_option_none</option>\n"; + } + if ( ! empty($categories)) { + + if ($r['show_option_all']) { + $show_option_all = apply_filters('list_cats', $$r['show_option_all']); + $selected = ('0' === strval($r['selected'])) ? " selected='selected'" : ''; + $output .= "\t" . '<option value="0"' . $selected . '>' . $show_option_all . '</option>' . "\n"; + } + + if ($r['show_option_none']) { + $show_option_none = apply_filters('list_cats', $r['show_option_none']); + $selected = selected($option_none_value, $r['selected'], false); + $output .= "\t" . + '<option value="' . + esc_attr($option_none_value) . + '"' . + $selected . + '>' . + $show_option_none . + '</option>' . + "\n"; + } + + if ($r['hierarchical']) { + $depth = $r['depth']; // Walk the full depth. + } else { + $depth = - 1; // Flat + } + $output .= walk_category_dropdown_tree($categories, $depth, $r); + } + if ( ! $r['hide_if_empty'] || ! empty($categories)) { + $output .= "</select>\n"; + } + + $output = apply_filters('wp_dropdown_cats', $output, $r); + + if ($r['echo']) { + echo $output; + } + + return $output; + } + + /** + * Display or retrieve the HTML list of categories. + * + * @since 2.1.0 + * @since 4.4.0 Introduced the `hide_title_if_empty` and `separator` arguments. The `current_category` argument was + * modified to optionally accept an array of values. + * + * @param string|array $args { + * Array of optional arguments. + * + * @type string $show_option_all Text to display for showing all categories. Default empty string. + * @type string $show_option_none Text to display for the 'no categories' option. + * Default 'No categories'. + * @type string $orderby The column to use for ordering categories. Default 'ID'. + * @type string $order Which direction to order categories. Accepts 'ASC' or 'DESC'. + * Default 'ASC'. + * @type bool|int $show_count Whether to show how many posts are in the category. Default 0. + * @type bool|int $hide_empty Whether to hide categories that don't have any posts attached to them. + * Default 1. + * @type bool|int $use_desc_for_title Whether to use the category description as the title attribute. + * Default 1. + * @type string $feed Text to use for the feed link. Default 'Feed for all posts filed + * under [cat name]'. + * @type string $feed_type Feed type. Used to build feed link. See {@link get_term_feed_link()}. + * Default empty string (default feed). + * @type string $feed_image URL of an image to use for the feed link. Default empty string. + * @type int $child_of Term ID to retrieve child terms of. See {@link get_terms()}. Default 0. + * @type array|string $exclude Array or comma/space-separated string of term IDs to exclude. + * If `$hierarchical` is true, descendants of `$exclude` terms will + * also be excluded; see `$exclude_tree`. See {@link get_terms()}. + * Default empty string. + * @type array|string $exclude_tree Array or comma/space-separated string of term IDs to exclude, along + * with their descendants. See {@link get_terms()}. Default empty + * string. + * @type bool|int $echo True to echo markup, false to return it. Default 1. + * @type int|array $current_category ID of category, or array of IDs of categories, that should get the + * 'current-cat' class. Default 0. + * @type bool $hierarchical Whether to include terms that have non-empty descendants. + * See {@link get_terms()}. Default true. + * @type string $title_li Text to use for the list title `<li>` element. Pass an empty string + * to disable. Default 'Categories'. + * @type bool $hide_title_if_empty Whether to hide the `$title_li` element if there are no terms in + * the list. Default false (title will always be shown). + * @type int $depth Category depth. Used for tab indentation. Default 0. + * @type string $taxonomy Taxonomy name. Default 'category'. + * @type string $separator Separator between links. Default '<br />'. + * } + * @return false|string HTML content only if 'echo' argument is 0. + */ + public function avh_wp_list_categories($args = '') { + $mywalker = new AVHEC_Walker_Category(); + $defaults = array( + 'child_of' => 0, + 'current_category' => 0, + 'depth' => 0, + 'echo' => 1, + 'exclude' => '', + 'exclude_tree' => '', + 'feed' => '', + 'feed_image' => '', + 'feed_type' => '', + 'hide_empty' => 1, + 'hide_title_if_empty' => false, + 'hierarchical' => true, + 'order' => 'ASC', + 'orderby' => 'name', + 'separator' => '<br />', + 'show_count' => 0, + 'show_last_update' => 0, + 'show_option_all' => '', + 'show_option_none' => __('No categories'), + 'style' => 'list', + 'taxonomy' => 'category', + 'title_li' => __('Categories'), + 'use_desc_for_title' => 1, + 'walker' => $mywalker + ); + + $r = wp_parse_args($args, $defaults); + + if ( ! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) { + $r['pad_counts'] = true; + } + + if (isset($r['show_date'])) { + $r['include_last_update_time'] = $r['show_date']; + } + + if (true == $r['hierarchical']) { + $exclude_tree = array(); + + if ($r['exclude_tree']) { + $exclude_tree = array_merge($exclude_tree, wp_parse_id_list($r['exclude_tree'])); + } + + if ($r['exclude']) { + $exclude_tree = array_merge($exclude_tree, wp_parse_id_list($r['exclude'])); + } + + $r['exclude_tree'] = $exclude_tree; + $r['exclude'] = ''; + } + + if ( ! isset($r['class'])) { + $r['class'] = ('category' == $r['taxonomy']) ? 'categories' : $r['taxonomy']; + } + + if ( ! taxonomy_exists($r['taxonomy'])) { + return false; + } + + $show_option_all = $r['show_option_all']; + $show_option_none = $r['show_option_none']; + + $categories = get_categories($r); + + $output = ''; + if ($r['title_li'] && 'list' == $r['style'] && ( ! empty($categories) || ! $r['hide_title_if_empty'])) { + $output = '<li class="' . esc_attr($r['class']) . '">' . $r['title_li'] . '<ul>'; + } + + if (empty($categories)) { + if ( ! empty($show_option_none)) { + if ('list' == $r['style']) { + $output .= '<li class="cat-item-none">' . __("No categories") . '</li>'; + } else { + $output .= $show_option_none; + } + } + } else { + if ( ! empty($show_option_all)) { + + $posts_page = ''; + $taxonomy_object = get_taxonomy($r['taxonomy']); + + if ( ! in_array('post', $taxonomy_object->object_type) && + ! in_array('page', $taxonomy_object->object_type) + ) { + foreach ($taxonomy_object->object_type as $object_type) { + $_object_type = get_post_type_object($object_type); + + // Grab the first one. + if ( ! empty($_object_type->has_archive)) { + $posts_page = get_post_type_archive_link($object_type); + break; + } + } + } + // Fallback for the 'All' link is the posts page. + if ( ! $posts_page) { + if ('page' == get_option('show_on_front') && get_option('page_for_posts')) { + $posts_page = get_permalink(get_option('page_for_posts')); + } else { + $posts_page = home_url('/'); + } + } + + $posts_page = esc_url($posts_page); + if ('list' == $r['style']) { + $output .= '<li class="cat-item-all"><a href="' . + $posts_page . + '">' . + $show_option_all . + '</a></li>'; + } else { + $output .= '<a href="' . $posts_page . '">' . $show_option_all . '</a>'; + } + } + if (empty($r['current_category']) && (is_category() || is_tax() || is_tag())) { + $current_term_object = get_queried_object(); + if ($current_term_object && $r['taxonomy'] === $current_term_object->taxonomy) { + $r['current_category'] = get_queried_object_id(); + } + } + + if ($r['hierarchical']) { + $depth = $r['depth']; + } else { + $depth = - 1; // Flat. + } + + $output .= walk_category_tree($categories, $depth, $r); + } + + if ($r['title_li'] && 'list' == $r['style']) { + $output .= '</ul></li>'; + } + + $html = apply_filters('wp_list_categories', $output, $args); + + if ($r['echo']) { + echo $html; + } else { + return $html; + } + + return; + } + + /** + * Checks if running version is newer and do upgrades if necessary + * + * @since 1.2.3 + * + * @param string $db_version + */ + public function doUpdateOptions($db_version) { + $options = $this->getOptions(); + + // Add none existing sections and/or elements to the options + foreach ($this->default_options as $section => $default_data) { + if ( ! array_key_exists($section, $options)) { + $options[ $section ] = $default_data; + continue; + } + foreach ($default_data as $element => $default_value) { + if ( ! array_key_exists($element, $options[ $section ])) { + $options[ $section ][ $element ] = $default_value; + } + } + } + + // Remove none existing sections and/or elements from the options + foreach ($options as $section => $data) { + if ( ! array_key_exists($section, $this->default_options)) { + unset($options[ $section ]); + continue; + } + foreach ($data as $element => $value) { + if ( ! array_key_exists($element, $this->default_options[ $section ])) { + unset($options[ $section ][ $element ]); + } + } + } + /** + * Update the options to the latests versions + */ + $options['general']['version'] = $this->version; + $options['general']['dbversion'] = $db_version; + $this->saveOptions($options); + } + + /** + * Get the base directory of a directory structure + * + * @param string $directory + * + * @return string + */ + public function getBaseDirectory($directory) { + // place each directory into array and get the last element + $directory_array = explode('/', $directory); + // get highest or top level in array of directory strings + $public_base = end($directory_array); + + return $public_base; + } + + public function getCategories() { + static $_categories = null; + if (null === $_categories) { + $_categories = get_categories('get=all'); + } + + return $_categories; + } + + public function getCategoriesId($categories) { + static $_categories_id = null; + if (null == $_categories_id) { + foreach ($categories as $key => $category) { + $_categories_id[ $category->term_id ] = $key; + } + } + + return $_categories_id; + } + + /** + * ******************************* + * * + * Methods for variable: options * + * * + * ****************************** + */ + + /** + * Get the value for an option element. + * If there's no option is set on the Admin page, return the default value. + * + * @param string $key + * @param string $option + * + * @return mixed + */ + public function getOptionElement($option, $key) { + if ($this->options[ $option ][ $key ]) { + $return = $this->options[ $option ][ $key ]; // From Admin Page + } else { + $return = $this->default_options[ $option ][ $key ]; // Default + } + + return ($return); + } + + /** + * return array + */ + public function getOptions() { + return ($this->options); + } + + /** + * @param array $options + */ + public function setOptions($options) { + $this->options = $options; + } + + public function handleInitializePlugin() { + global $wpdb; + + /** @var AVH_EC_Category_Group $catgrp */ + $catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); + $db_version = 4; + + $info['siteurl'] = get_option('siteurl'); + $info['plugin_dir'] = AVHEC_PLUGIN_DIR; + $info['graphics_url'] = AVHEC_PLUGIN_URL . '/images'; + + // Set class property for info + $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'] + ); + + // Set the default options + $this->default_options_general = array( + 'version' => $this->version, + 'dbversion' => $db_version, + 'alternative_name_select_category' => '' + ); + + // Set the default category group options + $no_group_id = $catgrp->getTermIDBy('slug', 'none'); + $home_group_id = $catgrp->getTermIDBy('slug', 'home'); + $default_group_id = $catgrp->getTermIDBy('slug', 'all'); + $this->default_options_category_group = array( + 'no_group' => $no_group_id, + 'home_group' => $home_group_id, + 'default_group' => $default_group_id + ); + + $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 + ); + + $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 + ); + + /** + * Set the options for the program + */ + $this->loadOptions(); + + // Check if we have to do updates + if (( ! isset($this->options['general']['dbversion'])) || + $this->options['general']['dbversion'] < $db_version + ) { + $this->doUpdateOptions($db_version); + } + + $db = new AVH_DB(); + if ( ! $db->field_exists('avhec_term_order', $wpdb->terms)) { + $wpdb->query("ALTER TABLE $wpdb->terms ADD `avhec_term_order` INT( 4 ) null DEFAULT '0'"); + } + + $this->handleTextdomain(); + add_filter('get_terms_orderby', array($this, 'applyOrderFilter'), 10, 2); + } + + /** + * Loads the i18n + */ + public function handleTextdomain() { + load_plugin_textdomain('avh-ec', false, AVHEC_RELATIVE_PLUGIN_DIR . '/lang'); + } + + /** + * Used in forms to set the checked option. + * + * @param mixed $checked + * @param mixed_type $current + * + * @return string + * @since 2.0 + */ + public function isChecked($checked, $current) { + if ($checked == $current) { + return (' checked="checked"'); + } + + return (''); + } + + /** + * Used in forms to set the SELECTED option + * + * @param string $current + * @param string $field + * + * @return string + */ + public function isSelected($current, $field) { + if ($current == $field) { + return (' SELECTED'); + } + + return (''); + } + + /** + * Retrieves the plugin options from the WordPress options table and assigns to class variable. + * If the options do not exists, like a new installation, the options are set to the default value. + * + * @return none + */ + public function loadOptions() { + $options = get_option($this->db_options_core); + if (false === $options) { // New installation + $this->resetToDefaultOptions(); + } else { + $this->setOptions($options); + } + } + + /** + * Reset to default options and save in DB + */ + public function resetToDefaultOptions() { + $this->options = $this->default_options; + $this->saveOptions($this->default_options); + } + + /** + * Save all current options and set the options + * + * @param array $options + */ + public function saveOptions($options) { + update_option($this->db_options_core, $options); + wp_cache_flush(); // Delete cache + $this->setOptions($options); + } } /** - * Create HTML list of categories. + * Create HTML dropdown list of Categories. * * @uses Walker */ -class AVHEC_Walker_Category extends Walker -{ - - /** - * - * @see Walker::$tree_type - * @since 2.1.0 - * @var string - */ - public $tree_type = 'category'; - - /** - * - * @see Walker::$db_fields - * @since 2.1.0 - * @todo Decouple this - * @var array - */ - public $db_fields = array('parent' => 'parent', 'id' => 'term_id'); - - /** - * - * @see Walker::start_lvl() - * @since 2.1.0 - * - * @param string $output - * Passed by reference. Used to append additional content. - * @param int $depth - * Depth of category. Used for tab indentation. - * @param array $args - * Will only append content if style argument value is 'list'. - */ - public function start_lvl(&$output, $depth = 0, $args = array()) - { - if ('list' != $args['style']) { - return; - } - - $indent = str_repeat("\t", $depth); - $output .= $indent . '<ul class="children">' . "\n"; - } - - /** - * - * @see Walker::end_lvl() - * @since 2.1.0 - * - * @param string $output - * Passed by reference. Used to append additional content. - * @param int $depth - * Depth of category. Used for tab indentation. - * @param array $args - * Will only append content if style argument value is 'list'. - */ - public function end_lvl(&$output, $depth = 0, $args = array()) - { - if ('list' != $args['style']) { - return; - } - - $indent = str_repeat("\t", $depth); - $output .= $indent . '</ul>' . "\n"; - } - - /** - * - * @see Walker::start_el() - * @since 2.1.0 - * - * @param string $output - * Passed by reference. Used to append additional content. - * @param object $object - * Category data object. - * @param int $depth - * Depth of category in reference to parents. - * @param array $args - */ - public function start_el(&$output, $object, $depth = 0, $args = array(), $current_object_id = 0) - { - extract($args); - - $cat_name = esc_attr($object->name); - $cat_name = apply_filters('list_cats', $cat_name, $object); - $link = '<div class="avhec-widget-line"><a href="' . get_category_link($object->term_id) . '" '; - if ($use_desc_for_title == 0 || empty($object->description)) { - $link .= 'title="' . sprintf(__('View all posts filed under %s'), $cat_name) . '"'; - } else { - $link .= 'title="' . esc_attr(strip_tags(apply_filters('category_description', $object->description, $object))) . '"'; - } - $link .= '>'; - $link .= $cat_name . '</a>'; - - if ((!empty($feed_image)) || (!empty($feed))) { - $link .= '<div class="avhec-widget-rss"> '; - - if (empty($feed_image)) { - $link .= '('; - } - - $link .= '<a href="' . get_category_feed_link($object->term_id, $feed_type) . '"'; - - if (empty($feed)) { - $alt = ' alt="' . sprintf(__('Feed for all posts filed under %s'), $cat_name) . '"'; - } else { - $title = ' title="' . $feed . '"'; - $alt = ' alt="' . $feed . '"'; - $name = $feed; - $link .= $title; - } - - $link .= '>'; - - if (empty($feed_image)) { - $link .= $name; - } else { - $link .= '<img src="' . $feed_image . '"' . $alt . $title . ' />'; - } - $link .= '</a>'; - if (empty($feed_image)) { - $link .= ')'; - } - $link .= '</div>'; - } - - if (isset($show_count) && $show_count) { - $link .= '<div class="avhec-widget-count"> (' . intval($object->count) . ')</div>'; - } - - if (isset($show_date) && $show_date) { - $link .= ' ' . gmdate('Y-m-d', $object->last_update_timestamp); - } - - // When on a single post get the post's category. This ensures that that category will be given the CSS style of "current category". - if (is_single()) { - $post_cats = get_the_category(); - $current_category = $post_cats[0]->term_id; - } - - if (isset($current_category) && $current_category) { - $_current_category = get_category($current_category); - } - - if ('list' == $args['style']) { - $output .= "\t" . '<li'; - $class = 'cat-item cat-item-' . $object->term_id; - if (isset($current_category) && $current_category && ($object->term_id == $current_category)) { - $class .= ' current-cat'; - } elseif (isset($_current_category) && $_current_category && ($object->term_id == $_current_category->parent)) { - $class .= ' current-cat-parent'; - } - $output .= ' class="' . $class . '"'; - $output .= '>' . $link . '</div>' . "\n"; - } else { - $output .= "\t" . $link . '</div><br />' . "\n"; - } - } - - /** - * - * @see Walker::end_el() - * @since 2.1.0 - * - * @param string $output - * Passed by reference. Used to append additional content. - * @param object $page - * Not used. - * @param int $depth - * Depth of category. Not used. - * @param array $args - * Only uses 'list' for whether should append to output. - */ - public function end_el(&$output, $object, $depth = 0, $args = array()) - { - if ('list' != $args['style']) { - return; - } - - $output .= '</li>' . "\n"; - } +class AVH_Walker_CategoryDropdown extends Walker_CategoryDropdown { + public function walk($elements, $max_depth) { + $args = array_slice(func_get_args(), 2); + $output = ''; + + if ($max_depth < - 1) { + return $output; + } + + if (empty($elements)) { + return $output; + } + + $parent_field = $this->db_fields['parent']; + + // flat display + if (- 1 == $max_depth) { + $empty_array = array(); + foreach ($elements as $e) { + $this->display_element($e, $empty_array, 1, 0, $args, $output); + } + + return $output; + } + + /* + * 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. + */ + $top_level_elements = array(); + $children_elements = array(); + foreach ($elements as $e) { + if (0 == $e->$parent_field) { + $top_level_elements[] = $e; + } else { + $children_elements[ $e->$parent_field ][] = $e; + } + } + + /* + * when none of the elements is top level assume the first one must be root of the sub elements + */ + if (empty($top_level_elements)) { + + $first = array_slice($elements, 0, 1); + $root = $first[0]; + + $top_level_elements = array(); + $children_elements = array(); + foreach ($elements as $e) { + if ($root->$parent_field == $e->$parent_field) { + $top_level_elements[] = $e; + } else { + $children_elements[ $e->$parent_field ][] = $e; + } + } + } + + foreach ($top_level_elements as $e) { + $this->display_element($e, $children_elements, $max_depth, 0, $args, $output); + } + + /* + * if we are displaying all levels, and remaining children_elements is not empty, then we got orphans, which should be displayed regardless + */ + if ((0 == $max_depth) && count($children_elements) > 0) { + $empty_array = array(); + foreach ($children_elements as $orphans) { + foreach ($orphans as $op) { + $this->display_element($op, $empty_array, 1, 0, $args, $output); + } + } + } + + return $output; + } } diff --git a/wp-content/plugins/extended-categories-widget/4.2/class/avh-ec.widgets.php b/wp-content/plugins/extended-categories-widget/4.2/class/avh-ec.widgets.php index 941500f329b5c10b884b425b7e3cecd15cddf4b1..10263071c8dfc909bd7b8e1ff7f0e09b6b443a2c 100644 --- a/wp-content/plugins/extended-categories-widget/4.2/class/avh-ec.widgets.php +++ b/wp-content/plugins/extended-categories-widget/4.2/class/avh-ec.widgets.php @@ -1,985 +1,1216 @@ <?php /** - * Widget Class for displaying categories. - * Extended version of the default categories. + * Class that will display the categories */ -class WP_Widget_AVH_ExtendedCategories_Normal extends WP_Widget -{ - - /** - * - * @var AVH_EC_Core - */ - public $core; - - /** - * PHP 5 Constructor - */ - public function __construct() - { - $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core'); - - // Convert the old option widget_extended_categories to widget_extended-categories - $old = get_option('widget_extended_categories'); - if (!(false === $old)) { - update_option('widget_extended-categories', $old); - delete_option('widget_extended_categories'); - } - $widget_ops = array('description' => __("An extended version of the default Categories widget.", 'avh-ec')); - WP_Widget::__construct('extended-categories', 'AVH Extended Categories', $widget_ops); - - add_action('wp_print_styles', array($this, 'actionWpPrintStyles')); - } - - public function actionWpPrintStyles() - { - if (!(false === is_active_widget(false, false, $this->id_base, true))) { - wp_register_style('avhec-widget', AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', array(), $this->core->version); - wp_enqueue_style('avhec-widget'); - } - } - - /** - * Display the widget - * - * @param unknown_type $args - * @param unknown_type $instance - */ - public function widget($args, $instance) - { - extract($args); - - $selectedonly = $instance['selectedonly']; - $c = $instance['count']; - $h = $instance['hierarchical']; - $d = $instance['depth']; - $e = $instance['hide_empty']; - $use_desc_for_title = $instance['use_desc_for_title']; - $s = isset($instance['sort_column']) ? $instance['sort_column'] : 'name'; - $o = isset($instance['sort_order']) ? $instance['sort_order'] : 'asc'; - $r = ($instance['rssfeed'] == true) ? 'RSS' : ''; - $i = isset($instance['rssimage']) ? $instance['rssimage'] : ''; - $invert = $instance['invert_included']; - - if (empty($r)) { - $i = ''; - } - - if (empty($d)) { - $d = 0; - } - - $title = apply_filters('widget_title', empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']); - $style = empty($instance['style']) ? 'list' : $instance['style']; - - $included_cats = ''; - if ($instance['post_category']) { - $post_category = unserialize($instance['post_category']); - $children = array(); - if (!$instance['selectedonly']) { - foreach ($post_category as $cat_id) { - $children = array_merge($children, get_term_children($cat_id, 'category')); - } - } - $included_cats = implode(",", array_merge($post_category, $children)); - } - - if ($invert) { - $inc_exc = 'exclude'; - } else { - $inc_exc = 'include'; - } - - $options = $this->core->getOptions(); - $show_option_none = __('Select Category', 'avh-ec'); - if ($options['general']['alternative_name_select_category']) { - $show_option_none = $options['general']['alternative_name_select_category']; - } - - $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); - echo $before_widget; - echo $this->core->comment; - echo $before_title . $title . $after_title; - - if ($style == 'list') { - echo '<ul>'; - $this->core->avh_wp_list_categories($cat_args); - echo '</ul>'; - } else { - $cat_args['name'] = 'extended-categories-select-' . $this->number; - $this->core->avh_wp_dropdown_categories($cat_args); - echo '<script type=\'text/javascript\'>' . "\n"; - echo '/* <![CDATA[ */' . "\n"; - echo ' var ec_dropdown_' . $this->number . ' = document.getElementById("extended-categories-select-' . $this->number . '");' . "\n"; - echo ' function ec_onCatChange_' . $this->number . '() {' . "\n"; - echo ' if (ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value > 0) {' . "\n"; - echo ' location.href = "' . home_url() . '/?cat="+ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value;' . "\n"; - echo ' }' . "\n"; - echo ' }' . "\n"; - echo ' ec_dropdown_' . $this->number . '.onchange = ec_onCatChange_' . $this->number . ';' . "\n"; - echo '/* ]]> */' . "\n"; - echo '</script>' . "\n"; - } - echo $after_widget; - } - - /** - * When Widget Control Form Is Posted - * - * @param unknown_type $new_instance - * @param unknown_type $old_instance - * @return unknown - */ - public function update($new_instance, $old_instance) - { - // update the instance's settings - if (!isset($new_instance['submit'])) { - return false; - } - - $instance = $old_instance; - - $instance['title'] = strip_tags(stripslashes($new_instance['title'])); - $instance['selectedonly'] = isset($new_instance['selectedonly']); - $instance['count'] = isset($new_instance['count']); - $instance['hierarchical'] = isset($new_instance['hierarchical']); - $instance['hide_empty'] = isset($new_instance['hide_empty']); - $instance['use_desc_for_title'] = isset($new_instance['use_desc_for_title']); - $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column'])); - $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order'])); - $instance['style'] = strip_tags(stripslashes($new_instance['style'])); - $instance['rssfeed'] = isset($new_instance['rssfeed']); - $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage'])); - if (array_key_exists('all', $new_instance['post_category'])) { - $instance['post_category'] = false; - } else { - $instance['post_category'] = serialize($new_instance['post_category']); - } - $instance['depth'] = (int) $new_instance['depth']; - if ($instance['depth'] < 0 || 11 < $instance['depth']) { - $instance['depth'] = 0; - } - $instance['invert_included'] = isset($new_instance['invert_included']); - - return $instance; - } - - /** - * Display Widget Control Form - * - * @param unknown_type $instance - */ - public function form($instance) - { - // displays the widget admin form - $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => '', 'depth' => 0)); - - // Prepare data for display - $depth = (int) $instance['depth']; - if ($depth < 0 || 11 < $depth) { - $depth = 0; - } - $selected_cats = (avhGetArrayValue($instance, 'post_category') !== '') ? unserialize($instance['post_category']) : false; - - echo '<p>'; - avh_doWidgetFormText($this->get_field_id('title'), $this->get_field_name('title'), __('Title', 'avh-ec'), avhGetArrayValue($instance, 'title')); - echo '</p>'; - - echo '<p>'; - avh_doWidgetFormCheckbox($this->get_field_id('selectedonly'), $this->get_field_name('selectedonly'), __('Show selected categories only', 'avh-ec'), (bool) avhGetArrayValue($instance, 'selectedonly')); - - avh_doWidgetFormCheckbox($this->get_field_id('count'), $this->get_field_name('count'), __('Show post counts', 'avh-ec'), (bool) avhGetArrayValue($instance, 'count')); - - avh_doWidgetFormCheckbox($this->get_field_id('hierarchical'), $this->get_field_name('hierarchical'), __('Show hierarchy', 'avh-ec'), (bool) avhGetArrayValue($instance, 'hierarchical')); - - $options = array(0 => __('All Levels', 'avh-ec'), 1 => __('Toplevel only', 'avh-ec')); - for ($i = 2; $i <= 11; $i++) { - $options[$i] = __('Child ', 'avh-ec') . ($i - 1); - } - avh_doWidgetFormSelect($this->get_field_id('depth'), $this->get_field_name('depth'), __('How many levels to show', 'avh-ec'), $options, $depth); - unset($options); - - avh_doWidgetFormCheckbox($this->get_field_id('hide_empty'), $this->get_field_name('hide_empty'), __('Hide empty categories', 'avh-ec'), (bool) avhGetArrayValue($instance, 'hide_empty')); - - 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')); - echo '</p>'; - - echo '<p>'; - $options['ID'] = __('ID', 'avh-ec'); - $options['name'] = __('Name', 'avh-ec'); - $options['count'] = __('Count', 'avh-ec'); - $options['slug'] = __('Slug', 'avh-ec'); - $options['avhec_manualorder'] = 'AVH EC ' . __('Manual Order', 'avh-ec'); - if (is_plugin_active('my-category-order/mycategoryorder.php')) { - $options['avhec_3rdparty_mycategoryorder'] = 'My Category Order'; - } - - avh_doWidgetFormSelect($this->get_field_id('sort_column'), $this->get_field_name('sort_column'), __('Sort by', 'avh-ec'), $options, avhGetArrayValue($instance, 'sort_column')); - unset($options); - - $options['asc'] = __('Ascending', 'avh-ec'); - $options['desc'] = __('Descending', 'avh-ec'); - avh_doWidgetFormSelect($this->get_field_id('sort_order'), $this->get_field_name('sort_order'), __('Sort order', 'avh-ec'), $options, avhGetArrayValue($instance, 'sort_order')); - unset($options); - - $options['list'] = __('List', 'avh-ec'); - $options['drop'] = __('Drop down', 'avh-ec'); - avh_doWidgetFormSelect($this->get_field_id('style'), $this->get_field_name('style'), __('Display style', 'avh-ec'), $options, avhGetArrayValue($instance, 'style')); - unset($options); - echo '</p>'; - - echo '<p>'; - - avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), $this->get_field_name('rssfeed'), __('Show RSS Feed', 'avh-ec'), (bool) avhGetArrayValue($instance, 'rssfeed')); - - avh_doWidgetFormText($this->get_field_id('rssimage'), $this->get_field_name('rssimage'), __('Path (URI) to RSS image', 'avh-ec'), avhGetArrayValue($instance, 'rssimage')); - - echo '</p>'; - - echo '<p>'; - echo '<b>' . __('Select categories', 'avh-ec') . '</b><hr />'; - 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;">'; - echo '<li id="' . $this->get_field_id('category--1') . '" class="popular-category">'; - echo '<label for="' . $this->get_field_id('post_category') . '" class="selectit">'; - 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' : '') . '> '; - _e('All Categories', 'avh-ec'); - echo '</label>'; - echo '</li>'; - ob_start(); - $this->avh_wp_category_checklist($selected_cats, $this->number); - ob_end_flush(); - echo '</ul>'; - echo '</p>'; - - echo '<p>'; - 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')); - echo '</p>'; - - echo '<input type="hidden" id="' . $this->get_field_id('submit') . '" name="' . $this->get_field_name('submit') . '" value="1" />'; - } - - /** - * Creates the categories checklist - * - * @param int $post_id - * @param int $descendants_and_self - * @param array $selected_cats - * @param array $popular_cats - * @param int $number - */ - public function avh_wp_category_checklist($selected_cats, $number) - { - $walker = new AVH_Walker_Category_Checklist(); - $walker->number = $number; - $walker->input_id = $this->get_field_id('post_category'); - $walker->input_name = $this->get_field_name('post_category'); - $walker->li_id = $this->get_field_id('category--1'); - - $args = array('taxonomy' => 'category', 'descendants_and_self' => 0, 'selected_cats' => $selected_cats, 'popular_cats' => array(), 'walker' => $walker, 'checked_ontop' => true, 'popular_cats' => array()); - - if (is_array($selected_cats)) { - $args['selected_cats'] = $selected_cats; - } else { - $args['selected_cats'] = array(); - } - - $categories = $this->core->getCategories(); - $_categories_id = $this->core->getCategoriesId($categories); - - // 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) - $checked_categories = array(); - foreach ($args['selected_cats'] as $key => $value) { - if (isset($_categories_id[$key])) { - $category_key = $_categories_id[$key]; - $checked_categories[] = $categories[$category_key]; - unset($categories[$category_key]); - } - } - - // Put checked cats on top - echo $walker->walk($checked_categories, 0, $args); - // Then the rest of them - echo $walker->walk($categories, 0, $args); - } +class AVH_Walker_Category_Checklist extends Walker { + public $db_fields = array('parent' => 'parent', 'id' => 'term_id'); + public $input_id; // TODO: decouple this + public $input_name; + public $li_id; + public $number; + public $tree_type = 'category'; + + public function end_el(&$output, $object, $depth = 0, $args = array()) { + $output .= "</li>\n"; + } + + public function end_lvl(&$output, $depth = 0, $args = array()) { + $indent = str_repeat("\t", $depth); + $output .= $indent . '</ul>' . "\n"; + } + + public function start_el(&$output, $object, $depth = 0, $args = array(), $current_object_id = 0) { + $args['selected_cats'] = empty($args['selected_cats']) ? array() : $args['selected_cats']; + $input_id = $this->input_id . '-' . $object->term_id; + $output .= "\n" . '<li id="' . $this->li_id . '">'; + $output .= '<label for="' . $input_id . '" class="selectit">'; + $output .= '<input value="' . + $object->term_id . + '" type="checkbox" name="' . + $this->input_name . + '[' . + $object->term_id . + ']" id="' . + $input_id . + '"' . + (in_array($object->term_id, $args['selected_cats']) ? ' checked="checked"' : "") . + '/> ' . + esc_html(apply_filters('the_category', $object->name)) . + '</label>'; + } + + public function start_lvl(&$output, $depth = 0, $args = array()) { + $indent = str_repeat("\t", $depth); + $output .= $indent . '<ul class="children">' . "\n"; + } + + /** + * Display array of elements hierarchically. + * It is a generic function which does not assume any existing order of + * elements. max_depth = -1 means flatly display every element. max_depth = + * 0 means display all levels. max_depth > 0 specifies the number of + * display levels. + * + * @since 2.1.0 + * + * @param array $elements + * @param int $max_depth + * + * @return string + */ + public function walk($elements, $max_depth) { + $args = array_slice(func_get_args(), 2); + $output = ''; + + if ($max_depth < - 1) { + return $output; + } + + if (empty($elements)) { // nothing to walk + return $output; + } + + $parent_field = $this->db_fields['parent']; + + // flat display + if (- 1 == $max_depth) { + $empty_array = array(); + foreach ($elements as $e) { + $this->display_element($e, $empty_array, 1, 0, $args, $output); + } + + return $output; + } + + /* + * 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. + */ + $top_level_elements = array(); + $children_elements = array(); + foreach ($elements as $e) { + if (0 == $e->$parent_field) { + $top_level_elements[] = $e; + } else { + $children_elements[ $e->$parent_field ][] = $e; + } + } + + /* + * when none of the elements is top level assume the first one must be root of the sub elements + */ + if (empty($top_level_elements)) { + + $first = array_slice($elements, 0, 1); + $root = $first[0]; + + $top_level_elements = array(); + $children_elements = array(); + foreach ($elements as $e) { + if ($root->$parent_field == $e->$parent_field) { + $top_level_elements[] = $e; + } else { + $children_elements[ $e->$parent_field ][] = $e; + } + } + } + + foreach ($top_level_elements as $e) { + $this->display_element($e, $children_elements, $max_depth, 0, $args, $output); + } + + /* + * if we are displaying all levels, and remaining children_elements is not empty, then we got orphans, which should be displayed regardless + */ + if (($max_depth == 0) && count($children_elements) > 0) { + $empty_array = array(); + foreach ($children_elements as $orphans) { + foreach ($orphans as $op) { + $this->display_element($op, $empty_array, 1, 0, $args, $output); + } + } + } + + return $output; + } } /** - * Widget Class for displaying the top categories + * Widget Class for displaying the grouped categories */ -class WP_Widget_AVH_ExtendedCategories_Top extends WP_Widget -{ - - /** - * - * @var AVH_EC_Core - */ - public $core; - - /** - * PHP 5 Constructor - */ - public function __construct() - { - $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core'); - - $widget_ops = array('description' => __("Shows the top categories.", 'avh-ec')); - WP_Widget::__construct(false, 'AVH Extended Categories: ' . __('Top Categories'), $widget_ops); - add_action('wp_print_styles', array($this, 'actionWpPrintStyles')); - } - - public function actionWpPrintStyles() - { - if (!(false === is_active_widget(false, false, $this->id_base, true))) { - wp_register_style('avhec-widget', AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', array(), $this->core->version); - wp_enqueue_style('avhec-widget'); - } - } - - /** - * Echo the widget content. - * - * Subclasses should over-ride this function to generate their widget code. - * - * @param array $args - * Display arguments including before_title, after_title, before_widget, and after_widget. - * @param array $instance - * The settings for the particular instance of the widget - */ - public function widget($args, $instance) - { - extract($args); - - $title = apply_filters('widget_title', empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']); - $style = empty($instance['style']) ? 'list' : $instance['style']; - if (!$a = (int) $instance['amount']) { - $a = 5; - } elseif ($a < 1) { - $a = 1; - } - $c = $instance['count']; - $use_desc_for_title = $instance['use_desc_for_title']; - $s = isset($instance['sort_column']) ? $instance['sort_column'] : 'name'; - $o = isset($instance['sort_order']) ? $instance['sort_order'] : 'asc'; - $r = ($instance['rssfeed'] === true) ? 'RSS' : ''; - $i = isset($instance['rssimage']) ? $instance['rssimage'] : ''; - if (empty($r)) { - $i = ''; - } - if (!empty($i)) { - if (!file_exists(ABSPATH . '/' . $i)) { - $i = ''; - } - } - - $options = $this->core->getOptions(); - $show_option_none = __('Select Category', 'avh-ec'); - if ($options['general']['alternative_name_select_category']) { - $show_option_none = $options['general']['alternative_name_select_category']; - } - - $top_cats = get_terms('category', array('fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => $a, 'hierarchical' => false)); - $included_cats = implode(",", $top_cats); - - $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); - echo $before_widget; - echo $this->core->comment; - echo $before_title . $title . $after_title; - echo '<ul>'; - - if ($style == 'list') { - wp_list_categories($cat_args); - } else { - $cat_args['name'] = 'extended-categories-top-select-' . $this->number; - wp_dropdown_categories($cat_args); - echo '<script type=\'text/javascript\'>' . "\n"; - echo '/* <![CDATA[ */' . "\n"; - echo ' var ec_dropdown_top_' . $this->number . ' = document.getElementById("extended-categories-top-select-' . $this->number . '");' . "\n"; - echo ' function ec_top_onCatChange_' . $this->number . '() {' . "\n"; - echo ' if (ec_dropdown_top_' . $this->number . '.options[ec_dropdown_top_' . $this->number . '.selectedIndex].value > 0) {' . "\n"; - echo ' location.href = "' . get_option('home') . '/?cat="+ec_dropdown_top_' . $this->number . '.options[ec_dropdown_top_' . $this->number . '.selectedIndex].value;' . "\n"; - echo ' }' . "\n"; - echo ' }' . "\n"; - echo ' ec_dropdown_top_' . $this->number . '.onchange = ec_top_onCatChange_' . $this->number . ';' . "\n"; - echo '/* ]]> */' . "\n"; - echo '</script>' . "\n"; - } - echo '</ul>'; - echo $after_widget; - } - - /** - * Update a particular instance. - * - * This function should check that $new_instance is set correctly. - * The newly calculated value of $instance should be returned. - * If "false" is returned, the instance won't be saved/updated. - * - * @param array $new_instance - * New settings for this instance as input by the user via form() - * @param array $old_instance - * Old settings for this instance - * @return array Settings to save or bool false to cancel saving - */ - public function update($new_instance, $old_instance) - { - // update the instance's settings - if (!isset($new_instance['submit'])) { - return false; - } - - $instance = $old_instance; - - $instance['title'] = strip_tags(stripslashes($new_instance['title'])); - $instance['amount'] = (int) $new_instance['amount']; - $instance['count'] = isset($new_instance['count']); - $instance['use_desc_for_title'] = isset($new_instance['use_desc_for_title']); - $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column'])); - $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order'])); - $instance['style'] = strip_tags(stripslashes($new_instance['style'])); - $instance['rssfeed'] = isset($new_instance['rssfeed']); - $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage'])); - - return $instance; - } - - /** - * Echo the settings update form - * - * @param array $instance - * Current settings - */ - public function form($instance) - { - // displays the widget admin form - $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => '', 'amount' => '5')); - - $amount = (int) avhGetArrayValue($instance, 'amount'); - if ($amount < 1) { - $amount = 1; - } - echo '<p>'; - avh_doWidgetFormText($this->get_field_id('title'), $this->get_field_name('title'), __('Title', 'avh-ec'), avhGetArrayValue($instance, 'title')); - echo '</p>'; - - echo '<p>'; - avh_doWidgetFormText($this->get_field_id('amount'), $this->get_field_name('amount'), __('How many categories to show', 'avh-ec'), $amount); - echo '</p>'; - - echo '<p>'; - avh_doWidgetFormCheckbox($this->get_field_id('count'), $this->get_field_name('count'), __('Show post counts', 'avh-ec'), (bool) avhGetArrayValue($instance, 'count')); - echo '<br />'; - - 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')); - echo '</p>'; - - echo '<p>'; - $options['ID'] = __('ID', 'avh-ec'); - $options['name'] = __('Name', 'avh-ec'); - $options['count'] = __('Count', 'avh-ec'); - $options['slug'] = __('Slug', 'avh-ec'); - avh_doWidgetFormSelect($this->get_field_id('sort_column'), $this->get_field_name('sort_column'), __('Sort by', 'avh-ec'), $options, avhGetArrayValue($instance, 'sort_column')); - unset($options); - - $options['asc'] = __('Ascending', 'avh-ec'); - $options['desc'] = __('Descending', 'avh-ec'); - avh_doWidgetFormSelect($this->get_field_id('sort_order'), $this->get_field_name('sort_order'), __('Sort order', 'avh-ec'), $options, avhGetArrayValue($instance, 'sort_order')); - unset($options); - - $options['list'] = __('List', 'avh-ec'); - $options['drop'] = __('Drop down', 'avh-ec'); - avh_doWidgetFormSelect($this->get_field_id('style'), $this->get_field_name('style'), __('Display style', 'avh-ec'), $options, avhGetArrayValue($instance, 'style')); - unset($options); - echo '</p>'; - - echo '<p>'; - - avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), $this->get_field_name('rssfeed'), __('Show RSS Feed', 'avh-ec'), (bool) avhGetArrayValue($instance, 'rssfeed')); - - avh_doWidgetFormText($this->get_field_id('rssimage'), $this->get_field_name('rssimage'), __('Path (URI) to RSS image', 'avh-ec'), avhGetArrayValue($instance, 'rssimage')); - - echo '</p>'; - - echo '<input type="hidden" id="' . $this->get_field_id('submit') . '" name="' . $this->get_field_name('submit') . '" value="1" />'; - } +class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget { + /** + * @var AVH_EC_Category_Group + */ + public $catgrp; + /** + * @var AVH_EC_Core + */ + public $core; + + /** + * PHP 5 Constructor + */ + public function __construct() { + $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core'); + $this->catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); + + $widget_ops = array('description' => __("Shows grouped categories.", 'avh-ec')); + WP_Widget::__construct(false, 'AVH Extended Categories: ' . __('Category Group'), $widget_ops); + add_action('wp_print_styles', array($this, 'actionWpPrintStyles')); + } + + public function actionWpPrintStyles() { + if ( ! (false === is_active_widget(false, false, $this->id_base, true))) { + wp_register_style('avhec-widget', + AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', + array(), + $this->core->version); + wp_enqueue_style('avhec-widget'); + } + } + + public function avh_wp_group_category_checklist($selected_cats, $number) { + $walker = new AVH_Walker_Category_Checklist(); + $walker->number = $number; + $walker->input_id = $this->get_field_id('post_group_category'); + $walker->input_name = $this->get_field_name('post_group_category'); + $walker->li_id = $this->get_field_id('group_category--1'); + + $args = array( + 'taxonomy' => 'avhec_catgroup', + 'descendants_and_self' => 0, + 'selected_cats' => array(), + 'popular_cats' => array(), + 'walker' => $walker, + 'checked_ontop' => true + ); + + if (is_array($selected_cats)) { + $args['selected_cats'] = $selected_cats; + } else { + $args['selected_cats'] = array(); + } + + $categories = (array) get_terms($args['taxonomy'], array('get' => 'all')); + + // 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) + $checked_categories = array(); + $keys = array_keys($categories); + + foreach ($keys as $k) { + if (in_array($categories[ $k ]->term_id, $args['selected_cats'])) { + $checked_categories[] = $categories[ $k ]; + unset($categories[ $k ]); + } + } + + // Put checked cats on top + echo $walker->walk($checked_categories, 0, $args); + // Then the rest of them + echo $walker->walk($categories, 0, $args); + } + + /** + * Display Widget Control Form + * + * @param array $instance + * + * @return string|void + */ + public function form($instance) { + // displays the widget admin form + $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => '')); + + $selected_cats = (avhGetArrayValue($instance, 'post_group_category') !== + '') ? unserialize($instance['post_group_category']) : false; + ob_start(); + echo '<p>'; + avh_doWidgetFormText($this->get_field_id('title'), + $this->get_field_name('title'), + __('Title', 'avh-ec'), + $instance['title']); + echo '</p>'; + + echo '<p>'; + + avh_doWidgetFormCheckbox($this->get_field_id('count'), + $this->get_field_name('count'), + __('Show post counts', 'avh-ec'), + (bool) avhGetArrayValue($instance, 'count')); + + avh_doWidgetFormCheckbox($this->get_field_id('hierarchical'), + $this->get_field_name('hierarchical'), + __('Show hierarchy', 'avh-ec'), + (bool) avhGetArrayValue($instance, 'hierarchical')); + + avh_doWidgetFormCheckbox($this->get_field_id('hide_empty'), + $this->get_field_name('hide_empty'), + __('Hide empty categories', 'avh-ec'), + (bool) avhGetArrayValue($instance, 'hide_empty')); + + 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')); + echo '</p>'; + + echo '<p>'; + $options['ID'] = __('ID', 'avh-ec'); + $options['name'] = __('Name', 'avh-ec'); + $options['count'] = __('Count', 'avh-ec'); + $options['slug'] = __('Slug', 'avh-ec'); + avh_doWidgetFormSelect($this->get_field_id('sort_column'), + $this->get_field_name('sort_column'), + __('Sort by', 'avh-ec'), + $options, + avhGetArrayValue($instance, 'sort_column')); + unset($options); + + $options['asc'] = __('Ascending', 'avh-ec'); + $options['desc'] = __('Descending', 'avh-ec'); + avh_doWidgetFormSelect($this->get_field_id('sort_order'), + $this->get_field_name('sort_order'), + __('Sort order', 'avh-ec'), + $options, + avhGetArrayValue($instance, 'sort_order')); + unset($options); + + $options['list'] = __('List', 'avh-ec'); + $options['drop'] = __('Drop down', 'avh-ec'); + avh_doWidgetFormSelect($this->get_field_id('style'), + $this->get_field_name('style'), + __('Display style', 'avh-ec'), + $options, + avhGetArrayValue($instance, 'style')); + unset($options); + echo '</p>'; + + echo '<p>'; + + avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), + $this->get_field_name('rssfeed'), + __('Show RSS Feed', 'avh-ec'), + (bool) avhGetArrayValue($instance, 'rssfeed')); + + avh_doWidgetFormText($this->get_field_id('rssimage'), + $this->get_field_name('rssimage'), + __('Path (URI) to RSS image', 'avh-ec'), + avhGetArrayValue($instance, 'rssimage')); + echo '</p>'; + + echo '<p>'; + echo '<b>' . __('Select Groups', 'avh-ec') . '</b><hr />'; + echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear" style="list-style-type: none; margin-left: 5px; padding-left: 0; margin-bottom: 20px;">'; + echo '<li id="' . $this->get_field_id('group_category--1') . '" class="popular-group_category">'; + echo '<label for="' . $this->get_field_id('group_post_category') . '" class="selectit">'; + 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' : '') . + '> '; + _e('Any Group', 'avh-ec'); + echo '</label>'; + echo '</li>'; + + $this->avh_wp_group_category_checklist($selected_cats, $this->number); + + echo '</ul>'; + echo '</p>'; + + echo '<input type="hidden" id="' . + $this->get_field_id('submit') . + '" name="' . + $this->get_field_name('submit') . + '" value="1" />'; + ob_end_flush(); + } + + public function getWidgetDoneCatGroup($id) { + $catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); + if (is_array($catgrp->widget_done_catgroup) && array_key_exists($id, $catgrp->widget_done_catgroup)) { + return true; + } + $catgrp->widget_done_catgroup[ $id ] = true; + + return false; + } + + /** + * When Widget Control Form Is Posted + * + * @param array $new_instance + * @param array $old_instance + * + * @return array|bool + */ + public function update($new_instance, $old_instance) { + // update the instance's settings + if ( ! isset($new_instance['submit'])) { + return false; + } + + $instance = $old_instance; + + $instance['title'] = strip_tags(stripslashes($new_instance['title'])); + $instance['count'] = isset($new_instance['count']); + $instance['hierarchical'] = isset($new_instance['hierarchical']); + $instance['hide_empty'] = isset($new_instance['hide_empty']); + $instance['use_desc_for_title'] = isset($new_instance['use_desc_for_title']); + $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column'])); + $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order'])); + $instance['style'] = strip_tags(stripslashes($new_instance['style'])); + $instance['rssfeed'] = isset($new_instance['rssfeed']); + $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage'])); + if (array_key_exists('all', $new_instance['post_group_category'])) { + $instance['post_group_category'] = false; + } else { + $instance['post_group_category'] = serialize($new_instance['post_group_category']); + } + + return $instance; + } + + /** + * Display the widget + * + * @param array $args + * @param array $instance + */ + public function widget($args, $instance) { + global $post, $wp_query; + + $catgrp = &AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); + $options = $this->core->getOptions(); + + $row = array(); + + if (is_home()) { + $special_page = 'home_group'; + } elseif (is_category()) { + $special_page = 'category_group'; + } elseif (is_day()) { + $special_page = 'day_group'; + } elseif (is_month()) { + $special_page = 'month_group'; + } elseif (is_year()) { + $special_page = 'year_group'; + } elseif (is_author()) { + $special_page = 'author_group'; + } elseif (is_search()) { + $special_page = 'search_group'; + } else { + $special_page = 'none'; + } + + $toDisplay = false; + if ('none' == $special_page) { + $terms = wp_get_object_terms($post->ID, $catgrp->taxonomy_name); + if ( ! empty($terms)) { + $selected_catgroups = unserialize($instance['post_group_category']); + foreach ($terms as $key => $value) { + if ($selected_catgroups === false || array_key_exists($value->term_id, $selected_catgroups)) { + if ( ! ($this->getWidgetDoneCatGroup($value->term_id))) { + $row = $value; + $group_found = true; + break; + } + } + } + } else { + $options = $this->core->options; + $no_cat_group = $options['cat_group']['no_group']; + $row = get_term_by('id', $no_cat_group, $catgrp->taxonomy_name); + $group_found = true; + } + } else { + if ('category_group' == $special_page) { + $tax_meta = get_option($this->core->db_options_tax_meta); + $term = $wp_query->get_queried_object(); + if (isset($tax_meta[ $term->taxonomy ][ $term->term_id ]['category_group_term_id'])) { + $sp_category_group_id = $tax_meta[ $term->taxonomy ][ $term->term_id ]['category_group_term_id']; + } else { + $sp_category_group = $this->catgrp->getGroupByCategoryID($term->term_id); + $sp_category_group_id = $sp_category_group->term_id; + } + } else { + $sp_category_group_id = $options['sp_cat_group'][ $special_page ]; + } + $row = get_term_by('id', + $sp_category_group_id, + $catgrp->taxonomy_name); // Returns false when non-existance. (empty(false)=true) + $group_found = true; + } + + if ($group_found) { + $toDisplay = true; + $category_group_id_none = $this->catgrp->getTermIDBy('slug', 'none'); + $selected_catgroups = unserialize($instance['post_group_category']); + + if ($category_group_id_none == $row->term_id) { + $toDisplay = false; + } elseif ( ! (false == $selected_catgroups || array_key_exists($row->term_id, $selected_catgroups))) { + $toDisplay = false; + } elseif ($special_page != 'none' && $this->getWidgetDoneCatGroup($sp_category_group_id)) { + $toDisplay = false; + } + } + + if ($toDisplay) { + + $c = $instance['count']; + $e = $instance['hide_empty']; + $h = $instance['hierarchical']; + $use_desc_for_title = $instance['use_desc_for_title']; + $s = isset($instance['sort_column']) ? $instance['sort_column'] : 'name'; + $o = isset($instance['sort_order']) ? $instance['sort_order'] : 'asc'; + $r = $instance['rssfeed'] ? 'RSS' : ''; + $i = $instance['rssimage'] ? $instance['rssimage'] : ''; + + if (empty($r)) { + $i = ''; + } + + $style = empty($instance['style']) ? 'list' : $instance['style']; + $group_id = $row->term_id; + $cats = $catgrp->getCategoriesFromGroup($group_id); + if (empty($instance['title'])) { + $title = $catgrp->getWidgetTitleForGroup($group_id); + if ( ! $title) { + $title = __('Categories', 'avh-ec'); + } + } else { + $title = $instance['title']; + } + $title = apply_filters('widget_title', $title); + + $included_cats = implode(',', $cats); + + $show_option_none = __('Select Category', 'avh-ec'); + if ($options['general']['alternative_name_select_category']) { + $show_option_none = $options['general']['alternative_name_select_category']; + } + + $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 + ); + echo $args['before_widget']; + echo $this->core->comment; + echo $args['before_title'] . $title . $args['after_title']; + + if ($style == 'list') { + echo '<ul>'; + $this->core->avh_wp_list_categories($cat_args, true); + echo '</ul>'; + } else { + $cat_args['name'] = 'extended-categories-select-group-' . $this->number; + $this->core->avh_wp_dropdown_categories($cat_args, true); + echo '<script type=\'text/javascript\'>' . "\n"; + echo '/* <![CDATA[ */' . "\n"; + echo ' var ec_dropdown_' . + $this->number . + ' = document.getElementById("extended-categories-select-group-' . + $this->number . + '");' . + "\n"; + echo ' function ec_onCatChange_' . $this->number . '() {' . "\n"; + echo ' if (ec_dropdown_' . + $this->number . + '.options[ec_dropdown_' . + $this->number . + '.selectedIndex].value > 0) {' . + "\n"; + echo ' location.href = "' . + get_option('home') . + '/?cat="+ec_dropdown_' . + $this->number . + '.options[ec_dropdown_' . + $this->number . + '.selectedIndex].value;' . + "\n"; + echo ' }' . "\n"; + echo ' }' . "\n"; + echo ' ec_dropdown_' . + $this->number . + '.onchange = ec_onCatChange_' . + $this->number . + ';' . + "\n"; + echo '/* ]]> */' . "\n"; + echo '</script>' . "\n"; + } + echo $args['after_widget']; + } + } } /** - * Widget Class for displaying the grouped categories + * Widget Class for displaying categories. + * Extended version of the default categories. */ -class WP_Widget_AVH_ExtendedCategories_Category_Group extends WP_Widget -{ - - /** - * - * @var AVH_EC_Core - */ - public $core; - - /** - * - * @var AVH_EC_Category_Group - */ - public $catgrp; - - /** - * PHP 5 Constructor - */ - public function __construct() - { - $this->core = & AVH_EC_Singleton::getInstance('AVH_EC_Core'); - $this->catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); - - $widget_ops = array('description' => __("Shows grouped categories.", 'avh-ec')); - WP_Widget::__construct(false, 'AVH Extended Categories: ' . __('Category Group'), $widget_ops); - add_action('wp_print_styles', array($this, 'actionWpPrintStyles')); - } - - public function actionWpPrintStyles() - { - if (!(false === is_active_widget(false, false, $this->id_base, true))) { - wp_register_style('avhec-widget', AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', array(), $this->core->version); - wp_enqueue_style('avhec-widget'); - } - } - - /** - * Display the widget - * - * @param unknown_type $args - * @param unknown_type $instance - */ - public function widget($args, $instance) - { - global $post, $wp_query; - - $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); - $options = $this->core->getOptions(); - - $row = array(); - - if (is_home()) { - $special_page = 'home_group'; - } elseif (is_category()) { - $special_page = 'category_group'; - } elseif (is_day()) { - $special_page = 'day_group'; - } elseif (is_month()) { - $special_page = 'month_group'; - } elseif (is_year()) { - $special_page = 'year_group'; - } elseif (is_author()) { - $special_page = 'author_group'; - } elseif (is_search()) { - $special_page = 'search_group'; - } else { - $special_page = 'none'; - } - - $toDisplay = false; - if ('none' == $special_page) { - $terms = wp_get_object_terms($post->ID, $catgrp->taxonomy_name); - if (!empty($terms)) { - $selected_catgroups = unserialize($instance['post_group_category']); - foreach ($terms as $key => $value) { - if ($selected_catgroups === false || array_key_exists($value->term_id, $selected_catgroups)) { - if (!($this->getWidgetDoneCatGroup($value->term_id))) { - $row = $value; - $group_found = true; - break; - } - } - } - } else { - $options = $this->core->options; - $no_cat_group = $options['cat_group']['no_group']; - $row = get_term_by('id', $no_cat_group, $catgrp->taxonomy_name); - $group_found = true; - } - } else { - if ('category_group' == $special_page) { - $tax_meta = get_option($this->core->db_options_tax_meta); - $term = $wp_query->get_queried_object(); - if (isset($tax_meta[$term->taxonomy][$term->term_id]['category_group_term_id'])) { - $sp_category_group_id = $tax_meta[$term->taxonomy][$term->term_id]['category_group_term_id']; - } else { - $sp_category_group = $this->catgrp->getGroupByCategoryID($term->term_id); - $sp_category_group_id = $sp_category_group->term_id; - } - } else { - $sp_category_group_id = $options['sp_cat_group'][$special_page]; - } - $row = get_term_by('id', $sp_category_group_id, $catgrp->taxonomy_name); // Returns false when non-existance. (empty(false)=true) - $group_found = true; - } - - if ($group_found) { - $toDisplay = true; - $category_group_id_none = $this->catgrp->getTermIDBy('slug', 'none'); - $selected_catgroups = unserialize($instance['post_group_category']); - - if ($category_group_id_none == $row->term_id) { - $toDisplay = false; - } elseif (!(false == $selected_catgroups || array_key_exists($row->term_id, $selected_catgroups))) { - $toDisplay = false; - } elseif ($special_page != 'none' && $this->getWidgetDoneCatGroup($sp_category_group_id)) { - $toDisplay = false; - } - } - - if ($toDisplay) { - extract($args); - - $c = $instance['count']; - $e = $instance['hide_empty']; - $h = $instance['hierarchical']; - $use_desc_for_title = $instance['use_desc_for_title']; - $s = isset($instance['sort_column']) ? $instance['sort_column'] : 'name'; - $o = isset($instance['sort_order']) ? $instance['sort_order'] : 'asc'; - $r = $instance['rssfeed'] ? 'RSS' : ''; - $i = $instance['rssimage'] ? $instance['rssimage'] : ''; - - if (empty($r)) { - $i = ''; - } - - $style = empty($instance['style']) ? 'list' : $instance['style']; - $group_id = $row->term_id; - $cats = $catgrp->getCategoriesFromGroup($group_id); - if (empty($instance['title'])) { - $title = $catgrp->getWidgetTitleForGroup($group_id); - if (!$title) { - $title = __('Categories', 'avh-ec'); - } - } else { - $title = $instance['title']; - } - $title = apply_filters('widget_title', $title); - - $included_cats = implode(',', $cats); - - $show_option_none = __('Select Category', 'avh-ec'); - if ($options['general']['alternative_name_select_category']) { - $show_option_none = $options['general']['alternative_name_select_category']; - } - - $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); - echo $before_widget; - echo $this->core->comment; - echo $before_title . $title . $after_title; - - if ($style == 'list') { - echo '<ul>'; - $this->core->avh_wp_list_categories($cat_args, true); - echo '</ul>'; - } else { - $cat_args['name'] = 'extended-categories-select-group-' . $this->number; - $this->core->avh_wp_dropdown_categories($cat_args, true); - echo '<script type=\'text/javascript\'>' . "\n"; - echo '/* <![CDATA[ */' . "\n"; - echo ' var ec_dropdown_' . $this->number . ' = document.getElementById("extended-categories-select-group-' . $this->number . '");' . "\n"; - echo ' function ec_onCatChange_' . $this->number . '() {' . "\n"; - echo ' if (ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value > 0) {' . "\n"; - echo ' location.href = "' . get_option('home') . '/?cat="+ec_dropdown_' . $this->number . '.options[ec_dropdown_' . $this->number . '.selectedIndex].value;' . "\n"; - echo ' }' . "\n"; - echo ' }' . "\n"; - echo ' ec_dropdown_' . $this->number . '.onchange = ec_onCatChange_' . $this->number . ';' . "\n"; - echo '/* ]]> */' . "\n"; - echo '</script>' . "\n"; - } - echo $after_widget; - } - } - - /** - * When Widget Control Form Is Posted - * - * @param unknown_type $new_instance - * @param unknown_type $old_instance - * @return unknown - */ - public function update($new_instance, $old_instance) - { - // update the instance's settings - if (!isset($new_instance['submit'])) { - return false; - } - - $instance = $old_instance; - - $instance['title'] = strip_tags(stripslashes($new_instance['title'])); - $instance['count'] = isset($new_instance['count']); - $instance['hierarchical'] = isset($new_instance['hierarchical']); - $instance['hide_empty'] = isset($new_instance['hide_empty']); - $instance['use_desc_for_title'] = isset($new_instance['use_desc_for_title']); - $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column'])); - $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order'])); - $instance['style'] = strip_tags(stripslashes($new_instance['style'])); - $instance['rssfeed'] = isset($new_instance['rssfeed']); - $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage'])); - if (array_key_exists('all', $new_instance['post_group_category'])) { - $instance['post_group_category'] = false; - } else { - $instance['post_group_category'] = serialize($new_instance['post_group_category']); - } - - return $instance; - } - - /** - * Display Widget Control Form - * - * @param unknown_type $instance - */ - public function form($instance) - { - // displays the widget admin form - $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => '')); - - $selected_cats = (avhGetArrayValue($instance, 'post_group_category') !== '') ? unserialize($instance['post_group_category']) : false; - ob_start(); - echo '<p>'; - avh_doWidgetFormText($this->get_field_id('title'), $this->get_field_name('title'), __('Title', 'avh-ec'), $instance['title']); - echo '</p>'; - - echo '<p>'; - - avh_doWidgetFormCheckbox($this->get_field_id('count'), $this->get_field_name('count'), __('Show post counts', 'avh-ec'), (bool) avhGetArrayValue($instance, 'count')); - - avh_doWidgetFormCheckbox($this->get_field_id('hierarchical'), $this->get_field_name('hierarchical'), __('Show hierarchy', 'avh-ec'), (bool) avhGetArrayValue($instance, 'hierarchical')); - - avh_doWidgetFormCheckbox($this->get_field_id('hide_empty'), $this->get_field_name('hide_empty'), __('Hide empty categories', 'avh-ec'), (bool) avhGetArrayValue($instance, 'hide_empty')); - - 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')); - echo '</p>'; - - echo '<p>'; - $options['ID'] = __('ID', 'avh-ec'); - $options['name'] = __('Name', 'avh-ec'); - $options['count'] = __('Count', 'avh-ec'); - $options['slug'] = __('Slug', 'avh-ec'); - avh_doWidgetFormSelect($this->get_field_id('sort_column'), $this->get_field_name('sort_column'), __('Sort by', 'avh-ec'), $options, avhGetArrayValue($instance, 'sort_column')); - unset($options); - - $options['asc'] = __('Ascending', 'avh-ec'); - $options['desc'] = __('Descending', 'avh-ec'); - avh_doWidgetFormSelect($this->get_field_id('sort_order'), $this->get_field_name('sort_order'), __('Sort order', 'avh-ec'), $options, avhGetArrayValue($instance, 'sort_order')); - unset($options); - - $options['list'] = __('List', 'avh-ec'); - $options['drop'] = __('Drop down', 'avh-ec'); - avh_doWidgetFormSelect($this->get_field_id('style'), $this->get_field_name('style'), __('Display style', 'avh-ec'), $options, avhGetArrayValue($instance, 'style')); - unset($options); - echo '</p>'; - - echo '<p>'; - - avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), $this->get_field_name('rssfeed'), __('Show RSS Feed', 'avh-ec'), (bool) avhGetArrayValue($instance, 'rssfeed')); - - avh_doWidgetFormText($this->get_field_id('rssimage'), $this->get_field_name('rssimage'), __('Path (URI) to RSS image', 'avh-ec'), avhGetArrayValue($instance, 'rssimage')); - echo '</p>'; - - echo '<p>'; - echo '<b>' . __('Select Groups', 'avh-ec') . '</b><hr />'; - 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;">'; - echo '<li id="' . $this->get_field_id('group_category--1') . '" class="popular-group_category">'; - echo '<label for="' . $this->get_field_id('group_post_category') . '" class="selectit">'; - 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' : '') . '> '; - _e('Any Group', 'avh-ec'); - echo '</label>'; - echo '</li>'; - - $this->avh_wp_group_category_checklist($selected_cats, $this->number); - - echo '</ul>'; - echo '</p>'; - - echo '<input type="hidden" id="' . $this->get_field_id('submit') . '" name="' . $this->get_field_name('submit') . '" value="1" />'; - ob_end_flush(); - } - - public function avh_wp_group_category_checklist($selected_cats, $number) - { - $walker = new AVH_Walker_Category_Checklist(); - $walker->number = $number; - $walker->input_id = $this->get_field_id('post_group_category'); - $walker->input_name = $this->get_field_name('post_group_category'); - $walker->li_id = $this->get_field_id('group_category--1'); - - $args = array('taxonomy' => 'avhec_catgroup', 'descendants_and_self' => 0, 'selected_cats' => array(), 'popular_cats' => array(), 'walker' => $walker, 'checked_ontop' => true); - - if (is_array($selected_cats)) { - $args['selected_cats'] = $selected_cats; - } else { - $args['selected_cats'] = array(); - } - - $categories = (array) get_terms($args['taxonomy'], array('get' => 'all')); - - // 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) - $checked_categories = array(); - $keys = array_keys($categories); - - foreach ($keys as $k) { - if (in_array($categories[$k]->term_id, $args['selected_cats'])) { - $checked_categories[] = $categories[$k]; - unset($categories[$k]); - } - } - - // Put checked cats on top - echo $walker->walk($checked_categories, 0, $args); - // Then the rest of them - echo $walker->walk($categories, 0, $args); - } - - public function getWidgetDoneCatGroup($id) - { - $catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group'); - if (is_array($catgrp->widget_done_catgroup) && array_key_exists($id, $catgrp->widget_done_catgroup)) { - return true; - } - $catgrp->widget_done_catgroup[$id] = true; - - return false; - } +class WP_Widget_AVH_ExtendedCategories_Normal extends WP_Widget { + /** + * @var AVH_EC_Core + */ + public $core; + + /** + * PHP 5 Constructor + */ + public function __construct() { + $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core'); + + // Convert the old option widget_extended_categories to widget_extended-categories + $old = get_option('widget_extended_categories'); + if ( ! (false === $old)) { + update_option('widget_extended-categories', $old); + delete_option('widget_extended_categories'); + } + $widget_ops = array('description' => __("An extended version of the default Categories widget.", 'avh-ec')); + WP_Widget::__construct('extended-categories', 'AVH Extended Categories', $widget_ops); + + add_action('wp_print_styles', array($this, 'actionWpPrintStyles')); + } + + public function actionWpPrintStyles() { + if ( ! (false === is_active_widget(false, false, $this->id_base, true))) { + wp_register_style('avhec-widget', + AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', + array(), + $this->core->version); + wp_enqueue_style('avhec-widget'); + } + } + + /** + * Creates the categories checklist + * + * @param array $selected_cats + * @param int $number + */ + public function avh_wp_category_checklist($selected_cats, $number) { + $walker = new AVH_Walker_Category_Checklist(); + $walker->number = $number; + $walker->input_id = $this->get_field_id('post_category'); + $walker->input_name = $this->get_field_name('post_category'); + $walker->li_id = $this->get_field_id('category--1'); + + $args = array( + 'taxonomy' => 'category', + 'descendants_and_self' => 0, + 'selected_cats' => $selected_cats, + 'popular_cats' => array(), + 'walker' => $walker, + 'checked_ontop' => true + ); + + if (is_array($selected_cats)) { + $args['selected_cats'] = $selected_cats; + } else { + $args['selected_cats'] = array(); + } + + $categories = $this->core->getCategories(); + $_categories_id = $this->core->getCategoriesId($categories); + + // 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) + $checked_categories = array(); + foreach ($args['selected_cats'] as $key => $value) { + if (isset($_categories_id[ $key ])) { + $category_key = $_categories_id[ $key ]; + $checked_categories[] = $categories[ $category_key ]; + unset($categories[ $category_key ]); + } + } + + // Put checked cats on top + echo $walker->walk($checked_categories, 0, $args); + // Then the rest of them + echo $walker->walk($categories, 0, $args); + } + + /** + * Display Widget Control Form + * + * @param array $instance + * + * @return string|void + */ + public function form($instance) { + // displays the widget admin form + $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => '', 'depth' => 0)); + + // Prepare data for display + $depth = (int) $instance['depth']; + if ($depth < 0 || 11 < $depth) { + $depth = 0; + } + $selected_cats = (avhGetArrayValue($instance, 'post_category') !== + '') ? unserialize($instance['post_category']) : false; + + echo '<p>'; + avh_doWidgetFormText($this->get_field_id('title'), + $this->get_field_name('title'), + __('Title', 'avh-ec'), + avhGetArrayValue($instance, 'title')); + echo '</p>'; + + echo '<p>'; + avh_doWidgetFormCheckbox($this->get_field_id('selectedonly'), + $this->get_field_name('selectedonly'), + __('Show selected categories only', 'avh-ec'), + (bool) avhGetArrayValue($instance, 'selectedonly')); + + avh_doWidgetFormCheckbox($this->get_field_id('count'), + $this->get_field_name('count'), + __('Show post counts', 'avh-ec'), + (bool) avhGetArrayValue($instance, 'count')); + + avh_doWidgetFormCheckbox($this->get_field_id('hierarchical'), + $this->get_field_name('hierarchical'), + __('Show hierarchy', 'avh-ec'), + (bool) avhGetArrayValue($instance, 'hierarchical')); + + $options = array(0 => __('All Levels', 'avh-ec'), 1 => __('Toplevel only', 'avh-ec')); + for ($i = 2; $i <= 11; $i ++) { + $options[ $i ] = __('Child ', 'avh-ec') . ($i - 1); + } + avh_doWidgetFormSelect($this->get_field_id('depth'), + $this->get_field_name('depth'), + __('How many levels to show', 'avh-ec'), + $options, + $depth); + unset($options); + + avh_doWidgetFormCheckbox($this->get_field_id('hide_empty'), + $this->get_field_name('hide_empty'), + __('Hide empty categories', 'avh-ec'), + (bool) avhGetArrayValue($instance, 'hide_empty')); + + 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')); + echo '</p>'; + + echo '<p>'; + $options['ID'] = __('ID', 'avh-ec'); + $options['name'] = __('Name', 'avh-ec'); + $options['count'] = __('Count', 'avh-ec'); + $options['slug'] = __('Slug', 'avh-ec'); + $options['avhec_manualorder'] = 'AVH EC ' . __('Manual Order', 'avh-ec'); + if (is_plugin_active('my-category-order/mycategoryorder.php')) { + $options['avhec_3rdparty_mycategoryorder'] = 'My Category Order'; + } + + avh_doWidgetFormSelect($this->get_field_id('sort_column'), + $this->get_field_name('sort_column'), + __('Sort by', 'avh-ec'), + $options, + avhGetArrayValue($instance, 'sort_column')); + unset($options); + + $options['asc'] = __('Ascending', 'avh-ec'); + $options['desc'] = __('Descending', 'avh-ec'); + avh_doWidgetFormSelect($this->get_field_id('sort_order'), + $this->get_field_name('sort_order'), + __('Sort order', 'avh-ec'), + $options, + avhGetArrayValue($instance, 'sort_order')); + unset($options); + + $options['list'] = __('List', 'avh-ec'); + $options['drop'] = __('Drop down', 'avh-ec'); + avh_doWidgetFormSelect($this->get_field_id('style'), + $this->get_field_name('style'), + __('Display style', 'avh-ec'), + $options, + avhGetArrayValue($instance, 'style')); + unset($options); + echo '</p>'; + + echo '<p>'; + + avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), + $this->get_field_name('rssfeed'), + __('Show RSS Feed', 'avh-ec'), + (bool) avhGetArrayValue($instance, 'rssfeed')); + + avh_doWidgetFormText($this->get_field_id('rssimage'), + $this->get_field_name('rssimage'), + __('Path (URI) to RSS image', 'avh-ec'), + avhGetArrayValue($instance, 'rssimage')); + + echo '</p>'; + + echo '<p>'; + echo '<b>' . __('Select categories', 'avh-ec') . '</b><hr />'; + echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear" style="list-style-type: none; margin-left: 5px; padding-left: 0; margin-bottom: 20px;">'; + echo '<li id="' . $this->get_field_id('category--1') . '" class="popular-category">'; + echo '<label for="' . $this->get_field_id('post_category') . '" class="selectit">'; + 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' : '') . + '> '; + _e('All Categories', 'avh-ec'); + echo '</label>'; + echo '</li>'; + ob_start(); + $this->avh_wp_category_checklist($selected_cats, $this->number); + ob_end_flush(); + echo '</ul>'; + echo '</p>'; + + echo '<p>'; + 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')); + echo '</p>'; + + echo '<input type="hidden" id="' . + $this->get_field_id('submit') . + '" name="' . + $this->get_field_name('submit') . + '" value="1" />'; + } + + /** + * When Widget Control Form Is Posted + * + * @param array $new_instance + * @param array $old_instance + * + * @return array|bool + */ + public function update($new_instance, $old_instance) { + // update the instance's settings + if ( ! isset($new_instance['submit'])) { + return false; + } + + $instance = $old_instance; + + $instance['title'] = strip_tags(stripslashes($new_instance['title'])); + $instance['selectedonly'] = isset($new_instance['selectedonly']); + $instance['count'] = isset($new_instance['count']); + $instance['hierarchical'] = isset($new_instance['hierarchical']); + $instance['hide_empty'] = isset($new_instance['hide_empty']); + $instance['use_desc_for_title'] = isset($new_instance['use_desc_for_title']); + $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column'])); + $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order'])); + $instance['style'] = strip_tags(stripslashes($new_instance['style'])); + $instance['rssfeed'] = isset($new_instance['rssfeed']); + $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage'])); + if (array_key_exists('all', $new_instance['post_category'])) { + $instance['post_category'] = false; + } else { + $instance['post_category'] = serialize($new_instance['post_category']); + } + $instance['depth'] = (int) $new_instance['depth']; + if ($instance['depth'] < 0 || 11 < $instance['depth']) { + $instance['depth'] = 0; + } + $instance['invert_included'] = isset($new_instance['invert_included']); + + return $instance; + } + + /** + * Display the widget + * + * @param array $args + * @param array $instance + */ + public function widget($args, $instance) { + $count = $instance['count']; + $hierarchical = $instance['hierarchical']; + $depth = $instance['depth']; + $hide_empty = $instance['hide_empty']; + $use_desc_for_title = $instance['use_desc_for_title']; + $sort_column = isset($instance['sort_column']) ? $instance['sort_column'] : 'name'; + $sort_order = isset($instance['sort_order']) ? $instance['sort_order'] : 'asc'; + $rss_feed = ($instance['rssfeed'] == true) ? 'RSS' : ''; + $rss_image = isset($instance['rssimage']) ? $instance['rssimage'] : ''; + $invert = $instance['invert_included']; + + if (empty($rss_feed)) { + $rss_image = ''; + } + + if (empty($depth)) { + $depth = 0; + } + + $title = apply_filters('widget_title', + empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']); + $style = empty($instance['style']) ? 'list' : $instance['style']; + + $included_cats = ''; + if ($instance['post_category']) { + $post_category = unserialize($instance['post_category']); + $children = array(); + if ( ! $instance['selectedonly']) { + foreach ($post_category as $cat_id) { + $children = array_merge($children, get_term_children($cat_id, 'category')); + } + } + $included_cats = implode(",", array_merge($post_category, $children)); + } + + if ($invert) { + $inc_exc = 'exclude'; + } else { + $inc_exc = 'include'; + } + + $options = $this->core->getOptions(); + $show_option_none = __('Select Category', 'avh-ec'); + if ($options['general']['alternative_name_select_category']) { + $show_option_none = $options['general']['alternative_name_select_category']; + } + + $cat_args = array( + $inc_exc => $included_cats, + 'orderby' => $sort_column, + 'order' => $sort_order, + 'show_count' => $count, + 'use_desc_for_title' => $use_desc_for_title, + 'hide_empty' => $hide_empty, + 'hierarchical' => $hierarchical, + 'depth' => $depth, + 'title_li' => '', + 'show_option_none' => $show_option_none, + 'feed' => $rss_feed, + 'feed_image' => $rss_image + ); + echo $args['before_widget']; + echo $this->core->comment; + echo $args['before_title'] . $title . $args['after_title']; + + if ($style == 'list') { + echo '<ul>'; + $this->core->avh_wp_list_categories($cat_args); + echo '</ul>'; + } else { + $cat_args['name'] = 'extended-categories-select-' . $this->number; + $this->core->avh_wp_dropdown_categories($cat_args); + echo '<script type=\'text/javascript\'>' . "\n"; + echo '/* <![CDATA[ */' . "\n"; + echo ' var ec_dropdown_' . + $this->number . + ' = document.getElementById("extended-categories-select-' . + $this->number . + '");' . + "\n"; + echo ' function ec_onCatChange_' . $this->number . '() {' . "\n"; + echo ' if (ec_dropdown_' . + $this->number . + '.options[ec_dropdown_' . + $this->number . + '.selectedIndex].value > 0) {' . + "\n"; + echo ' location.href = "' . + home_url() . + '/?cat="+ec_dropdown_' . + $this->number . + '.options[ec_dropdown_' . + $this->number . + '.selectedIndex].value;' . + "\n"; + echo ' }' . "\n"; + echo ' }' . "\n"; + echo ' ec_dropdown_' . + $this->number . + '.onchange = ec_onCatChange_' . + $this->number . + ';' . + "\n"; + echo '/* ]]> */' . "\n"; + echo '</script>' . "\n"; + } + echo $args['after_widget']; + } } /** - * Class that will display the categories + * Widget Class for displaying the top categories */ -class AVH_Walker_Category_Checklist extends Walker -{ - - public $tree_type = 'category'; - - public $db_fields = array('parent' => 'parent', 'id' => 'term_id'); // TODO: decouple this - public $number; - - public $input_id; - - public $input_name; - - public $li_id; - - /** - * Display array of elements hierarchically. - * - * It is a generic function which does not assume any existing order of - * elements. max_depth = -1 means flatly display every element. max_depth = - * 0 means display all levels. max_depth > 0 specifies the number of - * display levels. - * - * @since 2.1.0 - * - * @param array $elements - * @param int $max_depth - * @param array $args; - * @return string - */ - public function walk($elements, $max_depth) - { - $args = array_slice(func_get_args(), 2); - $output = ''; - - if ($max_depth < -1) { - return $output; - } - - if (empty($elements)) { // nothing to walk - return $output; - } - - $id_field = $this->db_fields['id']; - $parent_field = $this->db_fields['parent']; - - // flat display - if (-1 == $max_depth) { - $empty_array = array(); - foreach ($elements as $e) { - $this->display_element($e, $empty_array, 1, 0, $args, $output); - } - - return $output; - } - - /* - * 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. - */ - $top_level_elements = array(); - $children_elements = array(); - foreach ($elements as $e) { - if (0 == $e->$parent_field) { - $top_level_elements[] = $e; - } else { - $children_elements[$e->$parent_field][] = $e; - } - } - - /* - * when none of the elements is top level assume the first one must be root of the sub elements - */ - if (empty($top_level_elements)) { - - $first = array_slice($elements, 0, 1); - $root = $first[0]; - - $top_level_elements = array(); - $children_elements = array(); - foreach ($elements as $e) { - if ($root->$parent_field == $e->$parent_field) { - $top_level_elements[] = $e; - } else { - $children_elements[$e->$parent_field][] = $e; - } - } - } - - foreach ($top_level_elements as $e) { - $this->display_element($e, $children_elements, $max_depth, 0, $args, $output); - } - - /* - * if we are displaying all levels, and remaining children_elements is not empty, then we got orphans, which should be displayed regardless - */ - if (($max_depth == 0) && count($children_elements) > 0) { - $empty_array = array(); - foreach ($children_elements as $orphans) { - foreach ($orphans as $op) { - $this->display_element($op, $empty_array, 1, 0, $args, $output); - } - } - } - - return $output; - } - - public function start_lvl(&$output, $depth = 0, $args = array()) - { - $indent = str_repeat("\t", $depth); - $output .= $indent . '<ul class="children">' . "\n"; - } - - public function end_lvl(&$output, $depth = 0, $args = array()) - { - $indent = str_repeat("\t", $depth); - $output .= $indent . '</ul>' . "\n"; - } - - public function start_el(&$output, $object, $depth = 0, $args = array(), $current_object_id = 0) - { - extract($args); - if (!isset($selected_cats)) { - $selected_cats = array(); - } - $input_id = $this->input_id . '-' . $object->term_id; - $output .= "\n" . '<li id="' . $this->li_id . '">'; - $output .= '<label for="' . $input_id . '" class="selectit">'; - $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>'; - } - - public function end_el(&$output, $object, $depth = 0, $args = array()) - { - $output .= "</li>\n"; - } +class WP_Widget_AVH_ExtendedCategories_Top extends WP_Widget { + /** + * @var AVH_EC_Core + */ + public $core; + + /** + * PHP 5 Constructor + */ + public function __construct() { + $this->core = &AVH_EC_Singleton::getInstance('AVH_EC_Core'); + + $widget_ops = array('description' => __("Shows the top categories.", 'avh-ec')); + WP_Widget::__construct(false, 'AVH Extended Categories: ' . __('Top Categories'), $widget_ops); + add_action('wp_print_styles', array($this, 'actionWpPrintStyles')); + } + + public function actionWpPrintStyles() { + if ( ! (false === is_active_widget(false, false, $this->id_base, true))) { + wp_register_style('avhec-widget', + AVHEC_PLUGIN_URL . '/css/avh-ec.widget.css', + array(), + $this->core->version); + wp_enqueue_style('avhec-widget'); + } + } + + /** + * Echo the settings update form + * + * @param array $instance Current settings + * + * @return string|void + */ + public function form($instance) { + // displays the widget admin form + $instance = wp_parse_args((array) $instance, array('title' => '', 'rssimage' => '', 'amount' => '5')); + + $amount = (int) avhGetArrayValue($instance, 'amount'); + if ($amount < 1) { + $amount = 1; + } + echo '<p>'; + avh_doWidgetFormText($this->get_field_id('title'), + $this->get_field_name('title'), + __('Title', 'avh-ec'), + avhGetArrayValue($instance, 'title')); + echo '</p>'; + + echo '<p>'; + avh_doWidgetFormText($this->get_field_id('amount'), + $this->get_field_name('amount'), + __('How many categories to show', 'avh-ec'), + $amount); + echo '</p>'; + + echo '<p>'; + avh_doWidgetFormCheckbox($this->get_field_id('count'), + $this->get_field_name('count'), + __('Show post counts', 'avh-ec'), + (bool) avhGetArrayValue($instance, 'count')); + echo '<br />'; + + 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')); + echo '</p>'; + + echo '<p>'; + $options['ID'] = __('ID', 'avh-ec'); + $options['name'] = __('Name', 'avh-ec'); + $options['count'] = __('Count', 'avh-ec'); + $options['slug'] = __('Slug', 'avh-ec'); + avh_doWidgetFormSelect($this->get_field_id('sort_column'), + $this->get_field_name('sort_column'), + __('Sort by', 'avh-ec'), + $options, + avhGetArrayValue($instance, 'sort_column')); + unset($options); + + $options['asc'] = __('Ascending', 'avh-ec'); + $options['desc'] = __('Descending', 'avh-ec'); + avh_doWidgetFormSelect($this->get_field_id('sort_order'), + $this->get_field_name('sort_order'), + __('Sort order', 'avh-ec'), + $options, + avhGetArrayValue($instance, 'sort_order')); + unset($options); + + $options['list'] = __('List', 'avh-ec'); + $options['drop'] = __('Drop down', 'avh-ec'); + avh_doWidgetFormSelect($this->get_field_id('style'), + $this->get_field_name('style'), + __('Display style', 'avh-ec'), + $options, + avhGetArrayValue($instance, 'style')); + unset($options); + echo '</p>'; + + echo '<p>'; + + avh_doWidgetFormCheckbox($this->get_field_id('rssfeed'), + $this->get_field_name('rssfeed'), + __('Show RSS Feed', 'avh-ec'), + (bool) avhGetArrayValue($instance, 'rssfeed')); + + avh_doWidgetFormText($this->get_field_id('rssimage'), + $this->get_field_name('rssimage'), + __('Path (URI) to RSS image', 'avh-ec'), + avhGetArrayValue($instance, 'rssimage')); + + echo '</p>'; + + echo '<input type="hidden" id="' . + $this->get_field_id('submit') . + '" name="' . + $this->get_field_name('submit') . + '" value="1" />'; + } + + /** + * Update a particular instance. + * This function should check that $new_instance is set correctly. + * The newly calculated value of $instance should be returned. + * If "false" is returned, the instance won't be saved/updated. + * + * @param array $new_instance New settings for this instance as input by the user via form() + * @param array $old_instance Old settings for this instance + * + * @return array Settings to save or bool false to cancel saving + */ + public function update($new_instance, $old_instance) { + // update the instance's settings + if ( ! isset($new_instance['submit'])) { + return false; + } + + $instance = $old_instance; + + $instance['title'] = strip_tags(stripslashes($new_instance['title'])); + $instance['amount'] = (int) $new_instance['amount']; + $instance['count'] = isset($new_instance['count']); + $instance['use_desc_for_title'] = isset($new_instance['use_desc_for_title']); + $instance['sort_column'] = strip_tags(stripslashes($new_instance['sort_column'])); + $instance['sort_order'] = strip_tags(stripslashes($new_instance['sort_order'])); + $instance['style'] = strip_tags(stripslashes($new_instance['style'])); + $instance['rssfeed'] = isset($new_instance['rssfeed']); + $instance['rssimage'] = strip_tags(stripslashes($new_instance['rssimage'])); + + return $instance; + } + + /** + * Echo the widget content. + * Subclasses should over-ride this function to generate their widget code. + * + * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget. + * @param array $instance The settings for the particular instance of the widget + */ + public function widget($args, $instance) { + + $title = apply_filters('widget_title', + empty($instance['title']) ? __('Categories', 'avh-ec') : $instance['title']); + $style = empty($instance['style']) ? 'list' : $instance['style']; + if ( ! $a = (int) $instance['amount']) { + $a = 5; + } elseif ($a < 1) { + $a = 1; + } + $c = $instance['count']; + $use_desc_for_title = $instance['use_desc_for_title']; + $s = isset($instance['sort_column']) ? $instance['sort_column'] : 'name'; + $o = isset($instance['sort_order']) ? $instance['sort_order'] : 'asc'; + $r = ($instance['rssfeed'] === true) ? 'RSS' : ''; + $i = isset($instance['rssimage']) ? $instance['rssimage'] : ''; + if (empty($r)) { + $i = ''; + } + if ( ! empty($i)) { + if ( ! file_exists(ABSPATH . '/' . $i)) { + $i = ''; + } + } + + $options = $this->core->getOptions(); + $show_option_none = __('Select Category', 'avh-ec'); + if ($options['general']['alternative_name_select_category']) { + $show_option_none = $options['general']['alternative_name_select_category']; + } + + $top_cats = get_terms('category', + array( + 'fields' => 'ids', + 'orderby' => 'count', + 'order' => 'DESC', + 'number' => $a, + 'hierarchical' => false + )); + $included_cats = implode(",", $top_cats); + + $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 + ); + echo $args['before_widget']; + echo $this->core->comment; + echo $args['before_title'] . $title . $args['after_title']; + echo '<ul>'; + + if ($style == 'list') { + wp_list_categories($cat_args); + } else { + $cat_args['name'] = 'extended-categories-top-select-' . $this->number; + wp_dropdown_categories($cat_args); + echo '<script type=\'text/javascript\'>' . "\n"; + echo '/* <![CDATA[ */' . "\n"; + echo ' var ec_dropdown_top_' . + $this->number . + ' = document.getElementById("extended-categories-top-select-' . + $this->number . + '");' . + "\n"; + echo ' function ec_top_onCatChange_' . $this->number . '() {' . "\n"; + echo ' if (ec_dropdown_top_' . + $this->number . + '.options[ec_dropdown_top_' . + $this->number . + '.selectedIndex].value > 0) {' . + "\n"; + echo ' location.href = "' . + get_option('home') . + '/?cat="+ec_dropdown_top_' . + $this->number . + '.options[ec_dropdown_top_' . + $this->number . + '.selectedIndex].value;' . + "\n"; + echo ' }' . "\n"; + echo ' }' . "\n"; + echo ' ec_dropdown_top_' . + $this->number . + '.onchange = ec_top_onCatChange_' . + $this->number . + ';' . + "\n"; + echo '/* ]]> */' . "\n"; + echo '</script>' . "\n"; + } + echo '</ul>'; + echo $args['after_widget']; + } } diff --git a/wp-content/plugins/extended-categories-widget/4.2/css/avh-ec.admin.css b/wp-content/plugins/extended-categories-widget/4.2/css/avh-ec.admin.css index d7c05485be8dc186eefc41d1779362a695a6a318..b942f0a5b821715a2631b5c6df04dabec1958be6 100644 --- a/wp-content/plugins/extended-categories-widget/4.2/css/avh-ec.admin.css +++ b/wp-content/plugins/extended-categories-widget/4.2/css/avh-ec.admin.css @@ -1,13 +1,13 @@ .footer_avhec { - font-size: 0.8em; - text-align: center; + font-size : 0.8em; + text-align : center; } div.clearer { - clear: both; - line-height: 1px; - font-size: 1px; - height: 1px; + clear : both; + line-height : 1px; + font-size : 1px; + height : 1px; } /* Metabox in General */ @@ -20,12 +20,12 @@ table.avhec-options { } .avhec-metabox-wrap .p { - line-height: 140%; - margin: 1em 0; + line-height : 140%; + margin : 1em 0; } #avhecBoxOptions option { - padding: .5em; + padding : .5em; } .avhec-metabox-wrap span.description { @@ -33,17 +33,17 @@ table.avhec-options { } .avhec-metabox-wrap .b { - font-weight: bold; + font-weight : bold; } .avhec-metabox-wrap ul { - margin-bottom: 1em; + margin-bottom : 1em; } .avhec-metabox-wrap ul li { - line-height: 120%; - list-style: disc inside none; - margin-bottom: 0; + line-height : 120%; + list-style : disc inside none; + margin-bottom : 0; } #avhec-options input { @@ -56,13 +56,13 @@ table.avhec-options { /* Metabox FAQ */ #avhecBoxFAQ .inside ul { - margin-bottom: 6px; + margin-bottom : 6px; } #avhecBoxFAQ .inside ul li { - line-height: 120%; - list-style: disc inside none; - margin-bottom: 0; + line-height : 120%; + list-style : disc inside none; + margin-bottom : 0; } /* Metabox Donations*/ @@ -71,7 +71,7 @@ table.avhec-options { } #avhecBoxDonations .versions { - padding: 6px 10px 12px; + padding : 6px 10px 12px; } /* Metabox Donations*/ @@ -81,75 +81,74 @@ table.avhec-options { /* Metabox in post and page */ #post_avhec_category_group { - width: 100%; + width : 100%; } #avhec-catlist { - -moz-border-radius: 4px 4px 4px 4px; - background-color: #FFFFFF; - border: 1px solid #DFDFDF; - height: 20em; - margin-bottom: -1.8em; - overflow: auto; - width: 95%; + -moz-border-radius : 4px 4px 4px 4px; + background-color : #FFFFFF; + border : 1px solid #DFDFDF; + height : 20em; + margin-bottom : -1.8em; + overflow : auto; + width : 95%; } #avhec-catlist ul { - padding: 3px; + padding : 3px; } #avhec-catlist li ul { - padding: 0px; + padding : 0; } #avhec-catlist li { - margin-bottom: 0px; + margin-bottom : 0; } #avhecManualOrder { - width: 25%; - /* border: 1px solid #B2B2B2;*/ - /* margin: 10px 10px 10px 0px;*/ - /* padding: 5px 10px 5px 10px;*/ - /* list-style: none;*/ - /* background-color: #fff;*/ - /* border-radius: 3px;*/ - /* -webkit-border-radius: 3px;*/ + width : 25%; + /* border: 1px solid #B2B2B2;*/ + /* margin: 10px 10px 10px 0px;*/ + /* padding: 5px 10px 5px 10px;*/ + /* list-style: none;*/ + /* background-color: #fff;*/ + /* border-radius: 3px;*/ + /* -webkit-border-radius: 3px;*/ } #avhecManualOrder li.lineitem { - border: 1px solid #DFDFDF; - background-image: none; - border-radius: 3px; - -webkit-border-radius: 3px; - background-color: #FFFFFF; - color: #555555; - cursor: move; - margin-top: 5px; - margin-bottom: 5px; - padding: 2px 5px 2px 5px; - list-style: none outside none; + border : 1px solid #DFDFDF; + border-radius : 3px; + -webkit-border-radius : 3px; + background : #FFFFFF none; + color : #555555; + cursor : move; + margin-top : 5px; + margin-bottom : 5px; + padding : 2px 5px 2px 5px; + list-style : none outside none; } #avhecManualOrder .sortable-placeholder { - border: 1px dashed #B2B2B2; - margin-top: 5px; - margin-bottom: 5px; - padding: 2px 5px 2px 5px; - height: 1.5em; - line-height: 1.5em; - list-style: none outside none; - background-color: transparent; - /* IE10 */ - background-image: -ms-linear-gradient(top, #f9f9f9, #f5f5f5); - /* Firefox */ - background-image: -moz-linear-gradient(top, #f9f9f9, #f5f5f5); - /* Opera */ - background-image: -o-linear-gradient(top, #f9f9f9, #f5f5f5); - /* old Webkit */ - background-image: -webkit-gradient(linear, left top, left bottom, from(#f9f9f9), to(#f5f5f5) ); - /* new Webkit */ - background-image: -webkit-linear-gradient(top, #f9f9f9, #f5f5f5); - /* proposed W3C Markup */ - background-image: linear-gradient(top, #f9f9f9, #f5f5f5); -} \ No newline at end of file + border : 1px dashed #B2B2B2; + margin-top : 5px; + margin-bottom : 5px; + padding : 2px 5px 2px 5px; + height : 1.5em; + line-height : 1.5em; + list-style : none outside none; + background-color : transparent; + /* IE10 */ + background-image : -ms-linear-gradient(top, #f9f9f9, #f5f5f5); + /* Firefox */ + background-image : -moz-linear-gradient(top, #f9f9f9, #f5f5f5); + /* Opera */ + background-image : -o-linear-gradient(top, #f9f9f9, #f5f5f5); + /* old Webkit */ + background-image : -webkit-gradient(linear, left top, left bottom, from(#f9f9f9), to(#f5f5f5)); + /* new Webkit */ + background-image : -webkit-linear-gradient(top, #f9f9f9, #f5f5f5); + /* proposed W3C Markup */ + background-image : linear-gradient(top, #f9f9f9, #f5f5f5); +} diff --git a/wp-content/plugins/extended-categories-widget/4.2/css/avh-ec.widget.css b/wp-content/plugins/extended-categories-widget/4.2/css/avh-ec.widget.css index 25a86492027158e2aee27e65b763b3f122d7d27d..77334d8be728584604d3a1aeab2dcc0194fe30a9 100644 --- a/wp-content/plugins/extended-categories-widget/4.2/css/avh-ec.widget.css +++ b/wp-content/plugins/extended-categories-widget/4.2/css/avh-ec.widget.css @@ -1,12 +1,12 @@ /* AVH Extended Categories Widget CSS */ .avhec-widget-line { - display: inline-block; + display : inline-block; } .avhec-widget-count { - display: inline; + display : inline; } .avhec-widget-rss { - display: inline; -} \ No newline at end of file + display : inline; +} diff --git a/wp-content/plugins/extended-categories-widget/4.2/helpers/avh-common.php b/wp-content/plugins/extended-categories-widget/4.2/helpers/avh-common.php index 667b269e22ca2aad0b968d019d91c8d2fb3d9434..dea8155904a10200ae1af140a6d05cea70a8b86f 100644 --- a/wp-content/plugins/extended-categories-widget/4.2/helpers/avh-common.php +++ b/wp-content/plugins/extended-categories-widget/4.2/helpers/avh-common.php @@ -1,18 +1,18 @@ <?php -if ( !function_exists('avhGetArrayValue') ) { +if ( ! function_exists('avhGetArrayValue')) { /** * Get the value of $array[$name] * - * @param array $array + * @param array $array * @param string $name * * @return mixed An empty string when the $array[$name] does not exists */ - function avhGetArrayValue ($array, $name) - { - if ( isset($array[$name]) ) - return $array[$name]; + function avhGetArrayValue($array, $name) { + if (isset($array[ $name ])) { + return $array[ $name ]; + } return ''; } diff --git a/wp-content/plugins/extended-categories-widget/4.2/helpers/avh-forms.php b/wp-content/plugins/extended-categories-widget/4.2/helpers/avh-forms.php index 03064a5993ad1606c1d66da1b6aa618b2701e935..fa8abe8ee9adfdbe8a5e3a18c4b9d2096c73bd3e 100644 --- a/wp-content/plugins/extended-categories-widget/4.2/helpers/avh-forms.php +++ b/wp-content/plugins/extended-categories-widget/4.2/helpers/avh-forms.php @@ -1,43 +1,59 @@ <?php -if (!function_exists('avh_doWidgetFormText')) { +if ( ! function_exists('avh_doWidgetFormText')) { - function avh_doWidgetFormText($field_id, $field_name, $description, $value) - { - echo '<label for="' . $field_id . '">'; - echo $description; - echo '<input class="widefat" id="' . $field_id . '" name="' . $field_name . '" type="text" value="' . esc_attr($value) . '" /> '; - echo '</label>'; - echo '<br />'; - } + function avh_doWidgetFormText($field_id, $field_name, $description, $value) { + echo '<label for="' . $field_id . '">'; + echo $description; + echo '<input class="widefat" id="' . + $field_id . + '" name="' . + $field_name . + '" type="text" value="' . + esc_attr($value) . + '" /> '; + echo '</label>'; + echo '<br />'; + } } -if (!function_exists('avh_doWidgetFormCheckbox')) { +if ( ! function_exists('avh_doWidgetFormCheckbox')) { - function avh_doWidgetFormCheckbox($field_id, $field_name, $description, $is_checked = false) - { - echo '<label for="' . $field_id . '">'; - echo '<input class="checkbox" type="checkbox" id="' . $field_id . '" name="' . $field_name . '"' . ($is_checked ? ' CHECKED' : '') . ' /> '; - echo $description; - echo '</label>'; - echo '<br />'; - } + function avh_doWidgetFormCheckbox($field_id, $field_name, $description, $is_checked = false) { + echo '<label for="' . $field_id . '">'; + echo '<input class="checkbox" type="checkbox" id="' . + $field_id . + '" name="' . + $field_name . + '"' . + ($is_checked ? ' CHECKED' : '') . + ' /> '; + echo $description; + echo '</label>'; + echo '<br />'; + } } -if (!function_exists('avh_doWidgetFormSelect')) { +if ( ! function_exists('avh_doWidgetFormSelect')) { - function avh_doWidgetFormSelect($field_id, $field_name, $description, $options, $selected_value) - { - echo '<label for="' . $field_id . '">'; - echo $description . ' '; - echo '</label>'; + function avh_doWidgetFormSelect($field_id, $field_name, $description, $options, $selected_value) { + echo '<label for="' . $field_id . '">'; + echo $description . ' '; + echo '</label>'; - $data = ''; - foreach ($options as $value => $text) { - $data .= '<option value="' . $value . '" ' . ($value == $selected_value ? "SELECTED" : '') . '>' . $text . '</option>' . "/n"; - } - echo '<select id="' . $field_id . '" name="' . $field_name . '"> '; - echo $data; - echo '</select>'; - echo '<br />'; - } + $data = ''; + foreach ($options as $value => $text) { + $data .= '<option value="' . + $value . + '" ' . + ($value == $selected_value ? "SELECTED" : '') . + '>' . + $text . + '</option>' . + "/n"; + } + echo '<select id="' . $field_id . '" name="' . $field_name . '"> '; + echo $data; + echo '</select>'; + echo '<br />'; + } } diff --git a/wp-content/plugins/extended-categories-widget/4.2/js/avh-ec.admin.manualorder.js b/wp-content/plugins/extended-categories-widget/4.2/js/avh-ec.admin.manualorder.js index 34b4ae16827d893ba3be2b4a275c04af1cab68d7..332d125b6bac82efff19a2999eca6d65d215b949 100644 --- a/wp-content/plugins/extended-categories-widget/4.2/js/avh-ec.admin.manualorder.js +++ b/wp-content/plugins/extended-categories-widget/4.2/js/avh-ec.admin.manualorder.js @@ -1,19 +1,16 @@ function avhecManualOrder() { - jQuery("#avhecManualOrder").sortable({ - placeholder : "sortable-placeholder", - revert : false, - items : '.lineitem', - opacity: 0.65, - cursor: 'move', - forcePlaceholderSize: true, - tolerance : "pointer" - }); -}; - + 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")); -} \ No newline at end of file + jQuery('#updateText').html('Updating Category Order...'); + jQuery('#hdnManualOrder').val(jQuery('#avhecManualOrder').sortable('toArray')); +} diff --git a/wp-content/plugins/extended-categories-widget/4.2/js/avh-ec.admin.manualorder.min.js b/wp-content/plugins/extended-categories-widget/4.2/js/avh-ec.admin.manualorder.min.js new file mode 100644 index 0000000000000000000000000000000000000000..f9ff1e235ba43f64e84475f07f8a067ef81681b1 --- /dev/null +++ b/wp-content/plugins/extended-categories-widget/4.2/js/avh-ec.admin.manualorder.min.js @@ -0,0 +1 @@ +function avhecManualOrder(){jQuery("#avhecManualOrder").sortable({placeholder:"sortable-placeholder",revert:false,items:".lineitem",opacity:.65,cursor:"move",forcePlaceholderSize:true,tolerance:"pointer"})}addLoadEvent(avhecManualOrder);function orderCats(){jQuery("#updateText").html("Updating Category Order...");jQuery("#hdnManualOrder").val(jQuery("#avhecManualOrder").sortable("toArray"))} \ No newline at end of file diff --git a/wp-content/plugins/extended-categories-widget/4.2/js/avh-ec.categorygroup.js b/wp-content/plugins/extended-categories-widget/4.2/js/avh-ec.categorygroup.js index 7221dfa75b4bd0d5c2f9dd3844834ca8d53316a2..80a12c56f808c75f0c4ba76892d6a4b6f1c964aa 100644 --- a/wp-content/plugins/extended-categories-widget/4.2/js/avh-ec.categorygroup.js +++ b/wp-content/plugins/extended-categories-widget/4.2/js/avh-ec.categorygroup.js @@ -1,21 +1,21 @@ -jQuery(document).ready(function($) { - var options = false, delBefore, delAfter; - - delAfter = function( r, settings ) { - var id = $('cat', r).attr('id'), o; - for ( o = 0; o < options.length; o++ ) - if ( id == options[o].value ) - options[o] = null; - }; - - delBefore = function(s) { - if ( 'undefined' != showNotice ) - return showNotice.warn() ? s : false; - - return s; - }; - - $('#the-list').wpList({ delBefore: delBefore }); - - $('.delete a[class^="delete"]').live('click', function(){return false;}); +jQuery(document).ready(function ($) { + var options = false, delBefore, delAfter; + delAfter = function (r, settings) { + var id = $('cat', r).attr('id'), o; + for (o = 0; o < options.length; o++) { + if (id === options[o].value) { + options[o] = null; + } + } + }; + delBefore = function (s) { + if ('undefined' !== showNotice) { + return showNotice.warn() ? s : false; + } + return s; + }; + $('#the-list').wpList({delBefore: delBefore}); + $('.delete a[class^="delete"]').live('click', function () { + return false; + }); }); diff --git a/wp-content/plugins/extended-categories-widget/4.2/js/avh-ec.categorygroup.min.js b/wp-content/plugins/extended-categories-widget/4.2/js/avh-ec.categorygroup.min.js new file mode 100644 index 0000000000000000000000000000000000000000..bcfa262ff284f572d1075b539112a4d2b9f91699 --- /dev/null +++ b/wp-content/plugins/extended-categories-widget/4.2/js/avh-ec.categorygroup.min.js @@ -0,0 +1 @@ +jQuery(document).ready(function($){var options=false,delBefore,delAfter;delAfter=function(r,settings){var id=$("cat",r).attr("id"),o;for(o=0;o<options.length;o++){if(id===options[o].value){options[o]=null}}};delBefore=function(s){if("undefined"!==showNotice){return showNotice.warn()?s:false}return s};$("#the-list").wpList({delBefore:delBefore});$('.delete a[class^="delete"]').live("click",function(){return false})}); \ No newline at end of file diff --git a/wp-content/plugins/extended-categories-widget/AUTHORS b/wp-content/plugins/extended-categories-widget/AUTHORS index ac7e685d8c4448051adbd10fe965550719e0622d..d01b45d8d68f4fc7d7be0845f6c376ee7933fed8 100644 --- a/wp-content/plugins/extended-categories-widget/AUTHORS +++ b/wp-content/plugins/extended-categories-widget/AUTHORS @@ -1,5 +1,17 @@ -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 +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 + + Peter van der Does Stephan flynsarmy -Portions of the project are derived from other open source works are clearly marked. This file is auto generated, any changes will be lost. + + +Portions of the project are derived from other open source works are clearly +marked. + +This file is auto generated, any changes will be lost. diff --git a/wp-content/plugins/extended-categories-widget/libs/avh-common.php b/wp-content/plugins/extended-categories-widget/libs/avh-common.php index 1a8e75a73e941d7dede8b2713ee4bc822fb4725d..1f4a0abf79e5d1faae5fa8a640f3d359a123b696 100755 --- a/wp-content/plugins/extended-categories-widget/libs/avh-common.php +++ b/wp-content/plugins/extended-categories-widget/libs/avh-common.php @@ -1,105 +1,99 @@ <?php -if (! defined('AVH_FRAMEWORK')) - die('You are not allowed to call this page directly.'); -if (! class_exists('AVH_Common')) { - - final class AVH_Common - { +if ( ! defined('AVH_FRAMEWORK')) { + die('You are not allowed to call this page directly.'); +} +if ( ! class_exists('AVH_Common')) { - /** - * Sends the email - * - */ - public static function sendMail ($to, $subject, $message, $footer = array()) - { - $message = array_merge($message, $footer); - $msg = ''; - foreach ($message as $line) { - $msg .= $line . "\r\n"; - } - wp_mail($to, $subject, $msg); + final class AVH_Common { + /** + * Sends the email + */ + public static function sendMail($to, $subject, $message, $footer = array()) { + $message = array_merge($message, $footer); + $msg = ''; + foreach ($message as $line) { + $msg .= $line . "\r\n"; + } + wp_mail($to, $subject, $msg); - return; - } + return; + } - /** - * Returns the wordpress version - * Note: 2.7.x will return 2.7 - * - * @return float - */ - public static function getWordpressVersion () - { - static $_version = null; - if (! isset($_version)) { - // Include WordPress version - require (ABSPATH . WPINC . '/version.php'); - $_version = (float) $wp_version; - } + /** + * Returns the wordpress version + * Note: 2.7.x will return 2.7 + * + * @return float + */ + public static function getWordpressVersion() { + static $_version = null; + if ( ! isset($_version)) { + // Include WordPress version + require(ABSPATH . WPINC . '/version.php'); + $_version = (float) $wp_version; + } - return $_version; - } + return $_version; + } - /** - * Determines if the current version of PHP is greater then the supplied value - * - * @param string - * @return bool - */ - public static function isPHP ($version = '5.0.0') - { - static $_is_php = null; - $version = (string) $version; - if (! isset($_is_php[$version])) { - $_is_php[$version] = (version_compare(PHP_VERSION, $version) < 0) ? false : true; - } + /** + * Determines if the current version of PHP is greater then the supplied value + * + * @param string + * + * @return bool + */ + public static function isPHP($version = '5.0.0') { + static $_is_php = null; + $version = (string) $version; + if ( ! isset($_is_php[ $version ])) { + $_is_php[ $version ] = (version_compare(PHP_VERSION, $version) < 0) ? false : true; + } - return $_is_php[$version]; - } + return $_is_php[ $version ]; + } - /** - * Get the base directory of a directory structure - * - * @param string $directory - * @return string - * - */ - public static function getBaseDirectory ($directory) - { - //get public directory structure eg "/top/second/third" - $public_directory = dirname($directory); - //place each directory into array - $directory_array = explode('/', $public_directory); - //get highest or top level in array of directory strings - $public_base = max($directory_array); + /** + * Get the base directory of a directory structure + * + * @param string $directory + * + * @return string + */ + public static function getBaseDirectory($directory) { + //get public directory structure eg "/top/second/third" + $public_directory = dirname($directory); + //place each directory into array + $directory_array = explode('/', $public_directory); + //get highest or top level in array of directory strings + $public_base = max($directory_array); - return $public_base; - } + return $public_base; + } - /** - * This function will take an IP address or IP number in almost any format (that I can think of) and will return it's decimal unsigned equivalent, as a string. - * Kind => Input => Return => long2ip(Return) - * DottedQuadDec => 192.168.255.109 => 3232300909 => 192.168.255.109 - * PosIntStr => 3232300909 => 3232300909 => 192.168.255.109 - * NegIntStr => -1062666387 => 3232300909 => 192.168.255.109 - * PosInt => 3232300909 => 3232300909 => 192.168.255.109 - * NegInt => -1062666387 => 3232300909 => 192.168.255.109 - * DottedQuadHex => 0xc0.0xA8.0xFF.0x6D => 0 => 0.0.0.0 - * DottedQuadOct => 0300.0250.0377.0155 => 0 => 0.0.0.0 - * HexIntStr => 0xC0A8FF6D => 0 => 0.0.0.0 - * HexInt => 3232300909 => 3232300909 => 192.168.255.109 - * - * @param string/numeric $ip - */ - public static function getIp2long ($ip) - { - if (is_numeric($ip)) { - $return = sprintf("%u", floatval($ip)); - } else { - $return = sprintf("%u", floatval(ip2long($ip))); - } + /** + * This function will take an IP address or IP number in almost any format (that I can think of) and will return it's decimal unsigned equivalent, as a string. + * Kind => Input => Return => long2ip(Return) + * DottedQuadDec => 192.168.255.109 => 3232300909 => 192.168.255.109 + * PosIntStr => 3232300909 => 3232300909 => 192.168.255.109 + * NegIntStr => -1062666387 => 3232300909 => 192.168.255.109 + * PosInt => 3232300909 => 3232300909 => 192.168.255.109 + * NegInt => -1062666387 => 3232300909 => 192.168.255.109 + * DottedQuadHex => 0xc0.0xA8.0xFF.0x6D => 0 => 0.0.0.0 + * DottedQuadOct => 0300.0250.0377.0155 => 0 => 0.0.0.0 + * HexIntStr => 0xC0A8FF6D => 0 => 0.0.0.0 + * HexInt => 3232300909 => 3232300909 => 192.168.255.109 + * + * @param string /numeric $ip + */ + public static function getIp2long($ip) { + if (is_numeric($ip)) { + $return = sprintf("%u", floatval($ip)); + } else { + $return = sprintf("%u", floatval(ip2long($ip))); + } - return $return; - } - } + return $return; + } + } } diff --git a/wp-content/plugins/extended-categories-widget/libs/avh-db.php b/wp-content/plugins/extended-categories-widget/libs/avh-db.php index aeb8f0d55a87b6f792a86c37d57acc0266647e45..3e0cfb591aa4d55b5d60f40510d14fa07d14e1f1 100755 --- a/wp-content/plugins/extended-categories-widget/libs/avh-db.php +++ b/wp-content/plugins/extended-categories-widget/libs/avh-db.php @@ -1,20 +1,20 @@ <?php -if (! defined('AVH_FRAMEWORK')) +if ( ! defined('AVH_FRAMEWORK')) { die('You are not allowed to call this page directly.'); -if (! class_exists('AVH_DB')) { - - final class AVH_DB - { +} +if ( ! class_exists('AVH_DB')) { + final class AVH_DB { /** * Fetch MySQL Field Names * - * @access public - * @param string the table name - * @return array + * @access public + * + * @param string the table name + * + * @return array */ - public function getFieldNames ($table = '') - { + public function getFieldNames($table = '') { global $wpdb; $retval = wp_cache_get('field_names_' . $table, 'avhec'); @@ -23,13 +23,13 @@ if (! class_exists('AVH_DB')) { $result = $wpdb->get_results($sql, ARRAY_A); - $retval = array (); + $retval = array(); foreach ($result as $row) { if (isset($row['Field'])) { $retval[] = $row['Field']; } } - wp_cache_set('field_names_' . $table, $retval,'avhec',3600); + wp_cache_set('field_names_' . $table, $retval, 'avhec', 3600); } return $retval; @@ -37,29 +37,32 @@ if (! class_exists('AVH_DB')) { /** * Determine if a particular field exists - * @access public - * @param string - * @param string - * @return boolean + * + * @access public + * + * @param string + * @param string + * + * @return boolean */ - public function field_exists ($field_name, $table_name) - { + public function field_exists($field_name, $table_name) { return (in_array($field_name, $this->getFieldNames($table_name))); } /** * Show column query - * * Generates a platform-specific query string so that the column names can be fetched * - * @access public - * @param string the table name - * @return string + * @access public + * + * @param string the table name + * + * @return string */ - private function _getQueryShowColumns ($table = '') - { + private function _getQueryShowColumns($table = '') { global $wpdb; - return 'SHOW COLUMNS FROM '.$table; + + return 'SHOW COLUMNS FROM ' . $table; } } } diff --git a/wp-content/plugins/extended-categories-widget/libs/avh-registry.php b/wp-content/plugins/extended-categories-widget/libs/avh-registry.php index a24b9117605478f82834e365e41689dc57b26db6..704f80f61794106bc9e5ee3ef13bdd3ca4092d87 100755 --- a/wp-content/plugins/extended-categories-widget/libs/avh-registry.php +++ b/wp-content/plugins/extended-categories-widget/libs/avh-registry.php @@ -1,62 +1,64 @@ <?php -if (! defined('AVH_FRAMEWORK')) +if ( ! defined('AVH_FRAMEWORK')) { die('You are not allowed to call this page directly.'); -if (! class_exists('AVH_Settings_Registry')) { +} +if ( ! class_exists('AVH_Settings_Registry')) { - abstract class AVH_Settings_Registry - { + abstract class AVH_Settings_Registry { /** * Our array of settings + * * @access protected */ - private $_settings = array (); + private $_settings = array(); /** * Stores settings in the registry + * * @param string $data * @param string $key The key for the array + * * @return void */ - public function storeSetting ($key, $data) - { - $this->_settings[$key] = $data; - $this->$key = $data; + public function storeSetting($key, $data) { + $this->_settings[ $key ] = $data; + $this->$key = $data; } /** * Gets a setting from the registry + * * @param string $key The key in the array + * * @return mixed */ - public function getSetting ($key) - { - return $this->_settings[$key]; + public function getSetting($key) { + return $this->_settings[ $key ]; } /** * Removes a setting from the registry + * * @param string $key The key for the array */ - public function removeSetting ($key) - { - unset($this->_settings[$key]); + public function removeSetting($key) { + unset($this->_settings[ $key ]); } } } -if (! class_exists('AVH_Class_Registry')) { +if ( ! class_exists('AVH_Class_Registry')) { /** * Class registry - * */ - abstract class AVH_Class_Registry - { + abstract class AVH_Class_Registry { /** * Our array of objects + * * @access protected * @var array */ - private $_objects = array (); + private $_objects = array(); private $_dir; private $_class_file_prefix; private $_class_name_prefix; @@ -64,81 +66,77 @@ if (! class_exists('AVH_Class_Registry')) { /** * Loads a class * - * @param string $class Name of the class you want to load - * @param string $type What kind of class, System, Plugin + * @param string $class Name of the class you want to load + * @param string $type What kind of class, System, Plugin * @param boolean $store Store the class in the registry + * * @return object */ - public function load_class ($class, $type = 'system', $store = false) - { - if (isset($this->_objects[$class])) { - return ($this->_objects[$class]); + public function load_class($class, $type = 'system', $store = false) { + if (isset($this->_objects[ $class ])) { + return ($this->_objects[ $class ]); } switch ($type) { case 'plugin': - $in = '/class'; + $in = '/class'; $file = $this->_class_file_prefix . $class . '.php'; break; case 'system': default: - $in = '/libs'; + $in = '/libs'; $file = 'avh-' . $class . '.php'; } - require_once ($this->_dir . $in . '/' . strtolower($file)); - $name = ('system' == $type) ? 'AVH_' . $class : $this->_class_name_prefix . $class; + require_once($this->_dir . $in . '/' . strtolower($file)); + $name = ('system' == $type) ? 'AVH_' . $class : $this->_class_name_prefix . $class; $object = $this->instantiate_class(new $name()); if ($store) { - $this->_objects[$class] = $object; + $this->_objects[ $class ] = $object; } + return $object; } /** * Instantiate Class - * * Returns a new class object by reference, used by load_class() and the DB class. * Required to make PHP 5.3 cry. - * * Use: $obj =& instantiate_class(new Foo()); * - * @access public - * @param object - * @return object + * @access public + * + * @param object + * + * @return object */ - protected function instantiate_class (&$class_object) - { + protected function instantiate_class(&$class_object) { return $class_object; } /** * @param $dir the $dir to set */ - public function setDir ($dir) - { + public function setDir($dir) { $this->_dir = $dir; } /** - * @param $class Unique Identifier + * @param $class Unique Identifier * @param $class_prefix the $class_prefix to set */ - public function setClassFilePrefix ($class_prefix) - { + public function setClassFilePrefix($class_prefix) { $this->_class_file_prefix = $class_prefix; } /** - * @param $class Unique Identifier + * @param $class Unique Identifier * @param $class_name_prefix the $class_name_prefix to set */ - public function setClassNamePrefix ($class_name_prefix) - { + public function setClassNamePrefix($class_name_prefix) { $this->_class_name_prefix = $class_name_prefix; } - public function setClassProperties ($properties) - { - $default_properties = array ( 'type' => 'system', 'store' => false ); + public function setClassProperties($properties) { + $default_properties = array('type' => 'system', 'store' => false); } } } \ No newline at end of file diff --git a/wp-content/plugins/extended-categories-widget/libs/avh-security.php b/wp-content/plugins/extended-categories-widget/libs/avh-security.php index 36bc02a8f37bf7ad3f75f6e6a90e7d78f2354242..4a765bebd4fc5b9ac0f0414d16221ba0eebdaaee 100755 --- a/wp-content/plugins/extended-categories-widget/libs/avh-security.php +++ b/wp-content/plugins/extended-categories-widget/libs/avh-security.php @@ -1,46 +1,47 @@ <?php -if (! defined('AVH_FRAMEWORK')) +if ( ! defined('AVH_FRAMEWORK')) { die('You are not allowed to call this page directly.'); -if (! class_exists('AVH_Security')) { - - final class AVH_Security - { +} +if ( ! class_exists('AVH_Security')) { + final class AVH_Security { /** * Local nonce creation. WordPress uses the UID and sometimes I don't want that * Creates a random, one time use token. * * @param string|int $action Scalar value to add context to the nonce. - * @return string The one use form token * + * @return string The one use form token */ - public static function createNonce ($action = -1) - { + public static function createNonce($action = - 1) { $i = wp_nonce_tick(); + return substr(wp_hash($i . $action, 'nonce'), - 12, 10); } /** * Local nonce verification. WordPress uses the UID and sometimes I don't want that * Verify that correct nonce was used with time limit. - * * The user is given an amount of time to use the token, so therefore, since the * $action remain the same, the independent variable is the time. * - * @param string $nonce Nonce that was used in the form to verify + * @param string $nonce Nonce that was used in the form to verify * @param string|int $action Should give context to what is taking place and be the same when nonce was created. + * * @return bool Whether the nonce check passed or failed. */ - public static function verifyNonce ($nonce, $action = -1) - { + public static function verifyNonce($nonce, $action = - 1) { $r = false; $i = wp_nonce_tick(); // Nonce generated 0-12 hours ago if (substr(wp_hash($i . $action, 'nonce'), - 12, 10) == $nonce) { $r = 1; - } elseif (substr(wp_hash(($i - 1) . $action, 'nonce'), - 12, 10) == $nonce) { // Nonce generated 12-24 hours ago + } elseif (substr(wp_hash(($i - 1) . $action, 'nonce'), - 12, 10) == + $nonce + ) { // Nonce generated 12-24 hours ago $r = 2; } + return $r; } } diff --git a/wp-content/plugins/extended-categories-widget/libs/avh-visitor.php b/wp-content/plugins/extended-categories-widget/libs/avh-visitor.php index 6906a2bc9fe74ab74d0e97ba11f2043c662fb14b..a50c25102f0a86a3439752d37b3fc8cff846da5d 100755 --- a/wp-content/plugins/extended-categories-widget/libs/avh-visitor.php +++ b/wp-content/plugins/extended-categories-widget/libs/avh-visitor.php @@ -1,23 +1,31 @@ <?php -if (! defined('AVH_FRAMEWORK')) +if ( ! defined('AVH_FRAMEWORK')) { die('You are not allowed to call this page directly.'); -if (! class_exists('AVH_Visitor')) { - - final class AVH_Visitor - { +} +if ( ! class_exists('AVH_Visitor')) { + final class AVH_Visitor { /** * Get the user's IP * * @return string */ - public static function getUserIp () - { - $ip = array (); - foreach (array ( 'HTTP_CF_CONNECTING_IP', 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', - 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR' ) as $key) { + public static function getUserIp() { + $ip = array(); + foreach ( + array( + 'HTTP_CF_CONNECTING_IP', + 'HTTP_CLIENT_IP', + 'HTTP_X_FORWARDED_FOR', + 'HTTP_X_FORWARDED', + 'HTTP_X_CLUSTER_CLIENT_IP', + 'HTTP_FORWARDED_FOR', + 'HTTP_FORWARDED', + 'REMOTE_ADDR' + ) as $key + ) { if (array_key_exists($key, $_SERVER) === true) { - foreach (explode(',', $_SERVER[$key]) as $visitors_ip) { + foreach (explode(',', $_SERVER[ $key ]) as $visitors_ip) { $ip[] = str_replace(' ', '', $visitors_ip); } } @@ -26,7 +34,7 @@ if (! class_exists('AVH_Visitor')) { if (empty($ip)) { return '0.0.0.0'; } - $ip = array_values(array_unique($ip)); + $ip = array_values(array_unique($ip)); $return = null; // In PHP 5.3 and up the function filter_var can be used, much quicker as the regular expression check if (AVH_Common::isPHP('5.3')) { @@ -37,9 +45,9 @@ if (! class_exists('AVH_Visitor')) { } } } else { - $dec_octet = '(?:\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])'; + $dec_octet = '(?:\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])'; $ip4_address = $dec_octet . '.' . $dec_octet . '.' . $dec_octet . '.' . $dec_octet; - $match = array (); + $match = array(); foreach ($ip as $i) { if (preg_match('/^' . $ip4_address . '$/', $i, $match)) { if (preg_match('/^(127\.|10\.|192\.168\.|172\.((1[6-9])|(2[0-9])|(3[0-1]))\.)/', $i)) { @@ -54,6 +62,7 @@ if (! class_exists('AVH_Visitor')) { if (null === $return) { $return = '0.0.0.0'; } + return $return; } } diff --git a/wp-content/plugins/extended-categories-widget/readme.txt b/wp-content/plugins/extended-categories-widget/readme.txt index 46de71ff6200590eb1fcecc21e7335d1f9bce888..b026320ab58ee52d8aa30d2dabf5c940215e1c1a 100644 --- a/wp-content/plugins/extended-categories-widget/readme.txt +++ b/wp-content/plugins/extended-categories-widget/readme.txt @@ -3,8 +3,8 @@ Contributors: petervanderdoes Donate link: http://blog.avirtualhome.com/wordpress-plugins/ Tags: extended, categories, widget, top categories Requires at least: 2.3 -Tested up to: 4.2 -Stable tag: 4.0.1 +Tested up to: 4.5 +Stable tag: 4.0.6 The AVH Extended Categories Widgets gives you three widgets for displaying categories. == Description == @@ -139,8 +139,25 @@ Whether Widget 2 shows Movie or Music depends on the creation order of groups. I None == Changelog == += Version 4.0.6 = +* Creating the standard groups sometimes lead to an error. + += Version 4.0.5 = +* To much comment out. + += Version 4.0.4 = +* Uncaught error can occur at times. + += Version 4.0.3 = +* Security fix +* Update methods for displaying the categories +* Move to minified javascript + += Version 4.0.2 = +* Certain methods show notice of undefined variables. + = Version 4.0.1 = -* Post-Auth SQL Injection Vulnerability +* Post-Auth SQL Injection Vulnerability Only occurs for WordPress versions lower than 3.3 = Version 4.0.0 = diff --git a/wp-content/plugins/extended-categories-widget/uninstall.php b/wp-content/plugins/extended-categories-widget/uninstall.php index 3dfd0895b1f48e4f0a71aba30af19970358bc2b3..c5c4a483204bfb88398c0c60e15cc2e824e57212 100644 --- a/wp-content/plugins/extended-categories-widget/uninstall.php +++ b/wp-content/plugins/extended-categories-widget/uninstall.php @@ -2,21 +2,21 @@ // This is an include file, all normal WordPress functions will still work. // Because the plugin is already deactivated it won't recognize any class declarations. - -if (! defined('ABSPATH') && ! defined('WP_UNINSTALL_PLUGIN')) +if ( ! defined('ABSPATH') && ! defined('WP_UNINSTALL_PLUGIN')) { exit(); +} global $wpdb; if ('extended-categories-widget' == dirname($file)) { delete_option('avhec'); delete_option('avhec-tax_meta'); $db__used_by_plugin[] = $wpdb->prefix . 'avhec_category_groups'; - foreach($db__used_by_plugin as $table) { + foreach ($db__used_by_plugin as $table) { $wpdb->query('DROP TABLE IF EXISTS `' . $table . '`'); } - $result = $wpdb->query("ALTER TABLE $wpdb->terms DROP `avhec_term_order`"); - $cat_terms = get_terms('avhec_catgroup', array('hide_empty'=>false)); - foreach($cat_terms as $cat_term){ + $result = $wpdb->query("ALTER TABLE $wpdb->terms DROP `avhec_term_order`"); + $cat_terms = get_terms('avhec_catgroup', array('hide_empty' => false)); + foreach ($cat_terms as $cat_term) { wp_delete_term($cat_term->term_id, 'avhec_catgroup'); } } \ No newline at end of file diff --git a/wp-content/plugins/extended-categories-widget/widget-pre2.8.php b/wp-content/plugins/extended-categories-widget/widget-pre2.8.php index 85ce33d2b5fc21753ef98f67e674674a6a78bdad..aa2c4269df9b9676ddf1ccbc39caa981cabbba9f 100644 --- a/wp-content/plugins/extended-categories-widget/widget-pre2.8.php +++ b/wp-content/plugins/extended-categories-widget/widget-pre2.8.php @@ -1,17 +1,15 @@ <?php -function widget_extended_categories_init () -{ +function widget_extended_categories_init() { // Widgets exists? - if (! function_exists('wp_register_sidebar_widget') || ! function_exists('wp_register_widget_control')) { + if ( ! function_exists('wp_register_sidebar_widget') || ! function_exists('wp_register_widget_control')) { return; } - function widget_extended_categories ($args, $number = 1) - { + function widget_extended_categories($args, $number = 1) { $version = '3.6.4'; // Check for version - require (ABSPATH . WPINC . '/version.php'); + require(ABSPATH . WPINC . '/version.php'); if (version_compare($wp_version, '2.5.1', '<')) { $avh_extcat_canselectcats = false; } else { @@ -19,32 +17,58 @@ function widget_extended_categories_init () } extract($args); $options = get_option('widget_extended_categories'); - $c = $options[$number]['count'] ? '1' : '0'; - $h = $options[$number]['hierarchical'] ? '1' : '0'; - $e = $options[$number]['hide_empty'] ? '1' : '0'; - $s = $options[$number]['sort_column'] ? $options[$number]['sort_column'] : 'name'; - $o = $options[$number]['sort_order'] ? $options[$number]['sort_order'] : 'asc'; - $r = $options[$number]['rssfeed'] ? 'RSS' : ''; - $i = $options[$number]['rssimage'] ? $options[$number]['rssimage'] : ''; + $c = $options[ $number ]['count'] ? '1' : '0'; + $h = $options[ $number ]['hierarchical'] ? '1' : '0'; + $e = $options[ $number ]['hide_empty'] ? '1' : '0'; + $s = $options[ $number ]['sort_column'] ? $options[ $number ]['sort_column'] : 'name'; + $o = $options[ $number ]['sort_order'] ? $options[ $number ]['sort_order'] : 'asc'; + $r = $options[ $number ]['rssfeed'] ? 'RSS' : ''; + $i = $options[ $number ]['rssimage'] ? $options[ $number ]['rssimage'] : ''; if (empty($r)) { $i = ''; } - - $title = empty($options[$number]['title']) ? __('Categories') : attribute_escape($options[$number]['title']); - $style = empty($options[$number]['style']) ? 'list' : $options[$number]['style']; + + $title = empty($options[ $number ]['title']) ? __('Categories') : attribute_escape($options[ $number ]['title']); + $style = empty($options[ $number ]['style']) ? 'list' : $options[ $number ]['style']; if ($avh_extcat_canselectcats) { - if ($options[$number]['post_category']) { - $post_category = unserialize($options[$number]['post_category']); + if ($options[ $number ]['post_category']) { + $post_category = unserialize($options[ $number ]['post_category']); $included_cats = implode(",", $post_category); } - $cat_args = array('include'=>$included_cats, 'orderby'=>$s, 'order'=>$o, 'show_count'=>$c, 'hide_empty'=>$e, 'hierarchical'=>$h, 'title_li'=>'', 'show_option_none'=>__('Select Category'), 'feed'=>$r, 'feed_image'=>$i, 'name'=>'ec-cat-' . $number, 'depth'=>2); + $cat_args = array( + 'include' => $included_cats, + 'orderby' => $s, + 'order' => $o, + 'show_count' => $c, + 'hide_empty' => $e, + 'hierarchical' => $h, + 'title_li' => '', + 'show_option_none' => __('Select Category'), + 'feed' => $r, + 'feed_image' => $i, + 'name' => 'ec-cat-' . $number, + 'depth' => 2 + ); } else { - $cat_args = array('orderby'=>$s, 'order'=>$o, 'show_count'=>$c, 'hide_empty'=>$e, 'hierarchical'=>$h, 'title_li'=>'', 'show_option_none'=>__('Select Category'), 'feed'=>$r, 'feed_image'=>$i, 'name'=>'ec-cat-' . $number); + $cat_args = array( + 'orderby' => $s, + 'order' => $o, + 'show_count' => $c, + 'hide_empty' => $e, + 'hierarchical' => $h, + 'title_li' => '', + 'show_option_none' => __('Select Category'), + 'feed' => $r, + 'feed_image' => $i, + 'name' => 'ec-cat-' . $number + ); } echo $before_widget; - echo '<!-- AVH Extended Categories version ' . $version . ' | http://blog.avirtualhome.com/wordpress-plugins/ -->'; + echo '<!-- AVH Extended Categories version ' . + $version . + ' | http://blog.avirtualhome.com/wordpress-plugins/ -->'; echo $before_title . $title . $after_title; - + if ($style == 'list') { echo '<ul>'; wp_list_categories($cat_args); @@ -52,44 +76,43 @@ function widget_extended_categories_init () } else { wp_dropdown_categories($cat_args); ?> -<script lang='javascript'><!-- - var ec_dropdown_<?php - echo ($number); - ?> = document.getElementById('ec-cat-<?php - echo ($number); - ?>'); - function ec_onCatChange_<?php - echo ($number); - ?>() { - if ( ec_dropdown_<?php - echo ($number); - ?>.options[ec_dropdown_<?php - echo ($number); - ?>.selectedIndex].value > 0 ) { - location.href = "<?php - echo get_option('home'); - ?>/?cat="+ec_dropdown_<?php - echo ($number); - ?>.options[ec_dropdown_<?php - echo ($number); - ?>.selectedIndex].value; - } - } - ec_dropdown_<?php - echo ($number); - ?>.onchange = ec_onCatChange_<?php - echo ($number); - ?>; ---></script> -<?php + <script lang='javascript'><!-- + var ec_dropdown_<?php + echo($number); + ?> = document.getElementById('ec-cat-<?php + echo($number); + ?>'); + function ec_onCatChange_ <?php + echo($number); + ?>() { + if (ec_dropdown_<?php + echo($number); + ?>.options[ec_dropdown_<?php + echo($number); + ?>.selectedIndex].value > 0) { + location.href = "<?php + echo get_option('home'); + ?>/?cat=" + ec_dropdown_<?php + echo($number); + ?>.options[ec_dropdown_<?php + echo($number); + ?>.selectedIndex].value; + } + } + ec_dropdown_<?php + echo($number); + ?>.onchange = ec_onCatChange_<?php + echo($number); + ?>; + --></script> + <?php } echo $after_widget; } - function widget_extended_categories_control ($number = 1) - { + function widget_extended_categories_control($number = 1) { // Check for version - require (ABSPATH . WPINC . '/version.php'); + require(ABSPATH . WPINC . '/version.php'); if (version_compare($wp_version, '2.5.1', '<')) { $avh_extcat_canselectcats = false; } else { @@ -97,226 +120,238 @@ function widget_extended_categories_init () } // Get actual options $options = $newoptions = get_option('widget_extended_categories'); - if (! is_array($options)) { + if ( ! is_array($options)) { $options = $newoptions = array(); } // Post to new options array - - if ($_POST['categories-submit-' . $number]) { - $newoptions[$number]['title'] = strip_tags(stripslashes($_POST['categories-title-' . $number])); - $newoptions[$number]['count'] = isset($_POST['categories-count-' . $number]); - $newoptions[$number]['hierarchical'] = isset($_POST['categories-hierarchical-' . $number]); - $newoptions[$number]['hide_empty'] = isset($_POST['categories-hide_empty-' . $number]); - $newoptions[$number]['sort_column'] = strip_tags(stripslashes($_POST['categories-sort_column-' . $number])); - $newoptions[$number]['sort_order'] = strip_tags(stripslashes($_POST['categories-sort_order-' . $number])); - $newoptions[$number]['style'] = strip_tags(stripslashes($_POST['categories-style-' . $number])); - $newoptions[$number]['rssfeed'] = isset($_POST['categories-rssfeed-' . $number]); - $newoptions[$number]['rssimage'] = attribute_escape($_POST['categories-rssimage-' . $number]); + if ($_POST[ 'categories-submit-' . $number ]) { + $newoptions[ $number ]['title'] = strip_tags(stripslashes($_POST[ 'categories-title-' . $number ])); + $newoptions[ $number ]['count'] = isset($_POST[ 'categories-count-' . $number ]); + $newoptions[ $number ]['hierarchical'] = isset($_POST[ 'categories-hierarchical-' . $number ]); + $newoptions[ $number ]['hide_empty'] = isset($_POST[ 'categories-hide_empty-' . $number ]); + $newoptions[ $number ]['sort_column'] = strip_tags(stripslashes($_POST[ 'categories-sort_column-' . + $number ])); + $newoptions[ $number ]['sort_order'] = strip_tags(stripslashes($_POST[ 'categories-sort_order-' . + $number ])); + $newoptions[ $number ]['style'] = strip_tags(stripslashes($_POST[ 'categories-style-' . $number ])); + $newoptions[ $number ]['rssfeed'] = isset($_POST[ 'categories-rssfeed-' . $number ]); + $newoptions[ $number ]['rssimage'] = attribute_escape($_POST[ 'categories-rssimage-' . $number ]); if ($avh_extcat_canselectcats) { - if (in_array('-1', $_POST['post_category-' . $number], true)) { - $newoptions[$number]['post_category'] = false; + if (in_array('-1', $_POST[ 'post_category-' . $number ], true)) { + $newoptions[ $number ]['post_category'] = false; } else { - $newoptions[$number]['post_category'] = serialize($_POST['post_category-' . $number]); + $newoptions[ $number ]['post_category'] = serialize($_POST[ 'post_category-' . $number ]); } } - } - + // Update if new options if ($options != $newoptions) { $options = $newoptions; update_option('widget_extended_categories', $options); } - + // Prepare data for display - $title = htmlspecialchars($options[$number]['title'], ENT_QUOTES); - $count = $options[$number]['count'] ? 'checked="checked"' : ''; - $hierarchical = $options[$number]['hierarchical'] ? 'checked="checked"' : ''; - $hide_empty = $options[$number]['hide_empty'] ? 'checked="checked"' : ''; - $sort_id = ($options[$number]['sort_column'] == 'ID') ? ' SELECTED' : ''; - $sort_name = ($options[$number]['sort_column'] == 'name') ? ' SELECTED' : ''; - $sort_count = ($options[$number]['sort_column'] == 'count') ? ' SELECTED' : ''; - $sort_order_a = ($options[$number]['sort_order'] == 'asc') ? ' SELECTED' : ''; - $sort_order_d = ($options[$number]['sort_order'] == 'desc') ? ' SELECTED' : ''; - $style_list = ($options[$number]['style'] == 'list') ? ' SELECTED' : ''; - $style_drop = ($options[$number]['style'] == 'drop') ? ' SELECTED' : ''; - $rssfeed = $options[$number]['rssfeed'] ? 'checked="checked"' : ''; - $rssimage = htmlspecialchars($options[$number]['rssimage'], ENT_QUOTES); + $title = htmlspecialchars($options[ $number ]['title'], ENT_QUOTES); + $count = $options[ $number ]['count'] ? 'checked="checked"' : ''; + $hierarchical = $options[ $number ]['hierarchical'] ? 'checked="checked"' : ''; + $hide_empty = $options[ $number ]['hide_empty'] ? 'checked="checked"' : ''; + $sort_id = ($options[ $number ]['sort_column'] == 'ID') ? ' SELECTED' : ''; + $sort_name = ($options[ $number ]['sort_column'] == 'name') ? ' SELECTED' : ''; + $sort_count = ($options[ $number ]['sort_column'] == 'count') ? ' SELECTED' : ''; + $sort_order_a = ($options[ $number ]['sort_order'] == 'asc') ? ' SELECTED' : ''; + $sort_order_d = ($options[ $number ]['sort_order'] == 'desc') ? ' SELECTED' : ''; + $style_list = ($options[ $number ]['style'] == 'list') ? ' SELECTED' : ''; + $style_drop = ($options[ $number ]['style'] == 'drop') ? ' SELECTED' : ''; + $rssfeed = $options[ $number ]['rssfeed'] ? 'checked="checked"' : ''; + $rssimage = htmlspecialchars($options[ $number ]['rssimage'], ENT_QUOTES); if ($avh_extcat_canselectcats) { - $selected_cats = ($options[$number]['post_category'] != '') ? unserialize($options[$number]['post_category']) : false; + $selected_cats = ($options[ $number ]['post_category'] != + '') ? unserialize($options[ $number ]['post_category']) : false; } ?> -<div><label for="categories-title-<?php - echo $number; - ?>"><?php - _e('Title:'); - ?> - <input style="width: 250px;" - id="categories-title-<?php - echo $number; - ?>" - name="categories-title-<?php - echo $number; - ?>" type="text" - value="<?php - echo $title; - ?>" /> </label> <label - for="categories-count-<?php - echo $number; - ?>" - style="line-height: 35px; display: block;">Show post counts <input - class="checkbox" type="checkbox" <?php - echo $count; - ?> - id="categories-count-<?php - echo $number; - ?>" - name="categories-count-<?php - echo $number; - ?>" /> </label> <label - for="categories-hierarchical" - style="line-height: 35px; display: block;">Show hierarchy <input - class="checkbox" type="checkbox" <?php - echo $hierarchical; - ?> - id="categories-hierarchical-<?php - echo $number; - ?>" - name="categories-hierarchical-<?php - echo $number; - ?>" /> </label> <label - for="categories-hide_empty-<?php - echo $number; - ?>" - style="line-height: 35px; display: block;">Hide empty categories <input - class="checkbox" type="checkbox" <?php - echo $hide_empty; - ?> - id="categories-hide_empty-<?php - echo $number; - ?>" - name="categories-hide_empty-<?php - echo $number; - ?>" /> </label> <label - for="categories-sort_column-<?php - echo $number; - ?>" - style="line-height: 35px; display: block;">Sort by <select - id="categories-sort_column-<?php - echo $number; - ?>" - name="categories-sort_column-<?php - echo $number; - ?>"> - <option value="ID" <?php - echo $sort_id?>>ID</option> - <option value="name" <?php - echo $sort_name?>>Name</option> - <option value="count" <?php - echo $sort_count?>>Count</option> -</select> </label> <label - for="categories-sort_order-<?php - echo $number; - ?>" - style="line-height: 35px; display: block;">Sort order <select - id="categories-sort_order-<?php - echo $number; - ?>" - name="categories-sort_order-<?php - echo $number; - ?>"> - <option value="asc" <?php - echo $sort_order_a?>>Ascending</option> - <option value="desc" <?php - echo $sort_order_d?>>Descending</option> -</select> </label> <label for="categories-style-<?php - echo $number; - ?>" - style="line-height: 35px; display: block;">Display style <select - id="categories-style-<?php - echo $number; - ?>" - name="categories-style-<?php - echo $number; - ?>"> - <option value='list' <?php - echo $style_list; - ?>>List</option> - <option value='drop' <?php - echo $style_drop; - ?>>Drop down</option> -</select> </label> <label - for="categories-rssfeed-<?php - echo $number; - ?>" - style="line-height: 35px; display: block;">Show RSS Feed <input - class="checkbox" type="checkbox" <?php - echo $rssfeed; - ?> - id="categories-rssfeed-<?php - echo $number; - ?>" - name="categories-rssfeed-<?php - echo $number; - ?>" /> </label> <label - for="categories-rssimage-<?php - echo $number; - ?>"><?php - _e('Path (URI) to RSS image:'); - ?> - <input style="width: 250px;" - id="categories-rssimage-<?php - echo $number; - ?>" - name="categories-rssimage-<?php - echo $number; - ?>" type="text" - value="<?php - echo $rssimage; - ?>" /> </label> + <div><label for="categories-title-<?php + echo $number; + ?>"><?php + _e('Title:'); + ?> + <input style="width: 250px;" + id="categories-title-<?php + echo $number; + ?>" + name="categories-title-<?php + echo $number; + ?>" type="text" + value="<?php + echo $title; + ?>"/> </label> <label + for="categories-count-<?php + echo $number; + ?>" + style="line-height: 35px; display: block;">Show post counts <input + class="checkbox" type="checkbox" <?php + echo $count; + ?> + id="categories-count-<?php + echo $number; + ?>" + name="categories-count-<?php + echo $number; + ?>"/> </label> <label + for="categories-hierarchical" + style="line-height: 35px; display: block;">Show hierarchy <input + class="checkbox" type="checkbox" <?php + echo $hierarchical; + ?> + id="categories-hierarchical-<?php + echo $number; + ?>" + name="categories-hierarchical-<?php + echo $number; + ?>"/> </label> <label + for="categories-hide_empty-<?php + echo $number; + ?>" + style="line-height: 35px; display: block;">Hide empty categories <input + class="checkbox" type="checkbox" <?php + echo $hide_empty; + ?> + id="categories-hide_empty-<?php + echo $number; + ?>" + name="categories-hide_empty-<?php + echo $number; + ?>"/> </label> <label + for="categories-sort_column-<?php + echo $number; + ?>" + style="line-height: 35px; display: block;">Sort by <select + id="categories-sort_column-<?php + echo $number; + ?>" + name="categories-sort_column-<?php + echo $number; + ?>"> + <option value="ID" <?php + echo $sort_id ?>>ID + </option> + <option value="name" <?php + echo $sort_name ?>>Name + </option> + <option value="count" <?php + echo $sort_count ?>>Count + </option> + </select> </label> <label + for="categories-sort_order-<?php + echo $number; + ?>" + style="line-height: 35px; display: block;">Sort order <select + id="categories-sort_order-<?php + echo $number; + ?>" + name="categories-sort_order-<?php + echo $number; + ?>"> + <option value="asc" <?php + echo $sort_order_a ?>>Ascending + </option> + <option value="desc" <?php + echo $sort_order_d ?>>Descending + </option> + </select> </label> <label for="categories-style-<?php + echo $number; + ?>" + style="line-height: 35px; display: block;">Display style <select + id="categories-style-<?php + echo $number; + ?>" + name="categories-style-<?php + echo $number; + ?>"> + <option value='list' <?php + echo $style_list; + ?>>List + </option> + <option value='drop' <?php + echo $style_drop; + ?>>Drop down + </option> + </select> </label> <label + for="categories-rssfeed-<?php + echo $number; + ?>" + style="line-height: 35px; display: block;">Show RSS Feed <input + class="checkbox" type="checkbox" <?php + echo $rssfeed; + ?> + id="categories-rssfeed-<?php + echo $number; + ?>" + name="categories-rssfeed-<?php + echo $number; + ?>"/> </label> <label + for="categories-rssimage-<?php + echo $number; + ?>"><?php + _e('Path (URI) to RSS image:'); + ?> + <input style="width: 250px;" + id="categories-rssimage-<?php + echo $number; + ?>" + name="categories-rssimage-<?php + echo $number; + ?>" type="text" + value="<?php + echo $rssimage; + ?>"/> </label> -<?php - if ($avh_extcat_canselectcats) { - echo ' <b>Include these categories</b><hr />'; - 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;">'; - echo ' <li id="category--1-' . $number . '" class="popular-category">'; - echo ' <label for="in-category--1-' . $number . '" class="selectit">'; - echo ' <input value="-1" name="post_category-' . $number . '[]" id="in-category--1-' . $number . '" type="checkbox"'; - if (! $selected_cats) { - echo 'checked'; + <?php + if ($avh_extcat_canselectcats) { + echo ' <b>Include these categories</b><hr />'; + 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;">'; + echo ' <li id="category--1-' . $number . '" class="popular-category">'; + echo ' <label for="in-category--1-' . $number . '" class="selectit">'; + echo ' <input value="-1" name="post_category-' . + $number . + '[]" id="in-category--1-' . + $number . + '" type="checkbox"'; + if ( ! $selected_cats) { + echo 'checked'; + } + echo '> Include All Categories'; + echo ' </label>'; + echo ' </li>'; + avh_wp_category_checklist(0, 0, $selected_cats, false, $number); + echo ' </ul>'; } - echo '> Include All Categories'; - echo ' </label>'; - echo ' </li>'; - avh_wp_category_checklist(0, 0, $selected_cats, false, $number); - echo ' </ul>'; - } - ?> + ?> - <input type="hidden" id="categories-submit-<?php - echo $number; - ?>" - name="categories-submit-<?php - echo $number; - ?>" value="1" /></div> -<?php + <input type="hidden" id="categories-submit-<?php + echo $number; + ?>" + name="categories-submit-<?php + echo $number; + ?>" value="1"/></div> + <?php } /** * Called after the widget_extended_categories_page form has been submitted. * Set the amount of widgets wanted and register the widgets - * */ - function widget_extended_categories_setup () - { + function widget_extended_categories_setup() { $options = $newoptions = get_option('widget_extended_categories'); if (isset($_POST['extended_categories-number-submit'])) { $number = (int) $_POST['extended_categories-number']; - if ($number > 9) + if ($number > 9) { $number = 9; - if ($number < 1) + } + if ($number < 1) { $number = 1; + } $newoptions['number'] = $number; } if ($options != $newoptions) { @@ -328,151 +363,189 @@ function widget_extended_categories_init () /** * How many Wish List widgets are wanted. - * */ - function widget_extended_categories_page () - { + function widget_extended_categories_page() { $options = get_option('widget_extended_categories'); ?> -<div class="wrap"> -<form method="post"> -<h2><?php - _e('AVH Extended Categories Widgets', 'avhextendedcategories'); - ?></h2> -<p style="line-height: 30px;"><?php - _e('How many wishlist widgets would you like?', 'avhextendedcategories'); - ?> - <select id="extended_categories-number" - name="extended_categories-number" - value="<?php - echo $options['number']; - ?>"> - <?php - for ($i = 1; $i < 10; ++ $i) - echo "<option value='$i' " . ($options['number'] == $i ? "selected='selected'" : '') . ">$i</option>"; - ?> - </select> <span class="submit"><input type="submit" - name="extended_categories-number-submit" - id="extended_categories-number-submit" - value="<?php - echo attribute_escape(__('Save', 'avhextendedcategories')); - ?>" /></span></p> -</form> -</div> -<?php + <div class="wrap"> + <form method="post"> + <h2><?php + _e('AVH Extended Categories Widgets', 'avhextendedcategories'); + ?></h2> + <p style="line-height: 30px;"><?php + _e('How many wishlist widgets would you like?', 'avhextendedcategories'); + ?> + <select id="extended_categories-number" + name="extended_categories-number" + value="<?php + echo $options['number']; + ?>"> + <?php + for ($i = 1; $i < 10; ++ $i) { + echo "<option value='$i' " . + ($options['number'] == $i ? "selected='selected'" : '') . + ">$i</option>"; + } + ?> + </select> <span class="submit"><input type="submit" + name="extended_categories-number-submit" + id="extended_categories-number-submit" + value="<?php + echo attribute_escape(__('Save', 'avhextendedcategories')); + ?>"/></span></p> + </form> + </div> + <?php } - function widget_extended_categories_register () - { + function widget_extended_categories_register() { $options = get_option('widget_extended_categories'); - + $number = (int) $options['number']; - if ($number < 1) + if ($number < 1) { $number = 1; - if ($number > 9) + } + if ($number > 9) { $number = 9; + } for ($i = 1; $i <= 9; $i ++) { - $id = "extended-categories-$i"; + $id = "extended-categories-$i"; $name = sprintf(__('Extended Categories %d'), $i); - wp_register_sidebar_widget($id, $name, $i <= $number ? 'widget_extended_categories' : /* unregister */ '', array('classname'=>'widget_extended_categories_init'), $i); - wp_register_widget_control($id, $name, $i <= $number ? 'widget_extended_categories_control' : /* unregister */ '', array('width'=>300, 'height'=>270), $i); + wp_register_sidebar_widget($id, + $name, + $i <= $number ? 'widget_extended_categories' : /* unregister */ + '', + array('classname' => 'widget_extended_categories_init'), + $i); + wp_register_widget_control($id, + $name, + $i <= $number ? 'widget_extended_categories_control' : /* unregister */ + '', + array('width' => 300, 'height' => 270), + $i); } add_action('sidebar_admin_setup', 'widget_extended_categories_setup'); add_action('sidebar_admin_page', 'widget_extended_categories_page'); } - + // Launch Widgets widget_extended_categories_register(); } + add_action('plugins_loaded', 'widget_extended_categories_init'); /** - * As the original wp_category_checklist doesn't support multiple lists on the same page I needed to duplicate the functions - * use by the wp_category_checklist function - * + * As the original wp_category_checklist doesn't support multiple lists on the same page I needed to duplicate the + * functions use by the wp_category_checklist function */ + /** * Class that will display the categories - * */ -class AVH_Walker_Category_Checklist extends Walker -{ +class AVH_Walker_Category_Checklist extends Walker { + var $db_fields = array('parent' => 'parent', 'id' => 'term_id'); + var $number; //TODO: decouple this var $tree_type = 'category'; - var $db_fields = array('parent'=>'parent', 'id'=>'term_id'); //TODO: decouple this - var $number; - function start_lvl (&$output, $depth, $args) - { - $indent = str_repeat("\t", $depth); - $output .= "$indent<ul class='children'>\n"; + function end_el(&$output, $category, $depth, $args) { + $output .= "</li>\n"; } - function end_lvl (&$output, $depth, $args) - { + function end_lvl(&$output, $depth, $args) { $indent = str_repeat("\t", $depth); $output .= "$indent</ul>\n"; } - function start_el (&$output, $category, $depth, $args) - { + function start_el(&$output, $category, $depth, $args) { extract($args); - + $class = in_array($category->term_id, $popular_cats) ? ' class="popular-category"' : ''; - $output .= "\n<li id='category-$category->term_id-$this->number'$class>" . '<label for="in-category-' . $category->term_id . '-' . $this->number . '" class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="post_category-' . $this->number . '[]" id="in-category-' . $category->term_id . '-' . $this->number . '"' . (in_array($category->term_id, $selected_cats) ? ' checked="checked"' : "") . '/> ' . wp_specialchars(apply_filters('the_category', $category->name)) . '</label>'; + $output .= "\n<li id='category-$category->term_id-$this->number'$class>" . + '<label for="in-category-' . + $category->term_id . + '-' . + $this->number . + '" class="selectit"><input value="' . + $category->term_id . + '" type="checkbox" name="post_category-' . + $this->number . + '[]" id="in-category-' . + $category->term_id . + '-' . + $this->number . + '"' . + (in_array($category->term_id, $selected_cats) ? ' checked="checked"' : "") . + '/> ' . + wp_specialchars(apply_filters('the_category', $category->name)) . + '</label>'; } - function end_el (&$output, $category, $depth, $args) - { - $output .= "</li>\n"; + function start_lvl(&$output, $depth, $args) { + $indent = str_repeat("\t", $depth); + $output .= "$indent<ul class='children'>\n"; } } /** * Creates the categories checklist * - * @param int $post_id - * @param int $descendants_and_self + * @param int $post_id + * @param int $descendants_and_self * @param array $selected_cats * @param array $popular_cats - * @param int $number + * @param int $number */ -function avh_wp_category_checklist ($post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $number) -{ - $walker = new AVH_Walker_Category_Checklist(); +function avh_wp_category_checklist( + $post_id = 0, + $descendants_and_self = 0, + $selected_cats = false, + $popular_cats = false, + $number +) { + $walker = new AVH_Walker_Category_Checklist(); $walker->number = $number; - + $descendants_and_self = (int) $descendants_and_self; - + $args = array(); - if (is_array($selected_cats)) + if (is_array($selected_cats)) { $args['selected_cats'] = $selected_cats; - elseif ($post_id) + } elseif ($post_id) { $args['selected_cats'] = wp_get_post_categories($post_id); - else + } else { $args['selected_cats'] = array(); - - if (is_array($popular_cats)) + } + + if (is_array($popular_cats)) { $args['popular_cats'] = $popular_cats; - else - $args['popular_cats'] = get_terms('category', array('fields'=>'ids', 'orderby'=>'count', 'order'=>'DESC', 'number'=>10, 'hierarchical'=>false)); - + } else { + $args['popular_cats'] = get_terms('category', + array( + 'fields' => 'ids', + 'orderby' => 'count', + 'order' => 'DESC', + 'number' => 10, + 'hierarchical' => false + )); + } + if ($descendants_and_self) { $categories = get_categories("child_of=$descendants_and_self&hierarchical=0&hide_empty=0"); - $self = get_category($descendants_and_self); + $self = get_category($descendants_and_self); array_unshift($categories, $self); } else { $categories = get_categories('get=all'); } - + // 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) $checked_categories = array(); - for ($i = 0; isset($categories[$i]); $i ++) { - if (in_array($categories[$i]->term_id, $args['selected_cats'])) { - $checked_categories[] = $categories[$i]; - unset($categories[$i]); + for ($i = 0; isset($categories[ $i ]); $i ++) { + if (in_array($categories[ $i ]->term_id, $args['selected_cats'])) { + $checked_categories[] = $categories[ $i ]; + unset($categories[ $i ]); } } - + // Put checked cats on top echo call_user_func_array(array(&$walker, 'walk'), array($checked_categories, 0, $args)); // Then the rest of them diff --git a/wp-content/plugins/extended-categories-widget/widget_extended_categories.php b/wp-content/plugins/extended-categories-widget/widget_extended_categories.php index 3ab535b0f248ae968adae02a38e9b2f374a83a9a..8993f87d4564c48da65111a7a8a3a0585da4c4ec 100644 --- a/wp-content/plugins/extended-categories-widget/widget_extended_categories.php +++ b/wp-content/plugins/extended-categories-widget/widget_extended_categories.php @@ -3,71 +3,67 @@ * Plugin Name: AVH Extended Categories Widgets * Plugin URI: http://blog.avirtualhome.com/wordpress-plugins * Description: Replacement of the category widget to allow for greater customization of the category widget. - * Version: 4.0.1 + * Version: 4.0.6 * Author: Peter van der Does * Author URI: http://blog.avirtualhome.com/ - * - * Copyright 2012-2013 Peter van der Does (email : peter@avirtualhome.com) - + * Copyright 2012-2016 Peter van der Does (email : peter@avirtualhome.com) * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -if (!defined('AVH_FRAMEWORK')) { - define('AVH_FRAMEWORK', true); +if ( ! defined('AVH_FRAMEWORK')) { + define('AVH_FRAMEWORK', true); } -require (ABSPATH . WPINC . '/version.php'); +require(ABSPATH . WPINC . '/version.php'); $_avhec_version = (float) $wp_version; if ($_avhec_version >= 2.8) { - $_avhec_abs_dir = dirname(__FILE__); + $_avhec_abs_dir = dirname(__FILE__); - require_once ($_avhec_abs_dir . '/libs/avh-registry.php'); - require_once ($_avhec_abs_dir . '/libs/avh-common.php'); - require_once ($_avhec_abs_dir . '/libs/avh-security.php'); - require_once ($_avhec_abs_dir . '/libs/avh-visitor.php'); - require_once ($_avhec_abs_dir . '/libs/avh-db.php'); + require_once($_avhec_abs_dir . '/libs/avh-registry.php'); + require_once($_avhec_abs_dir . '/libs/avh-common.php'); + require_once($_avhec_abs_dir . '/libs/avh-security.php'); + require_once($_avhec_abs_dir . '/libs/avh-visitor.php'); + require_once($_avhec_abs_dir . '/libs/avh-db.php'); - switch ($_avhec_version) { - case ($_avhec_version >= 4.2): - $_avhec_version_dir = '/4.2'; - break; - case ($_avhec_version >= 3.6): - $_avhec_version_dir = '/3.6'; - break; - case ($_avhec_version >= 3.3): - $_avhec_version_dir = '/3.3'; - break; - case ($_avhec_version >= 2.8): - $_avhec_version_dir = '/2.8'; - break; - } + switch ($_avhec_version) { + case ($_avhec_version >= 4.2): + $_avhec_version_dir = '/4.2'; + break; + case ($_avhec_version >= 3.6): + $_avhec_version_dir = '/3.6'; + break; + case ($_avhec_version >= 3.3): + $_avhec_version_dir = '/3.3'; + break; + case ($_avhec_version >= 2.8): + $_avhec_version_dir = '/2.8'; + break; + } - $_avhec_dir = basename($_avhec_abs_dir); - $_avhec_url = plugins_url() . '/' . $_avhec_dir; + $_avhec_dir = basename($_avhec_abs_dir); + $_avhec_url = plugins_url() . '/' . $_avhec_dir; - define('AVHEC_PLUGIN_DIR', $_avhec_abs_dir); - define('AVHEC_RELATIVE_PLUGIN_DIR', $_avhec_dir); - define('AVHEC_PLUGIN_URL', $_avhec_url . $_avhec_version_dir); - define('AVHEC_ABSOLUTE_WORKING_DIR', AVHEC_PLUGIN_DIR . $_avhec_version_dir); - define('AVHEC_RELATIVE_WORKING_DIR', $_avhec_dir . $_avhec_version_dir); + define('AVHEC_PLUGIN_DIR', $_avhec_abs_dir); + define('AVHEC_RELATIVE_PLUGIN_DIR', $_avhec_dir); + define('AVHEC_PLUGIN_URL', $_avhec_url . $_avhec_version_dir); + define('AVHEC_ABSOLUTE_WORKING_DIR', AVHEC_PLUGIN_DIR . $_avhec_version_dir); + define('AVHEC_RELATIVE_WORKING_DIR', $_avhec_dir . $_avhec_version_dir); - unset($_avhec_version); - unset($_avhec_dir); - unset($_avhec_abs_dir); - unset($_avhec_version_dir); - unset($_avhec_url); - require (AVHEC_ABSOLUTE_WORKING_DIR . '/avh-ec.client.php'); + unset($_avhec_version); + unset($_avhec_dir); + unset($_avhec_abs_dir); + unset($_avhec_version_dir); + unset($_avhec_url); + require(AVHEC_ABSOLUTE_WORKING_DIR . '/avh-ec.client.php'); } else { - require_once 'widget-pre2.8.php'; + require_once 'widget-pre2.8.php'; }