/**
  * Returns a image-tag, URL and attributes for a image preview
  *
  * @param	mixed		$fileInfo Is a file path or an array containing a file info from tx_dam::file_compileInfo().
  * @param	string		$size Optional: $size is [w]x[h] of the image preview. 56 is default.
  * @param	mixed		$imgAttributes additional attributes for the image tag
  * @return	array		Thumbnail image tag, url and attributes with width/height
  * @todo calc width/height from cm size or similar when hpixels not available
  * @todo return false when file is missing?
  */
 function preview($fileInfo, $size = '', $imgAttributes = '')
 {
     // get some file information
     if (!is_array($fileInfo)) {
         $fileInfo = tx_dam::file_compileInfo($fileInfo);
     }
     $filepath = tx_dam::file_absolutePath($fileInfo);
     if ($filepath and @file_exists($filepath) and @is_file($filepath)) {
         $fileType = tx_dam::file_getType($fileInfo);
         if (!tx_dam_image::isPreviewPossible($fileType)) {
             return array();
         }
         if (!is_array($imgAttributes)) {
             $imgAttributes = tx_dam_image::tools_explodeAttributes($imgAttributes);
         }
         $imgAttributes['alt'] = isset($imgAttributes['alt']) ? $imgAttributes['alt'] : ($fileInfo['alt_text'] ? $fileInfo['alt_text'] : $fileInfo['title']);
         $imgAttributes['title'] = isset($imgAttributes['title']) ? $imgAttributes['title'] : $imgAttributes['alt'];
         // Check and parse the size parameter
         $size = trim($size);
         list($sizeX, $sizeY) = tx_dam_image::parseSize($size);
         $sizeMax = $max = max($sizeX, $sizeY);
         // get maximum image pixel size
         $maxImageSize = 0;
         if ($fileInfo['hpixels']) {
             $maxImageSize = max($fileInfo['hpixels'], $fileInfo['vpixels']);
         } elseif (t3lib_div::inList('gif,jpg,png', $fileType['file_type'])) {
             if (is_array($imgInfo = @getimagesize($filepath))) {
                 $fileInfo['hpixels'] = $imgInfo[0];
                 $fileInfo['vpixels'] = $imgInfo[1];
                 $maxImageSize = max($fileInfo['hpixels'], $fileInfo['vpixels']);
             }
         }
         // calculate the image preview size
         $useOriginalImage = false;
         if ($maxImageSize and $maxImageSize <= $sizeMax) {
             $useOriginalImage = true;
             $thumbSizeX = $fileInfo['hpixels'];
             $thumbSizeY = $fileInfo['vpixels'];
             $imgAttributes['width'] = $thumbSizeX;
             $imgAttributes['height'] = $thumbSizeY;
         } elseif ($maxImageSize) {
             list($thumbSizeX, $thumbSizeY) = tx_dam_image::calcSize($fileInfo['hpixels'], $fileInfo['vpixels'], $sizeX, $sizeY);
             $imgAttributes['width'] = $thumbSizeX;
             $imgAttributes['height'] = $thumbSizeY;
             $size = $thumbSizeX . 'x' . $thumbSizeY;
         } elseif (tx_dam_image::isPreviewPossible($fileType)) {
             $thumbSizeX = $sizeX;
             $thumbSizeY = $sizeY;
             $size = $thumbSizeX . 'x' . $thumbSizeY;
         } else {
             $thumbSizeX = 0;
             $thumbSizeY = 0;
         }
         $url = '';
         $thumbnail = '';
         if ($thumbSizeX) {
             // use the original image if it's size fits to the image preview size
             if ($useOriginalImage) {
                 if (TYPO3_MODE === 'FE') {
                     $url = preg_replace('#^' . preg_quote(PATH_site) . '#', '', $filepath);
                 } else {
                     $url = $GLOBALS['BACK_PATH'] . '../' . preg_replace('#^' . preg_quote(PATH_site) . '#', '', $filepath);
                 }
                 // use thumbs.php script
             } else {
                 $check = basename($filepath) . ':' . filemtime($filepath) . ':' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
                 $url = 'thumbs.php?';
                 $url .= '&file=' . rawurlencode($filepath);
                 $url .= $size ? '&size=' . $size : '';
                 $url .= '&md5sum=' . t3lib_div::shortMD5($check);
                 $url .= '&dummy=' . $GLOBALS['EXEC_TIME'];
                 if (TYPO3_MODE === 'FE') {
                     $url = TYPO3_mainDir . $url;
                 } else {
                     $url = $GLOBALS['BACK_PATH'] . $url;
                 }
             }
         }
         $imgAttributes = tx_dam_image::tools_implodeAttributes($imgAttributes);
         $thumbnail = '<img src="' . htmlspecialchars($url) . '"' . $imgAttributes . ' />';
     }
     return array('img' => $thumbnail, 'url' => $url, 'attributes' => $imgAttributes, 'sizeX' => $thumbSizeX, 'sizeY' => $thumbSizeY);
 }
    /**
     * Returns a dia like thumbnail
     *
     * @param	array		$row tx_dam record
     * @param	integer		$diaSize dia size
     * @param	integer		$diaMargin dia margin
     * @param	array		$showElements Extra elements to show: "title,info,icons"
     * @param	string		$onClick: ...
     * @param	boolean		$makeIcon: ...
     * @param	string		$actions action content to be displayed
     * @return	string		HTML output
     */
    function getDia($row, $diaSize = 115, $diaMargin = 10, $showElements = '', $onClick = NULL, $makeIcon = TRUE, $actions = '')
    {
        if (!is_array($showElements)) {
            $showElements = t3lib_div::trimExplode(',', $showElements, 1);
        }
        // extra CSS code for HTML header
        if (is_object($GLOBALS['SOBE']) and !isset($GLOBALS['SOBE']->doc->inDocStylesArray['tx_dam_SCbase_dia'])) {
            $GLOBALS['SOBE']->doc->inDocStylesArray['tx_dam_SCbase_dia'] = tx_dam_guiFunc::getDiaStyles($diaSize, $diaMargin);
        }
        // use css/stylesheet
        $iconBgColor = t3lib_div::modifyHTMLcolor($GLOBALS['SOBE']->doc->bgColor, -10, -10, -10);
        $titleLen = ceil(30 * ($diaSize - $diaMargin) / (200 - $diaMargin));
        $hpixels = $row['hpixels'];
        $vpixels = $row['vpixels'];
        if ($hpixels and $vpixels) {
            list($hpixels, $vpixels) = tx_dam_image::calcSize($hpixels, $vpixels, $diaSize, $diaSize);
        } else {
            if ($hpixels > $diaSize) {
                $hpixels = $diaSize;
            }
            if ($vpixels > $diaSize) {
                $vpixels = $diaSize;
            }
        }
        $uid = $row['uid'];
        $imgAttributes = array();
        $imgAttributes['title'] = str_replace("\n", '', t3lib_div::fixed_lgd_cs($row['description'], 50));
        if ($hpixels) {
            $imgAttributes['style'] = 'margin-top:' . (ceil(($diaSize - $vpixels) / 2) + $diaMargin) . 'px;';
        } else {
            $imgAttributes['style'] = 'margin-top:' . $diaMargin . 'px;';
        }
        $imgAttributes['onclick'] = $onClick;
        $thumb = tx_dam_image::previewImgTag($row, $diaSize, $imgAttributes);
        if (!$makeIcon and empty($thumb)) {
            return '';
        }
        if (empty($thumb)) {
            $thumb = tx_dam_guiFunc::getMediaTypeIconBox($row);
            if ($onClick) {
                $thumb = '<a href="#" onclick="' . htmlspecialchars($onClick) . '">' . $thumb . '</a>';
            }
        }
        $descr = '';
        if (in_array('title', $showElements)) {
            $descr .= htmlspecialchars(t3lib_div::fixed_lgd_cs($row['title'], $titleLen)) . '<br />';
        }
        if (in_array('info', $showElements)) {
            $code = strtoupper($row['file_type']) . ', ';
            $code .= $row['hpixels'] ? $row['hpixels'] . 'x' . $row['vpixels'] . ', ' : '';
            $code .= t3lib_div::formatSize($row['file_size']);
            $descr .= '<span class="txdam-descr">' . htmlspecialchars($code) . '</span>';
        }
        if ($descr) {
            $descr = '<div class="txdam-title">' . $descr . '</div>';
        }
        $icons = '';
        $iconArr = array();
        if (in_array('icons', $showElements)) {
            // deprecated
            $iconArr[] = tx_dam_SCbase::icon_editRec('tx_dam', $row['uid'], 'style="margin-left:3px;margin-right:3px;"');
            $iconArr[] = tx_dam_SCbase::btn_editRec_inNewWindow('tx_dam', $row['uid'], 'style="margin-left:3px;margin-right:3px;"');
            $iconArr[] = tx_dam_SCbase::icon_infoRec('tx_dam', $row['uid'], 'style="margin-left:3px;margin-right:3px;"');
            $iconArr[] = tx_dam_SCbase::btn_removeRecFromSel('tx_dam', $row['uid'], 'style="margin-left:3px;margin-right:3px;"');
        }
        if (in_array('actions', $showElements)) {
            $actions;
        }
        $icons = $icons ? '<div style="margin:3px;">' . implode('<span style="width:40px;"></span>', $iconArr) . '</div>' : '';
        $actions = $actions ? '<div style="margin:3px;">' . $actions . '</div>' : '';
        $diaCode = '
		<table class="txdam-dia" cellspacing="0" cellpadding="0" border="0">
		<tr><td><span class="txdam-dia">' . $thumb . '</span></td></tr>
		' . ($descr . $icons . $actions ? '<tr><td align="center" bgcolor="' . $iconBgColor . '">' . $descr . $icons . $actions . '</td></tr>' : '') . '
		</table> ';
        return $diaCode;
    }