TCEMainHook.php 104 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531
  1. <?php
  2. namespace Meramo\mrm_be\Hooks\TCE;
  3. use DOMDocument;
  4. use \TYPO3\CMS\Core\Utility\GeneralUtility;
  5. use \TYPO3\CMS\Core\Database\ConnectionPool;
  6. use \TYPO3\CMS\Core\Database\Connection;
  7. use \TYPO3\CMS\Core\Service\FlexFormService;
  8. use \TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools;
  9. use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
  10. use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
  11. use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
  12. use \Meramo\mrm_be\Mongoer as Mongoer;
  13. require_once GeneralUtility::getFileAbsFileName('typo3conf/ext/mrm_be/Resources/Private/PHP/phpqrcode/qrlib.php');
  14. class TCEMainHook
  15. {
  16. protected $imageSizes = array(
  17. 'mrm_be_cm_publication' => array(
  18. 'passthru' => array(
  19. 'small' => array('width' => 256),
  20. 'big' => array('width' => 512)
  21. )
  22. ),
  23. 'mrm_be_cm_homeheaderinfo' => array(
  24. 'i_1_1' => array(
  25. 'i_1_1' => array('width' => 140, 'height' => 140),
  26. ),
  27. 'i_16_9' => array(
  28. 'i_16_9' => array('width' => 140, 'height' => 79),
  29. ),
  30. 'default' => array(
  31. 'default' => array('width' => 140, 'height' => 94),
  32. )
  33. ),
  34. 'mrm_be_cm_explorerbox' => array(
  35. 'i_1_1' => array(
  36. 'img' => array('width' => 500, 'height' => 500),
  37. )
  38. ),
  39. 'mrm_be_cm_statementbox' => array(
  40. 'i_1_1' => array(
  41. 'img' => array('width' => 160, 'height' => 160),
  42. )
  43. ),
  44. 'mrm_be_cm_checklist-radiorange' => array(
  45. 'i_1_1' => array(
  46. 'img' => array('width' => 160, 'height' => 160),
  47. )
  48. ),
  49. 'mrm_be_cm_tileoverview' => array(
  50. 'default' => array(
  51. 'default_hero_lte600' => array('width' => 560, 'height' => 373),
  52. )
  53. ),
  54. 'mrm_be_cm_dynamic_tileexternaloverview' => array(
  55. 'default' => array(
  56. 'default_hero_lte600' => array('width' => 560, 'height' => 373),
  57. ),
  58. 'i_1_1' => array(
  59. 'square_big' => array('width' => 520, 'height' => 520),
  60. ),
  61. 'i_21_9' => array(
  62. 'flat_big' => array('width' => 700, 'height' => 300),
  63. ),
  64. ),
  65. 'mrm_be_cm_heroimage' => array(
  66. 'default' => array(
  67. 'lte600' => array('width' => 560, 'height' => 373),
  68. 'gt600' => array('width' => 408, 'height' => 272)
  69. ),
  70. ),
  71. 'mrm_be_cm_imageplus' => array(
  72. 'default' => array(
  73. 'ratio32' => array('width' => 439, 'height' => 293)
  74. ),
  75. 'i_16_9' => array(
  76. 'ratio169' => array('width' => 727, 'height' => 409)
  77. ),
  78. 'i_21_9' => array(
  79. 'ratio219' => array('width' => 984, 'height' => 422)
  80. )
  81. ),
  82. 'mrm_be_cm_contentimage' => array(
  83. 'i_1_1' => array(
  84. 'content_image' => array('width' => 160, 'height' => 160),
  85. 'content_image_maximized_lte600' => array('width' => 560, 'height' => 560),
  86. 'content_image_maximized_gt600' => array('width' => 460, 'height' => 460),
  87. ),
  88. ),
  89. 'mrm_be_cm_rawimage' => array('passthru' => true),
  90. 'mrm_be_cm_animation' => array('passthru' => true),
  91. 'mrm_be_cm_picturechoice' => array(
  92. 'i_1_1' => array(
  93. 'pic' => array('width' => 300, 'height' => 300)
  94. )
  95. ),
  96. 'overview_image' => array(
  97. 'default' => array(
  98. 'home_topics_lte767' => array('width' => 725, 'height' => 484),
  99. 'home_topics_gt767' => array('width' => 313, 'height' => 209),
  100. 'sidebar_banner_lte840' => array('width' => 100, 'height' => 66),
  101. 'rubrik_overview' => array('width' => 318, 'height' => 212),
  102. 'default_hero_lte600' => array('width' => 560, 'height' => 373),
  103. 'default_hero_gt600' => array('width' => 408, 'height' => 272, 'allowed_doktypes' => ['102']),
  104. ),
  105. 'i_1_1' => array(
  106. 'home_rubrik' => array('width' => 95, 'height' => 95),
  107. 'archive_block' => array('width' => 160, 'height' => 160),
  108. 'square_big' => array('width' => 520, 'height' => 520),
  109. ),
  110. 'i_16_9' => array(
  111. 'og' => array('width' => 1200, 'height' => 675),
  112. 'sidebar_banner_gt840' => array('width' => 282, 'height' => 159),
  113. ),
  114. 'i_21_9' => array(
  115. 'flat_tile' => array('width' => 400, 'height' => 171),
  116. 'flat_big' => array('width' => 700, 'height' => 300),
  117. ),
  118. )
  119. );
  120. private $imageService;
  121. private $resourceFactory;
  122. private $fileRepository;
  123. private $environmentService;
  124. private $queryBuilder;
  125. private $pageQueryBuilder;
  126. private $pageRepository;
  127. private $linkService;
  128. private $connection;
  129. function __construct()
  130. {
  131. $this->environmentService = GeneralUtility::makeInstance("TYPO3\CMS\Extbase\Service\EnvironmentService");
  132. $this->resourceFactory = GeneralUtility::makeInstance('TYPO3\CMS\Core\Resource\ResourceFactory');
  133. $this->imageService = GeneralUtility::makeInstance("TYPO3\CMS\Extbase\Service\ImageService");
  134. $this->fileRepository = GeneralUtility::makeInstance('TYPO3\CMS\Core\Resource\FileRepository');
  135. $this->pageRepository = GeneralUtility::makeInstance('TYPO3\CMS\Frontend\Page\PageRepository');
  136. $this->linkService = GeneralUtility::makeInstance('TYPO3\CMS\Core\LinkHandling\LinkService');
  137. $connection = GeneralUtility::makeInstance(ConnectionPool::class);
  138. $this->connection = $connection;
  139. $this->queryBuilder = $connection->getQueryBuilderForTable('tt_content');
  140. $this->queryBuilder->getRestrictions()->removeAll()
  141. ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
  142. ->add(GeneralUtility::makeInstance(HiddenRestriction::class));
  143. $this->pageQueryBuilder = $connection->getQueryBuilderForTable('pages');
  144. $this->pageQueryBuilder->getRestrictions()->removeAll();
  145. }
  146. public function processDatamap_beforeStart($pObj)
  147. {
  148. if (!isset($pObj->datamap['pages'])) return;
  149. foreach ($pObj->datamap['pages'] as $pid => &$_d) {
  150. if (!$pid || $pid < 0) continue;
  151. $starttime = $_d["starttime"];
  152. if ($starttime != 0)
  153. $_d["starttime"] = $this->startOfDay($starttime, null, true, true);
  154. $endtime = $_d["endtime"];
  155. if ($endtime != 0)
  156. $_d["endtime"] = $this->endOfDay($endtime, null, true, true);
  157. switch ($_d["red_status"]) {
  158. case "-1": //neu angelegt
  159. case "1": //in Bearbeitung
  160. case "2": //vorbereitet
  161. case "3": //geprüft
  162. case "21": //gesperrt
  163. case "22": //archiviert
  164. $_d["hidden"] = 1;
  165. break;
  166. case "11": //frei
  167. case "12": //online
  168. $_d["hidden"] = 0;
  169. break;
  170. default:
  171. break;
  172. }
  173. }
  174. }
  175. public function processCmdmap_afterFinish(\TYPO3\CMS\Core\DataHandling\DataHandler &$pObj)
  176. {
  177. if (!isset($pObj->datamap['pages'])) return;
  178. foreach ($pObj->datamap['pages'] as $pid => $_d) {
  179. if (!$pid || $pid < 0) continue;
  180. $this->log('processing PID: ' . $pid);
  181. $pageStatement = $this->pageQueryBuilder
  182. ->select('*')
  183. ->from('pages')
  184. ->setMaxResults(1)
  185. ->where(
  186. $this->pageQueryBuilder->expr()->eq('uid', $this->pageQueryBuilder->createNamedParameter($pid))
  187. )
  188. ->execute();
  189. $post = $pageStatement->fetchAll();
  190. $post = $post[0];
  191. if (!$post) continue;
  192. if ($post['doktype'] == 254) {
  193. $this->processFolderContent($post);
  194. continue;
  195. }
  196. if ($post['hidden'] == 1 || $post['deleted'] == 1) {
  197. Mongoer::sendRequest("pages", "delete", array("pageuid" => $pid));
  198. Mongoer::sendRequest("abialtcache", "delete", array("pageuid" => $pid));
  199. Mongoer::sendRequest("search", "delete", array("pageuid" => $pid));
  200. Mongoer::sendRequest("security", "delete", array("pageuid" => $pid));
  201. // DELETE existing page PDF
  202. $this->deletePagePDFIfExists($post['slug']);
  203. //continue;
  204. }
  205. $rootlineutil = GeneralUtility::makeInstance('TYPO3\CMS\Core\Utility\RootlineUtility', $pid);
  206. $rootline = array_reverse($rootlineutil->get($pid));
  207. $processedImages = array();
  208. $slugData = $this->constructSlug($pid);
  209. if (!$slugData) {
  210. $this->log($pid . " slugData empty");
  211. continue;
  212. }
  213. $qrfilename = '/var/www/html/typo3temp/' . mt_rand(0, 0xffffff) . '_' . mt_rand(0, 0xffffff) . '.svg';
  214. \QRcode::svg("https://abi.de" . $slugData, $qrfilename);
  215. $qrsvg = file_get_contents($qrfilename);
  216. unlink($qrfilename);
  217. $statement = $this->queryBuilder
  218. ->select('*')
  219. ->from('tt_content')
  220. ->where(
  221. $this->queryBuilder->expr()->eq('pid', $this->queryBuilder->createNamedParameter($pid))
  222. )
  223. ->execute();
  224. $fetchedTTContent = array();
  225. $pageType = "article";
  226. //$this->log($post["doktype"]);
  227. if ($post["doktype"] == 100) $pageType = "event-page";
  228. if ($post["doktype"] == 101) $pageType = "blog-page";
  229. if ($post["doktype"] == 102) $pageType = "blogger-page";
  230. if ($post["doktype"] == 103) $pageType = "archive";
  231. if ($post["doktype"] == 104) $pageType = "video-page";
  232. if ($post['is_siteroot'] == 1) $pageType = "home";
  233. // $overview_image = null;
  234. while ($row = $statement->fetch()) {
  235. $fetchedTTContent[] = $row;
  236. $row["doktype"] = $post["doktype"];
  237. }
  238. /* look for overview_image start */
  239. if ($pageType == "blogger-page" || $pageType == "video-page") {
  240. $overview_image = $this->processImagesTTContent($post, 'overview_image', 'pages', 'overview_image');
  241. $overview_image = $overview_image[0] ? $overview_image[0] : null;
  242. }
  243. if (!$overview_image) {
  244. $x = $this->findFirstAppearingElementByType("mrm_be_cm_postimage", $fetchedTTContent, "CType");
  245. if ($x) {
  246. $overview_image = $this->processImagesTTContent($x, 'overview_image');
  247. $overview_image = $overview_image[0] ? $overview_image[0] : null;
  248. }
  249. }
  250. if (!$overview_image) {
  251. foreach ($fetchedTTContent as $row) {
  252. if (!$overview_image && ($row['CType'] == "mrm_be_cm_heroimage" || $row['CType'] == "mrm_be_cm_contentimage" || $row['CType'] == "mrm_be_cm_rawimage")) {
  253. $overview_image = $this->processImagesTTContent($row, 'overview_image');
  254. $overview_image = $overview_image[0] ? $overview_image[0] : null;
  255. }
  256. }
  257. }
  258. /* look for overview_image end */
  259. if ($pageType != "home") {
  260. $initialContent = $this->createContentElement($pageType, array(), (object) array(), array());
  261. $initialH1Attribs = array();
  262. if ($post["roof"] && $post["roof"] != '') $initialH1Attribs["roof"] = $post["roof"];
  263. if ($post["title"] && $post["title"] != '') $initialH1Attribs["text"] = $post["title"];
  264. if (sizeof($initialH1Attribs) > 0) $initialContent["subElements"][] = $this->createContentElement("h1", array(), $initialH1Attribs);
  265. }
  266. $processedData = array(
  267. 'pageuid' => $pid,
  268. 'documentLanguage' => $post['documentlanguage'],
  269. 'url' => $slugData,
  270. 'shareableUrl' => "https://abi.de" . $slugData,
  271. 'title' => ($post['roof'] != '' ? $post['roof'] . ": " : "") . $post['title'],
  272. 'activeMenuPage' => $post['targetgroup'],
  273. 'overviewImage' => $overview_image,
  274. 'teasers' => array(
  275. 'teaserHome' => $post['teaserHome'],
  276. 'abstract' => $this->removeLinebreaks($post['abstract']),
  277. 'teaserOverview' => $post['teaserOverview'],
  278. 'title' => $post['title'],
  279. 'roof' => $post['roof'],
  280. 'intro' => ($pageType == 'blogger-page') ? $post['overview'] : $post['intro']
  281. ),
  282. 'sharingActivated' => $post['sharing_activated'] == 1 ? true : false,
  283. 'linkableInHTMLSitemap' => $post['forHTMLSitemap'] == 1 ? true : false,
  284. 'linkableOnHome' => $post['forHome'] == 1 ? true : false,
  285. 'linkableOnCategoryOverview' => $post['forCategoryOverview'] == 1 ? true : false,
  286. 'moveToTopPositionOnCategoryOverview' => $post['forCategoryOverviewTopPosition'] == 1 ? true : false,
  287. 'pageType' => $pageType,
  288. 'pageData' => array(
  289. 'title' => ($post['roof'] != '' ? $post['roof'] . ": " : "") . $post['title'],
  290. 'metas' => array(
  291. "<meta name=\"keywords\" content=\"" . $post["keywords"] . "\">",
  292. "<meta name=\"dcterms.date\" content=\"" . date("Y-m-d", $post['tstamp'] > $post['starttime'] ? $post['tstamp'] : $post['starttime']) . "\">",
  293. "<meta name=\"robots\" content=\"" . ($post['no_index'] == 0 ? "index" : "noindex") . ", " . ($post['no_follow'] == 0 ? "follow" : "nofollow") . "\" />",
  294. "<meta property=\"og:title\" content=\"" . ($post['roof'] != '' ? $post['roof'] . ": " : "") . $post['title'] . "\">",
  295. ($overview_image ? "<meta property=\"og:image\" content=\"https://abi.de/cdn/" . $overview_image["sources"]["og"] . "\" >" : ""),
  296. ),
  297. 'breadcrumbs' => $this->constructBreadCrumb($rootline, $post, $pageType),
  298. 'content' => $initialContent,
  299. 'sidebar' => $this->createContentElement("sidebar", array(), (object) array(), array()),
  300. ),
  301. 'linkedPosts' => array(),
  302. 'injections' => array(),
  303. 'qr2page' => $qrsvg,
  304. 'status' => $this->constructStatus($post)
  305. );
  306. //before content
  307. switch ($pageType) {
  308. case "blog-page":
  309. $processedData["pageData"]["content"]["subElements"][] = $this->createContentElement("injection", array("type" => "blog-author-info"));
  310. $processedData["injections"][] = "blog-author-info";
  311. $processedData["pageData"]["sidebar"]["subElements"][] = $this->createContentElement("injection", array("type" => "blog-page-sidebar"));
  312. $processedData["injections"][] = "blog-page-sidebar";
  313. break;
  314. case "blogger-page":
  315. $processedData["pageData"]["content"]["subElements"][] = $this->createContentElement("injection", array("type" => "blogger-page-author-image"));
  316. $processedData["injections"][] = "blogger-page-author-image";
  317. $text = $post['overview'] ?? $post['abstract'];
  318. $processedData["pageData"]["content"]["subElements"][] = $this->createContentElement("typo3_paragraph", array(), array('text' => '<p>' . $this->exchangeLinkBreaksWithBr($text) . '</p>'), null);
  319. $processedData["pageData"]["content"]["subElements"][] = $this->createContentElement("injection", array("type" => "blogger-page-author-latest-blogs"));
  320. $processedData["injections"][] = "blogger-page-author-latest-blogs";
  321. $processedData["pageData"]["sidebar"]["subElements"][] = $this->createContentElement("injection", array("type" => "blogger-page-sidebar"));
  322. $processedData["injections"][] = "blogger-page-sidebar";
  323. break;
  324. case "video-page":
  325. $processedData["pageData"]["content"]["subElements"][] = $this->createContentElement("injection", array("type" => "video-date-category"));
  326. $processedData["injections"][] = "video-date-category";
  327. $processedData["pageData"]["content"]["subElements"][] = $this->createContentElement("injection", array("type" => "video-info"));
  328. $processedData["injections"][] = "video-info";
  329. break;
  330. }
  331. foreach ($fetchedTTContent as $row) {
  332. $this->processData($row, $processedData, $processedImages);
  333. }
  334. //after content
  335. $processedData['pageData']['metas'][] = $this->constructMetaDescription($post['abstract'], $processedData['pageData']['content']);
  336. $processedData['pageData']['metas'][] = $this->constructMetaDescription($post['abstract'], $processedData['pageData']['content'], true);
  337. if ($pageType == "blog-page") {
  338. $processedData['pageData']['metas'][] = $this->constructMetaDescriptionForBlogPage('', $processedData['pageData']['content']);
  339. $processedData['pageData']['metas'][] = $this->constructMetaDescriptionForBlogPage('', $processedData['pageData']['content'], true);
  340. }
  341. $processedData['pageData']['metas'] = array_filter($processedData['pageData']['metas'], function ($val) {
  342. return $val != "";
  343. });
  344. switch ($pageType) {
  345. case "archive":
  346. $hasSpecificOverviewInjection = false;
  347. foreach ($processedData["injections"] as $inj) {
  348. if (str_contains($inj, "-archive-")) {
  349. $hasSpecificOverviewInjection = true;
  350. break;
  351. }
  352. }
  353. if (!$hasSpecificOverviewInjection) {
  354. $processedData["pageData"]["content"]["subElements"][] = $this->createContentElement("injection", array("type" => "archive-of-direct-childurls"));
  355. $processedData["injections"][] = "archive-of-direct-childurls";
  356. }
  357. break;
  358. case "event-page":
  359. if ($post["event_link"] && $post["event_link"] != "") {
  360. $processedData["pageData"]["content"]["subElements"][] = $this->createContentElement("typo3_paragraph", array(), array('text' => '<p><a href="' . $post["event_link"] . '" target="_blank">Weitere Infos zu dieser Veranstaltung »</a></p>'));
  361. }
  362. break;
  363. }
  364. if (sizeof($processedData['pageData']['sidebar']['subElements']) == 0) {
  365. $processedData['pageData']['sidebar'] = null;
  366. }
  367. if (sizeof($processedData['linkedPosts']) == 0) $processedData['linkedPosts'] = null;
  368. else
  369. $processedData['linkedPosts'] = array_values(array_unique($processedData['linkedPosts']));
  370. if (sizeof($processedData['injections']) == 0) $processedData['injections'] = null;
  371. else
  372. $processedData['injections'] = array_unique($processedData['injections']);
  373. if ($post['hidden'] == 1) {
  374. //TODO: SET STATUS ..
  375. }
  376. $this->deletePagePDFIfExists($processedData['url']);
  377. Mongoer::sendRequest("pages", "save", $processedData);
  378. $this->generatePDFPath($processedData['pageuid'], $processedData['url']);
  379. Mongoer::sendRequest("abialtcache", "delete", array("pageuid" => $pid));
  380. $security_user_pass = $post["security_user_pass"];
  381. if (!$security_user_pass || $security_user_pass == '')
  382. Mongoer::sendRequest("security", "delete", array("pageuid" => $pid));
  383. else {
  384. $tmp = array();
  385. foreach (preg_split('/\n|\r\n?/', $security_user_pass) as $itm) {
  386. $itm = trim($itm);
  387. $itm = explode('|', $itm);
  388. $tmp[$itm[0]] = $itm[1];
  389. }
  390. $security_user_pass = $tmp;
  391. Mongoer::sendRequest("security", "save", array("pageuid" => $pid, "url" => $processedData["url"], "data" => $security_user_pass));
  392. }
  393. //if($post['doktype'] != 1) continue;
  394. if ($post['no_search'] == 0) {
  395. $dkzer = new \Meramo\mrm_be\DKZer();
  396. $searchwords = $dkzer->getSearchWords($post['dkz_code_nrs']);
  397. $freesearchwords = preg_split('/\n|\r|,\n?/', $post['free_searchwords']);
  398. foreach ($freesearchwords as $sw) {
  399. $searchwords[] = $this->convertStringToTechnicalName($sw);
  400. }
  401. $ignoredsearchwords = preg_split('/\n|\r|,\n?/', $post['ignored_searchwords']);
  402. foreach ($ignoredsearchwords as &$sw) {
  403. $sw = $this->convertStringToTechnicalName($sw);
  404. }
  405. $searchwords = array_values(array_diff($searchwords, $ignoredsearchwords));
  406. $searchabletext = $this->constructSearchableText($processedData, true);
  407. $searchabletext_full = $this->constructSearchableText($processedData, false);
  408. $arra = array("pageuid" => $pid, "searchwords" => $searchwords, "text" => $searchabletext, "fulltext" => $searchabletext_full, "lesson" => null);
  409. $lessons = array_values(explode(',', $post['lesson']));
  410. if (sizeof($lessons) == 1 && $lessons[0] == "") $lessons = [];
  411. if (sizeof($lessons) > 0) {
  412. foreach ($lessons as &$l) $l = (int) $l;
  413. $arra['lesson'] = $lessons;
  414. }
  415. Mongoer::sendRequest("search", "save", $arra);
  416. } else Mongoer::sendRequest("search", "delete", array("pageuid" => $pid));
  417. }
  418. }
  419. private function createPDFHash($url)
  420. {
  421. $page = md5($url);
  422. return $page[0] . $page[1] . '/' . $page[2] . $page[3] . '/' . $page . '.pdf';
  423. }
  424. private function deletePagePDFIfExists($url)
  425. {
  426. $partialpath = \TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/pdf-storage/';
  427. $file = $this->createPDFHash($url);
  428. $filepath = $partialpath . $file;
  429. if (file_exists($filepath)) {
  430. unlink($filepath);
  431. return true;
  432. } else {
  433. return false;
  434. }
  435. }
  436. private function generatePDFPath($pageuid, $url)
  437. {
  438. $urlencoded = urlencode($url);
  439. // $this->log($url, true);
  440. $urlpart = "https://abi.de/pdfgen?u=";
  441. $pdfgenurl = $urlpart . $urlencoded;
  442. $data = [
  443. 'pageuid' => $pageuid,
  444. 'url' => $pdfgenurl,
  445. 'pdfhash' => $this->createPDFHash($url)
  446. ];
  447. Mongoer::sendRequest('pdfgenjobs', 'save', $data);
  448. }
  449. private function processFolderContent(&$post)
  450. {
  451. $statement = $this->queryBuilder
  452. ->select('*')
  453. ->from('tt_content')
  454. ->where(
  455. $this->queryBuilder->expr()->eq('pid', $this->queryBuilder->createNamedParameter($post["uid"]))
  456. )
  457. ->execute();
  458. $fetchedTTContent = array();
  459. while ($row = $statement->fetch()) {
  460. $fetchedTTContent[] = $row;
  461. }
  462. if ($post['backend_layout'] == 'pagets__19') {
  463. $themenderwoche = array();
  464. $ffs = GeneralUtility::makeInstance(FlexFormService::class);
  465. foreach ($fetchedTTContent as $row) {
  466. $flex = $ffs->convertFlexFormContentToArray($row['pi_flexform']);
  467. $themenderwoche[] = array(
  468. "key" => $flex['key'],
  469. "starttime" => $this->startOfDay($flex['starttime']),
  470. "endtime" => $this->endOfDay($flex['starttime'], '+6 days'),
  471. "monday" => (int) $this->parseUIDFromT3Url($flex['monday']),
  472. "tuesday" => (int) $this->parseUIDFromT3Url($flex['tuesday']),
  473. "wednesday" => (int) $this->parseUIDFromT3Url($flex['wednesday']),
  474. "thursday" => (int) $this->parseUIDFromT3Url($flex['thursday']),
  475. "friday" => (int) $this->parseUIDFromT3Url($flex['friday']),
  476. "saturday" => (int) $this->parseUIDFromT3Url($flex['saturday']),
  477. "sunday" => (int) $this->parseUIDFromT3Url($flex['sunday']),
  478. );
  479. }
  480. Mongoer::sendRequest("themaderwoche", "save", array("data" => $themenderwoche));
  481. }
  482. if ($post['backend_layout'] == 'pagets__20') {
  483. $menus = array();
  484. $ffs = GeneralUtility::makeInstance(FlexFormService::class);
  485. foreach ($fetchedTTContent as $row) {
  486. $flex = $ffs->convertFlexFormContentToArray($row['pi_flexform']);
  487. $items = array();
  488. foreach ((array) $flex["dynamicComponents"] as $link) {
  489. $linkedPostIds = array();
  490. $itm = $this->parseFlexFormLink($link["links"]["link"], null, $linkedPostIds);
  491. //$this->log($itm, false);
  492. unset($itm["href"]);
  493. $itm["pageuid"] = $linkedPostIds["linkedPosts"][0];
  494. $items[] = $itm;
  495. }
  496. $menus[] = array(
  497. 'headline' => $flex['headline'],
  498. 'menu_id' => $flex['mid'],
  499. 'items' => $items
  500. );
  501. }
  502. Mongoer::sendRequest("menues", "save", array("data" => $menus));
  503. }
  504. if ($post['backend_layout'] == 'pagets__21') {
  505. $topthemen = array();
  506. $ffs = GeneralUtility::makeInstance(FlexFormService::class);
  507. foreach ($fetchedTTContent as $row) {
  508. $flex = $ffs->convertFlexFormContentToArray($row['pi_flexform']);
  509. $topthemen[] = array(
  510. "key" => $flex['key'],
  511. "starttime" => $this->startOfDay($flex['starttime']),
  512. "endtime" => $this->endOfDay($flex['starttime'], '+13 days'),
  513. "section1" => (int) $this->parseUIDFromT3Url($flex['section1']),
  514. "section2" => (int) $this->parseUIDFromT3Url($flex['section2']),
  515. "section3" => (int) $this->parseUIDFromT3Url($flex['section3']),
  516. "section4" => (int) $this->parseUIDFromT3Url($flex['section4']),
  517. "section5" => (int) $this->parseUIDFromT3Url($flex['section5']),
  518. );
  519. }
  520. Mongoer::sendRequest("topthemen", "save", array("data" => $topthemen));
  521. }
  522. if ($post['backend_layout'] == 'pagets__23') {
  523. $maintenance = array();
  524. $ffs = GeneralUtility::makeInstance(FlexFormService::class);
  525. foreach ($fetchedTTContent as $row) {
  526. $flex = $ffs->convertFlexFormContentToArray($row['pi_flexform']);
  527. $maintenance[] = array(
  528. "starttime" => $flex['starttime'],
  529. "endtime" => $flex['endtime'],
  530. "infotext" => $flex['infotext']
  531. );
  532. }
  533. Mongoer::sendRequest("maintenance", "save", array("data" => $maintenance));
  534. }
  535. if ($post['backend_layout'] == 'pagets__27' || $post['backend_layout' == 'pagets__28']) {
  536. $chatbot = array();
  537. $ffs = GeneralUtility::makeInstance(FlexFormService::class);
  538. foreach ($fetchedTTContent as $row) {
  539. $isDirect = $row['CType'] == 'mrm_be_cm_chatbot-direct';
  540. $flex = $ffs->convertFlexFormContentToArray($row['pi_flexform']);
  541. $item = array();
  542. $item['terms'] = explode("\n", str_replace(',', '', $flex['settings']['terms']));
  543. $item['type'] = $isDirect ? 'direct' : $flex['settings']['type'];
  544. if ($isDirect) {
  545. $item['url'] = $this->replaceT3Link($flex['settings']['url'], null, $row, false);
  546. }
  547. if ($flex['settings']['type'] == 'reverse') {
  548. $item["category"] = (($flex['settings']['category'] == "Auswählen") ? '' : $flex['settings']['category']);
  549. }
  550. $chatbot[] = $item;
  551. }
  552. Mongoer::sendRequest("chatbot", "save", array("data" => $chatbot));
  553. }
  554. }
  555. private function removeLinebreaks($str)
  556. {
  557. return trim(preg_replace('/\s+/', ' ', $str));
  558. }
  559. private function exchangeLinkBreaksWithBr($str)
  560. {
  561. return trim(preg_replace('/\r\n/', '<br />', $str));
  562. }
  563. private function startOfDay($ts, $modify = null, $isAtomDate = false, $returnAtomDate = false)
  564. {
  565. $dt = null;
  566. if ($isAtomDate) {
  567. if (is_numeric($ts)) {
  568. $ts = $ts + 0;
  569. $dt = new \DateTime();
  570. $dt->setTimezone(new \DateTimeZone('UTC'));
  571. $dt->setTimestamp($ts);
  572. } else {
  573. $dt = new \DateTime($ts);
  574. $dt->setTimezone(new \DateTimeZone('UTC'));
  575. }
  576. } else {
  577. $dt = new \DateTime(null, new \DateTimeZone('Europe/Berlin'));
  578. $dt->setTimestamp($ts);
  579. }
  580. if ($modify) $dt->modify($modify);
  581. $bodStr = $dt->format('Y-m-d 00:00:00');
  582. $bodObj = \DateTime::createFromFormat('Y-m-d H:i:s', $bodStr, $returnAtomDate ? new \DateTimeZone('UTC') : new \DateTimeZone('Europe/Berlin'));
  583. if ($returnAtomDate) return $bodObj->format(\DateTimeInterface::ATOM);
  584. return (int) $bodObj->getTimestamp();
  585. }
  586. private function endOfDay($ts, $modify = null, $isAtomDate = false, $returnAtomDate = false)
  587. {
  588. $dt = null;
  589. if ($isAtomDate) {
  590. if (is_numeric($ts)) {
  591. $ts = $ts + 0;
  592. $dt = new \DateTime();
  593. $dt->setTimezone(new \DateTimeZone('UTC'));
  594. $dt->setTimestamp($ts);
  595. } else {
  596. $dt = new \DateTime($ts);
  597. $dt->setTimezone(new \DateTimeZone('UTC'));
  598. }
  599. } else {
  600. $dt = new \DateTime(null, new \DateTimeZone('Europe/Berlin'));
  601. $dt->setTimestamp($ts);
  602. }
  603. if ($modify) $dt->modify($modify);
  604. $eodStr = $dt->format('Y-m-d 23:59:59');
  605. $eodObj = \DateTime::createFromFormat('Y-m-d H:i:s', $eodStr, $returnAtomDate ? new \DateTimeZone('UTC') : new \DateTimeZone('Europe/Berlin'));
  606. if ($returnAtomDate) return $eodObj->format(\DateTimeInterface::ATOM);
  607. return (int) $eodObj->getTimestamp();
  608. }
  609. function array_search_by_key_recursive($needle, array $haystack, &$return)
  610. {
  611. foreach ($haystack as $k => $v) {
  612. if (is_array($v)) {
  613. $this->array_search_by_key_recursive($needle, $v, $return);
  614. } else {
  615. if ($k === $needle) {
  616. $return[] = $v;
  617. }
  618. }
  619. }
  620. }
  621. private function findFirstAppearingElementByType($type, $subs, $typeKey = "type")
  622. {
  623. foreach ($subs as $v) {
  624. if ($v[$typeKey] == $type) return $v;
  625. }
  626. return null;
  627. }
  628. private function checkOrReduceDescriptionLength($desc, $len)
  629. {
  630. $newStr = '';
  631. $desc = $this->removeLinebreaks($desc);
  632. if (is_string($desc) && mb_strlen($desc) < $len) {
  633. $newStr = $desc;
  634. } else {
  635. $newStr = substr($desc, 0, $len);
  636. $pos = strrpos($newStr, ' ');
  637. $newStr = substr($desc, 0, $pos);
  638. }
  639. return $newStr;
  640. }
  641. private function constructMetaDescription($abstract = '', $content, $isOgTag = false)
  642. {
  643. $desc = '';
  644. if ($abstract != '') $desc = $abstract;
  645. if (!$desc || $desc == '') {
  646. $desc = $this->findFirstAppearingElementByType("introtext", $content["subElements"]);
  647. if ($desc)
  648. $desc = $desc["attributes"]["text"];
  649. }
  650. if (!$desc || $desc == '')
  651. return '';
  652. if ($isOgTag)
  653. return "<meta property=\"og:description\" content=\"" . $this->checkOrReduceDescriptionLength($desc, 320) . "\">";
  654. return "<meta name=\"description\" content=\"" . $this->checkOrReduceDescriptionLength($desc, 320) . "\">";
  655. }
  656. private function constructMetaDescriptionForBlogPage($text = '', $content, $isOgTag = false)
  657. {
  658. $desc = '';
  659. if ($text != '') $desc = $text;
  660. if (!$desc || $desc == '') {
  661. $desc = $this->findFirstAppearingElementByType('typo3_paragraph', $content["subElements"]);
  662. if ($desc)
  663. $desc = strip_tags($desc["attributes"]["text"]);
  664. }
  665. if (!$desc || $desc == '')
  666. return '';
  667. if ($isOgTag)
  668. return "<meta property=\"og:description\" content=\"" . $this->checkOrReduceDescriptionLength($desc, 165) . ' …' . "\">";
  669. return "<meta name=\"description\" content=\"" . $this->checkOrReduceDescriptionLength($desc, 165) . ' …' . "\">";
  670. }
  671. private function constructSearchableText($content, $minimum = true)
  672. {
  673. $cr = [];
  674. if (!$minimum) {
  675. $this->array_search_by_key_recursive("text", $content["pageData"]["content"], $cr);
  676. } else {
  677. //$roof = $this->findFirstAppearingElementByType("roof", $content["pageData"]["content"]["subElements"]);
  678. //if($roof) $cr[] = $roof["attributes"]["text"];
  679. $h1 = $this->findFirstAppearingElementByType("h1", $content["pageData"]["content"]["subElements"]);
  680. if ($h1) {
  681. $cr[] = $h1["attributes"]["roof"];
  682. $cr[] = $h1["attributes"]["text"];
  683. }
  684. $introtext = $this->findFirstAppearingElementByType("introtext", $content["pageData"]["content"]["subElements"]);
  685. if ($introtext) $cr[] = $introtext["attributes"]["text"];
  686. }
  687. $cr = preg_replace("/\r|\n/", " ", strip_tags(implode(" ", $cr)));
  688. return $cr;
  689. }
  690. private function constructStatus($post)
  691. {
  692. $publicationType = null;
  693. switch ($post["red_status"]) {
  694. case "-1": //neu angelegt
  695. case "1": //in Bearbeitung
  696. case "2": //vorbereitet
  697. case "3": //geprüft
  698. case "21": //gesperrt
  699. case "22": //archiviert
  700. $publicationType = "preview";
  701. break;
  702. case "11": //frei
  703. case "12": //online
  704. $publicationType = "live";
  705. break;
  706. default:
  707. break;
  708. }
  709. $status = array(
  710. 'isLiveFrom' => -1,
  711. 'isLiveTill' => -1,
  712. 'publicationType' => $publicationType,
  713. 'orderStatus' => $post['orderStatus'],
  714. 'date-updated' => ($post['orderStatus'] === 'neu') ? $post['starttime'] : (($post['orderStatus'] === 'aktualisiert') ? $post['red_end'] : ''),
  715. 'seo' => array(
  716. 'sitemap_changefreq' => $post['sitemap_changefreq'],
  717. 'sitemap_priority' => $post['sitemap_priority'],
  718. 'sitemap_lastmod' => time(),
  719. ),
  720. );
  721. if ($post['starttime'] != 0) {
  722. $status['isLiveFrom'] = $this->startOfDay($post['starttime']);
  723. }
  724. if ($post['endtime'] != 0) {
  725. $status['isLiveTill'] = $this->endOfDay($post['endtime']);
  726. }
  727. if ($post['doktype'] == '101') {
  728. $status['blog_author'] = $post['blog_author'];
  729. $status['blog_category'] = $post['blog_category'];
  730. }
  731. if ($post['doktype'] == '100') {
  732. $status['event_state'] = $post['event_state'];
  733. $status['event_category'] = $post['event_category'];
  734. }
  735. if ($post['doktype'] == '104') {
  736. $status['video_category'] = $post['event_category'];
  737. }
  738. //$this->log($status, false);
  739. return $status;
  740. }
  741. private function constructRedirects($pageData)
  742. {
  743. $redirects = array(
  744. '/?id=' . $pageData['uid']
  745. );
  746. //TODO: Add a single \r to match old Macs line breaks?
  747. foreach (preg_split('/\n|\r\n?/', $pageData['redirects']) as $redir) {
  748. $redir = trim($redir);
  749. if ($redir == '') continue;
  750. $redirects[] = $redir;
  751. }
  752. return $redirects;
  753. }
  754. private function convertStringToTechnicalName($string)
  755. {
  756. $string = $this->sanitizeString($string);
  757. $string = preg_replace('/-/', '', $string);
  758. return strtoupper($string);
  759. }
  760. private function sanitizeString($string)
  761. {
  762. $table = array(
  763. 'Š' => 'S', 'š' => 's', 'Đ' => 'Dj', 'đ' => 'dj', 'Ž' => 'Z', 'ž' => 'z', 'Č' => 'C', 'č' => 'c', 'Ć' => 'C', 'ć' => 'c',
  764. 'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'AE', 'Å' => 'A', 'Æ' => 'A', 'Ç' => 'C', 'È' => 'E', 'É' => 'E',
  765. 'Ê' => 'E', 'Ë' => 'E', 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ï' => 'I', 'Ñ' => 'N', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O',
  766. 'Õ' => 'O', 'Ö' => 'OE', 'Ø' => 'O', 'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'UE', 'Ý' => 'Y', 'Þ' => 'B', 'ß' => 'Ss',
  767. 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'ae', 'å' => 'a', 'æ' => 'a', 'ç' => 'c', 'è' => 'e', 'é' => 'e',
  768. 'ê' => 'e', 'ë' => 'e', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'ð' => 'o', 'ñ' => 'n', 'ò' => 'o', 'ó' => 'o',
  769. 'ô' => 'o', 'õ' => 'o', 'ö' => 'oe', 'ø' => 'o', 'ü' => 'ue', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ý' => 'y', 'ý' => 'y',
  770. 'þ' => 'b', 'ÿ' => 'y', 'Ŕ' => 'R', 'ŕ' => 'r', '/' => ''
  771. );
  772. $x = preg_replace(array('/\s{2,}/', '/[\t\n]/'), ' ', $string);
  773. $x = trim(strtr($x, $table));
  774. $x = preg_replace('/[^A-Za-z0-9]+/', ' ', $x);
  775. $x = trim($x);
  776. $x = preg_replace('/ {1,}/', '-', $x);
  777. $x = trim($x, "-");
  778. return $x;
  779. }
  780. private function constructSlug($pid)
  781. {
  782. $postStatement = $this->pageQueryBuilder
  783. ->select('slug')
  784. ->from('pages')
  785. ->setMaxResults(1)
  786. ->where(
  787. $this->pageQueryBuilder->expr()->eq('uid', $this->pageQueryBuilder->createNamedParameter($pid))
  788. )
  789. ->execute();
  790. $postSlug = $postStatement->fetchAll();
  791. $postSlug = $postSlug[0];
  792. return $postSlug ? $postSlug["slug"] : null;
  793. }
  794. private function constructBreadCrumb($rootline, $page, $pageType)
  795. {
  796. $breadCrumb = $this->createContentElement('breadcrumbs');
  797. foreach ($rootline as $post) {
  798. if ($post['doktype'] == 254) continue;
  799. if ($post['is_siteroot'] == 1) continue;
  800. if ($page['uid'] == $post['uid'] && ($pageType == "blogger-page" || $pageType == "video-page"))
  801. $tit = $post['title'];
  802. else
  803. if ($post['use_roof_as_breadcrumb_text'] == 0)
  804. $tit = $post['title'];
  805. else
  806. $tit = $post['roof'] && $post['roof'] != '' ? $post['roof'] : $post['title'];
  807. $breadCrumb['subElements'][] = $this->createContentElement(
  808. 'breadcrumblink',
  809. array(
  810. 'title' => $tit,
  811. 'alt' => $tit,
  812. 'text' => $tit,
  813. 'href' => $this->constructSlug($post['uid'])
  814. )
  815. );
  816. }
  817. return $breadCrumb;
  818. }
  819. private function processData($dbReference, &$processedData, &$processedImages)
  820. {
  821. $isSidebar = $dbReference['colPos'] == 1;
  822. if ($isSidebar)
  823. $subs = &$processedData['pageData']['sidebar']['subElements'];
  824. else
  825. $subs = &$processedData['pageData']['content']['subElements'];
  826. $ffs = GeneralUtility::makeInstance(FlexFormService::class);
  827. $flex = $ffs->convertFlexFormContentToArray($dbReference['pi_flexform']);
  828. // print_r($flex);
  829. // die();
  830. switch ($dbReference['CType']) {
  831. case "mrm_be_cm_postimage":
  832. break;
  833. case "mrm_be_cm_voting":
  834. $s = $this->createContentElement(
  835. "voting",
  836. array(
  837. "labels" => array(
  838. "startbutton" => $flex["startbuttontext"],
  839. ),
  840. "resultscreen" => array(
  841. "headingTop" => $flex["resultheadingtop"],
  842. ),
  843. ),
  844. array(
  845. "items" => array(array(
  846. "text" => $flex["questiontext"],
  847. "type" => $flex["questiontype"] == "1" || $flex["questiontype"] == 1 ? "multi" : "single",
  848. "answers" => array_values(array_map(function ($x) {
  849. return array("text" => $x["settings"]["answer"]["text"], "value" => null);
  850. }, $flex["dynamicComponents"]))
  851. )),
  852. "validation" => array(
  853. "alreadyVoted" => $this->createContentElement("injection", array("type" => "voting-alreadyVoted")),
  854. "chartData" => $this->createContentElement("injection", array("type" => "voting-chartData|")),
  855. ),
  856. )
  857. );
  858. $cntr = 0;
  859. foreach ($s["attributes"]["items"][0]["answers"] as &$a) {
  860. $a["value"] = $cntr;
  861. $cntr++;
  862. }
  863. $s["attributes"]["validation"]["chartData"]["props"]["type"] .= $cntr;
  864. $processedData["injections"][] = "voting-alreadyVoted";
  865. $processedData["injections"][] = "voting-chartData|" . $cntr;
  866. $subs[] = $s;
  867. $processedData["status"]["hasVoting"] = true;
  868. break;
  869. case "mrm_be_cm_checklist-todo":
  870. $elements = $this->createContentElement(
  871. "checklist-todo",
  872. array(
  873. "headlines" => array(
  874. "main" => $flex["headline_main"],
  875. "done" => $flex["headline_done"],
  876. "not_done" => $flex["headline_not_done"],
  877. ),
  878. "controls" => array(
  879. "print" => $flex["enable_print"] == "1",
  880. "pdf" => $flex["enable_pdf"] == "1",
  881. ),
  882. "labels" => array(
  883. "submit" => $flex["label_submit"],
  884. "print" => $flex["label_print"],
  885. "pdf" => $flex["label_pdf"],
  886. ),
  887. "items" => (function ($flex, $dbReference) {
  888. $itms = array();
  889. $imgs = array();
  890. if ($flex["images"] != "0" && $flex["images"] != 0) {
  891. $imgs = $this->processImagesTTContent($dbReference, 'mrm_be_cm_contentimage', 'tt_content', 'image', 'uid', true, true);
  892. }
  893. foreach ($flex["items"] as $itm) {
  894. $i = $itm["item"];
  895. $a = array();
  896. if ($i["text"] != "") $a["text"] = $i["text"];
  897. if ($i["contains_image"] == "1" || $i["contains_image"] == 1) {
  898. $im = array_shift($imgs);
  899. if (isset($im)) $a["img"] = $im;
  900. }
  901. $itms[] = $a;
  902. }
  903. return $itms;
  904. })($flex, $dbReference),
  905. )
  906. );
  907. $subs[] = $elements;
  908. $processedData["status"]["hasChecklist"] = true;
  909. break;
  910. case "mrm_be_cm_checklist_todo_multi":
  911. $elements = $this->createContentElement(
  912. 'checklist-todo-multi',
  913. array(
  914. "texts" => array(
  915. "mainhead" => $flex['mainhead'],
  916. "description" => $flex['description'],
  917. ),
  918. "controls" => array(
  919. "print" => $flex["enable_print"] == "1",
  920. "pdf" => $flex["enable_pdf"] == "1",
  921. ),
  922. "labels" => array(
  923. "print" => $flex["label_print"],
  924. "pdf" => $flex["label_pdf"],
  925. ),
  926. "items" => (function ($flex) {
  927. $itms = [];
  928. $a = array();
  929. foreach ($flex['items'] as $itm) {
  930. if (is_array($itm)) {
  931. $a['head'] = $itm['item']['head'];
  932. $list = $itm['item']['list'];
  933. $doc = new \DOMDocument('1.0', 'utf-8');
  934. $doc->loadHTML('<?xml encoding="UTF-8">' . $list);
  935. $listitems = $doc->getElementsByTagName('li');
  936. $list = [];
  937. foreach ($listitems as $node) {
  938. foreach ($node->childNodes as $child) {
  939. $list[] = array('text' => $child->nodeValue);
  940. }
  941. $a['items'] = $list;
  942. }
  943. }
  944. $itms[] = $a;
  945. }
  946. return $itms;
  947. })($flex),
  948. ),
  949. );
  950. $subs[] = $elements;
  951. break;
  952. case "mrm_be_cm_checklist-input":
  953. $items = array();
  954. $dynContentCounter = 0;
  955. while (true) {
  956. $dynContentCounter++;
  957. if (!isset($flex["label" . $dynContentCounter])) break;
  958. if ($flex["label" . $dynContentCounter] === "") continue;
  959. $label = array(
  960. "label" => $flex["label" . $dynContentCounter]
  961. );
  962. $items[] = $label;
  963. }
  964. $elements = $this->createContentElement(
  965. "checklist-input",
  966. array(
  967. "headlines" => array(
  968. "main" => $flex["headline_main"],
  969. "results" => $flex["headline_result"],
  970. ),
  971. "intro" => $flex["intro"],
  972. "controls" => array(
  973. "print" => $flex["enable_print"] == "1",
  974. "pdf" => $flex["enable_pdf"] == "1",
  975. ),
  976. "labels" => array(
  977. "submit" => $flex["label_submit"],
  978. "print" => $flex["label_print"],
  979. "pdf" => $flex["label_pdf"],
  980. ),
  981. "items" => $items,
  982. )
  983. );
  984. $subs[] = $elements;
  985. $processedData["status"]["hasChecklist"] = true;
  986. break;
  987. case "mrm_be_cm_checklist-scale":
  988. $items = array();
  989. $dynContentCounter = 0;
  990. while (true) {
  991. $dynContentCounter++;
  992. if (!isset($flex["label" . $dynContentCounter])) break;
  993. if ($flex["label" . $dynContentCounter] === "") continue;
  994. $label = array(
  995. "label" => $flex["label" . $dynContentCounter]
  996. );
  997. $items[] = $label;
  998. }
  999. $elements = $this->createContentElement(
  1000. "checklist-scale",
  1001. array(
  1002. "headlines" => array(
  1003. "main" => $flex["headline_main"],
  1004. "results" => $flex["headline_result"],
  1005. ),
  1006. "intro" => $flex["intro"],
  1007. "maxPoints" => (int)$flex["maxpoints"],
  1008. "controls" => array(
  1009. "print" => $flex["enable_print"] == "1",
  1010. "pdf" => $flex["enable_pdf"] == "1",
  1011. ),
  1012. "labels" => array(
  1013. "nextbutton" => $flex["label_nextbutton"],
  1014. "lastbutton" => $flex["label_lastbutton"],
  1015. "print" => $flex["label_print"],
  1016. "pdf" => $flex["label_pdf"],
  1017. ),
  1018. "items" => $items,
  1019. )
  1020. );
  1021. $subs[] = $elements;
  1022. $processedData["status"]["hasChecklist"] = true;
  1023. break;
  1024. case "mrm_be_cm_checklist-radiorange":
  1025. $items = array();
  1026. $dynContentCounter = 0;
  1027. while (true) {
  1028. $dynContentCounter++;
  1029. if (!isset($flex["pointsFrom" . $dynContentCounter])) break;
  1030. if ($flex["pointsFrom" . $dynContentCounter] === "") continue;
  1031. $item = array(
  1032. "pointsFrom" => (int)$flex["pointsFrom" . $dynContentCounter],
  1033. "pointsTo" => (int)$flex["pointsTo" . $dynContentCounter],
  1034. "validationText" => $flex["validationText" . $dynContentCounter]
  1035. );
  1036. if ($flex["image" . $dynContentCounter] == 1) {
  1037. $images = $this->processImagesTTContent($dbReference, 'mrm_be_cm_checklist-radiorange', 'tt_content', 'flex_image_' . $dynContentCounter, 'uid', false, true);
  1038. $images = $images[0];
  1039. $images["src"] = $images["sources"]["img"];
  1040. unset($images["sources"]);
  1041. $item["img"] = $images;
  1042. }
  1043. $items[] = $item;
  1044. }
  1045. $elements = $this->createContentElement(
  1046. "checklist-radiorange",
  1047. array(
  1048. "headlines" => array(
  1049. "main" => $flex["headline_main"],
  1050. ),
  1051. "intro" => $flex["intro"],
  1052. "validation" => array(
  1053. "maxPoints" => (int)$flex["maxpoints"],
  1054. "items" => $items,
  1055. )
  1056. )
  1057. );
  1058. $subs[] = $elements;
  1059. $processedData["status"]["hasChecklist"] = true;
  1060. break;
  1061. case "mrm_be_cm_checklist-yesmaybeno":
  1062. $items = array();
  1063. foreach ($flex["dynamicComponents"] as $component) {
  1064. foreach ($component as $key => $value) {
  1065. $item = array(
  1066. "heading" => $value["headline"],
  1067. "text" => $value["text"]
  1068. );
  1069. }
  1070. if ($item) {
  1071. $items[] = $item;
  1072. }
  1073. unset($value);
  1074. }
  1075. $choices = array();
  1076. $choice_yes = array(
  1077. "label" => $flex["choice_value_yes"],
  1078. "value" => "yes"
  1079. );
  1080. $choice_maybe = array(
  1081. "label" => $flex["choice_value_maybe"],
  1082. "value" => "maybe"
  1083. );
  1084. $choice_no = array(
  1085. "label" => $flex["choice_value_no"],
  1086. "value" => "no"
  1087. );
  1088. $choices[] = $choice_yes;
  1089. $choices[] = $choice_maybe;
  1090. $choices[] = $choice_no;
  1091. $elements = $this->createContentElement(
  1092. "checklist-yesmaybeno",
  1093. array(
  1094. "headlines" => array(
  1095. "main" => $flex["headline_main"],
  1096. "results" => $flex["headline_result"],
  1097. ),
  1098. "intro" => $flex["intro"],
  1099. "controls" => array(
  1100. "print" => $flex["enable_print"] == "1",
  1101. "pdf" => $flex["enable_pdf"] == "1",
  1102. ),
  1103. "labels" => array(
  1104. "nextbutton" => $flex["label_nextbutton"],
  1105. "lastbutton" => $flex["label_lastbutton"],
  1106. "print" => $flex["label_print"],
  1107. "pdf" => $flex["label_pdf"],
  1108. ),
  1109. "choices" => $choices,
  1110. "items" => $items,
  1111. )
  1112. );
  1113. $subs[] = $elements;
  1114. $processedData["status"]["hasChecklist"] = true;
  1115. break;
  1116. case "mrm_be_cm_picturechoice":
  1117. $s = $this->createContentElement(
  1118. "picturechoice",
  1119. array(
  1120. "labels" => array(
  1121. "startbutton" => $flex["startbuttontext"],
  1122. "nextbutton" => $flex["nextbuttontext"],
  1123. "lastbutton" => $flex["lastbuttontext"],
  1124. "question" => $flex["question"],
  1125. "repeatbutton" => $flex["repeatbuttontext"],
  1126. ),
  1127. "resultscreen" => array(
  1128. "headingTop" => $flex["resultheadingtop"],
  1129. "end" => $flex["thanks"]
  1130. ),
  1131. "isRestartAble" => $flex["isRestartAble"] == 1 || $flex["isRestartAble"] == "1",
  1132. ),
  1133. array(
  1134. "items" => (function ($flex, $dbReference) {
  1135. $ret = array();
  1136. for ($i = 1; $i <= 3; $i++) {
  1137. $item = array();
  1138. for ($j = 1; $j <= 5; $j++) {
  1139. if ($flex["image" . $i . "_" . $j] == "1") {
  1140. $img = $this->processImagesTTContent($dbReference, 'mrm_be_cm_picturechoice', 'tt_content', 'flex_image_' . $i . "_" . $j, 'uid', false, true);
  1141. $img = $img[0];
  1142. $item[] = array(
  1143. "image" => $img,
  1144. "points" => (int) $flex["pointsOfImage" . $i . "_" . $j]
  1145. );
  1146. }
  1147. }
  1148. if (sizeof($item) > 0)
  1149. $ret[] = $item;
  1150. }
  1151. return $ret;
  1152. })($flex, $dbReference),
  1153. "validation" => array(
  1154. "maxPoints" => (int)$flex["maxpoints"],
  1155. "alreadyReachedPoints" => $this->createContentElement("injection", array("type" => "picturechoice-alreadyReachedPoints")),
  1156. "items" => array_map(
  1157. function ($i) {
  1158. $i["validationText"] = $this->checkTextForInternalLinks($i["validationText"], $dbReference, $processedData);
  1159. $i["pointsFrom"] = (int)$i["pointsFrom"];
  1160. $i["pointsTo"] = (int)$i["pointsTo"];
  1161. return $i;
  1162. },
  1163. array_filter(array_values(array_map(function ($v) {
  1164. return $v['settings']['validation'];
  1165. }, $flex["validations"])), function ($x) {
  1166. return $x != null;
  1167. })
  1168. //TODO: Core: Error handler (BE): PHP Warning: array_filter() expects parameter 1 (or 2 in another error message) to be array, null given in /var/www/html/typo3conf/ext/mrm_be/Classes/Hooks/TCE/TCEMainHook.php line 830
  1169. ),
  1170. ),
  1171. )
  1172. );
  1173. $processedData["injections"][] = "picturechoice-alreadyReachedPoints";
  1174. $subs[] = $s;
  1175. $processedData["status"]["hasPicturechoice"] = true;
  1176. break;
  1177. case "mrm_be_cm_quiz":
  1178. $s = $this->createContentElement(
  1179. "quiz",
  1180. array(
  1181. "labels" => array(
  1182. "startbutton" => $flex["startbuttontext"],
  1183. "nextbutton" => $flex["nextbuttontext"],
  1184. "lastbutton" => $flex["lastbuttontext"],
  1185. "question" => $flex["question"],
  1186. "repeatbutton" => $flex["repeatbuttontext"],
  1187. ),
  1188. "resultscreen" => array(
  1189. "headingTop" => $flex["resultheadingtop"],
  1190. "headingSub" => $flex["resultheadingsub"],
  1191. "validation" => $flex["validationstr"],
  1192. "end" => $flex["thanks"]
  1193. ),
  1194. "isRestartAble" => $flex["isRestartAble"] == 1 || $flex["isRestartAble"] == "1",
  1195. ),
  1196. array(
  1197. "items" => array_values(array_map(function ($v) {
  1198. $questionType = null;
  1199. $quest = $v['settings']['question'];
  1200. if (!isset($quest)) {
  1201. $quest = $v['settings']['question_multi'];
  1202. $questionType = "multi";
  1203. }
  1204. if (isset($quest["additional_text"]) && $quest["additional_text"] != "") {
  1205. $quest["text"] = $quest["text"] . " (" . $quest["additional_text"] . ")";
  1206. unset($quest["additional_text"]);
  1207. }
  1208. if ($questionType) $quest["type"] = $questionType;
  1209. unset($quest["rightanswer"]);
  1210. $i = 0;
  1211. $quest["answers"] = array();
  1212. while (1) {
  1213. $i++;
  1214. if (!isset($quest["answertext" . $i])) break;
  1215. if ($quest["answertext" . $i] === "") continue;
  1216. $quest["answers"][] = array("text" => $quest["answertext" . $i], "points" => (int)$quest["answerpoints" . $i]);
  1217. unset($quest["answertext" . $i]);
  1218. unset($quest["answerpoints" . $i]);
  1219. }
  1220. /* NOTE: DEPRECATED BY SINGLE INPUTS
  1221. $quest["answers"] = array_map(function($x) {
  1222. $x = explode("|", $x);
  1223. $x = array("text" => $x[0], "points" => (int)$x[1]);
  1224. return $x;
  1225. }, explode("\n", $quest["answers"]));
  1226. */
  1227. return $quest;
  1228. }, $flex["dynamicComponents"])),
  1229. "validation" => array(
  1230. "maxPoints" => (int)$flex["maxpoints"],
  1231. "averagePoints" => $this->createContentElement("injection", array("type" => "quiz-averagePoints")),
  1232. "alreadyReachedPoints" => $this->createContentElement("injection", array("type" => "quiz-alreadyReachedPoints")),
  1233. "items" => array_map(
  1234. function ($i) {
  1235. $i["validationText"] = $this->checkTextForInternalLinks($i["validationText"], $dbReference, $processedData);
  1236. return $i;
  1237. },
  1238. array_filter(array_values(array_map(function ($v) {
  1239. return $v['settings']['validation'];
  1240. }, $flex["dynamicComponents2"])), function ($x) {
  1241. return $x != null;
  1242. })
  1243. ),
  1244. ),
  1245. )
  1246. );
  1247. $processedData["injections"][] = "quiz-averagePoints";
  1248. $processedData["injections"][] = "quiz-alreadyReachedPoints";
  1249. $subs[] = $s;
  1250. $processedData["status"]["hasQuiz"] = true;
  1251. break;
  1252. case "mrm_be_cm_animation":
  1253. $script = $flex["script"];
  1254. if ($flex["staticfiles"] != "0" && $flex["staticfiles"] != 0) {
  1255. $imgs = $this->processImagesTTContent($dbReference);
  1256. foreach ($imgs as $idx => $v) {
  1257. $script = implode("#cdnurl#/" . $v["sources"]["passthru"], explode("%ASSET_" . ($idx + 1) . "%", $script));
  1258. }
  1259. }
  1260. $subs[] = $this->createContentElement("animation", array("addJQuery" => $flex["addJQuery"] == 1 || $flex["addJQuery"] == "1"), array("script" => $script));
  1261. $processedData["status"]["hasAnimation"] = true;
  1262. break;
  1263. case "mrm_be_cm_injection":
  1264. $subs[] = $this->createContentElement("injection", array("type" => $flex["text"]));
  1265. $processedData["injections"][] = $flex["text"];
  1266. break;
  1267. case "mrm_be_cm_roof":
  1268. $subs[] = $this->createContentElement("roof", array(), array("text" => $flex["text"]));
  1269. break;
  1270. case "mrm_be_cm_h1":
  1271. $subs[] = $this->createContentElement("h1", array(), array("text" => $flex["text"]));
  1272. break;
  1273. case "mrm_be_cm_h2":
  1274. $subs[] = $this->createContentElement("h2", array(), array("text" => $flex["text"]));
  1275. break;
  1276. case "mrm_be_cm_h3":
  1277. $subs[] = $this->createContentElement("h3", array(), array("text" => $flex["text"]));
  1278. break;
  1279. case "mrm_be_cm_introtext":
  1280. $text = preg_replace("/\n/", "<br />", $flex["text"]);
  1281. $subs[] = $this->createContentElement("introtext", array(), array("text" => $text));
  1282. break;
  1283. case "mrm_be_cm_button":
  1284. $href = $this->parseFlexFormLink($flex["button"], $dbReference, $processedData);
  1285. $buttonType = ($flex['buttonType'] == "0") ? 'button-link' : 'button-scream';
  1286. $button = $this->createContentElement("button", array('buttonType' => $buttonType), array("text" => $flex["text"], "href" => $href["href"], "target" => $href["target"]));
  1287. $subs[] = $button;
  1288. break;
  1289. case "mrm_be_cm_html":
  1290. $subs[] = $this->createContentElement("html", array(), array("text" => $flex["html"]));
  1291. break;
  1292. case "mrm_be_cm_heroimage":
  1293. $props = $this->processImagesTTContent($dbReference)[0];
  1294. $props["type"] = "typo3_hero";
  1295. $subs[] = $this->createContentElement("image", $props);
  1296. break;
  1297. case "mrm_be_cm_contentimage":
  1298. $props = $this->processImagesTTContent($dbReference)[0];
  1299. $props["type"] = "typo3_content";
  1300. $subs[] = $this->createContentElement("image", $props);
  1301. break;
  1302. case "mrm_be_cm_publication":
  1303. $imgprops = $this->processImagesTTContent($dbReference, 'mrm_be_cm_publication')[0];
  1304. $imgprops["type"] = "typo3_publication";
  1305. $publication = $this->createContentElement(
  1306. "publication",
  1307. array(
  1308. "starttime" => $this->startOfDay($flex['starttime']),
  1309. "endtime" => $this->endOfDay($flex['endtime']),
  1310. "issuekey" => $flex['issuekey'],
  1311. ),
  1312. array(
  1313. "image" => $imgprops,
  1314. "number" => $flex["issuenumber"],
  1315. "title" => $flex["issuetitle"],
  1316. "headline" => $flex["issueheadline"],
  1317. "link" => $this->parseFlexFormLink($flex["htmllink"], $dbReference, $processedData),
  1318. "pdf" => $this->parseFlexFormLink($flex["pdflink"], $dbReference, $processedData),
  1319. )
  1320. );
  1321. $subs[] = $publication;
  1322. break;
  1323. case "mrm_be_cm_rawimage":
  1324. $props = $this->processImagesTTContent($dbReference)[0];
  1325. $props["type"] = "typo3_raw";
  1326. $subs[] = $this->createContentElement("image", $props);
  1327. break;
  1328. case "mrm_be_cm_movingimagesvideo":
  1329. $subs[] = $this->createContentElement(
  1330. "movingimagesvideo",
  1331. array(
  1332. "hasNoticeForCrossPromotion" => $flex["hasNoticeForCrossPromotion"] == 1,
  1333. "hasNoticeForAccessibility" => $flex["hasNoticeForAccessibility"] == 1
  1334. ),
  1335. array("vid" => $flex["vid"])
  1336. );
  1337. break;
  1338. case "mrm_be_cm_paragraph":
  1339. $elements = $this->checkText($flex["text"], $dbReference, $processedData, "typo3_paragraph");
  1340. $subs = array_merge($subs, $elements);
  1341. break;
  1342. case "mrm_be_cm_additionalinfobox":
  1343. case "mrm_be_cm_infobox":
  1344. case "mrm_be_cm_extra_infosbox":
  1345. $type = null;
  1346. $open = null;
  1347. $noAutoOpen = null;
  1348. if ($dbReference['CType'] == "mrm_be_cm_additionalinfobox") $type = "typo3_additionalinfobox";
  1349. elseif ($dbReference['CType'] == "mrm_be_cm_infobox") $type = "typo3_infobox";
  1350. else $type = "typo3_extrainfosbox";
  1351. if ($dbReference['CType'] == "mrm_be_cm_additionalinfobox" || $dbReference['CType'] == "mrm_me_cm_extra_infosbox") $open = true;
  1352. else $open = $flex["isInitialyOpen"] == "1";
  1353. if ($dbReference['CType'] == "mrm_be_cm_additionalinfobox" || $dbReference['CType'] == "mrm_be_cm_infobox") $headline = $flex["headline"];
  1354. elseif ($dbReference['CType'] == "mrm_be_cm_extra_infosbox") $headline = '';
  1355. $this->log('Headline: ' . $headline, true);
  1356. $sub = $this->createContentElement(
  1357. $type,
  1358. array("open" => $open, "noAutoOpen" => $flex["noAutoOpen"] == 1),
  1359. array("headline" => $flex["headline"])
  1360. );
  1361. if ($flex["image"] == "1") {
  1362. $props = $this->processImagesTTContent($dbReference, "mrm_be_cm_contentimage")[0];
  1363. $props["type"] = "typo3_content";
  1364. $sub["subElements"][] = $this->createContentElement("image", $props);
  1365. } else {
  1366. switch ($flex["icon"]) {
  1367. case "1":
  1368. $sub["attributes"]["icon"] = "stadtinfo_basics";
  1369. break;
  1370. case "2":
  1371. $sub["attributes"]["icon"] = "geschichte";
  1372. break;
  1373. case "3":
  1374. $sub["attributes"]["icon"] = "kultur_freizeit";
  1375. break;
  1376. case "4":
  1377. $sub["attributes"]["icon"] = "besonderheiten";
  1378. break;
  1379. case "5":
  1380. $sub["attributes"]["icon"] = "kosten_geld";
  1381. break;
  1382. case "6":
  1383. $sub["attributes"]["icon"] = "hochschulen";
  1384. break;
  1385. case "7":
  1386. $sub["attributes"]["icon"] = "studieren";
  1387. break;
  1388. }
  1389. }
  1390. if ($flex["dynamicComponents"] && sizeof($flex["dynamicComponents"]) > 0)
  1391. foreach ($flex["dynamicComponents"] as $comp) {
  1392. $stype = array_keys($comp['settings'])[0];
  1393. $elements = [];
  1394. switch ($stype) {
  1395. case "box":
  1396. $box = $this->createContentElement("boxwrapper");
  1397. $box["subElements"] = array_merge($box["subElements"], $this->checkText($comp['settings']['box']['boxheadline'], $dbReference, $processedData, "h3"));
  1398. $box["subElements"] = array_merge($box["subElements"], $this->checkText($comp['settings']['box']['boxtext'], $dbReference, $processedData, "typo3_paragraph"));
  1399. $elements = [$box];
  1400. break;
  1401. case "boxheadline":
  1402. $elements = $this->checkText($comp['settings'][$stype][$stype], $dbReference, $processedData, "h3");
  1403. //$this->log($elements, false);
  1404. break;
  1405. case "boxtext":
  1406. $elements = $this->checkText($comp['settings'][$stype][$stype], $dbReference, $processedData, "typo3_paragraph");
  1407. break;
  1408. case "html":
  1409. $elements = $this->checkText($comp['settings'][$stype][$stype], $dbReference, $processedData, "html");
  1410. break;
  1411. }
  1412. $sub["subElements"] = array_merge($sub["subElements"], $elements);
  1413. $this->log($sub["subElements"], false);
  1414. }
  1415. $subs[] = $sub;
  1416. break;
  1417. case "mrm_be_cm_extra_infosbox_prefilled":
  1418. $type = "typo3_extrainfosbox_prefilled";
  1419. $open = $flex["isInitialyOpen"] == "0" ? true : false;
  1420. $headline = $flex['headline'];
  1421. $elements = [];
  1422. $sub = $this->createContentElement(
  1423. $type,
  1424. array("open" => $open, "noAutoOpen" => $flex["noAutoOpen"] == 1),
  1425. array("headline" => $flex["headline"])
  1426. );
  1427. if ($flex["image"] == "1") {
  1428. $props = $this->processImagesTTContent($dbReference, "mrm_be_cm_contentimage")[0];
  1429. $props["type"] = "typo3_content";
  1430. $sub["subElements"][] = $this->createContentElement("image", $props);
  1431. } else {
  1432. switch ($flex["icon"]) {
  1433. case "1":
  1434. $sub["attributes"]["icon"] = "stadtinfo_basics";
  1435. break;
  1436. case "2":
  1437. $sub["attributes"]["icon"] = "geschichte";
  1438. break;
  1439. case "3":
  1440. $sub["attributes"]["icon"] = "kultur_freizeit";
  1441. break;
  1442. case "4":
  1443. $sub["attributes"]["icon"] = "besonderheiten";
  1444. break;
  1445. case "5":
  1446. $sub["attributes"]["icon"] = "kosten_geld";
  1447. break;
  1448. case "6":
  1449. $sub["attributes"]["icon"] = "hochschulen";
  1450. break;
  1451. case "7":
  1452. $sub["attributes"]["icon"] = "studieren";
  1453. break;
  1454. }
  1455. }
  1456. $cleaned = [];
  1457. $keys = ["healine", "image", "icon", "isInitialyOpen", "noAutoOpen"];
  1458. foreach ($keys as $k) {
  1459. unset($k);
  1460. }
  1461. foreach ($flex as $key => $val) {
  1462. if (strpos($key, 'headline') != false) {
  1463. $new_value = str_replace('headline', '', $key);
  1464. if (array_key_exists($new_value, $cleaned)) {
  1465. continue;
  1466. } else {
  1467. $cleaned[$new_value]['headline'] = $val;
  1468. }
  1469. } elseif (strpos($key, 'text') != false) {
  1470. $new_value = str_replace('text', '', $key);
  1471. if (!array_key_exists($new_value, $cleaned)) {
  1472. continue;
  1473. } else {
  1474. $cleaned[$new_value]['text'] = $val;
  1475. }
  1476. } elseif (strpos($key, 'url') != false) {
  1477. $new_value = str_replace('url', '', $key);
  1478. if (!array_key_exists($new_value, $cleaned)) {
  1479. continue;
  1480. } else {
  1481. $cleaned[$new_value]['url'] = $val;
  1482. }
  1483. }
  1484. }
  1485. $data = [];
  1486. foreach ($cleaned as $k => $val) {
  1487. foreach ($val as $field => $value) {
  1488. if (isset($value) && !empty($value)) {
  1489. $data[$k][$field] = $value;
  1490. } else {
  1491. continue;
  1492. }
  1493. }
  1494. }
  1495. foreach ($data as $key => $value) {
  1496. $box = $this->createContentElement("boxwrapper");
  1497. if (isset($value['headline']) && !empty($value['headline'])) {
  1498. $box["subElements"] = array_merge($box["subElements"], $this->checkText($value['headline'], $dbReference, $processedData, "h3"));
  1499. }
  1500. if (isset($value['text']) && !empty($value['text'])) {
  1501. $box["subElements"] = array_merge($box["subElements"], $this->checkText($value['text'], $dbReference, $processedData, "typo3_paragraph"));
  1502. }
  1503. if (isset($value['url']) && !empty($value['url'])) {
  1504. $box["subElements"] = array_merge($box["subElements"], $this->checkText($value['url'], $dbReference, $processedData, "link"));
  1505. }
  1506. $elements[] = $box;
  1507. }
  1508. $sub["subElements"] = array_merge($sub["subElements"], $elements);
  1509. $subs[] = $sub;
  1510. break;
  1511. case "mrm_be_cm_foldout":
  1512. $sub = $this->createContentElement("typo3_foldout", array("open" => $flex["isInitialyOpen"] == "1", "noAutoOpen" => $flex["noAutoOpen"] == "1"), array("headline" => $flex["headline"]), array());
  1513. if ($flex["image"] == "1") {
  1514. $props = $this->processImagesTTContent($dbReference, "mrm_be_cm_contentimage")[0];
  1515. $props["type"] = "typo3_content";
  1516. $sub["subElements"][] = $this->createContentElement("image", $props);
  1517. } else {
  1518. switch ($flex["icon"]) {
  1519. case "1":
  1520. $sub["attributes"]["icon"] = "stadtinfo_basics";
  1521. break;
  1522. case "2":
  1523. $sub["attributes"]["icon"] = "geschichte";
  1524. break;
  1525. case "3":
  1526. $sub["attributes"]["icon"] = "kultur_freizeit";
  1527. break;
  1528. case "4":
  1529. $sub["attributes"]["icon"] = "besonderheiten";
  1530. break;
  1531. case "5":
  1532. $sub["attributes"]["icon"] = "kosten_geld";
  1533. break;
  1534. case "6":
  1535. $sub["attributes"]["icon"] = "hochschulen";
  1536. break;
  1537. case "7":
  1538. $sub["attributes"]["icon"] = "studieren";
  1539. break;
  1540. }
  1541. }
  1542. if ($flex["dynamicComponents"] && sizeof($flex["dynamicComponents"]) > 0)
  1543. foreach ($flex["dynamicComponents"] as $comp) {
  1544. $stype = array_keys($comp['settings'])[0];
  1545. $elements = $this->checkText($comp['settings'][$stype][$stype], $dbReference, $processedData, $stype == "paragraph" ? "typo3_paragraph" : ($stype == "headline" ? "h3" : $stype));
  1546. $sub["subElements"] = array_merge($sub["subElements"], $elements);
  1547. }
  1548. $subs[] = $sub;
  1549. break;
  1550. case "mrm_be_cm_newsletterabo":
  1551. $newsletterabo = $this->createContentElement("newsletterabo", array("cr_url" => $flex["cr_url"], "cr_url_BIZ" => $flex["cr_url_BIZ"]));
  1552. $subs[] = $newsletterabo;
  1553. break;
  1554. case "mrm_be_cm_linkage":
  1555. $subs[] = $this->createContentElement("sidebarheadline", array(), array("text" => $flex['headline']));
  1556. $banners = $this->createContentElement("sidebarbanners");
  1557. if ($flex['dynamicComponents'] && sizeof($flex['dynamicComponents']) > 0)
  1558. foreach ($flex['dynamicComponents'] as $banner) {
  1559. $banners["subElements"][] = $this->createContentElement("banner", $this->parseFlexFormLink($banner["settings"]["link"]["link"], $dbReference, $processedData));
  1560. }
  1561. $subs[] = $banners;
  1562. $subs[] = $this->createContentElement("injection", array("type" => "rubrik_content"));
  1563. $processedData["injections"][] = "rubrik_content";
  1564. $berufenet = $this->createContentElement("sidebarexternallinks", array("type" => "berufenet"), array("items" => []));
  1565. if ($flex['dynamicComponentsBerufeNet'] && sizeof($flex['dynamicComponentsBerufeNet']) != 0)
  1566. foreach ($flex['dynamicComponentsBerufeNet'] as $itm) {
  1567. $link = $this->parseFlexFormLink($itm["settings"]["link"]["link"], $dbReference, $processedData);
  1568. $link = '<a href="' . $link['href'] . '" target="' . $link['target'] . '" aria-label="Externer Link">' . $link['alt'] . '</a>';
  1569. $berufenet["attributes"]["items"][] = $link;
  1570. }
  1571. if (sizeof($berufenet["attributes"]["items"]) > 0) $subs[] = $berufenet;
  1572. $berufetv = $this->createContentElement("sidebarexternallinks", array("type" => "berufetv"), array("items" => []));
  1573. if ($flex['dynamicComponentsBerufeTV'] && sizeof($flex['dynamicComponentsBerufeTV']) != 0)
  1574. foreach ($flex['dynamicComponentsBerufeTV'] as $itm) {
  1575. $link = $this->parseFlexFormLink($itm["settings"]["link"]["link"], $dbReference, $processedData);
  1576. $link = '<a href="' . $link['href'] . '" target="' . $link['target'] . '" aria-label="Externer Link">' . $link['alt'] . '</a>';
  1577. $berufetv["attributes"]["items"][] = $link;
  1578. }
  1579. if (sizeof($berufetv["attributes"]["items"]) > 0) $subs[] = $berufetv;
  1580. $berufsausbildung = $this->createContentElement("sidebarexternallinks", array("type" => "berufsausbildung"), array("items" => []));
  1581. if ($flex['dynamicComponentsBerufsausbildung'] && sizeof($flex['dynamicComponentsBerufsausbildung']) != 0)
  1582. foreach ($flex['dynamicComponentsBerufsausbildung'] as $itm) {
  1583. $link = $this->parseFlexFormLink($itm["settings"]["link"]["link"], $dbReference, $processedData);
  1584. $link = '<a href="' . $link['href'] . '" target="' . $link['target'] . '" aria-label="Externer Link">' . $link['alt'] . '</a>';
  1585. $berufsausbildung["attributes"]["items"][] = $link;
  1586. }
  1587. if (sizeof($berufsausbildung["attributes"]["items"]) > 0) $subs[] = $berufsausbildung;
  1588. $ba_search = $this->createContentElement("sidebarexternallinks", array("type" => "ba_search"), array("items" => []));
  1589. if ($flex['dynamicComponentsBASearch'] && sizeof($flex['dynamicComponentsBASearch']) != 0)
  1590. foreach ($flex['dynamicComponentsBASearch'] as $itm) {
  1591. $link = $this->parseFlexFormLink($itm["settings"]["link"]["link"], $dbReference, $processedData);
  1592. $link = '<a href="' . $link['href'] . '" target="' . $link['target'] . '" aria-label="Externer Link">' . $link['alt'] . '</a>';
  1593. $ba_search["attributes"]["items"][] = $link;
  1594. }
  1595. if (sizeof($ba_search["attributes"]["items"]) > 0) $subs[] = $ba_search;
  1596. $studienwahl = $this->createContentElement("sidebarexternallinks", array("type" => "studienwahl"), array("items" => []));
  1597. if ($flex['dynamicComponentsStudienwahl'] && sizeof($flex['dynamicComponentsStudienwahl']) != 0)
  1598. foreach ($flex['dynamicComponentsStudienwahl'] as $itm) {
  1599. $link = $this->parseFlexFormLink($itm["settings"]["link"]["link"], $dbReference, $processedData);
  1600. $link = '<a href="' . $link['href'] . '" target="' . $link['target'] . '" aria-label="Externer Link">' . $link['alt'] . '</a>';
  1601. $studienwahl["attributes"]["items"][] = $link;
  1602. }
  1603. if (sizeof($studienwahl["attributes"]["items"]) > 0) $subs[] = $studienwahl;
  1604. if ($flex['enable_check_u']) {
  1605. $check_u = $this->createContentElement("extimgbutton", array("ariaLabel" => "Zur Check-U-Website", "href" => "https://www.arbeitsagentur.de/bildung/welche-ausbildung-welches-studium-passt", "target" => "_blank"), array("imgsrc" => "/public/media/ext-link_check_u.png"));
  1606. $subs[] = $check_u;
  1607. }
  1608. if ($flex['enable_studiencheck']) {
  1609. $studiencheck = $this->createContentElement("extimgbutton", array("ariaLabel" => "Zur Studiencheck-Website", "href" => "https://studiencheck.de/", "target" => "_blank"), array("imgsrc" => "/public/media/ext-link_studiencheck.png"));
  1610. $subs[] = $studiencheck;
  1611. }
  1612. break;
  1613. case "mrm_be_cm_homeheaderinfo":
  1614. $items = array();
  1615. for ($i = 1; $i <= 3; $i++) {
  1616. if ($flex["headline" . $i] != "" && $flex["text" . $i] != "") {
  1617. $item = array("heading" => $flex["headline" . $i], "text" => $flex["text" . $i]);
  1618. if ($flex["link" . $i] != "") {
  1619. $link = $this->parseFlexFormLink($flex["link" . $i], $dbReference, $processedData);
  1620. $item["href"] = $link["href"];
  1621. $item["linkTarget"] = $link["target"];
  1622. }
  1623. if ($flex["image" . $i] == "1") {
  1624. $imgs = $this->processImagesTTContent($dbReference, 'mrm_be_cm_homeheaderinfo', 'tt_content', 'flex_image_' . $i, 'uid', false);
  1625. $item["image"] = "#cdnurl#/" . $imgs[0]["sources"][$flex["imagesize" . $i]];
  1626. }
  1627. $items[] = $item;
  1628. }
  1629. }
  1630. $subs[] = $this->createContentElement("abimessages", array("data" => $items));
  1631. break;
  1632. case "mrm_be_cm_tileoverview":
  1633. $items = array();
  1634. for ($i = 1; $i <= 8; $i++) {
  1635. if ($flex["link" . $i] == "") continue;
  1636. $item = array();
  1637. $link = $this->parseFlexFormLink($flex["link" . $i], $dbReference, $processedData);
  1638. $item["href"] = $link["href"];
  1639. $item["linkTarget"] = $link["target"];
  1640. $item["text"] = $link["alt"];
  1641. if ($flex["image" . $i] == "1") {
  1642. $imgs = $this->processImagesTTContent($dbReference, 'mrm_be_cm_tileoverview', 'tt_content', 'flex_image_' . $i, 'uid', false);
  1643. $item["image"] = "#cdnurl#/" . $imgs[0]["sources"]["default_hero_lte600"];
  1644. }
  1645. $items[] = $item;
  1646. }
  1647. $subs[] = $this->createContentElement("tileoverview", array("items" => $items));
  1648. break;
  1649. case "mrm_be_cm_highlightbox":
  1650. $elements = $this->checkText($flex["text"], $dbReference, $processedData, "typo3_paragraph");
  1651. $subs[] = $this->createContentElement("highlightbox", array("icon" => $flex["icon"]), array(), $elements);
  1652. break;
  1653. case "mrm_be_cm_statementbox":
  1654. $items = array();
  1655. $dynContentCounter = 0;
  1656. while (1) {
  1657. $dynContentCounter++;
  1658. if (!isset($flex['text' . $dynContentCounter])) break;
  1659. if ($flex['text' . $dynContentCounter] === '' || $flex['name' . $dynContentCounter] === '') continue;
  1660. $item = array(
  1661. 'quote' => $flex['text' . $dynContentCounter],
  1662. 'cite' => $flex['name' . $dynContentCounter]
  1663. );
  1664. if ($flex['image' . $dynContentCounter] == 1) {
  1665. $imgs = $this->processImagesTTContent($dbReference, 'mrm_be_cm_statementbox', 'tt_content', 'flex_image_' . $dynContentCounter, 'uid', false);
  1666. $imgs = $imgs[0];
  1667. $imgs['src'] = "#cdnurl#/" . $imgs['sources']['img'];
  1668. unset($imgs['sources']);
  1669. $item['img'] = $imgs;
  1670. }
  1671. $items[] = $item;
  1672. }
  1673. $subs[] = $this->createContentElement('statementbox', array('items' => $items));
  1674. break;
  1675. case "mrm_be_cm_explorerbox":
  1676. $items = array();
  1677. $dynContentCounter = 0;
  1678. while (1) {
  1679. $dynContentCounter++;
  1680. if (!isset($flex['head' . $dynContentCounter])) break;
  1681. if ($flex['head' . $dynContentCounter] === '' || $flex['claim' . $dynContentCounter] === '' || $flex['image' . $dynContentCounter] == 0) continue;
  1682. $item = array(
  1683. 'heading' => $flex['head' . $dynContentCounter],
  1684. 'subheading' => $flex['claim' . $dynContentCounter],
  1685. 'text' => $flex['text' . $dynContentCounter]
  1686. );
  1687. if ($flex['image' . $dynContentCounter] == 1) {
  1688. $imgs = $this->processImagesTTContent($dbReference, 'mrm_be_cm_explorerbox', 'tt_content', 'flex_image_' . $dynContentCounter, 'uid', false);
  1689. $imgs = $imgs[0];
  1690. $imgs['src'] = "#cdnurl#/" . $imgs['sources']['img'];
  1691. unset($imgs['sources']);
  1692. $item['img'] = $imgs;
  1693. }
  1694. if ($flex['link' . $dynContentCounter] !== '') {
  1695. $button = $this->parseFlexFormLink($flex['link' . $dynContentCounter], $dbReference, $processedData);
  1696. $item['button'] = $button;
  1697. }
  1698. $items[] = $item;
  1699. }
  1700. $subs[] = $this->createContentElement('explorerbox', array('items' => $items));
  1701. break;
  1702. case "mrm_be_cm_dynamic_tileoverview":
  1703. $items = array();
  1704. foreach ($flex["dynamicComponents"] as $comp) {
  1705. foreach ($comp as $k => $v) {
  1706. $itm = null;
  1707. switch ($k) {
  1708. case "links":
  1709. $lnk = $this->parseFlexFormLink($v["link"], $dbReference, $processedData);
  1710. $itm = $this->createContentElement("tile_default", array("link" => $lnk, "coloured" => $v["coloured"] == 1, "allowed" => preg_split('/\+/', $v["type"]), "format" => $v["format"]));
  1711. if ($lnk["alt"]) $itm["props"]["headline"] = $lnk["alt"];
  1712. break;
  1713. case "buttons":
  1714. $itm = $this->createContentElement(
  1715. "tile_content",
  1716. array(
  1717. "headline" => $v["headline"],
  1718. "content" => $this->checkTextForInternalLinks($v["buttons"], $dbReference, $processedData)
  1719. )
  1720. );
  1721. break;
  1722. case "icons":
  1723. $lnk = $this->parseFlexFormLink($v["link"], $dbReference, $processedData);
  1724. $itm = $this->createContentElement("tile_icon", array("link" => $lnk, "icon" => $v["icon"]), array());
  1725. if ($lnk["alt"]) $itm["props"]["headline"] = $lnk["alt"];
  1726. break;
  1727. case "flat":
  1728. $lnk = $this->parseFlexFormLink($v["link"], $dbReference, $processedData);
  1729. $itm = $this->createContentElement("tile_flat", array("link" => $lnk));
  1730. if ($lnk["alt"]) $itm["props"]["headline"] = $lnk["alt"];
  1731. break;
  1732. case "injections":
  1733. $itm = $this->createContentElement("injection", array("type" => $v["text"]));
  1734. $processedData["injections"][] = $v["text"];
  1735. break;
  1736. }
  1737. if ($itm)
  1738. $items[] = $itm;
  1739. }
  1740. }
  1741. $dto = $this->createContentElement('dynamic_tileoverview', array(), array(), $items);
  1742. if ($flex["cssClass"] && $flex["cssClass"] !== "")
  1743. $dto["attributes"]["cssClassName"] = $flex["cssClass"];
  1744. $subs[] = $dto;
  1745. $processedData["status"]["hasDynamicTileOverview"] = true;
  1746. break;
  1747. case "mrm_be_cm_podcast":
  1748. //$items = array();
  1749. if ($flex['media'] == "1")
  1750. $media = $this->processAudio($dbReference, 'mrm_be_cm_podcast', 'tt_content', 'media', 'uid', true, true);
  1751. if ($flex['transcript'])
  1752. $transcript = $flex['transcript'];
  1753. $subs[] = $this->createContentElement('podcast', array(), array('media' => $media, 'transcript' => $transcript));
  1754. break;
  1755. case "mrm_be_cm_imageplus":
  1756. $props = $this->processImagesTTContent($dbReference)[0];
  1757. $props["type"] = "imageplus";
  1758. $props["headline"] = $flex['headline'] ?? '';
  1759. $props["description"] = $flex['description'] ?? '';
  1760. $props["link"] = $this->parseFlexFormLink($flex["link"], $dbReference, $processedData);
  1761. $props["customcss"] = $flex['customcss'] ?? '';
  1762. $subs[] = $this->createContentElement('imageplus', $props);
  1763. break;
  1764. case "mrm_be_cm_interviewfrage":
  1765. $props['lang'] = $flex['lang'] ?? '';
  1766. $subs[] = $this->createContentElement("interviewfrage", $props, array("question" => trim($flex['question'])));
  1767. break;
  1768. case "mrm_be_cm_interviewantwort":
  1769. $props['lang'] = $flex['lang'] ?? '';
  1770. $subs[] = $this->createContentElement("interviewantwort", $props, array("interviewee" => trim($flex['interviewee']), "answer" => trim($flex['answer'])));
  1771. break;
  1772. case "mrm_be_cm_foldout_h3":
  1773. $sub = $this->createContentElement("typo3_foldout_h3", array("open" => $flex["isInitialyOpen"] == "1", "noAutoOpen" => $flex["noAutoOpen"] == "1"), array("headline" => $flex["headline"]), array());
  1774. if ($flex["image"] == "1") {
  1775. $props = $this->processImagesTTContent($dbReference, "mrm_be_cm_contentimage")[0];
  1776. $props["type"] = "typo3_content";
  1777. $sub["subElements"][] = $this->createContentElement("image", $props);
  1778. } else {
  1779. switch ($flex["icon"]) {
  1780. case "1":
  1781. $sub["attributes"]["icon"] = "stadtinfo_basics";
  1782. break;
  1783. case "2":
  1784. $sub["attributes"]["icon"] = "geschichte";
  1785. break;
  1786. case "3":
  1787. $sub["attributes"]["icon"] = "kultur_freizeit";
  1788. break;
  1789. case "4":
  1790. $sub["attributes"]["icon"] = "besonderheiten";
  1791. break;
  1792. case "5":
  1793. $sub["attributes"]["icon"] = "kosten_geld";
  1794. break;
  1795. case "6":
  1796. $sub["attributes"]["icon"] = "hochschulen";
  1797. break;
  1798. case "7":
  1799. $sub["attributes"]["icon"] = "studieren";
  1800. break;
  1801. }
  1802. }
  1803. if ($flex["dynamicComponents"] && sizeof($flex["dynamicComponents"]) > 0)
  1804. foreach ($flex["dynamicComponents"] as $comp) {
  1805. $stype = array_keys($comp['settings'])[0];
  1806. $elements = $this->checkText($comp['settings'][$stype][$stype], $dbReference, $processedData, $stype == "paragraph" ? "typo3_paragraph" : ($stype == "headline" ? "h4" : $stype));
  1807. $sub["subElements"] = array_merge($sub["subElements"], $elements);
  1808. }
  1809. $subs[] = $sub;
  1810. break;
  1811. case "mrm_be_cm_quiz_direct":
  1812. //print_r($flex); die();
  1813. $s = $this->createContentElement(
  1814. "quizdirect",
  1815. array(
  1816. "labels" => array(
  1817. "startbutton" => $flex["startbuttontext"],
  1818. "submitbutton" => $flex["submitbuttontext"],
  1819. "nextbutton" => $flex["nextbuttontext"],
  1820. "lastbutton" => $flex["lastbuttontext"],
  1821. "question" => $flex["question"],
  1822. "repeatbutton" => $flex["repeatbuttontext"],
  1823. "qsuccess" => $flex["questionsuccesstext"],
  1824. "qfail" => $flex["questionfailtext"],
  1825. ),
  1826. "resultscreen" => array(
  1827. "headingTop" => $flex["resultheadingtop"],
  1828. "headingSub" => $flex["resultheadingsub"],
  1829. "validation" => $flex["validationstr"],
  1830. "end" => $flex["thanks"]
  1831. ),
  1832. "isRestartAble" => $flex["isRestartAble"] == 1 || $flex["isRestartAble"] == "1",
  1833. ),
  1834. array(
  1835. "items" => array_values(array_map(function ($v) {
  1836. $questionType = null;
  1837. $quest = $v['settings']['question'];
  1838. if (!isset($quest)) {
  1839. $quest = $v['settings']['question_multi'];
  1840. $questionType = "multi";
  1841. }
  1842. if (isset($quest["additional_text"]) && $quest["additional_text"] != "") {
  1843. $quest["text"] = $quest["text"] . " (" . $quest["additional_text"] . ")";
  1844. unset($quest["additional_text"]);
  1845. }
  1846. if ($questionType) $quest["type"] = $questionType;
  1847. unset($quest["rightanswer"]);
  1848. if (isset($quest['solutionText'])) $solution = $quest['solutionText'];
  1849. unset($quest['solutionText']);
  1850. $i = 0;
  1851. $quest["answers"] = array();
  1852. while (1) {
  1853. $i++;
  1854. if (!isset($quest["answertext" . $i])) break;
  1855. if ($quest["answertext" . $i] === "") continue;
  1856. $quest["answers"][] = array("text" => $quest["answertext" . $i], "points" => (int)$quest["answerpoints" . $i]);
  1857. unset($quest["answertext" . $i]);
  1858. unset($quest["answerpoints" . $i]);
  1859. }
  1860. $quest["solution"] = $solution;
  1861. return $quest;
  1862. }, $flex["dynamicComponents"])),
  1863. "validation" => array(
  1864. "maxPoints" => (int)$flex["maxpoints"],
  1865. "averagePoints" => $this->createContentElement("injection", array("type" => "quiz-averagePoints")),
  1866. "alreadyReachedPoints" => $this->createContentElement("injection", array("type" => "quiz-alreadyReachedPoints")),
  1867. "items" => ($flex["dynamicComponents2"] == 0) ? [] : array_map(
  1868. function ($i) {
  1869. if (empty($i["validationText"])) $i["validationText"] = "";
  1870. else $i["validationText"] = $this->checkTextForInternalLinks($i["validationText"], $dbReference, $processedData);
  1871. return $i;
  1872. },
  1873. array_filter(array_values(array_map(function ($v) {
  1874. return $v['settings']['validation'];
  1875. }, $flex["dynamicComponents2"])), function ($x) {
  1876. return $x != null;
  1877. })
  1878. ),
  1879. ),
  1880. )
  1881. );
  1882. $processedData["injections"][] = "quiz-averagePoints";
  1883. $processedData["injections"][] = "quiz-alreadyReachedPoints";
  1884. $subs[] = $s;
  1885. $processedData["status"]["hasQuiz"] = true;
  1886. break;
  1887. case "mrm_be_cm_dynamic_tileexternaloverview":
  1888. $type = "tile_external";
  1889. $prop = [];
  1890. $elements = [];
  1891. $imageData = $this->processImagesTTContent($dbReference, "mrm_be_cm_dynamic_tileexternaloverview");
  1892. foreach ($imageData as $key => $val) {
  1893. foreach ($val as $k => $field) {
  1894. $prop[$key]['type'] = 'tile_external';
  1895. if ($k === 'title') $prop[$key]['props']['headline'] = $field;
  1896. if ($k === 'caption') $prop[$key]['props']['description'] = $field;
  1897. if ($k === 'sources') $prop[$key]['props']['image']['sources'] = $field;
  1898. if ($k === 'link') $prop[$key]['props']['link'] = $this->processLink($field, null, $processedData);
  1899. }
  1900. }
  1901. $subs[] = $this->createContentElement('external_tileoverview', array(), null, $prop);
  1902. break;
  1903. default:
  1904. $this->log("MISSING PROCESSDATA 4 " . $dbReference['CType']);
  1905. $this->log($flex, false);
  1906. break;
  1907. }
  1908. }
  1909. private function processLink($link, $dbReference, &$processedData)
  1910. {
  1911. $cleanedLink = [];
  1912. if (substr($link, 0, 2) === 't3') {
  1913. $parts = explode(' ', $link);
  1914. $cleanedLink['href'] = $this->replaceT3Link($parts[0], $dbReference, $processedData);
  1915. $cleanedLink['target'] = '_top';
  1916. //$cleanedLink['title'] = $parts[3] ?? '';
  1917. } else {
  1918. $parts = explode(' ', $link);
  1919. $cleanedLink['href'] = $parts[0];
  1920. $cleanedLink['target'] = $parts[1];
  1921. //$cleanedLink['title'] = $parts[3] ?? '';
  1922. }
  1923. return $cleanedLink;
  1924. }
  1925. private function checkText($txt, $dbReference, &$processedData, $defaultElementType = "typo3_paragraph")
  1926. {
  1927. $txt = $this->checkTextForInternalLinks($txt, $dbReference, $processedData);
  1928. $txt = $this->refactorTextElements($txt, $defaultElementType);
  1929. return $txt;
  1930. }
  1931. private function refactorTextElements($txt, $defaultElementType)
  1932. {
  1933. if (strpos($txt, "<table") === FALSE) return [$this->createContentElement($defaultElementType, array(), array("text" => $txt))];
  1934. $elements = [];
  1935. while (($tablepos = strpos($txt, "<table")) !== FALSE) {
  1936. if ($tablepos != 0) {
  1937. //$this->log(trim(substr($txt, 0, $tablepos)));
  1938. $elements[] = $this->createContentElement($defaultElementType, array(), array("text" => trim(substr($txt, 0, $tablepos))));
  1939. $txt = substr($txt, $tablepos);
  1940. }
  1941. $tablepos = strpos($txt, "</table>") + 8;
  1942. $dom = new \DOMDocument();
  1943. @$dom->loadHTML('<?xml encoding="utf-8" ?><div id="sexy">' . trim(substr($txt, 0, $tablepos)) . '</div>', LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
  1944. $tab = $this->createContentElement("table", array("rows" => array(), "columnCount" => 0));
  1945. foreach ($dom->getElementsByTagName('tr') as $tr) {
  1946. $par = $tr->parentNode;
  1947. $row = [];
  1948. if ($tab["props"]["columnCount"] == 0) {
  1949. foreach ($tr->childNodes as $e) {
  1950. if ($e->tagName == "td" || $e->tagName == "th") {
  1951. $tab["props"]["columnCount"]++;
  1952. }
  1953. }
  1954. }
  1955. foreach ($tr->childNodes as $e) {
  1956. if ($e->tagName != "td" && $e->tagName != "th") continue;
  1957. $innerHTML = '';
  1958. foreach ($e->childNodes as $n) $innerHTML .= $dom->saveHtml($n);
  1959. $row[] = array(
  1960. "html" => "<p>" . $innerHTML . "</p>",
  1961. "isHeader" => $par->tagName == "thead",
  1962. "isRowHeader" => $e->tagName == "th" && $par->tagName != "thead",
  1963. );
  1964. }
  1965. $tab["props"]["rows"][] = $row;
  1966. }
  1967. $elements[] = $tab;
  1968. $txt = substr($txt, $tablepos);
  1969. }
  1970. $txt = trim($txt);
  1971. if ($txt != "")
  1972. $elements[] = $this->createContentElement($defaultElementType, array(), array("text" => $txt));
  1973. return $elements;
  1974. }
  1975. private function checkTextForInternalLinks($txt, $dbReference, &$processedData)
  1976. {
  1977. $dom = new \DOMDocument();
  1978. @$dom->loadHTML('<?xml encoding="utf-8" ?><div id="sexy">' . $txt . '</div>', LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
  1979. foreach ($dom->getElementsByTagName('a') as $link) {
  1980. $emptyHref = false;
  1981. $title = null;
  1982. $alt = null;
  1983. $href = null;
  1984. for ($i = 0; $i < $link->attributes->length; ++$i) {
  1985. $node = $link->attributes->item($i);
  1986. if ($node->nodeName == "href" && strpos($node->nodeValue, 'smartadserver.com') === FALSE) {
  1987. $nv = $node->nodeValue;
  1988. $nv = str_replace('&amp;', '&', $nv);
  1989. $href = $this->replaceT3Link($nv, $dbReference, $processedData);
  1990. $node->nodeValue = htmlspecialchars($href);
  1991. if ($node->nodeValue == '') $emptyHref = true;
  1992. }
  1993. if ($node->nodeName == "title" && $node->nodeValue != '') $title = $node->nodeValue;
  1994. if ($node->nodeName == "alt" && $node->nodeValue != '') $alt = $node->nodeValue;
  1995. }
  1996. if ($emptyHref) $link->removeAttribute('href');
  1997. else {
  1998. if (!$alt) {
  1999. //check for pdf files (AS-337)
  2000. if (strtolower(pathinfo($href, PATHINFO_EXTENSION)) == "pdf") {
  2001. $alt = "PDF-Download (öffnet sich in neuem Fenster)";
  2002. $link->setAttribute('target', '_blank');
  2003. $link->setAttribute('alt', $alt);
  2004. }
  2005. }
  2006. }
  2007. if ($title && !$alt) $link->setAttribute('alt', $title);
  2008. if ($title) $link->removeAttribute('title');
  2009. }
  2010. $txt = $dom->saveHTML($dom->getElementById('sexy'));
  2011. $txt = str_replace('<div id="sexy">', '', $txt);
  2012. $txt = substr($txt, 0, -6);
  2013. return trim($txt);
  2014. }
  2015. private function parseFlexFormLink($link, $dbReference, &$processedData)
  2016. {
  2017. $link = implode("/", explode("\/", $link));
  2018. [$href, $target, $css] = explode(" ", $link);
  2019. $alt = substr($link, strlen($href . $target . $css) + 3);
  2020. $alt = preg_replace('/&quot;/', '', trim($alt, " \""));
  2021. if ($href == "-") return null;
  2022. $href = $this->replaceT3Link($href, $dbReference, $processedData, true);
  2023. $ret = array("href" => $href);
  2024. if (!$target || $target == "-") $ret["target"] = "_top";
  2025. else $ret["target"] = $target;
  2026. if ($alt && $alt != "-") $ret["alt"] = $alt;
  2027. return $ret;
  2028. }
  2029. private function replaceT3Link($link, $dbReference, &$processedData, $addToLinkedPosts = false)
  2030. {
  2031. $uid = $this->parseUIDFromT3Url($link);
  2032. if (!$uid || $uid == '') return $link;
  2033. if (strpos($link, 't3://page?') !== false) {
  2034. if ($uid == "current") {
  2035. $link = str_replace('t3://page?uid=current', '', $link);
  2036. } else {
  2037. if ($addToLinkedPosts) {
  2038. $processedData['linkedPosts'][] = (int)$uid;
  2039. $link = "#linkedPost#" . $uid . "#/linkedPost#";
  2040. } else {
  2041. $pageStatement = $this->pageQueryBuilder
  2042. ->select('*')
  2043. ->from('pages')
  2044. ->setMaxResults(1)
  2045. ->where(
  2046. $this->pageQueryBuilder->expr()->eq('uid', $this->pageQueryBuilder->createNamedParameter($uid))
  2047. )
  2048. ->execute();
  2049. $post = $pageStatement->fetchAll();
  2050. $post = $post[0];
  2051. $link = $post['slug'];
  2052. }
  2053. }
  2054. }
  2055. if (strpos($link, 't3://file?') !== false)
  2056. $link = $this->setStaticFile($dbReference, $uid);
  2057. return $link;
  2058. }
  2059. private function setStaticFile($dbReference, $uid, $publicUrl = null)
  2060. {
  2061. $fnNameRef = $dbReference['pid'] . "|" . $dbReference['uid'] . "|" . $dbReference['CType'] . "|file|" . $uid;
  2062. if (!$publicUrl) {
  2063. $file = $this->resourceFactory->getFileObject($uid);
  2064. $publicUrl = $file->getPublicUrl();
  2065. }
  2066. try {
  2067. $fnName = basename($publicUrl);
  2068. $fnName = explode(".", $fnName);
  2069. $extension = array_pop($fnName);
  2070. $fnName = implode(".", $fnName);
  2071. } catch (Exception $e) {
  2072. $fnName = null;
  2073. }
  2074. return "#cdnurl#/" . $this->copyAndRenameFile($fnNameRef, "/" . $publicUrl, $fnName);
  2075. }
  2076. private function parseUIDFromT3Url($t3url)
  2077. {
  2078. $uid = null;
  2079. if ($t3url && $t3url != '' && substr($t3url, 0, 2) == "t3")
  2080. try {
  2081. parse_str(parse_url($t3url)['query'], $query);
  2082. $uid = $query['uid'];
  2083. } catch (Exception $e) {
  2084. }
  2085. return $uid;
  2086. }
  2087. private function createContentElement($type, $props = null, $attributes = null, $subElements = null)
  2088. {
  2089. if (is_null($props)) $props = array();
  2090. if (is_null($attributes)) $attributes = (object) array();
  2091. $props["__hbs_uid"] = '_ab' . mt_rand(0, 0xffffff) . '_' . mt_rand(0, 0xffffff);
  2092. $ele = array(
  2093. 'type' => $type,
  2094. 'props' => $props,
  2095. 'attributes' => $attributes,
  2096. );
  2097. if (!is_null($subElements)) $ele['subElements'] = $subElements;
  2098. else $ele['subElements'] = [];
  2099. return $ele;
  2100. }
  2101. private function processVideo($dbReference)
  2102. {
  2103. $data = $this->resourceFactory->convertFlexFormDataToConfigurationArray($dbReference['pi_flexform']);
  2104. $vids = array();
  2105. foreach ($data['settings']['video'] as $value) {
  2106. if ($value['posterConfiguration'] && $value['posterConfiguration'] != '') $vids['poster'] = $value['posterConfiguration']['image'];
  2107. if ($value['mp4Configuration'] && $value['mp4Configuration'] != '') $vids['mp4'] = $value['mp4Configuration']['video'];
  2108. if ($value['ogvConfiguration'] && $value['ogvConfiguration'] != '') $vids['ogv'] = $value['ogvConfiguration']['video'];
  2109. if ($value['webmConfiguration'] && $value['webmConfiguration'] != '') $vids['webm'] = $value['webmConfiguration']['video'];
  2110. if ($value['threegpConfiguration'] && $value['threegpConfiguration'] != '') $vids['3gp'] = $value['threegpConfiguration']['video'];
  2111. }
  2112. foreach ($vids as $key => &$value) {
  2113. $value = "/" . $value;
  2114. $fnNameRef = $dbReference['pid'] . "|" . $dbReference['uid'] . "|" . $dbReference['CType'] . "|" . $key;
  2115. $value = $this->copyAndRenameFile($fnNameRef, $value);
  2116. }
  2117. return $vids;
  2118. }
  2119. private function processImagesTTContent($dbReference, $ctypeOverride = '', $table = 'tt_content', $tableColumn = 'image', $refField = 'uid', $useRelationFetch = true, $addCDNPrefix = false)
  2120. {
  2121. if ($useRelationFetch)
  2122. $fileObjects = $this->fileRepository->findByRelation($table, $tableColumn, $dbReference[$refField]);
  2123. else {
  2124. $sysfilerefQueryBuilder = $this->connection->getQueryBuilderForTable('sys_file_reference');
  2125. $sysfileStatement = $sysfilerefQueryBuilder
  2126. ->select('uid')
  2127. ->from('sys_file_reference')
  2128. ->andWhere(
  2129. $sysfilerefQueryBuilder->expr()->eq('uid_foreign', intval($dbReference[$refField])),
  2130. $sysfilerefQueryBuilder->expr()->eq('tablenames', $sysfilerefQueryBuilder->createNamedParameter($table)),
  2131. $sysfilerefQueryBuilder->expr()->eq('fieldname', $sysfilerefQueryBuilder->createNamedParameter($tableColumn)),
  2132. )
  2133. ->execute();
  2134. $frows = $sysfileStatement->fetchAll();
  2135. foreach ($frows as $fileuid) {
  2136. $fileObjects[] = $this->fileRepository->findFileReferenceByUid(intval($fileuid['uid']));
  2137. }
  2138. }
  2139. $processedImages = array();
  2140. $ctypeOverride = $ctypeOverride != '' ? $ctypeOverride : $dbReference['CType'];
  2141. foreach ($fileObjects as $key => $value) {
  2142. $img = array(
  2143. 'reference' => $value->getReferenceProperties(),
  2144. 'original' => $value->getOriginalFile()->getProperties(),
  2145. );
  2146. $imgfn = rtrim($img['original']['identifier'], "/");
  2147. $image = $this->imageService->getImage('fileadmin/' . $imgfn, null, false);
  2148. $cropvariantcollection = \TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection::create($img['reference']['crop']);
  2149. $cropareas = $this->imageSizes[$ctypeOverride];
  2150. $processArray = array(
  2151. 'sources' => array()
  2152. );
  2153. $alt = $img['reference']['alternative'] != NULL ? $img['reference']['alternative'] : ($img['original']['alternative'] != NULL ? $img['original']['alternative'] : NULL);
  2154. $title = $img['reference']['title'] != NULL ? $img['reference']['title'] : ($img['original']['title'] != NULL ? $img['original']['title'] : NULL);
  2155. $caption = $img['reference']['description'] != NULL ? $img['reference']['description'] : ($img['original']['description'] != NULL ? $img['original']['description'] : NULL);
  2156. $link = $img['reference']['link'] != NULL ? $img['reference']['link'] : ($img['original']['link'] != NULL ? $img['original']['link'] : NULL);
  2157. $copyright = $img['reference']['copyright'] != NULL ? $img['reference']['copyright'] : ($img['original']['copyright'] != NULL ? $img['original']['copyright'] : NULL);
  2158. if ($alt != NULL) $processArray['alt'] = $alt;
  2159. if ($title != NULL) $processArray['title'] = $title;
  2160. if ($caption != NULL) $processArray['caption'] = $caption;
  2161. if ($link != NULL) $processArray['link'] = $link;
  2162. if ($copyright != NULL) $processArray['copyright'] = $copyright;
  2163. if ($cropareas['passthru']) {
  2164. if (is_array($cropareas['passthru'])) {
  2165. foreach ($cropareas['passthru'] as $sizename => $size) {
  2166. $processingInstructions = array(
  2167. 'width' => $size['width'],
  2168. 'minWidth' => $size['width'],
  2169. 'maxWidth' => $size['width'],
  2170. 'crop' => null
  2171. );
  2172. if ($size['height']) {
  2173. $processingInstructions = array_merge(
  2174. $processingInstructions,
  2175. array(
  2176. 'height' => $size['height'],
  2177. 'minHeight' => $size['height'],
  2178. 'maxHeight' => $size['height']
  2179. )
  2180. );
  2181. }
  2182. if ($size['maxHeight'])
  2183. $processingInstructions['maxHeight'] = $size['maxHeight'];
  2184. if ($size['minHeight'])
  2185. $processingInstructions['minHeight'] = $size['minHeight'];
  2186. $processedImage = $this->imageService->applyProcessingInstructions($image, $processingInstructions);
  2187. $imageUri = $this->imageService->getImageUri($processedImage);
  2188. $fnNameRef = $dbReference['pid'] . "|" . $dbReference['uid'] . "|" . $ctypeOverride . "|" . $img['reference']['uid'] . "|passthru|" . $sizename;
  2189. $processArray['sources'][$sizename] = $this->copyAndRenameFile($fnNameRef, $imageUri, $processArray['alt']);
  2190. }
  2191. } else {
  2192. $fnNameRef = $dbReference['pid'] . "|" . $dbReference['uid'] . "|" . $ctypeOverride . "|" . $img['reference']['uid'] . "|passthru";
  2193. $imageUri = $this->imageService->getImageUri($image);
  2194. $processArray['sources']['passthru'] = ($addCDNPrefix ? "#cdnurl#/" : "") . $this->copyAndRenameFile($fnNameRef, $imageUri, $processArray['alt']);
  2195. }
  2196. } else
  2197. foreach ($cropareas as $cropareaname => $sizes) {
  2198. $croparea = $cropvariantcollection->getCropArea($cropareaname);
  2199. foreach ($sizes as $sizename => $size) {
  2200. if ($dbReference["doktype"] && $size['allowed_doktypes'] && !in_array($dbReference["doktype"], $size['allowed_doktypes'])) continue;
  2201. $processingInstructions = array(
  2202. 'width' => $size['width'],
  2203. 'minWidth' => $size['width'],
  2204. 'maxWidth' => $size['width'],
  2205. 'crop' => $croparea->isEmpty() ? null : $croparea->makeAbsoluteBasedOnFile($image)
  2206. );
  2207. if ($size['height']) {
  2208. $processingInstructions = array_merge(
  2209. $processingInstructions,
  2210. array(
  2211. 'height' => $size['height'],
  2212. 'minHeight' => $size['height'],
  2213. 'maxHeight' => $size['height']
  2214. )
  2215. );
  2216. }
  2217. if ($size['maxHeight'])
  2218. $processingInstructions['maxHeight'] = $size['maxHeight'];
  2219. if ($size['minHeight'])
  2220. $processingInstructions['minHeight'] = $size['minHeight'];
  2221. $processedImage = $this->imageService->applyProcessingInstructions($image, $processingInstructions);
  2222. $imageUri = $this->imageService->getImageUri($processedImage);
  2223. $fnNameRef = $dbReference['pid'] . "|" . $dbReference['uid'] . "|" . $ctypeOverride . "|" . $img['reference']['uid'] . "|" . $cropareaname . "|" . $sizename;
  2224. $processArray['sources'][$sizename] = ($addCDNPrefix ? "#cdnurl#/" : "") . $this->copyAndRenameFile($fnNameRef, $imageUri, $processArray['alt']);
  2225. }
  2226. }
  2227. $processedImages[] = $processArray;
  2228. }
  2229. return $processedImages;
  2230. }
  2231. private function processAudio($dbReference, $ctypeOverride = '', $table = 'tt_content', $tableColumn = 'media', $refField = 'uid', $useRelationFetch = true, $copyToCDN = false)
  2232. {
  2233. if ($useRelationFetch)
  2234. $fileObjects = $this->fileRepository->findByRelation($table, $tableColumn, $dbReference[$refField]);
  2235. else {
  2236. $sysfilerefQueryBuilder = $this->connection->getQueryBuilderForTable('sys_file_reference');
  2237. $sysfileStatement = $sysfilerefQueryBuilder
  2238. ->select('uid')
  2239. ->from('sys_file_reference')
  2240. ->andWhere(
  2241. $sysfilerefQueryBuilder->expr()->eq('uid_foreign', intval($dbReference[$refField])),
  2242. $sysfilerefQueryBuilder->expr()->eq('tablenames', $sysfilerefQueryBuilder->createNamedParameter($table)),
  2243. $sysfilerefQueryBuilder->expr()->eq('fieldname', $sysfilerefQueryBuilder->createNamedParameter($tableColumn)),
  2244. )
  2245. ->execute();
  2246. $frows = $sysfileStatement->fetchAll();
  2247. foreach ($frows as $fileuid) {
  2248. $fileObjects[] = $this->fileRepository->findFileReferenceByUid(intval($fileuid['uid']));
  2249. }
  2250. }
  2251. $processedAudio = array();
  2252. $audio = [];
  2253. $ctypeOverride = $ctypeOverride != '' ? $ctypeOverride : $dbReference['CType'];
  2254. foreach ($fileObjects as $key => $value) {
  2255. $processedAudio = array(
  2256. 'reference' => $value->getReferenceProperties(),
  2257. 'original' => $value->getOriginalFile()->getProperties(),
  2258. );
  2259. if ($copyToCDN) {
  2260. $oringalFile = $processedAudio['original']['identifier'];
  2261. $extension = pathinfo($processedAudio['original']['identifier'], PATHINFO_EXTENSION);
  2262. $targetFile = substr(sha1($processedAudio['original']['identifier']), 0, 5) . '_podcast.' . $extension;
  2263. $oringalFile = '/fileadmin' . $oringalFile;
  2264. $url = $this->copyPodcastAudioFileToCDN($oringalFile, $targetFile);
  2265. }
  2266. $audio['name'] = $processedAudio['original']['name'];
  2267. $audio['url'] = $url;
  2268. $audio['title'] = $processedAudio['reference']['title'];
  2269. $audio['description'] = $processedAudio['reference']['description'];
  2270. }
  2271. return $audio;
  2272. }
  2273. private function copyAndRenameFile($destinationFnRef, $sourceUri, $altText = null)
  2274. {
  2275. $shaFileRef = sha1($destinationFnRef);
  2276. $workPath = substr($shaFileRef, 0, 2) . "/" . substr($shaFileRef, 2, 2);
  2277. $workFnPrefix = $shaFileRef;
  2278. if ($altText) {
  2279. $altText = substr($altText, 0, 100);
  2280. $workFnPrefix = $this->sanitizeString($altText) . "-" . $shaFileRef;
  2281. }
  2282. $workFn = $workFnPrefix . "." . pathinfo($sourceUri, PATHINFO_EXTENSION);
  2283. if (!file_exists(\TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/cdn/' . $workPath)) {
  2284. mkdir(\TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/cdn/' . $workPath, 0777, true);
  2285. }
  2286. copy(\TYPO3\CMS\Core\Core\Environment::getPublicPath() . $sourceUri, \TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/cdn/' . $workPath . '/' . $workFn);
  2287. return $workPath . '/' . $workFn;
  2288. }
  2289. private function copyPodcastAudioFileToCDN($sourceFile, $destinationFile)
  2290. {
  2291. $dir = 'podcast';
  2292. if (!file_exists(\TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/cdn/' . $dir)) {
  2293. mkdir(\TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/cdn/' . $dir, 0777, true);
  2294. }
  2295. copy(\TYPO3\CMS\Core\Core\Environment::getPublicPath() . $sourceFile, \TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/cdn/' . $dir . '/' . $destinationFile);
  2296. return '#cdnurl#/' . $dir . '/' . $destinationFile;
  2297. }
  2298. public function processCmdmap_deleteAction($table, $id, $recordToDelete, $recordWasDeleted = NULL, \TYPO3\CMS\Core\DataHandling\DataHandler &$pObj)
  2299. {
  2300. //$this->log('processCmdmap_deleteAction');
  2301. if ($table == "pages") {
  2302. Mongoer::sendRequest("pages", "delete", array("pageuid" => $id));
  2303. Mongoer::sendRequest("abialtcache", "delete", array("pageuid" => $pid));
  2304. Mongoer::sendRequest("search", "delete", array("pageuid" => $id));
  2305. Mongoer::sendRequest("security", "delete", array("pageuid" => $id));
  2306. Mongoer::sendRequest("previews", "delete", array("pageuid" => $id));
  2307. }
  2308. }
  2309. /* PRIVATES */
  2310. private function log($msg, $isString = true)
  2311. {
  2312. if (!$isString) {
  2313. $msg = json_encode($msg, JSON_PRETTY_PRINT);
  2314. }
  2315. file_put_contents('/var/www/html/typo3temp/debug.log', $msg . PHP_EOL, FILE_APPEND);
  2316. }
  2317. }