Changeset 1549


Ignore:
Timestamp:
Sep 19, 2006, 12:51:09 AM (18 years ago)
Author:
rvelices
Message:

RSS feed improvements:

  • send 404 when feed id missing/unknown
  • added a guid element for each feed item (make the difference between 2

different 0/1 items - they have the same link element)

  • don't update last_check unless some news are available
  • new images/updated albums removed from the 0/1 feed item
  • added 5 different feed items for new images/updated albums (generated by

grouping post date) with more information, thumbnails and links

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/feed.php

    r1331 r1549  
    110110  $user = mysql_fetch_array(pwg_query($query));
    111111}
    112 else
    113 {
    114   echo l10n('Unknown feed identifier');
    115   exit();
     112
     113if ( empty($user) )
     114{
     115  page_not_found('Unknown/missing feed identifier');
    116116}
    117117
     
    127127include_once(PHPWG_ROOT_PATH.'include/feedcreator.class.php');
    128128
     129$base_url = 'http://'.$_SERVER["HTTP_HOST"].cookie_path();
     130if ( strrpos($base_url, '/') !== strlen($base_url)-1 )
     131{
     132  $base_url .= '/';
     133}
     134$page['root_path']=$base_url;
     135
    129136$rss = new UniversalFeedCreator();
    130137
    131 $rss->title = $conf['gallery_title'].', notifications';
     138$rss->title = $conf['gallery_title'];
    132139$rss->title.= ' (as '.$user['username'].')';
    133140
     
    138145// +-----------------------------------------------------------------------+
    139146
    140 $news = news($user['last_check'], $dbnow);
     147$news = news($user['last_check'], $dbnow, true);
    141148
    142149if (count($news) > 0)
    143150{
    144   $item = new FeedItem(); 
     151  $item = new FeedItem();
    145152  $item->title = sprintf(l10n('New on %s'), $dbnow);
    146153  $item->link = $conf['gallery_url'];
    147  
     154
    148155  // content creation
    149156  $item->description = '<ul>';
     
    154161  $item->description.= '</ul>';
    155162  $item->descriptionHtmlSyndicated = true;
    156  
     163
    157164  $item->date = ts_to_iso8601(mysqldt_to_ts($dbnow));
    158   $item->author = 'PhpWebGallery notifier';
    159  
     165  $item->author = 'PhpWebGallery notifier';
     166  $item->guid= sprintf('%s', $dbnow);;
     167
    160168  $rss->addItem($item);
    161 }
    162 
    163 $query = '
     169
     170  $query = '
    164171UPDATE '.USER_FEED_TABLE.'
    165172  SET last_check = \''.$dbnow.'\'
    166173  WHERE id = \''.$_GET['feed'].'\'
    167174;';
    168 pwg_query($query);
     175  pwg_query($query);
     176}
     177
     178
     179// build items for new images/albums
     180$query = '
     181SELECT date_available,
     182      COUNT(DISTINCT id) nb_images,
     183      COUNT(DISTINCT category_id) nb_cats
     184  FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id=image_id
     185  WHERE category_id NOT IN ('.$user['forbidden_categories'].')
     186  GROUP BY date_available
     187  ORDER BY date_available DESC
     188  LIMIT 0,5
     189;';
     190$result = pwg_query($query);
     191$dates = array();
     192while ($row = mysql_fetch_array($result))
     193{
     194  array_push($dates, $row);
     195}
     196
     197foreach($dates as  $date_detail)
     198{ // for each recent post date we create a feed item
     199  $date = $date_detail['date_available'];
     200  $exploded_date = explode_mysqldt($date);
     201  $item = new FeedItem();
     202  $item->title = sprintf(l10n('%d new elements'), $date_detail['nb_images']);
     203  $item->title .= ' ('.$lang['month'][(int)$exploded_date['month']].' '.$exploded_date['day'].')';
     204  $item->link = make_index_url(
     205        array(
     206          'chronology_field' => 'posted',
     207          'chronology_style'=> 'monthly',
     208          'chronology_view' => 'calendar',
     209          'chronology_date' => explode('-', substr($date,0,10) )
     210        )
     211      );
     212
     213  $item->description .=
     214    '<a href="'.make_index_url().'">'.$conf['gallery_title'].'</a><br/> ';
     215
     216  $item->description .=
     217        '<li>'
     218        .sprintf(l10n('%d new elements'), $date_detail['nb_images'])
     219        .' ('
     220        .'<a href="'.make_index_url(array('section'=>'recent_pics')).'">'
     221          .l10n('recent_pics_cat').'</a>'
     222        .')'
     223        .'</li>';
     224
     225  // get some thumbnails ...
     226  $query = '
     227SELECT DISTINCT id, path, name, tn_ext
     228  FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id=image_id
     229  WHERE category_id NOT IN ('.$user['forbidden_categories'].')
     230    AND date_available="'.$date.'"
     231    AND tn_ext IS NOT NULL
     232  LIMIT 0,6
     233;';
     234  $result = pwg_query($query);
     235  while ($row = mysql_fetch_array($result))
     236  {
     237    $tn_src = get_thumbnail_src($row['path'], @$row['tn_ext']);
     238    $item->description .= '<img src="'.$tn_src.'"/>';
     239  }
     240  $item->description .= '...<br/>';
     241
     242
     243  $item->description .=
     244        '<li>'
     245        .sprintf(l10n('%d categories updated'), $date_detail['nb_cats'])
     246        .'</li>';
     247  // get some categories ...
     248  $query = '
     249SELECT DISTINCT c.uppercats, COUNT(DISTINCT i.id) img_count
     250  FROM '.IMAGES_TABLE.' i INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON i.id=image_id
     251    INNER JOIN '.CATEGORIES_TABLE.' c ON c.id=category_id
     252  WHERE category_id NOT IN ('.$user['forbidden_categories'].')
     253    AND date_available="'.$date.'"
     254  GROUP BY category_id
     255  ORDER BY img_count DESC
     256  LIMIT 0,6
     257;';
     258  $result = pwg_query($query);
     259  $item->description .= '<ul>';
     260  while ($row = mysql_fetch_array($result))
     261  {
     262    $item->description .=
     263          '<li>'
     264          .get_cat_display_name_cache($row['uppercats'])
     265          .' ('.sprintf(l10n('%d new elements'), $row['img_count']).')'
     266          .'</li>';
     267  }
     268  $item->description .= '</ul>';
     269
     270  $item->descriptionHtmlSyndicated = true;
     271
     272  $item->date = ts_to_iso8601(mysqldt_to_ts($date));
     273  $item->author = 'PhpWebGallery notifier';
     274  $item->guid= sprintf('%s', 'pics-'.$date);;
     275
     276  $rss->addItem($item);
     277}
    169278
    170279// send XML feed
  • trunk/include/feedcreator.class.php

    r801 r1549  
    7979        added support for mbox
    8080        tentative support for echo/necho/atom/pie/???
    81        
     81
    8282v1.2    07-20-03
    8383        intelligent auto-truncating of RSS 0.91 attributes
     
    101101/*** GENERAL USAGE *********************************************************
    102102
    103 include("feedcreator.class.php"); 
    104 
    105 $rss = new UniversalFeedCreator(); 
     103include("feedcreator.class.php");
     104
     105$rss = new UniversalFeedCreator();
    106106$rss->useCached(); // use cached version if age<1 hour
    107 $rss->title = "PHP news"; 
    108 $rss->description = "daily news from the PHP scripting world"; 
     107$rss->title = "PHP news";
     108$rss->description = "daily news from the PHP scripting world";
    109109
    110110//optional
     
    112112$rss->descriptionHtmlSyndicated = true;
    113113
    114 $rss->link = "http://www.dailyphp.net/news"; 
    115 $rss->syndicationURL = "http://www.dailyphp.net/".$_SERVER["PHP_SELF"]; 
    116 
    117 $image = new FeedImage(); 
    118 $image->title = "dailyphp.net logo"; 
    119 $image->url = "http://www.dailyphp.net/images/logo.gif"; 
    120 $image->link = "http://www.dailyphp.net"; 
    121 $image->description = "Feed provided by dailyphp.net. Click to visit."; 
     114$rss->link = "http://www.dailyphp.net/news";
     115$rss->syndicationURL = "http://www.dailyphp.net/".$_SERVER["PHP_SELF"];
     116
     117$image = new FeedImage();
     118$image->title = "dailyphp.net logo";
     119$image->url = "http://www.dailyphp.net/images/logo.gif";
     120$image->link = "http://www.dailyphp.net";
     121$image->description = "Feed provided by dailyphp.net. Click to visit.";
    122122
    123123//optional
     
    125125$image->descriptionHtmlSyndicated = true;
    126126
    127 $rss->image = $image; 
    128 
    129 // get your news items from somewhere, e.g. your database: 
    130 mysql_select_db($dbHost, $dbUser, $dbPass); 
    131 $res = mysql_query("SELECT * FROM news ORDER BY newsdate DESC"); 
    132 while ($data = mysql_fetch_object($res)) { 
    133     $item = new FeedItem(); 
    134     $item->title = $data->title; 
    135     $item->link = $data->url; 
    136     $item->description = $data->short; 
    137    
     127$rss->image = $image;
     128
     129// get your news items from somewhere, e.g. your database:
     130mysql_select_db($dbHost, $dbUser, $dbPass);
     131$res = mysql_query("SELECT * FROM news ORDER BY newsdate DESC");
     132while ($data = mysql_fetch_object($res)) {
     133    $item = new FeedItem();
     134    $item->title = $data->title;
     135    $item->link = $data->url;
     136    $item->description = $data->short;
     137
    138138    //optional
    139139    item->descriptionTruncSize = 500;
    140140    item->descriptionHtmlSyndicated = true;
    141141
    142     $item->date = $data->newsdate; 
    143     $item->source = "http://www.dailyphp.net"; 
    144     $item->author = "John Doe"; 
    145      
    146     $rss->addItem($item); 
    147 } 
     142    $item->date = $data->newsdate;
     143    $item->source = "http://www.dailyphp.net";
     144    $item->author = "John Doe";
     145
     146    $rss->addItem($item);
     147}
    148148
    149149// valid format strings are: RSS0.91, RSS1.0, RSS2.0, PIE0.1 (deprecated),
     
    180180         */
    181181        var $title, $description, $link;
    182        
     182
    183183        /**
    184184         * Optional attributes of an item.
    185185         */
    186186        var $author, $authorEmail, $image, $category, $comments, $guid, $source, $creator;
    187        
     187
    188188        /**
    189189         * Publishing date of an item. May be in one of the following formats:
     
    200200         */
    201201        var $date;
    202        
     202
    203203        /**
    204204         * Any additional elements to include as an assiciated array. All $key => $value pairs
     
    227227         */
    228228        var $title, $url, $link;
    229        
     229
    230230        /**
    231231         * Optional attributes of an image.
     
    245245         */
    246246        var $descriptionHtmlSyndicated;
    247        
     247
    248248        /**
    249249         * Indicates whether and to how many characters a description should be truncated.
    250250         */
    251251        var $descriptionTruncSize;
    252        
     252
    253253        /**
    254254         * Returns a formatted description field, depending on descriptionHtmlSyndicated and
    255255         * $descriptionTruncSize properties
    256          * @return    string    the formatted description 
     256         * @return    string    the formatted description
    257257         */
    258258        function getDescription() {
     
    268268/**
    269269 * An FeedHtmlField describes and generates
    270  * a feed, item or image html field (probably a description). Output is 
     270 * a feed, item or image html field (probably a description). Output is
    271271 * generated based on $truncSize, $syndicateHtml properties.
    272272 * @author Pascal Van Hecke <feedcreator.class.php@vanhecke.info>
     
    278278         */
    279279        var $rawFieldContent;
    280        
     280
    281281        /**
    282282         * Optional attributes of a FeedHtmlField.
    283          * 
     283         *
    284284         */
    285285        var $truncSize, $syndicateHtml;
    286        
     286
    287287        /**
    288288         * Creates a new instance of FeedHtmlField.
     
    294294                }
    295295        }
    296                
    297                
     296
     297
    298298        /**
    299299         * Creates the right output, depending on $truncSize, $syndicateHtml properties.
     
    301301         */
    302302        function output() {
    303                 // when field available and syndicated in html we assume 
     303                // when field available and syndicated in html we assume
    304304                // - valid html in $rawFieldContent and we enclose in CDATA tags
    305305                // - no truncation (truncating risks producing invalid html)
     
    333333class UniversalFeedCreator extends FeedCreator {
    334334        var $_feed;
    335        
     335
    336336        function _setFormat($format) {
    337337                switch (strtoupper($format)) {
    338                        
     338
    339339                        case "2.0":
    340340                                // fall through
     
    342342                                $this->_feed = new RSSCreator20();
    343343                                break;
    344                        
     344
    345345                        case "1.0":
    346346                                // fall through
     
    348348                                $this->_feed = new RSSCreator10();
    349349                                break;
    350                        
     350
    351351                        case "0.91":
    352352                                // fall through
     
    354354                                $this->_feed = new RSSCreator091();
    355355                                break;
    356                        
     356
    357357                        case "PIE0.1":
    358358                                $this->_feed = new PIECreator01();
    359359                                break;
    360                        
     360
    361361                        case "MBOX":
    362362                                $this->_feed = new MBOXCreator();
    363363                                break;
    364                        
     364
    365365                        case "OPML":
    366366                                $this->_feed = new OPMLCreator();
    367367                                break;
    368                                
     368
    369369                        case "ATOM":
    370370                                // fall through: always the latest ATOM version
    371                                
     371
    372372                        case "ATOM0.3":
    373373                                $this->_feed = new AtomCreator03();
    374374                                break;
    375                                
     375
    376376                        case "HTML":
    377377                                $this->_feed = new HTMLCreator();
    378378                                break;
    379                        
     379
    380380                        case "JS":
    381381                                // fall through
     
    383383                                $this->_feed = new JSCreator();
    384384                                break;
    385                        
     385
    386386                        default:
    387387                                $this->_feed = new RSSCreator091();
    388388                                break;
    389389                }
    390        
     390
    391391                $vars = get_object_vars($this);
    392392                foreach ($vars as $key => $value) {
     
    397397                }
    398398        }
    399        
     399
    400400        /**
    401401         * Creates a syndication feed based on the items previously added.
     
    410410                return $this->_feed->createFeed();
    411411        }
    412        
    413        
    414        
     412
     413
     414
    415415        /**
    416416         * Saves this feed as a file on the local disk. After the file is saved, an HTTP redirect
    417417         * header may be sent to redirect the use to the newly created file.
    418418         * @since 1.4
    419          * 
     419         *
    420420         * @param       string  format  format the feed should comply to. Valid values are:
    421421         *                      "PIE0.1" (deprecated), "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM", "ATOM0.3", "HTML", "JS"
     
    463463         */
    464464        var $title, $description, $link;
    465        
    466        
     465
     466
    467467        /**
    468468         * Optional attributes of a feed.
     
    475475        */
    476476        var $xslStyleSheet = "";
    477        
    478        
     477
     478
    479479        /**
    480480         * @access private
    481481         */
    482482        var $items = Array();
    483        
    484        
     483
     484
    485485        /**
    486486         * This feed's MIME content type.
     
    489489         */
    490490        var $contentType = "application/xml";
    491        
    492        
     491
     492
    493493        /**
    494494         * This feed's character encoding.
     
    496496         **/
    497497        var $encoding = "ISO-8859-1";
    498        
    499        
     498
     499
    500500        /**
    501501         * Any additional elements to include as an assiciated array. All $key => $value pairs
     
    507507         */
    508508        var $additionalElements = Array();
    509    
    510    
     509
     510
    511511        /**
    512512         * Adds an FeedItem to the feed.
     
    518518                $this->items[] = $item;
    519519        }
    520        
    521        
     520
     521
    522522        /**
    523523         * Truncates a string to a certain length at the most sensible point.
     
    526526         * If the string is truncated, " ..." is appended.
    527527         * If the string is already shorter than $length, it is returned unchanged.
    528          * 
     528         *
    529529         * @static
    530530         * @param string    string A string to be truncated.
     
    536536                        return $string;
    537537                }
    538                
     538
    539539                $pos = strrpos($string,".");
    540540                if ($pos>=$length-4) {
     
    545545                        return substr($string,0,$pos+1)." ...";
    546546                }
    547                
     547
    548548                $pos = strrpos($string," ");
    549549                if ($pos>=$length-4) {
     
    554554                        return substr($string,0,$pos)." ...";
    555555                }
    556                
     556
    557557                return substr($string,0,$length-4)." ...";
    558                        
    559         }
    560        
    561        
     558
     559        }
     560
     561
    562562        /**
    563563         * Creates a comment indicating the generator of this feed.
     
    568568                return "<!-- generator=\"".FEEDCREATOR_VERSION."\" -->\n";
    569569        }
    570        
    571        
     570
     571
    572572        /**
    573573         * Creates a string containing all additional elements specified in
     
    586586                return $ae;
    587587        }
    588        
     588
    589589        function _createStylesheetReferences() {
    590590                $xml = "";
     
    593593                return $xml;
    594594        }
    595        
    596        
     595
     596
    597597        /**
    598598         * Builds the feed's text.
    599599         * @abstract
    600          * @return    string    the feed's complete text 
     600         * @return    string    the feed's complete text
    601601         */
    602602        function createFeed() {
    603603        }
    604        
     604
    605605        /**
    606606         * Generate a filename for the feed cache file. The result will be $_SERVER["PHP_SELF"] with the extension changed to .xml.
    607607         * For example:
    608          * 
     608         *
    609609         * echo $_SERVER["PHP_SELF"]."\n";
    610610         * echo FeedCreator::_generateFilename();
    611          * 
     611         *
    612612         * would produce:
    613          * 
     613         *
    614614         * /rss/latestnews.php
    615615         * latestnews.xml
     
    623623                return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".xml";
    624624        }
    625        
    626        
     625
     626
    627627        /**
    628628         * @since 1.4
     
    631631        function _redirect($filename) {
    632632                // attention, heavily-commented-out-area
    633                
     633
    634634                // maybe use this in addition to file time checking
    635635                //Header("Expires: ".date("r",time()+$this->_timeout));
    636                
     636
    637637                /* no caching at all, doesn't seem to work as good:
    638638                Header("Cache-Control: no-cache");
    639639                Header("Pragma: no-cache");
    640640                */
    641                
     641
    642642                // HTTP redirect, some feed readers' simple HTTP implementations don't follow it
    643643                //Header("Location: ".$filename);
     
    648648                die();
    649649        }
    650    
     650
    651651        /**
    652652         * Turns on caching and checks if there is a recent version of this feed in the cache.
     
    668668                }
    669669        }
    670        
    671        
     670
     671
    672672        /**
    673673         * Saves this feed as a file on the local disk. After the file is saved, a redirect
    674674         * header may be sent to redirect the user to the newly created file.
    675675         * @since 1.4
    676          * 
     676         *
    677677         * @param filename      string  optional        the filename where a recent version of the feed is saved. If not specified, the filename is $_SERVER["PHP_SELF"] with the extension changed to .xml (see _generateFilename()).
    678678         * @param redirect      boolean optional        send an HTTP redirect header or not. If true, the user will be automatically redirected to the created file.
     
    693693                }
    694694        }
    695        
     695
    696696}
    697697
     
    703703class FeedDate {
    704704        var $unix;
    705        
     705
    706706        /**
    707707         * Creates a new instance of FeedDate representing a given date.
     
    711711        function FeedDate($dateString="") {
    712712                if ($dateString=="") $dateString = date("r");
    713                
     713
    714714                if (is_integer($dateString)) {
    715715                        $this->unix = $dateString;
     
    767767                return $date;
    768768        }
    769        
     769
    770770        /**
    771771         * Gets the date stored in this FeedDate as an ISO 8601 date.
     
    779779                return $date;
    780780        }
    781        
     781
    782782        /**
    783783         * Gets the date stored in this FeedDate as unix time stamp.
     
    803803         * Builds the RSS feed's text. The feed will be compliant to RDF Site Summary (RSS) 1.0.
    804804         * The feed will contain all items previously added in the same order.
    805          * @return    string    the feed's complete text 
    806          */
    807         function createFeed() {     
     805         * @return    string    the feed's complete text
     806         */
     807        function createFeed() {
    808808                $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
    809809                $feed.= $this->_createGeneratorComment();
     
    814814                $feed.= "<rdf:RDF\n";
    815815                $feed.= "    xmlns=\"http://purl.org/rss/1.0/\"\n";
    816                 $feed.= "    xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n"; 
     816                $feed.= "    xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n";
    817817                $feed.= "    xmlns:slash=\"http://purl.org/rss/1.0/modules/slash/\"\n";
    818818                $feed.= "    xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n";
     
    842842                }
    843843                $feed.= $this->_createAdditionalElements($this->additionalElements, "    ");
    844                
     844
    845845                for ($i=0;$i<count($this->items);$i++) {
    846846                        $feed.= "    <item rdf:about=\"".htmlspecialchars($this->items[$i]->link)."\">\n";
     
    889889                $this->contentType = "application/rss+xml";
    890890        }
    891        
     891
    892892        /**
    893893         * Sets this RSS feed's version number.
     
    901901         * Builds the RSS feed's text. The feed will be compliant to RDF Site Summary (RSS) 1.0.
    902902         * The feed will contain all items previously added in the same order.
    903          * @return    string    the feed's complete text 
     903         * @return    string    the feed's complete text
    904904         */
    905905        function createFeed() {
     
    907907                $feed.= $this->_createGeneratorComment();
    908908                $feed.= $this->_createStylesheetReferences();
    909                 $feed.= "<rss version=\"".$this->RSSVersion."\">\n"; 
     909                $feed.= "<rss version=\"".$this->RSSVersion."\">\n";
    910910                $feed.= "    <channel>\n";
    911911                $feed.= "        <title>".FeedCreator::iTrunc(htmlspecialchars($this->title),100)."</title>\n";
     
    919919                if ($this->image!=null) {
    920920                        $feed.= "        <image>\n";
    921                         $feed.= "            <url>".$this->image->url."</url>\n"; 
    922                         $feed.= "            <title>".FeedCreator::iTrunc(htmlspecialchars($this->image->title),100)."</title>\n"; 
     921                        $feed.= "            <url>".$this->image->url."</url>\n";
     922                        $feed.= "            <title>".FeedCreator::iTrunc(htmlspecialchars($this->image->title),100)."</title>\n";
    923923                        $feed.= "            <link>".$this->image->link."</link>\n";
    924924                        if ($this->image->width!="") {
     
    974974                        $feed.= "            <link>".htmlspecialchars($this->items[$i]->link)."</link>\n";
    975975                        $feed.= "            <description>".$this->items[$i]->getDescription()."</description>\n";
    976                        
     976
    977977                        if ($this->items[$i]->author!="") {
    978978                                $feed.= "            <author>".htmlspecialchars($this->items[$i]->author)."</author>\n";
     
    995995                        }
    996996                        if ($this->items[$i]->guid!="") {
    997                                 $feed.= "            <guid>".htmlspecialchars($this->items[$i]->guid)."</guid>\n";
     997                                $feed.= "            <guid isPermaLink=\"false\">".htmlspecialchars($this->items[$i]->guid)."</guid>\n";
    998998                        }
    999999                        $feed.= $this->_createAdditionalElements($this->items[$i]->additionalElements, "        ");
     
    10201020        parent::_setRSSVersion("2.0");
    10211021    }
    1022    
     1022
    10231023}
    10241024
     
    10331033 */
    10341034class PIECreator01 extends FeedCreator {
    1035        
     1035
    10361036        function PIECreator01() {
    10371037                $this->encoding = "utf-8";
    10381038        }
    1039    
     1039
    10401040        function createFeed() {
    10411041                $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
    10421042                $feed.= $this->_createStylesheetReferences();
    1043                 $feed.= "<feed version=\"0.1\" xmlns=\"http://example.com/newformat#\">\n"; 
     1043                $feed.= "<feed version=\"0.1\" xmlns=\"http://example.com/newformat#\">\n";
    10441044                $feed.= "    <title>".FeedCreator::iTrunc(htmlspecialchars($this->title),100)."</title>\n";
    10451045                $this->truncSize = 500;
     
    10821082 *
    10831083 * Some elements have not been implemented yet. These are (incomplete list):
    1084  * author URL, item author's email and URL, item contents, alternate links, 
     1084 * author URL, item author's email and URL, item contents, alternate links,
    10851085 * other link content types than text/html. Some of them may be created with
    10861086 * AtomCreator03::additionalElements.
     
    10961096                $this->encoding = "utf-8";
    10971097        }
    1098        
     1098
    10991099        function createFeed() {
    11001100                $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
     
    11051105                        $feed.= " xml:lang=\"".$this->language."\"";
    11061106                }
    1107                 $feed.= ">\n"; 
     1107                $feed.= ">\n";
    11081108                $feed.= "    <title>".htmlspecialchars($this->title)."</title>\n";
    11091109                $feed.= "    <tagline>".htmlspecialchars($this->description)."</tagline>\n";
     
    11641164                $this->encoding = "ISO-8859-15";
    11651165        }
    1166    
    1167         function qp_enc($input = "", $line_max = 76) { 
    1168                 $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); 
    1169                 $lines = preg_split("/(?:\r\n|\r|\n)/", $input); 
    1170                 $eol = "\r\n"; 
    1171                 $escape = "="; 
    1172                 $output = ""; 
    1173                 while( list(, $line) = each($lines) ) { 
    1174                         //$line = rtrim($line); // remove trailing white space -> no =20\r\n necessary 
    1175                         $linlen = strlen($line); 
    1176                         $newline = ""; 
    1177                         for($i = 0; $i < $linlen; $i++) { 
    1178                                 $c = substr($line, $i, 1); 
    1179                                 $dec = ord($c); 
    1180                                 if ( ($dec == 32) && ($i == ($linlen - 1)) ) { // convert space at eol only 
    1181                                         $c = "=20"; 
    1182                                 } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required 
    1183                                         $h2 = floor($dec/16); $h1 = floor($dec%16); 
    1184                                         $c = $escape.$hex["$h2"].$hex["$h1"]; 
    1185                                 } 
    1186                                 if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted 
    1187                                         $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay 
    1188                                         $newline = ""; 
    1189                                 } 
    1190                                 $newline .= $c; 
    1191                         } // end of for 
    1192                         $output .= $newline.$eol; 
    1193                 } 
    1194                 return trim($output); 
    1195         }
    1196        
     1166
     1167        function qp_enc($input = "", $line_max = 76) {
     1168                $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
     1169                $lines = preg_split("/(?:\r\n|\r|\n)/", $input);
     1170                $eol = "\r\n";
     1171                $escape = "=";
     1172                $output = "";
     1173                while( list(, $line) = each($lines) ) {
     1174                        //$line = rtrim($line); // remove trailing white space -> no =20\r\n necessary
     1175                        $linlen = strlen($line);
     1176                        $newline = "";
     1177                        for($i = 0; $i < $linlen; $i++) {
     1178                                $c = substr($line, $i, 1);
     1179                                $dec = ord($c);
     1180                                if ( ($dec == 32) && ($i == ($linlen - 1)) ) { // convert space at eol only
     1181                                        $c = "=20";
     1182                                } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
     1183                                        $h2 = floor($dec/16); $h1 = floor($dec%16);
     1184                                        $c = $escape.$hex["$h2"].$hex["$h1"];
     1185                                }
     1186                                if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
     1187                                        $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay
     1188                                        $newline = "";
     1189                                }
     1190                                $newline .= $c;
     1191                        } // end of for
     1192                        $output .= $newline.$eol;
     1193                }
     1194                return trim($output);
     1195        }
     1196
    11971197
    11981198        /**
    11991199         * Builds the MBOX contents.
    1200          * @return    string    the feed's complete text 
     1200         * @return    string    the feed's complete text
    12011201         */
    12021202        function createFeed() {
     
    12241224                return $feed;
    12251225        }
    1226        
     1226
    12271227        /**
    12281228         * Generate a filename for the feed cache file. Overridden from FeedCreator to prevent XML data types.
     
    12401240/**
    12411241 * OPMLCreator is a FeedCreator that implements OPML 1.0.
    1242  * 
     1242 *
    12431243 * @see http://opml.scripting.com/spec
    12441244 * @author Dirk Clemens, Kai Blankenhorn
     
    12501250                $this->encoding = "utf-8";
    12511251        }
    1252    
    1253         function createFeed() {     
     1252
     1253        function createFeed() {
    12541254                $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
    12551255                $feed.= $this->_createGeneratorComment();
     
    12921292
    12931293/**
    1294  * HTMLCreator is a FeedCreator that writes an HTML feed file to a specific 
     1294 * HTMLCreator is a FeedCreator that writes an HTML feed file to a specific
    12951295 * location, overriding the createFeed method of the parent FeedCreator.
    12961296 * The HTML produced can be included over http by scripting languages, or serve
    12971297 * as the source for an IFrame.
    12981298 * All output by this class is embedded in <div></div> tags to enable formatting
    1299  * using CSS. 
     1299 * using CSS.
    13001300 *
    13011301 * @author Pascal Van Hecke
     
    13051305
    13061306        var $contentType = "text/html";
    1307        
     1307
    13081308        /**
    13091309         * Contains HTML to be output at the start of the feed's html representation.
    13101310         */
    13111311        var $header;
    1312        
     1312
    13131313        /**
    13141314         * Contains HTML to be output at the end of the feed's html representation.
    13151315         */
    13161316        var $footer ;
    1317        
    1318         /**
    1319          * Contains HTML to be output between entries. A separator is only used in 
     1317
     1318        /**
     1319         * Contains HTML to be output between entries. A separator is only used in
    13201320         * case of multiple entries.
    13211321         */
    13221322        var $separator;
    1323        
    1324         /**
    1325          * Used to prefix the stylenames to make sure they are unique 
     1323
     1324        /**
     1325         * Used to prefix the stylenames to make sure they are unique
    13261326         * and do not clash with stylenames on the users' page.
    13271327         */
    13281328        var $stylePrefix;
    1329        
     1329
    13301330        /**
    13311331         * Determines whether the links open in a new window or not.
    13321332         */
    13331333        var $openInNewWindow = true;
    1334        
     1334
    13351335        var $imageAlign ="right";
    1336        
     1336
    13371337        /**
    13381338         * In case of very simple output you may want to get rid of the style tags,
    1339          * hence this variable.  There's no equivalent on item level, but of course you can 
     1339         * hence this variable.  There's no equivalent on item level, but of course you can
    13401340         * add strings to it while iterating over the items ($this->stylelessOutput .= ...)
    13411341         * and when it is non-empty, ONLY the styleless output is printed, the rest is ignored
     
    13461346        /**
    13471347         * Writes the HTML.
    1348          * @return    string    the scripts's complete text 
     1348         * @return    string    the scripts's complete text
    13491349         */
    13501350        function createFeed() {
     
    13531353                        return $this->stylelessOutput;
    13541354                }
    1355                
     1355
    13561356                //if no stylePrefix is set, generate it yourself depending on the script name
    13571357                if ($this->stylePrefix=="") {
     
    13631363                        $targetInsert = " target='_blank'";
    13641364                }
    1365                
     1365
    13661366                // use this array to put the lines in and implode later with "document.write" javascript
    13671367                $feedArray = array();
     
    13801380                        $feedArray[] = $imageStr;
    13811381                }
    1382                
     1382
    13831383                if ($this->title) {
    13841384                        $feedArray[] = "<div class='".$this->stylePrefix."title'><a href='".$this->link."' ".$targetInsert." class='".$this->stylePrefix."title'>".
     
    13901390                                "</div>";
    13911391                }
    1392                
     1392
    13931393                if ($this->header) {
    13941394                        $feedArray[] = "<div class='".$this->stylePrefix."header'>".$this->header."</div>";
    13951395                }
    1396                
     1396
    13971397                for ($i=0;$i<count($this->items);$i++) {
    13981398                        if ($this->separator and $i > 0) {
    13991399                                $feedArray[] = "<div class='".$this->stylePrefix."separator'>".$this->separator."</div>";
    14001400                        }
    1401                        
     1401
    14021402                        if ($this->items[$i]->title) {
    14031403                                if ($this->items[$i]->link) {
    1404                                         $feedArray[] = 
     1404                                        $feedArray[] =
    14051405                                                "<div class='".$this->stylePrefix."item_title'><a href='".$this->items[$i]->link."' class='".$this->stylePrefix.
    14061406                                                "item_title'".$targetInsert.">".FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)),100).
    14071407                                                "</a></div>";
    14081408                                } else {
    1409                                         $feedArray[] = 
     1409                                        $feedArray[] =
    14101410                                                "<div class='".$this->stylePrefix."item_title'>".
    14111411                                                FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)),100).
     
    14141414                        }
    14151415                        if ($this->items[$i]->getDescription()) {
    1416                                 $feedArray[] = 
     1416                                $feedArray[] =
    14171417                                "<div class='".$this->stylePrefix."item_description'>".
    14181418                                        str_replace("]]>", "", str_replace("<![CDATA[", "", $this->items[$i]->getDescription())).
     
    14231423                        $feedArray[] = "<div class='".$this->stylePrefix."footer'>".$this->footer."</div>";
    14241424                }
    1425                
     1425
    14261426                $feed= "".join($feedArray, "\r\n");
    14271427                return $feed;
    14281428        }
    1429    
     1429
    14301430        /**
    14311431         * Overrrides parent to produce .html extensions
     
    14391439                return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".html";
    14401440        }
    1441 }       
    1442 
    1443 
    1444 /**
    1445  * JSCreator is a class that writes a js file to a specific 
     1441}
     1442
     1443
     1444/**
     1445 * JSCreator is a class that writes a js file to a specific
    14461446 * location, overriding the createFeed method of the parent HTMLCreator.
    14471447 *
     
    14501450class JSCreator extends HTMLCreator {
    14511451        var $contentType = "text/javascript";
    1452        
     1452
    14531453        /**
    14541454         * writes the javascript
    1455          * @return    string    the scripts's complete text 
    1456          */
    1457         function createFeed() 
     1455         * @return    string    the scripts's complete text
     1456         */
     1457        function createFeed()
    14581458        {
    14591459                $feed = parent::createFeed();
    14601460                $feedArray = explode("\n",$feed);
    1461                
     1461
    14621462                $jsFeed = "";
    14631463                foreach ($feedArray as $value) {
     
    14661466                return $jsFeed;
    14671467        }
    1468    
     1468
    14691469        /**
    14701470         * Overrrides parent to produce .js extensions
     
    14781478                return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".js";
    14791479        }
    1480        
    1481 }       
     1480
     1481}
    14821482
    14831483
     
    14851485/*** TEST SCRIPT *********************************************************
    14861486
    1487 //include("feedcreator.class.php"); 
    1488 
    1489 $rss = new UniversalFeedCreator(); 
    1490 $rss->useCached(); 
    1491 $rss->title = "PHP news"; 
    1492 $rss->description = "daily news from the PHP scripting world"; 
     1487//include("feedcreator.class.php");
     1488
     1489$rss = new UniversalFeedCreator();
     1490$rss->useCached();
     1491$rss->title = "PHP news";
     1492$rss->description = "daily news from the PHP scripting world";
    14931493
    14941494//optional
     
    14971497//$rss->xslStyleSheet = "http://feedster.com/rss20.xsl";
    14981498
    1499 $rss->link = "http://www.dailyphp.net/news"; 
    1500 $rss->feedURL = "http://www.dailyphp.net/".$PHP_SELF; 
    1501 
    1502 $image = new FeedImage(); 
    1503 $image->title = "dailyphp.net logo"; 
    1504 $image->url = "http://www.dailyphp.net/images/logo.gif"; 
    1505 $image->link = "http://www.dailyphp.net"; 
    1506 $image->description = "Feed provided by dailyphp.net. Click to visit."; 
     1499$rss->link = "http://www.dailyphp.net/news";
     1500$rss->feedURL = "http://www.dailyphp.net/".$PHP_SELF;
     1501
     1502$image = new FeedImage();
     1503$image->title = "dailyphp.net logo";
     1504$image->url = "http://www.dailyphp.net/images/logo.gif";
     1505$image->link = "http://www.dailyphp.net";
     1506$image->description = "Feed provided by dailyphp.net. Click to visit.";
    15071507
    15081508//optional
     
    15101510$image->descriptionHtmlSyndicated = true;
    15111511
    1512 $rss->image = $image; 
    1513 
    1514 // get your news items from somewhere, e.g. your database: 
    1515 //mysql_select_db($dbHost, $dbUser, $dbPass); 
    1516 //$res = mysql_query("SELECT * FROM news ORDER BY newsdate DESC"); 
    1517 //while ($data = mysql_fetch_object($res)) { 
    1518         $item = new FeedItem(); 
    1519         $item->title = "This is an the test title of an item"; 
    1520         $item->link = "http://localhost/item/"; 
    1521         $item->description = "<b>description in </b><br/>HTML"; 
    1522        
     1512$rss->image = $image;
     1513
     1514// get your news items from somewhere, e.g. your database:
     1515//mysql_select_db($dbHost, $dbUser, $dbPass);
     1516//$res = mysql_query("SELECT * FROM news ORDER BY newsdate DESC");
     1517//while ($data = mysql_fetch_object($res)) {
     1518        $item = new FeedItem();
     1519        $item->title = "This is an the test title of an item";
     1520        $item->link = "http://localhost/item/";
     1521        $item->description = "<b>description in </b><br/>HTML";
     1522
    15231523        //optional
    15241524        //item->descriptionTruncSize = 500;
    15251525        $item->descriptionHtmlSyndicated = true;
    1526        
    1527         $item->date = time(); 
    1528         $item->source = "http://www.dailyphp.net"; 
    1529         $item->author = "John Doe"; 
    1530          
    1531         $rss->addItem($item); 
    1532 //} 
     1526
     1527        $item->date = time();
     1528        $item->source = "http://www.dailyphp.net";
     1529        $item->author = "John Doe";
     1530
     1531        $rss->addItem($item);
     1532//}
    15331533
    15341534// valid format strings are: RSS0.91, RSS1.0, RSS2.0, PIE0.1, MBOX, OPML, ATOM0.3, HTML, JS
    1535 echo $rss->saveFeed("RSS0.91", "feed.xml"); 
     1535echo $rss->saveFeed("RSS0.91", "feed.xml");
    15361536
    15371537
  • trunk/include/functions_notification.inc.php

    r1432 r1549  
    128128    list($count) = mysql_fetch_array(pwg_query($query));
    129129    return $count;
    130    
     130
    131131    break;
    132132    case 'info':
     
    153153      }
    154154
    155     $query = 'SELECT distinct '.implode(', ', $fields).' 
     155    $query = 'SELECT distinct '.implode(', ', $fields).'
    156156'.$query;
    157157    $result = pwg_query($query);
    158158
    159159    $infos = array();
    160  
     160
    161161    while ($row = mysql_fetch_array($result))
    162162    {
     
    346346
    347347/**
     348 * Formats a news line and adds it to the array (e.g. '5 new elements')
     349 */
     350function add_news_line(&$news, $count, $format, $url='', $add_url=false)
     351{
     352  if ($count > 0)
     353  {
     354    $line = sprintf($format, $count);
     355    if ($add_url and !empty($url) )
     356    {
     357      $line = '<a href="'.$url.'">'.$line.'</a>';
     358    }
     359    array_push($news, $line);
     360  }
     361}
     362
     363/**
    348364 * What's new between two dates ?
    349365 *
     
    355371 * @param string start date (mysql datetime format)
    356372 * @param string end date (mysql datetime format)
     373 * @param bool exclude_img_cats if true, no info about new images/categories
     374 * @param bool add_url add html A link around news
    357375 *
    358376 * @return array of news
    359377 */
    360 function news($start, $end)
     378function news($start, $end, $exclude_img_cats=false, $add_url=false)
    361379{
    362380  $news = array();
    363381
    364   $nb_new_comments = nb_new_comments($start, $end);
    365   if ($nb_new_comments > 0)
    366   {
    367     array_push($news, sprintf(l10n('%d new comments'), $nb_new_comments));
    368   }
    369 
    370   $nb_new_elements = nb_new_elements($start, $end);
    371   if ($nb_new_elements > 0)
    372   {
    373     array_push($news, sprintf(l10n('%d new elements'), $nb_new_elements));
    374   }
    375 
    376   $nb_updated_categories = nb_updated_categories($start, $end);
    377   if ($nb_updated_categories > 0)
    378   {
    379     array_push($news, sprintf(l10n('%d categories updated'),
    380                               $nb_updated_categories));
    381   }
    382  
     382  if (!$exclude_img_cats)
     383  {
     384    $nb_new_elements = nb_new_elements($start, $end);
     385    if ($nb_new_elements > 0)
     386    {
     387      array_push($news, sprintf(l10n('%d new elements'), $nb_new_elements));
     388    }
     389  }
     390
     391  if (!$exclude_img_cats)
     392  {
     393    $nb_updated_categories = nb_updated_categories($start, $end);
     394    if ($nb_updated_categories > 0)
     395    {
     396      array_push($news, sprintf(l10n('%d categories updated'),
     397                                $nb_updated_categories));
     398    }
     399  }
     400
     401  add_news_line( $news,
     402      nb_new_comments($start, $end), l10n('%d new comments'),
     403      get_root_url().'comments.php', $add_url );
     404
    383405  if (is_admin())
    384406  {
    385     $nb_unvalidated_comments = nb_unvalidated_comments($end);
    386     if ($nb_unvalidated_comments > 0)
    387     {
    388       array_push($news, sprintf(l10n('%d comments to validate'),
    389                                 $nb_unvalidated_comments));
    390     }
    391 
    392     $nb_new_users = nb_new_users($start, $end);
    393     if ($nb_new_users > 0)
    394     {
    395       array_push($news, sprintf(l10n('%d new users'), $nb_new_users));
    396     }
    397 
    398     $nb_waiting_elements = nb_waiting_elements();
    399     if ($nb_waiting_elements > 0)
    400     {
    401       array_push(
    402         $news,
    403         sprintf(
    404           l10n('%d waiting elements'),
    405           $nb_waiting_elements
    406           )
    407         );
    408     }
     407    add_news_line( $news,
     408        nb_unvalidated_comments($end), l10n('%d comments to validate'),
     409        get_root_url().'admin.php?page=comments', $add_url );
     410
     411    add_news_line( $news,
     412        nb_new_users($start, $end), l10n('%d new users'),
     413        PHPWG_ROOT_PATH.'admin.php?page=user_list', $add_url );
     414
     415    add_news_line( $news,
     416        nb_waiting_elements(), l10n('%d waiting elements'),
     417        PHPWG_ROOT_PATH.'admin.php?page=waiting', $add_url );
    409418  }
    410419
Note: See TracChangeset for help on using the changeset viewer.