/** * Send invite email * * @param integer $uid * @param string $email * @param string $code * @param integer $role * @param object $project * * @return boolean True on success */ public function sendInviteEmail($uid = 0, $email = '', $code = '', $role = 0, $model = '', $option = 'com_projects') { $uid = $uid ? $uid : 0; $email = $email ? $email : User::get('email'); if (!$email || !$uid && !$code) { return false; } $option = $option ? $option : $this->_option; $model = $model ? $model : $this->model; if (!$model->exists()) { return false; } $database = App::get('db'); // Validate email $regex = '/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-]+)+/'; if (!preg_match($regex, $email)) { return false; } // Set up email config $from = array('name' => Config::get('sitename') . ' ' . Lang::txt(strtoupper($option)), 'email' => Config::get('mailfrom'), 'multipart' => md5(date('U'))); // Email message subject if ($model->isProvisioned()) { $objPub = new \Components\Publications\Tables\Publication($database); $pub = $objPub->getProvPublication($model->get('id')); if (!$pub || !$pub->id) { return false; } $subject = $uid ? Lang::txt('COM_PROJECTS_EMAIL_SUBJECT_ADDED_PROV') : Lang::txt('COM_PROJECTS_EMAIL_SUBJECT_INVITE_PROV'); } else { $subject = $uid ? Lang::txt('COM_PROJECTS_EMAIL_SUBJECT_ADDED') . ' ' . $model->get('alias') : Lang::txt('COM_PROJECTS_EMAIL_SUBJECT_INVITE') . ' ' . $model->get('alias'); } // Message body $eview = new \Hubzero\Mail\View(array('base_path' => PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'site', 'name' => 'emails', 'layout' => 'invite_plain')); $eview->option = $option; $eview->project = $model; $eview->code = $code; $eview->email = $email; $eview->uid = $uid; $eview->role = $role; $eview->pub = isset($pub) ? $pub : ''; $message['plaintext'] = $eview->loadTemplate(false); $message['plaintext'] = str_replace("\n", "\r\n", $message['plaintext']); // HTML email $eview->setLayout('invite_html'); $message['multipart'] = $eview->loadTemplate(); $message['multipart'] = str_replace("\n", "\r\n", $message['multipart']); if ($uid) { // Send HUB message if (Event::trigger('xmessage.onSendMessage', array('projects_member_added', $subject, $message, $from, array($uid), $option))) { return true; } } else { if (\Components\Projects\Helpers\Html::email($email, Config::get('sitename') . ': ' . $subject, $message, $from)) { return true; } } return false; }