Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion URLResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ public function resolveURL($url) {

$url_is_open_graph = false;
$url_is_canonical = false;
$url_includes_redirect = false;
$url_redirect_30x_count = 0;

$url_results = array();
for ($i = 0; $i < $this->max_redirects; $i++) {
Expand All @@ -128,6 +130,9 @@ public function resolveURL($url) {
# Don't allow it to overwrite a true value determined from markup with a false value...
if (!$url_result->isOpenGraphURL()) { $url_result->isOpenGraphURL($url_is_open_graph); }
if (!$url_result->isCanonicalURL()) { $url_result->isCanonicalURL($url_is_canonical); }

# Propogate the 30x count
$url_result->redirect30xCount($url_redirect_30x_count);

# Also print a short status line regarding the URL once it is fetched
if ($this->is_debug) {
Expand Down Expand Up @@ -188,6 +193,7 @@ public function resolveURL($url) {
$url = $next_url;
$url_is_open_graph = $url_result->redirectTargetIsOpenGraphURL();
$url_is_canonical = $url_result->redirectTargetIsCanonicalURL();
$url_redirect_30x_count = $url_result->redirect30xCount();
}

return $this->resolveURLResults($url_results);
Expand Down Expand Up @@ -560,6 +566,8 @@ class URLResolverResult {
private $redirect_is_open_graph = false;
private $redirect_is_canonical = false;

private $redirect_30x_count = 0;

private $failed = false;
private $error = false;
private $error_message = '';
Expand All @@ -580,7 +588,11 @@ public function setHTTPStatusCode($status) { $this->status = $status; }
public function hasSuccessHTTPStatus() { return ($this->status == 200); }

# Returns _true_ if the [HTTP status code] for the resolved URL is 301 or 302.
public function hasRedirectHTTPStatus() { return ($this->status == 301 || $this->status == 302 || $this->status == 303); }
public function hasRedirectHTTPStatus() {
$isRedirect = ($this->status == 301 || $this->status == 302 || $this->status == 303);
$this->redirect30xCount( $isRedirect );
return $isRedirect;
}

# Returns the value of the Content-Type [HTTP header] for the resolved URL.
# If header not provided, _null_ is returned. Examples: text/html, image/jpeg, ...
Expand Down Expand Up @@ -614,6 +626,12 @@ public function isStartingURL($value=null) {
return $this->is_starting_point;
}

# Returns number of 30x redirects we've been through
public function redirect30xCount($value=null) {
if (isset($value)) { $this->redirect_30x_count += $value; }
return $this->redirect_30x_count;
}

# Returns true if an error occurred while resolving the URL.
# If this returns false, $url_result is guaranteed to have a status code.
public function didErrorOccur() {
Expand Down