Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400] [Versions 400 and 402] [Versions 400 and 403]

Microsoft Live Skydrive Repository Plugin

Author: Dan Poltawski <dan.poltawski@luns.net.uk>
Copyright: 2012 Lancaster University Network Services Ltd
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 1152 lines (45 kb)
Included or required:0 times
Referenced: 1 time
Includes or requires: 0 files

Defines 1 class


Class: repository_onedrive  - X-Ref

Microsoft onedrive repository plugin.

__construct($repositoryid, $context = SYSCONTEXTID, $options = array()   X-Ref
Constructor.

return: void
param: int $repositoryid repository instance id.
param: int|stdClass $context a context id or context object.
param: array $options repository options.
param: int $readonly indicate this repo is readonly or not.

get_user_oauth_client($overrideurl = false)   X-Ref
Get a cached user authenticated oauth client.

return: \core\oauth2\client
param: moodle_url $overrideurl - Use this url instead of the repo callback.

check_login()   X-Ref
Checks whether the user is authenticate or not.

return: bool true when logged in.

print_login()   X-Ref
Print or return the login form.

return: void|array for ajax.

print_login_popup($attr = null)   X-Ref
Print the login in a popup.

param: array|null $attr Custom attributes to be applied to popup div.

build_breadcrumb($path)   X-Ref
Build the breadcrumb from a path.

return: array containing name and path of each crumb.
param: string $path to create a breadcrumb from.

build_node_path($id, $name = '', $root = '')   X-Ref
Generates a safe path to a node.

Typically, a node will be id|Name of the node.

return: string path to the node.
param: string $id of the node.
param: string $name of the node, will be URL encoded.
param: string $root to append the node on, must be a result of this function.

explode_node_path($node)   X-Ref
Returns information about a node in a path.

return: array about the node.
param: string $node to extrat information from.

get_listing($path='', $page = '')   X-Ref
List the files and folders.

return: array of result.
param: string $path path to browse.
param: string $page page to browse.

search($searchtext, $page = 0)   X-Ref
Search throughout the OneDrive

return: array of results.
param: string $searchtext text to search for.
param: int $page search page.

query($q, $path = null, $parent = null, $page = 0)   X-Ref
Query OneDrive for files and folders using a search query.

Documentation about the query format can be found here:
https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/resources/driveitem
https://developer.microsoft.com/en-us/graph/docs/overview/query_parameters

This returns a list of files and folders with their details as they should be
formatted and returned by functions such as get_listing() or search().

return: array of files and folders.
param: string $q search query as expected by the Graph API.
param: string $path parent path of the current files, will not be used for the query.
param: string $parent Parent id.
param: int $page page.

logout()   X-Ref
Logout.

return: string

get_file($reference, $filename = '')   X-Ref
Get a file.

return: string JSON encoded array of information about the file.
param: string $reference reference of the file.
param: string $filename filename to save the file to.

get_file_reference($source)   X-Ref
Prepare file reference information.

We are using this method to clean up the source to make sure that it
is a valid source.

return: string file reference.
param: string $source of the file.

supported_filetypes()   X-Ref
What kind of files will be in this repository?

return: array return '*' means this repository support any files, otherwise

supported_returntypes()   X-Ref
Tells how the file can be picked from this repository.

return: int

default_returntype()   X-Ref
Which return type should be selected by default.

return: int

get_type_option_names()   X-Ref
Return names of the general options.
By default: no general option name.

return: array

callback()   X-Ref
Store the access token.


send_file($storedfile, $lifetime=null , $filter=0, $forcedownload=false, array $options = null)   X-Ref
Repository method to serve the referenced file

param: stored_file $storedfile the file that contains the reference
param: int $lifetime Number of seconds before the file should expire from caches (null means $CFG->filelifetime)
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: array $options additional options affecting the file serving

get_file_id_by_path(\repository_onedrive\rest $client, $fullpath)   X-Ref
See if a folder exists within a folder

return: string|boolean The file id if it exists or false.
param: \repository_onedrive\rest $client Authenticated client.
param: string $fullpath

delete_file_by_path(\repository_onedrive\rest $client, $fullpath)   X-Ref
Delete a file by full path.

return: boolean
param: \repository_onedrive\rest $client Authenticated client.
param: string $fullpath

create_folder_in_folder(\repository_onedrive\rest $client, $foldername, $parentid)   X-Ref
Create a folder within a folder

return: string The file id of the new folder.
param: \repository_onedrive\rest $client Authenticated client.
param: string $foldername The folder we are creating.
param: string $parentid The parent folder we are creating in.

get_file_summary(\repository_onedrive\rest $client, $fileid)   X-Ref
Get simple file info for humans.

return: stdClass
param: \repository_onedrive\rest $client Authenticated client.
param: string $fileid The file we are querying.

add_temp_writer_to_file(\repository_onedrive\rest $client, $fileid, $email)   X-Ref
Add a writer to the permissions on the file (temporary).

return: boolean
param: \repository_onedrive\rest $client Authenticated client.
param: string $fileid The file we are updating.
param: string $email The email of the writer account to add.

set_file_sharing_anyone_with_link_can_read(\repository_onedrive\rest $client, $fileid)   X-Ref
Allow anyone with the link to read the file.

return: boolean
param: \repository_onedrive\rest $client Authenticated client.
param: string $fileid The file we are updating.

get_mimetype_from_filename($filename)   X-Ref
Given a filename, use the core_filetypes registered types to guess a mimetype.

If no mimetype is known, return 'application/unknown';

return: string $mimetype
param: string $filename

upload_file(\repository_onedrive\rest $service, \curl $curl, \curl $authcurl,$filepath, $mimetype, $parentid, $filename)   X-Ref
Upload a file to onedrive.

return: string $fileid
param: \repository_onedrive\rest $service Authenticated client.
param: \curl $curl Curl client to perform the put operation (with no auth headers).
param: \curl $authcurl Curl client that will send authentication headers
param: string $filepath The local path to the file to upload
param: string $mimetype The new mimetype
param: string $parentid The folder to put it.
param: string $filename The name of the new file

reference_file_selected($reference, $context, $component, $filearea, $itemid)   X-Ref
Called when a file is selected as a "link".
Invoked at MOODLE/repository/repository_ajax.php

What should happen here is that the file should be copied to a new file owned by the moodle system user.
It should be organised in a folder based on the file context.
It's sharing permissions should allow read access with the link.
The returned reference should point to the newly copied file - not the original.

return: string $modifiedreference (final one before saving to DB)
param: string $reference this reference is generated by
param: context $context the target context for this new file.
param: string $component the target component for this new file.
param: string $filearea the target filearea for this new file.
param: string $itemid the target itemid for this new file.

get_reference_details($reference, $filestatus = 0)   X-Ref
Get human readable file info from the reference.

param: string $reference
param: int $filestatus

can_import_skydrive_files()   X-Ref
Return true if any instances of the skydrive repo exist - and we can import them.

return: bool

import_skydrive_files()   X-Ref
Import all the files that were created with the skydrive repo to this repo.

return: bool

type_config_form($mform, $classname = 'repository')   X-Ref
Edit/Create Admin Settings Moodle form.

param: moodleform $mform Moodle form (passed by reference).
param: string $classname repository class name.

repository_onedrive_oauth2_system_scopes(\core\oauth2\issuer $issuer)   X-Ref
Callback to get the required scopes for system account.

return: string
param: \core\oauth2\issuer $issuer