Annotation of /mambo/branches/4.6/components/com_content/content.class.php
Parent Directory
|
Revision Log
Revision 1756 - (view) (download)
| 1 : | elpie | 1756 | <?php |
| 2 : | /** | ||
| 3 : | * @package Mambo | ||
| 4 : | * @author Mambo Foundation Inc see README.php | ||
| 5 : | * @copyright (C) 2000 - 2009 Mambo Foundation Inc. | ||
| 6 : | * See COPYRIGHT.php for copyright notices and details. | ||
| 7 : | * @license GNU/GPL Version 2, see LICENSE.php | ||
| 8 : | * | ||
| 9 : | * Redistributions of files must retain the above copyright notice. | ||
| 10 : | * | ||
| 11 : | * Mambo is free software; you can redistribute it and/or | ||
| 12 : | * modify it under the terms of the GNU General Public License | ||
| 13 : | * as published by the Free Software Foundation; version 2 of the License. | ||
| 14 : | */ | ||
| 15 : | |||
| 16 : | /** | ||
| 17 : | * Category database table class | ||
| 18 : | */ | ||
| 19 : | class mosCategory extends mosDBTable { | ||
| 20 : | /** @var int Primary key */ | ||
| 21 : | var $id=null; | ||
| 22 : | /** @var int */ | ||
| 23 : | var $parent_id=null; | ||
| 24 : | /** @var string The menu title for the Category (a short name)*/ | ||
| 25 : | var $title=null; | ||
| 26 : | /** @var string The full name for the Category*/ | ||
| 27 : | var $name=null; | ||
| 28 : | /** @var string */ | ||
| 29 : | var $image=null; | ||
| 30 : | /** @var string */ | ||
| 31 : | var $section=null; | ||
| 32 : | /** @var int */ | ||
| 33 : | var $image_position=null; | ||
| 34 : | /** @var string */ | ||
| 35 : | var $description=null; | ||
| 36 : | /** @var boolean */ | ||
| 37 : | var $published=null; | ||
| 38 : | /** @var boolean */ | ||
| 39 : | var $checked_out=null; | ||
| 40 : | /** @var time */ | ||
| 41 : | var $checked_out_time=null; | ||
| 42 : | /** @var string */ | ||
| 43 : | var $editor=null; | ||
| 44 : | /** @var int */ | ||
| 45 : | var $ordering=null; | ||
| 46 : | /** @var int */ | ||
| 47 : | var $access=null; | ||
| 48 : | /** @var int */ | ||
| 49 : | var $count=null; | ||
| 50 : | /** @var string */ | ||
| 51 : | var $params=null; | ||
| 52 : | |||
| 53 : | /** | ||
| 54 : | * @param database A database connector object | ||
| 55 : | */ | ||
| 56 : | function mosCategory( &$db ) { | ||
| 57 : | $this->mosDBTable( '#__categories', 'id', $db ); | ||
| 58 : | } | ||
| 59 : | // overloaded check function | ||
| 60 : | function check() { | ||
| 61 : | // check for valid name | ||
| 62 : | if (trim( $this->title ) == '') { | ||
| 63 : | $this->_error = "Your Category must contain a title."; | ||
| 64 : | return false; | ||
| 65 : | } | ||
| 66 : | if (trim( $this->name ) == '') { | ||
| 67 : | $this->_error = "Your Category must have a name."; | ||
| 68 : | return false; | ||
| 69 : | } | ||
| 70 : | // check for existing name | ||
| 71 : | $this->_db->setQuery( "SELECT id FROM #__categories " | ||
| 72 : | . "\nWHERE name='".$this->name."' AND section='".$this->section."'" | ||
| 73 : | ); | ||
| 74 : | |||
| 75 : | $xid = intval( $this->_db->loadResult() ); | ||
| 76 : | if ($xid && $xid != intval( $this->id )) { | ||
| 77 : | $this->_error = "There is a category already with that name, please try again."; | ||
| 78 : | return false; | ||
| 79 : | } | ||
| 80 : | return true; | ||
| 81 : | } | ||
| 82 : | } | ||
| 83 : | |||
| 84 : | /** | ||
| 85 : | * Section database table class | ||
| 86 : | * @package Mambo | ||
| 87 : | */ | ||
| 88 : | class mosSection extends mosDBTable { | ||
| 89 : | /** @var int Primary key */ | ||
| 90 : | var $id=null; | ||
| 91 : | /** @var string The menu title for the Section (a short name)*/ | ||
| 92 : | var $title=null; | ||
| 93 : | /** @var string The full name for the Section*/ | ||
| 94 : | var $name=null; | ||
| 95 : | /** @var string */ | ||
| 96 : | var $image=null; | ||
| 97 : | /** @var string */ | ||
| 98 : | var $scope=null; | ||
| 99 : | /** @var int */ | ||
| 100 : | var $image_position=null; | ||
| 101 : | /** @var string */ | ||
| 102 : | var $description=null; | ||
| 103 : | /** @var boolean */ | ||
| 104 : | var $published=null; | ||
| 105 : | /** @var boolean */ | ||
| 106 : | var $checked_out=null; | ||
| 107 : | /** @var time */ | ||
| 108 : | var $checked_out_time=null; | ||
| 109 : | /** @var int */ | ||
| 110 : | var $ordering=null; | ||
| 111 : | /** @var int */ | ||
| 112 : | var $access=null; | ||
| 113 : | /** @var string */ | ||
| 114 : | var $params=''; | ||
| 115 : | |||
| 116 : | /** | ||
| 117 : | * @param database A database connector object | ||
| 118 : | */ | ||
| 119 : | function mosSection( &$db ) { | ||
| 120 : | $this->mosDBTable( '#__sections', 'id', $db ); | ||
| 121 : | } | ||
| 122 : | // overloaded check function | ||
| 123 : | function check() { | ||
| 124 : | // check for valid name | ||
| 125 : | if (trim( $this->title ) == '') { | ||
| 126 : | $this->_error = "Your Section must contain a title."; | ||
| 127 : | return false; | ||
| 128 : | } | ||
| 129 : | if (trim( $this->name ) == '') { | ||
| 130 : | $this->_error = "Your Section must have a name."; | ||
| 131 : | return false; | ||
| 132 : | } | ||
| 133 : | // check for existing name | ||
| 134 : | $this->_db->setQuery( "SELECT id FROM #__sections " | ||
| 135 : | . "\nWHERE name='$this->name' AND scope='$this->scope'" | ||
| 136 : | ); | ||
| 137 : | |||
| 138 : | $xid = intval( $this->_db->loadResult() ); | ||
| 139 : | if ($xid && $xid != intval( $this->id )) { | ||
| 140 : | $this->_error = "There is a section already with that name, please try again."; | ||
| 141 : | return false; | ||
| 142 : | } | ||
| 143 : | return true; | ||
| 144 : | } | ||
| 145 : | } | ||
| 146 : | |||
| 147 : | /** | ||
| 148 : | * Module database table class | ||
| 149 : | * @package Mambo | ||
| 150 : | */ | ||
| 151 : | class mosContent extends mosDBTable { | ||
| 152 : | /** @var int Primary key */ | ||
| 153 : | var $id=null; | ||
| 154 : | /** @var string */ | ||
| 155 : | var $title=null; | ||
| 156 : | /** @var string */ | ||
| 157 : | var $title_alias=null; | ||
| 158 : | /** @var string */ | ||
| 159 : | var $introtext=null; | ||
| 160 : | /** @var string */ | ||
| 161 : | var $fulltext=null; | ||
| 162 : | /** @var int */ | ||
| 163 : | var $state=null; | ||
| 164 : | /** @var int The id of the category section*/ | ||
| 165 : | var $sectionid=null; | ||
| 166 : | /** @var int DEPRECATED */ | ||
| 167 : | var $mask=null; | ||
| 168 : | /** @var int */ | ||
| 169 : | var $catid=null; | ||
| 170 : | /** @var datetime */ | ||
| 171 : | var $created=null; | ||
| 172 : | /** @var int User id*/ | ||
| 173 : | var $created_by=null; | ||
| 174 : | /** @var string An alias for the author*/ | ||
| 175 : | var $created_by_alias=null; | ||
| 176 : | /** @var datetime */ | ||
| 177 : | var $modified=null; | ||
| 178 : | /** @var int User id*/ | ||
| 179 : | var $modified_by=null; | ||
| 180 : | /** @var boolean */ | ||
| 181 : | var $checked_out=null; | ||
| 182 : | /** @var time */ | ||
| 183 : | var $checked_out_time=null; | ||
| 184 : | /** @var datetime */ | ||
| 185 : | var $frontpage_up=null; | ||
| 186 : | /** @var datetime */ | ||
| 187 : | var $frontpage_down=null; | ||
| 188 : | /** @var datetime */ | ||
| 189 : | var $publish_up=null; | ||
| 190 : | /** @var datetime */ | ||
| 191 : | var $publish_down=null; | ||
| 192 : | /** @var string */ | ||
| 193 : | var $images=null; | ||
| 194 : | /** @var string */ | ||
| 195 : | var $urls=null; | ||
| 196 : | /** @var string */ | ||
| 197 : | var $attribs=null; | ||
| 198 : | /** @var int */ | ||
| 199 : | var $version=null; | ||
| 200 : | /** @var int */ | ||
| 201 : | var $parentid=null; | ||
| 202 : | /** @var int */ | ||
| 203 : | var $ordering=null; | ||
| 204 : | /** @var string */ | ||
| 205 : | var $metakey=null; | ||
| 206 : | /** @var string */ | ||
| 207 : | var $metadesc=null; | ||
| 208 : | /** @var int */ | ||
| 209 : | var $access=null; | ||
| 210 : | /** @var int */ | ||
| 211 : | var $hits=null; | ||
| 212 : | |||
| 213 : | /** | ||
| 214 : | * @param database A database connector object | ||
| 215 : | */ | ||
| 216 : | function mosContent() { | ||
| 217 : | $db =& mamboDatabase::getInstance(); | ||
| 218 : | $this->mosDBTable( '#__content', 'id', $db ); | ||
| 219 : | } | ||
| 220 : | |||
| 221 : | /** | ||
| 222 : | * Validation and filtering | ||
| 223 : | */ | ||
| 224 : | function check() { | ||
| 225 : | // filter malicious code | ||
| 226 : | $ignoreList = array( 'introtext', 'fulltext' ); | ||
| 227 : | $this->filter( $ignoreList ); | ||
| 228 : | |||
| 229 : | /* | ||
| 230 : | TODO: This filter is too rigorous, | ||
| 231 : | need to implement more configurable solution | ||
| 232 : | // specific filters | ||
| 233 : | $iFilter = new InputFilter( null, null, 1, 1 ); | ||
| 234 : | $this->introtext = trim( $iFilter->process( $this->introtext ) ); | ||
| 235 : | $this->fulltext = trim( $iFilter->process( $this->fulltext ) ); | ||
| 236 : | */ | ||
| 237 : | |||
| 238 : | if (trim( str_replace( ' ', '', $this->fulltext ) ) == '') { | ||
| 239 : | $this->fulltext = ''; | ||
| 240 : | } | ||
| 241 : | |||
| 242 : | return true; | ||
| 243 : | } | ||
| 244 : | |||
| 245 : | /** | ||
| 246 : | * Converts record to XML | ||
| 247 : | * @param boolean Map foreign keys to text values | ||
| 248 : | */ | ||
| 249 : | function toXML( $mapKeysToText=false ) { | ||
| 250 : | global $database; | ||
| 251 : | |||
| 252 : | if ($mapKeysToText) { | ||
| 253 : | $query = 'SELECT name FROM #__sections WHERE id=' . $this->sectionid; | ||
| 254 : | $database->setQuery( $query ); | ||
| 255 : | $this->sectionid = $database->loadResult(); | ||
| 256 : | |||
| 257 : | $query = 'SELECT name FROM #__categories WHERE id=' . $this->catid; | ||
| 258 : | $database->setQuery( $query ); | ||
| 259 : | $this->catid = $database->loadResult(); | ||
| 260 : | |||
| 261 : | $query = 'SELECT name FROM #__users WHERE id=' . $this->created_by; | ||
| 262 : | $database->setQuery( $query ); | ||
| 263 : | $this->created_by = $database->loadResult(); | ||
| 264 : | } | ||
| 265 : | |||
| 266 : | return parent::toXML( $mapKeysToText ); | ||
| 267 : | } | ||
| 268 : | } | ||
| 269 : | |||
| 270 : | class mosExtendedContent extends mosContent { | ||
| 271 : | /** @var numeric */ | ||
| 272 : | var $rating = null; | ||
| 273 : | /** @var int */ | ||
| 274 : | var $rating_count = null; | ||
| 275 : | /** @var string */ | ||
| 276 : | var $author = null; | ||
| 277 : | /** @var string */ | ||
| 278 : | var $usertype = null; | ||
| 279 : | /** @var string */ | ||
| 280 : | var $section = null; | ||
| 281 : | /** @var string */ | ||
| 282 : | var $category = null; | ||
| 283 : | /** @var string */ | ||
| 284 : | var $groups = null; | ||
| 285 : | /** @var string */ | ||
| 286 : | var $text = null; | ||
| 287 : | |||
| 288 : | function getText () { | ||
| 289 : | return $this->text; | ||
| 290 : | } | ||
| 291 : | |||
| 292 : | function saveText ($text) { | ||
| 293 : | $this->text = $text; | ||
| 294 : | } | ||
| 295 : | |||
| 296 : | function getImages () { | ||
| 297 : | return $this->images; | ||
| 298 : | } | ||
| 299 : | |||
| 300 : | function saveImages ($images) { | ||
| 301 : | $this->images = $images; | ||
| 302 : | } | ||
| 303 : | |||
| 304 : | function getId () { | ||
| 305 : | return $this->id; | ||
| 306 : | } | ||
| 307 : | |||
| 308 : | function getRating () { | ||
| 309 : | return $this->rating; | ||
| 310 : | } | ||
| 311 : | |||
| 312 : | function getRatingCount () { | ||
| 313 : | return $this->rating_count; | ||
| 314 : | } | ||
| 315 : | |||
| 316 : | } | ||
| 317 : | |||
| 318 : | class contentHandler { | ||
| 319 : | var $_category_limit = 250; | ||
| 320 : | var $_category_status = 0; | ||
| 321 : | var $_category; | ||
| 322 : | var $_section_limit = 250; | ||
| 323 : | var $_section_status = 0; | ||
| 324 : | var $_sections; | ||
| 325 : | |||
| 326 : | function &getInstance () { | ||
| 327 : | static $instance; | ||
| 328 : | if (!is_object($instance)) $instance = new contentHandler(); | ||
| 329 : | return $instance; | ||
| 330 : | } | ||
| 331 : | /** | ||
| 332 : | * @return number of Published Blog Sections | ||
| 333 : | */ | ||
| 334 : | function getBlogSectionCount( ) { | ||
| 335 : | $menuhandler =& mosMenuHandler::getInstance(); | ||
| 336 : | if (count($menuhandler->getMenusByType('content_blog_section'))) { | ||
| 337 : | $query = "SELECT COUNT( m.id )" | ||
| 338 : | ."\n FROM #__content AS i" | ||
| 339 : | ."\n LEFT JOIN #__sections AS s ON i.sectionid=s.id" | ||
| 340 : | ."\n LEFT JOIN #__menu AS m ON m.componentid=s.id " | ||
| 341 : | ."\n WHERE m.type='content_blog_section'" | ||
| 342 : | ."\n AND m.published='1'" | ||
| 343 : | ; | ||
| 344 : | $database =& mamboDatabase::getInstance(); | ||
| 345 : | $database->setQuery( $query ); | ||
| 346 : | $count = $database->loadResult(); | ||
| 347 : | } else { | ||
| 348 : | $count = 0; | ||
| 349 : | } | ||
| 350 : | return $count; | ||
| 351 : | } | ||
| 352 : | |||
| 353 : | /** | ||
| 354 : | * @return number of Published Blog Categories | ||
| 355 : | */ | ||
| 356 : | function getBlogCategoryCount( ) { | ||
| 357 : | $menuhandler =& mosMenuHandler::getInstance(); | ||
| 358 : | if (count($menuhandler->getMenusByType('content_blog_category'))) { | ||
| 359 : | $query = "SELECT COUNT( m.id )" | ||
| 360 : | . "\n FROM #__content AS i" | ||
| 361 : | . "\n LEFT JOIN #__categories AS c ON i.catid=c.id" | ||
| 362 : | . "\n LEFT JOIN #__menu AS m ON m.componentid=c.id " | ||
| 363 : | . "\n WHERE m.type='content_blog_category'" | ||
| 364 : | . "\n AND m.published='1'" | ||
| 365 : | ; | ||
| 366 : | $database =& mamboDatabase::getInstance(); | ||
| 367 : | $database->setQuery( $query ); | ||
| 368 : | $count = $database->loadResult(); | ||
| 369 : | } | ||
| 370 : | else $count = 0; | ||
| 371 : | return $count; | ||
| 372 : | } | ||
| 373 : | |||
| 374 : | /** | ||
| 375 : | * @return number of Published Global Blog Sections | ||
| 376 : | */ | ||
| 377 : | function getGlobalBlogSectionCount( ) { | ||
| 378 : | $menuhandler =& mosMenuHandler::getInstance(); | ||
| 379 : | return $menuhandler->getGlobalBlogSectionCount(); | ||
| 380 : | } | ||
| 381 : | |||
| 382 : | /** | ||
| 383 : | * @return number of Static Content | ||
| 384 : | */ | ||
| 385 : | function getStaticContentCount( ) { | ||
| 386 : | $menuhandler =& mosMenuHandler::getInstance(); | ||
| 387 : | return $menuhandler->getMenuCount ('content_typed', 1); | ||
| 388 : | } | ||
| 389 : | |||
| 390 : | /** | ||
| 391 : | * @return number of Content Item Links | ||
| 392 : | */ | ||
| 393 : | function getContentItemLinkCount( ) { | ||
| 394 : | $menuhandler =& mosMenuHandler::getInstance(); | ||
| 395 : | return $menuhandler->getMenuCount ('content_item_link', 1); | ||
| 396 : | } | ||
| 397 : | |||
| 398 : | function getItemid ($id, $typed=1, $link=1, $bs=1, $bc=1, $gbs=1) { | ||
| 399 : | $_Itemid = null; | ||
| 400 : | $menuhandler =& mosMenuHandler::getInstance(); | ||
| 401 : | if ($typed) { | ||
| 402 : | // Search for typed link | ||
| 403 : | $_Itemid = $menuhandler->getIDByTypeLink('content_typed', "index.php?option=com_content&task=view&id=$id"); | ||
| 404 : | } | ||
| 405 : | |||
| 406 : | if ($_Itemid == null AND $link) { | ||
| 407 : | // Search for item link | ||
| 408 : | $_Itemid = $menuhandler->getIDByTypeLink('content_item_link', "index.php?option=com_content&task=view&id=$id"); | ||
| 409 : | } | ||
| 410 : | |||
| 411 : | if($_Itemid == null && $bc){ | ||
| 412 : | $catid = $this->getCategory($id); | ||
| 413 : | $_Itemid = $menuhandler->getCategoryItemId($catid); | ||
| 414 : | } | ||
| 415 : | |||
| 416 : | if($_Itemid == null && ($bs || $gbs)){ | ||
| 417 : | $sectionid = $this->getSection($id); | ||
| 418 : | $_Itemid = $menuhandler->getSectionItemId($sectionid, $gbs); | ||
| 419 : | } | ||
| 420 : | |||
| 421 : | if ($_Itemid == null) { | ||
| 422 : | // Search in main menu | ||
| 423 : | $menus = $menuhandler->getByParentOrder(0,'mainmenu'); | ||
| 424 : | $home = $menus[0]; | ||
| 425 : | $_Itemid = $home->id; | ||
| 426 : | } | ||
| 427 : | if ($_Itemid) return $_Itemid; | ||
| 428 : | else return mamboCore::get('Itemid'); | ||
| 429 : | } | ||
| 430 : | |||
| 431 : | |||
| 432 : | function getSection ($id) { | ||
| 433 : | $database =& mamboDatabase::getInstance(); | ||
| 434 : | $limit = $this->_section_limit; | ||
| 435 : | if (!$this->_section_status) { | ||
| 436 : | $database->setQuery("SELECT i.id, i.sectionid FROM #__content AS i, #__sections AS s WHERE i.sectionid=s.id ORDER BY i.id DESC LIMIT $limit"); | ||
| 437 : | $sections = $database->loadObjectList(); | ||
| 438 : | if ($sections) { | ||
| 439 : | foreach ($sections as $section) $this->_sections[$section->id] = $section->sectionid; | ||
| 440 : | $this->_section_status = count($sections); | ||
| 441 : | } | ||
| 442 : | } | ||
| 443 : | if ($this->_section_status) { | ||
| 444 : | if (isset($this->_sections[$id])) return $this->_sections[$id]; | ||
| 445 : | if (count($this->_sections) < $limit) return 0; | ||
| 446 : | $database->setQuery("SELECT i.sectionid FROM #__content AS i, #__sections AS s WHERE i.sectionid=s.id AND i.id=$id"); | ||
| 447 : | return $database->loadResult(); | ||
| 448 : | } | ||
| 449 : | else return 0; | ||
| 450 : | } | ||
| 451 : | |||
| 452 : | function getCategory ($id) { | ||
| 453 : | $database =& mamboDatabase::getInstance(); | ||
| 454 : | $limit = $this->_category_limit; | ||
| 455 : | if (!$this->_category_status) { | ||
| 456 : | $database->setQuery("SELECT i.id, i.catid FROM #__content AS i, #__categories AS s WHERE i.catid=s.id ORDER BY i.id DESC LIMIT $limit"); | ||
| 457 : | $categories = $database->loadObjectList(); | ||
| 458 : | if ($categories) { | ||
| 459 : | foreach ($categories as $category) $this->_categories[$category->id] = $category->catid; | ||
| 460 : | $this->_category_status = count($categories); | ||
| 461 : | } | ||
| 462 : | } | ||
| 463 : | if ($this->_category_status) { | ||
| 464 : | if (isset($this->_categories[$id])) return $this->_categories[$id]; | ||
| 465 : | if (count($this->_categories) < $limit) return 0; | ||
| 466 : | $database->setQuery("SELECT i.catid FROM #__content AS i, #__categories AS s WHERE i.catid=s.id AND i.id=$id"); | ||
| 467 : | return $database->loadResult(); | ||
| 468 : | } | ||
| 469 : | else return 0; | ||
| 470 : | } | ||
| 471 : | |||
| 472 : | } | ||
| 473 : | |||
| 474 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

