"MDL-21146, improve file license code"
This commit is contained in:
@@ -35,9 +35,9 @@ if (!during_initial_install()) { //do not use during installation
|
||||
$temp->add(new admin_setting_configselect('maxcategorydepth', get_string('configsitemaxcategorydepth','admin'), get_string('configsitemaxcategorydepthhelp','admin'), 0, $options));
|
||||
require_once($CFG->libdir . '/licenselib.php');
|
||||
$licenses = array();
|
||||
$array = license_manager::get();
|
||||
foreach ($array as $key=>$value) {
|
||||
$licenses[$value->shortname] = $value->fullname;
|
||||
$array = explode(',', $CFG->licenses);
|
||||
foreach ($array as $value) {
|
||||
$licenses[$value] = get_string($value, 'license');
|
||||
}
|
||||
$temp->add(new admin_setting_configselect('sitedefaultlicense', get_string('configsitedefaultlicense','admin'), get_string('configsitedefaultlicensehelp','admin'), 'allrightsreserved', $licenses));
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
$string['allrightsreserved'] = 'All rights reserved';
|
||||
$string['cc'] = 'Creative Commons';
|
||||
$string['cc-nd'] = 'Creative Commons - NoDerivs';
|
||||
$string['cc-nc-nd'] = 'Creative Commons - No Commercial NoDerivs';
|
||||
$string['cc-nc'] = 'Creative Commons - No Commercial';
|
||||
$string['cc-nc-sa'] = 'Creative Commons - No Commercial ShareAlike';
|
||||
$string['cc-sa'] = 'Creative Commons - ShareAlike';
|
||||
$string['public'] = 'Public domain';
|
||||
$string['unknown'] = 'Unknown license';
|
||||
+5
-4
@@ -5060,12 +5060,14 @@ class admin_setting_managelicenses extends admin_setting {
|
||||
public function output_html($data, $query='') {
|
||||
global $CFG, $OUTPUT;
|
||||
require_once($CFG->libdir . '/licenselib.php');
|
||||
$url = "licenses.php?sesskey=" . sesskey();
|
||||
|
||||
// display strings
|
||||
$txt = get_strings(array('administration', 'settings', 'name', 'enable', 'disable', 'none'));
|
||||
$licenses = license_manager::get();
|
||||
$licenses = license_manager::get_licenses();
|
||||
|
||||
$return = $OUTPUT->heading(get_string('managelicenses', 'admin'), 3, 'main', true);
|
||||
|
||||
$return .= $OUTPUT->box_start('generalbox editorsui');
|
||||
|
||||
$table = new html_table();
|
||||
@@ -5074,9 +5076,8 @@ class admin_setting_managelicenses extends admin_setting {
|
||||
$table->width = '100%';
|
||||
$table->data = array();
|
||||
|
||||
$url = "licenses.php?sesskey=" . sesskey();
|
||||
foreach ($licenses as $key => $value) {
|
||||
$displayname = html_writer::link($value->source, $value->fullname, array('target'=>'_blank'));
|
||||
foreach ($licenses as $value) {
|
||||
$displayname = html_writer::link($value->source, get_string($value->shortname, 'license'), array('target'=>'_blank'));
|
||||
|
||||
if ($value->enabled == 1) {
|
||||
$hideshow = html_writer::link($url.'&action=disable&license='.$value->shortname,
|
||||
|
||||
+170
-4
@@ -3115,7 +3115,7 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL");
|
||||
upgrade_main_savepoint($result, 2010032400);
|
||||
}
|
||||
|
||||
if ($result && $oldversion < 2010032405) {
|
||||
if ($result && $oldversion < 2010033101) {
|
||||
|
||||
/// Define field source to be added to files
|
||||
$table = new xmldb_table('files');
|
||||
@@ -3159,13 +3159,179 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL");
|
||||
if (!$dbman->table_exists($table)) {
|
||||
$dbman->create_table($table);
|
||||
}
|
||||
require_once($CFG->libdir . '/licenselib.php');
|
||||
license_manager::install_licenses();
|
||||
$active_licenses = array();
|
||||
|
||||
$license = new stdclass;
|
||||
|
||||
// add unknown license
|
||||
$license->shortname = 'unknown';
|
||||
$license->fullname = 'Unknown license';
|
||||
$license->source = '';
|
||||
$license->enabled = 1;
|
||||
$license->version = '2010033100';
|
||||
$active_licenses[] = $license->shortname;
|
||||
if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
|
||||
if ($record->version < $license->version) {
|
||||
// update license record
|
||||
$license->enabled = $record->enabled;
|
||||
$license->id = $record->id;
|
||||
$DB->update_record('license', $license);
|
||||
}
|
||||
} else {
|
||||
$DB->insert_record('license', $license);
|
||||
}
|
||||
|
||||
// add all rights reserved license
|
||||
$license->shortname = 'allrightsreserved';
|
||||
$license->fullname = 'All rights reserved';
|
||||
$license->source = 'http://en.wikipedia.org/wiki/All_rights_reserved';
|
||||
$license->enabled = 1;
|
||||
$license->version = '2010033100';
|
||||
$active_licenses[] = $license->shortname;
|
||||
if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
|
||||
if ($record->version < $license->version) {
|
||||
// update license record
|
||||
$license->id = $record->id;
|
||||
$license->enabled = $record->enabled;
|
||||
$DB->update_record('license', $license);
|
||||
}
|
||||
} else {
|
||||
$DB->insert_record('license', $license);
|
||||
}
|
||||
|
||||
// add public domain license
|
||||
$license->shortname = 'public';
|
||||
$license->fullname = 'Public Domain';
|
||||
$license->source = 'http://creativecommons.org/licenses/publicdomain/';
|
||||
$license->enabled = 1;
|
||||
$license->version = '2010033100';
|
||||
$active_licenses[] = $license->shortname;
|
||||
if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
|
||||
if ($record->version < $license->version) {
|
||||
// update license record
|
||||
$license->enabled = $record->enabled;
|
||||
$license->id = $record->id;
|
||||
$DB->update_record('license', $license);
|
||||
}
|
||||
} else {
|
||||
$DB->insert_record('license', $license);
|
||||
}
|
||||
|
||||
// add creative commons license
|
||||
$license->shortname = 'cc';
|
||||
$license->fullname = 'Creative Commons';
|
||||
$license->source = 'http://creativecommons.org/licenses/by/3.0/';
|
||||
$license->enabled = 1;
|
||||
$license->version = '2010033100';
|
||||
$active_licenses[] = $license->shortname;
|
||||
if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
|
||||
if ($record->version < $license->version) {
|
||||
// update license record
|
||||
$license->enabled = $record->enabled;
|
||||
$license->id = $record->id;
|
||||
$DB->update_record('license', $license);
|
||||
}
|
||||
} else {
|
||||
$DB->insert_record('license', $license);
|
||||
}
|
||||
|
||||
// add creative commons no derivs license
|
||||
$license->shortname = 'cc-nd';
|
||||
$license->fullname = 'Creative Commons - NoDerivs';
|
||||
$license->source = 'http://creativecommons.org/licenses/by-nd/3.0/';
|
||||
$license->enabled = 1;
|
||||
$license->version = '2010033100';
|
||||
$active_licenses[] = $license->shortname;
|
||||
if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
|
||||
if ($record->version < $license->version) {
|
||||
// update license record
|
||||
$license->enabled = $record->enabled;
|
||||
$license->id = $record->id;
|
||||
$DB->update_record('license', $license);
|
||||
}
|
||||
} else {
|
||||
$DB->insert_record('license', $license);
|
||||
}
|
||||
|
||||
// add creative commons no commercial no derivs license
|
||||
$license->shortname = 'cc-nc-nd';
|
||||
$license->fullname = 'Creative Commons - No Commercial NoDerivs';
|
||||
$license->source = 'http://creativecommons.org/licenses/by-nc-nd/3.0/';
|
||||
$license->enabled = 1;
|
||||
$license->version = '2010033100';
|
||||
$active_licenses[] = $license->shortname;
|
||||
if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
|
||||
if ($record->version < $license->version) {
|
||||
// update license record
|
||||
$license->enabled = $record->enabled;
|
||||
$license->id = $record->id;
|
||||
$DB->update_record('license', $license);
|
||||
}
|
||||
} else {
|
||||
$DB->insert_record('license', $license);
|
||||
}
|
||||
|
||||
// add creative commons no commercial
|
||||
$license->shortname = 'cc-nc-nd';
|
||||
$license->shortname = 'cc-nc';
|
||||
$license->fullname = 'Creative Commons - No Commercial';
|
||||
$license->source = 'http://creativecommons.org/licenses/by-nd/3.0/';
|
||||
$license->enabled = 1;
|
||||
$license->version = '2010033100';
|
||||
$active_licenses[] = $license->shortname;
|
||||
if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
|
||||
if ($record->version < $license->version) {
|
||||
// update license record
|
||||
$license->enabled = $record->enabled;
|
||||
$license->id = $record->id;
|
||||
$DB->update_record('license', $license);
|
||||
}
|
||||
} else {
|
||||
$DB->insert_record('license', $license);
|
||||
}
|
||||
|
||||
// add creative commons no commercial sharealike
|
||||
$license->shortname = 'cc-nc-sa';
|
||||
$license->fullname = 'Creative Commons - No Commercial ShareAlike';
|
||||
$license->source = 'http://creativecommons.org/licenses/by-nc-sa/3.0/';
|
||||
$license->enabled = 1;
|
||||
$license->version = '2010033100';
|
||||
$active_licenses[] = $license->shortname;
|
||||
if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
|
||||
if ($record->version < $license->version) {
|
||||
// update license record
|
||||
$license->enabled = $record->enabled;
|
||||
$license->id = $record->id;
|
||||
$DB->update_record('license', $license);
|
||||
}
|
||||
} else {
|
||||
$DB->insert_record('license', $license);
|
||||
}
|
||||
|
||||
// add creative commons sharealike
|
||||
$license->shortname = 'cc-sa';
|
||||
$license->fullname = 'Creative Commons - ShareAlike';
|
||||
$license->source = 'http://creativecommons.org/licenses/by-sa/3.0/';
|
||||
$license->enabled = 1;
|
||||
$license->version = '2010033100';
|
||||
$active_licenses[] = $license->shortname;
|
||||
if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
|
||||
if ($record->version < $license->version) {
|
||||
// update license record
|
||||
$license->enabled = $record->enabled;
|
||||
$license->id = $record->id;
|
||||
$DB->update_record('license', $license);
|
||||
}
|
||||
} else {
|
||||
$DB->insert_record('license', $license);
|
||||
}
|
||||
|
||||
set_config('licenses', implode(',', $active_licenses));
|
||||
/// set site default license
|
||||
set_config('sitedefaultlicense', 'allrightsreserved');
|
||||
|
||||
/// Main savepoint reached
|
||||
upgrade_main_savepoint($result, 2010032405);
|
||||
upgrade_main_savepoint($result, 2010033101);
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
+64
-46
@@ -43,17 +43,31 @@ class license_manager {
|
||||
// record exists
|
||||
if ($record->version < $license->version) {
|
||||
// update license record
|
||||
$license->enabled = $record->enabled;
|
||||
$license->id = $record->id;
|
||||
$DB->update_record('license', $license);
|
||||
} else {
|
||||
debugging('won\'t update');
|
||||
}
|
||||
} else {
|
||||
if ($license_id = $DB->insert_record('license', $license)) {
|
||||
return $license_id;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
$DB->insert_record('license', $license);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get license records
|
||||
* @param mixed $param
|
||||
* @return array
|
||||
*/
|
||||
static public function get_licenses($param = null) {
|
||||
global $DB;
|
||||
if (empty($param) || !is_array($param)) {
|
||||
$param = array();
|
||||
}
|
||||
// get licenses by conditions
|
||||
if ($records = $DB->get_records('license', $param)) {
|
||||
return $records;
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,26 +76,12 @@ class license_manager {
|
||||
* @param mixed $param the shortname of license, or an array
|
||||
* @return object
|
||||
*/
|
||||
static public function get($param = null) {
|
||||
static public function get_license_by_shortname($name) {
|
||||
global $DB;
|
||||
if (empty($param)) {
|
||||
$param = array();
|
||||
}
|
||||
|
||||
// get license by shortname
|
||||
if (is_string($param)) {
|
||||
if ($record = $DB->get_record('license', array('shortname'=>$name))) {
|
||||
return $record;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else if (is_array($param)) {
|
||||
// get licenses by conditions
|
||||
if ($records = $DB->get_records('license', $param)) {
|
||||
return $records;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
if ($record = $DB->get_record('license', array('shortname'=>$name))) {
|
||||
return $record;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,13 +92,12 @@ class license_manager {
|
||||
*/
|
||||
static public function enable($license) {
|
||||
global $DB;
|
||||
if ($record = $DB->get_record('license', array('shortname'=>$license))) {
|
||||
$record->enabled = 1;
|
||||
$DB->update_record('license', $record);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
if ($license = self::get_license_by_shortname($license)) {
|
||||
$license->enabled = 1;
|
||||
$DB->update_record('license', $license);
|
||||
}
|
||||
self::set_active_licenses();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,13 +107,25 @@ class license_manager {
|
||||
*/
|
||||
static public function disable($license) {
|
||||
global $DB;
|
||||
if ($record = $DB->get_record('license', array('shortname'=>$license))) {
|
||||
$record->enabled = 0;
|
||||
$DB->update_record('license', $record);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
if ($license = self::get_license_by_shortname($license)) {
|
||||
$license->enabled = 0;
|
||||
$DB->update_record('license', $license);
|
||||
}
|
||||
self::set_active_licenses();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store active licenses in global $CFG
|
||||
*/
|
||||
static private function set_active_licenses() {
|
||||
// set to global $CFG
|
||||
$licenses = self::get_licenses(array('enabled'=>1));
|
||||
$result = array();
|
||||
foreach ($licenses as $l) {
|
||||
$result[] = $l->shortname;
|
||||
}
|
||||
set_config('licenses', implode(',', $result));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,60 +134,67 @@ class license_manager {
|
||||
static public function install_licenses() {
|
||||
$license = new stdclass;
|
||||
|
||||
$license->shortname = 'unknown';
|
||||
$license->fullname = 'Unknown license';
|
||||
$license->source = '';
|
||||
$license->enabled = 1;
|
||||
$license->version = '2010033100';
|
||||
self::add($license);
|
||||
|
||||
$license->shortname = 'allrightsreserved';
|
||||
$license->fullname = 'All rights reserved';
|
||||
$license->source = 'http://en.wikipedia.org/wiki/All_rights_reserved';
|
||||
$license->enabled = 1;
|
||||
$license->version = '2010032500';
|
||||
$license->version = '2010033100';
|
||||
self::add($license);
|
||||
|
||||
$license->shortname = 'public';
|
||||
$license->fullname = 'Public Domain';
|
||||
$license->source = 'http://creativecommons.org/licenses/publicdomain/';
|
||||
$license->enabled = 1;
|
||||
$license->version = '2010032500';
|
||||
$license->version = '2010033100';
|
||||
self::add($license);
|
||||
|
||||
$license->shortname = 'cc';
|
||||
$license->fullname = 'Creative Commons';
|
||||
$license->source = 'http://creativecommons.org/licenses/by/3.0/';
|
||||
$license->enabled = 1;
|
||||
$license->version = '2010032500';
|
||||
$license->version = '2010033100';
|
||||
self::add($license);
|
||||
|
||||
$license->shortname = 'cc-nd';
|
||||
$license->fullname = 'Creative Commons - NoDerivs';
|
||||
$license->source = 'http://creativecommons.org/licenses/by-nd/3.0/';
|
||||
$license->enabled = 1;
|
||||
$license->version = '2010032500';
|
||||
$license->version = '2010033100';
|
||||
self::add($license);
|
||||
|
||||
$license->shortname = 'cc-nc-nd';
|
||||
$license->fullname = 'Creative Commons - No Commercial NoDerivs';
|
||||
$license->source = 'http://creativecommons.org/licenses/by-nc-nd/3.0/';
|
||||
$license->enabled = 1;
|
||||
$license->version = '2010032500';
|
||||
$license->version = '2010033100';
|
||||
self::add($license);
|
||||
|
||||
$license->shortname = 'cc-nc';
|
||||
$license->fullname = 'Creative Commons - No Commercial';
|
||||
$license->source = 'http://creativecommons.org/licenses/by-nd/3.0/';
|
||||
$license->enabled = 1;
|
||||
$license->version = '2010032500';
|
||||
$license->version = '2010033100';
|
||||
self::add($license);
|
||||
|
||||
$license->shortname = 'cc-nc-sa';
|
||||
$license->fullname = 'Creative Commons - No Commercial ShareAlike';
|
||||
$license->source = 'http://creativecommons.org/licenses/by-nc-sa/3.0/';
|
||||
$license->enabled = 1;
|
||||
$license->version = '2010032500';
|
||||
$license->version = '2010033100';
|
||||
self::add($license);
|
||||
|
||||
$license->shortname = 'cc-sa';
|
||||
$license->fullname = 'Creative Commons - ShareAlike';
|
||||
$license->source = 'http://creativecommons.org/licenses/by-sa/3.0/';
|
||||
$license->enabled = 1;
|
||||
$license->version = '2010032500';
|
||||
$license->version = '2010033100';
|
||||
self::add($license);
|
||||
}
|
||||
}
|
||||
|
||||
+8
-1
@@ -1766,8 +1766,15 @@ function initialise_filepicker($args) {
|
||||
global $CFG, $USER, $PAGE, $OUTPUT;
|
||||
$return = new stdclass;
|
||||
require_once($CFG->libdir . '/licenselib.php');
|
||||
$array = explode(',', $CFG->licenses);
|
||||
$licenses = array();
|
||||
foreach ($array as $license) {
|
||||
$l = new stdclass;
|
||||
$l->shortname = $license;
|
||||
$l->fullname = get_string($license, 'license');
|
||||
$licenses[] = $l;
|
||||
}
|
||||
|
||||
$licenses = license_manager::get(array('enabled'=>1));
|
||||
$return->licenses = $licenses;
|
||||
|
||||
$return->author = fullname($USER);
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
// This is compared against the values stored in the database to determine
|
||||
// whether upgrades should be performed (see lib/db/*.php)
|
||||
|
||||
$version = 2010032405; // YYYYMMDD = date of the last version bump
|
||||
$version = 2010033101; // YYYYMMDD = date of the last version bump
|
||||
// XX = daily increments
|
||||
|
||||
$release = '2.0 dev (Build: 20100331)'; // Human-friendly version name
|
||||
|
||||
Reference in New Issue
Block a user