From 73c59ebe1cba8eeaeb8b6acb5b1bc43ec5dd1372 Mon Sep 17 00:00:00 2001 From: mMarinetti Date: Fri, 30 Dec 2011 16:02:29 +0000 Subject: [PATCH] // theme class improvement git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@11953 b9a71923-0436-4b27-9f14-aed3839534dd --- classes/Theme.php | 19 ++++++++++++++++++- classes/Validate.php | 22 +++++++++++----------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/classes/Theme.php b/classes/Theme.php index 5a99c9479..06cb80317 100644 --- a/classes/Theme.php +++ b/classes/Theme.php @@ -30,6 +30,8 @@ class ThemeCore extends ObjectModel public $name; public $directory; + /** @var int access rights of created folders (octal) */ + public static $access_rights = 0775; /** * @see ObjectModel::$definition */ @@ -38,7 +40,7 @@ class ThemeCore extends ObjectModel 'primary' => 'id_theme', 'fields' => array( 'name' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 64, 'required' => true), - 'directory' => array('type' => self::TYPE_STRING, 'validate' => 'isValidThemeDir', 'size' => 64, 'required' => true), + 'directory' => array('type' => self::TYPE_STRING, 'validate' => 'isDirName', 'size' => 64, 'required' => true), ), ); @@ -93,4 +95,19 @@ class ThemeCore extends ObjectModel return Db::getInstance()->getValue('SELECT count(*) FROM '._DB_PREFIX_.'shop WHERE id_theme = '.(int)$this->id); } + + /** + * add only theme if the directory exists + * + * @param bool $null_values + * @param bool $autodate + * @return boolean Insertion result + */ + public function add($autodate = true, $null_values = false) + { + if (!is_dir(_PS_ALL_THEMES_DIR_.$this->directory)) + return false; + + return parent::add($autodate, $null_values); + } } diff --git a/classes/Validate.php b/classes/Validate.php index 947cefff0..86b4ddf4e 100644 --- a/classes/Validate.php +++ b/classes/Validate.php @@ -713,6 +713,17 @@ class ValidateCore { return preg_match('/^[a-zA-Z0-9_.-]*$/', $name); } + + /** + * Check for standard name directory validity + * + * @param string $name Name to validate + * @return boolean Validity is ok or not + */ + public static function isDirName($dir) + { + return (bool)preg_match('/^[a-zA-Z0-9_.-]*$/', $dir); + } /** * Check for admin panel tab name validity @@ -966,16 +977,5 @@ class ValidateCore return (bool)preg_match('/^[0-9]{3,4}[a-zA-Z]{1}$/s', $ape); } - /** - * Validate theme directory - * We currently check if the item is a valid theme directory - * - * @param string $dir - * @return boolean - */ - public static function isValidThemeDir($dir) - { - return ($dir[0] != '.') && is_dir(_PS_ALL_THEMES_DIR_.DIRECTORY_SEPARATOR.$dir); - } }