Fixed bug ##1740: date parameters are not configurable in indexed search
authorDmitry Dulepov <dmitry.dulepov@gmail.com>
Tue, 13 Apr 2010 12:00:16 +0000 (12:00 +0000)
committerDmitry Dulepov <dmitry.dulepov@gmail.com>
Tue, 13 Apr 2010 12:00:16 +0000 (12:00 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@7339 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/sysext/indexed_search/ext_typoscript_setup.txt
typo3/sysext/indexed_search/pi/class.tx_indexedsearch.php

index 7502cd8..111a9e8 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@
 
        * Fixed bug #14027: Tweak: Add "tiff" to imagefile_ext array
        * Fixed bug #14023: choose proper variable namings in tslib_cObj::getGlobal()
+       * Fixed bug ##1740: date parameters are not configurable in indexed search
 
 2010-04-13  Patrick Broens  <patrick@patrickbroens.nl>
 
index 8230a7b..ec05d07 100755 (executable)
@@ -5,6 +5,12 @@ config.index_metatags = 1
 plugin.tx_indexedsearch {
        templateFile = EXT:indexed_search/pi/indexed_search.tmpl
 
+       # Date formats for created/modified dates in search results. See PHP strftime() function. Leave blank for using system defaults
+       dateFormat {
+               created =
+               modified =
+       }
+
        show {
                rules = 1
                parsetimes = 0
index 9ae8301..3b76ab8 100755 (executable)
@@ -2096,12 +2096,9 @@ class tx_indexedsearch extends tslib_pibase {
         * @return      array           Modified template array
         */
        function makeInfo($row,$tmplArray)      {
-               $dateFormat = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'];
-               $timeFormat = $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'];
-
                $tmplArray['size'] = t3lib_div::formatSize($row['item_size']);
-               $tmplArray['created'] = date($dateFormat, $row['item_crdate']);
-               $tmplArray['modified'] = date($dateFormat.' '.$timeFormat, $row['item_mtime']);
+               $tmplArray['created'] = $this->formatCreatedDate($row['item_crdate']);
+               $tmplArray['modified'] = $this->formatModifiedDate($row['item_mtime']);
 
                $pathId = $row['data_page_id']?$row['data_page_id']:$row['page_id'];
                $pathMP = $row['data_page_id']?$row['data_page_mp']:'';
@@ -2427,6 +2424,51 @@ class tx_indexedsearch extends tslib_pibase {
                }
                return $result;
        }
+
+       /**
+        * Formats date as 'created' date
+        *
+        * @param int $date
+        * @param string $defaultFormat
+        * @return string
+        */
+       protected function formatCreatedDate($date) {
+               $defaultFormat = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'];
+               return $this->formatDate($date, 'created', $defaultFormat);
+       }
+
+       /**
+        * Formats date as 'modified' date
+        *
+        * @param int $date
+        * @param string $defaultFormat
+        * @return string
+        */
+       protected function formatModifiedDate($date) {
+               $defaultFormat = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] . ' ' .
+                       $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'];
+               return $this->formatDate($date, 'modified', $defaultFormat);
+       }
+
+       /**
+        * Formats the date using format string from TypoScript or default format
+        * if TypoScript format is not set
+        *
+        * @param int $date
+        * @param string $tsKey
+        * @param string $defaultFormat
+        * @return string
+        */
+       protected function formatDate($date, $tsKey, $defaultFormat) {
+               $strftimeFormat = $this->conf['dateFormat.'][$tsKey];
+               if ($strftimeFormat) {
+                       $result = strftime($strftimeFormat, $date);
+               }
+               else {
+                       $result = date($defaultFormat, $date);
+               }
+               return $result;
+       }
 }