root/trunk/handlers/show/show.php

Revision 1619, 11.8 KB (checked in by MasinAlDujaili, 7 months ago)

results of merging trunk and 1.3, mostly cosmetic changes, usage of core functions, singlequotes instead of doublequotes, matching language string constants and so on

  • Property svn:keywords set to Id
Line 
1<?php
2/**
3 * Display a page if the user has read access or is an admin.
4 *
5 * This is the default page handler used by Wikka when no other handler is specified.
6 * Depending on user privileges, it displays the page body or an error message. It also
7 * displays footer comments and a form to post comments, depending on ACL and general
8 * config settings.
9 *
10 * @package             Handlers
11 * @subpackage  Page
12 * @version             $Id$
13 * @license             http://www.gnu.org/copyleft/gpl.html GNU General Public License
14 * @filesource
15 *
16 * @uses                Config::$anony_delete_own_comments
17 * @uses                Config::$hide_comments
18 * @uses                Wakka::Format()
19 * @uses                Wakka::FormClose()
20 * @uses                Wakka::FormOpen()
21 * @uses                Wakka::GetConfigValue()
22 * @uses                Wakka::GetPageTag()
23 * @uses                Wakka::GetUser()
24 * @uses                Wakka::GetUserName()
25 * @uses                Wakka::HasAccess()
26 * @uses                Wakka::Href()
27 * @uses                Wakka::htmlspecialchars_ent()
28 * @uses                Wakka::LoadComments()
29 * @uses                Wakka::LoadPage()
30 * @uses                Wakka::FormatUser()
31 * @uses                Wakka::UserIsOwner()
32 *
33 */
34
35//constants
36define('SHOW_OLD_REVISION_SOURCE', 0); # if set to 1 shows by default the source of an old revision instead of the rendered version
37
38//validate URL parameters
39$raw = (!empty($_GET['raw']))? (int) $this->GetSafeVar('raw', 'get') : SHOW_OLD_REVISION_SOURCE;
40
41echo "\n".'<!--starting page content-->'."\n";
42echo '<div class="page"';
43echo (($user = $this->GetUser()) && ($user['doubleclickedit'] == 'N') || !$this->HasAccess('write')) ? '' : ' ondblclick="document.location=\''.$this->Href('edit', '', 'id='.$this->page['id']).'\';" '; #268
44echo '>'."\n";
45
46if (!$this->HasAccess('read'))
47{
48        echo '<p><em class="error">'.WIKKA_ERROR_ACL_READ.'</em></p>';
49        echo "\n".'</div><!--closing page content-->'."\n";
50}
51else
52{
53        if (!$this->page)
54        {
55                $createlink = '<a href="'.$this->Href('edit').'">'.WIKKA_PAGE_CREATE_LINK_DESC.'</a>';
56                echo '<p>'.sprintf(SHOW_ASK_CREATE_PAGE_CAPTION,$createlink).'</p>'."\n";
57                echo '</div><!--closing page content-->'."\n";
58        }
59        else
60        {
61                if ($this->page['latest'] == 'N')
62                {
63                        $pagelink = '<a href="'.$this->Href().'">'.$this->tag.'</a>';
64                        echo '<div class="revisioninfo">'."\n";
65                        echo '<h4 class="clear">'.sprintf(WIKKA_REVISION_NUMBER, '<a href="'.$this->Href('', '', 'time='.urlencode($this->page['time'])).'">['.$this->page['id'].']</a>').'</h4>'."\n";
66                        echo '<p>';
67                        echo sprintf(SHOW_OLD_REVISION_CAPTION, $pagelink, $this->FormatUser($this->page['user']), $this->Link($this->tag, 'revisions', $this->page['time'], TRUE, TRUE, '', 'datetime'));
68                       
69                        // added if encapsulation: in case where some pages were brutally deleted from database
70                        if ($latest = $this->LoadPage($this->tag))
71                        {
72?>
73                                <br />
74                                <?php echo $this->FormOpen('show', '', 'GET', '', 'left') ?>
75                                <input type="hidden" name="time" value="<?php echo $this->GetSafeVar('time', 'get') ?>" />
76                                <input type="hidden" name="raw" value="<?php echo ($raw == 1)? '0' :'1' ?>" />
77                                <input type="submit" value="<?php echo ($raw == 1)? SHOW_FORMATTED_BUTTON : SHOW_SOURCE_BUTTON ?>" />&nbsp;
78                                <?php echo $this->FormClose(); ?>
79<?php
80                                // if this is an editable revision, display form
81                                if ($this->HasAccess('write'))
82                                {
83?>
84                                        <?php echo $this->FormOpen('edit') ?>
85                                        <input type="hidden" name="previous" value="<?php echo $latest['id'] ?>" />
86                                        <input type="hidden" name="body" value="<?php echo $this->htmlspecialchars_ent($this->page['body']) ?>" />
87                                        <input type="submit" name="submit" value="<?php echo SHOW_RE_EDIT_BUTTON ?>" />
88                                        <?php echo $this->FormClose(); ?>
89<?php
90                                }
91                        }
92                        echo '</p><div class="clear"></div></div>';
93                }
94
95                // display page
96                if ($raw == 1)
97                {
98                        echo '<div class="wikisource">'.nl2br($this->htmlspecialchars_ent($this->page["body"], ENT_QUOTES)).'</div>';
99                }
100                else
101                {
102                        echo $this->Format($this->page['body'], 'wakka', 'page');
103                }
104                //clear floats at the end of the main div
105                echo "\n".'<div style="clear: both"></div>'."\n";
106                echo "\n".'</div><!--closing page content-->'."\n\n";
107
108                if ($this->GetConfigValue('hide_comments') != 1 &&
109                        $this->HasAccess('comment_read')
110                   )
111                {
112                        echo '<!-- starting comments block-->'."\n";
113                        echo '<div id="comments">'."\n";
114                        // store comments display in session
115                        $tag = $this->GetPageTag();
116                        $wantComments = $this->UserWantsComments($tag);
117                        if (!isset($_SESSION['show_comments'][$tag]) && $wantComments !== FALSE)
118                        {
119                                $_SESSION['show_comments'][$tag] = $wantComments;
120                        }
121
122                        // A GET comment style always overrides the SESSION comment style
123                        if (isset($_GET['show_comments']))
124                        {
125                                switch($this->GetSafeVar('show_comments', 'get'))
126                                {
127                                        case COMMENT_NO_DISPLAY:
128                                                $_SESSION['show_comments'][$tag] = COMMENT_NO_DISPLAY;
129                                                break;
130                                        case COMMENT_ORDER_DATE_ASC:
131                                                $_SESSION['show_comments'][$tag] = COMMENT_ORDER_DATE_ASC;
132                                                break;
133                                        case COMMENT_ORDER_DATE_DESC: 
134                                                $_SESSION['show_comments'][$tag] = COMMENT_ORDER_DATE_DESC;
135                                                break;
136                                        case COMMENT_ORDER_THREADED:
137                                                $_SESSION['show_comments'][$tag] = COMMENT_ORDER_THREADED;
138                                                break;
139                                }
140                        }
141
142                        // display comments!
143                        if (isset($_SESSION['show_comments'][$tag]) && $_SESSION['show_comments'][$tag] != COMMENT_NO_DISPLAY)
144                        {
145                                // load comments for this page
146                                $comments = $this->LoadComments($this->tag, $_SESSION['show_comments'][$tag]);
147                                $display_mode = $_SESSION['show_comments'][$tag];
148                                // set up icons
149                                $sort_desc_icon_url = $this->StaticHref('images/icons/sort_desc.gif');
150                                $sort_asc_icon_url = $this->StaticHref('images/icons/sort_asc.gif');
151                                $sort_comment_icon_url = $this->StaticHref('images/icons/comment.gif');
152
153
154                                // display comments header
155?>
156                                <!--starting comments header (show)-->
157                                <div class="commentsheader">
158                                        <div id="commentsnav">
159                                                <a href="<?php echo $this->Href('', '', 'show_comments='.COMMENT_ORDER_DATE_DESC.'#comments') ?>"><?php echo '<img class="'.($display_mode==COMMENT_ORDER_DATE_DESC ?  "icon_on" : "icon").'" alt="flat" title="Flat (newest first)" src="'.$sort_desc_icon_url.'" />' ?></a>
160                                                <a href="<?php echo $this->Href('', '', 'show_comments='.COMMENT_ORDER_DATE_ASC.'#comments') ?>"><?php echo '<img class="'.($display_mode==COMMENT_ORDER_DATE_ASC ?  "icon_on" : "icon").'" alt="flat" title="Flat (oldest first)" src="'.$sort_asc_icon_url.'" />' ?></a>
161                                                <a href="<?php echo $this->Href('', '', 'show_comments='.COMMENT_ORDER_THREADED.'#comments') ?>"><?php echo '<img class="'.($display_mode==COMMENT_ORDER_THREADED ?  "icon_on" : "icon").'" alt="threaded" title="Threaded" src="'.$sort_comment_icon_url.'" />' ?></a>
162                                        </div><!-- closing commentsnav div -->
163                                <?php echo COMMENTS_CAPTION ?>
164                                [<a href="<?php echo $this->Href('', '', 'show_comments='.COMMENT_NO_DISPLAY) ?>"><?php echo HIDE_COMMENTS_LINK_DESC ?></a>]
165<?php
166                        if ($this->HasAccess('comment_post'))
167                        {
168?>
169                                <?php echo $this->FormOpen('processcomment') ?>
170                                <input type="submit" name="submit" value="<?php echo COMMENT_NEW_BUTTON ?>" />
171                                <?php echo $this->FormClose() ?>
172<?php
173                        }
174?>
175                                </div><!--closing commentsheader (show)-->
176
177<?php
178                                // display comments themselves
179                                if ($comments)
180                                {
181                                        displayComments($this, $comments, $tag);
182                                }
183                        }
184                        else
185                        {
186
187                                echo '<!--starting comments header (hide)-->'."\n";
188                                echo '<div class="commentsheader">'."\n";
189                                $commentCount = $this->CountComments($this->tag);
190                                $showcomments_text = '';
191
192                                // Determine comment ordering preference
193                                $comment_ordering = NULL;
194                                if (isset($user['default_comment_display']))
195                                {
196                                        $comment_ordering = $user['default_comment_display'];
197                                }
198                                elseif (NULL !== $this->GetConfigValue('default_comment_display'))
199                                {
200                                        $comment_ordering = $this->GetConfigValue('default_comment_display');
201                                }
202
203                                // Convert from DB enum to PHP enum
204                                switch($comment_ordering)
205                                {
206                                        case 'date_asc':
207                                                $comment_ordering = COMMENT_ORDER_DATE_ASC;
208                                                break;
209                                        case 'date_desc':
210                                                $comment_ordering = COMMENT_ORDER_DATE_DESC;
211                                                break;
212                                        case 'threaded':
213                                        default:
214                                                $comment_ordering = COMMENT_ORDER_THREADED;
215                                                break;
216                                }                                                                                               
217
218                                switch ($commentCount)
219                                {
220                                        case 0:
221                                                $comments_message = STATUS_NO_COMMENTS.' ';
222                                                if ($this->HasAccess('comment_post'))
223                                                {
224                                                        $showcomments_text  = $this->FormOpen("processcomment");
225                                                        $showcomments_text .= '<input type="submit" name="submit" value="'.COMMENT_NEW_BUTTON.'" />';
226                                                        $showcomments_text .= $this->FormClose();
227                                                }
228                                                break;
229                                        case 1:
230                                                $comments_message = STATUS_ONE_COMMENT.' ';
231                                                $showcomments_text = '[<a href="'.$this->Href('', '', 'show_comments='.$comment_ordering.'#comments').'">'.DISPLAY_COMMENT_LINK_DESC.'</a>]';
232                                                break;
233                                        default:
234                                                $comments_message = sprintf(STATUS_SOME_COMMENTS, $commentCount).' ';
235
236                                                $showcomments_text = '[<a href="'.$this->Href('', '', 'show_comments='.$comment_ordering.'#comments').'">'.DISPLAY_COMMENTS_LABEL.'</a>]';
237                                }
238
239                                echo $comments_message;
240                                echo $showcomments_text;
241                                echo "\n".'</div><!--closing commentsheader (hide)-->'."\n";
242                        }
243                        echo '</div><!--closing comments block-->'."\n\n";
244                }
245        }
246}
247
248/**
249 * Display comments for ...
250 *
251 * @uses        Wakka::reg_username
252 * @uses        Wakka::GetUserName()
253 * @uses        Wakka::UserIsOwner()
254 * @uses        Wakka::FormatUser()
255 *
256 * @todo        document (including short description!
257 */
258function displayComments(&$obj, &$comments, $tag)
259{
260        $current_user = $obj->GetUserName();
261        $is_owner = $obj->UserIsOwner();
262        $prev_level = NULL;
263        $threaded = 0;
264        if ($_SESSION['show_comments'][$tag] == COMMENT_ORDER_THREADED)
265        {
266                $threaded = 1;
267        }
268
269        ?>
270        <div class="commentscontainer">
271        <?php
272        foreach ($comments as $comment)
273        {
274                # Handle legacy or non-threaded comments
275                if (!isset($comment['level']) || !$threaded)
276                {
277                        $comment['level'] = 0;
278                }
279
280                # Keep track of closing <div> tags to effect nesting
281                if (isset($prev_level) && ($comment['level'] <= $prev_level))
282                {
283                        for ($i=0; $i<$prev_level-$comment['level']+1; ++$i)
284                        {
285                                echo '</div><!--closing comment level '.$i.'-->'."\n";
286                        }
287                }
288
289                # Alternate light/dark comment styles per level
290                $comment_class = '';
291                if ($comment['level'] % 2 == 1)
292                {
293                        $comment_class = "comment-layout-1";
294                }
295                else
296                {
297                        $comment_class = "comment-layout-2";
298                }
299
300                if ($comment['status'] == 'deleted') {
301?>
302        <div class="<?php echo $comment_class ?>">
303                <div class="commentdeleted"><?php echo COMMENT_DELETED_LABEL ?></div>
304<?php
305                }
306                else
307                {
308                        # Some stats
309                        //$comment_author = $obj->LoadUser($comment['user'])? $obj->Format($comment['user']) : $comment['user'];
310                        $comment_author = $obj->FormatUser($comment['user']);
311                        $comment_ts = sprintf(COMMENT_TIME_CAPTION,$comment['time']);
312?>
313        <div id="comment_<?php echo $comment['id'] ?>" class="<?php echo $comment_class ?>" >
314                <div class="commentheader">
315                <div class="commentauthor"><?php echo COMMENT_BY_LABEL.$comment_author ?></div>
316                <div class="commentinfo"><?php echo $comment_ts ?></div>
317                </div>
318                <div class="commentbody">
319                <?php echo $comment['comment'] ?>
320                </div>
321<?php
322                        if ($obj->HasAccess('comment_post'))
323                        {
324                                echo '<div class="commentaction">';
325                                echo $obj->FormOpen("processcomment");
326?>
327                <input type="hidden" name="comment_id" value="<?php echo $comment['id'] ?>" />
328<?php
329?>
330                <input type="submit" name="submit" value="<?php echo COMMENT_REPLY_BUTTON ?>" />
331<?php
332                                /*
333                                $user = $obj->GetUser();
334                                if (isset($user))
335                                {
336                                        $name = $user['name'];
337                                }
338                                */
339                                #if ($is_owner || $name == $comment['user'] || ($obj->config['anony_delete_own_comments'] && $current_user == $comment['user']))
340                                if ($is_owner || $obj->reg_username == $comment['user'] || ($obj->config['anony_delete_own_comments'] && $current_user == $comment['user']))
341                                {
342?>
343                <input type="submit" name="submit" value="<?php echo COMMENT_DELETE_BUTTON ?>" />
344<?php
345                                }
346                                echo $obj->FormClose();
347                                echo "</div>";
348                        }
349                }
350                $prev_level = $comment['level'];
351        }
352        for ($i=0; $i<$prev_level+1; ++$i)
353        {
354                print '</div><!--closing comment level (end)-->'."\n";
355        }
356        ?>
357        </div>
358        <?php
359}
360?>
Note: See TracBrowser for help on using the browser.