ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
Auth_OpenID_Parse Class Reference

Require Auth_OpenID::arrayGet(). More...

+ Collaboration diagram for Auth_OpenID_Parse:

Public Member Functions

 Auth_OpenID_Parse ()
 tagMatcher ($tag_name, $close_tags=null)
 Returns a regular expression that will match a given tag in an SGML string.
 openTag ($tag_name)
 closeTag ($tag_name)
 htmlBegin ($s)
 htmlEnd ($s)
 headFind ()
 replaceEntities ($str)
 removeQuotes ($str)
 match ($regexp, $text, &$match)
 parseLinkAttrs ($html)
 Find all link tags in a string representing a HTML document and return a list of their attributes.
 relMatches ($rel_attr, $target_rel)
 linkHasRel ($link_attrs, $target_rel)
 findLinksRel ($link_attrs_list, $target_rel)
 findFirstHref ($link_attrs_list, $target_rel)

Data Fields

 $_re_flags = "si"
 Specify some flags for use with regex matching.
 $_removed_re = "<!--.*?-->|<!\[CDATA\[.*?\]\]>|<script\b(?!:)[^>]*>.*?<\/script>"
 Stuff to remove before we start looking for tags.
 $_tag_expr = "<%s\b(?!:)([^>]*?)(?:\/>|>(.*)(?:<\/?%s\s*>|\Z))"
 Starts with the tag name at a word boundary, where the tag name is not a namespace.
 $_attr_find = '\b(\w+)=("[^"]*"|\'[^\']*\'|[^\'"\s\/<>]+)'
 $_open_tag_expr = "<%s\b"
 $_close_tag_expr = "<((\/%s\b)|(%s[^>\/]*\/))>"

Detailed Description

Require Auth_OpenID::arrayGet().

Definition at line 87 of file Parse.php.

Member Function Documentation

Auth_OpenID_Parse::Auth_OpenID_Parse ( )

Definition at line 111 of file Parse.php.

{
$this->_link_find = sprintf("/<link\b(?!:)([^>]*)(?!<)>/%s",
$this->_re_flags);
$this->_entity_replacements = array(
'amp' => '&',
'lt' => '<',
'gt' => '>',
'quot' => '"'
);
$this->_attr_find = sprintf("/%s/%s",
$this->_attr_find,
$this->_re_flags);
$this->_removed_re = sprintf("/%s/%s",
$this->_removed_re,
$this->_re_flags);
$this->_ent_replace =
sprintf("&(%s);", implode("|",
$this->_entity_replacements));
}
Auth_OpenID_Parse::closeTag (   $tag_name)

Definition at line 161 of file Parse.php.

Referenced by htmlEnd().

{
$expr = sprintf($this->_close_tag_expr, $tag_name, $tag_name);
return sprintf("/%s/%s", $expr, $this->_re_flags);
}

+ Here is the caller graph for this function:

Auth_OpenID_Parse::findFirstHref (   $link_attrs_list,
  $target_rel 
)

Definition at line 344 of file Parse.php.

References Auth_OpenID\arrayGet(), and findLinksRel().

{
// Return the value of the href attribute for the first link
// tag in the list that has target_rel as a relationship.
// XXX: TESTME
$matches = $this->findLinksRel($link_attrs_list,
$target_rel);
if (!$matches) {
return null;
}
$first = $matches[0];
return Auth_OpenID::arrayGet($first, 'href', null);
}

+ Here is the call graph for this function:

Auth_OpenID_Parse::findLinksRel (   $link_attrs_list,
  $target_rel 
)

Definition at line 329 of file Parse.php.

References $result, and linkHasRel().

Referenced by findFirstHref().

{
// Filter the list of link attributes on whether it has
// target_rel as a relationship.
// XXX: TESTME
$result = array();
foreach ($link_attrs_list as $attr) {
if ($this->linkHasRel($attr, $target_rel)) {
$result[] = $attr;
}
}
return $result;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Auth_OpenID_Parse::headFind ( )

Definition at line 191 of file Parse.php.

References tagMatcher().

Referenced by parseLinkAttrs().

{
return $this->tagMatcher('head', array('body', 'html'));
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Auth_OpenID_Parse::htmlBegin (   $s)

Definition at line 167 of file Parse.php.

References $result, and openTag().

Referenced by parseLinkAttrs().

{
$matches = array();
$result = preg_match($this->openTag('html'), $s,
$matches, PREG_OFFSET_CAPTURE);
if ($result === false || !$matches) {
return false;
}
// Return the offset of the first match.
return $matches[0][1];
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Auth_OpenID_Parse::htmlEnd (   $s)

Definition at line 179 of file Parse.php.

References $result, and closeTag().

Referenced by parseLinkAttrs().

{
$matches = array();
$result = preg_match($this->closeTag('html'), $s,
$matches, PREG_OFFSET_CAPTURE);
if ($result === false || !$matches) {
return false;
}
// Return the offset of the first match.
return $matches[count($matches) - 1][1];
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Auth_OpenID_Parse::linkHasRel (   $link_attrs,
  $target_rel 
)

Definition at line 320 of file Parse.php.

References relMatches().

Referenced by findLinksRel().

{
// Does this link have target_rel as a relationship?
// XXX: TESTME
$rel_attr = Auth_OpeniD::arrayGet($link_attrs, 'rel', null);
return ($rel_attr && $this->relMatches($rel_attr,
$target_rel));
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Auth_OpenID_Parse::match (   $regexp,
  $text,
$match 
)

Definition at line 219 of file Parse.php.

Referenced by parseLinkAttrs().

{
if (!is_callable('mb_ereg_search_init')) {
return preg_match($regexp, $text, $match);
}
$regexp = substr($regexp, 1, strlen($regexp) - 2 - strlen($this->_re_flags));
mb_ereg_search_init($text);
if (!mb_ereg_search($regexp)) {
return false;
}
list($match) = mb_ereg_search_getregs();
return true;
}

+ Here is the caller graph for this function:

Auth_OpenID_Parse::openTag (   $tag_name)

Definition at line 155 of file Parse.php.

Referenced by htmlBegin().

{
$expr = sprintf($this->_open_tag_expr, $tag_name);
return sprintf("/%s/%s", $expr, $this->_re_flags);
}

+ Here is the caller graph for this function:

Auth_OpenID_Parse::parseLinkAttrs (   $html)

Find all link tags in a string representing a HTML document and return a list of their attributes.

Todo:
This is quite ineffective and may fail with the default pcre.backtrack_limit of 100000 in PHP 5.2, if $html is big. It should rather use stripos (in PHP5) or strpos()+strtoupper() in PHP4 to manage this.
Parameters
string$htmlThe text to parse
Returns
array $list An array of arrays of attributes, one for each link tag

Definition at line 247 of file Parse.php.

References headFind(), htmlBegin(), htmlEnd(), match(), removeQuotes(), and replaceEntities().

{
$stripped = preg_replace($this->_removed_re,
"",
$html);
$html_begin = $this->htmlBegin($stripped);
$html_end = $this->htmlEnd($stripped);
if ($html_begin === false) {
return array();
}
if ($html_end === false) {
$html_end = strlen($stripped);
}
$stripped = substr($stripped, $html_begin,
$html_end - $html_begin);
// Workaround to prevent PREG_BACKTRACK_LIMIT_ERROR:
$old_btlimit = ini_set( 'pcre.backtrack_limit', -1 );
// Try to find the <HEAD> tag.
$head_re = $this->headFind();
$head_match = '';
if (!$this->match($head_re, $stripped, $head_match)) {
ini_set( 'pcre.backtrack_limit', $old_btlimit );
return array();
}
$link_data = array();
$link_matches = array();
if (!preg_match_all($this->_link_find, $head_match,
$link_matches)) {
ini_set( 'pcre.backtrack_limit', $old_btlimit );
return array();
}
foreach ($link_matches[0] as $link) {
$attr_matches = array();
preg_match_all($this->_attr_find, $link, $attr_matches);
$link_attrs = array();
foreach ($attr_matches[0] as $index => $full_match) {
$name = $attr_matches[1][$index];
$value = $this->replaceEntities(
$this->removeQuotes($attr_matches[2][$index]));
$link_attrs[strtolower($name)] = $value;
}
$link_data[] = $link_attrs;
}
ini_set( 'pcre.backtrack_limit', $old_btlimit );
return $link_data;
}

+ Here is the call graph for this function:

Auth_OpenID_Parse::relMatches (   $rel_attr,
  $target_rel 
)

Definition at line 305 of file Parse.php.

Referenced by linkHasRel().

{
// Does this target_rel appear in the rel_str?
// XXX: TESTME
$rels = preg_split("/\s+/", trim($rel_attr));
foreach ($rels as $rel) {
$rel = strtolower($rel);
if ($rel == $target_rel) {
return 1;
}
}
return 0;
}

+ Here is the caller graph for this function:

Auth_OpenID_Parse::removeQuotes (   $str)

Definition at line 204 of file Parse.php.

Referenced by parseLinkAttrs().

{
$matches = array();
$double = '/^"(.*)"$/';
$single = "/^\'(.*)\'$/";
if (preg_match($double, $str, $matches)) {
return $matches[1];
} else if (preg_match($single, $str, $matches)) {
return $matches[1];
} else {
return $str;
}
}

+ Here is the caller graph for this function:

Auth_OpenID_Parse::replaceEntities (   $str)

Definition at line 196 of file Parse.php.

Referenced by parseLinkAttrs().

{
foreach ($this->_entity_replacements as $old => $new) {
$str = preg_replace(sprintf("/&%s;/", $old), $new, $str);
}
return $str;
}

+ Here is the caller graph for this function:

Auth_OpenID_Parse::tagMatcher (   $tag_name,
  $close_tags = null 
)

Returns a regular expression that will match a given tag in an SGML string.

Definition at line 140 of file Parse.php.

References $_tag_expr.

Referenced by headFind().

{
if ($close_tags) {
$options = implode("|", array_merge(array($tag_name), $close_tags));
$closer = sprintf("(?:%s)", $options);
} else {
$closer = $tag_name;
}
$expr = sprintf($expr, $tag_name, $closer);
return sprintf("/%s/%s", $expr, $this->_re_flags);
}

+ Here is the caller graph for this function:

Field Documentation

Auth_OpenID_Parse::$_attr_find = '\b(\w+)=("[^"]*"|\'[^\']*\'|[^\'"\s\/<>]+)'

Definition at line 106 of file Parse.php.

Auth_OpenID_Parse::$_close_tag_expr = "<((\/%s\b)|(%s[^>\/]*\/))>"

Definition at line 109 of file Parse.php.

Auth_OpenID_Parse::$_open_tag_expr = "<%s\b"

Definition at line 108 of file Parse.php.

Auth_OpenID_Parse::$_re_flags = "si"

Specify some flags for use with regex matching.

Definition at line 92 of file Parse.php.

Auth_OpenID_Parse::$_removed_re = "<!--.*?-->|<!\[CDATA\[.*?\]\]>|<script\b(?!:)[^>]*>.*?<\/script>"

Stuff to remove before we start looking for tags.

Definition at line 97 of file Parse.php.

Auth_OpenID_Parse::$_tag_expr = "<%s\b(?!:)([^>]*?)(?:\/>|>(.*)(?:<\/?%s\s*>|\Z))"

Starts with the tag name at a word boundary, where the tag name is not a namespace.

Definition at line 104 of file Parse.php.

Referenced by tagMatcher().


The documentation for this class was generated from the following file: