diff --git a/admin/licenses.php b/admin/licenses.php new file mode 100644 index 00000000000..dfd843d009d --- /dev/null +++ b/admin/licenses.php @@ -0,0 +1,57 @@ +. + +/** + * Allows admin to configure licenses. + */ + +require_once('../config.php'); +require_once($CFG->libdir.'/adminlib.php'); +require_once($CFG->libdir.'/licenselib.php'); + +require_login(); +require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)); + +$returnurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=managelicenses"; + +$action = optional_param('action', '', PARAM_ACTION); +$license = optional_param('license', '', PARAM_SAFEDIR); + +//////////////////////////////////////////////////////////////////////////////// +// process actions + +if (!confirm_sesskey()) { + redirect($returnurl); +} + +$return = true; +switch ($action) { + case 'disable': + license_manager::disable($license); + break; + + case 'enable': + license_manager::enable($license); + break; + + default: + break; +} + +if ($return) { + redirect ($returnurl); +} diff --git a/admin/settings/frontpage.php b/admin/settings/frontpage.php index 0028a67d155..1dd74638934 100644 --- a/admin/settings/frontpage.php +++ b/admin/settings/frontpage.php @@ -33,6 +33,13 @@ if (!during_initial_install()) { //do not use during installation $options[$i] = $i; } $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; + } + $temp->add(new admin_setting_configselect('sitedefaultlicense', get_string('configsitedefaultlicense','admin'), get_string('configsitedefaultlicensehelp','admin'), 'allrightsreserved', $licenses)); $temp->add(new admin_setting_sitesetcheckbox('numsections', get_string('sitesection'), get_string('sitesectionhelp','admin'), 1)); $temp->add(new admin_setting_sitesetselect('newsitems', get_string('newsitemsnumber'), '', 3, diff --git a/admin/settings/plugins.php b/admin/settings/plugins.php index 029beac7a8c..0a843e248f2 100644 --- a/admin/settings/plugins.php +++ b/admin/settings/plugins.php @@ -83,6 +83,11 @@ if ($hassiteconfig) { $ADMIN->add('editorsettings', $editor_setting); } } +/// License types + $ADMIN->add('modules', new admin_category('licensesettings', get_string('license'))); + $temp = new admin_settingpage('managelicenses', get_string('license')); + $temp->add(new admin_setting_managelicenses()); + $ADMIN->add('licensesettings', $temp); /// Filter plugins $ADMIN->add('modules', new admin_category('filtersettings', get_string('managefilters'))); diff --git a/files/files_ajax.php b/files/files_ajax.php index f02bf632ffc..f46ffacc5e1 100755 --- a/files/files_ajax.php +++ b/files/files_ajax.php @@ -20,7 +20,7 @@ * * @package moodlecore * @subpackage file - * @copyright 1999 onwards Dongsheng Cai + * @copyright 2010 Dongsheng Cai * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/lang/en_utf8/admin.php b/lang/en_utf8/admin.php index f70701aa49e..ccd2ffec1e1 100644 --- a/lang/en_utf8/admin.php +++ b/lang/en_utf8/admin.php @@ -211,6 +211,8 @@ $string['configlongtimenosee'] = 'If students haven\'t logged in for a very long $string['configlookahead'] = 'Days to look ahead'; $string['configmailnewline'] = 'Newline characters used in mail messages. CRLF is required according to RFC 822bis, some mail servers do automatic conversion from LF to CRLF, other mail servers do incorrect conversion from CRLF to CRCRLF, yet others reject mails with bare LF (qmail for example). Try changing this setting if you are having problems with undelivered emails or double newlines.'; $string['configmaxbytes'] = 'This specifies a maximum size that uploaded files can be throughout the whole site. This setting is limited by the PHP settings post_max_size and upload_max_filesize, as well as the Apache setting LimitRequestBody. In turn, maxbytes limits the range of sizes that can be chosen at course level or module level. If \'Server Limit\' is chosen, the server maximum allowed by the server will be used.'; +$string['configsitedefaultlicense'] = 'Default site license'; +$string['configsitedefaultlicensehelp'] = 'Default license will be used to publish content on this site'; $string['configsitemaxcategorydepth'] = 'Maximum Category Depth'; $string['configsitemaxcategorydepthhelp'] = 'This specifies the maximum depth of child categories shown'; $string['configmaxeditingtime'] = 'This specifies the amount of time people have to re-edit forum postings, glossary comments etc. Usually 30 minutes is a good value.'; @@ -574,6 +576,7 @@ $string['langupdatecomplete'] = 'Language pack update completed'; $string['latexpreamble'] = 'LaTeX preamble'; $string['latexsettings'] = 'LaTeX renderer Settings'; $string['latinexcelexport'] = 'Excel encoding'; +$string['licensesettings'] = 'License settings'; $string['localetext'] = 'Sitewide locale'; $string['localstringcustomization'] = 'Local string customization'; $string['location'] = 'Location'; @@ -588,6 +591,7 @@ $string['mailnewline'] = 'Newline characters in mail'; $string['maintfileopenerror'] = 'Error opening maintenance files!'; $string['maintinprogress'] = 'Maintenance is in progress...'; $string['managelang'] = 'Manage'; +$string['managelicenses'] = 'Manage licenses'; $string['manageqtypes'] = 'Manage question types'; $string['maintenancemode'] = 'In Maintenance Mode'; $string['maxbytes'] = 'Maximum uploaded file size'; diff --git a/lang/en_utf8/moodle.php b/lang/en_utf8/moodle.php index 877e7eb1f13..082eba7bc93 100644 --- a/lang/en_utf8/moodle.php +++ b/lang/en_utf8/moodle.php @@ -924,7 +924,8 @@ $string['latestlanguagepack'] = 'Check for latest language pack on moodle.org'; $string['latestnews'] = 'Latest News'; $string['layouttable'] = 'Layout table'; $string['leavetokeep'] = 'Leave blank to keep current password'; -$string['license'] = 'GPL License'; +$string['license'] = 'License'; +$string['gpllicense'] = 'GPL License'; $string['liketologin'] = 'Would you like to log in now with a full user account?'; $string['list'] = 'List'; $string['listfiles'] = 'List of files in $a'; diff --git a/lang/en_utf8/repository.php b/lang/en_utf8/repository.php index 404e6adc2fb..372dd913552 100644 --- a/lang/en_utf8/repository.php +++ b/lang/en_utf8/repository.php @@ -16,6 +16,7 @@ $string['areauserpersonal'] = 'Personal'; $string['areauserprofile'] = 'Profile'; $string['attachment'] = 'Attachment'; $string['attachedfiles'] = 'Attached files'; +$string['author'] = 'Author'; $string['back'] = '« Back'; $string['cacheexpire'] = 'Cache expire'; $string['cachecleared'] = 'Cached files are removed'; @@ -25,6 +26,7 @@ $string['cannotdownload'] = 'Cannot download this file'; $string['cannotdownloaddir'] = 'Cannot download this folder'; $string['cannotinitplugin'] = 'Call plugin_init failed'; $string['choosealink'] = 'Choose a link...'; +$string['chooselicense'] = 'Choose license'; $string['clicktohide'] = 'Click here to hide'; $string['clicktoshow'] = 'Click here to show'; $string['close'] = 'Close'; diff --git a/lib/adminlib.php b/lib/adminlib.php index 178e84c73df..7d9eae1d09e 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -5008,6 +5008,92 @@ class admin_setting_manageeditors extends admin_setting { } } +/** + * Special class for license administration. + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class admin_setting_managelicenses extends admin_setting { + /** + * Calls parent::__construct with specific arguments + */ + public function __construct() { + $this->nosave = true; + parent::__construct('licensesui', get_string('licensesettings', 'admin'), '', ''); + } + + /** + * Always returns true, does nothing + * + * @return true + */ + public function get_setting() { + return true; + } + + /** + * Always returns true, does nothing + * + * @return true + */ + public function get_defaultsetting() { + return true; + } + + /** + * Always returns '', does not write anything + * + * @return string Always returns '' + */ + public function write_setting($data) { + // do not write any setting + return ''; + } + + /** + * Builds the XHTML to display the control + * + * @param string $data Unused + * @param string $query + * @return string + */ + public function output_html($data, $query='') { + global $CFG, $OUTPUT; + require_once($CFG->libdir . '/licenselib.php'); + + // display strings + $txt = get_strings(array('administration', 'settings', 'name', 'enable', 'disable', 'none')); + $licenses = license_manager::get(); + + $return = $OUTPUT->heading(get_string('managelicenses', 'admin'), 3, 'main', true); + $return .= $OUTPUT->box_start('generalbox editorsui'); + + $table = new html_table(); + $table->head = array($txt->name, $txt->enable); + $table->align = array('left', 'center'); + $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')); + + if ($value->enabled == 1) { + $hideshow = html_writer::link($url.'&action=disable&license='.$value->shortname, + html_writer::tag('img', '', array('src'=>$OUTPUT->pix_url('i/hide'), 'class'=>'icon', 'alt'=>'disable'))); + } else { + $hideshow = html_writer::link($url.'&action=enable&license='.$value->shortname, + html_writer::tag('img', '', array('src'=>$OUTPUT->pix_url('i/show'), 'class'=>'icon', 'alt'=>'enable'))); + } + $enabled = true; + + $table->data[] =array($displayname, $hideshow); + } + $return .= html_writer::table($table); + $return .= $OUTPUT->box_end(); + return highlight($query, $return); + } +} /** * Special class for filter administration. * diff --git a/lib/db/install.xml b/lib/db/install.xml index 28ce6ef12c3..c3322d65e8a 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1,5 +1,5 @@ - @@ -2099,7 +2099,10 @@ - + + + + @@ -2391,7 +2394,7 @@ - +
@@ -2406,5 +2409,18 @@
+ + + + + + + + + + + + +
-
\ No newline at end of file + diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 50ab40abc47..b5aaa7370a3 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -3098,6 +3098,7 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); upgrade_main_savepoint($result, 2010031900); } + if ($result && $oldversion < 2010032400) { // Upgrade all of those using the standardold theme to the use the standard // theme instead @@ -3113,6 +3114,59 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); $DB->execute('UPDATE {user} SET theme=? WHERE theme=?', array('standard', 'standardold')); upgrade_main_savepoint($result, 2010032400); } + + if ($result && $oldversion < 2010032405) { + + /// Define field source to be added to files + $table = new xmldb_table('files'); + + $field = new xmldb_field('source', XMLDB_TYPE_TEXT, 'small', null, null, null, null, 'timemodified'); + + /// Conditionally launch add field source + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + $field = new xmldb_field('author', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'source'); + + /// Conditionally launch add field author + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + $field = new xmldb_field('license', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'author'); + + /// Conditionally launch add field license + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + /// Define table license to be created + $table = new xmldb_table('license'); + + /// Adding fields to table license + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); + $table->add_field('shortname', XMLDB_TYPE_CHAR, '255', null, null, null, null); + $table->add_field('fullname', XMLDB_TYPE_TEXT, 'small', null, null, null, null); + $table->add_field('source', XMLDB_TYPE_CHAR, '255', null, null, null, null); + $table->add_field('enabled', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1'); + $table->add_field('version', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); + + /// Adding keys to table license + $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + + /// Conditionally launch create table for license + if (!$dbman->table_exists($table)) { + $dbman->create_table($table); + } + require_once($CFG->libdir . '/licenselib.php'); + license_manager::install_licenses(); + /// set site default license + set_config('sitedefaultlicense', 'allrightsreserved'); + + /// Main savepoint reached + upgrade_main_savepoint($result, 2010032405); + } return $result; } diff --git a/lib/file/file_info.php b/lib/file/file_info.php index 5fad0a19080..96f1477be13 100644 --- a/lib/file/file_info.php +++ b/lib/file/file_info.php @@ -145,6 +145,30 @@ abstract class file_info { return null; } + /** + * Returns the license type of the file + * @return string license short name or null + */ + public function get_license() { + return null; + } + + /** + * Returns the author name of the file + * @return string author name or null + */ + public function get_author() { + return null; + } + + /** + * Returns the source of the file + * @return string a source url or null + */ + public function get_source() { + return null; + } + /** * Create new directory, may throw exception - make sure * params are valid. diff --git a/lib/file/file_info_stored.php b/lib/file/file_info_stored.php index efb4d95f751..a0068ff619e 100644 --- a/lib/file/file_info_stored.php +++ b/lib/file/file_info_stored.php @@ -175,6 +175,30 @@ class file_info_stored extends file_info { return $this->lf->is_directory(); } + /** + * Returns the license type of the file + * @return string license short name or null + */ + public function get_license() { + return $this->lf->get_license(); + } + + /** + * Returns the author name of the file + * @return string author name or null + */ + public function get_author() { + return $this->lf->get_author(); + } + + /** + * Returns the source of the file + * @return string a source url or null + */ + public function get_source() { + return $this->lf->get_source(); + } + /** * Returns list of children. * @return array of file_info instances diff --git a/lib/file/file_storage.php b/lib/file/file_storage.php index 6e73adab07b..bd464e10a84 100644 --- a/lib/file/file_storage.php +++ b/lib/file/file_storage.php @@ -457,7 +457,7 @@ class file_storage { * @return object stored_file instance of newly created file */ public function create_file_from_storedfile($file_record, $fileorid) { - global $DB; + global $DB, $CFG; if ($fileorid instanceof stored_file) { $fid = $fileorid->get_id(); @@ -514,6 +514,21 @@ class file_storage { } } + if ($key == 'source') { + $value = clean_param($value, PARAM_URL); + } + + if ($key == 'author') { + $value = clean_param($value, PARAM_TEXT); + } + + if ($key == 'license') { + $value = clean_param($value, PARAM_TEXT); + if ($value === '') { + $value = $CFG->sitedefaultlicense; + } + } + $newrecord->$key = $value; } @@ -573,6 +588,8 @@ class file_storage { $filename = array_pop($parts); $file_record->filename = clean_param($filename, PARAM_FILE); } + $source = !empty($file_record->source) ? $file_record->source : $url; + $file_record->source = clean_param($source, PARAM_URL); return $this->create_file_from_string($file_record, $content); } @@ -584,7 +601,7 @@ class file_storage { * @return object stored_file instance */ public function create_file_from_pathname($file_record, $pathname) { - global $DB; + global $DB, $CFG; $file_record = (array)$file_record; //do not modify the submitted record, this cast unlinks objects $file_record = (object)$file_record; // we support arrays too @@ -615,6 +632,13 @@ class file_storage { throw new file_exception('storedfileproblem', 'Invalid file name'); } + $file_record->source = clean_param($file_record->source, PARAM_URL); + $file_record->author = clean_param($file_record->author, PARAM_TEXT); + $file_record->license = clean_param($file_record->license, PARAM_TEXT); + if ($file_record->license === '') { + $file_record->license = $CFG->sitedefaultlicense; + } + $now = time(); $newrecord = new object(); @@ -629,6 +653,9 @@ class file_storage { $newrecord->timemodified = empty($file_record->timemodified) ? $now : $file_record->timemodified; $newrecord->mimetype = empty($file_record->mimetype) ? mimeinfo('type', $file_record->filename) : $file_record->mimetype; $newrecord->userid = empty($file_record->userid) ? null : $file_record->userid; + $newrecord->source = $file_record->source; + $newrecord->author = $file_record->author; + $newrecord->license = $file_record->license; list($newrecord->contenthash, $newrecord->filesize, $newfile) = $this->add_file_to_pool($pathname); @@ -660,7 +687,7 @@ class file_storage { * @return object stored_file instance */ public function create_file_from_string($file_record, $content) { - global $DB; + global $DB, $CFG; $file_record = (array)$file_record; //do not modify the submitted record, this cast unlinks objects $file_record = (object)$file_record; // we support arrays too @@ -691,6 +718,13 @@ class file_storage { throw new file_exception('storedfileproblem', 'Invalid file name'); } + $file_record->source = clean_param($file_record->source, PARAM_URL); + $file_record->author = clean_param($file_record->author, PARAM_TEXT); + $file_record->license = clean_param($file_record->license, PARAM_TEXT); + if ($file_record->license === '') { + $file_record->license = $CFG->sitedefaultlicense; + } + $now = time(); $newrecord = new object(); @@ -706,6 +740,10 @@ class file_storage { $newrecord->mimetype = empty($file_record->mimetype) ? mimeinfo('type', $file_record->filename) : $file_record->mimetype; $newrecord->userid = empty($file_record->userid) ? null : $file_record->userid; + $newrecord->license = empty($file_record->license) ? null : $CFG->sitedefaultlicense; + $newrecord->source = empty($file_record->source) ? null : ''; + $newrecord->author = empty($file_record->author) ? null : ''; + list($newrecord->contenthash, $newrecord->filesize, $newfile) = $this->add_string_to_pool($content); $newrecord->pathnamehash = $this->get_pathname_hash($newrecord->contextid, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->filename); diff --git a/lib/file/stored_file.php b/lib/file/stored_file.php index 6f2437e08db..b16256af6ed 100644 --- a/lib/file/stored_file.php +++ b/lib/file/stored_file.php @@ -372,4 +372,28 @@ class stored_file { public function get_pathnamehash() { return $this->file_record->pathnamehash; } + + /** + * Returns the license type of the file, it is a short name referred from license table + * @return string + */ + public function get_license() { + return $this->file_record->license; + } + + /** + * returns the author name of the file + * @return string + */ + public function get_author() { + return $this->file_record->license; + } + + /** + * Returns the source of the file, usually it is a url + * @return string + */ + public function get_source() { + return $this->file_record->source; + } } diff --git a/lib/flickrlib.php b/lib/flickrlib.php index efde966a06d..9bf65f6b8d9 100755 --- a/lib/flickrlib.php +++ b/lib/flickrlib.php @@ -14,7 +14,7 @@ * Please submit all problems or questions to the Help Forum on my project page: * {@link http://sourceforge.net/forum/forum.php?forum_id=469652} * - * Modified by Dongsheng Cai + * Modified by Dongsheng Cai * ChangeLog: * 1. Remove PEAR HTTP LIB, use curl.class.php (created by myself) * 2. Remove PEAR DB LIB diff --git a/lib/form/filemanager.php b/lib/form/filemanager.php index 895e187e248..076ba1d6540 100644 --- a/lib/form/filemanager.php +++ b/lib/form/filemanager.php @@ -31,7 +31,7 @@ require_once($CFG->dirroot.'/repository/lib.php'); class MoodleQuickForm_filemanager extends HTML_QuickForm_element { public $_helpbutton = ''; - protected $_options = array('mainfile'=>'', 'subdirs'=>1, 'maxbytes'=>0, 'maxfiles'=>-1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL); + protected $_options = array('mainfile'=>'', 'subdirs'=>1, 'maxbytes'=>-1, 'maxfiles'=>-1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL); function MoodleQuickForm_filemanager($elementName=null, $elementLabel=null, $attributes=null, $options=null) { global $CFG, $PAGE; diff --git a/lib/licenselib.php b/lib/licenselib.php new file mode 100644 index 00000000000..0d2f8646fba --- /dev/null +++ b/lib/licenselib.php @@ -0,0 +1,182 @@ +. + + +/** + * A namespace contains license specific functions + * + * @since 2.0 + * @package moodlecore + * @subpackage moodlecore + * @copyright 2010 Dongsheng Cai + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +class license_manager { + /** + * Adding a new license type + * @param object $license { + * shortname => string a shortname of license, will be refered by files table[required] + * fullname => string the fullname of the license [required] + * source => string the homepage of the license type[required] + * enabled => int is it enabled? + * version => int a version number used by moodle [required] + * } + */ + static public function add($license) { + global $DB; + if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) { + // record exists + if ($record->version < $license->version) { + // update license record + $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; + } + } + } + + /** + * Get license record by shortname + * @param mixed $param the shortname of license, or an array + * @return object + */ + static public function get($param = null) { + 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; + } + } + } + + /** + * Enable a license + * @param string $license the shortname of license + * @return boolean + */ + 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; + } + } + + /** + * Disable a license + * @param string $license the shortname of license + * @return boolean + */ + 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; + } + } + + /** + * Install moodle build-in licenses + */ + static public function install_licenses() { + $license = new stdclass; + + $license->shortname = 'allrightsreserved'; + $license->fullname = 'All rights reserved'; + $license->source = 'http://en.wikipedia.org/wiki/All_rights_reserved'; + $license->enabled = 1; + $license->version = '2010032500'; + self::add($license); + + $license->shortname = 'public'; + $license->fullname = 'Public Domain'; + $license->source = 'http://creativecommons.org/licenses/publicdomain/'; + $license->enabled = 1; + $license->version = '2010032500'; + 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'; + 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'; + 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'; + 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'; + 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'; + 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'; + self::add($license); + } +} diff --git a/lib/outputrequirementslib.php b/lib/outputrequirementslib.php index 557de73c2cb..fba2e5b3ee8 100644 --- a/lib/outputrequirementslib.php +++ b/lib/outputrequirementslib.php @@ -359,7 +359,7 @@ class page_requirements_manager { array('saving', 'repository'), array('search', 'repository'), array('searching', 'repository'), array('size', 'repository'), array('submit', 'repository'), array('sync', 'repository'), array('title', 'repository'), array('upload', 'repository'), array('uploading', 'repository'), array('xhtmlerror', 'repository'), - array('xhtml', 'quiz'), array('cancel'))); + array('xhtml', 'quiz'), array('cancel'), array('chooselicense', 'repository'), array('author', 'repository'))); break; case 'core_comment': $module = array('name' => 'core_comment', diff --git a/lib/setup.php b/lib/setup.php index 8c16a075ce5..b77c259ad0a 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -260,6 +260,10 @@ if (!isset($CFG->prefix)) { // Just in case it isn't defined in config.php $CFG->prefix = ''; } +if (empty($CFG->sitedefaultlicense)) { + $CFG->sitedefaultlicense = 'allrightsreserved'; +} + //point pear include path to moodles lib/pear so that includes and requires will search there for files before anywhere else //the problem is that we need specific version of quickforms and hacked excel files :-( ini_set('include_path', $CFG->libdir.'/pear' . PATH_SEPARATOR . ini_get('include_path')); diff --git a/repository/alfresco/repository.class.php b/repository/alfresco/repository.class.php index d1758a9ff4c..9a59fc02e17 100755 --- a/repository/alfresco/repository.class.php +++ b/repository/alfresco/repository.class.php @@ -199,7 +199,7 @@ class repository_alfresco extends repository { $fp = fopen($path, 'w'); $c = new curl; $c->download(array(array('url'=>$url, 'file'=>$fp))); - return array($path, $url); + return array('path'=>$path, 'url'=>$url); } public function print_search($client_id) { diff --git a/repository/filepicker.js b/repository/filepicker.js index 8569e98a9b5..34843b86a69 100644 --- a/repository/filepicker.js +++ b/repository/filepicker.js @@ -117,7 +117,14 @@ M.core_filepicker.init = function(Y, options) { } catch(e) { alert(M.str.repository.invalidjson+' - |'+source+'| -'+stripHTML(o.responseText)); } - args.callback(id,data,p); + // error checking + if (data.e) { + var panel_id = '#panel-'+data.client_id; + Y.one(panel_id).set('innerHTML', 'ERROR: '+data.e); + return; + } else { + args.callback(id,data,p); + } } }, arguments: { @@ -280,7 +287,6 @@ M.core_filepicker.init = function(Y, options) { if(node.children) { y_file.on('click', function(e, p) { if(dynload) { - console.info(p); var params = {'path':p.path}; scope.list(params); }else{ @@ -296,6 +302,8 @@ M.core_filepicker.init = function(Y, options) { fileinfo['title'] = list[k].title; fileinfo['source'] = list[k].source; fileinfo['thumbnail'] = list[k].thumbnail; + fileinfo['haslicense'] = list[k].haslicense?true:false; + fileinfo['hasauthor'] = list[k].hasauthor?true:false; y_title.on('click', function(e, args) { this.select_file(args); }, this, fileinfo); @@ -344,6 +352,25 @@ M.core_filepicker.init = function(Y, options) { if (this.options.externallink && this.options.env == 'editor') { html += ''+M.str.repository.linkexternal+'

'; } + + if (!args.hasauthor) { + // the author of the file + html += '

'; + html += ''; + html += '

'; + } + + if (!args.haslicense) { + // the license of the file + var licenses = this.options.licenses; + html += '

'; + html += '

'; + } + html += '

'; html += ''; html += '

'; @@ -360,6 +387,14 @@ M.core_filepicker.init = function(Y, options) { var title = Y.one('#newname-'+client_id).get('value'); var filesource = Y.one('#filesource-'+client_id).get('value'); var params = {'title':title, 'source':filesource, 'savepath': this.options.savepath}; + var license = Y.one('#select-license-'+client_id); + if (license) { + params['license'] = license.get('value'); + } + var author = Y.one('#text-author-'+client_id); + if (author) { + params['author'] = author.get('value'); + } if (this.options.env == 'editor') { var linkexternal = Y.one('#linkexternal-'+client_id).get('checked'); @@ -814,9 +849,26 @@ M.core_filepicker.init = function(Y, options) { var id = data.upload.id+'_'+client_id; var str = '
'; str += '
'; - str += ''; - str += ''; - str += ''; + str += ''; + str += ''; + str += ''; + str += ''; + str += ''; + str += ''; + str += ''; + str += ''; + str += ''; + str += ''; + str += '
'; + str += ''; + str += '
'+M.str.repository.chooselicense+': '; + var licenses = this.options.licenses; + str += ''; + str += '
'; str += ''; str += '
'; str += '
'; diff --git a/repository/filesystem/repository.class.php b/repository/filesystem/repository.class.php index 14f865a71e7..dd937f0d3f2 100644 --- a/repository/filesystem/repository.class.php +++ b/repository/filesystem/repository.class.php @@ -123,7 +123,7 @@ class repository_filesystem extends repository { // this is a hack to prevent move_to_file deleteing files // in local repository $CFG->repository_no_delete = true; - return array($file, ''); + return array('path'=>$file); } public function logout() { diff --git a/repository/flickr/repository.class.php b/repository/flickr/repository.class.php index 4df4f844319..e7bbcf64a99 100755 --- a/repository/flickr/repository.class.php +++ b/repository/flickr/repository.class.php @@ -267,7 +267,7 @@ class repository_flickr extends repository { $c->download(array( array('url'=>$url, 'file'=>$fp) )); - return array($path, $url); + return array('path'=>$path, 'url'=>$url); } /** diff --git a/repository/flickr_public/repository.class.php b/repository/flickr_public/repository.class.php index 07f891fa2dd..1efec7c9774 100644 --- a/repository/flickr_public/repository.class.php +++ b/repository/flickr_public/repository.class.php @@ -15,10 +15,6 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . - -require_once($CFG->libdir.'/flickrlib.php'); -require_once(dirname(__FILE__) . '/image.php'); - /** * repository_flickr_public class * This one is used to create public repository @@ -32,6 +28,9 @@ require_once(dirname(__FILE__) . '/image.php'); * @author Dongsheng Cai * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ + +require_once($CFG->libdir.'/flickrlib.php'); + class repository_flickr_public extends repository { private $flickr; public $photos; @@ -205,6 +204,19 @@ class repository_flickr_public extends repository { return $this->print_login(); } + public function license4moodle ($license_id) { + $license = array( + '1' => 'cc-nc-sa', + '2' => 'cc-nc', + '3' => 'cc-nc-nd', + '4' => 'cc', + '5' => 'cc-sa', + '6' => 'cc-nd', + '7' => 'allrightsreserved' + ); + return $license[$license_id]; + } + /** * search images on flickr * @@ -343,9 +355,17 @@ class repository_flickr_public extends repository { // append file extension $p['title'] .= $format; } - $ret['list'][] = array('title'=>$p['title'], 'source'=>$p['id'], - 'id'=>$p['id'],'thumbnail'=>$this->flickr->buildPhotoURL($p, 'Square'), - 'date'=>'', 'size'=>'unknown', 'url'=>'http://www.flickr.com/photos/'.$p['owner'].'/'.$p['id']); + $ret['list'][] = array( + 'title'=>$p['title'], + 'source'=>$p['id'], + 'id'=>$p['id'], + 'thumbnail'=>$this->flickr->buildPhotoURL($p, 'Square'), + 'date'=>'', + 'size'=>'unknown', + 'url'=>'http://www.flickr.com/photos/'.$p['owner'].'/'.$p['id'], + 'haslicense'=>true, + 'hasauthor'=>true + ); } } return $ret; @@ -389,30 +409,28 @@ class repository_flickr_public extends repository { */ public function get_file($photo_id, $file = '') { global $CFG; + $info = $this->flickr->photos_getInfo($photo_id); $result = $this->flickr->photos_getSizes($photo_id); + // download link + $source = ''; + // flickr photo page $url = ''; if (!empty($result[4])) { - $url = $result[4]['source']; + $source = $result[4]['source']; + $url = $result[4]['url']; } elseif(!empty($result[3])) { - $url = $result[3]['source']; + $source = $result[3]['source']; + $url = $result[3]['url']; } elseif(!empty($result[2])) { - $url = $result[2]['source']; + $source = $result[2]['source']; + $url = $result[2]['url']; } $path = $this->prepare_file($file); $fp = fopen($path, 'w'); $c = new curl; - $c->download(array(array('url'=>$url, 'file'=>$fp))); + $c->download(array(array('url'=>$source, 'file'=>$fp))); - $watermark = get_config('flickr_public', 'watermark'); - if ($watermark === 'on') { - $img = new moodle_image($path); - $pathinfo = pathinfo($path); - $newpath = $pathinfo['dirname'] . '/wm_' . $pathinfo['basename']; - $img->watermark($url, array(10,10), array('ttf'=>true, 'fontsize'=>9))->saveas($newpath); - unlink($path); - $path = $newpath; - } - return array($path, $url); + return array('path'=>$path, 'url'=>$url, 'author'=>$info['owner']['realname'], 'license'=>$this->license4moodle($info['license'])); } /** @@ -443,12 +461,9 @@ class repository_flickr_public extends repository { } $strrequired = get_string('required'); - $mform->addElement('checkbox', 'watermark', get_string('watermark', 'repository_flickr_public')); - $mform->addElement('text', 'api_key', get_string('apikey', 'repository_flickr_public'), array('value'=>$api_key,'size' => '40')); $mform->addRule('api_key', $strrequired, 'required', null, 'client'); - $mform->addElement('static', null, '', get_string('information','repository_flickr_public')); } @@ -457,7 +472,7 @@ class repository_flickr_public extends repository { * @return array */ public static function get_type_option_names() { - return array('api_key', 'watermark'); + return array('api_key'); } /** diff --git a/repository/googledocs/repository.class.php b/repository/googledocs/repository.class.php index a008055b83f..1dc8bd3f9f6 100644 --- a/repository/googledocs/repository.class.php +++ b/repository/googledocs/repository.class.php @@ -120,7 +120,7 @@ class repository_googledocs extends repository { $gdocs = new google_docs(new google_authsub($this->subauthtoken)); $gdocs->download_file($url, $fp); - return array($path, $url); + return array('path'=>$path, 'url'=>$url); } public function supported_filetypes() { diff --git a/repository/lib.php b/repository/lib.php index a1c74893576..374668b659a 100644 --- a/repository/lib.php +++ b/repository/lib.php @@ -1171,7 +1171,7 @@ abstract class repository { $fp = fopen($path, 'w'); $c = new curl; $c->download(array(array('url'=>$url, 'file'=>$fp))); - return array($path, $url); + return array('path'=>$path, 'url'=>$url); } /** @@ -1766,13 +1766,20 @@ final class repository_type_form extends moodleform { */ function initialise_filepicker($args) { global $CFG, $USER, $PAGE, $OUTPUT; + $return = new stdclass; + require_once($CFG->libdir . '/licenselib.php'); + + $licenses = license_manager::get(array('enabled'=>1)); + $return->licenses = $licenses; + + $return->author = fullname($USER); + $ft = new filetype_parser(); if (empty($args->context)) { $context = $PAGE->context; } else { $context = $args->context; } - $return = new stdclass; $user_context = get_context_instance(CONTEXT_USER, $USER->id); diff --git a/repository/mahara/repository.class.php b/repository/mahara/repository.class.php index cfa4229d30b..458b1037653 100644 --- a/repository/mahara/repository.class.php +++ b/repository/mahara/repository.class.php @@ -251,7 +251,7 @@ class repository_mahara extends repository { fwrite($fp,$content); fclose($fp); - return array($path, ''); + return array('path'=>$path); } diff --git a/repository/remotemoodle/repository.class.php b/repository/remotemoodle/repository.class.php index f644dd6e1d2..2615eb9bb55 100644 --- a/repository/remotemoodle/repository.class.php +++ b/repository/remotemoodle/repository.class.php @@ -255,7 +255,7 @@ class repository_remotemoodle extends repository { fwrite($fp,$content); fclose($fp); - return array($path, ''); + return array('path'=>$path); } diff --git a/repository/repository_ajax.php b/repository/repository_ajax.php index 61a7f5fd682..8a4a206828a 100755 --- a/repository/repository_ajax.php +++ b/repository/repository_ajax.php @@ -39,6 +39,8 @@ $callback = optional_param('callback', '', PARAM_CLEANHTML); $client_id = optional_param('client_id', '', PARAM_RAW); // client ID $contextid = optional_param('ctx_id', SYSCONTEXTID, PARAM_INT); // context ID $env = optional_param('env', 'filepicker', PARAM_ALPHA); // opened in editor or moodleform +$license = optional_param('license', $CFG->sitedefaultlicense, PARAM_TEXT); +$author = optional_param('author', '', PARAM_TEXT); $source = optional_param('source', '', PARAM_RAW); // file to download $itemid = optional_param('itemid', 0, PARAM_INT); $page = optional_param('page', '', PARAM_RAW); // page @@ -253,12 +255,12 @@ switch ($action) { } // get the file location - list($thefile, $url) = $repo->get_file($source, $saveas_filename); - if ($thefile === false) { + $file = $repo->get_file($source, $saveas_filename); + if ($file['path'] === false) { $err->e = get_string('cannotdownload', 'repository'); die(json_encode($err)); } - if (($maxbytes!==-1) && (filesize($thefile) > $maxbytes)) { + if (($maxbytes!==-1) && (filesize($file['path']) > $maxbytes)) { throw new file_exception('maxbytes'); } @@ -267,11 +269,20 @@ switch ($action) { $record->filename = $saveas_filename; $record->filearea = $saveas_filearea; $record->itemid = $itemid; - $record->license = ''; - $record->author = ''; - $record->source = $url; - $info = repository::move_to_filepool($thefile, $record); + if (!empty($file['license'])) { + $record->license = $file['license']; + } else { + $record->license = $license; + } + if (!empty($file['author'])) { + $record->author = $file['author']; + } else { + $record->author = $author; + } + $record->source = !empty($file['url']) ? $file['url'] : ''; + + $info = repository::move_to_filepool($file['path'], $record); if (empty($info)) { $info['e'] = get_string('error', 'moodle'); } @@ -286,7 +297,7 @@ switch ($action) { break; case 'upload': try { - $result = $repo->upload($maxbytes); + $result = $repo->upload(); $result['client_id'] = $client_id; echo json_encode($result); } catch (Exception $e){ diff --git a/repository/s3/repository.class.php b/repository/s3/repository.class.php index 0f3042e2208..c287dd57893 100644 --- a/repository/s3/repository.class.php +++ b/repository/s3/repository.class.php @@ -111,7 +111,7 @@ class repository_s3 extends repository { $filename = $arr[1]; $path = $this->prepare_file($file); $this->s->getObject($bucket, $filename, $path); - return array($path, ''); + return array('path'=>$path); } /** diff --git a/repository/upload/repository.class.php b/repository/upload/repository.class.php index b4fa21b10da..39b03179a05 100755 --- a/repository/upload/repository.class.php +++ b/repository/upload/repository.class.php @@ -36,8 +36,12 @@ class repository_upload extends repository { * @param array $options */ public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array()){ + global $CFG; parent::__construct($repositoryid, $context, $options); $this->itemid = optional_param('itemid', '', PARAM_INT); + $this->license = optional_param('license', $CFG->sitedefaultlicense, PARAM_TEXT); + $this->author = optional_param('author', '', PARAM_TEXT); + $this->filearea = optional_param('filearea', 'user_draft', PARAM_TEXT); $this->filepath = urldecode(optional_param('savepath', '/', PARAM_PATH)); } @@ -57,7 +61,13 @@ class repository_upload extends repository { */ public function upload() { try { - $this->info = $this->upload_to_filepool('repo_upload_file', 'user_draft', $this->filepath, $this->itemid); + $record = new stdclass; + $record->filearea = $this->filearea;; + $record->filepath = $this->filepath; + $record->itemid = $this->itemid; + $record->license = $this->license; + $record->author = $this->author; + $this->info = $this->upload_to_filepool('repo_upload_file', $record); } catch(Exception $e) { throw $e; } @@ -102,12 +112,15 @@ class repository_upload extends repository { * @param bool $override override file if exists * @return mixed stored_file object or false if error; may throw exception if duplicate found */ - public function upload_to_filepool($elname, $filearea='user_draft', $filepath='/', $itemid='', $filename = '', $override = true) { + public function upload_to_filepool($elname, $record, $override = true) { global $USER; + $context = get_context_instance(CONTEXT_USER, $USER->id); + $fs = get_file_storage(); + $browser = get_file_browser(); - if ($filepath !== '/') { - $filepath = trim($filepath, '/'); - $filepath = '/'.$filepath.'/'; + if ($record->filepath !== '/') { + $record->filepath = trim($record->filepath, '/'); + $record->filepath = '/'.$record->filepath.'/'; } if (!isset($_FILES[$elname])) { @@ -118,18 +131,15 @@ class repository_upload extends repository { throw new moodle_exception('maxbytes'); } - if (!$filename) { - $filename = $_FILES[$elname]['name']; + if (empty($record->filename)) { + $record->filename = $_FILES[$elname]['name']; } - $context = get_context_instance(CONTEXT_USER, $USER->id); - if (empty($itemid)) { - $itemid = (int)substr(hexdec(uniqid()), 0, 9)+rand(1,100); + if (empty($record->itemid)) { + $record->itemid = 0; } - $fs = get_file_storage(); - $browser = get_file_browser(); - if ($file = $fs->get_file($context->id, $filearea, $itemid, $filepath, $filename)) { + if ($file = $fs->get_file($context->id, $record->filearea, $record->itemid, $record->filepath, $record->filename)) { if ($override) { $file->delete(); } else { @@ -137,26 +147,22 @@ class repository_upload extends repository { } } - $file_record = new object(); - $file_record->contextid = $context->id; - $file_record->filearea = $filearea; - $file_record->itemid = $itemid; - $file_record->filepath = $filepath; - $file_record->filename = $filename; - $file_record->userid = $USER->id; + $record->contextid = $context->id; + $record->userid = $USER->id; + $record->source = ''; try { - $file = $fs->create_file_from_pathname($file_record, $_FILES[$elname]['tmp_name']); + $file = $fs->create_file_from_pathname($record, $_FILES[$elname]['tmp_name']); } catch (Exception $e) { $e->obj = $_FILES[$elname]; throw $e; } + $info = $browser->get_file_info($context, $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename()); return array( 'url'=>$info->get_url(), - 'id'=>$itemid, + 'id'=>$record->itemid, 'file'=>$file->get_filename() ); } } - diff --git a/repository/url/repository.class.php b/repository/url/repository.class.php index 2b335e7109d..2feaa977ba4 100755 --- a/repository/url/repository.class.php +++ b/repository/url/repository.class.php @@ -53,7 +53,7 @@ class repository_url extends repository { $fp = fopen($path, 'w'); $c = new curl; $c->download(array(array('url'=>$url, 'file'=>$fp))); - return array($path, $url); + return array('path'=>$path, 'url'=>$url); } public function check_login() { diff --git a/repository/webdav/repository.class.php b/repository/webdav/repository.class.php index f9ae727b8c7..fd7b8a07c55 100644 --- a/repository/webdav/repository.class.php +++ b/repository/webdav/repository.class.php @@ -76,7 +76,7 @@ class repository_webdav extends repository { $this->wd->get($url, $buffer); $fp = fopen($path, 'wb'); fwrite($fp, $buffer); - return array($path, ''); + return array('path'=>$path); } public function global_search() { return false; diff --git a/version.php b/version.php index caa1b8f58c7..3e4c0b48de7 100644 --- a/version.php +++ b/version.php @@ -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 = 2010032400; // YYYYMMDD = date of the last version bump + $version = 2010032405; // YYYYMMDD = date of the last version bump // XX = daily increments $release = '2.0 dev (Build: 20100329)'; // Human-friendly version name