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 );
22 define ( 'NAMESPACE_DFRN' , 'http://purl.org/macgirvin/dfrn/1.0' );
25 if(! class_exists('App')) {
28 public $module_loaded = false;
37 public $error = false;
51 function __construct() {
53 $this->config = array();
54 $this->page = array();
55 $this->pager= array();
57 $this->scheme = ((isset($_SERVER['HTTPS'])
58 && ($_SERVER['HTTPS'])) ? 'https' : 'http' );
59 $this->hostname = str_replace('www.','',
60 $_SERVER['SERVER_NAME']);
61 set_include_path("include/$this->hostname"
62 . PATH_SEPARATOR . 'include'
63 . PATH_SEPARATOR . '.' );
65 if(substr($_SERVER['QUERY_STRING'],0,2) == "q=")
66 $_SERVER['QUERY_STRING'] = substr($_SERVER['QUERY_STRING'],2);
67 $this->cmd = trim($_GET['q'],'/');
70 $this->argv = explode('/',$this->cmd);
71 $this->argc = count($this->argv);
72 if((array_key_exists('0',$this->argv)) && strlen($this->argv[0])) {
73 $this->module = $this->argv[0];
76 $this->module = 'home';
79 if($this->cmd == '.well-known/host-meta')
80 require_once('include/hostxrd.php');
82 $this->pager['page'] = ((x($_GET,'page')) ? $_GET['page'] : 1);
83 $this->pager['itemspage'] = 50;
84 $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
85 $this->pager['total'] = 0;
88 function get_baseurl($ssl = false) {
89 if(strlen($this->baseurl))
90 return $this->baseurl;
92 $this->baseurl = (($ssl) ? 'https' : $this->scheme) . "://" . $this->hostname
93 . ((isset($this->path) && strlen($this->path))
94 ? '/' . $this->path : '' );
95 return $this->baseurl;
98 function set_baseurl($url) {
99 $this->baseurl = $url;
102 function get_hostname() {
103 return $this->hostname;
106 function set_hostname($h) {
107 $this->hostname = $h;
110 function set_path($p) {
111 $this->path = ltrim(trim($p),'/');
114 function get_path() {
118 function set_pager_total($n) {
119 $this->pager['total'] = intval($n);
122 function set_pager_itemspage($n) {
123 $this->pager['itemspage'] = intval($n);
124 $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
128 function init_pagehead() {
129 if(file_exists("view/head.tpl"))
130 $s = file_get_contents("view/head.tpl");
131 $this->page['htmlhead'] = replace_macros($s,array('$baseurl' => $this->get_baseurl()));
137 if(! function_exists('x')) {
138 function x($s,$k = NULL) {
140 if((is_array($s)) && (array_key_exists($k,$s))) {
158 if(! function_exists('system_unavailable')) {
159 function system_unavailable() {
160 include('system_unavailable.php');
164 if(! function_exists('replace_macros')) {
165 function replace_macros($s,$r) {
170 if(is_array($r) && count($r)) {
171 foreach ($r as $k => $v ) {
176 return str_replace($search,$replace,$s);
180 function load_translation_table($lang) {
190 return $a->strings[$s];
194 if(! function_exists('fetch_url')) {
195 function fetch_url($url,$binary = false) {
196 $ch = curl_init($url);
197 if(! $ch) return false;
199 curl_setopt($ch, CURLOPT_HEADER, 0);
200 curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
201 curl_setopt($ch, CURLOPT_MAXREDIRS,8);
202 curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
204 curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
212 if(! function_exists('post_url')) {
213 function post_url($url,$params) {
214 $ch = curl_init($url);
215 if(! $ch) return false;
217 curl_setopt($ch, CURLOPT_HEADER, 0);
218 curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
219 curl_setopt($ch, CURLOPT_MAXREDIRS,8);
220 curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
221 curl_setopt($ch, CURLOPT_POST,1);
222 curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
230 if(! function_exists('random_string')) {
231 function random_string() {
232 return(hash('sha256',uniqid(rand(),true)));
235 if(! function_exists('notags')) {
236 function notags($string) {
237 // protect against :<> with high-bit set
238 return(str_replace(array("<",">","\xBA","\xBC","\xBE"), array('[',']','','',''), $string));
241 if(! function_exists('escape_tags')) {
242 function escape_tags($string) {
244 return(htmlspecialchars($string));
247 if(! function_exists('login')) {
248 function login($register = false) {
250 $register_html = (($register) ? file_get_contents("view/register-link.tpl") : "");
253 if(x($_SESSION,'authenticated')) {
254 $o = file_get_contents("view/logout.tpl");
257 $o = file_get_contents("view/login.tpl");
259 $o = replace_macros($o,array('$register_html' => $register_html ));
265 if(! function_exists('autoname')) {
266 function autoname($len) {
268 $vowels = array('a','a','ai','au','e','e','e','ee','ea','i','ie','o','ou','u');
269 if(mt_rand(0,5) == 4)
287 's','sc','sh','sm','sp','st',
295 $midcons = array('ck','ct','gn','ld','lf','lm','lt','mb','mm', 'mn','mp',
296 'nd','ng','nk','nt','rn','rp','rt');
298 $noend = array('bl', 'br', 'cl','cr','dr','fl','fr','gl','gr',
299 'kh', 'kl','kr','mn','pl','pr','rh','tr','qu','wh');
301 $start = mt_rand(0,2);
309 for ($x = 0; $x < $len; $x ++) {
310 $r = mt_rand(0,count($table) - 1);
313 if($table == $vowels)
314 $table = array_merge($cons,$midcons);
320 $word = substr($word,0,$len);
322 foreach($noend as $noe) {
323 if((strlen($word) > 2) && (substr($word,-2) == $noe)) {
324 $word = substr($word,0,-1);
328 if(substr($word,-1) == 'q')
329 $word = substr($word,0,-1);
333 if(! function_exists('killme')) {
335 session_write_close();
339 if(! function_exists('goaway')) {
340 function goaway($s) {
341 header("Location: $s");
346 if(! function_exists('xml_status')) {
347 function xml_status($st) {
348 header( "Content-type: text/xml" );
349 echo '<?xml version="1.0" encoding="UTF-8"?>'."\r\n";
350 echo "<result><status>$st</status></result>\r\n";
354 if(! function_exists('local_user')) {
355 function local_user() {
356 if((x($_SESSION,'authenticated')) && (x($_SESSION,'uid')))
357 return $_SESSION['uid'];
361 if(! function_exists('remote_user')) {
362 function remote_user() {
363 if((x($_SESSION,'authenticated')) && (x($_SESSION,'visitor_id')))
364 return $_SESSION['visitor_id'];
368 function footer(&$a) {
370 $s = fetch_url("http://fortunemod.com/cookie.php?equal=1");
371 $a->page['content'] .= "<div class=\"fortune\" >$s</div>";
374 if(! function_exists('notice')) {
375 function notice($s) {
377 $_SESSION['sysmsg'] .= $s;
381 if(! function_exists('get_max_import_size')) {
382 function get_max_import_size() {
384 return ((x($a->config,'max_import_size')) ? $a->config['max_import_size'] : 0 );
387 if(! function_exists('xmlify')) {
388 function xmlify($str) {
391 for($x = 0; $x < strlen($str); $x ++) {
422 $buffer = trim($buffer);
426 function unxmlify($s) {
427 $ret = str_replace('&','&', $s);
428 $ret = str_replace(array('<','>','"','''),array('<','>','"',"'"),$ret);
432 function hex2bin($s) {
433 return(pack("H*",$s));
437 function paginate(&$a) {
439 $stripped = ereg_replace("(&page=[0-9]*)","",$_SERVER['QUERY_STRING']);
440 $stripped = str_replace('q=','',$stripped);
441 $stripped = trim($stripped,'/');
442 $url = $a->get_baseurl() . '/' . $stripped;
445 if($a->pager['total'] > $a->pager['itemspage']) {
446 $o .= '<div class="pager">';
447 if($a->pager['page'] != 1)
448 $o .= '<span class="pager_prev">'."<a href=\"$url".'&page='.($a->pager['page'] - 1).'">' . t('prev') . '</a></span> ';
450 $o .= "<span class=\"pager_first\"><a href=\"$url"."&page=1\">" . t('first') . "</a></span> ";
452 $numpages = $a->pager['total'] / $a->pager['itemspage'];
455 $numstop = $numpages;
458 $numstart = (($pagenum > 7) ? ($pagenum - 7) : 1);
459 $numstop = (($pagenum > ($numpages - 7)) ? $numpages : ($numstart + 14));
462 for($i = $numstart; $i <= $numstop; $i++){
463 if($i == $a->pager['page'])
464 $o .= '<span class="pager_current">'.(($i < 10) ? ' '.$i : $i);
466 $o .= "<span class=\"pager_n\"><a href=\"$url"."&page=$i\">".(($i < 10) ? ' '.$i : $i)."</a>";
470 if(($a->pager['total'] % $a->pager['itemspage']) != 0) {
471 if($i == $a->pager['page'])
472 $o .= '<span class="pager_current">'.(($i < 10) ? ' '.$i : $i);
474 $o .= "<span class=\"pager_n\"><a href=\"$url"."&page=$i\">".(($i < 10) ? ' '.$i : $i)."</a>";
478 $lastpage = (($numpages > intval($numpages)) ? intval($numpages)+1 : $numpages);
479 $o .= "<span class=\"pager_last\"><a href=\"$url"."&page=$lastpage\">" . t('last') . "</a></span> ";
481 if(($a->pager['total'] - ($a->pager['itemspage'] * $a->pager['page'])) > 0)
482 $o .= '<span class="pager_next">'."<a href=\"$url"."&page=".($a->pager['page'] + 1).'">' . t('next') . '</a></span>';
483 $o .= '</div>'."\r\n";
488 function expand_acl($s) {
491 $a = explode('<',$s);
492 for($x = 0; $x < count($a); $x ++) {
493 $a[$x] = intval(str_replace(array('<','>'),array('',''),$a[$x]));