/**
  * Generates the cache file.
  *
  * @param string $sourcePath
  * @param string $languageKey
  * @return array
  * @throws \RuntimeException
  */
 protected function generateCacheFile($sourcePath, $languageKey)
 {
     $LOCAL_LANG = array();
     // Get PHP data
     include $sourcePath;
     if (!is_array($LOCAL_LANG)) {
         $fileName = substr($sourcePath, strlen(PATH_site));
         throw new \RuntimeException('TYPO3 Fatal Error: "' . $fileName . '" is no TYPO3 language file!', 1308898491);
     }
     // Converting the default language (English)
     // This needs to be done for a few accented loan words and extension names
     if (is_array($LOCAL_LANG['default']) && $this->targetCharset !== 'utf-8') {
         foreach ($LOCAL_LANG['default'] as &$labelValue) {
             $labelValue = $this->csConvObj->conv($labelValue, 'utf-8', $this->targetCharset);
         }
         unset($labelValue);
     }
     if ($languageKey !== 'default' && is_array($LOCAL_LANG[$languageKey]) && $this->sourceCharset != $this->targetCharset) {
         foreach ($LOCAL_LANG[$languageKey] as &$labelValue) {
             $labelValue = $this->csConvObj->conv($labelValue, $this->sourceCharset, $this->targetCharset);
         }
         unset($labelValue);
     }
     // Cache the content now:
     if (isset($LOCAL_LANG[$languageKey])) {
         $serContent = array('origFile' => $this->hashSource, 'LOCAL_LANG' => array('default' => $LOCAL_LANG['default'], $languageKey => $LOCAL_LANG[$languageKey]));
     } else {
         $serContent = array('origFile' => $this->hashSource, 'LOCAL_LANG' => array('default' => $LOCAL_LANG['default']));
     }
     $res = \TYPO3\CMS\Core\Utility\GeneralUtility::writeFileToTypo3tempDir($this->cacheFileName, serialize($serContent));
     if ($res) {
         throw new \RuntimeException('TYPO3 Fatal Error: "' . $res, 1308898501);
     }
     return $LOCAL_LANG;
 }
예제 #2
0
    /**
     * This method converts an sends mails.
     *
     * @param array $mailconf Mail configuration
     * @param array $orderdata Order data
     * @param string $template Template
     *
     * @return bool of \TYPO3\CMS\Core\Mail\MailMessage
     */
    protected function ordermoveSendMail(array $mailconf, array &$orderdata, &$template)
    {
        // First line is subject
        $parts = explode(chr(10), $mailconf['plain']['content'], 2);
        // add mail subject
        $mailconf['alternateSubject'] = trim($parts[0]);
        // replace plaintext content
        $mailconf['plain']['content'] = trim($parts[1]);
        /**
         * Convert Text to charset
         */
        $this->csConvObj->initCharset('utf-8');
        $this->csConvObj->initCharset('8bit');
        $mailconf['plain']['content'] = $this->csConvObj->conv($mailconf['plain']['content'], 'utf-8', 'utf-8');
        $mailconf['alternateSubject'] = $this->csConvObj->conv($mailconf['alternateSubject'], 'utf-8', 'utf-8');
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Hook/class.tx_commerce_ordermailhooks.php']['ordermoveSendMail'])) {
            GeneralUtility::deprecationLog('
				hook
				$GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'commerce/Classes/Hook/class.tx_commerce_ordermailhooks.php\'][\'ordermoveSendMail\']
				is deprecated since commerce 1.0.0, it will be removed in commerce 1.4.0, please use instead
				$GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'commerce/Classes/Hook/OrdermailHooks.php\'][\'ordermoveSendMail\']
			');
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Hook/class.tx_commerce_ordermailhooks.php']['ordermoveSendMail'] as $classRef) {
                $hookObj = GeneralUtility::getUserObj($classRef);
                if (method_exists($hookObj, 'postOrdermoveSendMail')) {
                    $hookObj->postOrdermoveSendMail($mailconf, $orderdata, $template);
                }
            }
        }
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Hook/OrdermailHooks.php']['ordermoveSendMail'])) {
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Hook/OrdermailHooks.php']['ordermoveSendMail'] as $classRef) {
                $hookObj = GeneralUtility::getUserObj($classRef);
                if (method_exists($hookObj, 'postOrdermoveSendMail')) {
                    $hookObj->postOrdermoveSendMail($mailconf, $orderdata, $template);
                }
            }
        }
        return Tx_Commerce_Utility_GeneralUtility::sendMail($mailconf);
    }
예제 #3
0
 /**
  * This method converts an sends mails.
  *
  * @param array $mailconf Mail configuration
  * @param array $orderdata Order data
  * @param string $template Template
  *
  * @return bool of \TYPO3\CMS\Core\Mail\MailMessage
  */
 protected function ordermoveSendMail(array $mailconf, array &$orderdata, &$template)
 {
     // First line is subject
     $parts = explode(chr(10), $mailconf['plain']['content'], 2);
     // add mail subject
     $mailconf['alternateSubject'] = trim($parts[0]);
     // replace plaintext content
     $mailconf['plain']['content'] = trim($parts[1]);
     /*
      * Convert Text to charset
      */
     $this->csConvObj->initCharset('utf-8');
     $this->csConvObj->initCharset('8bit');
     $mailconf['plain']['content'] = $this->csConvObj->conv($mailconf['plain']['content'], 'utf-8', 'utf-8');
     $mailconf['alternateSubject'] = $this->csConvObj->conv($mailconf['alternateSubject'], 'utf-8', 'utf-8');
     $hooks = \CommerceTeam\Commerce\Factory\HookFactory::getHooks('Hook/OrdermailHooks', 'ordermoveSendMail');
     foreach ($hooks as $hook) {
         if (method_exists($hook, 'postOrdermoveSendMail')) {
             $hook->postOrdermoveSendMail($mailconf, $orderdata, $template);
         }
     }
     return \CommerceTeam\Commerce\Utility\GeneralUtility::sendMail($mailconf);
 }
예제 #4
0
    /**
     * Main class of Spell Checker plugin for Typo3 CMS
     *
     * @return string content produced by the plugin
     */
    public function main()
    {
        $this->csConvObj = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Charset\CharsetConverter::class);
        // Setting start time
        $time_start = microtime(TRUE);
        $this->pspell_is_available = in_array('pspell', get_loaded_extensions());
        $this->AspellDirectory = trim($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey]['plugins']['SpellChecker']['AspellDirectory']) ?: '/usr/bin/aspell';
        // Setting command mode if requested and available
        $this->forceCommandMode = trim($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey]['plugins']['SpellChecker']['forceCommandMode']) ?: 0;
        if (!$this->pspell_is_available || $this->forceCommandMode) {
            $AspellVersionString = explode('Aspell', shell_exec($this->AspellDirectory . ' -v'));
            $AspellVersion = substr($AspellVersionString[1], 0, 4);
            if (doubleval($AspellVersion) < doubleval('0.5') && (!$this->pspell_is_available || $this->forceCommandMode)) {
                echo 'Configuration problem: Aspell version ' . $AspellVersion . ' too old. Spell checking cannot be performed in command mode.';
            }
            $this->defaultAspellEncoding = trim(shell_exec($this->AspellDirectory . ' config encoding'));
        }
        // Setting the list of dictionaries
        $dictionaryList = shell_exec($this->AspellDirectory . ' dump dicts');
        $dictionaryList = implode(',', GeneralUtility::trimExplode(LF, $dictionaryList, TRUE));
        $dictionaryArray = GeneralUtility::trimExplode(',', $dictionaryList, TRUE);
        $restrictToDictionaries = GeneralUtility::_POST('restrictToDictionaries');
        if ($restrictToDictionaries) {
            $dictionaryArray = array_intersect($dictionaryArray, GeneralUtility::trimExplode(',', $restrictToDictionaries, 1));
        }
        if (!count($dictionaryArray)) {
            $dictionaryArray[] = 'en';
        }
        $this->dictionary = GeneralUtility::_POST('dictionary');
        $defaultDictionary = $this->dictionary;
        if (!$defaultDictionary || !in_array($defaultDictionary, $dictionaryArray)) {
            $defaultDictionary = 'en';
        }
        uasort($dictionaryArray, 'strcoll');
        $dictionaryList = implode(',', $dictionaryArray);
        // Setting the dictionary
        if (empty($this->dictionary) || !in_array($this->dictionary, $dictionaryArray)) {
            $this->dictionary = 'en';
        }
        // Setting the pspell suggestion mode
        $this->pspellMode = GeneralUtility::_POST('pspell_mode') ? GeneralUtility::_POST('pspell_mode') : $this->pspellMode;
        // Now sanitize $this->pspellMode
        $this->pspellMode = GeneralUtility::inList('ultra,fast,normal,bad-spellers', $this->pspellMode) ? $this->pspellMode : 'normal';
        switch ($this->pspellMode) {
            case 'ultra':
            case 'fast':
                $pspellModeFlag = PSPELL_FAST;
                break;
            case 'bad-spellers':
                $pspellModeFlag = PSPELL_BAD_SPELLERS;
                break;
            case 'normal':
            default:
                $pspellModeFlag = PSPELL_NORMAL;
        }
        // Setting the charset
        if (GeneralUtility::_POST('pspell_charset')) {
            $this->charset = trim(GeneralUtility::_POST('pspell_charset'));
        }
        if (strtolower($this->charset) == 'iso-8859-1') {
            $this->parserCharset = strtolower($this->charset);
        }
        // In some configurations, Aspell uses 'iso8859-1' instead of 'iso-8859-1'
        $this->aspellEncoding = $this->parserCharset;
        if ($this->parserCharset == 'iso-8859-1' && strstr($this->defaultAspellEncoding, '8859-1')) {
            $this->aspellEncoding = $this->defaultAspellEncoding;
        }
        // However, we are going to work only in the parser charset
        if ($this->pspell_is_available && !$this->forceCommandMode) {
            $this->pspell_link = pspell_new($this->dictionary, '', '', $this->parserCharset, $pspellModeFlag);
        }
        // Setting the path to main dictionary
        $this->setMainDictionaryPath();
        // Setting the path to user personal dictionary, if any
        $this->setPersonalDictionaryPath();
        $this->fixPersonalDictionaryCharacterSet();
        $cmd = GeneralUtility::_POST('cmd');
        if ($cmd == 'learn') {
            // Only availble for BE_USERS, die silently if someone has gotten here by accident
            if (TYPO3_MODE !== 'BE' || !is_object($GLOBALS['BE_USER'])) {
                die('');
            }
            // Updating the personal word list
            $to_p_dict = GeneralUtility::_POST('to_p_dict');
            $to_p_dict = $to_p_dict ? $to_p_dict : array();
            $to_r_list = GeneralUtility::_POST('to_r_list');
            $to_r_list = $to_r_list ? $to_r_list : array();
            header('Content-Type: text/plain; charset=' . strtoupper($this->parserCharset));
            header('Pragma: no-cache');
            if ($to_p_dict || $to_r_list) {
                $tmpFileName = GeneralUtility::tempnam($this->filePrefix);
                $filehandle = fopen($tmpFileName, 'wb');
                if ($filehandle) {
                    // Get the character set of the main dictionary
                    // We need to convert the input into the character set of the main dictionary
                    $mainDictionaryCharacterSet = $this->getMainDictionaryCharacterSet();
                    // Write the personal words addition commands to the temporary file
                    foreach ($to_p_dict as $personal_word) {
                        $cmd = '&' . $this->csConvObj->conv($personal_word, $this->parserCharset, $mainDictionaryCharacterSet) . LF;
                        fwrite($filehandle, $cmd, strlen($cmd));
                    }
                    // Write the replacent pairs addition commands to the temporary file
                    foreach ($to_r_list as $replace_pair) {
                        $cmd = '$$ra ' . $this->csConvObj->conv($replace_pair[0], $this->parserCharset, $mainDictionaryCharacterSet) . ' , ' . $this->csConvObj->conv($replace_pair[1], $this->parserCharset, $mainDictionaryCharacterSet) . LF;
                        fwrite($filehandle, $cmd, strlen($cmd));
                    }
                    $cmd = '#' . LF;
                    $result = fwrite($filehandle, $cmd, strlen($cmd));
                    if ($result === FALSE) {
                        GeneralUtility::sysLog('SpellChecker tempfile write error: ' . $tmpFileName, $this->extKey, GeneralUtility::SYSLOG_SEVERITY_ERROR);
                    } else {
                        // Assemble the Aspell command
                        $aspellCommand = (TYPO3_OS === 'WIN' ? 'type ' : 'cat ') . escapeshellarg($tmpFileName) . ' | ' . $this->AspellDirectory . ' -a --mode=none' . ($this->personalDictionaryPath ? ' --home-dir=' . escapeshellarg($this->personalDictionaryPath) : '') . ' --lang=' . escapeshellarg($this->dictionary) . ' --encoding=' . escapeshellarg($mainDictionaryCharacterSet) . ' 2>&1';
                        $aspellResult = shell_exec($aspellCommand);
                        // Close and delete the temporary file
                        fclose($filehandle);
                        GeneralUtility::unlink_tempfile($tmpFileName);
                    }
                } else {
                    GeneralUtility::sysLog('SpellChecker tempfile open error: ' . $tmpFileName, $this->extKey, GeneralUtility::SYSLOG_SEVERITY_ERROR);
                }
            }
            flush();
            die;
        } else {
            // Check spelling content
            // Initialize output
            $this->result = '<?xml version="1.0" encoding="' . $this->parserCharset . '"?>
<!DOCTYPE html
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="' . substr($this->dictionary, 0, 2) . '" lang="' . substr($this->dictionary, 0, 2) . '">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=' . $this->parserCharset . '" />
<link rel="stylesheet" type="text/css" media="all" href="' . (TYPO3_MODE == 'BE' ? '../' : '') . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . '/Resources/Public/Css/Skin/Plugins/spell-checker-iframe.css" />
<script type="text/javascript">
/*<![CDATA[*/
<!--
';
            // Getting the input content
            $content = GeneralUtility::_POST('content');
            // Parsing the input HTML
            $parser = xml_parser_create(strtoupper($this->parserCharset));
            xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
            xml_set_object($parser, $this);
            if (!xml_set_element_handler($parser, 'startHandler', 'endHandler')) {
                echo 'Bad xml handler setting';
            }
            if (!xml_set_character_data_handler($parser, 'collectDataHandler')) {
                echo 'Bad xml handler setting';
            }
            if (!xml_set_default_handler($parser, 'defaultHandler')) {
                echo 'Bad xml handler setting';
            }
            if (!xml_parse($parser, '<?xml version="1.0" encoding="' . $this->parserCharset . '"?><spellchecker> ' . preg_replace('/&nbsp;/' . ($this->parserCharset == 'utf-8' ? 'u' : ''), ' ', $content) . ' </spellchecker>')) {
                echo 'Bad parsing';
            }
            if (xml_get_error_code($parser)) {
                throw new \UnexpectedException('Line ' . xml_get_current_line_number($parser) . ': ' . xml_error_string(xml_get_error_code($parser)), 1294585788);
            }
            xml_parser_free($parser);
            if ($this->pspell_is_available && !$this->forceCommandMode) {
                pspell_clear_session($this->pspell_link);
            }
            $this->result .= 'var suggestedWords = {' . $this->suggestedWords . '};
var dictionaries = "' . $dictionaryList . '";
var selectedDictionary = "' . $this->dictionary . '";
';
            // Calculating parsing and spell checkting time
            $time = number_format(microtime(TRUE) - $time_start, 2, ',', ' ');
            // Insert spellcheck info
            $this->result .= 'var spellcheckInfo = { "Total words":"' . $this->wordCount . '","Misspelled words":"' . sizeof($this->misspelled) . '","Total suggestions":"' . $this->suggestionCount . '","Total words suggested":"' . $this->suggestedWordCount . '","Spelling checked in":"' . $time . '" };
// -->
/*]]>*/
</script>
</head>
';
            $this->result .= '<body onload="window.parent.RTEarea[\'' . GeneralUtility::_POST('editorId') . '\'].editor.getPlugin(\'SpellChecker\').spellCheckComplete();">';
            $this->result .= preg_replace('/' . preg_quote('<?xml') . '.*' . preg_quote('?>') . '[' . preg_quote(LF . CR . chr(32)) . ']*/' . ($this->parserCharset == 'utf-8' ? 'u' : ''), '', $this->text);
            $this->result .= '<div style="display: none;">' . $dictionaries . '</div>';
            // Closing
            $this->result .= '
</body></html>';
            // Outputting
            header('Content-Type: text/html; charset=' . strtoupper($this->parserCharset));
            echo $this->result;
        }
    }
 /**
  * Converts input string from renderCharset to metaCharset IF the two charsets are different.
  *
  * @param string $content Content to be converted.
  * @param string $label Label (just for fun, no function)
  * @return string Converted content string.
  * @todo Define visibility
  */
 public function convOutputCharset($content, $label = '')
 {
     if ($this->renderCharset != $this->metaCharset) {
         $content = $this->csConvObj->conv($content, $this->renderCharset, $this->metaCharset, TRUE);
     }
     return $content;
 }
 /**
  * Splits the search word input into an array where each word is represented by an array with key "sword" holding the search word and key "oper" holding the SQL operator (eg. AND, OR)
  *
  * Only words with 2 or more characters are accepted
  * Max 200 chars total
  * Space is used to split words, "" can be used search for a whole string
  * AND, OR and NOT are prefix words, overruling the default operator
  * +/|/- equals AND, OR and NOT as operators.
  * All search words are converted to lowercase.
  *
  * $defOp is the default operator. 1=OR, 0=AND
  *
  * @param bool $defOp If TRUE, the default operator will be OR, not AND
  * @return array Returns array with search words if any found
  */
 public function getSearchWords($defOp)
 {
     // Shorten search-word string to max 200 bytes (does NOT take multibyte charsets into account - but never mind, shortening the string here is only a run-away feature!)
     $inSW = substr($this->piVars['sword'], 0, 200);
     // Convert to UTF-8 + conv. entities (was also converted during indexing!)
     $inSW = $this->charsetConverter->conv($inSW, $this->frontendController->metaCharset, 'utf-8');
     $inSW = $this->charsetConverter->entities_to_utf8($inSW);
     $sWordArray = false;
     if ($hookObj = $this->hookRequest('getSearchWords')) {
         $sWordArray = $hookObj->getSearchWords_splitSWords($inSW, $defOp);
     } else {
         if ($this->piVars['type'] == 20) {
             // type = Sentence
             $sWordArray = array(array('sword' => trim($inSW), 'oper' => 'AND'));
         } else {
             $searchWords = \TYPO3\CMS\IndexedSearch\Utility\IndexedSearchUtility::getExplodedSearchString($inSW, $defOp == 1 ? 'OR' : 'AND', $this->operator_translate_table);
             if (is_array($searchWords)) {
                 $sWordArray = $this->procSearchWordsByLexer($searchWords);
             }
         }
     }
     return $sWordArray;
 }
예제 #7
0
 /**
  * Convert character set and HTML entities in the value of input content array keys
  *
  * @param array $contentArr Standard content array
  * @param string $charset Charset of the input content (converted to utf-8)
  * @return void
  */
 public function charsetEntity2utf8(&$contentArr, $charset)
 {
     // Convert charset if necessary
     foreach ($contentArr as $key => $value) {
         if ((string) $contentArr[$key] !== '') {
             if ($charset !== 'utf-8') {
                 $contentArr[$key] = $this->csObj->conv($contentArr[$key], $charset, 'utf-8');
             }
             // decode all numeric / html-entities in the string to real characters:
             $contentArr[$key] = $this->csObj->entities_to_utf8($contentArr[$key], true);
         }
     }
 }
 /**
  * Splits the search word input into an array where each word is represented by an array with key "sword"
  * holding the search word and key "oper" holding the SQL operator (eg. AND, OR)
  *
  * Only words with 2 or more characters are accepted
  * Max 200 chars total
  * Space is used to split words, "" can be used search for a whole string
  * AND, OR and NOT are prefix words, overruling the default operator
  * +/|/- equals AND, OR and NOT as operators.
  * All search words are converted to lowercase.
  *
  * $defOp is the default operator. 1=OR, 0=AND
  *
  * @param bool $defaultOperator If TRUE, the default operator will be OR, not AND
  * @return array Search words if any found
  */
 protected function getSearchWords($defaultOperator)
 {
     // Shorten search-word string to max 200 bytes (does NOT take multibyte charsets into account - but never mind,
     // shortening the string here is only a run-away feature!)
     $searchWords = substr($this->sword, 0, 200);
     // Convert to UTF-8 + conv. entities (was also converted during indexing!)
     $searchWords = $this->charsetConverter->conv($searchWords, $GLOBALS['TSFE']->metaCharset, 'utf-8');
     $searchWords = $this->charsetConverter->entities_to_utf8($searchWords);
     $sWordArray = false;
     if ($hookObj = $this->hookRequest('getSearchWords')) {
         $sWordArray = $hookObj->getSearchWords_splitSWords($searchWords, $defaultOperator);
     } else {
         // sentence
         if ($this->searchData['searchType'] == 20) {
             $sWordArray = array(array('sword' => trim($searchWords), 'oper' => 'AND'));
         } else {
             // case-sensitive. Defines the words, which will be
             // operators between words
             $operatorTranslateTable = array(array('+', 'AND'), array('|', 'OR'), array('-', 'AND NOT'), array($this->charsetConverter->conv_case('utf-8', LocalizationUtility::translate('localizedOperandAnd', 'IndexedSearch'), 'toLower'), 'AND'), array($this->charsetConverter->conv_case('utf-8', LocalizationUtility::translate('localizedOperandOr', 'IndexedSearch'), 'toLower'), 'OR'), array($this->charsetConverter->conv_case('utf-8', LocalizationUtility::translate('localizedOperandNot', 'IndexedSearch'), 'toLower'), 'AND NOT'));
             $swordArray = \TYPO3\CMS\IndexedSearch\Utility\IndexedSearchUtility::getExplodedSearchString($searchWords, $defaultOperator == 1 ? 'OR' : 'AND', $operatorTranslateTable);
             if (is_array($swordArray)) {
                 $sWordArray = $this->procSearchWordsByLexer($swordArray);
             }
         }
     }
     return $sWordArray;
 }
 /**
  * Converts the subject and the expected result into utf-8.
  *
  * @param string $subject the subject, will be modified
  * @param string $expected the expected result, will be modified
  */
 protected function handleCharset(&$subject, &$expected)
 {
     $charsetConverter = new CharsetConverter();
     $subject = $charsetConverter->conv($subject, 'iso-8859-1', 'utf-8');
     $expected = $charsetConverter->conv($expected, 'iso-8859-1', 'utf-8');
 }