Advertisement
plas71k

Ioncube - decoded file

Dec 12th, 2012
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.94 KB | None | 0 0
  1. <?php
  2. class hanEmail
  3. {
  4.  
  5.     public $emailer = NULL;
  6.     public $header = NULL;
  7.     public $footer = NULL;
  8.     public $from = NULL;
  9.     public $to = NULL;
  10.     public $bcc = array( );
  11.     public $subject = NULL;
  12.     public $message = NULL;
  13.     public $html_email = FALSE;
  14.     private $_words = NULL;
  15.     private $temp_headers = array( );
  16.     private $_attachments = array( );
  17.     protected $registry = NULL;
  18.     protected $DB = NULL;
  19.     protected $settings = NULL;
  20.     protected $request = NULL;
  21.     protected $lang = NULL;
  22.     protected $member = NULL;
  23.     protected $memberData = NULL;
  24.  
  25.     public function __construct( $registry )
  26.     {
  27.         $this->registry = $registry;
  28.         $this->DB = $this->registry->DB( );
  29.         $this->settings =& $this->registry->fetchSettings( );
  30.         $this->request =& $this->registry->fetchRequest( );
  31.         $this->lang = $this->registry->getClass( "class_localization" );
  32.         $this->member = $this->registry->member( );
  33.         $this->memberData =& $this->registry->member( )->fetchMemberData( );
  34.     }
  35.  
  36.     public function init( )
  37.     {
  38.         $this->header = $this->settings['email_header'] ? $this->settings['email_header'] : "";
  39.         $this->footer = $this->settings['email_footer'] ? $this->settings['email_footer'] : "";
  40.         $classToLoad = IPSLib::loadlibrary( IPS_KERNEL_PATH."classEmail.php", "classEmail" );
  41.         $this->emailer = new $classToLoad( array(
  42.             "debug" => $this->settings['fake_mail'] ? $this->settings['fake_mail'] : "0",
  43.             "debug_path" => DOC_IPS_ROOT_PATH."_mail",
  44.             "smtp_host" => $this->settings['smtp_host'] ? $this->settings['smtp_host'] : "localhost",
  45.             "smtp_port" => intval( $this->settings['smtp_port'] ) ? intval( $this->settings['smtp_port'] ) : 25,
  46.             "smtp_user" => $this->settings['smtp_user'],
  47.             "smtp_pass" => $this->settings['smtp_pass'],
  48.             "smtp_helo" => $this->settings['smtp_helo'],
  49.             "method" => $this->settings['mail_method'],
  50.             "wrap_brackets" => $this->settings['mail_wrap_brackets'],
  51.             "extra_opts" => $this->settings['php_mail_extra'],
  52.             "charset" => IPS_DOC_CHAR_SET,
  53.             "html" => $this->html_email
  54.         ) );
  55.     }
  56.  
  57.     public function clearHeaders( )
  58.     {
  59.         $this->temp_headers = array( );
  60.     }
  61.  
  62.     public function setHeader( $key, $value )
  63.     {
  64.         $this->temp_headers[$key] = $value;
  65.     }
  66.  
  67.     public function sendMail( )
  68.     {
  69.         $this->init( );
  70.         if ( count( $this->_attachments ) )
  71.         {
  72.             foreach ( $this->_attachments as $a )
  73.             {
  74.                 $this->emailer->addAttachment( $a[0], $a[1], $a[2] );
  75.             }
  76.         }
  77.         $this->settings['board_name'] = $this->cleanMessage( $this->settings['board_name'] );
  78.         $this->emailer->setFrom( $this->from ? $this->from : $this->settings['email_out'], $this->settings['board_name'] );
  79.         $this->emailer->setTo( $this->to );
  80.         foreach ( $this->bcc as $bcc )
  81.         {
  82.             $this->emailer->addBCC( $bcc );
  83.         }
  84.         if ( count( $this->temp_headers ) )
  85.         {
  86.             foreach ( $this->temp_headers as $k => $v )
  87.             {
  88.                 $this->emailer->setHeader( $k, $v );
  89.             }
  90.         }
  91.         $this->emailer->setSubject( $this->_cleanSubject( $this->subject ) );
  92.         $this->emailer->setBody( $this->message );
  93.         $this->emailer->sendMail( );
  94.         $this->html_email = FALSE;
  95.         if ( $this->emailer->error )
  96.         {
  97.             return $this->fatalError( $this->emailer->error_msg, $this->emailer->error_help );
  98.         }
  99.         return true;
  100.     }
  101.  
  102.     public function getTemplate( $name, $language = "", $lang_file = "public_email_content", $app = "core" )
  103.     {
  104.         if ( $name == "" )
  105.         {
  106.             $this->error++;
  107.             $this->fatalError( "A valid email template ID was not passed to the email library during template parsing", "" );
  108.         }
  109.         if ( !$language )
  110.         {
  111.             $language = IPSLib::getdefaultlanguage( );
  112.         }
  113.         $this->registry->class_localization->loadLanguageFile( array(
  114.             $lang_file
  115.         ), $app, $language, TRUE );
  116.         if ( !isset( $this->lang->words[$name] ) )
  117.         {
  118.             if ( $language == IPSLib::getdefaultlanguage( ) )
  119.             {
  120.                 $this->fatalError( "Could not find an email template with an ID of '{$name}'", "" );
  121.             }
  122.             else
  123.             {
  124.                 $this->registry->class_localization->loadLanguageFile( array(
  125.                     $lang_file
  126.                 ), $app, IPSLib::getdefaultlanguage( ) );
  127.                 if ( !isset( $this->lang->words[$name] ) )
  128.                 {
  129.                     $this->fatalError( "Could not find an email template with an ID of '{$name}'", "" );
  130.                 }
  131.             }
  132.         }
  133.         if ( isset( $this->lang->words["subject__".$name] ) )
  134.         {
  135.             $this->subject = stripslashes( $this->lang->words["subject__".$name] );
  136.         }
  137.         $this->template = stripslashes( $this->lang->words['email_header'] ).stripslashes( $this->lang->words[$name] ).stripslashes( $this->lang->words['email_footer'] );
  138.     }
  139.  
  140.     public function buildMessage( $words, $noClean = false )
  141.     {
  142.         if ( $this->template == "" )
  143.         {
  144.             $this->error++;
  145.             $this->fatalError( "Could not build the email message, no template assigned", "Make sure a template is assigned first." );
  146.         }
  147.         $this->message = $this->template;
  148.         if ( $noClean )
  149.         {
  150.             $this->message = str_replace( "\n", "<br />", str_replace( "\r", "", $this->message ) );
  151.         }
  152.         $words['BOARD_ADDRESS'] = $this->settings['board_url']."/index.".$this->settings['php_ext'];
  153.         $words['WEB_ADDRESS'] = $this->settings['home_url'];
  154.         $words['BOARD_NAME'] = $this->settings['board_name'];
  155.         $words['SIGNATURE'] = $this->settings['signature'] ? $this->settings['signature'] : "";
  156.         if ( !$noClean )
  157.         {
  158.             foreach ( $words as $k => $v )
  159.             {
  160.                 $words[$k] = $this->cleanMessage( $v );
  161.             }
  162.         }
  163.         $this->_words = $words;
  164.         $this->message = preg_replace_callback( "/<#(.+?)#>/", array(
  165.             $this,
  166.             "_swapWords"
  167.         ), $this->message );
  168.         $this->subject = preg_replace_callback( "/<#(.+?)#>/", array(
  169.             $this,
  170.             "_swapWords"
  171.         ), $this->subject );
  172.         $this->_words = array( );
  173.     }
  174.  
  175.     private function _swapWords( $matches )
  176.     {
  177.         return $this->_words[$matches[1]];
  178.     }
  179.  
  180.     private function _cleanSubject( $subject )
  181.     {
  182.         $subject = strip_tags( $subject );
  183.         $subject = str_replace( "&#036;", "\$", $subject );
  184.         $subject = str_replace( "&#33;", "!", $subject );
  185.         $subject = str_replace( "&#34;", "\"", $subject );
  186.         $subject = str_replace( "&#39;", "'", $subject );
  187.         $subject = str_replace( "&#124;", "|", $subject );
  188.         $subject = str_replace( "&#38;", "&", $subject );
  189.         $subject = str_replace( "&#58;", ":", $subject );
  190.         $subject = str_replace( "&#91;", "[", $subject );
  191.         $subject = str_replace( "&#93;", "]", $subject );
  192.         $subject = str_replace( "&#064;", "@", $subject );
  193.         $subject = str_replace( "&nbsp;", " ", $subject );
  194.         return $subject;
  195.     }
  196.  
  197.     public function cleanMessage( $message = "" )
  198.     {
  199.         $message = preg_replace( "#\\[quote.*\\](.+?)\\[/quote\\]#s", "<br /><br />------------ QUOTE ----------<br />\\1<br />-----------------------------<br /><br />", $message );
  200.         $message = preg_replace_callback( "#\\[url=(.+?)\\](.+?)\\[/url\\]#", array(
  201.             $this,
  202.             "_formatUrl"
  203.         ), $message );
  204.         $message = IPSText::gettextclass( "bbcode" )->unconvertSmilies( $message );
  205.         $message = strip_tags( $message, "<br>" );
  206.         IPSText::gettextclass( "bbcode" )->parse_html = 0;
  207.         IPSText::gettextclass( "bbcode" )->parse_nl2br = 1;
  208.         IPSText::gettextclass( "bbcode" )->parse_bbcode = 0;
  209.         IPSText::gettextclass( "bbcode" )->parse_wordwrap = 0 - 1;
  210.         $message = IPSText::gettextclass( "bbcode" )->stripAllTags( $message, true, false );
  211.         $message = str_replace( "\n", "\r\n", $message );
  212.         $message = str_replace( "\r", "", $message );
  213.         $message = str_replace( "<br>", "\r\n", $message );
  214.         $message = str_replace( "<br />", "\r\n", $message );
  215.         $message = str_replace( "\r\n\r\n", "\r\n", $message );
  216.         $message = str_replace( "&quot;", "\"", $message );
  217.         $message = str_replace( "&#092;", "\\", $message );
  218.         $message = str_replace( "&#036;", "\$", $message );
  219.         $message = str_replace( "&#33;", "!", $message );
  220.         $message = str_replace( "&#34;", "\"", $message );
  221.         $message = str_replace( "&#39;", "'", $message );
  222.         $message = str_replace( "&#40;", "(", $message );
  223.         $message = str_replace( "&#41;", ")", $message );
  224.         $message = str_replace( "&lt;", "<", $message );
  225.         $message = str_replace( "&gt;", ">", $message );
  226.         $message = str_replace( "&#124;", "|", $message );
  227.         $message = str_replace( "&amp;", "&", $message );
  228.         $message = str_replace( "&#38;", "&", $message );
  229.         $message = str_replace( "&#58;", ":", $message );
  230.         $message = str_replace( "&#91;", "[", $message );
  231.         $message = str_replace( "&#93;", "]", $message );
  232.         $message = str_replace( "&#064;", "@", $message );
  233.         $message = str_replace( "&#60;", "<", $message );
  234.         $message = str_replace( "&#62;", ">", $message );
  235.         $message = str_replace( "&nbsp;", " ", $message );
  236.         return $message;
  237.     }
  238.  
  239.     public function _formatUrl( $matches )
  240.     {
  241.         $matches[1] = str_replace( array( "\"", "'", "&quot;", "&#039;", "&#39;" ), "", $matches[1] );
  242.         return $matches[2]." (".$matches[1].")";
  243.     }
  244.  
  245.     public function addAttachment( $data = "", $name = "", $ctype = "application/octet-stream" )
  246.     {
  247.         $this->_attachments[] = array(
  248.             $data,
  249.             $name,
  250.             $ctype
  251.         );
  252.     }
  253.  
  254.     private function fatalError( $msg, $help = "" )
  255.     {
  256.         $this->DB->insert( "mail_error_logs", array(
  257.             "mlog_date" => time( ),
  258.             "mlog_to" => $this->to,
  259.             "mlog_from" => $this->from,
  260.             "mlog_subject" => $this->subject,
  261.             "mlog_content" => substr( $this->message, 0, 200 ),
  262.             "mlog_msg" => $msg,
  263.             "mlog_code" => $this->emailer->smtp_code,
  264.             "mlog_smtp_msg" => $this->emailer->smtp_msg
  265.         ) );
  266.         return false;
  267.     }
  268.  
  269. }
  270.  
  271. if ( !defined( "IN_IPB" ) )
  272. {
  273.     print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded all the relevant files.";
  274.     exit( );
  275. }
  276. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement