Files
@ c7d7e38b2269
Branch filter:
Location: hot67beta/components/com_content/models/section.php
c7d7e38b2269
14.3 KiB
text/x-php
Initial import of the site.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 | <?php
/**
* @version $Id: section.php 10704 2008-08-21 09:38:40Z eddieajau $
* @package Joomla
* @subpackage Content
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant to the
* GNU General Public License, and as distributed it includes or is derivative
* of works licensed under the GNU General Public License or other free or open
* source software licenses. See COPYRIGHT.php for copyright notices and
* details.
*/
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );
jimport('joomla.application.component.model');
/**
* Content Component Section Model
*
* @package Joomla
* @subpackage Content
* @since 1.5
*/
class ContentModelSection extends JModel
{
/**
* Category id
*
* @var int
*/
var $_id = null;
/**
* Frontpage data array
*
* @var array
*/
var $_data = null;
/**
* Frontpage total
*
* @var integer
*/
var $_total = null;
/**
* Section data
*
* @var object
*/
var $_section = null;
/**
* Categories data
*
* @var array
*/
var $_categories = null;
/**
* Constructor
*
* @since 1.5
*/
function __construct( )
{
parent::__construct();
$id = JRequest::getVar('id', 0, '', 'int');
$this->setId((int)$id);
}
/**
* Method to set the section id
*
* @access public
* @param int Section ID number
*/
function setId($id)
{
// Set new ID and wipe data
$this->_id = $id;
$this->_data = array();
$this->_total = null;
$this->_section = null;
$this->_categories = null;
}
/**
* Method to get content item data for the section
*
* @param int $state The content state to pull from for the current
* section
* @since 1.5
*/
function getData($state = 1)
{
// Load the Category data
if ($this->_loadSection() && $this->_loadData($state))
{
// Initialize some variables
$user =& JFactory::getUser();
// Make sure the category is published
if (!$this->_section->published) {
JError::raiseError(404, JText::_("Resource Not Found"));
return false;
}
// check whether category access level allows access
if ($this->_section->access > $user->get('aid', 0)) {
JError::raiseError(403, JText::_("ALERTNOTAUTH"));
return false;
}
}
return $this->_data[$state];
}
/**
* Method to get the total number of content items for the section
*
* @access public
* @return integer
*/
function getTotal($state = 1)
{
// Lets load the content if it doesn't already exist
if (empty($this->_total))
{
$query = $this->_buildQuery($state);
$this->_total[$state] = $this->_getListCount($query);
}
return $this->_total[$state];
}
/**
* Method to get section data for the current section
*
* @since 1.5
*/
function getSection()
{
// Initialize some variables
$user =& JFactory::getUser();
// Load the Category data
if ($this->_loadSection())
{
// Make sure the category is published
if (!$this->_section->published) {
JError::raiseError(404, JText::_("Resource Not Found"));
return false;
}
// check whether category access level allows access
if ($this->_section->access > $user->get('aid', 0)) {
JError::raiseError(403, JText::_("ALERTNOTAUTH"));
return false;
}
}
return $this->_section;
}
/**
* Method to get sibling category data for the current category
*
* @since 1.5
*/
function getCategories()
{
// Initialize some variables
$user =& JFactory::getUser();
// Load the Category data
if ($this->_loadSection() && $this->_loadCategories())
{
// Make sure the category is published
if (!$this->_section->published) {
JError::raiseError(404, JText::_("Resource Not Found"));
return false;
}
// check whether category access level allows access
if ($this->_section->access > $user->get('aid', 0)) {
JError::raiseError(403, JText::_("ALERTNOTAUTH"));
return false;
}
}
return $this->_categories;
}
/**
* Method to get archived article data for the current section
*
* @param int $state The content state to pull from for the current section
* @since 1.5
*/
function getArchives($state = -1)
{
return $this->getData(-1);
}
/**
* Method to get archived article data for the current section
*
* @param int $state The content state to pull from for the current section
* @since 1.5
*/
function getTree()
{
return $this->_loadTree();
}
/**
* Method to load section data if it doesn't exist.
*
* @access private
* @return boolean True on success
*/
function _loadSection()
{
if (empty($this->_section))
{
// Lets get the information for the current section
if ($this->_id) {
$where = ' WHERE id = '. (int) $this->_id;
} else {
$where = null;
}
$query = 'SELECT *' .
' FROM #__sections' .
$where;
$this->_db->setQuery($query, 0, 1);
$this->_section = $this->_db->loadObject();
}
return true;
}
/**
* Method to load sibling category data if it doesn't exist.
*
* @access private
* @return boolean True on success
*/
function _loadCategories()
{
global $mainframe;
// Lets load the siblings if they don't already exist
if (empty($this->_categories))
{
$user =& JFactory::getUser();
// Get the page/component configuration
$params = &$mainframe->getParams();
$noauth = !$params->get('show_noauth');
$gid = $user->get('aid', 0);
$now = $mainframe->get('requestTime');
$nullDate = $this->_db->getNullDate();
// Ordering control
$orderby = $params->get('orderby', '');
$orderby = ContentHelperQuery::orderbySecondary($orderby);
// Handle the access permissions part of the main database query
if ($user->authorize('com_content', 'edit', 'content', 'all')) {
$xwhere = '';
$xwhere2 = ' AND b.state >= 0';
} else {
$xwhere = ' AND a.published = 1';
$xwhere2 = ' AND b.state = 1' .
' AND ( b.publish_up = '.$this->_db->Quote($nullDate).' OR b.publish_up <= '.$this->_db->Quote($now).' )' .
' AND ( b.publish_down = '.$this->_db->Quote($nullDate).' OR b.publish_down >= '.$this->_db->Quote($now).' )';
if ($noauth) {
$xwhere2 .= ' AND b.access <= '.(int) $gid;
}
}
// Determine whether to show/hide the empty categories and sections
$empty = null;
$empty_sec = null;
// show/hide empty categories in section
if (!$params->get('show_empty_categories')) {
$empty_sec = ' HAVING numitems > 0';
}
// Handle the access permissions
$access_check = null;
if ($noauth) {
$access_check = ' AND a.access <= '.(int) $gid;
//$access_check .= ' AND b.access <= '.(int) $gid;
}
// Query of categories within section
$query = 'SELECT a.*, COUNT( b.id ) AS numitems,' .
' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug'.
' FROM #__categories AS a' .
' LEFT JOIN #__content AS b ON b.catid = a.id'.
$xwhere2 .
' WHERE a.section = '.(int) $this->_id.
$xwhere.
$access_check .
' GROUP BY a.id'.$empty.$empty_sec .
' ORDER BY '. $orderby;
$this->_db->setQuery($query);
$this->_categories = $this->_db->loadObjectList();
}
return true;
}
/**
* Method to load content item data for items in the category if they don't
* exist.
*
* @access private
* @return boolean True on success
*/
function _loadData($state = 1)
{
if (empty($this->_section)) {
return false; // TODO: set error -- can't get siblings when we don't know the category
}
// Lets load the content if it doesn't already exist
if (empty($this->_data[$state]))
{
// Get the pagination request variables
$limit = JRequest::getVar('limit', 0, '', 'int');
$limitstart = JRequest::getVar('limitstart', 0, '', 'int');
$query = $this->_buildQuery();
$Arows = $this->_getList($query, $limitstart, $limit);
// special handling required as Uncategorized content does not have a section / category id linkage
$i = $limitstart;
$rows = array();
foreach ($Arows as $row)
{
// check to determine if section or category has proper access rights
$rows[$i] = $row;
$i ++;
}
$this->_data[$state] = $rows;
}
return true;
}
/**
* Method to load content item data for items in the category if they don't
* exist.
*
* @access private
* @return boolean True on success
*/
function _loadTree()
{
global $mainframe;
// Lets load the content if it doesn't already exist
if (empty($this->_tree))
{
$user =& JFactory::getUser();
$aid = $user->get('aid', 0);
$now = $mainframe->get('requestTime');
$nullDate = $this->_db->getNullDate();
// Get the information for the current section
if ($this->_id) {
$and = ' AND a.section = '.(int) $this->_id;
} else {
$and = null;
}
// Query of categories within section
$query = 'SELECT a.name AS catname, a.title AS cattitle, b.* ' .
' FROM #__categories AS a' .
' INNER JOIN #__content AS b ON b.catid = a.id' .
' AND b.state = 1' .
' AND ( b.publish_up = '.$this->_db->Quote($nullDate).' OR b.publish_up <= '.$this->_db->Quote($now).' )' .
' AND ( b.publish_down = '.$this->_db->Quote($nullDate).' OR b.publish_down >= '.$this->_db->Quote($now).' )';
' WHERE a.published = 1' .
$and .
' AND a.access <= '.(int) $aid .
' ORDER BY a.catid, a.ordering, b.ordering';
$this->_db->setQuery($query);
$this->_tree = $this->_db->loadObjectList();
}
return true;
}
function _buildQuery($state = 1)
{
global $mainframe;
// Get the page/component configuration
$params = &$mainframe->getParams();
// If voting is turned on, get voting data as well for the content items
$voting = ContentHelperQuery::buildVotingQuery($params);
// Get the WHERE and ORDER BY clauses for the query
$where = $this->_buildContentWhere($state);
$orderby = $this->_buildContentOrderBy($state);
$query = 'SELECT a.id, a.title, a.title_alias, a.introtext, a.fulltext, a.sectionid, a.state, a.catid, a.created, a.created_by, a.created_by_alias, a.modified, a.modified_by,' .
' a.checked_out, a.checked_out_time, a.publish_up, a.publish_down, a.attribs, a.hits, a.images, a.urls, a.ordering, a.metakey, a.metadesc, a.access,' .
' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug,'.
' CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(":", cc.id, cc.alias) ELSE cc.id END as catslug,'.
' CHAR_LENGTH( a.`fulltext` ) AS readmore, u.name AS author, u.usertype, cc.title AS category, g.name AS groups'.$voting['select'] .
' FROM #__content AS a' .
' INNER JOIN #__categories AS cc ON cc.id = a.catid' .
' LEFT JOIN #__sections AS s ON s.id = a.sectionid' .
' LEFT JOIN #__users AS u ON u.id = a.created_by' .
' LEFT JOIN #__groups AS g ON a.access = g.id'.
$voting['join'].
$where.
$orderby;
return $query;
}
function _buildContentOrderBy($state = 1)
{
$filter_order = JRequest::getCmd('filter_order');
$filter_order_Dir = JRequest::getWord('filter_order_Dir');
$orderby = ' ORDER BY ';
if ($filter_order && $filter_order_Dir) {
$orderby .= $filter_order .' '. $filter_order_Dir.', ';
}
// Get the page/component configuration
$app =& JFactory::getApplication();
$params =& $app->getParams();
switch ($state)
{
case -1:
// Special ordering for archive articles
$orderby_sec = $params->def('orderby', 'rdate');
$secondary = ContentHelperQuery::orderbySecondary($orderby_sec);
$primary = '';
break;
case 1:
default:
$orderby_sec = $params->def('orderby_sec', 'rdate');
$orderby_sec = ($orderby_sec == 'front') ? '' : $orderby_sec;
$orderby_pri = $params->def('orderby_pri', '');
$secondary = ContentHelperQuery::orderbySecondary($orderby_sec);
$primary = ContentHelperQuery::orderbyPrimary($orderby_pri);
break;
}
$orderby .= "$primary $secondary";
return $orderby;
}
function _buildContentWhere($state = 1)
{
global $mainframe;
$user =& JFactory::getUser();
$aid = $user->get('aid', 0);
$jnow =& JFactory::getDate();
$now = $jnow->toMySQL();
// Get the page/component configuration
$params = &$mainframe->getParams();
$noauth = !$params->get('show_noauth');
$nullDate = $this->_db->getNullDate();
// First thing we need to do is assert that the articles are in the current category
if ($noauth) {
$where = ' WHERE a.access <= '.(int) $aid;
} else {
$where = ' WHERE 1';
}
if ($this->_id) {
$where .= ' AND s.id = '.(int)$this->_id;
}
$where .= ' AND s.access <= '.(int) $aid;
$where .= ' AND cc.access <= '.(int) $aid;
$where .= ' AND s.published = 1';
$where .= ' AND cc.published = 1';
// Regular Published Content
switch ($state)
{
case 1:
if ($user->authorize('com_content', 'edit', 'content', 'all')) {
$where .= ' AND a.state >= 0';
} else {
$where .= ' AND a.state = 1' .
' AND ( publish_up = '.$this->_db->Quote($nullDate).' OR publish_up <= '.$this->_db->Quote($now).' )' .
' AND ( publish_down = '.$this->_db->Quote($nullDate).' OR publish_down >= '.$this->_db->Quote($now).' )';
}
break;
// Archive Content
case -1:
// Get some request vars specific to this state
$year = JRequest::getInt( 'year', date('Y') );
$month = JRequest::getInt( 'month', date('m') );
$where .= ' AND a.state = -1';
$where .= ' AND YEAR( a.created ) = '.(int) $year;
$where .= ' AND MONTH( a.created ) = '.(int) $month;
break;
default:
$where .= ' AND a.state = '.(int) $state;
break;
}
/*
* If we have a filter, and this is enabled... lets tack the AND clause
* for the filter onto the WHERE clause of the content item query.
*/
if ($params->get('filter'))
{
$filter = JRequest::getString('filter', '', 'request');
if ($filter) {
// clean filter variable
$filter = JString::strtolower($filter);
$filter = $this->_db->Quote( '%'.$this->_db->getEscaped( $filter, true ).'%', false );
switch ($params->get('filter_type'))
{
case 'title' :
$where .= ' AND LOWER( a.title ) LIKE '.$filter;
break;
case 'author' :
$where .= ' AND ( ( LOWER( u.name ) LIKE '.$filter.' ) OR ( LOWER( a.created_by_alias ) LIKE '.$filter.' ) )';
break;
case 'hits' :
$where .= ' AND a.hits LIKE '.$filter;
break;
}
}
}
return $where;
}
}
?>
|