示例#1
0
 /**
  * Tags Search method
  *
  * The sql must return the following fields that are
  * used in a common display routine: href, title, section, created, text,
  * browsernav
  * @param string Target search string
  * @param string mathcing option, exact|any|all
  * @param string ordering option, newest|oldest|popular|alpha|category
  * @param mixed An array if restricted to areas, null if search all
  */
 function onContentSearch($text, $phrase = '', $ordering = '', $areas = null)
 {
     $searchText = $text;
     if (is_array($areas)) {
         if (!array_intersect($areas, array_keys(plgSearchTagsAreas()))) {
             return array();
         }
     }
     // load plugin params info
     $plugin = JPluginHelper::getPlugin('search', 'cedtags');
     $pluginParams = new JParameter($plugin->params);
     $limit = $pluginParams->def('search_limit', 50);
     $text = trim($text);
     if ($text == '') {
         return array();
     }
     $rows = $this->searchForText($text, $limit);
     $count = count($rows);
     for ($i = 0; $i < $count; $i++) {
         $link = 'index.php?option=com_cedtag&task=tag&tag=' . CedTagsHelper::urlTagname($rows[$i]->name);
         $rows[$i]->href = JRoute::_($link);
         $rows[$i]->section = JText::_('TAG');
     }
     $return = array();
     foreach ($rows as $key => $tag) {
         if (searchHelper::checkNoHTML($tag, $searchText, array('name', 'title', 'text'))) {
             $return[] = $tag;
         }
     }
     return $return;
 }
示例#2
0
function plgSearchEvents($text, $phrase = '', $ordering = '', $areas = null)
{
    require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_search' . DS . 'helpers' . DS . 'search.php';
    if (is_array($areas)) {
        if (!array_intersect($areas, array_keys(plgSearchEventsAreas()))) {
            return array();
        }
    }
    // load plugin params info
    $plugin =& JPluginHelper::getPlugin('search', 'events');
    $pluginParams = new JParameter($plugin->params);
    $limit = $pluginParams->def('search_limit', 50);
    $text = trim($text);
    if ($text == '') {
        return array();
    }
    $events = KService::get('com://admin/calendar.model.events')->sort('tbl.start_date')->direction('ASC')->limit($limit)->search($text)->getList();
    $return = array();
    foreach ($events as $event) {
        if (searchHelper::checkNoHTML($event, $text, array('title', 'description'))) {
            $event->text = $event->description;
            $event->origin = 'events';
            $event->href = 'index.php?option=com_calendar&view=event&id=' . $event->id . '&slug=' . $event->slug;
            $event->section = JText::_('Events');
            $return[] = $event->getData();
        }
    }
    return $return;
}
function plgSearchArticles($text, $phrase = '', $ordering = '', $areas = null)
{
    require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_search' . DS . 'helpers' . DS . 'search.php';
    if (is_array($areas)) {
        if (!array_intersect($areas, array_keys(plgSearchArticlesAreas()))) {
            return array();
        }
    }
    // load plugin params info
    $plugin =& JPluginHelper::getPlugin('search', 'articles');
    $pluginParams = new JParameter($plugin->params);
    $limit = $pluginParams->def('search_limit', 50);
    $text = trim($text);
    if ($text == '') {
        return array();
    }
    $articles = KService::get('com://admin/news.model.articles')->sort('tbl.created_on')->direction('DESC')->limit($limit)->search($text)->getList();
    $return = array();
    foreach ($articles as $article) {
        if (searchHelper::checkNoHTML($article, $text, array('title', 'text'))) {
            $article->origin = 'articles';
            $article->href = 'index.php?option=com_news&view=article&id=' . $article->id . '&slug=' . $article->slug;
            $article->section = $article->category_title;
            $return[] = $article->getData();
        }
    }
    return $return;
}
示例#4
0
 /**
  * Categories Search method
  *
  * The sql must return the following fields that are
  * used in a common display routine: href, title, section, created, text,
  * browsernav
  * @param string Target search string
  * @param string mathcing option, exact|any|all
  * @param string ordering option, newest|oldest|popular|alpha|category
  * @param mixed An array if restricted to areas, null if search all
  */
 function onSearch($text, $phrase = '', $ordering = '', $areas = null)
 {
     $db =& JFactory::getDbo();
     $user =& JFactory::getUser();
     $groups = implode(',', $user->authorisedLevels());
     $searchText = $text;
     require_once JPATH_SITE . DS . 'components' . DS . 'com_content' . DS . 'helpers' . DS . 'route.php';
     if (is_array($areas)) {
         if (!array_intersect($areas, array_keys(plgSearchCategoryAreas()))) {
             return array();
         }
     }
     // load plugin params info
     $plugin =& JPluginHelper::getPlugin('search', 'categories');
     $pluginParams = new JParameter($plugin->params);
     $limit = $pluginParams->def('search_limit', 50);
     $text = trim($text);
     if ($text == '') {
         return array();
     }
     switch ($ordering) {
         case 'alpha':
             $order = 'a.title ASC';
             break;
         case 'category':
         case 'popular':
         case 'newest':
         case 'oldest':
         default:
             $order = 'a.title DESC';
     }
     $text = $db->Quote('%' . $db->getEscaped($text, true) . '%', false);
     $query = 'SELECT a.title, a.description AS text, "" AS created, "2" AS browsernav, a.id AS catid,' . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug' . ' FROM #__categories AS a' . ' WHERE (a.title LIKE ' . $text . ' OR a.description LIKE ' . $text . ')' . ' AND a.published = 1' . ' AND a.access IN (' . $groups . ')' . ' GROUP BY a.id' . ' ORDER BY ' . $order;
     $db->setQuery($query, 0, $limit);
     $rows = $db->loadObjectList();
     $count = count($rows);
     for ($i = 0; $i < $count; $i++) {
         $rows[$i]->href = ContentHelperRoute::getCategoryRoute($rows[$i]->slug);
         $rows[$i]->section = JText::_('Category');
     }
     $return = array();
     foreach ($rows as $key => $category) {
         if (searchHelper::checkNoHTML($category, $searchText, array('name', 'title', 'text'))) {
             $return[] = $category;
         }
     }
     return $return;
 }
示例#5
0
/**
* Sections Search method
*
* The sql must return the following fields that are used in a common display
* routine: href, title, section, created, text, browsernav
* @param string Target search string
* @param string mathcing option, exact|any|all
* @param string ordering option, newest|oldest|popular|alpha|category
 * @param mixed An array if restricted to areas, null if search all
*/
function plgSearchSections($text, $phrase = '', $ordering = '', $areas = null)
{
    $db =& JFactory::getDBO();
    $user =& JFactory::getUser();
    $searchText = $text;
    require_once JPATH_SITE . DS . 'components' . DS . 'com_content' . DS . 'helpers' . DS . 'route.php';
    if (is_array($areas)) {
        if (!array_intersect($areas, array_keys(plgSearchSectionAreas()))) {
            return array();
        }
    }
    // load plugin params info
    $plugin =& JPluginHelper::getPlugin('search', 'sections');
    $pluginParams = new JParameter($plugin->params);
    $limit = $pluginParams->def('search_limit', 50);
    $text = trim($text);
    if ($text == '') {
        return array();
    }
    switch ($ordering) {
        case 'alpha':
            $order = 'a.name ASC';
            break;
        case 'category':
        case 'popular':
        case 'newest':
        case 'oldest':
        default:
            $order = 'a.name DESC';
    }
    $text = $db->Quote('%' . $db->getEscaped($text, true) . '%', false);
    $query = 'SELECT a.title AS title, a.description AS text, a.name, ' . ' "" AS created,' . ' "2" AS browsernav,' . ' a.id AS secid' . ' FROM #__sections AS a' . ' WHERE ( a.name LIKE ' . $text . ' OR a.title LIKE ' . $text . ' OR a.description LIKE ' . $text . ' )' . ' AND a.published = 1' . ' AND a.access <= ' . (int) $user->get('aid') . ' GROUP BY a.id' . ' ORDER BY ' . $order;
    $db->setQuery($query, 0, $limit);
    $rows = $db->loadObjectList();
    $count = count($rows);
    for ($i = 0; $i < $count; $i++) {
        $rows[$i]->href = ContentHelperRoute::getSectionRoute($rows[$i]->secid);
        $rows[$i]->section = JText::_('Section');
    }
    $return = array();
    foreach ($rows as $key => $section) {
        if (searchHelper::checkNoHTML($section, $searchText, array('name', 'title', 'text'))) {
            $return[] = $section;
        }
    }
    return $return;
}
示例#6
0
 /**
  * Weblink Search method
  *
  * The sql must return the following fields that are used in a common display
  * routine: href, title, section, created, text, browsernav
  * @param string Target search string
  * @param string mathcing option, exact|any|all
  * @param string ordering option, newest|oldest|popular|alpha|category
  * @param mixed An array if the search it to be restricted to areas, null if search all
  */
 function onSearch($text, $phrase = '', $ordering = '', $areas = null)
 {
     $db =& JFactory::getDbo();
     $user =& JFactory::getUser();
     $groups = implode(',', $user->authorisedLevels());
     $searchText = $text;
     require_once JPATH_SITE . '/components/com_weblinks/router.php';
     if (is_array($areas)) {
         if (!array_intersect($areas, array_keys(plgSearchWeblinksAreas()))) {
             return array();
         }
     }
     // load plugin params info
     $plugin =& JPluginHelper::getPlugin('search', 'weblinks');
     $pluginParams = new JParameter($plugin->params);
     $limit = $pluginParams->def('search_limit', 50);
     $text = trim($text);
     if ($text == '') {
         return array();
     }
     $section = JText::_('WEB_LINKS');
     $wheres = array();
     switch ($phrase) {
         case 'exact':
             $text = $db->Quote('%' . $db->getEscaped($text, true) . '%', false);
             $wheres2 = array();
             $wheres2[] = 'a.url LIKE ' . $text;
             $wheres2[] = 'a.description LIKE ' . $text;
             $wheres2[] = 'a.title LIKE ' . $text;
             $where = '(' . implode(') OR (', $wheres2) . ')';
             break;
         case 'all':
         case 'any':
         default:
             $words = explode(' ', $text);
             $wheres = array();
             foreach ($words as $word) {
                 $word = $db->Quote('%' . $db->getEscaped($word, true) . '%', false);
                 $wheres2 = array();
                 $wheres2[] = 'a.url LIKE ' . $word;
                 $wheres2[] = 'a.description LIKE ' . $word;
                 $wheres2[] = 'a.title LIKE ' . $word;
                 $wheres[] = implode(' OR ', $wheres2);
             }
             $where = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wheres) . ')';
             break;
     }
     switch ($ordering) {
         case 'oldest':
             $order = 'a.date ASC';
             break;
         case 'popular':
             $order = 'a.hits DESC';
             break;
         case 'alpha':
             $order = 'a.title ASC';
             break;
         case 'category':
             $order = 'b.title ASC, a.title ASC';
             break;
         case 'newest':
         default:
             $order = 'a.date DESC';
     }
     $query = 'SELECT a.title AS title, a.description AS text, a.date AS created, a.url, ' . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug, ' . ' CASE WHEN CHAR_LENGTH(b.alias) THEN CONCAT_WS(\':\', b.id, b.alias) ELSE b.id END as catslug, ' . ' CONCAT_WS(" / ", ' . $db->Quote($section) . ', b.title) AS section,' . ' "1" AS browsernav' . ' FROM #__weblinks AS a' . ' INNER JOIN #__categories AS b ON b.id = a.catid' . ' WHERE (' . $where . ')' . ' AND a.state = 1' . ' AND b.published = 1' . ' AND b.access IN (' . $groups . ')' . ' ORDER BY ' . $order;
     $db->setQuery($query, 0, $limit);
     $rows = $db->loadObjectList();
     foreach ($rows as $key => $row) {
         $rows[$key]->href = WeblinksRoute::weblink($row->slug, $row->catslug);
     }
     $return = array();
     foreach ($rows as $key => $weblink) {
         if (searchHelper::checkNoHTML($weblink, $searchText, array('url', 'text', 'title'))) {
             $return[] = $weblink;
         }
     }
     return $return;
 }
示例#7
0
 /**
  * Content Search method
  * The sql must return the following fields that are used in a common display
  * routine: href, title, section, created, text, browsernav
  * @param string Target search string
  * @param string mathcing option, exact|any|all
  * @param string ordering option, newest|oldest|popular|alpha|category
  * @param mixed An array if the search it to be restricted to areas, null if search all
  */
 function onContentSearch($text, $phrase = '', $ordering = '', $areas = null)
 {
     $db = JFactory::getDbo();
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     $groups = implode(',', $user->getAuthorisedViewLevels());
     $tag = JFactory::getLanguage()->getTag();
     require_once JPATH_SITE . '/components/com_jdownloads/helpers/route.php';
     require_once JPATH_ADMINISTRATOR . '/components/com_search/helpers/search.php';
     $searchText = $text;
     if (is_array($areas)) {
         if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) {
             return array();
         }
     }
     $limit = $this->params->def('search_limit', 50);
     $nullDate = $db->getNullDate();
     $date = JFactory::getDate();
     $now = $date->toSql();
     $text = trim($text);
     if ($text == '') {
         return array();
     }
     $wheres = array();
     switch ($phrase) {
         case 'exact':
             $text = $db->Quote('%' . $db->escape($text, true) . '%', false);
             $wheres2 = array();
             $wheres2[] = 'a.file_title LIKE ' . $text;
             $wheres2[] = 'a.description LIKE ' . $text;
             $wheres2[] = 'a.description_long LIKE ' . $text;
             $wheres2[] = 'a.changelog LIKE ' . $text;
             $wheres2[] = 'a.author LIKE ' . $text;
             $wheres2[] = 'a.metakey LIKE ' . $text;
             $wheres2[] = 'a.metadesc LIKE ' . $text;
             $where = '(' . implode(') OR (', $wheres2) . ')';
             break;
         case 'all':
         case 'any':
         default:
             $words = explode(' ', $text);
             $wheres = array();
             foreach ($words as $word) {
                 $word = $db->Quote('%' . $db->escape($word, true) . '%', false);
                 $wheres2 = array();
                 $wheres2[] = 'a.file_title LIKE ' . $word;
                 $wheres2[] = 'a.description LIKE ' . $word;
                 $wheres2[] = 'a.description_long LIKE ' . $word;
                 $wheres2[] = 'a.changelog LIKE ' . $word;
                 $wheres2[] = 'a.author LIKE ' . $word;
                 $wheres2[] = 'a.metakey LIKE ' . $word;
                 $wheres2[] = 'a.metadesc LIKE ' . $word;
                 $wheres[] = implode(' OR ', $wheres2);
             }
             $where = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wheres) . ')';
             break;
     }
     $morder = '';
     switch ($ordering) {
         case 'oldest':
             $order = 'a.date_added ASC';
             break;
         case 'popular':
             $order = 'a.downloads DESC';
             break;
         case 'alpha':
             $order = 'a.file_title ASC';
             break;
         case 'category':
             $order = 'c.title ASC, a.title ASC';
             $morder = 'a.title ASC';
             break;
         case 'newest':
         default:
             $order = 'a.date_added DESC';
             break;
     }
     $uncategorised = JText::_('PLG_SEARCH_JDOWNLOADS_UNCATEGORISED');
     $rows = array();
     $query = $db->getQuery(true);
     // search downloads
     if ($limit > 0) {
         $query->clear();
         //sqlsrv changes
         $case_when = ' CASE WHEN ';
         $case_when .= $query->charLength('a.file_alias');
         $case_when .= ' THEN ';
         $a_id = $query->castAsChar('a.file_id');
         $case_when .= $query->concatenate(array($a_id, 'a.file_alias'), ':');
         $case_when .= ' ELSE ';
         $case_when .= $a_id . ' END as slug';
         $case_when1 = ' CASE WHEN ';
         $case_when1 .= $query->charLength('c.alias');
         $case_when1 .= ' THEN ';
         $c_id = $query->castAsChar('c.id');
         $case_when1 .= $query->concatenate(array($c_id, 'c.alias'), ':');
         $case_when1 .= ' ELSE ';
         $case_when1 .= $c_id . ' END as catslug';
         $query->select('a.file_title AS title, a.metadesc, a.metakey, a.date_added AS created, a.language, a.author, a.url_download, a.extern_file, a.password, a.license_agree, a.other_file_id');
         $query->select($query->concatenate(array('a.description', 'a.description_long')) . ' AS text');
         $query->select('CASE c.title WHEN \'root\' THEN ' . $db->Quote($uncategorised) . ' ELSE c.title END AS section, ' . $case_when . ',' . $case_when1 . ', ' . '\'2\' AS browsernav');
         $query->from('#__jdownloads_files AS a');
         $query->innerJoin('#__jdownloads_categories AS c ON c.id = a.cat_id');
         $query->where('(' . $where . ')' . 'AND a.published = 1 AND c.published = 1 AND a.access IN (' . $groups . ') ' . 'AND c.access IN (' . $groups . ') ' . 'AND (a.publish_from = ' . $db->Quote($nullDate) . ' OR a.publish_from <= ' . $db->Quote($now) . ') ' . 'AND (a.publish_to = ' . $db->Quote($nullDate) . ' OR a.publish_to >= ' . $db->Quote($now) . ')');
         $query->group('a.file_id, a.file_title, a.metadesc, a.metakey, a.date_added, a.description, a.description_long, c.title, a.file_alias, c.alias, c.id, a.author');
         $query->order($order);
         // Filter by language
         if ($app->isSite() && $app->getLanguageFilter()) {
             $query->where('a.language in (' . $db->Quote($tag) . ',' . $db->Quote('*') . ')');
             $query->where('c.language in (' . $db->Quote($tag) . ',' . $db->Quote('*') . ')');
         }
         $db->setQuery($query, 0, $limit);
         $list = $db->loadObjectList();
         $limit -= count($list);
         if (isset($list)) {
             $jlistConfig = JDHelper::buildjlistConfig();
             $user_rules = JDHelper::getUserRules();
             foreach ($list as $key => $item) {
                 $direct_download = $jlistConfig['direct.download'];
                 if (!$item->url_download && !$item->extern_file && !$item->other_file_id || $item->password || $item->license_agree || $user_rules->view_captcha) {
                     // this download is a simple document without a file so we can not use 'direct' download option
                     // or we need the summary page for password, captcha or license agree
                     $direct_download = 0;
                 }
                 if ($jlistConfig['view.detailsite']) {
                     // we must link to the details page
                     $list[$key]->href = JDownloadsHelperRoute::getDownloadRoute($item->slug, $item->catslug, $item->language);
                 } else {
                     if ($direct_download) {
                         // we must start the download process directly
                         $list[$key]->href = JRoute::_('index.php?option=com_jdownloads&amp;task=download.send&amp;id=' . (int) $item->slug . '&amp;catid=' . (int) $item->catslug . '&amp;m=0');
                     } else {
                         if (!$item->url_download && !$item->extern_file && !$item->other_file_id) {
                             // Download is only a simple document without a file so we must link to the details page
                             $list[$key]->href = JDownloadsHelperRoute::getDownloadRoute($item->slug, $item->catslug, $item->language);
                         } else {
                             // we must link to the summary page
                             $list[$key]->href = JRoute::_('index.php?option=com_jdownloads&amp;view=summary&amp;id=' . $item->slug . '&amp;catid=' . (int) $item->catslug);
                         }
                     }
                 }
             }
         }
         $rows[] = $list;
     }
     $results = array();
     if (count($rows)) {
         foreach ($rows as $row) {
             $new_row = array();
             foreach ($row as $key => $download) {
                 if (searchHelper::checkNoHTML($download, $searchText, array('text', 'title', 'metadesc', 'metakey', 'author'))) {
                     $new_row[] = $download;
                 }
             }
             $results = array_merge($results, (array) $new_row);
         }
     }
     return $results;
 }
示例#8
0
/**
 * Content Search method
 * The sql must return the following fields that are used in a common display
 * routine: href, title, section, created, text, browsernav
 * @param string Target search string
 * @param string mathcing option, exact|any|all
 * @param string ordering option, newest|oldest|popular|alpha|category
 * @param mixed An array if the search it to be restricted to areas, null if search all
 */
function plgSearchContent($text, $phrase = '', $ordering = '', $areas = null)
{
    global $mainframe;
    $db =& JFactory::getDBO();
    $user =& JFactory::getUser();
    require_once JPATH_SITE . DS . 'components' . DS . 'com_content' . DS . 'helpers' . DS . 'route.php';
    require_once JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_search' . DS . 'helpers' . DS . 'search.php';
    $searchText = $text;
    if (is_array($areas)) {
        if (!array_intersect($areas, array_keys(plgSearchContentAreas()))) {
            return array();
        }
    }
    // load plugin params info
    $plugin =& JPluginHelper::getPlugin('search', 'content');
    $pluginParams = new JParameter($plugin->params);
    $sContent = $pluginParams->get('search_content', 1);
    $sUncategorised = $pluginParams->get('search_uncategorised', 1);
    $sArchived = $pluginParams->get('search_archived', 1);
    $limit = $pluginParams->def('search_limit', 50);
    $nullDate = $db->getNullDate();
    $date =& JFactory::getDate();
    $now = $date->toMySQL();
    $text = trim($text);
    if ($text == '') {
        return array();
    }
    $wheres = array();
    switch ($phrase) {
        case 'exact':
            $text = $db->Quote('%' . $db->getEscaped($text, true) . '%', false);
            $wheres2 = array();
            $wheres2[] = 'a.title LIKE ' . $text;
            $wheres2[] = 'a.introtext LIKE ' . $text;
            $wheres2[] = 'a.`fulltext` LIKE ' . $text;
            $wheres2[] = 'a.metakey LIKE ' . $text;
            $wheres2[] = 'a.metadesc LIKE ' . $text;
            $where = '(' . implode(') OR (', $wheres2) . ')';
            break;
        case 'all':
        case 'any':
        default:
            $words = explode(' ', $text);
            $wheres = array();
            foreach ($words as $word) {
                $word = $db->Quote('%' . $db->getEscaped($word, true) . '%', false);
                $wheres2 = array();
                $wheres2[] = 'a.title LIKE ' . $word;
                $wheres2[] = 'a.introtext LIKE ' . $word;
                $wheres2[] = 'a.`fulltext` LIKE ' . $word;
                $wheres2[] = 'a.metakey LIKE ' . $word;
                $wheres2[] = 'a.metadesc LIKE ' . $word;
                $wheres[] = implode(' OR ', $wheres2);
            }
            $where = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wheres) . ')';
            break;
    }
    $morder = '';
    switch ($ordering) {
        case 'oldest':
            $order = 'a.created ASC';
            break;
        case 'popular':
            $order = 'a.hits DESC';
            break;
        case 'alpha':
            $order = 'a.title ASC';
            break;
        case 'category':
            $order = 'b.title ASC, a.title ASC';
            $morder = 'a.title ASC';
            break;
        case 'newest':
        default:
            $order = 'a.created DESC';
            break;
    }
    $rows = array();
    // search articles
    if ($sContent && $limit > 0) {
        $query = 'SELECT a.title AS title, a.metadesc, a.metakey,' . ' a.created AS created,' . ' CONCAT(a.introtext, a.`fulltext`) AS text,' . ' CONCAT_WS( "/", u.title, b.title ) AS section,' . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug,' . ' CASE WHEN CHAR_LENGTH(b.alias) THEN CONCAT_WS(":", b.id, b.alias) ELSE b.id END as catslug,' . ' u.id AS sectionid,' . ' "2" AS browsernav' . ' FROM #__content AS a' . ' INNER JOIN #__categories AS b ON b.id=a.catid' . ' INNER JOIN #__sections AS u ON u.id = a.sectionid' . ' WHERE ( ' . $where . ' )' . ' AND a.state = 1' . ' AND u.published = 1' . ' AND b.published = 1' . ' AND a.access <= ' . (int) $user->get('aid') . ' AND b.access <= ' . (int) $user->get('aid') . ' AND u.access <= ' . (int) $user->get('aid') . ' AND ( a.publish_up = ' . $db->Quote($nullDate) . ' OR a.publish_up <= ' . $db->Quote($now) . ' )' . ' AND ( a.publish_down = ' . $db->Quote($nullDate) . ' OR a.publish_down >= ' . $db->Quote($now) . ' )' . ' GROUP BY a.id' . ' ORDER BY ' . $order;
        $db->setQuery($query, 0, $limit);
        $list = $db->loadObjectList();
        $limit -= count($list);
        if (isset($list)) {
            foreach ($list as $key => $item) {
                $list[$key]->href = ContentHelperRoute::getArticleRoute($item->slug, $item->catslug, $item->sectionid);
            }
        }
        $rows[] = $list;
    }
    // search uncategorised content
    if ($sUncategorised && $limit > 0) {
        $query = 'SELECT id, a.title AS title, a.created AS created, a.metadesc, a.metakey, ' . ' a.introtext AS text,' . ' "2" as browsernav, "' . $db->Quote(JText::_('Uncategorised Content')) . '" AS section' . ' FROM #__content AS a' . ' WHERE (' . $where . ')' . ' AND a.state = 1' . ' AND a.access <= ' . (int) $user->get('aid') . ' AND a.sectionid = 0' . ' AND a.catid = 0' . ' AND ( a.publish_up = ' . $db->Quote($nullDate) . ' OR a.publish_up <= ' . $db->Quote($now) . ' )' . ' AND ( a.publish_down = ' . $db->Quote($nullDate) . ' OR a.publish_down >= ' . $db->Quote($now) . ' )' . ' ORDER BY ' . ($morder ? $morder : $order);
        $db->setQuery($query, 0, $limit);
        $list2 = $db->loadObjectList();
        $limit -= count($list2);
        if (isset($list2)) {
            foreach ($list2 as $key => $item) {
                $list2[$key]->href = ContentHelperRoute::getArticleRoute($item->id);
            }
        }
        $rows[] = $list2;
    }
    // search archived content
    if ($sArchived && $limit > 0) {
        $searchArchived = JText::_('Archived');
        $query = 'SELECT a.title AS title, a.metadesc, a.metakey,' . ' a.created AS created,' . ' a.introtext AS text,' . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug,' . ' CASE WHEN CHAR_LENGTH(b.alias) THEN CONCAT_WS(":", b.id, b.alias) ELSE b.id END as catslug,' . ' u.id AS sectionid,' . ' "2" AS browsernav' . ' FROM #__content AS a' . ' INNER JOIN #__categories AS b ON b.id=a.catid AND b.access <= ' . $user->get('gid') . ' INNER JOIN #__sections AS u ON u.id = a.sectionid' . ' WHERE ( ' . $where . ' )' . ' AND a.state = -1' . ' AND u.published = 1' . ' AND b.published = 1' . ' AND a.access <= ' . (int) $user->get('aid') . ' AND b.access <= ' . (int) $user->get('aid') . ' AND u.access <= ' . (int) $user->get('aid') . ' AND ( a.publish_up = ' . $db->Quote($nullDate) . ' OR a.publish_up <= ' . $db->Quote($now) . ' )' . ' AND ( a.publish_down = ' . $db->Quote($nullDate) . ' OR a.publish_down >= ' . $db->Quote($now) . ' )' . ' ORDER BY ' . $order;
        $db->setQuery($query, 0, $limit);
        $list3 = $db->loadObjectList();
        if (isset($list3)) {
            foreach ($list3 as $key => $item) {
                $list3[$key]->href = ContentHelperRoute::getArticleRoute($item->slug, $item->catslug, $item->sectionid);
            }
        }
        $rows[] = $list3;
    }
    $results = array();
    if (count($rows)) {
        foreach ($rows as $row) {
            $new_row = array();
            foreach ($row as $key => $article) {
                if (searchHelper::checkNoHTML($article, $searchText, array('text', 'title', 'metadesc', 'metakey'))) {
                    $new_row[] = $article;
                }
            }
            $results = array_merge($results, (array) $new_row);
        }
    }
    return $results;
}
示例#9
0
 function onContentSearch($text, $phrase = '', $ordering = '', $areas = null)
 {
     $app = JFactory::getApplication();
     $db = JFactory::getDBO();
     $searchText = $text;
     require_once JPATH_SITE . DS . 'components' . DS . 'com_djcatalog2' . DS . 'helpers' . DS . 'route.php';
     if (is_array($areas)) {
         if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) {
             return array();
         }
     }
     // load plugin params info
     $plugin = JPluginHelper::getPlugin('search', 'djcatalog2');
     $pluginParams = $this->params;
     $limit = $pluginParams->def('search_limit', 50);
     $text = trim($text);
     if ($text == '') {
         return array();
     }
     $query = $db->getQuery(true);
     $query->select('image.fullpath AS image, i.id AS id, i.alias as alias, i.name AS title, i.intro_desc AS intro, i.created as created, c.id AS catid, c.name AS category, c.alias as catalias, i.description as text, i.metakey as metakey, i.metadesc as metadesc, p.name as producer_name, "2" as browsernav');
     $query->from('#__djc2_items AS i');
     $where = '';
     $textSearch = array();
     switch ($phrase) {
         case 'exact':
             $textSearch[] = 'LOWER(i.name) LIKE ' . $db->quote('%' . $db->escape($text, true) . '%', false);
             $textSearch[] = 'LOWER(i.description) LIKE ' . $db->quote('%' . $db->escape($text, true) . '%', false);
             $textSearch[] = 'LOWER(i.intro_desc) LIKE ' . $db->quote('%' . $db->escape($text, true) . '%', false);
             $textSearch[] = 'LOWER(i.metadesc) LIKE ' . $db->quote('%' . $db->escape($text, true) . '%', false);
             $textSearch[] = 'LOWER(i.metakey) LIKE ' . $db->quote('%' . $db->escape($text, true) . '%', false);
             $textSearch[] = 'LOWER(c.name) LIKE ' . $db->quote('%' . $db->escape($text, true) . '%', false);
             $textSearch[] = 'LOWER(p.name) LIKE ' . $db->quote('%' . $db->escape($text, true) . '%', false);
             $optionsSearch = ' select i.id ' . ' from #__djc2_items as i ' . ' inner join #__djc2_items_extra_fields_values_int as efv on efv.item_id = i.id' . ' inner join #__djc2_items_extra_fields as ef on ef.id = efv.field_id and ef.searchable = 1 ' . ' inner join #__djc2_items_extra_fields_options as efo on efo.id = efv.value and lower(efo.value) like ' . $db->quote('%' . $db->escape($text, true) . '%', false) . ' union ' . 'select i.id ' . ' from #__djc2_items as i ' . ' inner join #__djc2_items_extra_fields_values_text as efv on efv.item_id = i.id' . ' inner join #__djc2_items_extra_fields as ef on ef.id = efv.field_id and ef.searchable = 1 and lower(efv.value) like ' . $db->quote('%' . $db->escape($text, true) . '%', false);
             $query->join('LEFT', '(' . $optionsSearch . ') AS customattribute_search ON customattribute_search.id = i.id');
             $textSearch[] = 'i.id = customattribute_search.id';
             $where = ' ( ' . implode(' OR ', $textSearch) . ' ) ';
             break;
         case 'all':
         case 'any':
         default:
             $words = explode(' ', $text);
             $textSearches = array();
             foreach ($words as $k => $word) {
                 $textSearch = array();
                 $textSearch[] = 'LOWER(i.name) LIKE ' . $db->quote('%' . $db->escape($word, true) . '%', false);
                 $textSearch[] = 'LOWER(i.description) LIKE ' . $db->quote('%' . $db->escape($word, true) . '%', false);
                 $textSearch[] = 'LOWER(i.intro_desc) LIKE ' . $db->quote('%' . $db->escape($word, true) . '%', false);
                 $textSearch[] = 'LOWER(i.metadesc) LIKE ' . $db->quote('%' . $db->escape($word, true) . '%', false);
                 $textSearch[] = 'LOWER(i.metakey) LIKE ' . $db->quote('%' . $db->escape($word, true) . '%', false);
                 $textSearch[] = 'LOWER(c.name) LIKE ' . $db->quote('%' . $db->escape($word, true) . '%', false);
                 $textSearch[] = 'LOWER(p.name) LIKE ' . $db->quote('%' . $db->escape($word, true) . '%', false);
                 $optionsSearch = ' select i.id ' . ' from #__djc2_items as i ' . ' inner join #__djc2_items_extra_fields_values_int as efv on efv.item_id = i.id' . ' inner join #__djc2_items_extra_fields as ef on ef.id = efv.field_id and ef.searchable = 1 ' . ' inner join #__djc2_items_extra_fields_options as efo on efo.id = efv.value and lower(efo.value) like ' . $db->quote('%' . $db->escape($word, true) . '%', false) . ' union ' . 'select i.id ' . ' from #__djc2_items as i ' . ' inner join #__djc2_items_extra_fields_values_text as efv on efv.item_id = i.id' . ' inner join #__djc2_items_extra_fields as ef on ef.id = efv.field_id and ef.searchable = 1 and lower(efv.value) like ' . $db->quote('%' . $db->escape($word, true) . '%', false);
                 $query->join('LEFT', '(' . $optionsSearch . ') AS customattribute_search_' . $k . ' ON customattribute_search_' . $k . '.id = i.id');
                 $textSearch[] = 'i.id = customattribute_search_' . $k . '.id';
                 $textSearches[] = implode(' OR ', $textSearch);
             }
             $where = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $textSearches) . ')';
             break;
     }
     $query->join('left', '#__djc2_categories AS c ON c.id = i.cat_id');
     $query->join('left', '#__djc2_producers AS p ON p.id = i.producer_id');
     $query->join('left', '#__djc2_images AS image ON image.item_id = i.id');
     $lang = JFactory::getLanguage();
     $query->where($where . " AND i.published=1 AND c.published=1 AND image.ordering = 1 AND i.language = '{$lang->getTag()}'");
     $query->group('i.id');
     switch ($ordering) {
         case 'alpha':
             $order = 'i.name ASC';
             break;
         case 'category':
         case 'popular':
         case 'newest':
         case 'oldest':
         default:
             $order = 'i.name DESC';
     }
     $query->order($order);
     $db->setQuery($query, 0, $limit);
     //echo str_replace('#_','jos',$query);
     $rows = $db->loadObjectList();
     $count = count($rows);
     for ($i = 0; $i < $count; $i++) {
         $rows[$i]->href = JRoute::_(DJCatalogHelperRoute::getItemRoute($rows[$i]->id . ':' . $rows[$i]->alias, $rows[$i]->catid . ':' . $rows[$i]->catalias));
         $rows[$i]->section = JText::_('PLG_SEARCH_DJCATALOG2_DJCATALOGITEMS') . ': ' . $rows[$i]->category;
         // because extra attributes are also taken into accout, we have to trick checkNoHTML function
         $rows[$i]->__term = $searchText;
     }
     $return = array();
     foreach ($rows as $key => $section) {
         if (searchHelper::checkNoHTML($section, $searchText, array('title', 'text', 'intro', 'metadesc', 'metakey', 'producer_name', '__term'))) {
             $return[] = $section;
         }
     }
     return $return;
 }
示例#10
0
 /**
  * Content Search method
  * The sql must return the following fields that are used in a common display
  * routine: href, title, section, created, text, browsernav
  * @param string Target search string
  * @param string mathcing option, exact|any|all
  * @param string ordering option, newest|oldest|popular|alpha|category
  * @param mixed An array if restricted to areas, null if search all
  */
 function onContentSearch($text, $phrase = '', $ordering = '', $areas = null)
 {
     $db = JFactory::getDbo();
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     // Get language
     $cntLang = substr(JFactory::getLanguage()->getTag(), 0, 2);
     // Current Content language (Can be natively switched in J2.5)
     $urlLang = JRequest::getWord('lang', '');
     // Language from URL (Can be switched via Joomfish in J1.5)
     $lang = FLEXI_J16GE || empty($urlLang) ? $cntLang : $urlLang;
     // COMPONENT PARAMETERS
     $cparams = $app->isSite() ? $app->getParams('com_flexicontent') : JComponentHelper::getParams('com_flexicontent');
     if (!defined('FLEXI_SECTION')) {
         define('FLEXI_SECTION', $cparams->get('flexi_section'));
     }
     // define section
     $show_noauth = $cparams->get('show_noauth', 0);
     // items the user cannot see ...
     $searchText = $text;
     $AllAreas = array_keys($this->_getAreas());
     $AllTypes = array_keys($this->_getContentTypes());
     if (is_array($areas)) {
         // search in selected areas
         $searchAreas = array_intersect($areas, $AllAreas);
         $searchTypes = array_intersect($areas, $AllTypes);
         if (!$searchAreas && !$searchTypes) {
             return array();
         }
         if (!$searchAreas) {
             $searchAreas = $AllAreas;
         }
         if (!$searchTypes) {
             $searchTypes = $AllTypes;
         }
     } else {
         // search in all avaliable areas if no selected ones
         $searchAreas = $AllAreas;
         $searchTypes = $AllTypes;
     }
     foreach ($searchTypes as $id => $tipe) {
         $searchTypes[$id] = preg_replace('/\\D/', '', $tipe);
     }
     $types = implode(', ', $searchTypes);
     $filter_lang = $this->params->def('filter_lang', 1);
     $limit = $this->params->def('search_limit', 50);
     // Dates for publish up & down items
     $date = JFactory::getDate();
     $nowDate = FLEXI_J16GE ? $date->toSql() : $date->toMySQL();
     $nullDate = $db->getNullDate();
     $text = trim($text);
     if ($text == '') {
         return array();
     }
     $wheres = array();
     switch ($phrase) {
         case 'exact':
             $text = FLEXI_J16GE ? $db->escape($text, true) : $db->getEscaped($text, true);
             $text = $db->Quote('%' . $text . '%', false);
             $wheres2 = array();
             if (in_array('FlexisearchTitle', $searchAreas)) {
                 $wheres2[] = 'i.title LIKE ' . $text;
             }
             if (in_array('FlexisearchDesc', $searchAreas)) {
                 $wheres2[] = 'i.introtext LIKE ' . $text;
                 $wheres2[] = 'i.fulltext LIKE ' . $text;
             }
             if (in_array('FlexisearchMeta', $searchAreas)) {
                 $wheres2[] = 'i.metakey LIKE ' . $text;
                 $wheres2[] = 'i.metadesc LIKE ' . $text;
             }
             if (in_array('FlexisearchFields', $searchAreas)) {
                 $wheres2[] = "f.field_type IN ('text','textselect') AND f.issearch=1 AND fir.value LIKE " . $text;
             }
             if (in_array('FlexisearchTags', $searchAreas)) {
                 $wheres2[] = 't.name LIKE ' . $text;
             }
             if (count($wheres2)) {
                 $where = '(' . implode(') OR (', $wheres2) . ')';
             }
             break;
         case 'all':
         case 'any':
         default:
             $words = explode(' ', $text);
             $wheres = array();
             foreach ($words as $word) {
                 $word = FLEXI_J16GE ? $db->escape($word, true) : $db->getEscaped($word, true);
                 $word = $db->Quote('%' . $word . '%', false);
                 $wheres2 = array();
                 if (in_array('FlexisearchTitle', $searchAreas)) {
                     $wheres2[] = 'i.title LIKE ' . $word;
                 }
                 if (in_array('FlexisearchDesc', $searchAreas)) {
                     $wheres2[] = 'i.introtext LIKE ' . $word;
                     $wheres2[] = 'i.fulltext LIKE ' . $word;
                 }
                 if (in_array('FlexisearchMeta', $searchAreas)) {
                     $wheres2[] = 'i.metakey LIKE ' . $word;
                     $wheres2[] = 'i.metadesc LIKE ' . $word;
                 }
                 if (in_array('FlexisearchFields', $searchAreas)) {
                     $wheres2[] = "f.field_type IN ('text','textselect') AND f.issearch=1 AND fir.value LIKE " . $word;
                 }
                 if (in_array('FlexisearchTags', $searchAreas)) {
                     $wheres2[] = 't.name LIKE ' . $word;
                 }
                 if (count($wheres2)) {
                     $wheres[] = '(' . implode(') OR (', $wheres2) . ')';
                 }
             }
             if (count($wheres)) {
                 $where = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wheres) . ')';
             }
             break;
     }
     if (!@$where) {
         return array();
     }
     //if ( empty($where) ) $where = '1';
     switch ($ordering) {
         //case 'relevance': $order = ' ORDER BY score DESC, i.title ASC'; break;
         case 'oldest':
             $order = 'i.created ASC';
             break;
         case 'popular':
             $order = 'i.hits DESC';
             break;
         case 'alpha':
             $order = 'i.title ASC';
             break;
         case 'category':
             $order = 'c.title ASC, i.title ASC';
             break;
         case 'newest':
             $order = 'i.created DESC';
             break;
         default:
             $order = 'i.created DESC';
             break;
     }
     // ****************************************************************************************
     // Create JOIN clause and WHERE clause part for filtering by current (viewing) access level
     // ****************************************************************************************
     $joinaccess = '';
     $andaccess = '';
     $select_access = '';
     // Extra access columns for main category and content type (item access will be added as 'access')
     $select_access .= ',  c.access as category_access, ty.access as type_access';
     if (!$show_noauth) {
         // User not allowed to LIST unauthorized items
         if (FLEXI_J16GE) {
             $aid_arr = JAccess::getAuthorisedViewLevels($user->id);
             $aid_list = implode(",", $aid_arr);
             $andaccess .= ' AND ty.access IN (0,' . $aid_list . ')';
             $andaccess .= ' AND  c.access IN (0,' . $aid_list . ')';
             $andaccess .= ' AND  i.access IN (0,' . $aid_list . ')';
         } else {
             $aid = (int) $user->get('aid');
             if (FLEXI_ACCESS) {
                 $joinaccess .= ' LEFT JOIN #__flexiaccess_acl AS gt ON ty.id = gt.axo AND gt.aco = "read" AND gt.axosection = "type"';
                 $joinaccess .= ' LEFT JOIN #__flexiaccess_acl AS gc ON  c.id = gc.axo AND gc.aco = "read" AND gc.axosection = "category"';
                 $joinaccess .= ' LEFT JOIN #__flexiaccess_acl AS gi ON  i.id = gi.axo AND gi.aco = "read" AND gi.axosection = "item"';
                 $andaccess .= ' AND (gt.aro IN ( ' . $user->gmid . ' ) OR ty.access <= ' . $aid . ')';
                 $andaccess .= ' AND (gc.aro IN ( ' . $user->gmid . ' ) OR  c.access <= ' . $aid . ')';
                 $andaccess .= ' AND (gi.aro IN ( ' . $user->gmid . ' ) OR  i.access <= ' . $aid . ')';
             } else {
                 $andaccess .= ' AND ty.access <= ' . $aid;
                 $andaccess .= ' AND  c.access <= ' . $aid;
                 $andaccess .= ' AND  i.access <= ' . $aid;
             }
         }
         $select_access .= ', 1 AS has_access';
     } else {
         // Access Flags for: content type, main category, item
         if (FLEXI_J16GE) {
             $aid_arr = JAccess::getAuthorisedViewLevels($user->id);
             $aid_list = implode(",", $aid_arr);
             $select_access .= ', ' . ' CASE WHEN ' . '  ty.access IN (' . $aid_list . ') AND ' . '   c.access IN (' . $aid_list . ') AND ' . '   i.access IN (' . $aid_list . ') ' . ' THEN 1 ELSE 0 END AS has_access';
         } else {
             $aid = (int) $user->get('aid');
             if (FLEXI_ACCESS) {
                 $joinaccess .= ' LEFT JOIN #__flexiaccess_acl AS gt ON ty.id = gt.axo AND gt.aco = "read" AND gt.axosection = "type"';
                 $joinaccess .= ' LEFT JOIN #__flexiaccess_acl AS gc ON  c.id = gc.axo AND gc.aco = "read" AND gc.axosection = "category"';
                 $joinaccess .= ' LEFT JOIN #__flexiaccess_acl AS gi ON  i.id = gi.axo AND gi.aco = "read" AND gi.axosection = "item"';
                 $select_access .= ', ' . ' CASE WHEN ' . '  (gt.aro IN ( ' . $user->gmid . ' ) OR ty.access <= ' . (int) $aid . ') AND ' . '  (gc.aro IN ( ' . $user->gmid . ' ) OR  c.access <= ' . (int) $aid . ') AND ' . '  (gi.aro IN ( ' . $user->gmid . ' ) OR  i.access <= ' . (int) $aid . ') ' . ' THEN 1 ELSE 0 END AS has_access';
             } else {
                 $select_access .= ', ' . ' CASE WHEN ' . '  (ty.access <= ' . (int) $aid . ') AND ' . '  ( c.access <= ' . (int) $aid . ') AND ' . '  ( i.access <= ' . (int) $aid . ') ' . ' THEN 1 ELSE 0 END AS has_access';
             }
         }
     }
     // **********************************************************************************************************************************************************
     // Create WHERE clause part for filtering by current active language, and current selected contend types ( !! although this is possible via a filter too ...)
     // **********************************************************************************************************************************************************
     $andlang = '';
     if ($app->isSite() && (FLEXI_FISH || FLEXI_J16GE && $app->getLanguageFilter()) && $filter_lang) {
         $andlang .= ' AND ( i.language LIKE ' . $db->Quote($lang . '%') . ' OR i.language="*" ) ';
         $andlang .= ' AND ( c.language LIKE ' . $db->Quote($lang . '%') . ' OR c.language="*" ) ';
     }
     // search articles
     $results = array();
     if ($limit > 0) {
         $query = $db->getQuery(true);
         $query->clear();
         $query->select('' . ' i.id as id,' . ' i.title AS title,' . ' i.language AS language,' . ' i.metakey AS metakey,' . ' i.metadesc AS metadesc,' . ' i.modified AS created,' . ' t.name AS tagname,' . ' fir.value as field,' . ' i.access, ie.type_id,' . ' CONCAT(i.introtext, i.fulltext) AS text,' . ' CONCAT_WS( " / ", ' . $db->Quote(JText::_('FLEXICONTENT')) . ', c.title, i.title ) AS section,' . ' CASE WHEN CHAR_LENGTH(i.alias) THEN CONCAT_WS(\':\', i.id, i.alias) ELSE i.id END AS slug,' . ' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END AS catslug,' . ' "2" AS browsernav' . $select_access);
         $query->from('#__content AS i ' . ' JOIN #__categories AS c ON i.catid = c.id' . ' JOIN #__flexicontent_items_ext AS ie ON i.id = ie.item_id' . ' JOIN #__flexicontent_types AS ty ON ie.type_id = ty.id' . ' LEFT JOIN #__flexicontent_fields_item_relations AS fir ON i.id = fir.item_id' . ' LEFT JOIN #__flexicontent_fields AS f ON fir.field_id = f.id' . ' LEFT JOIN #__flexicontent_tags_item_relations AS tir ON i.id = tir.itemid' . ' LEFT JOIN #__flexicontent_tags AS t ON tir.tid = t.id	' . $joinaccess);
         $query->where(' (' . $where . ') ' . ' AND ie.type_id IN(' . $types . ') ' . ' AND i.state IN (1, -5) AND c.published = 1 ' . ' AND (i.publish_up = ' . $db->Quote($nullDate) . ' OR i.publish_up <= ' . $db->Quote($nowDate) . ') ' . ' AND (i.publish_down = ' . $db->Quote($nullDate) . ' OR i.publish_down >= ' . $db->Quote($nowDate) . ') ' . $andaccess . $andlang);
         $query->group('i.id');
         $query->order($order);
         //echo "<pre style='white-space:normal!important;'>".$query."</pre>";
         $db->setQuery($query, 0, $limit);
         $list = $db->loadObjectList();
         if ($db->getErrorNum()) {
             echo $db->getErrorMsg();
         }
         if ($list) {
             $item_cats = FlexicontentFields::_getCategories($list);
             foreach ($list as $key => $item) {
                 // echo $item->title." ".$item->tagname."<br/>"; // Before checking for noHTML
                 if (FLEXI_J16GE || $item->sectionid == FLEXI_SECTION) {
                     $item->categories = isset($item_cats[$item->id]) ? $item_cats[$item->id] : array();
                     // in case of item categories missing
                     $item->href = JRoute::_(FlexicontentHelperRoute::getItemRoute($item->slug, $item->catslug, 0, $item));
                 } else {
                     $item->href = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catslug, $item->sectionid));
                 }
                 if (searchHelper::checkNoHTML($item, $searchText, array('title', 'metadesc', 'metakey', 'tagname', 'field', 'text'))) {
                     $results[$item->id] = $item;
                 }
             }
         }
     }
     return $results;
 }
示例#11
0
    /**
     * Search method
     *
     * The sql must return the following fields that are used in a common display
     * routine: href, title, section, created, text, browsernav
     *
     * @param string $keyword Target search string
     * @param string $type  matching option, exact|any|all
     * @param string $order ordering option, newest|oldest|popular|alpha|category
     * @param null   $areas An array if the search it to be restricted to areas, null if search all
     *
     * @return array results
     */
    public function onContentSearch($keyword, $type='', $order='', $areas=null)
    {
        if (is_array($areas))
        {
            if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) {
                return array();
            }
        }

        $keyword = trim($keyword);
        if (empty($keyword)) {
            return array();
        }

        $return = array();
        $pages  = KObjectManager::getInstance()->getObject('com://admin/docman.model.pages')->fetch();
        if (count($pages))
        {
            $limit = $this->params->def('search_limit', 50);

            $order_map = array(
                'default'  => array('tbl.title', 'ASC'),
                'oldest'   => array('tbl.created_on', 'ASC'),
                'newest'   => array('tbl.created_on', 'DESC'),
                'category' => array('category_title', 'ASC'),
                'popular'  => array('tbl.hits', 'DESC')
            );

            if (!array_key_exists($order, $order_map)) {
                $order = 'default';
            }
            list($sort, $direction) = $order_map[$order];

            $user = KObjectManager::getInstance()->getObject('user');

            $model = KObjectManager::getInstance()->getObject('com://admin/docman.model.documents');
            $model->enabled(1)
                ->status('published')
                ->current_user($user->getId())
                ->access($user->getRoles())
                ->page('all')
                ->search($keyword)
                ->search_by($type)
                ->limit($limit)
                ->sort($sort)
                ->direction($direction);

            $list = $model->fetch();

            if (!count($list)) {
                return array();
            }

            $return = array();
            foreach ($list as $item)
            {
                if (!$item->itemid || !searchHelper::checkNoHTML($item, $keyword, array('title', 'description'))) {
                    continue;
                }

                $entity = new stdClass();
                $entity->created = $item->created_on;

                $entity->href = JRoute::_(sprintf('index.php?option=com_docman&view=document&alias=%s&category_slug=%s&Itemid=%d',
                    $item->alias, $item->category->slug, $item->itemid));
                $entity->browsernav = '';
                $entity->title = $item->title;
                $entity->section = '';
                $entity->text = $item->description;

                $return[] = $entity;
            }
        }

        return $return;
    }
示例#12
0
 function onSearch($text, $phrase = '', $ordering = '', $areas = null)
 {
     JPlugin::loadLanguage('plg_search_j2store', JPATH_ADMINISTRATOR);
     jimport('joomla.html.parameter');
     $mainframe = JFactory::getApplication();
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     $db = JFactory::getDBO();
     $groups = implode(',', $user->getAuthorisedViewLevels());
     $jnow = JFactory::getDate();
     $now = $jnow->toSql();
     //2014-10-08 08:27:51
     $nullDate = $db->getNullDate();
     $accessCheck = " IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") ";
     $tagIDs = array();
     $itemIDs = array();
     $searchText = $text;
     if (is_array($areas)) {
         if (!array_intersect($areas, array_keys($this->onSearchAreas()))) {
             return array();
         }
     }
     $plugin = JPluginHelper::getPlugin('search', 'j2store');
     $pluginParams = class_exists('JParameter') ? new JParameter($plugin->params) : new JRegistry($plugin->params);
     $limit = $pluginParams->def('search_limit', 50);
     $text = JString::trim($text);
     if ($text == '') {
         return array();
     }
     switch ($phrase) {
         case 'exact':
             $text = $db->quote('%' . $db->escape($text, true) . '%', false);
             $wheres2 = array();
             $wheres2[] = 'p.item_sku LIKE ' . $text;
             $where = '(' . implode(') OR (', $wheres2) . ')';
             break;
         case 'all':
         case 'any':
         default:
             $words = explode(' ', $text);
             $wheres = array();
             foreach ($words as $word) {
                 $word = $db->quote('%' . $db->escape($word, true) . '%', false);
                 $wheres2 = array();
                 $wheres2[] = 'p.item_sku LIKE ' . $word;
                 $wheres[] = implode(' OR ', $wheres2);
             }
             $where = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wheres) . ')';
             break;
     }
     switch ($ordering) {
         case 'oldest':
             $order = 'a.created ASC';
             break;
         case 'popular':
             $order = 'a.hits DESC';
             break;
         case 'alpha':
             $order = 'a.title ASC';
             break;
         case 'category':
             $order = 'c.title ASC, a.title ASC';
             break;
         case 'newest':
         default:
             $order = 'a.created DESC';
             break;
     }
     $rows = array();
     $query = $db->getQuery(true);
     // Search articles.
     if ($limit > 0) {
         $query->clear();
         // SQLSRV changes.
         $case_when = ' CASE WHEN ';
         $case_when .= $query->charLength('a.alias', '!=', '0');
         $case_when .= ' THEN ';
         $a_id = $query->castAsChar('a.id');
         $case_when .= $query->concatenate(array($a_id, 'a.alias'), ':');
         $case_when .= ' ELSE ';
         $case_when .= $a_id . ' END as slug';
         $case_when1 = ' CASE WHEN ';
         $case_when1 .= $query->charLength('c.alias', '!=', '0');
         $case_when1 .= ' THEN ';
         $c_id = $query->castAsChar('c.id');
         $case_when1 .= $query->concatenate(array($c_id, 'c.alias'), ':');
         $case_when1 .= ' ELSE ';
         $case_when1 .= $c_id . ' END as catslug';
         $query->select('p.*');
         $query->from('#__j2store_prices as p');
         $query->where('p.product_enabled = 1');
         $query->where($where);
         $query->select('a.title AS title, a.metadesc, a.metakey, a.created AS created')->select($query->concatenate(array('a.introtext', 'a.fulltext')) . ' AS text')->select('c.title AS section, ' . $case_when . ',' . $case_when1 . ', ' . '\'2\' AS browsernav')->leftJoin('#__content as a ON a.id=p.article_id')->join('INNER', '#__categories AS c ON c.id=a.catid')->where('a.state=1 AND c.published = 1 AND a.access IN (' . $groups . ') ' . 'AND c.access IN (' . $groups . ') ' . 'AND (a.publish_up = ' . $db->quote($nullDate) . ' OR a.publish_up <= ' . $db->quote($now) . ') ' . 'AND (a.publish_down = ' . $db->quote($nullDate) . ' OR a.publish_down >= ' . $db->quote($now) . ')')->group('a.id, a.title, a.metadesc, a.metakey, a.created, a.introtext, a.fulltext, c.title, a.alias, c.alias, c.id')->order($order);
         // Filter by language.
         if ($app->isSite() && JLanguageMultilang::isEnabled()) {
             $query->where('a.language in (' . $db->quote($tag) . ',' . $db->quote('*') . ')')->where('c.language in (' . $db->quote($tag) . ',' . $db->quote('*') . ')');
         }
         $db->setQuery($query, 0, $limit);
         $list = $db->loadObjectList();
         $limit -= count($list);
         if (isset($list)) {
             foreach ($list as $key => $item) {
                 $list[$key]->href = ContentHelperRoute::getArticleRoute($item->slug, $item->catslug);
             }
         }
         $rows[] = $list;
     }
     $results = array();
     if (count($rows)) {
         foreach ($rows as $row) {
             $new_row = array();
             foreach ($row as $key => $item) {
                 $item->browsernav = '';
                 $item->tag = $searchText;
                 if (searchHelper::checkNoHTML($item, $searchText, array('text', 'title', 'metakey', 'metadesc', 'section', 'image_caption', 'image_credits', 'video_caption', 'video_credits', 'extra_fields_search', 'tag'))) {
                     $new_row[] = $item;
                 }
             }
             $results = array_merge($results, (array) $new_row);
         }
     }
     return $results;
 }
function plgSearchAcymailingsearch($text, $phrase = '', $ordering = '', $areas = null)
{
    if (!(include_once rtrim(JPATH_ADMINISTRATOR, DS) . DS . 'components' . DS . 'com_acymailing' . DS . 'helpers' . DS . 'helper.php')) {
        return array();
    }
    $db =& JFactory::getDBO();
    $user =& JFactory::getUser();
    $searchText = $text;
    if (is_array($areas)) {
        if (!array_intersect($areas, array_keys(plgSearchAcymailingsearchAreas()))) {
            return array();
        }
    }
    // load plugin params info
    $plugin =& JPluginHelper::getPlugin('search', 'content');
    $pluginParams = new JParameter($plugin->params);
    $limit = $pluginParams->get('search_limit', 50);
    $text = trim($text);
    if ($text == '') {
        return array();
    }
    $wheres = array();
    switch ($phrase) {
        case 'exact':
            $text = $db->Quote('%' . $db->getEscaped($text, true) . '%', false);
            $wheres2 = array();
            $wheres2[] = 'a.subject LIKE ' . $text;
            $wheres2[] = 'a.body LIKE ' . $text;
            $wheres2[] = 'a.altbody LIKE ' . $text;
            $where = '(' . implode(') OR (', $wheres2) . ')';
            break;
        case 'all':
        case 'any':
        default:
            $words = explode(' ', $text);
            $wheres = array();
            foreach ($words as $word) {
                $word = $db->Quote('%' . $db->getEscaped($word, true) . '%', false);
                $wheres2 = array();
                $wheres2[] = 'a.subject LIKE ' . $word;
                $wheres2[] = 'a.body LIKE ' . $word;
                $wheres2[] = 'a.altbody LIKE ' . $word;
                $wheres[] = implode(' OR ', $wheres2);
            }
            $where = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wheres) . ')';
            break;
    }
    $morder = '';
    switch ($ordering) {
        case 'oldest':
            $order = 'a.created ASC';
            break;
        case 'category':
            $order = 'b.ordering ASC';
            break;
        case 'alpha':
            $order = 'a.subject ASC';
            break;
        default:
            $order = 'a.created DESC';
            break;
    }
    //First we need to
    // search articles
    $query = 'SELECT "2" AS browsernav, a.*, b.listid, b.name as section, b.alias as listalias FROM `#__acymailing_list` as b ';
    $query .= 'LEFT JOIN `#__acymailing_listmail` as c ON b.listid = c.listid ';
    $query .= 'LEFT JOIN `#__acymailing_mail` as a ON c.mailid = a.mailid ';
    $query .= ' WHERE ( ' . $where . ' ) AND b.published = 1 AND b.visible = 1 AND a.type="news" AND a.published = 1 AND a.visible = 1 GROUP BY a.mailid ORDER BY ' . $order;
    $db->setQuery($query, 0, $limit);
    $newsletters = $db->loadObjectList();
    if (empty($newsletters)) {
        return array();
    }
    $return = array();
    foreach ($newsletters as $key => $item) {
        $newsletters[$key]->href = acymailing::completeLink('archive&task=view&listid=' . $item->listid . '-' . $item->listalias . '&mailid=' . $item->mailid . '-' . $item->alias);
        $newsletters[$key]->title = $newsletters[$key]->subject;
        $newsletters[$key]->created = JHTML::date(strtotime($item->created));
        $newsletters[$key]->text = $item->html && !empty($item->body) ? $item->body : nl2br($item->altbody);
        if (searchHelper::checkNoHTML($newsletters[$key], $text, array('title', 'text'))) {
            $return[] = $newsletters[$key];
        }
    }
    return $return;
}
示例#14
0
	/**
	 * Newsfeeds Search method
	 *
	 * The sql must return the following fields that are used in a common display
	 * routine: href, title, section, created, text, browsernav
	 * @param string Target search string
	 * @param string mathcing option, exact|any|all
	 * @param string ordering option, newest|oldest|popular|alpha|category
	 * @param mixed An array if the search it to be restricted to areas, null if search all
	 */
	function onContentSearch($text, $phrase='', $ordering='', $areas=null)
	{
		$db		= JFactory::getDbo();
		$app	= JFactory::getApplication();
		$user	= JFactory::getUser();

        $searchText = $text;

        $limit = $this->params->get( 'search_limit', 50 );

        $text = trim( $db->escape($text) );

        if ($text == '') {
            return array();
        }
        $section 	= JText::_( 'Auction Factory' );

        $wheres 	= array();
        switch ($phrase)
        {
            case 'exact':
                $text		= $db->Quote( '%'.$db->getEscaped( $text, true ).'%', false );
                $wheres2 	= array();
                $wheres2[] 	= 'a.shortdescription LIKE '.$text;
                $wheres2[] 	= 'a.title LIKE '.$text;
                $where 		= '(' . implode( ') OR (', $wheres2 ) . ')';
                break;

            case 'all':
            case 'any':
            default:
                $words 	= explode( ' ', $text );
                $wheres = array();
                foreach ($words as $word)
                {
                    $word		= $db->Quote( '%'.$db->getEscaped( $word, true ).'%', false );
                    $wheres2 	= array();
                    $wheres2[] 	= 'a.shortdescription LIKE '.$word;
                    $wheres2[] 	= 'a.title LIKE '.$word;
                    $wheres[] 	= implode( ' OR ', $wheres2 );
                }
                $where 	= '(' . implode( ($phrase == 'all' ? ') AND (' : ') OR ('), $wheres ) . ')';
                break;
        }

        switch ( $ordering ) {
            case 'alpha':
                $order = 'title ASC';
                break;

            case 'category':
                $order = 'catname ASC, title ASC';
                break;

            case 'oldest':
                $order = 'start_date ASC, title ASC';
                break;
            case 'newest':
                $order = 'start_date DESC, title ASC';
                break;
            case 'popular':
            default:
                $order = 'hits DESC';
        }
        require_once (JPATH_ROOT.DS.'components'.DS.'com_bids'.DS.'helpers'.DS.'tools.php');
        $tmp_id = BidsHelperTools::getMenuItemId(array("task"=>"listauctions"));

        $query = "SELECT a.title,"
        . "\n start_date AS created,"
        . "\n shortdescription AS text,"
        . "\n concat('Cat: ',b.title) AS section,"
        . "\n CONCAT( 'index.php?option=com_bids&task=viewbids&Itemid={$tmp_id}&id=', a.id, ':', a.title ) AS href,"
        . "\n '1' AS browsernav"
        . "\n FROM #__bid_auctions a "
        . "\n LEFT JOIN #__categories AS b ON b.id = a.cat"
        . "\n WHERE ( $where )"
        . "\n AND a.published = 1 and a.start_date<=UTC_TIMESTAMP()"
        . "\n ORDER BY $order"
        ;

        $db->setQuery( $query, 0, $limit );
        $rows = $db->loadObjectList();

        $return = array();
        foreach($rows AS $key => $weblink) {
            if(searchHelper::checkNoHTML($weblink, $searchText, array('url', 'text', 'title'))) {
                $return[] = $weblink;
            }
        }

        return $return;
	}
示例#15
0
 /**
  * Search content (categories).
  *
  * The SQL must return the following fields that are used in a common display
  * routine: href, title, section, created, text, browsernav.
  *
  * @param   string  $text      Target search string.
  * @param   string  $phrase    Matching option (possible values: exact|any|all).  Default is "any".
  * @param   string  $ordering  Ordering option (possible values: newest|oldest|popular|alpha|category).  Default is "newest".
  * @param   mixed   $areas     An array if the search is to be restricted to areas or null to search all areas.
  *
  * @return  array  Search results.
  *
  * @since   1.6
  */
 public function onContentSearch($text, $phrase = '', $ordering = '', $areas = null)
 {
     $db = JFactory::getDbo();
     $user = JFactory::getUser();
     $app = JFactory::getApplication();
     $groups = implode(',', $user->getAuthorisedViewLevels());
     $searchText = $text;
     if (is_array($areas)) {
         if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) {
             return array();
         }
     }
     $sContent = $this->params->get('search_content', 1);
     $sArchived = $this->params->get('search_archived', 1);
     $limit = $this->params->def('search_limit', 50);
     $state = array();
     if ($sContent) {
         $state[] = 1;
     }
     if ($sArchived) {
         $state[] = 2;
     }
     if (empty($state)) {
         return array();
     }
     $text = trim($text);
     if ($text == '') {
         return array();
     }
     /* TODO: The $where variable does not seem to be used at all
     		switch ($phrase)
     		{
     			case 'exact':
     				$text = $db->quote('%' . $db->escape($text, true) . '%', false);
     				$wheres2 = array();
     				$wheres2[] = 'a.title LIKE ' . $text;
     				$wheres2[] = 'a.description LIKE ' . $text;
     				$where = '(' . implode(') OR (', $wheres2) . ')';
     				break;
     
     			case 'any':
     			case 'all';
     			default:
     				$words = explode(' ', $text);
     				$wheres = array();
     				foreach ($words as $word)
     				{
     					$word = $db->quote('%' . $db->escape($word, true) . '%', false);
     					$wheres2 = array();
     					$wheres2[] = 'a.title LIKE ' . $word;
     					$wheres2[] = 'a.description LIKE ' . $word;
     					$wheres[] = implode(' OR ', $wheres2);
     				}
     				$where = '(' . implode(($phrase == 'all' ? ') AND (' : ') OR ('), $wheres) . ')';
     				break;
     		}
     		*/
     switch ($ordering) {
         case 'alpha':
             $order = 'a.title ASC';
             break;
         case 'category':
         case 'popular':
         case 'newest':
         case 'oldest':
         default:
             $order = 'a.title DESC';
     }
     $text = $db->quote('%' . $db->escape($text, true) . '%', false);
     $query = $db->getQuery(true);
     // SQLSRV changes.
     $case_when = ' CASE WHEN ';
     $case_when .= $query->charLength('a.alias', '!=', '0');
     $case_when .= ' THEN ';
     $a_id = $query->castAsChar('a.id');
     $case_when .= $query->concatenate(array($a_id, 'a.alias'), ':');
     $case_when .= ' ELSE ';
     $case_when .= $a_id . ' END as slug';
     $query->select('a.title, a.description AS text, \'\' AS created, \'2\' AS browsernav, a.id AS catid, ' . $case_when)->from('#__categories AS a')->where('(a.title LIKE ' . $text . ' OR a.description LIKE ' . $text . ') AND a.published IN (' . implode(',', $state) . ') AND a.extension = ' . $db->quote('com_content') . 'AND a.access IN (' . $groups . ')')->group('a.id, a.title, a.description, a.alias')->order($order);
     if ($app->isSite() && JLanguageMultilang::isEnabled()) {
         $query->where('a.language in (' . $db->quote(JFactory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')');
     }
     $db->setQuery($query, 0, $limit);
     try {
         $rows = $db->loadObjectList();
     } catch (RuntimeException $e) {
         $rows = array();
         JFactory::getApplication()->enqueueMessage(JText::_('JERROR_AN_ERROR_HAS_OCCURRED'), 'error');
         JLog::add($e->getMessage(), JLog::ERROR, 'controller');
     }
     $return = array();
     if ($rows) {
         $count = count($rows);
         for ($i = 0; $i < $count; $i++) {
             $rows[$i]->href = ContentHelperRoute::getCategoryRoute($rows[$i]->slug);
             $rows[$i]->section = JText::_('JCATEGORY');
         }
         foreach ($rows as $category) {
             if (searchHelper::checkNoHTML($category, $searchText, array('name', 'title', 'text'))) {
                 $return[] = $category;
             }
         }
     }
     return $return;
 }
示例#16
0
文件: weblinks.php 项目: 01J/topm
 /**
  * Search content (weblinks).
  *
  * The SQL must return the following fields that are used in a common display
  * routine: href, title, section, created, text, browsernav
  *
  * @param   string  $text      Target search string.
  * @param   string  $phrase    Matching option (possible values: exact|any|all).  Default is "any".
  * @param   string  $ordering  Ordering option (possible values: newest|oldest|popular|alpha|category).  Default is "newest".
  * @param   mixed   $areas     An array if the search it to be restricted to areas or null to search all areas.
  *
  * @return  array  Search results.
  *
  * @since   1.6
  */
 public function onContentSearch($text, $phrase = '', $ordering = '', $areas = null)
 {
     $db = JFactory::getDbo();
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     $groups = implode(',', $user->getAuthorisedViewLevels());
     $searchText = $text;
     if (is_array($areas)) {
         if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) {
             return array();
         }
     }
     $sContent = $this->params->get('search_content', 1);
     $sArchived = $this->params->get('search_archived', 1);
     $limit = $this->params->def('search_limit', 50);
     $state = array();
     if ($sContent) {
         $state[] = 1;
     }
     if ($sArchived) {
         $state[] = 2;
     }
     if (empty($state)) {
         return array();
     }
     $text = trim($text);
     if ($text == '') {
         return array();
     }
     $searchWeblinks = JText::_('PLG_SEARCH_WEBLINKS');
     switch ($phrase) {
         case 'exact':
             $text = $db->quote('%' . $db->escape($text, true) . '%', false);
             $wheres2 = array();
             $wheres2[] = 'a.url LIKE ' . $text;
             $wheres2[] = 'a.description LIKE ' . $text;
             $wheres2[] = 'a.title LIKE ' . $text;
             $where = '(' . implode(') OR (', $wheres2) . ')';
             break;
         case 'all':
         case 'any':
         default:
             $words = explode(' ', $text);
             $wheres = array();
             foreach ($words as $word) {
                 $word = $db->quote('%' . $db->escape($word, true) . '%', false);
                 $wheres2 = array();
                 $wheres2[] = 'a.url LIKE ' . $word;
                 $wheres2[] = 'a.description LIKE ' . $word;
                 $wheres2[] = 'a.title LIKE ' . $word;
                 $wheres[] = implode(' OR ', $wheres2);
             }
             $where = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wheres) . ')';
             break;
     }
     switch ($ordering) {
         case 'oldest':
             $order = 'a.created ASC';
             break;
         case 'popular':
             $order = 'a.hits DESC';
             break;
         case 'alpha':
             $order = 'a.title ASC';
             break;
         case 'category':
             $order = 'c.title ASC, a.title ASC';
             break;
         case 'newest':
         default:
             $order = 'a.created DESC';
     }
     $query = $db->getQuery(true);
     // SQLSRV changes.
     $case_when = ' CASE WHEN ';
     $case_when .= $query->charLength('a.alias', '!=', '0');
     $case_when .= ' THEN ';
     $a_id = $query->castAsChar('a.id');
     $case_when .= $query->concatenate(array($a_id, 'a.alias'), ':');
     $case_when .= ' ELSE ';
     $case_when .= $a_id . ' END as slug';
     $case_when1 = ' CASE WHEN ';
     $case_when1 .= $query->charLength('c.alias', '!=', '0');
     $case_when1 .= ' THEN ';
     $c_id = $query->castAsChar('c.id');
     $case_when1 .= $query->concatenate(array($c_id, 'c.alias'), ':');
     $case_when1 .= ' ELSE ';
     $case_when1 .= $c_id . ' END as catslug';
     $query->select('a.title AS title, \'\' AS created, a.url, a.description AS text, ' . $case_when . "," . $case_when1)->select($query->concatenate(array($db->quote($searchWeblinks), 'c.title'), " / ") . ' AS section')->select('\'1\' AS browsernav')->from('#__weblinks AS a')->join('INNER', '#__categories as c ON c.id = a.catid')->where('(' . $where . ') AND a.state IN (' . implode(',', $state) . ') AND c.published = 1 AND c.access IN (' . $groups . ')')->order($order);
     // Filter by language.
     if ($app->isSite() && JLanguageMultilang::isEnabled()) {
         $tag = JFactory::getLanguage()->getTag();
         $query->where('a.language in (' . $db->quote($tag) . ',' . $db->quote('*') . ')')->where('c.language in (' . $db->quote($tag) . ',' . $db->quote('*') . ')');
     }
     $db->setQuery($query, 0, $limit);
     $rows = $db->loadObjectList();
     $return = array();
     if ($rows) {
         foreach ($rows as $key => $row) {
             $rows[$key]->href = WeblinksHelperRoute::getWeblinkRoute($row->slug, $row->catslug);
         }
         foreach ($rows as $weblink) {
             if (searchHelper::checkNoHTML($weblink, $searchText, array('url', 'text', 'title'))) {
                 $return[] = $weblink;
             }
         }
     }
     return $return;
 }
示例#17
0
 function onContentSearch($text, $phrase = '', $ordering = '', $areas = null)
 {
     $app = JFactory::getApplication();
     $db = JFactory::getDBO();
     $searchText = $text;
     if (is_array($areas)) {
         if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) {
             return array();
         }
     }
     // load plugin params info
     $plugin = JPluginHelper::getPlugin('search', 'djclassifieds');
     $pluginParams = $this->params;
     $limit = $pluginParams->def('search_limit', 50);
     $text = trim($text);
     if ($text == '') {
         return array();
     }
     $wheres = array();
     $where = '';
     switch ($phrase) {
         case 'exact':
             $text = $db->Quote('%' . $db->getEscaped($text, true) . '%', false);
             $wheres2 = array();
             $wheres2[] = 'i.name LIKE ' . $text;
             $wheres2[] = 'i.intro_desc LIKE ' . $text;
             $wheres2[] = 'i.description LIKE ' . $text;
             $where = '(' . implode(') OR (', $wheres2) . ')';
             break;
         case 'all':
         case 'any':
         default:
             $words = explode(' ', $text);
             $wheres = array();
             foreach ($words as $word) {
                 $word = $db->Quote('%' . $db->getEscaped($word, true) . '%', false);
                 $wheres2 = array();
                 $wheres2[] = 'i.name LIKE ' . $word;
                 $wheres2[] = 'i.intro_desc LIKE ' . $word;
                 $wheres2[] = 'i.description LIKE ' . $word;
                 $wheres[] = implode(' OR ', $wheres2);
             }
             $where = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wheres) . ')';
             break;
     }
     switch ($ordering) {
         case 'alpha':
             $order = 'i.name ASC';
             break;
         case 'category':
         case 'popular':
         case 'newest':
         case 'oldest':
         default:
             $order = 'i.name DESC';
     }
     $date_time = JFactory::getDate();
     $date_exp = $date_time->toSQL();
     $text = $db->Quote('%' . $db->getEscaped($text, true) . '%', false);
     $query = ' SELECT i.id AS id, i.name AS title, i.alias as alias, i.intro_desc AS intro, i.date_start as created, c.id AS cat_id, c.name AS category, c.alias as c_alias, i.description as text,i.metakey, i.metadesc ' . ' FROM #__djcf_items AS i ' . ' LEFT JOIN #__djcf_categories AS c ON c.id = i.cat_id ' . ' WHERE i.date_exp > \'' . $date_exp . '\' AND (' . $where . ')' . ' AND i.published = 1 AND c.published = 1' . ' GROUP BY id' . ' ORDER BY ' . $order;
     $db->setQuery($query, 0, $limit);
     $rows = $db->loadObjectList();
     //echo '<pre>';print_r($rows);die();
     $count = count($rows);
     for ($i = 0; $i < $count; $i++) {
         $rows[$i]->href = JRoute::_(DJClassifiedsSEO::getItemRoute($rows[$i]->id . ':' . $rows[$i]->alias, $rows[$i]->cat_id . ':' . $rows[$i]->c_alias));
         $rows[$i]->section = JText::_('PLG_SEARCH_DJCLASSIFIEDS_DJCLASSIFIEDSITEMS') . ': ' . $rows[$i]->category;
         $rows[$i]->browsernav = 2;
     }
     $return = array();
     foreach ($rows as $key => $section) {
         if (searchHelper::checkNoHTML($section, $searchText, array('title', 'text', 'intro', 'metadesc', 'metakey'))) {
             $return[] = $section;
         }
     }
     //echo '<pre>';print_r($return);die();
     return $return;
 }
示例#18
0
文件: k2.php 项目: n4m4573/joomla-3.x
 function onSearch($text, $phrase = '', $ordering = '', $areas = null)
 {
     JPlugin::loadLanguage('plg_search_k2', JPATH_ADMINISTRATOR);
     jimport('joomla.html.parameter');
     $mainframe = JFactory::getApplication();
     $db = JFactory::getDBO();
     $jnow = JFactory::getDate();
     $now = K2_JVERSION == '15' ? $jnow->toMySQL() : $jnow->toSql();
     $nullDate = $db->getNullDate();
     $user = JFactory::getUser();
     if (K2_JVERSION != '15') {
         $accessCheck = " IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") ";
     } else {
         $aid = $user->get('aid');
         $accessCheck = " <= {$aid} ";
     }
     $tagIDs = array();
     $itemIDs = array();
     require_once JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_search' . DS . 'helpers' . DS . 'search.php';
     require_once JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'helpers' . DS . 'route.php';
     $searchText = $text;
     if (is_array($areas)) {
         if (!array_intersect($areas, array_keys($this->onSearchAreas()))) {
             return array();
         }
     }
     $plugin = JPluginHelper::getPlugin('search', 'k2');
     $pluginParams = class_exists('JParameter') ? new JParameter($plugin->params) : new JRegistry($plugin->params);
     $limit = $pluginParams->def('search_limit', 50);
     $text = JString::trim($text);
     if ($text == '') {
         return array();
     }
     $rows = array();
     if ($limit > 0) {
         if ($pluginParams->get('search_tags')) {
             $tagQuery = JString::str_ireplace('*', '', $text);
             $words = explode(' ', $tagQuery);
             for ($i = 0; $i < count($words); $i++) {
                 $words[$i] .= '*';
             }
             $tagQuery = implode(' ', $words);
             $escaped = K2_JVERSION == '15' ? $db->getEscaped($tagQuery, true) : $db->escape($tagQuery, true);
             $tagQuery = $db->Quote($escaped, false);
             $query = "SELECT id FROM #__k2_tags WHERE MATCH(name) AGAINST ({$tagQuery} IN BOOLEAN MODE) AND published=1";
             $db->setQuery($query);
             $tagIDs = K2_JVERSION == '30' ? $db->loadColumn() : $db->loadResultArray();
             if (count($tagIDs)) {
                 JArrayHelper::toInteger($tagIDs);
                 $query = "SELECT itemID FROM #__k2_tags_xref WHERE tagID IN (" . implode(',', $tagIDs) . ")";
                 $db->setQuery($query);
                 $itemIDs = K2_JVERSION == '30' ? $db->loadColumn() : $db->loadResultArray();
             }
         }
         if ($phrase == 'exact') {
             $text = JString::trim($text, '"');
             $escaped = K2_JVERSION == '15' ? $db->getEscaped($text, true) : $db->escape($text, true);
             $text = $db->Quote('"' . $db->getEscaped($text, true) . '"', false);
         } else {
             $text = JString::str_ireplace('*', '', $text);
             $words = explode(' ', $text);
             for ($i = 0; $i < count($words); $i++) {
                 if ($phrase == 'all') {
                     $words[$i] = '+' . $words[$i];
                 }
                 $words[$i] .= '*';
             }
             $text = implode(' ', $words);
             $escaped = K2_JVERSION == '15' ? $db->getEscaped($text, true) : $db->escape($text, true);
             $text = $db->Quote($escaped, false);
         }
         $query = "\r\n\t\tSELECT i.title AS title,\r\n\t    i.metadesc,\r\n\t    i.metakey,\r\n\t    c.name as section,\r\n\t    i.image_caption,\r\n\t    i.image_credits,\r\n\t    i.video_caption,\r\n\t    i.video_credits,\r\n\t    i.extra_fields_search,\r\n\t    i.created,\r\n    \tCONCAT(i.introtext, i.fulltext) AS text,\r\n    \tCASE WHEN CHAR_LENGTH(i.alias) THEN CONCAT_WS(':', i.id, i.alias) ELSE i.id END as slug,\r\n    \tCASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(':', c.id, c.alias) ELSE c.id END as catslug\r\n    \tFROM #__k2_items AS i\r\n    \tINNER JOIN #__k2_categories AS c ON c.id=i.catid AND c.access {$accessCheck}\r\n\t\tWHERE (";
         if ($pluginParams->get('search_tags') && count($itemIDs)) {
             JArrayHelper::toInteger($itemIDs);
             $query .= " i.id IN (" . implode(',', $itemIDs) . ") OR ";
         }
         $query .= "MATCH(i.title, i.introtext, i.`fulltext`,i.extra_fields_search,i.image_caption,i.image_credits,i.video_caption,i.video_credits,i.metadesc,i.metakey) AGAINST ({$text} IN BOOLEAN MODE)\r\n\t\t)\r\n\t\tAND i.trash = 0\r\n\t    AND i.published = 1\r\n\t    AND i.access {$accessCheck}\r\n\t    AND c.published = 1\r\n\t    AND c.access {$accessCheck}\r\n\t    AND c.trash = 0\r\n\t    AND ( i.publish_up = " . $db->Quote($nullDate) . " OR i.publish_up <= " . $db->Quote($now) . " )\r\n        AND ( i.publish_down = " . $db->Quote($nullDate) . " OR i.publish_down >= " . $db->Quote($now) . " )";
         if (K2_JVERSION != '15' && $mainframe->isSite() && $mainframe->getLanguageFilter()) {
             $languageTag = JFactory::getLanguage()->getTag();
             $query .= " AND c.language IN (" . $db->Quote($languageTag) . ", " . $db->Quote('*') . ") AND i.language IN (" . $db->Quote($languageTag) . ", " . $db->Quote('*') . ") ";
         }
         $query .= " GROUP BY i.id ";
         switch ($ordering) {
             case 'oldest':
                 $query .= 'ORDER BY i.created ASC';
                 break;
             case 'popular':
                 $query .= 'ORDER BY i.hits DESC';
                 break;
             case 'alpha':
                 $query .= 'ORDER BY i.title ASC';
                 break;
             case 'category':
                 $query .= 'ORDER BY c.name ASC, i.title ASC';
                 break;
             case 'newest':
             default:
                 $query .= 'ORDER BY i.created DESC';
                 break;
         }
         $db->setQuery($query, 0, $limit);
         $list = $db->loadObjectList();
         $limit -= count($list);
         if (isset($list)) {
             foreach ($list as $key => $item) {
                 $list[$key]->href = JRoute::_(K2HelperRoute::getItemRoute($item->slug, $item->catslug));
             }
         }
         $rows[] = $list;
     }
     $results = array();
     if (count($rows)) {
         foreach ($rows as $row) {
             $new_row = array();
             foreach ($row as $key => $item) {
                 $item->browsernav = '';
                 $item->tag = $searchText;
                 if (searchHelper::checkNoHTML($item, $searchText, array('text', 'title', 'metakey', 'metadesc', 'section', 'image_caption', 'image_credits', 'video_caption', 'video_credits', 'extra_fields_search', 'tag'))) {
                     $new_row[] = $item;
                 }
             }
             $results = array_merge($results, (array) $new_row);
         }
     }
     return $results;
 }
示例#19
0
 /**
  * Example Search method
  *
  * The sql must return the following fields that are used in a common display
  * routine:
  * - title;
  * - href:         link associated with the title;
  * - browsernav    if 1, link opens in a new window, otherwise in the same window;
  * - section       in parenthesis below the title;
  * - text;
  * - created;
  * @param string Target search string
  * @param string matching option, exact|any|all
  * @param string ordering option, newest|oldest|popular|alpha|category
  * @param mixed  An array if the search it to be restricted to areas, null if search all
  */
 function onContentSearch($text, $phrase = '', $ordering = '', $areas = null)
 {
     $db = JFactory::getDbo();
     //Set the database query offset & limit (may be parameterised):
     $offset = 0;
     $limit = 50;
     //Check that the this search area has been selected:
     if (is_array($areas)) {
         if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) {
             return array();
         }
     }
     //Strip white space from the search term:
     $searchText = trim($text);
     //If no search text, exit:
     if ($searchText == '') {
         return array();
     }
     //Initialise the array of where statements:
     $wheres = array();
     //Swiching on the string matching option (exact|any|all)...
     switch ($phrase) {
         //Exact match - match the whole search text:
         case 'exact':
             //Prepare the search text to be a mySQL wildcard and construct the where statement:
             $searchText = $db->quote('%' . $searchText . '%', true);
             $where = 'b.description LIKE ' . $searchText;
             break;
         case 'all':
         case 'any':
         default:
             //Convert the words to an arry:
             $words = explode(' ', $searchText);
             //Initialise the array of where statements:
             $wheres = array();
             //For each word in the search text...
             foreach ($words as $word) {
                 //Prepare the search text as a mySQL wildcard and append to the where statement array:
                 $word = $db->quote('%' . $word . '%', true);
                 //$wheres	= array();
                 $wheres[] = 'b.description LIKE ' . $word;
             }
             //Concatenate the where statements:
             $operator = $phrase == 'all' ? 'AND' : 'OR';
             $where = '(' . implode(' ' . $operator . ' ', $wheres) . ')';
             break;
     }
     //Switch on ordering (in this case trivial):
     switch ($ordering) {
         case 'oldest':
         case 'popular':
         case 'alpha':
         case 'category':
         case 'newest':
         default:
             $order = 'b.created DESC';
     }
     //Get a new query object:
     $query = $db->getQuery(true);
     //Construct the query:
     $query->select('b.name AS title, b.clickurl as href, "1" AS browsernav, ' . 'c.title AS section, b.description AS text, b.created AS created');
     $query->from('#__banners AS b')->join('INNER', '#__categories AS c ON c.id = b.catid')->where('(' . $where . ') AND (b.state=1) AND  (c.published=1)')->order($order);
     //Prepare & execute the query - offset & limit can be parameterised:
     $db->setQuery($query, $offset, $limit);
     $rows = $db->loadObjectList();
     /*
     The resulting executed query will be similar to this...
     	SELECT
     	  b.name AS title,
     	  b.clickurl as href,
     	  "1" AS browsernav,
     	  c.title AS section,
     	  b.description AS text,
     	  b.created AS created
     	FROM j16_banners AS b
     	INNER JOIN j16_categories AS c
     	  ON c.id = b.catid
     	WHERE ((b.description LIKE '%yourstring%'))
     	  AND (b.state=1)
     	  AND (c.published=1)
     	ORDER BY b.created DESC
     	LIMIT 0, 50
     */
     //Initialise the return array:
     $return = array();
     //If there's data...
     if ($rows) {
         //For each row of data...
         foreach ($rows as $key => $banner) {
             //If the search text can be found even after stripping HTML
             if (searchHelper::checkNoHTML($banner, $text, array('text'))) {
                 //Append to the return array:
                 $return[] = $banner;
             }
         }
     }
     return $return;
 }
示例#20
0
 /**
  * Content Search method
  * The sql must return the following fields that are used in a common display
  * routine: href, title, section, created, text, browsernav
  * @param string Target search string
  * @param string mathcing option, exact|any|all
  * @param string ordering option, newest|oldest|popular|alpha|category
  * @param mixed An array if the search it to be restricted to areas, null if search all
  */
 function onContentSearch($text, $phrase = '', $ordering = '', $areas = null)
 {
     $db = JFactory::getDbo();
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     $groups = implode(',', $user->getAuthorisedViewLevels());
     $tag = JFactory::getLanguage()->getTag();
     require_once JPATH_SITE . '/components/com_content/helpers/route.php';
     require_once JPATH_SITE . '/administrator/components/com_search/helpers/search.php';
     $searchText = $text;
     if (is_array($areas)) {
         if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) {
             return array();
         }
     }
     $sContent = $this->params->get('search_content', 1);
     $sArchived = $this->params->get('search_archived', 1);
     $limit = $this->params->def('search_limit', 50);
     $nullDate = $db->getNullDate();
     $date = JFactory::getDate();
     $now = $date->toMySQL();
     $text = trim($text);
     if ($text == '') {
         return array();
     }
     $wheres = array();
     switch ($phrase) {
         case 'exact':
             $text = $db->Quote('%' . $db->getEscaped($text, true) . '%', false);
             $wheres2 = array();
             $wheres2[] = 'a.title LIKE ' . $text;
             $wheres2[] = 'a.introtext LIKE ' . $text;
             $wheres2[] = 'a.fulltext LIKE ' . $text;
             $wheres2[] = 'a.metakey LIKE ' . $text;
             $wheres2[] = 'a.metadesc LIKE ' . $text;
             $where = '(' . implode(') OR (', $wheres2) . ')';
             break;
         case 'all':
         case 'any':
         default:
             $words = explode(' ', $text);
             $wheres = array();
             foreach ($words as $word) {
                 $word = $db->Quote('%' . $db->getEscaped($word, true) . '%', false);
                 $wheres2 = array();
                 $wheres2[] = 'a.title LIKE ' . $word;
                 $wheres2[] = 'a.introtext LIKE ' . $word;
                 $wheres2[] = 'a.fulltext LIKE ' . $word;
                 $wheres2[] = 'a.metakey LIKE ' . $word;
                 $wheres2[] = 'a.metadesc LIKE ' . $word;
                 $wheres[] = implode(' OR ', $wheres2);
             }
             $where = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wheres) . ')';
             break;
     }
     $morder = '';
     switch ($ordering) {
         case 'oldest':
             $order = 'a.created ASC';
             break;
         case 'popular':
             $order = 'a.hits DESC';
             break;
         case 'alpha':
             $order = 'a.title ASC';
             break;
         case 'category':
             $order = 'c.title ASC, a.title ASC';
             $morder = 'a.title ASC';
             break;
         case 'newest':
         default:
             $order = 'a.created DESC';
             break;
     }
     $rows = array();
     $query = $db->getQuery(true);
     // search articles
     if ($sContent && $limit > 0) {
         $query->clear();
         $query->select('a.title AS title, a.metadesc, a.metakey, a.created AS created, ' . 'CONCAT(a.introtext, a.fulltext) AS text, c.title AS section, ' . 'CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug, ' . 'CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(":", c.id, c.alias) ELSE c.id END as catslug, ' . '"2" AS browsernav');
         $query->from('#__content AS a');
         $query->innerJoin('#__categories AS c ON c.id=a.catid');
         $query->where('(' . $where . ')' . 'AND a.state=1 AND c.published = 1 AND a.access IN (' . $groups . ') ' . 'AND c.access IN (' . $groups . ') ' . 'AND (a.publish_up = ' . $db->Quote($nullDate) . ' OR a.publish_up <= ' . $db->Quote($now) . ') ' . 'AND (a.publish_down = ' . $db->Quote($nullDate) . ' OR a.publish_down >= ' . $db->Quote($now) . ')');
         $query->group('a.id');
         $query->order($order);
         // Filter by language
         if ($app->isSite() && $app->getLanguageFilter()) {
             $query->where('a.language in (' . $db->Quote($tag) . ',' . $db->Quote('*') . ')');
             $query->where('c.language in (' . $db->Quote($tag) . ',' . $db->Quote('*') . ')');
         }
         $db->setQuery($query, 0, $limit);
         $list = $db->loadObjectList();
         $limit -= count($list);
         if (isset($list)) {
             foreach ($list as $key => $item) {
                 $list[$key]->href = ContentHelperRoute::getArticleRoute($item->slug, $item->catslug);
             }
         }
         $rows[] = $list;
     }
     // search archived content
     if ($sArchived && $limit > 0) {
         $searchArchived = JText::_('JARCHIVED');
         $query->clear();
         $query->select('a.title AS title, a.metadesc, a.metakey, a.created AS created, ' . 'CONCAT(a.introtext, a.fulltext) AS text, ' . 'CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug, ' . 'CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(":", c.id, c.alias) ELSE c.id END as catslug, ' . 'CONCAT_WS("/", c.title) AS section, "2" AS browsernav');
         $query->from('#__content AS a');
         $query->innerJoin('#__categories AS c ON c.id=a.catid AND c.access IN (' . $groups . ')');
         $query->where('(' . $where . ') AND a.state = 2 AND c.published = 1 AND a.access IN (' . $groups . ') AND c.access IN (' . $groups . ') ' . 'AND (a.publish_up = ' . $db->Quote($nullDate) . ' OR a.publish_up <= ' . $db->Quote($now) . ') ' . 'AND (a.publish_down = ' . $db->Quote($nullDate) . ' OR a.publish_down >= ' . $db->Quote($now) . ')');
         $query->order($order);
         // Filter by language
         if ($app->isSite() && $app->getLanguageFilter()) {
             $query->where('a.language in (' . $db->Quote($tag) . ',' . $db->Quote('*') . ')');
             $query->where('c.language in (' . $db->Quote($tag) . ',' . $db->Quote('*') . ')');
         }
         $db->setQuery($query, 0, $limit);
         $list3 = $db->loadObjectList();
         // find an itemid for archived to use if there isn't another one
         $item = $app->getMenu()->getItems('link', 'index.php?option=com_content&view=archive', true);
         $itemid = isset($item) ? '&Itemid=' . $item->id : '';
         if (isset($list3)) {
             foreach ($list3 as $key => $item) {
                 $date = JFactory::getDate($item->created);
                 $created_month = $date->format("n");
                 $created_year = $date->format("Y");
                 $list3[$key]->href = JRoute::_('index.php?option=com_content&view=archive&year=' . $created_year . '&month=' . $created_month . $itemid);
             }
         }
         $rows[] = $list3;
     }
     $results = array();
     if (count($rows)) {
         foreach ($rows as $row) {
             $new_row = array();
             foreach ($row as $key => $article) {
                 if (searchHelper::checkNoHTML($article, $searchText, array('text', 'title', 'metadesc', 'metakey'))) {
                     $new_row[] = $article;
                 }
             }
             $results = array_merge($results, (array) $new_row);
         }
     }
     return $results;
 }
示例#21
0
 public function onContentSearch($text, $phrase = '', $ordering = '', $areas = null)
 {
     $db = JFactory::getDbo();
     $user = JFactory::getUser();
     $searchText = $text;
     // Load plugin params info
     $pluginParams = $this->params;
     $limit = $pluginParams->def('search_limit', 50);
     $text = trim($text);
     if ($text == '') {
         return array();
     }
     $section = JText::_('COM_REDSHOP_Products');
     $wheres = array();
     switch ($phrase) {
         case 'exact':
             $text = $db->Quote('%' . $db->getEscaped($text, true) . '%', false);
             $wheres2 = array();
             $wheres2[] = 'a.product_name LIKE ' . $text;
             $wheres2[] = 'a.product_number LIKE ' . $text;
             $wheres2[] = 'c.data_txt LIKE ' . $text;
             $where = '(' . implode(') OR (', $wheres2) . ')';
             break;
         case 'all':
         case 'any':
         default:
             $words = explode(' ', $text);
             $wheres = array();
             foreach ($words as $word) {
                 $word = $db->Quote('%' . $db->getEscaped($word, true) . '%', false);
                 $wheres2 = array();
                 $wheres2[] = 'a.product_name LIKE ' . $word;
                 $wheres2[] = 'a.product_number LIKE ' . $word;
                 $wheres2[] = 'c.data_txt LIKE ' . $word;
                 $wheres[] = implode(' OR ', $wheres2);
             }
             $where = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wheres) . ')';
             break;
     }
     switch ($ordering) {
         case 'oldest':
             $order = 'a.product_id ASC';
             break;
         case 'newest':
         default:
             $order = 'a.product_id DESC';
     }
     // Shopper group - choose from manufactures Start
     $rsUserhelper = new rsUserhelper();
     $shopper_group_manufactures = $rsUserhelper->getShopperGroupManufacturers();
     $whereaclProduct = "";
     if ($shopper_group_manufactures != "") {
         $whereaclProduct = " AND a.manufacturer_id IN (" . $shopper_group_manufactures . ") ";
     }
     // Shopper group - choose from manufactures End
     $query = 'SELECT c.data_txt as customtxt,a.product_id,a.product_name AS title,a.product_number as number,a.product_s_desc AS text,' . ' "2" AS browsernav,"Redshop product" as section,"" as created' . ' FROM #__redshop_product AS a LEFT join #__redshop_fields_data As c on c.itemid = a.product_id' . ' WHERE (' . $where . ') ' . $whereaclProduct . '' . ' AND a.published = 1' . ' ORDER BY ' . $order;
     $db->setQuery($query, 0, $limit);
     $rows = $db->loadObjectList();
     $redhelper = new redhelper();
     foreach ($rows as $key => $row) {
         $Itemid = $redhelper->getItemid($row->product_id);
         $rows[$key]->href = "index.php?option=com_redshop&view=product&pid=" . $row->product_id . "&Itemid=" . $Itemid;
     }
     $return = array();
     foreach ($rows as $key => $weblink) {
         if (searchHelper::checkNoHTML($weblink, $searchText, array('url', 'text', 'title', 'number', 'customtxt'))) {
             $return[] = $weblink;
         }
     }
     return $return;
 }
 /**
  * Categories Search method
  *
  * The sql must return the following fields that are
  * used in a common display routine: href, title, section, created, text,
  * browsernav
  * @param string Target search string
  * @param string mathcing option, exact|any|all
  * @param string ordering option, newest|oldest|popular|alpha|category
  * @param mixed An array if restricted to areas, null if search all
  */
 function onContentSearch($text, $phrase = '', $ordering = '', $areas = null)
 {
     $db = JFactory::getDbo();
     $user = JFactory::getUser();
     $app = JFactory::getApplication();
     $groups = implode(',', $user->getAuthorisedViewLevels());
     $searchText = $text;
     if (is_array($areas)) {
         if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) {
             return array();
         }
     }
     $sContent = $this->params->get('search_content', 1);
     $sArchived = $this->params->get('search_archived', 1);
     $limit = $this->params->def('search_limit', 50);
     $state = array();
     if ($sContent) {
         $state[] = 1;
     }
     if ($sArchived) {
         $state[] = 2;
     }
     $text = trim($text);
     if ($text == '') {
         return array();
     }
     switch ($phrase) {
         case 'exact':
             $text = $db->Quote('%' . $db->escape($text, true) . '%', false);
             $wheres2 = array();
             $wheres2[] = 'a.title LIKE ' . $text;
             $wheres2[] = 'a.description LIKE ' . $text;
             $where = '(' . implode(') OR (', $wheres2) . ')';
             break;
         case 'any':
         case 'all':
         default:
             $words = explode(' ', $text);
             $wheres = array();
             foreach ($words as $word) {
                 $word = $db->Quote('%' . $db->escape($word, true) . '%', false);
                 $wheres2 = array();
                 $wheres2[] = 'a.title LIKE ' . $word;
                 $wheres2[] = 'a.description LIKE ' . $word;
                 $wheres[] = implode(' OR ', $wheres2);
             }
             $where = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wheres) . ')';
             break;
     }
     switch ($ordering) {
         case 'alpha':
             $order = 'a.title ASC';
             break;
         case 'category':
         case 'popular':
         case 'newest':
         case 'oldest':
         default:
             $order = 'a.title DESC';
     }
     $text = $db->Quote('%' . $db->escape($text, true) . '%', false);
     $query = $db->getQuery(true);
     $return = array();
     if (!empty($state)) {
         //sqlsrv changes
         $case_when = ' CASE WHEN ';
         $case_when .= $query->charLength('a.alias');
         $case_when .= ' THEN ';
         $a_id = $query->castAsChar('a.id');
         $case_when .= $query->concatenate(array($a_id, 'a.alias'), ':');
         $case_when .= ' ELSE ';
         $case_when .= $a_id . ' END as slug';
         $query->select('a.title, a.description AS text, "" AS created, "2" AS browsernav, a.id AS catid, ' . $case_when);
         $query->from('#__categories AS a');
         $query->where('(a.title LIKE ' . $text . ' OR a.description LIKE ' . $text . ') AND a.published IN (' . implode(',', $state) . ') AND a.extension = \'com_content\'' . 'AND a.access IN (' . $groups . ')');
         $query->group('a.id');
         $query->order($order);
         if ($app->isSite() && $app->getLanguageFilter()) {
             $query->where('a.language in (' . $db->Quote(JFactory::getLanguage()->getTag()) . ',' . $db->Quote('*') . ')');
         }
         $db->setQuery($query, 0, $limit);
         $rows = $db->loadObjectList();
         if ($rows) {
             $count = count($rows);
             for ($i = 0; $i < $count; $i++) {
                 $rows[$i]->href = ContentHelperRoute::getCategoryRoute($rows[$i]->slug);
                 $rows[$i]->section = JText::_('JCATEGORY');
             }
             foreach ($rows as $key => $category) {
                 if (searchHelper::checkNoHTML($category, $searchText, array('name', 'title', 'text'))) {
                     $return[] = $category;
                 }
             }
         }
     }
     return $return;
 }
示例#23
0
function plgSearchItems($text, $phrase = '', $ordering = '', $areas = null)
{
    $mainframe =& JFactory::getApplication();
    $db =& JFactory::getDBO();
    $user =& JFactory::getUser();
    $aid = $user->get('aid');
    require_once JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_search' . DS . 'helpers' . DS . 'search.php';
    require_once JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'helpers' . DS . 'route.php';
    $searchText = $text;
    if (is_array($areas)) {
        if (!array_intersect($areas, array_keys(plgSearchItemsAreas()))) {
            return array();
        }
    }
    $plugin =& JPluginHelper::getPlugin('search', 'k2');
    $pluginParams = new JParameter($plugin->params);
    $limit = $pluginParams->def('search_limit', 50);
    $text = trim($text);
    if ($text == '') {
        return array();
    }
    $rows = array();
    if ($limit > 0) {
        $query = "SELECT i.title AS title,\n\t    i.metadesc, \n\t    i.metakey, \n\t    c.name as section, \n\t    i.image_caption, \n\t    i.image_credits, \n\t    i.video_caption, \n\t    i.video_credits, \n\t    i.extra_fields_search,";
        if ($pluginParams->get('search_tags')) {
            $query .= " tags.name as tag,";
        }
        $query .= " i.created,\n    \tCONCAT(i.introtext, i.fulltext) AS text, \n    \tCASE WHEN CHAR_LENGTH(i.alias) THEN CONCAT_WS(':', i.id, i.alias) ELSE i.id END as slug, \n    \tCASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(':', c.id, c.alias) ELSE c.id END as catslug  \n    \tFROM #__k2_items AS i INNER JOIN #__k2_categories AS c ON c.id=i.catid AND c.access <= " . $user->get('gid');
        if ($pluginParams->get('search_tags')) {
            $query .= " LEFT JOIN #__k2_tags_xref tags_xref ON tags_xref.itemID = i.id";
            $query .= " LEFT JOIN #__k2_tags tags ON tags.id = tags_xref.tagID";
        }
        $query .= " WHERE MATCH(i.title, i.introtext, i.`fulltext`";
        if ($pluginParams->get('search_tags')) {
            $query .= ",tags.name";
        }
        $query .= ",i.extra_fields_search,i.image_caption,i.image_credits,i.video_caption,i.video_credits,i.metadesc,i.metakey)";
        if ($phrase == 'exact') {
            $text = $db->Quote('"' . $db->getEscaped($text, true) . '"', false);
            $query .= " AGAINST ({$text}  IN BOOLEAN MODE)";
        } else {
            $text = $db->Quote($db->getEscaped($text, true), false);
            $query .= " AGAINST ({$text})";
        }
        $query .= " AND i.trash = 0\n\t    AND i.published = 1 \n\t    AND i.access <= " . $aid . " \n\t    AND c.published = 1 \n\t    AND c.access <= " . $aid . "\n\t    AND c.trash = 0\n\t    GROUP BY i.id ";
        switch ($ordering) {
            case 'oldest':
                $query .= 'ORDER BY i.created ASC';
                break;
            case 'popular':
                $query .= 'ORDER BY i.hits DESC';
                break;
            case 'alpha':
                $query .= 'ORDER BY i.title ASC';
                break;
            case 'category':
                $query .= 'ORDER BY c.name ASC, i.title ASC';
                break;
            case 'newest':
            default:
                $query .= 'ORDER BY i.created DESC';
                break;
        }
        $db->setQuery($query, 0, $limit);
        $list = $db->loadObjectList();
        $limit -= count($list);
        if (isset($list)) {
            foreach ($list as $key => $item) {
                $list[$key]->href = JRoute::_(K2HelperRoute::getItemRoute($item->slug, $item->catslug));
            }
        }
        $rows[] = $list;
    }
    $results = array();
    if (count($rows)) {
        foreach ($rows as $row) {
            $new_row = array();
            foreach ($row as $key => $item) {
                $item->browsernav = '';
                $check = array('text', 'title', 'metakey', 'metadesc', 'section', 'image_caption', 'image_credits', 'video_caption', 'video_credits', 'extra_fields_search');
                if ($pluginParams->get('search_tags')) {
                    $check[] = 'tag';
                }
                if (searchHelper::checkNoHTML($item, $searchText, array('text', 'title', 'metakey', 'metadesc', 'section', 'tag', 'image_caption', 'image_credits', 'video_caption', 'video_credits', 'extra_fields_search'))) {
                    $new_row[] = $item;
                }
            }
            $results = array_merge($results, (array) $new_row);
        }
    }
    return $results;
}
示例#24
0
 /**
  * Weblink Search method
  *
  * The sql must return the following fields that are used in a common display
  * routine: href, title, section, created, text, browsernav
  * @param string Target search string
  * @param string mathcing option, exact|any|all
  * @param string ordering option, newest|oldest|popular|alpha|category
  * @param mixed An array if the search it to be restricted to areas, null if search all
  */
 function onContentSearch($text, $phrase = '', $ordering = '', $areas = null)
 {
     $db = JFactory::getDbo();
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     $groups = implode(',', $user->getAuthorisedViewLevels());
     $searchText = $text;
     if (is_array($areas)) {
         if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) {
             return array();
         }
     }
     $sContent = $this->params->get('search_content', 1);
     $sArchived = $this->params->get('search_archived', 1);
     $limit = $this->params->def('search_limit', 50);
     $state = array();
     if ($sContent) {
         $state[] = 1;
     }
     if ($sArchived) {
         $state[] = 2;
     }
     $text = trim($text);
     if ($text == '') {
         return array();
     }
     $section = JText::_('PLG_SEARCH_WEBLINKS');
     $wheres = array();
     switch ($phrase) {
         case 'exact':
             $text = $db->Quote('%' . $db->getEscaped($text, true) . '%', false);
             $wheres2 = array();
             $wheres2[] = 'a.url LIKE ' . $text;
             $wheres2[] = 'a.description LIKE ' . $text;
             $wheres2[] = 'a.title LIKE ' . $text;
             $where = '(' . implode(') OR (', $wheres2) . ')';
             break;
         case 'all':
         case 'any':
         default:
             $words = explode(' ', $text);
             $wheres = array();
             foreach ($words as $word) {
                 $word = $db->Quote('%' . $db->getEscaped($word, true) . '%', false);
                 $wheres2 = array();
                 $wheres2[] = 'a.url LIKE ' . $word;
                 $wheres2[] = 'a.description LIKE ' . $word;
                 $wheres2[] = 'a.title LIKE ' . $word;
                 $wheres[] = implode(' OR ', $wheres2);
             }
             $where = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wheres) . ')';
             break;
     }
     switch ($ordering) {
         case 'oldest':
             $order = 'a.created ASC';
             break;
         case 'popular':
             $order = 'a.hits DESC';
             break;
         case 'alpha':
             $order = 'a.title ASC';
             break;
         case 'category':
             $order = 'c.title ASC, a.title ASC';
             break;
         case 'newest':
         default:
             $order = 'a.created DESC';
     }
     $return = array();
     if (!empty($state)) {
         $query = $db->getQuery(true);
         $query->select('a.title AS title, a.description AS text, a.created AS created, a.url, ' . 'CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug, ' . 'CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END as catslug, ' . 'CONCAT_WS(" / ", ' . $db->Quote($section) . ', c.title) AS section, "1" AS browsernav');
         $query->from('#__weblinks AS a');
         $query->innerJoin('#__categories AS c ON c.id = a.catid');
         $query->where('(' . $where . ')' . ' AND a.state in (' . implode(',', $state) . ') AND  c.published=1 AND  c.access IN (' . $groups . ')');
         $query->order($order);
         // Filter by language
         if ($app->isSite() && $app->getLanguageFilter()) {
             $tag = JFactory::getLanguage()->getTag();
             $query->where('a.language in (' . $db->Quote($tag) . ',' . $db->Quote('*') . ')');
             $query->where('c.language in (' . $db->Quote($tag) . ',' . $db->Quote('*') . ')');
         }
         $db->setQuery($query, 0, $limit);
         $rows = $db->loadObjectList();
         $return = array();
         if ($rows) {
             foreach ($rows as $key => $row) {
                 $rows[$key]->href = WeblinksHelperRoute::getWeblinkRoute($row->slug, $row->catslug);
             }
             foreach ($rows as $key => $weblink) {
                 if (searchHelper::checkNoHTML($weblink, $searchText, array('url', 'text', 'title'))) {
                     $return[] = $weblink;
                 }
             }
         }
     }
     return $return;
 }
示例#25
0
 /**
  * Event Search method
  *
  * The sql must return the following fields that are used in a common display
  * routine: href, title, section, created, text, browsernav
  *
  * @param   string  $text      Target search string
  * @param   string  $phrase    matching option, exact|any|all
  * @param   string  $ordering  ordering option, newest|oldest|popular|alpha|category
  * @param   mixed   $areas     An array if the search it to be restricted to areas, null if search all
  *
  * @return  array  searchresults
  */
 function onContentSearch($text, $phrase = '', $ordering = '', $areas = null)
 {
     if ($this->eventRouterLoaded == false) {
         return array();
     }
     $db = JFactory::getDBO();
     $user = JFactory::getUser();
     $searchText = $text;
     $searchin = array();
     if (is_array($areas)) {
         if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) {
             return array();
         }
     }
     $limit = $this->params->def('search_limit', 50);
     $text = trim($text);
     if ($text == '') {
         return array();
     }
     switch ($ordering) {
         case 'alpha':
             $order = 'a.name ASC';
             break;
         case 'newest':
             $order = 'a.sdate DESC';
             break;
         case 'category':
         case 'popular':
         case 'oldest':
         default:
             $order = 'a.sdate ASC';
     }
     $today = gmdate("Y-m-d");
     // Serach in
     $tags = array('name', 'organiser', 'teaser', 'text', 'contact', 'street', 'city', 'pcode', 'ainfo');
     $wheres = array();
     switch ($phrase) {
         case 'exact':
             $text = $db->Quote('%' . $db->getEscaped($text, true) . '%', false);
             $wheres2 = array();
             for ($i = 0; $i < count($tags); $i++) {
                 $t = $tags[$i];
                 if ($this->params->def('searchin' . $t, 1) == 1) {
                     $wheres2[] = 'a.' . $t . ' LIKE ' . $text;
                     $searchin[] = $t;
                 }
             }
             $where = '(' . implode(') OR (', $wheres2) . ')';
             break;
         case 'all':
         case 'any':
         default:
             $words = explode(' ', $text);
             $wheres = array();
             foreach ($words as $word) {
                 $word = $db->Quote('%' . $db->getEscaped($word, true) . '%', false);
                 $wheres2 = array();
                 for ($i = 0; $i < count($tags); $i++) {
                     $t = $tags[$i];
                     if ($this->params->def('searchin' . $t, 1) == 1) {
                         $wheres2[] = 'a.' . $t . ' LIKE ' . $word;
                         $searchin[] = $t;
                     }
                 }
                 $wheres[] = implode(' OR ', $wheres2);
             }
             $where = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wheres) . ')';
             break;
     }
     $query = $db->getQuery(true);
     $query->select('a.babioonevent_event_id AS id')->select('a.name AS title')->select('CONCAT(a.teaser,a.text) AS text')->select('a.created AS created')->select('"2" AS browsernav')->select('c.title as section')->select('a.organiser')->select('a.contact')->select('a.name')->from('#__babioonevent_events as a')->join('LEFT', '#__categories AS c ON a.catid = c.id')->where($where)->where('a.sdate >= "' . $today . '"')->where('a.enabled = 1')->where('c.published = 1')->group('a.babioonevent_event_id')->order($order);
     $db->setQuery($query, 0, $limit);
     $rows = $db->loadObjectList();
     $return = array();
     if (!empty($rows)) {
         // Get an itemid
         $Itemid = BabioonEventRouteHelper::getItemid('events');
         $link = 'index.php?option=com_babioonevent&view=event&layout=item&Itemid=' . $Itemid . '&id=';
         $count = count($rows);
         for ($i = 0; $i < $count; $i++) {
             $event = $rows[$i];
             $event->href = $link . $event->id;
             if (searchHelper::checkNoHTML($event, $searchText, $searchin)) {
                 $return[] = $event;
             }
         }
     }
     return $return;
 }