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)) {
221 if (!is_callable(
'mb_ereg_search_init')) {
222 if (!preg_match(
$regexp, $text, $match)) {
230 mb_ereg_search_init($text);
231 if (!mb_ereg_search(
$regexp)) {
234 $match = mb_ereg_search_getregs();
253 $stripped = preg_replace($this->_removed_re,
257 $html_begin = $this->
htmlBegin($stripped);
258 $html_end = $this->
htmlEnd($stripped);
260 if ($html_begin ===
false) {
264 if ($html_end ===
false) {
265 $html_end = strlen($stripped);
268 $stripped = substr($stripped, $html_begin,
269 $html_end - $html_begin);
272 $old_btlimit = ini_set(
'pcre.backtrack_limit', -1 );
276 $head_match = array();
277 if (!$this->
match($head_re, $stripped, $head_match)) {
278 ini_set(
'pcre.backtrack_limit', $old_btlimit );
282 $link_data = array();
283 $link_matches = array();
285 if (!preg_match_all($this->_link_find, $head_match[0],
287 ini_set(
'pcre.backtrack_limit', $old_btlimit );
291 foreach ($link_matches[0] as $link) {
292 $attr_matches = array();
293 preg_match_all($this->_attr_find, $link, $attr_matches);
294 $link_attrs = array();
295 foreach ($attr_matches[0] as $index => $full_match) {
296 $name = $attr_matches[1][$index];
300 $link_attrs[strtolower($name)] = $value;
302 $link_data[] = $link_attrs;
305 ini_set(
'pcre.backtrack_limit', $old_btlimit );
313 $rels = preg_split(
"/\s+/", trim($rel_attr));
314 foreach ($rels as $rel) {
315 $rel = strtolower($rel);
316 if ($rel == $target_rel) {
328 $rel_attr = Auth_OpeniD::arrayGet($link_attrs,
'rel', null);
329 return ($rel_attr && $this->
relMatches($rel_attr,
339 foreach ($link_attrs_list as $attr) {
358 $first = $matches[0];
368 $link_attrs = $p->parseLinkAttrs($html_text);
370 $server_url = $p->findFirstHref($link_attrs,
373 if ($server_url === null) {
376 $delegate_url = $p->findFirstHref($link_attrs,
378 return array($delegate_url, $server_url);
tagMatcher($tag_name, $close_tags=null)
if(!defined('SINGLEQUOTE')) define('SINGLEQUOTE' drivers adodb mssql inc php t an odd number of single quotes(this can cause problems below *and should be considered one wrong SQL). Exit with debug info. */if((substr_count($sql SINGLEQUOTE $regexp)
relMatches($rel_attr, $target_rel)
findFirstHref($link_attrs_list, $target_rel)
linkHasRel($link_attrs, $target_rel)
static arrayGet($arr, $key, $fallback=null)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren't numeric.
findLinksRel($link_attrs_list, $target_rel)
match($regexp, $text, &$match)
Auth_OpenID_legacy_discover($html_text, $server_rel, $delegate_rel)