From bf298439297c2ad11b27df16ff85665fc7db2894 Mon Sep 17 00:00:00 2001 From: kevin_fourie Date: Thu, 18 Oct 2007 13:44:12 +0000 Subject: [PATCH] Merged in from DEV trunk... --- bin/diagnoseIndexing.bat | 7 ------- bin/diagnoseIndexing.sh | 13 ------------- bin/indexMigrationTask.bat | 7 ------- bin/indexMigrationTask.sh | 13 ------------- bin/indexingTask.bat | 7 ------- bin/indexingTask.sh | 13 ------------- bin/luceneserver/ktlucene.jar | Bin 12327 -> 0 bytes bin/openoffice/DocumentConverter.py | 10 ++++++---- bin/optimizeIndexes.bat | 7 ------- bin/optimizeIndexes.sh | 13 ------------- examples/linux/init/dmsctl.sh | 2 +- ktwebdav/lib/KTWebDAVServer.inc.php | 9 +++++++-- ktwebservice/webservice.php | 46 ++++++++++++++++++++++++++++++++-------------- lib/documentmanagement/Document.inc | 19 +++++++++++++++++++ lib/security/Permission.inc | 45 ++++++++++++++++++++++++++++++--------------- lib/session/Session.inc | 4 +++- lib/users/User.inc | 82 +++++++++++++++++++++++++++++++++++++++++----------------------------------------- plugins/search2/ExternalDashlet.php | 2 +- search2.php | 5 +++++ search2/indexing/bin/recreateIndex.php | 3 ++- search2/indexing/indexerCore.inc.php | 155 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------- search2/indexing/indexers/JavaXMLRPCLuceneIndexer.inc.php | 18 ++++++++++-------- search2/indexing/indexers/PHPLuceneIndexer.inc.php | 25 +++++++++++++++++++++---- search2/search/expr.inc.php | 167 +++++++++++------------------------------------------------------------------------------------------------------------------------------------------------------------ templates/ktcore/search2/search_results.smarty | 34 +++++++++++++++++----------------- thirdparty/Smarty/plugins/modifier.mb_truncate.php | 8 +++++--- 26 files changed, 295 insertions(+), 419 deletions(-) delete mode 100644 bin/diagnoseIndexing.bat delete mode 100644 bin/diagnoseIndexing.sh delete mode 100644 bin/indexMigrationTask.bat delete mode 100644 bin/indexMigrationTask.sh delete mode 100644 bin/indexingTask.bat delete mode 100644 bin/indexingTask.sh delete mode 100644 bin/optimizeIndexes.bat delete mode 100644 bin/optimizeIndexes.sh diff --git a/bin/diagnoseIndexing.bat b/bin/diagnoseIndexing.bat deleted file mode 100644 index 03b71da..0000000 --- a/bin/diagnoseIndexing.bat +++ /dev/null @@ -1,7 +0,0 @@ -@echo off - -SET PATH=%PATH%;..\..\php;..\..\php\bin -setlocal -cd "@@BITROCK_INSTALLDIR@@\knowledgeTree\search2\indexing\bin" - -php -Cq diagnose.php \ No newline at end of file diff --git a/bin/diagnoseIndexing.sh b/bin/diagnoseIndexing.sh deleted file mode 100644 index 754e3d1..0000000 --- a/bin/diagnoseIndexing.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -# SETUP PATH TO FIND PHP -PATH=$PATH:../../php/bin:../../php: - -# WORK OUT DIRECTORIES -USER_DIR=`pwd` -SCRIPT_DIR=$USER_DIR/`dirname $0` -PHP_SCRIPT_DIR=$SCRIPT_DIR/../search2/indexing/bin - -# EXECUTE SCRIPT IN THE SCRIPT DIRECTORY -cd $PHP_SCRIPT_DIR -php -Cq diagnose.php \ No newline at end of file diff --git a/bin/indexMigrationTask.bat b/bin/indexMigrationTask.bat deleted file mode 100644 index efd1346..0000000 --- a/bin/indexMigrationTask.bat +++ /dev/null @@ -1,7 +0,0 @@ -@echo off - -SET PATH=%PATH%;..\..\php;..\..\php\bin -setlocal -cd "@@BITROCK_INSTALLDIR@@\knowledgeTree\search2\indexing\bin" - -php -Cq cronMigration.php \ No newline at end of file diff --git a/bin/indexMigrationTask.sh b/bin/indexMigrationTask.sh deleted file mode 100644 index 1bd2e86..0000000 --- a/bin/indexMigrationTask.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -# SETUP PATH TO FIND PHP -PATH=$PATH:../../php/bin:../../php: - -# WORK OUT DIRECTORIES -USER_DIR=`pwd` -SCRIPT_DIR=$USER_DIR/`dirname $0` -PHP_SCRIPT_DIR=$SCRIPT_DIR/../search2/indexing/bin - -# EXECUTE SCRIPT IN THE SCRIPT DIRECTORY -cd $PHP_SCRIPT_DIR -php -Cq cronMigration.php \ No newline at end of file diff --git a/bin/indexingTask.bat b/bin/indexingTask.bat deleted file mode 100644 index f7c19e7..0000000 --- a/bin/indexingTask.bat +++ /dev/null @@ -1,7 +0,0 @@ -@echo off - -SET PATH=%PATH%;..\..\php;..\..\php\bin -setlocal -cd "@@BITROCK_INSTALLDIR@@\knowledgeTree\search2\indexing\bin" - -php -Cq cronIndexer.php \ No newline at end of file diff --git a/bin/indexingTask.sh b/bin/indexingTask.sh deleted file mode 100644 index a62cbed..0000000 --- a/bin/indexingTask.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -# SETUP PATH TO FIND PHP -PATH=$PATH:../../php/bin:../../php: - -# WORK OUT DIRECTORIES -USER_DIR=`pwd` -SCRIPT_DIR=$USER_DIR/`dirname $0` -PHP_SCRIPT_DIR=$SCRIPT_DIR/../search2/indexing/bin - -# EXECUTE SCRIPT IN THE SCRIPT DIRECTORY -cd $PHP_SCRIPT_DIR -php -Cq cronIndexer.php \ No newline at end of file diff --git a/bin/luceneserver/ktlucene.jar b/bin/luceneserver/ktlucene.jar index 4ecac73..afbd400 100644 Binary files a/bin/luceneserver/ktlucene.jar and b/bin/luceneserver/ktlucene.jar differ diff --git a/bin/openoffice/DocumentConverter.py b/bin/openoffice/DocumentConverter.py index 238e05c..f03965f 100644 --- a/bin/openoffice/DocumentConverter.py +++ b/bin/openoffice/DocumentConverter.py @@ -7,7 +7,9 @@ # Copyright (C) 2007 Mirko Nasato # Licensed under the GNU LGPL v2.1 - http://www.gnu.org/licenses/lgpl.html # -DEFAULT_OPENOFFICE_PORT = 8100 +# Modified by Kevin Fourie - 2007-10-18 + +#DEFAULT_OPENOFFICE_PORT = 8100 import uno from os.path import abspath, splitext @@ -78,11 +80,11 @@ def _unoProps(**args): class DocumentConverter: - def __init__(self, port=DEFAULT_OPENOFFICE_PORT): + def __init__(self, host=argv[3], port=argv[4]): localContext = uno.getComponentContext() resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext) try: - context = resolver.resolve("uno:socket,host=localhost,port=%s;urp;StarOffice.ComponentContext" % port) + context = resolver.resolve("uno:socket,host=%s,port=%s;urp;StarOffice.ComponentContext" % (host, port)) except NoConnectException: raise DocumentConversionException, "failed to connect to OpenOffice.org on port %s" % port self.desktop = context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", context) @@ -127,7 +129,7 @@ if __name__ == "__main__": from sys import argv, exit if len(argv) < 3: - print "USAGE: " + argv[0] + " " + print "USAGE: " + argv[0] + " " exit(255) try: diff --git a/bin/optimizeIndexes.bat b/bin/optimizeIndexes.bat deleted file mode 100644 index 24eb298..0000000 --- a/bin/optimizeIndexes.bat +++ /dev/null @@ -1,7 +0,0 @@ -@echo off - -SET PATH=%PATH%;..\..\php;..\..\php\bin -setlocal -cd "@@BITROCK_INSTALLDIR@@\knowledgeTree\search2\indexing\bin" - -php -Cq optimise.php \ No newline at end of file diff --git a/bin/optimizeIndexes.sh b/bin/optimizeIndexes.sh deleted file mode 100644 index 40af015..0000000 --- a/bin/optimizeIndexes.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -# SETUP PATH TO FIND PHP -PATH=$PATH:../../php/bin:../../php: - -# WORK OUT DIRECTORIES -USER_DIR=`pwd` -SCRIPT_DIR=$USER_DIR/`dirname $0` -PHP_SCRIPT_DIR=$SCRIPT_DIR/../search2/indexing/bin - -# EXECUTE SCRIPT IN THE SCRIPT DIRECTORY -cd $PHP_SCRIPT_DIR -php -Cq optimise.php \ No newline at end of file diff --git a/examples/linux/init/dmsctl.sh b/examples/linux/init/dmsctl.sh index 346465d..746664b 100644 --- a/examples/linux/init/dmsctl.sh +++ b/examples/linux/init/dmsctl.sh @@ -43,7 +43,7 @@ XVFB_STATUS="" SOFFICE_PATH="$INSTALL_PATH/openoffice/program" SOFFICE_PIDFILE=$INSTALL_PATH/openoffice/soffice.bin.pid SOFFICE_PID="" -SOFFICE_PORT="8001" +SOFFICE_PORT="8100" SOFFICEBIN=$INSTALL_PATH/openoffice/program/soffice.bin SOFFICE="$SOFFICEBIN -nofirststartwizard -nologo -headless -display :$VDISPLAY -accept=socket,host=localhost,port=$SOFFICE_PORT;urp;StarOffice.ServiceManager" SOFFICE_STATUS="" diff --git a/ktwebdav/lib/KTWebDAVServer.inc.php b/ktwebdav/lib/KTWebDAVServer.inc.php index 312c64a..18dd7f8 100644 --- a/ktwebdav/lib/KTWebDAVServer.inc.php +++ b/ktwebdav/lib/KTWebDAVServer.inc.php @@ -1105,8 +1105,13 @@ class KTWebDAVServer extends HTTP_WebDAV_Server continue; } // FIXME: Direct database access - $sQuery = "SELECT id FROM folders WHERE parent_id = ? AND name = ?"; - $aParams = array($iFolderID, $sFolderName); + if($iFolderID == 0){ + $sQuery = "SELECT id FROM folders WHERE parent_id is null AND name = ?"; + $aParams = array($sFolderName); + }else{ + $sQuery = "SELECT id FROM folders WHERE parent_id = ? AND name = ?"; + $aParams = array($iFolderID, $sFolderName); + } $id = DBUtil::getOneResultKey(array($sQuery, $aParams), 'id'); if (PEAR::isError($id)) { $this->ktwebdavLog("A DB error occurred in _folderOrDocument", 'info', true); diff --git a/ktwebservice/webservice.php b/ktwebservice/webservice.php index 4a21003..4eaea70 100644 --- a/ktwebservice/webservice.php +++ b/ktwebservice/webservice.php @@ -195,16 +195,26 @@ class KTWebService $this->__typedef["{urn:$this->namespace}kt_search_result_item"] = array( 'document_id' => 'int', - 'title' => 'string', - 'rank' => 'float', + 'relevance' => 'float', 'text' => 'string', - 'filesize' => 'int', + 'title' => 'string', 'fullpath' => 'string', + 'filesize' => 'int', 'version' => 'string', 'filename' => 'string', - 'checked_out_user' => 'string', - 'is_available' => 'boolean', - 'workflow' => 'string' + 'folder_id' => 'int', + 'workflow' => 'string', + 'workflow_state' => 'string', + 'mime_type' => 'string', + 'owner' => 'string', + 'created_by' => 'string', + 'created_date' => 'string', + 'modified_by' => 'string', + 'modified_date' => 'string', + 'checked_out_by' => 'string', + 'checked_out_date' => 'string', + 'is_immutable' => 'bool', + 'status' => 'string', ); $this->__typedef["{urn:$this->namespace}kt_search_results"] = @@ -3334,26 +3344,34 @@ class KTWebService $results = array(); foreach($rs as $hit) { - if ($hit->IsLive) - { - - $item = array( + $item = array( 'document_id' => (int) $hit->DocumentID, 'title' => (string) $hit->Title, - 'rank' => (float) $hit->Rank, + 'relevance' => (float) $hit->Rank, 'text' => (string) $noText?'':$hit->Text, 'filesize' => (int) $hit->Filesize, 'fullpath' => (string) $hit->FullPath, 'version' => (string) $hit->Version, 'filename' => (string) $hit->Filename, - 'checked_out_user' => (string) $hit->CheckedOutUser, + 'checked_out_by' => (string) $hit->CheckedOutUser, + 'checked_out_date' => (string) $hit->DateCheckedOut, 'is_available' => (bool) $hit->IsAvailable, - 'workflow' => (string) $hit->Workflow + 'workflow' => (string) $hit->Workflow, + 'workflow_state' => (string) $hit->WorkflowState, + 'folder_id' => (int) $hit->FolderId, + 'mime_type' => (string) $hit->MimeType, + 'modified_by' => (string) $hit->ModifiedBy, + 'modified_date' => (string) $hit->DateModified, + 'created_by' => (string) $hit->CreatedBy, + 'created_date' => (string) $hit->DateCreated, + 'owner' => (string) $hit->Owner, + 'is_immutable'=> (bool) $hit->Immutable, + 'status' => (string) $hit->Status ); $item = new SOAP_Value('item',"{urn:$this->namespace}kt_search_result_item", $item); $results[] = $item; - } + } $response['message'] = ''; diff --git a/lib/documentmanagement/Document.inc b/lib/documentmanagement/Document.inc index 0e6c532..09d6726 100644 --- a/lib/documentmanagement/Document.inc +++ b/lib/documentmanagement/Document.inc @@ -640,6 +640,25 @@ class Document { return trim($aComment[1]); } + static function getStatusString($statusid) + { + $statuses = array( + 1=>_kt('Live'), + 2=>_kt('Published'), + 3=>_kt('Deleted'), + 4=>_kt('Archived'), + 5=>_kt('Incomplete'), + 6=>_kt('Version Deleted') + ); + + if (array_key_exists($statusid, $statuses)) + { + return $statuses[$statusid]; + } + + return _kt('Unknown State'); + } + diff --git a/lib/security/Permission.inc b/lib/security/Permission.inc index 17fc7c3..a37bc5f 100644 --- a/lib/security/Permission.inc +++ b/lib/security/Permission.inc @@ -12,7 +12,7 @@ * License Version 1.1.2 ("License"); You may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.knowledgetree.com/KPL - * + * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. * See the License for the specific language governing rights and @@ -23,9 +23,9 @@ * (ii) the KnowledgeTree copyright notice * in the same form as they appear in the distribution. See the License for * requirements. - * + * * The Original Code is: KnowledgeTree Open Source - * + * * The Initial Developer of the Original Code is The Jam Warehouse Software * (Pty) Ltd, trading as KnowledgeTree. * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright @@ -38,15 +38,15 @@ require_once(KT_LIB_DIR . '/permissions/permission.inc.php'); require_once(KT_LIB_DIR . '/permissions/permissionutil.inc.php'); class Permission { - + /** * Checks if the current user has write permission for a specific document. * * @param $oDocument Document to check * * @return boolean true if the current user has document write permission, false otherwise and set $_SESSION["errorMessage"] - */ - function userHasDocumentWritePermission($oDocument) { + */ + function userHasDocumentWritePermission($oDocument) { $oUser = User::get($_SESSION["userID"]); $oPermission = KTPermission::getByName('ktcore.permissions.write'); @@ -62,30 +62,30 @@ class Permission { * * @return boolean true if the user has document write permission, false otherwise and set $_SESSION["errorMessage"] */ - function userHasDocumentReadPermission($oDocument) { + function userHasDocumentReadPermission($oDocument) { $oUser = User::get($_SESSION["userID"]); $oPermission = KTPermission::getByName('ktcore.permissions.read'); return KTPermissionUtil::userHasPermissionOnItem($oUser, $oPermission, $oDocument); } - + /** * Checks if the current user has write permission for a specific folder - * + * * @param $oFolder Folder object to check * * @return boolean true if the user has folder write permission, false otherwise and set $_SESSION["errorMessage"] */ - function userHasFolderWritePermission($oFolder) { + function userHasFolderWritePermission($oFolder) { $oUser = User::get($_SESSION["userID"]); $oPermission = KTPermission::getByName('ktcore.permissions.write'); return KTPermissionUtil::userHasPermissionOnItem($oUser, $oPermission, $oFolder); } - - + + /** * Checks if the current user has read permission for a specific folder * @@ -93,14 +93,14 @@ class Permission { * * @return boolean true if the user has folder write permission, false otherwise and set $_SESSION["errorMessage"] */ - function userHasFolderReadPermission($oFolder) { + function userHasFolderReadPermission($oFolder) { $oUser = User::get($_SESSION["userID"]); $oPermission = KTPermission::getByName('ktcore.permissions.read'); return KTPermissionUtil::userHasPermissionOnItem($oUser, $oPermission, $oFolder); } - + /** * Check if the current user is a system administrator * @@ -123,7 +123,7 @@ class Permission { } return false; } - + function isUnitAdministratorForFolder($oUser, $oFolder) { $oFolder =& KTUtil::getObject('Folder', $oFolder); $oUser =& KTUtil::getObject('User', $oUser); @@ -150,6 +150,21 @@ class Permission { } return false; } + + /** + * Tell us if the administrator is in admin mode + * + * @return bool + */ + static function adminIsInAdminMode() + { + if (!Permission::userIsSystemAdministrator()) + { + return false; + } + return isset($_SESSION['adminmode']) && ($_SESSION['adminmode']+0); + } + } ?> diff --git a/lib/session/Session.inc b/lib/session/Session.inc index 54c6ee7..a70e017 100644 --- a/lib/session/Session.inc +++ b/lib/session/Session.inc @@ -45,10 +45,12 @@ class Session { session_start(); + + // Don't need to lock a user out the web interface if KT Tools exists and has no license. if (KTPluginUtil::pluginIsActive('ktdms.wintools')) { if (!$oUser->isAnonymous()) { require_once(KT_DIR . '/plugins/wintools/baobabkeyutil.inc.php'); - $res = BaobabKeyUtil::isBaobabUser($oUser); + $res = BaobabKeyUtil::isValidUser($oUser); if (PEAR::isError($res)) { return $res; } diff --git a/lib/users/User.inc b/lib/users/User.inc index ba71b5e..0c4c0dd 100644 --- a/lib/users/User.inc +++ b/lib/users/User.inc @@ -8,7 +8,7 @@ * License Version 1.1.2 ("License"); You may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.knowledgetree.com/KPL - * + * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. * See the License for the specific language governing rights and @@ -19,9 +19,9 @@ * (ii) the KnowledgeTree copyright notice * in the same form as they appear in the distribution. See the License for * requirements. - * + * * The Original Code is: KnowledgeTree Open Source - * + * * The Initial Developer of the Original Code is The Jam Warehouse Software * (Pty) Ltd, trading as KnowledgeTree. * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright @@ -29,13 +29,13 @@ * All Rights Reserved. * Contributor( s): ______________________________________ */ - -require_once(KT_LIB_DIR . '/database/dbutil.inc'); -require_once(KT_LIB_DIR . '/ktentity.inc'); + +require_once(KT_LIB_DIR . '/database/dbutil.inc'); +require_once(KT_LIB_DIR . '/ktentity.inc'); require_once(KT_LIB_DIR . "/util/sanitize.inc"); define('ADMIN_USER_ID', 1); - + class User extends KTEntity { /** user's login name */ var $sUserName; @@ -106,14 +106,14 @@ class User extends KTEntity { function _table() { return KTUtil::getTableName("users"); } - + // STATIC function _ktentityOptions() { return array( 'orderby' => 'name', ); } - + function getUserName() { return sanitizeForSQLtoHTML($this->sUserName); } function setUserName($sNewValue) { $this->sUserName = sanitizeForSQL($sNewValue); } @@ -169,11 +169,11 @@ class User extends KTEntity { return 'dashboard-state-' . $this->getId(); } - function getDashboardState() { + function getDashboardState() { return KTUtil::getSystemSetting($this->_getDashboardStateKey()); } - function setDashboardState($mValue) { + function setDashboardState($mValue) { KTUtil::setSystemSetting($this->_getDashboardStateKey(), $mValue); } @@ -182,9 +182,9 @@ class User extends KTEntity { require_once(KT_DIR . "/thirdparty/pear/JSON.php"); $dashletRegistry = & KTDashletRegistry::getSingleton(); - + $aDashlets = $dashletRegistry->getDashlets($this); - + $oJSON = new Services_JSON(); $state = $this->getDashboardState(); @@ -193,18 +193,18 @@ class User extends KTEntity { if (!isset($dashlets->left)) $dashlets->left = array(); if (!isset($dashlets->right)) $dashlets->right = array(); $mergedlist = kt_array_merge($dashlets->left,$dashlets->right); - - + + $knownlist = array(); foreach($mergedlist as $dashlet) { array_push($knownlist,$dashlet->id); } $update=false; - + //if (!isset($dashlets->left)) $dashlets->left=array(); //if (!isset($dashlets->right)) $dashlets->right=array(); - + $column=1; foreach($aDashlets as $dashlet) { @@ -215,7 +215,7 @@ class User extends KTEntity { $obj = new stdClass(); $obj->id=$class; $obj->state=0; - + if ($column == 0) array_push($dashlets->left,$obj); else @@ -223,19 +223,19 @@ class User extends KTEntity { $update=true; } } - + if ($update) { $state = $oJSON->encode($dashlets); $this->setDashboardState($state); } } - - + + function &get($iId) { return KTEntityUtil::get('User', $iId); } - + /** * update the datastore, without overwriting the password. * @@ -244,25 +244,25 @@ class User extends KTEntity { function doLimitedUpdate() { $sQuery = 'UPDATE ' . $this->_table() . ' SET '; $aParams = array(); - + $blacklist = array( "sPassword" => 1, ); - + $aParts = array(); // quick workaround to make the join less hurtful. - + foreach ($this->_aFieldToSelect as $attr => $column) { if (!array_key_exists($attr, $blacklist)) { $val = $this->$attr; $aParts[] = $column . ' = ?'; - $aParams[] = $val; - } + $aParams[] = $val; + } } $sQuery .= join(', ', $aParts); - + $sQuery .= ' WHERE id = ? '; $aParams[] = $this->getId(); - + $res = DBUtil::runQuery(array($sQuery, $aParams)); $group = sprintf("%s/%s", get_class($this), 'id'); @@ -272,8 +272,8 @@ class User extends KTEntity { return $res; } - - + + /** * Static function * Get a list of users @@ -329,7 +329,7 @@ class User extends KTEntity { $this->iId = $id; } - + /** Static function * Gets the user's default top level folder for the current user */ @@ -343,7 +343,7 @@ class User extends KTEntity { $oUnit =& Unit::get($iUnitId); return $oUnit->getFolderId(); } - + function &createFromArray($aOptions) { return KTEntityUtil::createFromArray('User', $aOptions); } function &getByUserName($sUserName, $aOptions = null) { return KTEntityUtil::getBy('User', 'username', $sUserName, $aOptions); @@ -385,7 +385,7 @@ class User extends KTEntity { $aParams = array(false); return DBUtil::getOneResultKey(array($sQuery, $aParams), 'number'); } - + function isAnonymous() { return $this->iId == -2; } function disable() { @@ -397,7 +397,7 @@ class User extends KTEntity { } return; } - + function enable() { $this->setDisabled(0); $this->update(); @@ -406,7 +406,7 @@ class User extends KTEntity { BaobabKeyUtil::allocateUser($this); } return; - } + } function create() { if (KTPluginUtil::pluginIsActive('ktdms.wintools')) { @@ -418,7 +418,7 @@ class User extends KTEntity { } return parent::create(); } - + function delete() { $this->setDisabled(2); @@ -429,7 +429,7 @@ class User extends KTEntity { $tempUserID = $this->iId; $DeletedUsername = 'kt_deleted_'.$tempUsername.'_'.$tempUserID; $this->setUsername($DeletedUsername); - + //nullify all authentication_xxx fields $this->setAuthenticationSourceId(null); $this->setAuthenticationDetails(null); @@ -440,13 +440,13 @@ class User extends KTEntity { $this->setAuthenticationDetailsDate2(null); $this->setAuthenticationDetailsBool1(null); $this->setAuthenticationDetailsBool2(null); - + $this->update(); if (KTPluginUtil::pluginIsActive('ktdms.wintools')) { require_once(KT_DIR . '/plugins/wintools/baobabkeyutil.inc.php'); - BaobabKeyUtil::allocateUser($this); + BaobabKeyUtil::deallocateUser($this); } return; - + } } diff --git a/plugins/search2/ExternalDashlet.php b/plugins/search2/ExternalDashlet.php index 8a010eb..816f139 100644 --- a/plugins/search2/ExternalDashlet.php +++ b/plugins/search2/ExternalDashlet.php @@ -97,7 +97,7 @@ class ExternalResourceStatusDashlet extends KTBaseDashlet function is_active($oUser) { - if (!Permission::userIsSystemAdministrator($oUser)) + if (!Permission::userIsSystemAdministrator($oUser->getId())) { return false; } diff --git a/search2.php b/search2.php index 13a3899..9007b9d 100644 --- a/search2.php +++ b/search2.php @@ -9,6 +9,7 @@ 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_DIR . '/search2/search/search.inc.php'); +require_once(KT_LIB_DIR . '/documentmanagement/Document.inc'); class SearchDispatcher extends KTStandardDispatcher { @@ -162,6 +163,10 @@ class SearchDispatcher extends KTStandardDispatcher { $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate("ktcore/search2/search_results"); + KTEntityUtil::_proxyCreate('KTDocumentContentVersion','KTDocumentContentVersionProxy'); + KTEntityUtil::_proxyCreate('KTDocumentCore','KTDocumentCoreProxy'); + KTEntityUtil::_proxyCreate('KTDocumentMetadataVersion','KTDocumentMetadataVersionProxy'); + $results = unserialize($_SESSION['search2_results']); if (!is_array($results) || count($results) == 0) diff --git a/search2/indexing/bin/recreateIndex.php b/search2/indexing/bin/recreateIndex.php index d5a8114..6935890 100644 --- a/search2/indexing/bin/recreateIndex.php +++ b/search2/indexing/bin/recreateIndex.php @@ -10,6 +10,8 @@ */ session_start(); +require_once(realpath('../../../config/dmsDefaults.php')); + print _kt("Recreate Lucene index") . "...\n"; $sure=false; @@ -39,7 +41,6 @@ if (!$sure) } -require_once(realpath('../../../config/dmsDefaults.php')); $config = KTConfig::getSingleton(); $indexer = $config->get('indexer/coreClass'); diff --git a/search2/indexing/indexerCore.inc.php b/search2/indexing/indexerCore.inc.php index 6d6da7d..54d7021 100644 --- a/search2/indexing/indexerCore.inc.php +++ b/search2/indexing/indexerCore.inc.php @@ -3,7 +3,7 @@ require_once('indexing/extractorCore.inc.php'); -class MatchResult +class QueryResultItem { protected $document_id; protected $title; @@ -13,15 +13,27 @@ class MatchResult protected $fullpath; protected $live; protected $version; + protected $mimeType; protected $filename; protected $thumbnail; // TODO: if not null, gui can display a thumbnail protected $viewer; // TODO: if not null, a viewer can be used to view the document protected $document; - protected $checkoutuser; - protected $workflowstate; + protected $checkedOutUser; + protected $dateCheckedout; + protected $workflowState; protected $workflow; - - public function __construct($document_id, $rank, $title, $text) + protected $modifiedBy; + protected $dateModified; + protected $createdBy; + protected $dateCreated; + protected $owner; + protected $immutable; + protected $deleted; + protected $status; + protected $folderId; + + + public function __construct($document_id, $rank=null, $title=null, $text=null) { $this->document_id=$document_id; $this->rank= $rank; @@ -48,17 +60,25 @@ class MatchResult private function loadDocumentInfo() { $sql = "SELECT - f.full_path, f.name, dcv.size as filesize, dcv.major_version, - dcv.minor_version, dcv.filename, cou.name as checkoutuser, w.human_name as workflow, ws.human_name as workflowstate + f.folder_id, f.full_path, f.name, dcv.size as filesize, dcv.major_version, + dcv.minor_version, dcv.filename, cou.name as checkoutuser, w.human_name as workflow, ws.human_name as workflowstate, + mt.mimetypes as mimetype, md.mime_doc as mimedoc, d.checkedout, mbu.name as modifiedbyuser, d.modified, + cbu.name as createdbyuser, ou.name as owneruser, d.immutable, d.status_id, d.created FROM documents d INNER JOIN document_metadata_version dmv ON d.metadata_version_id = dmv.id INNER JOIN document_content_version dcv ON dmv.content_version_id = dcv.id + INNER JOIN mime_types mt ON dcv.mime_id=mt.id LEFT JOIN folders f ON f.id=d.folder_id LEFT JOIN users cou ON d.checked_out_user_id=cou.id LEFT JOIN workflows w ON dmv.workflow_id=w.id LEFT JOIN workflow_states ws ON dmv.workflow_state_id = ws.id + LEFT JOIN mime_documents md ON mt.mime_document_id = md.id + LEFT JOIN users mbu ON d.modified_user_id=mbu.id + LEFT JOIN users cbu ON d.creator_id=cbu.id + LEFT JOIN users ou ON d.owner_id=ou.id + WHERE d.id=$this->document_id"; @@ -81,65 +101,86 @@ class MatchResult if (substr($this->fullpath,0,1) == '/') $this->fullpath = substr($this->fullpath,1); } - - $this->filesize = $result['filesize'] + 0; - - if ($this->filesize > 1024 * 1024 * 1024) - { - $this->filesize = floor($this->filesize / (1024 * 1024 * 1024)) . 'g'; - } - elseif ($this->filesize > 1024 * 1024) - { - $this->filesize = floor($this->filesize / (1024 * 1024)) . 'm'; - } - elseif ($this->filesize > 1024) - { - $this->filesize = floor($this->filesize / (1024)) . 'k'; - } - else - { - $this->filesize .= 'b'; - } + $this->filesize = KTUtil::filesizeToString($result['filesize']); $this->version = $result['major_version'] . '.' . $result['minor_version']; $this->filename=$result['filename']; - $this->checkoutuser = $result['checkoutuser']; + $this->checkedOutUser = $result['checkoutuser']; $this->workflow = $result['workflow']; - $this->workflowstate = $result['workflowstate']; + $this->workflowState = $result['workflowstate']; - } + $this->mimeType = $result['mimetype']; + $this->dateCheckedout = $result['checkedout']; + $this->modifiedBy = $result['modifiedbyuser']; + $this->dateModified = $result['modified']; + $this->createdBy = $result['createdbyuser']; + $this->dateCreated = $result['created']; + + $this->owner = $result['owneruser']; + $this->immutable = ($result['immutable'] + 0)?_kt('Immutable'):''; + $this->status = Document::getStatusString($result['status_id']); + $this->folderId = $result['folder_id']; + + } protected function __get($property) { switch($property) { - case 'DocumentID': return $this->document_id; - case 'Rank': return $this->rank; - case 'Text': return $this->text; - case 'Title': return $this->title; - case 'FullPath': return $this->fullpath; - case 'IsLive': return $this->live; - case 'Filesize': return $this->filesize; - case 'Version': return $this->version; - case 'Filename': return $this->filename; + case null: return ''; + case 'DocumentID': return (int) $this->document_id; + case 'Relevance': + case 'Rank': return (float) $this->rank; + case 'Text': return (string) $this->text; + case 'Title': return (string) $this->title; + case 'FullPath': return (string) $this->fullpath; + case 'IsLive': return (bool) $this->live; + case 'Filesize': return (int) $this->filesize; + case 'Version': return (string) $this->version; + case 'Filename': return (int)$this->filename; + case 'FolderId': return (int)$this->folderId; case 'Document': if (is_null($this->document)) + { $this->document = Document::get($this->document_id); + } return $this->document; case 'IsAvailable': return $this->Document->isLive(); - case 'CheckedOutUser': - return $this->checkoutuser; + return (string) $this->checkedOutUser; + case 'WorkflowOnly': + return (string)$this->workflow; + case 'WorkflowStateOnly': + return (string)$this->workflowState; case 'Workflow': if (is_null($this->workflow)) { return ''; } - return "$this->workflow - $this->workflowstate"; - case null: break; + return "$this->workflow - $this->workflowState"; + case 'MimeType': + return (string) $this->mimeType; + case 'DateCheckedOut': + return (string) $this->dateCheckedout; + case 'ModifiedBy': + return (string) $this->modifiedBy; + case 'DateModified': + return (string) $this->dateModified; + case 'CreatedBy': + return (string) $this->createdBy; + case 'DateCreated': + return (string) $this->dateCreated; + case 'Owner': + return (string) $this->owner; + case 'Immutable': + return (bool) $this->immutable; + case 'Status': + return $this->status; + case 'CanBeReadByUser': + return (bool) $this->live && (Permission::userHasDocumentReadPermission($this->Document) || Permission::adminIsInAdminMode()); default: throw new Exception("Unknown property '$property' to get on MatchResult"); } @@ -151,6 +192,7 @@ class MatchResult switch($property) { case 'Rank': $this->rank = number_format($value,2,'.',','); break; + case 'Title': $this->title = $value; break; case 'Text': $this->text = $value; break; default: throw new Exception("Unknown property '$property' to set on MatchResult"); @@ -166,35 +208,6 @@ function MatchResultCompare($a, $b) return ($a->Rank < $b->Rank) ? -1 : 1; } -class QueryResultItem extends MatchResult -{ - protected $discussion; - - public function __construct($document_id, $rank, $title, $text, $discussion) - { - parent::__construct($document_id, $rank, $title, $text); - $this->discussion=$discussion; - } - - protected function __isset($property) - { - switch($property) - { - case 'Discussion': return isset($this->discussion); - default: return parent::__isset($property); - } - } - - protected function __get($property) - { - switch($property) - { - case 'Discussion': return $this->discussion; - default: return parent::__get($property); - } - } -} - abstract class Indexer { /** diff --git a/search2/indexing/indexers/JavaXMLRPCLuceneIndexer.inc.php b/search2/indexing/indexers/JavaXMLRPCLuceneIndexer.inc.php index 9a9b296..70fdd64 100644 --- a/search2/indexing/indexers/JavaXMLRPCLuceneIndexer.inc.php +++ b/search2/indexing/indexers/JavaXMLRPCLuceneIndexer.inc.php @@ -100,7 +100,7 @@ class JavaXMLRPCLuceneIndexer extends Indexer public function optimise() { parent::optimise(); - $this->lucene->optimize(); + $this->lucene->optimise(); } /** @@ -128,18 +128,20 @@ class JavaXMLRPCLuceneIndexer extends Indexer { foreach ($hits as $hit) { - - $document_id = $hit->DocumentID; - $content = $hit->Text; - $discussion = $hit->Title; //TODO: fix to be discussion. lucen server is not returning discussion text as well.. - $title = $hit->Title; - $score = $hit->Rank; // avoid adding duplicates. If it is in already, it has higher priority. if (!array_key_exists($document_id, $results) || $score > $results[$document_id]->Score) { - $results[$document_id] = new QueryResultItem($document_id, $score, $title, $content, $discussion); + $item = new QueryResultItem($document_id); + $item->Title = $hit->Title; + $item->Text = $hit->Content; + $item->Rank = $hit->Rank; + + if ($item->CanBeReadByUser) + { + $results[$document_id] = $item; + } } } } diff --git a/search2/indexing/indexers/PHPLuceneIndexer.inc.php b/search2/indexing/indexers/PHPLuceneIndexer.inc.php index 10879aa..1e198fe 100644 --- a/search2/indexing/indexers/PHPLuceneIndexer.inc.php +++ b/search2/indexing/indexers/PHPLuceneIndexer.inc.php @@ -1,4 +1,4 @@ -lucene->find($query); @@ -187,15 +189,30 @@ class PHPLuceneIndexer extends Indexer $document = $hit->getDocument(); $document_id = PHPLuceneIndexer::stringToLong($document->DocumentID); - $content = $document->Content ; - $discussion = $document->Discussion ; + + $coreText = ''; + if ($queryContent) + { + $coreText .= $document->Content; + } + if ($queryDiscussion) + { + $coreText .= $document->Discussion; + } + + $content = $query->highlightMatches($coreText); + $title = $document->Title; $score = $hit->score; // avoid adding duplicates. If it is in already, it has higher priority. if (!array_key_exists($document_id, $results) || $score > $results[$document_id]->Score) { - $results[$document_id] = new QueryResultItem($document_id, $score, $title, $content, $discussion); + $item = new QueryResultItem($document_id, $score, $title, $content); + if ($item->CanBeReadByUser) + { + $results[$document_id] = $item; + } } } return $results; diff --git a/search2/search/expr.inc.php b/search2/search/expr.inc.php index 6fd6a0a..16f57be 100644 --- a/search2/search/expr.inc.php +++ b/search2/search/expr.inc.php @@ -847,16 +847,7 @@ class TextQueryBuilder implements QueryBuilder $init = $result->Rank; $score=0; $ranker = RankManager::get(); - $discussion = $result->Discussion; - if (!empty($discussion)) - { - $score += $init *$ranker->scoreField('Discussion', 'S'); - } - else - { - $score += $init *$ranker->scoreField('DocumentText', 'S'); - - } + $score += $init *$ranker->scoreField('DocumentText', 'S'); return $score; } @@ -865,142 +856,11 @@ class TextQueryBuilder implements QueryBuilder $this->query = $query; } - private function extractText($word, $maxwords=40, $maxlen=512) + function getResultText($result) { - $offset=stripos($this->text, $word); - - if ($offset === false) - { - return array(false, false); - } - - if ($offset == 0) - { - $startOffset = 0; - } - else - { - $text = substr($this->text, 0 , $offset); - - $lastsentence = strrpos($text, '.'); - if ($lastsentence === false) $lastsentence=0; - - if ($offset - $lastsentence > $maxlen) - { - $lastsentence = $offset - $maxlen; - } - - $text = substr($this->text, $lastsentence, $offset - $lastsentence); - - $wordoffset= strlen($text)-1; - $words = $maxwords; - while ($words > 0) - { - $text = substr($text, 0, $wordoffset); - $foundoffset = strrpos($text, ' '); - if ($foundoffset === false) - { - break; - } - $wordoffset = $foundoffset; - $words--; - } - $startOffset = $lastsentence + $wordoffset; - } - - - - $nextsentence = strpos($this->text, '.', $offset); - - $words = $maxwords; - $endOffset = $offset; - while ($words > 0) - { - $foundoffset = strpos($this->text, ' ', $endOffset+1); - if ($foundoffset === false) - { - break; - } - if ($endOffset > $offset + $maxlen) - { - break; - } - if ($endOffset > $nextsentence) - { - $endOffset = $nextsentence-1; - break; - } - $endOffset = $foundoffset; - - $words--; - } - - return array($startOffset, substr($this->text, $startOffset, $endOffset - $startOffset + 1)); + // not require! + return ''; } - - - public function getResultText($result) - { - $this->text = substr($result->Text,0,40960); - $words = array(); - $sentences = array(); - - preg_match_all('("[^"]*")',$this->query, $matches,PREG_OFFSET_CAPTURE); - - foreach($matches[0] as $word) - { - list($word,$offset) = $word; - $word = substr($word,1,-1); - $wordlen = strlen($word); - $res = $this->extractText($word); - list($sentenceOffset,$sentence) = $res; - - if ($sentenceOffset === false) - { - continue; - } - - if (array_key_exists($sentenceOffset, $sentences)) - { - $sentences[$sentenceOffset]['score']++; - } - else - { - $sentences[$sentenceOffset] = array( - 'sentence'=>$sentence, - 'score'=>1 - ); - } - - $sentence = $sentences[$sentenceOffset]['sentence']; - - preg_match_all("@$word@i",$sentence, $swords,PREG_OFFSET_CAPTURE); - foreach($swords[0] as $wordx) - { - list($wordx,$offset) = $wordx; - - $sentence = substr($sentence,0, $offset) . '' . substr($sentence, $offset, $wordlen) . '' . substr($sentence, $offset + $wordlen); - } - - $sentences[$sentenceOffset]['sentence'] = $sentence; - - $words[$word] = array( - 'sentence'=>$sentenceOffset - ); - } - - ksort($sentences); - $result = ''; - - foreach($sentences as $o=>$i) - { - if (!empty($result)) $result .= '   ...    '; - $result .= $i['sentence']; - } - - return $result; - } - } class SQLQueryBuilder implements QueryBuilder @@ -1226,7 +1086,10 @@ class SQLQueryBuilder implements QueryBuilder private function resolveMetadataOffset($expr) { - assert($expr->left()->isMetadataField() ); + if (!$expr->left()->isMetadataField()) + { + throw new Exception(_kt('Metadata field expected')); + } $offset=0; foreach($this->metadata as $item) @@ -2039,7 +1902,7 @@ class OpExpr extends Expr $rank = $exprbuilder->getRanking($item); if (!array_key_exists($document_id, $results) || $rank > $results[$document_id]->Rank) { - $results[$document_id] = new MatchResult($document_id, $rank, $item['title'], $exprbuilder->getResultText($item)); + $results[$document_id] = new QueryResultItem($document_id, $rank, $item['title'], $exprbuilder->getResultText($item)); } } @@ -2069,7 +1932,7 @@ class OpExpr extends Expr { $item->Rank = $exprbuilder->getRanking($item); $exprbuilder->setQuery($query); - $item->Text = $exprbuilder->getResultText($item); + //$item->Text = $exprbuilder->getResultText($item); ?? wipe - done at indexer level } return $results; @@ -2156,11 +2019,7 @@ class OpExpr extends Expr $permResults = array(); foreach($result as $idx=>$item) { - $doc = Document::get($item->DocumentID); - if (Permission::userHasDocumentReadPermission($doc)) - { - $permResults[$idx] = $item; - } + $permResults[$idx] = $item; } return $permResults; @@ -2189,10 +2048,6 @@ class OpExpr extends Expr $left->toViz($str, $phase); $right->toViz($str, $phase); } - } - - - ?> \ No newline at end of file diff --git a/templates/ktcore/search2/search_results.smarty b/templates/ktcore/search2/search_results.smarty index 36b39c7..4fa34b8 100644 --- a/templates/ktcore/search2/search_results.smarty +++ b/templates/ktcore/search2/search_results.smarty @@ -4,7 +4,6 @@

{i18n}Search Expression{/i18n}

-
{i18n}Search Expression{/i18n} {$txtQuery} @@ -99,6 +98,8 @@ function onShowAll(showall) {/literal} +
+
{if empty($iSavedID)}
@@ -108,8 +109,8 @@ function onShowAll(showall)
{/if} - - + +
{i18n}Search Results{/i18n} @@ -132,8 +133,6 @@ function onShowAll(showall) {assign var=cbid value=0} {foreach item=document from=$results} - - {if $document->IsLive} {$document->Title} {if $document->Title != $document->Filename} @@ -150,36 +149,35 @@ function onShowAll(showall) {i18n}Version:{/i18n} {$document->Version} {$document->Text} - {$document->FullPath}/{$document->Title} - {$document->Filesize} + {$document->FullPath}/{$document->Title} - {$document->Filesize} - {i18n}Created By:{/i18n} Conrad Vermeulen - {i18n}on{/i18n} 2007-09-28 + {i18n}Created By:{/i18n} {$document->CreatedBy} + {i18n}on{/i18n} {$document->DateCreated} - {assign var=workflow value=$document->Workflow} - {if $workflow != '' || $this->Document->IsCheckedOut} + + {if $workflow != ''} - {i18n}Workflow:{/i18n} {$workflow} + {i18n}Workflow:{/i18n} $document->Workflow} {/if} {if $document->CheckedOutUser != ''} - {i18n}Checked out by:{/i18n} {$document->CheckedOutUser} - {i18n}on{/i18n} 2007-09-28 + {i18n}Checked out by:{/i18n} {$document->CheckedOutUser} + {i18n}on{/i18n} {$document->DateCheckedOut} {else} - {i18n}Modified by:{/i18n} Conrad Vermeulen - {i18n}on{/i18n} 2007-09-28 + {i18n}Modified by:{/i18n} {$document->ModifiedBy} + {i18n}on{/i18n} {$document->DateModified} {/if} - {/if} +

{assign var=cbid value=$cbid+1} - {/if} {/foreach} @@ -197,9 +195,11 @@ function onShowAll(showall) +
{foreach from=$bulkactions item=bulkaction} {/foreach} + diff --git a/thirdparty/Smarty/plugins/modifier.mb_truncate.php b/thirdparty/Smarty/plugins/modifier.mb_truncate.php index 6118b86..248599c 100644 --- a/thirdparty/Smarty/plugins/modifier.mb_truncate.php +++ b/thirdparty/Smarty/plugins/modifier.mb_truncate.php @@ -26,12 +26,14 @@ function smarty_modifier_mb_truncate($string, $length = 80, $etc = '...', if ($length == 0) return ''; - if (mb_strlen($string) > $length) { - $length -= mb_strlen($etc); + if (mb_strlen($string, 'UTF-8') > $length) { + mb_internal_encoding("UTF-8"); + if (!$break_words) $string = preg_replace('/\s+?(\S+)?$/', '', mb_substr($string, 0, $length+1)); - return mb_substr($string, 0, $length).$etc; + return html_entity_decode(mb_substr($string, 0, $length, 'UTF-8').$etc, ENT_NOQUOTES, 'UTF-8'); + } else return $string; } -- libgit2 0.21.4