Skip to content

Commit

Permalink
one URL validator for all subclass uses
Browse files Browse the repository at this point in the history
  • Loading branch information
niallkennedy committed Nov 12, 2011
1 parent 20752e5 commit f8701ed
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions objects.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@ public static function datetime_to_iso_8601( DateTime $date ) {
$date->setTimezone(new DateTimeZone('GMT'));
return $date->format('c');
}

/**
* Test a URL for validity.
*
* @uses OpenGraphProtocol::is_valid_url if OpenGraphProtocol::VERIFY_URLS is true
* @param string $url absolute URL addressable from the public web
* @return bool true if URL is non-empty string. if VERIFY_URLS set then URL must also properly respond to a HTTP request.
*/
public static function is_valid_url( $url ) {
if ( is_string($url) && !empty($url) ) {
if (OpenGraphProtocol::VERIFY_URLS) {
$url = OpenGraphProtocol::is_valid_url( $url, array( 'text/html', 'application/xhtml+xml' ) );
if (!empty($url))
return true;
} else {
return true;
}
}
return false;
}
}

class OpenGraphProtocolArticle extends OpenGraphProtocolObject {
Expand Down Expand Up @@ -169,13 +189,9 @@ public function getAuthors() {
* @param string $author_uri Author URI
*/
public function addAuthor( $author_uri ) {
if ( is_string($author_uri) && !empty($author_uri) && !in_array($author_uri, $this->author)) {
if (OpenGraphProtocol::VERIFY_URLS) {
$author_uri = OpenGraphProtocol::is_valid_url( $author_uri, array( 'text/html', 'application/xhtml+xml' ) );
}
if (!empty($author_uri))
$this->author[] = $author_uri;
}
var_dump( static::is_valid_url($author_uri) );
if ( static::is_valid_url($author_uri) && !in_array($author_uri, $this->author))
$this->author[] = $author_uri;
return $this;
}

Expand Down Expand Up @@ -383,13 +399,8 @@ public function getAuthors() {
* @param string $author_uri
*/
public function addAuthor( $author_uri ) {
if ( is_string($author_uri) && !empty($author_uri) && !in_array($author_uri, $this->author)) {
if (OpenGraphProtocol::VERIFY_URLS) {
$author_uri = OpenGraphProtocol::is_valid_url( $author_uri, array( 'text/html', 'application/xhtml+xml' ) );
}
if (!empty($author_uri))
$this->author[] = $author_uri;
}
if ( static::is_valid_url($author_uri) && !in_array($author_uri, $this->author))
$this->author[] = $author_uri;
return $this;
}

Expand Down

0 comments on commit f8701ed

Please sign in to comment.