/**
  * Typoscript USER function for rendering DAM images.
  * This is a minimal Setup:
  * <pre>
  * yourObject.imagecol = USER
  * yourObject.imagecol {
  *   userFunc=tx_rnbase_util_TSFAL->printImages
  *   includeLibs = EXT:rn_base/util/class.tx_rnbase_util_TSFAL.php
  *   refField=imagecol
  *   refTable=tx_yourextkey_tablename
  *   template = EXT:rn_base/res/simplegallery.html
  *   # media is the fal reference record
  *   media {
  *     # field file contains the complete image path
  *     file = IMAGE
  *     file.file.import.field = file
  *   }
  *   # Optional setting for limit
  *   # limit = 1
  * }
  * </pre>
  * There are three additional fields in media record: file, file1 and thumbnail containing the complete
  * image path.
  * The output is rendered via HTML template with ListBuilder. Have a look at EXT:rn_base/res/simplegallery.html
  * Possible Typoscript options:
  * refField: DAM reference field of the media records (defined in TCA and used to locate the record in MM-Table)
  * refTable: should be the tablename where the DAM record is referenced to
  * template: Full path to HTML template file.
  * media: Formatting options of the DAM record. Have a look at tx_dam to find all column names
  * limit: Limits the number of medias
  * offset: Start media output with an offset
  * forcedIdField: force another reference column (other than UID or _LOCALIZED_UID)
  *
  *
  * @param string $content
  * @param array $tsConf
  * @return string
  */
 public function printImages($content, $tsConf)
 {
     tx_rnbase::load('tx_rnbase_util_Templates');
     $conf = $this->createConf($tsConf);
     $file = $conf->get('template');
     $file = $file ? $file : 'EXT:rn_base/res/simplegallery.html';
     $subpartName = $conf->get('subpartName');
     $subpartName = $subpartName ? $subpartName : '###DAM_IMAGES###';
     $templateCode = tx_rnbase_util_Templates::getSubpartFromFile($file, $subpartName);
     if (!$templateCode) {
         return '<!-- NO TEMPLATE OR SUBPART ' . $subpartName . ' FOUND -->';
     }
     // Is there a customized language field configured
     $langField = DEFAULT_LOCAL_FIELD;
     $locUid = $conf->getCObj()->data[$langField];
     // Save original uid
     if ($conf->get('forcedIdField')) {
         $langField = $conf->get('forcedIdField');
         // Copy localized UID
         $conf->getCObj()->data[DEFAULT_LOCAL_FIELD] = $conf->getCObj()->data[$langField];
     }
     // Check if there is a valid uid given.
     $parentUid = intval($conf->getCObj()->data[DEFAULT_LOCAL_FIELD] ? $conf->getCObj()->data[DEFAULT_LOCAL_FIELD] : $conf->getCObj()->data['uid']);
     if (!$parentUid) {
         return '<!-- Invalid data record given -->';
     }
     $medias = self::fetchFilesByTS($conf, $conf->getCObj());
     $listBuilder = tx_rnbase::makeInstance('tx_rnbase_util_ListBuilder');
     $out = $listBuilder->render($medias, FALSE, $templateCode, 'tx_rnbase_util_MediaMarker', 'media.', 'MEDIA', $conf->getFormatter());
     // Now set the identifier
     $markerArray = array('###MEDIA_PARENTUID###' => $parentUid);
     $out = tx_rnbase_util_BaseMarker::substituteMarkerArrayCached($out, $markerArray);
     return $out;
 }
 /**
  * Typoscript USER function for rendering DAM images.
  * This is a minimal Setup:
  * <pre>
  * yourObject.imagecol = USER
  * yourObject.imagecol {
  *   userFunc=tx_rnbase_util_TSDAM->printImages
  *   refField=imagecol
  *   refTable=tx_yourextkey_tablename
  *   template = EXT:rn_base/res/simplegallery.html
  *   # media is the dam record
  *   media {
  *     # field file contains the complete image path
  *     file = IMAGE
  *     file.file.import.field = file
  *   }
  *   # Optional setting for limit
  *   # limit = 1
  * }
  * </pre>
  * There are three additional fields in media record: file, file1 and thumbnail containing the complete
  * image path.
  * The output is rendered via HTML template with ListBuilder. Have a look at EXT:rn_base/res/simplegallery.html
  * Possible Typoscript options:
  * refField: DAM reference field of the media records (defined in TCA and used to locate the record in MM-Table)
  * refTable: should be the tablename where the DAM record is referenced to
  * template: Full path to HTML template file.
  * media: Formatting options of the DAM record. Have a look at tx_dam to find all column names
  * limit: Limits the number of medias
  * offset: Start media output with an offset
  * forcedIdField: force another refernce column (other than UID or _LOCALIZED_UID)
  *
  *
  * @param string $content
  * @param array $tsConf
  * @return string
  */
 function printImages($content, $tsConf)
 {
     if (!tx_rnbase_util_Extensions::isLoaded('dam')) {
         return '';
     }
     $conf = $this->createConf($tsConf);
     $file = $conf->get('template');
     $file = $file ? $file : 'EXT:rn_base/res/simplegallery.html';
     $subpartName = $conf->get('subpartName');
     $subpartName = $subpartName ? $subpartName : '###DAM_IMAGES###';
     $templateCode = tx_rnbase_util_Templates::getSubpartFromFile($file, $subpartName);
     if (!$templateCode) {
         return '<!-- NO TEMPLATE OR SUBPART ' . $subpartName . ' FOUND -->';
     }
     // Is there a customized language field configured
     $langField = DEFAULT_LOCAL_FIELD;
     $locUid = $conf->getCObj()->data[$langField];
     // Save original uid
     if ($conf->get('forcedIdField')) {
         $langField = $conf->get('forcedIdField');
         // Copy localized UID
         $conf->getCObj()->data[DEFAULT_LOCAL_FIELD] = $conf->getCObj()->data[$langField];
     }
     // Check if there is a valid uid given.
     $parentUid = intval($conf->getCObj()->data[DEFAULT_LOCAL_FIELD] ? $conf->getCObj()->data[DEFAULT_LOCAL_FIELD] : $conf->getCObj()->data['uid']);
     if (!$parentUid) {
         return '<!-- Invalid data record given -->';
     }
     $damPics = $this->fetchFileList($tsConf, $conf->getCObj());
     $conf->getCObj()->data[DEFAULT_LOCAL_FIELD] = $locUid;
     // Reset UID
     $offset = intval($conf->get('offset'));
     $limit = intval($conf->get('limit'));
     if (!$limit && $offset && count($damPics)) {
         $damPics = array_slice($damPics, $offset);
     } elseif ($limit && count($damPics)) {
         $damPics = array_slice($damPics, $offset, $limit);
     }
     $damDb = tx_rnbase::makeInstance('tx_dam_db');
     $medias = array();
     while (list($uid, $baseRecord) = each($damPics)) {
         $mediaObj = tx_rnbase::makeInstance('tx_rnbase_model_media', $baseRecord['uid']);
         // Localize data (DAM 1.1.0)
         if (method_exists($damDb, 'getRecordOverlay')) {
             $loc = $damDb->getRecordOverlay('tx_dam', $mediaObj->getRecord(), array('sys_language_uid' => $GLOBALS['TSFE']->sys_language_uid));
             if ($loc) {
                 $mediaObj->setProperty($loc);
             }
         }
         $mediaObj->setParentuid($parentUid);
         $medias[] = $mediaObj;
     }
     $listBuilder = tx_rnbase::makeInstance('tx_rnbase_util_ListBuilder');
     $out = $listBuilder->render($medias, FALSE, $templateCode, 'tx_rnbase_util_MediaMarker', 'media.', 'MEDIA', $conf->getFormatter());
     // Now set the identifier
     $markerArray['###MEDIA_PARENTUID###'] = $parentUid;
     $out = tx_rnbase_util_BaseMarker::substituteMarkerArrayCached($out, $markerArray);
     return $out;
 }
 /**
  * Returns the maps template from $confId.'template'
  *
  * @param tx_rnbase_configurations $configurations
  * @param string $confId
  * @return string empty string if template was not found
  */
 public static function getMapTemplate($configurations, $confId)
 {
     $file = $configurations->get($confId . 'template');
     if (!$file) {
         return '';
     }
     $subpartName = $configurations->get($confId . 'subpart');
     if (!$subpartName) {
         return '';
     }
     $ret = '';
     try {
         $subpart = tx_rnbase_util_Templates::getSubpartFromFile($file, $subpartName);
         $ret = str_replace(array("\r\n", "\n", "\r"), '', $subpart);
     } catch (Exception $e) {
         $ret = '';
     }
     return $ret;
 }