85 require_once
"Auth/OpenID.php";
98 "<!--.*?-->|<!\[CDATA\[.*?\]\]>|<script\b(?!:)[^>]*>.*?<\/script>";
104 var
$_tag_expr =
"<%s\b(?!:)([^>]*?)(?:\/>|>(.*)(?:<\/?%s\s*>|\Z))";
113 $this->_link_find = sprintf(
"/<link\b(?!:)([^>]*)(?!<)>/%s",
116 $this->_entity_replacements = array(
123 $this->_attr_find = sprintf(
"/%s/%s",
127 $this->_removed_re = sprintf(
"/%s/%s",
131 $this->_ent_replace =
132 sprintf(
"&(%s);", implode(
"|",
133 $this->_entity_replacements));
145 $options = implode(
"|", array_merge(array($tag_name), $close_tags));
146 $closer = sprintf(
"(?:%s)",
$options);
151 $expr = sprintf($expr, $tag_name, $closer);
152 return sprintf(
"/%s/%s", $expr, $this->_re_flags);
157 $expr = sprintf($this->_open_tag_expr, $tag_name);
158 return sprintf(
"/%s/%s", $expr, $this->_re_flags);
163 $expr = sprintf($this->_close_tag_expr, $tag_name, $tag_name);
164 return sprintf(
"/%s/%s", $expr, $this->_re_flags);
171 $matches, PREG_OFFSET_CAPTURE);
172 if (
$result ===
false || !$matches) {
176 return $matches[0][1];
183 $matches, PREG_OFFSET_CAPTURE);
184 if (
$result ===
false || !$matches) {
188 return $matches[count($matches) - 1][1];
193 return $this->
tagMatcher(
'head', array(
'body',
'html'));
198 foreach ($this->_entity_replacements as $old => $new) {
199 $str = preg_replace(sprintf(
"/&%s;/", $old), $new, $str);
207 $double =
'/^"(.*)"$/';
208 $single =
"/^\'(.*)\'$/";
210 if (preg_match($double, $str, $matches)) {
212 }
else if (preg_match($single, $str, $matches)) {
219 function match($regexp, $text, &$match)
221 if (!is_callable(
'mb_ereg_search_init')) {
222 return preg_match($regexp, $text, $match);
225 $regexp = substr($regexp, 1, strlen($regexp) - 2 - strlen($this->_re_flags));
226 mb_ereg_search_init($text);
227 if (!mb_ereg_search($regexp)) {
230 list($match) = mb_ereg_search_getregs();
249 $stripped = preg_replace($this->_removed_re,
253 $html_begin = $this->
htmlBegin($stripped);
254 $html_end = $this->
htmlEnd($stripped);
256 if ($html_begin ===
false) {
260 if ($html_end ===
false) {
261 $html_end = strlen($stripped);
264 $stripped = substr($stripped, $html_begin,
265 $html_end - $html_begin);
268 $old_btlimit = ini_set(
'pcre.backtrack_limit', -1 );
273 if (!$this->
match($head_re, $stripped, $head_match)) {
274 ini_set(
'pcre.backtrack_limit', $old_btlimit );
278 $link_data = array();
279 $link_matches = array();
281 if (!preg_match_all($this->_link_find, $head_match,
283 ini_set(
'pcre.backtrack_limit', $old_btlimit );
287 foreach ($link_matches[0] as $link) {
288 $attr_matches = array();
289 preg_match_all($this->_attr_find, $link, $attr_matches);
290 $link_attrs = array();
291 foreach ($attr_matches[0] as $index => $full_match) {
292 $name = $attr_matches[1][$index];
296 $link_attrs[strtolower($name)] = $value;
298 $link_data[] = $link_attrs;
301 ini_set(
'pcre.backtrack_limit', $old_btlimit );
309 $rels = preg_split(
"/\s+/", trim($rel_attr));
310 foreach ($rels as $rel) {
311 $rel = strtolower($rel);
312 if ($rel == $target_rel) {
324 $rel_attr = Auth_OpeniD::arrayGet($link_attrs,
'rel', null);
325 return ($rel_attr && $this->
relMatches($rel_attr,
335 foreach ($link_attrs_list as $attr) {
354 $first = $matches[0];
364 $link_attrs = $p->parseLinkAttrs($html_text);
366 $server_url = $p->findFirstHref($link_attrs,
369 if ($server_url === null) {
372 $delegate_url = $p->findFirstHref($link_attrs,
374 return array($delegate_url, $server_url);