/** * Add the the current Connections directory location/query to the page title. * * NOTE: $id really isn't optional, some plugins fail to use the `the_title` filter correctly, * ie. "Display Posts Shortcode", causes Connections to crash an burn if not supplied. * * @access private * @since 0.7.8 * @static * * @uses cnQuery::getVar() * * @param string $title The browser tab/window title. * @param int $id The page/post ID. * * @return string */ public static function filterPostTitle($title, $id = 0) { global $wp_query, $post; $original = $title; /** * Filter to allow the page title separator to be changed. * * @since 8.5.15 * * @param string $separator The title separator. */ $separator = apply_filters('cn_page_title_separator', '»'); // Whether or not to filter the page title with the current directory location. if (!cnSettingsAPI::get('connections', 'seo', 'page_title')) { return $title; } if (!is_object($post) || (!isset($wp_query->post) || !isset($wp_query->post->ID) || $wp_query->post->ID != $id) || !self::$filterPermalink) { return $title; } $pieces = array($title); if (cnQuery::getVar('cn-cat-slug')) { // If the category slug is a descendant, use the last slug from the URL for the query. $categorySlug = explode('/', cnQuery::getVar('cn-cat-slug')); if (isset($categorySlug[count($categorySlug) - 1])) { $categorySlug = $categorySlug[count($categorySlug) - 1]; } $term = cnTerm::getBy('slug', $categorySlug, 'category'); $category = new cnCategory($term); $pieces = array_merge(array('term-category-name' => $category->getName()), $pieces); } if (cnQuery::getVar('cn-cat')) { if (is_array(cnQuery::getVar('cn-cat'))) { return implode('', $pieces); } $categoryID = cnQuery::getVar('cn-cat'); $term = cnTerm::getBy('id', $categoryID, 'category'); $category = new cnCategory($term); $pieces = array_merge(array('term-category-name' => $category->getName()), $pieces); } if (cnQuery::getVar('cn-country')) { $pieces = array_merge(array('country' => urldecode(cnQuery::getVar('cn-country'))), $pieces); } if (cnQuery::getVar('cn-postal-code')) { $pieces = array_merge(array('postal-code' => urldecode(cnQuery::getVar('cn-postal-code'))), $pieces); } if (cnQuery::getVar('cn-region')) { $pieces = array_merge(array('region' => urldecode(cnQuery::getVar('cn-region'))), $pieces); } if (cnQuery::getVar('cn-locality')) { $pieces = array_merge(array('locality' => urldecode(cnQuery::getVar('cn-locality'))), $pieces); } if (cnQuery::getVar('cn-organization')) { $pieces = array_merge(array('organization' => urldecode(cnQuery::getVar('cn-organization'))), $pieces); } if (cnQuery::getVar('cn-department')) { $pieces = array_merge(array('department' => urldecode(cnQuery::getVar('cn-department'))), $pieces); } if (cnQuery::getVar('cn-entry-slug')) { // Grab an instance of the Connections object. $instance = Connections_Directory(); $result = $instance->retrieve->entries(array('slug' => urldecode(cnQuery::getVar('cn-entry-slug')))); // Make sure an entry is returned and if not, return $title unaltered. if (empty($result)) { return apply_filters('cn_page_title', implode(" {$separator} ", $pieces), $pieces, $separator, $original, $id); } $entry = new cnEntry($result[0]); $pieces = array_merge(array('name' => $entry->getName()), $pieces); } /** * Filter the parts of the page title. * * @since 8.5.15 * * @param string $title The page title. * @param array $pieces The pieces of the title. * @param string $separator The title separator. * @param string $original The original title. May have been altered by other filters hooked into the `the_title` filter. * @param int $id The post ID. */ $title = apply_filters('cn_page_title', implode(" {$separator} ", $pieces), $pieces, $separator, $original, $id); return $title; }
function connectionsShowCategoriesPage() { /* * Check whether user can edit categories. */ if (!current_user_can('connections_edit_categories')) { wp_die('<p id="error-page" style="-moz-background-clip:border; -moz-border-radius:11px; background:#FFFFFF none repeat scroll 0 0; border:1px solid #DFDFDF; color:#333333; display:block; font-size:12px; line-height:18px; margin:25px auto 20px; padding:1em 2em; text-align:center; width:700px">' . __('You do not have sufficient permissions to access this page.', 'connections') . '</p>'); } else { // Grab an instance of the Connections object. $instance = Connections_Directory(); $form = new cnFormObjects(); $taxonomy = 'category'; $action = ''; if (isset($_GET['cn-action'])) { $action = $_GET['cn-action']; } if ($action === 'edit_category') { $id = absint($_GET['id']); check_admin_referer('category_edit_' . $id); $term = $instance->retrieve->category($id); $category = new cnCategory($term); /** * Fires before the Edit Term form for all taxonomies. * * The dynamic portion of the hook name, `$taxonomy`, refers to * the taxonomy slug. * * @since 3.0.0 * * @param object $tag Current taxonomy term object. * @param string $taxonomy Current $taxonomy slug. */ do_action("cn_{$taxonomy}_pre_edit_form", $term, $taxonomy); ?> <div class="wrap"> <div class="form-wrap" style="width:600px; margin: 0 auto;"> <h2><a name="new"></a><?php _e('Edit Category', 'connections'); ?> </h2> <?php $attr = array('action' => '', 'method' => 'post', 'id' => 'addcat', 'name' => 'updatecategory'); $form->open($attr); $form->tokenField('update_category'); /** * Fires inside the Edit Term form tag. * * The dynamic portion of the hook name, `$taxonomy`, refers to * the taxonomy slug. * * @since 3.7.0 */ do_action("cn_{$taxonomy}_term_edit_form_tag"); ?> <div class="form-field form-required term-name-wrap"> <label for="category_name"><?php _e('Name', 'connections'); ?> </label> <input type="text" aria-required="true" size="40" value="<?php echo esc_attr($category->getName()); ?> " id="category_name" name="category_name"/> <input type="hidden" value="<?php echo esc_attr($category->getID()); ?> " id="category_id" name="category_id"/> <p><?php _e('The name is how it appears on your site.', 'connections'); ?> </p> </div> <div class="form-field term-slug-wrap"> <label for="category_slug"><?php _e('Slug', 'connections'); ?> </label> <input type="text" size="40" value="<?php echo esc_attr($category->getSlug()); ?> " id="category_slug" name="category_slug"/> <p><?php _e('The “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.', 'connections'); ?> </p> </div> <div class="form-field term-parent-wrap"> <label for="category_parent"><?php _e('Parent', 'connections'); ?> </label> <?php cnTemplatePart::walker('term-select', array('hide_empty' => 0, 'hide_if_empty' => FALSE, 'name' => 'category_parent', 'orderby' => 'name', 'taxonomy' => 'category', 'selected' => $category->getParent(), 'exclude_tree' => $category->getID(), 'hierarchical' => TRUE, 'show_option_none' => __('None', 'connections'))); ?> <p><?php _e('Categories can have a hierarchy. You might have a Jazz category, and under that have children categories for Bebop and Big Band. Totally optional.', 'connections'); ?> </p> </div> <div class="form-field term-description-wrap"> <?php ob_start(); /* * Now we're going to have to keep track of which TinyMCE plugins * WP core supports based on version, sigh. */ if (version_compare($GLOBALS['wp_version'], '3.8.999', '<')) { $tinymcePlugins = array('inlinepopups', 'tabfocus', 'paste', 'wordpress', 'wplink', 'wpdialogs'); } else { $tinymcePlugins = array('tabfocus', 'paste', 'wordpress', 'wplink', 'wpdialogs'); } wp_editor(wp_kses_post($category->getDescription()), 'category_description', array('media_buttons' => FALSE, 'tinymce' => array('editor_selector' => 'tinymce', 'toolbar1' => 'bold, italic, underline, |, bullist, numlist, |, justifyleft, justifycenter, justifyright, alignleft, aligncenter, alignright, |, link, unlink, |, pastetext, pasteword, removeformat, |, undo, redo', 'toolbar2' => '', 'inline_styles' => TRUE, 'relative_urls' => FALSE, 'remove_linebreaks' => FALSE, 'plugins' => implode(',', $tinymcePlugins)))); echo ob_get_clean(); ?> </div> <?php /** * Fires after the Edit Term form fields are displayed. * * The dynamic portion of the hook name, `$taxonomy`, refers to * the taxonomy slug. * * @since 3.0.0 * * @param object $tag Current taxonomy term object. * @param string $taxonomy Current taxonomy slug. */ do_action("cn_{$taxonomy}_edit_form_fields", $term, $taxonomy); /** * Fires at the end of the Edit Term form for all taxonomies. * * The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug. * * @since 3.0.0 * * @param object $tag Current taxonomy term object. * @param string $taxonomy Current taxonomy slug. */ do_action("{$taxonomy}_edit_form", $term, $taxonomy); ?> <input type="hidden" name="cn-action" value="update_category"/> <p class="submit"> <a class="button button-warning" href="admin.php?page=connections_categories"><?php _e('Cancel', 'connections'); ?> </a> <input type="submit" name="update" id="update" class="button button-primary" value="<?php _e('Update Category', 'connections'); ?> "/> </p> <?php $form->close(); ?> </div> </div> <?php } else { /** * @var CN_Terms_List_Table $table */ $table = cnTemplatePart::table('term-admin', array('screen' => get_current_screen()->id)); $table->prepare_items(); ?> <div class="wrap nosubsub"> <h2>Connections : <?php _e('Categories', 'connections'); ?> </h2> <form class="search-form" action="" method="get"> <input type="hidden" name="page" value="<?php echo esc_attr($_REQUEST['page']); ?> "/> <?php $table->search_box(__('Search Categories', 'connections'), 'category'); ?> </form> <br class="clear"/> <div id="col-container"> <div id="col-right"> <div class="col-wrap"> <?php $attr = array('action' => '', 'method' => 'post'); $form->open($attr); //$form->tokenField( 'bulk_delete_category' ); ?> <input type="hidden" name="cn-action" value="category_bulk_actions"/> <?php $table->display(); $form->close(); ?> <br class="clear" /> <script type="text/javascript"> /* <![CDATA[ */ (function ($) { $(document).ready(function () { $('#doaction, #doaction2').click(function () { if ($('select[name^="action"]').val() == 'delete') { var m = 'You are about to delete the selected category(ies).\n \'Cancel\' to stop, \'OK\' to delete.'; return showNotice.warn(m); } }); }); })(jQuery); /* ]]> */ </script> <div class="form-wrap"> <p><?php _e('<strong>Note:</strong><br/>Deleting a category which has been assigned to an entry will reassign that entry as <strong>Uncategorized</strong>.', 'connections'); ?> </p> </div> <?php /** * Fires after the taxonomy list table. * * The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug. * * @since 3.0.0 * * @param string $taxonomy The taxonomy name. */ do_action("cn_after-{$taxonomy}-table", $taxonomy); ?> </div> </div> <!-- right column --> <div id="col-left"> <div class="col-wrap"> <?php /** * Fires before the Add Term form for all taxonomies. * * The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug. * * @since 3.0.0 * * @param string $taxonomy The taxonomy slug. */ do_action("cn_{$taxonomy}_pre_add_form", $taxonomy); ?> <div class="form-wrap"> <h3><?php _e('Add New Category', 'connections'); ?> </h3> <?php $attr = array('action' => '', 'method' => 'post'); $form->open($attr); $form->tokenField('add_category'); /** * Fires at the beginning of the Add Tag form. * * The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug. * * @since 3.7.0 */ do_action("cn_{$taxonomy}_term_new_form_tag"); ?> <div class="form-field form-required term-name-wrap"> <label for="category_name"><?php _e('Name', 'connections'); ?> </label> <input type="text" aria-required="true" size="40" value="" id="category_name" name="category_name"/> <input type="hidden" value="" id="category_id" name="category_id"/> <p><?php _e('The name is how it appears on your site.', 'connections'); ?> </p> </div> <div class="form-field term-slug-wrap"> <label for="category_slug"><?php _e('Slug', 'connections'); ?> </label> <input type="text" size="40" value="" id="category_slug" name="category_slug"/> <p><?php _e('The “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.', 'connections'); ?> </p> </div> <div class="form-field term-parent-wrap"> <label for="category_parent"><?php _e('Parent', 'connections'); ?> </label> <?php $dropdown_args = array('hide_empty' => 0, 'hide_if_empty' => FALSE, 'taxonomy' => 'category', 'name' => 'category_parent', 'orderby' => 'name', 'hierarchical' => TRUE, 'show_option_none' => __('None', 'connections')); /** * Filter the taxonomy parent drop-down on the Edit Term page. * * @since 3.7.0 * * @param array $dropdown_args { * An array of taxonomy parent drop-down arguments. * * @type int|bool $hide_empty Whether to hide terms not attached to any posts. Default 0|false. * @type bool $hide_if_empty Whether to hide the drop-down if no terms exist. Default false. * @type string $taxonomy The taxonomy slug. * @type string $name Value of the name attribute to use for the drop-down select element. * Default 'parent'. * @type string $orderby The field to order by. Default 'name'. * @type bool $hierarchical Whether the taxonomy is hierarchical. Default true. * @type string $show_option_none Label to display if there are no terms. Default 'None'. * } * * @param string $taxonomy The taxonomy slug. */ $dropdown_args = apply_filters('cn_taxonomy_parent_dropdown_args', $dropdown_args, 'category'); cnTemplatePart::walker('term-select', $dropdown_args); ?> <p><?php _e('Categories can have a hierarchy. You might have a Jazz category, and under that have children categories for Bebop and Big Band. Totally optional.', 'connections'); ?> </p> </div> <div class="form-field term-description-wrap"> <?php ob_start(); /* * Now we're going to have to keep track of which TinyMCE plugins * WP core supports based on version, sigh. */ if (version_compare($GLOBALS['wp_version'], '3.8.999', '<')) { $tinymcePlugins = array('inlinepopups', 'tabfocus', 'paste', 'wordpress', 'wplink', 'wpdialogs'); } else { $tinymcePlugins = array('tabfocus', 'paste', 'wordpress', 'wplink', 'wpdialogs'); } wp_editor('', 'category_description', array('media_buttons' => FALSE, 'tinymce' => array('editor_selector' => 'tinymce', 'toolbar1' => 'bold, italic, underline, |, bullist, numlist, |, justifyleft, justifycenter, justifyright, alignleft, aligncenter, alignright, |, link, unlink, |, pastetext, pasteword, removeformat, |, undo, redo', 'toolbar2' => '', 'inline_styles' => TRUE, 'relative_urls' => FALSE, 'remove_linebreaks' => FALSE, 'plugins' => implode(',', $tinymcePlugins)))); echo ob_get_clean(); ?> </div> <input type="hidden" name="cn-action" value="add_category"/> <?php /** * Fires after the Add Term form fields for hierarchical taxonomies. * * The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug. * * @since 3.0.0 * * @param string $taxonomy The taxonomy slug. */ do_action("cn_{$taxonomy}_add_form_fields", $taxonomy); submit_button(__('Add New Category', 'connections'), 'primary', 'add'); /** * Fires at the end of the Add Term form for all taxonomies. * * The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug. * * @since 3.0.0 * * @param string $taxonomy The taxonomy slug. */ do_action("cn_{$taxonomy}_add_form", $taxonomy); ?> <?php $form->close(); ?> </div> </div> </div> <!-- left column --> </div> <!-- Column container --> </div> <?php } } }
public function showForm($data = NULL) { global $connections; $form = new cnFormObjects(); $category = new cnCategory($data); $parent = new cnCategory($connections->retrieve->category($category->getParent())); $level = NULL; $out = '<div class="form-field form-required connectionsform">'; $out .= '<label for="cat_name">Category Name</label>'; $out .= '<input type="text" aria-required="true" size="40" value="' . $category->getName() . '" id="category_name" name="category_name"/>'; $out .= '<input type="hidden" value="' . $category->getID() . '" id="category_id" name="category_id"/>'; $out .= '</div>'; $out .= '<div class="form-field connectionsform">'; $out .= '<label for="category_nicename">Category Slug</label>'; $out .= '<input type="text" size="40" value="' . $category->getSlug() . '" id="category_slug" name="category_slug"/>'; $out .= '</div>'; $out .= '<div class="form-field connectionsform">'; $out .= '<label for="category_parent">Category Parent</label>'; $out .= '<select class="postform" id="category_parent" name="category_parent">'; $out .= '<option value="0">None</option>'; $out .= $this->buildCategoryRow('option', $connections->retrieve->categories(), $level, $parent->getID()); $out .= '</select>'; $out .= '</div>'; $out .= '<div class="form-field connectionsform">'; $out .= '<label for="category_description">Description</label>'; $out .= '<textarea cols="40" rows="5" id="category_description" name="category_description">' . $category->getDescription() . '</textarea>'; $out .= '</div>'; echo $out; }
/** * Add the the current Connections directory location/query to the page title. * * NOTE: $id really isn't optional, some plugins fail to use the `the_title` filter correctly, * ie. "Display Posts Shortcode", causes Connections to crash an burn if not supplied. * * @access private * @since 0.7.8 * @static * * @uses get_query_var() * * @param string $title The browser tab/window title. * @param int $id The page/post ID. * * @return string */ public static function filterPostTitle($title, $id = 0) { global $wp_query, $post; // Whether or not to filter the page title with the current directory location. if (!cnSettingsAPI::get('connections', 'seo', 'page_title')) { return $title; } if (!is_object($post) || (!isset($wp_query->post) || !isset($wp_query->post->ID) || $wp_query->post->ID != $id) || !self::$filterPermalink) { return $title; } // Coerce $title to be an array. $title = (array) $title; if (get_query_var('cn-cat-slug')) { // If the category slug is a descendant, use the last slug from the URL for the query. $categorySlug = explode('/', get_query_var('cn-cat-slug')); if (isset($categorySlug[count($categorySlug) - 1])) { $categorySlug = $categorySlug[count($categorySlug) - 1]; } $term = cnTerm::getBy('slug', $categorySlug, 'category'); $category = new cnCategory($term); array_unshift($title, $category->getName()); } if (get_query_var('cn-cat')) { if (is_array(get_query_var('cn-cat'))) { return implode('', $title); } $categoryID = get_query_var('cn-cat'); $term = cnTerm::getBy('id', $categoryID, 'category'); $category = new cnCategory($term); array_unshift($title, $category->getName()); } if (get_query_var('cn-country')) { array_unshift($title, urldecode(get_query_var('cn-country'))); } if (get_query_var('cn-postal-code')) { array_unshift($title, urldecode(get_query_var('cn-postal-code'))); } if (get_query_var('cn-region')) { array_unshift($title, urldecode(get_query_var('cn-region'))); } if (get_query_var('cn-locality')) { array_unshift($title, urldecode(get_query_var('cn-locality'))); } if (get_query_var('cn-organization')) { array_unshift($title, urldecode(get_query_var('cn-organization'))); } if (get_query_var('cn-department')) { array_unshift($title, urldecode(get_query_var('cn-department'))); } if (get_query_var('cn-entry-slug')) { // Grab an instance of the Connections object. $instance = Connections_Directory(); $result = $instance->retrieve->entries(array('slug' => urldecode(get_query_var('cn-entry-slug')))); // Make sure an entry is returned and if not, return $title unaltered. if (empty($result)) { return implode(' » ', $title); } $entry = new cnEntry($result[0]); array_unshift($title, $entry->getName()); } return implode(' » ', $title); }