| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Source view] [Print] [Project Stats]
moodlelib.php - Moodle main library Main library file of miscellaneous general-purpose Moodle functions. Other main libraries: - weblib.php - functions that produce web output - datalib.php - functions that access the database
| Author: | Martin Dougiamas |
| License: | http://www.gnu.org/copyleft/gpl.html GNU Public License |
| Version: | $Id$ |
| File Size: | 8254 lines (274 kb) |
| Included or required: | 0 times |
| Referenced: | 2 times |
| Includes or requires: | 2 files lib/locallib.php version.php |
| required_param($parname, $type=PARAM_CLEAN) X-Ref |
| Returns a particular value for the named variable, taken from POST or GET. If the parameter doesn't exist then an error is thrown because we require this variable. This function should be used to initialise all required values in a script that are based on parameters. Usually it will be used like this: $id = required_param('id'); param: string $parname the name of the page parameter we want param: int $type expected type of parameter return: mixed |
| optional_param($parname, $default=NULL, $type=PARAM_CLEAN) X-Ref |
| Returns a particular value for the named variable, taken from POST or GET, otherwise returning a given default. This function should be used to initialise all optional values in a script that are based on parameters. Usually it will be used like this: $name = optional_param('name', 'Fred'); param: string $parname the name of the page parameter we want param: mixed $default the default value to return if nothing is found param: int $type expected type of parameter return: mixed |
| clean_param($param, $type) X-Ref |
| Used by {@link optional_param()} and {@link required_param()} to clean the variables and/or cast to specific types, based on an options field. <code> $course->format = clean_param($course->format, PARAM_ALPHA); $selectedgrade_item = clean_param($selectedgrade_item, PARAM_CLEAN); </code> param: mixed $param the variable we are cleaning param: int $type expected format of param after cleaning. return: mixed |
| html_is_blank($string) X-Ref |
| This function is useful for testing whether something you got back from the HTML editor actually contains anything. Sometimes the HTML editor appear to be empty, but actually you get back a <br> tag or something. param: string $string a string containing HTML. return: boolean does the string contain any actual content - that is text, |
| set_config($name, $value, $plugin=NULL) X-Ref |
| Set a key in global configuration Set a key/value pair in both this session's {@link $CFG} global variable and in the 'config' database table for future sessions. Can also be used to update keys for plugin-scoped configs in config_plugin table. In that case it doesn't affect $CFG. A NULL value will delete the entry. param: string $name the key to set param: string $value the value to set (without magic quotes) param: string $plugin (optional) the plugin scope return: bool |
| get_config($plugin=NULL, $name=NULL) X-Ref |
| Get configuration values from the global config table or the config_plugins table. If called with no parameters it will do the right thing generating $CFG safely from the database without overwriting existing values. If called with 2 parameters it will return a $string single value or false of the value is not found. param: string $plugin param: string $name return: hash-like object or single value |
| unset_config($name, $plugin=NULL) X-Ref |
| Removes a key from global configuration param: string $name the key to set param: string $plugin (optional) the plugin scope return: bool |
| get_cache_flags($type, $changedsince=NULL) X-Ref |
| Get volatile flags param: string $type param: int $changedsince return: records array |
| get_cache_flag($type, $name, $changedsince=NULL) X-Ref |
| Get volatile flags param: string $type param: string $name param: int $changedsince return: records array |
| set_cache_flag($type, $name, $value, $expiry=NULL) X-Ref |
| Set a volatile flag param: string $type the "type" namespace for the key param: string $name the key to set param: string $value the value to set (without magic quotes) - NULL will remove the flag param: int $expiry (optional) epoch indicating expiry - defaults to now()+ 24hs return: bool |
| unset_cache_flag($type, $name) X-Ref |
| Removes a single volatile flag param: string $type the "type" namespace for the key param: string $name the key to set return: bool |
| gc_cache_flags() X-Ref |
| Garbage-collect volatile flags |
| reload_user_preferences() X-Ref |
| Refresh current $USER session global variable with all their current preferences. |
| set_user_preference($name, $value, $otheruserid=NULL) X-Ref |
| Sets a preference for the current user Optionally, can set a preference for a different user object param: string $name The key to set as preference for the specified user param: string $value The value to set forthe $name key in the specified user's record param: int $otheruserid A moodle user ID return: bool |
| unset_user_preference($name, $otheruserid=NULL) X-Ref |
| Unsets a preference completely by deleting it from the database Optionally, can set a preference for a different user id param: string $name The key to unset as preference for the specified user param: int $otheruserid A moodle user ID |
| set_user_preferences($prefarray, $otheruserid=NULL) X-Ref |
| Sets a whole array of preferences for the current user param: array $prefarray An array of key/value pairs to be set param: int $otheruserid A moodle user ID return: bool |
| get_user_preferences($name=NULL, $default=NULL, $otheruserid=NULL) X-Ref |
| If no arguments are supplied this function will return all of the current user preferences as an array. If a name is specified then this function attempts to return that particular preference value. If none is found, then the optional value $default is returned, otherwise NULL. param: string $name Name of the key to use in finding a preference value param: string $default Value to be returned if the $name key is not set in the user preferences param: int $otheruserid A moodle user ID return: string |
| make_timestamp($year, $month=1, $day=1, $hour=0, $minute=0, $second=0, $timezone=99, $applydst=true) X-Ref |
| Given date parts in user time produce a GMT timestamp. param: int $year The year part to create timestamp of param: int $month The month part to create timestamp of param: int $day The day part to create timestamp of param: int $hour The hour part to create timestamp of param: int $minute The minute part to create timestamp of param: int $second The second part to create timestamp of param: float $timezone ? param: bool $applydst ? return: int timestamp |
| format_time($totalsecs, $str=NULL) X-Ref |
| Given an amount of time in seconds, returns string formatted nicely as weeks, days, hours etc as needed param: int $totalsecs ? param: array $str ? return: string |
| userdate($date, $format='', $timezone=99, $fixday = true) X-Ref |
| Returns a formatted string that represents a date in user time <b>WARNING: note that the format is for strftime(), not date().</b> Because of a bug in most Windows time libraries, we can't use the nicer %e, so we have to use %d which has leading zeroes. A lot of the fuss in the function is just getting rid of these leading zeroes as efficiently as possible. If parameter fixday = true (default), then take off leading zero from %d, else mantain it. param: int $date timestamp in GMT param: string $format strftime format param: float $timezone param: bool $fixday If true (default) then the leading return: string |
| usergetdate($time, $timezone=99) X-Ref |
| Given a $time timestamp in GMT (seconds since epoch), returns an array that represents the date in user time param: int $time Timestamp in GMT param: float $timezone ? return: array An array that represents the date in user time |
| usertime($date, $timezone=99) X-Ref |
| Given a GMT timestamp (seconds since epoch), offsets it by the timezone. eg 3pm in India is 3pm GMT - 7 * 3600 seconds param: int $date Timestamp in GMT param: float $timezone return: int |
| usergetmidnight($date, $timezone=99) X-Ref |
| Given a time, return the GMT timestamp of the most recent midnight for the current user. param: int $date Timestamp in GMT param: float $timezone ? return: ? |
| usertimezone($timezone=99) X-Ref |
| Returns a string that prints the user's timezone param: float $timezone The user's timezone return: string |
| get_user_timezone_offset($tz = 99) X-Ref |
| Returns a float which represents the user's timezone difference from GMT in hours Checks various settings and picks the most dominant of those which have a value param: float $tz If this value is provided and not equal to 99, it will be returned as is and no other settings will be checked return: int |
| get_timezone_offset($tz) X-Ref |
| Returns an int which represents the systems's timezone difference from GMT in seconds param: mixed $tz timezone return: int if found, false is timezone 99 or error |
| get_user_timezone($tz = 99) X-Ref |
| Returns a float or a string which denotes the user's timezone A float value means that a simple offset from GMT is used, while a string (it will be the name of a timezone in the database) means that for this timezone there are also DST rules to be taken into account Checks various settings and picks the most dominant of those which have a value param: float $tz If this value is provided and not equal to 99, it will be returned as is and no other settings will be checked return: mixed |
| get_timezone_record($timezonename) X-Ref |
| ? param: string $timezonename ? return: object |
| calculate_user_dst_table($from_year = NULL, $to_year = NULL, $strtimezone = NULL) X-Ref |
| ? param: ? $fromyear ? param: ? $to_year ? return: bool |
| dst_changes_for_year($year, $timezone) X-Ref |
| No description |
| dst_offset_on($time, $strtimezone = NULL) X-Ref |
| No description |
| find_day_in_month($startday, $weekday, $month, $year) X-Ref |
| No description |
| days_in_month($month, $year) X-Ref |
| Calculate the number of days in a given month param: int $month The month whose day count is sought param: int $year The year of the month whose day count is sought return: int |
| dayofweek($day, $month, $year) X-Ref |
| Calculate the position in the week of a specific calendar day param: int $day The day of the date whose position in the week is sought param: int $month The month of the date whose position in the week is sought param: int $year The year of the date whose position in the week is sought return: int |
| sesskey() X-Ref |
| Makes sure that $USER->sesskey exists, if $USER itself exists. It sets a new sesskey if one does not already exist, but does not overwrite existing sesskeys. Returns the sesskey string if $USER exists, or boolean false if not. return: string |
| confirm_sesskey($sesskey=NULL) X-Ref |
| For security purposes, this function will check that the currently given sesskey (passed as a parameter to the script or this function) matches that of the current user. param: string $sesskey optionally provided sesskey return: bool |
| course_setup($courseorid=0) X-Ref |
| Setup all global $CFG course variables, set locale and also themes This function can be used on pages that do not require login instead of require_login() param: mixed $courseorid id of the course or course object |
| require_login($courseorid=0, $autologinguest=true, $cm=null, $setwantsurltome=true) X-Ref |
| This function checks that the current user is logged in and has the required privileges This function checks that the current user is logged in, and optionally whether they are allowed to be in a particular course and view a particular course module. If they are not logged in, then it redirects them to the site login unless $autologinguest is set and {@link $CFG}->autologinguests is set to 1 in which case they are automatically logged in as guests. If $courseid is given and the user is not enrolled in that course then the user is redirected to the course enrolment page. If $cm is given and the coursemodule is hidden and the user is not a teacher in the course then the user is redirected to the course home page. param: mixed $courseorid id of the course or course object param: bool $autologinguest param: object $cm course module object param: bool $setwantsurltome Define if we want to set $SESSION->wantsurl, defaults to |
| require_logout() X-Ref |
| This function just makes sure a user is logged out. |
| require_course_login($courseorid, $autologinguest=true, $cm=null, $setwantsurltome=true) X-Ref |
| This is a weaker version of {@link require_login()} which only requires login when called from within a course rather than the site page, unless the forcelogin option is turned on. param: mixed $courseorid The course object or id in question param: bool $autologinguest Allow autologin guests if that is wanted param: object $cm Course activity module if known param: bool $setwantsurltome Define if we want to set $SESSION->wantsurl, defaults to |
| require_user_key_login($script, $instance=null) X-Ref |
| Require key login. Function terminates with error if key not found or incorrect. param: string $script unique script identifier param: int $instance optional instance id |
| create_user_key($script, $userid, $instance=null, $iprestriction=null, $validuntil=null) X-Ref |
| Creates a new private user access key. param: string $script unique target identifier param: int $userid param: instance $int optional instance id param: string $iprestriction optional ip restricted access param: timestamp $validuntil key valid only until given data return: string access key value |
| update_user_login_times() X-Ref |
| Modify the user table by setting the currently logged in user's last login to now. return: bool |
| user_not_fully_set_up($user) X-Ref |
| Determines if a user has completed setting up their account. param: user $user A {@link $USER} object to test for the existance of a valid name and email return: bool |
| over_bounce_threshold($user) X-Ref |
| No description |
| set_send_count($user,$reset=false) X-Ref |
param: $user - object containing an id param: $reset - will reset the count to 0 |
| set_bounce_count($user,$reset=false) X-Ref |
param: $user - object containing an id param: $reset - will reset the count to 0 |
| update_login_count() X-Ref |
| Keeps track of login attempts |
| reset_login_count() X-Ref |
| Resets login attempts |
| sync_metacourses() X-Ref |
| No description |
| sync_metacourse($course) X-Ref |
| Goes through all enrolment records for the courses inside the metacourse and sync with them. param: mixed $course the metacourse to synch. Either the course object itself, or the courseid. |
| add_to_metacourse($metacourseid, $courseid) X-Ref |
| Adds a record to the metacourse table and calls sync_metacoures |
| remove_from_metacourse($metacourseid, $courseid) X-Ref |
| Removes the record from the metacourse table and calls sync_metacourse |
| isloggedin() X-Ref |
| Determines if a user is currently logged in return: bool |
| isguestuser($user=NULL) X-Ref |
| Determines if a user is logged in as real guest user with username 'guest'. This function is similar to original isguest() in 1.6 and earlier. Current isguest() is deprecated - do not use it anymore. param: $user mixed user object or id, $USER if not specified return: bool true if user is the real guest user, false if not logged in or other user |
| isediting() X-Ref |
| Determines if the currently logged in user is in editing mode. Note: originally this function had $userid parameter - it was not usable anyway return: bool |
| ismoving($courseid) X-Ref |
| Determines if the logged in user is currently moving an activity param: int $courseid The id of the course being tested return: bool |
| fullname($user, $override=false) X-Ref |
| Given an object containing firstname and lastname values, this function returns a string with the full name of the person. The result may depend on system settings or language. 'override' will force both names to be used even if system settings specify one. param: object $user A {@link $USER} object to get full name of param: bool $override If true then the name will be first name followed by last name rather than adhering to fullnamedisplay setting. |
| set_moodle_cookie($thing) X-Ref |
| Sets a moodle cookie with an encrypted string param: string $thing The string to encrypt and place in a cookie |
| get_moodle_cookie() X-Ref |
| Gets a moodle cookie with an encrypted string return: string |
| exists_auth_plugin($auth) X-Ref |
| Returns whether a given authentication plugin exists. param: string $auth Form of authentication to check for. Defaults to the return: boolean Whether the plugin is available. |
| is_enabled_auth($auth) X-Ref |
| Checks if a given plugin is in the list of enabled authentication plugins. param: string $auth Authentication plugin. return: boolean Whether the plugin is enabled. |
| get_auth_plugin($auth) X-Ref |
| Returns an authentication plugin instance. param: string $auth name of authentication plugin return: object An instance of the required authentication plugin. |
| get_enabled_auth_plugins($fix=false) X-Ref |
| Returns array of active auth plugins. param: bool $fix fix $CFG->auth if needed return: array |
| is_internal_auth($auth) X-Ref |
| Returns true if an internal authentication method is being used. if method not specified then, global default is assumed param: string $auth Form of authentication required return: bool |
| get_user_fieldnames() X-Ref |
| Returns an array of user fields return: array User field/column names |
| create_guest_record() X-Ref |
| Creates the default "guest" user. Used both from admin/index.php and login/index.php return: mixed user object created or boolean false if the creation has failed |
| create_user_record($username, $password, $auth='manual') X-Ref |
| Creates a bare-bones user record param: string $username New user's username to add to record param: string $password New user's password to add to record param: string $auth Form of authentication required return: object A {@link $USER} object |
| update_user_record($username, $authplugin) X-Ref |
| Will update a local user record from an external source param: string $username New user's username to add to record return: user A {@link $USER} object |
| truncate_userinfo($info) X-Ref |
| No description |
| delete_user($user) X-Ref |
| Marks user deleted in internal user database and notifies the auth plugin. Also unenrols user from all roles and does other cleanup. param: object $user Userobject before delete (without system magic quotes) return: boolean success |
| guest_user() X-Ref |
| Retrieve the guest user object return: user A {@link $USER} object |
| authenticate_user_login($username, $password) X-Ref |
| Given a username and password, this function looks them up using the currently selected authentication mechanism, and if the authentication is successful, it returns a valid $user object from the 'user' table. Uses auth_ functions from the currently active auth module After authenticate_user_login() returns success, you will need to log that the user has logged in, and call complete_user_login() to set the session up. param: string $username User's username (with system magic quotes) param: string $password User's password (with system magic quotes) return: user|flase A {@link $USER} object or false if error |
| complete_user_login($user) X-Ref |
| Call to complete the user login process after authenticate_user_login() has succeeded. It will setup the $USER variable and other required bits and pieces. NOTE: - It will NOT log anything -- up to the caller to decide what to log. param: string $user obj return: user|flase A {@link $USER} object or false if error |
| validate_internal_user_password(&$user, $password) X-Ref |
| Compare password against hash stored in internal user table. If necessary it also updates the stored hash to new format. param: object user param: string plain text password return: bool is password valid? |
| hash_internal_user_password($password) X-Ref |
| Calculate hashed value from password using current hash mechanism. param: string password return: string password hash |
| update_internal_user_password(&$user, $password) X-Ref |
| Update pssword hash in user object. param: object user param: string plain text password param: bool store changes also in db, default true return: true if hash changed |
| get_complete_user_data($field, $value, $mnethostid=null) X-Ref |
| Get a complete user record, which includes all the info in the user record Intended for setting as $USER session variable param: string $field The user field to be checked for a given value. param: string $value The value to match for $field. return: user A {@link $USER} object. |
| check_password_policy($password, &$errmsg) X-Ref |
param: string $password the password to be checked agains the password policy param: string $errmsg the error message to display when the password doesn't comply with the policy. return: bool true if the password is valid according to the policy. false otherwise. |
| set_login_session_preferences() X-Ref |
| When logging in, this function is run to set certain preferences for the current SESSION |
| delete_course($courseorid, $showfeedback = true) X-Ref |
| Delete a course, including all related data from the database, and any associated files from the moodledata folder. param: mixed $courseorid The id of the course or course object to delete. param: bool $showfeedback Whether to display notifications of each action the function performs. return: bool true if all the removals succeeded. false if there were any failures. If this |
| remove_course_contents($courseid, $showfeedback=true) X-Ref |
| Clear a course out completely, deleting all content but don't delete the course itself param: int $courseid The id of the course that is being deleted param: bool $showfeedback Whether to display notifications of each action the function performs. return: bool true if all the removals succeeded. false if there were any failures. If this |
| shift_course_mod_dates($modname, $fields, $timeshift, $courseid) X-Ref |
| Change dates in module - used from course reset. param: strin $modname forum, assignent, etc param: array $fields array of date fields from mod table param: int $timeshift time difference return: success |
| reset_course_userdata($data) X-Ref |
| This function will empty a course of user data. It will retain the activities and the structure of the course. param: object $data an object containing all the settings including courseid (without magic quotes) return: array status array of array component, item, error |
| generate_email_processing_address($modid,$modargs) X-Ref |
| No description |
| moodle_process_email($modargs,$body) X-Ref |
| No description |
| get_mailer($action='get') X-Ref |
| Get mailer instance, enable buffering, flush buffer or disable buffering. param: $action string 'get', 'buffer', 'close' or 'flush' return: reference to mailer instance if 'get' used or nothing |
| email_to_user($user, $from, $subject, $messagetext, $messagehtml='', $attachment='', $attachname='', $usetrueaddress=true, $replyto='', $replytoname='', $wordwrapwidth=79) X-Ref |
| Send an email to a specified user param: user $user A {@link $USER} object param: user $from A {@link $USER} object param: string $subject plain text subject line of the email param: string $messagetext plain text version of the message param: string $messagehtml complete html version of the message (optional) param: string $attachment a file on the filesystem, relative to $CFG->dataroot param: string $attachname the name of the file (extension indicates MIME) param: bool $usetrueaddress determines whether $from email address should param: int $wordwrapwidth custom word wrap width return: bool|string Returns "true" if mail was sent OK, "emailstop" if email |
| generate_email_signoff() X-Ref |
| Generate a signoff for emails based on support settings |
| generate_email_supportuser() X-Ref |
| Generate a fake user for emails based on support settings |
| setnew_password_and_mail($user) X-Ref |
| Sets specified user's password and send the new password to the user via email. param: user $user A {@link $USER} object return: boolean|string Returns "true" if mail was sent OK, "emailstop" if email |
| reset_password_and_mail($user) X-Ref |
| Resets specified user's password and send the new password to the user via email. param: user $user A {@link $USER} object return: bool|string Returns "true" if mail was sent OK, "emailstop" if email |
| send_confirmation_email($user) X-Ref |
| Send email to specified user with confirmation text and activation link. param: user $user A {@link $USER} object return: bool|string Returns "true" if mail was sent OK, "emailstop" if email |
| send_password_change_confirmation_email($user) X-Ref |
| send_password_change_confirmation_email. param: user $user A {@link $USER} object return: bool|string Returns "true" if mail was sent OK, "emailstop" if email |
| send_password_change_info($user) X-Ref |
| send_password_change_info. param: user $user A {@link $USER} object return: bool|string Returns "true" if mail was sent OK, "emailstop" if email |
| email_is_not_allowed($email) X-Ref |
| Check that an email is allowed. It returns an error message if there was a problem. param: string $email Content of email return: string|false |
| email_welcome_message_to_user($course, $user=NULL) X-Ref |
| No description |
| make_mod_upload_directory($courseid) X-Ref |
| Makes an upload directory for a particular module. param: int $courseid The id of the course in question - maps to id field of 'course' table. return: string|false Returns full path to directory if successful, false if not |
| make_user_directory($userid, $test=false) X-Ref |
| Makes a directory for a particular user. param: int $userid The id of the user in question - maps to id field of 'user' table. param: bool $test Whether we are only testing the return value (do not create the directory) return: string|false Returns full path to directory if successful, false if not |
| get_user_directories($only_non_empty=true, $legacy=false) X-Ref |
| Returns an array of full paths to user directories, indexed by their userids. param: bool $only_non_empty Only return directories that contain files param: bool $legacy Search for user directories in legacy location (dataroot/users/userid) instead of (dataroot/user/section/userid) return: array An associative array: userid=>array(basedir => $basedir, userfolder => $userfolder) |
| valid_uploaded_file($newfile) X-Ref |
| Returns current name of file on disk if it exists. param: string $newfile File to be verified return: string Current name of file on disk if true |
| get_max_upload_file_size($sitebytes=0, $coursebytes=0, $modulebytes=0) X-Ref |
| Returns the maximum size for uploading files. There are seven possible upload limits: 1. in Apache using LimitRequestBody (no way of checking or changing this) 2. in php.ini for 'upload_max_filesize' (can not be changed inside PHP) 3. in .htaccess for 'upload_max_filesize' (can not be changed inside PHP) 4. in php.ini for 'post_max_size' (can not be changed inside PHP) 5. by the Moodle admin in $CFG->maxbytes 6. by the teacher in the current course $course->maxbytes 7. by the teacher for the current module, eg $assignment->maxbytes These last two are passed to this function as arguments (in bytes). Anything defined as 0 is ignored. The smallest of all the non-zero numbers is returned. param: int $sizebytes ? param: int $coursebytes Current course $course->maxbytes (in bytes) param: int $modulebytes Current module ->maxbytes (in bytes) return: int The maximum size for uploading files. |
| get_max_upload_sizes($sitebytes=0, $coursebytes=0, $modulebytes=0) X-Ref |
| Related to {@link get_max_upload_file_size()} - this function returns an array of possible sizes in an array, translated to the local language. param: int $sizebytes ? param: int $coursebytes Current course $course->maxbytes (in bytes) param: int $modulebytes Current module ->maxbytes (in bytes) return: int |
| print_file_upload_error($filearray = '', $returnerror = false) X-Ref |
| If there has been an error uploading a file, print the appropriate error message Numerical constants used as constant definitions not added until PHP version 4.2.0 $filearray is a 1-dimensional sub-array of the $_FILES array eg $filearray = $_FILES['userfile1'] If left empty then the first element of the $_FILES array will be used param: array $filearray A 1-dimensional sub-array of the $_FILES array param: bool $returnerror If true then a string error message will be returned. Otherwise the user will be notified of the error in a notify() call. return: bool|string |
| resolve_filename_collisions($destination,$files,$format='%s_%d.%s') X-Ref |
| handy function to loop through an array of files and resolve any filename conflicts both in the array of filenames and for what is already on disk. not really compatible with the similar function in uploadlib.php but this could be used for files/index.php for moving files around. |
| check_potential_filename($destination,$filename,$files) X-Ref |
| get_directory_list($rootdir, $excludefiles='', $descend=true, $getdirs=false, $getfiles=true) X-Ref |
| Returns an array with all the filenames in all subdirectories, relative to the given rootdir. If excludefile is defined, then that file/directory is ignored If getdirs is true, then (sub)directories are included in the output If getfiles is true, then files are included in the output (at least one of these must be true!) param: string $rootdir ? param: string $excludefile If defined then the specified file/directory is ignored param: bool $descend ? param: bool $getdirs If true then (sub)directories are included in the output param: bool $getfiles If true then files are included in the output return: array An array with all the filenames in |
| get_directory_size($rootdir, $excludefile='') X-Ref |
| Adds up all the files in a directory and works out the size. param: string $rootdir ? param: string $excludefile ? return: array |
| display_size($size) X-Ref |
| Converts bytes into display form param: string $size ? return: string |
| clean_filename($string) X-Ref |
| Cleans a given filename by removing suspicious or troublesome characters Only these are allowed: alphanumeric _ - . Unicode characters can be enabled by setting $CFG->unicodecleanfilename = true in config.php WARNING: unicode characters may not be compatible with zip compression in backup/restore, because native zip binaries do weird character conversions. Use PHP zipping instead. param: string $string file name return: string cleaned file name |
| current_language() X-Ref |
| Returns the code for the current language param: $USER param: $SESSION return: string |
| print_string($identifier, $module='', $a=NULL) X-Ref |
| Prints out a translated string. Prints out a translated string using the return value from the {@link get_string()} function. Example usage of this function when the string is in the moodle.php file:<br/> <code> echo '<strong>'; print_string('wordforstudent'); echo '</strong>'; </code> Example usage of this function when the string is not in the moodle.php file:<br/> <code> echo '<h1>'; print_string('typecourse', 'calendar'); echo '</h1>'; </code> param: string $identifier The key identifier for the localized string param: string $module The module where the key identifier is stored. If none is specified then moodle.php is used. param: mixed $a An object, string or number that can be used |
| clean_getstring_data( $a ) X-Ref |
| fix up the optional data in get_string()/print_string() etc ensure possible sprintf() format characters are escaped correctly needs to handle arbitrary strings and objects param: mixed $a An object, string or number that can be used return: mixed the supplied parameter 'cleaned' |
| places_to_search_for_lang_strings() X-Ref |
return: array places to look for lang strings based on the prefix to the |
| get_string($identifier, $module='', $a=NULL, $extralocations=NULL) X-Ref |
| Returns a localized string. Returns the translated string specified by $identifier as for $module. Uses the same format files as STphp. $a is an object, string or number that can be used within translation strings eg "hello \$a->firstname \$a->lastname" or "hello \$a" If you would like to directly echo the localized string use the function {@link print_string()} Example usage of this function involves finding the string you would like a local equivalent of and using its identifier and module information to retrive it.<br/> If you open moodle/lang/en/moodle.php and look near line 1031 you will find a string to prompt a user for their word for student <code> $string['wordforstudent'] = 'Your word for Student'; </code> So if you want to display the string 'Your word for student' in any language that supports it on your site you just need to use the identifier 'wordforstudent' <code> $mystring = '<strong>'. get_string('wordforstudent') .'</strong>'; </code> If the string you want is in another file you'd take a slightly different approach. Looking in moodle/lang/en/calendar.php you find around line 75: <code> $string['typecourse'] = 'Course event'; </code> If you want to display the string "Course event" in any language supported you would use the identifier 'typecourse' and the module 'calendar' (because it is in the file calendar.php): <code> $mystring = '<h1>'. get_string('typecourse', 'calendar') .'</h1>'; </code> As a last resort, should the identifier fail to map to a string the returned string will be [[ $identifier ]] param: string $identifier The key identifier for the localized string param: string $module The module where the key identifier is stored, usually expressed as the filename in the language pack without the .php on the end but can also be written as mod/forum or grade/export/xls. If none is specified then moodle.php is used. param: mixed $a An object, string or number that can be used param: array $extralocations An array of strings with other locations to look for string files return: string The localized string. |
| get_string_from_file($identifier, $langfile, $destination) X-Ref |
| This function is only used from {@link get_string()}. param: string $identifier ? param: string $langfile ? param: string $destination ? return: string|false ? |
| get_strings($array, $module='') X-Ref |
| Converts an array of strings to their localized value. param: array $array An array of strings param: string $module The language module that these strings can be found in. return: string |
| get_list_of_languages($refreshcache=false, $returnall=false) X-Ref |
| Returns a list of language codes and their full names hides the _local files from everyone. param: bool refreshcache force refreshing of lang cache param: bool returnall ignore langlist, return all languages available return: array An associative array with contents in the form of LanguageCode => LanguageName |
| get_list_of_charsets() X-Ref |
| Returns a list of charset codes. It's hardcoded, so they should be added manually (cheking that such charset is supported by the texlib library!) return: array And associative array with contents in the form of charset => charset |
| get_list_of_countries() X-Ref |
| Returns a list of country names in the current language return: array |
| get_list_of_themes() X-Ref |
| Returns a list of valid and compatible themes return: array |
| get_list_of_pixnames($lang = '') X-Ref |
| Returns a list of picture names in the current or specified language return: array |
| get_list_of_timezones() X-Ref |
| Returns a list of timezones in the current language return: array |
| get_list_of_currencies() X-Ref |
| Returns a list of currencies in the current language return: array |
| rc4encrypt($data) X-Ref |
| rc4encrypt param: string $data ? return: string |
| rc4decrypt($data) X-Ref |
| rc4decrypt param: string $data ? return: string |
| endecrypt($pwd, $data, $case) X-Ref |
| Based on a class by Mukul Sabharwal [mukulsabharwal @ yahoo.com] param: string $pwd ? param: string $data ? param: string $case ? return: string |
| add_event($event) X-Ref |
| Call this function to add an event to the calendar table and to call any calendar plugins param: array $event An associative array representing an event from the calendar table. The event will be identified by the id field. The object event should include the following: return: int The id number of the resulting record |
| update_event($event) X-Ref |
| Call this function to update an event in the calendar table the event will be identified by the id field of the $event object. param: array $event An associative array representing an event from the calendar table. The event will be identified by the id field. return: bool |
| delete_event($id) X-Ref |
| Call this function to delete the event with id $id from calendar table. param: int $id The id of an event from the 'calendar' table. return: array An associative array with the results from the SQL call. |
| hide_event($event) X-Ref |
| Call this function to hide an event in the calendar table the event will be identified by the id field of the $event object. param: array $event An associative array representing an event from the calendar table. The event will be identified by the id field. return: array An associative array with the results from the SQL call. |
| show_event($event) X-Ref |
| Call this function to unhide an event in the calendar table the event will be identified by the id field of the $event object. param: array $event An associative array representing an event from the calendar table. The event will be identified by the id field. return: array An associative array with the results from the SQL call. |
| get_list_of_plugins($plugin='mod', $exclude='', $basedir='') X-Ref |
| Lists plugin directories within some directory param: string $plugin dir under we'll look for plugins (defaults to 'mod') param: string $exclude dir name to exclude from the list (defaults to none) param: string $basedir full path to the base dir where $plugin resides (defaults to $CFG->dirroot) return: array of plugins found under the requested parameters |
| check_php_version($version='4.1.0') X-Ref |
| Returns true if the current version of PHP is greater that the specified one. param: string $version The version of php being tested. return: bool |
| check_browser_operating_system($brand) X-Ref |
| Checks to see if is the browser operating system matches the specified brand. Known brand: 'Windows','Linux','Macintosh','SGI','SunOS','HP-UX' param: string $brand The operating system identifier being tested return: bool true if the given brand below to the detected operating system |
| check_browser_version($brand='MSIE', $version=5.5) X-Ref |
| Checks to see if is a browser matches the specified brand and is equal or better version. param: string $brand The browser identifier being tested param: int $version The version of the browser return: bool true if the given version is below that of the detected browser |
| ini_get_bool($ini_get_arg) X-Ref |
| This function makes the return value of ini_get consistent if you are setting server directives through the .htaccess file in apache. Current behavior for value set from php.ini On = 1, Off = [blank] Current behavior for value set from .htaccess On = On, Off = Off Contributed by jdell @ unr.edu param: string $ini_get_arg ? return: bool |
| can_use_richtext_editor() X-Ref |
| Compatibility stub to provide backward compatibility Determines if the HTML editor is enabled. |
| can_use_html_editor() X-Ref |
| Determines if the HTML editor is enabled. This depends on site and user settings, as well as the current browser being used. return: string|false Returns false if editor is not being used, otherwise |
| check_gd_version() X-Ref |
| Hack to find out the GD version by parsing phpinfo output return: int GD version (1, 2, or 0) |
| moodle_needs_upgrading() X-Ref |
| Determine if moodle installation requires update Checks version numbers of main code and all modules to see if there are any mismatches return: bool |
| notify_login_failures() X-Ref |
| Notify admin users or admin user of any failed logins (since last notification). Note that this function must be only executed from the cron script It uses the cache_flags system to store temporary records, deleting them by name before finishing |
| moodle_setlocale($locale='') X-Ref |
| moodle_setlocale param: string $locale ? |
| moodle_strtolower($string, $encoding='') X-Ref |
| Converts string to lowercase using most compatible function available. param: string $string The string to convert to all lowercase characters. param: string $encoding The encoding on the string. return: string |
| count_words($string) X-Ref |
| Count words in a string. Words are defined as things between whitespace. param: string $string The text to be searched for words. return: int The count of words in the specified string |
| count_letters($string) X-Ref |
| No description |
| random_string($length=15) X-Ref |
| Generate and return a random string of the specified length. param: int $length The length of the string to be created. return: string |
| shorten_text($text, $ideal=30, $exact = false) X-Ref |
| No description |
| getweek($startdate, $thedate) X-Ref |
| Given dates in seconds, how many weeks is the date from startdate The first week is 1, the second 2 etc ... param: ? $startdate ? param: ? $thedate ? return: string |
| generate_password($maxlen=10) X-Ref |
| returns a randomly generated password of length $maxlen. inspired by {@link http://www.phpbuilder.com/columns/jesus19990502.php3} and {@link http://es2.php.net/manual/en/function.str-shuffle.php#73254} param: int $maxlen The maximum size of the password being generated. return: string |
| format_float($float, $decimalpoints=1, $localized=true) X-Ref |
| Given a float, prints it nicely. Localized floats must not be used in calculations! param: float $flaot The float to print param: int $places The number of decimal places to print. param: bool $localized use localized decimal separator return: string locale float |
| unformat_float($locale_float) X-Ref |
| Converts locale specific floating point/comma number back to standard PHP float value Do NOT try to do any math operations before this conversion on any user submitted floats! param: string $locale_float locale aware float representation |
| swapshuffle($array) X-Ref |
| Given a simple array, this shuffles it up just like shuffle() Unlike PHP's shuffle() this function works on any machine. param: array $array The array to be rearranged return: array |
| swapshuffle_assoc($array) X-Ref |
| Like {@link swapshuffle()}, but works on associative arrays param: array $array The associative array to be rearranged return: array |
| draw_rand_array($array, $draws) X-Ref |
| Given an arbitrary array, and a number of draws, this function returns an array with that amount of items. The indexes are retained. param: array $array ? param: ? $draws ? return: ? |
| microtime_diff($a, $b) X-Ref |
| microtime_diff param: string $a ? param: string $b ? return: string |
| make_menu_from_list($list, $separator=',') X-Ref |
| Given a list (eg a,b,c,d,e) this function returns an array of 1->a, 2->b, 3->c etc param: array $list ? param: string $separator ? |
| make_grades_menu($gradingtype) X-Ref |
| Creates an array that represents all the current grades that can be chosen using the given grading type. Negative numbers are scales, zero is no grade, and positive numbers are maximum grades. param: int $gradingtype ? |
| course_scale_used($courseid, $scaleid) X-Ref |
| This function returns the nummber of activities using scaleid in a courseid param: int $courseid ? param: int $scaleid ? return: int |
| site_scale_used($scaleid,&$courses) X-Ref |
| This function returns the nummber of activities using scaleid in the entire site param: int $scaleid ? return: int |
| make_unique_id_code($extra='') X-Ref |
| make_unique_id_code param: string $extra ? return: string |
| address_in_subnet($addr, $subnetstr) X-Ref |
| Function to check the passed address is within the passed subnet The parameter is a comma separated string of subnet definitions. Subnet strings can be in one of three formats: 1: xxx.xxx.xxx.xxx/xx 2: xxx.xxx 3: xxx.xxx.xxx.xxx-xxx //a range of IP addresses in the last group. Code for type 1 modified from user posted comments by mediator at {@link http://au.php.net/manual/en/function.ip2long.php} param: string $addr The address you are checking param: string $subnetstr The string of subnet addresses return: bool |
| httpsrequired() X-Ref |
| This function sets the $HTTPSPAGEREQUIRED global (used in some parts of moodle to change some links) and calculate the proper wwwroot to be used By using this function properly, we can ensure 100% https-ized pages at our entire discretion (login, forgot_password, change_password) |
| mtrace($string, $eol="\n", $sleep=0) X-Ref |
| For outputting debugging info param: string $string ? param: string $eol ? |
| cleardoubleslashes($path) X-Ref |
| No description |
| zip_files($originalfiles, $destination) X-Ref |
| No description |
| unzip_file($zipfile, $destination = '', $showstatus = true) X-Ref |
| No description |
| unzip_cleanfilename($p_event, &$p_header) X-Ref |
| No description |
| unzip_show_status($list,$removepath) X-Ref |
| No description |
| getremoteaddr() X-Ref |
| Returns most reliable client address return: string The remote IP address |
| cleanremoteaddr($addr) X-Ref |
| Cleans a remote address ready to put into the log table |
| file_put_contents($file, $contents) X-Ref |
| file_put_contents is only supported by php 5.0 and higher so if it is not predefined, define it here param: $file full path of the file to write param: $contents contents to be sent return: number of bytes written (false on error) |
| clone($obj) X-Ref |
| No description |
| scandir($directory) X-Ref |
| No description |
| array_combine($keys, $values) X-Ref |
| No description |
| fullclone($thing) X-Ref |
| This function will make a complete copy of anything it's given, regardless of whether it's an object or not. param: mixed $thing return: mixed |
| moodle_request_shutdown() X-Ref |
| No description |
| message_popup_window() X-Ref |
| If new messages are waiting for the current user, then return Javascript code to create a popup window return: string Javascript code |
| bounded_number($min, $value, $max) X-Ref |
| No description |
| array_is_nested($array) X-Ref |
| No description |
| get_performance_info() X-Ref |
| get_performance_info() pairs up with init_performance_info() loaded in setup.php. Returns an array with 'html' and 'txt' values ready for use, and each of the individual stats provided separately as well. |
| apd_get_profiling() X-Ref |
| No description |
| remove_dir($dir, $content_only=false) X-Ref |
| Delete directory or only it's content param: string $dir directory path param: bool $content_only return: bool success, true also if dir does not exist |
| check_dir_exists($dir, $create=false, $recursive=false) X-Ref |
| Function to check if a directory exists and optionally create it. param: string absolute directory path (must be under $CFG->dataroot) param: boolean create directory if does not exist param: boolean create directory recursively return: boolean true if directory exists or created |
| report_session_error() X-Ref |
| No description |
| object_property_exists( $obj, $property ) X-Ref |
| Detect if an object or a class contains a given property will take an actual object or the name of a class param: mix $obj Name of class or real object to test param: string $property name of property to find return: bool true if property exists |
| custom_script_path($urlpath='') X-Ref |
| Detect a custom script replacement in the data directory that will replace an existing moodle script param: string $urlpath path to the original script return: string full path name if a custom script exists return: bool false if no custom script exists |
| loadeditor($args) X-Ref |
| Wrapper function to load necessary editor scripts to $CFG->editorsrc array. Params can be coursei id or associative array('courseid' => value, 'name' => 'editorname'). param: mixed $args Courseid or associative array. |
| is_mnet_remote_user($user) X-Ref |
| Returns whether or not the user object is a remote MNET user. This function is in moodlelib because it does not rely on loading any of the MNET code. param: object $user A valid user object return: bool True if the user is from a remote Moodle. |
| is_enabled_enrol($enrol='') X-Ref |
| Checks if a given plugin is in the list of enabled enrolment plugins. param: string $auth Enrolment plugin. return: boolean Whether the plugin is enabled. |
| setup_lang_from_browser() X-Ref |
| This function will search for browser prefereed languages, setting Moodle to use the best one available if $SESSION->lang is undefined |
| is_newnav($navigation) X-Ref |
| No description |
| in_object_vars($var, $object) X-Ref |
| Checks whether the given variable name is defined as a variable within the given object. param: string $var The variable name param: object $object The object to check return: boolean |
| object_array_unique($array, $keep_key_assoc = true) X-Ref |
| Returns an array without repeated objects. This function is similar to array_unique, but for arrays that have objects as values param: unknown_type $array param: unknown_type $keep_key_assoc return: unknown |
| get_plugin_name($plugin, $type='mod') X-Ref |
| Returns the language string for the given plugin. param: string $plugin the plugin code name param: string $type the type of plugin (mod, block, filter) return: string The plugin language string |
| is_primary_admin($userid) X-Ref |
| Is a userid the primary administrator? param: $userid int id of user to check return: boolean |
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |