Source of file RssEntryTransformer.php
Size: 2,512 Bytes - Last Modified: 2021-12-23T10:48:37+00:00
/var/www/docs.ssmods.com/process/src/code/import/RssEntryTransformer.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 | <?php /** * @package silverstripe-rssconnector */ require_once Director::baseFolder() . '/rss-connector/thirdparty/htmlpurifier/HTMLPurifier.auto.php'; /** * Transforms an RSS entry into a local blog entry. * * @package silverstripe-rssconnector */ class RssEntryTransformer implements ExternalContentTransformer { protected $importer; public function transform($item, $parent, $strategy) { $params = $this->importer->getParams(); $guid = $item->getGuid(); $exists = DataObject::get_one('ExternalBlogEntry', sprintf( '"Guid" = \'%s\'', Convert::raw2sql($guid) )); if ($exists) { if ($strategy == ExternalContentTransformer::DS_SKIP) { return; } if ($strategy == ExternalContentTransformer::DS_OVERWRITE) { $entry = $exists; } } if (!isset($entry)) { $entry = new ExternalBlogEntry(); } $entry->Guid = $guid; $entry->ExternalLink = $item->Link; $entry->Title = $item->Title; $entry->ParentID = $parent->ID; $entry->Date = $item->Date; $entry->Author = $item->AuthorName; $entry->ProvideComments = isset($params['ProvideComments']); $purifier = new HTMLPurifier(); $entry->Content = $purifier->purify($item->Content); if (isset($params['ImportCategories'])) { $labels = $item->getCategories()->map('Term', 'Label'); $tags = array(); if ($params['UnknownCategories'] == 'skip') { foreach ($labels as $k => $label) { $exists = DB::query(sprintf( 'SELECT 1 FROM "BlogEntry" WHERE "Tags" LIKE \'%%%s%%\'', Convert::raw2sql($label) )); if (!$exists->column()) { unset($labels[$k]); } } } $tags = implode(', ', $labels); if ($params['ExtraTags']) { $tags .= ', ' . $params['ExtraTags']; } $entry->Tags = trim(trim($tags), ','); } $entry->write(); if (isset($params['PublishPosts'])) { $entry->publish('Stage', 'Live'); } } public function setImporter(RssContentImporter $importer) { $this->importer = $importer; } } |