diff options
Diffstat (limited to 'include/items.php')
-rwxr-xr-x | include/items.php | 148 |
1 files changed, 103 insertions, 45 deletions
diff --git a/include/items.php b/include/items.php index f6efea58c..7a94336be 100755 --- a/include/items.php +++ b/include/items.php @@ -9,13 +9,6 @@ require_once('include/permissions.php'); function collect_recipients($item,&$private) { -// FIXME - this needs a revision to handle public scope (this site, this network, etc.) -// We'll be changing this to return an array of -// - recipients -// - private -// - scope if message is public ('global', 'network: red', 'site: $sitename', 'connections') -// The receiving site will need to check the scope before creating a list of local recipients - require_once('include/group.php'); $private = ((intval($item['item_private'])) ? true : false); @@ -113,6 +106,7 @@ function collect_recipients($item,&$private) { * If it is, you should be able to use perm_is_allowed( ... 'post_comments'), and if it isn't you need to call * can_comment_on_post() */ + function can_comment_on_post($observer_xchan,$item) { // logger('can_comment_on_post: comment_policy: ' . $item['comment_policy'], LOGGER_DEBUG); @@ -153,6 +147,21 @@ function can_comment_on_post($observer_xchan,$item) { return false; } +/** + * @function add_source_route($iid,$hash) + * Adds $hash to the item source route specified by $iid + * @param integer $iid + * item['id'] of target item + * @param string $hash + * xchan_hash of the channel that sent the item + * Modifies item pointed to by $iid + * + * $item['route'] contains a comma-separated list of xchans that sent the current message, + * somewhat analogous to the * Received: header line in email. We can use this to perform + * loop detection and to avoid sending a particular item to any "upstream" sender (they + * already have a copy because they sent it to us). + * + */ function add_source_route($iid,$hash) { // logger('add_source_route ' . $iid . ' ' . $hash, LOGGER_DEBUG); @@ -352,6 +361,10 @@ function post_activity_item($arr) { } +/** + * @function get_public_feed($channel,$params) + * generate an Atom feed + */ function get_public_feed($channel,$params) { @@ -388,6 +401,9 @@ function get_public_feed($channel,$params) { return get_feed_for($channel,get_observer_hash(),$params); } + + + function get_feed_for($channel, $observer_hash, $params) { if(! channel) @@ -1822,6 +1838,9 @@ function item_store($arr,$allow_exec = false) { return $ret; } + call_hooks('item_store',$arr); + + // This hook remains for backward compatibility. call_hooks('post_remote',$arr); if(x($arr,'cancel')) { @@ -1952,8 +1971,6 @@ function item_store($arr,$allow_exec = false) { function item_store_update($arr,$allow_exec = false) { - - $d = array('item' => $arr, 'allow_exec' => $allow_exec); call_hooks('item_store_update', $d ); $arr = $d['item']; @@ -2100,7 +2117,7 @@ function item_store_update($arr,$allow_exec = false) { // $arr['item_flags'] = ((x($arr,'item_flags')) ? intval($arr['item_flags']) : $orig[0]['item_flags'] ); $arr['sig'] = ((x($arr,'sig')) ? $arr['sig'] : ''); - $arr['layout_mid'] = ((x($arr,'layout_mid')) ? dbesc($arr['layout_mid']) : $orig[0]['layout_mid'] ); + $arr['layout_mid'] = ((array_key_exists('layout_mid',$arr)) ? dbesc($arr['layout_mid']) : $orig[0]['layout_mid'] ); call_hooks('post_remote_update',$arr); @@ -2284,27 +2301,6 @@ function tag_deliver($uid,$item_id) { $item = $i[0]; - - $terms = get_terms_oftype($item['term'],TERM_BOOKMARK); - - if($terms && (! $item['item_restrict'])) { - logger('tag_deliver: found bookmark'); - $bookmark_self = intval(get_pconfig($uid,'system','bookmark_self')); - if(perm_is_allowed($u[0]['channel_id'],$item['author_xchan'],'bookmark') && (($item['author_xchan'] != $u[0]['channel_hash']) || ($bookmark_self))) { - require_once('include/bookmarks.php'); - require_once('include/Contact.php'); - - $s = q("select * from xchan where xchan_hash = '%s' limit 1", - dbesc($item['author_xchan']) - ); - if($s) { - foreach($terms as $t) { - bookmark_add($u[0],$s[0],$t,$item['item_private']); - } - } - } - } - if(($item['source_xchan']) && ($item['item_flags'] & ITEM_UPLINK) && ($item['item_flags'] & ITEM_THREAD_TOP) && ($item['edited'] != $item['created'])) { // this is an update to a post which was already processed by us and has a second delivery chain // Just start the second delivery chain to deliver the updated post @@ -2450,16 +2446,26 @@ function tag_deliver($uid,$item_id) { $body = preg_replace('/\[share(.*?)\[\/share\]/','',$body); + $tagged = false; + $plustagged = false; + + $pattern = '/@\!?\[zrl\=' . preg_quote($term['url'],'/') . '\]' . preg_quote($u[0]['channel_name'],'/') . '\[\/zrl\]/'; + if(preg_match($pattern,$body,$matches)) + $tagged = true; + $pattern = '/@\!?\[zrl\=' . preg_quote($term['url'],'/') . '\]' . preg_quote($u[0]['channel_name'] . '+','/') . '\[\/zrl\]/'; + if(preg_match($pattern,$body,$matches)) + $plustagged = true; - if(! preg_match($pattern,$body,$matches)) { + if(! ($tagged || $plustagged)) { logger('tag_deliver: mention was in a reshare - ignoring'); return; } - - // All good. - // Send a notification + $arr = array('channel_id' => $uid, 'item' => $item, 'body' => $body); + call_hooks('tagged',$arr); + + // Valid tag. Send a notification require_once('include/enotify.php'); notification(array( @@ -2472,6 +2478,14 @@ function tag_deliver($uid,$item_id) { 'otype' => 'item' )); + // Just a normal tag? + + if(! $plustagged) { + logger('tag_deliver: not a plus tag', LOGGER_DEBUG); + return; + } + + // plustagged - keep going, next check permissions if(! perm_is_allowed($uid,$item['author_xchan'],'tag_deliver')) { logger('tag_delivery denied for uid ' . $uid . ' and xchan ' . $item['author_xchan']); @@ -3707,13 +3721,53 @@ function first_post_date($uid,$wall = false) { intval($uid) ); - if(count($r)) { + if($r) { // logger('first_post_date: ' . $r[0]['id'] . ' ' . $r[0]['created'], LOGGER_DATA); return substr(datetime_convert('',date_default_timezone_get(),$r[0]['created']),0,10); } return false; } +/** + * modified posted_dates() {below} to arrange the list in years, which we'll eventually + * use to make a menu of years with collapsible sub-menus for the months instead of the + * current flat list of all representative dates. + */ + +function list_post_dates($uid,$wall) { + $dnow = datetime_convert('',date_default_timezone_get(),'now','Y-m-d'); + + $dthen = first_post_date($uid,$wall); + if(! $dthen) + return array(); + + // If it's near the end of a long month, backup to the 28th so that in + // consecutive loops we'll always get a whole month difference. + + if(intval(substr($dnow,8)) > 28) + $dnow = substr($dnow,0,8) . '28'; + if(intval(substr($dthen,8)) > 28) + $dnow = substr($dthen,0,8) . '28'; + + $ret = array(); + // Starting with the current month, get the first and last days of every + // month down to and including the month of the first post + while(substr($dnow, 0, 7) >= substr($dthen, 0, 7)) { + $dyear = intval(substr($dnow,0,4)); + $dstart = substr($dnow,0,8) . '01'; + $dend = substr($dnow,0,8) . get_dim(intval($dnow),intval(substr($dnow,5))); + $start_month = datetime_convert('','',$dstart,'Y-m-d'); + $end_month = datetime_convert('','',$dend,'Y-m-d'); + $str = day_translate(datetime_convert('','',$dnow,'F')); + if(! $ret[$dyear]) + $ret[$dyear] = array(); + $ret[$dyear][] = array($str,$end_month,$start_month); + $dnow = datetime_convert('','',$dnow . ' -1 month', 'Y-m-d'); + } + return $ret; +} + + function posted_dates($uid,$wall) { $dnow = datetime_convert('',date_default_timezone_get(),'now','Y-m-d'); @@ -3833,18 +3887,19 @@ function zot_feed($uid,$observer_xchan,$mindate) { $items = array(); if(is_sys_channel($uid)) { - require_once('include/security.php'); - $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 + $r = q("SELECT distinct parent from item + WHERE uid != %d + and uid in (" . stream_perms_api_uids(PERMS_PUBLIC) . ") AND item_restrict = 0 AND (item_flags & %d) and item_private = 0 $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 + $r = q("SELECT distinct parent from item + WHERE uid = %d AND item_restrict = 0 AND (item_flags & %d) $sql_extra ORDER BY created ASC $limit", intval($uid), @@ -3853,11 +3908,12 @@ function zot_feed($uid,$observer_xchan,$mindate) { } if($r) { - $parents_str = ids_to_querystr($r,'id'); - + $parents_str = ids_to_querystr($r,'parent'); + $sys_query = ((is_sys_channel($uid)) ? $sql_extra : ''); + $items = q("SELECT `item`.*, `item`.`id` AS `item_id` FROM `item` WHERE `item`.`item_restrict` = 0 - AND `item`.`parent` IN ( %s ) ", + AND `item`.`parent` IN ( %s ) $sys_query ", dbesc($parents_str) ); } @@ -3872,11 +3928,13 @@ function zot_feed($uid,$observer_xchan,$mindate) { else $items = array(); + + logger('zot_feed: number items: ' . count($items),LOGGER_DEBUG); + foreach($items as $item) $result[] = encode_item($item); return $result; - } |