From 1573e402030462fe109172169042ff378e9046c4 Mon Sep 17 00:00:00 2001
From: Moritz Strohm <strohm@data-quest.de>
Date: Tue, 25 Jul 2023 17:33:33 +0200
Subject: [PATCH] fixed errors and compatibility problems with Stud.IP 5.3 and
 PHP 8.0

---
 OwnCloudPlugin.class.php   | 6 +++---
 classes/OwncloudFile.php   | 8 +++++++-
 classes/OwncloudFolder.php | 6 +++++-
 controllers/file.php       | 2 +-
 plugin.manifest            | 6 +++---
 5 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/OwnCloudPlugin.class.php b/OwnCloudPlugin.class.php
index ab8d23e..663ac5f 100755
--- a/OwnCloudPlugin.class.php
+++ b/OwnCloudPlugin.class.php
@@ -20,7 +20,7 @@ class OwnCloudPlugin extends StudIPPlugin implements FilesystemPlugin {
         } elseif (Navigation::hasItem('/contents/files/my_files')) {
             Navigation::activateItem('/contents/files/my_files');
         }
-        if ($folder_id[0] === "/") {
+        if ($folder_id && $folder_id[0] === "/") {
             $folder_id = substr($folder_id, 1);
         }
         if ($folder_id && !$this->isFolder($folder_id)) {
@@ -78,7 +78,7 @@ class OwnCloudPlugin extends StudIPPlugin implements FilesystemPlugin {
 
     /**
      * @param $file_id : this is a path to the file. Remind that the chunks of this path need to be rawurlencoded!
-     * @param bool $with_blob : should OwnCloudPlugin retrieve the blib of the file as well?
+     * @param bool $with_blob : should OwnCloudPlugin retrieve the blob of the file as well?
      * @return FileRef|null : Returns the FileRef on success and null if the file doesn't exist.
      */
     public function getPreparedFile($file_id, $with_blob = false)
@@ -162,7 +162,7 @@ class OwnCloudPlugin extends StudIPPlugin implements FilesystemPlugin {
         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']) {
+        if (!empty($GLOBALS['OWNCLOUD_VERBOSE'])) {
             curl_setopt($r, CURLOPT_VERBOSE, true);
         }
         $xml = curl_exec($r);
diff --git a/classes/OwncloudFile.php b/classes/OwncloudFile.php
index 1977d17..e99a2bb 100644
--- a/classes/OwncloudFile.php
+++ b/classes/OwncloudFile.php
@@ -225,7 +225,7 @@ class OwncloudFile implements FileType
                 _('Datei löschen'),
                 Icon::create('trash', Icon::ROLE_CLICKABLE, ['size' => 20]),
                 [
-                    'formaction'   => URLHelper::getURL("dispatch.php/file/delete/{$this->getId()}", $flat_view ? ['from_flat_view' => 1] : []),
+                    'formaction'   => URLHelper::getURL("dispatch.php/file/delete/{$this->getId()}"),
                     'data-confirm' => sprintf(_('Soll die Datei "%s" wirklich gelöscht werden?'), $this->getFilename()),
                 ]
             );
@@ -444,4 +444,10 @@ class OwncloudFile implements FileType
 
         return $this;
     }
+
+    public function getAccessibility(): bool
+    {
+        //This information is not available for Nextcloud/Owncloud files.
+        return false;
+    }
 }
diff --git a/classes/OwncloudFolder.php b/classes/OwncloudFolder.php
index 7d4cab2..b5a34b8 100755
--- a/classes/OwncloudFolder.php
+++ b/classes/OwncloudFolder.php
@@ -363,7 +363,7 @@ class OwncloudFolder extends VirtualFolderType {
         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']) {
+        if (!empty($GLOBALS['OWNCLOUD_VERBOSE'])) {
             curl_setopt($r, CURLOPT_VERBOSE, true);
         }
 
@@ -431,6 +431,10 @@ class OwncloudFolder extends VirtualFolderType {
                     foreach ($node->childNodes as $prop) {
                         if ($prop->childNodes) {
                             foreach ($prop->childNodes as $attr) {
+                                if (!($attr instanceof DOMElement)) {
+                                    //DOMText or another DOM class that doesn't fit in here.
+                                    continue;
+                                }
                                 if (strtolower($attr->tagName) === "d:resourcetype") {
                                     $file_attributes['type'] = $attr->childNodes->item(0) && strtolower($attr->childNodes->item(0)->tagName) === "d:collection" ? "folder" : "file";
                                 }
diff --git a/controllers/file.php b/controllers/file.php
index a9695ea..48ff656 100644
--- a/controllers/file.php
+++ b/controllers/file.php
@@ -42,7 +42,7 @@ class FileController extends PluginController
                 $this->name
             );
 
-            if (!$result instanceof FileRef) {
+            if (!($result instanceof FileType)) {
                 $this->errors = array_merge($this->errors, $result);
             }
 
diff --git a/plugin.manifest b/plugin.manifest
index e243060..528880d 100755
--- a/plugin.manifest
+++ b/plugin.manifest
@@ -1,6 +1,6 @@
 pluginname=OwnCloudPlugin
 pluginclassname=OwnCloudPlugin
-version=2.0.3
+version=2.1.0
 origin=data-quest
-studipMinVersion=4.6
-studipMaxVersion=5.2.99
+studipMinVersion=5.0
+studipMaxVersion=5.3.99
-- 
GitLab