Exemple #1
0
 /**
  * return list view
  * filter allowed
  */
 public function getEntities()
 {
     $strTableName = \Input::get('tablename');
     $strTableData = $strTableName . '_data';
     $strWrapperID = \Input::get('wrapperID');
     $dateFormat = \Input::get('dateFormat') ? \Input::get('dateFormat') : \Config::get('dateFormat');
     $timeFormat = \Input::get('timeFormat') ? \Input::get('timeFormat') : \Config::get('timeFormat');
     $strTemplate = \Input::get('template') ? \Input::get('template') : 'fmodule_teaser';
     $this->tablename = $strTableData;
     $arrResults = [];
     $arrModuleData = $this->getModule($strTableName, $strWrapperID);
     $arrFields = $arrModuleData['arrFields'];
     $fieldWidgets = $arrModuleData['arrWidgets'];
     $mapFields = $arrModuleData['mapFields'];
     $arrCleanOptions = $arrModuleData['arrCleanOptions'];
     if (!$strTableName || !$strWrapperID) {
         $this->sendFailState("no back end module found");
     }
     if (!$this->Database->tableExists($strTableName)) {
         $this->sendFailState("no table found");
     }
     // get wrapper
     $wrapperDB = $this->Database->prepare('SELECT * FROM ' . $strTableName . ' WHERE id = ?')->execute($strWrapperID)->row();
     // get fields and create query
     $qResult = HelperModel::generateSQLQueryFromFilterArray($arrFields);
     $qStr = $qResult['qStr'];
     $qTextSearch = $qResult['isFulltextSearch'] ? $qResult['$qTextSearch'] : '';
     //get text search results
     $textSearchResults = array();
     if ($qTextSearch) {
         $textSearchResults = QueryModel::getTextSearchResult($qTextSearch, $strTableName, $strWrapperID, $qResult['searchSettings']);
     }
     $addDetailPage = $wrapperDB['addDetailPage'];
     $rootDB = $this->Database->prepare('SELECT * FROM ' . $strTableName . ' JOIN tl_page ON tl_page.id = ' . $strTableName . '.rootPage WHERE ' . $strTableName . '.id = ?')->execute($strWrapperID)->row();
     $qOrderByStr = $this->getOrderBy();
     $qProtectedStr = ' AND published = "1"';
     // get list
     $objList = $this->Database->prepare('SELECT * FROM ' . $strTableData . ' WHERE pid = ' . $strWrapperID . $qProtectedStr . $qStr . $qOrderByStr)->query();
     $arrItems = array();
     while ($objList->next()) {
         $arrItem = $objList->row();
         if (HelperModel::sortOutProtected($arrItem, $this->User->groups)) {
             continue;
         }
         if (!HelperModel::outSideScope($arrItem['start'], $arrItem['stop'])) {
             continue;
         }
         // image
         $imagePath = $this->generateSingeSrc($objList);
         if ($imagePath) {
             $arrItem['singleSRC'] = $imagePath;
         }
         if ($arrItem['size']) {
             $arrItem['size'] = deserialize($arrItem['size']);
         }
         if ($arrItem['cssID']) {
             $arrItem['cssID'] = deserialize($arrItem['cssID']);
         }
         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();
         }
         // create href
         $arrItem['href'] = null;
         if ($addDetailPage == '1' && $objList->source == 'default') {
             // reset target
             $arrItem['target'] = '';
             $arrItem['href'] = $this->generateUrl($rootDB, $arrItem['alias']);
             // $listDB->alias
         }
         if ($arrItem['source'] == 'external') {
             $arrItem['href'] = $arrItem['url'];
         }
         if ($arrItem['source'] == 'internal') {
             // reset target
             $arrItem['target'] = '';
             $jumpToDB = $this->Database->prepare('SELECT * FROM tl_page WHERE id = ?')->execute($objList->jumpTo)->row();
             $strTaxonomyUrl = \Config::get('taxonomyDisable') ? '' : $this->generateTaxonomyUrl();
             $arrItem['href'] = $this->generateFrontendUrl($jumpToDB, $strTaxonomyUrl);
         }
         // check for text search
         if ($qTextSearch) {
             if (!$textSearchResults[$arrItem['id']]) {
                 continue;
             }
         }
         //
         $arrItems[] = $arrItem;
     }
     if (\Input::get('orderBy') && mb_strtoupper(\Input::get('orderBy'), 'UTF-8') == 'RAND') {
         shuffle($arrItems);
     }
     $total = count($arrItems);
     $this->listViewLimit = $total;
     $this->createPagination($total);
     $objTemplate = new \FrontendTemplate($strTemplate);
     $strResults = '';
     for ($i = $this->listViewOffset; $i < $this->listViewLimit; $i++) {
         $item = $arrItems[$i];
         // set css and id
         $item['cssID'] = deserialize($item['cssID']);
         $item['itemID'] = $item['cssID'][0];
         $item['itemCSS'] = $item['cssID'][1] ? ' ' . $item['cssID'][1] : '';
         // set date format
         $date = date('Y-m-d', $item['date']);
         $time = date('H:i', $item['time']);
         $dateTime = $time ? $date . ' ' . $time : $date;
         $item['dateTime'] = $dateTime;
         $item['date'] = $item['date'] ? date($dateFormat, $item['date']) : '';
         $item['time'] = $item['time'] ? date($timeFormat, $item['time']) : '';
         // set more
         $item['more'] = $GLOBALS['TL_LANG']['MSC']['more'];
         // get list view ce
         $objCte = ContentModelExtend::findPublishedByPidAndTable($item['id'], $strTableName . '_data', array('fview' => 'list'));
         $arrElements = 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;
                 $arrElements[] = $this->getContentElement($objRow, $this->strColumn);
                 ++$intCount;
             }
         }
         $item['teaser'] = $arrElements;
         // set odd and even classes
         $item['cssClass'] = $i % 2 ? ' even' : ' odd';
         //field
         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 = $item[$id];
                 if (in_array($type, $arrayAsValue)) {
                     $value = deserialize($value);
                 }
                 // unserialize
                 $objFieldTemplate = new \FrontendTemplate($tplName);
                 $objFieldTemplate->setData(array('value' => $value, 'type' => $type, 'item' => $item));
                 $item[$id] = $objFieldTemplate->parse();
             }
         }
         // set last first classes
         if ($i == 0) {
             $item['cssClass'] .= ' first';
         }
         if ($i == $this->listViewLimit - 1) {
             $item['cssClass'] .= ' last';
         }
         // create marker path
         if ($item['addMarker'] && $item['markerSRC']) {
             if ($this->markerCache[$item['markerSRC']]) {
                 $item['markerSRC'] = $this->markerCache[$item['markerSRC']];
             } else {
                 $markerDB = $this->Database->prepare('SELECT * FROM tl_files WHERE uuid = ?')->execute($item['markerSRC']);
                 if ($markerDB->count()) {
                     $pathInfo = $markerDB->row()['path'];
                     if ($pathInfo) {
                         $this->markerCache[$item['markerSRC']] = $pathInfo;
                         $item['markerSRC'] = $pathInfo;
                     }
                 }
             }
         }
         // map settings from field
         if (!empty($mapFields)) {
             foreach ($mapFields as $map) {
                 $objMapTemplate = new \FrontendTemplate($map['template']);
                 $item['mapSettings'] = $map;
                 $objMapTemplate->setData($item);
                 $item[$map['fieldID']] = $objMapTemplate->parse();
             }
         }
         // mapSettings
         if (!empty($mapSettings)) {
             $item['mapSettings'] = $mapSettings;
         }
         // set clean options
         if (!empty($arrCleanOptions)) {
             $item['cleanOptions'] = $arrCleanOptions;
             // overwrite clean options
             foreach ($arrCleanOptions as $fieldID => $options) {
                 if ($item[$fieldID] && is_string($item[$fieldID])) {
                     $arrValues = explode(',', $item[$fieldID]);
                     $arrValuesAsString = array();
                     $arrValuesAsArray = array();
                     if (is_array($arrValues)) {
                         foreach ($arrValues as $val) {
                             $arrValuesAsArray[$val] = $options[$val];
                             $arrValuesAsString[] = $options[$val];
                         }
                     }
                     $item[$fieldID . 'AsArray'] = $arrValuesAsArray;
                     $item[$fieldID] = implode(', ', $arrValuesAsString);
                 }
             }
         }
         //set data
         $objTemplate->setData($item);
         //set image
         if ($item['addImage']) {
             $this->addImageToTemplate($objTemplate, array('singleSRC' => $item['singleSRC'], 'alt' => $item['alt'], 'size' => $item['size'], 'fullsize' => $item['fullsize'], 'caption' => $item['caption'], 'title' => $item['title']));
         }
         // set enclosure
         $objTemplate->enclosure = array();
         if ($item['addEnclosure']) {
             $this->addEnclosuresToTemplate($objTemplate, $item);
         }
         $arrResults[] = $item;
         $strResults .= $objTemplate->parse();
     }
     $arrData = array('arrData' => $arrResults, 'strTemplate' => $strResults, 'arrFields' => $arrModuleData, 'arrWrapper' => $wrapperDB, 'arrLabels' => array('noResults' => $GLOBALS['TL_LANG']['MSC']['noResult']));
     header('Content-type: application/json');
     echo json_encode($arrData, 512);
     exit;
 }
Exemple #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);
     }
 }