diff options
Diffstat (limited to 'vendor/edu-sharing-plugin/example')
| -rw-r--r-- | vendor/edu-sharing-plugin/example/example-api.php | 59 | ||||
| -rw-r--r-- | vendor/edu-sharing-plugin/example/example.php | 49 | ||||
| -rw-r--r-- | vendor/edu-sharing-plugin/example/index.html | 120 |
3 files changed, 0 insertions, 228 deletions
diff --git a/vendor/edu-sharing-plugin/example/example-api.php b/vendor/edu-sharing-plugin/example/example-api.php deleted file mode 100644 index a961a7d..0000000 --- a/vendor/edu-sharing-plugin/example/example-api.php +++ /dev/null @@ -1,59 +0,0 @@ -<?php -define('APP_ID', 'data-quest Test'); -define('BASE_URL', 'http://localhost:8080/edu-sharing'); -define('USERNAME', 'root@studip'); - - -header('Accept: application/json'); -header('Content-Type: application/json'); - -require_once "../edu-sharing-helper.php"; -require_once "../edu-sharing-helper-base.php"; -require_once "../edu-sharing-auth-helper.php"; -require_once "../edu-sharing-node-helper.php"; - -$privatekey = @file_get_contents('private.key'); -if(!$privatekey) { - die('no private key'); -} else { - $key["privatekey"] = $privatekey; -} -// init the base class instance we use for all helpers -$base = new EduSharingHelperBase(BASE_URL, $key["privatekey"], APP_ID); -$postData = json_decode(file_get_contents('php://input')); -$action = $postData->action; -$result = null; -if ($action === 'BASE_URL') { - $result = BASE_URL; -} else if ($action === 'GET_NODE') { - $nodeHelper = new EduSharingNodeHelper($base); - $result = $nodeHelper->getNodeByUsage( - new Usage( - $postData->nodeId, - $postData->nodeVersion, - $postData->containerId, - $postData->resourceId, - $postData->usageId - ) - ); -} else if ($action === 'CREATE_USAGE') { - $nodeHelper = new EduSharingNodeHelper($base); - $result = $nodeHelper->createUsage( - $postData->ticket, - $postData->containerId, - $postData->resourceId, - $postData->nodeId - ); -} else if ($action === 'DELETE_USAGE') { - $nodeHelper = new EduSharingNodeHelper($base); - $nodeHelper->deleteUsage( - $postData->nodeId, - $postData->usageId - ); -} else if ($action === 'TICKET') { - $authHelper = new EduSharingAuthHelper($base); - $ticket = $authHelper->getTicketForUser(USERNAME); - $result = $ticket; -} - -echo json_encode($result); diff --git a/vendor/edu-sharing-plugin/example/example.php b/vendor/edu-sharing-plugin/example/example.php deleted file mode 100644 index e959d59..0000000 --- a/vendor/edu-sharing-plugin/example/example.php +++ /dev/null @@ -1,49 +0,0 @@ -<?php -/** - * This is a sample file on how to use the edu-sharing remote library - * Run this script for the first time to create a private/public keypair - * On first run, a properties.xml file will be created - * Upload this file to your target edu-sharing (Admin-Tools -> Remote Systems -> Choose XML-File) - */ - -define('APP_ID', 'sample-app'); -define('USERNAME', 'tester'); -require_once "../edu-sharing-helper.php"; -require_once "../edu-sharing-helper-base.php"; -require_once "../edu-sharing-auth-helper.php"; -require_once "../edu-sharing-node-helper.php"; - -$privatekey = @file_get_contents('private.key'); -if(!$privatekey) { - $key = EduSharingHelper::generateKeyPair(); - // store the $key data inside your application, e.g. your database or plugin config - file_put_contents(APP_ID . '.properties.xml', EduSharingHelper::generateEduAppXMLData(APP_ID, $key['publickey'])); - file_put_contents('private.key', $key['privatekey']); - die('Wrote ' . APP_ID . '.properties.xml file. Upload it to edu-sharing, then run this script again'); -} else { - $key["privatekey"] = $privatekey; -} -if(count($argv) < 2) { - die('This script should be called as follow: "example.php http://localhost:8080/edu-sharing [<node-id>]"'); -} -// init the base class instance we use for all helpers -$base = new EduSharingHelperBase($argv[1], $key["privatekey"], APP_ID); -$base->setLanguage('de'); - -// authenticating (getting a ticket) and validating the given ticket -$authHelper = new EduSharingAuthHelper($base); -$ticket = $authHelper->getTicketForUser(USERNAME); -echo "Ticket validation result:\n"; -print_r($authHelper->getTicketAuthenticationInfo($ticket)); - -if(count($argv) !== 3) { - die("No node id given. Add a 3rd parameter to test create + fetching of nodes by usage"); -} -$nodeHelper = new EduSharingNodeHelper($base); -$usage = $nodeHelper->createUsage($ticket, '1', '1', $argv[2]); -echo "Usage create result:\n"; -print_r($usage); - -$node = $nodeHelper->getNodeByUsage($usage); -echo "Get node by usage:\n"; -print_r($node["node"]["name"]);
\ No newline at end of file diff --git a/vendor/edu-sharing-plugin/example/index.html b/vendor/edu-sharing-plugin/example/index.html deleted file mode 100644 index 9be18ce..0000000 --- a/vendor/edu-sharing-plugin/example/index.html +++ /dev/null @@ -1,120 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> -<head> - <meta charset="UTF-8"> - <title>Edu Sharing Usage Example</title> - <style> - body > div { - padding: 20px 10px; - } - pre { - border: 1px solid #eee; - padding: 10px; - margin: 10px; - } - </style> - <script> - let ticket; - let baseUrl = null; - let esWindow = null; - function openEduSharing() { - esWindow = window.open( - baseUrl + '/components/search?ticket=' + encodeURIComponent(ticket) + - '&reurl=IFRAME' - ); - } - window.addEventListener('message', receiveMessage, false); - async function receiveMessage(event){ - if(event.data.event === 'APPLY_NODE'){ // Event Name hier festlegen - esWindow.close(); - console.log(event.data.data); - usage = await createUsage(event.data.data.nodeId); - // in a real application, the usage is stored in your backend system - localStorage.setItem('usage', JSON.stringify(usage)); - await renderUsage(); - - } - } - async function renderUsage() { - if(localStorage.getItem('usage')) { - const usage = JSON.parse(localStorage.getItem('usage')); - document.querySelector('#usage').style.display = null; - document.querySelector('#delete-usage').style.display = null; - document.querySelector('#usage').innerHTML = JSON.stringify(usage, null, 4); - usage.action = 'GET_NODE'; - const render = await fetchAPI(usage) - document.querySelector('#render').innerHTML = render.detailsSnippet; - } - - } - async function createUsage(nodeId) { - return await fetchAPI({ - action: 'CREATE_USAGE', - ticket, - nodeId, - containerId: 'my_sample_page_1', - resourceId: Math.random() - }); - } - async function deleteUsage(nodeId) { - const usage = JSON.parse(localStorage.getItem('usage')); - await fetchAPI({ - action: 'DELETE_USAGE', - nodeId: usage.nodeId, - usageId: usage.usageId - }); - localStorage.removeItem('usage'); - document.querySelector('#render').style.display = 'none'; - document.querySelector('#usage').style.display = 'none'; - document.querySelector('#delete-usage').style.display = 'none'; - } - async function fetchAPI(data) { - return new Promise((resolve, reject) => { - var xhr = new XMLHttpRequest(); - xhr.open("POST", "example-api.php", true); - xhr.onload = () => { - if (xhr.readyState === 4) { - if (xhr.status === 200) { - resolve(JSON.parse(xhr.response)); - } else { - alert(xhr.statusText); - reject(xhr.statusText); - } - } - }; - xhr.onerror = function (e) { - alert(xhr.statusText); - }; - xhr.send(JSON.stringify(data)); - }); - } - async function getTicket() { - ticket = await fetchAPI({action: 'TICKET'}); - document.querySelector('#ticket').innerText = ticket; - document.querySelector('#edu-select').style.display = null; - - } - window.addEventListener('load', async () => { - baseUrl = await fetchAPI({action: 'BASE_URL'}); - await renderUsage(); - - await getTicket(); - }); - </script> -</head> -<body> -<div> - <button onclick="getTicket()">Re-Fetch ticket</button> - <span id="ticket">No ticket</span> -</div> -<div id="edu-select" style="display:none;"> - <button onclick="openEduSharing()">Open edu-sharing & select node</button> -</div> -<pre id="usage" style="display: none"></pre> -<div id="delete-usage" style="display: none"> - <button onclick="deleteUsage()">Delete current Usage</button> -</div> -<div id="render"></div> - -</body> -</html>
\ No newline at end of file |
