mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-20 21:15:14 +00:00
163 lines
4.1 KiB
PHP
163 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace Code\Module;
|
|
|
|
use App;
|
|
use Code\Lib\Apps;
|
|
use Code\Lib\Activity;
|
|
use Code\Lib\Libsync;
|
|
use Code\Web\Controller;
|
|
use Code\Lib\Navbar;
|
|
use Code\Render\Theme;
|
|
|
|
|
|
class Poke extends Controller
|
|
{
|
|
|
|
public function init()
|
|
{
|
|
|
|
$uid = local_channel();
|
|
if (!$uid) {
|
|
return;
|
|
}
|
|
|
|
if (!Apps::system_app_installed($uid, 'Poke')) {
|
|
return;
|
|
}
|
|
$channel = App::get_channel();
|
|
|
|
$verbs = get_poke_verbs();
|
|
|
|
if (isset($_REQUEST['pokeverb']) && array_key_exists(trim($_REQUEST['pokeverb']), $verbs)) {
|
|
set_pconfig($uid, 'system', 'pokeverb', trim($_REQUEST['pokeverb']));
|
|
return;
|
|
}
|
|
|
|
$verb = get_pconfig($uid, 'system', 'pokeverb', 'poke');
|
|
|
|
if (!array_key_exists($verb, $verbs)) {
|
|
return;
|
|
}
|
|
|
|
$activity = $verbs[$verb][0];
|
|
|
|
$xchan = trim($_REQUEST['xchan']);
|
|
|
|
if (!$xchan) {
|
|
return;
|
|
}
|
|
|
|
$r = q(
|
|
"SELECT * FROM xchan where xchan_hash = '%s' LIMIT 1",
|
|
dbesc($xchan)
|
|
);
|
|
|
|
if (!$r) {
|
|
logger('poke: no target.');
|
|
return;
|
|
}
|
|
|
|
$target = $r[0];
|
|
$parent_item = null;
|
|
|
|
$item_private = 1;
|
|
|
|
if ($target) {
|
|
$allow_cid = '<' . $target['abook_xchan'] . '>';
|
|
$allow_gid = EMPTY_STR;
|
|
$deny_cid = EMPTY_STR;
|
|
$deny_gid = EMPTY_STR;
|
|
}
|
|
|
|
$arr = [];
|
|
|
|
$arr['item_wall'] = 1;
|
|
$arr['owner_xchan'] = $channel['channel_hash'];
|
|
$arr['author_xchan'] = $channel['channel_hash'];
|
|
$arr['allow_cid'] = $allow_cid;
|
|
$arr['allow_gid'] = $allow_gid;
|
|
$arr['deny_cid'] = $deny_cid;
|
|
$arr['deny_gid'] = $deny_gid;
|
|
$arr['verb'] = 'Create';
|
|
$arr['item_private'] = 1;
|
|
$arr['obj_type'] = 'Note';
|
|
$arr['body'] = '[zrl=' . $channel['xchan_url'] . ']' . $channel['xchan_name'] . '[/zrl]' . ' ' . $verbs[$verb][2] . ' ' . '[zrl=' . $target['xchan_url'] . ']' . $target['xchan_name'] . '[/zrl]';
|
|
|
|
|
|
$arr['item_origin'] = 1;
|
|
$arr['item_wall'] = 1;
|
|
|
|
$obj = Activity::encode_item($arr, ((get_config('system', 'activitypub', ACTIVITYPUB_ENABLED)) ? true : false));
|
|
|
|
$i = post_activity_item($arr);
|
|
|
|
if ($i['success']) {
|
|
$item_id = $i['item_id'];
|
|
$r = q(
|
|
"select * from item where id = %d",
|
|
intval($item_id)
|
|
);
|
|
if ($r) {
|
|
xchan_query($r);
|
|
$sync_item = fetch_post_tags($r);
|
|
Libsync::build_sync_packet($uid, ['item' => [encode_item($sync_item[0], true)]]);
|
|
}
|
|
|
|
info(sprintf(t('You %1$s %2$s'), $verbs[$verb][2], $target['xchan_name']));
|
|
}
|
|
|
|
json_return_and_die(['success' => true]);
|
|
}
|
|
|
|
|
|
public function get()
|
|
{
|
|
|
|
if (!local_channel()) {
|
|
notice(t('Permission denied.') . EOL);
|
|
return;
|
|
}
|
|
|
|
if (!Apps::system_app_installed(local_channel(), 'Poke')) {
|
|
$o = '<b>' . t('Poke App (Not Installed)') . '</b><br>';
|
|
$o .= t('Poke or do something else to somebody');
|
|
return $o;
|
|
}
|
|
|
|
return t('Poke app is installed. To use, select Poke from the author drop-down menu in your stream.');
|
|
|
|
/**
|
|
|
|
Navbar::set_selected('Poke');
|
|
|
|
$name = '';
|
|
$id = '';
|
|
|
|
$verbs = get_poke_verbs();
|
|
|
|
$shortlist = [];
|
|
$current = get_pconfig(local_channel(), 'system', 'pokeverb', 'poke');
|
|
foreach ($verbs as $k => $v) {
|
|
$shortlist[] = [$k, $v[1], (($k === $current) ? true : false)];
|
|
}
|
|
|
|
|
|
$title = t('Poke');
|
|
$desc = t('Poke, prod or do other things to somebody');
|
|
|
|
$o = replace_macros(Theme::get_template('poke_content.tpl'), array(
|
|
'$title' => $title,
|
|
'$desc' => $desc,
|
|
'$clabel' => t('Recipient'),
|
|
'$choice' => t('Choose your default action'),
|
|
'$verbs' => $shortlist,
|
|
'$submit' => t('Submit'),
|
|
'$id' => $id
|
|
));
|
|
|
|
return $o;
|
|
*/
|
|
|
|
}
|
|
}
|