[ Index ]

PHP Cross Reference of phpwcms V1.4.7 _r403 (01.11.10)

title

Body

[close]

/ -> feeds.php (source)

   1  <?php
   2  /*************************************************************************************
   3     Copyright notice
   4     
   5     (c) 2002-2010 Oliver Georgi (oliver@phpwcms.de) // All rights reserved.
   6   
   7     This script is part of PHPWCMS. The PHPWCMS web content management system is
   8     free software; you can redistribute it and/or modify it under the terms of
   9     the GNU General Public License as published by the Free Software Foundation;
  10     either version 2 of the License, or (at your option) any later version.
  11    
  12     The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html
  13     A copy is found in the textfile GPL.txt and important notices to the license 
  14     from the author is found in LICENSE.txt distributed with these scripts.
  15    
  16     This script is distributed in the hope that it will be useful, but WITHOUT ANY 
  17     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  18     PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  19   
  20     This copyright notice MUST APPEAR in all copies of the script!
  21  *************************************************************************************/
  22  
  23  // creates feeds
  24  
  25  $phpwcms = array();
  26  
  27  require_once ('config/phpwcms/conf.inc.php');
  28  require_once  ('include/inc_lib/default.inc.php');
  29  
  30  require_once  (PHPWCMS_ROOT.'/include/inc_lib/dbcon.inc.php');
  31  
  32  require_once  (PHPWCMS_ROOT.'/include/inc_lib/general.inc.php');
  33  require_once  (PHPWCMS_ROOT.'/include/inc_front/front.func.inc.php');
  34  require_once  (PHPWCMS_ROOT.'/include/inc_ext/feedcreator/feedcreator.class.php');
  35  require_once  (PHPWCMS_ROOT.'/config/phpwcms/conf.indexpage.inc.php');
  36  
  37  
  38  $feeds_formats    = array('0.91', 'RSS0.91', '1.0', 'RSS1.0', '2.0', 'RSS2.0', 'ATOM', 'ATOM1.0', 'ATOM0.3');
  39  $feeds             = array();
  40  $feeds             = @parse_ini_file(PHPWCMS_ROOT.'/config/phpwcms/feeds.ini.php', true);
  41  
  42  if(empty($feeds) || (is_array($feeds) && count($feeds) == 0)) {
  43  
  44      $feeds['default'] = array(
  45                                  "title"                => "RSS 2.0",
  46                                  "description"        => "",
  47                                  "link"                => PHPWCMS_URL,
  48                                  "syndicationURL"    => PHPWCMS_URL.'feeds.php',
  49                                  "imagesrc"            => "",
  50                                  "imagetitle"        => "",
  51                                  "imagelink"            => "",
  52                                  "imagedescription"    => "",
  53                                  "timeZone"            => "+01:00",
  54                                  "cacheTTL"            => 3600,
  55                                  "structureID"        => "",
  56                                  "useauthor"            => 1,
  57                                  "feedAuthor"        => "",
  58                                  "feedEmail"            => "",
  59                                  "maxentries"        => 10,
  60                                  "encoding"            => "UTF-8",
  61                                  "defaultFormat"        => "RSS2.0",
  62                                  "filename"            => "default_feed.xml",
  63                                  "orderBy"            => 'livedate'
  64                                );
  65  
  66  }
  67  
  68  // chheck which feed data should be used
  69  reset($feeds);
  70  $default                 = isset($feeds['default']) ? 'default' : key($feeds);
  71  $custom                  = isset($_GET['feed']) ? strval(clean_slweg($_GET['feed'])) : $default;
  72  
  73  if(!isset($feeds[$custom])) {
  74  
  75      if($custom != '') {
  76          $feeds[$default]['structureID']    = $custom;
  77      }
  78      $custom                = $default;
  79  
  80  }
  81  
  82  $FEED                     = $feeds[$custom];
  83  
  84  $FEED['defaultFormat']    = empty($_GET['format']) ? trim($FEED['defaultFormat']) : strtoupper(clean_slweg($_GET['format']));
  85  $FEED['defaultFormat']    = in_array($FEED['defaultFormat'], $feeds_formats) ? $FEED['defaultFormat'] : "RSS2.0";
  86  
  87  if(!empty($FEED['structureID'])) {
  88  
  89      $FEED['structureID'] = explode(',', $FEED['structureID']);
  90      foreach($FEED['structureID'] as $key => $value) {
  91          $value = getFeedStructureID($value);
  92          if($value == '') {
  93              unset($FEED['structureID'][$key]);
  94          } else {
  95              $FEED['structureID'][$key] = intval($value);
  96          }
  97      }
  98      $FEED['structureID'] = array_unique($FEED['structureID']);
  99  
 100      if(count($FEED['structureID'])) {
 101          $FEED['structureID'] = implode(',', $FEED['structureID']);
 102          
 103          if(isset($_GET['feed']) && $FEED['structureID'] != '') {
 104              $FEED['filename'] = $FEED['structureID'].'.xml';
 105          }
 106          
 107      } else {
 108          $FEED['structureID'] = '';
 109      }
 110  
 111  }
 112  
 113  if(empty($FEED['filename'])) {
 114      $FEED['filename'] = md5($custom.$FEED['title']).'.xml';
 115  }
 116  $FEED['filename']        = 'content/rss/'.$FEED['defaultFormat'].'-'.$FEED['filename'];
 117  $FEED['maxentries']        = intval($FEED['maxentries']);
 118  $FEED['useauthor']        = intval($FEED['useauthor']);
 119  $FEED['encoding']        = empty($FEED['encoding']) ? 'utf-8' : $FEED['encoding'];
 120  
 121  define('FEED_ENCODING', trim(strtolower($FEED['encoding'])));
 122  define("TIME_ZONE","+01:00");
 123  
 124  $rss                         = new UniversalFeedCreator();
 125  $rss->useCached($FEED['defaultFormat'], $FEED['filename'], intval($FEED['cacheTTL'])); 
 126  $rss->title                 = $FEED['title']; 
 127  $rss->description             = $FEED['description']; 
 128  $rss->link                     = $FEED['link']; 
 129  $rss->syndicationURL         = $FEED['syndicationURL'];
 130  $rss->encoding                = FEED_ENCODING;
 131  if(!empty($FEED['feedAuthor'])) {
 132      $rss->editor            = $FEED['feedAuthor'];
 133  }
 134  if(!empty($FEED['feedEmail'])) {
 135      $rss->editorEmail        = $FEED['feedEmail'];
 136  }
 137  
 138  if(!empty($FEED['imagesrc'])) {
 139  
 140      $image                     = new FeedImage(); 
 141      $image->title             = $FEED['imagetitle']; 
 142      $image->url             = $FEED['imagesrc']; 
 143      $image->link            = $FEED['imagelink']; 
 144      $image->description        = $FEED['imagedescription']; 
 145      $rss->image             = $image;
 146  
 147  }
 148  
 149  $sql  =    "SELECT *, UNIX_TIMESTAMP(article_tstamp) AS article_changeDate ";
 150  $sql .= "FROM ".DB_PREPEND."phpwcms_article ar LEFT JOIN ".DB_PREPEND."phpwcms_articlecat ac ON ";
 151  $sql .=    "ar.article_cid=ac.acat_id WHERE ";
 152  
 153  if(isset($FEED['structureID']) && $FEED['structureID'] != '') {
 154  
 155      $sql .= " ar.article_cid IN (". $FEED['structureID'] .") AND ";
 156  
 157  }
 158  
 159  $sql .= "ar.article_public=1 AND ar.article_aktiv=1 AND ";
 160  $sql .= "ar.article_deleted=0 AND ar.article_begin < NOW() ";
 161  $sql .= "AND ar.article_end > NOW() AND ar.article_nosearch=0 ";
 162  $sql .= "AND article_norss=1 AND IF(ar.article_cid=0, ";
 163  $sql .= $indexpage['acat_aktiv'] && empty($indexpage['acat_regonly']) ? '1' : '0';
 164  $sql .= ", ac.acat_aktiv=1 AND ac.acat_trash=0 AND ac.acat_regonly=0) ";
 165  
 166  // define ordering
 167  if(empty($FEED['orderBy'])) {
 168      $FEED['orderBy'] = 'livedate';
 169  }
 170  switch(strtolower(trim($FEED['orderBy']))) {
 171  
 172                          // createdate
 173      case 'createdate':    $FEED['orderBy'] = 'ar.article_created';    
 174                          break;
 175  
 176                          // changedate
 177      case 'changedate':    $FEED['orderBy'] = 'ar.article_tstamp';    
 178                          break;
 179  
 180                          // killdate
 181      case 'killdate':    $FEED['orderBy'] = 'ar.article_end';    
 182                          break;
 183      
 184                          // livedate
 185      default:            $FEED['orderBy'] = 'ar.article_begin';
 186  
 187  }
 188  // define ASC, DESC, RAND
 189  if(empty($FEED['order'])) {
 190      $FEED['order'] = 'DESC';
 191  }
 192  switch(strtoupper(trim($FEED['orderBy']))) {
 193  
 194                      // random
 195      case 'RAND':    $FEED['order'] = 'RAND()';
 196                      break;
 197  
 198                      // ascending
 199      case 'ASC':        $FEED['order'] = $FEED['orderBy'] . ' ASC';
 200                      break;
 201      
 202                      // descending
 203      default:        $FEED['order'] = $FEED['orderBy'] . ' DESC';
 204  
 205  }
 206  
 207  //$sql .= "ORDER BY ar.article_begin DESC";
 208  $sql .= 'ORDER BY ' . $FEED['order'];
 209  
 210  if($FEED['maxentries']) {
 211      $sql .= " LIMIT ".$FEED['maxentries'];
 212  }
 213  $timePlus = 0;
 214  
 215  //dumpVar($sql); exit();
 216  
 217  if($result = mysql_query($sql, $db)) {
 218      while($data = mysql_fetch_assoc($result)) {
 219      
 220          $item = new FeedItem();
 221          $item->title             = combinedParser($data["article_title"], FEED_ENCODING);
 222          $item->link             = PHPWCMS_URL.'index.php?'.setGetArticleAid( $data );
 223          $item->description         = combinedParser( empty($data["article_summary"]) ? $data["article_subtitle"] : $data["article_summary"] , FEED_ENCODING); 
 224          $item->date             = $data['article_created'] + $timePlus;
 225          $item->updateDate        = $data['article_changeDate'] + $timePlus + 1;
 226          $item->source             = PHPWCMS_URL;
 227          
 228          if($FEED['useauthor'] || $FEED['defaultFormat'] == 'ATOM' || $FEED['defaultFormat'] == 'ATOM1.0') {
 229          
 230              if(!empty($data["article_username"])) {
 231                  $item->author     = $FEED['feedEmail'].' ('.combinedParser($data["article_username"]).')';
 232              } elseif($FEED['defaultFormat'] == 'ATOM' || $FEED['defaultFormat'] == 'ATOM1.0') {
 233                  $item->author     = $FEED['feedAuthor'];
 234              }
 235  
 236          }
 237          
 238          $item->guid                = PHPWCMS_URL.'index.php?'.setGetArticleAid( $data );
 239          $rss->addItem($item);
 240          
 241          $timePlus += 2;
 242      }
 243  } 
 244  
 245  
 246  
 247  $rss->saveFeed($FEED['defaultFormat'], $FEED['filename']); 
 248  
 249  
 250  
 251  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 252  
 253  
 254  function combinedParser($string, $charset='utf-8', $allowed_tags='') {
 255  
 256      $string = html_parser($string);
 257      $string = clean_replacement_tags($string, $allowed_tags);
 258      
 259      $string = str_replace('&nbsp;', ' ', $string);
 260  
 261      $string = decode_entities($string);
 262      $string = cleanUpSpecialHtmlEntities($string);
 263  
 264      if(!empty($string) && PHPWCMS_CHARSET != $charset) {
 265          $string = makeCharsetConversion($string, PHPWCMS_CHARSET, $charset);
 266      } else {
 267          $string = html_specialchars($string);
 268      }
 269      
 270      return $string;
 271  }
 272  
 273  
 274  function getFeedStructureID($value) {
 275      $value = trim($value);    
 276      if($value != '' && !is_num($value)) {
 277          //check for correct structureID when alias is given
 278          global $indexpage;
 279          $value = strtolower($value);
 280          if($indexpage['acat_aktiv'] && empty($indexpage['acat_regonly']) && strtolower($indexpage['acat_alias']) == $value) {
 281              return '0';
 282          }
 283          $sql  = "SELECT acat_id FROM ".DB_PREPEND."phpwcms_articlecat WHERE ";
 284          $sql .= "acat_aktiv=1 AND acat_trash=0 AND acat_regonly=0 AND acat_alias LIKE '";
 285          $sql .= aporeplace($value)."' LIMIT 1";
 286          $value = '';
 287          if($result = mysql_query($sql, $GLOBALS['db'])) {
 288              if($row = mysql_fetch_row($result)) {
 289                  $value = strval($row[0]);
 290              }
 291              mysql_free_result($result);
 292          }
 293      }
 294      return $value;
 295  }
 296  
 297  function is_num($var) {
 298      for ($i = 0; $i < strlen($var); $i++) {
 299          $ascii_code = ord($var[$i]);
 300          if(intval($ascii_code) >= 48 && intval($ascii_code) <= 57) {
 301              continue;
 302          } else {          
 303              return false;
 304          }
 305      } 
 306      return true;
 307  }
 308  
 309  
 310  
 311  ?>


Generated: Tue Nov 16 22:51:00 2010 Cross-referenced by PHPXref 0.7