PageRenderTime 169ms CodeModel.GetById 40ms RepoModel.GetById 7ms app.codeStats 0ms

/gforge/plugins/wiki/www/lib/prepend.php

https://github.com/neymanna/fusionforge
PHP | 153 lines | 85 code | 20 blank | 48 comment | 15 complexity | e749a53577781df599b8b9c478c60f19 MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /* lib/prepend.php
  3. *
  4. * Things which must be done and defined before anything else.
  5. */
  6. $RCS_IDS = '';
  7. function rcs_id ($id) {
  8. // Save memory
  9. if (defined('DEBUG') and DEBUG)
  10. $GLOBALS['RCS_IDS'] .= "$id\n";
  11. }
  12. rcs_id('$Id: prepend.php,v 1.43 2005/09/14 06:06:43 rurban Exp $');
  13. // see lib/stdlib.php: phpwiki_version()
  14. define('PHPWIKI_VERSION', '1.3.12p3');
  15. /**
  16. * Returns true if current php version is at mimimum a.b.c
  17. * Called: check_php_version(4,1)
  18. */
  19. function check_php_version ($a = '0', $b = '0', $c = '0') {
  20. static $PHP_VERSION;
  21. if (!isset($PHP_VERSION))
  22. $PHP_VERSION = substr( str_pad( preg_replace('/\D/','', PHP_VERSION), 3, '0'), 0, 3);
  23. return ($PHP_VERSION >= ($a.$b.$c));
  24. }
  25. /** PHP5 deprecated old-style globals if !(bool)ini_get('register_long_arrays').
  26. * See Bug #1180115
  27. * We want to work with those old ones instead of the new superglobals,
  28. * for easier coding.
  29. */
  30. foreach (array('SERVER','REQUEST','GET','POST','SESSION','ENV','COOKIE') as $k) {
  31. if (!isset($GLOBALS['HTTP_'.$k.'_VARS']) and isset($GLOBALS['_'.$k]))
  32. $GLOBALS['HTTP_'.$k.'_VARS'] =& $GLOBALS['_'.$k];
  33. }
  34. unset($k);
  35. // If your php was compiled with --enable-trans-sid it tries to
  36. // add a PHPSESSID query argument to all URL strings when cookie
  37. // support isn't detected in the client browser. For reasons
  38. // which aren't entirely clear (PHP bug) this screws up the URLs
  39. // generated by PhpWiki. Therefore, transparent session ids
  40. // should be disabled. This next line does that.
  41. //
  42. // (At the present time, you will not be able to log-in to PhpWiki,
  43. // unless your browser supports cookies.)
  44. @ini_set('session.use_trans_sid', 0);
  45. if (defined('DEBUG') and (DEBUG & 8) and extension_loaded("xdebug")) {
  46. xdebug_start_trace("trace"); // on Dbgp protocol add 2
  47. xdebug_enable();
  48. }
  49. // Used for debugging purposes
  50. class DebugTimer {
  51. function DebugTimer() {
  52. $this->_start = $this->microtime();
  53. if (function_exists('posix_times'))
  54. $this->_times = posix_times();
  55. }
  56. /**
  57. * @param string $which One of 'real', 'utime', 'stime', 'cutime', 'sutime'
  58. * @return float Seconds.
  59. */
  60. function getTime($which='real', $now=false) {
  61. if ($which == 'real')
  62. return $this->microtime() - $this->_start;
  63. if (isset($this->_times)) {
  64. if (!$now) $now = posix_times();
  65. $ticks = $now[$which] - $this->_times[$which];
  66. return $ticks / $this->_CLK_TCK();
  67. }
  68. return 0.0; // Not available.
  69. }
  70. function getStats() {
  71. if (!isset($this->_times)) {
  72. // posix_times() not available.
  73. return sprintf("real: %.3f", $this->getTime('real'));
  74. }
  75. $now = posix_times();
  76. return sprintf("real: %.3f, user: %.3f, sys: %.3f",
  77. $this->getTime('real'),
  78. $this->getTime('utime', $now),
  79. $this->getTime('stime', $now));
  80. }
  81. function _CLK_TCK() {
  82. // FIXME: this is clearly not always right.
  83. // But how to figure out the right value?
  84. return 100.0;
  85. }
  86. function microtime(){
  87. list($usec, $sec) = explode(" ", microtime());
  88. return ((float)$usec + (float)$sec);
  89. }
  90. }
  91. $RUNTIMER = new DebugTimer;
  92. /*
  93. if (defined('E_STRICT') and (E_ALL & E_STRICT)) // strict php5?
  94. error_reporting(E_ALL & ~E_STRICT); // exclude E_STRICT
  95. else
  96. error_reporting(E_ALL); // php4
  97. //echo " prepend: ", error_reporting();
  98. */
  99. require_once(dirname(__FILE__).'/ErrorManager.php');
  100. require_once(dirname(__FILE__).'/WikiCallback.php');
  101. // FIXME: deprecated
  102. function ExitWiki($errormsg = false)
  103. {
  104. global $request;
  105. static $in_exit = 0;
  106. if (is_object($request) and method_exists($request,"finish"))
  107. $request->finish($errormsg); // NORETURN
  108. if ($in_exit)
  109. exit;
  110. $in_exit = true;
  111. global $ErrorManager;
  112. $ErrorManager->flushPostponedErrors();
  113. if(!empty($errormsg)) {
  114. PrintXML(HTML::br(), $errormsg);
  115. print "\n</body></html>";
  116. }
  117. exit;
  118. }
  119. if (!defined('DEBUG') or (defined('DEBUG') and DEBUG > 2)) {
  120. $ErrorManager->setPostponedErrorMask(E_ALL); // ignore all errors
  121. $ErrorManager->setFatalHandler(new WikiFunctionCb('ExitWiki'));
  122. } else {
  123. $ErrorManager->setPostponedErrorMask(E_USER_NOTICE | E_NOTICE);
  124. }
  125. // (c-file-style: "gnu")
  126. // Local Variables:
  127. // mode: php
  128. // tab-width: 8
  129. // c-basic-offset: 4
  130. // c-hanging-comment-ender-p: nil
  131. // indent-tabs-mode: nil
  132. // End:
  133. ?>