Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Functions | Variables
locallib.php File Reference

This file contains the library of functions and constants for the lti module. More...

Functions

 get_tag ($tagname, $xpath, $attribute=null)
 Search for a tag within an XML DOMDocument. More...
 
 get_tool_proxy_edit_url (stdClass $proxy)
 Returns the edit url for the given tool proxy. More...
 
 get_tool_proxy_urls (stdClass $proxy)
 Returns the icon and edit urls for the tool proxy. More...
 
 get_tool_type_capability_groups ($type)
 Returns a summary of each LTI capability this tool type requires in plain language. More...
 
 get_tool_type_config ($type)
 Returns information on the configuration of the tool type. More...
 
 get_tool_type_course_url (stdClass $type)
 Returns the course url for the given tool type. More...
 
 get_tool_type_edit_url (stdClass $type)
 Returns the edit url for the given tool type. More...
 
 get_tool_type_icon_url (stdClass $type)
 Returns the icon for the given tool type. More...
 
 get_tool_type_instance_ids ($type)
 Returns the ids of each instance of this tool type. More...
 
 get_tool_type_state_info (stdClass $type)
 Returns information on the current state of the tool type. More...
 
 get_tool_type_urls (stdClass $type)
 Returns the icon and edit urls for the tool type and the course url if it is a course type. More...
 
 lti_add_config ($config)
 Add a tool configuration in the database. More...
 
 lti_add_tool_proxy ($config)
 Update the database with a tool proxy instance. More...
 
 lti_add_type ($type, $config)
 
 lti_build_content_item_selection_request ($id, $course, moodle_url $returnurl, $title='', $text='', $mediatypes=[], $presentationtargets=[], $autocreate=false, $multiple=false, $unsigned=false, $canconfirm=false, $copyadvice=false, $nonce='')
 Builds a standard LTI Content-Item selection request. More...
 
 lti_build_custom_parameters ($toolproxy, $tool, $instance, $params, $customstr, $instructorcustomstr, $islti2)
 This function builds the custom parameters. More...
 
 lti_build_login_request ($courseid, $id, $instance, $config, $messagetype)
 Prepares an LTI 1.3 login request. More...
 
 lti_build_registration_request ($toolproxy)
 Gets the parameters for the regirstration request. More...
 
 lti_build_request ($instance, $typeconfig, $course, $typeid=null, $islti2=false)
 This function builds the request that must be sent to the tool producer. More...
 
 lti_build_request_lti2 ($tool, $params)
 This function builds the request that must be sent to an LTI 2 tool provider. More...
 
 lti_build_sourcedid ($instanceid, $userid, $servicesalt, $typeid=null, $launchid=null)
 Build source ID. More...
 
 lti_build_standard_message ($instance, $orgid, $ltiversion, $messagetype='basic-lti-launch-request')
 This function builds the standard parameters for an LTI message that must be sent to the tool producer. More...
 
 lti_build_standard_request ($instance, $orgid, $islti2, $messagetype='basic-lti-launch-request')
 This function builds the standard parameters for an LTI 1 or 2 request that must be sent to the tool producer. More...
 
 lti_calculate_custom_parameter ($value)
 Calculates the value of a custom parameter that has not been specified earlier. More...
 
 lti_convert_content_items ($param)
 Converts the new Deep-Linking format for Content-Items to the old format. More...
 
 lti_convert_from_jwt ($typeid, $jwtparam)
 Verfies the JWT and converts its claims to their equivalent message parameter. More...
 
 lti_delete_tool_proxy ($id)
 Delete a Tool Proxy. More...
 
 lti_delete_type ($id)
 Delete a Basic LTI configuration. More...
 
 lti_ensure_url_is_https ($url)
 
 lti_filter_get_types ($course)
 Returns all basicLTI tools configured by the administrator. More...
 
 lti_filter_tool_proxy_types (array $toolproxies, $state)
 Given an array of tool proxies, filter them based on their state. More...
 
 lti_filter_tool_types (array $tools, $state)
 Given an array of tools, filter them based on their state. More...
 
 lti_force_type_config_settings ($instance, array $typeconfig)
 Enforce type config settings onto the LTI instance. More...
 
 lti_get_best_tool_by_url ($url, $tools, $courseid=null)
 
 lti_get_capabilities ()
 Initializes an array with the capabilities supported by the LTI module. More...
 
 lti_get_config ($ltiobject)
 Transforms a basic LTI object to an array. More...
 
 lti_get_configured_types ($courseid, $sectionreturn=0)
 Returns a list of configured types in the given course. More...
 
 lti_get_contexts ($json)
 Extracts the named contexts from a tool proxy. More...
 
 lti_get_custom_parameters ($toolproxy, $tool, $params, $parameters)
 Adds the custom parameters to an array. More...
 
 lti_get_domain_from_url ($url)
 
 lti_get_enabled_capabilities ($tool)
 Extracts the enabled capabilities into an array, including those implicitly declared in a parameter. More...
 
 lti_get_fqid ($contexts, $id)
 Converts an ID to a fully-qualified ID. More...
 
 lti_get_ims_role ($user, $cmid, $courseid, $islti2)
 Gets the IMS role string for the specified user and LTI course module. More...
 
 lti_get_instance_type (object $instance)
 Return the type of the instance, using domain matching if no explicit type is set. More...
 
 lti_get_jwt_claim_mapping ()
 Return the mapping for standard message parameters to JWT claim. More...
 
 lti_get_jwt_message_type_mapping ()
 Return the mapping for standard message types to JWT message_type claim. More...
 
 lti_get_launch_container ($lti, $toolconfig)
 
 lti_get_launch_data ($instance, $nonce='')
 Return the launch data required for opening the external tool. More...
 
 lti_get_lti_types_by_course ($courseid, $coursevisible=null)
 Returns all lti types visible in this course. More...
 
 lti_get_organizationid ($typeconfig)
 get Organization ID using default if no value provided More...
 
 lti_get_permitted_service_scopes ($type, $typeconfig)
 Initializes an array with the scopes for services supported by the LTI module. More...
 
 lti_get_service_by_name ($servicename)
 Initializes an instance of the named service. More...
 
 lti_get_service_by_resource_id ($services, $resourceid)
 Finds a service by id. More...
 
 lti_get_services ()
 Initializes an array with the services supported by the LTI module. More...
 
 lti_get_shared_secrets_by_key ($key)
 
 lti_get_tool_by_url_match ($url, $courseid=null, $state=LTI_TOOL_STATE_CONFIGURED)
 
 lti_get_tool_proxies ($orphanedonly)
 Returns lti tool proxies. More...
 
 lti_get_tool_proxies_from_registration_url ($regurl)
 Get the tool proxy instance given its registration URL. More...
 
 lti_get_tool_proxy ($id)
 Generates some of the tool proxy configuration based on the admin configuration details. More...
 
 lti_get_tool_proxy_config ($id)
 Generates some of the tool proxy configuration based on the admin configuration details. More...
 
 lti_get_tool_proxy_from_guid ($toolproxyguid)
 Get the tool proxy instance given its GUID. More...
 
 lti_get_tool_proxy_table ($toolproxies, $id)
 This function builds the tab for a category of tool proxies. More...
 
 lti_get_tool_settings ($toolproxyid, $courseid=null, $instanceid=null)
 Gets the tool settings. More...
 
 lti_get_tool_table ($tools, $id)
 
 lti_get_tools_by_domain ($domain, $state=null, $courseid=null)
 
 lti_get_tools_by_url ($url, $state, $courseid=null)
 
 lti_get_type ($typeid)
 
 lti_get_type_config ($typeid)
 Returns configuration details for the tool. More...
 
 lti_get_type_config_by_instance ($instance)
 Fetches LTI type configuration for an LTI instance. More...
 
 lti_get_type_config_from_instance ($id)
 Generates some of the tool configuration based on the instance details. More...
 
 lti_get_type_type_config ($id)
 Generates some of the tool configuration based on the admin configuration details. More...
 
 lti_get_types_for_add_instance ()
 Returns tool types for lti add instance and edit page. More...
 
 lti_get_url_thumbprint ($url)
 
 lti_initiate_login ($courseid, $id, $instance, $config, $messagetype='basic-lti-launch-request', $title='', $text='')
 Generate the form for initiating a login request for an LTI 1.3 message. More...
 
 lti_is_cartridge ($url)
 Determines if the given url is for a IMS basic cartridge. More...
 
 lti_launch_tool ($instance)
 Launch an external tool activity. More...
 
 lti_load_cartridge ($url, $map, $propertiesmap=array())
 Search for a tag within an XML DOMDocument. More...
 
 lti_load_tool_from_cartridge ($url, $lti)
 Allows you to load in the configuration for an external tool from an IMS cartridge. More...
 
 lti_load_tool_if_cartridge ($lti)
 Loads the cartridge information into the new tool, if the launch url is for a cartridge file. More...
 
 lti_load_type_from_cartridge ($url, $type)
 Allows you to load settings for an external tool type from an IMS cartridge. More...
 
 lti_load_type_if_cartridge ($type)
 Loads the cartridge information into the tool type, if the launch url is for a cartridge file. More...
 
 lti_log_request ($rawbody)
 Logs the request to a file in temp dir. More...
 
 lti_log_response ($responsexml, $e=null)
 Log an LTI response. More...
 
 lti_map_keyname ($key, $tolower=true)
 Used for building the names of the different custom parameters. More...
 
 lti_new_access_token ($typeid, $scopes)
 Create a new access token. More...
 
 lti_parse_custom_parameter ($toolproxy, $tool, $params, $value, $islti2)
 Parse a custom parameter to replace any substitution variables. More...
 
 lti_post_launch_html ($newparms, $endpoint, $debug=false)
 Posts the launch petition HTML. More...
 
 lti_prepare_type_for_save ($type, $config)
 
 lti_register ($toolproxy)
 Prepares an LTI registration request message. More...
 
 lti_request_is_using_ssl ()
 
 lti_set_state_for_type ($id, $state)
 
 lti_set_tool_settings ($settings, $toolproxyid, $courseid=null, $instanceid=null)
 Sets the tool settings (. More...
 
 lti_should_log_request ($rawbody)
 Determines if we should try to log the request. More...
 
 lti_sign_jwt ($parms, $endpoint, $oauthconsumerkey, $typeid=0, $nonce='')
 Converts the message paramters to their equivalent JWT claim and signs the payload to launch the external tool using JWT. More...
 
 lti_sign_parameters ($oldparms, $endpoint, $method, $oauthconsumerkey, $oauthconsumersecret)
 Signs the petition to launch the external tool using OAuth. More...
 
 lti_split_custom_parameters ($toolproxy, $tool, $params, $customstr, $islti2=false)
 Splits the custom parameters field to the various parameters. More...
 
 lti_tool_configuration_from_content_item ($typeid, $messagetype, $ltiversion, $consumerkey, $contentitemsjson)
 Processes the tool provider's response to the ContentItemSelectionRequest and builds the configuration data from the selected content item. More...
 
 lti_update_config ($config)
 Updates a tool configuration in the database. More...
 
 lti_update_tool_proxy ($toolproxy)
 Updates a tool proxy in the database. More...
 
 lti_update_type ($type, $config)
 
 lti_verify_jwt_signature ($typeid, $consumerkey, $jwtparam)
 Verifies the JWT signature of an incoming message. More...
 
 lti_verify_oauth_signature ($typeid, $consumerkey)
 Verifies the OAuth signature of an incoming message. More...
 
 lti_verify_with_keyset ($jwtparam, $keyseturl, $clientid)
 Verifies the JWT signature using a JWK keyset. More...
 
 serialise_tool_proxy (stdClass $proxy)
 Serialises this tool proxy. More...
 
 serialise_tool_type (stdClass $type)
 Serialises this tool type. More...
 

Variables

global $CFG
 
const LTI_ACCESS_TOKEN_LIFE 3600
 
const LTI_COURSEVISIBLE_ACTIVITYCHOOSER 2
 
const LTI_COURSEVISIBLE_NO 0
 
const LTI_COURSEVISIBLE_PRECONFIGURED 1
 
const LTI_DEFAULT_ORGID_SITEHOST 'SITEHOST'
 
const LTI_DEFAULT_ORGID_SITEID 'SITEID'
 
const LTI_JWK_KEYSET 'JWK_KEYSET'
 
const LTI_JWT_CLAIM_PREFIX 'https://purl.imsglobal.org/spec/lti'
 
const LTI_LAUNCH_CONTAINER_DEFAULT 1
 
const LTI_LAUNCH_CONTAINER_EMBED 2
 
const LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS 3
 
const LTI_LAUNCH_CONTAINER_REPLACE_MOODLE_WINDOW 5
 
const LTI_LAUNCH_CONTAINER_WINDOW 4
 
const LTI_RSA_KEY 'RSA_KEY'
 
const LTI_SETTING_ALWAYS 1
 
const LTI_SETTING_DELEGATE 2
 
const LTI_SETTING_NEVER 0
 
const LTI_TOOL_PROXY_STATE_ACCEPTED 3
 
const LTI_TOOL_PROXY_STATE_CONFIGURED 1
 
const LTI_TOOL_PROXY_STATE_PENDING 2
 
const LTI_TOOL_PROXY_STATE_REJECTED 4
 
const LTI_TOOL_PROXY_TAB 4
 
const LTI_TOOL_STATE_ANY 0
 
const LTI_TOOL_STATE_CONFIGURED 1
 
const LTI_TOOL_STATE_PENDING 2
 
const LTI_TOOL_STATE_REJECTED 3
 
const LTI_URL_DOMAIN_REGEX '/(?:https?:\/\/)?(?:www\.)?([^\/]+)(?:\/|$)/i'
 
const LTI_VERSION_1 'LTI-1p0'
 
const LTI_VERSION_1P3 '1.3.0'
 
const LTI_VERSION_2 'LTI-2p0'
 

Detailed Description

This file contains the library of functions and constants for the lti module.

Author
Marc Alier
Jordi Piguillem
Nikolas Galanis
Chris Scribner
Author
Stephen Vickers
License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later