[801] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
| 4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
[1018] | 5 | // | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net | |
---|
[801] | 6 | // +-----------------------------------------------------------------------+ |
---|
| 7 | // | branch : BSF (Best So Far) |
---|
| 8 | // | file : $RCSfile$ |
---|
| 9 | // | last update : $Date: 2006-12-07 03:49:20 +0000 (Thu, 07 Dec 2006) $ |
---|
| 10 | // | last modifier : $Author: rvelices $ |
---|
| 11 | // | revision : $Revision: 1639 $ |
---|
| 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 | |
---|
| 28 | define('PHPWG_ROOT_PATH','./'); |
---|
| 29 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); |
---|
[1018] | 30 | include_once(PHPWG_ROOT_PATH.'include/functions_notification.inc.php'); |
---|
[801] | 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 | */ |
---|
| 43 | function 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 | */ |
---|
| 64 | function 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 | */ |
---|
| 80 | function 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 | // clean $user array (include/user.inc.php has been executed) |
---|
| 92 | $user = array(); |
---|
| 93 | |
---|
| 94 | // echo '<pre>'.generate_key(50).'</pre>'; |
---|
| 95 | if (isset($_GET['feed']) |
---|
| 96 | and preg_match('/^[A-Za-z0-9]{50}$/', $_GET['feed'])) |
---|
| 97 | { |
---|
| 98 | $query = ' |
---|
[833] | 99 | SELECT uf.user_id AS id, |
---|
| 100 | ui.status, |
---|
| 101 | uf.last_check, |
---|
| 102 | u.'.$conf['user_fields']['username'].' AS username |
---|
| 103 | FROM '.USER_FEED_TABLE.' AS uf |
---|
| 104 | INNER JOIN '.USER_INFOS_TABLE.' AS ui |
---|
| 105 | ON ui.user_id = uf.user_id |
---|
| 106 | INNER JOIN '.USERS_TABLE.' AS u |
---|
| 107 | ON u.'.$conf['user_fields']['id'].' = uf.user_id |
---|
| 108 | WHERE uf.id = \''.$_GET['feed'].'\' |
---|
[801] | 109 | ;'; |
---|
| 110 | $user = mysql_fetch_array(pwg_query($query)); |
---|
| 111 | } |
---|
[1549] | 112 | |
---|
| 113 | if ( empty($user) ) |
---|
[801] | 114 | { |
---|
[1549] | 115 | page_not_found('Unknown/missing feed identifier'); |
---|
[801] | 116 | } |
---|
| 117 | |
---|
| 118 | $user['forbidden_categories'] = calculate_permissions($user['id'], |
---|
| 119 | $user['status']); |
---|
| 120 | if ('' == $user['forbidden_categories']) |
---|
| 121 | { |
---|
[1331] | 122 | $user['forbidden_categories'] = '0'; |
---|
[801] | 123 | } |
---|
| 124 | |
---|
| 125 | list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); |
---|
| 126 | |
---|
| 127 | include_once(PHPWG_ROOT_PATH.'include/feedcreator.class.php'); |
---|
| 128 | |
---|
[1604] | 129 | $base_url = get_host_url().cookie_path(); |
---|
[1549] | 130 | if ( strrpos($base_url, '/') !== strlen($base_url)-1 ) |
---|
| 131 | { |
---|
| 132 | $base_url .= '/'; |
---|
| 133 | } |
---|
| 134 | $page['root_path']=$base_url; |
---|
| 135 | |
---|
[801] | 136 | $rss = new UniversalFeedCreator(); |
---|
| 137 | |
---|
[1549] | 138 | $rss->title = $conf['gallery_title']; |
---|
[833] | 139 | $rss->title.= ' (as '.$user['username'].')'; |
---|
| 140 | |
---|
| 141 | $rss->link = $conf['gallery_url']; |
---|
| 142 | |
---|
[801] | 143 | // +-----------------------------------------------------------------------+ |
---|
| 144 | // | Feed creation | |
---|
| 145 | // +-----------------------------------------------------------------------+ |
---|
| 146 | |
---|
[1636] | 147 | if ( !isset($_GET['image_only']) ) |
---|
[801] | 148 | { |
---|
[1636] | 149 | $news = news($user['last_check'], $dbnow, true, true); |
---|
[1549] | 150 | |
---|
[1636] | 151 | if (count($news) > 0) |
---|
[801] | 152 | { |
---|
[1636] | 153 | $item = new FeedItem(); |
---|
| 154 | $item->title = sprintf(l10n('New on %s'), |
---|
| 155 | format_date($dbnow, 'mysql_datetime') ); |
---|
| 156 | $item->link = $conf['gallery_url']; |
---|
[1549] | 157 | |
---|
[1636] | 158 | // content creation |
---|
| 159 | $item->description = '<ul>'; |
---|
| 160 | foreach ($news as $line) |
---|
| 161 | { |
---|
| 162 | $item->description.= '<li>'.$line.'</li>'; |
---|
| 163 | } |
---|
| 164 | $item->description.= '</ul>'; |
---|
| 165 | $item->descriptionHtmlSyndicated = true; |
---|
[1549] | 166 | |
---|
[1636] | 167 | $item->date = ts_to_iso8601(mysqldt_to_ts($dbnow)); |
---|
| 168 | $item->author = 'PhpWebGallery notifier'; |
---|
| 169 | $item->guid= sprintf('%s', $dbnow);; |
---|
[801] | 170 | |
---|
[1636] | 171 | $rss->addItem($item); |
---|
| 172 | |
---|
| 173 | $query = ' |
---|
| 174 | UPDATE '.USER_FEED_TABLE.' |
---|
| 175 | SET last_check = \''.$dbnow.'\' |
---|
| 176 | WHERE id = \''.$_GET['feed'].'\' |
---|
| 177 | ;'; |
---|
| 178 | pwg_query($query); |
---|
| 179 | } |
---|
| 180 | } |
---|
| 181 | else |
---|
| 182 | { // update the last check to avoid deletion by maintenance task |
---|
[1549] | 183 | $query = ' |
---|
[833] | 184 | UPDATE '.USER_FEED_TABLE.' |
---|
| 185 | SET last_check = \''.$dbnow.'\' |
---|
| 186 | WHERE id = \''.$_GET['feed'].'\' |
---|
[801] | 187 | ;'; |
---|
[1549] | 188 | pwg_query($query); |
---|
| 189 | } |
---|
[801] | 190 | |
---|
[1639] | 191 | $dates = get_recent_post_dates( 5, 6, 6); |
---|
[1549] | 192 | |
---|
| 193 | foreach($dates as $date_detail) |
---|
| 194 | { // for each recent post date we create a feed item |
---|
| 195 | $date = $date_detail['date_available']; |
---|
| 196 | $exploded_date = explode_mysqldt($date); |
---|
| 197 | $item = new FeedItem(); |
---|
[1639] | 198 | $item->title = l10n_dec('%d element added', '%d elements added', $date_detail['nb_elements']); |
---|
[1549] | 199 | $item->title .= ' ('.$lang['month'][(int)$exploded_date['month']].' '.$exploded_date['day'].')'; |
---|
| 200 | $item->link = make_index_url( |
---|
| 201 | array( |
---|
| 202 | 'chronology_field' => 'posted', |
---|
| 203 | 'chronology_style'=> 'monthly', |
---|
| 204 | 'chronology_view' => 'calendar', |
---|
| 205 | 'chronology_date' => explode('-', substr($date,0,10) ) |
---|
| 206 | ) |
---|
| 207 | ); |
---|
| 208 | |
---|
| 209 | $item->description .= |
---|
| 210 | '<a href="'.make_index_url().'">'.$conf['gallery_title'].'</a><br/> '; |
---|
| 211 | |
---|
| 212 | $item->description .= |
---|
| 213 | '<li>' |
---|
[1639] | 214 | .l10n_dec('%d element added', '%d elements added', $date_detail['nb_elements']) |
---|
[1549] | 215 | .' (' |
---|
| 216 | .'<a href="'.make_index_url(array('section'=>'recent_pics')).'">' |
---|
| 217 | .l10n('recent_pics_cat').'</a>' |
---|
| 218 | .')' |
---|
| 219 | .'</li>'; |
---|
| 220 | |
---|
[1639] | 221 | foreach( $date_detail['elements'] as $element ) |
---|
[1549] | 222 | { |
---|
[1639] | 223 | $tn_src = get_thumbnail_url($element); |
---|
[1549] | 224 | $item->description .= '<img src="'.$tn_src.'"/>'; |
---|
| 225 | } |
---|
| 226 | $item->description .= '...<br/>'; |
---|
| 227 | |
---|
| 228 | $item->description .= |
---|
| 229 | '<li>' |
---|
[1639] | 230 | .l10n_dec('%d category updated', '%d categories updated', |
---|
[1637] | 231 | $date_detail['nb_cats']) |
---|
[1549] | 232 | .'</li>'; |
---|
[1639] | 233 | |
---|
[1549] | 234 | $item->description .= '<ul>'; |
---|
[1639] | 235 | foreach( $date_detail['categories'] as $cat ) |
---|
[1549] | 236 | { |
---|
| 237 | $item->description .= |
---|
| 238 | '<li>' |
---|
[1639] | 239 | .get_cat_display_name_cache($cat['uppercats']) |
---|
[1637] | 240 | .' ('. |
---|
[1639] | 241 | l10n_dec('%d element added', |
---|
| 242 | '%d elements added', $cat['img_count']).')' |
---|
[1549] | 243 | .'</li>'; |
---|
| 244 | } |
---|
| 245 | $item->description .= '</ul>'; |
---|
| 246 | |
---|
| 247 | $item->descriptionHtmlSyndicated = true; |
---|
| 248 | |
---|
| 249 | $item->date = ts_to_iso8601(mysqldt_to_ts($date)); |
---|
| 250 | $item->author = 'PhpWebGallery notifier'; |
---|
| 251 | $item->guid= sprintf('%s', 'pics-'.$date);; |
---|
| 252 | |
---|
| 253 | $rss->addItem($item); |
---|
| 254 | } |
---|
| 255 | |
---|
[801] | 256 | // send XML feed |
---|
| 257 | echo $rss->saveFeed('RSS2.0', '', true); |
---|
| 258 | ?> |
---|