]> git.mxchange.org Git - friendica.git/blobdiff - src/App.php
Logger Levels
[friendica.git] / src / App.php
index 0ba82077985774e9728d03afc27d17758a7a0e67..92eb9409cafe1af40b8bcbbcbe0204479aafe273 100644 (file)
@@ -34,8 +34,6 @@ class App
        public $query_string = '';
        public $config = [];
        public $page = [];
-       public $pager = [];
-       public $page_offset;
        public $profile;
        public $profile_uid;
        public $user;
@@ -303,16 +301,6 @@ class App
                        $this->module = 'home';
                }
 
-               // See if there is any page number information, and initialise pagination
-               $this->pager['page'] = !empty($_GET['page']) && intval($_GET['page']) > 0 ? intval($_GET['page']) : 1;
-               $this->pager['itemspage'] = 50;
-               $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
-
-               if ($this->pager['start'] < 0) {
-                       $this->pager['start'] = 0;
-               }
-               $this->pager['total'] = 0;
-
                // Detect mobile devices
                $mobile_detect = new MobileDetect();
                $this->is_mobile = $mobile_detect->isMobile();
@@ -517,6 +505,7 @@ class App
                $relative_script_path = defaults($_SERVER, 'REDIRECT_URI'       , $relative_script_path);
                $relative_script_path = defaults($_SERVER, 'REDIRECT_SCRIPT_URL', $relative_script_path);
                $relative_script_path = defaults($_SERVER, 'SCRIPT_URL'         , $relative_script_path);
+               $relative_script_path = defaults($_SERVER, 'REQUEST_URI'        , $relative_script_path);
 
                $this->urlPath = $this->getConfigValue('system', 'urlpath');
 
@@ -732,23 +721,6 @@ class App
                return $this->urlPath;
        }
 
-       public function setPagerTotal($n)
-       {
-               $this->pager['total'] = intval($n);
-       }
-
-       public function setPagerItemsPage($n)
-       {
-               $this->pager['itemspage'] = ((intval($n) > 0) ? intval($n) : 0);
-               $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
-       }
-
-       public function setPagerPage($n)
-       {
-               $this->pager['page'] = $n;
-               $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
-       }
-
        /**
         * Initializes App->page['htmlhead'].
         *
@@ -798,9 +770,6 @@ class App
                        $touch_icon = 'images/friendica-128.png';
                }
 
-               // get data wich is needed for infinite scroll on the network page
-               $infinite_scroll = infinite_scroll_data($this->module);
-
                Core\Addon::callHooks('head', $this->page['htmlhead']);
 
                $tpl = get_markup_template('head.tpl');
@@ -818,7 +787,6 @@ class App
                        '$update_interval' => $interval,
                        '$shortcut_icon'   => $shortcut_icon,
                        '$touch_icon'      => $touch_icon,
-                       '$infinite_scroll' => $infinite_scroll,
                        '$block_public'    => intval(Core\Config::get('system', 'block_public')),
                        '$stylesheets'     => $this->stylesheets,
                ]) . $this->page['htmlhead'];
@@ -1133,10 +1101,10 @@ class App
 
                $processlist = DBA::processlist();
                if ($processlist['list'] != '') {
-                       logger('Processcheck: Processes: ' . $processlist['amount'] . ' - Processlist: ' . $processlist['list'], LOGGER_DEBUG);
+                       Core\Logger::log('Processcheck: Processes: ' . $processlist['amount'] . ' - Processlist: ' . $processlist['list'], Logger::DEBUG);
 
                        if ($processlist['amount'] > $max_processes) {
-                               logger('Processcheck: Maximum number of processes for ' . $process . ' tasks (' . $max_processes . ') reached.', LOGGER_DEBUG);
+                               Core\Logger::log('Processcheck: Maximum number of processes for ' . $process . ' tasks (' . $max_processes . ') reached.', Logger::DEBUG);
                                return true;
                        }
                }
@@ -1182,7 +1150,7 @@ class App
                $reached = ($free < $min_memory);
 
                if ($reached) {
-                       logger('Minimal memory reached: ' . $free . '/' . $meminfo['MemTotal'] . ' - limit ' . $min_memory, LOGGER_DEBUG);
+                       Core\Logger::log('Minimal memory reached: ' . $free . '/' . $meminfo['MemTotal'] . ' - limit ' . $min_memory, Logger::DEBUG);
                }
 
                return $reached;
@@ -1212,7 +1180,7 @@ class App
                $load = Core\System::currentLoad();
                if ($load) {
                        if (intval($load) > $maxsysload) {
-                               logger('system: load ' . $load . ' for ' . $process . ' tasks (' . $maxsysload . ') too high.');
+                               Core\Logger::log('system: load ' . $load . ' for ' . $process . ' tasks (' . $maxsysload . ') too high.');
                                return true;
                        }
                }
@@ -1254,7 +1222,7 @@ class App
                        $resource = proc_open($cmdline . ' &', [], $foo, $this->getBasePath());
                }
                if (!is_resource($resource)) {
-                       logger('We got no resource for command ' . $cmdline, LOGGER_DEBUG);
+                       Core\Logger::log('We got no resource for command ' . $cmdline, Logger::DEBUG);
                        return;
                }
                proc_close($resource);
@@ -1285,27 +1253,27 @@ class App
        public static function isDirectoryUsable($directory, $check_writable = true)
        {
                if ($directory == '') {
-                       logger('Directory is empty. This shouldn\'t happen.', LOGGER_DEBUG);
+                       Core\Logger::log('Directory is empty. This shouldn\'t happen.', Logger::DEBUG);
                        return false;
                }
 
                if (!file_exists($directory)) {
-                       logger('Path "' . $directory . '" does not exist for user ' . self::getSystemUser(), LOGGER_DEBUG);
+                       Core\Logger::log('Path "' . $directory . '" does not exist for user ' . self::getSystemUser(), Logger::DEBUG);
                        return false;
                }
 
                if (is_file($directory)) {
-                       logger('Path "' . $directory . '" is a file for user ' . self::getSystemUser(), LOGGER_DEBUG);
+                       Core\Logger::log('Path "' . $directory . '" is a file for user ' . self::getSystemUser(), Logger::DEBUG);
                        return false;
                }
 
                if (!is_dir($directory)) {
-                       logger('Path "' . $directory . '" is not a directory for user ' . self::getSystemUser(), LOGGER_DEBUG);
+                       Core\Logger::log('Path "' . $directory . '" is not a directory for user ' . self::getSystemUser(), Logger::DEBUG);
                        return false;
                }
 
                if ($check_writable && !is_writable($directory)) {
-                       logger('Path "' . $directory . '" is not writable for user ' . self::getSystemUser(), LOGGER_DEBUG);
+                       Core\Logger::log('Path "' . $directory . '" is not writable for user ' . self::getSystemUser(), Logger::DEBUG);
                        return false;
                }
 
@@ -1678,7 +1646,7 @@ class App
                                } else {
                                        // Someone came with an invalid parameter, maybe as a DDoS attempt
                                        // We simply stop processing here
-                                       logger("Invalid ZRL parameter " . $_GET['zrl'], LOGGER_DEBUG);
+                                       Core\Logger::log("Invalid ZRL parameter " . $_GET['zrl'], Logger::DEBUG);
                                        Core\System::httpExit(403, ['title' => '403 Forbidden']);
                                }
                        }
@@ -1774,7 +1742,7 @@ class App
                        $privateapps = Core\Config::get('config', 'private_addons', false);
                        if (Core\Addon::isEnabled($this->module) && file_exists("addon/{$this->module}/{$this->module}.php")) {
                                //Check if module is an app and if public access to apps is allowed or not
-                               if ((!local_user()) && Core\Addon::isApp($this->module) && $privateapps) {
+                               if ((!local_user()) && Core\Hook::isAddonApp($this->module) && $privateapps) {
                                        info(Core\L10n::t("You must be logged in to use addons. "));
                                } else {
                                        include_once "addon/{$this->module}/{$this->module}.php";
@@ -1817,11 +1785,11 @@ class App
                                }
 
                                if (!empty($_SERVER['QUERY_STRING']) && ($_SERVER['QUERY_STRING'] === 'q=internal_error.html') && isset($dreamhost_error_hack)) {
-                                       logger('index.php: dreamhost_error_hack invoked. Original URI =' . $_SERVER['REQUEST_URI']);
+                                       Core\Logger::log('index.php: dreamhost_error_hack invoked. Original URI =' . $_SERVER['REQUEST_URI']);
                                        $this->internalRedirect($_SERVER['REQUEST_URI']);
                                }
 
-                               logger('index.php: page not found: ' . $_SERVER['REQUEST_URI'] . ' ADDRESS: ' . $_SERVER['REMOTE_ADDR'] . ' QUERY: ' . $_SERVER['QUERY_STRING'], LOGGER_DEBUG);
+                               Core\Logger::log('index.php: page not found: ' . $_SERVER['REQUEST_URI'] . ' ADDRESS: ' . $_SERVER['REMOTE_ADDR'] . ' QUERY: ' . $_SERVER['QUERY_STRING'], Logger::DEBUG);
 
                                header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . Core\L10n::t('Not Found'));
                                $tpl = get_markup_template("404.tpl");
@@ -1984,6 +1952,9 @@ class App
                // Theme templates expect $a as an App instance
                $a = $this;
 
+               // Used as is in view/php/default.php
+               $lang = Core\L10n::getCurrentLang();
+
                /// @TODO Looks unsafe (remote-inclusion), is maybe not but Core\Theme::getPathForFile() uses file_exists() but does not escape anything
                require_once $template;
        }
@@ -2006,4 +1977,20 @@ class App
                $redirectTo = $this->getBaseURL($ssl) . '/' . ltrim($toUrl, '/');
                Core\System::externalRedirect($redirectTo);
        }
+
+       /**
+        * Automatically redirects to relative or absolute URL
+        * Should only be used if it isn't clear if the URL is either internal or external
+        *
+        * @param string $toUrl The target URL
+        *
+        */
+       public function redirect($toUrl)
+       {
+               if (filter_var($toUrl, FILTER_VALIDATE_URL)) {
+                       Core\System::externalRedirect($toUrl);
+               } else {
+                       $this->internalRedirect($toUrl);
+               }
+       }
 }