4 * Implements hook_js_alter().
6 function librejs_js_alter(&$javascript) {
7 static $inline, $librejs;
8 // Add inline JavaScript license statement.
12 'group' => JS_LIBRARY,
20 'data' => theme('librejs_inline_license'),
23 $javascript[] = $inline;
25 $librejs = db_query('SELECT data, license, version FROM {librejs}')->fetchAllAssoc('data');
27 foreach ($javascript as $key => $js) {
28 if ($js['type'] == 'file' || $js['type'] == 'external') {
29 // Aggregated JavaScript will be tagged as GPLv3, so do not aggregate
30 // non-GPLv3-compatible JavaScript.
31 if (empty($librejs[$js['data']]->license)) {
32 $javascript[$key]['preprocess'] = FALSE;
34 // Merge JavaScript into database if not present or version has changed.
35 if (!isset($librejs[$js['data']]) || (isset($js['version']) && $librejs[$js['data']]->version != $js['version'])) {
36 $key = array('data' => $js['data']);
38 $fields['type'] = $js['type'];
39 if (isset($js['version'])) {
40 $fields['version'] = $js['version'];
42 db_merge('librejs')->key($key)->fields($fields)->execute();
49 * Returns a list of LibreJS-compatible licenses.
51 function librejs_licenses() {
53 'http://www.gnu.org/licenses/gpl-2.0.html' => 'GNU-GPL-2.0-or-later',
54 'http://www.gnu.org/licenses/gpl-3.0.html' => 'GNU-GPL-3.0-or-later',
55 'http://www.gnu.org/licenses/lgpl-2.1.html' => 'GNU-LGPL-2.1-or-later',
56 'http://www.gnu.org/licenses/lgpl-3.0.html' => 'GNU-LGPL-3.0-or-later',
57 'http://www.gnu.org/licenses/agpl-3.0.html' => 'GNU-AGPL-3.0-or-later',
58 'http://www.apache.org/licenses/LICENSE-2.0' => 'Apache-2.0-only',
59 'http://directory.fsf.org/wiki/License:BSD_3Clause' => 'Modified-BSD',
60 'http://creativecommons.org/publicdomain/zero/1.0/legalcode' => 'CC0-1.0-only',
61 'http://www.jclark.com/xml/copying.txt' => 'Expat',
62 'http://www.mozilla.org/MPL/2.0' => 'MPL-2.0-or-later',
68 * Implements hook_menu().
70 function librejs_menu() {
71 $items['librejs/jslicense'] = array(
72 'access arguments' => array('access jslicense'),
73 'page callback' => 'librejs_jslicense',
74 'title' => 'JavaScript license information',
75 'description' => 'License and source code of JavaScript used by the site.',
76 'file' => 'librejs.pages.inc',
77 'options' => array('attributes' => array('rel' => 'jslicense')),
79 $items['admin/config/development/librejs'] = array(
80 'access arguments' => array('administer site configuration'),
81 'page callback' => 'drupal_get_form',
82 'page arguments' => array('librejs_admin_settings'),
84 'description' => 'Configure the license and source of JavaScript used by the site.',
85 'file' => 'librejs.admin.inc',
91 * Implements hook_page_build().
93 function librejs_page_build(&$page) {
94 if (user_access('access jslicense')) {
95 $page['page_bottom']['librejs'] = array(
97 '#markup' => l(t('JavaScript license information'), 'librejs/jslicense', array('attributes' => array('rel' => 'jslicense', 'style' => 'display: none'))),
103 * Implements hook_permission().
105 function librejs_permission() {
107 'access jslicense' => array(
108 'title' => t('Access JavaScript license information'),
109 'description' => t('Roles granted this permission can identify and read all JavaScript files used by the site.'),
115 * Implements hook_theme().
117 function librejs_theme($existing, $type, $theme, $path) {
119 'librejs_inline_license' => array(
120 'template' => 'librejs-inline-license',
121 'variables' => array('year' => NULL, 'author' => NULL),
127 * Preprocess variables for librejs-inline-license.tpl.php
129 function template_preprocess_librejs_inline_license(&$variables) {
130 $variables['year'] = date('Y');
131 $variables['author'] = check_plain(variable_get('site_name', 'Drupal'));