2016-06-03 03:31:34 +00:00
|
|
|
<?php
|
|
|
|
namespace Zotlabs\Module;
|
|
|
|
|
2019-12-10 23:35:36 +00:00
|
|
|
use App;
|
2019-04-30 02:29:11 +00:00
|
|
|
use Zotlabs\Web\Controller;
|
|
|
|
use Zotlabs\Lib\Activity;
|
2020-06-15 07:29:56 +00:00
|
|
|
use Zotlabs\Daemon\Run;
|
2016-06-03 03:31:34 +00:00
|
|
|
|
2019-04-30 02:29:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
class React extends Controller {
|
2016-06-03 03:31:34 +00:00
|
|
|
|
|
|
|
function get() {
|
2017-11-27 02:29:24 +00:00
|
|
|
|
2016-06-03 03:31:34 +00:00
|
|
|
if(! local_channel())
|
|
|
|
return;
|
|
|
|
|
2017-11-27 02:29:24 +00:00
|
|
|
$sys = get_sys_channel();
|
2019-12-10 23:35:36 +00:00
|
|
|
$channel = App::get_channel();
|
2017-11-27 02:29:24 +00:00
|
|
|
|
2016-06-03 03:31:34 +00:00
|
|
|
$postid = $_REQUEST['postid'];
|
|
|
|
|
|
|
|
if(! $postid)
|
|
|
|
return;
|
|
|
|
|
|
|
|
$emoji = $_REQUEST['emoji'];
|
2017-11-27 02:29:24 +00:00
|
|
|
|
|
|
|
|
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())
|
|
|
|
);
|
|
|
|
|
2017-11-27 02:29:24 +00:00
|
|
|
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;
|
2017-11-27 02:29:24 +00:00
|
|
|
}
|
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
|
|
|
|
2019-04-30 02:29:11 +00:00
|
|
|
$n = [] ;
|
2016-06-03 03:31:34 +00:00
|
|
|
$n['aid'] = $channel['channel_account_id'];
|
|
|
|
$n['uid'] = $channel['channel_id'];
|
2016-06-04 01:46:59 +00:00
|
|
|
$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);
|
2017-07-11 03:18:33 +00:00
|
|
|
|
2017-11-27 02:29:24 +00:00
|
|
|
retain_item($postid);
|
2017-07-11 03:18:33 +00:00
|
|
|
|
2016-06-03 03:31:34 +00:00
|
|
|
if($x['success']) {
|
|
|
|
$nid = $x['item_id'];
|
2020-06-15 07:29:56 +00:00
|
|
|
Run::Summon( [ 'Notifier', 'like', $nid ] );
|
2016-06-03 03:31:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|