source: trunk/feed.php @ 1784

Last change on this file since 1784 was 1784, checked in by rub, 17 years ago

Issue 0000598: NBM: Add new informations

Notification by mail:
Add new informations about last categories and last images like new feature of RSS notification.

2 parts:

  • Possibility to send HTML mail
  • Include last categories and last images on HTML format into notification mail

ccs & HTML experts! Please! Check, fix, improve and enhance HTML mail content!

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2007-02-06 22:55:12 +0000 (Tue, 06 Feb 2007) $
10// | last modifier : $Author: rub $
11// | revision      : $Revision: 1784 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28define('PHPWG_ROOT_PATH','./');
29include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
30include_once(PHPWG_ROOT_PATH.'include/functions_notification.inc.php');
31
32// +-----------------------------------------------------------------------+
33// |                               functions                               |
34// +-----------------------------------------------------------------------+
35
36/**
37 * creates a Unix timestamp (number of seconds since 1970-01-01 00:00:00
38 * GMT) from a MySQL datetime format (2005-07-14 23:01:37)
39 *
40 * @param string mysql datetime format
41 * @return int timestamp
42 */
43function mysqldt_to_ts($mysqldt)
44{
45  $date = explode_mysqldt($mysqldt);
46  return mktime($date['hour'], $date['minute'], $date['second'],
47                $date['month'], $date['day'], $date['year']);
48}
49
50/**
51 * creates an ISO 8601 format date (2003-01-20T18:05:41+04:00) from Unix
52 * timestamp (number of seconds since 1970-01-01 00:00:00 GMT)
53 *
54 * function copied from Dotclear project http://dotclear.net
55 *
56 * @param int timestamp
57 * @return string ISO 8601 date format
58 */
59function ts_to_iso8601($ts)
60{
61  $tz = date('O',$ts);
62  $tz = substr($tz, 0, -2).':'.substr($tz, -2);
63  return date('Y-m-d\\TH:i:s',$ts).$tz;
64}
65
66// +-----------------------------------------------------------------------+
67// |                            initialization                             |
68// +-----------------------------------------------------------------------+
69
70$feed_id= isset($_GET['feed']) ? $_GET['feed'] : '';
71$image_only=isset($_GET['image_only']);
72
73// echo '<pre>'.generate_key(50).'</pre>';
74if ( !empty($feed_id) )
75{
76  $query = '
77SELECT user_id,
78       last_check
79  FROM '.USER_FEED_TABLE.'
80  WHERE id = \''.$feed_id.'\'
81;';
82  $feed_row = mysql_fetch_assoc(pwg_query($query));
83  if ( empty($feed_row) )
84  {
85    page_not_found('Unknown/missing feed identifier');
86  }
87  if ($feed_row['user_id']!=$user['id'])
88  { // new user
89    $user = array();
90    $user = build_user( $feed_row['user_id'], true );
91  }
92}
93else
94{
95  $image_only = true;
96  if (!$user['is_the_guest'])
97  {// auto session was created - so switch to guest
98    $user = array();
99    $user = build_user( $conf['guest_id'], true );
100  }
101}
102
103list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
104
105include_once(PHPWG_ROOT_PATH.'include/feedcreator.class.php');
106
107set_make_full_url();
108
109$rss = new UniversalFeedCreator();
110
111$rss->title = $conf['gallery_title'];
112$rss->title.= ' (as '.$user['username'].')';
113
114$rss->link = $conf['gallery_url'];
115
116// +-----------------------------------------------------------------------+
117// |                            Feed creation                              |
118// +-----------------------------------------------------------------------+
119
120if (!$image_only)
121{
122  $news = news($feed_row['last_check'], $dbnow, true, true);
123
124  if (count($news) > 0)
125  {
126    $item = new FeedItem();
127    $item->title = sprintf(l10n('New on %s'),
128        format_date($dbnow, 'mysql_datetime') );
129    $item->link = $conf['gallery_url'];
130
131    // content creation
132    $item->description = '<ul>';
133    foreach ($news as $line)
134    {
135      $item->description.= '<li>'.$line.'</li>';
136    }
137    $item->description.= '</ul>';
138    $item->descriptionHtmlSyndicated = true;
139
140    $item->date = ts_to_iso8601(mysqldt_to_ts($dbnow));
141    $item->author = 'PhpWebGallery notifier';
142    $item->guid= sprintf('%s', $dbnow);;
143
144    $rss->addItem($item);
145
146    $query = '
147UPDATE '.USER_FEED_TABLE.'
148  SET last_check = \''.$dbnow.'\'
149  WHERE id = \''.$feed_id.'\'
150;';
151    pwg_query($query);
152  }
153}
154else
155{
156  if ( !empty($feed_id) )
157  {// update the last check to avoid deletion by maintenance task
158    $query = '
159  UPDATE '.USER_FEED_TABLE.'
160    SET last_check = \''.$dbnow.'\'
161    WHERE id = \''.$feed_id.'\'
162  ;';
163    pwg_query($query);
164  }
165}
166
167$dates = get_recent_post_dates(5, 6, 6);
168
169foreach($dates as $date_detail)
170{ // for each recent post date we create a feed item
171  $item = new FeedItem();
172  $date = $date_detail['date_available'];
173  $item->title = get_title_recent_post_date($date_detail);
174  $item->link = make_index_url(
175        array(
176          'chronology_field' => 'posted',
177          'chronology_style'=> 'monthly',
178          'chronology_view' => 'calendar',
179          'chronology_date' => explode('-', substr($date,0,10) )
180        )
181      );
182
183  $item->description .=
184    '<a href="'.make_index_url().'">'.$conf['gallery_title'].'</a><br/> ';
185
186  $item->description .= get_html_description_recent_post_date($date_detail);
187
188  $item->descriptionHtmlSyndicated = true;
189
190  $item->date = ts_to_iso8601(mysqldt_to_ts($date));
191  $item->author = 'PhpWebGallery notifier';
192  $item->guid= sprintf('%s', 'pics-'.$date);;
193
194  $rss->addItem($item);
195}
196
197// send XML feed
198echo $rss->saveFeed('RSS2.0', '', true);
199?>
Note: See TracBrowser for help on using the repository browser.