<h2><?php echo link_to($doc->title, array('slug' => $doc->slug, 'module' => 'informationobject')); if (QubitTerm::PUBLICATION_STATUS_DRAFT_ID == $doc->publicationStatusId) { ?> <span class="publicationStatus">draft</span><?php } ?> </h2> <?php if ($doc->scopeAndContent) { ?> <div class="field"> <?php echo highlight_text(truncate_text($doc->scopeAndContent, 256), $sf_request->query); ?> </div> <?php } ?> <?php if ($doc->referenceCode) { ?> <?php echo render_show(__('Reference code'), render_value($doc->referenceCode)); ?> <?php } ?>
} else { $t->skip('mbstring extension is not enabled'); } // highlight_text() $t->diag('highlight_text()'); $t->is(highlight_text("This is a beautiful morning", "beautiful"), "This is a <strong class=\"highlight\">beautiful</strong> morning", 'text_highlighter() highlights a word given as its second argument'); $t->is(highlight_text("This is a beautiful morning, but also a beautiful day", "beautiful"), "This is a <strong class=\"highlight\">beautiful</strong> morning, but also a <strong class=\"highlight\">beautiful</strong> day", 'text_highlighter() highlights all occurrences of a word given as its second argument'); $t->is(highlight_text("This is a beautiful morning, but also a beautiful day", "beautiful", '<b>\\1</b>'), "This is a <b>beautiful</b> morning, but also a <b>beautiful</b> day", 'text_highlighter() takes a pattern as its third argument'); $t->is(highlight_text('', 'beautiful'), '', 'text_highlighter() returns an empty string if input is empty'); $t->is(highlight_text('', ''), '', 'text_highlighter() returns an empty string if input is empty'); $t->is(highlight_text('foobar', 'beautiful'), 'foobar', 'text_highlighter() does nothing is string to highlight is not present'); $t->is(highlight_text('foobar', ''), 'foobar', 'text_highlighter() returns input if string to highlight is not present'); $t->is(highlight_text("This is a beautiful! morning", "beautiful!"), "This is a <strong class=\"highlight\">beautiful!</strong> morning", 'text_highlighter() escapes search string to be safe in a regex'); $t->is(highlight_text("This is a beautiful! morning", "beautiful! morning"), "This is a <strong class=\"highlight\">beautiful! morning</strong>", 'text_highlighter() escapes search string to be safe in a regex'); $t->is(highlight_text("This is a beautiful? morning", "beautiful? morning"), "This is a <strong class=\"highlight\">beautiful? morning</strong>", 'text_highlighter() escapes search string to be safe in a regex'); $t->is(highlight_text("The http://www.google.com/ website is great", "http://www.google.com/"), "The <strong class=\"highlight\">http://www.google.com/</strong> website is great", 'text_highlighter() escapes search string to be safe in a regex'); // excerpt_text() $t->diag('excerpt_text()'); $t->is(excerpt_text('', 'foo', 5), '', 'text_excerpt() return an empty string if argument is empty'); $t->is(excerpt_text('foo', '', 5), '', 'text_excerpt() return an empty string if phrase is empty'); $t->is(excerpt_text("This is a beautiful morning", "beautiful", 5), "...is a beautiful morn...", 'text_excerpt() creates an excerpt of a text'); $t->is(excerpt_text("This is a beautiful morning", "this", 5), "This is a...", 'text_excerpt() creates an excerpt of a text'); $t->is(excerpt_text("This is a beautiful morning", "morning", 5), "...iful morning", 'text_excerpt() creates an excerpt of a text'); $t->is(excerpt_text("This is a beautiful morning", "morning", 5, '...', true), "... morning", 'text_excerpt() takes a fifth argument allowing excerpt on whitespace'); $t->is(excerpt_text("This is a beautiful morning", "beautiful", 5, '...', true), "... a beautiful ...", 'text_excerpt() takes a fifth argument allowing excerpt on whitespace'); $t->is(excerpt_text("This is a beautiful morning", "This", 5, '...', true), "This is ...", 'text_excerpt() takes a fifth argument allowing excerpt on whitespace'); $t->is(excerpt_text("This is a beautiful morning", "day"), '', 'text_excerpt() does nothing if the search string is not in input'); // wrap_text() $t->diag('wrap_text()'); $line = 'This is a very long line to be wrapped...'; $t->is(wrap_text($line), "This is a very long line to be wrapped...\n", 'wrap_text() wraps long lines with a default of 80');
public function search($text, $page = 1, $num = 10, $format = true) { global $scdb; $this->search->page = (int) $page; $this->search->num = (int) $num; $this->search->start = (int) ($page - 1) * $num; $s = strtr($text, array("%" => "%")); $s = safe_text(strip_tags($s)); $this->search->term = $s; $s = strtolower($s); $items = $scdb->get_results("\n\t\t\t\tSELECT transcript as text, PID, title FROM `{$scdb->comics}` WHERE `transcript` LIKE '%" . $s . "%'\n\t\t\t\tUNION SELECT title as text, PID, title FROM `{$scdb->comics}` WHERE `title` LIKE '%" . $s . "%'\n\t\t\t\tUNION SELECT info as text, PID, title FROM `{$scdb->comics}` WHERE `info` LIKE '%" . $s . "%'\n\t\t\t\t"); $this->search->num_results = $scdb->num_rows; if ($scdb->num_rows == 0) { return false; } $results = array(); $i = 0; $max = 0; foreach ($items as $item) { $n = substr_count(strtolower(strip_tags($item->text)), $s); $results[$i] = $item; $results[$i]->num = $n; $results[$i]->text = str_replace(array("\n", "\t", "\r"), ' ', $item->text); if ($n > $max) { $max = $n; } ++$i; } // an attempt at ordering by relevance function compare($x, $y) { $x = $x->num; $y = $y->num; if ($x == $y) { return 0; } elseif ($x > $y) { return -1; } else { return 1; } } usort($results, 'compare'); $count = count($results); if ($count > $num) { $results = array_slice($results, $this->search->page * $num - 1, $num, true); } if ($format === true) { $i = 0; foreach ($results as $result) { $small = smalltext($this->search->term, $result->text); $results[$i]->text = highlight_text($this->search->term, $small); ++$i; } } $this->search->results = $results; return $results; }
<div> <a href="<?php echo $comic->get_permalink($result->PID); ?> "> <?php echo ++$i; ?> . <?php echo $result->title; ?> <div><img src="<?php echo $comic->get_image_by_permalink($result->PID); ?> " alt="<?php echo highlight_text($comic->search->term, $smalltext); ?> " title="<?php echo $smalltext; ?> " /></div> </a> </div> <?php } } else { echo '<p class="search-zero">Sorry, no results!</p>'; } ?>
<div class="block"> <ul class="authors"> <?php foreach ($pager->getResults() as $author) { ?> <li> <a href="<?php echo url_for('user', array('username' => $author->getUsername())); ?> "> <span class="avatar"><?php echo avatar_for($author); ?> </span> <span class="name"><?php echo highlight_text($author->getFullName(), $form->getValue('search')); ?> </span> <?php if ($author->getPluginsCount()) { ?> <span class="badge"><?php echo $author->getPluginsCount(); ?> </span><?php } ?> </a> </li> <?php }
<?php use_helper('Text'); ?> <li <?php if (isset($i) && ($i + 1) % 3 === 0) { echo 'style="margin-right: 0"'; } ?> > <a href="<?php echo url_for('plugin', array('slug' => $plugin->getSlug())); ?> "> <span class="name"><?php echo highlight_text($plugin->getTitle(), isset($search) ? $search : ''); ?> <?php if ($plugin->isOfficial()) { echo image_tag('/images/official.gif', 'alt=Official plugin title=Official plugin'); } ?> </span> <span class="downloads" title="Downloads"><?php echo (int) $plugin->getDownloadsCount(); ?> </span> <span class="project_thumb"><?php echo thumbnail_for($plugin); ?> </span>
function bbcode_html($txt, $tinymce = 0) { $txt = str_replace("<", "<", $txt); $txt = str_replace(">", ">", $txt); $txt = str_replace(""", "\"", $txt); $txt = BadwordFilter($txt); $txt = replace($txt, $tinymce); $txt = highlight_text($txt); $txt = re_bbcode($txt); $txt = smileys($txt); $txt = glossar($txt); $txt = str_replace(""", "\"", $txt); return $txt; }