<?php

include '../../inc/init.inc';
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
//ini_set('display_errors', 0);
$url = urldecode($_GET['url']);
$url = Request::checkValues($url);
$return_array = array();
$base_url = substr($url, 0, strpos($url, "/", 8));
$relative_url = substr($url, 0, strrpos($url, "/") + 1);
// Get Data
$cc = new cURL(false);
$string = $cc->get($url);
$string = str_replace(array("\n", "\r", "\t", '</span>', '</div>'), '', $string);
$string = preg_replace('/(<(div|span)\\s[^>]+\\s?>)/', '', $string);
if (mb_detect_encoding($string, "UTF-8") != "UTF-8") {
    $string = utf8_encode($string);
}
// Parse Title
$nodes = Request::extract_tags($string, 'title');
$return_array['title'] = trim($nodes[0]['contents']);
// Parse Base
$base_override = false;
$base_regex = '/<base[^>]*' . 'href=[\\"|\'](.*)[\\"|\']/Ui';
preg_match_all($base_regex, $string, $base_match, PREG_PATTERN_ORDER);
if (strlen($base_match[1][0]) > 0) {
    $base_url = $base_match[1][0];
    $base_override = true;
}
// Parse Description
$return_array['description'] = '';