2009-06-16 08:47:07 +00:00
|
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Logiciel : HTML2PDF - classe ParsingHTML
|
|
|
|
|
*
|
|
|
|
|
* Convertisseur HTML => PDF, utilise fpdf de Olivier PLATHEY
|
2010-02-17 14:44:28 +00:00
|
|
|
|
* Distribu<EFBFBD> sous la licence LGPL.
|
2009-06-16 08:47:07 +00:00
|
|
|
|
*
|
2010-02-17 14:44:28 +00:00
|
|
|
|
* @author Laurent MINGUET <webmaster@html2pdf.fr>
|
|
|
|
|
* @version 3.28 - 18/01/2010
|
2009-06-16 08:47:07 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (!defined('__CLASS_PARSINGHTML__'))
|
|
|
|
|
{
|
|
|
|
|
define('__CLASS_PARSINGHTML__', true);
|
|
|
|
|
|
|
|
|
|
class parsingHTML
|
|
|
|
|
{
|
2010-02-17 14:44:28 +00:00
|
|
|
|
var $html = ''; // code HTML <20> parser
|
|
|
|
|
var $code = array(); // code HTML pars<72>
|
|
|
|
|
var $num = 0; // num<75>ro de table
|
2009-06-16 08:47:07 +00:00
|
|
|
|
var $level = 0; // niveaux de table
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructeur
|
|
|
|
|
*
|
|
|
|
|
* @return null
|
|
|
|
|
*/
|
|
|
|
|
function parsingHTML()
|
|
|
|
|
{
|
|
|
|
|
$this->num = 0;
|
|
|
|
|
$this->level = array($this->num);
|
|
|
|
|
$this->html = '';
|
|
|
|
|
$this->code = array();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2010-02-17 14:44:28 +00:00
|
|
|
|
* D<EFBFBD>finir le code HTML <EFBFBD> parser
|
2009-06-16 08:47:07 +00:00
|
|
|
|
*
|
|
|
|
|
* @param string code html
|
|
|
|
|
* @return null
|
|
|
|
|
*/
|
|
|
|
|
function setHTML($html)
|
|
|
|
|
{
|
|
|
|
|
$html = preg_replace('/<!--(.*)-->/isU', '', $html);
|
|
|
|
|
$this->html = $html;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* parser le code HTML
|
|
|
|
|
*
|
|
|
|
|
* @return null
|
|
|
|
|
*/
|
|
|
|
|
function parse()
|
|
|
|
|
{
|
|
|
|
|
$parents = array();
|
2010-02-17 14:44:28 +00:00
|
|
|
|
|
2009-06-16 08:47:07 +00:00
|
|
|
|
// chercher les balises HTML du code
|
|
|
|
|
$tmp = array();
|
2010-02-17 14:44:28 +00:00
|
|
|
|
$this->searchCode($tmp);
|
2009-06-16 08:47:07 +00:00
|
|
|
|
|
2010-02-17 14:44:28 +00:00
|
|
|
|
// identifier les balises une <20> une
|
2009-06-16 08:47:07 +00:00
|
|
|
|
$pre_in = false;
|
|
|
|
|
$pre_br = array(
|
|
|
|
|
'name' => 'br',
|
|
|
|
|
'close' => false,
|
|
|
|
|
'param' => array(
|
|
|
|
|
'style' => array(),
|
|
|
|
|
'num' => 0
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
2010-02-17 14:44:28 +00:00
|
|
|
|
$balises_no_closed = array(
|
|
|
|
|
'br', 'hr', 'img', 'col',
|
|
|
|
|
'input', 'link', 'option',
|
|
|
|
|
'circle', 'ellipse', 'path', 'rect', 'line', 'polygon', 'polyline'
|
|
|
|
|
);
|
2009-06-16 08:47:07 +00:00
|
|
|
|
$todos = array();
|
|
|
|
|
foreach($tmp as $part)
|
|
|
|
|
{
|
|
|
|
|
// si c'est un texte
|
|
|
|
|
if ($part[0]=='txt')
|
|
|
|
|
{
|
|
|
|
|
// enregistrer l'action correspondante
|
|
|
|
|
if (!$pre_in)
|
|
|
|
|
{
|
2010-02-17 14:44:28 +00:00
|
|
|
|
// if (trim($part[1])!=='')
|
|
|
|
|
// {
|
2009-06-16 08:47:07 +00:00
|
|
|
|
// remplacer tous les espaces, tabulations, saufs de ligne multiples par de simples espaces
|
|
|
|
|
$part[1] = preg_replace('/([\s]+)/is', ' ', $part[1]);
|
|
|
|
|
|
|
|
|
|
$todos[] = array(
|
|
|
|
|
'name' => 'write',
|
|
|
|
|
'close' => false,
|
|
|
|
|
'param' => array('txt' => $part[1]),
|
|
|
|
|
);
|
2010-02-17 14:44:28 +00:00
|
|
|
|
// }
|
2009-06-16 08:47:07 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$part[1] = str_replace("\r", '', $part[1]);
|
|
|
|
|
$part[1] = explode("\n", $part[1]);
|
|
|
|
|
|
|
|
|
|
foreach($part[1] as $k => $txt)
|
|
|
|
|
{
|
|
|
|
|
$txt = str_replace("\t", ' ', $txt);
|
|
|
|
|
$txt = str_replace(' ', ' ', $txt);
|
|
|
|
|
if ($k>0) $todos[] = $pre_br;
|
|
|
|
|
|
|
|
|
|
$todos[] = array(
|
|
|
|
|
'name' => 'write',
|
|
|
|
|
'close' => false,
|
|
|
|
|
'param' => array('txt' => $txt),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// sinon, analyser le code
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$res = $this->analiseCode($part[1]);
|
|
|
|
|
if ($res)
|
|
|
|
|
{
|
2010-02-17 14:44:28 +00:00
|
|
|
|
$res['html_pos'] = $part[2];
|
|
|
|
|
if (!in_array($res['name'], $balises_no_closed))
|
2009-06-16 08:47:07 +00:00
|
|
|
|
{
|
|
|
|
|
if ($res['close'])
|
|
|
|
|
{
|
|
|
|
|
if (count($parents)<1)
|
2010-02-17 14:44:28 +00:00
|
|
|
|
@HTML2PDF::makeError(3, __FILE__, __LINE__, $res['name'], $this->getHtmlErrorCode($res['html_pos']));
|
2009-06-16 08:47:07 +00:00
|
|
|
|
else if ($parents[count($parents)-1]!=$res['name'])
|
2010-02-17 14:44:28 +00:00
|
|
|
|
@HTML2PDF::makeError(4, __FILE__, __LINE__, $parents, $this->getHtmlErrorCode($res['html_pos']));
|
2009-06-16 08:47:07 +00:00
|
|
|
|
else
|
|
|
|
|
unset($parents[count($parents)-1]);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2010-02-17 14:44:28 +00:00
|
|
|
|
if ($res['autoclose'])
|
|
|
|
|
{
|
|
|
|
|
$todos[] = $res;
|
|
|
|
|
$res['params'] = array();
|
|
|
|
|
$res['close'] = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
$parents[count($parents)] = $res['name'];
|
|
|
|
|
|
2009-06-16 08:47:07 +00:00
|
|
|
|
}
|
2010-02-17 14:44:28 +00:00
|
|
|
|
if (($res['name']=='pre' || $res['name']=='code') && !$res['autoclose'])
|
|
|
|
|
$pre_in = !$res['close'];
|
2009-06-16 08:47:07 +00:00
|
|
|
|
}
|
2010-02-17 14:44:28 +00:00
|
|
|
|
|
2009-06-16 08:47:07 +00:00
|
|
|
|
$todos[] = $res;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-17 14:44:28 +00:00
|
|
|
|
// pour chaque action identifi<66>e, il faut nettoyer le d<>but et la fin des textes
|
2009-06-16 08:47:07 +00:00
|
|
|
|
// en fonction des balises qui l'entourent.
|
2010-02-17 14:44:28 +00:00
|
|
|
|
$balises_clean = array('page', 'page_header', 'page_footer', 'form',
|
|
|
|
|
'table', 'thead', 'tfoot', 'tr', 'td', 'th', 'br',
|
|
|
|
|
'div', 'hr', 'p', 'ul', 'ol', 'li',
|
|
|
|
|
'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
|
|
|
|
|
'bookmark',
|
|
|
|
|
'draw', 'circle', 'ellipse', 'path', 'rect', 'line', 'g', 'polygon', 'polyline');
|
2009-06-16 08:47:07 +00:00
|
|
|
|
$nb = count($todos);
|
|
|
|
|
for($k=0; $k<$nb; $k++)
|
|
|
|
|
{
|
|
|
|
|
//si c'est un texte
|
|
|
|
|
if ($todos[$k]['name']=='write')
|
|
|
|
|
{
|
2010-02-17 14:44:28 +00:00
|
|
|
|
// et qu'une balise sp<73>cifique le pr<70>c<EFBFBD>de => on nettoye les espaces du d<>but du texte
|
|
|
|
|
if ($k>0 && in_array($todos[$k-1]['name'], $balises_clean))
|
|
|
|
|
$todos[$k]['param']['txt'] = ltrim($todos[$k]['param']['txt']);
|
2009-06-16 08:47:07 +00:00
|
|
|
|
|
2010-02-17 14:44:28 +00:00
|
|
|
|
// et qu'une balise sp<73>cifique le suit => on nettoye les espaces de la fin du texte
|
|
|
|
|
if ($k<count($todos)-1 && in_array($todos[$k+1]['name'], $balises_clean))
|
|
|
|
|
$todos[$k]['param']['txt'] = rtrim($todos[$k]['param']['txt']);
|
|
|
|
|
|
|
|
|
|
if (!strlen($todos[$k]['param']['txt']))
|
|
|
|
|
unset($todos[$k]);
|
2009-06-16 08:47:07 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-02-17 14:44:28 +00:00
|
|
|
|
if (count($parents)) @HTML2PDF::makeError(5, __FILE__, __LINE__, $parents);
|
|
|
|
|
|
|
|
|
|
// liste des actions sauv<75>e
|
|
|
|
|
$this->code = array_values($todos);;
|
2009-06-16 08:47:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* parser le code HTML
|
|
|
|
|
*
|
2010-02-17 14:44:28 +00:00
|
|
|
|
* @param &array tableau de retour des donn<EFBFBD>es
|
2009-06-16 08:47:07 +00:00
|
|
|
|
* @return null
|
|
|
|
|
*/
|
2010-02-17 14:44:28 +00:00
|
|
|
|
function searchCode(&$tmp)
|
2009-06-16 08:47:07 +00:00
|
|
|
|
{
|
2010-02-17 14:44:28 +00:00
|
|
|
|
// s<>parer les balises du texte
|
2009-06-16 08:47:07 +00:00
|
|
|
|
$tmp = array();
|
|
|
|
|
$reg = '/(<[^>]+>)|([^<]+)+/isU';
|
|
|
|
|
|
2010-02-17 14:44:28 +00:00
|
|
|
|
// pour chaque <20>l<EFBFBD>ment trouv<75> :
|
2009-06-16 08:47:07 +00:00
|
|
|
|
$str = '';
|
|
|
|
|
$offset = 0;
|
2010-02-17 14:44:28 +00:00
|
|
|
|
while(preg_match($reg, $this->html, $parse, PREG_OFFSET_CAPTURE, $offset))
|
2009-06-16 08:47:07 +00:00
|
|
|
|
{
|
2010-02-17 14:44:28 +00:00
|
|
|
|
// si une balise a <20>t<EFBFBD> d<>tect<63>e
|
2009-06-16 08:47:07 +00:00
|
|
|
|
if ($parse[1][0])
|
|
|
|
|
{
|
2010-02-17 14:44:28 +00:00
|
|
|
|
// sauvegarde du texte pr<70>c<EFBFBD>dent si il existe
|
2009-06-16 08:47:07 +00:00
|
|
|
|
if ($str!=='') $tmp[] = array('txt',$str);
|
|
|
|
|
|
|
|
|
|
// sauvegarde de la balise
|
2010-02-17 14:44:28 +00:00
|
|
|
|
$tmp[] = array('code',trim($parse[1][0]), $offset);
|
2009-06-16 08:47:07 +00:00
|
|
|
|
|
|
|
|
|
// initialisation du texte suivant
|
|
|
|
|
$str = '';
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2010-02-17 14:44:28 +00:00
|
|
|
|
// ajout du texte <20> la fin de celui qui est d<>j<EFBFBD> d<>tect<63>
|
2009-06-16 08:47:07 +00:00
|
|
|
|
$str.= $parse[2][0];
|
|
|
|
|
}
|
|
|
|
|
// Update offset to the end of the match
|
|
|
|
|
$offset = $parse[0][1] + strlen($parse[0][0]);
|
2010-02-17 14:44:28 +00:00
|
|
|
|
unset($parse);
|
2009-06-16 08:47:07 +00:00
|
|
|
|
}
|
2010-02-17 14:44:28 +00:00
|
|
|
|
// si un texte est pr<70>sent <20> la fin, on l'enregistre
|
2009-06-16 08:47:07 +00:00
|
|
|
|
if ($str!='') $tmp[] = array('txt',$str);
|
|
|
|
|
unset($str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* analyse une balise HTML
|
|
|
|
|
*
|
2010-02-17 14:44:28 +00:00
|
|
|
|
* @param string code HTML <EFBFBD> identifier
|
2009-06-16 08:47:07 +00:00
|
|
|
|
* @return array action correspondante
|
|
|
|
|
*/
|
|
|
|
|
function analiseCode($code)
|
|
|
|
|
{
|
|
|
|
|
// nom de la balise et ouverture ou fermeture
|
|
|
|
|
$balise = '<([\/]{0,1})([_a-z0-9]+)([\/>\s]+)';
|
|
|
|
|
preg_match('/'.$balise.'/isU', $code, $match);
|
|
|
|
|
$close = ($match[1]=='/' ? true : false);
|
2010-02-17 14:44:28 +00:00
|
|
|
|
$autoclose = preg_match('/\/>$/isU', $code);
|
2009-06-16 08:47:07 +00:00
|
|
|
|
$name = strtolower($match[2]);
|
|
|
|
|
|
2010-02-17 14:44:28 +00:00
|
|
|
|
// param<61>tres obligatoires en fonction du nom de la balise
|
2009-06-16 08:47:07 +00:00
|
|
|
|
$param = array();
|
|
|
|
|
$param['style'] = '';
|
|
|
|
|
if ($name=='img') { $param['alt'] = ''; $param['src'] = ''; }
|
|
|
|
|
if ($name=='a') { $param['href'] = ''; }
|
|
|
|
|
|
2010-02-17 14:44:28 +00:00
|
|
|
|
// lecture des param<61>tres du type nom=valeur
|
2009-06-16 08:47:07 +00:00
|
|
|
|
$prop = '([a-zA-Z0-9_]+)=([^"\'\s>]+)';
|
|
|
|
|
preg_match_all('/'.$prop.'/is', $code, $match);
|
|
|
|
|
for($k=0; $k<count($match[0]); $k++)
|
|
|
|
|
$param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]);
|
|
|
|
|
|
2010-02-17 14:44:28 +00:00
|
|
|
|
// lecture des param<61>tres du type nom="valeur"
|
2009-06-16 08:47:07 +00:00
|
|
|
|
$prop = '([a-zA-Z0-9_]+)=["]([^"]*)["]';
|
|
|
|
|
preg_match_all('/'.$prop.'/is', $code, $match);
|
|
|
|
|
for($k=0; $k<count($match[0]); $k++)
|
|
|
|
|
$param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]);
|
|
|
|
|
|
2010-02-17 14:44:28 +00:00
|
|
|
|
// lecture des param<61>tres du type nom='valeur'
|
2009-06-16 08:47:07 +00:00
|
|
|
|
$prop = "([a-zA-Z0-9_]+)=[']([^']*)[']";
|
|
|
|
|
preg_match_all('/'.$prop.'/is', $code, $match);
|
|
|
|
|
for($k=0; $k<count($match[0]); $k++)
|
|
|
|
|
$param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]);
|
|
|
|
|
|
2010-02-17 14:44:28 +00:00
|
|
|
|
// mise en conformit<69> en style de chaque param<61>tre
|
2009-06-16 08:47:07 +00:00
|
|
|
|
$color = "#000000";
|
|
|
|
|
$border = null;
|
|
|
|
|
foreach($param as $key => $val)
|
|
|
|
|
{
|
|
|
|
|
$key = strtolower($key);
|
|
|
|
|
switch($key)
|
|
|
|
|
{
|
|
|
|
|
case 'width':
|
|
|
|
|
unset($param[$key]);
|
|
|
|
|
$param['style'] = 'width: '.$val.'px; '.$param['style'];
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'align':
|
2010-02-17 14:44:28 +00:00
|
|
|
|
if ($name==='img')
|
|
|
|
|
{
|
|
|
|
|
unset($param[$key]);
|
|
|
|
|
$param['style'] = 'float: '.$val.'; '.$param['style'];
|
|
|
|
|
}
|
|
|
|
|
elseif ($name!=='table')
|
2009-06-16 08:47:07 +00:00
|
|
|
|
{
|
|
|
|
|
unset($param[$key]);
|
|
|
|
|
$param['style'] = 'text-align: '.$val.'; '.$param['style'];
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'valign':
|
|
|
|
|
unset($param[$key]);
|
|
|
|
|
$param['style'] = 'vertical-align: '.$val.'; '.$param['style'];
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'height':
|
|
|
|
|
unset($param[$key]);
|
|
|
|
|
$param['style'] = 'height: '.$val.'px; '.$param['style'];
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'bgcolor':
|
|
|
|
|
unset($param[$key]);
|
|
|
|
|
$param['style'] = 'background: '.$val.'; '.$param['style'];
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'bordercolor':
|
|
|
|
|
unset($param[$key]);
|
|
|
|
|
$color = $val;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'border':
|
|
|
|
|
unset($param[$key]);
|
|
|
|
|
if (preg_match('/^[0-9]$/isU', $val)) $val = $val.'px';
|
|
|
|
|
$border = $val;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'cellpadding':
|
|
|
|
|
case 'cellspacing':
|
|
|
|
|
if (preg_match('/^([0-9]+)$/isU', $val)) $param[$key] = $val.'px';
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'colspan':
|
|
|
|
|
case 'rowspan':
|
|
|
|
|
$val = preg_replace('/[^0-9]/isU', '', $val);
|
|
|
|
|
if (!$val) $val = 1;
|
|
|
|
|
$param[$key] = $val;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($border!==null)
|
|
|
|
|
{
|
2010-02-17 14:44:28 +00:00
|
|
|
|
if ($border) $border = 'border: solid '.$border.' '.$color;
|
|
|
|
|
else $border = 'border: none';
|
|
|
|
|
|
|
|
|
|
$param['style'] = $border.'; '.$param['style'];
|
|
|
|
|
$param['border'] = $border;
|
2009-06-16 08:47:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-02-17 14:44:28 +00:00
|
|
|
|
// lecture des styles - d<>composition
|
2009-06-16 08:47:07 +00:00
|
|
|
|
$styles = explode(';', $param['style']);
|
|
|
|
|
$param['style'] = array();
|
|
|
|
|
foreach($styles as $style)
|
|
|
|
|
{
|
|
|
|
|
$tmp = explode(':', $style);
|
|
|
|
|
if (count($tmp)>1)
|
|
|
|
|
{
|
|
|
|
|
$cod = $tmp[0]; unset($tmp[0]); $tmp = implode(':', $tmp);
|
|
|
|
|
$param['style'][trim(strtolower($cod))] = preg_replace('/[\s]+/isU', ' ', trim($tmp));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-17 14:44:28 +00:00
|
|
|
|
// d<>termination du niveau de table pour les ouverture, avec ajout d'un level
|
2009-06-16 08:47:07 +00:00
|
|
|
|
if (in_array($name, array('ul', 'ol', 'table')) && !$close)
|
|
|
|
|
{
|
|
|
|
|
$this->num++;
|
|
|
|
|
$this->level[count($this->level)] = $this->num;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-17 14:44:28 +00:00
|
|
|
|
// attribution du niveau de table o<> se trouve l'<27>l<EFBFBD>ment
|
2009-06-16 08:47:07 +00:00
|
|
|
|
if (!isset($param['num'])) $param['num'] = $this->level[count($this->level)-1];
|
|
|
|
|
|
|
|
|
|
// pour les fins de table : suppression d'un level
|
|
|
|
|
if (in_array($name, array('ul', 'ol', 'table')) && $close)
|
|
|
|
|
{
|
|
|
|
|
unset($this->level[count($this->level)-1]);
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-17 14:44:28 +00:00
|
|
|
|
// retour de l'action identifi<66>e
|
|
|
|
|
return array('name' => $name, 'close' => $close ? 1 : 0, 'autoclose' => $autoclose, 'param' => $param);
|
2009-06-16 08:47:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-02-17 14:44:28 +00:00
|
|
|
|
// r<>cup<75>rer un niveau complet d'HTML entre une ouverture de balise et la fermeture correspondante
|
2009-06-16 08:47:07 +00:00
|
|
|
|
function getLevel($k)
|
|
|
|
|
{
|
|
|
|
|
// si le code n'existe pas : fin
|
|
|
|
|
if (!isset($this->code[$k])) return '';
|
|
|
|
|
|
2010-02-17 14:44:28 +00:00
|
|
|
|
// quelle balise faudra-t-il d<>tecter
|
2009-06-16 08:47:07 +00:00
|
|
|
|
$detect = $this->code[$k]['name'];
|
|
|
|
|
|
|
|
|
|
$level = 0; // niveau de profondeur
|
|
|
|
|
$end = false; // etat de fin de recherche
|
|
|
|
|
$code = ''; // code extrait
|
|
|
|
|
|
|
|
|
|
// tant que c'est pas fini, on boucle
|
|
|
|
|
while (!$end)
|
|
|
|
|
{
|
|
|
|
|
// action courante
|
|
|
|
|
$row = $this->code[$k];
|
|
|
|
|
|
|
|
|
|
// si write => on ajoute le texte
|
|
|
|
|
if ($row['name']=='write')
|
|
|
|
|
{
|
|
|
|
|
$code.= $row['param']['txt'];
|
|
|
|
|
}
|
|
|
|
|
// sinon, c'est une balise html
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$not = false; // indicateur de non prise en compte de la balise courante
|
|
|
|
|
|
|
|
|
|
// si c'est la balise que l'on cherche
|
|
|
|
|
if ($row['name']==$detect)
|
|
|
|
|
{
|
2010-02-17 14:44:28 +00:00
|
|
|
|
if ($level==0) { $not = true; } // si on est <20> la premiere balise : on l'ignore
|
2009-06-16 08:47:07 +00:00
|
|
|
|
$level+= ($row['close'] ? -1 : 1); // modification du niveau en cours en fonction de l'ouvertre / fermeture
|
|
|
|
|
if ($level==0) { $not = true; $end = true; } // si on est au niveau 0 : on a fini
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// si on doit prendre en compte la balise courante
|
|
|
|
|
if (!$not)
|
|
|
|
|
{
|
|
|
|
|
// ecriture du code HTML de la balise
|
|
|
|
|
$code.= '<'.($row['close'] ? '/' : '').$row['name'];
|
|
|
|
|
foreach($row['param'] as $key => $val)
|
|
|
|
|
{
|
|
|
|
|
if ($key=='style')
|
|
|
|
|
{
|
|
|
|
|
$tmp = '';
|
|
|
|
|
if (isset($val['text-align'])) unset($val['text-align']);
|
|
|
|
|
foreach($val as $ks => $vs) $tmp.= $ks.':'.$vs.'; ';
|
|
|
|
|
if (trim($tmp)) $code.= ' '.$key.'="'.$tmp.'"';
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$code.= ' '.$key.'="'.$val.'"';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$code.= '>';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-17 14:44:28 +00:00
|
|
|
|
// on continue tant qu'il y a du code <20> analyser...
|
2009-06-16 08:47:07 +00:00
|
|
|
|
if (isset($this->code[$k+1]))
|
|
|
|
|
$k++;
|
|
|
|
|
else
|
|
|
|
|
$end = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// retourne la position finale et le code HTML extrait
|
|
|
|
|
return array($k, $code);
|
|
|
|
|
}
|
2010-02-17 14:44:28 +00:00
|
|
|
|
|
|
|
|
|
function getHtmlErrorCode($pos)
|
|
|
|
|
{
|
|
|
|
|
return substr($this->html, $pos-30, 70);
|
|
|
|
|
}
|
2009-06-16 08:47:07 +00:00
|
|
|
|
}
|
|
|
|
|
}
|