TheLib_Core

Main access to the Code-Library.

Defined (1)

The class is defined in the following location(s).

/lib/wpmu-lib/inc/class-thelib-core.php  
  1. class TheLib_Core extends TheLib { 
  2.  
  3. /** 
  4. * Interface to the array component. 
  5. * @since 1.1.5 
  6. * @api 
  7. * @var TheLib_Array 
  8. */ 
  9. public $array = null; 
  10.  
  11. /** 
  12. * Interface to the Debug component. 
  13. * @since 1.1.0 
  14. * @api 
  15. * @var TheLib_Debug 
  16. */ 
  17. public $debug = null; 
  18.  
  19. /** 
  20. * Interface to the HTML component. 
  21. * @since 1.1.0 
  22. * @api 
  23. * @var TheLib_Html 
  24. */ 
  25. public $html = null; 
  26.  
  27. /** 
  28. * Interface to the Net component. 
  29. * @since 1.1.0 
  30. * @api 
  31. * @var TheLib_Net 
  32. */ 
  33. public $net = null; 
  34.  
  35. /** 
  36. * Interface to the session component. 
  37. * @since 1.1.5 
  38. * @api 
  39. * @var TheLib_Session 
  40. */ 
  41. public $session = null; 
  42.  
  43. /** 
  44. * Interface to the updates component. 
  45. * @since 1.1.5 
  46. * @api 
  47. * @var TheLib_Updates 
  48. */ 
  49. public $updates = null; 
  50.  
  51. /** 
  52. * Interface to the UI component. 
  53. * @since 1.1.5 
  54. * @api 
  55. * @var TheLib_Ui 
  56. */ 
  57. public $ui = null; 
  58.  
  59. /** 
  60. * Class constructor 
  61. * @since 1.0.0 
  62. * @internal 
  63. */ 
  64. public function __construct() { 
  65. parent::__construct(); 
  66.  
  67. self::$core = $this; 
  68.  
  69. // A List of all components. 
  70. $components = array( 
  71. 'array',  
  72. 'debug',  
  73. 'html',  
  74. 'net',  
  75. 'session',  
  76. 'updates',  
  77. 'ui',  
  78. ); 
  79.  
  80. // Create instances of each component. 
  81. foreach ( $components as $component ) { 
  82. if ( ! property_exists( $this, $component ) ) { continue; } 
  83.  
  84. $class_name = 'TheLib_' . ucfirst( $component ); 
  85. $this->$component = new $class_name(); 
  86.  
  87. /** 
  88. * Checks if the provided value evaluates to a boolean TRUE. 
  89. * Following values are considered true: 
  90. * - Boolean: true 
  91. * - Number: anything except 0 
  92. * - Strings: true, yes, on (case insensitive) 
  93. * @since 1.1.0 
  94. * @api 
  95. * @param mixed $value A value that will be evaluated as a boolean. 
  96. * @return bool True if the specified $value evaluated to TRUE. 
  97. */ 
  98. public function is_true( $value ) { 
  99. if ( false === $value || null === $value || '' === $value ) { 
  100. return false; 
  101. } elseif ( true === $value ) { 
  102. return true; 
  103. } elseif ( is_numeric( $value ) ) { 
  104. $value = intval( $value ); 
  105. return $value != 0; 
  106. } elseif ( is_string( $value ) ) { 
  107. $value = strtolower( trim( $value ) ); 
  108. return in_array( 
  109. $value,  
  110. array( 'true', 'yes', 'on', '1' ) 
  111. ); 
  112. return false; 
  113.  
  114. /** 
  115. * Opposite of the is_true() function. 
  116. * @since 3.0.0 
  117. * @param mixed $value A value that will be evaluated as a boolean 
  118. * @return bool True if the speciefied value evals as FALSE 
  119. */ 
  120. public function is_false( $value ) { 
  121. return ! $this->is_true( $value ); 
  122.  
  123. /** 
  124. * Converts a number from any base to another base. 
  125. * The from/to base values can even be non-numeric values. 
  126. * @since 2.0.2 
  127. * @api 
  128. * @param string $number A number in the base_from base. 
  129. * @param string $base_from List of characters 
  130. * E.g. 0123456789 to convert from decimal. 
  131. * @param string $base_to List of characters to use as destination base. 
  132. * E.g. 0123456789ABCDEF to convert to hexadecimal. 
  133. * @return string The converted number 
  134. */ 
  135. public function convert( $number, $base_from = '0123456789', $base_to = '0123456789ABCDEF' ) { 
  136. if ( $base_from == $base_to ) { 
  137. // No conversion needed. 
  138. return $number; 
  139.  
  140. $retval = ''; 
  141. $number_len = strlen( $number ); 
  142.  
  143. if ( '0123456789' == $base_to ) { 
  144. // Convert a value to normal decimal base. 
  145.  
  146. $arr_base_from = str_split( $base_from, 1 ); 
  147. $arr_number = str_split( $number, 1 ); 
  148. $base_from_len = strlen( $base_from ); 
  149. $retval = 0; 
  150. for ( $i = 1; $i <= $number_len; $i += 1 ) { 
  151. $retval = bcadd( 
  152. $retval,  
  153. bcmul( 
  154. array_search( $arr_number[$i - 1], $arr_base_from ),  
  155. bcpow( $base_from_len, $number_len - $i ) 
  156. ); 
  157. } else { 
  158. // Convert a value to a NON-decimal base. 
  159.  
  160. if ( '0123456789' != $base_from ) { 
  161. // Base value is non-decimal, convert it to decimal first. 
  162. $base10 = $this->convert( $number, $base_from, '0123456789' ); 
  163. } else { 
  164. // Base value is decimal. 
  165. $base10 = $number; 
  166.  
  167. $arr_base_to = str_split( $base_to, 1 ); 
  168. $base_to_len = strlen( $base_to ); 
  169. if ( $base10 < strlen( $base_to ) ) { 
  170. $retval = $arr_base_to[$base10]; 
  171. } else { 
  172. while ( 0 != $base10 ) { 
  173. $retval = $arr_base_to[bcmod( $base10, $base_to_len )] . $retval; 
  174. $base10 = bcdiv( $base10, $base_to_len, 0 ); 
  175.  
  176. return $retval; 
  177.