View difference between Paste ID: PKzb3Ma4 and 9EtXs7Rs
SHOW: | | - or go back to the newest paste.
1
<?php
2
3
function ShowDoc ($file)
4
{
5
    
6
    echo "<div style='background-color: #A0A0A0; width: 100%; font-size: 20px; padding: 3px; margin-top: 10px;'>File $file</div><br>";
7
    
8
    $code = file_get_contents($file);
9
    $pos = 0;
10
    $len = strlen($code);
11
    
12
    $brackets = 0;
13
    
14
    $bracketClass = array(0);
15
    
16
    $inSpecialComment = false;
17
    $specialComment = "";
18
    $inClass = 0;
19
    $class = "";
20
    
21
    for ($i = 0; $i < $len; $i ++)
22
    {
23
        $c = $code[$i];
24
        // Special comment!
25
        if ($c == "/" && $code[$i + 1] == "*" && $code[$i + 2] == "*")
26
        {
27
            $i += 2;
28
            $specialComment = "";
29
            $inSpecialComment = true;
30
        }
31
        else if ($inSpecialComment && $c == "*" && $code[$i + 1] == "/")
32
        {
33
            $i ++;
34
            $specialComment = preg_replace("/^\\s+\\*/m", "", $specialComment);
35
            $inSpecialComment = false;
36
        }
37
        else if ($inSpecialComment)
38
            $specialComment .= $c;
39
        else if (substr($code, $i, 6) == "class " && $specialComment != "")
40
        {
41
            $signature = trim(substr($code, $i, strpos($code, "\n", $i) - $i));
42
            
43
            echo "<table border='0' cellspacing='0' cellpadding='5' style='border: solid 1px black; margin-bottom: 5px; width: 100%;'>";
44
            list (, $class, ) = explode(" ", $signature);
45
            $wiki = @file_get_contents("http://www.nw-engine.com/wiki/index.php/Class_$class");
46
            if ($wiki == "" || strpos($wiki, "There is currently no text in this page.") !== FALSE)
47
                echo "<tr style='background-color: #E0E0E0;'><td colspan='2'><b>" . str_replace(" ", "&nbsp;", $signature) . "</b></td>";
48
            else
49
                echo "<tr style='background-color: #E0E0E0;'><td colspan='2'><a href='http://www.nw-engine.com/wiki/index.php/Class_$class'><b>" . str_replace(" ", "&nbsp;", $signature) . "</b></a></td>";
50
            echo "<td width='70%'>$specialComment</td></tr>";
51
            echo "<tr><td style='width: 20px;'></td><td colspan='2'>";
52
            $specialComment = "";
53
            $bracketClass[] = $brackets;
54
            $inClass ++;
55
        }
56
        else if (substr($code, $i, 9) == "function " && $specialComment != "")
57
        {
58
            $start = strrpos(substr($code, 0, $i), "\n");
59
            $signature = trim(substr($code, $start, strpos($code, "\n", $i) - $start));
60
            if (strpos($signature, "private ") === FALSE)
61
            {
62
                echo "<table border='0' cellspacing='0' cellpadding='0' style='margin-bottom: 5px; width: 100%; border: solid 1px #A0A0A0;'>";
63
                $signature = str_replace(array("public ", "function "), array("", ""), $signature);
64
                if (strpos($signature, "static ") !== FALSE)
65
                    $signature = str_replace("static ", "$class::", $signature);
66
                echo "<tr style='background-color: #E0E0E0;'><td colspan='2'><b>" . str_replace(" ", "&nbsp;", $signature) . "</b></td></tr>";
67
                $lines = preg_split("/^\\s+@/m", $specialComment);
68
                echo "<td width='20%'>&nbsp;</td><td>{$lines[0]}</td></tr>";
69
                array_shift($lines);
70
                foreach ($lines as $line)
71
                {
72
                    $line = trim($line);
73
                    if (substr($line, 0, 5) == "param")
74
                        $line = "<b>Parameter</b> " . substr($line, 5);
75
                    else if (substr($line, 0, 7) == "return ")
76
                        $line = "<b>Returns</b> " . substr($line, 7);
77
                    echo "<tr><td>&nbsp;</td><td>$line</td></tr>";
78
                }
79
                echo "</table>";
80
            }
81
            $specialComment = "";
82
        }
83
        else if ($c == "{")
84
            $brackets ++;
85
        else if ($c == "}")
86
        {
87
            $brackets --;
88
            if ($brackets <= $bracketClass[count($bracketClass) - 1] && $inClass > 0)
89
            {
90
                if (count($bracketClass) > 1)
91
                    array_pop($bracketClass);
92
                $inClass --;
93
                echo "</td></tr></table>";
94
            }
95
        }
96
    }
97
}
98
99
ShowDoc("demo/libs/common.php");
100
ShowDoc("demo/libs/template.php");
101
ShowDoc("demo/libs/db.php");
102
ShowDoc("demo/libs/items.php");
103
ShowDoc("demo/libs/stats.php");
104
ShowDoc("demo/libs/roles.php");
105
ShowDoc("demo/libs/ajax.php");