Skip to content

Commit

Permalink
build v0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sualko committed Oct 29, 2018
1 parent f971a91 commit 69ad1c5
Show file tree
Hide file tree
Showing 16 changed files with 211 additions and 146 deletions.
1 change: 0 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ module.exports = function(grunt) {
},
files: {
'build/js/settings/admin.min.js': ['js/settings/admin.js'],
'build/js/track.min.js': ['js/track.js']
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<name>Piwik/Matomo Tracking</name>
<summary>Track users with Piwik/Matomo</summary>
<description>Track users with Piwik/Matomo</description>
<version>0.4.1</version>
<version>0.5.0</version>
<licence>agpl</licence>
<author>Klaus Herberth</author>
<category>tools</category>
Expand Down
19 changes: 18 additions & 1 deletion build/appinfo/Application.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php
namespace OCA\Piwik\AppInfo;

use OCA\Piwik\Config;
use OCA\Piwik\Controller\SettingsController;
use OCA\Piwik\Controller\JavaScriptController;
use OCA\Piwik\Migration\Settings as SettingsMigration;
use OCP\AppFramework\App;
use OCP\IContainer;
Expand All @@ -15,14 +17,29 @@ public function __construct(array $urlParams = array())

$container = $this->getContainer();

$container->registerService('OCA\Piwik\Config', function (IContainer $c) {
return new Config(
$c->query('AppName'),
$c->query('OCP\IConfig')
);
});

/**
* Controllers
*/
$container->registerService('SettingsController', function (IContainer $c) {
return new SettingsController(
$c->query('AppName'),
$c->query('Request'),
$c->query('OCP\IConfig')
$c->query('OCA\Piwik\Config')
);
});

$container->registerService('JavaScriptController', function (IContainer $c) {
return new JavaScriptController(
$c->query('AppName'),
$c->query('Request'),
$c->query('OCA\Piwik\Config')
);
});

Expand Down
25 changes: 13 additions & 12 deletions build/appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@
$url = \OC::$server->getConfig()->getAppValue('piwik', 'url');

if (!empty($url)) {
OCP\Util::addScript('piwik', 'track');
\OCP\Util::addHeader(
'script',
[
'src' => \OC::$server->getURLGenerator()->linkToRoute('piwik.JavaScript.tracking'),
'nonce' => \OC::$server->getContentSecurityPolicyNonceManager()->getNonce(),
], ''
);

if (class_exists('\\OCP\\AppFramework\\Http\\ContentSecurityPolicy')) {
$url = parse_url($url, PHP_URL_HOST);
$url = parse_url($url, PHP_URL_HOST);
$policy = new OCP\AppFramework\Http\ContentSecurityPolicy();

$policy = new OCP\AppFramework\Http\ContentSecurityPolicy();
$policy->addAllowedScriptDomain('\'self\' ');
$policy->addAllowedImageDomain('\'self\' ');

if ($url !== false && array_key_exists('HTTP_HOST', $_SERVER)
&& $_SERVER['HTTP_HOST'] !== $url && !empty($url)) {
$policy->addAllowedScriptDomain($url);
$policy->addAllowedImageDomain($url);
}
if ($url !== false && array_key_exists('HTTP_HOST', $_SERVER)
&& $_SERVER['HTTP_HOST'] !== $url && !empty($url)) {
$policy->addAllowedScriptDomain($url);
$policy->addAllowedImageDomain($url);

\OC::$server->getContentSecurityPolicyManager()->addDefaultPolicy($policy);
}
Expand Down
12 changes: 6 additions & 6 deletions build/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<name>Piwik/Matomo Tracking</name>
<summary>Track users with Piwik/Matomo</summary>
<description>Track users with Piwik/Matomo</description>
<version>0.4.1</version>
<version>0.5.0</version>
<licence>agpl</licence>
<author>Klaus Herberth</author>
<category>tools</category>
Expand All @@ -14,16 +14,16 @@
<repository type="git">https://github.com/sualko/cloud_piwik.git</repository>

<dependencies>
<nextcloud min-version="11.0" max-version="14"/>
<nextcloud min-version="13.0" max-version="15"/>
</dependencies>

<settings>
<admin>OCA\Piwik\Settings\Admin</admin>
</settings>

<repair-steps>
<post-migration>
<step>OCA\Piwik\Migration\Settings</step>
</post-migration>
</repair-steps>

<settings>
<admin>OCA\Piwik\Settings\Admin</admin>
</settings>
</info>
5 changes: 3 additions & 2 deletions build/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
return [
'routes' => [
['name' => 'settings#index', 'url' => '/settings', 'verb' => 'GET'],
['name' => 'settings#update', 'url' => '/settings/{key}', 'verb' => 'PUT']
['name' => 'settings#update', 'url' => '/settings/{key}', 'verb' => 'PUT'],
['name' => 'JavaScript#tracking', 'url' => '/js/tracking.js', 'verb' => 'GET']
],
];
?>
?>
146 changes: 63 additions & 83 deletions build/js/track.js
Original file line number Diff line number Diff line change
@@ -1,121 +1,101 @@
/*!
* owncloud_piwik v0.4.1 - 2018-05-11
* cloud_piwik v0.5.0 - 2018-10-29
*
* Copyright (c) 2018 Klaus Herberth <[email protected]> <br>
* Released under the MIT license
*
* Please see https://github.com/sualko/owncloud_piwik
* Please see https://github.com/sualko/cloud_piwik
*
* @author Klaus Herberth <[email protected]>
* @version 0.4.1
* @version 0.5.0
* @license MIT
*/

/* global OC, oc_debug */
/* global OC */

var _paq = _paq || [];

(function() {
"use strict";

var piwik;
var options;

if (typeof localStorage !== 'undefined') {
var piwikString = localStorage.getItem('piwik');
try {
options = JSON.parse('%OPTIONS%');
} catch (err) {}

try {
piwik = JSON.parse(piwikString);
} catch (err) {}
if (!options || !options.url || !options.siteId) {
return;
}

if (piwik && (piwik.validUntil || 0) > (new Date()).getTime() && !oc_debug) {
// use cached options
track(piwik);
} else {
// load options
$.ajax({
method: 'GET',
url: OC.generateUrl('apps/piwik/settings'),
})
.done(function(response) {
var data = response ? response.data : {};

if (data.siteId && data.url) {
data.validUntil = (new Date()).getTime() + (data.validity * 1000);

localStorage.setItem('piwik', JSON.stringify(data));

track(data);
}
});
if (options.url[options.url.length - 1] !== '/') {
options.url += '/';
}

function track(options) {
var app = null;
var path = window.location.pathname;
var pathparts = path.match(/(?:index\.php\/)?apps\/([a-z0-9]+)\/?/i) || path.match(/(?:index\.php\/)?([a-z0-9]+)(\/([a-z0-9]+))?/i) || [];
var app = null;
var path = window.location.pathname;
var pathParts = path.match(/(?:index\.php\/)?apps\/([a-z0-9]+)\/?/i) || path.match(/(?:index\.php\/)?([a-z0-9]+)(\/([a-z0-9]+))?/i) || [];

if (pathparts.length >= 2) {
app = pathparts[1];
if (pathParts.length >= 2) {
app = pathParts[1];

if (app === 's') {
// rewrite app name
app = 'share';
if (app === 's') {
// rewrite app name
app = 'share';

var sharevalue = $('input[name="filename"]').val();
var shareValue = $('input[name="filename"]').val();

if (sharevalue) {
sharevalue = pathparts[3] + ' (' + sharevalue + ')';
if (shareValue) {
shareValue = pathParts[3] + ' (' + shareValue + ')';

// save share id + share name in slot 3
_paq.push(['setCustomVariable', '3', 'ShareNodes', sharevalue, 'page']);
} else {
sharevalue = pathparts[3];
}

// save share id in slot 2
_paq.push(['setCustomVariable', '2', 'Shares', pathparts[3], 'page']);
// save share id + share name in slot 3
_paq.push(['setCustomVariable', '3', 'ShareNodes', shareValue, 'page']);
} else {
shareValue = pathParts[3];
}

// save app name in slot 1
_paq.push(['setCustomVariable', '1', 'App', app, 'page']);
}

if (OC && OC.currentUser) {
// set user id
_paq.push(['setUserId', OC.currentUser]);
// save share id in slot 2
_paq.push(['setCustomVariable', '2', 'Shares', pathParts[3], 'page']);
}

if (options.trackDir === 'on' || options.trackDir === true) {
// track file browsing
// save app name in slot 1
_paq.push(['setCustomVariable', '1', 'App', app, 'page']);
}

$('#app-content').delegate('>div', 'afterChangeDirectory', function() {
// update title and url for next page view
_paq.push(['setDocumentTitle', document.title]);
_paq.push(['setCustomUrl', window.location.href]);
_paq.push(['trackPageView']);
});
}
if (OC && OC.currentUser && options.trackUser) {
// set user id
_paq.push(['setUserId', OC.currentUser]);
}

// set piwik options
_paq.push(['setTrackerUrl', options.url + 'piwik.php']);
_paq.push(['setSiteId', options.siteId]);
if (options.trackDir === 'on' || options.trackDir === true) {
// track file browsing

if (app !== 'files' || options.trackDir !== 'on') {
// track page view
$('#app-content').delegate('>div', 'afterChangeDirectory', function() {
// update title and url for next page view
_paq.push(['setDocumentTitle', document.title]);
_paq.push(['setCustomUrl', window.location.href]);
_paq.push(['trackPageView']);
}
});
}

if (typeof Piwik === 'undefined') {
// load piwik library
var d = document,
g = d.createElement('script'),
s = d.getElementsByTagName('script')[0];
g.type = 'text/javascript';
g.async = true;
g.defer = true;
g.src = options.url + 'piwik.js';
s.parentNode.insertBefore(g, s);
}
// set piwik options
_paq.push(['setTrackerUrl', options.url + 'piwik.php']);
_paq.push(['setSiteId', options.siteId]);

if (app !== 'files' || options.trackDir !== 'on') {
// track page view
_paq.push(['trackPageView']);
}

if (typeof Piwik === 'undefined') {
// load piwik library
var d = document,
g = d.createElement('script'),
s = d.getElementsByTagName('script')[0];
g.type = 'text/javascript';
g.async = true;
g.defer = true;
g.src = options.url + 'piwik.js';
s.parentNode.insertBefore(g, s);
}
}());
2 changes: 0 additions & 2 deletions build/js/track.min.js

This file was deleted.

1 change: 0 additions & 1 deletion build/js/track.min.js.map

This file was deleted.

34 changes: 34 additions & 0 deletions build/lib/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
namespace OCA\Piwik;

use OCP\IConfig;

class Config
{
public function __construct($appName, IConfig $config)
{
$this->appName = $appName;
$this->config = $config;
}

public function getAppValue($key, $default = null)
{
$value = $this->config->getAppValue($this->appName, $key, $default);
return (empty($value)) ? $default : $value;
}

public function setAppValue($key, $value)
{
return $this->config->setAppValue($this->appName, $key, $value);
}

public function getBooleanAppValue($key)
{
return $this->validateBoolean($this->getAppValue($key));
}

private function validateBoolean($val)
{
return $val === true || $val === 'true';
}
}
Loading

0 comments on commit 69ad1c5

Please sign in to comment.