PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/misc.inc.php

https://bitbucket.org/hky/bytehoard2
PHP | 111 lines | 78 code | 15 blank | 18 comment | 20 complexity | e53f2508364e783df977d7c1bc4db5b7 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /*
  3. * ByteHoard 2.1
  4. * Copyright (c) Andrew Godwin & contributors 2003-2004
  5. *
  6. * Miscellaneous Functions File
  7. * $Id: misc.inc.php,v 1.4 2005/07/28 23:06:07 andrewgodwin Exp $
  8. *
  9. */
  10. # Test for include status
  11. if (IN_BH != 1) { header("Location: ../index.php"); die(); }
  12. # Fixes ISS request_uri
  13. if(!isset($_SERVER['REQUEST_URI'])) {
  14. $arr = explode("/", $_SERVER['PHP_SELF']);
  15. $_SERVER['REQUEST_URI'] = "/" . $arr[count($arr)-1];
  16. if ($_SERVER['argv'][0]!="")
  17. $_SERVER['REQUEST_URI'] .= "?" . $_SERVER['argv'][0];
  18. }
  19. function bh_getskins() {
  20. global $bhconfig;
  21. # Open layouts folder
  22. $handle = opendir($bhconfig['bhfilepath']."/layouts/");
  23. # For each layout:
  24. while (false !== ($layout = readdir($handle))) {
  25. if (file_exists($bhconfig['bhfilepath']."/layouts/".$layout."/main.inc.php")) {
  26. # Open that layout's skins folder
  27. $handle2 = opendir($bhconfig['bhfilepath']."/layouts/".$layout."/skins/");
  28. # And for each skin:
  29. while (false !== ($skin = readdir($handle2))) {
  30. if (file_exists($bhconfig['bhfilepath']."/layouts/".$layout."/skins/".$skin."/skin.inc.php")) {
  31. # Load the defs file
  32. $bhskin = array();
  33. require $bhconfig['bhfilepath']."/layouts/".$layout."/skins/".$skin."/skin.inc.php";
  34. foreach ($bhskin as $key=>$value) {
  35. $bhskins[$layout.".".$skin][$key] = $value;
  36. }
  37. $bhskins[$layout.".".$skin]['layout'] = $layout;
  38. $bhskins[$layout.".".$skin]['skin'] = $skin;
  39. }
  40. }
  41. }
  42. }
  43. return $bhskins;
  44. }
  45. # To fix weird bugs
  46. function bh_get_docroot() {
  47. return str_replace($_SERVER['PHP_SELF'], "", $_SERVER['SCRIPT_FILENAME']);
  48. }
  49. function htmlpath($relative_path) {
  50. $realpath=realpath($relative_path);
  51. $htmlpath=str_replace(bh_get_docroot(),'',$realpath);
  52. return $htmlpath;
  53. }
  54. function bh_get_weburi() {
  55. global $bhconfig;
  56. if (!empty($bhconfig['baseuri'])) {
  57. if (substr($bhconfig['baseuri'], -1) != "/") { $bhconfig['baseuri'] .= "/"; }
  58. return $bhconfig['baseuri'];
  59. } else {
  60. if($_SERVER['HTTPS']=='on'){$httpsuff = 's';}
  61. if(defined("BH_ROOT")) { $htmlpath = BH_ROOT; } else { $htmlpath = "."; }
  62. return $sysurl = "http".$httpsuff."://".$_SERVER['HTTP_HOST'].htmlpath($htmlpath)."/";
  63. }
  64. }
  65. # Humanises times
  66. function bh_humanise_time($time) {
  67. if ($time == 0) { $time = "Now"; }
  68. elseif (($time) < (60)) { $time = $time." seconds"; }
  69. elseif (($time) < (60*60)) { $time = ceil($time/60)." mins"; }
  70. elseif (($time) < (60*60*24)) { $time = ceil($time/(60*60))." hours"; }
  71. elseif (($time) < (60*60*24*7)) { $time = ceil($time/(60*60*24))." days"; }
  72. elseif (($time) < (60*60*24*365)) { $time = ceil($time/(60*60*24*7))." weeks"; }
  73. elseif (($time) < (60*60*24*365*5)) { $time = ceil($time/(60*60*24*7*365))." years"; }
  74. elseif (($time) < (60*60*24*365*5*10)) { $time = ceil($time/(60*60*24*7*365))." decades"; }
  75. elseif (($time) < (60*60*24*365*5*100)) { $time = ceil($time/(60*60*24*7*365))." centuries"; }
  76. elseif (($time) < (60*60*24*365*5*1000)) { $time = ceil($time/(60*60*24*7*365))." millenia"; }
  77. else { $time = "Nearly forever"; }
  78. return $time;
  79. }
  80. # Humanises file sizes
  81. function bh_humanise_filesize($size) {
  82. $counter=0;
  83. while ($size > 1024) {$size=$size/1024; ++$counter;}
  84. switch ($counter) {
  85. case 2: $mysymbol="MB"; break;
  86. case 1: $mysymbol="KB"; break;
  87. case 0: $mysymbol="B"; break;
  88. case 3: $mysymbol="GB"; break;
  89. case 4: $mysymbol="TB"; break;
  90. case 5: $mysymbol="PB"; break;
  91. case 6: $mysymbol="EB"; break;
  92. case 7: $mysymbol="ZB"; break;
  93. case 8: $mysymbol="YB"; break;
  94. }
  95. return sprintf("%01.1f %s", $size, $mysymbol);
  96. }