function generate_rss($posts) { $feed = new Feed(); $channel = new Channel(); $rssLength = config('rss.char'); $channel->title(blog_title())->description(blog_description())->url(site_url())->appendTo($feed); foreach ($posts as $p) { if (!empty($rssLength)) { if (strlen(strip_tags($p->body)) < config('rss.char')) { $string = preg_replace('/\\s\\s+/', ' ', strip_tags($p->body)); $body = $string . '...'; } else { $string = preg_replace('/\\s\\s+/', ' ', strip_tags($p->body)); $string = substr($string, 0, config('rss.char')); $string = substr($string, 0, strrpos($string, ' ')); $body = $string . '...'; } } else { $body = $p->body; } $item = new Item(); $cats = explode(',', str_replace(' ', '', strip_tags(remove_accent($p->category)))); foreach ($cats as $cat) { $item->category($cat, site_url() . 'category/' . strtolower($cat)); } $item->title($p->title)->pubDate($p->date)->description($body)->url($p->url)->appendTo($channel); } echo $feed; }
function generate_rss($posts) { $feed = new Feed(); $channel = new Channel(); $rssLength = config('rss.char'); $channel->title(blog_title())->description(blog_description())->url(site_url())->appendTo($feed); foreach ($posts as $p) { if (!empty($rssLength)) { if (strlen(strip_tags($p->body)) < config('rss.char')) { $string = preg_replace('/\\s\\s+/', ' ', strip_tags($p->body)); $body = $string . '...' . ' <a class="readmore" href="' . $p->url . '#more">more</a>'; } else { $string = preg_replace('/\\s\\s+/', ' ', strip_tags($p->body)); $string = substr($string, 0, config('rss.char')); $string = substr($string, 0, strrpos($string, ' ')); $body = $string . '...' . ' <a class="readmore" href="' . $p->url . '#more">more</a>'; } } else { $body = $p->body; } $item = new Item(); $tags = explode(',', str_replace(' ', '', strip_tags($p->tag))); foreach ($tags as $tag) { $item->category($tag, site_url() . 'tag/' . $tag); } $item->title($p->title)->pubDate($p->date)->description($body)->url($p->url)->appendTo($channel); } echo $feed; }
$blogPostItem->url($url); $blogPostItem->guid($url, true); $description = $blogPost['body']; $description = strip_tags($description); $description = strtok($description, "\n"); if (strlen($description) > 250) { $description = wordwrap($description, 250); $description = strtok($description, "\n"); if (substr($description, -1) != '.') { $description .= '…'; } } $description = html_entity_decode($description); $blogPostItem->description($description); $categoryUrl = "https://blog.jacobemerick.com/{$blogPost['category']}/"; $blogPostItem->category($blogPost['category'], $categoryUrl); $pubDate = new DateTime($blogPost['date']); $blogPostItem->pubDate($pubDate->getTimestamp()); if (preg_match('@{{photo="([^\\/]+)/([^\\.]+).([^"]+)"}}@', $blogPost['body'], $match) == 1) { $photoPath = "/photo/{$match[1]}/{$match[2]}-size-large.{$match[3]}"; $photoInternalPath = __DIR__ . '/../../web/public' . $photoPath; $photoSize = filesize($photoInternalPath); /** * ugh, remote host does not have pecl fileinfo * * $fInfo = new finfo(FILEINFO_MIME_TYPE); * $photoType = $fInfo->file($photoInternalPath); * unset($fInfo); **/ $photoType = 'image/jpeg'; $blogPostItem->enclosure("https://blog.jacobemerick.com{$photoPath}", $photoSize, $photoType);
$feed = new Feed(); $channel = new Channel(); $channel->title('Wurst update status'); $channel->description("Uni-Hamburg server"); $channel->url('http://zbh.uni-hamburg.de'); $channel->appendTo($feed); $transformerCategory = new RecordToCategoryTransformer(); $transformerTitle = new RecordToTitleTransformer($transformerCategory); $transformerDescription = new RecordToDescriptionTransformer($app['twig']); foreach ($app['wurst.history']->collection() as $id => $element) { $item = new Item(); $item->author("wurst update"); $item->url("http://{$SERVER_ROOT_SCRIPT}/details/{$id}"); $item->pubDate($element->getDate()); $item->title($transformerTitle->transform($element)); $item->category($transformerCategory->transform($element)); $item->description($transformerDescription->transform($element)); $item->appendTo($channel); } return new Response($feed, 200); }); /** * Method to show details for given record in rss stream * * @todo ids for all records are not unique, * @todo so it may be a problem but this situation is not so probable * @todo we can just ignore that, but it should be changed for good * */ $app->get('/details/{unique}', function (Request $request, $unique) use($app) { assert($collection = $app['wurst.history']->collection(), "History can not be empty");