add photos and albums enumeration to Red API (will allow us to export either all our photos or individual albums using a script)
This commit is contained in:
@@ -6,6 +6,7 @@ require_once("conversation.php");
|
|||||||
require_once("oauth.php");
|
require_once("oauth.php");
|
||||||
require_once("html2plain.php");
|
require_once("html2plain.php");
|
||||||
require_once('include/security.php');
|
require_once('include/security.php');
|
||||||
|
require_once('include/photos.php');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
@@ -545,6 +546,23 @@ require_once('include/security.php');
|
|||||||
api_register_func('api/red/channel/stream','api_channel_stream', true);
|
api_register_func('api/red/channel/stream','api_channel_stream', true);
|
||||||
|
|
||||||
|
|
||||||
|
function api_albums(&$a,$type) {
|
||||||
|
json_return_and_die(photos_albums_list($a->get_channel(),$a->get_observer()));
|
||||||
|
}
|
||||||
|
api_register_func('api/red/albums','api_albums', true);
|
||||||
|
|
||||||
|
function api_photos(&$a,$type) {
|
||||||
|
$album = $_REQUEST['album'];
|
||||||
|
json_return_and_die(photos_list_photos($a->get_channel(),$a->get_observer()),$album);
|
||||||
|
}
|
||||||
|
api_register_func('api/red/photos','api_photos', true);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function api_statuses_mediap(&$a, $type) {
|
function api_statuses_mediap(&$a, $type) {
|
||||||
if (api_user() === false) {
|
if (api_user() === false) {
|
||||||
logger('api_statuses_update: no user');
|
logger('api_statuses_update: no user');
|
||||||
|
|||||||
@@ -250,13 +250,16 @@ function photos_albums_list($channel,$observer) {
|
|||||||
|
|
||||||
// add various encodings to the array so we can just loop through and pick them out in a template
|
// add various encodings to the array so we can just loop through and pick them out in a template
|
||||||
|
|
||||||
|
$ret = array('success' => false);
|
||||||
|
|
||||||
if($albums) {
|
if($albums) {
|
||||||
|
$ret['success'] = true;
|
||||||
foreach($albums as $k => $album) {
|
foreach($albums as $k => $album) {
|
||||||
$albums[$k]['urlencode'] = urlencode($album['album']);
|
$entry = array('text' => $album['album'], 'urlencode' => urlencode($album['album']),'bin2hex' => bin2hex($album['album']));
|
||||||
$albums[$k]['bin2hex'] = bin2hex($album['album']);
|
$ret[] = $entry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $albums;
|
return $ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,6 +283,36 @@ function photos_album_widget($channelx,$observer,$albums = null) {
|
|||||||
return $o;
|
return $o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function photos_list_photos($channel,$observer,$album = '') {
|
||||||
|
|
||||||
|
$channel_id = $channel['channel_id'];
|
||||||
|
$observer_xchan = (($observer) ? $observer['xchan_hash'] : '');
|
||||||
|
|
||||||
|
if(! perm_is_allowed($channel_id,$observer_xchan,'view_photos'))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
$sql_extra = permissions_sql($channel_id);
|
||||||
|
|
||||||
|
if($album)
|
||||||
|
$sql_extra .= " and album = '" . protect_sprintf(dbesc($album)) . "' ";
|
||||||
|
|
||||||
|
$ret = array('success' => false);
|
||||||
|
|
||||||
|
$r = q("select resource_id, created, edited, title, `desc`, album, filename, `type`, height, width, `size`, `scale`, profile, allow_cid, allow_gid, deny_cid, deny_gid from photo where uid = %d $sql_extra ",
|
||||||
|
intval($channel_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
if($r) {
|
||||||
|
$ret['success'] = true;
|
||||||
|
$ret['photos'] = $r;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function photos_album_exists($channel_id,$album) {
|
function photos_album_exists($channel_id,$album) {
|
||||||
$r = q("SELECT id from photo where album = '%s' and uid = %d limit 1",
|
$r = q("SELECT id from photo where album = '%s' and uid = %d limit 1",
|
||||||
dbesc($album),
|
dbesc($album),
|
||||||
|
|||||||
Reference in New Issue
Block a user