Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Updated the 1.x version

  • Loading branch information...
commit 2aed006098211596a728b604e49ca0aadc925daa 1 parent 3e240e0
Aaron Gustafson aarongustafson authored
68 EE1/system/plugins/Highlighter.php
... ... @@ -0,0 +1,68 @@
  1 +<?php
  2 +/**********************************************************************************************
  3 + * highlighter.php
  4 + **********************************************************************************************
  5 + * This class highlights text matches a search string (keyword) in html based documents, without destroying html-tags.
  6 + * This was necessary to scan database-entry written in html by keywords, and display them in another style.
  7 + **********************************************************************************************
  8 + * @name Highlighter
  9 + * @description Advanced keyword highlighter, keep HTML tags safe.
  10 + * @author(s) Bojidar Naydenov a.k.a Bojo (bojo2000@mail.bg) & Antony Raijekov a.k.a Zeos (dev@strategma.bg)
  11 + * @country Bulgaria
  12 + * @version 2.1
  13 + * @copyright GPL
  14 + * @access public
  15 + *********************************************************************************************/
  16 +class Highlighter
  17 +{
  18 + var $keyword;
  19 + var $replacement;
  20 + var $hightlight_bad_tags = array( "A", "IMG" ); //add here more, if you want to filter them
  21 +
  22 + //constructor
  23 + function Highlighter ( $keyword=FALSE, $replacement=FALSE )
  24 + {
  25 + $this->keyword = $keyword;
  26 + $this->replacement = $replacement;
  27 + } //end func highlight
  28 +
  29 + //private
  30 + function highlight ( $matches )
  31 + {
  32 + //check for bad tags and keyword
  33 + if ( ! in_array( strtoupper($matches[2]), $this->hightlight_bad_tags ) )
  34 + {
  35 + //put template [replacement]
  36 + $proceed = preg_replace( "#(".$this->keyword.")#si",
  37 + str_replace( "{keyword}", $matches[3], $this->replacement ),
  38 + $matches[0] );
  39 + }
  40 + else //return as-is
  41 + {
  42 + $proceed = $matches[0];
  43 + }
  44 + return stripslashes( $proceed );
  45 + } //end func hightlighter
  46 +
  47 + //main api
  48 + function process( $text, $keyword=FALSE, $replacement=FALSE )
  49 + {
  50 + //if there are specific keyword/replacement given
  51 + if ( $keyword != FALSE ) $this->keyword = $keyword;
  52 + if ( $replacement != FALSE ) $this->replacement = $replacement;
  53 +
  54 + //process text array(&$this, 'method_name'),
  55 + if ( isset($this->keyword) AND
  56 + isset($this->replacement) ):
  57 + return preg_replace_callback( "#(<([A-Za-z]+)[^>]*[\>]*)*(".$this->keyword.")(.*?)(<\/\\2>)*#si",
  58 + array( &$this, 'highlight' ),
  59 + $text );
  60 + else:
  61 + return $text;
  62 + endif;
  63 + } //end func process
  64 +
  65 +} // end Highlighter
  66 +
  67 +/* End of file Highlighter.php */
  68 +/* Location: ./system/expressionengine/third_party/easy_search_summary/Highlighter.php */
295 EE1/system/plugins/Summarizer.php
... ... @@ -0,0 +1,295 @@
  1 +<?php
  2 +
  3 +class Summarizer {
  4 +
  5 + var $debug;
  6 +
  7 + function Summarizer($debug=FALSE)
  8 + {
  9 + $this->debug = $debug;
  10 + }
  11 +
  12 + function excerpt( $text, $words, $length=150, $prefix="&#8230;", $suffix=NULL, $options=array() )
  13 + {
  14 + $text = html_entity_decode( $text, ENT_QUOTES, 'UTF-8' );
  15 +
  16 + // Set default score modifiers [tweak away...]
  17 + $options = array_merge( array(
  18 + 'exact_case_bonus' => 2,
  19 + 'exact_word_bonus' => 3,
  20 + 'abs_length_weight' => 0.0,
  21 + 'rel_length_weight' => 1.0,
  22 + 'debug' => $this->debug
  23 + ), $options);
  24 +
  25 + // Null suffix defaults to same as prefix
  26 + if ( is_null($suffix) ) $suffix = $prefix;
  27 +
  28 + // Not enough to work with?
  29 + if ( strlen($text) <= $length ) return $text;
  30 +
  31 + // Just in case
  32 + if ( ! is_array($words) ) $words = array($words);
  33 +
  34 + // Build the event list
  35 + // [also calculate maximum word length for relative weight bonus]
  36 + $events = array();
  37 + $maxWordLength = 0;
  38 +
  39 + foreach ($words as $word) {
  40 +
  41 + if (strlen($word) > $maxWordLength) $maxWordLength = strlen($word);
  42 +
  43 + $i = -1;
  44 + while ( ($i = stripos($text, $word, $i+1)) !== false )
  45 + {
  46 +
  47 + // Basic score for a match is always 1
  48 + $score = 1;
  49 +
  50 + // Apply modifiers
  51 + // Case matches exactly
  52 + if (substr($text, $i, strlen($word)) == $word) $score += $options['exact_case_bonus'];
  53 +
  54 + // Absolute length weight (longer words count for more)
  55 + if ($options['abs_length_weight'] != 0.0) $score += strlen($word) * $options['abs_length_weight'];
  56 +
  57 + // Relative length weight (longer words count for more)
  58 + if ($options['rel_length_weight'] != 0.0) $score += strlen($word) / $maxWordLength * $options['rel_length_weight'];
  59 +
  60 + // The start of the word matches exactly
  61 + if (preg_match('/\W/', substr($text, $i-1, 1))) $score += $options['exact_word_bonus'];
  62 +
  63 + // The end of the word matches exactly
  64 + if (preg_match('/\W/', substr($text, $i+strlen($word), 1))) $score += $options['exact_word_bonus'];
  65 +
  66 +
  67 + // Push event occurs when the word comes into range
  68 + $events[] = array(
  69 + 'type' => 'push',
  70 + 'word' => $word,
  71 + 'pos' => max(0, $i + strlen($word) - $length),
  72 + 'score' => $score
  73 + );
  74 + // Pop event occurs when the word goes out of range
  75 + $events[] = array(
  76 + 'type' => 'pop',
  77 + 'word' => $word,
  78 + 'pos' => $i + 1,
  79 + 'score' => $score
  80 + );
  81 + // Bump event makes it more attractive for words to be in the
  82 + // middle of the excerpt [@todo: this needs work]
  83 + $events[] = array(
  84 + 'type' => 'bump',
  85 + 'word' => $word,
  86 + 'pos' => max(0, $i + floor(strlen($word)/2) - floor($length/2)),
  87 + 'score' => 0.5
  88 + );
  89 +
  90 + } # end while
  91 +
  92 + } # end foreach
  93 +
  94 + // If nothing is found then just truncate from the beginning
  95 + if ( empty($events) ) return substr($text, 0, $length) . $suffix;
  96 +
  97 + // We want to handle each event in the order it occurs in
  98 + // [i.e. we want an event queue]
  99 + $M = new MultiSort();
  100 + $events = $M->sortArray( $events, 'pos', 'rcmp' );
  101 +
  102 + $scores = array();
  103 + $score = 0;
  104 + $current_words = array();
  105 +
  106 + // Process each event in turn
  107 + foreach ($events as $idx => $event )
  108 + {
  109 + $thisPos = floor($event['pos']);
  110 +
  111 + $word = strtolower($event['word']);
  112 +
  113 + switch ($event['type'])
  114 + {
  115 + case 'push':
  116 + if ( ! isset( $current_words[$word] ) )
  117 + {
  118 + // First occurence of a word gets full value
  119 + $current_words[$word] = 1;
  120 + $score += $event['score'];
  121 + }
  122 + else
  123 + {
  124 + // Subsequent occurrences mean less and less
  125 + $current_words[$word]++;
  126 + $score += $event['score'] / $current_words[$word];
  127 + }
  128 + break;
  129 + case 'pop':
  130 + if ( isset( $current_words[$word] ) )
  131 + {
  132 + if ( $current_words[$word] == 1 )
  133 + {
  134 + unset( $current_words[$word] );
  135 + $score -= ($event['score']);
  136 + }
  137 + else
  138 + {
  139 + $current_words[$word]--;
  140 + if ( $current_words[$word] != 0 ) $score -= $event['score'] / $current_words[$word];
  141 + }
  142 + }
  143 + break;
  144 + case 'bump':
  145 + if (!empty($event['score'])) {
  146 + $score += $event['score'];
  147 + }
  148 + break;
  149 + default:
  150 + break;
  151 + }
  152 +
  153 + // Close enough for government work...
  154 + $score = round($score, 2);
  155 +
  156 + // Store the position/score entry
  157 + $scores[$thisPos] = $score;
  158 +
  159 + // For use with debugging
  160 + $debugWords[$thisPos] = $current_words;
  161 +
  162 + // Remove score bump
  163 + if ($event['type'] == 'bump') $score -= $event['score'];
  164 +
  165 + } # end foreach ($events as $idx => $event )
  166 +
  167 + // Calculate the best score
  168 + // Yeah, could have done this in the main event loop
  169 + // but it's better here
  170 + $bestScore = 0;
  171 + foreach ($scores as $pos => $score) if ($score > $bestScore) $bestScore = $score;
  172 +
  173 +
  174 + if ( $options['debug'] )
  175 + {
  176 + // This is really quick, really tatty debug information
  177 + // (but it works)
  178 + echo "<table>";
  179 + echo "<caption>Events</caption>";
  180 + echo "<tr><th>Pos</th><th>Type</th><th>Word</th><th>Score</th>";
  181 + foreach ($events as $event)
  182 + {
  183 + echo "<tr>";
  184 + echo "<td>{$event['pos']}</td><td>{$event['type']}</td><td>{$event['word']}</td><td>{$event['score']}</td>";
  185 + echo "</tr>";
  186 + }
  187 + echo "</table>";
  188 +
  189 + echo "<table>";
  190 + echo "<caption>Positions and their scores</caption>";
  191 + $idx = 0;
  192 + foreach ($scores as $pos => $score)
  193 + {
  194 + $excerpt = substr($text, $pos, $length);
  195 + $style = ($score == $bestScore) ? 'background: #ff7;' : '';
  196 +
  197 + echo "<tr>";
  198 + echo "<th style=\"$style\">" . $idx . "</th>";
  199 + echo "<td style=\"$style\">" . $pos . "</td>";
  200 + echo "<td style=\"$style\"><div style=\"float: left; width: 2em; margin-right: 1em; text-align right; background: #ddd\">" .
  201 + $score . "</div><code>" . str_repeat('*', $score) . "</code></td>";
  202 + echo "<td style=\"$style\"><table>";
  203 +
  204 + foreach ($debugWords[$pos] as $word => $count) echo "<tr><td>$word</td><td>$count</td></tr>";
  205 +
  206 + echo "</table></td>";
  207 + echo "<td style=\"$style\">" . (
  208 + preg_replace('/(' . implode('|', $words) . ')/i',
  209 + '<b style="border: 1px solid red;">\1</b>',
  210 + htmlentities($excerpt))
  211 + ) . "</td>";
  212 + echo "</tr>";
  213 + $idx++;
  214 + }
  215 + echo "</table>";
  216 + }
  217 +
  218 +
  219 + // Find all positions that correspond to the best score
  220 + $positions = array();
  221 + foreach ($scores as $pos => $score)
  222 + {
  223 + if ($score == $bestScore) $positions[] = $pos;
  224 + }
  225 +
  226 + if ( count( $positions ) > 1)
  227 + {
  228 + // Scores are tied => do something clever to choose one
  229 + // @todo: Actually do something clever here
  230 + $pos = $positions[0];
  231 + }
  232 + else
  233 + {
  234 + $pos = $positions[0];
  235 + }
  236 +
  237 + // Extract the excerpt from the position, (pre|ap)pend the (pre|suf)fix
  238 + $excerpt = htmlspecialchars( substr($text, $pos, $length) );
  239 +
  240 + if ( $pos > 0 ) $excerpt = $prefix . $excerpt;
  241 +
  242 + if ( $pos + $length < strlen($text) ) $excerpt .= $suffix;
  243 +
  244 + return $excerpt;
  245 +
  246 + } # end Summarizer::excerpt
  247 +
  248 +} # end Summarizer
  249 +
  250 +class MultiSort {
  251 +
  252 + function sortArray($array,$parameter,$_function)
  253 + {
  254 + return $this->_uasort($array,$_function,$parameter);
  255 + }
  256 +
  257 + function cmp ($a, $b, $p)
  258 + {
  259 + return (strcmp ($a[$p],$b[$p]));
  260 + }
  261 +
  262 + function rcmp ($a, $b, $p)
  263 + {
  264 + return -1 * ( strcmp ( $a[$p], $b[$p] ) );
  265 + }
  266 +
  267 + function _uasort( $array, $func, $param )
  268 + {
  269 + for( $i=0; $i<sizeof($array); $i++ )
  270 + {
  271 + $tmp = $i;
  272 + for ( $j=1; $j<sizeof($array); $j++ )
  273 + {
  274 + $result = $this->$func($array[$tmp],$array[$j],$param);
  275 + if ($result == -1)
  276 + {
  277 + $array = $this->arraySwap( $array, $tmp, $j );
  278 + $tmp = $j;
  279 + }
  280 + }
  281 + }
  282 + return $array;
  283 + }
  284 +
  285 + function arrayswap($arr, $src, $dst)
  286 + {
  287 + $tmp = $arr[$dst];
  288 + $arr[$dst] = $arr[$src];
  289 + $arr[$src] = $tmp;
  290 + return $arr;
  291 + }
  292 +} # end MultiSort
  293 +
  294 +/* End of file Summarizer.php */
  295 +/* Location: ./system/expressionengine/third_party/easy_search_summary/Summarizer.php */
339 EE1/system/plugins/pi.easy_search_summary.php
@@ -17,178 +17,187 @@
17 17 */
18 18
19 19 $plugin_info = array(
20   - 'pi_name' => 'Search Summary',
21   - 'pi_version' => '1.0',
22   - 'pi_author' => 'Aaron Gustafson',
23   - 'pi_author_url' => 'http://easy-designs.net/',
24   - 'pi_description' => 'Creates a summary from content, based on keywords',
25   - 'pi_usage' => Search_summary::usage()
  20 + 'pi_name' => 'Search Summary',
  21 + 'pi_version' => '1.0',
  22 + 'pi_author' => 'Aaron Gustafson',
  23 + 'pi_author_url' => 'http://easy-designs.net/',
  24 + 'pi_description' => 'Creates a summary from content, based on keywords',
  25 + 'pi_usage' => Search_summary::usage()
26 26 );
27 27
28 28 class Search_summary {
29 29
30   - var $return_data;
31   - var $keywords;
  30 + var $return_data;
  31 + var $keywords;
32 32
33   - # the HTML needed for output
34   - var $term = '<strong class="{class}">{keyword}</strong>';
35   -
36   - /**
37   - * Search_summary constructor
38   - * sets any overrides and triggers the processing
39   - *
40   - * @param str $str - the content to be parsed
41   - */
42   - function Search_summary ( $str='', $keywords=array(), $class=FALSE )
43   - {
44   -
45   - # get any overrides
46   - global $TMPL, $FNS, $PREFS, $DB;
47   -
48   - $hash = FALSE;
49   - if ( ! count( $keywords ) &&
50   - ! $hash ) $hash = ( $temp = $TMPL->fetch_param('hash') ) ? $temp : array();
51   - if ( ! $class ) $class = ( $temp = $TMPL->fetch_param('class') ) ? $temp : 'term';
52   -
53   - # find the keywords
54   - if ( $hash )
55   - {
56   - if ( strlen( $hash ) > 32 ) $hash = substr( $hash, 0, 32 );
57   - $keywords = $DB->query(
58   - "SELECT `keywords`
59   - FROM `{$PREFS->ini('db_prefix')}_search`
60   - WHERE `search_id` = '{$DB->escape_str($hash)}'"
61   - )->row['keywords'];
62   - }
63   -
64   - # manage the keywords
65   - $keywords = explode( ' ', str_replace( '+', '', $keywords ) );
66   - $i = 0;
67   - $temp = array();
68   - $mult = FALSE;
69   - $quote = FALSE;
70   - foreach ( $keywords as $k )
71   - {
72   - $length = strlen( $k );
73   - if ( strpos( $k, '-' ) === 0 )
74   - {
75   - unset( $k );
76   - }
77   - else
78   - {
79   - if ( ! $mult &&
80   - ( strpos( $k, '"' ) === 0 ||
81   - strpos( $k, "'" ) === 0 ) )
82   - {
83   - $quote = substr( $k, 0, 1 );
84   - $mult = TRUE;
85   - $temp[$i] = preg_replace( '/^["\'+]/', '', $k );
86   - }
87   - elseif ( $mult &&
88   - strpos( $k, $quote ) == $length-1 )
89   - {
90   - $mult = FALSE;
91   - $temp[$i++] .= ' ' . preg_replace( '/["\']$/', '', $k );
92   - }
93   - elseif ( $mult )
94   - {
95   - $temp[$i] .= ' ' . $k;
96   - }
97   - else
98   - {
99   - $temp[$i++] = $k;
100   - }
101   - }
102   - }
103   - $this->keywords = $temp;
104   -
105   - # manage the highlight string
106   - $this->term = $FNS->var_swap( $this->term, array( 'class' => $class ) );
107   -
108   - # Fetch string
109   - if ( empty( $str ) ) $str = strip_tags( $TMPL->tagdata );
110   -
111   - # return the processed string
112   - $this->return_data = ( ! empty( $str ) ? $this->process( $str ) : $str );
113   -
114   - } # end Search_summary constructor
  33 + # the HTML needed for output
  34 + var $term = '<{tag} class="{class}">{keyword}</{tag}>';
  35 +
115 36
116   - /**
117   - * Search_summary::process()
118   - * processes the supplied content based on the configuration
119   - *
120   - * @param str $str - the content to be parsed
121   - */
122   - function process( $str )
123   - {
124   - require_once PATH . '../scripts/classes/Summarizer.php';
125   - $S = new Summarizer();
126   - $str = $S->excerpt( $str, $this->keywords );
127   -
128   - require_once PATH . '../scripts/classes/Highlighter.php';
129   - $h = new Highlighter();
130   - foreach ( $this->keywords as $k )
131   - {
132   - $str = $h->process( $str, $k, $this->term );
133   - }
134   -
135   - return $str;
136   - } # end Search_summary::process()
137   -
138   - /**
139   - * Search_summary::usage()
140   - * Describes how the plugin is used
141   - */
142   - function usage()
143   - {
144   - ob_start(); ?>
145   -Want to add some microformats support to your site _and_ gain additional CSS hooks around your images? If so, you've come to the right place. ItFigures comes with a set of sensible default that will allow you to use it right away. By default, it looks for images that sit inside a paragraph by themselves (or, optionally, with additional text).
146   -
147   -By implementing it with no options:
148   -
149   -{exp:itfigures}{body}{/exp:itfigures}
150   -
151   -when the plugin encounters
152   -
153   -<p><img src="foo.png" alt=""/></p>
154   -
155   -it will remake that as
156   -
157   -<div class="figure"><img class="image" src="foo.png" alt="" /></div>
158   -
159   -Providing it with additional element hooks in the content allows it to build a more robust figure:
160   -
161   -<p><img src="foo.png" alt="" style="float: right;"/> <em>Photo by Aaron</em> <strong>This is a sample image</strong></p>
162   -
163   -will become
164   -
165   -<div class="figure align-right">
166   - <img class="image" src="foo.png" alt="" />
167   - <p class="credit">Photo by Aaron</p>
168   - <p class="legend">This is a sample image</p>
169   -</div>
170   -
171   -making it quite simple to quickly generate figures without having to remember the markup.
172   -
173   -If you want to customize things further, you can use any or all of the optional properties:
174   -
175   -* left_class: the class for left-alignment ("align-left" by default)
176   -* right_class: the class for right-alignment ("align-right" by default)
177   -* figure_wrap: the wrapper element for the whole figure that we should look for ("p" by default)
178   -* credit_wrap: the wrapper element for the credit ("em" by default)
179   -* legend_wrap: the wrapper element for the legend ("strong" by default)
180   -* figure_el: the element you wish to use as the figure container ("div" by default)
181   -* content_el: the element you wish to use as the text content container (empty by default)
182   -* credit_el: the element you wish to use as the credit container ("p" by default)
183   -* legend_el: the element you wish to use as the legend container ("p" by default)
184   -* output_order: the order in which you want to output the contents into the figure ("img|credit|legend" by default, "img" must come first or last, but cannot come in the middle)
  37 + /**
  38 + * Search_summary constructor
  39 + * sets any overrides and triggers the processing
  40 + *
  41 + * @param str $str - the content to be parsed
  42 + */
  43 + function Search_summary ( $str='', $keywords=array(), $html_ver=5, $class=FALSE )
  44 + {
  45 +
  46 + # get any overrides
  47 + global $TMPL, $FNS, $PREFS, $DB;
  48 +
  49 + # get the hash
  50 + $hash = FALSE;
  51 + if ( ! count( $keywords ) && ! $hash )
  52 + {
  53 + $hash = ( $temp = $TMPL->fetch_param('hash') ) ? $temp : array();
  54 + }
  55 + # determine the tag to use
  56 + if ( $temp = $TMPL->fetch_param('html_version') ) $html_ver = $temp;
  57 + $tag = $html_ver==5 ? 'mark' : 'strong';
  58 + # determine the class of the keywords
  59 + if ( ! $class ) $class = ( $temp = $TMPL->fetch_param('class') ) ? $temp : 'term';
  60 + # any alternate content?
  61 + $alternates = array();
  62 + $i = 0;
  63 + while ( $i++ < 10 )
  64 + {
  65 + if ( $temp = $TMPL->fetch_param('alternate_'.$i) ) $alternates[] = $temp;
  66 + }
  67 +
  68 + # find the keywords
  69 + if ( $hash )
  70 + {
  71 + if ( strlen( $hash ) > 32 ) $hash = substr( $hash, 0, 32 );
  72 + $keywords = $DB->query(
  73 + "SELECT `keywords`
  74 + FROM `{$PREFS->ini('db_prefix')}_search`
  75 + WHERE `search_id` = '{$DB->escape_str($hash)}'"
  76 + )->row['keywords'];
  77 + }
  78 +
  79 + # manage the keywords
  80 + $keywords = explode( ' ', str_replace( '+', '', $keywords ) );
  81 + $i = 0;
  82 + $temp = array();
  83 + $mult = FALSE;
  84 + $quote = FALSE;
  85 + foreach ( $keywords as $k )
  86 + {
  87 + $length = strlen( $k );
  88 + if ( strpos( $k, '-' ) === 0 )
  89 + {
  90 + unset( $k );
  91 + }
  92 + else
  93 + {
  94 + if ( ! $mult &&
  95 + ( strpos( $k, '"' ) === 0 ||
  96 + strpos( $k, "'" ) === 0 ) )
  97 + {
  98 + $quote = substr( $k, 0, 1 );
  99 + $mult = TRUE;
  100 + $temp[$i] = preg_replace( '/^["\'+]/', '', $k );
  101 + }
  102 + elseif ( $mult && strpos( $k, $quote ) == $length-1 )
  103 + {
  104 + $mult = FALSE;
  105 + $temp[$i++] .= ' ' . preg_replace( '/["\']$/', '', $k );
  106 + }
  107 + elseif ( $mult )
  108 + {
  109 + $temp[$i] .= ' ' . $k;
  110 + }
  111 + else
  112 + {
  113 + $temp[$i++] = $k;
  114 + }
  115 + }
  116 + }
  117 + $this->keywords = $temp;
  118 +
  119 + # build the highlight string
  120 + $this->term = $FNS->var_swap( $this->term, array( 'tag' => $tag, 'class' => $class ) );
  121 +
  122 + # try the primary text
  123 + if ( empty( $str ) ) $str = strip_tags( $TMPL->tagdata );
  124 + $str = ! empty( $str ) ? $this->process( $str ) : $str;
  125 +
  126 + if ( strpos( $str, "$tag class=\"$class\"" )===FALSE &&
  127 + count( $alternates ) )
  128 + {
  129 + foreach ( $alternates as $temp )
  130 + {
  131 + # search
  132 + $temp = $this->process( strip_tags( $temp ) );
  133 + if ( strpos( $temp, "$tag class=\"$class\"" )!==FALSE )
  134 + {
  135 + $str = $temp;
  136 + break;
  137 + }
  138 + }
  139 + }
  140 +
  141 + $this->return_data = $str;
  142 + return $this->return_data;
  143 +
  144 + } # end Search_summary constructor
  145 +
  146 + /**
  147 + * Search_summary::process()
  148 + * processes the supplied content based on the configuration
  149 + *
  150 + * @param str $str - the content to be parsed
  151 + */
  152 + function process( $str )
  153 + {
  154 + require_once 'Summarizer.php';
  155 + $S = new Summarizer();
  156 + $str = $S->excerpt( $str, $this->keywords );
  157 +
  158 + require_once 'Highlighter.php';
  159 + $h = new Highlighter();
  160 + foreach ( $this->keywords as $k )
  161 + {
  162 + $str = $h->process( $str, $k, $this->term );
  163 + }
  164 +
  165 + return $str;
  166 + } # end Search_summary::process()
  167 +
  168 + /**
  169 + * Search_summary::usage()
  170 + * Describes how the plugin is used
  171 + */
  172 + function usage()
  173 + {
  174 + ob_start(); ?>
  175 + To create nice search summaries, use the following syntax:
  176 +
  177 + {exp:search_summary hash="{segment_2}"}{content_body}{/exp:search_summary}
  178 +
  179 + Where {segment_2} is the search hash in the URL.
  180 +
  181 + By default, the plugin uses HTML5 <code>&lt;mark&gt;</code> elements to wrap the keywords found. You can override that by setting the html version:
  182 +
  183 + {exp:search_summary hash="{segment_2}" html_version="4"}{content_body}{/exp:search_summary}
  184 +
  185 + By default, each found keyword is also classified as a “term,” but you can define your own class as well:
  186 +
  187 + {exp:search_summary hash="{segment_2}" class="found"}{content_body}{/exp:search_summary}
  188 +
  189 + You can also define (in order of priority) up to 10 alternate fields you’d like to summarize if a match isn’t found in the primary tag:
  190 +
  191 + {exp:search_summary hash="{segment_2}" alternate_1="{content_sidebar}" alternate_2="{content_footer}"}{content_body}{/exp:search_summary}
185 192
186 193 <?php
187   - $buffer = ob_get_contents();
188   - ob_end_clean();
189   - return $buffer;
190   - } # end ItFigures::usage()
  194 + $buffer = ob_get_contents();
  195 + ob_end_clean();
  196 + return $buffer;
  197 + } # end Easy_search_summary::usage()
  198 +
  199 +} # end Easy_search_summary
191 200
192   -} # end ItFigures
193 201
194   -?>
  202 +/* End of file pi.easy_search_summary.php */
  203 +/* Location: ./system/expressionengine/plugins/pi.easy_search_summary.php */
16 EE2/system/expressionengine/third_party/easy_search_summary/pi.easy_search_summary.php
@@ -11,12 +11,12 @@
11 11 */
12 12
13 13 $plugin_info = array(
14   - 'pi_name' => 'Easy Search Summary',
15   - 'pi_version' => '1.0',
16   - 'pi_author' => 'Aaron Gustafson',
  14 + 'pi_name' => 'Easy Search Summary',
  15 + 'pi_version' => '1.0',
  16 + 'pi_author' => 'Aaron Gustafson',
17 17 'pi_author_url' => 'http://easy-designs.net/',
18 18 'pi_description' => 'Creates a summary from content, based on keywords',
19   - 'pi_usage' => Easy_search_summary::usage()
  19 + 'pi_usage' => Easy_search_summary::usage()
20 20 );
21 21
22 22 class Easy_search_summary {
@@ -73,14 +73,14 @@ function __construct( $str='', $keywords=array(), $html_ver=5, $class=FALSE )
73 73 if ( strlen( $hash ) > 32 ) $hash = substr( $hash, 0, 32 );
74 74 $keywords = $this->EE->db->query(
75 75 "SELECT `keywords`
76   - FROM `exp_search`
77   - WHERE `search_id` = '{$this->EE->db->escape_str($hash)}'"
  76 + FROM `exp_search`
  77 + WHERE `search_id` = '{$this->EE->db->escape_str($hash)}'"
78 78 )->row('keywords');
79 79 }
80 80
81 81 # manage the keywords
82 82 $keywords = explode( ' ', str_replace( '+', '', $keywords ) );
83   - $i = 0;
  83 + $i = 0;
84 84 $temp = array();
85 85 $mult = FALSE;
86 86 $quote = FALSE;
@@ -116,7 +116,7 @@ function __construct( $str='', $keywords=array(), $html_ver=5, $class=FALSE )
116 116 }
117 117 $this->keywords = $temp;
118 118
119   - # manage the highlight string
  119 + # build the highlight string
120 120 $this->term = $this->EE->functions->var_swap( $this->term, array( 'tag' => $tag, 'class' => $class ) );
121 121
122 122 # try the primary text
23 LICENSE
... ... @@ -0,0 +1,23 @@
  1 +Copyright (c) 2008 Easy! Designs LLC
  2 +
  3 +Permission is hereby granted, free of charge, to any person
  4 +obtaining a copy of this software and associated documentation
  5 +files (the "Software"), to deal in the Software without
  6 +restriction, including without limitation the rights to use,
  7 +copy, modify, merge, publish, distribute, sublicense, and/or
  8 +sell copies of the Software, and to permit persons to whom the
  9 +Software is furnished to do so, subject to the following
  10 +conditions:
  11 +
  12 +The above copyright notice and this permission notice shall
  13 +be included in all copies or substantial portions of the
  14 +Software.
  15 +
  16 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17 +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  18 +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19 +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  20 +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  21 +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22 +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  23 +OTHER DEALINGS IN THE SOFTWARE.
35 README.textile
Source Rendered
... ... @@ -0,0 +1,35 @@
  1 +h1. Easy Search Summary
  2 +
  3 +Creates truncated search summaries that isolate searched keywords, highlighting them as well.
  4 +
  5 +h2. Current Version
  6 +
  7 +2.0 (20 February 2011)
  8 +
  9 +h2. Requirements
  10 +
  11 +None.
  12 +
  13 +h2. License
  14 +
  15 +Easy Search Summary is distributed under the liberal MIT License.
  16 +
  17 +h2. Usage
  18 +
  19 +To create nice search summaries, use the following syntax:
  20 +
  21 +<pre>{exp:search_summary hash="{segment_2}"}{content_body}{/exp:search_summary}</pre>
  22 +
  23 +Where {segment_2} is the search hash in the URL.
  24 +
  25 +By default, the plugin uses HTML5 <code>&lt;mark&gt;</code> elements to wrap the keywords found. You can override that by setting the html version:
  26 +
  27 +<pre>{exp:search_summary hash="{segment_2}" html_version="4"}{content_body}{/exp:search_summary}</pre>
  28 +
  29 +By default, each found keyword is also classified as a “term,” but you can define your own class as well:
  30 +
  31 +<pre>{exp:search_summary hash="{segment_2}" class="found"}{content_body}{/exp:search_summary}</pre>
  32 +
  33 +You can also define (in order of priority) up to 10 alternate fields you’d like to summarize if a match isn’t found in the primary tag:
  34 +
  35 +<pre>{exp:search_summary hash="{segment_2}" alternate_1="{content_sidebar}" alternate_2="{content_footer}"}{content_body}{/exp:search_summary}</pre>

0 comments on commit 2aed006

Please sign in to comment.
Something went wrong with that request. Please try again.