function WriteActivity($Activity, &$Sender, &$Session, $Comment) { $Activity = (object) $Activity; // If this was a status update or a wall comment, don't bother with activity strings $ActivityType = explode(' ', $Activity->ActivityType); // Make sure you strip out any extra css classes munged in here $ActivityType = $ActivityType[0]; $Author = UserBuilder($Activity, 'Activity'); $PhotoAnchor = UserPhoto($Author, 'Photo'); $CssClass = 'Item Activity ' . $ActivityType; if ($PhotoAnchor != '') { $CssClass .= ' HasPhoto'; } if (in_array($ActivityType, array('WallComment', 'WallPost', 'AboutUpdate'))) { $CssClass .= ' Condensed'; } $Title = ''; $Excerpt = $Activity->Story; if (!in_array($ActivityType, array('WallComment', 'WallPost', 'AboutUpdate'))) { $Title = '<div class="Title">' . Gdn_Format::ActivityHeadline($Activity, $Sender->ProfileUserID) . '</div>'; } else { if ($ActivityType == 'WallPost') { $RegardingUser = UserBuilder($Activity, 'Regarding'); $PhotoAnchor = UserPhoto($RegardingUser); $Title = '<div class="Title">' . UserAnchor($RegardingUser, 'Name') . ' <span>→</span> ' . UserAnchor($Author, 'Title Name') . '</div>'; $Excerpt = Gdn_Format::Display($Excerpt); } else { $Title = UserAnchor($Author, 'Title Name'); $Excerpt = Gdn_Format::Display($Excerpt); } } $Sender->EventArguments['Activity'] =& $Activity; $Sender->EventArguments['CssClass'] =& $CssClass; $Sender->FireEvent('BeforeActivity'); ?> <li id="Activity_<?php echo $Activity->ActivityID; ?> " class="<?php echo $CssClass; ?> "> <?php if ($Session->IsValid() && ($Session->UserID == $Activity->InsertUserID || $Session->CheckPermission('Garden.Activity.Delete'))) { echo '<div class="OptionButton">' . Anchor(T('Activity.Delete', 'Delete'), 'dashboard/activity/delete/' . $Activity->ActivityID . '/' . $Session->TransientKey() . '?Target=' . urlencode($Sender->SelfUrl), 'Delete') . '</div>'; } if ($PhotoAnchor != '') { ?> <div class="Author Photo"><?php echo $PhotoAnchor; ?> </div> <?php } ?> <div class="ItemContent Activity"> <?php echo $Title; ?> <div class="Excerpt"><?php echo $Excerpt; ?> </div> <div class="Meta"> <span class="DateCreated"><?php echo Gdn_Format::Date($Activity->DateInserted); ?> </span> <?php if ($Activity->AllowComments == '1' && $Session->IsValid()) { echo '<span class="AddComment">' . Anchor(T('Activity.Comment', 'Comment'), '#CommentForm_' . $Activity->ActivityID, 'CommentOption') . '</span>'; } $Sender->FireEvent('AfterMeta'); ?> </div> </div> <?php if ($Activity->AllowComments == '1') { // If there are comments, show them $FoundComments = FALSE; if (property_exists($Sender, 'CommentData') && is_object($Sender->CommentData)) { foreach ($Sender->CommentData->Result() as $Comment) { if (is_object($Comment) && $Comment->CommentActivityID == $Activity->ActivityID) { if ($FoundComments == FALSE) { echo '<ul class="DataList ActivityComments">'; } $FoundComments = TRUE; WriteActivityComment($Comment, $Sender, $Session); } } } if ($FoundComments == FALSE) { echo '<ul class="DataList ActivityComments Hidden">'; } if ($Session->IsValid()) { ?> <li class="CommentForm"> <?php echo Anchor(T('Write a comment'), '/dashboard/activity/comment/' . $Activity->ActivityID, 'CommentLink'); $CommentForm = Gdn::Factory('Form'); $CommentForm->SetModel($Sender->ActivityModel); $CommentForm->AddHidden('ActivityID', $Activity->ActivityID); $CommentForm->AddHidden('Return', Gdn_Url::Request()); echo $CommentForm->Open(array('action' => Url('/dashboard/activity/comment'), 'class' => 'Hidden')); echo $CommentForm->TextBox('Body', array('MultiLine' => TRUE, 'value' => '')); echo $CommentForm->Close('Comment'); ?> </li> <?php } ?> </ul> <?php } ?> </li> <?php }
/** * Queue a notification for sending. * * @since 2.0.17 * @access public * @param int $ActivityID * @param string $Story * @param string $Position * @param bool $Force */ public function QueueNotification($ActivityID, $Story = '', $Position = 'last', $Force = FALSE) { $Activity = $this->GetID($ActivityID); if (!is_object($Activity)) { return; } $Story = Gdn_Format::Text($Story == '' ? $Activity->Story : $Story, FALSE); // 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 = '/activity/item/' . $Activity->CommentActivityID; } $User = Gdn::UserModel()->GetID($Activity->RegardingUserID, DATASET_TYPE_OBJECT); //$this->SQL->Select('UserID, Name, Email, Preferences')->From('User')->Where('UserID', $Activity->RegardingUserID)->Get()->FirstRow(); if ($User) { if ($Force) { $Preference = $Force; } else { // $Preferences = Gdn_Format::Unserialize($User->Preferences); $ConfigPreference = C('Preferences.Email.' . $Activity->ActivityType, '0'); if ($ConfigPreference !== FALSE) { $Preference = GetValue('Email.' . $Activity->ActivityType, $User->Preferences, $ConfigPreference); } else { $Preference = FALSE; } } if ($Preference) { $ActivityHeadline = Gdn_Format::Text(Gdn_Format::ActivityHeadline($Activity, $Activity->ActivityUserID, $Activity->RegardingUserID), FALSE); $Email = new Gdn_Email(); $Email->Subject(sprintf(T('[%1$s] %2$s'), Gdn::Config('Garden.Title'), $ActivityHeadline)); $Email->To($User); $Message = sprintf($Story == '' ? T('EmailNotification', "%1\$s\n\n%2\$s") : T('EmailStoryNotification', "%3\$s\n\n%2\$s"), $ActivityHeadline, ExternalUrl($Activity->Route == '' ? '/' : $Activity->Route), $Story); $Email->Message($Message); if (!array_key_exists($User->UserID, $this->_NotificationQueue)) { $this->_NotificationQueue[$User->UserID] = array(); } $Notification = array('ActivityID' => $ActivityID, 'User' => $User, 'Email' => $Email, 'Route' => $Activity->Route, 'Story' => $Story, 'Headline' => $ActivityHeadline, 'Activity' => $Activity); if ($Position == 'first') { $this->_NotificationQueue[$User->UserID] = array_merge(array($Notification), $this->_NotificationQueue[$User->UserID]); } else { $this->_NotificationQueue[$User->UserID][] = $Notification; } } } }
/** * Queue a notification for sending. */ public function QueueNotification($ActivityID, $Story = '') { $Activity = $this->GetID($ActivityID); if (!is_object($Activity)) { return; } $Story = Gdn_Format::Text($Story == '' ? $Activity->Story : $Story, FALSE); // 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 . '/' . Gdn_Format::Url($CommentActivity->RegardingName) . '/#Activity_' . $Activity->CommentActivityID; } $User = $this->SQL->Select('UserID, Name, Email, Preferences')->From('User')->Where('UserID', $Activity->RegardingUserID)->Get()->FirstRow(); if ($User) { $Preferences = Gdn_Format::Unserialize($User->Preferences); $Preference = ArrayValue('Email.' . $Activity->ActivityType, $Preferences, Gdn::Config('Preferences.Email.' . $Activity->ActivityType)); if ($Preference) { $ActivityHeadline = Gdn_Format::Text(Gdn_Format::ActivityHeadline($Activity, $Activity->ActivityUserID, $Activity->RegardingUserID), FALSE); $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)); if (!array_key_exists($User->UserID, $this->_NotificationQueue)) { $this->_NotificationQueue[$User->UserID] = array(); } $this->_NotificationQueue[$User->UserID][] = array('ActivityID' => $ActivityID, 'User' => $User, 'Email' => $Email); } } }
echo '<li class="Activity ' . $Activity->ActivityType . '">'; // If this was a status update or a wall comment, don't bother with activity strings $ActivityType = explode(' ', $Activity->ActivityType); // Make sure you strip out any extra css classes munged in here $ActivityType = $ActivityType[0]; $Author = UserBuilder($Activity, 'Activity'); if (in_array($ActivityType, array('WallComment', 'AboutUpdate'))) { echo UserAnchor($Author, 'Name'); if ($Activity->ActivityType == 'WallComment' && $Activity->RegardingUserID > 0) { $Author = UserBuilder($Activity, 'Regarding'); echo '<span>→</span>' . UserAnchor($Author, 'Name'); } echo ' ' . Gdn_Format::Display($Activity->Story) . ' '; echo '<em>' . Gdn_Format::Date($Activity->DateInserted) . '</em>'; } else { echo Gdn_Format::ActivityHeadline($Activity); echo '<em>' . Gdn_Format::Date($Activity->DateInserted) . '</em>'; if ($Activity->Story != '') { echo '<div class="Story">'; echo $Activity->Story; echo '</div>'; } } echo '</li>'; } ?> <li class="ShowAll"><?php echo Anchor(T('↳ Show All'), 'activity/' . implode(',', $this->_RoleID)); ?> </li> </ul>
/** * Grabs all new notifications and adds them to the sender's inform queue. * * This method gets called by dashboard's hooks file to display new * notifications on every pageload. * * @since 2.0.18 * @access public * * @param object $Sender The object calling this method. */ public static function InformNotifications($Sender) { $Session = Gdn::Session(); if (!$Session->IsValid()) { return; } // Set the user's DateLastInform attribute to now. This value can be used // by addons to determine if their inform messages have already been sent. $InformLastActivityID = $Session->GetAttribute('Notifications.InformLastActivityID', 0); // Allow pluggability $Sender->EventArguments['InformLastActivityID'] =& $InformLastActivityID; $Sender->FireEvent('BeforeInformNotifications'); // Retrieve default preferences $Preferences = array(); $DefaultPreferences = C('Preferences.Popup', array()); foreach ($DefaultPreferences as $Preference => $Val) { if ($Val) { $Preferences[] = $Preference; } } // $User = Gdn::Database()->SQL()->Select('Preferences')->From('User')->Where('UserID', $Session->UserID)->Get()->FirstRow(); // if ($User) { // $PrefData = Gdn_Format::Unserialize($User->Preferences); // foreach ($PrefData as $Pref => $Val) { // if (substr($Pref, 0, 6) == 'Popup.') { // $Pref = substr($Pref, 6); // if ($Val) { // $Preferences[] = $Pref; // } else { // if (in_array($Pref, $Preferences)) // unset($Preferences[array_search($Pref, $Preferences)]); // } // } // } // } // if (count($Preferences) > 0) { // Grab the activity type ids for the desired notification prefs. $ActivityTypeIDs = array(); // $ActivityTypes = array(); $Data = Gdn::Database()->SQL()->GetWhere('ActivityType', array('Notify' => TRUE))->ResultArray(); // ->WhereIn('Name', $Preferences)->Get(); foreach ($Data as $ActivityType) { if (Gdn::Session()->GetPreference("Popup.{$ActivityType['Name']}", C("Preferences.Popup.{$ActivityType['Name']}", TRUE))) { $ActivityTypeIDs[] = $ActivityType['ActivityTypeID']; // $ActivityTypes[] = $ActivityType['Name']; } } if (count($ActivityTypeIDs) > 0) { // Retrieve new notifications $ActivityModel = new ActivityModel(); $NotificationData = $ActivityModel->GetNotificationsSince($Session->UserID, $InformLastActivityID, $ActivityTypeIDs); $InformLastActivityID = -1; // Add (no more than 5) notifications to the inform stack foreach ($NotificationData->Result() as $Notification) { // Make sure the user wants to be notified of this // if (!in_array($Notification->ActivityType, $Preferences)) { // continue; // } $UserPhoto = UserPhoto(UserBuilder($Notification, 'Activity'), 'Icon'); $ActivityType = explode(' ', $Notification->ActivityType); $ActivityType = $ActivityType[0]; $Excerpt = $Notification->Story; if (in_array($ActivityType, array('WallComment', 'AboutUpdate'))) { $Excerpt = Gdn_Format::Display($Excerpt); } // Inform the user of new messages $Sender->InformMessage($UserPhoto . Wrap(Gdn_Format::ActivityHeadline($Notification, $Session->UserID), 'div', array('class' => 'Title')) . Wrap($Excerpt, 'div', array('class' => 'Excerpt')), 'Dismissable AutoDismiss' . ($UserPhoto == '' ? '' : ' HasIcon')); // Assign the most recent activity id if ($InformLastActivityID == -1) { $InformLastActivityID = $Notification->ActivityID; } } } // } if ($InformLastActivityID > 0) { Gdn::UserModel()->SaveAttribute($Session->UserID, 'Notifications.InformLastActivityID', $InformLastActivityID); } }