diff --git a/modules/adsense/controllers/admin_adsense.php b/modules/adsense/controllers/admin_adsense.php new file mode 100644 index 00000000..13be83d8 --- /dev/null +++ b/modules/adsense/controllers/admin_adsense.php @@ -0,0 +1,57 @@ +page_title = t("Adsense settings"); + $view->content = new View("admin_adsense.html"); + $view->content->form = $this->_get_admin_form(); + print $view; + } + + public function save() { + access::verify_csrf(); + $form = $this->_get_admin_form(); + if ($form->validate()) { + module::set_var("adsense", "code", $form->adsense->code->value); + module::set_var("adsense", "location", $form->adsense->location->value); + message::success(t("Adsense settings updated")); + url::redirect("admin/adsense"); + } else { + print $form; + } + } + + private function _get_admin_form() { + $form = new Forge("admin/adsense/save", "", "post", array("id" => "g-adsense-admin-form")); + $adsense_settings = $form->group("adsense")->label(t("Adsense settings")); + $adsense_settings->textarea("code")->label(t("Adsense code")) + ->value(module::get_var("adsense", "code")); + $adsense_settings->dropdown("location") + ->label(t("Where should the ads be displayed?")) + ->options(array("header" => t("In the header"), + "sidebar" => t("In the sidebar"), + "footer" => t("In the footer"))) + ->selected(module::get_var("adsense", "location")); + $adsense_settings->submit("save")->value(t("Save")); + return $form; + } +} + diff --git a/modules/adsense/helpers/adsense_block.php b/modules/adsense/helpers/adsense_block.php new file mode 100644 index 00000000..7c00cb45 --- /dev/null +++ b/modules/adsense/helpers/adsense_block.php @@ -0,0 +1,39 @@ + t("Adsense")); + } + + static function get($block_id, $theme) { + $block = ""; + switch ($block_id) { + case "adsense": + if (module::get_var("adsense", "location") == "sidebar") { + $block = new Block(); + $block->css_id = "g-adsense"; + $block->title = t("Adsense"); + $block->content = new View("adsense_block.html"); + } + break; + } + return $block; + } +} \ No newline at end of file diff --git a/modules/adsense/helpers/adsense_event.php b/modules/adsense/helpers/adsense_event.php new file mode 100644 index 00000000..6611ebb1 --- /dev/null +++ b/modules/adsense/helpers/adsense_event.php @@ -0,0 +1,28 @@ +get("settings_menu") + ->append(Menu::factory("link") + ->id("adsense_menu") + ->label(t("Adsense")) + ->url(url::site("admin/adsense"))); + } +} diff --git a/modules/adsense/helpers/adsense_theme.php b/modules/adsense/helpers/adsense_theme.php new file mode 100644 index 00000000..97293992 --- /dev/null +++ b/modules/adsense/helpers/adsense_theme.php @@ -0,0 +1,54 @@ +' . $code . ' + '; + + return $google_code; + } + } + + static function footer($theme) { + if(module::get_var("adsense","location") == "footer") { + $code = module::get_var("adsense", "code"); + if (!$code) { + return; + } + $google_code = ' + + '; + + return $google_code; + } + } +} diff --git a/modules/adsense/module.info b/modules/adsense/module.info new file mode 100644 index 00000000..41cc63b2 --- /dev/null +++ b/modules/adsense/module.info @@ -0,0 +1,3 @@ +name = "Adsense" +description = "Display Google Adsense ads" +version = 1 diff --git a/modules/adsense/views/admin_adsense.html.php b/modules/adsense/views/admin_adsense.html.php new file mode 100644 index 00000000..f994fae5 --- /dev/null +++ b/modules/adsense/views/admin_adsense.html.php @@ -0,0 +1,7 @@ + +
+

+
+ +
+
diff --git a/modules/adsense/views/adsense_block.html.php b/modules/adsense/views/adsense_block.html.php new file mode 100644 index 00000000..53f8b20a --- /dev/null +++ b/modules/adsense/views/adsense_block.html.php @@ -0,0 +1,17 @@ +' . $code . ' + '; + + echo $google_code; +} +?> + diff --git a/modules/moduleupdates/controllers/admin_moduleupdates.php b/modules/moduleupdates/controllers/admin_moduleupdates.php index ba812515..1a7a2508 100644 --- a/modules/moduleupdates/controllers/admin_moduleupdates.php +++ b/modules/moduleupdates/controllers/admin_moduleupdates.php @@ -39,40 +39,136 @@ class Admin_Moduleupdates_Controller extends Admin_Controller { * @author brentil */ 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"); - $all_modules = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS); + $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() . '
'; + } - foreach (module::available() as $this_module_name => $module_info) { - - $remote_version = ''; - $remote_server = ''; - - list ($remote_version, $remote_server) = $this->get_remote_module_version($this_module_name); - - $font_color = "black"; - if ($remote_version == "DNE") { - $font_color = "blue"; - } else if ($module_info->version != '' and $module_info->code_version < $module_info->version) { - $font_color = "pink"; - } else if ($module_info->version != '' and $module_info->code_version > $module_info->version) { - $font_color = "orange"; - } else if ($remote_version < $module_info->code_version or ($module_info->version != '' and $remote_version < $module_info->version)) { - $font_color = "green"; - } else if ($remote_version > $module_info->code_version or ($module_info->version != '' and $remote_version > $module_info->version)) { - $font_color = "red"; - } + 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); + } - $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); + //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; - $view->content->vars = $all_modules; - + print $view; } @@ -91,22 +187,41 @@ class Admin_Moduleupdates_Controller extends Admin_Controller { * @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) { + private function get_remote_module_version ($module_name, $devDebug) { $version = 'DNE'; $server = ''; $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() . '
'; + //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"); @@ -118,7 +233,7 @@ class Admin_Moduleupdates_Controller extends Admin_Controller { //echo 'Message: ' .$e->getMessage() . '
'; } } - + if ($file != null) { while (!feof ($file)) { $line = fgets ($file, 1024); diff --git a/modules/moduleupdates/helpers/moduleupdates_installer.php b/modules/moduleupdates/helpers/moduleupdates_installer.php index c15f4d82..dd0dddb8 100644 --- a/modules/moduleupdates/helpers/moduleupdates_installer.php +++ b/modules/moduleupdates/helpers/moduleupdates_installer.php @@ -17,21 +17,35 @@ * 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) { - module::set_version("moduleupdates", 1); + module::set_version("moduleupdates", 2); + //Remove the ModuleUpdates cache entry 'JIC' + Cache::instance()->delete("ModuleUpdates"); + //create the blank ModuleUpdates cache entry with an expiration of 0 days + Cache::instance()->set("moduleupdates_cache", "", array("ModuleUpdates"), null); + Cache::instance()->set("moduleupdates_cache_updates", "", array("ModuleUpdates"), null); } } static function upgrade($version) { + module::set_version("moduleupdates", 2); + //Remove the ModuleUpdates cache entry 'JIC' + Cache::instance()->delete("ModuleUpdates"); + //Empty the ModuleUpdates cache entry so our new version starts from scratch + Cache::instance()->set("moduleupdates_cache", "", array("ModuleUpdates"), null); + Cache::instance()->set("moduleupdates_cache_updates", "", array("ModuleUpdates"), null); } static function uninstall() { - + + //Remove the ModuleUpdates cache entry as we remove the module + Cache::instance()->delete("ModuleUpdates"); module::delete("moduleupdates"); } } diff --git a/modules/moduleupdates/module.info b/modules/moduleupdates/module.info index 446d30db..8fad54ff 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 GitHub." -version = 1 +version = 2 diff --git a/modules/moduleupdates/views/admin_moduleupdates.html.php b/modules/moduleupdates/views/admin_moduleupdates.html.php index 8a7c6494..3fdc06a7 100644 --- a/modules/moduleupdates/views/admin_moduleupdates.html.php +++ b/modules/moduleupdates/views/admin_moduleupdates.html.php @@ -1,21 +1,33 @@ +
-

-

-
") ?> - Red = Your version is older than the GitHub
") ?> - 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
") ?> -

- - - +

+ +
+ +
" id="g-configure-moduleupdates-form"> + +
+ ModuleUpdates Information +
    +
  • Red = Your version is older than the GitHub
    ") ?>
  • +
  • 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,14 +37,12 @@ "> - + - +
"; ?> "; ?> "; ?> "; ?> "; ?> "; ?>
-
-
-
\ No newline at end of file + \ No newline at end of file diff --git a/themes/browny_wind/views/paginator.html.php b/themes/browny_wind/views/paginator.html.php index 5034c965..1f3017ad 100644 --- a/themes/browny_wind/views/paginator.html.php +++ b/themes/browny_wind/views/paginator.html.php @@ -26,11 +26,38 @@ // ?> +parent(); + endif; + $current_page = $position; + $total_pages = $total; + $siblings = $item->parent()->children(); + for ($i = 1; $i <= $total; $i++): + $_pagelist[$i] = $siblings[$i-1]->url(); + endfor; + } + endif; +?> +