aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2006-09-18 22:51:09 +0000
committerrvelices <rv-github@modusoptimus.com>2006-09-18 22:51:09 +0000
commit516df145c32d1da8acbfeb164f37896585b03236 (patch)
tree4fba8346cbe28281a582666b109bb1330df98e42
parentfc19eb794daf437ded2d75e8ab0d3c3f8c5bf62d (diff)
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
-rw-r--r--feed.php135
-rw-r--r--include/feedcreator.class.php446
-rw-r--r--include/functions_notification.inc.php87
3 files changed, 393 insertions, 275 deletions
diff --git a/feed.php b/feed.php
index ce307ece2..61fd63300 100644
--- a/feed.php
+++ b/feed.php
@@ -109,10 +109,10 @@ SELECT uf.user_id AS id,
;';
$user = mysql_fetch_array(pwg_query($query));
}
-else
+
+if ( empty($user) )
{
- echo l10n('Unknown feed identifier');
- exit();
+ page_not_found('Unknown/missing feed identifier');
}
$user['forbidden_categories'] = calculate_permissions($user['id'],
@@ -126,9 +126,16 @@ list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
include_once(PHPWG_ROOT_PATH.'include/feedcreator.class.php');
+$base_url = 'http://'.$_SERVER["HTTP_HOST"].cookie_path();
+if ( strrpos($base_url, '/') !== strlen($base_url)-1 )
+{
+ $base_url .= '/';
+}
+$page['root_path']=$base_url;
+
$rss = new UniversalFeedCreator();
-$rss->title = $conf['gallery_title'].', notifications';
+$rss->title = $conf['gallery_title'];
$rss->title.= ' (as '.$user['username'].')';
$rss->link = $conf['gallery_url'];
@@ -137,14 +144,14 @@ $rss->link = $conf['gallery_url'];
// | Feed creation |
// +-----------------------------------------------------------------------+
-$news = news($user['last_check'], $dbnow);
+$news = news($user['last_check'], $dbnow, true);
if (count($news) > 0)
{
- $item = new FeedItem();
+ $item = new FeedItem();
$item->title = sprintf(l10n('New on %s'), $dbnow);
$item->link = $conf['gallery_url'];
-
+
// content creation
$item->description = '<ul>';
foreach ($news as $line)
@@ -153,19 +160,121 @@ if (count($news) > 0)
}
$item->description.= '</ul>';
$item->descriptionHtmlSyndicated = true;
-
+
$item->date = ts_to_iso8601(mysqldt_to_ts($dbnow));
- $item->author = 'PhpWebGallery notifier';
-
+ $item->author = 'PhpWebGallery notifier';
+ $item->guid= sprintf('%s', $dbnow);;
+
$rss->addItem($item);
-}
-$query = '
+ $query = '
UPDATE '.USER_FEED_TABLE.'
SET last_check = \''.$dbnow.'\'
WHERE id = \''.$_GET['feed'].'\'
;';
-pwg_query($query);
+ pwg_query($query);
+}
+
+
+// build items for new images/albums
+$query = '
+SELECT date_available,
+ COUNT(DISTINCT id) nb_images,
+ COUNT(DISTINCT category_id) nb_cats
+ FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id=image_id
+ WHERE category_id NOT IN ('.$user['forbidden_categories'].')
+ GROUP BY date_available
+ ORDER BY date_available DESC
+ LIMIT 0,5
+;';
+$result = pwg_query($query);
+$dates = array();
+while ($row = mysql_fetch_array($result))
+{
+ array_push($dates, $row);
+}
+
+foreach($dates as $date_detail)
+{ // for each recent post date we create a feed item
+ $date = $date_detail['date_available'];
+ $exploded_date = explode_mysqldt($date);
+ $item = new FeedItem();
+ $item->title = sprintf(l10n('%d new elements'), $date_detail['nb_images']);
+ $item->title .= ' ('.$lang['month'][(int)$exploded_date['month']].' '.$exploded_date['day'].')';
+ $item->link = make_index_url(
+ array(
+ 'chronology_field' => 'posted',
+ 'chronology_style'=> 'monthly',
+ 'chronology_view' => 'calendar',
+ 'chronology_date' => explode('-', substr($date,0,10) )
+ )
+ );
+
+ $item->description .=
+ '<a href="'.make_index_url().'">'.$conf['gallery_title'].'</a><br/> ';
+
+ $item->description .=
+ '<li>'
+ .sprintf(l10n('%d new elements'), $date_detail['nb_images'])
+ .' ('
+ .'<a href="'.make_index_url(array('section'=>'recent_pics')).'">'
+ .l10n('recent_pics_cat').'</a>'
+ .')'
+ .'</li>';
+
+ // get some thumbnails ...
+ $query = '
+SELECT DISTINCT id, path, name, tn_ext
+ FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id=image_id
+ WHERE category_id NOT IN ('.$user['forbidden_categories'].')
+ AND date_available="'.$date.'"
+ AND tn_ext IS NOT NULL
+ LIMIT 0,6
+;';
+ $result = pwg_query($query);
+ while ($row = mysql_fetch_array($result))
+ {
+ $tn_src = get_thumbnail_src($row['path'], @$row['tn_ext']);
+ $item->description .= '<img src="'.$tn_src.'"/>';
+ }
+ $item->description .= '...<br/>';
+
+
+ $item->description .=
+ '<li>'
+ .sprintf(l10n('%d categories updated'), $date_detail['nb_cats'])
+ .'</li>';
+ // get some categories ...
+ $query = '
+SELECT DISTINCT c.uppercats, COUNT(DISTINCT i.id) img_count
+ FROM '.IMAGES_TABLE.' i INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON i.id=image_id
+ INNER JOIN '.CATEGORIES_TABLE.' c ON c.id=category_id
+ WHERE category_id NOT IN ('.$user['forbidden_categories'].')
+ AND date_available="'.$date.'"
+ GROUP BY category_id
+ ORDER BY img_count DESC
+ LIMIT 0,6
+;';
+ $result = pwg_query($query);
+ $item->description .= '<ul>';
+ while ($row = mysql_fetch_array($result))
+ {
+ $item->description .=
+ '<li>'
+ .get_cat_display_name_cache($row['uppercats'])
+ .' ('.sprintf(l10n('%d new elements'), $row['img_count']).')'
+ .'</li>';
+ }
+ $item->description .= '</ul>';
+
+ $item->descriptionHtmlSyndicated = true;
+
+ $item->date = ts_to_iso8601(mysqldt_to_ts($date));
+ $item->author = 'PhpWebGallery notifier';
+ $item->guid= sprintf('%s', 'pics-'.$date);;
+
+ $rss->addItem($item);
+}
// send XML feed
echo $rss->saveFeed('RSS2.0', '', true);
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 <feedcreator.class.php@vanhecke.info>
* @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 "<!-- generator=\"".FEEDCREATOR_VERSION."\" -->\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 .= "<?xml-stylesheet href=\"".$this->cssStyleSheet."\" type=\"text/css\"?>\n";
if ($this->xslStyleSheet) $xml .= "<?xml-stylesheet href=\"".$this->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 "<br /><b>Error creating feed file, please check write permissions.</b><br />";
}
}
-
+
}
@@ -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 = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
$feed.= $this->_createGeneratorComment();
if ($this->cssStyleSheet=="") {
@@ -813,7 +813,7 @@ class RSSCreator10 extends FeedCreator {
$feed.= $this->_createStylesheetReferences();
$feed.= "<rdf:RDF\n";
$feed.= " xmlns=\"http://purl.org/rss/1.0/\"\n";
- $feed.= " xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n";
+ $feed.= " xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n";
$feed.= " xmlns:slash=\"http://purl.org/rss/1.0/modules/slash/\"\n";
$feed.= " xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n";
$feed.= " <channel rdf:about=\"".$this->syndicationURL."\">\n";
@@ -841,7 +841,7 @@ class RSSCreator10 extends FeedCreator {
$feed.= " </image>\n";
}
$feed.= $this->_createAdditionalElements($this->additionalElements, " ");
-
+
for ($i=0;$i<count($this->items);$i++) {
$feed.= " <item rdf:about=\"".htmlspecialchars($this->items[$i]->link)."\">\n";
//$feed.= " <dc:type>Posting</dc:type>\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 = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
$feed.= $this->_createGeneratorComment();
$feed.= $this->_createStylesheetReferences();
- $feed.= "<rss version=\"".$this->RSSVersion."\">\n";
+ $feed.= "<rss version=\"".$this->RSSVersion."\">\n";
$feed.= " <channel>\n";
$feed.= " <title>".FeedCreator::iTrunc(htmlspecialchars($this->title),100)."</title>\n";
$this->descriptionTruncSize = 500;
@@ -918,8 +918,8 @@ class RSSCreator091 extends FeedCreator {
if ($this->image!=null) {
$feed.= " <image>\n";
- $feed.= " <url>".$this->image->url."</url>\n";
- $feed.= " <title>".FeedCreator::iTrunc(htmlspecialchars($this->image->title),100)."</title>\n";
+ $feed.= " <url>".$this->image->url."</url>\n";
+ $feed.= " <title>".FeedCreator::iTrunc(htmlspecialchars($this->image->title),100)."</title>\n";
$feed.= " <link>".$this->image->link."</link>\n";
if ($this->image->width!="") {
$feed.= " <width>".$this->image->width."</width>\n";
@@ -973,7 +973,7 @@ class RSSCreator091 extends FeedCreator {
$feed.= " <title>".FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)),100)."</title>\n";
$feed.= " <link>".htmlspecialchars($this->items[$i]->link)."</link>\n";
$feed.= " <description>".$this->items[$i]->getDescription()."</description>\n";
-
+
if ($this->items[$i]->author!="") {
$feed.= " <author>".htmlspecialchars($this->items[$i]->author)."</author>\n";
}
@@ -994,7 +994,7 @@ class RSSCreator091 extends FeedCreator {
$feed.= " <pubDate>".htmlspecialchars($itemDate->rfc822())."</pubDate>\n";
}
if ($this->items[$i]->guid!="") {
- $feed.= " <guid>".htmlspecialchars($this->items[$i]->guid)."</guid>\n";
+ $feed.= " <guid isPermaLink=\"false\">".htmlspecialchars($this->items[$i]->guid)."</guid>\n";
}
$feed.= $this->_createAdditionalElements($this->items[$i]->additionalElements, " ");
$feed.= " </item>\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 <scott@randomchaos.com> and Kai Blankenhorn <kaib@bitfolge.de>
*/
class PIECreator01 extends FeedCreator {
-
+
function PIECreator01() {
$this->encoding = "utf-8";
}
-
+
function createFeed() {
$feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
$feed.= $this->_createStylesheetReferences();
- $feed.= "<feed version=\"0.1\" xmlns=\"http://example.com/newformat#\">\n";
+ $feed.= "<feed version=\"0.1\" xmlns=\"http://example.com/newformat#\">\n";
$feed.= " <title>".FeedCreator::iTrunc(htmlspecialchars($this->title),100)."</title>\n";
$this->truncSize = 500;
$feed.= " <subtitle>".$this->getDescription()."</subtitle>\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 = "<?xml version=\"1.0\" encoding=\"".$this->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.= " <title>".htmlspecialchars($this->title)."</title>\n";
$feed.= " <tagline>".htmlspecialchars($this->description)."</tagline>\n";
$feed.= " <link rel=\"alternate\" type=\"text/html\" href=\"".htmlspecialchars($this->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;$i<count($this->items);$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 = "<?xml version=\"1.0\" encoding=\"".$this->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 <div></div> 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 .="/></a>";
$feedArray[] = $imageStr;
}
-
+
if ($this->title) {
$feedArray[] = "<div class='".$this->stylePrefix."title'><a href='".$this->link."' ".$targetInsert." class='".$this->stylePrefix."title'>".
FeedCreator::iTrunc(htmlspecialchars($this->title),100)."</a></div>";
@@ -1389,31 +1389,31 @@ class HTMLCreator extends FeedCreator {
str_replace("]]>", "", str_replace("<![CDATA[", "", $this->getDescription())).
"</div>";
}
-
+
if ($this->header) {
$feedArray[] = "<div class='".$this->stylePrefix."header'>".$this->header."</div>";
}
-
+
for ($i=0;$i<count($this->items);$i++) {
if ($this->separator and $i > 0) {
$feedArray[] = "<div class='".$this->stylePrefix."separator'>".$this->separator."</div>";
}
-
+
if ($this->items[$i]->title) {
if ($this->items[$i]->link) {
- $feedArray[] =
+ $feedArray[] =
"<div class='".$this->stylePrefix."item_title'><a href='".$this->items[$i]->link."' class='".$this->stylePrefix.
"item_title'".$targetInsert.">".FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)),100).
"</a></div>";
} else {
- $feedArray[] =
+ $feedArray[] =
"<div class='".$this->stylePrefix."item_title'>".
FeedCreator::iTrunc(htmlspecialchars(strip_tags($this->items[$i]->title)),100).
"</div>";
}
}
if ($this->items[$i]->getDescription()) {
- $feedArray[] =
+ $feedArray[] =
"<div class='".$this->stylePrefix."item_description'>".
str_replace("]]>", "", str_replace("<![CDATA[", "", $this->items[$i]->getDescription())).
"</div>";
@@ -1422,11 +1422,11 @@ class HTMLCreator extends FeedCreator {
if ($this->footer) {
$feedArray[] = "<div class='".$this->stylePrefix."footer'>".$this->footer."</div>";
}
-
+
$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 = "<b>description in </b><br/>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 = "<b>description in </b><br/>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);
@@ -345,6 +345,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 = '<a href="'.$url.'">'.$line.'</a>';
+ }
+ array_push($news, $line);
+ }
+}
+
+/**
* What's new between two dates ?
*
* Informations : number of new comments, number of new elements, number of
@@ -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;