AMP_Blacklist_Sanitizer::validate_a_node PHP Method

validate_a_node() private method

private validate_a_node ( $node )
    private function validate_a_node($node)
    {
        // Get the href attribute
        $href = $node->getAttribute('href');
        if (empty($href)) {
            // If no href, check that a is an anchor or not.
            // We don't need to validate anchors any further.
            return $node->hasAttribute('name') || $node->hasAttribute('id');
        }
        // If this is an anchor link, just return true
        if (0 === strpos($href, '#')) {
            return true;
        }
        // If the href starts with a '/', append the home_url to it for validation purposes.
        if (0 === stripos($href, '/')) {
            $href = untrailingslashit(get_home_url()) . $href;
        }
        $valid_protocols = array('http', 'https', 'mailto', 'sms', 'tel', 'viber', 'whatsapp');
        $special_protocols = array('tel', 'sms');
        // these ones don't valid with `filter_var+FILTER_VALIDATE_URL`
        $protocol = strtok($href, ':');
        if (false === filter_var($href, FILTER_VALIDATE_URL) && !in_array($protocol, $special_protocols)) {
            return false;
        }
        if (!in_array($protocol, $valid_protocols)) {
            return false;
        }
        return true;
    }