documentation2.php 3.8 KB
Newer Older
zYne's avatar
zYne committed
1 2 3
<?php
include("top.php"); 
require_once("highlight.php");
zYne's avatar
zYne committed
4
error_reporting(E_ALL);
zYne's avatar
zYne committed
5
set_include_path(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'vendor/');
zYne's avatar
zYne committed
6

zYne's avatar
zYne committed
7 8 9 10 11
$f = file_get_contents('menu.php');
$a = explode(PHP_EOL, $f);
$res = array();
$curr = false;

zYne's avatar
zYne committed
12
require_once('Text/Wiki.php');
pookey's avatar
pookey committed
13
require_once('Text/Wiki/Mediawiki.php');
zYne's avatar
zYne committed
14 15 16



zYne's avatar
zYne committed
17 18 19 20 21 22

class DocTool
{
    private $index;
    
    protected $highlighter;
zYne's avatar
zYne committed
23 24
    
    protected $wiki;
zYne's avatar
zYne committed
25 26 27 28

    public function __construct()
    {
        $this->highlighter = new PHP_Highlight;
zYne's avatar
zYne committed
29
        $this->wiki = new Text_Wiki;
zYne's avatar
zYne committed
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
    }
    public function parseIndex2($index)
    {
    	$ret = array();
        $path = array();
        $counters = array();

        foreach ($index as $k => $v) {
            if (empty($v)) {
                continue;
            }
            $v = rtrim($v);
            $i = count($path) - 1;

            $i = ($i > 0) ? $i : 0;

            $indent = substr_count($v, '    ');

            if ( ! isset($counters[$indent])) {
                $counters[$indent] = 0;
            }

            if ($indent > $i) {
                $counters[$indent]++;

                $path[] = trim($v);
            } else {
                $steps = abs($i - $indent);

                $key = ($i - $steps);
                while ($steps--) {
                    array_pop($path);
                    array_pop($counters);
                }
                
                $counters[$key]++;

                $path[$key] = trim($v);
            }

            $chapterName = implode(' - ', $path);

            $ret[] = array('index' => implode('.', $counters),
                           'name'  => $chapterName);

        }
        return $ret;
    }   

zYne's avatar
zYne committed
79 80
    public function renderBlock($name) 
    {
zYne's avatar
zYne committed
81

zYne's avatar
zYne committed
82
        if (file_exists("docs/$name.php")) {
zYne's avatar
zYne committed
83 84
            $c = file_get_contents("docs/$name.php");

zYne's avatar
zYne committed
85
            if (substr($c, 0, 5) == "<?php") {
zYne's avatar
zYne committed
86
                include("docs/$name.php");
zYne's avatar
zYne committed
87
            } elseif (strpos($c, '<br \>') !== false || 
88
                      strpos($c, '<br />') !== false ||
zYne's avatar
zYne committed
89 90
                      strpos($c, '<ul>') !== false ||
                      strpos($c, '<p>') !== false) {
zYne's avatar
zYne committed
91
                print $c;
zYne's avatar
zYne committed
92
            } else {
zYne's avatar
zYne committed
93
                print $this->wiki->transform($c) . "<br><br>";
zYne's avatar
zYne committed
94 95
            }
        }
zYne's avatar
zYne committed
96
        if (file_exists("codes/$name.php")) {
zYne's avatar
zYne committed
97 98 99 100 101
            $c = file_get_contents("codes/$name.php");
            $c = trim($c);
            $this->renderCode($c);
        }
    }
zYne's avatar
zYne committed
102 103
    public function renderCode($code = null) 
    {
zYne's avatar
zYne committed
104 105 106 107
        if( ! empty($code)) {
    
            $this->highlighter->loadString($code);
    
zYne's avatar
zYne committed
108
            print "<table border=1 class='dashed' cellpadding=0 cellspacing=0>";
zYne's avatar
zYne committed
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
            print "<tr><td><b>";
    
            $this->highlighter->toHtml();
            print "</b></td></tr>";
            print "</table>";
        }
    }
}
print "<pre>";
$doc = new DocTool();

function renderCode($code = null)
{
    global $doc;
    
    return $doc->renderCode($code);
}
$i   = $doc->parseIndex2($a);

//print_r($i);

?>
<table width="100%" cellspacing=0 cellpadding=0>
    <tr>
        <td width=50>
        <td>
        <td align="left" valign="top">
            <table width="100%" cellspacing=0 cellpadding=0>
            <tr>
zYne's avatar
zYne committed
138
                <td colspan=3 bgcolor="white">
zYne's avatar
zYne committed
139 140 141 142 143 144 145
                <img src="images/logo.jpg" align="left"><b class="title">Doctrine - PHP Data Persistence and ORM Tool</b>
                <hr>
                </td>
            </tr>
            <tr>
                <td bgcolor="white" valign="top">
                <?php
zYne's avatar
zYne committed
146
                include('content.php');
zYne's avatar
zYne committed
147 148 149 150 151 152 153 154
                ?>
                </td>
            </tr>
        </td>
        <td>
        </td>
    </tr>
</table>