| version 1.21, 2004/12/02 15:49:11 |
version 1.22, 2004/12/02 15:55:32 |
| Line 43 class HTML_Content |
|
| Line 43 class HTML_Content |
|
| var $_raw_cookies = array(); |
var $_raw_cookies = array(); |
| var $_fp = null; |
var $_fp = null; |
| |
|
| function HTML_Content($file = null, $cookies = null) |
function HTML_Content($file = null, $cookies = null) /* {{{ */ |
| { |
{ |
| $this->_cookies = is_array($cookies) ? $cookies : array(); |
$this->_cookies = is_array($cookies) ? $cookies : array(); |
| if ($file != null) { |
if ($file != null) { |
| return $this->setInputFile($file); |
return $this->setInputFile($file); |
| } |
} |
| return true; |
return true; |
| } |
} /* }}} */ |
| |
|
| /** |
/** |
| * Defines |
* Defines |
| Line 61 class HTML_Content |
|
| Line 61 class HTML_Content |
|
| * @see setInput(), parse() |
* @see setInput(), parse() |
| * @access public |
* @access public |
| */ |
*/ |
| function setInputFile($file, $cookies = null) |
function setInputFile($file, $cookies = null) /* {{{ */ |
| { |
{ |
| $this->_cookies = is_array($cookies) ? $cookies : $this->_cookies; |
$this->_cookies = is_array($cookies) ? $cookies : $this->_cookies; |
| if (is_string($file)) { |
if (is_string($file)) { |
| Line 69 class HTML_Content |
|
| Line 69 class HTML_Content |
|
| return true; |
return true; |
| } |
} |
| return false; |
return false; |
| } |
} /* }}} */ |
| |
|
| /** |
/** |
| * Sets the file handle to use with parse(). |
* Sets the file handle to use with parse(). |
| Line 78 class HTML_Content |
|
| Line 78 class HTML_Content |
|
| * @access public |
* @access public |
| * @see parse(), setInputFile() |
* @see parse(), setInputFile() |
| */ |
*/ |
| function setInput($fp) |
function setInput($fp) /* {{{ */ |
| { |
{ |
| if (is_resource($fp)) { |
if (is_resource($fp)) { |
| $this->_fp = $fp; |
$this->_fp = $fp; |
| Line 86 class HTML_Content |
|
| Line 86 class HTML_Content |
|
| } |
} |
| |
|
| return false; |
return false; |
| } |
} /* }}} */ |
| |
|
| function _getRemoteContent($url, &$data) |
function _getRemoteContent($url, &$data) /* {{{ */ |
| { |
{ |
| if (empty($url)) { |
if (empty($url)) { |
| return false; |
return false; |
| Line 138 class HTML_Content |
|
| Line 138 class HTML_Content |
|
| } |
} |
| } |
} |
| return true; |
return true; |
| } |
} /* }}} */ |
| |
|
| /** |
/** |
| * Central parsing function. |
* Central parsing function. |
| Line 148 class HTML_Content |
|
| Line 148 class HTML_Content |
|
| * @see parseString() |
* @see parseString() |
| * @access public |
* @access public |
| */ |
*/ |
| function parse($all_data = null) |
function parse($all_data = null) /* {{{ */ |
| { |
{ |
| if ($all_data === null) { |
if ($all_data === null) { |
| if (! is_resource(@$this->_fp)) { |
if (! is_resource(@$this->_fp)) { |
| Line 203 class HTML_Content |
|
| Line 203 class HTML_Content |
|
| $this->_data['body'] = $all_data; |
$this->_data['body'] = $all_data; |
| } |
} |
| return true; |
return true; |
| } |
} /* }}} */ |
| |
|
| function translateHead($ar) |
function translateHead($ar) /* {{{ */ |
| { |
{ |
| return $this->_translate('head', $ar); |
return $this->_translate('head', $ar); |
| } |
} /* }}} */ |
| |
|
| function translateBody($ar) |
function translateBody($ar) /* {{{ */ |
| { |
{ |
| return $this->_translate('body', $ar); |
return $this->_translate('body', $ar); |
| } |
} /* }}} */ |
| |
|
| function _translate($where, $ar) |
function _translate($where, $ar) /* {{{ */ |
| { |
{ |
| if (! is_array($ar)) { |
if (! is_array($ar)) { |
| return false; |
return false; |
| Line 224 class HTML_Content |
|
| Line 224 class HTML_Content |
|
| $this->_data[$where] = str_replace($key, $val, $this->_data[$where]); |
$this->_data[$where] = str_replace($key, $val, $this->_data[$where]); |
| } |
} |
| return true; |
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]; |
| if (! isset($ar)) { |
if (! isset($ar)) { |
| Line 242 class HTML_Content |
|
| Line 242 class HTML_Content |
|
| return false; |
return false; |
| } |
} |
| return @$ar[$idx]; |
return @$ar[$idx]; |
| } |
} /* }}} */ |
| |
|
| /* $where must be head/body, $name must be lowercase */ |
/* $where must be head/body, $name must be lowercase */ |
| function _parseTag($where, $name) |
function _parseTag($where, $name) /* {{{ */ |
| { |
{ |
| $ret = array(); |
$ret = array(); |
| $matches = array(); |
$matches = array(); |
| Line 275 class HTML_Content |
|
| Line 275 class HTML_Content |
|
| } |
} |
| |
|
| return $ret; |
return $ret; |
| } |
} /* }}} */ |
| |
|
| function getContentType() |
function getContentType() /* {{{ */ |
| { |
{ |
| return $this->_content_type; |
return $this->_content_type; |
| } |
} /* }}} */ |
| |
|
| function getNewURL() |
function getNewURL() /* {{{ */ |
| { |
{ |
| return $this->_new_url; |
return $this->_new_url; |
| } |
} /* }}} */ |
| |
|
| function getCookies() |
function getCookies() /* {{{ */ |
| { |
{ |
| return $this->_cookies; |
return $this->_cookies; |
| } |
} /* }}} */ |
| |
|
| function getRawCookies() |
function getRawCookies() /* {{{ */ |
| { |
{ |
| return $this->_raw_cookies; |
return $this->_raw_cookies; |
| } |
} /* }}} */ |
| |
|
| function getHTML() |
function getHTML() /* {{{ */ |
| { |
{ |
| return '<!DOCTYPE '.$this->_data['doctype'].">\n" |
return '<!DOCTYPE '.$this->_data['doctype'].">\n" |
| ."<HTML>\n"."<HEAD>\n".$this->_data['head']."\n</HEAD>\n" |
."<HTML>\n"."<HEAD>\n".$this->_data['head']."\n</HEAD>\n" |
| .'<BODY '.$this->_data['body_attr'].">\n" |
.'<BODY '.$this->_data['body_attr'].">\n" |
| .$this->_data['body']."\n</BODY>\n</HTML>\n"; |
.$this->_data['body']."\n</BODY>\n</HTML>\n"; |
| } |
} /* }}} */ |
| |
|
| function getHead() |
function getHead() /* {{{ */ |
| { |
{ |
| return $this->_data['head']; |
return $this->_data['head']; |
| } |
} /* }}} */ |
| |
|
| function getBody() |
function getBody() /* {{{ */ |
| { |
{ |
| return $this->_data['body']; |
return $this->_data['body']; |
| } |
} /* }}} */ |
| |
|
| function getTitle() |
function getTitle() /* {{{ */ |
| { |
{ |
| $title_tag = $this->_getTag('head', 'title', 0); |
$title_tag = $this->_getTag('head', 'title', 0); |
| return @is_array($title_tag) ? @$title_tag['__content'] : ''; |
return @is_array($title_tag) ? @$title_tag['__content'] : ''; |
| } |
} /* }}} */ |
| |
|
| function getTag($where, $name, $attr = '', $value = '') |
function getTag($where, $name, $attr = '', $value = '') /* {{{ */ |
| { |
{ |
| $attr = strtolower($attr); |
$attr = strtolower($attr); |
| $where = strtolower($where); |
$where = strtolower($where); |
| Line 348 class HTML_Content |
|
| Line 348 class HTML_Content |
|
| } |
} |
| } |
} |
| return false; |
return false; |
| } |
} /* }}} */ |
| |
|
| function getComposedTag($where, $name, $attr = '', $value = '') |
function getComposedTag($where, $name, $attr = '', $value = '') /* {{{ */ |
| { |
{ |
| $single = $attr == '' ? false : true; |
$single = $attr == '' ? false : true; |
| $ar = $this->getTag($where, $name, $attr, $value); |
$ar = $this->getTag($where, $name, $attr, $value); |
| Line 365 class HTML_Content |
|
| Line 365 class HTML_Content |
|
| $out_ar[] = HTML_Content::composeTag($name, $tag); |
$out_ar[] = HTML_Content::composeTag($name, $tag); |
| } |
} |
| return $out_ar; |
return $out_ar; |
| } |
} /* }}} */ |
| |
|
| function composeTag($name, $attributes) |
function composeTag($name, $attributes) /* {{{ */ |
| { |
{ |
| $ret = htmlspecialchars($name); |
$ret = htmlspecialchars($name); |
| foreach ($attributes as $attr => $value) { |
foreach ($attributes as $attr => $value) { |
| Line 391 class HTML_Content |
|
| Line 391 class HTML_Content |
|
| $ret .= '</'.htmlspecialchars($name).'>'; |
$ret .= '</'.htmlspecialchars($name).'>'; |
| } |
} |
| return $ret; |
return $ret; |
| } |
} /* }}} */ |
| |
|
| # |
# |
| # D E P R E C A T E D |
# D E P R E C A T E D |
| # |
# |
| |
|
| function getMeta($attr, $value) |
function getMeta($attr, $value) /* {{{ */ |
| { |
{ |
| $this->_data['meta'] == null && $this->_parseMeta(); |
$this->_data['meta'] == null && $this->_parseMeta(); |
| $attr = strtolower($attr); |
$attr = strtolower($attr); |
| Line 407 class HTML_Content |
|
| Line 407 class HTML_Content |
|
| return $this->_data['meta'][$i]; |
return $this->_data['meta'][$i]; |
| } |
} |
| } |
} |
| } |
} /* }}} */ |
| |
|
| function _parseTitle() |
function _parseTitle() /* {{{ */ |
| { |
{ |
| if (preg_match('|<title>(.*)</title>|si', $this->_data['head'], $matches)) { |
if (preg_match('|<title>(.*)</title>|si', $this->_data['head'], $matches)) { |
| $this->_data['title'] = trim($matches[1]); |
$this->_data['title'] = trim($matches[1]); |
| return; |
return; |
| } |
} |
| $this->_data['title'] = ''; |
$this->_data['title'] = ''; |
| } |
} /* }}} */ |
| |
|
| function _parseMeta() |
function _parseMeta() /* {{{ */ |
| { |
{ |
| $this->_data['meta'] = array(); |
$this->_data['meta'] = array(); |
| if (preg_match_all('|<meta ([^>]*)>|si', $this->_data['head'], $matches) > 0) { |
if (preg_match_all('|<meta ([^>]*)>|si', $this->_data['head'], $matches) > 0) { |
| Line 440 class HTML_Content |
|
| Line 440 class HTML_Content |
|
| $meta_idx++; |
$meta_idx++; |
| } |
} |
| } |
} |
| } |
} /* }}} */ |
| |
|
| } |
} |
| |
|
| |
/* Modeline for ViM {{{ |
| |
* vim: set ts=4: |
| |
* vim600: fdm=marker fdl=0 fdc=0: |
| |
* }}} */ |
| |
|
| ?> |
?> |