/** \Zend\Filter\HTMLEntities() */ public function index13Action() { $filter = new \Zend\Filter\HtmlEntities(); $input = 'Zend Framework 2 <> "" ? ~'; $output = $filter->filter($input); echo "<h3>" . $input . "</h3>"; echo "<h3>" . $output . "</h3>"; return false; }
public function index14Action() { echo "<h3 style='color:red;font-weight:bold'>" . __METHOD__ . "</h3>"; $filter = new \Zend\Filter\HtmlEntities(); $input = "trongle123>>!&"; $output = $filter->filter($input); echo "<h2>Input: {$input}</h2><br>"; echo "<h2>Output : {$output}</h2>"; return false; }
<?php /** * Copyright (c) 2014 Keith Casey. * * This code is designed to accompany the lynda.com video course "Design Patterns in PHP" * by Keith Casey. If you've received this code without seeing the videos, go watch the * videos. It will make way more sense and be more useful in general. */ require 'vendor/autoload.php'; $input = "This is a string of text that should be filtered & handle 's properly."; $htmlEntities = new Zend\Filter\HtmlEntities(); echo $htmlEntities->filter($input); echo '<br />'; $alphanumeric = new \Zend\I18n\Filter\Alnum(); echo $alphanumeric->filter($input); echo '<br />'; // Now allow whitespace $alphanumeric = new \Zend\I18n\Filter\Alnum(true); echo $alphanumeric->filter($input);
public function __invoke($entries, $template, $media) { $templateKey = static::VIEW_TEMPLATE; if (isset($entries['modulFormat'])) { $templateKey = $entries['modulFormat']; } $this->setTemplate($template->plugins->{$templateKey}); $labelReadMore = $this->labelReadMore->toArray(); $publishDate = $this->publishDate->toArray(); $publishDate['grid']['format']['dateFormat']['attr'] = $this->getDateFormat($entries); $filter = new \Zend\Filter\HtmlEntities(); $html = ''; foreach ($entries['modulContent']['news'] as $entry) { $article = ''; $head = ''; $arr = preg_split('/[\\s]+/', $entry['publish_date']); $lnPublishDate = $arr[0]; $publishDate['grid']['attr']['datetime'] = $entry['publish_date']; $head .= $this->deployRow($publishDate, $entry['publish_date']); if (isset($entry['publish_author'])) { $head .= $this->deployRow($this->publishAuthor, $entry['publish_author']); } $blogId = 'blog' . $entry['id']; if (null !== $this->toolbar) { $links['pdf'] = array('href' => '/' . $entry['id']); $links['facebook'] = array('href' => '?u=' . urlencode($this->view->protocol . '://' . $this->view->host . '/' . $entry['url'] . '/' . $entry['source'] . '/' . $entry['lnPublishDate'] . '#' . $blogId)); $links['sendmail'] = array('href' => '/' . $entry['id']); $head .= $this->view->contenttoolbar($links, $this->toolbar->toArray()); } $head .= $this->deployRow($this->headline, $entry['headline']); $article .= $this->deployRow($this->header, $head); if (1 !== (int) $entry['web_medias_id'] && 'no' !== $this->displayimage) { if ('mediateaserright' == $entry['htmlwidgets']) { $mediaTemplate = $this->mediateaserright->toArray(); } else { $mediaTemplate = $this->mediateaserleft->toArray(); } $setSize = array('landscape' => $this->teaserLandscapeSize, 'portrait' => $this->teaserPortraitSize); $mediaMetas = $this->setConvertparams($entry['media_metas'], true); $img = '<img src="' . $entry['media_link'] . '"'; if (is_array($setSize) && isset($setSize['landscape']) && false !== $setSize['landscape']) { $landscape = $setSize['landscape']; $styleAttr = ' landscape'; if (isset($setSize['portrait']) && false !== $setSize['portrait']) { $styleAttr = ' portrait'; $portrait = $setSize['portrait']; } else { $styleAttr = ' portrait'; $portrait = $landscape; } } else { $portrait = $landscape = $setSize; } $resize = new CalculateResize($landscape); $resize->setFile(DOCUMENT_ROOT . DS . $entry['media_link']); $resize->getNewSize(); if ('portrait' == $resize->getFormat()) { $resize->setTarget($portrait); $resize->getNewSize(); } $img .= ' ' . $resize->getHtmlString(); if (isset($mediaMetas['alt'])) { $img .= ' alt="' . $mediaMetas['alt'] . '"'; } if (false !== ($title = $this->hasValue($mediaMetas, 'title'))) { $img .= ' title="' . $title . '"'; } $img .= ' />'; $mediaTemplate['row']['attr']['class'] .= ' teaser-imageitem-size'; if (false !== ($caption = $this->hasValue($mediaMetas, 'caption'))) { $mediaTemplate['row']['content:before'] = $img; $images = $this->deployRow($mediaTemplate, $caption); } else { $images = $this->deployRow(array('grid' => $mediaTemplate['row']), $img); } $article .= $images; } $labelReadMore["grid"]["attr"]['href'] = '/' . $entry['url'] . '/' . $entry['source'] . '/' . $entry['lnPublishDate'] . '#' . $blogId; $labelReadMore["grid"]["attr"]['title'] = $entry['label_read_more'] . ' zu ' . $filter->filter($entry['headline']); if (strlen($entry['content_teaser']) > 1) { $article .= $entry['content_teaser']; $article .= $this->deployRow($labelReadMore, $entry['label_read_more']); } else { $content = $entry['content']; if ($entry['number_character_teaser'] > 0 && strlen($content) > $entry['number_character_teaser']) { $content = substr($content, 0, $entry['number_character_teaser']); $content = substr($content, 0, strrpos($content, " ")); $content = $content . ' ...</p>'; $article .= $content; $article .= $this->deployRow($labelReadMore, $entry['label_read_more']); } else { $article .= $content; } } //$article .= '<p><a class="button expand" title="Lesen Sie mehr" href="#">Lesen Sie mehr</a></p>'; //$newtemplate = $this->news->toArray(); //$newtemplate['grid']['content:after:outside'] = '<p><a class="button expand" title="Lesen Sie mehr" href="#">Lesen Sie mehr</a></p>'; $html .= $this->deployRow($this->news, $article); } if (null !== $this->wrapper) { $html = $this->deployRow($this->wrapper, $html); } return $html; }
/** * * @param array $content * @param unknown $medias * @param string $template * @param string $teasers * @return string */ public function __invoke($entries, $template, $media) { $html = ''; $this->convertGroupParams($entries['modulContent']['group']); $templateKey = static::VIEW_TEMPLATE; if (isset($entries['modulFormat'])) { $templateKey = $entries['modulFormat']; } $this->setTemplate($template->plugins->{$templateKey}); $labelReadMore = $this->labelReadMore->toArray(); $publishDate = $this->publishDate->toArray(); $publishDate['grid']['format']['dateFormat']['attr'] = $this->getDateFormat($entries); $header = $this->header->toArray(); $filter = new \Zend\Filter\HtmlEntities(); $urlFiler = new \ContentinumComponents\Filter\Url\Prepare(); $i = 0; foreach ($entries['modulContent']['news'] as $entry) { $head = ''; $article = ''; $blogId = 'blog' . $entry->webContent->id; $publishDate['grid']['attr']['datetime'] = $entry->webContent->publishDate; $head .= $this->deployRow($publishDate, $entry->webContent->publishDate); $head .= $this->deployRow($this->publishAuthor, $entry->webContent->publishAuthor); if (null !== $this->toolbar) { $links['pdf'] = array('href' => '/' . $entry->webContent->id . '/' . $entry->webContentgroup); $links['facebook'] = array('href' => '?u=' . urlencode($this->view->protocol . '://' . $this->view->host . '/' . $this->groupurl . '/' . $entry->webContent->source . '/' . $entry->webContent->publishDate . '#' . $blogId)); $links['sendmail'] = array('href' => '/' . $entry->webContent->id); $head .= $this->view->contenttoolbar($links, $this->toolbar->toArray()); } $head .= $this->deployRow($this->headline, $entry->webContent->headline); $header['grid']['attr']['id'] = $blogId; $article .= $this->deployRow($header, $head); if (1 !== $entry->webContent->webMediasId->id) { $setSizes = null; if ('mediateaserright' == $entry->webContent->htmlwidgets) { $mediaTemplate = $this->mediateaserright->toArray(); } else { $mediaTemplate = $this->mediateaserleft->toArray(); } if (false !== $this->teaserLandscapeSize) { $mediaStyle = ''; $setSizes = array('landscape' => $this->teaserLandscapeSize, 'portrait' => $this->teaserPortraitSize); } else { $setSizes = null; $mediaStyle = 'teaser-imageitem-size'; } $article .= $this->imagesrc($entry->webContent, $entry->webContent->webMediasId, $mediaTemplate, $mediaStyle, $setSizes); } if (isset($entries['modulContent']['archivbacklink'])) { $labelReadMore["grid"]["attr"]['data-backlink'] = '/' . $this->groupurl . '/' . $entries['modulContent']['archivbacklink']; $labelReadMore["grid"]["attr"]['class'] = $labelReadMore["grid"]["attr"]['class'] . ' setBacklink'; } $labelReadMore["grid"]["attr"]['href'] = '/' . $this->groupurl . '/' . $entry->webContent->source . '/' . $this->convertPublishDate($entry->webContent->publishDate) . '#' . $blogId; $labelReadMore["grid"]["attr"]['title'] = $entry->webContent->labelReadMore . ' zu ' . $filter->filter($entry->webContent->headline); if (strlen($entry->webContent->contentTeaser) > 1) { $article .= $entry->webContent->contentTeaser; $article .= $this->deployRow($labelReadMore, $entry->webContent->labelReadMore); } else { $content = $entry->webContent->content; if ($entry->webContent->numberCharacterTeaser > 0 && strlen($content) > $entry->webContent->numberCharacterTeaser) { $content = substr($content, 0, $entry->webContent->numberCharacterTeaser); $content = substr($content, 0, strrpos($content, " ")); $content = $content . ' ...</p>'; $article .= $content; $article .= $this->deployRow($labelReadMore, $entry->webContent->labelReadMore); } else { $article .= $this->formatElement($content, $entry->webContent); } } $html .= $this->deployRow($this->news, $article); $i++; } return $html; }
/** * * @param array $content * @param unknown $medias * @param string $template * @param string $teasers * @return string */ public function __invoke($entries, $template, $media) { $html = ''; $this->convertGroupParams($entries['modulContent']['group']); $numbernews = 10; if (false !== ($numbers = $this->getGroupParameter('numbernews'))) { $numbernews = (int) $numbers; } $templateKey = static::VIEW_TEMPLATE; if (false !== ($htmlwidgets = $this->getGroupParameter('htmlwidgets'))) { $templateKey = $htmlwidgets; } $this->setTemplate($template->plugins->{$templateKey}); if (false !== ($headline = $this->getGroupParameter('headlineGroup'))) { $this->groupName = $headline; } switch ($entries['modulFormat']) { case 'n': break; case 'y': default: $html .= $this->groupHeader('<h1>' . $this->groupName . '</h1>'); } $readMoreView = false; if (strlen($this->view->paramter['section']) > 1) { switch ($this->view->paramter['section']) { case 'tag': case 'archive': case 'category': $numbernews = 9999; break; default: $backLink = $this->backlink->toArray(); $readMoreView = true; break; } } $labelReadMore = $this->labelReadMore->toArray(); $publishDate = $this->publishDate->toArray(); $publishDate['grid']['format']['dateFormat']['attr'] = $this->getDateFormat($entries); $header = $this->header->toArray(); $filter = new \Zend\Filter\HtmlEntities(); $urlFiler = new \ContentinumComponents\Filter\Url\Prepare(); $links = array(); $i = 0; foreach ($entries['modulContent']['news'] as $entry) { $head = ''; $article = ''; $blogId = 'blog' . $entry->webContent->id; $publishDate['grid']['attr']['datetime'] = $entry->webContent->publishDate; $head .= $this->deployRow($publishDate, $entry->webContent->publishDate); $head .= $this->deployRow($this->publishAuthor, $entry->webContent->publishAuthor); if (null !== $this->toolbar) { $links['pdf'] = array('href' => '/' . $entry->webContent->id . '/' . $entry->webContentgroup); $links['facebook'] = array('href' => '?u=' . urlencode($this->view->protocol . '://' . $this->view->host . '/' . $this->groupurl . '/' . $entry->webContent->source . '/' . $entry->webContent->publishDate . '#' . $blogId)); $links['sendmail'] = array('href' => '/' . $entry->webContent->id); $head .= $this->view->contenttoolbar($links, $this->toolbar->toArray()); } $head .= $this->deployRow($this->headline, stripslashes($entry->webContent->headline)); $header['grid']['attr']['id'] = $blogId; $article .= $this->deployRow($header, $head); if (false === $readMoreView) { if (1 !== $entry->webContent->webMediasId->id) { $setSizes = null; if ('mediateaserright' == $entry->webContent->htmlwidgets) { $mediaTemplate = $this->mediateaserright->toArray(); } else { $mediaTemplate = $this->mediateaserleft->toArray(); } if (false !== $this->teaserLandscapeSize) { $mediaStyle = ''; $setSizes = array('landscape' => $this->teaserLandscapeSize, 'portrait' => $this->teaserPortraitSize); } else { $setSizes = null; $mediaStyle = 'teaser-imageitem-size'; } $article .= $this->imagesrc($entry->webContent, $entry->webContent->webMediasId, $mediaTemplate, $mediaStyle, $setSizes); } if (isset($entries['modulContent']['archivbacklink'])) { $labelReadMore["grid"]["attr"]['data-backlink'] = '/' . $this->groupurl . '/' . $entries['modulContent']['archivbacklink']; $labelReadMore["grid"]["attr"]['class'] = $labelReadMore["grid"]["attr"]['class'] . ' setBacklink'; } $labelReadMore["grid"]["attr"]['href'] = '/' . $this->groupurl . '/' . $entry->webContent->source . '/' . $this->convertPublishDate($entry->webContent->publishDate) . '#' . $blogId; $labelReadMore["grid"]["attr"]['title'] = $entry->webContent->labelReadMore . ' zu ' . $filter->filter($entry->webContent->headline); if (strlen($entry->webContent->contentTeaser) > 1) { $article .= $entry->webContent->contentTeaser; $article .= $this->deployRow($labelReadMore, $entry->webContent->labelReadMore); } else { $content = $entry->webContent->content; if ($entry->webContent->numberCharacterTeaser > 0 && strlen($content) > $entry->webContent->numberCharacterTeaser) { $content = substr($content, 0, $entry->webContent->numberCharacterTeaser); $content = substr($content, 0, strrpos($content, " ")); $content = $content . ' ...</p>'; $article .= $content; $article .= $this->deployRow($labelReadMore, $entry->webContent->labelReadMore); } else { $article .= $this->formatElement($content, $entry->webContent); } } } else { $article .= $entry->webContent->contentTeaser; if (1 !== $entry->webContent->webMediasId->id) { if (1 === $entry->webContent->mediaPlaceholder) { $article = str_replace('{MEDIAPLACE}', $this->imagesrc($entry->webContent, $entry->webContent->webMediasId, $this->media->toArray()), $article); } else { $article .= $this->imagesrc($entry->webContent, $entry->webContent->webMediasId, $this->media->toArray()); } } $article .= $this->formatElement($entry->webContent->content, $entry->webContent); if (isset($entries['modulContent']['newsplugins'])) { $plugins = $entries['modulContent']['newsplugins']; if (isset($plugins[$entry->webContent->modul][$entry->webContent->id])) { $pluginViewHelper = $this->view->pluginViewHelper[$entry->webContent->modul]; $article .= $this->view->{$pluginViewHelper}($plugins[$entry->webContent->modul][$entry->webContent->id], $this->view->pluginstyles, $entry->webContent->webMediasId); } } $backLink["grid"]["attr"]['href'] = '/' . $this->groupurl; if (isset($this->view->cookies['backlinkarchiv'])) { $backLink["grid"]["attr"]['class'] = $backLink["grid"]["attr"]['class'] . ' unsetBacklink'; $backLink["grid"]["attr"]['href'] = $this->view->cookies['backlinkarchiv']; } $backLink["grid"]["attr"]['title'] = $this->view->translate('Back'); $foot = $this->deployRow($backLink, $this->view->translate('Back')); if (null !== $this->footer) { $article .= $this->deployRow($this->footer, $foot); } } if (0 === $i) { $news = $this->news->toArray(); $news["grid"]["attr"]['class'] .= ' first-element'; $html .= $this->deployRow($news, $article); } else { $html .= $this->deployRow($this->news, $article); } $i++; if ($i === $numbernews) { break; } } return $html; }