Subversion Repositories Applications.papyrus

Rev

Rev 1372 | Details | Compare with Previous | Last modification | View Log | RSS feed

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