5 define('EOL', '<br />');
7 define('REGISTER_CLOSED', 0);
8 define('REGISTER_APPROVE', 1);
9 define('REGISTER_OPEN', 2);
12 if(! class_exists('App')) {
15 public $module_loaded = false;
21 public $error = false;
32 function __construct() {
34 $this->config = array();
35 $this->page = array();
37 $this->scheme = ((isset($_SERVER['HTTPS'])
38 && ($_SERVER['HTTPS'])) ? 'https' : 'http' );
39 $this->hostname = str_replace('www.','',
40 $_SERVER['SERVER_NAME']);
41 set_include_path("include/$this->hostname"
42 . PATH_SEPARATOR . 'include'
43 . PATH_SEPARATOR . '.' );
45 if(substr($_SERVER['QUERY_STRING'],0,2) == "q=")
46 $_SERVER['QUERY_STRING'] = substr($_SERVER['QUERY_STRING'],2);
47 // $this->cmd = trim($_SERVER['QUERY_STRING'],'/');
48 $this->cmd = trim($_GET['q'],'/');
50 $this->argv = explode('/',$this->cmd);
51 $this->argc = count($this->argv);
52 if((array_key_exists('0',$this->argv)) && strlen($this->argv[0])) {
53 $this->module = $this->argv[0];
56 $this->module = 'home';
60 function get_baseurl($ssl = false) {
62 return (($ssl) ? 'https' : $this->scheme) . "://" . $this->hostname
63 . ((isset($this->path) && strlen($this->path))
64 ? '/' . $this->path : '' );
67 function set_path($p) {
68 $this->path = ltrim(trim($p),'/');
71 function init_pagehead() {
72 if(file_exists("view/head.tpl"))
73 $s = file_get_contents("view/head.tpl");
74 $this->page['htmlhead'] = replace_macros($s,array('$baseurl' => $this->get_baseurl()));
80 if(! function_exists('x')) {
81 function x($s,$k = NULL) {
83 if((is_array($s)) && (array_key_exists($k,$s))) {
101 if(! function_exists('system_unavailable')) {
102 function system_unavailable() {
103 include('system_unavailable.php');
107 if(! function_exists('replace_macros')) {
108 function replace_macros($s,$r) {
113 if(is_array($r) && count($r)) {
114 foreach ($r as $k => $v ) {
119 return str_replace($search,$replace,$s);
124 if(! function_exists('fetch_url')) {
125 function fetch_url($url,$binary = false) {
126 $ch = curl_init($url);
127 if(! $ch) return false;
129 curl_setopt($ch, CURLOPT_HEADER, 0);
130 curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
131 curl_setopt($ch, CURLOPT_MAXREDIRS,8);
132 curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
134 curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
142 if(! function_exists('post_url')) {
143 function post_url($url,$params) {
144 $ch = curl_init($url);
145 if(! $ch) return false;
147 curl_setopt($ch, CURLOPT_HEADER, 0);
148 curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
149 curl_setopt($ch, CURLOPT_MAXREDIRS,8);
150 curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
151 curl_setopt($ch, CURLOPT_POST,1);
152 curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
160 if(! function_exists('random_string')) {
161 function random_string() {
162 return(hash('sha256',uniqid(rand(),true)));
165 if(! function_exists('notags')) {
166 function notags($string) {
167 // protect against :<> with high-bit set
168 return(str_replace(array("<",">","\xBA","\xBC","\xBE"), array('[',']','','',''), $string));
171 // The PHP built-in tag escape function has traditionally been buggy
172 if(! function_exists('escape_tags')) {
173 function escape_tags($string) {
174 return(str_replace(array("<",">","&"), array('<','>','&'), $string));
177 if(! function_exists('login')) {
178 function login($register = false) {
180 $register_html = (($register) ? file_get_contents("view/register-link.tpl") : "");
183 if(x($_SESSION,'authenticated')) {
184 $o = file_get_contents("view/logout.tpl");
187 $o = file_get_contents("view/login.tpl");
189 $o = replace_macros($o,array('$register_html' => $register_html ));
195 if(! function_exists('autoname')) {
196 function autoname($len) {
198 $vowels = array('a','a','ai','au','e','e','e','ee','ea','i','ie','o','ou','u');
199 if(mt_rand(0,5) == 4)
217 's','sc','sh','sm','sp','st',
225 $midcons = array('ck','ct','gn','ld','lf','lm','lt','mb','mm', 'mn','mp',
226 'nd','ng','nk','nt','rn','rp','rt');
228 $noend = array('bl', 'br', 'cl','cr','dr','fl','fr','gl','gr',
229 'kh', 'kl','kr','mn','pl','pr','rh','tr','qu','wh');
231 $start = mt_rand(0,2);
239 for ($x = 0; $x < $len; $x ++) {
240 $r = mt_rand(0,count($table) - 1);
243 if($table == $vowels)
244 $table = array_merge($cons,$midcons);
250 $word = substr($word,0,$len);
252 foreach($noend as $noe) {
253 if((strlen($word) > 2) && (substr($word,-2) == $noe)) {
254 $word = substr($word,0,-1);
258 if(substr($word,-1) == 'q')
259 $word = substr($word,0,-1);
263 if(! function_exists('killme')) {
265 session_write_close();
269 if(! function_exists('goaway')) {
270 function goaway($s) {
271 header("Location: $s");
276 if(! function_exists('xml_status')) {
277 function xml_status($st) {
278 header( "Content-type: text/xml");
279 echo '<?xml version="1.0" encoding="UTF-8"?>'."\r\n";
280 echo "<result><status>$st</status></result>\r\n";
284 if(! function_exists('local_user')) {
285 function local_user() {
286 if((x($_SESSION,'authenticated')) && (x($_SESSION,'uid')))
287 return $_SESSION['uid'];
291 if(! function_exists('remote_user')) {
292 function remote_user() {
293 if((x($_SESSION,'authenticated')) && (x($_SESSION,'cid')))
294 return $_SESSION['cid'];
298 function footer(&$a) {
300 $s = fetch_url("http://fortunemod.com/cookie.php?equal=1");
301 $a->page['content'] .= "<div class=\"fortune\" >$s</div>";
304 if(! function_exists('notice')) {
305 function notice($s) {
307 $_SESSION['sysmsg'] .= $s;