From 79f5fd8e2a4959b78cf8be6312962849e14e9d85 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 26 Mar 2014 16:09:07 -0700 Subject: allow zotfeed to create a firehose of a site. --- include/identity.php | 9 +++++++++ include/items.php | 31 ++++++++++++++++++++----------- include/security.php | 14 ++++++++------ mod/zotfeed.php | 5 +++++ version.inc | 2 +- 5 files changed, 43 insertions(+), 18 deletions(-) diff --git a/include/identity.php b/include/identity.php index c8a925dac..97c29516c 100644 --- a/include/identity.php +++ b/include/identity.php @@ -109,6 +109,15 @@ function get_sys_channel() { return false; } +function is_sys_channel($channel_id) { + $r = q("select channel_pageflags from channel where channel_id = %d limit 1", + intval($channel_id) + ); + if(($r) && ($r[0]['channel_pageflags'] & PAGE_SYSTEM)) + return true; + return false; +} + /** * @channel_total() diff --git a/include/items.php b/include/items.php index 428767676..dd5f4aac1 100755 --- a/include/items.php +++ b/include/items.php @@ -3763,24 +3763,33 @@ function zot_feed($uid,$observer_xchan,$mindate) { $items = array(); - $r = q("SELECT item.*, item.id as item_id from item - WHERE uid = %d AND item_restrict = 0 and id = parent - AND (item_flags & %d) - $sql_extra ORDER BY created ASC $limit", - intval($uid), - intval(ITEM_WALL) - ); - if($r) { + if(is_sys_channel($uid)) { + $r = q("SELECT item.*, item.id as item_id from item + WHERE uid in (" . stream_perms_api_uids(PERMS_PUBLIC) . ") AND item_restrict = 0 and id = parent + AND (item_flags & %d) + $sql_extra ORDER BY created ASC $limit", + intval($uid), + intval(ITEM_WALL) + ); + } + else { + $r = q("SELECT item.*, item.id as item_id from item + WHERE uid = %d AND item_restrict = 0 and id = parent + AND (item_flags & %d) + $sql_extra ORDER BY created ASC $limit", + intval($uid), + intval(ITEM_WALL) + ); + } + if($r) { $parents_str = ids_to_querystr($r,'id'); $items = q("SELECT `item`.*, `item`.`id` AS `item_id` FROM `item` - WHERE `item`.`uid` = %d AND `item`.`item_restrict` = 0 + WHERE `item`.`item_restrict` = 0 AND `item`.`parent` IN ( %s ) ", - intval($uid), dbesc($parents_str) ); - } if($items) { diff --git a/include/security.php b/include/security.php index f52615357..6b20e2904 100644 --- a/include/security.php +++ b/include/security.php @@ -346,8 +346,9 @@ function stream_perms_api_uids($perms_min = PERMS_SITE) { $ret = array(); if(local_user()) $ret[] = local_user(); - $r = q("select channel_id from channel where channel_r_stream > 0 and channel_r_stream <= %d", - intval($perms_min) + $r = q("select channel_id from channel where channel_r_stream > 0 and channel_r_stream <= %d and not (channel_pageflags & %d) ", + intval($perms_min), + intval(PAGE_ADULT) ); if($r) foreach($r as $rr) @@ -361,7 +362,7 @@ function stream_perms_api_uids($perms_min = PERMS_SITE) { $str .= ','; $str .= intval($rr); } -logger('stream_perms_api_uids: ' . $str); +logger('stream_perms_api_uids: ' . $str, LOGGER_DEBUG); return $str; } @@ -370,8 +371,9 @@ function stream_perms_xchans($perms_min = PERMS_SITE) { if(local_user()) $ret[] = get_observer_hash(); - $r = q("select channel_hash from channel where channel_r_stream > 0 and channel_r_stream <= %d", - intval($perms_min) + $r = q("select channel_hash from channel where channel_r_stream > 0 and channel_r_stream <= %d and not (channel_pageflags & %d)", + intval($perms_min), + intval(PAGE_ADULT) ); if($r) foreach($r as $rr) @@ -385,6 +387,6 @@ function stream_perms_xchans($perms_min = PERMS_SITE) { $str .= ','; $str .= "'" . dbesc($rr) . "'"; } -logger('stream_perms_xchans: ' . $str); +logger('stream_perms_xchans: ' . $str, LOGGER_DEBUG); return $str; } diff --git a/mod/zotfeed.php b/mod/zotfeed.php index 6d84a5a1e..1f5dc2cfa 100644 --- a/mod/zotfeed.php +++ b/mod/zotfeed.php @@ -25,6 +25,11 @@ function zotfeed_init(&$a) { dbesc(argv(1)) ); } + else { + $x = get_sys_channel(); + if($x) + $r = array($x); + } if(! $r) { $result['message'] = 'Channel not found.'; json_return_and_die($result); diff --git a/version.inc b/version.inc index a1b9d8790..cf2f2646a 100644 --- a/version.inc +++ b/version.inc @@ -1 +1 @@ -2014-03-25.627 +2014-03-26.628 -- cgit v1.2.3