\r\n");
define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' );
define ( 'REGISTER_CLOSED', 0);
define ( 'REGISTER_APPROVE', 1);
define ( 'REGISTER_OPEN', 2);
// relationship types
define ( 'REL_VIP', 1);
define ( 'REL_FAN', 2);
define ( 'REL_BUD', 3);
define ( 'NOTIFY_INTRO', 0x0001 );
define ( 'NOTIFY_CONFIRM', 0x0002 );
define ( 'NOTIFY_WALL', 0x0004 );
define ( 'NOTIFY_COMMENT', 0x0008 );
define ( 'NOTIFY_MAIL', 0x0010 );
define ( 'NAMESPACE_DFRN' , 'http://purl.org/macgirvin/dfrn/1.0' );
define ( 'NAMESPACE_THREAD' , 'http://purl.org/syndication/thread/1.0' );
define ( 'NAMESPACE_TOMB' , 'http://purl.org/atompub/tombstones/1.0' );
define ( 'NAMESPACE_ACTIVITY', 'http://activitystrea.ms/spec/1.0/' );
define ( 'NAMESPACE_ACTIVITY_SCHEMA', 'http://activitystrea.ms/schema/1.0/');
define ( 'ACTIVITY_LIKE', NAMESPACE_ACTIVITY_SCHEMA . 'like' );
define ( 'ACTIVITY_DISLIKE', NAMESPACE_DFRN . '/dislike' );
define ( 'ACTIVITY_OBJ_HEART', NAMESPACE_DFRN . '/heart' );
define ( 'ACTIVITY_FRIEND', NAMESPACE_ACTIVITY_SCHEMA . 'make-friend' );
define ( 'ACTIVITY_POST', NAMESPACE_ACTIVITY_SCHEMA . 'post' );
define ( 'ACTIVITY_UPDATE', NAMESPACE_ACTIVITY_SCHEMA . 'update' );
define ( 'ACTIVITY_OBJ_COMMENT', NAMESPACE_ACTIVITY_SCHEMA . 'comment' );
define ( 'ACTIVITY_OBJ_NOTE', NAMESPACE_ACTIVITY_SCHEMA . 'note' );
define ( 'ACTIVITY_OBJ_PERSON', NAMESPACE_ACTIVITY_SCHEMA . 'person' );
define ( 'ACTIVITY_OBJ_PHOTO', NAMESPACE_ACTIVITY_SCHEMA . 'photo' );
define ( 'ACTIVITY_OBJ_P_PHOTO', NAMESPACE_ACTIVITY_SCHEMA . 'profile-photo' );
define ( 'ACTIVITY_OBJ_ALBUM', NAMESPACE_ACTIVITY_SCHEMA . 'photo-album' );
define ( 'GRAVITY_PARENT', 0);
define ( 'GRAVITY_LIKE', 3);
define ( 'GRAVITY_COMMENT', 6);
if(! class_exists('App')) {
class App {
public $module_loaded = false;
public $config;
public $page;
public $profile;
public $user;
public $cid;
public $contact;
public $content;
public $data;
public $error = false;
public $cmd;
public $argv;
public $argc;
public $module;
public $pager;
public $strings;
public $path;
private $scheme;
private $hostname;
private $baseurl;
private $db;
function __construct() {
$this->config = array();
$this->page = array();
$this->pager= array();
$this->scheme = ((isset($_SERVER['HTTPS'])
&& ($_SERVER['HTTPS'])) ? 'https' : 'http' );
$this->hostname = str_replace('www.','',
$_SERVER['SERVER_NAME']);
set_include_path("include/$this->hostname"
. PATH_SEPARATOR . 'include'
. PATH_SEPARATOR . '.' );
if(substr($_SERVER['QUERY_STRING'],0,2) == "q=")
$_SERVER['QUERY_STRING'] = substr($_SERVER['QUERY_STRING'],2);
$this->cmd = trim($_GET['q'],'/');
$this->argv = explode('/',$this->cmd);
$this->argc = count($this->argv);
if((array_key_exists('0',$this->argv)) && strlen($this->argv[0])) {
$this->module = $this->argv[0];
}
else {
$this->module = 'home';
}
if($this->cmd === '.well-known/host-meta')
require_once('include/hostxrd.php');
$this->pager['page'] = ((x($_GET,'page')) ? $_GET['page'] : 1);
$this->pager['itemspage'] = 50;
$this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
$this->pager['total'] = 0;
}
function get_baseurl($ssl = false) {
if(strlen($this->baseurl))
return $this->baseurl;
$this->baseurl = (($ssl) ? 'https' : $this->scheme) . "://" . $this->hostname
. ((isset($this->path) && strlen($this->path))
? '/' . $this->path : '' );
return $this->baseurl;
}
function set_baseurl($url) {
$this->baseurl = $url;
$this->hostname = basename($url);
}
function get_hostname() {
return $this->hostname;
}
function set_hostname($h) {
$this->hostname = $h;
}
function set_path($p) {
$this->path = ltrim(trim($p),'/');
}
function get_path() {
return $this->path;
}
function set_pager_total($n) {
$this->pager['total'] = intval($n);
}
function set_pager_itemspage($n) {
$this->pager['itemspage'] = intval($n);
$this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
}
function init_pagehead() {
$tpl = load_view_file("view/head.tpl");
$this->page['htmlhead'] = replace_macros($tpl,array(
'$baseurl' => $this->get_baseurl()
));
}
}}
if(! function_exists('x')) {
function x($s,$k = NULL) {
if($k != NULL) {
if((is_array($s)) && (array_key_exists($k,$s))) {
if($s[$k])
return (int) 1;
return (int) 0;
}
return false;
}
else {
if(isset($s)) {
if($s) {
return (int) 1;
}
return (int) 0;
}
return false;
}
}}
if(! function_exists('system_unavailable')) {
function system_unavailable() {
include('system_unavailable.php');
killme();
}}
if(! function_exists('check_config')) {
function check_config(&$a) {
load_config('system');
$build = get_config('system','build');
if(! x($build))
$build = set_config('system','build',BUILD_ID);
$url = get_config('system','url');
if(! x($url))
$url = set_config('system','url',$a->get_baseurl());
if($build != BUILD_ID) {
$stored = intval($build);
$current = intval(BUILD_ID);
if(($stored < $current) && file_exists('update.php')) {
// We're reporting a different version than what is currently installed.
// Run any existing update scripts to bring the database up to current.
require_once('update.php');
for($x = $stored; $x < $current; $x ++) {
if(function_exists('update_' . $x)) {
$func = 'update_' . $x;
$func($a);
}
}
set_config('system','build', BUILD_ID);
}
}
return;
}}
if(! function_exists('replace_macros')) {
function replace_macros($s,$r) {
$search = array();
$replace = array();
if(is_array($r) && count($r)) {
foreach ($r as $k => $v ) {
$search[] = $k;
$replace[] = $v;
}
}
return str_replace($search,$replace,$s);
}}
if(! function_exists('load_translation_table')) {
function load_translation_table($lang) {
global $a;
}}
if(! function_exists('t')) {
function t($s) {
global $a;
if($a->strings[$s])
return $a->strings[$s];
return $s;
}}
if(! function_exists('fetch_url')) {
function fetch_url($url,$binary = false) {
$ch = curl_init($url);
if(! $ch) return false;
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch, CURLOPT_MAXREDIRS,8);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
$prx = get_config('system','proxy');
if(strlen($prx)) {
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_PROXY, $prx);
$prxusr = get_config('system','proxyuser');
if(strlen($prxusr))
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $prxusr);
}
if($binary)
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$s = curl_exec($ch);
curl_close($ch);
return($s);
}}
if(! function_exists('post_url')) {
function post_url($url,$params) {
$ch = curl_init($url);
if(! $ch) return false;
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch, CURLOPT_MAXREDIRS,8);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
$prx = get_config('system','proxy');
if(strlen($prx)) {
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_PROXY, $prx);
$prxusr = get_config('system','proxyuser');
if(strlen($prxusr))
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $prxusr);
}
$s = curl_exec($ch);
curl_close($ch);
return($s);
}}
if(! function_exists('random_string')) {
function random_string() {
return(hash('sha256',uniqid(rand(),true)));
}}
if(! function_exists('notags')) {
function notags($string) {
// protect against :<> with high-bit set
return(str_replace(array("<",">","\xBA","\xBC","\xBE"), array('[',']','','',''), $string));
}}
if(! function_exists('escape_tags')) {
function escape_tags($string) {
return(htmlspecialchars($string));
}}
if(! function_exists('login')) {
function login($register = false) {
$o = "";
$register_html = (($register) ? load_view_file("view/register-link.tpl") : "");
if(x($_SESSION,'authenticated')) {
$o = load_view_file("view/logout.tpl");
}
else {
$o = load_view_file("view/login.tpl");
$o = replace_macros($o,array('$register_html' => $register_html ));
}
return $o;
}}
if(! function_exists('autoname')) {
function autoname($len) {
$vowels = array('a','a','ai','au','e','e','e','ee','ea','i','ie','o','ou','u');
if(mt_rand(0,5) == 4)
$vowels[] = 'y';
$cons = array(
'b','bl','br',
'c','ch','cl','cr',
'd','dr',
'f','fl','fr',
'g','gh','gl','gr',
'h',
'j',
'k','kh','kl','kr',
'l',
'm',
'n',
'p','ph','pl','pr',
'qu',
'r','rh',
's','sc','sh','sm','sp','st',
't','th','tr',
'v',
'w','wh',
'x',
'z','zh'
);
$midcons = array('ck','ct','gn','ld','lf','lm','lt','mb','mm', 'mn','mp',
'nd','ng','nk','nt','rn','rp','rt');
$noend = array('bl', 'br', 'cl','cr','dr','fl','fr','gl','gr',
'kh', 'kl','kr','mn','pl','pr','rh','tr','qu','wh');
$start = mt_rand(0,2);
if($start == 0)
$table = $vowels;
else
$table = $cons;
$word = '';
for ($x = 0; $x < $len; $x ++) {
$r = mt_rand(0,count($table) - 1);
$word .= $table[$r];
if($table == $vowels)
$table = array_merge($cons,$midcons);
else
$table = $vowels;
}
$word = substr($word,0,$len);
foreach($noend as $noe) {
if((strlen($word) > 2) && (substr($word,-2) == $noe)) {
$word = substr($word,0,-1);
break;
}
}
if(substr($word,-1) == 'q')
$word = substr($word,0,-1);
return $word;
}}
if(! function_exists('killme')) {
function killme() {
session_write_close();
exit;
}}
if(! function_exists('goaway')) {
function goaway($s) {
header("Location: $s");
killme();
}}
if(! function_exists('xml_status')) {
function xml_status($st) {
header( "Content-type: text/xml" );
echo ''."\r\n";
echo "