From ad0bba3ac3facb55dd7ed7035cac920441eafe90 Mon Sep 17 00:00:00 2001 From: brentil Date: Tue, 4 Jan 2011 22:21:23 -0500 Subject: [PATCH 1/2] MU 5 - Fully supports 3.x versions along with pulling version information from multiple sources (Core, Contrib, & GalleryModules). Code cleanup and debug removal. --- .../controllers/admin_moduleupdates.php | 266 ++++++++++------- .../helpers/moduleupdates_event.php | 2 +- .../helpers/moduleupdates_installer.php | 6 +- 3.0/modules/moduleupdates/module.info | 2 +- .../views/admin_moduleupdates.html.php | 35 ++- .../controllers/admin_moduleupdates.php | 271 +++++++++++------- .../helpers/moduleupdates_installer.php | 8 +- 3.1/modules/moduleupdates/module.info | 2 +- .../views/admin_moduleupdates.html.php | 33 ++- 9 files changed, 382 insertions(+), 243 deletions(-) diff --git a/3.0/modules/moduleupdates/controllers/admin_moduleupdates.php b/3.0/modules/moduleupdates/controllers/admin_moduleupdates.php index b1274111..926d8196 100755 --- a/3.0/modules/moduleupdates/controllers/admin_moduleupdates.php +++ b/3.0/modules/moduleupdates/controllers/admin_moduleupdates.php @@ -16,7 +16,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ - class Admin_Moduleupdates_Controller extends Admin_Controller { /** @@ -44,15 +43,10 @@ class Admin_Moduleupdates_Controller extends Admin_Controller { $view->page_title = t("Gallery 3 :: Manage Module Updates"); $view->content = new View("admin_moduleupdates.html"); - $devDebug = false; $refreshCache = false; $cache = unserialize(Cache::instance()->get("moduleupdates_cache")); $cache_updates = unserialize(Cache::instance()->get("moduleupdates_cache_updates")); - - //--------------------------------------------------------------------------------------------- - //echo 'Message 01: ' .$cache_updates . '
'; - //--------------------------------------------------------------------------------------------- //if someone pressed the button to refresh now if (request::method() == "post") { @@ -78,7 +72,6 @@ class Admin_Moduleupdates_Controller extends Admin_Controller { } } catch (Exception $e) { - //echo 'Message: ' .$e->getMessage() . '
'; } //Check the ability to access the Google $Google = null; @@ -91,71 +84,79 @@ class Admin_Moduleupdates_Controller extends Admin_Controller { } } catch (Exception $e) { - //echo 'Message: ' .$e->getMessage() . '
'; } + $update_count = 0; + if($refreshCache == true){ foreach (module::available() as $this_module_name => $module_info) { + + $font_color_local = "black"; + $core_version = ''; + $core_server = ''; + $core_dlink = ''; + $font_color_core = "black"; + $contrib_version = ''; + $contrib_server = ''; + $contrib_dlink = ''; + $font_color_contrib = "black"; + $gh_version = ''; + $gh_server = ''; + $gh_dlink = ''; + $font_color_gh = "black"; - //example code for setting cache values - //Cache::instance()->set($key, "$log{$msg}", array("task", "log", "import"), 2592000); - //example delete cache - //Cache::instance()->delete("update_l10n_cache:{$task->id}"); - //example for reading cache - //$log = Cache::instance()->get($key); - $remote_version = ''; - $remote_server = ''; - $update_count = 0; - list ($remote_version, $remote_server) = $this->get_remote_module_version($this_module_name, $devDebug); + $font_color_local = $this->get_local_module_version_color ($module_info->version, $module_info->code_version); + list ($core_version, $core_server) = $this->get_remote_module_version($this_module_name, "CORE"); + $font_color_core = $this->get_module_version_color ($module_info->version, $module_info->code_version, $core_version); + list ($contrib_version, $contrib_server) = $this->get_remote_module_version($this_module_name, "CONTRIB"); + $font_color_contrib = $this->get_module_version_color ($module_info->version, $module_info->code_version, $contrib_version); + list ($gh_version, $gh_server) = $this->get_remote_module_version($this_module_name, "GH"); + $font_color_gh = $this->get_module_version_color ($module_info->version, $module_info->code_version, $gh_version); - $font_color = "black"; - //BLUE - DNE: Does Not Exist, this module was not found - if ($remote_version == "DNE") { - $font_color = "blue"; - //PINK - Your installed version is newer than file version - } else if ($module_info->version != '' and $module_info->code_version < $module_info->version) { - $font_color = "pink"; - //ORANGE - Your file version is newer than the installed version - } else if ($module_info->version != '' and $module_info->code_version > $module_info->version) { - $font_color = "orange"; - //GREEN - Your version is newer than the GitHub - } else if ($remote_version < $module_info->code_version or ($module_info->version != '' - and $remote_version < $module_info->version)) { - $font_color = "green"; - //RED - Your version is older than the GitHub - } else if ($remote_version > $module_info->code_version or ($module_info->version != '' - and $remote_version > $module_info->version)) { - $font_color = "red"; + if($font_color_core == "red" or $font_color_contrib == "red" or $font_color_gh == "red"){ $update_count++; - /* - if($remote_server == "(G3)"){ - $module_info->name = "".$module_info->name.""; - }else if($remote_server == "(G3CC)"){ - $module_info->name = "".$module_info->name.""; - }else if($remote_server == "(brentil)"){ - $module_info->name = "".$module_info->name.""; - } - */ } $module_info->name = "".$module_info->name.""; + if (is_numeric($core_version)) { + if($core_version > $module_info->version) { + //https://github.com/gallery/gallery3/tree/master/modules/recaptcha + //"http://github.com/gallery/gallery3/tree/master/modules/".$this_module_name + $core_dlink = "http://github.com/gallery/gallery3/tree/master/modules/".$this_module_name; + } + } + + if (is_numeric($contrib_version)) { + if($contrib_version > $module_info->version) { + //https://github.com/gallery/gallery3-contrib/tree/master/3.0/modules/moduleupdates + //"http://github.com/gallery/gallery3-contrib/tree/master/". substr_replace(gallery::VERSION,"",strpos(gallery::VERSION," ")) ."/modules/".$this_module_name + $contrib_dlink = "http://github.com/gallery/gallery3-contrib/tree/master/". substr_replace(gallery::VERSION,"",strpos(gallery::VERSION," ")) ."/modules/".$this_module_name; + } + } + + if (is_numeric($gh_version)) { + if($gh_version > $module_info->version) { + $gh_dlink = "http://www.gallerymodules.com/update/".$this_module_name; + } + } + //populate the list fo modules and their data $cache->$this_module_name = array ("name" => $module_info->name, "locked" => $module_info->locked, "code_version" => $module_info->code_version, "active" => $module_info->active, "version" => $module_info->version,"description" => $module_info->description, - "remote_version" => $remote_version, "remote_server" => $remote_server, "font_color" => $font_color); + "core_version" => $core_version, "core_server" => $core_server, "font_color_core" => $font_color_core, + "contrib_version" => $contrib_version, "contrib_server" => $contrib_server, "font_color_contrib" => $font_color_contrib, + "gh_version" => $gh_version, "gh_server" => $gh_server, "font_color_gh" => $font_color_gh, + "font_color_local" => $font_color_local, "core_dlink" => $core_dlink, "contrib_dlink" => $contrib_dlink, + "gh_dlink" => $gh_dlink); } //Define right now as YYYY.MM.DD HH:MM with the # of updates that are out of date $cache_updates = array("date" => date("Y.m.d - H:i"), "updates" => $update_count); - - //--------------------------------------------------------------------------------------------- - //echo 'Message 02: ' .$cache_updates . '
'; - //--------------------------------------------------------------------------------------------- - + //Write out the new data to cache with a 30 day expiration & 0 for update data so it's always present Cache::instance()->set("moduleupdates_cache", serialize($cache), array("ModuleUpdates"), 30*86400); Cache::instance()->set("moduleupdates_cache_updates", serialize($cache_updates), array("ModuleUpdates"), null); @@ -174,6 +175,52 @@ class Admin_Moduleupdates_Controller extends Admin_Controller { } + /** + * + **/ + private function get_module_version_color ($version, $code_version, $remote_version) { + + $font_color = "black"; + + //BLACK - no module version detected + if ($remote_version == "") { + $font_color = "black"; + //BLUE - DNE: Does Not Exist, this module was not found + } else if ($remote_version == "DNE") { + $font_color = "blue"; + //GREEN - Your version is newer than the GitHub + } else if ($remote_version < $code_version or ($version != '' + and $remote_version < $version)) { + $font_color = "green"; + //RED - Your version is older than the GitHub + } else if ($remote_version > $code_version or ($version != '' + and $remote_version > $version)) { + $font_color = "red"; + } + + return $font_color; + } + + + /** + * + **/ + private function get_local_module_version_color ($version, $code_version) { + + $font_color = "black"; + + //PINK - Your installed version is newer than file version + if ($version != '' and $code_version < $version) { + $font_color = "pink"; + //ORANGE - Your file version is newer than the installed version + } else if ($version != '' and $code_version > $version) { + $font_color = "orange"; + } + + return $font_color; + } + + /** * Parses the known GitHub repositories for new versions of modules. * @@ -183,71 +230,82 @@ class Admin_Moduleupdates_Controller extends Admin_Controller { * * http://github.com/gallery/gallery3 * http://github.com/gallery/gallery3-contrib + * http://www.gallerymodules.com * * @author brentil - * @param String The folder name of the module to search for on the remote GitHub server - * @return Array An array with the remote module version and the server it was found on. + * @param String - The folder name of the module to search for on the remote GitHub server + * @param String - The remote server to check against + * @return Array - An array with the remote module version and the server it was found on. */ - private function get_remote_module_version ($module_name, $devDebug) { + private function get_remote_module_version ($module_name, $server_location) { - $version = 'DNE'; + $version = ''; $server = ''; $file = null; - //For development debug only - if ($devDebug == true){ - if ($file == null) { - try { - $file = fopen ("http://github.com/brentil/gallery3-contrib/raw/master/". substr_replace(gallery::VERSION,"",strpos(gallery::VERSION," ")) ."/modules/".$module_name."/module.info", "r"); - if ($file != null) { - $server = '(brentil)'; + switch ($server_location) { + case "CONTRIB": + //Check the Gallery3 Community Contributions GitHub + if ($file == null) { + try { + $file = fopen ("http://github.com/gallery/gallery3-contrib/raw/master/". substr_replace(gallery::VERSION,"",strpos(gallery::VERSION," ")) ."/modules/".$module_name."/module.info", "r"); + if ($file != null) { + $server = '(GCC)'; + } + } + catch (Exception $e) { + } } - } - catch (Exception $e) { - //echo 'Message: ' .$e->getMessage() . '
'; - } - } - } - - //Check the main Gallery3 GitHub - if ($file == null) { - try { - $file = fopen ("http://github.com/gallery/gallery3/raw/master/modules/".$module_name."/module.info", "r"); - if ($file != null) { - $server = '(G)'; - } - } - catch (Exception $e) { - //echo 'Message: ' .$e->getMessage() . '
'; - } + break; + case "CORE": + //Check the main Gallery3 GitHub + if ($file == null) { + try { + $file = fopen ("http://github.com/gallery/gallery3/raw/master/modules/".$module_name."/module.info", "r"); + if ($file != null) { + $server = '(G)'; + } + } + catch (Exception $e) { + } + } + break; + case "GH": + //Check GalleryModules.com + if ($file == null) { + try { + $file = fopen ("http://www.gallerymodules.com/m/".$module_name, "r"); + if ($file != null) { + $server = '(GH)'; + } + } + catch (Exception $e) { + } + } + break; } - - //Check the Gallery3 Community Contributions GitHub - if ($file == null) { - try { - $file = fopen ("http://github.com/gallery/gallery3-contrib/raw/master/". substr_replace(gallery::VERSION,"",strpos(gallery::VERSION," ")) ."/modules/".$module_name."/module.info", "r"); - if ($file != null) { - $server = '(GCC)'; - } - } - catch (Exception $e) { - //echo 'Message: ' .$e->getMessage() . '
'; - } - } - - if ($file != null) { + + if ($file != null) { while (!feof ($file)) { $line = fgets ($file, 1024); - - //Regular expression to find & gather the version number in the remote module.info file - if (preg_match ("@version = (.*)@i", $line, $out)) { - $version = $out[1]; - break; - } + if ($server_location == "GH"){ + //GH stores only the version info + if($line == "Not entered" or $line == "See git") { + $line = ""; + } + $version = $line; + break; + } else { + //Regular expression to find & gather the version number in the remote module.info file + if (preg_match ("@version = (.*)@i", $line, $out)) { + $version = $out[1]; + break; + } + } } fclose ($file); } - return array ($version, $server); - } -} + return array ($version, $server); + } +} \ No newline at end of file diff --git a/3.0/modules/moduleupdates/helpers/moduleupdates_event.php b/3.0/modules/moduleupdates/helpers/moduleupdates_event.php index 8dbed46c..dd6efc9c 100644 --- a/3.0/modules/moduleupdates/helpers/moduleupdates_event.php +++ b/3.0/modules/moduleupdates/helpers/moduleupdates_event.php @@ -27,4 +27,4 @@ class moduleupdates_event_Core { ->label(t("Module Updates")) ->url(url::site("admin/moduleupdates"))); } -} +} \ No newline at end of file diff --git a/3.0/modules/moduleupdates/helpers/moduleupdates_installer.php b/3.0/modules/moduleupdates/helpers/moduleupdates_installer.php index 39d1dcc0..911f6b81 100644 --- a/3.0/modules/moduleupdates/helpers/moduleupdates_installer.php +++ b/3.0/modules/moduleupdates/helpers/moduleupdates_installer.php @@ -23,8 +23,8 @@ class moduleupdates_installer { static function install() { $version = module::get_version("moduleupdates"); - if ($version == 0) { - module::set_version("moduleupdates", 4); + if ($version < 1) { + module::set_version("moduleupdates", 5); //Remove the ModuleUpdates cache entry 'JIC' Cache::instance()->delete("ModuleUpdates"); //create the blank ModuleUpdates cache entry with an expiration of 0 days @@ -34,7 +34,7 @@ class moduleupdates_installer { } static function upgrade($version) { - module::set_version("moduleupdates", 4); + module::set_version("moduleupdates", 5); //Remove the ModuleUpdates cache entry 'JIC' Cache::instance()->delete("ModuleUpdates"); //Empty the ModuleUpdates cache entry so our new version starts from scratch diff --git a/3.0/modules/moduleupdates/module.info b/3.0/modules/moduleupdates/module.info index 722abecc..34868eaf 100755 --- a/3.0/modules/moduleupdates/module.info +++ b/3.0/modules/moduleupdates/module.info @@ -1,3 +1,3 @@ name = "Module Updates" description = "Compares your installed module version against the ones stored in the GitHub." -version = 4 \ No newline at end of file +version = 5 \ No newline at end of file diff --git a/3.0/modules/moduleupdates/views/admin_moduleupdates.html.php b/3.0/modules/moduleupdates/views/admin_moduleupdates.html.php index 3d7d5453..d1e0aa3a 100644 --- a/3.0/modules/moduleupdates/views/admin_moduleupdates.html.php +++ b/3.0/modules/moduleupdates/views/admin_moduleupdates.html.php @@ -2,7 +2,7 @@
-

+

@@ -16,7 +16,6 @@
  • Green = Your version is newer than the GitHub
    ") ?>
  • Orange = Your file version is newer than the installed version
    ") ?>
  • Pink = Your installed version is newer than file version
    ") ?>
  • -
  • Blue = Does Not Exist/No information available
    ") ?>
  • ") ?>
  • " class="submit" />
  • @@ -25,24 +24,36 @@
      -
    • +
    - - - - + + + + + + "> - - - - + + + + + + + + + + + + + +
    [File/Installed]") ?> Installed") ?>
    "; ?> "; ?> "; ?> "; ?> "; ?> *"; } ?> "; } ?> "; ?> *"; } ?> $module_name['code_version']) { echo "".$module_name['core_version']."";} else { echo $module_name['core_version']; } ?> "; } ?> "; ?> *"; } ?> $module_name['version'] or $module_name['core_version'] > $module_name['code_version']) { echo "".$module_name['contrib_version']."";} else { echo $module_name['contrib_version']; } ?> "; } ?> "; ?> *"; } ?> $module_name['version'] or $module_name['core_version'] > $module_name['code_version']) { echo "".$module_name['gh_version']."";} else { echo $module_name['gh_version']; } ?> "; } ?>
    Installed") ?>
    -
    + \ No newline at end of file diff --git a/3.1/modules/moduleupdates/controllers/admin_moduleupdates.php b/3.1/modules/moduleupdates/controllers/admin_moduleupdates.php index ee74c90d..926d8196 100755 --- a/3.1/modules/moduleupdates/controllers/admin_moduleupdates.php +++ b/3.1/modules/moduleupdates/controllers/admin_moduleupdates.php @@ -16,7 +16,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ - class Admin_Moduleupdates_Controller extends Admin_Controller { /** @@ -44,15 +43,10 @@ class Admin_Moduleupdates_Controller extends Admin_Controller { $view->page_title = t("Gallery 3 :: Manage Module Updates"); $view->content = new View("admin_moduleupdates.html"); - $devDebug = false; - $refreshCache = false; + $refreshCache = false; $cache = unserialize(Cache::instance()->get("moduleupdates_cache")); - $cache_updates = unserialize(Cache::instance()->get("moduleupdates_cache_updates")); - - //--------------------------------------------------------------------------------------------- - //echo 'Message 01: ' .$cache_updates . '
    '; - //--------------------------------------------------------------------------------------------- + $cache_updates = unserialize(Cache::instance()->get("moduleupdates_cache_updates")); //if someone pressed the button to refresh now if (request::method() == "post") { @@ -78,7 +72,6 @@ class Admin_Moduleupdates_Controller extends Admin_Controller { } } catch (Exception $e) { - //echo 'Message: ' .$e->getMessage() . '
    '; } //Check the ability to access the Google $Google = null; @@ -91,71 +84,79 @@ class Admin_Moduleupdates_Controller extends Admin_Controller { } } catch (Exception $e) { - //echo 'Message: ' .$e->getMessage() . '
    '; } + $update_count = 0; + if($refreshCache == true){ foreach (module::available() as $this_module_name => $module_info) { + + $font_color_local = "black"; + $core_version = ''; + $core_server = ''; + $core_dlink = ''; + $font_color_core = "black"; + $contrib_version = ''; + $contrib_server = ''; + $contrib_dlink = ''; + $font_color_contrib = "black"; + $gh_version = ''; + $gh_server = ''; + $gh_dlink = ''; + $font_color_gh = "black"; - //example code for setting cache values - //Cache::instance()->set($key, "$log{$msg}", array("task", "log", "import"), 2592000); - //example delete cache - //Cache::instance()->delete("update_l10n_cache:{$task->id}"); - //example for reading cache - //$log = Cache::instance()->get($key); - $remote_version = ''; - $remote_server = ''; - $update_count = 0; - list ($remote_version, $remote_server) = $this->get_remote_module_version($this_module_name, $devDebug); + $font_color_local = $this->get_local_module_version_color ($module_info->version, $module_info->code_version); + list ($core_version, $core_server) = $this->get_remote_module_version($this_module_name, "CORE"); + $font_color_core = $this->get_module_version_color ($module_info->version, $module_info->code_version, $core_version); + list ($contrib_version, $contrib_server) = $this->get_remote_module_version($this_module_name, "CONTRIB"); + $font_color_contrib = $this->get_module_version_color ($module_info->version, $module_info->code_version, $contrib_version); + list ($gh_version, $gh_server) = $this->get_remote_module_version($this_module_name, "GH"); + $font_color_gh = $this->get_module_version_color ($module_info->version, $module_info->code_version, $gh_version); - $font_color = "black"; - //BLUE - DNE: Does Not Exist, this module was not found - if ($remote_version == "DNE") { - $font_color = "blue"; - //PINK - Your installed version is newer than file version - } else if ($module_info->version != '' and $module_info->code_version < $module_info->version) { - $font_color = "pink"; - //ORANGE - Your file version is newer than the installed version - } else if ($module_info->version != '' and $module_info->code_version > $module_info->version) { - $font_color = "orange"; - //GREEN - Your version is newer than the GitHub - } else if ($remote_version < $module_info->code_version or ($module_info->version != '' - and $remote_version < $module_info->version)) { - $font_color = "green"; - //RED - Your version is older than the GitHub - } else if ($remote_version > $module_info->code_version or ($module_info->version != '' - and $remote_version > $module_info->version)) { - $font_color = "red"; + if($font_color_core == "red" or $font_color_contrib == "red" or $font_color_gh == "red"){ $update_count++; - /* - if($remote_server == "(G3)"){ - $module_info->name = "".$module_info->name.""; - }else if($remote_server == "(G3CC)"){ - $module_info->name = "".$module_info->name.""; - }else if($remote_server == "(brentil)"){ - $module_info->name = "".$module_info->name.""; - } - */ } $module_info->name = "".$module_info->name.""; + if (is_numeric($core_version)) { + if($core_version > $module_info->version) { + //https://github.com/gallery/gallery3/tree/master/modules/recaptcha + //"http://github.com/gallery/gallery3/tree/master/modules/".$this_module_name + $core_dlink = "http://github.com/gallery/gallery3/tree/master/modules/".$this_module_name; + } + } + + if (is_numeric($contrib_version)) { + if($contrib_version > $module_info->version) { + //https://github.com/gallery/gallery3-contrib/tree/master/3.0/modules/moduleupdates + //"http://github.com/gallery/gallery3-contrib/tree/master/". substr_replace(gallery::VERSION,"",strpos(gallery::VERSION," ")) ."/modules/".$this_module_name + $contrib_dlink = "http://github.com/gallery/gallery3-contrib/tree/master/". substr_replace(gallery::VERSION,"",strpos(gallery::VERSION," ")) ."/modules/".$this_module_name; + } + } + + if (is_numeric($gh_version)) { + if($gh_version > $module_info->version) { + $gh_dlink = "http://www.gallerymodules.com/update/".$this_module_name; + } + } + //populate the list fo modules and their data $cache->$this_module_name = array ("name" => $module_info->name, "locked" => $module_info->locked, "code_version" => $module_info->code_version, "active" => $module_info->active, "version" => $module_info->version,"description" => $module_info->description, - "remote_version" => $remote_version, "remote_server" => $remote_server, "font_color" => $font_color); + "core_version" => $core_version, "core_server" => $core_server, "font_color_core" => $font_color_core, + "contrib_version" => $contrib_version, "contrib_server" => $contrib_server, "font_color_contrib" => $font_color_contrib, + "gh_version" => $gh_version, "gh_server" => $gh_server, "font_color_gh" => $font_color_gh, + "font_color_local" => $font_color_local, "core_dlink" => $core_dlink, "contrib_dlink" => $contrib_dlink, + "gh_dlink" => $gh_dlink); } //Define right now as YYYY.MM.DD HH:MM with the # of updates that are out of date $cache_updates = array("date" => date("Y.m.d - H:i"), "updates" => $update_count); - - //--------------------------------------------------------------------------------------------- - //echo 'Message 02: ' .$cache_updates . '
    '; - //--------------------------------------------------------------------------------------------- - + //Write out the new data to cache with a 30 day expiration & 0 for update data so it's always present Cache::instance()->set("moduleupdates_cache", serialize($cache), array("ModuleUpdates"), 30*86400); Cache::instance()->set("moduleupdates_cache_updates", serialize($cache_updates), array("ModuleUpdates"), null); @@ -167,12 +168,59 @@ class Admin_Moduleupdates_Controller extends Admin_Controller { $view->content->csrf = access::csrf_token(); $view->content->Google = $Google; $view->content->GitHub = $GitHub; + $view->content->Gallery_Version = substr_replace(gallery::VERSION,"",strpos(gallery::VERSION," ")); print $view; } + /** + * + **/ + private function get_module_version_color ($version, $code_version, $remote_version) { + + $font_color = "black"; + + //BLACK - no module version detected + if ($remote_version == "") { + $font_color = "black"; + //BLUE - DNE: Does Not Exist, this module was not found + } else if ($remote_version == "DNE") { + $font_color = "blue"; + //GREEN - Your version is newer than the GitHub + } else if ($remote_version < $code_version or ($version != '' + and $remote_version < $version)) { + $font_color = "green"; + //RED - Your version is older than the GitHub + } else if ($remote_version > $code_version or ($version != '' + and $remote_version > $version)) { + $font_color = "red"; + } + + return $font_color; + } + + + /** + * + **/ + private function get_local_module_version_color ($version, $code_version) { + + $font_color = "black"; + + //PINK - Your installed version is newer than file version + if ($version != '' and $code_version < $version) { + $font_color = "pink"; + //ORANGE - Your file version is newer than the installed version + } else if ($version != '' and $code_version > $version) { + $font_color = "orange"; + } + + return $font_color; + } + + /** * Parses the known GitHub repositories for new versions of modules. * @@ -182,71 +230,82 @@ class Admin_Moduleupdates_Controller extends Admin_Controller { * * http://github.com/gallery/gallery3 * http://github.com/gallery/gallery3-contrib + * http://www.gallerymodules.com * * @author brentil - * @param String The folder name of the module to search for on the remote GitHub server - * @return Array An array with the remote module version and the server it was found on. + * @param String - The folder name of the module to search for on the remote GitHub server + * @param String - The remote server to check against + * @return Array - An array with the remote module version and the server it was found on. */ - private function get_remote_module_version ($module_name, $devDebug) { + private function get_remote_module_version ($module_name, $server_location) { - $version = 'DNE'; + $version = ''; $server = ''; $file = null; - //For development debug only - if ($devDebug == true){ - if ($file == null) { - try { - $file = fopen ("http://github.com/brentil/gallery3-contrib/raw/master/3.1/modules/".$module_name."/module.info", "r"); - if ($file != null) { - $server = '(brentil)'; + switch ($server_location) { + case "CONTRIB": + //Check the Gallery3 Community Contributions GitHub + if ($file == null) { + try { + $file = fopen ("http://github.com/gallery/gallery3-contrib/raw/master/". substr_replace(gallery::VERSION,"",strpos(gallery::VERSION," ")) ."/modules/".$module_name."/module.info", "r"); + if ($file != null) { + $server = '(GCC)'; + } + } + catch (Exception $e) { + } } - } - catch (Exception $e) { - //echo 'Message: ' .$e->getMessage() . '
    '; - } - } - } - - //Check the main Gallery3 GitHub - if ($file == null) { - try { - $file = fopen ("http://github.com/gallery/gallery3/raw/master/modules/".$module_name."/module.info", "r"); - if ($file != null) { - $server = '(G3)'; - } - } - catch (Exception $e) { - //echo 'Message: ' .$e->getMessage() . '
    '; - } + break; + case "CORE": + //Check the main Gallery3 GitHub + if ($file == null) { + try { + $file = fopen ("http://github.com/gallery/gallery3/raw/master/modules/".$module_name."/module.info", "r"); + if ($file != null) { + $server = '(G)'; + } + } + catch (Exception $e) { + } + } + break; + case "GH": + //Check GalleryModules.com + if ($file == null) { + try { + $file = fopen ("http://www.gallerymodules.com/m/".$module_name, "r"); + if ($file != null) { + $server = '(GH)'; + } + } + catch (Exception $e) { + } + } + break; } - - //Check the Gallery3 Community Contributions GitHub - if ($file == null) { - try { - $file = fopen ("http://github.com/gallery/gallery3-contrib/raw/master/3.1/modules/".$module_name."/module.info", "r"); - if ($file != null) { - $server = '(G3CC)'; - } - } - catch (Exception $e) { - //echo 'Message: ' .$e->getMessage() . '
    '; - } - } - - if ($file != null) { + + if ($file != null) { while (!feof ($file)) { $line = fgets ($file, 1024); - - //Regular expression to find & gather the version number in the remote module.info file - if (preg_match ("@version = (.*)@i", $line, $out)) { - $version = $out[1]; - break; - } + if ($server_location == "GH"){ + //GH stores only the version info + if($line == "Not entered" or $line == "See git") { + $line = ""; + } + $version = $line; + break; + } else { + //Regular expression to find & gather the version number in the remote module.info file + if (preg_match ("@version = (.*)@i", $line, $out)) { + $version = $out[1]; + break; + } + } } fclose ($file); } - return array ($version, $server); - } -} + return array ($version, $server); + } +} \ No newline at end of file diff --git a/3.1/modules/moduleupdates/helpers/moduleupdates_installer.php b/3.1/modules/moduleupdates/helpers/moduleupdates_installer.php index dd0dddb8..911f6b81 100644 --- a/3.1/modules/moduleupdates/helpers/moduleupdates_installer.php +++ b/3.1/modules/moduleupdates/helpers/moduleupdates_installer.php @@ -23,8 +23,8 @@ class moduleupdates_installer { static function install() { $version = module::get_version("moduleupdates"); - if ($version == 0) { - module::set_version("moduleupdates", 2); + if ($version < 1) { + module::set_version("moduleupdates", 5); //Remove the ModuleUpdates cache entry 'JIC' Cache::instance()->delete("ModuleUpdates"); //create the blank ModuleUpdates cache entry with an expiration of 0 days @@ -34,7 +34,7 @@ class moduleupdates_installer { } static function upgrade($version) { - module::set_version("moduleupdates", 2); + module::set_version("moduleupdates", 5); //Remove the ModuleUpdates cache entry 'JIC' Cache::instance()->delete("ModuleUpdates"); //Empty the ModuleUpdates cache entry so our new version starts from scratch @@ -48,4 +48,4 @@ class moduleupdates_installer { Cache::instance()->delete("ModuleUpdates"); module::delete("moduleupdates"); } -} +} \ No newline at end of file diff --git a/3.1/modules/moduleupdates/module.info b/3.1/modules/moduleupdates/module.info index cf43770b..34868eaf 100755 --- a/3.1/modules/moduleupdates/module.info +++ b/3.1/modules/moduleupdates/module.info @@ -1,3 +1,3 @@ name = "Module Updates" description = "Compares your installed module version against the ones stored in the GitHub." -version = 3 +version = 5 \ No newline at end of file diff --git a/3.1/modules/moduleupdates/views/admin_moduleupdates.html.php b/3.1/modules/moduleupdates/views/admin_moduleupdates.html.php index 3fdc06a7..d1e0aa3a 100644 --- a/3.1/modules/moduleupdates/views/admin_moduleupdates.html.php +++ b/3.1/modules/moduleupdates/views/admin_moduleupdates.html.php @@ -2,7 +2,7 @@
    -

    +

    @@ -16,7 +16,6 @@
  • Green = Your version is newer than the GitHub
    ") ?>
  • Orange = Your file version is newer than the installed version
    ") ?>
  • Pink = Your installed version is newer than file version
    ") ?>
  • -
  • Blue = Does Not Exist/No information available
    ") ?>
  • ") ?>
  • " class="submit" />
  • @@ -25,24 +24,36 @@
      -
    • +
    - - - - + + + + + + "> - - - - + + + + + + + + + + + + + +
    [File/Installed]") ?> Installed") ?>
    "; ?> "; ?> "; ?> "; ?> "; ?> *"; } ?> "; } ?> "; ?> *"; } ?> $module_name['code_version']) { echo "".$module_name['core_version']."";} else { echo $module_name['core_version']; } ?> "; } ?> "; ?> *"; } ?> $module_name['version'] or $module_name['core_version'] > $module_name['code_version']) { echo "".$module_name['contrib_version']."";} else { echo $module_name['contrib_version']; } ?> "; } ?> "; ?> *"; } ?> $module_name['version'] or $module_name['core_version'] > $module_name['code_version']) { echo "".$module_name['gh_version']."";} else { echo $module_name['gh_version']; } ?> "; } ?>
    Installed") ?>
    \ No newline at end of file From 14cf53f70602146132a82ead0aa687b780717b0e Mon Sep 17 00:00:00 2001 From: brentil Date: Wed, 5 Jan 2011 20:54:37 -0500 Subject: [PATCH 2/2] Fix for GalleryModules 3.1 version paths and clarified verbiage. --- .../controllers/admin_moduleupdates.php | 25 ++++++++----- .../views/admin_moduleupdates.html.php | 36 +++++++++---------- .../controllers/admin_moduleupdates.php | 25 ++++++++----- .../views/admin_moduleupdates.html.php | 36 +++++++++---------- 4 files changed, 70 insertions(+), 52 deletions(-) diff --git a/3.0/modules/moduleupdates/controllers/admin_moduleupdates.php b/3.0/modules/moduleupdates/controllers/admin_moduleupdates.php index 926d8196..8c06c351 100755 --- a/3.0/modules/moduleupdates/controllers/admin_moduleupdates.php +++ b/3.0/modules/moduleupdates/controllers/admin_moduleupdates.php @@ -123,23 +123,26 @@ class Admin_Moduleupdates_Controller extends Admin_Controller { if (is_numeric($core_version)) { if($core_version > $module_info->version) { - //https://github.com/gallery/gallery3/tree/master/modules/recaptcha - //"http://github.com/gallery/gallery3/tree/master/modules/".$this_module_name $core_dlink = "http://github.com/gallery/gallery3/tree/master/modules/".$this_module_name; } } if (is_numeric($contrib_version)) { if($contrib_version > $module_info->version) { - //https://github.com/gallery/gallery3-contrib/tree/master/3.0/modules/moduleupdates - //"http://github.com/gallery/gallery3-contrib/tree/master/". substr_replace(gallery::VERSION,"",strpos(gallery::VERSION," ")) ."/modules/".$this_module_name - $contrib_dlink = "http://github.com/gallery/gallery3-contrib/tree/master/". substr_replace(gallery::VERSION,"",strpos(gallery::VERSION," ")) ."/modules/".$this_module_name; + $contrib_dlink = "http://github.com/gallery/gallery3-contrib/tree/master/". + substr_replace(gallery::VERSION,"",strpos(gallery::VERSION," ")) ."/modules/".$this_module_name; } } if (is_numeric($gh_version)) { if($gh_version > $module_info->version) { - $gh_dlink = "http://www.gallerymodules.com/update/".$this_module_name; + $this_gm_repo = str_replace(".","",substr_replace(gallery::VERSION,"",strpos(gallery::VERSION," "))); + if($this_gm_repo == "30"){ + $gh_dlink = "http://www.gallerymodules.com/update/".$this_module_name; + } else { + $gh_dlink = "http://www.gallerymodules.com/update".this_gm_repo."/".$this_module_name; + } + } } @@ -248,7 +251,8 @@ class Admin_Moduleupdates_Controller extends Admin_Controller { //Check the Gallery3 Community Contributions GitHub if ($file == null) { try { - $file = fopen ("http://github.com/gallery/gallery3-contrib/raw/master/". substr_replace(gallery::VERSION,"",strpos(gallery::VERSION," ")) ."/modules/".$module_name."/module.info", "r"); + $file = fopen ("http://github.com/gallery/gallery3-contrib/raw/master/". + substr_replace(gallery::VERSION,"",strpos(gallery::VERSION," "))."/modules/".$module_name."/module.info", "r"); if ($file != null) { $server = '(GCC)'; } @@ -274,7 +278,12 @@ class Admin_Moduleupdates_Controller extends Admin_Controller { //Check GalleryModules.com if ($file == null) { try { - $file = fopen ("http://www.gallerymodules.com/m/".$module_name, "r"); + $this_gm_repo = str_replace(".","",substr_replace(gallery::VERSION,"",strpos(gallery::VERSION," "))); + if($this_gm_repo == "30"){ + $file = fopen ("http://www.gallerymodules.com/m/".$module_name, "r"); + } else { + $file = fopen ("http://www.gallerymodules.com/".this_gm_repo."m/".$module_name, "r"); + } if ($file != null) { $server = '(GH)'; } diff --git a/3.0/modules/moduleupdates/views/admin_moduleupdates.html.php b/3.0/modules/moduleupdates/views/admin_moduleupdates.html.php index d1e0aa3a..a5dc4a0b 100644 --- a/3.0/modules/moduleupdates/views/admin_moduleupdates.html.php +++ b/3.0/modules/moduleupdates/views/admin_moduleupdates.html.php @@ -3,7 +3,7 @@

    - +
    @@ -24,35 +24,35 @@
      -
    • +
    - - - - - - + + + + + + "> - - - - + + + + - - - - - - + + + + + +
    Installed") ?>
    Installed") ?>
    "; ?> *"; } ?> "; } ?> "; ?> *"; } ?> $module_name['code_version']) { echo "".$module_name['core_version']."";} else { echo $module_name['core_version']; } ?> "; } ?> "; ?> *"; } ?> $module_name['version'] or $module_name['core_version'] > $module_name['code_version']) { echo "".$module_name['contrib_version']."";} else { echo $module_name['contrib_version']; } ?> "; } ?> "; ?> *"; } ?> $module_name['version'] or $module_name['core_version'] > $module_name['code_version']) { echo "".$module_name['gh_version']."";} else { echo $module_name['gh_version']; } ?> "; } ?> "; ?> *"; } ?> "; } ?> "; ?> *"; } ?> $module_name['code_version']) { echo "".$module_name['core_version']."";} else { echo $module_name['core_version']; } ?> "; } ?> "; ?> *"; } ?> $module_name['version'] or $module_name['core_version'] > $module_name['code_version']) { echo "".$module_name['contrib_version']."";} else { echo $module_name['contrib_version']; } ?> "; } ?> "; ?> *"; } ?> $module_name['version'] or $module_name['core_version'] > $module_name['code_version']) { echo "".$module_name['gh_version']."";} else { echo $module_name['gh_version']; } ?> "; } ?>
    Installed") ?>
    Installed") ?>
    diff --git a/3.1/modules/moduleupdates/controllers/admin_moduleupdates.php b/3.1/modules/moduleupdates/controllers/admin_moduleupdates.php index 926d8196..8c06c351 100755 --- a/3.1/modules/moduleupdates/controllers/admin_moduleupdates.php +++ b/3.1/modules/moduleupdates/controllers/admin_moduleupdates.php @@ -123,23 +123,26 @@ class Admin_Moduleupdates_Controller extends Admin_Controller { if (is_numeric($core_version)) { if($core_version > $module_info->version) { - //https://github.com/gallery/gallery3/tree/master/modules/recaptcha - //"http://github.com/gallery/gallery3/tree/master/modules/".$this_module_name $core_dlink = "http://github.com/gallery/gallery3/tree/master/modules/".$this_module_name; } } if (is_numeric($contrib_version)) { if($contrib_version > $module_info->version) { - //https://github.com/gallery/gallery3-contrib/tree/master/3.0/modules/moduleupdates - //"http://github.com/gallery/gallery3-contrib/tree/master/". substr_replace(gallery::VERSION,"",strpos(gallery::VERSION," ")) ."/modules/".$this_module_name - $contrib_dlink = "http://github.com/gallery/gallery3-contrib/tree/master/". substr_replace(gallery::VERSION,"",strpos(gallery::VERSION," ")) ."/modules/".$this_module_name; + $contrib_dlink = "http://github.com/gallery/gallery3-contrib/tree/master/". + substr_replace(gallery::VERSION,"",strpos(gallery::VERSION," ")) ."/modules/".$this_module_name; } } if (is_numeric($gh_version)) { if($gh_version > $module_info->version) { - $gh_dlink = "http://www.gallerymodules.com/update/".$this_module_name; + $this_gm_repo = str_replace(".","",substr_replace(gallery::VERSION,"",strpos(gallery::VERSION," "))); + if($this_gm_repo == "30"){ + $gh_dlink = "http://www.gallerymodules.com/update/".$this_module_name; + } else { + $gh_dlink = "http://www.gallerymodules.com/update".this_gm_repo."/".$this_module_name; + } + } } @@ -248,7 +251,8 @@ class Admin_Moduleupdates_Controller extends Admin_Controller { //Check the Gallery3 Community Contributions GitHub if ($file == null) { try { - $file = fopen ("http://github.com/gallery/gallery3-contrib/raw/master/". substr_replace(gallery::VERSION,"",strpos(gallery::VERSION," ")) ."/modules/".$module_name."/module.info", "r"); + $file = fopen ("http://github.com/gallery/gallery3-contrib/raw/master/". + substr_replace(gallery::VERSION,"",strpos(gallery::VERSION," "))."/modules/".$module_name."/module.info", "r"); if ($file != null) { $server = '(GCC)'; } @@ -274,7 +278,12 @@ class Admin_Moduleupdates_Controller extends Admin_Controller { //Check GalleryModules.com if ($file == null) { try { - $file = fopen ("http://www.gallerymodules.com/m/".$module_name, "r"); + $this_gm_repo = str_replace(".","",substr_replace(gallery::VERSION,"",strpos(gallery::VERSION," "))); + if($this_gm_repo == "30"){ + $file = fopen ("http://www.gallerymodules.com/m/".$module_name, "r"); + } else { + $file = fopen ("http://www.gallerymodules.com/".this_gm_repo."m/".$module_name, "r"); + } if ($file != null) { $server = '(GH)'; } diff --git a/3.1/modules/moduleupdates/views/admin_moduleupdates.html.php b/3.1/modules/moduleupdates/views/admin_moduleupdates.html.php index d1e0aa3a..a5dc4a0b 100644 --- a/3.1/modules/moduleupdates/views/admin_moduleupdates.html.php +++ b/3.1/modules/moduleupdates/views/admin_moduleupdates.html.php @@ -3,7 +3,7 @@

    - +
    @@ -24,35 +24,35 @@
      -
    • +
    - - - - - - + + + + + + "> - - - - + + + + - - - - - - + + + + + +
    Installed") ?>
    Installed") ?>
    "; ?> *"; } ?> "; } ?> "; ?> *"; } ?> $module_name['code_version']) { echo "".$module_name['core_version']."";} else { echo $module_name['core_version']; } ?> "; } ?> "; ?> *"; } ?> $module_name['version'] or $module_name['core_version'] > $module_name['code_version']) { echo "".$module_name['contrib_version']."";} else { echo $module_name['contrib_version']; } ?> "; } ?> "; ?> *"; } ?> $module_name['version'] or $module_name['core_version'] > $module_name['code_version']) { echo "".$module_name['gh_version']."";} else { echo $module_name['gh_version']; } ?> "; } ?> "; ?> *"; } ?> "; } ?> "; ?> *"; } ?> $module_name['code_version']) { echo "".$module_name['core_version']."";} else { echo $module_name['core_version']; } ?> "; } ?> "; ?> *"; } ?> $module_name['version'] or $module_name['core_version'] > $module_name['code_version']) { echo "".$module_name['contrib_version']."";} else { echo $module_name['contrib_version']; } ?> "; } ?> "; ?> *"; } ?> $module_name['version'] or $module_name['core_version'] > $module_name['code_version']) { echo "".$module_name['gh_version']."";} else { echo $module_name['gh_version']; } ?> "; } ?>
    Installed") ?>
    Installed") ?>