[801] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[2297] | 3 | // | Piwigo - a PHP based picture gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
| 5 | // | Copyright(C) 2008 Piwigo Team http://piwigo.org | |
---|
| 6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
| 7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
| 8 | // +-----------------------------------------------------------------------+ |
---|
| 9 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 10 | // | it under the terms of the GNU General Public License as published by | |
---|
| 11 | // | the Free Software Foundation | |
---|
| 12 | // | | |
---|
| 13 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 16 | // | General Public License for more details. | |
---|
| 17 | // | | |
---|
| 18 | // | You should have received a copy of the GNU General Public License | |
---|
| 19 | // | along with this program; if not, write to the Free Software | |
---|
| 20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 21 | // | USA. | |
---|
| 22 | // +-----------------------------------------------------------------------+ |
---|
[801] | 23 | |
---|
| 24 | define('PHPWG_ROOT_PATH','./'); |
---|
| 25 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); |
---|
[1018] | 26 | include_once(PHPWG_ROOT_PATH.'include/functions_notification.inc.php'); |
---|
[801] | 27 | |
---|
| 28 | // +-----------------------------------------------------------------------+ |
---|
| 29 | // | functions | |
---|
| 30 | // +-----------------------------------------------------------------------+ |
---|
| 31 | |
---|
| 32 | /** |
---|
| 33 | * creates a Unix timestamp (number of seconds since 1970-01-01 00:00:00 |
---|
| 34 | * GMT) from a MySQL datetime format (2005-07-14 23:01:37) |
---|
| 35 | * |
---|
| 36 | * @param string mysql datetime format |
---|
| 37 | * @return int timestamp |
---|
| 38 | */ |
---|
| 39 | function mysqldt_to_ts($mysqldt) |
---|
| 40 | { |
---|
| 41 | $date = explode_mysqldt($mysqldt); |
---|
| 42 | return mktime($date['hour'], $date['minute'], $date['second'], |
---|
| 43 | $date['month'], $date['day'], $date['year']); |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | /** |
---|
| 47 | * creates an ISO 8601 format date (2003-01-20T18:05:41+04:00) from Unix |
---|
| 48 | * timestamp (number of seconds since 1970-01-01 00:00:00 GMT) |
---|
| 49 | * |
---|
| 50 | * function copied from Dotclear project http://dotclear.net |
---|
| 51 | * |
---|
| 52 | * @param int timestamp |
---|
| 53 | * @return string ISO 8601 date format |
---|
| 54 | */ |
---|
| 55 | function ts_to_iso8601($ts) |
---|
| 56 | { |
---|
| 57 | $tz = date('O',$ts); |
---|
| 58 | $tz = substr($tz, 0, -2).':'.substr($tz, -2); |
---|
| 59 | return date('Y-m-d\\TH:i:s',$ts).$tz; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | // +-----------------------------------------------------------------------+ |
---|
| 63 | // | initialization | |
---|
| 64 | // +-----------------------------------------------------------------------+ |
---|
| 65 | |
---|
[1750] | 66 | $feed_id= isset($_GET['feed']) ? $_GET['feed'] : ''; |
---|
| 67 | $image_only=isset($_GET['image_only']); |
---|
[801] | 68 | |
---|
| 69 | // echo '<pre>'.generate_key(50).'</pre>'; |
---|
[1750] | 70 | if ( !empty($feed_id) ) |
---|
[801] | 71 | { |
---|
| 72 | $query = ' |
---|
[1750] | 73 | SELECT user_id, |
---|
| 74 | last_check |
---|
| 75 | FROM '.USER_FEED_TABLE.' |
---|
| 76 | WHERE id = \''.$feed_id.'\' |
---|
[801] | 77 | ;'; |
---|
[1750] | 78 | $feed_row = mysql_fetch_assoc(pwg_query($query)); |
---|
| 79 | if ( empty($feed_row) ) |
---|
| 80 | { |
---|
| 81 | page_not_found('Unknown/missing feed identifier'); |
---|
| 82 | } |
---|
| 83 | if ($feed_row['user_id']!=$user['id']) |
---|
| 84 | { // new user |
---|
| 85 | $user = build_user( $feed_row['user_id'], true ); |
---|
| 86 | } |
---|
[801] | 87 | } |
---|
[1750] | 88 | else |
---|
[801] | 89 | { |
---|
[1750] | 90 | $image_only = true; |
---|
[2029] | 91 | if (!is_a_guest()) |
---|
[1750] | 92 | {// auto session was created - so switch to guest |
---|
| 93 | $user = build_user( $conf['guest_id'], true ); |
---|
| 94 | } |
---|
[801] | 95 | } |
---|
| 96 | |
---|
[1850] | 97 | // Check the status now after the user has been loaded |
---|
| 98 | check_status(ACCESS_GUEST); |
---|
| 99 | |
---|
[801] | 100 | list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();')); |
---|
| 101 | |
---|
| 102 | include_once(PHPWG_ROOT_PATH.'include/feedcreator.class.php'); |
---|
| 103 | |
---|
[1750] | 104 | set_make_full_url(); |
---|
[1549] | 105 | |
---|
[801] | 106 | $rss = new UniversalFeedCreator(); |
---|
[2132] | 107 | $rss->encoding=get_pwg_charset(); |
---|
[1549] | 108 | $rss->title = $conf['gallery_title']; |
---|
[833] | 109 | $rss->title.= ' (as '.$user['username'].')'; |
---|
| 110 | |
---|
| 111 | $rss->link = $conf['gallery_url']; |
---|
| 112 | |
---|
[801] | 113 | // +-----------------------------------------------------------------------+ |
---|
| 114 | // | Feed creation | |
---|
| 115 | // +-----------------------------------------------------------------------+ |
---|
| 116 | |
---|
[2152] | 117 | $news = array(); |
---|
[1750] | 118 | if (!$image_only) |
---|
[801] | 119 | { |
---|
[1750] | 120 | $news = news($feed_row['last_check'], $dbnow, true, true); |
---|
[1549] | 121 | |
---|
[1636] | 122 | if (count($news) > 0) |
---|
[801] | 123 | { |
---|
[1636] | 124 | $item = new FeedItem(); |
---|
| 125 | $item->title = sprintf(l10n('New on %s'), |
---|
| 126 | format_date($dbnow, 'mysql_datetime') ); |
---|
| 127 | $item->link = $conf['gallery_url']; |
---|
[1549] | 128 | |
---|
[1636] | 129 | // content creation |
---|
| 130 | $item->description = '<ul>'; |
---|
| 131 | foreach ($news as $line) |
---|
| 132 | { |
---|
| 133 | $item->description.= '<li>'.$line.'</li>'; |
---|
| 134 | } |
---|
| 135 | $item->description.= '</ul>'; |
---|
| 136 | $item->descriptionHtmlSyndicated = true; |
---|
[1549] | 137 | |
---|
[2296] | 138 | $item->date = mysqldt_to_ts($dbnow); |
---|
[2339] | 139 | $item->author = 'Piwigo notifier'; |
---|
[1636] | 140 | $item->guid= sprintf('%s', $dbnow);; |
---|
[801] | 141 | |
---|
[1636] | 142 | $rss->addItem($item); |
---|
| 143 | |
---|
| 144 | $query = ' |
---|
| 145 | UPDATE '.USER_FEED_TABLE.' |
---|
| 146 | SET last_check = \''.$dbnow.'\' |
---|
[1750] | 147 | WHERE id = \''.$feed_id.'\' |
---|
[1636] | 148 | ;'; |
---|
| 149 | pwg_query($query); |
---|
| 150 | } |
---|
| 151 | } |
---|
[2152] | 152 | |
---|
| 153 | if ( !empty($feed_id) and empty($news) ) |
---|
| 154 | {// update the last check from time to time to avoid deletion by maintenance tasks |
---|
| 155 | if ( !isset($feed_row['last_check']) |
---|
| 156 | or time()-mysqldt_to_ts($feed_row['last_check']) > 30*24*3600 ) |
---|
| 157 | { |
---|
[1750] | 158 | $query = ' |
---|
[2152] | 159 | UPDATE '.USER_FEED_TABLE.' |
---|
| 160 | SET last_check = DATE_ADD(\''.$dbnow.'\', INTERVAL -15 DAY ) |
---|
| 161 | WHERE id = \''.$feed_id.'\' |
---|
| 162 | ;'; |
---|
[1750] | 163 | pwg_query($query); |
---|
| 164 | } |
---|
[1549] | 165 | } |
---|
[801] | 166 | |
---|
[1871] | 167 | $dates = get_recent_post_dates_array($conf['recent_post_dates']['RSS']); |
---|
[1549] | 168 | |
---|
[1784] | 169 | foreach($dates as $date_detail) |
---|
[1549] | 170 | { // for each recent post date we create a feed item |
---|
[1784] | 171 | $item = new FeedItem(); |
---|
[1549] | 172 | $date = $date_detail['date_available']; |
---|
[1784] | 173 | $item->title = get_title_recent_post_date($date_detail); |
---|
[1549] | 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 | |
---|
[1784] | 186 | $item->description .= get_html_description_recent_post_date($date_detail); |
---|
[1549] | 187 | |
---|
| 188 | $item->descriptionHtmlSyndicated = true; |
---|
| 189 | |
---|
[2296] | 190 | $item->date = mysqldt_to_ts($date); |
---|
[2339] | 191 | $item->author = 'Piwigo notifier'; |
---|
[1549] | 192 | $item->guid= sprintf('%s', 'pics-'.$date);; |
---|
| 193 | |
---|
| 194 | $rss->addItem($item); |
---|
| 195 | } |
---|
| 196 | |
---|
[2296] | 197 | $fileName= $conf['local_data_dir'].'/tmp'; |
---|
| 198 | @mkdir($fileName); // just in case |
---|
| 199 | $fileName.='/feed.xml'; |
---|
[801] | 200 | // send XML feed |
---|
[2296] | 201 | echo $rss->saveFeed('RSS2.0', $fileName, true); |
---|
[801] | 202 | ?> |
---|