Valery Romanchev |
25.02.2008 15:14 |
[snippet] FCE для загрузки файлов (с иконкой и размером файла)
Иногда нужны кастомные FCE для download section
вот пример (здесь вручную вставляется картинка для PDF файла, поскольку на продакшен сервере не работала нормально генерерация превью для PDF)
Код:
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<T3DataStructure>
<meta type="array">
<langDisable>1</langDisable>
</meta>
<ROOT type="array">
<tx_templavoila type="array">
<title>ROOT</title>
<description>Select the HTML element on the page which you want to be the overall container element for the template.</description>
</tx_templavoila>
<type>array</type>
<el type="array">
<field_subtitle type="array">
<tx_templavoila type="array">
<title>Subtitle</title>
<sample_data type="array">
<numIndex index="0"></numIndex>
</sample_data>
<eType>input</eType>
<TypoScript><![CDATA[
10 < lib.fce_title
10.wrap = <p class="file-title">|</p>
20 = TEXT
20 {
field = field_subtitle
required = 1
#typolink.parameter.field = field_file
wrap = <p class="file-subtitle">|</p>
}
30 = COA
30 {
wrap = <p class="file-filename">(|)</p>
10 = TEXT
10 {
field = field_file
postUserFunc = user_get_filename
}
}
}]]></TypoScript>
</tx_templavoila>
<TCEforms type="array">
<config type="array">
<type>input</type>
<size>48</size>
<eval>trim</eval>
</config>
<label>Subtitle</label>
</TCEforms>
</field_subtitle>
<field_file type="array">
<tx_templavoila type="array">
<title>File</title>
<sample_data type="array">
<numIndex index="0"></numIndex>
</sample_data>
<eType>link</eType>
<TypoScript><![CDATA[
10 = IMAGE
10.file = fileadmin/templates/img/icon_pdf.gif
10.stdWrap.typolink.parameter.current = 1
10.if.isTrue.field= field_file
10.wrap = |<br />
20 = COA
20.stdWrap.typolink.parameter.current = 1
20 {
30 = TEXT
30 {
# field = current
current = 1
postUserFunc = user_get_filedesc
}
} }]]></TypoScript>
</tx_templavoila>
<TCEforms type="array">
<config type="array">
<type>input</type>
<size>15</size>
<max>256</max>
<checkbox></checkbox>
<eval>trim</eval>
<wizards type="array">
<_PADDING type="integer">2</_PADDING>
<link type="array">
<type>popup</type>
<title>Link</title>
<icon>link_popup.gif</icon>
<script>browse_links.php?mode=wizard</script>
<JSopenParams>height=300,width=500,status=0,menubar=0,scrollbars=1</JSopenParams>
</link>
</wizards>
</config>
<label>File</label>
</TCEforms>
</field_file>
<field_zip type="array">
<tx_templavoila type="array">
<title>ZIP-file</title>
<sample_data type="array">
<numIndex index="0"></numIndex>
</sample_data>
<eType>link</eType>
<TypoScript><![CDATA[
10 = IMAGE
10.file = fileadmin/templates/img/icon_zip.gif
10.stdWrap.typolink.parameter.current = 1
10.wrap = |<br />
10.if.isTrue.field= field_zip
20 = COA
20.stdWrap.typolink.parameter.current = 1
20 {
30 = TEXT
30 {
current = 1
postUserFunc = user_get_filedesc
}
}
}]]></TypoScript>
</tx_templavoila>
<TCEforms type="array">
<config type="array">
<type>input</type>
<size>15</size>
<max>256</max>
<checkbox></checkbox>
<eval>trim</eval>
<wizards type="array">
<_PADDING type="integer">2</_PADDING>
<link type="array">
<type>popup</type>
<title>Link</title>
<icon>link_popup.gif</icon>
<script>browse_links.php?mode=wizard</script>
<JSopenParams>height=300,width=500,status=0,menubar=0,scrollbars=1</JSopenParams>
</link>
</wizards>
</config>
<label>ZIP-file</label>
</TCEforms>
</field_zip>
<field_image type="array">
<tx_templavoila type="array">
<title>Image</title>
<sample_data type="array">
<numIndex index="0"></numIndex>
</sample_data>
<eType>image</eType>
<TypoScript>
10 = IMAGE
10.file.import = uploads/tx_templavoila/
10.file.import.current = 1
10.file.import.listNum = 0
# 10.file.maxW = 200
10.stdWrap.typolink.parameter.field = field_file
10.stdWrap.if.isTrue.field= field_image
</TypoScript>
</tx_templavoila>
<TCEforms type="array">
<config type="array">
<type>group</type>
<internal_type>file</internal_type>
<allowed>gif,png,jpg,jpeg</allowed>
<max_size>1000</max_size>
<uploadfolder>uploads/tx_templavoila</uploadfolder>
<show_thumbs>1</show_thumbs>
<size>1</size>
<maxitems>1</maxitems>
<minitems>0</minitems>
</config>
<label>Image</label>
</TCEforms>
</field_image>
</el>
</ROOT>
</T3DataStructure>
PHP код:
<?
function user_filename($strUrl) {
$pieces = explode(" ", trim($strUrl));
if ($pieces[1] == "_blank") {
$res = $pieces[0];
}
else{
$res = trim($strUrl);
}
return $res;
}
function user_get_fileclass($strUrl, $arrOpt)
{
$strUrl = user_filename($strUrl);
$strExt = strrchr( $strUrl, '.' );
$strExt = strtolower( $strExt );
$strExt = substr( $strExt, 1 );
return( $strExt );
}
function user_get_filename($strUrl)
{
$strUrl = user_filename($strUrl);
$strExt = basename($strUrl);
// $strExt = strrchr( $strUrl, '.' );
// $strExt = strtolower( $strExt );
// $strExt = substr( $strExt, 1 );
return( $strExt );
}
function user_get_filedesc($strUrl)
{
if ($strUrl) {
$strUrl = user_filename($strUrl);
$strDocRoot = PATH_site;
$strFile = $strDocRoot . $strUrl;
$strFile = urldecode( $strFile );
$intFileSize = filesize( $strFile );
if( $intFileSize < 1024*1024 ) {
$intFileSize = (int)$intFileSize / 1024;
$strFileSizeIndicator = 'KB';
$intFileSize = round( $intFileSize, 0 );
} else {
$intFileSize = (int)$intFileSize / (1024*1024);
$strFileSizeIndicator = 'MB';
$intFileSize = round( $intFileSize, 1 );
}
// $strExt = strrchr( $strUrl, '.' );
// $strExt = strtoupper( $strExt );
// $strExt = substr( $strExt, 1 );
// $strResult = "Size $intFileSize $strFileSizeIndicator ($strExt)";
$strResult = "ca. $intFileSize $strFileSizeIndicator";
}
else $strResult ='';
return( $strResult );
}
?>
Код:
# snippet by Pavel Antonov
tt_content.templavoila_pi1 {
10 = LOAD_REGISTER
10.fce_header.field = header
}
lib.fce_title = TEXT
lib.fce_title.data = register:fce_header
includeLibs.for_tv = fileadmin/templates/ts/user_func.php
|