Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions classes/event_handler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

/**
* This software is intended for use with Oxwall Free Community Software http://www.oxwall.org/ and is
* licensed under The BSD license.

* ---
* Copyright (c) 2011, Oxwall Foundation
* All rights reserved.

* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* - Neither the name of the Oxwall Foundation nor the names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.

* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* 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.
*/

class GANALYTICS_CLASS_EventHandler
{
private static $classInstance;

public static function getInstance()
{
if ( self::$classInstance === null )
{
self::$classInstance = new self();
}

return self::$classInstance;
}

private function __construct()
{

}

public function init()
{
OW::getEventManager()->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'))));
}
}
}
24 changes: 17 additions & 7 deletions controllers/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,40 @@ 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);

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);
}
}
34 changes: 1 addition & 33 deletions init.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("' . trim(OW::getConfig()->getValue('ganalytics', 'web_property_id')) . '");
pageTracker._trackPageview();
} catch(err) {}
</script>';

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();
20 changes: 18 additions & 2 deletions install.php
Original file line number Diff line number Diff line change
Expand Up @@ -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("
<!-- Google Analytics -->
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>
<!-- End Google Analytics -->
");

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');
Expand Down
Binary file modified langs.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<authorEmail>plugins@oxwall.org</authorEmail>
<authorUrl>http://www.oxwall.org/foundation</authorUrl>
<developerKey>e547ebcf734341ec11911209d93a1054</developerKey>
<build>8710</build>
<build>8718</build>
<copyright>(C) 2009 Oxwall Foundation. All rights reserved.</copyright>
<license>The BSD License</license>
<licenseUrl>http://www.opensource.org/licenses/bsd-license.php</licenseUrl>
Expand Down
7 changes: 7 additions & 0 deletions update/8718/langs/language_en/ganalytics.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<prefix name="ganalytics" label="Google Analytics" language_tag="en" language_label="English">
<key name="admin_index_google_analytics_code_save_error_message"><value>Please submit valid value</value></key>
<key name="admin_index_google_analytics_code_save_success_message"><value>Parameters updated</value></key>
<key name="admin_settings_google_analytics_code_desc"><value>This is how Google Analytics identifies your site. &lt;a href="http://www.google.com/analytics/learn/setupchecklist.html"&gt;Read more&lt;/a&gt;</value></key>
<key name="admin_settings_google_analytics_code_label"><value>Js Code</value></key>
</prefix>
2 changes: 2 additions & 0 deletions update/8718/langs/language_en/language.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<language tag="en" label="English" rtl="0"/>
53 changes: 53 additions & 0 deletions update/8718/update.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/**
* This software is intended for use with Oxwall Free Community Software http://www.oxwall.org/ and is
* licensed under The BSD license.

* ---
* Copyright (c) 2011, Oxwall Foundation
* All rights reserved.

* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* - Neither the name of the Oxwall Foundation nor the names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.

* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* 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.
*/

$googleAnalyticsCodeExample = htmlentities("
<!-- Google Analytics -->
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>
<!-- End Google Analytics -->
");

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");
48 changes: 24 additions & 24 deletions views/controllers/admin_index.html
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
{form name="ganalytics_web_id"}
<table class="ow_table_1 ow_form">
<tr class="ow_tr_first">
<th class="ow_name ow_txtleft" colspan="3">
<span class="ow_section_icon ow_ic_gear_wheel">{text key="ganalytics+admin_settings_section_label"}</span>
</th>
</tr>
<tr class="{cycle values='ow_alt1, ow_alt2'} ow_tr_last">
<td class="ow_label">
{text key="ganalytics+admin_settings_web_property_id_label"}
</td>
<td class="ow_value">
{input name='web_property_id'}<br />
{error name='web_property_id'}
</td>
<td class="ow_desc">{text key="ganalytics+admin_settings_web_property_id_desc"}</td>
</tr>
</table>
<div class="clearfix ow_stdmargin">
<div class="ow_right">
{submit name="submit" class="ow_ic_save"}
</div>
</div>
{form name="google_analytics_code"}
<table class="ow_table_1 ow_form">
<tr class="ow_tr_first">
<th class="ow_name ow_txtleft" colspan="3">
<span class="ow_section_icon ow_ic_gear_wheel">{text key="ganalytics+admin_settings_section_label"}</span>
</th>
</tr>
<tr class="{cycle values='ow_alt1, ow_alt2'} ow_tr_last">
<td class="ow_label">
{text key="ganalytics+admin_settings_google_analytics_code_label"}
</td>
<td class="ow_value">
{input name='google_analytics_code'}<br />
{error name='google_analytics_code'}
</td>
<td class="ow_desc">{text key="ganalytics+admin_settings_google_analytics_code_desc"}</td>
</tr>
</table>

<div class="clearfix ow_stdmargin">
<div class="ow_right">
{submit name="submit" class="ow_ic_save"}
</div>
</div>
{/form}