slitaz-forge diff forum/vanilla/themes/slitaz/views/discussion/helper_functions.php @ rev 2

move vanilla-config & themes in vanilla directory
author Eric Joseph-Alexandre <erjo@slitaz.org>
date Wed Dec 22 10:41:18 2010 +0100 (2010-12-22)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/forum/vanilla/themes/slitaz/views/discussion/helper_functions.php	Wed Dec 22 10:41:18 2010 +0100
     1.3 @@ -0,0 +1,118 @@
     1.4 +<?php if (!defined('APPLICATION')) exit();
     1.5 +
     1.6 +/**
     1.7 + * $Object is either a Comment or the original Discussion.
     1.8 + */
     1.9 +function WriteComment($Object, $Sender, $Session, $CurrentOffset, $counter) {
    1.10 +   $Author = UserBuilder($Object, 'Insert');
    1.11 +   $Type = property_exists($Object, 'CommentID') ? 'Comment' : 'Discussion';
    1.12 +	$Sender->EventArguments['Object'] = $Object;
    1.13 +   $Sender->EventArguments['Type'] = $Type;
    1.14 +   $Sender->EventArguments['Author'] = $Author;
    1.15 +   $CssClass = 'Item Comment ' . $counter;
    1.16 +   if ($Type == 'Comment') {
    1.17 +      $Sender->EventArguments['Comment'] = $Object;   
    1.18 +      $Id = 'Comment_'.$Object->CommentID;
    1.19 +      $Permalink = '/discussion/comment/'.$Object->CommentID.'/#Comment_'.$Object->CommentID;
    1.20 +   } else {
    1.21 +      $Sender->EventArguments['Discussion'] = $Object;   
    1.22 +      $CssClass .= ' FirstComment';
    1.23 +      $Id = 'Discussion_'.$Object->DiscussionID;
    1.24 +      $Permalink = '/discussion/'.$Object->DiscussionID.'/'.Gdn_Format::Url($Object->Name).'/p1';
    1.25 +   }
    1.26 +   $Sender->Options = '';
    1.27 +   $CssClass .= $Object->InsertUserID == $Session->UserID ? ' Mine' : '';
    1.28 +   $Sender->FireEvent('BeforeCommentDisplay');
    1.29 +?>
    1.30 +<li class="<?php echo $CssClass; ?>" id="<?php echo $Id; ?>">
    1.31 +   <div class="Comment">
    1.32 +      <div class="Meta">
    1.33 +         <?php $Sender->FireEvent('BeforeCommentMeta'); ?>
    1.34 +         <div class="Author">
    1.35 +            <?php
    1.36 +            echo UserPhoto($Author);
    1.37 +            echo UserAnchor($Author);
    1.38 +            ?>
    1.39 +			<div class="clear">&nbsp;</div>
    1.40 +         </div>
    1.41 +         <span class="DateCreated">
    1.42 +            <?php
    1.43 +            echo Gdn_Format::Date($Object->DateInserted);
    1.44 +            ?>
    1.45 +         </span>
    1.46 +         <span class="Permalink">
    1.47 +            <?php echo Anchor(T('Permalink'), $Permalink, 'Permalink', array('name' => 'Item_'.($CurrentOffset+1), 'rel' => 'nofollow')); ?>
    1.48 +         </span>
    1.49 +         <?php WriteOptionList($Object, $Sender, $Session); ?>
    1.50 +         <div class="CommentInfo">
    1.51 +            <?php $Sender->FireEvent('CommentInfo'); ?>
    1.52 +         </div>
    1.53 +         <?php $Sender->FireEvent('AfterCommentMeta'); ?>
    1.54 +      </div>
    1.55 +      <div class="Message">
    1.56 +			<?php $Sender->FireEvent('BeforeCommentBody'); ?>
    1.57 +			<?php 
    1.58 +			   $Object->FormatBody = Gdn_Format::To($Object->Body, $Object->Format);
    1.59 +			   $Sender->FireEvent('AfterCommentFormat');
    1.60 +			   $Object = $Sender->EventArguments['Object'];
    1.61 +			   echo $Object->FormatBody;
    1.62 +			?>
    1.63 +		</div><div class="clear">&nbsp;</div>
    1.64 +      <?php $Sender->FireEvent('AfterCommentBody'); ?>
    1.65 +   </div>
    1.66 +</li>
    1.67 +<?php
    1.68 +	$Sender->FireEvent('AfterComment');
    1.69 +}
    1.70 +
    1.71 +function WriteOptionList($Object, $Sender, $Session) {
    1.72 +   $EditContentTimeout = C('Garden.EditContentTimeout', -1);
    1.73 +	$CanEdit = $EditContentTimeout == -1 || strtotime($Object->DateInserted) + $EditContentTimeout > time();
    1.74 +	$TimeLeft = '';
    1.75 +	if ($CanEdit && $EditContentTimeout > 0) {
    1.76 +		$TimeLeft = strtotime($Object->DateInserted) + $EditContentTimeout - time();
    1.77 +		$TimeLeft = $TimeLeft > 0 ? ' ('.Gdn_Format::Seconds($TimeLeft).')' : '';
    1.78 +	}
    1.79 +
    1.80 +   $Sender->Options = '';
    1.81 +	$CategoryID = GetValue('CategoryID', $Object);
    1.82 +	if(!$CategoryID && property_exists($Sender, 'Discussion'))
    1.83 +		$CategoryID = GetValue('CategoryID', $Sender->Discussion);
    1.84 +		
    1.85 +   // Show discussion options if this is the discussion / first comment
    1.86 +   if ($Sender->EventArguments['Type'] == 'Discussion') {
    1.87 +      // Can the user edit the discussion?
    1.88 +      if (($CanEdit && $Session->UserID == $Object->InsertUserID) || $Session->CheckPermission('Vanilla.Discussions.Edit', TRUE, 'Category', $CategoryID))
    1.89 +         $Sender->Options .= '<span>'.Anchor(T('Edit'), '/vanilla/post/editdiscussion/'.$Object->DiscussionID, 'EditDiscussion').$TimeLeft.'</span>';
    1.90 +         
    1.91 +      // Can the user announce?
    1.92 +      if ($Session->CheckPermission('Vanilla.Discussions.Announce', TRUE, 'Category', $CategoryID))
    1.93 +         $Sender->Options .= '<span>'.Anchor(T($Sender->Discussion->Announce == '1' ? 'Unannounce' : 'Announce'), 'vanilla/discussion/announce/'.$Object->DiscussionID.'/'.$Session->TransientKey(), 'AnnounceDiscussion') . '</span>';
    1.94 +
    1.95 +      // Can the user sink?
    1.96 +      if ($Session->CheckPermission('Vanilla.Discussions.Sink', TRUE, 'Category', $CategoryID))
    1.97 +         $Sender->Options .= '<span>'.Anchor(T($Sender->Discussion->Sink == '1' ? 'Unsink' : 'Sink'), 'vanilla/discussion/sink/'.$Object->DiscussionID.'/'.$Session->TransientKey().'?Target='.urlencode($Sender->SelfUrl), 'SinkDiscussion') . '</span>';
    1.98 +
    1.99 +      // Can the user close?
   1.100 +      if ($Session->CheckPermission('Vanilla.Discussions.Close', TRUE, 'Category', $CategoryID))
   1.101 +         $Sender->Options .= '<span>'.Anchor(T($Sender->Discussion->Closed == '1' ? 'Reopen' : 'Close'), 'vanilla/discussion/close/'.$Object->DiscussionID.'/'.$Session->TransientKey().'?Target='.urlencode($Sender->SelfUrl), 'CloseDiscussion') . '</span>';
   1.102 +      
   1.103 +      // Can the user delete?
   1.104 +      if ($Session->CheckPermission('Vanilla.Discussions.Delete', TRUE, 'Category', $CategoryID))
   1.105 +         $Sender->Options .= '<span>'.Anchor(T('Delete Discussion'), 'vanilla/discussion/delete/'.$Object->DiscussionID.'/'.$Session->TransientKey(), 'DeleteDiscussion') . '</span>';
   1.106 +   } else {
   1.107 +      // And if this is just another comment in the discussion ...
   1.108 +      
   1.109 +      // Can the user edit the comment?
   1.110 +      if (($CanEdit && $Session->UserID == $Object->InsertUserID) || $Session->CheckPermission('Vanilla.Comments.Edit', TRUE, 'Category', $Sender->Discussion->CategoryID))
   1.111 +         $Sender->Options .= '<span>'.Anchor(T('Edit'), '/vanilla/post/editcomment/'.$Object->CommentID, 'EditComment').$TimeLeft.'</span>';
   1.112 +
   1.113 +      // Can the user delete the comment?
   1.114 +      if ($Session->CheckPermission('Vanilla.Comments.Delete', TRUE, 'Category', $CategoryID))
   1.115 +         $Sender->Options .= '<span>'.Anchor(T('Delete'), 'vanilla/discussion/deletecomment/'.$Object->CommentID.'/'.$Session->TransientKey().'/?Target='.urlencode($Sender->SelfUrl), 'DeleteComment') . '</span>';
   1.116 +   }
   1.117 +   
   1.118 +   // Allow plugins to add options
   1.119 +   $Sender->FireEvent('CommentOptions');
   1.120 +   echo $Sender->Options;
   1.121 +}
   1.122 \ No newline at end of file