⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 search.inc.php

📁 PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?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): ______________________________________
 *
 */

require_once('search/SearchCommandParser.php');
require_once('search/SearchCommandLexer.php');
require_once('search/fieldRegistry.inc.php');
require_once('search/expr.inc.php');
require_once(KT_LIB_DIR . '/security/Permission.inc');

// TODO: move standalone functions into a class.... what was I thinking?

function rank_compare($a, $b)
{
	if ($a->Rank == $b->Rank)
	{
		if ($a->Title == $b->Title)
			return 0;
		// we'll show docs in ascending order by name
		return ($a->Title < $b->Title)?-1:1;
	}
	// we want to be in descending order
	return ($a->Rank > $b->Rank)?-1:1;
}

function search_alias_compare($a, $b)
{
	if ($a['alias'] == $b['alias']) return 0;
	return ($a['alias'] < $b['alias'])?-1:1;
}

function searchfix($str)
{
    return str_replace(array("\n","\r"), array('',''), addslashes($str));
}

// TODO: replace manual json construction with json_encode().

class SearchHelper
{
	public static function correctPath($path)
	{
		if (OS_WINDOWS)
		{
			return str_replace('/','\\', $path);
		}
		else
		{
			return str_replace('\\','/', $path);
		}
	}

	public static function checkOpenOfficeAvailablity()
	{
		$config =& KTConfig::getSingleton();
		$ooHost = $config->get('openoffice/host', 'localhost');
		$ooPort = $config->get('openoffice/port', 8100);

		$connection = @fsockopen($ooHost, $ooPort,$errno, $errstr, 2);
		if (false === $connection)
		{
			return  sprintf(_kt("Cannot connect to Open Office Server on host '%s:%s'."), $ooHost, $ooPort);
		}
		fclose($connection);

		return null;
	}

	public static function getSavedSearchEvents()
	{
		// TODO
		$sql = "";
	}

	public static function getJSdocumentTypesStruct($documenttypes = null)
	{
		if (is_null($documenttypes))
		{
			$documenttypes = SearchHelper::getDocumentTypes();
		}
		$dt=0;
		$documenttypes_str = '[';
		foreach($documenttypes as $user)
		{
			if ($dt++ > 0) $documenttypes_str .= ',';
			$id=$user['id'];
			$name=searchfix($user['name']);

			$documenttypes_str .= "\n\t{id: \"$id\", name: \"$name\"}";
		}
		$documenttypes_str .= ']';
		return $documenttypes_str;

	}

	public static function getJSmimeTypesStruct($mimetypes = null)
	{
		if (is_null($mimetypes))
		{
			$mimetypes = SearchHelper::getMimeTypes();
		}
		$mt=0;
		$mimetypes_str = '[';
		foreach($mimetypes as $user)
		{
			if ($mt++ > 0) $mimetypes_str .= ',';

			$name=$user['name'];

			$mimetypes_str .= "\n\t\"$name\"";
		}
		$mimetypes_str .= ']';

		return $mimetypes_str;
	}

	public static function getJSusersStruct($users = null)
	{
		if (is_null($users))
		{
			$users = SearchHelper::getUsers();
		}

		$uo=0;
		$users_str = '[';
		foreach($users as $user)
		{
			if ($uo++ > 0) $users_str .= ',';
			$id=$user['id'];
			$name=searchfix($user['name']);

			$users_str .= "\n\t{id: \"$id\", name: \"$name\"}";
		}
		$users_str .= ']';

		return $users_str;
	}

	public static function getJSfieldsStruct($fields = null)
	{
		if (is_null($fields))
		{
			$fields = SearchHelper::getSearchFields();
		}
        $fields_str = '[';
		$fo=0;
		foreach($fields as $field)
		{
			if ($fo++ > 0) $fields_str .= ',';
			$alias = searchfix($field['alias']);
			$display = searchfix($field['display']);
			$type = $field['type'];
			$fields_str .= "\n\t{alias: \"$alias\", name: \"$display\", type:\"$type\"}";
		}
		$fields_str .= ']';

		return $fields_str;
	}

	public static function getJSworkflowStruct($workflows = null)
	{
		if (is_null($workflows))
		{
			$workflows = SearchHelper::getWorkflows();
		}

		$workflow_str = '[';
        $wo=0;
        foreach($workflows as $workflow)
        {
        	if ($wo++ > 0) $workflow_str .= ',';
        	$wid = $workflow['id'];
        	$name = searchfix($workflow['name']);

        	$workflow_str .= "\n\t{id:\"$wid\", name: \"$name\", states: [ ";

        	$result['workflows'][$wid] = $workflow;
        	$states = SearchHelper::getWorkflowStates($wid);
        	$result['workflows'][$wid]['states'] = array();
        	$so=0;
        	foreach($states as $state)
        	{
        		if ($so++>0) $workflow_str .= ',';
				$sid = $state['id'];
				$name=searchfix($state['name']);
				$result['workflows'][$wid]['states'][$sid] = $state;
				$workflow_str .= "\n\t\t{id:\"$wid\", name: \"$name\"}";
        	}
        	$workflow_str .= ']}';
        }
        $workflow_str .= ']';

        return $workflow_str;
	}

	public static function getJSfieldsetStruct($fieldsets = null)
	{
		if (is_null($fieldsets))
		{
			$fieldsets = SearchHelper::getFieldsets();
		}

		$fieldset_str = '[';
		$fso=0;
        foreach($fieldsets as $fieldset)
        {
        	$fsid=$fieldset['id'];
        	$name = searchfix($fieldset['name']);
        	$desc = searchfix($fieldset['description']);
        	if ($fso++>0) $fieldset_str .= ',';
        	$fieldset_str .= "\n\t{id:\"$fsid\",name:\"$name\",description:\"$desc\", fields: [";


        	$result['fieldsets'][$fsid] = $fieldset;
        	$fields = SearchHelper::getFields($fsid);
			$result['fieldsets'][$fsid]['fields'] = array();
			$fo=0;
        	foreach($fields as $field)
        	{
        		if ($fo++ >0) $fieldset_str .= ',';
				$fid = $field['id'];
				$name= searchfix($field['name']);
				$desc = searchfix($field['description']);
				$datatype=$field['datatype'];
				$control=$field['control'];
        		$fieldset_str .= "\n\t\t{id:\"$fid\", name:\"$name\", description:\"$desc\", datatype:\"$datatype\", control:\"$control\", options: [";
        		$options = $field['options'];
        		$oo = 0;
        		if (!is_array($options))
        		{
        			$options = array();
        		}
        		foreach($options as $option)
        		{
        			if ($oo++ > 0) $fieldset_str .= ',';
        			$oid = $option['id'];
					$name= searchfix($option['name']);
        			$fieldset_str .= "\n\t\t\t{id: \"$oid\", name: \"$name\"}";
        		}
        		$fieldset_str .= ']}';
        		$result['fieldsets'][$fsid]['fields'][$fid] = $field;
        	}
        	$fieldset_str .= ']}';

        }
        $fieldset_str .= ']';

        return $fieldset_str;
	}


	public static function getSavedSearches($userID)
	{

		// need to test for broken db configuration so that the queries dont fail
		// and so that we can be redirected to the db error page
		// TODO: maybe best to have a special db error page rather than the default template when logged in

		global $default;
		if (is_null($default->_db) || PEAR::isError($default->_db)) return array();

		$sql = "SELECT id, name FROM search_saved WHERE type='S'";

		// if we are not the system admin, then we get only ours or shared searches
		if (!Permission::userIsSystemAdministrator($userID))
		{
			$sql .= "  and ( user_id=$userID OR shared=1 ) ";
		}

		$rs = DBUtil::getResultArray($sql);
		return $rs;
	}

	public static function getSearchFields()
	{
		$registry = ExprFieldRegistry::getRegistry();

		$fields = $registry->getFields();

		$results = array();
		foreach($fields as $field )
		{
			$type = $field->getInputRequirements();
			$type = $type['value']['type'];
			$results[] = array('alias'=>$field->getAlias(), 'display'=>$field->getDisplay(), 'type'=>$type);
		}
		usort($results, search_alias_compare);
		return $results;
	}

	public static function getFolder($folderID, $userid)
	{
		$folder = Folder::get($folderID + 0);
		if (PEAR::isError($folder))
		{
			return $folder;
		}

		if (!Permission::userHasFolderReadPermission($folder))
		{
			return new PEAR_Error(_kt('no permission to read folder'));
		}

		$sql = "SELECT id, name FROM folders WHERE parent_id=$folderID ORDER BY name";
		$rs = DBUtil::getResultArray($sql);
		if (PEAR::isError($rs))
		{
			return $rs;
		}

		$folders = array();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -