boot.php - code cleanup + doxygen

This commit is contained in:
rabuzarus 2015-12-24 01:31:17 +01:00
parent 7faa111c9b
commit 40b0d383d5
1 changed files with 1132 additions and 1085 deletions

303
boot.php
View File

@ -1,4 +1,21 @@
<?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/network.php');
@ -358,7 +375,8 @@ function startup() {
*
* 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
* and tries to make some sense of it, and
* stores our page contents and config storage
@ -366,9 +384,7 @@ function startup() {
* before we spit the page out.
*
*/
if(! class_exists('App')) {
class App {
class App {
public $module_loaded = false;
public $query_string;
@ -417,10 +433,12 @@ if(! class_exists('App')) {
public $theme_thread_allow = true;
public $theme_events_in_profile = true;
// An array for all theme-controllable parameters
// Mostly unimplemented yet. Only options 'stylesheet' and
// beyond are used.
/**
* @brief An array for all theme-controllable parameters
*
* Mostly unimplemented yet. Only options 'template_engine' and
* beyond are used.
*/
public $theme = array(
'sourcename' => '',
'videowidth' => 425,
@ -431,9 +449,13 @@ if(! class_exists('App')) {
'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();
// array of instanced template engines ('name'=>'instance')
/**
* @brief An array of instanced template engines ('name'=>'instance')
*/
public $template_engine_instance = array();
private $ldelim = array(
@ -457,6 +479,9 @@ if(! class_exists('App')) {
private $cached_profile_image;
private $cached_profile_picdate;
/**
* App constructor.
*/
function __construct() {
global $default_timezone;
@ -851,8 +876,10 @@ if(! class_exists('App')) {
/**
* register template engine class
* if $name is "", is used class static property $class::$name
* @brief Register template engine class
*
* If $name is "", is used class static property $class::$name
*
* @param string $class
* @param string $name
*/
@ -869,8 +896,10 @@ if(! class_exists('App')) {
}
/**
* return template engine instance. If $name is not defined,
* return engine defined by theme, or default
* @brief Return template engine instance.
*
* If $name is not defined, return engine defined by theme,
* or default
*
* @param strin $name Template engine name
* @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();
}
/**
* @brief Returns the active template engine.
*
* @return string
*/
function get_template_engine() {
return $this->theme['template_engine'];
}
@ -947,28 +981,34 @@ if(! class_exists('App')) {
return($this->is_friendica_app);
}
}
}
// 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() {
/**
* @brief Retrieve the App structure
*
* Useful in functions which require it but don't get it passed to them
*/
function get_app() {
global $a;
return $a;
}
};
}
// 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;
if(! function_exists('x')) {
function x($s,$k = NULL) {
/**
* @brief 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;
*
* @param string|array $s variable to check
* @param string $k key inside the array to check
*
* @return bool|int
*/
function x($s,$k = NULL) {
if($k != NULL) {
if((is_array($s)) && (array_key_exists($k,$s))) {
if($s[$k])
@ -986,21 +1026,19 @@ if(! function_exists('x')) {
}
return false;
}
}
}
// called from db initialisation if db is dead.
if(! function_exists('system_unavailable')) {
function system_unavailable() {
/**
* @brief Called from db initialisation if db is dead.
*/
function system_unavailable() {
include('system_unavailable.php');
system_down();
killme();
}
}
function clean_urls() {
global $a;
// if($a->config['system']['clean_urls'])
@ -1016,17 +1054,36 @@ function z_path() {
return $base;
}
/**
* @brief Returns the baseurl.
*
* @see App::get_baseurl()
*
* @return string
*/
function z_root() {
global $a;
return $a->get_baseurl();
}
/**
* @brief Return absolut URL for given $path.
*
* @param string $path
*
* @return string
*/
function absurl($path) {
if(strpos($path,'/') === 0)
return z_path() . $path;
return $path;
}
/**
* @brief Function to check if request was an AJAX (xmlhttprequest) request.
*
* @return boolean
*/
function is_ajax() {
return (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
}
@ -1044,13 +1101,11 @@ function check_db() {
}
// Sets the base url for use in cmdline programs which don't have
// $_SERVER variables
if(! function_exists('check_url')) {
function check_url(&$a) {
/**
* Sets the base url for use in cmdline programs which don't have
* $_SERVER variables
*/
function check_url(&$a) {
$url = get_config('system','url');
@ -1066,14 +1121,13 @@ if(! function_exists('check_url')) {
$url = set_config('system','url',$a->get_baseurl());
return;
}
}
// Automatic database updates
if(! function_exists('update_db')) {
function update_db(&$a) {
/**
* @brief Automatic database updates
*/
function update_db(&$a) {
$build = get_config('system','build');
if(! x($build))
$build = set_config('system','build',DB_UPDATE_VERSION);
@ -1132,10 +1186,9 @@ if(! function_exists('update_db')) {
}
return;
}
}
if(!function_exists('run_update_function')){
function run_update_function($x) {
function run_update_function($x) {
if(function_exists('update_' . $x)) {
// There could be a lot of processes running or about to run.
@ -1174,12 +1227,10 @@ if(!function_exists('run_update_function')){
return true;
}
return true;
}
}
if(! function_exists('check_plugins')) {
function check_plugins(&$a) {
function check_plugins(&$a) {
/**
*
@ -1234,7 +1285,6 @@ if(! function_exists('check_plugins')) {
load_hooks();
return;
}
}
function get_guid($size=16, $prefix = "") {
@ -1256,12 +1306,18 @@ 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'].
// returns the complete html for inserting into the page
if(! function_exists('login')) {
function login($register = false, $hiddens=false) {
/**
* @brief Wrapper for adding a login box.
*
* @param bool $register
* 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) {
$a = get_app();
$o = "";
$reg = false;
@ -1320,75 +1376,69 @@ if(! function_exists('login')) {
call_hooks('login_hook',$o);
return $o;
}
}
// Used to end the current process, after saving session state.
if(! function_exists('killme')) {
function killme() {
/**
* @brief Used to end the current process, after saving session state.
*/
function killme() {
session_write_close();
exit;
}
}
// redirect to another URL and terminate this process.
if(! function_exists('goaway')) {
function goaway($s) {
/**
* @brief Redirect to another URL and terminate this process.
*/
function goaway($s) {
header("Location: $s");
killme();
}
}
// Returns the uid of locally logged in user or false.
if(! function_exists('local_user')) {
function local_user() {
/**
* @brief Returns the user id of locally logged in user or false.
*
* @return int|bool user id or false
*/
function local_user() {
if((x($_SESSION,'authenticated')) && (x($_SESSION,'uid')))
return intval($_SESSION['uid']);
return false;
}
}
// Returns contact id of authenticated site visitor or false
if(! function_exists('remote_user')) {
function remote_user() {
/**
/* @brief Returns contact id of authenticated site visitor or false
*
* @return int|bool visitor_id or false
*/
function remote_user() {
if((x($_SESSION,'authenticated')) && (x($_SESSION,'visitor_id')))
return intval($_SESSION['visitor_id']);
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
*
* @param string $s - Text of notice
*/
function notice($s) {
function notice($s) {
$a = get_app();
if(! x($_SESSION,'sysmsg')) $_SESSION['sysmsg'] = array();
if($a->interactive)
$_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
*
* @param string $s - Text of notice
*/
function info($s) {
function info($s) {
$a = get_app();
if (local_user() AND get_pconfig(local_user(),'system','ignore_info'))
@ -1397,17 +1447,17 @@ if(! function_exists('info')) {
if(! x($_SESSION,'sysmsg_info')) $_SESSION['sysmsg_info'] = array();
if($a->interactive)
$_SESSION['sysmsg_info'][] = $s;
}
}
// wrapper around config to limit the text length of an incoming message
if(! function_exists('get_max_import_size')) {
function get_max_import_size() {
/**
* @brief Wrapper around config to limit the text length of an incoming message
*
* @return int
*/
function get_max_import_size() {
global $a;
return ((x($a->config,'max_import_size')) ? $a->config['max_import_size'] : 0 );
}
}
/**
@ -1423,9 +1473,7 @@ if(! function_exists('get_max_import_size')) {
*
* $cmd and string args are surrounded with ""
*/
if(! function_exists('proc_run')) {
function proc_run($cmd){
function proc_run($cmd){
$a = get_app();
@ -1508,11 +1556,9 @@ if(! function_exists('proc_run')) {
proc_close(proc_open('cmd /c start /b ' . $cmdline,array(),$foo,dirname(__FILE__)));
else
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');
$a = get_app();
@ -1586,15 +1632,16 @@ if(! function_exists('current_theme')) {
if(count($fallback))
return (str_replace('view/theme/','', substr($fallback[0],0,-10)));
}
}
/*
* 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.
*/
if(! function_exists('current_theme_url')) {
function current_theme_url() {
/**
* @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.
*
* @return string
*/
function current_theme_url() {
global $a;
$t = current_theme();
@ -1604,11 +1651,9 @@ if(! function_exists('current_theme_url')) {
return($a->get_baseurl() . '/view/theme/' . $t . '/style.pcss' . $opts);
return($a->get_baseurl() . '/view/theme/' . $t . '/style.css');
}
}
if(! function_exists('feed_birthday')) {
function feed_birthday($uid,$tz) {
function feed_birthday($uid,$tz) {
/**
*
@ -1653,11 +1698,14 @@ if(! function_exists('feed_birthday')) {
}
return $birthday;
}
}
if(! function_exists('is_site_admin')) {
function is_site_admin() {
/**
* @brief Check if current user has admin role.
*
* @return bool true if user is an admin
*/
function is_site_admin() {
$a = get_app();
$adminlist = explode(",", str_replace(" ", "", $a->config['admin_email']));
@ -1666,12 +1714,10 @@ if(! function_exists('is_site_admin')) {
if(local_user() && x($a->user,'email') && x($a->config,'admin_email') && in_array($a->user['email'], $adminlist))
return true;
return false;
}
}
if(! function_exists('load_contact_links')) {
function load_contact_links($uid) {
function load_contact_links($uid) {
$a = get_app();
@ -1693,15 +1739,16 @@ if(! function_exists('load_contact_links')) {
$a->contacts = $ret;
return;
}
}
/**
* returns querystring as string from a mapped array
*
* @param params Array
* @return string
*/
* @brief Returns querystring as string from a mapped array.
*
* @param array $params mapped array with query parameters
* @param string $name of parameter, default null
*
* @return string
*/
function build_querystring($params, $name=null) {
$ret = "";
foreach($params as $key=>$val) {