/** * constructor * * @access public * @param array $options Associated options array * @return void */ public function __construct($options) { $this->object = Jaws_Mail::getInstance('notification'); // fetch all registry keys related to site attributes $this->attributes = $GLOBALS['app']->Registry->fetchAll('Settings', false); Jaws_Translate::getInstance()->LoadTranslation('Global', JAWS_COMPONENT_OTHERS, $this->attributes['site_language']); $this->attributes['site_url'] = $GLOBALS['app']->GetSiteURL('/'); $this->attributes['site_direction'] = _t_lang($this->attributes['site_language'], 'GLOBAL_LANG_DIRECTION'); }
/** * This function mails the comments to the owner * * @access public * @param int $link The permanent link * @param string $from_email The email to sendto * @param string $comment The body of the email (The actual comment) * @param string $url The actual comment url */ function MailComment($link, $from_email, $comment, $url) { $subject = _t('SHOUTBOX_COMMENT_MAIL_TITLE'); $comment .= "<br /><br />"; $comment .= _t("SHOUTBOX_COMMENT_MAIL_VISIT_URL", $link . '/', $this->gadget->registry->fetch('site_name', 'Settings')); $mail = Jaws_Mail::getInstance(); $mail->SetFrom($from_email); $mail->AddRecipient(''); $mail->SetSubject($subject); $mail->SetBody($comment, 'html'); $mail->send(); }
/** * Changes a password from a given key * * @access public * @param string $key Recovery key * @return mixed True on success or Jaws_Error on failure */ function ChangePassword($key) { $jUser = new Jaws_User(); $user = $jUser->GetUserByPasswordVerifyKey($key); if (Jaws_Error::IsError($user) || empty($user)) { return false; } // generate new password $password = Jaws_Utils::RandomText(8); $res = $jUser->UpdateUser($user['id'], array('username' => $user['username'], 'nickname' => $user['nickname'], 'email' => $user['email'], 'password' => $password)); if (Jaws_Error::IsError($res)) { return $res; } $site_url = $GLOBALS['app']->getSiteURL('/'); $site_name = $this->gadget->registry->fetch('site_name', 'Settings'); $tpl = $this->gadget->template->load('NewPassword.txt'); $tpl->SetBlock('NewPassword'); $tpl->SetVariable('say_hello', _t('USERS_EMAIL_REPLACEMENT_HELLO', $user['nickname'])); $tpl->SetVariable('username', $user['username']); $tpl->SetVariable('nickname', $user['nickname']); $tpl->SetVariable('password', $password); $tpl->SetVariable('message', _t('USERS_FORGOT_PASSWORD_CHANGED_MESSAGE', $user['username'])); $tpl->SetVariable('lbl_password', _t('USERS_USERS_PASSWORD')); $tpl->SetVariable('lbl_username', _t('USERS_USERS_USERNAME')); $tpl->SetVariable('thanks', _t('GLOBAL_THANKS')); $tpl->SetVariable('site-name', $site_name); $tpl->SetVariable('site-url', $site_url); $tpl->ParseBlock('NewPassword'); $message = $tpl->Get(); $subject = _t('USERS_FORGOT_PASSWORD_CHANGED_SUBJECT'); $mail = Jaws_Mail::getInstance(); $mail->SetFrom(); $mail->AddRecipient($user['email']); $mail->SetSubject($subject); $mail->SetBody($this->gadget->ParseText($message)); $mresult = $mail->send(); if (Jaws_Error::IsError($mresult)) { return new Jaws_Error(_t('USERS_FORGOT_ERROR_SENDING_MAIL')); } return true; }
/** * Send email to recipient * * @access public * @param string $to Recipient email address * @param int $cid Contact ID * @return mixed True on Success or Jaws_Error on Failure */ function SendEmailToRecipient($to, $cid) { $model = $this->gadget->model->load('Contacts'); $contact = $model->GetContact($cid); if (Jaws_Error::IsError($contact)) { return $contact; } if (!isset($contact['id'])) { return new Jaws_Error(_t('CONTACT_ERROR_CONTACT_DOES_NOT_EXISTS')); } $from_name = $contact['name']; $from_email = $contact['email']; $site_url = $GLOBALS['app']->getSiteURL('/'); $site_name = $this->gadget->registry->fetch('site_name', 'Settings'); $format = $this->gadget->registry->fetch('email_format'); if ($format == 'html') { $message = Jaws_String::AutoParagraph($contact['msg_txt']); } else { $message = $contact['msg_txt']; } $tpl = $this->gadget->template->load('SendToRecipient.html'); $tpl->SetBlock($format); $tpl->SetVariable('lbl_name', _t('GLOBAL_NAME')); $tpl->SetVariable('lbl_email', _t('GLOBAL_EMAIL')); $tpl->SetVariable('lbl_company', _t('CONTACT_COMPANY')); $tpl->SetVariable('lbl_url', _t('GLOBAL_URL')); $tpl->SetVariable('lbl_tel', _t('CONTACT_TEL')); $tpl->SetVariable('lbl_fax', _t('CONTACT_FAX')); $tpl->SetVariable('lbl_mobile', _t('CONTACT_MOBILE')); $tpl->SetVariable('lbl_address', _t('CONTACT_ADDRESS')); $tpl->SetVariable('lbl_recipient', _t('CONTACT_RECIPIENT')); $tpl->SetVariable('lbl_subject', _t('CONTACT_SUBJECT')); $tpl->SetVariable('lbl_message', _t('CONTACT_MESSAGE')); $tpl->SetVariable('name', $contact['name']); $tpl->SetVariable('email', $contact['email']); $tpl->SetVariable('company', $contact['company']); $tpl->SetVariable('url', $contact['url']); $tpl->SetVariable('tel', $contact['tel']); $tpl->SetVariable('fax', $contact['fax']); $tpl->SetVariable('mobile', $contact['mobile']); $tpl->SetVariable('address', $contact['address']); $tpl->SetVariable('recipient', $to); $tpl->SetVariable('subject', $contact['subject']); $tpl->SetVariable('message', $message); $tpl->SetVariable('site-name', $site_name); $tpl->SetVariable('site-url', $site_url); $tpl->ParseBlock($format); $template = $tpl->Get(); $mail = Jaws_Mail::getInstance(); $mail->SetFrom($from_email, $from_name); $mail->AddRecipient($to); $mail->SetSubject(Jaws_XSS::defilter($contact['subject'])); $mail->SetBody($template, $format); $result = $mail->send(); if (Jaws_Error::IsError($result)) { return $result; } return true; }
/** * Send contact reply * * @access public * @param int $cid Contact ID * @return mixed True on Success or Jaws_Error on Failure */ function SendReply($cid) { $model = $this->gadget->model->loadAdmin('Contacts'); $contact = $model->GetReply($cid); if (Jaws_Error::IsError($contact)) { $GLOBALS['app']->Session->PushLastResponse(_t('GLOBAL_ERROR_QUERY_FAILED'), RESPONSE_ERROR); return new Jaws_Error(_t('GLOBAL_ERROR_QUERY_FAILED')); } if (!isset($contact['id'])) { $GLOBALS['app']->Session->PushLastResponse(_t('CONTACT_ERROR_CONTACT_DOES_NOT_EXISTS'), RESPONSE_ERROR); return new Jaws_Error(_t('CONTACT_ERROR_CONTACT_DOES_NOT_EXISTS')); } $from_name = ''; $from_email = ''; $to = $contact['email']; $rid = $contact['recipient']; if ($rid != 0) { $rModel = $this->gadget->model->load('Recipients'); $recipient = $rModel->GetRecipient($rid); if (Jaws_Error::IsError($recipient)) { $GLOBALS['app']->Session->PushLastResponse(_t('GLOBAL_ERROR_QUERY_FAILED'), RESPONSE_ERROR); return new Jaws_Error(_t('GLOBAL_ERROR_QUERY_FAILED')); } if (!isset($recipient['id'])) { $GLOBALS['app']->Session->PushLastResponse(_t('CONTACT_ERROR_RECIPIENT_DOES_NOT_EXISTS'), RESPONSE_ERROR); return new Jaws_Error(_t('CONTACT_ERROR_RECIPIENT_DOES_NOT_EXISTS')); } $from_name = $recipient['name']; $from_email = $recipient['email']; } $format = $this->gadget->registry->fetch('email_format'); if ($format == 'html') { $reply = $this->gadget->ParseText($contact['reply']); } else { $reply = $contact['reply']; } $jDate = Jaws_Date::getInstance(); $site_url = $GLOBALS['app']->getSiteURL('/'); $site_name = $this->gadget->registry->fetch('site_name', 'Settings'); $site_language = $this->gadget->registry->fetch('site_language', 'Settings'); $profile_url = $GLOBALS['app']->getSiteURL('/') . $GLOBALS['app']->Map->GetURLFor('Users', 'Profile', array('user' => $GLOBALS['app']->Session->GetAttribute('username'))); Jaws_Translate::getInstance()->LoadTranslation('Global', JAWS_COMPONENT_OTHERS, $site_language); Jaws_Translate::getInstance()->LoadTranslation('Contact', JAWS_COMPONENT_GADGET, $site_language); $tpl = $this->gadget->template->load('SendReplyTo.html', array('loadFromTheme' => true, 'loadRTLDirection' => _t_lang($site_language, 'GLOBAL_LANG_DIRECTION') == 'rtl')); $tpl->SetBlock($format); $tpl->SetVariable('lbl_name', _t_lang($site_language, 'GLOBAL_NAME')); $tpl->SetVariable('lbl_email', _t_lang($site_language, 'GLOBAL_EMAIL')); $tpl->SetVariable('lbl_message', _t_lang($site_language, 'CONTACT_MESSAGE')); $tpl->SetVariable('lbl_reply', _t_lang($site_language, 'CONTACT_REPLY')); $tpl->SetVariable('name', $contact['name']); $tpl->SetVariable('email', $contact['email']); $tpl->SetVariable('subject', $contact['subject']); $tpl->SetVariable('message', $contact['msg_txt']); $tpl->SetVariable('reply', $reply); $tpl->SetVariable('createtime', $jDate->Format($contact['createtime'])); $tpl->SetVariable('nickname', $GLOBALS['app']->Session->GetAttribute('nickname')); $tpl->SetVariable('profile_url', $profile_url); $tpl->SetVariable('site-name', $site_name); $tpl->SetVariable('site-url', $site_url); $tpl->ParseBlock($format); $template = $tpl->Get(); $subject = _t_lang($site_language, 'CONTACT_REPLY_TO', Jaws_XSS::defilter($contact['subject'])); $mail = Jaws_Mail::getInstance(); $mail->SetFrom($from_email, $from_name); $mail->AddRecipient($to); $mail->AddRecipient('', 'cc'); $mail->SetSubject($subject); $mail->SetBody($template, $format); $result = $mail->send(); if (Jaws_Error::IsError($result)) { $GLOBALS['app']->Session->PushLastResponse(_t('CONTACT_ERROR_REPLY_NOT_SENT'), RESPONSE_ERROR); return false; } $model->UpdateReplySent($cid, true); $GLOBALS['app']->Session->PushLastResponse(_t('CONTACT_REPLY_SENT'), RESPONSE_NOTICE); return true; }
/** * Checks if user/email are valid, if they are then generates a recovery * secret key and sends it to the user * * @access public * @param string $user_email User email * @return bool True on success or Jaws_Error on failure */ function SendRecoveryKey($user_email) { $userModel = new Jaws_User(); $uInfos = $userModel->GetUserInfoByEmail($user_email); if (Jaws_Error::IsError($uInfos)) { return $uInfos; } if (empty($uInfos)) { return new Jaws_Error(_t('USERS_USER_NOT_EXIST')); } foreach ($uInfos as $info) { $verifyKey = $userModel->UpdatePasswordVerifyKey($info['id']); if (Jaws_Error::IsError($verifyKey)) { $verifyKey->SetMessage(_t('GLOBAL_ERROR_QUERY_FAILED')); return $verifyKey; } $site_url = $GLOBALS['app']->getSiteURL('/'); $site_name = $this->gadget->registry->fetch('site_name', 'Settings'); $tpl = $this->gadget->template->load('RecoverPassword.txt'); $tpl->SetBlock('RecoverPassword'); $tpl->SetVariable('lbl_username', _t('USERS_USERS_USERNAME')); $tpl->SetVariable('username', $info['username']); $tpl->SetVariable('nickname', $info['nickname']); $tpl->SetVariable('say_hello', _t('USERS_EMAIL_REPLACEMENT_HELLO', $info['nickname'])); $tpl->SetVariable('message', _t('USERS_FORGOT_MAIL_MESSAGE')); $tpl->SetVariable('lbl_url', _t('GLOBAL_URL')); $tpl->SetVariable('url', $this->gadget->urlMap('ChangePassword', array('key' => $verifyKey), true)); $tpl->SetVariable('lbl_ip', _t('GLOBAL_IP')); $tpl->SetVariable('ip', $_SERVER['REMOTE_ADDR']); $tpl->SetVariable('thanks', _t('GLOBAL_THANKS')); $tpl->SetVariable('site-name', $site_name); $tpl->SetVariable('site-url', $site_url); $tpl->ParseBlock('RecoverPassword'); $message = $tpl->Get(); $subject = _t('USERS_FORGOT_REMEMBER', $site_name); $mail = Jaws_Mail::getInstance(); $mail->SetFrom(); $mail->AddRecipient($user_email); $mail->SetSubject($subject); $mail->SetBody($this->gadget->ParseText($message)); $mresult = $mail->send(); if (Jaws_Error::IsError($mresult)) { $mresult->SetMessage(_t('USERS_FORGOT_ERROR_SENDING_MAIL')); return $mresult; } } }
/** * Sends the Email * * @access public * @param string $target JSON decoded array ([to, cc, bcc] or [user, group]) * @param string $subject Subject of the Email * @param string $message Message body of the Email * @param string $attachment Attachment * @return string XHTML template content */ function SendEmail($target, $subject, $message, $attachment) { $this->gadget->CheckPermission('AccessToMailer'); $mail = Jaws_Mail::getInstance(); $mail->SetFrom(); $mail->SetSubject(Jaws_XSS::defilter($subject)); // To, Cc, Bcc if (isset($target['to'])) { if (!empty($target['to'])) { $recipients = explode(',', $target['to']); foreach ($recipients as $recpt) { $mail->AddRecipient($recpt, 'To'); } } if (!empty($target['cc'])) { $recipients = explode(',', $target['cc']); foreach ($recipients as $recpt) { $mail->AddRecipient($recpt, 'Cc'); } } if (!empty($target['bcc'])) { $recipients = explode(',', $target['bcc']); foreach ($recipients as $recpt) { $mail->AddRecipient($recpt, 'Bcc'); } } } else { $userModel = new Jaws_User(); if ($target['user'] != 0) { $user = $userModel->GetUser((int) $target['user']); if (!Jaws_Error::IsError($user)) { $mail->AddRecipient($user['nickname'] . ' <' . $user['email'] . '>', 'To'); } } else { if ($target['group'] == 0) { $target['group'] = false; } $users = $userModel->GetUsers($target['group'], null, true); foreach ($users as $user) { $mail->AddRecipient($user['nickname'] . ' <' . $user['email'] . '>', 'Bcc'); } } } $message = $this->PrepareMessage($message); $format = $this->gadget->registry->fetch('email_format'); $mail->SetBody($message, $format); if (!empty($attachment)) { $attachment = Jaws_Utils::upload_tmp_dir() . '/' . $attachment; if (file_exists($attachment)) { $mail->SetBody($attachment, 'file'); Jaws_Utils::Delete($attachment); } } $result = $mail->send(); if (Jaws_Error::IsError($result)) { $GLOBALS['app']->Session->PushLastResponse(_t('CONTACT_ERROR_EMAIL_NOT_SENT'), RESPONSE_ERROR); return false; } $GLOBALS['app']->Session->PushLastResponse(_t('CONTACT_NOTICE_EMAIL_SENT'), RESPONSE_NOTICE); return true; }
/** * Mails reply to the sender * * @access public * @param string $email Comment sender's email * @param string $message Message * @param string $reply Reply message * @param int $replier Replier Id * @return mixed True on successfully or Jaws_Error on failure */ function EmailReply($email, $message, $reply, $replier) { $site_url = $GLOBALS['app']->getSiteURL('/'); $site_name = $this->gadget->registry->fetch('site_name', 'Settings'); $site_language = $this->gadget->registry->fetch('site_language', 'Settings'); Jaws_Translate::getInstance()->LoadTranslation('Global', JAWS_COMPONENT_OTHERS, $site_language); Jaws_Translate::getInstance()->LoadTranslation('Comments', JAWS_COMPONENT_GADGET, $site_language); $tpl = $this->gadget->template->load('EmailReply.html'); $tpl->SetBlock('notification'); $tpl->SetVariable('lbl_message', _t_lang($site_language, 'COMMENTS_MESSAGE')); $tpl->SetVariable('message', $message); $tpl->SetVariable('replier', _t_lang($site_language, 'COMMENTS_REPLY_BY', $replier)); $tpl->SetVariable('lbl_reply', _t_lang($site_language, 'COMMENTS_REPLY')); $tpl->SetVariable('reply', $reply); $tpl->SetVariable('site_name', $site_name); $tpl->SetVariable('site_url', $site_url); $tpl->ParseBlock('notification'); $template = $tpl->Get(); $ObjMail = Jaws_Mail::getInstance(); $ObjMail->SetFrom(); if (empty($email)) { $ObjMail->AddRecipient('', 'to'); } else { $ObjMail->AddRecipient($email); $ObjMail->AddRecipient('', 'cc'); } $ObjMail->SetSubject(_t_lang('COMMENTS_YOU_GET_REPLY')); $ObjMail->SetBody($template, 'html'); return $ObjMail->send(); }
/** * Mails add/edit topic notification to the admins * * @access public * @param string $event_type Event type * @param string $forum_title Forum title * @param string $topic_link Link of the topic * @param string $topic_subject Topic subject * @param string $topic_message Post message content * @param string $reason Reason of doing action * @return mixed True on successfully or Jaws_Error on failure */ function TopicNotification($event_type, $forum_title, $topic_link, $topic_subject, $topic_message, $reason = null) { $site_url = $GLOBALS['app']->getSiteURL('/'); $site_name = $this->gadget->registry->fetch('site_name', 'Settings'); $event_type = strtoupper($event_type); // user profile link $lnkProfile =& Piwi::CreateWidget('Link', $GLOBALS['app']->Session->GetAttribute('nickname'), $GLOBALS['app']->Map->GetURLFor('Users', 'Profile', array('user' => $GLOBALS['app']->Session->GetAttribute('username')), true)); $event_subject = _t("FORUMS_TOPICS_{$event_type}_NOTIFICATION_SUBJECT", $forum_title); $event_message = _t("FORUMS_TOPICS_{$event_type}_NOTIFICATION_MESSAGE", $lnkProfile->Get()); $tpl = $this->gadget->template->load('TopicNotification.html'); $tpl->SetBlock('notification'); $tpl->SetVariable('notification', $event_message); $tpl->SetVariable('lbl_subject', _t('FORUMS_TOPICS_SUBJECT')); $tpl->SetVariable('subject', $topic_subject); $tpl->SetVariable('lbl_message', _t('FORUMS_POSTS_MESSAGE')); $tpl->SetVariable('message', $topic_message); $tpl->SetVariable('lbl_url', _t('FORUMS_TOPIC')); $tpl->SetVariable('url', $topic_link); $tpl->SetVariable('site_name', $site_name); $tpl->SetVariable('site_url', $site_url); if (!empty($reason)) { $tpl->SetBlock('notification/reason'); $tpl->SetVariable('lbl_reason', _t('FORUMS_POSTS_REASON')); $tpl->SetVariable('lbl_reason', $reason); $tpl->ParseBlock('notification/reason'); } $tpl->ParseBlock('notification'); $template = $tpl->Get(); $ObjMail = Jaws_Mail::getInstance(); $ObjMail->SetFrom(); $ObjMail->AddRecipient('', 'to'); $ObjMail->SetSubject($event_subject); $ObjMail->SetBody($template, 'html'); return $ObjMail->send(); }
/** * Mails activate notification to the user * * @access public * @param array $user User's attributes array * @param string $anon_activation Anonymous activation type * @return mixed True on successfully or Jaws_Error on failure */ function ActivateNotification($user, $anon_activation) { $site_url = $GLOBALS['app']->getSiteURL('/'); $site_name = $this->gadget->registry->fetch('site_name', 'Settings'); $tpl = $this->gadget->template->load('UserNotification.txt'); $tpl->SetBlock('Notification'); $tpl->SetVariable('say_hello', _t('USERS_REGISTER_HELLO', $user['nickname'])); $tpl->SetVariable('message', _t('USERS_ACTIVATE_ACTIVATED_MAIL_MSG')); if ($anon_activation == 'user') { $tpl->SetBlock('Notification/IP'); $tpl->SetVariable('lbl_ip', _t('GLOBAL_IP')); $tpl->SetVariable('ip', $_SERVER['REMOTE_ADDR']); $tpl->ParseBlock('Notification/IP'); } $tpl->SetVariable('lbl_username', _t('USERS_USERS_USERNAME')); $tpl->SetVariable('username', $user['username']); $tpl->SetVariable('thanks', _t('GLOBAL_THANKS')); $tpl->SetVariable('site-name', $site_name); $tpl->SetVariable('site-url', $site_url); $tpl->ParseBlock('Notification'); $body = $tpl->Get(); $subject = _t('USERS_REGISTER_SUBJECT', $site_name); $mail = Jaws_Mail::getInstance(); $mail->SetFrom(); $mail->AddRecipient($user['email']); $mail->SetSubject($subject); $mail->SetBody($this->gadget->ParseText($body)); return $mail->send(); }
/** * Sends replace email notification to user * * @access public * @param int $user_id User's ID * @param string $nickname User's nickname * @param string $new_email User's new email * @param string $old_email User's old email * @return mixed True on success otherwise Jaws_Error on failure */ function ReplaceEmailNotification($user_id, $username, $nickname, $new_email, $old_email) { $tpl = $this->gadget->template->load('NewEmail.txt'); $tpl->SetBlock('Notification'); $tpl->SetVariable('nickname', $nickname); $tpl->SetVariable('say_hello', _t('USERS_EMAIL_REPLACEMENT_HELLO', $nickname)); $tpl->SetVariable('message', _t('USERS_EMAIL_REPLACEMENT_MSG')); $tpl->SetBlock('Notification/IP'); $tpl->SetVariable('lbl_ip', _t('GLOBAL_IP')); $tpl->SetVariable('ip', $_SERVER['REMOTE_ADDR']); $tpl->ParseBlock('Notification/IP'); $tpl->SetVariable('lbl_username', _t('USERS_USERS_USERNAME')); $tpl->SetVariable('username', $username); $tpl->SetVariable('lbl_email', _t('GLOBAL_EMAIL')); $tpl->SetVariable('email', $old_email); $jUser = new Jaws_User(); $verifyKey = $jUser->UpdateEmailVerifyKey($user_id); if (Jaws_Error::IsError($verifyKey)) { return $verifyKey; } else { $tpl->SetBlock('Notification/Activation'); $tpl->SetVariable('lbl_activation_link', _t('USERS_ACTIVATE_ACTIVATION_LINK')); $tpl->SetVariable('activation_link', $this->gadget->urlMap('ReplaceUserEmail', array('key' => $verifyKey), true)); $tpl->ParseBlock('Notification/Activation'); } $site_url = $GLOBALS['app']->getSiteURL('/'); $site_name = $this->gadget->registry->fetch('site_name', 'Settings'); $tpl->SetVariable('site-name', $site_name); $tpl->SetVariable('site-url', $site_url); $tpl->SetVariable('thanks', _t('GLOBAL_THANKS')); $tpl->ParseBlock('Notification'); $body = $tpl->Get(); $subject = _t('USERS_EMAIL_REPLACEMENT_SUBJECT', $site_name); $mail = Jaws_Mail::getInstance(); $mail->SetFrom(); $mail->AddRecipient($new_email); $mail->SetSubject($subject); $mail->SetBody($this->gadget->ParseText($body)); $mresult = $mail->send(); if (Jaws_Error::IsError($mresult)) { return $mresult; } return true; }