From b1529800536d55a74716647899495ac11f31ee77 Mon Sep 17 00:00:00 2001 From: Alex Kuretz Date: Thu, 17 May 2012 16:39:06 -0600 Subject: [PATCH 1/3] Update Google Analytics module to version 3 code created by undagiga in this forum topic: http://gallery.menalto.com/node/88884#comment-368272 --- .../controllers/admin_google_analytics.php | 113 ++++++++++-------- .../helpers/google_analytics_event.php | 56 ++++----- .../helpers/google_analytics_installer.php | 45 +++++++ .../helpers/google_analytics_theme.php | 99 ++++++++------- 3.0/modules/google_analytics/module.info | 10 +- .../views/admin_google_analytics.html.php | 12 +- 6 files changed, 196 insertions(+), 139 deletions(-) create mode 100644 3.0/modules/google_analytics/helpers/google_analytics_installer.php diff --git a/3.0/modules/google_analytics/controllers/admin_google_analytics.php b/3.0/modules/google_analytics/controllers/admin_google_analytics.php index 6cb7b5a9..328e294a 100644 --- a/3.0/modules/google_analytics/controllers/admin_google_analytics.php +++ b/3.0/modules/google_analytics/controllers/admin_google_analytics.php @@ -1,53 +1,62 @@ -_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->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" => "g-admin-form")); - $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; - } +_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); + module::set_var("google_analytics", "owneradmin_hidden", $form->google_analytics_code->inputs["analytics_owneradmin_hidden"]->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->checkbox("analytics_owneradmin_hidden")->label(t("Omit code for owner and admin")) + ->checked(module::get_var("google_analytics", "owneradmin_hidden", false) == 1); + $group->submit("submit")->value(t("Save")); + + return $form; + } } \ No newline at end of file diff --git a/3.0/modules/google_analytics/helpers/google_analytics_event.php b/3.0/modules/google_analytics/helpers/google_analytics_event.php index 0bab69ee..1cef1b08 100644 --- a/3.0/modules/google_analytics/helpers/google_analytics_event.php +++ b/3.0/modules/google_analytics/helpers/google_analytics_event.php @@ -1,28 +1,28 @@ -get("settings_menu") - ->append(Menu::factory("link") - ->id("google_analytics_menu") - ->label(t("Google Analytics")) - ->url(url::site("admin/google_analytics"))); - } -} +get("settings_menu") + ->append(Menu::factory("link") + ->id("google_analytics_menu") + ->label(t("Google Analytics")) + ->url(url::site("admin/google_analytics"))); + } +} diff --git a/3.0/modules/google_analytics/helpers/google_analytics_installer.php b/3.0/modules/google_analytics/helpers/google_analytics_installer.php new file mode 100644 index 00000000..9c61bfd5 --- /dev/null +++ b/3.0/modules/google_analytics/helpers/google_analytics_installer.php @@ -0,0 +1,45 @@ + - - - '; - - return $google_code; - } -} +item->owner_id != identity::active_user()->id) && (identity::active_user()->admin == 0) ) { + $u_o = 0; + } + + if ( $u_o == 0 || ( ($u_o == 1) && (module::get_var("google_analytics", "owneradmin_hidden") == 0) ) ) { + $google_code = ' + + + '; + + return $google_code; + } + + } + +} + + diff --git a/3.0/modules/google_analytics/module.info b/3.0/modules/google_analytics/module.info index ca5a51e3..0fc159bd 100644 --- a/3.0/modules/google_analytics/module.info +++ b/3.0/modules/google_analytics/module.info @@ -1,7 +1,3 @@ -name = "Google Analytics" -description = "Renders the Google Analytics Code at the end of the page. Written by 'mcp'." -version = 2 -author_name = "" -author_url = "" -info_url = "http://codex.gallery2.org/Gallery3:Modules:google_analytics" -discuss_url = "http://gallery.menalto.com/forum_module_google_analytics" +name = Google Analytics +description = Renders the Google Analytics Code at the end of the page. +version = 3 \ No newline at end of file diff --git a/3.0/modules/google_analytics/views/admin_google_analytics.html.php b/3.0/modules/google_analytics/views/admin_google_analytics.html.php index e516f35a..9abc3c39 100644 --- a/3.0/modules/google_analytics/views/admin_google_analytics.html.php +++ b/3.0/modules/google_analytics/views/admin_google_analytics.html.php @@ -1,6 +1,6 @@ - -
-

-

- -
+ +
+

+

+ +
From 6059dd02d39c5be1beacf5f50227763aef1fb4bf Mon Sep 17 00:00:00 2001 From: Alex Kuretz Date: Thu, 17 May 2012 16:41:07 -0600 Subject: [PATCH 2/3] Update Google Analytics module to insert tracking code in head of page. --- .../google_analytics/helpers/google_analytics_theme.php | 2 +- 3.0/modules/google_analytics/module.info | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/3.0/modules/google_analytics/helpers/google_analytics_theme.php b/3.0/modules/google_analytics/helpers/google_analytics_theme.php index 8f173c1b..d9b858d2 100644 --- a/3.0/modules/google_analytics/helpers/google_analytics_theme.php +++ b/3.0/modules/google_analytics/helpers/google_analytics_theme.php @@ -18,7 +18,7 @@ */ class google_analytics_theme { - static function page_bottom($theme) + static function head($theme) { $u_o = 1; if ( ($theme->item->owner_id != identity::active_user()->id) && (identity::active_user()->admin == 0) ) { diff --git a/3.0/modules/google_analytics/module.info b/3.0/modules/google_analytics/module.info index 0fc159bd..b49b147b 100644 --- a/3.0/modules/google_analytics/module.info +++ b/3.0/modules/google_analytics/module.info @@ -1,3 +1,7 @@ name = Google Analytics -description = Renders the Google Analytics Code at the end of the page. -version = 3 \ No newline at end of file +description = Renders the Google Analytics Code in the head of the page. +version = 4 +author_name = "" +author_url = "" +info_url = "http://codex.gallery2.org/Gallery3:Modules:google_analytics" +discuss_url = "http://gallery.menalto.com/node/88884" From 949ce2be1d8a95f4857c4120fc57f95fac53fec4 Mon Sep 17 00:00:00 2001 From: Alex Kuretz Date: Fri, 18 May 2012 09:39:07 -0600 Subject: [PATCH 3/3] Update Google Analytics module, fixing installer version issue --- .../google_analytics/helpers/google_analytics_installer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/3.0/modules/google_analytics/helpers/google_analytics_installer.php b/3.0/modules/google_analytics/helpers/google_analytics_installer.php index 9c61bfd5..0e52c059 100644 --- a/3.0/modules/google_analytics/helpers/google_analytics_installer.php +++ b/3.0/modules/google_analytics/helpers/google_analytics_installer.php @@ -22,12 +22,12 @@ class google_analytics_installer { module::set_var("google_analytics", "code", ""); module::set_var("google_analytics", "owneradmin_hidden", ""); - module::set_version("google_analytics", 3); + module::set_version("google_analytics", 4); } static function upgrade($version) { - module::set_version("google_analytics", 3); + module::set_version("google_analytics", 4); } static function deactivate()