X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=inline;f=src%2FApp.php;h=445101309384a2f651b46fd69f78b507835538a4;hb=4894e89f036be1f8a82523ac69d56ae36e7685df;hp=9fb63ce6792e1d1f21b13cad6663adc239b24fc8;hpb=dfbaa6e198d26bf1e921bae62923a820bef7925d;p=friendica.git
diff --git a/src/App.php b/src/App.php
index 9fb63ce679..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;
@@ -138,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;
@@ -303,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();
@@ -321,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');
}
/**
@@ -517,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');
@@ -732,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'].
*
@@ -780,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();
}
@@ -798,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,
@@ -818,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'];
@@ -851,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')
]);
@@ -863,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'];
@@ -880,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
@@ -1133,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;
}
}
@@ -1182,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;
@@ -1212,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;
}
}
@@ -1254,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);
@@ -1285,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;
}
@@ -1603,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());
}
}
@@ -1678,7 +1518,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'], Core\Logger::DEBUG);
Core\System::httpExit(403, ['title' => '403 Forbidden']);
}
}
@@ -1714,7 +1554,7 @@ class App
$this->module = 'maintenance';
} else {
$this->checkURL();
- check_db(false);
+ Core\Update::check(false);
Core\Addon::loadAddons();
Core\Hook::loadHooks();
}
@@ -1817,15 +1657,15 @@ 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'], Core\Logger::DEBUG);
header($_SERVER["SERVER_PROTOCOL"] . ' 404 ' . Core\L10n::t('Not Found'));
- $tpl = get_markup_template("404.tpl");
- $this->page['content'] = replace_macros($tpl, [
+ $tpl = Core\Renderer::getMarkupTemplate("404.tpl");
+ $this->page['content'] = Core\Renderer::replaceMacros($tpl, [
'$message' => Core\L10n::t('Page not found.')
]);
}
@@ -1913,7 +1753,7 @@ class App
// Add the navigation (menu) template
if ($this->module != 'install' && $this->module != 'maintenance') {
- $this->page['htmlhead'] .= replace_macros(get_markup_template('nav_head.tpl'), []);
+ $this->page['htmlhead'] .= Core\Renderer::replaceMacros(Core\Renderer::getMarkupTemplate('nav_head.tpl'), []);
$this->page['nav'] = Content\Nav::build($this);
}
@@ -1984,6 +1824,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;
}