/**
  * creates the searchbox
  * 1. fills the marker for marker based templating and renders the searchbox
  * 2. fills fluid variables for fluid based templating to $this->fluidTemplateVariables
  *
  * @return string rendered searchbox (for static or ajax templating, not for fluid templating)
  */
 public function getSearchboxContent()
 {
     // get main template code
     $content = $this->cObj->getSubpart($this->templateCode, '###SEARCHBOX_STATIC###');
     // set page = 1 if not set yet or if we are in static mode
     if (!$this->piVars['page'] || $this->conf['renderMethod'] == 'static' || $this->conf['renderMethod'] == "fluidtemplate") {
         $pageValue = 1;
     } else {
         $pageValue = $this->piVars['page'];
     }
     $content = $this->cObj->substituteMarker($content, '###HIDDEN_PAGE_VALUE###', $pageValue);
     $this->fluidTemplateVariables['page'] = $pageValue;
     // submit
     $content = $this->cObj->substituteMarker($content, '###SUBMIT_VALUE###', $this->pi_getLL('submit'));
     $this->fluidTemplateVariables['submitAltText'] = $this->pi_getLL('submit');
     // searchword input value
     $searchString = $this->piVars['sword'];
     if (!empty($searchString) && $searchString != $this->pi_getLL('searchbox_default_value')) {
         $this->swordValue = $searchString;
         $searchboxFocusJS = '';
         $searchboxBlurJS = '';
     } else {
         $this->swordValue = $this->pi_getLL('searchbox_default_value');
         // set javascript for resetting searchbox value
         $searchboxFocusJS = 'searchboxFocus(this);';
         $searchboxBlurJS = 'searchboxBlur(this);';
     }
     $content = $this->cObj->substituteMarker($content, '###SWORD_VALUE###', htmlspecialchars($this->swordValue));
     $this->fluidTemplateVariables['searchword'] = htmlspecialchars($this->swordValue);
     $content = $this->cObj->substituteMarker($content, '###SEARCHBOX_DEFAULT_VALUE###', htmlspecialchars($this->pi_getLL('searchbox_default_value')));
     $this->fluidTemplateVariables['searchwordDefault'] = htmlspecialchars($this->pi_getLL('searchbox_default_value'));
     $content = $this->cObj->substituteMarker($content, '###SWORD_ONFOCUS###', $searchboxFocusJS);
     $content = $this->cObj->substituteMarker($content, '###SWORD_ONBLUR###', $searchboxBlurJS);
     $content = $this->cObj->substituteMarker($content, '###SORTBYFIELD###', $this->piVars['sortByField']);
     $this->fluidTemplateVariables['sortByField'] = $this->piVars['sortByField'];
     $content = $this->cObj->substituteMarker($content, '###SORTBYDIR###', $this->piVars['sortByDir']);
     $this->fluidTemplateVariables['sortByDir'] = $this->piVars['sortByDir'];
     // set onsubmit action
     if ($this->conf['renderMethod'] != 'static') {
         $onSubmitMarker = 'onsubmit="document.getElementById(\'pagenumber\').value=1;"';
     } else {
         $onSubmitMarker = '';
     }
     $content = $this->cObj->substituteMarker($content, '###ONSUBMIT###', $onSubmitMarker);
     // get filters
     $renderedFilters = $this->renderFilters();
     $content = $this->cObj->substituteMarker($content, '###FILTER###', $renderedFilters);
     $this->fluidTemplateVariables['filter'] = $renderedFilters;
     // set form action pid
     $content = $this->cObj->substituteMarker($content, '###FORM_TARGET_PID###', $this->conf['resultPage']);
     $this->fluidTemplateVariables['targetpage'] = $this->conf['resultPage'];
     // set form action
     $siteUrl = TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
     $lParam = TYPO3\CMS\Core\Utility\GeneralUtility::_GET('L');
     $mpParam = TYPO3\CMS\Core\Utility\GeneralUtility::_GET('MP');
     $typeParam = TYPO3\CMS\Core\Utility\GeneralUtility::_GP('type');
     $actionUrl = $siteUrl . 'index.php';
     $content = $this->cObj->substituteMarker($content, '###FORM_ACTION###', $actionUrl);
     $this->fluidTemplateVariables['actionUrl'] = $actionUrl;
     // set other hidden fields
     $hiddenFieldsContent = '';
     // language parameter
     if (isset($lParam)) {
         $hiddenFieldValue = intval($lParam);
         $hiddenFieldsContent .= '<input type="hidden" name="L" value="' . $hiddenFieldValue . '" />';
         $this->fluidTemplateVariables['lparam'] = $hiddenFieldValue;
     }
     // mountpoint parameter
     if (isset($mpParam)) {
         // the only allowed characters in the MP parameter are digits and , and -
         $hiddenFieldValue = preg_replace('/[^0-9,-]/', '', $mpParam);
         $hiddenFieldsContent .= '<input type="hidden" name="MP" value="' . $hiddenFieldValue . '" />';
         $this->fluidTemplateVariables['mpparam'] = $hiddenFieldValue;
     }
     $content = $this->cObj->substituteMarker($content, '###HIDDENFIELDS###', $hiddenFieldsContent);
     // type param
     if ($typeParam) {
         $hiddenFieldValue = intval($typeParam);
         $typeContent = $this->cObj->getSubpart($this->templateCode, '###SUB_PAGETYPE###');
         $typeContent = $this->cObj->substituteMarker($typeContent, '###PAGETYPE###', $typeParam);
         $this->fluidTemplateVariables['typeparam'] = $hiddenFieldValue;
     } else {
         $typeContent = '';
     }
     $content = $this->cObj->substituteSubpart($content, '###SUB_PAGETYPE###', $typeContent, $recursive = 1);
     // add submit button in static mode
     if ($this->conf['renderMethod'] == 'static') {
         $submitButton = '<input type="submit" value="' . $this->pi_getLL('submit') . '" />';
     } else {
         $submitButton = '';
     }
     $content = $this->cObj->substituteMarker($content, '###SUBMIT###', $submitButton);
     // set reset link
     unset($linkconf);
     $linkconf['parameter'] = $this->conf['resultPage'];
     $resetUrl = $this->cObj->typoLink_URL($linkconf);
     $this->fluidTemplateVariables['resetUrl'] = $resetUrl;
     $resetLink = '<a href="' . $resetUrl . '" class="resetButton"><span>' . $this->pi_getLL('reset_button') . '</span></a>';
     $content = $this->cObj->substituteMarker($content, '###RESET###', $resetLink);
     // init onDomReadyAction
     $this->initDomReadyAction();
     return $content;
 }
示例#2
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;
     }
 }