aboutsummaryrefslogtreecommitdiffstats
path: root/admin/include/themes.class.php
diff options
context:
space:
mode:
Diffstat (limited to 'admin/include/themes.class.php')
-rw-r--r--admin/include/themes.class.php185
1 files changed, 82 insertions, 103 deletions
diff --git a/admin/include/themes.class.php b/admin/include/themes.class.php
index 654d220ef..7832c42e0 100644
--- a/admin/include/themes.class.php
+++ b/admin/include/themes.class.php
@@ -2,7 +2,7 @@
// +-----------------------------------------------------------------------+
// | Piwigo - a PHP based photo gallery |
// +-----------------------------------------------------------------------+
-// | Copyright(C) 2008-2013 Piwigo Team http://piwigo.org |
+// | Copyright(C) 2008-2014 Piwigo Team http://piwigo.org |
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
// +-----------------------------------------------------------------------+
@@ -21,6 +21,36 @@
// | USA. |
// +-----------------------------------------------------------------------+
+/**
+ * class DummyTheme_maintain
+ * used when a theme uses the old procedural declaration of maintenance methods
+ */
+class DummyTheme_maintain extends ThemeMaintain
+{
+ function activate($theme_version, &$errors=array())
+ {
+ if (is_callable('theme_activate'))
+ {
+ return theme_activate($this->theme_id, $theme_version, $errors);
+ }
+ }
+ function deactivate()
+ {
+ if (is_callable('theme_deactivate'))
+ {
+ return theme_deactivate($this->theme_id);
+ }
+ }
+ function delete()
+ {
+ if (is_callable('theme_delete'))
+ {
+ return theme_delete($this->theme_id);
+ }
+ }
+}
+
+
class themes
{
var $fs_themes = array();
@@ -41,6 +71,37 @@ class themes
}
/**
+ * Returns the maintain class of a theme
+ * or build a new class with the procedural methods
+ * @param string $theme_id
+ */
+ private static function build_maintain_class($theme_id)
+ {
+ $file_to_include = PHPWG_THEMES_PATH.'/'.$theme_id.'/admin/maintain.inc.php';
+ $classname = $theme_id.'_maintain';
+
+ if (file_exists($file_to_include))
+ {
+ include_once($file_to_include);
+
+ if (class_exists($classname))
+ {
+ $theme_maintain = new $classname($theme_id);
+ }
+ else
+ {
+ $theme_maintain = new DummyTheme_maintain($theme_id);
+ }
+ }
+ else
+ {
+ $theme_maintain = new DummyTheme_maintain($theme_id);
+ }
+
+ return $theme_maintain;
+ }
+
+ /**
* Perform requested actions
* @param string - action
* @param string - theme id
@@ -55,7 +116,7 @@ class themes
$crt_db_theme = $this->db_themes_by_id[$theme_id];
}
- $file_to_include = PHPWG_THEMES_PATH.'/'.$theme_id.'/admin/maintain.inc.php';
+ $theme_maintain = self::build_maintain_class($theme_id);
$errors = array();
@@ -77,34 +138,23 @@ class themes
$missing_parent = $this->missing_parent_theme($theme_id);
if (isset($missing_parent))
{
- array_push(
- $errors,
- sprintf(
- l10n('Impossible to activate this theme, the parent theme is missing: %s'),
- $missing_parent
- )
+ $errors[] = l10n(
+ 'Impossible to activate this theme, the parent theme is missing: %s',
+ $missing_parent
);
break;
}
-
if ($this->fs_themes[$theme_id]['mobile']
and !empty($conf['mobile_theme'])
and $conf['mobile_theme'] != $theme_id)
{
- array_push($errors, l10n('You can activate only one mobile theme.'));
+ $errors[] = l10n('You can activate only one mobile theme.');
break;
}
- if (file_exists($file_to_include))
- {
- include($file_to_include);
- if (function_exists('theme_activate'))
- {
- theme_activate($theme_id, $this->fs_themes[$theme_id]['version'], $errors);
- }
- }
+ $theme_maintain->activate($this->fs_themes[$theme_id]['version'], $errors);
if (empty($errors))
{
@@ -134,10 +184,7 @@ INSERT INTO '.THEMES_TABLE.'
// you can't deactivate the last theme
if (count($this->db_themes_by_id) <= 1)
{
- array_push(
- $errors,
- l10n('Impossible to deactivate this theme, you need at least one theme.')
- );
+ $errors[] = l10n('Impossible to deactivate this theme, you need at least one theme.');
break;
}
@@ -147,8 +194,7 @@ INSERT INTO '.THEMES_TABLE.'
$new_theme = null;
$query = '
-SELECT
- id
+SELECT id
FROM '.THEMES_TABLE.'
WHERE id != \''.$theme_id.'\'
;';
@@ -165,14 +211,7 @@ SELECT
$this->set_default_theme($new_theme);
}
- if (file_exists($file_to_include))
- {
- include($file_to_include);
- if (function_exists('theme_deactivate'))
- {
- theme_deactivate($theme_id);
- }
- }
+ $theme_maintain->deactivate();
$query = '
DELETE
@@ -190,7 +229,7 @@ DELETE
case 'delete':
if (!empty($crt_db_theme))
{
- array_push($errors, 'CANNOT DELETE - THEME IS INSTALLED');
+ $errors[] = 'CANNOT DELETE - THEME IS INSTALLED';
break;
}
if (!isset($this->fs_themes[$theme_id]))
@@ -202,20 +241,16 @@ DELETE
$children = $this->get_children_themes($theme_id);
if (count($children) > 0)
{
- array_push(
- $errors,
- sprintf(
- l10n('Impossible to delete this theme. Other themes depends on it: %s'),
- implode(', ', $children)
- )
+ $errors[] = l10n(
+ 'Impossible to delete this theme. Other themes depends on it: %s',
+ implode(', ', $children)
);
break;
}
- if (!$this->deltree(PHPWG_THEMES_PATH.$theme_id))
- {
- $this->send_to_trash(PHPWG_THEMES_PATH.$theme_id);
- }
+ $theme_maintain->delete();
+
+ deltree(PHPWG_THEMES_PATH.$theme_id, PHPWG_THEMES_PATH . 'trash');
break;
case 'set_default':
@@ -256,7 +291,7 @@ DELETE
{
if (isset($test_child['parent']) and $test_child['parent'] == $theme_id)
{
- array_push($children, $test_child['name']);
+ $children[] = $test_child['name'];
}
}
@@ -316,7 +351,7 @@ SELECT
$themes = array();
while ($row = pwg_db_fetch_assoc($result))
{
- array_push($themes, $row);
+ $themes[] = $row;
}
return $themes;
}
@@ -622,7 +657,7 @@ SELECT
and $old_files = file($extract_path.'/obsolete.list', FILE_IGNORE_NEW_LINES)
and !empty($old_files))
{
- array_push($old_files, 'obsolete.list');
+ $old_files[] = 'obsolete.list';
foreach($old_files as $old_file)
{
$path = $extract_path.'/'.$old_file;
@@ -632,10 +667,7 @@ SELECT
}
elseif (is_dir($path))
{
- if (!$this->deltree($path))
- {
- $this->send_to_trash($path);
- }
+ deltree($path, PHPWG_THEMES_PATH . 'trash');
}
}
}
@@ -655,59 +687,6 @@ SELECT
}
/**
- * delete $path directory
- * @param string - path
- */
- function deltree($path)
- {
- if (is_dir($path))
- {
- $fh = opendir($path);
- while ($file = readdir($fh))
- {
- if ($file != '.' and $file != '..')
- {
- $pathfile = $path . '/' . $file;
- if (is_dir($pathfile))
- {
- $this->deltree($pathfile);
- }
- else
- {
- @unlink($pathfile);
- }
- }
- }
- closedir($fh);
- return @rmdir($path);
- }
- }
-
- /**
- * send $path to trash directory
- * @param string - path
- */
- function send_to_trash($path)
- {
- $trash_path = PHPWG_THEMES_PATH . 'trash';
- if (!is_dir($trash_path))
- {
- @mkdir($trash_path);
- $file = @fopen($trash_path . '/.htaccess', 'w');
- @fwrite($file, 'deny from all');
- @fclose($file);
- }
- while ($r = $trash_path . '/' . md5(uniqid(rand(), true)))
- {
- if (!is_dir($r))
- {
- @rename($path, $r);
- break;
- }
- }
- }
-
- /**
* Sort functions
*/
function theme_version_compare($a, $b)