diff options
author | friendica <info@friendica.com> | 2013-04-04 18:54:24 -0700 |
---|---|---|
committer | friendica <info@friendica.com> | 2013-04-04 18:54:24 -0700 |
commit | 989e78137edf1c8d0a85038965fb12e7bffb3e7a (patch) | |
tree | 3fe185b3fdd8fe8d42544df869680c38f28128f3 /include/items.php | |
parent | 6e17be3e85b710f0197e13051374eb45b675e93c (diff) | |
download | volse-hubzilla-989e78137edf1c8d0a85038965fb12e7bffb3e7a.tar.gz volse-hubzilla-989e78137edf1c8d0a85038965fb12e7bffb3e7a.tar.bz2 volse-hubzilla-989e78137edf1c8d0a85038965fb12e7bffb3e7a.zip |
wrapper function to create arbitrary activities (e.g. for plugins and apps) with a minimal amount of fuss, though the amount of fuss could increase significantly depending on the nature of the activity. For a simple wall post, just set the $arr['body'] to the desired text and we'll do the rest. If the activity requires special verbs, objects or targets, these will all need to be constructed.
Diffstat (limited to 'include/items.php')
-rwxr-xr-x | include/items.php | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/include/items.php b/include/items.php index ebff34496..27213b9d2 100755 --- a/include/items.php +++ b/include/items.php @@ -53,6 +53,71 @@ function collect_recipients($item,&$private) { } +/** + * @function post_activity_item($arr) + * + * post an activity + * + * @param array $arr + * + * In its simplest form one needs only to set $arr['body'] to post a note to the logged in channel's wall. + * Much more complex activities can be created. Permissions are checked. No filtering, tag expansion + * or other processing is performed. + * + * @returns array + * 'success' => true or false + * 'activity' => the resulting activity if successful + */ + +function post_activity_item($arr) { + + $ret = array('success' => false); + + if(! x($arr,'item_flags')) { + $arr['item_flags'] = ITEM_ORIGIN | ITEM_WALL | ITEM_THREAD_TOP; + } + + $channel = get_app()->get_channel(); + $observer = get_app()->get_observer(); + + $arr['aid'] = ((x($arr,'aid')) ? $arr['aid'] : $channel['channel_account_id']); + $arr['uid'] = ((x($arr,'uid')) ? $arr['uid'] : $channel['channel_id']); + + if(! perm_is_allowed($arr['uid'],$observer['xchan_hash'],(($arr['parent']) ? 'post_comment' : 'post_wall'))) { + $ret['message'] = t('Permission denied'); + return $ret; + } + + $arr['mid'] = ((x($arr,'mid')) ? $arr['mid'] : item_message_id()); + $arr['parent_mid'] = ((x($arr,'parent_mid')) ? $arr['parent_mid'] : $arr['mid']); + $arr['thr_parent'] = ((x($arr,'thr_parent')) ? $arr['thr_parent'] : $arr['mid']); + + $arr['owner_xchan'] = ((x($arr,'owner_xchan')) ? $arr['owner_xchan'] : $channel['channel_hash']); + $arr['author_xchan'] = ((x($arr,'author_xchan')) ? $arr['author_xchan'] : $observer['xchan_hash']); + + $arr['verb'] = ((x($arr,'verb')) ? $arr['verb'] : ACTIVITY_POST); + $arr['obj_type'] = ((x($arr,'obj_type')) ? $arr['obj_type'] : ACTIVITY_OBJ_NOTE); + + $arr['allow_cid'] = ((x($arr,'allow_cid')) ? $arr['allow_cid'] : $channel['channel_allow_cid']); + $arr['allow_gid'] = ((x($arr,'allow_gid')) ? $arr['allow_gid'] : $channel['channel_allow_gid']); + $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']); + + $post_id = item_store($arr); + + if($post_id) { + $arr['id'] = $post_id; + call_hooks('post_local_end', $arr); + proc_run('php','include/notifier.php','activity',$post_id); + $ret['success'] = true; + $ret['activity'] = $ret; + } + + return $ret; + +} + + function get_public_feed($channel,$params) { |