PageRenderTime 54ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/installation/models/setup.php

https://github.com/joebushi/joomla
PHP | 330 lines | 186 code | 52 blank | 92 comment | 18 complexity | 808a41587a5881e9901fbe24357f95a9 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @package Joomla.Installation
  5. * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
  6. * @license GNU General Public License version 2 or later; see LICENSE.txt
  7. */
  8. defined('_JEXEC') or die;
  9. jimport('joomla.application.component.model');
  10. /**
  11. * Setup model for the Joomla Core Installer.
  12. *
  13. * @package Joomla.Installation
  14. * @since 1.6
  15. */
  16. class JInstallationModelSetup extends JModel
  17. {
  18. /**
  19. * Get the current setup options from the session.
  20. *
  21. * @return array
  22. */
  23. public function getOptions()
  24. {
  25. $session = & JFactory::getSession();
  26. $options = $session->get('setup.options', array());
  27. return $options;
  28. }
  29. /**
  30. * Store the current setup options in the session.
  31. *
  32. * @return array
  33. */
  34. public function storeOptions($options)
  35. {
  36. // Get the current setup options from the session.
  37. $session = &JFactory::getSession();
  38. $old = $session->get('setup.options', array());
  39. // Merge the new setup options into the current ones and store in the session.
  40. $options = array_merge($old, (array)$options);
  41. $session->set('setup.options', $options);
  42. // If the setup language is set in the options, set it separately in the session.
  43. if (!empty($options['language'])) {
  44. $session->set('setup.language', $options['language']);
  45. }
  46. return $options;
  47. }
  48. /**
  49. * Method to get the link form.
  50. *
  51. * @return mixed JForm object on success, false on failure.
  52. * @since 1.6
  53. */
  54. public function &getForm($view = null)
  55. {
  56. // Initialise variables.
  57. $false = false;
  58. if (!$view) {
  59. $view = JRequest::getWord('view', 'language');
  60. }
  61. // Get the form.
  62. jimport('joomla.form.form');
  63. JForm::addFormPath(JPATH_COMPONENT.'/models/forms');
  64. JForm::addFieldPath(JPATH_COMPONENT.'/models/fields');
  65. $form = &JForm::getInstance($view, 'jform', true, array('array' => 'jform'));
  66. // Check for an error.
  67. if (JError::isError($form)) {
  68. $this->setError($form->getMessage());
  69. return $false;
  70. }
  71. // Check the session for previously entered form data.
  72. $data = (array) $this->getOptions();
  73. // Bind the form data if present.
  74. if (!empty($data)) {
  75. $form->bind($data);
  76. }
  77. return $form;
  78. }
  79. public function getDboptions()
  80. {
  81. // Initialise variables.
  82. $options = array();
  83. // Create an array of known database connect functions.
  84. $map = array(
  85. 'MySQL' => 'mysql_connect',
  86. 'MySQLi' => 'mysqli_connect',
  87. );
  88. // Iterate over the options, building an array.
  89. $found = false;
  90. foreach ($map as $k => $v)
  91. {
  92. // Only list available options.
  93. if (!function_exists($v)) {
  94. continue;
  95. }
  96. // Create the option object.
  97. $option = new stdClass;
  98. $option->text = $k;
  99. $option->value = strtolower($k);
  100. // Select the first available.
  101. if (!$found) {
  102. $option->selected = ' selected="selected"';
  103. $found = true;
  104. }
  105. $options[] = $option;
  106. }
  107. return $options;
  108. }
  109. /**
  110. * Generate a panel of language choices for the user to select their language
  111. *
  112. * @return boolean True if successful
  113. * @since 1.5
  114. */
  115. public function getLanguages()
  116. {
  117. // Initialise variables.
  118. $app = &JFactory::getApplication();
  119. // Detect the native language.
  120. jimport('joomla.language.helper');
  121. $native = JLanguageHelper::detectLanguage();
  122. // Get a forced language if it exists.
  123. $forced = $app->getLocalise();
  124. if (!empty($forced['language'])) {
  125. $native = $forced['language'];
  126. }
  127. // Get the list of available languages.
  128. $list = JLanguageHelper::createLanguageList($native);
  129. if (!$list || JError::isError($list)) {
  130. $list = array();
  131. }
  132. return $list;
  133. }
  134. /**
  135. * Gets PHP options.
  136. *
  137. * @return array
  138. */
  139. public function getPhpOptions()
  140. {
  141. // Initialise variables.
  142. $options = array();
  143. // Check the PHP Version.
  144. $option = new stdClass;
  145. $option->label = JText::_('PHP_VERSION').' >= 5.2.0';
  146. $option->state = (phpversion() >= '5.2.0');
  147. $option->notice = null;
  148. $options[] = $option;
  149. // Check for zlib support.
  150. $option = new stdClass;
  151. $option->label = JText::_('ZLIB_COMPRESSION_SUPPORT');
  152. $option->state = extension_loaded('zlib');
  153. $option->notice = null;
  154. $options[] = $option;
  155. // Check for XML support.
  156. $option = new stdClass;
  157. $option->label = JText::_('XML_SUPPORT');
  158. $option->state = extension_loaded('xml');
  159. $option->notice = null;
  160. $options[] = $option;
  161. // Check for MySQL support.
  162. $option = new stdClass;
  163. $option->label = JText::_('MYSQL_SUPPORT');
  164. $option->state = (function_exists('mysql_connect') || function_exists('mysqli_connect'));
  165. $option->notice = null;
  166. $options[] = $option;
  167. // Check for mbstring options.
  168. if (extension_loaded('mbstring'))
  169. {
  170. // Check for default MB language.
  171. $option = new stdClass;
  172. $option->label = JText::_('MB_LANGUAGE_IS_DEFAULT');
  173. $option->state = (strtolower(ini_get('mbstring.language')) == 'neutral');
  174. $option->notice = ($option->state) ? null : JText::_('NOTICEMBLANGNOTDEFAULT');
  175. $options[] = $option;
  176. // Check for MB function overload.
  177. $option = new stdClass;
  178. $option->label = JText::_('MB_STRING_OVERLOAD_OFF');
  179. $option->state = (ini_get('mbstring.func_overload') == 0);
  180. $option->notice = ($option->state) ? null : JText::_('NOTICEMBSTRINGOVERLOAD');
  181. $options[] = $option;
  182. }
  183. // Check for configuration file writeable.
  184. $option = new stdClass;
  185. $option->label = 'configuration.php '.JText::_('writable');
  186. $option->state = ((@file_exists('../configuration.php') && @is_writable('../configuration.php')) || is_writable('../'));
  187. $option->notice = ($option->state) ? null : JText::_('NOTICEYOUCANSTILLINSTALL');
  188. $options[] = $option;
  189. return $options;
  190. }
  191. /**
  192. * Gets PHP Settings.
  193. *
  194. * @return array
  195. */
  196. public function getPhpSettings()
  197. {
  198. // Initialise variables.
  199. $settings = array();
  200. // Check for safe mode.
  201. $setting = new stdClass;
  202. $setting->label = JText::_('SAFE_MODE');
  203. $setting->state = (bool) ini_get('safe_mode');
  204. $setting->recommended = false;
  205. $settings[] = $setting;
  206. // Check for display errors.
  207. $setting = new stdClass;
  208. $setting->label = JText::_('DISPLAY_ERRORS');
  209. $setting->state = (bool) ini_get('display_errors');
  210. $setting->recommended = false;
  211. $settings[] = $setting;
  212. // Check for file uploads.
  213. $setting = new stdClass;
  214. $setting->label = JText::_('FILE_UPLOADS');
  215. $setting->state = (bool) ini_get('file_uploads');
  216. $setting->recommended = true;
  217. $settings[] = $setting;
  218. // Check for magic quotes.
  219. $setting = new stdClass;
  220. $setting->label = JText::_('MAGIC_QUOTES_RUNTIME');
  221. $setting->state = (bool) ini_get('magic_quotes_runtime');
  222. $setting->recommended = false;
  223. $settings[] = $setting;
  224. // Check for register globals.
  225. $setting = new stdClass;
  226. $setting->label = JText::_('REGISTER_GLOBALS');
  227. $setting->state = (bool) ini_get('register_globals');
  228. $setting->recommended = false;
  229. $settings[] = $setting;
  230. // Check for output buffering.
  231. $setting = new stdClass;
  232. $setting->label = JText::_('OUTPUT_BUFFERING');
  233. $setting->state = (bool) ini_get('output_buffering');
  234. $setting->recommended = false;
  235. $settings[] = $setting;
  236. // Check for session auto-start.
  237. $setting = new stdClass;
  238. $setting->label = JText::_('SESSION_AUTO_START');
  239. $setting->state = (bool) ini_get('session.auto_start');
  240. $setting->recommended = false;
  241. $settings[] = $setting;
  242. return $settings;
  243. }
  244. /**
  245. * Method to validate the form data.
  246. *
  247. * @param array The form data.
  248. * @return array|bool Array of filtered data if valid, false otherwise.
  249. * @since 1.6
  250. */
  251. public function validate($data, $view = null)
  252. {
  253. // Get the form.
  254. $form = &$this->getForm($view);
  255. // Check for an error.
  256. if ($form === false) {
  257. return false;
  258. }
  259. // Filter and validate the form data.
  260. $data = $form->filter($data);
  261. $return = $form->validate($data);
  262. // Check for an error.
  263. if (JError::isError($return)) {
  264. $this->setError($return->getMessage());
  265. return false;
  266. }
  267. // Check the validation results.
  268. if ($return === false)
  269. {
  270. // Get the validation messages from the form.
  271. foreach ($form->getErrors() as $message) {
  272. $this->setError($message);
  273. }
  274. return false;
  275. }
  276. return $data;
  277. }
  278. }