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 define ( 'NOTIFY_INTRO', 0x0001 );
17 define ( 'NOTIFY_CONFIRM', 0x0002 );
18 define ( 'NOTIFY_WALL', 0x0004 );
19 define ( 'NOTIFY_COMMENT', 0x0008 );
20 define ( 'NOTIFY_MAIL', 0x0010 );
25 if(! class_exists('App')) {
28 public $module_loaded = false;
36 public $error = false;
49 function __construct() {
51 $this->config = array();
52 $this->page = array();
53 $this->pager= array();
55 $this->scheme = ((isset($_SERVER['HTTPS'])
56 && ($_SERVER['HTTPS'])) ? 'https' : 'http' );
57 $this->hostname = str_replace('www.','',
58 $_SERVER['SERVER_NAME']);
59 set_include_path("include/$this->hostname"
60 . PATH_SEPARATOR . 'include'
61 . PATH_SEPARATOR . '.' );
63 if(substr($_SERVER['QUERY_STRING'],0,2) == "q=")
64 $_SERVER['QUERY_STRING'] = substr($_SERVER['QUERY_STRING'],2);
65 $this->cmd = trim($_GET['q'],'/');
68 $this->argv = explode('/',$this->cmd);
69 $this->argc = count($this->argv);
70 if((array_key_exists('0',$this->argv)) && strlen($this->argv[0])) {
71 $this->module = $this->argv[0];
74 $this->module = 'home';
76 $this->pager['page'] = ((x($_GET,'page')) ? $_GET['page'] : 1);
77 $this->pager['itemspage'] = 50;
78 $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
79 $this->pager['total'] = 0;
82 function get_baseurl($ssl = false) {
83 if(strlen($this->baseurl))
84 return $this->baseurl;
86 $this->baseurl = (($ssl) ? 'https' : $this->scheme) . "://" . $this->hostname
87 . ((isset($this->path) && strlen($this->path))
88 ? '/' . $this->path : '' );
89 return $this->baseurl;
92 function set_baseurl($url) {
93 $this->baseurl = $url;
96 function get_hostname() {
97 return $this->hostname;
100 function set_hostname($h) {
101 $this->hostname = $h;
104 function set_path($p) {
105 $this->path = ltrim(trim($p),'/');
108 function get_path() {
112 function set_pager_total($n) {
113 $this->pager['total'] = intval($n);
116 function set_pager_itemspage($n) {
117 $this->pager['itemspage'] = intval($n);
118 $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
122 function init_pagehead() {
123 if(file_exists("view/head.tpl"))
124 $s = file_get_contents("view/head.tpl");
125 $this->page['htmlhead'] = replace_macros($s,array('$baseurl' => $this->get_baseurl()));
131 if(! function_exists('x')) {
132 function x($s,$k = NULL) {
134 if((is_array($s)) && (array_key_exists($k,$s))) {
152 if(! function_exists('system_unavailable')) {
153 function system_unavailable() {
154 include('system_unavailable.php');
158 if(! function_exists('replace_macros')) {
159 function replace_macros($s,$r) {
164 if(is_array($r) && count($r)) {
165 foreach ($r as $k => $v ) {
170 return str_replace($search,$replace,$s);
175 if(! function_exists('fetch_url')) {
176 function fetch_url($url,$binary = false) {
177 $ch = curl_init($url);
178 if(! $ch) return false;
180 curl_setopt($ch, CURLOPT_HEADER, 0);
181 curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
182 curl_setopt($ch, CURLOPT_MAXREDIRS,8);
183 curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
185 curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
193 if(! function_exists('post_url')) {
194 function post_url($url,$params) {
195 $ch = curl_init($url);
196 if(! $ch) return false;
198 curl_setopt($ch, CURLOPT_HEADER, 0);
199 curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
200 curl_setopt($ch, CURLOPT_MAXREDIRS,8);
201 curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
202 curl_setopt($ch, CURLOPT_POST,1);
203 curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
211 if(! function_exists('random_string')) {
212 function random_string() {
213 return(hash('sha256',uniqid(rand(),true)));
216 if(! function_exists('notags')) {
217 function notags($string) {
218 // protect against :<> with high-bit set
219 return(str_replace(array("<",">","\xBA","\xBC","\xBE"), array('[',']','','',''), $string));
222 if(! function_exists('escape_tags')) {
223 function escape_tags($string) {
225 return(htmlspecialchars($string));
228 if(! function_exists('login')) {
229 function login($register = false) {
231 $register_html = (($register) ? file_get_contents("view/register-link.tpl") : "");
234 if(x($_SESSION,'authenticated')) {
235 $o = file_get_contents("view/logout.tpl");
238 $o = file_get_contents("view/login.tpl");
240 $o = replace_macros($o,array('$register_html' => $register_html ));
246 if(! function_exists('autoname')) {
247 function autoname($len) {
249 $vowels = array('a','a','ai','au','e','e','e','ee','ea','i','ie','o','ou','u');
250 if(mt_rand(0,5) == 4)
268 's','sc','sh','sm','sp','st',
276 $midcons = array('ck','ct','gn','ld','lf','lm','lt','mb','mm', 'mn','mp',
277 'nd','ng','nk','nt','rn','rp','rt');
279 $noend = array('bl', 'br', 'cl','cr','dr','fl','fr','gl','gr',
280 'kh', 'kl','kr','mn','pl','pr','rh','tr','qu','wh');
282 $start = mt_rand(0,2);
290 for ($x = 0; $x < $len; $x ++) {
291 $r = mt_rand(0,count($table) - 1);
294 if($table == $vowels)
295 $table = array_merge($cons,$midcons);
301 $word = substr($word,0,$len);
303 foreach($noend as $noe) {
304 if((strlen($word) > 2) && (substr($word,-2) == $noe)) {
305 $word = substr($word,0,-1);
309 if(substr($word,-1) == 'q')
310 $word = substr($word,0,-1);
314 if(! function_exists('killme')) {
316 session_write_close();
320 if(! function_exists('goaway')) {
321 function goaway($s) {
322 header("Location: $s");
327 if(! function_exists('xml_status')) {
328 function xml_status($st) {
329 header( "Content-type: text/xml" );
330 echo '<?xml version="1.0" encoding="UTF-8"?>'."\r\n";
331 echo "<result><status>$st</status></result>\r\n";
335 if(! function_exists('local_user')) {
336 function local_user() {
337 if((x($_SESSION,'authenticated')) && (x($_SESSION,'uid')))
338 return $_SESSION['uid'];
342 if(! function_exists('remote_user')) {
343 function remote_user() {
344 if((x($_SESSION,'authenticated')) && (x($_SESSION,'cid')))
345 return $_SESSION['cid'];
349 function footer(&$a) {
351 $s = fetch_url("http://fortunemod.com/cookie.php?equal=1");
352 $a->page['content'] .= "<div class=\"fortune\" >$s</div>";
355 if(! function_exists('notice')) {
356 function notice($s) {
358 $_SESSION['sysmsg'] .= $s;
362 if(! function_exists('get_max_import_size')) {
363 function get_max_import_size() {
365 return ((x($a->config,'max_import_size')) ? $a->config['max_import_size'] : 0 );
368 if(! function_exists('xmlify')) {
369 function xmlify($str) {
372 for($x = 0; $x < strlen($str); $x ++) {
403 $buffer = trim($buffer);
407 function unxmlify($s) {
408 $ret = str_replace('&','&', $s);
409 $ret = str_replace(array('<','>','"','''),array('<','>','"',"'"),$ret);
413 function hex2bin($s) {
414 return(pack("H*",$s));
418 function paginate(&$a) {
420 $stripped = ereg_replace("(&page=[0-9]*)","",$_SERVER['QUERY_STRING']);
421 $stripped = str_replace('q=','',$stripped);
422 $stripped = trim($stripped,'/');
423 $url = $a->get_baseurl() . '/' . $stripped;
426 if($a->pager['total'] > $a->pager['itemspage']) {
427 $o .= '<div class="pager">';
428 if($a->pager['page'] != 1)
429 $o .= '<span class="pager_prev">'."<a href=\"$url".'&page='.($a->pager['page'] - 1).'">prev</a></span> ';
431 $o .= "<span class=\"pager_first\"><a href=\"$url"."&page=1\">first</a></span> ";
433 $numpages = $a->pager['total'] / $a->pager['itemspage'];
436 $numstop = $numpages;
439 $numstart = (($pagenum > 7) ? ($pagenum - 7) : 1);
440 $numstop = (($pagenum > ($numpages - 7)) ? $numpages : ($numstart + 14));
443 for($i = $numstart; $i <= $numstop; $i++){
444 if($i == $a->pager['page'])
445 $o .= '<span class="pager_current">'.(($i < 10) ? ' '.$i : $i);
447 $o .= "<span class=\"pager_n\"><a href=\"$url"."&page=$i\">".(($i < 10) ? ' '.$i : $i)."</a>";
451 if(($a->pager['total'] % $a->pager['itemspage']) != 0) {
452 if($i == $a->pager['page'])
453 $o .= '<span class="pager_current">'.(($i < 10) ? ' '.$i : $i);
455 $o .= "<span class=\"pager_n\"><a href=\"$url"."&page=$i\">".(($i < 10) ? ' '.$i : $i)."</a>";
459 $lastpage = (($numpages > intval($numpages)) ? intval($numpages)+1 : $numpages);
460 $o .= "<span class=\"pager_last\"><a href=\"$url"."&page=$lastpage\">last</a></span> ";
462 if(($a->pager['total'] - ($a->pager['itemspage'] * $a->pager['page'])) > 0)
463 $o .= '<span class="pager_next">'."<a href=\"$url"."&page=".($a->pager['page'] + 1).'">next</a></span>';
464 $o .= '</div>'."\r\n";
469 function expand_acl($s) {
472 $a = explode('<',$s);
473 for($x = 0; $x < count($a); $x ++) {
474 $a[$x] = intval(str_replace(array('<','>'),array('',''),$a[$x]));