PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/custom-sidebars/inc/external/wpmu-lib/inc/class-thelib-core.php

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