From 20a844085f42975a9e2d20a9cd489a0251d52ad5 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 1 Mar 2021 12:11:42 +0300 Subject: hide version for bundled plugins because it's meaningless; for everything else support showing version using git (if about[0] is null) --- classes/pref/prefs.php | 61 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 6 deletions(-) (limited to 'classes/pref') diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php index 3436e4f60..565ddaded 100644 --- a/classes/pref/prefs.php +++ b/classes/pref/prefs.php @@ -795,6 +795,7 @@ class Pref_Prefs extends Handler_Protected { foreach ($tmppluginhost->get_plugins() as $name => $plugin) { $about = $plugin->about(); + $version = htmlspecialchars($this->_get_plugin_version($plugin)); if ($about[3] ?? false) { $is_checked = in_array($name, $system_enabled) ? "checked" : ""; @@ -811,9 +812,11 @@ class Pref_Prefs extends Handler_Protected { open_in_new -
- -
+ +
+ +
+ get_plugins() as $name => $plugin) { $about = $plugin->about(); + $version = htmlspecialchars($this->_get_plugin_version($plugin)); if (empty($about[3]) || $about[3] == false) { @@ -875,9 +879,11 @@ class Pref_Prefs extends Handler_Protected { open_in_new -
- -
+ +
+ +
+ ["pipe", "w"], // STDOUT + 2 => ["pipe", "w"], // STDERR + ]; + + $proc = proc_open("git --no-pager log --pretty=\"%ct %h\" -n1 HEAD", + $descriptorspec, $pipes, $dir); + + if (is_resource($proc)) { + $stdout = stream_get_contents($pipes[1]); + $stderr = stream_get_contents($pipes[2]); + $status = proc_close($proc); + + if ($status == 0) { + list($timestamp, $commit) = explode(" ", $stdout); + return trim(strftime("%y.%m", (int)$timestamp) . "-$commit"); + } else { + return T_sprintf("Git error [RC=%d]: %s", $status, $stderr); + } + } + } + + function _get_plugin_version(Plugin $plugin) { + $about = $plugin->about(); + + if (!empty($about[0])) { + return T_sprintf("v%.2f, by %s", $about[0], $about[2]); + } else { + $ref = new ReflectionClass(get_class($plugin)); + + $plugin_dir = dirname($ref->getFileName()); + + if (basename($plugin_dir) == "plugins") { + return ""; + } + + if (is_dir("$plugin_dir/.git")) { + return T_sprintf("v%s, by %s", $this->_get_version_from_git($plugin_dir), $about[2]); + } + } + } + static function _get_updated_plugins() { $root_dir = dirname(dirname(__DIR__)); # we're in classes/pref/ $plugin_dirs = array_filter(glob("$root_dir/plugins.local/*"), "is_dir"); -- cgit v1.2.3-54-g00ecf