// add theme add/remove function
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@11831 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
+48
-1
@@ -28,6 +28,7 @@
|
||||
class ThemeCore extends ObjectModel
|
||||
{
|
||||
public $name;
|
||||
public $directory;
|
||||
|
||||
/**
|
||||
* @see ObjectModel::$definition
|
||||
@@ -36,7 +37,8 @@ class ThemeCore extends ObjectModel
|
||||
'table' => 'theme',
|
||||
'primary' => 'id_theme',
|
||||
'fields' => array(
|
||||
'name' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 64),
|
||||
'name' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 64, 'required' => true),
|
||||
'directory' => array('type' => self::TYPE_STRING, 'validate' => 'isValidThemeDir', 'size' => 64, 'required' => true),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -47,4 +49,49 @@ class ThemeCore extends ObjectModel
|
||||
ORDER BY name';
|
||||
return Db::getInstance()->executeS($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* return an array of all available theme (installed or not)
|
||||
*
|
||||
* @param boolean $installed
|
||||
* @return array string (directory)
|
||||
*/
|
||||
public static function getAvailable($installed_only = true){
|
||||
static $dirlist = array();
|
||||
$available_theme = array();
|
||||
|
||||
if (empty($dirlist))
|
||||
{
|
||||
$themes = scandir(_PS_ALL_THEMES_DIR_);
|
||||
foreach ($themes AS $theme)
|
||||
if (is_dir(_PS_ALL_THEMES_DIR_.DIRECTORY_SEPARATOR.$theme) && $theme[0] != '.')
|
||||
$dirlist[] = $theme;
|
||||
}
|
||||
|
||||
if ($installed_only)
|
||||
{
|
||||
$themes = Theme::getThemes();
|
||||
foreach($themes as $theme_obj)
|
||||
$themes_dir[] = $theme_obj['directory'];
|
||||
foreach( $dirlist as $theme)
|
||||
if (false !== array_search($theme, $themes_dir))
|
||||
$available_theme[] = $theme;
|
||||
}
|
||||
else
|
||||
$available_theme = $dirlist;
|
||||
|
||||
return $available_theme;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* check if a theme is used by a shop
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isUsed()
|
||||
{
|
||||
return Db::getInstance()->getValue('SELECT count(*)
|
||||
FROM '._DB_PREFIX_.'shop WHERE id_theme = '.(int)$this->id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -965,5 +965,17 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ class ShopCore extends ObjectModel
|
||||
public $deleted;
|
||||
|
||||
public $theme_name;
|
||||
public $theme_directory;
|
||||
public $physical_uri;
|
||||
public $virtual_uri;
|
||||
public $domain;
|
||||
@@ -122,7 +123,7 @@ class ShopCore extends ObjectModel
|
||||
|
||||
if ($this->id)
|
||||
{
|
||||
$sql = 'SELECT su.physical_uri, su.virtual_uri, su.domain, su.domain_ssl, t.name
|
||||
$sql = 'SELECT su.physical_uri, su.virtual_uri, su.domain, su.domain_ssl, t.name, t.directory
|
||||
FROM '._DB_PREFIX_.'shop s
|
||||
LEFT JOIN '._DB_PREFIX_.'shop_url su ON (s.id_shop = su.id_shop)
|
||||
LEFT JOIN '._DB_PREFIX_.'theme t ON (t.id_theme = s.id_theme)
|
||||
@@ -134,6 +135,7 @@ class ShopCore extends ObjectModel
|
||||
return;
|
||||
|
||||
$this->theme_name = $row['name'];
|
||||
$this->theme_directory = $row['directory'];
|
||||
$this->physical_uri = $row['physical_uri'];
|
||||
$this->virtual_uri = $row['virtual_uri'];
|
||||
$this->domain = $row['domain'];
|
||||
@@ -324,7 +326,7 @@ class ShopCore extends ObjectModel
|
||||
*/
|
||||
public function getTheme()
|
||||
{
|
||||
return $this->theme_name;
|
||||
return $this->theme_directory;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user