streams/Code/Module/Blocks.php

186 lines
5.2 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\Web\Controller;
use Code\Lib\Channel;
use Code\Render\Theme;
2022-02-12 20:43:29 +00:00
2022-01-25 20:51:37 +00:00
2016-04-19 03:38:38 +00:00
require_once('include/conversation.php');
2021-12-02 23:02:31 +00:00
class Blocks 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-08-26 22:37:04 +00:00
return '';
2021-12-02 23:02:31 +00:00
}
$which = argv(1);
$_SESSION['return_url'] = App::$query_string;
$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'] : '');
$perms = get_all_perms($owner, $ob_hash);
if (!$perms['write_pages']) {
notice(t('Permission denied.') . EOL);
2022-08-26 22:37:04 +00:00
return '';
2021-12-02 23:02:31 +00:00
}
// Block design features from visitors
if ((!$uid) || ($uid != $owner)) {
notice(t('Permission denied.') . EOL);
2022-08-26 22:37:04 +00:00
return '';
2021-12-02 23:02:31 +00:00
}
2022-08-26 22:37:04 +00:00
$mimetype = (($_REQUEST['mimetype']) ?: get_pconfig($owner, 'system', 'page_mimetype'));
2021-12-02 23:02:31 +00:00
$x = array(
'webpage' => ITEM_TYPE_BLOCK,
'is_owner' => true,
'nickname' => App::$profile['channel_address'],
'lockstate' => (($channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 'lock' : 'unlock'),
'bang' => '',
'showacl' => false,
'visitor' => true,
'mimetype' => $mimetype,
'mimeselect' => true,
'hide_location' => true,
'ptlabel' => t('Block Name'),
'profile_uid' => intval($owner),
'expanded' => true,
'novoting' => true,
'bbco_autocomplete' => 'bbcode',
'bbcode' => true
);
2021-12-03 03:01:39 +00:00
if ($_REQUEST['title']) {
2021-12-02 23:02:31 +00:00
$x['title'] = $_REQUEST['title'];
2021-12-03 03:01:39 +00:00
}
if ($_REQUEST['body']) {
2021-12-02 23:02:31 +00:00
$x['body'] = $_REQUEST['body'];
2021-12-03 03:01:39 +00:00
}
if ($_REQUEST['pagetitle']) {
2021-12-02 23:02:31 +00:00
$x['pagetitle'] = $_REQUEST['pagetitle'];
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
$editor = status_editor($x);
2021-12-03 03:01:39 +00:00
$r = q(
"select iconfig.iid, iconfig.k, iconfig.v, mid, title, body, mimetype, created, edited from iconfig
left join item on iconfig.iid = item.id
where uid = %d and iconfig.cat = 'system' and iconfig.k = 'BUILDBLOCK'
and item_type = %d order by item.created desc",
2021-12-02 23:02:31 +00:00
intval($owner),
intval(ITEM_TYPE_BLOCK)
);
$pages = null;
if ($r) {
$pages = [];
foreach ($r as $rr) {
$element_arr = array(
'type' => 'block',
'title' => $rr['title'],
'body' => $rr['body'],
'created' => $rr['created'],
'edited' => $rr['edited'],
'mimetype' => $rr['mimetype'],
'pagetitle' => $rr['v'],
'mid' => $rr['mid']
);
$pages[$rr['iid']][] = array(
'url' => $rr['iid'],
'name' => $rr['v'],
'title' => $rr['title'],
'created' => $rr['created'],
'edited' => $rr['edited'],
'bb_element' => '[element]' . base64url_encode(json_encode($element_arr)) . '[/element]'
);
}
}
//Build the base URL for edit links
$url = z_root() . '/editblock/' . $which;
2022-08-20 22:30:14 +00:00
$o = replace_macros(Theme::get_template('blocklist.tpl'), array(
2021-12-02 23:02:31 +00:00
'$baseurl' => $url,
'$title' => t('Blocks'),
'$name' => t('Block Name'),
'$blocktitle' => t('Block Title'),
'$created' => t('Created'),
'$edited' => t('Edited'),
'$create' => t('Create'),
'$edit' => t('Edit'),
'$share' => t('Share'),
'$delete' => t('Delete'),
'$editor' => $editor,
'$pages' => $pages,
'$channel' => $which,
'$view' => t('View'),
'$preview' => '1',
));
return $o;
}
2016-04-19 03:38:38 +00:00
}