Skip to content

Commit

Permalink
bug:2898 make some updates methods static + factorize code from plugi…
Browse files Browse the repository at this point in the history
…ns, themes & languages

git-svn-id: http://piwigo.org/svn/trunk@23821 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
mistic100 committed Jul 7, 2013
1 parent 718ef5a commit d95425b
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 232 deletions.
54 changes: 54 additions & 0 deletions admin/include/functions.php
Expand Up @@ -2527,4 +2527,58 @@ function get_dirs($directory)
}
return $sub_dirs;
}

/**
* recursively delete a directory
* @param string $path
* @param string $trash_path, try to move the directory to this path if it cannot be delete
*/
function deltree($path, $trash_path=null)
{
if (is_dir($path))
{
$fh = opendir($path);
while ($file = readdir($fh))
{
if ($file != '.' and $file != '..')
{
$pathfile = $path . '/' . $file;
if (is_dir($pathfile))
{
deltree($pathfile, $trash_path);
}
else
{
@unlink($pathfile);
}
}
}
closedir($fh);

if (@rmdir($path))
{
return true;
}
elseif (!empty($trash_path))
{
if (!is_dir($trash_path))
{
@mkgetdir($trash_path, MKGETDIR_RECURSIVE|MKGETDIR_DIE_ON_ERROR|MKGETDIR_PROTECT_HTACCESS);
}
while ($r = $trash_path . '/' . md5(uniqid(rand(), true)))
{
if (!is_dir($r))
{
@rename($path, $r);
break;
}
}
}
else
{
return false;
}
}
}

?>
63 changes: 2 additions & 61 deletions admin/include/languages.class.php
Expand Up @@ -112,10 +112,7 @@ function perform_action($action, $language_id)
;';
pwg_query($query);

if (!$this->deltree(PHPWG_ROOT_PATH.'language/'.$language_id))
{
$this->send_to_trash(PHPWG_ROOT_PATH.'language/'.$language_id);
}
deltree(PHPWG_ROOT_PATH.'language/'.$language_id, PHPWG_ROOT_PATH.'language/trash');
break;

case 'set_default':
Expand Down Expand Up @@ -381,10 +378,7 @@ function extract_language_files($action, $revision, $dest='')
}
elseif (is_dir($path))
{
if (!$this->deltree($path))
{
$this->send_to_trash($path);
}
deltree($path, PHPWG_ROOT_PATH.'language/trash');
}
}
}
Expand All @@ -405,59 +399,6 @@ function extract_language_files($action, $revision, $dest='')
return $status;
}

/**
* 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_ROOT_PATH . 'language/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
*/
Expand Down
63 changes: 2 additions & 61 deletions admin/include/plugins.class.php
Expand Up @@ -166,10 +166,7 @@ function perform_action($action, $plugin_id)
{
break;
}
if (!$this->deltree(PHPWG_PLUGINS_PATH . $plugin_id))
{
$this->send_to_trash(PHPWG_PLUGINS_PATH . $plugin_id);
}
deltree(PHPWG_PLUGINS_PATH . $plugin_id, PHPWG_PLUGINS_PATH . 'trash');
break;
}
return $errors;
Expand Down Expand Up @@ -514,10 +511,7 @@ function extract_plugin_files($action, $revision, $dest)
}
elseif (is_dir($path))
{
if (!$this->deltree($path))
{
$this->send_to_trash($path);
}
deltree($path, PHPWG_PLUGINS_PATH . 'trash');
}
}
}
Expand Down Expand Up @@ -553,59 +547,6 @@ function get_merged_extensions($version=PHPWG_VERSION)
}
return $merged_extensions;
}

/**
* 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_PLUGINS_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
Expand Down
63 changes: 2 additions & 61 deletions admin/include/themes.class.php
Expand Up @@ -221,10 +221,7 @@ function perform_action($action, $theme_id)
}
}

if (!$this->deltree(PHPWG_THEMES_PATH.$theme_id))
{
$this->send_to_trash(PHPWG_THEMES_PATH.$theme_id);
}
deltree(PHPWG_THEMES_PATH.$theme_id, PHPWG_THEMES_PATH . 'trash');
break;

case 'set_default':
Expand Down Expand Up @@ -641,10 +638,7 @@ function extract_theme_files($action, $revision, $dest)
}
elseif (is_dir($path))
{
if (!$this->deltree($path))
{
$this->send_to_trash($path);
}
deltree($path, PHPWG_THEMES_PATH . 'trash');
}
}
}
Expand All @@ -663,59 +657,6 @@ function extract_theme_files($action, $revision, $dest)
return $status;
}

/**
* 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
*/
Expand Down

0 comments on commit d95425b

Please sign in to comment.