-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
107 lines (84 loc) · 3.37 KB
/
Copy pathindex.php
File metadata and controls
107 lines (84 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
error_reporting(E_ALL);
$config = include 'config.php';
include_once 'libs/Request/Path.php';
include_once 'libs/Template.php';
include_once 'libs/markdown.php';
$rq = new Awf_Request_Path();
$file = $rq->toArray();
$suite = array_shift($file);
$suites = array_keys($config['tests']);
if (empty($suite) || !isset($config['tests'][$suite])) $suite = $suites[0];
$testsPath = $config['tests'][$suite];
$defaultFile = 'intro';
// Determine the right file
if (empty($file)) $file = $defaultFile;
else $file = implode('/', $file);
//$file = preg_replace('/[^a-zA-Z0-9\-\.\/]+/','',str_replace('../','',$file));
$filePath = $testsPath . '/' . $file . '.html';
if (!file_exists($filePath)){
$file = $defaultFile;
$filePath = 'templates/' . $file . '.html';
}
// Create template instance
$tpl = new Awf_Template();
$tpl->baseurl = $baseurl = $_SERVER['SCRIPT_NAME'];
$tpl->basepath = $basepath = str_replace('index.php', '', $baseurl);
$slashPos = strrpos($file, '/', -1);
$tpl->title = str_replace('_', ' ', ($slashPos !== false) ? substr($file, $slashPos + 1) : $file);
$tpl->suite = $suite;
$tpl->appName = $config['app-name'];
$tpl->jasmine = $config['jasmine'];
$tpl->fireBugLight = $config['fireBugLight'];
// Get the content
$content = file_get_contents($filePath);
// Replace urls with the right ones
$content = explode('href="/', $content);
foreach ($content as &$part){
if (substr($part, 0, 4) == 'asset') $baseurl . '/' . $part;
}
$content = implode('href="/', $content);
// Replace script src attribute
$content = str_replace('/Tests/', $basepath.$testsPath . '/', $content);
$content = str_replace('/depender/build', $basepath . 'build.php', $content);
$content = str_replace('/asset/more/', $basepath . $testsPath . '/_assets/', $content);
$content = preg_replace('/\/ajax_((html|json)_echo)\//', $basepath . 'ajax.php', $content);
$content = preg_replace('/\/echo\/jsonp[\/]?/', $basepath . 'ajax.php?jsonp=1', $content);
$tpl->content = $content;
// Get the menu
$menu = array();
$tests = array(); // all tests
foreach ($config['tests'] as $suiteName => $path){
$categories = array(); // tests by category
$dir = new DirectoryIterator($path);
foreach ($dir as $fileinfo){
if (!$fileinfo->isDot() && $fileinfo->isDir() && $fileinfo->getFilename() != '_assets'){
$category = array();
$catName = $fileinfo->getFilename();
$dir2 = new DirectoryIterator($path . '/' . $fileinfo->getFilename());
foreach ($dir2 as $fileinfo2){
if ($fileinfo2->isFile() && substr($fileinfo2->getFilename(), -5) == '.html'){
$test = str_replace('.html', '', $fileinfo2->getFilename());
$category[] = $test;
if ($suite == $suiteName) $tests[] = $catName . '/' . $test; // previous and next
}
}
$categories[$catName] = $category;
}
}
$menu[$suiteName] = $categories;
}
$tpl->menu = $menu;
// Get previous and next test
$testIndex = array_search($file, $tests);
$nextTest = $prevTest = false;
if ($testIndex !== false){
if (isset($tests[$testIndex + 1])) $nextTest = $tests[$testIndex + 1];
if (isset($tests[$testIndex - 1])) $prevTest = $tests[$testIndex - 1];
}
$tpl->nextTest = $nextTest;
$tpl->nextTestTitle = str_replace('_', ' ', substr($nextTest, strrpos($nextTest, '/', -1) + 1));
$tpl->prevTest = $prevTest;
$tpl->prevTestTitle = str_replace('_', ' ', substr($prevTest, strrpos($prevTest, '/', -1) + 1));
// Fire the page!!
$tpl->display('index.php');