streams/Zotlabs/Module/Editpost.php

149 lines
4.2 KiB
PHP
Raw Normal View History

2016-04-19 03:38:38 +00:00
<?php
2021-06-04 05:02:38 +00:00
namespace Zotlabs\Module;
2016-04-19 03:38:38 +00:00
2021-06-04 05:02:38 +00:00
use App;
use Zotlabs\Web\Controller;
2019-03-25 03:08:23 +00:00
use Zotlabs\Lib\Apps;
2021-03-28 19:14:47 +00:00
use Zotlabs\Lib\PermissionDescription;
2019-03-25 03:08:23 +00:00
2016-04-19 03:38:38 +00:00
require_once('include/acl_selectors.php');
require_once('include/taxonomy.php');
require_once('include/conversation.php');
2016-04-19 03:38:38 +00:00
2021-06-04 05:02:38 +00:00
class Editpost extends Controller {
2016-04-19 03:38:38 +00:00
function get() {
2016-04-30 18:47:52 +00:00
2021-06-04 05:02:38 +00:00
$output = EMPTY_STR;
2016-04-30 18:47:52 +00:00
2021-06-04 05:02:38 +00:00
if (! local_channel()) {
2016-04-19 03:38:38 +00:00
notice( t('Permission denied.') . EOL);
return;
}
2016-04-30 18:47:52 +00:00
2016-04-19 03:38:38 +00:00
$post_id = ((argc() > 1) ? intval(argv(1)) : 0);
2016-04-30 18:47:52 +00:00
2021-06-04 05:02:38 +00:00
if (! $post_id) {
2016-04-19 03:38:38 +00:00
notice( t('Item not found') . EOL);
return;
}
2016-04-30 18:47:52 +00:00
2021-06-04 05:02:38 +00:00
$item = q("SELECT * FROM item WHERE id = %d AND ( owner_xchan = '%s' OR author_xchan = '%s' ) LIMIT 1",
2016-04-19 03:38:38 +00:00
intval($post_id),
dbesc(get_observer_hash()),
dbesc(get_observer_hash())
);
2016-04-30 18:47:52 +00:00
// don't allow web editing of potentially binary content (item_obscured = 1)
2021-06-04 05:02:38 +00:00
if ((! $item) || intval($item[0]['item_obscured'])) {
2016-04-19 03:38:38 +00:00
notice( t('Item is not editable') . EOL);
return;
}
2016-04-30 18:47:52 +00:00
2021-06-04 05:02:38 +00:00
$item = array_shift($item);
$owner_uid = intval($item['uid']);
$owner = channelx_by_n($owner_uid);
if ($item['resource_type'] === 'photo' && $item['resource_id'] && $owner) {
goaway(z_root() . '/photos/' . $owner['channel_address'] . '/image/' . $item['resource_id'] . '?expandform=1');
2017-05-29 23:25:27 +00:00
}
2021-06-04 05:02:38 +00:00
if ($item['resource_type'] === 'event' && $item['resource_id']) {
goaway(z_root() . '/events/' . $item['resource_id'] . '?expandform=1');
2016-04-19 03:38:38 +00:00
}
2016-04-30 18:47:52 +00:00
2021-06-04 05:02:38 +00:00
$channel = App::get_channel();
2016-04-19 03:38:38 +00:00
$category = '';
$collections = [];
2019-03-25 03:08:23 +00:00
$catsenabled = ((Apps::system_app_installed($owner_uid,'Categories')) ? 'categories' : '');
2016-04-30 18:47:52 +00:00
// we have a single item, but fetch_post_tags expects an array. Convert it before and after.
$item = array_shift(fetch_post_tags([$item]));
2021-06-04 05:02:38 +00:00
if ($catsenabled) {
$cats = get_terms_oftype($item['term'], TERM_CATEGORY);
2021-06-04 05:02:38 +00:00
if ($cats) {
foreach ($cats as $cat) {
2021-06-04 05:02:38 +00:00
if (strlen($category)) {
$category .= ', ';
2021-06-04 05:02:38 +00:00
}
$category .= $cat['term'];
}
}
}
2021-06-04 05:02:38 +00:00
$clcts = get_terms_oftype($item['term'], TERM_PCATEGORY);
if ($clcts) {
foreach ($clcts as $clct) {
$collections[] = $clct['term'];
}
2016-04-19 03:38:38 +00:00
}
2016-04-30 18:47:52 +00:00
2021-06-04 05:02:38 +00:00
if ($item['attach']) {
$j = json_decode($item['attach'],true);
if ($j) {
foreach ($j as $jj) {
$item['body'] .= "\n" . '[attachment]' . basename($jj['href']) . ',' . $jj['revision'] . '[/attachment]' . "\n";
2016-04-19 03:38:38 +00:00
}
}
}
2021-06-04 05:02:38 +00:00
if (intval($item['item_unpublished'])) {
2020-11-30 00:38:45 +00:00
// clear the old creation date if editing a saved draft. These will always show as just created.
2021-06-04 05:02:38 +00:00
unset($item['created']);
}
if ($item['summary']) {
$item['body'] = '[summary]' . $item['summary'] . '[/summary]' . "\n\n" . $item['body'];
2020-11-30 00:38:45 +00:00
}
2021-06-04 05:02:38 +00:00
$x = [
'nickname' => $channel['channel_address'],
'item' => $item,
'editor_autocomplete'=> true,
'bbco_autocomplete'=> 'bbcode',
2021-06-04 05:02:38 +00:00
'return_path' => $_SESSION['return_url'],
'button' => t('Submit'),
'hide_voting' => true,
'hide_future' => true,
'hide_location' => true,
2021-06-04 05:02:38 +00:00
'is_draft' => ((intval($item['item_unpublished'])) ? true : false),
'parent' => (($item['mid'] === $item['parent_mid']) ? 0 : $item['parent']),
'mimetype' => $item['mimetype'],
'ptyp' => $item['obj_type'],
'body' => htmlspecialchars_decode(undo_post_tagging($item['body']),ENT_COMPAT),
'post_id' => $post_id,
'defloc' => $channel['channel_location'],
'visitor' => true,
'title' => htmlspecialchars_decode($item['title'],ENT_COMPAT),
'category' => $category,
'showacl' => ((intval($item['item_unpublished'])) ? true : false),
'lockstate' => (($item['allow_cid'] || $item['allow_gid'] || $item['deny_cid'] || $item['deny_gid']) ? 'lock' : 'unlock'),
'acl' => populate_acl($item, true, PermissionDescription::fromGlobalPermission('view_stream'), get_post_aclDialogDescription(), 'acl_dialog_post'),
2021-03-28 19:14:47 +00:00
'bang' => EMPTY_STR,
2021-06-04 05:02:38 +00:00
'permissions' => $item,
'profile_uid' => $owner_uid,
'catsenabled' => $catsenabled,
'collections' => $collections,
2021-06-04 05:02:38 +00:00
'jotnets' => true,
'hide_expire' => true,
2021-06-04 05:02:38 +00:00
'bbcode' => true
];
2021-03-11 03:30:25 +00:00
$editor = status_editor($x);
2016-04-30 18:47:52 +00:00
2021-06-04 05:02:38 +00:00
$output .= replace_macros(get_markup_template('edpost_head.tpl'),
[ '$title' => t('Edit post'), '$cancel' => t('Cancel'), '$editor' => $editor ] );
2016-04-30 18:47:52 +00:00
2021-06-04 05:02:38 +00:00
return $output;
2016-04-30 18:47:52 +00:00
2016-04-19 03:38:38 +00:00
}
2016-04-30 18:47:52 +00:00
2016-04-19 03:38:38 +00:00
}