@@ -34,6 +34,9 @@ discard block |
||
34 | 34 | return self::run_query($query); |
35 | 35 | } |
36 | 36 | |
37 | + /** |
|
38 | + * @param integer $total |
|
39 | + */ |
|
37 | 40 | public static function getRecentList($total) |
38 | 41 | { |
39 | 42 | $query = " |
@@ -178,6 +181,9 @@ discard block |
||
178 | 181 | return self::run_row_query($query); |
179 | 182 | } |
180 | 183 | |
184 | + /** |
|
185 | + * @param string $date |
|
186 | + */ |
|
181 | 187 | public static function getByDate($date) |
182 | 188 | { |
183 | 189 | $date = self::escape($date); |
@@ -5,9 +5,9 @@ discard block |
||
5 | 5 | final class LogCollector extends Collector |
6 | 6 | { |
7 | 7 | |
8 | - public static function getList($total, $offset = 0) |
|
9 | - { |
|
10 | - $query = " |
|
8 | + public static function getList($total, $offset = 0) |
|
9 | + { |
|
10 | + $query = " |
|
11 | 11 | SELECT |
12 | 12 | `log`.`id`, |
13 | 13 | `log`.`title`, |
@@ -31,8 +31,8 @@ discard block |
||
31 | 31 | `log`.`date` DESC |
32 | 32 | LIMIT |
33 | 33 | {$offset}, {$total}"; |
34 | - return self::run_query($query); |
|
35 | - } |
|
34 | + return self::run_query($query); |
|
35 | + } |
|
36 | 36 | |
37 | 37 | public static function getRecentList($total) |
38 | 38 | { |
@@ -62,21 +62,21 @@ discard block |
||
62 | 62 | return self::run_query($query); |
63 | 63 | } |
64 | 64 | |
65 | - public static function getListCount() |
|
66 | - { |
|
67 | - $query = " |
|
65 | + public static function getListCount() |
|
66 | + { |
|
67 | + $query = " |
|
68 | 68 | SELECT |
69 | 69 | COUNT(1) AS `count` |
70 | 70 | FROM |
71 | 71 | `jpemeric_waterfall`.`log` |
72 | 72 | WHERE |
73 | 73 | `is_public` = '1'"; |
74 | - return self::get_count($query); |
|
75 | - } |
|
74 | + return self::get_count($query); |
|
75 | + } |
|
76 | 76 | |
77 | - public static function getCompanionListForLog($log) |
|
78 | - { |
|
79 | - $query = " |
|
77 | + public static function getCompanionListForLog($log) |
|
78 | + { |
|
79 | + $query = " |
|
80 | 80 | SELECT |
81 | 81 | `companion`.`name`, |
82 | 82 | `companion`.`alias` |
@@ -87,12 +87,12 @@ discard block |
||
87 | 87 | ON `log_companion_map`.`companion` = `companion`.`id` |
88 | 88 | WHERE |
89 | 89 | `log_companion_map`.`log` = '{$log}'"; |
90 | - return self::run_query($query); |
|
91 | - } |
|
90 | + return self::run_query($query); |
|
91 | + } |
|
92 | 92 | |
93 | - public static function getWaterfallListForLog($log) |
|
94 | - { |
|
95 | - $query = " |
|
93 | + public static function getWaterfallListForLog($log) |
|
94 | + { |
|
95 | + $query = " |
|
96 | 96 | SELECT |
97 | 97 | `waterfall`.`name`, |
98 | 98 | `waterfall`.`alias`, |
@@ -110,12 +110,12 @@ discard block |
||
110 | 110 | `waterfall`.`is_public` = '1' |
111 | 111 | ORDER BY |
112 | 112 | `log_waterfall_map`.`order`"; |
113 | - return self::run_query($query); |
|
114 | - } |
|
113 | + return self::run_query($query); |
|
114 | + } |
|
115 | 115 | |
116 | - public static function getLogListForWaterfall($waterfall) |
|
117 | - { |
|
118 | - $query = " |
|
116 | + public static function getLogListForWaterfall($waterfall) |
|
117 | + { |
|
118 | + $query = " |
|
119 | 119 | SELECT |
120 | 120 | `log`.`title`, |
121 | 121 | `log`.`alias`, |
@@ -130,12 +130,12 @@ discard block |
||
130 | 130 | `log`.`is_public` = '1' |
131 | 131 | ORDER BY |
132 | 132 | `log`.`date`"; |
133 | - return self::run_query($query); |
|
134 | - } |
|
133 | + return self::run_query($query); |
|
134 | + } |
|
135 | 135 | |
136 | - public static function getTagListForLog($log) |
|
137 | - { |
|
138 | - $query = " |
|
136 | + public static function getTagListForLog($log) |
|
137 | + { |
|
138 | + $query = " |
|
139 | 139 | SELECT |
140 | 140 | `tag`.`name`, |
141 | 141 | `tag`.`alias` |
@@ -144,14 +144,14 @@ discard block |
||
144 | 144 | INNER JOIN |
145 | 145 | `jpemeric_waterfall`.`log_tag_map` |
146 | 146 | ON `log_tag_map`.`tag` = `tag`.`id` && `log_tag_map`.`log` = '{$log}'"; |
147 | - return self::run_query($query); |
|
148 | - } |
|
147 | + return self::run_query($query); |
|
148 | + } |
|
149 | 149 | |
150 | - public static function getByAlias($alias) |
|
151 | - { |
|
152 | - $alias = self::escape($alias); |
|
150 | + public static function getByAlias($alias) |
|
151 | + { |
|
152 | + $alias = self::escape($alias); |
|
153 | 153 | |
154 | - $query = " |
|
154 | + $query = " |
|
155 | 155 | SELECT |
156 | 156 | `log`.`id`, |
157 | 157 | `log`.`title`, |
@@ -175,8 +175,8 @@ discard block |
||
175 | 175 | `log`.`is_public` = '1' |
176 | 176 | LIMIT 1"; |
177 | 177 | |
178 | - return self::run_row_query($query); |
|
179 | - } |
|
178 | + return self::run_row_query($query); |
|
179 | + } |
|
180 | 180 | |
181 | 181 | public static function getByDate($date) |
182 | 182 | { |
@@ -195,9 +195,9 @@ discard block |
||
195 | 195 | return self::run_row_query($query); |
196 | 196 | } |
197 | 197 | |
198 | - public static function getById($log) |
|
199 | - { |
|
200 | - $query = " |
|
198 | + public static function getById($log) |
|
199 | + { |
|
200 | + $query = " |
|
201 | 201 | SELECT |
202 | 202 | `title`, |
203 | 203 | `date`, |
@@ -208,12 +208,12 @@ discard block |
||
208 | 208 | `id` = '{$log}' AND |
209 | 209 | `is_public` = '1' |
210 | 210 | LIMIT 1"; |
211 | - return self::run_row_query($query); |
|
212 | - } |
|
211 | + return self::run_row_query($query); |
|
212 | + } |
|
213 | 213 | |
214 | - public static function getPreviousLog($log) |
|
215 | - { |
|
216 | - $query = " |
|
214 | + public static function getPreviousLog($log) |
|
215 | + { |
|
216 | + $query = " |
|
217 | 217 | SELECT |
218 | 218 | `title`, |
219 | 219 | `date`, |
@@ -233,12 +233,12 @@ discard block |
||
233 | 233 | `date` DESC |
234 | 234 | LIMIT 1"; |
235 | 235 | |
236 | - return self::run_row_query($query); |
|
237 | - } |
|
236 | + return self::run_row_query($query); |
|
237 | + } |
|
238 | 238 | |
239 | - public static function getNextLog($log) |
|
240 | - { |
|
241 | - $query = " |
|
239 | + public static function getNextLog($log) |
|
240 | + { |
|
241 | + $query = " |
|
242 | 242 | SELECT |
243 | 243 | `title`, |
244 | 244 | `date`, |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | `date` ASC |
259 | 259 | LIMIT 1"; |
260 | 260 | |
261 | - return self::run_row_query($query); |
|
262 | - } |
|
261 | + return self::run_row_query($query); |
|
262 | + } |
|
263 | 263 | |
264 | 264 | } |
@@ -2,11 +2,11 @@ discard block |
||
2 | 2 | |
3 | 3 | Loader::load('collector', 'Collector'); |
4 | 4 | |
5 | -final class LogCollector extends Collector |
|
6 | -{ |
|
5 | +final class LogCollector extends Collector |
|
6 | +{ |
|
7 | 7 | |
8 | - public static function getList($total, $offset = 0) |
|
9 | - { |
|
8 | + public static function getList($total, $offset = 0) |
|
9 | + { |
|
10 | 10 | $query = " |
11 | 11 | SELECT |
12 | 12 | `log`.`id`, |
@@ -34,8 +34,8 @@ discard block |
||
34 | 34 | return self::run_query($query); |
35 | 35 | } |
36 | 36 | |
37 | - public static function getRecentList($total) |
|
38 | - { |
|
37 | + public static function getRecentList($total) |
|
38 | + { |
|
39 | 39 | $query = " |
40 | 40 | SELECT |
41 | 41 | `log`.`title`, |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | return self::run_query($query); |
63 | 63 | } |
64 | 64 | |
65 | - public static function getListCount() |
|
66 | - { |
|
65 | + public static function getListCount() |
|
66 | + { |
|
67 | 67 | $query = " |
68 | 68 | SELECT |
69 | 69 | COUNT(1) AS `count` |
@@ -74,8 +74,8 @@ discard block |
||
74 | 74 | return self::get_count($query); |
75 | 75 | } |
76 | 76 | |
77 | - public static function getCompanionListForLog($log) |
|
78 | - { |
|
77 | + public static function getCompanionListForLog($log) |
|
78 | + { |
|
79 | 79 | $query = " |
80 | 80 | SELECT |
81 | 81 | `companion`.`name`, |
@@ -90,8 +90,8 @@ discard block |
||
90 | 90 | return self::run_query($query); |
91 | 91 | } |
92 | 92 | |
93 | - public static function getWaterfallListForLog($log) |
|
94 | - { |
|
93 | + public static function getWaterfallListForLog($log) |
|
94 | + { |
|
95 | 95 | $query = " |
96 | 96 | SELECT |
97 | 97 | `waterfall`.`name`, |
@@ -113,8 +113,8 @@ discard block |
||
113 | 113 | return self::run_query($query); |
114 | 114 | } |
115 | 115 | |
116 | - public static function getLogListForWaterfall($waterfall) |
|
117 | - { |
|
116 | + public static function getLogListForWaterfall($waterfall) |
|
117 | + { |
|
118 | 118 | $query = " |
119 | 119 | SELECT |
120 | 120 | `log`.`title`, |
@@ -133,8 +133,8 @@ discard block |
||
133 | 133 | return self::run_query($query); |
134 | 134 | } |
135 | 135 | |
136 | - public static function getTagListForLog($log) |
|
137 | - { |
|
136 | + public static function getTagListForLog($log) |
|
137 | + { |
|
138 | 138 | $query = " |
139 | 139 | SELECT |
140 | 140 | `tag`.`name`, |
@@ -147,8 +147,8 @@ discard block |
||
147 | 147 | return self::run_query($query); |
148 | 148 | } |
149 | 149 | |
150 | - public static function getByAlias($alias) |
|
151 | - { |
|
150 | + public static function getByAlias($alias) |
|
151 | + { |
|
152 | 152 | $alias = self::escape($alias); |
153 | 153 | |
154 | 154 | $query = " |
@@ -178,8 +178,8 @@ discard block |
||
178 | 178 | return self::run_row_query($query); |
179 | 179 | } |
180 | 180 | |
181 | - public static function getByDate($date) |
|
182 | - { |
|
181 | + public static function getByDate($date) |
|
182 | + { |
|
183 | 183 | $date = self::escape($date); |
184 | 184 | |
185 | 185 | $query = " |
@@ -195,8 +195,8 @@ discard block |
||
195 | 195 | return self::run_row_query($query); |
196 | 196 | } |
197 | 197 | |
198 | - public static function getById($log) |
|
199 | - { |
|
198 | + public static function getById($log) |
|
199 | + { |
|
200 | 200 | $query = " |
201 | 201 | SELECT |
202 | 202 | `title`, |
@@ -211,8 +211,8 @@ discard block |
||
211 | 211 | return self::run_row_query($query); |
212 | 212 | } |
213 | 213 | |
214 | - public static function getPreviousLog($log) |
|
215 | - { |
|
214 | + public static function getPreviousLog($log) |
|
215 | + { |
|
216 | 216 | $query = " |
217 | 217 | SELECT |
218 | 218 | `title`, |
@@ -236,8 +236,8 @@ discard block |
||
236 | 236 | return self::run_row_query($query); |
237 | 237 | } |
238 | 238 | |
239 | - public static function getNextLog($log) |
|
240 | - { |
|
239 | + public static function getNextLog($log) |
|
240 | + { |
|
241 | 241 | $query = " |
242 | 242 | SELECT |
243 | 243 | `title`, |
@@ -117,6 +117,9 @@ |
||
117 | 117 | return self::run_query($query); |
118 | 118 | } |
119 | 119 | |
120 | + /** |
|
121 | + * @param string $alias |
|
122 | + */ |
|
120 | 123 | public static function getByOldAlias($alias) |
121 | 124 | { |
122 | 125 | $alias = self::escape($alias); |
@@ -2,11 +2,11 @@ discard block |
||
2 | 2 | |
3 | 3 | Loader::load('collector', 'Collector'); |
4 | 4 | |
5 | -final class WaterfallCollector extends Collector |
|
6 | -{ |
|
5 | +final class WaterfallCollector extends Collector |
|
6 | +{ |
|
7 | 7 | |
8 | - public static function getList($total, $offset = 0) |
|
9 | - { |
|
8 | + public static function getList($total, $offset = 0) |
|
9 | + { |
|
10 | 10 | $query = " |
11 | 11 | SELECT |
12 | 12 | `waterfall`.`id`, |
@@ -43,8 +43,8 @@ discard block |
||
43 | 43 | return self::run_query($query); |
44 | 44 | } |
45 | 45 | |
46 | - public static function getMapList() |
|
47 | - { |
|
46 | + public static function getMapList() |
|
47 | + { |
|
48 | 48 | $query = " |
49 | 49 | SELECT |
50 | 50 | `waterfall`.`name`, |
@@ -74,8 +74,8 @@ discard block |
||
74 | 74 | return self::run_query($query); |
75 | 75 | } |
76 | 76 | |
77 | - public static function getListCount() |
|
78 | - { |
|
77 | + public static function getListCount() |
|
78 | + { |
|
79 | 79 | $query = " |
80 | 80 | SELECT |
81 | 81 | COUNT(1) AS `count` |
@@ -92,8 +92,8 @@ discard block |
||
92 | 92 | return self::get_count($query); |
93 | 93 | } |
94 | 94 | |
95 | - public static function getNearbyList($waterfall) |
|
96 | - { |
|
95 | + public static function getNearbyList($waterfall) |
|
96 | + { |
|
97 | 97 | $query = " |
98 | 98 | SELECT |
99 | 99 | `waterfall`.`name`, |
@@ -117,8 +117,8 @@ discard block |
||
117 | 117 | return self::run_query($query); |
118 | 118 | } |
119 | 119 | |
120 | - public static function getByOldAlias($alias) |
|
121 | - { |
|
120 | + public static function getByOldAlias($alias) |
|
121 | + { |
|
122 | 122 | $alias = self::escape($alias); |
123 | 123 | |
124 | 124 | $query = " |
@@ -137,8 +137,8 @@ discard block |
||
137 | 137 | return self::run_row_query($query); |
138 | 138 | } |
139 | 139 | |
140 | - public static function getByAlias($watercourse, $waterfall) |
|
141 | - { |
|
140 | + public static function getByAlias($watercourse, $waterfall) |
|
141 | + { |
|
142 | 142 | $watercourse = self::escape($watercourse); |
143 | 143 | $waterfall = self::escape($waterfall); |
144 | 144 |
@@ -5,9 +5,9 @@ discard block |
||
5 | 5 | final class WaterfallCollector extends Collector |
6 | 6 | { |
7 | 7 | |
8 | - public static function getList($total, $offset = 0) |
|
9 | - { |
|
10 | - $query = " |
|
8 | + public static function getList($total, $offset = 0) |
|
9 | + { |
|
10 | + $query = " |
|
11 | 11 | SELECT |
12 | 12 | `waterfall`.`id`, |
13 | 13 | `waterfall`.`name`, |
@@ -40,8 +40,8 @@ discard block |
||
40 | 40 | `watercourse`.`name` |
41 | 41 | LIMIT |
42 | 42 | {$offset}, {$total}"; |
43 | - return self::run_query($query); |
|
44 | - } |
|
43 | + return self::run_query($query); |
|
44 | + } |
|
45 | 45 | |
46 | 46 | public static function getMapList() |
47 | 47 | { |
@@ -74,9 +74,9 @@ discard block |
||
74 | 74 | return self::run_query($query); |
75 | 75 | } |
76 | 76 | |
77 | - public static function getListCount() |
|
78 | - { |
|
79 | - $query = " |
|
77 | + public static function getListCount() |
|
78 | + { |
|
79 | + $query = " |
|
80 | 80 | SELECT |
81 | 81 | COUNT(1) AS `count` |
82 | 82 | FROM |
@@ -89,8 +89,8 @@ discard block |
||
89 | 89 | ON `county`.`id` = `waterfall`.`county` |
90 | 90 | WHERE |
91 | 91 | `waterfall`.`is_public` = '1'"; |
92 | - return self::get_count($query); |
|
93 | - } |
|
92 | + return self::get_count($query); |
|
93 | + } |
|
94 | 94 | |
95 | 95 | public static function getNearbyList($waterfall) |
96 | 96 | { |
@@ -137,12 +137,12 @@ discard block |
||
137 | 137 | return self::run_row_query($query); |
138 | 138 | } |
139 | 139 | |
140 | - public static function getByAlias($watercourse, $waterfall) |
|
141 | - { |
|
142 | - $watercourse = self::escape($watercourse); |
|
143 | - $waterfall = self::escape($waterfall); |
|
140 | + public static function getByAlias($watercourse, $waterfall) |
|
141 | + { |
|
142 | + $watercourse = self::escape($watercourse); |
|
143 | + $waterfall = self::escape($waterfall); |
|
144 | 144 | |
145 | - $query = " |
|
145 | + $query = " |
|
146 | 146 | SELECT |
147 | 147 | `waterfall`.`id` AS `id`, |
148 | 148 | `waterfall`.`name`, |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | `waterfall`.`is_public` = '1' |
193 | 193 | LIMIT 1"; |
194 | 194 | |
195 | - return self::run_row_query($query); |
|
196 | - } |
|
195 | + return self::run_row_query($query); |
|
196 | + } |
|
197 | 197 | |
198 | 198 | } |
@@ -97,6 +97,9 @@ |
||
97 | 97 | return $tag_array; |
98 | 98 | } |
99 | 99 | |
100 | + /** |
|
101 | + * @param boolean $trim |
|
102 | + */ |
|
100 | 103 | final private function get_body_for_post($post, $trim) |
101 | 104 | { |
102 | 105 | $body = $post->body; |
@@ -6,150 +6,150 @@ |
||
6 | 6 | abstract class DefaultPageController extends PageController |
7 | 7 | { |
8 | 8 | |
9 | - private static $RECENT_COMMENT_COUNT = 10; |
|
10 | - private static $MINIMUM_TAG_COUNT = 10; |
|
11 | - protected static $LENGTH_OF_TRIMMED_POST = 300; |
|
9 | + private static $RECENT_COMMENT_COUNT = 10; |
|
10 | + private static $MINIMUM_TAG_COUNT = 10; |
|
11 | + protected static $LENGTH_OF_TRIMMED_POST = 300; |
|
12 | 12 | |
13 | - protected static $BLOG_SITE_ID = 2; |
|
13 | + protected static $BLOG_SITE_ID = 2; |
|
14 | 14 | |
15 | - private static $INTRODUCTION_IMAGE_PATTERN = '<img src="/photo/%s/%s-size-%s.jpg" height="%d" width="%d" alt="%s" />'; |
|
15 | + private static $INTRODUCTION_IMAGE_PATTERN = '<img src="/photo/%s/%s-size-%s.jpg" height="%d" width="%d" alt="%s" />'; |
|
16 | 16 | |
17 | - protected function set_head_data() |
|
18 | - { |
|
17 | + protected function set_head_data() |
|
18 | + { |
|
19 | 19 | $this->set_head('rss_link', [ |
20 | - 'title' => 'Jacob Emerick Blog Feed', |
|
21 | - 'url' => '/rss.xml' |
|
20 | + 'title' => 'Jacob Emerick Blog Feed', |
|
21 | + 'url' => '/rss.xml' |
|
22 | 22 | ]); |
23 | 23 | $this->set_head('rss_comment_link', [ |
24 | - 'title' => 'Jacob Emerick Blog Comment Feed', |
|
25 | - 'url' => '/rss-comments.xml' |
|
24 | + 'title' => 'Jacob Emerick Blog Comment Feed', |
|
25 | + 'url' => '/rss-comments.xml' |
|
26 | 26 | ]); |
27 | 27 | |
28 | - $this->add_css('normalize'); |
|
29 | - $this->add_css('blog'); |
|
30 | - } |
|
31 | - |
|
32 | - protected function get_introduction() |
|
33 | - { |
|
34 | - return; |
|
35 | - } |
|
36 | - |
|
37 | - protected function get_introduction_image($id) |
|
38 | - { |
|
39 | - Loader::load('collector', 'image/PhotoCollector'); |
|
40 | - $photo_result = PhotoCollector::getRow($id); |
|
28 | + $this->add_css('normalize'); |
|
29 | + $this->add_css('blog'); |
|
30 | + } |
|
31 | + |
|
32 | + protected function get_introduction() |
|
33 | + { |
|
34 | + return; |
|
35 | + } |
|
36 | + |
|
37 | + protected function get_introduction_image($id) |
|
38 | + { |
|
39 | + Loader::load('collector', 'image/PhotoCollector'); |
|
40 | + $photo_result = PhotoCollector::getRow($id); |
|
41 | 41 | |
42 | - if($photo_result == null) |
|
43 | - return; |
|
42 | + if($photo_result == null) |
|
43 | + return; |
|
44 | 44 | |
45 | - $name = $photo_result->name; |
|
46 | - $category = $photo_result->category; |
|
47 | - $size = 'medium'; |
|
48 | - $height = 375; |
|
49 | - $width = 500; |
|
50 | - $description = $photo_result->description; |
|
45 | + $name = $photo_result->name; |
|
46 | + $category = $photo_result->category; |
|
47 | + $size = 'medium'; |
|
48 | + $height = 375; |
|
49 | + $width = 500; |
|
50 | + $description = $photo_result->description; |
|
51 | 51 | |
52 | - return sprintf(self::$INTRODUCTION_IMAGE_PATTERN, $category, $name, $size, $height, $width, $description); |
|
53 | - } |
|
54 | - |
|
55 | - protected function set_body_data() |
|
56 | - { |
|
57 | - $this->set_body('introduction', $this->get_introduction()); |
|
58 | - $this->set_body('right_side', $this->get_right_side()); |
|
59 | - $this->set_body('activity_array', $this->get_recent_activity()); |
|
52 | + return sprintf(self::$INTRODUCTION_IMAGE_PATTERN, $category, $name, $size, $height, $width, $description); |
|
53 | + } |
|
54 | + |
|
55 | + protected function set_body_data() |
|
56 | + { |
|
57 | + $this->set_body('introduction', $this->get_introduction()); |
|
58 | + $this->set_body('right_side', $this->get_right_side()); |
|
59 | + $this->set_body('activity_array', $this->get_recent_activity()); |
|
60 | 60 | |
61 | - $this->set_body_view('Page'); |
|
62 | - } |
|
61 | + $this->set_body_view('Page'); |
|
62 | + } |
|
63 | 63 | |
64 | - final protected function format_post($post, $trim = false) |
|
65 | - { |
|
66 | - $post_object = new stdclass(); |
|
64 | + final protected function format_post($post, $trim = false) |
|
65 | + { |
|
66 | + $post_object = new stdclass(); |
|
67 | 67 | |
68 | - $post_object->title = $post['title']; |
|
69 | - $post_object->path = "/{$post['category']}/{$post['path']}/"; |
|
70 | - $post_object->category = ucwords(str_replace('-', ' ', $post['category'])); |
|
71 | - $post_object->category_link = "/{$post['category']}/"; |
|
72 | - $post_object->tags = $this->get_tags_for_post($post); |
|
73 | - $post_object->image = Content::instance('FetchFirstPhoto', $post['body'])->activate(false, 'small'); |
|
74 | - $post_object->body = $this->get_body_for_post($post, $trim); |
|
75 | - $post_object->date = $this->get_parsed_date($post['date']); |
|
76 | - |
|
77 | - return $post_object; |
|
78 | - } |
|
79 | - |
|
80 | - final private function get_tags_for_post($post) |
|
81 | - { |
|
68 | + $post_object->title = $post['title']; |
|
69 | + $post_object->path = "/{$post['category']}/{$post['path']}/"; |
|
70 | + $post_object->category = ucwords(str_replace('-', ' ', $post['category'])); |
|
71 | + $post_object->category_link = "/{$post['category']}/"; |
|
72 | + $post_object->tags = $this->get_tags_for_post($post); |
|
73 | + $post_object->image = Content::instance('FetchFirstPhoto', $post['body'])->activate(false, 'small'); |
|
74 | + $post_object->body = $this->get_body_for_post($post, $trim); |
|
75 | + $post_object->date = $this->get_parsed_date($post['date']); |
|
76 | + |
|
77 | + return $post_object; |
|
78 | + } |
|
79 | + |
|
80 | + final private function get_tags_for_post($post) |
|
81 | + { |
|
82 | 82 | global $container; |
83 | 83 | $repository = new Jacobemerick\Web\Domain\Blog\Tag\MysqlTagRepository($container['db_connection_locator']); |
84 | 84 | $tag_result = $repository->getTagsForPost($post['id']); |
85 | 85 | |
86 | 86 | $tag_array = array(); |
87 | - foreach($tag_result as $tag) |
|
88 | - { |
|
89 | - $tag_object = new stdclass(); |
|
90 | - $tag_object->name = $tag['tag']; |
|
91 | - $tag_object->link = Content::instance('URLSafe', "/tag/{$tag['tag']}/")->activate(); |
|
92 | - $tag_array[] = $tag_object; |
|
93 | - } |
|
94 | - return $tag_array; |
|
95 | - } |
|
96 | - |
|
97 | - final private function get_body_for_post($post, $trim) |
|
98 | - { |
|
99 | - $body = $post['body']; |
|
87 | + foreach($tag_result as $tag) |
|
88 | + { |
|
89 | + $tag_object = new stdclass(); |
|
90 | + $tag_object->name = $tag['tag']; |
|
91 | + $tag_object->link = Content::instance('URLSafe', "/tag/{$tag['tag']}/")->activate(); |
|
92 | + $tag_array[] = $tag_object; |
|
93 | + } |
|
94 | + return $tag_array; |
|
95 | + } |
|
96 | + |
|
97 | + final private function get_body_for_post($post, $trim) |
|
98 | + { |
|
99 | + $body = $post['body']; |
|
100 | 100 | |
101 | - if($trim) |
|
102 | - $body = Content::instance('SmartTrim', $body)->activate(self::$LENGTH_OF_TRIMMED_POST); |
|
101 | + if($trim) |
|
102 | + $body = Content::instance('SmartTrim', $body)->activate(self::$LENGTH_OF_TRIMMED_POST); |
|
103 | 103 | |
104 | - $body = Content::instance('FixPhoto', $body)->activate(false, 'standard'); |
|
105 | - $body = Content::instance('MarkupCode', $body)->activate(); |
|
104 | + $body = Content::instance('FixPhoto', $body)->activate(false, 'standard'); |
|
105 | + $body = Content::instance('MarkupCode', $body)->activate(); |
|
106 | 106 | |
107 | - return $body; |
|
108 | - } |
|
109 | - |
|
110 | - final protected function get_right_side() |
|
111 | - { |
|
112 | - $side_array = array(); |
|
113 | - $side_array['tags'] = $this->get_tag_cloud(); |
|
114 | - $side_array['comments'] = $this->get_comments(); |
|
115 | - return $side_array; |
|
116 | - } |
|
117 | - |
|
118 | - final private function get_tag_cloud() |
|
119 | - { |
|
107 | + return $body; |
|
108 | + } |
|
109 | + |
|
110 | + final protected function get_right_side() |
|
111 | + { |
|
112 | + $side_array = array(); |
|
113 | + $side_array['tags'] = $this->get_tag_cloud(); |
|
114 | + $side_array['comments'] = $this->get_comments(); |
|
115 | + return $side_array; |
|
116 | + } |
|
117 | + |
|
118 | + final private function get_tag_cloud() |
|
119 | + { |
|
120 | 120 | global $container; |
121 | 121 | $repository = new Jacobemerick\Web\Domain\Blog\Tag\MysqlTagRepository($container['db_connection_locator']); |
122 | 122 | $tag_result = $repository->getTagCloud(); |
123 | 123 | |
124 | - $maximum_tag_count = $this->get_maximum_tag_count($tag_result); |
|
124 | + $maximum_tag_count = $this->get_maximum_tag_count($tag_result); |
|
125 | 125 | |
126 | - $cloud_array = array(); |
|
127 | - foreach($tag_result as $tag) |
|
128 | - { |
|
129 | - if($tag['count'] < self::$MINIMUM_TAG_COUNT) |
|
130 | - continue; |
|
126 | + $cloud_array = array(); |
|
127 | + foreach($tag_result as $tag) |
|
128 | + { |
|
129 | + if($tag['count'] < self::$MINIMUM_TAG_COUNT) |
|
130 | + continue; |
|
131 | 131 | |
132 | - $tag_object = new stdclass(); |
|
133 | - $tag_object->name = $tag['tag']; |
|
134 | - $tag_object->link = Content::instance('URLSafe', "/tag/{$tag['tag']}/")->activate(); |
|
135 | - $tag_object->scalar = floor(($tag['count'] - 1) * (9 / ($maximum_tag_count - self::$MINIMUM_TAG_COUNT))); |
|
136 | - $cloud_array[] = $tag_object; |
|
137 | - } |
|
132 | + $tag_object = new stdclass(); |
|
133 | + $tag_object->name = $tag['tag']; |
|
134 | + $tag_object->link = Content::instance('URLSafe', "/tag/{$tag['tag']}/")->activate(); |
|
135 | + $tag_object->scalar = floor(($tag['count'] - 1) * (9 / ($maximum_tag_count - self::$MINIMUM_TAG_COUNT))); |
|
136 | + $cloud_array[] = $tag_object; |
|
137 | + } |
|
138 | 138 | |
139 | - return $cloud_array; |
|
140 | - } |
|
139 | + return $cloud_array; |
|
140 | + } |
|
141 | 141 | |
142 | - final private function get_maximum_tag_count($tag_result) |
|
143 | - { |
|
144 | - $maximum = 1; |
|
142 | + final private function get_maximum_tag_count($tag_result) |
|
143 | + { |
|
144 | + $maximum = 1; |
|
145 | 145 | |
146 | - foreach($tag_result as $tag) |
|
147 | - { |
|
148 | - if($tag['count'] > $maximum) |
|
149 | - $maximum = $tag['count']; |
|
150 | - } |
|
151 | - return $maximum; |
|
152 | - } |
|
146 | + foreach($tag_result as $tag) |
|
147 | + { |
|
148 | + if($tag['count'] > $maximum) |
|
149 | + $maximum = $tag['count']; |
|
150 | + } |
|
151 | + return $maximum; |
|
152 | + } |
|
153 | 153 | |
154 | 154 | final private function get_comments() |
155 | 155 | { |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | Loader::load('collector', 'image/PhotoCollector'); |
40 | 40 | $photo_result = PhotoCollector::getRow($id); |
41 | 41 | |
42 | - if($photo_result == null) |
|
42 | + if ($photo_result == null) |
|
43 | 43 | return; |
44 | 44 | |
45 | 45 | $name = $photo_result->name; |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | $tag_result = $repository->getTagsForPost($post['id']); |
85 | 85 | |
86 | 86 | $tag_array = array(); |
87 | - foreach($tag_result as $tag) |
|
87 | + foreach ($tag_result as $tag) |
|
88 | 88 | { |
89 | 89 | $tag_object = new stdclass(); |
90 | 90 | $tag_object->name = $tag['tag']; |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | { |
99 | 99 | $body = $post['body']; |
100 | 100 | |
101 | - if($trim) |
|
101 | + if ($trim) |
|
102 | 102 | $body = Content::instance('SmartTrim', $body)->activate(self::$LENGTH_OF_TRIMMED_POST); |
103 | 103 | |
104 | 104 | $body = Content::instance('FixPhoto', $body)->activate(false, 'standard'); |
@@ -124,9 +124,9 @@ discard block |
||
124 | 124 | $maximum_tag_count = $this->get_maximum_tag_count($tag_result); |
125 | 125 | |
126 | 126 | $cloud_array = array(); |
127 | - foreach($tag_result as $tag) |
|
127 | + foreach ($tag_result as $tag) |
|
128 | 128 | { |
129 | - if($tag['count'] < self::$MINIMUM_TAG_COUNT) |
|
129 | + if ($tag['count'] < self::$MINIMUM_TAG_COUNT) |
|
130 | 130 | continue; |
131 | 131 | |
132 | 132 | $tag_object = new stdclass(); |
@@ -143,9 +143,9 @@ discard block |
||
143 | 143 | { |
144 | 144 | $maximum = 1; |
145 | 145 | |
146 | - foreach($tag_result as $tag) |
|
146 | + foreach ($tag_result as $tag) |
|
147 | 147 | { |
148 | - if($tag['count'] > $maximum) |
|
148 | + if ($tag['count'] > $maximum) |
|
149 | 149 | $maximum = $tag['count']; |
150 | 150 | } |
151 | 151 | return $maximum; |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | $container['logger']->info("CommentService | Sidebar | {$elapsed}"); |
175 | 175 | |
176 | 176 | $array = array(); |
177 | - foreach($comment_response as $comment) |
|
177 | + foreach ($comment_response as $comment) |
|
178 | 178 | { |
179 | 179 | $body = Content::instance('CleanComment', $comment['body'])->activate(); |
180 | 180 | $body = strip_tags($body); |
@@ -3,8 +3,8 @@ discard block |
||
3 | 3 | Loader::load('controller', '/PageController'); |
4 | 4 | Loader::load('utility', 'Content'); |
5 | 5 | |
6 | -abstract class DefaultPageController extends PageController |
|
7 | -{ |
|
6 | +abstract class DefaultPageController extends PageController |
|
7 | +{ |
|
8 | 8 | |
9 | 9 | private static $RECENT_COMMENT_COUNT = 10; |
10 | 10 | private static $MINIMUM_TAG_COUNT = 10; |
@@ -14,8 +14,8 @@ discard block |
||
14 | 14 | |
15 | 15 | private static $INTRODUCTION_IMAGE_PATTERN = '<img src="/photo/%s/%s-size-%s.jpg" height="%d" width="%d" alt="%s" />'; |
16 | 16 | |
17 | - protected function set_head_data() |
|
18 | - { |
|
17 | + protected function set_head_data() |
|
18 | + { |
|
19 | 19 | $this->set_head('rss_link', [ |
20 | 20 | 'title' => 'Jacob Emerick Blog Feed', |
21 | 21 | 'url' => '/rss.xml' |
@@ -29,18 +29,19 @@ discard block |
||
29 | 29 | $this->add_css('blog'); |
30 | 30 | } |
31 | 31 | |
32 | - protected function get_introduction() |
|
33 | - { |
|
32 | + protected function get_introduction() |
|
33 | + { |
|
34 | 34 | return; |
35 | 35 | } |
36 | 36 | |
37 | - protected function get_introduction_image($id) |
|
38 | - { |
|
37 | + protected function get_introduction_image($id) |
|
38 | + { |
|
39 | 39 | Loader::load('collector', 'image/PhotoCollector'); |
40 | 40 | $photo_result = PhotoCollector::getRow($id); |
41 | 41 | |
42 | - if($photo_result == null) |
|
43 | - return; |
|
42 | + if($photo_result == null) { |
|
43 | + return; |
|
44 | + } |
|
44 | 45 | |
45 | 46 | $name = $photo_result->name; |
46 | 47 | $category = $photo_result->category; |
@@ -52,8 +53,8 @@ discard block |
||
52 | 53 | return sprintf(self::$INTRODUCTION_IMAGE_PATTERN, $category, $name, $size, $height, $width, $description); |
53 | 54 | } |
54 | 55 | |
55 | - protected function set_body_data() |
|
56 | - { |
|
56 | + protected function set_body_data() |
|
57 | + { |
|
57 | 58 | $this->set_body('introduction', $this->get_introduction()); |
58 | 59 | $this->set_body('right_side', $this->get_right_side()); |
59 | 60 | $this->set_body('activity_array', $this->get_recent_activity()); |
@@ -61,8 +62,8 @@ discard block |
||
61 | 62 | $this->set_body_view('Page'); |
62 | 63 | } |
63 | 64 | |
64 | - final protected function format_post($post, $trim = false) |
|
65 | - { |
|
65 | + final protected function format_post($post, $trim = false) |
|
66 | + { |
|
66 | 67 | $post_object = new stdclass(); |
67 | 68 | |
68 | 69 | $post_object->title = $post['title']; |
@@ -77,8 +78,8 @@ discard block |
||
77 | 78 | return $post_object; |
78 | 79 | } |
79 | 80 | |
80 | - final private function get_tags_for_post($post) |
|
81 | - { |
|
81 | + final private function get_tags_for_post($post) |
|
82 | + { |
|
82 | 83 | global $container; |
83 | 84 | $repository = new Jacobemerick\Web\Domain\Blog\Tag\MysqlTagRepository($container['db_connection_locator']); |
84 | 85 | $tag_result = $repository->getTagsForPost($post['id']); |
@@ -94,12 +95,13 @@ discard block |
||
94 | 95 | return $tag_array; |
95 | 96 | } |
96 | 97 | |
97 | - final private function get_body_for_post($post, $trim) |
|
98 | - { |
|
98 | + final private function get_body_for_post($post, $trim) |
|
99 | + { |
|
99 | 100 | $body = $post['body']; |
100 | 101 | |
101 | - if($trim) |
|
102 | - $body = Content::instance('SmartTrim', $body)->activate(self::$LENGTH_OF_TRIMMED_POST); |
|
102 | + if($trim) { |
|
103 | + $body = Content::instance('SmartTrim', $body)->activate(self::$LENGTH_OF_TRIMMED_POST); |
|
104 | + } |
|
103 | 105 | |
104 | 106 | $body = Content::instance('FixPhoto', $body)->activate(false, 'standard'); |
105 | 107 | $body = Content::instance('MarkupCode', $body)->activate(); |
@@ -107,16 +109,16 @@ discard block |
||
107 | 109 | return $body; |
108 | 110 | } |
109 | 111 | |
110 | - final protected function get_right_side() |
|
111 | - { |
|
112 | + final protected function get_right_side() |
|
113 | + { |
|
112 | 114 | $side_array = array(); |
113 | 115 | $side_array['tags'] = $this->get_tag_cloud(); |
114 | 116 | $side_array['comments'] = $this->get_comments(); |
115 | 117 | return $side_array; |
116 | 118 | } |
117 | 119 | |
118 | - final private function get_tag_cloud() |
|
119 | - { |
|
120 | + final private function get_tag_cloud() |
|
121 | + { |
|
120 | 122 | global $container; |
121 | 123 | $repository = new Jacobemerick\Web\Domain\Blog\Tag\MysqlTagRepository($container['db_connection_locator']); |
122 | 124 | $tag_result = $repository->getTagCloud(); |
@@ -126,8 +128,9 @@ discard block |
||
126 | 128 | $cloud_array = array(); |
127 | 129 | foreach($tag_result as $tag) |
128 | 130 | { |
129 | - if($tag['count'] < self::$MINIMUM_TAG_COUNT) |
|
130 | - continue; |
|
131 | + if($tag['count'] < self::$MINIMUM_TAG_COUNT) { |
|
132 | + continue; |
|
133 | + } |
|
131 | 134 | |
132 | 135 | $tag_object = new stdclass(); |
133 | 136 | $tag_object->name = $tag['tag']; |
@@ -139,20 +142,21 @@ discard block |
||
139 | 142 | return $cloud_array; |
140 | 143 | } |
141 | 144 | |
142 | - final private function get_maximum_tag_count($tag_result) |
|
143 | - { |
|
145 | + final private function get_maximum_tag_count($tag_result) |
|
146 | + { |
|
144 | 147 | $maximum = 1; |
145 | 148 | |
146 | 149 | foreach($tag_result as $tag) |
147 | 150 | { |
148 | - if($tag['count'] > $maximum) |
|
149 | - $maximum = $tag['count']; |
|
151 | + if($tag['count'] > $maximum) { |
|
152 | + $maximum = $tag['count']; |
|
153 | + } |
|
150 | 154 | } |
151 | 155 | return $maximum; |
152 | 156 | } |
153 | 157 | |
154 | - final private function get_comments() |
|
155 | - { |
|
158 | + final private function get_comments() |
|
159 | + { |
|
156 | 160 | global $container; |
157 | 161 | $repository = new Jacobemerick\Web\Domain\Comment\Comment\ServiceCommentRepository($container['comment_service_api']); |
158 | 162 | $start = microtime(true); |
@@ -25,6 +25,9 @@ discard block |
||
25 | 25 | return; |
26 | 26 | } |
27 | 27 | |
28 | + /** |
|
29 | + * @param string $content |
|
30 | + */ |
|
28 | 31 | private function wrap_in_list($content) |
29 | 32 | { |
30 | 33 | $content_array = explode("\n", $content); |
@@ -44,6 +47,9 @@ discard block |
||
44 | 47 | return $content; |
45 | 48 | } |
46 | 49 | |
50 | + /** |
|
51 | + * @param string $type |
|
52 | + */ |
|
47 | 53 | private function highlight_code($content, $type) |
48 | 54 | { |
49 | 55 | switch($type) |
@@ -10,10 +10,10 @@ discard block |
||
10 | 10 | protected function execute($title = '') |
11 | 11 | { |
12 | 12 | preg_match_all(self::$MARKUP_DELIMITER, $this->content, $matches); |
13 | - if(count($matches[1]) == 0) |
|
13 | + if (count($matches[1]) == 0) |
|
14 | 14 | return; |
15 | 15 | |
16 | - foreach($matches[3] as $key => $match) |
|
16 | + foreach ($matches[3] as $key => $match) |
|
17 | 17 | { |
18 | 18 | $replacement = $match; |
19 | 19 | $replacement = $this->wrap_in_list($replacement); |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | { |
30 | 30 | $content_array = explode("\n", $content); |
31 | 31 | |
32 | - foreach($content_array as $key => $row) |
|
32 | + foreach ($content_array as $key => $row) |
|
33 | 33 | { |
34 | 34 | $new_row = ($key % 2 == 0) ? '<li class="even">' : '<li class="odd">'; |
35 | 35 | $new_row .= '<p>'; |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | |
47 | 47 | private function highlight_code($content, $type) |
48 | 48 | { |
49 | - switch($type) |
|
49 | + switch ($type) |
|
50 | 50 | { |
51 | 51 | default : |
52 | 52 | return $content; |
@@ -5,53 +5,53 @@ |
||
5 | 5 | final class MarkupCodeContent extends Content |
6 | 6 | { |
7 | 7 | |
8 | - private static $MARKUP_DELIMITER = '@<pre( rel="(.*?)")?>(.*?)</pre>@s'; |
|
8 | + private static $MARKUP_DELIMITER = '@<pre( rel="(.*?)")?>(.*?)</pre>@s'; |
|
9 | 9 | |
10 | - protected function execute($title = '') |
|
11 | - { |
|
12 | - preg_match_all(self::$MARKUP_DELIMITER, $this->content, $matches); |
|
13 | - if(count($matches[1]) == 0) |
|
14 | - return; |
|
10 | + protected function execute($title = '') |
|
11 | + { |
|
12 | + preg_match_all(self::$MARKUP_DELIMITER, $this->content, $matches); |
|
13 | + if(count($matches[1]) == 0) |
|
14 | + return; |
|
15 | 15 | |
16 | - foreach($matches[3] as $key => $match) |
|
17 | - { |
|
18 | - $replacement = $match; |
|
19 | - $replacement = $this->wrap_in_list($replacement); |
|
20 | - $replacement = $this->highlight_code($replacement, $matches[2][$key]); |
|
16 | + foreach($matches[3] as $key => $match) |
|
17 | + { |
|
18 | + $replacement = $match; |
|
19 | + $replacement = $this->wrap_in_list($replacement); |
|
20 | + $replacement = $this->highlight_code($replacement, $matches[2][$key]); |
|
21 | 21 | |
22 | - $this->content = str_replace($match, $replacement, $this->content); |
|
23 | - } |
|
22 | + $this->content = str_replace($match, $replacement, $this->content); |
|
23 | + } |
|
24 | 24 | |
25 | - return; |
|
26 | - } |
|
25 | + return; |
|
26 | + } |
|
27 | 27 | |
28 | - private function wrap_in_list($content) |
|
29 | - { |
|
30 | - $content_array = explode("\n", $content); |
|
28 | + private function wrap_in_list($content) |
|
29 | + { |
|
30 | + $content_array = explode("\n", $content); |
|
31 | 31 | |
32 | - foreach($content_array as $key => $row) |
|
33 | - { |
|
34 | - $new_row = ($key % 2 == 0) ? '<li class="even">' : '<li class="odd">'; |
|
35 | - $new_row .= '<p>'; |
|
36 | - $new_row .= $row; |
|
37 | - $new_row .= '</p>'; |
|
38 | - $new_row .= '</li>'; |
|
39 | - $content_array[$key] = $new_row; |
|
40 | - } |
|
32 | + foreach($content_array as $key => $row) |
|
33 | + { |
|
34 | + $new_row = ($key % 2 == 0) ? '<li class="even">' : '<li class="odd">'; |
|
35 | + $new_row .= '<p>'; |
|
36 | + $new_row .= $row; |
|
37 | + $new_row .= '</p>'; |
|
38 | + $new_row .= '</li>'; |
|
39 | + $content_array[$key] = $new_row; |
|
40 | + } |
|
41 | 41 | |
42 | - $content = implode($content_array); |
|
43 | - $content = "<ol>{$content}</ol>"; |
|
44 | - return $content; |
|
45 | - } |
|
42 | + $content = implode($content_array); |
|
43 | + $content = "<ol>{$content}</ol>"; |
|
44 | + return $content; |
|
45 | + } |
|
46 | 46 | |
47 | - private function highlight_code($content, $type) |
|
48 | - { |
|
49 | - switch($type) |
|
50 | - { |
|
51 | - default : |
|
52 | - return $content; |
|
53 | - break; |
|
54 | - } |
|
55 | - } |
|
47 | + private function highlight_code($content, $type) |
|
48 | + { |
|
49 | + switch($type) |
|
50 | + { |
|
51 | + default : |
|
52 | + return $content; |
|
53 | + break; |
|
54 | + } |
|
55 | + } |
|
56 | 56 | |
57 | 57 | } |
58 | 58 | \ No newline at end of file |
@@ -2,16 +2,17 @@ discard block |
||
2 | 2 | |
3 | 3 | Loader::load('utility', 'Content'); |
4 | 4 | |
5 | -final class MarkupCodeContent extends Content |
|
6 | -{ |
|
5 | +final class MarkupCodeContent extends Content |
|
6 | +{ |
|
7 | 7 | |
8 | 8 | private static $MARKUP_DELIMITER = '@<pre( rel="(.*?)")?>(.*?)</pre>@s'; |
9 | 9 | |
10 | - protected function execute($title = '') |
|
11 | - { |
|
10 | + protected function execute($title = '') |
|
11 | + { |
|
12 | 12 | preg_match_all(self::$MARKUP_DELIMITER, $this->content, $matches); |
13 | - if(count($matches[1]) == 0) |
|
14 | - return; |
|
13 | + if(count($matches[1]) == 0) { |
|
14 | + return; |
|
15 | + } |
|
15 | 16 | |
16 | 17 | foreach($matches[3] as $key => $match) |
17 | 18 | { |
@@ -25,8 +26,8 @@ discard block |
||
25 | 26 | return; |
26 | 27 | } |
27 | 28 | |
28 | - private function wrap_in_list($content) |
|
29 | - { |
|
29 | + private function wrap_in_list($content) |
|
30 | + { |
|
30 | 31 | $content_array = explode("\n", $content); |
31 | 32 | |
32 | 33 | foreach($content_array as $key => $row) |
@@ -44,8 +45,8 @@ discard block |
||
44 | 45 | return $content; |
45 | 46 | } |
46 | 47 | |
47 | - private function highlight_code($content, $type) |
|
48 | - { |
|
48 | + private function highlight_code($content, $type) |
|
49 | + { |
|
49 | 50 | switch($type) |
50 | 51 | { |
51 | 52 | default : |
@@ -62,6 +62,9 @@ |
||
62 | 62 | $this->is_trimmed = true; |
63 | 63 | } |
64 | 64 | |
65 | + /** |
|
66 | + * @param string $content |
|
67 | + */ |
|
65 | 68 | private function trim_html_string($content, $length) |
66 | 69 | { |
67 | 70 | $content = preg_replace(self::$PHOTO_PLACEHOLDER_MATCH, '', $content); |
@@ -27,20 +27,20 @@ discard block |
||
27 | 27 | protected function execute() |
28 | 28 | { |
29 | 29 | $args = func_get_args(); |
30 | - if(count($args) < 1) |
|
30 | + if (count($args) < 1) |
|
31 | 31 | { |
32 | 32 | trigger_error('Someone called SmartTrimContent w/o defining a length... bad!'); |
33 | 33 | return; |
34 | 34 | } |
35 | 35 | |
36 | - if(count($args) == 2) |
|
36 | + if (count($args) == 2) |
|
37 | 37 | $etc = $args[1]; |
38 | 38 | else |
39 | 39 | $etc = self::$ETC; |
40 | 40 | |
41 | 41 | $length = $args[0]; |
42 | 42 | |
43 | - if($length < strlen($this->content)) |
|
43 | + if ($length < strlen($this->content)) |
|
44 | 44 | $this->trim_string($length); |
45 | 45 | else |
46 | 46 | $etc = ''; |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | |
55 | 55 | $last_right_bracket_position = strripos($content, self::$RIGHT_BRACKET); |
56 | 56 | $last_left_bracket_position = strripos($content, self::$LEFT_BRACKET); |
57 | - if($last_left_bracket_position > $last_right_bracket_position) |
|
57 | + if ($last_left_bracket_position > $last_right_bracket_position) |
|
58 | 58 | $content = substr($content, 0, $last_left_bracket_position); |
59 | 59 | $content = trim($content); |
60 | 60 | |
@@ -73,16 +73,16 @@ discard block |
||
73 | 73 | $content = current($content); |
74 | 74 | |
75 | 75 | $max_length = $length; |
76 | - foreach($matches[0] as $match) |
|
76 | + foreach ($matches[0] as $match) |
|
77 | 77 | { |
78 | 78 | $max_length += strlen($match[0]); |
79 | - if($max_length <= $match[1]) |
|
79 | + if ($max_length <= $match[1]) |
|
80 | 80 | break; |
81 | 81 | |
82 | - $content = substr($content, 0, $match[1]) . $match[0] . substr($content, $match[1]); |
|
82 | + $content = substr($content, 0, $match[1]).$match[0].substr($content, $match[1]); |
|
83 | 83 | } |
84 | 84 | |
85 | - if(substr($content, -7) == '</p><p>') |
|
85 | + if (substr($content, -7) == '</p><p>') |
|
86 | 86 | $content = substr($content, 0, -7); |
87 | 87 | |
88 | 88 | return $content; |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | $tags_preg = $this->get_tags_preg(self::$EXCLUDE_TAGS); |
95 | 95 | preg_match_all($tags_preg, $content, $matches, PREG_OFFSET_CAPTURE); |
96 | 96 | |
97 | - if(count($matches[1]) % 2 == 1) |
|
97 | + if (count($matches[1]) % 2 == 1) |
|
98 | 98 | { |
99 | 99 | $cut_tag = end($matches[1]); |
100 | 100 | $cut_tag_position = $cut_tag[1] - 1; |
@@ -112,9 +112,9 @@ discard block |
||
112 | 112 | preg_match_all($tags_preg, $content, $matches); |
113 | 113 | $open_tags = array(); |
114 | 114 | |
115 | - foreach($matches[1] as $tag) |
|
115 | + foreach ($matches[1] as $tag) |
|
116 | 116 | { |
117 | - if(in_array($tag, $open_tags)) |
|
117 | + if (in_array($tag, $open_tags)) |
|
118 | 118 | { |
119 | 119 | $key = array_search($tag, $open_tags); |
120 | 120 | unset($open_tags[$key]); |
@@ -124,11 +124,11 @@ discard block |
||
124 | 124 | } |
125 | 125 | |
126 | 126 | $open_tags = array_reverse($open_tags); |
127 | - if(count($open_tags) > 0) |
|
127 | + if (count($open_tags) > 0) |
|
128 | 128 | { |
129 | - foreach($open_tags as $key => $open_tag) |
|
129 | + foreach ($open_tags as $key => $open_tag) |
|
130 | 130 | { |
131 | - if($key == count($open_tags) - 1) |
|
131 | + if ($key == count($open_tags) - 1) |
|
132 | 132 | $content .= $etc; |
133 | 133 | $content .= "</{$open_tag}>"; |
134 | 134 | } |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | |
142 | 142 | private function get_tags_preg($tag_array) |
143 | 143 | { |
144 | - return '@</?(' . implode('|', $tag_array) . ')@'; |
|
144 | + return '@</?('.implode('|', $tag_array).')@'; |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | } |
@@ -5,143 +5,143 @@ |
||
5 | 5 | class SmartTrimContent extends Content |
6 | 6 | { |
7 | 7 | |
8 | - private static $EXCLUDE_TAGS = array( |
|
9 | - 'a', |
|
10 | - 'div', |
|
11 | - 'h4', |
|
12 | - 'pre'); |
|
13 | - private static $INCLUDE_TAGS = array( |
|
14 | - 'li', |
|
15 | - 'ol', |
|
16 | - 'p', |
|
17 | - 'ul'); |
|
18 | - private static $PHOTO_PLACEHOLDER_MATCH = '/{{photo="(.*)"}}/'; |
|
19 | - private static $HTML_TAG_PATTERN = '/<[^>]+>/'; |
|
20 | - private static $CUT_MARKER = '/*/ CUT HERE /*/'; |
|
21 | - private static $RIGHT_BRACKET = '>'; |
|
22 | - private static $LEFT_BRACKET = '<'; |
|
23 | - private static $ETC = '…'; |
|
8 | + private static $EXCLUDE_TAGS = array( |
|
9 | + 'a', |
|
10 | + 'div', |
|
11 | + 'h4', |
|
12 | + 'pre'); |
|
13 | + private static $INCLUDE_TAGS = array( |
|
14 | + 'li', |
|
15 | + 'ol', |
|
16 | + 'p', |
|
17 | + 'ul'); |
|
18 | + private static $PHOTO_PLACEHOLDER_MATCH = '/{{photo="(.*)"}}/'; |
|
19 | + private static $HTML_TAG_PATTERN = '/<[^>]+>/'; |
|
20 | + private static $CUT_MARKER = '/*/ CUT HERE /*/'; |
|
21 | + private static $RIGHT_BRACKET = '>'; |
|
22 | + private static $LEFT_BRACKET = '<'; |
|
23 | + private static $ETC = '…'; |
|
24 | 24 | |
25 | - private $is_trimmed; |
|
25 | + private $is_trimmed; |
|
26 | 26 | |
27 | - protected function execute() |
|
28 | - { |
|
29 | - $args = func_get_args(); |
|
30 | - if(count($args) < 1) |
|
31 | - { |
|
32 | - trigger_error('Someone called SmartTrimContent w/o defining a length... bad!'); |
|
33 | - return; |
|
34 | - } |
|
27 | + protected function execute() |
|
28 | + { |
|
29 | + $args = func_get_args(); |
|
30 | + if(count($args) < 1) |
|
31 | + { |
|
32 | + trigger_error('Someone called SmartTrimContent w/o defining a length... bad!'); |
|
33 | + return; |
|
34 | + } |
|
35 | 35 | |
36 | - if(count($args) == 2) |
|
37 | - $etc = $args[1]; |
|
38 | - else |
|
39 | - $etc = self::$ETC; |
|
36 | + if(count($args) == 2) |
|
37 | + $etc = $args[1]; |
|
38 | + else |
|
39 | + $etc = self::$ETC; |
|
40 | 40 | |
41 | - $length = $args[0]; |
|
41 | + $length = $args[0]; |
|
42 | 42 | |
43 | - if($length < strlen($this->content)) |
|
44 | - $this->trim_string($length); |
|
43 | + if($length < strlen($this->content)) |
|
44 | + $this->trim_string($length); |
|
45 | 45 | else |
46 | 46 | $etc = ''; |
47 | - $this->check_exclude_tags(); |
|
48 | - $this->close_tags($etc); |
|
49 | - } |
|
47 | + $this->check_exclude_tags(); |
|
48 | + $this->close_tags($etc); |
|
49 | + } |
|
50 | 50 | |
51 | - private function trim_string($length) |
|
52 | - { |
|
53 | - $content = $this->trim_html_string($this->content, $length); |
|
51 | + private function trim_string($length) |
|
52 | + { |
|
53 | + $content = $this->trim_html_string($this->content, $length); |
|
54 | 54 | |
55 | - $last_right_bracket_position = strripos($content, self::$RIGHT_BRACKET); |
|
56 | - $last_left_bracket_position = strripos($content, self::$LEFT_BRACKET); |
|
57 | - if($last_left_bracket_position > $last_right_bracket_position) |
|
58 | - $content = substr($content, 0, $last_left_bracket_position); |
|
59 | - $content = trim($content); |
|
55 | + $last_right_bracket_position = strripos($content, self::$RIGHT_BRACKET); |
|
56 | + $last_left_bracket_position = strripos($content, self::$LEFT_BRACKET); |
|
57 | + if($last_left_bracket_position > $last_right_bracket_position) |
|
58 | + $content = substr($content, 0, $last_left_bracket_position); |
|
59 | + $content = trim($content); |
|
60 | 60 | |
61 | - $this->content = $content; |
|
62 | - $this->is_trimmed = true; |
|
63 | - } |
|
61 | + $this->content = $content; |
|
62 | + $this->is_trimmed = true; |
|
63 | + } |
|
64 | 64 | |
65 | - private function trim_html_string($content, $length) |
|
66 | - { |
|
67 | - $content = preg_replace(self::$PHOTO_PLACEHOLDER_MATCH, '', $content); |
|
68 | - preg_match_all(self::$HTML_TAG_PATTERN, $content, $matches, PREG_OFFSET_CAPTURE); |
|
69 | - $content = strip_tags($content); |
|
65 | + private function trim_html_string($content, $length) |
|
66 | + { |
|
67 | + $content = preg_replace(self::$PHOTO_PLACEHOLDER_MATCH, '', $content); |
|
68 | + preg_match_all(self::$HTML_TAG_PATTERN, $content, $matches, PREG_OFFSET_CAPTURE); |
|
69 | + $content = strip_tags($content); |
|
70 | 70 | |
71 | - $content = wordwrap($content, $length, self::$CUT_MARKER); |
|
72 | - $content = explode(self::$CUT_MARKER, $content); |
|
73 | - $content = current($content); |
|
71 | + $content = wordwrap($content, $length, self::$CUT_MARKER); |
|
72 | + $content = explode(self::$CUT_MARKER, $content); |
|
73 | + $content = current($content); |
|
74 | 74 | |
75 | - $max_length = $length; |
|
76 | - foreach($matches[0] as $match) |
|
77 | - { |
|
78 | - $max_length += strlen($match[0]); |
|
79 | - if($max_length <= $match[1]) |
|
80 | - break; |
|
75 | + $max_length = $length; |
|
76 | + foreach($matches[0] as $match) |
|
77 | + { |
|
78 | + $max_length += strlen($match[0]); |
|
79 | + if($max_length <= $match[1]) |
|
80 | + break; |
|
81 | 81 | |
82 | - $content = substr($content, 0, $match[1]) . $match[0] . substr($content, $match[1]); |
|
83 | - } |
|
82 | + $content = substr($content, 0, $match[1]) . $match[0] . substr($content, $match[1]); |
|
83 | + } |
|
84 | 84 | |
85 | - if(substr($content, -7) == '</p><p>') |
|
86 | - $content = substr($content, 0, -7); |
|
85 | + if(substr($content, -7) == '</p><p>') |
|
86 | + $content = substr($content, 0, -7); |
|
87 | 87 | |
88 | - return $content; |
|
89 | - } |
|
88 | + return $content; |
|
89 | + } |
|
90 | 90 | |
91 | - private function check_exclude_tags() |
|
92 | - { |
|
93 | - $content = $this->content; |
|
94 | - $tags_preg = $this->get_tags_preg(self::$EXCLUDE_TAGS); |
|
95 | - preg_match_all($tags_preg, $content, $matches, PREG_OFFSET_CAPTURE); |
|
91 | + private function check_exclude_tags() |
|
92 | + { |
|
93 | + $content = $this->content; |
|
94 | + $tags_preg = $this->get_tags_preg(self::$EXCLUDE_TAGS); |
|
95 | + preg_match_all($tags_preg, $content, $matches, PREG_OFFSET_CAPTURE); |
|
96 | 96 | |
97 | - if(count($matches[1]) % 2 == 1) |
|
98 | - { |
|
99 | - $cut_tag = end($matches[1]); |
|
100 | - $cut_tag_position = $cut_tag[1] - 1; |
|
101 | - $content = substr($content, 0, $cut_tag_position); |
|
102 | - } |
|
103 | - $content = trim($content); |
|
97 | + if(count($matches[1]) % 2 == 1) |
|
98 | + { |
|
99 | + $cut_tag = end($matches[1]); |
|
100 | + $cut_tag_position = $cut_tag[1] - 1; |
|
101 | + $content = substr($content, 0, $cut_tag_position); |
|
102 | + } |
|
103 | + $content = trim($content); |
|
104 | 104 | |
105 | - $this->content = $content; |
|
106 | - } |
|
105 | + $this->content = $content; |
|
106 | + } |
|
107 | 107 | |
108 | - private function close_tags($etc) |
|
109 | - { |
|
110 | - $content = $this->content; |
|
111 | - $tags_preg = $this->get_tags_preg(self::$INCLUDE_TAGS); |
|
112 | - preg_match_all($tags_preg, $content, $matches); |
|
113 | - $open_tags = array(); |
|
108 | + private function close_tags($etc) |
|
109 | + { |
|
110 | + $content = $this->content; |
|
111 | + $tags_preg = $this->get_tags_preg(self::$INCLUDE_TAGS); |
|
112 | + preg_match_all($tags_preg, $content, $matches); |
|
113 | + $open_tags = array(); |
|
114 | 114 | |
115 | - foreach($matches[1] as $tag) |
|
116 | - { |
|
117 | - if(in_array($tag, $open_tags)) |
|
118 | - { |
|
119 | - $key = array_search($tag, $open_tags); |
|
120 | - unset($open_tags[$key]); |
|
121 | - } |
|
122 | - else |
|
123 | - $open_tags[] = $tag; |
|
124 | - } |
|
115 | + foreach($matches[1] as $tag) |
|
116 | + { |
|
117 | + if(in_array($tag, $open_tags)) |
|
118 | + { |
|
119 | + $key = array_search($tag, $open_tags); |
|
120 | + unset($open_tags[$key]); |
|
121 | + } |
|
122 | + else |
|
123 | + $open_tags[] = $tag; |
|
124 | + } |
|
125 | 125 | |
126 | - $open_tags = array_reverse($open_tags); |
|
127 | - if(count($open_tags) > 0) |
|
128 | - { |
|
129 | - foreach($open_tags as $key => $open_tag) |
|
130 | - { |
|
131 | - if($key == count($open_tags) - 1) |
|
132 | - $content .= $etc; |
|
133 | - $content .= "</{$open_tag}>"; |
|
134 | - } |
|
135 | - } |
|
136 | - else |
|
137 | - $content .= $etc; |
|
126 | + $open_tags = array_reverse($open_tags); |
|
127 | + if(count($open_tags) > 0) |
|
128 | + { |
|
129 | + foreach($open_tags as $key => $open_tag) |
|
130 | + { |
|
131 | + if($key == count($open_tags) - 1) |
|
132 | + $content .= $etc; |
|
133 | + $content .= "</{$open_tag}>"; |
|
134 | + } |
|
135 | + } |
|
136 | + else |
|
137 | + $content .= $etc; |
|
138 | 138 | |
139 | - $this->content = $content; |
|
140 | - } |
|
139 | + $this->content = $content; |
|
140 | + } |
|
141 | 141 | |
142 | - private function get_tags_preg($tag_array) |
|
143 | - { |
|
144 | - return '@</?(' . implode('|', $tag_array) . ')@'; |
|
145 | - } |
|
142 | + private function get_tags_preg($tag_array) |
|
143 | + { |
|
144 | + return '@</?(' . implode('|', $tag_array) . ')@'; |
|
145 | + } |
|
146 | 146 | |
147 | 147 | } |
@@ -2,8 +2,8 @@ discard block |
||
2 | 2 | |
3 | 3 | Loader::load('utility', 'Content'); |
4 | 4 | |
5 | -class SmartTrimContent extends Content |
|
6 | -{ |
|
5 | +class SmartTrimContent extends Content |
|
6 | +{ |
|
7 | 7 | |
8 | 8 | private static $EXCLUDE_TAGS = array( |
9 | 9 | 'a', |
@@ -24,8 +24,8 @@ discard block |
||
24 | 24 | |
25 | 25 | private $is_trimmed; |
26 | 26 | |
27 | - protected function execute() |
|
28 | - { |
|
27 | + protected function execute() |
|
28 | + { |
|
29 | 29 | $args = func_get_args(); |
30 | 30 | if(count($args) < 1) |
31 | 31 | { |
@@ -33,37 +33,40 @@ discard block |
||
33 | 33 | return; |
34 | 34 | } |
35 | 35 | |
36 | - if(count($args) == 2) |
|
37 | - $etc = $args[1]; |
|
38 | - else |
|
39 | - $etc = self::$ETC; |
|
36 | + if(count($args) == 2) { |
|
37 | + $etc = $args[1]; |
|
38 | + } else { |
|
39 | + $etc = self::$ETC; |
|
40 | + } |
|
40 | 41 | |
41 | 42 | $length = $args[0]; |
42 | 43 | |
43 | - if($length < strlen($this->content)) |
|
44 | - $this->trim_string($length); |
|
45 | - else |
|
46 | - $etc = ''; |
|
44 | + if($length < strlen($this->content)) { |
|
45 | + $this->trim_string($length); |
|
46 | + } else { |
|
47 | + $etc = ''; |
|
48 | + } |
|
47 | 49 | $this->check_exclude_tags(); |
48 | 50 | $this->close_tags($etc); |
49 | 51 | } |
50 | 52 | |
51 | - private function trim_string($length) |
|
52 | - { |
|
53 | + private function trim_string($length) |
|
54 | + { |
|
53 | 55 | $content = $this->trim_html_string($this->content, $length); |
54 | 56 | |
55 | 57 | $last_right_bracket_position = strripos($content, self::$RIGHT_BRACKET); |
56 | 58 | $last_left_bracket_position = strripos($content, self::$LEFT_BRACKET); |
57 | - if($last_left_bracket_position > $last_right_bracket_position) |
|
58 | - $content = substr($content, 0, $last_left_bracket_position); |
|
59 | + if($last_left_bracket_position > $last_right_bracket_position) { |
|
60 | + $content = substr($content, 0, $last_left_bracket_position); |
|
61 | + } |
|
59 | 62 | $content = trim($content); |
60 | 63 | |
61 | 64 | $this->content = $content; |
62 | 65 | $this->is_trimmed = true; |
63 | 66 | } |
64 | 67 | |
65 | - private function trim_html_string($content, $length) |
|
66 | - { |
|
68 | + private function trim_html_string($content, $length) |
|
69 | + { |
|
67 | 70 | $content = preg_replace(self::$PHOTO_PLACEHOLDER_MATCH, '', $content); |
68 | 71 | preg_match_all(self::$HTML_TAG_PATTERN, $content, $matches, PREG_OFFSET_CAPTURE); |
69 | 72 | $content = strip_tags($content); |
@@ -76,20 +79,22 @@ discard block |
||
76 | 79 | foreach($matches[0] as $match) |
77 | 80 | { |
78 | 81 | $max_length += strlen($match[0]); |
79 | - if($max_length <= $match[1]) |
|
80 | - break; |
|
82 | + if($max_length <= $match[1]) { |
|
83 | + break; |
|
84 | + } |
|
81 | 85 | |
82 | 86 | $content = substr($content, 0, $match[1]) . $match[0] . substr($content, $match[1]); |
83 | 87 | } |
84 | 88 | |
85 | - if(substr($content, -7) == '</p><p>') |
|
86 | - $content = substr($content, 0, -7); |
|
89 | + if(substr($content, -7) == '</p><p>') { |
|
90 | + $content = substr($content, 0, -7); |
|
91 | + } |
|
87 | 92 | |
88 | 93 | return $content; |
89 | 94 | } |
90 | 95 | |
91 | - private function check_exclude_tags() |
|
92 | - { |
|
96 | + private function check_exclude_tags() |
|
97 | + { |
|
93 | 98 | $content = $this->content; |
94 | 99 | $tags_preg = $this->get_tags_preg(self::$EXCLUDE_TAGS); |
95 | 100 | preg_match_all($tags_preg, $content, $matches, PREG_OFFSET_CAPTURE); |
@@ -105,8 +110,8 @@ discard block |
||
105 | 110 | $this->content = $content; |
106 | 111 | } |
107 | 112 | |
108 | - private function close_tags($etc) |
|
109 | - { |
|
113 | + private function close_tags($etc) |
|
114 | + { |
|
110 | 115 | $content = $this->content; |
111 | 116 | $tags_preg = $this->get_tags_preg(self::$INCLUDE_TAGS); |
112 | 117 | preg_match_all($tags_preg, $content, $matches); |
@@ -118,9 +123,9 @@ discard block |
||
118 | 123 | { |
119 | 124 | $key = array_search($tag, $open_tags); |
120 | 125 | unset($open_tags[$key]); |
121 | - } |
|
122 | - else |
|
123 | - $open_tags[] = $tag; |
|
126 | + } else { |
|
127 | + $open_tags[] = $tag; |
|
128 | + } |
|
124 | 129 | } |
125 | 130 | |
126 | 131 | $open_tags = array_reverse($open_tags); |
@@ -128,19 +133,20 @@ discard block |
||
128 | 133 | { |
129 | 134 | foreach($open_tags as $key => $open_tag) |
130 | 135 | { |
131 | - if($key == count($open_tags) - 1) |
|
132 | - $content .= $etc; |
|
136 | + if($key == count($open_tags) - 1) { |
|
137 | + $content .= $etc; |
|
138 | + } |
|
133 | 139 | $content .= "</{$open_tag}>"; |
134 | 140 | } |
135 | - } |
|
136 | - else |
|
137 | - $content .= $etc; |
|
141 | + } else { |
|
142 | + $content .= $etc; |
|
143 | + } |
|
138 | 144 | |
139 | 145 | $this->content = $content; |
140 | 146 | } |
141 | 147 | |
142 | - private function get_tags_preg($tag_array) |
|
143 | - { |
|
148 | + private function get_tags_preg($tag_array) |
|
149 | + { |
|
144 | 150 | return '@</?(' . implode('|', $tag_array) . ')@'; |
145 | 151 | } |
146 | 152 |
@@ -34,6 +34,9 @@ |
||
34 | 34 | return false; |
35 | 35 | } |
36 | 36 | |
37 | + /** |
|
38 | + * @param string $key |
|
39 | + */ |
|
37 | 40 | static function getGet($key = null) |
38 | 41 | { |
39 | 42 | if($key) |
@@ -18,9 +18,9 @@ discard block |
||
18 | 18 | |
19 | 19 | static function getServer($key = null) |
20 | 20 | { |
21 | - if($key) |
|
21 | + if ($key) |
|
22 | 22 | { |
23 | - if(isset(self::$server[$key])) |
|
23 | + if (isset(self::$server[$key])) |
|
24 | 24 | return self::$server[$key]; |
25 | 25 | return false; |
26 | 26 | } |
@@ -29,16 +29,16 @@ discard block |
||
29 | 29 | |
30 | 30 | static function isAjax() |
31 | 31 | { |
32 | - if(self::getServer(self::$AJAX_REQUEST)) |
|
32 | + if (self::getServer(self::$AJAX_REQUEST)) |
|
33 | 33 | return true; |
34 | 34 | return false; |
35 | 35 | } |
36 | 36 | |
37 | 37 | static function getGet($key = null) |
38 | 38 | { |
39 | - if($key) |
|
39 | + if ($key) |
|
40 | 40 | { |
41 | - if(isset(self::$get[$key])) |
|
41 | + if (isset(self::$get[$key])) |
|
42 | 42 | return self::$get[$key]; |
43 | 43 | return false; |
44 | 44 | } |
@@ -47,9 +47,9 @@ discard block |
||
47 | 47 | |
48 | 48 | static function getPost($key = null) |
49 | 49 | { |
50 | - if($key) |
|
50 | + if ($key) |
|
51 | 51 | { |
52 | - if(isset(self::$post[$key])) |
|
52 | + if (isset(self::$post[$key])) |
|
53 | 53 | return self::$post[$key]; |
54 | 54 | return false; |
55 | 55 | } |
@@ -3,78 +3,78 @@ |
||
3 | 3 | class Request |
4 | 4 | { |
5 | 5 | |
6 | - private static $server = array(); |
|
7 | - private static $get = array(); |
|
8 | - private static $post = array(); |
|
6 | + private static $server = array(); |
|
7 | + private static $get = array(); |
|
8 | + private static $post = array(); |
|
9 | 9 | |
10 | - private static $AJAX_REQUEST = 'HTTP_X_REQUESTED_WITH'; |
|
10 | + private static $AJAX_REQUEST = 'HTTP_X_REQUESTED_WITH'; |
|
11 | 11 | |
12 | - static function init() |
|
13 | - { |
|
14 | - self::make_server(); |
|
15 | - self::make_get(); |
|
16 | - self::make_post(); |
|
17 | - } |
|
12 | + static function init() |
|
13 | + { |
|
14 | + self::make_server(); |
|
15 | + self::make_get(); |
|
16 | + self::make_post(); |
|
17 | + } |
|
18 | 18 | |
19 | - static function getServer($key = null) |
|
20 | - { |
|
21 | - if($key) |
|
22 | - { |
|
23 | - if(isset(self::$server[$key])) |
|
24 | - return self::$server[$key]; |
|
25 | - return false; |
|
26 | - } |
|
27 | - return self::$server; |
|
28 | - } |
|
19 | + static function getServer($key = null) |
|
20 | + { |
|
21 | + if($key) |
|
22 | + { |
|
23 | + if(isset(self::$server[$key])) |
|
24 | + return self::$server[$key]; |
|
25 | + return false; |
|
26 | + } |
|
27 | + return self::$server; |
|
28 | + } |
|
29 | 29 | |
30 | - static function isAjax() |
|
31 | - { |
|
32 | - if(self::getServer(self::$AJAX_REQUEST)) |
|
33 | - return true; |
|
34 | - return false; |
|
35 | - } |
|
30 | + static function isAjax() |
|
31 | + { |
|
32 | + if(self::getServer(self::$AJAX_REQUEST)) |
|
33 | + return true; |
|
34 | + return false; |
|
35 | + } |
|
36 | 36 | |
37 | - static function getGet($key = null) |
|
38 | - { |
|
39 | - if($key) |
|
40 | - { |
|
41 | - if(isset(self::$get[$key])) |
|
42 | - return self::$get[$key]; |
|
43 | - return false; |
|
44 | - } |
|
45 | - return self::$get; |
|
46 | - } |
|
37 | + static function getGet($key = null) |
|
38 | + { |
|
39 | + if($key) |
|
40 | + { |
|
41 | + if(isset(self::$get[$key])) |
|
42 | + return self::$get[$key]; |
|
43 | + return false; |
|
44 | + } |
|
45 | + return self::$get; |
|
46 | + } |
|
47 | 47 | |
48 | - static function getPost($key = null) |
|
49 | - { |
|
50 | - if($key) |
|
51 | - { |
|
52 | - if(isset(self::$post[$key])) |
|
53 | - return self::$post[$key]; |
|
54 | - return false; |
|
55 | - } |
|
56 | - return self::$post; |
|
57 | - } |
|
48 | + static function getPost($key = null) |
|
49 | + { |
|
50 | + if($key) |
|
51 | + { |
|
52 | + if(isset(self::$post[$key])) |
|
53 | + return self::$post[$key]; |
|
54 | + return false; |
|
55 | + } |
|
56 | + return self::$post; |
|
57 | + } |
|
58 | 58 | |
59 | - public static function hasPost() |
|
60 | - { |
|
61 | - return is_array(self::$post) && !empty(self::$post); |
|
62 | - } |
|
59 | + public static function hasPost() |
|
60 | + { |
|
61 | + return is_array(self::$post) && !empty(self::$post); |
|
62 | + } |
|
63 | 63 | |
64 | - static function make_server() |
|
65 | - { |
|
66 | - self::$server = $_SERVER; |
|
67 | - } |
|
64 | + static function make_server() |
|
65 | + { |
|
66 | + self::$server = $_SERVER; |
|
67 | + } |
|
68 | 68 | |
69 | - static function make_get() |
|
70 | - { |
|
71 | - self::$get = $_GET; |
|
72 | - } |
|
69 | + static function make_get() |
|
70 | + { |
|
71 | + self::$get = $_GET; |
|
72 | + } |
|
73 | 73 | |
74 | - static function make_post() |
|
75 | - { |
|
76 | - self::$post = $_POST; |
|
77 | - } |
|
74 | + static function make_post() |
|
75 | + { |
|
76 | + self::$post = $_POST; |
|
77 | + } |
|
78 | 78 | |
79 | 79 | } |
80 | 80 |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -class Request |
|
4 | -{ |
|
3 | +class Request |
|
4 | +{ |
|
5 | 5 | |
6 | 6 | private static $server = array(); |
7 | 7 | private static $get = array(); |
@@ -9,70 +9,74 @@ discard block |
||
9 | 9 | |
10 | 10 | private static $AJAX_REQUEST = 'HTTP_X_REQUESTED_WITH'; |
11 | 11 | |
12 | - static function init() |
|
13 | - { |
|
12 | + static function init() |
|
13 | + { |
|
14 | 14 | self::make_server(); |
15 | 15 | self::make_get(); |
16 | 16 | self::make_post(); |
17 | 17 | } |
18 | 18 | |
19 | - static function getServer($key = null) |
|
20 | - { |
|
19 | + static function getServer($key = null) |
|
20 | + { |
|
21 | 21 | if($key) |
22 | 22 | { |
23 | - if(isset(self::$server[$key])) |
|
24 | - return self::$server[$key]; |
|
23 | + if(isset(self::$server[$key])) { |
|
24 | + return self::$server[$key]; |
|
25 | + } |
|
25 | 26 | return false; |
26 | 27 | } |
27 | 28 | return self::$server; |
28 | 29 | } |
29 | 30 | |
30 | - static function isAjax() |
|
31 | - { |
|
32 | - if(self::getServer(self::$AJAX_REQUEST)) |
|
33 | - return true; |
|
31 | + static function isAjax() |
|
32 | + { |
|
33 | + if(self::getServer(self::$AJAX_REQUEST)) { |
|
34 | + return true; |
|
35 | + } |
|
34 | 36 | return false; |
35 | 37 | } |
36 | 38 | |
37 | - static function getGet($key = null) |
|
38 | - { |
|
39 | + static function getGet($key = null) |
|
40 | + { |
|
39 | 41 | if($key) |
40 | 42 | { |
41 | - if(isset(self::$get[$key])) |
|
42 | - return self::$get[$key]; |
|
43 | + if(isset(self::$get[$key])) { |
|
44 | + return self::$get[$key]; |
|
45 | + } |
|
43 | 46 | return false; |
44 | 47 | } |
45 | 48 | return self::$get; |
46 | 49 | } |
47 | 50 | |
48 | - static function getPost($key = null) |
|
49 | - { |
|
51 | + static function getPost($key = null) |
|
52 | + { |
|
50 | 53 | if($key) |
51 | 54 | { |
52 | - if(isset(self::$post[$key])) |
|
53 | - return self::$post[$key]; |
|
55 | + if(isset(self::$post[$key])) { |
|
56 | + return self::$post[$key]; |
|
57 | + } |
|
54 | 58 | return false; |
55 | 59 | } |
56 | 60 | return self::$post; |
57 | 61 | } |
58 | 62 | |
59 | - public static function hasPost() |
|
60 | - { |
|
63 | + public static function hasPost() |
|
64 | + { |
|
61 | 65 | return is_array(self::$post) && !empty(self::$post); |
62 | 66 | } |
63 | 67 | |
64 | - static function make_server() |
|
65 | - { |
|
68 | + static function make_server() |
|
69 | + { |
|
66 | 70 | self::$server = $_SERVER; |
67 | 71 | } |
68 | 72 | |
69 | - static function make_get() |
|
70 | - { |
|
73 | + static function make_get() |
|
74 | + { |
|
71 | 75 | self::$get = $_GET; |
72 | 76 | } |
73 | 77 | |
74 | - static function make_post() |
|
75 | - { |
|
78 | + static function make_post() |
|
79 | + { |
|
76 | 80 | self::$post = $_POST; |
77 | 81 | } |
78 | 82 |
@@ -38,6 +38,9 @@ discard block |
||
38 | 38 | self::$array['pieces'] = (array) $uri_array; |
39 | 39 | } |
40 | 40 | |
41 | + /** |
|
42 | + * @return string |
|
43 | + */ |
|
41 | 44 | static function getSite() |
42 | 45 | { |
43 | 46 | return self::$array['site']; |
@@ -66,6 +69,9 @@ discard block |
||
66 | 69 | return substr($file, strrpos($file, '.') + 1);; |
67 | 70 | } |
68 | 71 | |
72 | + /** |
|
73 | + * @param integer $piece |
|
74 | + */ |
|
69 | 75 | static function getPiece($piece = null) |
70 | 76 | { |
71 | 77 | if(!$piece) |
@@ -15,11 +15,11 @@ discard block |
||
15 | 15 | static private function form_url_array($host, $uri) |
16 | 16 | { |
17 | 17 | $uri = substr($uri, 1); |
18 | - if(strpos($uri, '?')) |
|
18 | + if (strpos($uri, '?')) |
|
19 | 19 | $uri = substr($uri, 0, strpos($uri, '?')); |
20 | 20 | $uri_array = explode('/', $uri); |
21 | 21 | |
22 | - if(!Loader::isLive()) |
|
22 | + if (!Loader::isLive()) |
|
23 | 23 | $host = substr($host, strpos($host, '.') + 1); |
24 | 24 | |
25 | 25 | self::$array['host'] = $host; |
@@ -41,9 +41,9 @@ discard block |
||
41 | 41 | $base .= '/'; |
42 | 42 | |
43 | 43 | self::$array['base'] = $base; |
44 | - self::$array['uri'] = '/' . implode('/', $uri_array); |
|
44 | + self::$array['uri'] = '/'.implode('/', $uri_array); |
|
45 | 45 | |
46 | - if(end($uri_array) == '') |
|
46 | + if (end($uri_array) == '') |
|
47 | 47 | $uri_array = array_slice($uri_array, 0, count($uri_array) - 1); |
48 | 48 | self::$array['pieces'] = (array) $uri_array; |
49 | 49 | } |
@@ -71,21 +71,21 @@ discard block |
||
71 | 71 | static function getExtension() |
72 | 72 | { |
73 | 73 | $file = self::getPiece(-1); |
74 | - if(substr($file, -1) == '/') |
|
74 | + if (substr($file, -1) == '/') |
|
75 | 75 | return false; |
76 | - return substr($file, strrpos($file, '.') + 1);; |
|
76 | + return substr($file, strrpos($file, '.') + 1); ; |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | static function getPiece($piece = null) |
80 | 80 | { |
81 | - if(!$piece) |
|
81 | + if (!$piece) |
|
82 | 82 | return self::$array['pieces']; |
83 | 83 | |
84 | - if($piece == -1) |
|
84 | + if ($piece == -1) |
|
85 | 85 | return end(self::$array['pieces']); |
86 | 86 | |
87 | 87 | $piece = $piece - 1; |
88 | - if(array_key_exists($piece, self::$array['pieces'])) |
|
88 | + if (array_key_exists($piece, self::$array['pieces'])) |
|
89 | 89 | return self::$array['pieces'][$piece]; |
90 | 90 | return; |
91 | 91 | } |
@@ -3,35 +3,35 @@ discard block |
||
3 | 3 | class URLDecode |
4 | 4 | { |
5 | 5 | |
6 | - private static $array = array(); |
|
6 | + private static $array = array(); |
|
7 | 7 | |
8 | - static function init() |
|
9 | - { |
|
10 | - $host = $_SERVER['HTTP_HOST']; |
|
11 | - $uri = $_SERVER['REQUEST_URI']; |
|
12 | - self::form_url_array($host, $uri); |
|
13 | - } |
|
8 | + static function init() |
|
9 | + { |
|
10 | + $host = $_SERVER['HTTP_HOST']; |
|
11 | + $uri = $_SERVER['REQUEST_URI']; |
|
12 | + self::form_url_array($host, $uri); |
|
13 | + } |
|
14 | 14 | |
15 | - static private function form_url_array($host, $uri) |
|
16 | - { |
|
17 | - $uri = substr($uri, 1); |
|
18 | - if(strpos($uri, '?')) |
|
19 | - $uri = substr($uri, 0, strpos($uri, '?')); |
|
20 | - $uri_array = explode('/', $uri); |
|
15 | + static private function form_url_array($host, $uri) |
|
16 | + { |
|
17 | + $uri = substr($uri, 1); |
|
18 | + if(strpos($uri, '?')) |
|
19 | + $uri = substr($uri, 0, strpos($uri, '?')); |
|
20 | + $uri_array = explode('/', $uri); |
|
21 | 21 | |
22 | - if(!Loader::isLive()) |
|
23 | - $host = substr($host, strpos($host, '.') + 1); |
|
22 | + if(!Loader::isLive()) |
|
23 | + $host = substr($host, strpos($host, '.') + 1); |
|
24 | 24 | |
25 | - self::$array['host'] = $host; |
|
25 | + self::$array['host'] = $host; |
|
26 | 26 | |
27 | 27 | if ( |
28 | - $host == 'www.waterfallsofthekeweenaw.com' || |
|
28 | + $host == 'www.waterfallsofthekeweenaw.com' || |
|
29 | 29 | $host == 'waterfallsofthekeweenaw.com' |
30 | 30 | ) { |
31 | - self::$array['site'] = 'waterfalls'; |
|
32 | - } else { |
|
33 | - self::$array['site'] = substr($host, 0, strpos($host, '.')); |
|
34 | - } |
|
31 | + self::$array['site'] = 'waterfalls'; |
|
32 | + } else { |
|
33 | + self::$array['site'] = substr($host, 0, strpos($host, '.')); |
|
34 | + } |
|
35 | 35 | |
36 | 36 | $base = ''; |
37 | 37 | $base .= (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http'; |
@@ -40,55 +40,55 @@ discard block |
||
40 | 40 | $base .= $host; |
41 | 41 | $base .= '/'; |
42 | 42 | |
43 | - self::$array['base'] = $base; |
|
44 | - self::$array['uri'] = '/' . implode('/', $uri_array); |
|
43 | + self::$array['base'] = $base; |
|
44 | + self::$array['uri'] = '/' . implode('/', $uri_array); |
|
45 | 45 | |
46 | - if(end($uri_array) == '') |
|
47 | - $uri_array = array_slice($uri_array, 0, count($uri_array) - 1); |
|
48 | - self::$array['pieces'] = (array) $uri_array; |
|
49 | - } |
|
46 | + if(end($uri_array) == '') |
|
47 | + $uri_array = array_slice($uri_array, 0, count($uri_array) - 1); |
|
48 | + self::$array['pieces'] = (array) $uri_array; |
|
49 | + } |
|
50 | 50 | |
51 | - static function getSite() |
|
52 | - { |
|
53 | - return self::$array['site']; |
|
54 | - } |
|
51 | + static function getSite() |
|
52 | + { |
|
53 | + return self::$array['site']; |
|
54 | + } |
|
55 | 55 | |
56 | - static function getHost() |
|
57 | - { |
|
58 | - return self::$array['host']; |
|
59 | - } |
|
56 | + static function getHost() |
|
57 | + { |
|
58 | + return self::$array['host']; |
|
59 | + } |
|
60 | 60 | |
61 | - static function getBase() |
|
62 | - { |
|
63 | - return self::$array['base']; |
|
64 | - } |
|
61 | + static function getBase() |
|
62 | + { |
|
63 | + return self::$array['base']; |
|
64 | + } |
|
65 | 65 | |
66 | - static function getURI() |
|
67 | - { |
|
68 | - return self::$array['uri']; |
|
69 | - } |
|
66 | + static function getURI() |
|
67 | + { |
|
68 | + return self::$array['uri']; |
|
69 | + } |
|
70 | 70 | |
71 | - static function getExtension() |
|
72 | - { |
|
73 | - $file = self::getPiece(-1); |
|
74 | - if(substr($file, -1) == '/') |
|
75 | - return false; |
|
76 | - return substr($file, strrpos($file, '.') + 1);; |
|
77 | - } |
|
71 | + static function getExtension() |
|
72 | + { |
|
73 | + $file = self::getPiece(-1); |
|
74 | + if(substr($file, -1) == '/') |
|
75 | + return false; |
|
76 | + return substr($file, strrpos($file, '.') + 1);; |
|
77 | + } |
|
78 | 78 | |
79 | - static function getPiece($piece = null) |
|
80 | - { |
|
81 | - if(!$piece) |
|
82 | - return self::$array['pieces']; |
|
79 | + static function getPiece($piece = null) |
|
80 | + { |
|
81 | + if(!$piece) |
|
82 | + return self::$array['pieces']; |
|
83 | 83 | |
84 | - if($piece == -1) |
|
85 | - return end(self::$array['pieces']); |
|
84 | + if($piece == -1) |
|
85 | + return end(self::$array['pieces']); |
|
86 | 86 | |
87 | - $piece = $piece - 1; |
|
88 | - if(array_key_exists($piece, self::$array['pieces'])) |
|
89 | - return self::$array['pieces'][$piece]; |
|
90 | - return; |
|
91 | - } |
|
87 | + $piece = $piece - 1; |
|
88 | + if(array_key_exists($piece, self::$array['pieces'])) |
|
89 | + return self::$array['pieces'][$piece]; |
|
90 | + return; |
|
91 | + } |
|
92 | 92 | |
93 | 93 | } |
94 | 94 |
@@ -1,26 +1,28 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -class URLDecode |
|
4 | -{ |
|
3 | +class URLDecode |
|
4 | +{ |
|
5 | 5 | |
6 | 6 | private static $array = array(); |
7 | 7 | |
8 | - static function init() |
|
9 | - { |
|
8 | + static function init() |
|
9 | + { |
|
10 | 10 | $host = $_SERVER['HTTP_HOST']; |
11 | 11 | $uri = $_SERVER['REQUEST_URI']; |
12 | 12 | self::form_url_array($host, $uri); |
13 | 13 | } |
14 | 14 | |
15 | - static private function form_url_array($host, $uri) |
|
16 | - { |
|
15 | + static private function form_url_array($host, $uri) |
|
16 | + { |
|
17 | 17 | $uri = substr($uri, 1); |
18 | - if(strpos($uri, '?')) |
|
19 | - $uri = substr($uri, 0, strpos($uri, '?')); |
|
18 | + if(strpos($uri, '?')) { |
|
19 | + $uri = substr($uri, 0, strpos($uri, '?')); |
|
20 | + } |
|
20 | 21 | $uri_array = explode('/', $uri); |
21 | 22 | |
22 | - if(!Loader::isLive()) |
|
23 | - $host = substr($host, strpos($host, '.') + 1); |
|
23 | + if(!Loader::isLive()) { |
|
24 | + $host = substr($host, strpos($host, '.') + 1); |
|
25 | + } |
|
24 | 26 | |
25 | 27 | self::$array['host'] = $host; |
26 | 28 | |
@@ -43,50 +45,55 @@ discard block |
||
43 | 45 | self::$array['base'] = $base; |
44 | 46 | self::$array['uri'] = '/' . implode('/', $uri_array); |
45 | 47 | |
46 | - if(end($uri_array) == '') |
|
47 | - $uri_array = array_slice($uri_array, 0, count($uri_array) - 1); |
|
48 | + if(end($uri_array) == '') { |
|
49 | + $uri_array = array_slice($uri_array, 0, count($uri_array) - 1); |
|
50 | + } |
|
48 | 51 | self::$array['pieces'] = (array) $uri_array; |
49 | 52 | } |
50 | 53 | |
51 | - static function getSite() |
|
52 | - { |
|
54 | + static function getSite() |
|
55 | + { |
|
53 | 56 | return self::$array['site']; |
54 | 57 | } |
55 | 58 | |
56 | - static function getHost() |
|
57 | - { |
|
59 | + static function getHost() |
|
60 | + { |
|
58 | 61 | return self::$array['host']; |
59 | 62 | } |
60 | 63 | |
61 | - static function getBase() |
|
62 | - { |
|
64 | + static function getBase() |
|
65 | + { |
|
63 | 66 | return self::$array['base']; |
64 | 67 | } |
65 | 68 | |
66 | - static function getURI() |
|
67 | - { |
|
69 | + static function getURI() |
|
70 | + { |
|
68 | 71 | return self::$array['uri']; |
69 | 72 | } |
70 | 73 | |
71 | - static function getExtension() |
|
72 | - { |
|
74 | + static function getExtension() |
|
75 | + { |
|
73 | 76 | $file = self::getPiece(-1); |
74 | - if(substr($file, -1) == '/') |
|
75 | - return false; |
|
77 | + if(substr($file, -1) == '/') { |
|
78 | + return false; |
|
79 | + } |
|
76 | 80 | return substr($file, strrpos($file, '.') + 1);; |
77 | 81 | } |
78 | 82 | |
79 | - static function getPiece($piece = null) |
|
80 | - { |
|
81 | - if(!$piece) |
|
82 | - return self::$array['pieces']; |
|
83 | + static function getPiece($piece = null) |
|
84 | + { |
|
85 | + if(!$piece) { |
|
86 | + return self::$array['pieces']; |
|
87 | + } |
|
83 | 88 | |
84 | - if($piece == -1) |
|
85 | - return end(self::$array['pieces']); |
|
89 | + if($piece == -1) { |
|
90 | + return end(self::$array['pieces']); |
|
91 | + } |
|
86 | 92 | |
87 | 93 | $piece = $piece - 1; |
88 | - if(array_key_exists($piece, self::$array['pieces'])) |
|
89 | - return self::$array['pieces'][$piece]; |
|
94 | + if(array_key_exists($piece, self::$array['pieces'])) { |
|
95 | + return self::$array['pieces'][$piece]; |
|
96 | + } |
|
90 | 97 | return; |
91 | 98 | } |
92 | 99 |
@@ -72,6 +72,11 @@ |
||
72 | 72 | return $matches[0] == $string; |
73 | 73 | } |
74 | 74 | |
75 | + /** |
|
76 | + * @param string $type |
|
77 | + * @param string $key |
|
78 | + * @param string $validation |
|
79 | + */ |
|
75 | 80 | public static function checkRequest($type, $key, $validation, $strict = false) |
76 | 81 | { |
77 | 82 | switch($type) |
@@ -11,39 +11,39 @@ discard block |
||
11 | 11 | |
12 | 12 | public static function isBoolean($value, $strict = false) |
13 | 13 | { |
14 | - if($strict && ($value === true || $value === false)) |
|
14 | + if ($strict && ($value === true || $value === false)) |
|
15 | 15 | return true; |
16 | - if(!$strict && ((bool) $value === true || (bool) $value === false)) |
|
16 | + if (!$strict && ((bool) $value === true || (bool) $value === false)) |
|
17 | 17 | return true; |
18 | 18 | return false; |
19 | 19 | } |
20 | 20 | |
21 | 21 | public static function isDate($value) |
22 | 22 | { |
23 | - if(strtotime($value) !== -1) |
|
23 | + if (strtotime($value) !== -1) |
|
24 | 24 | return true; |
25 | - if(date('y', $value) !== false) |
|
25 | + if (date('y', $value) !== false) |
|
26 | 26 | return true; |
27 | 27 | return false; |
28 | 28 | } |
29 | 29 | |
30 | 30 | public static function isInteger($value, $strict = false) |
31 | 31 | { |
32 | - if($strict) |
|
32 | + if ($strict) |
|
33 | 33 | return is_int($value); |
34 | 34 | return (int) $value == $value; |
35 | 35 | } |
36 | 36 | |
37 | 37 | public static function isIP($value) |
38 | 38 | { |
39 | - if(self::isInteger(ip2long($value))) |
|
39 | + if (self::isInteger(ip2long($value))) |
|
40 | 40 | return true; |
41 | 41 | return false; |
42 | 42 | } |
43 | 43 | |
44 | 44 | public static function isString($value, $strict = false) |
45 | 45 | { |
46 | - if($strict) |
|
46 | + if ($strict) |
|
47 | 47 | return is_string($value); |
48 | 48 | return (string) $value == $value; |
49 | 49 | } |
@@ -67,14 +67,14 @@ discard block |
||
67 | 67 | private static function check_value($pattern, $string) |
68 | 68 | { |
69 | 69 | preg_match($pattern, $string, $matches); |
70 | - if(empty($matches)) |
|
70 | + if (empty($matches)) |
|
71 | 71 | return false; |
72 | 72 | return $matches[0] == $string; |
73 | 73 | } |
74 | 74 | |
75 | 75 | public static function checkRequest($type, $key, $validation, $strict = false) |
76 | 76 | { |
77 | - switch($type) |
|
77 | + switch ($type) |
|
78 | 78 | { |
79 | 79 | case 'server': |
80 | 80 | $value = Request::getServer($key); |
@@ -84,10 +84,10 @@ discard block |
||
84 | 84 | break; |
85 | 85 | } |
86 | 86 | |
87 | - if($value == false) |
|
87 | + if ($value == false) |
|
88 | 88 | return false; |
89 | 89 | |
90 | - switch($validation) |
|
90 | + switch ($validation) |
|
91 | 91 | { |
92 | 92 | case 'boolean': |
93 | 93 | return self::isBoolean($value, $strict); |
@@ -5,110 +5,110 @@ |
||
5 | 5 | class Validate |
6 | 6 | { |
7 | 7 | |
8 | - private static $NAME_REGEX = '@[a-z\s\'-]+@i'; |
|
9 | - private static $EMAIL_REGEX = '@(?:[a-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")\@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])@i'; |
|
10 | - private static $URL_REGEX = '@((https?|ftp)\:\/\/)?([a-z0-9-.]*)\.([a-z]{2,3})(\/([a-z0-9+\$_-]\.?)+)*\/?(\?[a-z+&\$_.-][a-z0-9;:\@&%=+\/\$_.-]*)?(#[a-z_.-][a-z0-9+\$_.-]*)?@i'; |
|
8 | + private static $NAME_REGEX = '@[a-z\s\'-]+@i'; |
|
9 | + private static $EMAIL_REGEX = '@(?:[a-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")\@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])@i'; |
|
10 | + private static $URL_REGEX = '@((https?|ftp)\:\/\/)?([a-z0-9-.]*)\.([a-z]{2,3})(\/([a-z0-9+\$_-]\.?)+)*\/?(\?[a-z+&\$_.-][a-z0-9;:\@&%=+\/\$_.-]*)?(#[a-z_.-][a-z0-9+\$_.-]*)?@i'; |
|
11 | 11 | |
12 | - public static function isBoolean($value, $strict = false) |
|
13 | - { |
|
14 | - if($strict && ($value === true || $value === false)) |
|
15 | - return true; |
|
16 | - if(!$strict && ((bool) $value === true || (bool) $value === false)) |
|
17 | - return true; |
|
18 | - return false; |
|
19 | - } |
|
12 | + public static function isBoolean($value, $strict = false) |
|
13 | + { |
|
14 | + if($strict && ($value === true || $value === false)) |
|
15 | + return true; |
|
16 | + if(!$strict && ((bool) $value === true || (bool) $value === false)) |
|
17 | + return true; |
|
18 | + return false; |
|
19 | + } |
|
20 | 20 | |
21 | - public static function isDate($value) |
|
22 | - { |
|
23 | - if(strtotime($value) !== -1) |
|
24 | - return true; |
|
25 | - if(date('y', $value) !== false) |
|
26 | - return true; |
|
27 | - return false; |
|
28 | - } |
|
21 | + public static function isDate($value) |
|
22 | + { |
|
23 | + if(strtotime($value) !== -1) |
|
24 | + return true; |
|
25 | + if(date('y', $value) !== false) |
|
26 | + return true; |
|
27 | + return false; |
|
28 | + } |
|
29 | 29 | |
30 | - public static function isInteger($value, $strict = false) |
|
31 | - { |
|
32 | - if($strict) |
|
33 | - return is_int($value); |
|
34 | - return (int) $value == $value; |
|
35 | - } |
|
30 | + public static function isInteger($value, $strict = false) |
|
31 | + { |
|
32 | + if($strict) |
|
33 | + return is_int($value); |
|
34 | + return (int) $value == $value; |
|
35 | + } |
|
36 | 36 | |
37 | - public static function isIP($value) |
|
38 | - { |
|
39 | - if(self::isInteger(ip2long($value))) |
|
40 | - return true; |
|
41 | - return false; |
|
42 | - } |
|
37 | + public static function isIP($value) |
|
38 | + { |
|
39 | + if(self::isInteger(ip2long($value))) |
|
40 | + return true; |
|
41 | + return false; |
|
42 | + } |
|
43 | 43 | |
44 | - public static function isString($value, $strict = false) |
|
45 | - { |
|
46 | - if($strict) |
|
47 | - return is_string($value); |
|
48 | - return (string) $value == $value; |
|
49 | - } |
|
44 | + public static function isString($value, $strict = false) |
|
45 | + { |
|
46 | + if($strict) |
|
47 | + return is_string($value); |
|
48 | + return (string) $value == $value; |
|
49 | + } |
|
50 | 50 | |
51 | - public static function isURL($value) |
|
52 | - { |
|
53 | - return true; |
|
54 | - return self::check_value(self::$URL_REGEX, $value); |
|
55 | - } |
|
51 | + public static function isURL($value) |
|
52 | + { |
|
53 | + return true; |
|
54 | + return self::check_value(self::$URL_REGEX, $value); |
|
55 | + } |
|
56 | 56 | |
57 | - public static function isName($value) |
|
58 | - { |
|
59 | - return self::check_value(self::$NAME_REGEX, $value); |
|
60 | - } |
|
57 | + public static function isName($value) |
|
58 | + { |
|
59 | + return self::check_value(self::$NAME_REGEX, $value); |
|
60 | + } |
|
61 | 61 | |
62 | - public static function isEmail($value) |
|
63 | - { |
|
64 | - return self::check_value(self::$EMAIL_REGEX, $value); |
|
65 | - } |
|
62 | + public static function isEmail($value) |
|
63 | + { |
|
64 | + return self::check_value(self::$EMAIL_REGEX, $value); |
|
65 | + } |
|
66 | 66 | |
67 | - private static function check_value($pattern, $string) |
|
68 | - { |
|
69 | - preg_match($pattern, $string, $matches); |
|
70 | - if(empty($matches)) |
|
71 | - return false; |
|
72 | - return $matches[0] == $string; |
|
73 | - } |
|
67 | + private static function check_value($pattern, $string) |
|
68 | + { |
|
69 | + preg_match($pattern, $string, $matches); |
|
70 | + if(empty($matches)) |
|
71 | + return false; |
|
72 | + return $matches[0] == $string; |
|
73 | + } |
|
74 | 74 | |
75 | - public static function checkRequest($type, $key, $validation, $strict = false) |
|
76 | - { |
|
77 | - switch($type) |
|
78 | - { |
|
79 | - case 'server': |
|
80 | - $value = Request::getServer($key); |
|
81 | - break; |
|
82 | - case 'post': |
|
83 | - $value = Request::getPost($key); |
|
84 | - break; |
|
85 | - } |
|
75 | + public static function checkRequest($type, $key, $validation, $strict = false) |
|
76 | + { |
|
77 | + switch($type) |
|
78 | + { |
|
79 | + case 'server': |
|
80 | + $value = Request::getServer($key); |
|
81 | + break; |
|
82 | + case 'post': |
|
83 | + $value = Request::getPost($key); |
|
84 | + break; |
|
85 | + } |
|
86 | 86 | |
87 | - if($value == false) |
|
88 | - return false; |
|
87 | + if($value == false) |
|
88 | + return false; |
|
89 | 89 | |
90 | - switch($validation) |
|
91 | - { |
|
92 | - case 'boolean': |
|
93 | - return self::isBoolean($value, $strict); |
|
94 | - case 'date': |
|
95 | - return self::isDate($value); |
|
96 | - case 'integer': |
|
97 | - return self::isInteger($value, $strict); |
|
98 | - case 'ip': |
|
99 | - return self::isIP($value); |
|
100 | - case 'string': |
|
101 | - return self::isString($value, $strict); |
|
102 | - case 'url': |
|
103 | - return self::isURL($value, $strict); |
|
104 | - case 'name': |
|
105 | - return self::isName($value, $strict); |
|
106 | - case 'email': |
|
107 | - return self::isEmail($value, $strict); |
|
108 | - } |
|
90 | + switch($validation) |
|
91 | + { |
|
92 | + case 'boolean': |
|
93 | + return self::isBoolean($value, $strict); |
|
94 | + case 'date': |
|
95 | + return self::isDate($value); |
|
96 | + case 'integer': |
|
97 | + return self::isInteger($value, $strict); |
|
98 | + case 'ip': |
|
99 | + return self::isIP($value); |
|
100 | + case 'string': |
|
101 | + return self::isString($value, $strict); |
|
102 | + case 'url': |
|
103 | + return self::isURL($value, $strict); |
|
104 | + case 'name': |
|
105 | + return self::isName($value, $strict); |
|
106 | + case 'email': |
|
107 | + return self::isEmail($value, $strict); |
|
108 | + } |
|
109 | 109 | |
110 | - return false; |
|
111 | - } |
|
110 | + return false; |
|
111 | + } |
|
112 | 112 | |
113 | 113 | } |
114 | 114 |
@@ -2,78 +2,86 @@ discard block |
||
2 | 2 | |
3 | 3 | Loader::load('utility', 'Request'); |
4 | 4 | |
5 | -class Validate |
|
6 | -{ |
|
5 | +class Validate |
|
6 | +{ |
|
7 | 7 | |
8 | 8 | private static $NAME_REGEX = '@[a-z\s\'-]+@i'; |
9 | 9 | private static $EMAIL_REGEX = '@(?:[a-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")\@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])@i'; |
10 | 10 | private static $URL_REGEX = '@((https?|ftp)\:\/\/)?([a-z0-9-.]*)\.([a-z]{2,3})(\/([a-z0-9+\$_-]\.?)+)*\/?(\?[a-z+&\$_.-][a-z0-9;:\@&%=+\/\$_.-]*)?(#[a-z_.-][a-z0-9+\$_.-]*)?@i'; |
11 | 11 | |
12 | - public static function isBoolean($value, $strict = false) |
|
13 | - { |
|
14 | - if($strict && ($value === true || $value === false)) |
|
15 | - return true; |
|
16 | - if(!$strict && ((bool) $value === true || (bool) $value === false)) |
|
17 | - return true; |
|
12 | + public static function isBoolean($value, $strict = false) |
|
13 | + { |
|
14 | + if($strict && ($value === true || $value === false)) { |
|
15 | + return true; |
|
16 | + } |
|
17 | + if(!$strict && ((bool) $value === true || (bool) $value === false)) { |
|
18 | + return true; |
|
19 | + } |
|
18 | 20 | return false; |
19 | 21 | } |
20 | 22 | |
21 | - public static function isDate($value) |
|
22 | - { |
|
23 | - if(strtotime($value) !== -1) |
|
24 | - return true; |
|
25 | - if(date('y', $value) !== false) |
|
26 | - return true; |
|
23 | + public static function isDate($value) |
|
24 | + { |
|
25 | + if(strtotime($value) !== -1) { |
|
26 | + return true; |
|
27 | + } |
|
28 | + if(date('y', $value) !== false) { |
|
29 | + return true; |
|
30 | + } |
|
27 | 31 | return false; |
28 | 32 | } |
29 | 33 | |
30 | - public static function isInteger($value, $strict = false) |
|
31 | - { |
|
32 | - if($strict) |
|
33 | - return is_int($value); |
|
34 | + public static function isInteger($value, $strict = false) |
|
35 | + { |
|
36 | + if($strict) { |
|
37 | + return is_int($value); |
|
38 | + } |
|
34 | 39 | return (int) $value == $value; |
35 | 40 | } |
36 | 41 | |
37 | - public static function isIP($value) |
|
38 | - { |
|
39 | - if(self::isInteger(ip2long($value))) |
|
40 | - return true; |
|
42 | + public static function isIP($value) |
|
43 | + { |
|
44 | + if(self::isInteger(ip2long($value))) { |
|
45 | + return true; |
|
46 | + } |
|
41 | 47 | return false; |
42 | 48 | } |
43 | 49 | |
44 | - public static function isString($value, $strict = false) |
|
45 | - { |
|
46 | - if($strict) |
|
47 | - return is_string($value); |
|
50 | + public static function isString($value, $strict = false) |
|
51 | + { |
|
52 | + if($strict) { |
|
53 | + return is_string($value); |
|
54 | + } |
|
48 | 55 | return (string) $value == $value; |
49 | 56 | } |
50 | 57 | |
51 | - public static function isURL($value) |
|
52 | - { |
|
58 | + public static function isURL($value) |
|
59 | + { |
|
53 | 60 | return true; |
54 | 61 | return self::check_value(self::$URL_REGEX, $value); |
55 | 62 | } |
56 | 63 | |
57 | - public static function isName($value) |
|
58 | - { |
|
64 | + public static function isName($value) |
|
65 | + { |
|
59 | 66 | return self::check_value(self::$NAME_REGEX, $value); |
60 | 67 | } |
61 | 68 | |
62 | - public static function isEmail($value) |
|
63 | - { |
|
69 | + public static function isEmail($value) |
|
70 | + { |
|
64 | 71 | return self::check_value(self::$EMAIL_REGEX, $value); |
65 | 72 | } |
66 | 73 | |
67 | - private static function check_value($pattern, $string) |
|
68 | - { |
|
74 | + private static function check_value($pattern, $string) |
|
75 | + { |
|
69 | 76 | preg_match($pattern, $string, $matches); |
70 | - if(empty($matches)) |
|
71 | - return false; |
|
77 | + if(empty($matches)) { |
|
78 | + return false; |
|
79 | + } |
|
72 | 80 | return $matches[0] == $string; |
73 | 81 | } |
74 | 82 | |
75 | - public static function checkRequest($type, $key, $validation, $strict = false) |
|
76 | - { |
|
83 | + public static function checkRequest($type, $key, $validation, $strict = false) |
|
84 | + { |
|
77 | 85 | switch($type) |
78 | 86 | { |
79 | 87 | case 'server': |
@@ -84,8 +92,9 @@ discard block |
||
84 | 92 | break; |
85 | 93 | } |
86 | 94 | |
87 | - if($value == false) |
|
88 | - return false; |
|
95 | + if($value == false) { |
|
96 | + return false; |
|
97 | + } |
|
89 | 98 | |
90 | 99 | switch($validation) |
91 | 100 | { |
@@ -36,6 +36,10 @@ discard block |
||
36 | 36 | $this->replace_element_patterns(); |
37 | 37 | } |
38 | 38 | |
39 | + /** |
|
40 | + * @param string $pattern |
|
41 | + * @param string $replace |
|
42 | + */ |
|
39 | 43 | private function process_element($pattern, $replace) |
40 | 44 | { |
41 | 45 | $match_count = preg_match_all($pattern, $this->content, $matches, PREG_SET_ORDER); |
@@ -75,6 +79,10 @@ discard block |
||
75 | 79 | $this->content = strip_tags($this->content); |
76 | 80 | } |
77 | 81 | |
82 | + /** |
|
83 | + * @param string $pattern |
|
84 | + * @param string $replace |
|
85 | + */ |
|
78 | 86 | private function link_unlinked_urls($pattern, $replace) |
79 | 87 | { |
80 | 88 | $match_count = preg_match_all($pattern, $this->content, $matches, PREG_SET_ORDER); |
@@ -40,10 +40,10 @@ discard block |
||
40 | 40 | { |
41 | 41 | $match_count = preg_match_all($pattern, $this->content, $matches, PREG_SET_ORDER); |
42 | 42 | |
43 | - if($match_count < 1) |
|
43 | + if ($match_count < 1) |
|
44 | 44 | return; |
45 | 45 | |
46 | - foreach($matches as $match) |
|
46 | + foreach ($matches as $match) |
|
47 | 47 | { |
48 | 48 | $full_match = array_shift($match); |
49 | 49 | $placeholder = $this->create_placeholder($full_match); |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | |
57 | 57 | private function create_placeholder($text) |
58 | 58 | { |
59 | - return md5($text . rand()); |
|
59 | + return md5($text.rand()); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | private function create_full_match_pattern($text) |
@@ -79,10 +79,10 @@ discard block |
||
79 | 79 | { |
80 | 80 | $match_count = preg_match_all($pattern, $this->content, $matches, PREG_SET_ORDER); |
81 | 81 | |
82 | - if($match_count < 1) |
|
82 | + if ($match_count < 1) |
|
83 | 83 | return; |
84 | 84 | |
85 | - foreach($matches as $match) |
|
85 | + foreach ($matches as $match) |
|
86 | 86 | { |
87 | 87 | $full_match = array_shift($match); |
88 | 88 | $full_match_pattern = $this->create_full_match_pattern($full_match); |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | |
100 | 100 | private function replace_element_patterns() |
101 | 101 | { |
102 | - foreach($this->replacement_array as $key => $replace) |
|
102 | + foreach ($this->replacement_array as $key => $replace) |
|
103 | 103 | { |
104 | 104 | $this->content = str_replace($key, $replace, $this->content); |
105 | 105 | } |
@@ -5,104 +5,104 @@ |
||
5 | 5 | final class CleanCommentContent extends Content |
6 | 6 | { |
7 | 7 | |
8 | - private static $LINK_PATTERN = '@<a.*href=["\']([^"\']*)["\'].*>(.*)</a>@i'; |
|
9 | - private static $BOLD_PATTERN = '@<b.*>(.*)</b>@i'; |
|
10 | - private static $ITALIC_PATTERN = '@<i.*>(.*)</i>@i'; |
|
11 | - private static $CODE_PATTERN = '@<pre[^>]*>(.*)</pre>@is'; |
|
8 | + private static $LINK_PATTERN = '@<a.*href=["\']([^"\']*)["\'].*>(.*)</a>@i'; |
|
9 | + private static $BOLD_PATTERN = '@<b.*>(.*)</b>@i'; |
|
10 | + private static $ITALIC_PATTERN = '@<i.*>(.*)</i>@i'; |
|
11 | + private static $CODE_PATTERN = '@<pre[^>]*>(.*)</pre>@is'; |
|
12 | 12 | |
13 | - private static $LINK_REPLACE = '<a href="%s" rel="nofollow" target="_blank">%s</a>'; |
|
14 | - private static $BOLD_REPLACE = '<b>%s</b>'; |
|
15 | - private static $ITALIC_REPLACE = '<i>%s</i>'; |
|
16 | - private static $CODE_REPLACE = '<pre>%s</pre>'; |
|
13 | + private static $LINK_REPLACE = '<a href="%s" rel="nofollow" target="_blank">%s</a>'; |
|
14 | + private static $BOLD_REPLACE = '<b>%s</b>'; |
|
15 | + private static $ITALIC_REPLACE = '<i>%s</i>'; |
|
16 | + private static $CODE_REPLACE = '<pre>%s</pre>'; |
|
17 | 17 | |
18 | - private static $URL_PATTERN = '@(https?://[a-z0-9\.-]+\.[a-z]{2,6}[^\s]*[^\.,\?\!;\s]+)@i'; |
|
19 | - private static $LINE_BREAK_PATTERN = '@([\r\n]+)@'; |
|
18 | + private static $URL_PATTERN = '@(https?://[a-z0-9\.-]+\.[a-z]{2,6}[^\s]*[^\.,\?\!;\s]+)@i'; |
|
19 | + private static $LINE_BREAK_PATTERN = '@([\r\n]+)@'; |
|
20 | 20 | |
21 | - private static $LINE_BREAK_REPLACE = '<br />'; |
|
21 | + private static $LINE_BREAK_REPLACE = '<br />'; |
|
22 | 22 | |
23 | - private $replacement_array = array(); |
|
23 | + private $replacement_array = array(); |
|
24 | 24 | |
25 | - protected function execute() |
|
26 | - { |
|
27 | - $this->process_element(self::$CODE_PATTERN, self::$CODE_REPLACE); |
|
28 | - $this->process_element(self::$LINK_PATTERN, self::$LINK_REPLACE); |
|
29 | - $this->process_element(self::$ITALIC_PATTERN, self::$ITALIC_REPLACE); |
|
30 | - $this->process_element(self::$BOLD_PATTERN, self::$BOLD_REPLACE); |
|
25 | + protected function execute() |
|
26 | + { |
|
27 | + $this->process_element(self::$CODE_PATTERN, self::$CODE_REPLACE); |
|
28 | + $this->process_element(self::$LINK_PATTERN, self::$LINK_REPLACE); |
|
29 | + $this->process_element(self::$ITALIC_PATTERN, self::$ITALIC_REPLACE); |
|
30 | + $this->process_element(self::$BOLD_PATTERN, self::$BOLD_REPLACE); |
|
31 | 31 | |
32 | - $this->strip_extra_tags(); |
|
32 | + $this->strip_extra_tags(); |
|
33 | 33 | |
34 | - $this->link_unlinked_urls(self::$URL_PATTERN, self::$LINK_REPLACE); |
|
35 | - $this->add_line_breaks(); |
|
36 | - $this->replace_element_patterns(); |
|
37 | - } |
|
38 | - |
|
39 | - private function process_element($pattern, $replace) |
|
40 | - { |
|
41 | - $match_count = preg_match_all($pattern, $this->content, $matches, PREG_SET_ORDER); |
|
34 | + $this->link_unlinked_urls(self::$URL_PATTERN, self::$LINK_REPLACE); |
|
35 | + $this->add_line_breaks(); |
|
36 | + $this->replace_element_patterns(); |
|
37 | + } |
|
38 | + |
|
39 | + private function process_element($pattern, $replace) |
|
40 | + { |
|
41 | + $match_count = preg_match_all($pattern, $this->content, $matches, PREG_SET_ORDER); |
|
42 | 42 | |
43 | - if($match_count < 1) |
|
44 | - return; |
|
43 | + if($match_count < 1) |
|
44 | + return; |
|
45 | 45 | |
46 | - foreach($matches as $match) |
|
47 | - { |
|
48 | - $full_match = array_shift($match); |
|
49 | - $placeholder = $this->create_placeholder($full_match); |
|
50 | - $full_match_pattern = $this->create_full_match_pattern($full_match); |
|
46 | + foreach($matches as $match) |
|
47 | + { |
|
48 | + $full_match = array_shift($match); |
|
49 | + $placeholder = $this->create_placeholder($full_match); |
|
50 | + $full_match_pattern = $this->create_full_match_pattern($full_match); |
|
51 | 51 | |
52 | - $this->content = preg_replace($full_match_pattern, $placeholder, $this->content, 1); |
|
53 | - $this->replacement_array[$placeholder] = vsprintf($replace, $match); |
|
54 | - } |
|
55 | - } |
|
56 | - |
|
57 | - private function create_placeholder($text) |
|
58 | - { |
|
59 | - return md5($text . rand()); |
|
60 | - } |
|
61 | - |
|
62 | - private function create_full_match_pattern($text) |
|
63 | - { |
|
64 | - $pattern = ''; |
|
65 | - $pattern .= '@'; |
|
66 | - $pattern .= preg_quote($text, '@'); |
|
67 | - $pattern .= '@'; |
|
68 | - $pattern .= 'i'; |
|
52 | + $this->content = preg_replace($full_match_pattern, $placeholder, $this->content, 1); |
|
53 | + $this->replacement_array[$placeholder] = vsprintf($replace, $match); |
|
54 | + } |
|
55 | + } |
|
56 | + |
|
57 | + private function create_placeholder($text) |
|
58 | + { |
|
59 | + return md5($text . rand()); |
|
60 | + } |
|
61 | + |
|
62 | + private function create_full_match_pattern($text) |
|
63 | + { |
|
64 | + $pattern = ''; |
|
65 | + $pattern .= '@'; |
|
66 | + $pattern .= preg_quote($text, '@'); |
|
67 | + $pattern .= '@'; |
|
68 | + $pattern .= 'i'; |
|
69 | 69 | |
70 | - return $pattern; |
|
71 | - } |
|
70 | + return $pattern; |
|
71 | + } |
|
72 | 72 | |
73 | - private function strip_extra_tags() |
|
74 | - { |
|
75 | - $this->content = strip_tags($this->content); |
|
76 | - } |
|
73 | + private function strip_extra_tags() |
|
74 | + { |
|
75 | + $this->content = strip_tags($this->content); |
|
76 | + } |
|
77 | 77 | |
78 | - private function link_unlinked_urls($pattern, $replace) |
|
79 | - { |
|
80 | - $match_count = preg_match_all($pattern, $this->content, $matches, PREG_SET_ORDER); |
|
78 | + private function link_unlinked_urls($pattern, $replace) |
|
79 | + { |
|
80 | + $match_count = preg_match_all($pattern, $this->content, $matches, PREG_SET_ORDER); |
|
81 | 81 | |
82 | - if($match_count < 1) |
|
83 | - return; |
|
82 | + if($match_count < 1) |
|
83 | + return; |
|
84 | 84 | |
85 | - foreach($matches as $match) |
|
86 | - { |
|
87 | - $full_match = array_shift($match); |
|
88 | - $full_match_pattern = $this->create_full_match_pattern($full_match); |
|
89 | - $replace = sprintf($replace, $match[0], $match[0]); |
|
85 | + foreach($matches as $match) |
|
86 | + { |
|
87 | + $full_match = array_shift($match); |
|
88 | + $full_match_pattern = $this->create_full_match_pattern($full_match); |
|
89 | + $replace = sprintf($replace, $match[0], $match[0]); |
|
90 | 90 | |
91 | - $this->content = preg_replace($full_match_pattern, $replace, $this->content, 1); |
|
92 | - } |
|
93 | - } |
|
94 | - |
|
95 | - private function add_line_breaks() |
|
96 | - { |
|
97 | - $this->content = preg_replace(self::$LINE_BREAK_PATTERN, self::$LINE_BREAK_REPLACE, $this->content); |
|
98 | - } |
|
99 | - |
|
100 | - private function replace_element_patterns() |
|
101 | - { |
|
102 | - foreach($this->replacement_array as $key => $replace) |
|
103 | - { |
|
104 | - $this->content = str_replace($key, $replace, $this->content); |
|
105 | - } |
|
106 | - } |
|
91 | + $this->content = preg_replace($full_match_pattern, $replace, $this->content, 1); |
|
92 | + } |
|
93 | + } |
|
94 | + |
|
95 | + private function add_line_breaks() |
|
96 | + { |
|
97 | + $this->content = preg_replace(self::$LINE_BREAK_PATTERN, self::$LINE_BREAK_REPLACE, $this->content); |
|
98 | + } |
|
99 | + |
|
100 | + private function replace_element_patterns() |
|
101 | + { |
|
102 | + foreach($this->replacement_array as $key => $replace) |
|
103 | + { |
|
104 | + $this->content = str_replace($key, $replace, $this->content); |
|
105 | + } |
|
106 | + } |
|
107 | 107 | |
108 | 108 | } |
109 | 109 | \ No newline at end of file |
@@ -2,8 +2,8 @@ discard block |
||
2 | 2 | |
3 | 3 | Loader::load('utility', 'Content'); |
4 | 4 | |
5 | -final class CleanCommentContent extends Content |
|
6 | -{ |
|
5 | +final class CleanCommentContent extends Content |
|
6 | +{ |
|
7 | 7 | |
8 | 8 | private static $LINK_PATTERN = '@<a.*href=["\']([^"\']*)["\'].*>(.*)</a>@i'; |
9 | 9 | private static $BOLD_PATTERN = '@<b.*>(.*)</b>@i'; |
@@ -22,8 +22,8 @@ discard block |
||
22 | 22 | |
23 | 23 | private $replacement_array = array(); |
24 | 24 | |
25 | - protected function execute() |
|
26 | - { |
|
25 | + protected function execute() |
|
26 | + { |
|
27 | 27 | $this->process_element(self::$CODE_PATTERN, self::$CODE_REPLACE); |
28 | 28 | $this->process_element(self::$LINK_PATTERN, self::$LINK_REPLACE); |
29 | 29 | $this->process_element(self::$ITALIC_PATTERN, self::$ITALIC_REPLACE); |
@@ -36,12 +36,13 @@ discard block |
||
36 | 36 | $this->replace_element_patterns(); |
37 | 37 | } |
38 | 38 | |
39 | - private function process_element($pattern, $replace) |
|
40 | - { |
|
39 | + private function process_element($pattern, $replace) |
|
40 | + { |
|
41 | 41 | $match_count = preg_match_all($pattern, $this->content, $matches, PREG_SET_ORDER); |
42 | 42 | |
43 | - if($match_count < 1) |
|
44 | - return; |
|
43 | + if($match_count < 1) { |
|
44 | + return; |
|
45 | + } |
|
45 | 46 | |
46 | 47 | foreach($matches as $match) |
47 | 48 | { |
@@ -54,13 +55,13 @@ discard block |
||
54 | 55 | } |
55 | 56 | } |
56 | 57 | |
57 | - private function create_placeholder($text) |
|
58 | - { |
|
58 | + private function create_placeholder($text) |
|
59 | + { |
|
59 | 60 | return md5($text . rand()); |
60 | 61 | } |
61 | 62 | |
62 | - private function create_full_match_pattern($text) |
|
63 | - { |
|
63 | + private function create_full_match_pattern($text) |
|
64 | + { |
|
64 | 65 | $pattern = ''; |
65 | 66 | $pattern .= '@'; |
66 | 67 | $pattern .= preg_quote($text, '@'); |
@@ -70,17 +71,18 @@ discard block |
||
70 | 71 | return $pattern; |
71 | 72 | } |
72 | 73 | |
73 | - private function strip_extra_tags() |
|
74 | - { |
|
74 | + private function strip_extra_tags() |
|
75 | + { |
|
75 | 76 | $this->content = strip_tags($this->content); |
76 | 77 | } |
77 | 78 | |
78 | - private function link_unlinked_urls($pattern, $replace) |
|
79 | - { |
|
79 | + private function link_unlinked_urls($pattern, $replace) |
|
80 | + { |
|
80 | 81 | $match_count = preg_match_all($pattern, $this->content, $matches, PREG_SET_ORDER); |
81 | 82 | |
82 | - if($match_count < 1) |
|
83 | - return; |
|
83 | + if($match_count < 1) { |
|
84 | + return; |
|
85 | + } |
|
84 | 86 | |
85 | 87 | foreach($matches as $match) |
86 | 88 | { |
@@ -92,13 +94,13 @@ discard block |
||
92 | 94 | } |
93 | 95 | } |
94 | 96 | |
95 | - private function add_line_breaks() |
|
96 | - { |
|
97 | + private function add_line_breaks() |
|
98 | + { |
|
97 | 99 | $this->content = preg_replace(self::$LINE_BREAK_PATTERN, self::$LINE_BREAK_REPLACE, $this->content); |
98 | 100 | } |
99 | 101 | |
100 | - private function replace_element_patterns() |
|
101 | - { |
|
102 | + private function replace_element_patterns() |
|
103 | + { |
|
102 | 104 | foreach($this->replacement_array as $key => $replace) |
103 | 105 | { |
104 | 106 | $this->content = str_replace($key, $replace, $this->content); |