]> git.mxchange.org Git - friendica.git/blobdiff - src/App.php
Merge pull request #4243 from MrPetovan/task/switch-to-array-new-style
[friendica.git] / src / App.php
index ec03829933d8478ea81b6c53ecfe6b1d7ccfadf7..fdd928ba1a1c7b64a226301fd8ca1a5fdfa78d79 100644 (file)
@@ -2,16 +2,21 @@
 
 namespace Friendica;
 
+use Friendica\Core\System;
+use Friendica\Core\Cache;
 use Friendica\Core\Config;
 use Friendica\Core\PConfig;
+use Friendica\Database\DBM;
 
-use Cache;
-use dbm;
+use dba;
 
 use Detection\MobileDetect;
 
 use Exception;
 
+require_once 'boot.php';
+require_once 'include/dba.php';
+
 /**
  *
  * class: App
@@ -28,9 +33,11 @@ use Exception;
 class App {
 
        public $module_loaded = false;
+       public $module_class = null;
        public $query_string;
        public $config;
        public $page;
+       public $page_offset;
        public $profile;
        public $profile_uid;
        public $user;
@@ -39,7 +46,7 @@ class App {
        public $contacts;
        public $page_contact;
        public $content;
-       public $data = array();
+       public $data = [];
        public $error = false;
        public $cmd;
        public $argv;
@@ -53,14 +60,15 @@ class App {
        public $timezone;
        public $interactive = true;
        public $plugins;
-       public $apps = array();
+       public $plugins_admin = [];
+       public $apps = [];
        public $identities;
        public $is_mobile = false;
        public $is_tablet = false;
        public $is_friendica_app;
-       public $performance = array();
-       public $callstack = array();
-       public $theme_info = array();
+       public $performance = [];
+       public $callstack = [];
+       public $theme_info = [];
        public $backend = true;
        public $nav_sel;
        public $category;
@@ -71,7 +79,6 @@ class App {
        public $videowidth = 425;
        public $videoheight = 350;
        public $force_max_items = 0;
-       public $theme_thread_allow = true;
        public $theme_events_in_profile = true;
 
        /**
@@ -80,35 +87,34 @@ class App {
         * Mostly unimplemented yet. Only options 'template_engine' and
         * beyond are used.
         */
-       public $theme = array(
+       public $theme = [
                'sourcename' => '',
                'videowidth' => 425,
                'videoheight' => 350,
                'force_max_items' => 0,
-               'thread_allow' => true,
                'stylesheet' => '',
                'template_engine' => 'smarty3',
-       );
+       ];
 
        /**
         * @brief An array of registered template engines ('name'=>'class name')
         */
-       public $template_engines = array();
+       public $template_engines = [];
 
        /**
         * @brief An array of instanced template engines ('name'=>'instance')
         */
-       public $template_engine_instance = array();
+       public $template_engine_instance = [];
        public $process_id;
        public $queue;
-       private $ldelim = array(
+       private $ldelim = [
                'internal' => '',
                'smarty3' => '{{'
-       );
-       private $rdelim = array(
+       ];
+       private $rdelim = [
                'internal' => '',
                'smarty3' => '}}'
-       );
+       ];
        private $scheme;
        private $hostname;
        private $db;
@@ -130,8 +136,14 @@ class App {
 
                $hostname = '';
 
-               if (file_exists('.htpreconfig.php')) {
-                       include '.htpreconfig.php';
+               if (! static::directory_usable($basepath, false)) {
+                       throw new Exception('Basepath ' . $basepath . ' isn\'t usable.');
+               }
+
+               $this->basepath = rtrim($basepath, DIRECTORY_SEPARATOR);
+
+               if (file_exists($this->basepath.DIRECTORY_SEPARATOR.'.htpreconfig.php')) {
+                       include $this->basepath.DIRECTORY_SEPARATOR.'.htpreconfig.php';
                }
 
                $this->timezone = ((x($default_timezone)) ? $default_timezone : 'UTC');
@@ -148,16 +160,16 @@ class App {
                $this->performance['marktime'] = 0;
                $this->performance['markstart'] = microtime(true);
 
-               $this->callstack['database'] = array();
-               $this->callstack['database_write'] = array();
-               $this->callstack['network'] = array();
-               $this->callstack['file'] = array();
-               $this->callstack['rendering'] = array();
-               $this->callstack['parser'] = array();
+               $this->callstack['database'] = [];
+               $this->callstack['database_write'] = [];
+               $this->callstack['network'] = [];
+               $this->callstack['file'] = [];
+               $this->callstack['rendering'] = [];
+               $this->callstack['parser'] = [];
 
-               $this->config = array();
-               $this->page = array();
-               $this->pager = array();
+               $this->config = [];
+               $this->page = [];
+               $this->pager = [];
 
                $this->query_string = '';
 
@@ -199,17 +211,10 @@ class App {
                        $this->hostname = $hostname;
                }
 
-               if (! static::directory_usable($basepath, false)) {
-                       throw new Exception('Basepath ' . $basepath . ' isn\'t usable.');
-               }
-
-               $this->basepath = rtrim($basepath, DIRECTORY_SEPARATOR);
-
                set_include_path(
                        get_include_path() . PATH_SEPARATOR
                        . $this->basepath . DIRECTORY_SEPARATOR . 'include' . PATH_SEPARATOR
                        . $this->basepath . DIRECTORY_SEPARATOR . 'library' . PATH_SEPARATOR
-                       . $this->basepath . DIRECTORY_SEPARATOR . 'library/langdet' . PATH_SEPARATOR
                        . $this->basepath);
 
 
@@ -269,7 +274,7 @@ class App {
                        $this->module = str_replace('-', '_', $this->module);
                } else {
                        $this->argc = 1;
-                       $this->argv = array('home');
+                       $this->argv = ['home'];
                        $this->module = 'home';
                }
 
@@ -294,7 +299,7 @@ class App {
                // Register template engines
                $dc = get_declared_classes();
                foreach ($dc as $k) {
-                       if (in_array('ITemplateEngine', class_implements($k))) {
+                       if (in_array('Friendica\Render\ITemplateEngine', class_implements($k))) {
                                $this->register_template_engine($k);
                        }
                }
@@ -310,10 +315,8 @@ class App {
         *
         * @return string
         */
-       public static function get_basepath() {
-               if (isset($this)) {
-                       $basepath = $this->basepath;
-               }
+       public function get_basepath() {
+               $basepath = $this->basepath;
 
                if (! $basepath) {
                        $basepath = Config::get('system', 'basepath');
@@ -369,11 +372,6 @@ class App {
         * @return string Friendica server base URL
         */
        function get_baseurl($ssl = false) {
-               // Is the function called statically?
-               if (!(isset($this) && get_class($this) == __CLASS__)) {
-                       return self::$a->get_baseurl($ssl);
-               }
-
                $scheme = $this->scheme;
 
                if (Config::get('system', 'ssl_policy') == SSL_POLICY_FULL) {
@@ -419,8 +417,8 @@ class App {
                                $this->path = trim($parsed['path'], '\\/');
                        }
 
-                       if (file_exists('.htpreconfig.php')) {
-                               include '.htpreconfig.php';
+                       if (file_exists($this->basepath.DIRECTORY_SEPARATOR.'.htpreconfig.php')) {
+                               include $this->basepath.DIRECTORY_SEPARATOR.'.htpreconfig.php';
                        }
 
                        if (Config::get('config', 'hostname') != '') {
@@ -519,8 +517,8 @@ class App {
                $invinite_scroll = infinite_scroll_data($this->module);
 
                $tpl = get_markup_template('head.tpl');
-               $this->page['htmlhead'] = replace_macros($tpl, array(
-                               '$baseurl' => $this->get_baseurl(), // FIXME for z_path!!!!
+               $this->page['htmlhead'] = replace_macros($tpl, [
+                               '$baseurl' => $this->get_baseurl(),
                                '$local_user' => local_user(),
                                '$generator' => 'Friendica' . ' ' . FRIENDICA_VERSION,
                                '$delitem' => t('Delete this item?'),
@@ -531,7 +529,7 @@ class App {
                                '$touch_icon' => $touch_icon,
                                '$stylesheet' => $stylesheet,
                                '$infinite_scroll' => $invinite_scroll,
-                       )) . $this->page['htmlhead'];
+                       ]) . $this->page['htmlhead'];
        }
 
        function init_page_end() {
@@ -539,9 +537,9 @@ class App {
                        $this->page['end'] = '';
                }
                $tpl = get_markup_template('end.tpl');
-               $this->page['end'] = replace_macros($tpl, array(
-                               '$baseurl' => $this->get_baseurl() // FIXME for z_path!!!!
-                       )) . $this->page['end'];
+               $this->page['end'] = replace_macros($tpl, [
+                               '$baseurl' => $this->get_baseurl()
+                       ]) . $this->page['end'];
        }
 
        function set_curl_code($code) {
@@ -581,11 +579,6 @@ class App {
         */
        function remove_baseurl($orig_url) {
 
-               // Is the function called statically?
-               if (!(isset($this) && get_class($this) == __CLASS__)) {
-                       return self::$a->remove_baseurl($orig_url);
-               }
-
                // Remove the hostname from the url if it is an internal link
                $nurl = normalise_link($orig_url);
                $base = normalise_link($this->get_baseurl());
@@ -627,7 +620,7 @@ class App {
         * If $name is not defined, return engine defined by theme,
         * or default
         *
-        * @param strin $name Template engine name
+        * @param string $name Template engine name
         * @return object Template Engine instance
         */
        function template_engine($name = '') {
@@ -692,7 +685,7 @@ class App {
                $this->performance[$value] += (float) $duration;
                $this->performance['marktime'] += (float) $duration;
 
-               $callstack = $this->callstack();
+               $callstack = System::callstack();
 
                if (!isset($this->callstack[$value][$callstack])) {
                        // Prevent ugly E_NOTICE
@@ -712,57 +705,37 @@ class App {
 
                $this->remove_inactive_processes();
 
-               q('START TRANSACTION');
+               dba::transaction();
 
                $r = q('SELECT `pid` FROM `process` WHERE `pid` = %d', intval(getmypid()));
-               if (!dbm::is_result($r)) {
-                       q("INSERT INTO `process` (`pid`,`command`,`created`) VALUES (%d, '%s', '%s')", intval(getmypid()), dbesc($command), dbesc(datetime_convert()));
+               if (!DBM::is_result($r)) {
+                       dba::insert('process', ['pid' => getmypid(), 'command' => $command, 'created' => datetime_convert()]);
                }
-               q('COMMIT');
+               dba::commit();
        }
 
        /**
         * @brief Remove inactive processes
         */
        function remove_inactive_processes() {
-               q('START TRANSACTION');
+               dba::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']));
+                                       dba::delete('process', ['pid' => $process['pid']]);
                                }
                        }
                }
-               q('COMMIT');
+               dba::commit();
        }
 
        /**
         * @brief Remove the active process from the "process" table
         */
        function end_process() {
-               q('DELETE FROM `process` WHERE `pid` = %d', intval(getmypid()));
-       }
-
-       /**
-        * @brief Returns a string with a callstack. Can be used for logging.
-        *
-        * @return string
-        */
-       function callstack($depth = 4) {
-               $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $depth + 2);
-
-               // We remove the first two items from the list since they contain data that we don't need.
-               array_shift($trace);
-               array_shift($trace);
-
-               $callstack = array();
-               foreach ($trace AS $func) {
-                       $callstack[] = $func['function'];
-               }
-
-               return implode(', ', $callstack);
+               dba::delete('process', ['pid' => getmypid()]);
        }
 
        function get_useragent() {
@@ -787,7 +760,7 @@ class App {
         * @return bool Is it a known backend?
         */
        function is_backend() {
-               static $backends = array();
+               static $backends = [];
                $backends[] = '_well_known';
                $backends[] = 'api';
                $backends[] = 'dfrn_notify';
@@ -835,7 +808,7 @@ class App {
                        }
                }
 
-               $processlist = dbm::processlist();
+               $processlist = DBM::processlist();
                if ($processlist['list'] != '') {
                        logger('Processcheck: Processes: ' . $processlist['amount'] . ' - Processlist: ' . $processlist['list'], LOGGER_DEBUG);
 
@@ -864,7 +837,7 @@ class App {
 
                $memdata = explode("\n", file_get_contents('/proc/meminfo'));
 
-               $meminfo = array();
+               $meminfo = [];
                foreach ($memdata as $line) {
                        list($key, $val) = explode(':', $line);
                        $meminfo[$key] = (int) trim(str_replace('kB', '', $val));
@@ -951,9 +924,9 @@ class App {
                }
 
                if (Config::get('system', 'proc_windows')) {
-                       $resource = proc_open('cmd /c start /b ' . $cmdline, array(), $foo, $this->get_basepath());
+                       $resource = proc_open('cmd /c start /b ' . $cmdline, [], $foo, $this->get_basepath());
                } else {
-                       $resource = proc_open($cmdline . ' &', array(), $foo, $this->get_basepath());
+                       $resource = proc_open($cmdline . ' &', [], $foo, $this->get_basepath());
                }
                if (!is_resource($resource)) {
                        logger('We got no resource for command ' . $cmdline, LOGGER_DEBUG);