/** * 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; } }
/** * 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 */ 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; }