Subversion Repositories Sites.tela-botanica.org

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
420 florian 1
<?php
2
if (!defined("WIKINI_VERSION"))
3
{
4
            die ("acc&egrave;s direct interdit");
5
}
6
 
7
if (!function_exists("wakka2callbacktableaux"))
8
{
9
	function parsetable($thing)
10
	{
11
		$tableattr = 'border="1"';
12
//		echo "parsetable debut : \$thing = $thing<br>";
13
		// recuperation des attributs
14
		preg_match("/^\[\|(.*)$/m",$thing,$match);
15
//		echo "parsetable : \$match = ";var_dump($match);echo "<br>";
16
		if ($match[1]){
17
			$tableattr = $match[1];
18
		}
19
		$table = "<table $tableattr >\n";
20
		//suppression de [|xxxx et de |]
21
		$thing = preg_replace("/^\[\|(.*)$/m","",$thing);
22
		$thing = trim(preg_replace("/\|\]/m","",$thing));
23
//		echo "parsetable suppression [| |]: \$thing = $thing<br>";
24
		//recuperation de chaque ligne
25
		$rows = preg_split("/$/m",$thing,-1,PREG_SPLIT_NO_EMPTY);
26
//		echo "parsetable preg_split:";var_dump($rows);echo "<br>";
27
		//analyse de chaque ligne
28
		foreach ($rows as $row){
29
			$table .= parsetablerow($row);
30
		}
31
		$table.= "</table>";
32
		return $table;
33
	}
34
	//parse la definition d'une ligne
35
	function parsetablerow($row)
36
	{
37
		$rowattr = "";
38
 
39
		$row = trim($row);
40
//		echo "parsetablerow debut : \$row = $row<br>";
41
		//detection des attributs de ligne => si la ligne ne commence pas par | alors attribut
42
		if (!preg_match("/^\|/",$row,$match)){
43
			preg_match("/^!([^\|]*)!\|/",$row,$match);
44
			$rowattr = $match[1];
45
//			echo "\$rowattr = $rowattr<br>";
46
			$row = trim(preg_replace("/^!([^\|]*)!/","",$row));
47
		}
48
		$result .= "   <tr $rowattr>\n";
49
		$row = trim(preg_replace("/^\|/","",trim($row)));
50
		$row = trim(preg_replace("/\|$/","",trim($row)));
51
//		echo "parsetablerow sans attribut : \$row = $row<br>";
52
 
53
		//recuperation de chaque cellule
54
		$cells = explode("|",$row);	//nb : seule les indices impaire sont significatif
55
//		echo "parsetablerow preg_split \$cells:";var_dump($cells);echo "<br>";
56
		$i=0;
57
		foreach ($cells as $cell){
58
//			if ($i % 2){
59
//				echo "\$cell = $cell<br>";
60
				$result .= parsetablecell($cell);
61
//			}
62
			$i++;
63
		}
64
		$result .= "   </tr>\n";
65
		return $result;
66
	}
67
	//parse la definition d'une cellule
68
	function parsetablecell($cell)
69
	{
70
		global $wiki;
71
		$cellattr = "";
72
 
73
		if (preg_match("/^!(.*)!/",$cell,$match)){
74
			$cellattr = $match[1];
75
		}
76
		$cell = preg_replace("/^!(.*)!/","",$cell);
77
		//si espace au debut => align=right
78
		//si espace a la fin => align=left
79
		//si espace debut et fin => align=center
80
		if (preg_match("/^\s(.*)/",$cell)){
81
			$align="right";
82
		}
83
		if (preg_match("/^(.*)\s$/",$cell)){
84
			$align="left";
85
		}
86
		if (preg_match("/^\s(.*)\s$/",$cell)){
87
			$align="center";
88
		}
89
		if ($align) $cellattr .= " align=\"$align\"";
90
//		echo "\$this->classname = ".get_class($wiki)."<br>";
91
		return "      <td $cellattr>".$wiki->Format($cell)."</td>\n";
92
	}
93
 
94
 
95
 
96
    function wakka2callbacktableaux($things)
97
    {
98
            $thing = $things[1];
99
 
100
            global $wiki;
101
 
102
			if (preg_match("/^\[\|(.*)\|\]/s", $thing)) {
103
				$thing=preg_replace("/<br \/>/","", $thing);
104
				return parsetable($thing);
105
			}
106
 
107
            // if we reach this point, it must have been an accident.
108
            return $thing;
109
    }
110
 
111
}
112
 
113
$plugin_output_new = preg_replace_callback("/(^\[\|.*?\|\])/ms", "wakka2callbacktableaux", $plugin_output_new);