Files
contao-leaflet-maps/src/Backend/About.php

116 lines
3.3 KiB
PHP
Raw Normal View History

2015-01-09 20:57:19 +01:00
<?php
/**
2017-10-05 15:45:43 +02:00
* Leaflet maps for Contao CMS.
*
2016-10-11 10:40:15 +02:00
* @package contao-leaflet-maps
2015-01-09 20:57:19 +01:00
* @author David Molineus <david.molineus@netzmacht.de>
2017-10-11 15:00:48 +02:00
* @copyright 2014-2017 netzmacht David Molineus. All rights reserved.
2017-10-05 15:45:43 +02:00
* @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-maps/blob/master/LICENSE
2015-01-09 20:57:19 +01:00
* @filesource
*/
namespace Netzmacht\Contao\Leaflet\Backend;
2015-01-12 19:03:29 +01:00
/**
* Credits backend module.
*
* @package Netzmacht\Contao\Leaflet\Backend
*/
2015-01-19 09:54:33 +01:00
class About
2015-01-09 20:57:19 +01:00
{
2015-01-12 19:03:29 +01:00
/**
* Generate the backend view.
*
* @return string
*/
2015-01-09 20:57:19 +01:00
public function generate()
{
2015-01-19 11:32:22 +01:00
$template = new \BackendTemplate('be_leaflet_about');
2015-01-09 20:57:19 +01:00
2015-01-12 19:03:29 +01:00
$template->headline = 'Leaftlet maps integration for Contao CMS';
$template->libraries = $this->getLibraries();
2015-01-09 20:57:19 +01:00
list($template->version, $template->dependencies) = $this->extractFromComposer();
return $template->parse();
}
2015-01-12 19:03:29 +01:00
/**
* Get list of all libraries.
*
* @return array
*
* @SuppressWarnings(PHPMD.Superglobals)
*/
2015-01-09 20:57:19 +01:00
private function getLibraries()
{
return array_map(
function ($library) {
$library = array_merge(
[
2015-01-09 20:57:19 +01:00
'homepage' => null,
'version' => null,
],
2015-01-09 20:57:19 +01:00
$library
);
if ($library['homepage']) {
$library['homepage'] = sprintf(
'<a href="%s" %s>%s</a>',
$library['homepage'],
LINK_NEW_WINDOW,
preg_replace('#^(https?://(www)?)#i', '', $library['homepage'])
);
}
return $library;
},
array_filter(
$GLOBALS['LEAFLET_LIBRARIES'],
function ($library) {
return isset($library['name']) && isset($library['license']);
}
)
);
}
2015-01-12 19:03:29 +01:00
/**
* Extract version and dependencies from composer.
*
* @return array
*/
2015-01-09 20:57:19 +01:00
private function extractFromComposer()
{
2017-10-09 17:06:04 +02:00
$extFile = TL_ROOT . '/vendor/netzmacht/contao-leaflet-maps/composer.json';
$lockFile = TL_ROOT . '/composer.lock';
2015-01-09 20:57:19 +01:00
2015-01-19 11:32:22 +01:00
if (!file_exists($extFile) || !file_exists($lockFile)) {
return [];
2015-01-09 20:57:19 +01:00
}
2015-01-19 11:32:22 +01:00
$extension = json_decode(file_get_contents($extFile), true);
$installed = json_decode(file_get_contents($lockFile), true);
$deps = [];
2015-01-09 20:57:19 +01:00
$version = null;
foreach ($installed['packages'] as $package) {
if ($package['name'] === 'netzmacht/contao-leaflet-maps') {
$version = $package['version'];
2015-01-19 11:32:22 +01:00
} elseif (isset($extension['require'][$package['name']])) {
$deps[] = [
2015-01-09 20:57:19 +01:00
'name' => $package['name'],
'version' => $package['version'],
'license' => !empty($package['license']) ? implode(', ', $package['license']) : '',
'homepage' => sprintf(
'<a href="https://packagist.org/packages/%s" target="_blank">Visit packagist</a>',
$package['name']
),
];
2015-01-09 20:57:19 +01:00
}
}
return [$version, $deps];
2015-01-09 20:57:19 +01:00
}
}