function smarty_block_mtotherblog($args, $content, &$ctx, &$repeat)
 {
     $localvars = array('local_blog_id', 'blog_id', 'blog');
     if (!isset($content)) {
         $blog_id = $args['blog_id'];
         if (!$blog_id) {
             $repeat = false;
             return '';
         }
         $ctx->localize($localvars);
         // do permission checking...
         if ($blog_id) {
             list($attr, $blogs) = multiblog_filter_blogs($ctx, 'include_blogs', array($args['blog_id']));
             if ($attr != 'include_blogs' || !count($blogs) || $blogs[0] != $blog_id) {
                 $repeat = false;
                 $ctx->restore($localvars);
                 return '';
             }
         }
         $blog = $ctx->mt->db->fetch_blog($blog_id);
         $ctx->stash('blog', $blog);
         $ctx->stash('blog_id', $blog_id);
     } else {
         $repeat = false;
     }
     if (!$repeat) {
         $ctx->restore($localvars);
     }
     return $content;
 }
Esempio n. 2
0
function multiblog_filter_blogs_from_args(&$ctx, &$args)
{
    # SANITY CHECK ON ARGUMENTS
    # Set and clean up working variables
    $incl = $args['include_blogs'];
    $incl or $incl = $args['blog_ids'];
    $incl or $incl = $args['blog_id'];
    $excl = $args['exclude_blogs'];
    # Remove spaces
    $incl = preg_replace('/\\s+/', '', $incl);
    $excl = preg_replace('/\\s+/', '', $excl);
    # If there are no multiblog arguments to filter, we don't need to be here
    if (!($incl or $excl)) {
        return true;
    }
    # Only one multiblog argument can be used
    $tagcount = 0;
    $possible_args = array($args['include_blogs'], $args['blog_ids'], $args['blog_id'], $args['exclude_blogs']);
    foreach ($possible_args as $arg) {
        $arg != '' and $tagcount++;
    }
    if ($tagcount > 1) {
        return false;
    }
    # exclude_blogs="all" is not allowed
    if ($excl and $excl == 'all') {
        return false;
    }
    # blog_id attribute only accepts a single blog ID
    if ($args['blog_id'] and !preg_match('/^\\d+$/', $args['blog_id'])) {
        return false;
    }
    # Make sure include_blogs/exclude_blogs is valid
    if (($incl or $excl) != 'all' and !preg_match('/^\\d+([,-]\\d+)*$/', $incl or $excl)) {
        return false;
    }
    # Prepare for filter_blogs
    $blogs = array();
    $attr = $incl ? 'include_blogs' : 'exclude_blogs';
    $val = $incl ? $incl : $excl;
    if (preg_match('/-/', $val)) {
        # parse range blog ids out
        $list = preg_split('/\\s*,\\s*/', $val);
        foreach ($list as $item) {
            if (preg_match('/(\\d+)-(\\d+)/', $item, $matches)) {
                for ($i = $matches[1]; $i <= $matches[2]; $i++) {
                    $blogs[] = $i;
                }
            } else {
                $blogs[] = $item;
            }
        }
    } else {
        $blogs = preg_split('/\\s*,\\s*/', $val);
    }
    # Filter the blogs using the MultiBlog access controls
    list($attr, $blogs) = multiblog_filter_blogs($ctx, $attr, $blogs);
    if (!($attr && count($blogs))) {
        return false;
    }
    # Rewrite the args to the modifed value
    if ($args['blog_ids']) {
        unset($args['blog_ids']);
    }
    // Deprecated
    if ($args['blog_id']) {
        $args['blog_id'] = $blogs[0];
    } else {
        unset($args['include_blogs']);
        unset($args['exclude_blogs']);
        $args[$attr] = implode(',', $blogs);
    }
    return true;
}