PageRenderTime 50ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/fuel/application/helpers/utility_helper.php

http://github.com/daylightstudio/FUEL-CMS
PHP | 162 lines | 82 code | 14 blank | 66 comment | 27 complexity | 4eab742ff7c47bcf6fc55b7f0e9caccc MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception
  1. <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * FUEL CMS
  4. * http://www.getfuelcms.com
  5. *
  6. * An open source Content Management System based on the
  7. * Codeigniter framework (http://codeigniter.com)
  8. *
  9. * @package FUEL CMS
  10. * @author David McReynolds @ Daylight Studio
  11. * @copyright Copyright (c) 2011, Run for Daylight LLC.
  12. * @license http://www.getfuelcms.com/user_guide/general/license
  13. * @link http://www.getfuelcms.com
  14. * @filesource
  15. */
  16. // ------------------------------------------------------------------------
  17. /**
  18. * FUEL Utility Helper
  19. *
  20. * This helper is a collection of functions that assists a developer in
  21. * capturing/debugging content and its related code
  22. *
  23. * @package FUEL CMS
  24. * @subpackage Helpers
  25. * @category Helpers
  26. * @author David McReynolds @ Daylight Studio
  27. * @link http://www.getfuelcms.com/user_guide/helpers/asset_helpers
  28. */
  29. // --------------------------------------------------------------------
  30. /**
  31. * Capture content via an output buffer
  32. *
  33. * @param boolean turn on output buffering
  34. * @param string if set to 'all', will clear end the buffer and clean it
  35. * @return string return buffered content
  36. */
  37. function capture($on = TRUE, $clean = 'all')
  38. {
  39. $str = '';
  40. if ($on)
  41. {
  42. ob_start();
  43. }
  44. else
  45. {
  46. $str = ob_get_contents();
  47. if (!empty($str))
  48. {
  49. if ($clean == 'all')
  50. {
  51. ob_end_clean();
  52. }
  53. else if ($clean)
  54. {
  55. ob_clean();
  56. }
  57. }
  58. return $str;
  59. }
  60. }
  61. // --------------------------------------------------------------------
  62. /**
  63. * Format true value
  64. *
  65. * @param mixed possible true value
  66. * @return string formatted true value
  67. */
  68. function is_true_val($val)
  69. {
  70. $val = strtolower($val);
  71. return ($val == 'y' || $val == 'yes' || $val === 1 || $val == '1' || $val== 'true' || $val == 't');
  72. }
  73. // --------------------------------------------------------------------
  74. /**
  75. * Boolean check to determine string content is serialized
  76. *
  77. * @param mixed possible serialized string
  78. * @return boolean
  79. */
  80. function is_serialized_str($data)
  81. {
  82. if ( !is_string($data))
  83. return false;
  84. $data = trim($data);
  85. if ( 'N;' == $data )
  86. return true;
  87. if ( !preg_match('/^([adObis]):/', $data, $badions))
  88. return false;
  89. switch ( $badions[1] ) :
  90. case 'a' :
  91. case 'O' :
  92. case 's' :
  93. if ( preg_match("/^{$badions[1]}:[0-9]+:.*[;}]\$/s", $data))
  94. return true;
  95. break;
  96. case 'b' :
  97. case 'i' :
  98. case 'd' :
  99. if ( preg_match("/^{$badions[1]}:[0-9.E-]+;\$/", $data))
  100. return true;
  101. break;
  102. endswitch;
  103. return false;
  104. }
  105. // --------------------------------------------------------------------
  106. /**
  107. * Print object in human-readible format
  108. *
  109. * @param object object variable
  110. * @param boolean return as string if true
  111. * @return string
  112. */
  113. function print_obj($obj, $return = false)
  114. {
  115. $str = "<pre>";
  116. if (is_array($obj))
  117. {
  118. // to prevent circular references
  119. if (is_a(current($obj), 'Data_record'))
  120. {
  121. foreach($obj as $key => $val)
  122. {
  123. $str .= '['.$key.']';
  124. $str .= $val;
  125. }
  126. }
  127. else
  128. {
  129. $str .= print_r($obj, true);
  130. }
  131. }
  132. $str .= "</pre>";
  133. if ($return) return $str;
  134. echo $str;
  135. }
  136. // --------------------------------------------------------------------
  137. /**
  138. * Returns the global CI object
  139. *
  140. * @return object
  141. */
  142. function CI() {
  143. if (!function_exists('get_instance')) return FALSE;
  144. $CI =& get_instance();
  145. return $CI;
  146. }
  147. /* End of file utility_helper.php */
  148. /* Location: ./application/helpers/utility_helper.php */