public function Activity($UserReference = '', $Username = '', $UserID = '')
 {
     $this->Permission('Garden.Profiles.View');
     $this->GetUserInfo($UserReference, $Username, $UserID);
     $this->SetTabView('Activity');
     $this->ActivityModel = new ActivityModel();
     $Session = Gdn::Session();
     $Comment = $this->Form->GetFormValue('Comment');
     if ($Session->UserID > 0 && $this->Form->AuthenticatedPostBack() && !StringIsNullOrEmpty($Comment)) {
         $Comment = substr($Comment, 0, 1000);
         // Limit to 1000 characters...
         // Update About if necessary
         $ActivityType = 'WallComment';
         $SendNotification = TRUE;
         if ($Session->UserID == $this->User->UserID) {
             $SendNotification = FALSE;
             $this->UserModel->SaveAbout($Session->UserID, $Comment);
             $this->User->About = $Comment;
             $this->SetJson('UserData', $this->FetchView('user'));
             $ActivityType = 'AboutUpdate';
         }
         $NewActivityID = $this->ActivityModel->Add($Session->UserID, $ActivityType, $Comment, $this->User->UserID, '', '/profile/' . $this->User->UserID . '/' . Gdn_Format::Url($this->User->Name), $SendNotification);
         if ($this->_DeliveryType === DELIVERY_TYPE_ALL) {
             Redirect('dashboard/profile/' . $UserReference);
         } else {
             // Load just the single new comment
             $this->HideActivity = TRUE;
             $this->ActivityData = $this->ActivityModel->GetWhere('ActivityID', $NewActivityID);
             $this->View = 'activities';
             $this->ControllerName = 'activity';
         }
     } else {
         $this->ProfileUserID = $this->User->UserID;
         $this->ActivityData = $this->ActivityModel->Get($this->User->UserID);
         if ($this->ActivityData->NumRows() > 0) {
             $ActivityData = $this->ActivityData->Result();
             $ActivityIDs = ConsolidateArrayValuesByKey($ActivityData, 'ActivityID');
             $LastActivity = $this->ActivityData->FirstRow();
             $LastModifiedDate = Gdn_Format::ToTimestamp($this->User->DateUpdated);
             $LastActivityDate = Gdn_Format::ToTimestamp($LastActivity->DateInserted);
             if ($LastModifiedDate < $LastActivityDate) {
                 $LastModifiedDate = $LastActivityDate;
             }
             // Make sure to only query this page if the user has no new activity since the requesting browser last saw it.
             $this->SetLastModified($LastModifiedDate);
             $this->CommentData = $this->ActivityModel->GetComments($ActivityIDs);
         } else {
             $this->CommentData = FALSE;
         }
     }
     // Set the canonical Url.
     if (is_numeric($this->User->Name) || Gdn_Format::Url($this->User->Name) != strtolower($this->User->Name)) {
         $this->CanonicalUrl(Url('profile/' . $this->User->UserID . '/' . Gdn_Format::Url($this->User->Name), TRUE));
     } else {
         $this->CanonicalUrl(Url('profile/' . strtolower($this->User->Name), TRUE));
     }
     $this->Render();
 }
 public function ToString()
 {
     if (!Gdn::Session()->CheckPermission('Garden.Activity.View')) {
         return '';
     }
     if (StringIsNullOrEmpty($this->ActivityModuleTitle)) {
         $this->ActivityModuleTitle = T('Recent Activity');
     }
     $Data = $this->ActivityData;
     if (is_object($Data) && $Data->NumRows() > 0) {
         return parent::ToString();
     }
     return '';
 }
 /**
  * Set DateLastComment to null & sink & close if this is an insert and 'Show as Page' was selected.
  */
 public function discussionModel_beforeSaveDiscussion_handler($sender, &$args)
 {
     if (CheckPermission('Garden.Community.Manage') || CheckPermission('Garden.Settings.Manage')) {
         if ($args['Insert'] && $args['FormPostValues']['Page'] == 1) {
             $args['FormPostValues']['DateLastComment'] = NULL;
             $args['FormPostValues']['Sink'] = 1;
             $args['FormPostValues']['Closed'] = 1;
             $args['FormPostValues']['Type'] = 'SimplePage';
             if (StringIsNullOrEmpty($args['FormPostValues']['ForeignID'])) {
                 $sender->Validation->AddValidationResult('ForeignID', 'URL Slug required for pages.');
             }
         }
     }
 }
Example #4
0
 public function DefineLocation($Message)
 {
     if (is_object($Message)) {
         if ($Message->Controller == 'Base') {
             $Message->Location = 'Base';
         } else {
             $Message->Location = $Message->Application;
             if (!StringIsNullOrEmpty($Message->Controller)) {
                 $Message->Location .= '/' . $Message->Controller;
             }
             if (!StringIsNullOrEmpty($Message->Method)) {
                 $Message->Location .= '/' . $Message->Method;
             }
         }
     }
     return $Message;
 }
Example #5
0
 public function DefineLocation($Message)
 {
     if (is_object($Message)) {
         if (in_array($Message->Controller, $this->_SpecialLocations)) {
             $Message->Location = $Message->Controller;
         } else {
             $Message->Location = $Message->Application;
             if (!StringIsNullOrEmpty($Message->Controller)) {
                 $Message->Location .= '/' . $Message->Controller;
             }
             if (!StringIsNullOrEmpty($Message->Method)) {
                 $Message->Location .= '/' . $Message->Method;
             }
         }
     }
     return $Message;
 }
 /**
  * Build the Message's Location property and add it.
  *
  * @param mixed $Message Array or object.
  * @return mixed Array or object given with Location property/key added.
  */
 public function DefineLocation($Message)
 {
     $Controller = GetValue('Controller', $Message);
     $Application = GetValue('Application', $Message);
     $Method = GetValue('Method', $Message);
     if (in_array($Controller, $this->_SpecialLocations)) {
         SetValue('Location', $Message, $Controller);
     } else {
         SetValue('Location', $Message, $Application);
         if (!StringIsNullOrEmpty($Controller)) {
             SetValue('Location', $Message, GetValue('Location', $Message) . '/' . $Controller);
         }
         if (!StringIsNullOrEmpty($Method)) {
             SetValue('Location', $Message, GetValue('Location', $Message) . '/' . $Method);
         }
     }
     return $Message;
 }
 public function Index($RoleID = '')
 {
     $this->Permission('Garden.Activity.View');
     // Limit to specific RoleIDs?
     if ($RoleID != '') {
         $RoleID = explode(',', $RoleID);
     }
     $this->AddJsFile('activity.js');
     $this->Title(T('Recent Activity'));
     $Session = Gdn::Session();
     $Comment = $this->Form->GetFormValue('Comment');
     $this->CommentData = FALSE;
     if ($Session->UserID > 0 && $this->Form->AuthenticatedPostBack() && !StringIsNullOrEmpty($Comment)) {
         $Comment = substr($Comment, 0, 1000);
         // Limit to 1000 characters...
         // Update About if necessary
         $ActivityType = 'WallComment';
         $NewActivityID = $this->ActivityModel->Add($Session->UserID, $ActivityType, $Comment);
         if ($this->_DeliveryType === DELIVERY_TYPE_ALL) {
             Redirect('activity');
         } else {
             // Load just the single new comment
             $this->HideActivity = TRUE;
             $this->ActivityData = $this->ActivityModel->GetWhere('ActivityID', $NewActivityID);
             $this->View = 'activities';
         }
     } else {
         $this->ActivityData = is_array($RoleID) ? $this->ActivityModel->GetForRole($RoleID) : $this->ActivityModel->Get();
         if ($this->ActivityData->NumRows() > 0) {
             $ActivityData = $this->ActivityData->ResultArray();
             $ActivityIDs = ConsolidateArrayValuesByKey($ActivityData, 'ActivityID');
             $this->CommentData = $this->ActivityModel->GetComments($ActivityIDs);
         }
         $this->View = 'all';
     }
     $this->Render();
 }
Example #8
0
 function ReplaceEmpty(&$Collection, $R)
 {
     if (is_object($Collection)) {
         foreach (get_object_vars($Collection) as $Property => $Value) {
             if (StringIsNullOrEmpty($Value)) {
                 $Collection->{$Property} = $R;
             }
         }
     } else {
         if (is_array($Collection)) {
             foreach ($Collection as &$Value) {
                 if (StringIsNullOrEmpty($Value)) {
                     $Value = $R;
                 }
             }
         }
     }
     return $Collection;
 }
Example #9
0
 function CheckRequirements($ItemName, $RequiredItems, $EnabledItems, $RequiredItemTypeCode)
 {
     // 1. Make sure that $RequiredItems are present
     if (is_array($RequiredItems)) {
         foreach ($RequiredItems as $RequiredItemName => $RequiredVersion) {
             if (array_key_exists($RequiredItemName, $EnabledItems) === FALSE) {
                 throw new Exception(sprintf(Gdn::Translate('%1$s requires the %2$s %3$s version %4$s.'), $ItemName, $RequiredItemName, $RequiredItemTypeCode, $RequiredVersion));
             } else {
                 if (StringIsNullOrEmpty($RequiredVersion) === FALSE) {
                     // If the item exists and is enabled, check the version
                     $EnabledVersion = ArrayValue('Version', ArrayValue($RequiredItemName, $EnabledItems, array()), '');
                     if ($EnabledVersion !== $RequiredVersion) {
                         // Check for version ranges (<, <=, >, >=)
                         $Matches = FALSE;
                         preg_match_all('/(>|>=|<|<=){1}([\\d\\.]+)/', $RequiredVersion, $Matches);
                         if (is_array($Matches) && count($Matches) == 3 && count($Matches[1]) > 0) {
                             // The matches array should contain a three parts:
                             /*
                              eg. The following $RequiredVersion string:
                                >1.33<=4.1
                             would result in:
                                Array (
                                      [0] => Array
                                          (
                                              [0] => >1.33
                                              [1] => <=4.1
                                          )
                                      [1] => Array
                                          (
                                              [0] => >
                                              [1] => <=
                                          )
                                      [2] => Array
                                          (
                                              [0] => 1.33
                                              [1] => 4.1
                                          )
                                  )
                             */
                             $Operators = $Matches[1];
                             $Versions = $Matches[2];
                             $Count = count($Operators);
                             for ($i = 0; $i < $Count; ++$i) {
                                 $Operator = $Operators[$i];
                                 $MatchVersion = $Versions[$i];
                                 if (!version_compare($EnabledVersion, $MatchVersion, $Operator)) {
                                     throw new Exception(sprintf(Gdn::Translate('%1$s requires the %2$s %3$s version %4$s %5$s'), $ItemName, $RequiredItemName, $RequiredItemTypeCode, $Operator, $MatchVersion));
                                 }
                             }
                         } else {
                             if ($RequiredVersion != '*' && $RequiredVersion != '') {
                                 throw new Exception(sprintf(Gdn::Translate('%1$s requires the %2$s %3$s version %4$s'), $ItemName, $RequiredItemName, $RequiredItemTypeCode, $RequiredVersion));
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Example #10
0
 public function Activity($UserReference = '')
 {
     $this->SetTabView($UserReference, 'Activity');
     $this->ActivityModel = new ActivityModel();
     $Session = Gdn::Session();
     $Comment = $this->Form->GetFormValue('Comment');
     if ($Session->UserID > 0 && $this->Form->AuthenticatedPostBack() && !StringIsNullOrEmpty($Comment)) {
         $Comment = substr($Comment, 0, 1000);
         // Limit to 1000 characters...
         // Update About if necessary
         $ActivityType = 'WallComment';
         if ($Session->UserID == $this->User->UserID) {
             $this->UserModel->SaveAbout($Session->UserID, $Comment);
             $this->User->About = $Comment;
             $this->SetJson('UserData', $this->FetchView('user'));
             $ActivityType = 'AboutUpdate';
         }
         $NewActivityID = $this->ActivityModel->Add($Session->UserID, $ActivityType, $Comment, $this->User->UserID);
         /*         if (strlen(trim($About)) > 0)
                     AddActivity($UserID, 'AboutUpdate', $About);
         */
         if ($this->_DeliveryType === DELIVERY_TYPE_ALL) {
             Redirect('garden/profile/' . $UserReference);
         } else {
             // Load just the single new comment
             $this->HideActivity = TRUE;
             $this->ActivityData = $this->ActivityModel->GetWhere('ActivityID', $NewActivityID);
             $this->View = 'activities';
             $this->ControllerName = 'activity';
         }
     } else {
         $this->ProfileUserID = $this->User->UserID;
         $this->ActivityData = $this->ActivityModel->Get($this->User->UserID);
         if ($this->ActivityData->NumRows() > 0) {
             $LastActivity = $this->ActivityData->FirstRow();
             $LastModifiedDate = Format::ToTimestamp($this->User->DateUpdated);
             $LastActivityDate = Format::ToTimestamp($LastActivity->DateInserted);
             if ($LastModifiedDate < $LastActivityDate) {
                 $LastModifiedDate = $LastActivityDate;
             }
             // Make sure to only query this page if the user has no new activity since the requesting browser last saw it.
             $this->SetLastModified($LastModifiedDate);
             $FirstActivityID = $this->ActivityData->LastRow()->ActivityID;
             $this->CommentData = $this->ActivityModel->GetComments($FirstActivityID, $LastActivity->ActivityID, $this->User->UserID);
         } else {
             $this->CommentData = FALSE;
         }
     }
     $this->Render();
 }
Example #11
0
if (!defined('APPLICATION')) {
    exit;
}
// Get the information for displaying the connection information.
if (!($ConnectName = $this->Form->GetFormValue('FullName'))) {
    $ConnectName = $this->Form->GetFormValue('Name');
}
$ConnectPhoto = $this->Form->GetFormValue('Photo');
if (!$ConnectPhoto) {
    $ConnectPhoto = '/applications/dashboard/design/images/usericon.gif';
}
$ConnectSource = $this->Form->GetFormValue('ProviderName');
?>
<div class="Connect">
	<h1><?php 
echo StringIsNullOrEmpty($ConnectSource) ? T("Sign in") : sprintf(T('%s Connect'), $ConnectSource);
?>
</h1>
	<div>
	<?php 
echo $this->Form->Open();
echo $this->Form->Errors();
if ($ConnectName || $ConnectPhoto) {
    ?>
		<div class="MeBox">
			<?php 
    if ($ConnectPhoto) {
        echo '<span class="PhotoWrap">', Img($ConnectPhoto, array('alt' => T('Profile Picture'), 'class' => 'ProfilePhoto')), '</span>';
    }
    echo '<div class="WhoIs">';
    if ($ConnectName && $ConnectSource) {
   /**
    * Returns an update statement for the specified table with the provided
    * $Data.
    *
    * @param array $Tables The name of the table to updated data in.
    * @param array $Data An associative array of FieldName => Value pairs that should be inserted
    * $Table.
    * @param mixed $Where A where clause (or array containing multiple where clauses) to be applied
    * to the where portion of the update statement.
    */
   public function GetUpdate($Tables, $Data, $Where) {
      if (!is_array($Data))
         trigger_error(ErrorMessage('The data provided is not in a proper format (Array).', 'MySQLDriver', '_GetUpdate'), E_USER_ERROR);

      $Sets = array();
      foreach($Data as $Field => $Value) {
         $Sets[] = $Field." = ".$Value;
      }

      $sql = 'update '.$this->_FromTables($Tables);

      if (count($this->_Joins) > 0) {
         $sql .= "\n";
         
         $Join = $this->_Joins[count($this->_Joins) - 1];
   
         $sql .= implode("\n", $this->_Joins);
      }

      $sql .= " set \n ".implode(",\n ", $Sets);
      if (is_array($Where) && count($Where) > 0) {
         $sql .= "\nwhere ".implode("\n ", $Where);

         // Close any where groups that were left open.
         for ($i = 0; $i < $this->_OpenWhereGroupCount; ++$i) {
            $sql .= ')';
         }
         $this->_OpenWhereGroupCount = 0;
      } else if (is_string($Where) && !StringIsNullOrEmpty($Where)) {
         $sql .= ' where '.$Where;
      }
      return $sql;
   }
 /**
  * Validate tags when saving a discussion.
  */
 public function DiscussionModel_BeforeSaveDiscussion_Handler($Sender, $Args)
 {
     $FormPostValues = GetValue('FormPostValues', $Args, array());
     $TagsString = trim(strtolower(GetValue('Tags', $FormPostValues, '')));
     $NumTagsMax = C('Plugin.Tagging.Max', 5);
     // Tags can only contain unicode and the following ASCII: a-z 0-9 + # _ .
     if (StringIsNullOrEmpty($TagsString) && C('Plugins.Tagging.Required')) {
         $Sender->Validation->AddValidationResult('Tags', 'You must specify at least one tag.');
     } else {
         $Tags = TagModel::SplitTags($TagsString);
         if (!TagModel::ValidateTags($Tags)) {
             $Sender->Validation->AddValidationResult('Tags', '@' . T('ValidateTag', 'Tags cannot contain commas.'));
         } elseif (count($Tags) > $NumTagsMax) {
             $Sender->Validation->AddValidationResult('Tags', '@' . sprintf(T('You can only specify up to %s tags.'), $NumTagsMax));
         } else {
         }
     }
 }
Example #14
0
        ?>
      <li id="Conversation_<?php 
        echo $Row['ConversationID'];
        ?>
" class="Item">
         <?php 
        $JumpToItem = $Row['CountMessages'] - $Row['CountNewMessages'];
        $Url = "/messages/{$Row['ConversationID']}/#Item_{$JumpToItem}";
        if ($SubjectsVisible && $Row['Subject']) {
            $Message = htmlspecialchars($Row['Title']);
        } elseif ($Row['Format'] == 'Text') {
            $Message = SliceString(Gdn_Format::To($Row['LastMessage'], $Conversation['Format']), 100);
        } else {
            $Message = SliceString(Gdn_Format::Text(Gdn_Format::To($Row['LastMessage'], $Row['Format']), FALSE), 100);
        }
        if (StringIsNullOrEmpty(trim($Message))) {
            $Message = T('Blank Message');
        }
        echo Anchor($Message, $Url, 'ConversationLink');
        ?>
         <div class="Meta">
            <span class="MItem Participants">
               <?php 
        $First = TRUE;
        foreach ($Row['Participants'] as $User) {
            if ($First) {
                $First = FALSE;
            } else {
                echo ', ';
            }
            if ($User['UserID'] == Gdn::Session()->UserID) {
 /** 
  * Show activity feed for this user.
  *
  * @since 2.0.0
  * @access public
  * @param mixed $UserReference Unique identifier, possible ID or username.
  * @param string $Username Username.
  * @param int $UserID Unique ID.
  * @param int $Offset How many to skip (for paging).
  */
 public function Activity($UserReference = '', $Username = '', $UserID = '', $Offset = '0')
 {
     $this->Permission('Garden.Profiles.View');
     // Object setup
     $Session = Gdn::Session();
     $this->ActivityModel = new ActivityModel();
     // Calculate offset
     $Offset = is_numeric($Offset) ? $Offset : 0;
     if ($Offset < 0) {
         $Offset = 0;
     }
     // Get user, tab, and comment
     $this->GetUserInfo($UserReference, $Username, $UserID);
     $this->SetTabView('Activity');
     $Comment = $this->Form->GetFormValue('Comment');
     if ($Session->UserID > 0 && $this->Form->AuthenticatedPostBack() && !StringIsNullOrEmpty($Comment) && CheckPermission('Garden.Profiles.Edit')) {
         // Active user has submitted a comment
         $Comment = substr($Comment, 0, 1000);
         // Limit to 1000 characters...
         // Update About if necessary.
         $SendNotification = TRUE;
         if ($Session->UserID == $this->User->UserID) {
             $SendNotification = FALSE;
             $this->UserModel->SaveAbout($Session->UserID, $Comment);
             $this->User->About = $Comment;
             $this->SetJson('UserData', $this->FetchView('user'));
             $ActivityUserID = $Session->UserID;
             $RegardingUserID = $ActivityUserID;
             $ActivityType = 'AboutUpdate';
         } else {
             $ActivityUserID = $this->User->UserID;
             $RegardingUserID = $Session->UserID;
             $ActivityType = 'WallPost';
         }
         // Create activity entry
         $NewActivityID = $this->ActivityModel->Add($ActivityUserID, $ActivityType, $Comment, $RegardingUserID, '', '/profile/' . $this->ProfileUrl(), FALSE);
         // @todo Add a notification too.
         if ($this->_DeliveryType === DELIVERY_TYPE_ALL) {
             Redirect('dashboard/profile/' . $this->ProfileUrl());
         } else {
             // Load just the single new comment
             $this->HideActivity = TRUE;
             $this->ActivityData = $this->ActivityModel->GetWhere('ActivityID', $NewActivityID);
             $this->View = 'activities';
             $this->ControllerName = 'activity';
         }
     } else {
         // Load data to display
         $this->ProfileUserID = $this->User->UserID;
         $Limit = 50;
         $this->SetData('ActivityData', $this->ActivityModel->Get($this->User->UserID, $Offset, $Limit), TRUE);
         $TotalRecords = $this->ActivityModel->GetCount($this->User->UserID);
         if ($this->ActivityData->NumRows() > 0) {
             $ActivityData = $this->ActivityData->Result();
             $ActivityIDs = ConsolidateArrayValuesByKey($ActivityData, 'ActivityID');
             $LastActivity = $this->ActivityData->FirstRow();
             $LastModifiedDate = Gdn_Format::ToTimestamp($this->User->DateUpdated);
             $LastActivityDate = Gdn_Format::ToTimestamp($LastActivity->DateInserted);
             if ($LastModifiedDate < $LastActivityDate) {
                 $LastModifiedDate = $LastActivityDate;
             }
             // Make sure to only query this page if the user has no new activity since the requesting browser last saw it.
             $this->SetLastModified($LastModifiedDate);
             $this->CommentData = $this->ActivityModel->GetComments($ActivityIDs);
         } else {
             $this->CommentData = FALSE;
         }
         // Build a pager
         $PagerFactory = new Gdn_PagerFactory();
         $this->Pager = $PagerFactory->GetPager('MorePager', $this);
         $this->Pager->MoreCode = 'More';
         $this->Pager->LessCode = 'Newer Activity';
         $this->Pager->ClientID = 'Pager';
         $this->Pager->Configure($Offset, $Limit, $TotalRecords, 'profile/activity/' . $this->User->UserID . '/' . Gdn_Format::Url($this->User->Name) . '/' . $this->User->UserID . '/%1$s/');
         // 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'));
             if ($Offset > 0) {
                 $this->View = 'activities';
                 $this->ControllerName = 'Activity';
             }
         }
     }
     // Set the canonical Url.
     if (is_numeric($this->User->Name) || Gdn_Format::Url($this->User->Name) != strtolower($this->User->Name)) {
         $this->CanonicalUrl(Url('profile/' . $this->User->UserID . '/' . Gdn_Format::Url($this->User->Name), TRUE));
     } else {
         $this->CanonicalUrl(Url('profile/' . strtolower($this->User->Name), TRUE));
     }
     $this->Render();
 }
Example #16
0
 public function DiscussionController_AfterCommentMeta_Handler($Sender)
 {
     //		if (!C('Plugins.Voting.Enabled'))
     //			return;
     /*
     		echo '<span class="Votes">';
     			$Session = Gdn::Session();
     			$Object = GetValue('Object', $Sender->EventArguments);
     			$VoteType = $Sender->EventArguments['Type'] == 'Discussion' ? 'votediscussion' : 'votecomment';
     			$ID = $Sender->EventArguments['Type'] == 'Discussion' ? $Object->DiscussionID : $Object->CommentID;
     			$CssClass = '';
     			$VoteUpUrl = '/discussion/'.$VoteType.'/'.$ID.'/voteup/'.$Session->TransientKey().'/';
     			$VoteDownUrl = '/discussion/'.$VoteType.'/'.$ID.'/votedown/'.$Session->TransientKey().'/';
     			if (!$Session->IsValid()) {
     				$VoteUpUrl = Gdn::Authenticator()->SignInUrl($Sender->SelfUrl);
     				$VoteDownUrl = $VoteUpUrl;
     				$CssClass = ' SignInPopup';
     			}
     			echo Anchor(Wrap(Wrap('Vote Up', 'i'), 'i', array('class' => 'ArrowSprite SpriteUp', 'rel' => 'nofollow')), $VoteUpUrl, 'VoteUp'.$CssClass);
     			echo Wrap(StringIsNullOrEmpty($Object->Score) ? '0' : Gdn_Format::BigNumber($Object->Score));
     			echo Anchor(Wrap(Wrap('Vote Down', 'i'), 'i', array('class' => 'ArrowSprite SpriteDown', 'rel' => 'nofollow')), $VoteDownUrl, 'VoteDown'.$CssClass);
     		echo '</span>';
     */
     $Session = Gdn::Session();
     $Object = GetValue('Object', $Sender->EventArguments);
     $VoteType = $Sender->EventArguments['Type'] == 'Discussion' ? 'votediscussion' : 'votecomment';
     $ID = $Sender->EventArguments['Type'] == 'Discussion' ? $Object->DiscussionID : $Object->CommentID;
     $CssClass = '';
     $VoteUpUrl = '/discussion/' . $VoteType . '/' . $ID . '/voteup/' . $Session->TransientKey() . '/';
     $VoteDownUrl = '/discussion/' . $VoteType . '/' . $ID . '/votedown/' . $Session->TransientKey() . '/';
     if (!$Session->IsValid()) {
         $VoteUpUrl = Gdn::Authenticator()->SignInUrl($Sender->SelfUrl);
         $VoteDownUrl = $VoteUpUrl;
         $CssClass = ' SignInPopup';
     }
     echo '<span class="Voter">';
     echo Anchor(Wrap(Wrap('Vote Up', 'i'), 'i', array('class' => 'ArrowSprite SpriteUp', 'rel' => 'nofollow')), $VoteUpUrl, 'VoteUp' . $CssClass);
     echo Wrap(StringIsNullOrEmpty($Object->Score) ? '0' : Gdn_Format::BigNumber($Object->Score));
     echo Anchor(Wrap(Wrap('Vote Down', 'i'), 'i', array('class' => 'ArrowSprite SpriteDown', 'rel' => 'nofollow')), $VoteDownUrl, 'VoteDown' . $CssClass);
     echo '</span>';
 }
 /**
  * Default activity stream.
  * 
  * @since 2.0.0
  * @access public
  * @todo Validate comment length rather than truncating.
  * 
  * @param int $RoleID Unique ID of role to limit activity to.
  * @param int $Offset Number of activity items to skip.
  */
 public function Index($RoleID = '', $Offset = FALSE) {
    $this->Permission('Garden.Activity.View');
    
    // Limit to specific RoleIDs?
    if ($RoleID == 0)
       $RoleID = '';
       
    if ($RoleID != '')
       $RoleID = explode(',', $RoleID);
       
    // Which page to load
    $Offset = is_numeric($Offset) ? $Offset : 0;
    if ($Offset < 0)
       $Offset = 0;
    
    // Page meta
    $this->AddJsFile('jquery.gardenmorepager.js');
    $this->AddJsFile('activity.js');
    $this->Title(T('Recent Activity'));
    
    // Comment submission 
    $Session = Gdn::Session();
    $Comment = $this->Form->GetFormValue('Comment');
    $this->CommentData = FALSE;
    if ($Session->UserID > 0 && $this->Form->AuthenticatedPostBack() && !StringIsNullOrEmpty($Comment)) {
       $Comment = substr($Comment, 0, 1000); // Limit to 1000 characters...
       
       // Update About if necessary
       $ActivityType = 'WallComment';
       $NewActivityID = $this->ActivityModel->Add(
          $Session->UserID,
          $ActivityType,
          $Comment);
       
       if ($this->_DeliveryType === DELIVERY_TYPE_ALL) {
          Redirect('activity');
       } else {
          // Load just the single new comment
          $this->HideActivity = TRUE;
          $this->ActivityData = $this->ActivityModel->GetWhere('ActivityID', $NewActivityID);
          $this->View = 'activities';
       }
    } else {
       $Limit = 50;
       $this->ActivityData = is_array($RoleID) ? $this->ActivityModel->GetForRole($RoleID, $Offset, $Limit) : $this->ActivityModel->Get('', $Offset, $Limit);
       $TotalRecords = is_array($RoleID) ? $this->ActivityModel->GetCountForRole($RoleID) : $this->ActivityModel->GetCount();
       if ($this->ActivityData->NumRows() > 0) {
          $ActivityData = $this->ActivityData->ResultArray();
          $ActivityIDs = ConsolidateArrayValuesByKey($ActivityData, 'ActivityID');
          $this->CommentData = $this->ActivityModel->GetComments($ActivityIDs);
       }
       $this->View = 'all';
       
       // Build a pager
       $PagerFactory = new Gdn_PagerFactory();
       $this->Pager = $PagerFactory->GetPager('MorePager', $this);
       $this->Pager->MoreCode = 'More';
       $this->Pager->LessCode = 'Newer Activity';
       $this->Pager->ClientID = 'Pager';
       $this->Pager->Configure(
          $Offset,
          $Limit,
          $TotalRecords,
          'activity/'.(is_array($RoleID) ? implode(',', $RoleID) : '0').'/%1$s/%2$s/'
       );
       
       // 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 = 'activities';
       }
    }
    
    // Add RecentUser module
    $RecentUserModule = new RecentUserModule($this);
    $RecentUserModule->GetData();
    $this->AddModule($RecentUserModule);
    
    $this->SetData('ActivityData', $this->ActivityData);
    
    $this->Render();
 }
Example #18
0
 /**
  * Validate tags when saving a discussion.
  */
 public function DiscussionModel_BeforeSaveDiscussion_Handler($Sender)
 {
     if (!C('Plugins.Tagging.Enabled')) {
         return;
     }
     $FormPostValues = GetValue('FormPostValues', $Sender->EventArguments, array());
     $Tags = trim(strtolower(GetValue('Tags', $FormPostValues, '')));
     // Tags can only contain: a-z 0-9 + # _ .
     if (StringIsNullOrEmpty($Tags) && C('Plugins.Tagging.Required')) {
         $Sender->Validation->AddValidationResult('Tags', 'You must specify at least one tag.');
     } else {
         if (!StringIsNullOrEmpty($Tags) && !ValidateRegex($Tags, '/^([\\s\\d\\w\\+-_.#]+)$/si')) {
             $Sender->Validation->AddValidationResult('Tags', 'Tags can only contain the following characters: a-z 0-9 + # _ .');
         } else {
             if (count(array_unique(explode(' ', $Tags))) > 5) {
                 $Sender->Validation->AddValidationResult('Tags', 'You can only specify up to 5 tags.');
             }
         }
     }
 }