function multiblog_block_wrapper(&$args, $content, &$ctx, &$repeat)
{
    $tag = $ctx->this_tag();
    $localvars = array('entries', 'current_timestamp', 'current_timestamp_end', 'category', 'archive_category', 'local_blog_id');
    if (!isset($content)) {
        $ctx->localize($localvars);
        if (($tag === 'mtblogs' || $tag === 'mtwebsites') && $args['ignore_archive_context']) {
            $ctx->stash('entries', null);
            $ctx->stash('current_timestamp', null);
            $ctx->stash('current_timestamp_end', null);
            $ctx->stash('category', null);
            $ctx->stash('archive_category', null);
        }
        # Set multiblog tag context if applicable
        if ($ctx->stash('multiblog_context')) {
            $incl = $ctx->stash('multiblog_include_blog_ids');
            if (isset($incl)) {
                $args['include_blogs'] = $incl;
            }
            $excl = $ctx->stash('multiblog_exclude_blog_ids');
            if (isset($excl)) {
                $args['exclude_blogs'] = $excl;
            }
        }
        # Load multiblog access control list
        $incl = $args['include_blogs'] || $args['include_websites'] || $args['blog_id'] || $args['blog_ids'] || $tag == 'mtblogs' || $tag == 'mtwebsites';
        $excl = $args['exclude_blogs'] || $args['exclude_websites'];
        if ($incl || $excl) {
            $acl = multiblog_load_acl($ctx);
            if (!empty($acl) && !empty($acl['allow'])) {
                $args['allows'] = $acl['allow'];
            } elseif (!empty($acl) && !empty($acl['deny'])) {
                $args['denies'] = $acl['deny'];
            }
        }
        # Fix for MTMultiBlogIfLocalBlog which should never return
        # true with MTTags block because tags are cross-blog
        if ($ctx->this_tag() == 'mttags') {
            $ctx->stash('local_blog_id', 0);
        }
    }
    # Call original tag handler with new multiblog args
    global $multiblog_orig_handlers;
    $fn = $multiblog_orig_handlers[$tag];
    $result = $fn($args, $content, $ctx, $repeat);
    # Restore localized variables if last loop
    if (!$repeat) {
        $ctx->restore($localvars);
    }
    return $result;
}
Example #2
0
 function multiblog_loop($args, $content, &$ctx, &$repeat)
 {
     $localvars = array('entries', 'current_timestamp', 'current_timestamp_end', 'category', 'archive_category', '_blogs', '_blogs_counter', 'blog', 'blog_id', 'multiblog_context', 'multiblog_blog_ids');
     if (!isset($content)) {
         $ctx->localize($localvars);
         if ($args['ignore_archive_context']) {
             $ctx->stash('entries', null);
             $ctx->stash('current_timestamp', null);
             $ctx->stash('current_timestamp_end', null);
             $ctx->stash('category', null);
             $ctx->stash('archive_category', null);
         }
         # Load multiblog access control list
         $acl = multiblog_load_acl($ctx);
         if (!empty($acl) && !empty($acl['allow'])) {
             $args['allows'] = $acl['allow'];
         } elseif (!empty($acl) && !empty($acl['deny'])) {
             $args['denies'] = $acl['deny'];
         }
         $args['class'] = '*';
         $blogs = $ctx->mt->db()->fetch_blogs($args);
         $ctx->stash('_blogs', $blogs);
         $counter = 0;
     } else {
         $blogs = $ctx->stash('_blogs');
         $counter = $ctx->stash('_blogs_counter');
     }
     if ($counter < count($blogs)) {
         $blog = $blogs[$counter];
         $ctx->stash('blog', $blog);
         $ctx->stash('blog_id', $blog->blog_id);
         $ctx->stash('_blogs_counter', $counter + 1);
         $ctx->stash('multiblog_context', 'include_blogs');
         $ctx->stash('multiblog_blog_ids', $blog->blog_id);
         $repeat = true;
     } else {
         # Restore localized variables once we're
         # finished with all blogs in scope
         $ctx->restore($localvars);
         $repeat = false;
     }
     return $content;
 }