system/modules/dma_elementgenerator/DMAElementGenerator.php line 51

Open in your IDE?
  1. <?php
  2. /**
  3. * Contao Open Source CMS
  4. *
  5. * Copyright (c) 2005-2015 Leo Feyer
  6. *
  7. * @license LGPL-3.0+
  8. */
  9. namespace DMA;
  10. use Contao\ContentModel;
  11. /**
  12. * Class DMAElementGeneratorContent
  13. *
  14. * the dynamic contentelement
  15. *
  16. * @copyright DMA GmbH
  17. * @author Carsten Kollmeier
  18. * @author Janosch Skuplik <skuplik@dma.do>
  19. * @package DMAElementGenerator
  20. */
  21. class DMAElementGenerator extends \Frontend
  22. {
  23. protected $strTemplate = 'dma_eg_default';
  24. private $blnDisplayInDivs = false;
  25. public function generate($data)
  26. {
  27. return $this->compile($data);
  28. }
  29. public function dmaEgLoadLanguageFile($strName, $strLanguage)
  30. {
  31. // wird für die Installations-Routine benötigt
  32. if (!$this->Database->tableExists("tl_dma_eg"))
  33. {
  34. return;
  35. }
  36. // Support für ce-access etc.
  37. if ($strName == "default")
  38. {
  39. $objContentElements = \DmaEgModel::findBy('content', 1);
  40. if ($objContentElements !== null)
  41. {
  42. while($objContentElements->next())
  43. {
  44. $GLOBALS['TL_LANG']['CTE'][DMA_EG_PREFIX . $objContentElements->id] = array
  45. (
  46. $objContentElements->title,
  47. $objContentElements->description ? $objContentElements->description : $objContentElements->title
  48. );
  49. }
  50. }
  51. }
  52. }
  53. protected function compile($data)
  54. {
  55. $elementID = str_replace(DMA_EG_PREFIX, '', $data->type);
  56. $objElement = \DmaEgModel::findOneBy('id', $elementID);
  57. if ($objElement === null)
  58. {
  59. return;
  60. }
  61. //Im Backend in jedem Fall ein html5-Template verwenden
  62. if (TL_MODE == 'BE' && version_compare(VERSION . '.' . BUILD, '2.10.0', '>='))
  63. {
  64. try
  65. {
  66. $this->getTemplate($objElement->template);
  67. }
  68. catch (\Exception $e)
  69. {
  70. $objElement->template = $this->strTemplate;
  71. }
  72. }
  73. if (TL_MODE == 'BE' && $objElement->be_template)
  74. {
  75. $objElement->template = $objElement->be_template;
  76. }
  77. if (TL_MODE == 'FE' && $data->dmaElementTpl)
  78. {
  79. $objElement->template = $data->dmaElementTpl;
  80. }
  81. //Ausgabe in divs statt ul-li-Kontruktion ermöglichen
  82. if ($objElement->display_in_divs)
  83. {
  84. $this->blnDisplayInDivs = true;
  85. }
  86. //eigene Klasse für ce_ oder mod_ Überschreibt die standardmäßige dma_eg_?
  87. if ($objElement->class)
  88. {
  89. $data->type = $objElement->class;
  90. }
  91. $arrElements = array();
  92. $arrLabels = array();
  93. $arrClasses = array();
  94. $arrTemplateData = array();
  95. $arrData = deserialize($data->dma_eg_data);
  96. $objField = \DmaEgFieldsModel::findAllNotLegendsByPid($elementID);
  97. if ($objField === null)
  98. {
  99. return "";
  100. }
  101. $strFields = '';
  102. while ($objField->next())
  103. {
  104. if ($objField->useCheckboxCondition && !$objField->renderHiddenData)
  105. {
  106. if ($objField->subpaletteSelector)
  107. {
  108. $objSubSelector = \DmaEgFieldsModel::findOneBy('id', $objField->subpaletteSelector);
  109. if ($objSubSelector !== null && $arrData[$objSubSelector->title] == "")
  110. {
  111. continue;
  112. }
  113. }
  114. }
  115. $strFieldTemplate = "dma_egfield_default";
  116. if (TL_MODE == "FE")
  117. {
  118. $strFieldTemplate = $objField->template ? $objField->template : 'dma_egfield_default';
  119. }
  120. $objFieldTemplate = new \FrontendTemplate($strFieldTemplate);
  121. //Ausgabe in divs statt ul-li-Konstruktion ermöglichen
  122. if ($this->blnDisplayInDivs)
  123. {
  124. $objFieldTemplate->divs = true;
  125. }
  126. //Ausgabe ohne label ermöglichen
  127. if ($objElement->without_label)
  128. {
  129. $objFieldTemplate->nolabels = true;
  130. }
  131. //echo $objField->title;
  132. $objFieldTemplate->addImage = false;
  133. $objFieldTemplate->title = $objField->title;
  134. $objFieldTemplate->value = $arrElements[$objField->title] = $arrData[$objField->title] ?? '';
  135. $objFieldTemplate->label = $arrLabels[$objField->title] = $objField->label;
  136. $objFieldTemplate->class = $arrClasses[$objField->title] = ($objField->class == '' ? '' : $objField->class.' ').$objField->type;
  137. //intelligente Ausgabe ;-)
  138. $arrTemplateData[$objField->title] = array();
  139. $arrTemplateData[$objField->title]['raw'] = $arrData[$objField->title] ?? '';
  140. $arrTemplateData[$objField->title]['value'] = $arrData[$objField->title] ?? '';
  141. $arrTemplateData[$objField->title]['type'] = $objField->type;
  142. $arrTemplateData[$objField->title]['label'] = $objField->label;
  143. //formatierte Ausgabe von bekannten Fällen
  144. if ($objField->eval_rgxp)
  145. {
  146. switch ($objField->eval_rgxp)
  147. {
  148. case 'date':
  149. $objFieldTemplate->value = $arrTemplateData[$objField->title]['value'] = $this->parseDate($GLOBALS['TL_CONFIG']['dateFormat'], $arrData[$objField->title]);
  150. break;
  151. case 'datim':
  152. $objFieldTemplate->value = $arrTemplateData[$objField->title]['value'] = $this->parseDate($GLOBALS['TL_CONFIG']['datimFormat'], $arrData[$objField->title]);
  153. break;
  154. case 'time':
  155. $objFieldTemplate->value = $arrTemplateData[$objField->title]['value'] = $this->parseDate($GLOBALS['TL_CONFIG']['timeFormat'], $arrData[$objField->title]);
  156. break;
  157. case 'email':
  158. $objFieldTemplate->value = $arrTemplateData[$objField->title]['value'] = '{{email::'.$arrData[$objField->title].'}}';
  159. break;
  160. }
  161. }
  162. //Handling von Textareas ohne RTE
  163. if ($objField->type=='textarea' && !$objField->eval_rte && !$objField->eval_allow_html)
  164. {
  165. //Einfügen von Zeilenumbrüchen
  166. $objFieldTemplate->value = $arrTemplateData[$objField->title]['value'] = nl2br($arrData[$objField->title]);
  167. }
  168. //Handling von checkboxen
  169. if ($objField->type=='checkbox' && is_array(trimsplit(',',$arrData[$objField->title])))
  170. {
  171. $tempArrCbx = trimsplit(',',$arrData[$objField->title]);
  172. $objFieldTemplate->value = '';
  173. $arrTemplateData[$objField->title]['value'] = array();
  174. foreach ($tempArrCbx as $checkbox)
  175. {
  176. $objFieldTemplate->value .= '<span class="cbx_entry">' . $checkbox . '</span>';
  177. $arrTemplateData[$objField->title]['value'][] = $checkbox;
  178. }
  179. }
  180. // Handling von Listen
  181. if ($objField->type=='listWizard' && is_array(trimsplit(',',$arrData[$objField->title])))
  182. {
  183. $arrTemplateData[$objField->title]['value'] = deserialize($arrData[$objField->title]);
  184. }
  185. // Handling von Tabellen
  186. if ($objField->type=='tableWizard' && is_array(trimsplit(',',$arrData[$objField->title])))
  187. {
  188. $arrTemplateData[$objField->title]['value'] = deserialize($arrData[$objField->title]);
  189. $arrTemplateData[$objField->title]['data'] = array();
  190. $limit = count($arrTemplateData[$objField->title]['value']);
  191. for ($j=0; $j<$limit; $j++)
  192. {
  193. $class_tr = '';
  194. if ($j == 0)
  195. {
  196. $class_tr .= ' row_first';
  197. }
  198. if ($j == ($limit - 1))
  199. {
  200. $class_tr .= ' row_last';
  201. }
  202. $class_eo = (($j % 2) == 0) ? ' even' : ' odd';
  203. foreach ($arrTemplateData[$objField->title]['value'][$j] as $i=>$v)
  204. {
  205. $class_td = '';
  206. if ($i == 0)
  207. {
  208. $class_td .= ' col_first';
  209. }
  210. if ($i == (count($arrTemplateData[$objField->title]['value'][$j]) - 1))
  211. {
  212. $class_td .= ' col_last';
  213. }
  214. $arrTemplateData[$objField->title]['data']['row_' . $j . $class_tr . $class_eo][] = array
  215. (
  216. 'class' => 'col_'.$i . $class_td,
  217. 'content' => (($v != '') ? ($v) : '&nbsp;')
  218. );
  219. }
  220. }
  221. }
  222. // Handling von Selectmenüs mit Datenbankstruktur
  223. if ($objField->type == 'select' && $objField->optionsType == 'database')
  224. {
  225. $objDatabaseData = $this->Database->prepare("SELECT * FROM " . $objField->optDbTable . " WHERE id=?")
  226. ->limit(1)
  227. ->execute($arrData[$objField->title]);
  228. if ($objDatabaseData->numRows == 1)
  229. {
  230. $arrTemplateData[$objField->title]['value'] = $objDatabaseData->row();
  231. }
  232. }
  233. // Handling von Selectmenüs auf Array-Basis
  234. if ($objField->type == 'select' && $objField->optionsType == 'array')
  235. {
  236. if (is_array($GLOBALS['TL_DMA_SELECT_OPTIONS'][$objField->optArrayKey]))
  237. {
  238. if ($GLOBALS['TL_DMA_SELECT_OPTIONS'][$objField->optArrayKey][$arrData[$objField->title]])
  239. {
  240. $arrTemplateData[$objField->title]['value'] = $GLOBALS['TL_DMA_SELECT_OPTIONS'][$objField->optArrayKey][$arrData[$objField->title]];
  241. }
  242. }
  243. }
  244. // Handling von Selectmenüs und eigener Key-Struktur
  245. if ($objField->type == 'select' && $objField->optionsType == 'manual' && $objField->showLabelInFrontend)
  246. {
  247. $arrOptions = deserialize($objField->options);
  248. if (is_array($arrOptions))
  249. {
  250. foreach ($arrOptions as $index => $arrOptionData)
  251. {
  252. if ($arrOptionData['value'] == $arrData[$objField->title])
  253. {
  254. $arrElements[$objField->title] = $arrTemplateData[$objField->title]['value'] = $objFieldTemplate->value = $arrOptionData['label'];
  255. }
  256. }
  257. }
  258. }
  259. //Handling von Seiten
  260. if ($objField->type=='pageTree')
  261. {
  262. if (substr($objField->eval_field_type,3)=='checkbox')
  263. {
  264. $tempArray = trimsplit(',',$arrData[$objField->title]);
  265. $arrData[$objField->title] = serialize($tempArray);
  266. }
  267. if (is_array(deserialize($arrData[$objField->title])))
  268. {
  269. //mehrere Seiten
  270. $tempArrPages = deserialize($arrData[$objField->title]);
  271. $arrTemplateData[$objField->title]['value'] = array();
  272. foreach ($tempArrPages as $page)
  273. {
  274. $objLinkedPage = $this->Database->prepare("SELECT * FROM tl_page WHERE id=?")
  275. ->limit(1)
  276. ->execute($page);
  277. if ($objLinkedPage->numRows)
  278. {
  279. $arrTemplateData[$objField->title]['value'][] = array(
  280. 'raw' => $page,
  281. 'alias' => $objLinkedPage->alias,
  282. 'href' => $this->generateFrontendUrl($objLinkedPage->row()),
  283. 'title' => $objLinkedPage->title
  284. );
  285. }
  286. }
  287. }
  288. else
  289. {
  290. $objLinkedPage = $this->Database->prepare("SELECT * FROM tl_page WHERE id=?")
  291. ->limit(1)
  292. ->execute($arrData[$objField->title]);
  293. if ($objLinkedPage->numRows)
  294. {
  295. $arrTemplateData[$objField->title]['value'] = array(
  296. 'alias' => $objLinkedPage->alias,
  297. 'href' => $this->generateFrontendUrl($objLinkedPage->row()),
  298. 'title' => $objLinkedPage->title
  299. );
  300. $objFieldTemplate->value = $this->generateFrontendUrl($objLinkedPage->row());
  301. }
  302. }
  303. }
  304. //Dateihandling - zusätzliche Informationen
  305. if ($objField->type=='fileTree')
  306. {
  307. if (substr($objField->eval_field_type,3)=='checkbox')
  308. {
  309. $tempArray = trimsplit(',',$arrData[$objField->title]);
  310. $arrData[$objField->title] = serialize($tempArray);
  311. }
  312. if (is_array(deserialize($arrData[$objField->title])))
  313. {
  314. //mehrere Dateien
  315. $tempArrFiles = deserialize($arrData[$objField->title]);
  316. if ($objField->eval_sortable)
  317. {
  318. $tmp = deserialize($data->orderSRC);
  319. if (!empty($tmp) && is_array($tmp))
  320. {
  321. // Remove all values
  322. $arrOrder = array_map(function(){}, array_flip($tmp));
  323. // Move the matching elements to their position in $arrOrder
  324. foreach ($tempArrFiles as $k=>$v)
  325. {
  326. $vBin = \StringUtil::uuidToBin($v);
  327. if (array_key_exists($vBin, $arrOrder))
  328. {
  329. $arrOrder[$vBin] = $v;
  330. unset($tempArrFiles[$k]);
  331. }
  332. }
  333. // Append the left-over images at the end
  334. if (!empty($tempArrFiles))
  335. {
  336. $arrOrder = array_merge($arrOrder, array_values($tempArrFiles));
  337. }
  338. // Remove empty (unreplaced) entries
  339. $tempArrFiles = array_values(array_filter($arrOrder));
  340. unset($arrOrder);
  341. }
  342. }
  343. $arrTemplateData[$objField->title]['value'] = array();
  344. foreach ($tempArrFiles as $file)
  345. {
  346. $objFile = null;
  347. if (is_numeric($file))
  348. {
  349. $objFiles = \FilesModel::findByPk($file);
  350. if ($objFiles)
  351. {
  352. $arrImage = array
  353. (
  354. 'singleSRC' => $objFiles->path
  355. );
  356. $objFile = new \File($objFiles->path, true);
  357. }
  358. }
  359. elseif (strlen($file)==36)
  360. {
  361. $objFiles = \FilesModel::findByUuid($file);
  362. if ($objFiles)
  363. {
  364. $arrImage = array(
  365. 'singleSRC' => $objFiles->path
  366. );
  367. $objFile = new \File($objFiles->path, true);
  368. }
  369. }
  370. elseif (is_file(TL_ROOT . '/' . $file))
  371. {
  372. $objFile = new \File($file);
  373. }
  374. // Send the file to the browser
  375. if ($this->Input->get('file', true) && $this->Input->get('file', true) != '')
  376. {
  377. $file = $this->Input->get('file', true);
  378. if ($file == $objFile->value)
  379. {
  380. $this->sendFileToBrowser($file);
  381. }
  382. }
  383. if ($objFile)
  384. {
  385. $arrTemplateData[$objField->title]['value'][] = array(
  386. 'raw' => $file,
  387. 'src' => $objFile->value,
  388. 'meta' => $objFiles ? deserialize($objFiles->meta) : '',
  389. 'value' => $objFile->value,
  390. 'dl' => $this->Environment->request . (($GLOBALS['TL_CONFIG']['disableAlias'] || strpos($this->Environment->request, '?') !== false) ? '&amp;' : '?') . 'file=' . $this->urlEncode($objFile->value),
  391. 'attributes' => array(
  392. 'width' => $objFile->width,
  393. 'height' => $objFile->height,
  394. 'extension' => $objFile->extension,
  395. 'icon' => $objFile->icon,
  396. 'size' => $this->getReadableSize($objFile->filesize, 1),
  397. 'filename' => $objFile->filename
  398. )
  399. );
  400. //$arrElementData[] = $objFile->path;
  401. }
  402. }
  403. }
  404. else
  405. {
  406. //eine Datei
  407. // file-handling for Contao 3
  408. $objFile = null;
  409. if (is_numeric($arrData[$objField->title]))
  410. {
  411. $objFiles = \FilesModel::findByPk($arrData[$objField->title]);
  412. if ($objFiles)
  413. {
  414. $arrImage = array(
  415. 'singleSRC' => $objFiles->path
  416. );
  417. $objFile = new \File($objFiles->path, true);
  418. }
  419. }
  420. elseif (strlen($arrData[$objField->title])==36)
  421. {
  422. $objFiles = \FilesModel::findByUuid($arrData[$objField->title]);
  423. if ($objFiles)
  424. {
  425. $arrImage = array(
  426. 'singleSRC' => $objFiles->path
  427. );
  428. $objFile = new \File($objFiles->path, true);
  429. }
  430. }
  431. else
  432. {
  433. if (is_file(TL_ROOT . '/' . $arrData[$objField->title]))
  434. {
  435. $objFile = new \File($arrData[$objField->title]);
  436. $arrImage = array(
  437. 'singleSRC' => $arrData[$objField->title]
  438. );
  439. }
  440. }
  441. //var_dump($objFile);
  442. //$objFile = new file($arrData['singleSRC']);
  443. // Send the file to the browser
  444. if ($this->Input->get('file', true) && $this->Input->get('file', true) != '')
  445. {
  446. $file = $this->Input->get('file', true);
  447. if ($file == $objFile->value)
  448. {
  449. $this->sendFileToBrowser($file);
  450. }
  451. }
  452. if ($objFile) {
  453. $arrTemplateData[$objField->title]['value'] = array();
  454. $arrTemplateData[$objField->title]['value'][] = array(
  455. 'raw' => $arrData[$objField->title],
  456. 'meta' => $objFiles ? deserialize($objFiles->meta) : '',
  457. 'src' => $objFile->value,
  458. 'value' => $objFile->value,
  459. 'dl' => $this->Environment->request . (($GLOBALS['TL_CONFIG']['disableAlias'] || strpos($this->Environment->request, '?') !== false) ? '&amp;' : '?') . 'file=' . $this->urlEncode($objFile->value),
  460. 'attributes' => array(
  461. 'width' => $objFile->width,
  462. 'height' => $objFile->height,
  463. 'extension' => $objFile->extension,
  464. 'icon' => $objFile->icon,
  465. 'size' => $this->getReadableSize($objFile->filesize, 1),
  466. 'filename' => $objFile->filename
  467. )
  468. );
  469. if ($objFile->width && $objFile->height)
  470. {
  471. $this->addImageToTemplate($objFieldTemplate, $arrImage, null, null);
  472. }
  473. $objFieldTemplate->value = '';
  474. $arrElements[$objField->title] = $objFile->path;
  475. }
  476. }
  477. }
  478. // Handling von kompletten Links
  479. if ($objField->type=='hyperlink')
  480. {
  481. $linkData = array();
  482. $arrHyperlinkData = deserialize($objField->hyperlink_data);
  483. if (is_array($arrHyperlinkData) && sizeof($arrHyperlinkData)>0)
  484. {
  485. foreach ($arrHyperlinkData as $hyperlinkData)
  486. {
  487. $linkData[$hyperlinkData] = $arrData[$objField->title . '--' . $hyperlinkData];
  488. }
  489. }
  490. if ($linkData['url'])
  491. {
  492. $objHyperlink = new dmaHyperlinkHelper($linkData);
  493. $objFieldTemplate->value = $objHyperlink->generate();
  494. $arrElements[$objField->title] = $objHyperlink->generate();
  495. $arrTemplateData[$objField->title]['raw'] = $linkData;//deserialize($objField->hyperlink_data);
  496. $arrTemplateData[$objField->title]['value'] = $linkData['url'];
  497. if (strpos($linkData['url'], "{{link_url::")!==false)
  498. {
  499. $intLinkId = str_replace(array('{{link_url::', '}}'), '', $linkData['url']);
  500. $objPageModel = \PageModel::findPublishedById($intLinkId);
  501. if ($objPageModel !== null)
  502. {
  503. $arrTemplateData[$objField->title]['raw']['page'] = $objPageModel->row();
  504. }
  505. }
  506. }
  507. }
  508. // Handling von kompletten Bildern
  509. if ($objField->type=='image' && $objField->image_data)
  510. {
  511. $arrImage = array();
  512. $arrImage['id'] = $data->id;
  513. $arrImageData = deserialize($objField->image_data);
  514. if (is_array($arrImageData) && sizeof($arrImageData)>0)
  515. {
  516. foreach ($arrImageData as $imageData)
  517. {
  518. $arrImage[$imageData] = $arrData[$objField->title . '--' . $imageData] ?? '';
  519. }
  520. }
  521. $arrImagePrecompiled = $arrImage;
  522. // file-handling for Contao 3
  523. if (is_numeric($arrImage['singleSRC']))
  524. {
  525. $objFile = \FilesModel::findByPk($arrImage['singleSRC']);
  526. /*if ($objFile === null || !is_file(TL_ROOT . '/' . $objFile->path))
  527. {
  528. $arrImage['singleSRC'] = '';
  529. }*/
  530. $arrTemplateData[$objField->title]['raw'] = $arrImage;//['singleSRC'];
  531. if (is_file(TL_ROOT . '/' . $objFile->path))
  532. {
  533. $objFileData = new \File($objFile->path, true);
  534. $arrTemplateData[$objField->title]['attributes'] = array(
  535. 'width' => $objFileData->width,
  536. 'height' => $objFileData->height,
  537. 'extension' => $objFileData->extension,
  538. 'icon' => $objFileData->icon,
  539. 'size' => $this->getReadableSize($objFileData->filesize, 1),
  540. 'filename' => $objFileData->filename
  541. );
  542. }
  543. if ($objFile->meta)
  544. {
  545. $arrTemplateData[$objField->title]['meta'] = deserialize($objFile->meta);
  546. }
  547. $arrTemplateData[$objField->title]['value'] = $objFile->path;
  548. $arrImagePrecompiled['singleSRC'] = $objFile->path;
  549. }
  550. elseif (\Validator::isUuid($arrImage['singleSRC']))
  551. {
  552. $objFile = \FilesModel::findByUuid($arrImage['singleSRC']);
  553. if ($objFile)
  554. {
  555. $arrTemplateData[$objField->title]['raw'] = $arrImage;//['singleSRC'];
  556. if (is_file(TL_ROOT . '/' . $objFile->path))
  557. {
  558. $objFileData = new \File($objFile->path, true);
  559. $arrTemplateData[$objField->title]['attributes'] = array(
  560. 'width' => $objFileData->width,
  561. 'height' => $objFileData->height,
  562. 'extension' => $objFileData->extension,
  563. 'icon' => $objFileData->icon,
  564. 'size' => $this->getReadableSize($objFileData->filesize, 1),
  565. 'filename' => $objFileData->filename
  566. );
  567. }
  568. if ($objFile->meta)
  569. {
  570. $arrTemplateData[$objField->title]['meta'] = deserialize($objFile->meta);
  571. }
  572. $arrTemplateData[$objField->title]['value'] = $objFile->path;
  573. $arrImagePrecompiled['singleSRC'] = $objFile->path;
  574. }
  575. }
  576. if ($arrImage['size'] ?? null)
  577. {
  578. $arrSize = deserialize($arrImage['size']);
  579. $arrTemplateData[$objField->title]['value'] = \Image::get($objFile->path, $arrSize[0], $arrSize[1], $arrSize[2]);
  580. }
  581. //$objFieldTemplate->class = $objFieldTemplate->class ? ($objFieldTemplate->class . " " . $arrImage['floating']) : $arrImage['floating'];
  582. if ($arrImagePrecompiled['singleSRC'] ?? null)
  583. {
  584. $this->addImageToTemplate($objFieldTemplate, $arrImagePrecompiled);
  585. $arrImage['type'] = 'image';
  586. $objImage = new dmaContentImageHelper($arrImage);
  587. $arrElements[$objField->title] = $objImage->generate();
  588. }
  589. }
  590. if ($arrTemplateData[$objField->title]['value'])
  591. {
  592. $objFieldTemplate->addData = $arrTemplateData[$objField->title];
  593. $strFields .= $objFieldTemplate->parse();
  594. $arrTemplateData[$objField->title]['parsed'] = $objFieldTemplate->parse();
  595. //$arrElements[$objField->title] = $objFieldTemplate->parse();
  596. }
  597. }
  598. if (is_array(unserialize($objElement->template))) {
  599. return null;
  600. }
  601. $objTemplate = new \FrontendTemplate(($objElement->template ? $objElement->template : $this->strTemplate));
  602. //Ausgabe in divs statt ul-li-Konstruktion ermöglichen
  603. if ($this->blnDisplayInDivs)
  604. {
  605. $objTemplate->divs = true;
  606. }
  607. $objArticle = $this->Database->prepare("SELECT title,alias FROM tl_article WHERE id=?")
  608. ->limit(1)
  609. ->execute($data->pid);
  610. $objTemplate->contentElement = true;
  611. $objTemplate->id = $data->id;
  612. $objTemplate->articleID = $data->pid;
  613. $objTemplate->articleTitle = $objArticle->title;
  614. $objTemplate->articleAlias = $objArticle->alias;
  615. $objTemplate->elements = $arrElements;
  616. $objTemplate->labels = $arrLabels;
  617. $objTemplate->classes = $arrClasses;
  618. $objTemplate->fields = $strFields;
  619. $objTemplate->data = $arrTemplateData;
  620. // Counter for Elements and Global
  621. if (!isset($GLOBALS['DMA_EG']['EL_COUNT']['all']))
  622. {
  623. $GLOBALS['DMA_EG']['EL_COUNT']['all'] = 0;
  624. }
  625. else {
  626. $GLOBALS['DMA_EG']['EL_COUNT']['all']++;
  627. }
  628. if (!isset($GLOBALS['DMA_EG']['EL_COUNT'][standardize($objElement->title)]))
  629. {
  630. $GLOBALS['DMA_EG']['EL_COUNT'][standardize($objElement->title)] = 0;
  631. }
  632. else {
  633. $GLOBALS['DMA_EG']['EL_COUNT'][standardize($objElement->title)]++;
  634. }
  635. $objTemplate->gobalCounter = $GLOBALS['DMA_EG']['EL_COUNT']['all'];
  636. $objTemplate->singleCounter = $GLOBALS['DMA_EG']['EL_COUNT'][standardize($objElement->title)];
  637. $arrStyle = array();
  638. if (isset($data->space[0]) && $data->space[0] != '')
  639. {
  640. $arrStyle[] = 'margin-top:'.$data->space[0].'px;';
  641. }
  642. if (isset($data->space[1]) && $data->space[1] != '')
  643. {
  644. $arrStyle[] = 'margin-bottom:'.$data->space[1].'px;';
  645. }
  646. $objTemplate->style = count($arrStyle) ? implode(' ', $arrStyle) : '';
  647. $objTemplate->cssID = ($data->cssID[0] != '') ? ' id="' . $data->cssID[0] . '"' : '';
  648. $objTemplate->class = trim(($objElement->content ? 'ce_' : 'mod_') . $data->type . ' ' . $data->cssID[1]);
  649. return $objTemplate->parse();
  650. }
  651. // we need to use an own method for the executePostActions-function
  652. // the table-fields are no real fields
  653. public function fixedAjaxRequest($strAction, \DataContainer $dc) {
  654. if ($strAction=='reloadPagetreeDMA' || $strAction=='reloadFiletreeDMA')
  655. {
  656. $intId = \Input::get('id');
  657. $strField = $strFieldName = \Input::post('name');
  658. // Handle the keys in "edit multiple" mode
  659. if (\Input::get('act') == 'editAll')
  660. {
  661. $intId = preg_replace('/.*_([0-9a-zA-Z]+)$/', '$1', $strField);
  662. $strField = preg_replace('/(.*)_[0-9a-zA-Z]+$/', '$1', $strField);
  663. }
  664. // Validate the request data
  665. if ($GLOBALS['TL_DCA'][$dc->table]['config']['dataContainer'] == 'File')
  666. {
  667. // The field does not exist
  668. if (!array_key_exists($strField, $GLOBALS['TL_CONFIG']))
  669. {
  670. $this->log('Field "' . $strField . '" does not exist in the global configuration', 'Ajax executePostActions()', TL_ERROR);
  671. header('HTTP/1.1 400 Bad Request');
  672. die('Bad Request');
  673. }
  674. }
  675. elseif ($this->Database->tableExists($dc->table))
  676. {
  677. // The field does not exist
  678. if (!$this->Database->fieldExists($strField, $dc->table))
  679. {
  680. $this->log('Field "' . $strField . '" does not exist in table "' . $dc->table . '"', 'Ajax executePostActions()', TL_ERROR);
  681. //header('HTTP/1.1 400 Bad Request');
  682. //die('Bad Request');
  683. }
  684. $objRow = $this->Database->prepare("SELECT * FROM " . $dc->table . " WHERE id=?")
  685. ->execute($intId);
  686. // The record does not exist
  687. if ($objRow->numRows < 1)
  688. {
  689. $this->log('A record with the ID "' . $intId . '" does not exist in table "' . $dc->table . '"', 'Ajax executePostActions()', TL_ERROR);
  690. //header('HTTP/1.1 400 Bad Request');
  691. //die('Bad Request');
  692. }
  693. }
  694. $varValue = \Input::post('value');
  695. $strKey = ($strAction == 'reloadPagetreeDMA') ? 'pageTree' : 'fileTree';
  696. // Convert the selected values
  697. if ($varValue != '')
  698. {
  699. if (strstr($varValue, "\t"))
  700. {
  701. // Contao 3.1
  702. $varValue = trimsplit("\t", $varValue);
  703. }
  704. else
  705. {
  706. // Contao 3.0
  707. $varValue = trimsplit(',', $varValue);
  708. }
  709. // Automatically add resources to the DBAFS
  710. if ($strKey == 'fileTree')
  711. {
  712. foreach ($varValue as $k=>$v)
  713. {
  714. $varValue[$k] = \Dbafs::addResource($v)->id;
  715. }
  716. }
  717. $varValue = serialize($varValue);
  718. }
  719. // Set the new value
  720. if ($GLOBALS['TL_DCA'][$dc->table]['config']['dataContainer'] == 'File')
  721. {
  722. $GLOBALS['TL_CONFIG'][$strField] = $varValue;
  723. $arrAttribs['activeRecord'] = null;
  724. }
  725. elseif ($this->Database->tableExists($dc->table))
  726. {
  727. $objRow->$strField = $varValue;
  728. $arrAttribs['activeRecord'] = $objRow;
  729. }
  730. $arrAttribs['id'] = $strFieldName;
  731. $arrAttribs['name'] = $strFieldName;
  732. $arrAttribs['value'] = $varValue;
  733. $arrAttribs['strTable'] = $dc->table;
  734. $arrAttribs['strField'] = $strField;
  735. $objWidget = new $GLOBALS['BE_FFL'][$strKey]($arrAttribs);
  736. echo $objWidget->generate();
  737. }
  738. }
  739. }
  740. class dmaHyperlinkHelper extends \ContentHyperlink
  741. {
  742. public function __construct($arrData)
  743. {
  744. $arrData['tstamp'] = time();
  745. $this->type = 'hyperlink';
  746. $this->url = $arrData['url'] ?? '';
  747. $this->target = $arrData['target'] ?? '';
  748. $this->linkTitle = $arrData['linkTitle'] ?? '';
  749. $this->rel = $arrData['rel'] ?? '';
  750. $this->embed = $arrData['embed'] ?? '';
  751. }
  752. }
  753. class dmaContentImageHelper extends \ContentImage
  754. {
  755. public function __construct($arrData)
  756. {
  757. $arrData['tstamp'] = time();
  758. $this->type = 'image';
  759. $this->singleSRC = $arrData['singleSRC'];
  760. $this->id = $arrData['id'];
  761. $this->arrData = $arrData;
  762. $this->objModel = new ContentModel();
  763. }
  764. }