Esempio n. 1
0
 /**
  * Menu Page General Options
  *
  * @return none
  */
 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 "\t\t\t</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();
 }
Esempio n. 2
0
 /**
  * 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;
     }
 }
 /** 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;
 }