Added feature #7199: Add TypoScript options to remove spaces and file extensions...
authorJeff Segars <jsegars@alumni.rice.edu>
Tue, 16 Nov 2010 17:35:34 +0000 (17:35 +0000)
committerJeff Segars <jsegars@alumni.rice.edu>
Tue, 16 Nov 2010 17:35:34 +0000 (17:35 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@9405 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/sysext/css_styled_content/pi1/class.tx_cssstyledcontent_pi1.php
typo3/sysext/css_styled_content/static/setup.txt

index 9b1d247..2efce14 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2010-11-16  Jeff Segars  <jeff@webempoweredchurch.org>
+
+       * Added feature #7199: Add TypoScript options to remove spaces and file extensions from link text for uploads (Thanks to Steffen Ritter)
+
 2010-11-16  Christian Kuhn  <lolli@schwarzbu.ch>
 
        * Added feature #16360: [saltedpasswords] Provide a task for bulk update of passwords for use with saltedpasswords (Thanks to Marcus Krause)
index e7dcba7..e0e4084 100755 (executable)
@@ -325,6 +325,9 @@ class tx_cssstyledcontent_pi1 extends tslib_pibase {
                                if ($conf['labelStdWrap.']) {
                                        $conf['linkProc.']['labelStdWrap.'] = $conf['labelStdWrap.'];
                                }
+                               if ($conf['useSpacesInLinkText'] || $conf['stripFileExtensionFromLinkText']) {
+                                       $conf['linkProc.']['removePrependedNumbers'] = 0;
+                               }
 
                                        // Traverse the files found:
                                $filesData = array();
@@ -347,7 +350,18 @@ class tx_cssstyledcontent_pi1 extends tslib_pibase {
                                                $GLOBALS['TSFE']->register['fileSize'] = $filesData[$key]['filesize'];
                                                $GLOBALS['TSFE']->register['fileExtension'] = $filesData[$key]['fileextension'];
                                                $GLOBALS['TSFE']->register['description'] = $filesData[$key]['description'];
-                                               $filesData[$key]['linkedFilenameParts'] = explode('//**//',$this->cObj->filelink($fileName, $conf['linkProc.']));
+                                               $filesData[$key]['linkedFilenameParts']
+                                                       = $this->beautifyFileLink(
+                                                               explode(
+                                                                       '//**//',
+                                                                       $this->cObj->filelink(
+                                                                               $fileName, $conf['linkProc.']
+                                                                       )
+                                                               ),
+                                                               $fileName,
+                                                               $conf['useSpacesInLinkText'],
+                                                               $conf['stripFileExtensionFromLinkText']
+                                                       );
                                        }
                                }
 
@@ -874,6 +888,40 @@ class tx_cssstyledcontent_pi1 extends tslib_pibase {
         ************************************/
 
        /**
+        * Returns a link text string which replaces underscores in filename with
+        * blanks.
+        *
+        * Has the possibility to cut off FileType.
+
+        * @param array $links
+        *        array with [0] linked file icon, [1] text link
+        * @param string $fileName
+        *        the name of the file to be linked (without path)
+        * @param boolean $useSpaces
+        *        whether underscores in the file name should be replaced with spaces
+        * @param boolean $cutFileExtension
+        *        whether the file extension should be removed
+        *
+        * @return array modified array with new link text
+        */
+       protected function beautifyFileLink(
+               array $links, $fileName, $useSpaces = FALSE, $cutFileExtension = FALSE
+       ) {
+               $linkText = $fileName;
+               if ($useSpaces) {
+                       $linkText = str_replace('_', ' ', $linkText);
+               }
+               if ($cutFileExtension) {
+                       $pos = strrpos($linkText, '.');
+                       $linkText = substr($linkText, 0, $pos);
+               }
+               $links[1] = str_replace(
+                       '>' . $fileName . '<', '>' . $linkText . '<', $links[1]
+               );
+               return $links;
+       }
+
+       /**
         * Returns table attributes for uploads / tables.
         *
         * @param       array           TypoScript configuration array
index 9e542e1..2409d16 100644 (file)
@@ -879,6 +879,8 @@ tt_content.uploads {
                        30.bytes = 1
                        30.bytes.labels = {$styles.content.uploads.filesizeBytesLabels}
                }
+               useSpacesInLinkText = 0
+               stripFileExtensionFromLinkText = 0
        }
 
        20.color {