/**
  * @param array(string) addresses to send message to
  * @param message string
  * @param messageParam array(string)
  * @param message subject
  * @param message subjParam
  * @return void
  * @access public
  */
 function CMS_setMessages($addresses, $message, $subject, $withApplicationLabel = true)
 {
     // loop through addresses and create email message
     foreach ($addresses as $address) {
         $email = new CMS_email();
         if ($email->setEmailTo($address)) {
             $email->setSubject($subject, $withApplicationLabel);
             $email->setBody($message);
             $this->_messages[] = $email;
         } else {
             $this->raiseError("Email Catalog: mail not registered:" . $address);
         }
     }
 }
Exemple #2
0
 /**
  * Module script task
  * @param array $parameters the task parameters
  *		task : string task to execute
  *		object : string module codename for the task
  *		field : string module uid
  *		...	: optional field relative parameters
  * @return Boolean true/false
  * @access public
  */
 function scriptTask($parameters)
 {
     switch ($parameters['task']) {
         case 'emailNotification':
             @set_time_limit(300);
             $module = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID());
             //create a new script for all recipients
             $allUsers = $this->_getRecipients($parameters['object']);
             foreach ($allUsers as $userId) {
                 //add script to send email for user if needed
                 CMS_scriptsManager::addScript($module, array('task' => 'emailSend', 'user' => $userId, 'field' => $parameters['field'], 'object' => $parameters['object']));
             }
             //then set sending date to current date
             $sendingDate = new CMS_date();
             $sendingDate->setNow();
             $this->_subfieldValues[1]->setValue($sendingDate->getDBValue());
             $this->writeToPersistence();
             break;
         case 'emailSend':
             @set_time_limit(300);
             $params = $this->getParamsValues();
             if (!sensitiveIO::isPositiveInteger($parameters['user'])) {
                 return false;
             }
             //instanciate script related item
             $item = CMS_poly_object_catalog::getObjectByID($parameters['object'], false, true);
             if (!is_object($item) || $item->hasError()) {
                 return false;
             }
             //instanciate user
             $cms_user = new CMS_profile_user($parameters['user']);
             //check user
             if (!$cms_user || $cms_user->hasError() || !$cms_user->isActive() || $cms_user->isDeleted() || !sensitiveIO::isValidEmail($cms_user->getEmail())) {
                 return false;
             }
             $cms_language = $cms_user->getLanguage();
             //globalise cms_user and cms_language
             $GLOBALS['cms_language'] = $cms_user->getLanguage();
             $GLOBALS['cms_user'] = $cms_user;
             //check user clearance on object
             if (!$item->userHasClearance($cms_user, CLEARANCE_MODULE_VIEW)) {
                 return false;
             }
             //create email subject
             $parameters['item'] = $item;
             $parameters['public'] = true;
             $polymodParsing = new CMS_polymod_definition_parsing($params['emailSubject'], false);
             $subject = $polymodParsing->getContent(CMS_polymod_definition_parsing::OUTPUT_RESULT, $parameters);
             $body = '';
             //create email body
             if ($params['emailBody']['type'] == 1) {
                 //send body
                 $parameters['module'] = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID());
                 $polymodParsing = new CMS_polymod_definition_parsing($params['emailBody']['html'], true, CMS_polymod_definition_parsing::PARSE_MODE, $parameters['module']);
                 $body = $polymodParsing->getContent(CMS_polymod_definition_parsing::OUTPUT_RESULT, $parameters);
             } elseif ($params['emailBody']['type'] == 2) {
                 //send a page
                 $page = CMS_tree::getPageById($params['emailBody']['pageID']);
                 if (!$page || $page->hasError()) {
                     $this->raiseError('Page ID is not a valid page : ' . $params['emailBody']['pageID']);
                     return false;
                 }
                 $pageHTMLFile = new CMS_file($page->getHTMLURL(false, false, PATH_RELATIVETO_FILESYSTEM));
                 if (!$pageHTMLFile->exists()) {
                     $this->raiseError('Page HTML file does not exists : ' . $page->getHTMLURL(false, false, PATH_RELATIVETO_FILESYSTEM));
                     return false;
                 }
                 $body = $pageHTMLFile->readContent();
                 //create page URL call
                 $polymodParsing = new CMS_polymod_definition_parsing($params['emailBody']['pageURL'], false);
                 $pageURL = $polymodParsing->getContent(CMS_polymod_definition_parsing::OUTPUT_RESULT, $parameters);
                 parse_str($pageURL, $GLOBALS['_REQUEST']);
                 //$GLOBALS['_REQUEST']
                 //parse and eval HTML page
                 $cms_page_included = true;
                 $GLOBALS['cms_page_included'] = $cms_page_included;
                 //eval() the PHP code
                 $body = sensitiveIO::evalPHPCode($body);
                 $website = $page->getWebsite();
                 $webroot = $website->getURL();
                 //replace URLs values
                 $replace = array('="/' => '="' . $webroot . '/', "='/" => "='" . $webroot . "/", "url(/" => "url(" . $webroot . "/");
                 $body = str_replace(array_keys($replace), $replace, $body);
             } else {
                 $this->raiseError('No valid email type to send : ' . $params['emailBody']['type']);
                 return false;
             }
             if (isset($sendmail)) {
                 //$body .= print_r($sendmail,true);
             }
             //drop email sending
             if (isset($sendmail) && $sendmail === false) {
                 return false;
             }
             //if no body for email or if sendmail var is set to false, quit
             if (!$body) {
                 $this->raiseError('No email body to send ... Email parameters : user : '******'user'] . ' - object ' . $parameters['object']);
                 return false;
             }
             //This code is for debug purpose only.
             //$testFile = new CMS_file('/test/test_'.$cms_user->getUserId().'.php', CMS_file::WEBROOT);
             //$testFile->setContent($body);
             //$testFile->writeToPersistence();
             // Set email
             $email = new CMS_email();
             $email->setSubject($subject);
             $email->setEmailHTML($body);
             $email->setEmailTo($cms_user->getEmail());
             if ($params['includeFiles']) {
                 //check for file fields attached to object
                 $files = array();
                 $this->_getFieldsFiles($item, $files);
                 if (sizeof($files)) {
                     foreach ($files as $file) {
                         $email->setFile($file);
                     }
                 }
             }
             //set email From
             if (!$params['emailFrom']) {
                 $email->setFromName(APPLICATION_LABEL);
                 $email->setEmailFrom(APPLICATION_POSTMASTER_EMAIL);
             } else {
                 $email->setFromName($params['emailFrom']);
                 $email->setEmailFrom($params['emailFrom']);
             }
             //Send
             if ($email->sendEmail()) {
                 //store email sent number
                 $this->_subfieldValues[2]->setValue($this->_subfieldValues[2]->getValue() + 1);
                 $this->writeToPersistence();
                 return true;
             } else {
                 return false;
             }
             break;
         default:
             $this->raiseError('No valid task given : ' . $parameters['task']);
             return false;
             break;
     }
 }
Exemple #3
0
    $body = "A 404 Error occured on your website.\n";
    $body .= "\n\n";
    $body .= 'The requested file : ' . CMS_websitesCatalog::getMainURL() . $_SERVER['REQUEST_URI'] . ' was not found.' . "\n\n";
    $body .= 'From (Referer) : ' . (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '') . "\n\n";
    $body .= 'Date : ' . date('r') . "\n\n";
    if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
        $body .= 'User : '******'REMOTE_ADDR'] . ' (' . $_SERVER['HTTP_ACCEPT_LANGUAGE'] . ')' . "\n\n";
    } else {
        $body .= 'User : '******'REMOTE_ADDR'] . "\n\n";
    }
    if (isset($_SERVER['HTTP_USER_AGENT'])) {
        $body .= 'Browser : ' . $_SERVER['HTTP_USER_AGENT'] . "\n\n";
    }
    $body .= 'Host : ' . $_SERVER['HTTP_HOST'] . ' (' . $_SERVER['SERVER_ADDR'] . ")\n\n";
    $body .= 'This email is automaticaly sent from your website. You can stop this sending with the parameter ERROR404 EMAIL ALERT.';
    $mail = new CMS_email();
    $mail->setSubject("404 Error in " . APPLICATION_LABEL);
    $mail->setBody($body);
    $mail->setEmailFrom(APPLICATION_POSTMASTER_EMAIL . "<" . APPLICATION_POSTMASTER_EMAIL . ">");
    $mail->setEmailTo(APPLICATION_MAINTAINER_EMAIL);
    $mainURL = CMS_websitesCatalog::getMainURL();
    $cms_language = CMS_languagesCatalog::getByCode('en');
    $mail->setFooter($cms_language->getMessage(CMS_emailsCatalog::MESSAGE_EMAIL_BODY_URLS, array(APPLICATION_LABEL, $mainURL . "/", $mainURL . PATH_ADMIN_WR . "/")));
    $mail->setTemplate(PATH_MAIL_TEMPLATES_FS);
    $mail->sendEmail();
}
//try to get website by path to serve specific 404 page
$path = pathinfo(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), PATHINFO_DIRNAME);
$website = null;
if ($path && $path != '/') {
    $websites = CMS_websitesCatalog::getAll('order');