Add display of version numbers next to plugin listings
authorpdontthink <pdontthink@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Sat, 3 Feb 2007 00:10:25 +0000 (00:10 +0000)
committerpdontthink <pdontthink@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Sat, 3 Feb 2007 00:10:25 +0000 (00:10 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@12217 7612ce4b-ef26-0410-bec9-ea0150e637f0

config/conf.pl

index f73864b8acf4164f8cdbf4c4a47702368928aa42..0f3c4c3fa6cb42e7f28cae9b4f6f420a397870a7 100755 (executable)
@@ -723,7 +723,7 @@ while ( ( $command ne "q" ) && ( $command ne "Q" ) && ( $command ne ":q" ) ) {
         $num = 0;
         for ( $count = 0 ; $count <= $#plugins ; $count++ ) {
             $num = $count + 1;
         $num = 0;
         for ( $count = 0 ; $count <= $#plugins ; $count++ ) {
             $num = $count + 1;
-            print "    $num. $plugins[$count]\n";
+            print "    $num. $plugins[$count]" . get_plugin_version($plugins[$count]) . "\n";
         }
         print "\n  Available Plugins:\n";
         opendir( DIR, "../plugins" );
         }
         print "\n  Available Plugins:\n";
         opendir( DIR, "../plugins" );
@@ -747,7 +747,7 @@ while ( ( $command ne "q" ) && ( $command ne "Q" ) && ( $command ne ":q" ) ) {
 
         for ( $i = 0 ; $i <= $#unused_plugins ; $i++ ) {
             $num = $num + 1;
 
         for ( $i = 0 ; $i <= $#unused_plugins ; $i++ ) {
             $num = $num + 1;
-            print "    $num. $unused_plugins[$i]\n";
+            print "    $num. $unused_plugins[$i]" . get_plugin_version($unused_plugins[$i]) . "\n";
         }
         closedir DIR;
 
         }
         closedir DIR;
 
@@ -5104,6 +5104,68 @@ sub quote_single($) {
     return $string;
 }
 
     return $string;
 }
 
+# determine a plugin's version number
+#
+# parses the setup.php file, looking for the
+# version string in the <plugin>_info() or the
+# <plugin>_version functions.
+#
+sub get_plugin_version() {
+
+    my $plugin_name = shift(@_);
+
+    $setup_file = '../plugins/' . $plugin_name . '/setup.php';
+    if ( -e "$setup_file" ) {
+        # Make sure that file is readable
+        if (! -r "$setup_file") {
+            print "\n";
+            print "WARNING:\n";
+            print "The file \"$setup_file\" was found, but you don't\n";
+            print "have rights to read it.  The plugin \"";
+            print $plugin_name . "\" may not work correctly until you fix this.\n";
+            print "\nPress enter to continue";
+            $ctu = <STDIN>;
+            print "\n";
+            next;
+        }
+
+        $version = ' ';
+# FIXME: grep the file instead of reading it into memory?
+        $whole_file = '';
+        open( FILE, "$setup_file" );
+        while ( $line = <FILE> ) {
+            $whole_file .= $line;
+        }
+        close(FILE);
+
+        # ideally, there is a version in the <plugin>_info function...
+        #
+        if ($whole_file =~ /('version'\s*=>\s*['"](.*?)['"])/) {
+            $version .= $2;
+
+        # this assumes there is only one function that returns 
+        # a static string in the setup file
+        #
+        } elsif ($whole_file =~ /(return\s*['"](.*?)['"])/) {
+            $version .= $2;
+        }
+
+        return $version;
+
+        } else {
+            print "\n";
+            print "WARNING:\n";
+            print "The file \"$setup_file\" was not found.\n";
+            print "The plugin \"" . $plugin_name;
+            print "\" may not work correctly until you fix this.\n";
+            print "\nPress enter to continue";
+            $ctu = <STDIN>;
+            print "\n";
+            next;
+        }
+
+}
+
 # parses the setup.php files for all activated plugins and
 # builds static plugin hooks array so we don't have to load
 # ALL plugins are runtime and build the hook array on every
 # parses the setup.php files for all activated plugins and
 # builds static plugin hooks array so we don't have to load
 # ALL plugins are runtime and build the hook array on every