blob: e959d597cc6a0a26d2755f11c04120e3910b3381 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
<?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"]);
|