Skip to content
Snippets Groups Projects
OwncloudFolder.php 20.2 KiB
Newer Older
Rasmus Fuhse's avatar
Rasmus Fuhse committed
<?php

class OwncloudFolder extends VirtualFolderType {

Rasmus Fuhse's avatar
Rasmus Fuhse committed
    protected $did_propfind = false;

    public static function availableInRange($range_id_or_object, $user_id)
    {
        return $range_id_or_object == 'OwnCloudPlugin';
    }

Rasmus Fuhse's avatar
Rasmus Fuhse committed
    public function isWritable($user_id)
    {
Rasmus Fuhse's avatar
Rasmus Fuhse committed
        return true;
Rasmus Fuhse's avatar
Rasmus Fuhse committed
    }

    public function isEditable($user_id)
    {
Rasmus Fuhse's avatar
Rasmus Fuhse committed
    }

    public function isSubfolderAllowed($user_id)
    {
        return true;
    }

Rasmus Fuhse's avatar
Rasmus Fuhse committed
    public function isFileDownloadable($file_id, $user_id)
    {
        return true;
    }

Rasmus Fuhse's avatar
Rasmus Fuhse committed
    public function isFileEditable($fileref_or_id, $user_id)
    {
        return true;
    }

    public function isFileWritable($fileref_or_id, $user_id)
    {
        return true;
    }


    public function store()
        $old_id = $this->parent_id . '/' . rawurlencode($this->name);

        if ($this->getId() != $old_id) {

            $webdav = $this->getWebDavURL();
            $header = array();
            $header[] = self::getAuthHeader();
            $header[] = "Destination: ". $webdav . $this->id;
            $r = curl_init();
            curl_setopt($r, CURLOPT_CUSTOMREQUEST, "MOVE");
            curl_setopt($r, CURLOPT_URL, $webdav . $old_id);
            curl_setopt($r, CURLOPT_HTTPHEADER, ($header));
            curl_setopt($r, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($r, CURLOPT_SSL_VERIFYPEER, (bool) Config::get()->OWNCLOUD_SSL_VERIFYPEER);
            curl_setopt($r, CURLOPT_SSL_VERIFYHOST, (bool) Config::get()->OWNCLOUD_SSL_VERIFYPEER);
Rasmus Fuhse's avatar
Rasmus Fuhse committed
            if ($GLOBALS['OWNCLOUD_VERBOSE']) {
                curl_setopt($r, CURLOPT_VERBOSE, true);
            }
            curl_exec($r);
            $status = curl_getinfo($r, CURLINFO_HTTP_CODE);
            curl_close($r);

            return ($status >= 200) && ($status < 300);

        }
        return false;
    }

    public function delete()
    {
        return $this->deleteFile($this->id);
    }

Rasmus Fuhse's avatar
Rasmus Fuhse committed
    public function deleteFile($file_ref_id)
    {
Rasmus Fuhse's avatar
Rasmus Fuhse committed
        $webdav = $this->getWebDavURL();

        $header = array();
        $header[] = self::getAuthHeader();
Rasmus Fuhse's avatar
Rasmus Fuhse committed

        $r = curl_init();
        curl_setopt($r, CURLOPT_CUSTOMREQUEST, "DELETE");
Rasmus Fuhse's avatar
Rasmus Fuhse committed
        curl_setopt($r, CURLOPT_URL, $webdav . $file_ref_id);
Rasmus Fuhse's avatar
Rasmus Fuhse committed
        curl_setopt($r, CURLOPT_HTTPHEADER, ($header));
        curl_setopt($r, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($r, CURLOPT_SSL_VERIFYPEER, (bool) Config::get()->OWNCLOUD_SSL_VERIFYPEER);
        curl_setopt($r, CURLOPT_SSL_VERIFYHOST, (bool) Config::get()->OWNCLOUD_SSL_VERIFYPEER);
Rasmus Fuhse's avatar
Rasmus Fuhse committed
        if ($GLOBALS['OWNCLOUD_VERBOSE']) {
            curl_setopt($r, CURLOPT_VERBOSE, true);
        }
Rasmus Fuhse's avatar
Rasmus Fuhse committed

        curl_exec($r);
Rasmus Fuhse's avatar
Rasmus Fuhse committed
        $status = curl_getinfo($r, CURLINFO_HTTP_CODE);
Rasmus Fuhse's avatar
Rasmus Fuhse committed
        curl_close($r);
Rasmus Fuhse's avatar
Rasmus Fuhse committed
        return ($status >= 200) && ($status < 300);
Rasmus Fuhse's avatar
Rasmus Fuhse committed
    }

    public function addFile(FileType $file, $user_id = null)
    {
        $webdav = $this->getWebDavURL();

        if ($this->fileExists($file->getFilename())) {
Rasmus Fuhse's avatar
Rasmus Fuhse committed
            if (strpos($filedata['name'], ".")) {
                $end = substr($filedata['name'], strpos($filedata['name'], "."));
                $name_raw = substr($filedata['name'], 0, strpos($filedata['name'], "."));
            } else {
                $name_raw = $filedata['name'];
            }
            $i = 0;
            do {
                $i++;
                $new_name = $name_raw."(".$i.").".$end;
            } while ($this->fileExists($new_name));
            $filedata['name'] = $new_name;
            $file->data['name'] = $new_name;
Rasmus Fuhse's avatar
Rasmus Fuhse committed
        }

        $file_ref_id = $this->id . (mb_strlen($this->id) ? '/' : '') . rawurlencode($file->getFilename());
        $header = array();
        $header[] = self::getAuthHeader();
Rasmus Fuhse's avatar
Rasmus Fuhse committed

Rasmus Fuhse's avatar
Rasmus Fuhse committed
        $data = $file->getPath();
        //Verlinkungen URLFile extra berücksichtigen?  $url_template = "[InternetShortcut]\nURL=%s";
        $fh_res = fopen($data, 'r');

        $r = curl_init();
        curl_setopt($r, CURLOPT_PUT, 1);
        curl_setopt($r, CURLOPT_URL, $webdav . $file_ref_id);
        curl_setopt($r, CURLOPT_HTTPHEADER, ($header));
        curl_setopt($r, CURLOPT_INFILE, $fh_res);
        curl_setopt($r, CURLOPT_INFILESIZE, filesize($data));
        curl_setopt($r, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($r, CURLOPT_SSL_VERIFYPEER, (bool) Config::get()->OWNCLOUD_SSL_VERIFYPEER);
        curl_setopt($r, CURLOPT_SSL_VERIFYHOST, (bool) Config::get()->OWNCLOUD_SSL_VERIFYPEER);
Rasmus Fuhse's avatar
Rasmus Fuhse committed
        if ($GLOBALS['OWNCLOUD_VERBOSE']) {
            curl_setopt($r, CURLOPT_VERBOSE, true);
        }
        curl_exec($r);
        $status = curl_getinfo($r, CURLINFO_HTTP_CODE);
        curl_close($r);
        fclose($fh_res);

Rasmus Fuhse's avatar
Rasmus Fuhse committed
        $plugin = PluginManager::getInstance()->getPlugin("OwnCloudPlugin");
        return $plugin->getPreparedFile($file_ref_id);
    }

    public function copyFile($file_ref_id)
    {
        $webdav = $this->getWebDavURL();
        $tmp_parts = explode('/', $file_ref_id);
Rasmus Fuhse's avatar
Rasmus Fuhse committed

        $name = end($tmp_parts);
        if ($this->fileExists($name)) {
            if (strpos($name, ".")) {
                $end = substr($name, strpos($name, "."));
                $name_raw = substr($name, 0, strpos($name, "."));
            } else {
                $name_raw = $name;
            }
            $i = 0;
            do {
                $i++;
                $new_name = $name_raw."(".$i.").".$end;
            } while ($this->fileExists($new_name));
            $name = $new_name;
        }

        $destination = $this->id . (mb_strlen($this->id) ? '/' : '') . rawurlencode($name);

        $header = array();
        $header[] = self::getAuthHeader();
        $header[] = "Destination: ". $webdav . $destination;

        $r = curl_init();
        curl_setopt($r, CURLOPT_CUSTOMREQUEST, "COPY");
        curl_setopt($r, CURLOPT_URL, $webdav . $file_ref_id);
        curl_setopt($r, CURLOPT_HTTPHEADER, ($header));
        curl_setopt($r, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($r, CURLOPT_SSL_VERIFYPEER, (bool) Config::get()->OWNCLOUD_SSL_VERIFYPEER);
        curl_setopt($r, CURLOPT_SSL_VERIFYHOST, (bool) Config::get()->OWNCLOUD_SSL_VERIFYPEER);
Rasmus Fuhse's avatar
Rasmus Fuhse committed
        if ($GLOBALS['OWNCLOUD_VERBOSE']) {
            curl_setopt($r, CURLOPT_VERBOSE, true);
        }

        curl_exec($r);
        $status = curl_getinfo($r, CURLINFO_HTTP_CODE);
        curl_close($r);
Rasmus Fuhse's avatar
Rasmus Fuhse committed

        $plugin = PluginManager::getInstance()->getPlugin("OwnCloudPlugin");
        return $plugin->getPreparedFile($destination);
    }

    public function moveFile($file_ref_id)
    {
        $webdav = $this->getWebDavURL();

        $tmp_parts = explode('/', $file_ref_id);
Rasmus Fuhse's avatar
Rasmus Fuhse committed

        $name = end($tmp_parts);
        if ($this->fileExists($name)) {
            if (strpos($name, ".")) {
                $end = substr($name, strpos($name, "."));
                $name_raw = substr($name, 0, strpos($name, "."));
            } else {
                $name_raw = $name;
            }
            $i = 0;
            do {
                $i++;
                $new_name = $name_raw."(".$i.").".$end;
            } while ($this->fileExists($new_name));
            $name = $new_name;
        }
        $destination = $this->id . (mb_strlen($this->id)?'/':'') . rawurlencode($name);

        $header = array();
        $header[] = self::getAuthHeader();
        $header[] = "Destination: ". $webdav . $destination;

        $r = curl_init();
        curl_setopt($r, CURLOPT_CUSTOMREQUEST, "MOVE");
        curl_setopt($r, CURLOPT_URL, $webdav . $file_ref_id);
        curl_setopt($r, CURLOPT_HTTPHEADER, ($header));
        curl_setopt($r, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($r, CURLOPT_SSL_VERIFYPEER, (bool) Config::get()->OWNCLOUD_SSL_VERIFYPEER);
        curl_setopt($r, CURLOPT_SSL_VERIFYHOST, (bool) Config::get()->OWNCLOUD_SSL_VERIFYPEER);
Rasmus Fuhse's avatar
Rasmus Fuhse committed
        if ($GLOBALS['OWNCLOUD_VERBOSE']) {
            curl_setopt($r, CURLOPT_VERBOSE, true);
        }

        curl_exec($r);
        $status = curl_getinfo($r, CURLINFO_HTTP_CODE);
        curl_close($r);
Rasmus Fuhse's avatar
Rasmus Fuhse committed

        $plugin = PluginManager::getInstance()->getPlugin("OwnCloudPlugin");
        return $plugin->getPreparedFile($destination);
    }

    public function editFile($file_ref_id, $name = null, $description = null,  $content_terms_of_use_id = null)
    {
        if (!$name) {
            return false;
Rasmus Fuhse's avatar
Rasmus Fuhse committed
        $webdav = $this->getWebDavURL();
        if ($this->fileExists(rawurlencode($name))) {
            if (strpos($name, ".")) {
                $end = substr($name, strpos($name, "."));
                $name_raw = substr($name, 0, strpos($name, "."));
            } else {
                $name_raw = $name;
            }
            $i = 0;
            do {
                $i++;
                $new_name = $name_raw."(".$i.").".$end;
            } while ($this->fileExists(rawurlencode($new_name)));
            $name = $new_name;
        }
        $destination = $this->id . (mb_strlen($this->id)?'/':'') . rawurlencode($name);

        $header = array();
        $header[] = self::getAuthHeader();
        $header[] = "Destination: ". $webdav . $destination;

        $r = curl_init();
        curl_setopt($r, CURLOPT_CUSTOMREQUEST, "MOVE");
        curl_setopt($r, CURLOPT_URL, $webdav . $file_ref_id);
        curl_setopt($r, CURLOPT_HTTPHEADER, ($header));
        curl_setopt($r, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($r, CURLOPT_SSL_VERIFYPEER, (bool) Config::get()->OWNCLOUD_SSL_VERIFYPEER);
        curl_setopt($r, CURLOPT_SSL_VERIFYHOST, (bool) Config::get()->OWNCLOUD_SSL_VERIFYPEER);
Rasmus Fuhse's avatar
Rasmus Fuhse committed
        if ($GLOBALS['OWNCLOUD_VERBOSE']) {
            curl_setopt($r, CURLOPT_VERBOSE, true);
        }

        curl_exec($r);
        $status = curl_getinfo($r, CURLINFO_HTTP_CODE);
        curl_close($r);
Rasmus Fuhse's avatar
Rasmus Fuhse committed
        $plugin = PluginManager::getInstance()->getPlugin("OwnCloudPlugin");
        return $plugin->getPreparedFile($destination);
    }

    public function createSubfolder(FolderType $foldertype)
Rasmus Fuhse's avatar
Rasmus Fuhse committed
    {
        $webdav = $this->getWebDavURL();
Rasmus Fuhse's avatar
Rasmus Fuhse committed
        if ($foldertype->getId()) {
            $name = explode('/', $foldertype->getId());
            $name = end($name);
        } else {
            $name = rawurlencode($foldertype->name);
        }
Rasmus Fuhse's avatar
Rasmus Fuhse committed
        if ($this->folderExists($name)) {
            $name_raw = $name;
            $i = 0;
            do {
                $i++;
                $new_name = $name_raw."(".$i.")";
            } while ($this->folderExists($new_name));
            $name = $new_name;
        }
Rasmus Fuhse's avatar
Rasmus Fuhse committed
        $destination = $this->id . (mb_strlen($this->id)?'/':'') . $name;
        $header = array();
        $header[] = self::getAuthHeader();

        $r = curl_init();

        curl_setopt($r, CURLOPT_CUSTOMREQUEST, "MKCOL");
        curl_setopt($r, CURLOPT_URL, $webdav . $destination);
        curl_setopt($r, CURLOPT_HTTPHEADER, ($header));
        curl_setopt($r, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($r, CURLOPT_SSL_VERIFYPEER, (bool) Config::get()->OWNCLOUD_SSL_VERIFYPEER);
        curl_setopt($r, CURLOPT_SSL_VERIFYHOST, (bool) Config::get()->OWNCLOUD_SSL_VERIFYPEER);
Rasmus Fuhse's avatar
Rasmus Fuhse committed
        if ($GLOBALS['OWNCLOUD_VERBOSE']) {
            curl_setopt($r, CURLOPT_VERBOSE, true);
        }

        curl_exec($r);
        $status = curl_getinfo($r, CURLINFO_HTTP_CODE);
        curl_close($r);

Rasmus Fuhse's avatar
Rasmus Fuhse committed
        $plugin = PluginManager::getInstance()->getPlugin("OwnCloudPlugin");
        return (($status >= 200) && ($status < 300)) ? $plugin->getFolder($destination) : false;
Rasmus Fuhse's avatar
Rasmus Fuhse committed

    protected function getWebDavURL()
    {
Rasmus Fuhse's avatar
Rasmus Fuhse committed
        $url = Config::get()->OWNCLOUD_ENDPOINT ?: UserConfig::get($GLOBALS['user']->id)->OWNCLOUD_ENDPOINT_USER;
Rasmus Fuhse's avatar
Rasmus Fuhse committed
        if ($url[strlen($url) - 1] !== "/") {
            $url .= "/";
        }
        $webdav = $url . "remote.php/webdav/";
        return $webdav;
    }

    protected function fetchObjects()
    {
        if ($this->did_propfind === true) {
            return;
        }
        $webdav = $this->getWebDavURL();
        $root = "remote.php/webdav/".$this->id;


        $header = array();
        $header[] = self::getAuthHeader();
Rasmus Fuhse's avatar
Rasmus Fuhse committed
        $header[] = "Depth: 1";
Rasmus Fuhse's avatar
Rasmus Fuhse committed

        $r = curl_init();
        curl_setopt($r, CURLOPT_CUSTOMREQUEST, "PROPFIND");
        curl_setopt($r, CURLOPT_URL, $webdav . $this->id);
Rasmus Fuhse's avatar
Rasmus Fuhse committed
        curl_setopt($r, CURLOPT_HTTPHEADER, ($header));
        curl_setopt($r, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($r, CURLOPT_SSL_VERIFYPEER, (bool) Config::get()->OWNCLOUD_SSL_VERIFYPEER);
        curl_setopt($r, CURLOPT_SSL_VERIFYHOST, (bool) Config::get()->OWNCLOUD_SSL_VERIFYPEER);
Rasmus Fuhse's avatar
Rasmus Fuhse committed
        if ($GLOBALS['OWNCLOUD_VERBOSE']) {
            curl_setopt($r, CURLOPT_VERBOSE, true);
        }
Rasmus Fuhse's avatar
Rasmus Fuhse committed

        $xml = curl_exec($r);
        $info = curl_getinfo($r);
        if ($info['http_code'] === 401 && \Owncloud\OAuth::hasAccessToken()) {
            \Owncloud\OAuth::removeAccessToken();
            PageLayout::postError(sprintf(_("Zugangsberechtigung zu %s abgelaufen. Erneuern Sie die Verbindung zu %s."), Config::get()->OWNCLOUD_NAME, Config::get()->OWNCLOUD_NAME));
        }
Rasmus Fuhse's avatar
Rasmus Fuhse committed
        curl_close($r);

Rasmus Fuhse's avatar
Rasmus Fuhse committed
        if (!$xml) {
            PageLayout::postError(sprintf(_("Konnte keine Daten von %s bekommen."), Config::get()->OWNCLOUD_NAME));
Rasmus Fuhse's avatar
Rasmus Fuhse committed
            $this->subfolders = array();
            $this->files = array();
            $this->did_propfind = true;
            return;
        }

Rasmus Fuhse's avatar
Rasmus Fuhse committed
        $doc = new DOMDocument();
        $doc->loadXML($xml);

        foreach ($doc->getElementsByTagNameNS("DAV:", "error") as $error) {
            foreach ($error->childNodes as $node) {
                if (strtolower($node->tagName) === "s:message") {
                    PageLayout::postError($node->nodeValue);
                }
            }
        }

Rasmus Fuhse's avatar
Rasmus Fuhse committed
        foreach ($doc->getElementsByTagNameNS("DAV:","response") as $file) {
            //response
            //  -> href
            //  -> propstat
            //    -> prop
            //      -> resourcetype
            //      -> getcontentlength
            //      -> getcontenttype
            //      -> getlastmodified
            //    -> status
            $file_attributes = array();

            foreach ($file->childNodes as $node) {
Rasmus Fuhse's avatar
Rasmus Fuhse committed
                if (strtolower($node->tagName) === "d:href") {
                    $nodeValue = $node->nodeValue;
                    if ($nodeValue[strlen($nodeValue) - 1] === "/") {
                        $nodeValue = substr($nodeValue, 0, -1);
                    }
                    if ($nodeValue[0] === "/") {
                        $nodeValue = substr($nodeValue, 1);
                    }
Rasmus Fuhse's avatar
Rasmus Fuhse committed
                    $nodeValue = str_replace(array("(", ")", "'", "$", "+", "!", "*", ","), array("%28", "%29", "%27", "%24", "%2B", "%21", "%2A", "%2C"), $nodeValue); //for Owncloud only
Rasmus Fuhse's avatar
Rasmus Fuhse committed
                    if (strpos(rawurldecode($nodeValue), rawurldecode($root)) !== false) {
                        $path = substr($nodeValue, strpos(rawurldecode($nodeValue), rawurldecode($root)) + strlen($root));
                    } else {
                        $path = null;
                    }
Rasmus Fuhse's avatar
Rasmus Fuhse committed
                    $path_array = preg_split("/\//", $path, 0, PREG_SPLIT_NO_EMPTY);
                    $file_attributes['name'] = rawurldecode(array_pop($path_array));
                    if (!trim($file_attributes['name']) || ($path === $this->id) || !$path) {
Rasmus Fuhse's avatar
Rasmus Fuhse committed
                        continue 2;
                    }
                }
Rasmus Fuhse's avatar
Rasmus Fuhse committed
                if (strtolower($node->tagName) === "d:propstat") {
Rasmus Fuhse's avatar
Rasmus Fuhse committed
                    foreach ($node->childNodes as $prop) {
Rasmus Fuhse's avatar
Rasmus Fuhse committed
                        if ($prop->childNodes) {
                            foreach ($prop->childNodes as $attr) {
                                if (strtolower($attr->tagName) === "d:resourcetype") {
                                    $file_attributes['type'] = $attr->childNodes->item(0) && strtolower($attr->childNodes->item(0)->tagName) === "d:collection" ? "folder" : "file";
Rasmus Fuhse's avatar
Rasmus Fuhse committed
                                }
                                if (strtolower($attr->tagName) === "d:getcontentlength") {
                                    $file_attributes['size'] = $attr->nodeValue;
                                }
                                if (strtolower($attr->tagName) === "d:getcontenttype") {
                                    $file_attributes['contenttype'] = $attr->nodeValue;
                                }
                                if (strtolower($attr->tagName) === "d:creationdate") {
                                    $file_attributes['chdate'] = strtotime($attr->nodeValue);
                                }
                                if (strtolower($attr->tagName) === "d:displayname") {
                                    $file_attributes['name'] = $attr->nodeValue;
                                }
Rasmus Fuhse's avatar
Rasmus Fuhse committed
                                if (strtolower($attr->tagName) === "d:getlastmodified") {
Rasmus Fuhse's avatar
Rasmus Fuhse committed
                                    $file_attributes['chdate'] = strtotime($attr->nodeValue);
                                }
Rasmus Fuhse's avatar
Rasmus Fuhse committed
                            }
                        }
                    }
                }
            }
Rasmus Fuhse's avatar
Rasmus Fuhse committed
            if (trim($file_attributes['name'])) {
                if ($file_attributes['type'] === "folder") {
                    $this->subfolders[] = new OwncloudFolder(array(
                        'id' => ($this->id ? $this->id . "/" : "") . rawurlencode($file_attributes['name']),
                        'name' => $file_attributes['name'],
                        'parent_id' => $this->id,
                        'user_id' => $GLOBALS['user']->id,
Rasmus Fuhse's avatar
Rasmus Fuhse committed
                        'range_type' => $this->plugin_id,
                        'range_id' => 'OwnCloudPlugin'
                    ), $this->plugin_id);
                } else {
                    $content_type = $file_attributes['contenttype'] ?: get_mime_type($file_attributes['name']);
                    $this->files[] = new OwncloudFile([
Rasmus Fuhse's avatar
Rasmus Fuhse committed
                        'id' => ($this->id ? $this->id . "/" : "") . rawurlencode($file_attributes['name']),
                        'name' => $file_attributes['name'],
                        'size' => $file_attributes['size'],
                        'mime_type' => $content_type,
                        'description' => "",
                        'user_id' => $GLOBALS['user']->id,
Rasmus Fuhse's avatar
Rasmus Fuhse committed
                        'chdate' => $file_attributes['chdate'],
                        'download_url' => URLHelper::getURL("plugins.php/owncloudplugin/download/" . ($this->id ? $this->id . "/" : "") . rawurlencode($file_attributes['name']))
                    ], $this);
Rasmus Fuhse's avatar
Rasmus Fuhse committed
                }
Rasmus Fuhse's avatar
Rasmus Fuhse committed
            }
        }
        //var_dump($this->files); die();
Rasmus Fuhse's avatar
Rasmus Fuhse committed
        $this->did_propfind = true;
    }

    public function getFiles()
    {
        $this->fetchObjects();
        return $this->files;
    }

    public function getSubfolders()
    {
        $this->fetchObjects();
        return $this->subfolders;
Rasmus Fuhse's avatar
Rasmus Fuhse committed
    }

    public function setDataFromEditTemplate($request)
    {
        if (!$request['name']) {
            return MessageBox::error(_('Die Bezeichnung des Ordners fehlt.'));
        }

        $plugin = PluginEngine::getPlugin($request["from_plugin"]);
        if (empty($request['parent_id'])) {
            $this->folderdata['id'] = $request['name'];
        } else {
            $this->folderdata['id'] = $request['parent_id'] . '/' . $request['name'];
        $this->folderdata['parent_id'] = $request['parent_id'];
        $this->folderdata['range_type'] = $plugin->getPluginId();
        $this->folderdata['range_id'] = $plugin->getPluginName();
        $this->folderdata['plugin_id'] = $plugin->getPluginId();
        return $this;
    }

    public function getParent()
    {
        if ($this->id == $this->parent_id) {
            return null;
        }
        $plugin = PluginEngine::getPlugin('OwnCloudPlugin');
        return $plugin->getFolder($this->parent_id);
    }

Rasmus Fuhse's avatar
Rasmus Fuhse committed
    public function fileExists($name)
    {
        foreach ($this->getFiles() as $file) {
            if ($file->name === $name) {
                return true;
            }
        }
        return false;
    }

    public function folderExists($name)
    {
        foreach ($this->getSubfolders() as $folder) {
            if ($folder->name === $name) {
                return true;
            }
        }
        return false;
    }

    static public function getAuthHeader()
    {
        return "Authorization: Bearer " . \Owncloud\OAuth::getAccessToken();
    }

    public function getAdditionalColumns()
    {
        return [];
    }

    public function getAdditionalActionButtons()
    {
        return [];
    }