diff options
author | friendica <info@friendica.com> | 2013-06-16 20:44:29 -0700 |
---|---|---|
committer | friendica <info@friendica.com> | 2013-06-16 20:44:29 -0700 |
commit | 28cd8594a7dcaf7d21b8b92c44ace34dc8aa6dd4 (patch) | |
tree | 3ab9fa8c4b810cc9f5626e3585b45fb047623c5e /include | |
parent | 764ee785f5505c2be804a850b8e4029598d81739 (diff) | |
download | volse-hubzilla-28cd8594a7dcaf7d21b8b92c44ace34dc8aa6dd4.tar.gz volse-hubzilla-28cd8594a7dcaf7d21b8b92c44ace34dc8aa6dd4.tar.bz2 volse-hubzilla-28cd8594a7dcaf7d21b8b92c44ace34dc8aa6dd4.zip |
implement 'can_comment_on_post()' which doesn't require a separate DB lookup per item.
Diffstat (limited to 'include')
-rw-r--r-- | include/ItemObject.php | 2 | ||||
-rwxr-xr-x | include/items.php | 42 | ||||
-rwxr-xr-x | include/text.php | 2 |
3 files changed, 43 insertions, 3 deletions
diff --git a/include/ItemObject.php b/include/ItemObject.php index ccd192ff5..351f446d4 100644 --- a/include/ItemObject.php +++ b/include/ItemObject.php @@ -44,7 +44,7 @@ class Item extends BaseObject { $this->commentable = $this->writable; if(($this->observer) && (! $this->writable)) { - $this->commentable = perm_is_allowed($this->data['uid'],$this->observer['xchan_hash'],'post_comments'); + $this->commentable = can_comment_on_post($this->observer['xchan_hash'],$data); } // logger('writable: ' . $this->writable); diff --git a/include/items.php b/include/items.php index 9d93accfe..93fc09ae9 100755 --- a/include/items.php +++ b/include/items.php @@ -53,6 +53,37 @@ function collect_recipients($item,&$private) { } + +function can_comment_on_post($observer_xchan,$item) { + if(! $observer_xchan) + return false; + if($item['comment_policy'] === 'none') + return false; + switch($item['comment_policy']) { + case 'self': + if($observer_xchan === $item['author_xchan'] || $observer_xchan === $item['owner_xchan']) + return true; + break; + case 'public': + return false; + break; + case 'contacts': + case '': + if(($item['owner']['abook_xchan']) && ($item['owner']['abook_their_perms'] & PERMS_W_COMMENT)) + return true; + break; + default: + break; + } + if(strstr('network:',$item['comment_policy']) && strstr('red',$item['comment_policy'])) + return true; + if(strstr('site:', $item['comment_policy']) && strstr(get_app()->get_hostname(),$item['comment_policy'])) + return true; + + return false; +} + + /** * @function red_zrl_callback * preg_match function when fixing 'naked' links in mod item.php @@ -142,6 +173,7 @@ function post_activity_item($arr) { $arr['deny_cid'] = ((x($arr,'deny_cid')) ? $arr['deny_cid'] : $channel['channel_deny_cid']); $arr['deny_gid'] = ((x($arr,'deny_gid')) ? $arr['deny_gid'] : $channel['channel_deny_gid']); + $arr['comment_policy'] = map_policy($channel['channel_w_comment']); // for the benefit of plugins, we will behave as if this is an API call rather than a normal online post @@ -481,7 +513,8 @@ function get_item_elements($x) { $arr['mimetype'] = (($x['mimetype']) ? htmlentities($x['mimetype'], ENT_COMPAT,'UTF-8',false) : ''); $arr['obj_type'] = (($x['object_type']) ? htmlentities($x['object_type'], ENT_COMPAT,'UTF-8',false) : ''); $arr['tgt_type'] = (($x['target_type']) ? htmlentities($x['target_type'], ENT_COMPAT,'UTF-8',false) : ''); - + $arr['comment_policy'] = (($x['comment_scope']) ? htmlentities($x['comment_scope'], ENT_COMPAT,'UTF-8',false) : 'contacts'); + $arr['object'] = activity_sanitise($x['object']); $arr['target'] = activity_sanitise($x['target']); @@ -1332,10 +1365,17 @@ function item_store($arr,$force_parent = false) { $arr['attach'] = ((x($arr,'attach')) ? notags(trim($arr['attach'])) : ''); $arr['app'] = ((x($arr,'app')) ? notags(trim($arr['app'])) : ''); $arr['item_restrict'] = ((x($arr,'item_restrict')) ? intval($arr['item_restrict']) : 0 ); + + $arr['comment_policy'] = ((x($arr,'comment_policy')) ? notags(trim($arr['comment_policy'])) : 'contacts' ); + $arr['item_flags'] = ((x($arr,'item_flags')) ? intval($arr['item_flags']) : 0 ); $arr['item_flags'] = $arr['item_flags'] | ITEM_UNSEEN; + if($arr['comment_policy'] == 'none') + $arr['item_flags'] = $arr['item_flags'] | ITEM_NOCOMMENT; + + // handle time travelers // Allow a bit of fudge in case somebody just has a slightly slow/fast clock diff --git a/include/text.php b/include/text.php index 71f2257ac..c51ee0bd2 100755 --- a/include/text.php +++ b/include/text.php @@ -1794,7 +1794,7 @@ function ids_to_querystr($arr,$idx = 'id') { // author_xchan and owner_xchan. If $abook is true also include the abook info. // This is needed in the API to save extra per item lookups there. -function xchan_query(&$items,$abook = false) { +function xchan_query(&$items,$abook = true) { $arr = array(); if($items && count($items)) { foreach($items as $item) { |