]*)>|is', '<$1>', $value);
		}
		return $value;
	}
	public function end($stream,$data){
		$this->body = $stream;
		
		$this->footer = $this->from_template($this->footer, $data);
		$this->header = $this->from_template($this->header, $data);
		$this->zip->addFromString('word/document.xml', $this->body);
		if(!empty($this->header)) $this->zip->addFromString('word/header1.xml', $this->header);
		if(!empty($this->footer)) $this->zip->addFromString('word/footer1.xml', $this->footer);
		$this->zip->addFromString('word/_rels/document.xml.rels', $this->relationships);
		$this->zip->close();
		
		$stream = file_get_contents($this->destination);
		unlink($this->destination);
		return $stream;
	}
	public function decomposeKey($datas,$key){
		if(array_key_exists($key, $datas)) return isset($datas[$key]) ? $datas[$key] : '' ;
		
		$attributes = explode('.',$key);
		$current = $datas;
		$value = null;
        foreach ($attributes as $attribute) {
        	if(!array_key_exists($attribute, $current))  break;
        	$current = $current[$attribute];
        	$value = isset($current) ?  $current :  '';
        }
        return $value;
	}
	// Converti les data wysiwyg en wysiwyg word
	public static function convert_text_format($value){
		//Remplace les  et les 
 par les w:br word
		$value = str_replace(array('
','
','
',''),'',$value);
		//todo ameliorable
		$value = str_replace(array('- '),' - ',$value);
		$value = str_replace(array(''),'',$value);
		$value = str_replace('
','',$value);
		
        //todo - $value = preg_replace('|([^<]*)|is', '$1', $value);
		return $value;
	}
	public static function strip($content){
		$content = preg_replace_callback(
			'#\{\{([^\]]+)\}\}#U',
			function ($match) {
				return strip_tags($match[0]);
			},
			$content
		);
		return $content;
	}
}
?>