This repository has been archived by the owner on Aug 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_request.php
53 lines (48 loc) · 1.7 KB
/
process_request.php
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
50
51
52
53
<?php
// Initializing API
use Keyteq\Keymedia\KeymediaClient;
$options = get_option('keymedia_settings');
$apiUser = $options['keymedia_username'];
$apiKey = $options['keymedia_token'];
$apiHost = $options['keymedia_host'];
$search = isset($_GET['search']) ? $_GET['search'] : false;
$album = isset($_GET['album']) ? $_GET['album'] : false;
$out = array();
switch ($_GET['rest']) {
case 'list_media':
$client = new KeymediaClient($apiUser, $apiHost, $apiKey);
$response = $client->listMedia($album, $search);
foreach ($response as $k => $item) {
$out[$k] = $item->toArray();
$out[$k]['thumbnailUrl'] = $item->getThumbnailUrl(150, 150);
$out[$k]['microthumbnailUrl'] = $item->getThumbnailUrl(40, 40);
$out[$k]['isImage'] = $item->isImage();
}
break;
case 'list_albums':
$client = new KeymediaClient($apiUser, $apiHost, $apiKey);
$response = $client->listAlbums();
foreach ($response as $item) {
$out[] = $item->toArray();
}
break;
case 'upload':
$client = new KeymediaClient($apiUser, $apiHost, $apiKey);
$client->postMedia(
$_FILES['file']['tmp_name'], $_FILES['file']['name']
);
break;
case 'check_connection':
$client = new KeymediaClient($_GET['username'], $_GET['host'], $_GET['token']);
$out = $client->isConnected();
break;
case 'get_token':
$out = false;
if(isset($_GET['password'])) {
$client = new KeymediaClient($_GET['username'], $_GET['host']);
$out = $client->getToken($_GET['password']);
}
break;
}
echo json_encode($out);
exit();