use DOMXPath;
use Friendica\App;
use Friendica\Content\Nav;
-use Friendica\Core\Config\Configuration;
-use Friendica\Core\Config\PConfiguration;
+use Friendica\Core\Config\IConfiguration;
+use Friendica\Core\Config\IPConfiguration;
use Friendica\Core\Hook;
use Friendica\Core\L10n\L10n;
use Friendica\Core\Renderer;
use Friendica\Core\Theme;
use Friendica\Module\Special\HTTPException as ModuleHTTPException;
use Friendica\Network\HTTPException;
+use Friendica\Util\Strings;
/**
* Contains the page specific environment variables for the current Page
/**
* @var array Contains all stylesheets, which should get loaded during page
*/
- private $stylesheets;
+ private $stylesheets = [];
/**
* @var array Contains all scripts, which are added to the footer at last
*/
- private $footerScripts;
+ private $footerScripts = [];
/**
* @var array The page content, which are showed directly
*/
- private $page;
+ private $page = [
+ 'aside' => '',
+ 'bottom' => '',
+ 'content' => '',
+ 'footer' => '',
+ 'htmlhead' => '',
+ 'nav' => '',
+ 'page_title' => '',
+ 'right_aside' => '',
+ 'template' => '',
+ 'title' => '',
+ ];
/**
* @var string The basepath of the page
*/
public function __construct(string $basepath)
{
$this->basePath = $basepath;
-
- $this->page = [
- 'aside' => '',
- 'bottom' => '',
- 'content' => '',
- 'footer' => '',
- 'htmlhead' => '',
- 'nav' => '',
- 'page_title' => '',
- 'right_aside' => '',
- 'template' => '',
- 'title' => ''
- ];
}
/**
* @param App $app The Friendica App instance
* @param Module $module The loaded Friendica module
* @param L10n $l10n The l10n language instance
- * @param Configuration $config The Friendica configuration
- * @param PConfiguration $pConfig The Friendica personal configuration (for user)
+ * @param IConfiguration $config The Friendica configuration
+ * @param IPConfiguration $pConfig The Friendica personal configuration (for user)
*
* @throws HTTPException\InternalServerErrorException
*/
- private function initHead(App $app, Module $module, L10n $l10n, Configuration $config, PConfiguration $pConfig)
+ private function initHead(App $app, Module $module, L10n $l10n, IConfiguration $config, IPConfiguration $pConfig)
{
$interval = ((local_user()) ? $pConfig->get(local_user(), 'system', 'update_interval') : 40000);
* being first
*/
$this->page['htmlhead'] = Renderer::replaceMacros($tpl, [
- '$local_user' => local_user(),
- '$generator' => 'Friendica' . ' ' . FRIENDICA_VERSION,
- '$delitem' => $l10n->t('Delete this item?'),
- '$update_interval' => $interval,
- '$shortcut_icon' => $shortcut_icon,
- '$touch_icon' => $touch_icon,
- '$block_public' => intval($config->get('system', 'block_public')),
- '$stylesheets' => $this->stylesheets,
- ]) . $this->page['htmlhead'];
+ '$local_user' => local_user(),
+ '$generator' => 'Friendica' . ' ' . FRIENDICA_VERSION,
+ '$delitem' => $l10n->t('Delete this item?'),
+ '$update_interval' => $interval,
+ '$shortcut_icon' => $shortcut_icon,
+ '$touch_icon' => $touch_icon,
+ '$block_public' => intval($config->get('system', 'block_public')),
+ '$stylesheets' => array_unique($this->stylesheets),
+ ]) . $this->page['htmlhead'];
}
/**
* - footer.tpl template
*
* @param App $app The Friendica App instance
+ * @param Mode $mode The Friendica runtime mode
* @param L10n $l10n The l10n instance
*
* @throws HTTPException\InternalServerErrorException
*/
- private function initFooter(App $app, L10n $l10n)
+ private function initFooter(App $app, Mode $mode, L10n $l10n)
{
// If you're just visiting, let javascript take you home
if (!empty($_SESSION['visitor_home'])) {
/*
* Add a "toggle mobile" link if we're using a mobile device
*/
- if ($app->is_mobile || $app->is_tablet) {
+ if ($mode->isMobile() || $mode->isTablet()) {
if (isset($_SESSION['show-mobile']) && !$_SESSION['show-mobile']) {
$link = 'toggle_mobile?address=' . urlencode(curPageURL());
} else {
$tpl = Renderer::getMarkupTemplate('footer.tpl');
$this->page['footer'] = Renderer::replaceMacros($tpl, [
- '$footerScripts' => $this->footerScripts,
- ]) . $this->page['footer'];
+ '$footerScripts' => array_unique($this->footerScripts),
+ ]) . $this->page['footer'];
}
/**
$arr = ['content' => $content];
Hook::callAll($moduleClass . '_mod_content', $arr);
$content = $arr['content'];
- $arr = ['content' => call_user_func([$moduleClass, 'content'])];
+ $arr = ['content' => call_user_func([$moduleClass, 'content'], $module->getParameters())];
Hook::callAll($moduleClass . '_mod_aftercontent', $arr);
$content .= $arr['content'];
} catch (HTTPException $e) {
* @param Mode $mode The current node mode
* @param Module $module The loaded Friendica module
* @param L10n $l10n The l10n language class
- * @param Configuration $config The Configuration of this node
- * @param PConfiguration $pconfig The personal/user configuration
+ * @param IConfiguration $config The Configuration of this node
+ * @param IPConfiguration $pconfig The personal/user configuration
*
* @throws HTTPException\InternalServerErrorException
*/
- public function run(App $app, BaseURL $baseURL, Mode $mode, Module $module, L10n $l10n, Configuration $config, PConfiguration $pconfig)
+ public function run(App $app, BaseURL $baseURL, Mode $mode, Module $module, L10n $l10n, IConfiguration $config, IPConfiguration $pconfig)
{
$moduleName = $module->getName();
- // Initialize module that can set the current theme in the init() method, either directly or via App->profile_uid
- $this->page['page_title'] = $moduleName;
-
/* Create the page content.
* Calls all hooks which are including content operations
*
*/
$this->initContent($module, $mode);
+ // Load current theme info after module has been initialized as theme could have been set in module
+ $currentTheme = $app->getCurrentTheme();
+ $theme_info_file = 'view/theme/' . $currentTheme . '/theme.php';
+ if (file_exists($theme_info_file)) {
+ require_once $theme_info_file;
+ }
+
+ if (function_exists(str_replace('-', '_', $currentTheme) . '_init')) {
+ $func = str_replace('-', '_', $currentTheme) . '_init';
+ $func($app);
+ }
+
/* Create the page head after setting the language
* and getting any auth credentials.
*
/* Build the page ending -- this is stuff that goes right before
* the closing </body> tag
*/
- $this->initFooter($app, $l10n);
+ $this->initFooter($app, $mode, $l10n);
- if (!$app->isAjax()) {
+ if (!$mode->isAjax()) {
Hook::callAll('page_end', $this->page['content']);
}
* to load another page template than the default one.
* The page templates are located in /view/php/ or in the theme directory.
*/
- if (isset($_GET["mode"])) {
- $template = Theme::getPathForFile($_GET["mode"] . '.php');
+ if (isset($_GET['mode'])) {
+ $template = Theme::getPathForFile('php/' . Strings::sanitizeFilePathItem($_GET['mode']) . '.php');
}
// If there is no page template use the default page template
if (empty($template)) {
- $template = Theme::getPathForFile("default.php");
+ $template = Theme::getPathForFile('php/default.php');
}
// Theme templates expect $a as an App instance
- $a = $this;
+ $a = $app;
// Used as is in view/php/default.php
$lang = $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;
}
}