* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 7456 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class AdminInformation extends AdminTab
{
private function _getTestResultHtml()
{
$html = '';
// Functions list to test with 'test_system'
$funcs = array('fopen', 'fclose', 'fread', 'fwrite', 'rename', 'file_exists', 'unlink', 'rmdir', 'mkdir', 'getcwd', 'chdir', 'chmod');
// Test list to execute (function/args)
$tests = array(
'phpversion' => false,
'upload' => false,
'system' => $funcs,
'gd' => false,
'mysql_support' => false,
'config_dir' => PS_ADMIN_DIR.'/../config/',
'tools_dir' => PS_ADMIN_DIR.'/../tools/smarty/compile',
'cache_dir' => PS_ADMIN_DIR.'/../tools/smarty/cache/',
'sitemap' => PS_ADMIN_DIR.'/../sitemap.xml',
'img_dir' => PS_ADMIN_DIR.'/../img/',
'mails_dir' => PS_ADMIN_DIR.'/../mails/',
'module_dir' => PS_ADMIN_DIR.'/../modules/',
'theme_lang_dir' => PS_ADMIN_DIR.'/../themes/'._THEME_NAME_.'/lang/',
'translations_dir' => PS_ADMIN_DIR.'/../translations/',
'customizable_products_dir' => PS_ADMIN_DIR.'/../upload/',
'virtual_products_dir' => PS_ADMIN_DIR.'/../download/'
);
$tests_op = array(
'fopen' => false,
'register_globals' => false,
'gz' => false
);
$testsErrors = array(
'phpversion' => $this->l('Update your PHP version'),
'upload' => $this->l('Configure your server to allow the upload file'),
'system' => $this->l('Configure your server to allow the creation of directories and write to files'),
'gd' => $this->l('Enable the GD library on your server'),
'mysql_support' => $this->l('Enable the MySQL support on your server'),
'config_dir' => $this->l('Set write permissions for config folder'),
'tools_dir' => $this->l('Set write permissions for tools folder'),
'cache_dir' => $this->l('Set write permissions for cache folder'),
'sitemap' => $this->l('Set write permissions for sitemap.xml file'),
'img_dir' => $this->l('Set write permissions for img folder and subfolders/recursively'),
'mails_dir' => $this->l('Set write permissions for mails folder and subfolders/recursively'),
'module_dir' => $this->l('Set write permissions for modules folder and subfolders/recursively'),
'theme_lang_dir' => $this->l('Set write permissions for themes/')._THEME_NAME_.$this->l('/lang/ folder and subfolders/recursively'),
'translations_dir' => $this->l('Set write permissions for translations folder and subfolders/recursively'),
'customizable_products_dir' => $this->l('Set write permissions for upload folder and subfolders/recursively'),
'virtual_products_dir' => $this->l('Set write permissions for download folder and subfolders/recursively'),
'fopen' => $this->l('Enable fopen on your server'),
'register_globals' => $this->l('Set PHP register global option to off'),
'gz' => $this->l('Enable GZIP compression on your server')
);
$paramsRequiredResults = self::check($tests);
$paramsOptionalResults = self::check($tests_op);
$html .= '
'.$this->l('Required parameters').':';
if (!in_array('fail', $paramsRequiredResults))
$html .= ' OK
';
else
{
$html .= ' '.$this->l('Please consult the following error(s)').'
';
foreach ($paramsRequiredResults AS $key => $value)
if ($value == 'fail')
$html .= '- '.$testsErrors[$key].'
';
$html .= '
';
}
$html .= '
'.$this->l('Optional parameters').':';
if (!in_array('fail', $paramsOptionalResults))
$html .= ' OK
';
else
{
$html .= ' '.$this->l('Please consult the following error(s)').'
';
foreach ($paramsOptionalResults AS $key => $value)
if ($value == 'fail')
$html .= '- '.$testsErrors[$key].'
';
$html .= '
';
}
return $html;
}
public function display()
{
global $currentIndex;
echo '
'.$this->l('Information').'
';
}
static private function check($tests)
{
$res = array();
foreach ($tests AS $key => $test)
$res[$key] = self::run($key, $test);
return $res;
}
static private function run($ptr, $arg = 0)
{
if (call_user_func(array('self', 'test_'.$ptr), $arg))
return ('ok');
return ('fail');
}
// Misc functions
static private function test_phpversion()
{
return PHP_VERSION_ID >= 50000; /* PHP version > 5.0 */
}
static private function test_mysql_support()
{
return function_exists('mysql_connect');
}
static private function test_upload()
{
return ini_get('file_uploads');
}
static private function test_fopen()
{
return ini_get('allow_url_fopen');
}
static private function test_system($funcs)
{
foreach ($funcs AS $func)
if (!function_exists($func))
return false;
return true;
}
static private function test_gd()
{
return function_exists('imagecreatetruecolor');
}
static private function test_register_globals()
{
return !ini_get('register_globals');
}
static private function test_gz()
{
if (function_exists('gzencode'))
return !(@gzencode('dd') === false);
return false;
}
// is_writable dirs
static private function test_dir($dir, $recursive = false)
{
if (!is_writable($dir) OR !$dh = opendir($dir))
return false;
if ($recursive)
{
while (($file = readdir($dh)) !== false)
if (@filetype($dir.$file) == 'dir' AND $file != '.' AND $file != '..')
if (!self::test_dir($dir.$file, true))
return false;
}
closedir($dh);
return true;
}
// is_writable files
static private function test_file($file)
{
return (file_exists($file) AND is_writable($file));
}
static private function test_config_dir($dir)
{
return self::test_dir($dir);
}
static private function test_sitemap($dir)
{
return self::test_file($dir);
}
static private function test_root_dir($dir)
{
return self::test_dir($dir);
}
static private function test_admin_dir($dir)
{
return self::test_dir($dir);
}
static private function test_img_dir($dir)
{
return self::test_dir($dir, true);
}
static private function test_module_dir($dir)
{
return self::test_dir($dir, true);
}
static private function test_tools_dir($dir)
{
return self::test_dir($dir);
}
static function test_cache_dir($dir)
{
return self::test_dir($dir);
}
static private function test_download_dir($dir)
{
return self::test_dir($dir);
}
static private function test_mails_dir($dir)
{
return self::test_dir($dir, true);
}
static private function test_translations_dir($dir)
{
return self::test_dir($dir, true);
}
static private function test_theme_lang_dir($dir)
{
return self::test_dir($dir, true);
}
static private function test_customizable_products_dir($dir)
{
return self::test_dir($dir);
}
static private function test_virtual_products_dir($dir)
{
return self::test_dir($dir);
}
}