// search results $res_items = array(); if (!$this->error && count($this->results) > 0) { foreach ($this->results as $result) { $item = array(); $item['title'] = $result->title; $item['text'] = substr(YOOsearchHelper::stripText($result->text), 0, $char_limit); $item['text'] = substr_replace($item['text'], '...', strrpos($item['text'], ' ')); $item['url'] = JRoute::_($result->href, false); $res_items[] = $item; } } // limit result $cat_items = array_slice($cat_items, 0, $cat_limit); $res_items = array_slice($res_items, 0, $res_limit); echo YOOsearchHelper::encodeJson(array('categories' => $cat_items, 'results' => $res_items, 'count' => count($this->results), 'error' => $this->error)); } else { ?> <div class="joomla <?php echo $this->escape($this->params->get('pageclass_sfx')); ?> "> <div class="search"> <?php if ($this->params->get('show_page_title', 1)) { ?> <h1 class="pagetitle"> <?php echo $this->escape($this->params->get('page_title'));
function encodeJson($a = false) { if (is_null($a)) { return 'null'; } if ($a === false) { return 'false'; } if ($a === true) { return 'true'; } if (is_scalar($a)) { if (is_float($a)) { $a = str_replace(",", ".", strval($a)); } static $jsonReplaces = array(array("\\", "/", "\n", "\t", "\r", "\\b", "\f", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\\"')); return '"' . str_replace($jsonReplaces[0], $jsonReplaces[1], $a) . '"'; } $isList = true; for ($i = 0, reset($a); $i < count($a); $i++, next($a)) { if (key($a) !== $i) { $isList = false; break; } } $result = array(); if ($isList) { foreach ($a as $v) { $result[] = YOOsearchHelper::encodeJson($v); } return '[ ' . join(', ', $result) . ' ]'; } else { foreach ($a as $k => $v) { $result[] = YOOsearchHelper::encodeJson($k) . ': ' . YOOsearchHelper::encodeJson($v); } return '{ ' . join(', ', $result) . ' }'; } }