コード例 #1
0
 public function __construct($instance, $args)
 {
     // Check whether we displaying the results of a prevous use (ie. silverghyll_tpicker is set)
     $this->inputs = apply_filters('tpicker_inputs', taxonomy_picker_tpicker_array());
     // Get the configuration options from the database
     $this->options = apply_filters('tpicker_options', get_option('taxonomy-picker-options'));
     if (empty($this->options['empty-terms'])) {
         $this->options['empty-terms'] = 'always';
     }
     // Upgrade defence for new option
     // Upgrade defence for v1.8 - won't be needed long term.  If taxonomies haven't been set, process the instance
     if (empty($instance['taxonomies'])) {
         $instance = taxonomy_picker_taxonomies_array($instance);
     }
     // Pre-process the instance for efficiency
     $this->combo = $instance['combo'];
     // Saved our combobox type
     $set_categories = '';
     //We may set a value
     if (!empty($instance['taxonomies']) and is_array($instance['taxonomies'])) {
         // Protect from nothing chosen
         foreach ($instance['taxonomies'] as $taxonomy_name => $data_item) {
             // Loop through chosen list of taxonomies
             if ($taxonomy_name == 'post_type') {
                 $tax_label = 'Post Type';
             } else {
                 $taxonomy = get_taxonomy($taxonomy_name);
                 // Taxonomy name is dynamic in case it has changed
                 if ($taxonomy_name == 'category' and !empty($instance['category_title'])) {
                     $tax_label = $instance['category_title'];
                 } elseif (is_object($taxonomy)) {
                     $tax_label = $taxonomy->label;
                 } else {
                     // Probably a string (e.g. post_type) so use the information we have
                     $tax_Label = $taxonomy_name;
                 }
             }
             // ==Post Type?
             $tax_label = __($tax_label, 'tpicker') . $this->options['punctuation'];
             $this->taxonomies[$tax_label] = $data_item;
         }
         ksort($this->taxonomies);
         //Put taxonomies into alpha label order
     }
     $this->taxonomies = apply_filters('tpicker_taxonomies', $this->taxonomies);
     // Filter taxonomy order
     if ($args) {
         extract($args);
     }
     // Unpack $before_widget etc
     $this->title = apply_filters('widget_title', $instance['title']);
     if ($this->title) {
         $this->title = $this->before_title . $this->title . $this->after_title;
     }
     // Wrap it
     $this->id = array_key_exists('id', $instance) ? $instance['id'] : 'unset';
     $this->before_widget = apply_filters('tpicker_before', $before_widget ? $before_widget : $this->before_widget);
     $this->after_widget = apply_filters('tpicker_after', $after_widget ? $after_widget : $this->after_widget);
     $this->hidesearch = array_key_exists('hidesearch', $instance) ? true : false;
     // Defaults to show (false)
     $this->date_match = $instance['date_match'];
     // Must be present so just read in
     $this->choose_categories = $instance['choose_categories'];
     $cats = explode(',', $this->set_categories);
     // Limit list of categories
     if ($this->choose_categories == 'I') {
         // Only allow specified categories
         $set_categories = 'cat=' . $instance['set_categories'];
         // We can pass it as is because it will become the list of all categories for query_posts
         $cats = explode(',', $instance['set_categories']);
         // Should be a list of cat IDs
         foreach ($cats as $cat) {
             // Test against each of our permitted categories
             $this->categories[$cat] = get_term_by('ID', $cat, 'category');
             // Add individual categories to the array
         }
     } elseif ($instance['choose_categories'] == 'E') {
         // Reject specified categories
         $set_categories = 'cat=-' . str_replace(',', ',-', $instance['set_categories']);
         // Prefix each cat id with - to exclude it
         $all_cats[] = get_terms('category');
         // Add individual categories to the array
         foreach ($all_cats as $acat) {
             // Test against each of our permitted categories
             $allowed = true;
             foreach ($cats as $cat) {
                 // Test against each of our permitted categories
                 if ($acat->ID == $cat) {
                     $allowed = false;
                     break;
                 }
             }
             if ($allowed) {
                 $this->categories[$cat] = get_term($cat, 'category');
                 // Add individual categories to the array
             }
         }
     }
     // Set default term arguments for get_terms
     switch ($this->options['empty-terms']) {
         // How to handle empty items
         case 'always':
             $this->term_args['hide_empty'] = 0;
             break;
         case 'never':
             $this->term_args['hide_empty'] = 1;
             $this->term_args['hierarchical'] = 1;
             break;
         case 'sometimes':
             $this->term_args['hide_empty'] = 1;
             $this->term_args['hierarchical'] = 1;
     }
     $this->term_args['pad_counts'] = 1;
     // Add options for optional ordering of results
     $this->orderby = $instance['results_orderby'] ? $instance['results_orderby'] : '_default';
     // Default value for people upgrading from earlier widget versions
     $this->order = $instance['results_order'] ? $instance['results_order'] : '_DESC';
     return true;
 }
コード例 #2
0
function tpicker_query_string()
{
    // Check whether we displaying the results of a prevous use (ie. silverghyll_tpicker is set)
    $tpicker_inputs = taxonomy_picker_tpicker_array();
    if (empty($tpicker_inputs)) {
        return "";
    } else {
        foreach ($tpicker_inputs as $key => $data) {
            $taxonomy = get_taxonomy($key == 'tag' ? 'post_tag' : $key);
            $result .= $taxonomy->label . ': ' . $data . '; ';
        }
    }
    return $result;
}