function block_get_favorite($uid)
{
    static $allowdiy = null;
    $allowdiy = isset($allowdiy) ? $allowdiy : checkperm('allowdiy');
    $blockfavorite = $permission = array();
    $uid = intval($uid);
    if ($uid) {
        foreach (C::t('common_block_favorite')->fetch_all_by_uid($uid) as $value) {
            $blockfavorite[$value['bid']] = $value['bid'];
        }
    }
    if (!empty($blockfavorite)) {
        $blocks = C::t('common_block')->fetch_all($blockfavorite);
        if (!$allowdiy) {
            $permission = C::t('common_block_permission')->fetch_all_by_uid($uid);
        }
        foreach ($blocks as $bid => $value) {
            if (!$allowdiy && $permission[$bid]) {
                $value = array_merge($value, $permission[$bid]);
            }
            $value = formatblockvalue($value);
            $value['favorite'] = true;
            $blockfavorite[$value['bid']] = $value;
        }
        $blockfavorite = array_filter($blockfavorite, 'is_array');
    }
    return $blockfavorite;
}
Пример #2
0
function block_get_favorite($uid)
{
    $blockfavorite = array();
    $uid = intval($uid);
    if ($uid) {
        $query = DB::query('SELECT bid FROM ' . DB::table('common_block_favorite') . " WHERE uid='{$uid}' ORDER BY dateline DESC");
        while ($value = DB::fetch($query)) {
            $blockfavorite[$value['bid']] = $value['bid'];
        }
    }
    $blockfields = 'b.bid,b.blockclass,b.name,b.script,b.dateline,b.cachetime';
    if (!empty($blockfavorite)) {
        if (checkperm('allowdiy')) {
            $query = DB::query("SELECT {$blockfields} FROM " . DB::table('common_block') . ' b' . " WHERE b.bid IN (" . dimplode($blockfavorite) . ")");
        } else {
            $query = DB::query("SELECT {$blockfields},bp.allowmanage,bp.allowrecommend,bp.needverify FROM " . DB::table('common_block') . ' b' . ' LEFT JOIN ' . DB::table('common_block_permission') . ' bp ON b.bid=bp.bid' . " WHERE bp.uid='{$uid}' AND b.bid IN (" . dimplode($blockfavorite) . ")");
        }
        while ($value = DB::fetch($query)) {
            $value = formatblockvalue($value);
            $value['favorite'] = true;
            $blockfavorite[$value['bid']] = $value;
        }
        $blockfavorite = array_filter($blockfavorite, 'is_array');
    }
    return $blockfavorite;
}