slitaz-forge view forum/themes/slitaz-2/views/discussion/helper_functions.php @ rev 1

Add slitaz themes for vanilla
author Eric Joseph-Alexandre <erjo@slitaz.org>
date Wed Dec 22 10:36:12 2010 +0100 (2010-12-22)
parents
children
line source
1 <?php if (!defined('APPLICATION')) exit();
3 /**
4 * $Object is either a Comment or the original Discussion.
5 */
6 function WriteComment($Object, $Sender, $Session, $CurrentOffset, $counter) {
7 $Author = UserBuilder($Object, 'Insert');
8 $Type = property_exists($Object, 'CommentID') ? 'Comment' : 'Discussion';
9 $Sender->EventArguments['Object'] = $Object;
10 $Sender->EventArguments['Type'] = $Type;
11 $Sender->EventArguments['Author'] = $Author;
12 $CssClass = 'Item Comment ' . $counter;
13 if ($Type == 'Comment') {
14 $Sender->EventArguments['Comment'] = $Object;
15 $Id = 'Comment_'.$Object->CommentID;
16 $Permalink = '/discussion/comment/'.$Object->CommentID.'/#Comment_'.$Object->CommentID;
17 } else {
18 $Sender->EventArguments['Discussion'] = $Object;
19 $CssClass .= ' FirstComment';
20 $Id = 'Discussion_'.$Object->DiscussionID;
21 $Permalink = '/discussion/'.$Object->DiscussionID.'/'.Gdn_Format::Url($Object->Name).'/p1';
22 }
23 $Sender->Options = '';
24 $CssClass .= $Object->InsertUserID == $Session->UserID ? ' Mine' : '';
25 $Sender->FireEvent('BeforeCommentDisplay');
26 ?>
27 <li class="<?php echo $CssClass; ?>" id="<?php echo $Id; ?>">
28 <div class="Comment">
29 <div class="Meta">
30 <?php $Sender->FireEvent('BeforeCommentMeta'); ?>
31 <div class="Author">
32 <?php
33 echo UserPhoto($Author);
34 echo UserAnchor($Author);
35 ?>
36 <div class="clear">&nbsp;</div>
37 </div>
38 <span class="DateCreated">
39 <?php
40 echo Gdn_Format::Date($Object->DateInserted);
41 ?>
42 </span>
43 <span class="Permalink">
44 <?php echo Anchor(T('Permalink'), $Permalink, 'Permalink', array('name' => 'Item_'.($CurrentOffset+1), 'rel' => 'nofollow')); ?>
45 </span>
46 <?php WriteOptionList($Object, $Sender, $Session); ?>
47 <div class="CommentInfo">
48 <?php $Sender->FireEvent('CommentInfo'); ?>
49 </div>
50 <?php $Sender->FireEvent('AfterCommentMeta'); ?>
51 </div>
52 <div class="Message">
53 <?php $Sender->FireEvent('BeforeCommentBody'); ?>
54 <?php
55 $Object->FormatBody = Gdn_Format::To($Object->Body, $Object->Format);
56 $Sender->FireEvent('AfterCommentFormat');
57 $Object = $Sender->EventArguments['Object'];
58 echo $Object->FormatBody;
59 ?>
60 </div><div class="clear">&nbsp;</div>
61 <?php $Sender->FireEvent('AfterCommentBody'); ?>
62 </div>
63 </li>
64 <?php
65 $Sender->FireEvent('AfterComment');
66 }
68 function WriteOptionList($Object, $Sender, $Session) {
69 $EditContentTimeout = C('Garden.EditContentTimeout', -1);
70 $CanEdit = $EditContentTimeout == -1 || strtotime($Object->DateInserted) + $EditContentTimeout > time();
71 $TimeLeft = '';
72 if ($CanEdit && $EditContentTimeout > 0) {
73 $TimeLeft = strtotime($Object->DateInserted) + $EditContentTimeout - time();
74 $TimeLeft = $TimeLeft > 0 ? ' ('.Gdn_Format::Seconds($TimeLeft).')' : '';
75 }
77 $Sender->Options = '';
78 $CategoryID = GetValue('CategoryID', $Object);
79 if(!$CategoryID && property_exists($Sender, 'Discussion'))
80 $CategoryID = GetValue('CategoryID', $Sender->Discussion);
82 // Show discussion options if this is the discussion / first comment
83 if ($Sender->EventArguments['Type'] == 'Discussion') {
84 // Can the user edit the discussion?
85 if (($CanEdit && $Session->UserID == $Object->InsertUserID) || $Session->CheckPermission('Vanilla.Discussions.Edit', TRUE, 'Category', $CategoryID))
86 $Sender->Options .= '<span>'.Anchor(T('Edit'), '/vanilla/post/editdiscussion/'.$Object->DiscussionID, 'EditDiscussion').$TimeLeft.'</span>';
88 // Can the user announce?
89 if ($Session->CheckPermission('Vanilla.Discussions.Announce', TRUE, 'Category', $CategoryID))
90 $Sender->Options .= '<span>'.Anchor(T($Sender->Discussion->Announce == '1' ? 'Unannounce' : 'Announce'), 'vanilla/discussion/announce/'.$Object->DiscussionID.'/'.$Session->TransientKey(), 'AnnounceDiscussion') . '</span>';
92 // Can the user sink?
93 if ($Session->CheckPermission('Vanilla.Discussions.Sink', TRUE, 'Category', $CategoryID))
94 $Sender->Options .= '<span>'.Anchor(T($Sender->Discussion->Sink == '1' ? 'Unsink' : 'Sink'), 'vanilla/discussion/sink/'.$Object->DiscussionID.'/'.$Session->TransientKey().'?Target='.urlencode($Sender->SelfUrl), 'SinkDiscussion') . '</span>';
96 // Can the user close?
97 if ($Session->CheckPermission('Vanilla.Discussions.Close', TRUE, 'Category', $CategoryID))
98 $Sender->Options .= '<span>'.Anchor(T($Sender->Discussion->Closed == '1' ? 'Reopen' : 'Close'), 'vanilla/discussion/close/'.$Object->DiscussionID.'/'.$Session->TransientKey().'?Target='.urlencode($Sender->SelfUrl), 'CloseDiscussion') . '</span>';
100 // Can the user delete?
101 if ($Session->CheckPermission('Vanilla.Discussions.Delete', TRUE, 'Category', $CategoryID))
102 $Sender->Options .= '<span>'.Anchor(T('Delete Discussion'), 'vanilla/discussion/delete/'.$Object->DiscussionID.'/'.$Session->TransientKey(), 'DeleteDiscussion') . '</span>';
103 } else {
104 // And if this is just another comment in the discussion ...
106 // Can the user edit the comment?
107 if (($CanEdit && $Session->UserID == $Object->InsertUserID) || $Session->CheckPermission('Vanilla.Comments.Edit', TRUE, 'Category', $Sender->Discussion->CategoryID))
108 $Sender->Options .= '<span>'.Anchor(T('Edit'), '/vanilla/post/editcomment/'.$Object->CommentID, 'EditComment').$TimeLeft.'</span>';
110 // Can the user delete the comment?
111 if ($Session->CheckPermission('Vanilla.Comments.Delete', TRUE, 'Category', $CategoryID))
112 $Sender->Options .= '<span>'.Anchor(T('Delete'), 'vanilla/discussion/deletecomment/'.$Object->CommentID.'/'.$Session->TransientKey().'/?Target='.urlencode($Sender->SelfUrl), 'DeleteComment') . '</span>';
113 }
115 // Allow plugins to add options
116 $Sender->FireEvent('CommentOptions');
117 echo $Sender->Options;