1 | <?php |
||
19 | class Functions { |
||
20 | |||
21 | /** |
||
22 | * This array contains the cached short month names, based on the cal_info functions. |
||
23 | * Retrieves the abbrevmonths values of months: Jan, Feb, Mar... |
||
24 | * |
||
25 | * @uses cal_info |
||
26 | * @var array $calendarShortMonths Cached array of abbreviated short month names |
||
27 | */ |
||
28 | private static $calendarShortMonths = array(); |
||
29 | |||
30 | /** |
||
31 | * Debug tool: prompt a Javascript pop-up with a text |
||
32 | * |
||
33 | * @param string $text Text to display |
||
34 | */ |
||
35 | static public function promptAlert($text){ |
||
40 | |||
41 | /** |
||
42 | * Return the result of a division, and a default value if denomintaor is 0 |
||
43 | * |
||
44 | * @param integer $num Numerator |
||
45 | * @param integer $denom Denominator |
||
46 | * @param float $default Default value if denominator null or 0 |
||
47 | * @return float Result of the safe division |
||
48 | */ |
||
49 | public static function safeDivision($num, $denom, $default = 0) { |
||
55 | |||
56 | /** |
||
57 | * Returns the percentage of two numbers |
||
58 | * |
||
59 | * @param int $num Numerator |
||
60 | * @param int $denom Denominator |
||
61 | * @param float $default Default value if denominator null or 0 |
||
62 | * @return float Percentage |
||
63 | */ |
||
64 | public static function getPercentage($num, $denom, $default = 0){ |
||
67 | |||
68 | /** |
||
69 | * Get width and heigth of an image resized in order fit a target size. |
||
70 | * |
||
71 | * @param string $file The image to resize |
||
72 | * @param int $target The final max width/height |
||
73 | * @return array array of ($width, $height). One of them must be $target |
||
74 | */ |
||
75 | static public function getResizedImageSize($file, $target=25){ |
||
83 | |||
84 | |||
85 | /** |
||
86 | * Checks if a table exist in the DB schema |
||
87 | * |
||
88 | * @param string $table Name of the table to look for |
||
89 | * @return boolean Does the table exist |
||
90 | */ |
||
91 | public static function doesTableExist($table) { |
||
99 | |||
100 | /** |
||
101 | * Returns a randomy generated token of a given size |
||
102 | * |
||
103 | * @param int $length Length of the token, default to 32 |
||
104 | * @return string Random token |
||
105 | */ |
||
106 | public static function generateRandomToken($length=32) { |
||
125 | |||
126 | /** |
||
127 | * Generate the key used by the encryption to safe base64 functions. |
||
128 | * |
||
129 | * @return string Encryption key |
||
130 | */ |
||
131 | protected static function getBase64EncryptionKey() { |
||
138 | |||
139 | /** |
||
140 | * Encrypt a text, and encode it to base64 compatible with URL use |
||
141 | * (no +, no /, no =) |
||
142 | * |
||
143 | * @param string $data Text to encrypt |
||
144 | * @return string Encrypted and encoded text |
||
145 | */ |
||
146 | public static function encryptToSafeBase64($data){ |
||
159 | |||
160 | /** |
||
161 | * Decode and encrypt a text from base64 compatible with URL use |
||
162 | * |
||
163 | * @param string $encrypted Text to decrypt |
||
164 | * @return string Decrypted text |
||
165 | */ |
||
166 | public static function decryptFromSafeBase64($encrypted){ |
||
190 | |||
191 | /** |
||
192 | * Encode a string from the file system encoding to UTF-8 (if necessary) |
||
193 | * |
||
194 | * @param string $string Filesystem encoded string to encode |
||
195 | * @return string UTF-8 encoded string |
||
196 | */ |
||
197 | public static function encodeFileSystemToUtf8($string){ |
||
203 | |||
204 | /** |
||
205 | * Encode a string from UTF-8 to the file system encoding (if necessary) |
||
206 | * |
||
207 | * @param string $string UTF-8 encoded string to encode |
||
208 | * @return string Filesystem encoded string |
||
209 | */ |
||
210 | public static function encodeUtf8ToFileSystem($string){ |
||
216 | |||
217 | /** |
||
218 | * Check whether a path is under a valid form. |
||
219 | * |
||
220 | * @param string $filename Filename path to check |
||
221 | * @param boolean $acceptfolder Should folders be accepted? |
||
222 | * @return boolean True if path valid |
||
223 | */ |
||
224 | public static function isValidPath($filename, $acceptfolder = FALSE) { |
||
228 | |||
229 | /** |
||
230 | * Return short names for the months of the specific calendar. |
||
231 | * |
||
232 | * @see \cal_info() |
||
233 | * @param integer $calendarId Calendar ID (according to PHP cal_info) |
||
234 | * @return array Array of month short names |
||
235 | */ |
||
236 | public static function getCalendarShortMonths($calendarId = 0) { |
||
243 | |||
244 | /** |
||
245 | * Returns the generation associated with a Sosa number |
||
246 | * |
||
247 | * @param int $sosa Sosa number |
||
248 | * @return number |
||
249 | */ |
||
250 | public static function getGeneration($sosa){ |
||
253 | |||
254 | |||
255 | |||
256 | |||
257 | /** |
||
258 | * Returns whether the image type is supported by the system, and if so, return the standardised type |
||
259 | * |
||
260 | * @param string $reqtype Extension to test |
||
261 | * @return boolean|string Is supported? |
||
262 | */ |
||
263 | public static function isImageTypeSupported($reqtype) { |
||
279 | |||
280 | } |
||
281 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.