Skip to content

Commit

Permalink
deprecate license_homepage plugin metadata and link to a LICENSE[.md|…
Browse files Browse the repository at this point in the history
….txt] file if found (#10756)

* deprecate license_homepage plugin metadata, and link to a LICENSE[.md|.txt] file if found

* Make license view HTML only without menu
  • Loading branch information
mattab committed Oct 20, 2016
1 parent cbf4a83 commit f694787
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 5 deletions.
2 changes: 0 additions & 2 deletions core/Plugin.php
Expand Up @@ -42,7 +42,6 @@
* - **homepage**: The URL to the plugin's website.
* - **authors**: A list of author arrays with keys for 'name', 'email' and 'homepage'
* - **license**: The license the code uses (eg, GPL, MIT, etc.).
* - **license_homepage**: URL to website describing the license used.
* - **version**: The plugin version (eg, 1.0.1).
* - **theme**: `true` or `false`. If `true`, the plugin will be treated as a theme.
*
Expand Down Expand Up @@ -184,7 +183,6 @@ private function hasDefinedPluginInformationInPluginClass()
* - 'author_homepage' => string // author homepage URL (or email "mailto:youremail@example.org")
* - 'homepage' => string // plugin homepage URL
* - 'license' => string // plugin license
* - 'license_homepage' => string // license homepage URL
* - 'version' => string // plugin version number; examples and 3rd party plugins must not use Version::VERSION; 3rd party plugins must increment the version number with each plugin release
* - 'theme' => bool // Whether this plugin is a theme (a theme is a plugin, but a plugin is not necessarily a theme)
*
Expand Down
37 changes: 35 additions & 2 deletions core/Plugin/MetadataLoader.php
Expand Up @@ -57,6 +57,12 @@ public function load()
unset($plugin['description']);
}

// look for a license file
$licenseFile = $this->getPathToLicenseFile();
if(!empty($licenseFile)) {
$plugin['license_file'] = $licenseFile;
}

return array_merge(
$defaults,
$plugin
Expand All @@ -78,7 +84,6 @@ private function getDefaultPluginInformation()
'homepage' => 'http://piwik.org/',
'authors' => array(array('name' => 'Piwik', 'homepage' => 'http://piwik.org/')),
'license' => 'GPL v3+',
'license_homepage' => 'http://www.gnu.org/licenses/gpl.html',
'version' => Version::VERSION,
'theme' => false,
'require' => array()
Expand All @@ -87,7 +92,7 @@ private function getDefaultPluginInformation()

private function loadPluginInfoJson()
{
$path = \Piwik\Plugin\Manager::getPluginsDirectory() . $this->pluginName . '/' . self::PLUGIN_JSON_FILENAME;
$path = $this->getPathToPluginFolder() . '/' . self::PLUGIN_JSON_FILENAME;
return $this->loadJsonMetadata($path);
}

Expand All @@ -111,4 +116,32 @@ private function loadJsonMetadata($path)

return $info;
}

/**
* @return string
*/
private function getPathToPluginFolder()
{
return \Piwik\Plugin\Manager::getPluginsDirectory() . $this->pluginName;
}

/**
* @return null|string
*/
public function getPathToLicenseFile()
{
$prefixPath = $this->getPathToPluginFolder() . '/';
$licenseFiles = array(
'LICENSE',
'LICENSE.md',
'LICENSE.txt'
);
foreach ($licenseFiles as $licenseFile) {
$pathToLicense = $prefixPath . $licenseFile;
if (is_file($pathToLicense) && is_readable($pathToLicense)) {
return $pathToLicense;
}
}
return null;
}
}
19 changes: 19 additions & 0 deletions plugins/CorePluginsAdmin/Controller.php
Expand Up @@ -483,6 +483,25 @@ public function uninstall($redirectAfter = true)
$this->redirectAfterModification($redirectAfter);
}

public function showLicense()
{
$pluginName = Common::getRequestVar('pluginName', null, 'string');

$metadata = new Plugin\MetadataLoader($pluginName);
$license_file = $metadata->getPathToLicenseFile();

$license = 'No license file found for this plugin.';
if(!empty($license_file)) {
$license = file_get_contents($license_file);
$license = nl2br($license);
}

$view = $this->configureView('@CorePluginsAdmin/license');
$view->pluginName = $pluginName;
$view->license = $license;
return $view->render();
}

protected function initPluginModification($nonceName)
{
Piwik::checkUserHasSuperUserAccess();
Expand Down
4 changes: 4 additions & 0 deletions plugins/CorePluginsAdmin/templates/license.twig
@@ -0,0 +1,4 @@

<h1>License for {{ pluginName|raw }}</h1>

{{ license|raw }}
2 changes: 1 addition & 1 deletion plugins/CorePluginsAdmin/templates/macros.twig
Expand Up @@ -216,7 +216,7 @@
</div>
{% if plugin.info.license is defined %}
<div class="plugin-license">
{% if plugin.info.license_homepage is defined %}<a title="{{ 'CorePluginsAdmin_LicenseHomepage'|translate }}" rel="noreferrer" target="_blank" href="{{ plugin.info.license_homepage }}">{% endif %}{{ plugin.info.license }}{% if plugin.info.license_homepage is defined %}</a>{% endif %}
{% if plugin.info.license_file is defined %}<a title="{{ 'CorePluginsAdmin_LicenseHomepage'|translate }}" rel="noreferrer" target="_blank" href="index.php?module=CorePluginsAdmin&action=showLicense&pluginName={{ name }}">{% endif %}{{ plugin.info.license }}{% if plugin.info.license_file is defined %}</a>{% endif %}
</div>
{% endif %}
{% if plugin.info.authors is defined %}
Expand Down

0 comments on commit f694787

Please sign in to comment.