streams/Code/Module/Editblock.php

163 lines
4.5 KiB
PHP
Raw Normal View History

2016-04-19 03:38:38 +00:00
<?php
2021-12-03 03:01:39 +00:00
2022-02-16 04:08:28 +00:00
namespace Code\Module;
2016-04-19 03:38:38 +00:00
2019-04-17 23:54:06 +00:00
use App;
2022-02-16 04:08:28 +00:00
use Code\Lib\Libprofile;
use Code\Lib\MarkdownSoap;
use Code\Web\Controller;
use Code\Lib\Channel;
use Code\Render\Theme;
2022-02-12 20:43:29 +00:00
2022-01-25 01:26:12 +00:00
2019-04-17 23:54:06 +00:00
2016-05-07 21:05:48 +00:00
require_once('include/conversation.php');
2016-04-19 03:38:38 +00:00
2021-12-02 23:02:31 +00:00
class Editblock extends Controller
{
public function init()
{
if (argc() > 1 && argv(1) === 'sys' && is_site_admin()) {
2022-01-25 01:26:12 +00:00
$sys = Channel::get_system();
2021-12-02 23:02:31 +00:00
if ($sys && intval($sys['channel_id'])) {
App::$is_sys = true;
}
}
2021-12-03 03:01:39 +00:00
if (argc() > 1) {
2021-12-02 23:02:31 +00:00
$which = argv(1);
2021-12-03 03:01:39 +00:00
} else {
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
Libprofile::load($which);
}
public function get()
{
if (!App::$profile) {
notice(t('Requested profile is not available.') . EOL);
App::$error = 404;
2022-09-04 01:35:50 +00:00
return '';
2021-12-02 23:02:31 +00:00
}
$which = argv(1);
$uid = local_channel();
$owner = 0;
$channel = null;
$observer = App::get_observer();
$channel = App::get_channel();
if (App::$is_sys && is_site_admin()) {
2022-01-25 01:26:12 +00:00
$sys = Channel::get_system();
2021-12-02 23:02:31 +00:00
if ($sys && intval($sys['channel_id'])) {
$uid = $owner = intval($sys['channel_id']);
$channel = $sys;
$observer = $sys;
}
}
if (!$owner) {
// Figure out who the page owner is.
2021-12-03 03:01:39 +00:00
$r = q(
"select channel_id from channel where channel_address = '%s'",
2021-12-02 23:02:31 +00:00
dbesc($which)
);
if ($r) {
$owner = intval($r[0]['channel_id']);
}
}
$ob_hash = (($observer) ? $observer['xchan_hash'] : '');
if (!perm_is_allowed($owner, $ob_hash, 'write_pages')) {
notice(t('Permission denied.') . EOL);
2022-09-04 01:35:50 +00:00
return '';
2021-12-02 23:02:31 +00:00
}
$is_owner = (($uid && $uid == $owner) ? true : false);
$o = '';
// Figure out which post we're editing
$post_id = ((argc() > 2) ? intval(argv(2)) : 0);
if (!($post_id && $owner)) {
notice(t('Item not found') . EOL);
2022-09-04 01:35:50 +00:00
return '';
2021-12-02 23:02:31 +00:00
}
2021-12-03 03:01:39 +00:00
$itm = q(
"SELECT * FROM item WHERE id = %d and uid = %s LIMIT 1",
2021-12-02 23:02:31 +00:00
intval($post_id),
intval($owner)
);
if ($itm) {
2021-12-03 03:01:39 +00:00
$item_id = q(
"select * from iconfig where cat = 'system' and k = 'BUILDBLOCK' and iid = %d limit 1",
2021-12-02 23:02:31 +00:00
intval($itm[0]['id'])
);
2021-12-03 03:01:39 +00:00
if ($item_id) {
2021-12-02 23:02:31 +00:00
$block_title = $item_id[0]['v'];
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
} else {
notice(t('Item not found') . EOL);
2022-09-04 01:35:50 +00:00
return '';
2021-12-02 23:02:31 +00:00
}
$mimetype = $itm[0]['mimetype'];
$content = $itm[0]['body'];
2021-12-03 03:01:39 +00:00
if ($itm[0]['mimetype'] === 'text/markdown') {
2021-12-02 23:02:31 +00:00
$content = MarkdownSoap::unescape($itm[0]['body']);
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
$rp = 'blocks/' . $channel['channel_address'];
2022-09-04 01:35:50 +00:00
$x = [
2016-05-07 21:05:48 +00:00
'nickname' => $channel['channel_address'],
2021-03-22 04:56:18 +00:00
'bbco_autocomplete'=> ((in_array($mimetype, [ 'text/bbcode', 'text/x-multicode' ])) ? 'bbcode' : 'comanche-block'),
2016-05-07 21:05:48 +00:00
'return_path' => $rp,
'webpage' => ITEM_TYPE_BLOCK,
'ptlabel' => t('Block Name'),
'button' => t('Edit'),
2021-03-22 04:56:18 +00:00
'writefiles' => ((in_array($mimetype, [ 'text/bbcode', 'text/x-multicode' ])) ? perm_is_allowed($owner, get_observer_hash(), 'write_storage') : false),
'weblink' => ((in_array($mimetype, [ 'text/bbcode' , 'text/x-multicode' ])) ? t('Insert web link') : false),
2016-05-07 21:05:48 +00:00
'hide_voting' => true,
'hide_future' => true,
'hide_location' => true,
'hide_expire' => true,
'showacl' => false,
'ptyp' => $itm[0]['type'],
'mimeselect' => true,
'mimetype' => $itm[0]['mimetype'],
2017-03-18 23:41:43 +00:00
'body' => undo_post_tagging($content),
2016-05-07 21:05:48 +00:00
'post_id' => $post_id,
'visitor' => true,
'title' => htmlspecialchars($itm[0]['title'],ENT_COMPAT,'UTF-8'),
'placeholdertitle' => t('Title (optional)'),
'pagetitle' => $block_title,
'profile_uid' => (intval($channel['channel_id'])),
2021-03-22 04:56:18 +00:00
'bbcode' => ((in_array($mimetype, [ 'text/bbcode' , 'text/x-multicode' ])) ? true : false)
2022-09-04 01:35:50 +00:00
];
2016-05-04 09:49:29 +00:00
2021-12-02 23:02:31 +00:00
$editor = status_editor($x);
2016-05-04 09:49:29 +00:00
2022-09-04 01:35:50 +00:00
$o .= replace_macros(Theme::get_template('edpost_head.tpl'), [
2021-12-02 23:02:31 +00:00
'$title' => t('Edit Block'),
'$delete' => ((($itm[0]['author_xchan'] === $ob_hash) || ($itm[0]['owner_xchan'] === $ob_hash)) ? t('Delete') : false),
'$id' => $itm[0]['id'],
'$cancel' => t('Cancel'),
'$editor' => $editor
2022-09-04 01:35:50 +00:00
]);
2016-05-04 09:49:29 +00:00
2021-12-02 23:02:31 +00:00
return $o;
}
2016-05-04 09:53:38 +00:00
}