/**
     * The main function in the class
     *
     * @return	string		HTML content
     */
    function cacheFiles()
    {
        $content = '';
        // CURRENT:
        $content .= '<strong>1: The current cache files:</strong>' . Tx_Extdeveval_Compatibility::viewArray(t3lib_extMgm::currentCacheFiles());
        // REMOVING?
        if (t3lib_div::_GP('REMOVE_temp_CACHED')) {
            $number = $this->removeCacheFiles();
            $content .= '<hr /><p><strong>2: Tried to remove ' . $number . ' cache files.</strong></p>';
        }
        if (t3lib_div::_GP('REMOVE_temp_CACHED_ALL')) {
            $content .= '<hr /><p><strong>2: Removing ALL "temp_CACHED_*" files:</strong></p>' . $this->removeALLtempCachedFiles();
        }
        $files = t3lib_div::getFilesInDir(PATH_typo3conf, 'php');
        $tRows = array();
        foreach ($files as $f) {
            $tRows[] = '<tr>
				<td>' . htmlspecialchars($f) . '</td>
				<td>' . t3lib_div::formatSize(filesize(PATH_typo3conf . $f)) . '</td>
			</tr>';
        }
        $content .= '<br /><strong>3: PHP files (now) in "' . PATH_typo3conf . '":</strong><br />
		<table border="1">' . implode('', $tRows) . '</table>

		<input type="submit" name="REMOVE_temp_CACHED" value="REMOVE current temp_CACHED files" />
		<input type="submit" name="REMOVE_temp_CACHED_ALL" value="REMOVE ALL temp_CACHED_* files" />
		<input type="submit" name="_" value="Refresh" />
		';
        return $content;
    }
 /**
  * Main function
  *
  * @param	string		Absolute path to the selected PHP file
  * @param	string		Extension dir (local, global, system) relative to PATH_site
  * @return	string		HTML content.
  */
 function main($phpFile, $extensionDir)
 {
     if (@is_file($phpFile)) {
         $fCheck = $this->checkLLfilename($phpFile);
         if (!$fCheck) {
             $newFileName = preg_replace('#\\.php$#', '.xml', $phpFile);
             if (!@is_file($newFileName)) {
                 if (t3lib_div::_GP('doSave')) {
                     return $this->renderSaveDone($phpFile, $newFileName);
                 } else {
                     return $this->renderSaveForm($phpFile);
                 }
                 return Tx_Extdeveval_Compatibility::viewArray(array($phpFile, $extensionDir));
             } else {
                 return 'ERROR: Output file "' . $newFileName . '" existed already!';
             }
         } else {
             return 'ERROR: ' . $fCheck;
         }
     }
 }
 /**
  * Generates the sprites for t3skin.
  *
  * @return	string		HTML content
  */
 public function createSpritesForT3Skin()
 {
     /** @var $generator t3lib_SpriteManager_SpriteGenerator */
     $generator = t3lib_div::makeInstance('t3lib_SpriteManager_SpriteGenerator', 't3skin');
     $this->unlinkT3SkinFiles();
     $data = $generator->setSpriteFolder(TYPO3_mainDir . 'sysext/t3skin/images/sprites/')->setCSSFolder(TYPO3_mainDir . 'sysext/t3skin/stylesheets/sprites/')->setOmmitSpriteNameInIconName(TRUE)->setIncludeTimestampInCSS(TRUE)->generateSpriteFromFolder(array(TYPO3_mainDir . 'sysext/t3skin/images/icons/'));
     $version = Tx_Extdeveval_Compatibility::convertVersionNumberToInteger(TYPO3_version);
     // IE6 fallback sprites have been removed with TYPO3 4.6
     if ($version < 4006000) {
         $gifSpritesPath = PATH_typo3 . 'sysext/t3skin/stylesheets/ie6/z_t3-icons-gifSprites.css';
         if (FALSE === rename($data['cssGif'], $gifSpritesPath)) {
             throw new tx_extdeveval_exception('The file "' . $data['cssGif'] . '" could not be renamed to "' . $gifSpritesPath . '"');
         }
     }
     $stddbPath = PATH_site . 't3lib/stddb/tables.php';
     $stddbContents = file_get_contents($stddbPath);
     $newContent = '$GLOBALS[\'TBE_STYLES\'][\'spriteIconApi\'][\'coreSpriteImageNames\'] = array(' . LF . TAB . '\'' . implode('\',' . LF . TAB . '\'', $data['iconNames']) . '\'' . LF . ');' . LF;
     $stddbContents = preg_replace('/\\$GLOBALS\\[\'TBE_STYLES\'\\]\\[\'spriteIconApi\'\\]\\[\'coreSpriteImageNames\'\\] = array\\([\\s\',\\w-]*\\);/', $newContent, $stddbContents);
     if (FALSE === t3lib_div::writeFile($stddbPath, $stddbContents)) {
         throw new tx_extdeveval_exception('Could not write file "' . $stddbPath . '"');
     }
     $output = 'Sprites successfully regenerated';
     return $output;
 }
 /**
  * The main function in the class
  *
  * @return	string		HTML content
  */
 function main()
 {
     $output = 'Enter [table]:[uid]:[fieldlist (optional)] <input name="table_uid" value="' . htmlspecialchars(t3lib_div::_POST('table_uid')) . '" />';
     $output .= '<input type="submit" name="_" value="REFRESH" /><br/>';
     // Show record:
     if (t3lib_div::_POST('table_uid')) {
         list($table, $uid, $fieldName) = t3lib_div::trimExplode(':', t3lib_div::_POST('table_uid'), 1);
         if ($GLOBALS['TCA'][$table]) {
             $rec = t3lib_BEfunc::getRecordRaw($table, 'uid=' . intval($uid), $fieldName ? $fieldName : '*');
             if (count($rec)) {
                 $pidOfRecord = $rec['pid'];
                 $output .= '<input type="checkbox" name="show_path" value="1"' . (t3lib_div::_POST('show_path') ? ' checked="checked"' : '') . '/> Show path and rootline of record<br/>';
                 if (t3lib_div::_POST('show_path')) {
                     $output .= '<br/>Path of PID ' . $pidOfRecord . ': <em>' . t3lib_BEfunc::getRecordPath($pidOfRecord, '', 30) . '</em><br/>';
                     $output .= 'RL:' . Tx_Extdeveval_Compatibility::viewArray(t3lib_BEfunc::BEgetRootLine($pidOfRecord)) . '<br/>';
                     $output .= 'FLAGS:' . ($rec['deleted'] ? ' <b>DELETED</b>' : '') . ($rec['pid'] == -1 ? ' <b>OFFLINE VERSION of ' . $rec['t3ver_oid'] . '</b>' : '') . '<br/><hr/>';
                 }
                 if (t3lib_div::_POST('_EDIT')) {
                     $output .= '<hr/>Edit:<br/><br/>';
                     $output .= '<input type="submit" name="_SAVE" value="SAVE" /><br/>';
                     foreach ($rec as $field => $value) {
                         $output .= '<b>' . htmlspecialchars($field) . ':</b><br/>';
                         if (count(explode(chr(10), $value)) > 1) {
                             $output .= '<textarea name="record[' . $table . '][' . $uid . '][' . $field . ']" cols="100" rows="10">' . t3lib_div::formatForTextarea($value) . '</textarea><br/>';
                         } else {
                             $output .= '<input name="record[' . $table . '][' . $uid . '][' . $field . ']" value="' . htmlspecialchars($value) . '" size="100" /><br/>';
                         }
                     }
                 } elseif (t3lib_div::_POST('_SAVE')) {
                     $incomingData = t3lib_div::_POST('record');
                     $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid=' . intval($uid), $incomingData[$table][$uid]);
                     $output .= '<br/>Updated ' . $table . ':' . $uid . '...';
                     $this->updateRefIndex($table, $uid);
                 } else {
                     if (t3lib_div::_POST('_DELETE')) {
                         $GLOBALS['TYPO3_DB']->exec_DELETEquery($table, 'uid=' . intval($uid));
                         $output .= '<br/>Deleted ' . $table . ':' . $uid . '...';
                         $this->updateRefIndex($table, $uid);
                     } else {
                         $output .= '<input type="submit" name="_EDIT" value="EDIT" />';
                         $output .= '<input type="submit" name="_DELETE" value="DELETE" onclick="return confirm(\'Are you sure you wish to delete?\');" />';
                         $output .= '<br/>' . md5(implode($rec));
                         $output .= Tx_Extdeveval_Compatibility::viewArray($rec);
                     }
                 }
             } else {
                 $output .= 'No record existed!';
             }
         }
     }
     return $output;
 }
    /**
     * Rendering the table icons
     *
     * @return	string		HTML
     */
    function renderTableIcons()
    {
        if (is_array($GLOBALS['TCA'][$this->tableName])) {
            // Set the default:
            $this->testRecords = array();
            $this->testRecords[] = array();
            $tableCols = array();
            // Set hidden:
            if ($GLOBALS['TCA'][$this->tableName]['ctrl']['enablecolumns']['disabled'] && $this->optionsMatrix['Hidden']) {
                $this->addTestRecordFields(array($GLOBALS['TCA'][$this->tableName]['ctrl']['enablecolumns']['disabled'] => 1));
                $tableCols['Hidden'] = $GLOBALS['TCA'][$this->tableName]['ctrl']['enablecolumns']['disabled'];
            }
            // Set starttime:
            if ($GLOBALS['TCA'][$this->tableName]['ctrl']['enablecolumns']['starttime'] && $this->optionsMatrix['Starttime']) {
                $this->addTestRecordFields(array($GLOBALS['TCA'][$this->tableName]['ctrl']['enablecolumns']['starttime'] => time() + 60));
                $tableCols['Starttime'] = $GLOBALS['TCA'][$this->tableName]['ctrl']['enablecolumns']['starttime'];
            }
            // Set endtime:
            if ($GLOBALS['TCA'][$this->tableName]['ctrl']['enablecolumns']['endtime'] && $this->optionsMatrix['Endtime']) {
                $this->addTestRecordFields(array($GLOBALS['TCA'][$this->tableName]['ctrl']['enablecolumns']['endtime'] => time() + 60));
                /*				$this->addTestRecordFields(array(
                					$GLOBALS['TCA'][$this->tableName]['ctrl']['enablecolumns']['endtime'] => time() - 60
                				));
                	*/
                $tableCols['Endtime'] = $GLOBALS['TCA'][$this->tableName]['ctrl']['enablecolumns']['endtime'];
            }
            // Set fe_group:
            if ($GLOBALS['TCA'][$this->tableName]['ctrl']['enablecolumns']['fe_group'] && $this->optionsMatrix['Access']) {
                $this->addTestRecordFields(array($GLOBALS['TCA'][$this->tableName]['ctrl']['enablecolumns']['fe_group'] => 1));
                $tableCols['Access'] = $GLOBALS['TCA'][$this->tableName]['ctrl']['enablecolumns']['fe_group'];
            }
            // If "pages" table, add "extendToSubpages"
            if ($this->tableName == 'pages' && $this->optionsMatrix['Incl.Sub']) {
                $this->addTestRecordFields(array('extendToSubpages' => 1));
                $tableCols['Incl.Sub'] = 'extendToSubpages';
            }
            // Set "delete" flag:
            if ($GLOBALS['TCA'][$this->tableName]['ctrl']['delete'] && $this->optionsMatrix['Del.']) {
                $this->testRecords[] = array($GLOBALS['TCA'][$this->tableName]['ctrl']['delete'] => 1);
                $tableCols['Del.'] = $GLOBALS['TCA'][$this->tableName]['ctrl']['delete'];
            }
            // _NO_ICON_FOUND
            if ($this->optionsMatrix['_NO_ICON_FOUND']) {
                $this->testRecords[] = array('_NO_ICON_FOUND' => 1);
            }
            if ($this->tableName == 'pages') {
                $tempArray = array();
                if ($this->optionsMatrix['Doktype']) {
                    foreach ($GLOBALS['PAGES_TYPES'] as $doktype => $dat) {
                        if ($dat['icon']) {
                            foreach ($this->testRecords as $rec) {
                                $tempArray[] = array_merge($rec, array('doktype' => $doktype));
                            }
                        }
                    }
                    $tableCols['Doktype'] = 'doktype';
                }
                if ($this->optionsMatrix['Module']) {
                    foreach ($GLOBALS['ICON_TYPES'] as $module => $dat) {
                        if ($dat['icon']) {
                            foreach ($this->testRecords as $rec) {
                                $tempArray[] = array_merge($rec, array('module' => $module));
                            }
                        }
                    }
                    $tableCols['Module'] = 'module';
                }
                $this->testRecords = array_merge($tempArray, $this->testRecords);
            } elseif (is_array($GLOBALS['TCA'][$this->tableName]['ctrl']['typeicons']) && $this->optionsMatrix['TypeIcon']) {
                $tempArray = array();
                foreach ($GLOBALS['TCA'][$this->tableName]['ctrl']['typeicons'] as $typeVal => $dat) {
                    foreach ($this->testRecords as $rec) {
                        $tempArray[] = array_merge($rec, array($GLOBALS['TCA'][$this->tableName]['ctrl']['typeicon_column'] => $typeVal));
                    }
                }
                $tableCols['TypeIcon'] = $GLOBALS['TCA'][$this->tableName]['ctrl']['typeicon_column'];
                $this->testRecords = array_merge($tempArray, $this->testRecords);
            }
            // Render table:
            $tRows = array();
            $sortRows = array();
            // Draw header:
            $tCells = array();
            $tCells[] = 'Icon:';
            $tCells[] = 'Name:';
            foreach ($tableCols as $label => $field) {
                $tCells[] = $label . ':';
            }
            $tRows[] = '
				<tr class="bgColor5" style="font-weight: bold;">
					<td>' . implode('</td>
					<td>', $tCells) . '</td>
				</tr>';
            // Traverse fake records, render icons:
            foreach ($this->testRecords as $row) {
                $tCells = array();
                $icon = t3lib_iconWorks::getIconImage($this->tableName, $row, $GLOBALS['BACK_PATH']);
                $tCells[] = $icon;
                $attrib = t3lib_div::get_tag_attributes($icon);
                $fileName = substr($attrib['src'], strlen($GLOBALS['BACK_PATH']));
                $tCells[] = $fileName;
                $sortRows[] = $fileName;
                foreach ($tableCols as $label => $field) {
                    switch ($label) {
                        case 'Hidden':
                        case 'Access':
                        case 'Del.':
                        case 'Incl.Sub':
                            $tCells[] = $row[$field] ? 'YES' : '';
                            break;
                        case 'Endtime':
                        case 'Starttime':
                            $tCells[] = $row[$field] ? t3lib_BEfunc::date($row[$field]) : '';
                            break;
                        default:
                            $tCells[] = $row[$field];
                            break;
                    }
                }
                $tRows[] = '
					<tr class="bgColor4">
						<td>' . implode('</td>
						<td>', $tCells) . '</td>
					</tr>';
            }
            // Create table with icons:
            $output = $this->tableName . ':
				<table border="0" cellpadding="0" cellspacing="1">
					' . implode('', $tRows) . '
				</table>';
            // Show unique filenames involved:
            sort($sortRows);
            $sortRows = array_unique($sortRows);
            $output .= '<br /><p><strong>Unique icons:</strong></p>' . count($sortRows);
            $output .= '<br/><br/>';
            $output .= '<p><strong>Filenames:</strong></p>' . Tx_Extdeveval_Compatibility::viewArray($sortRows);
            // DEVELOPMENT purposes, do NOT rename if you don't know what you are doing!
            #$this->renameIconsInTypo3Temp();
        }
        return $output;
    }
 /**
  * Processing of the submitted form; Will create and write the XLIFF file and tell the new file name.
  *
  * @param string $xmlFile Absolute path to the locallang.xml file to convert
  * @param string $newFilename The new file name to write to (absolute path, .xlf ending)
  * @param string $langKey The language key
  * @return string HTML text string message
  */
 protected function renderSaveDone($xmlFile, $newFileName, $langKey)
 {
     // Initialize variables:
     $xml = array();
     $LOCAL_LANG = $this->getLLarray($xmlFile);
     $xml[] = '<?xml version="1.0" encoding="utf-8" standalone="yes" ?>';
     $xml[] = '<xliff version="1.0">';
     $xml[] = '	<file source-language="en"' . ($langKey !== 'default' ? ' target-language="' . $langKey . '"' : '') . ' datatype="plaintext" original="messages" date="' . gmdate('Y-m-d\\TH:i:s\\Z') . '"' . ' product-name="' . $this->extension . '">';
     $xml[] = '		<header/>';
     $xml[] = '		<body>';
     $version = Tx_Extdeveval_Compatibility::convertVersionNumberToInteger(TYPO3_version);
     foreach ($LOCAL_LANG[$langKey] as $key => $data) {
         $source = $version < 4006000 ? $LOCAL_LANG['default'][$key] : $data[0]['source'];
         $target = $version < 4006000 ? $data : $data[0]['target'];
         if ($langKey === 'default') {
             $xml[] = '			<trans-unit id="' . $key . '" xml:space="preserve">';
             $xml[] = '				<source>' . htmlspecialchars($source) . '</source>';
             $xml[] = '			</trans-unit>';
         } else {
             $xml[] = '			<trans-unit id="' . $key . '" xml:space="preserve" approved="yes">';
             $xml[] = '				<source>' . htmlspecialchars($source) . '</source>';
             $xml[] = '				<target>' . htmlspecialchars($target) . '</target>';
             $xml[] = '			</trans-unit>';
         }
     }
     $xml[] = '		</body>';
     $xml[] = '	</file>';
     $xml[] = '</xliff>';
     if (!file_exists($newFileName)) {
         # debug(array($XML));
         t3lib_div::writeFile($newFileName, implode(LF, $xml));
         return 'File written to disk: ' . $newFileName;
     }
 }
    /**
     * Creating TYPO3 Glossary XML file
     *
     * @return	string		HTML content
     */
    function calc_wiki2llxml()
    {
        // Render input form:
        $content = '
			<h3>Input Wiki code for TYPO3 glossary to form a locallang-XML file out of it:</h3>
				<textarea rows="10" name="inputCalc[wiki2llxml][input]" wrap="off"' . $GLOBALS['TBE_TEMPLATE']->formWidthText(48, 'width:98%;', 'off') . '>' . t3lib_div::formatForTextarea($this->inputCalc['wiki2llxml']['input']) . '</textarea>
				<input type="submit" name="cmd[wiki2llxml]" value="Convert" />
		';
        if ($this->cmd == 'wiki2llxml' && trim($this->inputCalc['wiki2llxml']['input'])) {
            $inputValue = $this->inputCalc['wiki2llxml']['input'];
            // Clean out super-headers:
            $inputValue = preg_replace('#([^=])===[[:space:]]*[[:alnum:]]*[[:space:]]*===([^=])#', '${1}${2}', $inputValue);
            // Split by term header:
            $rawTerms = explode('=====', $inputValue);
            $organizedTerms = array();
            $termKey = '';
            foreach ($rawTerms as $k => $v) {
                if ($k % 2 == 0) {
                    if ($termKey) {
                        $tK = $this->calc_wiki2llxml_termkey($termKey);
                        if ($tK) {
                            $organizedTerms[$tK] = array();
                            $rawdata = trim($v);
                            list($description, $moreInfo) = explode("''More info:''", $rawdata, 2);
                            if ($moreInfo) {
                                list($moreInfo, $otherTerms) = explode("''Other matching terms:''", $moreInfo, 2);
                            } else {
                                list($description, $otherTerms) = explode("''Other matching terms:''", $description, 2);
                            }
                            $description = trim(strip_tags($description));
                            $moreInfo = trim(strip_tags($moreInfo));
                            $otherTerms = trim(strip_tags($otherTerms));
                            $organizedTerms[$tK] = array('term' => $termKey, 'RAWDATA' => trim($rawdata), 'description' => $description, 'moreInfo' => $moreInfo, 'otherTerms' => $otherTerms);
                        }
                    }
                } else {
                    $termKey = trim($v);
                }
            }
            // Traverse terms to clean up moreInfo and otherTerms:
            foreach ($organizedTerms as $key => $termData) {
                // Other Terms fixing.
                $oT = t3lib_div::trimExplode(',', $termData['otherTerms'], 1);
                $organizedTerms[$key]['otherTerms'] = array();
                foreach ($oT as $t) {
                    $tK = $this->calc_wiki2llxml_termkey($t);
                    if (isset($organizedTerms[$tK])) {
                        $organizedTerms[$key]['otherTerms'][$tK] = array('type' => 'existing');
                    } elseif ($tK) {
                        $organizedTerms[$tK] = array('RAWDATA' => '[alias for "' . $key . '"]', 'term' => $t, 'description' => 'See "' . $organizedTerms[$key]['term'] . '"', 'otherTerms' => array($key => array('type' => 'existing')));
                        $organizedTerms[$key]['otherTerms'][$tK] = array('type' => 'alias');
                    }
                }
                // More information splitted:
                $termData['moreInfo'] = preg_replace('#\\[\\[([^]]+)\\]\\]#', '[http://wiki.typo3.org/index.php/${1}]', $termData['moreInfo']);
                $parts = preg_split('#(\\[)([^\\]]+)(\\])#', $termData['moreInfo'], 10000, PREG_SPLIT_DELIM_CAPTURE);
                $organizedTerms[$key]['moreInfo'] = array();
                foreach ($parts as $kk => $vv) {
                    if ($kk % 2 == 0) {
                        $link = trim($vv);
                        if ($link && $link != ',') {
                            list($link, $title) = preg_split('#[ |]#', $link, 2);
                            $organizedTerms[$key]['moreInfo'][] = array('url' => $link, 'title' => $title);
                        }
                    }
                }
                // Removal of the RAW data which is not so interesting for us:
                unset($organizedTerms[$key]['RAWDATA']);
            }
            $content .= Tx_Extdeveval_Compatibility::viewArray($organizedTerms);
            ksort($organizedTerms);
            $content .= '
			<textarea rows="10" name="_" wrap="off"' . $GLOBALS['TBE_TEMPLATE']->formWidthText(48, 'width:98%;', 'off') . '>' . t3lib_div::formatForTextarea($this->calc_wiki2llxml_createXML($organizedTerms)) . '</textarea>';
        }
        return $content;
    }
    /**
     * Function rendering the status form and executing the splitting operation
     *
     * @param	array		XML file content as array!
     * @param	string		The absolute file name the content is read from
     * @return	string		HTML content.
     */
    function renderForm($fileContent, $phpFile)
    {
        // Meta Data of file
        $content .= 'Description: <b>' . htmlspecialchars($fileContent['meta']['description']) . '</b>';
        if (!@is_writable($phpFile)) {
            return 'ERROR: File "' . $phpFile . '" was not writeable!';
        }
        // Initiate:
        $languages = explode('|', TYPO3_languages);
        $createFile = t3lib_div::_POST('createFile');
        $removePoint = t3lib_div::_POST('removePoint');
        $log = array();
        $saveOriginalBack = FALSE;
        $tableRows = array();
        foreach ($languages as $lKey) {
            if ($lKey != 'default') {
                $tableCells = array();
                // Title:
                $tableCells[] = htmlspecialchars($lKey);
                // Content:
                $tableCells[] = is_array($fileContent['data'][$lKey]) ? count($fileContent['data'][$lKey]) . ' labels locally' : htmlspecialchars($fileContent['data'][$lKey]);
                // Status:
                if (!is_array($fileContent['data'][$lKey]) && strlen(trim($fileContent['data'][$lKey]))) {
                    // An external file WAS configured - we only give status then:
                    $absFileName = t3lib_div::getFileAbsFileName($fileContent['data'][$lKey]);
                    if ($absFileName) {
                        if (@is_file($absFileName)) {
                            $tableCells[] = 'External file exists, OK.';
                        } else {
                            $tableCells[] = '<b>ERROR:</b> External file did not exist, should exist!
											<hr>REMOVE POINTER: <input type="checkbox" name="removePoint[' . $lKey . ']" value="1" />';
                            if (t3lib_div::_GP('_create_') && $removePoint[$lKey]) {
                                $log[] = 'Removing pointer "' . $fileContent['data'][$lKey] . '"';
                                unset($fileContent['data'][$lKey]);
                                $saveOriginalBack = TRUE;
                            }
                        }
                    } else {
                        $tableCells[] = 'External file path did not resolve, maybe extension is not loaded.';
                    }
                } else {
                    // No external file yet:
                    $fileName = t3lib_div::llXmlAutoFileName($phpFile, $lKey);
                    #	str_replace('###LANGKEY###',$lKey,$fileContent['meta']['ext_filename_template']);
                    $absFileName = t3lib_div::getFileAbsFileName($fileName);
                    if ($absFileName) {
                        if (@is_file($absFileName)) {
                            $tableCells[] = 'External Automatic file exists, OK.';
                        } else {
                            if (t3lib_div::_GP('_create_')) {
                                if ($createFile[$lKey]) {
                                    $OK = 1;
                                    $dirname = dirname($absFileName);
                                    if (!@is_dir($dirname)) {
                                        $OK = 0;
                                        if (t3lib_div::isFirstPartOfStr($dirname, PATH_site . 'typo3conf/l10n/')) {
                                            $err = t3lib_div::mkdir_deep(PATH_site . 'typo3conf/l10n/', substr($dirname, strlen(PATH_site . 'typo3conf/l10n/')));
                                            if ($err) {
                                                $log[] = 'Creating directory ' . $dirname . ' failed';
                                            } else {
                                                $OK = 1;
                                            }
                                        } else {
                                            $log[] = 'Creating directory ' . $dirname . ' failed (2)';
                                        }
                                    }
                                    if ($OK) {
                                        // Creating data for external file:
                                        $extArray = array();
                                        // Setting language specific information in the XML file array:
                                        $extArray['data'][$lKey] = is_array($fileContent['data'][$lKey]) ? $fileContent['data'][$lKey] : array();
                                        $extArray['orig_hash'][$lKey] = is_array($fileContent['orig_hash'][$lKey]) ? $fileContent['orig_hash'][$lKey] : array();
                                        $extArray['orig_text'][$lKey] = is_array($fileContent['orig_text'][$lKey]) ? $fileContent['orig_text'][$lKey] : array();
                                        // Create XML and save file:
                                        $XML = $this->createXML($extArray, TRUE);
                                        // Write file:
                                        t3lib_div::writeFile($absFileName, $XML);
                                        // Checking if the localized file was saved as it should be:
                                        if (md5(t3lib_div::getUrl($absFileName)) == md5($XML)) {
                                            $log[] = 'Saved external XML, validated OK';
                                            // Prepare SAVING original:
                                            // Setting reference to the external file:
                                            unset($fileContent['data'][$lKey]);
                                            // Unsetting the hash and original text for this language as well:
                                            unset($fileContent['orig_hash'][$lKey]);
                                            unset($fileContent['orig_text'][$lKey]);
                                            $saveOriginalBack = TRUE;
                                        } else {
                                            $log[] = 'ERROR: MD5 sum of saved external file did not match XML going in!';
                                        }
                                    }
                                }
                            } else {
                                $tableCells[] = '
									<input type="checkbox" name="createFile[' . $lKey . ']" value="1" checked="checked" />
								File did not exist, will be created if checkbox selected.<br/>
								(' . $fileName . ')';
                            }
                        }
                    } else {
                        $tableCells[] = 'Template file path did not resolve, maybe extension is not loaded.';
                    }
                }
                // Compiling row:
                $tableRows[] = '
					<tr>
						<td>' . implode('</td>
						<td>', $tableCells) . '
						</td>
					</tr>';
            }
        }
        if (t3lib_div::_GP('_create_')) {
            // SAVING ORIGINAL FILE BACK:
            if ($saveOriginalBack) {
                $log[] = 'Saving original back now...';
                $XML = $this->createXML($fileContent);
                t3lib_div::writeFile($phpFile, $XML);
                // Checking if the main file was saved as it should be:
                if (md5(t3lib_div::getUrl($phpFile)) == md5($XML)) {
                    $log[] = 'Validated OK';
                } else {
                    $log[] = 'ERROR: MD5 sum did not match!!!';
                }
            }
            $content .= '<h3>LOG:</h3>' . implode('<br/>', $log) . '
					<hr/>
					<input type="submit" name="" value="Back" />';
        } else {
            $content .= '<table border="1" cellpadding="1" cellspacing="1">' . implode('', $tableRows) . '</table>
					<br/>
					<input type="submit" name="_create_" value="Update" />';
        }
        // Meta Data of file
        $content .= '<h3>Meta Data and default labels of file:</h3>' . 'Meta data:' . (is_array($fileContent['meta']) ? Tx_Extdeveval_Compatibility::viewArray($fileContent['meta']) : '') . 'Default labels:' . (is_array($fileContent['data']['default']) ? Tx_Extdeveval_Compatibility::viewArray($fileContent['data']['default']) : '');
        return $content;
    }
 /**
  * Determines whether a given TYPO3 version is used.
  *
  * @param string $version
  * @return boolean
  */
 protected function isAtLeastVersion($version)
 {
     return Tx_Extdeveval_Compatibility::convertVersionNumberToInteger(TYPO3_version) >= Tx_Extdeveval_Compatibility::convertVersionNumberToInteger($version);
 }
    /**
     * The main function in the class
     *
     * @param	string		The absolute path to an existing PHP file which should be analysed
     * @param	string		The local/global/system extension main directory relative to PATH_site - normally set to "typo3conf/ext/" for local extensions
     * @param	boolean		If true, an abstract of the source code of the functions will be included (approx. 500 bytes per function)
     * @return	string		HTML content from the function
     */
    function analyseFile($filepath, $extDir, $includeCodeAbstract = 1)
    {
        $wsreg = "[\t ]*\r?\n";
        #$wsreg = "[\t\n\r ]";
        // Getting the content from the phpfile.
        $content = t3lib_div::getUrl($filepath);
        $hash_current = md5($content);
        $hash_current_noWhiteSpace = md5(preg_replace('#' . $wsreg . '#', '', $content));
        // Splitting the file based on a regex:
        // NOTICE: "\{" (escaping a curly brace) should NOT be done when it is in [] - thus below it should be "[^{]" and not "[^\{]" - the last will also find backslash characters in addition to curly braces. But curly braces outside of [] seems to need this.
        $splitRegEx = chr(10) . '[' . chr(13) . chr(9) . chr(32) . ']*(' . '((private|public|protected)[[:space:]]+)?(static[[:space:]]+)?function[[:space:]]+[&]?[[:alnum:]_]+[[:space:]]*\\([^{]*' . '|' . 'class[[:space:]]+[[:alnum:]_]+[^{]*' . ')\\{[' . chr(13) . chr(9) . chr(32) . ']*' . chr(10);
        $parts = preg_split('#' . $splitRegEx . '#', $content);
        // Traversing the splitted array and putting the pieces into a new array, $fileParts, where the cut-out part is also added.
        $fileParts = array();
        $lenCount = 0;
        foreach ($parts as $k => $v) {
            if ($k) {
                // Find the part that the regex matched (which is NOT in the parts array):
                $reg = '';
                preg_match('#^' . $splitRegEx . '#', substr($content, $lenCount), $reg);
                $fileParts[] = $reg[0];
                $lenCount += strlen($reg[0]);
            }
            // ... Then add the value from the parts-array:
            $fileParts[] = $v;
            $lenCount += strlen($v);
        }
        // Finally, if the processing into the $fileParts array was successful the imploded version of this array will match the input $content. So we do this integrity check here:
        if (md5(implode('', $fileParts)) == md5($content)) {
            // Remove trailing space and "13" chars:
            foreach ($fileParts as $partKey => $partValue) {
                $partLines = explode(chr(10), str_replace(chr(13), '', $partValue));
                foreach ($partLines as $lineNum => $lineValue) {
                    $partLines[$lineNum] = rtrim($lineValue);
                }
                $fileParts[$partKey] = implode(chr(10), $partLines);
            }
            // Traversing the array, trying to find
            $visualParts = array();
            $currentClass = '';
            $this->sectionTextCounter = 0;
            $this->classCounter = 0;
            foreach ($fileParts as $k => $v) {
                $visualParts[$k] = htmlspecialchars($v);
                if ($k % 2) {
                    $this->fileInfo[$k]['header'] = trim($v);
                    $isClassName = $this->isHeaderClass($v);
                    if ($isClassName) {
                        $this->fileInfo[$k]['class'] = 1;
                        $this->classCounter++;
                        $currentClass = $isClassName;
                    }
                    $this->fileInfo[$k]['parentClass'] = $currentClass;
                    // Try to locate existing comment:
                    $SET = 0;
                    $cDat = array();
                    $comment = t3lib_div::revExplode('**/', $fileParts[$k - 1], 2);
                    if (trim($comment[1]) && preg_match('#\\*\\/$#', trim($comment[1]))) {
                        $SET = 1;
                        // There was a comment! Now, parse it.
                        if ($k > 1) {
                            $sectionText = $this->getSectionDivisionComment($comment[0]);
                            if (is_array($sectionText)) {
                                $this->sectionTextCounter++;
                                $this->fileInfo[$k]['sectionText'] = $sectionText;
                            }
                        }
                        $blankCDat = $this->tryToMakeParamTagsFromFunctionDefLine($v);
                        $cDat = $this->parseFunctionComment($comment[1], $blankCDat);
                        $this->fileInfo[$k]['cDat'] = $cDat;
                    } else {
                        $comment = t3lib_div::revExplode('}', $fileParts[$k - 1], 2);
                        if (isset($comment[1]) && !trim($comment[1])) {
                            $SET = 2;
                            $comment[0] .= '}' . chr(10) . chr(10) . '	';
                        } else {
                            $comment = t3lib_div::revExplode('{', $fileParts[$k - 1], 2);
                            if (isset($comment[1]) && !trim($comment[1])) {
                                $SET = 2;
                                $comment[0] .= '{' . chr(10) . chr(10) . '	';
                            }
                        }
                        if ($SET == 2) {
                            $cDat['text'] = '[Describe function...]';
                            // Notice, if this is ever changed, should be changes for analyser tool (see checkCommentQuality() ) as well.
                            $cDat['param'] = $this->tryToMakeParamTagsFromFunctionDefLine($v);
                            $cDat['return'] = array('[type]', '...');
                        }
                    }
                    if (!isset($fileParts[$k + 2])) {
                        // ... if this is last item!
                        $this->fileInfo[$k]['content'] = $includeCodeAbstract ? $this->includeContent($fileParts[$k + 1], $this->fileInfo[$k]['class']) : '';
                        $this->fileInfo[$k]['content_size'] = strlen($fileParts[$k + 1]);
                        $this->fileInfo[$k]['content_lines'] = substr_count($fileParts[$k + 1], chr(10));
                    } elseif (isset($this->fileInfo[$k - 2])) {
                        // ... otherwise operate on the FORMER item!
                        $this->fileInfo[$k - 2]['content'] = $includeCodeAbstract ? $this->includeContent($comment[0], $this->fileInfo[$k - 2]['class']) : '';
                        $this->fileInfo[$k - 2]['content_size'] = strlen($comment[0]);
                        $this->fileInfo[$k - 2]['content_lines'] = substr_count($comment[0], chr(10));
                    }
                    if ($SET) {
                        $commentLinesWhiteSpacePrefix = $this->getWhiteSpacePrefix($comment[0]);
                        $comment[1] = $this->generateComment($cDat, $commentLinesWhiteSpacePrefix, $this->isHeaderClass($v));
                        $origPart = $fileParts[$k - 1];
                        $fileParts[$k - 1] = implode('', $comment);
                        // If there was a change, then make a markup of the visual output:
                        $vComment = $comment;
                        $vComment[0] = htmlspecialchars($vComment[0]);
                        if ($k > 1) {
                            if (strlen($vComment[0]) > 1000) {
                                $vComment[0] = substr($vComment[0], 0, 450) . chr(10) . '<span style="color:green; font-weight:bold;">[...]</span>' . chr(10) . substr($vComment[0], -500);
                            }
                        }
                        $color = $origPart == $fileParts[$k - 1] ? 'black' : ($SET == 1 ? 'navy' : 'red');
                        $this->colorCount[$color]++;
                        $vComment[1] = '<span style="color:' . $color . '; font-weight:bold;">' . htmlspecialchars($vComment[1]) . '</span>';
                        $visualParts[$k - 1] = implode('', $vComment);
                    }
                }
            }
            // Count lines:
            $lines = 0;
            foreach ($fileParts as $k => $v) {
                if ($k % 2) {
                    $this->fileInfo[$k]['atLine'] = $lines;
                }
                $lines += substr_count($fileParts[$k], chr(10));
            }
            $fileParts[0] = $this->splitHeader($fileParts[0]);
            $visualParts[0] = '<span style="color:#663300;">' . htmlspecialchars($fileParts[0]) . '</span>';
            $output = '';
            $output .= '<b>Color count:</b><br />"red"=new comments<br />"navy"=existing, modified<br />"black"=existing, not modified' . Tx_Extdeveval_Compatibility::viewArray($this->colorCount);
            // Output the file
            if (t3lib_div::_GP('_save_script')) {
                if (@is_file($filepath) && t3lib_div::isFirstPartOfStr($filepath, PATH_site . $extDir)) {
                    $output .= '<b>SAVED TO: ' . substr($filepath, strlen(PATH_site)) . '</b>';
                    t3lib_div::writeFile($filepath, implode('', $fileParts));
                } else {
                    $output .= '<b>NO FILE/NO PERMISSION!!!: ' . substr($filepath, strlen(PATH_site)) . '</b>';
                }
                $output .= '<hr />';
                $output .= '<input type="submit" name="_" value="RETURN" />';
            } else {
                $hash_new = md5(implode('', $fileParts));
                $hash_new_noWhiteSpace = md5(preg_replace('#' . $wsreg . '#', '', implode('', $fileParts)));
                $output .= '
				' . $hash_current . ' - Current file HASH<br />
				' . $hash_new . ' - New file HASH<br />
				' . ($hash_current != $hash_new && $hash_current_noWhiteSpace == $hash_new_noWhiteSpace ? '<em>(Difference only concerns whitespace!)</em><br /><br />' : '<br />') . '
				(If the hash strings are similar you don\'t need to save since nothing would be changed)<br />
				';
                $output .= '
				<b><br />This is the substititions that will be carried out if you press the "Save" button in the bottom of this page:</b><hr />';
                $output .= '<input type="submit" name="_save_script" value="SAVE!" />';
                $output .= '<pre>' . str_replace(chr(9), '&nbsp;&nbsp;&nbsp;', implode('', $visualParts)) . '</pre>';
                $output .= '<hr />';
                $output .= '<input type="submit" name="_save_script" value="SAVE!" />';
                $output .= '<br /><br /><b>Instructions:</b><br />';
                $output .= '0) Make a backup of the script - what if something goes wrong? Are you prepared?<br />';
                $output .= '1) Press the button if you are OK with the changes. RED comments are totally new - BLUE comments are existing comments but parsed/reformatted.<br />';
            }
            return $output;
        } else {
            return 'ERROR: There was an internal error in process of splitting the PHP-script.';
        }
    }
    /**
     * The main function in the class
     *
     * @return	string		HTML content
     */
    function main()
    {
        $inputCode = t3lib_div::_GP('input_code');
        $content = '';
        $content .= '
		<textarea rows="15" name="input_code" wrap="off"' . $GLOBALS['TBE_TEMPLATE']->formWidthText(48, 'width:98%;', 'off') . '>' . t3lib_div::formatForTextarea($inputCode) . '</textarea>
		<br />
		<input type="submit" name="highlight_php" value="PHP" />
		<input type="submit" name="highlight_ts" value="TypoScript" />
		<input type="submit" name="highlight_xml" value="XML" />
		<input type="submit" name="highlight_xml2array" value="xml2array()" />
		<br />
		<input type="checkbox" name="option_linenumbers" value="1"' . (t3lib_div::_GP('option_linenumbers') ? ' checked="checked"' : '') . ' /> Linenumbers (TS/PHP)<br />
		<input type="checkbox" name="option_blockmode" value="1"' . (t3lib_div::_GP('option_blockmode') ? ' checked="checked"' : '') . ' /> Blockmode (TS)<br />
		<input type="checkbox" name="option_analytic" value="1"' . (t3lib_div::_GP('option_analytic') ? ' checked="checked"' : '') . ' /> Analytic style (TS/XML)<br />
		<input type="checkbox" name="option_showparsed" value="1"' . (t3lib_div::_GP('option_showparsed') ? ' checked="checked"' : '') . ' /> Show parsed structure (TS/XML)<br />

		';
        if (trim($inputCode)) {
            // Highlight PHP
            if (t3lib_div::_GP('highlight_php')) {
                if (substr(trim($inputCode), 0, 2) != '<?') {
                    $inputCode = '<?php' . chr(10) . chr(10) . chr(10) . $inputCode . chr(10) . chr(10) . chr(10) . '?>';
                }
                $formattedContent = highlight_string($inputCode, 1);
                if (t3lib_div::_GP('option_linenumbers')) {
                    $lines = explode('<br />', $formattedContent);
                    foreach ($lines as $k => $v) {
                        $lines[$k] = '<font color="black">' . str_pad($k - 2, 4, ' ', STR_PAD_LEFT) . ':</font> ' . $v;
                    }
                    $formattedContent = implode('<br />', $lines);
                }
                // Remove regular linebreaks
                $formattedContent = preg_replace('#[' . chr(10) . chr(13) . ']#', '', $formattedContent);
                // Wrap in <pre> tags
                $content .= '<hr /><pre class="ts-hl">' . $formattedContent . '</pre>';
            }
            // Highlight TypoScript
            if (t3lib_div::_GP('highlight_ts')) {
                $tsparser = t3lib_div::makeInstance("t3lib_TSparser");
                if (t3lib_div::_GP('option_analytic')) {
                    $tsparser->highLightStyles = $this->highLightStyles_analytic;
                    $tsparser->highLightBlockStyles_basecolor = '';
                    $tsparser->highLightBlockStyles = $this->highLightBlockStyles;
                } else {
                    $tsparser->highLightStyles = $this->highLightStyles;
                }
                $tsparser->lineNumberOffset = 0;
                $formattedContent = $tsparser->doSyntaxHighlight($inputCode, t3lib_div::_GP('option_linenumbers') ? array($tsparser->lineNumberOffset) : '', t3lib_div::_GP('option_blockmode'));
                $content .= '<hr />' . $formattedContent;
                #debug($inputCode);
                #$tsparser->xmlToTypoScriptStruct($inputCode);
                if (t3lib_div::_GP('option_showparsed')) {
                    $content .= '<hr />' . Tx_Extdeveval_Compatibility::viewArray($tsparser->setup);
                    /*
                    ob_start();
                    print_r($tsparser->setup);
                    $content.='<hr /><pre>'.ob_get_contents().'</pre>';
                    ob_end_clean();
                    */
                }
            }
            // Highlight XML
            if (t3lib_div::_GP('highlight_xml')) {
                $formattedContent = $this->xmlHighLight($inputCode, t3lib_div::_GP('option_analytic') ? $this->highLightStyles_analytic : $this->highLightStyles);
                $content .= '<hr /><em>Notice: This highlighted version of the above XML data is parsed and then re-formatted. Therefore comments are not included and a 100% similarity with the source is not guaranteed. However the content should be just as valid XML as the source (except CDATA which is not detected as such!!!).</em><br><br>' . $formattedContent;
                if (t3lib_div::_GP('option_showparsed')) {
                    $treeDat = t3lib_div::xml2tree($inputCode);
                    $content .= '<hr />';
                    $content .= 'MD5: ' . md5(serialize($treeDat));
                    $content .= Tx_Extdeveval_Compatibility::viewArray($treeDat);
                }
            }
            // Highlight XML content parsable with xml2array()
            if (t3lib_div::_GP('highlight_xml2array')) {
                $formattedContent = $this->xml2arrayHighLight($inputCode);
                $content .= '<hr /><br>' . $formattedContent;
                if (t3lib_div::_GP('option_showparsed')) {
                    $treeDat = t3lib_div::xml2array($inputCode);
                    $content .= '<hr />';
                    $content .= 'MD5: ' . md5(serialize($treeDat));
                    $content .= Tx_Extdeveval_Compatibility::viewArray($treeDat);
                }
            }
        }
        return $content;
    }