public function index() { $parsedown = new \ParsedownExtra(); $config = Configuration::find(1); $posts = Post::published()->orderBy('published_at', 'desc')->get(); $feed = new Feed(); $channel = new Channel(); $channel->title($config->blog_title)->description($config->blog_description)->url(url('/'))->appendTo($feed); foreach ($posts as $post) { $item = new Item(); $item->title($post->title)->description($parsedown->parse($post->content))->url(url("/articles/{$post->slug}"))->guid(url("/articles/{$post->slug}"), true)->appendTo($channel); } return response($feed)->header('Content-Type', 'application/rss+xml'); }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id, $param1 = null, $param2 = null) { //Get a specific item $entry = Contentful::entries()->limitByType('2wKn6yEnZewu2SCCkus4as')->includeLinks(10)->get(); /** * get youtube video ID from URL * * @param string $url * @return string Youtube video id or FALSE if none found. */ function youtube_id_from_url($url) { $pattern = '%^# Match any youtube URL (?:https?://)? # Optional scheme. Either http or https (?:www\\.)? # Optional www subdomain (?: # Group host alternatives youtu\\.be/ # Either youtu.be, | youtube\\.com # or youtube.com (?: # Group path alternatives /embed/ # Either /embed/ | /v/ # or /v/ | /watch\\?v= # or /watch\\?v= ) # End path alternatives. ) # End host alternatives. ([\\w-]{10,12}) # Allow 10-12 for 11 char youtube id. $%x'; $result = preg_match($pattern, $url, $matches); if (false !== $result) { return $matches[1]; } return false; } foreach ($entry['items'] as $key => $post) { if ($post['fields']['slug'] == $id) { //global $post; //content $blog['title'] = $post['fields']['title']; $blog['body'] = Markdown::parse($post['fields']['body']); $blog['slug'] = $post['fields']['slug']; //media $blog['imageId'] = $post['fields']['featuredImage']['sys']['id']; if (isset($post['fields']['gallery'])) { //Prepare the gallery of images foreach ($post['fields']['gallery'] as $keyId => $imgId) { $id = $imgId['sys']['id']; foreach ($entry['includes']['Asset'] as $key => $asset) { if ($id == $asset['sys']['id']) { $gallery[$key]['id'] = $asset['sys']['id']; $gallery[$key]['imageUrl'] = $asset['fields']['file']['url']; } } } $blog['gallery'] = $gallery; } if (isset($post['fields']['location'])) { $blog['location'] = $post['fields']['location']; } if (isset($post['fields']['video3'])) { $blog['video'] = youtube_id_from_url($post['fields']['video3']); } if (isset($post['fields']['image'])) { $blog['image'] = Image::cache(function ($image) use($post) { $image->make($post['fields']['image'])->encode('data-url'); }, null, false); } //metadeta $blog['createdAt'] = $post['sys']['createdAt']; } } //get a specific asset $assets = Contentful::assets()->where('sys.id', '=', $blog['imageId'])->get(); //setting the width of the image on the fly! $blog['imageUrl'] = Image::cache(function ($image) use($assets) { $image->make('http:' . $assets['items'][0]['fields']['file']['url'] . '?' . 'w=400&fm=jpg')->greyscale()->encode('data-url'); }, null, false); $params = display($param1, $param2); $params['blog'] = $blog; return view('blog.item')->with($params); }