]> git.mxchange.org Git - friendica.git/blobdiff - boot.php
Split poco discovery in smaller function calls
[friendica.git] / boot.php
index 9a766d41dc1ded72e3ff382e4225103b04751eb2..ef787c63530ce1c9d304ffd814bedf70ba12fe22 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -19,6 +19,8 @@
 
 require_once('include/autoloader.php');
 
+use \Friendica\Core\Config;
+
 require_once('include/config.php');
 require_once('include/network.php');
 require_once('include/plugin.php');
@@ -38,7 +40,7 @@ define ( 'FRIENDICA_PLATFORM',     'Friendica');
 define ( 'FRIENDICA_CODENAME',     'Asparagus');
 define ( 'FRIENDICA_VERSION',      '3.5.1-dev' );
 define ( 'DFRN_PROTOCOL_VERSION',  '2.23'    );
-define ( 'DB_UPDATE_VERSION',      1209      );
+define ( 'DB_UPDATE_VERSION',      1213      );
 
 /**
  * @brief Constant with a HTML line break.
@@ -670,22 +672,23 @@ class App {
 
                #set_include_path("include/$this->hostname" . PATH_SEPARATOR . get_include_path());
 
-               if((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,9) === "pagename=") {
+               if ((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,9) === "pagename=") {
                        $this->query_string = substr($_SERVER['QUERY_STRING'],9);
                        // removing trailing / - maybe a nginx problem
                        if (substr($this->query_string, 0, 1) == "/")
                                $this->query_string = substr($this->query_string, 1);
-               } elseif((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,2) === "q=") {
+               } elseif ((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,2) === "q=") {
                        $this->query_string = substr($_SERVER['QUERY_STRING'],2);
                        // removing trailing / - maybe a nginx problem
                        if (substr($this->query_string, 0, 1) == "/")
                                $this->query_string = substr($this->query_string, 1);
                }
 
-               if (x($_GET,'pagename'))
+               if (x($_GET,'pagename')) {
                        $this->cmd = trim($_GET['pagename'],'/\\');
-               elseif (x($_GET,'q'))
+               } elseif (x($_GET,'q')) {
                        $this->cmd = trim($_GET['q'],'/\\');
+               }
 
 
                // fix query_string
@@ -694,13 +697,15 @@ class App {
 
                // unix style "homedir"
 
-               if(substr($this->cmd,0,1) === '~')
+               if (substr($this->cmd,0,1) === '~') {
                        $this->cmd = 'profile/' . substr($this->cmd,1);
+               }
 
                // Diaspora style profile url
 
-               if(substr($this->cmd,0,2) === 'u/')
+               if (substr($this->cmd,0,2) === 'u/') {
                        $this->cmd = 'profile/' . substr($this->cmd,2);
+               }
 
 
                /*
@@ -767,7 +772,7 @@ class App {
 
        }
 
-       function get_basepath() {
+       public static function get_basepath() {
 
                $basepath = get_config("system", "basepath");
 
@@ -806,7 +811,7 @@ class App {
        function get_baseurl($ssl = false) {
 
                // Is the function called statically?
-               if (!is_object($this)) {
+               if (!(isset($this) && get_class($this) == __CLASS__)) {
                        return self::$a->get_baseurl($ssl);
                }
 
@@ -820,24 +825,22 @@ class App {
 
                $scheme = $this->scheme;
 
-               if ((x($this->config, 'system')) && (x($this->config['system'], 'ssl_policy'))) {
-                       if (intval($this->config['system']['ssl_policy']) === SSL_POLICY_FULL) {
-                               $scheme = 'https';
-                       }
+               if (Config::get('system', 'ssl_policy') === SSL_POLICY_FULL) {
+                       $scheme = 'https';
+               }
 
-                       //      Basically, we have $ssl = true on any links which can only be seen by a logged in user
-                       //      (and also the login link). Anything seen by an outsider will have it turned off.
+               //      Basically, we have $ssl = true on any links which can only be seen by a logged in user
+               //      (and also the login link). Anything seen by an outsider will have it turned off.
 
-                       if ($this->config['system']['ssl_policy'] == SSL_POLICY_SELFSIGN) {
-                               if ($ssl) {
-                                       $scheme = 'https';
-                               } else {
-                                       $scheme = 'http';
-                               }
+               if (Config::get('system', 'ssl_policy') == SSL_POLICY_SELFSIGN) {
+                       if ($ssl) {
+                               $scheme = 'https';
+                       } else {
+                               $scheme = 'http';
                        }
                }
 
-               if (get_config('config', 'hostname') != '') {
+               if (Config::get('config', 'hostname') != '') {
                        $this->hostname = get_config('config', 'hostname');
                }
 
@@ -1028,7 +1031,7 @@ class App {
                } else {
                        $r = q("SELECT `contact`.`avatar-date` AS picdate FROM `contact` WHERE `contact`.`thumb` like '%%/%s'",
                                $common_filename);
-                       if(! dbm::is_result($r)){
+                       if (! dbm::is_result($r)) {
                                $this->cached_profile_image[$avatar_image] = $avatar_image;
                        } else {
                                $this->cached_profile_picdate[$common_filename] = "?rev=".urlencode($r[0]['picdate']);
@@ -1050,7 +1053,7 @@ class App {
        function remove_baseurl($orig_url){
 
                // Is the function called statically?
-               if (!is_object($this)) {
+               if (!(isset($this) && get_class($this) == __CLASS__)) {
                        return(self::$a->remove_baseurl($orig_url));
                }
 
@@ -1191,7 +1194,7 @@ class App {
                q("START TRANSACTION");
 
                $r = q("SELECT `pid` FROM `process` WHERE `pid` = %d", intval(getmypid()));
-               if(!dbm::is_result($r)) {
+               if (!dbm::is_result($r)) {
                        q("INSERT INTO `process` (`pid`,`command`,`created`) VALUES (%d, '%s', '%s')",
                                intval(getmypid()),
                                dbesc($command),
@@ -1207,7 +1210,7 @@ class App {
                q("START TRANSACTION");
 
                $r = q("SELECT `pid` FROM `process`");
-               if(dbm::is_result($r)) {
+               if (dbm::is_result($r)) {
                        foreach ($r AS $process) {
                                if (!posix_kill($process["pid"], 0)) {
                                        q("DELETE FROM `process` WHERE `pid` = %d", intval($process["pid"]));
@@ -1294,10 +1297,6 @@ class App {
         */
        function max_processes_reached() {
 
-               // Is the function called statically?
-               if (!is_object($this))
-                       return(self::$a->max_processes_reached());
-
                if ($this->is_backend()) {
                        $process = "backend";
                        $max_processes = get_config('system', 'max_processes_backend');
@@ -1329,10 +1328,6 @@ class App {
         */
        function maxload_reached() {
 
-               // Is the function called statically?
-               if (!is_object($this))
-                       return(self::$a->maxload_reached());
-
                if ($this->is_backend()) {
                        $process = "backend";
                        $maxsysload = intval(get_config('system', 'maxloadavg'));
@@ -1396,11 +1391,15 @@ class App {
                        // If the last worker fork was less than 10 seconds before then don't fork another one.
                        // This should prevent the forking of masses of workers.
                        if (get_config("system", "worker")) {
-                               if ((time() - get_config("system", "proc_run_started")) < 10)
-                                       return;
-
+                               $cachekey = "app:proc_run:started";
+                               $result = Cache::get($cachekey);
+                               if (!is_null($result)) {
+                                       if ((time() - $result) < 10) {
+                                               return;
+                                       }
+                               }
                                // Set the timestamp of the last proc_run
-                               set_config("system", "proc_run_started", time());
+                               Cache::set($cachekey, time(), CACHE_MINUTE);
                        }
 
                        $args[0] = ((x($this->config,'php_path')) && (strlen($this->config['php_path'])) ? $this->config['php_path'] : 'php');
@@ -1479,17 +1478,16 @@ function system_unavailable() {
 
 
 function clean_urls() {
-       global $a;
-       //      if($a->config['system']['clean_urls'])
+       $a = get_app();
        return true;
-       //      return false;
 }
 
 function z_path() {
-       global $a;
-       $base = $a->get_baseurl();
+       $base = App::get_baseurl();
+
        if(! clean_urls())
                $base .= '/?q=';
+
        return $base;
 }
 
@@ -1499,10 +1497,10 @@ function z_path() {
  * @see App::get_baseurl()
  *
  * @return string
+ * @TODO Maybe super-flous and deprecated? Seems to only wrap App::get_baseurl()
  */
 function z_root() {
-       global $a;
-       return $a->get_baseurl();
+       return App::get_baseurl();
 }
 
 /**
@@ -1544,7 +1542,7 @@ function check_db() {
  * Sets the base url for use in cmdline programs which don't have
  * $_SERVER variables
  */
-function check_url(&$a) {
+function check_url(App $a) {
 
        $url = get_config('system','url');
 
@@ -1555,9 +1553,9 @@ function check_url(&$a) {
        // We will only change the url to an ip address if there is no existing setting
 
        if(! x($url))
-               $url = set_config('system','url',$a->get_baseurl());
-       if((! link_compare($url,$a->get_baseurl())) && (! preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/",$a->get_hostname)))
-               $url = set_config('system','url',$a->get_baseurl());
+               $url = set_config('system','url',App::get_baseurl());
+       if((! link_compare($url,App::get_baseurl())) && (! preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/",$a->get_hostname)))
+               $url = set_config('system','url',App::get_baseurl());
 
        return;
 }
@@ -1566,7 +1564,7 @@ function check_url(&$a) {
 /**
  * @brief Automatic database updates
  */
-function update_db(&$a) {
+function update_db(App $a) {
        $build = get_config('system','build');
        if(! x($build))
                $build = set_config('system','build',DB_UPDATE_VERSION);
@@ -1575,7 +1573,7 @@ function update_db(&$a) {
                $stored = intval($build);
                $current = intval(DB_UPDATE_VERSION);
                if($stored < $current) {
-                       load_config('database');
+                       Config::load('database');
 
                        // We're reporting a different version than what is currently installed.
                        // Run any existing update scripts to bring the database up to current.
@@ -1682,10 +1680,10 @@ function run_update_function($x) {
  * @param App $a
  *
         */
-function check_plugins(&$a) {
+function check_plugins(App $a) {
 
        $r = q("SELECT * FROM `addon` WHERE `installed` = 1");
-       if(dbm::is_result($r))
+       if (dbm::is_result($r))
                $installed = $r;
        else
                $installed = array();
@@ -1903,7 +1901,7 @@ function info($s) {
  * @return int
  */
 function get_max_import_size() {
-       global $a;
+       $a = get_app();
        return ((x($a->config,'max_import_size')) ? $a->config['max_import_size'] : 0 );
 }
 
@@ -2029,7 +2027,7 @@ function current_theme(){
                $r = q("select theme from user where uid = %d limit 1",
                        intval($a->profile_uid)
                );
-               if(dbm::is_result($r))
+               if (dbm::is_result($r))
                        $page_theme = $r[0]['theme'];
        }
 
@@ -2045,16 +2043,18 @@ function current_theme(){
 //             $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
        $is_mobile = $a->is_mobile || $a->is_tablet;
 
-       $standard_system_theme = ((isset($a->config['system']['theme'])) ? $a->config['system']['theme'] : '');
+       $standard_system_theme = Config::get('system', 'theme', '');
        $standard_theme_name = ((isset($_SESSION) && x($_SESSION,'theme')) ? $_SESSION['theme'] : $standard_system_theme);
 
-       if($is_mobile) {
-               if(isset($_SESSION['show-mobile']) && !$_SESSION['show-mobile']) {
+       if ($is_mobile) {
+               if (isset($_SESSION['show-mobile']) && !$_SESSION['show-mobile']) {
                        $system_theme = $standard_system_theme;
                        $theme_name = $standard_theme_name;
-               }
-               else {
-                       $system_theme = ((isset($a->config['system']['mobile-theme'])) ? $a->config['system']['mobile-theme'] : $standard_system_theme);
+               } else {
+                       $system_theme = Config::get('system', 'mobile-theme', '');
+                       if ($system_theme == '') {
+                               $system_theme = $standard_system_theme;
+                       }
                        $theme_name = ((isset($_SESSION) && x($_SESSION,'mobile-theme')) ? $_SESSION['mobile-theme'] : $system_theme);
 
                        if($theme_name === '---') {
@@ -2100,7 +2100,7 @@ function current_theme(){
  * @return string
  */
 function current_theme_url() {
-       global $a;
+       $a = get_app();
 
        $t = current_theme();
 
@@ -2142,7 +2142,7 @@ function feed_birthday($uid,$tz) {
                        intval($uid)
        );
 
-       if(dbm::is_result($p)) {
+       if (dbm::is_result($p)) {
                $tmp_dob = substr($p[0]['dob'],5);
                if(intval($tmp_dob)) {
                        $y = datetime_convert($tz,$tz,'now','Y');
@@ -2365,20 +2365,27 @@ function get_lockpath() {
        return "";
 }
 
+/**
+ * @brief Returns the path where spool files are stored
+ *
+ * @return string Spool path
+ */
 function get_spoolpath() {
        $spoolpath = get_config('system','spoolpath');
-       if (($spoolpath != "") AND is_dir($spoolpath) AND is_writable($spoolpath))
+       if (($spoolpath != "") AND is_dir($spoolpath) AND is_writable($spoolpath)) {
                return($spoolpath);
+       }
 
        $temppath = get_temppath();
 
        if ($temppath != "") {
                $spoolpath = $temppath."/spool";
 
-               if (!is_dir($spoolpath))
+               if (!is_dir($spoolpath)) {
                        mkdir($spoolpath);
-               elseif (!is_writable($spoolpath))
+               } elseif (!is_writable($spoolpath)) {
                        $spoolpath = $temppath;
+               }
 
                if (is_dir($spoolpath) AND is_writable($spoolpath)) {
                        set_config("system", "spoolpath", $spoolpath);
@@ -2410,7 +2417,8 @@ function get_temppath() {
        return("");
 }
 
-function set_template_engine(&$a, $engine = 'internal') {
+/// @deprecated
+function set_template_engine(App $a, $engine = 'internal') {
 /// @note This function is no longer necessary, but keep it as a wrapper to the class method
 /// to avoid breaking themes again unnecessarily