streams/Zotlabs/Widget/Random_block.php

57 lines
1.3 KiB
PHP
Raw Normal View History

<?php
namespace Zotlabs\Widget;
2021-12-02 22:33:36 +00:00
use App;
2021-12-02 23:02:31 +00:00
class Random_block
{
2021-12-02 23:02:31 +00:00
public function widget($arr)
{
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 (array_key_exists('contains', $arr)) {
2021-12-02 23:02:31 +00:00
$contains = $arr['contains'];
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
$o = '';
2021-12-02 23:02:31 +00:00
require_once('include/security.php');
$sql_options = item_permissions_sql($channel_id);
2021-12-02 23:02:31 +00:00
$randfunc = db_getfunc('RAND');
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 like '%s' and iconfig.k = 'BUILDBLOCK' and
item_type = %d $sql_options order by $randfunc limit 1",
2021-12-02 23:02:31 +00:00
intval($channel_id),
dbesc('%' . $contains . '%'),
intval(ITEM_TYPE_BLOCK)
);
if ($r) {
$o = '<div class="widget bblock">';
2021-12-03 03:01:39 +00:00
if ($r[0]['title']) {
2021-12-02 23:02:31 +00:00
$o .= '<h3>' . $r[0]['title'] . '</h3>';
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
$o .= prepare_text($r[0]['body'], $r[0]['mimetype']);
$o .= '</div>';
}
return $o;
}
}