streams/Code/Widget/Item.php

66 lines
1.6 KiB
PHP
Raw Normal View History

<?php
2022-02-16 04:08:28 +00:00
namespace Code\Widget;
2021-12-02 22:33:36 +00:00
use App;
require_once('include/security.php');
2022-10-23 21:18:44 +00:00
class Item implements WidgetInterface
2021-12-02 23:02:31 +00:00
{
2022-10-23 21:18:44 +00:00
public function widget(array $arr): string
2021-12-02 23:02:31 +00:00
{
2021-12-02 23:02:31 +00:00
$channel_id = 0;
2021-12-03 03:01:39 +00:00
if (array_key_exists('channel_id', $arr) && intval($arr['channel_id'])) {
2021-12-02 23:02:31 +00:00
$channel_id = intval($arr['channel_id']);
2021-12-03 03:01:39 +00:00
}
if (!$channel_id) {
2021-12-02 23:02:31 +00:00
$channel_id = App::$profile_uid;
2021-12-03 03:01:39 +00:00
}
if (!$channel_id) {
2021-12-02 23:02:31 +00:00
return '';
2021-12-03 03:01:39 +00:00
}
2021-12-03 03:01:39 +00:00
if ((!$arr['mid']) && (!$arr['title'])) {
2021-12-02 23:02:31 +00:00
return '';
2021-12-03 03:01:39 +00:00
}
2021-12-03 03:01:39 +00:00
if (!perm_is_allowed($channel_id, get_observer_hash(), 'view_pages')) {
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
$sql_extra = item_permissions_sql($channel_id);
2021-12-02 23:02:31 +00:00
if ($arr['title']) {
2021-12-03 03:01:39 +00:00
$r = q(
"select item.* from item left join iconfig on item.id = iconfig.iid
where item.uid = %d and iconfig.cat = 'system' and iconfig.v = '%s'
2022-09-03 05:23:54 +00:00
and iconfig.k = 'WEBPAGE' and item_type = %d $sql_extra limit 1",
2021-12-02 23:02:31 +00:00
intval($channel_id),
dbesc($arr['title']),
intval(ITEM_TYPE_WEBPAGE)
);
} else {
2021-12-03 03:01:39 +00:00
$r = q(
"select * from item where mid = '%s' and uid = %d and item_type = "
2021-12-02 23:02:31 +00:00
. intval(ITEM_TYPE_WEBPAGE) . " $sql_extra limit 1",
dbesc($arr['mid']),
intval($channel_id)
);
}
2021-12-03 03:01:39 +00:00
if (!$r) {
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
xchan_query($r);
$r = fetch_post_tags($r);
2021-12-02 23:02:31 +00:00
$o = prepare_page($r[0]);
return $o;
}
}