aboutsummaryrefslogtreecommitdiffstats
path: root/admin/include/functions_plugins.inc.php
diff options
context:
space:
mode:
authorpatdenice <patdenice@piwigo.org>2008-03-02 17:53:23 +0000
committerpatdenice <patdenice@piwigo.org>2008-03-02 17:53:23 +0000
commit78e175b3fb7c8d2f9824b15632595523f9ea236c (patch)
treef4ee8463f6b506e3deb474853bf5c4e28db5963c /admin/include/functions_plugins.inc.php
parentfab44f72a89396d624be49311fc0622635d44f8a (diff)
Enhance plugins administtration
git-svn-id: http://piwigo.org/svn/trunk@2242 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'admin/include/functions_plugins.inc.php')
-rw-r--r--admin/include/functions_plugins.inc.php178
1 files changed, 178 insertions, 0 deletions
diff --git a/admin/include/functions_plugins.inc.php b/admin/include/functions_plugins.inc.php
index b86c2d0a4..25ad0dd65 100644
--- a/admin/include/functions_plugins.inc.php
+++ b/admin/include/functions_plugins.inc.php
@@ -107,4 +107,182 @@ function get_admin_plugin_menu_link($file)
return $url;
}
+/**
+ * Sort plugins by status
+ */
+function sort_plugins_by_state($plugins, $db_plugins_by_id)
+{
+ $active_plugins = array();
+ $inactive_plugins = array();
+ $not_installed = array();
+
+ foreach($plugins as $plugin_id => $plugin)
+ {
+ if (isset($db_plugins_by_id[$plugin_id]))
+ {
+ $db_plugins_by_id[$plugin_id]['state'] == 'active' ?
+ $active_plugins[$plugin_id] = $plugin : $inactive_plugins[$plugin_id] = $plugin;
+ }
+ else
+ {
+ $not_installed[$plugin_id] = $plugin;
+ }
+ }
+ return $active_plugins + $inactive_plugins + $not_installed;
+}
+
+
+/**
+ * Retrieve PEM server datas
+ * @param bool (true for retrieve new extensions)
+ */
+function check_server_plugins($newext=false)
+{
+ global $fs_plugins;
+
+ foreach($fs_plugins as $plugin_id => $fs_plugin)
+ {
+ if (!empty($fs_plugin['uri']) and strpos($fs_plugin['uri'] , 'extension_view.php?eid='))
+ {
+ list( , $extension) = explode('extension_view.php?eid=', $fs_plugin['uri']);
+ if (!is_numeric($extension)) continue;
+ $plugins_to_check[] = $extension;
+ $fs_plugins[$plugin_id]['extension'] = $extension;
+ }
+ }
+
+ $url = PEM_URL . '/uptodate.php?version=' . rawurlencode(PHPWG_VERSION) . '&extensions=' . implode(',', $plugins_to_check);
+ $url .= $newext ? '&newext=Plugin' : '';
+
+ if (!empty($plugins_to_check) and $source = @file_get_contents($url))
+ {
+ return @unserialize($source);
+ }
+ return false;
+}
+
+
+/**
+ * Extract plugin files from archive
+ * @param string - install or upgrade
+ * @param string - archive URL
+ * @param string - destination path
+ */
+function extract_plugin_files($action, $source, $dest)
+{
+ global $archive;
+ if ($archive = tempnam( PHPWG_PLUGINS_PATH, 'zip'))
+ {
+ if (@copy(PEM_URL . str_replace(' ', '%20', $source), $archive))
+ {
+ $zip = new PclZip($archive);
+ if ($list = $zip->listContent())
+ {
+ foreach ($list as $file)
+ {
+ // we search main.inc.php in archive
+ if (basename($file['filename']) == 'main.inc.php'
+ and (!isset($main_filepath) or strlen($file['filename']) < strlen($main_filepath)))
+ {
+ $main_filepath = $file['filename'];
+ }
+ }
+
+ if (isset($main_filepath))
+ {
+ $root = dirname($main_filepath); // main.inc.php path in archive
+ if ($action == 'upgrade') $extract_path = PHPWG_PLUGINS_PATH . $dest;
+ else $extract_path = PHPWG_PLUGINS_PATH . ($root == '.' ? 'extension_' . $dest : basename($root));
+
+ if($result = $zip->extract(PCLZIP_OPT_PATH, $extract_path,
+ PCLZIP_OPT_REMOVE_PATH, $root,
+ PCLZIP_OPT_REPLACE_NEWER))
+ {
+ foreach ($result as $file)
+ {
+ if ($file['stored_filename'] == $main_filepath)
+ {
+ $status = $file['status'];
+ break;
+ }
+ }
+ }
+ else $status = 'extract_error';
+ }
+ else $status = 'archive_error';
+ }
+ else $status = 'archive_error';
+ }
+ else $status = 'dl_archive_error';
+ }
+ else $status = 'temp_path_error';
+
+ @unlink($archive);
+ return $status;
+}
+
+
+/**
+ * delete $path directory
+ * @param string - path
+ */
+function pm_deltree($path)
+{
+ if (is_dir($path))
+ {
+ $fh = opendir($path);
+ while ($file = readdir($fh))
+ {
+ if ($file != '.' and $file != '..')
+ {
+ $pathfile = $path . '/' . $file;
+ if (is_dir($pathfile)) pm_deltree($pathfile);
+ else @unlink($pathfile);
+ }
+ }
+ closedir($fh);
+ return @rmdir($path);
+ }
+}
+
+
+/**
+ * send $path to trash directory
+ * @param string - path
+ */
+function send_pm_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
+ */
+function extension_name_compare($a, $b)
+{
+ return strcmp(strtolower($a['ext_name']), strtolower($b['ext_name']));
+}
+function extension_author_compare($a, $b)
+{
+ $r = strcmp(strtolower($a['author']), strtolower($b['author']));
+ if ($r == 0) return extension_name_compare($a, $b);
+ else return $r;
+}
+
?> \ No newline at end of file