| version 1.3, 2002/10/08 22:37:41 |
version 1.4, 2002/10/14 22:38:27 |
|
|
| |
|
| */ |
*/ |
| |
|
| |
|
| |
|
| class HTML_Content |
class HTML_Content |
| { |
{ |
| |
|
| Line 39 class HTML_Content |
|
| Line 37 class HTML_Content |
|
| 'body_tags' => null |
'body_tags' => null |
| ); |
); |
| |
|
| function HTML_Content() |
var $_content_type = null; |
| |
var $_new_url = null; |
| |
|
| |
function HTML_Content($file = null) |
| { |
{ |
| |
if ($file != null) { |
| |
return $this->setInputFile($file); |
| |
} |
| |
return true; |
| } |
} |
| |
|
| /** |
/** |
| Line 54 class HTML_Content |
|
| Line 59 class HTML_Content |
|
| */ |
*/ |
| function setInputFile($file) |
function setInputFile($file) |
| { |
{ |
| $fp = @fopen($file, 'rb'); |
if (is_string($file)) { |
| if (is_resource($fp)) { |
$this->_file = $file; |
| $this->_fp = $fp; |
return true; |
| return $fp; |
|
| } |
} |
| |
|
| //return $this->raiseError($php_errormsg); |
|
| return false; |
return false; |
| } |
} |
| |
|
| Line 78 class HTML_Content |
|
| Line 80 class HTML_Content |
|
| return true; |
return true; |
| } |
} |
| |
|
| return $this->raiseError("not a file resource"); |
return false; |
| |
} |
| |
|
| |
function _getRemoteContent($url, &$data) |
| |
{ |
| |
if (empty($url)) { |
| |
return false; |
| |
} |
| |
|
| |
include_once 'HTTP/Request.php'; |
| |
|
| |
for ($i = 0; ; $i++) { |
| |
$r = &new HTTP_Request($url); |
| |
if ($i == 0) { |
| |
foreach ($_POST as $key => $val) { |
| |
$r->addPostData($key, $val); |
| |
} |
| |
} |
| |
$ret = $r->sendRequest(); |
| |
if ($ret !== true) { |
| |
return $ret; |
| |
} |
| |
if ($r->getResponseCode() == 301) { |
| |
$url = $r->getResponseHeader('Location'); |
| |
$this->_new_url = $url; |
| |
continue; |
| |
} else { |
| |
/* |
| |
if (strncasecmp('text/html', $r->getResponseHeader('Content-Type'), 9)) { |
| |
header('Content-Type: '.$r->getResponseHeader('Content-Type')); |
| |
echo $r->getResponseBody(); |
| |
exit; |
| |
} */ |
| |
$this->_content_type = $r->getResponseHeader('Content-Type'); |
| |
$data = $r->getResponseBody(); |
| |
break; |
| |
} |
| |
} |
| |
return true; |
| } |
} |
| |
|
| /** |
/** |
| Line 92 class HTML_Content |
|
| Line 132 class HTML_Content |
|
| function parse($all_data = '') |
function parse($all_data = '') |
| { |
{ |
| if ($all_data == '') { |
if ($all_data == '') { |
| if (!is_resource($this->_fp)) { |
if (! is_resource($this->_fp)) { |
| //return $this->raiseError('no input'); |
if (! strncmp($this->_file, "http://", 7)) { |
| return false; |
if ($this->_getRemoteContent($this->_file, $all_data) !== true) { |
| |
return false; |
| |
} |
| |
} else { |
| |
$this->_fp = @fopen($this->_file, 'rb'); |
| |
if (! is_resource($this->_fp)) { |
| |
return false; |
| |
} |
| |
} |
| } |
} |
| |
if ($all_data == '') { |
| $all_data = ''; |
while ($data = fread($this->_fp, 2048)) { |
| while ($data = fread($this->_fp, 2048)) { |
$all_data .= $data; |
| $all_data .= $data; |
} |
| |
fclose($this->_fp); |
| } |
} |
| fclose($this->_fp); |
|
| } |
} |
| |
|
| $this->_data['doctype'] = ''; |
$this->_data['doctype'] = ''; |
| Line 109 class HTML_Content |
|
| Line 157 class HTML_Content |
|
| $this->_data['body'] = ''; |
$this->_data['body'] = ''; |
| $this->_data['head_attr'] = ''; |
$this->_data['head_attr'] = ''; |
| $this->_data['body_attr'] = ''; |
$this->_data['body_attr'] = ''; |
| |
! isset($this->_content_type) && $this->_content_type = 'text/html'; |
| |
|
| if (preg_match('|^\s*<!DOCTYPE ([^>]*)>|', $all_data, $matches)) { |
if (preg_match('|^\s*<!DOCTYPE ([^>]*)>|', $all_data, $matches)) { |
| $this->_data['doctype'] = trim($matches[1]); |
$this->_data['doctype'] = trim($matches[1]); |
| Line 127 class HTML_Content |
|
| Line 176 class HTML_Content |
|
| return true; |
return true; |
| } |
} |
| |
|
| |
function translateHead($ar) |
| |
{ |
| |
return $this->_translate('head', $ar); |
| |
} |
| |
|
| |
function translateBody($ar) |
| |
{ |
| |
return $this->_translate('body', $ar); |
| |
} |
| |
|
| |
function _translate($where, $ar) |
| |
{ |
| |
if (! is_array($ar)) { |
| |
return false; |
| |
} |
| |
foreach ($ar as $key => $val) { |
| |
$this->_data[$where] = str_replace($key, $val, $this->_data[$where]); |
| |
} |
| |
return true; |
| |
} |
| |
|
| function _getTag($where, $name, $idx = -1) |
function _getTag($where, $name, $idx = -1) |
| { |
{ |
| $ar =& $this->_data[$where.'_tags'][$name]; |
$ar =& $this->_data[$where.'_tags'][$name]; |
| Line 147 class HTML_Content |
|
| Line 217 class HTML_Content |
|
| { |
{ |
| $ret = array(); |
$ret = array(); |
| $matches = array(); |
$matches = array(); |
| /* |
|
| echo "$where/$name/"; |
|
| echo htmlspecialchars('|<'.$name.'([^>]*)>([^<>]*)</'.$name.'>|si'); |
|
| echo '<hr>'; |
|
| echo htmlspecialchars($this->_data[$where]); |
|
| echo '<hr>'; |
|
| */ |
|
| if (preg_match_all('|<'.$name.'([^>]*)>(.*)</'.$name.'>|si', |
if (preg_match_all('|<'.$name.'([^>]*)>(.*)</'.$name.'>|si', |
| $this->_data[$where], $matches) > 0) { |
$this->_data[$where], $matches) > 0) { |
| } elseif (preg_match_all('|<'.$name.'([^>]*)>|si', |
} elseif (preg_match_all('|<'.$name.'([^>]*)>|si', |
| Line 181 class HTML_Content |
|
| Line 245 class HTML_Content |
|
| return $ret; |
return $ret; |
| } |
} |
| |
|
| |
function getContentType() |
| |
{ |
| |
return $this->_content_type; |
| |
} |
| |
|
| |
function getNewURL() |
| |
{ |
| |
return $this->_new_url; |
| |
} |
| |
|
| function getHTML() |
function getHTML() |
| { |
{ |
| return '<!DOCTYPE '.$this->_data['doctype'].">\n" |
return '<!DOCTYPE '.$this->_data['doctype'].">\n" |
| Line 325 class HTML_Content |
|
| Line 399 class HTML_Content |
|
| } |
} |
| } |
} |
| |
|
| |
|
| } |
} |
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| ?> |
?> |