From 48533f15293e3184586d77e51a350c01b87a84e8 Mon Sep 17 00:00:00 2001 From: Conrad Vermeulen Date: Thu, 20 Sep 2007 15:41:59 +0000 Subject: [PATCH] KTS-673 "The search algorithm needs some work" Updated. --- lib/templating/kt3template.inc.php | 172 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------------- 1 file changed, 89 insertions(+), 83 deletions(-) diff --git a/lib/templating/kt3template.inc.php b/lib/templating/kt3template.inc.php index 543354c..ebefee2 100644 --- a/lib/templating/kt3template.inc.php +++ b/lib/templating/kt3template.inc.php @@ -6,7 +6,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 @@ -17,9 +17,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 @@ -33,15 +33,16 @@ * KT3 Template Base * * Represents core UI logic, including how sub-components interact with - * the overall page. + * the overall page. * * For the meaning of each of the variables and functions, see inline. * */ - + require_once(KT_LIB_DIR . "/plugins/pluginregistry.inc.php"); require_once(KT_LIB_DIR . "/templating/templating.inc.php"); require_once(KT_LIB_DIR . "/session/control.inc"); +require_once(KT_DIR . '/search2/search/search.inc.php'); class KTPage { var $hide_section = false; @@ -55,13 +56,13 @@ class KTPage { var $theme_ie_only_css = Array(); var $js_standalone = Array(); var $css_standalone = Array(); - + /** context-relevant information */ var $errStack = Array(); var $infoStack = Array(); var $portlets = Array(); var $show_portlets = true; - + /** miscellaneous items */ var $title = ''; var $systemName = APP_NAME; @@ -72,11 +73,11 @@ class KTPage { var $menu = null; var $userMenu = null; var $helpPage = null; - + /** the "component". Used to set the page header (see documentation for explanation). */ var $componentLabel = 'Browse Documents'; var $componentClass = 'browse_collections'; - + /** $contents is the center of the page. In KT < 3, this was CentralPayload. */ var $contents = ''; @@ -84,14 +85,14 @@ class KTPage { var $contentType = 'text/html'; var $charset = 'UTF-8'; - + var $content_class; - + /* further initialisation */ function KTPage() { - global $default; + global $default; $oConfig = KTConfig::getSingleton(); - + /* default css files initialisation */ $aCSS = Array( "resources/css/kt-framing.css", @@ -99,7 +100,7 @@ class KTPage { "resources/css/kt-headings.css" ); $this->requireCSSResources($aCSS); - + if($oConfig->get('ui/morphEnabled') == '1'){ $morphTheme = $oConfig->get('ui/morphTo'); $this->requireThemeCSSResource('skins/kts_'.$oConfig->get('ui/morphTo').'/kt-morph.css'); @@ -107,13 +108,13 @@ class KTPage { } // IE only $this->requireCSSResource("resources/css/kt-ie-icons.css", true); - + /* default js files initialisation */ $aJS = Array(); $aJS[] = 'thirdpartyjs/yui/yahoo/yahoo.js'; $aJS[] = 'thirdpartyjs/yui/utilities/utilities.js'; - /* + /* $aJS[] = 'thirdpartyjs/MochiKit/MochiKit.js'; $aJS[] = 'thirdpartyjs/MochiKit/New.js'; $aJS[] = 'thirdpartyjs/MochiKit/DragAndDrop.js'; @@ -127,31 +128,32 @@ class KTPage { $aJS[] = 'thirdpartyjs/curvycorners/rounded_corners.inc.js'; $aJS[] = 'resources/js/loader.js'; $aJS[] = 'thirdpartyjs/yui/tools/tools.js'; - + $aJS[] = 'thirdpartyjs/yui/connection/connection.js'; + + - //$aJS[] = 'thirdpartyjs/MochiKit/Iter.js'; //$aJS[] = 'thirdpartyjs/MochiKit/DOM.js'; //$aJS[] = 'thirdpartyjs/MochiKit/Logging.js'; //$aJS[] = 'thirdpartyjs/MochiKit/Async.js'; - //$aJS[] = 'thirdpartyjs/MochiKit/Signal.js'; + //$aJS[] = 'thirdpartyjs/MochiKit/Signal.js'; //$aJS[] = 'thirdpartyjs/MochiKit/.js'; //$aJS[] = 'resources/js/translate.js'; $this->requireJSResources($aJS); - + // this is horrid, but necessary. $this->requireJSStandalone('addLoadEvent(partial(initDeleteProtection, "' . _kt('Are you sure you wish to delete this item?') . '"));'); - + /* menu initialisation*/ // FIXME: how do we want to handle the menu? $this->initMenu(); - + /* portlet initialisation */ $this->show_portlets = true; /* breadcrumbs */ } - + // initiliase the menu. function initMenu() { // FIXME: we lost the getDefaultAction stuff - do we care? @@ -160,25 +162,25 @@ class KTPage { "browse" => $this->_actionHelper(array("name" => _kt("Browse Documents"), "action" => "browse", "active" => 0)), "administration" => $this->_actionHelper(array("name" => _kt("DMS Administration"), "action" => "administration", "active" => 0)),); } - - - function setTitle($sTitle) { - $this->title = $sTitle; + + + function setTitle($sTitle) { + $this->title = $sTitle; } - - /* javascript handling */ + + /* javascript handling */ // require that the specified JS file is referenced. function requireJSResource($sResourceURL) { - $this->js_resources[$sResourceURL] = 1; // use the keys to prevent multiple copies. + $this->js_resources[$sResourceURL] = 1; // use the keys to prevent multiple copies. } - + // require that the specified JS files are referenced. function requireJSResources($aResourceURLs) { foreach ($aResourceURLs as $sResourceURL) { $this->js_resources[$sResourceURL] = 1; } } - + // list the distinct js resources. function getJSResources() { return array_keys($this->js_resources); @@ -191,7 +193,7 @@ class KTPage { function getJSStandalone() { return array_keys($this->js_standalone); } - + /* css handling */ // require that the specified CSS file is referenced. function requireCSSResource($sResourceURL, $ieOnly = false) { @@ -201,7 +203,7 @@ class KTPage { $this->ie_only_css[$sResourceURL] = 1; } } - + // require that the specified CSS file is referenced. function requireThemeCSSResource($sResourceURL, $ieOnly = false) { if ($ieOnly !== true) { @@ -210,28 +212,28 @@ class KTPage { $this->theme_ie_only_css[$sResourceURL] = 1; } } - + // require that the specified CSS files are referenced. function requireCSSResources($aResourceURLs) { foreach ($aResourceURLs as $sResourceURL) { $this->css_resources[$sResourceURL] = 1; } } - + // list the distinct CSS resources. function getCSSResources() { return array_keys($this->css_resources); } - + // list the distinct CSS resources. function getThemeCSSResources() { return array_keys($this->theme_css_resources); } - + function getCSSResourcesForIE() { return array_keys($this->ie_only_css); } - + function getThemeCSSResourcesForIE() { return array_keys($this->theme_ie_only_css); } @@ -243,13 +245,13 @@ class KTPage { function getCSSStandalone() { return array_keys($this->css_standalone); } - + function setPageContents($contents) { $this->contents = $contents; } function setShowPortlets($bShow) { $this->show_portlets = $bShow; } - + /* set the breadcrumbs. the first item is the area name. the rest are breadcrumbs. */ - function setBreadcrumbs($aBreadcrumbs) { + function setBreadcrumbs($aBreadcrumbs) { $breadLength = count($aBreadcrumbs); if ($breadLength != 0) { $this->breadcrumbSection = $this->_actionhelper($aBreadcrumbs[0]); @@ -262,12 +264,12 @@ class KTPage { $this->breadcrumbs = array_map(array(&$this, "_actionhelper"), array_slice($aBreadcrumbs, 1)); } } - + function setBreadcrumbDetails($sBreadcrumbDetails) { $this->breadcrumbDetails = $sBreadcrumbDetails; } function setUser($oUser) { $this->user = $oUser; } - - function setContentClass($sClass) { $this->content_class = $sClass; } - + + function setContentClass($sClass) { $this->content_class = $sClass; } + // FIXME refactor setSection to be generic, not an if-else. // assume this is admin for now. function setSection($sSection) { @@ -277,54 +279,54 @@ class KTPage { $this->menu['administration']['active'] = 1; } else if ($sSection == 'dashboard') { $this->componentLabel = _kt('Dashboard'); - $this->componentClass = 'dashboard'; + $this->componentClass = 'dashboard'; } else if ($sSection == 'browse') { $this->componentLabel = _kt('Browse Documents'); - $this->componentClass = 'browse_collections'; + $this->componentClass = 'browse_collections'; } else if ($sSection == 'view_details') { $this->componentLabel = _kt('Document Details'); - $this->componentClass = 'document_details'; + $this->componentClass = 'document_details'; } else if ($sSection == 'search') { $this->componentLabel = _kt('Search'); - $this->componentClass = 'search'; + $this->componentClass = 'search'; } else if ($sSection == 'preferences') { $this->componentLabel = _kt('Preferences'); - $this->componentClass = 'preferences'; + $this->componentClass = 'preferences'; } else { $this->componentLabel = _kt('Dashboard'); - $this->componentClass = 'dashboard'; + $this->componentClass = 'dashboard'; } } function addError($sError) { array_push($this->errStack, $sError); } function addInfo($sInfo) { array_push($this->infoStack, $sInfo); } - + /** no-one cares what a portlet is, but it should be renderable, and have its ->title member set. */ function addPortlet($oPortlet) { array_push($this->portlets, $oPortlet); } - + /* LEGACY */ var $deprecationWarning = "Legacy UI API: "; function setCentralPayload($sCentral) { $this->contents = $sCentral; $this->addError($this->deprecationWarning . "called setCentralPayload"); } - + function setOnloadJavascript($appendix) { $this->addError($this->deprecationWarning . "called setOnloadJavascript (no-act)"); } function setDHtmlScrolling($appendix) { $this->addError($this->deprecationWarning . "called setDHTMLScrolling (no-act)"); } function setFormAction($appendix) { $this->addError($this->deprecationWarning . "called setFormAction (no-act)"); } function setSubmitMethod($appendix) { $this->addError($this->deprecationWarning . "called setSubmitMethod (no-act)"); } function setHasRequiredFields($appendix) { $this->addError($this->deprecationWarning . "called setHasRequiredFields (no-act)"); } function setAdditionalJavascript($appendix) { $this->addError($this->deprecationWarning . "called setAdditionalJavascript (no-act)"); } - + function hideSection() { $this->hide_section = true; } function setSecondaryTitle($sSecondary) { $this->secondary_title = $sSecondary; } - + /* final render call. */ function render() { - global $default; + global $default; $oConfig = KTConfig::getSingleton(); if (empty($this->contents)) { @@ -335,16 +337,16 @@ class KTPage { $this->addError(_kt("This page did not produce any content")); $this->contents = ""; } - + if (!is_string($this->contents)) { $this->contents = $this->contents->render(); } - + // if we have no portlets, make the ui a tad nicer. if (empty($this->portlets)) { $this->show_portlets = false; } - + if (empty($this->title)) { if (!empty($this->breadcrumbDetails)) { $this->title = $this->breadcrumbDetails; @@ -357,9 +359,9 @@ class KTPage { $this->title = $this->componentLabel; } } - + $this->userMenu = array(); - if (!(PEAR::isError($this->user) || is_null($this->user) || $this->user->isAnonymous())) { + if (!(PEAR::isError($this->user) || is_null($this->user) || $this->user->isAnonymous())) { if ($oConfig->get("user_prefs/restrictPreferences", false) && !Permission::userIsSystemAdministrator($this->user->getId())) { $this->userMenu = array("logout" => $this->_actionHelper(array("name" => _kt("Logout"), "action" => "logout", "active" => 0)),); } else { @@ -369,42 +371,46 @@ class KTPage { } } else { $this->userMenu = array("login" => $this->_actionHelper(array("name" => _kt("Login"), "action" => "login")),); - } - + } + // FIXME we need a more complete solution to navigation restriction if (!is_null($this->menu['administration']) && !is_null($this->user)) { if (!Permission::userIsSystemAdministrator($this->user->getId())) { unset($this->menu['administration']); } } - + $sContentType = 'Content-type: ' . $this->contentType; if(!empty($this->charset)) { $sContentType .= '; charset=' . $this->charset; }; - + header($sContentType); - - $oTemplating =& KTTemplating::getSingleton(); + + $savedSearches = SearchHelper::getSavedSearches($_SESSION['userID']); + + $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate($this->template); - $aTemplateData = array("page" => $this, - "systemversion" => $default->systemVersion, - "versionname" => $default->versionName,); + $aTemplateData = array( + "page" => $this, + "systemversion" => $default->systemVersion, + "versionname" => $default->versionName, + 'savedSearches'=> $savedSearches); if ($oConfig->get("ui/automaticRefresh", false)) { $aTemplateData['refreshTimeout'] = (int)$oConfig->get("session/sessionTimeout") + 3; } - + // unlike the rest of KT, we use echo here. echo $oTemplate->render($aTemplateData); } - + /** heler functions */ // returns an array ("url", "label") function _actionhelper($aActionTuple) { $aTuple = Array("label" => $aActionTuple["name"]); - if ($aActionTuple["action"]) { + if ($aActionTuple["action"]) { $aTuple["url"] = generateControllerLink($aActionTuple["action"], $aActionTuple["query"]); } else if ($aActionTuple["url"]) { $sUrl = $aActionTuple["url"]; @@ -418,22 +424,22 @@ class KTPage { } else { $aTuple["url"] = false; } - + return $aTuple; } - + function setHelp($sHelpPage) { $this->helpPage = $sHelpPage; } - + function getHelpURL() { - if (empty($this->helpPage)) { + if (empty($this->helpPage)) { return null; } - - return KTUtil::ktLink('help.php',$this->helpPage); + + return KTUtil::ktLink('help.php',$this->helpPage); } - + function getReqTime() { $microtime_simple = explode(' ', microtime()); $finaltime = (float) $microtime_simple[1] + (float) $microtime_simple[0]; @@ -449,7 +455,7 @@ class KTPage { return; } } - + } ?> -- libgit2 0.21.4