streams/Code/Module/React.php

102 lines
2.7 KiB
PHP
Raw Normal View History

2016-06-03 03:31:34 +00:00
<?php
2021-12-03 03:01:39 +00:00
2022-02-16 04:08:28 +00:00
namespace Code\Module;
2016-06-03 03:31:34 +00:00
use App;
2022-02-16 04:08:28 +00:00
use Code\Web\Controller;
use Code\Lib\Activity;
use Code\Daemon\Run;
use Code\Lib\Channel;
2016-06-03 03:31:34 +00:00
2021-12-02 23:02:31 +00:00
class React extends Controller
{
2021-12-02 23:02:31 +00:00
public function get()
{
2021-12-03 03:01:39 +00:00
if (!local_channel()) {
2021-12-02 23:02:31 +00:00
return;
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
2022-01-25 01:26:12 +00:00
$sys = Channel::get_system();
2021-12-02 23:02:31 +00:00
$channel = App::get_channel();
$postid = $_REQUEST['postid'];
2021-12-03 03:01:39 +00:00
if (!$postid) {
2021-12-02 23:02:31 +00:00
return;
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
$emoji = $_REQUEST['emoji'];
if ($emoji) {
2021-12-03 03:01:39 +00:00
$i = q(
"select * from item where id = %d and uid = %d",
2021-12-02 23:02:31 +00:00
intval($postid),
intval(local_channel())
);
if (!$i) {
// try the global public stream
2021-12-03 03:01:39 +00:00
$i = q(
"select * from item where id = %d and uid = %d",
2021-12-02 23:02:31 +00:00
intval($postid),
intval($sys['channel_id'])
);
// try the local public stream
if (!$i) {
2021-12-03 03:01:39 +00:00
$i = q(
"select * from item where id = %d and item_wall = 1 and item_private = 0",
2021-12-02 23:02:31 +00:00
intval($postid)
);
}
2022-01-25 01:26:12 +00:00
if ($i && local_channel() && (!Channel::is_system(local_channel()))) {
2021-12-02 23:02:31 +00:00
$i = [copy_of_pubitem($channel, $i[0]['mid'])];
$postid = (($i) ? $i[0]['id'] : 0);
}
}
if (!$i) {
return;
}
$item = array_shift($i);
$n = [];
$n['aid'] = $channel['channel_account_id'];
$n['uid'] = $channel['channel_id'];
$n['item_origin'] = true;
$n['item_type'] = $item['item_type'];
$n['parent'] = $postid;
$n['parent_mid'] = $item['mid'];
$n['uuid'] = new_uuid();
$n['mid'] = z_root() . '/item/' . $n['uuid'];
$n['verb'] = 'emojiReaction';
$n['body'] = "\n\n" . '[img=32x32]' . z_root() . '/images/emoji/' . $emoji . '.png[/img]' . "\n\n";
$n['author_xchan'] = $channel['channel_hash'];
$n['obj'] = Activity::fetch_item(['id' => $item['mid']]);
$n['obj_type'] = ((array_path_exists('obj/type', $n)) ? $n['obj']['type'] : EMPTY_STR);
$n['tgt_type'] = 'Image';
$n['target'] = [
'type' => 'Image',
'name' => $emoji,
'url' => z_root() . '/images/emoji/' . $emoji . '.png'
];
$x = item_store($n);
retain_item($postid);
if ($x['success']) {
$nid = $x['item_id'];
Run::Summon(['Notifier', 'like', $nid]);
}
}
}
2021-12-03 03:01:39 +00:00
}