Completed
Push — master ( a11acf...bff0db )
by Justin
06:24
created
system/packages/com.jukusoft.cms.groups/classes/groups.php 2 patches
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -27,128 +27,128 @@
 block discarded – undo
27 27
 
28 28
 class Groups {
29 29
 
30
-	protected $my_groups = array();
30
+    protected $my_groups = array();
31 31
 
32
-	public function __construct() {
33
-		//
34
-	}
32
+    public function __construct() {
33
+        //
34
+    }
35 35
 
36
-	public function loadMyGroups (int $userID) {
37
-		if (Cache::contains("groups", "own-groups-" . $userID)) {
38
-			$this->my_groups = Cache::get("groups", "own-groups-" . $userID);
39
-		} else {
40
-			$rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}group_members` LEFT JOIN `{praefix}groups` ON `{praefix}group_members`.`groupID` = `{praefix}groups`.`groupID` WHERE `{praefix}group_members`.`userID` = :userID AND `{praefix}group_members`.`activated` = '1'; ", array(
41
-				'userID' => array(
42
-					'type' => PDO::PARAM_INT,
43
-					'value' => $userID
44
-				)
45
-			));
36
+    public function loadMyGroups (int $userID) {
37
+        if (Cache::contains("groups", "own-groups-" . $userID)) {
38
+            $this->my_groups = Cache::get("groups", "own-groups-" . $userID);
39
+        } else {
40
+            $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}group_members` LEFT JOIN `{praefix}groups` ON `{praefix}group_members`.`groupID` = `{praefix}groups`.`groupID` WHERE `{praefix}group_members`.`userID` = :userID AND `{praefix}group_members`.`activated` = '1'; ", array(
41
+                'userID' => array(
42
+                    'type' => PDO::PARAM_INT,
43
+                    'value' => $userID
44
+                )
45
+            ));
46 46
 
47
-			$this->my_groups = $rows;
47
+            $this->my_groups = $rows;
48 48
 
49
-			//cache rows
50
-			Cache::put("groups", "own-groups-" . $userID, $this->my_groups);
51
-		}
52
-	}
49
+            //cache rows
50
+            Cache::put("groups", "own-groups-" . $userID, $this->my_groups);
51
+        }
52
+    }
53 53
 
54
-	public function listGroupIDs () : array {
55
-		$array = array();
54
+    public function listGroupIDs () : array {
55
+        $array = array();
56 56
 
57
-		foreach ($this->my_groups as $group_row) {
58
-			$array[] = $group_row['groupID'];
59
-		}
57
+        foreach ($this->my_groups as $group_row) {
58
+            $array[] = $group_row['groupID'];
59
+        }
60 60
 
61
-		return $array;
62
-	}
61
+        return $array;
62
+    }
63 63
 
64
-	public function listMyGroups () : array {
65
-		$array = array();
64
+    public function listMyGroups () : array {
65
+        $array = array();
66 66
 
67
-		foreach ($this->my_groups as $row) {
68
-			$group = new Group();
69
-			$group->loadByRow($row);
67
+        foreach ($this->my_groups as $row) {
68
+            $group = new Group();
69
+            $group->loadByRow($row);
70 70
 
71
-			$array[] = $group;
72
-		}
71
+            $array[] = $group;
72
+        }
73 73
 
74
-		return $array;
75
-	}
74
+        return $array;
75
+    }
76 76
 
77
-	public static function createGroupIfIdAbsent (int $groupID, string $name, string $description, string $color = "#000000", bool $show = true, bool $system_group = false, bool $auto_assign_regist = false) {
78
-		//check, if color is valide
79
-		$validator = new Validator_Color();
77
+    public static function createGroupIfIdAbsent (int $groupID, string $name, string $description, string $color = "#000000", bool $show = true, bool $system_group = false, bool $auto_assign_regist = false) {
78
+        //check, if color is valide
79
+        $validator = new Validator_Color();
80 80
 
81
-		if (!$validator->isValide($color)) {
82
-			throw new IllegalArgumentException("color '" . $color . "' isnt a valide hex color.");
83
-		}
81
+        if (!$validator->isValide($color)) {
82
+            throw new IllegalArgumentException("color '" . $color . "' isnt a valide hex color.");
83
+        }
84 84
 
85
-		Database::getInstance()->execute("INSERT INTO `{praefix}groups` (
85
+        Database::getInstance()->execute("INSERT INTO `{praefix}groups` (
86 86
 			`groupID`, `name`, `description`, `color`, `auto_assign_regist`, `system_group`, `show`, `activated`
87 87
 		) VALUES (
88 88
 			:groupID, :name, :description, :color, :auto_assign_regist, :system_group, :show, '1'
89 89
 		) ON DUPLICATE KEY UPDATE `groupID` = :groupID; ", array(
90
-			'groupID' => $groupID,
91
-			'name' => Validator_String::get($name),
92
-			'description' => Validator_String::get($description),
93
-			'color' => $color,
94
-			'auto_assign_regist' => ($auto_assign_regist ? 1 : 0),
95
-			'system_group' => ($system_group ? 1 : 0),
96
-			'show' => ($show ? 1 : 0)
97
-		));
98
-
99
-		//clear complete cache for all groups, so membership cache is also cleared
100
-		Cache::clear("groups");
101
-	}
102
-
103
-	public static function deleteGroup (int $groupID) {
104
-		$group = new Group();
105
-
106
-		try {
107
-			$group->loadById($groupID);
108
-		} catch (IllegalStateException $e) {
109
-			//group doesnt exists, we dont have to do anything
110
-			return;
111
-		}
112
-
113
-		$group->delete();
114
-	}
115
-
116
-	public static function addGroupToUser (int $groupID, int $userID, bool $group_leader = false) {
117
-		Database::getInstance()->execute("INSERT INTO `{praefix}group_members` (
90
+            'groupID' => $groupID,
91
+            'name' => Validator_String::get($name),
92
+            'description' => Validator_String::get($description),
93
+            'color' => $color,
94
+            'auto_assign_regist' => ($auto_assign_regist ? 1 : 0),
95
+            'system_group' => ($system_group ? 1 : 0),
96
+            'show' => ($show ? 1 : 0)
97
+        ));
98
+
99
+        //clear complete cache for all groups, so membership cache is also cleared
100
+        Cache::clear("groups");
101
+    }
102
+
103
+    public static function deleteGroup (int $groupID) {
104
+        $group = new Group();
105
+
106
+        try {
107
+            $group->loadById($groupID);
108
+        } catch (IllegalStateException $e) {
109
+            //group doesnt exists, we dont have to do anything
110
+            return;
111
+        }
112
+
113
+        $group->delete();
114
+    }
115
+
116
+    public static function addGroupToUser (int $groupID, int $userID, bool $group_leader = false) {
117
+        Database::getInstance()->execute("INSERT INTO `{praefix}group_members` (
118 118
 			`groupID`, `userID`, `group_leader`, `activated`
119 119
 		) VALUES (
120 120
 			:groupID, :userID, :group_leader, '1'
121 121
 		) ON DUPLICATE KEY UPDATE `group_leader` = :group_leader; ", array(
122
-			'groupID' => array(
123
-				'type' => PDO::PARAM_INT,
124
-				'value' => $groupID
125
-			),
126
-			'userID' => array(
127
-				'type' => PDO::PARAM_INT,
128
-				'value' => $userID
129
-			),
130
-			'group_leader' => ($group_leader ? 1 : 0)
131
-		));
132
-
133
-		//clear cache
134
-		Cache::clear("groups", "own-groups-" . $userID);
135
-	}
136
-
137
-	public static function removeGroupFromUser (int $groupID, int $userID) {
138
-		Database::getInstance()->execute("DELETE FROM `{praefix}group_members` WHERE `groupID` = :groupID AND `userID` = :userID; ", array(
139
-			'groupID' => array(
140
-				'type' => PDO::PARAM_INT,
141
-				'value' => $groupID
142
-			),
143
-			'userID' => array(
144
-				'type' => PDO::PARAM_INT,
145
-				'value' => $userID
146
-			)
147
-		));
148
-
149
-		//clear cache
150
-		Cache::clear("groups", "own-groups-" . $userID);
151
-	}
122
+            'groupID' => array(
123
+                'type' => PDO::PARAM_INT,
124
+                'value' => $groupID
125
+            ),
126
+            'userID' => array(
127
+                'type' => PDO::PARAM_INT,
128
+                'value' => $userID
129
+            ),
130
+            'group_leader' => ($group_leader ? 1 : 0)
131
+        ));
132
+
133
+        //clear cache
134
+        Cache::clear("groups", "own-groups-" . $userID);
135
+    }
136
+
137
+    public static function removeGroupFromUser (int $groupID, int $userID) {
138
+        Database::getInstance()->execute("DELETE FROM `{praefix}group_members` WHERE `groupID` = :groupID AND `userID` = :userID; ", array(
139
+            'groupID' => array(
140
+                'type' => PDO::PARAM_INT,
141
+                'value' => $groupID
142
+            ),
143
+            'userID' => array(
144
+                'type' => PDO::PARAM_INT,
145
+                'value' => $userID
146
+            )
147
+        ));
148
+
149
+        //clear cache
150
+        Cache::clear("groups", "own-groups-" . $userID);
151
+    }
152 152
 
153 153
 }
154 154
 
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 		//
34 34
 	}
35 35
 
36
-	public function loadMyGroups (int $userID) {
36
+	public function loadMyGroups(int $userID) {
37 37
 		if (Cache::contains("groups", "own-groups-" . $userID)) {
38 38
 			$this->my_groups = Cache::get("groups", "own-groups-" . $userID);
39 39
 		} else {
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 		}
52 52
 	}
53 53
 
54
-	public function listGroupIDs () : array {
54
+	public function listGroupIDs() : array {
55 55
 		$array = array();
56 56
 
57 57
 		foreach ($this->my_groups as $group_row) {
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 		return $array;
62 62
 	}
63 63
 
64
-	public function listMyGroups () : array {
64
+	public function listMyGroups() : array {
65 65
 		$array = array();
66 66
 
67 67
 		foreach ($this->my_groups as $row) {
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 		return $array;
75 75
 	}
76 76
 
77
-	public static function createGroupIfIdAbsent (int $groupID, string $name, string $description, string $color = "#000000", bool $show = true, bool $system_group = false, bool $auto_assign_regist = false) {
77
+	public static function createGroupIfIdAbsent(int $groupID, string $name, string $description, string $color = "#000000", bool $show = true, bool $system_group = false, bool $auto_assign_regist = false) {
78 78
 		//check, if color is valide
79 79
 		$validator = new Validator_Color();
80 80
 
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 		Cache::clear("groups");
101 101
 	}
102 102
 
103
-	public static function deleteGroup (int $groupID) {
103
+	public static function deleteGroup(int $groupID) {
104 104
 		$group = new Group();
105 105
 
106 106
 		try {
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 		$group->delete();
114 114
 	}
115 115
 
116
-	public static function addGroupToUser (int $groupID, int $userID, bool $group_leader = false) {
116
+	public static function addGroupToUser(int $groupID, int $userID, bool $group_leader = false) {
117 117
 		Database::getInstance()->execute("INSERT INTO `{praefix}group_members` (
118 118
 			`groupID`, `userID`, `group_leader`, `activated`
119 119
 		) VALUES (
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 		Cache::clear("groups", "own-groups-" . $userID);
135 135
 	}
136 136
 
137
-	public static function removeGroupFromUser (int $groupID, int $userID) {
137
+	public static function removeGroupFromUser(int $groupID, int $userID) {
138 138
 		Database::getInstance()->execute("DELETE FROM `{praefix}group_members` WHERE `groupID` = :groupID AND `userID` = :userID; ", array(
139 139
 			'groupID' => array(
140 140
 				'type' => PDO::PARAM_INT,
Please login to merge, or discard this patch.
system/packages/com.jukusoft.cms.groups/classes/group.php 2 patches
Indentation   +206 added lines, -206 removed lines patch added patch discarded remove patch
@@ -27,212 +27,212 @@
 block discarded – undo
27 27
 
28 28
 class Group {
29 29
 
30
-	protected $groupID = -1;
31
-	protected $row = null;
32
-
33
-	public function __construct() {
34
-		//
35
-	}
36
-
37
-	public function loadById (int $groupID) {
38
-		if (Cache::contains("groups", "group-" . $groupID)) {
39
-			$this->row = Cache::get("groups", "group-" . $groupID);
40
-		} else {
41
-			$row = Database::getInstance()->getRow("SELECT * FROM `{praefix}groups` WHERE `groupID` = :groupID AND `acivated` = '1'; ", array(
42
-				'groupID' => array(
43
-					'type' => PDO::PARAM_INT,
44
-					'value' => $groupID
45
-				)
46
-			));
47
-
48
-			if (!$row) {
49
-				throw new IllegalStateException("Group with groupID " . $groupID . " doesnt exists.");
50
-			}
51
-
52
-			$this->row = $row;
53
-			$this->groupID = $row['groupID'];
54
-
55
-			//cache database row
56
-			Cache::put("groups", "group-" . $groupID, $row);
57
-		}
58
-	}
59
-
60
-	public function loadByRow (array $row) {
61
-		$this->row = $row;
62
-		$this->groupID = $row['groupID'];
63
-	}
64
-
65
-	public function update (string $name, string $description, string $color, bool $auto_assign_regist = false) {
66
-		//throw event
67
-		Events::throwEvent("before_update_group", array(
68
-			'groupID' => $this->groupID,
69
-			'old_row' => $this->row,
70
-			'name' => &$name,
71
-			'description' => &$description,
72
-			'color' => &$color,
73
-			'auto_assign_regist' => &$auto_assign_regist
74
-		));
75
-
76
-		Database::getInstance()->execute("UPDATE `{praefix}groups` SET `name` = :name, `description` = :description, `color` = :color, `auto_assign_regist` = :auto_assign_regist WHERE `groupID` = :groupID; ", array(
77
-			'name' => $name,
78
-			'description' => $description,
79
-			'color' => $color,
80
-			'auto_assign_regist' => ($auto_assign_regist ? 1 : 0),
81
-			'groupID' => array(
82
-				'type' => PDO::PARAM_INT,
83
-				'value' => $this->groupID
84
-			)
85
-		));
86
-
87
-		//throw event
88
-		Events::throwEvent("after_update_group", array(
89
-			'groupID' => $this->groupID,
90
-			'old_row' => $this->row,
91
-		));
92
-
93
-		//update row in-memory
94
-		$this->row['name'] = $name;
95
-		$this->row['description'] = $description;
96
-		$this->row['color'] = $color;
97
-		$this->row['auto_assign_regist'] = ($auto_assign_regist ? 1 : 0);
98
-
99
-		//clear cache
100
-		Cache::clear("groups", "group-" . $this->groupID);
101
-	}
102
-
103
-	public function putCache () {
104
-		//cache database row
105
-		Cache::put("groups", "group-" . $this->groupID, $this->row);
106
-	}
107
-
108
-	public function removeCache () {
109
-		//clear cache data for this group
110
-		Cache::clear("groups", "group-" . $this->groupID);
111
-	}
112
-
113
-	/**
114
-	 * get id of group
115
-	 *
116
-	 * @return id of group
117
-	 */
118
-	public function getGroupID () : int {
119
-		return $this->groupID;
120
-	}
121
-
122
-	/**
123
-	 * get name of group
124
-	 *
125
-	 * @return name of group
126
-	 */
127
-	public function getName () : string {
128
-		return $this->row['name'];
129
-	}
130
-
131
-	/**
132
-	 * get group description
133
-	 *
134
-	 * @return group description
135
-	 */
136
-	public function getDescription () : string {
137
-		return $this->row['description'];
138
-	}
139
-
140
-	/**
141
-	 * get color of group (e.q. #FF0000)
142
-	 *
143
-	 * @return color of group in hex
144
-	 */
145
-	public function getColor () : string {
146
-		return $this->row['color'];
147
-	}
148
-
149
-	/**
150
-	 * check, if group is a system group, so group cannot be deleted and is required by system
151
-	 *
152
-	 * @return true, if group is a system group
153
-	 */
154
-	public function isSystemGroup () : bool {
155
-		return $this->row['system_group'] === 1;
156
-	}
157
-
158
-	/**
159
-	 * check for auto assign flag, this is means a group is automatically assigned to users on registration
160
-	 *
161
-	 * @return true, if group is a auto assign group on registration
162
-	 */
163
-	public function isAutoAssignGroup () : bool {
164
-		return $this->row['auto_assign_regist'] === 1;
165
-	}
166
-
167
-	public function getRow () : array {
168
-		return $this->row;
169
-	}
170
-
171
-	public function visible () : bool {
172
-		return $this->row['show'] === 1;
173
-	}
174
-
175
-	public function hasRank () : bool {
176
-		return $this->row['rank'] !== "none";
177
-	}
178
-
179
-	public function getRank () : string {
180
-		return $this->row['rank'];
181
-	}
182
-
183
-	public function hasRankImage () : bool {
184
-		return $this->row['rank_image'] !== "none";
185
-	}
186
-
187
-	public function getRankImage () : string {
188
-		return $this->row['rank_image'];
189
-	}
190
-
191
-	public function isActivated () : bool {
192
-		return $this->row['activated'] === 1;
193
-	}
194
-
195
-	public function delete () {
196
-		if ($this->groupID <= 0) {
197
-			throw new IllegalStateException("groupID cannot be <= 0, maybe group wasnt loaded with loadById() or loadByRow()?");
198
-		}
199
-
200
-		$delete_group = true;
201
-
202
-		//throw event, so plugins can avoid deleting of groups
203
-		Events::throwEvent("before_delete_group", array(
204
-			'groupID' => $this->groupID,
205
-			'row' => $this->row,
206
-			'delete_group' => &$delete_group
207
-		));
208
-
209
-		if ($delete_group) {
210
-			//delete group from database
211
-			Database::getInstance()->execute("DELETE * FROM `{praefix}groups` WHERE `groupID` = :groupID; ", array(
212
-				'groupID' => array(
213
-					'type' => PDO::PARAM_INT,
214
-					'value' => $this->groupID
215
-				)
216
-			));
217
-
218
-			//delete all members of group
219
-			Database::getInstance()->execute("DELETE * FROM `{praefix}group_members` WHERE `groupID` = :groupID; ", array(
220
-				'groupID' => array(
221
-					'type' => PDO::PARAM_INT,
222
-					'value' => $this->groupID
223
-				)
224
-			));
225
-
226
-			//clear cache
227
-			Cache::clear("groups", "group-" . $this->groupID);
228
-
229
-			//throw event, so plugins can cleanup
230
-			Events::throwEvent("after_delete_group", array(
231
-				'groupID' => $this->groupID,
232
-				'row' => $this->row
233
-			));
234
-		}
235
-	}
30
+    protected $groupID = -1;
31
+    protected $row = null;
32
+
33
+    public function __construct() {
34
+        //
35
+    }
36
+
37
+    public function loadById (int $groupID) {
38
+        if (Cache::contains("groups", "group-" . $groupID)) {
39
+            $this->row = Cache::get("groups", "group-" . $groupID);
40
+        } else {
41
+            $row = Database::getInstance()->getRow("SELECT * FROM `{praefix}groups` WHERE `groupID` = :groupID AND `acivated` = '1'; ", array(
42
+                'groupID' => array(
43
+                    'type' => PDO::PARAM_INT,
44
+                    'value' => $groupID
45
+                )
46
+            ));
47
+
48
+            if (!$row) {
49
+                throw new IllegalStateException("Group with groupID " . $groupID . " doesnt exists.");
50
+            }
51
+
52
+            $this->row = $row;
53
+            $this->groupID = $row['groupID'];
54
+
55
+            //cache database row
56
+            Cache::put("groups", "group-" . $groupID, $row);
57
+        }
58
+    }
59
+
60
+    public function loadByRow (array $row) {
61
+        $this->row = $row;
62
+        $this->groupID = $row['groupID'];
63
+    }
64
+
65
+    public function update (string $name, string $description, string $color, bool $auto_assign_regist = false) {
66
+        //throw event
67
+        Events::throwEvent("before_update_group", array(
68
+            'groupID' => $this->groupID,
69
+            'old_row' => $this->row,
70
+            'name' => &$name,
71
+            'description' => &$description,
72
+            'color' => &$color,
73
+            'auto_assign_regist' => &$auto_assign_regist
74
+        ));
75
+
76
+        Database::getInstance()->execute("UPDATE `{praefix}groups` SET `name` = :name, `description` = :description, `color` = :color, `auto_assign_regist` = :auto_assign_regist WHERE `groupID` = :groupID; ", array(
77
+            'name' => $name,
78
+            'description' => $description,
79
+            'color' => $color,
80
+            'auto_assign_regist' => ($auto_assign_regist ? 1 : 0),
81
+            'groupID' => array(
82
+                'type' => PDO::PARAM_INT,
83
+                'value' => $this->groupID
84
+            )
85
+        ));
86
+
87
+        //throw event
88
+        Events::throwEvent("after_update_group", array(
89
+            'groupID' => $this->groupID,
90
+            'old_row' => $this->row,
91
+        ));
92
+
93
+        //update row in-memory
94
+        $this->row['name'] = $name;
95
+        $this->row['description'] = $description;
96
+        $this->row['color'] = $color;
97
+        $this->row['auto_assign_regist'] = ($auto_assign_regist ? 1 : 0);
98
+
99
+        //clear cache
100
+        Cache::clear("groups", "group-" . $this->groupID);
101
+    }
102
+
103
+    public function putCache () {
104
+        //cache database row
105
+        Cache::put("groups", "group-" . $this->groupID, $this->row);
106
+    }
107
+
108
+    public function removeCache () {
109
+        //clear cache data for this group
110
+        Cache::clear("groups", "group-" . $this->groupID);
111
+    }
112
+
113
+    /**
114
+     * get id of group
115
+     *
116
+     * @return id of group
117
+     */
118
+    public function getGroupID () : int {
119
+        return $this->groupID;
120
+    }
121
+
122
+    /**
123
+     * get name of group
124
+     *
125
+     * @return name of group
126
+     */
127
+    public function getName () : string {
128
+        return $this->row['name'];
129
+    }
130
+
131
+    /**
132
+     * get group description
133
+     *
134
+     * @return group description
135
+     */
136
+    public function getDescription () : string {
137
+        return $this->row['description'];
138
+    }
139
+
140
+    /**
141
+     * get color of group (e.q. #FF0000)
142
+     *
143
+     * @return color of group in hex
144
+     */
145
+    public function getColor () : string {
146
+        return $this->row['color'];
147
+    }
148
+
149
+    /**
150
+     * check, if group is a system group, so group cannot be deleted and is required by system
151
+     *
152
+     * @return true, if group is a system group
153
+     */
154
+    public function isSystemGroup () : bool {
155
+        return $this->row['system_group'] === 1;
156
+    }
157
+
158
+    /**
159
+     * check for auto assign flag, this is means a group is automatically assigned to users on registration
160
+     *
161
+     * @return true, if group is a auto assign group on registration
162
+     */
163
+    public function isAutoAssignGroup () : bool {
164
+        return $this->row['auto_assign_regist'] === 1;
165
+    }
166
+
167
+    public function getRow () : array {
168
+        return $this->row;
169
+    }
170
+
171
+    public function visible () : bool {
172
+        return $this->row['show'] === 1;
173
+    }
174
+
175
+    public function hasRank () : bool {
176
+        return $this->row['rank'] !== "none";
177
+    }
178
+
179
+    public function getRank () : string {
180
+        return $this->row['rank'];
181
+    }
182
+
183
+    public function hasRankImage () : bool {
184
+        return $this->row['rank_image'] !== "none";
185
+    }
186
+
187
+    public function getRankImage () : string {
188
+        return $this->row['rank_image'];
189
+    }
190
+
191
+    public function isActivated () : bool {
192
+        return $this->row['activated'] === 1;
193
+    }
194
+
195
+    public function delete () {
196
+        if ($this->groupID <= 0) {
197
+            throw new IllegalStateException("groupID cannot be <= 0, maybe group wasnt loaded with loadById() or loadByRow()?");
198
+        }
199
+
200
+        $delete_group = true;
201
+
202
+        //throw event, so plugins can avoid deleting of groups
203
+        Events::throwEvent("before_delete_group", array(
204
+            'groupID' => $this->groupID,
205
+            'row' => $this->row,
206
+            'delete_group' => &$delete_group
207
+        ));
208
+
209
+        if ($delete_group) {
210
+            //delete group from database
211
+            Database::getInstance()->execute("DELETE * FROM `{praefix}groups` WHERE `groupID` = :groupID; ", array(
212
+                'groupID' => array(
213
+                    'type' => PDO::PARAM_INT,
214
+                    'value' => $this->groupID
215
+                )
216
+            ));
217
+
218
+            //delete all members of group
219
+            Database::getInstance()->execute("DELETE * FROM `{praefix}group_members` WHERE `groupID` = :groupID; ", array(
220
+                'groupID' => array(
221
+                    'type' => PDO::PARAM_INT,
222
+                    'value' => $this->groupID
223
+                )
224
+            ));
225
+
226
+            //clear cache
227
+            Cache::clear("groups", "group-" . $this->groupID);
228
+
229
+            //throw event, so plugins can cleanup
230
+            Events::throwEvent("after_delete_group", array(
231
+                'groupID' => $this->groupID,
232
+                'row' => $this->row
233
+            ));
234
+        }
235
+    }
236 236
 
237 237
 }
238 238
 
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 		//
35 35
 	}
36 36
 
37
-	public function loadById (int $groupID) {
37
+	public function loadById(int $groupID) {
38 38
 		if (Cache::contains("groups", "group-" . $groupID)) {
39 39
 			$this->row = Cache::get("groups", "group-" . $groupID);
40 40
 		} else {
@@ -57,12 +57,12 @@  discard block
 block discarded – undo
57 57
 		}
58 58
 	}
59 59
 
60
-	public function loadByRow (array $row) {
60
+	public function loadByRow(array $row) {
61 61
 		$this->row = $row;
62 62
 		$this->groupID = $row['groupID'];
63 63
 	}
64 64
 
65
-	public function update (string $name, string $description, string $color, bool $auto_assign_regist = false) {
65
+	public function update(string $name, string $description, string $color, bool $auto_assign_regist = false) {
66 66
 		//throw event
67 67
 		Events::throwEvent("before_update_group", array(
68 68
 			'groupID' => $this->groupID,
@@ -100,12 +100,12 @@  discard block
 block discarded – undo
100 100
 		Cache::clear("groups", "group-" . $this->groupID);
101 101
 	}
102 102
 
103
-	public function putCache () {
103
+	public function putCache() {
104 104
 		//cache database row
105 105
 		Cache::put("groups", "group-" . $this->groupID, $this->row);
106 106
 	}
107 107
 
108
-	public function removeCache () {
108
+	public function removeCache() {
109 109
 		//clear cache data for this group
110 110
 		Cache::clear("groups", "group-" . $this->groupID);
111 111
 	}
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 	 *
116 116
 	 * @return id of group
117 117
 	 */
118
-	public function getGroupID () : int {
118
+	public function getGroupID() : int {
119 119
 		return $this->groupID;
120 120
 	}
121 121
 
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 	 *
125 125
 	 * @return name of group
126 126
 	 */
127
-	public function getName () : string {
127
+	public function getName() : string {
128 128
 		return $this->row['name'];
129 129
 	}
130 130
 
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 	 *
134 134
 	 * @return group description
135 135
 	 */
136
-	public function getDescription () : string {
136
+	public function getDescription() : string {
137 137
 		return $this->row['description'];
138 138
 	}
139 139
 
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 	 *
143 143
 	 * @return color of group in hex
144 144
 	 */
145
-	public function getColor () : string {
145
+	public function getColor() : string {
146 146
 		return $this->row['color'];
147 147
 	}
148 148
 
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 	 *
152 152
 	 * @return true, if group is a system group
153 153
 	 */
154
-	public function isSystemGroup () : bool {
154
+	public function isSystemGroup() : bool {
155 155
 		return $this->row['system_group'] === 1;
156 156
 	}
157 157
 
@@ -160,39 +160,39 @@  discard block
 block discarded – undo
160 160
 	 *
161 161
 	 * @return true, if group is a auto assign group on registration
162 162
 	 */
163
-	public function isAutoAssignGroup () : bool {
163
+	public function isAutoAssignGroup() : bool {
164 164
 		return $this->row['auto_assign_regist'] === 1;
165 165
 	}
166 166
 
167
-	public function getRow () : array {
167
+	public function getRow() : array {
168 168
 		return $this->row;
169 169
 	}
170 170
 
171
-	public function visible () : bool {
171
+	public function visible() : bool {
172 172
 		return $this->row['show'] === 1;
173 173
 	}
174 174
 
175
-	public function hasRank () : bool {
175
+	public function hasRank() : bool {
176 176
 		return $this->row['rank'] !== "none";
177 177
 	}
178 178
 
179
-	public function getRank () : string {
179
+	public function getRank() : string {
180 180
 		return $this->row['rank'];
181 181
 	}
182 182
 
183
-	public function hasRankImage () : bool {
183
+	public function hasRankImage() : bool {
184 184
 		return $this->row['rank_image'] !== "none";
185 185
 	}
186 186
 
187
-	public function getRankImage () : string {
187
+	public function getRankImage() : string {
188 188
 		return $this->row['rank_image'];
189 189
 	}
190 190
 
191
-	public function isActivated () : bool {
191
+	public function isActivated() : bool {
192 192
 		return $this->row['activated'] === 1;
193 193
 	}
194 194
 
195
-	public function delete () {
195
+	public function delete() {
196 196
 		if ($this->groupID <= 0) {
197 197
 			throw new IllegalStateException("groupID cannot be <= 0, maybe group wasnt loaded with loadById() or loadByRow()?");
198 198
 		}
Please login to merge, or discard this patch.
system/packages/com.jukusoft.cms.user/classes/loginhandler.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -27,9 +27,9 @@
 block discarded – undo
27 27
 
28 28
 class LoginHandler {
29 29
 
30
-	public static function handle () : array {
31
-		//
32
-	}
30
+    public static function handle () : array {
31
+        //
32
+    }
33 33
 
34 34
 }
35 35
 
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
27 27
 
28 28
 class LoginHandler {
29 29
 
30
-	public static function handle () : array {
30
+	public static function handle() : array {
31 31
 		//
32 32
 	}
33 33
 
Please login to merge, or discard this patch.
system/packages/com.jukusoft.cms.page/classes/pagerights.php 2 patches
Indentation   +142 added lines, -142 removed lines patch added patch discarded remove patch
@@ -27,160 +27,160 @@
 block discarded – undo
27 27
 
28 28
 class PageRights {
29 29
 
30
-	protected $pageID = 0;
31
-	protected $page = null;
32
-	protected $group_rows = null;
33
-	protected $user_rows = null;
34
-
35
-	public function __construct(Page $page) {
36
-		$this->pageID = $page->getPageID();
37
-		$this->page = $page;
38
-	}
39
-
40
-	public function load () {
41
-		if (Cache::contains("page_rights", "page_" . $this->pageID)) {
42
-			$this->group_rows = Cache::get("page_rights", "page_" . $this->pageID);
43
-		} else {
44
-			$rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}page_rights` WHERE `pageID` = :pageID; ", array(
45
-				'pageID' => array(
46
-					'type' => PDO::PARAM_INT,
47
-					'value' => $this->pageID
48
-				)
49
-			));
50
-
51
-			$array = array();
52
-
53
-			foreach ($rows as $row) {
54
-				if (!isset($array[$row['groupID']])) {
55
-					$array[$row['groupID']] = array();
56
-				}
57
-
58
-				$array[$row['groupID']][$row['token']] = $row['value'];
59
-			}
60
-
61
-			//cache results
62
-			Cache::put("page_rights", "page_" . $this->pageID, $array);
63
-
64
-			$this->group_rows = $array;
65
-		}
66
-
67
-		if (Cache::contains("page_rights", "page_user_" . $this->pageID)) {
68
-			$this->user_rows = Cache::get("page_rights", "page_user_" . $this->pageID);
69
-		} else {
70
-			$rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}page_user_rights` WHERE `pageID` = :pageID; ", array(
71
-				'pageID' => array(
72
-					'type' => PDO::PARAM_INT,
73
-					'value' => $this->pageID
74
-				)
75
-			));
76
-
77
-			$array = array();
78
-
79
-			foreach ($rows as $row) {
80
-				if (!isset($array[$row['userID']])) {
81
-					$array[$row['userID']] = array();
82
-				}
83
-
84
-				$array[$row['userID']][$row['token']] = $row['value'];
85
-			}
86
-
87
-			//cache results
88
-			Cache::put("page_rights", "page_user_" . $this->pageID, $array);
89
-
90
-			$this->user_rows = $array;
91
-		}
92
-	}
93
-
94
-	/**
95
-	 * check, if user has right for this page
96
-	 */
97
-	public function checkRights (int $userID, array $groupIDs, string $token) : bool {
98
-		$value = 0;
99
-
100
-		//per default published pages are visible, if not specified
101
-		if ($token == "see") {
102
-			$value = -1;
103
-		}
104
-
105
-		//iterate through user groups
106
-		foreach ($groupIDs as $groupID) {
107
-			//check, if permissions exists for groupID
108
-			if (!isset($this->group_rows[$groupID])) {
109
-				//no rights specified for this group
110
-				continue;
111
-			}
112
-
113
-			if (!isset($this->group_rows[$groupID][$token])) {
114
-				continue;
115
-			}
116
-
117
-			$row_value = $this->group_rows[$groupID][$token];
118
-
119
-			if ($row_value > $value) {
120
-				$value = $row_value;
121
-			}
122
-		}
123
-
124
-		if (isset($this->user_rows[$userID]) && isset($this->user_rows[$userID][$token])) {
125
-			$row_value = $this->user_rows[$userID][$token];
126
-
127
-			if ($row_value > $value) {
128
-				$value = $row_value;
129
-			}
130
-		}
131
-
132
-		return $value == 1 || $value == -1;
133
-	}
134
-
135
-	protected function mergeRow (array $permissions, string $token, int $value) : array {
136
-		if ($value < 0 || $value > 2) {
137
-			throw new IllegalArgumentException("token ('" . $token . "') value '" . $value . "' is not allowed, value has to be >= 0 and <= 2.");
138
-		}
139
-
140
-		if (!isset($permissions[$token])) {
141
-			$permissions[$token] = $value;
142
-		} else {
143
-			$current_value = $permissions[$token];
144
-
145
-			if ($value > $current_value) {
146
-				$permissions[$token] = $value;
147
-			}
148
-		}
30
+    protected $pageID = 0;
31
+    protected $page = null;
32
+    protected $group_rows = null;
33
+    protected $user_rows = null;
34
+
35
+    public function __construct(Page $page) {
36
+        $this->pageID = $page->getPageID();
37
+        $this->page = $page;
38
+    }
39
+
40
+    public function load () {
41
+        if (Cache::contains("page_rights", "page_" . $this->pageID)) {
42
+            $this->group_rows = Cache::get("page_rights", "page_" . $this->pageID);
43
+        } else {
44
+            $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}page_rights` WHERE `pageID` = :pageID; ", array(
45
+                'pageID' => array(
46
+                    'type' => PDO::PARAM_INT,
47
+                    'value' => $this->pageID
48
+                )
49
+            ));
50
+
51
+            $array = array();
52
+
53
+            foreach ($rows as $row) {
54
+                if (!isset($array[$row['groupID']])) {
55
+                    $array[$row['groupID']] = array();
56
+                }
57
+
58
+                $array[$row['groupID']][$row['token']] = $row['value'];
59
+            }
60
+
61
+            //cache results
62
+            Cache::put("page_rights", "page_" . $this->pageID, $array);
63
+
64
+            $this->group_rows = $array;
65
+        }
66
+
67
+        if (Cache::contains("page_rights", "page_user_" . $this->pageID)) {
68
+            $this->user_rows = Cache::get("page_rights", "page_user_" . $this->pageID);
69
+        } else {
70
+            $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}page_user_rights` WHERE `pageID` = :pageID; ", array(
71
+                'pageID' => array(
72
+                    'type' => PDO::PARAM_INT,
73
+                    'value' => $this->pageID
74
+                )
75
+            ));
76
+
77
+            $array = array();
78
+
79
+            foreach ($rows as $row) {
80
+                if (!isset($array[$row['userID']])) {
81
+                    $array[$row['userID']] = array();
82
+                }
83
+
84
+                $array[$row['userID']][$row['token']] = $row['value'];
85
+            }
86
+
87
+            //cache results
88
+            Cache::put("page_rights", "page_user_" . $this->pageID, $array);
89
+
90
+            $this->user_rows = $array;
91
+        }
92
+    }
93
+
94
+    /**
95
+     * check, if user has right for this page
96
+     */
97
+    public function checkRights (int $userID, array $groupIDs, string $token) : bool {
98
+        $value = 0;
99
+
100
+        //per default published pages are visible, if not specified
101
+        if ($token == "see") {
102
+            $value = -1;
103
+        }
104
+
105
+        //iterate through user groups
106
+        foreach ($groupIDs as $groupID) {
107
+            //check, if permissions exists for groupID
108
+            if (!isset($this->group_rows[$groupID])) {
109
+                //no rights specified for this group
110
+                continue;
111
+            }
112
+
113
+            if (!isset($this->group_rows[$groupID][$token])) {
114
+                continue;
115
+            }
116
+
117
+            $row_value = $this->group_rows[$groupID][$token];
118
+
119
+            if ($row_value > $value) {
120
+                $value = $row_value;
121
+            }
122
+        }
123
+
124
+        if (isset($this->user_rows[$userID]) && isset($this->user_rows[$userID][$token])) {
125
+            $row_value = $this->user_rows[$userID][$token];
126
+
127
+            if ($row_value > $value) {
128
+                $value = $row_value;
129
+            }
130
+        }
131
+
132
+        return $value == 1 || $value == -1;
133
+    }
134
+
135
+    protected function mergeRow (array $permissions, string $token, int $value) : array {
136
+        if ($value < 0 || $value > 2) {
137
+            throw new IllegalArgumentException("token ('" . $token . "') value '" . $value . "' is not allowed, value has to be >= 0 and <= 2.");
138
+        }
139
+
140
+        if (!isset($permissions[$token])) {
141
+            $permissions[$token] = $value;
142
+        } else {
143
+            $current_value = $permissions[$token];
144
+
145
+            if ($value > $current_value) {
146
+                $permissions[$token] = $value;
147
+            }
148
+        }
149 149
 
150
-		return $permissions;
151
-	}
150
+        return $permissions;
151
+    }
152 152
 
153
-	public static function setDefaultAllowedGroups (int $pageID, array $groupIDs) {
154
-		if (sizeof($groupIDs) == 0) {
155
-			throw new IllegalArgumentException("no groupIDs was set.");
156
-		}
153
+    public static function setDefaultAllowedGroups (int $pageID, array $groupIDs) {
154
+        if (sizeof($groupIDs) == 0) {
155
+            throw new IllegalArgumentException("no groupIDs was set.");
156
+        }
157 157
 
158
-		$lines = array();
158
+        $lines = array();
159 159
 
160
-		foreach ($groupIDs as $groupID) {
161
-			//validate groupID
162
-			$groupID = Validator_Int::get($groupID);
160
+        foreach ($groupIDs as $groupID) {
161
+            //validate groupID
162
+            $groupID = Validator_Int::get($groupID);
163 163
 
164
-			$lines[] = "('" . $groupID . "', '" . $pageID . "', 'see', '1')";
165
-		}
166
-
167
-		$line_str = implode(",\n", $lines);
168
-
169
-		Database::getInstance()->execute("INSERT INTO `{praefix}page_rights` (
164
+            $lines[] = "('" . $groupID . "', '" . $pageID . "', 'see', '1')";
165
+        }
166
+
167
+        $line_str = implode(",\n", $lines);
168
+
169
+        Database::getInstance()->execute("INSERT INTO `{praefix}page_rights` (
170 170
 			`groupID`, `pageID`, `token`, `value`
171 171
 		) VALUES 
172 172
 			" . $line_str . "
173 173
 		ON DUPLICATE KEY UPDATE `value` = '1'; ");
174 174
 
175
-		//clear cache
176
-		Cache::clear("page_rights", "page_" . $pageID);
177
-	}
175
+        //clear cache
176
+        Cache::clear("page_rights", "page_" . $pageID);
177
+    }
178 178
 
179
-	public static function setDefaultAllowedGroupsForAlias (string $alias, array $groupIDs) {
180
-		$pageID = Page::getPageIDByAlias($alias);
179
+    public static function setDefaultAllowedGroupsForAlias (string $alias, array $groupIDs) {
180
+        $pageID = Page::getPageIDByAlias($alias);
181 181
 
182
-		self::setDefaultAllowedGroups($pageID, $groupIDs);
183
-	}
182
+        self::setDefaultAllowedGroups($pageID, $groupIDs);
183
+    }
184 184
 
185 185
 }
186 186
 
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 		$this->page = $page;
38 38
 	}
39 39
 
40
-	public function load () {
40
+	public function load() {
41 41
 		if (Cache::contains("page_rights", "page_" . $this->pageID)) {
42 42
 			$this->group_rows = Cache::get("page_rights", "page_" . $this->pageID);
43 43
 		} else {
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 	/**
95 95
 	 * check, if user has right for this page
96 96
 	 */
97
-	public function checkRights (int $userID, array $groupIDs, string $token) : bool {
97
+	public function checkRights(int $userID, array $groupIDs, string $token) : bool {
98 98
 		$value = 0;
99 99
 
100 100
 		//per default published pages are visible, if not specified
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 		return $value == 1 || $value == -1;
133 133
 	}
134 134
 
135
-	protected function mergeRow (array $permissions, string $token, int $value) : array {
135
+	protected function mergeRow(array $permissions, string $token, int $value) : array {
136 136
 		if ($value < 0 || $value > 2) {
137 137
 			throw new IllegalArgumentException("token ('" . $token . "') value '" . $value . "' is not allowed, value has to be >= 0 and <= 2.");
138 138
 		}
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 		return $permissions;
151 151
 	}
152 152
 
153
-	public static function setDefaultAllowedGroups (int $pageID, array $groupIDs) {
153
+	public static function setDefaultAllowedGroups(int $pageID, array $groupIDs) {
154 154
 		if (sizeof($groupIDs) == 0) {
155 155
 			throw new IllegalArgumentException("no groupIDs was set.");
156 156
 		}
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 		Cache::clear("page_rights", "page_" . $pageID);
177 177
 	}
178 178
 
179
-	public static function setDefaultAllowedGroupsForAlias (string $alias, array $groupIDs) {
179
+	public static function setDefaultAllowedGroupsForAlias(string $alias, array $groupIDs) {
180 180
 		$pageID = Page::getPageIDByAlias($alias);
181 181
 
182 182
 		self::setDefaultAllowedGroups($pageID, $groupIDs);
Please login to merge, or discard this patch.
system/packages/com.jukusoft.cms.page/classes/pageloader.php 2 patches
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -27,15 +27,15 @@
 block discarded – undo
27 27
 
28 28
 class PageLoader {
29 29
 
30
-	public static function loadInstance (string $type_name) : PageType {
31
-		if ($type_name == null || empty($type_name)) {
32
-			throw new NullPointerException("page_type cannot be null or empty.");
33
-		}
30
+    public static function loadInstance (string $type_name) : PageType {
31
+        if ($type_name == null || empty($type_name)) {
32
+            throw new NullPointerException("page_type cannot be null or empty.");
33
+        }
34 34
 
35
-		$class = $type_name;//DataBase::getInstance()->escape($type_name);
35
+        $class = $type_name;//DataBase::getInstance()->escape($type_name);
36 36
 
37
-		return new $class();
38
-	}
37
+        return new $class();
38
+    }
39 39
 
40 40
 }
41 41
 
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -27,12 +27,12 @@
 block discarded – undo
27 27
 
28 28
 class PageLoader {
29 29
 
30
-	public static function loadInstance (string $type_name) : PageType {
30
+	public static function loadInstance(string $type_name) : PageType {
31 31
 		if ($type_name == null || empty($type_name)) {
32 32
 			throw new NullPointerException("page_type cannot be null or empty.");
33 33
 		}
34 34
 
35
-		$class = $type_name;//DataBase::getInstance()->escape($type_name);
35
+		$class = $type_name; //DataBase::getInstance()->escape($type_name);
36 36
 
37 37
 		return new $class();
38 38
 	}
Please login to merge, or discard this patch.
system/packages/com.jukusoft.cms.db.upgrader/classes/dbtable.php 2 patches
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -848,11 +848,11 @@  discard block
 block discarded – undo
848 848
             }
849 849
 
850 850
             if (isset($column['default']) && $column['default'] != null) {
851
-            	if ($column['default'] === "CURRENT_TIMESTAMP") {
852
-					$default_str = " DEFAULT CURRENT_TIMESTAMP";
853
-				} else {
854
-					$default_str = " DEFAULT '" . $column['default'] . "'";
855
-				}
851
+                if ($column['default'] === "CURRENT_TIMESTAMP") {
852
+                    $default_str = " DEFAULT CURRENT_TIMESTAMP";
853
+                } else {
854
+                    $default_str = " DEFAULT '" . $column['default'] . "'";
855
+                }
856 856
             }
857 857
 
858 858
             switch ($column['type']) {
@@ -1298,10 +1298,10 @@  discard block
 block discarded – undo
1298 1298
             //create table structure
1299 1299
             $this->create();
1300 1300
         } else {
1301
-        	var_dump($this->detectTableChanges());
1301
+            var_dump($this->detectTableChanges());
1302 1302
 
1303 1303
             //TODO: add code here
1304
-			//throw new Exception("Upgrading of tables isnt supported yet.");
1304
+            //throw new Exception("Upgrading of tables isnt supported yet.");
1305 1305
         }
1306 1306
     }
1307 1307
 
@@ -1420,109 +1420,109 @@  discard block
 block discarded – undo
1420 1420
     }
1421 1421
 
1422 1422
     protected function detectTableChanges () : array {
1423
-    	//columns
1424
-    	$changed_columns = array();
1425
-    	$added_columns = array();
1426
-    	$removed_columns = array();
1423
+        //columns
1424
+        $changed_columns = array();
1425
+        $added_columns = array();
1426
+        $removed_columns = array();
1427 1427
 
1428
-    	//indexes
1429
-		$changed_indexes = array();
1430
-		$added_indexes = array();
1431
-		$removed_indexes = array();
1428
+        //indexes
1429
+        $changed_indexes = array();
1430
+        $added_indexes = array();
1431
+        $removed_indexes = array();
1432 1432
 
1433 1433
 
1434 1434
         //compare current state with should state
1435
-		$current_columns = $this->listColumnsFromDatabase();
1436
-		$should_columns = $this->columns;
1437
-
1438
-		//check for added columns
1439
-		foreach ($should_columns as $name=>$column_data) {
1440
-			if (!isset($current_columns[$name])) {
1441
-				//new column found
1442
-				$added_columns[$name] = $should_columns[$name];
1443
-			}
1444
-		}
1445
-
1446
-		//check for removed columns
1447
-		foreach ($current_columns as $name=>$column_data) {
1448
-			if (!isset($should_columns[$name])) {
1449
-				//removed column found
1450
-				$removed_columns[$name] = $current_columns[$name];
1451
-			}
1452
-		}
1453
-
1454
-		//check for changed columns
1455
-		foreach ($should_columns as $name=>$column_data) {
1456
-			//we dont have to check this column, if the column was added
1457
-			if (isset($added_columns[$name])) {
1458
-				continue;
1459
-			}
1460
-
1461
-			//we dont have to check this column, if the column was removed
1462
-			if (isset($removed_columns[$name])) {
1463
-				continue;
1464
-			}
1465
-
1466
-			//check for differences
1467
-			foreach ($should_columns[$name] as $key=>$value) {
1468
-				if (!isset($should_columns[$name][$key]) && !@is_null($should_columns[$name][$key])) {
1469
-					echo "Column '" . $key . "' not found.\n\n";
1470
-
1471
-					echo "should columns:\n";
1472
-					var_dump($should_columns);
1473
-
1474
-					echo "\n\ncurrent columns:\n";
1475
-					var_dump($current_columns);
1476
-
1477
-					echo "\n\n";
1478
-				}
1479
-
1480
-				if (strcmp($name, "charset") && @$current_columns[$name][$key] == "NULL") {
1481
-					continue;
1482
-				}
1483
-
1484
-				if (strcmp($name, "bool(false)")) {
1485
-					continue;
1486
-				}
1487
-
1488
-				if (!isset($current_columns[$name][$key]) && !@is_null($current_columns[$name][$key])) {
1489
-					echo "$" . "current_columns['" . $name . "']['" . $key . "'] not found:\n";
1490
-					var_dump($current_columns);
1491
-
1492
-					echo "\n\nshould columns:\n";
1493
-					var_dump($should_columns);
1494
-				}
1495
-
1496
-				if ($current_columns[$name][$key] != $value) {
1497
-					$changed_columns[$name] = $should_columns[$name];
1498
-				}
1499
-			}
1500
-		}
1501
-
1502
-		//TODO: check for changed indexes / keys
1503
-
1504
-		//TODO: change database engine if neccessary
1505
-
1506
-		//TODO: change charset if neccessary
1507
-
1508
-		return array(
1509
-			'added_columns' => $added_columns,
1510
-			"removed_columns" => $removed_columns,
1511
-			"changed_columns" => $changed_columns,
1512
-			"added_indexes" => $added_indexes,
1513
-			"removed_indexes" => $removed_indexes,
1514
-			"changed_indexes" => $changed_indexes
1515
-		);
1435
+        $current_columns = $this->listColumnsFromDatabase();
1436
+        $should_columns = $this->columns;
1437
+
1438
+        //check for added columns
1439
+        foreach ($should_columns as $name=>$column_data) {
1440
+            if (!isset($current_columns[$name])) {
1441
+                //new column found
1442
+                $added_columns[$name] = $should_columns[$name];
1443
+            }
1444
+        }
1445
+
1446
+        //check for removed columns
1447
+        foreach ($current_columns as $name=>$column_data) {
1448
+            if (!isset($should_columns[$name])) {
1449
+                //removed column found
1450
+                $removed_columns[$name] = $current_columns[$name];
1451
+            }
1452
+        }
1453
+
1454
+        //check for changed columns
1455
+        foreach ($should_columns as $name=>$column_data) {
1456
+            //we dont have to check this column, if the column was added
1457
+            if (isset($added_columns[$name])) {
1458
+                continue;
1459
+            }
1460
+
1461
+            //we dont have to check this column, if the column was removed
1462
+            if (isset($removed_columns[$name])) {
1463
+                continue;
1464
+            }
1465
+
1466
+            //check for differences
1467
+            foreach ($should_columns[$name] as $key=>$value) {
1468
+                if (!isset($should_columns[$name][$key]) && !@is_null($should_columns[$name][$key])) {
1469
+                    echo "Column '" . $key . "' not found.\n\n";
1470
+
1471
+                    echo "should columns:\n";
1472
+                    var_dump($should_columns);
1473
+
1474
+                    echo "\n\ncurrent columns:\n";
1475
+                    var_dump($current_columns);
1476
+
1477
+                    echo "\n\n";
1478
+                }
1479
+
1480
+                if (strcmp($name, "charset") && @$current_columns[$name][$key] == "NULL") {
1481
+                    continue;
1482
+                }
1483
+
1484
+                if (strcmp($name, "bool(false)")) {
1485
+                    continue;
1486
+                }
1487
+
1488
+                if (!isset($current_columns[$name][$key]) && !@is_null($current_columns[$name][$key])) {
1489
+                    echo "$" . "current_columns['" . $name . "']['" . $key . "'] not found:\n";
1490
+                    var_dump($current_columns);
1491
+
1492
+                    echo "\n\nshould columns:\n";
1493
+                    var_dump($should_columns);
1494
+                }
1495
+
1496
+                if ($current_columns[$name][$key] != $value) {
1497
+                    $changed_columns[$name] = $should_columns[$name];
1498
+                }
1499
+            }
1500
+        }
1501
+
1502
+        //TODO: check for changed indexes / keys
1503
+
1504
+        //TODO: change database engine if neccessary
1505
+
1506
+        //TODO: change charset if neccessary
1507
+
1508
+        return array(
1509
+            'added_columns' => $added_columns,
1510
+            "removed_columns" => $removed_columns,
1511
+            "changed_columns" => $changed_columns,
1512
+            "added_indexes" => $added_indexes,
1513
+            "removed_indexes" => $removed_indexes,
1514
+            "changed_indexes" => $changed_indexes
1515
+        );
1516 1516
     }
1517 1517
 
1518 1518
     /**
1519 1519
      * backup table
1520
-	 *
1521
-	 * @param $output_file file where sql query should be written in
1520
+     *
1521
+     * @param $output_file file where sql query should be written in
1522 1522
      */
1523 1523
     public function backup (string $output_file) : void {
1524
-    	//TODO: implement this feature
1525
-	}
1524
+        //TODO: implement this feature
1525
+    }
1526 1526
 
1527 1527
     public function truncate () {
1528 1528
         $this->db_driver->query("TRUNCATE `" . $this->table_name . "`; ");
Please login to merge, or discard this patch.
Spacing   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -50,12 +50,12 @@  discard block
 block discarded – undo
50 50
 
51 51
     protected $db_driver = null;
52 52
 
53
-    public function __construct (string $table_name, DBDriver &$db_driver) {
53
+    public function __construct(string $table_name, DBDriver &$db_driver) {
54 54
         $this->table_name = $this->escape($table_name);
55 55
         $this->db_driver = &$db_driver;
56 56
     }
57 57
 
58
-    public function setEngine (string $engine_name) {
58
+    public function setEngine(string $engine_name) {
59 59
         $found = false;
60 60
         $founded_engine = "";
61 61
 
@@ -77,15 +77,15 @@  discard block
 block discarded – undo
77 77
         $this->db_engine = $engine_name;
78 78
     }
79 79
 
80
-    public function setCharset (string $charset) {
80
+    public function setCharset(string $charset) {
81 81
         $this->charset = utf8_encode(htmlentities($charset));
82 82
     }
83 83
 
84
-    public function setTmpTable (bool $tmp_table) {
84
+    public function setTmpTable(bool $tmp_table) {
85 85
         $this->temp_table = $tmp_table;
86 86
     }
87 87
 
88
-    public function setAutoIncrementStartValue (int $value) {
88
+    public function setAutoIncrementStartValue(int $value) {
89 89
         $this->auto_increment = $value;
90 90
     }
91 91
 
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
      * @param $unsigned unsigned value false / true
98 98
      * @param $zerofill true, if values should be filled with 0, if value length isnt length of column
99 99
      */
100
-    public function addInt (string $name, int $length = null, bool $not_null = false, bool $auto_increment = false, int $default_value = null, bool $unsigned = false, bool $zerofill = false) {
100
+    public function addInt(string $name, int $length = null, bool $not_null = false, bool $auto_increment = false, int $default_value = null, bool $unsigned = false, bool $zerofill = false) {
101 101
         $this->columns[$name] = array(
102 102
             'type' => "int",
103 103
             'name' => $name,
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
     /**
114 114
      * addInteger() is an alias to addInt()
115 115
      */
116
-    public function addInteger (string $name, int $length = null, bool $not_null = false, bool $auto_increment = false, int $default_value = null, bool $unsigned = false, bool $zerofill = false) {
116
+    public function addInteger(string $name, int $length = null, bool $not_null = false, bool $auto_increment = false, int $default_value = null, bool $unsigned = false, bool $zerofill = false) {
117 117
         $this->addInt($name, $length, $not_null, $auto_increment, $default_value, $unsigned, $zerofill);
118 118
     }
119 119
 
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
      * @param $length length of column
125 125
      * @param $zerofill true, if values should be filled with 0, if value length isnt length of column
126 126
      */
127
-    public function addUnsignedInteger (string $name, int $length = null, bool $not_null = false, bool $auto_increment = false, int $default_value = null, bool $zerofill = false) {
127
+    public function addUnsignedInteger(string $name, int $length = null, bool $not_null = false, bool $auto_increment = false, int $default_value = null, bool $zerofill = false) {
128 128
         $this->columns[$name] = array(
129 129
             'type' => "int",
130 130
             'name' => $name,
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
         );
138 138
     }
139 139
 
140
-    public function addVarchar (string $name, int $length = 255, bool $not_null = false, string $default_value = null, bool $binary = false, string $charset = null) {
140
+    public function addVarchar(string $name, int $length = 255, bool $not_null = false, string $default_value = null, bool $binary = false, string $charset = null) {
141 141
         $this->columns[$name] = array(
142 142
             'type' => "varchar",
143 143
             'name' => $name,
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
         );
150 150
     }
151 151
 
152
-    public function addBit (string $name, int $length = null, bool $not_null = false, string $default_value = null) {
152
+    public function addBit(string $name, int $length = null, bool $not_null = false, string $default_value = null) {
153 153
         $this->columns[$name] = array(
154 154
             'type' => "bit",
155 155
             'name' => $name,
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
         );
160 160
     }
161 161
 
162
-    public function addBinary (string $name, int $length = null, bool $not_null = false, string $default_value = null) {
162
+    public function addBinary(string $name, int $length = null, bool $not_null = false, string $default_value = null) {
163 163
         $this->columns[$name] = array(
164 164
             'type' => "binary",
165 165
             'name' => $name,
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
         );
170 170
     }
171 171
 
172
-    public function addText (string $name, bool $not_null = false, string $default_value = null, bool $binary = false, string $charset = null) {
172
+    public function addText(string $name, bool $not_null = false, string $default_value = null, bool $binary = false, string $charset = null) {
173 173
         $this->columns[$name] = array(
174 174
             'type' => "text",
175 175
             'name' => $name,
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
         );
181 181
     }
182 182
 
183
-    public function addChar (string $name, int $length = 255, bool $not_null = false, string $default_value = null, bool $binary = false, string $charset = null) {
183
+    public function addChar(string $name, int $length = 255, bool $not_null = false, string $default_value = null, bool $binary = false, string $charset = null) {
184 184
         $this->columns[$name] = array(
185 185
             'type' => "char",
186 186
             'name' => $name,
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
         );
193 193
     }
194 194
 
195
-    public function addTinyText (string $name, bool $not_null = false, string $default_value = null, bool $binary = false, string $charset = null) {
195
+    public function addTinyText(string $name, bool $not_null = false, string $default_value = null, bool $binary = false, string $charset = null) {
196 196
         $this->columns[$name] = array(
197 197
             'type' => "tinytext",
198 198
             'name' => $name,
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
         );
204 204
     }
205 205
 
206
-    public function addMediumText (string $name, bool $not_null = false, string $default_value = null, bool $binary = false, string $charset = null) {
206
+    public function addMediumText(string $name, bool $not_null = false, string $default_value = null, bool $binary = false, string $charset = null) {
207 207
         $this->columns[$name] = array(
208 208
             'type' => "mediumtext",
209 209
             'name' => $name,
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
         );
215 215
     }
216 216
 
217
-    public function addLongText (string $name, bool $not_null = false, string $default_value = null, bool $binary = false, string $charset = null) {
217
+    public function addLongText(string $name, bool $not_null = false, string $default_value = null, bool $binary = false, string $charset = null) {
218 218
         $this->columns[$name] = array(
219 219
             'type' => "longtext",
220 220
             'name' => $name,
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
         );
226 226
     }
227 227
 
228
-    public function addTinyInt (string $name, int $length = null, bool $not_null = false, bool $auto_increment = false, int $default_value = null, bool $unsigned = false, bool $zerofill = false) {
228
+    public function addTinyInt(string $name, int $length = null, bool $not_null = false, bool $auto_increment = false, int $default_value = null, bool $unsigned = false, bool $zerofill = false) {
229 229
         $this->columns[$name] = array(
230 230
             'type' => "tinyint",
231 231
             'name' => $name,
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
         );
239 239
     }
240 240
 
241
-    public function addSmallInt (string $name, int $length = null, bool $not_null = false, bool $auto_increment = false, int $default_value = null, bool $unsigned = false, bool $zerofill = false) {
241
+    public function addSmallInt(string $name, int $length = null, bool $not_null = false, bool $auto_increment = false, int $default_value = null, bool $unsigned = false, bool $zerofill = false) {
242 242
         $this->columns[$name] = array(
243 243
             'type' => "smallint",
244 244
             'name' => $name,
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
         );
252 252
     }
253 253
 
254
-    public function addMediumInt (string $name, int $length = null, bool $not_null = false, bool $auto_increment = false, int $default_value = null, bool $unsigned = false, bool $zerofill = false) {
254
+    public function addMediumInt(string $name, int $length = null, bool $not_null = false, bool $auto_increment = false, int $default_value = null, bool $unsigned = false, bool $zerofill = false) {
255 255
         $this->columns[$name] = array(
256 256
             'type' => "mediumint",
257 257
             'name' => $name,
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
         );
265 265
     }
266 266
 
267
-    public function addBigInt (string $name, int $length = null, bool $not_null = false, bool $auto_increment = false, int $default_value = null, bool $unsigned = false, bool $zerofill = false) {
267
+    public function addBigInt(string $name, int $length = null, bool $not_null = false, bool $auto_increment = false, int $default_value = null, bool $unsigned = false, bool $zerofill = false) {
268 268
         $this->columns[$name] = array(
269 269
             'type' => "bigint",
270 270
             'name' => $name,
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
         );
278 278
     }
279 279
 
280
-    public function addDecimal (string $name, int $length = 5, int $decimals = 2, bool $not_null = false, int $default_value = null, bool $unsigned = false, bool $zerofill = false) {
280
+    public function addDecimal(string $name, int $length = 5, int $decimals = 2, bool $not_null = false, int $default_value = null, bool $unsigned = false, bool $zerofill = false) {
281 281
         //DECIMAL doesnt support AUTO_INCREMENT
282 282
 
283 283
         $this->columns[$name] = array(
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
         );
293 293
     }
294 294
 
295
-    public function addNumeric (string $name, int $length = 5, int $decimals = 2, bool $not_null = false, int $default_value = null, bool $unsigned = false, bool $zerofill = false) {
295
+    public function addNumeric(string $name, int $length = 5, int $decimals = 2, bool $not_null = false, int $default_value = null, bool $unsigned = false, bool $zerofill = false) {
296 296
         //NUMERIC doesnt support AUTO_INCREMENT
297 297
 
298 298
         $this->columns[$name] = array(
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
         );
308 308
     }
309 309
 
310
-    public function addDouble (string $name, int $length = 5, int $decimals = 2, bool $not_null = false, bool $auto_increment = false, int $default_value = null, bool $unsigned = false, bool $zerofill = false) {
310
+    public function addDouble(string $name, int $length = 5, int $decimals = 2, bool $not_null = false, bool $auto_increment = false, int $default_value = null, bool $unsigned = false, bool $zerofill = false) {
311 311
         $this->columns[$name] = array(
312 312
             'type' => "double",
313 313
             'name' => $name,
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
         );
322 322
     }
323 323
 
324
-    public function addFloat (string $name, int $length = 5, int $decimals = 2, bool $not_null = false, bool $auto_increment = false, int $default_value = null, bool $unsigned = false, bool $zerofill = false) {
324
+    public function addFloat(string $name, int $length = 5, int $decimals = 2, bool $not_null = false, bool $auto_increment = false, int $default_value = null, bool $unsigned = false, bool $zerofill = false) {
325 325
         $this->columns[$name] = array(
326 326
             'type' => "float",
327 327
             'name' => $name,
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
         );
336 336
     }
337 337
 
338
-    public function addReal (string $name, int $length = 5, int $decimals = 2, bool $not_null = false, bool $auto_increment = false, int $default_value = null, bool $unsigned = false, bool $zerofill = false) {
338
+    public function addReal(string $name, int $length = 5, int $decimals = 2, bool $not_null = false, bool $auto_increment = false, int $default_value = null, bool $unsigned = false, bool $zerofill = false) {
339 339
         $this->columns[$name] = array(
340 340
             'type' => "real",
341 341
             'name' => $name,
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
         );
350 350
     }
351 351
 
352
-    public function addBlob (string $name, bool $not_null = false, string $default_value = null) {
352
+    public function addBlob(string $name, bool $not_null = false, string $default_value = null) {
353 353
         $this->columns[$name] = array(
354 354
             'type' => "blob",
355 355
             'name' => $name,
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
         );
359 359
     }
360 360
 
361
-    public function addTinyBlob (string $name, bool $not_null = false, string $default_value = null) {
361
+    public function addTinyBlob(string $name, bool $not_null = false, string $default_value = null) {
362 362
         $this->columns[$name] = array(
363 363
             'type' => "tinyblob",
364 364
             'name' => $name,
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
         );
368 368
     }
369 369
 
370
-    public function addMediumBlob (string $name, bool $not_null = false, string $default_value = null) {
370
+    public function addMediumBlob(string $name, bool $not_null = false, string $default_value = null) {
371 371
         $this->columns[$name] = array(
372 372
             'type' => "mediumblob",
373 373
             'name' => $name,
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
         );
377 377
     }
378 378
 
379
-    public function addLongBlob (string $name, bool $not_null = false, string $default_value = null) {
379
+    public function addLongBlob(string $name, bool $not_null = false, string $default_value = null) {
380 380
         $this->columns[$name] = array(
381 381
             'type' => "longblob",
382 382
             'name' => $name,
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
         );
386 386
     }
387 387
 
388
-    public function addEnum (string $name, $values = array(), bool $not_null = false, string $default_value = null, string $charset = null) {
388
+    public function addEnum(string $name, $values = array(), bool $not_null = false, string $default_value = null, string $charset = null) {
389 389
         $this->columns[$name] = array(
390 390
             'type' => "enum",
391 391
             'name' => $name,
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
         );
397 397
     }
398 398
 
399
-    public function addSet (string $name, array $values = array(), bool $not_null = false, string $default_value = null, string $charset = null) {
399
+    public function addSet(string $name, array $values = array(), bool $not_null = false, string $default_value = null, string $charset = null) {
400 400
         $this->columns[$name] = array(
401 401
             'type' => "set",
402 402
             'name' => $name,
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
         );
408 408
     }
409 409
 
410
-    public function addDate (string $name, bool $not_null = false, string $default_value = null) {
410
+    public function addDate(string $name, bool $not_null = false, string $default_value = null) {
411 411
         $this->columns[$name] = array(
412 412
             'type' => "date",
413 413
             'name' => $name,
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
         );
417 417
     }
418 418
 
419
-    public function addTime (string $name, bool $not_null = false, string $default_value = null, int $fsp = null) {
419
+    public function addTime(string $name, bool $not_null = false, string $default_value = null, int $fsp = null) {
420 420
         $this->columns[$name] = array(
421 421
             'type' => "time",
422 422
             'name' => $name,
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
         );
427 427
     }
428 428
 
429
-    public function addYear (string $name, bool $not_null = false, string $default_value = null) {
429
+    public function addYear(string $name, bool $not_null = false, string $default_value = null) {
430 430
         $this->columns[$name] = array(
431 431
             'type' => "year",
432 432
             'name' => $name,
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
         );
436 436
     }
437 437
 
438
-    public function addJSON (string $name, bool $not_null = false, string $default_value = null) {
438
+    public function addJSON(string $name, bool $not_null = false, string $default_value = null) {
439 439
         $this->columns[$name] = array(
440 440
             'type' => "json",
441 441
             'name' => $name,
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
         );
445 445
     }
446 446
 
447
-    public function addTimestamp (string $name, bool $not_null = false, string $default_value = null, bool $on_update_current_timestamp = false, int $fsp = null) {
447
+    public function addTimestamp(string $name, bool $not_null = false, string $default_value = null, bool $on_update_current_timestamp = false, int $fsp = null) {
448 448
         $this->columns[$name] = array(
449 449
             'type' => "timestamp",
450 450
             'name' => $name,
@@ -455,7 +455,7 @@  discard block
 block discarded – undo
455 455
         );
456 456
     }
457 457
 
458
-    public function addDateTime (string $name, bool $not_null = false, string $default_value = null, int $fsp = null) {
458
+    public function addDateTime(string $name, bool $not_null = false, string $default_value = null, int $fsp = null) {
459 459
         $this->columns[$name] = array(
460 460
             'type' => "datetime",
461 461
             'name' => $name,
@@ -465,14 +465,14 @@  discard block
 block discarded – undo
465 465
         );
466 466
     }
467 467
 
468
-    public function addPrimaryKey ($columns) {
468
+    public function addPrimaryKey($columns) {
469 469
         $this->indexes['primary'] = array(
470 470
             'type' => "primary",
471 471
             'columns' => $columns
472 472
         );
473 473
     }
474 474
 
475
-    public function addIndex ($columns, string $index_name = null) {
475
+    public function addIndex($columns, string $index_name = null) {
476 476
         if ($index_name == null) {
477 477
             if (!is_array($columns)) {
478 478
                 $index_name = "ix_" . $columns;
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
         );
490 490
     }
491 491
 
492
-    public function addUnique ($columns, string $index_name = null) {
492
+    public function addUnique($columns, string $index_name = null) {
493 493
         if ($index_name == null) {
494 494
             if (!is_array($columns)) {
495 495
                 $index_name = "uq_" . $columns;
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
         );
507 507
     }
508 508
 
509
-    public function addSpatial ($columns, string $index_name = null) {
509
+    public function addSpatial($columns, string $index_name = null) {
510 510
         if ($index_name == null) {
511 511
             if (!is_array($columns)) {
512 512
                 $index_name = "sp_" . $columns;
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
         );
524 524
     }
525 525
 
526
-    public function addFulltext ($columns, string $index_name = null) {
526
+    public function addFulltext($columns, string $index_name = null) {
527 527
         if ($index_name == null) {
528 528
             if (!is_array($columns)) {
529 529
                 $index_name = "ix_" . $columns;
@@ -540,7 +540,7 @@  discard block
 block discarded – undo
540 540
         );
541 541
     }
542 542
 
543
-    public function addForeignKey ($columns, string $reference_table_name, $reference_columns, string $index_name = null, string $on_update = null, string $on_delete = null) {
543
+    public function addForeignKey($columns, string $reference_table_name, $reference_columns, string $index_name = null, string $on_update = null, string $on_delete = null) {
544 544
         if ($index_name == null) {
545 545
             if (!is_array($columns)) {
546 546
                 $index_name = "ix_" . $columns;
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
         );
562 562
     }
563 563
 
564
-    public function generateCreateQuery () : string {
564
+    public function generateCreateQuery() : string {
565 565
         $tmp_str = "";
566 566
 
567 567
         if ($this->temp_table) {
@@ -599,7 +599,7 @@  discard block
 block discarded – undo
599 599
         return $sql;
600 600
     }
601 601
 
602
-    protected function generateColoumQuery () : string {
602
+    protected function generateColoumQuery() : string {
603 603
         //generate lines of coloum definitions
604 604
         $lines = $this->getColoumLines();
605 605
 
@@ -607,7 +607,7 @@  discard block
 block discarded – undo
607 607
         return implode(",\r\n", $lines) . "";
608 608
     }
609 609
 
610
-    protected function generateIndexQuery () : string {
610
+    protected function generateIndexQuery() : string {
611 611
         //check, if no index is set
612 612
         if (count($this->indexes) == 0) {
613 613
             return "";
@@ -829,7 +829,7 @@  discard block
 block discarded – undo
829 829
         return ",\r\n" . implode(",\r\n", $lines);
830 830
     }
831 831
 
832
-    protected function getColoumLines () : array {
832
+    protected function getColoumLines() : array {
833 833
         $lines = array();
834 834
 
835 835
         foreach ($this->columns as $column) {
@@ -1285,7 +1285,7 @@  discard block
 block discarded – undo
1285 1285
     /**
1286 1286
      * create table structure in database, if table not exists
1287 1287
      */
1288
-    public function create () {
1288
+    public function create() {
1289 1289
         //create table
1290 1290
         $this->db_driver->execute($this->generateCreateQuery());
1291 1291
     }
@@ -1293,7 +1293,7 @@  discard block
 block discarded – undo
1293 1293
     /**
1294 1294
      * upgrades table structure in database, or if table not exists, creates table
1295 1295
      */
1296
-    public function upgrade () {
1296
+    public function upgrade() {
1297 1297
         if (!$this->existsTable()) {
1298 1298
             //create table structure
1299 1299
             $this->create();
@@ -1305,7 +1305,7 @@  discard block
 block discarded – undo
1305 1305
         }
1306 1306
     }
1307 1307
 
1308
-    public function listColumnsFromDatabase () : array {
1308
+    public function listColumnsFromDatabase() : array {
1309 1309
         $columns = array();
1310 1310
 
1311 1311
         //get columns from database
@@ -1406,7 +1406,7 @@  discard block
 block discarded – undo
1406 1406
                 'length' => $length,
1407 1407
                 'decimals' => $decimals,
1408 1408
                 'not_null' => $not_null,
1409
-                'values' => $values,//only for enum and set
1409
+                'values' => $values, //only for enum and set
1410 1410
                 'auto_increment' => $auto_increment,
1411 1411
                 'on_update_current_timestamp' => $on_update_current_timestamp,
1412 1412
                 'unsigned' => $unsigned,
@@ -1419,7 +1419,7 @@  discard block
 block discarded – undo
1419 1419
         return $columns;
1420 1420
     }
1421 1421
 
1422
-    protected function detectTableChanges () : array {
1422
+    protected function detectTableChanges() : array {
1423 1423
     	//columns
1424 1424
     	$changed_columns = array();
1425 1425
     	$added_columns = array();
@@ -1520,64 +1520,64 @@  discard block
 block discarded – undo
1520 1520
 	 *
1521 1521
 	 * @param $output_file file where sql query should be written in
1522 1522
      */
1523
-    public function backup (string $output_file) : void {
1523
+    public function backup(string $output_file) : void {
1524 1524
     	//TODO: implement this feature
1525 1525
 	}
1526 1526
 
1527
-    public function truncate () {
1527
+    public function truncate() {
1528 1528
         $this->db_driver->query("TRUNCATE `" . $this->table_name . "`; ");
1529 1529
     }
1530 1530
 
1531 1531
     /**
1532 1532
      * alias to truncate()
1533 1533
      */
1534
-    public function cleanUp () {
1534
+    public function cleanUp() {
1535 1535
         $this->truncate();
1536 1536
     }
1537 1537
 
1538
-    public function check () {
1538
+    public function check() {
1539 1539
         //check table
1540 1540
         return $this->db_driver->getRow("CHECK TABLE `{DBPRAEFIX}" . $this->table_name . "`; ");
1541 1541
     }
1542 1542
 
1543
-    public function analyze () {
1543
+    public function analyze() {
1544 1544
         //check table
1545 1545
         return $this->db_driver->getRow("ANALYZE TABLE `{DBPRAEFIX}" . $this->table_name . "`; ");
1546 1546
     }
1547 1547
 
1548
-    public function optimize () {
1548
+    public function optimize() {
1549 1549
         //optimize table
1550 1550
         return $this->db_driver->listRows("OPTIMIZE TABLE `{DBPRAEFIX}" . $this->table_name . "`; ");
1551 1551
     }
1552 1552
 
1553
-    public function flush () {
1553
+    public function flush() {
1554 1554
         //flush table
1555 1555
         $this->db_driver->query("FLUSH TABLE `{DBPRAEFIX}" . $this->table_name . "`; ");
1556 1556
     }
1557 1557
 
1558
-    public function drop () {
1558
+    public function drop() {
1559 1559
         //drop table
1560 1560
         $this->db_driver->query("DROP TABLE `{DBPRAEFIX}" . $this->table_name . "`; ");
1561 1561
     }
1562 1562
 
1563
-    public function existsTable () : bool {
1563
+    public function existsTable() : bool {
1564 1564
         return count($this->db_driver->listRows("SHOW TABLES LIKE '{DBPRAEFIX}" . $this->table_name . "'; ")) > 0;
1565 1565
     }
1566 1566
 
1567
-    public function escape (string $str) {
1567
+    public function escape(string $str) {
1568 1568
         return utf8_encode(htmlentities($str));
1569 1569
     }
1570 1570
 
1571
-    public static function listTables (DBDriver &$dbDriver) {
1571
+    public static function listTables(DBDriver &$dbDriver) {
1572 1572
         return $dbDriver->listRows("SHOW TABLES; ");
1573 1573
     }
1574 1574
 
1575
-    public static function getTableStructure (string $table_name, DBDriver &$dbDriver) {
1575
+    public static function getTableStructure(string $table_name, DBDriver &$dbDriver) {
1576 1576
         //https://dev.mysql.com/doc/refman/5.5/en/creating-tables.html
1577 1577
         return $dbDriver->listRows("DESCRIBE `{DBPRAEFIX}" . $table_name . "`; ");
1578 1578
     }
1579 1579
 
1580
-    public static function getTableStructureByInformationSchema (string $table_name, DBDriver &$dbDriver) {
1580
+    public static function getTableStructureByInformationSchema(string $table_name, DBDriver &$dbDriver) {
1581 1581
         //https://makandracards.com/makandra/2531-show-the-character-set-and-the-collation-of-your-mysql-tables
1582 1582
 
1583 1583
         //http://stackoverflow.com/questions/8662906/getting-mysql-to-display-the-encoding-used-for-a-particular-column
@@ -1588,7 +1588,7 @@  discard block
 block discarded – undo
1588 1588
         return $dbDriver->listRows("SELECT * FROM `information_schema`.`COLUMNS` WHERE `TABLE_SCHEMA` = '" . $dbDriver->getDatabaseName() . "' AND `TABLE_NAME` = `{DBPRAEFIX}" . $table_name . "`; ", array(), true);
1589 1589
     }
1590 1590
 
1591
-    public static function listIndexes (string $table_name, DBDriver &$dbDriver) {
1591
+    public static function listIndexes(string $table_name, DBDriver &$dbDriver) {
1592 1592
         return $dbDriver->listRows("SHOW INDEX FROM `{DBPRAEFIX}" . $table_name . "`; ");
1593 1593
     }
1594 1594
 
Please login to merge, or discard this patch.
system/packages/com.jukusoft.cms.xtpl/xtpl/caching_xtemplate.class.php 2 patches
Indentation   +293 added lines, -293 removed lines patch added patch discarded remove patch
@@ -30,350 +30,350 @@
 block discarded – undo
30 30
  */
31 31
 class CachingXTemplate extends XTemplate {
32 32
 
33
-	/**
34
-	 * Cache expiry time (seconds)
35
-	 *
36
-	 * @access public
37
-	 * @var int
38
-	 */
39
-	public $cache_expiry	= 0;
40
-
41
-	/**
42
-	 * Cache file unique identifier
43
-	 *
44
-	 * @example session_id()
45
-	 * @access public
46
-	 * @var string
47
-	 */
48
-	public $cache_unique	= 'unique';
49
-
50
-	/**
51
-	 * Filename extension
52
-	 *
53
-	 * @example .xcache
54
-	 * @access public
55
-	 * @var string
56
-	 */
57
-	public $cache_ext		= '.xcache';
58
-
59
-	/**
60
-	 * Path to cache dir
61
-	 * Needs to be writable by webserver
62
-	 *
63
-	 * @example ./xcache
64
-	 * @access public
65
-	 * @var string
66
-	 */
67
-	public $cache_dir		= './xcache';
68
-
69
-	/**
70
-	 * Flag showing whether template is cached
71
-	 *
72
-	 * @access private
73
-	 * @var boolean
74
-	 */
75
-	private $_template_is_cached	= false;
76
-
77
-	/**
78
-	 * Cache expiry time
79
-	 *
80
-	 * @access private
81
-	 * @var int
82
-	 */
83
-	private $_cache_expiry			= 0;
84
-
85
-	/**
86
-	 * File modified time
87
-	 *
88
-	 * @access private
89
-	 * @var int
90
-	 */
91
-	private $_cache_filemtime		= 0;
92
-
93
-	/**
94
-	 * Override of parent constructor
95
-	 *
96
-	 * @access public
33
+    /**
34
+     * Cache expiry time (seconds)
35
+     *
36
+     * @access public
37
+     * @var int
38
+     */
39
+    public $cache_expiry	= 0;
40
+
41
+    /**
42
+     * Cache file unique identifier
43
+     *
44
+     * @example session_id()
45
+     * @access public
46
+     * @var string
47
+     */
48
+    public $cache_unique	= 'unique';
49
+
50
+    /**
51
+     * Filename extension
52
+     *
53
+     * @example .xcache
54
+     * @access public
55
+     * @var string
56
+     */
57
+    public $cache_ext		= '.xcache';
58
+
59
+    /**
60
+     * Path to cache dir
61
+     * Needs to be writable by webserver
62
+     *
63
+     * @example ./xcache
64
+     * @access public
65
+     * @var string
66
+     */
67
+    public $cache_dir		= './xcache';
68
+
69
+    /**
70
+     * Flag showing whether template is cached
71
+     *
72
+     * @access private
73
+     * @var boolean
74
+     */
75
+    private $_template_is_cached	= false;
76
+
77
+    /**
78
+     * Cache expiry time
79
+     *
80
+     * @access private
81
+     * @var int
82
+     */
83
+    private $_cache_expiry			= 0;
84
+
85
+    /**
86
+     * File modified time
87
+     *
88
+     * @access private
89
+     * @var int
90
+     */
91
+    private $_cache_filemtime		= 0;
92
+
93
+    /**
94
+     * Override of parent constructor
95
+     *
96
+     * @access public
97 97
      * @param string $file Template file to work on
98 98
      * @param string $tpldir Location of template files (useful for keeping files outside web server root)
99 99
      * @param array $files Filenames lookup
100 100
      * @param string $mainblock Name of main block in the template
101 101
      * @param boolean $autosetup If true, run setup() as part of constuctor
102
-	 * @param int $cache_expiry Seconds to cache for
103
-	 * @param string $cache_unique Unique file id (e.g. session_id())
104
-	 * @param string $cache_dir Cache folder
105
-	 * @param string $cache_ext Cache file extension
106
-	 */
107
-	public function __construct($file, $tpldir = '', $files = null, $mainblock = 'main', $autosetup = true, $cache_expiry = 0, $cache_unique = '', $cache_dir = './xcache', $cache_ext = '.xcache') {
108
-
109
-		$this->restart($file, $tpldir, $files, $mainblock, $autosetup, $this->tag_start_delim, $this->tag_end_delim, $cache_expiry, $cache_unique, $cache_dir, $cache_ext);
110
-
111
-	}
112
-
113
-	/**
114
-	 * Override of parent restart method
115
-	 *
116
-	 * @access public
117
-	 * @param string $file Template file to work on
118
-	 * @param string $tpldir Location of template files
119
-	 * @param array $files Filenames lookup
120
-	 * @param string $mainblock Name of main block in the template
121
-	 * @param boolean $autosetup If true, run setup() as part of restarting
122
-	 * @param string $tag_start {
123
-	 * @param string $tag_end }
124
-	 * @param int $cache_expiry Seconds to cache for
125
-	 * @param string $cache_unique Unique file id (e.g. session_id())
126
-	 * @param string $cache_dir Cache folder
127
-	 * @param string $cache_ext Cache file extension
128
-	 */
129
-	public function restart ($file, $tpldir = '', $files = null, $mainblock = 'main', $autosetup = true, $tag_start = '{', $tag_end = '}', $cache_expiry = 0, $cache_unique = '', $cache_dir = './xcache', $cache_ext = '.xcache') {
130
-
131
-		if ($cache_expiry > 0) {
132
-			$this->cache_expiry = $cache_expiry;
133
-		}
134
-
135
-		if (!empty($cache_unique)) {
136
-			if (!preg_match('/^\./', $cache_unique)) {
137
-				$cache_unique = '.' . $cache_unique;
138
-			}
139
-			$this->cache_unique = $cache_unique;
140
-		}
141
-
142
-		if (!empty($cache_dir)) {
143
-			$this->cache_dir = $cache_dir;
144
-		}
145
-
146
-		if (!empty($cache_ext)) {
147
-			if (!preg_match('/^\./', $cache_ext)) {
148
-				$cache_ext = '.' . $cache_ext;
149
-			}
150
-			$this->cache_ext = $cache_ext;
151
-		}
152
-
153
-		// Call parent restart method but don't run setup yet!
154
-		parent::restart($file, $tpldir, $files, $mainblock, false, $tag_start, $tag_end);
155
-
156
-		if ($this->cache_expiry > 0) {
157
-			$this->read_template_cache();
158
-		}
159
-
160
-		if (!$this->_template_is_cached && $autosetup) {
161
-			$this->setup();
162
-		}
163
-	}
164
-
165
-	/**
166
-	 * Override of parent assign method
167
-	 *
168
-	 * @access public
102
+     * @param int $cache_expiry Seconds to cache for
103
+     * @param string $cache_unique Unique file id (e.g. session_id())
104
+     * @param string $cache_dir Cache folder
105
+     * @param string $cache_ext Cache file extension
106
+     */
107
+    public function __construct($file, $tpldir = '', $files = null, $mainblock = 'main', $autosetup = true, $cache_expiry = 0, $cache_unique = '', $cache_dir = './xcache', $cache_ext = '.xcache') {
108
+
109
+        $this->restart($file, $tpldir, $files, $mainblock, $autosetup, $this->tag_start_delim, $this->tag_end_delim, $cache_expiry, $cache_unique, $cache_dir, $cache_ext);
110
+
111
+    }
112
+
113
+    /**
114
+     * Override of parent restart method
115
+     *
116
+     * @access public
117
+     * @param string $file Template file to work on
118
+     * @param string $tpldir Location of template files
119
+     * @param array $files Filenames lookup
120
+     * @param string $mainblock Name of main block in the template
121
+     * @param boolean $autosetup If true, run setup() as part of restarting
122
+     * @param string $tag_start {
123
+     * @param string $tag_end }
124
+     * @param int $cache_expiry Seconds to cache for
125
+     * @param string $cache_unique Unique file id (e.g. session_id())
126
+     * @param string $cache_dir Cache folder
127
+     * @param string $cache_ext Cache file extension
128
+     */
129
+    public function restart ($file, $tpldir = '', $files = null, $mainblock = 'main', $autosetup = true, $tag_start = '{', $tag_end = '}', $cache_expiry = 0, $cache_unique = '', $cache_dir = './xcache', $cache_ext = '.xcache') {
130
+
131
+        if ($cache_expiry > 0) {
132
+            $this->cache_expiry = $cache_expiry;
133
+        }
134
+
135
+        if (!empty($cache_unique)) {
136
+            if (!preg_match('/^\./', $cache_unique)) {
137
+                $cache_unique = '.' . $cache_unique;
138
+            }
139
+            $this->cache_unique = $cache_unique;
140
+        }
141
+
142
+        if (!empty($cache_dir)) {
143
+            $this->cache_dir = $cache_dir;
144
+        }
145
+
146
+        if (!empty($cache_ext)) {
147
+            if (!preg_match('/^\./', $cache_ext)) {
148
+                $cache_ext = '.' . $cache_ext;
149
+            }
150
+            $this->cache_ext = $cache_ext;
151
+        }
152
+
153
+        // Call parent restart method but don't run setup yet!
154
+        parent::restart($file, $tpldir, $files, $mainblock, false, $tag_start, $tag_end);
155
+
156
+        if ($this->cache_expiry > 0) {
157
+            $this->read_template_cache();
158
+        }
159
+
160
+        if (!$this->_template_is_cached && $autosetup) {
161
+            $this->setup();
162
+        }
163
+    }
164
+
165
+    /**
166
+     * Override of parent assign method
167
+     *
168
+     * @access public
169 169
      * @param string $name Variable to assign $val to
170 170
      * @param string / array $val Value to assign to $name
171
-	 * @param boolean $magic_quotes
172
-	 */
173
-	public function assign ($name, $val = '', $magic_quotes = false) {
174
-
175
-		if (!$this->_template_is_cached) {
176
-			parent::assign($name, $val, $magic_quotes);
177
-		}
178
-	}
179
-
180
-	/**
181
-	 * Override of parent assign_file method
182
-	 *
171
+     * @param boolean $magic_quotes
172
+     */
173
+    public function assign ($name, $val = '', $magic_quotes = false) {
174
+
175
+        if (!$this->_template_is_cached) {
176
+            parent::assign($name, $val, $magic_quotes);
177
+        }
178
+    }
179
+
180
+    /**
181
+     * Override of parent assign_file method
182
+     *
183 183
      * @access public
184 184
      * @param string $name Variable to assign $val to
185 185
      * @param string / array $val Values to assign to $name
186
-	 */
187
-	public function assign_file ($name, $val = '') {
186
+     */
187
+    public function assign_file ($name, $val = '') {
188 188
 
189
-		if (!$this->_template_is_cached) {
190
-			parent::assign_file($name, $val);
191
-		}
192
-	}
189
+        if (!$this->_template_is_cached) {
190
+            parent::assign_file($name, $val);
191
+        }
192
+    }
193 193
 
194
-	/**
195
-	 * Override of parent parse method
196
-	 *
194
+    /**
195
+     * Override of parent parse method
196
+     *
197 197
      * @access public
198 198
      * @param string $bname Block name to parse
199
-	 * @param int $cache_expiry Seconds to cache block for
200
-	 */
201
-	public function parse ($bname, $cache_expiry = 0) {
199
+     * @param int $cache_expiry Seconds to cache block for
200
+     */
201
+    public function parse ($bname, $cache_expiry = 0) {
202 202
 
203
-		if (!$this->_template_is_cached) {
203
+        if (!$this->_template_is_cached) {
204 204
 
205
-			if (!$this->read_block_cache($bname, $cache_expiry)) {
205
+            if (!$this->read_block_cache($bname, $cache_expiry)) {
206 206
 
207
-				parent::parse($bname);
207
+                parent::parse($bname);
208 208
 
209
-				$this->write_block_cache($bname, $cache_expiry);
210
-			}
211
-		}
212
-	}
209
+                $this->write_block_cache($bname, $cache_expiry);
210
+            }
211
+        }
212
+    }
213 213
 
214
-	/**
215
-	 * Override of parent text method
216
-	 *
214
+    /**
215
+     * Override of parent text method
216
+     *
217 217
      * @access public
218 218
      * @param string $bname Block name to return
219 219
      * @return string
220
-	 */
221
-	public function text ($bname = '') {
220
+     */
221
+    public function text ($bname = '') {
222 222
 
223
-		$text = parent::text($bname);
223
+        $text = parent::text($bname);
224 224
 
225
-		if (!$this->_template_is_cached && $this->cache_expiry > 0) {
225
+        if (!$this->_template_is_cached && $this->cache_expiry > 0) {
226 226
 
227
-			$this->write_template_cache();
227
+            $this->write_template_cache();
228 228
 
229
-		} elseif ($this->debug && $this->output_type == 'HTML') {
229
+        } elseif ($this->debug && $this->output_type == 'HTML') {
230 230
 
231
-			$text_header = "<!-- CachingXTemplate debug:\n";
231
+            $text_header = "<!-- CachingXTemplate debug:\n";
232 232
 
233
-			if ($this->cache_expiry > 0) {
233
+            if ($this->cache_expiry > 0) {
234 234
 
235
-				$filename = $this->_get_filename();
235
+                $filename = $this->_get_filename();
236 236
 
237
-				$file = $this->cache_dir . DIRECTORY_SEPARATOR . $filename . $this->cache_unique . $this->cache_ext;
237
+                $file = $this->cache_dir . DIRECTORY_SEPARATOR . $filename . $this->cache_unique . $this->cache_ext;
238 238
 
239
-				$text_header .= 'File: ' . $file . "\nExpires in: " . ($this->_cache_filemtime - $this->_cache_expiry) . " seconds -->\n";
240
-			} else {
241
-				$text_header .= "Template Cache (whole template) disabled -->\n";
242
-			}
239
+                $text_header .= 'File: ' . $file . "\nExpires in: " . ($this->_cache_filemtime - $this->_cache_expiry) . " seconds -->\n";
240
+            } else {
241
+                $text_header .= "Template Cache (whole template) disabled -->\n";
242
+            }
243 243
 
244
-			$text = $text_header . $text;
245
-		}
244
+            $text = $text_header . $text;
245
+        }
246 246
 
247
-		return $text;
248
-	}
247
+        return $text;
248
+    }
249 249
 
250
-	/**
251
-	 * Read whole template cache file
252
-	 *
253
-	 * @access protected
254
-	 */
255
-	protected function read_template_cache () {
250
+    /**
251
+     * Read whole template cache file
252
+     *
253
+     * @access protected
254
+     */
255
+    protected function read_template_cache () {
256 256
 
257
-		$filename = $this->_get_filename();
257
+        $filename = $this->_get_filename();
258 258
 
259
-		$file = $this->cache_dir . DIRECTORY_SEPARATOR . $filename . DIRECTORY_SEPARATOR . $this->cache_unique . $this->cache_ext;
259
+        $file = $this->cache_dir . DIRECTORY_SEPARATOR . $filename . DIRECTORY_SEPARATOR . $this->cache_unique . $this->cache_ext;
260 260
 
261
-		if ($this->cache_expiry > 0 && file_exists($file)) {
261
+        if ($this->cache_expiry > 0 && file_exists($file)) {
262 262
 
263
-			$this->_cache_filemtime = filemtime($file);
264
-			$this->_cache_expiry = time() - $this->cache_expiry;
263
+            $this->_cache_filemtime = filemtime($file);
264
+            $this->_cache_expiry = time() - $this->cache_expiry;
265 265
 
266
-			if ($this->_cache_filemtime >= $this->_cache_expiry) {
267
-				if ($parsed_blocks = file_get_contents($file)) {
268
-					$this->parsed_blocks = unserialize($parsed_blocks);
269
-					$this->_template_is_cached = true;
270
-				}
271
-			} else {
272
-				// Stale file
273
-				if (is_writable($this->cache_dir) && is_writable($file)) {
274
-					unlink($file);
275
-				}
276
-			}
277
-		}
278
-	}
266
+            if ($this->_cache_filemtime >= $this->_cache_expiry) {
267
+                if ($parsed_blocks = file_get_contents($file)) {
268
+                    $this->parsed_blocks = unserialize($parsed_blocks);
269
+                    $this->_template_is_cached = true;
270
+                }
271
+            } else {
272
+                // Stale file
273
+                if (is_writable($this->cache_dir) && is_writable($file)) {
274
+                    unlink($file);
275
+                }
276
+            }
277
+        }
278
+    }
279 279
 
280
-	/**
281
-	 * Write out whole template cache file
282
-	 *
283
-	 * @access protected
284
-	 */
285
-	protected function write_template_cache () {
280
+    /**
281
+     * Write out whole template cache file
282
+     *
283
+     * @access protected
284
+     */
285
+    protected function write_template_cache () {
286 286
 
287
-		if ($this->cache_expiry > 0 && is_writable($this->cache_dir)) {
287
+        if ($this->cache_expiry > 0 && is_writable($this->cache_dir)) {
288 288
 
289
-			$filename = $this->_get_filename();
289
+            $filename = $this->_get_filename();
290 290
 
291
-			if (!file_exists($this->cache_dir . DIRECTORY_SEPARATOR . $filename)) {
292
-				mkdir($this->cache_dir . DIRECTORY_SEPARATOR . $filename);
293
-			}
291
+            if (!file_exists($this->cache_dir . DIRECTORY_SEPARATOR . $filename)) {
292
+                mkdir($this->cache_dir . DIRECTORY_SEPARATOR . $filename);
293
+            }
294 294
 
295
-			file_put_contents($this->cache_dir . DIRECTORY_SEPARATOR . $filename . DIRECTORY_SEPARATOR . $this->cache_unique . $this->cache_ext, serialize($this->parsed_blocks));
296
-		}
297
-	}
295
+            file_put_contents($this->cache_dir . DIRECTORY_SEPARATOR . $filename . DIRECTORY_SEPARATOR . $this->cache_unique . $this->cache_ext, serialize($this->parsed_blocks));
296
+        }
297
+    }
298 298
 
299
-	/**
300
-	 * Read block level cache file
301
-	 *
302
-	 * @access protected
303
-	 * @param string $bname Block name to read from cache
304
-	 * @param ing $cache_expiry Seconds to cache block for
305
-	 * @return boolean
306
-	 */
307
-	protected function read_block_cache ($bname, $cache_expiry = 0) {
299
+    /**
300
+     * Read block level cache file
301
+     *
302
+     * @access protected
303
+     * @param string $bname Block name to read from cache
304
+     * @param ing $cache_expiry Seconds to cache block for
305
+     * @return boolean
306
+     */
307
+    protected function read_block_cache ($bname, $cache_expiry = 0) {
308 308
 
309
-		$retval = false;
309
+        $retval = false;
310 310
 
311
-		$filename = $this->_get_filename();
311
+        $filename = $this->_get_filename();
312 312
 
313
-		$file = $this->cache_dir . DIRECTORY_SEPARATOR . $filename . DIRECTORY_SEPARATOR . $bname . $this->cache_unique . $this->cache_ext;
313
+        $file = $this->cache_dir . DIRECTORY_SEPARATOR . $filename . DIRECTORY_SEPARATOR . $bname . $this->cache_unique . $this->cache_ext;
314
+
315
+        if ($cache_expiry > 0 && file_exists($file)) {
316
+
317
+            $filemtime = filemtime($file);
318
+            $cache_expiry = time() - $cache_expiry;
319
+
320
+            if ($filemtime >= $cache_expiry) {
321
+                if ($block = file_get_contents($file)) {
322
+                    $block = unserialize($block);
323
+                    if ($this->debug) {
324
+                        $block = "<!-- CachingXTemplate debug:\nFile: " . $file . "\nBlock: " . $bname . "\nExpires in: " . ($filemtime - $cache_expiry) . ' seconds -->' . "\n" . $block;
325
+                    }
326
+                    $this->parsed_blocks[$bname] = $block;
327
+                    $retval = true;
328
+                }
329
+            } else {
330
+                // Stale file
331
+                if (is_writable($this->cache_dir) && is_writable($file)) {
332
+                    unlink($file);
333
+                }
334
+            }
335
+        }
336
+
337
+        return $retval;
338
+    }
339
+
340
+    /**
341
+     * Write out block level cache file
342
+     *
343
+     * @access protected
344
+     * @param string $bname Block name to cache
345
+     * @param int $cache_expiry Seconds to cache block for
346
+     */
347
+    protected function write_block_cache ($bname, $cache_expiry = 0) {
348
+
349
+        if ($cache_expiry > 0 && is_writable($this->cache_dir)) {
350
+
351
+            $filename = $this->_get_filename();
352
+
353
+            if (!file_exists($this->cache_dir . DIRECTORY_SEPARATOR . $filename)) {
354
+                mkdir($this->cache_dir . DIRECTORY_SEPARATOR . $filename);
355
+            }
356
+
357
+            file_put_contents($this->cache_dir . DIRECTORY_SEPARATOR . $filename . DIRECTORY_SEPARATOR . $bname . $this->cache_unique . $this->cache_ext, serialize($this->parsed_blocks[$bname]));
358
+        }
359
+    }
360
+
361
+    /**
362
+     * Create the main part of the cache filename
363
+     *
364
+     * @access private
365
+     * @return string
366
+     */
367
+    private function _get_filename () {
314 368
 
315
-		if ($cache_expiry > 0 && file_exists($file)) {
369
+        $filename = $this->filename;
370
+        if (!empty($this->tpldir)) {
316 371
 
317
-			$filemtime = filemtime($file);
318
-			$cache_expiry = time() - $cache_expiry;
372
+            $filename = str_replace(DIRECTORY_SEPARATOR, '_', $this->tpldir . DIRECTORY_SEPARATOR) . $this->filename;
373
+        }
319 374
 
320
-			if ($filemtime >= $cache_expiry) {
321
-				if ($block = file_get_contents($file)) {
322
-					$block = unserialize($block);
323
-					if ($this->debug) {
324
-						$block = "<!-- CachingXTemplate debug:\nFile: " . $file . "\nBlock: " . $bname . "\nExpires in: " . ($filemtime - $cache_expiry) . ' seconds -->' . "\n" . $block;
325
-					}
326
-					$this->parsed_blocks[$bname] = $block;
327
-					$retval = true;
328
-				}
329
-			} else {
330
-				// Stale file
331
-				if (is_writable($this->cache_dir) && is_writable($file)) {
332
-					unlink($file);
333
-				}
334
-			}
335
-		}
336
-
337
-		return $retval;
338
-	}
339
-
340
-	/**
341
-	 * Write out block level cache file
342
-	 *
343
-	 * @access protected
344
-	 * @param string $bname Block name to cache
345
-	 * @param int $cache_expiry Seconds to cache block for
346
-	 */
347
-	protected function write_block_cache ($bname, $cache_expiry = 0) {
348
-
349
-		if ($cache_expiry > 0 && is_writable($this->cache_dir)) {
350
-
351
-			$filename = $this->_get_filename();
352
-
353
-			if (!file_exists($this->cache_dir . DIRECTORY_SEPARATOR . $filename)) {
354
-				mkdir($this->cache_dir . DIRECTORY_SEPARATOR . $filename);
355
-			}
356
-
357
-			file_put_contents($this->cache_dir . DIRECTORY_SEPARATOR . $filename . DIRECTORY_SEPARATOR . $bname . $this->cache_unique . $this->cache_ext, serialize($this->parsed_blocks[$bname]));
358
-		}
359
-	}
360
-
361
-	/**
362
-	 * Create the main part of the cache filename
363
-	 *
364
-	 * @access private
365
-	 * @return string
366
-	 */
367
-	private function _get_filename () {
368
-
369
-		$filename = $this->filename;
370
-		if (!empty($this->tpldir)) {
371
-
372
-			$filename = str_replace(DIRECTORY_SEPARATOR, '_', $this->tpldir . DIRECTORY_SEPARATOR) . $this->filename;
373
-		}
374
-
375
-		return $filename;
376
-	}
375
+        return $filename;
376
+    }
377 377
 }
378 378
 
379 379
 ?>
380 380
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	 * @access public
37 37
 	 * @var int
38 38
 	 */
39
-	public $cache_expiry	= 0;
39
+	public $cache_expiry = 0;
40 40
 
41 41
 	/**
42 42
 	 * Cache file unique identifier
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 	 * @access public
46 46
 	 * @var string
47 47
 	 */
48
-	public $cache_unique	= 'unique';
48
+	public $cache_unique = 'unique';
49 49
 
50 50
 	/**
51 51
 	 * Filename extension
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 	 * @access public
55 55
 	 * @var string
56 56
 	 */
57
-	public $cache_ext		= '.xcache';
57
+	public $cache_ext = '.xcache';
58 58
 
59 59
 	/**
60 60
 	 * Path to cache dir
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	 * @access public
65 65
 	 * @var string
66 66
 	 */
67
-	public $cache_dir		= './xcache';
67
+	public $cache_dir = './xcache';
68 68
 
69 69
 	/**
70 70
 	 * Flag showing whether template is cached
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 	 * @access private
73 73
 	 * @var boolean
74 74
 	 */
75
-	private $_template_is_cached	= false;
75
+	private $_template_is_cached = false;
76 76
 
77 77
 	/**
78 78
 	 * Cache expiry time
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 	 * @access private
81 81
 	 * @var int
82 82
 	 */
83
-	private $_cache_expiry			= 0;
83
+	private $_cache_expiry = 0;
84 84
 
85 85
 	/**
86 86
 	 * File modified time
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 	 * @access private
89 89
 	 * @var int
90 90
 	 */
91
-	private $_cache_filemtime		= 0;
91
+	private $_cache_filemtime = 0;
92 92
 
93 93
 	/**
94 94
 	 * Override of parent constructor
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 	 * @param string $cache_dir Cache folder
127 127
 	 * @param string $cache_ext Cache file extension
128 128
 	 */
129
-	public function restart ($file, $tpldir = '', $files = null, $mainblock = 'main', $autosetup = true, $tag_start = '{', $tag_end = '}', $cache_expiry = 0, $cache_unique = '', $cache_dir = './xcache', $cache_ext = '.xcache') {
129
+	public function restart($file, $tpldir = '', $files = null, $mainblock = 'main', $autosetup = true, $tag_start = '{', $tag_end = '}', $cache_expiry = 0, $cache_unique = '', $cache_dir = './xcache', $cache_ext = '.xcache') {
130 130
 
131 131
 		if ($cache_expiry > 0) {
132 132
 			$this->cache_expiry = $cache_expiry;
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
      * @param string / array $val Value to assign to $name
171 171
 	 * @param boolean $magic_quotes
172 172
 	 */
173
-	public function assign ($name, $val = '', $magic_quotes = false) {
173
+	public function assign($name, $val = '', $magic_quotes = false) {
174 174
 
175 175
 		if (!$this->_template_is_cached) {
176 176
 			parent::assign($name, $val, $magic_quotes);
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
      * @param string $name Variable to assign $val to
185 185
      * @param string / array $val Values to assign to $name
186 186
 	 */
187
-	public function assign_file ($name, $val = '') {
187
+	public function assign_file($name, $val = '') {
188 188
 
189 189
 		if (!$this->_template_is_cached) {
190 190
 			parent::assign_file($name, $val);
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
      * @param string $bname Block name to parse
199 199
 	 * @param int $cache_expiry Seconds to cache block for
200 200
 	 */
201
-	public function parse ($bname, $cache_expiry = 0) {
201
+	public function parse($bname, $cache_expiry = 0) {
202 202
 
203 203
 		if (!$this->_template_is_cached) {
204 204
 
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
      * @param string $bname Block name to return
219 219
      * @return string
220 220
 	 */
221
-	public function text ($bname = '') {
221
+	public function text($bname = '') {
222 222
 
223 223
 		$text = parent::text($bname);
224 224
 
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 	 *
253 253
 	 * @access protected
254 254
 	 */
255
-	protected function read_template_cache () {
255
+	protected function read_template_cache() {
256 256
 
257 257
 		$filename = $this->_get_filename();
258 258
 
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 	 *
283 283
 	 * @access protected
284 284
 	 */
285
-	protected function write_template_cache () {
285
+	protected function write_template_cache() {
286 286
 
287 287
 		if ($this->cache_expiry > 0 && is_writable($this->cache_dir)) {
288 288
 
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
 	 * @param ing $cache_expiry Seconds to cache block for
305 305
 	 * @return boolean
306 306
 	 */
307
-	protected function read_block_cache ($bname, $cache_expiry = 0) {
307
+	protected function read_block_cache($bname, $cache_expiry = 0) {
308 308
 
309 309
 		$retval = false;
310 310
 
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 	 * @param string $bname Block name to cache
345 345
 	 * @param int $cache_expiry Seconds to cache block for
346 346
 	 */
347
-	protected function write_block_cache ($bname, $cache_expiry = 0) {
347
+	protected function write_block_cache($bname, $cache_expiry = 0) {
348 348
 
349 349
 		if ($cache_expiry > 0 && is_writable($this->cache_dir)) {
350 350
 
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
 	 * @access private
365 365
 	 * @return string
366 366
 	 */
367
-	private function _get_filename () {
367
+	private function _get_filename() {
368 368
 
369 369
 		$filename = $this->filename;
370 370
 		if (!empty($this->tpldir)) {
Please login to merge, or discard this patch.
system/packages/com.jukusoft.cms.xtpl/xtpl/xtemplate.class.php 2 patches
Indentation   +889 added lines, -889 removed lines patch added patch discarded remove patch
@@ -24,288 +24,288 @@  discard block
 block discarded – undo
24 24
  */
25 25
 class XTemplate {
26 26
 
27
-	/**
28
-	 * Properties
29
-	 */
30
-
31
-	/**
32
-	 * Raw contents of the template file
33
-	 *
34
-	 * @access public
35
-	 * @var string
36
-	 */
37
-	public $filecontents = '';
38
-
39
-	/**
40
-	 * Unparsed blocks
41
-	 *
42
-	 * @access public
43
-	 * @var array
44
-	 */
45
-	public $blocks = array();
46
-
47
-	/**
48
-	 * Parsed blocks
49
-	 *
50
-	 * @var unknown_type
51
-	 */
52
-	public $parsed_blocks = array();
53
-
54
-	/**
55
-	 * Preparsed blocks (for file includes)
56
-	 *
57
-	 * @access public
58
-	 * @var array
59
-	 */
60
-	public $preparsed_blocks = array();
61
-
62
-	/**
63
-	 * Block parsing order for recursive parsing
64
-	 * (Sometimes reverse :)
65
-	 *
66
-	 * @access public
67
-	 * @var array
68
-	 */
69
-	public $block_parse_order = array();
70
-
71
-	/**
72
-	 * Store sub-block names
73
-	 * (For fast resetting)
74
-	 *
75
-	 * @access public
76
-	 * @var array
77
-	 */
78
-	public $sub_blocks = array();
79
-
80
-	/**
81
-	 * Variables array
82
-	 *
83
-	 * @access public
84
-	 * @var array
85
-	 */
86
-	public $vars = array();
87
-
88
-	/**
89
-	 * File variables array
90
-	 *
91
-	 * @access public
92
-	 * @var array
93
-	 */
94
-	public $filevars = array();
95
-
96
-	/**
97
-	 * Filevars' parent block
98
-	 *
99
-	 * @access public
100
-	 * @var array
101
-	 */
102
-	public $filevar_parent = array();
103
-
104
-	/**
105
-	 * File caching during duration of script
106
-	 * e.g. files only cached to speed {FILE "filename"} repeats
107
-	 *
108
-	 * @access public
109
-	 * @var array
110
-	 */
111
-	public $filecache = array();
112
-
113
-	/**
114
-	 * Location of template files
115
-	 *
116
-	 * @access public
117
-	 * @var string
118
-	 */
119
-	public $tpldir = '';
120
-
121
-	/**
122
-	 * Filenames lookup table
123
-	 *
124
-	 * @access public
125
-	 * @var null
126
-	 */
127
-	public $files = null;
128
-
129
-	/**
130
-	 * Template filename
131
-	 *
132
-	 * @access public
133
-	 * @var string
134
-	 */
135
-	public $filename = '';
136
-
137
-	// moved to setup method so uses the tag_start & end_delims
138
-	/**
139
-	 * RegEx for file includes
140
-	 *
141
-	 * "/\{FILE\s*\"([^\"]+)\"\s*\}/m";
142
-	 *
143
-	 * @access public
144
-	 * @var string
145
-	 */
146
-	public $file_delim = '';
147
-
148
-	/**
149
-	 * RegEx for file include variable
150
-	 *
151
-	 * "/\{FILE\s*\{([A-Za-z0-9\._]+?)\}\s*\}/m";
152
-	 *
153
-	 * @access public
154
-	 * @var string
155
-	 */
156
-	public $filevar_delim = '';
157
-
158
-	/**
159
-	 * RegEx for file includes with newlines
160
-	 *
161
-	 * "/^\s*\{FILE\s*\{([A-Za-z0-9\._]+?)\}\s*\}\s*\n/m";
162
-	 *
163
-	 * @access public
164
-	 * @var string
165
-	 */
166
-	public $filevar_delim_nl = '';
167
-
168
-	/**
169
-	 * Template block start delimiter
170
-	 *
171
-	 * @access public
172
-	 * @var string
173
-	 */
174
-	public $block_start_delim = '<!-- ';
175
-
176
-	/**
177
-	 * Template block end delimiter
178
-	 *
179
-	 * @access public
180
-	 * @var string
181
-	 */
182
-	public $block_end_delim = '-->';
183
-
184
-	/**
185
-	 * Template block start word
186
-	 *
187
-	 * @access public
188
-	 * @var string
189
-	 */
190
-	public $block_start_word = 'BEGIN:';
191
-
192
-	/**
193
-	 * Template block end word
194
-	 *
195
-	 * The last 3 properties and this make the delimiters look like:
196
-	 * @example <!-- BEGIN: block_name -->
197
-	 * if you use the default syntax.
198
-	 *
199
-	 * @access public
200
-	 * @var string
201
-	 */
202
-	public $block_end_word = 'END:';
203
-
204
-	/**
205
-	 * Template tag start delimiter
206
-	 *
207
-	 * This makes the delimiters look like:
208
-	 * @example {tagname}
209
-	 * if you use the default syntax.
210
-	 *
211
-	 * @access public
212
-	 * @var string
213
-	 */
214
-	public $tag_start_delim = '{';
215
-
216
-	/**
217
-	 * Template tag end delimiter
218
-	 *
219
-	 * This makes the delimiters look like:
220
-	 * @example {tagname}
221
-	 * if you use the default syntax.
222
-	 *
223
-	 * @access public
224
-	 * @var string
225
-	 */
226
-	public $tag_end_delim = '}';
227
-	/* this makes the delimiters look like: {tagname} if you use my syntax. */
228
-
229
-	/**
230
-	 * Regular expression element for comments within tags and blocks
231
-	 *
232
-	 * @example {tagname#My Comment}
233
-	 * @example {tagname #My Comment}
234
-	 * @example <!-- BEGIN: blockname#My Comment -->
235
-	 * @example <!-- BEGIN: blockname #My Comment -->
236
-	 *
237
-	 * @access public
238
-	 * @var string
239
-	 */
240
-	public $comment_preg = '( ?#.*?)?';
241
-
242
-	/**
243
-	 * Default main template block name
244
-	 *
245
-	 * @access public
246
-	 * @var string
247
-	 */
248
-	public $mainblock = 'main';
249
-
250
-	/**
251
-	 * Script output type
252
-	 *
253
-	 * @access public
254
-	 * @var string
255
-	 */
256
-	public $output_type = 'HTML';
257
-
258
-	/**
259
-	 * Debug mode
260
-	 *
261
-	 * @access public
262
-	 * @var boolean
263
-	 */
264
-	public $debug = false;
265
-
266
-	/**
267
-	 * Null string for unassigned vars
268
-	 *
269
-	 * @access protected
270
-	 * @var array
271
-	 */
272
-	protected $_null_string = array('' => '');
273
-
274
-	/**
275
-	 * Null string for unassigned blocks
276
-	 *
277
-	 * @access protected
278
-	 * @var array
279
-	 */
280
-	protected $_null_block = array('' => '');
281
-
282
-	/**
283
-	 * Errors
284
-	 *
285
-	 * @access protected
286
-	 * @var string
287
-	 */
288
-	protected $_error = '';
289
-
290
-	/**
291
-	 * Auto-reset sub blocks
292
-	 *
293
-	 * @access protected
294
-	 * @var boolean
295
-	 */
296
-	protected $_autoreset = true;
297
-
298
-	/**
299
-	 * Set to FALSE to generate errors if a non-existant blocks is referenced
300
-	 *
301
-	 * @author NW
302
-	 * @since 2002/10/17
303
-	 * @access protected
304
-	 * @var boolean
305
-	 */
306
-	protected $_ignore_missing_blocks = true;
307
-
308
-	/**
27
+    /**
28
+     * Properties
29
+     */
30
+
31
+    /**
32
+     * Raw contents of the template file
33
+     *
34
+     * @access public
35
+     * @var string
36
+     */
37
+    public $filecontents = '';
38
+
39
+    /**
40
+     * Unparsed blocks
41
+     *
42
+     * @access public
43
+     * @var array
44
+     */
45
+    public $blocks = array();
46
+
47
+    /**
48
+     * Parsed blocks
49
+     *
50
+     * @var unknown_type
51
+     */
52
+    public $parsed_blocks = array();
53
+
54
+    /**
55
+     * Preparsed blocks (for file includes)
56
+     *
57
+     * @access public
58
+     * @var array
59
+     */
60
+    public $preparsed_blocks = array();
61
+
62
+    /**
63
+     * Block parsing order for recursive parsing
64
+     * (Sometimes reverse :)
65
+     *
66
+     * @access public
67
+     * @var array
68
+     */
69
+    public $block_parse_order = array();
70
+
71
+    /**
72
+     * Store sub-block names
73
+     * (For fast resetting)
74
+     *
75
+     * @access public
76
+     * @var array
77
+     */
78
+    public $sub_blocks = array();
79
+
80
+    /**
81
+     * Variables array
82
+     *
83
+     * @access public
84
+     * @var array
85
+     */
86
+    public $vars = array();
87
+
88
+    /**
89
+     * File variables array
90
+     *
91
+     * @access public
92
+     * @var array
93
+     */
94
+    public $filevars = array();
95
+
96
+    /**
97
+     * Filevars' parent block
98
+     *
99
+     * @access public
100
+     * @var array
101
+     */
102
+    public $filevar_parent = array();
103
+
104
+    /**
105
+     * File caching during duration of script
106
+     * e.g. files only cached to speed {FILE "filename"} repeats
107
+     *
108
+     * @access public
109
+     * @var array
110
+     */
111
+    public $filecache = array();
112
+
113
+    /**
114
+     * Location of template files
115
+     *
116
+     * @access public
117
+     * @var string
118
+     */
119
+    public $tpldir = '';
120
+
121
+    /**
122
+     * Filenames lookup table
123
+     *
124
+     * @access public
125
+     * @var null
126
+     */
127
+    public $files = null;
128
+
129
+    /**
130
+     * Template filename
131
+     *
132
+     * @access public
133
+     * @var string
134
+     */
135
+    public $filename = '';
136
+
137
+    // moved to setup method so uses the tag_start & end_delims
138
+    /**
139
+     * RegEx for file includes
140
+     *
141
+     * "/\{FILE\s*\"([^\"]+)\"\s*\}/m";
142
+     *
143
+     * @access public
144
+     * @var string
145
+     */
146
+    public $file_delim = '';
147
+
148
+    /**
149
+     * RegEx for file include variable
150
+     *
151
+     * "/\{FILE\s*\{([A-Za-z0-9\._]+?)\}\s*\}/m";
152
+     *
153
+     * @access public
154
+     * @var string
155
+     */
156
+    public $filevar_delim = '';
157
+
158
+    /**
159
+     * RegEx for file includes with newlines
160
+     *
161
+     * "/^\s*\{FILE\s*\{([A-Za-z0-9\._]+?)\}\s*\}\s*\n/m";
162
+     *
163
+     * @access public
164
+     * @var string
165
+     */
166
+    public $filevar_delim_nl = '';
167
+
168
+    /**
169
+     * Template block start delimiter
170
+     *
171
+     * @access public
172
+     * @var string
173
+     */
174
+    public $block_start_delim = '<!-- ';
175
+
176
+    /**
177
+     * Template block end delimiter
178
+     *
179
+     * @access public
180
+     * @var string
181
+     */
182
+    public $block_end_delim = '-->';
183
+
184
+    /**
185
+     * Template block start word
186
+     *
187
+     * @access public
188
+     * @var string
189
+     */
190
+    public $block_start_word = 'BEGIN:';
191
+
192
+    /**
193
+     * Template block end word
194
+     *
195
+     * The last 3 properties and this make the delimiters look like:
196
+     * @example <!-- BEGIN: block_name -->
197
+     * if you use the default syntax.
198
+     *
199
+     * @access public
200
+     * @var string
201
+     */
202
+    public $block_end_word = 'END:';
203
+
204
+    /**
205
+     * Template tag start delimiter
206
+     *
207
+     * This makes the delimiters look like:
208
+     * @example {tagname}
209
+     * if you use the default syntax.
210
+     *
211
+     * @access public
212
+     * @var string
213
+     */
214
+    public $tag_start_delim = '{';
215
+
216
+    /**
217
+     * Template tag end delimiter
218
+     *
219
+     * This makes the delimiters look like:
220
+     * @example {tagname}
221
+     * if you use the default syntax.
222
+     *
223
+     * @access public
224
+     * @var string
225
+     */
226
+    public $tag_end_delim = '}';
227
+    /* this makes the delimiters look like: {tagname} if you use my syntax. */
228
+
229
+    /**
230
+     * Regular expression element for comments within tags and blocks
231
+     *
232
+     * @example {tagname#My Comment}
233
+     * @example {tagname #My Comment}
234
+     * @example <!-- BEGIN: blockname#My Comment -->
235
+     * @example <!-- BEGIN: blockname #My Comment -->
236
+     *
237
+     * @access public
238
+     * @var string
239
+     */
240
+    public $comment_preg = '( ?#.*?)?';
241
+
242
+    /**
243
+     * Default main template block name
244
+     *
245
+     * @access public
246
+     * @var string
247
+     */
248
+    public $mainblock = 'main';
249
+
250
+    /**
251
+     * Script output type
252
+     *
253
+     * @access public
254
+     * @var string
255
+     */
256
+    public $output_type = 'HTML';
257
+
258
+    /**
259
+     * Debug mode
260
+     *
261
+     * @access public
262
+     * @var boolean
263
+     */
264
+    public $debug = false;
265
+
266
+    /**
267
+     * Null string for unassigned vars
268
+     *
269
+     * @access protected
270
+     * @var array
271
+     */
272
+    protected $_null_string = array('' => '');
273
+
274
+    /**
275
+     * Null string for unassigned blocks
276
+     *
277
+     * @access protected
278
+     * @var array
279
+     */
280
+    protected $_null_block = array('' => '');
281
+
282
+    /**
283
+     * Errors
284
+     *
285
+     * @access protected
286
+     * @var string
287
+     */
288
+    protected $_error = '';
289
+
290
+    /**
291
+     * Auto-reset sub blocks
292
+     *
293
+     * @access protected
294
+     * @var boolean
295
+     */
296
+    protected $_autoreset = true;
297
+
298
+    /**
299
+     * Set to FALSE to generate errors if a non-existant blocks is referenced
300
+     *
301
+     * @author NW
302
+     * @since 2002/10/17
303
+     * @access protected
304
+     * @var boolean
305
+     */
306
+    protected $_ignore_missing_blocks = true;
307
+
308
+    /**
309 309
      * PHP 5 Constructor - Instantiate the object
310 310
      *
311 311
      * @param string $file Template file to work on
@@ -315,12 +315,12 @@  discard block
 block discarded – undo
315 315
      * @param boolean $autosetup If true, run setup() as part of constuctor
316 316
      * @return XTemplate
317 317
      */
318
-	public function __construct($file, $tpldir = '', $files = null, $mainblock = 'main', $autosetup = true) {
318
+    public function __construct($file, $tpldir = '', $files = null, $mainblock = 'main', $autosetup = true) {
319 319
 
320
-		$this->restart($file, $tpldir, $files, $mainblock, $autosetup, $this->tag_start_delim, $this->tag_end_delim);
321
-	}
320
+        $this->restart($file, $tpldir, $files, $mainblock, $autosetup, $this->tag_start_delim, $this->tag_end_delim);
321
+    }
322 322
 
323
-	/**
323
+    /**
324 324
      * PHP 4 Constructor - Instantiate the object
325 325
      *
326 326
      * @deprecated Use PHP 5 constructor instead
@@ -331,111 +331,111 @@  discard block
 block discarded – undo
331 331
      * @param boolean $autosetup If true, run setup() as part of constuctor
332 332
      * @return XTemplate
333 333
      */
334
-	public function XTemplate ($file, $tpldir = '', $files = null, $mainblock = 'main', $autosetup = true) {
335
-
336
-		assert('Deprecated - use PHP 5 constructor');
337
-	}
338
-
339
-
340
-	/***************************************************************************/
341
-	/***[ public stuff ]********************************************************/
342
-	/***************************************************************************/
343
-
344
-	/**
345
-	 * Restart the class - allows one instantiation with several files processed by restarting
346
-	 * e.g. $xtpl = new XTemplate('file1.xtpl');
347
-	 * $xtpl->parse('main');
348
-	 * $xtpl->out('main');
349
-	 * $xtpl->restart('file2.xtpl');
350
-	 * $xtpl->parse('main');
351
-	 * $xtpl->out('main');
352
-	 * (Added in response to sf:641407 feature request)
353
-	 *
354
-	 * @param string $file Template file to work on
355
-	 * @param string/array $tpldir Location of template files
356
-	 * @param array $files Filenames lookup
357
-	 * @param string $mainblock Name of main block in the template
358
-	 * @param boolean $autosetup If true, run setup() as part of restarting
359
-	 * @param string $tag_start {
360
-	 * @param string $tag_end }
361
-	 */
362
-	public function restart ($file, $tpldir = '', $files = null, $mainblock = 'main', $autosetup = true, $tag_start = '{', $tag_end = '}') {
363
-
364
-		$this->filename = $file;
365
-
366
-		// From SF Feature request 1202027
367
-		// Kenneth Kalmer
368
-		$this->tpldir = $tpldir;
369
-		if (defined('XTPL_DIR') && empty($this->tpldir)) {
370
-			$this->tpldir = XTPL_DIR;
371
-		}
372
-
373
-		if (is_array($files)) {
374
-			$this->files = $files;
375
-		}
376
-
377
-		$this->mainblock = $mainblock;
378
-
379
-		$this->tag_start_delim = $tag_start;
380
-		$this->tag_end_delim = $tag_end;
381
-
382
-		// Start with fresh file contents
383
-		$this->filecontents = '';
384
-
385
-		// Reset the template arrays
386
-		$this->blocks = array();
387
-		$this->parsed_blocks = array();
388
-		$this->preparsed_blocks = array();
389
-		$this->block_parse_order = array();
390
-		$this->sub_blocks = array();
391
-		$this->vars = array();
392
-		$this->filevars = array();
393
-		$this->filevar_parent = array();
394
-		$this->filecache = array();
395
-
396
-		if ($autosetup) {
397
-			$this->setup();
398
-		}
399
-	}
400
-
401
-	/**
334
+    public function XTemplate ($file, $tpldir = '', $files = null, $mainblock = 'main', $autosetup = true) {
335
+
336
+        assert('Deprecated - use PHP 5 constructor');
337
+    }
338
+
339
+
340
+    /***************************************************************************/
341
+    /***[ public stuff ]********************************************************/
342
+    /***************************************************************************/
343
+
344
+    /**
345
+     * Restart the class - allows one instantiation with several files processed by restarting
346
+     * e.g. $xtpl = new XTemplate('file1.xtpl');
347
+     * $xtpl->parse('main');
348
+     * $xtpl->out('main');
349
+     * $xtpl->restart('file2.xtpl');
350
+     * $xtpl->parse('main');
351
+     * $xtpl->out('main');
352
+     * (Added in response to sf:641407 feature request)
353
+     *
354
+     * @param string $file Template file to work on
355
+     * @param string/array $tpldir Location of template files
356
+     * @param array $files Filenames lookup
357
+     * @param string $mainblock Name of main block in the template
358
+     * @param boolean $autosetup If true, run setup() as part of restarting
359
+     * @param string $tag_start {
360
+     * @param string $tag_end }
361
+     */
362
+    public function restart ($file, $tpldir = '', $files = null, $mainblock = 'main', $autosetup = true, $tag_start = '{', $tag_end = '}') {
363
+
364
+        $this->filename = $file;
365
+
366
+        // From SF Feature request 1202027
367
+        // Kenneth Kalmer
368
+        $this->tpldir = $tpldir;
369
+        if (defined('XTPL_DIR') && empty($this->tpldir)) {
370
+            $this->tpldir = XTPL_DIR;
371
+        }
372
+
373
+        if (is_array($files)) {
374
+            $this->files = $files;
375
+        }
376
+
377
+        $this->mainblock = $mainblock;
378
+
379
+        $this->tag_start_delim = $tag_start;
380
+        $this->tag_end_delim = $tag_end;
381
+
382
+        // Start with fresh file contents
383
+        $this->filecontents = '';
384
+
385
+        // Reset the template arrays
386
+        $this->blocks = array();
387
+        $this->parsed_blocks = array();
388
+        $this->preparsed_blocks = array();
389
+        $this->block_parse_order = array();
390
+        $this->sub_blocks = array();
391
+        $this->vars = array();
392
+        $this->filevars = array();
393
+        $this->filevar_parent = array();
394
+        $this->filecache = array();
395
+
396
+        if ($autosetup) {
397
+            $this->setup();
398
+        }
399
+    }
400
+
401
+    /**
402 402
      * setup - the elements that were previously in the constructor
403 403
      *
404 404
      * @access public
405 405
      * @param boolean $add_outer If true is passed when called, it adds an outer main block to the file
406 406
      */
407
-	public function setup ($add_outer = false) {
407
+    public function setup ($add_outer = false) {
408 408
 
409
-		$this->tag_start_delim = preg_quote($this->tag_start_delim);
410
-		$this->tag_end_delim = preg_quote($this->tag_end_delim);
409
+        $this->tag_start_delim = preg_quote($this->tag_start_delim);
410
+        $this->tag_end_delim = preg_quote($this->tag_end_delim);
411 411
 
412
-		// Setup the file delimiters
412
+        // Setup the file delimiters
413 413
 
414
-		// regexp for file includes
415
-		$this->file_delim = "/" . $this->tag_start_delim . "FILE\s*\"([^\"]+)\"" . $this->comment_preg . $this->tag_end_delim . "/m";
414
+        // regexp for file includes
415
+        $this->file_delim = "/" . $this->tag_start_delim . "FILE\s*\"([^\"]+)\"" . $this->comment_preg . $this->tag_end_delim . "/m";
416 416
 
417
-		// regexp for file includes
418
-		$this->filevar_delim = "/" . $this->tag_start_delim . "FILE\s*" . $this->tag_start_delim . "([A-Za-z0-9\._]+?)" . $this->comment_preg . $this->tag_end_delim . $this->comment_preg . $this->tag_end_delim . "/m";
417
+        // regexp for file includes
418
+        $this->filevar_delim = "/" . $this->tag_start_delim . "FILE\s*" . $this->tag_start_delim . "([A-Za-z0-9\._]+?)" . $this->comment_preg . $this->tag_end_delim . $this->comment_preg . $this->tag_end_delim . "/m";
419 419
 
420
-		// regexp for file includes w/ newlines
421
-		$this->filevar_delim_nl = "/^\s*" . $this->tag_start_delim . "FILE\s*" . $this->tag_start_delim . "([A-Za-z0-9\._]+?)" . $this->comment_preg . $this->tag_end_delim . $this->comment_preg . $this->tag_end_delim . "\s*\n/m";
420
+        // regexp for file includes w/ newlines
421
+        $this->filevar_delim_nl = "/^\s*" . $this->tag_start_delim . "FILE\s*" . $this->tag_start_delim . "([A-Za-z0-9\._]+?)" . $this->comment_preg . $this->tag_end_delim . $this->comment_preg . $this->tag_end_delim . "\s*\n/m";
422 422
 
423
-		if (empty($this->filecontents)) {
424
-			// read in template file
425
-			$this->filecontents = $this->_r_getfile($this->filename);
426
-		}
423
+        if (empty($this->filecontents)) {
424
+            // read in template file
425
+            $this->filecontents = $this->_r_getfile($this->filename);
426
+        }
427 427
 
428
-		if ($add_outer) {
429
-			$this->_add_outer_block();
430
-		}
428
+        if ($add_outer) {
429
+            $this->_add_outer_block();
430
+        }
431 431
 
432
-		// preprocess some stuff
433
-		$this->blocks = $this->_maketree($this->filecontents, '');
434
-		$this->filevar_parent = $this->_store_filevar_parents($this->blocks);
435
-		$this->scan_globals();
436
-	}
432
+        // preprocess some stuff
433
+        $this->blocks = $this->_maketree($this->filecontents, '');
434
+        $this->filevar_parent = $this->_store_filevar_parents($this->blocks);
435
+        $this->scan_globals();
436
+    }
437 437
 
438
-	/**
438
+    /**
439 439
      * assign a variable
440 440
      *
441 441
      * @example Simplest case:
@@ -459,500 +459,500 @@  discard block
 block discarded – undo
459 459
      * @access public
460 460
      * @param string $name Variable to assign $val to
461 461
      * @param string / array $val Value to assign to $name
462
-	 * @param boolean $reset_array Reset the variable array if $val is an array
462
+     * @param boolean $reset_array Reset the variable array if $val is an array
463 463
      */
464
-	public function assign ($name, $val = '', $reset_array = true) {
464
+    public function assign ($name, $val = '', $reset_array = true) {
465 465
 
466
-		if (is_array($name)) {
466
+        if (is_array($name)) {
467 467
 
468
-			foreach ($name as $k => $v) {
468
+            foreach ($name as $k => $v) {
469 469
 
470
-				$this->vars[$k] = $v;
471
-			}
472
-		} elseif (is_array($val)) {
470
+                $this->vars[$k] = $v;
471
+            }
472
+        } elseif (is_array($val)) {
473 473
 
474
-			// Clear the existing values
475
-    		if ($reset_array) {
476
-    			$this->vars[$name] = array();
477
-    		}
474
+            // Clear the existing values
475
+            if ($reset_array) {
476
+                $this->vars[$name] = array();
477
+            }
478 478
 
479
-        	foreach ($val as $k => $v) {
479
+            foreach ($val as $k => $v) {
480 480
 
481
-        		$this->vars[$name][$k] = $v;
482
-        	}
481
+                $this->vars[$name][$k] = $v;
482
+            }
483 483
 
484
-		} else {
484
+        } else {
485 485
 
486
-			$this->vars[$name] = $val;
487
-		}
488
-	}
486
+            $this->vars[$name] = $val;
487
+        }
488
+    }
489 489
 
490
-	/**
490
+    /**
491 491
      * assign a file variable
492 492
      *
493 493
      * @access public
494 494
      * @param string $name Variable to assign $val to
495 495
      * @param string / array $val Values to assign to $name
496 496
      */
497
-	public function assign_file ($name, $val = '') {
497
+    public function assign_file ($name, $val = '') {
498 498
 
499
-		if (is_array($name)) {
499
+        if (is_array($name)) {
500 500
 
501
-			foreach ($name as $k => $v) {
501
+            foreach ($name as $k => $v) {
502 502
 
503
-				$this->_assign_file_sub($k, $v);
504
-			}
505
-		} else {
503
+                $this->_assign_file_sub($k, $v);
504
+            }
505
+        } else {
506 506
 
507
-			$this->_assign_file_sub($name, $val);
508
-		}
509
-	}
507
+            $this->_assign_file_sub($name, $val);
508
+        }
509
+    }
510 510
 
511
-	/**
511
+    /**
512 512
      * parse a block
513 513
      *
514 514
      * @access public
515 515
      * @param string $bname Block name to parse
516 516
      */
517
-	public function parse ($bname) {
517
+    public function parse ($bname) {
518 518
 
519
-		if (isset($this->preparsed_blocks[$bname])) {
519
+        if (isset($this->preparsed_blocks[$bname])) {
520 520
 
521
-			$copy = $this->preparsed_blocks[$bname];
521
+            $copy = $this->preparsed_blocks[$bname];
522 522
 
523
-		} elseif (isset($this->blocks[$bname])) {
523
+        } elseif (isset($this->blocks[$bname])) {
524 524
 
525
-			$copy = $this->blocks[$bname];
525
+            $copy = $this->blocks[$bname];
526 526
 
527
-		} elseif ($this->_ignore_missing_blocks) {
528
-			// ------------------------------------------------------
529
-			// NW : 17 Oct 2002. Added default of ignore_missing_blocks
530
-			//      to allow for generalised processing where some
531
-			//      blocks may be removed from the HTML without the
532
-			//      processing code needing to be altered.
533
-			// ------------------------------------------------------
534
-			// JRC: 3/1/2003 added set error to ignore missing functionality
535
-			$this->_set_error("parse: blockname [$bname] does not exist");
536
-			return;
527
+        } elseif ($this->_ignore_missing_blocks) {
528
+            // ------------------------------------------------------
529
+            // NW : 17 Oct 2002. Added default of ignore_missing_blocks
530
+            //      to allow for generalised processing where some
531
+            //      blocks may be removed from the HTML without the
532
+            //      processing code needing to be altered.
533
+            // ------------------------------------------------------
534
+            // JRC: 3/1/2003 added set error to ignore missing functionality
535
+            $this->_set_error("parse: blockname [$bname] does not exist");
536
+            return;
537 537
 
538
-		} else {
538
+        } else {
539 539
 
540
-			$this->_set_error("parse: blockname [$bname] does not exist");
541
-		}
540
+            $this->_set_error("parse: blockname [$bname] does not exist");
541
+        }
542 542
 
543
-		/* from there we should have no more {FILE } directives */
544
-		if (!isset($copy)) {
545
-			die('Block: ' . $bname);
546
-		}
543
+        /* from there we should have no more {FILE } directives */
544
+        if (!isset($copy)) {
545
+            die('Block: ' . $bname);
546
+        }
547 547
 
548
-		$copy = preg_replace($this->filevar_delim_nl, '', $copy);
548
+        $copy = preg_replace($this->filevar_delim_nl, '', $copy);
549 549
 
550
-		$var_array = array();
550
+        $var_array = array();
551 551
 
552
-		/* find & replace variables+blocks */
553
-		preg_match_all("|" . $this->tag_start_delim . "([A-Za-z0-9\._]+?" . $this->comment_preg . ")" . $this->tag_end_delim. "|", $copy, $var_array);
552
+        /* find & replace variables+blocks */
553
+        preg_match_all("|" . $this->tag_start_delim . "([A-Za-z0-9\._]+?" . $this->comment_preg . ")" . $this->tag_end_delim. "|", $copy, $var_array);
554 554
 
555
-		$var_array = $var_array[1];
555
+        $var_array = $var_array[1];
556 556
 
557
-		foreach ($var_array as $k => $v) {
557
+        foreach ($var_array as $k => $v) {
558 558
 
559
-			// Are there any comments in the tags {tag#a comment for documenting the template}
560
-			$any_comments = explode('#', $v);
561
-			$v = rtrim($any_comments[0]);
559
+            // Are there any comments in the tags {tag#a comment for documenting the template}
560
+            $any_comments = explode('#', $v);
561
+            $v = rtrim($any_comments[0]);
562 562
 
563
-			if (sizeof($any_comments) > 1) {
563
+            if (sizeof($any_comments) > 1) {
564 564
 
565
-				$comments = $any_comments[1];
566
-			} else {
565
+                $comments = $any_comments[1];
566
+            } else {
567 567
 
568
-				$comments = '';
569
-			}
568
+                $comments = '';
569
+            }
570 570
 
571
-			$sub = explode('.', $v);
571
+            $sub = explode('.', $v);
572 572
 
573
-			if ($sub[0] == '_BLOCK_') {
573
+            if ($sub[0] == '_BLOCK_') {
574 574
 
575
-				unset($sub[0]);
575
+                unset($sub[0]);
576 576
 
577
-				$bname2 = implode('.', $sub);
577
+                $bname2 = implode('.', $sub);
578 578
 
579
-				// trinary operator eliminates assign error in E_ALL reporting
580
-				$var = isset($this->parsed_blocks[$bname2]) ? $this->parsed_blocks[$bname2] : null;
581
-				$nul = (!isset($this->_null_block[$bname2])) ? $this->_null_block[''] : $this->_null_block[$bname2];
579
+                // trinary operator eliminates assign error in E_ALL reporting
580
+                $var = isset($this->parsed_blocks[$bname2]) ? $this->parsed_blocks[$bname2] : null;
581
+                $nul = (!isset($this->_null_block[$bname2])) ? $this->_null_block[''] : $this->_null_block[$bname2];
582 582
 
583
-				if ($var === '') {
583
+                if ($var === '') {
584 584
 
585
-					if ($nul == '') {
586
-						// -----------------------------------------------------------
587
-						// Removed requirement for blocks to be at the start of string
588
-						// -----------------------------------------------------------
589
-						//                      $copy=preg_replace("/^\s*\{".$v."\}\s*\n*/m","",$copy);
590
-						// Now blocks don't need to be at the beginning of a line,
591
-						//$copy=preg_replace("/\s*" . $this->tag_start_delim . $v . $this->tag_end_delim . "\s*\n*/m","",$copy);
592
-						$copy = preg_replace("|" . $this->tag_start_delim . $v . $this->tag_end_delim . "|m", '', $copy);
585
+                    if ($nul == '') {
586
+                        // -----------------------------------------------------------
587
+                        // Removed requirement for blocks to be at the start of string
588
+                        // -----------------------------------------------------------
589
+                        //                      $copy=preg_replace("/^\s*\{".$v."\}\s*\n*/m","",$copy);
590
+                        // Now blocks don't need to be at the beginning of a line,
591
+                        //$copy=preg_replace("/\s*" . $this->tag_start_delim . $v . $this->tag_end_delim . "\s*\n*/m","",$copy);
592
+                        $copy = preg_replace("|" . $this->tag_start_delim . $v . $this->tag_end_delim . "|m", '', $copy);
593 593
 
594
-					} else {
594
+                    } else {
595 595
 
596
-						$copy = preg_replace("|" . $this->tag_start_delim . $v . $this->tag_end_delim . "|m", "$nul", $copy);
597
-					}
598
-				} else {
596
+                        $copy = preg_replace("|" . $this->tag_start_delim . $v . $this->tag_end_delim . "|m", "$nul", $copy);
597
+                    }
598
+                } else {
599 599
 
600
-					//$var = trim($var);
601
-					switch (true) {
602
-						case preg_match('/^\n/', $var) && preg_match('/\n$/', $var):
603
-							$var = substr($var, 1, -1);
604
-							break;
600
+                    //$var = trim($var);
601
+                    switch (true) {
602
+                        case preg_match('/^\n/', $var) && preg_match('/\n$/', $var):
603
+                            $var = substr($var, 1, -1);
604
+                            break;
605 605
 
606
-						case preg_match('/^\n/', $var):
607
-							$var = substr($var, 1);
608
-							break;
606
+                        case preg_match('/^\n/', $var):
607
+                            $var = substr($var, 1);
608
+                            break;
609 609
 
610
-						case preg_match('/\n$/', $var):
611
-							$var = substr($var, 0, -1);
612
-							break;
613
-					}
610
+                        case preg_match('/\n$/', $var):
611
+                            $var = substr($var, 0, -1);
612
+                            break;
613
+                    }
614 614
 
615
-					// SF Bug no. 810773 - thanks anonymous
616
-					$var = str_replace('\\', '\\\\', $var);
617
-					// Ensure dollars in strings are not evaluated reported by SadGeezer 31/3/04
618
-					$var = str_replace('$', '\\$', $var);
619
-					// Replaced str_replaces with preg_quote
620
-					//$var = preg_quote($var);
621
-					$var = str_replace('\\|', '|', $var);
622
-					$copy = preg_replace("|" . $this->tag_start_delim . $v . $this->tag_end_delim . "|m", "$var", $copy);
615
+                    // SF Bug no. 810773 - thanks anonymous
616
+                    $var = str_replace('\\', '\\\\', $var);
617
+                    // Ensure dollars in strings are not evaluated reported by SadGeezer 31/3/04
618
+                    $var = str_replace('$', '\\$', $var);
619
+                    // Replaced str_replaces with preg_quote
620
+                    //$var = preg_quote($var);
621
+                    $var = str_replace('\\|', '|', $var);
622
+                    $copy = preg_replace("|" . $this->tag_start_delim . $v . $this->tag_end_delim . "|m", "$var", $copy);
623 623
 
624
-					if (preg_match('/^\n/', $copy) && preg_match('/\n$/', $copy)) {
625
-						$copy = substr($copy, 1, -1);
626
-					}
627
-				}
628
-			} else {
624
+                    if (preg_match('/^\n/', $copy) && preg_match('/\n$/', $copy)) {
625
+                        $copy = substr($copy, 1, -1);
626
+                    }
627
+                }
628
+            } else {
629 629
 
630
-				$var = $this->vars;
630
+                $var = $this->vars;
631 631
 
632
-				foreach ($sub as $v1) {
632
+                foreach ($sub as $v1) {
633 633
 
634
-					// NW 4 Oct 2002 - Added isset and is_array check to avoid NOTICE messages
635
-					// JC 17 Oct 2002 - Changed EMPTY to stlen=0
636
-					//                if (empty($var[$v1])) { // this line would think that zeros(0) were empty - which is not true
637
-					if (!isset($var[$v1]) || (!is_array($var[$v1]) && strlen($var[$v1]) == 0)) {
634
+                    // NW 4 Oct 2002 - Added isset and is_array check to avoid NOTICE messages
635
+                    // JC 17 Oct 2002 - Changed EMPTY to stlen=0
636
+                    //                if (empty($var[$v1])) { // this line would think that zeros(0) were empty - which is not true
637
+                    if (!isset($var[$v1]) || (!is_array($var[$v1]) && strlen($var[$v1]) == 0)) {
638 638
 
639
-						// Check for constant, when variable not assigned
640
-						if (defined($v1)) {
639
+                        // Check for constant, when variable not assigned
640
+                        if (defined($v1)) {
641 641
 
642
-							$var[$v1] = constant($v1);
642
+                            $var[$v1] = constant($v1);
643 643
 
644
-						} else {
644
+                        } else {
645 645
 
646
-							$var[$v1] = null;
647
-						}
648
-					}
646
+                            $var[$v1] = null;
647
+                        }
648
+                    }
649 649
 
650
-					$var = $var[$v1];
651
-				}
650
+                    $var = $var[$v1];
651
+                }
652 652
 
653
-				$nul = (!isset($this->_null_string[$v])) ? ($this->_null_string[""]) : ($this->_null_string[$v]);
654
-				$var = (!isset($var)) ? $nul : $var;
653
+                $nul = (!isset($this->_null_string[$v])) ? ($this->_null_string[""]) : ($this->_null_string[$v]);
654
+                $var = (!isset($var)) ? $nul : $var;
655 655
 
656
-				if ($var === '') {
657
-					// -----------------------------------------------------------
658
-					// Removed requriement for blocks to be at the start of string
659
-					// -----------------------------------------------------------
660
-					//                    $copy=preg_replace("|^\s*\{".$v." ?#?".$comments."\}\s*\n|m","",$copy);
661
-					$copy = preg_replace("|" . $this->tag_start_delim . $v . "( ?#" . $comments . ")?" . $this->tag_end_delim . "|m", '', $copy);
662
-				}
656
+                if ($var === '') {
657
+                    // -----------------------------------------------------------
658
+                    // Removed requriement for blocks to be at the start of string
659
+                    // -----------------------------------------------------------
660
+                    //                    $copy=preg_replace("|^\s*\{".$v." ?#?".$comments."\}\s*\n|m","",$copy);
661
+                    $copy = preg_replace("|" . $this->tag_start_delim . $v . "( ?#" . $comments . ")?" . $this->tag_end_delim . "|m", '', $copy);
662
+                }
663 663
 
664
-				$var = trim($var);
665
-				// SF Bug no. 810773 - thanks anonymous
666
-				$var = str_replace('\\', '\\\\', $var);
667
-				// Ensure dollars in strings are not evaluated reported by SadGeezer 31/3/04
668
-				$var = str_replace('$', '\\$', $var);
669
-				// Replace str_replaces with preg_quote
670
-				//$var = preg_quote($var);
671
-				$var = str_replace('\\|', '|', $var);
672
-				$copy = preg_replace("|" . $this->tag_start_delim . $v . "( ?#" . $comments . ")?" . $this->tag_end_delim . "|m", "$var", $copy);
673
-
674
-				if (preg_match('/^\n/', $copy) && preg_match('/\n$/', $copy)) {
675
-					$copy = substr($copy, 1);
676
-				}
677
-			}
678
-		}
679
-
680
-		if (isset($this->parsed_blocks[$bname])) {
681
-			$this->parsed_blocks[$bname] .= $copy;
682
-		} else {
683
-			$this->parsed_blocks[$bname] = $copy;
684
-		}
685
-
686
-		/* reset sub-blocks */
687
-		if ($this->_autoreset && (!empty($this->sub_blocks[$bname]))) {
688
-
689
-			reset($this->sub_blocks[$bname]);
690
-
691
-			foreach ($this->sub_blocks[$bname] as $k => $v) {
692
-				$this->reset($v);
693
-			}
694
-		}
695
-	}
696
-
697
-	/**
664
+                $var = trim($var);
665
+                // SF Bug no. 810773 - thanks anonymous
666
+                $var = str_replace('\\', '\\\\', $var);
667
+                // Ensure dollars in strings are not evaluated reported by SadGeezer 31/3/04
668
+                $var = str_replace('$', '\\$', $var);
669
+                // Replace str_replaces with preg_quote
670
+                //$var = preg_quote($var);
671
+                $var = str_replace('\\|', '|', $var);
672
+                $copy = preg_replace("|" . $this->tag_start_delim . $v . "( ?#" . $comments . ")?" . $this->tag_end_delim . "|m", "$var", $copy);
673
+
674
+                if (preg_match('/^\n/', $copy) && preg_match('/\n$/', $copy)) {
675
+                    $copy = substr($copy, 1);
676
+                }
677
+            }
678
+        }
679
+
680
+        if (isset($this->parsed_blocks[$bname])) {
681
+            $this->parsed_blocks[$bname] .= $copy;
682
+        } else {
683
+            $this->parsed_blocks[$bname] = $copy;
684
+        }
685
+
686
+        /* reset sub-blocks */
687
+        if ($this->_autoreset && (!empty($this->sub_blocks[$bname]))) {
688
+
689
+            reset($this->sub_blocks[$bname]);
690
+
691
+            foreach ($this->sub_blocks[$bname] as $k => $v) {
692
+                $this->reset($v);
693
+            }
694
+        }
695
+    }
696
+
697
+    /**
698 698
      * returns the parsed text for a block, including all sub-blocks.
699 699
      *
700 700
      * @access public
701 701
      * @param string $bname Block name to parse
702 702
      */
703
-	public function rparse ($bname) {
703
+    public function rparse ($bname) {
704 704
 
705
-		if (!empty($this->sub_blocks[$bname])) {
705
+        if (!empty($this->sub_blocks[$bname])) {
706 706
 
707
-			reset($this->sub_blocks[$bname]);
707
+            reset($this->sub_blocks[$bname]);
708 708
 
709
-			foreach ($this->sub_blocks[$bname] as $k => $v) {
709
+            foreach ($this->sub_blocks[$bname] as $k => $v) {
710 710
 
711
-				if (!empty($v)) {
712
-					$this->rparse($v);
713
-				}
714
-			}
715
-		}
711
+                if (!empty($v)) {
712
+                    $this->rparse($v);
713
+                }
714
+            }
715
+        }
716 716
 
717
-		$this->parse($bname);
718
-	}
717
+        $this->parse($bname);
718
+    }
719 719
 
720
-	/**
720
+    /**
721 721
      * inserts a loop ( call assign & parse )
722 722
      *
723 723
      * @access public
724 724
      * @param string $bname Block name to assign
725 725
      * @param string $var Variable to assign values to
726 726
      * @param string / array $value Value to assign to $var
727
-    */
728
-	public function insert_loop ($bname, $var, $value = '') {
727
+     */
728
+    public function insert_loop ($bname, $var, $value = '') {
729 729
 
730
-		$this->assign($var, $value);
731
-		$this->parse($bname);
732
-	}
730
+        $this->assign($var, $value);
731
+        $this->parse($bname);
732
+    }
733 733
 
734
-	/**
734
+    /**
735 735
      * parses a block for every set of data in the values array
736 736
      *
737 737
      * @access public
738 738
      * @param string $bname Block name to loop
739 739
      * @param string $var Variable to assign values to
740 740
      * @param array $values Values to assign to $var
741
-    */
742
-	public function array_loop ($bname, $var, &$values) {
741
+     */
742
+    public function array_loop ($bname, $var, &$values) {
743 743
 
744
-		if (is_array($values)) {
744
+        if (is_array($values)) {
745 745
 
746
-			foreach($values as $v) {
746
+            foreach($values as $v) {
747 747
 
748
-				$this->insert_loop($bname, $var, $v);
749
-			}
750
-		}
751
-	}
748
+                $this->insert_loop($bname, $var, $v);
749
+            }
750
+        }
751
+    }
752 752
 
753
-	/**
753
+    /**
754 754
      * returns the parsed text for a block
755 755
      *
756 756
      * @access public
757 757
      * @param string $bname Block name to return
758 758
      * @return string
759 759
      */
760
-	public function text ($bname = '') {
760
+    public function text ($bname = '') {
761 761
 
762
-		$text = '';
762
+        $text = '';
763 763
 
764
-		if ($this->debug && $this->output_type == 'HTML') {
765
-			// JC 20/11/02 echo the template filename if in development as
766
-			// html comment
767
-			$text .= '<!-- XTemplate: ' . realpath($this->filename) . " -->\n";
768
-		}
764
+        if ($this->debug && $this->output_type == 'HTML') {
765
+            // JC 20/11/02 echo the template filename if in development as
766
+            // html comment
767
+            $text .= '<!-- XTemplate: ' . realpath($this->filename) . " -->\n";
768
+        }
769 769
 
770
-		$bname = !empty($bname) ? $bname : $this->mainblock;
770
+        $bname = !empty($bname) ? $bname : $this->mainblock;
771 771
 
772
-		$text .= isset($this->parsed_blocks[$bname]) ? $this->parsed_blocks[$bname] : $this->get_error();
772
+        $text .= isset($this->parsed_blocks[$bname]) ? $this->parsed_blocks[$bname] : $this->get_error();
773 773
 
774
-		return $text;
775
-	}
774
+        return $text;
775
+    }
776 776
 
777
-	/**
777
+    /**
778 778
      * prints the parsed text
779 779
      *
780 780
      * @access public
781 781
      * @param string $bname Block name to echo out
782 782
      */
783
-	public function out ($bname) {
783
+    public function out ($bname) {
784 784
 
785
-		$out = $this->text($bname);
786
-		//        $length=strlen($out);
787
-		//header("Content-Length: ".$length); // TODO: Comment this back in later
785
+        $out = $this->text($bname);
786
+        //        $length=strlen($out);
787
+        //header("Content-Length: ".$length); // TODO: Comment this back in later
788 788
 
789
-		echo $out;
790
-	}
789
+        echo $out;
790
+    }
791 791
 
792
-	/**
792
+    /**
793 793
      * prints the parsed text to a specified file
794 794
      *
795 795
      * @access public
796 796
      * @param string $bname Block name to write out
797 797
      * @param string $fname File name to write to
798 798
      */
799
-	public function out_file ($bname, $fname) {
799
+    public function out_file ($bname, $fname) {
800 800
 
801
-		if (!empty($bname) && !empty($fname) && is_writeable($fname)) {
801
+        if (!empty($bname) && !empty($fname) && is_writeable($fname)) {
802 802
 
803
-			$fp = fopen($fname, 'w');
804
-			fwrite($fp, $this->text($bname));
805
-			fclose($fp);
806
-		}
807
-	}
803
+            $fp = fopen($fname, 'w');
804
+            fwrite($fp, $this->text($bname));
805
+            fclose($fp);
806
+        }
807
+    }
808 808
 
809
-	/**
809
+    /**
810 810
      * resets the parsed text
811 811
      *
812 812
      * @access public
813 813
      * @param string $bname Block to reset
814 814
      */
815
-	public function reset ($bname) {
815
+    public function reset ($bname) {
816 816
 
817
-		$this->parsed_blocks[$bname] = '';
818
-	}
817
+        $this->parsed_blocks[$bname] = '';
818
+    }
819 819
 
820
-	/**
820
+    /**
821 821
      * returns true if block was parsed, false if not
822 822
      *
823 823
      * @access public
824 824
      * @param string $bname Block name to test
825 825
      * @return boolean
826 826
      */
827
-	public function parsed ($bname) {
827
+    public function parsed ($bname) {
828 828
 
829
-		return (!empty($this->parsed_blocks[$bname]));
830
-	}
829
+        return (!empty($this->parsed_blocks[$bname]));
830
+    }
831 831
 
832
-	/**
832
+    /**
833 833
      * sets the string to replace in case the var was not assigned
834 834
      *
835 835
      * @access public
836 836
      * @param string $str Display string for null block
837 837
      * @param string $varname Variable name to apply $str to
838 838
      */
839
-	public function set_null_string($str, $varname = '') {
840
-
841
-		$this->_null_string[$varname] = $str;
842
-	}
843
-
844
-	/**
845
-	 * Backwards compatibility only
846
-	 *
847
-	 * @param string $str
848
-	 * @param string $varname
849
-	 * @deprecated Change to set_null_string to keep in with rest of naming convention
850
-	 */
851
-	public function SetNullString ($str, $varname = '') {
852
-		$this->set_null_string($str, $varname);
853
-	}
854
-
855
-	/**
839
+    public function set_null_string($str, $varname = '') {
840
+
841
+        $this->_null_string[$varname] = $str;
842
+    }
843
+
844
+    /**
845
+     * Backwards compatibility only
846
+     *
847
+     * @param string $str
848
+     * @param string $varname
849
+     * @deprecated Change to set_null_string to keep in with rest of naming convention
850
+     */
851
+    public function SetNullString ($str, $varname = '') {
852
+        $this->set_null_string($str, $varname);
853
+    }
854
+
855
+    /**
856 856
      * sets the string to replace in case the block was not parsed
857 857
      *
858 858
      * @access public
859 859
      * @param string $str Display string for null block
860 860
      * @param string $bname Block name to apply $str to
861 861
      */
862
-	public function set_null_block ($str, $bname = '') {
863
-
864
-		$this->_null_block[$bname] = $str;
865
-	}
866
-
867
-	/**
868
-	 * Backwards compatibility only
869
-	 *
870
-	 * @param string $str
871
-	 * @param string $bname
872
-	 * @deprecated Change to set_null_block to keep in with rest of naming convention
873
-	 */
874
-	public function SetNullBlock ($str, $bname = '') {
875
-		$this->set_null_block($str, $bname);
876
-	}
877
-
878
-	/**
862
+    public function set_null_block ($str, $bname = '') {
863
+
864
+        $this->_null_block[$bname] = $str;
865
+    }
866
+
867
+    /**
868
+     * Backwards compatibility only
869
+     *
870
+     * @param string $str
871
+     * @param string $bname
872
+     * @deprecated Change to set_null_block to keep in with rest of naming convention
873
+     */
874
+    public function SetNullBlock ($str, $bname = '') {
875
+        $this->set_null_block($str, $bname);
876
+    }
877
+
878
+    /**
879 879
      * sets AUTORESET to 1. (default is 1)
880 880
      * if set to 1, parse() automatically resets the parsed blocks' sub blocks
881 881
      * (for multiple level blocks)
882 882
      *
883 883
      * @access public
884 884
      */
885
-	public function set_autoreset () {
885
+    public function set_autoreset () {
886 886
 
887
-		$this->_autoreset = true;
888
-	}
887
+        $this->_autoreset = true;
888
+    }
889 889
 
890
-	/**
890
+    /**
891 891
      * sets AUTORESET to 0. (default is 1)
892 892
      * if set to 1, parse() automatically resets the parsed blocks' sub blocks
893 893
      * (for multiple level blocks)
894 894
      *
895 895
      * @access public
896 896
      */
897
-	public function clear_autoreset () {
897
+    public function clear_autoreset () {
898 898
 
899
-		$this->_autoreset = false;
900
-	}
899
+        $this->_autoreset = false;
900
+    }
901 901
 
902
-	/**
902
+    /**
903 903
      * scans global variables and assigns to PHP array
904 904
      *
905 905
      * @access public
906 906
      */
907
-	public function scan_globals () {
907
+    public function scan_globals () {
908 908
 
909
-		reset($GLOBALS);
909
+        reset($GLOBALS);
910 910
 
911
-		foreach ($GLOBALS as $k => $v) {
912
-			$GLOB[$k] = $v;
913
-		}
911
+        foreach ($GLOBALS as $k => $v) {
912
+            $GLOB[$k] = $v;
913
+        }
914 914
 
915
-		/**
916
-		 * Access global variables as:
917
-		 * @example {PHP._SERVER.HTTP_HOST}
918
-		 * in your template!
919
-		 */
920
-		$this->assign('PHP', $GLOB);
921
-	}
915
+        /**
916
+         * Access global variables as:
917
+         * @example {PHP._SERVER.HTTP_HOST}
918
+         * in your template!
919
+         */
920
+        $this->assign('PHP', $GLOB);
921
+    }
922 922
 
923
-	/**
923
+    /**
924 924
      * gets error condition / string
925 925
      *
926 926
      * @access public
927 927
      * @return boolean / string
928 928
      */
929
-	public function get_error () {
929
+    public function get_error () {
930 930
 
931
-		// JRC: 3/1/2003 Added ouptut wrapper and detection of output type for error message output
932
-		$retval = false;
931
+        // JRC: 3/1/2003 Added ouptut wrapper and detection of output type for error message output
932
+        $retval = false;
933 933
 
934
-		if ($this->_error != '') {
934
+        if ($this->_error != '') {
935 935
 
936
-			switch ($this->output_type) {
937
-				case 'HTML':
938
-				case 'html':
939
-					$retval = '<b>[XTemplate]</b><ul>' . nl2br(str_replace('* ', '<li>', str_replace(" *\n", "</li>\n", $this->_error))) . '</ul>';
940
-					break;
936
+            switch ($this->output_type) {
937
+                case 'HTML':
938
+                case 'html':
939
+                    $retval = '<b>[XTemplate]</b><ul>' . nl2br(str_replace('* ', '<li>', str_replace(" *\n", "</li>\n", $this->_error))) . '</ul>';
940
+                    break;
941 941
 
942
-				default:
943
-					$retval = '[XTemplate] ' . str_replace(' *\n', "\n", $this->_error);
944
-					break;
945
-			}
946
-		}
942
+                default:
943
+                    $retval = '[XTemplate] ' . str_replace(' *\n', "\n", $this->_error);
944
+                    break;
945
+            }
946
+        }
947 947
 
948
-		return $retval;
949
-	}
948
+        return $retval;
949
+    }
950 950
 
951
-	/***************************************************************************/
952
-	/***[ private stuff ]*******************************************************/
953
-	/***************************************************************************/
951
+    /***************************************************************************/
952
+    /***[ private stuff ]*******************************************************/
953
+    /***************************************************************************/
954 954
 
955
-	/**
955
+    /**
956 956
      * generates the array containing to-be-parsed stuff:
957 957
      * $blocks["main"],$blocks["main.table"],$blocks["main.table.row"], etc.
958 958
      * also builds the reverse parse order.
@@ -961,343 +961,343 @@  discard block
 block discarded – undo
961 961
      * @param string $con content to be processed
962 962
      * @param string $parentblock name of the parent block in the block hierarchy
963 963
      */
964
-	public function _maketree ($con, $parentblock='') {
964
+    public function _maketree ($con, $parentblock='') {
965 965
 
966
-		$blocks = array();
966
+        $blocks = array();
967 967
 
968
-		$con2 = explode($this->block_start_delim, $con);
968
+        $con2 = explode($this->block_start_delim, $con);
969 969
 
970
-		if (!empty($parentblock)) {
970
+        if (!empty($parentblock)) {
971 971
 
972
-			$block_names = explode('.', $parentblock);
973
-			$level = sizeof($block_names);
972
+            $block_names = explode('.', $parentblock);
973
+            $level = sizeof($block_names);
974 974
 
975
-		} else {
975
+        } else {
976 976
 
977
-			$block_names = array();
978
-			$level = 0;
979
-		}
977
+            $block_names = array();
978
+            $level = 0;
979
+        }
980 980
 
981
-		// JRC 06/04/2005 Added block comments (on BEGIN or END) <!-- BEGIN: block_name#Comments placed here -->
982
-		//$patt = "($this->block_start_word|$this->block_end_word)\s*(\w+)\s*$this->block_end_delim(.*)";
983
-		$patt = "(" . $this->block_start_word . "|" . $this->block_end_word . ")\s*(\w+)" . $this->comment_preg . "\s*" . $this->block_end_delim . "(.*)";
981
+        // JRC 06/04/2005 Added block comments (on BEGIN or END) <!-- BEGIN: block_name#Comments placed here -->
982
+        //$patt = "($this->block_start_word|$this->block_end_word)\s*(\w+)\s*$this->block_end_delim(.*)";
983
+        $patt = "(" . $this->block_start_word . "|" . $this->block_end_word . ")\s*(\w+)" . $this->comment_preg . "\s*" . $this->block_end_delim . "(.*)";
984 984
 
985
-		foreach($con2 as $k => $v) {
985
+        foreach($con2 as $k => $v) {
986 986
 
987
-			$res = array();
987
+            $res = array();
988 988
 
989
-			if (preg_match_all("/$patt/ims", $v, $res, PREG_SET_ORDER)) {
990
-				// $res[0][1] = BEGIN or END
991
-				// $res[0][2] = block name
992
-				// $res[0][3] = comment
993
-				// $res[0][4] = kinda content
994
-				$block_word	= $res[0][1];
995
-				$block_name	= $res[0][2];
996
-				$comment	= $res[0][3];
997
-				$content	= $res[0][4];
989
+            if (preg_match_all("/$patt/ims", $v, $res, PREG_SET_ORDER)) {
990
+                // $res[0][1] = BEGIN or END
991
+                // $res[0][2] = block name
992
+                // $res[0][3] = comment
993
+                // $res[0][4] = kinda content
994
+                $block_word	= $res[0][1];
995
+                $block_name	= $res[0][2];
996
+                $comment	= $res[0][3];
997
+                $content	= $res[0][4];
998 998
 
999
-				if (strtoupper($block_word) == $this->block_start_word) {
999
+                if (strtoupper($block_word) == $this->block_start_word) {
1000 1000
 
1001
-					$parent_name = implode('.', $block_names);
1001
+                    $parent_name = implode('.', $block_names);
1002 1002
 
1003
-					// add one level - array("main","table","row")
1004
-					$block_names[++$level] = $block_name;
1003
+                    // add one level - array("main","table","row")
1004
+                    $block_names[++$level] = $block_name;
1005 1005
 
1006
-					// make block name (main.table.row)
1007
-					$cur_block_name=implode('.', $block_names);
1006
+                    // make block name (main.table.row)
1007
+                    $cur_block_name=implode('.', $block_names);
1008 1008
 
1009
-					// build block parsing order (reverse)
1010
-					$this->block_parse_order[] = $cur_block_name;
1009
+                    // build block parsing order (reverse)
1010
+                    $this->block_parse_order[] = $cur_block_name;
1011 1011
 
1012
-					//add contents. trinary operator eliminates assign error in E_ALL reporting
1013
-					$blocks[$cur_block_name] = isset($blocks[$cur_block_name]) ? $blocks[$cur_block_name] . $content : $content;
1012
+                    //add contents. trinary operator eliminates assign error in E_ALL reporting
1013
+                    $blocks[$cur_block_name] = isset($blocks[$cur_block_name]) ? $blocks[$cur_block_name] . $content : $content;
1014 1014
 
1015
-					// add {_BLOCK_.blockname} string to parent block
1016
-					$blocks[$parent_name] .= str_replace('\\', '', $this->tag_start_delim) . '_BLOCK_.' . $cur_block_name . str_replace('\\', '', $this->tag_end_delim);
1015
+                    // add {_BLOCK_.blockname} string to parent block
1016
+                    $blocks[$parent_name] .= str_replace('\\', '', $this->tag_start_delim) . '_BLOCK_.' . $cur_block_name . str_replace('\\', '', $this->tag_end_delim);
1017 1017
 
1018
-					// store sub block names for autoresetting and recursive parsing
1019
-					$this->sub_blocks[$parent_name][] = $cur_block_name;
1018
+                    // store sub block names for autoresetting and recursive parsing
1019
+                    $this->sub_blocks[$parent_name][] = $cur_block_name;
1020 1020
 
1021
-					// store sub block names for autoresetting
1022
-					$this->sub_blocks[$cur_block_name][] = '';
1021
+                    // store sub block names for autoresetting
1022
+                    $this->sub_blocks[$cur_block_name][] = '';
1023 1023
 
1024
-				} else if (strtoupper($block_word) == $this->block_end_word) {
1024
+                } else if (strtoupper($block_word) == $this->block_end_word) {
1025 1025
 
1026
-					unset($block_names[$level--]);
1026
+                    unset($block_names[$level--]);
1027 1027
 
1028
-					$parent_name = implode('.', $block_names);
1028
+                    $parent_name = implode('.', $block_names);
1029 1029
 
1030
-					// add rest of block to parent block
1031
-					$blocks[$parent_name] .= $content;
1032
-				}
1033
-			} else {
1030
+                    // add rest of block to parent block
1031
+                    $blocks[$parent_name] .= $content;
1032
+                }
1033
+            } else {
1034 1034
 
1035
-				// no block delimiters found
1036
-				// Saves doing multiple implodes - less overhead
1037
-				$tmp = implode('.', $block_names);
1035
+                // no block delimiters found
1036
+                // Saves doing multiple implodes - less overhead
1037
+                $tmp = implode('.', $block_names);
1038 1038
 
1039
-				if ($k) {
1040
-					$blocks[$tmp] .= $this->block_start_delim;
1041
-				}
1039
+                if ($k) {
1040
+                    $blocks[$tmp] .= $this->block_start_delim;
1041
+                }
1042 1042
 
1043
-				// trinary operator eliminates assign error in E_ALL reporting
1044
-				$blocks[$tmp] = isset($blocks[$tmp]) ? $blocks[$tmp] . $v : $v;
1045
-			}
1046
-		}
1043
+                // trinary operator eliminates assign error in E_ALL reporting
1044
+                $blocks[$tmp] = isset($blocks[$tmp]) ? $blocks[$tmp] . $v : $v;
1045
+            }
1046
+        }
1047 1047
 
1048
-		return $blocks;
1049
-	}
1048
+        return $blocks;
1049
+    }
1050 1050
 
1051
-	/**
1051
+    /**
1052 1052
      * Sub processing for assign_file method
1053 1053
      *
1054 1054
      * @access private
1055 1055
      * @param string $name
1056 1056
      * @param string $val
1057 1057
      */
1058
-	private function _assign_file_sub ($name, $val) {
1058
+    private function _assign_file_sub ($name, $val) {
1059 1059
 
1060
-		if (isset($this->filevar_parent[$name])) {
1060
+        if (isset($this->filevar_parent[$name])) {
1061 1061
 
1062
-			if ($val != '') {
1062
+            if ($val != '') {
1063 1063
 
1064
-				$val = $this->_r_getfile($val);
1064
+                $val = $this->_r_getfile($val);
1065 1065
 
1066
-				foreach($this->filevar_parent[$name] as $parent) {
1066
+                foreach($this->filevar_parent[$name] as $parent) {
1067 1067
 
1068
-					if (isset($this->preparsed_blocks[$parent]) && !isset($this->filevars[$name])) {
1068
+                    if (isset($this->preparsed_blocks[$parent]) && !isset($this->filevars[$name])) {
1069 1069
 
1070
-						$copy = $this->preparsed_blocks[$parent];
1070
+                        $copy = $this->preparsed_blocks[$parent];
1071 1071
 
1072
-					} elseif (isset($this->blocks[$parent])) {
1072
+                    } elseif (isset($this->blocks[$parent])) {
1073 1073
 
1074
-						$copy = $this->blocks[$parent];
1075
-					}
1074
+                        $copy = $this->blocks[$parent];
1075
+                    }
1076 1076
 
1077
-					$res = array();
1077
+                    $res = array();
1078 1078
 
1079
-					preg_match_all($this->filevar_delim, $copy, $res, PREG_SET_ORDER);
1079
+                    preg_match_all($this->filevar_delim, $copy, $res, PREG_SET_ORDER);
1080 1080
 
1081
-					if (is_array($res) && isset($res[0])) {
1081
+                    if (is_array($res) && isset($res[0])) {
1082 1082
 
1083
-						// Changed as per solution in SF bug ID #1261828
1084
-						foreach ($res as $v) {
1083
+                        // Changed as per solution in SF bug ID #1261828
1084
+                        foreach ($res as $v) {
1085 1085
 
1086
-							// Changed as per solution in SF bug ID #1261828
1087
-							if ($v[1] == $name) {
1086
+                            // Changed as per solution in SF bug ID #1261828
1087
+                            if ($v[1] == $name) {
1088 1088
 
1089
-								// Changed as per solution in SF bug ID #1261828
1090
-								$copy = preg_replace("/" . preg_quote($v[0]) . "/", "$val", $copy);
1091
-								$this->preparsed_blocks = array_merge($this->preparsed_blocks, $this->_maketree($copy, $parent));
1092
-								$this->filevar_parent = array_merge($this->filevar_parent, $this->_store_filevar_parents($this->preparsed_blocks));
1093
-							}
1094
-						}
1095
-					}
1096
-				}
1097
-			}
1098
-		}
1089
+                                // Changed as per solution in SF bug ID #1261828
1090
+                                $copy = preg_replace("/" . preg_quote($v[0]) . "/", "$val", $copy);
1091
+                                $this->preparsed_blocks = array_merge($this->preparsed_blocks, $this->_maketree($copy, $parent));
1092
+                                $this->filevar_parent = array_merge($this->filevar_parent, $this->_store_filevar_parents($this->preparsed_blocks));
1093
+                            }
1094
+                        }
1095
+                    }
1096
+                }
1097
+            }
1098
+        }
1099 1099
 
1100
-		$this->filevars[$name] = $val;
1101
-	}
1100
+        $this->filevars[$name] = $val;
1101
+    }
1102 1102
 
1103
-	/**
1103
+    /**
1104 1104
      * store container block's name for file variables
1105 1105
      *
1106 1106
      * @access public - aiming for private
1107 1107
      * @param array $blocks
1108 1108
      * @return array
1109 1109
      */
1110
-	public function _store_filevar_parents ($blocks){
1110
+    public function _store_filevar_parents ($blocks){
1111 1111
 
1112
-		$parents = array();
1112
+        $parents = array();
1113 1113
 
1114
-		foreach ($blocks as $bname => $con) {
1114
+        foreach ($blocks as $bname => $con) {
1115 1115
 
1116
-			$res = array();
1116
+            $res = array();
1117 1117
 
1118
-			preg_match_all($this->filevar_delim, $con, $res);
1118
+            preg_match_all($this->filevar_delim, $con, $res);
1119 1119
 
1120
-			foreach ($res[1] as $k => $v) {
1120
+            foreach ($res[1] as $k => $v) {
1121 1121
 
1122
-				$parents[$v][] = $bname;
1123
-			}
1124
-		}
1125
-		return $parents;
1126
-	}
1122
+                $parents[$v][] = $bname;
1123
+            }
1124
+        }
1125
+        return $parents;
1126
+    }
1127 1127
 
1128
-	/**
1128
+    /**
1129 1129
      * Set the error string
1130 1130
      *
1131 1131
      * @access private
1132 1132
      * @param string $str
1133 1133
      */
1134
-	private function _set_error ($str)    {
1134
+    private function _set_error ($str)    {
1135 1135
 
1136
-		// JRC: 3/1/2003 Made to append the error messages
1137
-		$this->_error .= '* ' . $str . " *\n";
1138
-		// JRC: 3/1/2003 Removed trigger error, use this externally if you want it eg. trigger_error($xtpl->get_error())
1139
-		//trigger_error($this->get_error());
1140
-	}
1136
+        // JRC: 3/1/2003 Made to append the error messages
1137
+        $this->_error .= '* ' . $str . " *\n";
1138
+        // JRC: 3/1/2003 Removed trigger error, use this externally if you want it eg. trigger_error($xtpl->get_error())
1139
+        //trigger_error($this->get_error());
1140
+    }
1141 1141
 
1142
-	/**
1142
+    /**
1143 1143
      * returns the contents of a file
1144 1144
      *
1145 1145
      * @access protected
1146 1146
      * @param string $file
1147 1147
      * @return string
1148 1148
      */
1149
-	protected function _getfile ($file) {
1149
+    protected function _getfile ($file) {
1150 1150
 
1151
-		if (!isset($file)) {
1152
-			// JC 19/12/02 added $file to error message
1153
-			$this->_set_error('!isset file name!' . $file);
1151
+        if (!isset($file)) {
1152
+            // JC 19/12/02 added $file to error message
1153
+            $this->_set_error('!isset file name!' . $file);
1154 1154
 
1155
-			return '';
1156
-		}
1155
+            return '';
1156
+        }
1157 1157
 
1158
-		// check if filename is mapped to other filename
1159
-		if (isset($this->files)) {
1158
+        // check if filename is mapped to other filename
1159
+        if (isset($this->files)) {
1160 1160
 
1161
-			if (isset($this->files[$file])) {
1161
+            if (isset($this->files[$file])) {
1162 1162
 
1163
-				$file = $this->files[$file];
1164
-			}
1165
-		}
1163
+                $file = $this->files[$file];
1164
+            }
1165
+        }
1166 1166
 
1167
-		// prepend template dir
1168
-		if (!empty($this->tpldir)) {
1167
+        // prepend template dir
1168
+        if (!empty($this->tpldir)) {
1169 1169
 
1170
-			/**
1171
-			 * Support hierarchy of file locations to search
1172
-			 *
1173
-			 * @example Supply array of filepaths when instantiating
1174
-			 * 			First path supplied that has the named file is prioritised
1175
-			 * 			$xtpl = new XTemplate('myfile.xtpl', array('.','/mypath', '/mypath2'));
1176
-			 * @since 29/05/2007
1177
-			 */
1178
-			if (is_array($this->tpldir)) {
1170
+            /**
1171
+             * Support hierarchy of file locations to search
1172
+             *
1173
+             * @example Supply array of filepaths when instantiating
1174
+             * 			First path supplied that has the named file is prioritised
1175
+             * 			$xtpl = new XTemplate('myfile.xtpl', array('.','/mypath', '/mypath2'));
1176
+             * @since 29/05/2007
1177
+             */
1178
+            if (is_array($this->tpldir)) {
1179 1179
 
1180
-				foreach ($this->tpldir as $dir) {
1180
+                foreach ($this->tpldir as $dir) {
1181 1181
 
1182
-					if (is_readable($dir . DIRECTORY_SEPARATOR . $file)) {
1183
-						$file = $dir . DIRECTORY_SEPARATOR . $file;
1184
-						break;
1185
-					}
1186
-				}
1187
-			} else {
1182
+                    if (is_readable($dir . DIRECTORY_SEPARATOR . $file)) {
1183
+                        $file = $dir . DIRECTORY_SEPARATOR . $file;
1184
+                        break;
1185
+                    }
1186
+                }
1187
+            } else {
1188 1188
 
1189
-				$file = $this->tpldir. DIRECTORY_SEPARATOR . $file;
1190
-			}
1191
-		}
1189
+                $file = $this->tpldir. DIRECTORY_SEPARATOR . $file;
1190
+            }
1191
+        }
1192 1192
 
1193
-		$file_text = '';
1193
+        $file_text = '';
1194 1194
 
1195
-		if (isset($this->filecache[$file])) {
1195
+        if (isset($this->filecache[$file])) {
1196 1196
 
1197
-			$file_text .= $this->filecache[$file];
1197
+            $file_text .= $this->filecache[$file];
1198 1198
 
1199
-			if ($this->debug) {
1200
-				$file_text = '<!-- XTemplate debug cached: ' . realpath($file) . ' -->' . "\n" . $file_text;
1201
-			}
1199
+            if ($this->debug) {
1200
+                $file_text = '<!-- XTemplate debug cached: ' . realpath($file) . ' -->' . "\n" . $file_text;
1201
+            }
1202 1202
 
1203
-		} else {
1203
+        } else {
1204 1204
 
1205
-			if (is_file($file) && is_readable($file)) {
1205
+            if (is_file($file) && is_readable($file)) {
1206 1206
 
1207
-				if (filesize($file)) {
1207
+                if (filesize($file)) {
1208 1208
 
1209
-					if (!($fh = fopen($file, 'r'))) {
1209
+                    if (!($fh = fopen($file, 'r'))) {
1210 1210
 
1211
-						$this->_set_error('Cannot open file: ' . realpath($file));
1212
-						return '';
1213
-					}
1211
+                        $this->_set_error('Cannot open file: ' . realpath($file));
1212
+                        return '';
1213
+                    }
1214 1214
 
1215
-					$file_text .= fread($fh,filesize($file));
1216
-					fclose($fh);
1215
+                    $file_text .= fread($fh,filesize($file));
1216
+                    fclose($fh);
1217 1217
 
1218
-				}
1218
+                }
1219 1219
 
1220
-				if ($this->debug) {
1221
-					$file_text = '<!-- XTemplate debug: ' . realpath($file) . ' -->' . "\n" . $file_text;
1222
-				}
1220
+                if ($this->debug) {
1221
+                    $file_text = '<!-- XTemplate debug: ' . realpath($file) . ' -->' . "\n" . $file_text;
1222
+                }
1223 1223
 
1224
-			} elseif (str_replace('.', '', phpversion()) >= '430' && $file_text = @file_get_contents($file, true)) {
1225
-				// Enable use of include path by using file_get_contents
1226
-				// Implemented at suggestion of SF Feature Request ID #1529478 michaelgroh
1227
-				if ($file_text === false) {
1228
-					$this->_set_error("[" . realpath($file) . "] ($file) does not exist");
1229
-					$file_text = "<b>__XTemplate fatal error: file [$file] does not exist in the include path__</b>";
1230
-				} elseif ($this->debug) {
1231
-					$file_text = '<!-- XTemplate debug: ' . realpath($file) . ' (via include path) -->' . "\n" . $file_text;
1232
-				}
1233
-			} elseif (!is_file($file)) {
1224
+            } elseif (str_replace('.', '', phpversion()) >= '430' && $file_text = @file_get_contents($file, true)) {
1225
+                // Enable use of include path by using file_get_contents
1226
+                // Implemented at suggestion of SF Feature Request ID #1529478 michaelgroh
1227
+                if ($file_text === false) {
1228
+                    $this->_set_error("[" . realpath($file) . "] ($file) does not exist");
1229
+                    $file_text = "<b>__XTemplate fatal error: file [$file] does not exist in the include path__</b>";
1230
+                } elseif ($this->debug) {
1231
+                    $file_text = '<!-- XTemplate debug: ' . realpath($file) . ' (via include path) -->' . "\n" . $file_text;
1232
+                }
1233
+            } elseif (!is_file($file)) {
1234 1234
 
1235
-				// NW 17 Oct 2002 : Added realpath around the file name to identify where the code is searching.
1236
-				$this->_set_error("[" . realpath($file) . "] ($file) does not exist");
1237
-				$file_text .= "<b>__XTemplate fatal error: file [$file] does not exist__</b>";
1235
+                // NW 17 Oct 2002 : Added realpath around the file name to identify where the code is searching.
1236
+                $this->_set_error("[" . realpath($file) . "] ($file) does not exist");
1237
+                $file_text .= "<b>__XTemplate fatal error: file [$file] does not exist__</b>";
1238 1238
 
1239
-			} elseif (!is_readable($file)) {
1239
+            } elseif (!is_readable($file)) {
1240 1240
 
1241
-				$this->_set_error("[" . realpath($file) . "] ($file) is not readable");
1242
-				$file_text .= "<b>__XTemplate fatal error: file [$file] is not readable__</b>";
1243
-			}
1241
+                $this->_set_error("[" . realpath($file) . "] ($file) is not readable");
1242
+                $file_text .= "<b>__XTemplate fatal error: file [$file] is not readable__</b>";
1243
+            }
1244 1244
 
1245
-			$this->filecache[$file] = $file_text;
1246
-		}
1245
+            $this->filecache[$file] = $file_text;
1246
+        }
1247 1247
 
1248
-		return $file_text;
1249
-	}
1248
+        return $file_text;
1249
+    }
1250 1250
 
1251
-	/**
1251
+    /**
1252 1252
      * recursively gets the content of a file with {FILE "filename.tpl"} directives
1253 1253
      *
1254 1254
      * @access public - aiming for private
1255 1255
      * @param string $file
1256 1256
      * @return string
1257 1257
      */
1258
-	public function _r_getfile ($file) {
1258
+    public function _r_getfile ($file) {
1259 1259
 
1260
-		$text = $this->_getfile($file);
1260
+        $text = $this->_getfile($file);
1261 1261
 
1262
-		$res = array();
1262
+        $res = array();
1263 1263
 
1264
-		while (preg_match($this->file_delim,$text,$res)) {
1264
+        while (preg_match($this->file_delim,$text,$res)) {
1265 1265
 
1266
-			$text2 = $this->_getfile($res[1]);
1267
-			$text = preg_replace("'".preg_quote($res[0])."'",$text2,$text);
1268
-		}
1266
+            $text2 = $this->_getfile($res[1]);
1267
+            $text = preg_replace("'".preg_quote($res[0])."'",$text2,$text);
1268
+        }
1269 1269
 
1270
-		return $text;
1271
-	}
1270
+        return $text;
1271
+    }
1272 1272
 
1273 1273
 
1274
-	/**
1274
+    /**
1275 1275
      * add an outer block delimiter set useful for rtfs etc - keeps them editable in word
1276 1276
      *
1277 1277
      * @access private
1278 1278
      */
1279
-	private function _add_outer_block () {
1279
+    private function _add_outer_block () {
1280 1280
 
1281
-		$before = $this->block_start_delim . $this->block_start_word . ' ' . $this->mainblock . ' ' . $this->block_end_delim;
1282
-		$after = $this->block_start_delim . $this->block_end_word . ' ' . $this->mainblock . ' ' . $this->block_end_delim;
1281
+        $before = $this->block_start_delim . $this->block_start_word . ' ' . $this->mainblock . ' ' . $this->block_end_delim;
1282
+        $after = $this->block_start_delim . $this->block_end_word . ' ' . $this->mainblock . ' ' . $this->block_end_delim;
1283 1283
 
1284
-		$this->filecontents = $before . "\n" . $this->filecontents . "\n" . $after;
1285
-	}
1284
+        $this->filecontents = $before . "\n" . $this->filecontents . "\n" . $after;
1285
+    }
1286 1286
 
1287
-	/**
1287
+    /**
1288 1288
      * Debug function - var_dump wrapped in '<pre></pre>' tags
1289 1289
      *
1290 1290
      * @access private
1291 1291
      * @param multiple var_dumps all the supplied arguments
1292 1292
      */
1293
-	private function _pre_var_dump ($args) {
1294
-
1295
-		if ($this->debug) {
1296
-			echo '<pre>';
1297
-			var_dump(func_get_args());
1298
-			echo '</pre>';
1299
-		}
1300
-	}
1293
+    private function _pre_var_dump ($args) {
1294
+
1295
+        if ($this->debug) {
1296
+            echo '<pre>';
1297
+            var_dump(func_get_args());
1298
+            echo '</pre>';
1299
+        }
1300
+    }
1301 1301
 } /* end of XTemplate class. */
1302 1302
 
1303 1303
 ?>
1304 1304
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
      * @param boolean $autosetup If true, run setup() as part of constuctor
332 332
      * @return XTemplate
333 333
      */
334
-	public function XTemplate ($file, $tpldir = '', $files = null, $mainblock = 'main', $autosetup = true) {
334
+	public function XTemplate($file, $tpldir = '', $files = null, $mainblock = 'main', $autosetup = true) {
335 335
 
336 336
 		assert('Deprecated - use PHP 5 constructor');
337 337
 	}
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
 	 * @param string $tag_start {
360 360
 	 * @param string $tag_end }
361 361
 	 */
362
-	public function restart ($file, $tpldir = '', $files = null, $mainblock = 'main', $autosetup = true, $tag_start = '{', $tag_end = '}') {
362
+	public function restart($file, $tpldir = '', $files = null, $mainblock = 'main', $autosetup = true, $tag_start = '{', $tag_end = '}') {
363 363
 
364 364
 		$this->filename = $file;
365 365
 
@@ -404,7 +404,7 @@  discard block
 block discarded – undo
404 404
      * @access public
405 405
      * @param boolean $add_outer If true is passed when called, it adds an outer main block to the file
406 406
      */
407
-	public function setup ($add_outer = false) {
407
+	public function setup($add_outer = false) {
408 408
 
409 409
 		$this->tag_start_delim = preg_quote($this->tag_start_delim);
410 410
 		$this->tag_end_delim = preg_quote($this->tag_end_delim);
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
      * @param string / array $val Value to assign to $name
462 462
 	 * @param boolean $reset_array Reset the variable array if $val is an array
463 463
      */
464
-	public function assign ($name, $val = '', $reset_array = true) {
464
+	public function assign($name, $val = '', $reset_array = true) {
465 465
 
466 466
 		if (is_array($name)) {
467 467
 
@@ -494,7 +494,7 @@  discard block
 block discarded – undo
494 494
      * @param string $name Variable to assign $val to
495 495
      * @param string / array $val Values to assign to $name
496 496
      */
497
-	public function assign_file ($name, $val = '') {
497
+	public function assign_file($name, $val = '') {
498 498
 
499 499
 		if (is_array($name)) {
500 500
 
@@ -514,7 +514,7 @@  discard block
 block discarded – undo
514 514
      * @access public
515 515
      * @param string $bname Block name to parse
516 516
      */
517
-	public function parse ($bname) {
517
+	public function parse($bname) {
518 518
 
519 519
 		if (isset($this->preparsed_blocks[$bname])) {
520 520
 
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
 		$var_array = array();
551 551
 
552 552
 		/* find & replace variables+blocks */
553
-		preg_match_all("|" . $this->tag_start_delim . "([A-Za-z0-9\._]+?" . $this->comment_preg . ")" . $this->tag_end_delim. "|", $copy, $var_array);
553
+		preg_match_all("|" . $this->tag_start_delim . "([A-Za-z0-9\._]+?" . $this->comment_preg . ")" . $this->tag_end_delim . "|", $copy, $var_array);
554 554
 
555 555
 		$var_array = $var_array[1];
556 556
 
@@ -700,7 +700,7 @@  discard block
 block discarded – undo
700 700
      * @access public
701 701
      * @param string $bname Block name to parse
702 702
      */
703
-	public function rparse ($bname) {
703
+	public function rparse($bname) {
704 704
 
705 705
 		if (!empty($this->sub_blocks[$bname])) {
706 706
 
@@ -725,7 +725,7 @@  discard block
 block discarded – undo
725 725
      * @param string $var Variable to assign values to
726 726
      * @param string / array $value Value to assign to $var
727 727
     */
728
-	public function insert_loop ($bname, $var, $value = '') {
728
+	public function insert_loop($bname, $var, $value = '') {
729 729
 
730 730
 		$this->assign($var, $value);
731 731
 		$this->parse($bname);
@@ -739,11 +739,11 @@  discard block
 block discarded – undo
739 739
      * @param string $var Variable to assign values to
740 740
      * @param array $values Values to assign to $var
741 741
     */
742
-	public function array_loop ($bname, $var, &$values) {
742
+	public function array_loop($bname, $var, &$values) {
743 743
 
744 744
 		if (is_array($values)) {
745 745
 
746
-			foreach($values as $v) {
746
+			foreach ($values as $v) {
747 747
 
748 748
 				$this->insert_loop($bname, $var, $v);
749 749
 			}
@@ -757,7 +757,7 @@  discard block
 block discarded – undo
757 757
      * @param string $bname Block name to return
758 758
      * @return string
759 759
      */
760
-	public function text ($bname = '') {
760
+	public function text($bname = '') {
761 761
 
762 762
 		$text = '';
763 763
 
@@ -780,7 +780,7 @@  discard block
 block discarded – undo
780 780
      * @access public
781 781
      * @param string $bname Block name to echo out
782 782
      */
783
-	public function out ($bname) {
783
+	public function out($bname) {
784 784
 
785 785
 		$out = $this->text($bname);
786 786
 		//        $length=strlen($out);
@@ -796,7 +796,7 @@  discard block
 block discarded – undo
796 796
      * @param string $bname Block name to write out
797 797
      * @param string $fname File name to write to
798 798
      */
799
-	public function out_file ($bname, $fname) {
799
+	public function out_file($bname, $fname) {
800 800
 
801 801
 		if (!empty($bname) && !empty($fname) && is_writeable($fname)) {
802 802
 
@@ -812,7 +812,7 @@  discard block
 block discarded – undo
812 812
      * @access public
813 813
      * @param string $bname Block to reset
814 814
      */
815
-	public function reset ($bname) {
815
+	public function reset($bname) {
816 816
 
817 817
 		$this->parsed_blocks[$bname] = '';
818 818
 	}
@@ -824,7 +824,7 @@  discard block
 block discarded – undo
824 824
      * @param string $bname Block name to test
825 825
      * @return boolean
826 826
      */
827
-	public function parsed ($bname) {
827
+	public function parsed($bname) {
828 828
 
829 829
 		return (!empty($this->parsed_blocks[$bname]));
830 830
 	}
@@ -848,7 +848,7 @@  discard block
 block discarded – undo
848 848
 	 * @param string $varname
849 849
 	 * @deprecated Change to set_null_string to keep in with rest of naming convention
850 850
 	 */
851
-	public function SetNullString ($str, $varname = '') {
851
+	public function SetNullString($str, $varname = '') {
852 852
 		$this->set_null_string($str, $varname);
853 853
 	}
854 854
 
@@ -859,7 +859,7 @@  discard block
 block discarded – undo
859 859
      * @param string $str Display string for null block
860 860
      * @param string $bname Block name to apply $str to
861 861
      */
862
-	public function set_null_block ($str, $bname = '') {
862
+	public function set_null_block($str, $bname = '') {
863 863
 
864 864
 		$this->_null_block[$bname] = $str;
865 865
 	}
@@ -871,7 +871,7 @@  discard block
 block discarded – undo
871 871
 	 * @param string $bname
872 872
 	 * @deprecated Change to set_null_block to keep in with rest of naming convention
873 873
 	 */
874
-	public function SetNullBlock ($str, $bname = '') {
874
+	public function SetNullBlock($str, $bname = '') {
875 875
 		$this->set_null_block($str, $bname);
876 876
 	}
877 877
 
@@ -882,7 +882,7 @@  discard block
 block discarded – undo
882 882
      *
883 883
      * @access public
884 884
      */
885
-	public function set_autoreset () {
885
+	public function set_autoreset() {
886 886
 
887 887
 		$this->_autoreset = true;
888 888
 	}
@@ -894,7 +894,7 @@  discard block
 block discarded – undo
894 894
      *
895 895
      * @access public
896 896
      */
897
-	public function clear_autoreset () {
897
+	public function clear_autoreset() {
898 898
 
899 899
 		$this->_autoreset = false;
900 900
 	}
@@ -904,7 +904,7 @@  discard block
 block discarded – undo
904 904
      *
905 905
      * @access public
906 906
      */
907
-	public function scan_globals () {
907
+	public function scan_globals() {
908 908
 
909 909
 		reset($GLOBALS);
910 910
 
@@ -926,7 +926,7 @@  discard block
 block discarded – undo
926 926
      * @access public
927 927
      * @return boolean / string
928 928
      */
929
-	public function get_error () {
929
+	public function get_error() {
930 930
 
931 931
 		// JRC: 3/1/2003 Added ouptut wrapper and detection of output type for error message output
932 932
 		$retval = false;
@@ -961,7 +961,7 @@  discard block
 block discarded – undo
961 961
      * @param string $con content to be processed
962 962
      * @param string $parentblock name of the parent block in the block hierarchy
963 963
      */
964
-	public function _maketree ($con, $parentblock='') {
964
+	public function _maketree($con, $parentblock = '') {
965 965
 
966 966
 		$blocks = array();
967 967
 
@@ -982,7 +982,7 @@  discard block
 block discarded – undo
982 982
 		//$patt = "($this->block_start_word|$this->block_end_word)\s*(\w+)\s*$this->block_end_delim(.*)";
983 983
 		$patt = "(" . $this->block_start_word . "|" . $this->block_end_word . ")\s*(\w+)" . $this->comment_preg . "\s*" . $this->block_end_delim . "(.*)";
984 984
 
985
-		foreach($con2 as $k => $v) {
985
+		foreach ($con2 as $k => $v) {
986 986
 
987 987
 			$res = array();
988 988
 
@@ -1004,7 +1004,7 @@  discard block
 block discarded – undo
1004 1004
 					$block_names[++$level] = $block_name;
1005 1005
 
1006 1006
 					// make block name (main.table.row)
1007
-					$cur_block_name=implode('.', $block_names);
1007
+					$cur_block_name = implode('.', $block_names);
1008 1008
 
1009 1009
 					// build block parsing order (reverse)
1010 1010
 					$this->block_parse_order[] = $cur_block_name;
@@ -1055,7 +1055,7 @@  discard block
 block discarded – undo
1055 1055
      * @param string $name
1056 1056
      * @param string $val
1057 1057
      */
1058
-	private function _assign_file_sub ($name, $val) {
1058
+	private function _assign_file_sub($name, $val) {
1059 1059
 
1060 1060
 		if (isset($this->filevar_parent[$name])) {
1061 1061
 
@@ -1063,7 +1063,7 @@  discard block
 block discarded – undo
1063 1063
 
1064 1064
 				$val = $this->_r_getfile($val);
1065 1065
 
1066
-				foreach($this->filevar_parent[$name] as $parent) {
1066
+				foreach ($this->filevar_parent[$name] as $parent) {
1067 1067
 
1068 1068
 					if (isset($this->preparsed_blocks[$parent]) && !isset($this->filevars[$name])) {
1069 1069
 
@@ -1107,7 +1107,7 @@  discard block
 block discarded – undo
1107 1107
      * @param array $blocks
1108 1108
      * @return array
1109 1109
      */
1110
-	public function _store_filevar_parents ($blocks){
1110
+	public function _store_filevar_parents($blocks) {
1111 1111
 
1112 1112
 		$parents = array();
1113 1113
 
@@ -1131,7 +1131,7 @@  discard block
 block discarded – undo
1131 1131
      * @access private
1132 1132
      * @param string $str
1133 1133
      */
1134
-	private function _set_error ($str)    {
1134
+	private function _set_error($str) {
1135 1135
 
1136 1136
 		// JRC: 3/1/2003 Made to append the error messages
1137 1137
 		$this->_error .= '* ' . $str . " *\n";
@@ -1146,7 +1146,7 @@  discard block
 block discarded – undo
1146 1146
      * @param string $file
1147 1147
      * @return string
1148 1148
      */
1149
-	protected function _getfile ($file) {
1149
+	protected function _getfile($file) {
1150 1150
 
1151 1151
 		if (!isset($file)) {
1152 1152
 			// JC 19/12/02 added $file to error message
@@ -1186,7 +1186,7 @@  discard block
 block discarded – undo
1186 1186
 				}
1187 1187
 			} else {
1188 1188
 
1189
-				$file = $this->tpldir. DIRECTORY_SEPARATOR . $file;
1189
+				$file = $this->tpldir . DIRECTORY_SEPARATOR . $file;
1190 1190
 			}
1191 1191
 		}
1192 1192
 
@@ -1212,7 +1212,7 @@  discard block
 block discarded – undo
1212 1212
 						return '';
1213 1213
 					}
1214 1214
 
1215
-					$file_text .= fread($fh,filesize($file));
1215
+					$file_text .= fread($fh, filesize($file));
1216 1216
 					fclose($fh);
1217 1217
 
1218 1218
 				}
@@ -1255,16 +1255,16 @@  discard block
 block discarded – undo
1255 1255
      * @param string $file
1256 1256
      * @return string
1257 1257
      */
1258
-	public function _r_getfile ($file) {
1258
+	public function _r_getfile($file) {
1259 1259
 
1260 1260
 		$text = $this->_getfile($file);
1261 1261
 
1262 1262
 		$res = array();
1263 1263
 
1264
-		while (preg_match($this->file_delim,$text,$res)) {
1264
+		while (preg_match($this->file_delim, $text, $res)) {
1265 1265
 
1266 1266
 			$text2 = $this->_getfile($res[1]);
1267
-			$text = preg_replace("'".preg_quote($res[0])."'",$text2,$text);
1267
+			$text = preg_replace("'" . preg_quote($res[0]) . "'", $text2, $text);
1268 1268
 		}
1269 1269
 
1270 1270
 		return $text;
@@ -1276,7 +1276,7 @@  discard block
 block discarded – undo
1276 1276
      *
1277 1277
      * @access private
1278 1278
      */
1279
-	private function _add_outer_block () {
1279
+	private function _add_outer_block() {
1280 1280
 
1281 1281
 		$before = $this->block_start_delim . $this->block_start_word . ' ' . $this->mainblock . ' ' . $this->block_end_delim;
1282 1282
 		$after = $this->block_start_delim . $this->block_end_word . ' ' . $this->mainblock . ' ' . $this->block_end_delim;
@@ -1290,7 +1290,7 @@  discard block
 block discarded – undo
1290 1290
      * @access private
1291 1291
      * @param multiple var_dumps all the supplied arguments
1292 1292
      */
1293
-	private function _pre_var_dump ($args) {
1293
+	private function _pre_var_dump($args) {
1294 1294
 
1295 1295
 		if ($this->debug) {
1296 1296
 			echo '<pre>';
Please login to merge, or discard this patch.
system/packages/com.jukusoft.cms.xtpl/classes/template.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 	protected $template = null;
22 22
 	protected static $registeredTemplate = array();
23 23
 
24
-	public function __construct ($file, Registry &$registry = null) {
24
+	public function __construct($file, Registry &$registry = null) {
25 25
 		if ($registry == null) {
26 26
 			$registry = Registry::singleton();
27 27
 		}
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 		$this->template->assign("USERNAME", User::current()->getUsername());
72 72
 
73 73
 		$style_name = $registry->getSetting("current_style_name");
74
-		$this->template->assign("STYLE_PATH",DomainUtils::getBaseURL() . "/styles/" . $style_name . "/");
74
+		$this->template->assign("STYLE_PATH", DomainUtils::getBaseURL() . "/styles/" . $style_name . "/");
75 75
 
76 76
 		Events::throwEvent("init_template", array(
77 77
 			'file' => &$file,
@@ -82,36 +82,36 @@  discard block
 block discarded – undo
82 82
 
83 83
 	}
84 84
 
85
-	public function assign ($var, $value) {
85
+	public function assign($var, $value) {
86 86
 		$this->template->assign($var, $value);
87 87
 	}
88 88
 
89
-	public function parse ($name = "main") {
89
+	public function parse($name = "main") {
90 90
 		$this->template->parse($name);
91 91
 	}
92 92
 
93
-	public function getCode ($name = "main") {
93
+	public function getCode($name = "main") {
94 94
 		return $this->template->text($name);
95 95
 	}
96 96
 
97
-	public static function registerTemplate ($template, $file) {
97
+	public static function registerTemplate($template, $file) {
98 98
 		self::$registeredTemplate[$template] = $file;
99 99
 	}
100 100
 
101
-	public static function clearTemplates () {
101
+	public static function clearTemplates() {
102 102
 		self::$registeredTemplate = array();
103 103
 	}
104 104
 
105
-	public static function createTemplate ($file) {
105
+	public static function createTemplate($file) {
106 106
 		$class = (String) __CLASS__;
107 107
 		return new $class($file);
108 108
 	}
109 109
 
110
-	public static function getName () {
110
+	public static function getName() {
111 111
 		return __CLASS__;
112 112
 	}
113 113
 
114
-	public static function findTemplate (string $tpl_name, Registry &$registry) : string {
114
+	public static function findTemplate(string $tpl_name, Registry &$registry) : string {
115 115
 		if (strpos($tpl_name, ".tpl") !== FALSE) {
116 116
 			//remove file extension
117 117
 			$tpl_name = str_replace(".tpl", "", $tpl_name);
Please login to merge, or discard this patch.
Indentation   +131 added lines, -131 removed lines patch added patch discarded remove patch
@@ -18,137 +18,137 @@
 block discarded – undo
18 18
 
19 19
 class Template {
20 20
 
21
-	protected $template = null;
22
-	protected static $registeredTemplate = array();
23
-
24
-	public function __construct ($file, Registry &$registry = null) {
25
-		if ($registry == null) {
26
-			$registry = Registry::singleton();
27
-		}
28
-
29
-		if (!class_exists("XTemplate", false)) {
30
-			require_once(ROOT_PATH . "system/packages/com.jukusoft.cms.xtpl/xtpl/xtemplate.class.php");
31
-		}
32
-
33
-		if (isset(self::$registeredTemplate[$file])) {
34
-			$file = self::$registeredTemplate[$file];
35
-		}
36
-
37
-		//find file
38
-		$file = self::findTemplate($file, $registry);
39
-
40
-		$this->template = new XTemplate($file);
41
-		$this->template->assign("REGISTRY", $registry->listSettings());
42
-
43
-		//set CSRF token
44
-		$this->template->assign("CSRF_TOKEN", Security::getCSRFToken());
45
-
46
-		//set domain, current page and so on
47
-		$this->template->assign("DOMAIN", DomainUtils::getCurrentDomain());
48
-		$this->template->assign("BASE_URL", DomainUtils::getBaseURL());
49
-		$this->template->assign("CURRENT_URL", DomainUtils::getURL());
50
-		$this->template->assign("FOLDER", $registry->getSetting("folder"));
51
-
52
-		//set language settings
53
-		$this->template->assign("PREF_LANG", $registry->getSetting("pref_lang"));
54
-		$this->template->assign("LANG_TOKEN", $registry->getSetting("lang_token"));
55
-
56
-		$redirect_url = urlencode(DomainUtils::getURL());
57
-
58
-		if (isset($_REQUEST['redirect_url']) && !empty($_REQUEST['redirect_url'])) {
59
-			$redirect_url = $_REQUEST['redirect_url'];
60
-		}
61
-
62
-		$domain = $registry->getObject("domain");
63
-		$this->template->assign("HOME_PAGE", $domain->getHomePage());
64
-		$this->template->assign("LOGIN_PAGE", Settings::get("login_page", "login"));
65
-		$this->template->assign("LOGIN_URL", DomainUtils::getBaseURL() . "/" . Settings::get("login_page", "login") . "?action=login&redirect_url=" . $redirect_url);
66
-		$this->template->assign("LOGOUT_PAGE", Settings::get("logout_page", "logout"));
67
-		$this->template->assign("LOGOUT_URL", DomainUtils::getBaseURL() . "/" . Settings::get("logout_page", "logout") . "?csrf_token=" . urlencode(Security::getCSRFToken()));
68
-
69
-		//set user variables
70
-		$this->template->assign("USERID", User::current()->getID());
71
-		$this->template->assign("USERNAME", User::current()->getUsername());
72
-
73
-		$style_name = $registry->getSetting("current_style_name");
74
-		$this->template->assign("STYLE_PATH",DomainUtils::getBaseURL() . "/styles/" . $style_name . "/");
75
-
76
-		Events::throwEvent("init_template", array(
77
-			'file' => &$file,
78
-			'template' => &$this,
79
-			'template_instance' => &$this->template,
80
-			'registry' => &$registry
81
-		));
82
-
83
-	}
84
-
85
-	public function assign ($var, $value) {
86
-		$this->template->assign($var, $value);
87
-	}
88
-
89
-	public function parse ($name = "main") {
90
-		$this->template->parse($name);
91
-	}
92
-
93
-	public function getCode ($name = "main") {
94
-		return $this->template->text($name);
95
-	}
96
-
97
-	public static function registerTemplate ($template, $file) {
98
-		self::$registeredTemplate[$template] = $file;
99
-	}
100
-
101
-	public static function clearTemplates () {
102
-		self::$registeredTemplate = array();
103
-	}
104
-
105
-	public static function createTemplate ($file) {
106
-		$class = (String) __CLASS__;
107
-		return new $class($file);
108
-	}
109
-
110
-	public static function getName () {
111
-		return __CLASS__;
112
-	}
113
-
114
-	public static function findTemplate (string $tpl_name, Registry &$registry) : string {
115
-		if (strpos($tpl_name, ".tpl") !== FALSE) {
116
-			//remove file extension
117
-			$tpl_name = str_replace(".tpl", "", $tpl_name);
118
-		}
119
-
120
-		//check, if file path was set
121
-		if (file_exists($tpl_name . ".tpl")) {
122
-			return $tpl_name . ".tpl";
123
-		}
124
-
125
-		//find file
126
-		$current_style = $registry->getSetting("current_style_name");
127
-		$style_path = STYLE_PATH . $current_style . "/";
128
-
129
-		$array = explode("_", $tpl_name);
130
-
131
-		if (sizeof($array) == 3) {
132
-			//plugin or style template
133
-			if ($array[0] === "plugin") {
134
-				return PLUGIN_PATH . $array[1] . "/templates/" . $array[2] . ".tpl";
135
-			} else {
136
-				throw new Exception("templates with 2 '_' (expect 'plugin') arent supported yet.");
137
-			}
138
-		} else if (sizeof($array) == 1) {
139
-			//search in style path
140
-			if (file_exists($style_path . $tpl_name . ".tpl")) {
141
-				return $style_path . $tpl_name . ".tpl";
142
-			} else if (file_exists(STYLE_PATH . "default/" . $tpl_name . ".tpl")) {
143
-				//use default template
144
-				return STYLE_PATH . "default/" . $tpl_name . ".tpl";
145
-			} else {
146
-				throw new Exception("Coulnd't found template '" . $tpl_name . "' (search path: '" . $style_path . $tpl_name . ".tpl" . "'!");
147
-			}
148
-		} else {
149
-			throw new IllegalStateException("Coulndt found template file '" . $tpl_name . "', because unknown array size: " . sizeof($array));
150
-		}
151
-	}
21
+    protected $template = null;
22
+    protected static $registeredTemplate = array();
23
+
24
+    public function __construct ($file, Registry &$registry = null) {
25
+        if ($registry == null) {
26
+            $registry = Registry::singleton();
27
+        }
28
+
29
+        if (!class_exists("XTemplate", false)) {
30
+            require_once(ROOT_PATH . "system/packages/com.jukusoft.cms.xtpl/xtpl/xtemplate.class.php");
31
+        }
32
+
33
+        if (isset(self::$registeredTemplate[$file])) {
34
+            $file = self::$registeredTemplate[$file];
35
+        }
36
+
37
+        //find file
38
+        $file = self::findTemplate($file, $registry);
39
+
40
+        $this->template = new XTemplate($file);
41
+        $this->template->assign("REGISTRY", $registry->listSettings());
42
+
43
+        //set CSRF token
44
+        $this->template->assign("CSRF_TOKEN", Security::getCSRFToken());
45
+
46
+        //set domain, current page and so on
47
+        $this->template->assign("DOMAIN", DomainUtils::getCurrentDomain());
48
+        $this->template->assign("BASE_URL", DomainUtils::getBaseURL());
49
+        $this->template->assign("CURRENT_URL", DomainUtils::getURL());
50
+        $this->template->assign("FOLDER", $registry->getSetting("folder"));
51
+
52
+        //set language settings
53
+        $this->template->assign("PREF_LANG", $registry->getSetting("pref_lang"));
54
+        $this->template->assign("LANG_TOKEN", $registry->getSetting("lang_token"));
55
+
56
+        $redirect_url = urlencode(DomainUtils::getURL());
57
+
58
+        if (isset($_REQUEST['redirect_url']) && !empty($_REQUEST['redirect_url'])) {
59
+            $redirect_url = $_REQUEST['redirect_url'];
60
+        }
61
+
62
+        $domain = $registry->getObject("domain");
63
+        $this->template->assign("HOME_PAGE", $domain->getHomePage());
64
+        $this->template->assign("LOGIN_PAGE", Settings::get("login_page", "login"));
65
+        $this->template->assign("LOGIN_URL", DomainUtils::getBaseURL() . "/" . Settings::get("login_page", "login") . "?action=login&redirect_url=" . $redirect_url);
66
+        $this->template->assign("LOGOUT_PAGE", Settings::get("logout_page", "logout"));
67
+        $this->template->assign("LOGOUT_URL", DomainUtils::getBaseURL() . "/" . Settings::get("logout_page", "logout") . "?csrf_token=" . urlencode(Security::getCSRFToken()));
68
+
69
+        //set user variables
70
+        $this->template->assign("USERID", User::current()->getID());
71
+        $this->template->assign("USERNAME", User::current()->getUsername());
72
+
73
+        $style_name = $registry->getSetting("current_style_name");
74
+        $this->template->assign("STYLE_PATH",DomainUtils::getBaseURL() . "/styles/" . $style_name . "/");
75
+
76
+        Events::throwEvent("init_template", array(
77
+            'file' => &$file,
78
+            'template' => &$this,
79
+            'template_instance' => &$this->template,
80
+            'registry' => &$registry
81
+        ));
82
+
83
+    }
84
+
85
+    public function assign ($var, $value) {
86
+        $this->template->assign($var, $value);
87
+    }
88
+
89
+    public function parse ($name = "main") {
90
+        $this->template->parse($name);
91
+    }
92
+
93
+    public function getCode ($name = "main") {
94
+        return $this->template->text($name);
95
+    }
96
+
97
+    public static function registerTemplate ($template, $file) {
98
+        self::$registeredTemplate[$template] = $file;
99
+    }
100
+
101
+    public static function clearTemplates () {
102
+        self::$registeredTemplate = array();
103
+    }
104
+
105
+    public static function createTemplate ($file) {
106
+        $class = (String) __CLASS__;
107
+        return new $class($file);
108
+    }
109
+
110
+    public static function getName () {
111
+        return __CLASS__;
112
+    }
113
+
114
+    public static function findTemplate (string $tpl_name, Registry &$registry) : string {
115
+        if (strpos($tpl_name, ".tpl") !== FALSE) {
116
+            //remove file extension
117
+            $tpl_name = str_replace(".tpl", "", $tpl_name);
118
+        }
119
+
120
+        //check, if file path was set
121
+        if (file_exists($tpl_name . ".tpl")) {
122
+            return $tpl_name . ".tpl";
123
+        }
124
+
125
+        //find file
126
+        $current_style = $registry->getSetting("current_style_name");
127
+        $style_path = STYLE_PATH . $current_style . "/";
128
+
129
+        $array = explode("_", $tpl_name);
130
+
131
+        if (sizeof($array) == 3) {
132
+            //plugin or style template
133
+            if ($array[0] === "plugin") {
134
+                return PLUGIN_PATH . $array[1] . "/templates/" . $array[2] . ".tpl";
135
+            } else {
136
+                throw new Exception("templates with 2 '_' (expect 'plugin') arent supported yet.");
137
+            }
138
+        } else if (sizeof($array) == 1) {
139
+            //search in style path
140
+            if (file_exists($style_path . $tpl_name . ".tpl")) {
141
+                return $style_path . $tpl_name . ".tpl";
142
+            } else if (file_exists(STYLE_PATH . "default/" . $tpl_name . ".tpl")) {
143
+                //use default template
144
+                return STYLE_PATH . "default/" . $tpl_name . ".tpl";
145
+            } else {
146
+                throw new Exception("Coulnd't found template '" . $tpl_name . "' (search path: '" . $style_path . $tpl_name . ".tpl" . "'!");
147
+            }
148
+        } else {
149
+            throw new IllegalStateException("Coulndt found template file '" . $tpl_name . "', because unknown array size: " . sizeof($array));
150
+        }
151
+    }
152 152
 
153 153
 }
154 154
 
Please login to merge, or discard this patch.