@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | 26 | |
27 | - class Html{ |
|
27 | + class Html { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Generate the html anchor link |
@@ -35,19 +35,19 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @return string|void the anchor link generated html if $return is true or display it if not |
37 | 37 | */ |
38 | - public static function a($link = '', $anchor = null, array $attributes = array(), $return = true){ |
|
38 | + public static function a($link = '', $anchor = null, array $attributes = array(), $return = true) { |
|
39 | 39 | $link = Url::site_url($link); |
40 | - if(! $anchor){ |
|
40 | + if (!$anchor) { |
|
41 | 41 | $anchor = $link; |
42 | 42 | } |
43 | 43 | $str = null; |
44 | - $str .= '<a href = "'.$link.'"'; |
|
44 | + $str .= '<a href = "' . $link . '"'; |
|
45 | 45 | $str .= attributes_to_string($attributes); |
46 | 46 | $str .= '>'; |
47 | 47 | $str .= $anchor; |
48 | 48 | $str .= '</a>'; |
49 | 49 | |
50 | - if($return){ |
|
50 | + if ($return) { |
|
51 | 51 | return $str; |
52 | 52 | } |
53 | 53 | echo $str; |
@@ -62,18 +62,18 @@ discard block |
||
62 | 62 | * |
63 | 63 | * @return string|void the generated html for mailto link if $return is true or display it if not |
64 | 64 | */ |
65 | - public static function mailto($link, $anchor = null, array $attributes = array(), $return = true){ |
|
66 | - if(! $anchor){ |
|
65 | + public static function mailto($link, $anchor = null, array $attributes = array(), $return = true) { |
|
66 | + if (!$anchor) { |
|
67 | 67 | $anchor = $link; |
68 | 68 | } |
69 | 69 | $str = null; |
70 | - $str .= '<a href = "mailto:'.$link.'"'; |
|
70 | + $str .= '<a href = "mailto:' . $link . '"'; |
|
71 | 71 | $str .= attributes_to_string($attributes); |
72 | 72 | $str .= '>'; |
73 | 73 | $str .= $anchor; |
74 | 74 | $str .= '</a>'; |
75 | 75 | |
76 | - if($return){ |
|
76 | + if ($return) { |
|
77 | 77 | return $str; |
78 | 78 | } |
79 | 79 | echo $str; |
@@ -86,14 +86,14 @@ discard block |
||
86 | 86 | * |
87 | 87 | * @return string|void the generated "br" html if $return is true or display it if not |
88 | 88 | */ |
89 | - public static function br($nb = 1, $return = true){ |
|
89 | + public static function br($nb = 1, $return = true) { |
|
90 | 90 | $nb = (int) $nb; |
91 | 91 | $str = null; |
92 | 92 | for ($i = 1; $i <= $nb; $i++) { |
93 | 93 | $str .= '<br />'; |
94 | 94 | } |
95 | 95 | |
96 | - if($return){ |
|
96 | + if ($return) { |
|
97 | 97 | return $str; |
98 | 98 | } |
99 | 99 | echo $str; |
@@ -107,13 +107,13 @@ discard block |
||
107 | 107 | * |
108 | 108 | * @return string|void the generated "hr" html if $return is true or display it if not. |
109 | 109 | */ |
110 | - public static function hr($nb = 1, array $attributes = array(), $return = true){ |
|
110 | + public static function hr($nb = 1, array $attributes = array(), $return = true) { |
|
111 | 111 | $nb = (int) $nb; |
112 | 112 | $str = null; |
113 | 113 | for ($i = 1; $i <= $nb; $i++) { |
114 | - $str .= '<hr' .attributes_to_string($attributes). ' />'; |
|
114 | + $str .= '<hr' . attributes_to_string($attributes) . ' />'; |
|
115 | 115 | } |
116 | - if($return){ |
|
116 | + if ($return) { |
|
117 | 117 | return $str; |
118 | 118 | } |
119 | 119 | echo $str; |
@@ -129,14 +129,14 @@ discard block |
||
129 | 129 | * |
130 | 130 | * @return string|void the generated header html if $return is true or display it if not. |
131 | 131 | */ |
132 | - public static function head($type = 1, $text = null, $nb = 1, array $attributes = array(), $return = true){ |
|
132 | + public static function head($type = 1, $text = null, $nb = 1, array $attributes = array(), $return = true) { |
|
133 | 133 | $nb = (int) $nb; |
134 | 134 | $type = (int) $type; |
135 | 135 | $str = null; |
136 | 136 | for ($i = 1; $i <= $nb; $i++) { |
137 | - $str .= '<h' . $type . attributes_to_string($attributes). '>' .$text. '</h' . $type . '>'; |
|
137 | + $str .= '<h' . $type . attributes_to_string($attributes) . '>' . $text . '</h' . $type . '>'; |
|
138 | 138 | } |
139 | - if($return){ |
|
139 | + if ($return) { |
|
140 | 140 | return $str; |
141 | 141 | } |
142 | 142 | echo $str; |
@@ -151,8 +151,8 @@ discard block |
||
151 | 151 | * |
152 | 152 | * @return string|void the generated "ul" html if $return is true or display it if not. |
153 | 153 | */ |
154 | - public static function ul($data = array(), $attributes = array(), $return = true){ |
|
155 | - if($return){ |
|
154 | + public static function ul($data = array(), $attributes = array(), $return = true) { |
|
155 | + if ($return) { |
|
156 | 156 | return self::buildUlOl($data, $attributes, true, 'ul'); |
157 | 157 | } |
158 | 158 | self::buildUlOl($data, $attributes, false, 'ul'); |
@@ -166,8 +166,8 @@ discard block |
||
166 | 166 | * @param boolean $return whether need return the generated html or just display it directly |
167 | 167 | * @return string|void the generated "ol" html if $return is true or display it if not. |
168 | 168 | */ |
169 | - public static function ol($data = array(), $attributes = array(), $return = true){ |
|
170 | - if($return){ |
|
169 | + public static function ol($data = array(), $attributes = array(), $return = true) { |
|
170 | + if ($return) { |
|
171 | 171 | return self::buildUlOl($data, $attributes, true, 'ol'); |
172 | 172 | } |
173 | 173 | self::buildUlOl($data, $attributes, false, 'ol'); |
@@ -186,23 +186,23 @@ discard block |
||
186 | 186 | * @param boolean $return whether need return the generated html or just display it directly |
187 | 187 | * @return string|void the generated "table" html if $return is true or display it if not. |
188 | 188 | */ |
189 | - public static function table($headers = array(), $body = array(), $attributes = array(), $use_footer = false, $return = true){ |
|
189 | + public static function table($headers = array(), $body = array(), $attributes = array(), $use_footer = false, $return = true) { |
|
190 | 190 | $headers = (array) $headers; |
191 | 191 | $body = (array) $body; |
192 | 192 | $str = null; |
193 | 193 | $tableAttributes = ''; |
194 | - if(! empty($attributes['table'])){ |
|
194 | + if (!empty($attributes['table'])) { |
|
195 | 195 | $tableAttributes = ' ' . attributes_to_string($attributes['table']); |
196 | 196 | } |
197 | 197 | $str .= '<table' . $tableAttributes . '>'; |
198 | 198 | $str .= self::buildTableHeader($headers, $attributes); |
199 | 199 | $str .= self::buildTableBody($body, $attributes); |
200 | 200 | |
201 | - if($use_footer){ |
|
201 | + if ($use_footer) { |
|
202 | 202 | $str .= self::buildTableFooter($headers, $attributes); |
203 | 203 | } |
204 | 204 | $str .= '</table>'; |
205 | - if($return){ |
|
205 | + if ($return) { |
|
206 | 206 | return $str; |
207 | 207 | } |
208 | 208 | echo $str; |
@@ -213,24 +213,24 @@ discard block |
||
213 | 213 | * @see Html::table |
214 | 214 | * @return string|null |
215 | 215 | */ |
216 | - protected static function buildTableHeader(array $headers, $attributes = array()){ |
|
216 | + protected static function buildTableHeader(array $headers, $attributes = array()) { |
|
217 | 217 | $str = null; |
218 | 218 | $theadAttributes = ''; |
219 | - if(! empty($attributes['thead'])){ |
|
219 | + if (!empty($attributes['thead'])) { |
|
220 | 220 | $theadAttributes = ' ' . attributes_to_string($attributes['thead']); |
221 | 221 | } |
222 | 222 | $theadtrAttributes = ''; |
223 | - if(! empty($attributes['thead_tr'])){ |
|
223 | + if (!empty($attributes['thead_tr'])) { |
|
224 | 224 | $theadtrAttributes = ' ' . attributes_to_string($attributes['thead_tr']); |
225 | 225 | } |
226 | 226 | $thAttributes = ''; |
227 | - if(! empty($attributes['thead_th'])){ |
|
227 | + if (!empty($attributes['thead_th'])) { |
|
228 | 228 | $thAttributes = ' ' . attributes_to_string($attributes['thead_th']); |
229 | 229 | } |
230 | - $str .= '<thead' . $theadAttributes .'>'; |
|
231 | - $str .= '<tr' . $theadtrAttributes .'>'; |
|
230 | + $str .= '<thead' . $theadAttributes . '>'; |
|
231 | + $str .= '<tr' . $theadtrAttributes . '>'; |
|
232 | 232 | foreach ($headers as $value) { |
233 | - $str .= '<th' . $thAttributes .'>' .$value. '</th>'; |
|
233 | + $str .= '<th' . $thAttributes . '>' . $value . '</th>'; |
|
234 | 234 | } |
235 | 235 | $str .= '</tr>'; |
236 | 236 | $str .= '</thead>'; |
@@ -242,21 +242,21 @@ discard block |
||
242 | 242 | * @see Html::table |
243 | 243 | * @return string|null |
244 | 244 | */ |
245 | - protected static function buildTableBody(array $body, $attributes = array()){ |
|
245 | + protected static function buildTableBody(array $body, $attributes = array()) { |
|
246 | 246 | $str = null; |
247 | 247 | $tbodyAttributes = ''; |
248 | - if(! empty($attributes['tbody'])){ |
|
248 | + if (!empty($attributes['tbody'])) { |
|
249 | 249 | $tbodyAttributes = ' ' . attributes_to_string($attributes['tbody']); |
250 | 250 | } |
251 | 251 | $tbodytrAttributes = ''; |
252 | - if(! empty($attributes['tbody_tr'])){ |
|
252 | + if (!empty($attributes['tbody_tr'])) { |
|
253 | 253 | $tbodytrAttributes = ' ' . attributes_to_string($attributes['tbody_tr']); |
254 | 254 | } |
255 | 255 | $tbodytdAttributes = ''; |
256 | - if(! empty($attributes['tbody_td'])){ |
|
256 | + if (!empty($attributes['tbody_td'])) { |
|
257 | 257 | $tbodytdAttributes = ' ' . attributes_to_string($attributes['tbody_td']); |
258 | 258 | } |
259 | - $str .= '<tbody' . $tbodyAttributes .'>'; |
|
259 | + $str .= '<tbody' . $tbodyAttributes . '>'; |
|
260 | 260 | $str .= self::buildTableBodyContent($body, $tbodytrAttributes, $tbodytdAttributes); |
261 | 261 | $str .= '</tbody>'; |
262 | 262 | return $str; |
@@ -269,13 +269,13 @@ discard block |
||
269 | 269 | * @param string $tbodytdAttributes the html attributes for each td in tbody |
270 | 270 | * @return string |
271 | 271 | */ |
272 | - protected static function buildTableBodyContent(array $body, $tbodytrAttributes, $tbodytdAttributes){ |
|
272 | + protected static function buildTableBodyContent(array $body, $tbodytrAttributes, $tbodytdAttributes) { |
|
273 | 273 | $str = null; |
274 | 274 | foreach ($body as $row) { |
275 | - if(is_array($row)){ |
|
276 | - $str .= '<tr' . $tbodytrAttributes .'>'; |
|
275 | + if (is_array($row)) { |
|
276 | + $str .= '<tr' . $tbodytrAttributes . '>'; |
|
277 | 277 | foreach ($row as $value) { |
278 | - $str .= '<td' . $tbodytdAttributes .'>' .$value. '</td>'; |
|
278 | + $str .= '<td' . $tbodytdAttributes . '>' . $value . '</td>'; |
|
279 | 279 | } |
280 | 280 | $str .= '</tr>'; |
281 | 281 | } |
@@ -288,24 +288,24 @@ discard block |
||
288 | 288 | * @see Html::table |
289 | 289 | * @return string|null |
290 | 290 | */ |
291 | - protected static function buildTableFooter(array $footers, $attributes = array()){ |
|
291 | + protected static function buildTableFooter(array $footers, $attributes = array()) { |
|
292 | 292 | $str = null; |
293 | 293 | $tfootAttributes = ''; |
294 | - if(! empty($attributes['tfoot'])){ |
|
294 | + if (!empty($attributes['tfoot'])) { |
|
295 | 295 | $tfootAttributes = ' ' . attributes_to_string($attributes['tfoot']); |
296 | 296 | } |
297 | 297 | $tfoottrAttributes = ''; |
298 | - if(! empty($attributes['tfoot_tr'])){ |
|
298 | + if (!empty($attributes['tfoot_tr'])) { |
|
299 | 299 | $tfoottrAttributes = ' ' . attributes_to_string($attributes['tfoot_tr']); |
300 | 300 | } |
301 | 301 | $thAttributes = ''; |
302 | - if(! empty($attributes['tfoot_th'])){ |
|
302 | + if (!empty($attributes['tfoot_th'])) { |
|
303 | 303 | $thAttributes = ' ' . attributes_to_string($attributes['tfoot_th']); |
304 | 304 | } |
305 | - $str .= '<tfoot' . $tfootAttributes .'>'; |
|
306 | - $str .= '<tr' . $tfoottrAttributes .'>'; |
|
305 | + $str .= '<tfoot' . $tfootAttributes . '>'; |
|
306 | + $str .= '<tr' . $tfoottrAttributes . '>'; |
|
307 | 307 | foreach ($footers as $value) { |
308 | - $str .= '<th' . $thAttributes .'>' .$value. '</th>'; |
|
308 | + $str .= '<th' . $thAttributes . '>' . $value . '</th>'; |
|
309 | 309 | } |
310 | 310 | $str .= '</tr>'; |
311 | 311 | $str .= '</tfoot>'; |
@@ -319,23 +319,23 @@ discard block |
||
319 | 319 | * @param string $olul the type 'ol' or 'ul' |
320 | 320 | * @return void|string |
321 | 321 | */ |
322 | - protected static function buildUlOl($data = array(), $attributes = array(), $return = true, $olul = 'ul'){ |
|
322 | + protected static function buildUlOl($data = array(), $attributes = array(), $return = true, $olul = 'ul') { |
|
323 | 323 | $data = (array) $data; |
324 | 324 | $str = null; |
325 | 325 | $olulAttributes = ''; |
326 | - if(! empty($attributes[$olul])){ |
|
326 | + if (!empty($attributes[$olul])) { |
|
327 | 327 | $olulAttributes = ' ' . attributes_to_string($attributes[$olul]); |
328 | 328 | } |
329 | 329 | $liAttributes = ''; |
330 | - if(! empty($attributes['li'])){ |
|
330 | + if (!empty($attributes['li'])) { |
|
331 | 331 | $liAttributes = ' ' . attributes_to_string($attributes['li']); |
332 | 332 | } |
333 | 333 | $str .= '<' . $olul . $olulAttributes . '>'; |
334 | 334 | foreach ($data as $row) { |
335 | - $str .= '<li' . $liAttributes .'>' .$row. '</li>'; |
|
335 | + $str .= '<li' . $liAttributes . '>' . $row . '</li>'; |
|
336 | 336 | } |
337 | 337 | $str .= '</' . $olul . '>'; |
338 | - if($return){ |
|
338 | + if ($return) { |
|
339 | 339 | return $str; |
340 | 340 | } |
341 | 341 | echo $str; |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | */ |
26 | 26 | |
27 | 27 | |
28 | - class Form{ |
|
28 | + class Form { |
|
29 | 29 | |
30 | 30 | /** |
31 | 31 | * Generate the form opened tag |
@@ -35,23 +35,23 @@ discard block |
||
35 | 35 | * @param string $enctype the form enctype like "multipart/form-data" |
36 | 36 | * @return string the generated form html |
37 | 37 | */ |
38 | - public static function open($path = null, array $attributes = array(), $method = 'POST', $enctype = null){ |
|
39 | - if($path){ |
|
38 | + public static function open($path = null, array $attributes = array(), $method = 'POST', $enctype = null) { |
|
39 | + if ($path) { |
|
40 | 40 | $path = Url::site_url($path); |
41 | 41 | } |
42 | 42 | $method = strtoupper($method); |
43 | 43 | $str = null; |
44 | - $str .= '<form action = "'.$path.'" method = "'.$method.'"'; |
|
45 | - if(! empty($enctype)){ |
|
46 | - $str .= ' enctype = "'.$enctype.'" '; |
|
44 | + $str .= '<form action = "' . $path . '" method = "' . $method . '"'; |
|
45 | + if (!empty($enctype)) { |
|
46 | + $str .= ' enctype = "' . $enctype . '" '; |
|
47 | 47 | } |
48 | - if(! isset($attributes['accept-charset'])){ |
|
48 | + if (!isset($attributes['accept-charset'])) { |
|
49 | 49 | $attributes['accept-charset'] = get_config('charset', 'utf-8'); |
50 | 50 | } |
51 | 51 | $str .= attributes_to_string($attributes); |
52 | 52 | $str .= '>'; |
53 | 53 | //if CSRF is enabled in the configuration |
54 | - if(get_config('csrf_enable', false) && $method == 'POST'){ |
|
54 | + if (get_config('csrf_enable', false) && $method == 'POST') { |
|
55 | 55 | $csrfValue = Security::generateCSRF(); |
56 | 56 | $csrfName = get_config('csrf_key', 'csrf_key'); |
57 | 57 | $str .= static::hidden($csrfName, $csrfValue); |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * @see Form::open() for more details |
65 | 65 | * @return string the generated multipart form html |
66 | 66 | */ |
67 | - public static function openMultipart($path = null, array $attributes = array(), $method = 'POST'){ |
|
67 | + public static function openMultipart($path = null, array $attributes = array(), $method = 'POST') { |
|
68 | 68 | return self::open($path, $attributes, $method, 'multipart/form-data'); |
69 | 69 | } |
70 | 70 | |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | * Generate the form close |
73 | 73 | * @return string the form close html |
74 | 74 | */ |
75 | - public static function close(){ |
|
75 | + public static function close() { |
|
76 | 76 | return '</form>'; |
77 | 77 | } |
78 | 78 | |
@@ -83,10 +83,10 @@ discard block |
||
83 | 83 | * @param array $legendAttributes the legend additional HTML attributes. Is used only is $legend is not empty |
84 | 84 | * @return string the generated fieldset value |
85 | 85 | */ |
86 | - public static function fieldset($legend = '', array $fieldsetAttributes = array(), array $legendAttributes = array()){ |
|
86 | + public static function fieldset($legend = '', array $fieldsetAttributes = array(), array $legendAttributes = array()) { |
|
87 | 87 | $str = '<fieldset' . attributes_to_string($fieldsetAttributes) . '>'; |
88 | - if($legend){ |
|
89 | - $str .= '<legend' . attributes_to_string($legendAttributes) . '>'.$legend.'</legend>'; |
|
88 | + if ($legend) { |
|
89 | + $str .= '<legend' . attributes_to_string($legendAttributes) . '>' . $legend . '</legend>'; |
|
90 | 90 | } |
91 | 91 | return $str; |
92 | 92 | } |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * Generate the fieldset close tag |
96 | 96 | * @return string the generated html for fieldset close |
97 | 97 | */ |
98 | - public static function fieldsetClose(){ |
|
98 | + public static function fieldsetClose() { |
|
99 | 99 | return '</fieldset>'; |
100 | 100 | } |
101 | 101 | |
@@ -105,12 +105,12 @@ discard block |
||
105 | 105 | * @param string $name the form field name |
106 | 106 | * @return string the error message if exists and null if not |
107 | 107 | */ |
108 | - public static function error($name){ |
|
108 | + public static function error($name) { |
|
109 | 109 | $return = null; |
110 | 110 | $obj = & get_instance(); |
111 | - if(isset($obj->formvalidation)){ |
|
111 | + if (isset($obj->formvalidation)) { |
|
112 | 112 | $errors = $obj->formvalidation->returnErrors(); |
113 | - if(isset($errors[$name])){ |
|
113 | + if (isset($errors[$name])) { |
|
114 | 114 | list($errorStart, $errorEnd) = $obj->formvalidation->getErrorDelimiter(); |
115 | 115 | $return = $errorStart . $errors[$name] . $errorEnd; |
116 | 116 | } |
@@ -124,9 +124,9 @@ discard block |
||
124 | 124 | * @param mixed $default the default value if can not found the given form field name |
125 | 125 | * @return mixed the form field value if is set, otherwise return the default value. |
126 | 126 | */ |
127 | - public static function value($name, $default = null){ |
|
127 | + public static function value($name, $default = null) { |
|
128 | 128 | $value = get_instance()->request->query($name); |
129 | - if(strlen($value) > 0){ |
|
129 | + if (strlen($value) > 0) { |
|
130 | 130 | return $value; |
131 | 131 | } |
132 | 132 | return $default; |
@@ -139,14 +139,14 @@ discard block |
||
139 | 139 | * @param array $attributes the additional attributes to be added |
140 | 140 | * @return string the generated label html content |
141 | 141 | */ |
142 | - public static function label($label, $for = '', array $attributes = array()){ |
|
142 | + public static function label($label, $for = '', array $attributes = array()) { |
|
143 | 143 | $str = '<label'; |
144 | - if($for){ |
|
145 | - $str .= ' for = "'.$for.'"'; |
|
144 | + if ($for) { |
|
145 | + $str .= ' for = "' . $for . '"'; |
|
146 | 146 | } |
147 | 147 | $str .= attributes_to_string($attributes); |
148 | 148 | $str .= '>'; |
149 | - $str .= $label.'</label>'; |
|
149 | + $str .= $label . '</label>'; |
|
150 | 150 | return $str; |
151 | 151 | } |
152 | 152 | |
@@ -158,9 +158,9 @@ discard block |
||
158 | 158 | * @param string $type the type of the form field (password, text, submit, button, etc.) |
159 | 159 | * @return string the generated form field html content for the input |
160 | 160 | */ |
161 | - public static function input($name, $value = null, array $attributes = array(), $type = 'text'){ |
|
161 | + public static function input($name, $value = null, array $attributes = array(), $type = 'text') { |
|
162 | 162 | $str = null; |
163 | - $str .= '<input name = "'.$name.'" value = "'.$value.'" type = "'.$type.'"'; |
|
163 | + $str .= '<input name = "' . $name . '" value = "' . $value . '" type = "' . $type . '"'; |
|
164 | 164 | $str .= attributes_to_string($attributes); |
165 | 165 | $str .= '/>'; |
166 | 166 | return $str; |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | * Generate the form field for "text" |
171 | 171 | * @see Form::input() for more details |
172 | 172 | */ |
173 | - public static function text($name, $value = null, array $attributes = array()){ |
|
173 | + public static function text($name, $value = null, array $attributes = array()) { |
|
174 | 174 | return self::input($name, $value, $attributes, 'text'); |
175 | 175 | } |
176 | 176 | |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * Generate the form field for "password" |
179 | 179 | * @see Form::input() for more details |
180 | 180 | */ |
181 | - public static function password($name, $value = null, array $attributes = array()){ |
|
181 | + public static function password($name, $value = null, array $attributes = array()) { |
|
182 | 182 | return self::input($name, $value, $attributes, 'password'); |
183 | 183 | } |
184 | 184 | |
@@ -186,8 +186,8 @@ discard block |
||
186 | 186 | * Generate the form field for "radio" |
187 | 187 | * @see Form::input() for more details |
188 | 188 | */ |
189 | - public static function radio($name, $value = null, $checked = false, array $attributes = array()){ |
|
190 | - if($checked){ |
|
189 | + public static function radio($name, $value = null, $checked = false, array $attributes = array()) { |
|
190 | + if ($checked) { |
|
191 | 191 | $attributes['checked'] = true; |
192 | 192 | } |
193 | 193 | return self::input($name, $value, $attributes, 'radio'); |
@@ -197,8 +197,8 @@ discard block |
||
197 | 197 | * Generate the form field for "checkbox" |
198 | 198 | * @see Form::input() for more details |
199 | 199 | */ |
200 | - public static function checkbox($name, $value = null, $checked = false, array $attributes = array()){ |
|
201 | - if($checked){ |
|
200 | + public static function checkbox($name, $value = null, $checked = false, array $attributes = array()) { |
|
201 | + if ($checked) { |
|
202 | 202 | $attributes['checked'] = true; |
203 | 203 | } |
204 | 204 | return self::input($name, $value, $attributes, 'checkbox'); |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | * Generate the form field for "number" |
209 | 209 | * @see Form::input() for more details |
210 | 210 | */ |
211 | - public static function number($name, $value = null, array $attributes = array()){ |
|
211 | + public static function number($name, $value = null, array $attributes = array()) { |
|
212 | 212 | return self::input($name, $value, $attributes, 'number'); |
213 | 213 | } |
214 | 214 | |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | * Generate the form field for "phone" |
217 | 217 | * @see Form::input() for more details |
218 | 218 | */ |
219 | - public static function phone($name, $value = null, array $attributes = array()){ |
|
219 | + public static function phone($name, $value = null, array $attributes = array()) { |
|
220 | 220 | return self::input($name, $value, $attributes, 'phone'); |
221 | 221 | } |
222 | 222 | |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | * Generate the form field for "email" |
225 | 225 | * @see Form::input() for more details |
226 | 226 | */ |
227 | - public static function email($name, $value = null, array $attributes = array()){ |
|
227 | + public static function email($name, $value = null, array $attributes = array()) { |
|
228 | 228 | return self::input($name, $value, $attributes, 'email'); |
229 | 229 | } |
230 | 230 | |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | * Generate the form field for "search" |
233 | 233 | * @see Form::input() for more details |
234 | 234 | */ |
235 | - public static function search($name, $value = null, array $attributes = array()){ |
|
235 | + public static function search($name, $value = null, array $attributes = array()) { |
|
236 | 236 | return self::input($name, $value, $attributes, 'search'); |
237 | 237 | } |
238 | 238 | |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | * Generate the form field for "hidden" |
241 | 241 | * @see Form::input() for more details |
242 | 242 | */ |
243 | - public static function hidden($name, $value = null, array $attributes = array()){ |
|
243 | + public static function hidden($name, $value = null, array $attributes = array()) { |
|
244 | 244 | return self::input($name, $value, $attributes, 'hidden'); |
245 | 245 | } |
246 | 246 | |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | * Generate the form field for "file" |
249 | 249 | * @see Form::input() for more details |
250 | 250 | */ |
251 | - public static function file($name, array $attributes = array()){ |
|
251 | + public static function file($name, array $attributes = array()) { |
|
252 | 252 | return self::input($name, null, $attributes, 'file'); |
253 | 253 | } |
254 | 254 | |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | * Generate the form field for "button" |
257 | 257 | * @see Form::input() for more details |
258 | 258 | */ |
259 | - public static function button($name, $value = null, array $attributes = array()){ |
|
259 | + public static function button($name, $value = null, array $attributes = array()) { |
|
260 | 260 | return self::input($name, $value, $attributes, 'button'); |
261 | 261 | } |
262 | 262 | |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | * Generate the form field for "reset" |
265 | 265 | * @see Form::input() for more details |
266 | 266 | */ |
267 | - public static function reset($name, $value = null, array $attributes = array()){ |
|
267 | + public static function reset($name, $value = null, array $attributes = array()) { |
|
268 | 268 | return self::input($name, $value, $attributes, 'reset'); |
269 | 269 | } |
270 | 270 | |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | * Generate the form field for "submit" |
273 | 273 | * @see Form::input() for more details |
274 | 274 | */ |
275 | - public static function submit($name, $value = null, array $attributes = array()){ |
|
275 | + public static function submit($name, $value = null, array $attributes = array()) { |
|
276 | 276 | return self::input($name, $value, $attributes, 'submit'); |
277 | 277 | } |
278 | 278 | |
@@ -283,12 +283,12 @@ discard block |
||
283 | 283 | * @param array $attributes the additional attributes to be added |
284 | 284 | * @return string the generated textarea form html content |
285 | 285 | */ |
286 | - public static function textarea($name, $value = '', array $attributes = array()){ |
|
286 | + public static function textarea($name, $value = '', array $attributes = array()) { |
|
287 | 287 | $str = null; |
288 | - $str .= '<textarea name = "'.$name.'"'; |
|
288 | + $str .= '<textarea name = "' . $name . '"'; |
|
289 | 289 | $str .= attributes_to_string($attributes); |
290 | 290 | $str .= '>'; |
291 | - $str .= $value.'</textarea>'; |
|
291 | + $str .= $value . '</textarea>'; |
|
292 | 292 | return $str; |
293 | 293 | } |
294 | 294 | |
@@ -300,20 +300,20 @@ discard block |
||
300 | 300 | * @param array $attributes the additional attribute to be added |
301 | 301 | * @return string the generated form field html content for select |
302 | 302 | */ |
303 | - public static function select($name, $values = null, $selected = null, array $attributes = array()){ |
|
304 | - if(! is_array($values)){ |
|
303 | + public static function select($name, $values = null, $selected = null, array $attributes = array()) { |
|
304 | + if (!is_array($values)) { |
|
305 | 305 | $values = array('' => $values); |
306 | 306 | } |
307 | 307 | $str = null; |
308 | - $str .= '<select name = "'.$name.'"'; |
|
308 | + $str .= '<select name = "' . $name . '"'; |
|
309 | 309 | $str .= attributes_to_string($attributes); |
310 | 310 | $str .= '>'; |
311 | - foreach($values as $key => $val){ |
|
311 | + foreach ($values as $key => $val) { |
|
312 | 312 | $select = ''; |
313 | - if($key == $selected){ |
|
313 | + if ($key == $selected) { |
|
314 | 314 | $select = 'selected'; |
315 | 315 | } |
316 | - $str .= '<option value = "'.$key.'" '.$select.'>'.$val.'</option>'; |
|
316 | + $str .= '<option value = "' . $key . '" ' . $select . '>' . $val . '</option>'; |
|
317 | 317 | } |
318 | 318 | $str .= '</select>'; |
319 | 319 | return $str; |
@@ -1,204 +1,204 @@ |
||
1 | 1 | <?php |
2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
3 | - /** |
|
4 | - * TNH Framework |
|
5 | - * |
|
6 | - * A simple PHP framework using HMVC architecture |
|
7 | - * |
|
8 | - * This content is released under the GNU GPL License (GPL) |
|
9 | - * |
|
10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
11 | - * |
|
12 | - * This program is free software; you can redistribute it and/or |
|
13 | - * modify it under the terms of the GNU General Public License |
|
14 | - * as published by the Free Software Foundation; either version 3 |
|
15 | - * of the License, or (at your option) any later version. |
|
16 | - * |
|
17 | - * This program is distributed in the hope that it will be useful, |
|
18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20 | - * GNU General Public License for more details. |
|
21 | - * |
|
22 | - * You should have received a copy of the GNU General Public License |
|
23 | - * along with this program; if not, write to the Free Software |
|
24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
25 | - */ |
|
26 | - |
|
27 | - /** |
|
28 | - * @file bootstrap.php |
|
29 | - * |
|
30 | - * Contains the loading process: loading of constants, common functions, libraries |
|
31 | - * configurations, etc |
|
32 | - * verification of the environment and the routing of the request. |
|
33 | - * |
|
34 | - * @package core |
|
35 | - * @author Tony NGUEREZA |
|
36 | - * @copyright Copyright (c) 2017 |
|
37 | - * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
38 | - * @link http://www.iacademy.cf |
|
39 | - * @version 1.0.0 |
|
40 | - * @filesource |
|
41 | - */ |
|
2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
3 | + /** |
|
4 | + * TNH Framework |
|
5 | + * |
|
6 | + * A simple PHP framework using HMVC architecture |
|
7 | + * |
|
8 | + * This content is released under the GNU GPL License (GPL) |
|
9 | + * |
|
10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
11 | + * |
|
12 | + * This program is free software; you can redistribute it and/or |
|
13 | + * modify it under the terms of the GNU General Public License |
|
14 | + * as published by the Free Software Foundation; either version 3 |
|
15 | + * of the License, or (at your option) any later version. |
|
16 | + * |
|
17 | + * This program is distributed in the hope that it will be useful, |
|
18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20 | + * GNU General Public License for more details. |
|
21 | + * |
|
22 | + * You should have received a copy of the GNU General Public License |
|
23 | + * along with this program; if not, write to the Free Software |
|
24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
25 | + */ |
|
26 | + |
|
27 | + /** |
|
28 | + * @file bootstrap.php |
|
29 | + * |
|
30 | + * Contains the loading process: loading of constants, common functions, libraries |
|
31 | + * configurations, etc |
|
32 | + * verification of the environment and the routing of the request. |
|
33 | + * |
|
34 | + * @package core |
|
35 | + * @author Tony NGUEREZA |
|
36 | + * @copyright Copyright (c) 2017 |
|
37 | + * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
38 | + * @link http://www.iacademy.cf |
|
39 | + * @version 1.0.0 |
|
40 | + * @filesource |
|
41 | + */ |
|
42 | 42 | |
43 | - //if the application is running in CLI mode $_SESSION global variable is not available |
|
44 | - if (IS_CLI) { |
|
45 | - $_SESSION = array(); |
|
46 | - } |
|
43 | + //if the application is running in CLI mode $_SESSION global variable is not available |
|
44 | + if (IS_CLI) { |
|
45 | + $_SESSION = array(); |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * inclusion of global constants of the environment that contain : name of the framework, |
|
50 | - * version, release date, version of PHP required, etc. |
|
51 | - */ |
|
52 | - require_once CORE_PATH . 'constants.php'; |
|
48 | + /** |
|
49 | + * inclusion of global constants of the environment that contain : name of the framework, |
|
50 | + * version, release date, version of PHP required, etc. |
|
51 | + */ |
|
52 | + require_once CORE_PATH . 'constants.php'; |
|
53 | 53 | |
54 | - /** |
|
55 | - * include file containing commons functions used in the framework such: show_error, |
|
56 | - * php_exception_handler, php_error_handler, get_instance, etc. |
|
57 | - */ |
|
58 | - require_once CORE_PATH . 'common.php'; |
|
59 | - |
|
60 | - /** |
|
61 | - * Include of the file containing the BaseClass |
|
62 | - */ |
|
63 | - require_once CORE_CLASSES_PATH . 'BaseClass.php'; |
|
64 | - |
|
65 | - /** |
|
66 | - * Include of the file containing the BaseClass |
|
67 | - */ |
|
68 | - require_once CORE_CLASSES_PATH . 'BaseStaticClass.php'; |
|
69 | - |
|
70 | - /** |
|
71 | - * The Benchmark class |
|
72 | - */ |
|
73 | - $BENCHMARK = & class_loader('Benchmark'); |
|
54 | + /** |
|
55 | + * include file containing commons functions used in the framework such: show_error, |
|
56 | + * php_exception_handler, php_error_handler, get_instance, etc. |
|
57 | + */ |
|
58 | + require_once CORE_PATH . 'common.php'; |
|
59 | + |
|
60 | + /** |
|
61 | + * Include of the file containing the BaseClass |
|
62 | + */ |
|
63 | + require_once CORE_CLASSES_PATH . 'BaseClass.php'; |
|
64 | + |
|
65 | + /** |
|
66 | + * Include of the file containing the BaseClass |
|
67 | + */ |
|
68 | + require_once CORE_CLASSES_PATH . 'BaseStaticClass.php'; |
|
69 | + |
|
70 | + /** |
|
71 | + * The Benchmark class |
|
72 | + */ |
|
73 | + $BENCHMARK = & class_loader('Benchmark'); |
|
74 | 74 | |
75 | - $BENCHMARK->mark('APP_EXECUTION_START'); |
|
75 | + $BENCHMARK->mark('APP_EXECUTION_START'); |
|
76 | 76 | |
77 | - /** |
|
78 | - * instance of the Log class |
|
79 | - */ |
|
77 | + /** |
|
78 | + * instance of the Log class |
|
79 | + */ |
|
80 | 80 | $LOGGER = & class_loader('Log', 'classes'); |
81 | 81 | |
82 | 82 | $LOGGER->setLogger('ApplicationBootstrap'); |
83 | 83 | |
84 | 84 | $LOGGER->debug('Checking PHP version ...'); |
85 | 85 | |
86 | - /** |
|
87 | - * Verification of the PHP environment: minimum and maximum version |
|
88 | - */ |
|
89 | - if (version_compare(phpversion(), TNH_REQUIRED_PHP_MIN_VERSION, '<')){ |
|
90 | - show_error('Your PHP Version [' . phpversion() . '] is less than [' . TNH_REQUIRED_PHP_MIN_VERSION . '], please install a new version or update your PHP to the latest.', 'PHP Error environment'); |
|
91 | - } else if(version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')){ |
|
92 | - show_error('Your PHP Version [' . phpversion() . '] is greather than [' . TNH_REQUIRED_PHP_MAX_VERSION . '] please install a PHP version that is compatible.', 'PHP Error environment'); |
|
93 | - } |
|
94 | - $LOGGER->info('PHP version [' . phpversion() . '] is OK [REQUIRED MINIMUM: ' . TNH_REQUIRED_PHP_MIN_VERSION . ', REQUIRED MAXIMUM: ' . TNH_REQUIRED_PHP_MAX_VERSION . '], application can work without any issue'); |
|
95 | - |
|
96 | - /** |
|
97 | - * Setting of the PHP error message handling function |
|
98 | - */ |
|
99 | - set_error_handler('php_error_handler'); |
|
100 | - |
|
101 | - /** |
|
102 | - * Setting of the PHP error exception handling function |
|
103 | - */ |
|
104 | - set_exception_handler('php_exception_handler'); |
|
105 | - |
|
106 | - /** |
|
107 | - * Setting of the PHP shutdown handling function |
|
108 | - */ |
|
109 | - register_shutdown_function('php_shudown_handler'); |
|
86 | + /** |
|
87 | + * Verification of the PHP environment: minimum and maximum version |
|
88 | + */ |
|
89 | + if (version_compare(phpversion(), TNH_REQUIRED_PHP_MIN_VERSION, '<')){ |
|
90 | + show_error('Your PHP Version [' . phpversion() . '] is less than [' . TNH_REQUIRED_PHP_MIN_VERSION . '], please install a new version or update your PHP to the latest.', 'PHP Error environment'); |
|
91 | + } else if(version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')){ |
|
92 | + show_error('Your PHP Version [' . phpversion() . '] is greather than [' . TNH_REQUIRED_PHP_MAX_VERSION . '] please install a PHP version that is compatible.', 'PHP Error environment'); |
|
93 | + } |
|
94 | + $LOGGER->info('PHP version [' . phpversion() . '] is OK [REQUIRED MINIMUM: ' . TNH_REQUIRED_PHP_MIN_VERSION . ', REQUIRED MAXIMUM: ' . TNH_REQUIRED_PHP_MAX_VERSION . '], application can work without any issue'); |
|
95 | + |
|
96 | + /** |
|
97 | + * Setting of the PHP error message handling function |
|
98 | + */ |
|
99 | + set_error_handler('php_error_handler'); |
|
100 | + |
|
101 | + /** |
|
102 | + * Setting of the PHP error exception handling function |
|
103 | + */ |
|
104 | + set_exception_handler('php_exception_handler'); |
|
105 | + |
|
106 | + /** |
|
107 | + * Setting of the PHP shutdown handling function |
|
108 | + */ |
|
109 | + register_shutdown_function('php_shudown_handler'); |
|
110 | 110 | |
111 | - //if user have some composer packages |
|
112 | - $LOGGER->debug('Check for composer autoload'); |
|
113 | - if(file_exists(VENDOR_PATH . 'autoload.php')){ |
|
114 | - $LOGGER->info('The composer autoload file exists include it'); |
|
115 | - require_once VENDOR_PATH . 'autoload.php'; |
|
116 | - } else{ |
|
117 | - $LOGGER->info('The composer autoload file does not exist skipping'); |
|
118 | - } |
|
111 | + //if user have some composer packages |
|
112 | + $LOGGER->debug('Check for composer autoload'); |
|
113 | + if(file_exists(VENDOR_PATH . 'autoload.php')){ |
|
114 | + $LOGGER->info('The composer autoload file exists include it'); |
|
115 | + require_once VENDOR_PATH . 'autoload.php'; |
|
116 | + } else{ |
|
117 | + $LOGGER->info('The composer autoload file does not exist skipping'); |
|
118 | + } |
|
119 | 119 | |
120 | - $LOGGER->debug('Begin to load the required resources'); |
|
121 | - |
|
122 | - /** |
|
123 | - * Load the EventInfo class file |
|
124 | - */ |
|
125 | - require_once CORE_CLASSES_PATH . 'EventInfo.php'; |
|
126 | - |
|
127 | - |
|
128 | - $BENCHMARK->mark('CONFIG_INIT_START'); |
|
129 | - /** |
|
130 | - * Load configurations and using the |
|
131 | - * static method "init()" to initialize the Config class . |
|
132 | - */ |
|
133 | - $CONFIG = & class_loader('Config', 'classes'); |
|
134 | - $CONFIG->init(); |
|
135 | - $BENCHMARK->mark('CONFIG_INIT_END'); |
|
136 | - |
|
137 | - $BENCHMARK->mark('MODULE_INIT_START'); |
|
138 | - /** |
|
139 | - * Load modules and using the |
|
140 | - * static method "init()" to initialize the Module class. |
|
141 | - */ |
|
142 | - $MODULE = & class_loader('Module', 'classes'); |
|
143 | - $MODULE->init(); |
|
144 | - $BENCHMARK->mark('MODULE_INIT_END'); |
|
145 | - |
|
146 | - $LOGGER->debug('Loading Base Controller ...'); |
|
147 | - /** |
|
148 | - * Include of the file containing the Base Controller class |
|
149 | - */ |
|
150 | - require_once CORE_CLASSES_PATH . 'Controller.php'; |
|
151 | - $LOGGER->info('Base Controller loaded successfully'); |
|
152 | - |
|
153 | - /** |
|
154 | - * Register controllers autoload function |
|
155 | - */ |
|
156 | - spl_autoload_register('autoload_controller'); |
|
157 | - |
|
158 | - /** |
|
159 | - * Loading Security class |
|
160 | - */ |
|
161 | - $SECURITY =& class_loader('Security', 'classes'); |
|
162 | - $SECURITY->checkWhiteListIpAccess(); |
|
120 | + $LOGGER->debug('Begin to load the required resources'); |
|
121 | + |
|
122 | + /** |
|
123 | + * Load the EventInfo class file |
|
124 | + */ |
|
125 | + require_once CORE_CLASSES_PATH . 'EventInfo.php'; |
|
126 | + |
|
127 | + |
|
128 | + $BENCHMARK->mark('CONFIG_INIT_START'); |
|
129 | + /** |
|
130 | + * Load configurations and using the |
|
131 | + * static method "init()" to initialize the Config class . |
|
132 | + */ |
|
133 | + $CONFIG = & class_loader('Config', 'classes'); |
|
134 | + $CONFIG->init(); |
|
135 | + $BENCHMARK->mark('CONFIG_INIT_END'); |
|
136 | + |
|
137 | + $BENCHMARK->mark('MODULE_INIT_START'); |
|
138 | + /** |
|
139 | + * Load modules and using the |
|
140 | + * static method "init()" to initialize the Module class. |
|
141 | + */ |
|
142 | + $MODULE = & class_loader('Module', 'classes'); |
|
143 | + $MODULE->init(); |
|
144 | + $BENCHMARK->mark('MODULE_INIT_END'); |
|
145 | + |
|
146 | + $LOGGER->debug('Loading Base Controller ...'); |
|
147 | + /** |
|
148 | + * Include of the file containing the Base Controller class |
|
149 | + */ |
|
150 | + require_once CORE_CLASSES_PATH . 'Controller.php'; |
|
151 | + $LOGGER->info('Base Controller loaded successfully'); |
|
152 | + |
|
153 | + /** |
|
154 | + * Register controllers autoload function |
|
155 | + */ |
|
156 | + spl_autoload_register('autoload_controller'); |
|
157 | + |
|
158 | + /** |
|
159 | + * Loading Security class |
|
160 | + */ |
|
161 | + $SECURITY =& class_loader('Security', 'classes'); |
|
162 | + $SECURITY->checkWhiteListIpAccess(); |
|
163 | 163 | |
164 | - /** |
|
165 | - * Loading Url class |
|
166 | - */ |
|
167 | - $URL =& class_loader('Url', 'classes'); |
|
164 | + /** |
|
165 | + * Loading Url class |
|
166 | + */ |
|
167 | + $URL =& class_loader('Url', 'classes'); |
|
168 | 168 | |
169 | - if(get_config('cache_enable', false)){ |
|
170 | - /** |
|
171 | - * Load Cache interface file |
|
172 | - */ |
|
173 | - require_once CORE_CLASSES_CACHE_PATH . 'CacheInterface.php'; |
|
174 | - $cacheHandler = get_config('cache_handler'); |
|
175 | - if(! $cacheHandler){ |
|
176 | - show_error('The cache feature is enabled in the configuration but the cache handler class is not set.'); |
|
177 | - } |
|
178 | - $CACHE = null; |
|
179 | - //first check if the cache handler is the system driver |
|
180 | - if(file_exists(CORE_CLASSES_CACHE_PATH . $cacheHandler . '.php')){ |
|
181 | - $CACHE =& class_loader($cacheHandler, 'classes/cache'); |
|
182 | - } else{ |
|
183 | - //it's not a system driver use user library |
|
184 | - $CACHE =& class_loader($cacheHandler); |
|
185 | - } |
|
186 | - //check if the page already cached |
|
187 | - if(! empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'get'){ |
|
188 | - $RESPONSE = & class_loader('Response', 'classes'); |
|
189 | - if ($RESPONSE->renderFinalPageFromCache($CACHE)){ |
|
190 | - return; |
|
191 | - } |
|
192 | - } |
|
193 | - } |
|
169 | + if(get_config('cache_enable', false)){ |
|
170 | + /** |
|
171 | + * Load Cache interface file |
|
172 | + */ |
|
173 | + require_once CORE_CLASSES_CACHE_PATH . 'CacheInterface.php'; |
|
174 | + $cacheHandler = get_config('cache_handler'); |
|
175 | + if(! $cacheHandler){ |
|
176 | + show_error('The cache feature is enabled in the configuration but the cache handler class is not set.'); |
|
177 | + } |
|
178 | + $CACHE = null; |
|
179 | + //first check if the cache handler is the system driver |
|
180 | + if(file_exists(CORE_CLASSES_CACHE_PATH . $cacheHandler . '.php')){ |
|
181 | + $CACHE =& class_loader($cacheHandler, 'classes/cache'); |
|
182 | + } else{ |
|
183 | + //it's not a system driver use user library |
|
184 | + $CACHE =& class_loader($cacheHandler); |
|
185 | + } |
|
186 | + //check if the page already cached |
|
187 | + if(! empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'get'){ |
|
188 | + $RESPONSE = & class_loader('Response', 'classes'); |
|
189 | + if ($RESPONSE->renderFinalPageFromCache($CACHE)){ |
|
190 | + return; |
|
191 | + } |
|
192 | + } |
|
193 | + } |
|
194 | 194 | |
195 | - //load model class |
|
196 | - require_once CORE_CLASSES_MODEL_PATH . 'Model.php'; |
|
195 | + //load model class |
|
196 | + require_once CORE_CLASSES_MODEL_PATH . 'Model.php'; |
|
197 | 197 | |
198 | - $LOGGER->info('Everything is OK load Router library and dispatch the request to the corresponding controller'); |
|
199 | - /** |
|
200 | - * Routing |
|
201 | - * instantiation of the "Router" class and request processing. |
|
202 | - */ |
|
203 | - $ROUTER = & class_loader('Router', 'classes'); |
|
204 | - $ROUTER->processRequest(); |
|
198 | + $LOGGER->info('Everything is OK load Router library and dispatch the request to the corresponding controller'); |
|
199 | + /** |
|
200 | + * Routing |
|
201 | + * instantiation of the "Router" class and request processing. |
|
202 | + */ |
|
203 | + $ROUTER = & class_loader('Router', 'classes'); |
|
204 | + $ROUTER->processRequest(); |
@@ -86,9 +86,9 @@ discard block |
||
86 | 86 | /** |
87 | 87 | * Verification of the PHP environment: minimum and maximum version |
88 | 88 | */ |
89 | - if (version_compare(phpversion(), TNH_REQUIRED_PHP_MIN_VERSION, '<')){ |
|
89 | + if (version_compare(phpversion(), TNH_REQUIRED_PHP_MIN_VERSION, '<')) { |
|
90 | 90 | show_error('Your PHP Version [' . phpversion() . '] is less than [' . TNH_REQUIRED_PHP_MIN_VERSION . '], please install a new version or update your PHP to the latest.', 'PHP Error environment'); |
91 | - } else if(version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')){ |
|
91 | + } else if (version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')) { |
|
92 | 92 | show_error('Your PHP Version [' . phpversion() . '] is greather than [' . TNH_REQUIRED_PHP_MAX_VERSION . '] please install a PHP version that is compatible.', 'PHP Error environment'); |
93 | 93 | } |
94 | 94 | $LOGGER->info('PHP version [' . phpversion() . '] is OK [REQUIRED MINIMUM: ' . TNH_REQUIRED_PHP_MIN_VERSION . ', REQUIRED MAXIMUM: ' . TNH_REQUIRED_PHP_MAX_VERSION . '], application can work without any issue'); |
@@ -110,10 +110,10 @@ discard block |
||
110 | 110 | |
111 | 111 | //if user have some composer packages |
112 | 112 | $LOGGER->debug('Check for composer autoload'); |
113 | - if(file_exists(VENDOR_PATH . 'autoload.php')){ |
|
113 | + if (file_exists(VENDOR_PATH . 'autoload.php')) { |
|
114 | 114 | $LOGGER->info('The composer autoload file exists include it'); |
115 | 115 | require_once VENDOR_PATH . 'autoload.php'; |
116 | - } else{ |
|
116 | + } else { |
|
117 | 117 | $LOGGER->info('The composer autoload file does not exist skipping'); |
118 | 118 | } |
119 | 119 | |
@@ -158,35 +158,35 @@ discard block |
||
158 | 158 | /** |
159 | 159 | * Loading Security class |
160 | 160 | */ |
161 | - $SECURITY =& class_loader('Security', 'classes'); |
|
161 | + $SECURITY = & class_loader('Security', 'classes'); |
|
162 | 162 | $SECURITY->checkWhiteListIpAccess(); |
163 | 163 | |
164 | 164 | /** |
165 | 165 | * Loading Url class |
166 | 166 | */ |
167 | - $URL =& class_loader('Url', 'classes'); |
|
167 | + $URL = & class_loader('Url', 'classes'); |
|
168 | 168 | |
169 | - if(get_config('cache_enable', false)){ |
|
169 | + if (get_config('cache_enable', false)) { |
|
170 | 170 | /** |
171 | 171 | * Load Cache interface file |
172 | 172 | */ |
173 | 173 | require_once CORE_CLASSES_CACHE_PATH . 'CacheInterface.php'; |
174 | 174 | $cacheHandler = get_config('cache_handler'); |
175 | - if(! $cacheHandler){ |
|
175 | + if (!$cacheHandler) { |
|
176 | 176 | show_error('The cache feature is enabled in the configuration but the cache handler class is not set.'); |
177 | 177 | } |
178 | 178 | $CACHE = null; |
179 | 179 | //first check if the cache handler is the system driver |
180 | - if(file_exists(CORE_CLASSES_CACHE_PATH . $cacheHandler . '.php')){ |
|
181 | - $CACHE =& class_loader($cacheHandler, 'classes/cache'); |
|
182 | - } else{ |
|
180 | + if (file_exists(CORE_CLASSES_CACHE_PATH . $cacheHandler . '.php')) { |
|
181 | + $CACHE = & class_loader($cacheHandler, 'classes/cache'); |
|
182 | + } else { |
|
183 | 183 | //it's not a system driver use user library |
184 | - $CACHE =& class_loader($cacheHandler); |
|
184 | + $CACHE = & class_loader($cacheHandler); |
|
185 | 185 | } |
186 | 186 | //check if the page already cached |
187 | - if(! empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'get'){ |
|
187 | + if (!empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'get') { |
|
188 | 188 | $RESPONSE = & class_loader('Response', 'classes'); |
189 | - if ($RESPONSE->renderFinalPageFromCache($CACHE)){ |
|
189 | + if ($RESPONSE->renderFinalPageFromCache($CACHE)) { |
|
190 | 190 | return; |
191 | 191 | } |
192 | 192 | } |
@@ -53,14 +53,14 @@ discard block |
||
53 | 53 | //put the first letter of class to upper case |
54 | 54 | $class = ucfirst($class); |
55 | 55 | static $classes = array(); |
56 | - if (isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log'){ |
|
56 | + if (isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log') { |
|
57 | 57 | return $classes[$class]; |
58 | 58 | } |
59 | 59 | $found = false; |
60 | 60 | foreach (array(ROOT_PATH, CORE_PATH) as $path) { |
61 | 61 | $file = $path . $dir . '/' . $class . '.php'; |
62 | - if (file_exists($file)){ |
|
63 | - if (class_exists($class, false) === false){ |
|
62 | + if (file_exists($file)) { |
|
63 | + if (class_exists($class, false) === false) { |
|
64 | 64 | require_once $file; |
65 | 65 | } |
66 | 66 | //already found |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | break; |
69 | 69 | } |
70 | 70 | } |
71 | - if (! $found){ |
|
71 | + if (!$found) { |
|
72 | 72 | //can't use show_error() at this time because some dependencies not yet loaded |
73 | 73 | set_http_status_header(503); |
74 | 74 | echo 'Cannot find the class [' . $class . ']'; |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | /* |
79 | 79 | TODO use the best method to get the Log instance |
80 | 80 | */ |
81 | - if ($class == 'Log'){ |
|
81 | + if ($class == 'Log') { |
|
82 | 82 | //can't use the instruction like "return new Log()" |
83 | 83 | //because we need return the reference instance of the loaded class. |
84 | 84 | $log = new Log(); |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | function & class_loaded($class = null){ |
104 | 104 | static $list = array(); |
105 | - if ($class !== null){ |
|
105 | + if ($class !== null) { |
|
106 | 106 | $list[strtolower($class)] = $class; |
107 | 107 | } |
108 | 108 | return $list; |
@@ -117,14 +117,14 @@ discard block |
||
117 | 117 | */ |
118 | 118 | function & load_configurations(array $overwrite_values = array()){ |
119 | 119 | static $config; |
120 | - if (empty($config)){ |
|
120 | + if (empty($config)) { |
|
121 | 121 | $file = CONFIG_PATH . 'config.php'; |
122 | 122 | $found = false; |
123 | - if (file_exists($file)){ |
|
123 | + if (file_exists($file)) { |
|
124 | 124 | require_once $file; |
125 | 125 | $found = true; |
126 | 126 | } |
127 | - if (! $found){ |
|
127 | + if (!$found) { |
|
128 | 128 | set_http_status_header(503); |
129 | 129 | echo 'Unable to find the configuration file [' . $file . ']'; |
130 | 130 | die(); |
@@ -144,9 +144,9 @@ discard block |
||
144 | 144 | * |
145 | 145 | * @return mixed the config value |
146 | 146 | */ |
147 | - function get_config($key, $default = null){ |
|
147 | + function get_config($key, $default = null) { |
|
148 | 148 | static $cfg; |
149 | - if (empty($cfg)){ |
|
149 | + if (empty($cfg)) { |
|
150 | 150 | $cfg[0] = & load_configurations(); |
151 | 151 | } |
152 | 152 | return array_key_exists($key, $cfg[0]) ? $cfg[0][$key] : $default; |
@@ -160,9 +160,9 @@ discard block |
||
160 | 160 | * |
161 | 161 | * @codeCoverageIgnore |
162 | 162 | */ |
163 | - function save_to_log($level, $message, $logger = null){ |
|
164 | - $log =& class_loader('Log', 'classes'); |
|
165 | - if ($logger){ |
|
163 | + function save_to_log($level, $message, $logger = null) { |
|
164 | + $log = & class_loader('Log', 'classes'); |
|
165 | + if ($logger) { |
|
166 | 166 | $log->setLogger($logger); |
167 | 167 | } |
168 | 168 | $log->writeLog($message, $level); |
@@ -175,8 +175,8 @@ discard block |
||
175 | 175 | * |
176 | 176 | * @codeCoverageIgnore |
177 | 177 | */ |
178 | - function set_http_status_header($code = 200, $text = null){ |
|
179 | - if (empty($text)){ |
|
178 | + function set_http_status_header($code = 200, $text = null) { |
|
179 | + if (empty($text)) { |
|
180 | 180 | $http_status = array( |
181 | 181 | 100 => 'Continue', |
182 | 182 | 101 => 'Switching Protocols', |
@@ -220,20 +220,20 @@ discard block |
||
220 | 220 | 504 => 'Gateway Timeout', |
221 | 221 | 505 => 'HTTP Version Not Supported', |
222 | 222 | ); |
223 | - if (isset($http_status[$code])){ |
|
223 | + if (isset($http_status[$code])) { |
|
224 | 224 | $text = $http_status[$code]; |
225 | 225 | } |
226 | - else{ |
|
226 | + else { |
|
227 | 227 | show_error('No HTTP status text found for your code please check it.'); |
228 | 228 | } |
229 | 229 | } |
230 | 230 | |
231 | - if (strpos(php_sapi_name(), 'cgi') === 0){ |
|
231 | + if (strpos(php_sapi_name(), 'cgi') === 0) { |
|
232 | 232 | header('Status: ' . $code . ' ' . $text, TRUE); |
233 | 233 | } |
234 | - else{ |
|
234 | + else { |
|
235 | 235 | $proto = 'HTTP/1.1'; |
236 | - if(isset($_SERVER['SERVER_PROTOCOL'])){ |
|
236 | + if (isset($_SERVER['SERVER_PROTOCOL'])) { |
|
237 | 237 | $proto = $_SERVER['SERVER_PROTOCOL']; |
238 | 238 | } |
239 | 239 | header($proto . ' ' . $code . ' ' . $text, TRUE, $code); |
@@ -249,13 +249,13 @@ discard block |
||
249 | 249 | * |
250 | 250 | * @codeCoverageIgnore |
251 | 251 | */ |
252 | - function show_error($msg, $title = 'error', $logging = true){ |
|
252 | + function show_error($msg, $title = 'error', $logging = true) { |
|
253 | 253 | $title = strtoupper($title); |
254 | 254 | $data = array(); |
255 | 255 | $data['error'] = $msg; |
256 | 256 | $data['title'] = $title; |
257 | - if ($logging){ |
|
258 | - save_to_log('error', '['.$title.'] '.strip_tags($msg), 'GLOBAL::ERROR'); |
|
257 | + if ($logging) { |
|
258 | + save_to_log('error', '[' . $title . '] ' . strip_tags($msg), 'GLOBAL::ERROR'); |
|
259 | 259 | } |
260 | 260 | $response = & class_loader('Response', 'classes'); |
261 | 261 | $response->sendError($data); |
@@ -269,18 +269,18 @@ discard block |
||
269 | 269 | * |
270 | 270 | * @return boolean true if the web server uses the https protocol, false if not. |
271 | 271 | */ |
272 | - function is_https(){ |
|
272 | + function is_https() { |
|
273 | 273 | /* |
274 | 274 | * some servers pass the "HTTPS" parameter in the server variable, |
275 | 275 | * if is the case, check if the value is "on", "true", "1". |
276 | 276 | */ |
277 | - if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'){ |
|
277 | + if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') { |
|
278 | 278 | return true; |
279 | 279 | } |
280 | - if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'){ |
|
280 | + if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
281 | 281 | return true; |
282 | 282 | } |
283 | - if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off'){ |
|
283 | + if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') { |
|
284 | 284 | return true; |
285 | 285 | } |
286 | 286 | return false; |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | * |
296 | 296 | * @return boolean true if is a valid URL address or false. |
297 | 297 | */ |
298 | - function is_url($url){ |
|
298 | + function is_url($url) { |
|
299 | 299 | return preg_match('/^(http|https|ftp):\/\/(.*)/', $url) == 1; |
300 | 300 | } |
301 | 301 | |
@@ -305,8 +305,8 @@ discard block |
||
305 | 305 | * @param string $controllerClass the controller class name to be loaded |
306 | 306 | * @codeCoverageIgnore |
307 | 307 | */ |
308 | - function autoload_controller($controllerClass){ |
|
309 | - if (file_exists($path = APPS_CONTROLLER_PATH . $controllerClass . '.php')){ |
|
308 | + function autoload_controller($controllerClass) { |
|
309 | + if (file_exists($path = APPS_CONTROLLER_PATH . $controllerClass . '.php')) { |
|
310 | 310 | require_once $path; |
311 | 311 | } |
312 | 312 | } |
@@ -320,11 +320,11 @@ discard block |
||
320 | 320 | * |
321 | 321 | * @return boolean |
322 | 322 | */ |
323 | - function php_exception_handler($ex){ |
|
324 | - if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){ |
|
325 | - show_error('An exception is occured in file '. $ex->getFile() .' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode()); |
|
323 | + function php_exception_handler($ex) { |
|
324 | + if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) { |
|
325 | + show_error('An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode()); |
|
326 | 326 | } |
327 | - else{ |
|
327 | + else { |
|
328 | 328 | save_to_log('error', 'An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception'); |
329 | 329 | } |
330 | 330 | return true; |
@@ -341,16 +341,16 @@ discard block |
||
341 | 341 | * |
342 | 342 | * @return boolean |
343 | 343 | */ |
344 | - function php_error_handler($errno , $errstr, $errfile , $errline){ |
|
344 | + function php_error_handler($errno, $errstr, $errfile, $errline) { |
|
345 | 345 | $isError = (((E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR | E_USER_ERROR) & $errno) === $errno); |
346 | - if ($isError){ |
|
346 | + if ($isError) { |
|
347 | 347 | set_http_status_header(500); |
348 | 348 | } |
349 | - if (! (error_reporting() & $errno)) { |
|
349 | + if (!(error_reporting() & $errno)) { |
|
350 | 350 | save_to_log('error', 'An error is occurred in the file ' . $errfile . ' at line ' . $errline . ' raison : ' . $errstr, 'PHP ERROR'); |
351 | 351 | return; |
352 | 352 | } |
353 | - if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){ |
|
353 | + if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) { |
|
354 | 354 | $errorType = 'error'; |
355 | 355 | switch ($errno) { |
356 | 356 | case E_USER_WARNING: |
@@ -360,9 +360,9 @@ discard block |
||
360 | 360 | $errorType = 'notice'; |
361 | 361 | break; |
362 | 362 | } |
363 | - show_error('An error is occurred in the file <b>' . $errfile . '</b> at line <b>' . $errline .'</b> raison : ' . $errstr, 'PHP ' . $errorType); |
|
363 | + show_error('An error is occurred in the file <b>' . $errfile . '</b> at line <b>' . $errline . '</b> raison : ' . $errstr, 'PHP ' . $errorType); |
|
364 | 364 | } |
365 | - if ($isError){ |
|
365 | + if ($isError) { |
|
366 | 366 | die(); |
367 | 367 | } |
368 | 368 | return true; |
@@ -372,10 +372,10 @@ discard block |
||
372 | 372 | * This function is used to run in shutdown situation of the script |
373 | 373 | * @codeCoverageIgnore |
374 | 374 | */ |
375 | - function php_shudown_handler(){ |
|
375 | + function php_shudown_handler() { |
|
376 | 376 | $lastError = error_get_last(); |
377 | 377 | if (isset($lastError) && |
378 | - ($lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))){ |
|
378 | + ($lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))) { |
|
379 | 379 | php_error_handler($lastError['type'], $lastError['message'], $lastError['file'], $lastError['line']); |
380 | 380 | } |
381 | 381 | } |
@@ -393,11 +393,11 @@ discard block |
||
393 | 393 | * |
394 | 394 | * @return string string of the HTML attribute. |
395 | 395 | */ |
396 | - function attributes_to_string(array $attributes){ |
|
396 | + function attributes_to_string(array $attributes) { |
|
397 | 397 | $str = ' '; |
398 | 398 | //we check that the array passed as an argument is not empty. |
399 | - if (! empty($attributes)){ |
|
400 | - foreach($attributes as $key => $value){ |
|
399 | + if (!empty($attributes)) { |
|
400 | + foreach ($attributes as $key => $value) { |
|
401 | 401 | $key = trim(htmlspecialchars($key)); |
402 | 402 | $value = trim(htmlspecialchars($value)); |
403 | 403 | /* |
@@ -407,10 +407,10 @@ discard block |
||
407 | 407 | * $attr = array('placeholder' => 'I am a "puple"') |
408 | 408 | * $str = attributes_to_string($attr); => placeholder = "I am a \"puple\"" |
409 | 409 | */ |
410 | - if ($value && strpos('"', $value) !== false){ |
|
410 | + if ($value && strpos('"', $value) !== false) { |
|
411 | 411 | $value = addslashes($value); |
412 | 412 | } |
413 | - $str .= $key.' = "'.$value.'" '; |
|
413 | + $str .= $key . ' = "' . $value . '" '; |
|
414 | 414 | } |
415 | 415 | } |
416 | 416 | //remove the space after using rtrim() |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | * |
427 | 427 | * @return string the stringfy value |
428 | 428 | */ |
429 | - function stringfy_vars($var){ |
|
429 | + function stringfy_vars($var) { |
|
430 | 430 | return print_r($var, true); |
431 | 431 | } |
432 | 432 | |
@@ -437,18 +437,18 @@ discard block |
||
437 | 437 | * |
438 | 438 | * @return mixed the sanitize value |
439 | 439 | */ |
440 | - function clean_input($str){ |
|
441 | - if (is_array($str)){ |
|
440 | + function clean_input($str) { |
|
441 | + if (is_array($str)) { |
|
442 | 442 | $str = array_map('clean_input', $str); |
443 | 443 | } |
444 | - else if (is_object($str)){ |
|
444 | + else if (is_object($str)) { |
|
445 | 445 | $obj = $str; |
446 | 446 | foreach ($str as $var => $value) { |
447 | 447 | $obj->$var = clean_input($value); |
448 | 448 | } |
449 | 449 | $str = $obj; |
450 | 450 | } |
451 | - else{ |
|
451 | + else { |
|
452 | 452 | $str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8'); |
453 | 453 | } |
454 | 454 | return $str; |
@@ -466,11 +466,11 @@ discard block |
||
466 | 466 | * |
467 | 467 | * @return string the string with the hidden part. |
468 | 468 | */ |
469 | - function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*'){ |
|
469 | + function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*') { |
|
470 | 470 | //get the string length |
471 | 471 | $len = strlen($str); |
472 | 472 | //if str is empty |
473 | - if ($len <= 0){ |
|
473 | + if ($len <= 0) { |
|
474 | 474 | return str_repeat($hiddenChar, 6); |
475 | 475 | } |
476 | 476 | //if the length is less than startCount and endCount |
@@ -478,14 +478,14 @@ discard block |
||
478 | 478 | //or startCount is negative or endCount is negative |
479 | 479 | //return the full string hidden |
480 | 480 | |
481 | - if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)){ |
|
481 | + if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)) { |
|
482 | 482 | return str_repeat($hiddenChar, $len); |
483 | 483 | } |
484 | 484 | //the start non hidden string |
485 | 485 | $startNonHiddenStr = substr($str, 0, $startCount); |
486 | 486 | //the end non hidden string |
487 | 487 | $endNonHiddenStr = null; |
488 | - if ($endCount > 0){ |
|
488 | + if ($endCount > 0) { |
|
489 | 489 | $endNonHiddenStr = substr($str, - $endCount); |
490 | 490 | } |
491 | 491 | //the hidden string |
@@ -498,40 +498,40 @@ discard block |
||
498 | 498 | * This function is used to set the initial session config regarding the configuration |
499 | 499 | * @codeCoverageIgnore |
500 | 500 | */ |
501 | - function set_session_config(){ |
|
501 | + function set_session_config() { |
|
502 | 502 | //$_SESSION is not available on cli mode |
503 | - if (! IS_CLI){ |
|
504 | - $logger =& class_loader('Log', 'classes'); |
|
503 | + if (!IS_CLI) { |
|
504 | + $logger = & class_loader('Log', 'classes'); |
|
505 | 505 | $logger->setLogger('PHPSession'); |
506 | 506 | //set session params |
507 | 507 | $sessionHandler = get_config('session_handler', 'files'); //the default is to store in the files |
508 | 508 | $sessionName = get_config('session_name'); |
509 | - if ($sessionName){ |
|
509 | + if ($sessionName) { |
|
510 | 510 | session_name($sessionName); |
511 | 511 | } |
512 | 512 | $logger->info('Session handler: ' . $sessionHandler); |
513 | 513 | $logger->info('Session name: ' . $sessionName); |
514 | 514 | |
515 | - if ($sessionHandler == 'files'){ |
|
515 | + if ($sessionHandler == 'files') { |
|
516 | 516 | $sessionSavePath = get_config('session_save_path'); |
517 | - if ($sessionSavePath){ |
|
518 | - if (! is_dir($sessionSavePath)){ |
|
517 | + if ($sessionSavePath) { |
|
518 | + if (!is_dir($sessionSavePath)) { |
|
519 | 519 | mkdir($sessionSavePath, 1773); |
520 | 520 | } |
521 | 521 | session_save_path($sessionSavePath); |
522 | 522 | $logger->info('Session save path: ' . $sessionSavePath); |
523 | 523 | } |
524 | 524 | } |
525 | - else if ($sessionHandler == 'database'){ |
|
525 | + else if ($sessionHandler == 'database') { |
|
526 | 526 | //load database session handle library |
527 | 527 | //Database Session handler Model |
528 | 528 | require_once CORE_CLASSES_MODEL_PATH . 'DBSessionHandlerModel.php'; |
529 | 529 | |
530 | - $DBS =& class_loader('DBSessionHandler', 'classes'); |
|
530 | + $DBS = & class_loader('DBSessionHandler', 'classes'); |
|
531 | 531 | session_set_save_handler($DBS, true); |
532 | 532 | $logger->info('session save path: ' . get_config('session_save_path')); |
533 | 533 | } |
534 | - else{ |
|
534 | + else { |
|
535 | 535 | show_error('Invalid session handler configuration'); |
536 | 536 | } |
537 | 537 | $lifetime = get_config('session_cookie_lifetime', 0); |
@@ -554,9 +554,9 @@ discard block |
||
554 | 554 | $logger->info('Session lifetime: ' . $lifetime); |
555 | 555 | $logger->info('Session cookie path: ' . $path); |
556 | 556 | $logger->info('Session domain: ' . $domain); |
557 | - $logger->info('Session is secure: ' . ($secure ? 'TRUE':'FALSE')); |
|
557 | + $logger->info('Session is secure: ' . ($secure ? 'TRUE' : 'FALSE')); |
|
558 | 558 | |
559 | - if ((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()){ |
|
559 | + if ((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()) { |
|
560 | 560 | $logger->info('Session not yet start, start it now'); |
561 | 561 | session_start(); |
562 | 562 | } |
@@ -222,16 +222,14 @@ discard block |
||
222 | 222 | ); |
223 | 223 | if (isset($http_status[$code])){ |
224 | 224 | $text = $http_status[$code]; |
225 | - } |
|
226 | - else{ |
|
225 | + } else{ |
|
227 | 226 | show_error('No HTTP status text found for your code please check it.'); |
228 | 227 | } |
229 | 228 | } |
230 | 229 | |
231 | 230 | if (strpos(php_sapi_name(), 'cgi') === 0){ |
232 | 231 | header('Status: ' . $code . ' ' . $text, TRUE); |
233 | - } |
|
234 | - else{ |
|
232 | + } else{ |
|
235 | 233 | $proto = 'HTTP/1.1'; |
236 | 234 | if(isset($_SERVER['SERVER_PROTOCOL'])){ |
237 | 235 | $proto = $_SERVER['SERVER_PROTOCOL']; |
@@ -323,8 +321,7 @@ discard block |
||
323 | 321 | function php_exception_handler($ex){ |
324 | 322 | if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){ |
325 | 323 | show_error('An exception is occured in file '. $ex->getFile() .' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode()); |
326 | - } |
|
327 | - else{ |
|
324 | + } else{ |
|
328 | 325 | save_to_log('error', 'An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception'); |
329 | 326 | } |
330 | 327 | return true; |
@@ -440,15 +437,13 @@ discard block |
||
440 | 437 | function clean_input($str){ |
441 | 438 | if (is_array($str)){ |
442 | 439 | $str = array_map('clean_input', $str); |
443 | - } |
|
444 | - else if (is_object($str)){ |
|
440 | + } else if (is_object($str)){ |
|
445 | 441 | $obj = $str; |
446 | 442 | foreach ($str as $var => $value) { |
447 | 443 | $obj->$var = clean_input($value); |
448 | 444 | } |
449 | 445 | $str = $obj; |
450 | - } |
|
451 | - else{ |
|
446 | + } else{ |
|
452 | 447 | $str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8'); |
453 | 448 | } |
454 | 449 | return $str; |
@@ -521,8 +516,7 @@ discard block |
||
521 | 516 | session_save_path($sessionSavePath); |
522 | 517 | $logger->info('Session save path: ' . $sessionSavePath); |
523 | 518 | } |
524 | - } |
|
525 | - else if ($sessionHandler == 'database'){ |
|
519 | + } else if ($sessionHandler == 'database'){ |
|
526 | 520 | //load database session handle library |
527 | 521 | //Database Session handler Model |
528 | 522 | require_once CORE_CLASSES_MODEL_PATH . 'DBSessionHandlerModel.php'; |
@@ -530,8 +524,7 @@ discard block |
||
530 | 524 | $DBS =& class_loader('DBSessionHandler', 'classes'); |
531 | 525 | session_set_save_handler($DBS, true); |
532 | 526 | $logger->info('session save path: ' . get_config('session_save_path')); |
533 | - } |
|
534 | - else{ |
|
527 | + } else{ |
|
535 | 528 | show_error('Invalid session handler configuration'); |
536 | 529 | } |
537 | 530 | $lifetime = get_config('session_cookie_lifetime', 0); |
@@ -1,9 +1,9 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | defined('ROOT_PATH') || exit('Access denied'); |
3 | - /** |
|
4 | - * Form validation language message (English) |
|
5 | - */ |
|
6 | - $lang['fv_required'] = 'Field %1 is required.'; |
|
3 | + /** |
|
4 | + * Form validation language message (English) |
|
5 | + */ |
|
6 | + $lang['fv_required'] = 'Field %1 is required.'; |
|
7 | 7 | $lang['fv_min_length'] = 'Field %1 must contain at least %2 characters.'; |
8 | 8 | $lang['fv_max_length'] = 'Field %1 must contain at most %2 characters.'; |
9 | 9 | $lang['fv_exact_length'] = 'Field %1 must contain exactly %2 characters.'; |
@@ -14,8 +14,8 @@ discard block |
||
14 | 14 | $lang['fv_not_equal_post_key'] = 'Field %1 must not be the same as field %2.'; |
15 | 15 | $lang['fv_not_equal_string'] = 'Field %1 must not contain the value %2.'; |
16 | 16 | $lang['fv_depends'] = 'Field %1 depends on field %2 which is not valid.'; |
17 | - $lang['fv_is_unique'] = 'The value of field %1 already exists.'; |
|
18 | - $lang['fv_is_unique_update'] = 'The value of field %1 already exists for another record.'; |
|
17 | + $lang['fv_is_unique'] = 'The value of field %1 already exists.'; |
|
18 | + $lang['fv_is_unique_update'] = 'The value of field %1 already exists for another record.'; |
|
19 | 19 | $lang['fv_exists'] = 'The value of the field %1 does not exist.'; |
20 | 20 | $lang['fv_regex'] = 'The value of the field %1 does not use the correct format.'; |
21 | 21 | $lang['fv_in_list'] = 'The value of field %1 must be one of the list (%2).'; |
@@ -3,7 +3,7 @@ |
||
3 | 3 | /** |
4 | 4 | * File upload language messages (English) |
5 | 5 | */ |
6 | - $lang['fu_upload_err_ini_size'] = 'The uploaded file exceeds the upload_max_filesize directive in php.ini.'; |
|
6 | + $lang['fu_upload_err_ini_size'] = 'The uploaded file exceeds the upload_max_filesize directive in php.ini.'; |
|
7 | 7 | $lang['fu_upload_err_form_size'] = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.'; |
8 | 8 | $lang['fu_upload_err_partial'] = 'The uploaded file was only partially uploaded.'; |
9 | 9 | $lang['fu_upload_err_no_file'] = 'No file was choosed. Please select one.'; |