Example #1
0
 /**
  * Ajax Helper: inline delete of the groups
  */
 function ajaxDeleteGroup()
 {
     $group_id = isset($_POST['id']) ? (int) $_POST['id'] : 0;
     check_ajax_referer('delete-avhecgroup_' . $group_id);
     if (!current_user_can('manage_categories')) {
         die('-1');
     }
     $check = $this->catgrp->getGroup($group_id);
     if (false === $check) {
         die('1');
     }
     if ($this->catgrp->doDeleteGroup($group_id)) {
         die('1');
     } else {
         die('0');
     }
 }
 /**
  * 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&#8217; 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();
 }