/wp-content/plugins/sitepress-multilingual-cms/inc/hacks/missing-php-functions.php

https://bitbucket.org/adatux_/uakami · PHP · 153 lines · 123 code · 16 blank · 14 comment · 39 complexity · 73a49af5193b5b46427090ba2801e56a MD5 · raw file

  1. <?php
  2. // json_decode
  3. if ( !function_exists('json_decode') ){
  4. include_once ICL_PLUGIN_PATH . '/lib/JSON.php';
  5. function json_decode($data, $bool) {
  6. if ($bool) {
  7. $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
  8. } else {
  9. $json = new Services_JSON();
  10. }
  11. return( $json->decode($data) );
  12. }
  13. }
  14. if(!function_exists('_cleanup_header_comment')){
  15. function _cleanup_header_comment($str) {
  16. return trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', $str));
  17. }
  18. }
  19. /* remove this when we stop supporting WP versions below 3.0 */
  20. if(!function_exists('wp_get_mu_plugins')){
  21. function wp_get_mu_plugins() {
  22. $mu_plugins = array();
  23. if ( !is_dir( WPMU_PLUGIN_DIR ) )
  24. return $mu_plugins;
  25. if ( ! $dh = opendir( WPMU_PLUGIN_DIR ) )
  26. return $mu_plugins;
  27. while ( ( $plugin = readdir( $dh ) ) !== false ) {
  28. if ( substr( $plugin, -4 ) == '.php' )
  29. $mu_plugins[] = WPMU_PLUGIN_DIR . '/' . $plugin;
  30. }
  31. closedir( $dh );
  32. sort( $mu_plugins );
  33. return $mu_plugins;
  34. }
  35. }
  36. if(!function_exists('money_format')):
  37. /*
  38. That it is an implementation of the function money_format for the
  39. platforms that do not it bear.
  40. The function accepts to same string of format accepts for the
  41. original function of the PHP.
  42. (Sorry. my writing in English is very bad)
  43. The function is tested using PHP 5.1.4 in Windows XP
  44. and Apache WebServer.
  45. */
  46. function money_format($format, $number)
  47. {
  48. $regex = '/%((?:[\^!\-]|\+|\(|\=.)*)([0-9]+)?'.
  49. '(?:#([0-9]+))?(?:\.([0-9]+))?([in%])/';
  50. if (setlocale(LC_MONETARY, 0) == 'C') {
  51. setlocale(LC_MONETARY, '');
  52. }
  53. $locale = localeconv();
  54. preg_match_all($regex, $format, $matches, PREG_SET_ORDER);
  55. foreach ($matches as $fmatch) {
  56. $value = floatval($number);
  57. $flags = array(
  58. 'fillchar' => preg_match('/\=(.)/', $fmatch[1], $match) ?
  59. $match[1] : ' ',
  60. 'nogroup' => preg_match('/\^/', $fmatch[1]) > 0,
  61. 'usesignal' => preg_match('/\+|\(/', $fmatch[1], $match) ?
  62. $match[0] : '+',
  63. 'nosimbol' => preg_match('/\!/', $fmatch[1]) > 0,
  64. 'isleft' => preg_match('/\-/', $fmatch[1]) > 0
  65. );
  66. $width = trim($fmatch[2]) ? (int)$fmatch[2] : 0;
  67. $left = trim($fmatch[3]) ? (int)$fmatch[3] : 0;
  68. $right = trim($fmatch[4]) ? (int)$fmatch[4] : $locale['int_frac_digits'];
  69. $conversion = $fmatch[5];
  70. $positive = true;
  71. if ($value < 0) {
  72. $positive = false;
  73. $value *= -1;
  74. }
  75. $letter = $positive ? 'p' : 'n';
  76. $prefix = $suffix = $cprefix = $csuffix = $signal = '';
  77. $signal = $positive ? $locale['positive_sign'] : $locale['negative_sign'];
  78. switch (true) {
  79. case $locale["{$letter}_sign_posn"] == 1 && $flags['usesignal'] == '+':
  80. $prefix = $signal;
  81. break;
  82. case $locale["{$letter}_sign_posn"] == 2 && $flags['usesignal'] == '+':
  83. $suffix = $signal;
  84. break;
  85. case $locale["{$letter}_sign_posn"] == 3 && $flags['usesignal'] == '+':
  86. $cprefix = $signal;
  87. break;
  88. case $locale["{$letter}_sign_posn"] == 4 && $flags['usesignal'] == '+':
  89. $csuffix = $signal;
  90. break;
  91. case $flags['usesignal'] == '(':
  92. case $locale["{$letter}_sign_posn"] == 0:
  93. $prefix = '(';
  94. $suffix = ')';
  95. break;
  96. }
  97. if (!$flags['nosimbol']) {
  98. $currency = $cprefix .
  99. ($conversion == 'i' ? $locale['int_curr_symbol'] : $locale['currency_symbol']) .
  100. $csuffix;
  101. } else {
  102. $currency = '';
  103. }
  104. $space = $locale["{$letter}_sep_by_space"] ? ' ' : '';
  105. $value = number_format($value, $right, $locale['mon_decimal_point'],
  106. $flags['nogroup'] ? '' : $locale['mon_thousands_sep']);
  107. $value = @explode($locale['mon_decimal_point'], $value);
  108. $n = strlen($prefix) + strlen($currency) + strlen($value[0]);
  109. if ($left > 0 && $left > $n) {
  110. $value[0] = str_repeat($flags['fillchar'], $left - $n) . $value[0];
  111. }
  112. $value = implode($locale['mon_decimal_point'], $value);
  113. if ($locale["{$letter}_cs_precedes"]) {
  114. $value = $prefix . $currency . $space . $value . $suffix;
  115. } else {
  116. $value = $prefix . $value . $space . $currency . $suffix;
  117. }
  118. if ($width > 0) {
  119. $value = str_pad($value, $width, $flags['fillchar'], $flags['isleft'] ?
  120. STR_PAD_RIGHT : STR_PAD_LEFT);
  121. }
  122. $format = str_replace($fmatch[0], $value, $format);
  123. }
  124. return $format;
  125. }
  126. endif;
  127. if(!defined('E_DEPRECATED')){ define('E_DEPRECATED', 8192); }
  128. if(!function_exists('esc_textarea')):
  129. function esc_textarea( $text ) {
  130. $safe_text = htmlspecialchars( $text, ENT_QUOTES );
  131. return apply_filters( 'esc_textarea', $safe_text, $text );
  132. }
  133. endif;
  134. ?>