summaryrefslogtreecommitdiff
path: root/src/lib/Site.class.php
blob: 1204089dbe5f24a5f2c1946258cf317236eb731a (plain)
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('Singleton.class.php');
require_once('Database.class.php');

class Site extends Singleton {
	public function shortUrl($longUrl) {
		$ch = curl_init('http://ur1.ca');
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_POST, true);
		curl_setopt($ch, CURLOPT_POSTFILEDS,
		            'longurl='.urlencode($longUrl));
		$html = curl_exec();
		preg_match('/Your ur1 is: <a href="([^"]*)">/',$html,$matches);
		$shortUrl = $matches[1];
		curl_close($ch);
		return $shortUrl;
	}

	public function baseUrl() {
		$base = $_SERVER['REQUEST_URI'];
		
		$db = Database::getInstance();
		if ($db !== null) {
			$b = $db->getSysConf('baseurl');
			if ($b != false) {
				$base = $b;
			}
		}
		
		return $base;
	}
}