Source for file email.php

Documentation is available at email.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Installation
  4.  * @subpackage  Controller
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. /**
  13.  * Controller class to e-mail the configuration info for the Joomla Installer.
  14.  *
  15.  * @package     Joomla.Installation
  16.  * @subpackage  Controller
  17.  * @since       3.1
  18.  */
  19. {
  20.     /**
  21.      * Constructor.
  22.      *
  23.      * @since   3.2
  24.      */
  25.     public function __construct()
  26.     {
  27.         parent::__construct();
  28.  
  29.         // Overrides application config and set the configuration.php file so the send function will work
  30.         JFactory::$config null;
  31.         JFactory::getConfig(JPATH_SITE '/configuration.php');
  32.         JFactory::$session null;
  33.     }
  34.  
  35.     /**
  36.      * Execute the controller.
  37.      *
  38.      * @return  void 
  39.      *
  40.      * @since   3.1
  41.      */
  42.     public function execute()
  43.     {
  44.         // Get the application
  45.         /* @var InstallationApplicationWeb $app */
  46.         $app $this->getApplication();
  47.  
  48.         // Check for request forgeries. - @TODO - Restore this check
  49.         // JSession::checkToken() or $app->sendJsonResponse(new Exception(JText::_('JINVALID_TOKEN'), 403));
  50.  
  51.         // Get the setup model.
  52.         $model new InstallationModelSetup;
  53.  
  54.         // Get the options from the session
  55.         $options $model->getOptions();
  56.  
  57.         $name    $options['admin_user'];
  58.         $email   $options['admin_email'];
  59.         $subject JText::sprintf(JText::_('INSTL_EMAIL_SUBJECT')$options['site_name']);
  60.  
  61.         // Prepare email body
  62.         $body array();
  63.         $body[JText::sprintf(JText::_('INSTL_EMAIL_HEADING')$options['site_name']);
  64.         $body['';
  65.         $body[array(JText::_('INSTL_SITE_NAME_LABEL')$options['site_name']);
  66.  
  67.         $body[$this->emailTitle(JText::_('INSTL_COMPLETE_ADMINISTRATION_LOGIN_DETAILS'));
  68.         $body[array(JText::_('JEMAIL')$options['admin_email']);
  69.         $body[array(JText::_('JUSERNAME')$options['admin_user']);
  70.  
  71.         if ($options['summary_email_passwords'])
  72.         {
  73.             $body[array(JText::_('INSTL_ADMIN_PASSWORD_LABEL')$options['admin_password']);
  74.         }
  75.  
  76.         $body[$this->emailTitle(JText::_('INSTL_DATABASE'));
  77.         $body[array(JText::_('INSTL_DATABASE_TYPE_LABEL')$options['db_type']);
  78.         $body[array(JText::_('INSTL_DATABASE_HOST_LABEL')$options['db_host']);
  79.         $body[array(JText::_('INSTL_DATABASE_USER_LABEL')$options['db_user']);
  80.  
  81.         if ($options['summary_email_passwords'])
  82.         {
  83.             $body[array(JText::_('INSTL_DATABASE_PASSWORD_LABEL')$options['db_pass']);
  84.         }
  85.  
  86.         $body[array(JText::_('INSTL_DATABASE_NAME_LABEL')$options['db_name']);
  87.         $body[array(JText::_('INSTL_DATABASE_PREFIX_LABEL')$options['db_prefix']);
  88.  
  89.         if (isset($options['ftp_enable']&& $options['ftp_enable'])
  90.         {
  91.             $body[$this->emailTitle(JText::_('INSTL_FTP'));
  92.             $body[array(JText::_('INSTL_FTP_USER_LABEL')$options['ftp_user']);
  93.  
  94.             if ($options['summary_email_passwords'])
  95.             {
  96.                 $body[arrayJText::_('INSTL_FTP_PASSWORD_LABEL')$options['ftp_pass']);
  97.             }
  98.  
  99.             $body[array(JText::_('INSTL_FTP_HOST_LABEL')$options['ftp_host']);
  100.             $body[array(JText::_('INSTL_FTP_PORT_LABEL')$options['ftp_port']);
  101.         }
  102.  
  103.         $max 0;
  104.  
  105.         foreach ($body as $line)
  106.         {
  107.             if (is_array($line))
  108.             {
  109.                 $max max(array($maxstrlen($line['0'])));
  110.             }
  111.         }
  112.  
  113.         foreach ($body as $i => $line)
  114.         {
  115.             if (is_array($line))
  116.             {
  117.                 $label $line['0'];
  118.                 $label .= ': ' str_repeat(' '$max strlen($label));
  119.                 $body[$i$label $line['1'];
  120.             }
  121.         }
  122.  
  123.         $body implode("\r\n"$body);
  124.  
  125.         $mail JFactory::getMailer();
  126.         $mail->addRecipient($email);
  127.         $mail->addReplyTo($email$name);
  128.         $mail->setSender(array($email$name));
  129.         $mail->setSubject($subject);
  130.         $mail->setBody($body);
  131.  
  132.         $r new stdClass;
  133.         $r->view 'complete';
  134.  
  135.         try
  136.         {
  137.             $mail->Send();
  138.         }
  139.         catch (Exception $e)
  140.         {
  141.             $app->enqueueMessage(JText::_('INSTL_EMAIL_NOT_SENT')'notice');
  142.         }
  143.  
  144.         $app->sendJsonResponse($r);
  145.     }
  146.  
  147.     /**
  148.      * Prepares a title line for the e-mail
  149.      *
  150.      * @param   string  $title  The title pre-formatting
  151.      *
  152.      * @return  string 
  153.      *
  154.      * @since   3.1
  155.      */
  156.     protected function emailTitle($title)
  157.     {
  158.         return "\r\n" $title "\r\n" str_repeat('='strlen($title));
  159.     }
  160. }

Documentation generated on Tue, 19 Nov 2013 15:02:25 +0100 by phpDocumentor 1.4.3