aboutsummaryrefslogtreecommitdiffstats
path: root/mod/parse_url.php
blob: 33381a0d271be0363535bf2a6e29aa5ad892ccc6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php

require_once('library/HTML5/Parser.php');

function parse_url_content(&$a) {
	$url = trim($_GET['url']);

	$template = "<a href=\"%s\" >%s</a>";

	if($url) 
		$s = fetch_url($url);
	
	if(! $s) {
		echo sprintf($template,$url,$url);
		killme();
	}

	$dom = HTML5_Parser::parse($s);

	if(! $dom)
		return $ret;

	$items = $dom->getElementsByTagName('title');
	
	foreach($items as $item) {
		$title = $item->textContent;
		break;
	}

	echo sprintf($template,$url,$title);
	killme();
}