[1] | 1 | <?php |
---|
| 2 | /** |
---|
| 3 | * Utilities.inc.php |
---|
| 4 | * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information |
---|
| 5 | */ |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | /** |
---|
| 9 | * Print variable dump. |
---|
| 10 | * |
---|
| 11 | * @param mixed $var Variable to dump. |
---|
| 12 | * @param bool $display Hide the dump in HTML comments? |
---|
| 13 | * @param bool $var_dump Use var_dump instead of print_r. |
---|
| 14 | */ |
---|
| 15 | function dump($var, $display=false, $var_dump=false) |
---|
| 16 | { |
---|
| 17 | echo $display ? "\n<br /><pre>\n" : "\n\n\n<!--\n"; |
---|
| 18 | if ($var_dump) { |
---|
| 19 | var_dump($var); |
---|
| 20 | } else { |
---|
| 21 | print_r($var); |
---|
| 22 | } |
---|
| 23 | echo $display ? "\n</pre><br />\n" : "\n-->\n\n\n"; |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | /** |
---|
| 27 | * Return dump as variable. |
---|
| 28 | * |
---|
| 29 | * @param mixed $var Variable to dump. |
---|
| 30 | * @return string Dump of var. |
---|
| 31 | */ |
---|
| 32 | function getDump($var) |
---|
| 33 | { |
---|
| 34 | ob_start(); |
---|
| 35 | print_r($var); |
---|
| 36 | $d = ob_get_contents(); |
---|
| 37 | ob_end_clean(); |
---|
| 38 | return $d; |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | /** |
---|
| 42 | * Return dump as cleaned text. Useful for dumping data into emails. |
---|
| 43 | * |
---|
| 44 | * @param mixed $var Variable to dump. |
---|
| 45 | * @return string Dump of var. |
---|
| 46 | */ |
---|
| 47 | function fancyDump($var, $indent='') |
---|
| 48 | { |
---|
| 49 | $output = ''; |
---|
| 50 | if (is_array($var)) { |
---|
| 51 | foreach ($var as $k=>$v) { |
---|
| 52 | $k = ucfirst(strtolower(str_replace(array('_', ' '), ' ', $k))); |
---|
| 53 | if (is_array($v)) { |
---|
| 54 | $output .= sprintf("\n%s%s: %s\n", $indent, $k, fancyDump($v, $indent . $indent)); |
---|
| 55 | } else { |
---|
| 56 | $output .= sprintf("%s%s: %s\n", $indent, $k, $v); |
---|
| 57 | } |
---|
| 58 | } |
---|
| 59 | } else { |
---|
| 60 | $output .= sprintf("%s%s\n", $indent, $var); |
---|
| 61 | } |
---|
| 62 | return $output; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | /** |
---|
[42] | 66 | * Returns text with appropriate html translations. |
---|
[1] | 67 | * |
---|
| 68 | * @param string $txt Text to clean. |
---|
[42] | 69 | * @param bool $preserve_html If set to true, oTxt will not translage <, >, ", or ' |
---|
[1] | 70 | * characters into HTML entities. This allows HTML to pass |
---|
| 71 | * through unmunged. |
---|
| 72 | * @return string Cleaned text. |
---|
| 73 | */ |
---|
| 74 | function oTxt($txt, $preserve_html=false) |
---|
| 75 | { |
---|
[136] | 76 | $app =& App::getInstance(); |
---|
| 77 | |
---|
[1] | 78 | $search = array(); |
---|
| 79 | $replace = array(); |
---|
| 80 | |
---|
| 81 | // Make converted ampersand entities into normal ampersands (they will be done manually later) to retain HTML entities. |
---|
| 82 | $search['retain_ampersand'] = '/&/'; |
---|
| 83 | $replace['retain_ampersand'] = '&'; |
---|
| 84 | |
---|
| 85 | if ($preserve_html) { |
---|
| 86 | // Convert characters that must remain non-entities for displaying HTML. |
---|
| 87 | $search['retain_left_angle'] = '/</'; |
---|
| 88 | $replace['retain_left_angle'] = '<'; |
---|
[42] | 89 | |
---|
[1] | 90 | $search['retain_right_angle'] = '/>/'; |
---|
| 91 | $replace['retain_right_angle'] = '>'; |
---|
[42] | 92 | |
---|
[1] | 93 | $search['retain_single_quote'] = '/'/'; |
---|
| 94 | $replace['retain_single_quote'] = "'"; |
---|
[42] | 95 | |
---|
[1] | 96 | $search['retain_double_quote'] = '/"/'; |
---|
| 97 | $replace['retain_double_quote'] = '"'; |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | // & becomes &. Exclude any occurance where the & is followed by a alphanum or unicode caracter. |
---|
[32] | 101 | $search['ampersand'] = '/&(?![\w\d#]{1,10};)/'; |
---|
| 102 | $replace['ampersand'] = '&'; |
---|
[1] | 103 | |
---|
[136] | 104 | return preg_replace($search, $replace, htmlentities($txt, ENT_QUOTES, $app->getParam('character_set'))); |
---|
[1] | 105 | } |
---|
| 106 | |
---|
| 107 | /** |
---|
[103] | 108 | * Returns text with stylistic modifications. Warning: this will break some HTML attibutes! |
---|
[111] | 109 | * TODO: Allow a string such as this to be passted: <a href="javascript:openPopup('/foo/bar.php')">Click here</a> |
---|
[1] | 110 | * |
---|
| 111 | * @param string $txt Text to clean. |
---|
| 112 | * @return string Cleaned text. |
---|
| 113 | */ |
---|
| 114 | function fancyTxt($txt) |
---|
| 115 | { |
---|
[103] | 116 | $search = array(); |
---|
| 117 | $replace = array(); |
---|
| 118 | |
---|
| 119 | // "double quoted text" becomes “double quoted text” |
---|
| 120 | $search['double_quotes'] = '/(^|[^\w=])(?:"|"|"|"|“)([^"]+?)(?:"|"|"|"|”)([^\w]|$)/ms'; // " is the same as " and " and " |
---|
| 121 | $replace['double_quotes'] = '$1“$2”$3'; |
---|
| 122 | |
---|
| 123 | // text's apostrophes become text’s apostrophes |
---|
| 124 | $search['apostrophe'] = '/(\w)(?:\'|'|')(\w)/ms'; |
---|
| 125 | $replace['apostrophe'] = '$1’$2'; |
---|
| 126 | |
---|
| 127 | // 'single quoted text' becomes ‘single quoted text’ |
---|
| 128 | $search['single_quotes'] = '/(^|[^\w=])(?:\'|'|‘)([^\']+?)(?:\'|'|’)([^\w]|$)/ms'; |
---|
| 129 | $replace['single_quotes'] = '$1‘$2’$3'; |
---|
| 130 | |
---|
| 131 | // plural posessives' apostrophes become posessives’ |
---|
| 132 | $search['apostrophes'] = '/(s)(?:\'|'|')(\s)/ms'; |
---|
| 133 | $replace['apostrophes'] = '$1’$2'; |
---|
| 134 | |
---|
| 135 | // em--dashes become em—dashes |
---|
| 136 | $search['em_dash'] = '/(\s*[^!<-])--([^>-]\s*)/'; |
---|
| 137 | $replace['em_dash'] = '$1—$2'; |
---|
| 138 | |
---|
| 139 | return preg_replace($search, $replace, $txt); |
---|
[1] | 140 | } |
---|
| 141 | |
---|
[42] | 142 | |
---|
[1] | 143 | /** |
---|
| 144 | * Generates a hexadecibal html color based on provided word. |
---|
| 145 | * |
---|
| 146 | * @access public |
---|
| 147 | * @param string $text A string for which to convert to color. |
---|
| 148 | * @return string A hexadecimal html color. |
---|
| 149 | */ |
---|
| 150 | function getTextColor($text, $method=1) |
---|
| 151 | { |
---|
| 152 | $r = substr(md5($text), 0, 1); |
---|
| 153 | $g = substr(md5($text), 1, 1); |
---|
| 154 | $b = substr(md5($text), 2, 1); |
---|
| 155 | |
---|
| 156 | switch ($method) { |
---|
| 157 | case 2 : |
---|
| 158 | if (hexdec($r) > hexdec('c')) { |
---|
| 159 | $r = dechex(hexdec('f') - hexdec($r)); |
---|
| 160 | } |
---|
| 161 | if (hexdec($g) > hexdec('c')) { |
---|
| 162 | $g = dechex(hexdec('f') - hexdec($g)); |
---|
| 163 | } |
---|
| 164 | if (hexdec($b) > hexdec('c')) { |
---|
| 165 | $b = dechex(hexdec('f') - hexdec($b)); |
---|
| 166 | } |
---|
| 167 | break; |
---|
[42] | 168 | |
---|
[1] | 169 | case 1 : |
---|
| 170 | default : |
---|
| 171 | $r = dechex(round(hexdec($r) * .8)); |
---|
| 172 | $g = dechex(round(hexdec($g) * .8)); |
---|
| 173 | $b = dechex(round(hexdec($b) * .6)); |
---|
| 174 | break; |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | return $r . $r . $g . $g . $b . $b; |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | /** |
---|
| 181 | * Encodes a string into unicode values 128-255. |
---|
| 182 | * Useful for hiding an email address from spambots. |
---|
| 183 | * |
---|
| 184 | * @access public |
---|
| 185 | * @param string $text A line of text to encode. |
---|
| 186 | * @return string Encoded text. |
---|
| 187 | */ |
---|
| 188 | function encodeAscii($text) |
---|
| 189 | { |
---|
| 190 | $ouput = ''; |
---|
| 191 | $num = strlen($text); |
---|
| 192 | for ($i=0; $i<$num; $i++) { |
---|
| 193 | $output .= sprintf('&#%03s', ord($text{$i})); |
---|
| 194 | } |
---|
| 195 | return $output; |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | /** |
---|
[84] | 199 | * Encodes an email into a "user at domain dot com" format. |
---|
[9] | 200 | * |
---|
| 201 | * @access public |
---|
| 202 | * @param string $email An email to encode. |
---|
| 203 | * @param string $at Replaces the @. |
---|
| 204 | * @param string $dot Replaces the .. |
---|
| 205 | * @return string Encoded email. |
---|
| 206 | */ |
---|
[53] | 207 | function encodeEmail($email, $at=' at ', $dot=' dot ') |
---|
[9] | 208 | { |
---|
| 209 | $search = array('/@/', '/\./'); |
---|
| 210 | $replace = array($at, $dot); |
---|
| 211 | return preg_replace($search, $replace, $email); |
---|
| 212 | } |
---|
| 213 | |
---|
| 214 | /** |
---|
[84] | 215 | * Turns "a really long string" into "a rea...string" |
---|
| 216 | * |
---|
| 217 | * @access public |
---|
| 218 | * @param string $str Input string |
---|
| 219 | * @param int $len Maximum string length. |
---|
| 220 | * @param string $where Where to cut the string. One of: 'start', 'middle', or 'end'. |
---|
| 221 | * @return string Truncated output string |
---|
| 222 | * @author Quinn Comendant <quinn@strangecode.com> |
---|
| 223 | * @since 29 Mar 2006 13:48:49 |
---|
| 224 | */ |
---|
| 225 | function truncate($str, $len, $where='middle') |
---|
| 226 | { |
---|
| 227 | $part1 = floor(($len - 3) / 2); |
---|
| 228 | $part2 = ceil(($len - 3) / 2); |
---|
| 229 | switch ($where) { |
---|
| 230 | case 'start' : |
---|
[189] | 231 | return preg_replace(array(sprintf('/^.{4,}(.{%s})$/sU', $part1 + $part2), '/\s*\.{3,}\s*/sU'), array('...$1', '...'), $str); |
---|
[84] | 232 | break; |
---|
| 233 | default : |
---|
| 234 | case 'middle' : |
---|
[189] | 235 | return preg_replace(array(sprintf('/^(.{%s}).{4,}(.{%s})$/sU', $part1, $part2), '/\s*\.{3,}\s*/sU'), array('$1...$2', '...'), $str); |
---|
[84] | 236 | break; |
---|
| 237 | case 'end' : |
---|
[189] | 238 | return preg_replace(array(sprintf('/^(.{%s}).{4,}$/sU', $part1 + $part2), '/\s*\.{3,}\s*/sU'), array('$1...', '...'), $str); |
---|
[84] | 239 | break; |
---|
| 240 | } |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | /** |
---|
[1] | 244 | * Return a human readable filesize. |
---|
| 245 | * |
---|
| 246 | * @param int $size Size |
---|
| 247 | * @param int $unit The maximum unit |
---|
| 248 | * @param int $format The return string format |
---|
| 249 | * @author Aidan Lister <aidan@php.net> |
---|
| 250 | * @version 1.1.0 |
---|
| 251 | */ |
---|
[201] | 252 | function humanFileSize($size, $format='%01.2f %s', $max_unit=null) |
---|
[1] | 253 | { |
---|
| 254 | // Units |
---|
| 255 | $units = array('B', 'KB', 'MB', 'GB', 'TB'); |
---|
| 256 | $ii = count($units) - 1; |
---|
[42] | 257 | |
---|
[1] | 258 | // Max unit |
---|
[154] | 259 | $max_unit = array_search((string) $max_unit, $units); |
---|
| 260 | if ($max_unit === null || $max_unit === false) { |
---|
| 261 | $max_unit = $ii; |
---|
[1] | 262 | } |
---|
[42] | 263 | |
---|
[1] | 264 | // Loop |
---|
| 265 | $i = 0; |
---|
[154] | 266 | while ($max_unit != $i && $size >= 1024 && $i < $ii) { |
---|
[1] | 267 | $size /= 1024; |
---|
| 268 | $i++; |
---|
| 269 | } |
---|
[42] | 270 | |
---|
[1] | 271 | return sprintf($format, $size, $units[$i]); |
---|
| 272 | } |
---|
| 273 | |
---|
[180] | 274 | /* |
---|
[189] | 275 | * Returns a human readable amount of time for the given amount of seconds. |
---|
[180] | 276 | * |
---|
| 277 | * 45 seconds |
---|
| 278 | * 12 minutes |
---|
| 279 | * 3.5 hours |
---|
| 280 | * 2 days |
---|
| 281 | * 1 week |
---|
| 282 | * 4 months |
---|
| 283 | * |
---|
| 284 | * Months are calculated using the real number of days in a year: 365.2422 / 12. |
---|
| 285 | * |
---|
| 286 | * @access public |
---|
[189] | 287 | * @param int $seconds Seconds of time. |
---|
[180] | 288 | * @param string $max_unit Key value from the $units array. |
---|
| 289 | * @param string $format Sprintf formatting string. |
---|
| 290 | * @return string Value of units elapsed. |
---|
| 291 | * @author Quinn Comendant <quinn@strangecode.com> |
---|
| 292 | * @version 1.0 |
---|
| 293 | * @since 23 Jun 2006 12:15:19 |
---|
| 294 | */ |
---|
[189] | 295 | function humanTime($seconds, $max_unit=null, $format='%01.1f') |
---|
[180] | 296 | { |
---|
[202] | 297 | // Units: array of seconds in the unit, singular and plural unit names. |
---|
[180] | 298 | $units = array( |
---|
| 299 | 'second' => array(1, _("second"), _("seconds")), |
---|
| 300 | 'minute' => array(60, _("minute"), _("minutes")), |
---|
| 301 | 'hour' => array(3600, _("hour"), _("hours")), |
---|
| 302 | 'day' => array(86400, _("day"), _("days")), |
---|
| 303 | 'week' => array(604800, _("week"), _("weeks")), |
---|
| 304 | 'month' => array(2629743.84, _("month"), _("months")), |
---|
| 305 | 'year' => array(31556926.08, _("year"), _("years")), |
---|
| 306 | 'decade' => array(315569260.8, _("decade"), _("decades")), |
---|
| 307 | ); |
---|
| 308 | |
---|
[202] | 309 | // Max unit to calculate. |
---|
[180] | 310 | $max_unit = isset($units[$max_unit]) ? $max_unit : 'decade'; |
---|
| 311 | |
---|
[189] | 312 | $final_time = $seconds; |
---|
[191] | 313 | $last_unit = 'second'; |
---|
[180] | 314 | foreach ($units as $k => $v) { |
---|
[189] | 315 | if ($max_unit != $k && $seconds >= $v[0]) { |
---|
| 316 | $final_time = $seconds / $v[0]; |
---|
[180] | 317 | $last_unit = $k; |
---|
| 318 | } |
---|
| 319 | } |
---|
[189] | 320 | $final_time = sprintf($format, $final_time); |
---|
| 321 | return sprintf('%s %s', $final_time, (1 == $final_time ? $units[$last_unit][1] : $units[$last_unit][2])); |
---|
[180] | 322 | } |
---|
| 323 | |
---|
[1] | 324 | /** |
---|
[26] | 325 | * Returns stats of a file from the include path. |
---|
| 326 | * |
---|
| 327 | * @param string $file File in include path. |
---|
| 328 | * @return mixed Value of requested key from fstat(), or false on error. |
---|
| 329 | * @author Quinn Comendant <quinn@strangecode.com> |
---|
| 330 | * @since 03 Dec 2005 14:23:26 |
---|
| 331 | */ |
---|
| 332 | function statIncludePath($file, $stat) |
---|
| 333 | { |
---|
| 334 | // Open file pointer read-only using include path. |
---|
| 335 | if ($fp = fopen($file, 'r', true)) { |
---|
| 336 | // File opend successfully, get stats. |
---|
| 337 | $stats = fstat($fp); |
---|
| 338 | fclose($fp); |
---|
| 339 | // Return specified stats. |
---|
| 340 | return $stats[$stat]; |
---|
| 341 | } else { |
---|
| 342 | return false; |
---|
| 343 | } |
---|
| 344 | } |
---|
| 345 | |
---|
| 346 | /** |
---|
[1] | 347 | * If $var is net set or null, set it to $default. Otherwise leave it alone. |
---|
| 348 | * Returns the final value of $var. Use to find a default value of one is not avilable. |
---|
| 349 | * |
---|
| 350 | * @param mixed $var The variable that is being set. |
---|
| 351 | * @param mixed $default What to set it to if $val is not currently set. |
---|
[42] | 352 | * @return mixed The resulting value of $var. |
---|
[1] | 353 | */ |
---|
| 354 | function setDefault(&$var, $default='') |
---|
| 355 | { |
---|
| 356 | if (!isset($var)) { |
---|
| 357 | $var = $default; |
---|
| 358 | } |
---|
| 359 | return $var; |
---|
| 360 | } |
---|
| 361 | |
---|
| 362 | /** |
---|
| 363 | * Like preg_quote() except for arrays, it takes an array of strings and puts |
---|
| 364 | * a backslash in front of every character that is part of the regular |
---|
| 365 | * expression syntax. |
---|
| 366 | * |
---|
| 367 | * @param array $array input array |
---|
| 368 | * @param array $delim optional character that will also be excaped. |
---|
| 369 | * @return array an array with the same values as $array1 but shuffled |
---|
| 370 | */ |
---|
| 371 | function pregQuoteArray($array, $delim='/') |
---|
| 372 | { |
---|
| 373 | if (!empty($array)) { |
---|
| 374 | if (is_array($array)) { |
---|
| 375 | foreach ($array as $key=>$val) { |
---|
| 376 | $quoted_array[$key] = preg_quote($val, $delim); |
---|
| 377 | } |
---|
| 378 | return $quoted_array; |
---|
| 379 | } else { |
---|
| 380 | return preg_quote($array, $delim); |
---|
| 381 | } |
---|
| 382 | } |
---|
| 383 | } |
---|
| 384 | |
---|
| 385 | /** |
---|
| 386 | * Converts a PHP Array into encoded URL arguments and return them as an array. |
---|
| 387 | * |
---|
| 388 | * @param mixed $data An array to transverse recursivly, or a string |
---|
| 389 | * to use directly to create url arguments. |
---|
| 390 | * @param string $prefix The name of the first dimension of the array. |
---|
| 391 | * If not specified, the first keys of the array will be used. |
---|
| 392 | * @return array URL with array elements as URL key=value arguments. |
---|
| 393 | */ |
---|
| 394 | function urlEncodeArray($data, $prefix='', $_return=true) { |
---|
[42] | 395 | |
---|
[1] | 396 | // Data is stored in static variable. |
---|
| 397 | static $args; |
---|
[42] | 398 | |
---|
[1] | 399 | if (is_array($data)) { |
---|
| 400 | foreach ($data as $key => $val) { |
---|
| 401 | // If the prefix is empty, use the $key as the name of the first dimention of the "array". |
---|
| 402 | // ...otherwise, append the key as a new dimention of the "array". |
---|
| 403 | $new_prefix = ('' == $prefix) ? urlencode($key) : $prefix . '[' . urlencode($key) . ']'; |
---|
| 404 | // Enter recursion. |
---|
| 405 | urlEncodeArray($val, $new_prefix, false); |
---|
| 406 | } |
---|
| 407 | } else { |
---|
[20] | 408 | // We've come to the last dimention of the array, save the "array" and its value. |
---|
[1] | 409 | $args[$prefix] = urlencode($data); |
---|
| 410 | } |
---|
[42] | 411 | |
---|
[1] | 412 | if ($_return) { |
---|
| 413 | // This is not a recursive execution. All recursion is complete. |
---|
| 414 | // Reset static var and return the result. |
---|
| 415 | $ret = $args; |
---|
| 416 | $args = array(); |
---|
| 417 | return is_array($ret) ? $ret : array(); |
---|
| 418 | } |
---|
| 419 | } |
---|
| 420 | |
---|
| 421 | /** |
---|
| 422 | * Converts a PHP Array into encoded URL arguments and return them in a string. |
---|
| 423 | * |
---|
| 424 | * @param mixed $data An array to transverse recursivly, or a string |
---|
| 425 | * to use directly to create url arguments. |
---|
| 426 | * @param string $prefix The name of the first dimention of the array. |
---|
| 427 | * If not specified, the first keys of the array will be used. |
---|
| 428 | * @return string url A string ready to append to a url. |
---|
| 429 | */ |
---|
| 430 | function urlEncodeArrayToString($data, $prefix='') { |
---|
[42] | 431 | |
---|
[1] | 432 | $array_args = urlEncodeArray($data, $prefix); |
---|
| 433 | $url_args = ''; |
---|
| 434 | $delim = ''; |
---|
| 435 | foreach ($array_args as $key=>$val) { |
---|
| 436 | $url_args .= $delim . $key . '=' . $val; |
---|
| 437 | $delim = ini_get('arg_separator.output'); |
---|
| 438 | } |
---|
| 439 | return $url_args; |
---|
| 440 | } |
---|
| 441 | |
---|
| 442 | /** |
---|
| 443 | * Fills an arrray with the result from a multiple ereg search. |
---|
| 444 | * Curtesy of Bruno - rbronosky@mac.com - 10-May-2001 |
---|
| 445 | * Blame him for the funky do...while loop. |
---|
| 446 | * |
---|
| 447 | * @param mixed $pattern regular expression needle |
---|
| 448 | * @param mixed $string haystack |
---|
| 449 | * @return array populated with each found result |
---|
| 450 | */ |
---|
| 451 | function eregAll($pattern, $string) |
---|
| 452 | { |
---|
| 453 | do { |
---|
| 454 | if (!ereg($pattern, $string, $temp)) { |
---|
| 455 | continue; |
---|
| 456 | } |
---|
| 457 | $string = str_replace($temp[0], '', $string); |
---|
| 458 | $results[] = $temp; |
---|
| 459 | } while (ereg($pattern, $string, $temp)); |
---|
| 460 | return $results; |
---|
| 461 | } |
---|
| 462 | |
---|
| 463 | /** |
---|
| 464 | * Prints the word "checked" if a variable is set, and optionally matches |
---|
| 465 | * the desired value, otherwise prints nothing, |
---|
[42] | 466 | * used for printing the word "checked" in a checkbox form input. |
---|
[1] | 467 | * |
---|
| 468 | * @param mixed $var the variable to compare |
---|
| 469 | * @param mixed $value optional, what to compare with if a specific value is required. |
---|
| 470 | */ |
---|
| 471 | function frmChecked($var, $value=null) |
---|
| 472 | { |
---|
| 473 | if (func_num_args() == 1 && $var) { |
---|
| 474 | // 'Checked' if var is true. |
---|
| 475 | echo ' checked="checked" '; |
---|
| 476 | } else if (func_num_args() == 2 && $var == $value) { |
---|
| 477 | // 'Checked' if var and value match. |
---|
| 478 | echo ' checked="checked" '; |
---|
| 479 | } else if (func_num_args() == 2 && is_array($var)) { |
---|
| 480 | // 'Checked' if the value is in the key or the value of an array. |
---|
| 481 | if (isset($var[$value])) { |
---|
| 482 | echo ' checked="checked" '; |
---|
| 483 | } else if (in_array($value, $var)) { |
---|
| 484 | echo ' checked="checked" '; |
---|
| 485 | } |
---|
| 486 | } |
---|
| 487 | } |
---|
| 488 | |
---|
| 489 | /** |
---|
| 490 | * prints the word "selected" if a variable is set, and optionally matches |
---|
| 491 | * the desired value, otherwise prints nothing, |
---|
[42] | 492 | * otherwise prints nothing, used for printing the word "checked" in a |
---|
| 493 | * select form input |
---|
[1] | 494 | * |
---|
| 495 | * @param mixed $var the variable to compare |
---|
| 496 | * @param mixed $value optional, what to compare with if a specific value is required. |
---|
| 497 | */ |
---|
| 498 | function frmSelected($var, $value=null) |
---|
| 499 | { |
---|
| 500 | if (func_num_args() == 1 && $var) { |
---|
| 501 | // 'selected' if var is true. |
---|
| 502 | echo ' selected="selected" '; |
---|
| 503 | } else if (func_num_args() == 2 && $var == $value) { |
---|
| 504 | // 'selected' if var and value match. |
---|
| 505 | echo ' selected="selected" '; |
---|
| 506 | } else if (func_num_args() == 2 && is_array($var)) { |
---|
| 507 | // 'selected' if the value is in the key or the value of an array. |
---|
| 508 | if (isset($var[$value])) { |
---|
| 509 | echo ' selected="selected" '; |
---|
| 510 | } else if (in_array($value, $var)) { |
---|
| 511 | echo ' selected="selected" '; |
---|
| 512 | } |
---|
| 513 | } |
---|
| 514 | } |
---|
| 515 | |
---|
| 516 | /** |
---|
[111] | 517 | * Adds slashes to values of an array and converts the array to a comma |
---|
| 518 | * delimited list. If value provided is a string return the string |
---|
| 519 | * escaped. This is useful for putting values coming in from posted |
---|
| 520 | * checkboxes into a SET column of a database. |
---|
| 521 | * |
---|
[1] | 522 | * |
---|
[111] | 523 | * @param array $in Array to convert. |
---|
[1] | 524 | * @return string Comma list of array values. |
---|
| 525 | */ |
---|
[224] | 526 | function escapedList($in, $separator="', '") |
---|
[1] | 527 | { |
---|
[136] | 528 | $db =& DB::getInstance(); |
---|
| 529 | |
---|
[111] | 530 | if (is_array($in) && !empty($in)) { |
---|
[224] | 531 | return join($separator, array_map(array($db, 'escapeString'), $in)); |
---|
[111] | 532 | } else { |
---|
[136] | 533 | return $db->escapeString($in); |
---|
[1] | 534 | } |
---|
| 535 | } |
---|
| 536 | |
---|
| 537 | /** |
---|
[111] | 538 | * Converts a human string date into a SQL-safe date. Dates nearing |
---|
| 539 | * infinity use the date 2038-01-01 so conversion to unix time format |
---|
| 540 | * remain within valid range. |
---|
[1] | 541 | * |
---|
| 542 | * @param array $date String date to convert. |
---|
[42] | 543 | * @param array $format Date format to pass to date(). |
---|
[1] | 544 | * Default produces MySQL datetime: 0000-00-00 00:00:00. |
---|
| 545 | * @return string SQL-safe date. |
---|
| 546 | */ |
---|
| 547 | function strToSQLDate($date, $format='Y-m-d H:i:s') |
---|
| 548 | { |
---|
| 549 | // Translate the human string date into SQL-safe date format. |
---|
[219] | 550 | if (empty($date) || strpos($date, '0000-00-00') !== false || strtotime($date) === -1 || strtotime($date) === false) { |
---|
[224] | 551 | // Return a string of zero time, formatted the same as $format. |
---|
| 552 | return strtr($format, array( |
---|
| 553 | 'Y' => '0000', |
---|
| 554 | 'm' => '00', |
---|
| 555 | 'd' => '00', |
---|
| 556 | 'H' => '00', |
---|
| 557 | 'i' => '00', |
---|
| 558 | 's' => '00', |
---|
| 559 | )); |
---|
[1] | 560 | } else { |
---|
[219] | 561 | return date($format, strtotime($date)); |
---|
[1] | 562 | } |
---|
| 563 | } |
---|
| 564 | |
---|
| 565 | /** |
---|
| 566 | * If magic_quotes_gpc is in use, run stripslashes() on $var. If $var is an |
---|
| 567 | * array, stripslashes is run on each value, recursivly, and the stripped |
---|
[51] | 568 | * array is returned. |
---|
[1] | 569 | * |
---|
| 570 | * @param mixed $var The string or array to un-quote, if necessary. |
---|
| 571 | * @return mixed $var, minus any magic quotes. |
---|
| 572 | */ |
---|
| 573 | function dispelMagicQuotes($var) |
---|
| 574 | { |
---|
| 575 | static $magic_quotes_gpc; |
---|
[42] | 576 | |
---|
[1] | 577 | if (!isset($magic_quotes_gpc)) { |
---|
| 578 | $magic_quotes_gpc = get_magic_quotes_gpc(); |
---|
| 579 | } |
---|
[42] | 580 | |
---|
[1] | 581 | if ($magic_quotes_gpc) { |
---|
| 582 | if (!is_array($var)) { |
---|
| 583 | $var = stripslashes($var); |
---|
| 584 | } else { |
---|
| 585 | foreach ($var as $key=>$val) { |
---|
| 586 | if (is_array($val)) { |
---|
| 587 | $var[$key] = dispelMagicQuotes($val); |
---|
| 588 | } else { |
---|
| 589 | $var[$key] = stripslashes($val); |
---|
| 590 | } |
---|
| 591 | } |
---|
| 592 | } |
---|
| 593 | } |
---|
| 594 | return $var; |
---|
| 595 | } |
---|
| 596 | |
---|
| 597 | /** |
---|
| 598 | * Get a form variable from GET or POST data, stripped of magic |
---|
| 599 | * quotes if necessary. |
---|
| 600 | * |
---|
| 601 | * @param string $var (optional) The name of the form variable to look for. |
---|
| 602 | * @param string $default (optional) The value to return if the |
---|
| 603 | * variable is not there. |
---|
| 604 | * @return mixed A cleaned GET or POST if no $var specified. |
---|
| 605 | * @return string A cleaned form $var if found, or $default. |
---|
| 606 | */ |
---|
| 607 | function getFormData($var=null, $default=null) |
---|
| 608 | { |
---|
| 609 | if ('POST' == getenv('REQUEST_METHOD') && is_null($var)) { |
---|
| 610 | return dispelMagicQuotes($_POST); |
---|
| 611 | } else if ('GET' == getenv('REQUEST_METHOD') && is_null($var)) { |
---|
| 612 | return dispelMagicQuotes($_GET); |
---|
| 613 | } |
---|
| 614 | if (isset($_POST[$var])) { |
---|
[51] | 615 | return dispelMagicQuotes($_POST[$var]); |
---|
[1] | 616 | } else if (isset($_GET[$var])) { |
---|
[51] | 617 | return dispelMagicQuotes($_GET[$var]); |
---|
[1] | 618 | } else { |
---|
| 619 | return $default; |
---|
| 620 | } |
---|
| 621 | } |
---|
| 622 | function getPost($var=null, $default=null) |
---|
| 623 | { |
---|
| 624 | if (is_null($var)) { |
---|
[51] | 625 | return dispelMagicQuotes($_POST); |
---|
[1] | 626 | } |
---|
| 627 | if (isset($_POST[$var])) { |
---|
[51] | 628 | return dispelMagicQuotes($_POST[$var]); |
---|
[1] | 629 | } else { |
---|
| 630 | return $default; |
---|
| 631 | } |
---|
| 632 | } |
---|
| 633 | function getGet($var=null, $default=null) |
---|
| 634 | { |
---|
| 635 | if (is_null($var)) { |
---|
[51] | 636 | return dispelMagicQuotes($_GET); |
---|
[1] | 637 | } |
---|
| 638 | if (isset($_GET[$var])) { |
---|
[51] | 639 | return dispelMagicQuotes($_GET[$var]); |
---|
[1] | 640 | } else { |
---|
| 641 | return $default; |
---|
| 642 | } |
---|
| 643 | } |
---|
| 644 | |
---|
| 645 | /** |
---|
| 646 | * Signs a value using md5 and a simple text key. In order for this |
---|
| 647 | * function to be useful (i.e. secure) the key must be kept secret, which |
---|
| 648 | * means keeping it as safe as database credentials. Putting it into an |
---|
| 649 | * environment variable set in httpd.conf is a good place. |
---|
| 650 | * |
---|
| 651 | * @access public |
---|
| 652 | * @param string $val The string to sign. |
---|
[159] | 653 | * @param string $salt (Optional) A text key to use for computing the signature. |
---|
[1] | 654 | * @return string The original value with a signature appended. |
---|
| 655 | */ |
---|
[159] | 656 | function addSignature($val, $salt=null) |
---|
[1] | 657 | { |
---|
[159] | 658 | $app =& App::getInstance(); |
---|
| 659 | |
---|
| 660 | if ('' == trim($val)) { |
---|
[201] | 661 | $app->logMsg(sprintf('Cannot add signature to an empty string.', null), LOG_INFO, __FILE__, __LINE__); |
---|
[159] | 662 | return ''; |
---|
[1] | 663 | } |
---|
[42] | 664 | |
---|
[159] | 665 | if (!isset($salt)) { |
---|
| 666 | $salt = $app->getParam('signing_key'); |
---|
[1] | 667 | } |
---|
| 668 | |
---|
[159] | 669 | return $val . '-' . substr(md5($salt . md5($val . $salt)), 0, 18); |
---|
[1] | 670 | } |
---|
| 671 | |
---|
| 672 | /** |
---|
| 673 | * Strips off the signature appended by addSignature(). |
---|
| 674 | * |
---|
| 675 | * @access public |
---|
| 676 | * @param string $signed_val The string to sign. |
---|
| 677 | * @return string The original value with a signature removed. |
---|
| 678 | */ |
---|
| 679 | function removeSignature($signed_val) |
---|
| 680 | { |
---|
| 681 | return substr($signed_val, 0, strrpos($signed_val, '-')); |
---|
| 682 | } |
---|
| 683 | |
---|
| 684 | |
---|
| 685 | /** |
---|
| 686 | * Verifies a signature appened to a value by addSignature(). |
---|
| 687 | * |
---|
| 688 | * @access public |
---|
| 689 | * @param string $signed_val A value with appended signature. |
---|
[159] | 690 | * @param string $salt (Optional) A text key to use for computing the signature. |
---|
[1] | 691 | * @return bool True if the signature matches the var. |
---|
| 692 | */ |
---|
[159] | 693 | function verifySignature($signed_val, $salt=null) |
---|
[1] | 694 | { |
---|
| 695 | // Strip the value from the signed value. |
---|
[22] | 696 | $val = removeSignature($signed_val); |
---|
[1] | 697 | // If the signed value matches the original signed value we consider the value safe. |
---|
[159] | 698 | if ($signed_val == addSignature($val, $salt)) { |
---|
[1] | 699 | // Signature verified. |
---|
| 700 | return true; |
---|
| 701 | } else { |
---|
| 702 | return false; |
---|
| 703 | } |
---|
| 704 | } |
---|
| 705 | |
---|
| 706 | /** |
---|
| 707 | * Sends empty output to the browser and flushes the php buffer so the client |
---|
[42] | 708 | * will see data before the page is finished processing. |
---|
[1] | 709 | */ |
---|
| 710 | function flushBuffer() { |
---|
| 711 | echo str_repeat(' ', 205); |
---|
| 712 | flush(); |
---|
| 713 | } |
---|
| 714 | |
---|
| 715 | /** |
---|
| 716 | * Adds email address to mailman mailing list. Requires /etc/sudoers entry for apache to sudo execute add_members. |
---|
| 717 | * Don't forget to allow php_admin_value open_basedir access to "/var/mailman/bin". |
---|
| 718 | * |
---|
| 719 | * @access public |
---|
| 720 | * @param string $email Email address to add. |
---|
| 721 | * @param string $list Name of list to add to. |
---|
| 722 | * @param bool $send_welcome_message True to send welcome message to subscriber. |
---|
| 723 | * @return bool True on success, false on failure. |
---|
| 724 | */ |
---|
| 725 | function mailmanAddMember($email, $list, $send_welcome_message=false) |
---|
| 726 | { |
---|
[136] | 727 | $app =& App::getInstance(); |
---|
| 728 | |
---|
| 729 | $add_members = '/var/mailman/bin/add_members'; |
---|
[1] | 730 | if (is_executable($add_members) && is_readable($add_members)) { |
---|
| 731 | $welcome_msg = $send_welcome_message ? 'y' : 'n'; |
---|
| 732 | exec(sprintf('/bin/echo %s | /usr/bin/sudo %s -r - --welcome-msg=%s --admin-notify=n %s', escapeshellarg($email), escapeshellarg($add_members), $welcome_msg, escapeshellarg($list)), $stdout, $return_code); |
---|
| 733 | if (0 == $return_code) { |
---|
[136] | 734 | $app->logMsg(sprintf('Mailman add member success for list: %s, user: %s', $list, $email, $stdout), LOG_INFO, __FILE__, __LINE__); |
---|
[1] | 735 | return true; |
---|
| 736 | } else { |
---|
[136] | 737 | $app->logMsg(sprintf('Mailman add member failed for list: %s, user: %s, with message: %s', $list, $email, $stdout), LOG_WARNING, __FILE__, __LINE__); |
---|
[1] | 738 | return false; |
---|
| 739 | } |
---|
| 740 | } else { |
---|
[136] | 741 | $app->logMsg(sprintf('Mailman add member program not executable: %s', $add_members), LOG_ALERT, __FILE__, __LINE__); |
---|
[1] | 742 | return false; |
---|
| 743 | } |
---|
| 744 | } |
---|
| 745 | |
---|
| 746 | /** |
---|
| 747 | * Removes email address from mailman mailing list. Requires /etc/sudoers entry for apache to sudo execute add_members. |
---|
| 748 | * Don't forget to allow php_admin_value open_basedir access to "/var/mailman/bin". |
---|
| 749 | * |
---|
| 750 | * @access public |
---|
| 751 | * @param string $email Email address to add. |
---|
| 752 | * @param string $list Name of list to add to. |
---|
| 753 | * @param bool $send_user_ack True to send goodbye message to subscriber. |
---|
| 754 | * @return bool True on success, false on failure. |
---|
| 755 | */ |
---|
| 756 | function mailmanRemoveMember($email, $list, $send_user_ack=false) |
---|
| 757 | { |
---|
[136] | 758 | $app =& App::getInstance(); |
---|
| 759 | |
---|
[1] | 760 | $remove_members = '/var/mailman/bin/remove_members'; |
---|
| 761 | if (is_executable($remove_members) && is_readable($remove_members)) { |
---|
| 762 | $userack = $send_user_ack ? '' : '--nouserack'; |
---|
| 763 | exec(sprintf('/usr/bin/sudo %s %s --noadminack %s %s', escapeshellarg($remove_members), $userack, escapeshellarg($list), escapeshellarg($email)), $stdout, $return_code); |
---|
| 764 | if (0 == $return_code) { |
---|
[136] | 765 | $app->logMsg(sprintf('Mailman remove member success for list: %s, user: %s', $list, $email, $stdout), LOG_INFO, __FILE__, __LINE__); |
---|
[1] | 766 | return true; |
---|
| 767 | } else { |
---|
[136] | 768 | $app->logMsg(sprintf('Mailman remove member failed for list: %s, user: %s, with message: %s', $list, $email, $stdout), LOG_WARNING, __FILE__, __LINE__); |
---|
[1] | 769 | return false; |
---|
| 770 | } |
---|
| 771 | } else { |
---|
[136] | 772 | $app->logMsg(sprintf('Mailman remove member program not executable: %s', $remove_members), LOG_ALERT, __FILE__, __LINE__); |
---|
[1] | 773 | return false; |
---|
| 774 | } |
---|
| 775 | } |
---|
| 776 | |
---|
| 777 | /** |
---|
[42] | 778 | * Returns the remote IP address, taking into consideration proxy servers. |
---|
[1] | 779 | * |
---|
| 780 | * @param bool $dolookup If true we resolve to IP to a host name, |
---|
| 781 | * if false we don't. |
---|
| 782 | * @return string IP address if $dolookup is false or no arg |
---|
| 783 | * Hostname if $dolookup is true |
---|
| 784 | */ |
---|
| 785 | function getRemoteAddr($dolookup=false) |
---|
| 786 | { |
---|
| 787 | $ip = getenv('HTTP_CLIENT_IP'); |
---|
| 788 | if (empty($ip) || $ip == 'unknown' || $ip == 'localhost' || $ip == '127.0.0.1') { |
---|
| 789 | $ip = getenv('HTTP_X_FORWARDED_FOR'); |
---|
| 790 | if (empty($ip) || $ip == 'unknown' || $ip == 'localhost' || $ip == '127.0.0.1') { |
---|
| 791 | $ip = getenv('REMOTE_ADDR'); |
---|
| 792 | } |
---|
| 793 | } |
---|
| 794 | return $dolookup && '' != $ip ? gethostbyaddr($ip) : $ip; |
---|
| 795 | } |
---|
| 796 | |
---|
| 797 | /** |
---|
| 798 | * Tests whether a given IP address can be found in an array of IP address networks. |
---|
| 799 | * Elements of networks array can be single IP addresses or an IP address range in CIDR notation |
---|
| 800 | * See: http://en.wikipedia.org/wiki/Classless_inter-domain_routing |
---|
| 801 | * |
---|
| 802 | * @access public |
---|
| 803 | * @param string IP address to search for. |
---|
| 804 | * @param array Array of networks to search within. |
---|
| 805 | * @return mixed Returns the network that matched on success, false on failure. |
---|
| 806 | */ |
---|
| 807 | function ipInRange($ip, $networks) |
---|
| 808 | { |
---|
| 809 | if (!is_array($networks)) { |
---|
| 810 | $networks = array($networks); |
---|
| 811 | } |
---|
[42] | 812 | |
---|
[1] | 813 | $ip_binary = sprintf('%032b', ip2long($ip)); |
---|
| 814 | foreach ($networks as $network) { |
---|
| 815 | if (preg_match('![\d\.]{7,15}/\d{1,2}!', $network)) { |
---|
| 816 | // IP is in CIDR notation. |
---|
| 817 | list($cidr_ip, $cidr_bitmask) = split('/', $network); |
---|
| 818 | $cidr_ip_binary = sprintf('%032b', ip2long($cidr_ip)); |
---|
| 819 | if (substr($ip_binary, 0, $cidr_bitmask) === substr($cidr_ip_binary, 0, $cidr_bitmask)) { |
---|
| 820 | // IP address is within the specified IP range. |
---|
| 821 | return $network; |
---|
| 822 | } |
---|
| 823 | } else { |
---|
| 824 | if ($ip === $network) { |
---|
| 825 | // IP address exactly matches. |
---|
| 826 | return $network; |
---|
| 827 | } |
---|
| 828 | } |
---|
| 829 | } |
---|
[42] | 830 | |
---|
[1] | 831 | return false; |
---|
| 832 | } |
---|
| 833 | |
---|
| 834 | /** |
---|
[159] | 835 | * If the given $url is on the same web site, return true. This can be used to |
---|
| 836 | * prevent from sending sensitive info in a get query (like the SID) to another |
---|
| 837 | * domain. |
---|
| 838 | * |
---|
| 839 | * @param string $url the URI to test. |
---|
| 840 | * @return bool True if given $url is our domain or has no domain (is a relative url), false if it's another. |
---|
| 841 | */ |
---|
| 842 | function isMyDomain($url) |
---|
| 843 | { |
---|
| 844 | static $urls = array(); |
---|
| 845 | |
---|
| 846 | if (!isset($urls[$url])) { |
---|
| 847 | if (!preg_match('|https?://[\w.]+/|', $url)) { |
---|
| 848 | // If we can't find a domain we assume the URL is local (i.e. "/my/url/path/" or "../img/file.jpg"). |
---|
| 849 | $urls[$url] = true; |
---|
| 850 | } else { |
---|
| 851 | $urls[$url] = preg_match('|https?://[\w.]*' . preg_quote(getenv('HTTP_HOST'), '|') . '|i', $url); |
---|
| 852 | } |
---|
| 853 | } |
---|
| 854 | return $urls[$url]; |
---|
| 855 | } |
---|
| 856 | |
---|
| 857 | /** |
---|
| 858 | * Takes a URL and returns it without the query or anchor portion |
---|
| 859 | * |
---|
| 860 | * @param string $url any kind of URI |
---|
| 861 | * @return string the URI with ? or # and everything after removed |
---|
| 862 | */ |
---|
| 863 | function stripQuery($url) |
---|
| 864 | { |
---|
| 865 | return preg_replace('![?#].*!', '', $url); |
---|
| 866 | } |
---|
| 867 | |
---|
| 868 | /** |
---|
[42] | 869 | * Returns a fully qualified URL to the current script, including the query. |
---|
[1] | 870 | * |
---|
| 871 | * @return string a full url to the current script |
---|
| 872 | */ |
---|
| 873 | function absoluteMe() |
---|
| 874 | { |
---|
| 875 | $protocol = ('on' == getenv('HTTPS')) ? 'https://' : 'http://'; |
---|
| 876 | return $protocol . getenv('HTTP_HOST') . getenv('REQUEST_URI'); |
---|
| 877 | } |
---|
| 878 | |
---|
| 879 | /** |
---|
| 880 | * Compares the current url with the referring url. |
---|
| 881 | * |
---|
[159] | 882 | * @param bool $exclude_query Remove the query string first before comparing. |
---|
| 883 | * @return bool True if the current URL is the same as the refering URL, false otherwise. |
---|
[1] | 884 | */ |
---|
| 885 | function refererIsMe($exclude_query=false) |
---|
| 886 | { |
---|
| 887 | if ($exclude_query) { |
---|
| 888 | return (stripQuery(absoluteMe()) == stripQuery(getenv('HTTP_REFERER'))); |
---|
| 889 | } else { |
---|
| 890 | return (absoluteMe() == getenv('HTTP_REFERER')); |
---|
| 891 | } |
---|
| 892 | } |
---|
| 893 | |
---|
| 894 | /** |
---|
| 895 | * Stub functions used when installation does not have |
---|
| 896 | * GNU gettext extension installed |
---|
| 897 | */ |
---|
| 898 | if (!extension_loaded('gettext')) { |
---|
| 899 | /** |
---|
| 900 | * Translates text |
---|
[42] | 901 | * |
---|
[1] | 902 | * @access public |
---|
| 903 | * @param string $text the text to be translated |
---|
| 904 | * @return string translated text |
---|
| 905 | */ |
---|
| 906 | function gettext($text) { |
---|
| 907 | return $text; |
---|
| 908 | } |
---|
[42] | 909 | |
---|
[1] | 910 | /** |
---|
| 911 | * Translates text |
---|
[42] | 912 | * |
---|
[1] | 913 | * @access public |
---|
| 914 | * @param string $text the text to be translated |
---|
| 915 | * @return string translated text |
---|
| 916 | */ |
---|
| 917 | function _($text) { |
---|
| 918 | return $text; |
---|
| 919 | } |
---|
[42] | 920 | |
---|
[1] | 921 | /** |
---|
| 922 | * Translates text by domain |
---|
[42] | 923 | * |
---|
[1] | 924 | * @access public |
---|
| 925 | * @param string $domain the language to translate the text into |
---|
| 926 | * @param string $text the text to be translated |
---|
| 927 | * @return string translated text |
---|
| 928 | */ |
---|
| 929 | function dgettext($domain, $text) { |
---|
| 930 | return $text; |
---|
| 931 | } |
---|
[42] | 932 | |
---|
[1] | 933 | /** |
---|
| 934 | * Translates text by domain and category |
---|
[42] | 935 | * |
---|
[1] | 936 | * @access public |
---|
| 937 | * @param string $domain the language to translate the text into |
---|
| 938 | * @param string $text the text to be translated |
---|
| 939 | * @param string $category the language dialect to use |
---|
| 940 | * @return string translated text |
---|
| 941 | */ |
---|
| 942 | function dcgettext($domain, $text, $category) { |
---|
| 943 | return $text; |
---|
| 944 | } |
---|
[42] | 945 | |
---|
[1] | 946 | /** |
---|
| 947 | * Binds the text domain |
---|
[42] | 948 | * |
---|
[1] | 949 | * @access public |
---|
| 950 | * @param string $domain the language to translate the text into |
---|
[42] | 951 | * @param string |
---|
[1] | 952 | * @return string translated text |
---|
| 953 | */ |
---|
| 954 | function bindtextdomain($domain, $directory) { |
---|
| 955 | return $domain; |
---|
| 956 | } |
---|
[42] | 957 | |
---|
[1] | 958 | /** |
---|
| 959 | * Sets the text domain |
---|
[42] | 960 | * |
---|
[1] | 961 | * @access public |
---|
| 962 | * @param string $domain the language to translate the text into |
---|
| 963 | * @return string translated text |
---|
| 964 | */ |
---|
| 965 | function textdomain($domain) { |
---|
| 966 | return $domain; |
---|
| 967 | } |
---|
| 968 | } |
---|
| 969 | |
---|
| 970 | |
---|
| 971 | |
---|
| 972 | ?> |
---|