source: trunk/feed.php @ 1750

Last change on this file since 1750 was 1750, checked in by rvelices, 17 years ago
  • plugins with own independent scripts work now (cookie_path and url root are

correct)

  • prepare a bit some url functions so that later we can fully embed pwg in

scripts located outside pwg

  • remove some unnecessary language strings
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 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-01-24 05:07:08 +0000 (Wed, 24 Jan 2007) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 1750 $
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 * explodes a MySQL datetime format (2005-07-14 23:01:37) in fields "year",
38 * "month", "day", "hour", "minute", "second".
39 *
40 * @param string mysql datetime format
41 * @return array
42 */
43function explode_mysqldt($mysqldt)
44{
45  $date = array();
46  list($date['year'],
47       $date['month'],
48       $date['day'],
49       $date['hour'],
50       $date['minute'],
51       $date['second'])
52    = preg_split('/[-: ]/', $mysqldt);
53
54  return $date;
55}
56
57/**
58 * creates a Unix timestamp (number of seconds since 1970-01-01 00:00:00
59 * GMT) from a MySQL datetime format (2005-07-14 23:01:37)
60 *
61 * @param string mysql datetime format
62 * @return int timestamp
63 */
64function mysqldt_to_ts($mysqldt)
65{
66  $date = explode_mysqldt($mysqldt);
67  return mktime($date['hour'], $date['minute'], $date['second'],
68                $date['month'], $date['day'], $date['year']);
69}
70
71/**
72 * creates an ISO 8601 format date (2003-01-20T18:05:41+04:00) from Unix
73 * timestamp (number of seconds since 1970-01-01 00:00:00 GMT)
74 *
75 * function copied from Dotclear project http://dotclear.net
76 *
77 * @param int timestamp
78 * @return string ISO 8601 date format
79 */
80function ts_to_iso8601($ts)
81{
82  $tz = date('O',$ts);
83  $tz = substr($tz, 0, -2).':'.substr($tz, -2);
84  return date('Y-m-d\\TH:i:s',$ts).$tz;
85}
86
87// +-----------------------------------------------------------------------+
88// |                            initialization                             |
89// +-----------------------------------------------------------------------+
90
91$feed_id= isset($_GET['feed']) ? $_GET['feed'] : '';
92$image_only=isset($_GET['image_only']);
93
94// echo '<pre>'.generate_key(50).'</pre>';
95if ( !empty($feed_id) )
96{
97  $query = '
98SELECT user_id,
99       last_check
100  FROM '.USER_FEED_TABLE.'
101  WHERE id = \''.$feed_id.'\'
102;';
103  $feed_row = mysql_fetch_assoc(pwg_query($query));
104  if ( empty($feed_row) )
105  {
106    page_not_found('Unknown/missing feed identifier');
107  }
108  if ($feed_row['user_id']!=$user['id'])
109  { // new user
110    $user = array();
111    $user = build_user( $feed_row['user_id'], true );
112  }
113}
114else
115{
116  $image_only = true;
117  if (!$user['is_the_guest'])
118  {// auto session was created - so switch to guest
119    $user = array();
120    $user = build_user( $conf['guest_id'], true );
121  }
122}
123
124list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
125
126include_once(PHPWG_ROOT_PATH.'include/feedcreator.class.php');
127
128set_make_full_url();
129
130$rss = new UniversalFeedCreator();
131
132$rss->title = $conf['gallery_title'];
133$rss->title.= ' (as '.$user['username'].')';
134
135$rss->link = $conf['gallery_url'];
136
137// +-----------------------------------------------------------------------+
138// |                            Feed creation                              |
139// +-----------------------------------------------------------------------+
140
141if (!$image_only)
142{
143  $news = news($feed_row['last_check'], $dbnow, true, true);
144
145  if (count($news) > 0)
146  {
147    $item = new FeedItem();
148    $item->title = sprintf(l10n('New on %s'),
149        format_date($dbnow, 'mysql_datetime') );
150    $item->link = $conf['gallery_url'];
151
152    // content creation
153    $item->description = '<ul>';
154    foreach ($news as $line)
155    {
156      $item->description.= '<li>'.$line.'</li>';
157    }
158    $item->description.= '</ul>';
159    $item->descriptionHtmlSyndicated = true;
160
161    $item->date = ts_to_iso8601(mysqldt_to_ts($dbnow));
162    $item->author = 'PhpWebGallery notifier';
163    $item->guid= sprintf('%s', $dbnow);;
164
165    $rss->addItem($item);
166
167    $query = '
168UPDATE '.USER_FEED_TABLE.'
169  SET last_check = \''.$dbnow.'\'
170  WHERE id = \''.$feed_id.'\'
171;';
172    pwg_query($query);
173  }
174}
175else
176{
177  if ( !empty($feed_id) )
178  {// update the last check to avoid deletion by maintenance task
179    $query = '
180  UPDATE '.USER_FEED_TABLE.'
181    SET last_check = \''.$dbnow.'\'
182    WHERE id = \''.$feed_id.'\'
183  ;';
184    pwg_query($query);
185  }
186}
187
188$dates = get_recent_post_dates( 5, 6, 6);
189
190foreach($dates as  $date_detail)
191{ // for each recent post date we create a feed item
192  $date = $date_detail['date_available'];
193  $exploded_date = explode_mysqldt($date);
194  $item = new FeedItem();
195  $item->title = l10n_dec('%d new element', '%d new elements', $date_detail['nb_elements']);
196  $item->title .= ' ('.$lang['month'][(int)$exploded_date['month']].' '.$exploded_date['day'].')';
197  $item->link = make_index_url(
198        array(
199          'chronology_field' => 'posted',
200          'chronology_style'=> 'monthly',
201          'chronology_view' => 'calendar',
202          'chronology_date' => explode('-', substr($date,0,10) )
203        )
204      );
205
206  $item->description .=
207    '<a href="'.make_index_url().'">'.$conf['gallery_title'].'</a><br/> ';
208
209  $item->description .=
210        '<li>'
211        .l10n_dec('%d new element', '%d new elements', $date_detail['nb_elements'])
212        .' ('
213        .'<a href="'.make_index_url(array('section'=>'recent_pics')).'">'
214          .l10n('recent_pics_cat').'</a>'
215        .')'
216        .'</li>';
217
218  foreach( $date_detail['elements'] as $element )
219  {
220    $tn_src = get_thumbnail_url($element);
221    $item->description .= '<img src="'.$tn_src.'"/>';
222  }
223  $item->description .= '...<br/>';
224
225  $item->description .=
226        '<li>'
227        .l10n_dec('%d category updated', '%d categories updated',
228                  $date_detail['nb_cats'])
229        .'</li>';
230
231  $item->description .= '<ul>';
232  foreach( $date_detail['categories'] as $cat )
233  {
234    $item->description .=
235          '<li>'
236          .get_cat_display_name_cache($cat['uppercats'])
237          .' ('.
238          l10n_dec('%d new element',
239                   '%d new elements', $cat['img_count']).')'
240          .'</li>';
241  }
242  $item->description .= '</ul>';
243
244  $item->descriptionHtmlSyndicated = true;
245
246  $item->date = ts_to_iso8601(mysqldt_to_ts($date));
247  $item->author = 'PhpWebGallery notifier';
248  $item->guid= sprintf('%s', 'pics-'.$date);;
249
250  $rss->addItem($item);
251}
252
253// send XML feed
254echo $rss->saveFeed('RSS2.0', '', true);
255?>
Note: See TracBrowser for help on using the repository browser.