Completed
Push — master ( 945d9a...e5db64 )
by Schlaefer
02:51
created
app/Lib/Saito/User/SaitoUserTrait.php 3 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 
5 5
 	trait SaitoUserTrait {
6 6
 
7
-		static private $__accessions = array (
7
+		static private $__accessions = array(
8 8
 			'anon'	=> 0,
9 9
 			'user'	=> 1,
10 10
 			'mod'		=> 2,
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 			}
47 47
 
48 48
 			if (empty($user['id']) === false) {
49
-				$this->_id = (int)$user['id'];
49
+				$this->_id = (int) $user['id'];
50 50
 				$this->_isLoggedIn = true;
51 51
 			}
52 52
 
@@ -75,12 +75,12 @@  discard block
 block discarded – undo
75 75
 			if (is_int($user)) {
76 76
 				$id = $user;
77 77
 			} elseif (is_string($user)) {
78
-				$id = (int)$user;
78
+				$id = (int) $user;
79 79
 			} elseif (is_array($user)) {
80 80
 				if (isset($user['User']['id'])) {
81
-					$id = (int)$user['User']['id'];
81
+					$id = (int) $user['User']['id'];
82 82
 				} elseif (isset($user['id'])) {
83
-					$id = (int)$user['id'];
83
+					$id = (int) $user['id'];
84 84
 				}
85 85
 			} elseif ($user instanceof ForumsUserInterface) {
86 86
 				$id = $user->getId();
Please login to merge, or discard this patch.
Indentation   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -1,198 +1,198 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-	namespace Saito\User;
4
-
5
-	trait SaitoUserTrait {
6
-
7
-		static private $__accessions = array (
8
-			'anon'	=> 0,
9
-			'user'	=> 1,
10
-			'mod'		=> 2,
11
-			'admin'	=> 3,
12
-		);
13
-
14
-		/**
15
-		 * User ID
16
-		 *
17
-		 * @var int
18
-		 */
19
-		protected $_id = null;
20
-
21
-		/**
22
-		 * Stores if a user is logged in
23
-		 *
24
-		 * @var bool
25
-		 */
26
-		protected $_isLoggedIn = false;
27
-
28
-
29
-		/**
30
-		 * User settings
31
-		 *
32
-		 * @var array
33
-		 */
34
-		protected $_settings = null;
35
-
36
-		public function setSettings($user) {
37
-			if (empty($user)) {
38
-				$this->_id = null;
39
-				$this->_settings = null;
40
-				$this->_isLoggedIn = false;
41
-				return false;
42
-			}
43
-
44
-			if (empty($user) || !is_array($user)) {
45
-				trigger_error("Can't find user.");
46
-			}
47
-
48
-			if (empty($user['id']) === false) {
49
-				$this->_id = (int)$user['id'];
50
-				$this->_isLoggedIn = true;
51
-			}
52
-
53
-			$this->_settings = $user;
54
-
55
-			// perf-cheat
56
-			if (array_key_exists('last_refresh', $this->_settings)) {
57
-				$this->_settings['last_refresh_unix'] = strtotime($this->_settings['last_refresh']);
58
-			}
59
-		}
60
-
61
-		public function getSettings() {
62
-			return $this->_settings;
63
-		}
64
-
65
-		public function getId() {
66
-			return $this->_id;
67
-		}
68
-
69
-		public function isLoggedIn() {
70
-			return $this->_isLoggedIn;
71
-		}
72
-
73
-		public function isSame($user) {
74
-			$id = null;
75
-			if (is_int($user)) {
76
-				$id = $user;
77
-			} elseif (is_string($user)) {
78
-				$id = (int)$user;
79
-			} elseif (is_array($user)) {
80
-				if (isset($user['User']['id'])) {
81
-					$id = (int)$user['User']['id'];
82
-				} elseif (isset($user['id'])) {
83
-					$id = (int)$user['id'];
84
-				}
85
-			} elseif ($user instanceof ForumsUserInterface) {
86
-				$id = $user->getId();
87
-			}
88
-			return $id === $this->getId();
89
-		}
90
-
91
-		public function isUser() {
92
-			return self::_isUserForRole($this->_settings['user_type']);
93
-		}
94
-
95
-		public function isMod() {
96
-			return self::_isModForRole($this->_settings['user_type']);
97
-		}
98
-
99
-		public function isModOnly() {
100
-			return self::$__accessions[$this->_getRole()] === 2;
101
-		}
102
-
103
-		/**
104
-		 * checks if current user ignores user with ID $userId
105
-		 *
106
-		 * @param int $userId
107
-		 * @return bool
108
-		 */
109
-		public function ignores($userId) {
110
-			if (!$this->isLoggedIn()) {
111
-				return false;
112
-			}
113
-			return isset($this->_settings['ignores'][$userId]);
114
-		}
115
-
116
-		public function isAdmin() {
117
-			return self::_isAdminForRole($this->_settings['user_type']);
118
-		}
119
-
120
-		public function isForbidden() {
121
-			if (!empty($this->_settings['user_lock'])) {
122
-				return 'locked';
123
-			}
124
-			if (!empty($this->_settings['activate_code'])) {
125
-				return 'unactivated';
126
-			}
127
-			return false;
128
-		}
129
-
130
-		public function mockUserType($type) {
131
-			$MockedUser = clone $this;
132
-			$MockedUser['user_type'] = $type;
133
-			return $MockedUser;
134
-		}
135
-
136
-		protected function _getRole() {
137
-			if ($this->_id === null) {
138
-				return 'anon';
139
-			} else {
140
-				return $this->_settings['user_type'];
141
-			}
142
-		}
143
-
144
-		protected static function _isUserForRole($userType) {
145
-			$accession = self::_maxAccessionForUserType($userType);
146
-			return ($accession >= 1) ? true : false;
147
-		}
148
-
149
-		protected static function _isModForRole($userType) {
150
-			$accession = self::_maxAccessionForUserType($userType);
151
-			return ($accession >= 2) ? true : false;
152
-		}
153
-
154
-		protected static function _isAdminForRole($userType) {
155
-			$accession = self::_maxAccessionForUserType($userType);
156
-			return ($accession === 3) ? true : false;
157
-		}
158
-
159
-		/**
160
-		 * Get maximum value of the allowed accession
161
-		 *
162
-		 * Very handy for DB requests
163
-		 *
164
-		 * @mlf some day we will have user->type->accession->categories tables and relations,
165
-		 * that will be an happy day
166
-		 *
167
-		 * @return int
168
-		 */
169
-		public function getMaxAccession() {
170
-			$userType = $this->_getRole();
171
-			return self::_maxAccessionForUserType($userType);
172
-		}
173
-
174
-		protected static function _maxAccessionForUserType($userType) {
175
-			if (isset(self::$__accessions[$userType])) :
176
-				return self::$__accessions[$userType];
177
-			else :
178
-				return 0;
179
-			endif;
180
-		}
181
-
182
-		public function offsetExists($offset) {
183
-			return isset($this->_settings[$offset]);
184
-		}
185
-
186
-		public function offsetGet($offset) {
187
-			return $this->_settings[$offset];
188
-		}
189
-
190
-		public function offsetSet($offset, $value) {
191
-			$this->_settings[$offset] = $value;
192
-		}
193
-
194
-		public function offsetUnset($offset) {
195
-			unset($this->_settings[$offset]);
196
-		}
197
-
198
-	}
199 3
\ No newline at end of file
4
+    namespace Saito\User;
5
+
6
+    trait SaitoUserTrait {
7
+
8
+        static private $__accessions = array (
9
+            'anon'	=> 0,
10
+            'user'	=> 1,
11
+            'mod'		=> 2,
12
+            'admin'	=> 3,
13
+        );
14
+
15
+        /**
16
+         * User ID
17
+         *
18
+         * @var int
19
+         */
20
+        protected $_id = null;
21
+
22
+        /**
23
+         * Stores if a user is logged in
24
+         *
25
+         * @var bool
26
+         */
27
+        protected $_isLoggedIn = false;
28
+
29
+
30
+        /**
31
+         * User settings
32
+         *
33
+         * @var array
34
+         */
35
+        protected $_settings = null;
36
+
37
+        public function setSettings($user) {
38
+            if (empty($user)) {
39
+                $this->_id = null;
40
+                $this->_settings = null;
41
+                $this->_isLoggedIn = false;
42
+                return false;
43
+            }
44
+
45
+            if (empty($user) || !is_array($user)) {
46
+                trigger_error("Can't find user.");
47
+            }
48
+
49
+            if (empty($user['id']) === false) {
50
+                $this->_id = (int)$user['id'];
51
+                $this->_isLoggedIn = true;
52
+            }
53
+
54
+            $this->_settings = $user;
55
+
56
+            // perf-cheat
57
+            if (array_key_exists('last_refresh', $this->_settings)) {
58
+                $this->_settings['last_refresh_unix'] = strtotime($this->_settings['last_refresh']);
59
+            }
60
+        }
61
+
62
+        public function getSettings() {
63
+            return $this->_settings;
64
+        }
65
+
66
+        public function getId() {
67
+            return $this->_id;
68
+        }
69
+
70
+        public function isLoggedIn() {
71
+            return $this->_isLoggedIn;
72
+        }
73
+
74
+        public function isSame($user) {
75
+            $id = null;
76
+            if (is_int($user)) {
77
+                $id = $user;
78
+            } elseif (is_string($user)) {
79
+                $id = (int)$user;
80
+            } elseif (is_array($user)) {
81
+                if (isset($user['User']['id'])) {
82
+                    $id = (int)$user['User']['id'];
83
+                } elseif (isset($user['id'])) {
84
+                    $id = (int)$user['id'];
85
+                }
86
+            } elseif ($user instanceof ForumsUserInterface) {
87
+                $id = $user->getId();
88
+            }
89
+            return $id === $this->getId();
90
+        }
91
+
92
+        public function isUser() {
93
+            return self::_isUserForRole($this->_settings['user_type']);
94
+        }
95
+
96
+        public function isMod() {
97
+            return self::_isModForRole($this->_settings['user_type']);
98
+        }
99
+
100
+        public function isModOnly() {
101
+            return self::$__accessions[$this->_getRole()] === 2;
102
+        }
103
+
104
+        /**
105
+         * checks if current user ignores user with ID $userId
106
+         *
107
+         * @param int $userId
108
+         * @return bool
109
+         */
110
+        public function ignores($userId) {
111
+            if (!$this->isLoggedIn()) {
112
+                return false;
113
+            }
114
+            return isset($this->_settings['ignores'][$userId]);
115
+        }
116
+
117
+        public function isAdmin() {
118
+            return self::_isAdminForRole($this->_settings['user_type']);
119
+        }
120
+
121
+        public function isForbidden() {
122
+            if (!empty($this->_settings['user_lock'])) {
123
+                return 'locked';
124
+            }
125
+            if (!empty($this->_settings['activate_code'])) {
126
+                return 'unactivated';
127
+            }
128
+            return false;
129
+        }
130
+
131
+        public function mockUserType($type) {
132
+            $MockedUser = clone $this;
133
+            $MockedUser['user_type'] = $type;
134
+            return $MockedUser;
135
+        }
136
+
137
+        protected function _getRole() {
138
+            if ($this->_id === null) {
139
+                return 'anon';
140
+            } else {
141
+                return $this->_settings['user_type'];
142
+            }
143
+        }
144
+
145
+        protected static function _isUserForRole($userType) {
146
+            $accession = self::_maxAccessionForUserType($userType);
147
+            return ($accession >= 1) ? true : false;
148
+        }
149
+
150
+        protected static function _isModForRole($userType) {
151
+            $accession = self::_maxAccessionForUserType($userType);
152
+            return ($accession >= 2) ? true : false;
153
+        }
154
+
155
+        protected static function _isAdminForRole($userType) {
156
+            $accession = self::_maxAccessionForUserType($userType);
157
+            return ($accession === 3) ? true : false;
158
+        }
159
+
160
+        /**
161
+         * Get maximum value of the allowed accession
162
+         *
163
+         * Very handy for DB requests
164
+         *
165
+         * @mlf some day we will have user->type->accession->categories tables and relations,
166
+         * that will be an happy day
167
+         *
168
+         * @return int
169
+         */
170
+        public function getMaxAccession() {
171
+            $userType = $this->_getRole();
172
+            return self::_maxAccessionForUserType($userType);
173
+        }
174
+
175
+        protected static function _maxAccessionForUserType($userType) {
176
+            if (isset(self::$__accessions[$userType])) :
177
+                return self::$__accessions[$userType];
178
+            else :
179
+                return 0;
180
+            endif;
181
+        }
182
+
183
+        public function offsetExists($offset) {
184
+            return isset($this->_settings[$offset]);
185
+        }
186
+
187
+        public function offsetGet($offset) {
188
+            return $this->_settings[$offset];
189
+        }
190
+
191
+        public function offsetSet($offset, $value) {
192
+            $this->_settings[$offset] = $value;
193
+        }
194
+
195
+        public function offsetUnset($offset) {
196
+            unset($this->_settings[$offset]);
197
+        }
198
+
199
+    }
200 200
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -174,8 +174,10 @@
 block discarded – undo
174 174
 		protected static function _maxAccessionForUserType($userType) {
175 175
 			if (isset(self::$__accessions[$userType])) :
176 176
 				return self::$__accessions[$userType];
177
-			else :
177
+			else {
178
+			    :
178 179
 				return 0;
180
+			}
179 181
 			endif;
180 182
 		}
181 183
 
Please login to merge, or discard this patch.
app/Lib/Saito/User/Categories.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -18,15 +18,15 @@
 block discarded – undo
18 18
 		}
19 19
 
20 20
 		protected function _isAll() {
21
-			return (int)$this->_user['user_category_active'] === -1;
21
+			return (int) $this->_user['user_category_active'] === -1;
22 22
 		}
23 23
 
24 24
 		protected function _isSingle() {
25
-			return (int)$this->_user['user_category_active'] > 0;
25
+			return (int) $this->_user['user_category_active'] > 0;
26 26
 		}
27 27
 
28 28
 		protected function _isCustom() {
29
-			return (int)$this->_user['user_category_active'] == 0 &&
29
+			return (int) $this->_user['user_category_active'] == 0 &&
30 30
 			empty($this->_user['user_category_custom']) === false;
31 31
 		}
32 32
 
Please login to merge, or discard this patch.
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -1,60 +1,60 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-	namespace Saito\User;
3
+    namespace Saito\User;
4 4
 
5
-	class Categories {
5
+    class Categories {
6 6
 
7
-		protected $_user;
7
+        protected $_user;
8 8
 
9
-		protected $_categories;
9
+        protected $_categories;
10 10
 
11 11
 /**
12 12
  * @param array $user
13 13
  * @param array $categories
14 14
  */
15
-		public function __construct(array $user, array $categories) {
16
-			$this->_user = $user;
17
-			$this->_categories = $categories;
18
-		}
15
+        public function __construct(array $user, array $categories) {
16
+            $this->_user = $user;
17
+            $this->_categories = $categories;
18
+        }
19 19
 
20
-		protected function _isAll() {
21
-			return (int)$this->_user['user_category_active'] === -1;
22
-		}
20
+        protected function _isAll() {
21
+            return (int)$this->_user['user_category_active'] === -1;
22
+        }
23 23
 
24
-		protected function _isSingle() {
25
-			return (int)$this->_user['user_category_active'] > 0;
26
-		}
24
+        protected function _isSingle() {
25
+            return (int)$this->_user['user_category_active'] > 0;
26
+        }
27 27
 
28
-		protected function _isCustom() {
29
-			return (int)$this->_user['user_category_active'] == 0 &&
30
-			empty($this->_user['user_category_custom']) === false;
31
-		}
28
+        protected function _isCustom() {
29
+            return (int)$this->_user['user_category_active'] == 0 &&
30
+            empty($this->_user['user_category_custom']) === false;
31
+        }
32 32
 
33
-		protected function _filterOutNonExisting($categories) {
34
-			return array_intersect_key($categories, $this->_categories);
35
-		}
33
+        protected function _filterOutNonExisting($categories) {
34
+            return array_intersect_key($categories, $this->_categories);
35
+        }
36 36
 
37
-		protected function _getCustom() {
38
-			// add new categories to custom set
39
-			//
40
-			// [4 => true, 7 => '0'] + [4 => '4', 7 => '7', 13 => '13']
41
-			// becomes
42
-			// [4 => true, 7 => '0', 13 => '13']
43
-			// with 13 => '13' trueish
44
-			if (empty($this->_user['user_category_custom'])) {
45
-				$this->_user['user_category_custom'] = [];
46
-			}
47
-			$custom = $this->_user['user_category_custom'] + $this->_categories;
37
+        protected function _getCustom() {
38
+            // add new categories to custom set
39
+            //
40
+            // [4 => true, 7 => '0'] + [4 => '4', 7 => '7', 13 => '13']
41
+            // becomes
42
+            // [4 => true, 7 => '0', 13 => '13']
43
+            // with 13 => '13' trueish
44
+            if (empty($this->_user['user_category_custom'])) {
45
+                $this->_user['user_category_custom'] = [];
46
+            }
47
+            $custom = $this->_user['user_category_custom'] + $this->_categories;
48 48
 
49
-			// then filter for zeros to get only the user categories
50
-			//  [4 => true, 13 => '13']
51
-			$custom = array_filter($custom);
49
+            // then filter for zeros to get only the user categories
50
+            //  [4 => true, 13 => '13']
51
+            $custom = array_filter($custom);
52 52
 
53
-			$custom = $this->_filterOutNonExisting($custom);
53
+            $custom = $this->_filterOutNonExisting($custom);
54 54
 
55
-			$keys = array_keys($custom);
56
-			return array_combine($keys, $keys);
57
-		}
55
+            $keys = array_keys($custom);
56
+            return array_combine($keys, $keys);
57
+        }
58 58
 
59 59
 /**
60 60
  * @return array
@@ -63,21 +63,21 @@  discard block
 block discarded – undo
63 63
  * $type: active type: 'all', 'single' or 'custom'
64 64
  * $custom: categories for 'custom' [cat_id1, cat_id2, …]
65 65
  */
66
-		public function get() {
67
-			$custom = $this->_getCustom();
68
-			if ($this->_isSingle()) {
69
-				$type = 'single';
70
-				$categories = $this->_filterOutNonExisting(
71
-					[$this->_user['user_category_active'] => $this->_user['user_category_active']]
72
-				);
73
-			} elseif ($this->_isCustom()) {
74
-				$type = 'custom';
75
-				$categories = $custom;
76
-			} else {
77
-				$type = 'all';
78
-				$categories = $this->_categories;
79
-			}
80
-			return [$categories, $type, $custom];
81
-		}
66
+        public function get() {
67
+            $custom = $this->_getCustom();
68
+            if ($this->_isSingle()) {
69
+                $type = 'single';
70
+                $categories = $this->_filterOutNonExisting(
71
+                    [$this->_user['user_category_active'] => $this->_user['user_category_active']]
72
+                );
73
+            } elseif ($this->_isCustom()) {
74
+                $type = 'custom';
75
+                $categories = $custom;
76
+            } else {
77
+                $type = 'all';
78
+                $categories = $this->_categories;
79
+            }
80
+            return [$categories, $type, $custom];
81
+        }
82 82
 
83
-	}
83
+    }
Please login to merge, or discard this patch.
app/Lib/Saito/User/Bookmarks.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@
 block discarded – undo
40 40
 				);
41 41
 				if (!empty($bookmarks)) {
42 42
 					foreach ($bookmarks as $bookmark) {
43
-						$this->_bookmarks[(int)$bookmark['Bookmark']['entry_id']] = (int)$bookmark['Bookmark']['id'];
43
+						$this->_bookmarks[(int) $bookmark['Bookmark']['entry_id']] = (int) $bookmark['Bookmark']['id'];
44 44
 					}
45 45
 				}
46 46
 			}
Please login to merge, or discard this patch.
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -1,50 +1,50 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-	namespace Saito\User;
4
-
5
-	/**
6
-	 * Class Bookmarks handles bookmarks for a CurrentUser
7
-	 */
8
-	class Bookmarks {
9
-
10
-		/**
11
-		 * @var bookmarks format: [entry_id => id, …]
12
-		 */
13
-		protected $_bookmarks;
14
-
15
-		protected $_CurrentUser;
16
-
17
-		public function __construct(\CurrentUserComponent $CurrentUser) {
18
-			$this->_CurrentUser = $CurrentUser;
19
-		}
20
-
21
-		public function isBookmarked($entryId) {
22
-			if (!$this->_CurrentUser->isLoggedIn()) {
23
-				return false;
24
-			}
25
-			if ($this->_bookmarks === null) {
26
-				$this->_get();
27
-			}
28
-			return isset($this->_bookmarks[$entryId]);
29
-		}
30
-
31
-		protected function _get() {
32
-			if ($this->_bookmarks !== null) {
33
-				return $this->_bookmarks;
34
-			}
35
-			$this->_bookmarks = [];
36
-			if (!$this->_CurrentUser->isLoggedIn() === false) {
37
-				$bookmarks = $this->_CurrentUser->_User->Bookmark->findAllByUserId(
38
-					$this->_CurrentUser->getId(),
39
-					['contain' => false]
40
-				);
41
-				if (!empty($bookmarks)) {
42
-					foreach ($bookmarks as $bookmark) {
43
-						$this->_bookmarks[(int)$bookmark['Bookmark']['entry_id']] = (int)$bookmark['Bookmark']['id'];
44
-					}
45
-				}
46
-			}
47
-			return $this->_bookmarks;
48
-		}
49
-
50
-	}
3
+    namespace Saito\User;
4
+
5
+    /**
6
+     * Class Bookmarks handles bookmarks for a CurrentUser
7
+     */
8
+    class Bookmarks {
9
+
10
+        /**
11
+         * @var bookmarks format: [entry_id => id, …]
12
+         */
13
+        protected $_bookmarks;
14
+
15
+        protected $_CurrentUser;
16
+
17
+        public function __construct(\CurrentUserComponent $CurrentUser) {
18
+            $this->_CurrentUser = $CurrentUser;
19
+        }
20
+
21
+        public function isBookmarked($entryId) {
22
+            if (!$this->_CurrentUser->isLoggedIn()) {
23
+                return false;
24
+            }
25
+            if ($this->_bookmarks === null) {
26
+                $this->_get();
27
+            }
28
+            return isset($this->_bookmarks[$entryId]);
29
+        }
30
+
31
+        protected function _get() {
32
+            if ($this->_bookmarks !== null) {
33
+                return $this->_bookmarks;
34
+            }
35
+            $this->_bookmarks = [];
36
+            if (!$this->_CurrentUser->isLoggedIn() === false) {
37
+                $bookmarks = $this->_CurrentUser->_User->Bookmark->findAllByUserId(
38
+                    $this->_CurrentUser->getId(),
39
+                    ['contain' => false]
40
+                );
41
+                if (!empty($bookmarks)) {
42
+                    foreach ($bookmarks as $bookmark) {
43
+                        $this->_bookmarks[(int)$bookmark['Bookmark']['entry_id']] = (int)$bookmark['Bookmark']['id'];
44
+                    }
45
+                }
46
+            }
47
+            return $this->_bookmarks;
48
+        }
49
+
50
+    }
Please login to merge, or discard this patch.
app/Lib/Saito/Markup/Parser.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -67,13 +67,13 @@
 block discarded – undo
67 67
 					}
68 68
 					// add newline to wrapped lines
69 69
 					if (mb_strlen($line) > 60) {
70
-						$out .= $line . "\n";
70
+						$out .= $line."\n";
71 71
 						$line = '';
72 72
 					}
73 73
 				}
74 74
 				$out .= $line;
75 75
 			endforeach;
76
-			$out = preg_replace("/^/m", $this->_cSettings['quote_symbol'] . " ",
76
+			$out = preg_replace("/^/m", $this->_cSettings['quote_symbol']." ",
77 77
 				$out);
78 78
 			return $out;
79 79
 		}
Please login to merge, or discard this patch.
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -1,82 +1,82 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-	namespace Saito\Markup;
3
+    namespace Saito\Markup;
4 4
 
5
-	abstract class Parser {
5
+    abstract class Parser {
6 6
 
7
-		/**
8
-		 * @var array cache for app settings
9
-		 */
10
-		protected $_cSettings;
7
+        /**
8
+         * @var array cache for app settings
9
+         */
10
+        protected $_cSettings;
11 11
 
12
-		/**
13
-		 * @var Helper Helper usually the ParseHelper
14
-		 */
15
-		protected $_Helper;
12
+        /**
13
+         * @var Helper Helper usually the ParseHelper
14
+         */
15
+        protected $_Helper;
16 16
 
17
-		public function __construct(\Helper $Helper, array $settings = []) {
18
-			$this->_Helper = $Helper;
19
-			$this->_cSettings = $settings;
20
-		}
17
+        public function __construct(\Helper $Helper, array $settings = []) {
18
+            $this->_Helper = $Helper;
19
+            $this->_cSettings = $settings;
20
+        }
21 21
 
22
-		/**
23
-		 * should render the markup to HTML
24
-		 *
25
-		 * @param string $string unescaped markup
26
-		 * @param array $options
27
-		 * @return string !!Make sure to escape HTML special chars, or you'll have a bad day!!
28
-		 */
29
-		abstract public function parse($string, array $options = []);
22
+        /**
23
+         * should render the markup to HTML
24
+         *
25
+         * @param string $string unescaped markup
26
+         * @param array $options
27
+         * @return string !!Make sure to escape HTML special chars, or you'll have a bad day!!
28
+         */
29
+        abstract public function parse($string, array $options = []);
30 30
 
31
-		public function citeText($string) {
32
-			if (empty($string)) {
33
-				return '';
34
-			}
35
-			$out = '';
36
-			// split already quoted lines
37
-			$citeLines = preg_split("/(^{$this->_cSettings['quote_symbol']}.*?$\n)/m",
38
-				$string,
39
-				null,
40
-				PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
41
-			foreach ($citeLines as $citeLine):
42
-				if (mb_strpos($citeLine, $this->_cSettings['quote_symbol']) === 0) {
43
-					// already quoted lines need no further processing
44
-					$out .= $citeLine;
45
-					continue;
46
-				}
47
-				// split [bbcode]
48
-				$matches = preg_split('`(\[(.+?)=?.*?\].+?\[/\2\])`',
49
-					$citeLine,
50
-					null,
51
-					PREG_SPLIT_DELIM_CAPTURE);
52
-				$i = 0;
53
-				$line = '';
54
-				foreach ($matches as $match) {
55
-					// the [bbcode] preg_split uses a backreference \2 which is in the $matches
56
-					// but is not needed in the results
57
-					// @todo elegant solution
58
-					$i++;
59
-					if ($i % 3 == 0) {
60
-						continue;
61
-					}
62
-					// wrap long lines
63
-					if (mb_strpos($match, '[') !== 0) {
64
-						$line .= wordwrap($match);
65
-					} else {
66
-						$line .= $match;
67
-					}
68
-					// add newline to wrapped lines
69
-					if (mb_strlen($line) > 60) {
70
-						$out .= $line . "\n";
71
-						$line = '';
72
-					}
73
-				}
74
-				$out .= $line;
75
-			endforeach;
76
-			$out = preg_replace("/^/m", $this->_cSettings['quote_symbol'] . " ",
77
-				$out);
78
-			return $out;
79
-		}
31
+        public function citeText($string) {
32
+            if (empty($string)) {
33
+                return '';
34
+            }
35
+            $out = '';
36
+            // split already quoted lines
37
+            $citeLines = preg_split("/(^{$this->_cSettings['quote_symbol']}.*?$\n)/m",
38
+                $string,
39
+                null,
40
+                PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
41
+            foreach ($citeLines as $citeLine):
42
+                if (mb_strpos($citeLine, $this->_cSettings['quote_symbol']) === 0) {
43
+                    // already quoted lines need no further processing
44
+                    $out .= $citeLine;
45
+                    continue;
46
+                }
47
+                // split [bbcode]
48
+                $matches = preg_split('`(\[(.+?)=?.*?\].+?\[/\2\])`',
49
+                    $citeLine,
50
+                    null,
51
+                    PREG_SPLIT_DELIM_CAPTURE);
52
+                $i = 0;
53
+                $line = '';
54
+                foreach ($matches as $match) {
55
+                    // the [bbcode] preg_split uses a backreference \2 which is in the $matches
56
+                    // but is not needed in the results
57
+                    // @todo elegant solution
58
+                    $i++;
59
+                    if ($i % 3 == 0) {
60
+                        continue;
61
+                    }
62
+                    // wrap long lines
63
+                    if (mb_strpos($match, '[') !== 0) {
64
+                        $line .= wordwrap($match);
65
+                    } else {
66
+                        $line .= $match;
67
+                    }
68
+                    // add newline to wrapped lines
69
+                    if (mb_strlen($line) > 60) {
70
+                        $out .= $line . "\n";
71
+                        $line = '';
72
+                    }
73
+                }
74
+                $out .= $line;
75
+            endforeach;
76
+            $out = preg_replace("/^/m", $this->_cSettings['quote_symbol'] . " ",
77
+                $out);
78
+            return $out;
79
+        }
80 80
 
81
-	}
81
+    }
82 82
 
Please login to merge, or discard this patch.
app/Lib/Saito/Smiley/Renderer.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -93,11 +93,11 @@  discard block
 block discarded – undo
93 93
 		protected function _pregQuote(array &$codes) {
94 94
 			$delimiter = '/';
95 95
 			foreach ($codes as $key => $code) {
96
-				$codes[$key] = $delimiter .
96
+				$codes[$key] = $delimiter.
97 97
 					// a smiley can't be concatenated to a string and requires a
98 98
 					// whitespace in front
99
-					'(^|(?<=(\s)))' .
100
-					preg_quote($code, $delimiter) .
99
+					'(^|(?<=(\s)))'.
100
+					preg_quote($code, $delimiter).
101 101
 					$delimiter;
102 102
 			}
103 103
 		}
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 					//= pixel image smileys
122 122
 				} else {
123 123
 					$replacements['html'][$k] = $this->_Helper->Html->image(
124
-						'smilies/' . $smiley['image'],
124
+						'smilies/'.$smiley['image'],
125 125
 						[
126 126
 							'alt' => $smiley['code'],
127 127
 							'class' => 'saito-smiley-image',
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 				// $s['html'][] = $this->_Helper->Html->image('smilies/gacker_large.png');
153 153
 				if ($additionalButton['type'] === 'image') {
154 154
 					$additionalButton['replacement'] = $this->_Helper->Html->image(
155
-						'markitup' . DS . $additionalButton['replacement'],
155
+						'markitup'.DS.$additionalButton['replacement'],
156 156
 						['class' => 'saito-smiley-image']
157 157
 					);
158 158
 				}
Please login to merge, or discard this patch.
Indentation   +161 added lines, -161 removed lines patch added patch discarded remove patch
@@ -1,163 +1,163 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-	namespace Saito\Smiley;
4
-
5
-	class Renderer {
6
-
7
-		const DEBUG_SMILIES_KEY = ':smilies-debug:';
8
-
9
-		protected $_replacements;
10
-
11
-		/**
12
-		 * @var \Saito\Smiley\Cache
13
-		 */
14
-		protected $_smileyData;
15
-
16
-		protected $_useCache;
17
-
18
-		public function __construct($smileyData) {
19
-			$this->_smileyData = $smileyData;
20
-		}
21
-
22
-		/**
23
-		 * Replaces all smiley-codes in a string with appropriate HTML-tags
24
-		 *
25
-		 * @param $string
26
-		 * @return string
27
-		 * @throws \RuntimeException
28
-		 */
29
-		public function replace($string) {
30
-			$replacements = $this->_getReplacements();
31
-			$string = preg_replace(
32
-				$replacements['codes'],
33
-				$replacements['html'],
34
-				$string
35
-			);
36
-			if ($string === null) {
37
-				throw new \RuntimeException("Can't replace smilies. 1420630983");
38
-			}
39
-			$string = $this->_debug($string, $replacements);
40
-			return $string;
41
-		}
42
-
43
-		public function setHelper(\Helper $Helper) {
44
-			$this->_Helper = $Helper;
45
-		}
46
-
47
-		/**
48
-		 * outputs all available smilies :allSmilies:
49
-		 *
50
-		 * useful for debugging
51
-		 */
52
-		protected function _debug($string, $replacements) {
53
-			if (strpos($string, self::DEBUG_SMILIES_KEY) === false) {
54
-				return $string;
55
-			}
56
-			$smilies = $this->_smileyData->get();
57
-			$out[] = '<table class="table table-simple">';
58
-			$out[] = '<tr><th>Icon</th><th>Code</th><th>Image</th><th>Title</th></tr>';
59
-			foreach ($replacements['html'] as $k => $smiley) {
60
-				$title = $this->_l10n($smilies[$k]['title']);
61
-				$out[] = '<tr>';
62
-				$out[] = "<td>{$smiley}</td><td>{$smilies[$k]['code']}</td><td>{$smilies[$k]['image']}</td><td>{$title}</td>";
63
-				$out[] = '</tr>';
64
-			}
65
-			$out[] = '</table>';
66
-			return str_replace(self::DEBUG_SMILIES_KEY, implode('', $out), $string);
67
-		}
68
-
69
-		protected function _getReplacements() {
70
-			if (!$this->_replacements && $this->_useCache) {
71
-				$this->_replacements = Cache::read('Saito.Smilies.html');
72
-			}
73
-
74
-			if (!$this->_replacements) {
75
-				$this->_replacements = ['codes' => [], 'html' => []];
76
-				$this->_addSmilies($this->_replacements);
77
-				$this->_addAdditionalButtons($this->_replacements);
78
-				$this->_pregQuote($this->_replacements['codes']);
79
-
80
-				if ($this->_useCache) {
81
-					Cache::write('Saito.Smilies.html', $this->_replacements);
82
-				}
83
-			}
84
-
85
-			return $this->_replacements;
86
-		}
87
-
88
-		/**
89
-		 * prepares an array with smiliey-codes to be used in a preg_replace
90
-		 *
91
-		 * @param array $codes
92
-		 */
93
-		protected function _pregQuote(array &$codes) {
94
-			$delimiter = '/';
95
-			foreach ($codes as $key => $code) {
96
-				$codes[$key] = $delimiter .
97
-					// a smiley can't be concatenated to a string and requires a
98
-					// whitespace in front
99
-					'(^|(?<=(\s)))' .
100
-					preg_quote($code, $delimiter) .
101
-					$delimiter;
102
-			}
103
-		}
104
-
105
-		protected function _addSmilies(&$replacements) {
106
-			$smilies = $this->_smileyData->get();
107
-			foreach ($smilies as $k => $smiley) {
108
-				$replacements['codes'][] = $smiley['code'];
109
-				$title = $this->_l10n($smiley['title']);
110
-
111
-				//= vector font smileys
112
-				if ($smiley['type'] === 'font') {
113
-					$replacements['html'][$k] = $this->_Helper->Html->tag(
114
-						'i',
115
-						'',
116
-						[
117
-							'class' => "saito-smiley-font saito-smiley-{$smiley['image']}",
118
-							'title' => $title
119
-						]
120
-					);
121
-					//= pixel image smileys
122
-				} else {
123
-					$replacements['html'][$k] = $this->_Helper->Html->image(
124
-						'smilies/' . $smiley['image'],
125
-						[
126
-							'alt' => $smiley['code'],
127
-							'class' => 'saito-smiley-image',
128
-							'title' => $title
129
-						]
130
-					);
131
-				}
132
-			}
133
-		}
134
-
135
-		protected function _l10n($string) {
136
-			return __d('nondynamic', $string);
137
-		}
138
-
139
-		/**
140
-		 * Adds additional buttons from global config
141
-		 *
142
-		 * @param $replacements
143
-		 */
144
-		protected function _addAdditionalButtons(&$replacements) {
145
-			$additionalButtons = $this->_smileyData->getAdditionalSmilies();
146
-			if (empty($additionalButtons)) {
147
-				return;
148
-			}
149
-			foreach ($additionalButtons as $additionalButton) {
150
-				// $s['codes'][] = ':gacker:';
151
-				$replacements['codes'][] = $additionalButton['code'];
152
-				// $s['html'][] = $this->_Helper->Html->image('smilies/gacker_large.png');
153
-				if ($additionalButton['type'] === 'image') {
154
-					$additionalButton['replacement'] = $this->_Helper->Html->image(
155
-						'markitup' . DS . $additionalButton['replacement'],
156
-						['class' => 'saito-smiley-image']
157
-					);
158
-				}
159
-				$replacements['html'][] = $additionalButton['replacement'];
160
-			}
161
-		}
162
-
163
-	}
164 3
\ No newline at end of file
4
+    namespace Saito\Smiley;
5
+
6
+    class Renderer {
7
+
8
+        const DEBUG_SMILIES_KEY = ':smilies-debug:';
9
+
10
+        protected $_replacements;
11
+
12
+        /**
13
+         * @var \Saito\Smiley\Cache
14
+         */
15
+        protected $_smileyData;
16
+
17
+        protected $_useCache;
18
+
19
+        public function __construct($smileyData) {
20
+            $this->_smileyData = $smileyData;
21
+        }
22
+
23
+        /**
24
+         * Replaces all smiley-codes in a string with appropriate HTML-tags
25
+         *
26
+         * @param $string
27
+         * @return string
28
+         * @throws \RuntimeException
29
+         */
30
+        public function replace($string) {
31
+            $replacements = $this->_getReplacements();
32
+            $string = preg_replace(
33
+                $replacements['codes'],
34
+                $replacements['html'],
35
+                $string
36
+            );
37
+            if ($string === null) {
38
+                throw new \RuntimeException("Can't replace smilies. 1420630983");
39
+            }
40
+            $string = $this->_debug($string, $replacements);
41
+            return $string;
42
+        }
43
+
44
+        public function setHelper(\Helper $Helper) {
45
+            $this->_Helper = $Helper;
46
+        }
47
+
48
+        /**
49
+         * outputs all available smilies :allSmilies:
50
+         *
51
+         * useful for debugging
52
+         */
53
+        protected function _debug($string, $replacements) {
54
+            if (strpos($string, self::DEBUG_SMILIES_KEY) === false) {
55
+                return $string;
56
+            }
57
+            $smilies = $this->_smileyData->get();
58
+            $out[] = '<table class="table table-simple">';
59
+            $out[] = '<tr><th>Icon</th><th>Code</th><th>Image</th><th>Title</th></tr>';
60
+            foreach ($replacements['html'] as $k => $smiley) {
61
+                $title = $this->_l10n($smilies[$k]['title']);
62
+                $out[] = '<tr>';
63
+                $out[] = "<td>{$smiley}</td><td>{$smilies[$k]['code']}</td><td>{$smilies[$k]['image']}</td><td>{$title}</td>";
64
+                $out[] = '</tr>';
65
+            }
66
+            $out[] = '</table>';
67
+            return str_replace(self::DEBUG_SMILIES_KEY, implode('', $out), $string);
68
+        }
69
+
70
+        protected function _getReplacements() {
71
+            if (!$this->_replacements && $this->_useCache) {
72
+                $this->_replacements = Cache::read('Saito.Smilies.html');
73
+            }
74
+
75
+            if (!$this->_replacements) {
76
+                $this->_replacements = ['codes' => [], 'html' => []];
77
+                $this->_addSmilies($this->_replacements);
78
+                $this->_addAdditionalButtons($this->_replacements);
79
+                $this->_pregQuote($this->_replacements['codes']);
80
+
81
+                if ($this->_useCache) {
82
+                    Cache::write('Saito.Smilies.html', $this->_replacements);
83
+                }
84
+            }
85
+
86
+            return $this->_replacements;
87
+        }
88
+
89
+        /**
90
+         * prepares an array with smiliey-codes to be used in a preg_replace
91
+         *
92
+         * @param array $codes
93
+         */
94
+        protected function _pregQuote(array &$codes) {
95
+            $delimiter = '/';
96
+            foreach ($codes as $key => $code) {
97
+                $codes[$key] = $delimiter .
98
+                    // a smiley can't be concatenated to a string and requires a
99
+                    // whitespace in front
100
+                    '(^|(?<=(\s)))' .
101
+                    preg_quote($code, $delimiter) .
102
+                    $delimiter;
103
+            }
104
+        }
105
+
106
+        protected function _addSmilies(&$replacements) {
107
+            $smilies = $this->_smileyData->get();
108
+            foreach ($smilies as $k => $smiley) {
109
+                $replacements['codes'][] = $smiley['code'];
110
+                $title = $this->_l10n($smiley['title']);
111
+
112
+                //= vector font smileys
113
+                if ($smiley['type'] === 'font') {
114
+                    $replacements['html'][$k] = $this->_Helper->Html->tag(
115
+                        'i',
116
+                        '',
117
+                        [
118
+                            'class' => "saito-smiley-font saito-smiley-{$smiley['image']}",
119
+                            'title' => $title
120
+                        ]
121
+                    );
122
+                    //= pixel image smileys
123
+                } else {
124
+                    $replacements['html'][$k] = $this->_Helper->Html->image(
125
+                        'smilies/' . $smiley['image'],
126
+                        [
127
+                            'alt' => $smiley['code'],
128
+                            'class' => 'saito-smiley-image',
129
+                            'title' => $title
130
+                        ]
131
+                    );
132
+                }
133
+            }
134
+        }
135
+
136
+        protected function _l10n($string) {
137
+            return __d('nondynamic', $string);
138
+        }
139
+
140
+        /**
141
+         * Adds additional buttons from global config
142
+         *
143
+         * @param $replacements
144
+         */
145
+        protected function _addAdditionalButtons(&$replacements) {
146
+            $additionalButtons = $this->_smileyData->getAdditionalSmilies();
147
+            if (empty($additionalButtons)) {
148
+                return;
149
+            }
150
+            foreach ($additionalButtons as $additionalButton) {
151
+                // $s['codes'][] = ':gacker:';
152
+                $replacements['codes'][] = $additionalButton['code'];
153
+                // $s['html'][] = $this->_Helper->Html->image('smilies/gacker_large.png');
154
+                if ($additionalButton['type'] === 'image') {
155
+                    $additionalButton['replacement'] = $this->_Helper->Html->image(
156
+                        'markitup' . DS . $additionalButton['replacement'],
157
+                        ['class' => 'saito-smiley-image']
158
+                    );
159
+                }
160
+                $replacements['html'][] = $additionalButton['replacement'];
161
+            }
162
+        }
163
+
164
+    }
165 165
\ No newline at end of file
Please login to merge, or discard this patch.
app/Lib/Saito/Exception/SaitoBlackholeException.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@
 block discarded – undo
7 7
 	class SaitoBlackholeException extends \BadRequestException {
8 8
 
9 9
 		public function __construct($type = null, $data = []) {
10
-			$message = 'Request was blackholed. Type: ' . $type;
10
+			$message = 'Request was blackholed. Type: '.$type;
11 11
 			$this->__Logger = new ExceptionLogger;
12 12
 			$this->__Logger->write($message, $data);
13 13
 			parent::__construct($message, 400);
Please login to merge, or discard this patch.
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -1,17 +1,17 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-	namespace Saito\Exception;
3
+    namespace Saito\Exception;
4 4
 
5
-	use Saito\Exception\Logger\ExceptionLogger;
5
+    use Saito\Exception\Logger\ExceptionLogger;
6 6
 
7
-	class SaitoBlackholeException extends \BadRequestException {
7
+    class SaitoBlackholeException extends \BadRequestException {
8 8
 
9
-		public function __construct($type = null, $data = []) {
10
-			$message = 'Request was blackholed. Type: ' . $type;
11
-			$this->__Logger = new ExceptionLogger;
12
-			$this->__Logger->write($message, $data);
13
-			parent::__construct($message, 400);
14
-		}
9
+        public function __construct($type = null, $data = []) {
10
+            $message = 'Request was blackholed. Type: ' . $type;
11
+            $this->__Logger = new ExceptionLogger;
12
+            $this->__Logger->write($message, $data);
13
+            parent::__construct($message, 400);
14
+        }
15 15
 
16
-	}
16
+    }
17 17
 
Please login to merge, or discard this patch.
app/Lib/Saito/Exception/Logger/ExceptionLogger.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 
49 49
 			$requestMethod = $request ? $request->method() : false;
50 50
 			if ($url && $requestMethod) {
51
-				$url .= ' ' . $requestMethod;
51
+				$url .= ' '.$requestMethod;
52 52
 			}
53 53
 			if ($url) {
54 54
 				$this->_add($url, 'Request URL');
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 				$message[] = sprintf("  #%d %s", $i, $line);
126 126
 				$i++;
127 127
 			}
128
-			return "\n" . implode("\n", $message);
128
+			return "\n".implode("\n", $message);
129 129
 		}
130 130
 
131 131
 		protected function _add($val, $key = null, $prepend = false) {
Please login to merge, or discard this patch.
Indentation   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -1,147 +1,147 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-	namespace Saito\Exception\Logger;
4
-
5
-	\App::uses('CakeLog', 'Log');
6
-
7
-	class ExceptionLogger {
8
-
9
-		private $__lines = [];
10
-
11
-		/**
12
-		 * @param null $message
13
-		 * @param null $data
14
-		 * - `msgs` array with additional message-lines
15
-		 * @throws \InvalidArgumentException
16
-		 */
17
-		public function write($message, $data = null) {
18
-			//# process message(s)
19
-			$msgs = [$message];
20
-			if (isset($data['msgs'])) {
21
-				$msgs = array_merge($msgs, $data['msgs']);
22
-			}
23
-			// prepend main message in front of metadata added by subclasses
24
-			foreach (array_reverse($msgs) as $key => $msg) {
25
-				$this->_add($msg, $key, true);
26
-			}
27
-
28
-			//# add exception data
29
-			if (isset($data['e'])) {
30
-				/** @var $Exception \Exception */
31
-				$Exception = $data['e'];
32
-				unset($data['e']);
33
-				$message = $Exception->getMessage();
34
-				if (!empty($message)) {
35
-					$this->_add($message);
36
-				}
37
-			}
38
-
39
-			//# add request data
40
-			$request = (php_sapi_name() !== 'cli') ? \Router::getRequest() : false;
41
-
42
-			$url = false;
43
-			if (isset($data['URL'])) {
44
-				$url = $data['URL'];
45
-			} elseif ($request) {
46
-				$url = $request->here();
47
-			}
48
-
49
-			$requestMethod = $request ? $request->method() : false;
50
-			if ($url && $requestMethod) {
51
-				$url .= ' ' . $requestMethod;
52
-			}
53
-			if ($url) {
54
-				$this->_add($url, 'Request URL');
55
-			}
56
-
57
-			if (isset($_SERVER['HTTP_USER_AGENT'])) {
58
-				$this->_add($_SERVER['HTTP_USER_AGENT'], 'User-Agent');
59
-			}
60
-
61
-			$this->_addUser($data);
62
-
63
-			if (!empty($request->data)) {
64
-				$this->_add($this->_filterData($request->data), 'Data');
65
-			}
66
-
67
-			$this->_write();
68
-		}
69
-
70
-		/**
71
-		 * adds data about current user to log entry
72
-		 *
73
-		 * @param $data
74
-		 * @throws \InvalidArgumentException
75
-		 */
76
-		protected function _addUser($data) {
77
-			if (!isset($data['CurrentUser'])) {
78
-				return;
79
-			}
80
-			$CurrentUser = $data['CurrentUser'];
81
-			if (!is_a($data['CurrentUser'], 'CurrentUserComponent')) {
82
-				throw new \InvalidArgumentException;
83
-			}
84
-			if ($CurrentUser->isLoggedIn()) {
85
-				$username = "{$CurrentUser['username']} (id: {$CurrentUser['id']})";
86
-			} else {
87
-				$username = 'anonymous';
88
-			}
89
-			$this->_add($username, 'Current user');
90
-		}
91
-
92
-		/**
93
-		 * Filters request-data which should not be in server logs
94
-		 *
95
-		 * esp. cleartext passwords in $_POST data
96
-		 *
97
-		 * @param $data
98
-		 * @return array
99
-		 */
100
-		protected function _filterData($data) {
101
-			if (!is_array($data)) {
102
-				return $data;
103
-			}
104
-			foreach ($data as $key => $datum) {
105
-				if (is_array($datum)) {
106
-					$data[$key] = $this->_filterData($datum);
107
-					continue;
108
-				}
109
-
110
-				if (stripos($key, 'password') !== false) {
111
-					$data[$key] = '***********';
112
-				}
113
-			}
114
-			return $data;
115
-		}
116
-
117
-		protected function _write() {
118
-			\CakeLog::write('saito.error', $this->_message());
119
-		}
120
-
121
-		protected function _message() {
122
-			$message = [];
123
-			$i = 1;
124
-			foreach ($this->__lines as $line) {
125
-				$message[] = sprintf("  #%d %s", $i, $line);
126
-				$i++;
127
-			}
128
-			return "\n" . implode("\n", $message);
129
-		}
130
-
131
-		protected function _add($val, $key = null, $prepend = false) {
132
-			if (is_array($val)) {
133
-				$val = print_r($this->_filterData($val), true);
134
-			}
135
-			if (is_string($key)) {
136
-				$val = "$key: $val";
137
-			}
138
-
139
-			if ($prepend) {
140
-				array_unshift($this->__lines, $val);
141
-			} else {
142
-				$this->__lines[] = $val;
143
-			}
144
-		}
145
-
146
-	}
3
+    namespace Saito\Exception\Logger;
4
+
5
+    \App::uses('CakeLog', 'Log');
6
+
7
+    class ExceptionLogger {
8
+
9
+        private $__lines = [];
10
+
11
+        /**
12
+         * @param null $message
13
+         * @param null $data
14
+         * - `msgs` array with additional message-lines
15
+         * @throws \InvalidArgumentException
16
+         */
17
+        public function write($message, $data = null) {
18
+            //# process message(s)
19
+            $msgs = [$message];
20
+            if (isset($data['msgs'])) {
21
+                $msgs = array_merge($msgs, $data['msgs']);
22
+            }
23
+            // prepend main message in front of metadata added by subclasses
24
+            foreach (array_reverse($msgs) as $key => $msg) {
25
+                $this->_add($msg, $key, true);
26
+            }
27
+
28
+            //# add exception data
29
+            if (isset($data['e'])) {
30
+                /** @var $Exception \Exception */
31
+                $Exception = $data['e'];
32
+                unset($data['e']);
33
+                $message = $Exception->getMessage();
34
+                if (!empty($message)) {
35
+                    $this->_add($message);
36
+                }
37
+            }
38
+
39
+            //# add request data
40
+            $request = (php_sapi_name() !== 'cli') ? \Router::getRequest() : false;
41
+
42
+            $url = false;
43
+            if (isset($data['URL'])) {
44
+                $url = $data['URL'];
45
+            } elseif ($request) {
46
+                $url = $request->here();
47
+            }
48
+
49
+            $requestMethod = $request ? $request->method() : false;
50
+            if ($url && $requestMethod) {
51
+                $url .= ' ' . $requestMethod;
52
+            }
53
+            if ($url) {
54
+                $this->_add($url, 'Request URL');
55
+            }
56
+
57
+            if (isset($_SERVER['HTTP_USER_AGENT'])) {
58
+                $this->_add($_SERVER['HTTP_USER_AGENT'], 'User-Agent');
59
+            }
60
+
61
+            $this->_addUser($data);
62
+
63
+            if (!empty($request->data)) {
64
+                $this->_add($this->_filterData($request->data), 'Data');
65
+            }
66
+
67
+            $this->_write();
68
+        }
69
+
70
+        /**
71
+         * adds data about current user to log entry
72
+         *
73
+         * @param $data
74
+         * @throws \InvalidArgumentException
75
+         */
76
+        protected function _addUser($data) {
77
+            if (!isset($data['CurrentUser'])) {
78
+                return;
79
+            }
80
+            $CurrentUser = $data['CurrentUser'];
81
+            if (!is_a($data['CurrentUser'], 'CurrentUserComponent')) {
82
+                throw new \InvalidArgumentException;
83
+            }
84
+            if ($CurrentUser->isLoggedIn()) {
85
+                $username = "{$CurrentUser['username']} (id: {$CurrentUser['id']})";
86
+            } else {
87
+                $username = 'anonymous';
88
+            }
89
+            $this->_add($username, 'Current user');
90
+        }
91
+
92
+        /**
93
+         * Filters request-data which should not be in server logs
94
+         *
95
+         * esp. cleartext passwords in $_POST data
96
+         *
97
+         * @param $data
98
+         * @return array
99
+         */
100
+        protected function _filterData($data) {
101
+            if (!is_array($data)) {
102
+                return $data;
103
+            }
104
+            foreach ($data as $key => $datum) {
105
+                if (is_array($datum)) {
106
+                    $data[$key] = $this->_filterData($datum);
107
+                    continue;
108
+                }
109
+
110
+                if (stripos($key, 'password') !== false) {
111
+                    $data[$key] = '***********';
112
+                }
113
+            }
114
+            return $data;
115
+        }
116
+
117
+        protected function _write() {
118
+            \CakeLog::write('saito.error', $this->_message());
119
+        }
120
+
121
+        protected function _message() {
122
+            $message = [];
123
+            $i = 1;
124
+            foreach ($this->__lines as $line) {
125
+                $message[] = sprintf("  #%d %s", $i, $line);
126
+                $i++;
127
+            }
128
+            return "\n" . implode("\n", $message);
129
+        }
130
+
131
+        protected function _add($val, $key = null, $prepend = false) {
132
+            if (is_array($val)) {
133
+                $val = print_r($this->_filterData($val), true);
134
+            }
135
+            if (is_string($key)) {
136
+                $val = "$key: $val";
137
+            }
138
+
139
+            if ($prepend) {
140
+                array_unshift($this->__lines, $val);
141
+            } else {
142
+                $this->__lines[] = $val;
143
+            }
144
+        }
145
+
146
+    }
147 147
 
Please login to merge, or discard this patch.
app/Lib/Saito/Thread/Renderer/HtmlRendererAbstract.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 				$childrenHtml .= $this->_renderNode($child);
59 59
 			}
60 60
 			$level = $node->getLevel();
61
-			$html .= '<li>' . $this->_wrapUl($childrenHtml, $level + 1) . '</li>';
61
+			$html .= '<li>'.$this->_wrapUl($childrenHtml, $level + 1).'</li>';
62 62
 			return $html;
63 63
 		}
64 64
 
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 			$data = '';
82 82
 			if ($level === 0) {
83 83
 				$class .= ' root';
84
-				$data = 'data-id="' . $id . '"';
84
+				$data = 'data-id="'.$id.'"';
85 85
 			}
86 86
 			return "<ul {$data} class=\"{$class}\">{$string}</ul>";
87 87
 		}
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 		protected function _css($node) {
96 96
 			$entryType = ($node->isRoot()) ? 'et-root' : 'et-reply';
97 97
 			$entryType .= ($node->isNew()) ? ' et-new' : ' et-old';
98
-			if ($node->get('id') === (int)$this->_settings['currentEntry']) {
98
+			if ($node->get('id') === (int) $this->_settings['currentEntry']) {
99 99
 				$entryType .= ' et-current';
100 100
 			}
101 101
 			$css = $entryType;
Please login to merge, or discard this patch.
Indentation   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -1,108 +1,108 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-	namespace Saito\Thread\Renderer;
4
-
5
-	/**
6
-	 * renders posting into an ul-li HTML-list tree
7
-	 *
8
-	 * Check and benchmark on front-page if you perform changes here!
9
-	 */
10
-	abstract class HtmlRendererAbstract {
11
-
12
-		/** * @var SaitoEventManager */
13
-		use \Saito\Posting\Renderer\HelperTrait;
14
-
15
-		protected $_EntryHelper;
16
-
17
-		protected $_defaults = [
18
-			'currentEntry' => null,
19
-			'ignore' => true,
20
-			'rootWrap' => false
21
-		];
22
-
23
-		protected $_settings;
24
-
25
-		protected $_lastAnswer;
26
-
27
-		protected $_SEM;
28
-
29
-		public function __construct(\EntryHHelper $EntryHelper, $options = []) {
30
-			$this->_EntryHelper = $EntryHelper;
31
-			$this->_SEM = \SaitoEventManager::getInstance();
32
-			$this->setOptions($options);
33
-		}
34
-
35
-		public function render(\Saito\Posting\PostingInterface $node) {
36
-			$this->_lastAnswer = $node->getThread()->getLastAnswer();
37
-			$html = $this->_renderNode($node);
38
-			if ($node->isRoot() || $this->_settings['rootWrap']) {
39
-				$html = $this->_wrapUl($html, 0, $node->get('id'));
40
-			}
41
-			return $html;
42
-		}
43
-
44
-		public function setOptions($options) {
45
-			$this->_settings = $options + $this->_defaults;
46
-		}
47
-
48
-		protected function _renderNode(\Saito\Posting\PostingInterface $node) {
49
-			$html = $this->_renderCore($node);
50
-
51
-			$children = $node->getChildren();
52
-			if (empty($children)) {
53
-				return $html;
54
-			}
55
-
56
-			$childrenHtml = '';
57
-			foreach ($node->getChildren() as $child) {
58
-				$childrenHtml .= $this->_renderNode($child);
59
-			}
60
-			$level = $node->getLevel();
61
-			$html .= '<li>' . $this->_wrapUl($childrenHtml, $level + 1) . '</li>';
62
-			return $html;
63
-		}
64
-
65
-		protected abstract function _renderCore(\Saito\Posting\PostingInterface $node);
66
-
67
-		/**
68
-		 * Wraps li tags with ul tag
69
-		 *
70
-		 * @param string $string li html list
71
-		 * @param $level
72
-		 * @param $id
73
-		 * @return string
74
-		 */
75
-		protected function _wrapUl($string, $level = null, $id = null) {
76
-			if ($level >= $this->_settings['maxThreadDepthIndent']) {
77
-				return $string;
78
-			}
79
-
80
-			$class = 'threadTree-node';
81
-			$data = '';
82
-			if ($level === 0) {
83
-				$class .= ' root';
84
-				$data = 'data-id="' . $id . '"';
85
-			}
86
-			return "<ul {$data} class=\"{$class}\">{$string}</ul>";
87
-		}
88
-
89
-		/**
90
-		 * generates CSS classes
91
-		 *
92
-		 * @param $node
93
-		 * @return string
94
-		 */
95
-		protected function _css($node) {
96
-			$entryType = ($node->isRoot()) ? 'et-root' : 'et-reply';
97
-			$entryType .= ($node->isNew()) ? ' et-new' : ' et-old';
98
-			if ($node->get('id') === (int)$this->_settings['currentEntry']) {
99
-				$entryType .= ' et-current';
100
-			}
101
-			$css = $entryType;
102
-			if ($this->_settings['ignore'] && $node->isIgnored()) {
103
-				$css .= ' ignored';
104
-			}
105
-			return $css;
106
-		}
107
-
108
-	}
3
+    namespace Saito\Thread\Renderer;
4
+
5
+    /**
6
+     * renders posting into an ul-li HTML-list tree
7
+     *
8
+     * Check and benchmark on front-page if you perform changes here!
9
+     */
10
+    abstract class HtmlRendererAbstract {
11
+
12
+        /** * @var SaitoEventManager */
13
+        use \Saito\Posting\Renderer\HelperTrait;
14
+
15
+        protected $_EntryHelper;
16
+
17
+        protected $_defaults = [
18
+            'currentEntry' => null,
19
+            'ignore' => true,
20
+            'rootWrap' => false
21
+        ];
22
+
23
+        protected $_settings;
24
+
25
+        protected $_lastAnswer;
26
+
27
+        protected $_SEM;
28
+
29
+        public function __construct(\EntryHHelper $EntryHelper, $options = []) {
30
+            $this->_EntryHelper = $EntryHelper;
31
+            $this->_SEM = \SaitoEventManager::getInstance();
32
+            $this->setOptions($options);
33
+        }
34
+
35
+        public function render(\Saito\Posting\PostingInterface $node) {
36
+            $this->_lastAnswer = $node->getThread()->getLastAnswer();
37
+            $html = $this->_renderNode($node);
38
+            if ($node->isRoot() || $this->_settings['rootWrap']) {
39
+                $html = $this->_wrapUl($html, 0, $node->get('id'));
40
+            }
41
+            return $html;
42
+        }
43
+
44
+        public function setOptions($options) {
45
+            $this->_settings = $options + $this->_defaults;
46
+        }
47
+
48
+        protected function _renderNode(\Saito\Posting\PostingInterface $node) {
49
+            $html = $this->_renderCore($node);
50
+
51
+            $children = $node->getChildren();
52
+            if (empty($children)) {
53
+                return $html;
54
+            }
55
+
56
+            $childrenHtml = '';
57
+            foreach ($node->getChildren() as $child) {
58
+                $childrenHtml .= $this->_renderNode($child);
59
+            }
60
+            $level = $node->getLevel();
61
+            $html .= '<li>' . $this->_wrapUl($childrenHtml, $level + 1) . '</li>';
62
+            return $html;
63
+        }
64
+
65
+        protected abstract function _renderCore(\Saito\Posting\PostingInterface $node);
66
+
67
+        /**
68
+         * Wraps li tags with ul tag
69
+         *
70
+         * @param string $string li html list
71
+         * @param $level
72
+         * @param $id
73
+         * @return string
74
+         */
75
+        protected function _wrapUl($string, $level = null, $id = null) {
76
+            if ($level >= $this->_settings['maxThreadDepthIndent']) {
77
+                return $string;
78
+            }
79
+
80
+            $class = 'threadTree-node';
81
+            $data = '';
82
+            if ($level === 0) {
83
+                $class .= ' root';
84
+                $data = 'data-id="' . $id . '"';
85
+            }
86
+            return "<ul {$data} class=\"{$class}\">{$string}</ul>";
87
+        }
88
+
89
+        /**
90
+         * generates CSS classes
91
+         *
92
+         * @param $node
93
+         * @return string
94
+         */
95
+        protected function _css($node) {
96
+            $entryType = ($node->isRoot()) ? 'et-root' : 'et-reply';
97
+            $entryType .= ($node->isNew()) ? ' et-new' : ' et-old';
98
+            if ($node->get('id') === (int)$this->_settings['currentEntry']) {
99
+                $entryType .= ' et-current';
100
+            }
101
+            $css = $entryType;
102
+            if ($this->_settings['ignore'] && $node->isIgnored()) {
103
+                $css .= ' ignored';
104
+            }
105
+            return $css;
106
+        }
107
+
108
+    }
Please login to merge, or discard this patch.
index.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 define('DS', DIRECTORY_SEPARATOR);
28 28
 define('ROOT', dirname(__FILE__));
29 29
 define('WEBROOT_DIR', 'webroot');
30
-define('WWW_ROOT', ROOT . DS . APP_DIR . DS . WEBROOT_DIR . DS);
30
+define('WWW_ROOT', ROOT.DS.APP_DIR.DS.WEBROOT_DIR.DS);
31 31
 
32 32
 /**
33 33
  * This only needs to be changed if the "cake" directory is located
@@ -39,12 +39,12 @@  discard block
 block discarded – undo
39 39
 if (!defined('CAKE_CORE_INCLUDE_PATH')) {
40 40
 	define(
41 41
 	'CAKE_CORE_INCLUDE_PATH',
42
-		ROOT . DS . APP_DIR . DS . 'Vendor' . DS . 'pear-pear.cakephp.org' . DS . 'CakePHP'
42
+		ROOT.DS.APP_DIR.DS.'Vendor'.DS.'pear-pear.cakephp.org'.DS.'CakePHP'
43 43
 	);
44 44
 }
45 45
 
46 46
 if (!defined('CAKE_CORE_INCLUDE_PATH')) {
47
-	define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . 'lib');
47
+	define('CAKE_CORE_INCLUDE_PATH', ROOT.DS.'lib');
48 48
 }
49 49
 
50
-require APP_DIR . DS . WEBROOT_DIR . DS . 'index.php';
50
+require APP_DIR.DS.WEBROOT_DIR.DS.'index.php';
Please login to merge, or discard this patch.
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -37,14 +37,14 @@
 block discarded – undo
37 37
 
38 38
 // Core path for CakePHP 2 via composer
39 39
 if (!defined('CAKE_CORE_INCLUDE_PATH')) {
40
-	define(
41
-	'CAKE_CORE_INCLUDE_PATH',
42
-		ROOT . DS . APP_DIR . DS . 'Vendor' . DS . 'pear-pear.cakephp.org' . DS . 'CakePHP'
43
-	);
40
+    define(
41
+    'CAKE_CORE_INCLUDE_PATH',
42
+        ROOT . DS . APP_DIR . DS . 'Vendor' . DS . 'pear-pear.cakephp.org' . DS . 'CakePHP'
43
+    );
44 44
 }
45 45
 
46 46
 if (!defined('CAKE_CORE_INCLUDE_PATH')) {
47
-	define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . 'lib');
47
+    define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . 'lib');
48 48
 }
49 49
 
50 50
 require APP_DIR . DS . WEBROOT_DIR . DS . 'index.php';
Please login to merge, or discard this patch.