/wp-content/plugins/buddypress/bp-core/bp-core-wpabstraction.php

https://github.com/jazbek/nycga2 · PHP · 162 lines · 94 code · 23 blank · 45 comment · 26 complexity · cb1d6714c247c1766ae6ba8bd02cbf5b MD5 · raw file

  1. <?php
  2. /*****
  3. * WordPress Abstraction
  4. *
  5. * The functions within this file will detect the version of WordPress you are running
  6. * and will alter the environment so BuddyPress can run regardless.
  7. *
  8. * The code below mostly contains function mappings. This code is subject to change once
  9. * the 3.0 WordPress version merge takes place.
  10. */
  11. // Exit if accessed directly
  12. if ( !defined( 'ABSPATH' ) ) exit;
  13. /**
  14. * Only add abstraction functions if WordPress is not in multisite mode
  15. */
  16. if ( !is_multisite() ) {
  17. global $wpdb;
  18. $wpdb->base_prefix = $wpdb->prefix;
  19. $wpdb->blogid = BP_ROOT_BLOG;
  20. if ( !function_exists( 'get_blog_option' ) ) {
  21. function get_blog_option( $blog_id, $option_name, $default = false ) {
  22. return get_option( $option_name, $default );
  23. }
  24. }
  25. if ( !function_exists( 'update_blog_option' ) ) {
  26. function update_blog_option( $blog_id, $option_name, $value ) {
  27. return update_option( $option_name, $value );
  28. }
  29. }
  30. if ( !function_exists( 'delete_blog_option' ) ) {
  31. function delete_blog_option( $blog_id, $option_name ) {
  32. return delete_option( $option_name );
  33. }
  34. }
  35. if ( !function_exists( 'switch_to_blog' ) ) {
  36. function switch_to_blog() {
  37. return bp_get_root_blog_id();
  38. }
  39. }
  40. if ( !function_exists( 'restore_current_blog' ) ) {
  41. function restore_current_blog() {
  42. return bp_get_root_blog_id();
  43. }
  44. }
  45. if ( !function_exists( 'get_blogs_of_user' ) ) {
  46. function get_blogs_of_user() {
  47. return false;
  48. }
  49. }
  50. if ( !function_exists( 'update_blog_status' ) ) {
  51. function update_blog_status() {
  52. return true;
  53. }
  54. }
  55. if ( !function_exists( 'is_subdomain_install' ) ) {
  56. function is_subdomain_install() {
  57. if ( ( defined( 'VHOST' ) && 'yes' == VHOST ) || ( defined( 'SUBDOMAIN_INSTALL' ) && SUBDOMAIN_INSTALL ) )
  58. return true;
  59. return false;
  60. }
  61. }
  62. }
  63. function bp_core_get_status_sql( $prefix = false ) {
  64. if ( !is_multisite() )
  65. return "{$prefix}user_status = 0";
  66. else
  67. return "{$prefix}spam = 0 AND {$prefix}deleted = 0 AND {$prefix}user_status = 0";
  68. }
  69. /**
  70. * Multibyte encoding fallback functions
  71. *
  72. * The PHP multibyte encoding extension is not enabled by default. In cases where it is not enabled,
  73. * these functions provide a fallback.
  74. *
  75. * Borrowed from MediaWiki, under the GPLv2. Thanks!
  76. */
  77. if ( !function_exists( 'mb_strlen' ) ) {
  78. /**
  79. * Fallback implementation of mb_strlen, hardcoded to UTF-8.
  80. * @param string $str
  81. * @param string $enc optional encoding; ignored
  82. * @return int
  83. */
  84. function mb_strlen( $str, $enc = '' ) {
  85. $counts = count_chars( $str );
  86. $total = 0;
  87. // Count ASCII bytes
  88. for( $i = 0; $i < 0x80; $i++ ) {
  89. $total += $counts[$i];
  90. }
  91. // Count multibyte sequence heads
  92. for( $i = 0xc0; $i < 0xff; $i++ ) {
  93. $total += $counts[$i];
  94. }
  95. return $total;
  96. }
  97. }
  98. if ( !function_exists( 'mb_strpos' ) ) {
  99. /**
  100. * Fallback implementation of mb_strpos, hardcoded to UTF-8.
  101. * @param $haystack String
  102. * @param $needle String
  103. * @param $offset String: optional start position
  104. * @param $encoding String: optional encoding; ignored
  105. * @return int
  106. */
  107. function mb_strpos( $haystack, $needle, $offset = 0, $encoding = '' ) {
  108. $needle = preg_quote( $needle, '/' );
  109. $ar = array();
  110. preg_match( '/' . $needle . '/u', $haystack, $ar, PREG_OFFSET_CAPTURE, $offset );
  111. if( isset( $ar[0][1] ) ) {
  112. return $ar[0][1];
  113. } else {
  114. return false;
  115. }
  116. }
  117. }
  118. if ( !function_exists( 'mb_strrpos' ) ) {
  119. /**
  120. * Fallback implementation of mb_strrpos, hardcoded to UTF-8.
  121. * @param $haystack String
  122. * @param $needle String
  123. * @param $offset String: optional start position
  124. * @param $encoding String: optional encoding; ignored
  125. * @return int
  126. */
  127. function mb_strrpos( $haystack, $needle, $offset = 0, $encoding = '' ) {
  128. $needle = preg_quote( $needle, '/' );
  129. $ar = array();
  130. preg_match_all( '/' . $needle . '/u', $haystack, $ar, PREG_OFFSET_CAPTURE, $offset );
  131. if( isset( $ar[0] ) && count( $ar[0] ) > 0 &&
  132. isset( $ar[0][count( $ar[0] ) - 1][1] ) ) {
  133. return $ar[0][count( $ar[0] ) - 1][1];
  134. } else {
  135. return false;
  136. }
  137. }
  138. }
  139. ?>