| [ Index ] |
|
Code source de Plume CMS 1.2.2 |
1 <?php 2 /* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 3 /* 4 # ***** BEGIN LICENSE BLOCK ***** 5 # This file is part of Plume CMS, a website management application. 6 # Copyright (C) 2001-2005 Loic d'Anterroches and contributors. 7 # 8 # Plume CMS is free software; you can redistribute it and/or modify 9 # it under the terms of the GNU General Public License as published by 10 # the Free Software Foundation; either version 2 of the License, or 11 # (at your option) any later version. 12 # 13 # Plume CMS is distributed in the hope that it will be useful, 14 # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 # GNU General Public License for more details. 17 # 18 # You should have received a copy of the GNU General Public License 19 # along with this program; if not, write to the Free Software 20 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 # 22 # ***** END LICENSE BLOCK ***** */ 23 24 /** 25 * Levels of rights for the users. Equivalent to the ones 26 * in lib.auth.php, need a merging at some point. 27 */ 28 define('PX_USER_LEVEL_ADMIN', 9); 29 define('PX_USER_LEVEL_ADVANCED', 5); 30 define('PX_USER_LEVEL_SIMPLE', 1); 31 define('PX_USER_LEVEL_DISABLE', 0); 32 33 require_once dirname(__FILE__).'/class.l10n.php'; 34 35 /** 36 * Basic manager, it implements basic functionnalities 37 */ 38 class BasicManager extends CError 39 { 40 var $con = null; 41 var $user = null; 42 var $l10n = null; 43 44 function BasicManager() 45 { 46 $this->con =& pxDBConnect(); 47 } 48 49 function setUser(&$user) 50 { 51 global $_PX_website_config; 52 $this->user = $user; 53 $this->l10n = new l10n($this->user->lang); 54 if (!empty($this->user->website)) { 55 if (file_exists($GLOBALS['_PX_config']['manager_path'].'/conf/configweb_'.$this->user->website.'.php')) { 56 include_once($GLOBALS['_PX_config']['manager_path'].'/conf/configweb_'.$this->user->website.'.php'); 57 } 58 } 59 return true; 60 } 61 62 function getUsers() 63 { 64 $r = 'SELECT * FROM '.$this->con->pfx.'users'; 65 if ($this->user->f('user_id') != 1) { 66 $r .= "\n".'LEFT JOIN '.$this->con->pfx.'grants ON 67 '.$this->con->pfx.'users.user_id='.$this->con->pfx.'grants.user_id 68 WHERE '.$this->con->pfx.'grants.website_id=\''.$this->user->website.'\''; 69 } 70 if (($rs = $this->con->select($r, 'User')) !== false) { 71 return $rs; 72 } else { 73 $this->setError('MySQL: '.$this->con->error(), 500); 74 return false; 75 } 76 } 77 78 function getUserById($id) 79 { 80 if (strlen($id) && preg_match('/^[0-9]+$/',$id)) { 81 $where = 'WHERE user_id=\''.$this->con->escapeStr($id).'\''; 82 } else { 83 $where = 'WHERE user_username=\''.$this->con->escapeStr($id).'\''; 84 } 85 $r = 'SELECT * FROM '.$this->con->pfx.'users '.$where; 86 if (($rs = $this->con->select($r, 'User')) !== false) { 87 return $rs; 88 } else { 89 $this->setError('MySQL : '.$this->con->error(), 500); 90 return false; 91 } 92 } 93 94 95 96 97 /** Get all the categories of the current website. 98 99 @param int parent id of the categories ('') 100 @param string extra condition ('') 101 @param string order condition ('ORDER BY category_path') 102 @return object recordset 103 */ 104 function getCategories($parentid = '', $extra = '', $order = 'ORDER BY category_path') 105 { 106 $r = 'SELECT * FROM '.$this->con->pfx.'categories WHERE website_id=\''.$this->user->website.'\''; 107 if (!empty($parentid)) { 108 $r .= ' AND category_parentid=\''.$this->con->escapeStr($parentid).'\''; 109 } 110 if (!empty($extra)) { 111 $r .= ' AND ('.$extra.')'; 112 } 113 $r .= ' '.$order; 114 if (($rs = $this->con->select($r)) !== false) { 115 return $rs; 116 } else { 117 $this->setError('MySQL : '.$this->con->error(), 500); 118 return false; 119 } 120 } 121 122 /** Get a category by id or path 123 124 @param int => by id, string => by path 125 @return object recordset 126 */ 127 function getCategory($id) 128 { 129 if (preg_match('/^[0-9]+$/', $id)) { 130 $r = 'SELECT * FROM '.$this->con->pfx.'categories WHERE website_id=\''.$this->user->website.'\' 131 AND category_id=\''.$this->con->escapeStr($id).'\''; 132 } else { 133 $r = 'SELECT * FROM '.$this->con->pfx.'categories WHERE website_id=\''.$this->user->website.'\' 134 AND category_path=\''.$this->con->escapeStr($id).'\''; 135 } 136 137 if (($rs = $this->con->select($r)) !== false) { 138 return $rs; 139 } else { 140 $this->setError('MySQL : '.$this->con->error(), 500); 141 return false; 142 } 143 } 144 145 /** 146 * Get templates. 147 * 148 * Get the list of templates for the website with a filter by 149 * radical. 150 * 151 * @return array 152 * @param string radical 153 */ 154 function getTemplates($rad='') 155 { 156 $res = array(); 157 if (strlen($rad) > 0) { 158 $regex = '/^('.$rad.')\_([A-Za-z0-9\_\-]+)(\.tpl|\.php|\.html|\.htm|\.xhtml)$/i'; 159 } else { 160 $regex = '/^()([A-Za-z0-9\_\-]+)(\.tpl|\.php|\.html|\.htm|\.xhtml)$/i'; 161 } 162 if (false !== ($rep=@opendir(config::f('manager_path').'/templates/'.config::f('theme_id')))) { 163 while ($file = readdir($rep)) { 164 if (preg_match($regex, $file, $match)) { 165 $res[$match[2].$match[3]] = $file; 166 } 167 } 168 } else { 169 $this->setError( __('Error: Impossible to load the list of templates, check the availability of the template folder.'), 500); 170 } 171 return $res; 172 } 173 174 175 176 function getSites($id = '') 177 { 178 $r = 'SELECT * FROM '.$this->con->pfx.'websites'; 179 if (strlen($id)) 180 $r .= ' WHERE website_id = \''.$this->con->escapeStr($id).'\''; 181 182 if (($rs = $this->con->select($r)) !== false) { 183 return $rs; 184 } else { 185 $this->setError('MySQL : '.$this->con->error(), 500); 186 return false; 187 } 188 } 189 190 191 /** 192 Get resources by search. 193 194 @return object Resource or as specified 195 @param string Query string 196 @param bool Is the resource available online (true) 197 @param string Type of the resource (all) 198 @param string Type of object to return 199 */ 200 function searchResources($query, $online=true, $type='', $class='ResourceSet') 201 { 202 include_once dirname(__FILE__).'/class.search.php'; 203 include_once dirname(__FILE__).'/class.resourceset.php'; 204 205 $this->con = &pxDBConnect(); 206 $s = new Search($this->con, $this->user->website); 207 $sql = $s->create_search_query_string($query); 208 $extra = ''; 209 if ($online) { 210 $extra .= ' AND '.$this->con->pfx.'resources.publicationdate <= '.date::stamp(); 211 $extra .= ' AND '.$this->con->pfx.'resources.enddate >= '.date::stamp(); 212 $extra .= ' AND '.$this->con->pfx.'resources.status = '.PX_RESOURCE_STATUS_VALIDE; 213 } 214 if (!empty($type)) { 215 $extra .= ' AND '.$this->con->pfx.'resources.type_id=\''.$this->con->escapeStr($type).'\''; 216 } 217 $sql = sprintf($sql, $extra); 218 219 if (($rs = $this->con->select($sql, $class)) !== false) { 220 return $rs; 221 } else { 222 $this->setError('MySQL : '.$this->con->error(), 500); 223 return false; 224 } 225 226 } 227 228 /** Get a list of resources, possible filter by user, date, status, 229 category. 230 231 @author loic d'Anterroches 232 @return object Resource 233 @param int user id 234 @paran int status 235 @param int category 236 @param string type_id 237 @param int date start (last modification) 238 @param int date end (last modification) 239 @param string limit 240 @param string order ASC or DESC [default] 241 @paran bool availableonline if set to true, will find only the that have good startdate and enddate for today 242 */ 243 function getResources($user_id='', $status='', $category='', $type='', $datestart='', $dateend='', $limit='', $order='DESC', $availableonline = false) 244 { 245 $r = 'SELECT * FROM '.$this->con->pfx.'resources 246 LEFT JOIN '.$this->con->pfx.'categoryasso ON '.$this->con->pfx.'categoryasso.identifier='.$this->con->pfx.'resources.identifier 247 LEFT JOIN '.$this->con->pfx.'categories ON '.$this->con->pfx.'categoryasso.category_id='.$this->con->pfx.'categories.category_id 248 LEFT JOIN '.$this->con->pfx.'websites ON '.$this->con->pfx.'websites.website_id='.$this->con->pfx.'resources.website_id '; 249 if ($type == 'news') { 250 $r .= ' LEFT JOIN '.$this->con->pfx.'news ON '.$this->con->pfx.'news.resource_id='.$this->con->pfx.'resources.resource_id '; 251 } 252 $r .= ' WHERE '.$this->con->pfx.'resources.website_id=\''.$this->user->website.'\' '; 253 254 if (strlen($user_id)/* || !authAsLevel(PX_USER_LEVEL_ADVANCED, $this->user->website)*/) { 255 $r .= ' AND '.$this->con->pfx.'resources.user_id=\''; 256 $r .= ( (strlen($user_id)) ? $user_id : $this->user->user['user_id']).'\''; 257 } 258 if (strlen($status)) 259 $r .= ' AND '.$this->con->pfx.'resources.status=\''.$this->con->escapeStr($status).'\''; 260 if (strlen($category)) 261 $r .= ' AND '.$this->con->pfx.'categories.category_id=\''.$this->con->escapeStr($category).'\''; 262 else 263 $r .= ' AND '.$this->con->pfx.'categoryasso.categoryasso_type='.PX_RESOURCE_CATEGORY_MAIN.' '; 264 if (strlen($type)) 265 $r .= ' AND '.$this->con->pfx.'resources.type_id=\''.$this->con->escapeStr($type).'\''; 266 if (strlen($datestart)) { 267 $r .= ' AND '.$this->con->pfx.'resources.modifdate >= '.$datestart; 268 } 269 if (strlen($dateend)) { 270 $r .= ' AND '.$this->con->pfx.'resources.modifdate <= '.$dateend; 271 } 272 if ($availableonline) { 273 $r .= ' AND '.$this->con->pfx.'resources.publicationdate <= '.date::stamp(); 274 $r .= ' AND '.$this->con->pfx.'resources.enddate >= '.date::stamp(); 275 } 276 if ($order == 'DESC' or $order == 'ASC') { 277 $r .= ' ORDER BY '.$this->con->pfx.'resources.modifdate '.(($order == 'DESC') ? 'DESC' : 'ASC'); 278 } else { 279 $r .= ' '.sprintf($order, $this->con->pfx); 280 } 281 282 // By Olivier Meunier << 283 if ($limit != '') { 284 $limit = (preg_match('/^[0-9]+$/',$limit)) ? '0,'.$limit : $limit; 285 $r .= ' LIMIT '.$limit.' '; 286 } 287 // >> 288 289 if (($rs = $this->con->select($r, 'resourceset')) !== false) { 290 return $rs; 291 } else { 292 $this->setError('MySQL : '.$this->con->error(), 500); 293 return false; 294 } 295 } 296 297 /** Get a resource by its identifier or id 298 299 @author loic d'Anterroches 300 @return object Resource or false 301 @param string/int identifier 302 @param string type of object to return default is 'Resource' 303 */ 304 function getResourceByIdentifier($identifier = '', $class = 'Resource') 305 { 306 $r = 'SELECT * FROM '.$this->con->pfx.'resources 307 LEFT JOIN '.$this->con->pfx.'categoryasso ON '.$this->con->pfx.'categoryasso.identifier='.$this->con->pfx.'resources.identifier 308 LEFT JOIN '.$this->con->pfx.'categories ON '.$this->con->pfx.'categoryasso.category_id='.$this->con->pfx.'categories.category_id 309 LEFT JOIN '.$this->con->pfx.'websites ON '.$this->con->pfx.'websites.website_id='.$this->con->pfx.'resources.website_id '; 310 if ($class == 'News') { 311 $r .= ' LEFT JOIN '.$this->con->pfx.'news ON '.$this->con->pfx.'news.resource_id='.$this->con->pfx.'resources.resource_id '; 312 } 313 $r .= ' WHERE 314 categoryasso_type=\''.PX_RESOURCE_CATEGORY_MAIN.'\''; 315 if (strlen($identifier) && preg_match('/^[0-9]+$/',$identifier)) 316 $r .= ' AND '.$this->con->pfx.'resources.resource_id=\''.$this->con->escapeStr($identifier).'\''; 317 elseif (strlen($identifier)) 318 $r .= ' AND '.$this->con->pfx.'resources.identifier=\''.$this->con->escapeStr($identifier).'\''; 319 else 320 return false; 321 322 if (($rs = $this->con->select($r, $class)) !== false) { 323 $rs->load(); 324 return $rs; 325 } else { 326 $this->setError('MySQL: '.$this->con->error(), 500); 327 return false; 328 } 329 } 330 331 332 333 /** 334 @note Available under MPL 1.1/GPL 2.0/LGPL 2.1 with DotClear Weblog 335 More details: http://www.dotclear.net/ 336 @author Olivier Meunier 337 */ 338 function getAllDates($format='m',$type='',$cat='') 339 { 340 if ($format == 'y') { 341 $len = 4; 342 } elseif ($type == 'd') { 343 $len = 8; 344 } else { 345 $len = 6; 346 } 347 348 $reqPlus = ' WHERE '.$this->con->pfx.'resources.website_id=\''.$this->user->website.'\' '; 349 350 if (strlen($type)) $reqPlus .= ' AND '.$this->con->pfx.'resources.type_id=\''.$this->con->escapeStr($type).'\' '; 351 if (strlen($cat)) $reqPlus .= ' AND category_id =\''.$this->con->escapeStr($cat).'\' '; 352 353 $strReq = 'SELECT DISTINCT RPAD(LEFT(CONCAT(modifdate),'.$len.'),8,\'01\') '; 354 $strReq .= ' FROM '.$this->con->pfx.'resources '; 355 if (strlen($cat)) 356 $strReq .= 'LEFT JOIN '.$this->con->pfx.'categoryasso ON '.$this->con->pfx. 357 'categoryasso.identifier='.$this->con->pfx.'resources.identifier'; 358 359 $strReq .= $reqPlus.' ORDER BY modifdate DESC '; 360 361 if (($rs = $this->con->select($strReq)) === false) { 362 $this->setError('MySQL : '.$this->con->error(), 500); 363 return false; 364 } else { 365 $res = array(); 366 while(!$rs->EOF()) { 367 $res[str_pad($rs->field(0),14,'0')] = str_pad($rs->field(0),14,'0'); 368 $rs->moveNext(); 369 } 370 return $res; 371 } 372 } 373 374 function getEarlierDate($format='m', $type='', $cat='', $website='') 375 { 376 if ($format == 'y') { 377 $len = 4; 378 } elseif ($type == 'd') { 379 $len = 8; 380 } else { 381 $len = 6; 382 } 383 384 if (strlen($website) == 0) { 385 $website = $this->user->website; 386 } 387 $reqPlus = ' WHERE '.$this->con->pfx.'resources.website_id=\''.$this->con->escapeStr($website).'\' '; 388 389 if (strlen($type)) $reqPlus .= ' AND '.$this->con->pfx.'resources.type_id=\''.$this->con->escapeStr($type).'\' '; 390 if (strlen($cat)) $reqPlus .= ' AND category_id =\''.$this->con->escapeStr($cat).'\' '; 391 392 $strReq = 'SELECT DISTINCT RPAD(LEFT(CONCAT(modifdate),'.$len.'),8,\'01\') '; 393 $strReq .= ' FROM '.$this->con->pfx.'resources '; 394 if (strlen($cat)) 395 $strReq .= 'LEFT JOIN '.$this->con->pfx.'categoryasso ON '.$this->con->pfx. 396 'categoryasso.identifier='.$this->con->pfx.'resources.identifier'; 397 398 $strReq .= $reqPlus.' ORDER BY modifdate DESC LIMIT 1'; 399 400 if (($rs = $this->con->select($strReq)) === false) { 401 $this->setError('MySQL : '.$this->con->error(), 500); 402 return false; 403 } else { 404 if ($rs->nbRow() == 1) 405 return str_pad($rs->field(0),14,'0'); 406 return false; 407 } 408 } 409 410 411 /** 412 Search for a resource. Restriction to available online or by type. 413 414 @param string Query string 415 @param bool Available online (true) 416 @param string Type of resource ('') 417 @return object Recordset of the resources 418 */ 419 function search($query, $online = true, $type = '') 420 { 421 422 } 423 424 } // end class Manager 425 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Mon Nov 26 11:57:01 2007 | par Balluche grâce à PHPXref 0.7 |
|