*/ public function index() { $view = new Admin_View("admin.html"); $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") { access::verify_csrf(); $cache = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS); $cache_updates = array("date" => "", "updates" => 0); $refreshCache = true; }else if(count($cache) < 1 or $cache_updates['date'] == ""){ //if there are no items in the cache array or the update date is "" refresh the data $cache = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS); $cache_updates = array("date" => "", "updates" => 0); $refreshCache = true; } //Check the ability to access the Gallery3 GitHub $GitHub = null; try { $GitHub = fopen ("http://github.com", "r"); if ($GitHub != null) { $GitHub = 'Online'; }else{ $GitHub = 'Offline'; } } catch (Exception $e) { //echo 'Message: ' .$e->getMessage() . '
'; } //Check the ability to access the Google $Google = null; try { $Google = fopen ("http://google.com", "r"); if ($Google != null) { $Google = 'Online'; }else{ $Google = 'Offline'; } } catch (Exception $e) { //echo 'Message: ' .$e->getMessage() . '
'; } if($refreshCache == true){ foreach (module::available() as $this_module_name => $module_info) { //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 = "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"; $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.""; //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); } //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); log::success("moduleupdates", t("Completed checking remote GitHub for modules updates.")); } $view->content->vars = $cache; $view->content->update_time = $cache_updates['date']; $view->content->csrf = access::csrf_token(); $view->content->Google = $Google; $view->content->GitHub = $GitHub; print $view; } /** * 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, $devDebug) { $version = 'DNE'; $server = ''; $file = null; //For development debug only if ($devDebug == true){ if ($file == null) { try { $file = fopen ("http://github.com/brentil/gallery3-contrib/raw/master/modules/".$module_name."/module.info", "r"); if ($file != null) { $server = '(brentil)'; } } 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() . '
'; } } //Check the Gallery3 Community Contributions GitHub if ($file == null) { try { $file = fopen ("http://github.com/gallery/gallery3-contrib/raw/master/modules/".$module_name."/module.info", "r"); if ($file != null) { $server = '(G3CC)'; } } catch (Exception $e) { //echo 'Message: ' .$e->getMessage() . '
'; } } 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; } } fclose ($file); } return array ($version, $server); } }