File modules/cms/action/SearchAction.class.php

Last commit: Fri Apr 15 14:51:22 2022 +0200	dankert	Refactoring: User,Config and Database info is now stored in the Request, because so there is no session required for clients which are using Basic Authorization.
1 <?php 2 3 namespace cms\action; 4 5 use cms\base\Configuration as C; 6 use cms\model\Content; 7 use cms\model\Permission; 8 use cms\model\BaseObject; 9 use cms\model\File; 10 use cms\model\Project; 11 use cms\model\Template; 12 use cms\model\User; 13 use cms\model\Value; 14 use util\Session; 15 16 17 // OpenRat Content Management System 18 // Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de 19 // 20 // This program is free software; you can redistribute it and/or 21 // modify it under the terms of the GNU General Public License 22 // as published by the Free Software Foundation; either version 2 23 // of the License, or (at your option) any later version. 24 // 25 // This program is distributed in the hope that it will be useful, 26 // but WITHOUT ANY WARRANTY; without even the implied warranty of 27 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 28 // GNU General Public License for more details. 29 // 30 // You should have received a copy of the GNU General Public License 31 // along with this program; if not, write to the Free Software 32 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 33 34 35 36 37 /** 38 * Action-Klasse fuer die Suchfunktion. 39 * 40 * @author $Author$ 41 * @version $Revision$ 42 * @package openrat.actions 43 */ 44 class SearchAction extends BaseAction 45 { 46 const FLAG_ID = 1; 47 const FLAG_NAME = 2; 48 const FLAG_FILENAME = 4; 49 const FLAG_DESCRIPTION = 8; 50 const FLAG_VALUE = 16; 51 52 /** 53 * leerer Kontruktor 54 */ 55 function __construct() 56 { 57 parent::__construct(); 58 } 59 60 61 62 public function editView() 63 { 64 $user = $this->currentUser; 65 $this->setTemplateVar( 'users' ,User::listAll() ); 66 $this->setTemplateVar( 'act_userid',$user->userid ); 67 } 68 69 /** 70 * Query the search 71 * 72 * @param $searchText string search query text 73 * @param $searchFlag int field selector 74 */ 75 protected function performSearch($searchText, $searchFlag) 76 { 77 $listObjectIds = array(); 78 $listTemplateIds = array(); 79 80 $resultList = array(); 81 82 83 if ( $searchFlag & self::FLAG_ID ) 84 { 85 if ( BaseObject::available( intval($searchText) ) ) { 86 87 $listObjectIds[intval($searchText)] = intval( $searchText ); 88 } 89 90 if ( $this->userIsAdmin() ) { 91 92 $user = new User( intval($searchText) ); 93 94 try { 95 $user->load(); 96 97 $userResult = array( 'url' => '', 98 'type' => 'user', 99 'id' => $user->userid, 100 'name' => $user->fullname, 101 'desc' => $user->desc, 102 'lastchange_date' => 0 ); 103 $resultList['u'.$user->userid] = $userResult; 104 } 105 catch( \util\exception\ObjectNotFoundException $content) { 106 ; // userid is unknown 107 } 108 } 109 } 110 111 if ( $searchFlag & self::FLAG_NAME ) 112 { 113 if ( $this->userIsAdmin() ) { 114 115 $user = User::loadWithName($searchText,User::AUTH_TYPE_INTERNAL); 116 if (is_object($user)) { 117 $userResult = array('url' => '', 118 'type' => 'user', 119 'id' => $user->userid, 120 'name' => $user->fullname, 121 'desc' => $user->desc, 122 'lastchange_date' => 0); 123 $resultList['u'.$user->userid] = $userResult; 124 } 125 } 126 127 $listObjectIds += BaseObject::getObjectIdsByName( $searchText ); 128 } 129 130 if ( $searchFlag & self::FLAG_DESCRIPTION ) 131 { 132 $listObjectIds += BaseObject::getObjectIdsByDescription( $searchText ); 133 } 134 135 if ( $searchFlag & self::FLAG_FILENAME ) 136 { 137 $listObjectIds += BaseObject::getObjectIdsByFilename( $searchText ); 138 139 $listObjectIds += File::getObjectIdsByExtension( $searchText ); 140 } 141 142 // Inhalte durchsuchen 143 if ( $searchFlag & self::FLAG_VALUE ) 144 { 145 $listObjectIds += Content::getObjectIdsByValue( $searchText ); 146 147 $listTemplateIds += Template::getTemplateIdsByValue( $searchText ); 148 } 149 150 $resultList = array_merge( $resultList, $this->explainResult( $listObjectIds, $listTemplateIds ) ); 151 152 $this->setTemplateVar( 'result',$resultList ); 153 } 154 155 156 /** 157 * Transforms the found objects into an array of search results. 158 * 159 * @param $listObjectIds Object ids 160 * @param $listTemplateIds template ids 161 * @return array 162 * @throws \util\exception\ObjectNotFoundException 163 */ 164 private function explainResult( $listObjectIds, $listTemplateIds ) 165 { 166 $resultList = array(); 167 168 foreach( $listObjectIds as $objectid ) 169 { 170 $o = new BaseObject( $objectid ); 171 $o->load(); 172 if ($o->hasRight( Permission::ACL_READ )) 173 $resultList['o'.$objectid] = [ 174 'id' => $objectid, 175 'type' => $o->getType(), 176 'name' => $o->filename, 177 'lastchange_date' => $o->lastchangeDate, 178 'desc' => '' 179 ]; 180 } 181 182 foreach( $listTemplateIds as $templateid ) 183 { 184 $t = new Template( $templateid ); 185 $t->load(); 186 $p = new Project( $t->projectid ); 187 $rootObject = new BaseObject( $p->getRootObjectId() ); 188 if ($rootObject->hasRight( Permission::ACL_PROP )) // only project admins may read the templates 189 $resultList['t'.$templateid] = [ 190 'id' => $templateid, 191 'type'=> 'template', 192 'name'=> $t->name, 193 'desc'=> '', 194 'lastchange_date'=> 0 195 ]; 196 } 197 198 return $resultList; 199 } 200 201 202 /** 203 * The search is executable for all users. 204 * But the search results are filtered. 205 * 206 * @return true 207 */ 208 public function checkAccess() { 209 return true; 210 } 211 }
Download modules/cms/action/SearchAction.class.php
History Fri, 15 Apr 2022 14:51:22 +0200 dankert Refactoring: User,Config and Database info is now stored in the Request, because so there is no session required for clients which are using Basic Authorization. Thu, 10 Mar 2022 10:28:14 +0100 dankert Fix: Fulltext-Search was broken due to the last Content-Refactoring Mon, 6 Dec 2021 22:56:52 +0100 dankert Fixes: Layout fix for search; unique results in search. Sun, 5 Dec 2021 20:33:24 +0100 dankert Cleanup: Removed unusable properties from class 'Value' and 'BaseObject'. Sun, 14 Mar 2021 22:29:56 +0100 Jan Dankert Refactoring: Clearer access check. Mon, 4 Jan 2021 19:03:18 +0100 Jan Dankert Refactoring: ACL class is renamed to Permission, because most RBAC/DMAC concepts are calling it a permission. Wed, 18 Nov 2020 00:18:10 +0100 Jan Dankert Refactoring Part 2: Removing all unnecessary methods in the action base classes. Tue, 17 Nov 2020 23:51:00 +0100 Jan Dankert Refactoring: Every Actionmethod has now its own class. Sat, 31 Oct 2020 00:43:29 +0100 Jan Dankert New: Support for OpenId Connect; Removed: Support for LDAP. Tue, 29 Sep 2020 22:17:11 +0200 Jan Dankert Refactoring: Do not use global constants. Tue, 29 Sep 2020 01:13:54 +0200 Jan Dankert Fix: The search function now finds objects id with a length less than 3. Sat, 26 Sep 2020 10:32:02 +0200 Jan Dankert Refactoring: No global $conf array any more. Sun, 23 Feb 2020 04:01:30 +0100 Jan Dankert Refactoring with Namespaces for the cms modules, part 1: moving.