boot.php - code cleanup + doxygen
This commit is contained in:
parent
7faa111c9b
commit
40b0d383d5
243
boot.php
243
boot.php
|
@ -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,8 +384,6 @@ function startup() {
|
|||
* before we spit the page out.
|
||||
*
|
||||
*/
|
||||
|
||||
if(! class_exists('App')) {
|
||||
class App {
|
||||
|
||||
public $module_loaded = false;
|
||||
|
@ -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'];
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
if(! function_exists('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')) {
|
||||
/**
|
||||
* @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))) {
|
||||
|
@ -987,18 +1027,16 @@ if(! function_exists('x')) {
|
|||
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() {
|
||||
include('system_unavailable.php');
|
||||
system_down();
|
||||
killme();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function 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,12 +1101,10 @@ function check_db() {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Sets the base url for use in cmdline programs which don't have
|
||||
// $_SERVER variables
|
||||
|
||||
if(! function_exists('check_url')) {
|
||||
/**
|
||||
* Sets the base url for use in cmdline programs which don't have
|
||||
* $_SERVER variables
|
||||
*/
|
||||
function check_url(&$a) {
|
||||
|
||||
$url = get_config('system','url');
|
||||
|
@ -1067,12 +1122,11 @@ if(! function_exists('check_url')) {
|
|||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Automatic database updates
|
||||
|
||||
if(! function_exists('update_db')) {
|
||||
/**
|
||||
* @brief Automatic database updates
|
||||
*/
|
||||
function update_db(&$a) {
|
||||
$build = get_config('system','build');
|
||||
if(! x($build))
|
||||
|
@ -1133,8 +1187,7 @@ if(! function_exists('update_db')) {
|
|||
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(!function_exists('run_update_function')){
|
||||
|
||||
function run_update_function($x) {
|
||||
if(function_exists('update_' . $x)) {
|
||||
|
||||
|
@ -1175,10 +1228,8 @@ if(!function_exists('run_update_function')){
|
|||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(! function_exists('check_plugins')) {
|
||||
function check_plugins(&$a) {
|
||||
|
||||
/**
|
||||
|
@ -1235,7 +1286,6 @@ if(! function_exists('check_plugins')) {
|
|||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
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'].
|
||||
// returns the complete html for inserting into the page
|
||||
|
||||
if(! function_exists('login')) {
|
||||
/**
|
||||
* @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 = "";
|
||||
|
@ -1321,53 +1377,48 @@ if(! function_exists('login')) {
|
|||
|
||||
return $o;
|
||||
}
|
||||
}
|
||||
|
||||
// Used to end the current process, after saving session state.
|
||||
|
||||
if(! function_exists('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')) {
|
||||
/**
|
||||
* @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')) {
|
||||
/**
|
||||
* @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')) {
|
||||
/**
|
||||
/* @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
|
||||
*
|
||||
|
@ -1379,10 +1430,9 @@ if(! function_exists('notice')) {
|
|||
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
|
||||
*
|
||||
|
@ -1398,17 +1448,17 @@ if(! function_exists('info')) {
|
|||
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')) {
|
||||
/**
|
||||
* @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,8 +1473,6 @@ if(! function_exists('get_max_import_size')) {
|
|||
*
|
||||
* $cmd and string args are surrounded with ""
|
||||
*/
|
||||
|
||||
if(! function_exists('proc_run')) {
|
||||
function proc_run($cmd){
|
||||
|
||||
$a = get_app();
|
||||
|
@ -1509,9 +1557,7 @@ if(! function_exists('proc_run')) {
|
|||
else
|
||||
proc_close(proc_open($cmdline." &",array(),$foo,dirname(__FILE__)));
|
||||
}
|
||||
}
|
||||
|
||||
if(! function_exists('current_theme')) {
|
||||
function current_theme(){
|
||||
$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 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.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
if(! function_exists('current_theme_url')) {
|
||||
function current_theme_url() {
|
||||
global $a;
|
||||
|
||||
|
@ -1605,9 +1652,7 @@ if(! function_exists('current_theme_url')) {
|
|||
|
||||
return($a->get_baseurl() . '/view/theme/' . $t . '/style.css');
|
||||
}
|
||||
}
|
||||
|
||||
if(! function_exists('feed_birthday')) {
|
||||
function feed_birthday($uid,$tz) {
|
||||
|
||||
/**
|
||||
|
@ -1654,9 +1699,12 @@ if(! function_exists('feed_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() {
|
||||
$a = get_app();
|
||||
|
||||
|
@ -1667,10 +1715,8 @@ if(! function_exists('is_site_admin')) {
|
|||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(! function_exists('load_contact_links')) {
|
||||
function load_contact_links($uid) {
|
||||
|
||||
$a = get_app();
|
||||
|
@ -1694,12 +1740,13 @@ if(! function_exists('load_contact_links')) {
|
|||
$a->contacts = $ret;
|
||||
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
|
||||
*/
|
||||
function build_querystring($params, $name=null) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user