[ Index ]

PHP Cross Reference of e107 v1


title

Body

[close]

/ -> news.php (source)

   1  <?php
   2  /*
   3  + ----------------------------------------------------------------------------+
   4  |     e107 website system
   5  |
   6  |     Copyright (C) 2001-2002 Steve Dunstan (jalist@e107.org)
   7  |     Copyright (C) 2008-2010 e107 Inc (e107.org)
   8  |
   9  |
  10  |     Released under the terms and conditions of the
  11  |     GNU General Public License (http://gnu.org).
  12  |
  13  |     $URL: https://e107.svn.sourceforge.net/svnroot/e107/trunk/e107_0.7/news.php $
  14  |     $Revision: 12324 $
  15  |     $Id: news.php 12324 2011-07-23 21:02:44Z e107coders $
  16  |     $Author: e107coders $
  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  unset($tmp);
  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                  setNewsMeta('extend',$news);
 241            }
 242            
 243            define("e_PAGETITLE",$news['news_title']);
 244          }
 245  
 246          if (TRUE)
 247          {
 248              /* Added by nlStart - show links to previous and next news */
 249              if (!isset($news['news_extended'])) $news['news_extended'] = '';
 250              
 251              $news['news_extended'].="<div style='text-align:center;'><a class='news-extended-category-link' href='".e_SELF."?cat.".$id."'>".LAN_NEWS_85."</a> &nbsp; <a class='news-extended-overview-link' href='".e_SELF."'>".LAN_NEWS_84."</a></div>";
 252              
 253              $prev_query = "SELECT news_id, news_title FROM `#news`
 254                  WHERE `news_id` < ".intval($sub_action)." AND `news_category`=".$id." AND `news_class` REGEXP '".e_CLASS_REGEXP."' 
 255                  AND NOT (`news_class` REGEXP ".$nobody_regexp.") 
 256                  AND `news_start` < ".time()." AND (`news_end`=0 || `news_end` > ".time().') ORDER BY `news_id` DESC LIMIT 1';
 257              
 258              $sql->db_Select_gen($prev_query);
 259              $prev_news = $sql->db_Fetch();
 260              
 261              if ($prev_news)
 262              {
 263                  $news['news_extended'].="<div class='news-extended-older' style='float:left;'><a class='news-extended-older' href='".e_SELF."?extend.".$prev_news['news_id']."'>".LAN_NEWS_86."</a></div>";
 264              }
 265              
 266              $next_query = "SELECT news_id, news_title FROM `#news` AS n
 267                  WHERE `news_id` > ".intval($sub_action)." AND `news_category` = ".$id." AND `news_class` REGEXP '".e_CLASS_REGEXP."' 
 268                  AND NOT (`news_class` REGEXP ".$nobody_regexp.") 
 269                  AND `news_start` < ".time()." AND (`news_end`=0 || `news_end` > ".time().') ORDER BY `news_id` ASC LIMIT 1';
 270              
 271              $sql->db_Select_gen($next_query);
 272              $next_news = $sql->db_Fetch();
 273              
 274              if ($next_news)
 275              {
 276                  $news['news_extended'].="<div class='news-extended-newer' style='float:right;'><a class='news-extended-newer' href='".e_SELF."?extend.".$next_news['news_id']."'>".LAN_NEWS_87."</a></div>";
 277              }
 278              $news['news_extended'].="<br /><br />";
 279          }
 280          
 281          require_once(HEADERF);
 282          ob_start();
 283          $ix->render_newsitem($news, 'extend');
 284          $cache_data = ob_get_contents();
 285          ob_end_flush();
 286          setNewsCache($cacheString, $cache_data);
 287          require_once(FOOTERF);
 288          exit;
 289      }
 290      else
 291      {
 292          $action = 'default';
 293      }
 294  }
 295  
 296  
 297  //------------------------------------------------------
 298  //            DISPLAY NEWS IN LIST FORMAT HERE
 299  //------------------------------------------------------
 300  // Show title, author, first part of news item...
 301  if (empty($order))
 302  {
 303    $order = 'news_datestamp';
 304  }
 305  $order = $tp -> toDB($order, true);
 306  
 307  $interval = $pref['newsposts'];
 308  
 309  switch ($action)
 310  {
 311    case "list" :
 312      $sub_action = intval($sub_action);
 313      $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().")");
 314  //    $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
 315      $query = "SELECT  n.*, u.user_id, u.user_name, u.user_customtitle, nc.category_name, nc.category_icon FROM #news AS n
 316          LEFT JOIN #user AS u ON n.news_author = u.user_id
 317          LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id
 318          WHERE n.news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (n.news_class REGEXP ".$nobody_regexp.") 
 319          AND n.news_start < ".time()." AND (n.news_end=0 || n.news_end>".time().") 
 320          AND n.news_category={$sub_action} 
 321          ORDER BY n.news_sticky DESC,".$order." DESC LIMIT ".intval($newsfrom).",".ITEMVIEW;
 322      break;
 323  
 324  
 325    case "item" :
 326      $sub_action = intval($sub_action);
 327      $news_total = 1;
 328      if(isset($pref['trackbackEnabled']) && $pref['trackbackEnabled']) 
 329      {
 330        $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
 331          LEFT JOIN #user AS u ON n.news_author = u.user_id
 332          LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id
 333          LEFT JOIN #trackback AS tb ON tb.trackback_pid  = n.news_id
 334          WHERE n.news_id={$sub_action} AND n.news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (n.news_class REGEXP ".$nobody_regexp.") 
 335          AND n.news_start < ".time()." AND (n.news_end=0 || n.news_end>".time().")
 336          GROUP by n.news_id";
 337      }
 338      else
 339      { 
 340        $query = "SELECT n.*, u.user_id, u.user_name, u.user_customtitle, nc.category_name, nc.category_icon FROM #news AS n
 341          LEFT JOIN #user AS u ON n.news_author = u.user_id
 342          LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id
 343          WHERE n.news_id={$sub_action} AND n.news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (n.news_class REGEXP ".$nobody_regexp.") 
 344          AND n.news_start < ".time()." AND (n.news_end=0 || n.news_end>".time().")";
 345      }
 346      break;
 347  
 348    case "month" :
 349    case "day" :
 350      $item = $tp -> toDB($sub_action).'20000101';
 351      $year = substr($item, 0, 4);
 352      $month = substr($item, 4,2);
 353      if ($action == 'day')
 354      {
 355        $day = substr($item, 6, 2);
 356        $lastday = $day;
 357      }
 358      else
 359      {    // A month's worth
 360        $day = 1;
 361        $lastday = date("t", $startdate);
 362      }
 363      $startdate = mktime(0, 0, 0, $month, $day, $year);
 364      $enddate = mktime(23, 59, 59, $month, $lastday, $year);
 365      $query = "SELECT n.*, u.user_id, u.user_name, u.user_customtitle, nc.category_name, nc.category_icon FROM #news AS n
 366          LEFT JOIN #user AS u ON n.news_author = u.user_id
 367          LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id
 368          WHERE n.news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (n.news_class REGEXP ".$nobody_regexp.") 
 369          AND n.news_start < ".time()." AND (n.news_end=0 || n.news_end>".time().") 
 370          AND n.news_render_type<2 AND n.news_datestamp > {$startdate} AND n.news_datestamp < {$enddate} 
 371          ORDER BY ".$order." DESC LIMIT ".intval($newsfrom).",".ITEMVIEW;
 372  
 373      $news_total = $sql->db_Count("news AS n", "(*)", "WHERE n.news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (n.news_class REGEXP ".$nobody_regexp.") 
 374          AND n.news_start < ".time()." AND (n.news_end=0 || n.news_end>".time().") 
 375          AND n.news_render_type<2 AND n.news_datestamp > {$startdate} AND n.news_datestamp < {$enddate}");
 376      break;
 377  
 378    case 'default' :
 379    default :
 380      $action = '';
 381      $cacheString = 'news.php_default_';        // Make sure its sensible
 382      $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" );
 383  
 384      if(!isset($pref['newsposts_archive']))
 385      {
 386          $pref['newsposts_archive'] = 0;
 387      }
 388      $interval = $pref['newsposts']-$pref['newsposts_archive'];        // Number of 'full' posts to show
 389  
 390      // Get number of news item to show
 391      if(isset($pref['trackbackEnabled']) && $pref['trackbackEnabled']) 
 392      {
 393          $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
 394          LEFT JOIN #user AS u ON n.news_author = u.user_id
 395          LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id
 396          LEFT JOIN #trackback AS tb ON tb.trackback_pid  = n.news_id
 397          WHERE n.news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (n.news_class REGEXP ".$nobody_regexp.")
 398          AND n.news_start < ".time()." AND (n.news_end=0 || n.news_end>".time().")
 399          AND n.news_render_type<2
 400          GROUP by n.news_id
 401          ORDER BY news_sticky DESC, ".$order." DESC LIMIT ".intval($newsfrom).",".$pref['newsposts'];
 402      }
 403      else
 404      {
 405          $query = "SELECT n.*, u.user_id, u.user_name, u.user_customtitle, nc.category_name, nc.category_icon FROM #news AS n
 406          LEFT JOIN #user AS u ON n.news_author = u.user_id
 407          LEFT JOIN #news_category AS nc ON n.news_category = nc.category_id
 408          WHERE n.news_class REGEXP '".e_CLASS_REGEXP."' AND NOT (n.news_class REGEXP ".$nobody_regexp.")
 409          AND n.news_start < ".time()." AND (n.news_end=0 || n.news_end>".time().")
 410          AND n.news_render_type<2
 411          ORDER BY n.news_sticky DESC, ".$order." DESC LIMIT ".intval($newsfrom).",".$pref['newsposts'];
 412      }
 413  }    // END - switch($action)
 414  
 415  
 416  if($newsCachedPage = checkCache($cacheString)) // normal news front-page - with cache.
 417  {
 418      require_once(HEADERF);
 419  
 420      if(!$action)
 421      {
 422          if (isset($pref['fb_active']))
 423          {
 424              require_once(e_PLUGIN."featurebox/featurebox.php");
 425          }
 426          if (isset($pref['nfp_display']) && $pref['nfp_display'] == 1)
 427          {
 428              require_once(e_PLUGIN."newforumposts_main/newforumposts_main.php");
 429          }
 430  
 431      }
 432  
 433      //news archive
 434      if ($action != "item" && $action != 'list' && $pref['newsposts_archive']) {
 435          if ($sql->db_Select_gen($query)) {
 436              $newsAr = $sql -> db_getList();
 437              if($newsarchive = checkCache('newsarchive')){
 438                  $newsCachedPage = $newsCachedPage.$newsarchive;
 439              }else{
 440                  show_newsarchive($newsAr,$interval);
 441              }
 442          }
 443      }
 444      renderCache($newsCachedPage, TRUE);
 445  }
 446  
 447  
 448  //if (!($news_total = $sql->db_Select_gen($query))) 
 449  if (!$sql->db_Select_gen($query))
 450  {  // No news items
 451    require_once(HEADERF);
 452    echo "<br /><br /><div style='text-align:center'><b>".(strstr(e_QUERY, "month") ? LAN_NEWS_462 : LAN_NEWS_83)."</b></div><br /><br />";
 453    require_once(FOOTERF);
 454    exit;
 455  } 
 456  
 457  $newsAr = $sql -> db_getList();
 458  
 459  
 460  $p_title = ($action == "item") ? $newsAr[1]['news_title'] : $tp->toHTML($newsAr[1]['category_name'],FALSE,'TITLE');
 461  
 462  if($action != "" && !is_numeric($action))
 463  {
 464      if($action == "item" && $pref['meta_news_summary'] && $newsAr[1]['news_title'])
 465      {
 466          setNewsMeta('item',$newsAr[1]);
 467          // define("META_DESCRIPTION",SITENAME.": ".$newsAr[1]['news_title']." - ".$newsAr[1]['news_summary']);
 468      }
 469      define("e_PAGETITLE", $p_title);
 470  }
 471  
 472  require_once(HEADERF);
 473  if(!$action)
 474  {
 475      if (isset($pref['fb_active'])){   // --->feature box
 476          require_once(e_PLUGIN."featurebox/featurebox.php");
 477      }
 478  
 479      if (isset($pref['nfp_display']) && $pref['nfp_display'] == 1){
 480          require_once(e_PLUGIN."newforumposts_main/newforumposts_main.php");
 481      }
 482  }
 483  
 484  if(isset($pref['news_unstemplate']) && $pref['news_unstemplate'] && file_exists(THEME."news_template.php")) 
 485  {
 486      // theme specific template required ...
 487      require_once(THEME."news_template.php");
 488  
 489      if($ALTERNATECLASS1)
 490      {
 491        return TRUE;
 492      }
 493  
 494      $newscolumns = (isset($NEWSCOLUMNS) ? $NEWSCOLUMNS : 1);
 495      $newspercolumn = (isset($NEWSITEMSPERCOLUMN) ? $NEWSITEMSPERCOLUMN : 10);
 496      $newsdata = array();
 497      $loop = 1;
 498      foreach($newsAr as $news) {
 499  
 500          if(is_array($ALTERNATECLASSES)) {
 501              $newsdata[$loop] .= "<div class='{$ALTERNATECLASSES[0]}'>".$ix->render_newsitem($news, "return")."</div>";
 502              $ALTERNATECLASSES = array_reverse($ALTERNATECLASSES);
 503          } else {
 504              $newsdata[$loop] .= $ix->render_newsitem($news, "return");
 505          }
 506          $loop ++;
 507          if($loop > $newscolumns) {
 508              $loop = 1;
 509          }
 510      }
 511      $loop = 1;
 512      foreach($newsdata as $data) {
 513          $var = "ITEMS{$loop}";
 514          $$var = $data;
 515          $loop ++;
 516      }
 517      $text = preg_replace("/\{(.*?)\}/e", '$\1', $NEWSCLAYOUT);
 518  
 519      require_once(HEADERF);
 520      $sub_action = intval($sub_action);
 521      $parms = $news_total.",".ITEMVIEW.",".$newsfrom.",".e_SELF.'?'.($action ? $action : 'default' ).($sub_action ? ".".$sub_action : ".0").".[FROM]";
 522      $nextprev = $tp->parseTemplate("{NEXTPREV={$parms}}");
 523      $text .= ($nextprev ? "<div class='nextprev'>".$nextprev."</div>" : "");
 524  //    $text=''.$text.'<center>'.$nextprev.'</center>';
 525     
 526      echo $text;
 527      setNewsCache($cacheString, $text);
 528  } 
 529  else 
 530  {
 531      ob_start();
 532  
 533      $newpostday = 0;
 534      $thispostday = 0;
 535      $pref['newsHeaderDate'] = 1;
 536      $gen = new convert();
 537  
 538      if (!defined("DATEHEADERCLASS")) {
 539          define("DATEHEADERCLASS", "nextprev");
 540          // if not defined in the theme, default class nextprev will be used for new date header
 541      }
 542  
 543      // #### normal newsitems, rendered via render_newsitem(), the $query is changed above (no other changes made) ---------
 544  
 545      $i= 1;
 546      while(isset($newsAr[$i]) && $i <= $interval) {
 547          $news = $newsAr[$i];
 548          //        render new date header if pref selected ...
 549          $thispostday = strftime("%j", $news['news_datestamp']);
 550          if ($newpostday != $thispostday && (isset($pref['news_newdateheader']) && $pref['news_newdateheader'])) 
 551          {
 552            echo "<div class='".DATEHEADERCLASS."'>".strftime("%A %d %B %Y", $news['news_datestamp'])."</div>";
 553          }
 554          $newpostday = $thispostday;
 555          $news['category_id'] = $news['news_category'];
 556          if ($action == "item") 
 557          {
 558            unset($news['news_render_type']);
 559          }
 560  
 561          $ix->render_newsitem($news);
 562          $i++;
 563      }
 564      $sub_action = intval($sub_action);
 565      $parms = $news_total.",".ITEMVIEW.",".$newsfrom.",".e_SELF.'?'.($action ? $action : 'default' ).($sub_action ? ".".$sub_action : ".0").".[FROM]";
 566      $nextprev = $tp->parseTemplate("{NEXTPREV={$parms}}");
 567       echo ($nextprev ? "<div class='nextprev'>".$nextprev."</div>" : "");
 568  
 569      $cache_data = ob_get_clean();
 570      require_once(HEADERF);
 571      echo $cache_data;
 572      setNewsCache($cacheString, $cache_data);
 573  }
 574  
 575  // ##### --------------------------------------------------------------------------------------------------------------
 576  
 577  function show_newsarchive($newsAr, $i = 1)
 578  {
 579      global $ns, $gen, $pref, $tp, $news_archive_shortcodes, $NEWSARCHIVE, $news2;
 580  
 581      // do not show the news archive on the news.php?item.X page (but only on the news mainpage)
 582      require_once(e_FILE.'shortcode/batch/news_archives.php');
 583  
 584      $textnewsarchive = '';
 585      ob_start();
 586  
 587      $i++;            // First entry to show
 588      while(isset($newsAr[$i]))
 589      {
 590          $news2 = $newsAr[$i];
 591          // Code from Lisa
 592          // copied from the rss creation, but added here to make sure the url for the newsitem is to the news.php?item.X
 593          // instead of the actual hyperlink that may have been added to a newstitle on creation
 594          $search = array();
 595          $replace = array();
 596          $search[0] = "/\<a href=\"(.*?)\">(.*?)<\/a>/si";
 597          $replace[0] = '\\2';
 598          $search[1] = "/\<a href='(.*?)'>(.*?)<\/a>/si";
 599          $replace[1] = '\\2';
 600          $search[2] = "/\<a href='(.*?)'>(.*?)<\/a>/si";
 601          $replace[2] = '\\2';
 602          $search[3] = "/\<a href=&quot;(.*?)&quot;>(.*?)<\/a>/si";
 603          $replace[3] = '\\2';
 604          $search[4] = "/\<a href=&#39;(.*?)&#39;>(.*?)<\/a>/si";
 605          $replace[4] = '\\2';
 606          $news2['news_title'] = preg_replace($search, $replace, $news2['news_title']);
 607          // End of code from Lisa
 608  
 609          $gen = new convert;
 610          $news2['news_datestamp'] = $gen->convert_date($news2['news_datestamp'], "short");
 611  
 612  
 613          if(!$NEWSARCHIVE){
 614              $NEWSARCHIVE ="<div>
 615                      <table style='width:98%;'>
 616                      <tr>
 617                      <td>
 618                      <div>{ARCHIVE_BULLET} <b>{ARCHIVE_LINK}</b> <span class='smalltext'><i>{ARCHIVE_AUTHOR} @ ({ARCHIVE_DATESTAMP}) ({ARCHIVE_CATEGORY})</i></span></div>
 619                      </td>
 620                      </tr>
 621                      </table>
 622                      </div>";
 623          }
 624  
 625          $textnewsarchive .= $tp->parseTemplate($NEWSARCHIVE, FALSE, $news_archive_shortcodes);
 626          $i++;
 627      }
 628      $ns->tablerender($pref['newsposts_archive_title'], $textnewsarchive, 'news_archive');
 629      $newsarchive = ob_get_contents();
 630      ob_end_flush(); // dump collected data
 631      setNewsCache('newsarchive', $newsarchive);
 632  }
 633  
 634  // #### new: news archive ---------------------------------------------------------------------------------------------
 635  if ($action != "item" && $action != 'list' && $pref['newsposts_archive']) 
 636  {
 637    show_newsarchive($newsAr,$interval);
 638  }
 639  // #### END -----------------------------------------------------------------------------------------------------------
 640  
 641  if ($action != "item") 
 642  {
 643      if (is_numeric($action))
 644      {
 645          $action = "";
 646      }
 647   //    $parms = $news_total.",".ITEMVIEW.",".$newsfrom.",".e_SELF.'?'."[FROM].".$action.(isset($sub_action) ? ".".$sub_action : "");
 648   //    $nextprev = $tp->parseTemplate("{NEXTPREV={$parms}}");
 649   //    echo ($nextprev ? "<div class='nextprev'>".$nextprev."</div>" : "");
 650  }
 651  
 652  if(is_dir("remotefile")) {
 653      require_once(e_HANDLER."file_class.php");
 654      $file = new e_file;
 655      $reject = array('$.','$..','/','CVS','thumbs.db','*._$', 'index', 'null*', 'Readme.txt');
 656      $crem = $file -> get_files(e_BASE."remotefile", "", $reject);
 657      if(count($crem)) {
 658          foreach($crem as $loadrem) {
 659              if(strstr($loadrem['fname'], "load_")) {
 660                  require_once(e_BASE."remotefile/".$loadrem['fname']);
 661              }
 662          }
 663      }
 664  }
 665  
 666  if (isset($pref['nfp_display']) && $pref['nfp_display'] == 2) {
 667      require_once(e_PLUGIN."newforumposts_main/newforumposts_main.php");
 668  }
 669  
 670  render_newscats();
 671  
 672  require_once(FOOTERF);
 673  
 674  
 675  // =========================================================================
 676  function setNewsCache($cache_tag, $cache_data) {
 677      global $e107cache;
 678      $e107cache->set($cache_tag, $cache_data);
 679      $e107cache->set($cache_tag."_title", defined("e_PAGETITLE") ? e_PAGETITLE : '');
 680      $e107cache->set($cache_tag."_diz", defined("META_DESCRIPTION") ? META_DESCRIPTION : '');
 681      $e107cache->set($cache_tag."_og", defined("META_OG") ? META_OG : '');
 682  }
 683  
 684  /**
 685   * Mode: extend or item
 686   */
 687  function setNewsMeta($mode,$news)
 688  {
 689      if($news['news_thumbnail'])
 690      {
 691          $image = (substr($news['news_thumbnail'],0,3)=="{e_") ? $tp->replaceConstants($news['news_thumbnail']) : SITEURL.e_IMAGE."newspost_images/".$news['news_thumbnail'];    
 692      }
 693      else
 694      {
 695          $image = "";
 696      }
 697          
 698      $og_array = array(
 699          'title'            => $news['news_title'],
 700          'type'            => 'article',                  
 701          'url'            => e_SELF."?".$mode.".".$news['news_id'],
 702          'image'            => ($image) ? $image : '',
 703          'description'     => $news['news_summary'],
 704          'site_name'        => SITENAME
 705      );
 706                
 707      define('META_OG',serialize($og_array));
 708      define('META_DESCRIPTION',SITENAME.': '.$news['news_title'].' - '.$news['news_summary']);
 709  }
 710  
 711  function checkCache($cacheString){
 712      global $pref,$e107cache;
 713      $cache_data = $e107cache->retrieve($cacheString);
 714      $cache_title = $e107cache->retrieve($cacheString."_title");
 715      $cache_diz = $e107cache->retrieve($cacheString."_diz");
 716      $cache_og = $e107cache->retrieve($cacheString."_og");
 717      
 718      $etitle = ($cache_title != "e_PAGETITLE") ? $cache_title : "";
 719      $ediz    = ($cache_diz != "META_DESCRIPTION") ? $cache_diz : "";
 720      $og        = ($cache_og != "META_OG") ? $cache_og : "";
 721      
 722      if($etitle)
 723      {
 724          define(e_PAGETITLE,$etitle);
 725      }
 726      
 727      if($ediz)
 728      {
 729          define("META_DESCRIPTION",$ediz);
 730      }
 731      
 732      if($og)
 733      {
 734          define("META_OG",$og);
 735      }    
 736  
 737      if ($cache_data) {
 738          return $cache_data;
 739      } else {
 740          return false;
 741      }
 742  }
 743  
 744  function renderCache($cache, $nfp = FALSE){
 745      global $pref,$tp,$sql,$CUSTOMFOOTER, $FOOTER,$cust_footer,$ph;
 746      global $db_debug,$ns,$eTraffic,$eTimingStart, $error_handler, $db_time, $sql2, $mySQLserver, $mySQLuser, $mySQLpassword, $mySQLdefaultdb,$e107;
 747      echo $cache;
 748      if (isset($nfp) && isset($pref['nfp_display']) && $pref['nfp_display'] == 2) {
 749          require_once(e_PLUGIN."newforumposts_main/newforumposts_main.php");
 750      }
 751      render_newscats();
 752      require_once(FOOTERF);
 753      exit;
 754  }
 755  
 756  function render_newscats(){  // --  CNN Style Categories. ----
 757      global $pref,$ns,$tp;
 758      if (isset($pref['news_cats']) && $pref['news_cats'] == '1') {
 759          $text3 = $tp->toHTML("{NEWS_CATEGORIES}", TRUE, 'parse_sc,nobreak,emotes_off,no_make_clickable');
 760          $ns->tablerender(LAN_NEWS_23, $text3, 'news_cat');
 761      }
 762  }
 763  
 764  ?>


Generated: Mon Mar 12 16:28:38 2012 Cross Reference PHPXref