/**
 * Given a URL extracted from a page, return an absolute URL
 *
 * Takes a URL (e.g. /test) extracted from a page (e.g. http://foo.com/bar/) and
 * returns an absolute URL (e.g. http://foo.com/bar/test). Absolute URLs are
 * returned as-is.
 *
 * A null value is returned in the event that the extracted_url is blank or it's
 * unable to be parsed.
 *
 * @param  string       $extracted_url   Relative or absolute URL extracted from page
 * @param  string       $page_url        URL of page
 * @return string|null                   Absolute URL, or null
 */
function sist_relative_to_absolute_url($extracted_url, $page_url)
{
    $extracted_url = trim($extracted_url);
    if ($extracted_url === '') {
        return null;
    }
    // check for a protocol-less URL
    // (Note: there's a bug in PHP <= 5.4.7 where parsed URLs starting with //
    // are treated as a path. So we're doing this check upfront.)
    // http://php.net/manual/en/function.parse-url.php#example-4617
    if (strpos($extracted_url, '//') === 0) {
        // if this is a local URL, add the protocol to the URL
        if (stripos($extracted_url, '//' . sist_get_origin_host()) === 0) {
            $extracted_url = substr_replace($extracted_url, sist_get_origin_scheme() . '://', 0, 2);
        }
        return $extracted_url;
    }
    $parsed_extracted_url = parse_url($extracted_url);
    // parse_url can sometimes return false; bail if it does
    if ($parsed_extracted_url === false) {
        return null;
    }
    if (isset($parsed_extracted_url['host'])) {
        return $extracted_url;
    } elseif (isset($parsed_extracted_url['scheme'])) {
        // examples of schemes without hosts: java:, data:
        return $extracted_url;
    } else {
        // no host on extracted page (might be relative url)
        $path = isset($parsed_extracted_url['path']) ? $parsed_extracted_url['path'] : '';
        $query = isset($parsed_extracted_url['query']) ? '?' . $parsed_extracted_url['query'] : '';
        $fragment = isset($parsed_extracted_url['fragment']) ? '#' . $parsed_extracted_url['fragment'] : '';
        // turn our relative url into an absolute url
        $extracted_url = phpUri::parse($page_url)->join($path . $query . $fragment);
        return $extracted_url;
    }
}
 /**
  * Render the options page.
  *
  * @return void
  */
 public function display_options_page()
 {
     if (isset($_POST['save'])) {
         $this->save_options();
         $message = __('Settings saved.', self::SLUG);
         $this->view->add_flash('updated', $message);
     }
     $this->view->set_layout('admin')->set_template('options')->assign('slug', self::SLUG)->assign('origin_scheme', sist_get_origin_scheme())->assign('origin_host', sist_get_origin_host())->assign('destination_scheme', $this->options->get('destination_scheme'))->assign('destination_host', $this->options->get('destination_host'))->assign('temp_files_dir', $this->options->get('temp_files_dir'))->assign('additional_urls', $this->options->get('additional_urls'))->assign('delivery_method', $this->options->get('delivery_method'))->assign('local_dir', $this->options->get('local_dir'))->assign('delete_temp_files', $this->options->get('delete_temp_files'))->assign('aws_s3_bucket', $this->options->get('aws_s3_bucket'))->assign('aws_access_key_id', $this->options->get('aws_access_key_id'))->assign('aws_secret_access_key', $this->options->get('aws_secret_access_key'))->render();
 }