From b2eafa02a20347ef90bceca9f6b2ed7c54a812df Mon Sep 17 00:00:00 2001 From: dmolavi Date: Fri, 3 Feb 2012 19:33:09 -0500 Subject: [PATCH] Updated ModuleUpdates to take advantage of new .ini file at GalleryModules.com. This results in lower server load on GalleryModules, and reduces the number of fopen() calls on the gallery server. --- .../controllers/admin_moduleupdates.php | 68 +++++++++++-------- 3.0/modules/moduleupdates/module.info | 2 +- .../controllers/admin_moduleupdates.php | 68 +++++++++++-------- 3.1/modules/moduleupdates/module.info | 2 +- 4 files changed, 80 insertions(+), 60 deletions(-) diff --git a/3.0/modules/moduleupdates/controllers/admin_moduleupdates.php b/3.0/modules/moduleupdates/controllers/admin_moduleupdates.php index 72ec5112..6ead769c 100755 --- a/3.0/modules/moduleupdates/controllers/admin_moduleupdates.php +++ b/3.0/modules/moduleupdates/controllers/admin_moduleupdates.php @@ -243,7 +243,6 @@ class Admin_Moduleupdates_Controller extends Admin_Controller { return $font_color; } - /** * Parses the known GitHub repositories for new versions of modules. * @@ -309,45 +308,56 @@ class Admin_Moduleupdates_Controller extends Admin_Controller { //Check GalleryModules.com if ($file == null) { try { - $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)'; - } + $fp = fopen('gm.ini', 'w'); + if(function_exists("curl_init")) { + $cp = curl_init("http://www.gallerymodules.com/gallerymodules.ini"); + curl_setopt($cp, CURLOPT_FILE, $fp); + + $buffer = curl_exec($cp); + + curl_close($cp); + $file = 1; + fclose($fp); + } else { + fwrite($fp,file_get_contents("http://www.gallerymodules.com/gallerymodules.ini")); + fclose($fp); + $file = 1; + } + + $this_gm_repo = str_replace(".","",substr_replace(gallery::VERSION,"",strpos(gallery::VERSION," "))); + + if ($file != null) { + $gm_array = parse_ini_file('gm.ini',true); + unlink('gm.ini'); + $server = '(GH)'; + } } catch (Exception $e) { + echo $e; } } break; - } + } - if ($file != null) { + if ($file != null) { + if ($server_location == "GH"){ + if($this_gm_repo == "30") { + $version = $gm_array[$module_name]['g3']; + } else { + $version = $gm_array[$module_name]['g31']; + } + } else { while (!feof ($file)) { $line = fgets ($file, 1024); - if ($server_location == "GH"){ - //GH stores only the version info - if($line == "Not entered" or $line == "See git") { - $line = ""; - } - if (substr_count($line, '.') > 0) { - $line = str_replace('.','',$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; - } - } + //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); } diff --git a/3.0/modules/moduleupdates/module.info b/3.0/modules/moduleupdates/module.info index 7c73c340..68ff7ca3 100755 --- a/3.0/modules/moduleupdates/module.info +++ b/3.0/modules/moduleupdates/module.info @@ -1,6 +1,6 @@ name = "ModuleUpdates" description = "Compares your installed module version against the ones stored in the GitHub." -version = 8 +version = 9 author_name = "brentil" author_url = "http://gallery.menalto.com/user/153736" info_url = "http://codex.gallery2.org/Gallery3:Modules:moduleupdates" diff --git a/3.1/modules/moduleupdates/controllers/admin_moduleupdates.php b/3.1/modules/moduleupdates/controllers/admin_moduleupdates.php index 72ec5112..6ead769c 100755 --- a/3.1/modules/moduleupdates/controllers/admin_moduleupdates.php +++ b/3.1/modules/moduleupdates/controllers/admin_moduleupdates.php @@ -243,7 +243,6 @@ class Admin_Moduleupdates_Controller extends Admin_Controller { return $font_color; } - /** * Parses the known GitHub repositories for new versions of modules. * @@ -309,45 +308,56 @@ class Admin_Moduleupdates_Controller extends Admin_Controller { //Check GalleryModules.com if ($file == null) { try { - $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)'; - } + $fp = fopen('gm.ini', 'w'); + if(function_exists("curl_init")) { + $cp = curl_init("http://www.gallerymodules.com/gallerymodules.ini"); + curl_setopt($cp, CURLOPT_FILE, $fp); + + $buffer = curl_exec($cp); + + curl_close($cp); + $file = 1; + fclose($fp); + } else { + fwrite($fp,file_get_contents("http://www.gallerymodules.com/gallerymodules.ini")); + fclose($fp); + $file = 1; + } + + $this_gm_repo = str_replace(".","",substr_replace(gallery::VERSION,"",strpos(gallery::VERSION," "))); + + if ($file != null) { + $gm_array = parse_ini_file('gm.ini',true); + unlink('gm.ini'); + $server = '(GH)'; + } } catch (Exception $e) { + echo $e; } } break; - } + } - if ($file != null) { + if ($file != null) { + if ($server_location == "GH"){ + if($this_gm_repo == "30") { + $version = $gm_array[$module_name]['g3']; + } else { + $version = $gm_array[$module_name]['g31']; + } + } else { while (!feof ($file)) { $line = fgets ($file, 1024); - if ($server_location == "GH"){ - //GH stores only the version info - if($line == "Not entered" or $line == "See git") { - $line = ""; - } - if (substr_count($line, '.') > 0) { - $line = str_replace('.','',$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; - } - } + //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); } diff --git a/3.1/modules/moduleupdates/module.info b/3.1/modules/moduleupdates/module.info index 7c73c340..68ff7ca3 100755 --- a/3.1/modules/moduleupdates/module.info +++ b/3.1/modules/moduleupdates/module.info @@ -1,6 +1,6 @@ name = "ModuleUpdates" description = "Compares your installed module version against the ones stored in the GitHub." -version = 8 +version = 9 author_name = "brentil" author_url = "http://gallery.menalto.com/user/153736" info_url = "http://codex.gallery2.org/Gallery3:Modules:moduleupdates"