search2.php.svn-base
来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· SVN-BASE 代码 · 共 706 行 · 第 1/2 页
SVN-BASE
706 行
<?php/** * $Id$ * * KnowledgeTree Community Edition * Document Management Made Simple * Copyright (C) 2008 KnowledgeTree Inc. * Portions copyright The Jam Warehouse Software (Pty) Limited * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the * Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, * California 94120-7775, or email info@knowledgetree.com. * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by * KnowledgeTree" logo and retain the original copyright notice. If the display of the * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices * must display the words "Powered by KnowledgeTree" and retain the original * copyright notice. * Contributor( s): ______________________________________ */// TODO: do we have to serialise/unserialise the results. this is not optimal!!!session_start();require_once("config/dmsDefaults.php");require_once(KT_DIR . '/search2/indexing/indexerCore.inc.php');require_once(KT_LIB_DIR . "/unitmanagement/Unit.inc");require_once(KT_LIB_DIR . "/templating/templating.inc.php");require_once(KT_LIB_DIR . "/dispatcher.inc.php");require_once(KT_LIB_DIR . "/widgets/forms.inc.php");require_once(KT_LIB_DIR . "/actions/bulkaction.php");require_once(KT_LIB_DIR . '/browse/DocumentCollection.inc.php');require_once(KT_LIB_DIR . '/documentmanagement/Document.inc');require_once(KT_LIB_DIR . '/browse/PartialQuery.inc.php');function search2queryCompare($a, $b){ global $search2queryColumn, $search2queryOrder; if ($a->$search2queryColumn == $b->$search2queryColumn) { return 0; } $result = ($a->$search2queryColumn < $b->$search2queryColumn)?-1:1; if ($search2queryOrder == 'asc') return $result; else return - $result;}/** * Assists with old browse search results * * @param unknown_type $sSortColumn * @param unknown_type $sSortOrder */function search2QuerySort($sSortColumn, $sSortOrder){ $defaultSortColumn = $_SESSION['search2_sort_column']; $defaultSortOrder = $_SESSION['search2_sort_order']; if (($defaultSortColumn == $sSortColumn) && ($defaultSortOrder == $sSortOrder)) { return; } global $search2queryColumn, $search2queryOrder; $search2queryOrder = strtolower($sSortOrder); switch(strtolower($sSortColumn)) { case 'ktcore.columns.title': $search2queryColumn = 'Title'; break; case 'ktcore.columns.workflow_state': $search2queryColumn = 'WorkflowAndState'; break; case 'ktcore.columns.checkedout_by': $search2queryColumn = 'CheckedOutBy'; break; case 'ktcore.columns.creationdate': $search2queryColumn = 'DateCreated'; break; case 'ktcore.columns.modificationdate': $search2queryColumn = 'DateModified'; break; case 'ktcore.columns.creator': $search2queryColumn = 'CreatedBy'; break; case 'ktcore.columns.docid': $search2queryColumn = 'DocumentID'; break; case 'ktcore.columns.document_type': $search2queryColumn = 'DocumentType'; break; default: return; } $results = unserialize($_SESSION['search2_results']); usort($results, 'search2queryCompare'); $_SESSION['search2_results'] = serialize($results);}/** * Search2Query is used to provide allow the old browse search to work * */class Search2Query extends PartialQuery{ function _count($type) { $count = 0; $results = unserialize($_SESSION['search2_results']); switch ($type) { case 'Document': return count($results['docs']) + count($results['shortdocs']); case 'Folder': return count($results['folders']) + count($results['shortfolders']); default: return 0; } } function getFolderCount() { return $this->_count('Folder'); } function getDocumentCount() { return $this->_count('Document'); } function getItems($type, $iStart, $iSize, $sSortColumn, $sSortOrder) { // TODO: quick hack. do this more optimally!!!! $results = unserialize($_SESSION['search2_results']); switch ($type) { case 'Document': $type = 'docs'; break; case 'Folder': $type = 'folders'; break; } $resultArray = $results[$type]; foreach($results['short' . $type] as $rec) { $resultArray[] = $rec; } $resultArray = array_slice($resultArray, $iStart, $iSize); $results = array(); foreach($resultArray as $rec) { $results[] = array('id'=>$rec->Id); } return $results; } function getFolders($iBatchSize, $iBatchStart, $sSortColumn, $sSortOrder, $sJoinClause = null, $aJoinParams = null) { return $this->getItems('Folder', $iBatchStart, $iBatchSize, $sSortColumn, $sSortOrder); } function getDocuments($iBatchSize, $iBatchStart, $sSortColumn, $sSortOrder, $sJoinClause = null, $aJoinParams = null) { return $this->getItems('Document', $iBatchStart, $iBatchSize, $sSortColumn, $sSortOrder); }}class SearchDispatcher extends KTStandardDispatcher { private $curUserId; private $sysAdmin; private $savedSearchId; const RESULTS_PER_PAGE = 25; const MAX_PAGE_MOVEMENT = 10; public function __construct() { parent::KTStandardDispatcher(); $this->curUserId = $_SESSION['userID']; $this->sysAdmin=Permission::userIsSystemAdministrator(); if (array_key_exists('fSavedSearchId',$_GET)) { $this->savedSearchId = sanitizeForSQL($_GET['fSavedSearchId']); } } function do_main() { redirect(KTBrowseUtil::getBrowseBaseUrl()); } /** * This proceses any given search expression. * On success, it redirects to the searchResults page. * * @param string $query */ private function processQuery($query) { try { $expr = parseExpression($query); $results = $expr->evaluate(); $results = resolveSearchShortcuts($results); usort($result['docs'], 'rank_compare'); $_SESSION['search2_results'] = serialize($results); $_SESSION['search2_query'] = $query; $_SESSION['search2_sort'] = 'rank'; $this->redirectTo('searchResults'); } catch(Exception $e) { $this->errorRedirectTo('guiBuilder', _kt('Could not process query.') . $e->getMessage()); } } function do_refreshLuceneStats() { $indexer = Indexer::get(); $indexer->updateIndexStats(); redirect(KTUtil::kt_url().'/dashboard.php'); } function do_refreshDashboardStatus() { session_unregister('ExternalResourceStatus'); session_unregister('IndexingStatus'); redirect(KTUtil::kt_url().'/dashboard.php'); } function do_refresh(){ // Get query from session $query = $_SESSION['search2_query']; $this->processQuery($query); $this->redirectTo('searchResults'); } /** * Processes a query sent by HTTP POST in searchQuery. * */ function do_process() { if (empty($_REQUEST['txtQuery'])) { $this->errorRedirectTo('searchResults', _kt('Please reattempt the query. The query is missing.')); } $query = $_REQUEST['txtQuery']; // Strip out returns - they cause a js error [unterminated string literal] $query = str_replace(array("\r\n", "\r", "\n"), array(' ', ' ', ' '), $query); $_SESSION['search2_quick'] = 0; $_SESSION['search2_general'] = 0; if (isset($_REQUEST['cbQuickQuery']) && $_REQUEST['cbQuickQuery'] +0 == 1) { $_SESSION['search2_quick'] = 1; if (stripos($query, 'generaltext') !== false || stripos($query, 'metadata') !== false) { preg_match('/["][^"]*["]/', $query, $out); $_SESSION['search2_quickQuery'] = substr($out[0],1,-1); } } else { $_SESSION['search2_quickQuery'] = ''; } if (isset($_REQUEST['cbQuickGeneral']) && $_REQUEST['cbQuickGeneral'] +0 == 1) { $_SESSION['search2_general'] = 1; } session_unregister('search2_savedid'); $this->processQuery($query); } /** * Returns the saved query is resolved from HTTP GET fSavedSearchId field. * * @return mixed False if error, else string. */ private function getSavedExpression() { if (is_null($this->savedSearchId)) { $this->errorRedirectToParent(_kt('The saved search id was not passed correctly.')); } $_SESSION['search2_savedid'] = $this->savedSearchId; $sql = "SELECT name, expression FROM search_saved WHERE type='S' AND id=$this->savedSearchId"; if (!$this->sysAdmin) { $sql .= " and ( user_id=$this->curUserId OR shared=1 ) "; } $query = DBUtil::getOneResult($sql); if (PEAR::isError($query)) { $this->errorRedirectToParent(_kt('The saved search could not be resolved.')); } $_SESSION['search2_savedname'] = $query['name']; return array($query['name'],$query['expression']);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?