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