All public methods return $this for chaining purposes. ie. $Email->Subject('Hi')->Message('Just saying hi!')- To('joe@vanillaforums.com')->Send();
Inheritance: extends Gdn_Pluggable
コード例 #1
0
ファイル: functions.misc.php プロジェクト: ru4/arabbnota
 /** 
  * Send email message.
  */
 function SendEmailMessage($Recipient, $Subject, $Message, $Options = False)
 {
     $MimeType = ArrayValue('MimeType', $Options, 'text/plain');
     $SenderEmail = ArrayValue('SenderEmail', $Options, '');
     $SenderName = ArrayValue('SenderName', $Options, '');
     $Email = new Gdn_Email();
     $Result = $Email->From($SenderEmail, $SenderName)->MimeType($MimeType)->Subject($Subject)->To($Recipient)->Message($Message)->Send();
     return $Result;
 }
コード例 #2
0
ファイル: class.console.php プロジェクト: ru4/arabbnota
 public static function ErrorHandler($Error, $Message = '', $File = '', $Line = '')
 {
     if (error_reporting() == 0) {
         return False;
     }
     $Object = 'PHP';
     $Method = 'Function';
     if (is_object($Error)) {
         $Info = False;
         foreach ($Error->GetTrace() as $Info) {
             break;
         }
         $Method = ArrayValue('function', $Info, $Method);
         $Object = ArrayValue('class', $Info, $Object);
         $Message = $Error->GetMessage();
         $File = $Error->GetFile();
         $Line = $Error->GetLine();
         $Error = -1;
     }
     $File = str_replace(PATH_ROOT . DS, '', $File);
     switch ($Error) {
         case E_NOTICE:
             $Code = 'NOTICE';
             break;
         case E_WARNING:
             $Code = 'WARNING';
             break;
         case -1:
             $Code = 'UNCAUGHT EXCEPTION';
             break;
         default:
             $Code = 'ERROR';
     }
     $Message = strip_tags($Message);
     self::Message('%s: %s in %s on line %s', $Code, $Message, $File, $Line);
     self::Message($Message);
     LogMessage($File, $Line, $Object, $Method, $Message, $Code);
     // send error to email
     $To = Gdn::Config('Plugins.UsefulFunctions.Console.ErrorsEmailToAddress');
     if (self::Check() && $To != False) {
         $Text = sprintf(Gdn::Translate('Error in console script %1$s %2$s %3$s %4$s'), $Code, $Message, $File, $Line);
         if (!class_exists('Gdn_Email')) {
             return error_log("Error ({$Code})", 1, $To, $Text);
         }
         $Email = new Gdn_Email();
         $Email->To($To)->Message($Text)->Subject("Error ({$Code})")->Send('ErrorInConsoleScript');
     }
     exit;
 }
コード例 #3
0
 /**
  * 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;
             }
         }
     }
 }
コード例 #4
0
 /**
  * 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 = 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!'));
             $emailTemplate = $Email->getEmailTemplate();
             $emailTemplate->setMessage($Message, true)->setButton(externalUrl('/'), t('Check it out'));
             $Email->setEmailTemplate($emailTemplate);
             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();
 }
コード例 #5
0
 /**
  *
  *
  * @param $InvitationID
  * @throws Exception
  */
 public function send($InvitationID)
 {
     $Invitation = $this->GetByInvitationID($InvitationID);
     $Session = Gdn::session();
     if ($Invitation === false) {
         throw new Exception(t('ErrorRecordNotFound'));
     } elseif ($Session->UserID != $Invitation->SenderUserID) {
         throw new Exception(t('InviteErrorPermission', t('ErrorPermission')));
     } else {
         // Some information for the email
         $RegistrationUrl = ExternalUrl("entry/registerinvitation/{$Invitation->Code}");
         $AppTitle = Gdn::config('Garden.Title');
         $Email = new Gdn_Email();
         $Email->subject(sprintf(t('[%s] Invitation'), $AppTitle));
         $Email->to($Invitation->Email);
         $emailTemplate = $Email->getEmailTemplate();
         $message = t('Hello!') . ' ' . sprintf(t('%s has invited you to join %s.'), $Invitation->SenderName, $AppTitle);
         $emailTemplate->setButton($RegistrationUrl, t('Join this Community Now'))->setMessage($message)->setTitle(sprintf(t('Join %s'), $AppTitle));
         $Email->setEmailTemplate($emailTemplate);
         try {
             $Email->send();
         } catch (Exception $e) {
             if (debug()) {
                 throw $e;
             }
         }
     }
 }
コード例 #6
0
 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();
         }
     }
 }
コード例 #7
0
 /**
  * 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 = val('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);
             $url = externalUrl(val('Route', $Activity) == '' ? '/' : val('Route', $Activity));
             $emailTemplate = $Email->getEmailTemplate()->setButton($url, t('Check it out'))->setTitle(Gdn_Format::plainText(val('Headline', $Activity)));
             if ($message = val('Story', $Activity)) {
                 $emailTemplate->setMessage($message, true);
             }
             $Email->setEmailTemplate($emailTemplate);
             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;
             }
         }
     }
 }
コード例 #8
0
 /**
  * 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();
 }
コード例 #9
0
ファイル: class.usermodel.php プロジェクト: vanilla/vanilla
 /**
  * Send forgot password email.
  *
  * @param string $Email
  * @return bool
  */
 public function passwordRequest($Email)
 {
     if (!$Email) {
         return false;
     }
     $Users = $this->getWhere(['Email' => $Email])->resultObject();
     if (count($Users) == 0) {
         // Check for the username.
         $Users = $this->getWhere(['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;
     }
     $NoEmail = true;
     foreach ($Users as $User) {
         if (!$User->Email) {
             continue;
         }
         $Email = new Gdn_Email();
         // Instantiate in loop to clear previous settings
         $PasswordResetKey = betterRandomString(20, 'Aa0');
         $PasswordResetExpires = strtotime('+1 hour');
         $this->saveAttribute($User->UserID, 'PasswordResetKey', $PasswordResetKey);
         $this->saveAttribute($User->UserID, 'PasswordResetExpires', $PasswordResetExpires);
         $AppTitle = c('Garden.Title');
         $Email->subject('[' . $AppTitle . '] ' . t('Reset Your Password'));
         $Email->to($User->Email);
         $emailTemplate = $Email->getEmailTemplate()->setTitle(t('Reset Your Password'))->setMessage(sprintf(t('We\'ve received a request to change your password.'), $AppTitle))->setButton(externalUrl('/entry/passwordreset/' . $User->UserID . '/' . $PasswordResetKey), t('Change My Password'));
         $Email->setEmailTemplate($emailTemplate);
         try {
             $Email->send();
         } catch (Exception $e) {
             if (debug()) {
                 throw $e;
             }
         }
         $NoEmail = false;
     }
     if ($NoEmail) {
         $this->Validation->addValidationResult('Name', 'There is no email address associated with that account.');
         return false;
     }
     return true;
 }
コード例 #10
0
 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;
 }
コード例 #11
0
 /**
  * Sets up a new Gdn_Email object with a test email.
  *
  * @param string $image The img src of the previewed image
  * @param string $textColor The hex color code of the text.
  * @param string $backGroundColor The hex color code of the background color.
  * @param string $containerBackgroundColor The hex color code of the container background color.
  * @param string $buttonTextColor The hex color code of the link color.
  * @param string $buttonBackgroundColor The hex color code of the button background.
  * @return Gdn_Email The email object with the test colors set.
  */
 public function getTestEmail($image = '', $textColor = '', $backGroundColor = '', $containerBackgroundColor = '', $buttonTextColor = '', $buttonBackgroundColor = '')
 {
     $emailer = new Gdn_Email();
     $email = $emailer->getEmailTemplate();
     if ($image) {
         $email->setImage($image);
     }
     if ($textColor) {
         $email->setTextColor($textColor);
     }
     if ($backGroundColor) {
         $email->setBackgroundColor($backGroundColor);
     }
     if ($backGroundColor) {
         $email->setContainerBackgroundColor($containerBackgroundColor);
     }
     if ($buttonTextColor) {
         $email->setDefaultButtonTextColor($buttonTextColor);
     }
     if ($buttonBackgroundColor) {
         $email->setDefaultButtonBackgroundColor($buttonBackgroundColor);
     }
     $message = t('Test Email Message');
     $email->setMessage($message)->setTitle(t('Test Email'))->setButton(externalUrl('/'), t('Check it out'));
     $emailer->setEmailTemplate($email);
     return $emailer;
 }
コード例 #12
0
ファイル: class.usermodel.php プロジェクト: rnovino/Garden
 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;
 }
コード例 #13
0
 public function ReturEmailToSender($ErrorText = '')
 {
     $Email = new Gdn_Email();
     $Message = LocalizedMessage('ReturEmailToSender %1$s %2$s %3$s', $this->Subject, $this->BodyText, $ErrorText);
     $Email->To($this->SenderMail, $this->SenderName)->Subject('[Ошибка] ' . $this->Subject)->Message($Message)->Send();
     $this->Delete();
     return $this;
 }
コード例 #14
0
 protected function Send($EmailDataSet, $To, $Subject = False, $Message = False)
 {
     if (is_array($To)) {
         $RecipientEmailList = GetValue('RecipientEmailList', $To);
         $Subject = GetValue('Subject', $To);
         $Message = GetValue('Body', $To);
     }
     $Email = new Gdn_Email();
     foreach ($EmailDataSet as $RecipientEmail => $RecipientName) {
         $Email->Bcc($RecipientEmail, $RecipientName);
     }
     $Email->To($RecipientEmailList)->Subject($Subject)->Message($Message)->Send();
     return True;
 }
コード例 #15
0
 /**
  *
  *
  * @param $InvitationID
  * @throws Exception
  */
 public function send($InvitationID)
 {
     $Invitation = $this->GetByInvitationID($InvitationID);
     $Session = Gdn::session();
     if ($Invitation === false) {
         throw new Exception(t('ErrorRecordNotFound'));
     } elseif ($Session->UserID != $Invitation->SenderUserID) {
         throw new Exception(t('InviteErrorPermission', t('ErrorPermission')));
     } else {
         // Some information for the email
         $RegistrationUrl = ExternalUrl("entry/registerinvitation/{$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();
     }
 }
コード例 #16
0
ファイル: class.usermodel.php プロジェクト: RodSloan/vanilla
 /**
  * Send forgot password email.
  *
  * @param $Email
  * @return bool
  * @throws Exception
  */
 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;
     }
     $NoEmail = true;
     foreach ($Users as $User) {
         if (!$User->Email) {
             continue;
         }
         $Email = new Gdn_Email();
         // Instantiate in loop to clear previous settings
         $PasswordResetKey = BetterRandomString(20, 'Aa0');
         $PasswordResetExpires = strtotime('+1 hour');
         $this->saveAttribute($User->UserID, 'PasswordResetKey', $PasswordResetKey);
         $this->saveAttribute($User->UserID, 'PasswordResetExpires', $PasswordResetExpires);
         $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;
 }
コード例 #17
0
ファイル: default.php プロジェクト: DreamerKing/greasyfork
 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;
     }
 }
コード例 #18
0
ファイル: class.usermodel.php プロジェクト: TiGR/Garden
 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;
 }
コード例 #19
0
ファイル: class.activitymodel.php プロジェクト: nbudin/Garden
 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.
             }
         }
     }
 }
コード例 #20
0
 /**
  * Handle flagging process in a discussion.
  */
 public function DiscussionController_Flag_Create($Sender)
 {
     if (!C('Plugins.Flagging.Enabled')) {
         return;
     }
     // Signed in users only.
     if (!($UserID = Gdn::Session()->UserID)) {
         return;
     }
     $UserName = Gdn::Session()->User->Name;
     $Arguments = $Sender->RequestArgs;
     if (sizeof($Arguments) != 5) {
         return;
     }
     list($Context, $ElementID, $ElementAuthorID, $ElementAuthor, $EncodedURL) = $Arguments;
     $URL = base64_decode(str_replace('-', '=', $EncodedURL));
     $Sender->SetData('Plugin.Flagging.Data', array('Context' => $Context, 'ElementID' => $ElementID, 'ElementAuthorID' => $ElementAuthorID, 'ElementAuthor' => $ElementAuthor, 'URL' => $URL, 'UserID' => $UserID, 'UserName' => $UserName));
     if ($Sender->Form->AuthenticatedPostBack()) {
         $SQL = Gdn::SQL();
         $Comment = $Sender->Form->GetValue('Plugin.Flagging.Reason');
         $Sender->SetData('Plugin.Flagging.Reason', $Comment);
         $CreateDiscussion = C('Plugins.Flagging.UseDiscussions');
         if ($CreateDiscussion) {
             // Category
             $CategoryID = C('Plugins.Flagging.CategoryID');
             // New discussion name
             if ($Context == 'comment') {
                 $Result = $SQL->Select('d.Name')->Select('c.Body')->From('Comment c')->Join('Discussion d', 'd.DiscussionID = c.DiscussionID', 'left')->Where('c.CommentID', $ElementID)->Get()->FirstRow();
             } elseif ($Context == 'discussion') {
                 $DiscussionModel = new DiscussionModel();
                 $Result = $DiscussionModel->GetID($ElementID);
             }
             $DiscussionName = GetValue('Name', $Result);
             $PrefixedDiscussionName = T('FlagPrefix', 'FLAG: ') . $DiscussionName;
             // Prep data for the template
             $Sender->SetData('Plugin.Flagging.Report', array('DiscussionName' => $DiscussionName, 'FlaggedContent' => GetValue('Body', $Result)));
             // Assume no discussion exists
             $this->DiscussionID = NULL;
             // Get discussion ID if already flagged
             $FlagResult = Gdn::SQL()->Select('DiscussionID')->From('Flag fl')->Where('ForeignType', $Context)->Where('ForeignID', $ElementID)->Get()->FirstRow();
             if ($FlagResult) {
                 // New comment in existing discussion
                 $DiscussionID = $FlagResult->DiscussionID;
                 $ReportBody = $Sender->FetchView($this->GetView('reportcomment.php'));
                 $SQL->Insert('Comment', array('DiscussionID' => $DiscussionID, 'InsertUserID' => $UserID, 'Body' => $ReportBody, 'Format' => 'Html', 'DateInserted' => date('Y-m-d H:i:s')));
                 $CommentModel = new CommentModel();
                 $CommentModel->UpdateCommentCount($DiscussionID);
             } else {
                 // New discussion body
                 $ReportBody = $Sender->FetchView($this->GetView('report.php'));
                 $DiscussionID = $SQL->Insert('Discussion', array('InsertUserID' => $UserID, 'UpdateUserID' => $UserID, 'CategoryID' => $CategoryID, 'Name' => $PrefixedDiscussionName, 'Body' => $ReportBody, 'Format' => 'Html', 'CountComments' => 1, 'DateInserted' => date('Y-m-d H:i:s'), 'DateUpdated' => date('Y-m-d H:i:s'), 'DateLastComment' => date('Y-m-d H:i:s')));
                 // Update discussion count
                 $DiscussionModel = new DiscussionModel();
                 $DiscussionModel->UpdateDiscussionCount($CategoryID);
             }
         }
         try {
             // Insert the flag
             $SQL->Insert('Flag', array('DiscussionID' => $DiscussionID, 'InsertUserID' => $UserID, 'InsertName' => $UserName, 'AuthorID' => $ElementAuthorID, 'AuthorName' => $ElementAuthor, 'ForeignURL' => $URL, 'ForeignID' => $ElementID, 'ForeignType' => $Context, 'Comment' => $Comment, 'DateInserted' => date('Y-m-d H:i:s')));
         } catch (Exception $e) {
         }
         // Notify users with permission who've chosen to be notified
         if (!$FlagResult) {
             // Only send if this is first time it's being flagged.
             $Sender->SetData('Plugin.Flagging.DiscussionID', $DiscussionID);
             $Subject = isset($PrefixedDiscussionName) ? $PrefixedDiscussionName : T('FlagDiscussion', 'A discussion was flagged');
             $EmailBody = $Sender->FetchView($this->GetView('reportemail.php'));
             $NotifyUsers = C('Plugins.Flagging.NotifyUsers', array());
             // Send emails
             $UserModel = new UserModel();
             foreach ($NotifyUsers as $UserID) {
                 $User = $UserModel->GetID($UserID);
                 $Email = new Gdn_Email();
                 $Email->To($User->Email)->Subject(sprintf(T('[%1$s] %2$s'), Gdn::Config('Garden.Title'), $Subject))->Message($EmailBody)->Send();
             }
         }
         $Sender->InformMessage(T('FlagSent', "Your complaint has been registered."));
     }
     $Sender->Render($this->GetView('flag.php'));
 }
コード例 #21
0
 /**
  * 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);
         }
     }
 }