function _highlight(&$results, $word) { $words = explode(' ', $word); foreach ($results as $i => $result) { $result->text = strip_tags($result->text); $result->text = RSTicketsProHelper::shorten($result->text); foreach ($words as $word) { $pattern = '#' . preg_quote($word) . '#i'; $result->text = preg_replace($pattern, '<b class="rsticketspro_highlight">\\0</b>', $result->text); } $results[$i] = $result; } }
function trim($string, $max = 255, $more = '...') { return RSTicketsProHelper::shorten($string, $max, $more); }
function KBSearch() { header('Content-type: text/html; charset=utf-8'); $value = JRequest::getVar('filter'); if (!$value) { die; } $db = JFactory::getDBO(); $escvalue = $db->getEscaped($value); $escvalue = str_replace(' ', '%', $escvalue); $db->setQuery("SELECT * FROM #__rsticketspro_kb_content WHERE (name LIKE '%" . $escvalue . "%' OR text LIKE '%" . $escvalue . "%') AND published=1 ORDER BY category_id, ordering LIMIT 5"); $results = $db->loadObjectList(); $db->setQuery("SELECT COUNT(id) FROM #__rsticketspro_kb_content WHERE (name LIKE '%" . $escvalue . "%' OR text LIKE '%" . $escvalue . "%') AND published=1"); $total = $db->loadResult(); $showing = $total < 5 ? $total : 5; ?> <div id="rst_livesearch_total"><?php echo JText::sprintf('RST_KB_RESULTS', $total, $showing, $total); ?> <a href="javascript: void(0);" onclick="return rst_close_search();">[<?php echo JText::_('RST_CLOSE'); ?> ]</a></div> <ul id="rst_livesearch_ul"> <?php foreach ($results as $i => $result) { $name = str_replace($value, '<strong>' . $value . '</strong>', $result->name); $text = RSTicketsProHelper::shorten(str_replace($value, '<strong>' . $value . '</strong>', strip_tags($result->text))); ?> <li> <a href="javascript: void(0);" onclick="rst_update_editor(document.getElementById('rst_result_<?php echo $i; ?> ').innerHTML); return rst_close_search();"><?php echo $name; ?> </a> <p><?php echo $text; ?> </p> <div id="rst_result_<?php echo $i; ?> " style="display: none;"><?php echo $result->text; ?> </div> </li> <?php } echo '</ul>'; die; }