Completed
Push — master ( 2c1eb1...6e4c54 )
by Justin
03:16
created
plugins/calender/classes/calenders.php 1 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.
plugins/calender/classes/calender.php 1 patch
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -34,95 +34,95 @@
 block discarded – undo
34 34
 
35 35
 class Calender {
36 36
 
37
-	protected $calenderID = -1;
38
-	protected $row = null;
39
-	protected $user_row = null;
40
-
41
-	public function __construct (array $row = null, array $user_row = null) {
42
-		if (!is_null($row) && !empty($row)) {
43
-			$this->calenderID = $row['id'];
44
-			$this->row = $row;
45
-		}
46
-
47
-		if (!is_null($user_row) && !empty($user_row)) {
48
-			$this->user_row = $user_row;
49
-		}
50
-	}
51
-
52
-	public function load (int $calenderID) {
53
-		if ($calenderID <= 0) {
54
-			throw new \IllegalArgumentException("calenderID has to be greater than 0.");
55
-		}
56
-
57
-		if (Cache::contains("plugin-calender", "calender-" . $calenderID)) {
58
-			$this->row = Cache::get("plugin-calender", "calender-" . $calenderID);
59
-		} else {
60
-			//get calender from database
61
-			$row = Database::getInstance()->getRow("SELECT * FROM `{praefix}plugin_calender_calenders` WHERE `id` = :calenderID; ", array(
62
-				'calenderID' => array(
63
-					'type' => PDO::PARAM_INT,
64
-					'value' => $calenderID
65
-				)
66
-			));
67
-
68
-			if (!$row) {
69
-				throw new IllegalStateException("calender with id '" . $calenderID . "' doesnt exists.");
70
-			}
71
-
72
-			$this->row = $row;
73
-
74
-			//put row to cache
75
-			Cache::put("plugin-calender", "calender-" . $calenderID, $row);
76
-		}
77
-
78
-		$this->calenderID = $this->row['id'];
79
-	}
80
-
81
-	public function getID () : int {
82
-		return $this->calenderID;
83
-	}
84
-
85
-	public function getTitle () : string {
86
-		return $this->row['title'];
87
-	}
88
-
89
-	public function getDescription () : string {
90
-		return $this->row['description'];
91
-	}
92
-
93
-	public function getType () : string {
94
-		return $this->row['type'];
95
-	}
96
-
97
-	public function getPermission () : string {
98
-		if ($this->user_row == null || empty($this->user_row)) {
99
-			throw new IllegalStateException("user row wasnt set in constructor.");
100
-		}
101
-
102
-		return $this->user_row['value'];
103
-	}
104
-
105
-	public function listAllEvents (bool $only_current_events = false) : array {
106
-		//read from database, dont cache
107
-		$rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}plugin_calender_events` WHERE `calenderID` = :calenderID" . ($only_current_events ? " AND DATE(`to_date`) >= DATE(NOW())" : "") . " ORDER BY `from_date`; ", array(
108
-			'calenderID' => array(
109
-				'type' => PDO::PARAM_INT,
110
-				'value' => $this->getID()
111
-			)
112
-		));
113
-
114
-		$events = array();
115
-
116
-		foreach ($rows as $row) {
117
-			$events[] = new Event($row);
118
-		}
119
-
120
-		return $events;
121
-	}
122
-
123
-	public static function castCalender (Calender $calender) : Calender {
124
-		return $calender;
125
-	}
37
+    protected $calenderID = -1;
38
+    protected $row = null;
39
+    protected $user_row = null;
40
+
41
+    public function __construct (array $row = null, array $user_row = null) {
42
+        if (!is_null($row) && !empty($row)) {
43
+            $this->calenderID = $row['id'];
44
+            $this->row = $row;
45
+        }
46
+
47
+        if (!is_null($user_row) && !empty($user_row)) {
48
+            $this->user_row = $user_row;
49
+        }
50
+    }
51
+
52
+    public function load (int $calenderID) {
53
+        if ($calenderID <= 0) {
54
+            throw new \IllegalArgumentException("calenderID has to be greater than 0.");
55
+        }
56
+
57
+        if (Cache::contains("plugin-calender", "calender-" . $calenderID)) {
58
+            $this->row = Cache::get("plugin-calender", "calender-" . $calenderID);
59
+        } else {
60
+            //get calender from database
61
+            $row = Database::getInstance()->getRow("SELECT * FROM `{praefix}plugin_calender_calenders` WHERE `id` = :calenderID; ", array(
62
+                'calenderID' => array(
63
+                    'type' => PDO::PARAM_INT,
64
+                    'value' => $calenderID
65
+                )
66
+            ));
67
+
68
+            if (!$row) {
69
+                throw new IllegalStateException("calender with id '" . $calenderID . "' doesnt exists.");
70
+            }
71
+
72
+            $this->row = $row;
73
+
74
+            //put row to cache
75
+            Cache::put("plugin-calender", "calender-" . $calenderID, $row);
76
+        }
77
+
78
+        $this->calenderID = $this->row['id'];
79
+    }
80
+
81
+    public function getID () : int {
82
+        return $this->calenderID;
83
+    }
84
+
85
+    public function getTitle () : string {
86
+        return $this->row['title'];
87
+    }
88
+
89
+    public function getDescription () : string {
90
+        return $this->row['description'];
91
+    }
92
+
93
+    public function getType () : string {
94
+        return $this->row['type'];
95
+    }
96
+
97
+    public function getPermission () : string {
98
+        if ($this->user_row == null || empty($this->user_row)) {
99
+            throw new IllegalStateException("user row wasnt set in constructor.");
100
+        }
101
+
102
+        return $this->user_row['value'];
103
+    }
104
+
105
+    public function listAllEvents (bool $only_current_events = false) : array {
106
+        //read from database, dont cache
107
+        $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}plugin_calender_events` WHERE `calenderID` = :calenderID" . ($only_current_events ? " AND DATE(`to_date`) >= DATE(NOW())" : "") . " ORDER BY `from_date`; ", array(
108
+            'calenderID' => array(
109
+                'type' => PDO::PARAM_INT,
110
+                'value' => $this->getID()
111
+            )
112
+        ));
113
+
114
+        $events = array();
115
+
116
+        foreach ($rows as $row) {
117
+            $events[] = new Event($row);
118
+        }
119
+
120
+        return $events;
121
+    }
122
+
123
+    public static function castCalender (Calender $calender) : Calender {
124
+        return $calender;
125
+    }
126 126
 
127 127
 }
128 128
 
Please login to merge, or discard this patch.
plugins/workshops/install/install.php 1 patch
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.
plugins/workshops/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.
plugins/workshops/classes/workshopsapi.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -31,33 +31,33 @@
 block discarded – undo
31 31
 
32 32
 class WorkshopsApi {
33 33
 
34
-	public static function listAllWorkshops () : array {
35
-		$res = array();
34
+    public static function listAllWorkshops () : array {
35
+        $res = array();
36 36
 
37
-		//read workshops directly from database
38
-		$rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}plugin_workshops_workshops` ORDER BY `order`; ");
37
+        //read workshops directly from database
38
+        $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}plugin_workshops_workshops` ORDER BY `order`; ");
39 39
 
40
-		$array = array();
40
+        $array = array();
41 41
 
42
-		foreach ($rows as $row) {
43
-			$array[] = array(
44
-				'id' => $row['id'],
45
-				'title' => utf8_encode($row['title']),
46
-				'description' => utf8_encode($row['description']),
47
-				'image' => utf8_encode($row['image']),
48
-				'day' => utf8_encode($row['day']),
49
-				'time' => utf8_encode($row['time']),
50
-				'interval' => utf8_encode($row['interval']),
51
-				'location' => utf8_encode($row['location']),
52
-				'responsible' => utf8_encode($row['responsible']),
53
-				'order' => $row['order']
54
-			);
55
-		}
42
+        foreach ($rows as $row) {
43
+            $array[] = array(
44
+                'id' => $row['id'],
45
+                'title' => utf8_encode($row['title']),
46
+                'description' => utf8_encode($row['description']),
47
+                'image' => utf8_encode($row['image']),
48
+                'day' => utf8_encode($row['day']),
49
+                'time' => utf8_encode($row['time']),
50
+                'interval' => utf8_encode($row['interval']),
51
+                'location' => utf8_encode($row['location']),
52
+                'responsible' => utf8_encode($row['responsible']),
53
+                'order' => $row['order']
54
+            );
55
+        }
56 56
 
57
-		$res['workshops'] = $array;
57
+        $res['workshops'] = $array;
58 58
 
59
-		return $res;
60
-	}
59
+        return $res;
60
+    }
61 61
 
62 62
 }
63 63
 
Please login to merge, or discard this patch.
plugins/facebookapi/facebook-sdk/Facebook/Facebook.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -602,8 +602,8 @@
 block discarded – undo
602 602
         } while (!$chunk->isLastChunk());
603 603
 
604 604
         return [
605
-          'video_id' => $chunk->getVideoId(),
606
-          'success' => $uploader->finish($endpoint, $chunk->getUploadSessionId(), $metadata),
605
+            'video_id' => $chunk->getVideoId(),
606
+            'success' => $uploader->finish($endpoint, $chunk->getUploadSessionId(), $metadata),
607 607
         ];
608 608
     }
609 609
 
Please login to merge, or discard this patch.
plugins/facebookapi/facebook-sdk/Facebook/FacebookApp.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@
 block discarded – undo
47 47
     public function __construct($id, $secret)
48 48
     {
49 49
         if (!is_string($id)
50
-          // Keeping this for BC. Integers greater than PHP_INT_MAX will make is_int() return false
50
+            // Keeping this for BC. Integers greater than PHP_INT_MAX will make is_int() return false
51 51
           && !is_int($id)) {
52 52
             throw new FacebookSDKException('The "app_id" must be formatted as a string since many app ID\'s are greater than PHP_INT_MAX on some systems.');
53 53
         }
Please login to merge, or discard this patch.
system/packages/com.jukusoft.cms.plugin/classes/plugin.php 1 patch
Indentation   +236 added lines, -236 removed lines patch added patch discarded remove patch
@@ -27,242 +27,242 @@
 block discarded – undo
27 27
 
28 28
 class Plugin {
29 29
 
30
-	//directory name of plugin
31
-	protected $name = "";
32
-
33
-	//database row
34
-	protected $row = array();
35
-
36
-	protected $json_data = null;
37
-
38
-	protected static $allowed_types = array("library", "api", "metaplugin", "project", "importer", "addon");
39
-
40
-	/**
41
-	 * default constructor
42
-	 *
43
-	 * @param string $name directory name of plugin
44
-	 * @param array $row optional database row from plugin
45
-	 */
46
-	public function __construct(string $name, array $row = array()) {
47
-		$this->name = $name;
48
-		$this->row = $row;
49
-	}
50
-
51
-	/**
52
-	 * load plugin.json file
53
-	 */
54
-	public function load () {
55
-		$file_path = PLUGIN_PATH . $this->name . "/plugin.json";
56
-
57
-		//check, if file exists
58
-		if (!file_exists($file_path)) {
59
-			throw new IllegalStateException("plugin.json for plugin '" . $this->name . "' does not exists (expected path: '" . $file_path . "')!");
60
-		}
61
-
62
-		$this->json_data = json_decode(file_get_contents($file_path), true);
63
-	}
64
-
65
-	public function loadRow () {
66
-		if (Cache::contains("plugins", "plugin_row_" . $this->name)) {
67
-			$this->row = Cache::get("plugins", "plugin_row_" . $this->name);
68
-		} else {
69
-			$row = Database::getInstance()->getRow("SELECT * FROM `{praefix}plugins` WHERE `name` = :name; ", array('name' => $this->name));
70
-
71
-			Cache::put("plugins", "plugin_row_" . $this->name, $row);
72
-
73
-			$this->row = $row;
74
-		}
75
-	}
76
-
77
-	/**
78
-	 * get directory name of plugin
79
-	 *
80
-	 * @return string directory name of plugin
81
-	 */
82
-	public function getName () : string {
83
-		return $this->name;
84
-	}
85
-
86
-	public function getPath () : string {
87
-		return PLUGIN_PATH . $this->name . "/";
88
-	}
89
-
90
-	public function exists () : bool {
91
-		$file_path = PLUGIN_PATH . $this->name . "/plugin.json";
92
-
93
-		return file_exists($file_path);
94
-	}
95
-
96
-	public function getType () : string {
97
-		$type = $this->json_data['type'];
98
-
99
-		if (!in_array($type, self::$allowed_types)) {
100
-			throw new IllegalStateException("plugin type '" . $type . "' (plugin '" . $this->name . "') is not supported!");
101
-		}
102
-
103
-		return $type;
104
-	}
105
-
106
-	public function getTitle () : string {
107
-		return htmlentities($this->json_data['title']);
108
-	}
109
-
110
-	public function getDescription (string $lang_token = "") : string {
111
-		$desc = $this->json_data['description'];
112
-
113
-		if (is_array($desc)) {
114
-			//several languages are supported
115
-			if (empty($lang_token) || !isset($desc[$lang_token])) {
116
-				//return english description
117
-				return htmlentities($desc['en']);
118
-			} else {
119
-				return htmlentities($desc[$lang_token]);
120
-			}
121
-		} else {
122
-			//use default language
123
-			return htmlentities($desc);
124
-		}
125
-	}
126
-
127
-	public function getVersion () : string {
128
-		if ($this->json_data['version'] == null || empty($this->json_data['version'])) {
129
-			throw new IllegalStateException("plugin.json of plugin '" . $this->name . "' doesnt contains 'version' key.");
130
-		}
131
-
132
-		return $this->json_data['version'];
133
-	}
134
-
135
-	public function getInstalledVersion () : string {
136
-		if (empty($this->row)) {
137
-			throw new IllegalStateException("plugin instance wasnt loaded with row.");
138
-		}
139
-
140
-		return (!empty($this->row) ? $this->row['version'] : "n/a");
141
-	}
142
-
143
-	public function getHomepage () : string {
144
-		return (isset($this->json_data['homepage']) ? $this->json_data['homepage'] : "");
145
-	}
146
-
147
-	public function getLicense () : string {
148
-		return $this->json_data['license'];
149
-	}
150
-
151
-	public function listAuthors () : array {
152
-		return $this->json_data['authors'];
153
-	}
154
-
155
-	public function listSupportArray () : array {
156
-		return $this->json_data['support'];
157
-	}
158
-
159
-	public function hasSourceLink () : bool {
160
-		return isset($this->json_data['support']) && isset($this->json_data['support']['source']);
161
-	}
162
-
163
-	public function getSourceLink () : string {
164
-		if ($this->hasSourceLink()) {
165
-			return $this->json_data['support']['source'];
166
-		} else {
167
-			return "";
168
-		}
169
-	}
170
-
171
-	public function hasIssuesLink () : bool {
172
-		return isset($this->json_data['support']) && isset($this->json_data['support']['issues']);
173
-	}
174
-
175
-	public function getIssuesLink () : string {
176
-		if ($this->hasIssuesLink()) {
177
-			return $this->json_data['support']['issues'];
178
-		} else {
179
-			return "";
180
-		}
181
-	}
182
-
183
-	public function hasSupportMail () : bool {
184
-		return isset($this->json_data['support']) && isset($this->json_data['support']['email']);
185
-	}
186
-
187
-	public function getSupportMail () : string {
188
-		if ($this->hasSupportMail()) {
189
-			return $this->json_data['support']['email'];
190
-		} else {
191
-			return "";
192
-		}
193
-	}
194
-
195
-	public function listSupportLinks () : array {
196
-		$array = array();
197
-
198
-		if ($this->hasIssuesLink()) {
199
-			$array[] = array(
200
-				'title' => Translator::translate("Issues"),
201
-				'href' => $this->getIssuesLink()
202
-			);
203
-		}
204
-
205
-		if ($this->hasSourceLink()) {
206
-			$array[] = array(
207
-				'title' => Translator::translate("Source"),
208
-				'href' => $this->getSourceLink()
209
-			);
210
-		}
211
-
212
-		if ($this->hasSupportMail()) {
213
-			$array[] = array(
214
-				'title' => Translator::translate("Mail"),
215
-				'href' => "mailto:" . $this->getSupportMail(),
216
-			);
217
-		}
218
-
219
-		return $array;
220
-	}
221
-
222
-	public function listKeywords () : array {
223
-		return $this->json_data['keywords'];
224
-	}
225
-
226
-	public function listCategories () : array {
227
-		return $this->json_data['categories'];
228
-	}
229
-
230
-	public function hasInstallJson () : bool {
231
-		return isset($this->json_data['installation']) && $this->json_data['installation'] == true;
232
-	}
233
-
234
-	public function getInstallJsonFile () : string {
235
-		return "install.json";
236
-	}
237
-
238
-	public function getRequiredPlugins () : array {
239
-		return $this->json_data['require'];
240
-	}
241
-
242
-	public function isAlpha () : bool {
243
-		return PHPUtils::endsWith($this->getVersion(), "-alpha");
244
-	}
245
-
246
-	public function isBeta () : bool {
247
-		return PHPUtils::endsWith($this->getVersion(), "-beta");
248
-	}
249
-
250
-	public function isInstalled () : bool {
251
-		return (!empty($this->row) ? $this->row['installed'] == 1 : false);
252
-	}
253
-
254
-	public function isUpgradeAvailable () : bool {
255
-		//check, if local and installed version are different
256
-		return $this->getVersion() !== $this->getInstalledVersion();
257
-	}
258
-
259
-	public function isActivated () : bool {
260
-		return (!empty($this->row) ? $this->row['activated'] == 1 : false);
261
-	}
262
-
263
-	public static function castPlugin (Plugin $plugin) : Plugin {
264
-		return $plugin;
265
-	}
30
+    //directory name of plugin
31
+    protected $name = "";
32
+
33
+    //database row
34
+    protected $row = array();
35
+
36
+    protected $json_data = null;
37
+
38
+    protected static $allowed_types = array("library", "api", "metaplugin", "project", "importer", "addon");
39
+
40
+    /**
41
+     * default constructor
42
+     *
43
+     * @param string $name directory name of plugin
44
+     * @param array $row optional database row from plugin
45
+     */
46
+    public function __construct(string $name, array $row = array()) {
47
+        $this->name = $name;
48
+        $this->row = $row;
49
+    }
50
+
51
+    /**
52
+     * load plugin.json file
53
+     */
54
+    public function load () {
55
+        $file_path = PLUGIN_PATH . $this->name . "/plugin.json";
56
+
57
+        //check, if file exists
58
+        if (!file_exists($file_path)) {
59
+            throw new IllegalStateException("plugin.json for plugin '" . $this->name . "' does not exists (expected path: '" . $file_path . "')!");
60
+        }
61
+
62
+        $this->json_data = json_decode(file_get_contents($file_path), true);
63
+    }
64
+
65
+    public function loadRow () {
66
+        if (Cache::contains("plugins", "plugin_row_" . $this->name)) {
67
+            $this->row = Cache::get("plugins", "plugin_row_" . $this->name);
68
+        } else {
69
+            $row = Database::getInstance()->getRow("SELECT * FROM `{praefix}plugins` WHERE `name` = :name; ", array('name' => $this->name));
70
+
71
+            Cache::put("plugins", "plugin_row_" . $this->name, $row);
72
+
73
+            $this->row = $row;
74
+        }
75
+    }
76
+
77
+    /**
78
+     * get directory name of plugin
79
+     *
80
+     * @return string directory name of plugin
81
+     */
82
+    public function getName () : string {
83
+        return $this->name;
84
+    }
85
+
86
+    public function getPath () : string {
87
+        return PLUGIN_PATH . $this->name . "/";
88
+    }
89
+
90
+    public function exists () : bool {
91
+        $file_path = PLUGIN_PATH . $this->name . "/plugin.json";
92
+
93
+        return file_exists($file_path);
94
+    }
95
+
96
+    public function getType () : string {
97
+        $type = $this->json_data['type'];
98
+
99
+        if (!in_array($type, self::$allowed_types)) {
100
+            throw new IllegalStateException("plugin type '" . $type . "' (plugin '" . $this->name . "') is not supported!");
101
+        }
102
+
103
+        return $type;
104
+    }
105
+
106
+    public function getTitle () : string {
107
+        return htmlentities($this->json_data['title']);
108
+    }
109
+
110
+    public function getDescription (string $lang_token = "") : string {
111
+        $desc = $this->json_data['description'];
112
+
113
+        if (is_array($desc)) {
114
+            //several languages are supported
115
+            if (empty($lang_token) || !isset($desc[$lang_token])) {
116
+                //return english description
117
+                return htmlentities($desc['en']);
118
+            } else {
119
+                return htmlentities($desc[$lang_token]);
120
+            }
121
+        } else {
122
+            //use default language
123
+            return htmlentities($desc);
124
+        }
125
+    }
126
+
127
+    public function getVersion () : string {
128
+        if ($this->json_data['version'] == null || empty($this->json_data['version'])) {
129
+            throw new IllegalStateException("plugin.json of plugin '" . $this->name . "' doesnt contains 'version' key.");
130
+        }
131
+
132
+        return $this->json_data['version'];
133
+    }
134
+
135
+    public function getInstalledVersion () : string {
136
+        if (empty($this->row)) {
137
+            throw new IllegalStateException("plugin instance wasnt loaded with row.");
138
+        }
139
+
140
+        return (!empty($this->row) ? $this->row['version'] : "n/a");
141
+    }
142
+
143
+    public function getHomepage () : string {
144
+        return (isset($this->json_data['homepage']) ? $this->json_data['homepage'] : "");
145
+    }
146
+
147
+    public function getLicense () : string {
148
+        return $this->json_data['license'];
149
+    }
150
+
151
+    public function listAuthors () : array {
152
+        return $this->json_data['authors'];
153
+    }
154
+
155
+    public function listSupportArray () : array {
156
+        return $this->json_data['support'];
157
+    }
158
+
159
+    public function hasSourceLink () : bool {
160
+        return isset($this->json_data['support']) && isset($this->json_data['support']['source']);
161
+    }
162
+
163
+    public function getSourceLink () : string {
164
+        if ($this->hasSourceLink()) {
165
+            return $this->json_data['support']['source'];
166
+        } else {
167
+            return "";
168
+        }
169
+    }
170
+
171
+    public function hasIssuesLink () : bool {
172
+        return isset($this->json_data['support']) && isset($this->json_data['support']['issues']);
173
+    }
174
+
175
+    public function getIssuesLink () : string {
176
+        if ($this->hasIssuesLink()) {
177
+            return $this->json_data['support']['issues'];
178
+        } else {
179
+            return "";
180
+        }
181
+    }
182
+
183
+    public function hasSupportMail () : bool {
184
+        return isset($this->json_data['support']) && isset($this->json_data['support']['email']);
185
+    }
186
+
187
+    public function getSupportMail () : string {
188
+        if ($this->hasSupportMail()) {
189
+            return $this->json_data['support']['email'];
190
+        } else {
191
+            return "";
192
+        }
193
+    }
194
+
195
+    public function listSupportLinks () : array {
196
+        $array = array();
197
+
198
+        if ($this->hasIssuesLink()) {
199
+            $array[] = array(
200
+                'title' => Translator::translate("Issues"),
201
+                'href' => $this->getIssuesLink()
202
+            );
203
+        }
204
+
205
+        if ($this->hasSourceLink()) {
206
+            $array[] = array(
207
+                'title' => Translator::translate("Source"),
208
+                'href' => $this->getSourceLink()
209
+            );
210
+        }
211
+
212
+        if ($this->hasSupportMail()) {
213
+            $array[] = array(
214
+                'title' => Translator::translate("Mail"),
215
+                'href' => "mailto:" . $this->getSupportMail(),
216
+            );
217
+        }
218
+
219
+        return $array;
220
+    }
221
+
222
+    public function listKeywords () : array {
223
+        return $this->json_data['keywords'];
224
+    }
225
+
226
+    public function listCategories () : array {
227
+        return $this->json_data['categories'];
228
+    }
229
+
230
+    public function hasInstallJson () : bool {
231
+        return isset($this->json_data['installation']) && $this->json_data['installation'] == true;
232
+    }
233
+
234
+    public function getInstallJsonFile () : string {
235
+        return "install.json";
236
+    }
237
+
238
+    public function getRequiredPlugins () : array {
239
+        return $this->json_data['require'];
240
+    }
241
+
242
+    public function isAlpha () : bool {
243
+        return PHPUtils::endsWith($this->getVersion(), "-alpha");
244
+    }
245
+
246
+    public function isBeta () : bool {
247
+        return PHPUtils::endsWith($this->getVersion(), "-beta");
248
+    }
249
+
250
+    public function isInstalled () : bool {
251
+        return (!empty($this->row) ? $this->row['installed'] == 1 : false);
252
+    }
253
+
254
+    public function isUpgradeAvailable () : bool {
255
+        //check, if local and installed version are different
256
+        return $this->getVersion() !== $this->getInstalledVersion();
257
+    }
258
+
259
+    public function isActivated () : bool {
260
+        return (!empty($this->row) ? $this->row['activated'] == 1 : false);
261
+    }
262
+
263
+    public static function castPlugin (Plugin $plugin) : Plugin {
264
+        return $plugin;
265
+    }
266 266
 
267 267
 }
268 268
 
Please login to merge, or discard this patch.
system/packages/com.jukusoft.cms.plugin/extensions/menuinstaller.php 1 patch
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -27,54 +27,54 @@
 block discarded – undo
27 27
 
28 28
 class MenuInstaller extends PluginInstaller_Plugin {
29 29
 
30
-	public function install(Plugin $plugin, array $install_json): bool {
31
-		if (isset($install_json['menus'])) {
32
-			foreach ($install_json['menus'] as $menu) {
33
-				$menuID = $menu['menuID'];
34
-
35
-				if (PHPUtils::containsStr($menuID, "settings:")) {
36
-					$array = explode(":", $menuID);
37
-
38
-					//load value from settings
39
-					$menuID = intval(Settings::get($array[1], 1));
40
-				}
41
-
42
-				if (isset($menu['parent']) && PHPUtils::containsStr($menu['parent'], "settings:")) {
43
-					$array = explode(":", $menu['parent']);
44
-
45
-					$menu['parent'] = intval(Settings::get($array[1]));
46
-				}
47
-
48
-				$title = $menu['title'];
49
-				$url = $menu['url'];
50
-				$parent = (isset($menu['parent']) ? intval($menu['parent']) : -1);
51
-				$unique_name = (isset($menu['unique_name']) ? $menu['unique_name'] : "");
52
-				$type = (isset($menu['type']) ? $menu['type'] : "page");
53
-				$permissions = (isset($menu['permissions']) ? $menu['permissions'] : array("none"));
54
-				$login_required = (isset($menu['login_required']) ? boolval($menu['login_required']) : false);
55
-				$icon = (isset($menu['icon']) ? $menu['icon'] : "fa fa-circle");
56
-				$order = (isset($menu['order']) ? intval($menu['order']) : 10);
57
-
58
-				//create menu
59
-				Menu::createMenu(-1, $menuID, $title, $url, $parent, $unique_name, $type, $permissions, $login_required, $icon, $order, "plugin_" . $plugin->getName());
60
-			}
61
-		}
62
-
63
-		return true;
64
-	}
65
-
66
-	public function uninstall(Plugin $plugin, array $install_json): bool {
67
-		Menu::deleteMenusByOwner("plugin_" . $plugin->getName());
68
-
69
-		return true;
70
-	}
71
-
72
-	public function upgrade(Plugin $plugin, array $install_json): bool {
73
-		//remove old menus
74
-		$this->uninstall($plugin, $install_json);
75
-
76
-		return $this->install($plugin, $install_json);
77
-	}
30
+    public function install(Plugin $plugin, array $install_json): bool {
31
+        if (isset($install_json['menus'])) {
32
+            foreach ($install_json['menus'] as $menu) {
33
+                $menuID = $menu['menuID'];
34
+
35
+                if (PHPUtils::containsStr($menuID, "settings:")) {
36
+                    $array = explode(":", $menuID);
37
+
38
+                    //load value from settings
39
+                    $menuID = intval(Settings::get($array[1], 1));
40
+                }
41
+
42
+                if (isset($menu['parent']) && PHPUtils::containsStr($menu['parent'], "settings:")) {
43
+                    $array = explode(":", $menu['parent']);
44
+
45
+                    $menu['parent'] = intval(Settings::get($array[1]));
46
+                }
47
+
48
+                $title = $menu['title'];
49
+                $url = $menu['url'];
50
+                $parent = (isset($menu['parent']) ? intval($menu['parent']) : -1);
51
+                $unique_name = (isset($menu['unique_name']) ? $menu['unique_name'] : "");
52
+                $type = (isset($menu['type']) ? $menu['type'] : "page");
53
+                $permissions = (isset($menu['permissions']) ? $menu['permissions'] : array("none"));
54
+                $login_required = (isset($menu['login_required']) ? boolval($menu['login_required']) : false);
55
+                $icon = (isset($menu['icon']) ? $menu['icon'] : "fa fa-circle");
56
+                $order = (isset($menu['order']) ? intval($menu['order']) : 10);
57
+
58
+                //create menu
59
+                Menu::createMenu(-1, $menuID, $title, $url, $parent, $unique_name, $type, $permissions, $login_required, $icon, $order, "plugin_" . $plugin->getName());
60
+            }
61
+        }
62
+
63
+        return true;
64
+    }
65
+
66
+    public function uninstall(Plugin $plugin, array $install_json): bool {
67
+        Menu::deleteMenusByOwner("plugin_" . $plugin->getName());
68
+
69
+        return true;
70
+    }
71
+
72
+    public function upgrade(Plugin $plugin, array $install_json): bool {
73
+        //remove old menus
74
+        $this->uninstall($plugin, $install_json);
75
+
76
+        return $this->install($plugin, $install_json);
77
+    }
78 78
 
79 79
 }
80 80
 
Please login to merge, or discard this patch.