/** * Content of custom meta box of Simple Tags * * @param object $post * @return void * @author Amaury Balmer */ public static function metabox($post) { // Get options $autocomplete_min = (int) SimpleTags_Plugin::get_option_value('autocomplete_min'); ?> <p> <?php if (SimpleTags_Plugin::get_option_value('autocomplete_type') == 'textarea') { ?> <textarea class="widefat" name="adv-tags-input" id="adv-tags-input" rows="3" cols="5"><?php echo SimpleTags_Admin::getTermsToEdit('post_tag', $post->ID); ?> </textarea> <?php } else { ?> <input type="text" class="widefat" name="adv-tags-input" id="adv-tags-input" value="<?php echo esc_attr(SimpleTags_Admin::getTermsToEdit('post_tag', $post->ID)); ?> " /> <?php } ?> <?php _e('Separate tags with commas', 'simpletags'); ?> </p> <script type="text/javascript"> <!-- st_init_autocomplete( '#adv-tags-input', '<?php echo admin_url("admin-ajax.php?action=simpletags&st_action=helper_js_collection"); ?> ', <?php echo $autocomplete_min; ?> ); --> </script> <?php }
/** * WP Page - Mass edit tags * */ public static function pageMassEditTags() { global $wpdb, $wp_locale, $wp_query; list($post_stati, $avail_post_stati) = self::edit_data_query(); if (!isset($_GET['paged'])) { $_GET['paged'] = 1; } // Display message settings_errors(__CLASS__); ?> <div class="wrap"> <?php SimpleTags_Admin::boxSelectorTaxonomy('st_mass_terms'); ?> <form id="posts-filter" action="" method="get"> <input type="hidden" name="page" value="st_mass_terms" /> <input type="hidden" name="taxo" value="<?php echo esc_attr(SimpleTags_Admin::$taxonomy); ?> " /> <input type="hidden" name="cpt" value="<?php echo esc_attr(SimpleTags_Admin::$post_type); ?> " /> <h2><?php _e('Mass edit terms', 'simpletags'); ?> </h2> <ul class="subsubsub"> <?php $status_links = array(); $num_posts = wp_count_posts(SimpleTags_Admin::$post_type, 'readable'); $class = empty($_GET['post_status']) && empty($_GET['post_type']) ? ' class="current"' : ''; $status_links[] = '<li><a href="' . admin_url('tools.php') . '?page=st_mass_terms&cpt=' . SimpleTags_Admin::$post_type . '&taxo=' . SimpleTags_Admin::$taxonomy . '"' . $class . '>' . __('All', 'simpletags') . '</a>'; foreach ($post_stati as $status => $label) { $class = ''; if (!in_array($status, $avail_post_stati)) { continue; } if (empty($num_posts->{$status})) { continue; } if (isset($_GET['post_status']) && $status == $_GET['post_status']) { $class = ' class="current"'; } $status_links[] = '<li><a href="' . admin_url('tools.php') . '?page=st_mass_terms&cpt=' . SimpleTags_Admin::$post_type . '&taxo=' . SimpleTags_Admin::$taxonomy . '&post_status=' . $status . '"' . $class . '>' . sprintf(_n($label[2][0], $label[2][1], (int) $num_posts->{$status}), number_format_i18n($num_posts->{$status})) . '</a>'; } echo implode(' |</li>', $status_links) . '</li>'; unset($status_links); $class = !empty($_GET['post_type']) ? ' class="current"' : ''; ?> </ul> <?php if (isset($_GET['post_status'])) { ?> <input type="hidden" name="post_status" value="<?php echo esc_attr($_GET['post_status']); ?> " /> <?php } ?> <p class="search-box"> <input type="text" id="post-search-input" name="s" value="<?php the_search_query(); ?> " /> <input type="submit" value="<?php _e('Search', 'simpletags'); ?> " class="button" /> </p> <div class="tablenav"> <?php $posts_per_page = isset($_GET['posts_per_page']) ? (int) $_GET['posts_per_page'] : 0; if ((int) $posts_per_page == 0) { $posts_per_page = 15; } $page_links = paginate_links(array('base' => add_query_arg('paged', '%#%'), 'format' => '', 'total' => ceil($wp_query->found_posts / $posts_per_page), 'current' => (int) $_GET['paged'])); if ($page_links) { echo "<div class='tablenav-pages'>{$page_links}</div>"; } ?> <div style="float: left"> <?php if (!is_singular()) { $arc_result = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM {$wpdb->posts} WHERE post_type = %s ORDER BY post_date DESC", SimpleTags_Admin::$post_type)); $month_count = count($arc_result); if (!isset($_GET['m'])) { $_GET['m'] = ''; } if ($month_count && !(1 == $month_count && 0 == $arc_result[0]->mmonth)) { ?> <select name='m'> <option<?php selected(@$_GET['m'], 0); ?> value='0'><?php _e('Show all dates', 'simpletags'); ?> </option> <?php foreach ($arc_result as $arc_row) { if ($arc_row->yyear == 0) { continue; } $arc_row->mmonth = zeroise($arc_row->mmonth, 2); if ($arc_row->yyear . $arc_row->mmonth == $_GET['m']) { $default = ' selected="selected"'; } else { $default = ''; } echo "<option{$default} value='{$arc_row->yyear}{$arc_row->mmonth}'>"; echo $wp_locale->get_month($arc_row->mmonth) . " {$arc_row->yyear}"; echo "</option>\n"; } ?> </select> <?php } ?> <select name="posts_per_page" id="posts_per_page"> <option <?php if (!isset($_GET['posts_per_page'])) { echo 'selected="selected"'; } ?> value=""><?php _e('Quantity…', 'simpletags'); ?> </option> <option <?php selected($posts_per_page, 10); ?> value="10">10</option> <option <?php selected($posts_per_page, 20); ?> value="20">20</option> <option <?php selected($posts_per_page, 30); ?> value="30">30</option> <option <?php selected($posts_per_page, 40); ?> value="40">40</option> <option <?php selected($posts_per_page, 50); ?> value="50">50</option> <option <?php selected($posts_per_page, 100); ?> value="100">100</option> <option <?php selected($posts_per_page, 200); ?> value="200">200</option> </select> <input type="submit" id="post-query-submit" value="<?php _e('Filter', 'simpletags'); ?> " class="button-secondary" /> <?php } ?> </div> <br style="clear:both;" /> </div> </form> <br style="clear:both;" /> <?php if (have_posts()) { add_filter('the_title', 'esc_html'); ?> <form name="post" id="post" method="post"> <table class="widefat post fixed"> <thead> <tr> <th class="manage-column"><?php _e('Post title', 'simpletags'); ?> </th> <th class="manage-column"><?php printf(__('Terms : %s', 'simpletags'), esc_html(SimpleTags_Admin::$taxo_name)); ?> </th> </tr> </thead> <tbody> <?php $class = 'alternate'; while (have_posts()) { the_post(); $class = $class == 'alternate' ? '' : 'alternate'; ?> <tr valign="top" class="<?php echo $class; ?> "> <th scope="row"><a href="<?php echo admin_url('post.php?action=edit&post=' . get_the_ID()); ?> " title="<?php _e('Edit', 'simpletags'); ?> "><?php echo get_the_title() == '' ? the_ID() : the_title(); ?> </a></th> <td><input id="tags-input<?php the_ID(); ?> " class="autocomplete-input tags_input" type="text" size="100" name="tags[<?php the_ID(); ?> ]" value="<?php echo SimpleTags_Admin::getTermsToEdit(SimpleTags_Admin::$taxonomy, get_the_ID()); ?> " /></td> </tr> <?php } ?> </tbody> </table> <p class="submit"> <input type="hidden" name="secure_mass" value="<?php echo wp_create_nonce('st_mass_terms'); ?> " /> <input class="button-primary" type="submit" name="update_mass" value="<?php _e('Update all »', 'simpletags'); ?> " /> </p> </form> <?php } else { ?> <p><?php _e('No content to edit.', 'simpletags'); ?> <?php } ?> <p><?php _e('Visit the <a href="https://github.com/herewithme/simple-tags">plugin\'s homepage</a> for further details. If you find a bug, or have a fantastic idea for this plugin, <a href="mailto:amaury@wordpress-fr.net">ask me</a> !', 'simpletags'); ?> </p> <?php SimpleTags_Admin::printAdminFooter(); ?> </div> <?php do_action('simpletags-mass_terms', SimpleTags_Admin::$taxonomy); }
/** * Method for build the page HTML manage tags * * @return void * @author Amaury Balmer */ public static function page_manage_tags() { // Control Post data if (isset($_POST['term_action'])) { if (!wp_verify_nonce($_POST['term_nonce'], 'simpletags_admin')) { // Origination and intention add_settings_error(__CLASS__, __CLASS__, __('Security problem. Try again. If this problem persist, contact <a href="mailto:amaury@wordpress-fr.net">plugin author</a>.', 'simpletags'), 'error'); } elseif (!isset(SimpleTags_Admin::$taxonomy) || !taxonomy_exists(SimpleTags_Admin::$taxonomy)) { // Valid taxo ? add_settings_error(__CLASS__, __CLASS__, __('Missing valid taxonomy for work... Try again. If this problem persist, contact <a href="mailto:amaury@wordpress-fr.net">plugin author</a>.', 'simpletags'), 'error'); } elseif ($_POST['term_action'] == 'renameterm') { $oldtag = isset($_POST['renameterm_old']) ? $_POST['renameterm_old'] : ''; $newtag = isset($_POST['renameterm_new']) ? $_POST['renameterm_new'] : ''; self::renameTerms(SimpleTags_Admin::$taxonomy, $oldtag, $newtag); } elseif ($_POST['term_action'] == 'deleteterm') { $todelete = isset($_POST['deleteterm_name']) ? $_POST['deleteterm_name'] : ''; self::deleteTermsByTermList(SimpleTags_Admin::$taxonomy, $todelete); } elseif ($_POST['term_action'] == 'addterm') { $matchtag = isset($_POST['addterm_match']) ? $_POST['addterm_match'] : ''; $newtag = isset($_POST['addterm_new']) ? $_POST['addterm_new'] : ''; self::addMatchTerms(SimpleTags_Admin::$taxonomy, $matchtag, $newtag); } elseif ($_POST['term_action'] == 'remove-rarelyterms') { self::removeRarelyUsed(SimpleTags_Admin::$taxonomy, (int) $_POST['number-rarely']); } /* elseif ( $_POST['term_action'] == 'editslug' ) { $matchtag = (isset($_POST['tagname_match'])) ? $_POST['tagname_match'] : ''; $newslug = (isset($_POST['tagslug_new'])) ? $_POST['tagslug_new'] : ''; self::editTermSlug( SimpleTags_Admin::$taxonomy, $matchtag, $newslug ); }*/ } // Default order if (!isset($_GET['order'])) { $_GET['order'] = 'name-asc'; } settings_errors(__CLASS__); ?> <div class="wrap st_wrap"> <?php SimpleTags_Admin::boxSelectorTaxonomy('st_manage'); ?> <h2><?php _e('Simple Tags: Manage Terms', 'simpletags'); ?> </h2> <p><?php _e('Visit the <a href="https://github.com/herewithme/simple-tags">plugin\'s homepage</a> for further details. If you find a bug, or have a fantastic idea for this plugin, <a href="mailto:amaury@wordpress-fr.net">ask me</a> !', 'simpletags'); ?> </p> <div class="clear"></div> <div id="term-list"> <h3><?php _e('Click terms list:', 'simpletags'); ?> </h3> <form action="" method="get"> <div> <input type="hidden" name="page" value="st_manage"/> <input type="hidden" name="taxo" value="<?php echo esc_attr(SimpleTags_Admin::$taxonomy); ?> "/> <input type="hidden" name="cpt" value="<?php echo esc_attr(SimpleTags_Admin::$post_type); ?> "/> <select name="order"> <option <?php selected($_GET['order'], 'count-asc'); ?> value="count-asc"><?php _e('Least used', 'simpletags'); ?> </option> <option <?php selected($_GET['order'], 'count-desc'); ?> value="count-desc"><?php _e('Most popular', 'simpletags'); ?> </option> <option <?php selected($_GET['order'], 'name-asc'); ?> value="name-asc"><?php _e('Alphabetical (default)', 'simpletags'); ?> </option> <option <?php selected($_GET['order'], 'name-desc'); ?> value="name-desc"><?php _e('Inverse Alphabetical', 'simpletags'); ?> </option> <option <?php selected($_GET['order'], 'random'); ?> value="random"><?php _e('Random', 'simpletags'); ?> </option> </select> <input class="button" type="submit" value="<?php _e('Sort', 'simpletags'); ?> "/> </div> </form> <div id="term-list-inner"> <?php if (isset($_GET['order'])) { $order = explode('-', stripslashes($_GET['order'])); if (!isset($order[1])) { $order[1] = ''; } // for skip notice on random... $order = '&selectionby=' . $order[0] . '&selection=' . $order[1] . '&orderby=' . $order[0] . '&order=' . $order[1]; } else { $order = '&selectionby=name&selection=asc&orderby=name&order=asc'; } st_tag_cloud('hide_empty=false&number=&color=false&get=all&title=' . $order . '&taxonomy=' . SimpleTags_Admin::$taxonomy); ?> </div> </div> <table id="manage-table-terms" class="form-table"> <tr valign="top"> <th scope="row"><strong><?php _e('Rename/Merge Terms', 'simpletags'); ?> </strong></th> <td> <p><?php _e('Enter the term to rename and its new value. You can use this feature to merge terms too. Click "Rename" and all posts which use this term will be updated.', 'simpletags'); ?> </p> <p><?php _e('You can specify multiple terms to rename by separating them with commas.', 'simpletags'); ?> </p> <fieldset> <form action="" method="post"> <input type="hidden" name="taxo" value="<?php echo esc_attr(SimpleTags_Admin::$taxonomy); ?> "/> <input type="hidden" name="cpt" value="<?php echo esc_attr(SimpleTags_Admin::$post_type); ?> "/> <input type="hidden" name="term_action" value="renameterm"/> <input type="hidden" name="term_nonce" value="<?php echo wp_create_nonce('simpletags_admin'); ?> "/> <p> <label for="renameterm_old"><?php _e('Term(s) to rename:', 'simpletags'); ?> </label> <br/> <input type="text" class="autocomplete-input" id="renameterm_old" name="renameterm_old" value="" size="40"/> </p> <p> <label for="renameterm_new"><?php _e('New term name(s):', 'simpletags'); ?> <br/> <input type="text" class="autocomplete-input" id="renameterm_new" name="renameterm_new" value="" size="40"/> </p> <input class="button-primary" type="submit" name="rename" value="<?php _e('Rename', 'simpletags'); ?> "/> </form> </fieldset> </td> </tr> <tr valign="top"> <th scope="row"><strong><?php _e('Delete Terms', 'simpletags'); ?> </strong></th> <td> <p><?php _e('Enter the name of terms to delete. Terms will be removed from all posts.', 'simpletags'); ?> </p> <p><?php _e('You can specify multiple terms to delete by separating them with commas', 'simpletags'); ?> .</p> <fieldset> <form action="" method="post"> <input type="hidden" name="taxo" value="<?php echo esc_attr(SimpleTags_Admin::$taxonomy); ?> "/> <input type="hidden" name="cpt" value="<?php echo esc_attr(SimpleTags_Admin::$post_type); ?> "/> <input type="hidden" name="term_action" value="deleteterm"/> <input type="hidden" name="term_nonce" value="<?php echo wp_create_nonce('simpletags_admin'); ?> "/> <p> <label for="deleteterm_name"><?php _e('Term(s) to delete:', 'simpletags'); ?> </label> <br/> <input type="text" class="autocomplete-input" id="deleteterm_name" name="deleteterm_name" value="" size="40"/> </p> <input class="button-primary" type="submit" name="delete" value="<?php _e('Delete', 'simpletags'); ?> "/> </form> </fieldset> </td> </tr> <tr valign="top"> <th scope="row"><strong><?php _e('Add Terms', 'simpletags'); ?> </strong></th> <td> <p><?php _e('This feature lets you add one or more new terms to all posts which match any of the terms given.', 'simpletags'); ?> </p> <p><?php _e('You can specify multiple terms to add by separating them with commas. If you want the term(s) to be added to all posts, then don\'t specify any terms to match.', 'simpletags'); ?> </p> <fieldset> <form action="" method="post"> <input type="hidden" name="taxo" value="<?php echo esc_attr(SimpleTags_Admin::$taxonomy); ?> "/> <input type="hidden" name="cpt" value="<?php echo esc_attr(SimpleTags_Admin::$post_type); ?> "/> <input type="hidden" name="term_action" value="addterm"/> <input type="hidden" name="term_nonce" value="<?php echo wp_create_nonce('simpletags_admin'); ?> "/> <p> <label for="addterm_match"><?php _e('Term(s) to match:', 'simpletags'); ?> </label> <br/> <input type="text" class="autocomplete-input" id="addterm_match" name="addterm_match" value="" size="40"/> </p> <p> <label for="addterm_new"><?php _e('Term(s) to add:', 'simpletags'); ?> </label> <br/> <input type="text" class="autocomplete-input" id="addterm_new" name="addterm_new" value="" size="40"/> </p> <input class="button-primary" type="submit" name="Add" value="<?php _e('Add', 'simpletags'); ?> "/> </form> </fieldset> </td> </tr> <tr valign="top"> <th scope="row"><strong><?php _e('Remove rarely used terms', 'simpletags'); ?> </strong></th> <td> <p><?php _e('This feature allows you to remove rarely used terms.', 'simpletags'); ?> </p> <p><?php _e('You can specify the number below which will be removed terms. If you put 5, all terms with a counter inferior to 5 will be deleted. The terms with a counter equal to 5 is keep.', 'simpletags'); ?> </p> <fieldset> <form action="" method="post"> <input type="hidden" name="taxo" value="<?php echo esc_attr(SimpleTags_Admin::$taxonomy); ?> "/> <input type="hidden" name="cpt" value="<?php echo esc_attr(SimpleTags_Admin::$post_type); ?> "/> <input type="hidden" name="term_action" value="remove-rarelyterms"/> <input type="hidden" name="term_nonce" value="<?php echo wp_create_nonce('simpletags_admin'); ?> "/> <p> <label for="number-delete"><?php _e('Numbers minimum:', 'simpletags'); ?> </label> <br/> <select name="number-rarely" id="number-delete"> <?php for ($i = 1; $i <= 100; $i++) { ?> <option value="<?php echo $i; ?> "><?php echo $i; ?> </option> <?php } ?> </select> </p> <input class="button-primary" type="submit" name="Delete" value="<?php _e('Delete rarely used', 'simpletags'); ?> "/> </form> </fieldset> </td> </tr> <?php /* <tr valign="top"> <th scope="row"><strong><?php _e('Edit Term Slug', 'simpletags'); ?></strong></th> <td> <p><?php _e('Enter the term name to edit and its new slug. <a href="http://codex.wordpress.org/Glossary#Slug">Slug definition</a>', 'simpletags'); ?></p> <p><?php _e('You can specify multiple terms to rename by separating them with commas.', 'simpletags'); ?></p> <fieldset> <form action="" method="post"> <input type="hidden" name="taxo" value="<?php echo esc_attr(SimpleTags_Admin::$taxonomy); ?>" /> <input type="hidden" name="cpt" value="<?php echo esc_attr(SimpleTags_Admin::$post_type); ?>" /> <input type="hidden" name="term_action" value="editslug" /> <input type="hidden" name="term_nonce" value="<?php echo wp_create_nonce('simpletags_admin'); ?>" /> <p> <label for="tagname_match"><?php _e('Term(s) to match:', 'simpletags'); ?></label> <br /> <input type="text" class="autocomplete-input" id="tagname_match" name="tagname_match" value="" size="40" /> </p> <p> <label for="tagslug_new"><?php _e('Slug(s) to set:', 'simpletags'); ?></label> <br /> <input type="text" class="autocomplete-input" id="tagslug_new" name="tagslug_new" value="" size="40" /> </p> <input class="button-primary" type="submit" name="edit" value="<?php _e('Edit', 'simpletags'); ?>" /> </form> </fieldset> </td> </tr> */ ?> <tr> <th scope="row"><strong><?php _e('Technical informations', 'simpletags'); ?> </strong></th> <td> <p><strong><?php _e('Renaming', 'simpletags'); ?> </strong></p> <p> <em><?php _e('Simple Tags don\'t use the same method as WordPress for rename a term. For example, in WordPress you have 2 terms : "Blogging" and "Bloging". When you want edit the term "Bloging" for rename it on "Blogging", WordPress will keep the two terms with the same name but with a different slug. <br />With Simple Tags, when you edit "Bloging" for "Blogging", Simple Tags merge posts filled with "Bloging" to "Blogging" and it delete the term "Bloging". Another logic ;)', 'simpletags'); ?> <em></p> </td> </tr> </table> <div class="clear"></div> <?php SimpleTags_Admin::printAdminFooter(); ?> </div> <?php do_action('simpletags-manage_terms', SimpleTags_Admin::$taxonomy); }
/** * Suggest tags from local database * */ public static function ajax_suggest_local() { status_header(200); header("Content-Type: text/html; charset=" . get_bloginfo('charset')); if ((int) wp_count_terms('post_tag', 'ignore_empty=false') == 0) { // No tags to suggest echo '<p>' . __('No terms in your WordPress database.', 'simpletags') . '</p>'; exit; } // Get data $content = stripslashes($_POST['content']) . ' ' . stripslashes($_POST['title']); $content = trim($content); if (empty($content)) { echo '<p>' . __('No text was sent.', 'simpletags') . '</p>'; exit; } // Get all terms $terms = SimpleTags_Admin::getTermsForAjax('post_tag', ''); if (empty($terms) || $terms == false) { echo '<p>' . __('No results from your WordPress database.', 'simpletags') . '</p>'; exit; } $flag = false; foreach ((array) $terms as $term) { $term = stripslashes($term->name); if (is_string($term) && !empty($term) && stristr($content, $term)) { $flag = true; echo '<span class="local">' . esc_html($term) . '</span>' . "\n"; } } if ($flag == false) { echo '<p>' . __('No correspondance between your content and terms from the WordPress database.', 'simpletags') . '</p>'; } else { echo '<div class="clear"></div>'; } exit; }
/** * Display a span list for click tags * * @return void * @author Amaury Balmer */ public static function ajax_click_tags() { status_header(200); // Send good header HTTP header("Content-Type: text/html; charset=" . get_bloginfo('charset')); if ((int) wp_count_terms('post_tag', 'ignore_empty=false') == 0) { // No tags to suggest echo '<p>' . __('No terms in your WordPress database.', 'simpletags') . '</p>'; exit; } // Prepare search $search = isset($_GET['q']) ? trim(stripslashes($_GET['q'])) : ''; $post_id = isset($_GET['post_id']) ? intval($_GET['post_id']) : 0; // Order tags before selection (count-asc/count-desc/name-asc/name-desc/random) $order_click_tags = strtolower(SimpleTags_Plugin::get_option_value('order_click_tags')); $order_by = $order = ''; switch ($order_click_tags) { case 'count-asc': $order_by = 'tt.count'; $order = 'ASC'; break; case 'random': $order_by = 'RAND()'; $order = ''; break; case 'count-desc': $order_by = 'tt.count'; $order = 'DESC'; break; case 'name-desc': $order_by = 't.name'; $order = 'DESC'; break; default: // name-asc $order_by = 't.name'; $order = 'ASC'; break; } // Get all terms, or filter with search $terms = SimpleTags_Admin::getTermsForAjax('post_tag', $search, $order_by, $order); if (empty($terms) || $terms == false) { echo '<p>' . __('No results from your WordPress database.', 'simpletags') . '</p>'; exit; } // Get terms for current post $post_terms = array(); if ($post_id > 0) { $post_terms = wp_get_post_terms($post_id, 'post_tag', array('fields' => 'ids')); } foreach ((array) $terms as $term) { $class_current = in_array($term->term_id, $post_terms) ? 'used_term' : ''; echo '<span class="local ' . $class_current . '">' . esc_html(stripslashes($term->name)) . '</span>' . "\n"; } echo '<div class="clear"></div>'; exit; }
/** * WP Page - Auto Tags * * @return void * @author Amaury Balmer */ public static function pageAutoTerms() { global $wpdb; // Get options $options = get_option(STAGS_OPTIONS_NAME_AUTO); if ($options == false) { // First save ? $options = array(); } if (!isset($options[SimpleTags_Admin::$post_type])) { // First save for this CPT ? $options[SimpleTags_Admin::$post_type] = array(); } if (!isset($options[SimpleTags_Admin::$post_type][SimpleTags_Admin::$taxonomy])) { // First save for this taxo ? $options[SimpleTags_Admin::$post_type][SimpleTags_Admin::$taxonomy] = array(); } $taxo_options = $options[SimpleTags_Admin::$post_type][SimpleTags_Admin::$taxonomy]; // Edit local option taxo $action = false; if (isset($_POST['update_auto_list'])) { check_admin_referer('update_auto_list-simpletags'); // Tags list $terms_list = stripslashes($_POST['auto_list']); $terms = explode(',', $terms_list); // Remove empty and duplicate elements $terms = array_filter($terms, '_delete_empty_element'); $terms = array_unique($terms); $taxo_options['auto_list'] = maybe_serialize($terms); // Active auto terms ? $taxo_options['use_auto_terms'] = isset($_POST['use_auto_terms']) && $_POST['use_auto_terms'] == '1' ? '1' : '0'; // All terms ? $taxo_options['at_all'] = isset($_POST['at_all']) && $_POST['at_all'] == '1' ? '1' : '0'; // Empty only ? $taxo_options['at_empty'] = isset($_POST['at_empty']) && $_POST['at_empty'] == '1' ? '1' : '0'; // Full word ? $taxo_options['only_full_word'] = isset($_POST['only_full_word']) && $_POST['only_full_word'] == '1' ? '1' : '0'; // Support hashtag format ? $taxo_options['allow_hashtag_format'] = isset($_POST['allow_hashtag_format']) && $_POST['allow_hashtag_format'] == '1' ? '1' : '0'; $options[SimpleTags_Admin::$post_type][SimpleTags_Admin::$taxonomy] = $taxo_options; update_option(STAGS_OPTIONS_NAME_AUTO, $options); add_settings_error(__CLASS__, __CLASS__, __('Auto terms options updated !', 'simpletags'), 'updated'); } elseif (isset($_GET['action']) && $_GET['action'] == 'auto_tag') { $action = true; $n = isset($_GET['n']) ? intval($_GET['n']) : 0; } $terms_list = ''; if (isset($taxo_options['auto_list']) && !empty($taxo_options['auto_list'])) { $terms = maybe_unserialize($taxo_options['auto_list']); if (is_array($terms)) { $terms_list = implode(', ', $terms); } } settings_errors(__CLASS__); ?> <div class="wrap st_wrap"> <h2><?php _e('Overview', 'simpletags'); ?> <p><?php _e('The bulb are lit when the association taxonomy and custom post type have the classification automatic activated. Otherwise, the bulb is off.', 'simpletags'); ?> <table class="widefat tag fixed" cellspacing="0"> <thead> <tr> <th scope="col" id="label" class="manage-column column-name"><?php _e('Custom types / Taxonomies', 'simpletags'); ?> </th> <?php foreach (get_taxonomies(array('show_ui' => true), 'object') as $taxo) { if (empty($taxo->labels->name)) { continue; } echo '<th scope="col">' . esc_html($taxo->labels->name) . '</th>'; } ?> </tr> </thead> <tfoot> <tr> <th scope="col" class="manage-column column-name"><?php _e('Custom types / Taxonomies', 'simpletags'); ?> </th> <?php foreach (get_taxonomies(array('show_ui' => true), 'object') as $taxo) { if (empty($taxo->labels->name)) { continue; } echo '<th scope="col">' . esc_html($taxo->labels->name) . '</th>'; } ?> </tr> </tfoot> <tbody id="the-list" class="list:taxonomies"> <?php $class = 'alternate'; $i = 0; foreach (get_post_types(array(), 'objects') as $post_type) { if (!$post_type->show_ui || empty($post_type->labels->name)) { continue; } // Get compatible taxo for current post type $compatible_taxonomies = get_object_taxonomies($post_type->name); if (empty($compatible_taxonomies)) { continue; } $i++; $class = $class == 'alternate' ? '' : 'alternate'; ?> <tr id="custom type-<?php echo $i; ?> " class="<?php echo $class; ?> "> <th class="name column-name"><?php echo esc_html($post_type->labels->name); ?> </th> <?php foreach (get_taxonomies(array('show_ui' => true), 'object') as $line_taxo) { if (empty($line_taxo->labels->name)) { continue; } echo '<td>' . "\n"; if (in_array($line_taxo->name, $compatible_taxonomies)) { if (isset($options[$post_type->name][$line_taxo->name]) && isset($options[$post_type->name][$line_taxo->name]['use_auto_terms']) && $options[$post_type->name][$line_taxo->name]['use_auto_terms'] == '1') { echo '<a href="' . self::$tools_base_url . 'st_auto&taxo=' . $line_taxo->name . '&cpt=' . $post_type->name . '"><img src="' . STAGS_URL . '/assets/images/lightbulb.png" alt="' . __('Context configured & actived.', 'simpletags') . '" /></a>' . "\n"; } else { echo '<a href="' . self::$tools_base_url . 'st_auto&taxo=' . $line_taxo->name . '&cpt=' . $post_type->name . '"><img src="' . STAGS_URL . '/assets/images/lightbulb_off.png" alt="' . __('Context unconfigured.', 'simpletags') . '" /></a>' . "\n"; } } else { echo '-' . "\n"; } echo '</td>' . "\n"; } ?> </tr> <?php } ?> </tbody> </table> <div class="clear"></div> </div> <div class="wrap st_wrap"> <h2><?php printf(__('Auto Terms for %s and %s', 'simpletags'), '<strong>' . SimpleTags_Admin::$post_type_name . '</strong>', '<strong>' . SimpleTags_Admin::$taxo_name . '</strong>'); ?> </h2> <?php if ($action === false) { ?> <h3><?php _e('Auto terms list', 'simpletags'); ?> </h3> <p><?php _e('This feature allows Wordpress to look into post content and title for specified terms when saving posts. If your post content or title contains the word "WordPress" and you have "wordpress" in auto terms list, Simple Tags will add automatically "wordpress" as term for this post.', 'simpletags'); ?> </p> <h3><?php _e('Options', 'simpletags'); ?> </h3> <form action="<?php echo self::$tools_base_url . 'st_auto&taxo=' . SimpleTags_Admin::$taxonomy . '&cpt=' . SimpleTags_Admin::$post_type; ?> " method="post"> <table class="form-table"> <tr valign="top"> <th scope="row"><?php _e('Activation', 'simpletags'); ?> </th> <td> <input type="checkbox" id="use_auto_terms" name="use_auto_terms" value="1" <?php echo isset($taxo_options['use_auto_terms']) && $taxo_options['use_auto_terms'] == 1 ? 'checked="checked"' : ''; ?> /> <label for="use_auto_terms"><?php _e('Active Auto Tags.', 'simpletags'); ?> </label> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Terms database', 'simpletags'); ?> </th> <td> <input type="checkbox" id="at_all" name="at_all" value="1" <?php echo isset($taxo_options['at_all']) && $taxo_options['at_all'] == 1 ? 'checked="checked"' : ''; ?> /> <label for="at_all"><?php _e('Use also local terms database with auto terms. (Warning, this option can increases the CPU consumption a lot if you have many terms)', 'simpletags'); ?> </label> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Target', 'simpletags'); ?> </th> <td> <input type="checkbox" id="at_empty" name="at_empty" value="1" <?php echo isset($taxo_options['at_empty']) && $taxo_options['at_empty'] == 1 ? 'checked="checked"' : ''; ?> /> <label for="at_empty"><?php _e('Autotag only posts without terms.', 'simpletags'); ?> </label> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Whole Word ?', 'simpletags'); ?> </th> <td> <input type="checkbox" id="only_full_word" name="only_full_word" value="1" <?php echo isset($taxo_options['only_full_word']) && $taxo_options['only_full_word'] == 1 ? 'checked="checked"' : ''; ?> /> <label for="only_full_word"><?php _e('Autotag only a post when terms finded in the content are a the same name. (whole word only)', 'simpletags'); ?> </label> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Suport Hashtag format ?', 'simpletags'); ?> </th> <td> <input type="checkbox" id="allow_hashtag_format" name="allow_hashtag_format" value="1" <?php echo isset($taxo_options['allow_hashtag_format']) && $taxo_options['allow_hashtag_format'] == 1 ? 'checked="checked"' : ''; ?> /> <label for="allow_hashtag_format"><?php _e('When the whole word option is enabled, hashtag will not be autotag because of # prefix. This option allow to fixed this issue!', 'simpletags'); ?> </label> </td> </tr> <tr valign="top"> <th scope="row"><label for="auto_list"><?php _e('Keywords list', 'simpletags'); ?> </label></th> <td> <input type="text" id="auto_list" class="auto_list" name="auto_list" value="<?php echo esc_attr($terms_list); ?> " style="width:98%;" /> <br /><?php _e('Separated with a comma', 'simpletags'); ?> </td> </tr> </table> <p class="submit"> <?php wp_nonce_field('update_auto_list-simpletags'); ?> <input class="button-primary" type="submit" name="update_auto_list" value="<?php _e('Update options »', 'simpletags'); ?> " /> </p> </form> <h3><?php _e('Auto terms old content', 'simpletags'); ?> </h3> <p> <?php _e('Simple Tags can also tag all existing contents of your blog. This feature use auto terms list above-mentioned.', 'simpletags'); ?> </p> <p class="submit"> <a class="button-primary" href="<?php echo self::$tools_base_url . 'st_auto&taxo=' . SimpleTags_Admin::$taxonomy . '&cpt=' . SimpleTags_Admin::$post_type . '&action=auto_tag'; ?> "><?php _e('Auto terms all content »', 'simpletags'); ?> </a> </p> <?php } else { // Counter if ($n == 0) { update_option('tmp_auto_terms_st', 0); } // Get objects $objects = (array) $wpdb->get_results($wpdb->prepare("SELECT ID, post_title, post_content FROM {$wpdb->posts} WHERE post_type = %s AND post_status = 'publish' ORDER BY ID DESC LIMIT %d, 20", SimpleTags_Admin::$post_type, $n)); if (!empty($objects)) { echo '<ul>'; foreach ($objects as $object) { SimpleTags_Client_Autoterms::auto_terms_post($object, SimpleTags_Admin::$taxonomy, $taxo_options, true); echo '<li>#' . $object->ID . ' ' . $object->post_title . '</li>'; unset($object); } echo '</ul>'; ?> <p><?php _e("If your browser doesn't start loading the next page automatically click this link:", 'simpletags'); ?> <a href="<?php echo self::$tools_base_url . 'st_auto&taxo=' . SimpleTags_Admin::$taxonomy . '&cpt=' . SimpleTags_Admin::$post_type . '&action=auto_tag&n=' . ($n + 20); ?> "><?php _e('Next content', 'simpletags'); ?> </a></p> <script type="text/javascript"> // <![CDATA[ function nextPage() { location.href = "<?php echo self::$tools_base_url . 'st_auto&taxo=' . SimpleTags_Admin::$taxonomy . '&cpt=' . SimpleTags_Admin::$post_type . '&action=auto_tag&n=' . ($n + 20); ?> "; } window.setTimeout( 'nextPage()', 300 ); // ]]> </script> <?php } else { $counter = get_option('tmp_auto_terms_st'); delete_option('tmp_auto_terms_st'); echo '<p><strong>' . sprintf(__('All done! %s terms added.', 'simpletags'), $counter) . '</strong></p>'; } } ?> <p><?php _e('Visit the <a href="https://github.com/herewithme/simple-tags">plugin\'s homepage</a> for further details. If you find a bug, or have a fantastic idea for this plugin, <a href="mailto:amaury@wordpress-fr.net">ask me</a> !', 'simpletags'); ?> </p> <?php SimpleTags_Admin::printAdminFooter(); ?> </div> <?php do_action('simpletags-auto_terms', SimpleTags_Admin::$taxonomy); }
/** * Add settings page on WordPress admin menu * * @return void * @author Amaury Balmer */ public static function admin_menu() { add_options_page(__('Simple Tags: Options', 'simpletags'), __('Simple Tags', 'simpletags'), 'admin_simple_tags', self::menu_slug, array(__CLASS__, 'page_options')); self::$admin_url = admin_url('/options-general.php?page=' . self::menu_slug); }