Browse Source

move subdomain check into a function

pull/9/head
Aaron Parecki 8 years ago
parent
commit
efa4e3a6d7
2 changed files with 7 additions and 3 deletions
  1. +1
    -3
      controllers/API.php
  2. +6
    -0
      lib/helpers.php

+ 1
- 3
controllers/API.php View File

@ -103,9 +103,7 @@ class API {
foreach($xpath->query('//a[@href]') as $href) {
$url = $href->getAttribute('href');
$domain = parse_url($url, PHP_URL_HOST);
if($url == $target || $domain == $target_domain ||
# subdomain check
($target_domain and $domain and substr_compare($domain, '.' . $target_domain, -(strlen($target_domain) + 1)) == 0)) {
if($url == $target || $domain == $target_domain || str_ends_with($domain, $target_domain)) {
$found[$url] = null;
}
}

+ 6
- 0
lib/helpers.php View File

@ -42,6 +42,12 @@ function random_string($len) {
return $str;
}
// Returns true if $needle is the end of the $haystack
function str_ends_with($haystack, $needle) {
if($needle == '' || $haystack == '') return false;
return strpos(strrev($haystack), strrev($needle)) === 0;
}
function display_url($url) {
return preg_replace(['/^https?:\/\//','/\/$/'], '', $url);
}

Loading…
Cancel
Save