コード例 #1
0
ファイル: email.php プロジェクト: davidmottet/automne
 /**
  * Send the mail
  *
  * @return boolean true on success, false on failure
  * @access public
  */
 function sendEmail()
 {
     if ($this->hasError()) {
         $this->raiseError('Cannot send email, error appened');
         return false;
     }
     $emailSent = true;
     if (!$this->_emailTo) {
         $this->raiseError('emailTo can not be null');
         return false;
     }
     $OB = "----=_OuterBoundary_000";
     $IB = "----=_InnerBoundery_001";
     $encoding = $this->_emailEncoding ? $this->_emailEncoding : APPLICATION_DEFAULT_ENCODING;
     if ($this->_template) {
         //if template is provided for email HTML, use it
         $template = new CMS_file($this->_template);
         $templateContent = $template->getContent();
         $replace = array('{{subject}}' => $this->_subject, '{{body}}' => $this->_emailHTML ? $this->_emailHTML : $this->convertTextToHTML($this->_body), '{{footer}}' => $this->convertTextToHTML($this->_footer), '{{href}}' => CMS_websitesCatalog::getMainURL(), '{{charset}}' => strtoupper($encoding));
         $Html = str_replace(array_keys($replace), $replace, $templateContent);
     } elseif ($this->_emailHTML) {
         //if HTML content is provided for email, use it
         //if this mail contain relative link, append default website address
         if (io::strpos($this->_emailHTML, 'href="/') !== false || io::strpos($this->_emailHTML, 'src="/') !== false) {
             $url = CMS_websitesCatalog::getMainURL();
             $this->_emailHTML = str_replace(array('href="/', 'src="/'), array('href="' . $url . '/', 'src="' . $url . '/'), $this->_emailHTML);
         }
         $Html = $this->_emailHTML;
     } else {
         //else use text content converted to HTML
         $Html = $this->convertTextToHTML($this->_body . ($this->_footer ? "\n\n" . $this->_footer : ''));
     }
     $Text = $this->_body ? $this->_body . ($this->_footer ? "\n\n" . $this->_footer : '') : "Sorry, but you need an HTML compatible mailer to read this mail...";
     $From = $this->_emailFrom ? $this->_emailFrom : APPLICATION_POSTMASTER_EMAIL;
     $FromName = $this->_fromName ? $this->_fromName : '';
     $toUsers = is_array($this->_emailTo) && $this->_emailTo ? $this->_emailTo : array($this->_emailTo);
     $cc = is_array($this->_cc) && $this->_cc ? $this->_cc : ($this->_cc ? array($this->_cc) : '');
     $bcc = is_array($this->_bcc) && $this->_bcc ? $this->_bcc : ($this->_bcc ? array($this->_bcc) : '');
     $toNames = is_array($this->_toName) && $this->_toName ? $this->_toName : array($this->_toName);
     $Error = $this->_error ? $this->_error : '';
     $Subject = $this->_subject;
     $AttmFiles = $this->_files;
     //Messages start with text/html alternatives in OB
     $Msg = "This is a multi-part message in MIME format.\n";
     $Msg .= "\n--" . $OB . "\n";
     $Msg .= "Content-Type: multipart/alternative;\n\tboundary=\"" . $IB . "\"\n\n";
     //plaintext section
     $Msg .= "\n--" . $IB . "\n";
     $Msg .= "Content-Type: text/plain;\n\tcharset=\"" . $encoding . "\"\n";
     $Msg .= "Content-Transfer-Encoding: 8bit\n\n";
     // plaintext goes here
     $Msg .= $Text . "\n\n";
     // html section
     $Msg .= "\n--" . $IB . "\n";
     $Msg .= "Content-Type: text/html;\n\tcharset=\"" . $encoding . "\"\n";
     $Msg .= "Content-Transfer-Encoding: base64\n\n";
     // html goes here
     $Msg .= chunk_split(base64_encode($Html), 76, "\n") . "\n\n";
     // end of IB
     $Msg .= "\n--" . $IB . "--\n";
     // attachments
     if (is_array($AttmFiles) && $AttmFiles) {
         foreach ($AttmFiles as $AttmFile) {
             $patharray = explode("/", $AttmFile);
             $FileName = $patharray[count($patharray) - 1];
             $Msg .= "\n--" . $OB . "\n";
             $Msg .= "Content-Type: application/octet-stream;\n\tname=\"" . $FileName . "\"\n";
             $Msg .= "Content-Transfer-Encoding: base64\n";
             $Msg .= "Content-Disposition: attachment;\n\tfilename=\"" . $FileName . "\"\n\n";
             //file goes here
             $fd = fopen($AttmFile, "r");
             $FileContent = fread($fd, filesize($AttmFile));
             fclose($fd);
             $FileContent = chunk_split(base64_encode($FileContent), 76, "\n");
             $Msg .= $FileContent;
             $Msg .= "\n\n";
         }
     }
     if (LOG_SENDING_MAIL) {
         global $cms_user;
         $user = $cms_user ? $cms_user : CMS_profile_usersCatalog::getById(ROOT_PROFILEUSER_ID);
     }
     //message ends
     $Msg .= "\n--" . $OB . "--\n";
     foreach ($toUsers as $key => $to) {
         if (sensitiveIO::isValidEmail($to)) {
             $headers = "MIME-Version: 1.0\n";
             if ($FromName) {
                 $headers .= "From: " . $this->EncodeHeader($FromName) . " <" . $From . ">\n";
                 $headers .= "Reply-To: " . $this->EncodeHeader($FromName) . " <" . $From . ">\n";
                 $headers .= "Return-Path: " . $this->EncodeHeader($FromName) . " <" . $From . ">\n";
                 $headers .= "X-Sender: " . $this->EncodeHeader($FromName) . " <" . $From . ">\n";
             } else {
                 $headers .= "From: " . $From . "\n";
                 $headers .= "Reply-To: " . $From . "\n";
                 $headers .= "Return-Path: " . $From . "\n";
                 $headers .= "X-Sender: " . $From . "\n";
             }
             if (isset($toNames[$key]) && $toNames[$key]) {
                 $to = $this->EncodeHeader($toNames[$key]) . " <" . $to . ">";
             }
             if ($Error) {
                 $headers .= "Errors-To: " . $Error . "\n";
             }
             if ($cc) {
                 $headers .= "Cc: " . implode(',', $cc) . "\n";
             }
             if ($bcc) {
                 $headers .= "Bcc: " . implode(',', $bcc) . "\n";
             }
             /*$headers.="User-Agent: Automne (TM)\n";*/
             //Cause email to be reported as spam
             $headers .= "X-Mailer: Automne (TM)\n";
             $headers .= "X-Priority: 3\n";
             $headers .= "Content-Type: multipart/mixed;\n\tboundary=\"" . $OB . "\"\n";
             //Check drop emails list (Automne default emails)
             if (!in_array($to, $this->_drop) && !in_array($From, $this->_drop)) {
                 //log in the cms_error_log the complete email
                 if (LOG_APPLICATION_MAIL) {
                     $this->log($to . "\n" . $this->EncodeHeader($Subject) . "\n\n" . $Msg);
                 }
                 //if mail deactivated always return true
                 if (NO_APPLICATION_MAIL) {
                     return $emailSent;
                 } else {
                     //send emails
                     $sent = @mail($to, $this->EncodeHeader($Subject), $Msg, $headers);
                 }
                 $emailSent = $emailSent && $sent;
                 if (LOG_SENDING_MAIL) {
                     $log = new CMS_log();
                     $log->logMiscAction(CMS_log::LOG_ACTION_SEND_EMAIL, $user, 'Email To ' . $to . ', From : ' . $From . ', Subject : ' . $Subject . ', Sent : ' . ($sent ? 'Yes' : 'Error'));
                 }
             } else {
                 if (LOG_SENDING_MAIL) {
                     $log = new CMS_log();
                     $log->logMiscAction(CMS_log::LOG_ACTION_SEND_EMAIL, $user, 'Email To ' . $to . ', From : ' . $From . ', Subject : ' . $Subject . ', Sent : No, Dropped because sender or receiver address is under Automne drop address list');
                 } else {
                     $this->raiseError('Email to ' . $to . ', from : ' . $From . ' (subject : ' . $Subject . '), Dropped because sender or receiver address is under Automne drop address list');
                 }
             }
         } else {
             if (LOG_SENDING_MAIL) {
                 $log = new CMS_log();
                 $log->logMiscAction(CMS_log::LOG_ACTION_SEND_EMAIL, $user, 'Email To ' . $to . ', From : ' . $From . ', Subject : ' . $Subject . ', Sent : No, Dropped because receiver address is not valid');
             } else {
                 $this->raiseError('Email to ' . $to . ', from : ' . $From . ' (subject : ' . $Subject . '), Dropped because receiver address is not valid');
             }
         }
     }
     if (!$emailSent) {
         $this->raiseError('Email was not sent, please check your sendmail configuration or SMTP connection in php.ini');
     }
     return $emailSent;
 }
コード例 #2
0
}
if ($objectId && (!isset($object) || $object->hasError())) {
    CMS_grandFather::raiseError('Error, objectId does not exists or has an error : ' . $objectId);
    $view->setContent($content);
    $view->show();
}
if (isset($object)) {
    //load item if any
    if ($itemId) {
        $item = new CMS_poly_object($objectId, $itemId);
        if ($action == 'save' || $action == 'save-validate') {
            $itemLabel = sensitiveIO::sanitizeJSString($item->getLabel());
            if ($object->isPrimaryResource()) {
                //put a lock on the resource or warn user if item is already locked by another user
                if ($lock = $item->getLock()) {
                    $lockUser = CMS_profile_usersCatalog::getById($lock);
                    if ($lockUser->getUserId() != $cms_user->getUserId()) {
                        $lockDate = $item->getLockDate();
                        $date = $lockDate ? $lockDate->getLocalizedDate($cms_language->getDateFormat() . ' @ H:i:s') : '';
                        $name = sensitiveIO::sanitizeJSString($lockUser->getFullName());
                        CMS_grandFather::raiseError('Error, item ' . $itemId . ' is locked by ' . $lockUser->getFullName());
                        $jscontent = "\n\t\t\t\t\t\tAutomne.message.popup({\n\t\t\t\t\t\t\tmsg: \t\t\t\t'{$cms_language->getJSMessage(MESSAGE_PAGE_ELEMENT_LOCKED, array($itemLabel, $name, $date), MOD_POLYMOD_CODENAME)}',\n\t\t\t\t\t\t\tbuttons: \t\t\tExt.MessageBox.OK,\n\t\t\t\t\t\t\tclosable: \t\t\tfalse,\n\t\t\t\t\t\t\ticon: \t\t\t\tExt.MessageBox.ERROR\n\t\t\t\t\t\t});";
                        $view->addJavascript($jscontent);
                        $view->setContent($content);
                        $view->show();
                    }
                } else {
                    $item->lock($cms_user);
                }
            }
            //check user rights on item
コード例 #3
0
 /**
  * Returns the label for current status.
  *
  * @param CMS_language $language : Current language to get label
  * @return string label
  * @access public
  */
 function getStatusLabel($language)
 {
     //Hack : check for non-sense status (usually it is a page which creation is not properly done)
     if ($this->_publication == RESOURCE_PUBLICATION_NEVERVALIDATED && !$this->_editions) {
         $this->addEdition(RESOURCE_EDITION_CONTENT, $user);
         $this->writeToPersistence();
     }
     $img_status = $this->_publication == RESOURCE_PUBLICATION_NEVERVALIDATED ? "rond" : "carre";
     if ($this->_publication == RESOURCE_PUBLICATION_PUBLIC) {
         $img_status .= "_pub";
     }
     if ($this->_proposedFor == RESOURCE_LOCATION_DELETED) {
         $img_status .= "_sup";
     }
     if ($this->_proposedFor == RESOURCE_LOCATION_ARCHIVED) {
         $img_status .= "_arc";
     }
     if (($this->_editions & RESOURCE_EDITION_BASEDATA || $this->_editions & RESOURCE_EDITION_CONTENT) && !($this->_validationsRefused & RESOURCE_EDITION_BASEDATA) && !($this->_validationsRefused & RESOURCE_EDITION_CONTENT)) {
         $img_status .= "-o";
     } elseif ($this->_validationsRefused & RESOURCE_EDITION_BASEDATA || $this->_validationsRefused & RESOURCE_EDITION_CONTENT || $this->_validationsRefused & RESOURCE_EDITION_LOCATION) {
         $img_status .= "-r";
     } else {
         $img_status .= "-v";
     }
     if ($this->_editions & RESOURCE_EDITION_SIBLINGSORDER) {
         if ($this->_validationsRefused & RESOURCE_EDITION_SIBLINGSORDER) {
             $img_siblings = "orderefuse";
         } else {
             $img_siblings = "ordervalider";
         }
     }
     if ($this->_editions & RESOURCE_EDITION_MOVE) {
         if ($this->_validationsRefused & RESOURCE_EDITION_MOVE) {
             $img_siblings = "mouvrefuse";
         } else {
             $img_siblings = "mouvalider";
         }
     }
     if ($this->getDraft() && $img_status == 'rond-o') {
         $img_status = 'draft';
     }
     $label = $this->_getStatusLabel($img_status);
     $label .= isset($img_siblings) ? ', ' . $this->_getStatusLabel($img_siblings) : '';
     if ($lockUserId = $this->getLock()) {
         $lockUser = CMS_profile_usersCatalog::getById($lockUserId);
         $lockDate = $this->getLockDate();
         if (is_object($lockUser) && is_object($lockDate)) {
             $label .= ' - ' . $language->getMessage(self::MESSAGE_STATUS_LOCKEDBY) . ' ' . $lockUser->getFullName() . ' (' . $lockDate->getLocalizedDate($language->getDateFormat() . ' - H:i:s') . ')';
         } else {
             $label .= ' - ' . $language->getMessage(self::MESSAGE_STATUS_LOCKED);
         }
     }
     if ($this->getDraft()) {
         $label .= $img_status != 'draft' ? ' - ' . $language->getMessage(self::MESSAGE_STATUS_DRAFT) : $language->getMessage(self::MESSAGE_STATUS_DRAFT);
     }
     /*if ($this->getDraft() && $img_status == 'rond-o') {
     			$label .= $language->getMessage(self::MESSAGE_STATUS_DRAFT);
     		}*/
     return $label;
 }