misc.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * The Zoo
  4. *
  5. * @copyright (c) 2007 OSI
  6. * @author Frédéric G. MARAND
  7. * @license Licensed under the CeCILL 2.0
  8. * @version CVS: $Id: misc.php,v 1.4 2007-06-10 19:39:54 marand Exp $
  9. * @link http://drupal.org/project/offload
  10. * @since Not applicable yet
  11. * @package default
  12. */
  13. /**
  14. * Interface used by function providing non-standard comparisons
  15. * @package default
  16. */
  17. interface Comparable_Interface
  18. {
  19. /**
  20. * Compare the current instance
  21. *
  22. * @param Comparable_Interface $other
  23. * @return int
  24. */
  25. public function cmp(Comparable_Interface $other);
  26. }
  27. function _debug($msg)
  28. {
  29. global $_debug_active ;
  30. if ($_debug_active)
  31. echo $msg;
  32. }
  33. /**
  34. * Old school autoloader.
  35. */
  36. /*
  37. function __autoload($name)
  38. {
  39. _debug("Autoloading $name\n");
  40. require_once("$name.php");
  41. }
  42. */
  43. /**
  44. * Sample PSR-0 autoloader.
  45. *
  46. * Do not use as such: it is only placed here to show use of the FSM classes in
  47. * a PSR-0 application.
  48. *
  49. * Straight from the PSR-0 standard.
  50. *
  51. * @param string $className
  52. */
  53. function psr0_autoload($className) {
  54. $className = ltrim($className, '\\');
  55. $fileName = '';
  56. $namespace = '';
  57. if ($lastNsPos = strripos($className, '\\')) {
  58. $namespace = substr($className, 0, $lastNsPos);
  59. $className = substr($className, $lastNsPos + 1);
  60. $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
  61. }
  62. $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
  63. //print_r(debug_backtrace());
  64. $sts = require $fileName;
  65. }
  66. function get_temp_dir()
  67. {
  68. return 'e:/src/OsinetOffice/tmp';
  69. }
  70. /**
  71. * @link http://blog.riff.org/2006_11_19_console_encoding_in_php_gtk_apps
  72. *
  73. * @param string $s
  74. * @return string
  75. */
  76. function output_encoder($s)
  77. {
  78. return iconv('UTF-8', 'IBM850', $s);
  79. }
  80. // Activate the OB handler:
  81. ob_start("output_encoder", 2);
  82. /**
  83. * automatically find the glade file for a class file
  84. *
  85. */
  86. function load_glade()
  87. {
  88. return new GladeXML(basename($_SERVER['PHP_SELF'], 'php') . 'glade');
  89. }
  90. /**
  91. * returns the name of the invoking function/method
  92. * if it's a method, it is prefixed by the class name
  93. *
  94. * @return string
  95. */
  96. function func_name($level = 1)
  97. {
  98. $trace = debug_backtrace();
  99. $func = $trace[$level]['function'];
  100. if (isset($trace[$level]['class']))
  101. $func = $trace[$level]['class'] . '::' . $func;
  102. return $func;
  103. }