/**
     * Main function, redering the actual content of the editing page
     *
     * @return void
     */
    public function main()
    {
        $this->getButtons();
        // Hook	before compiling the output
        if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['preOutputProcessingHook'])) {
            $preOutputProcessingHook =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['preOutputProcessingHook'];
            if (is_array($preOutputProcessingHook)) {
                $hookParameters = array('content' => &$this->content, 'target' => &$this->target);
                foreach ($preOutputProcessingHook as $hookFunction) {
                    GeneralUtility::callUserFunction($hookFunction, $hookParameters, $this);
                }
            }
        }
        $pageContent = '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('tce_file')) . '" method="post" id="EditFileController" name="editform">';
        $pageContent .= '<h1>' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_edit.php.pagetitle') . ' ' . htmlspecialchars($this->fileObject->getName()) . '</h1>';
        $code = '';
        $extList = $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'];
        try {
            if (!$extList || !GeneralUtility::inList($extList, $this->fileObject->getExtension())) {
                throw new \Exception('Files with that extension are not editable.');
            }
            // Read file content to edit:
            $fileContent = $this->fileObject->getContents();
            // Making the formfields
            $hValue = BackendUtility::getModuleUrl('file_edit', array('target' => $this->origTarget, 'returnUrl' => $this->returnUrl));
            $code .= '
                <div id="c-edit">
					<textarea rows="30" name="file[editfile][0][data]" wrap="off"  class="form-control text-monospace t3js-enable-tab">' . htmlspecialchars($fileContent) . '</textarea>
					<input type="hidden" name="file[editfile][0][target]" value="' . $this->fileObject->getUid() . '" />
					<input type="hidden" name="redirect" value="' . htmlspecialchars($hValue) . '" />
				</div>
				<br />';
        } catch (\Exception $e) {
            $code .= sprintf($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_edit.php.coundNot'), $extList);
        }
        // Ending of section and outputting editing form:
        $pageContent .= $code;
        // Hook	after compiling the output
        if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['postOutputProcessingHook'])) {
            $postOutputProcessingHook =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['postOutputProcessingHook'];
            if (is_array($postOutputProcessingHook)) {
                $hookParameters = array('pageContent' => &$pageContent, 'target' => &$this->target);
                foreach ($postOutputProcessingHook as $hookFunction) {
                    GeneralUtility::callUserFunction($hookFunction, $hookParameters, $this);
                }
            }
        }
        $pageContent .= '</form>';
        $this->content = $pageContent;
        $this->moduleTemplate->setContent($this->content);
    }
Пример #2
0
    /**
     * Main function, redering the actual content of the editing page
     *
     * @return void
     */
    public function main()
    {
        $docHeaderButtons = $this->getButtons();
        $this->content = $this->doc->startPage($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_edit.php.pagetitle'));
        // Hook	before compiling the output
        if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['preOutputProcessingHook'])) {
            $preOutputProcessingHook =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['preOutputProcessingHook'];
            if (is_array($preOutputProcessingHook)) {
                $hookParameters = array('content' => &$this->content, 'target' => &$this->target);
                foreach ($preOutputProcessingHook as $hookFunction) {
                    GeneralUtility::callUserFunction($hookFunction, $hookParameters, $this);
                }
            }
        }
        $pageContent = $this->doc->header($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_edit.php.pagetitle') . ' ' . htmlspecialchars($this->fileObject->getName()));
        $pageContent .= $this->doc->spacer(2);
        $code = '';
        $extList = $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'];
        try {
            if (!$extList || !GeneralUtility::inList($extList, $this->fileObject->getExtension())) {
                throw new \Exception('Files with that extension are not editable.');
            }
            // Read file content to edit:
            $fileContent = $this->fileObject->getContents();
            // Making the formfields
            $hValue = BackendUtility::getModuleUrl('file_edit', array('target' => $this->origTarget, 'returnUrl' => $this->returnUrl));
            // Edit textarea:
            $code .= '
				<div id="c-edit">
					<textarea rows="30" name="file[editfile][0][data]" wrap="off" ' . $this->doc->formWidth(48, TRUE, 'width:98%;height:80%') . ' class="text-monospace t3js-enable-tab">' . GeneralUtility::formatForTextarea($fileContent) . '</textarea>
					<input type="hidden" name="file[editfile][0][target]" value="' . $this->fileObject->getUid() . '" />
					<input type="hidden" name="redirect" value="' . htmlspecialchars($hValue) . '" />
					' . \TYPO3\CMS\Backend\Form\FormEngine::getHiddenTokenField('tceAction') . '
				</div>
				<br />';
            // Make shortcut:
            if ($this->getBackendUser()->mayMakeShortcut()) {
                $docHeaderButtons['shortcut'] = $this->doc->makeShortcutIcon('target', '', 'file_edit', 1);
            } else {
                $docHeaderButtons['shortcut'] = '';
            }
        } catch (\Exception $e) {
            $code .= sprintf($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:file_edit.php.coundNot'), $extList);
        }
        // Ending of section and outputting editing form:
        $pageContent .= $this->doc->sectionEnd();
        $pageContent .= $code;
        // Hook	after compiling the output
        if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['postOutputProcessingHook'])) {
            $postOutputProcessingHook =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['postOutputProcessingHook'];
            if (is_array($postOutputProcessingHook)) {
                $hookParameters = array('pageContent' => &$pageContent, 'target' => &$this->target);
                foreach ($postOutputProcessingHook as $hookFunction) {
                    GeneralUtility::callUserFunction($hookFunction, $hookParameters, $this);
                }
            }
        }
        // Add the HTML as a section:
        $markerArray = array('CSH' => $docHeaderButtons['csh'], 'FUNC_MENU' => '', 'BUTTONS' => $docHeaderButtons, 'PATH' => $this->title, 'CONTENT' => $pageContent);
        $this->content .= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray);
        $this->content .= $this->doc->endPage();
        $this->content = $this->doc->insertStylesAndJS($this->content);
    }
Пример #3
0
 /**
  * Convert PNG image using pngquant command.
  *
  * @param AbstractFile $file
  */
 public function convertPngImage(AbstractFile $file)
 {
     try {
         if (self::EXTENSION_PNG !== $file->getExtension()) {
             return;
         }
         // Ignore processed file which uses original file
         if ($file instanceof ProcessedFile && $file->usesOriginalFile()) {
             $this->logger->debug('Do not convert processed file identical with its original file', array('file' => $inputFilePath));
             return;
         }
         // Set input/output files for pngquant command
         // Input file is the the specified file we want to quantize
         // Output file is a temporary file in typo3temp directory
         $inputFilePath = PATH_site . $file->getPublicUrl();
         $outputFilePath = GeneralUtility::tempnam('sg_pngquant_', '.' . self::EXTENSION_PNG);
         // Build command line
         $cmd = $this->buildCommand($inputFilePath, $outputFilePath);
         $result = CommandUtility::exec($cmd, $output, $returnValue);
         if (0 === $returnValue) {
             // Replace content
             if ($file instanceof ProcessedFile) {
                 // For processed file, only convert real processed file (i.e. different than their original file)
                 // Temporary file is automatically removed when updating a processed file
                 $this->logger->debug('Update processed file', array('cmd' => $cmd));
                 $file->updateWithLocalFile($outputFilePath);
             } elseif (!$this->confArray['keepOriginal']) {
                 // Convert original files according to extension configuration
                 // After conversion the temporary file is removed
                 $this->logger->debug('Update original file', array('cmd' => $cmd));
                 $contents = @file_get_contents($outputFilePath);
                 $file->setContents($contents);
             }
         } else {
             $this->logger->error('Convert image', array('cmd' => $cmd, 'result' => $result, 'output' => $output, 'returnValue' => $returnValue));
         }
     } catch (\RuntimeException $e) {
         $this->logger->error($e->getMessage());
     }
     // Remove temporary file, if exists
     if (file_exists($outputFilePath)) {
         $this->removeTemporaryFile($outputFilePath);
     }
 }
    /**
     * Main function, redering the actual content of the editing page
     *
     * @return void
     * @todo Define visibility
     */
    public function main()
    {
        //TODO: change locallang*.php to locallang*.xml
        $docHeaderButtons = $this->getButtons();
        $this->content = $this->doc->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_edit.php.pagetitle'));
        // Hook	before compiling the output
        if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['preOutputProcessingHook'])) {
            $preOutputProcessingHook =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['preOutputProcessingHook'];
            if (is_array($preOutputProcessingHook)) {
                $hookParameters = array('content' => &$this->content, 'target' => &$this->target);
                foreach ($preOutputProcessingHook as $hookFunction) {
                    \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($hookFunction, $hookParameters, $this);
                }
            }
        }
        $pageContent = $this->doc->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_edit.php.pagetitle') . ' ' . htmlspecialchars($this->fileObject->getName()));
        $pageContent .= $this->doc->spacer(2);
        $code = '';
        $extList = $GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'];
        if ($extList && \TYPO3\CMS\Core\Utility\GeneralUtility::inList($extList, $this->fileObject->getExtension())) {
            // Read file content to edit:
            $fileContent = $this->fileObject->getContents();
            // Making the formfields
            $hValue = 'file_edit.php?target=' . rawurlencode($this->origTarget) . '&returnUrl=' . rawurlencode($this->returnUrl);
            // Edit textarea:
            $code .= '
				<div id="c-edit">
					<textarea rows="30" name="file[editfile][0][data]" wrap="off"' . $this->doc->formWidthText(48, 'width:98%;height:80%', 'off') . ' class="fixed-font enable-tab">' . \TYPO3\CMS\Core\Utility\GeneralUtility::formatForTextarea($fileContent) . '</textarea>
					<input type="hidden" name="file[editfile][0][target]" value="' . $this->fileObject->getUid() . '" />
					<input type="hidden" name="redirect" value="' . htmlspecialchars($hValue) . '" />
				</div>
				<br />';
            // Make shortcut:
            if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
                $this->MCONF['name'] = 'xMOD_file_edit.php';
                $docHeaderButtons['shortcut'] = $this->doc->makeShortcutIcon('target', '', $this->MCONF['name'], 1);
            } else {
                $docHeaderButtons['shortcut'] = '';
            }
        } else {
            $code .= sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:file_edit.php.coundNot'), $extList);
        }
        // Ending of section and outputting editing form:
        $pageContent .= $this->doc->sectionEnd();
        $pageContent .= $code;
        // Hook	after compiling the output
        if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['postOutputProcessingHook'])) {
            $postOutputProcessingHook =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/file_edit.php']['postOutputProcessingHook'];
            if (is_array($postOutputProcessingHook)) {
                $hookParameters = array('pageContent' => &$pageContent, 'target' => &$this->target);
                foreach ($postOutputProcessingHook as $hookFunction) {
                    \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($hookFunction, $hookParameters, $this);
                }
            }
        }
        // Add the HTML as a section:
        $markerArray = array('CSH' => $docHeaderButtons['csh'], 'FUNC_MENU' => \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']), 'BUTTONS' => $docHeaderButtons, 'PATH' => $this->title, 'CONTENT' => $pageContent);
        $this->content .= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray);
        $this->content .= $this->doc->endPage();
        $this->content = $this->doc->insertStylesAndJS($this->content);
    }