From 516df145c32d1da8acbfeb164f37896585b03236 Mon Sep 17 00:00:00 2001 From: rvelices Date: Mon, 18 Sep 2006 22:51:09 +0000 Subject: 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 git-svn-id: http://piwigo.org/svn/trunk@1549 68402e56-0260-453c-a942-63ccdbb3a9ee --- include/feedcreator.class.php | 446 ++++++++++++++++----------------- include/functions_notification.inc.php | 87 ++++--- 2 files changed, 271 insertions(+), 262 deletions(-) (limited to 'include') diff --git a/include/feedcreator.class.php b/include/feedcreator.class.php index da4825b18..2b23e9472 100644 --- a/include/feedcreator.class.php +++ b/include/feedcreator.class.php @@ -78,7 +78,7 @@ v1.3 10-02-03 renamed to FeedCreator, as it not only creates RSS anymore added support for mbox tentative support for echo/necho/atom/pie/??? - + v1.2 07-20-03 intelligent auto-truncating of RSS 0.91 attributes don't create some attributes when they're not set @@ -100,51 +100,51 @@ v1.0 06-24-03 /*** GENERAL USAGE ********************************************************* -include("feedcreator.class.php"); +include("feedcreator.class.php"); -$rss = new UniversalFeedCreator(); +$rss = new UniversalFeedCreator(); $rss->useCached(); // use cached version if age<1 hour -$rss->title = "PHP news"; -$rss->description = "daily news from the PHP scripting world"; +$rss->title = "PHP news"; +$rss->description = "daily news from the PHP scripting world"; //optional $rss->descriptionTruncSize = 500; $rss->descriptionHtmlSyndicated = true; -$rss->link = "http://www.dailyphp.net/news"; -$rss->syndicationURL = "http://www.dailyphp.net/".$_SERVER["PHP_SELF"]; +$rss->link = "http://www.dailyphp.net/news"; +$rss->syndicationURL = "http://www.dailyphp.net/".$_SERVER["PHP_SELF"]; -$image = new FeedImage(); -$image->title = "dailyphp.net logo"; -$image->url = "http://www.dailyphp.net/images/logo.gif"; -$image->link = "http://www.dailyphp.net"; -$image->description = "Feed provided by dailyphp.net. Click to visit."; +$image = new FeedImage(); +$image->title = "dailyphp.net logo"; +$image->url = "http://www.dailyphp.net/images/logo.gif"; +$image->link = "http://www.dailyphp.net"; +$image->description = "Feed provided by dailyphp.net. Click to visit."; //optional $image->descriptionTruncSize = 500; $image->descriptionHtmlSyndicated = true; -$rss->image = $image; - -// get your news items from somewhere, e.g. your database: -mysql_select_db($dbHost, $dbUser, $dbPass); -$res = mysql_query("SELECT * FROM news ORDER BY newsdate DESC"); -while ($data = mysql_fetch_object($res)) { - $item = new FeedItem(); - $item->title = $data->title; - $item->link = $data->url; - $item->description = $data->short; - +$rss->image = $image; + +// get your news items from somewhere, e.g. your database: +mysql_select_db($dbHost, $dbUser, $dbPass); +$res = mysql_query("SELECT * FROM news ORDER BY newsdate DESC"); +while ($data = mysql_fetch_object($res)) { + $item = new FeedItem(); + $item->title = $data->title; + $item->link = $data->url; + $item->description = $data->short; + //optional item->descriptionTruncSize = 500; item->descriptionHtmlSyndicated = true; - $item->date = $data->newsdate; - $item->source = "http://www.dailyphp.net"; - $item->author = "John Doe"; - - $rss->addItem($item); -} + $item->date = $data->newsdate; + $item->source = "http://www.dailyphp.net"; + $item->author = "John Doe"; + + $rss->addItem($item); +} // valid format strings are: RSS0.91, RSS1.0, RSS2.0, PIE0.1 (deprecated), // MBOX, OPML, ATOM, ATOM0.3, HTML, JS @@ -179,12 +179,12 @@ class FeedItem extends HtmlDescribable { * Mandatory attributes of an item. */ var $title, $description, $link; - + /** * Optional attributes of an item. */ var $author, $authorEmail, $image, $category, $comments, $guid, $source, $creator; - + /** * Publishing date of an item. May be in one of the following formats: * @@ -199,7 +199,7 @@ class FeedItem extends HtmlDescribable { * 1043082341 */ var $date; - + /** * Any additional elements to include as an assiciated array. All $key => $value pairs * will be included unencoded in the feed item in the form @@ -226,7 +226,7 @@ class FeedImage extends HtmlDescribable { * Mandatory attributes of an image. */ var $title, $url, $link; - + /** * Optional attributes of an image. */ @@ -244,16 +244,16 @@ class HtmlDescribable { * Indicates whether the description field should be rendered in HTML. */ var $descriptionHtmlSyndicated; - + /** * Indicates whether and to how many characters a description should be truncated. */ var $descriptionTruncSize; - + /** * Returns a formatted description field, depending on descriptionHtmlSyndicated and * $descriptionTruncSize properties - * @return string the formatted description + * @return string the formatted description */ function getDescription() { $descriptionField = new FeedHtmlField($this->description); @@ -267,7 +267,7 @@ class HtmlDescribable { /** * An FeedHtmlField describes and generates - * a feed, item or image html field (probably a description). Output is + * a feed, item or image html field (probably a description). Output is * generated based on $truncSize, $syndicateHtml properties. * @author Pascal Van Hecke * @version 1.6 @@ -277,13 +277,13 @@ class FeedHtmlField { * Mandatory attributes of a FeedHtmlField. */ var $rawFieldContent; - + /** * Optional attributes of a FeedHtmlField. - * + * */ var $truncSize, $syndicateHtml; - + /** * Creates a new instance of FeedHtmlField. * @param $string: if given, sets the rawFieldContent property @@ -293,14 +293,14 @@ class FeedHtmlField { $this->rawFieldContent = $parFieldContent; } } - - + + /** * Creates the right output, depending on $truncSize, $syndicateHtml properties. * @return string the formatted field */ function output() { - // when field available and syndicated in html we assume + // when field available and syndicated in html we assume // - valid html in $rawFieldContent and we enclose in CDATA tags // - no truncation (truncating risks producing invalid html) if (!$this->rawFieldContent) { @@ -332,62 +332,62 @@ class FeedHtmlField { */ class UniversalFeedCreator extends FeedCreator { var $_feed; - + function _setFormat($format) { switch (strtoupper($format)) { - + case "2.0": // fall through case "RSS2.0": $this->_feed = new RSSCreator20(); break; - + case "1.0": // fall through case "RSS1.0": $this->_feed = new RSSCreator10(); break; - + case "0.91": // fall through case "RSS0.91": $this->_feed = new RSSCreator091(); break; - + case "PIE0.1": $this->_feed = new PIECreator01(); break; - + case "MBOX": $this->_feed = new MBOXCreator(); break; - + case "OPML": $this->_feed = new OPMLCreator(); break; - + case "ATOM": // fall through: always the latest ATOM version - + case "ATOM0.3": $this->_feed = new AtomCreator03(); break; - + case "HTML": $this->_feed = new HTMLCreator(); break; - + case "JS": // fall through case "JAVASCRIPT": $this->_feed = new JSCreator(); break; - + default: $this->_feed = new RSSCreator091(); break; } - + $vars = get_object_vars($this); foreach ($vars as $key => $value) { // prevent overwriting of properties "contentType", "encoding"; do not copy "_feed" itself @@ -396,7 +396,7 @@ class UniversalFeedCreator extends FeedCreator { } } } - + /** * Creates a syndication feed based on the items previously added. * @@ -409,14 +409,14 @@ class UniversalFeedCreator extends FeedCreator { $this->_setFormat($format); return $this->_feed->createFeed(); } - - - + + + /** * Saves this feed as a file on the local disk. After the file is saved, an HTTP redirect * header may be sent to redirect the use to the newly created file. * @since 1.4 - * + * * @param string format format the feed should comply to. Valid values are: * "PIE0.1" (deprecated), "mbox", "RSS0.91", "RSS1.0", "RSS2.0", "OPML", "ATOM", "ATOM0.3", "HTML", "JS" * @param string filename 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()). @@ -462,8 +462,8 @@ class FeedCreator extends HtmlDescribable { * Mandatory attributes of a feed. */ var $title, $description, $link; - - + + /** * Optional attributes of a feed. */ @@ -474,29 +474,29 @@ class FeedCreator extends HtmlDescribable { * Ignored in the output when empty. */ var $xslStyleSheet = ""; - - + + /** * @access private */ var $items = Array(); - - + + /** * This feed's MIME content type. * @since 1.4 * @access private */ var $contentType = "application/xml"; - - + + /** * This feed's character encoding. * @since 1.6.1 **/ var $encoding = "ISO-8859-1"; - - + + /** * Any additional elements to include as an assiciated array. All $key => $value pairs * will be included unencoded in the feed in the form @@ -506,8 +506,8 @@ class FeedCreator extends HtmlDescribable { * the FeedCreator class used. */ var $additionalElements = Array(); - - + + /** * Adds an FeedItem to the feed. * @@ -517,15 +517,15 @@ class FeedCreator extends HtmlDescribable { function addItem($item) { $this->items[] = $item; } - - + + /** * Truncates a string to a certain length at the most sensible point. * First, if there's a '.' character near the end of the string, the string is truncated after this character. * If there is no '.', the string is truncated after the last ' ' character. * If the string is truncated, " ..." is appended. * If the string is already shorter than $length, it is returned unchanged. - * + * * @static * @param string string A string to be truncated. * @param int length the maximum length the string should be truncated to @@ -535,7 +535,7 @@ class FeedCreator extends HtmlDescribable { if (strlen($string)<=$length) { return $string; } - + $pos = strrpos($string,"."); if ($pos>=$length-4) { $string = substr($string,0,$length-4); @@ -544,7 +544,7 @@ class FeedCreator extends HtmlDescribable { if ($pos>=$length*0.4) { return substr($string,0,$pos+1)." ..."; } - + $pos = strrpos($string," "); if ($pos>=$length-4) { $string = substr($string,0,$length-4); @@ -553,12 +553,12 @@ class FeedCreator extends HtmlDescribable { if ($pos>=$length*0.4) { return substr($string,0,$pos)." ..."; } - + return substr($string,0,$length-4)." ..."; - + } - - + + /** * Creates a comment indicating the generator of this feed. * The format of this comment seems to be recognized by @@ -567,8 +567,8 @@ class FeedCreator extends HtmlDescribable { function _createGeneratorComment() { return "\n"; } - - + + /** * Creates a string containing all additional elements specified in * $additionalElements. @@ -585,32 +585,32 @@ class FeedCreator extends HtmlDescribable { } return $ae; } - + function _createStylesheetReferences() { $xml = ""; if (isset($this->cssStyleSheet)) $xml .= "cssStyleSheet."\" type=\"text/css\"?>\n"; if ($this->xslStyleSheet) $xml .= "xslStyleSheet."\" type=\"text/xsl\"?>\n"; return $xml; } - - + + /** * Builds the feed's text. * @abstract - * @return string the feed's complete text + * @return string the feed's complete text */ function createFeed() { } - + /** * Generate a filename for the feed cache file. The result will be $_SERVER["PHP_SELF"] with the extension changed to .xml. * For example: - * + * * echo $_SERVER["PHP_SELF"]."\n"; * echo FeedCreator::_generateFilename(); - * + * * would produce: - * + * * /rss/latestnews.php * latestnews.xml * @@ -622,23 +622,23 @@ class FeedCreator extends HtmlDescribable { $fileInfo = pathinfo($_SERVER["PHP_SELF"]); return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".xml"; } - - + + /** * @since 1.4 * @access private */ function _redirect($filename) { // attention, heavily-commented-out-area - + // maybe use this in addition to file time checking //Header("Expires: ".date("r",time()+$this->_timeout)); - + /* no caching at all, doesn't seem to work as good: Header("Cache-Control: no-cache"); Header("Pragma: no-cache"); */ - + // HTTP redirect, some feed readers' simple HTTP implementations don't follow it //Header("Location: ".$filename); @@ -647,7 +647,7 @@ class FeedCreator extends HtmlDescribable { readfile($filename, "r"); die(); } - + /** * Turns on caching and checks if there is a recent version of this feed in the cache. * If there is, an HTTP redirect header is sent. @@ -667,13 +667,13 @@ class FeedCreator extends HtmlDescribable { $this->_redirect($filename); } } - - + + /** * Saves this feed as a file on the local disk. After the file is saved, a redirect * header may be sent to redirect the user to the newly created file. * @since 1.4 - * + * * @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()). * @param redirect boolean optional send an HTTP redirect header or not. If true, the user will be automatically redirected to the created file. */ @@ -692,7 +692,7 @@ class FeedCreator extends HtmlDescribable { echo "
Error creating feed file, please check write permissions.
"; } } - + } @@ -702,7 +702,7 @@ class FeedCreator extends HtmlDescribable { */ class FeedDate { var $unix; - + /** * Creates a new instance of FeedDate representing a given date. * Accepts RFC 822, ISO 8601 date formats as well as unix time stamps. @@ -710,7 +710,7 @@ class FeedDate { */ function FeedDate($dateString="") { if ($dateString=="") $dateString = date("r"); - + if (is_integer($dateString)) { $this->unix = $dateString; return; @@ -766,7 +766,7 @@ class FeedDate { if (TIME_ZONE!="") $date .= " ".str_replace(":","",TIME_ZONE); return $date; } - + /** * Gets the date stored in this FeedDate as an ISO 8601 date. * @@ -778,7 +778,7 @@ class FeedDate { if (TIME_ZONE!="") $date = str_replace("+00:00",TIME_ZONE,$date); return $date; } - + /** * Gets the date stored in this FeedDate as unix time stamp. * @@ -802,9 +802,9 @@ class RSSCreator10 extends FeedCreator { /** * Builds the RSS feed's text. The feed will be compliant to RDF Site Summary (RSS) 1.0. * The feed will contain all items previously added in the same order. - * @return string the feed's complete text + * @return string the feed's complete text */ - function createFeed() { + function createFeed() { $feed = "encoding."\"?>\n"; $feed.= $this->_createGeneratorComment(); if ($this->cssStyleSheet=="") { @@ -813,7 +813,7 @@ class RSSCreator10 extends FeedCreator { $feed.= $this->_createStylesheetReferences(); $feed.= "\n"; $feed.= " syndicationURL."\">\n"; @@ -841,7 +841,7 @@ class RSSCreator10 extends FeedCreator { $feed.= " \n"; } $feed.= $this->_createAdditionalElements($this->additionalElements, " "); - + for ($i=0;$iitems);$i++) { $feed.= " items[$i]->link)."\">\n"; //$feed.= " Posting\n"; @@ -888,7 +888,7 @@ class RSSCreator091 extends FeedCreator { $this->_setRSSVersion("0.91"); $this->contentType = "application/rss+xml"; } - + /** * Sets this RSS feed's version number. * @access private @@ -900,13 +900,13 @@ class RSSCreator091 extends FeedCreator { /** * Builds the RSS feed's text. The feed will be compliant to RDF Site Summary (RSS) 1.0. * The feed will contain all items previously added in the same order. - * @return string the feed's complete text + * @return string the feed's complete text */ function createFeed() { $feed = "encoding."\"?>\n"; $feed.= $this->_createGeneratorComment(); $feed.= $this->_createStylesheetReferences(); - $feed.= "RSSVersion."\">\n"; + $feed.= "RSSVersion."\">\n"; $feed.= " \n"; $feed.= " ".FeedCreator::iTrunc(htmlspecialchars($this->title),100)."\n"; $this->descriptionTruncSize = 500; @@ -918,8 +918,8 @@ class RSSCreator091 extends FeedCreator { if ($this->image!=null) { $feed.= " \n"; - $feed.= " ".$this->image->url."\n"; - $feed.= " ".FeedCreator::iTrunc(htmlspecialchars($this->image->title),100)."\n"; + $feed.= " ".$this->image->url."\n"; + $feed.= " ".FeedCreator::iTrunc(htmlspecialchars($this->image->title),100)."\n"; $feed.= " ".$this->image->link."\n"; if ($this->image->width!="") { $feed.= " ".$this->image->width."\n"; @@ -973,7 +973,7 @@ class RSSCreator091 extends FeedCreator { $feed.= " ".FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)),100)."\n"; $feed.= " ".htmlspecialchars($this->items[$i]->link)."\n"; $feed.= " ".$this->items[$i]->getDescription()."\n"; - + if ($this->items[$i]->author!="") { $feed.= " ".htmlspecialchars($this->items[$i]->author)."\n"; } @@ -994,7 +994,7 @@ class RSSCreator091 extends FeedCreator { $feed.= " ".htmlspecialchars($itemDate->rfc822())."\n"; } if ($this->items[$i]->guid!="") { - $feed.= " ".htmlspecialchars($this->items[$i]->guid)."\n"; + $feed.= " ".htmlspecialchars($this->items[$i]->guid)."\n"; } $feed.= $this->_createAdditionalElements($this->items[$i]->additionalElements, " "); $feed.= " \n"; @@ -1019,7 +1019,7 @@ class RSSCreator20 extends RSSCreator091 { function RSSCreator20() { parent::_setRSSVersion("2.0"); } - + } @@ -1032,15 +1032,15 @@ class RSSCreator20 extends RSSCreator091 { * @author Scott Reynen and Kai Blankenhorn */ class PIECreator01 extends FeedCreator { - + function PIECreator01() { $this->encoding = "utf-8"; } - + function createFeed() { $feed = "encoding."\"?>\n"; $feed.= $this->_createStylesheetReferences(); - $feed.= "\n"; + $feed.= "\n"; $feed.= " ".FeedCreator::iTrunc(htmlspecialchars($this->title),100)."\n"; $this->truncSize = 500; $feed.= " ".$this->getDescription()."\n"; @@ -1081,7 +1081,7 @@ class PIECreator01 extends FeedCreator { * for the feed or an author for every single feed item. * * Some elements have not been implemented yet. These are (incomplete list): - * author URL, item author's email and URL, item contents, alternate links, + * author URL, item author's email and URL, item contents, alternate links, * other link content types than text/html. Some of them may be created with * AtomCreator03::additionalElements. * @@ -1095,7 +1095,7 @@ class AtomCreator03 extends FeedCreator { $this->contentType = "application/atom+xml"; $this->encoding = "utf-8"; } - + function createFeed() { $feed = "encoding."\"?>\n"; $feed.= $this->_createGeneratorComment(); @@ -1104,7 +1104,7 @@ class AtomCreator03 extends FeedCreator { if ($this->language!="") { $feed.= " xml:lang=\"".$this->language."\""; } - $feed.= ">\n"; + $feed.= ">\n"; $feed.= " ".htmlspecialchars($this->title)."\n"; $feed.= " ".htmlspecialchars($this->description)."\n"; $feed.= " link)."\"/>\n"; @@ -1163,41 +1163,41 @@ class MBOXCreator extends FeedCreator { $this->contentType = "text/plain"; $this->encoding = "ISO-8859-15"; } - - function qp_enc($input = "", $line_max = 76) { - $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); - $lines = preg_split("/(?:\r\n|\r|\n)/", $input); - $eol = "\r\n"; - $escape = "="; - $output = ""; - while( list(, $line) = each($lines) ) { - //$line = rtrim($line); // remove trailing white space -> no =20\r\n necessary - $linlen = strlen($line); - $newline = ""; - for($i = 0; $i < $linlen; $i++) { - $c = substr($line, $i, 1); - $dec = ord($c); - if ( ($dec == 32) && ($i == ($linlen - 1)) ) { // convert space at eol only - $c = "=20"; - } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required - $h2 = floor($dec/16); $h1 = floor($dec%16); - $c = $escape.$hex["$h2"].$hex["$h1"]; - } - if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted - $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay - $newline = ""; - } - $newline .= $c; - } // end of for - $output .= $newline.$eol; - } - return trim($output); + + function qp_enc($input = "", $line_max = 76) { + $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); + $lines = preg_split("/(?:\r\n|\r|\n)/", $input); + $eol = "\r\n"; + $escape = "="; + $output = ""; + while( list(, $line) = each($lines) ) { + //$line = rtrim($line); // remove trailing white space -> no =20\r\n necessary + $linlen = strlen($line); + $newline = ""; + for($i = 0; $i < $linlen; $i++) { + $c = substr($line, $i, 1); + $dec = ord($c); + if ( ($dec == 32) && ($i == ($linlen - 1)) ) { // convert space at eol only + $c = "=20"; + } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required + $h2 = floor($dec/16); $h1 = floor($dec%16); + $c = $escape.$hex["$h2"].$hex["$h1"]; + } + if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted + $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay + $newline = ""; + } + $newline .= $c; + } // end of for + $output .= $newline.$eol; + } + return trim($output); } - + /** * Builds the MBOX contents. - * @return string the feed's complete text + * @return string the feed's complete text */ function createFeed() { for ($i=0;$iitems);$i++) { @@ -1223,7 +1223,7 @@ class MBOXCreator extends FeedCreator { } return $feed; } - + /** * Generate a filename for the feed cache file. Overridden from FeedCreator to prevent XML data types. * @return string the feed cache filename @@ -1239,7 +1239,7 @@ class MBOXCreator extends FeedCreator { /** * OPMLCreator is a FeedCreator that implements OPML 1.0. - * + * * @see http://opml.scripting.com/spec * @author Dirk Clemens, Kai Blankenhorn * @since 1.5 @@ -1249,8 +1249,8 @@ class OPMLCreator extends FeedCreator { function OPMLCreator() { $this->encoding = "utf-8"; } - - function createFeed() { + + function createFeed() { $feed = "encoding."\"?>\n"; $feed.= $this->_createGeneratorComment(); $feed.= $this->_createStylesheetReferences(); @@ -1291,12 +1291,12 @@ class OPMLCreator extends FeedCreator { /** - * HTMLCreator is a FeedCreator that writes an HTML feed file to a specific + * HTMLCreator is a FeedCreator that writes an HTML feed file to a specific * location, overriding the createFeed method of the parent FeedCreator. * The HTML produced can be included over http by scripting languages, or serve * as the source for an IFrame. * All output by this class is embedded in
tags to enable formatting - * using CSS. + * using CSS. * * @author Pascal Van Hecke * @since 1.7 @@ -1304,39 +1304,39 @@ class OPMLCreator extends FeedCreator { class HTMLCreator extends FeedCreator { var $contentType = "text/html"; - + /** * Contains HTML to be output at the start of the feed's html representation. */ var $header; - + /** * Contains HTML to be output at the end of the feed's html representation. */ var $footer ; - + /** - * Contains HTML to be output between entries. A separator is only used in + * Contains HTML to be output between entries. A separator is only used in * case of multiple entries. */ var $separator; - + /** - * Used to prefix the stylenames to make sure they are unique + * Used to prefix the stylenames to make sure they are unique * and do not clash with stylenames on the users' page. */ var $stylePrefix; - + /** * Determines whether the links open in a new window or not. */ var $openInNewWindow = true; - + var $imageAlign ="right"; - + /** * In case of very simple output you may want to get rid of the style tags, - * hence this variable. There's no equivalent on item level, but of course you can + * hence this variable. There's no equivalent on item level, but of course you can * add strings to it while iterating over the items ($this->stylelessOutput .= ...) * and when it is non-empty, ONLY the styleless output is printed, the rest is ignored * in the function createFeed(). @@ -1345,14 +1345,14 @@ class HTMLCreator extends FeedCreator { /** * Writes the HTML. - * @return string the scripts's complete text + * @return string the scripts's complete text */ function createFeed() { // if there is styleless output, use the content of this variable and ignore the rest if ($this->stylelessOutput!="") { return $this->stylelessOutput; } - + //if no stylePrefix is set, generate it yourself depending on the script name if ($this->stylePrefix=="") { $this->stylePrefix = str_replace(".", "_", $this->_generateFilename())."_"; @@ -1362,7 +1362,7 @@ class HTMLCreator extends FeedCreator { if ($this->openInNewWindow) { $targetInsert = " target='_blank'"; } - + // use this array to put the lines in and implode later with "document.write" javascript $feedArray = array(); if ($this->image!=null) { @@ -1379,7 +1379,7 @@ class HTMLCreator extends FeedCreator { $imageStr .="/>"; $feedArray[] = $imageStr; } - + if ($this->title) { $feedArray[] = ""; @@ -1389,31 +1389,31 @@ class HTMLCreator extends FeedCreator { str_replace("]]>", "", str_replace("getDescription())). ""; } - + if ($this->header) { $feedArray[] = "
".$this->header."
"; } - + for ($i=0;$iitems);$i++) { if ($this->separator and $i > 0) { $feedArray[] = "
".$this->separator."
"; } - + if ($this->items[$i]->title) { if ($this->items[$i]->link) { - $feedArray[] = + $feedArray[] = ""; } else { - $feedArray[] = + $feedArray[] = "
". FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)),100). "
"; } } if ($this->items[$i]->getDescription()) { - $feedArray[] = + $feedArray[] = "
". str_replace("]]>", "", str_replace("items[$i]->getDescription())). "
"; @@ -1422,11 +1422,11 @@ class HTMLCreator extends FeedCreator { if ($this->footer) { $feedArray[] = "
".$this->footer."
"; } - + $feed= "".join($feedArray, "\r\n"); return $feed; } - + /** * Overrrides parent to produce .html extensions * @@ -1438,34 +1438,34 @@ class HTMLCreator extends FeedCreator { $fileInfo = pathinfo($_SERVER["PHP_SELF"]); return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".html"; } -} +} /** - * JSCreator is a class that writes a js file to a specific + * JSCreator is a class that writes a js file to a specific * location, overriding the createFeed method of the parent HTMLCreator. * * @author Pascal Van Hecke */ class JSCreator extends HTMLCreator { var $contentType = "text/javascript"; - + /** * writes the javascript - * @return string the scripts's complete text + * @return string the scripts's complete text */ - function createFeed() + function createFeed() { $feed = parent::createFeed(); $feedArray = explode("\n",$feed); - + $jsFeed = ""; foreach ($feedArray as $value) { $jsFeed .= "document.write('".trim(addslashes($value))."');\n"; } return $jsFeed; } - + /** * Overrrides parent to produce .js extensions * @@ -1477,62 +1477,62 @@ class JSCreator extends HTMLCreator { $fileInfo = pathinfo($_SERVER["PHP_SELF"]); return substr($fileInfo["basename"],0,-(strlen($fileInfo["extension"])+1)).".js"; } - -} + +} /*** TEST SCRIPT ********************************************************* -//include("feedcreator.class.php"); +//include("feedcreator.class.php"); -$rss = new UniversalFeedCreator(); -$rss->useCached(); -$rss->title = "PHP news"; -$rss->description = "daily news from the PHP scripting world"; +$rss = new UniversalFeedCreator(); +$rss->useCached(); +$rss->title = "PHP news"; +$rss->description = "daily news from the PHP scripting world"; //optional //$rss->descriptionTruncSize = 500; //$rss->descriptionHtmlSyndicated = true; //$rss->xslStyleSheet = "http://feedster.com/rss20.xsl"; -$rss->link = "http://www.dailyphp.net/news"; -$rss->feedURL = "http://www.dailyphp.net/".$PHP_SELF; +$rss->link = "http://www.dailyphp.net/news"; +$rss->feedURL = "http://www.dailyphp.net/".$PHP_SELF; -$image = new FeedImage(); -$image->title = "dailyphp.net logo"; -$image->url = "http://www.dailyphp.net/images/logo.gif"; -$image->link = "http://www.dailyphp.net"; -$image->description = "Feed provided by dailyphp.net. Click to visit."; +$image = new FeedImage(); +$image->title = "dailyphp.net logo"; +$image->url = "http://www.dailyphp.net/images/logo.gif"; +$image->link = "http://www.dailyphp.net"; +$image->description = "Feed provided by dailyphp.net. Click to visit."; //optional $image->descriptionTruncSize = 500; $image->descriptionHtmlSyndicated = true; -$rss->image = $image; - -// get your news items from somewhere, e.g. your database: -//mysql_select_db($dbHost, $dbUser, $dbPass); -//$res = mysql_query("SELECT * FROM news ORDER BY newsdate DESC"); -//while ($data = mysql_fetch_object($res)) { - $item = new FeedItem(); - $item->title = "This is an the test title of an item"; - $item->link = "http://localhost/item/"; - $item->description = "description in
HTML"; - +$rss->image = $image; + +// get your news items from somewhere, e.g. your database: +//mysql_select_db($dbHost, $dbUser, $dbPass); +//$res = mysql_query("SELECT * FROM news ORDER BY newsdate DESC"); +//while ($data = mysql_fetch_object($res)) { + $item = new FeedItem(); + $item->title = "This is an the test title of an item"; + $item->link = "http://localhost/item/"; + $item->description = "description in
HTML"; + //optional //item->descriptionTruncSize = 500; $item->descriptionHtmlSyndicated = true; - - $item->date = time(); - $item->source = "http://www.dailyphp.net"; - $item->author = "John Doe"; - - $rss->addItem($item); -//} + + $item->date = time(); + $item->source = "http://www.dailyphp.net"; + $item->author = "John Doe"; + + $rss->addItem($item); +//} // valid format strings are: RSS0.91, RSS1.0, RSS2.0, PIE0.1, MBOX, OPML, ATOM0.3, HTML, JS -echo $rss->saveFeed("RSS0.91", "feed.xml"); +echo $rss->saveFeed("RSS0.91", "feed.xml"); diff --git a/include/functions_notification.inc.php b/include/functions_notification.inc.php index 4061e57c8..de13a28c9 100644 --- a/include/functions_notification.inc.php +++ b/include/functions_notification.inc.php @@ -127,7 +127,7 @@ function custom_notification_query($action, $type, $start, $end) '.$query; list($count) = mysql_fetch_array(pwg_query($query)); return $count; - + break; case 'info': switch($type) @@ -152,12 +152,12 @@ function custom_notification_query($action, $type, $start, $end) break; } - $query = 'SELECT distinct '.implode(', ', $fields).' + $query = 'SELECT distinct '.implode(', ', $fields).' '.$query; $result = pwg_query($query); $infos = array(); - + while ($row = mysql_fetch_array($result)) { array_push($infos, $row); @@ -344,6 +344,22 @@ function news_exists($start, $end) ); } +/** + * Formats a news line and adds it to the array (e.g. '5 new elements') + */ +function add_news_line(&$news, $count, $format, $url='', $add_url=false) +{ + if ($count > 0) + { + $line = sprintf($format, $count); + if ($add_url and !empty($url) ) + { + $line = ''.$line.''; + } + array_push($news, $line); + } +} + /** * What's new between two dates ? * @@ -354,58 +370,51 @@ function news_exists($start, $end) * * @param string start date (mysql datetime format) * @param string end date (mysql datetime format) + * @param bool exclude_img_cats if true, no info about new images/categories + * @param bool add_url add html A link around news * * @return array of news */ -function news($start, $end) +function news($start, $end, $exclude_img_cats=false, $add_url=false) { $news = array(); - $nb_new_comments = nb_new_comments($start, $end); - if ($nb_new_comments > 0) + if (!$exclude_img_cats) { - array_push($news, sprintf(l10n('%d new comments'), $nb_new_comments)); + $nb_new_elements = nb_new_elements($start, $end); + if ($nb_new_elements > 0) + { + array_push($news, sprintf(l10n('%d new elements'), $nb_new_elements)); + } } - $nb_new_elements = nb_new_elements($start, $end); - if ($nb_new_elements > 0) + if (!$exclude_img_cats) { - array_push($news, sprintf(l10n('%d new elements'), $nb_new_elements)); + $nb_updated_categories = nb_updated_categories($start, $end); + if ($nb_updated_categories > 0) + { + array_push($news, sprintf(l10n('%d categories updated'), + $nb_updated_categories)); + } } - $nb_updated_categories = nb_updated_categories($start, $end); - if ($nb_updated_categories > 0) - { - array_push($news, sprintf(l10n('%d categories updated'), - $nb_updated_categories)); - } - + add_news_line( $news, + nb_new_comments($start, $end), l10n('%d new comments'), + get_root_url().'comments.php', $add_url ); + if (is_admin()) { - $nb_unvalidated_comments = nb_unvalidated_comments($end); - if ($nb_unvalidated_comments > 0) - { - array_push($news, sprintf(l10n('%d comments to validate'), - $nb_unvalidated_comments)); - } + add_news_line( $news, + nb_unvalidated_comments($end), l10n('%d comments to validate'), + get_root_url().'admin.php?page=comments', $add_url ); - $nb_new_users = nb_new_users($start, $end); - if ($nb_new_users > 0) - { - array_push($news, sprintf(l10n('%d new users'), $nb_new_users)); - } + add_news_line( $news, + nb_new_users($start, $end), l10n('%d new users'), + PHPWG_ROOT_PATH.'admin.php?page=user_list', $add_url ); - $nb_waiting_elements = nb_waiting_elements(); - if ($nb_waiting_elements > 0) - { - array_push( - $news, - sprintf( - l10n('%d waiting elements'), - $nb_waiting_elements - ) - ); - } + add_news_line( $news, + nb_waiting_elements(), l10n('%d waiting elements'), + PHPWG_ROOT_PATH.'admin.php?page=waiting', $add_url ); } return $news; -- cgit v1.2.3