HtmlExport.class.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. require_once(__DIR__.SLASH.'TextExport.class.php');
  3. class HtmlExport extends TextExport{
  4. public $mime = 'text/html';
  5. public $extension = 'html';
  6. public $description = 'Fichier page web HTML';
  7. public function sample($dataset,$level = 0,$parent=''){
  8. $stream = '<!DOCTYPE html><html lang="fr"><head><meta charset="utf-8"></head><body>';
  9. $stream .= self::recursive_sample($dataset, $level,$parent);
  10. $stream .= '</body></html>';
  11. return $stream;
  12. }
  13. public function recursive_sample($dataset,$level = 0,$parent=''){
  14. $stream = '';
  15. $parent = ($parent!=''?$parent.'.':'');
  16. $indentation = str_repeat("<div style='width:20px;display:inline-block;height:10px;'></div>", $level);
  17. foreach($dataset as $macro => $infos){
  18. $infos['type'] = isset($infos['type']) ? $infos['type'] : '';
  19. switch($infos['type']){
  20. case 'list':
  21. $stream .= $indentation.'<h3>-'.$parent.$macro.' '.(isset($infos['label'])?': '.$infos['label']:'').' (liste)'.'</h3>'.PHP_EOL;
  22. $stream .= $indentation.'{{#'.$parent.$macro.'}}'.'<br/>'.PHP_EOL;;
  23. if(is_array($infos['value']) && isset($infos['value'][0])) $stream .= self::sample($infos['value'][0],$level+1);
  24. $stream .=$indentation.'<br>{{/'.$parent.$macro.'}}';
  25. break;
  26. case 'image':
  27. $stream .= $indentation.'<img src="{{'.$parent.$macro.'::image}}">'.$infos['label'];
  28. break;
  29. case 'object':
  30. $stream .= '<h3>'.$indentation.'-'.$parent.$macro.' '.(isset($infos['label'])?': '.$infos['label']:'').'</h3>'.PHP_EOL;;
  31. $stream .= self::sample($infos['value'],$level+1,$parent.$macro);
  32. break;
  33. default :
  34. $stream .= $indentation.'{{'.$parent.$macro.'}} : '.( !isset($infos['label']) ? '': $infos['label']).'<br/>'.PHP_EOL;
  35. break;
  36. }
  37. }
  38. return $stream;
  39. }
  40. public function formatValue($type,$value){
  41. if($type == 'image') return 'data:image/png;base64,'.base64_encode($value);
  42. return $value;
  43. }
  44. }
  45. ?>