| [ Index ] | PHP Cross Reference of Mambo 4.6.5 |
|
| [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Mambo 4 * @subpackage Content 5 * @author Mambo Foundation Inc see README.php 6 * @copyright (C) 2000 - 2009 Mambo Foundation Inc. 7 * See COPYRIGHT.php for copyright notices and details. 8 * @license GNU/GPL Version 2, see LICENSE.php 9 * 10 * Redistributions of files must retain the above copyright notice. 11 * 12 * Mambo is free software; you can redistribute it and/or 13 * modify it under the terms of the GNU General Public License 14 * as published by the Free Software Foundation; version 2 of the License. 15 */ 16 17 /** ensure this file is being included by a parent file */ 18 defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); 19 20 require_once( $mainframe->getPath( 'front_html', 'com_content' ) ); 21 require_once($mainframe->getPath('class')); 22 23 $id = intval( mosGetParam( $_REQUEST, 'id', 0 ) ); 24 $sectionid = intval( mosGetParam( $_REQUEST, 'sectionid', 0 ) ); 25 $pop = intval( mosGetParam( $_REQUEST, 'pop', 0 ) ); 26 $task = trim( mosGetParam( $_REQUEST, 'task', '' ) ); 27 $limit = intval( mosGetParam( $_REQUEST, 'limit', '' ) ); 28 $limitstart = intval( mosGetParam( $_REQUEST, 'limitstart', 0 ) ); 29 30 $now = date( 'Y-m-d H:i:s', time() + $mosConfig_offset * 60 * 60 ); 31 32 // Editor usertype check 33 $access = new stdClass(); 34 $access->canEdit = $acl->acl_check( 'action', 'edit', 'users', $my->usertype, 'content', 'all' ); 35 $access->canEditOwn = $acl->acl_check( 'action', 'edit', 'users', $my->usertype, 'content', 'own' ); 36 $access->canPublish = $acl->acl_check( 'action', 'publish', 'users', $my->usertype, 'content', 'all' ); 37 38 // cache activation 39 $cache =& mosCache::getCache( 'com_content' ); 40 41 // loads function for frontpage component 42 if ( $option == 'com_frontpage' ) { 43 //frontpage( $option, $gid, $pop, $now ); 44 $cache->call( 'frontpage', $gid, $access, $pop, $limit, $limitstart); 45 return; 46 } 47 48 switch ( strtolower( $task ) ) { 49 case 'findkey': 50 findKeyItem( $gid, $access, $pop, $option, $now ); 51 break; 52 53 case 'view': 54 showItem( $id, $gid, $access, $pop, $option, $now ); 55 break; 56 57 case 'section': 58 $cache->call( 'showSection', $id, $gid, $access ); 59 break; 60 61 case 'category': 62 $cache->call( 'showCategory', $id, $gid, $access, $sectionid, $limit, $limitstart ); 63 break; 64 65 case 'blogsection': 66 $cache->call('showBlogSection', $id, $gid, $access, $pop, $limit, $limitstart ); 67 break; 68 69 case 'blogcategorymulti': 70 case 'blogcategory': 71 $cache->call( 'showBlogCategory', $id, $gid, $access, $pop, $limit, $limitstart ); 72 break; 73 74 case 'archivesection': 75 showArchiveSection( $id, $gid, $access, $pop, $option ); 76 break; 77 78 case 'archivecategory': 79 showArchiveCategory( $id, $gid, $access, $pop, $option, $now ); 80 break; 81 82 case 'edit': 83 editItem( $id, $gid, $access, 0, $task, $Itemid ); 84 break; 85 86 case 'new': 87 editItem( 0, $gid, $access, $sectionid, $task, $Itemid ); 88 break; 89 90 case 'save': 91 mosCache::cleanCache( 'com_content' ); 92 saveContent( $access ); 93 break; 94 95 case 'cancel': 96 cancelContent( $access ); 97 break; 98 99 case 'emailform': 100 emailContentForm( $id ); 101 break; 102 103 case 'emailsend': 104 emailContentSend( $id ); 105 break; 106 107 case 'vote': 108 recordVote ( $user_rating , $cid , $database); 109 break; 110 111 default: 112 $cache->call('showBlogSection', 0, $gid, $access, $pop, $limit, $limitstart ); 113 break; 114 } 115 116 /** 117 * Searches for an item by a key parameter 118 * @param int The user access level 119 * @param object Actions this user can perform 120 * @param int 121 * @param string The url option 122 * @param string A timestamp 123 */ 124 function findKeyItem( $gid, $access, $pop, $option, $now ) { 125 global $database; 126 $keyref = mosGetParam( $_REQUEST, 'keyref', '' ); 127 $keyref = $database->getEscaped( $keyref ); 128 129 $query = 'SELECT id 130 FROM #__content 131 WHERE attribs LIKE \'%keyref=' . $keyref . '%\' 132 '; 133 $database->setQuery( $query ); 134 $id = $database->loadResult(); 135 if ($id > 0) { 136 showItem( $id, $gid, $access, $pop, $option, $now ); 137 } else { 138 echo 'Key not found '. $keyref; 139 } 140 } 141 142 function frontpage( $gid, &$access, $pop, $limit, $limitstart) { 143 global $database, $mainframe, $my, $Itemid; 144 global $mosConfig_offset; 145 146 $noauth = !$mainframe->getCfg( 'shownoauth' ); 147 148 // Parameters 149 $menu =& new mosMenu( $database ); 150 $menu->load( $Itemid ); 151 $params =& new mosParameters( $menu->params ); 152 $orderby_sec = $params->def( 'orderby_sec', '' ); 153 $orderby_pri = $params->def( 'orderby_pri', '' ); 154 $header = $params->def( 'header', $menu->name ); 155 $page_title = $params->def( 'page_title', 0 ); 156 // Ordering control 157 $order_sec = _orderby_sec( $orderby_sec ); 158 $order_pri = _orderby_pri( $orderby_pri ); 159 160 $now = date( "Y-m-d H:i:s", time()+$mosConfig_offset*60*60 ); 161 162 global $acl; 163 $viewAccess = ($gid >= $acl->get_group_id( 'Registered', 'ARO' ) ? 1 : 0) + ($gid >= $acl->get_group_id( 'Author', 'ARO' ) ? 1 : 0); 164 // query records 165 $query = "SELECT a.*, ROUND( v.rating_sum / v.rating_count ) AS rating, v.rating_count, u.name AS author, u.usertype, s.name AS section, cc.name AS category, g.name AS groups" 166 . "\n FROM #__content AS a" 167 . "\n INNER JOIN #__content_frontpage AS f ON f.content_id = a.id" 168 . "\n LEFT JOIN #__categories AS cc ON cc.id = a.catid" 169 . "\n LEFT JOIN #__sections AS s ON s.id = a.sectionid" 170 . "\n LEFT JOIN #__users AS u ON u.id = a.created_by" 171 . "\n LEFT JOIN #__content_rating AS v ON a.id = v.content_id" 172 . "\n LEFT JOIN #__groups AS g ON a.access = g.id" 173 . "\n WHERE a.state = '1'" 174 . ( $noauth ? "\n AND a.access <= '". $my->gid ."'" : '' ) 175 . "\n AND ( publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now' )" 176 . "\n AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now' )" 177 . "\n AND a.access <= ". $viewAccess 178 . "\n ORDER BY ". $order_pri . $order_sec 179 ; 180 $rows = $database->doSQLget($query, 'mosExtendedContent'); 181 182 // Dynamic Page Title 183 $mainframe->SetPageTitle( $header ); 184 185 BlogOutput( $rows, $params, $gid, $access, $pop, $menu, null, $limit, $limitstart ); 186 } 187 188 189 function showSection( $id, $gid, &$access ) { 190 global $database, $mainframe, $mosConfig_offset, $Itemid; 191 192 $noauth = !$mainframe->getCfg( 'shownoauth' ); 193 $now = date( 'Y-m-d H:i:s', time() + $mosConfig_offset * 60 * 60 ); 194 // Paramters 195 $params = new stdClass(); 196 if ( $Itemid ) { 197 $menu = new mosMenu( $database ); 198 $menu->load( $Itemid ); 199 $params =& new mosParameters( $menu->params ); 200 } else { 201 $menu = ""; 202 $params =& new mosParameters( $menu->params ); 203 204 } 205 $orderby = $params->get( 'orderby', '' ); 206 207 $params->set( 'type', 'section' ); 208 209 $params->def( 'page_title', 1 ); 210 $params->def( 'pageclass_sfx', '' ); 211 $params->def( 'other_cat_section', 1 ); 212 $params->def( 'other_cat', 1 ); 213 $params->def( 'empty_cat', 0 ); 214 $params->def( 'cat_items', 1 ); 215 $params->def( 'cat_description', 1 ); 216 $params->def( 'description', 1 ); 217 $params->def( 'description-image', 1 ); 218 $params->def( 'back_button', $mainframe->getCfg( 'back_button' ) ); 219 $params->def( 'pageclass_sfx', '' ); 220 221 // Ordering control 222 $orderby = _orderby_sec( $orderby ); 223 224 $section = new mosSection( $database ); 225 $section->load( $id ); 226 227 if ( $access->canEdit ) { 228 $xwhere = ''; 229 $xwhere2 = "\n AND b.state >= '0'"; 230 } else { 231 $xwhere = "\n AND a.published = '1'"; 232 $xwhere2 = "\n AND b.state = '1'" 233 . "\n AND ( publish_up = '0000-00-00 00:00:00' OR publish_up <= '". $now ."' )" 234 . "\n AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '". $now ."' )" 235 ; 236 } 237 238 // show/hide empty categories 239 if ( $params->get( 'empty_cat' ) ) { 240 $empty = ''; 241 } else { 242 $empty = "\n HAVING COUNT( b.id ) > 0"; 243 } 244 245 // Main Query 246 $query = ' 247 SELECT a.*, COUNT( b.id ) AS numitems 248 FROM #__categories AS a 249 LEFT JOIN #__content AS b ON b.catid = a.id '. $xwhere2 .' 250 WHERE a.section = \'' . $section->id .'\' '. $xwhere; 251 if ($noauth) { 252 $query .= ' 253 AND a.access <= '. $gid; 254 } 255 $query .= ' 256 GROUP BY a.id 257 ' . $empty . ' 258 ORDER BY ' . $orderby; 259 260 $database->setQuery( $query ); 261 $other_categories = $database->loadObjectList(); 262 263 // Dynamic Page Title 264 $mainframe->SetPageTitle( $menu->name ); 265 266 HTML_content::showContentList( $section, NULL, $access, $id, NULL, $gid, $params, NULL, $other_categories, NULL ); 267 } 268 269 270 /** 271 * @param int The category id 272 * @param int The group id of the user 273 * @param int The access level of the user 274 * @param int The section id 275 * @param int The number of items to dislpay 276 * @param int The offset for pagination 277 */ 278 function showCategory( $id, $gid, &$access, $sectionid, $limit, $limitstart ) { 279 global $database, $mainframe, $Itemid, $mosConfig_offset, $mosConfig_list_limit; 280 281 $noauth = !$mainframe->getCfg( 'shownoauth' ); 282 $selected = mosGetParam( $_POST, 'order', '' ); 283 $now = date( 'Y-m-d H:i:s', time() + $mosConfig_offset * 60 * 60 ); 284 // Paramters 285 $params = new stdClass(); 286 if ( $Itemid ) { 287 $menu = new mosMenu( $database ); 288 $menu->load( $Itemid ); 289 $params =& new mosParameters( $menu->params ); 290 } else { 291 $menu = ""; 292 $params =& new mosParameters( '' ); 293 } 294 295 if ( $selected ) { 296 $orderby = $selected; 297 } else { 298 $orderby = $params->get( 'orderby', 'rdate' ); 299 $selected = $orderby; 300 } 301 302 $params->set( 'type', 'category' ); 303 304 $params->def( 'page_title', 1 ); 305 $params->def( 'title', 1 ); 306 $params->def( 'hits', $mainframe->getCfg( 'hits' ) ); 307 $params->def( 'author', !$mainframe->getCfg( 'hideAuthor' ) ); 308 $params->def( 'date', !$mainframe->getCfg( 'hideCreateDate' ) ); 309 $params->def( 'date_format', _DATE_FORMAT_LC ); 310 $params->def( 'navigation', 2 ); 311 $params->def( 'display', 1 ); 312 $params->def( 'display_num', $mosConfig_list_limit ); 313 $params->def( 'other_cat', 1 ); 314 $params->def( 'empty_cat', 0 ); 315 $params->def( 'cat_items', 1 ); 316 $params->def( 'cat_description', 0 ); 317 $params->def( 'description', 1 ); 318 $params->def( 'description-image', 1 ); 319 $params->def( 'back_button', $mainframe->getCfg( 'back_button' ) ); 320 $params->def( 'pageclass_sfx', '' ); 321 $params->def( 'headings', 1 ); 322 $params->def( 'order_select', 1 ); 323 $params->def( 'filter', 1 ); 324 $params->def( 'filter_type', 'title' ); 325 326 // Ordering control 327 $orderby = _orderby_sec( $orderby ); 328 329 $category = new mosCategory( $database ); 330 $category->load( $id ); 331 332 if ( $sectionid == 0 ) { 333 $sectionid = $category->section; 334 } 335 336 $pathway =& mosPathway::getInstance(); 337 $pathway->addItem($category->title, categoryURL($sectionid, $id)); 338 339 if ( $access->canEdit ) { 340 $xwhere = ''; 341 $xwhere2 = "\n AND b.state >= '0'"; 342 } else { 343 $xwhere = "\n AND c.published='1'"; 344 $xwhere2 = "\n AND b.state='1'" 345 . "\n AND ( publish_up = '0000-00-00 00:00:00' OR publish_up <= '". $now ."' )" 346 . "\n AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '". $now ."' )" 347 ; 348 } 349 350 $pagetitle = ''; 351 if ( $Itemid ) { 352 $menu = new mosMenu( $database ); 353 $menu->load( $Itemid ); 354 $pagetitle = $menu->name; 355 } // if 356 357 // show/hide empty categories 358 $empty = ''; 359 if ( !$params->get( 'empty_cat' ) ) 360 $empty = "\n HAVING COUNT( b.id ) > 0"; 361 362 // get the list of other categories 363 $query = "SELECT c.*, COUNT( b.id ) AS numitems" 364 . "\n FROM #__categories AS c" 365 . "\n LEFT JOIN #__content AS b ON b.catid = c.id " 366 . $xwhere2 367 . ( $noauth ? "\n AND b.access <= '". $gid ."'" : '' ) 368 . "\n WHERE c.section = '". $category->section. "'" 369 . $xwhere 370 . ( $noauth ? "\n AND c.access <= '". $gid ."'" : '' ) 371 . "\n GROUP BY c.id" 372 . $empty 373 . "\n ORDER BY c.ordering" 374 ; 375 $database->setQuery( $query ); 376 $other_categories = $database->loadObjectList(); 377 378 // get the total number of published items in the category 379 // filter functionality 380 $_and = ''; 381 if ($filter = mosGetParam($_POST, 'filter', '')) { 382 $filter = strtolower( $filter ); 383 $filter = $database->getEscaped($filter); 384 if ( $params->get( 'filter' ) ) { 385 switch ( $params->get( 'filter_type' ) ) { 386 case 'title': 387 $_and = "\n AND LOWER( a.title ) LIKE '%". $filter ."%'"; 388 break; 389 case 'author': 390 $_and = "\n AND ( ( LOWER( u.name ) LIKE '%". $filter ."%' ) OR ( LOWER( a.created_by_alias ) LIKE '%". $filter ."%' ) )"; 391 break; 392 case 'hits': 393 $_and = "\n AND a.hits LIKE '%". $filter ."%'"; 394 break; 395 } 396 } 397 398 } 399 400 if ( $access->canEdit ) { 401 $xwhere = "\n AND a.state >= '0'"; 402 } else { 403 $xwhere = "\n AND a.state='1'" 404 . "\n AND ( publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now' )" 405 . "\n AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now' )" 406 ; 407 } 408 409 $query = "SELECT COUNT(a.id) as numitems" 410 . "\n FROM #__content AS a" 411 . "\n LEFT JOIN #__users AS u ON u.id = a.created_by" 412 . "\n LEFT JOIN #__groups AS g ON a.access = g.id" 413 . "\n WHERE a.catid='". $category->id ."' ". $xwhere 414 . ( $noauth ? "\n AND a.access<='". $gid ."'" : '' ) 415 . "\n AND '". $category->access ."'<='". $gid ."'" 416 . $_and 417 . "\n ORDER BY ". $orderby ."" 418 ; 419 $database->setQuery( $query ); 420 $counter = $database->loadObjectList(); 421 $total = $counter[0]->numitems; 422 $limit = $limit ? $limit : $params->get( 'display_num' ) ; 423 if ( $total <= $limit ) $limitstart = 0; 424 425 require_once( $GLOBALS['mosConfig_absolute_path'] . '/includes/pageNavigation.php' ); 426 $pageNav = new mosPageNav( $total, $limitstart, $limit ); 427 428 // get the list of items for this category 429 $query = "SELECT a.id, a.title, a.hits, a.created_by, a.created_by_alias, a.created AS created, a.access, u.name AS author, a.state, g.name AS groups" 430 . "\n FROM #__content AS a" 431 . "\n LEFT JOIN #__users AS u ON u.id = a.created_by" 432 . "\n LEFT JOIN #__groups AS g ON a.access = g.id" 433 . "\n WHERE a.catid='". $category->id ."' ". $xwhere 434 . ( $noauth ? "\n AND a.access<='". $gid ."'" : '' ) 435 . "\n AND '". $category->access ."'<='". $gid ."'" 436 . $_and 437 . "\n ORDER BY ". $orderby ."" 438 . "\n LIMIT ". $limitstart .", ". $limit 439 ; 440 $database->setQuery( $query ); 441 $items = $database->loadObjectList(); 442 443 $check = 0; 444 if ( $params->get( 'date' ) ) { 445 $order[] = mosHTML::makeOption( 'date', T_('Date Asc') ); 446 $order[] = mosHTML::makeOption( 'rdate', T_('Date Desc')); 447 $check .= 1; 448 } 449 if ( $params->get( 'title' ) ) { 450 $order[] = mosHTML::makeOption( 'alpha', T_('Title Asc') ); 451 $order[] = mosHTML::makeOption( 'ralpha', T_('Title Desc') ); 452 $check .= 1; 453 } 454 if ( $params->get( 'hits' ) ) { 455 $order[] = mosHTML::makeOption( 'hits', T_('Hits Asc') ); 456 $order[] = mosHTML::makeOption( 'rhits', T_('Hits Desc') ); 457 $check .= 1; 458 } 459 if ( $params->get( 'author' ) ) { 460 $order[] = mosHTML::makeOption( 'author', T_('Author Asc') ); 461 $order[] = mosHTML::makeOption( 'rauthor', T_('Author Desc') ); 462 $check .= 1; 463 } 464 $order[] = mosHTML::makeOption( 'order', T_('Ordering') ); 465 $lists['order'] = mosHTML::selectList( $order, 'order', 'class="inputbox" size="1" onchange="document.adminForm.submit();"', 'value', 'text', $selected ); 466 if ( $check < 1 ) { 467 $lists['order'] = ''; 468 $params->set( 'order_select', 0 ); 469 } 470 471 $lists['task'] = 'category'; 472 $lists['filter'] = $filter; 473 474 // Dynamic Page Title 475 $mainframe->SetPageTitle( $pagetitle ); 476 477 HTML_content::showContentList( $category, $items, $access, $id, $sectionid, $gid, $params, $pageNav, $other_categories, $lists ); 478 } // showCategory 479 480 481 function showBlogSection( $id=0, $gid, &$access, $pop, $limit, $limitstart ) { 482 global $database, $mainframe, $mosConfig_offset, $Itemid, $option, $task; 483 484 $noauth = !$mainframe->getCfg( 'shownoauth' ); 485 $now = date( 'Y-m-d H:i:s', time() + $mosConfig_offset * 60 * 60 ); 486 // Parameters 487 $pageTitle = ''; 488 if ( $Itemid ) { 489 $menu = new mosMenu( $database ); 490 $menu->load( $Itemid ); 491 if ( strpos(strtolower($menu->link), 'blogsection') === false ) { 492 $menu = ''; 493 } else { 494 // only load params and set title if the menu item loaded is a blog section 495 $pageTitle = $menu->name; 496 $params =& new mosParameters( $menu->params ); 497 } 498 } 499 500 // no Itemid OR menu item loaded is not a blog section 501 // try to find a blog entry in the menu database 502 if (!$menu) { 503 $database->setQuery("SELECT * FROM #__menu WHERE link LIKE '%blogsection%'"); 504 $rows = $database->loadObjectList(); 505 if (count($rows)) { 506 $params =& new mosParameters( $rows[0]->params ); 507 } 508 } 509 510 // no menu item found and no params loaded so create a default params object 511 if (!$params) $params =& new mosParameters( $menu->params ); 512 513 // new blog multiple section handling 514 if ( !$id ) { 515 $id = $params->def( 'sectionid', 0 ); 516 } 517 518 $where = _where( 1, $access, $noauth, $gid, $id, $now ); 519 520 // Ordering control 521 $orderby_sec = $params->def( 'orderby_sec', 'rdate' ); 522 $orderby_pri = $params->def( 'orderby_pri', '' ); 523 $order_sec = _orderby_sec( $orderby_sec ); 524 $order_pri = _orderby_pri( $orderby_pri ); 525 526 // Main data query 527 $query = "SELECT a.*, ROUND( v.rating_sum / v.rating_count ) AS rating, v.rating_count, u.name AS author, u.usertype, cc.name AS category, g.name AS groups, s.title AS section" 528 . "\n FROM #__content AS a" 529 . "\n INNER JOIN #__categories AS cc ON cc.id = a.catid" 530 . "\n LEFT JOIN #__users AS u ON u.id = a.created_by" 531 . "\n LEFT JOIN #__content_rating AS v ON a.id = v.content_id" 532 . "\n LEFT JOIN #__sections AS s ON a.sectionid = s.id" 533 . "\n LEFT JOIN #__groups AS g ON a.access = g.id" 534 . ( count( $where ) ? "\n WHERE ".implode( "\n AND ", $where ) : '' ) 535 . "\n AND s.access<=$gid" 536 . "\n ORDER BY ". $order_pri . $order_sec 537 ; 538 // $database->setQuery( $query ); 539 // $rows = $database->loadObjectList(); 540 $rows = $database->doSQLget($query, 'mosExtendedContent'); 541 542 // Dynamic Page Title 543 // do we have multiple sections? 544 $multiple_sections = false; 545 if (count($rows)) { 546 $temp = array(); 547 foreach($rows as $row) { 548 $temp[$row->section] = ''; 549 } 550 if (count($temp) > 1) { 551 $multiple_sections = true; 552 } 553 unset($temp); 554 } 555 if (!$pageTitle) { 556 // set the page title 557 if ($rows[0]->section && !$multiple_sections){ 558 $pageTitle = $rows[0]->section; 559 } else { 560 $pageTitle = T_('Blog'); 561 } 562 // fudge the pathway 563 $mainframe->appendPathway($pageTitle); 564 } 565 $mainframe->setPageTitle( $pageTitle ); 566 567 // restore borrowed $row->section to null - IMPORTANT 568 if (count($rows)) { 569 for($i=0; $i<count($rows); $i++) $rows[$i]->section = ''; 570 } 571 572 BlogOutput( $rows, $params, $gid, $access, $pop, $menu, null, $limit, $limitstart ); 573 } 574 575 function showBlogCategory( $id=0, $gid, &$access, $pop, $limit, $limitstart ) { 576 global $database, $mainframe, $mosConfig_offset, $Itemid; 577 578 $noauth = !$mainframe->getCfg( 'shownoauth' ); 579 $now = date( 'Y-m-d H:i:s', time() + $mosConfig_offset * 60 * 60 ); 580 // Paramters 581 $params = new stdClass(); 582 if ( $Itemid ) { 583 $menu = new mosMenu( $database ); 584 $menu->load( $Itemid ); 585 $params =& new mosParameters( $menu->params ); 586 } else { 587 $menu = ""; 588 $params =& new mosParameters( '' ); 589 } 590 591 // new blog multiple section handling 592 if ( !$id ) { 593 $id = $params->def( 'categoryid', 0 ); 594 } 595 596 $where = _where( 2, $access, $noauth, $gid, $id, $now ); 597 598 // Ordering control 599 $orderby_sec = $params->def( 'orderby_sec', 'rdate' ); 600 $orderby_pri = $params->def( 'orderby_pri', '' ); 601 $order_sec = _orderby_sec( $orderby_sec ); 602 $order_pri = _orderby_pri( $orderby_pri ); 603 604 // Main data query 605 $query = "SELECT a.*, ROUND( v.rating_sum / v.rating_count ) AS rating, v.rating_count, u.name AS author, u.usertype, s.name AS section, g.name AS groups, cc.name AS category" 606 . "\n FROM #__content AS a" 607 . "\n LEFT JOIN #__categories AS cc ON cc.id = a.catid" 608 . "\n LEFT JOIN #__users AS u ON u.id = a.created_by" 609 . "\n LEFT JOIN #__content_rating AS v ON a.id = v.content_id" 610 . "\n LEFT JOIN #__sections AS s ON a.sectionid = s.id" 611 . "\n LEFT JOIN #__groups AS g ON a.access = g.id" 612 . ( count( $where ) ? "\n WHERE ".implode( "\n AND ", $where ) : '' ) 613 . "\n AND s.access <= ". $gid 614 . "\n ORDER BY ". $order_pri . $order_sec; 615 ; 616 // $database->setQuery( $query ); 617 // $rows = $database->loadObjectList(); 618 $rows = $database->doSQLget($query, 'mosExtendedContent'); 619 620 // Dynamic Page Title 621 $mainframe->SetPageTitle( $menu->name ); 622 623 BlogOutput( $rows, $params, $gid, $access, $pop, $menu, null, $limit, $limitstart ); 624 } 625 626 function showArchiveSection( $id=NULL, $gid, &$access, $pop, $option ) { 627 global $database, $mainframe, $mosConfig_offset; 628 global $Itemid; 629 630 $noauth = !$mainframe->getCfg( 'shownoauth' ); 631 632 // Parameters 633 $year = mosGetParam( $_REQUEST, 'year', date( 'Y' ) ); 634 $month = mosGetParam( $_REQUEST, 'month', date( 'm' ) ); 635 636 $params = new stdClass(); 637 if ( $Itemid ) { 638 $menu = new mosMenu( $database ); 639 $menu->load( $Itemid ); 640 $params =& new mosParameters( $menu->params ); 641 } else { 642 $menu = ""; 643 $params =& new mosParameters( '' ); 644 } 645 646 $params->set( 'intro_only', 1 ); 647 $params->set( 'year', $year ); 648 $params->set( 'month', $month ); 649 650 // Ordering control 651 $orderby_sec = $params->def( 'orderby_sec', 'rdate' ); 652 $orderby_pri = $params->def( 'orderby_pri', '' ); 653 $order_sec = _orderby_sec( $orderby_sec ); 654 $order_pri = _orderby_pri( $orderby_pri ); 655 656 // used in query 657 $where = _where( -1, $access, $noauth, $gid, $id, NULL, $year, $month ); 658 659 // checks to see if 'All Sections' options used 660 if ( $id == 0 ) { 661 $check = ''; 662 } else { 663 $check = 'AND a.sectionid = '. $id ; 664 } 665 // query to determine if there are any archived entries for the section 666 $query = "SELECT a.id" 667 . "\n FROM #__content as a" 668 . "\n WHERE a.state = '-1'" 669 . $check 670 ; 671 $database->setQuery( $query ); 672 $items = $database->loadObjectList(); 673 $archives = count( $items ); 674 675 // Main Query 676 $query = "SELECT a.*, ROUND(v.rating_sum/v.rating_count) AS rating, v.rating_count, u.name AS author, u.usertype, cc.name AS category, g.name AS groups" 677 . "\n FROM #__content AS a" 678 . "\n INNER JOIN #__categories AS cc ON cc.id = a.catid" 679 . "\n LEFT JOIN #__users AS u ON u.id = a.created_by" 680 . "\n LEFT JOIN #__content_rating AS v ON a.id = v.content_id" 681 . "\n LEFT JOIN #__sections AS s ON a.sectionid = s.id" 682 . "\n LEFT JOIN #__groups AS g ON a.access = g.id" 683 . ( count( $where ) ? "\n WHERE ". implode( "\n AND ", $where ) : '') 684 . "\n AND s.access <= ". $gid 685 . "\n ORDER BY ". $order_pri . $order_sec 686 ; 687 // $database->setQuery( $query ); 688 // $rows = $database->loadObjectList(); 689 $rows = $database->doSQLget($query, 'mosExtendedContent'); 690 691 // initiate form 692 echo '<form action="'.sefRelToAbs( 'index.php').'" method="post">'; 693 694 // Dynamic Page Title 695 $mainframe->SetPageTitle( $menu->name ); 696 697 if ( !$archives ) { 698 // if no archives for category, hides search and outputs empty message 699 echo '<br /><div align="center">'. T_('There are currently no Archived Entries for this Category') .'</div>'; 700 } else { 701 BlogOutput( $rows, $params, $gid, $access, $pop, $menu, 1 ); 702 } 703 704 echo '<input type="hidden" name="id" value="'. $id .'" />'; 705 echo '<input type="hidden" name="Itemid" value="'. $Itemid .'" />'; 706 echo '<input type="hidden" name="task" value="archivesection" />'; 707 echo '<input type="hidden" name="option" value="com_content" />'; 708 echo '<input type="hidden" name="module" value="1" />'; 709 echo '</form>'; 710 } 711 712 713 function showArchiveCategory( $id=0, $gid, &$access, $pop, $option, $now ) { 714 global $database, $mainframe, $mosConfig_offset; 715 global $Itemid; 716 717 // Parameters 718 $noauth = !$mainframe->getCfg( 'shownoauth' ); 719 $year = mosGetParam( $_REQUEST, 'year', date( 'Y' ) ); 720 $month = mosGetParam( $_REQUEST, 'month', date( 'm' ) ); 721 $module = trim( mosGetParam( $_REQUEST, 'module', '' ) ); 722 723 // used by archive module 724 if ( $module ) { 725 $check = ''; 726 } else { 727 $check = 'AND a.catid = '. $id; 728 } 729 730 if ( $Itemid ) { 731 $menu = new mosMenu( $database ); 732 $menu->load( $Itemid ); 733 $params =& new mosParameters( $menu->params ); 734 } else { 735 $menu = ""; 736 $params =& new mosParameters( '' ); 737 } 738 739 $params->set( 'year', $year ); 740 $params->set( 'month', $month ); 741 742 // Ordering control 743 $orderby_sec = $params->def( 'orderby', 'rdate' ); 744 $order_sec = _orderby_sec( $orderby_sec ); 745 746 // used in query 747 $where = _where( -2, $access, $noauth, $gid, $id, NULL, $year, $month ); 748 749 // query to determine if there are any archived entries for the category 750 $query = "SELECT a.id" 751 . "\n FROM #__content as a" 752 . "\n WHERE a.state = '-1'" 753 . "\n ". $check 754 ; 755 $database->setQuery( $query ); 756 $items = $database->loadObjectList(); 757 $archives = count( $items ); 758 759 $query = "SELECT a.*, ROUND( v.rating_sum / v.rating_count ) AS rating, v.rating_count, u.name AS author, u.usertype, s.name AS section, g.name AS groups" 760 . "\n FROM #__content AS a" 761 . "\n LEFT JOIN #__users AS u ON u.id = a.created_by" 762 . "\n LEFT JOIN #__content_rating AS v ON a.id = v.content_id" 763 . "\n LEFT JOIN #__sections AS s ON a.sectionid = s.id" 764 . "\n LEFT JOIN #__groups AS g ON a.access = g.id" 765 . ( count( $where ) ? "\n WHERE ". implode( "\n AND ", $where ) : '' ) 766 . "\n AND s.access <= ". $gid 767 . "\n ORDER BY ". $order_sec 768 ; 769 // $database->setQuery( $query ); 770 // $rows = $database->loadObjectList(); 771 $rows = $database->doSQLget($query, 'mosExtendedContent'); 772 773 // initiate form 774 echo '<form action="'.sefRelToAbs( 'index.php').'" method="post">'; 775 776 // Page Title 777 $mainframe->SetPageTitle( $menu->name ); 778 779 if ( !$archives ) { 780 // if no archives for category, hides search and outputs empty message 781 echo '<br /><div align="center">'. T_('There are currently no Archived Entries for this Category') .'</div>'; 782 } else { 783 BlogOutput( $rows, $params, $gid, $access, $pop, $menu, 1 ); 784 } 785 786 echo '<input type="hidden" name="id" value="'. $id .'" />'; 787 echo '<input type="hidden" name="Itemid" value="'. $Itemid .'" />'; 788 echo '<input type="hidden" name="task" value="archivecategory" />'; 789 echo '<input type="hidden" name="option" value="com_content" />'; 790 echo '<input type="hidden" name="module" value="1" />'; 791 echo '</form>'; 792 } 793 794 795 function BlogOutput ( &$rows, &$params, $gid, &$access, $pop, &$menu, $archive=NULL, $limit = 0, $limitstart = 0 ) { 796 global $mainframe, $Itemid, $task, $id, $option, $database, $mosConfig_live_site; 797 798 // parameters 799 if ( $params->get( 'page_title', 1 ) && $menu) { 800 $header = $params->def( 'header', $menu->name ); 801 } else { 802 $header = ''; 803 } 804 $columns = $params->def( 'columns', 2 ); 805 if ( $columns == 0 ) { 806 $columns = 1; 807 } 808 $intro = $params->def( 'intro', 4 ); 809 $leading = $params->def( 'leading', 1 ); 810 $links = $params->def( 'link', 4 ); 811 $pagination = $params->def( 'pagination', 2 ); 812 $pagination_results = $params->def( 'pagination_results', 1 ); 813 $pagination_results = $params->def( 'pagination_results', 1 ); 814 $descrip = $params->def( 'description', 1 ); 815 $descrip_image = $params->def( 'description_image', 1 ); 816 // needed for back button for page 817 $back = $params->get( 'back_button', $mainframe->getCfg( 'back_button' ) ); 818 // needed to disable back button for item 819 $params->set( 'back_button', 0 ); 820 $params->def( 'pageclass_sfx', '' ); 821 $params->set( 'intro_only', 1 ); 822 823 $total = count( $rows ); 824 825 // pagination support 826 if (!$limitstart){ 827 $limitstart = intval( mosGetParam( $_REQUEST, 'limitstart', 0 ) ); 828 } 829 $limit = $intro + $leading + $links; 830 if ( $total <= $limit ) { 831 $limitstart = 0; 832 } 833 $i = $limitstart; 834 835 // needed to reduce queries used by getItemid 836 require_once(mamboCore::get('mosConfig_absolute_path').'/components/com_content/content.class.php'); 837 $handler =& new contentHandler(); 838 $ItemidCount['bs'] = $handler->getBlogSectionCount(); 839 $ItemidCount['bc'] = $handler->getBlogCategoryCount(); 840 $ItemidCount['gbs'] = $handler->getGlobalBlogSectionCount(); 841 842 // used to display section/catagory description text and images 843 // currently not supported in Archives 844 if ( $menu && $menu->componentid && ( $descrip || $descrip_image ) ) { 845 switch ( $menu->type ) { 846 case 'content_blog_section': 847 $description = new mosSection( $database ); 848 $description->load( $menu->componentid ); 849 break; 850 851 case 'content_blog_category': 852 $description = new mosCategory( $database ); 853 $description->load( $menu->componentid ); 854 break; 855 856 default: 857 $menu->componentid = 0; 858 break; 859 } 860 } 861 862 // Page Output 863 // page header 864 if ( $header ) { 865 echo '<div class="componentheading'. $params->get( 'pageclass_sfx' ) .'">'. $header .'</div>'; 866 } 867 868 if ( $archive ) { 869 echo '<br />'; 870 echo mosHTML::monthSelectList( 'month', 'size="1" class="inputbox"', $params->get( 'month' ) ); 871 echo mosHTML::integerSelectList( 2000, 2010, 1, 'year', 'size="1" class="inputbox"', $params->get( 'year' ), "%04d" ); 872 echo '<input type="submit" class="button" />'; 873 } 874 875 // checks to see if there are there any items to display 876 if ( $total ) { 877 $col_with = 100 / $columns; // width of each column 878 $width = 'width="'. $col_with .'%"'; 879 880 if ( $archive ) { 881 // Search Success message 882 $msg = sprintf( T_('Here are the Archived entries for %s %s'), $params->get( 'month' ), $params->get( 'year' ) ); 883 echo "<br /><br /><div align='center'>". $msg ."</div><br /><br />"; 884 } 885 echo '<table class="blog' . $params->get( 'pageclass_sfx' ) . '" cellpadding="0" cellspacing="0">'; 886 887 // Secrion/Category Description & Image 888 if ( $menu && $menu->componentid && ( $descrip || $descrip_image ) ) { 889 $link = $mosConfig_live_site .'/images/stories/'. $description->image; 890 echo '<tr>'; 891 echo '<td valign="top">'; 892 if ( $descrip_image && $description->image ) { 893 echo '<img src="'. $link .'" align="'. $description->image_position .'" hspace="6" alt="" />'; 894 } 895 if ( $descrip && $description->description ) { 896 echo $description->description; 897 } 898 echo '<br /><br />'; 899 echo '</td>'; 900 echo '</tr>'; 901 } 902 903 // Leading story output 904 if ( $leading ) { 905 echo '<tr>'; 906 echo '<td valign="top">'; 907 for ( $z = 0; $z < $leading; $z++ ) { 908 if ( $i >= $total ) { 909 // stops loop if total number of items is less than the number set to display as leading 910 break; 911 } 912 echo '<div>'; 913 show( $rows[$i], $params, $gid, $access, $pop, $option, $ItemidCount ); 914 echo '</div>'; 915 $i++; 916 } 917 echo '</td>'; 918 echo '</tr>'; 919 } 920 921 if ( $intro && ( $i < $total ) ) { 922 echo '<tr>'; 923 echo '<td valign="top">'; 924 echo '<table width="100%" cellpadding="0" cellspacing="0">'; 925 // intro story output 926 for ( $z = 0; $z < $intro; $z++ ) { 927 if ( $i >= $total ) { 928 // stops loop if total number of items is less than the number set to display as intro + leading 929 break; 930 } 931 932 if ( !( $z % $columns ) || $columns == 1 ) { 933 echo '<tr>'; 934 } 935 936 echo '<td valign="top" '. $width .'>'; 937 938 // outputs either intro or only a link 939 if ( $z < $intro ) { 940 show( $rows[$i], $params, $gid, $access, $pop, $option, $ItemidCount ); 941 } else { 942 echo '</td>'; 943 echo '</tr>'; 944 break; 945 } 946 947 echo '</td>'; 948 949 if ( !( ( $z + 1 ) % $columns ) || $columns == 1 ) { 950 echo '</tr>'; 951 } 952 953 $i++; 954 } 955 956 // this is required to output a final closing </tr> tag when the number of items does not fully 957 // fill the last row of output - a blank column is left 958 if ( $intro % $columns ) { 959 echo '</tr>'; 960 } 961 962 echo '</table>'; 963 echo '</td>'; 964 echo '</tr>'; 965 } 966 967 // Links output 968 if ( $links && ( $i < $total ) ) { 969 echo '<tr>'; 970 echo '<td valign="top">'; 971 echo '<div class="blog_more'. $params->get( 'pageclass_sfx' ) .'">'; 972 HTML_content::showLinks( $rows, $links, $total, $i, 1 ); 973 echo '</div>'; 974 echo '</td>'; 975 echo '</tr>'; 976 } 977 978 // Pagination output 979 if ( $pagination ) { 980 if ( ( $pagination == 2 ) && ( $total <= $limit ) ) { 981 // not visible when they is no 'other' pages to display 982 } else { 983 // get the total number of records 984 $limitstart = $limitstart ? $limitstart : 0; 985 require_once( $GLOBALS['mosConfig_absolute_path'] . '/includes/pageNavigation.php' ); 986 $pageNav = new mosPageNav( $total, $limitstart, $limit ); 987 if ( $option == 'com_frontpage' ) { 988 $link = 'index.php?option=com_frontpage&Itemid='. $Itemid; 989 } else if ( $archive ) { 990 $year = $params->get( 'year' ); 991 $month = $params->get( 'month' ); 992 $link = 'index.php?option=com_content&task='. $task .'&id='. $id .'&Itemid='. $Itemid.'&year='. $year .'&month='. $month; 993 } else { 994 $link = 'index.php?option=com_content&task='. $task .'&id='. $id .'&Itemid='. $Itemid; 995 } 996 echo '<tr>'; 997 echo '<td valign="top" align="center">'; 998 echo $pageNav->writePagesLinks( $link ); 999 echo '<br /><br />'; 1000 echo '</td>'; 1001 echo '</tr>'; 1002 if ( $pagination_results ) { 1003 echo '<tr>'; 1004 echo '<td valign="top" align="center">'; 1005 echo $pageNav->writePagesCounter(); 1006 echo '</td>'; 1007 echo '</tr>'; 1008 } 1009 } 1010 } 1011 1012 echo '</table>'; 1013 1014 } else if ( $archive && !$total ) { 1015 // Search Failure message for Archives 1016 $msg = sprintf( T_('There are no Archived entries for %s %s'), $params->get( 'month' ), $params->get( 'year' ) ); 1017 echo '<br /><br /><div align="center">'. $msg .'</div><br />'; 1018 } else { 1019 // Generic blog empty display 1020 echo T_('There are no items to display'); 1021 } 1022 1023 // Back Button 1024 $params->set( 'back_button', $back ); 1025 mosHTML::BackButton ( $params ); 1026 } 1027 1028 1029 function showItem( $uid, $gid, &$access, $pop, $option, $now ) { 1030 global $database, $mainframe; 1031 global $mosConfig_offset, $mosConfig_live_site, $mosConfig_MetaTitle, $mosConfig_MetaAuthor; 1032 1033 if ( $access->canEdit ) { 1034 $xwhere=''; 1035 } else { 1036 $xwhere = "AND (a.state = '1' OR a.state = '-1')" 1037 . "\n AND (publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now')" 1038 . "\n AND (publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now')" 1039 ; 1040 } 1041 1042 global $acl; 1043 $viewAccess = ($gid >= $acl->get_group_id( 'Registered', 'ARO' ) ? 1 : 0) + ($gid >= $acl->get_group_id( 'Author', 'ARO' ) ? 1 : 0); 1044 $query = "SELECT a.*, ROUND(v.rating_sum/v.rating_count) AS rating, v.rating_count, u.name AS author, u.usertype, cc.name AS category, s.name AS section, g.name AS groups" 1045 . "\n FROM #__content AS a" 1046 . "\n LEFT JOIN #__categories AS cc ON cc.id = a.catid" 1047 . "\n LEFT JOIN #__sections AS s ON s.id = cc.section AND s.scope='content'" 1048 . "\n LEFT JOIN #__users AS u ON u.id = a.created_by" 1049 . "\n LEFT JOIN #__content_rating AS v ON a.id = v.content_id" 1050 . "\n LEFT JOIN #__groups AS g ON a.access = g.id" 1051 . "\n WHERE a.id='". $uid ."' ". $xwhere 1052 . "\n AND a.access <= ". $viewAccess 1053 ; 1054 $database->setQuery( $query ); 1055 $row = new mosExtendedContent(); 1056 1057 if ( $database->loadObject( $row ) ) { 1058 $pathway =& mosPathway::getInstance(); 1059 $pathway->addItem($row->category, categoryURL($row->sectionid, $row->catid)); 1060 $pathway->addItem($row->title, ''); 1061 $params =& new mosParameters( $row->attribs ); 1062 $params->set( 'intro_only', 0 ); 1063 $params->def( 'back_button', $mainframe->getCfg( 'back_button' ) ); 1064 if ( $row->sectionid == 0) { 1065 $params->set( 'item_navigation', 0 ); 1066 } else { 1067 $params->set( 'item_navigation', $mainframe->getCfg( 'item_navigation' ) ); 1068 } 1069 // loads the links for Next & Previous Button 1070 if ( $params->get( 'item_navigation' ) ) { 1071 $query = "SELECT a.id" 1072 . "\n FROM #__content AS a" 1073 . "\n WHERE a.catid = ". $row->catid."" 1074 . "\n AND a.state = $row->state AND ordering < $row->ordering" 1075 . ($access->canEdit ? "" : "\n AND a.access <= '". $gid ."'" ) 1076 . "\n AND ( a.publish_up = '0000-00-00 00:00:00' OR a.publish_up <= '". $now ."' )" 1077 . "\n AND ( a.publish_down = '0000-00-00 00:00:00' OR a.publish_down >= '". $now ."' )" 1078 . "\n ORDER BY a.ordering DESC" 1079 . "\n LIMIT 1" 1080 ; 1081 $database->setQuery( $query ); 1082 $row->prev = $database->loadResult(); 1083 1084 $query = "SELECT a.id" 1085 . "\n FROM #__content AS a" 1086 . "\n WHERE a.catid = ". $row->catid."" 1087 . "\n AND a.state = $row->state AND ordering > $row->ordering" 1088 . ($access->canEdit ? "" : "\n AND a.access <= '". $gid ."'" ) 1089 . "\n AND ( a.publish_up = '0000-00-00 00:00:00' OR a.publish_up <= '". $now ."' )" 1090 . "\n AND ( a.publish_down = '0000-00-00 00:00:00' OR a.publish_down >= '". $now ."' )" 1091 . "\n ORDER BY a.ordering" 1092 . "\n LIMIT 1" 1093 ; 1094 $database->setQuery( $query ); 1095 $row->next = $database->loadResult(); 1096 } 1097 // page title 1098 $mainframe->setPageTitle( $row->title ); 1099 if ($mosConfig_MetaTitle=='1') { 1100 $mainframe->addMetaTag( 'title' , $row->title ); 1101 } 1102 if ($mosConfig_MetaAuthor=='1') { 1103 $mainframe->addMetaTag( 'author' , $row->author ); 1104 } 1105 1106 show( $row, $params, $gid, $access, $pop, $option ); 1107 } else { 1108 mosNotAuth(); 1109 return; 1110 } 1111 } 1112 1113 1114 function show( $row, $params, $gid, &$access, $pop, $option, $ItemidCount=NULL ) { 1115 global $database, $mainframe, $Itemid; 1116 global $mosConfig_live_site, $mosConfig_absolute_path; 1117 global $options, $task; 1118 1119 //$cache = mosCache::getCache('com_content','Output'); 1120 1121 $noauth = !$mainframe->getCfg( 'shownoauth' ); 1122 1123 if ( $access->canEdit ) { 1124 if ( $row->id === null || $row->access > $gid ) { 1125 mosNotAuth(); 1126 return; 1127 } 1128 } else { 1129 if ( $row->id === null || $row->state == 0 ) { 1130 mosNotAuth(); 1131 return; 1132 } 1133 if ( $row->access > $gid ) { 1134 if ( $noauth ) { 1135 mosNotAuth(); 1136 return; 1137 } else { 1138 if ( !( $params->get( 'intro_only' ) ) ) { 1139 mosNotAuth(); 1140 return; 1141 } 1142 } 1143 } 1144 } 1145 1146 // GC Parameters 1147 $params->def( 'link_titles', $mainframe->getCfg( 'link_titles' ) ); 1148 $params->def( 'author', !$mainframe->getCfg( 'hideAuthor' ) ); 1149 $params->def( 'createdate', !$mainframe->getCfg( 'hideCreateDate' ) ); 1150 $params->def( 'modifydate', !$mainframe->getCfg( 'hideModifyDate' ) ); 1151 $params->def( 'print', !$mainframe->getCfg( 'hidePrint' ) ); 1152 $params->def( 'pdf', !$mainframe->getCfg( 'hidePdf' ) ); 1153 $params->def( 'email', !$mainframe->getCfg( 'hideEmail' ) ); 1154 $params->def( 'rating', $mainframe->getCfg( 'vote' ) ); 1155 $params->def( 'icons', $mainframe->getCfg( 'icons' ) ); 1156 $params->def( 'readmore', $mainframe->getCfg( 'readmore' ) ); 1157 // Other Params 1158 $params->def( 'image', 1 ); 1159 $params->def( 'section', 0 ); 1160 $params->def( 'section_link', 0 ); 1161 $params->def( 'category', 0 ); 1162 $params->def( 'category_link', 0 ); 1163 $params->def( 'introtext', 1 ); 1164 $params->def( 'pageclass_sfx', '' ); 1165 $params->def( 'item_title', 1 ); 1166 $params->def( 'url', 1 ); 1167 1168 // loads the link for Section name 1169 if ( $params->get( 'section_link' ) ) { 1170 $query = "SELECT a.id" 1171 . "\n FROM #__menu AS a" 1172 . "\n WHERE a.componentid = '". $row->sectionid."'" 1173 . "\n AND a.type = 'content_section'" 1174 . "\n AND a.published = 1" 1175 ; 1176 $database->setQuery( $query ); 1177 $_Itemid = $database->loadResult(); 1178 if (!intval($_Itemid)) 1179 $_Itemid = intval($Itemid) ? intval($Itemid) : 1; 1180 $link = sefRelToAbs( 'index.php?option=com_content&task=section&id='. $row->sectionid .'&Itemid='.$_Itemid ); 1181 $row->section = '<a href="'. $link .'">'. $row->section .'</a>'; 1182 } 1183 1184 // loads the link for Category name 1185 if ( $params->get( 'category_link' ) ) { 1186 $query = "SELECT a.id" 1187 . "\n FROM #__menu AS a" 1188 . "\n WHERE a.componentid = ". $row->catid."" 1189 . "\n AND a.type = 'content_category'" 1190 . "\n AND a.published = 1" 1191 ; 1192 $database->setQuery( $query ); 1193 $_Itemid = $database->loadResult(); 1194 if (!intval($_Itemid)) 1195 $_Itemid = intval($Itemid) ? intval($Itemid) : 1; 1196 $link = sefRelToAbs( 'index.php?option=com_content&task=section&id='. $row->sectionid .'&Itemid='.$_Itemid ); 1197 $link = sefRelToAbs( 'index.php?option=com_content&task=category&sectionid='. $row->sectionid .'&id='. $row->catid .'&Itemid='.$_Itemid ); 1198 $row->category = '<a href="'. $link .'">'. $row->category .'</a>'; 1199 } 1200 1201 // loads current template for the pop-up window 1202 $template = ''; 1203 if ( $pop ) { 1204 $params->set( 'popup', 1 ); 1205 $database->setQuery( "SELECT template FROM #__templates_menu WHERE client_id='0' AND menuid='0'" ); 1206 $template = $database->loadResult(); 1207 } 1208 1209 // show/hides the intro text 1210 if ( $params->get( 'introtext' ) ) { 1211 $row->text = $row->introtext. ( $params->get( 'intro_only' ) ? '' : chr(13) . chr(13) . $row->fulltext); 1212 } else { 1213 $row->text = $row->fulltext; 1214 } 1215 1216 // deal with the {mospagebreak} mambots 1217 // only permitted in the full text area 1218 $page = intval( mosGetParam( $_REQUEST, 'limitstart', 0 ) ); 1219 1220 // record the hit 1221 if ( !$params->get( 'intro_only' ) ) { 1222 $obj = new mosContent( $database ); 1223 $obj->hit( $row->id ); 1224 } 1225 //if(!($cache->start($task.$row->id.$page,'com_content'))){ 1226 HTML_content::show( $row, $params, $access, $page, $option, $ItemidCount ); 1227 // $cache->end(); 1228 //} 1229 } 1230 1231 1232 function editItem( $uid, $gid, &$access, $sectionid=0, $task, $Itemid ){ 1233 global $database, $mainframe, $my; 1234 global $mosConfig_absolute_path, $mosConfig_live_site; 1235 1236 $row = new mosContent( $database ); 1237 // load the row from the db table 1238 $row->load( $uid ); 1239 1240 // fail if checked out not by 'me' 1241 if ( $row->checked_out && $row->checked_out <> $my->id ) { 1242 echo"<script>alert('".sprintf(T_('The module [ %s ] is currently being edited by another person.'), $row->title)."'); window.history.go(-1); </script>"; 1243 exit; 1244 } 1245 1246 if ( $uid ) { 1247 // existing record 1248 if ( !( $access->canEdit || ( $access->canEditOwn && $row->created_by == $my->id ) ) ) { 1249 mosNotAuth(); 1250 return; 1251 } 1252 } else { 1253 // new record 1254 if (!($access->canEdit || $access->canEditOwn)) { 1255 mosNotAuth(); 1256 return; 1257 } 1258 } 1259 1260 if ( $uid ) { 1261 $sectionid = $row->sectionid; 1262 } 1263 1264 $lists = array(); 1265 1266 // get the type name - which is a special category 1267 $query = "SELECT name FROM #__sections WHERE id='$sectionid'"; 1268 $database->setQuery( $query ); 1269 $section = $database->loadResult(); 1270 1271 if ( $uid == 0 ) { 1272 $row->catid = 0; 1273 } 1274 1275 if ( $uid ) { 1276 $row->checkout( $my->id ); 1277 if (trim( $row->publish_down ) == "0000-00-00 00:00:00") { 1278 $row->publish_down = 'Never'; 1279 } 1280 if (trim( $row->images )) { 1281 $row->images = explode( "\n", $row->images ); 1282 } else { 1283 $row->images = array(); 1284 } 1285 $query = "SELECT name from #__users" 1286 . "\n WHERE id = ". $row->created_by 1287 ; 1288 $database->setQuery( $query ); 1289 $row->creator = $database->loadResult(); 1290 1291 $query = "SELECT name from #__users" 1292 . "\n WHERE id = ". $row->modified_by 1293 ; 1294 $database->setQuery( $query ); 1295 $row->modifier = $database->loadResult(); 1296 1297 $query = "SELECT content_id from #__content_frontpage" 1298 ."\n WHERE content_id = ". $row->id 1299 ; 1300 $database->setQuery( $query ); 1301 $row->frontpage = $database->loadResult(); 1302 } else { 1303 $row->sectionid = $sectionid; 1304 $row->version = 0; 1305 $row->state = 0; 1306 $row->ordering = 0; 1307 $row->images = array(); 1308 $row->publish_up = date( 'Y-m-d', time() ); 1309 $row->publish_down = 'Never'; 1310 $row->creator = 0; 1311 $row->modifier = 0; 1312 $row->frontpage = 0; 1313 } 1314 1315 // calls function to read image from directory 1316 $pathA = $mosConfig_absolute_path .'/images/stories'; 1317 $pathL = $mosConfig_live_site .'/images/stories'; 1318 $images = array(); 1319 $folders = array(); 1320 $folders[] = mosHTML::makeOption( '/' ); 1321 require_once ($mosConfig_absolute_path.'/administrator/includes/mosAdminMenus.php'); 1322 mosAdminMenus::ReadImages( $pathA, '/', $folders, $images ); 1323 // list of folders in images/stories/ 1324 $lists['folders'] = mosAdminMenus::GetImageFolders( $folders, $pathL ); 1325 // list of images in specfic folder in images/stories/ 1326 $lists['imagefiles'] = mosAdminMenus::GetImages( $images, $pathL ); 1327 // list of saved images 1328 $lists['imagelist'] = mosAdminMenus::GetSavedImages( $row, $pathL ); 1329 1330 // make the select list for the states 1331 $states[] = mosHTML::makeOption( 0, T_('Unpublished') ); 1332 $states[] = mosHTML::makeOption( 1, T_('Published') ); 1333 $lists['state'] = mosHTML::selectList( $states, 'state', 'class="inputbox" size="1"', 'value', 'text', intval( $row->state ) ); 1334 1335 // build the html select list for ordering 1336 $query = "SELECT ordering AS value, title AS text" 1337 . "\n FROM #__content" 1338 . "\n WHERE catid = '$row->catid'" 1339 . "\n ORDER BY ordering" 1340 ; 1341 $lists['ordering'] = mosAdminMenus::SpecificOrdering( $row, $uid, $query, 1 ); 1342 // build list of categories 1343 $lists['catid'] = mosAdminMenus::ComponentCategory( 'catid', $sectionid, intval( $row->catid ) ); 1344 // build the select list for the image positions 1345 $lists['_align'] = mosAdminMenus::Positions( '_align' ); 1346 // build the select list for the image caption alignment 1347 $lists['_caption_align'] = mosAdminMenus::Positions( '_caption_align' ); 1348 // build the html select list for the group access 1349 $lists['access'] = mosAdminMenus::Access( $row ); 1350 1351 // build the select list for the image caption position 1352 $pos[] = mosHTML::makeOption( 'bottom', _CMN_BOTTOM ); 1353 $pos[] = mosHTML::makeOption( 'top', _CMN_TOP ); 1354 $lists['_caption_position'] = mosHTML::selectList( $pos, '_caption_position', 'class="inputbox" size="1"', 'value', 'text' ); 1355 1356 HTML_content::editContent( $row, $section, $lists, $images, $access, $my->id, $sectionid, $task, $Itemid ); 1357 } 1358 1359 1360 /** 1361 * Saves the content item an edit form submit 1362 */ 1363 function saveContent( &$access ) { 1364 global $database, $mainframe, $my; 1365 global $mosConfig_absolute_path; 1366 1367 $row = new mosContent( $database ); 1368 if ( !$row->bind( $_POST ) ) { 1369 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 1370 exit(); 1371 } 1372 // sanitize 1373 $row->id = intval($row->id); 1374 $row->catid = intval($row->catid); 1375 $row->sectionid = intval($row->sectionid); 1376 $isNew = $row->id < 1; 1377 if ( $isNew ) { 1378 // new record 1379 if ( !( $access->canEdit || $access->canEditOwn ) ) { 1380 mosNotAuth(); 1381 return; 1382 } 1383 $row->created = date( 'Y-m-d H:i:s' ); 1384 $row->created_by = $my->id; 1385 } else { 1386 // existing record 1387 if ( !( $access->canEdit || ( $access->canEditOwn && $row->created_by == $my->id ) ) ) { 1388 mosNotAuth(); 1389 return; 1390 } 1391 $row->modified = date( 'Y-m-d H:i:s' ); 1392 $row->modified_by = $my->id; 1393 } 1394 if ( trim( $row->publish_down ) == 'Never' ) { 1395 $row->publish_down = '0000-00-00 00:00:00'; 1396 } 1397 1398 if (!$row->check()) { 1399 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 1400 exit(); 1401 } 1402 $row->version++; 1403 if (!$row->store()) { 1404 echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; 1405 exit(); 1406 } 1407 1408 // manage frontpage items 1409 require_once( $mainframe->getPath( 'class', 'com_frontpage' ) ); 1410 $fp = new mosFrontPage( $database ); 1411 1412 if ( mosGetParam( $_REQUEST, 'frontpage', 0 ) ) { 1413 1414 // toggles go to first place 1415 if (!$fp->load( $row->id )) { 1416 // new entry 1417 $database->setQuery( "INSERT INTO #__content_frontpage VALUES ('$row->id','1')" ); 1418 if (!$database->query()) { 1419 echo "<script> alert('".$database->stderr()."');</script>\n"; 1420 exit(); 1421 } 1422 $fp->ordering = 1; 1423 } 1424 } else { 1425 // no frontpage mask 1426 if ( !$fp->delete( $row->id ) ) { 1427 $msg .= $fp->stderr(); 1428 } 1429 $fp->ordering = 0; 1430 } 1431 $fp->updateOrder(); 1432 1433 $row->checkin(); 1434 $row->updateOrder( "catid='$row->catid'" ); 1435 1436 // gets section name of item 1437 $database->setQuery( "SELECT s.title" 1438 . "\n FROM #__sections AS s" 1439 . "\n WHERE s.scope = 'content'" 1440 . "\n AND s.id = '". $row->sectionid ."'" 1441 ); 1442 // gets category name of item 1443 $section = $database->loadResult(); 1444 $database->setQuery( "SELECT c.title" 1445 . "\n FROM #__categories AS c" 1446 . "\n WHERE c.id = '". $row->catid ."'" 1447 ); 1448 $category = $database->loadResult(); 1449 1450 if ( $isNew ) { 1451 // messaging for new items 1452 require_once ( $mosConfig_absolute_path .'/components/com_messages/messages.class.php' ); 1453 $database->setQuery( "SELECT id FROM #__users WHERE sendEmail = '1'" ); 1454 $users = $database->loadResultArray(); 1455 if ($users) { 1456 foreach ($users as $user_id) { 1457 $msg = new mosMessage( $database ); 1458 $msg->send( $my->id, $user_id, T_("New Item"), sprintf( T_('A new content item has been submitted by [ %s ] titled [ %s ] from section [ %s ] and category [ %s ]'), $my->username, $row->title, $section, $category ) ); 1459 } 1460 } 1461 } 1462 $Itemid = mosGetParam( $_POST, 'Returnid', '0' ); 1463 $msg = $isNew ? T_('Thanks for your submission; it will be reviewed before being posted to the site.') : T_('Item saved successfully.'); 1464 1465 $link = $isNew ? 'index.php' : sefRelToAbs( 'index.php?option=com_content&task=view&id='.$row->id.'&Itemid='.$Itemid ); 1466 mosRedirect( $link, $msg); 1467 } 1468 1469 1470 /** 1471 * Cancels an edit operation 1472 * @param database A database connector object 1473 */ 1474 function cancelContent( &$access ) { 1475 global $database, $mainframe, $my; 1476 1477 $row = new mosContent( $database ); 1478 $row->bind( $_POST ); 1479 // sanitize 1480 $row->id = intval($row->id); 1481 1482 if ( $access->canEdit || ( $access->canEditOwn && $row->created_by == $my->id ) ) { 1483 $row->checkin(); 1484 } 1485 1486 $Itemid = mosGetParam( $_POST, 'Returnid', '0' ); 1487 1488 $link = sefRelToAbs( 'index.php?option=com_content&task=view&id='.$row->id.'&Itemid='.$Itemid ); 1489 mosRedirect( $link ); 1490 } 1491 1492 /** 1493 * Shows the email form for a given content item. 1494 */ 1495 function emailContentForm( $uid ) { 1496 global $database, $mainframe, $my; 1497 $row = new mosContent( $database ); 1498 $row->load( $uid ); 1499 1500 if ( $row->id === null || $row->access > $my->gid ) { 1501 mosNotAuth(); 1502 return; 1503 } else { 1504 $template=''; 1505 $database->setQuery( "SELECT template FROM #__templates_menu WHERE client_id = '0' AND menuid = '0'" ); 1506 $template = $database->loadResult(); 1507 HTML_content::emailForm( $row->id, $row->title, $template ); 1508 } 1509 1510 } 1511 1512 1513 /** 1514 * Shows the email form for a given content item. 1515 */ 1516 function emailContentSend( $uid ) { 1517 global $database, $mainframe; 1518 global $mosConfig_live_site, $mosConfig_sitename; 1519 global $mosConfig_mailfrom, $mosConfig_fromname; 1520 1521 $_Itemid = $mainframe->getItemid( $uid, 0, 0 ); 1522 1523 $email = trim( mosGetParam( $_POST, 'email', '' ) ); 1524 $yourname = trim( mosGetParam( $_POST, 'yourname', '' ) ); 1525 $youremail = trim( mosGetParam( $_POST, 'youremail', '' ) ); 1526 $subject_default = sprintf(T_('Item sent by %s'), $yourname); 1527 $subject = trim( mosGetParam( $_POST, 'subject', $subject_default ) ); 1528 1529 mos_session_start(); 1530 $form_check = mosGetParam( $_POST, 'form_check', '' ); 1531 if (empty($_SESSION['_form_check_']['com_content']) || $form_check != $_SESSION['_form_check_']['com_content']) { 1532 // the form hasn't been generated by the server on this session 1533 exit; 1534 } 1535 if ( !$email || !$youremail || ( is_email( $email ) == false ) || ( is_email( $youremail ) == false ) ) { 1536 echo "<script>alert (\"".T_('You must enter valid e-mail addresses for both yourself and your recipient.')."\"); window.history.go(-1);</script>"; 1537 exit(0); 1538 } 1539 1540 $template=''; 1541 $database->setQuery( "SELECT template FROM #__templates_menu WHERE client_id='0' AND menuid='0'" ); 1542 $template = $database->loadResult(); 1543 1544 // link sent in email 1545 $link = sefRelToAbs( $mosConfig_live_site .'/index.php?option=com_content&task=view&id='. $uid .'&Itemid='. $_Itemid ); 1546 // message text 1547 $msg = sprintf( T_(' The following page from the \"%s\" website has been sent to you by %s ( %s ).\n\nYou can access it at the following url:\n%s'), $mosConfig_sitename, $yourname, $youremail, $link ); 1548 1549 // mail function 1550 mosMail( $mosConfig_mailfrom, $mosConfig_fromname, $email, $subject, $msg ); 1551 1552 HTML_content::emailSent( $email, $template ); 1553 } 1554 1555 function is_email( $email ){ 1556 $rBool = false; 1557 1558 if ( preg_match( "/[\w\.\-]+@\w+[\w\.\-]*?\.\w{1,4}/", $email ) ) { 1559 $rBool = true; 1560 } 1561 return $rBool; 1562 } 1563 1564 function recordVote() { 1565 global $database, $mosConfig_live_site, $mosConfig_offset, $acl, $gid; 1566 1567 $user_rating = mosGetParam( $_REQUEST, 'user_rating', 0 ); 1568 $cid = mosGetParam( $_REQUEST, 'cid', 0 ); 1569 $cid = intval( $cid ); 1570 $Itemid = mosGetParam( $_REQUEST, 'Itemid', 0 ); 1571 $Itemid = intval( $Itemid ); 1572 $user_rating = intval( $user_rating ); 1573 $now = date( 'Y-m-d H:i:s', time() + $mosConfig_offset * 60 * 60 ); 1574 $viewAccess = ($gid >= $acl->get_group_id( 'Registered', 'ARO' ) ? 1 : 0) + ($gid >= $acl->get_group_id( 'Author', 'ARO' ) ? 1 : 0); 1575 1576 $url = sefReltoAbs("index.php?option=com_content&task=view&id={$cid}&Itemid={$Itemid}"); 1577 if ( ( $user_rating >= 1 ) and ( $user_rating <= 5 ) ) { 1578 $currip = getenv( 'REMOTE_ADDR' ); 1579 1580 $query = "SELECT * FROM #__content as c WHERE id = $cid AND (c.state = '1' OR c.state = '-1')" 1581 . "\n AND (c.publish_up = '0000-00-00 00:00:00' OR c.publish_up <= '$now')" 1582 . "\n AND (c.publish_down = '0000-00-00 00:00:00' OR c.publish_down >= '$now')" 1583 . "\n AND access <= ". $viewAccess; 1584 ; 1585 $database->setQuery( $query ); 1586 $database->loadObject( $row ); 1587 if ( $row != NULL){ 1588 $query = "SELECT * FROM #__content_rating WHERE content_id = $cid"; 1589 $database->setQuery( $query ); 1590 $votesdb = NULL; 1591 if ( !( $database->loadObject( $votesdb ) ) ) { 1592 $query = "INSERT INTO #__content_rating ( content_id, lastip, rating_sum, rating_count )" 1593 . "\n VALUES ( '$cid', '$currip', '$user_rating', '1' )"; 1594 $database->setQuery( $query ); 1595 $database->query() or die( $database->stderr() );; 1596 } else { 1597 if ($currip <> ($votesdb->lastip)) { 1598 $query = "UPDATE #__content_rating" 1599 . "\n SET rating_count = rating_count + 1," 1600 . "\n rating_sum = rating_sum + $user_rating," 1601 . "\n lastip = '$currip'" 1602 . "\n WHERE content_id = ". $cid 1603 ; 1604 $database->setQuery( $query ); 1605 $database->query() or die( $database->stderr() ); 1606 } else { 1607 mosRedirect ( $url, T_('You already voted for this poll today!') ); 1608 } 1609 } 1610 mosRedirect ( $url, T_('Thanks for your vote!') ); 1611 } else { 1612 mosRedirect ( $url, T_('The rating for this item is not allowed!') ); 1613 } 1614 } 1615 } 1616 1617 1618 function _orderby_pri( $orderby ) { 1619 switch ( $orderby ) { 1620 case 'alpha': 1621 $orderby = 'cc.title, '; 1622 break; 1623 case 'ralpha': 1624 $orderby = 'cc.title DESC, '; 1625 break; 1626 case 'order': 1627 $orderby = 'cc.ordering, '; 1628 break; 1629 default: 1630 $orderby = ''; 1631 break; 1632 } 1633 1634 return $orderby; 1635 } 1636 1637 1638 function _orderby_sec( $orderby ) { 1639 switch ( $orderby ) { 1640 case 'date': 1641 $orderby = 'a.created'; 1642 break; 1643 case 'rdate': 1644 $orderby = 'a.created DESC'; 1645 break; 1646 case 'alpha': 1647 $orderby = 'a.title'; 1648 break; 1649 case 'ralpha': 1650 $orderby = 'a.title DESC'; 1651 break; 1652 case 'hits': 1653 $orderby = 'a.hits DESC'; 1654 break; 1655 case 'rhits': 1656 $orderby = 'a.hits ASC'; 1657 break; 1658 case 'order': 1659 $orderby = 'a.ordering'; 1660 break; 1661 case 'author': 1662 $orderby = 'a.created_by, u.name'; 1663 break; 1664 case 'rauthor': 1665 $orderby = 'a.created_by DESC, u.name DESC'; 1666 break; 1667 case 'front': 1668 $orderby = 'f.ordering'; 1669 break; 1670 default: 1671 $orderby = 'a.ordering'; 1672 break; 1673 } 1674 1675 return $orderby; 1676 } 1677 1678 /* 1679 * @param int 0 = Archives, 1 = Section, 2 = Category 1680 */ 1681 function _where( $type=1, &$access, &$noauth, $gid, $id, $now=NULL, $year=NULL, $month=NULL ) { 1682 $where = array(); 1683 1684 // normal 1685 if ( $type > 0) { 1686 $where[] = "a.state = '1'"; 1687 if ( !$access->canEdit ) { 1688 $where[] = "( a.publish_up = '0000-00-00 00:00:00' OR a.publish_up <= '". $now ."' )"; 1689 $where[] = "( a.publish_down = '0000-00-00 00:00:00' OR a.publish_down >= '". $now ."' )"; 1690 } 1691 if ( $noauth ) { 1692 $where[] = "a.access <= '". $gid ."'"; 1693 } 1694 if ( $id > 0 ) { 1695 if ( $type == 1 ) { 1696 $where[] = "a.sectionid IN ( ". $id ." ) "; 1697 } else if ( $type == 2 ) { 1698 $where[] = "a.catid IN ( ". $id ." ) "; 1699 } 1700 } 1701 } 1702 1703 // archive 1704 if ( $type < 0 ) { 1705 $where[] = "a.state='-1'"; 1706 if ( $year ) { 1707 $where[] = "YEAR( a.created ) = '". $year ."'"; 1708 } 1709 if ( $month ) { 1710 $where[] = "MONTH( a.created ) = '". $month ."'"; 1711 } 1712 if ( $noauth ) { 1713 $where[] = "a.access <= '". $gid ."'"; 1714 } 1715 if ( $id > 0 ) { 1716 if ( $type == -1 ) { 1717 $where[] = "a.sectionid = '". $id ."'"; 1718 } else if ( $type == -2) { 1719 $where[] = "a.catid = '". $id ."'"; 1720 } 1721 } 1722 } 1723 1724 return $where; 1725 } 1726 1727 function sectionURL ($sectionid) { 1728 $menuHandler = mosMenuHandler::getInstance(); 1729 $Itemid = $menuHandler->getSectionItemId($sectionid); 1730 return "index.php?option=com_content&task=section&id=$sectionid&Itemid=$Itemid"; 1731 } 1732 1733 function categoryURL ($sectionid, $catid) { 1734 $menuHandler = mosMenuHandler::getInstance(); 1735 $Itemid = $menuHandler->getCategoryItemId($catid); 1736 return "index.php?option=com_content&task=category§ionid=$sectionid&id=$catid&Itemid=$Itemid"; 1737 } 1738 1739 ?>