summaryrefslogtreecommitdiff
path: root/src/lib/MessageManager.class.php
blob: d327eb7b270fb084783ea7cb7b7c36e29977e68a (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php

class MessageManager {
	private $conf;
	private $base;
	
	private $users = array();		
	
	private $database;
	private $pw_hasher;
	private $template;
	private $pluginManager;
	
	public function __construct($conf_file) {
		$this->conf = $conf_file;
		if (!file_exists($this->conf)) {
			$this->base = $_SERVER['REQUEST_URI'];
			$t = $this->template();
			$t->header('Message Manager');
			$t->paragraph(
			    'Awe shiz, dude, conf.php doesn\'t exist, you '.
			    'need to go through the '.
			    '<a href="installer">installer</a>.');
			$t->footer();
			exit();
		}
		session_start();
	}

	// Load Things
	
	public function database() {
		if (!isset($this->database)) {
			require_once('Database.class.php');
			$this->database = new Database($this->conf);
		}
		return $this->database;
	}

	public function hasher() {
		if (!isset($this->pw_hasher)) {
			require_once('PasswordHash.class.php');
			$this->pw_hasher = new PasswordHash(8, false);
		}
		return $this->pw_hasher;
	}
	
	public function template() {
		if (!isset($this->template)) {
			require_once(VIEWPATH.'/Template.class.php');
			$this->template = new Template($this->baseUrl(), $this);
		}
		return $this->template;
	}
	
	public function pluginManager() {
		if (!isset($this->pluginManager)) {
			require_once('PluginManager.class.php');
			$this->pluginManager = new PluginManager();
		}
		return $this->pluginManager;
	}

	// Utility functions
		
	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() {
		if (!isset($this->base)) {
			$this->base = $this->database()->getSysConf('baseurl');
		}
		return $this->base;
	}
}