streams/Zotlabs/Module/React.php

91 lines
1.8 KiB
PHP
Raw Normal View History

2016-06-03 03:31:34 +00:00
<?php
namespace Zotlabs\Module;
use App;
use Zotlabs\Web\Controller;
use Zotlabs\Lib\Activity;
use Zotlabs\Daemon\Master;
2016-06-03 03:31:34 +00:00
class React extends Controller {
2016-06-03 03:31:34 +00:00
function get() {
2016-06-03 03:31:34 +00:00
if(! local_channel())
return;
$sys = get_sys_channel();
$channel = App::get_channel();
2016-06-03 03:31:34 +00:00
$postid = $_REQUEST['postid'];
if(! $postid)
return;
$emoji = $_REQUEST['emoji'];
2020-02-04 01:51:42 +00:00
if($emoji) {
2016-06-03 03:31:34 +00:00
$i = q("select * from item where id = %d and uid = %d",
intval($postid),
intval(local_channel())
);
if(! $i) {
$i = q("select * from item where id = %d and uid = %d",
intval($postid),
intval($sys['channel_id'])
);
if($i) {
$i = [ copy_of_pubitem($channel, $i[0]['mid']) ];
$postid = (($i) ? $i[0]['id'] : 0);
}
}
if(! $i) {
2016-06-03 03:31:34 +00:00
return;
}
2016-06-03 03:31:34 +00:00
2019-05-03 02:39:08 +00:00
$item = array_shift($i);
2016-06-03 03:31:34 +00:00
$n = [] ;
2016-06-03 03:31:34 +00:00
$n['aid'] = $channel['channel_account_id'];
$n['uid'] = $channel['channel_id'];
$n['item_origin'] = true;
2019-05-03 02:39:08 +00:00
$n['item_type'] = $item['item_type'];
2016-06-03 03:31:34 +00:00
$n['parent'] = $postid;
2019-05-03 02:39:08 +00:00
$n['parent_mid'] = $item['mid'];
2019-02-19 22:59:22 +00:00
$n['uuid'] = new_uuid();
$n['mid'] = z_root() . '/item/' . $n['uuid'];
2019-05-03 02:39:08 +00:00
$n['verb'] = 'emojiReaction';
2019-05-03 04:21:10 +00:00
$n['body'] = "\n\n" . '[img=32x32]' . z_root() . '/images/emoji/' . $emoji . '.png[/img]' . "\n\n";
2016-06-03 03:31:34 +00:00
$n['author_xchan'] = $channel['channel_hash'];
2019-05-03 02:39:08 +00:00
$n['obj'] = Activity::fetch_item( [ 'id' => $item['mid'] ] );
$n['obj_type'] = ((array_path_exists('obj/type',$n)) ? $n['obj']['type'] : EMPTY_STR);
2019-05-03 04:21:10 +00:00
$n['tgt_type'] = 'Image';
$n['target'] = [
'type' => 'Image',
'name' => $emoji,
'url' => z_root() . '/images/emoji/' . $emoji . '.png'
];
2019-05-03 02:39:08 +00:00
2016-06-03 03:31:34 +00:00
$x = item_store($n);
retain_item($postid);
2016-06-03 03:31:34 +00:00
if($x['success']) {
$nid = $x['item_id'];
Master::Summon( [ 'Notifier', 'like', $nid ] );
2016-06-03 03:31:34 +00:00
}
}
}
}