Source for file setup.php

Documentation is available at setup.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Installation
  4.  * @subpackage  Model
  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.  * Setup model for the Joomla Core Installer.
  14.  *
  15.  * @package     Joomla.Installation
  16.  * @subpackage  Model
  17.  * @since       3.1
  18.  */
  19. {
  20.     /**
  21.      * Get the current setup options from the session.
  22.      *
  23.      * @return  array  An array of options from the session
  24.      *
  25.      * @since   3.1
  26.      */
  27.     public function getOptions()
  28.     {
  29.         $session JFactory::getSession();
  30.         $options $session->get('setup.options'array());
  31.  
  32.         return $options;
  33.     }
  34.  
  35.     /**
  36.      * Store the current setup options in the session.
  37.      *
  38.      * @param   array  $options  The installation options
  39.      *
  40.      * @return  array  An array of options from the session
  41.      *
  42.      * @since   3.1
  43.      */
  44.     public function storeOptions($options)
  45.     {
  46.         // Get the current setup options from the session.
  47.         $session JFactory::getSession();
  48.         $old $session->get('setup.options'array());
  49.  
  50.         // Ensure that we have language
  51.         if (!isset($options['language']|| empty($options['language']))
  52.         {
  53.             $options['language'JFactory::getLanguage()->getTag();
  54.         }
  55.  
  56.         // Merge the new setup options into the current ones and store in the session.
  57.         $options array_merge($old(array) $options);
  58.         $session->set('setup.options'$options);
  59.  
  60.         return $options;
  61.     }
  62.  
  63.     /**
  64.      * Method to get the form.
  65.      *
  66.      * @param   string  $view  The view being processed
  67.      *
  68.      * @return  mixed  JForm object on success, false on failure.
  69.      *
  70.      * @since   3.1
  71.      */
  72.     public function getForm($view null)
  73.     {
  74.         /* @var InstallationApplicationWeb $app */
  75.         $app JFactory::getApplication();
  76.  
  77.         if (!$view)
  78.         {
  79.             $view $app->input->getWord('view''site');
  80.         }
  81.  
  82.         // Get the form.
  83.         JForm::addFormPath(JPATH_COMPONENT '/model/forms');
  84.         JForm::addFieldPath(JPATH_COMPONENT '/model/fields');
  85.         JForm::addRulePath(JPATH_COMPONENT '/model/rules');
  86.  
  87.         try
  88.         {
  89.             $form JForm::getInstance('jform'$viewarray('control' => 'jform'));
  90.         }
  91.         catch (Exception $e)
  92.         {
  93.             $app->enqueueMessage($e->getMessage()'error');
  94.             return false;
  95.         }
  96.  
  97.         // Check the session for previously entered form data.
  98.         $data = (array) $this->getOptions();
  99.  
  100.         // Bind the form data if present.
  101.         if (!empty($data))
  102.         {
  103.             $form->bind($data);
  104.         }
  105.  
  106.         return $form;
  107.     }
  108.  
  109.     /**
  110.      * Method to check the form data
  111.      *
  112.      * @param   string  $page  The view being checked
  113.      *
  114.      * @return  array  Validated form data
  115.      *
  116.      * @since   3.1
  117.      */
  118.     public function checkForm($page 'site')
  119.     {
  120.         // Get the application object.
  121.         /* @var InstallationApplicationWeb $app */
  122.         $app JFactory::getApplication();
  123.  
  124.         // Get the posted values from the request and validate them.
  125.         $data   $app->input->post->get('jform'array()'array');
  126.         $return    $this->validate($data$page);
  127.  
  128.         // Attempt to save the data before validation
  129.         $form $this->getForm();
  130.         $data $form->filter($data);
  131.         unset($data['admin_password2']);
  132.         $this->storeOptions($data);
  133.  
  134.         // Check for validation errors.
  135.         if ($return === false)
  136.         {
  137.             // Redirect back to the previous page.
  138.             $r new stdClass;
  139.             $r->view $page;
  140.             $app->sendJsonResponse($r);
  141.         }
  142.  
  143.         unset($return['admin_password2']);
  144.  
  145.         // Store the options in the session.
  146.         $vars $this->storeOptions($return);
  147.  
  148.         return $vars;
  149.     }
  150.  
  151.     /**
  152.      * Generate a panel of language choices for the user to select their language
  153.      *
  154.      * @return  boolean True if successful
  155.      *
  156.      * @since    3.1
  157.      */
  158.     public function getLanguages()
  159.     {
  160.         /* @var InstallationApplicationWeb $app */
  161.         $app JFactory::getApplication();
  162.  
  163.         // Detect the native language.
  164.         $native JLanguageHelper::detectLanguage();
  165.  
  166.         if (empty($native))
  167.         {
  168.             $native 'en-GB';
  169.         }
  170.  
  171.         // Get a forced language if it exists.
  172.         $forced $app->getLocalise();
  173.  
  174.         if (!empty($forced['language']))
  175.         {
  176.             $native $forced['language'];
  177.         }
  178.  
  179.         // Get the list of available languages.
  180.         $list JLanguageHelper::createLanguageList($native);
  181.  
  182.         if (!$list || $list instanceof Exception)
  183.         {
  184.             $list array();
  185.         }
  186.  
  187.         return $list;
  188.     }
  189.  
  190.     /**
  191.      * Checks the availability of the parse_ini_file and parse_ini_string functions.
  192.      *
  193.      * @return    boolean  True if the method exists
  194.      *
  195.      * @since    3.1
  196.      */
  197.     public function getIniParserAvailability()
  198.     {
  199.         $disabled_functions ini_get('disable_functions');
  200.  
  201.         if (!empty($disabled_functions))
  202.         {
  203.             // Attempt to detect them in the disable_functions black list
  204.             $disabled_functions explode(','trim($disabled_functions));
  205.             $number_of_disabled_functions count($disabled_functions);
  206.  
  207.             for ($i 0$i $number_of_disabled_functions$i++)
  208.             {
  209.                 $disabled_functions[$itrim($disabled_functions[$i]);
  210.             }
  211.  
  212.             $result !in_array('parse_ini_string'$disabled_functions);
  213.         }
  214.         else
  215.         {
  216.             // Attempt to detect their existence; even pure PHP implementation of them will trigger a positive response, though.
  217.             $result function_exists('parse_ini_string');
  218.         }
  219.  
  220.         return $result;
  221.     }
  222.  
  223.     /**
  224.      * Gets PHP options.
  225.      *
  226.      * @return    array  Array of PHP config options
  227.      *
  228.      * @since   3.1
  229.      */
  230.     public function getPhpOptions()
  231.     {
  232.         $options array();
  233.  
  234.         // Check the PHP Version.
  235.         $option new stdClass;
  236.         $option->label  JText::_('INSTL_PHP_VERSION'' >= 5.3.1';
  237.         $option->state  version_compare(PHP_VERSION'5.3.1''>=');
  238.         $option->notice null;
  239.         $options[$option;
  240.  
  241.         // Check for magic quotes gpc.
  242.         $option new stdClass;
  243.         $option->label  JText::_('INSTL_MAGIC_QUOTES_GPC');
  244.         $option->state  (ini_get('magic_quotes_gpc'== false);
  245.         $option->notice null;
  246.         $options[$option;
  247.  
  248.         // Check for register globals.
  249.         $option new stdClass;
  250.         $option->label  JText::_('INSTL_REGISTER_GLOBALS');
  251.         $option->state  (ini_get('register_globals'== false);
  252.         $option->notice null;
  253.         $options[$option;
  254.  
  255.         // Check for zlib support.
  256.         $option new stdClass;
  257.         $option->label  JText::_('INSTL_ZLIB_COMPRESSION_SUPPORT');
  258.         $option->state  extension_loaded('zlib');
  259.         $option->notice null;
  260.         $options[$option;
  261.  
  262.         // Check for XML support.
  263.         $option new stdClass;
  264.         $option->label  JText::_('INSTL_XML_SUPPORT');
  265.         $option->state  extension_loaded('xml');
  266.         $option->notice null;
  267.         $options[$option;
  268.  
  269.         // Check for database support.
  270.         // We are satisfied if there is at least one database driver available.
  271.         $available JDatabaseDriver::getConnectors();
  272.         $option new stdClass;
  273.         $option->label  JText::_('INSTL_DATABASE_SUPPORT');
  274.         $option->label .= '<br />(' implode(', '$available')';
  275.         $option->state  count($available);
  276.         $option->notice null;
  277.         $options[$option;
  278.  
  279.         // Check for mbstring options.
  280.         if (extension_loaded('mbstring'))
  281.         {
  282.             // Check for default MB language.
  283.             $option new stdClass;
  284.             $option->label  JText::_('INSTL_MB_LANGUAGE_IS_DEFAULT');
  285.             $option->state  (strtolower(ini_get('mbstring.language')) == 'neutral');
  286.             $option->notice ($option->statenull JText::_('INSTL_NOTICEMBLANGNOTDEFAULT');
  287.             $options[$option;
  288.  
  289.             // Check for MB function overload.
  290.             $option new stdClass;
  291.             $option->label  JText::_('INSTL_MB_STRING_OVERLOAD_OFF');
  292.             $option->state  (ini_get('mbstring.func_overload'== 0);
  293.             $option->notice ($option->statenull JText::_('INSTL_NOTICEMBSTRINGOVERLOAD');
  294.             $options[$option;
  295.         }
  296.  
  297.         // Check for a missing native parse_ini_file implementation
  298.         $option new stdClass;
  299.         $option->label  JText::_('INSTL_PARSE_INI_FILE_AVAILABLE');
  300.         $option->state  $this->getIniParserAvailability();
  301.         $option->notice null;
  302.         $options[$option;
  303.  
  304.         // Check for missing native json_encode / json_decode support
  305.         $option new stdClass;
  306.         $option->label  JText::_('INSTL_JSON_SUPPORT_AVAILABLE');
  307.         $option->state  function_exists('json_encode'&& function_exists('json_decode');
  308.         $option->notice null;
  309.         $options[$option;
  310.  
  311.         // Check for configuration file writable.
  312.         $writable (is_writable(JPATH_CONFIGURATION '/configuration.php')
  313.             || (!file_exists(JPATH_CONFIGURATION '/configuration.php'&& is_writable(JPATH_ROOT)));
  314.  
  315.         $option new stdClass;
  316.         $option->label  JText::sprintf('INSTL_WRITABLE''configuration.php');
  317.         $option->state  $writable;
  318.         $option->notice ($option->statenull JText::_('INSTL_NOTICEYOUCANSTILLINSTALL');
  319.         $options[$option;
  320.  
  321.         return $options;
  322.     }
  323.  
  324.     /**
  325.      * Checks if all of the mandatory PHP options are met
  326.      *
  327.      * @return  boolean  True on success
  328.      *
  329.      * @since   3.1
  330.      */
  331.     public function getPhpOptionsSufficient()
  332.     {
  333.         $result  true;
  334.         $options $this->getPhpOptions();
  335.  
  336.         foreach ($options as $option)
  337.         {
  338.             if (is_null($option->notice))
  339.             {
  340.                 $result ($result && $option->state);
  341.             }
  342.         }
  343.  
  344.         return $result;
  345.     }
  346.  
  347.     /**
  348.      * Gets PHP Settings.
  349.      *
  350.      * @return  array 
  351.      *
  352.      * @since   3.1
  353.      */
  354.     public function getPhpSettings()
  355.     {
  356.         $settings array();
  357.  
  358.         // Check for safe mode.
  359.         $setting new stdClass;
  360.         $setting->label JText::_('INSTL_SAFE_MODE');
  361.         $setting->state = (bool) ini_get('safe_mode');
  362.         $setting->recommended false;
  363.         $settings[$setting;
  364.  
  365.         // Check for display errors.
  366.         $setting new stdClass;
  367.         $setting->label JText::_('INSTL_DISPLAY_ERRORS');
  368.         $setting->state = (bool) ini_get('display_errors');
  369.         $setting->recommended false;
  370.         $settings[$setting;
  371.  
  372.         // Check for file uploads.
  373.         $setting new stdClass;
  374.         $setting->label JText::_('INSTL_FILE_UPLOADS');
  375.         $setting->state = (bool) ini_get('file_uploads');
  376.         $setting->recommended true;
  377.         $settings[$setting;
  378.  
  379.         // Check for magic quotes runtimes.
  380.         $setting new stdClass;
  381.         $setting->label JText::_('INSTL_MAGIC_QUOTES_RUNTIME');
  382.         $setting->state = (bool) ini_get('magic_quotes_runtime');
  383.         $setting->recommended false;
  384.         $settings[$setting;
  385.  
  386.         // Check for output buffering.
  387.         $setting new stdClass;
  388.         $setting->label JText::_('INSTL_OUTPUT_BUFFERING');
  389.         $setting->state = (bool) ini_get('output_buffering');
  390.         $setting->recommended false;
  391.         $settings[$setting;
  392.  
  393.         // Check for session auto-start.
  394.         $setting new stdClass;
  395.         $setting->label JText::_('INSTL_SESSION_AUTO_START');
  396.         $setting->state = (bool) ini_get('session.auto_start');
  397.         $setting->recommended false;
  398.         $settings[$setting;
  399.  
  400.         // Check for native ZIP support
  401.         $setting new stdClass;
  402.         $setting->label JText::_('INSTL_ZIP_SUPPORT_AVAILABLE');
  403.         $setting->state function_exists('zip_open'&& function_exists('zip_read');
  404.         $setting->recommended true;
  405.         $settings[$setting;
  406.  
  407.         return $settings;
  408.     }
  409.  
  410.     /**
  411.      * Method to validate the form data.
  412.      *
  413.      * @param   array   $data  The form data.
  414.      * @param   string  $view  The view.
  415.      *
  416.      * @return  mixed   Array of filtered data if valid, false otherwise.
  417.      *
  418.      * @since    3.1
  419.      */
  420.     public function validate($data$view null)
  421.     {
  422.         /* @var InstallationApplicationWeb $app */
  423.         $app JFactory::getApplication();
  424.  
  425.         // Get the form.
  426.         $form $this->getForm($view);
  427.  
  428.         // Check for an error.
  429.         if ($form === false)
  430.         {
  431.             return false;
  432.         }
  433.  
  434.         // Filter and validate the form data.
  435.         $data   $form->filter($data);
  436.         $return $form->validate($data);
  437.  
  438.         // Check for an error.
  439.         if ($return instanceof Exception)
  440.         {
  441.             $app->enqueueMessage($return->getMessage()'warning');
  442.             return false;
  443.         }
  444.  
  445.         // Check the validation results.
  446.         if ($return === false)
  447.         {
  448.             // Get the validation messages from the form.
  449.             foreach ($form->getErrors(as $message)
  450.             {
  451.                 if ($message instanceof Exception)
  452.                 {
  453.                     $app->enqueueMessage($message->getMessage()'warning');
  454.                 }
  455.                 else
  456.                 {
  457.                     $app->enqueueMessage($message'warning');
  458.                 }
  459.             }
  460.  
  461.             return false;
  462.         }
  463.  
  464.         return $data;
  465.     }
  466. }

Documentation generated on Tue, 19 Nov 2013 15:12:58 +0100 by phpDocumentor 1.4.3