Completed
Push — master ( d13b22...a2d243 )
by Justin
05:45
created
packages/com.jukusoft.cms.plugin/extensions/filepermissionsinstaller.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -52,8 +52,8 @@  discard block
 block discarded – undo
52 52
 
53 53
 				$chmod_value = "0" . $chmod_value;
54 54
 
55
-				if(!chmod($file_path, $chmod_value)) {
56
-					throw new IllegalStateException("Cannot change file permissions of directory '". $file_path . "' (plugin: " . $plugin->getName() . ".");
55
+				if (!chmod($file_path, $chmod_value)) {
56
+					throw new IllegalStateException("Cannot change file permissions of directory '" . $file_path . "' (plugin: " . $plugin->getName() . ".");
57 57
 				}
58 58
 			}
59 59
 		}
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 		return $this->install($plugin, $install_json);
69 69
 	}
70 70
 
71
-	public function getPriority () : int {
71
+	public function getPriority() : int {
72 72
 		return 5;
73 73
 	}
74 74
 
Please login to merge, or discard this patch.
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -27,52 +27,52 @@
 block discarded – undo
27 27
 
28 28
 class FilePermissionsInstaller extends PluginInstaller_Plugin {
29 29
 
30
-	public function install(Plugin $plugin, array $install_json): bool {
31
-		if (isset($install_json['chmod'])) {
32
-			$files = $install_json['chmod'];
30
+    public function install(Plugin $plugin, array $install_json): bool {
31
+        if (isset($install_json['chmod'])) {
32
+            $files = $install_json['chmod'];
33 33
 
34
-			foreach ($files as $file=>$chmod_value) {
35
-				if (strpos($file, "..") !== FALSE) {
36
-					throw new IllegalArgumentException("Its not allowed that chmod file path in install.json of plugin '" . $plugin->getName() . "' contains '..' in path.");
37
-				}
34
+            foreach ($files as $file=>$chmod_value) {
35
+                if (strpos($file, "..") !== FALSE) {
36
+                    throw new IllegalArgumentException("Its not allowed that chmod file path in install.json of plugin '" . $plugin->getName() . "' contains '..' in path.");
37
+                }
38 38
 
39
-				$file_path = ROOT_PATH . $file;
39
+                $file_path = ROOT_PATH . $file;
40 40
 
41
-				if (!file_exists($file_path)) {
42
-					//create directory
43
-					throw new IllegalStateException("directory '" . htmlentities($file_path) . "' doesnt exists.");
41
+                if (!file_exists($file_path)) {
42
+                    //create directory
43
+                    throw new IllegalStateException("directory '" . htmlentities($file_path) . "' doesnt exists.");
44 44
 
45
-					//TODO: remove this line later
46
-					//mkdir($file_path);
47
-				}
45
+                    //TODO: remove this line later
46
+                    //mkdir($file_path);
47
+                }
48 48
 
49
-				if (strlen($chmod_value) != 3) {
50
-					throw new IllegalArgumentException("Exception in install.json of plugin '" . $plugin->getName() . "': chmod value has to be a length of 3 characters (like 755).");
51
-				}
49
+                if (strlen($chmod_value) != 3) {
50
+                    throw new IllegalArgumentException("Exception in install.json of plugin '" . $plugin->getName() . "': chmod value has to be a length of 3 characters (like 755).");
51
+                }
52 52
 
53
-				$chmod_value = "0" . $chmod_value;
53
+                $chmod_value = "0" . $chmod_value;
54 54
 
55
-				if(!chmod($file_path, $chmod_value)) {
56
-					throw new IllegalStateException("Cannot change file permissions of directory '". $file_path . "' (plugin: " . $plugin->getName() . ".");
57
-				}
58
-			}
59
-		}
55
+                if(!chmod($file_path, $chmod_value)) {
56
+                    throw new IllegalStateException("Cannot change file permissions of directory '". $file_path . "' (plugin: " . $plugin->getName() . ".");
57
+                }
58
+            }
59
+        }
60 60
 
61
-		return true;
62
-	}
61
+        return true;
62
+    }
63 63
 
64
-	public function uninstall(Plugin $plugin, array $install_json): bool {
65
-		//dont do anything
66
-		return true;
67
-	}
64
+    public function uninstall(Plugin $plugin, array $install_json): bool {
65
+        //dont do anything
66
+        return true;
67
+    }
68 68
 
69
-	public function upgrade(Plugin $plugin, array $install_json): bool {
70
-		return $this->install($plugin, $install_json);
71
-	}
69
+    public function upgrade(Plugin $plugin, array $install_json): bool {
70
+        return $this->install($plugin, $install_json);
71
+    }
72 72
 
73
-	public function getPriority () : int {
74
-		return 5;
75
-	}
73
+    public function getPriority () : int {
74
+        return 5;
75
+    }
76 76
 
77 77
 }
78 78
 
Please login to merge, or discard this patch.
system/packages/com.jukusoft.cms.tools/classes/sendmailpage.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -27,20 +27,20 @@  discard block
 block discarded – undo
27 27
 
28 28
 class SendMailPage extends PageType {
29 29
 
30
-	public function getAdditionalHeaderCode(): string {
31
-		$base_url = DomainUtils::getBaseURL() . "/";
30
+    public function getAdditionalHeaderCode(): string {
31
+        $base_url = DomainUtils::getBaseURL() . "/";
32 32
 
33
-		return "<!-- iCheck -->
33
+        return "<!-- iCheck -->
34 34
   				<link rel=\"stylesheet\" href=\"" . $base_url . "styles/admin/plugins/iCheck/flat/blue.css\">
35 35
 		
36 36
 				<!-- bootstrap wysihtml5 - text editor -->
37 37
   				<link rel=\"stylesheet\" href=\"" . $base_url . "styles/admin/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css\">";
38
-	}
38
+    }
39 39
 
40
-	public function getFooterScripts(): string {
41
-		$base_url = DomainUtils::getBaseURL() . "/";
40
+    public function getFooterScripts(): string {
41
+        $base_url = DomainUtils::getBaseURL() . "/";
42 42
 
43
-		return "<!-- iCheck -->
43
+        return "<!-- iCheck -->
44 44
 				<script src=\"" . $base_url . "styles/admin/plugins/iCheck/icheck.min.js\"></script>
45 45
 				<!-- Bootstrap WYSIHTML5 -->
46 46
 				<script src=\"" . $base_url . "styles/admin/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js\"></script>
@@ -59,79 +59,79 @@  discard block
 block discarded – undo
59 59
 					});
60 60
 				  });
61 61
 				</script>";
62
-	}
63
-
64
-	public function getContent(): string {
65
-		$template = new DwooTemplate("pages/sendmail");
66
-
67
-		$template->assign("form_action", DomainUtils::generateURL("admin/sendmail"));
68
-		$template->assign("content", "");
69
-
70
-		if (isset($_REQUEST['submit'])) {
71
-			//first, check csrf token
72
-			if (!Security::checkCSRFToken()) {
73
-				$template->assign("error_message", "Wrong CSRF token!");
74
-
75
-				if (isset($_POST['content'])) {
76
-					$template->assign("content", $_POST['content']);
77
-				}
78
-			} else {
79
-				$required_fields = array("to_mail", "subject", "content");
80
-
81
-				foreach ($required_fields as $field) {
82
-					if (!isset($_POST[$field]) || empty($_POST[$field])) {
83
-						$template->assign("error_message", "Please complete form!");
84
-
85
-						if (isset($_POST['content'])) {
86
-							$template->assign("content", $_POST['content']);
87
-						}
88
-
89
-						return $template->getCode();
90
-					}
91
-				}
92
-
93
-				//form is complete
94
-
95
-				//get values
96
-				$to_mail = $_POST['to_mail'];
97
-				$subject = $_POST['subject'];
98
-				$content = $_POST['content'];
99
-
100
-				//check, if mail is valide
101
-				if (!(new Validator_Mail())->isValide($to_mail)) {
102
-					$template->assign("error_message", "Mail is not valide!");
103
-
104
-					if (isset($_POST['content'])) {
105
-						$template->assign("content", $_POST['content']);
106
-					}
107
-				} else if (!(new Validator_String())->isValide($subject)) {
108
-					$template->assign("error_message", "Subject is not valide!");
109
-
110
-					if (isset($_POST['content'])) {
111
-						$template->assign("content", $_POST['content']);
112
-					}
113
-				} else {
114
-					//parameters are valide, send mail
115
-
116
-					if (MailApi::sendHTMLMail($to_mail, $subject, $content)) {
117
-						$template->assign("success_message", "Mail sended successfully!");
118
-					} else {
119
-						$template->assign("error_message", "Sending of mail failed!");
120
-
121
-						if (isset($_POST['content'])) {
122
-							$template->assign("content", $_POST['content']);
123
-						}
124
-					}
125
-				}
126
-			}
127
-		}
128
-
129
-		return $template->getCode();
130
-	}
131
-
132
-	public function listRequiredPermissions(): array {
133
-		return array("can_send_board_mails");
134
-	}
62
+    }
63
+
64
+    public function getContent(): string {
65
+        $template = new DwooTemplate("pages/sendmail");
66
+
67
+        $template->assign("form_action", DomainUtils::generateURL("admin/sendmail"));
68
+        $template->assign("content", "");
69
+
70
+        if (isset($_REQUEST['submit'])) {
71
+            //first, check csrf token
72
+            if (!Security::checkCSRFToken()) {
73
+                $template->assign("error_message", "Wrong CSRF token!");
74
+
75
+                if (isset($_POST['content'])) {
76
+                    $template->assign("content", $_POST['content']);
77
+                }
78
+            } else {
79
+                $required_fields = array("to_mail", "subject", "content");
80
+
81
+                foreach ($required_fields as $field) {
82
+                    if (!isset($_POST[$field]) || empty($_POST[$field])) {
83
+                        $template->assign("error_message", "Please complete form!");
84
+
85
+                        if (isset($_POST['content'])) {
86
+                            $template->assign("content", $_POST['content']);
87
+                        }
88
+
89
+                        return $template->getCode();
90
+                    }
91
+                }
92
+
93
+                //form is complete
94
+
95
+                //get values
96
+                $to_mail = $_POST['to_mail'];
97
+                $subject = $_POST['subject'];
98
+                $content = $_POST['content'];
99
+
100
+                //check, if mail is valide
101
+                if (!(new Validator_Mail())->isValide($to_mail)) {
102
+                    $template->assign("error_message", "Mail is not valide!");
103
+
104
+                    if (isset($_POST['content'])) {
105
+                        $template->assign("content", $_POST['content']);
106
+                    }
107
+                } else if (!(new Validator_String())->isValide($subject)) {
108
+                    $template->assign("error_message", "Subject is not valide!");
109
+
110
+                    if (isset($_POST['content'])) {
111
+                        $template->assign("content", $_POST['content']);
112
+                    }
113
+                } else {
114
+                    //parameters are valide, send mail
115
+
116
+                    if (MailApi::sendHTMLMail($to_mail, $subject, $content)) {
117
+                        $template->assign("success_message", "Mail sended successfully!");
118
+                    } else {
119
+                        $template->assign("error_message", "Sending of mail failed!");
120
+
121
+                        if (isset($_POST['content'])) {
122
+                            $template->assign("content", $_POST['content']);
123
+                        }
124
+                    }
125
+                }
126
+            }
127
+        }
128
+
129
+        return $template->getCode();
130
+    }
131
+
132
+    public function listRequiredPermissions(): array {
133
+        return array("can_send_board_mails");
134
+    }
135 135
 
136 136
 }
137 137
 
Please login to merge, or discard this patch.
system/packages/com.jukusoft.cms.tools/classes/clearcachepage.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -27,15 +27,15 @@
 block discarded – undo
27 27
 
28 28
 class ClearCachePage extends PageType {
29 29
 
30
-	public function getContent(): string {
31
-		Registry::singleton()->setSetting("clear_cache", true);
30
+    public function getContent(): string {
31
+        Registry::singleton()->setSetting("clear_cache", true);
32 32
 
33
-		$template = new DwooTemplate("pages/clearcache");
33
+        $template = new DwooTemplate("pages/clearcache");
34 34
 
35
-		$template->assign("success_message", "Cache cleared successfully!");
35
+        $template->assign("success_message", "Cache cleared successfully!");
36 36
 
37
-		return $template->getCode();
38
-	}
37
+        return $template->getCode();
38
+    }
39 39
 
40 40
 }
41 41
 
Please login to merge, or discard this patch.
plugins/calender/install/install.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -17,8 +17,8 @@
 block discarded – undo
17 17
  */
18 18
 
19 19
 if (!defined("PLUGIN_INSTALLER")) {
20
-	echo "You cannot access this file directly!";
21
-	exit;
20
+    echo "You cannot access this file directly!";
21
+    exit;
22 22
 }
23 23
 
24 24
 /**
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@
 block discarded – undo
63 63
 $table->addVarchar("image", 600, true, "none");
64 64
 $table->addInt("all_day", 10, true, false, 0);
65 65
 $table->addTimestamp("from_date", true, "0000-00-00 00:00:00");
66
-$table->addTimestamp("to_date",true, "0000-00-00 00:00:00");
66
+$table->addTimestamp("to_date", true, "0000-00-00 00:00:00");
67 67
 $table->addVarchar("location", 600, true, "");
68 68
 $table->addVarchar("color", 255, true, "none");
69 69
 $table->addInt("activated", 10, true, false, 1);
Please login to merge, or discard this patch.
plugins/calender/install/uninstall.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -26,8 +26,8 @@
 block discarded – undo
26 26
  */
27 27
 
28 28
 if (!defined("PLUGIN_INSTALLER")) {
29
-	echo "You cannot access this file directly!";
30
-	exit;
29
+    echo "You cannot access this file directly!";
30
+    exit;
31 31
 }
32 32
 
33 33
 //delete plugin tables
Please login to merge, or discard this patch.
system/core/classes/phputils.php 2 patches
Indentation   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -11,176 +11,176 @@
 block discarded – undo
11 11
     }
12 12
 
13 13
     public static function isModRewriteAvailable () {
14
-    	if (function_exists("apache_get_modules")) {
15
-    		if (in_array('mod_rewrite',apache_get_modules())) {
16
-    			return true;
17
-			}
14
+        if (function_exists("apache_get_modules")) {
15
+            if (in_array('mod_rewrite',apache_get_modules())) {
16
+                return true;
17
+            }
18 18
 
19
-			return false;
20
-		}
19
+            return false;
20
+        }
21 21
 
22
-		return false;
23
-	}
24
-
25
-	public static function startsWith ($haystack, $needle) : bool {
26
-    	//https://stackoverflow.com/questions/834303/startswith-and-endswith-functions-in-php
22
+        return false;
23
+    }
27 24
 
28
-		$length = strlen($needle);
29
-		return (substr($haystack, 0, $length) === $needle);
30
-	}
25
+    public static function startsWith ($haystack, $needle) : bool {
26
+        //https://stackoverflow.com/questions/834303/startswith-and-endswith-functions-in-php
31 27
 
32
-	public static function endsWith ($haystack, $needle) : bool {
33
-		$length = strlen($needle);
28
+        $length = strlen($needle);
29
+        return (substr($haystack, 0, $length) === $needle);
30
+    }
34 31
 
35
-		return $length === 0 || (substr($haystack, -$length) === $needle);
36
-	}
32
+    public static function endsWith ($haystack, $needle) : bool {
33
+        $length = strlen($needle);
37 34
 
38
-	/**
39
-	 * get IP address of client browser
40
-	 *
41
-	 * @return IPv4 / IPv6 address (up to 45 characters)
42
-	 */
43
-	public static function getClientIP () : string {
44
-    	//https://stackoverflow.com/questions/3003145/how-to-get-the-client-ip-address-in-php
35
+        return $length === 0 || (substr($haystack, -$length) === $needle);
36
+    }
45 37
 
46
-    	$ip = "";
38
+    /**
39
+     * get IP address of client browser
40
+     *
41
+     * @return IPv4 / IPv6 address (up to 45 characters)
42
+     */
43
+    public static function getClientIP () : string {
44
+        //https://stackoverflow.com/questions/3003145/how-to-get-the-client-ip-address-in-php
45
+
46
+        $ip = "";
47
+
48
+        if (isset($_SERVER['HTTP_CLIENT_IP']) && !empty($_SERVER['HTTP_CLIENT_IP'])) {
49
+            $ip = $_SERVER['HTTP_CLIENT_IP'];
50
+        } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
51
+            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
52
+        } else {
53
+            $ip = $_SERVER['REMOTE_ADDR'];
54
+        }
55
+
56
+        return $ip;
57
+    }
47 58
 
48
-		if (isset($_SERVER['HTTP_CLIENT_IP']) && !empty($_SERVER['HTTP_CLIENT_IP'])) {
49
-			$ip = $_SERVER['HTTP_CLIENT_IP'];
50
-		} elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
51
-			$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
52
-		} else {
53
-			$ip = $_SERVER['REMOTE_ADDR'];
54
-		}
59
+    public static function strEqs (string $str1, string $str2) : bool {
60
+        return strcmp($str1, $str2) === 0;
61
+    }
55 62
 
56
-		return $ip;
57
-	}
58
-
59
-	public static function strEqs (string $str1, string $str2) : bool {
60
-		return strcmp($str1, $str2) === 0;
61
-	}
62
-
63
-	/**
64
-	 * Generate a random string, using a cryptographically secure
65
-	 * pseudorandom number generator (random_int)
66
-	 *
67
-	 * For PHP 7, random_int is a PHP core function
68
-	 * For PHP 5.x, depends on https://github.com/paragonie/random_compat
69
-	 *
70
-	 * @param int $length      How many characters do we want?
71
-	 * @param string $keyspace A string of all possible characters
72
-	 *                         to select from
73
-	 *
74
-	 * @link https://stackoverflow.com/questions/4356289/php-random-string-generator/31107425#31107425
75
-	 *
76
-	 * @return string
77
-	 */
78
-	public static function randomString(int $length, string $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') : string {
79
-		$str = '';
80
-		$max = mb_strlen($keyspace, '8bit') - 1;
81
-
82
-		for ($i = 0; $i < $length; ++$i) {
83
-			$str .= $keyspace[random_int(0, $max)];
84
-		}
63
+    /**
64
+     * Generate a random string, using a cryptographically secure
65
+     * pseudorandom number generator (random_int)
66
+     *
67
+     * For PHP 7, random_int is a PHP core function
68
+     * For PHP 5.x, depends on https://github.com/paragonie/random_compat
69
+     *
70
+     * @param int $length      How many characters do we want?
71
+     * @param string $keyspace A string of all possible characters
72
+     *                         to select from
73
+     *
74
+     * @link https://stackoverflow.com/questions/4356289/php-random-string-generator/31107425#31107425
75
+     *
76
+     * @return string
77
+     */
78
+    public static function randomString(int $length, string $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') : string {
79
+        $str = '';
80
+        $max = mb_strlen($keyspace, '8bit') - 1;
81
+
82
+        for ($i = 0; $i < $length; ++$i) {
83
+            $str .= $keyspace[random_int(0, $max)];
84
+        }
85
+
86
+        return $str;
87
+    }
85 88
 
86
-		return $str;
87
-	}
89
+    public static function getHostname () : string {
90
+        if (function_exists("gethostname")) {
91
+            return gethostname();
92
+        } else {
93
+            //Or, an option that also works before PHP 5.3
94
+            return php_uname('n');
95
+        }
96
+    }
88 97
 
89
-	public static function getHostname () : string {
90
-		if (function_exists("gethostname")) {
91
-			return gethostname();
92
-		} else {
93
-			//Or, an option that also works before PHP 5.3
94
-			return php_uname('n');
95
-		}
96
-	}
97
-
98
-	public static function sendPOSTRequest (string $url, array $data = array()) {
99
-		//check, if allow_url_fopen is enabled
100
-		if (PHPUtils::isUrlfopenEnabled()) {
101
-			// use key 'http' even if you send the request to https://...
102
-			$options = array(
103
-				'http' => array(
104
-					'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
105
-					'method'  => 'POST',
106
-					'content' => http_build_query($data)
107
-				)
108
-			);
109
-			$context  = stream_context_create($options);
110
-			$result = file_get_contents($url, false, $context);
111
-
112
-			if ($result === FALSE) {
113
-				return false;
114
-			}
115
-
116
-			return $result;
117
-		} else {
118
-			//try to use curl instead
119
-
120
-			//https://stackoverflow.com/questions/2138527/php-curl-http-post-sample-code?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
121
-
122
-			//create a new curl session
123
-			$ch = curl_init();
124
-
125
-			curl_setopt($ch, CURLOPT_URL, $url);
126
-			curl_setopt($ch, CURLOPT_POST, 1);
127
-			curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));//"postvar1=value1&postvar2=value2&postvar3=value3"
128
-
129
-			//receive server response
130
-			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
131
-			$result = curl_exec ($ch);
132
-
133
-			//close curl session
134
-			curl_close ($ch);
135
-
136
-			return $result;
137
-		}
138
-	}
98
+    public static function sendPOSTRequest (string $url, array $data = array()) {
99
+        //check, if allow_url_fopen is enabled
100
+        if (PHPUtils::isUrlfopenEnabled()) {
101
+            // use key 'http' even if you send the request to https://...
102
+            $options = array(
103
+                'http' => array(
104
+                    'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
105
+                    'method'  => 'POST',
106
+                    'content' => http_build_query($data)
107
+                )
108
+            );
109
+            $context  = stream_context_create($options);
110
+            $result = file_get_contents($url, false, $context);
111
+
112
+            if ($result === FALSE) {
113
+                return false;
114
+            }
115
+
116
+            return $result;
117
+        } else {
118
+            //try to use curl instead
119
+
120
+            //https://stackoverflow.com/questions/2138527/php-curl-http-post-sample-code?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
121
+
122
+            //create a new curl session
123
+            $ch = curl_init();
124
+
125
+            curl_setopt($ch, CURLOPT_URL, $url);
126
+            curl_setopt($ch, CURLOPT_POST, 1);
127
+            curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));//"postvar1=value1&postvar2=value2&postvar3=value3"
128
+
129
+            //receive server response
130
+            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
131
+            $result = curl_exec ($ch);
132
+
133
+            //close curl session
134
+            curl_close ($ch);
135
+
136
+            return $result;
137
+        }
138
+    }
139 139
 
140
-	public static function isUrlfopenEnabled () : bool {
141
-		$res = ini_get("allow_url_fopen");
140
+    public static function isUrlfopenEnabled () : bool {
141
+        $res = ini_get("allow_url_fopen");
142 142
 
143
-		if ($res) {
144
-			return true;
145
-		} else {
146
-			return false;
147
-		}
148
-	}
143
+        if ($res) {
144
+            return true;
145
+        } else {
146
+            return false;
147
+        }
148
+    }
149 149
 
150
-	public static function isCurlAvailable () : bool {
151
-		/*if  (in_array  ('curl', get_loaded_extensions())) {
150
+    public static function isCurlAvailable () : bool {
151
+        /*if  (in_array  ('curl', get_loaded_extensions())) {
152 152
 			return true;
153 153
 		}
154 154
 		else {
155 155
 			return false;
156 156
 		}*/
157 157
 
158
-		return function_exists('curl_version');
159
-	}
158
+        return function_exists('curl_version');
159
+    }
160 160
 
161
-	public static function isGettextAvailable () : bool {
162
-		return function_exists("gettext");
163
-	}
161
+    public static function isGettextAvailable () : bool {
162
+        return function_exists("gettext");
163
+    }
164 164
 
165
-	public static function clearGetTextCache () {
166
-		//clear stats cache, often this clears also gettext cache
167
-		clearstatcache();
168
-	}
165
+    public static function clearGetTextCache () {
166
+        //clear stats cache, often this clears also gettext cache
167
+        clearstatcache();
168
+    }
169 169
 
170
-	public static function checkSessionStarted (bool $throw_exception = true) : bool {
171
-		if (session_status() !== PHP_SESSION_ACTIVE) {
172
-			if ($throw_exception) {
173
-				throw new IllegalStateException("session wasnt started yet.");
174
-			}
170
+    public static function checkSessionStarted (bool $throw_exception = true) : bool {
171
+        if (session_status() !== PHP_SESSION_ACTIVE) {
172
+            if ($throw_exception) {
173
+                throw new IllegalStateException("session wasnt started yet.");
174
+            }
175 175
 
176
-			return false;
177
-		}
176
+            return false;
177
+        }
178 178
 
179
-		return true;
180
-	}
179
+        return true;
180
+    }
181 181
 
182
-	public static function containsStr (string $haystack, string $needle) : bool {
183
-		return strpos($haystack, $needle) !== FALSE;
184
-	}
182
+    public static function containsStr (string $haystack, string $needle) : bool {
183
+        return strpos($haystack, $needle) !== FALSE;
184
+    }
185 185
 
186 186
 }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -2,17 +2,17 @@  discard block
 block discarded – undo
2 2
 
3 3
 class PHPUtils {
4 4
 
5
-    public static function isMemcacheAvailable () {
5
+    public static function isMemcacheAvailable() {
6 6
         return class_exists('Memcache');
7 7
     }
8 8
 
9
-    public static function isMemcachedAvailable () {
9
+    public static function isMemcachedAvailable() {
10 10
         return class_exists('Memcached');
11 11
     }
12 12
 
13
-    public static function isModRewriteAvailable () {
13
+    public static function isModRewriteAvailable() {
14 14
     	if (function_exists("apache_get_modules")) {
15
-    		if (in_array('mod_rewrite',apache_get_modules())) {
15
+    		if (in_array('mod_rewrite', apache_get_modules())) {
16 16
     			return true;
17 17
 			}
18 18
 
@@ -22,14 +22,14 @@  discard block
 block discarded – undo
22 22
 		return false;
23 23
 	}
24 24
 
25
-	public static function startsWith ($haystack, $needle) : bool {
25
+	public static function startsWith($haystack, $needle) : bool {
26 26
     	//https://stackoverflow.com/questions/834303/startswith-and-endswith-functions-in-php
27 27
 
28 28
 		$length = strlen($needle);
29 29
 		return (substr($haystack, 0, $length) === $needle);
30 30
 	}
31 31
 
32
-	public static function endsWith ($haystack, $needle) : bool {
32
+	public static function endsWith($haystack, $needle) : bool {
33 33
 		$length = strlen($needle);
34 34
 
35 35
 		return $length === 0 || (substr($haystack, -$length) === $needle);
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	 *
41 41
 	 * @return IPv4 / IPv6 address (up to 45 characters)
42 42
 	 */
43
-	public static function getClientIP () : string {
43
+	public static function getClientIP() : string {
44 44
     	//https://stackoverflow.com/questions/3003145/how-to-get-the-client-ip-address-in-php
45 45
 
46 46
     	$ip = "";
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 		return $ip;
57 57
 	}
58 58
 
59
-	public static function strEqs (string $str1, string $str2) : bool {
59
+	public static function strEqs(string $str1, string $str2) : bool {
60 60
 		return strcmp($str1, $str2) === 0;
61 61
 	}
62 62
 
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 		return $str;
87 87
 	}
88 88
 
89
-	public static function getHostname () : string {
89
+	public static function getHostname() : string {
90 90
 		if (function_exists("gethostname")) {
91 91
 			return gethostname();
92 92
 		} else {
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 		}
96 96
 	}
97 97
 
98
-	public static function sendPOSTRequest (string $url, array $data = array()) {
98
+	public static function sendPOSTRequest(string $url, array $data = array()) {
99 99
 		//check, if allow_url_fopen is enabled
100 100
 		if (PHPUtils::isUrlfopenEnabled()) {
101 101
 			// use key 'http' even if you send the request to https://...
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 					'content' => http_build_query($data)
107 107
 				)
108 108
 			);
109
-			$context  = stream_context_create($options);
109
+			$context = stream_context_create($options);
110 110
 			$result = file_get_contents($url, false, $context);
111 111
 
112 112
 			if ($result === FALSE) {
@@ -124,20 +124,20 @@  discard block
 block discarded – undo
124 124
 
125 125
 			curl_setopt($ch, CURLOPT_URL, $url);
126 126
 			curl_setopt($ch, CURLOPT_POST, 1);
127
-			curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));//"postvar1=value1&postvar2=value2&postvar3=value3"
127
+			curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); //"postvar1=value1&postvar2=value2&postvar3=value3"
128 128
 
129 129
 			//receive server response
130 130
 			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
131
-			$result = curl_exec ($ch);
131
+			$result = curl_exec($ch);
132 132
 
133 133
 			//close curl session
134
-			curl_close ($ch);
134
+			curl_close($ch);
135 135
 
136 136
 			return $result;
137 137
 		}
138 138
 	}
139 139
 
140
-	public static function isUrlfopenEnabled () : bool {
140
+	public static function isUrlfopenEnabled() : bool {
141 141
 		$res = ini_get("allow_url_fopen");
142 142
 
143 143
 		if ($res) {
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 		}
148 148
 	}
149 149
 
150
-	public static function isCurlAvailable () : bool {
150
+	public static function isCurlAvailable() : bool {
151 151
 		/*if  (in_array  ('curl', get_loaded_extensions())) {
152 152
 			return true;
153 153
 		}
@@ -158,16 +158,16 @@  discard block
 block discarded – undo
158 158
 		return function_exists('curl_version');
159 159
 	}
160 160
 
161
-	public static function isGettextAvailable () : bool {
161
+	public static function isGettextAvailable() : bool {
162 162
 		return function_exists("gettext");
163 163
 	}
164 164
 
165
-	public static function clearGetTextCache () {
165
+	public static function clearGetTextCache() {
166 166
 		//clear stats cache, often this clears also gettext cache
167 167
 		clearstatcache();
168 168
 	}
169 169
 
170
-	public static function checkSessionStarted (bool $throw_exception = true) : bool {
170
+	public static function checkSessionStarted(bool $throw_exception = true) : bool {
171 171
 		if (session_status() !== PHP_SESSION_ACTIVE) {
172 172
 			if ($throw_exception) {
173 173
 				throw new IllegalStateException("session wasnt started yet.");
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 		return true;
180 180
 	}
181 181
 
182
-	public static function containsStr (string $haystack, string $needle) : bool {
182
+	public static function containsStr(string $haystack, string $needle) : bool {
183 183
 		return strpos($haystack, $needle) !== FALSE;
184 184
 	}
185 185
 
Please login to merge, or discard this patch.
system/packages/com.jukusoft.cms.plugin/extensions/apimethodinstaller.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -27,34 +27,34 @@
 block discarded – undo
27 27
 
28 28
 class ApiMethodInstaller extends PluginInstaller_Plugin {
29 29
 
30
-	public function install(Plugin $plugin, array $install_json): bool {
31
-		if (isset($install_json['api_methods'])) {
32
-			foreach ($install_json['api_methods'] as $array) {
33
-				$api_method = $array['api_method'];
34
-				$classname = $array['class'];
35
-				$method = $array['method'];
36
-
37
-				//add api method
38
-				ApiMethod::addMethod($api_method, $classname, $method, "plugin_" . $plugin->getName());
39
-			}
40
-		}
41
-
42
-		return true;
43
-	}
44
-
45
-	public function uninstall(Plugin $plugin, array $install_json): bool {
46
-		ApiMethod::deleteMethodsByOwner("plugin_" . $plugin->getName());
47
-
48
-		return true;
49
-	}
50
-
51
-	public function upgrade(Plugin $plugin, array $install_json): bool {
52
-		//remove api methods first
53
-		$this->uninstall($plugin, $install_json);
54
-
55
-		//install api methods
56
-		return $this->install($plugin, $install_json);
57
-	}
30
+    public function install(Plugin $plugin, array $install_json): bool {
31
+        if (isset($install_json['api_methods'])) {
32
+            foreach ($install_json['api_methods'] as $array) {
33
+                $api_method = $array['api_method'];
34
+                $classname = $array['class'];
35
+                $method = $array['method'];
36
+
37
+                //add api method
38
+                ApiMethod::addMethod($api_method, $classname, $method, "plugin_" . $plugin->getName());
39
+            }
40
+        }
41
+
42
+        return true;
43
+    }
44
+
45
+    public function uninstall(Plugin $plugin, array $install_json): bool {
46
+        ApiMethod::deleteMethodsByOwner("plugin_" . $plugin->getName());
47
+
48
+        return true;
49
+    }
50
+
51
+    public function upgrade(Plugin $plugin, array $install_json): bool {
52
+        //remove api methods first
53
+        $this->uninstall($plugin, $install_json);
54
+
55
+        //install api methods
56
+        return $this->install($plugin, $install_json);
57
+    }
58 58
 
59 59
 }
60 60
 
Please login to merge, or discard this patch.
system/packages/com.jukusoft.cms.apimethods/classes/apimethod.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -21,11 +21,11 @@  discard block
 block discarded – undo
21 21
 	protected $apimethods = array();
22 22
 	protected $method = array();
23 23
 
24
-	public function __construct () {
24
+	public function __construct() {
25 25
 		//
26 26
 	}
27 27
 
28
-	public function loadApiMethods () {
28
+	public function loadApiMethods() {
29 29
 
30 30
 		if (Cache::contains("apimethods", "apimethods")) {
31 31
 			$this->apimethods = Cache::get("apimethods", "apimethods");
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 
43 43
 	}
44 44
 
45
-	public function loadMethod ($method) : bool {
45
+	public function loadMethod($method) : bool {
46 46
 		if (isset($this->apimethods[$method])) {
47 47
 			$this->method = $this->apimethods[$method];
48 48
 
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 		return false;
53 53
 	}
54 54
 
55
-	public function executeApiMethod () {
55
+	public function executeApiMethod() {
56 56
 
57 57
 		if (!$this->method) {
58 58
 			exit;
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 		}
82 82
 	}
83 83
 
84
-	public static function addMethod (string $api_method, string $class_name, string $method, string $owner = "system", string $response_type = "") {
84
+	public static function addMethod(string $api_method, string $class_name, string $method, string $owner = "system", string $response_type = "") {
85 85
 		//add method to database
86 86
 		Database::getInstance()->execute("INSERT INTO `{praefix}api_methods` (
87 87
 			`api_method`, `classname`, `method`, `response_type`, `owner`, `activated`
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 		Cache::clear("apimethods");
100 100
 	}
101 101
 
102
-	public static function deleteMethod (string $api_method) {
102
+	public static function deleteMethod(string $api_method) {
103 103
 		//delete from database
104 104
 		Database::getInstance()->execute("DELETE FROM `{praefix}api_methods` WHERE `api_method` = :api_method; ", array(
105 105
 			'api_method' => $api_method
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 		Cache::clear("apimethods");
110 110
 	}
111 111
 
112
-	public static function deleteMethodsByOwner (string $owner) {
112
+	public static function deleteMethodsByOwner(string $owner) {
113 113
 		//delete from database
114 114
 		Database::getInstance()->execute("DELETE FROM `{praefix}api_methods` WHERE `owner` = :owner; ", array(
115 115
 			'owner' => $owner
Please login to merge, or discard this patch.
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -18,106 +18,106 @@
 block discarded – undo
18 18
 
19 19
 class ApiMethod {
20 20
 
21
-	protected $apimethods = array();
22
-	protected $method = array();
21
+    protected $apimethods = array();
22
+    protected $method = array();
23 23
 
24
-	public function __construct () {
25
-		//
26
-	}
24
+    public function __construct () {
25
+        //
26
+    }
27 27
 
28
-	public function loadApiMethods () {
28
+    public function loadApiMethods () {
29 29
 
30
-		if (Cache::contains("apimethods", "apimethods")) {
31
-			$this->apimethods = Cache::get("apimethods", "apimethods");
32
-		} else {
33
-			$rows = (Array) DataBase::getInstance()->listRows("SELECT * FROM `{praefix}api_methods` WHERE `activated` = '1'; ");
30
+        if (Cache::contains("apimethods", "apimethods")) {
31
+            $this->apimethods = Cache::get("apimethods", "apimethods");
32
+        } else {
33
+            $rows = (Array) DataBase::getInstance()->listRows("SELECT * FROM `{praefix}api_methods` WHERE `activated` = '1'; ");
34 34
 
35
-			foreach ($rows as $row) {
36
-				$row = (Array) $row;
37
-				$this->apimethods[$row['api_method']] = $row;
38
-			}
35
+            foreach ($rows as $row) {
36
+                $row = (Array) $row;
37
+                $this->apimethods[$row['api_method']] = $row;
38
+            }
39 39
 
40
-			Cache::put("apimethods", "apimethods", $this->apimethods);
41
-		}
40
+            Cache::put("apimethods", "apimethods", $this->apimethods);
41
+        }
42 42
 
43
-	}
43
+    }
44 44
 
45
-	public function loadMethod ($method) : bool {
46
-		if (isset($this->apimethods[$method])) {
47
-			$this->method = $this->apimethods[$method];
45
+    public function loadMethod ($method) : bool {
46
+        if (isset($this->apimethods[$method])) {
47
+            $this->method = $this->apimethods[$method];
48 48
 
49
-			return true;
50
-		}
49
+            return true;
50
+        }
51 51
 
52
-		return false;
53
-	}
52
+        return false;
53
+    }
54 54
 
55
-	public function executeApiMethod () {
55
+    public function executeApiMethod () {
56 56
 
57
-		if (!$this->method) {
58
-			exit;
59
-		}
57
+        if (!$this->method) {
58
+            exit;
59
+        }
60 60
 
61
-		if ($this->method['response_type'] != "specific") {
62
-			header("Content-Type: " . $this->method['response_type']);
63
-		}
61
+        if ($this->method['response_type'] != "specific") {
62
+            header("Content-Type: " . $this->method['response_type']);
63
+        }
64 64
 
65
-		$classname = $this->method['classname'];
66
-		$method = $this->method['method'];
65
+        $classname = $this->method['classname'];
66
+        $method = $this->method['method'];
67 67
 
68
-		$args = array();
69
-		Events::throwEvent("apimethods", array('method' => $this->method, 'args' => &$args));
68
+        $args = array();
69
+        Events::throwEvent("apimethods", array('method' => $this->method, 'args' => &$args));
70 70
 
71
-		$result = call_user_func(array($classname, $method), $args);
71
+        $result = call_user_func(array($classname, $method), $args);
72 72
 
73
-		if (is_array($result)) {
74
-			if (!isset($result['status'])) {
75
-				$result['status'] = 200;
76
-			}
73
+        if (is_array($result)) {
74
+            if (!isset($result['status'])) {
75
+                $result['status'] = 200;
76
+            }
77 77
 
78
-			echo json_encode($result);
79
-		} else {
80
-			echo $result;
81
-		}
82
-	}
78
+            echo json_encode($result);
79
+        } else {
80
+            echo $result;
81
+        }
82
+    }
83 83
 
84
-	public static function addMethod (string $api_method, string $class_name, string $method, string $owner = "system", string $response_type = "") {
85
-		//add method to database
86
-		Database::getInstance()->execute("INSERT INTO `{praefix}api_methods` (
84
+    public static function addMethod (string $api_method, string $class_name, string $method, string $owner = "system", string $response_type = "") {
85
+        //add method to database
86
+        Database::getInstance()->execute("INSERT INTO `{praefix}api_methods` (
87 87
 			`api_method`, `classname`, `method`, `response_type`, `owner`, `activated`
88 88
 		) VALUES (
89 89
 			:api_method, :class_name, :method, :response_type, :owner, '1'
90 90
 		) ON DUPLICATE KEY UPDATE `classname` = :class_name, `method` = :method, `response_type` = :response_type, `owner` = :owner, `activated` = '1'; ", array(
91
-			'api_method' => $api_method,
92
-			'class_name' => $class_name,
93
-			'method' => $method,
94
-			'response_type' => $response_type,
95
-			'owner' => $owner
96
-		));
97
-
98
-		//clear cache
99
-		Cache::clear("apimethods");
100
-	}
101
-
102
-	public static function deleteMethod (string $api_method) {
103
-		//delete from database
104
-		Database::getInstance()->execute("DELETE FROM `{praefix}api_methods` WHERE `api_method` = :api_method; ", array(
105
-			'api_method' => $api_method
106
-		));
107
-
108
-		//clear cache
109
-		Cache::clear("apimethods");
110
-	}
111
-
112
-	public static function deleteMethodsByOwner (string $owner) {
113
-		//delete from database
114
-		Database::getInstance()->execute("DELETE FROM `{praefix}api_methods` WHERE `owner` = :owner; ", array(
115
-			'owner' => $owner
116
-		));
117
-
118
-		//clear cache
119
-		Cache::clear("apimethods");
120
-	}
91
+            'api_method' => $api_method,
92
+            'class_name' => $class_name,
93
+            'method' => $method,
94
+            'response_type' => $response_type,
95
+            'owner' => $owner
96
+        ));
97
+
98
+        //clear cache
99
+        Cache::clear("apimethods");
100
+    }
101
+
102
+    public static function deleteMethod (string $api_method) {
103
+        //delete from database
104
+        Database::getInstance()->execute("DELETE FROM `{praefix}api_methods` WHERE `api_method` = :api_method; ", array(
105
+            'api_method' => $api_method
106
+        ));
107
+
108
+        //clear cache
109
+        Cache::clear("apimethods");
110
+    }
111
+
112
+    public static function deleteMethodsByOwner (string $owner) {
113
+        //delete from database
114
+        Database::getInstance()->execute("DELETE FROM `{praefix}api_methods` WHERE `owner` = :owner; ", array(
115
+            'owner' => $owner
116
+        ));
117
+
118
+        //clear cache
119
+        Cache::clear("apimethods");
120
+    }
121 121
 
122 122
 }
123 123
 
Please login to merge, or discard this patch.
plugins/calender/classes/calenders.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 
36 36
 class Calenders {
37 37
 
38
-	public static function listMyCalenderIDs (int $userUD) : array {
38
+	public static function listMyCalenderIDs(int $userUD) : array {
39 39
 		if (Cache::contains("plugin-calender", "calenderIDs-" . $userUD)) {
40 40
 			return Cache::get("plugin-calender", "calenderIDs-" . $userUD);
41 41
 		} else {
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 		}
66 66
 	}
67 67
 
68
-	public static function listMyCalenders (int $userID) : array {
68
+	public static function listMyCalenders(int $userID) : array {
69 69
 		if (Cache::contains("plugin-calender", "my-calenders-" . $userID)) {
70 70
 			return Cache::get("plugin-calender", "my-calenders-" . $userID);
71 71
 		} else {
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 	 *
109 109
 	 * @return array with calender IDs in form calenderID=>value
110 110
 	 */
111
-	protected static function listCalenderRowsByGroups (array $groupIDs) : array {
111
+	protected static function listCalenderRowsByGroups(array $groupIDs) : array {
112 112
 		$array = array();
113 113
 
114 114
 		foreach ($groupIDs as $id) {
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 		return $res_array;
130 130
 	}
131 131
 
132
-	protected static function listCalenderRowsByUser (int $userID) : array {
132
+	protected static function listCalenderRowsByUser(int $userID) : array {
133 133
 		if (Cache::contains("plugin-calender", "calender-ids-by-user-" . $userID)) {
134 134
 			return Cache::get("plugin-calender", "calender-ids-by-user-" . $userID);
135 135
 		} else {
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 		}
157 157
 	}
158 158
 
159
-	public static function valueToInt (string $value) : int {
159
+	public static function valueToInt(string $value) : int {
160 160
 		switch ($value) {
161 161
 			case "read":
162 162
 				return 1;
Please login to merge, or discard this patch.
Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -35,139 +35,139 @@
 block discarded – undo
35 35
 
36 36
 class Calenders {
37 37
 
38
-	public static function listMyCalenderIDs (int $userUD) : array {
39
-		if (Cache::contains("plugin-calender", "calenderIDs-" . $userUD)) {
40
-			return Cache::get("plugin-calender", "calenderIDs-" . $userUD);
41
-		} else {
42
-			$groups = new Groups();
43
-			$groups->loadMyGroups(User::current()->getID());
44
-			$groupIDs = $groups->listGroupIDs();
45
-
46
-			//get calenders by groups
47
-			$calender_ids = self::listCalenderRowsByGroups($groupIDs);
48
-
49
-			//merge arrays
50
-			foreach (self::listCalenderRowsByUser(User::current()->getID()) as $calenderID=>$row) {
51
-				if (isset($calender_ids[$calender_ids])) {
52
-					//check, which is higher permission
53
-					if (self::valueToInt($calender_ids[$calenderID]['value']) < self::valueToInt($row['value'])) {
54
-						$calender_ids[$calenderID] = $row;
55
-					}
56
-				} else {
57
-					$calender_ids[$calenderID] = $row;
58
-				}
59
-			}
60
-
61
-			//put results to cache
62
-			Cache::put("plugin-calender", "calenderIDs-" . $userUD, $calender_ids);
63
-
64
-			return $calender_ids;
65
-		}
66
-	}
67
-
68
-	public static function listMyCalenders (int $userID) : array {
69
-		if (Cache::contains("plugin-calender", "my-calenders-" . $userID)) {
70
-			return Cache::get("plugin-calender", "my-calenders-" . $userID);
71
-		} else {
72
-			$array = array();
73
-
74
-			$array1 = array();
75
-			$user_rows = array();
76
-
77
-			foreach (self::listMyCalenderIDs($userID) as $calenderID=>$row) {
78
-				$array1[] = "`id` = '" . intval($calenderID) . "'";
79
-				$user_rows[$calenderID] = $row;
80
-			}
81
-
82
-			$array_str = (!empty($array1) ? " OR " : "") . implode(" OR ", $array1);
83
-
84
-			$rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}plugin_calender_calenders` WHERE `id` = '-1'" . $array_str . "; ");
85
-
86
-			foreach ($rows as $row) {
87
-				$calenderID = $row['id'];
88
-
89
-				//create new calender
90
-				$calender = new Calender($row, $user_rows[$calenderID]);
91
-
92
-				$array[] = $calender;
93
-			}
94
-
95
-			//put array to cache
96
-			Cache::put("plugin-calender", "my-calenders-" . $userID, $array);
97
-
98
-			return $array;
99
-		}
100
-	}
101
-
102
-	/**
103
-	 * list calender ids in this form calenderID=>value
104
-	 *
105
-	 * Dont use this method directly, because its not cached!
106
-	 *
107
-	 * @param $groupIDs array with ids of groups, user belongs to
108
-	 *
109
-	 * @return array with calender IDs in form calenderID=>value
110
-	 */
111
-	protected static function listCalenderRowsByGroups (array $groupIDs) : array {
112
-		$array = array();
113
-
114
-		foreach ($groupIDs as $id) {
115
-			$array[] = "`groupID` = '" . intval($id) . "'";
116
-		}
117
-
118
-		$array_str = (!empty($array) ? " OR " : "") . implode(" OR ", $array);
119
-
120
-		$rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}plugin_calender_group_rights` WHERE `groupID` = '-1'" . $array_str . "; ");
121
-
122
-		$res_array = array();
123
-
124
-		foreach ($rows as $row) {
125
-			$calenderID = $row['calenderID'];
126
-			$res_array[$calenderID] = $row;
127
-		}
128
-
129
-		return $res_array;
130
-	}
131
-
132
-	protected static function listCalenderRowsByUser (int $userID) : array {
133
-		if (Cache::contains("plugin-calender", "calender-ids-by-user-" . $userID)) {
134
-			return Cache::get("plugin-calender", "calender-ids-by-user-" . $userID);
135
-		} else {
136
-			$array = array();
137
-
138
-			//get calenders from database
139
-			$rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}plugin_calender_user_rights` WHERE `userID` = :userID; ", array(
140
-				'userID' => array(
141
-					'type' => PDO::PARAM_INT,
142
-					'value' => $userID
143
-				)
144
-			));
145
-
146
-			foreach ($rows as $row) {
147
-				$calenderID = $row['calenderID'];
148
-
149
-				$array[$calenderID] = $row;
150
-			}
151
-
152
-			//cache results
153
-			Cache::put("plugin-calender", "calender-ids-by-user-" . $userID, $array);
154
-
155
-			return $array;
156
-		}
157
-	}
158
-
159
-	public static function valueToInt (string $value) : int {
160
-		switch ($value) {
161
-			case "read":
162
-				return 1;
163
-			case "write":
164
-				return 2;
165
-			case "owner":
166
-				return 3;
167
-			default:
168
-				throw new \IllegalArgumentException("Unknown calender value '" . $value . "'!");
169
-		}
170
-	}
38
+    public static function listMyCalenderIDs (int $userUD) : array {
39
+        if (Cache::contains("plugin-calender", "calenderIDs-" . $userUD)) {
40
+            return Cache::get("plugin-calender", "calenderIDs-" . $userUD);
41
+        } else {
42
+            $groups = new Groups();
43
+            $groups->loadMyGroups(User::current()->getID());
44
+            $groupIDs = $groups->listGroupIDs();
45
+
46
+            //get calenders by groups
47
+            $calender_ids = self::listCalenderRowsByGroups($groupIDs);
48
+
49
+            //merge arrays
50
+            foreach (self::listCalenderRowsByUser(User::current()->getID()) as $calenderID=>$row) {
51
+                if (isset($calender_ids[$calender_ids])) {
52
+                    //check, which is higher permission
53
+                    if (self::valueToInt($calender_ids[$calenderID]['value']) < self::valueToInt($row['value'])) {
54
+                        $calender_ids[$calenderID] = $row;
55
+                    }
56
+                } else {
57
+                    $calender_ids[$calenderID] = $row;
58
+                }
59
+            }
60
+
61
+            //put results to cache
62
+            Cache::put("plugin-calender", "calenderIDs-" . $userUD, $calender_ids);
63
+
64
+            return $calender_ids;
65
+        }
66
+    }
67
+
68
+    public static function listMyCalenders (int $userID) : array {
69
+        if (Cache::contains("plugin-calender", "my-calenders-" . $userID)) {
70
+            return Cache::get("plugin-calender", "my-calenders-" . $userID);
71
+        } else {
72
+            $array = array();
73
+
74
+            $array1 = array();
75
+            $user_rows = array();
76
+
77
+            foreach (self::listMyCalenderIDs($userID) as $calenderID=>$row) {
78
+                $array1[] = "`id` = '" . intval($calenderID) . "'";
79
+                $user_rows[$calenderID] = $row;
80
+            }
81
+
82
+            $array_str = (!empty($array1) ? " OR " : "") . implode(" OR ", $array1);
83
+
84
+            $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}plugin_calender_calenders` WHERE `id` = '-1'" . $array_str . "; ");
85
+
86
+            foreach ($rows as $row) {
87
+                $calenderID = $row['id'];
88
+
89
+                //create new calender
90
+                $calender = new Calender($row, $user_rows[$calenderID]);
91
+
92
+                $array[] = $calender;
93
+            }
94
+
95
+            //put array to cache
96
+            Cache::put("plugin-calender", "my-calenders-" . $userID, $array);
97
+
98
+            return $array;
99
+        }
100
+    }
101
+
102
+    /**
103
+     * list calender ids in this form calenderID=>value
104
+     *
105
+     * Dont use this method directly, because its not cached!
106
+     *
107
+     * @param $groupIDs array with ids of groups, user belongs to
108
+     *
109
+     * @return array with calender IDs in form calenderID=>value
110
+     */
111
+    protected static function listCalenderRowsByGroups (array $groupIDs) : array {
112
+        $array = array();
113
+
114
+        foreach ($groupIDs as $id) {
115
+            $array[] = "`groupID` = '" . intval($id) . "'";
116
+        }
117
+
118
+        $array_str = (!empty($array) ? " OR " : "") . implode(" OR ", $array);
119
+
120
+        $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}plugin_calender_group_rights` WHERE `groupID` = '-1'" . $array_str . "; ");
121
+
122
+        $res_array = array();
123
+
124
+        foreach ($rows as $row) {
125
+            $calenderID = $row['calenderID'];
126
+            $res_array[$calenderID] = $row;
127
+        }
128
+
129
+        return $res_array;
130
+    }
131
+
132
+    protected static function listCalenderRowsByUser (int $userID) : array {
133
+        if (Cache::contains("plugin-calender", "calender-ids-by-user-" . $userID)) {
134
+            return Cache::get("plugin-calender", "calender-ids-by-user-" . $userID);
135
+        } else {
136
+            $array = array();
137
+
138
+            //get calenders from database
139
+            $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}plugin_calender_user_rights` WHERE `userID` = :userID; ", array(
140
+                'userID' => array(
141
+                    'type' => PDO::PARAM_INT,
142
+                    'value' => $userID
143
+                )
144
+            ));
145
+
146
+            foreach ($rows as $row) {
147
+                $calenderID = $row['calenderID'];
148
+
149
+                $array[$calenderID] = $row;
150
+            }
151
+
152
+            //cache results
153
+            Cache::put("plugin-calender", "calender-ids-by-user-" . $userID, $array);
154
+
155
+            return $array;
156
+        }
157
+    }
158
+
159
+    public static function valueToInt (string $value) : int {
160
+        switch ($value) {
161
+            case "read":
162
+                return 1;
163
+            case "write":
164
+                return 2;
165
+            case "owner":
166
+                return 3;
167
+            default:
168
+                throw new \IllegalArgumentException("Unknown calender value '" . $value . "'!");
169
+        }
170
+    }
171 171
 
172 172
 }
173 173
 
Please login to merge, or discard this patch.