5 define('EOL', "<br />\r\n");
7 define('REGISTER_CLOSED', 0);
8 define('REGISTER_APPROVE', 1);
9 define('REGISTER_OPEN', 2);
11 define ( 'DIRECTION_ANY', 0);
12 define ( 'DIRECTION_IN', 1);
13 define ( 'DIRECTION_OUT', 2);
14 define ( 'DIRECTION_BOTH', 3);
16 if(! class_exists('App')) {
19 public $module_loaded = false;
26 public $error = false;
37 function __construct() {
39 $this->config = array();
40 $this->page = array();
42 $this->scheme = ((isset($_SERVER['HTTPS'])
43 && ($_SERVER['HTTPS'])) ? 'https' : 'http' );
44 $this->hostname = str_replace('www.','',
45 $_SERVER['SERVER_NAME']);
46 set_include_path("include/$this->hostname"
47 . PATH_SEPARATOR . 'include'
48 . PATH_SEPARATOR . '.' );
50 if(substr($_SERVER['QUERY_STRING'],0,2) == "q=")
51 $_SERVER['QUERY_STRING'] = substr($_SERVER['QUERY_STRING'],2);
52 // $this->cmd = trim($_SERVER['QUERY_STRING'],'/');
53 $this->cmd = trim($_GET['q'],'/');
55 $this->argv = explode('/',$this->cmd);
56 $this->argc = count($this->argv);
57 if((array_key_exists('0',$this->argv)) && strlen($this->argv[0])) {
58 $this->module = $this->argv[0];
61 $this->module = 'home';
65 function get_baseurl($ssl = false) {
67 return (($ssl) ? 'https' : $this->scheme) . "://" . $this->hostname
68 . ((isset($this->path) && strlen($this->path))
69 ? '/' . $this->path : '' );
72 function set_path($p) {
73 $this->path = ltrim(trim($p),'/');
76 function init_pagehead() {
77 if(file_exists("view/head.tpl"))
78 $s = file_get_contents("view/head.tpl");
79 $this->page['htmlhead'] = replace_macros($s,array('$baseurl' => $this->get_baseurl()));
85 if(! function_exists('x')) {
86 function x($s,$k = NULL) {
88 if((is_array($s)) && (array_key_exists($k,$s))) {
106 if(! function_exists('system_unavailable')) {
107 function system_unavailable() {
108 include('system_unavailable.php');
112 if(! function_exists('replace_macros')) {
113 function replace_macros($s,$r) {
118 if(is_array($r) && count($r)) {
119 foreach ($r as $k => $v ) {
124 return str_replace($search,$replace,$s);
129 if(! function_exists('fetch_url')) {
130 function fetch_url($url,$binary = false) {
131 $ch = curl_init($url);
132 if(! $ch) return false;
134 curl_setopt($ch, CURLOPT_HEADER, 0);
135 curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
136 curl_setopt($ch, CURLOPT_MAXREDIRS,8);
137 curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
139 curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
147 if(! function_exists('post_url')) {
148 function post_url($url,$params) {
149 $ch = curl_init($url);
150 if(! $ch) return false;
152 curl_setopt($ch, CURLOPT_HEADER, 0);
153 curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
154 curl_setopt($ch, CURLOPT_MAXREDIRS,8);
155 curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
156 curl_setopt($ch, CURLOPT_POST,1);
157 curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
165 if(! function_exists('random_string')) {
166 function random_string() {
167 return(hash('sha256',uniqid(rand(),true)));
170 if(! function_exists('notags')) {
171 function notags($string) {
172 // protect against :<> with high-bit set
173 return(str_replace(array("<",">","\xBA","\xBC","\xBE"), array('[',']','','',''), $string));
176 // The PHP built-in tag escape function has traditionally been buggy
177 if(! function_exists('escape_tags')) {
178 function escape_tags($string) {
179 return(str_replace(array("<",">","&"), array('<','>','&'), $string));
182 if(! function_exists('login')) {
183 function login($register = false) {
185 $register_html = (($register) ? file_get_contents("view/register-link.tpl") : "");
188 if(x($_SESSION,'authenticated')) {
189 $o = file_get_contents("view/logout.tpl");
192 $o = file_get_contents("view/login.tpl");
194 $o = replace_macros($o,array('$register_html' => $register_html ));
200 if(! function_exists('autoname')) {
201 function autoname($len) {
203 $vowels = array('a','a','ai','au','e','e','e','ee','ea','i','ie','o','ou','u');
204 if(mt_rand(0,5) == 4)
222 's','sc','sh','sm','sp','st',
230 $midcons = array('ck','ct','gn','ld','lf','lm','lt','mb','mm', 'mn','mp',
231 'nd','ng','nk','nt','rn','rp','rt');
233 $noend = array('bl', 'br', 'cl','cr','dr','fl','fr','gl','gr',
234 'kh', 'kl','kr','mn','pl','pr','rh','tr','qu','wh');
236 $start = mt_rand(0,2);
244 for ($x = 0; $x < $len; $x ++) {
245 $r = mt_rand(0,count($table) - 1);
248 if($table == $vowels)
249 $table = array_merge($cons,$midcons);
255 $word = substr($word,0,$len);
257 foreach($noend as $noe) {
258 if((strlen($word) > 2) && (substr($word,-2) == $noe)) {
259 $word = substr($word,0,-1);
263 if(substr($word,-1) == 'q')
264 $word = substr($word,0,-1);
268 if(! function_exists('killme')) {
270 session_write_close();
274 if(! function_exists('goaway')) {
275 function goaway($s) {
276 header("Location: $s");
281 if(! function_exists('xml_status')) {
282 function xml_status($st) {
283 header( "Content-type: text/xml");
284 echo '<?xml version="1.0" encoding="UTF-8"?>'."\r\n";
285 echo "<result><status>$st</status></result>\r\n";
289 if(! function_exists('local_user')) {
290 function local_user() {
291 if((x($_SESSION,'authenticated')) && (x($_SESSION,'uid')))
292 return $_SESSION['uid'];
296 if(! function_exists('remote_user')) {
297 function remote_user() {
298 if((x($_SESSION,'authenticated')) && (x($_SESSION,'cid')))
299 return $_SESSION['cid'];
303 function footer(&$a) {
305 $s = fetch_url("http://fortunemod.com/cookie.php?equal=1");
306 $a->page['content'] .= "<div class=\"fortune\" >$s</div>";
309 if(! function_exists('notice')) {
310 function notice($s) {
312 $_SESSION['sysmsg'] .= $s;
317 if(! function_exists('xmlify')) {
318 function xmlify($str) {
321 for($x = 0; $x < strlen($str); $x ++) {
352 $buffer = trim($buffer);
357 function hex2bin($s) {
358 return(pack("H*",$s));