From 74bca55d52c815837bd7bde42dca85db5cf503f8 Mon Sep 17 00:00:00 2001 From: brentil Date: Sat, 19 Jun 2010 22:52:26 -0400 Subject: [PATCH] Cleaned up copy of v1 to conform to coding standards, file spacing, and added extra documentation. --- .../controllers/admin_moduleupdates.php | 107 ++++++++++++------ .../helpers/moduleupdates_event.php | 10 +- .../helpers/moduleupdates_installer.php | 6 +- modules/moduleupdates/module.info | 2 +- .../views/admin_moduleupdates.html.php | 13 ++- 5 files changed, 86 insertions(+), 52 deletions(-) diff --git a/modules/moduleupdates/controllers/admin_moduleupdates.php b/modules/moduleupdates/controllers/admin_moduleupdates.php index 0c381371..fc9d1905 100644 --- a/modules/moduleupdates/controllers/admin_moduleupdates.php +++ b/modules/moduleupdates/controllers/admin_moduleupdates.php @@ -1,9 +1,43 @@ - + */ public function index() { $view = new Admin_View("admin.html"); $view->page_title = t("Gallery 3 :: Manage Module Updates"); @@ -11,78 +45,81 @@ class Admin_Moduleupdates_Controller extends Admin_Controller { $all_modules = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS); - foreach (module::available() as $this_module_name => $module_info){ + foreach (module::available() as $this_module_name => $module_info) { - list($remote_version, $remote_server) = $this->get_remote_module_version($this_module_name); + list ($remote_version, $remote_server) = $this->get_remote_module_version($this_module_name); $font_color = "black"; - if($remote_version == "DNE"){ + if ($remote_version == "DNE") { $font_color = "blue"; - }else if($remote_version < $module_info->code_version){ + } else if ($remote_version < $module_info->code_version) { $font_color = "green"; - }else if($remote_version > $module_info->code_version){ + } else if ($remote_version > $module_info->code_version) { $font_color = "red"; } - $all_modules->$this_module_name = array("name" => $module_info->name, "locked" => $module_info->locked, "code_version" => $module_info->code_version, "locked" => $module_info->active, "version" => $module_info->version,"description" => $module_info->description, "remote_version" => $remote_version, "remote_server" => $remote_server, "font_color" => $font_color); - //echo $this_module_name."=".$this->get_remote_module_version($this_module_name)."
"; + $all_modules->$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); } - //$view->content->vars = module::available(); - $view->content->vars = $all_modules; print $view; } - private function get_remote_module_version($module_name){ + + /** + * Parses the known GitHub repositories for new versions of modules. + * + * Searches the remote GitHub repositories for a module with a like filename to that of the ones + * installed in the running Gallery isntall. Reads the remote modules module.info file to + * gather the version information. Uses the following locations; + * + * http://github.com/gallery/gallery3 + * http://github.com/gallery/gallery3-contrib + * + * @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. + */ + private function get_remote_module_version ($module_name) { - //http://github.com/gallery/gallery3-contrib/raw/master/modules/**MOD_NAME**/module.info $version = 'DNE'; $server = ''; $file = null; - try{ + try { $file = fopen ("http://github.com/gallery/gallery3/raw/master/modules/".$module_name."/module.info", "r"); - //$file = fopen ("http://github.com/gallery/gallery3-contrib/raw/master/modules/google_analytics/module.info", "r"); $server = '(G3)'; } - catch(Exception $e){ + catch (Exception $e) { //echo 'Message: ' .$e->getMessage() . '
'; } if ($file == null) { - try{ + try { $file = fopen ("http://github.com/gallery/gallery3-contrib/raw/master/modules/".$module_name."/module.info", "r"); $server = '(G3CC)'; } - catch(Exception $e){ + catch (Exception $e) { //echo 'Message: ' .$e->getMessage() . '
'; } } - - if ($file == null) { - try{ - $file = fopen ("http://github.com/rWatcher/gallery3-contrib/raw/master/modules/".$module_name."/module.info", "r"); - $server = '(rW)'; - } - catch(Exception $e){ - //echo 'Message: ' .$e->getMessage() . '
'; - } - } - - + if ($file != null) { while (!feof ($file)) { $line = fgets ($file, 1024); - /* This only works if the title and its tags are on one line */ + + //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); - } + fclose ($file); + } + return array ($version, $server); } - } diff --git a/modules/moduleupdates/helpers/moduleupdates_event.php b/modules/moduleupdates/helpers/moduleupdates_event.php index 132470d6..dd6efc9c 100644 --- a/modules/moduleupdates/helpers/moduleupdates_event.php +++ b/modules/moduleupdates/helpers/moduleupdates_event.php @@ -16,17 +16,11 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ - -/* -class moduleupdates_event { - static function module_change($changes) { - } - -} -*/ class moduleupdates_event_Core { + static function admin_menu($menu, $theme) { + $menu->get("settings_menu") ->append(Menu::factory("link") ->id("moduleupdates_menu") diff --git a/modules/moduleupdates/helpers/moduleupdates_installer.php b/modules/moduleupdates/helpers/moduleupdates_installer.php index da9d7e24..c15f4d82 100644 --- a/modules/moduleupdates/helpers/moduleupdates_installer.php +++ b/modules/moduleupdates/helpers/moduleupdates_installer.php @@ -16,11 +16,13 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ + class moduleupdates_installer { + static function install() { + $version = module::get_version("moduleupdates"); if ($version == 0) { - /* @todo Put database creation here */ module::set_version("moduleupdates", 1); } } @@ -29,7 +31,7 @@ class moduleupdates_installer { } static function uninstall() { - /* @todo Put database table drops here */ + module::delete("moduleupdates"); } } diff --git a/modules/moduleupdates/module.info b/modules/moduleupdates/module.info index 2da9d37b..446d30db 100644 --- a/modules/moduleupdates/module.info +++ b/modules/moduleupdates/module.info @@ -1,3 +1,3 @@ name = "Module Updates" -description = "Compares your installed module version against the ones stored in the GIT Hub." +description = "Compares your installed module version against the ones stored in the GitHub." version = 1 diff --git a/modules/moduleupdates/views/admin_moduleupdates.html.php b/modules/moduleupdates/views/admin_moduleupdates.html.php index 693b683a..e4e3f038 100644 --- a/modules/moduleupdates/views/admin_moduleupdates.html.php +++ b/modules/moduleupdates/views/admin_moduleupdates.html.php @@ -1,31 +1,32 @@ +

-
") ?> +
") ?> Red = Out of Date
") ?> Green = Your version is newer
") ?> Blue = Does Not Exist/No information available
") ?>

    -
  • +
- + - + "> - + - +
"; ?> "; ?> "; ?> "; ?> "; ?> "; ?>