/** * Initialize Simple Tags client * * @return SimpleTags */ public function __construct() { // Load translation add_action('init', array(__CLASS__, 'init_translation')); // Add pages in WP_Query if ((int) SimpleTags_Plugin::get_option_value('use_tag_pages') == 1) { add_action('init', array(__CLASS__, 'init'), 11); add_action('parse_query', array(__CLASS__, 'parse_query')); } // Call autolinks ? if ((int) SimpleTags_Plugin::get_option_value('auto_link_tags') == 1) { require STAGS_DIR . '/inc/class.client.autolinks.php'; new SimpleTags_Client_Autolinks(); } // Call related posts ? if ((int) SimpleTags_Plugin::get_option_value('active_related_posts') == 1) { require STAGS_DIR . '/inc/class.client.related_posts.php'; new SimpleTags_Client_RelatedPosts(); } // Call auto terms ? require STAGS_DIR . '/inc/class.client.autoterms.php'; new SimpleTags_Client_Autoterms(); // Call post tags ? require STAGS_DIR . '/inc/class.client.post_tags.php'; new SimpleTags_Client_PostTags(); return true; }
public function __construct() { // Embedded tag cloud if ((int) SimpleTags_Plugin::get_option_value('allow_embed_tcloud') == 1) { add_shortcode('st_tag_cloud', array(__CLASS__, 'shortcode')); add_shortcode('st-tag-cloud', array(__CLASS__, 'shortcode')); } }
/** * Build HTML of form * * @param object $post * * @return void * @author Amaury Balmer */ public static function metabox($post) { // Get auto options $auto_options = get_option(STAGS_OPTIONS_NAME_AUTO); // Auto terms for this CPT ? if ((int) SimpleTags_Plugin::get_option_value('active_autotags') == 1 && isset($auto_options[$post->post_type]) && !empty($auto_options[$post->post_type])) { $meta_value = get_post_meta($post->ID, '_exclude_autotags', true); echo '<p>' . "\n"; echo '<label><input type="checkbox" name="exclude_autotags" value="true" ' . checked($meta_value, true, false) . ' /> ' . __('Disable auto tags ?', 'simpletags') . '</label><br />' . "\n"; echo '</p>' . "\n"; echo '<input type="hidden" name="_meta_autotags" value="true" />'; } $taxonomies = get_object_taxonomies($post->post_type); if ((int) SimpleTags_Plugin::get_option_value('auto_link_tags') == 1 && in_array('post_tag', $taxonomies)) { $meta_value = get_post_meta($post->ID, '_exclude_autolinks', true); echo '<p>' . "\n"; echo '<label><input type="checkbox" name="exclude_autolinks" value="true" ' . checked($meta_value, true, false) . ' /> ' . __('Disable auto links ?', 'simpletags') . '</label><br />' . "\n"; echo '</p>' . "\n"; echo '<input type="hidden" name="_meta_autolink" value="true" />'; } }
/** * Auto add current tags post to post content * * @param string $content * @return string */ public static function the_content($content = '') { // Get option $tt_embedded = SimpleTags_Plugin::get_option_value('tt_embedded'); $marker = false; if (is_feed()) { if ((int) SimpleTags_Plugin::get_option_value('tt_feed') == 1) { $marker = true; } } elseif (!empty($tt_embedded)) { switch ($tt_embedded) { case 'blogonly': $marker = is_feed() ? false : true; break; case 'homeonly': $marker = is_home() ? true : false; break; case 'singularonly': $marker = is_singular() ? true : false; break; case 'singleonly': $marker = is_single() ? true : false; break; case 'pageonly': $marker = is_page() ? true : false; break; case 'all': $marker = true; break; case 'no': default: $marker = false; break; } } if ($marker === true) { return $content . self::extendedPostTags('', false); } return $content; }
/** * Initialize Admin * * @return void * @author Amaury Balmer */ public function __construct() { // DB Upgrade ? self::upgrade(); // Which taxo ? self::registerDetermineTaxonomy(); // Admin menu add_action('admin_menu', array(__CLASS__, 'admin_menu')); // Load JavaScript and CSS add_action('admin_enqueue_scripts', array(__CLASS__, 'admin_enqueue_scripts')); // Load custom part of plugin depending option if ((int) SimpleTags_Plugin::get_option_value('use_suggested_tags') == 1) { require STAGS_DIR . '/inc/class.admin.suggest.php'; new SimpleTags_Admin_Suggest(); } if ((int) SimpleTags_Plugin::get_option_value('use_click_tags') == 1) { require STAGS_DIR . '/inc/class.admin.clickterms.php'; new SimpleTags_Admin_ClickTags(); } if ((int) SimpleTags_Plugin::get_option_value('use_autocompletion') == 1) { require STAGS_DIR . '/inc/class.admin.autocomplete.php'; new SimpleTags_Admin_Autocomplete(); } if ((int) SimpleTags_Plugin::get_option_value('active_mass_edit') == 1) { require STAGS_DIR . '/inc/class.admin.mass.php'; new SimpleTags_Admin_Mass(); } if ((int) SimpleTags_Plugin::get_option_value('active_manage') == 1) { require STAGS_DIR . '/inc/class.admin.manage.php'; new SimpleTags_Admin_Manage(); } if ((int) SimpleTags_Plugin::get_option_value('active_autotags') == 1) { require STAGS_DIR . '/inc/class.admin.autoterms.php'; new SimpleTags_Admin_AutoTags(); } if ((int) SimpleTags_Plugin::get_option_value('active_autotags') == 1 || (int) SimpleTags_Plugin::get_option_value('auto_link_tags') == 1) { require STAGS_DIR . '/inc/class.admin.post.php'; new SimpleTags_Admin_Post_Settings(); } }
/** * public static function called on mass terms page * * @param string $taxonomy * @return void * @author Amaury Balmer */ public static function mass_terms_js($taxonomy = '') { // Get option $autocomplete_min = (int) SimpleTags_Plugin::get_option_value('autocomplete_min'); ?> <script type="text/javascript"> <!-- st_init_autocomplete( '.autocomplete-input', "<?php echo admin_url('admin-ajax.php?action=simpletags&st_action=helper_js_collection&taxonomy=' . $taxonomy); ?> ", <?php echo $autocomplete_min; ?> ); --> </script> <?php }
/** * Suggest tags from Tag4Site * */ public static function ajax_tag4site() { status_header(200); header("Content-Type: text/html; charset=" . get_bloginfo('charset')); // API Key ? if (SimpleTags_Plugin::get_option_value('tag4site_key') == '') { echo '<p>' . __('Tag4Site need an API key to work. You can register on service website to obtain a key and set it on Simple Tags options.', '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; } // Build params $response = wp_remote_post('http://api.tag4site.ru/', array('timeout' => 30, 'body' => array('api_key' => SimpleTags_Plugin::get_option_value('tag4site_key'), 'text' => $content, 'format' => 'json'))); if (!is_wp_error($response) && $response != null) { if (wp_remote_retrieve_response_code($response) == 200) { $data = wp_remote_retrieve_body($response); } } $data = json_decode($data); $code = $data->code; if ($code > 0) { $err = $data->error; echo '<p>' . __('Tag4Site API error #' . $code . ': ' . $err, 'simpletags') . '</p>'; exit; } $data = $data->tags; if (empty($data)) { echo '<p>' . __('No data from Tag4Site API. Try again later.', 'simpletags') . '</p>'; exit; } foreach ((array) $data as $term) { echo '<span class="local">' . esc_html($term->name) . '</span>' . "\n"; } echo '<div class="clear"></div>'; exit; }
/** * Suggest tags from Zemanta * */ public static function ajax_zemanta() { status_header(200); header("Content-Type: text/html; charset=" . get_bloginfo('charset')); // API Key ? if (SimpleTags_Plugin::get_option_value('zemanta_key') == '') { echo '<p>' . __('Zemanta need an API key to work. You can register on service website to obtain a key and set it on Simple Tags options.', '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; } // Build params $response = wp_remote_post('http://api.zemanta.com/services/rest/0.0/', array('body' => array('method' => 'zemanta.suggest', 'api_key' => SimpleTags_Plugin::get_option_value('zemanta_key'), 'text' => $content, 'format' => 'json', 'return_rdf_links' => 0, 'return_images' => 0))); if (!is_wp_error($response) && $response != null) { if (wp_remote_retrieve_response_code($response) == 200) { $data = wp_remote_retrieve_body($response); } } $data = json_decode($data); $data = $data->keywords; if (empty($data)) { echo '<p>' . __('No results from Zemanta API.', 'simpletags') . '</p>'; exit; } foreach ((array) $data as $term) { echo '<span class="local">' . esc_html($term->name) . '</span>' . "\n"; } 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; }
/** * Replace text by link, except HTML tag, and already text into link, use PregEXP. * * @param string $content * @param string $search * @param string $replace * @param string $case * @param string $rel */ private static function _replace_by_links_regexp(&$content, $search = '', $replace = '', $case = '', $rel = '') { $must_tokenize = true; // will perform basic tokenization $tokens = null; // two kinds of tokens: markup and text $j = 0; $filtered = ''; // will filter text token by token $match = '/(\\PL|\\A)(' . preg_quote($search, "/") . ')(\\PL|\\Z)/u' . $case; $substitute = '$1<a href="' . $replace . '" class="st_tag internal_tag" ' . $rel . ' title="' . esc_attr(sprintf(SimpleTags_Plugin::get_option_value('auto_link_title'), $search)) . "\">\$2</a>\$3"; //$match = "/\b" . preg_quote($search, "/") . "\b/".$case; //$substitute = '<a href="'.$replace.'" class="st_tag internal_tag" '.$rel.' title="'. esc_attr( sprintf( __('Posts tagged with %s', 'simpletags'), $search ) )."\">$0</a>"; // for efficiency only tokenize if forced to do so if ($must_tokenize) { // this regexp is taken from PHP Markdown by Michel Fortin: http://www.michelf.com/projects/php-markdown/ $comment = '(?s:<!(?:--.*?--\\s*)+>)|'; $processing_instruction = '(?s:<\\?.*?\\?>)|'; $tag = '(?:<[/!$]?[-a-zA-Z0-9:]+\\b(?>[^"\'>]+|"[^"]*"|\'[^\']*\')*>)'; $markup = $comment . $processing_instruction . $tag; $flags = PREG_SPLIT_DELIM_CAPTURE; $tokens = preg_split("{({$markup})}", $content, -1, $flags); $must_tokenize = false; } // there should always be at least one token, but check just in case $anchor_level = 0; if (isset($tokens) && is_array($tokens) && count($tokens) > 0) { $i = 0; foreach ($tokens as $token) { if (++$i % 2 && $token != '') { // this token is (non-markup) text if ($anchor_level == 0) { // linkify if not inside anchor tags if (preg_match($match, $token)) { // use preg_match for compatibility with PHP 4 $j++; if ($j <= SimpleTags_Plugin::get_option_value('auto_link_max_by_tag') || SimpleTags_Plugin::get_option_value('auto_link_max_by_tag') == 0) { // Limit replacement at 1 by default, or options value ! $token = preg_replace($match, $substitute, $token); // only PHP 5 supports calling preg_replace with 5 arguments } $must_tokenize = true; // re-tokenize next time around } } } else { // this token is markup if (preg_match("#<\\s*a\\s+[^>]*>#i", $token)) { // found <a ...> $anchor_level++; } elseif (preg_match("#<\\s*/\\s*a\\s*>#i", $token)) { // found </a> $anchor_level--; } } $filtered .= $token; // this token has now been filtered } $content = $filtered; // filtering completed for this link } }
/** * Suggest tags from ProxemAPI * */ public static function ajax_proxem_api() { status_header(200); header("Content-Type: text/html; charset=" . get_bloginfo('charset')); // API Key ? if (SimpleTags_Plugin::get_option_value('proxem_key') == '') { echo '<p>' . __('Proxem API need an API key to work. You can register on service website to obtain a key and set it on Simple Tags options.', '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; } // Build params $response = wp_remote_post('https://proxem-thematization.p.mashape.com/api/wikiAnnotator/GetCategories?nbtopcat=10', array('headers' => array('X-Mashape-Key' => SimpleTags_Plugin::get_option_value('proxem_key'), 'Accept' => "application/json", 'Content-Type' => "text/plain"), 'body' => $content, 'timeout' => 15)); if (!is_wp_error($response) && $response != null) { if (wp_remote_retrieve_response_code($response) == 200) { $data = wp_remote_retrieve_body($response); } } $data = json_decode($data); if ($data == false || !isset($data->categories)) { var_dump($response); return false; } if (empty($data->categories)) { echo '<p>' . __('No results from Proxem API.', 'simpletags') . '</p>'; exit; } foreach ((array) $data->categories as $term) { echo '<span class="local">' . esc_html($term->name) . '</span>' . "\n"; } echo '<div class="clear"></div>'; exit; }