boot.php - code cleanup + doxygen

This commit is contained in:
rabuzarus 2015-12-24 01:31:17 +01:00
parent 7faa111c9b
commit 40b0d383d5

243
boot.php
View file

@ -1,4 +1,21 @@
<?php <?php
/** @file boot.php
*
* This file defines some global constants and includes the central App class.
*/
/**
* Friendica
*
* Friendica is a communications platform for integrated social communications
* utilising decentralised communications and linkage to several indie social
* projects - as well as popular mainstream providers.
*
* Our mission is to free our friends and families from the clutches of
* data-harvesting corporations, and pave the way to a future where social
* communications are free and open and flow between alternate providers as
* easily as email does today.
*/
require_once('include/config.php'); require_once('include/config.php');
require_once('include/network.php'); require_once('include/network.php');
@ -358,7 +375,8 @@ function startup() {
* *
* class: App * class: App
* *
* Our main application structure for the life of this page * @brief Our main application structure for the life of this page.
*
* Primarily deals with the URL that got us here * Primarily deals with the URL that got us here
* and tries to make some sense of it, and * and tries to make some sense of it, and
* stores our page contents and config storage * stores our page contents and config storage
@ -366,8 +384,6 @@ function startup() {
* before we spit the page out. * before we spit the page out.
* *
*/ */
if(! class_exists('App')) {
class App { class App {
public $module_loaded = false; public $module_loaded = false;
@ -417,10 +433,12 @@ if(! class_exists('App')) {
public $theme_thread_allow = true; public $theme_thread_allow = true;
public $theme_events_in_profile = true; public $theme_events_in_profile = true;
// An array for all theme-controllable parameters /**
// Mostly unimplemented yet. Only options 'stylesheet' and * @brief An array for all theme-controllable parameters
// beyond are used. *
* Mostly unimplemented yet. Only options 'template_engine' and
* beyond are used.
*/
public $theme = array( public $theme = array(
'sourcename' => '', 'sourcename' => '',
'videowidth' => 425, 'videowidth' => 425,
@ -431,9 +449,13 @@ if(! class_exists('App')) {
'template_engine' => 'smarty3', 'template_engine' => 'smarty3',
); );
// array of registered template engines ('name'=>'class name') /**
* @brief An array of registered template engines ('name'=>'class name')
*/
public $template_engines = array(); public $template_engines = array();
// array of instanced template engines ('name'=>'instance') /**
* @brief An array of instanced template engines ('name'=>'instance')
*/
public $template_engine_instance = array(); public $template_engine_instance = array();
private $ldelim = array( private $ldelim = array(
@ -457,6 +479,9 @@ if(! class_exists('App')) {
private $cached_profile_image; private $cached_profile_image;
private $cached_profile_picdate; private $cached_profile_picdate;
/**
* App constructor.
*/
function __construct() { function __construct() {
global $default_timezone; global $default_timezone;
@ -851,8 +876,10 @@ if(! class_exists('App')) {
/** /**
* register template engine class * @brief Register template engine class
* if $name is "", is used class static property $class::$name *
* If $name is "", is used class static property $class::$name
*
* @param string $class * @param string $class
* @param string $name * @param string $name
*/ */
@ -869,8 +896,10 @@ if(! class_exists('App')) {
} }
/** /**
* return template engine instance. If $name is not defined, * @brief Return template engine instance.
* return engine defined by theme, or default *
* If $name is not defined, return engine defined by theme,
* or default
* *
* @param strin $name Template engine name * @param strin $name Template engine name
* @return object Template Engine instance * @return object Template Engine instance
@ -899,6 +928,11 @@ if(! class_exists('App')) {
echo "template engine <tt>$template_engine</tt> is not registered!\n"; killme(); echo "template engine <tt>$template_engine</tt> is not registered!\n"; killme();
} }
/**
* @brief Returns the active template engine.
*
* @return string
*/
function get_template_engine() { function get_template_engine() {
return $this->theme['template_engine']; return $this->theme['template_engine'];
} }
@ -948,26 +982,32 @@ if(! class_exists('App')) {
} }
} }
}
// retrieve the App structure /**
// useful in functions which require it but don't get it passed to them * @brief Retrieve the App structure
*
if(! function_exists('get_app')) { * Useful in functions which require it but don't get it passed to them
*/
function get_app() { function get_app() {
global $a; global $a;
return $a; return $a;
} }
};
// Multi-purpose function to check variable state. /**
// Usage: x($var) or $x($array,'key') * @brief Multi-purpose function to check variable state.
// returns false if variable/key is not set *
// if variable is set, returns 1 if has 'non-zero' value, otherwise returns 0. * Usage: x($var) or $x($array, 'key')
// e.g. x('') or x(0) returns 0; *
* returns false if variable/key is not set
if(! function_exists('x')) { * if variable is set, returns 1 if has 'non-zero' value, otherwise returns 0.
* e.g. x('') or x(0) returns 0;
*
* @param string|array $s variable to check
* @param string $k key inside the array to check
*
* @return bool|int
*/
function x($s,$k = NULL) { function x($s,$k = NULL) {
if($k != NULL) { if($k != NULL) {
if((is_array($s)) && (array_key_exists($k,$s))) { if((is_array($s)) && (array_key_exists($k,$s))) {
@ -987,18 +1027,16 @@ if(! function_exists('x')) {
return false; return false;
} }
} }
}
// called from db initialisation if db is dead.
if(! function_exists('system_unavailable')) { /**
* @brief Called from db initialisation if db is dead.
*/
function system_unavailable() { function system_unavailable() {
include('system_unavailable.php'); include('system_unavailable.php');
system_down(); system_down();
killme(); killme();
} }
}
function clean_urls() { function clean_urls() {
@ -1016,17 +1054,36 @@ function z_path() {
return $base; return $base;
} }
/**
* @brief Returns the baseurl.
*
* @see App::get_baseurl()
*
* @return string
*/
function z_root() { function z_root() {
global $a; global $a;
return $a->get_baseurl(); return $a->get_baseurl();
} }
/**
* @brief Return absolut URL for given $path.
*
* @param string $path
*
* @return string
*/
function absurl($path) { function absurl($path) {
if(strpos($path,'/') === 0) if(strpos($path,'/') === 0)
return z_path() . $path; return z_path() . $path;
return $path; return $path;
} }
/**
* @brief Function to check if request was an AJAX (xmlhttprequest) request.
*
* @return boolean
*/
function is_ajax() { function is_ajax() {
return (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'); return (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
} }
@ -1044,12 +1101,10 @@ function check_db() {
} }
/**
* Sets the base url for use in cmdline programs which don't have
// Sets the base url for use in cmdline programs which don't have * $_SERVER variables
// $_SERVER variables */
if(! function_exists('check_url')) {
function check_url(&$a) { function check_url(&$a) {
$url = get_config('system','url'); $url = get_config('system','url');
@ -1067,12 +1122,11 @@ if(! function_exists('check_url')) {
return; return;
} }
}
// Automatic database updates /**
* @brief Automatic database updates
if(! function_exists('update_db')) { */
function update_db(&$a) { function update_db(&$a) {
$build = get_config('system','build'); $build = get_config('system','build');
if(! x($build)) if(! x($build))
@ -1133,8 +1187,7 @@ if(! function_exists('update_db')) {
return; return;
} }
}
if(!function_exists('run_update_function')){
function run_update_function($x) { function run_update_function($x) {
if(function_exists('update_' . $x)) { if(function_exists('update_' . $x)) {
@ -1175,10 +1228,8 @@ if(!function_exists('run_update_function')){
} }
return true; return true;
} }
}
if(! function_exists('check_plugins')) {
function check_plugins(&$a) { function check_plugins(&$a) {
/** /**
@ -1235,7 +1286,6 @@ if(! function_exists('check_plugins')) {
return; return;
} }
}
function get_guid($size=16, $prefix = "") { function get_guid($size=16, $prefix = "") {
@ -1256,11 +1306,17 @@ function get_guid($size=16, $prefix = "") {
} }
} }
// 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']. * @brief Wrapper for adding a login box.
// returns the complete html for inserting into the page *
* @param bool $register
if(! function_exists('login')) { * If $register == true provide a registration link.
* This will most always depend on the value of $a->config['register_policy'].
* @param bool $hiddens
*
* @return string
* Returns the complete html for inserting into the page
*/
function login($register = false, $hiddens=false) { function login($register = false, $hiddens=false) {
$a = get_app(); $a = get_app();
$o = ""; $o = "";
@ -1321,53 +1377,48 @@ if(! function_exists('login')) {
return $o; return $o;
} }
}
// Used to end the current process, after saving session state. /**
* @brief Used to end the current process, after saving session state.
if(! function_exists('killme')) { */
function killme() { function killme() {
session_write_close(); session_write_close();
exit; exit;
} }
}
// redirect to another URL and terminate this process. /**
* @brief Redirect to another URL and terminate this process.
if(! function_exists('goaway')) { */
function goaway($s) { function goaway($s) {
header("Location: $s"); header("Location: $s");
killme(); killme();
} }
}
// Returns the uid of locally logged in user or false. /**
* @brief Returns the user id of locally logged in user or false.
if(! function_exists('local_user')) { *
* @return int|bool user id or false
*/
function local_user() { function local_user() {
if((x($_SESSION,'authenticated')) && (x($_SESSION,'uid'))) if((x($_SESSION,'authenticated')) && (x($_SESSION,'uid')))
return intval($_SESSION['uid']); return intval($_SESSION['uid']);
return false; return false;
} }
}
// Returns contact id of authenticated site visitor or false /**
/* @brief Returns contact id of authenticated site visitor or false
if(! function_exists('remote_user')) { *
* @return int|bool visitor_id or false
*/
function remote_user() { function remote_user() {
if((x($_SESSION,'authenticated')) && (x($_SESSION,'visitor_id'))) if((x($_SESSION,'authenticated')) && (x($_SESSION,'visitor_id')))
return intval($_SESSION['visitor_id']); return intval($_SESSION['visitor_id']);
return false; return false;
} }
}
// 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')) {
/** /**
* Show an error message to user. * @brief Show an error message to user.
* *
* This function save text in session, to be shown to the user at next page load * This function save text in session, to be shown to the user at next page load
* *
@ -1379,10 +1430,9 @@ if(! function_exists('notice')) {
if($a->interactive) if($a->interactive)
$_SESSION['sysmsg'][] = $s; $_SESSION['sysmsg'][] = $s;
} }
}
if(! function_exists('info')) {
/** /**
* Show an info message to user. * @brief Show an info message to user.
* *
* This function save text in session, to be shown to the user at next page load * This function save text in session, to be shown to the user at next page load
* *
@ -1398,17 +1448,17 @@ if(! function_exists('info')) {
if($a->interactive) if($a->interactive)
$_SESSION['sysmsg_info'][] = $s; $_SESSION['sysmsg_info'][] = $s;
} }
}
// wrapper around config to limit the text length of an incoming message /**
* @brief Wrapper around config to limit the text length of an incoming message
if(! function_exists('get_max_import_size')) { *
* @return int
*/
function get_max_import_size() { function get_max_import_size() {
global $a; global $a;
return ((x($a->config,'max_import_size')) ? $a->config['max_import_size'] : 0 ); return ((x($a->config,'max_import_size')) ? $a->config['max_import_size'] : 0 );
} }
}
/** /**
* *
@ -1423,8 +1473,6 @@ if(! function_exists('get_max_import_size')) {
* *
* $cmd and string args are surrounded with "" * $cmd and string args are surrounded with ""
*/ */
if(! function_exists('proc_run')) {
function proc_run($cmd){ function proc_run($cmd){
$a = get_app(); $a = get_app();
@ -1509,9 +1557,7 @@ if(! function_exists('proc_run')) {
else else
proc_close(proc_open($cmdline." &",array(),$foo,dirname(__FILE__))); proc_close(proc_open($cmdline." &",array(),$foo,dirname(__FILE__)));
} }
}
if(! function_exists('current_theme')) {
function current_theme(){ function current_theme(){
$app_base_themes = array('duepuntozero', 'dispy', 'quattro'); $app_base_themes = array('duepuntozero', 'dispy', 'quattro');
@ -1587,13 +1633,14 @@ if(! function_exists('current_theme')) {
return (str_replace('view/theme/','', substr($fallback[0],0,-10))); return (str_replace('view/theme/','', substr($fallback[0],0,-10)));
} }
}
/* /**
* Return full URL to theme which is currently in effect. * @brief Return full URL to theme which is currently in effect.
*
* Provide a sane default if nothing is chosen or the specified theme does not exist. * Provide a sane default if nothing is chosen or the specified theme does not exist.
*
* @return string
*/ */
if(! function_exists('current_theme_url')) {
function current_theme_url() { function current_theme_url() {
global $a; global $a;
@ -1605,9 +1652,7 @@ if(! function_exists('current_theme_url')) {
return($a->get_baseurl() . '/view/theme/' . $t . '/style.css'); return($a->get_baseurl() . '/view/theme/' . $t . '/style.css');
} }
}
if(! function_exists('feed_birthday')) {
function feed_birthday($uid,$tz) { function feed_birthday($uid,$tz) {
/** /**
@ -1654,9 +1699,12 @@ if(! function_exists('feed_birthday')) {
return $birthday; return $birthday;
} }
}
if(! function_exists('is_site_admin')) { /**
* @brief Check if current user has admin role.
*
* @return bool true if user is an admin
*/
function is_site_admin() { function is_site_admin() {
$a = get_app(); $a = get_app();
@ -1667,10 +1715,8 @@ if(! function_exists('is_site_admin')) {
return true; return true;
return false; return false;
} }
}
if(! function_exists('load_contact_links')) {
function load_contact_links($uid) { function load_contact_links($uid) {
$a = get_app(); $a = get_app();
@ -1694,12 +1740,13 @@ if(! function_exists('load_contact_links')) {
$a->contacts = $ret; $a->contacts = $ret;
return; return;
} }
}
/** /**
* returns querystring as string from a mapped array * @brief Returns querystring as string from a mapped array.
*
* @param array $params mapped array with query parameters
* @param string $name of parameter, default null
* *
* @param params Array
* @return string * @return string
*/ */
function build_querystring($params, $name=null) { function build_querystring($params, $name=null) {