/** * Includes the locallang file for the 'formhandler' extension * * @return array The LOCAL_LANG array */ function includeLocalLang() { $llFile = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('formhandler') . 'Resources/Language/locallang_db.xml'; $parser = TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Localization\\Parser\\LocallangXmlParser'); $LOCAL_LANG = $parser->getParsedData($llFile, $GLOBALS['LANG']->lang, 'utf-8'); return $LOCAL_LANG; }
/** * Returns content of a file. If it's an image the content of the file is not returned but rather an image tag is. * This method is taken from tslib_content * TODO: cache result * * @param string The filename, being a TypoScript resource data type or a FAL-Reference (file:123) * @param string Additional parameters (attributes). Default is empty alt and title tags. * @return string If jpg,gif,jpeg,png: returns image_tag with picture in. If html,txt: returns content string * @see FILE() */ public static function getFileResource($fName, $options = array()) { if (!(is_object($GLOBALS['TSFE']) && is_object($GLOBALS['TSFE']->tmpl))) { tx_rnbase::load('tx_rnbase_util_Misc'); tx_rnbase_util_Misc::prepareTSFE(array('force' => TRUE)); } if (self::isFALReference($fName)) { /** @var FileRepository $fileRepository */ $fileRepository = TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository'); $fileObject = $fileRepository->findByUid(intval(substr($fName, 5))); $incFile = is_object($fileObject) ? $fileObject->getForLocalProcessing(FALSE) : FALSE; } else { $incFile = self::getFileName($fName); } if ($incFile) { // Im BE muss ein absoluter Pfad verwendet werden $fullPath = TYPO3_MODE == 'BE' ? PATH_site . $incFile : $incFile; $utility = tx_rnbase_util_Typo3Classes::getGeneralUtilityClass(); $fileinfo = $utility::split_fileref($incFile); if ($utility::inList('jpg,gif,jpeg,png', $fileinfo['fileext'])) { $imgFile = $incFile; $imgInfo = @getImageSize($imgFile); $addParams = isset($options['addparams']) ? $options['addparams'] : 'alt="" title=""'; $ret = '<img src="' . $GLOBALS['TSFE']->absRefPrefix . $imgFile . '" width="' . $imgInfo[0] . '" height="' . $imgInfo[1] . '"' . self::getBorderAttr(' border="0"') . ' ' . $addParams . ' />'; } elseif (file_exists($fullPath) && filesize($fullPath) < 1024 * 1024) { $ret = @file_get_contents($fullPath); $subpart = isset($options['subpart']) ? $options['subpart'] : ''; if ($subpart) { tx_rnbase::load('tx_rnbase_util_Templates'); $ret = tx_rnbase_util_Templates::getSubpart($ret, $subpart); } } } return $ret; }
/** * tx_t3devapi_export::exportRecordsToXML() * Example : * $query['SELECT'] = 'uid,title,category'; * $query['FROM'] = 'tt_news'; * $query['WHERE'] = ''; * * @param array $query * @return string */ public function exportRecordsToXML($query) { $xmlObj = TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('t3lib_xml', 'typo3_export'); $xmlObj->setRecFields($query['FROM'], $query['SELECT']); $xmlObj->renderHeader(); $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($query['SELECT'], $query['FROM'], $query['WHERE'], $query['GROUPBY'], $query['ORDERBY'], $query['LIMIT']); $xmlObj->renderRecords($query['FROM'], $res); $xmlObj->renderFooter(); $GLOBALS['TYPO3_DB']->sql_free_result($res); return $xmlObj->getResult(); }
/** * Loads a template file and generate the content * * @param array $context datas to send * @return string */ public function fluidView($context = array()) { $renderer = TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Fluid_View_TemplateView'); $controllerContext = TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Extbase_MVC_Controller_ControllerContext'); $controllerContext->setRequest(TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Extbase_MVC_Web_Request')); $renderer->setControllerContext($controllerContext); $renderer->setPartialRootPath(TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($this->extKey) . "res/partials/"); $renderer->setTemplateRootPath(TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($this->extKey) . "res/templates/"); $renderer->setLayoutRootPath(TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($this->extKey) . "res/layouts"); $renderer->setTemplatePathAndFilename($this->template); foreach ($context as $key => $value) { $renderer->assign($key, $value); } return $renderer->render(); }
/** * Find all ids from given ids and level * * @param string $pidList comma separated list of ids * @param integer $recursive recursive levels * @return string comma separated list of ids */ public static function extendPidListByChildren($pidList = '', $recursive = 0) { $recursive = (int) $recursive; if ($recursive <= 0) { return $pidList; } $queryGenerator = TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\QueryGenerator'); $recursiveStoragePids = $pidList; $storagePids = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $pidList); foreach ($storagePids as $startPid) { $pids = $queryGenerator->getTreeList($startPid, $recursive, 0, 'hidden=0'); if (strlen($pids) > 0) { $recursiveStoragePids .= ',' . $pids; } } return $recursiveStoragePids; }
/** * Get the result row with getProcessedValueExtra() * It allow you to respect the TCA rules * * @param array $row * @param string $table * @return array */ public static function getResultRow($row, $table) { $record = array(); foreach ($row as $fieldName => $fieldValue) { if (TYPO3_MODE == 'FE') { // $GLOBALS['TSFE']->includeTCA(); $GLOBALS['LANG'] = TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Lang\\LanguageService'); $GLOBALS['LANG']->init($GLOBALS['TSFE']->tmpl->setup['config.']['language']); } $record[$fieldName] = \TYPO3\CMS\Backend\Utility\BackendUtility::getProcessedValueExtra($table, $fieldName, $fieldValue, 0, $row['uid']); } return $record; }
/** * Get the HTML code of the pahe browser * * @param int $numberOfPages * @return string HTML code */ public function getHTMLPageBrowser($numberOfPages) { $conf = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_pagebrowse_pi1.']; $conf = array_merge($conf, array('pageParameterName' => $this->prefixId . '|page', 'numberOfPages' => $numberOfPages)); $cObj = TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer'); $cObj->start(array(), ''); return $cObj->cObjGetSingle('USER', $conf); }
/** * Return the HTML code of the RTE content passed through the process * * @param string $val * @param array $dataArray * @return string */ public function getRTEContent($val, $dataArray) { if (!$this->RTEObj) { /** @var $RTEObj tx_rtehtmlarea_pi2 */ $this->RTEObj = TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_rtehtmlarea_pi2'); } if ($this->RTEObj->isAvailable()) { return $this->RTEObj->transformContent('db', $val, $this->table, $this->field, $dataArray, $this->specConf, $this->thisConfig, '', $this->thePidValue); } }
/** * Build the TSFE (for the BE for example) * * @param int $pid * @return void */ public static function initTSFE($id) { if (tx_additionalreports_util::intFromVer(TYPO3_version) < 6002000) { require_once PATH_t3lib . 'class.t3lib_befunc.php'; require_once PATH_t3lib . 'stddb/tables.php'; require_once PATH_tslib . 'class.tslib_pagegen.php'; require_once PATH_tslib . 'class.tslib_fe.php'; require_once PATH_t3lib . 'class.t3lib_page.php'; require_once PATH_tslib . 'class.tslib_content.php'; require_once PATH_t3lib . 'class.t3lib_userauth.php'; require_once PATH_tslib . 'class.tslib_feuserauth.php'; require_once PATH_t3lib . 'class.t3lib_tstemplate.php'; require_once PATH_t3lib . 'class.t3lib_cs.php'; } if (!is_object($GLOBALS['TT'])) { $GLOBALS['TT'] = TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('t3lib_TimeTrackNull'); } if (version_compare(TYPO3_version, '4.3.0', '<')) { $tsfeClassName = TYPO3\CMS\Core\Utility\GeneralUtility::makeInstanceClassName('tslib_fe'); $GLOBALS['TSFE'] = new $tsfeClassName($GLOBALS['TYPO3_CONF_VARS'], $id, ''); } else { $GLOBALS['TSFE'] = TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tslib_fe', $GLOBALS['TYPO3_CONF_VARS'], $id, ''); } $GLOBALS['TSFE']->connectToDB(); $GLOBALS['TSFE']->initFEuser(); //$GLOBALS['TSFE']->checkAlternativeIdMethods(); $GLOBALS['TSFE']->determineId(); $GLOBALS['TSFE']->getCompressedTCarray(); $GLOBALS['TSFE']->initTemplate(); $GLOBALS['TSFE']->getConfigArray(); }
/** * Processes helpers TS : finds and evaluates them in HTML code. * Example : ###TS:path.to.some.ts.property.or.content.object### * * @param array $templateMarkers * @param string $content * @param array $viewHelperArgumentLists * @return string */ protected function processHelpersTs($templateMarkers, $content, $viewHelperArgumentLists) { foreach ($viewHelperArgumentLists as $viewHelperArgument) { $path = $viewHelperArgument; $pathExploded = explode('.', trim($path)); $depth = count($pathExploded); $pathBranch = $GLOBALS['TSFE']->tmpl->setup; $value = ''; for ($i = 0; $i < $depth; $i++) { if ($i < $depth - 1) { $pathBranch = $pathBranch[$pathExploded[$i] . '.']; } elseif (empty($pathExploded[$i])) { // path ends with a dot. We return the rest of the array $value = $pathBranch; } else { // path ends without a dot. We return the value. $value = $pathBranch[$pathExploded[$i]]; if (isset($pathBranch[$pathExploded[$i] . '.'])) { // okay, seems to be a TS Content Element, let's run it $cObj = TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer'); $value = $cObj->cObjGetSingle($pathBranch[$pathExploded[$i]], $pathBranch[$pathExploded[$i] . '.']); } } } $content = \TYPO3\CMS\Core\Html\HtmlParser::substituteMarker($content, '###TS:' . $viewHelperArgument . '###', $value); } return $content; }
/** * Generate the dbcheck report * * @return string HTML code */ public static function displayDbCheck() { $sqlStatements = tx_additionalreports_util::getSqlUpdateStatements(); $dbchecks = array(); if (!empty($sqlStatements['update']['add'])) { $dbchecks[1]['title'] = 'Add fields'; $dbchecks[1]['items'] = $sqlStatements['update']['add']; } if (!empty($sqlStatements['update']['change'])) { $dbchecks[2]['title'] = 'Changing fields'; foreach ($sqlStatements['update']['change'] as $itemKey => $itemValue) { if (isset($sqlStatements['update']['change_currentValue'][$itemKey])) { $dbchecks[2]['items'][] = $itemValue . ' -- [current: ' . $sqlStatements['update']['change_currentValue'][$itemKey] . ']'; } else { $dbchecks[2]['items'][] = $itemValue; } } } if (!empty($sqlStatements['remove']['change'])) { $dbchecks[3]['title'] = 'Remove unused fields (rename with prefix)'; $dbchecks[3]['items'] = $sqlStatements['remove']['change']; } if (!empty($sqlStatements['remove']['drop'])) { $dbchecks[4]['title'] = 'Drop fields (really!)'; $dbchecks[4]['items'] = $sqlStatements['remove']['drop']; } if (!empty($sqlStatements['update']['create_table'])) { $dbchecks[5]['title'] = 'Add tables'; $dbchecks[5]['items'] = $sqlStatements['update']['create_table']; } if (!empty($sqlStatements['remove']['change_table'])) { $dbchecks[6]['title'] = 'Removing tables (rename with prefix)'; foreach ($sqlStatements['remove']['change_table'] as $itemKey => $itemValue) { if (!empty($sqlStatements['remove']['tables_count'][$itemKey])) { $dbchecks[6]['items'][] = $itemValue . ' -- [' . $sqlStatements['remove']['tables_count'][$itemKey] . ']'; } else { $dbchecks[6]['items'][] = $itemValue . ' -- [empty]'; } } } if (!empty($sqlStatements['remove']['drop_table'])) { $dbchecks[7]['title'] = 'Drop tables (really!)'; foreach ($sqlStatements['remove']['drop_table'] as $itemKey => $itemValue) { if (!empty($sqlStatements['remove']['tables_count'][$itemKey])) { $dbchecks[7]['items'][] = $itemValue . ' -- [' . $sqlStatements['remove']['tables_count'][$itemKey] . ']'; } else { $dbchecks[7]['items'][] = $itemValue . ' -- [empty]'; } } } // dump sql structure $items = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('table_name', 'information_schema.tables', 'table_schema = \'' . TYPO3_db . '\'', '', 'table_name'); $sqlStructure = ''; foreach ($items as $table) { $resSqlDump = $GLOBALS['TYPO3_DB']->sql_query('SHOW CREATE TABLE ' . $table['table_name']); $sqlDump = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($resSqlDump); $sqlStructure .= $sqlDump['Create Table'] . "\r\n\r\n"; $GLOBALS['TYPO3_DB']->sql_free_result($resSqlDump); } $content = '<h3 class="uppercase">Dump SQL Structure (md5:' . md5($sqlStructure) . ')</h3>'; $content .= '<textarea style="width:100%;height:200px;">' . $sqlStructure . '</textarea>'; $view = TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Fluid\\View\\StandaloneView'); $view->setTemplatePathAndFilename(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('additional_reports') . 'Resources/Private/Templates/dbcheck-fluid.html'); $view->assign('dbchecks', $dbchecks); return $view->render() . $content; }
/** * Generates the module content * * @return void */ function moduleContent() { $this->extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ke_search']); $content = ''; $do = TYPO3\CMS\Core\Utility\GeneralUtility::_GET('do'); switch ((string) $this->MOD_SETTINGS['function']) { // start indexing process case 1: // make indexer instance and init /* @var $indexer tx_kesearch_indexer */ $indexer = TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_kesearch_indexer'); // get indexer configurations $indexerConfigurations = $indexer->getConfigurations(); // action: start indexer or remove lock if ($do == 'startindexer') { // start indexing in verbose mode with cleanup process $content .= $indexer->startIndexing(true, $this->extConf); } else { if ($do == 'rmLock') { // remove lock from registry - admin only! if ($GLOBALS['BE_USER']->user['admin']) { $this->registry->removeAllByNamespace('tx_kesearch'); } else { $content .= '<p>' . $GLOBALS['LANG']->getLL('not_allowed_remove_indexer_lock') . '</p>'; } } } // show information about indexer configurations and number of records // if action "start indexing" is not selected if ($do != 'startindexer') { $content .= $this->printIndexerConfigurations($indexerConfigurations); $content .= $this->printNumberOfRecords(); } // check for index process lock in registry // remove lock if older than 12 hours $lockTime = $this->registry->get('tx_kesearch', 'startTimeOfIndexer'); $compareTime = time() - 60 * 60 * 12; if ($lockTime !== null && $lockTime < $compareTime) { // lock is older than 12 hours // remove lock and show "start index" button $this->registry->removeAllByNamespace('tx_kesearch'); $lockTime = null; } // show "start indexing" or "remove lock" button if ($lockTime !== null) { if (!$GLOBALS['BE_USER']->user['admin']) { // print warning message for non-admins $content .= '<br /><p style="color: red; font-weight: bold;">WARNING!</p>'; $content .= '<p>The indexer is already running and can not be started twice.</p>'; } else { // show 'remove lock' button for admins $content .= '<br /><p>The indexer is already running and can not be started twice.</p>'; $content .= '<p>The indexing process was started at ' . strftime('%c', $lockTime) . '.</p>'; $content .= '<p>You can remove the lock by clicking the following button.</p>'; $moduleUrl = TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('web_txkesearchM1', array('id' => $this->id, 'do' => 'rmLock')); $content .= '<br /><a class="lock-button" href="' . $moduleUrl . '">RemoveLock</a>'; } } else { // no lock set - show "start indexer" link if indexer configurations have been found if ($indexerConfigurations) { $moduleUrl = TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('web_txkesearchM1', array('id' => $this->id, 'do' => 'startindexer')); $content .= '<br /><a class="index-button" href="' . $moduleUrl . '">' . $GLOBALS['LANG']->getLL('start_indexer') . '</a>'; } else { $content .= '<div class="alert alert-info">' . $GLOBALS['LANG']->getLL('no_indexer_configurations') . '</div>'; } } $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('start_indexer'), $content, 0, 1); break; // show indexed content // show indexed content case 2: if ($this->id) { // page is selected: get indexed content $content = '<h2>Index content for page ' . $this->id . '</h2>'; $content .= $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.path') . ': ' . TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($this->pageinfo['_thePath'], -50); $content .= $this->getIndexedContent($this->id); } else { // no page selected: show message $content = '<div class="alert alert-info">' . $GLOBALS['LANG']->getLL('select_a_page') . '</div>'; } $this->content .= $this->doc->section('Show Indexed Content', $content, 0, 1); break; // index table information // index table information case 3: $content = $this->renderIndexTableInformation(); $this->content .= $this->doc->section('Index Table Information', $content, 0, 1); break; // searchword statistics // searchword statistics case 4: // days to show $days = 30; $content = $this->getSearchwordStatistics($this->id, $days); $this->content .= $this->doc->section('Searchword Statistics for the last ' . $days . ' days', $content, 0, 1); break; // clear index // clear index case 5: $content = ''; // admin only access if ($GLOBALS['BE_USER']->user['admin']) { if ($do == 'clear') { $query = 'TRUNCATE TABLE tx_kesearch_index' . $table; $res = $GLOBALS['TYPO3_DB']->sql_query($query); } $content .= '<p>' . $GLOBALS['LANG']->getLL('index_contains') . ' ' . $this->getNumberOfRecordsInIndex() . ' ' . $GLOBALS['LANG']->getLL('records') . '.</p>'; // show "clear index" link $moduleUrl = TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('web_txkesearchM1', array('id' => $this->id, 'do' => 'clear')); $content .= '<br /><a class="index-button" href="' . $moduleUrl . '">Clear whole search index!</a>'; } else { $content .= '<p>Clear search index: This function is available to admins only.</p>'; } $this->content .= $this->doc->section('Clear Index', $content, 0, 1); break; // last indexing report // last indexing report case 6: $content = $this->showLastIndexingReport(); $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('function6'), $content, 0, 1); break; } }