root/branches/release-38/php/lib/block.mtcomments.php @ 2378

Revision 2378, 2.7 kB (checked in by bchoate, 19 months ago)

Applying fix for BugId:79781

  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2# Movable Type (r) Open Source (C) 2001-2008 Six Apart, Ltd.
3# This program is distributed under the terms of the
4# GNU General Public License, version 2.
5#
6# $Id$
7
8function smarty_block_mtcomments($args, $content, &$ctx, &$repeat) {
9    $localvars = array('comments', 'comment_order_num','comment','current_timestamp', 'commenter', 'blog', 'blog_id', 'conditional', 'else_content');
10    if (!isset($content)) {
11        $ctx->localize($localvars);
12        $entry = $ctx->stash('entry');
13        if ($entry)
14            $args['entry_id'] = $entry['entry_id'];
15        $blog = $ctx->stash('blog');
16        if ($blog)
17            $args['blog_id'] = $blog['blog_id'];
18        $comments = $ctx->mt->db->fetch_comments($args);
19        $ctx->stash('comments', $comments);
20        $counter = 0;
21    } else {
22        $comments = $ctx->stash('comments');
23        $counter = $ctx->stash('comment_order_num');
24    }
25
26    if (empty($comments)) {
27        $ret = $ctx->_hdlr_if($args, $content, $ctx, $repeat, 0);
28        if (!$repeat)
29              $ctx->restore($localvars);
30        return $ret;
31    }
32
33    $ctx->stash('conditional', empty($comments) ? 0 : 1);
34    if ($counter < count($comments)) {
35        $blog_id = $ctx->stash('blog_id');
36        $comment = $comments[$counter];
37        if ($comment['comment_commenter_id']) {
38            $commenter = $ctx->mt->db->fetch_author($comment['comment_commenter_id']);
39            $permission = $ctx->mt->db->fetch_permission(array('blog_id' => $comment['comment_blog_id'], 'id' => $comment['comment_commenter_id']));
40            if ( isset($permission) && count($permission) > 0 ) {
41                $commenter = array($commenter);
42                $commenter = array_merge($commenter, $permission[0]);
43            }
44            $ctx->stash('commenter', $commenter);
45        } else {
46            $ctx->__stash['commenter'] = null;
47        }
48        if ($blog_id != $comment['comment_blog_id']) {
49            $blog_id = $comment['comment_blog_id'];
50            $ctx->stash('blog_id', $blog_id);
51            $ctx->stash('blog', $ctx->mt->db->fetch_blog($blog_id));
52        }
53        $ctx->stash('comment', $comment);
54        $ctx->stash('current_timestamp', $comment['comment_created_on']);
55        $ctx->stash('comment_order_num', $counter + 1);
56        $repeat = true;
57        $count = $counter + 1;
58        $ctx->__stash['vars']['__counter__'] = $count;
59        $ctx->__stash['vars']['__odd__'] = ($count % 2) == 1;
60        $ctx->__stash['vars']['__even__'] = ($count % 2) == 0;
61        $ctx->__stash['vars']['__first__'] = $count == 1;
62        $ctx->__stash['vars']['__last__'] = ($count == count($comments));
63    } else {
64        $ctx->restore($localvars);
65        $repeat = false;
66    }
67    return $content;
68}
69?>
Note: See TracBrowser for help on using the browser.