Esempio n. 1
0
 /**
  * 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;
     }
 }