mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-20 06:55:19 +00:00
56 lines
1.4 KiB
PHP
56 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Code\Widget;
|
|
|
|
use App;
|
|
|
|
class Random_block implements WidgetInterface
|
|
{
|
|
|
|
public function widget(array $arguments): string
|
|
{
|
|
|
|
$channel_id = 0;
|
|
if (array_key_exists('channel_id', $arguments) && intval($arguments['channel_id'])) {
|
|
$channel_id = intval($arguments['channel_id']);
|
|
}
|
|
if (!$channel_id) {
|
|
$channel_id = App::$profile_uid;
|
|
}
|
|
if (!$channel_id) {
|
|
return '';
|
|
}
|
|
|
|
if (array_key_exists('contains', $arguments)) {
|
|
$contains = $arguments['contains'];
|
|
}
|
|
|
|
$o = '';
|
|
|
|
require_once('include/security.php');
|
|
$sql_options = item_permissions_sql($channel_id);
|
|
|
|
$randfunc = db_getfunc('RAND');
|
|
|
|
$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 like '%s' and iconfig.k = 'BUILDBLOCK' and
|
|
item_type = %d $sql_options order by $randfunc limit 1",
|
|
intval($channel_id),
|
|
dbesc('%' . $contains . '%'),
|
|
intval(ITEM_TYPE_BLOCK)
|
|
);
|
|
|
|
if ($r) {
|
|
$o = '<div class="widget bblock">';
|
|
if ($r[0]['title']) {
|
|
$o .= '<h3>' . $r[0]['title'] . '</h3>';
|
|
}
|
|
|
|
$o .= prepare_text($r[0]['body'], $r[0]['mimetype']);
|
|
$o .= '</div>';
|
|
}
|
|
|
|
return $o;
|
|
}
|
|
}
|