function search_blogs($query, $look) { $inDB = cmsDatabase::getInstance(); $searchModel = cms_model_search::initModel(); global $_LANG; $sql = "SELECT con.*, cat.title cat_title, cat.id cat_id, cat.owner owner, cat.user_id user_id, cat.seolink as bloglink\n\t\t\tFROM cms_blog_posts con\n\t\t\tINNER JOIN cms_blogs cat ON cat.id = con.blog_id AND cat.allow_who = 'all' AND cat.owner = 'user'\n\t\t\tWHERE MATCH(con.title, con.content) AGAINST ('{$query}' IN BOOLEAN MODE) AND con.published = 1 LIMIT 100"; $result = $inDB->query($sql); if ($inDB->num_rows($result)) { cmsCore::loadLanguage('components/blogs'); cmsCore::loadModel('blogs'); $model = new cms_model_blogs(); while ($item = $inDB->fetch_assoc($result)) { $result_array = array(); $result_array['link'] = $model->getPostURL($item['bloglink'], $item['seolink']); $result_array['place'] = $_LANG['BLOG'] . ' «' . $item['cat_title'] . '»'; $result_array['placelink'] = $model->getBlogURL($item['bloglink']); $result_array['description'] = $searchModel->getProposalWithSearchWord($item['content_html']); $result_array['title'] = $item['title']; $result_array['pubdate'] = $item['pubdate']; $result_array['session_id'] = session_id(); $searchModel->addResult($result_array); } } return; }
function mod_search($module_id, $cfg) { cmsCore::loadModel('search'); cmsCore::loadLanguage('components/search'); $model = cms_model_search::initModel(); cmsPage::initTemplate('modules', $cfg['tpl'])->assign('enable_components', $model->getEnableComponentsWithSupportSearch())->display($cfg['tpl']); return true; }
function sphinx_add_result_forum($items) { $inCore = cmsCore::getInstance(); global $_LANG; cmsCore::loadLanguage('components/forum'); $config = $inCore->loadComponentConfig('forum'); $search_model = cms_model_search::initModel(); foreach ($items as $id => $item) { if (!cmsCore::checkContentAccess($item['attrs']['access_list'])) { continue; } $pages = ceil($item['attrs']['post_count'] / $config['pp_thread']); $result_array = array( 'link' => '/forum/thread'. $id .'-'. $pages .'.html', 'place' => $item['attrs']['forum'], 'placelink' => '/forum/'. $item['attrs']['forum_id'], 'description' => $search_model->getProposalWithSearchWord($item['attrs']['description']), 'title' => $item['attrs']['title'], 'pubdate' => date('Y-m-d H:i:s', $item['attrs']['pubdate']) ); $search_model->addResult($result_array); } // Ищем в тексте постов $cl = new SphinxClient(); $cl->SetServer('127.0.0.1', 9312); $cl->SetMatchMode(SPH_MATCH_EXTENDED2); $cl->SetLimits(0, 100); $result = $cl->Query($search_model->against, $search_model->config['Sphinx_Search']['prefix'] .'_forum_posts'); if ($result !== false) { foreach ($result['matches'] as $id => $item) { $pages = ceil($item['attrs']['post_count'] / $config['pp_thread']); $post_page = ($pages > 1) ? postPage::getPage($item['attrs']['thread_id'], $id, $config['pp_thread']) : 1; $result_array = array( 'link' => '/forum/thread'. $item['attrs']['thread_id'] .'-'. $post_page .'.html#'. $id, 'place' => $_LANG['FORUM_POST'], 'placelink' => '/forum/thread'. $item['attrs']['thread_id'] .'-'. $post_page .'.html#'. $id, 'description' => $search_model->getProposalWithSearchWord($item['attrs']['content_html']), 'title' => $item['attrs']['thread'], 'imageurl' => $item['attrs']['fileurl'], 'pubdate' => date('Y-m-d H:i:s', $item['attrs']['pubdate']) ); $search_model->addResult($result_array); } } return; }
/** * Инициализирует и возвращает объект модели * Singleton * @return obj $instance */ public static function initModel() { if (self::$instance === null) { // Загружаем конфигурацию компонента $config = cmsCore::getInstance()->loadComponentConfig('search'); // Инициализируем класс провайдера if (self::loadProviderClass($config['search_engine'])) { self::$instance = new $config['search_engine'](); } else { self::$instance = new self; } } return self::$instance; }
function search_forum($query, $look) { $inCore = cmsCore::getInstance(); $inDB = cmsDatabase::getInstance(); $searchModel = cms_model_search::initModel(); global $_LANG; cmsCore::loadLanguage('components/forum'); $config = $inCore->loadComponentConfig('forum'); // Ищем в названиях тем $sql = "SELECT t.*, f.title as forum, f.id as forum_id, f.access_list\r\n FROM cms_forum_threads t\r\n INNER JOIN cms_forums f ON f.id = t.forum_id\r\n WHERE MATCH(t.title) AGAINST ('{$query}' IN BOOLEAN MODE) AND t.is_hidden=0 LIMIT 50"; $result = $inDB->query($sql); if ($inDB->num_rows($result)) { while ($item = $inDB->fetch_assoc($result)) { if (!cmsCore::checkContentAccess($item['access_list'])) { continue; } $result_array = array(); $pages = ceil($item['post_count'] / $config['pp_thread']); $result_array['link'] = "/forum/thread{$item['id']}-{$pages}.html"; $result_array['place'] = $item['forum']; $result_array['placelink'] = "/forum/" . $item['forum_id']; $result_array['title'] = $item['title']; $result_array['pubdate'] = $item['pubdate']; $result_array['description'] = $searchModel->getProposalWithSearchWord($item['description']); $result_array['session_id'] = session_id(); $searchModel->addResult($result_array); } } // Ищем в тексте постов $sql = "SELECT p.*, t.title as thread, t.id as thread_id, t.post_count, img.fileurl\r\n FROM cms_forum_posts p\r\n INNER JOIN cms_forum_threads t ON t.id = p.thread_id AND t.is_hidden=0\r\n LEFT JOIN cms_upload_images img ON img.target_id = p.id AND img.target = 'post' AND img.component = 'forum'\r\n WHERE MATCH(p.content) AGAINST ('{$query}' IN BOOLEAN MODE) LIMIT 50"; $result = $inDB->query($sql); if ($inDB->num_rows($result)) { while ($item = $inDB->fetch_assoc($result)) { $result_array = array(); $pages = ceil($item['post_count'] / $config['pp_thread']); $post_page = $pages > 1 ? postPage::getPage($item['thread_id'], $item['id'], $config['pp_thread']) : 1; $result_array['link'] = "/forum/thread{$item['thread_id']}-{$post_page}.html#{$item['id']}"; $result_array['place'] = $_LANG['FORUM_POST']; $result_array['placelink'] = $result_array['link']; $result_array['description'] = $searchModel->getProposalWithSearchWord($item['content_html']); $result_array['title'] = $item['thread']; $result_array['pubdate'] = $item['pubdate']; $result_array['imageurl'] = $item['fileurl']; $result_array['session_id'] = session_id(); $searchModel->addResult($result_array); } } return; }
function sphinx_add_result_clubs($items) { global $_LANG; cmsCore::m('clubs'); $search_model = cms_model_search::initModel(); foreach ($items as $id => $item) { $result_array = array( 'link' => cmsCore::m('clubs')->getPostURL($item['attrs']['user_id'], $item['attrs']['seolink']), 'place' => ' «'. $item['attrs']['cat_title'] .'»', 'placelink' => cmsCore::m('clubs')->getBlogURL($item['attrs']['user_id']), 'description' => $search_model->getProposalWithSearchWord($item['attrs']['content_html']), 'title' => $item['attrs']['title'], 'imageurl' => $item['fileurl'], 'pubdate' => date('Y-m-d H:i:s', $item['attrs']['pubdate']) ); $search_model->addResult($result_array); } /////// поиск по клубным фоткам ////////// $cl = new SphinxClient(); $cl->SetServer('127.0.0.1', 9312); $cl->SetMatchMode(SPH_MATCH_EXTENDED2); $cl->SetLimits(0, 100); $result = $cl->Query($search_model->against, $search_model->config['Sphinx_Search']['prefix'] .'_clubs_photos'); if ($result !== false) { foreach ($result['matches'] as $id => $item) { $result_array = array( 'link' => '/clubs/photo'. $id .'.html', 'place' => $_LANG['CLUBS_PHOTOALBUM'] .' «'. $item['attrs']['cat_title'] .'»', 'placelink' => '/clubs/photoalbum'. $item['attrs']['cat_id'], 'description' => $search_model->getProposalWithSearchWord($item['attrs']['description']), 'title' => $item['attrs']['title'], 'imageurl' => (file_exists(PATH .'/images/photos/medium/'. $item['attrs']['file']) ? '/images/photos/medium/'. $item['attrs']['file'] : ''), 'pubdate' => date('Y-m-d H:i:s', $item['attrs']['pubdate']) ); $search_model->addResult($result_array); } } return; }
function search_clubs($query, $look) { $inDB = cmsDatabase::getInstance(); $searchModel = cms_model_search::initModel(); global $_LANG; cmsCore::loadModel('clubs'); $model = new cms_model_clubs(); /////// поиск по клубным блогам ////////// $sql = "SELECT con.*, cat.title cat_title, cat.id cat_id, cat.owner owner, cat.user_id, img.fileurl\r\n\t\t\tFROM cms_blog_posts con\r\n\t\t\tINNER JOIN cms_blogs cat ON cat.id = con.blog_id AND cat.allow_who = 'all' AND cat.owner = 'club'\r\n LEFT JOIN cms_upload_images img ON img.target_id = con.id AND img.target = 'blog_post' AND img.component = 'clubs'\r\n\t\t\tWHERE MATCH(con.title, con.content) AGAINST ('{$query}' IN BOOLEAN MODE) AND con.published = 1 LIMIT 100"; $result = $inDB->query($sql); if ($inDB->num_rows($result)) { while ($item = $inDB->fetch_assoc($result)) { $result_array = array(); $result_array['link'] = $model->getPostURL($item['user_id'], $item['seolink']); $result_array['place'] = ' «' . $item['cat_title'] . '»'; $result_array['placelink'] = $model->getBlogURL($item['user_id']); $result_array['description'] = $searchModel->getProposalWithSearchWord($item['content_html']); $result_array['title'] = $item['title']; $result_array['pubdate'] = $item['pubdate']; $result_array['imageurl'] = $item['fileurl']; $result_array['session_id'] = session_id(); $searchModel->addResult($result_array); } } /////// поиск по клубным фоткам ////////// $sql = "SELECT f.*, a.title as cat, a.id as cat_id\r\n\t\t\tFROM cms_photo_files f\r\n\t\t\tINNER JOIN cms_photo_albums a ON a.id = f.album_id AND a.published = 1 AND a.NSDiffer != ''\r\n\t\t\tWHERE MATCH(f.title, f.description) AGAINST ('{$query}' IN BOOLEAN MODE) AND f.published = 1"; $result = $inDB->query($sql); if ($inDB->num_rows($result)) { while ($item = $inDB->fetch_assoc($result)) { $result_array = array(); $result_array['link'] = "/clubs/photo" . $item['id'] . ".html"; $result_array['place'] = $_LANG['CLUBS_PHOTOALBUM'] . ' «' . $item['cat'] . '»'; $result_array['placelink'] = '/clubs/photoalbum' . $item['cat_id']; $result_array['description'] = $searchModel->getProposalWithSearchWord($item['description']); $result_array['title'] = $item['title']; $result_array['pubdate'] = $item['pubdate']; $result_array['imageurl'] = HOST . '/images/photos/medium/' . $item['file'] ? '/images/photos/medium/' . $item['file'] : ''; $result_array['session_id'] = session_id(); $searchModel->addResult($result_array); } } return; }
function search_catalog($query, $look) { $inDB = cmsDatabase::getInstance(); $searchModel = cms_model_search::initModel(); $sql = "SELECT i.*, c.title as cat, c.id as cat_id\n\t\t\t\tFROM cms_uc_items i\n\t\t\t\tINNER JOIN cms_uc_cats c ON c.id = i.category_id AND c.published = 1\n\t\t\t\tWHERE MATCH(i.title, i.fieldsdata) AGAINST ('{$query}' IN BOOLEAN MODE) AND i.published = 1 LIMIT 100"; $result = $inDB->query($sql); if ($inDB->num_rows($result)) { while ($item = $inDB->fetch_assoc($result)) { $result_array = array(); $result_array['link'] = "/catalog/item" . $item['id'] . ".html"; $result_array['place'] = $item['cat']; $result_array['placelink'] = "/catalog/" . $item['cat_id']; $result_array['title'] = $item['title']; $result_array['pubdate'] = $item['pubdate']; $result_array['session_id'] = session_id(); $searchModel->addResult($result_array); } } return; }
function search_board($query, $look) { $inDB = cmsDatabase::getInstance(); $searchModel = cms_model_search::initModel(); $sql = "SELECT f.*, f.title as title, a.title as cat, a.id as cat_id\n\t\t\t\tFROM cms_board_items f\n\t\t\t\tINNER JOIN cms_board_cats a ON a.id = f.category_id AND a.published = 1\n\t\t\t\tWHERE MATCH(f.title, f.content) AGAINST ('{$query}' IN BOOLEAN MODE) AND f.published = 1 LIMIT 100"; $result = $inDB->query($sql); if ($inDB->num_rows($result)) { while ($item = $inDB->fetch_assoc($result)) { $result_array = array(); $result_array['link'] = "/board/read" . $item['id'] . ".html"; $result_array['place'] = $item['cat']; $result_array['placelink'] = '/board/' . $item['cat_id']; $result_array['description'] = $searchModel->getProposalWithSearchWord($item['content']); $result_array['title'] = $item['title']; $result_array['pubdate'] = $item['pubdate']; $result_array['session_id'] = session_id(); $searchModel->addResult($result_array); } } return; }
function search_armedlist($query, $look) { $inDB = cmsDatabase::getInstance(); $searchModel = cms_model_search::initModel(); global $_LANG; $sql = "SELECT con.*, cat.title cat_title, cat.id cat_id\n\t\t\tFROM cms_armedlist_quests con\n\t\t\tINNER JOIN cms_armedlist_cats cat ON cat.id = con.category_id AND cat.published = 1\n\t\t\tWHERE MATCH(con.quest, con.answer) AGAINST ('{$query}' IN BOOLEAN MODE) AND con.published = 1 LIMIT 100"; $result = $inDB->query($sql); if ($inDB->num_rows($result)) { cmsCore::loadLanguage('components/armedlist'); while ($item = $inDB->fetch_assoc($result)) { $result_array = array(); $result_array['link'] = '/armedlist/quest' . $item['id'] . '.html'; $result_array['place'] = $_LANG['ARMEDLIST'] . ' → ' . $item['cat_title']; $result_array['placelink'] = '/armedlist/' . $item['cat_id']; $result_array['description'] = $searchModel->getProposalWithSearchWord($item['answer']); $result_array['title'] = mb_substr($item['quest'], 0, 70) . '...'; $result_array['pubdate'] = $item['pubdate']; $result_array['session_id'] = session_id(); $searchModel->addResult($result_array); } } return; }
function search_content($query, $look) { $inDB = cmsDatabase::getInstance(); $searchModel = cms_model_search::initModel(); global $_LANG; $sql = "SELECT con.*, cat.title cat_title, cat.id cat_id, cat.seolink as cat_seolink, cat.parent_id as cat_parent_id\n\t\t\t\tFROM cms_content con\n\t\t\t\tINNER JOIN cms_category cat ON cat.id = con.category_id AND cat.published = 1\n\t\t\t\tWHERE MATCH(con.title, con.content) AGAINST ('{$query}' IN BOOLEAN MODE) AND con.is_end = 0 AND con.published = 1 LIMIT 100"; $result = $inDB->query($sql); if ($inDB->num_rows($result)) { cmsCore::loadLanguage('components/content'); while ($item = $inDB->fetch_assoc($result)) { $result_array = array(); $result_array['link'] = "/" . $item['seolink'] . ".html"; $result_array['place'] = $_LANG['CATALOG_ARTICLES']; $result_array['placelink'] = $item['cat_parent_id'] > 0 ? "/" . $item['cat_seolink'] : $link; $result_array['description'] = $searchModel->getProposalWithSearchWord($item['content']); $result_array['title'] = $item['title']; $result_array['pubdate'] = $item['pubdate']; $result_array['session_id'] = session_id(); $searchModel->addResult($result_array); } } return; }
function search_photos($query, $look) { $inDB = cmsDatabase::getInstance(); $searchModel = cms_model_search::initModel(); $sql = "SELECT f.*, a.title as cat, a.id as cat_id\n\t\t\tFROM cms_photo_files f\n\t\t\tINNER JOIN cms_photo_albums a ON a.id = f.album_id AND a.published = 1 AND a.NSDiffer = ''\n\t\t\tWHERE MATCH(f.title, f.description) AGAINST ('{$query}' IN BOOLEAN MODE) AND f.published = 1"; $result = $inDB->query($sql); if ($inDB->num_rows($result)) { global $_LANG; cmsCore::loadLanguage('components/photos'); while ($item = $inDB->fetch_assoc($result)) { $result_array = array(); $result_array['link'] = "/photos/photo" . $item['id'] . ".html"; $result_array['place'] = $_LANG['PHOTOALBUM'] . ' «' . $item['cat'] . '»'; $result_array['placelink'] = '/photos/' . $item['cat_id']; $result_array['description'] = $searchModel->getProposalWithSearchWord($item['description']); $result_array['title'] = $item['title']; $result_array['pubdate'] = $item['pubdate']; $result_array['session_id'] = session_id(); $searchModel->addResult($result_array); } } return; }
function search() { $inCore = cmsCore::getInstance(); $inPage = cmsPage::getInstance(); $inDB = cmsDatabase::getInstance(); global $_LANG; $model = cms_model_search::initModel(); $do = $inCore->do; $pagetitle = $inCore->getComponentTitle(); $inPage->setTitle($pagetitle); $inPage->addPathway($pagetitle, '/search'); /* ==================================================================================================== */ /* ==================================================================================================== */ if ($do == 'view') { if (mb_strlen($model->query) <= 3 && mb_strlen($model->query) >= 1) { cmsCore::addSessionMessage($_LANG['ERROR'] .': '. $_LANG['SHORT_QUERY'], 'error'); $inCore->redirect('/search'); } if ($model->query) { $inPage->addPathway($model->query); // если параметры запроса изменились // делаем полный поиск, заполняя кеш // иначе берем из кеша результаты if (!$model->isChangedParams()) { // Удаляем записи поиска от текущей сессии $model->deleteResultsFromThisSession(); // Готовим поиск // выполняется поиск по индексу фултекст if (!$model->prepareSearch()) { cmsCore::error404(); } // Кладем в сессию текущие параметры запроса cmsUser::sessionPut('query_params', $model->parametrs_array); // кладем в сессию слова запроса cmsUser::sessionPut('searchquery', $model->words); } // формируем условия выборки $model->whereSessionIs(session_id()); $model->wherePeriodIs(); if ($model->order_by_date) { cmsCore::c('db')->orderBy('pubdate', 'DESC'); } else { cmsCore::c('db')->orderBy('id', 'ASC'); } // Получаем общее количество результатов $total = $model->getCountResults(); // Получаем сами результаты поиска if ($total) { $results = $model->getResults(); } else { cmsCore::c('db')->resetConditions(); } } cmsPage::initTemplate('components', 'com_search_text')-> assign('query', $model->query)-> assign('look', $model->look)-> assign('order_by_date', $model->order_by_date)-> assign('from_pubdate', $model->from_pubdate)-> assign('results', $results)-> assign('total', $total)-> assign('enable_components', $model->getEnableComponentsWithSupportSearch())-> assign('from_component', $model->from_component)-> assign('external_link', str_replace('%q%', urlencode($model->query), $_LANG['FIND_EXTERNAL_URL']))-> assign('host', HOST)-> assign('pagebar', cmsPage::getPagebar($total, $model->page, $model->config['perpage'], 'javascript:paginator(%page%)'))-> display(); } /* ==================================================================================================== */ /* ==================================================================================================== */ if ($do == 'tag') { if (mb_strlen($model->query) <= 3 && mb_strlen($model->query) >= 1) { cmsCore::addSessionMessage($_LANG['EMPTY_QUERY'], 'error'); $inCore->redirect('/search'); } $inPage->setTitle($_LANG['SEARCH_BY_TAG'] .' "'. $model->query .'"'); if ($model->query) { $inPage->addPathway($_LANG['SEARCH_BY_TAG'] .' "'. $model->query .'"'); } $inPage->initAutocomplete(); $total = $model->getCountTags(); $results = $model->searchByTag(); cmsPage::initTemplate('components', 'com_search_tag')-> assign('query', $model->query)-> assign('results', $results)-> assign('total', $total)-> assign('autocomplete_js', $inPage->getAutocompleteJS('tagsearch', 'query', false))-> assign('external_link', '/index.php?view=search&query='. urlencode($model->query) .'&look=allwords')-> assign('pagebar', cmsPage::getPagebar($total, $model->page, $model->config['perpage'], '/search/tag/'. urlencode($model->query) .'/page%page%.html'))-> display(); } return true; }
$pdir = @opendir(PATH . '/components/search/providers/'); if (!$pdir) { return false; } $provider_array = array(); while ($provider = readdir($pdir)) { if ($provider != '.' && $provider != '..' && !is_dir(PATH . '/components/search/providers/' . $provider)) { $provider = mb_substr($provider, 0, mb_strrpos($provider, '.')); $provider_array[] = $provider; } } closedir($pdir); return $provider_array; } cmsCore::loadModel('search'); $model = cms_model_search::initModel(); $opt = cmsCore::request('opt', 'str', ''); $toolmenu[] = array('icon' => 'save.gif', 'title' => $_LANG['SAVE'], 'link' => 'javascript:document.optform.submit();'); $toolmenu[] = array('icon' => 'cancel.gif', 'title' => $_LANG['CANCEL'], 'link' => '?view=components'); cpToolMenu($toolmenu); if ($opt == 'save') { if (!cmsUser::checkCsrfToken()) { cmsCore::error404(); } $cfg = array(); $cfg['perpage'] = cmsCore::request('perpage', 'int', 15); $cfg['comp'] = cmsCore::request('comp', 'array_str'); $cfg['search_engine'] = preg_replace('/[^a-z_]/i', '', cmsCore::request('search_engine', 'str', '')); if ($model->config['search_engine'] && class_exists($model->config['search_engine']) && method_exists($model->config['search_engine'], 'getProviderConfig')) { foreach ($model->getProviderConfig() as $key => $value) { $cfg[$model->config['search_engine']][$value] = cmsCore::request($value, 'str', '');