]> git.mxchange.org Git - friendica.git/blobdiff - src/App/Page.php
Creating interfaces for Config/PConfig & fix tests
[friendica.git] / src / App / Page.php
index ea94f9cfef6a73ba37d7bdc08c206ec243447924..5efb9f7ca3d64deae2f9fd1da93fce07964395d4 100644 (file)
@@ -7,14 +7,15 @@ use DOMDocument;
 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
@@ -29,15 +30,26 @@ class Page implements ArrayAccess
        /**
         * @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
         */
@@ -49,19 +61,6 @@ class Page implements ArrayAccess
        public function __construct(string $basepath)
        {
                $this->basePath = $basepath;
-
-               $this->page = [
-                       'aside'       => '',
-                       'bottom'      => '',
-                       'content'     => '',
-                       'footer'      => '',
-                       'htmlhead'    => '',
-                       'nav'         => '',
-                       'page_title'  => '',
-                       'right_aside' => '',
-                       'template'    => '',
-                       'title'       => ''
-               ];
        }
 
        /**
@@ -172,12 +171,12 @@ class Page implements ArrayAccess
         * @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);
 
@@ -224,15 +223,15 @@ class Page implements ArrayAccess
                 * 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'];
        }
 
        /**
@@ -282,8 +281,8 @@ class Page implements ArrayAccess
 
                $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'];
        }
 
        /**
@@ -308,7 +307,7 @@ class Page implements ArrayAccess
                        $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) {
@@ -348,12 +347,12 @@ class Page implements ArrayAccess
         * @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();
 
@@ -455,13 +454,13 @@ class Page implements ArrayAccess
                 * 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
@@ -470,7 +469,6 @@ class Page implements ArrayAccess
                // 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;
        }
 }