-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.php
More file actions
95 lines (75 loc) · 3.86 KB
/
index.php
File metadata and controls
95 lines (75 loc) · 3.86 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
// index.php
// This is an example page that will display the contents of a given onedrive folder.
// If an access_token is not available, it'll direct the user to login with onedrive.
require_once "src/functions.inc.php";
// Try and get a valid access_token from the token store.
$token = onedrive_tokenstore::acquire_token(); // Call this function to grab a current access_token, or false if none is available.
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>oneDrive demo</title>
<?php
if (!$token) { // If no token, prompt to login. Call onedrive_auth::build_oauth_url() to get the redirect URL.
echo "<div>";
echo "<img src='statics/key-icon.png' width='32px' style='vertical-align: middle;'> ";
echo "<span style='vertical-align: middle;'><a href='".onedrive_auth::build_oauth_url()."'>Login with OneDrive</a></span>";
echo "</div>";
} else { // Otherwise, if we have a token, use it to create an object and start calling methods to build our page.
$sd2 = new onedrive($token);
$quotaresp = $sd2->get_quota();
echo "Quota remaining: ".round((((int)$quotaresp['available']/1024)/1024))." Mbytes.</p>";
echo "<p><b>Create folder here:<br>";
echo "<form method='post' action='createfolder.php'><input type='hidden' name='currentfolderid' value='".@$_GET['folderid']."'><input type='text' name='foldername' placeholder='Folder Name'> <input type='submit' name='submit' value='submit'></form>";
echo "</p>";
// First, time to create a new OneDrive object.
$sd = new onedrive($token);
// Time to prepare and make the request to get the list of files.
if (empty($_GET['folderid'])) {
if (empty($_GET['offset'])) {
$response = $sd->get_folder(null, 'name', 'ascending', 10); // Gets the first 10 items of the root folder.
} else {
$response = $sd->get_folder(null, 'name', 'ascending', 10, $_GET['offset']); // Gets the next 10 items of the root folder from the specified offset.
}
$properties = $sd->get_folder_properties(null);
} else {
if (empty($_GET['offset'])) {
$response = $sd->get_folder($_GET['folderid'], 'name', 'ascending', 10); // Gets the first 10 items of the specified folder.
} else {
$response = $sd->get_folder($_GET['folderid'], 'name', 'ascending', 10, $_GET['offset']); // Gets the next 10 items of the specified folder from the specified offset.
}
$properties = $sd->get_folder_properties($_GET['folderid']);
}
// Now we've got our files and folder properties, time to display them.
echo "<p><div id='bodyheader'><b>".$properties['name']."</b><br>";
if (! empty($properties['parent_id'])) {
echo "<a href='index.php?folderid=".$properties['parent_id']."'>Up to parent folder</a>";
}
echo "</div>";
echo "<br>";
foreach ($response['data'] as $item) { // Loop through the items in the folder and generate the list of items.
echo "<div>";
if ($item['type'] == 'folder' || $item['type'] =='album') {
echo "<img src='statics/folder-icon.png' width='32px' style='vertical-align: middle;'> ";
echo "<span style='vertical-align: middle;'><a title='Open folder' href='index.php?folderid=".$item['id']."'>".$item['name']."</a></span>";
} else {
echo "<img src='statics/".$item['type']."-icon.png' width='32px' style='vertical-align: middle;'> ";
echo "<span style='vertical-align: middle;'><a title='Download' href='download.php?fileid=".$item['id']."'>".$item['name']."</a><br>";
echo "<a href='properties.php?fileid=".$item['id']."'>Properties</a></span>";
}
echo "</div>";
echo "<br>";
}
if (@$response['paging']['nextoffset'] != 0) {
echo "<a href='index.php?folderid=".$_GET['folderid']."&offset=".$response['paging']['nextoffset']."'>See More</a>";
} else {
echo "No more files in folder";
}
echo "<br>";
echo "<a href='logout.php'>Log Out</a>";
}
?>
</body>
</html>