po/src/feed.php

376 lines
13 KiB
PHP

<?php
// Copyright (C) 2002-2006 Balint Kis (balint@k-i-s.net)
// Copyright (C) 2005-2013 Solomon Peachy (pizza@shaftnet.org)
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
include_once "include/config.php";
include_once "include/site.php";
include_once "include/common.php";
include_once "include/search.php";
include_once "include/feedcreator.class.php";
$format = "RSS2.0";
$database = site_prolog();
//$base_url = $site_url;
$base_url = '';
$rss = new UniversalFeedCreator();
$rss->addNamespace("media", "http://search.yahoo.com/mrss/");
$rss->useCached();
// photos [user] [folder] [album] [tag]
// folders [id] [user] [tag]
// albums [id] [user] [tag]
// Initialize stuff
$froms = array();
$filter = "";
// Work around bug in JustPictures and possibly others...
foreach ($_REQUEST as $key => $value) {
if (substr($value, -1) == "?") {
$_REQUEST[$key] = substr($value, 0, strlen($value) - 1);
} elseif (substr($value, -3, -1) == "%3f") {
$_REQUEST[$key] = substr($value, 0, strlen($value) -3);
}
}
$feedtype = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'photos';
switch ($feedtype) {
case 'photos':
{
$offset = isset($_REQUEST['offset']) ? pg_escape_string($database, $_REQUEST['offset']) : 0;
$limit = isset($_REQUEST['limit']) ? pg_escape_string($database, $_REQUEST['limit']) : 100;
$order = isset($_REQUEST['orderby']) ? pg_escape_string($database, $_REQUEST['orderby']) : 8;
$size = isset($_REQUEST['size']) ? pg_escape_string($database, $_REQUEST['size']) : 2;
}
$global_args = array();
$global_args['size'] = $size;
switch ($_REQUEST['subtype']) {
case 'user':
$user_id = pg_escape_string($database, $_REQUEST['id']);
$rss->title = $site_title . " : " . disp_user_string($database, $user_id, FALSE);
$rss->description = $rss->title;
$rss->link = $base_url . generate_link('user', $user_id);
$froms = array();
$master = "and photo_version.master = 't'"; //optional?
$filter = "photo.users = '$user_id' $master";
break;
case 'folder':
$folder_id = pg_escape_string($database, $_REQUEST['id']);
$path_to_folder = get_path_to($database, 'folder', $folder_id, FALSE);
$rss->title = $site_title . " $path_to_folder ";
$rss->description = $rss->title;
$rss->link = $base_url . generate_link('folder', $folder_id);
$froms = array('folder');
$master = "and photo_version.master = 't'"; //optional?
$filter = "photo.folder = '$folder_id'
and folder.identifier = photo.folder $master";
break;
case 'album':
$album_id = pg_escape_string($database, $_REQUEST['id']);
$path_to_album = get_path_to($database, 'album', $album_id, FALSE);
$rss->title = $site_title . " $path_to_album ";
$rss->description = $rss->title;
$rss->link = $base_url . generate_link('album', $album_id);
$global_args['album'] = $album_id;
$froms = array('album_content');
$filter = "photo_version.identifier = album_content.version
and photo.identifier = album_content.photo
and album_content.album = $album_id";
break;
case 'tag':
$search_data = $_REQUEST['id']; // this is escaped later.
$keywords = extract_keywords($search_data, $po_options['search_enable_stemming']);
$sql_combined_search_string = build_sql_search_string_keywords($keywords);
$rss->title = "$site_title : ".$strings['search_searched_for']."<strong>$search_data</strong>";
$rss->description = $rss->title;
$rss->link = $base_url . generate_link('tag', $search_data);
$froms = array();
$master_args = "and photo_version.master = 't'";
$filter = " ($sql_combined_search_string) $master_args";
break;
default:
// pick whatever images come up..
break;
}
$photo_data = get_photo_query($database, array(), $froms, $filter, $offset, $limit, $order);
if ($photo_data === FALSE) break;
for ($cell_counter = 0; $cell_counter < sizeof($photo_data); $cell_counter++) {
$photo = $photo_data[$offset + $cell_counter];
if ($photo === FALSE) break;
$photo['caption'] = get_photo_title($photo['caption'], $photo['title'], $photo['original_image_name']);
$item = new FeedItem();
$item->title = $photo['caption'];
$photo_args = $global_args;
$photo_args['ver'] = $photo['version'];
unset($photo_args['size']);
$item->link = $base_url . generate_link('photo', $photo['identifier'], $photo_args);
$item->guid = $item->link;
$photo_args = $global_args;
$photo_args['ver'] = $photo['version'];
$item->description = "<img src=\"". $base_url . generate_link("image", $photo['identifier'], $photo_args)."\"/>";
$item->date = emit_date_html($photo['date_of_exposure'], 'iso8601');
$item->author = $photo['author'];
$item->authorEmail = " "; # XXX fixme?
$item->source = $base_url;
$item->additionalElements['media:content url="'. $base_url . generate_link("image", $photo['identifier'], $photo_args).'" medium="image" type="image/jpeg" /'] = '';
$item->additionalElements['media:title'] = $item->title;
$item->additionalElements['media:description'] = htmlentities($item->description);
# $item->additionalElements['media:keywords'] = 'a, b, c, d';
# $item->additionalElements['media:copyright'] = 'blablabla';
$photo_args['size'] = 1; # Reset to 1 for the thumbnail..
$item->additionalElements['media:thumbnail url="'. $base_url . generate_link("image", $photo['identifier'], $photo_args) . '" /'] = "";
$rss->addItem($item);
}
break;
case 'folder':
{
$offset = isset($_REQUEST['offset']) ? pg_escape_string($database, $_REQUEST['offset']) : 0;
$limit = isset($_REQUEST['limit']) ? pg_escape_string($database, $_REQUEST['limit']) : 25;
$order = isset($_REQUEST['orderby']) ? pg_escape_string($database, $_REQUEST['orderby']) : 2;
}
$sql_query_order_by_string = $folder_order_by_string[$order][0];
$sql_query_access_rights_string = "can_access_folder(folder.identifier, $po_user[id], '{".$passwords."}')";
switch ($_REQUEST['subtype']) {
case 'tag':
$search_data = $_REQUEST['id']; // is escaped later
$keywords = extract_keywords($search_data, $po_options['search_enable_stemming']);
$sql_search_string = build_sql_search_string($keywords, "folder.caption");
$sql_search_string .= " OR " . build_sql_search_string($keywords, "folder.description");
$itemized_search_string = build_folder_search_string($keywords, "search_string", "");
$rss->title = $site_title . $strings['search_searched_for'] ." $itemized_search_string";
$rss->description = $rss->title;
$rss->link = $base_url . generate_link('folder', $folder_id);
break;
case 'user':
$user_id = pg_escape_string($database, $_REQUEST['id']);
$rss->title = $site_title . " : " . disp_user_string($database, $user_id, FALSE);
$rss->description = $rss->title;
$rss->link = $base_url . generate_link('user', $user_id);
$sql_search_string = " folder.users = $user_id ";
break;
default:
$folder_id = pg_escape_string($database, $_REQUEST['id']);
$path_to_folder = get_path_to($database, 'folder', $folder_id, FALSE);
$rss->title = $site_title . " $path_to_folder ";
$rss->description = $rss->title;
$rss->link = $base_url . generate_link('folder', $folder_id);
// $rss->thumbnail = ?? folder_thumbnail blabla...
if ($folder_id) {
$sql_search_string = " folder.parent_folder = $folder_id ";
} else {
$sql_search_string = " folder.parent_folder is null ";
}
// XXX restrict to single user?
break;
}
$search_result = pg_query($database,
"select caption, folder.identifier, date_of_creation, folder.date_changed, folder.description,
first_name, last_name, users.identifier as user_id,
count_subfolders_by_folder(folder.identifier, $po_user[id], '{".$passwords."}') as subs,
count_photos_by_folder(folder.identifier, $po_user[id], '{".$passwords."}') as photos, thumb_ver
from folder, users
where ($sql_search_string)
and $sql_query_access_rights_string
and users.identifier = folder.users
order by $sql_query_order_by_string
offset $offset
limit $limit");
$search_result = pg_fetch_all($search_result);
if ($search_result === FALSE) break;
$args = array();
for ($i = 0 ; $i < sizeof($search_result); $i++) {
$row = $search_result[$offset + $i];
if ($row === FALSE) break;
$item = new FeedItem();
$item->title = $row['caption'];
$item->link = $base_url . generate_link('folder', $row['identifier'], $args);
$item->guid = $item->link;
$item->description = "<p>$row[caption]</p><p>$row[description]</p>"; // XXX include photo count?
$item->date = emit_date_html($row['date_of_creation'], 'iso8601'); // XXX date_changed?
$item->author = $row['user_id']; // XXX fix the right userid/name?
$item->source = $base_url;
$rss->addItem($item);
}
break;
case 'album':
{
$offset = isset($_REQUEST['offset']) ? pg_escape_string($database, $_REQUEST['offset']) : 0;
$limit = isset($_REQUEST['limit']) ? pg_escape_string($database, $_REQUEST['limit']) : 25;
$order = isset($_REQUEST['orderby']) ? pg_escape_string($database, $_REQUEST['orderby']) : 2;
}
$sql_query_order_by_string = $folder_order_by_string[$order][0];
$sql_query_access_rights_string = "can_access_album(album.identifier, $po_user[id], '{".$passwords."}')";
switch ($_REQUEST['subtype']) {
case 'tag':
$search_data = $_REQUEST['id']; // is escaepd later
$keywords = extract_keywords($search_data, $po_options['search_enable_stemming']);
$sql_search_string = build_sql_search_string($keywords, "album.caption");
$sql_search_string .= " OR " . build_sql_search_string($keywords, "album.description");
$itemized_search_string = build_folder_search_string($keywords, "search_string", "");
$rss->title = $site_title . $strings['search_searched_for'] ." $itemized_search_string";
$rss->description = $rss->title;
$rss->link = $base_url . generate_link('album', $album_id);
break;
case 'user':
$user_id = pg_escape_string($database, $_REQUEST['id']);
$rss->title = $site_title . " : " . disp_user_string($database, $user_id, FALSE);
$rss->description = $rss->title;
$rss->link = $base_url . generate_link('user', $user_id);
$sql_search_string = " album.users = $user_id ";
break;
default:
$album_id = pg_escape_string($database, $_REQUEST['id']);
$path_to_album = get_path_to($database, 'album', $album_id, FALSE);
$rss->title = $site_title . " $path_to_album ";
$rss->description = $rss->title;
$rss->link = $base_url . generate_link('album', $album_id);
// $rss->thumbnail = ?? album_thumbnail blabla...
if ($album_id) {
$sql_search_string = " album.parent_album = $album_id ";
} else {
$sql_search_string = " album.parent_album is null ";
}
// XXX restrict to single user?
break;
}
$search_result = pg_query($database,
"select caption, album.identifier, date_of_creation, album.date_changed, album.description,
first_name, last_name, users.identifier as user_id,
count_subalbums_by_album(album.identifier, $po_user[id], '{".$passwords."}') as subs,
count_photos_by_album(album.identifier, $po_user[id], '{".$passwords."}') as photos, thumb_ver
from album, users
where ($sql_search_string)
and $sql_query_access_rights_string
and users.identifier = album.users
order by $sql_query_order_by_string
offset $offset
limit $limit");
$search_result = pg_fetch_all($search_result);
$args = array();
for ($i = 0 ; $i < sizeof($search_result); $i++) {
$row = $search_result[$offset + $i];
if ($row == FALSE) break;
$item = new FeedItem();
$item->title = $row['caption'];
$item->link = $base_url . generate_link('album', $row['identifier'], $args);
$item->guid = $item->link;
$item->description = "<p>$row[caption]</p><p>$row[description]</p>"; // XXX include photo count?
$item->date = emit_date_html($row['date_of_creation'], 'iso8601'); // XXX date_changed?
$item->author = $row['user_id']; // XXX fix the right userid/name?
$item->source = $base_url;
$rss->addItem($item);
}
break;
default:
break;
}
$rss->outputFeed($format);
site_epilog($database);
?>