~ubuntu-branches/ubuntu/hardy/gallery2/hardy-security

« back to all changes in this revision

Viewing changes to modules/comment/ShowAllComments.inc

  • Committer: Bazaar Package Importer
  • Author(s): Michael C. Schultheiss
  • Date: 2006-04-16 16:42:35 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060416164235-8uy0u4bfjdxpge2o
Tags: 2.1.1-1
* New upstream release (Closes: #362936)
  + Bugfixes for Postgres7 (Closes: #359000, #362152)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/*
 
3
 * $RCSfile: ShowAllComments.inc,v $
 
4
 *
 
5
 * Gallery - a web based photo album viewer and editor
 
6
 * Copyright (C) 2000-2006 Bharat Mediratta
 
7
 *
 
8
 * This program is free software; you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as published by
 
10
 * the Free Software Foundation; either version 2 of the License, or (at
 
11
 * your option) any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful, but
 
14
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
 * General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License
 
19
 * along with this program; if not, write to the Free Software
 
20
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
 
21
 */
 
22
 
 
23
/**
 
24
 * @version $Revision: 1.3 $ $Date: 2006/01/10 04:39:11 $
 
25
 * @package Comment
 
26
 * @subpackage UserInterface
 
27
 * @author Johannes Schmittat <Johannes@Schmittat.com>
 
28
 */
 
29
 
 
30
/**
 
31
 * This view will show all comments stored in the Gallery
 
32
 *
 
33
 * @package Comment
 
34
 * @subpackage UserInterface
 
35
 *
 
36
 */
 
37
class ShowAllCommentsView extends GalleryView {
 
38
 
 
39
    /**
 
40
     * @see GalleryView::loadTemplate
 
41
     */
 
42
    function loadTemplate(&$template, &$form) {
 
43
        GalleryCoreApi::requireOnce('modules/comment/classes/GalleryCommentHelper.class');
 
44
 
 
45
        list ($ret, $item) = $this->_getItem();
 
46
        if ($ret) {
 
47
            return array($ret->wrap(__FILE__, __LINE__), null);
 
48
        }
 
49
        $ret = GalleryCoreApi::assertHasItemPermission($item->getId(), 'comment.view');
 
50
        if ($ret) {
 
51
            return array($ret->wrap(__FILE__, __LINE__), null);
 
52
        }
 
53
 
 
54
        list ($ret, $showCount) =
 
55
            GalleryCoreApi::getPluginParameter('module', 'comment', 'comments.show');
 
56
        if ($ret) {
 
57
            return array($ret->wrap(__FILE__, __LINE__), null);
 
58
        }
 
59
        $page = GalleryUtilities::getRequestVariables('page');
 
60
        if (empty($page)) {
 
61
            $page = 1;
 
62
        }
 
63
 
 
64
        list ($ret, $comments, $count) = GalleryCommentHelper::fetchAllComments(
 
65
            $item->getId(), $showCount, ($page - 1) * $showCount, ORDER_DESCENDING);
 
66
        if ($ret) {
 
67
            return array($ret->wrap(__FILE__, __LINE__), null);
 
68
        }
 
69
 
 
70
        $commenters = $itemIds = $can = $itemData = array();
 
71
        for ($i = 0; $i < count($comments); $i++) {
 
72
            /* Get the commenter ids */
 
73
            $commenters[$comments[$i]->getCommenterId()] = 1;
 
74
            $itemIds[$comments[$i]->getParentId()] = 1;
 
75
 
 
76
            /* Extract the member data */
 
77
            $comments[$i] = (array)$comments[$i];
 
78
        }
 
79
 
 
80
        if (!empty($commenters)) {
 
81
            list ($ret, $commentersList) =
 
82
                GalleryCoreApi::loadEntitiesById(array_keys($commenters));
 
83
            if ($ret) {
 
84
                return array($ret->wrap(__FILE__, __LINE__), null);
 
85
            }
 
86
 
 
87
            foreach ($commentersList as $commenter) {
 
88
                $commenters[$commenter->getId()] = (array)$commenter;
 
89
            }
 
90
        }
 
91
 
 
92
        if (!empty($itemIds)) {
 
93
            $itemIds = array_keys($itemIds);
 
94
            $ret = GalleryCoreApi::studyPermissions($itemIds);
 
95
            if ($ret) {
 
96
                return array($ret->wrap(__FILE__, __LINE__), null);
 
97
            }
 
98
            list ($ret, $itemList) = GalleryCoreApi::loadEntitiesById($itemIds);
 
99
            if ($ret) {
 
100
                return array($ret->wrap(__FILE__, __LINE__), null);
 
101
            }
 
102
            foreach ($itemList as $it) {
 
103
                $items[$it->getId()] = (array)$it;
 
104
            }
 
105
            list ($ret, $thumbnails) = GalleryCoreApi::fetchThumbnailsByItemIds($itemIds);
 
106
            if ($ret) {
 
107
                return array($ret->wrap(__FILE__, __LINE__), null);
 
108
            }
 
109
        }
 
110
 
 
111
        foreach ($comments as $comment) {
 
112
            list ($ret, $permissions) = GalleryCoreApi::getPermissions($comment['parentId']);
 
113
            if ($ret) {
 
114
                return array($ret->wrap(__FILE__, __LINE__), null);
 
115
            }
 
116
            foreach (array('delete' => 'comment.delete',
 
117
                           'edit' => 'comment.edit') as $canFlag => $permission) {
 
118
                $can[$comment['id']][$canFlag] = isset($permissions[$permission]);
 
119
            }
 
120
 
 
121
            if (!isset($itemData[$comment['parentId']])) {
 
122
                $it = $items[$comment['parentId']];
 
123
                if (isset($thumbnails[$comment['parentId']])) {
 
124
                    $it['thumb'] = (array)$thumbnails[$comment['parentId']];
 
125
                }
 
126
                $itemData[$comment['parentId']] = $it;
 
127
            }
 
128
        }
 
129
 
 
130
        $navigator = array('page' => $page, 'pageCount' => ceil($count/$showCount));
 
131
        if ($page > 1) {
 
132
            $navigator['first'] = array('urlParams' => array('view' => 'comment.ShowAllComments',
 
133
                                  'itemId' => $item->getId(), 'page' => 1));
 
134
            $navigator['back'] = array('urlParams' => array('view' => 'comment.ShowAllComments',
 
135
                                 'itemId' => $item->getId(), 'page' => $page - 1));
 
136
        }
 
137
        if ($page < $navigator['pageCount']) {
 
138
            $navigator['next'] = array('urlParams' => array('view' => 'comment.ShowAllComments',
 
139
                                 'itemId' => $item->getId(), 'page' => $page + 1));
 
140
            $navigator['last'] = array('urlParams' => array('view' => 'comment.ShowAllComments',
 
141
                                 'itemId' => $item->getId(), 'page' => $navigator['pageCount']));
 
142
        }
 
143
 
 
144
        $template->setVariable('ShowAllComments', array(
 
145
            'comments' => $comments,
 
146
            'commenters' => $commenters,
 
147
            'can' => $can,
 
148
            'item' => (array)$item,
 
149
            'itemData' => $itemData,
 
150
            'navigator' => $navigator));
 
151
        $template->style('modules/comment/comment.css');
 
152
 
 
153
        return array(null,
 
154
                     array('body' => 'modules/comment/templates/ShowAllComments.tpl'));
 
155
    }
 
156
 
 
157
    /**
 
158
     * @see GalleryView::getViewDescription()
 
159
     */
 
160
    function getViewDescription() {
 
161
        list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'comment');
 
162
        if ($ret) {
 
163
            return array($ret->wrap(__FILE__, __LINE__), null);
 
164
        }
 
165
 
 
166
        return array(null, $module->translate('show comments'));
 
167
    }
 
168
}
 
169
?>