fix lists in readme
[sview.git] / s.php
1 <?php
2
3 //Function to get resources (using $nlevels below)
4 function r($toppath) {
5 global $nlevels;
6 $res = '';
7 for ($i=0; $i<$nlevels; $i++)
8 $res .= '../';
9 $res .= $toppath;
10 return $res;
11 }
12
13 //////////////////////////////////////////////////
14
15 //Start buffering output
16 ob_start();
17
18 //Report any error
19 error_reporting(E_ALL);
20
21 //Sub-path path to the currently running script. If we're directly on top of a
22 //domain, this will probably be empty, else for instance: /john/mysite
23 $subpath = str_replace('/index.php', '', $_SERVER['PHP_SELF']);
24
25 //Turn a request like /john/mysite/get/page.php?a=32 into /get/page.php?a=32
26 $request = str_replace($subpath, '', $_SERVER['REQUEST_URI']);
27
28 //Turn a request like /get/page.php?a=32 into get/page?a=32
29 $request = str_replace('.php', '', $request);
30
31 //Keep only what stands before '?' : get/page
32 $location = trim(explode('?', $request)[0], '/');
33 //[HACK] The following works better on my university server
34 //~ $interrmark = strrpos($request, '?');
35 //~ $location = trim(($interrmark!==FALSE ? substr($request,0,$interrmark) : $request), '/');
36
37 //If the user asked for main index.php, consider he wanted home page
38 if ($location == 'index') $location = '';
39
40 //[HACK] Count the number of sub-levels to go up to meet assets folder
41 $nlevels = substr_count($location, '/');
42
43 //Turn get/page into site/get/page.php
44 $phpfile = 'site/'.(strlen($location)>0?$location:'home').'.php';
45
46 //Include default values for title, headers, javascripts...
47 include 'defaults.php';
48
49 //Include common PHP code (functions and constants)
50 include 'common.php';
51
52 //Finally, include the PHP file
53 include (file_exists($phpfile) ? $phpfile : 'site/404.php');
54
55 //regular template: flush output into $content variable
56 $content = ob_get_contents();
57 ob_end_clean();