Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2275 lines
61 KiB

12 years ago
<?php
set_time_limit(0);
11 years ago
define ( 'BUILD_ID', 1034 );
define ( 'FRIENDIKA_VERSION', '2.10.0902' );
11 years ago
define ( 'DFRN_PROTOCOL_VERSION', '2.0' );
12 years ago
11 years ago
define ( 'EOL', "<br />\r\n" );
define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' );
define ( 'DOWN_ARROW', '&#x21e9;' );
/**
* SSL redirection policies
*/
define ( 'SSL_POLICY_NONE', 0 );
define ( 'SSL_POLICY_FULL', 1 );
define ( 'SSL_POLICY_SELFSIGN', 2 );
/**
* log levels
*/
define ( 'LOGGER_NORMAL', 0 );
define ( 'LOGGER_TRACE', 1 );
define ( 'LOGGER_DEBUG', 2 );
define ( 'LOGGER_DATA', 3 );
define ( 'LOGGER_ALL', 4 );
/**
* registration policies
*/
11 years ago
define ( 'REGISTER_CLOSED', 0 );
define ( 'REGISTER_APPROVE', 1 );
define ( 'REGISTER_OPEN', 2 );
12 years ago
/**
* relationship types
*/
12 years ago
11 years ago
define ( 'REL_VIP', 1);
define ( 'REL_FAN', 2);
define ( 'REL_BUD', 3);
/**
* Hook array order
*/
define ( 'HOOK_HOOK', 0);
define ( 'HOOK_FILE', 1);
define ( 'HOOK_FUNCTION', 2);
/**
*
* page/profile types
*
* PAGE_NORMAL is a typical personal profile account
* PAGE_SOAPBOX automatically approves all friend requests as REL_FAN, (readonly)
* PAGE_COMMUNITY automatically approves all friend requests as REL_FAN, but with
* write access to wall and comments (no email and not included in page owner's ACL lists)
* PAGE_FREELOVE automatically approves all friend requests as full friends (REL_BUD).
*
*/
define ( 'PAGE_NORMAL', 0 );
define ( 'PAGE_SOAPBOX', 1 );
define ( 'PAGE_COMMUNITY', 2 );
define ( 'PAGE_FREELOVE', 3 );
/**
* Maximum number of "people who like (or don't like) this" that we will list by name
*/
11 years ago
define ( 'MAX_LIKERS', 75);
/**
* email notification options
*/
11 years ago
define ( 'NOTIFY_INTRO', 0x0001 );
define ( 'NOTIFY_CONFIRM', 0x0002 );
define ( 'NOTIFY_WALL', 0x0004 );
define ( 'NOTIFY_COMMENT', 0x0008 );
define ( 'NOTIFY_MAIL', 0x0010 );
/**
* various namespaces we may need to parse
*/
11 years ago
11 years ago
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 ( 'NAMESPACE_MEDIA', 'http://purl.org/syndication/atommedia' );
define ( 'NAMESPACE_SALMON_ME', 'http://salmon-protocol.org/ns/magic-env' );
define ( 'NAMESPACE_OSTATUSSUB', 'http://ostatus.org/schema/1.0/subscribe' );
define ( 'NAMESPACE_GEORSS', 'http://www.georss.org/georss' );
define ( 'NAMESPACE_POCO', 'http://portablecontacts.net/spec/1.0' );
define ( 'NAMESPACE_FEED', 'http://schemas.google.com/g/2010#updates-from' );
11 years ago
/**
* activity stream defines
*/
11 years ago
define ( 'ACTIVITY_LIKE', NAMESPACE_ACTIVITY_SCHEMA . 'like' );
11 years ago
define ( 'ACTIVITY_DISLIKE', NAMESPACE_DFRN . '/dislike' );
11 years ago
define ( 'ACTIVITY_OBJ_HEART', NAMESPACE_DFRN . '/heart' );
define ( 'ACTIVITY_FRIEND', NAMESPACE_ACTIVITY_SCHEMA . 'make-friend' );
define ( 'ACTIVITY_FOLLOW', NAMESPACE_ACTIVITY_SCHEMA . 'follow' );
define ( 'ACTIVITY_UNFOLLOW', NAMESPACE_ACTIVITY_SCHEMA . 'stop-following' );
define ( 'ACTIVITY_POST', NAMESPACE_ACTIVITY_SCHEMA . 'post' );
define ( 'ACTIVITY_UPDATE', NAMESPACE_ACTIVITY_SCHEMA . 'update' );
define ( 'ACTIVITY_TAG', NAMESPACE_ACTIVITY_SCHEMA . 'tag' );
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' );
/**
* item weight for query ordering
*/
11 years ago
define ( 'GRAVITY_PARENT', 0);
define ( 'GRAVITY_LIKE', 3);
define ( 'GRAVITY_COMMENT', 6);
/**
*
* Reverse the effect of magic_quotes_gpc if it is enabled.
* Please disable magic_quotes_gpc so we don't have to do this.
* See http://php.net/manual/en/security.magicquotes.disabling.php
*
*/
if (get_magic_quotes_gpc()) {
$process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
while (list($key, $val) = each($process)) {
foreach ($val as $k => $v) {
unset($process[$key][$k]);
if (is_array($v)) {
$process[$key][stripslashes($k)] = $v;
$process[] = &$process[$key][stripslashes($k)];
} else {
$process[$key][stripslashes($k)] = stripslashes($v);
}
}
}
unset($process);
}
/**
*
* class: App
*
* Our main application structure for the life of this page
* Primarily deals with the URL that got us here
* and tries to make some sense of it, and
* stores our page contents and config storage
* and anything else that might need to be passed around
* before we spit the page out.
*
*/
11 years ago
12 years ago
if(! class_exists('App')) {
class App {
public $module_loaded = false;
public $query_string;
12 years ago
public $config;
public $page;
public $profile;
public $user;
public $cid;
public $contact;
12 years ago
public $content;
public $data;
12 years ago
public $error = false;
public $cmd;
public $argv;
public $argc;
public $module;
12 years ago
public $pager;
12 years ago
public $strings;
public $path;
11 years ago
public $hooks;
public $timezone;
public $interactive = true;
11 years ago
12 years ago
private $scheme;
private $hostname;
private $baseurl;
12 years ago
private $db;
private $curl_code;
private $curl_headers;
12 years ago
function __construct() {
$this->config = array();
$this->page = array();
12 years ago
$this->pager= array();
12 years ago
$this->query_string = '';
$this->scheme = ((isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'])) ? 'https' : 'http' );
11 years ago
if(x($_SERVER,'SERVER_NAME'))
$this->hostname = $_SERVER['SERVER_NAME'];
set_include_path("include/$this->hostname" . PATH_SEPARATOR . 'include' . PATH_SEPARATOR . '.' );
if((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,2) === "q=")
$this->query_string = substr($_SERVER['QUERY_STRING'],2);
11 years ago
if(x($_GET,'q'))
$this->cmd = trim($_GET['q'],'/\\');
12 years ago
/**
* Figure out if we are running at the top of a domain
* or in a sub-directory and adjust accordingly
*/
$path = trim(dirname($_SERVER['SCRIPT_NAME']),'/\\');
if(isset($path) && strlen($path) && ($path != $this->path))
$this->path = $path;
12 years ago
/**
*
* Break the URL path into C style argc/argv style arguments for our
* modules. Given "http://example.com/module/arg1/arg2", $this->argc
* will be 3 (integer) and $this->argv will contain:
* [0] => 'module'
* [1] => 'arg1'
* [2] => 'arg2'
*
*
* There will always be one argument. If provided a naked domain
* URL, $this->argv[0] is set to "home".
*
*/
12 years ago
$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';
}
/**
* Special handling for the webfinger/lrdd host XRD file
* Just spit out the contents and exit.
*/
if($this->cmd === '.well-known/host-meta')
require_once('include/hostxrd.php');
/**
* See if there is any page number information, and initialise
* pagination
*/
12 years ago
$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;
12 years ago
}
function get_baseurl($ssl = false) {
$scheme = $this->scheme;
if(x($this->config,'ssl_policy')) {
if(($ssl) || ($this->config['ssl_policy'] == SSL_POLICY_FULL))
$scheme = 'https';
if(($this->config['ssl_policy'] == SSL_POLICY_SELFSIGN) && (local_user() || x($_POST,'auth-params')))
$scheme = 'https';
}
$this->baseurl = $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);
12 years ago
}
function get_hostname() {
return $this->hostname;
}
function set_hostname($h) {
$this->hostname = $h;
}
12 years ago
function set_path($p) {
$this->path = trim(trim($p),'/');
12 years ago
}
function get_path() {
return $this->path;
}
12 years ago
function set_pager_total($n) {
$this->pager['total'] = intval($n);
}
12 years ago
function set_pager_itemspage($n) {
$this->pager['itemspage'] = intval($n);
$this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
}
12 years ago
function init_pagehead() {
$this->page['title'] = $this->config['sitename'];
$tpl = load_view_file("view/head.tpl");
$this->page['htmlhead'] = replace_macros($tpl,array(
'$baseurl' => $this->get_baseurl() . '/',
'$generator' => 'Friendika' . ' ' . FRIENDIKA_VERSION
));
12 years ago
}
function set_curl_code($code) {
$this->curl_code = $code;
}
function get_curl_code() {
return $this->curl_code;
}
function set_curl_headers($headers) {
$this->curl_headers = $headers;
}
function get_curl_headers() {
return $this->curl_headers;
}
12 years ago
}}
// retrieve the App structure
// useful in functions which require it but don't get it passed to them
if(! function_exists('get_app')) {
function get_app() {
global $a;
return $a;
}};
12 years ago
11 years ago
// Multi-purpose function to check variable state.
// Usage: x($var) or $x($array,'key')
// returns false if variable/key is not set
// if variable is set, returns 1 if has 'non-zero' value, otherwise returns 0.
// e.g. x('') or x(0) returns 0;
12 years ago
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;
}
}}
11 years ago
// called from db initialisation if db is dead.
12 years ago
if(! function_exists('system_unavailable')) {
function system_unavailable() {
include('system_unavailable.php');
killme();
}}
11 years ago
// Primarily involved with database upgrade, but also sets the
// base url for use in cmdline programs which don't have
// $_SERVER variables, and synchronising the state of installed plugins.
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');
11 years ago
for($x = $stored; $x < $current; $x ++) {
if(function_exists('update_' . $x)) {
$func = 'update_' . $x;
$func($a);
}
}
set_config('system','build', BUILD_ID);
}
}
/**
*
* Synchronise plugins:
*
* $a->config['system']['addon'] contains a comma-separated list of names
* of plugins/addons which are used on this system.
* Go through the database list of already installed addons, and if we have
* an entry, but it isn't in the config list, call the uninstall procedure
* and mark it uninstalled in the database (for now we'll remove it).
* Then go through the config list and if we have a plugin that isn't installed,
* call the install procedure and add it to the database.
*
*/
$r = q("SELECT * FROM `addon` WHERE `installed` = 1");
if(count($r))
$installed = $r;
else
$installed = array();
$plugins = get_config('system','addon');
$plugins_arr = array();
if($plugins)
$plugins_arr = explode(',',str_replace(' ', '',$plugins));
$installed_arr = array();
if(count($installed)) {
foreach($installed as $i) {
if(! in_array($i['name'],$plugins_arr)) {
logger("Addons: uninstalling " . $i['name']);
q("DELETE FROM `addon` WHERE `id` = %d LIMIT 1",
intval($i['id'])
);
@include_once('addon/' . $i['name'] . '/' . $i['name'] . '.php');
if(function_exists($i['name'] . '_uninstall')) {
$func = $i['name'] . '_uninstall';
$func();
}
}
else
$installed_arr[] = $i['name'];
}
}
if(count($plugins_arr)) {
foreach($plugins_arr as $p) {
if(! in_array($p,$installed_arr)) {
logger("Addons: installing " . $p);
@include_once('addon/' . $p . '/' . $p . '.php');
if(function_exists($p . '_install')) {
$func = $p . '_install';
$func();
$r = q("INSERT INTO `addon` (`name`, `installed`) VALUES ( '%s', 1 ) ",
dbesc($p)
);
}
}
}
}
return;
}}
11 years ago
// This is our template processor.
// $s is the string requiring macro substitution.
// $r is an array of key value pairs (search => replace)
// returns substituted string.
// WARNING: this is pretty basic, and doesn't properly handle search strings that are substrings of each other.
// For instance if 'test' => "foo" and 'testing' => "bar", testing could become either bar or fooing,
// depending on the order in which they were declared in the array.
12 years ago
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);
}}
11 years ago
// load string translation table for alternate language
11 years ago
if(! function_exists('load_translation_table')) {
12 years ago
function load_translation_table($lang) {
global $a;
if(file_exists("view/$lang/strings.php"))
include("view/$lang/strings.php");
}}
12 years ago
11 years ago
// translate string if translation exists
if(! function_exists('t')) {
12 years ago
function t($s) {
11 years ago
$a = get_app();
12 years ago
11 years ago
if(x($a->strings,$s))
12 years ago
return $a->strings[$s];
return $s;
}}
12 years ago
11 years ago
// curl wrapper. If binary flag is true, return binary
// results.
12 years ago
if(! function_exists('fetch_url')) {
function fetch_url($url,$binary = false, &$redirects = 0) {
11 years ago
$a = get_app();
12 years ago
$ch = curl_init($url);
if(($redirects > 8) || (! $ch))
return false;
12 years ago
curl_setopt($ch, CURLOPT_HEADER, true);
12 years ago
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
$curl_time = intval(get_config('system','curl_timeout'));
curl_setopt($ch, CURLOPT_TIMEOUT, (($curl_time !== false) ? $curl_time : 60));
// by default we will allow self-signed certs
// but you can override this
$check_cert = get_config('system','verifyssl');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, (($check_cert) ? true : false));
$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);
}
12 years ago
if($binary)
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$a->set_curl_code(0);
// don't let curl abort the entire application
// if it throws any errors.
$s = @curl_exec($ch);
$http_code = intval(curl_getinfo($ch, CURLINFO_HTTP_CODE));
$header = substr($s,0,strpos($s,"\r\n\r\n"));
if(stristr($header,'100') && (strlen($header) < 30)) {
// 100 Continue has two headers, get the real one
$s = substr($s,strlen($header)+4);
$header = substr($s,0,strpos($s,"\r\n\r\n"));
}
if($http_code == 301 || $http_code == 302 || $http_code == 303) {
$matches = array();
preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches);
$url = trim(array_pop($matches));
$url_parsed = parse_url($url);
if (isset($url_parsed)) {
$redirects++;
return fetch_url($url,$binary,$redirects);
}
}
$a->set_curl_code($http_code);
$body = substr($s,strlen($header)+4);
$a->set_curl_headers($header);
12 years ago
curl_close($ch);
return($body);
12 years ago
}}
11 years ago
// post request to $url. $params is an array of post variables.
12 years ago
if(! function_exists('post_url')) {
function post_url($url,$params, $headers = null, &$redirects = 0) {
11 years ago
$a = get_app();
12 years ago
$ch = curl_init($url);
if(($redirects > 8) || (! $ch))
return false;
12 years ago
curl_setopt($ch, CURLOPT_HEADER, true);
12 years ago
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
$curl_time = intval(get_config('system','curl_timeout'));
curl_setopt($ch, CURLOPT_TIMEOUT, (($curl_time !== false) ? $curl_time : 60));
if(is_array($headers))
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$check_cert = get_config('system','verifyssl');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, (($check_cert) ? true : false));
$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);
}
12 years ago
$a->set_curl_code(0);
// don't let curl abort the entire application
// if it throws any errors.
$s = @curl_exec($ch);
$http_code = intval(curl_getinfo($ch, CURLINFO_HTTP_CODE));
$header = substr($s,0,strpos($s,"\r\n\r\n"));
if(stristr($header,'100') && (strlen($header) < 30)) {
// 100 Continue has two headers, get the real one
$s = substr($s,strlen($header)+4);
$header = substr($s,0,strpos($s,"\r\n\r\n"));
}
if($http_code == 301 || $http_code == 302 || $http_code == 303) {
$matches = array();
preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches);
$url = trim(array_pop($matches));
$url_parsed = parse_url($url);
if (isset($url_parsed)) {
$redirects++;
return post_url($url,$binary,$headers,$redirects);
}
}
$a->set_curl_code($http_code);
$body = substr($s,strlen($header)+4);
$a->set_curl_headers($header);
12 years ago
curl_close($ch);
return($body);
12 years ago
}}
11 years ago
// random hash, 64 chars
12 years ago
if(! function_exists('random_string')) {
function random_string() {
return(hash('sha256',uniqid(rand(),true)));
}}
/**
* This is our primary input filter.
*
* The high bit hack only involved some old IE browser, forget which (IE5/Mac?)
* that had an XSS attack vector due to stripping the high-bit on an 8-bit character
* after cleansing, and angle chars with the high bit set could get through as markup.
*
* This is now disabled because it was interfering with some legitimate unicode sequences
* and hopefully there aren't a lot of those browsers left.
*
* Use this on any text input where angle chars are not valid or permitted
* They will be replaced with safer brackets. This may be filtered further
* if these are not allowed either.
*
*/
11 years ago
12 years ago
if(! function_exists('notags')) {
function notags($string) {
return(str_replace(array("<",">"), array('[',']'), $string));
// High-bit filter no longer used
// return(str_replace(array("<",">","\xBA","\xBC","\xBE"), array('[',']','','',''), $string));
12 years ago
}}
11 years ago
// use this on "body" or "content" input where angle chars shouldn't be removed,
// and allow them to be safely displayed.
12 years ago
if(! function_exists('escape_tags')) {
function escape_tags($string) {
12 years ago
return(htmlspecialchars($string));
12 years ago
}}
11 years ago
// wrapper for adding a login box. If $register == true provide a registration
// link. This will most always depend on the value of $a->config['register_policy'].
11 years ago
// returns the complete html for inserting into the page
11 years ago
12 years ago
if(! function_exists('login')) {
function login($register = false) {
$o = "";
$register_html = (($register) ? load_view_file("view/register-link.tpl") : "");
12 years ago
$noid = get_config('system','no_openid');
if($noid) {
$classname = 'no-openid';
$namelabel = t('Nickname or Email address: ');
$passlabel = t('Password: ');
$login = t('Login');
}
else {
$classname = 'openid';
$namelabel = t('Nickname/Email/OpenID: ');
$passlabel = t("Password \x28if not OpenID\x29: ");
$login = t('Login');
}
$lostpass = t('Forgot your password?');
$lostlink = t('Password Reset');
12 years ago
if(x($_SESSION,'authenticated')) {
$tpl = load_view_file("view/logout.tpl");
12 years ago
}
else {
$tpl = load_view_file("view/login.tpl");
12 years ago
}
$o = replace_macros($tpl,array(
'$register_html' => $register_html,
'$classname' => $classname,
'$namelabel' => $namelabel,
'$passlabel' => $passlabel,
'$login' => $login,
'$lostpass' => $lostpass,
'$lostlink' => $lostlink
));
12 years ago
return $o;
}}
11 years ago
// generate a string that's random, but usually pronounceable.
// used to generate initial passwords
12 years ago
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;
}}
11 years ago
// Used to end the current process, after saving session state.
12 years ago
if(! function_exists('killme')) {
function killme() {
session_write_close();
exit;
}}
11 years ago
// redirect to another URL and terminate this process.
12 years ago
if(! function_exists('goaway')) {
function goaway($s) {
header("Location: $s");
killme();
}}
11 years ago
// Generic XML return
// Outputs a basic dfrn XML status structure to STDOUT, with a <status> variable
// of $st and an optional text <message> of $message and terminates the current process.
12 years ago
if(! function_exists('xml_status')) {
function xml_status($st, $message = '') {
11 years ago
$xml_message = ((strlen($message)) ? "\t<message>" . xmlify($message) . "</message>\r\n" : '');
if($st)
logger('xml_status returning non_zero: ' . $st . " message=" . $message);
header( "Content-type: text/xml" );
12 years ago
echo '<?xml version="1.0" encoding="UTF-8"?>'."\r\n";
echo "<result>\r\n\t<status>$st</status>\r\n$xml_message</result>\r\n";
12 years ago
killme();
}}
11 years ago
// Returns the uid of locally logged in user or false.
11 years ago
12 years ago
if(! function_exists('local_user')) {
function local_user() {
if((x($_SESSION,'authenticated')) && (x($_SESSION,'uid')))
return intval($_SESSION['uid']);
12 years ago
return false;
}}
11 years ago
// Returns contact id of authenticated site visitor or false
12 years ago
if(! function_exists('remote_user')) {
function remote_user() {
if((x($_SESSION,'authenticated')) && (x($_SESSION,'visitor_id')))
return intval($_SESSION['visitor_id']);
12 years ago
return false;
}}
11 years ago
// contents of $s are displayed prominently on the page the next time
// a page is loaded. Usually used for errors or alerts.
if(! function_exists('notice')) {
function notice($s) {
$a = get_app();
if($a->interactive)
$_SESSION['sysmsg'] .= $s;
}}
11 years ago
// wrapper around config to limit the text length of an incoming message
if(! function_exists('get_max_import_size')) {
function get_max_import_size() {
global $a;
return ((x($a->config,'max_import_size')) ? $a->config['max_import_size'] : 0 );