public function onSearch() { $form = $this->getForm(); // if (false !== ($error = $form->validate($this->module))) { // return $error.$this->templateSearch(); // } $users = GDO::table('GWF_User'); $term = Common::getRequest('term'); if (false !== ($error = $this->validate_term($this->module, $term))) { return $error; } $fields = array('user_name', 'user_email'); $by = Common::getGet('by', self::DEFAULT_BY); $dir = Common::getGet('dir', self::DEFAULT_DIR); $orderby = $users->getMultiOrderby($by, $dir); if (false === ($conditions = GWF_QuickSearch::getQuickSearchConditions($users, $fields, $term))) { $conditions = '0'; } $hits = $users->countRows($conditions); $ipp = $this->module->cfgUsersPerPage(); $nPages = GWF_PageMenu::getPagecount($ipp, $hits); $page = Common::clamp((int) Common::getGet('page', 1), 1, $nPages); $from = GWF_PageMenu::getFrom($page, $ipp); $tVars = array('searched' => true, 'form' => $form->templateX($this->module->lang('ft_search')), 'hits' => $hits, 'users' => $users->selectObjects('*', $conditions, $orderby, $ipp, $from), 'term' => $term, 'pagemenu' => GWF_PageMenu::display($page, $nPages, GWF_WEB_ROOT . 'index.php?mo=Admin&me=UserSearch&term=' . urlencode($term) . '&by=' . urlencode($by) . '&dir=' . urlencode($dir) . '&page=1'), 'sort_url' => GWF_WEB_ROOT . 'index.php?mo=Admin&me=UserSearch&term=' . urlencode($term) . '&by=%BY%&dir=%DIR%&page=1'); return $this->module->templatePHP('user_search.php', $tVars); }
/** * Search the quotes. Return array of matching IDs. * @param string $term * @return array */ public static function searchQuotes($term) { $quotes = self::table(__CLASS__); if (false === ($conditions = GWF_QuickSearch::getQuickSearchConditions($quotes, array('quot_text'), $term))) { return array(); } return $quotes->selectColumn('quot_id', $conditions, 'quot_id'); }
private function templateThread() { $this->thread->increase('thread_viewcount', 1); if (false !== ($user = GWF_Session::getUser())) { if (false === $this->thread->markRead($user)) { echo GWF_HTML::err('ERR_DATABASE', __FILE__, __LINE__); } } $tVars = array('thread' => $this->thread, 'posts' => $this->thread->getPostPage($this->ppt, $this->page), 'pagemenu' => $this->getPageMenu(), 'actions' => true, 'title' => true, 'reply' => $this->thread->hasReplyPermission(GWF_Session::getUser(), $this->module), 'nav' => true, 'can_vote' => $user === false ? false : $this->module->cfgVotesEnabled(), 'can_thank' => $user === false ? false : $this->module->cfgThanksEnabled(), 'term' => GWF_QuickSearch::getQuickSearchHighlights(Common::getRequest('term', '')), 'page' => $this->page, 'href_add_poll' => $this->thread->hrefAddPoll(), 'href_edit' => $this->thread->getEditHREF()); return $this->module->templatePHP('show_thread.php', $tVars); }
private function getQuickSearchTable() { $user = GWF_User::getStaticOrGuest(); $orders = GDO::table('GWF_Order'); $orders instanceof GWF_Order; $o = Common::getGet('o') !== false; $bit = $o ? 'o' : 't'; $sortURL = $this->getMethodHref('&' . $bit . '=1&by=%BY%&dir=%DIR%'); $fields = $orders->getSearchableFields($user); $term = Common::getRequestString('term', ''); // var_dump($fields, $term); if (false === ($conditions = GWF_QuickSearch::getQuickSearchConditions($orders, $fields, $term))) { $conditions = '0'; } return GWF_TableGDO::display($this->module, $orders, $user, $sortURL, $conditions, 25, true); }
private function onQuickSearch($term) { $fields = array('link_href', 'link_descr'); if ($this->module->cfgLongDescription()) { $fields[] = 'link_descr2'; } $links = GDO::table('GWF_Links'); $by = $links->getWhitelistedBy(Common::getGet('by'), 'link_id'); $dir = GDO::getWhitelistedDirS(Common::getGet('dir'), 'DESC'); $conditions = $this->module->getPermQuery(GWF_Session::getUser()); $limit = 50; $from = 0; if (false === ($matches = GWF_QuickSearch::search($links, $fields, $term, "{$by} {$dir}", $limit, $from, $conditions))) { return $this->templateSearch(array(), ''); } return $this->templateSearch($matches, $term); }
private function onSearch() { $form = $this->formSearch(); if (false !== ($error = $form->validate($this->module))) { return $error . $this->templateSearch(); } $ipp = self::IPP; $term = $form->getVar('searchterm'); $tagname = NULL; $table = GDO::table('Slay_Song'); $whitelist = array('(ss_lyrics>0)', '(ss_options&1)', '(ss_sid_path!=NULL)'); $joins = array('lyrics'); if (false === ($where = GWF_QuickSearch::getQuickSearchConditions($table, array('ss_artist', 'ss_title', 'ss_composer'), $term))) { return GWF_HTML::err('ERR_SEARCH_TERM') . $this->templateSearch(); } $term2 = GDO::escape($term); // $term2 = str_replace(array('%', '_'), array('\\%', '\\_'), $term); $term3 = '1'; if ('0' !== ($tag = $form->getVar('searchtag'))) { $tagname = Slay_Tag::getNameByID($tag); $term3 = 'sst_count>0'; $joins[] = 'searchtag'; } $where = "(({$where}) OR (ssl_lyrics LIKE '%{$term2}%')) AND ({$term3})"; $nItems = $table->countRows($where, $joins); $nPages = GWF_PageMenu::getPagecount($ipp, $nItems); $page = Common::clamp(Common::getGetInt('page'), 1, $nPages); $from = GWF_PageMenu::getFrom($page, $ipp); $by = Common::getGetString('by', self::BY); $dir = Common::getGetString('dir', self::DIR); $orderby = $table->getMultiOrderby($by, $dir, false, $whitelist); $matches = $table->selectAll('*', $where, $orderby, $joins, $ipp, $from, GDO::ARRAY_O); $headers = array(array(), array($this->module->lang('L'), '(ss_lyrics>0)'), array($this->module->lang('T'), 'ss_taggers'), array($this->module->lang('D'), '(ss_options&1)'), array($this->module->lang('th_artist'), 'ss_artist'), array($this->module->lang('th_title'), 'ss_title'), array($this->module->lang('th_duration'), 'ss_duration'), array($this->l('th_bpm'), 'ss_bpm'), array($this->l('th_key'), 'ss_key')); if ($tag > 0) { $headers[] = array($this->module->lang(Slay_Tag::getNameByID($tag)), 'sst_count'); } $headers[] = array($this->module->lang('th_tags')); $tVars = array('form' => $form->templateX($this->module->lang('ft_search'), GWF_WEB_ROOT . 'index.php'), 'pagemenu' => GWF_PageMenu::display($page, $nPages, GWF_WEB_ROOT . sprintf('index.php?mo=Slaytags&me=Search&searchterm=%s&searchtag=%s&by=%s&dir=%s&page=%%PAGE%%', urlencode($term), $tag, urlencode($by), urlencode($dir))), 'matches' => $matches, 'sort_url' => GWF_WEB_ROOT . sprintf('index.php?mo=Slaytags&me=Search&searchterm=%s&searchtag=%s&by=%%BY%%&dir=%%DIR%%&page=1', urlencode($term), $tag), 'is_admin' => GWF_User::isStaffS(), 'headers' => $headers, 'singletag' => $tagname, 'no_match' => count($matches) === 0); return $this->module->template('search.tpl', $tVars); }
private function onQuickSearch($term) { $pms = GDO::table('GWF_PM'); $by = Common::getGet('by', ''); $dir = Common::getGet('dir', ''); $orderby = $pms->getMultiOrderby($by, $dir); $ipp = $this->module->cfgPMPerPage(); if (false === ($conditions = GWF_QuickSearch::getQuickSearchConditions($pms, self::$fields, $term))) { $conditions = '0'; } $uid = GWF_Session::getUserID(); $conditions = "({$conditions}) AND (pm_owner={$uid})"; $nItems = $pms->countRows($conditions); $nPages = GWF_PageMenu::getPagecount($ipp, $nItems); $page = Common::clamp(intval(Common::getGet('page')), 1, $nPages); $from = GWF_PageMenu::getFrom($page, $ipp); $result = $pms->selectObjects('*', $conditions, $orderby, $ipp, $from); # search(self::$fields, $term, $orderby, $ipp, $from); $href = GWF_WEB_ROOT . 'index.php?mo=PM&me=Search&term=' . urlencode($term) . '&page=%PAGE%&by=' . urlencode($by) . '&dir=' . urlencode($dir); $tVars = array('form_q' => $this->getFormQuick()->templateX($this->module->lang('ft_quicksearch'), false, GWF_WEB_ROOT . 'index.php?mo=PM&me=Search'), 'term' => $term, 'pagemenu' => GWF_PageMenu::display($page, $nPages, $href), 'pms' => $result, 'form_action' => htmlspecialchars(GWF_WEB_ROOT . 'index.php?mo=PM&me=Search'), 'sort_url' => GWF_WEB_ROOT . 'index.php?mo=PM&me=Search&term=' . urlencode($term) . '&by=%BY%&dir=%DIR%'); return $this->module->templatePHP('search.php', $tVars); }
public function onQuickSearch($term) { $posts = GDO::table('GWF_ForumPost'); $fields = $posts->getSearchableFields(GWF_User::getStaticOrGuest()); $_GET['term'] = $term = trim($term); // $term = Common::getRequest('term', ''); if (false === ($conditions = GWF_QuickSearch::getQuickSearchConditions($posts, $fields, $term))) { $conditions = '0'; } $permQuery = GWF_ForumPost::getPermQuery(); $conditions .= ' AND (' . $permQuery . ')'; $by = Common::getGet('by', 'post_date'); $dir = Common::getGet('dir', 'DESC'); $orderby = $posts->getMultiOrderby($by, $dir); $ipp = $this->module->getThreadsPerPage(); $nItems = $posts->countRows($conditions); $nPages = GWF_PageMenu::getPagecount($ipp, $nItems); $page = Common::clamp(Common::getGet('page', 1), 1, $nPages); $href = $this->getMethodHref(sprintf('&term=%s&by=%s&dir=%s&page=%%PAGE%%', urlencode($term), urlencode($by), urlencode($dir))); $this->pagemenu = GWF_PageMenu::display($page, $nPages, $href); $result = GWF_QuickSearch::search($posts, $fields, $term, $orderby, $ipp, GWF_PageMenu::getFrom($page, $ipp), $permQuery); $this->sortURL = $this->getMethodHref(sprintf('&term=%s&by=%%BY%%&dir=%%DIR%%&page=1', urlencode($term))); return $this->templateSearch($result, $term); }
/** * Search the links database and return an array of IDs. * @param $term * @return array */ public static function searchLinks($term) { $links = self::table(__CLASS__); if (false === ($conditions = GWF_QuickSearch::getQuickSearchConditions($links, array('link_url', 'link_text'), $term))) { return array(); } $conditions .= ' AND link_type="html"'; return $links->selectColumn('link_id', $conditions, 'link_id DESC'); }
public function execute() { $form = $this->formQuicksearch(); # I like typehinting :S $module = $this->module; $module instanceof Module_PageBuilder; $user = GWF_User::getStaticOrGuest(); $ulid = GWF_Language::getCurrentID(); $table = GDO::table('GWF_Page'); $joins = NULL; $tablename = $table->getTableName(); # Build where clause $term = ''; $where = '1'; $language = ''; $languaged = '1'; if (isset($_GET['quicksearch'])) { # Termwhere if ('' !== ($term = Common::getGetString('term', ''))) { $fields = array('page_author_name', 'page_title', 'page_content'); if (false === ($where = GWF_QuickSearch::getQuickSearchConditions($table, $fields, $term))) { $where = '1'; } } # Langwhere if (0 !== ($language = Common::getGetInt('lang', 0))) { if (GWF_LangSelect::isValidLanguage($language, false, GWF_Language::SUPPORTED)) { $languaged = "(SELECT 1 FROM `{$tablename}` lt WHERE lt.page_otherid=t.page_otherid AND lt.page_lang={$language})"; } } } $published = 'page_options&' . (GWF_Page::ENABLED | GWF_Page::LOCKED) . '=' . GWF_Page::ENABLED; $permquery = '1'; # TODO: Check group permissions! $where = "({$permquery}) AND ({$where}) AND ({$published}) AND ({$languaged})"; # Setup pagemenu $ipp = 25; $nItems = $table->selectVar('COUNT(DISTINCT(page_otherid))', $where, '', $joins); $nPages = GWF_PageMenu::getPagecount($ipp, $nItems); $page = Common::clamp(Common::getGetInt('page', 1), 1, $nPages); $from = GWF_PageMenu::getFrom($page, $ipp); # Setup order $by = Common::getGetString('by', 'page_id'); $dir = Common::getGetString('dir', 'ASC'); $orderby = $table->getMultiOrderby($by, $dir); # Now query only page_otherids if (false === ($pageids = $table->selectColumn('DISTINCT(page_otherid)', $where, $orderby, $joins, $ipp, $from))) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } # Setup page array $pages = array(); $languages = GWF_Language::getSupported(); foreach ($pageids as $otherid) { $pagedata = $table->selectAll('page_id, page_lang, page_author_name, page_create_date, page_date, page_url, page_title', "page_otherid={$otherid}", "page_id={$otherid}"); $title = ''; $_langs = array(); foreach ($pagedata as $data) { $pagelang = $data['page_lang']; // echo "$pagelang<br/>"; # English 2nd choice if ($pagelang === '1' && $title === '') { $title = $data['page_title']; } elseif ($data['page_lang'] === $ulid) { $title = $data['page_title']; } # Store for next loop $_langs[$pagelang] = array($data['page_url']); } # Build output flags $langstring = ''; foreach ($languages as $language) { $language instanceof GWF_Language; $lid = $language->getID(); if (isset($_langs[$lid])) { $langstring .= sprintf('<a href="%s%s">%s</a>', GWF_WEB_ROOT, $_langs[$lid][0], $language->displayFlag(), $lid); } else { $langstring .= sprintf('<a href="%sindex.php?mo=PageBuilder&me=Translate&pageid=%s&to_lang_id=%s">%s</a>', GWF_WEB_ROOT, $otherid, $lid, GWF_Language::displayUnknownFlag($module->lang('translate_to', array($language->displayName())))); } } # Add as page row $pages[] = array('page_id' => $pagedata[0]['page_id'], 'page_otherid' => $otherid, 'page_title' => $title, 'page_url' => $pagedata[0]['page_url'], 'languages' => $langstring, 'page_date' => $pagedata[0]['page_date'], 'page_create_date' => $pagedata[0]['page_create_date'], 'page_author_name' => $pagedata[0]['page_author_name']); } # Display $tVars = array('quicksearch' => $form->templateX($this->module->lang('ft_search'), GWF_WEB_ROOT . 'index.php'), 'pages' => $pages, 'languages' => $languages, 'pagemenu' => GWF_PageMenu::display($page, $nPages, GWF_WEB_ROOT . 'index.php?mo=Lamb&me=Links&term=' . urlencode($term) . '&by=' . urlencode($by) . '&dir=' . urlencode($dir) . '&page=%PAGE%'), 'sort_url' => GWF_WEB_ROOT . 'index.php?mo=Lamb&me=Links&language=' . $language . '&term=' . urlencode($term) . '&by=%BY%&dir=%DIR%&page=' . $page); return $module->template('search.tpl', $tVars); }
public function on_search(SR_Player $player, array $args) { $ipp = 5; $count = count($args); if ($count !== 1) { $player->message(Shadowhelp::getHelp($player, 'bazar_search')); return false; } $term = $args[0]; $table = GDO::table('SR_BazarItem'); if (false === ($conditions = GWF_QuickSearch::getQuickSearchConditions($table, array('sr4ba_iname'), $term))) { $player->message(Shadowhelp::getHelp($player, 'bazar_search')); return false; } $orderby = 'sr4ba_price ASC'; $nItems = $table->countRows($conditions); if ($nItems === 0) { $player->msg('1007'); // $player->message('No item matches your search query :('); return false; } $nPages = GWF_PageMenu::getPagecount($ipp, $nItems); $old_term = $player->getTemp(self::TEMP_SEARCH, ''); if ($old_term === $term) { $page = $player->getTemp(self::TEMP_PAGE, 1); if ($page >= $nPages) { $player->unsetTemp(self::TEMP_PAGE); } else { $player->setTemp(self::TEMP_PAGE, $page + 1); } } else { $player->setTemp(self::TEMP_SEARCH, $term); $page = 1; if ($page < $nPages) { $player->setTemp(self::TEMP_PAGE, 2); } } if ($page > $nPages) { $player->msg('1009'); // $player->unsetTemp(self::TEMP_PAGE); // $player->message('There are no more matches.'); return false; } $from = GWF_PageMenu::getFrom($page, $ipp); if (false === ($result = $table->select('*', $conditions, $orderby, NULL, $ipp, $from))) { $player->message('Database error!'); return false; } $out = ''; $format = $player->lang('fmt_bazar_search'); while (false !== ($row = $table->fetch($result, GDO::ARRAY_A))) { $out .= sprintf($format, $row['sr4ba_pname'], $row['sr4ba_iname'], $row['sr4ba_iamt'], Shadowfunc::displayNuyen($row['sr4ba_price'])); // $out .= sprintf(", %s \X02%s\X02 %s%s", $row['sr4ba_pname'], $row['sr4ba_iname'], $row['sr4ba_price'], $amt); } $table->free($result); return $player->msg('5160', array($page, $nPages, substr($out, 2))); // return $player->message(sprintf('Matches %d/%d: %s.', $page, $nPages, substr($out, 2))); }