[Typo3-dev] Dynamic upload-file description (php function)

dan frost dan at danfrost.co.uk
Mon Jul 21 11:53:07 CEST 2003


Hello all,

Because there was no response to my SWITCH and CASE posting, I wrote a 
function in Php to handle the job. Please find it below.
The class would be included as a USER function. It's documented and has 
a TS example in the comments.

I have found myself having to write a number of such functions - for 
example, a bytes_only function, which doesn't append the bytes value 
with a "K".

My question is: what is the best way to implement these functions - as 
an extension to tslib_content; as an extension which acts as a library 
of functions; as a template acting as a library; or something else. Or, 
is there an extension, or project of sundry TS functions and scripts 
(much like CPAN is to PERL)?

Any responses greatly appreciated.

Cheers,
dan


<--- CODE --->
class user_string_functions {
     function custom_tag($content, $conf) {
       /*
       * GNU License, D. Frost, 21st July 2003.
       *
       * -- needs testing with various file-system and file-resource 
inputs. --
       */
       /* function custom_tag($content, $conf) {}
       *
       *  Takes (required) filename and (optional) tag lines
       *  Returns a suitable tag-line, determined by the suffix of the 
filename
       *
       * Variables:
       *  $content         - not used.
       *  $conf[filename]    - required. The value to divide and round
       *  $conf[suffix.]   - optional. Sets tag lines for
       *
       * Example use:
             # include the standard library
       includeLibs.test_library = fileadmin/dan_fold/includeLibs.inc
             user.10 = USER
       user.10.userFunc =  user_string_functions->custom_tag
       user.10 {
           # pass file name - can be any length, with any number of 
full-stops (.)
           filename =   my.fat.document.log
                 # pass custom tag lines as required, Syntax (vars in 
<..>s):
           # suffix.<eg> = <some tag line>
           suffix.doc = Wordy, wordy
           suffix.xls = cells cells cells
           suffix.log = Log files
       }
       *
       */
       # test input values - log error if required values not present
       if($conf["filename"]) {
           # standard tag-lines
           $tag_lines = array( "doc" => "Word Document",
                               "xls" => "Excel Spreadsheet",
                               "pdf" => "Adobe Pdf File",
                               "html" => "Html (internet) File",
                               "mp3" => "Mp3, media file",
                               "mpeg" => "Mpeg media file",
                               "jpg" => "Jpeg image file",
                               "Gif" => "Gif image file",
                               "suffix" => "Tag line goes here");
                     # 1. get suffix from $conf[filename] and make ALL 
LOWERCASE!
           preg_match("/.+(\.)([\w]{2,10})/", trim($conf["filename"]), 
$out);
           $suffix = $out[2];
                     # 2. if $conf[suffix] is set (holds custom taglines) -
           #     ..then set the array entries (set above)
           if($conf["suffix."]) {
               foreach($conf["suffix."] as $suf => $tagline) {
                   $tag_lines[$suf] = $tagline;
               }
           }
                     # return tag line, if there is one. If not, returns 
"";
           return $tag_lines[$suffix] ? $tag_lines[$suffix] : "";
       } else {
           // log an error          }
   }
}
<--- CODE --->







More information about the TYPO3-dev mailing list