From fc671304fe3fc3e9bdf56872a6cbf777f3b9af5a Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 10 Jul 2009 23:25:40 +0800 Subject: [PATCH 1/4] Add the dynamic module to contrib Signed-off-by: Tim Almdal --- modules/dynamic/controllers/admin_dynamic.php | 81 +++++++++++++++++++ modules/dynamic/controllers/dynamic.php | 64 +++++++++++++++ modules/dynamic/helpers/dynamic_installer.php | 46 +++++++++++ modules/dynamic/helpers/dynamic_menu.php | 27 +++++++ modules/dynamic/helpers/dynamic_theme.php | 39 +++++++++ modules/dynamic/module.info | 3 + modules/dynamic/views/admin_dynamic.html.php | 5 ++ modules/dynamic/views/dynamic_block.html.php | 10 +++ 8 files changed, 275 insertions(+) create mode 100644 modules/dynamic/controllers/admin_dynamic.php create mode 100644 modules/dynamic/controllers/dynamic.php create mode 100644 modules/dynamic/helpers/dynamic_installer.php create mode 100644 modules/dynamic/helpers/dynamic_menu.php create mode 100644 modules/dynamic/helpers/dynamic_theme.php create mode 100644 modules/dynamic/module.info create mode 100644 modules/dynamic/views/admin_dynamic.html.php create mode 100644 modules/dynamic/views/dynamic_block.html.php diff --git a/modules/dynamic/controllers/admin_dynamic.php b/modules/dynamic/controllers/admin_dynamic.php new file mode 100644 index 00000000..50dac459 --- /dev/null +++ b/modules/dynamic/controllers/admin_dynamic.php @@ -0,0 +1,81 @@ +_get_view(); + } + + public function handler() { + access::verify_csrf(); + + $form = $this->_get_form(); + if ($form->validate()) { + foreach (array("updates", "popular") as $album) { + $album_defn = unserialize(module::get_var("dynamic", $album)); + $group = $form->inputs[$album]; + $album_defn->enabled = $group->inputs["{$album}_enabled"]->value; + $album_defn->description = $group->inputs["{$album}_description"]->value; + $album_defn->limit = $group->inputs["{$album}_limit"] === "" ? null : + $group->inputs["{$album}_limit"]->value; + module::set_var("dynamic", $album, serialize($album_defn)); + } + + message::success(t("Dynamic Albums Configured")); + + url::redirect("admin/dynamic"); + } + + print $this->_get_view($form); + } + + private function _get_view($form=null) { + $v = new Admin_View("admin.html"); + $v->content = new View("admin_dynamic.html"); + $v->content->form = empty($form) ? $this->_get_form() : $form; + return $v; + } + + private function _get_form() { + + $form = new Forge("admin/dynamic/handler", "", "post", + array("id" => "gAdminForm")); + + foreach (array("updates", "popular") as $album) { + $album_defn = unserialize(module::get_var("dynamic", $album)); + + $group = $form->group($album)->label(t($album_defn->title)); + $group->checkbox("{$album}_enabled") + ->label(t("Enable")) + ->value(1) + ->checked($album_defn->enabled); + $group->input("{$album}_limit") + ->label(t("Limit (leave empty for unlimited)")) + ->value(empty($album_defn->limit) ? "" : $album_defn->limit) + ->rules("valid_numeric"); + $group->textarea("{$album}_description") + ->label(t("Description")) + ->rules("length[0,2048]") + ->value($album_defn->description); + } + + $form->submit("submit")->value(t("Submit")); + + return $form; + } +} \ No newline at end of file diff --git a/modules/dynamic/controllers/dynamic.php b/modules/dynamic/controllers/dynamic.php new file mode 100644 index 00000000..6b5f2915 --- /dev/null +++ b/modules/dynamic/controllers/dynamic.php @@ -0,0 +1,64 @@ +_show("updates"); + } + + public function popular() { + print $this->_show("popular"); + } + + private function _show($album) { + $page_size = module::get_var("gallery", "page_size", 9); + $page = $this->input->get("page", "1"); + + $album_defn = unserialize(module::get_var("dynamic", $album)); + $children_count = $album_defn->limit; + if (empty($children_count)) { + $children_count = ORM::factory("item") + ->viewable() + ->where("type !=", "album") + ->count_all(); + } + + $offset = ($page-1) * $page_size; + + $max_pages = ceil($children_count / $page_size); + + // Make sure that the page references a valid offset + if ($page < 1 || ($children_count && $page > ceil($children_count / $page_size))) { + Kohana::show_404(); + } + + $template = new Theme_View("page.html", "dynamic"); + $template->set_global("page_size", $page_size); + $template->set_global("children", ORM::factory("item") + ->viewable() + ->where("type !=", "album") + ->orderby($album_defn->key_field, "DESC") + ->find_all($page_size, $offset)); + $template->set_global("children_count", $children_count); + $template->content = new View("dynamic.html"); + $template->content->title = t($album_defn->title); + + print $template; + } + +} \ No newline at end of file diff --git a/modules/dynamic/helpers/dynamic_installer.php b/modules/dynamic/helpers/dynamic_installer.php new file mode 100644 index 00000000..66d6298d --- /dev/null +++ b/modules/dynamic/helpers/dynamic_installer.php @@ -0,0 +1,46 @@ + false, + "limit" => null, + "description" => "", + "key_field" => "view_count", + "title" => t("Most Viewed")))); + module::set_var("dynamic", "updates", + serialize((object)array("enabled" => false, + "limit" => null, + "description" => "", + "key_field" => "created", + "title" => t("Recent Changes")))); + module::set_version("dynamic", 1); + } + } + + static function upgrade($version) { + } + + static function uninstall() { + /* @todo Put database table drops here */ + module::delete("dynamic"); + } +} diff --git a/modules/dynamic/helpers/dynamic_menu.php b/modules/dynamic/helpers/dynamic_menu.php new file mode 100644 index 00000000..b2c73d6f --- /dev/null +++ b/modules/dynamic/helpers/dynamic_menu.php @@ -0,0 +1,27 @@ +get("content_menu") + ->append(Menu::factory("link") + ->id("dynamic_menu") + ->label(t("Dynamic Albums")) + ->url(url::site("admin/dynamic"))); + } +} diff --git a/modules/dynamic/helpers/dynamic_theme.php b/modules/dynamic/helpers/dynamic_theme.php new file mode 100644 index 00000000..ba355098 --- /dev/null +++ b/modules/dynamic/helpers/dynamic_theme.php @@ -0,0 +1,39 @@ +enabled) { + $albums[$album] = $album_defn->title; + } + } + if (!empty($albums)) { + $block = new Block(); + $block->css_id = "gDynamic"; + $block->title = t("Dynamic Albums"); + $block->content = new View("dynamic_block.html"); + $block->content->albums = $albums; + return $block; + } + return ""; + } + +} diff --git a/modules/dynamic/module.info b/modules/dynamic/module.info new file mode 100644 index 00000000..aa5e0432 --- /dev/null +++ b/modules/dynamic/module.info @@ -0,0 +1,3 @@ +name = Dynamic +description = Adds the Recent Changes and Most Viewed dynamic albums +version = 1 diff --git a/modules/dynamic/views/admin_dynamic.html.php b/modules/dynamic/views/admin_dynamic.html.php new file mode 100644 index 00000000..cd7ccfea --- /dev/null +++ b/modules/dynamic/views/admin_dynamic.html.php @@ -0,0 +1,5 @@ + +
+

+ +
diff --git a/modules/dynamic/views/dynamic_block.html.php b/modules/dynamic/views/dynamic_block.html.php new file mode 100644 index 00000000..d14c2900 --- /dev/null +++ b/modules/dynamic/views/dynamic_block.html.php @@ -0,0 +1,10 @@ + +
+
    + $text): ?> +
  • + "> +
  • + +
+
From 5153654060fe3b5396907ff7c8cc07df4530a108 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 11 Jul 2009 08:23:57 -0700 Subject: [PATCH 2/4] Original version of Google Analytics module, by mcp (http://gallery.menalto.com/node/88884) --- .../controllers/admin_google_analytics.php | 59 +++++++++++++++++++ .../helpers/google_analytics_installer.php | 38 ++++++++++++ .../helpers/google_analytics_menu.php | 27 +++++++++ .../helpers/google_analytics_theme.php | 43 ++++++++++++++ modules/google_analytics/module.info | 3 + .../views/admin_google_analytics.html.php | 6 ++ 6 files changed, 176 insertions(+) create mode 100644 modules/google_analytics/controllers/admin_google_analytics.php create mode 100644 modules/google_analytics/helpers/google_analytics_installer.php create mode 100644 modules/google_analytics/helpers/google_analytics_menu.php create mode 100644 modules/google_analytics/helpers/google_analytics_theme.php create mode 100644 modules/google_analytics/module.info create mode 100644 modules/google_analytics/views/admin_google_analytics.html.php diff --git a/modules/google_analytics/controllers/admin_google_analytics.php b/modules/google_analytics/controllers/admin_google_analytics.php new file mode 100644 index 00000000..84489520 --- /dev/null +++ b/modules/google_analytics/controllers/admin_google_analytics.php @@ -0,0 +1,59 @@ +_get_view(); + } + + public function handler() + { + access::verify_csrf(); + + $form = $this->_get_form(); + + if ($form->validate()) + { + module::set_var("google_analytics", "code", $form->google_analytics_code->inputs["analytics_code"]->value); + url::redirect("admin/google_analytics"); + } + + print $this->_get_view($form); + } + + private function _get_view($form=null) + { + $v = new Admin_View("admin.html"); + $v->content = new View("admin_google_analytics.html"); + $v->content->form = empty($form) ? $this->_get_form() : $form; + return $v; + } + + private function _get_form() + { + $form = new Forge("admin/google_analytics/handler", "", "post", + array("id" => "gAdminForm")); + $group = $form->group("google_analytics_code"); + $group->input("analytics_code")->label(t('Enter the Web-Property-ID given by Google.'))->rules("required")->value(module::get_var("google_analytics", "code")); + $group->submit("submit")->value(t("Save")); + + return $form; + } +} \ No newline at end of file diff --git a/modules/google_analytics/helpers/google_analytics_installer.php b/modules/google_analytics/helpers/google_analytics_installer.php new file mode 100644 index 00000000..a0395899 --- /dev/null +++ b/modules/google_analytics/helpers/google_analytics_installer.php @@ -0,0 +1,38 @@ +get("settings_menu") + ->append(Menu::factory("link") + ->id("google_analytics_menu") + ->label(t("Google Analytics")) + ->url(url::site("admin/google_analytics"))); + } +} diff --git a/modules/google_analytics/helpers/google_analytics_theme.php b/modules/google_analytics/helpers/google_analytics_theme.php new file mode 100644 index 00000000..0a512389 --- /dev/null +++ b/modules/google_analytics/helpers/google_analytics_theme.php @@ -0,0 +1,43 @@ + + + + '; + + return $google_code; + } + +} diff --git a/modules/google_analytics/module.info b/modules/google_analytics/module.info new file mode 100644 index 00000000..3d4af688 --- /dev/null +++ b/modules/google_analytics/module.info @@ -0,0 +1,3 @@ +name = Google Analytics +description = Renders the Google Analytics Code at the end of the page. +version = 1.2 \ No newline at end of file diff --git a/modules/google_analytics/views/admin_google_analytics.html.php b/modules/google_analytics/views/admin_google_analytics.html.php new file mode 100644 index 00000000..328fcb73 --- /dev/null +++ b/modules/google_analytics/views/admin_google_analytics.html.php @@ -0,0 +1,6 @@ + +
+

+

+ +
From 766554602262fb586a3d907c35e9b3e1612a5443 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 11 Jul 2009 08:24:22 -0700 Subject: [PATCH 3/4] Clean up style --- .../controllers/admin_google_analytics.php | 30 ++++++++----------- .../helpers/google_analytics_installer.php | 25 +++++----------- .../helpers/google_analytics_menu.php | 9 +++--- .../helpers/google_analytics_theme.php | 18 +++++------ modules/google_analytics/module.info | 4 +-- 5 files changed, 35 insertions(+), 51 deletions(-) diff --git a/modules/google_analytics/controllers/admin_google_analytics.php b/modules/google_analytics/controllers/admin_google_analytics.php index 84489520..cf3eef5a 100644 --- a/modules/google_analytics/controllers/admin_google_analytics.php +++ b/modules/google_analytics/controllers/admin_google_analytics.php @@ -1,4 +1,5 @@ -_get_view(); } - public function handler() - { + public function handler() { access::verify_csrf(); $form = $this->_get_form(); - - if ($form->validate()) - { - module::set_var("google_analytics", "code", $form->google_analytics_code->inputs["analytics_code"]->value); + if ($form->validate()) { + module::set_var( + "google_analytics", "code", $form->google_analytics_code->analytics_code->value); url::redirect("admin/google_analytics"); } print $this->_get_view($form); } - private function _get_view($form=null) - { + private function _get_view($form=null) { $v = new Admin_View("admin.html"); $v->content = new View("admin_google_analytics.html"); $v->content->form = empty($form) ? $this->_get_form() : $form; return $v; } - - private function _get_form() - { - $form = new Forge("admin/google_analytics/handler", "", "post", - array("id" => "gAdminForm")); + + private function _get_form() { + $form = new Forge("admin/google_analytics/handler", "", "post", array("id" => "gAdminForm")); $group = $form->group("google_analytics_code"); $group->input("analytics_code")->label(t('Enter the Web-Property-ID given by Google.'))->rules("required")->value(module::get_var("google_analytics", "code")); $group->submit("submit")->value(t("Save")); diff --git a/modules/google_analytics/helpers/google_analytics_installer.php b/modules/google_analytics/helpers/google_analytics_installer.php index a0395899..54d5b8e2 100644 --- a/modules/google_analytics/helpers/google_analytics_installer.php +++ b/modules/google_analytics/helpers/google_analytics_installer.php @@ -1,4 +1,5 @@ -get("settings_menu") ->append(Menu::factory("link") - ->id("google_analytics_menu") - ->label(t("Google Analytics")) - ->url(url::site("admin/google_analytics"))); + ->id("google_analytics_menu") + ->label(t("Google Analytics")) + ->url(url::site("admin/google_analytics"))); } } diff --git a/modules/google_analytics/helpers/google_analytics_theme.php b/modules/google_analytics/helpers/google_analytics_theme.php index 0a512389..b8933ba6 100644 --- a/modules/google_analytics/helpers/google_analytics_theme.php +++ b/modules/google_analytics/helpers/google_analytics_theme.php @@ -1,4 +1,5 @@ - - '; - - return $google_code; + + return $google_code; } - } diff --git a/modules/google_analytics/module.info b/modules/google_analytics/module.info index 3d4af688..dade4fd6 100644 --- a/modules/google_analytics/module.info +++ b/modules/google_analytics/module.info @@ -1,3 +1,3 @@ name = Google Analytics -description = Renders the Google Analytics Code at the end of the page. -version = 1.2 \ No newline at end of file +description = Renders the Google Analytics Code at the end of the page. (by mcp) +version = 1.2 From 3ec8ccfff8e1dbffc5d24d22976579b79aee6ade Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 11 Jul 2009 08:26:25 -0700 Subject: [PATCH 4/4] Fix issues w/ module.info -- can't use parens in the description --- modules/google_analytics/module.info | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/google_analytics/module.info b/modules/google_analytics/module.info index dade4fd6..4743a47a 100644 --- a/modules/google_analytics/module.info +++ b/modules/google_analytics/module.info @@ -1,3 +1,3 @@ name = Google Analytics -description = Renders the Google Analytics Code at the end of the page. (by mcp) +description = Renders the Google Analytics Code at the end of the page. Written by 'mcp'. version = 1.2