Skip to content

Commit

Permalink
"MDL-21146, improve file license code"
Browse files Browse the repository at this point in the history
  • Loading branch information
Dongsheng Cai committed Mar 31, 2010
1 parent 1e9bbac commit d1d4813
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 59 deletions.
6 changes: 3 additions & 3 deletions admin/settings/frontpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
$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));

Expand Down
10 changes: 10 additions & 0 deletions lang/en_utf8/license.php
Original file line number Diff line number Diff line change
@@ -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';
9 changes: 5 additions & 4 deletions lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -5060,12 +5060,14 @@ public function write_setting($data) {
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();
Expand All @@ -5074,9 +5076,8 @@ public function output_html($data, $query='') {
$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,
Expand Down
174 changes: 170 additions & 4 deletions lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3115,7 +3115,7 @@ function xmldb_main_upgrade($oldversion) {
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');
Expand Down Expand Up @@ -3159,13 +3159,179 @@ function xmldb_main_upgrade($oldversion) {
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;
Expand Down
Loading

0 comments on commit d1d4813

Please sign in to comment.