hasRequestParameter('uri')) { throw new common_exception_MissingParameter('uri', __METHOD__); } if (!$this->hasRequestParameter('stylesheetUri')) { throw new common_exception_MissingParameter('stylesheetUri', __METHOD__); } if (!$this->hasRequestParameter('lang')) { throw new common_exception_MissingParameter('lang', __METHOD__); } $item = new \core_kernel_classes_Resource($this->getRequestParameter('uri')); $lang = $this->getRequestParameter('lang'); $styleSheet = $this->getRequestParameter('stylesheetUri'); if (!\tao_helpers_File::securityCheck($styleSheet, true)) { throw new \common_exception_Error('invalid stylesheet path "' . $styleSheet . '"'); } $css = $this->getCssArray(); CssHelper::saveCssFile($item, $lang, $styleSheet, $css); } /** * Load the custom styles as JSON * * @throws \common_exception_IsAjaxAction * @throws \common_exception_MissingParameter */ public function load() { if (!$this->hasRequestParameter('uri')) { throw new common_exception_MissingParameter('uri', __METHOD__); } if (!$this->hasRequestParameter('stylesheetUri')) { throw new common_exception_MissingParameter('stylesheetUri', __METHOD__); } if (!$this->hasRequestParameter('lang')) { throw new common_exception_MissingParameter('lang', __METHOD__); } $item = new \core_kernel_classes_Resource($this->getRequestParameter('uri')); $lang = $this->getRequestParameter('lang'); $styleSheet = $this->getRequestParameter('stylesheetUri'); if (!\tao_helpers_File::securityCheck($styleSheet, true)) { throw new \common_exception_Error('invalid stylesheet path "' . $styleSheet . '"'); } $cssArray = CssHelper::loadCssFile($item, $lang, $styleSheet); $this->returnJson($cssArray); } /** * Convert CSS JSON to array * * @return mixed * @throws \common_exception_MissingParameter * @throws \common_exception_InvalidArgumentType */ private function getCssArray() { if (!$this->hasRequestParameter('cssJson')) { throw new common_exception_MissingParameter('cssJson', __CLASS__ . '::' . \Context::getInstance()->getActionName()); } $cssArr = json_decode($_POST['cssJson'], true); if (!is_array($cssArr)) { throw new common_exception_InvalidArgumentType(__CLASS__, \Context::getInstance()->getActionName(), 0, 'json encoded array'); } return $cssArr; } /** * Download custom styles */ public function download() { if (!$this->hasRequestParameter('uri')) { throw new common_exception_MissingParameter('uri', __METHOD__); } if (!$this->hasRequestParameter('stylesheetUri')) { throw new common_exception_MissingParameter('stylesheetUri', __METHOD__); } if (!$this->hasRequestParameter('lang')) { throw new common_exception_MissingParameter('lang', __METHOD__); } $item = new \core_kernel_classes_Resource($this->getRequestParameter('uri')); $lang = $this->getRequestParameter('lang'); $styleSheet = $this->getRequestParameter('stylesheetUri'); if (!\tao_helpers_File::securityCheck($styleSheet, true)) { throw new \common_exception_Error('invalid stylesheet path "' . $styleSheet . '"'); } header('Set-Cookie: fileDownload=true'); setcookie('fileDownload', 'true', 0, '/'); header('Content-type: application/octet-stream'); header(sprintf('Content-Disposition: attachment; filename=%s', basename($styleSheet))); echo CssHelper::downloadCssFile($item, $lang, $styleSheet); } }