[ Index ]

PHP Cross Reference of Mambo 4.6.5

[ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/modules/ -> mod_latestnews.php (source)

   1  <?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  /** ensure this file is being included by a parent file */
  17  defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
  18  
  19  global $mosConfig_offset, $mosConfig_live_site, $mainframe, $acl, $my;
  20  
  21  $type         = intval( $params->get( 'type', 1 ) );
  22  $count         = intval( $params->get( 'count', 5 ) );
  23  $count         = intval( $params->get( 'count', 5 ) );
  24  $catid         = trim( $params->get( 'catid' ) );
  25  $secid         = trim( $params->get( 'secid' ) );
  26  $show_front    = $params->get( 'show_front', 1 );
  27  $class_sfx    = $params->get( 'moduleclass_sfx' );
  28  
  29  $now         = date( 'Y-m-d H:i:s', time() + $mosConfig_offset * 60 * 60 );
  30  
  31  $access = !$mainframe->getCfg( 'shownoauth' );
  32  $viewAccess = ($my->gid >= $acl->get_group_id( 'Registered', 'ARO' ) ? 1 : 0) + ($my->gid >= $acl->get_group_id( 'Author', 'ARO' ) ? 1 : 0);
  33  
  34  // select between Content Items, Static Content or both
  35  switch ( $type ) {
  36      case 2: //Static Content only
  37          $query = "SELECT a.id, a.title"
  38          . "\n FROM #__content AS a"
  39          . "\n WHERE ( a.state = '1' AND a.checked_out = '0' AND a.sectionid = '0' )"
  40          . "\n AND ( a.publish_up = '0000-00-00 00:00:00' OR a.publish_up <= '". $now ."' )"
  41          . "\n AND ( a.publish_down = '0000-00-00 00:00:00' OR a.publish_down >= '". $now ."' )"
  42          . ( $access ? "\n AND a.access <= '". $viewAccess ."'" : '' )
  43          . "\n ORDER BY a.created DESC LIMIT $count"
  44          ;
  45          $database->setQuery( $query );
  46          $rows = $database->loadObjectList();    
  47          break;
  48  
  49      case 3: //Both
  50          $query = "SELECT a.id, a.title, a.sectionid"
  51          . "\n FROM #__content AS a"
  52          . "\n WHERE ( a.state = '1' AND a.checked_out = '0' )"
  53          . "\n AND ( a.publish_up = '0000-00-00 00:00:00' OR a.publish_up <= '". $now ."' )"
  54          . "\n AND ( a.publish_down = '0000-00-00 00:00:00' OR a.publish_down >= '". $now ."' )"
  55          . ( $access ? "\n AND a.access <= '". $viewAccess ."'" : '' )
  56          . "\n ORDER BY a.created DESC LIMIT $count"
  57          ;
  58          $database->setQuery( $query );
  59          $rows = $database->loadObjectList();    
  60          break;
  61          
  62      case 1:  //Content Items only
  63      default:
  64          $query = "SELECT a.id, a.title, a.sectionid, a.catid"
  65          . "\n FROM #__content AS a"
  66          . "\n LEFT JOIN #__content_frontpage AS f ON f.content_id = a.id"
  67          . "\n WHERE ( a.state = '1' AND a.checked_out = '0' AND a.sectionid > '0' )"
  68          . "\n AND ( a.publish_up = '0000-00-00 00:00:00' OR a.publish_up <= '". $now ."' )"
  69          . "\n AND ( a.publish_down = '0000-00-00 00:00:00' OR a.publish_down >= '". $now ."' )"
  70          . ( $access ? "\n AND a.access <= '". $viewAccess ."'" : '' )
  71          . ( $catid ? "\n AND ( a.catid IN (". $catid .") )" : '' )
  72          . ( $secid ? "\n AND ( a.sectionid IN (". $secid .") )" : '' )
  73          . ( $show_front == "0" ? "\n AND f.content_id IS NULL" : '' )
  74          . "\n ORDER BY a.created DESC LIMIT $count"
  75          ;
  76          $database->setQuery( $query );
  77          $rows = $database->loadObjectList();
  78          break;        
  79  }
  80  
  81  // Output
  82  ?>
  83  
  84  <?php
  85  if (is_array($rows)) {
  86      // needed to reduce queries used by getItemid for Content Items
  87      if ( ( $type == 1 ) || ( $type == 3 ) ) {
  88          require_once(mamboCore::get('mosConfig_absolute_path').'/components/com_content/content.class.php');
  89          $handler =& new contentHandler();
  90          $bs     = $handler->getBlogSectionCount();
  91          $bc     = $handler->getBlogCategoryCount();
  92          $gbs     = $handler->getGlobalBlogSectionCount();
  93      }
  94      
  95      $menuhandler =& mosMenuHandler::getInstance();
  96      
  97      echo '<ul class="latestnews'.$class_sfx.'">';
  98      
  99      foreach ( $rows as $row ) {
 100          // get Itemid
 101          switch ( $type ) {
 102              case 2:
 103                  $Itemid = $menuhandler->getIDByTypeCid ('content_typed', $row->id);
 104                  break;
 105                  
 106              case 3:
 107                  if ( $row->sectionid ) {
 108                      $Itemid = $mainframe->getItemid( $row->id, 0, 0, $bs, $bc, $gbs );
 109                  }
 110                  else $Itemid = $menuhandler->getIDByTypeCid ('content_typed', $row->id);
 111                  break;
 112  
 113              case 1:
 114              default:
 115                  $Itemid = $mainframe->getItemid( $row->id, 0, 0, $bs, $bc, $gbs );
 116                  break;
 117          }
 118          
 119          // Blank itemid checker for SEF
 120          if ($Itemid == NULL) {
 121              $Itemid = '';
 122          } else {
 123              $Itemid = '&amp;Itemid='. $Itemid;
 124          }
 125          
 126          $link = sefRelToAbs( 'index.php?option=com_content&amp;task=view&amp;id='. $row->id . $Itemid );
 127          ?>
 128          <li class="latestnews<?php echo $class_sfx; ?>">
 129          <a href="<?php echo $link; ?>" class="latestnews<?php echo $class_sfx; ?>">
 130          <?php echo $row->title; ?>
 131          </a>
 132          </li>
 133          <?php
 134      }
 135      
 136      echo '</ul>';
 137  }
 138  ?>