コード例 #1
0
ファイル: compatibility.php プロジェクト: nrporter/scriblio
 public function get_tag_link($tag)
 {
     if ($term = get_term_by('slug', $tag['slug'], $tag['taxonomy'])) {
         return scriblio()->facets()->permalink(scriblio()->facets()->_tax_to_facet[$term->taxonomy], $term);
     }
     return '';
 }
コード例 #2
0
ファイル: class-scriblio.php プロジェクト: nrporter/scriblio
 /**
  * Register our known facets, then do the scrib_register_facets action
  */
 public function wp_loaded()
 {
     // turn on performance profiling if requested
     if (isset($_REQUEST['scriblio-profiler']) && current_user_can('manage_options')) {
         $this->profiler = TRUE;
     }
     // cachebuster
     if (isset($_REQUEST['scriblio-cachebuster']) && current_user_can('manage_options')) {
         $this->cachebuster = TRUE;
     }
     // if we're loading default facets, then figure out what they are
     if ($this->options['register_default_facets']) {
         $this->options['facets'] = $this->get_default_facets();
     } else {
         $this->options['facets'] = array();
     }
     // Filter the default facets
     $this->options['facets'] = apply_filters('go_config', $this->options['facets'], 'scriblio-facets');
     // load the facets we know about
     if (is_array($this->options['facets'])) {
         foreach ($this->options['facets'] as $facet => $options) {
             scriblio()->register_facet($facet, $options['class'], $options['args']);
         }
     }
     // end if
     // call the trigger so facets defined in other plugins can load
     do_action('scrib_register_facets');
 }
コード例 #3
0
 function get_terms_in_post($post_id = FALSE)
 {
     if (!$post_id) {
         $post_id = get_the_ID();
     }
     if (!$post_id) {
         return FALSE;
     }
     scriblio()->timer('facet_taxonomy::get_terms_in_post');
     $terms = wp_get_object_terms($post_id, $this->taxonomy);
     $terms = apply_filters('scriblio_facet_taxonomy_terms', $terms);
     $terms_in_post = array();
     foreach ($terms as $term) {
         $terms_in_post[] = (object) array('facet' => $this->facets->_tax_to_facet[$term->taxonomy], 'slug' => $term->slug, 'name' => $term->name, 'description' => $term->description, 'term_id' => $term->term_id, 'term_taxonomy_id' => $term->term_taxonomy_id, 'count' => $term->count);
     }
     scriblio()->timer('facet_taxonomy::get_terms_in_post');
     return $terms_in_post;
 }
コード例 #4
0
 /**
  * generate a cache key based on $base, taking into account our version
  * number and whether scriblio()->cachebuster is set or not.
  *
  * @param string $base the base of our cache key
  * @param bool $hash hash the resulting key if TRUE
  * @return string a unique cache key based on $base and our plugin version
  */
 public function get_cache_key($base, $hash = TRUE)
 {
     $key = ($hash ? md5($base) : $base) . '|' . $this->version;
     return $key . (scriblio()->cachebuster ? 'CACHEBUSTER' : '');
 }
コード例 #5
0
ファイル: class-facets.php プロジェクト: nrporter/scriblio
 public function generate_tag_cloud($tags, $args = '')
 {
     scriblio()->timer('generate_tag_cloud');
     global $wp_rewrite;
     $args = wp_parse_args($args, array('smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45, 'name' => 'name', 'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC'));
     if (!$tags) {
         return;
     }
     $counts = array();
     foreach ((array) $tags as $tag_key => $tag_val) {
         $counts[$tag_val->slug . ':' . $tag_val->facet] = $tag_val->count;
         $tag_info[$tag_val->slug . ':' . $tag_val->facet] = $tag_val;
         // preserve the original ordering in case orderby is 'none'
         // $tag_key is just the numeric array index of $tag_val
         $orig_order[$tag_val->slug . ':' . $tag_val->facet] = $tag_key;
     }
     //END foreach
     if (!$counts) {
         return;
     }
     asort($counts);
     if ($args['number'] > 0) {
         $counts = array_slice($counts, -$args['number'], $args['number'], TRUE);
     }
     //end if
     $min_count = min($counts);
     $spread = max($counts) - $min_count;
     if ($spread <= 0) {
         $spread = 1;
     }
     $font_spread = $args['largest'] - $args['smallest'];
     if ($font_spread <= 0) {
         $font_spread = 1;
     }
     $font_step = $font_spread / $spread;
     // SQL cannot save you; this is a second (potentially different) sort on a subset of data.
     if ('name' == $args['orderby']) {
         uksort($counts, 'strnatcasecmp');
     } elseif ('none' == $args['orderby']) {
         // copy values of $counts to $orig_order
         $orig_order = array_replace($orig_order, $counts);
         // and then filter out any key not in $counts
         $counts = array_intersect_key($orig_order, $counts);
     } else {
         asort($counts);
     }
     if ('DESC' == $args['order']) {
         $counts = array_reverse($counts, true);
     }
     $a = array();
     foreach ($counts as $tag => $count) {
         $is_selected = $this->facets->{$tag_info[$tag]->facet}->selected($tag_info[$tag]);
         $term_name = apply_filters('scriblio_facets_facet_description', trim($args['name'] == 'description' ? $tag_info[$tag]->description : $tag_info[$tag]->name), $tag_info[$tag]->facet);
         $before_link = apply_filters('scriblio_facets_tag_cloud_pre_link', '', $tag_info[$tag]->facet, $count, $this->count_found_posts);
         if (!is_string($before_link)) {
             $before_link = '';
             trigger_error(__FILE__ . ':' . __LINE__ . ' filter expected a string, but got something else ' . var_export($before_link, TRUE) . ' referrer:' . $_SERVER['HTTP_REFERER'], E_USER_NOTICE);
         }
         $a[] = sprintf('<%1$s class="%2$s" data-term="%3$s" data-taxonomy="%4$s" data-term-url="%5$s">%11$s<a href="%6$s" class="term-link" title="%7$s"%8$s>%9$s%10$s</a></%1$s>', 'list' == $args['format'] ? 'li' : 'span', $is_selected ? 'selected' : '', esc_attr($term_name), esc_attr($this->facets->{$tag_info[$tag]->facet}->label), $this->permalink($tag_info[$tag]->facet, $tag_info[$tag], -1), $this->permalink($tag_info[$tag]->facet, $tag_info[$tag], (int) (!$is_selected)), esc_attr(sprintf(__('%d topics'), $count)), 'list' == $args['format'] ? '' : 'style="font-size: ' . ($args['smallest'] + ($count - $min_count) * $font_step) . $args['unit'] . ';"', esc_html($term_name), 'list' == $args['format'] ? '<span class="count"><span class="meta-sep">&nbsp;</span>' . number_format($count) . '</span>' : '', $before_link);
     }
     //end foreach
     switch ($args['format']) {
         case 'array':
             $return =& $a;
             break;
         case 'list':
             $return = "<ul class='wp-tag-cloud'>\n\t" . convert_chars(wptexturize(join("\n\t", $a))) . "\n</ul>\n";
             break;
         case 'flat':
         case 'cloud':
         default:
             $return = "<div class='wp-tag-cloud'>\n" . convert_chars(wptexturize(join("\n", $a))) . "\n</div>\n";
     }
     //end switch
     scriblio()->timer('generate_tag_cloud', $args);
     return $return;
 }
コード例 #6
0
ファイル: scriblio.php プロジェクト: nrporter/scriblio
<?php

/*
Plugin Name: Scriblio Search
Plugin URI: http://wordpress.org/plugins/scriblio/
Version: 3.3
Author: Casey Bisson
Author URI: http://maisonbisson.com/blog/
*/
// include required components
require_once __DIR__ . '/plugin/class-scriblio.php';
scriblio();
コード例 #7
0
 /**
  * Convert a keyword search term to a taxonomy (embodied in a facet)
  *
  * @return mixed an array with two elements of [ new_facet_name, new_facet]
  *  if the keyword search can be converted to a facet, or FALSE if not.
  */
 public function to_taxonomy()
 {
     // there should only be one term since we don't break up the search
     // string from the search textbox
     $search_slug = sanitize_title_with_dashes(array_keys($this->facets->selected_facets->searchword)[0]);
     // check if we have cached facets for $search_slug
     $facets = wp_cache_get($search_slug, $this->cache_group);
     if (FALSE !== $facets && empty($facets)) {
         return FALSE;
         // empty cached result
     }
     // not found in our cache
     if (FALSE === $facets) {
         // get all terms with slug $search_slug
         $terms = $this->get_taxonomy_terms($search_slug);
         // sort the terms by count since the counts may have changed
         // after they were loaded from the DB
         usort($terms, array($this, 'compare_count_desc'));
         if (empty($terms)) {
             // cache negative results too
             wp_cache_set($search_slug, array(), $this->cache_group, $this->cache_ttl);
             return FALSE;
         }
         // iterate over $terms, which are now in descending count order,
         // until we get a facet.
         foreach ($terms as $term) {
             // cast the result to an array so we can check if it's empty
             $facets = (array) scriblio()->get_terms_as_facets(array($term));
             if (!empty($facets)) {
                 break;
             }
         }
         //END foreach
         // cache the results. $facets should contain just one term,
         // or it could be empty
         wp_cache_set($search_slug, $facets, $this->cache_group, $this->cache_ttl);
     }
     //END if
     if (empty($facets)) {
         return FALSE;
         // still got nothing
     }
     $new_facet_name = array_keys($facets)[0];
     // cast back to an object so we can dereference $facets->$new_facet_name
     $facets = (object) $facets;
     // make sure the converted facet/taxonomy is selected for the search
     if (!isset($this->facets->selected_facets->{$new_facet_name})) {
         $this->facets->selected_facets->{$new_facet_name} = $facets->{$new_facet_name};
     }
     // merge new terms in $facets with any existing search term in the
     // converted facet/taxonomy
     $this->facets->selected_facets->{$new_facet_name} = array_merge($this->facets->selected_facets->{$new_facet_name}, $facets->{$new_facet_name});
     // not a keyword search any more
     unset($this->facets->selected_facets->searchword);
     return TRUE;
 }