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