*/ class syntax_plugin_newsfeed_carousel extends AbstractStream { public function connectTo($mode): void { $this->Lexer->addSpecialPattern('{{news-carousel>.+?}}', $mode, 'plugin_newsfeed_carousel'); } public function handle($match, $state, $pos, Doku_Handler $handler): array { preg_match_all('/([a-z]+)="([^".]*)"/', substr($match, 16, -2), $matches); $parameters = []; foreach ($matches[1] as $index => $match) { $parameters[$match] = $matches[2][$index]; } return [$state, [$parameters]]; } public function render($format, Doku_Renderer $renderer, $data): bool { if ($format !== 'xhtml') { return true; } [$state, $match] = $data; switch ($state) { case DOKU_LEXER_SPECIAL: [$param] = $match; $renderer->nocache(); $stream = $this->helper->serviceStream->findByName($param['stream']); $allNews = $stream->getNews(); if (count($allNews)) { $this->renderCarousel($renderer, $allNews, $param); } } return true; } private function renderCarousel(Doku_Renderer $renderer, array $news, array $params): void { $id = uniqid(); $indicators = []; $items = []; $noFeeds = 5; for ($i = 0; $i < $noFeeds; $i++) { if (!isset($news[$i])) { break; }; /** * @var $feed ModelNews; */ $feed = $news[$i]; $indicators[] = '
  • '; $items[] = $this->getCarouselItem($feed, !$i); } $renderer->doc .= ''; } private function renderCarouselIndicators(Doku_Renderer $renderer, array $indicators): void { $renderer->doc .= ''; } private function renderCarouselItems(Doku_Renderer $renderer, array $items): void { $renderer->doc .= ''; } private function getCarouselItem(ModelNews $feed, bool $active): string { $style = ''; if ($feed->hasImage()) { $style .= 'background-image: url(' . ml($feed->image, ['w' => 1200]) . ')'; } $background = 'bg-' . $feed->category . '-fade '; $html = ''; $html .= ''; return $html; } private function getText(ModelNews $feed): string { return '

    ' . $feed->renderText() . '

    '; } private function getHeadline(ModelNews $feed): string { return '

    ' . hsc($feed->title) . '

    '; } private function getLink(ModelNews $feed): string { if ($feed->linkTitle) { if (preg_match('|^https?://|', $feed->linkHref)) { $href = hsc($feed->linkHref); } else { $href = wl($feed->linkHref, null, true); } return '

    ' . $feed->linkTitle . '

    '; } return ''; } }