예제 #1
0
 /**
  * Internal function to sends an email from a user to another user
  *
  * @param  UserTable|stdClass  $toUser        Receiver
  * @param  UserTable           $fromUser      Sender
  * @param  string              $replyToName   Reply-To name
  * @param  string              $replyToEmail  Reply-To email address
  * @param  string              $subject       Subject
  * @param  string              $message       HTML message for PMS
  * @param  boolean             $addPrefix     Add prefix text to explain who is sending from which site ?
  * @param  int                 $mode          false = plain text, true = HTML
  * @param  null|string         $cc            Email CC address
  * @param  null|string         $bcc           Email BCC address
  * @param  null|string         $attachment    Email attachment files
  * @param  boolean|string      $fromEmail     From email address (overrides from row email): false = from row email, null = system email, otherwise use as specified
  * @param  boolean|string      $fromName      From name (overrides from row name): false = from row name, null = system name, otherwise use a specified
  * @return boolean                            Result
  */
 private function _sendEmailMSG($toUser, $fromUser, $replyToName, $replyToEmail, $subject, $message, $addPrefix = false, $mode = 0, $cc = null, $bcc = null, $attachment = null, $fromEmail = false, $fromName = false)
 {
     global $_CB_framework, $ueConfig, $_PLUGINS, $_SERVER;
     $_PLUGINS->trigger('onBeforeSendEmailMSG', array($this, &$toUser, &$fromUser, &$subject, &$message, &$addPrefix, &$mode, &$cc, &$bcc, &$attachment));
     if ($addPrefix) {
         $toUserLanguage = CBuser::getInstance((int) $toUser->id)->getUserData()->getUserLanguage();
         $savedLanguage = CBTxt::setLanguage($toUserLanguage);
         $preMsg = $this->_replaceVariables(CBTxt::T('EMAIL_NOTE_MESSAGE_FROM_NAME_AT_SITENAME_TO_YOU', '------- This is a message from [formatname] at [sitename] ([siteurl]) to you: -------') . "\r\n\r\n", $fromUser, $mode);
         $postMsg = $this->_replaceVariables("\r\n\r\n" . CBTxt::T('EMAIL_NOTE', '------ NOTES: ------') . (isset($ueConfig['allow_email_replyto']) && $ueConfig['allow_email_replyto'] == 2 ? "\r\n\r\n" . CBTxt::T('EMAIL_NOTE_WHEN_REPLYING_CHECK_ADDRESS', 'When replying, please check carefully that the email address of [formatname] is [email].') : null) . "\r\n\r\n" . CBTxt::T('EMAIL_NOTE_UNSEEN_ADDRESS', 'This user did not see your email address. If you reply the recipient will have your email address.') . "\r\n\r\n" . CBTxt::T('EMAIL_NOTE_CONTENTS_DISCLAIMER', '[sitename] owners cannot accept any responsibility for the contents of the email and of user email addresses.'), $fromUser, $mode);
         $message = $preMsg . $message . $postMsg;
         $fromName = getNameFormat($fromUser->name, $fromUser->username, $ueConfig['name_format']) . ' @ ' . $_CB_framework->getCfg('sitename');
         CBTxt::setLanguage($savedLanguage);
     }
     $this->errorMSG = null;
     $result = comprofilerMail($fromEmail !== false ? $fromEmail : $fromUser->email, $fromName !== false ? $fromName : $fromUser->name, $toUser->email, $subject, $message, $mode, $cc, $bcc, $attachment, $replyToEmail, $replyToName, $this->mailerProperties, $this->errorMSG);
     $_PLUGINS->trigger('onAfterSendEmailMSG', array($result, $this, $toUser, $fromUser, $subject, $message, $addPrefix, $mode, $cc, $bcc, $attachment));
     return $result;
 }
예제 #2
0
 /**
  * loads a plugins main php file
  *
  * @param  PluginTable  $plugin
  * @return bool
  */
 public function _loadPluginFile($plugin)
 {
     /** @noinspection PhpUnusedLocalVariableInspection */
     global $_CB_framework, $_PLUGINS;
     // $_PLUGINS is needed for the include below.
     // We don't want language files PHP loading as we do that through cbimport:
     if ($plugin->type == 'language') {
         return false;
     }
     $path = $_CB_framework->getCfg('absolute_path') . '/' . $this->getPluginRelPath($plugin) . '/' . $plugin->element . '.php';
     if (file_exists($path) && is_readable($path)) {
         $savePreviousPluginId = $this->_setLoading($plugin, true);
         $langCache = CBTxt::setLanguage(null);
         $plgLangPath = $_CB_framework->getCfg('absolute_path') . '/' . $this->getPluginRelPath($plugin) . '/language';
         $langPath = $_CB_framework->getCfg('absolute_path') . '/components/com_comprofiler/plugin/language';
         $lang = $_CB_framework->getCfg('lang_tag');
         if ($_CB_framework->getUi() == 2) {
             $langLoaded = CBTxt::import($langPath, $lang, '/cbplugin/' . $plugin->element . '-admin_language.php', false);
             if (!$langLoaded) {
                 CBTxt::import($plgLangPath, $lang, 'admin_language.php');
             }
         }
         $langLoaded = CBTxt::import($langPath, $lang, 'cbplugin/' . $plugin->element . '-language.php', false);
         if (!$langLoaded) {
             CBTxt::import($plgLangPath, $lang, 'language.php');
         }
         // We don't want plugins language files to alter the current language loaded so lets reset it:
         CBTxt::setLanguage($langCache);
         /** @noinspection PhpIncludeInspection */
         require_once $path;
         $this->_setLoading($plugin, $savePreviousPluginId);
         return true;
     } else {
         return false;
     }
 }
 /**
  * Activates a user
  * user plugins must have been loaded
  *
  * @param  UserTable  $user
  * @param  int        $ui               1=frontend, 2=backend, 0=no UI: machine-machine UI
  * @param  string     $cause            (one of: 'UserRegistration', 'UserConfirmation', 'UserApproval', 'NewUser', 'UpdateUser')
  * @param  boolean    $mailToAdmins     true if the standard new-user email should be sent to admins if moderator emails are enabled
  * @param  boolean    $mailToUser       true if the welcome new user email (from CB config) should be sent to the new user
  * @param  boolean    $triggerBeforeActivate
  * @return array                        Texts to display
  */
 function activateUser(&$user, $ui, $cause, $mailToAdmins = true, $mailToUser = true, $triggerBeforeActivate = true)
 {
     global $ueConfig, $_PLUGINS;
     static $notificationsSent = array();
     $activate = $user->confirmed && $user->approved == 1;
     $showSysMessage = true;
     $savedLanguage = CBTxt::setLanguage($user->getUserLanguage());
     $messagesToUser = getActivationMessage($user, $cause);
     CBTxt::setLanguage($savedLanguage);
     if ($cause == 'UserConfirmation' && $user->approved == 0) {
         $activate = false;
         $msg = array('emailAdminSubject' => array('sys' => CBTxt::T('UE_REG_ADMIN_PA_SUB', 'ACTION REQUIRED! New user sign up request pending approval')), 'emailAdminMessage' => array('sys' => CBTxt::T('UE_REG_ADMIN_PA_MSG', "A new user has signed up at [SITEURL] and requires approval.\nThis email contains their details\n\nName - [NAME]\nE-mail - [EMAILADDRESS]\nUsername - [USERNAME]\n\n\nPlease do not respond to this message as it is automatically generated and is for informational purposes only.\n")), 'emailUserSubject' => array(), 'emailUserMessage' => array());
     } elseif ($user->confirmed == 0) {
         $msg = array('emailAdminSubject' => array(), 'emailAdminMessage' => array());
         $savedLanguage = CBTxt::setLanguage($user->getUserLanguage());
         $msg['emailUserSubject'] = array('sys' => CBTxt::T(stripslashes($ueConfig['reg_pend_appr_sub'])));
         $msg['emailUserMessage'] = array('sys' => CBTxt::T(stripslashes($ueConfig['reg_pend_appr_msg'])));
         CBTxt::setLanguage($savedLanguage);
     } elseif ($cause == 'SameUserRegistrationAgain') {
         $activate = false;
         $msg = array('emailAdminSubject' => array(), 'emailAdminMessage' => array(), 'emailUserSubject' => array(), 'emailUserMessage' => array());
     } elseif ($user->confirmed && !($user->approved == 1)) {
         $msg = array('emailAdminSubject' => array('sys' => CBTxt::T('UE_REG_ADMIN_PA_SUB', 'ACTION REQUIRED! New user sign up request pending approval')), 'emailAdminMessage' => array('sys' => CBTxt::T('UE_REG_ADMIN_PA_MSG', "A new user has signed up at [SITEURL] and requires approval.\nThis email contains their details\n\nName - [NAME]\nE-mail - [EMAILADDRESS]\nUsername - [USERNAME]\n\n\nPlease do not respond to this message as it is automatically generated and is for informational purposes only.\n")));
         $savedLanguage = CBTxt::setLanguage($user->getUserLanguage());
         $msg['emailUserSubject'] = array('sys' => CBTxt::T(stripslashes($ueConfig['reg_pend_appr_sub'])));
         $msg['emailUserMessage'] = array('sys' => CBTxt::T(stripslashes($ueConfig['reg_pend_appr_msg'])));
         CBTxt::setLanguage($savedLanguage);
     } elseif ($user->confirmed && $user->approved == 1) {
         $msg = array('emailAdminSubject' => array('sys' => CBTxt::T('UE_REG_ADMIN_SUB', 'New user sign up')), 'emailAdminMessage' => array('sys' => CBTxt::T('UE_REG_ADMIN_MSG', "A new user has signed up at [SITEURL].\nThis email contains their details\n\nName - [NAME]\nE-mail - [EMAILADDRESS]\nUsername - [USERNAME]\n\n\nPlease do not respond to this message as it is automatically generated and is for information purposes only.\n")));
         $savedLanguage = CBTxt::setLanguage($user->getUserLanguage());
         $msg['emailUserSubject'] = array('sys' => CBTxt::T(stripslashes($ueConfig['reg_welcome_sub'])));
         $msg['emailUserMessage'] = array('sys' => CBTxt::T(stripslashes($ueConfig['reg_welcome_msg'])));
         CBTxt::setLanguage($savedLanguage);
     }
     $msg['messagesToUser'] = $messagesToUser;
     if ($triggerBeforeActivate) {
         $results = $_PLUGINS->trigger('onBeforeUserActive', array(&$user, $ui, $cause, $mailToAdmins, $mailToUser));
         if ($_PLUGINS->is_errors() && $ui != 0) {
             echo $_PLUGINS->getErrorMSG('<br />');
         }
         foreach ($results as $res) {
             if (is_array($res)) {
                 $activate = $activate && $res['activate'];
                 $mailToAdmins = $mailToAdmins && $res['mailToAdmins'];
                 $mailToUser = $mailToUser && $res['mailToUser'];
                 $showSysMessage = $showSysMessage && $res['showSysMessage'];
                 foreach (array_keys($msg) as $key) {
                     if (isset($res[$key]) && $res[$key]) {
                         array_push($msg[$key], $res[$key]);
                     }
                 }
             }
         }
         if (!($mailToAdmins && $ueConfig['moderatorEmail'] == 1)) {
             unset($msg['emailAdminSubject']['sys']);
             unset($msg['emailAdminMessage']['sys']);
         }
         if (!$mailToUser) {
             unset($msg['emailUserSubject']['sys']);
             unset($msg['emailUserMessage']['sys']);
         }
         if (!$showSysMessage) {
             unset($msg['messagesToUser']['sys']);
         }
     }
     if ($activate) {
         $user->block = 0;
         $user->storeBlock(false);
         $user->removeActivationCode();
     }
     if ($activate) {
         $_PLUGINS->trigger('onUserActive', array(&$user, $ui, $cause, $mailToAdmins, $mailToUser));
         if ($_PLUGINS->is_errors() && $ui != 0) {
             $msg['messagesToUser'] = $_PLUGINS->getErrorMSG('<br />') . $msg['messagesToUser'];
         }
     }
     if (!isset($notificationsSent[$user->id][$user->confirmed][$user->approved][$user->block])) {
         // in case done several times (e.g. plugins), avoid resending messages.
         $cbNotification = new cbNotification();
         if ($ueConfig['moderatorEmail'] && count($msg['emailAdminMessage'])) {
             $pwd = $user->password;
             $user->password = null;
             $cbNotification->sendToModerators(implode(', ', $msg['emailAdminSubject']), $cbNotification->_replaceVariables(implode('\\n\\n', $msg['emailAdminMessage']), $user));
             $user->password = $pwd;
         }
         if (count($msg['emailUserMessage'])) {
             $cbNotification->sendFromSystem($user, implode(', ', $msg['emailUserSubject']), implode('\\n\\n', $msg['emailUserMessage']), true, isset($ueConfig['reg_email_html']) ? (int) $ueConfig['reg_email_html'] : 0);
         }
         $notificationsSent[$user->id][$user->confirmed][$user->approved][$user->block] = true;
     }
     return $msg['messagesToUser'];
 }
예제 #4
0
 /**
  * Changes the ban state of a user
  *
  * @param  int              $state   0: Unbanned, 1: Banned, 2: Pending
  * @param  null|UserTable  $by      The user that is banning or unbanning
  * @param  null|string     $reason  The reason for the ban or unban
  * @return bool
  */
 public function banUser($state, $by = null, $reason = null)
 {
     global $_CB_framework, $ueConfig, $_PLUGINS;
     if ($this->banned == $state) {
         return true;
     }
     if (!$by) {
         $by = CBuser::getMyUserDataInstance();
     }
     $values = array();
     $_PLUGINS->trigger('onBeforeUserBan', array(&$this, &$state, &$by, &$reason));
     if ($_PLUGINS->is_errors()) {
         $this->setError($_PLUGINS->getErrorMSG(false));
         return false;
     }
     $values['banned'] = (int) $state;
     if ($reason) {
         $values['bannedreason'] = $reason;
     }
     if ($state == 0) {
         $values['unbannedby'] = (int) $by->id;
         $values['unbanneddate'] = $_CB_framework->getUTCDate();
     } elseif ($state == 1) {
         $values['bannedby'] = (int) $by->id;
         $values['banneddate'] = $_CB_framework->getUTCDate();
     }
     if ($this->storeDatabaseValues($values, false)) {
         $_PLUGINS->trigger('onAfterUserBan', array($this, $state, $by, $reason));
         $cbNotification = new cbNotification();
         $savedLanguage = CBTxt::setLanguage($this->getUserLanguage());
         if ($state == 0) {
             $cbNotification->sendFromSystem((int) $this->id, CBTxt::T('UE_UNBANUSER_SUB', 'User Profile Unbanned'), CBTxt::T('UE_UNBANUSER_MSG', 'Your user profile was unbanned by an administrator. Your profile is now visible to all users again.'));
         } elseif ($state == 1) {
             $cbNotification->sendFromSystem((int) $this->id, CBTxt::T('UE_BANUSER_SUB', 'User Profile Banned.'), CBTxt::T('UE_BANUSER_MSG', 'Your user profile was banned by an administrator. Please log in and review why it was banned.'));
         } elseif ($state == 2) {
             if (isset($ueConfig['emailpass']) && $ueConfig['moderatorEmail'] == 1 && $_CB_framework->getUi() != 2) {
                 $cbNotification->sendToModerators(CBTxt::T('UE_UNBANUSERREQUEST_SUB', 'Unban Request Pending Review'), CBTxt::T('UE_UNBANUSERREQUEST_MSG', 'A user has submitted a request to unban their profile. Please log in and take the appropriate action.'));
             }
         }
         CBTxt::setLanguage($savedLanguage);
         return true;
     }
     return false;
 }