diff --git a/class.tinymce.php b/Classes/Loader.php similarity index 62% rename from class.tinymce.php rename to Classes/Loader.php index feb788d8b2f0476899289ec44773d339b18d1c1f..94311d45b16e40fa09c4e0f5dace425da3a4f88c 100644 --- a/class.tinymce.php +++ b/Classes/Loader.php @@ -1,5 +1,7 @@ <?php +namespace SGalinski\Tinymce; + /*************************************************************** * Copyright notice * @@ -24,13 +26,19 @@ * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ +use TYPO3\CMS\Backend\Utility\BackendUtility; +use TYPO3\CMS\Core\Page\PageRenderer; +use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Lang\LanguageService; + /** * tinyMCE initialisation class * * Usage: - * $tinyMCE = t3lib_div::makeInstance('tinyMCE'); - * $tinyMCE->loadConfiguration($configuration); - * $javascript = $tinyMCE->getJS(); + * $tinyMceLoader = GeneralUtility::makeInstance('\SGalinski\Tinymce\Loader'); + * $tinyMceLoader->loadConfiguration($configurationFile); + * $javascript = $tinyMceLoader->loadJsViaPageRenderer(); * * Basic Configuration: * @@ -38,7 +46,7 @@ * selector: 'textarea' * }); */ -class tinyMCE { +class Loader { /** * TinyMCE configuration * @@ -72,36 +80,29 @@ class tinyMCE { * @return void */ protected function setLanguage() { - /** @var $languageInstance language */ + /** @var $languageInstance LanguageService */ $languageInstance = (TYPO3_MODE === 'FE' ? $GLOBALS['TSFE'] : $GLOBALS['LANG']); $languageKey = $languageInstance->lang; if (TYPO3_MODE === 'BE') { - $groupOrUserProps = t3lib_BEfunc::getModTSconfig('', 'tx_tinyMCE'); + $groupOrUserProps = BackendUtility::getModTSconfig('', 'tx_tinyMCE'); if (trim($groupOrUserProps['properties']['prefLang']) !== '') { $languageKey = $groupOrUserProps['properties']['prefLang']; } } // language conversion from TLD to iso631 - if (class_exists('\TYPO3\CMS\Core\Localization\Locales')) { - /** @var $locales \TYPO3\CMS\Core\Localization\Locales */ - $locales = t3lib_div::makeInstance('\TYPO3\CMS\Core\Localization\Locales'); - $locales->initialize(); - $isoArray = $locales->getIsoMapping(); - } elseif (class_exists('t3lib_l10n_Locales')) { - /** @var $locales t3lib_l10n_Locales */ - $locales = t3lib_div::makeInstance('t3lib_l10n_Locales'); - $isoArray = $locales->getIsoMapping(); - } else { - $isoArray = $languageInstance->csConvObj->isoArray; - } + /** @var $locales \TYPO3\CMS\Core\Localization\Locales */ + $locales = GeneralUtility::makeInstance('\TYPO3\CMS\Core\Localization\Locales'); + $locales->initialize(); + $isoArray = $locales->getIsoMapping(); if (array_key_exists($languageKey, $isoArray)) { $languageKey = $isoArray[$languageKey]; } - $languageFile = PATH_site . t3lib_extMgm::siteRelPath('tinymce') . 'tinymce/langs/' . $languageKey . '.js'; + $languageFile = PATH_site . ExtensionManagementUtility::siteRelPath('tinymce') . + 'tinymce/langs/' . $languageKey . '.js'; if (!is_file($languageFile)) { $languageKey = 'en'; } @@ -110,42 +111,12 @@ class tinyMCE { } /** - * Returns a file that contains the tinymce configuration + * Returns a file that contains the tinyMCE configuration * * @param bool $loadConfigurationWithTimer useful in relation with AJAX * @return string */ protected function getConfiguration($loadConfigurationWithTimer = FALSE) { -// $configurationOptions = array(); -// foreach ($this->tinymceConfiguration['strings'] as $option => $value) { -// $value = '\'' . str_replace('\'', '\\\'', $value) . '\''; -// $configurationOptions[] = "\t" . $option . ': ' . $value; -// } -// -// foreach ($this->tinymceConfiguration['boolAndInt'] as $option => $value) { -// if (is_numeric($value)) { -// if (strpos($value, '.')) { -// $value = (float) $value; -// } else { -// $value = (int) $value; -// } -// } -// $configurationOptions[] = "\t" . $option . ': ' . $value; -// } -// -// foreach ($this->tinymceConfiguration['arrays'] as $option => $value) { -// $configurationOptions[] = "\t" . $option . ': ' . $value; -// } -// -// foreach ($this->tinymceConfiguration['objects'] as $option => $value) { -// $configurationOptions[] = "\t" . $option . ': ' . $value; -// } -// -// foreach ($this->tinymceConfiguration['functions'] as $option => $value) { -// $configurationOptions[] = "\t" . $option . ': ' . $value; -// } -// $configuration .= implode(",\n", $configurationOptions); - $configuration = $this->tinymceConfiguration['preJS']; $configuration .= ' var executeTinymceInit = function() { @@ -168,7 +139,7 @@ class tinyMCE { $file = PATH_site . 'typo3temp/' . $filename; if (!is_file($file)) { file_put_contents($file, $configuration); - t3lib_div::fixPermissions($file); + GeneralUtility::fixPermissions($file); } return $this->getPath($file, TRUE); @@ -186,7 +157,8 @@ class tinyMCE { $output = ''; if (!self::$init) { self::$init = TRUE; - $script = $GLOBALS['BACK_PATH'] . t3lib_extMgm::extRelPath('tinymce') . 'tinymce/tinymce.min.js'; + $script = $GLOBALS['BACK_PATH'] . ExtensionManagementUtility::extRelPath('tinymce') . + 'tinymce/tinymce.min.js'; $output = '<script type="text/javascript" src="' . $script . '"></script>'; $script = $this->getConfiguration($loadConfigurationWithTimer); @@ -199,17 +171,17 @@ class tinyMCE { /** * Loads the required javascript via the given page renderer instance * - * @param t3lib_PageRenderer $pageRenderer + * @param PageRenderer $pageRenderer * @param bool $loadConfigurationWithTimer * @return void */ - public function loadJsViaPageRenderer(t3lib_PageRenderer $pageRenderer, $loadConfigurationWithTimer = FALSE) { + public function loadJsViaPageRenderer(PageRenderer $pageRenderer, $loadConfigurationWithTimer = FALSE) { if (self::$init) { return; } self::$init = TRUE; - $script = $GLOBALS['BACK_PATH'] . t3lib_extMgm::extRelPath('tinymce') . 'tinymce/tinymce.min.js'; + $script = $GLOBALS['BACK_PATH'] . ExtensionManagementUtility::extRelPath('tinymce') . 'tinymce/tinymce.min.js'; $pageRenderer->addJsLibrary('tinymce', $script, 'text/javascript', FALSE, TRUE, '', TRUE); $script = $this->getConfiguration($loadConfigurationWithTimer); @@ -219,10 +191,6 @@ class tinyMCE { /** * Parses and processes the tinyMCE configuration * - * Note: Unfortunately we didn't solved the riddle how to parse object and function blocks. So we can't parse - * the configuration in detail. Also the regexp has some other possible minor flaws. Recursion (?R) could be a - * possible way. - * * @param string $configuration file reference or configuration string * @return array */ @@ -230,7 +198,7 @@ class tinyMCE { $configurationArray = array(); // try to resolve a potential TYPO3 file path - $configurationFile = t3lib_div::getFileAbsFileName($configuration); + $configurationFile = GeneralUtility::getFileAbsFileName($configuration); if (is_file($configurationFile)) { $configuration = file_get_contents($configurationFile); } @@ -245,28 +213,6 @@ class tinyMCE { $configurationArray['configurationData'] = trim($matches[2]); $configurationArray['postJS'] = trim($matches[3]); - // split options into an array (four value types: values in quotes, int/booleans, arrays, objects, functions) -// $pattern = '([^:\[\(\{]+?)\s*:\s*(?:(\[.*?\])|(\{.*\})|(function.*\})|["\']([^"\']*)["|\']\s*|([^,\n]*))[,\n]\n?'; -// preg_match_all('/' . $pattern . '/is', $matches[2] . "\n", $options); -// for ($i = 0; $i < count($options[1]); ++$i) { -// if (trim($options[2][$i]) !== '') { -// // array -// $configurationArray['arrays'][trim($options[1][$i])] = trim($options[2][$i]); -// } elseif (trim($options[3][$i]) !== '') { -// // object -// $configurationArray['objects'][trim($options[1][$i])] = trim($options[3][$i]); -// } elseif (trim($options[4][$i]) !== '') { -// // function -// $configurationArray['functions'][trim($options[1][$i])] = trim($options[4][$i]); -// } elseif (trim($options[6][$i]) !== '') { -// // int/bool -// $configurationArray['boolAndInt'][trim($options[1][$i])] = trim($options[6][$i]); -// } else { -// // quoted value (value can be empty) -// $configurationArray['strings'][trim($options[1][$i])] = trim($options[5][$i]); -// } -// } - return $configurationArray; } @@ -301,8 +247,8 @@ class tinyMCE { protected function replaceTypo3Paths($configuration) { $replacementFunction = function ($value) { // getPath should be used, but this causes a php exception with PHP 5.3 as $this isn't set there - return '\'' . t3lib_div::getIndpEnv('TYPO3_SITE_URL') . - str_replace(PATH_site, '', t3lib_div::getFileAbsFileName($value[1])) . '\''; + return '\'' . GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . + str_replace(PATH_site, '', GeneralUtility::getFileAbsFileName($value[1])) . '\''; }; return preg_replace_callback('/["\'](EXT:[^"\']*)["\']/is', $replacementFunction, $configuration); @@ -317,9 +263,9 @@ class tinyMCE { * @return string */ protected function getPath($relativePath, $returnWithDomain = FALSE) { - $finalPath = $absolutePath = t3lib_div::getFileAbsFileName($relativePath); + $finalPath = $absolutePath = GeneralUtility::getFileAbsFileName($relativePath); if ($returnWithDomain) { - $finalPath = t3lib_div::getIndpEnv('TYPO3_SITE_URL') . str_replace(PATH_site, '', $absolutePath); + $finalPath = GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . str_replace(PATH_site, '', $absolutePath); } return $finalPath; } diff --git a/ext_emconf.php b/ext_emconf.php index 63c4cd1fedf039b0701877092ce71131c36457bf..e24cd9eee899dc29a7f4ca1344af0e12126db074 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -1,15 +1,5 @@ <?php -/*************************************************************** - * Extension Manager/Repository config file for ext "tinymce". - * - * Auto generated 05-08-2014 22:42 - * - * Manual updates: - * Only the data in the array - everything else is removed by next - * writing. "version" and "dependencies" must not be touched! - ***************************************************************/ - $EM_CONF[$_EXTKEY] = array ( 'title' => 'tinyMCE', 'description' => 'TinyMCE sources including a small PHP API', @@ -26,8 +16,8 @@ $EM_CONF[$_EXTKEY] = array ( array ( 'depends' => array ( - 'php' => '5.2.0-5.5.99', - 'typo3' => '4.5.0-6.2.99', + 'php' => '5.3.0-5.6.99', + 'typo3' => '6.2.0-6.2.99', ), 'conflicts' => array (