@@ -32,9 +32,9 @@ discard block |
||
| 32 | 32 | * |
| 33 | 33 | * @param string $text Text to display |
| 34 | 34 | */ |
| 35 | - static public function promptAlert($text){ |
|
| 35 | + static public function promptAlert($text) { |
|
| 36 | 36 | echo '<script>'; |
| 37 | - echo 'alert("',fw\Filter::escapeHtml($text),'")'; |
|
| 37 | + echo 'alert("', fw\Filter::escapeHtml($text), '")'; |
|
| 38 | 38 | echo '</script>'; |
| 39 | 39 | } |
| 40 | 40 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @return float Result of the safe division |
| 48 | 48 | */ |
| 49 | 49 | public static function safeDivision($num, $denom, $default = 0) { |
| 50 | - if($denom && $denom!=0){ |
|
| 50 | + if ($denom && $denom != 0) { |
|
| 51 | 51 | return $num / $denom; |
| 52 | 52 | } |
| 53 | 53 | return $default; |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * @param float $default Default value if denominator null or 0 |
| 62 | 62 | * @return float Percentage |
| 63 | 63 | */ |
| 64 | - public static function getPercentage($num, $denom, $default = 0){ |
|
| 64 | + public static function getPercentage($num, $denom, $default = 0) { |
|
| 65 | 65 | return 100 * self::safeDivision($num, $denom, $default); |
| 66 | 66 | } |
| 67 | 67 | |
@@ -72,8 +72,8 @@ discard block |
||
| 72 | 72 | * @param int $target The final max width/height |
| 73 | 73 | * @return array array of ($width, $height). One of them must be $target |
| 74 | 74 | */ |
| 75 | - static public function getResizedImageSize($file, $target=25){ |
|
| 76 | - list($width, $height, , ) = getimagesize($file); |
|
| 75 | + static public function getResizedImageSize($file, $target = 25) { |
|
| 76 | + list($width, $height,,) = getimagesize($file); |
|
| 77 | 77 | $max = max($width, $height); |
| 78 | 78 | $rapp = $target / $max; |
| 79 | 79 | $width = intval($rapp * $width); |
@@ -103,21 +103,21 @@ discard block |
||
| 103 | 103 | * @param int $length Length of the token, default to 32 |
| 104 | 104 | * @return string Random token |
| 105 | 105 | */ |
| 106 | - public static function generateRandomToken($length=32) { |
|
| 106 | + public static function generateRandomToken($length = 32) { |
|
| 107 | 107 | $chars = str_split('abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'); |
| 108 | 108 | $len_chars = count($chars); |
| 109 | 109 | $token = ''; |
| 110 | 110 | |
| 111 | 111 | for ($i = 0; $i < $length; $i++) |
| 112 | - $token .= $chars[ mt_rand(0, $len_chars - 1) ]; |
|
| 112 | + $token .= $chars[mt_rand(0, $len_chars - 1)]; |
|
| 113 | 113 | |
| 114 | 114 | # Number of 32 char chunks |
| 115 | - $chunks = ceil( strlen($token) / 32 ); |
|
| 115 | + $chunks = ceil(strlen($token) / 32); |
|
| 116 | 116 | $md5token = ''; |
| 117 | 117 | |
| 118 | 118 | # Run each chunk through md5 |
| 119 | - for ( $i=1; $i<=$chunks; $i++ ) |
|
| 120 | - $md5token .= md5( substr($token, $i * 32 - 32, 32) ); |
|
| 119 | + for ($i = 1; $i <= $chunks; $i++) |
|
| 120 | + $md5token .= md5(substr($token, $i * 32 - 32, 32)); |
|
| 121 | 121 | |
| 122 | 122 | # Trim the token |
| 123 | 123 | return substr($md5token, 0, $length); |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | */ |
| 131 | 131 | protected static function getBase64EncryptionKey() { |
| 132 | 132 | $key = 'STANDARDKEYIFNOSERVER'; |
| 133 | - if(!empty(Filter::server('SERVER_NAME')) && !empty(Filter::server('SERVER_SOFTWARE'))) |
|
| 133 | + if (!empty(Filter::server('SERVER_NAME')) && !empty(Filter::server('SERVER_SOFTWARE'))) |
|
| 134 | 134 | $key = md5(Filter::server('SERVER_NAME').Filter::server('SERVER_SOFTWARE')); |
| 135 | 135 | |
| 136 | 136 | return $key; |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | * @param string $data Text to encrypt |
| 144 | 144 | * @return string Encrypted and encoded text |
| 145 | 145 | */ |
| 146 | - public static function encryptToSafeBase64($data){ |
|
| 146 | + public static function encryptToSafeBase64($data) { |
|
| 147 | 147 | $nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
| 148 | 148 | $id = sodium_crypto_secretbox($data, $nonce, self::getBase64EncryptionKey()); |
| 149 | 149 | $encrypted = base64_encode($nonce.$id); |
@@ -163,12 +163,12 @@ discard block |
||
| 163 | 163 | * @param string $encrypted Text to decrypt |
| 164 | 164 | * @return string Decrypted text |
| 165 | 165 | */ |
| 166 | - public static function decryptFromSafeBase64($encrypted){ |
|
| 166 | + public static function decryptFromSafeBase64($encrypted) { |
|
| 167 | 167 | $encrypted = str_replace('-', '+', $encrypted); |
| 168 | 168 | $encrypted = str_replace('_', '/', $encrypted); |
| 169 | 169 | $encrypted = str_replace('*', '=', $encrypted); |
| 170 | 170 | $encrypted = base64_decode($encrypted); |
| 171 | - if($encrypted === false) |
|
| 171 | + if ($encrypted === false) |
|
| 172 | 172 | throw new \InvalidArgumentException('The encrypted value is not in correct base64 format.'); |
| 173 | 173 | |
| 174 | 174 | if (mb_strlen($encrypted, '8bit') < (SODIUM_CRYPTO_SECRETBOX_NONCEBYTES + SODIUM_CRYPTO_SECRETBOX_MACBYTES)) |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | |
| 180 | 180 | $decrypted = sodium_crypto_secretbox_open($ciphertext, $nonce, self::getBase64EncryptionKey()); |
| 181 | 181 | |
| 182 | - if($decrypted === false) { |
|
| 182 | + if ($decrypted === false) { |
|
| 183 | 183 | throw new \InvalidArgumentException('The message has been tampered with in transit.'); |
| 184 | 184 | } |
| 185 | 185 | |
@@ -194,9 +194,9 @@ discard block |
||
| 194 | 194 | * @param string $string Filesystem encoded string to encode |
| 195 | 195 | * @return string UTF-8 encoded string |
| 196 | 196 | */ |
| 197 | - public static function encodeFileSystemToUtf8($string){ |
|
| 197 | + public static function encodeFileSystemToUtf8($string) { |
|
| 198 | 198 | if (strtoupper(substr(php_uname('s'), 0, 7)) === 'WINDOWS') { |
| 199 | - return iconv('cp1252', 'utf-8//IGNORE',$string); |
|
| 199 | + return iconv('cp1252', 'utf-8//IGNORE', $string); |
|
| 200 | 200 | } |
| 201 | 201 | return $string; |
| 202 | 202 | } |
@@ -207,9 +207,9 @@ discard block |
||
| 207 | 207 | * @param string $string UTF-8 encoded string to encode |
| 208 | 208 | * @return string Filesystem encoded string |
| 209 | 209 | */ |
| 210 | - public static function encodeUtf8ToFileSystem($string){ |
|
| 210 | + public static function encodeUtf8ToFileSystem($string) { |
|
| 211 | 211 | if (preg_match('//u', $string) && strtoupper(substr(php_uname('s'), 0, 7)) === 'WINDOWS') { |
| 212 | - return iconv('utf-8', 'cp1252//IGNORE' , $string); |
|
| 212 | + return iconv('utf-8', 'cp1252//IGNORE', $string); |
|
| 213 | 213 | } |
| 214 | 214 | return $string; |
| 215 | 215 | } |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | * @return boolean True if path valid |
| 223 | 223 | */ |
| 224 | 224 | public static function isValidPath($filename, $acceptfolder = FALSE) { |
| 225 | - if(strpbrk($filename, $acceptfolder ? '?%*:|"<>' : '\\/?%*:|"<>') === FALSE) return true; |
|
| 225 | + if (strpbrk($filename, $acceptfolder ? '?%*:|"<>' : '\\/?%*:|"<>') === FALSE) return true; |
|
| 226 | 226 | return false; |
| 227 | 227 | } |
| 228 | 228 | |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | * @return array Array of month short names |
| 235 | 235 | */ |
| 236 | 236 | public static function getCalendarShortMonths($calendarId = 0) { |
| 237 | - if(!isset(self::$calendarShortMonths[$calendarId])) { |
|
| 237 | + if (!isset(self::$calendarShortMonths[$calendarId])) { |
|
| 238 | 238 | $calendar_info = cal_info($calendarId); |
| 239 | 239 | self::$calendarShortMonths[$calendarId] = $calendar_info['abbrevmonths']; |
| 240 | 240 | } |
@@ -247,8 +247,8 @@ discard block |
||
| 247 | 247 | * @param int $sosa Sosa number |
| 248 | 248 | * @return number |
| 249 | 249 | */ |
| 250 | - public static function getGeneration($sosa){ |
|
| 251 | - return(int)log($sosa, 2)+1; |
|
| 250 | + public static function getGeneration($sosa) { |
|
| 251 | + return(int)log($sosa, 2) + 1; |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | |