$foo = parse_url($_SERVER["REQUEST_URI"]); $machine = $tikilib->httpPrefix() . dirname($foo["path"]); $smarty->assign('mail_machine', $machine); $parts = explode('/', $foo['path']); if (count($parts) > 1) { unset($parts[count($parts) - 1]); } $smarty->assign('mail_machine_raw', $tikilib->httpPrefix() . implode('/', $parts)); // TODO: mail_machine_site may be required for some sef url with rewrite to sub-directory. To refine. (nkoth) $smarty->assign('mail_machine_site', $tikilib->httpPrefix()); $mail = new TikiMail(); } global $prefs; // TODO: optimise by grouping user by language $languageEmail = $tikilib->get_user_preference($not['user'], "language", $prefs['site_language']); $mail->setUser($not['user']); $mail_data = $smarty->fetchLang($languageEmail, 'mail/user_watch_wiki_page_comment_subject.tpl'); $mail->setSubject(sprintf($mail_data, $_REQUEST["page"])); $mail_data = $smarty->fetchLang($languageEmail, 'mail/user_watch_wiki_page_comment.tpl'); $mail->setText($mail_data); $mail->buildMessage(); $mail->send(array($not['email'])); } } // redirect back to parent after edit/post to create GET request instead of POST to allow proper bookmarking/refreshing, etc. if (isset($forum_mode) && $forum_mode == 'y') { $url = "tiki-view_forum_thread.php?forumId=" . $_REQUEST['forumId'] . "&comments_parentId=" . $_REQUEST['comments_parentId']; if (!empty($_REQUEST['comments_threshold'])) { $url .= "&comments_threshold=" . $_REQUEST['comments_threshold']; } if (!empty($_REQUEST['comments_offset'])) {
$sent = 0; $unsubmsg = ''; $errors = array(); $users = $nllib->get_all_subscribers($_REQUEST["nlId"], $nl_info["unsubMsg"]); foreach ($users as $us) { $userEmail = $us["login"]; $email = $us["email"]; if ($email == "") { $errors[] = array("user" => $userEmail, "email" => ""); continue; } if ($userEmail == "") { $userEmail = $userlib->get_user_by_email($email); } if ($userEmail) { $mail->setUser($userEmail); } $mail->setFrom($tikilib->get_preference("sender_email", "")); $mail->setSubject($_REQUEST["subject"]); // htmlMimeMail memorised the encoded subject $languageEmail = !$userEmail ? $language : $tikilib->get_user_preference($userEmail, "language", $language); if ($nl_info["unsubMsg"] == 'y') { $unsubmsg = $nllib->get_unsub_msg($_REQUEST["nlId"], $userEmail, $languageEmail, $us["code"], $userEmail); if (stristr($html, "</body>") === false) { $msg = $html . nl2br($unsubmsg); } else { $msg = str_replace("</body>", nl2br($unsubmsg) . "</body>", $html); } } else { $msg = $html; }
function action_email_wikipage($input) { Services_Exception_Disabled::check('feature_wiki'); Services_Exception_Denied::checkGlobal('admin_users'); $check = Services_Exception_BadRequest::checkAccess(); //first pass - show confirm popup if (!empty($check['ticket'])) { $users = $input->asArray('checked'); if (count($users) > 0) { //provide redirect if js is not enabled $referer = Services_Utilities_Controller::noJsPath(); return ['title' => tra('Send wiki page content by email to selected users'), 'confirmAction' => $input->action->word(), 'confirmController' => 'user', 'customMsg' => tra('For these selected users:'), 'items' => $users, 'extra' => ['referer' => $referer], 'ticket' => $check['ticket'], 'modal' => '1', 'confirm' => 'y']; } else { throw new Services_Exception(tra('No users were selected. Please select one or more users.'), 409); } //after confirm submit - perform action and return success feedback } elseif ($check === true && $_SERVER['REQUEST_METHOD'] === 'POST') { $wikiTpl = $input['wikiTpl']; $tikilib = TikiLib::lib('tiki'); $pageinfo = $tikilib->get_page_info($wikiTpl); if (!$pageinfo) { throw new Services_Exception_NotFound(tra('Page not found')); } if (empty($pageinfo['description'])) { throw new Services_Exception(tra('The page does not have a description, which is mandatory to perform this action.')); } $bcc = $input['bcc']; include_once 'lib/webmail/tikimaillib.php'; $mail = new TikiMail(); if (!empty($bcc)) { if (!validate_email($bcc)) { throw new Services_Exception(tra('Invalid bcc email address.')); } $mail->setBcc($bcc); $bccmsg = tr('and blind copied to %0', $bcc); } $foo = parse_url($_SERVER['REQUEST_URI']); $machine = $tikilib->httpPrefix(true) . dirname($foo['path']); $machine = preg_replace('!/$!', '', $machine); // just in case global $smarty, $user; $smarty->assign_by_ref('mail_machine', $machine); $users = json_decode($input['items'], true); $logslib = TikiLib::lib('logs'); foreach ($users as $mail_user) { $smarty->assign_by_ref('user', $mail_user); $mail->setUser($mail_user); $mail->setSubject($pageinfo['description']); $text = $smarty->fetch('wiki:' . $wikiTpl); if (empty($text)) { throw new Services_Exception(tra('The template page has no text or it cannot be extracted.')); } $mail->setHtml($text); if (!$mail->send($this->lib->get_user_email($mail_user))) { $errormsg = tra('Unable to send mail'); if (Perms::get()->admin) { $mailerrors = print_r($mail->errors, true); $errormsg .= $mailerrors; } throw new Services_Exception($errormsg); } else { if (!empty($bcc)) { $logmsg = sprintf(tra('Mail sent to user %s'), $mail_user); } $logmsg = !empty($bccmsg) ? $logmsg . ' ' . $bccmsg : $logmsg; if (!empty($msg)) { $logslib->add_log('adminusers', $logmsg, $user); } } $smarty->assign_by_ref('user', $user); } //return to page //if javascript is not enabled $extra = json_decode($input['extra'], true); if (!empty($extra['referer'])) { $this->access->redirect($extra['referer'], tra('Page sent'), null, 'feedback'); } $msg = count($users) === 1 ? tr('The page %0 has been emailed to the following user:'******'The page %0 has been emailed to the following users:', $wikiTpl); $toMsg = !empty($bcc) ? tr('And blind copied to %0.', $bcc) : ''; return ['extra' => 'post', 'feedback' => ['ajaxtype' => 'feedback', 'ajaxheading' => tra('Success'), 'ajaxitems' => $users, 'ajaxmsg' => $msg, 'ajaxtoMsg' => $toMsg, 'modal' => '1']]; } }
/** * @param $calitemId * @param $data */ function watch($calitemId, $data) { global $prefs, $user; $smarty = TikiLib::lib('smarty'); $tikilib = TikiLib::lib('tiki'); $nots = $tikilib->get_event_watches('calendar_changed', $data['calendarId']); if ($prefs['calendar_watch_editor'] != "y" || $prefs['user_calendar_watch_editor'] != "y") { for ($i = count($nots) - 1; $i >= 0; --$i) { if ($nots[$i]['user'] == $data["user"]) { unset($nots[$i]); break; } } } if ($prefs['feature_daily_report_watches'] == 'y') { $reportsManager = Reports_Factory::build('Reports_Manager'); $reportsManager->addToCache($nots, array('event' => 'calendar_changed', 'calitemId' => $calitemId, 'user' => $user)); } if ($nots) { include_once 'lib/webmail/tikimaillib.php'; $mail = new TikiMail(); $smarty->assign('mail_new', $new); $smarty->assign('mail_data', $data); $smarty->assign('mail_calitemId', $calitemId); $foo = parse_url($_SERVER["REQUEST_URI"]); $machine = $tikilib->httpPrefix(true) . dirname($foo["path"]); $machine = preg_replace("!/\$!", "", $machine); // just incase $smarty->assign('mail_machine', $machine); $defaultLanguage = $prefs['site_language']; foreach ($nots as $not) { $mail->setUser($not['user']); $mail_data = $smarty->fetchLang($defaultLanguage, "mail/user_watch_calendar_subject.tpl"); $mail->setSubject($mail_data); $mail_data = $smarty->fetchLang($defaultLanguage, "mail/user_watch_calendar.tpl"); $mail->setText($mail_data); $mail->send(array($not['email'])); } } }
function sendFileGalleryEmailNotification($event, $galleryId, $galleryName, $name, $filename, $description, $action, $user) { global $tikilib, $feature_user_watches, $smarty, $userlib, $sender_email; $nots = array(); $defaultLanguage = $tikilib->get_preference("language", "en"); // Users watching this gallery if ($feature_user_watches == 'y') { $nots = $tikilib->get_event_watches($event, $galleryId); for ($i = count($nots) - 1; $i >= 0; --$i) { $nots[$i]['language'] = $tikilib->get_user_preference($nots[$i]['user'], "language", $defaultLanguage); } } if (count($nots)) { include_once 'lib/webmail/tikimaillib.php'; $mail = new TikiMail(); $smarty->assign('galleryName', $galleryName); $smarty->assign('mail_date', date("U")); $smarty->assign('author', $user); $foo = parse_url($_SERVER["REQUEST_URI"]); $machine = $tikilib->httpPrefix() . dirname($foo["path"]); $smarty->assign('mail_machine', $machine); foreach ($nots as $not) { $mail->setUser($not['user']); $mail_data = $smarty->fetchLang($not['language'], "mail/user_watch_file_gallery_changed_subject.tpl"); $mail->setSubject(sprintf($mail_data, $galleryName)); if ($action == 'upload file') { $mail_data = $smarty->fetchLang($not['language'], "mail/user_watch_file_gallery_upload.tpl"); } elseif ($action == 'remove file') { $mail_data = $smarty->fetchLang($not['language'], "mail/user_watch_file_gallery_remove_file.tpl"); } $mail->setText($mail_data); $mail->buildMessage(); $mail->send(array($not['email'])); } } }
function sendStructureEmailNotification($params) { global $tikilib, $smarty, $prefs; global $structlib; include_once 'lib/structures/structlib.php'; if ($params['action'] == 'move_up' || $params['action'] == 'move_down') { $nots = $structlib->get_watches('', $params['parent_id'], false); } else { $nots = $structlib->get_watches('', $params['page_ref_id']); } if (!empty($nots)) { $defaultLanguage = $prefs['site_language']; $foo = parse_url($_SERVER["REQUEST_URI"]); $machine = $tikilib->httpPrefix() . dirname($foo["path"]); $smarty->assign_by_ref('mail_machine', $machine); include_once 'lib/webmail/tikimaillib.php'; $mail = new TikiMail(); $smarty->assign_by_ref('action', $params['action']); $smarty->assign_by_ref('page_ref_id', $params['page_ref_id']); if (!empty($params['name'])) { $smarty->assign('name', $params['name']); } foreach ($nots as $not) { $mail->setUser($not['user']); $not['language'] = $tikilib->get_user_preference($not['user'], 'language', $defaultLanguage); $mail_subject = $smarty->fetchLang($not['language'], 'mail/user_watch_structure_subject.tpl'); $mail_data = $smarty->fetchLang($not['language'], 'mail/user_watch_structure.tpl'); $mail->setSubject($mail_subject); $mail->setText($mail_data); $mail->buildMessage(); $mail->send(array($not['email'])); } } }
function watch($calitemId, $data) { global $tikilib, $smarty, $prefs; if ($nots = $tikilib->get_event_watches('calendar_changed', $data['calendarId'])) { include_once 'lib/webmail/tikimaillib.php'; $mail = new TikiMail(); $smarty->assign('mail_new', $new); $smarty->assign('mail_data', $data); $smarty->assign('mail_calitemId', $calitemId); $foo = parse_url($_SERVER["REQUEST_URI"]); $machine = $tikilib->httpPrefix() . dirname($foo["path"]); $machine = preg_replace("!/\$!", "", $machine); // just incase $smarty->assign('mail_machine', $machine); $defaultLanguage = $prefs['site_language']; foreach ($nots as $not) { $mail->setUser($not['user']); $mail_data = $smarty->fetchLang($defaultLanguage, "mail/user_watch_calendar_subject.tpl"); $mail->setSubject($mail_data); $mail_data = $smarty->fetchLang($defaultLanguage, "mail/user_watch_calendar.tpl"); $mail->setText($mail_data); $mail->buildMessage(); $mail->send(array($not['email'])); } } }
if (!empty($_REQUEST['bcc'])) { if (!validate_email($_REQUEST['bcc'])) { $smarty->assign('msg', tra('Invalid or unknown email')); $smarty->display('error.tpl'); die; } $mail->setBcc($_REQUEST['bcc']); } $foo = parse_url($_SERVER['REQUEST_URI']); $machine = $tikilib->httpPrefix(true) . dirname($foo['path']); $machine = preg_replace('!/$!', '', $machine); // just incase $smarty->assign_by_ref('mail_machine', $machine); foreach ($_REQUEST['checked'] as $mail_user) { $smarty->assign_by_ref('user', $mail_user); $mail->setUser($mail_user); $mail->setSubject($info['description']); $text = $smarty->fetch('wiki:' . $_REQUEST['wikiTpl']); if (empty($text)) { $smarty->assign('msg', tra('Error')); $smarty->display('error.tpl'); die; } $mail->setHtml($text); $mail->send($userlib->get_user_email($mail_user)); } $smarty->assign_by_ref('user', $user); } if (!isset($_REQUEST['sort_mode'])) { $sort_mode = 'login_asc'; } else {
function sendStructureEmailNotification($params) { global $prefs; $tikilib = TikiLib::lib('tiki'); $smarty = TikiLib::lib('smarty'); $structlib = TikiLib::lib('struct'); $params['event'] = 'structure_' . $params['action']; if ($params['action'] == 'move_up' || $params['action'] == 'move_down') { $nots = $structlib->get_watches('', $params['parent_id'], false); } else { $nots = $structlib->get_watches('', $params['page_ref_id']); } if ($prefs['feature_daily_report_watches'] == 'y') { $reportsManager = Reports_Factory::build('Reports_Manager'); $reportsManager->addToCache($nots, $params); } if (!empty($nots)) { $defaultLanguage = $prefs['site_language']; $foo = parse_url($_SERVER["REQUEST_URI"]); $machine = $tikilib->httpPrefix(true) . dirname($foo["path"]); $smarty->assign_by_ref('mail_machine', $machine); include_once 'lib/webmail/tikimaillib.php'; $smarty->assign_by_ref('action', $params['action']); $smarty->assign_by_ref('page_ref_id', $params['page_ref_id']); if (!empty($params['name'])) { $smarty->assign('name', $params['name']); } foreach ($nots as $not) { $mail = new TikiMail(); $mail->setUser($not['user']); $not['language'] = $tikilib->get_user_preference($not['user'], 'language', $defaultLanguage); $mail_subject = $smarty->fetchLang($not['language'], 'mail/user_watch_structure_subject.tpl'); $mail_data = $smarty->fetchLang($not['language'], 'mail/user_watch_structure.tpl'); $mail->setSubject($mail_subject); $mail->setText($mail_data); $mail->send(array($not['email'])); } } }
/** * This is a function to invite users to temporarily access the site via a token * @param array $emails Emails to send the invite to * @param array $groups Groups that the temporary user should have (Registered is not included unless explicitly added) * @param int $timeout How long the invitation is valid for, in seconds. * @param string $prefix Username of the created users will be the token ID prefixed with this * @param string $path Users will have to autologin using this path on the site using the token * @throws Exception */ function invite_tempuser($emails, $groups, $timeout, $prefix = 'guest', $path = 'index.php') { global $smarty, $user, $prefs; include_once 'lib/webmail/tikimaillib.php'; $mail = new TikiMail(); foreach ($emails as $email) { if (!validate_email($email)) { throw new Exception(tr('Invalid email address "%0"', $email)); } } $foo = parse_url($_SERVER['REQUEST_URI']); $machine = $this->httpPrefix(true) . dirname($foo['path']); $machine = preg_replace('!/$!', '', $machine); // just in case $smarty->assign_by_ref('mail_machine', $machine); $smarty->assign('mail_sender', $user); $smarty->assign('expiry', $user); $mail->setBcc($this->get_user_email($user)); $smarty->assign('token_expiry', $this->get_long_datetime($this->now + $timeout)); require_once 'lib/auth/tokens.php'; foreach ($emails as $email) { $tokenlib = AuthTokens::build($prefs); $token_url = $tokenlib->includeToken($machine . "/{$path}", $groups, $email, $timeout, -1, true, $prefix); include_once 'tiki-sefurl.php'; $token_url = filter_out_sefurl($token_url); $smarty->assign('token_url', $token_url); $mail->setUser($user); $mail->setSubject($smarty->fetch('mail/invite_tempuser_subject.tpl')); $mail->setHtml($smarty->fetch('mail/invite_tempuser.tpl')); if (!$mail->send($email)) { throw new Exception(tr('Unable to send mail to invite "%0"', $email)); } $smarty->assign_by_ref('user', $user); } }