streams/Code/Module/Card_edit.php

149 lines
4.4 KiB
PHP
Raw Normal View History

2017-08-24 00:46:20 +00:00
<?php
2021-12-03 03:01:39 +00:00
2022-02-16 04:08:28 +00:00
namespace Code\Module;
2017-08-24 00:46:20 +00:00
2021-12-02 22:33:36 +00:00
use App;
2022-02-16 04:08:28 +00:00
use Code\Lib\Apps;
use Code\Lib\PermissionDescription;
use Code\Web\Controller;
use Code\Lib\Channel;
use Code\Lib\Libacl;
use Code\Render\Theme;
2022-02-12 20:43:29 +00:00
2019-03-25 03:08:23 +00:00
2017-08-24 00:46:20 +00:00
require_once('include/conversation.php');
2021-12-02 23:02:31 +00:00
class Card_edit extends Controller
{
public function get()
{
// Figure out which post we're editing
$post_id = ((argc() > 1) ? intval(argv(1)) : 0);
if (!$post_id) {
notice(t('Item not found') . EOL);
2022-08-26 22:37:04 +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 item_type = %d LIMIT 1",
2021-12-02 23:02:31 +00:00
intval($post_id),
intval(ITEM_TYPE_CARD)
);
if ($itm) {
2021-12-03 03:01:39 +00:00
$item_id = q(
"select * from iconfig where cat = 'system' and k = 'CARD' 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
$card_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-08-26 22:37:04 +00:00
return '';
2021-12-02 23:02:31 +00:00
}
$owner = $itm[0]['uid'];
$uid = local_channel();
$observer = App::get_observer();
2022-01-25 01:26:12 +00:00
$channel = Channel::from_id($owner);
2021-12-02 23:02:31 +00:00
if (!$channel) {
notice(t('Channel not found.') . EOL);
2022-08-26 22:37:04 +00:00
return '';
2021-12-02 23:02:31 +00:00
}
$ob_hash = (($observer) ? $observer['xchan_hash'] : '');
if (!perm_is_allowed($owner, $ob_hash, 'write_pages')) {
notice(t('Permission denied.') . EOL);
2022-08-26 22:37:04 +00:00
return '';
2021-12-02 23:02:31 +00:00
}
$is_owner = (($uid && $uid == $owner) ? true : false);
$o = '';
$category = '';
$catsenabled = ((Apps::system_app_installed($owner, 'Categories')) ? 'categories' : '');
if ($catsenabled) {
$itm = fetch_post_tags($itm);
$cats = get_terms_oftype($itm[0]['term'], TERM_CATEGORY);
foreach ($cats as $cat) {
2021-12-03 03:01:39 +00:00
if (strlen($category)) {
2021-12-02 23:02:31 +00:00
$category .= ', ';
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
$category .= $cat['term'];
}
}
if ($itm[0]['attach']) {
$j = json_decode($itm[0]['attach'], true);
if ($j) {
foreach ($j as $jj) {
$itm[0]['body'] .= "\n" . '[attachment]' . basename($jj['href']) . ',' . $jj['revision'] . '[/attachment]' . "\n";
}
}
}
$mimetype = $itm[0]['mimetype'];
$content = $itm[0]['body'];
$rp = 'cards/' . $channel['channel_address'];
$x = array(
'nickname' => $channel['channel_address'],
'bbco_autocomplete' => 'bbcode',
'return_path' => $rp,
'webpage' => ITEM_TYPE_CARD,
'button' => t('Edit'),
'writefiles' => perm_is_allowed($owner, get_observer_hash(), 'write_pages'),
'weblink' => t('Insert web link'),
'hide_voting' => false,
'hide_future' => false,
'hide_location' => false,
'hide_expire' => false,
'showacl' => true,
2022-01-25 20:51:37 +00:00
'acl' => Libacl::populate($itm[0], false, PermissionDescription::fromGlobalPermission('view_pages')),
2021-12-02 23:02:31 +00:00
'permissions' => $itm[0],
'lockstate' => (($itm[0]['allow_cid'] || $itm[0]['allow_gid'] || $itm[0]['deny_cid'] || $itm[0]['deny_gid']) ? 'lock' : 'unlock'),
'ptyp' => $itm[0]['type'],
'mimeselect' => false,
'mimetype' => $itm[0]['mimetype'],
'body' => undo_post_tagging($content),
'post_id' => $post_id,
'visitor' => true,
'title' => htmlspecialchars($itm[0]['title'], ENT_COMPAT, 'UTF-8'),
'placeholdertitle' => t('Title (optional)'),
'pagetitle' => $card_title,
'profile_uid' => (intval($channel['channel_id'])),
'catsenabled' => $catsenabled,
'category' => $category,
2021-03-22 04:56:18 +00:00
'bbcode' => ((in_array($mimetype, [ 'text/bbcode', 'text/x-multicode' ])) ? true : false)
2021-12-02 23:02:31 +00:00
);
2017-08-24 00:46:20 +00:00
2021-12-02 23:02:31 +00:00
$editor = status_editor($x);
2017-08-24 00:46:20 +00:00
2022-02-12 20:43:29 +00:00
$o .= replace_macros(Theme::get_template('edpost_head.tpl'), array(
2021-12-02 23:02:31 +00:00
'$title' => t('Edit Card'),
'$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
));
2017-08-24 00:46:20 +00:00
2021-12-02 23:02:31 +00:00
return $o;
}
2017-08-24 00:46:20 +00:00
}