/** * Build search query and add it to the $results * * @param object $request \Components\Search\Models\Basic\Request * @param object &$results \Components\Search\Models\Basic\Result\Set * @param object $authz \Components\Search\Models\Basic\Authorization * @return void */ public static function onSearch($request, &$results, $authz) { $terms = $request->get_term_ar(); $weight = '(match(wp.title) against (\'' . join(' ', $terms['stemmed']) . '\') + match(wv.pagetext) against (\'' . join(' ', $terms['stemmed']) . '\'))'; $addtl_where = array(); foreach ($terms['mandatory'] as $mand) { $addtl_where[] = "(wp.title LIKE '%{$mand}%' OR wv.pagetext LIKE '%{$mand}%')"; } foreach ($terms['forbidden'] as $forb) { $addtl_where[] = "(wp.title NOT LIKE '%{$forb}%' AND wv.pagetext NOT LIKE '%{$forb}%')"; } $viewlevels = implode(',', User::getAuthorisedViewLevels()); if ($gids = $authz->get_group_ids()) { $authorization = '(wp.access IN (0,' . $viewlevels . ') OR (wp.access = 1 AND xg.gidNumber IN (' . join(',', $gids) . ')))'; } else { $authorization = '(wp.access IN (0,' . $viewlevels . '))'; } // fml $groupAuth = array(); if ($authz->is_super_admin()) { $groupAuth[] = '1'; } else { $groupAuth[] = 'xg.plugins LIKE \'%wiki=anyone%\''; if (!$authz->is_guest()) { $groupAuth[] = 'xg.plugins LIKE \'%wiki=registered%\''; if ($gids = $authz->get_group_ids()) { $groupAuth[] = '(xg.plugins LIKE \'%wiki=members%\' AND xg.gidNumber IN (' . join(',', $gids) . '))'; } } } $rows = new \Components\Search\Models\Basic\Result\Sql("SELECT\n\t\t\t\twp.title,\n\t\t\t\twp.scope,\n\t\t\t\twp.scope_id,\n\t\t\t\twv.pagehtml AS description,\n\t\t\t\tCASE\n\t\t\t\t\tWHEN wp.path != '' THEN concat(wp.path, '/', wp.pagename)\n\t\t\t\t\tELSE wp.pagename\n\t\t\t\tEND AS link,\n\t\t\t\t{$weight} AS weight,\n\t\t\t\twv.created AS date,\n\t\t\t\tCASE\n\t\t\t\t\tWHEN wp.scope='project' THEN 'Project Notes'\n\t\t\t\t\tELSE 'Wiki'\n\t\t\t\tEND AS section\n\t\t\tFROM `#__wiki_versions` wv\n\t\t\tINNER JOIN `#__wiki_pages` wp\n\t\t\t\tON wp.id = wv.page_id\n\t\t\tLEFT JOIN `#__xgroups` xg ON xg.gidNumber = wp.scope_id AND wp.scope='group'\n\t\t\tWHERE\n\t\t\t\t{$authorization} AND\n\t\t\t\t{$weight} > 0 AND\n\t\t\t\twp.state < 2 AND\n\t\t\t\twv.id = (SELECT MAX(wv2.id) FROM `#__wiki_versions` wv2 WHERE wv2.page_id = wv.page_id) " . ($addtl_where ? ' AND ' . join(' AND ', $addtl_where) : '') . " AND (xg.gidNumber IS NULL OR (" . implode(' OR ', $groupAuth) . "))\n\t\t\t ORDER BY {$weight} DESC"); include_once Component::path('com_wiki') . DS . 'models' . DS . 'page.php'; foreach ($rows->to_associative() as $row) { if (!$row) { continue; } $page = \Components\Wiki\Models\Page::blank(); $page->set('pagename', $row->link); $page->set('scope', $row->scope); $page->set('scope_id', $row->scope_id); $row->set_link(Route::url($page->link())); // rough de-wikifying. probably a bit faster than rendering to html and then stripping the tags, but not perfect //$row->set_description(preg_replace('/(\[+.*?\]+|\{+.*?\}+|[=*])/', '', $row->get_description())); $row->set_description(strip_tags($row->get_description())); $results->add($row); } }
* @package hubzero-cms * @copyright Copyright 2005-2015 HUBzero Foundation, LLC. * @license http://opensource.org/licenses/MIT MIT */ // No direct access. defined('_HZEXEC_') or die; Pathway::append(Lang::txt('COM_WIKI_SEARCH'), $this->page->link('base') . '&pagename=Special:Search'); $database = App::get('db'); $limit = Request::getInt('limit', Config::get('list_limit')); $start = Request::getInt('limitstart', 0); $term = Request::getVar('q', ''); $filters = array('state' => array(0, 1)); if ($space = Request::getVar('namespace', '')) { $filters['namespace'] = urldecode($space); } $pages = \Components\Wiki\Models\Page::blank()->getTableName(); $versions = \Components\Wiki\Models\Version::blank()->getTableName(); $weight = '(match(' . $pages . '.title) against (' . $database->Quote($term) . ') + match(' . $versions . '.pagetext) against (' . $database->Quote($term) . '))'; $rows = $this->book->pages($filters)->select($pages . '.*')->select($versions . '.created_by')->select($versions . '.summary')->select($weight, 'weight')->join($versions, $versions . '.id', $pages . '.version_id')->whereRaw($weight . ' > 0')->order('weight', 'desc')->paginated()->rows(); ?> <form action="<?php echo Route::url($this->page->link('base') . '&pagename=Special:Search'); ?> " method="get"> <div class="container data-entry"> <input class="entry-search-submit" type="submit" value="<?php echo Lang::txt('COM_WIKI_SEARCH'); ?> " /> <fieldset class="entry-search"> <legend><?php
/** * Event call to get content for public project page * * @param object $model * @return mixed */ public function onProjectPublicList($model) { if (!$model->exists() || !$model->isPublic()) { return false; } if (!$model->params->get('notes_public', 0)) { return false; } $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'notes', 'name' => 'publist')); require_once PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'tables' . DS . 'publicstamp.php'; $database = App::get('db'); $objSt = new \Components\Projects\Tables\Stamp($database); $view->items = $objSt->getPubList($model->get('id'), 'notes'); $view->page = \Components\Wiki\Models\Page::blank(); $view->model = $model; return $view->loadTemplate(); }