Commit 186bd80f authored by lechuck's avatar lechuck Committed by lechuck

Upgrade Extended Categories to 3.6.4

parent 38030ac2
......@@ -58,7 +58,7 @@ function avhextendedcategories_init ()
$avhec_admin = new AVH_EC_Admin();
}
AVH_EC_Singleton::getInstance('AVH_EC_Core');
add_action('widgets_init', 'avhextendedcategories_widgets_init');
} // End avhamazon_init()
......
......@@ -4,7 +4,6 @@
* AVH Extended Categorie Category Group Class
*
* @author Peter van der Does
* @copyright 2010
*/
class AVH_EC_Category_Group
{
......@@ -13,11 +12,11 @@ class AVH_EC_Category_Group
* @var string
*/
var $taxonomy_name;
var $db_options_widget_titles;
var $options_widget_titles;
var $widget_done_catgroup;
/**
......@@ -37,19 +36,19 @@ class AVH_EC_Category_Group
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.
*
......@@ -59,9 +58,9 @@ class AVH_EC_Category_Group
}
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'));
}
/**
......@@ -82,19 +81,19 @@ class AVH_EC_Category_Group
function doCreateTable ()
{
global $wpdb;
// Setup the DB Tables
$charset_collate = '';
if (version_compare(mysql_get_server_info(), '4.1.0', '>=')) {
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);
}
......@@ -112,7 +111,7 @@ class AVH_EC_Category_Group
$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));
}
/**
......@@ -128,13 +127,13 @@ class AVH_EC_Category_Group
$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);
$this->setWidgetTitleForGroup($all_group_id['term_id'], '');
$this->setWidgetTitleForGroup($home_group_id['term_id'], '');
}
$options = get_option($this->db_options_widget_titles);
if (! $options) {
$options = array();
......@@ -186,10 +185,10 @@ class AVH_EC_Category_Group
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();
......@@ -215,9 +214,9 @@ class AVH_EC_Category_Group
function setCategoriesForGroup ($group_id, $categories = array())
{
global $wpdb;
$old_categories = $this->getCategoriesFromGroup($group_id);
if (! is_array($categories)) {
$categories = array();
}
......@@ -228,10 +227,10 @@ class AVH_EC_Category_Group
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 . ')';
......@@ -239,16 +238,16 @@ class AVH_EC_Category_Group
$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;
}
......@@ -316,7 +315,7 @@ class AVH_EC_Category_Group
function getGroup ($group_id)
{
global $wpdb;
$result = get_term((int) $group_id, $this->taxonomy_name);
if (null === $result) {
$result = false;
......@@ -327,7 +326,7 @@ class AVH_EC_Category_Group
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)) {
......@@ -357,14 +356,14 @@ class AVH_EC_Category_Group
*/
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);
}
......@@ -379,7 +378,7 @@ class AVH_EC_Category_Group
*/
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);
......
......@@ -10,9 +10,9 @@ class AVH_EC_Core
var $default_options_general;
var $default_options_category_group;
var $default_options_sp_category_group;
var $db_options_tax_meta;
var $options;
/**
......@@ -26,13 +26,13 @@ class AVH_EC_Core
* @var AVH_EC_Category_Group
*/
$catgrp = & AVH_EC_Singleton::getInstance('AVH_EC_Category_Group');
$this->version = '3.4.2';
$this->version = '3.6.4';
$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);
add_action('init', array ( &$this, 'handleInitializePlugin' ), 10);
}
/**
......@@ -47,43 +47,66 @@ class AVH_EC_Core
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['lang_dir'] = AVHEC_RELATIVE_WORKING_DIR . '/lang';
$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'], 'lang_dir'=>$info['lang_dir'], 'graphics_url'=>$info['graphics_url']);
$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'=>'');
$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);
$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);
}
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;
}
/**
......@@ -93,9 +116,9 @@ class AVH_EC_Core
*/
function handleTextdomain ()
{
load_plugin_textdomain('avh-ec', false, $this->info['lang_dir']);
load_plugin_textdomain('avh-ec', false, AVHEC_RELATIVE_PLUGIN_DIR . '/lang');
}
/**
......@@ -107,7 +130,7 @@ class AVH_EC_Core
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)) {
......@@ -120,7 +143,19 @@ class AVH_EC_Core
}
}
}
// 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
*/
......@@ -172,7 +207,7 @@ class AVH_EC_Core
{
//place each directory into array and get the last element
$return = end(explode('/', $directory));
return $return;
}
......@@ -181,7 +216,7 @@ class AVH_EC_Core
* Methods for variable: options *
* *
********************************/
/**
* @param array $data
*/
......@@ -288,44 +323,44 @@ class AVH_EC_Core
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']) {
$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_categories($r);
$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 ($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 {
......@@ -334,12 +369,12 @@ class AVH_EC_Core
$output .= walk_category_dropdown_tree($categories, $depth, $r);
$output .= "</select>\n";
}
$output = apply_filters('wp_dropdown_cats', $output);
if ($echo)
echo $output;
return $output;
}
......@@ -379,35 +414,35 @@ class AVH_EC_Core
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);
$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>';
......@@ -415,30 +450,30 @@ class AVH_EC_Core
$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
......@@ -476,53 +511,53 @@ class AVH_Walker_CategoryDropdown extends Walker_CategoryDropdown
function walk ($elements, $max_depth)
{
$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'];
$parent_field = $this->db_fields['parent'];
// flat display
if (- 1 == $max_depth) {
$empty_array = array();