[ Index ]

PHP Cross Reference of E107 v0.7.22 code documentation

title

Body

[close]

/ -> news.php (source)

   1  <?php
   2  /*
   3  + ----------------------------------------------------------------------------+
   4  |     e107 website system
   5  |
   6  |     ©Steve Dunstan 2001-2002
   7  |     http://e107.org
   8  |     jalist@e107.org
   9  |
  10  |     Released under the terms and conditions of the
  11  |     GNU General Public License (http://gnu.org).
  12  |
  13  |     $Source: /cvs_backup/e107_0.7/news.php,v $
  14  |     $Revision: 11461 $
  15  |     $Date: 2010-04-05 17:34:57 -0400 (Mon, 05 Apr 2010) $
  16  |     $Author: e107steved $
  17  +----------------------------------------------------------------------------+
  18  */
  19  require_once ("class2.php");
  20  require_once(e_HANDLER."news_class.php");
  21  //require_once(e_HANDLER."comment_class.php");
  22  //$cobj = new comment;
  23  
  24  if (isset($NEWSHEADER)) 
  25  {
  26    require_once(HEADERF);
  27    require_once(FOOTERF);
  28    exit;
  29  }
  30  
  31  include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/lan_news.php');        // Temporary
  32  
  33  $cacheString = 'news.php_default_';
  34  $action = '';
  35  $sub_action = '';
  36  $order = 'news_datestamp';
  37  $newsfrom = 0;
  38  
  39  if (!defined('ITEMVIEW'))
  40  {
  41    define('ITEMVIEW', varset($pref['newsposts'],15));
  42  }
  43  
  44  if (e_QUERY) 
  45  {
  46      $tmp = explode('.', e_QUERY);
  47      $action = $tmp[0];                            // At least one parameter here
  48      $sub_action = varset($tmp[1],'');            // Usually a numeric category, or numeric news item number, but don't presume yet
  49  //    $id = varset($tmp[2],'');                    // ID of specific news item where required
  50      $newsfrom = intval(varset($tmp[2],0));        // Item number for first item on multi-page lists
  51      $cacheString = 'news.php_'.e_QUERY;
  52  }
  53  
  54  //$newsfrom = (!is_numeric($action) || !e_QUERY ? 0 : ($action ? $action : e_QUERY));
  55  
  56  // Usually the first query parameter is the action.
  57  // For any of the 'list' modes (inc month, day), the action being second is a legacy situation
  58  // .... which can hopefully go sometime
  59  if (is_numeric($action) && isset($tmp[1]) && (($tmp[1] == 'list') || ($tmp[1] == 'month') || ($tmp[1] == 'day')))
  60  {
  61      $action = $tmp[1];
  62      $sub_action = varset($tmp[0],'');
  63  }
  64  
  65  
  66  
  67  if ($action == 'all' || $action == 'cat') 
  68  {
  69    $sub_action = intval(varset($tmp[1],0));
  70  }
  71  
  72  /*
  73  Variables Used:
  74      $action - the basic display format/filter
  75      $sub_action - category number or news item number
  76      $newsfrom - first item number in list (default 0) - derived from nextprev
  77      $order - sets the listing order for 'list' format
  78  */
  79  
  80  
  81  $ix = new news;
  82  $nobody_regexp = "'(^|,)(".str_replace(",", "|", e_UC_NOBODY).")(,|$)'";
  83  
  84  //------------------------------------------------------
  85  //        DISPLAY NEWS IN 'CATEGORY' FORMAT HERE
  86  //------------------------------------------------------
  87  // Just title and a few other details
  88  if ($action == 'cat' || $action == 'all')
  89  {    // --> Cache
  90      if($newsCachedPage = checkCache($cacheString))
  91      {
  92          require_once(HEADERF);
  93          renderCache($newsCachedPage, TRUE);
  94      }
  95      // <-- Cache
  96  
  97  
  98      $category = intval($sub_action);
  99      if ($action == 'cat' && $category != 0)    
 100      {
 101          $gen = new convert;
 102          $sql->db_Select("news_category", "*", "category_id='{$category}'");
 103          $row = $sql->db_Fetch();
 104          extract($row);  // still required for the table-render.  :(
 105      }
 106      if ($action == 'all')
 107      {
 108          if(!defined("NEWSALL_LIMIT")) { define("NEWSALL_LIMIT",10); }
 109          // show archive of all news items using list-style template.
 110          $news_total = $sql->db_Count("news", "(*)", "WHERE news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (news_class REGEXP ".$nobody_regexp.") AND news_start < ".time()." AND (news_end=0 || news_end>".time().")");
 111          $query = "SELECT n.*, u.user_id, u.user_name, u.user_customtitle, nc.category_name, nc.category_icon FROM #news AS n
 112          LEFT JOIN #user AS u ON n.news_author = u.user_id
 113          LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id
 114          WHERE n.news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (n.news_class REGEXP ".$nobody_regexp.") AND n.news_start < ".time()."
 115          AND (n.news_end=0 || n.news_end>".time().")  
 116          ORDER BY n.news_sticky DESC, n.news_datestamp DESC 
 117          LIMIT ".intval($newsfrom).",".NEWSALL_LIMIT;
 118          $category_name = "All";
 119      }
 120      elseif ($action == 'cat')
 121      {
 122          // show archive of all news items in a particular category using list-style template.
 123          $news_total = $sql->db_Count("news", "(*)", "WHERE news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (news_class REGEXP ".$nobody_regexp.") AND news_start < ".time()." AND (news_end=0 || news_end>".time().") AND news_category=".intval($sub_action));
 124          if(!defined("NEWSLIST_LIMIT")) { define("NEWSLIST_LIMIT",10); }
 125          $query = "SELECT n.*, u.user_id, u.user_name, u.user_customtitle, nc.category_name, nc.category_icon FROM #news AS n
 126          LEFT JOIN #user AS u ON n.news_author = u.user_id
 127          LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id
 128          WHERE n.news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (n.news_class REGEXP ".$nobody_regexp.") 
 129          AND n.news_start < ".time()." AND (n.news_end=0 || n.news_end>".time().") 
 130          AND n.news_category=".intval($sub_action)." 
 131          ORDER BY n.news_datestamp DESC 
 132          LIMIT ".intval($newsfrom).",".NEWSLIST_LIMIT;
 133      }
 134  
 135      if($category_name)
 136      {
 137          define('e_PAGETITLE', $tp->toHTML($category_name,FALSE,'TITLE'));
 138      }
 139  
 140      require_once(HEADERF);
 141  
 142      if(!$NEWSLISTSTYLE)
 143      {
 144          $NEWSLISTSTYLE = "
 145          <div style='padding:3px;width:100%'>
 146          <table style='border-bottom:1px solid black;width:100%' cellpadding='0' cellspacing='0'>
 147          <tr>
 148          <td style='vertical-align:top;padding:3px;width:20px'>
 149          {NEWSCATICON}
 150          </td><td style='text-align:left;padding:3px'>
 151          {NEWSTITLELINK=extend}
 152          <br />
 153          {NEWSSUMMARY}
 154          <span class='smalltext'>
 155          {NEWSDATE}
 156          {NEWSCOMMENTS}
 157          </span>
 158          </td><td style='width:55px'>
 159          {NEWSTHUMBNAIL}
 160          </td></tr></table>
 161          </div>\n";
 162  
 163      }
 164      $param['itemlink'] = (defined('NEWSLIST_ITEMLINK')) ? NEWSLIST_ITEMLINK : '';
 165      $param['thumbnail'] =(defined('NEWSLIST_THUMB')) ? NEWSLIST_THUMB : 'border:0px';
 166      $param['catlink']  = (defined('NEWSLIST_CATLINK')) ? NEWSLIST_CATLINK : '';
 167      $param['caticon'] =  (defined('NEWSLIST_CATICON')) ? NEWSLIST_CATICON : ICONSTYLE;
 168      $sql->db_Select_gen($query);
 169      $newsList = $sql->db_getList();
 170      foreach($newsList as $row)
 171      {
 172        $text .= $ix->render_newsitem($row, 'return', '', $NEWSLISTSTYLE, $param);
 173      }
 174  
 175      $amount = ($action == "all") ? NEWSALL_LIMIT : NEWSLIST_LIMIT;
 176  
 177      $icon = ($row['category_icon']) ? "<img src='".e_IMAGE."icons/".$row['category_icon']."' alt='' />" : "";
 178      $parms = $news_total.",".$amount.",".$newsfrom.",".e_SELF.'?'.$action.".".$category.".[FROM]";
 179      $text .= "<div class='nextprev'>".$tp->parseTemplate("{NEXTPREV={$parms}}")."</div>";
 180  
 181      if(!$NEWSLISTTITLE)
 182      {
 183          $NEWSLISTTITLE = LAN_NEWS_82." '".$tp->toHTML($category_name,FALSE,'TITLE')."'";
 184      }
 185      else
 186      {
 187          $NEWSLISTTITLE = str_replace("{NEWSCATEGORY}",$tp->toHTML($category_name,FALSE,'TITLE'),$NEWSLISTTITLE);
 188      }
 189      $text .= "<div style='text-align:center;'><a href='".e_SELF."'>".LAN_NEWS_84."</a></div>";
 190      ob_start();
 191      $ns->tablerender($NEWSLISTTITLE, $text);
 192      $cache_data = ob_get_flush();
 193      setNewsCache($cacheString, $cache_data);
 194      require_once(FOOTERF);
 195      exit;
 196  }
 197  
 198  
 199  
 200  //------------------------------------------------------
 201  //        DISPLAY SINGLE ITEM IN EXTENDED FORMAT HERE
 202  //------------------------------------------------------
 203  if ($action == 'extend') 
 204  {    // --> Cache
 205      if($newsCachedPage = checkCache($cacheString))
 206      {
 207          require_once(HEADERF);
 208          renderCache($newsCachedPage, TRUE);        // This exits if cache used
 209      }
 210      // <-- Cache
 211  
 212      if(isset($pref['trackbackEnabled']) && $pref['trackbackEnabled']) 
 213      {
 214          $query = "SELECT COUNT(tb.trackback_pid) AS tb_count, n.*, u.user_id, u.user_name, u.user_customtitle, nc.category_name, nc.category_icon FROM #news AS n
 215              LEFT JOIN #user AS u ON n.news_author = u.user_id
 216              LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id
 217              LEFT JOIN #trackback AS tb ON tb.trackback_pid  = n.news_id
 218              WHERE n.news_id=".intval($sub_action)." AND n.news_class REGEXP '".e_CLASS_REGEXP."' 
 219              AND NOT (n.news_class REGEXP ".$nobody_regexp.") 
 220              AND n.news_start < ".time()." AND (n.news_end=0 || n.news_end>".time().') ';
 221      }
 222      else
 223      {
 224          $query = "SELECT n.*, u.user_id, u.user_name, u.user_customtitle, nc.category_name, nc.category_icon FROM #news AS n
 225              LEFT JOIN #user AS u ON n.news_author = u.user_id
 226              LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id
 227              WHERE n.news_id=".intval($sub_action)." AND n.news_class REGEXP '".e_CLASS_REGEXP."' 
 228              AND NOT (n.news_class REGEXP ".$nobody_regexp.") 
 229              AND n.news_start < ".time()." AND (n.news_end=0 || n.news_end>".time().") ";
 230      }
 231      if ($sql->db_Select_gen($query))
 232      {
 233          $news = $sql->db_Fetch();
 234          $id = $news['news_category'];        // Use category of this news item to generate next/prev links
 235  
 236          if($news['news_title'])
 237          {
 238            if($pref['meta_news_summary'] && $news['news_title'])
 239            {
 240              define('META_DESCRIPTION',SITENAME.': '.$news['news_title'].' - '.$news['news_summary']);
 241            }
 242            define("e_PAGETITLE",$news['news_title']);
 243          }
 244  
 245          if (TRUE)
 246          {
 247              /* Added by nlStart - show links to previous and next news */
 248              if (!isset($news['news_extended'])) $news['news_extended'] = '';
 249              $news['news_extended'].="<div style='text-align:center;'><a href='".e_SELF."?cat.".$id."'>".LAN_NEWS_85."</a> &nbsp; <a href='".e_SELF."'>".LAN_NEWS_84."</a></div>";
 250              $prev_query = "SELECT news_id, news_title FROM `#news`
 251                  WHERE `news_id` < ".intval($sub_action)." AND `news_category`=".$id." AND `news_class` REGEXP '".e_CLASS_REGEXP."' 
 252                  AND NOT (`news_class` REGEXP ".$nobody_regexp.") 
 253                  AND `news_start` < ".time()." AND (`news_end`=0 || `news_end` > ".time().') ORDER BY `news_id` DESC LIMIT 1';
 254              $sql->db_Select_gen($prev_query);
 255              $prev_news = $sql->db_Fetch();
 256              if ($prev_news)
 257              {
 258                  $news['news_extended'].="<div style='float:right;'><a href='".e_SELF."?extend.".$prev_news['news_id']."'>".LAN_NEWS_86."</a></div>";
 259              }
 260              $next_query = "SELECT news_id, news_title FROM `#news` AS n
 261                  WHERE `news_id` > ".intval($sub_action)." AND `news_category` = ".$id." AND `news_class` REGEXP '".e_CLASS_REGEXP."' 
 262                  AND NOT (`news_class` REGEXP ".$nobody_regexp.") 
 263                  AND `news_start` < ".time()." AND (`news_end`=0 || `news_end` > ".time().') ORDER BY `news_id` ASC LIMIT 1';
 264              $sql->db_Select_gen($next_query);
 265              $next_news = $sql->db_Fetch();
 266              if ($next_news)
 267              {
 268                  $news['news_extended'].="<div style='float:left;'><a href='".e_SELF."?extend.".$next_news['news_id']."'>".LAN_NEWS_87."</a></div>";
 269              }
 270              $news['news_extended'].="<br /><br />";
 271          }
 272          
 273          require_once(HEADERF);
 274          ob_start();
 275          $ix->render_newsitem($news, 'extend');
 276          $cache_data = ob_get_contents();
 277          ob_end_flush();
 278          setNewsCache($cacheString, $cache_data);
 279          require_once(FOOTERF);
 280          exit;
 281      }
 282      else
 283      {
 284          $action = 'default';
 285      }
 286  }
 287  
 288  
 289  //------------------------------------------------------
 290  //            DISPLAY NEWS IN LIST FORMAT HERE
 291  //------------------------------------------------------
 292  // Show title, author, first part of news item...
 293  if (empty($order))
 294  {
 295    $order = 'news_datestamp';
 296  }
 297  $order = $tp -> toDB($order, true);
 298  
 299  $interval = $pref['newsposts'];
 300  
 301  switch ($action)
 302  {
 303    case "list" :
 304      $sub_action = intval($sub_action);
 305      $news_total = $sql->db_Count("news", "(*)", "WHERE news_category={$sub_action} AND news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (news_class REGEXP ".$nobody_regexp.") AND news_start < ".time()." AND (news_end=0 || news_end>".time().")");
 306  //    $query = "SELECT  SQL_CALC_FOUND_ROWS n.*, u.user_id, u.user_name, u.user_customtitle, nc.category_name, nc.category_icon FROM #news AS n
 307      $query = "SELECT  n.*, u.user_id, u.user_name, u.user_customtitle, nc.category_name, nc.category_icon FROM #news AS n
 308          LEFT JOIN #user AS u ON n.news_author = u.user_id
 309          LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id
 310          WHERE n.news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (n.news_class REGEXP ".$nobody_regexp.") 
 311          AND n.news_start < ".time()." AND (n.news_end=0 || n.news_end>".time().") 
 312          AND n.news_category={$sub_action} 
 313          ORDER BY n.news_sticky DESC,".$order." DESC LIMIT ".intval($newsfrom).",".ITEMVIEW;
 314      break;
 315  
 316  
 317    case "item" :
 318      $sub_action = intval($sub_action);
 319      $news_total = 1;
 320      if(isset($pref['trackbackEnabled']) && $pref['trackbackEnabled']) 
 321      {
 322        $query = "SELECT COUNT(tb.trackback_pid) AS tb_count, n.*, u.user_id, u.user_name, u.user_customtitle, nc.category_name, nc.category_icon FROM #news AS n
 323          LEFT JOIN #user AS u ON n.news_author = u.user_id
 324          LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id
 325          LEFT JOIN #trackback AS tb ON tb.trackback_pid  = n.news_id
 326          WHERE n.news_id={$sub_action} AND n.news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (n.news_class REGEXP ".$nobody_regexp.") 
 327          AND n.news_start < ".time()." AND (n.news_end=0 || n.news_end>".time().")
 328          GROUP by n.news_id";
 329      }
 330      else
 331      { 
 332        $query = "SELECT n.*, u.user_id, u.user_name, u.user_customtitle, nc.category_name, nc.category_icon FROM #news AS n
 333          LEFT JOIN #user AS u ON n.news_author = u.user_id
 334          LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id
 335          WHERE n.news_id={$sub_action} AND n.news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (n.news_class REGEXP ".$nobody_regexp.") 
 336          AND n.news_start < ".time()." AND (n.news_end=0 || n.news_end>".time().")";
 337      }
 338      break;
 339  
 340    case "month" :
 341    case "day" :
 342      $item = $tp -> toDB($sub_action).'20000101';
 343      $year = substr($item, 0, 4);
 344      $month = substr($item, 4,2);
 345      if ($action == 'day')
 346      {
 347        $day = substr($item, 6, 2);
 348        $lastday = $day;
 349      }
 350      else
 351      {    // A month's worth
 352        $day = 1;
 353        $lastday = date("t", $startdate);
 354      }
 355      $startdate = mktime(0, 0, 0, $month, $day, $year);
 356      $enddate = mktime(23, 59, 59, $month, $lastday, $year);
 357      $query = "SELECT n.*, u.user_id, u.user_name, u.user_customtitle, nc.category_name, nc.category_icon FROM #news AS n
 358          LEFT JOIN #user AS u ON n.news_author = u.user_id
 359          LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id
 360          WHERE n.news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (n.news_class REGEXP ".$nobody_regexp.") 
 361          AND n.news_start < ".time()." AND (n.news_end=0 || n.news_end>".time().") 
 362          AND n.news_render_type<2 AND n.news_datestamp > {$startdate} AND n.news_datestamp < {$enddate} 
 363          ORDER BY ".$order." DESC LIMIT ".intval($newsfrom).",".ITEMVIEW;
 364  
 365      $news_total = $sql->db_Count("news", "(*)", "WHERE n.news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (n.news_class REGEXP ".$nobody_regexp.") 
 366          AND n.news_start < ".time()." AND (n.news_end=0 || n.news_end>".time().") 
 367          AND n.news_render_type<2 AND n.news_datestamp > {$startdate} AND n.news_datestamp < {$enddate}");
 368      break;
 369  
 370    case 'default' :
 371    default :
 372      $action = '';
 373      $cacheString = 'news.php_default_';        // Make sure its sensible
 374      $news_total = $sql->db_Count("news", "(*)", "WHERE news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (news_class REGEXP ".$nobody_regexp.") AND news_start < ".time()." AND (news_end=0 || news_end>".time().") AND news_render_type<2" );
 375  
 376      if(!isset($pref['newsposts_archive']))
 377      {
 378          $pref['newsposts_archive'] = 0;
 379      }
 380      $interval = $pref['newsposts']-$pref['newsposts_archive'];        // Number of 'full' posts to show
 381  
 382      // Get number of news item to show
 383      if(isset($pref['trackbackEnabled']) && $pref['trackbackEnabled']) 
 384      {
 385          $query = "SELECT COUNT(tb.trackback_pid) AS tb_count, n.*, u.user_id, u.user_name, u.user_customtitle, nc.category_name, nc.category_icon, COUNT(*) AS tbcount FROM #news AS n
 386          LEFT JOIN #user AS u ON n.news_author = u.user_id
 387          LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id
 388          LEFT JOIN #trackback AS tb ON tb.trackback_pid  = n.news_id
 389          WHERE n.news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (n.news_class REGEXP ".$nobody_regexp.")
 390          AND n.news_start < ".time()." AND (n.news_end=0 || n.news_end>".time().")
 391          AND n.news_render_type<2
 392          GROUP by n.news_id
 393          ORDER BY news_sticky DESC, ".$order." DESC LIMIT ".intval($newsfrom).",".$pref['newsposts'];
 394      }
 395      else
 396      {
 397          $query = "SELECT n.*, u.user_id, u.user_name, u.user_customtitle, nc.category_name, nc.category_icon FROM #news AS n
 398          LEFT JOIN #user AS u ON n.news_author = u.user_id
 399          LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id
 400          WHERE n.news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (n.news_class REGEXP ".$nobody_regexp.")
 401          AND n.news_start < ".time()." AND (n.news_end=0 || n.news_end>".time().")
 402          AND n.news_render_type<2
 403          ORDER BY n.news_sticky DESC, ".$order." DESC LIMIT ".intval($newsfrom).",".$pref['newsposts'];
 404      }
 405  }    // END - switch($action)
 406  
 407  
 408  if($newsCachedPage = checkCache($cacheString)) // normal news front-page - with cache.
 409  {
 410      require_once(HEADERF);
 411  
 412      if(!$action)
 413      {
 414          if (isset($pref['fb_active']))
 415          {
 416              require_once(e_PLUGIN."featurebox/featurebox.php");
 417          }
 418          if (isset($pref['nfp_display']) && $pref['nfp_display'] == 1)
 419          {
 420              require_once(e_PLUGIN."newforumposts_main/newforumposts_main.php");
 421          }
 422  
 423      }
 424  
 425      //news archive
 426      if ($action != "item" && $action != 'list' && $pref['newsposts_archive']) {
 427          if ($sql->db_Select_gen($query)) {
 428              $newsAr = $sql -> db_getList();
 429              if($newsarchive = checkCache('newsarchive')){
 430                  $newsCachedPage = $newsCachedPage.$newsarchive;
 431              }else{
 432                  show_newsarchive($newsAr,$interval);
 433              }
 434          }
 435      }
 436      renderCache($newsCachedPage, TRUE);
 437  }
 438  
 439  
 440  //if (!($news_total = $sql->db_Select_gen($query))) 
 441  if (!$sql->db_Select_gen($query))
 442  {  // No news items
 443    require_once(HEADERF);
 444    echo "<br /><br /><div style='text-align:center'><b>".(strstr(e_QUERY, "month") ? LAN_NEWS_462 : LAN_NEWS_83)."</b></div><br /><br />";
 445    require_once(FOOTERF);
 446    exit;
 447  } 
 448  
 449  $newsAr = $sql -> db_getList();
 450  
 451  
 452  $p_title = ($action == "item") ? $newsAr[1]['news_title'] : $tp->toHTML($newsAr[1]['category_name'],FALSE,'TITLE');
 453  
 454  if($action != "" && !is_numeric($action))
 455  {
 456      if($action == "item" && $pref['meta_news_summary'] && $newsAr[1]['news_title'])
 457      {
 458        define("META_DESCRIPTION",SITENAME.": ".$newsAr[1]['news_title']." - ".$newsAr[1]['news_summary']);
 459      }
 460      define("e_PAGETITLE", $p_title);
 461  }
 462  
 463  require_once(HEADERF);
 464  if(!$action)
 465  {
 466      if (isset($pref['fb_active'])){   // --->feature box
 467          require_once(e_PLUGIN."featurebox/featurebox.php");
 468      }
 469  
 470      if (isset($pref['nfp_display']) && $pref['nfp_display'] == 1){
 471          require_once(e_PLUGIN."newforumposts_main/newforumposts_main.php");
 472      }
 473  }
 474  
 475  if(isset($pref['news_unstemplate']) && $pref['news_unstemplate'] && file_exists(THEME."news_template.php")) 
 476  {
 477      // theme specific template required ...
 478      require_once(THEME."news_template.php");
 479  
 480      if($ALTERNATECLASS1)
 481      {
 482        return TRUE;
 483      }
 484  
 485      $newscolumns = (isset($NEWSCOLUMNS) ? $NEWSCOLUMNS : 1);
 486      $newspercolumn = (isset($NEWSITEMSPERCOLUMN) ? $NEWSITEMSPERCOLUMN : 10);
 487      $newsdata = array();
 488      $loop = 1;
 489      foreach($newsAr as $news) {
 490  
 491          if(is_array($ALTERNATECLASSES)) {
 492              $newsdata[$loop] .= "<div class='{$ALTERNATECLASSES[0]}'>".$ix->render_newsitem($news, "return")."</div>";
 493              $ALTERNATECLASSES = array_reverse($ALTERNATECLASSES);
 494          } else {
 495              $newsdata[$loop] .= $ix->render_newsitem($news, "return");
 496          }
 497          $loop ++;
 498          if($loop > $newscolumns) {
 499              $loop = 1;
 500          }
 501      }
 502      $loop = 1;
 503      foreach($newsdata as $data) {
 504          $var = "ITEMS{$loop}";
 505          $$var = $data;
 506          $loop ++;
 507      }
 508      $text = preg_replace("/\{(.*?)\}/e", '$\1', $NEWSCLAYOUT);
 509  
 510      require_once(HEADERF);
 511      $parms = $news_total.",".ITEMVIEW.",".$newsfrom.",".e_SELF.'?'.($action ? $action : 'default' ).($sub_action ? ".".$sub_action : ".0").".[FROM]";
 512      $nextprev = $tp->parseTemplate("{NEXTPREV={$parms}}");
 513      $text .= ($nextprev ? "<div class='nextprev'>".$nextprev."</div>" : "");
 514  //    $text=''.$text.'<center>'.$nextprev.'</center>';
 515     
 516      echo $text;
 517      setNewsCache($cacheString, $text);
 518  } 
 519  else 
 520  {
 521      ob_start();
 522  
 523      $newpostday = 0;
 524      $thispostday = 0;
 525      $pref['newsHeaderDate'] = 1;
 526      $gen = new convert();
 527  
 528      if (!defined("DATEHEADERCLASS")) {
 529          define("DATEHEADERCLASS", "nextprev");
 530          // if not defined in the theme, default class nextprev will be used for new date header
 531      }
 532  
 533      // #### normal newsitems, rendered via render_newsitem(), the $query is changed above (no other changes made) ---------
 534  
 535      $i= 1;
 536      while(isset($newsAr[$i]) && $i <= $interval) {
 537          $news = $newsAr[$i];
 538          //        render new date header if pref selected ...
 539          $thispostday = strftime("%j", $news['news_datestamp']);
 540          if ($newpostday != $thispostday && (isset($pref['news_newdateheader']) && $pref['news_newdateheader'])) 
 541          {
 542            echo "<div class='".DATEHEADERCLASS."'>".strftime("%A %d %B %Y", $news['news_datestamp'])."</div>";
 543          }
 544          $newpostday = $thispostday;
 545          $news['category_id'] = $news['news_category'];
 546          if ($action == "item") 
 547          {
 548            unset($news['news_render_type']);
 549          }
 550  
 551          $ix->render_newsitem($news);
 552          $i++;
 553      }
 554      $parms = $news_total.",".ITEMVIEW.",".$newsfrom.",".e_SELF.'?'.($action ? $action : 'default' ).($sub_action ? ".".$sub_action : ".0").".[FROM]";
 555      $nextprev = $tp->parseTemplate("{NEXTPREV={$parms}}");
 556       echo ($nextprev ? "<div class='nextprev'>".$nextprev."</div>" : "");
 557  
 558      $cache_data = ob_get_clean();
 559      require_once(HEADERF);
 560      echo $cache_data;
 561      setNewsCache($cacheString, $cache_data);
 562  }
 563  
 564  // ##### --------------------------------------------------------------------------------------------------------------
 565  
 566  function show_newsarchive($newsAr, $i = 1)
 567  {
 568      global $ns, $gen, $pref, $tp, $news_archive_shortcodes, $NEWSARCHIVE, $news2;
 569  
 570      // do not show the news archive on the news.php?item.X page (but only on the news mainpage)
 571      require_once(e_FILE.'shortcode/batch/news_archives.php');
 572  
 573      $textnewsarchive = '';
 574      ob_start();
 575  
 576      $i++;            // First entry to show
 577      while(isset($newsAr[$i]))
 578      {
 579          $news2 = $newsAr[$i];
 580          // Code from Lisa
 581          // copied from the rss creation, but added here to make sure the url for the newsitem is to the news.php?item.X
 582          // instead of the actual hyperlink that may have been added to a newstitle on creation
 583          $search = array();
 584          $replace = array();
 585          $search[0] = "/\<a href=\"(.*?)\">(.*?)<\/a>/si";
 586          $replace[0] = '\\2';
 587          $search[1] = "/\<a href='(.*?)'>(.*?)<\/a>/si";
 588          $replace[1] = '\\2';
 589          $search[2] = "/\<a href='(.*?)'>(.*?)<\/a>/si";
 590          $replace[2] = '\\2';
 591          $search[3] = "/\<a href=&quot;(.*?)&quot;>(.*?)<\/a>/si";
 592          $replace[3] = '\\2';
 593          $search[4] = "/\<a href=&#39;(.*?)&#39;>(.*?)<\/a>/si";
 594          $replace[4] = '\\2';
 595          $news2['news_title'] = preg_replace($search, $replace, $news2['news_title']);
 596          // End of code from Lisa
 597  
 598          $gen = new convert;
 599          $news2['news_datestamp'] = $gen->convert_date($news2['news_datestamp'], "short");
 600  
 601  
 602          if(!$NEWSARCHIVE){
 603              $NEWSARCHIVE ="<div>
 604                      <table style='width:98%;'>
 605                      <tr>
 606                      <td>
 607                      <div>{ARCHIVE_BULLET} <b>{ARCHIVE_LINK}</b> <span class='smalltext'><i>{ARCHIVE_AUTHOR} @ ({ARCHIVE_DATESTAMP}) ({ARCHIVE_CATEGORY})</i></span></div>
 608                      </td>
 609                      </tr>
 610                      </table>
 611                      </div>";
 612          }
 613  
 614          $textnewsarchive .= $tp->parseTemplate($NEWSARCHIVE, FALSE, $news_archive_shortcodes);
 615          $i++;
 616      }
 617      $ns->tablerender($pref['newsposts_archive_title'], $textnewsarchive, 'news_archive');
 618      $newsarchive = ob_get_contents();
 619      ob_end_flush(); // dump collected data
 620      setNewsCache('newsarchive', $newsarchive);
 621  }
 622  
 623  // #### new: news archive ---------------------------------------------------------------------------------------------
 624  if ($action != "item" && $action != 'list' && $pref['newsposts_archive']) 
 625  {
 626    show_newsarchive($newsAr,$interval);
 627  }
 628  // #### END -----------------------------------------------------------------------------------------------------------
 629  
 630  if ($action != "item") {
 631      if (is_numeric($action)){
 632          $action = "";
 633      }
 634   //    $parms = $news_total.",".ITEMVIEW.",".$newsfrom.",".e_SELF.'?'."[FROM].".$action.(isset($sub_action) ? ".".$sub_action : "");
 635   //    $nextprev = $tp->parseTemplate("{NEXTPREV={$parms}}");
 636   //    echo ($nextprev ? "<div class='nextprev'>".$nextprev."</div>" : "");
 637  }
 638  
 639  if(is_dir("remotefile")) {
 640      require_once(e_HANDLER."file_class.php");
 641      $file = new e_file;
 642      $reject = array('$.','$..','/','CVS','thumbs.db','*._$', 'index', 'null*', 'Readme.txt');
 643      $crem = $file -> get_files(e_BASE."remotefile", "", $reject);
 644      if(count($crem)) {
 645          foreach($crem as $loadrem) {
 646              if(strstr($loadrem['fname'], "load_")) {
 647                  require_once(e_BASE."remotefile/".$loadrem['fname']);
 648              }
 649          }
 650      }
 651  }
 652  
 653  if (isset($pref['nfp_display']) && $pref['nfp_display'] == 2) {
 654      require_once(e_PLUGIN."newforumposts_main/newforumposts_main.php");
 655  }
 656  
 657  render_newscats();
 658  
 659  require_once(FOOTERF);
 660  
 661  
 662  // =========================================================================
 663  function setNewsCache($cache_tag, $cache_data) {
 664      global $e107cache;
 665      $e107cache->set($cache_tag, $cache_data);
 666      $e107cache->set($cache_tag."_title", defined("e_PAGETITLE") ? e_PAGETITLE : '');
 667      $e107cache->set($cache_tag."_diz", defined("META_DESCRIPTION") ? META_DESCRIPTION : '');
 668  }
 669  
 670  function checkCache($cacheString){
 671      global $pref,$e107cache;
 672      $cache_data = $e107cache->retrieve($cacheString);
 673      $cache_title = $e107cache->retrieve($cacheString."_title");
 674      $cache_diz = $e107cache->retrieve($cacheString."_diz");
 675      $etitle = ($cache_title != "e_PAGETITLE") ? $cache_title : "";
 676      $ediz = ($cache_diz != "META_DESCRIPTION") ? $cache_diz : "";
 677      if($etitle){
 678          define(e_PAGETITLE,$etitle);
 679      }
 680      if($ediz){
 681          define("META_DESCRIPTION",$ediz);
 682      }
 683      if ($cache_data) {
 684          return $cache_data;
 685      } else {
 686          return false;
 687      }
 688  }
 689  
 690  function renderCache($cache, $nfp = FALSE){
 691      global $pref,$tp,$sql,$CUSTOMFOOTER, $FOOTER,$cust_footer,$ph;
 692      global $db_debug,$ns,$eTraffic,$eTimingStart, $error_handler, $db_time, $sql2, $mySQLserver, $mySQLuser, $mySQLpassword, $mySQLdefaultdb,$e107;
 693      echo $cache;
 694      if (isset($nfp) && isset($pref['nfp_display']) && $pref['nfp_display'] == 2) {
 695          require_once(e_PLUGIN."newforumposts_main/newforumposts_main.php");
 696      }
 697      render_newscats();
 698      require_once(FOOTERF);
 699      exit;
 700  }
 701  
 702  function render_newscats(){  // --  CNN Style Categories. ----
 703      global $pref,$ns,$tp;
 704      if (isset($pref['news_cats']) && $pref['news_cats'] == '1') {
 705          $text3 = $tp->toHTML("{NEWS_CATEGORIES}", TRUE, 'parse_sc,nobreak,emotes_off,no_make_clickable');
 706          $ns->tablerender(LAN_NEWS_23, $text3, 'news_cat');
 707      }
 708  }
 709  
 710  ?>


Generated: Tue Aug 3 00:19:13 2010
Open Source related documentation for developers.