diff --git a/pages/ajax.document.php b/pages/ajax.document.php index de526f027..b9b1d96ee 100644 --- a/pages/ajax.document.php +++ b/pages/ajax.document.php @@ -35,7 +35,7 @@ try require_once(APPROOT.'/application/loginwebpage.class.inc.php'); - $oPage = new AjaxPage(""); + $oPage = new DownloadPage(""); $operation = utils::ReadParam('operation', ''); $sClass = utils::ReadParam('class', 'MissingAjaxParam', false, 'class'); @@ -88,10 +88,8 @@ try case 'dict': $sSignature = Utils::ReadParam('s', ''); // Sanitization prevents / and .. - $oPage = new AjaxPage(""); // New page to cleanup the no_cache done above $oPage->SetContentType('text/javascript'); - $oPage->add_header('Cache-control: public, max-age=86400'); // Cache for 24 hours - $oPage->add_header("Pragma: cache"); // Reset the value set .... where ? + $oPage->set_cache(86400); // Cache for 24 hours // X-Frame http header : set in page constructor, but we need to allow frame integration for this specific page // so we're resetting its value ! (see N°3416) diff --git a/pages/ajax.render.php b/pages/ajax.render.php index 15fd427e0..a0e3e1a87 100644 --- a/pages/ajax.render.php +++ b/pages/ajax.render.php @@ -1943,12 +1943,12 @@ EOF break; case 'xlsx_download': - $oPage = new DownloadPage(); + $oPage = new DownloadPage(''); $sToken = utils::ReadParam('token', '', false, 'raw_data'); $oPage->SetContentType('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); $oPage->SetContentDisposition('attachment', 'export.xlsx'); $sFileContent = ExcelExporter::GetExcelFileFromToken($sToken); - $oPage->SetContent($sFileContent); + $oPage->add($sFileContent); ExcelExporter::CleanupFromToken($sToken); break; @@ -2331,10 +2331,10 @@ EOF if (substr($sMimeType, 0, 5) == 'text/') { $sMimeType .= ';charset='.strtolower($oExporter->GetCharacterSet()); } - $oPage = new DownloadPage(); + $oPage = new DownloadPage(''); $oPage->SetContentType($sMimeType); $oPage->SetContentDisposition('attachment', $oExporter->GetDownloadFileName()); - $oPage->SetContent(file_get_contents($oExporter->GetTmpFilePath())); + $oPage->add(file_get_contents($oExporter->GetTmpFilePath())); } } break; diff --git a/sources/application/WebPage/AjaxPage.php b/sources/application/WebPage/AjaxPage.php index 6b2517fb3..c4ae2a94a 100644 --- a/sources/application/WebPage/AjaxPage.php +++ b/sources/application/WebPage/AjaxPage.php @@ -5,7 +5,6 @@ */ use Combodo\iTop\Application\TwigBase\Twig\TwigHelper; -use Combodo\iTop\Application\UI\Base\iUIBlock; use Combodo\iTop\Application\UI\Base\Layout\iUIContentBlock; use Combodo\iTop\Renderer\BlockRenderer; use Combodo\iTop\Renderer\Console\ConsoleBlockRenderer; @@ -293,14 +292,13 @@ EOF * @inheritDoc * @throws \Exception */ - public function add($sHtml): ?iUIBlock + public function add($sHtml) { if (($this->m_oTabs->GetCurrentTabContainer() != '') && ($this->m_oTabs->GetCurrentTab() != '')) { $this->m_oTabs->AddToTab($this->m_oTabs->GetCurrentTabContainer(), $this->m_oTabs->GetCurrentTab(), $sHtml); } else { - return parent::add($sHtml); + parent::add($sHtml); } - return null; } /** diff --git a/sources/application/WebPage/CLIPage.php b/sources/application/WebPage/CLIPage.php index a403b20d3..8528af113 100644 --- a/sources/application/WebPage/CLIPage.php +++ b/sources/application/WebPage/CLIPage.php @@ -16,8 +16,6 @@ // You should have received a copy of the GNU Affero General Public License // along with iTop. If not, see -use \Combodo\iTop\Application\UI\Base\iUIBlock; - /** * CLI page * The page adds the content-type text/XML and the encoding into the headers @@ -39,20 +37,17 @@ class CLIPage implements Page public function output() { - if (class_exists('DBSearch')) - { - DBSearch::RecordQueryTrace(); - } - if (class_exists('ExecutionKPI')) - { - ExecutionKPI::ReportStats(); - } + if (class_exists('DBSearch')) { + DBSearch::RecordQueryTrace(); + } + if (class_exists('ExecutionKPI')) { + ExecutionKPI::ReportStats(); + } } - public function add($sText): ?iUIBlock + public function add($sText) { echo $sText; - return null; } public function p($sText) diff --git a/sources/application/WebPage/CSVPage.php b/sources/application/WebPage/CSVPage.php index b73df8343..ab8b3465e 100644 --- a/sources/application/WebPage/CSVPage.php +++ b/sources/application/WebPage/CSVPage.php @@ -16,8 +16,6 @@ // You should have received a copy of the GNU Affero General Public License // along with iTop. If not, see -use Combodo\iTop\Application\UI\Base\iUIBlock; - /** * Simple web page with no includes or fancy formatting, useful to generateXML documents * The page adds the content-type text/XML and the encoding into the headers @@ -56,26 +54,24 @@ class CSVPage extends WebPage { DBSearch::RecordQueryTrace(); } - if (class_exists('ExecutionKPI')) - { - ExecutionKPI::ReportStats(); - } + if (class_exists('ExecutionKPI')) { + ExecutionKPI::ReportStats(); + } } public function small_p($sText) { } - public function add($sText): ?iUIBlock + public function add($sText) { $this->s_content .= $sText; - return null; - } + } public function p($sText) { $this->s_content .= $sText."\n"; - } + } public function add_comment($sText) { diff --git a/sources/application/WebPage/DownloadPage.php b/sources/application/WebPage/DownloadPage.php index 799e222a0..643473597 100644 --- a/sources/application/WebPage/DownloadPage.php +++ b/sources/application/WebPage/DownloadPage.php @@ -5,68 +5,37 @@ */ -class DownloadPage +class DownloadPage extends AjaxPage { - /** @var string */ - protected $sContentType; - /** @var string */ - protected $sContentDisposition; /**@var string */ protected $sContent; - /** - * @var string - */ - protected $sContentFileName; - /** - * @param string $sContentType - * - * @return $this - */ - public function SetContentType(string $sContentType) + public function __construct($s_title) { - $this->sContentType = $sContentType; - - return $this; - } - - /** - * Set the content-disposition (mime type) for the page's content - * - * @param $sDisposition string The disposition: 'inline' or 'attachment' - * @param $sFileName string The original name of the file - * - * @return $this - */ - public function SetContentDisposition($sDisposition, $sFileName) - { - $this->sContentDisposition = $sDisposition; - $this->sContentFileName = $sFileName; - - return $this; + parent::__construct($s_title); } /** * @param string $sContent * - * @return $this */ - public function SetContent(string $sContent) + public function add($sContent) { $this->sContent = $sContent; - - return $this; } public function output() { if (!empty($this->sContentType)) { - header('Content-type: '.$this->sContentType); + $this->add_header('Content-type: '.$this->sContentType); } if (!empty($this->sContentDisposition)) { - header('Content-Disposition: '.$this->sContentDisposition.'; filename="'.$this->sContentFileName.'"'); + $this->add_header('Content-Disposition: '.$this->sContentDisposition.'; filename="'.$this->sContentFileName.'"'); } + foreach ($this->a_headers as $s_header) { + header($s_header); + } + echo $this->sContent; } - } diff --git a/sources/application/WebPage/Page.php b/sources/application/WebPage/Page.php index 923376939..8d8d748c7 100644 --- a/sources/application/WebPage/Page.php +++ b/sources/application/WebPage/Page.php @@ -4,8 +4,6 @@ * @license http://opensource.org/licenses/AGPL-3.0 */ -use Combodo\iTop\Application\UI\Base\iUIBlock; - /** * Generic interface common to CLI and Web pages @@ -26,7 +24,7 @@ interface Page * * @return void */ - public function add($sText): ?iUIBlock; + public function add($sText); /** * Add a paragraph to the body of the page diff --git a/sources/application/WebPage/WebPage.php b/sources/application/WebPage/WebPage.php index a74d384d1..28681b16a 100644 --- a/sources/application/WebPage/WebPage.php +++ b/sources/application/WebPage/WebPage.php @@ -202,9 +202,9 @@ class WebPage implements Page /** * @inheritDoc */ - public function add($s_html): ?iUIBlock + public function add($s_html) { - return $this->oContentLayout->AddHtml($s_html); + $this->oContentLayout->AddHtml($s_html); } /** @@ -1172,7 +1172,7 @@ class WebPage implements Page * * @return void */ - public function SetContentType($sContentType) + public function SetContentType(string $sContentType) { $this->sContentType = $sContentType; } diff --git a/sources/application/WebPage/XMLPage.php b/sources/application/WebPage/XMLPage.php index 3d9a81f4d..7a28a8ce7 100644 --- a/sources/application/WebPage/XMLPage.php +++ b/sources/application/WebPage/XMLPage.php @@ -16,8 +16,6 @@ // You should have received a copy of the GNU Affero General Public License // along with iTop. If not, see -use Combodo\iTop\Application\UI\Base\iUIBlock; - /** * Class XMLPage * @@ -64,22 +62,17 @@ class XMLPage extends WebPage } echo $this->s_content; } - if (class_exists('DBSearch')) - { + if (class_exists('DBSearch')) { DBSearch::RecordQueryTrace(); } } - public function add($sText): ?iUIBlock + public function add($sText) { - if (!$this->m_bPassThrough) - { + if (!$this->m_bPassThrough) { parent::add($sText); - } - else - { - if ($this->m_bHeaderSent) - { + } else { + if ($this->m_bHeaderSent) { echo $sText; } else @@ -97,7 +90,6 @@ class XMLPage extends WebPage $this->m_bHeaderSent = true; } } - return null; } public function small_p($sText) diff --git a/sources/application/WebPage/iTopWebPage.php b/sources/application/WebPage/iTopWebPage.php index e88f65803..3148348f7 100644 --- a/sources/application/WebPage/iTopWebPage.php +++ b/sources/application/WebPage/iTopWebPage.php @@ -1092,14 +1092,13 @@ EOF * @inheritDoc * @throws \Exception */ - public function add($sHtml): ?iUIBlock + public function add($sHtml) { if (($this->m_oTabs->GetCurrentTabContainer() != '') && ($this->m_oTabs->GetCurrentTab() != '')) { $this->m_oTabs->AddToCurrentTab($sHtml); } else { - return parent::add($sHtml); + parent::add($sHtml); } - return null; } public function AddUiBlock(?iUIBlock $oBlock): ?iUIBlock