From 7e6bc04ef57185fa4591b056a796b5f591d57453 Mon Sep 17 00:00:00 2001 From: Rasmus Fuhse <fuhse@data-quest.de> Date: Wed, 10 Mar 2021 18:08:44 +0100 Subject: [PATCH] bugfixing uploads --- classes/OwncloudFile.php | 70 +++++++++++++++++++++----------------- classes/OwncloudFolder.php | 23 ++----------- 2 files changed, 41 insertions(+), 52 deletions(-) diff --git a/classes/OwncloudFile.php b/classes/OwncloudFile.php index 52be0ce..e25bdf1 100644 --- a/classes/OwncloudFile.php +++ b/classes/OwncloudFile.php @@ -98,7 +98,7 @@ class OwncloudFile implements FileType */ public function getDownloads() { - return 0; + return null; } @@ -178,31 +178,16 @@ class OwncloudFile implements FileType ['data-dialog' => ''], 'file-display-info' ); - if ($current_action === 'flat') { - if (Navigation::hasItem('/course/files') && Navigation::getItem('/course/files')->isActive()) { - $actionMenu->addLink( - URLHelper::getURL('dispatch.php/course/files/index/' . $this->fileref->folder_id), - _('Ordner öffnen'), - Icon::create('folder-empty', Icon::ROLE_CLICKABLE, ['size' => 20]) - ); - } elseif (Navigation::hasItem('/files_dashboard/files') && Navigation::getItem('/files_dashboard/files')->isActive()) { - $actionMenu->addLink( - URLHelper::getURL('dispatch.php/files/index/' . $this->fileref->folder_id), - _('Ordner öffnen'), - Icon::create('folder-empty', Icon::ROLE_CLICKABLE, ['size' => 20]) - ); - } - } if ($this->isEditable($GLOBALS['user']->id)) { $actionMenu->addLink( - URLHelper::getURL('dispatch.php/file/edit/' . $this->fileref->id), + URLHelper::getURL('dispatch.php/file/edit/' . $this->getId()), _('Datei bearbeiten'), Icon::create('edit', Icon::ROLE_CLICKABLE, ['size' => 20]), ['data-dialog' => ''], 'file-edit' ); $actionMenu->addLink( - URLHelper::getURL('dispatch.php/file/update/' . $this->fileref->id), + URLHelper::getURL('dispatch.php/file/update/' . $this->getId()), _('Datei aktualisieren'), Icon::create('refresh', Icon::ROLE_CLICKABLE, ['size' => 20]), ['data-dialog' => ''], @@ -211,7 +196,7 @@ class OwncloudFile implements FileType } if ($this->isWritable($GLOBALS['user']->id)) { $actionMenu->addLink( - URLHelper::getURL('dispatch.php/file/choose_destination/move/' . $this->fileref->id), + URLHelper::getURL('dispatch.php/file/choose_destination/move/' . $this->getId()), _('Datei verschieben'), Icon::create('file+move_right', Icon::ROLE_CLICKABLE, ['size' => 20]), ['data-dialog' => 'size=auto'], @@ -220,7 +205,7 @@ class OwncloudFile implements FileType } if ($this->isDownloadable($GLOBALS['user']->id) && $GLOBALS['user']->id !== 'nobody') { $actionMenu->addLink( - URLHelper::getURL('dispatch.php/file/choose_destination/copy/' . $this->fileref->id), + URLHelper::getURL('dispatch.php/file/choose_destination/copy/' . $this->getId()), _('Datei kopieren'), Icon::create('file+add', Icon::ROLE_CLICKABLE, ['size' => 20]), ['data-dialog' => 'size=auto'], @@ -234,16 +219,6 @@ class OwncloudFile implements FileType 'link-to-clipboard' ); } - if (Context::isCourse() && Feedback::isActivated()) { - if (Feedback::hasCreatePerm(Context::getId())) { - $actionMenu->addLink( - URLHelper::getURL('dispatch.php/course/feedback/create_form/'. $this->fileref->id . '/FileRef'), - _('Neues Feedback-Element'), - Icon::create('star+add', Icon::ROLE_CLICKABLE, ['size' => 20]), - ['data-dialog' => '1'] - ); - } - } if ($this->isWritable($GLOBALS['user']->id)) { $actionMenu->addButton( 'delete', @@ -344,7 +319,40 @@ class OwncloudFile implements FileType */ public function convertToStandardFile() { - //TODO + $url = Config::get()->OWNCLOUD_ENDPOINT ?: UserConfig::get($GLOBALS['user']->id)->OWNCLOUD_ENDPOINT_USER; + if ($url[strlen($url) - 1] !== "/") { + $url .= "/"; + } + $webdav = $url . "remote.php/webdav/"; + + $header = array(); + $header[] = OwnCloudFolder::getAuthHeader(); + + $r = curl_init(); + curl_setopt($r, CURLOPT_CUSTOMREQUEST, "GET"); + curl_setopt($r, CURLOPT_URL, $webdav.$file_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); + if ($GLOBALS['OWNCLOUD_VERBOSE']) { + curl_setopt($r, CURLOPT_VERBOSE, true); + } + + $content = curl_exec($r); + $info = curl_getinfo($r); + curl_close($r); + $path = $GLOBALS['TMP_PATH']."/owncloudplugin_".md5(uniqid()); + file_put_contents( + $path, + $content + ); + return StandardFile::create([ + 'name' => $this->getFilename(), + 'type' => $this->getMimeType(), + 'size' => $this->getSize(), + 'tmp_name' => $path + ]); } /** diff --git a/classes/OwncloudFolder.php b/classes/OwncloudFolder.php index 8088c83..73aa38a 100755 --- a/classes/OwncloudFolder.php +++ b/classes/OwncloudFolder.php @@ -125,27 +125,8 @@ class OwncloudFolder extends VirtualFolderType { $header = array(); $header[] = self::getAuthHeader(); - $url_template = "[InternetShortcut]\nURL=%s"; - - $data = $GLOBALS['TMP_PATH']."/file_".md5(uniqid()); - - if (is_a($file, "URLFile")) { - if ($filedata->getURL()) { - $data = $GLOBALS['TMP_PATH']."/file_".md5(uniqid()); - file_put_contents($data, sprintf($url_template, $filedata->getURL())); - $file_ref_id .= ".url"; - } else { - $data = $filedata->getPath(); - } - } else { - if ($filedata['url']) { - $data = $GLOBALS['TMP_PATH']."/file_".md5(uniqid()); - file_put_contents($data, sprintf($url_template, $filedata['url'])); - $file_ref_id .= ".url"; - } else { - $data = $filedata['tmp_name']; - } - } + $data = $file->getPath(); + //Verlinkungen URLFile extra berücksichtigen? $url_template = "[InternetShortcut]\nURL=%s"; $fh_res = fopen($data, 'r'); $r = curl_init(); -- GitLab