misc.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * The OSInet Zoo.
  4. *
  5. * Miscellaneous functions of dubious value, mostly used in PHP-GTK code < 2008.
  6. *
  7. * WARNING: including this files turns on output buffering. Useful in PHP-GTK
  8. * apps, possibly troublesome elsewhere.
  9. *
  10. * @copyright (c) 2007 OSI
  11. * @author Frédéric G. MARAND
  12. * @license Licensed under the CeCILL 2.0
  13. * @link http://drupal.org/project/offload
  14. */
  15. /**
  16. * Interface used by function providing non-standard comparisons.
  17. */
  18. interface Comparable_Interface {
  19. /**
  20. * Compare the current instance
  21. *
  22. * @param Comparable_Interface $other
  23. *
  24. * @return int
  25. */
  26. public function cmp(Comparable_Interface $other);
  27. }
  28. /**
  29. * Echo message depending on global $_debug_active value.
  30. *
  31. * @param mixed $msg
  32. */
  33. function _debug($msg) {
  34. global $_debug_active ;
  35. if ($_debug_active)
  36. echo $msg;
  37. }
  38. /**
  39. * Convert encoding to IBM850 for PHP-GTK apps on Windows.
  40. *
  41. * @link http://blog.riff.org/2006_11_19_console_encoding_in_php_gtk_apps
  42. *
  43. * @param string $s
  44. *
  45. * @return string
  46. */
  47. function output_encoder($s) {
  48. return iconv('UTF-8', 'IBM850', $s);
  49. }
  50. /**
  51. * Automatically find the glade file for a PHP-GTK class file.
  52. */
  53. function load_glade() {
  54. return new GladeXML(basename(__FILE__, 'php') . 'glade');
  55. }
  56. /**
  57. * Returns the name of the invoking function/method. If it's a method, it is
  58. * prefixed by the class name.
  59. *
  60. * @return string
  61. */
  62. function func_name($level = 1) {
  63. $trace = debug_backtrace();
  64. $func = $trace[$level]['function'];
  65. if (isset($trace[$level]['class'])) {
  66. $func = $trace[$level]['class'] . '::' . $func;
  67. }
  68. return $func;
  69. }
  70. // Activate the OB handler:
  71. ob_start("output_encoder", 2);