/** * 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; }
/** * 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'); $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 "\t\t\t</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 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(); }