*/
class App
{
- const MODE_LOCALCONFIGPRESENT = 1;
- const MODE_DBAVAILABLE = 2;
- const MODE_DBCONFIGAVAILABLE = 4;
- const MODE_MAINTENANCEDISABLED = 8;
-
- /**
- * @deprecated since version 2008.08 Use App->isInstallMode() instead to check for install mode.
- */
- const MODE_INSTALL = 0;
-
- /**
- * @deprecated since version 2008.08 Use the precise mode constant to check for a specific capability instead.
- */
- const MODE_NORMAL = App::MODE_LOCALCONFIGPRESENT | App::MODE_DBAVAILABLE | App::MODE_DBCONFIGAVAILABLE | App::MODE_MAINTENANCEDISABLED;
-
public $module_loaded = false;
public $module_class = null;
public $query_string = '';
public $argv;
public $argc;
public $module;
- public $mode = App::MODE_INSTALL;
public $strings;
public $basepath;
public $urlpath;
public $force_max_items = 0;
public $theme_events_in_profile = true;
+ public $stylesheets = [];
+ public $footerScripts = [];
+
+ /**
+ * Register a stylesheet file path to be included in the <head> tag of every page.
+ * Inclusion is done in App->initHead().
+ * The path can be absolute or relative to the Friendica installation base folder.
+ *
+ * @see App->initHead()
+ *
+ * @param string $path
+ */
+ public function registerStylesheet($path)
+ {
+ $url = str_replace($this->get_basepath() . DIRECTORY_SEPARATOR, '', $path);
+
+ $this->stylesheets[] = trim($url, '/');
+ }
+
+ /**
+ * Register a javascript file path to be included in the <footer> tag of every page.
+ * Inclusion is done in App->initFooter().
+ * The path can be absolute or relative to the Friendica installation base folder.
+ *
+ * @see App->initFooter()
+ *
+ * @param string $path
+ */
+ public function registerFooterScript($path)
+ {
+ $url = str_replace($this->get_basepath() . DIRECTORY_SEPARATOR, '', $path);
+
+ $this->footerScripts[] = trim($url, '/');
+ }
+
/**
* @brief An array for all theme-controllable parameters
*
$this->loadDatabase();
- $this->determineMode();
+ App\Mode::determine($this->basepath);
$this->determineUrlPath();
Config::load();
- if ($this->mode & self::MODE_DBAVAILABLE) {
+ if (App\Mode::has(App\Mode::DBAVAILABLE)) {
Core\Addon::loadHooks();
$this->loadAddonConfig();
'aside' => '',
'bottom' => '',
'content' => '',
- 'end' => '',
'footer' => '',
'htmlhead' => '',
'nav' => '',
}
}
- /**
- * Sets the App mode
- *
- * - App::MODE_INSTALL : Either the database connection can't be established or the config table doesn't exist
- * - App::MODE_MAINTENANCE: The maintenance mode has been set
- * - App::MODE_NORMAL : Normal run with all features enabled
- *
- * @return type
- */
- private function determineMode()
- {
- $this->mode = 0;
-
- if (!file_exists($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php')
- && !file_exists($this->basepath . DIRECTORY_SEPARATOR . '.htconfig.php')) {
- return;
- }
-
- $this->mode |= App::MODE_LOCALCONFIGPRESENT;
-
- if (!DBA::connected()) {
- return;
- }
-
- $this->mode |= App::MODE_DBAVAILABLE;
-
- if (DBA::fetchFirst("SHOW TABLES LIKE 'config'") === false) {
- return;
- }
-
- $this->mode |= App::MODE_DBCONFIGAVAILABLE;
-
- if (Config::get('system', 'maintenance')) {
- return;
- }
-
- $this->mode |= App::MODE_MAINTENANCEDISABLED;
- }
-
public function loadDatabase()
{
if (DBA::connected()) {
$this->save_timestamp($stamp1, 'network');
}
- /**
- * Install mode is when the local config file is missing or the DB schema hasn't been installed yet.
- *
- * @return bool
- */
- public function isInstallMode()
- {
- return !($this->mode & App::MODE_LOCALCONFIGPRESENT) || !($this->mode & App::MODE_DBCONFIGAVAILABLE);
- }
-
/**
* @brief Returns the base filesystem path of the App
*
$this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
}
- public function init_pagehead()
+ /**
+ * Initializes App->page['htmlhead'].
+ *
+ * Includes:
+ * - Page title
+ * - Favicons
+ * - Registered stylesheets (through App->registerStylesheet())
+ * - Infinite scroll data
+ * - head.tpl template
+ */
+ public function initHead()
{
$interval = ((local_user()) ? PConfig::get(local_user(), 'system', 'update_interval') : 40000);
$this->page['title'] = $this->config['sitename'];
}
- /* put the head template at the beginning of page['htmlhead']
- * since the code added by the modules frequently depends on it
- * being first
- */
- if (!isset($this->page['htmlhead'])) {
- $this->page['htmlhead'] = '';
- }
-
- // If we're using Smarty, then doing replace_macros() will replace
- // any unrecognized variables with a blank string. Since we delay
- // replacing $stylesheet until later, we need to replace it now
- // with another variable name
- if ($this->theme['template_engine'] === 'smarty3') {
- $stylesheet = $this->get_template_ldelim('smarty3') . '$stylesheet' . $this->get_template_rdelim('smarty3');
+ if (!empty($this->theme['stylesheet'])) {
+ $stylesheet = $this->theme['stylesheet'];
} else {
- $stylesheet = '$stylesheet';
+ $stylesheet = $this->getCurrentThemeStylesheetPath();
}
+ $this->registerStylesheet($stylesheet);
+
$shortcut_icon = Config::get('system', 'shortcut_icon');
if ($shortcut_icon == '') {
$shortcut_icon = 'images/friendica-32.png';
}
// get data wich is needed for infinite scroll on the network page
- $invinite_scroll = infinite_scroll_data($this->module);
+ $infinite_scroll = infinite_scroll_data($this->module);
+
+ Core\Addon::callHooks('head', $this->page['htmlhead']);
$tpl = get_markup_template('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, [
'$baseurl' => $this->get_baseurl(),
'$local_user' => local_user(),
'$update_interval' => $interval,
'$shortcut_icon' => $shortcut_icon,
'$touch_icon' => $touch_icon,
- '$stylesheet' => $stylesheet,
- '$infinite_scroll' => $invinite_scroll,
+ '$infinite_scroll' => $infinite_scroll,
'$block_public' => intval(Config::get('system', 'block_public')),
+ '$stylesheets' => $this->stylesheets,
]) . $this->page['htmlhead'];
}
- public function init_page_end()
+ /**
+ * Initializes App->page['footer'].
+ *
+ * Includes:
+ * - Javascript homebase
+ * - Mobile toggle link
+ * - Registered footer scripts (through App->registerFooterScript())
+ * - footer.tpl template
+ */
+ public function initFooter()
{
- if (!isset($this->page['end'])) {
- $this->page['end'] = '';
+ // If you're just visiting, let javascript take you home
+ if (!empty($_SESSION['visitor_home'])) {
+ $homebase = $_SESSION['visitor_home'];
+ } elseif (local_user()) {
+ $homebase = 'profile/' . $this->user['nickname'];
}
- $tpl = get_markup_template('end.tpl');
- $this->page['end'] = replace_macros($tpl, [
- '$baseurl' => $this->get_baseurl()
- ]) . $this->page['end'];
+
+ if (isset($homebase)) {
+ $this->page['footer'] .= '<script>var homebase="' . $homebase . '";</script>' . "\n";
+ }
+
+ /*
+ * Add a "toggle mobile" link if we're using a mobile device
+ */
+ if ($this->is_mobile || $this->is_tablet) {
+ if (isset($_SESSION['show-mobile']) && !$_SESSION['show-mobile']) {
+ $link = 'toggle_mobile?address=' . curPageURL();
+ } else {
+ $link = 'toggle_mobile?off=1&address=' . curPageURL();
+ }
+ $this->page['footer'] .= replace_macros(get_markup_template("toggle_mobile_footer.tpl"), [
+ '$toggle_link' => $link,
+ '$toggle_text' => Core\L10n::t('toggle mobile')
+ ]);
+ }
+
+ Core\Addon::callHooks('footer', $this->page['footer']);
+
+ $tpl = get_markup_template('footer.tpl');
+ $this->page['footer'] = replace_macros($tpl, [
+ '$baseurl' => $this->get_baseurl(),
+ '$footerScripts' => $this->footerScripts,
+ ]) . $this->page['footer'];
}
public function set_curl_code($code)
*/
public function getCurrentTheme()
{
- if ($this->isInstallMode()) {
+ if (App\Mode::isInstall()) {
return '';
}