private function parseFeed($author, $feed) { $contenttype = $this->config['contenttype']; $reader = new Reader(); $resource = $reader->download($feed['feed']); // Return the right parser instance according to the feed format $parser = $reader->getParser($resource->getUrl(), $resource->getContent(), $resource->getEncoding()); // Return a Feed object $feeditems = $parser->execute(); // Print the feed properties with the magic method __toString() // slice $items = array_slice($feeditems->items, 0, $this->config['itemAmount']); foreach ($items as $item) { //echo "<hr>\n"; //echo " - " .$item->getTitle() . "<br>\n - " . \Bolt\Helpers\String::slug( $item->getTitle() ) . "\n"; // try to get an existing record for this item $record = $this->app['storage']->getContent($contenttype, array('slug' => \Bolt\Helpers\String::slug($item->getTitle()), 'returnsingle' => true)); if (!$record) { // New one. $record = $this->app['storage']->getContentObject($contenttype); echo "\n<b>[NEW]</b> "; $new = true; } else { echo "\n<b>[UPD]</b> : " . $record->values['id']; $new = false; } $date = new \DateTime("@" . $item->getDate()); if ($item->getContent() != false) { $raw = $item->getContent(); } else { $raw = $item->getIntro(); } // Sanitize/clean the HTML. $maid = new \Maid\Maid(array('output-format' => 'html', 'allowed-tags' => array('p', 'br', 'hr', 's', 'u', 'strong', 'em', 'i', 'b', 'li', 'ul', 'ol', 'menu', 'blockquote', 'pre', 'code', 'tt', 'h2', 'h3', 'h4', 'h5', 'h6', 'dd', 'dl', 'dh', 'table', 'tbody', 'thead', 'tfoot', 'th', 'td', 'tr', 'a', 'img'), 'allowed-attribs' => array('id', 'class', 'name', 'value', 'href', 'src'))); $content = $maid->clean($raw); // if ($item->getImage() != "") { // $image = $item->getImage(); // } else { $image = $this->findImage($content, $feed['url']); // } $values = array('itemid' => $item->getId(), 'title' => "" . $item->getTitle(), 'raw' => "" . $raw, 'body' => "" . $content, 'author' => $author, 'image' => $image, 'status' => 'published', 'sitetitle' => $feed['title'], 'sitesource' => $feed['url']); // echo "<img src='".$image['file']."' width='200'>"; if ($new || $date instanceof \DateTime) { echo "[1]"; $values['datecreated'] = $date instanceof \DateTime ? $date->format('Y-m-d H:i:s') : ""; $values['datepublish'] = $date instanceof \DateTime ? $date->format('Y-m-d H:i:s') : ""; } else { dump($date); echo "[2]"; } // $record->setTaxonomy('tags', $item->getTags()); // $record->setTaxonomy('authors', $author); $record->setValues($values); $id = $this->app['storage']->saveContent($record); echo " - " . $values['datecreated'] . " / " . $values['title']; flush(); } }
/** * Formats the given string as Markdown in HTML * * @param string $content * @return string Markdown output */ public function markdown($content) { // Parse the field as Markdown, return HTML $output = \Parsedown::instance()->parse($content); // Sanitize/clean the HTML. $maid = new \Maid\Maid(array('output-format' => 'html', 'allowed-tags' => array('html', 'head', 'body', 'section', 'div', 'p', 'br', 'hr', 's', 'u', 'strong', 'em', 'i', 'b', 'li', 'ul', 'ol', 'menu', 'blockquote', 'pre', 'code', 'tt', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'dd', 'dl', 'dh', 'table', 'tbody', 'thead', 'tfoot', 'th', 'td', 'tr', 'a', 'img'), 'allowed-attribs' => array('id', 'class', 'name', 'value', 'href', 'src'))); $output = $maid->clean($output); return $output; }
/** * Creates RSS safe content. Wraps it in CDATA tags, strips style and * scripts out. Can optionally also return a (cleaned) excerpt. * * @param string $field The field to clean up * @param int $excerptLength Number of chars of the excerpt * @return string RSS safe string */ public function rss_safe($field = '', $excerptLength = 0) { if (array_key_exists($field, $this->values)) { if ($this->fieldtype($field) == 'html') { $value = $this->values[$field]; // Completely remove style and script blocks $maid = new \Maid\Maid(array('allowed-tags' => array('a', 'b', 'br', 'hr', 'h1', 'h2', 'h3', 'h4', 'p', 'strong', 'em', 'i', 'u', 'strike', 'ul', 'ol', 'li', 'img'), 'output-format' => 'html')); $result = $maid->clean($value); if ($excerptLength > 0) { $result = trimText($result, $excerptLength, false, true, false); } return '<![CDATA[ ' . $result . ' ]]>'; } else { return $this->values[$field]; } } return ""; }
/** * Formats the given string as Markdown in HTML. * * @param string $content * * @return string Markdown output */ public function markdown($content) { // Parse the field as Markdown, return HTML $output = \ParsedownExtra::instance()->text($content); $config = $this->app['config']->get('general/htmlcleaner'); $allowed_tags = !empty($config['allowed_tags']) ? $config['allowed_tags'] : array('div', 'p', 'br', 'hr', 's', 'u', 'strong', 'em', 'i', 'b', 'li', 'ul', 'ol', 'blockquote', 'pre', 'code', 'tt', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'dd', 'dl', 'dh', 'table', 'tbody', 'thead', 'tfoot', 'th', 'td', 'tr', 'a', 'img'); $allowed_attributes = !empty($config['allowed_attributes']) ? $config['allowed_attributes'] : array('id', 'class', 'name', 'value', 'href', 'src'); // Sanitize/clean the HTML. $maid = new \Maid\Maid(array('output-format' => 'html', 'allowed-tags' => $allowed_tags, 'allowed-attribs' => $allowed_attributes)); $output = $maid->clean($output); return $output; }
public function rss_safe($fields = '', $excerptLength = 0) { // Make sure we have an array of fields. Even if it's only one. if (!is_array($fields)) { $fields = explode(',', $fields); } $fields = array_map('trim', $fields); $result = ''; foreach ($fields as $field) { if (array_key_exists($field, $this->values)) { // Completely remove style and script blocks $maid = new \Maid\Maid(array('allowed-tags' => array('a', 'b', 'br', 'hr', 'h1', 'h2', 'h3', 'h4', 'p', 'strong', 'em', 'i', 'u', 'strike', 'ul', 'ol', 'li', 'img'), 'output-format' => 'html')); $result .= $maid->clean($this->values[$field]); } } if ($excerptLength > 0) { $result .= trimText($result, $excerptLength, false, true, false); } return '<![CDATA[ ' . $result . ' ]]>'; }