http_get( $this->origin() . '/', 'GET /', $evidence );
if ( '' !== $res['error'] && 0 === $res['code'] ) {
return $this->unable( 'Could not reach the homepage — ' . $res['error'], $evidence );
}
if ( 200 !== $res['code'] ) {
return $this->fail( 'Homepage returned HTTP ' . $res['code'], $evidence );
}
$html = $res['body'];
$head = preg_match( '#
]*>(.*?)#is', $html, $m ) ? $m[1] : $html;
$signals = array(
'lang' => (bool) preg_match( '#]*\blang=["\'][a-z]#i', $html ),
'canonical' => (bool) preg_match( '#]*\brel=["\']canonical["\']#i', $head ),
'og:type' => (bool) preg_match( '#]*\bproperty=["\']og:type["\']#i', $head ),
'og:image' => (bool) preg_match( '#]*\bproperty=["\']og:image["\']#i', $head ),
);
$has_title = (bool) preg_match( '#]*>\s*\S#i', $head );
$missing = array_keys(
array_filter(
$signals,
static function ( $v ) {
return ! $v;
}
)
);
$present = array_keys( array_filter( $signals ) );
$details = array(
'present' => $present,
'missing' => $missing,
'title' => $has_title,
);
$evidence[] = Evidence::parse(
'Inspect for identity metadata',
empty( $missing ) ? 'positive' : 'negative',
'Present: ' . ( empty( $present ) ? 'none' : implode( ', ', $present ) ) . '. Missing: ' . ( empty( $missing ) ? 'none' : implode( ', ', $missing ) ) . '.'
);
if ( ! empty( $missing ) ) {
return $this->fail( 'Homepage is missing ' . implode( ', ', $missing ), $evidence, $details );
}
return $this->pass( 'Homepage declares lang, canonical, og:type and og:image', $evidence, $details );
}
}