-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
160 changed files
with
8,203 additions
and
5,031 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
namespace Tdt\Core\Analytics; | ||
|
||
/** | ||
* GA Tracker class. | ||
* | ||
* @copyright (C) 2011, 2014 by OKFN Belgium vzw/asbl | ||
* @license AGPLv3 | ||
* @author Jan Vansteenlandt <[email protected]> | ||
* @author appreciate.be | ||
*/ | ||
|
||
class GaTracker implements TrackerInterface | ||
{ | ||
private $IGNORE = ['api', 'discovery']; | ||
|
||
public function track($request, $tracker_id) | ||
{ | ||
$path = $request->path(); | ||
$extension = ''; | ||
|
||
if (strpos($path, '.') !== false) { | ||
$uri_parts = explode('.', $request->path()); | ||
|
||
$extension = strtolower(array_pop($uri_parts)); | ||
$path = implode('', $uri_parts); | ||
} else { | ||
$extension = 'html'; | ||
} | ||
|
||
// Get some meta-data from the definition to add to the GA as a dimension | ||
$definitions = \App::make('Tdt\Core\Repositories\Interfaces\DefinitionRepositoryInterface'); | ||
$definition = $definitions->getByIdentifier($path); | ||
|
||
$license = 'Not provided'; | ||
$theme = 'Not provided'; | ||
|
||
if (!empty($definition['rights'])) { | ||
$license = $definition['rights']; | ||
} | ||
|
||
if (!empty($definition['theme'])) { | ||
$theme = $definition['theme']; | ||
} | ||
|
||
// Get the target audience and category. | ||
$segments = $request->segments(); | ||
|
||
if (count($segments) >= 2 && !in_array($segments[0], $this->IGNORE)) { | ||
// The URL of the GA | ||
$url = 'http://www.google-analytics.com/collect'; | ||
|
||
// The version of the Google Analytics Measurement Protocol. | ||
$data['v'] = 1; | ||
|
||
// The tracker ID. | ||
$data['tid'] = $tracker_id; | ||
|
||
// GA requires a user ID, but since all requests are anonymous | ||
// we generate a unique string to use as ID. | ||
$data['cid'] = sprintf( | ||
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x', | ||
mt_rand(0, 0xffff), | ||
mt_rand(0, 0xffff), | ||
mt_rand(0, 0xffff), | ||
mt_rand(0, 0x0fff) | 0x4000, | ||
mt_rand(0, 0x3fff) | 0x8000, | ||
mt_rand(0, 0xffff), | ||
mt_rand(0, 0xffff), | ||
mt_rand(0, 0xffff) | ||
); | ||
|
||
// The type of 'hit', in this case we use pageview. | ||
$data['t'] = 'pageview'; | ||
|
||
// The url to track, required when using 'pageview' as type. | ||
$data['dp'] = $path; | ||
$data['cd1'] = $extension; | ||
$data['cd2'] = $theme; | ||
$data['cd3'] = $license; | ||
|
||
$ch = curl_init(); | ||
curl_setopt($ch, CURLOPT_URL, $url); | ||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded')); | ||
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
curl_setopt($ch, CURLOPT_POST, true); | ||
curl_setopt($ch, CURLOPT_POSTFIELDS, utf8_encode(http_build_query($data))); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | ||
$response = curl_exec($ch); | ||
curl_close($ch); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace Tdt\Core\Analytics; | ||
|
||
interface TrackerInterface | ||
{ | ||
public function track($request, $tracker_id); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace Tdt\Core\Analytics; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
|
||
class TrackerServiceProvider extends ServiceProvider | ||
{ | ||
|
||
public function register() | ||
{ | ||
\App::bind( | ||
'Tdt\Core\Analytics\TrackerInterface', | ||
'Tdt\Core\Analytics\GaTracker' | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,6 @@ | |
* @license AGPLv3 | ||
* @author Jan Vansteenlandt <[email protected]> | ||
*/ | ||
|
||
abstract class ApiController extends \Controller | ||
{ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
<?php | ||
|
||
namespace Tdt\Core\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
|
||
use Tdt\Core\Repositories\Interfaces\DefinitionRepositoryInterface; | ||
use Tdt\Core\Commands\Ie\Definitions; | ||
use Tdt\Core\Commands\Ie\Users; | ||
use Tdt\Core\Commands\Ie\Groups; | ||
|
||
class DcatLicenses extends Command | ||
{ | ||
/** | ||
* The console command name. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'datatank:licenses'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Seed the licenses for the datasets. By default it will install a set of internationally known licenses.'; | ||
|
||
/** | ||
* The URI for the default licenses | ||
* | ||
* @var string | ||
*/ | ||
protected $licenses_uri = 'https://raw.githubusercontent.com/tdt/licenses/master/'; | ||
|
||
/** | ||
* The default license | ||
* | ||
* @var string | ||
*/ | ||
protected $DEFAULT_LICENSE = 'international_licenses'; | ||
|
||
/** | ||
* Create a new command instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* Ask the user which functionality he wants to use (definitions|users) | ||
* then based on the input, proceed with the logic for chosen option. | ||
* | ||
* This option is given as an input argument upon making the command. | ||
* | ||
* @return void | ||
*/ | ||
public function fire() | ||
{ | ||
$this->seedLicenses(); | ||
} | ||
|
||
/** | ||
* Get the console command arguments. | ||
* | ||
* @return array | ||
*/ | ||
protected function getArguments() | ||
{ | ||
return array( | ||
array('name', InputArgument::OPTIONAL, 'The name of the licenses document hosted on https://github.com/tdt/licenses that should be seeded into the datatank. Default value is international_licenses.', $this->DEFAULT_LICENSE), | ||
); | ||
} | ||
|
||
/** | ||
* Get the console command options. | ||
* | ||
* @return array | ||
*/ | ||
protected function getOptions() | ||
{ | ||
return array( | ||
); | ||
} | ||
|
||
/** | ||
* Seed the themes | ||
* | ||
* @return @void | ||
*/ | ||
private function seedLicenses() | ||
{ | ||
$this->info('---- Seeding new licenses ----'); | ||
|
||
$license_name = $this->argument('name'); | ||
|
||
$license_uri = $this->licenses_uri . $license_name; | ||
|
||
if (substr($license_uri, -5) != '.json') { | ||
$license_uri .= '.json'; | ||
} | ||
|
||
// Try to get the themes from the ns.thedatatank.com (semantic data) | ||
try { | ||
$this->info('Trying to fetch triples from the uri: ' . $license_uri); | ||
|
||
try { | ||
$licenses_graph = \EasyRdf_Graph::newAndLoad($license_uri, 'jsonld'); | ||
} catch (\EasyRdf_Http_Exception $ex) { | ||
$this->info('We could not fetch licenses from the URL ' . $license_uri . ', defaulting to ' . $this->DEFAULT_LICENSE . '.'); | ||
|
||
$licenses_graph = $this->fetchDefaultGraph(); | ||
} | ||
|
||
if ($licenses_graph->isEmpty()) { | ||
$this->info('We could not fetch licenses from the URL ' . $license_uri . ', defaulting to ' . $this->DEFAULT_LICENSE . '.'); | ||
|
||
$licenses_graph = $this->fetchDefaultGraph(); | ||
|
||
} else { | ||
$this->info('Fetched new licenses, removing the old ones.'); | ||
|
||
// Empty the licenses table | ||
\License::truncate(); | ||
} | ||
|
||
// Fetch the resources with a skos:conceptScheme relationship | ||
$licenses = $licenses_graph->allOfType('cc:License'); | ||
|
||
$taxonomy_uris = array(); | ||
|
||
foreach ($licenses as $license) { | ||
$url = ''; | ||
$title = ''; | ||
$identifier = ''; | ||
|
||
$title_resource = $license->getLiteral('dc:title'); | ||
$identifier_resource = $license->getLiteral('dc:identifier'); | ||
|
||
if (!empty($title_resource)) { | ||
$title = $title_resource->getValue(); | ||
} | ||
|
||
if (!empty($identifier_resource)) { | ||
$identifier = $identifier_resource->getValue(); | ||
} | ||
|
||
if (!$license->isBNode()) { | ||
$url = $license->getUri(); | ||
} | ||
|
||
\License::create([ | ||
'url' => $url, | ||
'title' => $title, | ||
'license_id' => $identifier | ||
]); | ||
|
||
$this->info('Added license "' . $identifier . '" with title "' . $title . '" and URI ' . $url); | ||
} | ||
|
||
} catch (EasyRdf_Exception $ex) { | ||
$this->info('An error occurred when we tried to fetch online themes.'); | ||
} | ||
} | ||
|
||
/** | ||
* Fetch the default licenses | ||
* | ||
* @return \EasyRdf_Graph | ||
*/ | ||
private function fetchDefaultGraph() | ||
{ | ||
$license_uri = $this->licenses_uri . $this->DEFAULT_LICENSE . '.json'; | ||
|
||
return \EasyRdf_Graph::newAndLoad($license_uri, 'jsonld'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.