diff --git a/classes/event_handler.php b/classes/event_handler.php new file mode 100644 index 0000000..0943b8c --- /dev/null +++ b/classes/event_handler.php @@ -0,0 +1,81 @@ +bind(OW_EventManager::ON_PLUGINS_INIT, [$this, 'afterInit']); + } + + public function afterInit() + { + OW::getEventManager()->bind(OW_EventManager::ON_FINALIZE, [$this, 'googleAnalyticsAddCode']); + OW::getEventManager()->bind('admin.add_admin_notification', [$this, 'googleAnalyticsAdminNotification']); + } + + public function googleAnalyticsAddCode( OW_Event $event ) + { + $googleAnalyticsCode = stripslashes(html_entity_decode(OW::getConfig()->getValue('ganalytics', 'google_analytics_code'))); + + if ( $googleAnalyticsCode !== null ) + { + OW::getDocument()->appendBody($googleAnalyticsCode); + } + } + + public function googleAnalyticsAdminNotification( BASE_CLASS_EventCollector $event ) + { + $webPropertyId = OW::getConfig()->getValue('ganalytics', 'web_property_id'); + + if ( empty($webPropertyId) ) + { + $event->add(OW::getLanguage()->text('ganalytics', 'admin_notification_text', array('link' => OW::getRouter()->urlForRoute('ganalytics_admin')))); + } + } +} \ No newline at end of file diff --git a/controllers/admin.php b/controllers/admin.php index 03b9f33..33e94f4 100644 --- a/controllers/admin.php +++ b/controllers/admin.php @@ -47,9 +47,11 @@ public function index() $this->setPageHeading(OW::getLanguage()->text('ganalytics', 'admin_index_heading')); $this->setPageHeadingIconClass('ow_ic_gear_wheel'); - $form = new Form('ganalytics_web_id'); - $element = new TextField('web_property_id'); + $form = new Form('google_analytics_code'); + + $element = new Textarea('google_analytics_code'); $form->addElement($element); + $submit = new Submit('submit'); $submit->setValue(OW::getLanguage()->text('admin', 'save_btn_label')); $form->addElement($submit); @@ -57,20 +59,28 @@ public function index() if ( OW::getRequest()->isPost() && $form->isValid($_POST) ) { $data = $form->getValues(); - if ( !empty($data['web_property_id']) && strlen(trim($data['web_property_id'])) > 0 ) + if ( !empty($data['google_analytics_code']) && strlen(trim($data['google_analytics_code'])) > 0 ) { - OW::getConfig()->saveConfig('ganalytics', 'web_property_id', trim($data['web_property_id'])); - OW::getFeedback()->info(OW::getLanguage()->text('ganalytics', 'admin_index_property_id_save_success_message')); + $googleAnalyticsCode = htmlentities(trim($data['google_analytics_code'])); + + if( !get_magic_quotes_gpc() ) + { + $googleAnalyticsCode = addslashes($googleAnalyticsCode); + } + + OW::getConfig()->saveConfig('ganalytics', 'google_analytics_code', $googleAnalyticsCode); + OW::getFeedback()->info(OW::getLanguage()->text('ganalytics', 'admin_index_google_analytics_code_save_success_message')); } else { - OW::getFeedback()->error(OW::getLanguage()->text('ganalytics', 'admin_index_property_id_save_error_message')); + OW::getFeedback()->error(OW::getLanguage()->text('ganalytics', 'admin_index_google_analytics_code_save_error_message')); } $this->redirect(); } - $element->setValue(OW::getConfig()->getValue('ganalytics', 'web_property_id')); + $googleAnalyticsCode = stripslashes(html_entity_decode(OW::getConfig()->getValue('ganalytics', 'google_analytics_code'))); + $element->setValue($googleAnalyticsCode); $this->addForm($form); } } \ No newline at end of file diff --git a/init.php b/init.php index f302dbc..7831398 100644 --- a/init.php +++ b/init.php @@ -28,39 +28,7 @@ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -$webPropertyId = OW::getConfig()->getValue('ganalytics', 'web_property_id'); - -if ( $webPropertyId !== null ) -{ - - function ganalytics_add_code() - { - - $code = ' - '; - - OW::getDocument()->appendBody($code); - } - OW::getEventManager()->bind(OW_EventManager::ON_FINALIZE, 'ganalytics_add_code'); -} OW::getRouter()->addRoute(new OW_Route('ganalytics_admin', 'admin/plugins/ganalytics', 'GANALYTICS_CTRL_Admin', 'index')); -function ganalytics_admin_notification( BASE_CLASS_EventCollector $event ) -{ - $wpid = OW::getConfig()->getValue('ganalytics', 'web_property_id'); - - if ( empty($wpid) ) - { - $event->add(OW::getLanguage()->text('ganalytics', 'admin_notification_text', array('link' => OW::getRouter()->urlForRoute('ganalytics_admin')))); - } -} -OW::getEventManager()->bind('admin.add_admin_notification', 'ganalytics_admin_notification'); +GANALYTICS_CLASS_EventHandler::getInstance()->init(); diff --git a/install.php b/install.php index f9125bd..579b44d 100644 --- a/install.php +++ b/install.php @@ -29,9 +29,25 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -if ( !OW::getConfig()->configExists('ganalytics', 'web_property_id') ) +$googleAnalyticsCodeExample = htmlentities(" + + + + +"); + +if( !get_magic_quotes_gpc() ) +{ + $googleAnalyticsCodeExample = addslashes($googleAnalyticsCodeExample); +} + +if ( !OW::getConfig()->configExists('ganalytics', 'google_analytics_code') ) { - OW::getConfig()->addConfig('ganalytics', 'web_property_id', null); + OW::getConfig()->addConfig('ganalytics', 'google_analytics_code', $googleAnalyticsCodeExample); } OW::getPluginManager()->addPluginSettingsRouteName('ganalytics', 'ganalytics_admin'); diff --git a/langs.zip b/langs.zip index 1aa1e21..782e543 100644 Binary files a/langs.zip and b/langs.zip differ diff --git a/plugin.xml b/plugin.xml index e319331..48c160f 100644 --- a/plugin.xml +++ b/plugin.xml @@ -8,7 +8,7 @@ plugins@oxwall.org http://www.oxwall.org/foundation e547ebcf734341ec11911209d93a1054 - 8710 + 8718 (C) 2009 Oxwall Foundation. All rights reserved. The BSD License http://www.opensource.org/licenses/bsd-license.php diff --git a/update/8718/langs/language_en/ganalytics.xml b/update/8718/langs/language_en/ganalytics.xml new file mode 100644 index 0000000..8dc9b70 --- /dev/null +++ b/update/8718/langs/language_en/ganalytics.xml @@ -0,0 +1,7 @@ + + + Please submit valid value + Parameters updated + This is how Google Analytics identifies your site. <a href="http://www.google.com/analytics/learn/setupchecklist.html">Read more</a> + Js Code + diff --git a/update/8718/langs/language_en/language.xml b/update/8718/langs/language_en/language.xml new file mode 100644 index 0000000..c236899 --- /dev/null +++ b/update/8718/langs/language_en/language.xml @@ -0,0 +1,2 @@ + + diff --git a/update/8718/update.php b/update/8718/update.php new file mode 100644 index 0000000..a7a8181 --- /dev/null +++ b/update/8718/update.php @@ -0,0 +1,53 @@ + + + + +"); + +if( !get_magic_quotes_gpc() ) +{ + $googleAnalyticsCodeExample = addslashes($googleAnalyticsCodeExample); +} + +if ( !OW::getConfig()->configExists('ganalytics', 'google_analytics_code') ) +{ + OW::getConfig()->addConfig('ganalytics', 'google_analytics_code', $googleAnalyticsCodeExample); +} + +Updater::getLanguageService()->importPrefixFromDir(__DIR__ . DS . "langs"); \ No newline at end of file diff --git a/views/controllers/admin_index.html b/views/controllers/admin_index.html index 4d6fd7d..97c48dc 100644 --- a/views/controllers/admin_index.html +++ b/views/controllers/admin_index.html @@ -1,25 +1,25 @@ -{form name="ganalytics_web_id"} - - - - - - - - - -
- {text key="ganalytics+admin_settings_section_label"} -
- {text key="ganalytics+admin_settings_web_property_id_label"} - - {input name='web_property_id'}
- {error name='web_property_id'} -
{text key="ganalytics+admin_settings_web_property_id_desc"}
- -
-
- {submit name="submit" class="ow_ic_save"} -
-
+{form name="google_analytics_code"} + + + + + + + + + +
+ {text key="ganalytics+admin_settings_section_label"} +
+ {text key="ganalytics+admin_settings_google_analytics_code_label"} + + {input name='google_analytics_code'}
+ {error name='google_analytics_code'} +
{text key="ganalytics+admin_settings_google_analytics_code_desc"}
+ +
+
+ {submit name="submit" class="ow_ic_save"} +
+
{/form}