Beispiel #1
0
 public function Index($Offset = 0, $Limit = NULL)
 {
     $this->AddJsFile('/js/library/jquery.gardenmorepager.js');
     $this->AddJsFile('search.js');
     $this->Title(Translate('Search'));
     if (!is_numeric($Limit)) {
         $Limit = Gdn::Config('Garden.Search.PerPage', 20);
     }
     $Search = $this->Form->GetFormValue('Search');
     $ResultSet = $this->SearchModel->Search($Search, $Offset, $Limit);
     $this->SetData('SearchResults', $ResultSet, TRUE);
     $this->SetData('SearchTerm', Format::Text($Search), TRUE);
     $NumResults = $ResultSet->NumRows();
     if ($NumResults == $Offset + $Limit) {
         $NumResults++;
     }
     // Build a pager
     $PagerFactory = new PagerFactory();
     $Pager = $PagerFactory->GetPager('MorePager', $this);
     $Pager->MoreCode = 'More Results';
     $Pager->LessCode = 'Previous Results';
     $Pager->ClientID = 'Pager';
     $Pager->Configure($Offset, $Limit, $NumResults, 'garden/search/%1$s/%2$s/?Search=' . Format::Url($Search));
     $this->SetData('Pager', $Pager, TRUE);
     $this->View = 'results';
     $this->Render();
 }
Beispiel #2
0
 /**
  * Create a comment.
  *
  * @param int The DiscussionID to add the comment to. If blank, this method will throw an error.
  */
 public function Comment($DiscussionID = '')
 {
     $this->AddJsFile('js/library/jquery.autogrow.js');
     $this->AddJsFile('post.js');
     $this->AddJsFile('autosave.js');
     $Session = Gdn::Session();
     $this->Form->SetModel($this->CommentModel);
     $CommentID = isset($this->Comment) && property_exists($this->Comment, 'CommentID') ? $this->Comment->CommentID : '';
     $DraftID = isset($this->Comment) && property_exists($this->Comment, 'DraftID') ? $this->Comment->DraftID : '';
     $this->EventArguments['CommentID'] = $CommentID;
     $Editing = $CommentID > 0 || $DraftID > 0;
     $this->EventArguments['Editing'] = $Editing;
     $DiscussionID = is_numeric($DiscussionID) ? $DiscussionID : $this->Form->GetFormValue('DiscussionID', 0);
     $this->Form->AddHidden('DiscussionID', $DiscussionID);
     $this->Form->AddHidden('CommentID', $CommentID);
     $this->Form->AddHidden('DraftID', $DraftID, TRUE);
     $this->DiscussionID = $DiscussionID;
     $Discussion = $this->DiscussionModel->GetID($DiscussionID);
     if ($Editing) {
         if ($this->Comment->InsertUserID != $Session->UserID) {
             $this->Permission('Vanilla.Comments.Edit', $Discussion->CategoryID);
         }
     } else {
         $this->Permission('Vanilla.Comments.Add', $Discussion->CategoryID);
     }
     if ($this->Form->AuthenticatedPostBack() === FALSE) {
         if (isset($this->Comment)) {
             $this->Form->SetData($this->Comment);
         }
     } else {
         // Save as a draft?
         $FormValues = $this->Form->FormValues();
         if ($DraftID == 0) {
             $DraftID = $this->Form->GetFormValue('DraftID', 0);
         }
         $Draft = $this->Form->ButtonExists('Save Draft') ? TRUE : FALSE;
         $this->EventArguments['Draft'] = $Draft;
         $Preview = $this->Form->ButtonExists('Preview') ? TRUE : FALSE;
         if ($Draft) {
             $DraftID = $this->DraftModel->Save($FormValues);
             $this->Form->AddHidden('DraftID', $DraftID, TRUE);
             $this->Form->SetValidationResults($this->DraftModel->ValidationResults());
         } else {
             if (!$Preview) {
                 $CommentID = $this->CommentModel->Save($FormValues);
                 $this->Form->SetValidationResults($this->CommentModel->ValidationResults());
                 if ($CommentID > 0 && $DraftID > 0) {
                     $this->DraftModel->Delete($DraftID);
                 }
             }
         }
         // Handle non-ajax requests first:
         if ($this->_DeliveryType == DELIVERY_TYPE_ALL) {
             if ($this->Form->ErrorCount() == 0) {
                 // Make sure that this form knows what comment we are editing.
                 if ($CommentID > 0) {
                     $this->Form->AddHidden('CommentID', $CommentID);
                 }
                 // If the comment was not a draft
                 if (!$Draft) {
                     // Redirect redirect to the new comment
                     $Discussion = $this->DiscussionModel->GetID($DiscussionID);
                     Redirect('/vanilla/discussion/' . $DiscussionID . '/' . Format::Url($Discussion->Name) . '/#Comment_' . $CommentID);
                 } elseif ($Preview) {
                     // If this was a preview click, create a comment shell with the values for this comment
                     $this->Comment = new stdClass();
                     $this->Comment->InsertUserID = $Session->User->UserID;
                     $this->Comment->InsertName = $Session->User->Name;
                     $this->Comment->InsertPhoto = $Session->User->Photo;
                     $this->Comment->DateInserted = Format::Date();
                     $this->Comment->Body = ArrayValue('Body', $FormValues, '');
                     $this->AddAsset('Content', $this->FetchView('preview'));
                 } else {
                     // If this was a draft save, notify the user about the save
                     $this->StatusMessage = sprintf(Gdn::Translate('Draft saved at %s'), Format::Date());
                 }
             }
         } else {
             // Handle ajax-based requests
             if ($this->Form->ErrorCount() > 0) {
                 // Return the form errors
                 $this->StatusMessage = $this->Form->Errors();
             } else {
                 // Make sure that the ajax request form knows about the newly created comment or draft id
                 $this->SetJson('CommentID', $CommentID);
                 $this->SetJson('DraftID', $DraftID);
                 if ($Preview) {
                     // If this was a preview click, create a comment shell with the values for this comment
                     $this->Comment = new stdClass();
                     $this->Comment->InsertUserID = $Session->User->UserID;
                     $this->Comment->InsertName = $Session->User->Name;
                     $this->Comment->InsertPhoto = $Session->User->Photo;
                     $this->Comment->DateInserted = Format::Date();
                     $this->Comment->Body = ArrayValue('Body', $FormValues, '');
                     $this->View = 'preview';
                 } elseif (!$Draft) {
                     // If the comment was not a draft
                     // If adding a comment
                     if ($Editing) {
                         // Just reload the comment in question
                         $this->Offset = $this->CommentModel->GetOffset($CommentID);
                         $this->CommentData = $this->CommentModel->Get($DiscussionID, 1, $this->Offset - 1);
                         // Load the discussion
                         $this->Discussion = $this->DiscussionModel->GetID($DiscussionID);
                         $this->ControllerName = 'discussion';
                         $this->View = 'comments';
                         // Also define the discussion url in case this request came from the post screen and needs to be redirected to the discussion
                         $this->SetJson('DiscussionUrl', Url('/discussion/' . $DiscussionID . '/' . Format::Url($this->Discussion->Name) . '/#Comment_' . $CommentID));
                     } else {
                         // Otherwise load all new comments that the user hasn't seen yet
                         $LastCommentID = $this->Form->GetFormValue('LastCommentID');
                         if (!is_numeric($LastCommentID)) {
                             $LastCommentID = $CommentID - 1;
                         }
                         // Failsafe back to this new comment if the lastcommentid was not defined properly
                         // Make sure the view knows the current offset
                         $this->Offset = $this->CommentModel->GetOffset($LastCommentID);
                         // Make sure to load all new comments since the page was last loaded by this user
                         $this->CommentData = $this->CommentModel->GetNew($DiscussionID, $LastCommentID);
                         // Load the discussion
                         $this->Discussion = $this->DiscussionModel->GetID($DiscussionID);
                         $this->ControllerName = 'discussion';
                         $this->View = 'comments';
                         // Make sure to set the user's discussion watch records
                         $CountComments = $this->CommentModel->GetCount($DiscussionID);
                         $Limit = $this->CommentData->NumRows();
                         $Offset = $CountComments - $Limit;
                         $this->CommentModel->SetWatch($this->Discussion, $Limit, $Offset, $CountComments);
                     }
                 } else {
                     // If this was a draft save, notify the user about the save
                     $this->StatusMessage = sprintf(Gdn::Translate('Draft saved at %s'), Format::Date());
                 }
                 // And update the draft count
                 $UserModel = Gdn::UserModel();
                 $CountDrafts = $UserModel->GetAttribute($Session->UserID, 'CountDrafts', 0);
                 $MyDrafts = Gdn::Translate('My Drafts');
                 if (is_numeric($CountDrafts) && $CountDrafts > 0) {
                     $MyDrafts .= '<span>' . $CountDrafts . '</span>';
                 }
                 $this->SetJson('MyDrafts', $MyDrafts);
             }
         }
     }
     $this->FireEvent('BeforeCommentRender');
     $this->Render();
 }
Beispiel #3
0
function WriteDiscussion($Discussion, &$Sender, &$Session, $Alt)
{
    $CssClass = 'DiscussionRow';
    $CssClass .= $Discussion->Bookmarked == '1' ? ' Bookmarked' : '';
    $CssClass .= $Alt . ' ';
    $CssClass .= $Discussion->Announce == '1' ? ' Announcement' : '';
    $CssClass .= $Discussion->InsertUserID == $Session->UserID ? ' Mine' : '';
    $CountUnreadComments = $Discussion->CountComments - $Discussion->CountCommentWatch;
    $CssClass .= $CountUnreadComments > 0 && $Session->IsValid() ? ' New' : '';
    ?>
<li class="<?php 
    echo $CssClass;
    ?>
">
   <ul class="Discussion">
      <?php 
    if ($Sender->ShowOptions) {
        ?>
      <li class="Options">
         <?php 
        // Build up the options that the user has for each discussion
        if ($Session->IsValid()) {
            // Bookmark link
            echo Anchor('<span>*</span>', '/vanilla/discussion/bookmark/' . $Discussion->DiscussionID . '/' . $Session->TransientKey() . '?Target=' . urlencode($Sender->SelfUrl), 'Bookmark' . ($Discussion->Bookmarked == '1' ? ' Bookmarked' : ''), array('title' => Gdn::Translate($Discussion->Bookmarked == '1' ? 'Unbookmark' : 'Bookmark')));
            $Sender->Options = '';
            // Dismiss an announcement
            if ($Discussion->Announce == '1' && $Discussion->Dismissed != '1') {
                $Sender->Options .= '<li>' . Anchor('Dismiss', 'vanilla/discussion/dismissannouncement/' . $Discussion->DiscussionID . '/' . $Session->TransientKey(), 'DismissAnnouncement') . '</li>';
            }
            // Edit discussion
            if ($Discussion->FirstUserID == $Session->UserID || $Session->CheckPermission('Vanilla.Discussions.Edit', $Discussion->CategoryID)) {
                $Sender->Options .= '<li>' . Anchor('Edit', 'vanilla/post/editdiscussion/' . $Discussion->DiscussionID, 'EditDiscussion') . '</li>';
            }
            // Announce discussion
            if ($Session->CheckPermission('Vanilla.Discussions.Announce', $Discussion->CategoryID)) {
                $Sender->Options .= '<li>' . Anchor($Discussion->Announce == '1' ? 'Unannounce' : 'Announce', 'vanilla/discussion/announce/' . $Discussion->DiscussionID . '/' . $Session->TransientKey(), 'AnnounceDiscussion') . '</li>';
            }
            // Sink discussion
            if ($Session->CheckPermission('Vanilla.Discussions.Sink', $Discussion->CategoryID)) {
                $Sender->Options .= '<li>' . Anchor($Discussion->Sink == '1' ? 'Unsink' : 'Sink', 'vanilla/discussion/sink/' . $Discussion->DiscussionID . '/' . $Session->TransientKey() . '?Target=' . urlencode($Sender->SelfUrl), 'SinkDiscussion') . '</li>';
            }
            // Close discussion
            if ($Session->CheckPermission('Vanilla.Discussions.Close', $Discussion->CategoryID)) {
                $Sender->Options .= '<li>' . Anchor($Discussion->Closed == '1' ? 'Reopen' : 'Close', 'vanilla/discussion/close/' . $Discussion->DiscussionID . '/' . $Session->TransientKey() . '?Target=' . urlencode($Sender->SelfUrl), 'CloseDiscussion') . '</li>';
            }
            // Delete discussion
            if ($Session->CheckPermission('Vanilla.Discussions.Delete', $Discussion->CategoryID)) {
                $Sender->Options .= '<li>' . Anchor('Delete', 'vanilla/discussion/delete/' . $Discussion->DiscussionID . '/' . $Session->TransientKey() . '?Target=' . urlencode($Sender->SelfUrl), 'DeleteDiscussion') . '</li>';
            }
            // Allow plugins to add options
            $Sender->FireEvent('DiscussionOptions');
            if ($Sender->Options != '') {
                ?>
               <ul class="Options">
                  <li><strong><?php 
                echo Gdn::Translate('Options');
                ?>
</strong>
                     <ul>
                        <?php 
                echo $Sender->Options;
                ?>
                     </ul>
                  </li>
               </ul>
               <?php 
            }
        }
        ?>
      </li>
      <?php 
    }
    ?>
      <li class="Title">
         <strong><?php 
    echo Anchor(Format::Text($Discussion->Name), '/discussion/' . $Discussion->DiscussionID . '/' . Format::Url($Discussion->Name) . ($Discussion->CountCommentWatch > 0 ? '/#Item_' . $Discussion->CountCommentWatch : ''), 'DiscussionLink');
    ?>
</strong>
      </li>
      <li class="Meta">
         <?php 
    echo '<span>';
    echo sprintf(Plural($Discussion->CountComments, '%s comment', '%s comments'), $Discussion->CountComments);
    echo '</span>';
    if ($CountUnreadComments > 0 && $Session->IsValid()) {
        echo '<strong>', sprintf(Gdn::Translate('%s new'), $CountUnreadComments), '</strong>';
    }
    echo '<span>';
    printf(Gdn::Translate('Most recent by %1$s %2$s'), UserAnchor($Discussion->LastName), Format::Date($Discussion->LastDate));
    echo '</span>';
    echo Anchor($Discussion->Category, '/categories/' . urlencode($Discussion->Category), 'Category');
    $Sender->FireEvent('DiscussionMeta');
    ?>
      </li>
   </ul>
</li>
<?php 
}
Beispiel #4
0
 public function ProfileController_Discussions_Create(&$Sender)
 {
     $UserReference = ArrayValue(0, $Sender->RequestArgs, '');
     $Offset = ArrayValue(1, $Sender->RequestArgs, 0);
     // Tell the ProfileController what tab to load
     $Sender->SetTabView($UserReference, 'Discussions', 'Profile', 'Discussions', 'Vanilla');
     // Load the data for the requested tab.
     if (!is_numeric($Offset) || $Offset < 0) {
         $Offset = 0;
     }
     $Limit = Gdn::Config('Vanilla.Discussions.PerPage', 30);
     $DiscussionModel = new Gdn_DiscussionModel();
     $Sender->DiscussionData = $DiscussionModel->Get($Offset, $Limit, array('d.InsertUserID' => $Sender->User->UserID));
     $CountDiscussions = $Offset + $Sender->DiscussionData->NumRows();
     if ($Sender->DiscussionData->NumRows() == $Limit) {
         $CountDiscussions = $Offset + $Limit + 1;
     }
     // Build a pager
     $PagerFactory = new PagerFactory();
     $Sender->Pager = $PagerFactory->GetPager('MorePager', $Sender);
     $Sender->Pager->MoreCode = 'More Discussions';
     $Sender->Pager->LessCode = 'Newer Discussions';
     $Sender->Pager->ClientID = 'Pager';
     $Sender->Pager->Configure($Offset, $Limit, $CountDiscussions, 'profile/discussions/' . Format::Url($Sender->User->Name) . '/%1$s/');
     // Deliver json data if necessary
     if ($Sender->DeliveryType() != DELIVERY_TYPE_ALL && $Offset > 0) {
         $Sender->SetJson('LessRow', $Sender->Pager->ToString('less'));
         $Sender->SetJson('MoreRow', $Sender->Pager->ToString('more'));
         $Sender->View = 'discussions';
     }
     // Set the handlertype back to normal on the profilecontroller so that it fetches it's own views
     $Sender->HandlerType = HANDLER_TYPE_NORMAL;
     // Do not show discussion options
     $Sender->ShowOptions = FALSE;
     // Render the ProfileController
     $Sender->Render();
 }
Beispiel #5
0
 public function Index($DiscussionID = '', $Offset = '', $Limit = '')
 {
     $this->AddCssFile('vanilla.css');
     $Session = Gdn::Session();
     if ($this->Head) {
         $this->Head->AddScript('/js/library/jquery.resizable.js');
         $this->Head->AddScript('/js/library/jquery.ui.packed.js');
         $this->Head->AddScript('/js/library/jquery.autogrow.js');
         $this->Head->AddScript('/js/library/jquery.gardenmorepager.js');
         $this->Head->AddScript('/applications/vanilla/js/options.js');
         $this->Head->AddScript('/applications/vanilla/js/bookmark.js');
         $this->Head->AddScript('/applications/vanilla/js/discussion.js');
         $this->Head->AddScript('/applications/vanilla/js/autosave.js');
     }
     // Load the discussion record
     $DiscussionID = is_numeric($DiscussionID) && $DiscussionID > 0 ? $DiscussionID : 0;
     $this->SetData('Discussion', $this->DiscussionModel->GetID($DiscussionID), TRUE);
     if (!is_object($this->Discussion)) {
         Redirect('FileNotFound');
     }
     // Check Permissions
     $this->Permission('Vanilla.Discussions.View', $this->Discussion->CategoryID);
     $this->SetData('CategoryID', $this->CategoryID = $this->Discussion->CategoryID, TRUE);
     if ($this->Discussion === FALSE) {
         return $this->ReDispatch('garden/home/filenotfound');
     } else {
         // Setup
         if ($this->Head) {
             $this->Head->Title(Format::Text($this->Discussion->Name));
         }
         // Define the query offset & limit
         if (!is_numeric($Limit) || $Limit < 0) {
             $Limit = Gdn::Config('Vanilla.Comments.PerPage', 50);
         }
         $this->Offset = $Offset;
         if (!is_numeric($this->Offset) || $this->Offset < 0) {
             // Round down to the appropriate offset based on the user's read comments & comments per page
             $CountCommentWatch = $this->Discussion->CountCommentWatch > 0 ? $this->Discussion->CountCommentWatch : 0;
             if ($CountCommentWatch > $this->Discussion->CountComments) {
                 $CountCommentWatch = $this->Discussion->CountComments;
             }
             // (((67 comments / 10 perpage) = 6.7) rounded down = 6) * 10 perpage = offset 60;
             $this->Offset = floor($CountCommentWatch / $Limit) * $Limit;
         }
         if ($this->Offset < 0) {
             $this->Offset = 0;
         }
         // Make sure to set the user's discussion watch records
         $this->CommentModel->SetWatch($this->Discussion, $Limit, $this->Offset, $this->Discussion->CountComments);
         // Load the comments
         $this->SetData('CommentData', $this->CommentData = $this->CommentModel->Get($DiscussionID, $Limit, $this->Offset), TRUE);
         // Build a pager
         $PagerFactory = new PagerFactory();
         $this->Pager = $PagerFactory->GetPager('MorePager', $this);
         $this->Pager->MoreCode = '%1$s more comments';
         $this->Pager->LessCode = '%1$s older comments';
         $this->Pager->ClientID = 'Pager';
         $this->Pager->Configure($this->Offset, $Limit, $this->Discussion->CountComments, 'vanilla/discussion/' . $DiscussionID . '/%1$s/%2$s/' . Format::Url($this->Discussion->Name));
     }
     // Define the form for the comment input
     $this->Form = Gdn::Factory('Form', 'Comment');
     $this->DiscussionID = $this->Discussion->DiscussionID;
     $this->Form->AddHidden('DiscussionID', $this->DiscussionID);
     $this->Form->AddHidden('CommentID', '');
     $this->Form->AddHidden('DraftID', '');
     $this->Form->Action = Url('/vanilla/post/comment/');
     // Deliver json data if necessary
     if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
         $this->SetJson('LessRow', $this->Pager->ToString('less'));
         $this->SetJson('MoreRow', $this->Pager->ToString('more'));
         $this->View = 'comments';
     }
     // Add Modules
     $this->AddModule('NewDiscussionModule');
     $this->AddModule('CategoriesModule');
     $DraftsModule = new DraftsModule($this);
     $DraftsModule->GetData(20, $DiscussionID);
     $this->AddModule($DraftsModule);
     $BookmarkedModule = new BookmarkedModule($this);
     $BookmarkedModule->GetData();
     $this->AddModule($BookmarkedModule);
     $this->FireEvent('DiscussionRenderBefore');
     $this->Render();
 }
 public function RecordActivity($UserID, $DiscussionID, $DiscussionName)
 {
     // Report that the discussion was created
     AddActivity($UserID, 'NewDiscussion', Anchor(Format::Text($DiscussionName), 'vanilla/discussion/' . $DiscussionID . '/' . Format::Url($DiscussionName)));
     // Get the user's discussion count
     $Data = $this->SQL->Select('DiscussionID', 'count', 'CountDiscussions')->From('Discussion')->Where('InsertUserID', $UserID)->Get();
     // Save the count to the user table
     $this->SQL->Update('User')->Set('CountDiscussions', $Data->NumRows() > 0 ? $Data->FirstRow()->CountDiscussions : 0)->Where('UserID', $UserID)->Put();
 }
Beispiel #7
0
 public function PostController_Reply_Create(&$Sender, $EventArguments = '')
 {
     $Sender->View = PATH_PLUGINS . DS . 'VanillaCommentReplies' . DS . 'views' . DS . 'vanilla_post_reply.php';
     $ReplyCommentID = 0;
     if (is_array($EventArguments) && array_key_exists(0, $EventArguments)) {
         $ReplyCommentID = is_numeric($EventArguments[0]) ? $EventArguments[0] : 0;
     }
     $ReplyModel = Gdn::Factory('ReplyModel');
     $Sender->ReplyCommentID = $ReplyCommentID;
     // Set the model on the form.
     $Sender->Form->SetModel($ReplyModel);
     // Make sure the form knows which comment we're replying to
     $Sender->Form->AddHidden('ReplyCommentID', $ReplyCommentID);
     $Sender->ReplyComment = $Sender->CommentModel->GetID($ReplyCommentID);
     $Discussion = $Sender->DiscussionModel->GetID($Sender->ReplyComment->DiscussionID);
     $Sender->Permission('Vanilla.Comments.Add', $Discussion->CategoryID);
     if ($Sender->Form->AuthenticatedPostBack()) {
         $CommentID = $Sender->Form->Save();
         if ($Sender->Form->ErrorCount() == 0) {
             // Redirect if this is not an ajax request
             if ($Sender->DeliveryType() == DELIVERY_TYPE_ALL) {
                 $Discussion = $ReplyModel->GetDiscussion($CommentID);
                 Redirect('/vanilla/discussion/' . $Discussion->DiscussionID . '/' . Format::Url($Discussion->Name) . '#Comment_' . $CommentID);
             }
             // Load all new replies that the user hasn't seen yet
             $LastCommentID = $Sender->Form->GetFormValue('LastCommentID');
             if (!is_numeric($LastCommentID)) {
                 $LastCommentID = $CommentID - 1;
             }
             $Sender->ReplyData = $ReplyModel->GetNew($ReplyCommentID, $LastCommentID);
             $Sender->CurrentReply = is_object($Sender->ReplyData) ? $Sender->ReplyData->NextRow() : FALSE;
             $Replies = $Sender->ReplyComment->CountReplies + 1;
             $Sender->SetJson('Replies', sprintf(Translate(Plural($Replies, '%s Reply', '%s Replies')), $Replies));
             $Sender->SetJson('CommentID', $CommentID);
             $Sender->Discussion = $Sender->DiscussionModel->GetID($Sender->ReplyComment->DiscussionID);
             $Sender->ControllerName = 'discussion';
             $Sender->View = PATH_PLUGINS . DS . 'VanillaCommentReplies' . DS . 'views' . DS . 'replies.php';
         } else {
             if ($Sender->_DeliveryType !== DELIVERY_TYPE_ALL) {
                 // Handle ajax-based errors
                 $Sender->StatusMessage = $Sender->Form->Errors();
             }
         }
     }
     $Sender->Render();
 }
Beispiel #8
0
<?php

if (!defined('APPLICATION')) {
    exit;
}
$Session = Gdn::Session();
$CancelUrl = '/vanilla/discussions';
if (Gdn::Config('Vanilla.Categories.Use') === TRUE && $this->CategoryID > 0 && $this->CategoryData->NumRows() > 0) {
    foreach ($this->CategoryData->Result() as $Cat) {
        if ($Cat->CategoryID == $this->CategoryID) {
            $CancelUrl = '/vanilla/discussions/0/' . $Cat->CategoryID . '/' . Format::Url($Cat->Name);
            break;
        }
    }
}
?>
<div id="DiscussionForm">
   <h2><?php 
echo T(property_exists($this, 'Discussion') ? 'Edit Discussion' : 'Start a New Discussion');
?>
</h2>
   <?php 
echo $this->Form->Open();
echo $this->Form->Errors();
echo $this->Form->Label('Discussion Title', 'Name');
echo $this->Form->TextBox('Name', array('maxlength' => 100));
if (Gdn::Config('Vanilla.Categories.Use') === TRUE) {
    echo '<div class="Category">';
    echo $this->Form->Label('Category', 'CategoryID');
    echo $this->Form->DropDown('CategoryID', $this->CategoryData, array('TextField' => 'Name', 'ValueField' => 'CategoryID'));
    echo '</div>';
Beispiel #9
0
 public function SendNotification($ActivityID, $Story = '')
 {
     $Activity = $this->GetID($ActivityID);
     if (!is_object($Activity)) {
         return;
     }
     $Story = Format::Text($Story == '' ? $Activity->Story : $Story);
     // If this is a comment on another activity, fudge the activity a bit so that everything appears properly.
     if (is_null($Activity->RegardingUserID) && $Activity->CommentActivityID > 0) {
         $CommentActivity = $this->GetID($Activity->CommentActivityID);
         $Activity->RegardingUserID = $CommentActivity->RegardingUserID;
         $Activity->Route = '/profile/' . $CommentActivity->RegardingUserID . '/' . Format::Url($CommentActivity->RegardingName) . '/#Activity_' . $Activity->CommentActivityID;
     }
     $User = $this->SQL->Select('Name, Email, Preferences')->From('User')->Where('UserID', $Activity->RegardingUserID)->Get()->FirstRow();
     if ($User) {
         $Preferences = Format::Unserialize($User->Preferences);
         $Preference = ArrayValue('Email.' . $Activity->ActivityType, $Preferences, Gdn::Config('Preferences.Email.' . $Activity->ActivityType));
         if ($Preference) {
             $ActivityHeadline = Format::Text(Format::ActivityHeadline($Activity, $Activity->ActivityUserID, $Activity->RegardingUserID));
             $Email = new Gdn_Email();
             $Email->Subject(sprintf(T('[%1$s] %2$s'), Gdn::Config('Garden.Title'), $ActivityHeadline));
             $Email->To($User->Email, $User->Name);
             $Email->From(Gdn::Config('Garden.SupportEmail'), Gdn::Config('Garden.SupportName'));
             $Email->Message(sprintf(T($Story == '' ? 'EmailNotification' : 'EmailStoryNotification'), $ActivityHeadline, Url($Activity->Route == '' ? '/' : $Activity->Route, TRUE), $Story));
             try {
                 $Email->Send();
             } catch (Exception $ex) {
                 // Don't do anything with the exception.
             }
         }
     }
 }
Beispiel #10
0
 /**
  * Adds a tab (or array of tabs) to the profile tab collection.
  *
  * @param mixed The tab name (or array of tab names) to add to the profile tab collection.
  * @param string URL the tab should point to.
  */
 public function AddProfileTab($TabName, $TabUrl = '')
 {
     if (!is_array($TabName)) {
         $TabName = array($TabName => $TabUrl);
     }
     foreach ($TabName as $Name => $Url) {
         if ($Url == '') {
             $Url = '/profile/' . strtolower($Name) . '/' . $this->User->UserID . '/' . Format::Url($this->User->Name);
         }
         $this->_ProfileTabs[$Name] = $Url;
     }
 }
Beispiel #11
0
<?php

if (!defined('APPLICATION')) {
    exit;
}
$Session = Gdn::Session();
if ($Session->IsValid()) {
    // Bookmark link
    echo Anchor('<span>*</span>', '/vanilla/discussion/bookmark/' . $this->Discussion->DiscussionID . '/' . $Session->TransientKey() . '?Target=' . urlencode($this->SelfUrl), 'Bookmark' . ($this->Discussion->Bookmarked == '1' ? ' Bookmarked' : ''), array('title' => Gdn::Translate($this->Discussion->Bookmarked == '1' ? 'Unbookmark' : 'Bookmark')));
}
?>
<h2><?php 
if (Gdn::Config('Vanilla.Categories.Use') === TRUE) {
    echo Anchor($this->Discussion->Category, 'categories/' . $this->Discussion->CategoryID . '/' . Format::Url($this->Discussion->Category));
    echo '<span>&bull;</span>';
}
echo Format::Text($this->Discussion->Name);
?>
</h2>
<?php 
echo $this->Pager->ToString('less');
echo $this->RenderAsset('DiscussionBefore');
?>
<ul id="Discussion">
   <?php 
echo $this->FetchView('comments');
?>
</ul>
<?php 
if ($this->Pager->LastPage()) {
    $this->AddDefinition('DiscussionID', $this->Data['Discussion']->DiscussionID);
Beispiel #12
0
function WriteDiscussion($Discussion, &$Sender, &$Session, $Alt)
{
    $CssClass = 'Item';
    $CssClass .= $Discussion->Bookmarked == '1' ? ' Bookmarked' : '';
    $CssClass .= $Alt . ' ';
    $CssClass .= $Discussion->Announce == '1' ? ' Announcement' : '';
    $CssClass .= $Discussion->InsertUserID == $Session->UserID ? ' Mine' : '';
    $CountUnreadComments = $Discussion->CountComments - $Discussion->CountCommentWatch;
    $CssClass .= $CountUnreadComments > 0 && $Session->IsValid() ? ' New' : '';
    $Sender->EventArguments['Discussion'] =& $Discussion;
    $Last = UserBuilder($Discussion, 'Last');
    ?>
<li class="<?php 
    echo $CssClass;
    ?>
">
   <?php 
    WriteOptions($Discussion, $Sender, $Session);
    ?>
   <div class="ItemContent Discussion">
      <?php 
    echo Anchor(Format::Text($Discussion->Name), '/discussion/' . $Discussion->DiscussionID . '/' . Format::Url($Discussion->Name) . ($Discussion->CountCommentWatch > 0 ? '/#Item_' . $Discussion->CountCommentWatch : ''), 'Title');
    ?>
      <?php 
    $Sender->FireEvent('AfterDiscussionTitle');
    ?>
      <div class="Meta">
         <?php 
    if ($Discussion->Announce == '1') {
        ?>
         <span class="Announcement"><?php 
        echo T('Announcement');
        ?>
</span>
         <?php 
    }
    ?>
         <span><?php 
    printf(Plural($Discussion->CountComments, '%s comment', '%s comments'), $Discussion->CountComments);
    ?>
</span>
         <?php 
    if ($CountUnreadComments > 0 && $Session->IsValid()) {
        echo '<strong>', sprintf(T('%s new'), $CountUnreadComments), '</strong>';
    }
    ?>
         <span><?php 
    printf(T('Most recent by %1$s %2$s'), UserAnchor($Last), Format::Date($Discussion->LastDate));
    ?>
</span>
         <span><?php 
    echo Anchor($Discussion->Category, '/categories/' . $Discussion->CategoryUrlCode, 'Category');
    ?>
</span>
         <?php 
    $Sender->FireEvent('DiscussionMeta');
    ?>
      </div>
   </div>
</li>
<?php 
}
Beispiel #13
0
        $Class .= ' HasPhoto';
    }
    $Class = trim($Class);
    $Name = $Session->UserID == $Conversation->LastMessageUserID ? 'You' : $Conversation->LastMessageName;
    $JumpToItem = $Conversation->CountMessages - $Conversation->CountNewMessages;
    ?>
<li<?php 
    echo $Class == '' ? '' : ' class="' . $Class . '"';
    ?>
>
   <?php 
    echo UserPhoto($Conversation->LastMessageName, $Conversation->LastMessagePhoto, 'Photo');
    ?>
   <div>
      <?php 
    echo Anchor($Name, '/profile/' . Format::Url($Conversation->LastMessageName), 'Name');
    echo Anchor(SliceString(Format::Text($Conversation->LastMessage), 100), '/messages/' . $Conversation->ConversationID . '/#Item_' . $JumpToItem, 'Message');
    echo '<div class="Meta">';
    echo Format::Date($Conversation->DateLastMessage);
    echo '<span>&bull;</span>';
    printf(Translate(Plural($Conversation->CountMessages, '%s message', '%s messages')), $Conversation->CountMessages);
    if ($Conversation->CountNewMessages > 0) {
        echo '<span>&bull;</span>';
        echo '<em>';
        printf(Gdn::Translate('%s new'), $Conversation->CountNewMessages);
        echo '</em>';
    }
    echo '</div>';
    ?>
   </div>
</li>
Beispiel #14
0
<?php

if (!defined('APPLICATION')) {
    exit;
}
// An individual discussion record for all panel modules to use when rendering a discussion list.
?>
<li id="<?php 
echo 'Bookmark_' . $Discussion->DiscussionID;
?>
">
   <strong><?php 
echo Anchor($Discussion->Name, '/discussion/' . $Discussion->DiscussionID . '/' . Format::Url($Discussion->Name) . ($Discussion->CountCommentWatch > 0 ? '/#Item_' . $Discussion->CountCommentWatch : ''), 'DiscussionLink');
?>
</strong>
   <div class="Meta">
      <?php 
echo '<span>' . $Discussion->CountComments . '</span>';
$CountUnreadComments = $Discussion->CountComments - $Discussion->CountCommentWatch;
if ($CountUnreadComments > 0) {
    echo '<strong>' . sprintf('%s new', $CountUnreadComments) . '</strong>';
}
$Last = new stdClass();
$Last->UserID = $Discussion->LastUserID;
$Last->Name = $Discussion->LastName;
echo '<span>' . Format::Date($Discussion->LastDate) . ' ' . UserAnchor($Last) . '</span>';
?>
   </div>
</li>
Beispiel #15
0
if (!defined('APPLICATION')) {
    exit;
}
$ViewLocation = $this->FetchViewLocation('discussions', 'discussions');
?>
<ul class="Categories">
   <?php 
foreach ($this->CategoryData->Result() as $Category) {
    $this->Category = $Category;
    $this->DiscussionData = $this->CategoryDiscussionData[$Category->CategoryID];
    if ($this->DiscussionData->NumRows() > 0) {
        ?>
   <li>
      <h1><?php 
        echo Anchor($Category->Name, '/discussions/0/' . $Category->CategoryID . '/' . Format::Url($Category->Name));
        ?>
</h1>
      <ul class="DataList Discussions">
         <?php 
        include $this->FetchViewLocation('discussions', 'discussions');
        ?>
      </ul>
      <?php 
        if ($this->DiscussionData->NumRows() == $this->DiscussionsPerCategory) {
            ?>
      <div class="More"><?php 
            echo Anchor('More Discussions', '/categories/' . urlencode($this->Category->Name));
            ?>
</div>
      <?php