Source for file xPliciMail.class.php

Documentation is available at xPliciMail.class.php

  1. <?php   /*
  2.    *@=@=@=@ START LICENSE @=@=@=@*
  3.    Copyright or © or Copr. Stéphane TRICHET and Nicolas SOTRON
  4.    
  5.    stephane.t@simpliciweb.net and nicolas.s@simpliciweb.net
  6.    
  7.    This software is a computer program whose purpose is to make a
  8.    web hosting platform
  9.    
  10.    This software is governed by the CeCILL  license under French law and
  11.    abiding by the rules of distribution of free software.  You can  use, 
  12.    modify and/ or redistribute the software under the terms of the CeCILL
  13.    license as circulated by CEA, CNRS and INRIA at the following URL
  14.    "http://www.cecill.info". 
  15.    
  16.    As a counterpart to the access to the source code and  rights to copy,
  17.    modify and redistribute granted by the license, users are provided only
  18.    with a limited warranty  and the software's author,  the holder of the
  19.    economic rights,  and the successive licensors  have only  limited
  20.    liability. 
  21.    
  22.    In this respect, the user's attention is drawn to the risks associated
  23.    with loading,  using,  modifying and/or developing or reproducing the
  24.    software by the user in light of its specific status of free software,
  25.    that may mean  that it is complicated to manipulate,  and  that  also
  26.    therefore means  that it is reserved for developers  and  experienced
  27.    professionals having in-depth computer knowledge. Users are therefore
  28.    encouraged to load and test the software's suitability as regards their
  29.    requirements in conditions enabling the security of their systems and/or 
  30.    data to be ensured and,  more generally, to use and operate it in the 
  31.    same conditions as regards security. 
  32.    
  33.    The fact that you are presently reading this means that you have had
  34.    knowledge of the CeCILL license and that you accept its terms.
  35.    *@=@=@=@ END   LICENSE @=@=@=@*
  36.  
  37. */?><?php  
  38.  
  39. /**
  40.  * xPliciMail Class
  41.  * 
  42.  * 
  43.  * @author SimpliciWeb
  44.  * @version $Id: xPliciMail.class.php 913 2008-03-19 15:46:33Z stephanet $
  45.  * @package Common
  46.  * @subpackage FrameWork
  47.  */    
  48. /**
  49.  * Require Mail.php
  50.  */
  51. require_once('Mail.php');
  52. /**
  53.  * Require Mail/mime.php
  54.  */
  55. require_once('Mail/mime.php');
  56.  
  57. /**
  58.  * Abstract class to send an email
  59.  *
  60.  * @author SimpliciWeb
  61.  * @version $Id: xPliciMail.class.php 913 2008-03-19 15:46:33Z stephanet $
  62.  * @package Common
  63.  * @subpackage FrameWork
  64.  */
  65.  
  66.     class xPliciMail  {
  67.         
  68.         
  69.         /**
  70.          * Interface needed for sending mail
  71.          *
  72.          * @var string 
  73.          */
  74.         var $m_interface_needed = "null";
  75.  
  76.         /**
  77.          * Subject for the mail
  78.          *
  79.          * @var string 
  80.          */
  81.         var $m_subject = "";
  82.         /**
  83.          * recipients separated by coma
  84.          *
  85.          * @var string 
  86.          */
  87.         var $m_recipients_by_coma = "";
  88.         /**
  89.          * From email
  90.          *
  91.          * @var string 
  92.          */
  93.         var $m_from_email = "";
  94.         /**
  95.          * From name
  96.          *
  97.          * @var string 
  98.          */
  99.         var $m_from_name = "";
  100.         /**
  101.          * Subject prefix
  102.          *
  103.          * @var string 
  104.          */
  105.         var $m_subject_prefix = "";
  106.  
  107.         /**
  108.          * List of body type authorised : HTML,PLAIN_TEXT
  109.          *
  110.          * @var array 
  111.          */
  112.         var $m_authorized_body_type = array();
  113.         /**
  114.          *  Type of email body
  115.          *
  116.          * @var string 
  117.          */
  118.         var $m_body_type = "";
  119.         
  120.         /**
  121.          * Debug
  122.          *
  123.          * @var bool 
  124.          */
  125.         var $m_debug = false;
  126.  
  127.         
  128.         /**
  129.          * Constructor, init the requests and objects
  130.          *
  131.          * @param bool $send_from_admin_super 
  132.          * @return xPliciMail 
  133.          */
  134.         function xPliciMail($send_from_admin_super false{
  135.  
  136.             global $g_object_loader;
  137.  
  138.             $object_internalmail =$g_object_loader->getTInternalMail();
  139.             $this->m_interface_needed = $object_internalmail->getValueOf("METHOD""null");
  140.  
  141.             $params_for_interface unserialize($object_internalmail->getValueOf("PARAMETERS"serialize(array())));
  142.  
  143.  
  144.             // informations locales à chaque site Internet
  145.             if ($send_from_admin_super == false{
  146.                 // on charge les paramètres pour l'envoi en interne à partir de la
  147.                 // base de donnée du super admin
  148.                 global $g_object_loader;
  149.                 $array_mail_settings array();
  150.                 $object_tglobalscope =$g_object_loader->getTGlobalScopeVariable();
  151.                 $object_tglobalscope->getMailSettings($array_mail_settingsfalse);
  152.                 $this->m_from_email        = getFromArray("from"$array_mail_settings'');
  153.                 $this->m_from_name        = getFromArray("from_name"$array_mail_settings'');
  154.                 $this->m_subject_prefix = getFromArray("subject_prefixe"$array_mail_settings'');
  155.             else {
  156.  
  157.                 $this->m_from_email        = "notexist@simpliciweb.net";
  158.                 $this->m_from_name        = "PLICI Platform";
  159.                 $this->m_subject_prefix = "[PLICI]";
  160.             }
  161.  
  162.             // Set body type authorized
  163.             array_push($this->m_authorized_body_type"HTML");
  164.             array_push($this->m_authorized_body_type"PLAIN_TEXT");
  165.  
  166.             // Set default body type 
  167.             $this->m_body_type = "HTML";
  168.  
  169.  
  170.             if ($this->m_debugprint_r_net($params_for_interface);
  171.             if ($this->m_debugecho_net($this->m_interface_needed);
  172.             
  173.             // Create the mail object using the Mail::factory method
  174.             $this->mail_object =Mail::factory($this->m_interface_needed$params_for_interface);
  175.  
  176.  
  177.  
  178.         
  179.  
  180.         /**
  181.          * Erase subject
  182.          *
  183.          */
  184.         function eraseSubjectPrefix(){
  185.             $this->m_subject_prefix = "";
  186.         }
  187.  
  188.         /**
  189.          * Set subject prefix
  190.          *
  191.          * @param string $p_string 
  192.          */
  193.         function setSubjectPrefix($p_string{
  194.             $this->m_subject_prefix .= $p_string;
  195.         }
  196.  
  197.         function setSubject($p_string{
  198.             $this->m_subject = $p_string;
  199.         }
  200.  
  201.         /**
  202.          * Set recipients separated by coma
  203.          *
  204.          * @param string $p_recipients 
  205.          */
  206.         function setRecipients($p_recipients{
  207.             $this->m_recipients_by_coma = $p_recipients
  208.         }
  209.  
  210.         /**
  211.          * Set from email
  212.          *
  213.          * @param string $p_mail 
  214.          */
  215.         function setFromEmail($p_mail{
  216.             $this->m_from_email = $p_mail;
  217.         }
  218.  
  219.         /**
  220.          * Set from name
  221.          *
  222.          * @param string $p_name 
  223.          */
  224.         function setFromName($p_name{
  225.             $this->m_from_name = $p_name;
  226.         }
  227.         
  228.         /**
  229.          * Clear subject prefix
  230.          *
  231.          */
  232.         function clearSubjectPrefix({
  233.             $this->m_subject_prefix = "";
  234.         }
  235.  
  236.         /**
  237.          * Set body type
  238.          *
  239.          * @param string $p_body_type 
  240.          */
  241.         function setBodyType($p_body_type{
  242.             // Set in upper case
  243.             $_p_body_type strtoupper($p_body_type);
  244.             // Verify if is valid type
  245.             if (in_array($_p_body_type$this->m_authorized_body_type))
  246.             {
  247.                 // Valid type so set it
  248.                 $this->m_body_type = $_p_body_type;
  249.             }
  250.         }
  251.         
  252.         /**
  253.          * Send email
  254.          *
  255.          * @param string $p_content 
  256.          * @return bool TRUE on error
  257.          */
  258.         function xSend($p_content{
  259.  
  260.             // On construit proprement le from et le from_name
  261.             if (trim($this->m_from_name!= ""{
  262.                 $from_name str_replace("\"""'"$this->m_from_name);
  263.                 $from "\"".$from_name."\" <".$this->m_from_email.">";
  264.             }
  265.  
  266.             $headers array(
  267.                             'From' => $from,
  268.                             'Subject' => $this->m_subject,
  269.                             'Content-Type' => 'text/html'
  270.             );
  271.  
  272.  
  273.  
  274.             $array_recipients explode(","$this->m_recipients_by_coma);
  275.  
  276.  
  277.             if (isset($array_recipients&& isset($array_recipients[0]))
  278.                 $headers['To']     $array_recipients[0];
  279.  
  280.             global $g_object_loader;
  281.             
  282.  
  283.             // on crée un mail au format texte BRUT et texte HTML
  284.             $object_dbconnexion =$g_object_loader->getDbConnexion();
  285.             $object_Mail_mime new Mail_mime("WINNT"==PHP_OS?"\r":""."\n");            $text_html $p_content;
  286.             $text_html $p_content;
  287.             $text_brut $object_dbconnexion->translate("HTML_TO_PLAIN"$text_html);
  288.             $object_Mail_mime->setTXTBody($text_brutfalsefalse);
  289.  
  290.             // If necessary use email HTML headers
  291.             if ("HTML" == $this->m_body_type)
  292.             {
  293.                 $object_Mail_mime->setHTMLBody($text_htmlfalsetrue);    
  294.             }
  295.  
  296.             $p_content $object_Mail_mime->get();
  297.  
  298.             // on ajoute les headers pour le mime_type            
  299.             $headers array_merge($headers$object_Mail_mime->headers());
  300.             
  301.             $headers['Subject'$object_dbconnexion->translate("HTML_TO_PLAIN_STRING"
  302.                 ($this->m_subject_prefix != ""?" ".$this->m_subject_prefix." ":"").$headers['Subject']);
  303.  
  304.  
  305.  
  306.             // add an empty because it help when using the Mail interface
  307.             //$headers[''] = "";
  308.                 
  309.             if ($this->m_debugprint_r_net($array_recipients);
  310.             if ($this->m_debugprint_r_net($headers);
  311.             if ($this->m_debugecho_net($p_content);
  312.  
  313.             $value_to_return $this->mail_object->send($array_recipients$headers$p_content);
  314.             
  315.             $there_is_an_error false;
  316.             if (PEAR::isError($value_to_return)) {
  317.                 trigger_error("[".date("D M d G:i:s Y")."] "."xPliciMail.class.php error: ".$value_to_return->getMessage()."\n");
  318.                 if ($this->m_debugecho_net("[".date("D M d G:i:s Y")."] "."xPliciMail.class.php error: ".$value_to_return->getMessage()."\n");
  319.                 $there_is_an_error true;
  320.             }
  321.  
  322.                 
  323.             return $there_is_an_error;
  324.                 
  325.         
  326.         }
  327.         
  328.         /**
  329.          * Convert cotent with base mail template
  330.          *
  331.          * @param string $p_content 
  332.          * @return string 
  333.          */
  334.         function convertContentWithBaseMailTemplate ($p_content{
  335.             
  336.             // $p_content
  337.             // $g_object_loader
  338.             // 
  339.             // on ajoute les headers et footer obligé au mail
  340.             // en utilisant un template
  341.             global $g_object_loader;
  342.             $smarty_for_mail =$g_object_loader->getSmarty_custom();
  343.  
  344.             //Save cache statut
  345.             $cache_backup_status $smarty_for_mail->canNotBeCached();
  346.  
  347.             //Disabled Cache
  348.             $smarty_for_mail->setCannotBeCached(true);
  349.  
  350.             $smarty_for_mail->assign_by_ref('mail_content'$p_content);
  351.             
  352.             // il faut aller chercher le template dans le front
  353.             $object_siteinformation =$g_object_loader->getSiteInformation();
  354.             $prefix_for_front "";
  355.             $file_mail_sent_name 'mail_base.html';
  356.             //if ($object_siteinformation->isAdmin())
  357.                 $object_siteinformation->getExistTemplateNotCompiledFilePath($file_mail_sent_name$prefix_for_fronttrue);
  358.  
  359.             $p_content $smarty_for_mail->fetch($prefix_for_front.'mail_base.html');
  360.  
  361.             // Set old cache status
  362.             $smarty_for_mail->setCannotBeCached($cache_backup_status);
  363.  
  364.             // on code les adresses pour qu'elles soient absolues
  365.             $object_siteinformation =$g_object_loader->getSiteInformation();
  366.             $httpservername $object_siteinformation->getHttpServername(true);
  367.             $p_content ereg_replace ("(href|src)=([\"'])/""\\1=\\2".$httpservername."/"$p_content);
  368.             
  369.             return $p_content
  370.         }
  371.     
  372.     }
  373.  
  374. ?>

Documentation generated on Tue, 25 Mar 2008 15:37:32 +0100 by phpDocumentor 1.3.2