Exemplo n.º 1
0
 /**
  * return detail view
  */
 public function getDetail()
 {
     $strTableName = \Input::get('tablename');
     $strWrapperID = \Input::get('wrapperID');
     $strDataTable = $strTableName . '_data';
     $dateFormat = \Input::get('dateFormat') ? \Input::get('dateFormat') : \Config::get('dateFormat');
     $timeFormat = \Input::get('timeFormat') ? \Input::get('timeFormat') : \Config::get('timeFormat');
     $template = \Input::get('template') ? \Input::get('template') : 'fmodule_full';
     $alias = \Input::get('alias');
     $id = \Input::get('id');
     if (!$strTableName || !$strWrapperID) {
         $this->sendFailState("no back end module found");
     }
     if (!$this->Database->tableExists($strTableName)) {
         $this->sendFailState("table do not exist");
     }
     $arrModuleData = $this->getModule($strTableName, $strWrapperID);
     $arrFields = $arrModuleData['arrFields'];
     $fieldWidgets = $arrModuleData['arrWidgets'];
     $mapFields = $arrModuleData['mapFields'];
     $arrCleanOptions = $arrModuleData['arrCleanOptions'];
     $strResult = '';
     $objTemplate = new \FrontendTemplate($template);
     $qProtectedStr = ' AND published = "1"';
     $arrItem = $this->Database->prepare('SELECT * FROM ' . $strDataTable . ' WHERE pid = ? AND (alias = ? OR id = ?) OR (alias = ? OR id = ?)' . $qProtectedStr . '')->execute($strWrapperID, $alias, (int) $alias, $id, (int) $id)->row();
     $arrWrapper = $this->Database->prepare('SELECT * FROM ' . $strTableName . ' WHERE id = ?')->execute($strWrapperID)->row();
     // image
     $imagePath = $this->generateSingeSrc($arrItem);
     if ($imagePath) {
         $arrItem['singleSRC'] = $imagePath;
     }
     //set css and id
     $arrItem['cssID'] = deserialize($arrItem['cssID']);
     $arrItem['itemID'] = $arrItem['cssID'][0];
     $arrItem['itemCSS'] = $arrItem['cssID'][1] ? ' ' . $arrItem['cssID'][1] : '';
     $arrItem['cssClass'] = '';
     $objCte = \ContentModel::findPublishedByPidAndTable($arrItem['id'], $strTableName . '_data');
     $detail = array();
     $teaser = array();
     if ($objCte !== null) {
         $intCount = 0;
         $intLast = $objCte->count() - 1;
         while ($objCte->next()) {
             $arrCss = array();
             $objRow = $objCte->current();
             if ($intCount == 0 || $intCount == $intLast) {
                 if ($intCount == 0) {
                     $arrCss[] = 'first';
                 }
                 if ($intCount == $intLast) {
                     $arrCss[] = 'last';
                 }
             }
             $objRow->classes = $arrCss;
             if ($objRow->fview == 'list') {
                 $teaser[] = $this->getContentElement($objRow, $this->strColumn);
             } else {
                 $detail[] = $this->getContentElement($objRow, $this->strColumn);
             }
             ++$intCount;
         }
     }
     // author
     $authorDB = null;
     if ($arrItem['author']) {
         $authorDB = $this->Database->prepare('SELECT * FROM tl_user WHERE id = ?')->execute($arrItem['author'])->row();
         unset($authorDB['password']);
         unset($authorDB['session']);
     }
     $arrItem['teaser'] = $teaser;
     $arrItem['detail'] = $detail;
     $arrItem['author'] = $authorDB;
     $arrItem['date'] = $arrItem['date'] ? date($dateFormat, $arrItem['date']) : '';
     $arrItem['time'] = $arrItem['time'] ? date($timeFormat, $arrItem['time']) : '';
     $arrItem['filter'] = $arrFields;
     if (!empty($fieldWidgets)) {
         $arrayAsValue = array('list.blank', 'list.keyValue', 'table.blank');
         foreach ($fieldWidgets as $widget) {
             $id = $widget['fieldID'];
             $tplName = $widget['widgetTemplate'];
             $type = $widget['widgetType'];
             $value = $arrItem[$id];
             if (in_array($type, $arrayAsValue)) {
                 $value = deserialize($value);
             }
             $objFieldTemplate = new \FrontendTemplate($tplName);
             $objFieldTemplate->setData(array('value' => $value, 'type' => $type, 'item' => $arrItem));
             $arrItem[$id] = $objFieldTemplate->parse();
         }
     }
     // create marker path
     if ($arrItem['addMarker'] && $arrItem['markerSRC']) {
         if ($this->markerCache[$arrItem['markerSRC']]) {
             $arrItem['markerSRC'] = $this->markerCache[$arrItem['markerSRC']];
         } else {
             $markerDB = $this->Database->prepare('SELECT * FROM tl_files WHERE uuid = ?')->execute($arrItem['markerSRC']);
             if ($markerDB->count()) {
                 $pathInfo = $markerDB->row()['path'];
                 if ($pathInfo) {
                     $this->markerCache[$arrItem['markerSRC']] = $pathInfo;
                     $arrItem['markerSRC'] = $pathInfo;
                 }
             }
         }
     }
     // add gallery
     if ($arrItem['addGallery'] && $arrItem['multiSRC']) {
         $objGallery = new GalleryGenerator();
         $objGallery->id = $arrItem['id'];
         $objGallery->sortBy = $arrItem['sortBy'];
         $objGallery->orderSRC = $arrItem['orderSRC'];
         $objGallery->metaIgnore = $arrItem['metaIgnore'];
         $objGallery->numberOfItems = $arrItem['numberOfItems'];
         $objGallery->perPage = $arrItem['perPageGallery'];
         $objGallery->perRow = $arrItem['perRow'];
         $objGallery->size = $arrItem['size'];
         $objGallery->fullsize = $arrItem['fullsize'];
         $objGallery->galleryTpl = $arrItem['galleryTpl'];
         $objGallery->getAllImages($arrItem['multiSRC']);
         $arrItem['gallery'] = $objGallery->renderGallery();
     }
     // map
     if (!empty($mapFields)) {
         foreach ($mapFields as $map) {
             $objMapTemplate = new \FrontendTemplate($map['template']);
             $arrItem['mapSettings'] = $map;
             $objMapTemplate->setData($arrItem);
             $arrItem[$map['fieldID']] = $objMapTemplate->parse();
         }
     }
     // set clean options
     if (!empty($arrCleanOptions)) {
         $arrItem['cleanOptions'] = $arrCleanOptions;
         // overwrite clean options
         foreach ($arrCleanOptions as $fieldID => $options) {
             if ($arrItem[$fieldID] && is_string($arrItem[$fieldID])) {
                 $arrValues = explode(',', $arrItem[$fieldID]);
                 $arrValuesAsString = array();
                 $arrValuesAsArray = array();
                 if (is_array($arrValues)) {
                     foreach ($arrValues as $val) {
                         $arrValuesAsArray[$val] = $options[$val];
                         $arrValuesAsString[] = $options[$val];
                     }
                 }
                 $arrItem[$fieldID . 'AsArray'] = $arrValuesAsArray;
                 $arrItem[$fieldID] = implode(', ', $arrValuesAsString);
             }
         }
     }
     // set data
     $objTemplate->setData($arrItem);
     // enclosure
     $objTemplate->enclosure = array();
     if ($arrItem['addEnclosure']) {
         $this->addEnclosuresToTemplate($objTemplate, $arrItem);
     }
     // add image
     if ($arrItem['addImage']) {
         $this->addImageToTemplate($objTemplate, array('singleSRC' => $arrItem['singleSRC'], 'alt' => $arrItem['alt'], 'size' => $arrItem['size'], 'fullsize' => $arrItem['fullsize'], 'caption' => $arrItem['caption'], 'title' => $arrItem['title']));
     }
     $strResult .= $objTemplate->parse();
     $arrData = ['arrData' => $arrItem, 'mapFields' => $mapFields, 'arrWrapper' => $arrWrapper, 'strTemplate' => $strResult, 'arrGoBack' => ['referer' => 'javascript:history.go(-1)', 'back' => $GLOBALS['TL_LANG']['MSC']['goBack']]];
     header('Content-type: application/json');
     echo json_encode($arrData, 512);
     exit;
 }
Exemplo n.º 2
0
 /**
  *
  */
 protected function compile()
 {
     global $objPage;
     $listID = $this->f_list_field;
     $strDetailTemplate = $this->f_detail_template;
     $listModuleDB = $this->Database->prepare('SELECT * FROM tl_module WHERE id = ?')->execute($listID)->row();
     $tablename = $listModuleDB['f_select_module'];
     $wrapperID = $listModuleDB['f_select_wrapper'];
     $moduleDB = $this->Database->prepare('SELECT tl_fmodules.id AS moduleID, tl_fmodules.*, tl_fmodules_filters.*  FROM tl_fmodules LEFT JOIN tl_fmodules_filters ON tl_fmodules.id = tl_fmodules_filters.pid WHERE tablename = ? ORDER BY tl_fmodules_filters.sorting')->execute($tablename);
     $alias = \Input::get('auto_item');
     $isAlias = QueryModel::isValue($alias);
     if (!$isAlias) {
         $objHandler = new $GLOBALS['TL_PTY']['error_404']();
         $objHandler->generate($objPage->id);
         exit;
     }
     $doNotSetByID = array('orderBy', 'sorting_fields', 'pagination');
     $doNotSetByType = array('legend_end', 'legend_start', 'wrapper_field');
     $fieldWidgets = array();
     $arrModules = array();
     $mapFields = array();
     $arrCleanOptions = array();
     //
     while ($moduleDB->next()) {
         $arrModule = $moduleDB->row();
         if (in_array($arrModule['fieldID'], $doNotSetByID) || in_array($arrModule['type'], $doNotSetByType)) {
             continue;
         }
         // map
         if ($arrModule['type'] == 'map_field') {
             $mapFields[] = HelperModel::setGoogleMap($arrModule);
             // set loadMapScript to true
             $this->loadMapScript = true;
             // load map libraries
             if (!$GLOBALS['loadGoogleMapLibraries']) {
                 $GLOBALS['loadGoogleMapLibraries'] = $arrModule['mapInfoBox'] ? true : false;
             }
         }
         if ($arrModule['type'] == 'widget') {
             $tplName = $arrModule['widgetTemplate'];
             $tpl = '';
             if (!$tplName) {
                 $tplNameType = explode('.', $arrModule['widget_type'])[0];
                 $tplNameArr = $this->getTemplateGroup('fm_field_' . $tplNameType);
                 $tpl = current($tplNameArr);
                 $tpl = $this->parseTemplateName($tpl);
             }
             $fieldWidgets[$arrModule['fieldID']] = array('fieldID' => $arrModule['fieldID'], 'widgetType' => $arrModule['widget_type'], 'widgetTemplate' => $arrModule['widgetTemplate'] ? $arrModule['widgetTemplate'] : $tpl);
         }
         // has options
         if ($arrModule['type'] == 'simple_choice' || $arrModule['type'] == 'multi_choice') {
             $dcaHelper = new DCAHelper();
             $arrCleanOptions[$arrModule['fieldID']] = $dcaHelper->getOptions($arrModule, $tablename, $wrapperID);
         }
         $arrModules[$arrModule['fieldID']] = $arrModule;
     }
     $qProtectedStr = ' AND published = "1"';
     if (HelperModel::previewMode()) {
         $qProtectedStr = '';
     }
     $itemDB = $this->Database->prepare('SELECT * FROM ' . $tablename . '_data WHERE pid = ? AND (alias = ? OR id = ?) ' . $qProtectedStr . '')->execute($wrapperID, $alias, (int) $alias)->row();
     $wrapperDB = $this->Database->prepare('SELECT * FROM ' . $tablename . ' WHERE id = ?')->execute($wrapperID)->row();
     $strResult = '';
     // overwrite template
     if ($itemDB['auto_detail_template'] && strcmp($itemDB['auto_detail_template'], 'fmodule_full')) {
         $strDetailTemplate = $itemDB['auto_detail_template'];
     }
     $objTemplate = new \FrontendTemplate($strDetailTemplate);
     if (count($itemDB) < 1) {
         $objHandler = new $GLOBALS['TL_PTY']['error_404']();
         $objHandler->generate($objPage->id);
         exit;
     }
     if (HelperModel::sortOutProtected($itemDB, $this->User->groups)) {
         $objHandler = new $GLOBALS['TL_PTY']['error_403']();
         $objHandler->generate($objPage->id);
         exit;
     }
     // image
     $imagePath = $this->generateSingeSrc($itemDB);
     if ($imagePath) {
         $itemDB['singleSRC'] = $imagePath;
     }
     // size
     $imgSize = false;
     // Override the default image size
     if ($this->imgSize != '') {
         $size = deserialize($this->imgSize);
         if ($size[0] > 0 || $size[1] > 0 || is_numeric($size[2])) {
             $imgSize = $this->imgSize;
         }
     }
     if ($imgSize) {
         $itemDB['size'] = $imgSize;
     }
     //set css and id
     $itemDB['cssID'] = deserialize($itemDB['cssID']);
     $itemDB['itemID'] = $itemDB['cssID'][0];
     $itemDB['itemCSS'] = $itemDB['cssID'][1] ? ' ' . $itemDB['cssID'][1] : '';
     $itemDB['cssClass'] = '';
     $objCte = \ContentModel::findPublishedByPidAndTable($itemDB['id'], $tablename . '_data');
     $detail = array();
     $teaser = array();
     if ($objCte !== null) {
         $intCount = 0;
         $intLast = $objCte->count() - 1;
         while ($objCte->next()) {
             $arrCss = array();
             $objRow = $objCte->current();
             if ($intCount == 0 || $intCount == $intLast) {
                 if ($intCount == 0) {
                     $arrCss[] = 'first';
                 }
                 if ($intCount == $intLast) {
                     $arrCss[] = 'last';
                 }
             }
             $objRow->classes = $arrCss;
             if ($objRow->fview == 'list') {
                 $teaser[] = $this->getContentElement($objRow, $this->strColumn);
             } else {
                 $detail[] = $this->getContentElement($objRow, $this->strColumn);
             }
             ++$intCount;
         }
     }
     // seo
     if ($this->fm_overwrite_seoSettings) {
         $descriptionColName = $this->fm_seoDescription ? $this->fm_seoDescription : 'description';
         $pageTitleColName = $this->fm_seoPageTitle ? $this->fm_seoPageTitle : 'title';
         $seoDescription = strip_tags($itemDB[$descriptionColName]);
         $objPage->description = $seoDescription;
         $objPage->pageTitle = $itemDB[$pageTitleColName];
         // set hreflang
         if ($this->fm_seoHrefLang) {
             $strHrefLangAttributes = HelperModel::getHrefAttributes($tablename, $alias, null, $itemDB, $wrapperDB);
             $GLOBALS['TL_HEAD'][] = $strHrefLangAttributes;
         }
     }
     // author
     $authorDB = null;
     if ($itemDB['author']) {
         $authorDB = $this->Database->prepare('SELECT * FROM tl_user WHERE id = ?')->execute($itemDB['author'])->row();
         unset($authorDB['password']);
         unset($authorDB['session']);
     }
     $itemDB['teaser'] = $teaser;
     $itemDB['detail'] = $detail;
     $itemDB['author'] = $authorDB;
     $itemDB['date'] = $itemDB['date'] ? date($objPage->dateFormat, $itemDB['date']) : '';
     $itemDB['time'] = $itemDB['time'] ? date($objPage->timeFormat, $itemDB['time']) : '';
     $itemDB['filter'] = $arrModules;
     if (!empty($fieldWidgets)) {
         $arrayAsValue = array('list.blank', 'list.keyValue', 'table.blank');
         foreach ($fieldWidgets as $widget) {
             $id = $widget['fieldID'];
             $tplName = $widget['widgetTemplate'];
             $type = $widget['widgetType'];
             $value = $itemDB[$id];
             if (in_array($type, $arrayAsValue)) {
                 $value = deserialize($value);
             }
             $objFieldTemplate = new \FrontendTemplate($tplName);
             $objFieldTemplate->setData(array('value' => $value, 'type' => $type, 'item' => $itemDB));
             $itemDB[$id] = $objFieldTemplate->parse();
         }
     }
     // add gallery
     if ($itemDB['addGallery'] && $itemDB['multiSRC']) {
         $objGallery = new GalleryGenerator();
         $objGallery->id = $itemDB['id'];
         $objGallery->sortBy = $itemDB['sortBy'];
         $objGallery->orderSRC = $itemDB['orderSRC'];
         $objGallery->metaIgnore = $itemDB['metaIgnore'];
         $objGallery->numberOfItems = $itemDB['numberOfItems'];
         $objGallery->perPage = $itemDB['perPageGallery'];
         $objGallery->perRow = $itemDB['perRow'];
         $objGallery->size = $itemDB['size'];
         $objGallery->fullsize = $itemDB['fullsize'];
         $objGallery->galleryTpl = $itemDB['galleryTpl'];
         $objGallery->getAllImages($itemDB['multiSRC']);
         $itemDB['gallery'] = $objGallery->renderGallery();
     }
     // create marker path
     if ($itemDB['addMarker'] && $itemDB['markerSRC']) {
         if ($this->markerCache[$itemDB['markerSRC']]) {
             $itemDB['markerSRC'] = $this->markerCache[$itemDB['markerSRC']];
         } else {
             $markerDB = $this->Database->prepare('SELECT * FROM tl_files WHERE uuid = ?')->execute($itemDB['markerSRC']);
             if ($markerDB->count()) {
                 $pathInfo = $markerDB->row()['path'];
                 if ($pathInfo) {
                     $this->markerCache[$itemDB['markerSRC']] = $pathInfo;
                     $itemDB['markerSRC'] = $pathInfo;
                 }
             }
         }
     }
     // map
     if (!empty($mapFields)) {
         foreach ($mapFields as $map) {
             $objMapTemplate = new \FrontendTemplate($map['template']);
             $itemDB['mapSettings'] = $map;
             $objMapTemplate->setData($itemDB);
             $itemDB[$map['fieldID']] = $objMapTemplate->parse();
         }
     }
     // set clean options
     if (!empty($arrCleanOptions)) {
         $itemDB['cleanOptions'] = $arrCleanOptions;
         // overwrite clean options
         foreach ($arrCleanOptions as $fieldID => $options) {
             if ($itemDB[$fieldID] && is_string($itemDB[$fieldID])) {
                 $arrValues = explode(',', $itemDB[$fieldID]);
                 $arrValuesAsString = array();
                 $arrValuesAsArray = array();
                 if (is_array($arrValues)) {
                     foreach ($arrValues as $val) {
                         $arrValuesAsArray[$val] = $options[$val];
                         $arrValuesAsString[] = $options[$val];
                     }
                 }
                 $itemDB[$fieldID . 'AsArray'] = $arrValuesAsArray;
                 $itemDB[$fieldID] = implode(', ', $arrValuesAsString);
             }
         }
     }
     // floating class
     $itemDB['floatClass'] = 'float_' . $itemDB['floating'];
     $objTemplate->setData($itemDB);
     $strTitle = $itemDB['title'];
     //enclosure
     $objTemplate->enclosure = array();
     if ($itemDB['addEnclosure']) {
         $this->addEnclosuresToTemplate($objTemplate, $itemDB);
     }
     //add image
     if ($itemDB['addImage']) {
         $this->addImageToTemplate($objTemplate, array('singleSRC' => $itemDB['singleSRC'], 'title' => $itemDB['imgTitle'], 'alt' => $itemDB['alt'], 'size' => $itemDB['size'], 'fullsize' => $itemDB['fullsize'], 'caption' => $itemDB['caption']));
     }
     $objTemplate->title = $strTitle;
     $objTemplate->addBefore = $itemDB['floatClass'] == 'float_below' ? false : true;
     $strResult .= $objTemplate->parse();
     $this->Template->referer = 'javascript:history.go(-1)';
     $this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack'];
     $this->Template->result = $strResult;
     //allow comments
     $this->Template->allowComments = $wrapperDB['allowComments'];
     if ($wrapperDB['allowComments']) {
         $this->import('Comments');
         $arrNotifies = array();
         if ($wrapperDB['notify'] != 'notify_author') {
             $arrNotifies[] = $GLOBALS['TL_ADMIN_EMAIL'];
         }
         if ($wrapperDB['notify'] != 'notify_admin') {
             if ($authorDB != null && $authorDB['email'] != '') {
                 $arrNotifies[] = $authorDB['email'];
             }
         }
         $objConfig = new \stdClass();
         $objConfig->perPage = $wrapperDB['perPage'];
         $objConfig->order = $wrapperDB['sortOrder'];
         $objConfig->template = $this->com_template;
         $objConfig->requireLogin = $wrapperDB['requireLogin'];
         $objConfig->disableCaptcha = $wrapperDB['disableCaptcha'];
         $objConfig->bbcode = $wrapperDB['bbcode'];
         $objConfig->moderate = $wrapperDB['moderate'];
         $this->Comments->addCommentsToTemplate($this->Template, $objConfig, $tablename . '_data', $itemDB['id'], $arrNotifies);
     }
     // set js files
     if ($this->loadMapScript) {
         $language = $objPage->language ? $objPage->language : 'en';
         $GLOBALS['TL_HEAD']['mapJS'] = DiverseFunction::setMapJs($language);
     }
 }