X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=inline;f=src%2FApp.php;h=445101309384a2f651b46fd69f78b507835538a4;hb=4894e89f036be1f8a82523ac69d56ae36e7685df;hp=cd1386e590d067d17c732ba731d9a9eb43d05d1a;hpb=a0bd96d58727695540099b1ff6fe033aa4e8f6ef;p=friendica.git diff --git a/src/App.php b/src/App.php index cd1386e590..4451013093 100644 --- a/src/App.php +++ b/src/App.php @@ -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; @@ -50,20 +48,14 @@ class App public $argv; public $argc; public $module; - public $strings; - public $hooks = []; public $timezone; public $interactive = true; - public $addons; - public $addons_admin = []; - public $apps = []; public $identities; public $is_mobile = false; public $is_tablet = false; public $performance = []; public $callstack = []; public $theme_info = []; - public $nav_sel; public $category; // Allow themes to control internal parameters // by changing App values in theme.php @@ -144,40 +136,8 @@ class App $this->footerScripts[] = trim($url, '/'); } - /** - * @brief An array for all theme-controllable parameters - * - * Mostly unimplemented yet. Only options 'template_engine' and - * beyond are used. - */ - public $theme = [ - 'sourcename' => '', - 'videowidth' => 425, - 'videoheight' => 350, - 'force_max_items' => 0, - 'stylesheet' => '', - 'template_engine' => 'smarty3', - ]; - - /** - * @brief An array of registered template engines ('name'=>'class name') - */ - public $template_engines = []; - - /** - * @brief An array of instanced template engines ('name'=>'instance') - */ - public $template_engine_instance = []; public $process_id; public $queue; - private $ldelim = [ - 'internal' => '', - 'smarty3' => '{{' - ]; - private $rdelim = [ - 'internal' => '', - 'smarty3' => '}}' - ]; private $scheme; private $hostname; @@ -309,16 +269,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(); @@ -327,7 +277,7 @@ class App $this->isAjax = strtolower(defaults($_SERVER, 'HTTP_X_REQUESTED_WITH', '')) == 'xmlhttprequest'; // Register template engines - $this->registerTemplateEngine('Friendica\Render\FriendicaSmartyEngine'); + Core\Renderer::registerTemplateEngine('Friendica\Render\FriendicaSmartyEngine'); } /** @@ -363,25 +313,14 @@ class App Core\Config::load(); if ($this->getMode()->has(App\Mode::DBAVAILABLE)) { - Core\Addon::loadHooks(); + Core\Hook::loadHooks(); $this->loadAddonConfig(); } $this->loadDefaultTimezone(); - $this->page = [ - 'aside' => '', - 'bottom' => '', - 'content' => '', - 'footer' => '', - 'htmlhead' => '', - 'nav' => '', - 'page_title' => '', - 'right_aside' => '', - 'template' => '', - 'title' => '' - ]; + Core\L10n::init(); $this->process_id = Core\System::processID('log'); } @@ -534,6 +473,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'); @@ -590,7 +530,11 @@ class App $stamp1 = microtime(true); - DBA::connect($db_host, $db_user, $db_pass, $db_data, $charset); + if (DBA::connect($db_host, $db_user, $db_pass, $db_data, $charset)) { + // Loads DB_UPDATE_VERSION constant + Database\DBStructure::definition(false); + } + unset($db_host, $db_user, $db_pass, $db_data, $charset); $this->saveTimestamp($stamp1, 'network'); @@ -745,23 +689,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']. * @@ -793,8 +720,8 @@ class App $this->page['title'] = $this->config['sitename']; } - if (!empty($this->theme['stylesheet'])) { - $stylesheet = $this->theme['stylesheet']; + if (!empty(Core\Renderer::$theme['stylesheet'])) { + $stylesheet = Core\Renderer::$theme['stylesheet']; } else { $stylesheet = $this->getCurrentThemeStylesheetPath(); } @@ -811,17 +738,14 @@ 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'); + $tpl = Core\Renderer::getMarkupTemplate('head.tpl'); /* put the head template at the beginning of page['htmlhead'] * since the code added by the modules frequently depends on it * being first */ - $this->page['htmlhead'] = replace_macros($tpl, [ + $this->page['htmlhead'] = Core\Renderer::replaceMacros($tpl, [ '$baseurl' => $this->getBaseURL(), '$local_user' => local_user(), '$generator' => 'Friendica' . ' ' . FRIENDICA_VERSION, @@ -831,7 +755,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']; @@ -864,11 +787,11 @@ class App */ if ($this->is_mobile || $this->is_tablet) { if (isset($_SESSION['show-mobile']) && !$_SESSION['show-mobile']) { - $link = 'toggle_mobile?address=' . curPageURL(); + $link = 'toggle_mobile?address=' . urlencode(curPageURL()); } else { - $link = 'toggle_mobile?off=1&address=' . curPageURL(); + $link = 'toggle_mobile?off=1&address=' . urlencode(curPageURL()); } - $this->page['footer'] .= replace_macros(get_markup_template("toggle_mobile_footer.tpl"), [ + $this->page['footer'] .= Core\Renderer::replaceMacros(Core\Renderer::getMarkupTemplate("toggle_mobile_footer.tpl"), [ '$toggle_link' => $link, '$toggle_text' => Core\L10n::t('toggle mobile') ]); @@ -876,8 +799,8 @@ class App Core\Addon::callHooks('footer', $this->page['footer']); - $tpl = get_markup_template('footer.tpl'); - $this->page['footer'] = replace_macros($tpl, [ + $tpl = Core\Renderer::getMarkupTemplate('footer.tpl'); + $this->page['footer'] = Core\Renderer::replaceMacros($tpl, [ '$baseurl' => $this->getBaseURL(), '$footerScripts' => $this->footerScripts, ]) . $this->page['footer']; @@ -893,114 +816,18 @@ class App public function removeBaseURL($origURL) { // Remove the hostname from the url if it is an internal link - $nurl = normalise_link($origURL); - $base = normalise_link($this->getBaseURL()); + $nurl = Util\Strings::normaliseLink($origURL); + $base = Util\Strings::normaliseLink($this->getBaseURL()); $url = str_replace($base . '/', '', $nurl); // if it is an external link return the orignal value - if ($url == normalise_link($origURL)) { + if ($url == Util\Strings::normaliseLink($origURL)) { return $origURL; } else { return $url; } } - /** - * @brief Register template engine class - * - * @param string $class - */ - private function registerTemplateEngine($class) - { - $v = get_class_vars($class); - if (!empty($v['name'])) { - $name = $v['name']; - $this->template_engines[$name] = $class; - } else { - echo "template engine $class cannot be registered without a name.\n"; - die(); - } - } - - /** - * @brief Return template engine instance. - * - * If $name is not defined, return engine defined by theme, - * or default - * - * @return object Template Engine instance - */ - public function getTemplateEngine() - { - $template_engine = defaults($this->theme, 'template_engine', 'smarty3'); - - if (isset($this->template_engines[$template_engine])) { - if (isset($this->template_engine_instance[$template_engine])) { - return $this->template_engine_instance[$template_engine]; - } else { - $class = $this->template_engines[$template_engine]; - $obj = new $class; - $this->template_engine_instance[$template_engine] = $obj; - return $obj; - } - } - - echo "template engine $template_engine is not registered!\n"; - exit(); - } - - /** - * @brief Returns the active template engine. - * - * @return string the active template engine - */ - public function getActiveTemplateEngine() - { - return $this->theme['template_engine']; - } - - /** - * sets the active template engine - * - * @param string $engine the template engine (default is Smarty3) - */ - public function setActiveTemplateEngine($engine = 'smarty3') - { - $this->theme['template_engine'] = $engine; - } - - /** - * Gets the right delimiter for a template engine - * - * Currently: - * Internal = '' - * Smarty3 = '{{' - * - * @param string $engine The template engine (default is Smarty3) - * - * @return string the right delimiter - */ - public function getTemplateLeftDelimiter($engine = 'smarty3') - { - return $this->ldelim[$engine]; - } - - /** - * Gets the left delimiter for a template engine - * - * Currently: - * Internal = '' - * Smarty3 = '}}' - * - * @param string $engine The template engine (default is Smarty3) - * - * @return string the left delimiter - */ - public function getTemplateRightDelimiter($engine = 'smarty3') - { - return $this->rdelim[$engine]; - } - /** * Saves a timestamp for a value - f.e. a call * Necessary for profiling Friendica @@ -1146,10 +973,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'], Core\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.', Core\Logger::DEBUG); return true; } } @@ -1195,7 +1022,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, Core\Logger::DEBUG); } return $reached; @@ -1225,7 +1052,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; } } @@ -1267,7 +1094,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, Core\Logger::DEBUG); return; } proc_close($resource); @@ -1298,27 +1125,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.', Core\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(), Core\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(), Core\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(), Core\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(), Core\Logger::DEBUG); return false; } @@ -1616,7 +1443,7 @@ class App // and www.example.com vs example.com. // We will only change the url to an ip address if there is no existing setting - if (empty($url) || (!link_compare($url, $this->getBaseURL())) && (!preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/", $this->getHostName()))) { + if (empty($url) || (!Util\Strings::compareLink($url, $this->getBaseURL())) && (!preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/", $this->getHostName()))) { Core\Config::set('system', 'url', $this->getBaseURL()); } } @@ -1663,40 +1490,18 @@ class App Core\Addon::callHooks('init_1'); } - $lang = Core\L10n::getBrowserLanguage(); - - Core\L10n::loadTranslationTable($lang); - - // Exclude the backend processes from the session management if (!$this->isBackend()) { $stamp1 = microtime(true); session_start(); - $this->saveTimestamp($stamp1, "parser"); + $this->saveTimestamp($stamp1, 'parser'); + Core\L10n::setSessionVariable(); + Core\L10n::setLangFromSession(); } else { $_SESSION = []; Core\Worker::executeIfIdle(); } - /* Language was set earlier, but we can over-ride it in the session. - * We have to do it here because the session was just now opened. - */ - if (!empty($_SESSION['authenticated']) && empty($_SESSION['language'])) { - $_SESSION['language'] = $lang; - // we haven't loaded user data yet, but we need user language - if (!empty($_SESSION['uid'])) { - $user = DBA::selectFirst('user', ['language'], ['uid' => $_SESSION['uid']]); - if (DBA::isResult($user)) { - $_SESSION['language'] = $user['language']; - } - } - } - - if (!empty($_SESSION['language']) && $_SESSION['language'] !== $lang) { - $lang = $_SESSION['language']; - Core\L10n::loadTranslationTable($lang); - } - // ZRL if (!empty($_GET['zrl']) && $this->getMode()->isNormal()) { $this->query_string = Model\Profile::stripZrls($this->query_string); @@ -1713,10 +1518,8 @@ 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); - header('HTTP/1.1 403 Forbidden'); - echo "