1 | <?php |
||
52 | class PMF_Utils |
||
53 | { |
||
54 | /** |
||
55 | * Get the content at the given URL using an HTTP GET call. |
||
56 | * |
||
57 | * @param string $url URL of the content |
||
58 | * |
||
59 | * @return string |
||
60 | */ |
||
61 | public static function getHTTPContent($url) |
||
92 | |||
93 | /** |
||
94 | * Returns date from out of time. |
||
95 | * |
||
96 | * @return string |
||
97 | */ |
||
98 | public static function getNeverExpireDate() |
||
105 | |||
106 | /** |
||
107 | * Returns a phpMyFAQ date. |
||
108 | * |
||
109 | * @param int $unixTime Unix timestamp |
||
110 | * |
||
111 | * @return string |
||
112 | */ |
||
113 | public static function getPMFDate($unixTime = null) |
||
122 | |||
123 | /** |
||
124 | * Check if a given string could be a language. |
||
125 | * |
||
126 | * @param string $lang Language |
||
127 | * |
||
128 | * @return bool |
||
129 | */ |
||
130 | public static function isLanguage($lang) |
||
134 | |||
135 | /** |
||
136 | * Checks if a date is a phpMyFAQ valid date. |
||
137 | * |
||
138 | * @param int $date Date |
||
139 | * |
||
140 | * @return int |
||
141 | */ |
||
142 | public static function isLikeOnPMFDate($date) |
||
157 | |||
158 | /** |
||
159 | * Shortens a string for a given number of words. |
||
160 | * |
||
161 | * @param string $str String |
||
162 | * @param int $char Characters |
||
163 | * |
||
164 | * @return string |
||
165 | * |
||
166 | * @todo This function doesn't work with Chinese, Japanese and Korean |
||
167 | * because they don't have spaces as word delimiters |
||
168 | */ |
||
169 | public static function makeShorterText($str, $char) |
||
170 | { |
||
171 | |||
172 | $str = PMF_String::preg_replace('/\s+/u', ' ', $str); |
||
173 | $arrStr = explode(' ', $str); |
||
174 | $shortStr = ''; |
||
175 | $num = count($arrStr); |
||
176 | |||
177 | if ($num > $char) { |
||
178 | for ($j = 0; $j <= $char; ++$j) { |
||
179 | $shortStr .= $arrStr[$j].' '; |
||
180 | } |
||
181 | $shortStr .= '...'; |
||
182 | } else { |
||
183 | $shortStr = $str; |
||
184 | } |
||
185 | |||
186 | return $shortStr; |
||
187 | } |
||
188 | |||
189 | /** |
||
190 | * Resolves the PMF markers like e.g. %sitename%. |
||
191 | * |
||
192 | * @param string $text Text contains PMF markers |
||
193 | * @param PMF_Configuration $config |
||
194 | * |
||
195 | * @return string |
||
196 | */ |
||
197 | public static function resolveMarkers($text, PMF_Configuration $config) |
||
211 | |||
212 | /** |
||
213 | * Shuffles an associative array without losing key associations. |
||
214 | * |
||
215 | * @param array $data Array of data |
||
216 | * |
||
217 | * @return array $shuffled_data Array of shuffled data |
||
218 | */ |
||
219 | public static function shuffleData($data) |
||
237 | |||
238 | /** |
||
239 | * This method chops a string. |
||
240 | * |
||
241 | * @param string $string String to chop |
||
242 | * @param int $words Number of words |
||
243 | * |
||
244 | * @return string |
||
245 | */ |
||
246 | public static function chopString($string, $words) |
||
260 | |||
261 | /** |
||
262 | * Adds a highlighted word to a string. |
||
263 | * |
||
264 | * @param string $string String |
||
265 | * @param string $highlight Given word for highlighting |
||
266 | * |
||
267 | * @return string |
||
268 | */ |
||
269 | public static function setHighlightedString($string, $highlight) |
||
299 | |||
300 | /** |
||
301 | * Callback function for filtering HTML from URLs and images. |
||
302 | * |
||
303 | * @param array $matches Array of matches from regex pattern |
||
304 | * |
||
305 | * @return string |
||
306 | */ |
||
307 | public static function highlightNoLinks(Array $matches) |
||
323 | |||
324 | /** |
||
325 | * Tries to detect if a string could be a HTML element |
||
326 | * |
||
327 | * @param $string |
||
328 | * |
||
329 | * @return bool |
||
330 | */ |
||
331 | public static function isForbiddenElement($string) |
||
345 | |||
346 | /** |
||
347 | * debug_backtrace() wrapper function. |
||
348 | * |
||
349 | * @param $string |
||
350 | * |
||
351 | * @return string |
||
352 | */ |
||
353 | public static function debug($string) |
||
371 | |||
372 | /** |
||
373 | * Parses a given string and convert all the URLs into links. |
||
374 | * |
||
375 | * @param string $string |
||
376 | * |
||
377 | * @return string |
||
378 | */ |
||
379 | public static function parseUrl($string) |
||
394 | |||
395 | /** |
||
396 | * Moves given key of an array to the top |
||
397 | * |
||
398 | * @param array $array |
||
399 | * @param string $key |
||
400 | */ |
||
401 | public static function moveToTop(&$array, $key) |
||
407 | } |
||
408 |
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.