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;
27 public $error = false;
38 function __construct() {
40 $this->config = array();
41 $this->page = array();
42 $this->pager= array();
44 $this->scheme = ((isset($_SERVER['HTTPS'])
45 && ($_SERVER['HTTPS'])) ? 'https' : 'http' );
46 $this->hostname = str_replace('www.','',
47 $_SERVER['SERVER_NAME']);
48 set_include_path("include/$this->hostname"
49 . PATH_SEPARATOR . 'include'
50 . PATH_SEPARATOR . '.' );
52 if(substr($_SERVER['QUERY_STRING'],0,2) == "q=")
53 $_SERVER['QUERY_STRING'] = substr($_SERVER['QUERY_STRING'],2);
54 $this->cmd = trim($_GET['q'],'/');
57 $this->argv = explode('/',$this->cmd);
58 $this->argc = count($this->argv);
59 if((array_key_exists('0',$this->argv)) && strlen($this->argv[0])) {
60 $this->module = $this->argv[0];
63 $this->module = 'home';
65 $this->pager['page'] = ((x($_GET,'page')) ? $_GET['page'] : 1);
66 $this->pager['itemspage'] = 50;
67 $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
68 $this->pager['total'] = 0;
71 function get_baseurl($ssl = false) {
73 return (($ssl) ? 'https' : $this->scheme) . "://" . $this->hostname
74 . ((isset($this->path) && strlen($this->path))
75 ? '/' . $this->path : '' );
78 function set_path($p) {
79 $this->path = ltrim(trim($p),'/');
82 function set_pager_total($n) {
83 $this->pager['total'] = intval($n);
85 function set_pager_itemspage($n) {
86 $this->pager['itemspage'] = intval($n);
87 $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
91 function init_pagehead() {
92 if(file_exists("view/head.tpl"))
93 $s = file_get_contents("view/head.tpl");
94 $this->page['htmlhead'] = replace_macros($s,array('$baseurl' => $this->get_baseurl()));
100 if(! function_exists('x')) {
101 function x($s,$k = NULL) {
103 if((is_array($s)) && (array_key_exists($k,$s))) {
121 if(! function_exists('system_unavailable')) {
122 function system_unavailable() {
123 include('system_unavailable.php');
127 if(! function_exists('replace_macros')) {
128 function replace_macros($s,$r) {
133 if(is_array($r) && count($r)) {
134 foreach ($r as $k => $v ) {
139 return str_replace($search,$replace,$s);
144 if(! function_exists('fetch_url')) {
145 function fetch_url($url,$binary = false) {
146 $ch = curl_init($url);
147 if(! $ch) return false;
149 curl_setopt($ch, CURLOPT_HEADER, 0);
150 curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
151 curl_setopt($ch, CURLOPT_MAXREDIRS,8);
152 curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
154 curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
162 if(! function_exists('post_url')) {
163 function post_url($url,$params) {
164 $ch = curl_init($url);
165 if(! $ch) return false;
167 curl_setopt($ch, CURLOPT_HEADER, 0);
168 curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
169 curl_setopt($ch, CURLOPT_MAXREDIRS,8);
170 curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
171 curl_setopt($ch, CURLOPT_POST,1);
172 curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
180 if(! function_exists('random_string')) {
181 function random_string() {
182 return(hash('sha256',uniqid(rand(),true)));
185 if(! function_exists('notags')) {
186 function notags($string) {
187 // protect against :<> with high-bit set
188 return(str_replace(array("<",">","\xBA","\xBC","\xBE"), array('[',']','','',''), $string));
191 // The PHP built-in tag escape function has traditionally been buggy
192 if(! function_exists('escape_tags')) {
193 function escape_tags($string) {
195 array('&', '"', "'", '<', '>'),
196 array('&', '"', ''', '<', '>'), $string));
199 if(! function_exists('login')) {
200 function login($register = false) {
202 $register_html = (($register) ? file_get_contents("view/register-link.tpl") : "");
205 if(x($_SESSION,'authenticated')) {
206 $o = file_get_contents("view/logout.tpl");
209 $o = file_get_contents("view/login.tpl");
211 $o = replace_macros($o,array('$register_html' => $register_html ));
217 if(! function_exists('autoname')) {
218 function autoname($len) {
220 $vowels = array('a','a','ai','au','e','e','e','ee','ea','i','ie','o','ou','u');
221 if(mt_rand(0,5) == 4)
239 's','sc','sh','sm','sp','st',
247 $midcons = array('ck','ct','gn','ld','lf','lm','lt','mb','mm', 'mn','mp',
248 'nd','ng','nk','nt','rn','rp','rt');
250 $noend = array('bl', 'br', 'cl','cr','dr','fl','fr','gl','gr',
251 'kh', 'kl','kr','mn','pl','pr','rh','tr','qu','wh');
253 $start = mt_rand(0,2);
261 for ($x = 0; $x < $len; $x ++) {
262 $r = mt_rand(0,count($table) - 1);
265 if($table == $vowels)
266 $table = array_merge($cons,$midcons);
272 $word = substr($word,0,$len);
274 foreach($noend as $noe) {
275 if((strlen($word) > 2) && (substr($word,-2) == $noe)) {
276 $word = substr($word,0,-1);
280 if(substr($word,-1) == 'q')
281 $word = substr($word,0,-1);
285 if(! function_exists('killme')) {
287 session_write_close();
291 if(! function_exists('goaway')) {
292 function goaway($s) {
293 header("Location: $s");
298 if(! function_exists('xml_status')) {
299 function xml_status($st) {
300 header( "Content-type: text/xml");
301 echo '<?xml version="1.0" encoding="UTF-8"?>'."\r\n";
302 echo "<result><status>$st</status></result>\r\n";
306 if(! function_exists('local_user')) {
307 function local_user() {
308 if((x($_SESSION,'authenticated')) && (x($_SESSION,'uid')))
309 return $_SESSION['uid'];
313 if(! function_exists('remote_user')) {
314 function remote_user() {
315 if((x($_SESSION,'authenticated')) && (x($_SESSION,'cid')))
316 return $_SESSION['cid'];
320 function footer(&$a) {
322 $s = fetch_url("http://fortunemod.com/cookie.php?equal=1");
323 $a->page['content'] .= "<div class=\"fortune\" >$s</div>";
326 if(! function_exists('notice')) {
327 function notice($s) {
329 $_SESSION['sysmsg'] .= $s;
334 if(! function_exists('xmlify')) {
335 function xmlify($str) {
338 for($x = 0; $x < strlen($str); $x ++) {
369 $buffer = trim($buffer);
374 function hex2bin($s) {
375 return(pack("H*",$s));
379 function paginate(&$a) {
381 $stripped = ereg_replace("(&page=[0-9]*)","",$_SERVER['QUERY_STRING']);
382 $stripped = str_replace('q=','',$stripped);
383 $stripped = trim($stripped,'/');
384 $url = $a->get_baseurl() . '/' . $stripped;
387 if($a->pager['total'] > $a->pager['itemspage']) {
388 $o .= '<div class="pager">';
389 if($a->pager['page'] != 1)
390 $o .= '<span class="pager_prev">'."<a href=\"$url".'&page='.($a->pager['page'] - 1).'">prev</a></span> ';
392 $o .= "<span class=\"pager_first\"><a href=\"$url"."&page=1\">first</a></span> ";
394 $numpages = $a->pager['total'] / $a->pager['itemspage'];
397 $numstop = $numpages;
400 $numstart = (($pagenum > 7) ? ($pagenum - 7) : 1);
401 $numstop = (($pagenum > ($numpages - 7)) ? $numpages : ($numstart + 14));
404 for($i = $numstart; $i <= $numstop; $i++){
405 if($i == $a->pager['page'])
406 $o .= '<span class="pager_current">'.(($i < 10) ? ' '.$i : $i);
408 $o .= "<span class=\"pager_n\"><a href=\"$url"."&page=$i\">".(($i < 10) ? ' '.$i : $i)."</a>";
412 if(($a->pager['total'] % $a->pager['itemspage']) != 0) {
413 if($i == $a->pager['page'])
414 $o .= '<span class="pager_current">'.(($i < 10) ? ' '.$i : $i);
416 $o .= "<span class=\"pager_n\"><a href=\"$url"."&page=$i\">".(($i < 10) ? ' '.$i : $i)."</a>";
420 $lastpage = (($numpages > intval($numpages)) ? intval($numpages)+1 : $numpages);
421 $o .= "<span class=\"pager_last\"><a href=\"$url"."&page=$lastpage\">last</a></span> ";
423 if(($a->pager['total'] - ($a->pager['itemspage'] * $a->pager['page'])) > 0)
424 $o .= '<span class="pager_next">'."<a href=\"$url"."&page=".($a->pager['page'] + 1).'">next</a></span>';
425 $o .= '</div>'."\r\n";
430 function expand_acl($s) {
433 $a = explode('<',$s);
434 for($x = 0; $x < count($a); $x ++) {
435 $a[$x] = intval(str_replace(array('<','>'),array('',''),$a[$x]));