lib MDL-19236 added phpdocs and copyrights

This commit is contained in:
samhemelryk 2009-05-25 08:27:25 +00:00
parent 5fc45c3ff4
commit ba21c9d440
7 changed files with 899 additions and 352 deletions

View File

@ -35,6 +35,9 @@ require_once("$CFG->libdir/packer/zip_packer.php");
/**
* Given a physical path to a file, returns the URL through which it can be reached in Moodle.
*
* @global object
* @global string
* @param string $path Physical path to a file
* @param array $options associative array of GET variables to append to the URL
* @param string $type (questionfile|rssfile|user|usergroup|httpscoursefile|coursefile)
@ -104,7 +107,9 @@ function get_file_url($path, $options=null, $type='coursefile') {
/**
* Encodes file serving url
* TODO: decide if we really need this
*
* @todo decide if we really need this
* @global object
* @param string $urlbase
* @param string $path /filearea/itemid/dir/dir/file.exe
* @param bool $forcedownload
@ -139,6 +144,7 @@ function file_encode_url($urlbase, $path, $forcedownload=false, $https=false) {
/**
* Prepares standardised text field fro editing with Editor formslib element
*
* @param object $data $database entry field
* @param string $field name of data field
* @param array $options various options
@ -206,6 +212,7 @@ function file_prepare_standard_editor($data, $field, array $options, $context=nu
/**
* Prepares editing with File manager formslib element
*
* @param object $data $database entry field
* @param string $field name of data field
* @param array $options various options
@ -252,6 +259,7 @@ function file_postupdate_standard_editor($data, $field, array $options, $context
/**
* Saves text and files modified by Editor formslib element
*
* @param object $data $database entry field
* @param string $field name of data field
* @param array $options various options
@ -281,6 +289,7 @@ function file_prepare_standard_filemanager($data, $field, array $options, $conte
/**
* Saves files modified by File manager formslib element
*
* @param object $data $database entry field
* @param string $field name of data field
* @param array $options various options
@ -319,6 +328,9 @@ function file_postupdate_standard_filemanager($data, $field, array $options, $co
}
/**
*
* @global object
* @global object
* @return int a random but available draft itemid that can be used to create a new draft
* file area.
*/
@ -346,6 +358,9 @@ function file_get_unused_draft_itemid() {
* Initialise a draft file area from a real one by copying the files. A draft
* area will be created if one does not already exist. Normally you should
* get $draftitemid by calling file_get_submitted_draft_itemid('elementname');
*
* @global object
* @global object
* @param int &$draftitemid the id of the draft area to use, or 0 to create a new one, in which case this parameter is updated.
* @param integer $contextid This parameter and the next two identify the file area to copy files from.
* @param string $filearea helps indentify the file area.
@ -394,6 +409,8 @@ function file_prepare_draft_area(&$draftitemid, $contextid, $filearea, $itemid,
/**
* Convert encoded URLs in $text from the @@PLUGINFILE@@/... form to an actual URL.
*
* @global object
* @param string $text The content that may contain ULRs in need of rewriting.
* @param string $file The script that should be used to serve these files. pluginfile.php, draftfile.php, etc.
* @param integer $contextid This parameter and the next two identify the file area to use.
@ -429,6 +446,9 @@ function file_rewrite_pluginfile_urls($text, $file, $contextid, $filearea, $item
/**
* Returns information about files in a draft area.
*
* @global object
* @global object
* @param integer $draftitemid the draft area item id.
* @return array with the following entries:
* 'filecount' => number of files in the draft area.
@ -451,6 +471,7 @@ function file_get_draft_area_info($draftitemid) {
/**
* Returns draft area itemid for a given element.
*
* @param string $elname name of formlib editor element, or a hidden form field that stores the draft area item id, etc.
* @return inteter the itemid, or 0 if there is not one yet.
*/
@ -468,12 +489,15 @@ function file_get_submitted_draft_itemid($elname) {
/**
* Saves files from a draft file area to a real one (merging the list of files).
* Can rewrite URLs in some content at the same time if desired.
* @param int $draftitemid the id of the draft area to use. Normally obtained
*
* @global object
* @global object
* @param integer $draftitemid the id of the draft area to use. Normally obtained
* from file_get_submitted_draft_itemid('elementname') or similar.
* @param integer $contextid This parameter and the next two identify the file area to save to.
* @param string $filearea indentifies the file area.
* @param integer $itemid helps identifies the file area.
* @param array $optionss area options (subdirs=>false, maxfiles=-1, maxbytes=0)
* @param array $options area options (subdirs=>false, maxfiles=-1, maxbytes=0)
* @param string $text some html content that needs to have embedded links rewritten
* to the @@PLUGINFILE@@ form for saving in the database.
* @param boolean $forcehttps force https urls.
@ -598,8 +622,9 @@ function file_save_draft_area_files($draftitemid, $contextid, $filearea, $itemid
/**
* Returns description of upload error
*
* @param int $errorcode found in $_FILES['filename.ext']['error']
* @return error description string, '' if ok
* @return string error description string, '' if ok
*/
function file_get_upload_error($errorcode) {
@ -649,6 +674,7 @@ function file_get_upload_error($errorcode) {
* Fetches content of file from Internet (using proxy if defined). Uses cURL extension if present.
* Due to security concerns only downloads from http(s) sources are supported.
*
* @global object
* @param string $url file url starting with http(s)://
* @param array $headers http headers, null if none. If set, should be an
* associative array of header name => value pairs.
@ -839,7 +865,7 @@ function download_file_content($url, $headers=null, $postdata=null, $fullrespons
}
/**
* @return List of information about file types based on extensions.
* @return array List of information about file types based on extensions.
* Associative array of extension (lower-case) to associative array
* from 'element name' to data. Current element names are 'type' and 'icon'.
* Unknown types should use the 'xxx' entry which includes defaults.
@ -1014,6 +1040,8 @@ function get_mimetypes_array() {
* Obtains information about a filetype based on its extension. Will
* use a default if no information is present about that particular
* extension.
*
* @global object
* @param string $element Desired information (usually 'icon'
* for icon filename or 'type' for MIME type)
* @param string $filename Filename we're looking up
@ -1054,6 +1082,7 @@ function mimeinfo($element, $filename) {
/**
* Obtains information about a filetype based on the MIME type rather than
* the other way around.
*
* @param string $element Desired information (usually 'icon')
* @param string $mimetype MIME type we're looking up
* @return string Requested piece of information from array
@ -1074,6 +1103,7 @@ function mimeinfo_from_type($element, $mimetype) {
/**
* Get information about a filetype based on the icon file.
*
* @param string $element Desired information (usually 'icon')
* @param string $icon Icon file path.
* @param boolean $all return all matching entries (defaults to false - last match)
@ -1103,6 +1133,7 @@ function mimeinfo_from_icon($element, $icon, $all=false) {
/**
* Obtains descriptions for file types (e.g. 'Microsoft Word document') from the
* mimetypes.php language file.
*
* @param string $mimetype MIME type (can be obtained using the mimeinfo function)
* @param bool $capitalise If true, capitalises first character of result
* @return string Text description
@ -1122,6 +1153,7 @@ function get_mimetype_description($mimetype,$capitalise=false) {
/**
* Reprot file is not found or not accessible
*
* @return does not return, terminates script
*/
function send_file_not_found() {
@ -1133,6 +1165,8 @@ function send_file_not_found() {
/**
* Handles the sending of temporary file to user, download is forced.
* File is deleted after abort or succesful sending.
*
* @global object
* @param string $path path to file, preferably from moodledata/temp/something; or content of file itself
* @param string $filename proposed file name when saving file
* @param bool $path is content of file
@ -1200,6 +1234,10 @@ function send_temp_file_finished($path) {
/**
* Handles the sending of file data to the user's browser, including support for
* byteranges etc.
*
* @global object
* @global object
* @global object
* @param string $path Path of file on disk (including real filename), or actual content of file as string
* @param string $filename Filename to send
* @param int $lifetime Number of seconds before the file should expire from caches (default 24 hours)
@ -1414,17 +1452,20 @@ function send_file($path, $filename, $lifetime = 'default' , $filter=0, $pathiss
/**
* Handles the sending of file data to the user's browser, including support for
* byteranges etc.
*
* @global object
* @global object
* @global object
* @param object $stored_file local file object
* @param int $lifetime Number of seconds before the file should expire from caches (default 24 hours)
* @param int $filter 0 (default)=no filtering, 1=all files, 2=html files only
* @param bool $forcedownload If true (default false), forces download of file rather than view in browser/plugin
* @param string $filename Override filename
* @param string $mimetype Include to specify the MIME type; leave blank to have it guess the type from $filename
* @param bool $dontdie - return control to caller afterwards. this is not recommended and only used for cleanup tasks.
* if this is passed as true, ignore_user_abort is called. if you don't want your processing to continue on cancel,
* you must detect this case when control is returned using connection_aborted. Please not that session is closed
* and should not be reopened.
* @return no return or void, script execution stopped unless $dontdie is true
* @return void no return or void, script execution stopped unless $dontdie is true
*/
function send_stored_file($stored_file, $lifetime=86400 , $filter=0, $forcedownload=false, $filename=null, $dontdie=false) {
global $CFG, $COURSE, $SESSION;
@ -1594,6 +1635,16 @@ function send_stored_file($stored_file, $lifetime=86400 , $filter=0, $forcedownl
die; //no more chars to output!!!
}
/**
* Retreievs an array of records from a CSV file and places
* them into a given table structure
*
* @global object
* @global object
* @param string $file The path to a CSV file
* @param string $table The table to retrieve columns from
* @return bool|array Returns an array of CSV records or false
*/
function get_records_csv($file, $table) {
global $CFG, $DB;
@ -1634,6 +1685,15 @@ function get_records_csv($file, $table) {
return $rows;
}
/**
*
* @global object
* @global object
* @param string $file The file to put the CSV content into
* @param array $records An array of records to write to a CSV file
* @param string $table The table to get columns from
* @return bool success
*/
function put_records_csv($file, $records, $table = NULL) {
global $CFG, $DB;
@ -1701,6 +1761,7 @@ function put_records_csv($file, $records, $table = NULL) {
* considered an error.
*
* @param $location the path to remove.
* @return bool
*/
function fulldelete($location) {
if (is_dir($location)) {
@ -1734,6 +1795,11 @@ function fulldelete($location) {
/**
* Send requested byterange of file.
*
* @param object $handle A file handle
* @param string $mimetype The mimetype for the output
* @param array $ranges An array of ranges to send
* @param string $filesize The size of the content if only one range is used
*/
function byteserving_send_file($handle, $mimetype, $ranges, $filesize) {
$chunksize = 1*(1024*1024); // 1MB chunks - must be less than 2MB!
@ -1791,8 +1857,10 @@ function byteserving_send_file($handle, $mimetype, $ranges, $filesize) {
/**
* add includes (js and css) into uploaded files
* before returning them, useful for themes and utf.js includes
* @param string text - text to search and replace
* @return string - text with added head includes
*
* @global object
* @param string $text text to search and replace
* @return string text with added head includes
*/
function file_modify_html_header($text) {
// first look for <head> tag
@ -1842,7 +1910,7 @@ function file_modify_html_header($text) {
* RESTful cURL class
*
* This is a wrapper class for curl, it is quite easy to use:
*
* <code>
* $c = new curl;
* // enable cache
* $c = new curl(array('cache'=>true));
@ -1857,28 +1925,40 @@ function file_modify_html_header($text) {
* $html = $c->post('http://example.com/', array('q'=>'words', 'name'=>'moodle'));
* // HTTP PUT Method
* $html = $c->put('http://example.com/', array('file'=>'/var/www/test.txt');
* </code>
*
* @package moodlecore
* @author Dongsheng Cai <dongsheng@cvs.moodle.org>
* @version 0.4 dev
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
class curl {
/** @var bool */
public $cache = false;
public $proxy = false;
/** @var string */
public $version = '0.4 dev';
/** @var array */
public $response = array();
public $header = array();
/** @var string */
public $info;
public $error;
/** @var array */
private $options;
/** @var string */
private $proxy_host = '';
private $proxy_auth = '';
private $proxy_type = '';
/** @var bool */
private $debug = false;
private $cookie = false;
/**
* @global object
* @param array $options
*/
public function __construct($options = array()){
global $CFG;
if (!function_exists('curl_init')) {
@ -1933,6 +2013,9 @@ class curl {
$this->proxy = array('proxy'=>$this->proxy_host);
}
}
/**
* Resets the CURL options that have already been set
*/
public function resetopt(){
$this->options = array();
$this->options['CURLOPT_USERAGENT'] = 'MoodleBot/1.0';
@ -1958,10 +2041,6 @@ class curl {
/**
* Reset Cookie
*
* @param array $options If array is null, this function will
* reset the options to default value.
*
*/
public function resetcookie() {
if (!empty($this->cookie)) {
@ -2032,6 +2111,9 @@ class curl {
* private callback function
* Formatting HTTP Response Header
*
* @param mixed $ch Apparently not used
* @param string $header
* @return int The strlen of the header
*/
private function formatHeader($ch, $header)
{
@ -2058,6 +2140,10 @@ class curl {
/**
* Set options for individual curl instance
*
* @param object $curl A curl handle
* @param array $options
* @return object The curl handle
*/
private function apply_opt($curl, $options) {
// Clean up
@ -2102,13 +2188,22 @@ class curl {
}
return $curl;
}
/*
/**
* Download multiple files in parallel
*
* Calls {@link multi()} with specific download headers
*
* <code>
* $c = new curl;
* $c->download(array(
* array('url'=>'http://localhost/', 'file'=>fopen('a', 'wb')),
* array('url'=>'http://localhost/20/', 'file'=>fopen('b', 'wb'))
* ));
* </code>
*
* @param array $requests An array of files to request
* @param array $options An array of options to set
* @return array An array of results
*/
public function download($requests, $options = array()) {
$options['CURLOPT_BINARYTRANSFER'] = 1;
@ -2118,6 +2213,10 @@ class curl {
/*
* Mulit HTTP Requests
* This function could run multi-requests in parallel.
*
* @param array $requests An array of files to request
* @param array $options An array of options to set
* @return array An array of results
*/
protected function multi($requests, $options = array()) {
$count = count($requests);
@ -2150,6 +2249,10 @@ class curl {
}
/**
* Single HTTP Request
*
* @param string $url The URL to request
* @param array $options
* @return bool
*/
protected function request($url, $options = array()){
// create curl instance
@ -2188,6 +2291,12 @@ class curl {
/**
* HTTP HEAD method
*
* @see request()
*
* @param string $url
* @param array $options
* @return bool
*/
public function head($url, $options = array()){
$options['CURLOPT_HTTPGET'] = 0;
@ -2198,6 +2307,11 @@ class curl {
/**
* HTTP POST method
*
* @param string $url
* @param array|string $params
* @param array $options
* @return bool
*/
public function post($url, $params = '', $options = array()){
$options['CURLOPT_POST'] = 1;
@ -2221,6 +2335,11 @@ class curl {
/**
* HTTP GET method
*
* @param string $url
* @param array $params
* @param array $options
* @return bool
*/
public function get($url, $params = array(), $options = array()){
$options['CURLOPT_HTTPGET'] = 1;
@ -2234,6 +2353,11 @@ class curl {
/**
* HTTP PUT method
*
* @param string $url
* @param array $params
* @param array $options
* @return bool
*/
public function put($url, $params = array(), $options = array()){
$file = $params['file'];
@ -2255,6 +2379,11 @@ class curl {
/**
* HTTP DELETE method
*
* @param string $url
* @param array $params
* @param array $options
* @return bool
*/
public function delete($url, $param = array(), $options = array()){
$options['CURLOPT_CUSTOMREQUEST'] = 'DELETE';
@ -2266,6 +2395,10 @@ class curl {
}
/**
* HTTP TRACE method
*
* @param string $url
* @param array $options
* @return bool
*/
public function trace($url, $options = array()){
$options['CURLOPT_CUSTOMREQUEST'] = 'TRACE';
@ -2274,6 +2407,10 @@ class curl {
}
/**
* HTTP OPTIONS method
*
* @param string $url
* @param array $options
* @return bool
*/
public function options($url, $options = array()){
$options['CURLOPT_CUSTOMREQUEST'] = 'OPTIONS';
@ -2285,19 +2422,26 @@ class curl {
/**
* This class is used by cURL class, use case:
*
* <code>
* $CFG->repositorycacheexpire = 120;
* $CFG->curlcache = 120;
*
* $c = new curl(array('cache'=>true), 'module_cache'=>'repository');
* $ret = $c->get('http://www.google.com');
* </code>
*
* @package moodlecore
* @subpackage file
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class curl_cache {
/** @var string */
public $dir = '';
/**
*
* @global $CFG
* @param string @module, which module is using curl_cache
* @global object
* @param string @module which module is using curl_cache
*
*/
function __construct($module = 'repository'){
@ -2324,7 +2468,12 @@ class curl_cache {
}
/**
* TODO Document
* @todo Document this function
*
* @global object
* @global object
* @param mixed $param
* @return bool|string
*/
public function get($param){
global $CFG, $USER;
@ -2346,7 +2495,12 @@ class curl_cache {
}
/**
* TODO Document
* @todo Document this function
*
* @global object
* @global object
* @param mixed $param
* @param mixed $val
*/
public function set($param, $val){
global $CFG, $USER;
@ -2357,7 +2511,9 @@ class curl_cache {
}
/**
* TODO Document
* @todo Document this function
*
* @param int $expire The number os seconds before expiry
*/
public function cleanup($expire){
if($dir = opendir($this->dir)){
@ -2374,7 +2530,8 @@ class curl_cache {
/**
* delete current user's cache file
*
* @return null
* @global object
* @global object
*/
public function refresh(){
global $CFG, $USER;
@ -2391,9 +2548,19 @@ class curl_cache {
}
/**
* TODO Document
* @todo Document this class
*
* @package moodlecore
* @subpackage file
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class file_type_to_ext {
/**
* @todo Document this function
* @global object
* @param string $file
*/
public function __construct($file = '') {
global $CFG;
if (empty($file)) {
@ -2406,7 +2573,9 @@ class file_type_to_ext {
}
/**
* TODO Document
* @todo Document this function
* @param array $parent
* @param array $types
*/
private function _browse_nodes($parent, $types) {
$key = (string)$parent['TEXT'];
@ -2425,7 +2594,8 @@ class file_type_to_ext {
}
/**
* TODO Document
* @todo Document this function
* @param array $parent
*/
private function _select_nodes($parent){
if(isset($parent->node)) {
@ -2439,7 +2609,9 @@ class file_type_to_ext {
/**
* TODO Document
* @todo Document this function
* @param array $types
* @return mixed
*/
public function get_file_ext($types) {
$this->result = array();

View File

@ -1,41 +1,35 @@
<?php // $Id$
<?php
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Library functions for managing text filter plugins.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package moodlecore
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* The states a filter can be in, stored in the filter_active table.
*/
/** The states a filter can be in, stored in the filter_active table. */
define('TEXTFILTER_ON', 1);
/** The states a filter can be in, stored in the filter_active table. */
define('TEXTFILTER_INHERIT', 0);
/** The states a filter can be in, stored in the filter_active table. */
define('TEXTFILTER_OFF', -1);
/** The states a filter can be in, stored in the filter_active table. */
define('TEXTFILTER_DISABLED', -9999);
/**
@ -44,20 +38,28 @@ define('TEXTFILTER_DISABLED', -9999);
* format_text and format_string functions.
*
* This class is a singleton.
*
* @package moodlecore
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class filter_manager {
/** This list of active filters, by context, for filtering content.
* An array contextid => array of filter objects. */
/**
* @var array This list of active filters, by context, for filtering content.
* An array contextid => array of filter objects.
*/
protected $textfilters = array();
/** This list of active filters, by context, for filtering strings.
* An array contextid => array of filter objects. */
/**
* @var array This list of active filters, by context, for filtering strings.
* An array contextid => array of filter objects.
*/
protected $stringfilters = array();
/** Exploded version of $CFG->stringfilters. */
/** @var array Exploded version of $CFG->stringfilters. */
protected $stringfilternames = array();
/** Holds the singleton instance. */
/** @var object Holds the singleton instance. */
protected static $singletoninstance;
protected function __construct() {
@ -65,7 +67,8 @@ class filter_manager {
}
/**
* @return the singleton instance.
* @global object
* @return object the singleton instance.
*/
public static function instance() {
if (is_null(self::$singletoninstance)) {
@ -79,7 +82,12 @@ class filter_manager {
return self::$singletoninstance;
}
/** Load all the filters required by this context. */
/**
* Load all the filters required by this context.
*
* @param object $context
* @param int $courseid
*/
protected function load_filters($context, $courseid) {
$filters = filter_get_active_in_context($context);
$this->textfilters[$context->id] = array();
@ -97,12 +105,14 @@ class filter_manager {
}
/**
* Factory method for creating a filter.
* Factory method for creating a filter
*
* @global object
* @param string $filter The filter name, for example 'filter/tex' or 'mod/glossary'.
* @param $context context object.
* @param $courseid course if.
* @param $localconfig array of local configuration variables for this filter.
* @return moodle_text_filter The filter, or null, if this type of filter is
* @param object $context context object.
* @param int $courseid course id.
* @param array $localconfig array of local configuration variables for this filter.
* @return object moodle_text_filter The filter, or null, if this type of filter is
* not recognised or could not be created.
*/
protected function make_filter_object($filtername, $context, $courseid, $localconfig) {
@ -126,6 +136,12 @@ class filter_manager {
return null;
}
/**
* @todo Document this function
* @param string $text
* @param array $filterchain
* @return string $text
*/
protected function apply_filter_chain($text, $filterchain) {
foreach ($filterchain as $filter) {
$text = $filter->filter($text);
@ -133,6 +149,12 @@ class filter_manager {
return $text;
}
/**
* @todo Document this function
* @param object $context
* @param int $courseid
* @return object A text filter
*/
protected function get_text_filters($context, $courseid) {
if (!isset($this->textfilters[$context->id])) {
$this->load_filters($context, $courseid);
@ -140,6 +162,12 @@ class filter_manager {
return $this->textfilters[$context->id];
}
/**
* @todo Document this function
* @param object $context
* @param int $courseid
* @return object A string filter
*/
protected function get_string_filters($context, $courseid) {
if (!isset($this->stringfilters[$context->id])) {
$this->load_filters($context, $courseid);
@ -147,6 +175,14 @@ class filter_manager {
return $this->stringfilters[$context->id];
}
/**
* Filter some text
*
* @param string $text The text to filter
* @param object $context
* @param int $courseid
* @return string resulting text
*/
public function filter_text($text, $context, $courseid) {
$text = $this->apply_filter_chain($text, $this->get_text_filters($context, $courseid));
/// <nolink> tags removed for XHTML compatibility
@ -154,10 +190,24 @@ class filter_manager {
return $text;
}
/**
* Filter a peice of string
*
* @param string $string The text to filter
* @param object $context
* @param int $courseid
* @return string resulting string
*/
public function filter_string($string, $context, $courseid) {
return $this->apply_filter_chain($string, $this->get_string_filters($context, $courseid));
}
/**
* @todo Document this function
* @param object $context
* @param int $courseid
* @return object A string filter
*/
public function text_filtering_hash($context, $courseid) {
$filters = $this->get_text_filters($context, $courseid);
$hashes = array();
@ -171,16 +221,31 @@ class filter_manager {
/**
* Filter manager subclass that does nothing. Having this simplifies the logic
* of format_text, etc.
*
* @todo Document this class
*
* @package moodlecore
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class null_filter_manager {
/**
* @return string
*/
public function filter_text($text, $context, $courseid) {
return $text;
}
/**
* @return string
*/
public function filter_string($string, $context, $courseid) {
return $string;
}
/**
* @return string
*/
public function text_filtering_hash() {
return '';
}
@ -188,27 +253,56 @@ class null_filter_manager {
/**
* Filter manager subclass that tacks how much work it does.
*
* @todo Document this class
*
* @package moodlecore
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class performance_measuring_filter_manager extends filter_manager {
/** @var int */
protected $filterscreated = 0;
protected $textsfiltered = 0;
protected $stringsfiltered = 0;
/**
* @param string $filtername
* @param object $context
* @param int $courseid
* @param mixed $localconfig
* @return mixed
*/
protected function make_filter_object($filtername, $context, $courseid, $localconfig) {
$this->filterscreated++;
return parent::make_filter_object($filtername, $context, $courseid, $localconfig);
}
/**
* @param string $text
* @param object $context
* @param int $courseid
* @return mixed
*/
public function filter_text($text, $context, $courseid) {
$this->textsfiltered++;
return parent::filter_text($text, $context, $courseid);
}
/**
* @param string $string
* @param object $context
* @param int $courseid
* @return mixed
*/
public function filter_string($string, $context, $courseid) {
$this->stringsfiltered++;
return parent::filter_string($string, $context, $courseid);
}
/**
* @return array
*/
public function get_performance_summary() {
return array(array(
'contextswithfilters' => count($this->textfilters),
@ -227,13 +321,17 @@ class performance_measuring_filter_manager extends filter_manager {
/**
* Base class for text filters. You just need to override this class and
* implement the filter method.
*
* @package moodlecore
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class moodle_text_filter {
/** The course we are in. */
/** @var int The course we are in. */
protected $courseid;
/** The context we are in. */
/** @var object The context we are in. */
protected $context;
/** Any local configuration for this filter in this context. */
/** @var object Any local configuration for this filter in this context. */
protected $localconfig;
/**
@ -248,12 +346,16 @@ abstract class moodle_text_filter {
$this->localconfig = $localconfig;
}
/**
* @return string The class name of the current class
*/
public function hash() {
return __CLASS__;
}
/**
* Override this funciton to actually implement the filtering.
*
* @param $text some HTML content.
* @return the HTML content after the filtering has been applied.
*/
@ -263,12 +365,18 @@ abstract class moodle_text_filter {
/**
* moodle_text_filter implementation that encapsulates an old-style filter that
* only defines a function, not a class.
*
* @package moodlecore
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class legacy_filter extends moodle_text_filter {
/** @var string */
protected $filterfunction;
/**
* Set any context-specific configuration for this filter.
*
* @param string $filterfunction
* @param object $context The current course id.
* @param object $context The current context.
@ -279,27 +387,40 @@ class legacy_filter extends moodle_text_filter {
$this->filterfunction = $filterfunction;
}
/**
* @param string $text
* @return mixed
*/
public function filter($text) {
return call_user_func($this->filterfunction, $this->courseid, $text);
}
}
/// Define one exclusive separator that we'll use in the temp saved tags
/// keys. It must be something rare enough to avoid having matches with
/// filterobjects. MDL-18165
/**
* Define one exclusive separator that we'll use in the temp saved tags
* keys. It must be something rare enough to avoid having matches with
* filterobjects. MDL-18165
*/
define('EXCL_SEPARATOR', '-%-');
/**
* This is just a little object to define a phrase and some instructions
* for how to process it. Filters can create an array of these to pass
* to the filter_phrases function below.
*
* @package moodlecore
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
**/
class filterobject {
/** @var string */
var $phrase;
var $hreftagbegin;
var $hreftagend;
/** @var bool */
var $casesensitive;
var $fullmatch;
/** @var mixed */
var $replacementphrase;
var $work_phrase;
var $work_hreftagbegin;
@ -307,9 +428,19 @@ class filterobject {
var $work_casesensitive;
var $work_fullmatch;
var $work_replacementphrase;
/** @var bool */
var $work_calculated;
/// a constructor just because I like constructing
/**
* A constructor just because I like constructing
*
* @param string $phrase
* @param string $hreftagbegin
* @param string $hreftagend
* @param bool $casesensitive
* @param bool $fullmatch
* @param mixed $replacementphrase
*/
function filterobject($phrase, $hreftagbegin='<span class="highlight">',
$hreftagend='</span>',
$casesensitive=false,
@ -333,7 +464,7 @@ class filterobject {
* else if $filterlocation = 'filter' then does get_string('filtername', 'filter_' . $filter);
* with a fallback to get_string('filtername', $filter) for backwards compatibility.
* These are the only two options supported at the moment.
* @param string $filterlocation 'filter' or 'mod'.
*
* @param string $filter the folder name where the filter lives.
* @return string the human-readable name for this filter.
*/
@ -362,6 +493,8 @@ function filter_get_name($filter) {
/**
* Get the names of all the filters installed in this Moodle.
*
* @global object
* @return array path => filter name from the appropriate lang file. e.g.
* array('mod/glossary' => 'Glossary Auto-linking', 'filter/tex' => 'TeX Notation');
* sorted in alphabetical order of name.
@ -386,6 +519,8 @@ function filter_get_all_installed() {
/**
* Set the global activated state for a text filter.
*
* @global object
* @param string $filter The filter name, for example 'filter/tex' or 'mod/glossary'.
* @param integer $state One of the values TEXTFILTER_ON, TEXTFILTER_OFF or TEXTFILTER_DISABLED.
* @param integer $sortorder (optional) a position in the sortorder to place this filter.
@ -479,6 +614,8 @@ function filter_is_enabled($filter) {
/**
* Return a list of all the filters that may be in use somewhere.
*
* @staticvar array $enabledfilters
* @return array where the keys and values are both the filter name, like 'filter/tex'.
*/
function filter_get_globally_enabled() {
@ -498,6 +635,8 @@ function filter_get_globally_enabled() {
/**
* Return the names of the filters that should also be applied to strings
* (when they are enabled).
*
* @global object
* @return array where the keys and values are both the filter name, like 'filter/tex'.
*/
function filter_get_string_filters() {
@ -513,6 +652,7 @@ function filter_get_string_filters() {
/**
* Sets whether a particular active filter should be applied to all strings by
* format_string, or just used by format_text.
*
* @param string $filter The filter name, for example 'filter/tex' or 'mod/glossary'.
* @param boolean $applytostrings if true, this filter will apply to format_string
* and format_text, when it is enabled.
@ -533,9 +673,12 @@ function filter_set_applies_to_strings($filter, $applytostrings) {
/**
* Set the local activated state for a text filter.
*
* @global object
* @param string $filter The filter name, for example 'filter/tex' or 'mod/glossary'.
* @param integer $contextid The id of the context to get the local config for.
* @param integer $state One of the values TEXTFILTER_ON, TEXTFILTER_OFF or TEXTFILTER_INHERIT.
* @return void
*/
function filter_set_local_state($filter, $contextid, $state) {
global $DB;
@ -576,6 +719,8 @@ function filter_set_local_state($filter, $contextid, $state) {
/**
* Set a particular local config variable for a filter in a context.
*
* @global object
* @param string $filter The filter name, for example 'filter/tex' or 'mod/glossary'.
* @param integer $contextid The id of the context to get the local config for.
* @param string $name the setting name.
@ -604,6 +749,8 @@ function filter_set_local_config($filter, $contextid, $name, $value) {
/**
* Remove a particular local config variable for a filter in a context.
*
* @global object
* @param string $filter The filter name, for example 'filter/tex' or 'mod/glossary'.
* @param integer $contextid The id of the context to get the local config for.
* @param string $name the setting name.
@ -618,6 +765,8 @@ function filter_unset_local_config($filter, $contextid, $name) {
* filter is running) you don't need to call this, becuase the config is fetched
* for you automatically. You only need this, for example, when you are getting
* the config so you can show the user an editing from.
*
* @global object
* @param string $filter The filter name, for example 'filter/tex' or 'mod/glossary'.
* @param integer $contextid The ID of the context to get the local config for.
* @return array of name => value pairs.
@ -630,7 +779,10 @@ function filter_get_local_config($filter, $contextid) {
/**
* This function is for use by backup. Gets all the filter information specific
* to one context.
* @return array with two elements. The first element is an array of objects with
*
* @global object
* @param int $contextid
* @return array Array with two elements. The first element is an array of objects with
* fields filter and active. These come from the filter_active table. The
* second element is an array of objects with fields filter, name and value
* from the filter_config table.
@ -648,8 +800,8 @@ function filter_get_all_local_settings($contextid) {
* Get the list of active filters, in the order that they should be used
* for a particular context, along with any local configuration variables.
*
* @global object
* @param object $context a context
*
* @return array an array where the keys are the filter names, for example
* 'filter/tex' or 'mod/glossary' and the values are any local
* configuration for that filter, as an array of name => value pairs
@ -695,6 +847,8 @@ function filter_get_active_in_context($context) {
/**
* List all of the filters that are available in this context, and what the
* local and interited states of that filter are.
*
* @global object
* @param object $context a context that is not the system context.
* @return array an array with filter names, for example 'filter/tex' or
* 'mod/glossary' as keys. and and the values are objects with fields:
@ -736,6 +890,8 @@ function filter_get_available_in_context($context) {
/**
* This function is for use by the filter administration page.
*
* @global object
* @return array 'filtername' => object with fields 'filter' (=filtername), 'active' and 'sortorder'
*/
function filter_get_global_states() {
@ -746,6 +902,8 @@ function filter_get_global_states() {
/**
* Delete all the data in the database relating to a filter, prior to deleting it.
*
* @global object
* @param string $filter The filter name, for example 'filter/tex' or 'mod/glossary'.
*/
function filter_delete_all_for_filter($filter) {
@ -759,6 +917,8 @@ function filter_delete_all_for_filter($filter) {
/**
* Delete all the data in the database relating to a context, used when contexts are deleted.
*
* @global object
* @param integer $contextid The id of the context being deleted.
*/
function filter_delete_all_for_context($contextid) {
@ -772,6 +932,7 @@ function filter_delete_all_for_context($contextid) {
* (The settings page for a filter must be called, for example,
* filtersettingfiltertex or filtersettingmodglossay.)
*
* @global object
* @param string $filter The filter name, for example 'filter/tex' or 'mod/glossary'.
* @return boolean Whether there should be a 'Settings' link on the config page.
*/
@ -784,6 +945,7 @@ function filter_has_global_settings($filter) {
/**
* Does this filter have local (per-context) settings?
*
* @global object
* @param string $filter The filter name, for example 'filter/tex' or 'mod/glossary'.
* @return boolean Whether there should be a 'Settings' link on the manage filters in context page.
*/
@ -796,6 +958,7 @@ function filter_has_local_settings($filter) {
/**
* Certain types of context (block and user) may not have local filter settings.
* the function checks a context to see whether it may have local config.
*
* @param object $context a context.
* @return boolean whether this context may have local filter settings.
*/
@ -806,10 +969,13 @@ function filter_context_may_have_filter_settings($context) {
/**
* Process phrases intelligently found within a HTML text (such as adding links)
*
* param text the text that we are filtering
* param link_array an array of filterobjects
* param ignoretagsopen an array of opening tags that we should ignore while filtering
* param ignoretagsclose an array of corresponding closing tags
* @global object
* @staticvar array $usedpharses
* @param string $text the text that we are filtering
* @param array $link_array an array of filterobjects
* @param array $ignoretagsopen an array of opening tags that we should ignore while filtering
* @param array $ignoretagsclose an array of corresponding closing tags
* @return string
**/
function filter_phrases($text, &$link_array, $ignoretagsopen=NULL, $ignoretagsclose=NULL) {
@ -1005,6 +1171,11 @@ function filter_phrases($text, &$link_array, $ignoretagsopen=NULL, $ignoretagscl
return $text;
}
/**
* @todo Document this function
* @param array $linkarray
* @return array
*/
function filter_remove_duplicates($linkarray) {
$concepts = array(); // keep a record of concepts as we cycle through
@ -1035,10 +1206,10 @@ function filter_remove_duplicates($linkarray) {
* converted with some <#xEXCL_SEPARATORx#> codes replacing the extracted text. Such extracted
* texts are returned in the ignoretags array (as values), with codes as keys.
*
* param text the text that we are filtering (in/out)
* param filterignoretagsopen an array of open tags to start searching
* param filterignoretagsclose an array of close tags to end searching
* param ignoretags an array of saved strings useful to rebuild the original text (in/out)
* @param string $text the text that we are filtering (in/out)
* @param array $filterignoretagsopen an array of open tags to start searching
* @param array $filterignoretagsclose an array of close tags to end searching
* @param array $ignoretags an array of saved strings useful to rebuild the original text (in/out)
**/
function filter_save_ignore_tags(&$text,$filterignoretagsopen,$filterignoretagsclose,&$ignoretags) {
@ -1066,8 +1237,8 @@ function filter_save_ignore_tags(&$text,$filterignoretagsopen,$filterignoretagsc
* It returns the text converted with some <%xEXCL_SEPARATORx%> codes replacing the extracted text. Such extracted
* texts are returned in the tags array (as values), with codes as keys.
*
* param text the text that we are filtering (in/out)
* param tags an array of saved strings useful to rebuild the original text (in/out)
* @param string $text the text that we are filtering (in/out)
* @param array $tags an array of saved strings useful to rebuild the original text (in/out)
**/
function filter_save_tags(&$text,&$tags) {
@ -1083,6 +1254,10 @@ function filter_save_tags(&$text,&$tags) {
/**
* Add missing openpopup javascript to HTML files.
*
* @global object
* @param string $text
* @return string
*/
function filter_add_javascript($text) {
global $CFG;

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,19 @@
<?php // $Id$
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* formslib.php - library of classes for creating forms in Moodle, based on PEAR QuickForms.
*
@ -16,11 +31,12 @@
* elements, these elements clean themselves.
*
*
* @author Jamie Pratt
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @copyright Jamie Pratt <me@jamiep.org>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @package moodlecore
*/
//setup.php icludes our hacked pear libs first
/** setup.php icludes our hacked pear libs first */
require_once 'HTML/QuickForm.php';
require_once 'HTML/QuickForm/DHTMLRulesTableless.php';
require_once 'HTML/QuickForm/Renderer/Tableless.php';
@ -45,6 +61,11 @@ if ($CFG->debug >= DEBUG_ALL){
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'pear_handle_error');
}
/**
* @global object
* @staticvar bool $done
* @todo This is NOT xhtml strict, we will need something like require_css()
*/
function form_init_date_js() {
global $CFG;
static $done = false;
@ -65,13 +86,18 @@ function form_init_date_js() {
* subclass such a moodleform_mod for each form you want to display and/or process with formslib.
*
* You will write your own definition() method which performs the form set up.
*
* @package moodlecore
* @copyright Jamie Pratt <me@jamiep.org>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class moodleform {
/** @var string */
protected $_formname; // form name
/**
* quickform object definition
*
* @var MoodleQuickForm
* @var object MoodleQuickForm
*/
protected $_form;
/**
@ -82,7 +108,7 @@ class moodleform {
protected $_customdata;
/**
* definition_after_data executed flag
* @var definition_finalized
* @var object definition_finalized
*/
protected $_definition_finalized = false;
@ -108,7 +134,8 @@ class moodleform {
* it if you don't need to as the target attribute is deprecated in xhtml
* strict.
* @param mixed $attributes you can pass a string of html attributes here or an array.
* @return moodleform
* @param bool $editable
* @return object moodleform
*/
function moodleform($action=null, $customdata=null, $method='post', $target='', $attributes=null, $editable=true) {
if (empty($action)){
@ -175,6 +202,8 @@ class moodleform {
/**
* Internal method. Alters submitted data to be suitable for quickforms processing.
* Must be called when the form is fully set up.
*
* @param string $method
*/
function _process_submission($method) {
$submission = array();
@ -203,6 +232,11 @@ class moodleform {
/**
* Internal method. Validates all old-style uploaded files.
*
* @global object
* @global object
* @param array $files
* @return bool|array Success or an array of errors
*/
function _validate_files(&$files) {
global $CFG, $COURSE;
@ -305,6 +339,9 @@ class moodleform {
$this->_form->setDefaults($default_values);
}
/**
* @param bool $um
*/
function set_upload_manager($um=false) {
debugging('Not used anymore, please fix code!');
}
@ -318,6 +355,9 @@ class moodleform {
return $this->_form->isSubmitted();
}
/**
* @staticvar bool $nosubmit
*/
function no_submit_button_pressed(){
static $nosubmit = null; // one check is enough
if (!is_null($nosubmit)){
@ -341,6 +381,7 @@ class moodleform {
/**
* Check that form data is valid.
*
* @staticvar bool $validated
* @return bool true if form data valid
*/
function is_validated() {
@ -456,6 +497,8 @@ class moodleform {
/**
* Save verified uploaded files into directory. Upload process can be customised from definition()
* NOTE: please use save_stored_file() or save_file()
*
* @return bool Always false
*/
function save_files($destination) {
debugging('Not used anymore, please fix code! Use save_stored_file() or save_file() instead');
@ -464,6 +507,8 @@ class moodleform {
/**
* Returns name of uploaded file.
*
* @global object
* @param string $elname, first element if null
* @return mixed false in case of failure, string if ok
*/
@ -512,6 +557,8 @@ class moodleform {
/**
* Save file to standard filesystem
*
* @global object
* @param string $elname name of element
* @param string $pathname full path name of file
* @param bool $override override file if exists
@ -560,6 +607,8 @@ class moodleform {
/**
* Save file to local filesystem pool
*
* @global object
* @param string $elname name of element
* @param int $newcontextid
* @param string $newfilearea
@ -632,6 +681,8 @@ class moodleform {
/**
* Get content of uploaded file.
*
* @global object
* @param $element name of file upload element
* @return mixed false in case of failure, string if ok
*/
@ -821,8 +872,10 @@ class moodleform {
/**
* Adds a link/button that controls the checked state of a group of checkboxes.
*
* @global object
* @param int $groupid The id of the group of advcheckboxes this element controls
* @param string $text The text of the link. Defaults to "select all/none"
* @param string $buttontext The text of the link. Defaults to "select all/none"
* @param array $attributes associative array of HTML attributes
* @param int $originalValue The original general state of the checkboxes before the user first clicks this element
*/
@ -926,8 +979,12 @@ EOS;
* call methods on this class from within abstract methods that you override on moodleform such
* as definition and definition_after_data
*
* @package moodlecore
* @copyright Jamie Pratt <me@jamiep.org>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
/** @var array */
var $_types = array();
var $_dependencies = array();
/**
@ -975,12 +1032,14 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
/**
* Class constructor - same parameters as HTML_QuickForm_DHTMLRulesTableless
*
* @global object
* @staticvar int $formcounter
* @param string $formName Form's name.
* @param string $method (optional)Form's method defaults to 'POST'
* @param mixed $action (optional)Form's action - string or moodle_url
* @param string $target (optional)Form's target defaults to none
* @param mixed $attributes (optional)Extra attributes for <form> tag
* @param bool $trackSubmit (optional)Whether to track if the form was submitted by adding a special hidden field
* @access public
*/
function MoodleQuickForm($formName, $method, $action, $target='', $attributes=null){
@ -1084,8 +1143,7 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
/**
* Accepts a renderer
*
* @param HTML_QuickForm_Renderer An HTML_QuickForm_Renderer object
* @since 3.0
* @param object $renderer HTML_QuickForm_Renderer An HTML_QuickForm_Renderer object
* @access public
* @return void
*/
@ -1131,8 +1189,9 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
parent::accept($renderer);
}
/**
* @param string $elementName
*/
function closeHeaderBefore($elementName){
$renderer =& $this->defaultRenderer();
$renderer->addStopFieldsetElements($elementName);
@ -1169,6 +1228,10 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
$this->_types = $paramtypes + $this->_types;
}
/**
* @param array $submission
* @param array $files
*/
function updateSubmission($submission, $files) {
$this->_flagSubmitted = false;
@ -1197,10 +1260,16 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
}
}
/**
* @return string
*/
function getReqHTML(){
return $this->_reqHTML;
}
/**
* @return string
*/
function getAdvancedHTML(){
return $this->_advancedHTML;
}
@ -1223,7 +1292,8 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
* Add an array of buttons to the form
* @param array $buttons An associative array representing help button to attach to
* to the form. keys of array correspond to names of elements in form.
*
* @param bool $suppresscheck
* @param string $function
* @access public
*/
function setHelpButtons($buttons, $suppresscheck=false, $function='helpbutton'){
@ -1236,10 +1306,11 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
* Add a single button.
*
* @param string $elementname name of the element to add the item to
* @param array $button - arguments to pass to function $function
* @param boolean $suppresscheck - whether to throw an error if the element
* @param array $button arguments to pass to function $function
* @param boolean $suppresscheck whether to throw an error if the element
* doesn't exist.
* @param string $function - function to generate html from the arguments in $button
* @param string $function
*/
function setHelpButton($elementname, $button, $suppresscheck=false, $function='helpbutton'){
if (array_key_exists($elementname, $this->_elementIndex)){
@ -1261,6 +1332,7 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
/**
* Set constant value not overriden by _POST or _GET
* note: this does not work for complex names with [] :-(
*
* @param string $elname name of element
* @param mixed $value
* @return void
@ -1271,6 +1343,9 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
$element->onQuickFormEvent('updateValue', null, $this);
}
/**
* @param string $elementList
*/
function exportValues($elementList = null){
$unfiltered = array();
if (null === $elementList) {
@ -1318,9 +1393,7 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
* @param string $validation (optional)Where to perform validation: "server", "client"
* @param boolean $reset Client-side validation: reset the form element to its original value if there is an error?
* @param boolean $force Force the rule to be applied, even if the target form element does not exist
* @since 1.0
* @access public
* @throws HTML_QuickForm_Error
*/
function addRule($element, $message, $type, $format=null, $validation='server', $reset = false, $force = false)
{
@ -1346,9 +1419,7 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
* @param int $howmany (optional)How many valid elements should be in the group
* @param string $validation (optional)Where to perform validation: "server", "client"
* @param bool $reset Client-side: whether to reset the element's value to its original state if validation failed.
* @since 2.5
* @access public
* @throws HTML_QuickForm_Error
*/
function addGroupRule($group, $arg1, $type='', $format=null, $howmany=0, $validation = 'server', $reset = false)
{
@ -1568,6 +1639,9 @@ function validate_' . $this->_formName . '(frm) {
}
}
/**
* @return string
*/
function getLockOptionEndScript(){
$iname = $this->getAttribute('id').'items';
@ -1605,6 +1679,10 @@ function validate_' . $this->_formName . '(frm) {
return $js;
}
/**
* @param mixed $element
* @return array
*/
function _getElNamesRecursive($element) {
if (is_string($element)) {
if (!$this->elementExists($element)) {
@ -1671,10 +1749,17 @@ function validate_' . $this->_formName . '(frm) {
$this->_noSubmitButtons[]=$buttonname;
}
/**
* @param string $buttonname
* @return mixed
*/
function isNoSubmitButton($buttonname){
return (array_search($buttonname, $this->_noSubmitButtons)!==FALSE);
}
/**
* @param string $buttonname
*/
function _registerCancelButton($addfieldsname){
$this->_cancelButtons[]=$addfieldsname;
}
@ -1687,9 +1772,7 @@ function validate_' . $this->_formName . '(frm) {
* This function also removes all previously defined rules.
*
* @param mixed $elementList array or string of element(s) to be frozen
* @since 1.0
* @access public
* @throws HTML_QuickForm_Error
*/
function hardFreeze($elementList=null)
{
@ -1730,10 +1813,10 @@ function validate_' . $this->_formName . '(frm) {
*
* This function also removes all previously defined rules of elements it freezes.
*
* throws HTML_QuickForm_Error
*
* @param array $elementList array or string of element(s) not to be frozen
* @since 1.0
* @access public
* @throws HTML_QuickForm_Error
*/
function hardFreezeAllVisibleExcept($elementList)
{
@ -1781,8 +1864,9 @@ function validate_' . $this->_formName . '(frm) {
*
* Stylesheet is part of standard theme and should be automatically included.
*
* @author Jamie Pratt <me@jamiep.org>
* @license gpl license
* @package moodlecore
* @copyright Jamie Pratt <me@jamiep.org>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{
@ -1855,6 +1939,9 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{
parent::HTML_QuickForm_Renderer_Tableless();
}
/**
* @param array $elements
*/
function setAdvancedElements($elements){
$this->_advancedElements = $elements;
}
@ -1862,7 +1949,7 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{
/**
* What to do when starting the form
*
* @param MoodleQuickForm $form
* @param object $form MoodleQuickForm
*/
function startForm(&$form){
$this->_reqHTML = $form->getReqHTML();
@ -1878,7 +1965,12 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{
}
/**
* @param object $group Passed by reference
* @param mixed $required
* @param mixed $error
*/
function startGroup(&$group, $required, $error){
if (method_exists($group, 'getElementTemplateType')){
$html = $this->_elementTemplates[$group->getElementTemplateType()];
@ -1918,7 +2010,11 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{
}
parent::startGroup($group, $required, $error);
}
/**
* @param object $element
* @param mixed $required
* @param mixed $error
*/
function renderElement(&$element, $required, $error){
//manipulate id of all elements before rendering
if (!is_null($element->getAttribute('id'))) {
@ -1976,6 +2072,9 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{
parent::renderElement($element, $required, $error);
}
/**
* @param object $form Passed by reference
*/
function finishForm(&$form){
if ($form->isFrozen()){
$this->_hiddenHtml = '';
@ -1989,7 +2088,7 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{
/**
* Called when visiting a header element
*
* @param object An HTML_QuickForm_header element being visited
* @param object $header An HTML_QuickForm_header element being visited
* @access public
* @return void
*/
@ -2061,10 +2160,13 @@ showAdvancedInit('{$name}_script', '$elementName', '$buttonlabel', '$hidetext',
}
}
/**
* @global object $GLOBALS['_HTML_QuickForm_default_renderer']
* @name $_HTML_QuickForm_default_renderer
*/
$GLOBALS['_HTML_QuickForm_default_renderer'] =& new MoodleQuickForm_Renderer();
// Please keep this list in alphabetical order.
/** Please keep this list in alphabetical order. */
MoodleQuickForm::registerElementType('advcheckbox', "$CFG->libdir/form/advcheckbox.php", 'MoodleQuickForm_advcheckbox');
MoodleQuickForm::registerElementType('button', "$CFG->libdir/form/button.php", 'MoodleQuickForm_button');
MoodleQuickForm::registerElementType('cancel', "$CFG->libdir/form/cancel.php", 'MoodleQuickForm_cancel');

View File

@ -1,31 +1,44 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* gdlib.php - Collection of routines in Moodle related to
* processing images using GD
*
* @author Martin Dougiamas etc
* @version $Id$
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package moodlecore
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* short description (optional)
*
* long description
* @uses $CFG
* @param type? $dst_img description?
* @param type? $src_img description?
* @param type? $dst_x description?
* @param type? $dst_y description?
* @param type? $src_x description?
* @param type? $src_y description?
* @param type? $dst_w description?
* @param type? $dst_h description?
* @param type? $src_w description?
* @param type? $src_h description?
* @return ?
* @global object
* @param object $dst_img
* @param object $src_img
* @param int $dst_x
* @param int $dst_y
* @param int $src_x
* @param int $src_y
* @param int $dst_w
* @param int $dst_h
* @param int $src_w
* @param int $src_h
* @return bool
* @todo Finish documenting this function
*/
function ImageCopyBicubic ($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) {
@ -73,6 +86,8 @@ function ImageCopyBicubic ($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $
/**
* Delete profile images associated with user or group
*
* @global object
* @param int $id user or group id
* @param string $dir type of entity - 'groups' or 'users'
* @return boolean success
@ -94,6 +109,7 @@ function delete_profile_image($id, $dir='users') {
* Given an upload manager with the right settings, this function performs a virus scan, and then scales and crops
* it and saves it in the right place to be a "user" or "group" image.
*
* @global object
* @param int $id user or group id
* @param string $dir type of entity - groups, user, ...
* @return string $destination (profile image destination path) or false on error
@ -153,7 +169,7 @@ function save_profile_image($id, $userform, $dir='user') {
* Given a path to an image file this function scales and crops it and saves it in
* the right place to be a "user" or "group" image.
*
* @uses $CFG
* @global object
* @param string $originalfile the path of the original image file
* @param string $destination the final destination directory of the profile image
* @return boolean
@ -256,8 +272,9 @@ function process_profile_image($originalfile, $destination) {
* Given a user id this function scales and crops the user images to remove
* the one pixel black border.
*
* @uses $CFG
* @param int $id description?
* @global object
* @param int $id
* @param string $dir
* @return boolean
*/
function upgrade_profile_image($id, $dir='users') {

View File

@ -1,4 +1,4 @@
<?php // $Id$
<?php
/**
* Moodle - Modular Object-Oriented Dynamic Learning Environment
* http://moodle.org
@ -17,14 +17,15 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package moodle
* @package moodlecore
* @subpackage lib
* @author Dan Poltawski <talktodan@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright Dan Poltawski <talktodan@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
* Simple implementation of some Google API functions for Moodle.
*/
/** Include essential file */
require_once($CFG->libdir.'/filelib.php');
/**
@ -33,6 +34,11 @@ require_once($CFG->libdir.'/filelib.php');
* Most Google API Calls required that requests are sent with an
* Authorization header + token. This class extends the curl class
* to aid this
*
* @package moodlecore
* @subpackage lib
* @copyright Dan Poltawski <talktodan@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class google_auth_request extends curl{
protected $token = '';
@ -78,6 +84,11 @@ abstract class google_auth_request extends curl{
/**
* Used to uprade a google AuthSubRequest one-time token into
* a session token which can be used long term.
*
* @package moodlecore
* @subpackage lib
* @copyright Dan Poltawski <talktodan@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class google_authsub_request extends google_auth_request {
const AUTHSESSION_URL = 'https://www.google.com/accounts/AuthSubSessionToken';
@ -114,6 +125,11 @@ class google_authsub_request extends google_auth_request {
/**
* Allows http calls using google subauth authorisation
*
* @package moodlecore
* @subpackage lib
* @copyright Dan Poltawski <talktodan@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class google_authsub extends google_auth_request {
const LOGINAUTH_URL = 'https://www.google.com/accounts/AuthSubRequest';
@ -199,7 +215,12 @@ class google_authsub extends google_auth_request {
/**
* Class for manipulating google documents through the google data api
* Docs for this can be found here:
* http://code.google.com/apis/documents/docs/2.0/developers_guide_protocol.html
* {@link http://code.google.com/apis/documents/docs/2.0/developers_guide_protocol.html}
*
* @package moodlecore
* @subpackage lib
* @copyright Dan Poltawski <talktodan@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class google_docs {
// need both docs and the spreadsheets realm
@ -320,7 +341,12 @@ class google_docs {
/**
* Class for manipulating picasa through the google data api
* Docs for this can be found here:
* http://code.google.com/apis/picasaweb/developers_guide_protocol.html
* {@link http://code.google.com/apis/picasaweb/developers_guide_protocol.html}
*
* @package moodlecore
* @subpackage lib
* @copyright Dan Poltawski <talktodan@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class google_picasa {
const REALM = 'http://picasaweb.google.com/data/';
@ -502,10 +528,15 @@ class google_picasa {
/**
* Beginings of an implementation of Clientogin authenticaton for google
* accounts as documented here:
* http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html#ClientLogin
* {@link http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html#ClientLogin}
*
* With this authentication we have to accept a username and password and to post
* it to google. Retrieving a token for use afterwards.
*
* @package moodlecore
* @subpackage lib
* @copyright Dan Poltawski <talktodan@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class google_authclient extends google_auth_request {
const LOGIN_URL = 'https://www.google.com/accounts/ClientLogin';

View File

@ -1,36 +1,29 @@
<?php // $Id$
<?php
///////////////////////////////////////////////////////////////////////////
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Library of functions for gradebook - both public and internal
*
* @author Moodle HQ developers
* @version $Id$
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package moodlecore
* @package moodlecore
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/** Include essential files */
require_once($CFG->libdir . '/grade/constants.php');
require_once($CFG->libdir . '/grade/grade_category.php');
@ -52,7 +45,10 @@ require_once($CFG->libdir . '/grade/grade_outcome.php');
* 'grademin', 'scaleid', 'multfactor', 'plusfactor', 'deleted' and 'hidden'. 'reset' means delete all current grades including locked ones.
*
* Manual, course or category items can not be updated by this function.
* @public
* @access public
* @global object
* @global object
* @global object
* @param string $source source of the grade such as 'mod/assignment'
* @param int $courseid id of course
* @param string $itemtype type of grade item - mod, block
@ -304,7 +300,8 @@ function grade_update($source, $courseid, $itemtype, $itemmodule, $iteminstance,
/**
* Updates outcomes of user
* Manual outcomes can not be updated.
* @public
*
* @access public
* @param string $source source of the grade such as 'mod/assignment'
* @param int $courseid id of course
* @param string $itemtype 'mod', 'block'
@ -328,13 +325,15 @@ function grade_update_outcomes($source, $courseid, $itemtype, $itemmodule, $item
/**
* Returns grading information for given activity - optionally with users grades
* Manual, course or category items can not be queried.
* @public
*
* @access public
* @global object
* @param int $courseid id of course
* @param string $itemtype 'mod', 'block'
* @param string $itemmodule 'forum, 'quiz', etc.
* @param int $iteminstance id of the item module
* @param int $userid_or_ids optional id of the graded user or array of ids; if userid not used, returns only information about grade_item
* @return array of grade information objects (scaleid, name, grade and locked status, etc.) indexed with itemnumbers
* @return array Array of grade information objects (scaleid, name, grade and locked status, etc.) indexed with itemnumbers
*/
function grade_get_grades($courseid, $itemtype, $itemmodule, $iteminstance, $userid_or_ids=null) {
global $CFG;
@ -547,8 +546,11 @@ function grade_get_grades($courseid, $itemtype, $itemmodule, $iteminstance, $use
/**
* Returns course gradebook setting
*
* @global object
* @param int $courseid
* @param string $name of setting, maybe null if reset only
* @param string $default
* @param bool $resetcache force reset of internal static cache
* @return string value, NULL if no setting
*/
@ -583,6 +585,8 @@ function grade_get_setting($courseid, $name, $default=null, $resetcache=false) {
/**
* Returns all course gradebook settings as object properties
*
* @global object
* @param int $courseid
* @return object
*/
@ -603,6 +607,8 @@ function grade_get_settings($courseid) {
/**
* Add/update course gradebook setting
*
* @global object
* @param int $courseid
* @param string $name of setting
* @param string value, NULL means no setting==remove
@ -633,11 +639,12 @@ function grade_set_setting($courseid, $name, $value) {
/**
* Returns string representation of grade value
*
* @param float $value grade value
* @param object $grade_item - by reference to prevent scale reloading
* @param bool $localized use localised decimal separator
* @param int $displaytype type of display - GRADE_DISPLAY_TYPE_REAL, GRADE_DISPLAY_TYPE_PERCENTAGE, GRADE_DISPLAY_TYPE_LETTER
* @param int $decimalplaces number of decimal places when displaying float values
* @param int $decimals number of decimal places when displaying float values
* @return string
*/
function grade_format_gradevalue($value, &$grade_item, $localized=true, $displaytype=null, $decimals=null) {
@ -701,6 +708,9 @@ function grade_format_gradevalue($value, &$grade_item, $localized=true, $display
}
}
/**
* @todo Document this function
*/
function grade_format_gradevalue_real($value, $grade_item, $decimals, $localized) {
if ($grade_item->gradetype == GRADE_TYPE_SCALE) {
if (!$scale = $grade_item->load_scale()) {
@ -714,7 +724,9 @@ function grade_format_gradevalue_real($value, $grade_item, $decimals, $localized
return format_float($value, $decimals, $localized);
}
}
/**
* @todo Document this function
*/
function grade_format_gradevalue_percentage($value, $grade_item, $decimals, $localized) {
$min = $grade_item->grademin;
$max = $grade_item->grademax;
@ -725,7 +737,9 @@ function grade_format_gradevalue_percentage($value, $grade_item, $decimals, $loc
$percentage = (($value-$min)*100)/($max-$min);
return format_float($percentage, $decimals, $localized).' %';
}
/**
* @todo Document this function
*/
function grade_format_gradevalue_letter($value, $grade_item) {
$context = get_context_instance(CONTEXT_COURSE, $grade_item->courseid);
if (!$letters = grade_get_letters($context)) {
@ -749,6 +763,7 @@ function grade_format_gradevalue_letter($value, $grade_item) {
/**
* Returns grade options for gradebook category menu
*
* @param int $courseid
* @param bool $includenew include option for new category (-1)
* @return array of grade categories in course
@ -783,6 +798,7 @@ function grade_get_categories_menu($courseid, $includenew=false) {
/**
* Returns grade letters array used in context
*
* @param object $context object or null for defaults
* @return array of grade_boundary=>letter_string
*/
@ -830,10 +846,12 @@ function grade_get_letters($context=null) {
/**
* Verify new value of idnumber - checks for uniqueness of new idnumbers, old are kept intact
*
* @global object
* @param string idnumber string (with magic quotes)
* @param int $courseid - id numbers are course unique only
* @param int $courseid id numbers are course unique only
* @param object $grade_item is item idnumber
* @param object $cm used for course module idnumbers and items attached to modules
* @param object $gradeitem is item idnumber
* @return boolean true means idnumber ok
*/
function grade_verify_idnumber($idnumber, $courseid, $grade_item=null, $cm=null) {
@ -864,6 +882,8 @@ function grade_verify_idnumber($idnumber, $courseid, $grade_item=null, $cm=null)
/**
* Force final grade recalculation in all course items
*
* @global object
* @param int $courseid
*/
function grade_force_full_regrading($courseid) {
@ -873,6 +893,8 @@ function grade_force_full_regrading($courseid) {
/**
* Forces regrading of all site grades - usualy when chanign site setings
* @global object
* @global object
*/
function grade_force_site_regrading() {
global $CFG, $DB;
@ -998,9 +1020,12 @@ function grade_regrade_final_grades($courseid, $userid=null, $updated_item=null)
/**
* Refetches data from all course activities
*
* @global object
* @global object
* @param int $courseid
* @param string $modname
* @return success
* @return void
*/
function grade_grab_course_grades($courseid, $modname=null) {
global $CFG, $DB;
@ -1049,7 +1074,11 @@ function grade_grab_course_grades($courseid, $modname=null) {
/**
* Force full update of module grades in central gradebook
*
* @global object
* @global object
* @param object $modinstance object with extra cmidnumber and modname property
* @param int $userid
* @return boolean success
*/
function grade_update_mod_grades($modinstance, $userid=0) {
@ -1079,7 +1108,10 @@ function grade_update_mod_grades($modinstance, $userid=0) {
/**
* Remove grade letters for given context
*
* @global object
* @param object $context
* @param bool $showfeedback
*/
function remove_grade_letters($context, $showfeedback) {
global $DB;
@ -1093,6 +1125,8 @@ function remove_grade_letters($context, $showfeedback) {
}
/**
* Remove all grade related course data - history is kept
*
* @global object
* @param int $courseid
* @param bool $showfeedback print feedback
*/
@ -1134,6 +1168,8 @@ function remove_course_grades($courseid, $showfeedback) {
/**
* Called when course category deleted - cleanup gradebook
*
* @global object
* @param int $categoryid course category id
* @param int $newparentid empty means everything deleted, otherwise id of category where content moved
* @param bool $showfeedback print feedback
@ -1147,6 +1183,10 @@ function grade_course_category_delete($categoryid, $newparentid, $showfeedback)
/**
* Does gradebook cleanup when module uninstalled.
*
* @global object
* @global object
* @param string $modname
*/
function grade_uninstalled_module($modname) {
global $CFG, $DB;
@ -1167,6 +1207,9 @@ function grade_uninstalled_module($modname) {
/**
* Grading cron job
*
* @global object
* @global object
*/
function grade_cron() {
global $CFG, $DB;
@ -1221,8 +1264,9 @@ function grade_cron() {
/**
* Resel all course grades
*
* @param int $courseid
* @return success
* @return bool success
*/
function grade_course_reset($courseid) {
@ -1245,7 +1289,8 @@ function grade_course_reset($courseid) {
/**
* Convert number to 5 decimalfloat, empty tring or null db compatible format
* (we need this to decide if db value changed)
* @param mixed number
*
* @param mixed $number
* @return mixed float or null
*/
function grade_floatval($number) {
@ -1260,9 +1305,10 @@ function grade_floatval($number) {
/**
* Compare two float numbers safely. Uses 5 decimals php precision. Nulls accepted too.
* Used for skipping of db updates
*
* @param float $f1
* @param float $f2
* @return true if different
* @return bool true if different
*/
function grade_floats_different($f1, $f2) {
// note: db rounding for 10,5 is different from php round() function