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

/Server/SWXPHP/2.00/php/services/index.php

http://swx-format.googlecode.com/
PHP | 440 lines | 229 code | 178 blank | 33 comment | 60 complexity | b0ebd9f9e4c32a2ffda40c464ec4d810 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. <?php
  2. // Tell the service explorer not to list this file.
  3. //no_explore
  4. // Init stuff
  5. $resdir = '_idvr';
  6. $version = '2006.5';
  7. require $resdir.'/functions.php';
  8. $starttime = microtime_c(); // PHP4 compatible microtime, see functions.php for details
  9. define('base', dirname(__file__));
  10. define('NL', "\n");
  11. // Load config
  12. if(file_exists($configfile = $resdir.'/config.ini')) {
  13. $conf = parse_ini_file($configfile);
  14. } else {
  15. die('Error: could not load configuration file (config.ini). Please make sure it is in the '.$resdir.' directory.');
  16. }
  17. // Load language file
  18. if(file_exists($langfile = $resdir.'/languages/'.$conf['Language'].'.ini')) {
  19. $lang = parse_ini_file($langfile, true);
  20. } else {
  21. die('Error: could not load language file "'.$conf['Language'].'.ini". Please check your Language setting in '.$resdir.'/config.ini and make sure the appropriate language file exists in '.$resdir.'/languages.');
  22. }
  23. // More initialization
  24. $filters = array();
  25. $headers = array();
  26. $templist = array();
  27. $list = array();
  28. $count = array('file' => 0, 'dir' => 0);
  29. $filelist = '';
  30. $totalsize = 0;
  31. $themeinfo = '';
  32. $dir_c = ''; // Client-side directory
  33. $dir_s = ''; // Server-side directory
  34. $dir_a = false; // Whether this directory can be viewed
  35. $newlocation = false;
  36. // Clear stat cache if DisableStatCache is set to true
  37. if($conf['DisableStatCache']) clearstatcache();
  38. // Prepare filters
  39. require $resdir.'/filters.php';
  40. $filters = prepare_filters($filters);
  41. // Check GET['dir'] data, clean up if necessary
  42. $dir_c = isset($_GET['dir']) ? $_GET['dir'] : false;
  43. $dir_s = pathcheck($dir_c, base);
  44. $dir_c = substr($dir_s, strlen(base)+1);
  45. if(isset($_GET['dir'])) {
  46. if($_GET['dir'] !== $dir_c) {
  47. $newlocation = './'.($dir_c ? '?dir='.pathurlencode($dir_c) : '');
  48. } elseif($conf['DisableHiddenDirectViewing']) {
  49. // Check if Show filters match current directory
  50. foreach($filters['show'] as $showf) {
  51. if(preg_match($showf, $dir_c)) {
  52. $dir_a = true;
  53. break;
  54. }
  55. }
  56. // Check if Hide filters match current directory
  57. if($dir_a) {
  58. foreach($filters['hide'] as $hidef) {
  59. if(preg_match($hidef, $dir_c)) {
  60. $dir_a = false;
  61. break;
  62. }
  63. }
  64. }
  65. // If hidden, go back to root directory
  66. if(!$dir_a) {
  67. $newlocation = './';
  68. }
  69. }
  70. }
  71. if($newlocation) redirect($newlocation);
  72. $dir_c = (string) $dir_c;
  73. // Create table headers
  74. $headers['name'] = $lang['Headers']['Name'];
  75. if($conf['ShowSizes']) $headers['size'] = $lang['Headers']['Size'];
  76. if($conf['ShowPerms']) $headers['perms'] = $lang['Headers']['Permissions'];
  77. if($conf['ShowModTimes']) $headers['modtime'] = $lang['Headers']['ModTime'];
  78. // The dirty work
  79. if($files = glob($dir_s.'/*')) {
  80. foreach($files as $n => $rfile) {
  81. $file = array();
  82. $file['raw'] = substr($rfile, strlen(base)+1);
  83. $file['show'] = false;
  84. $file['type'] = (is_dir($file['raw'])) ? 'dir' : 'file';
  85. $file['name'] = basename($file['raw']).($file['type'] == 'dir' && $conf['DirAppendSlashes'] ? '/' : '');
  86. $file['link'] = ($file['type'] == 'dir' ? '?dir=' : '').pathurlencode($file['raw']);
  87. // Check Show filters
  88. foreach($filters['show'] as $showf) {
  89. if(preg_match($showf, $file['raw'])) {
  90. $file['show'] = true;
  91. break;
  92. }
  93. }
  94. // If file matched any Show filter, check Hide filters
  95. if($file['show']) {
  96. foreach($filters['hide'] as $hidef) {
  97. if(preg_match($hidef, $file['raw'])) {
  98. $file['show'] = false;
  99. break;
  100. }
  101. }
  102. }
  103. if($file['show']) {
  104. // Create a temporary list that can be sorted easily
  105. $templist[$n]['name'] = $file['name'];
  106. $templist[$n]['type'] = $file['type'];
  107. $templist[$n]['link'] = $file['link'];
  108. $templist[$n]['raw'] = $file['raw'];
  109. if($conf['ShowSizes']) {
  110. if($conf['FileSizeType'] == 'recursive') {
  111. $file['size'] = rfilesize($file['raw']);
  112. } elseif($conf['FileSizeType'] == 'diskspace') {
  113. $file['size'] = filespace($file['raw']);
  114. } else {
  115. $file['size'] = filesize($file['raw']);
  116. }
  117. $totalsize += $templist[$n]['size'] = $file['size'];
  118. }
  119. if($conf['ShowPerms']) {
  120. $file['perms'] = substr(sprintf('%o', fileperms($file['raw'])), -3);
  121. $templist[$n]['perms'] = ($conf['FilePermsType'] == 'symbolic' ? oct2sym($file['perms']) : $file['perms']);
  122. }
  123. if($conf['ShowModTimes']) {
  124. $file['modtime'] = filemtime($file['raw']);
  125. $templist[$n]['modtime'] = $file['modtime'];
  126. }
  127. if($conf['ShowFileCount']) {
  128. $count[$file['type']]++;
  129. }
  130. }
  131. }
  132. // Sorting
  133. // customsort() checks the config options, so no check is needed here
  134. // See functions.php for more details
  135. customsort($templist);
  136. }
  137. $filecount = count($templist);
  138. // Check if the list contains any items
  139. if($filecount > 0) {
  140. // Assemble the final list
  141. foreach($templist as $n => $tlval) {
  142. $list[$n]['name'] = '<a class="'.$tlval['type'].'" href="'.$tlval['link'].'">'.htmlentities($tlval['name']).'</a>';
  143. // Has user asked for PHP files to be displayed as source instead of run?
  144. if ($conf['ShowPHPSource'])
  145. {
  146. // Yes, see if this is a PHP file and, if so, make a link to display its source.
  147. if (substr($tlval['name'], -4, 4) == '.php')
  148. {
  149. $list[$n]['name'] = '<a class="'.$tlval['type'].'" href="'.$resdir.'/showsource.php?file=../'.$tlval['link'].'" target="_blank">'.htmlentities($tlval['name']).'</a>';
  150. }
  151. else
  152. {
  153. // Make it a regular link
  154. $list[$n]['name'] = '<a class="'.$tlval['type'].'" href="'.$tlval['link'].'">'.htmlentities($tlval['name']).'</a>';
  155. }
  156. }
  157. if($conf['ShowSizes']) $list[$n]['size'] = htmlentities($conf['FileSizeType'] == 'simple' && $tlval['type'] == 'dir' ? '--' : efilesize($tlval['size'], $conf['RoundSizes'], $lang['Num']));
  158. if($conf['ShowPerms']) $list[$n]['perms'] = htmlentities($tlval['perms']);
  159. if($conf['ShowModTimes']) $list[$n]['modtime'] = htmlentities(date($conf['DateTimeFormat'], $tlval['modtime']));
  160. }
  161. } else {
  162. // Empty list
  163. $list[0]['name'] = htmlentities($lang['General']['EmptyName']);
  164. if($conf['ShowSizes']) $list[0]['size'] = htmlentities($lang['General']['Empty']);
  165. if($conf['ShowPerms']) $list[0]['perms'] = htmlentities($lang['General']['Empty']);
  166. if($conf['ShowModTimes']) $list[0]['modtime'] = htmlentities($lang['General']['Empty']);
  167. }
  168. // Construct table
  169. $filelist .= '<table id="list">'.NL;
  170. $filelist .= '<tr>'.NL;
  171. foreach($headers as $headerk => $headerv) {
  172. $filelist .= '<th class="'.$headerk.'"><span>'.htmlentities($headerv).'</span></th>'.NL;
  173. }
  174. $filelist .= '</tr>'.NL;
  175. foreach($list as $item) {
  176. $filelist .= '<tr>'.NL;
  177. foreach($item as $itemk => $itemv) {
  178. $filelist .= '<td class="'.$itemk.'"><span>'.$itemv.'</span></td>'.NL;
  179. }
  180. $filelist .= '</tr>'.NL;
  181. }
  182. $filelist .= '</table>'.NL;
  183. ?>
  184. <html>
  185. <head>
  186. <title><?php echo htmlentities($conf['Title']); ?></title>
  187. <link rel="stylesheet" type="text/css" href="<?php echo $resdir.'/themes/'.$conf['Theme']; ?>" />
  188. <?php
  189. $oldFolder = getcwd();
  190. $servicesFolder = $oldFolder;
  191. chdir('../../flash/examples/');
  192. $examplesFolder = getcwd();
  193. chdir($oldFolder);
  194. $folderOverride = '../../';
  195. $current = 2; // Set services folder as root.
  196. require('../../site/header.php');
  197. chdir($oldFolder);
  198. ?>
  199. <div id="wrap">
  200. <h1><?php echo '<b>'.htmlentities($conf['Header']).'</b>'.($conf['ShowDateTime'] ? ' :: '.date($conf['DateTimeFormat']) : ''); ?></h1>
  201. <?php
  202. // InfoBox; parse comments away and evaluate
  203. if($conf['InfoBox']) {
  204. $ibContent = file_get_contents($resdir.'/infobox.php');
  205. infobox('info1', $ibContent);
  206. }
  207. // Same as above, but for a per-directory info box
  208. if($conf['DirInfoBox'] && file_exists($sInfoBox = $dir_s.'/'.$conf['DirInfoBoxFile'])) {
  209. $sIbContent = file_get_contents($sInfoBox);
  210. infobox('info2', $sIbContent);
  211. }
  212. ?>
  213. <div id="files">
  214. <div id="nav">
  215. <?php
  216. // Create the path display
  217. echo '<div id="path">'.construct_path_links($dir_c, $conf['DirectoryLabel']).'</div>'.NL;
  218. // File count
  219. if($conf['ShowFileCount']) {
  220. echo '<span id="filecount">'.NL;
  221. echo htmlentities(sprintf($lang['Nav']['FileCount'], $count['dir'], ($count['dir'] == 1 ? $lang['Nav']['DirsSingular'] : $lang['Nav']['DirsPlural']), $count['file'], ($count['file'] == 1 ? $lang['Nav']['FilesSingular'] : $lang['Nav']['FilesPlural'])));
  222. if($conf['ShowSizes'] && $conf['ShowDirTotalSize']) {
  223. echo '<span id="totalsize">';
  224. echo htmlentities(sprintf($lang['Nav']['TotalSize'], efilesize($totalsize, $conf['RoundSizes'], $lang['Num'])));
  225. echo '</span>'.NL;
  226. }
  227. echo '</span>'.NL;
  228. }
  229. ?>
  230. <br class="cl" />
  231. </div>
  232. <?php echo $filelist; ?>
  233. </div>
  234. <?php
  235. // Page generation time
  236. if($conf['ShowGenTime']) {
  237. $gentime = number_format(microtime_c()-$starttime, $conf['RoundGenTime'], $lang['Num']['DecimalSeparator'], '');
  238. echo '<div id="gentime">';
  239. echo htmlentities(sprintf($lang['Footer']['PageGenerationTime'], $gentime));
  240. echo '</div>'.NL;
  241. }
  242. // Credits
  243. if($conf['ShowCredits']) {
  244. $themecredits = file($resdir.'/themes/'.$conf['Theme']);
  245. if(substr($themecredits[0], 0, 2) == '/*') {
  246. if(
  247. preg_match('#\[thmname\](.*)$#', $themecredits[1], $theme_name) &&
  248. preg_match('#\[creator\](.*)$#', $themecredits[2], $theme_crtr)
  249. ) {
  250. $themeinfo = htmlentities(sprintf($lang['Footer']['CreditsTheme'], $theme_name[1], $theme_crtr[1]));
  251. } else {
  252. $themeinfo = '';
  253. }
  254. }
  255. $credits = '<div id="credits">'.NL.'<a href="http://idv.sf.net">'.htmlentities(sprintf($lang['Footer']['CreditsIDV'], $version)).'</a><span>'.$themeinfo.'</span>'.NL.'</div>';
  256. echo $credits;
  257. }
  258. ?>
  259. <br class="cl" />
  260. </div>
  261. <div id="footer">
  262. <?php require('../../site/footer.php'); ?>