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