Newer
Older
class OwnCloudPlugin extends StudIPPlugin implements FilesystemPlugin {
public function getFileSelectNavigation()
{
$nav = new Navigation(_("OwnCloud"));
$nav->setImage(Icon::create("cloud2", "clickable"));
return $nav;
}
public function getFolder($folder_id = null)
{
$parts = parse_url(UserConfig::get($GLOBALS['user']->id)->OWNCLOUD_ENDPOINT);
$url = $parts['scheme']
.urlencode(UserConfig::get($GLOBALS['user']->id)->OWNCLOUD_USERNAME)
.":"
.urlencode(UserConfig::get($GLOBALS['user']->id)->OWNCLOUD_PASSWORD)
."@"
.$parts['host']
.($parts['port'] ? ":".$parts['port'] : "")
.($parts['path'] ?: "");
if ($url[strlen($url) - 1] !== "/") {
$url .= "/";
}
$header[] = "Authorization: Bearer ".\Owncloud\OAuth::getAccessToken();
$r = curl_init();
curl_setopt($r, CURLOPT_HTTPHEADER, ($header));
curl_setopt($r, CURLOPT_RETURNTRANSFER, 1);
$doc = new DOMDocument();
$doc->loadXML($xml);
$folder = new VirtualFolderType(array(
foreach ($doc->getElementsByTagNameNS("DAV:","response") as $file) {
//response
// -> href
// -> propstat
// -> prop
// -> resourcetype
// -> getcontentlength
// -> getcontenttype
// -> getlastmodified
// -> status
$file_attributes = array();
foreach ($file->childNodes as $node) {
if ($node->tagName === "d:href") {
$file_attributes['name'] = substr($node->nodeValue, strpos($node->nodeValue, $root) + strlen($root));
$file_attributes['name'] = urldecode(array_pop(preg_split("/\//", $file_attributes['name'], 0, PREG_SPLIT_NO_EMPTY)));
if ($node->tagName === "d:propstat") {
foreach ($node->childNodes as $prop) {
foreach ($prop->childNodes as $attr) {
if ($attr->tagName === "d:resourcetype") {
$file_attributes['type'] = $attr->childNodes[0] && $attr->childNodes[0]->tagName === "d:collection" ? "folder" : "file";
if ($attr->tagName === "d:getcontentlength") {
$file_attributes['size'] = $attr->nodeValue;
if ($attr->tagName === "d:getcontenttype") {
$file_attributes['contenttype'] = $attr->nodeValue;
if ($attr->tagName === "d:getlastmodified") {
$file_attributes['chdate'] = strtotime($attr->nodeValue);
}
}
if ($file_attributes['type'] === "folder") {
$subfolder = new VirtualFolderType(array(
'id' => ($folder_id ? $folder_id."/" : "").$file_attributes['name'],
'name' => $file_attributes['name'],
'parent_id' => $folder_id
), $this->getPluginId());
$folder->createSubfolder($subfolder);
} else {
$folder->createFile(array(
'id' => ($folder_id ? $folder_id."/" : "").$file_attributes['name'],
'name' => $file_attributes['name'],
'size' => $file_attributes['size'],
'mime_type' => $file_attributes['contenttype'],
'description' => "",
'chdate' => $file_attributes['chdate']
));
}
}
return $folder;
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
}
public function getPreparedFile($file_id)
{
//TODO
$url = "https://www.googleapis.com/books/v1/volumes/".$file_id."?key=".urlencode(self::$googlebooksapikey);
$info = file_get_contents($url);
$info = studip_utf8decode(json_decode($info, true));
$download = $info['accessInfo']['pdf']['downloadLink'] ?: $info['accessInfo']['epub']['downloadLink'];
$tmp_path = $GLOBALS['TMP_PATH']."/".md5(uniqid());
if (!$download) {
var_dump($info);
} else {
file_put_contents($tmp_path, file_get_contents($download));
$file = array(
'name' => $info['volumeInfo']['title'] . ($info['accessInfo']['pdf']['downloadLink'] ? ".pdf" : ".epub"),
'size' => filesize($tmp_path),
'type' => $info['accessInfo']['pdf']['downloadLink'] ? "application/pdf" : "application/epub+zip",
'tmp_path' => $tmp_path,
'description' => $info['volumeInfo']['publishedDate'].", ".implode(", ", (array) $info['volumeInfo']['authors'])
);
return $file;
}
}
public function filesystemConfigurationURL()
{
return PluginEngine::getURL($this, array(), "configure/myarea");
}
return false;
}
public function getSearchParameters()
{
// TODO: Implement getSearchParameters() method.
}
public function search($text, $parameters = array())
{
return null;
}
public function isSource()
{
return UserConfig::get($GLOBALS['user']->id)->OWNCLOUD_ACTIVATED;
}
public function isPersonalFileArea()
{
return UserConfig::get($GLOBALS['user']->id)->OWNCLOUD_ACTIVATED;
}
}