public static function isWritingURI() { $path = Request::path(); $writing_path = Writing::path(); $URIhasWritingPathPrefix = 0; $isUsingPathPrefix = Config::get('writing.use_path_prefix'); $slug = $path; /*if($isUsingPathPrefix) { echo 'using_prefix = true;<br>'; } else { echo 'using_prefix = false;<br>'; }*/ if ($isUsingPathPrefix == true) { $URIhasWritingPathPrefix = count(explode($writing_path, $path)) - 1; if ($URIhasWritingPathPrefix) { $slug = str_replace($writing_path, "", $path); } else { return false; } if ($article = DB::table('articles')->whereSlug($slug)->first()) { return true; } else { return false; } } if (!$isUsingPathPrefix) { if ($URIhasWritingPathPrefix) { return false; } if ($article = DB::table('articles')->whereSlug($slug)->first()) { return true; } else { return false; } } return false; }
public function getFeed(Request $request) { // create new feed $feed = App::make("feed"); // cache the feed for 60 minutes (second parameter is optional) $feed->setCache(60, 'laravelFeedKey'); // check if there is cached feed and build new only if is not if (!$feed->isCached()) { $default_author = 'Nono Martínez Alonso'; // creating rss feed with our most recent articles $show = Config::get('writing.feed.show'); $articles = Article::published()->public()->rss()->orderBy('published_at', 'DESC')->take($show)->get(); // set your feed's title, description, link, pubdate and language $feed->title = Config::get('writing.feed.title'); $feed->description = Config::get('writing.feed.description'); $feed->logo = Config::get('writing.feed.logo'); $feed->link = \URL::to('/' . Writing::path()); $feed->setDateFormat('datetime'); // 'datetime', 'timestamp' or 'carbon' $feed->pubdate = $articles[0]->published_at; $feed->lang = 'en'; $feed->setShortening(false); // true or false $feed->setTextLimit(159); // maximum length of description text $feed->setView("writing::feed.rss"); foreach ($articles as $article) { // set item's title, author, url, pubdate, description and content $imageURL = ''; $image = ''; if ($article->image) { $image = '<p><img src="' . $article->image . '" alt="' . $article->title . '"></p>'; } if ($article->video) { $image = '<p><a href="' . $request->root() . '/' . Writing::path() . $article->slug . '">' . '<img src="' . \Thinker::getVideoThumb($article->video) . '" alt="' . $article->title . '"></a></p>'; } if ($imageURL != '') { $image = '<p><img src="' . $imageURL . '" alt="' . $article->title . '"></p>'; } $feed->add($article->title, $default_author, \URL::to(Writing::path() . $article->slug), $article->published_at, '', str_replace('<img', '<img width="100%"', $image . \Markdown::string($article->text))); } } // first param is the feed format // optional: second param is cache duration (value of 0 turns off caching) // optional: you can set custom cache key with 3rd param as string //return $feed->render('atom'); return \Response::make($feed->render('rss', -1), 200, array('Content-Type' => 'text/xml', 'Cache-Control' => 'no-cache')); // to return your feed as a string set second param to -1 // $xml = $feed->render('atom', -1); }
/*----------------------------------------------------------------*/ /* WritingController /*----------------------------------------------------------------*/ Route::group(['middleware' => Config::get("writing.middlewares")], function () { $path = Writing::path(); //TODO: $path_admin = Writing::pathAdmin(); if (Writing::isAvailableURI()) { Route::get('/@{user_twitter}', function ($user_twitter) { $user = User::where('twitter', '=', $user_twitter)->first(); return view('writing::profile')->withUser($user); }); Route::post('articles', 'Nonoesp\\Writing\\Controllers\\WritingController@getArticlesWithIds'); Route::get($path, array('as' => 'blog', 'uses' => 'Nonoesp\\Writing\\Controllers\\WritingController@showHome')); Route::get($path . 'tag/{tag}', 'Nonoesp\\Writing\\Controllers\\WritingController@showArticleTag'); Route::get($path . '{id}', 'Nonoesp\\Writing\\Controllers\\WritingController@showArticleWithId')->where('id', '[0-9]+'); if (Writing::isWritingURI()) { // Check this is an actual article route Route::get($path . '{slug}', 'Nonoesp\\Writing\\Controllers\\WritingController@showArticle'); } // Feed Route::get(Config::get('writing.feed.route'), array('as' => 'feed', 'uses' => 'Nonoesp\\Writing\\Controllers\\WritingController@getFeed')); } /*----------------------------------------------------------------*/ /* AdminController /*----------------------------------------------------------------*/ Route::group(array('middleware' => 'login'), function () { Route::get('/admin', 'Nonoesp\\Writing\\Controllers\\AdminController@getDashboard'); // Articles Route::get('/admin/articles', 'Nonoesp\\Writing\\Controllers\\AdminController@getArticleList'); Route::any('/admin/article/edit/{id}', array('as' => 'article.edit', 'uses' => 'Nonoesp\\Writing\\Controllers\\AdminController@ArticleEdit')); Route::get('/admin/article/add', 'Nonoesp\\Writing\\Controllers\\AdminController@getArticleCreate');