/** * Prompts new admins how to get started using new install. * * @since 2.0.0 * @access public */ public function GettingStarted() { $this->Permission('Garden.Settings.Manage'); $this->SetData('Title', T('Getting Started')); $this->AddSideMenu('dashboard/settings/gettingstarted'); $this->TextEnterEmails = T('TextEnterEmails', 'Type email addresses separated by commas here'); if ($this->Form->AuthenticatedPostBack()) { // Do invitations to new members. $Message = $this->Form->GetFormValue('InvitationMessage'); $Message .= "\n\n" . Gdn::Request()->Url('/', TRUE); $Message = trim($Message); $Recipients = $this->Form->GetFormValue('Recipients'); if ($Recipients == $this->TextEnterEmails) { $Recipients = ''; } $Recipients = explode(',', $Recipients); $CountRecipients = 0; foreach ($Recipients as $Recipient) { if (trim($Recipient) != '') { $CountRecipients++; if (!ValidateEmail($Recipient)) { $this->Form->AddError(sprintf(T('%s is not a valid email address'), $Recipient)); } } } if ($CountRecipients == 0) { $this->Form->AddError(T('You must provide at least one recipient')); } if ($this->Form->ErrorCount() == 0) { $Email = new Gdn_Email(); $Email->Subject(T('Check out my new community!')); $Email->Message($Message); foreach ($Recipients as $Recipient) { if (trim($Recipient) != '') { $Email->To($Recipient); try { $Email->Send(); } catch (Exception $ex) { $this->Form->AddError($ex); } } } } if ($this->Form->ErrorCount() == 0) { $this->InformMessage(T('Your invitations were sent successfully.')); } } $this->Render(); }
/** * 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; } } } }
public function PasswordRequest($Email) { $User = $this->GetWhere(array('Email' => $Email))->FirstRow(); if (!is_object($User) || $Email == '') { return FALSE; } $PasswordResetKey = RandomString(6); $this->SaveAttribute($User->UserID, 'PasswordResetKey', $PasswordResetKey); $AppTitle = Gdn::Config('Garden.Title'); $Email = new Gdn_Email(); $Email->Subject(sprintf(T('[%s] Password Reset Request'), $AppTitle)); $Email->To($User->Email); //$Email->From(Gdn::Config('Garden.Support.Email'), Gdn::Config('Garden.Support.Name')); $Email->Message(sprintf(T('PasswordRequest'), $User->Name, $AppTitle, Url('/entry/passwordreset/' . $User->UserID . '/' . $PasswordResetKey, TRUE))); $Email->Send(); return TRUE; }
/** * 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); } } }
public function Send($InvitationID) { $Invitation = $this->GetByInvitationID($InvitationID); $Session = Gdn::Session(); if ($Invitation === FALSE) { throw new Exception(T('ErrorRecordNotFound')); } else { if ($Session->UserID != $Invitation->SenderUserID) { throw new Exception(T('ErrorPermission')); } else { // Some information for the email $RegistrationUrl = CombinePaths(array(Gdn::Request()->WebPath(TRUE, FALSE), 'entry', 'register', $Invitation->Code), '/'); $AppTitle = Gdn::Config('Garden.Title'); $Email = new Gdn_Email(); $Email->Subject(sprintf(T('[%s] Invitation'), $AppTitle)); $Email->To($Invitation->Email); $Email->From($Invitation->SenderEmail, $Invitation->SenderName); $Email->Message(sprintf(T('EmailInvitation'), $Invitation->SenderName, $AppTitle, $RegistrationUrl)); $Email->Send(); } } }
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. } } } }
private function SendNotification($Sender, $IsDiscussion) { $Session = Gdn::Session(); # don't send on edit if ($Sender->RequestMethod == 'editdiscussion' || $Sender->RequestMethod == 'editcomment') { return; } # discussion info $UserName = $Session->User->Name; $DiscussionID = $Sender->EventArguments['Discussion']->DiscussionID; $DiscussionName = $Sender->EventArguments['Discussion']->Name; $ScriptID = $Sender->EventArguments['Discussion']->ScriptID; # no script - do nothing if (!isset($ScriptID) || !is_numeric($ScriptID)) { return; } # look up the user we might e-mail $DiscussionModel = new DiscussionModel(); $prefix = $DiscussionModel->SQL->Database->DatabasePrefix; $DiscussionModel->SQL->Database->DatabasePrefix = ''; $UserInfo = $DiscussionModel->SQL->Select('u.author_email_notification_type_id, u.email, u.name, s.default_name script_name, u.id, ua.UserID forum_user_id')->From('scripts s')->Join('users u', 's.user_id = u.id')->Join('GDN_UserAuthentication ua', 'ua.ForeignUserKey = u.id')->Where('s.id', $ScriptID)->Get()->NextRow(DATASET_TYPE_ARRAY); $DiscussionModel->SQL->Database->DatabasePrefix = $prefix; $NotificationPreference = $UserInfo['author_email_notification_type_id']; # 1: no notifications # 2: new discussions # 3: new discussions and comments # no notifications if ($NotificationPreference != 2 && $NotificationPreference != 3) { return; } # discussions only if ($NotificationPreference == 2 && !$IsDiscussion) { return; } # don't self-notify if ($UserInfo['forum_user_id'] == $Session->User->UserID) { return; } $NotificationEmail = $UserInfo['email']; $NotificationName = $UserInfo['name']; $ScriptName = $UserInfo['script_name']; if ($IsDiscussion) { $ActivityHeadline = $UserName . ' started a discussion on ' . $ScriptName; } else { $ActivityHeadline = $UserName . ' commented on a discussion about ' . $ScriptName; } $UserId = $UserInfo['id']; $AccountUrl = 'https://greasyfork.org/users/' . $UserId; $Email = new Gdn_Email(); $Email->Subject(sprintf(T('[%1$s] %2$s'), Gdn::Config('Garden.Title'), $ActivityHeadline)); $Email->To($NotificationEmail, $NotificationName); if ($IsDiscussion) { $Email->Message(sprintf("%s started a discussion '%s' on your script '%s'. Check it out: %s\n\nYou can change your notification settings on your Greasy Fork account page at %s", $UserName, $DiscussionName, $ScriptName, Url('/discussion/' . $DiscussionID . '/' . Gdn_Format::Url($DiscussionName), TRUE), $AccountUrl)); } else { $Email->Message(sprintf("%s commented on the discussion '%s' on your script '%s'. Check it out: %s\n\nYou can change your notification settings on your Greasy Fork account page at %s", $UserName, $DiscussionName, $ScriptName, Url('/discussion/' . $DiscussionID . '/' . Gdn_Format::Url($DiscussionName), TRUE), $AccountUrl)); } #print_r($Email); #die; try { $Email->Send(); } catch (Exception $ex) { # report but keep going echo $ex; } }
public function PasswordRequest($Email) { if (!$Email) { return FALSE; } $Users = $this->GetWhere(array('Email' => $Email))->ResultObject(); if (count($Users) == 0) { // Check for the username. $Users = $this->GetWhere(array('Name' => $Email))->ResultObject(); } $this->EventArguments['Users'] =& $Users; $this->EventArguments['Email'] = $Email; $this->FireEvent('BeforePasswordRequest'); if (count($Users) == 0) { $this->Validation->AddValidationResult('Name', "Couldn't find an account associated with that email/username."); return FALSE; } $Email = new Gdn_Email(); $NoEmail = TRUE; foreach ($Users as $User) { if (!$User->Email) { continue; } $PasswordResetKey = RandomString(6); $this->SaveAttribute($User->UserID, 'PasswordResetKey', $PasswordResetKey); $AppTitle = C('Garden.Title'); $Email->Subject(sprintf(T('[%s] Password Reset Request'), $AppTitle)); $Email->To($User->Email); $Email->Message(sprintf(T('PasswordRequest'), $User->Name, $AppTitle, ExternalUrl('/entry/passwordreset/' . $User->UserID . '/' . $PasswordResetKey))); $Email->Send(); $NoEmail = FALSE; } if ($NoEmail) { $this->Validation->AddValidationResult('Name', 'There is no email address associated with that account.'); return FALSE; } return TRUE; }
public function PasswordRequest($Email) { if (!$Email) { return FALSE; } $Users = $this->GetWhere(array('Email' => $Email))->ResultObject(); if (count($Users) == 0 && C('Garden.Registration.NameUnique', 1)) { // Check for the username. $Users = $this->GetWhere(array('Name' => $Email))->ResultObject(); } $this->EventArguments['Users'] =& $Users; $this->EventArguments['Email'] = $Email; $this->FireEvent('BeforePasswordRequest'); if (count($Users) == 0) { return FALSE; } $Email = new Gdn_Email(); foreach ($Users as $User) { $PasswordResetKey = RandomString(6); $this->SaveAttribute($User->UserID, 'PasswordResetKey', $PasswordResetKey); $AppTitle = C('Garden.Title'); $Email->Subject(sprintf(T('[%s] Password Reset Request'), $AppTitle)); $Email->To($User->Email); $Email->Message(sprintf(T('PasswordRequest'), $User->Name, $AppTitle, ExternalUrl('/entry/passwordreset/' . $User->UserID . '/' . $PasswordResetKey))); $Email->Send(); } return TRUE; }
public function Send($InvitationID) { $Invitation = $this->GetByInvitationID($InvitationID); $Session = Gdn::Session(); if ($Invitation === FALSE) { throw new Exception(T('ErrorRecordNotFound')); } else { if ($Session->UserID != $Invitation->SenderUserID) { throw new Exception(T('InviteErrorPermission', T('ErrorPermission'))); } else { // Some information for the email $RegistrationUrl = ExternalUrl("entry/register/{$Invitation->Code}"); $AppTitle = Gdn::Config('Garden.Title'); $Email = new Gdn_Email(); $Email->Subject(sprintf(T('[%s] Invitation'), $AppTitle)); $Email->To($Invitation->Email); $Email->Message(sprintf(T('EmailInvitation'), $Invitation->SenderName, $AppTitle, $RegistrationUrl)); $Email->Send(); } } }