class.displayCode.php
Gesponsorde koppelingen
PHP script bestanden
Code (php)
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/* * * * * * * * * * * * * * * * * * * * * * * * *
* Author : Anthony Huebers
* Email : [email protected]
* Name : display code
* Version : 1.0
* Since : 22-06-2010
* Last updated : 22-06-2010
* * * * * * * */
class displayCode {
/* *
* Store settings
*/
private static $path, $recursive, $displayHidden;
/* *
* Store allowed extensions
*/
private static $allowedExtensions = array();
/* *
* Store files
*/
private static $files = array();
/* *
* Display script by path
*/
public function __construct($allowedExtensions = 'php, ini, js') {
/* *
* Set allowed extensions
*/
return self::$allowedExtensions = explode(',', str_replace(' ', '', $allowedExtensions));
}
public function displayCodeByPath($path, $recursive = true, $displayHidden = false) {
/* *
* Set start load time
*/
$microtime = explode(' ', microtime());
$startLoadTime = $microtime[1] + $microtime[0];
/* *
* Store settings
*/
self::$path = $path;
self::$recursive = $recursive;
self::$displayHidden = $displayHidden;
/* *
* Get files
*/
self::getFiles($path);
/* *
* Create and print table of content
*/
print self::createTableOfContent();
/* *
* Highlight and print files
*/
print self::highlightFiles();
/* *
* Footer with load time
*/
$microtime = explode(' ', microtime());
$loadTime = $microtime[0] + $microtime[1] - $startLoadTime;
print 'Developed by Anthony Huebers - Generated in '.substr($loadTime, 0, 10).' seconds';
}
private function getFiles($dir) {
/* *
* Open directory
*/
$dirHandler = opendir($dir);
while ($file = readdir($dirHandler)) {
/* *
* No hidden files (start with .)
*/
if(self::$displayHidden === true || stripos($file, '.') !== 0) {
/* *
* Check if it's a directory
*/
if(is_dir(($dir.$file)) && self::$recursive === true) {
/* *
* Recursive
*/
self::getFiles($dir.$file.'/', self::$recursive);
}else{
/* *
* Get extension
*/
$extension = substr(strrchr($file, '.'), 1);
/* *
* Store file
*/
if(in_array($extension, self::$allowedExtensions)) {
self::$files[] = $dir.$file;
}
}
}
}
closedir($dirHandler);
}
private function createTableOfContent() {
/* *
* Start
*/
print '<h1>Table Of Content:</h1><ul>';
/* *
* Foreach file
*/
$i = 0;
foreach (self::$files as $file) {
$file = str_replace(self::$path, '', $file);
print '<li><a href="#'.$i++.'">'.$file.'</a></li>';
}
/* *
* Close
*/
print '</ul>';
}
private function highlightFiles() {
/* *
* Foreach file
*/
$i = 0;
foreach (self::$files as $file) {
$filename = str_replace(self::$path, '', $file);
echo '<a name="'.$i++.'"><h2>'.$filename.'</h2></a>';
highlight_file($file);
echo '<hr>';
}
}
}
?>
/* * * * * * * * * * * * * * * * * * * * * * * * *
* Author : Anthony Huebers
* Email : [email protected]
* Name : display code
* Version : 1.0
* Since : 22-06-2010
* Last updated : 22-06-2010
* * * * * * * */
class displayCode {
/* *
* Store settings
*/
private static $path, $recursive, $displayHidden;
/* *
* Store allowed extensions
*/
private static $allowedExtensions = array();
/* *
* Store files
*/
private static $files = array();
/* *
* Display script by path
*/
public function __construct($allowedExtensions = 'php, ini, js') {
/* *
* Set allowed extensions
*/
return self::$allowedExtensions = explode(',', str_replace(' ', '', $allowedExtensions));
}
public function displayCodeByPath($path, $recursive = true, $displayHidden = false) {
/* *
* Set start load time
*/
$microtime = explode(' ', microtime());
$startLoadTime = $microtime[1] + $microtime[0];
/* *
* Store settings
*/
self::$path = $path;
self::$recursive = $recursive;
self::$displayHidden = $displayHidden;
/* *
* Get files
*/
self::getFiles($path);
/* *
* Create and print table of content
*/
print self::createTableOfContent();
/* *
* Highlight and print files
*/
print self::highlightFiles();
/* *
* Footer with load time
*/
$microtime = explode(' ', microtime());
$loadTime = $microtime[0] + $microtime[1] - $startLoadTime;
print 'Developed by Anthony Huebers - Generated in '.substr($loadTime, 0, 10).' seconds';
}
private function getFiles($dir) {
/* *
* Open directory
*/
$dirHandler = opendir($dir);
while ($file = readdir($dirHandler)) {
/* *
* No hidden files (start with .)
*/
if(self::$displayHidden === true || stripos($file, '.') !== 0) {
/* *
* Check if it's a directory
*/
if(is_dir(($dir.$file)) && self::$recursive === true) {
/* *
* Recursive
*/
self::getFiles($dir.$file.'/', self::$recursive);
}else{
/* *
* Get extension
*/
$extension = substr(strrchr($file, '.'), 1);
/* *
* Store file
*/
if(in_array($extension, self::$allowedExtensions)) {
self::$files[] = $dir.$file;
}
}
}
}
closedir($dirHandler);
}
private function createTableOfContent() {
/* *
* Start
*/
print '<h1>Table Of Content:</h1><ul>';
/* *
* Foreach file
*/
$i = 0;
foreach (self::$files as $file) {
$file = str_replace(self::$path, '', $file);
print '<li><a href="#'.$i++.'">'.$file.'</a></li>';
}
/* *
* Close
*/
print '</ul>';
}
private function highlightFiles() {
/* *
* Foreach file
*/
$i = 0;
foreach (self::$files as $file) {
$filename = str_replace(self::$path, '', $file);
echo '<a name="'.$i++.'"><h2>'.$filename.'</h2></a>';
highlight_file($file);
echo '<hr>';
}
}
}
?>