streams/mod/mood.php

140 lines
3.2 KiB
PHP
Raw Normal View History

2012-08-24 03:00:10 +00:00
<?php
require_once('include/security.php');
require_once('include/bbcode.php');
require_once('include/items.php');
function mood_init(&$a) {
2015-01-29 04:56:04 +00:00
if(! local_channel())
2012-08-24 03:00:10 +00:00
return;
2015-01-29 04:56:04 +00:00
$uid = local_channel();
$channel = $a->get_channel();
2012-08-24 03:00:10 +00:00
$verb = notags(trim($_GET['verb']));
if(! $verb)
return;
$verbs = get_mood_verbs();
if(! array_key_exists($verb,$verbs))
2012-08-24 03:00:10 +00:00
return;
$activity = ACTIVITY_MOOD . '#' . urlencode($verb);
$parent = ((x($_GET,'parent')) ? intval($_GET['parent']) : 0);
logger('mood: verb ' . $verb, LOGGER_DEBUG);
if($parent) {
$r = q("select mid, owner_xchan, private, allow_cid, allow_gid, deny_cid, deny_gid
2012-08-24 03:00:10 +00:00
from item where id = %d and parent = %d and uid = %d limit 1",
intval($parent),
intval($parent),
intval($uid)
);
if(count($r)) {
$parent_mid = $r[0]['mid'];
$private = $r[0]['item_private'];
2012-08-24 03:00:10 +00:00
$allow_cid = $r[0]['allow_cid'];
$allow_gid = $r[0]['allow_gid'];
$deny_cid = $r[0]['deny_cid'];
$deny_gid = $r[0]['deny_gid'];
}
}
else {
2012-11-14 03:32:59 +00:00
$private = 0;
2012-08-24 03:00:10 +00:00
2012-11-14 03:32:59 +00:00
$allow_cid = $channel['channel_allow_cid'];
$allow_gid = $channel['channel_allow_gid'];
$deny_cid = $channel['channel_deny_cid'];
$deny_gid = $channel['channel_deny_gid'];
2012-08-24 03:00:10 +00:00
}
2012-11-14 03:32:59 +00:00
$poster = $a->get_observer();
2012-08-24 03:00:10 +00:00
$mid = item_message_id();
2012-08-24 03:00:10 +00:00
$action = sprintf( t('%1$s is %2$s','mood'), '[zrl=' . $poster['xchan_url'] . ']' . $poster['xchan_name'] . '[/zrl]' , $verbs[$verb]);
$item_flags = ITEM_WALL|ITEM_ORIGIN;
if(! $parent_mid)
2012-11-14 03:32:59 +00:00
$item_flags |= ITEM_THREAD_TOP;
2012-08-24 03:00:10 +00:00
$arr = array();
2012-11-14 03:32:59 +00:00
$arr['aid'] = get_account_id();
2012-08-24 03:00:10 +00:00
$arr['uid'] = $uid;
$arr['mid'] = $mid;
$arr['parent_mid'] = (($parent_mid) ? $parent_mid : $mid);
2012-11-14 03:32:59 +00:00
$arr['item_flags'] = $item_flags;
$arr['author_xchan'] = $poster['xchan_hash'];
$arr['owner_xchan'] = (($parent_mid) ? $r[0]['owner_xchan'] : $poster['xchan_hash']);
2012-08-24 03:00:10 +00:00
$arr['title'] = '';
$arr['allow_cid'] = $allow_cid;
$arr['allow_gid'] = $allow_gid;
$arr['deny_cid'] = $deny_cid;
$arr['deny_gid'] = $deny_gid;
$arr['item_private'] = $private;
2012-08-24 03:00:10 +00:00
$arr['verb'] = $activity;
$arr['body'] = $action;
if ((! $arr['plink']) && ($arr['item_flags'] & ITEM_THREAD_TOP)) {
$arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . $arr['mid'];
}
$post = item_store($arr);
$item_id = $post['item_id'];
2012-08-24 03:00:10 +00:00
if($item_id) {
2012-11-14 03:32:59 +00:00
proc_run('php',"include/notifier.php","activity", $item_id);
}
2012-08-24 03:00:10 +00:00
2012-11-14 03:32:59 +00:00
call_hooks('post_local_end', $arr);
2012-11-14 04:53:33 +00:00
if($_SESSION['return_url'])
goaway(z_root() . '/' . $_SESSION['return_url']);
2012-08-24 03:00:10 +00:00
return;
}
function mood_content(&$a) {
2015-01-29 04:56:04 +00:00
if(! local_channel()) {
2012-08-24 03:00:10 +00:00
notice( t('Permission denied.') . EOL);
return;
}
$parent = ((x($_GET,'parent')) ? intval($_GET['parent']) : '0');
$verbs = get_mood_verbs();
$shortlist = array();
foreach($verbs as $k => $v)
if($v !== 'NOTRANSLATION')
$shortlist[] = array($k,$v);
$tpl = get_markup_template('mood_content.tpl');
$o = replace_macros($tpl,array(
'$title' => t('Mood'),
'$desc' => t('Set your current mood and tell your friends'),
'$verbs' => $shortlist,
'$parent' => $parent,
'$submit' => t('Submit'),
));
return $o;
2015-01-09 14:18:45 +00:00
}