From cdba520d92857e679e6cbc6486bd16b0217d8daf Mon Sep 17 00:00:00 2001
From: Jan-Hendrik Willms <tleilax+studip@gmail.com>
Date: Tue, 13 Jun 2023 13:14:44 +0000
Subject: [PATCH] fix incorrect usage of implode parameters, fixes #2729

Closes #2729

Merge request studip/studip!1847
---
 lib/elearning/Ilias3ConnectedPermissions.class.php |  6 ++----
 lib/elearning/Ilias3ContentModule.class.php        |  1 -
 lib/elearning/Ilias3Soap.class.php                 |  6 +++---
 lib/elearning/Ilias4Soap.class.php                 |  4 ++--
 lib/elearning/Ilias5Soap.class.php                 |  4 ++--
 lib/ilias_interface/IliasSoap.class.php            |  6 +++---
 lib/models/MvvFileFileref.php                      |  2 +-
 lib/soap/StudipSoapClient.class.php                | 13 ++++++-------
 8 files changed, 19 insertions(+), 23 deletions(-)

diff --git a/lib/elearning/Ilias3ConnectedPermissions.class.php b/lib/elearning/Ilias3ConnectedPermissions.class.php
index 9bf2fcd6d41..5ac5f59c24c 100644
--- a/lib/elearning/Ilias3ConnectedPermissions.class.php
+++ b/lib/elearning/Ilias3ConnectedPermissions.class.php
@@ -111,8 +111,6 @@ class Ilias3ConnectedPermissions extends ConnectedPermissions
                     }
                 }
             }
-//             if ($GLOBALS["debug"] == true)
-//                 echo "P$proper_role A$active_role U" . $user_crs_role . " R" . implode($connected_cms[$this->cms_type]->user->getRoles(), ".")."<br>";
         }
 
         // is user already course-member? otherwise add member with proper role
@@ -205,9 +203,9 @@ class Ilias3ConnectedPermissions extends ConnectedPermissions
                     $module_id,
                     $connected_cms[$this->cms_type]->user->getId()
                     );
-//      echo "MID".$module_id."UID".$connected_cms[$this->cms_type]->user->getId()."OPS".implode($this->tree_allowed_operations,"-") ;
-        if (! is_array($this->tree_allowed_operations))
+        if (!is_array($this->tree_allowed_operations)) {
             return false;
+        }
 
         $no_permission = false;
         if (isset($current_module)) { //TODO: fixes Warning:Creating default object from empty value - possible side effects
diff --git a/lib/elearning/Ilias3ContentModule.class.php b/lib/elearning/Ilias3ContentModule.class.php
index 63857bfc94d..3067575779b 100644
--- a/lib/elearning/Ilias3ContentModule.class.php
+++ b/lib/elearning/Ilias3ContentModule.class.php
@@ -62,7 +62,6 @@ class Ilias3ContentModule extends ContentModule
                 $user_name = trim($user_data["title"] . " " . $user_data["firstname"] . " " . $user_data["lastname"]);
                 $this->setAuthors($user_name);
             }
-//          echo $object_data["accessInfo"] . ": " . implode($object_data["operations"], ".");
             $this->setPermissions($object_data["accessInfo"], $object_data["operations"]);
         }
         else
diff --git a/lib/elearning/Ilias3Soap.class.php b/lib/elearning/Ilias3Soap.class.php
index 6a43b9bb611..4fc5a65f3d5 100644
--- a/lib/elearning/Ilias3Soap.class.php
+++ b/lib/elearning/Ilias3Soap.class.php
@@ -93,7 +93,7 @@ class Ilias3Soap extends StudipSoapClient
     */
     function call($method, $params)
     {
-        $index = md5($method . ":" . implode($params, "-"));
+        $index = md5($method . ":" . implode('-', $params));
         // return false if no session_id is given
         if (($method != "login") AND ($params["sid"] == ""))
             return false;
@@ -597,9 +597,9 @@ class Ilias3Soap extends StudipSoapClient
         {
             $objects = $this->parseXML($result);
             $roles = [];
-            foreach ($objects as $count => $role)
+            foreach ($objects as $count => $role) {
                 $roles[$count] = $role["obj_id"];
-//          echo implode($roles, ".");
+            }
             return $roles;
         }
         return false;
diff --git a/lib/elearning/Ilias4Soap.class.php b/lib/elearning/Ilias4Soap.class.php
index 91723386fb0..27c28fb0f53 100644
--- a/lib/elearning/Ilias4Soap.class.php
+++ b/lib/elearning/Ilias4Soap.class.php
@@ -141,7 +141,7 @@ class Ilias4Soap extends Ilias3Soap
         }
 
         if (is_array($path)) {
-            return implode($path, $this->separator_string);
+            return implode($this->separator_string, $path);
         } else {
             return false;
         }
@@ -173,7 +173,7 @@ class Ilias4Soap extends Ilias3Soap
         }
 
         if (is_array($path)) {
-            return implode($path, '_');
+            return implode('_', $path);
         } else {
             return false;
         }
diff --git a/lib/elearning/Ilias5Soap.class.php b/lib/elearning/Ilias5Soap.class.php
index 80c683d111b..cf8bd4c4e5b 100644
--- a/lib/elearning/Ilias5Soap.class.php
+++ b/lib/elearning/Ilias5Soap.class.php
@@ -30,7 +30,7 @@ class Ilias5Soap extends Ilias4Soap
      */
     function call($method, $params)
     {
-        $index = md5($method . ":" . implode($params, "-"));
+        $index = md5($method . ":" . implode('-', $params));
         // return false if no session_id is given
         if (($method != "login") AND ($params["sid"] == ""))
             return false;
@@ -111,4 +111,4 @@ class Ilias5Soap extends Ilias4Soap
         $result = $this->call('login', $param);
         return $result;
     }
-}
\ No newline at end of file
+}
diff --git a/lib/ilias_interface/IliasSoap.class.php b/lib/ilias_interface/IliasSoap.class.php
index 231b8e90f33..e140a9f5705 100644
--- a/lib/ilias_interface/IliasSoap.class.php
+++ b/lib/ilias_interface/IliasSoap.class.php
@@ -111,7 +111,7 @@ class IliasSoap extends StudipSoapClient
             return false;
         }
 
-        $cache_index = md5($method . ':' . implode($params, '-'));
+        $cache_index = md5($method . ':' . implode('-', $params));
         if ($this->caching_active && isset($this->soap_cache[$cache_index]) && $method !== 'login') {
             $result = $this->soap_cache[$cache_index];
         } else {
@@ -1128,7 +1128,7 @@ class IliasSoap extends StudipSoapClient
         }
 
         if (is_array($path)) {
-            return implode($path, $this->separator_string);
+            return implode($this->separator_string, $path);
         } else {
             return false;
         }
@@ -1160,7 +1160,7 @@ class IliasSoap extends StudipSoapClient
         }
 
         if (is_array($path)) {
-            return implode($path, '_');
+            return implode('_', $path);
         } else {
             return false;
         }
diff --git a/lib/models/MvvFileFileref.php b/lib/models/MvvFileFileref.php
index 13be9e15415..0771055936e 100644
--- a/lib/models/MvvFileFileref.php
+++ b/lib/models/MvvFileFileref.php
@@ -83,7 +83,7 @@ class MvvFileFileref extends ModuleManagementModel
                 list($category, $type) = explode('/', $mime_type, 2);
                 if ($category == 'application') {
                     foreach ($application_category as $name => $type_name) {
-                        if (preg_match('/' . implode($type_name, '|') . '/i', $type)) {
+                        if (preg_match('/' . implode('|', $type_name) . '/i', $type)) {
                             return $name;
                         }
                     }
diff --git a/lib/soap/StudipSoapClient.class.php b/lib/soap/StudipSoapClient.class.php
index 01b13928fa1..f6c0cadcbb0 100644
--- a/lib/soap/StudipSoapClient.class.php
+++ b/lib/soap/StudipSoapClient.class.php
@@ -32,15 +32,14 @@ class StudipSoapClient
         {
             $this->faultstring = $result["faultstring"];
             if (!in_array(mb_strtolower($this->faultstring), ["session not valid","session invalid", "session idled"]))
-                $this->error .= "<b>" . sprintf(_("SOAP-Fehler, Funktion \"%s\":"), $method) . "</b> " . $result["faultstring"] . " (" . $result["faultcode"] . ")<br>"; //.implode($params,"-");
-        }
-        else
-        {
+                $this->error .= "<b>" . sprintf(_("SOAP-Fehler, Funktion \"%s\":"), $method) . "</b> " . $result["faultstring"] . " (" . $result["faultcode"] . ")<br>";
+        } else {
             $err = $this->soap_client->getError();
-            if ($err)
-                $this->error .= "<b>" . sprintf(_("SOAP-Fehler, Funktion \"%s\":"), $method) . "</b> " . $err . "<br>"; //.implode($params,"-") . htmlspecialchars($this->soap_client->response, ENT_QUOTES);
-            else
+            if ($err) {
+                $this->error .= "<b>" . sprintf(_("SOAP-Fehler, Funktion \"%s\":"), $method) . "</b> " . $err . "<br>";
+            } else {
                 return $result;
+            }
         }
         error_log($this->error);
         return false;
-- 
GitLab