[TASK] Extract html into fluid template from info module in admin panel 59/56159/7
authorJoerg Boesche <typo3@joergboesche.de>
Thu, 15 Mar 2018 11:53:08 +0000 (12:53 +0100)
committerSusanne Moog <susanne.moog@typo3.org>
Thu, 15 Mar 2018 19:58:19 +0000 (20:58 +0100)
The info module should use a fluid template instead of
the old php-html mixed data structure.

Resolves: #84286
Releases: master
Change-Id: Idcd0a21c8f7b3410ca7e67f746d45031652dce07
Reviewed-on: https://review.typo3.org/56159
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
Reviewed-by: Tobi Kretschmann <tobi@tobishome.de>
Tested-by: Tobi Kretschmann <tobi@tobishome.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
12 files changed:
typo3/sysext/adminpanel/Classes/Modules/InfoModule.php
typo3/sysext/adminpanel/Resources/Private/Language/locallang_info.xlf [new file with mode: 0644]
typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Info/DocumentSize.html [new file with mode: 0644]
typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Info/FeUserGroupList.html [new file with mode: 0644]
typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Info/FrontendUser.html [new file with mode: 0644]
typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Info/ImagesOnPage.html [new file with mode: 0644]
typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Info/Page.html [new file with mode: 0644]
typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Info/PageCache.html [new file with mode: 0644]
typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Info/TotalParsetime.html [new file with mode: 0644]
typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Info/UserIntObjects.html [new file with mode: 0644]
typo3/sysext/adminpanel/Resources/Private/Templates/Modules/Info.html [new file with mode: 0644]
typo3/sysext/lang/Resources/Private/Language/locallang_tsfe.xlf

index c9e432d..82ba912 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-declare(strict_types=1);
+declare(strict_types = 1);
 
 namespace TYPO3\CMS\Adminpanel\Modules;
 
@@ -18,6 +18,7 @@ namespace TYPO3\CMS\Adminpanel\Modules;
 
 use TYPO3\CMS\Core\TimeTracker\TimeTracker;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Fluid\View\StandaloneView;
 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
 
 /**
@@ -33,69 +34,30 @@ class InfoModule extends AbstractModule
      */
     public function getContent(): string
     {
-        $output = [];
+        $view = GeneralUtility::makeInstance(StandaloneView::class);
+        $templateNameAndPath = $this->extResources . '/Templates/Modules/Info.html';
+        $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templateNameAndPath));
+        $view->setPartialRootPaths([$this->extResources . '/Partials']);
         $tsfe = $this->getTypoScriptFrontendController();
-        if ($this->getBackendUser()->uc['TSFE_adminConfig']['display_info']) {
-            $tableArr = [];
-            if ($this->getConfigurationOption('noCache')) {
-                $theBytes = 0;
-                $count = 0;
-                if (!empty($tsfe->imagesOnPage)) {
-                    $tableArr[] = [$this->extGetLL('info_imagesOnPage'), count($tsfe->imagesOnPage), true];
-                    foreach ($GLOBALS['TSFE']->imagesOnPage as $file) {
-                        $fs = @filesize($file);
-                        $tableArr[] = [TAB . $file, GeneralUtility::formatSize($fs)];
-                        $theBytes += $fs;
-                        $count++;
-                    }
-                }
-                // Add an empty line
-                $tableArr[] = [$this->extGetLL('info_imagesSize'), GeneralUtility::formatSize($theBytes), true];
-                $tableArr[] = [
-                    $this->extGetLL('info_DocumentSize'),
-                    GeneralUtility::formatSize(strlen($tsfe->content)),
-                    true,
-                ];
-                $tableArr[] = ['', ''];
-            }
-            $tableArr[] = [$this->extGetLL('info_id'), $tsfe->id];
-            $tableArr[] = [$this->extGetLL('info_type'), $tsfe->type];
-            $tableArr[] = [$this->extGetLL('info_groupList'), $tsfe->gr_list];
-            $tableArr[] = [
-                $this->extGetLL('info_noCache'),
-                $this->extGetLL('info_noCache_' . ($tsfe->no_cache ? 'no' : 'yes')),
-            ];
-            $tableArr[] = [$this->extGetLL('info_countUserInt'), count($tsfe->config['INTincScript'] ?? [])];
-
-            if (!empty($tsfe->fe_user->user['uid'])) {
-                $tableArr[] = [$this->extGetLL('info_feuserName'), htmlspecialchars($tsfe->fe_user->user['username'])];
-                $tableArr[] = [$this->extGetLL('info_feuserId'), htmlspecialchars($tsfe->fe_user->user['uid'])];
-            }
-
-            $tableArr[] = [
-                $this->extGetLL('info_totalParsetime'),
-                $this->getTimeTracker()->getParseTime() . ' ms',
-                true,
-            ];
-            $table = '';
-            foreach ($tableArr as $key => $arr) {
-                $label = (isset($arr[2]) ? '<strong>' . $arr[0] . '</strong>' : $arr[0]);
-                $value = (string)$arr[1] !== '' ? $arr[1] : '';
-                $table .= '
-                    <tr>
-                        <td>' . $label . '</td>
-                        <td>' . htmlspecialchars((string)$value) . '</td>
-                    </tr>';
-            }
 
-            $output[] = '<div class="typo3-adminPanel-table-overflow">';
-            $output[] = '  <table class="typo3-adminPanel-table">';
-            $output[] = '    ' . $table;
-            $output[] = '  </table>';
-            $output[] = '</div>';
-        }
+        $view->assignMultiple([
+            'info' => [
+                'pageUid' => $tsfe->id,
+                'pageType' => $tsfe->type,
+                'groupList' => $tsfe->gr_list,
+                'noCache' => $this->isNoCacheEnabled(),
+                'countUserInt' => \count($tsfe->config['INTincScript'] ?? []),
+                'totalParsetime' => $this->getTimeTracker()->getParseTime(),
+                'feUser' => [
+                    'uid' => $tsfe->fe_user->user['uid'] ?? 0,
+                    'username' => $tsfe->fe_user->user['username'] ?? ''
+                ],
+                'imagesOnPage' => $this->collectImagesOnPage(),
+                'documentSize' => $this->collectDocumentSize()
+            ]
+        ]);
 
-        return implode('', $output);
+        return $view->render();
     }
 
     /**
@@ -111,7 +73,8 @@ class InfoModule extends AbstractModule
      */
     public function getLabel(): string
     {
-        return $this->extGetLL('info');
+        $locallangFileAndPath = 'LLL:' . $this->extResources . '/Language/locallang_info.xlf:module.label';
+        return $this->getLanguageService()->sL($locallangFileAndPath);
     }
 
     /**
@@ -129,4 +92,64 @@ class InfoModule extends AbstractModule
     {
         return GeneralUtility::makeInstance(TimeTracker::class);
     }
+
+    /**
+     * Collects images from TypoScriptFrontendController and calculates the total size.
+     * Returns human readable image sizes for fluid template output
+     *
+     * @return array
+     */
+    private function collectImagesOnPage(): array
+    {
+        $imagesOnPage = [
+            'files' => [],
+            'total' => 0,
+            'totalSize' => 0,
+            'totalSizeHuman' => GeneralUtility::formatSize(0)
+        ];
+
+        if ($this->isNoCacheEnabled() === false) {
+            return $imagesOnPage;
+        }
+
+        $count = 0;
+        $totalImageSize = 0;
+        if (!empty($this->getTypoScriptFrontendController()->imagesOnPage)) {
+            foreach ($this->getTypoScriptFrontendController()->imagesOnPage as $file) {
+                $fileSize = @filesize($file);
+                $imagesOnPage['files'][] = [
+                    'name' => $file,
+                    'size' => $fileSize,
+                    'sizeHuman' => GeneralUtility::formatSize($fileSize)
+                ];
+                $totalImageSize += $fileSize;
+                $count++;
+            }
+        }
+        $imagesOnPage['totalSize'] = GeneralUtility::formatSize($totalImageSize);
+        $imagesOnPage['total'] = $count;
+        return $imagesOnPage;
+    }
+
+    /**
+     * Gets the document size from the current page in a human readable format
+     * @return string
+     */
+    private function collectDocumentSize(): string
+    {
+        $documentSize = 0;
+        if ($this->isNoCacheEnabled() === true) {
+            $documentSize = \mb_strlen($this->getTypoScriptFrontendController()->content, 'UTF-8');
+        }
+
+        return GeneralUtility::formatSize($documentSize);
+    }
+
+    /**
+     * @return bool
+     */
+    private function isNoCacheEnabled(): bool
+    {
+        return (bool)$this->getTypoScriptFrontendController()->no_cache;
+    }
 }
diff --git a/typo3/sysext/adminpanel/Resources/Private/Language/locallang_info.xlf b/typo3/sysext/adminpanel/Resources/Private/Language/locallang_info.xlf
new file mode 100644 (file)
index 0000000..80c0357
--- /dev/null
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xliff version="1.0" xmlns:t3="http://typo3.org/schemas/xliff">
+    <file t3:id="1520862805" source-language="en" datatype="plaintext" original="messages" date="2018-03-12T13:52:01Z" product-name="adminpanel">
+        <header/>
+        <body>
+            <trans-unit id="module.label">
+                <source>Info</source>
+            </trans-unit>
+            <trans-unit id="imagesOnPage">
+                <source>Images on this page</source>
+            </trans-unit>
+            <trans-unit id="imagesSize">
+                <source>Total image file sizes</source>
+            </trans-unit>
+            <trans-unit id="DocumentSize">
+                <source>Document size</source>
+            </trans-unit>
+            <trans-unit id="pageUid">
+                <source>Page Uid</source>
+            </trans-unit>
+            <trans-unit id="pageType">
+                <source>Page type</source>
+            </trans-unit>
+            <trans-unit id="groupList">
+                <source>Frontenduser group combination</source>
+            </trans-unit>
+            <trans-unit id="noCache">
+                <source>Page cached</source>
+            </trans-unit>
+            <trans-unit id="noCache_yes">
+                <source>Yes</source>
+            </trans-unit>
+            <trans-unit id="noCache_no">
+                <source>No</source>
+            </trans-unit>
+            <trans-unit id="countUserInt">
+                <source>Count of USER_INT objects</source>
+            </trans-unit>
+            <trans-unit id="feuserName">
+                <source>Name of logged in FE-User</source>
+            </trans-unit>
+            <trans-unit id="feuserId">
+                <source>Id of logged in FE-User</source>
+            </trans-unit>
+            <trans-unit id="totalParsetime">
+                <source>Total parsetime</source>
+            </trans-unit>
+        </body>
+    </file>
+</xliff>
diff --git a/typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Info/DocumentSize.html b/typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Info/DocumentSize.html
new file mode 100644 (file)
index 0000000..c86bbae
--- /dev/null
@@ -0,0 +1,7 @@
+<tr>
+    <td><strong>
+        <f:translate
+                key="LLL:EXT:adminpanel/Resources/Private/Language/locallang_info.xlf:DocumentSize"/>
+    </strong></td>
+    <td>{info.documentSize}</td>
+</tr>
diff --git a/typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Info/FeUserGroupList.html b/typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Info/FeUserGroupList.html
new file mode 100644 (file)
index 0000000..3275864
--- /dev/null
@@ -0,0 +1,6 @@
+<tr>
+    <td>
+        <f:translate key="LLL:EXT:adminpanel/Resources/Private/Language/locallang_info.xlf:groupList"/>
+    </td>
+    <td>{info.groupList}</td>
+</tr>
diff --git a/typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Info/FrontendUser.html b/typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Info/FrontendUser.html
new file mode 100644 (file)
index 0000000..08a11db
--- /dev/null
@@ -0,0 +1,14 @@
+<f:if condition="{info.feUser.uid} > 0">
+    <tr>
+        <td>
+            <f:translate key="LLL:EXT:adminpanel/Resources/Private/Language/locallang_info.xlf:feuserName"/>
+        </td>
+        <td>{info.feUser.username}</td>
+    </tr>
+    <tr>
+        <td>
+            <f:translate key="LLL:EXT:adminpanel/Resources/Private/Language/locallang_info.xlf:feuserId"/>
+        </td>
+        <td>{info.feUser.uid}</td>
+    </tr>
+</f:if>
diff --git a/typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Info/ImagesOnPage.html b/typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Info/ImagesOnPage.html
new file mode 100644 (file)
index 0000000..5e0d659
--- /dev/null
@@ -0,0 +1,24 @@
+<f:if condition="{info.imagesOnPage.total} > 0">
+    <tr>
+        <td><strong>
+            <f:translate
+                    key="LLL:EXT:adminpanel/Resources/Private/Language/locallang_info.xlf:imagesOnPage"/>
+        </strong></td>
+        <td>{info.imagesOnPage.total}</td>
+    </tr>
+
+    <f:for each="{info.imagesOnPage.files}" as="file">
+        <tr>
+            <td>&nbsp; {file.name}</td>
+            <td>{file.sizeHuman}</td>
+        </tr>
+    </f:for>
+
+    <tr>
+        <td><strong>
+            <f:translate
+                    key="LLL:EXT:adminpanel/Resources/Private/Language/locallang_info.xlf:imagesSize"/>
+        </strong></td>
+        <td>{info.imagesOnPage.totalSize}</td>
+    </tr>
+</f:if>
diff --git a/typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Info/Page.html b/typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Info/Page.html
new file mode 100644 (file)
index 0000000..a554924
--- /dev/null
@@ -0,0 +1,12 @@
+<tr>
+    <td>
+        <f:translate key="LLL:EXT:adminpanel/Resources/Private/Language/locallang_info.xlf:pageUid"/>
+    </td>
+    <td>{info.pageUid}</td>
+</tr>
+<tr>
+    <td>
+        <f:translate key="LLL:EXT:adminpanel/Resources/Private/Language/locallang_info.xlf:pageType"/>
+    </td>
+    <td>{info.pageType}</td>
+</tr>
diff --git a/typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Info/PageCache.html b/typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Info/PageCache.html
new file mode 100644 (file)
index 0000000..9c0191c
--- /dev/null
@@ -0,0 +1,9 @@
+<tr>
+    <td>
+        <f:translate key="LLL:EXT:adminpanel/Resources/Private/Language/locallang_info.xlf:noCache"/>
+    </td>
+    <td>
+        <f:translate
+                key="LLL:EXT:adminpanel/Resources/Private/Language/locallang_info.xlf:noCache_{f:if(condition:'{info.noCache}',then:'no',else:'yes')}"/>
+    </td>
+</tr>
diff --git a/typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Info/TotalParsetime.html b/typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Info/TotalParsetime.html
new file mode 100644 (file)
index 0000000..fc7cf0b
--- /dev/null
@@ -0,0 +1,6 @@
+<tr>
+    <td><strong>
+        <f:translate key="LLL:EXT:adminpanel/Resources/Private/Language/locallang_info.xlf:totalParsetime"/>
+    </strong></td>
+    <td>{info.totalParsetime} ms</td>
+</tr>
diff --git a/typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Info/UserIntObjects.html b/typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Info/UserIntObjects.html
new file mode 100644 (file)
index 0000000..7b4b390
--- /dev/null
@@ -0,0 +1,6 @@
+<tr>
+    <td>
+        <f:translate key="LLL:EXT:adminpanel/Resources/Private/Language/locallang_info.xlf:countUserInt"/>
+    </td>
+    <td>{info.countUserInt}</td>
+</tr>
diff --git a/typo3/sysext/adminpanel/Resources/Private/Templates/Modules/Info.html b/typo3/sysext/adminpanel/Resources/Private/Templates/Modules/Info.html
new file mode 100644 (file)
index 0000000..d3d9cb0
--- /dev/null
@@ -0,0 +1,18 @@
+<div class="typo3-adminPanel-table-overflow">
+    <table class="typo3-adminPanel-table">
+        <f:if condition="{info.noCache}">
+            <f:render partial="Modules/Info/ImagesOnPage" arguments="{_all}" debug="false" />
+            <f:render partial="Modules/Info/DocumentSize" arguments="{_all}" debug="false" />
+            <tr>
+                <td>&nbsp;</td>
+                <td>&nbsp;</td>
+            </tr>
+        </f:if>
+        <f:render partial="Modules/Info/Page" arguments="{_all}" debug="false" />
+        <f:render partial="Modules/Info/FeUserGroupList" arguments="{_all}" debug="false" />
+        <f:render partial="Modules/Info/PageCache" arguments="{_all}" debug="false" />
+        <f:render partial="Modules/Info/UserIntObjects" arguments="{_all}" debug="false" />
+        <f:render partial="Modules/Info/FrontendUser" arguments="{_all}" debug="false" />
+        <f:render partial="Modules/Info/TotalParsetime" arguments="{_all}" debug="false" />
+    </table>
+</div>
index 5368d88..f759873 100644 (file)
                        <trans-unit id="edit_db_list">
                                <source>Web&gt;List module</source>
                        </trans-unit>
-                       <trans-unit id="info">
-                               <source>Info</source>
+                       <trans-unit id="tsdebug">
+                               <source>TypoScript</source>
                        </trans-unit>
-                       <trans-unit id="info_imagesOnPage">
-                               <source>Images on this page</source>
+                       <trans-unit id="tsdebug_tree">
+                               <source>Tree display</source>
                        </trans-unit>
-                       <trans-unit id="info_imagesSize">
-                               <source>Total image file sizes</source>
+                       <trans-unit id="tsdebug_LR">
+                               <source>Track content rendering</source>
                        </trans-unit>
-                       <trans-unit id="info_DocumentSize">
-                               <source>Document size</source>
+                       <trans-unit id="tsdebug_forceTemplateParsing">
+                               <source>Force TS Rendering</source>
                        </trans-unit>
-                       <trans-unit id="info_id">
-                               <source>Page Uid</source>
+                       <trans-unit id="tsdebug_displayTimes">
+                               <source>Display all times</source>
                        </trans-unit>
-                       <trans-unit id="info_type">
-                               <source>Page type</source>
+                       <trans-unit id="tsdebug_displayMessages">
+                               <source>Display messages</source>
                        </trans-unit>
-                       <trans-unit id="info_groupList">
-                               <source>Frontenduser group combination</source>
-                       </trans-unit>
-                       <trans-unit id="info_noCache">
-                               <source>Page cached</source>
-                       </trans-unit>
-                       <trans-unit id="info_noCache_yes">
-                               <source>Yes</source>
-                       </trans-unit>
-                       <trans-unit id="info_noCache_no">
-                               <source>No</source>
-                       </trans-unit>
-                       <trans-unit id="info_countUserInt">
-                               <source>Count of USER_INT objects</source>
-                       </trans-unit>
-                       <trans-unit id="info_feuserName">
-                               <source>Name of logged in FE-User</source>
-                       </trans-unit>
-                       <trans-unit id="info_feuserId">
-                               <source>Id of logged in FE-User</source>
-                       </trans-unit>
-                       <trans-unit id="info_totalParsetime">
-                               <source>Total parsetime</source>
+                       <trans-unit id="tsdebug_displayContent">
+                               <source>Display content</source>
                        </trans-unit>
+
                        <trans-unit id="update">
                                <source>Update</source>
                        </trans-unit>