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;
36 public $error = false;
50 function __construct() {
52 $this->config = array();
53 $this->page = array();
54 $this->pager= array();
56 $this->scheme = ((isset($_SERVER['HTTPS'])
57 && ($_SERVER['HTTPS'])) ? 'https' : 'http' );
58 $this->hostname = str_replace('www.','',
59 $_SERVER['SERVER_NAME']);
60 set_include_path("include/$this->hostname"
61 . PATH_SEPARATOR . 'include'
62 . PATH_SEPARATOR . '.' );
64 if(substr($_SERVER['QUERY_STRING'],0,2) == "q=")
65 $_SERVER['QUERY_STRING'] = substr($_SERVER['QUERY_STRING'],2);
66 $this->cmd = trim($_GET['q'],'/');
69 $this->argv = explode('/',$this->cmd);
70 $this->argc = count($this->argv);
71 if((array_key_exists('0',$this->argv)) && strlen($this->argv[0])) {
72 $this->module = $this->argv[0];
75 $this->module = 'home';
78 if($this->cmd == '.well-known/host-meta')
79 require_once('include/hostxrd.php');
81 $this->pager['page'] = ((x($_GET,'page')) ? $_GET['page'] : 1);
82 $this->pager['itemspage'] = 50;
83 $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
84 $this->pager['total'] = 0;
87 function get_baseurl($ssl = false) {
88 if(strlen($this->baseurl))
89 return $this->baseurl;
91 $this->baseurl = (($ssl) ? 'https' : $this->scheme) . "://" . $this->hostname
92 . ((isset($this->path) && strlen($this->path))
93 ? '/' . $this->path : '' );
94 return $this->baseurl;
97 function set_baseurl($url) {
98 $this->baseurl = $url;
101 function get_hostname() {
102 return $this->hostname;
105 function set_hostname($h) {
106 $this->hostname = $h;
109 function set_path($p) {
110 $this->path = ltrim(trim($p),'/');
113 function get_path() {
117 function set_pager_total($n) {
118 $this->pager['total'] = intval($n);
121 function set_pager_itemspage($n) {
122 $this->pager['itemspage'] = intval($n);
123 $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
127 function init_pagehead() {
128 if(file_exists("view/head.tpl"))
129 $s = file_get_contents("view/head.tpl");
130 $this->page['htmlhead'] = replace_macros($s,array('$baseurl' => $this->get_baseurl()));
136 if(! function_exists('x')) {
137 function x($s,$k = NULL) {
139 if((is_array($s)) && (array_key_exists($k,$s))) {
157 if(! function_exists('system_unavailable')) {
158 function system_unavailable() {
159 include('system_unavailable.php');
163 if(! function_exists('replace_macros')) {
164 function replace_macros($s,$r) {
169 if(is_array($r) && count($r)) {
170 foreach ($r as $k => $v ) {
175 return str_replace($search,$replace,$s);
179 function load_translation_table($lang) {
189 return $a->strings[$s];
193 if(! function_exists('fetch_url')) {
194 function fetch_url($url,$binary = false) {
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);
203 curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
211 if(! function_exists('post_url')) {
212 function post_url($url,$params) {
213 $ch = curl_init($url);
214 if(! $ch) return false;
216 curl_setopt($ch, CURLOPT_HEADER, 0);
217 curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
218 curl_setopt($ch, CURLOPT_MAXREDIRS,8);
219 curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
220 curl_setopt($ch, CURLOPT_POST,1);
221 curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
229 if(! function_exists('random_string')) {
230 function random_string() {
231 return(hash('sha256',uniqid(rand(),true)));
234 if(! function_exists('notags')) {
235 function notags($string) {
236 // protect against :<> with high-bit set
237 return(str_replace(array("<",">","\xBA","\xBC","\xBE"), array('[',']','','',''), $string));
240 if(! function_exists('escape_tags')) {
241 function escape_tags($string) {
243 return(htmlspecialchars($string));
246 if(! function_exists('login')) {
247 function login($register = false) {
249 $register_html = (($register) ? file_get_contents("view/register-link.tpl") : "");
252 if(x($_SESSION,'authenticated')) {
253 $o = file_get_contents("view/logout.tpl");
256 $o = file_get_contents("view/login.tpl");
258 $o = replace_macros($o,array('$register_html' => $register_html ));
264 if(! function_exists('autoname')) {
265 function autoname($len) {
267 $vowels = array('a','a','ai','au','e','e','e','ee','ea','i','ie','o','ou','u');
268 if(mt_rand(0,5) == 4)
286 's','sc','sh','sm','sp','st',
294 $midcons = array('ck','ct','gn','ld','lf','lm','lt','mb','mm', 'mn','mp',
295 'nd','ng','nk','nt','rn','rp','rt');
297 $noend = array('bl', 'br', 'cl','cr','dr','fl','fr','gl','gr',
298 'kh', 'kl','kr','mn','pl','pr','rh','tr','qu','wh');
300 $start = mt_rand(0,2);
308 for ($x = 0; $x < $len; $x ++) {
309 $r = mt_rand(0,count($table) - 1);
312 if($table == $vowels)
313 $table = array_merge($cons,$midcons);
319 $word = substr($word,0,$len);
321 foreach($noend as $noe) {
322 if((strlen($word) > 2) && (substr($word,-2) == $noe)) {
323 $word = substr($word,0,-1);
327 if(substr($word,-1) == 'q')
328 $word = substr($word,0,-1);
332 if(! function_exists('killme')) {
334 session_write_close();
338 if(! function_exists('goaway')) {
339 function goaway($s) {
340 header("Location: $s");
345 if(! function_exists('xml_status')) {
346 function xml_status($st) {
347 header( "Content-type: text/xml" );
348 echo '<?xml version="1.0" encoding="UTF-8"?>'."\r\n";
349 echo "<result><status>$st</status></result>\r\n";
353 if(! function_exists('local_user')) {
354 function local_user() {
355 if((x($_SESSION,'authenticated')) && (x($_SESSION,'uid')))
356 return $_SESSION['uid'];
360 if(! function_exists('remote_user')) {
361 function remote_user() {
362 if((x($_SESSION,'authenticated')) && (x($_SESSION,'visitor_id')))
363 return $_SESSION['visitor_id'];
367 function footer(&$a) {
369 $s = fetch_url("http://fortunemod.com/cookie.php?equal=1");
370 $a->page['content'] .= "<div class=\"fortune\" >$s</div>";
373 if(! function_exists('notice')) {
374 function notice($s) {
376 $_SESSION['sysmsg'] .= $s;
380 if(! function_exists('get_max_import_size')) {
381 function get_max_import_size() {
383 return ((x($a->config,'max_import_size')) ? $a->config['max_import_size'] : 0 );
386 if(! function_exists('xmlify')) {
387 function xmlify($str) {
390 for($x = 0; $x < strlen($str); $x ++) {
421 $buffer = trim($buffer);
425 function unxmlify($s) {
426 $ret = str_replace('&','&', $s);
427 $ret = str_replace(array('<','>','"','''),array('<','>','"',"'"),$ret);
431 function hex2bin($s) {
432 return(pack("H*",$s));
436 function paginate(&$a) {
438 $stripped = ereg_replace("(&page=[0-9]*)","",$_SERVER['QUERY_STRING']);
439 $stripped = str_replace('q=','',$stripped);
440 $stripped = trim($stripped,'/');
441 $url = $a->get_baseurl() . '/' . $stripped;
444 if($a->pager['total'] > $a->pager['itemspage']) {
445 $o .= '<div class="pager">';
446 if($a->pager['page'] != 1)
447 $o .= '<span class="pager_prev">'."<a href=\"$url".'&page='.($a->pager['page'] - 1).'">' . t('prev') . '</a></span> ';
449 $o .= "<span class=\"pager_first\"><a href=\"$url"."&page=1\">" . t('first') . "</a></span> ";
451 $numpages = $a->pager['total'] / $a->pager['itemspage'];
454 $numstop = $numpages;
457 $numstart = (($pagenum > 7) ? ($pagenum - 7) : 1);
458 $numstop = (($pagenum > ($numpages - 7)) ? $numpages : ($numstart + 14));
461 for($i = $numstart; $i <= $numstop; $i++){
462 if($i == $a->pager['page'])
463 $o .= '<span class="pager_current">'.(($i < 10) ? ' '.$i : $i);
465 $o .= "<span class=\"pager_n\"><a href=\"$url"."&page=$i\">".(($i < 10) ? ' '.$i : $i)."</a>";
469 if(($a->pager['total'] % $a->pager['itemspage']) != 0) {
470 if($i == $a->pager['page'])
471 $o .= '<span class="pager_current">'.(($i < 10) ? ' '.$i : $i);
473 $o .= "<span class=\"pager_n\"><a href=\"$url"."&page=$i\">".(($i < 10) ? ' '.$i : $i)."</a>";
477 $lastpage = (($numpages > intval($numpages)) ? intval($numpages)+1 : $numpages);
478 $o .= "<span class=\"pager_last\"><a href=\"$url"."&page=$lastpage\">" . t('last') . "</a></span> ";
480 if(($a->pager['total'] - ($a->pager['itemspage'] * $a->pager['page'])) > 0)
481 $o .= '<span class="pager_next">'."<a href=\"$url"."&page=".($a->pager['page'] + 1).'">' . t('next') . '</a></span>';
482 $o .= '</div>'."\r\n";
487 function expand_acl($s) {
490 $a = explode('<',$s);
491 for($x = 0; $x < count($a); $x ++) {
492 $a[$x] = intval(str_replace(array('<','>'),array('',''),$a[$x]));