}; // Replace notFoundHandler to use an API response $container['notFoundHandler'] = function ($c) { return function ($request, $response) use($c) { return $c['response']->withHeader('Content-Type', 'application/json')->write('{ message: "Matching API call not found." }'); }; }; // Replace the errorHandler to use an API response $container['errorHandler'] = function ($c) { return function ($request, $response, $exception) use($c) { $c['logger']->addError('Server error', $exception->getTrace()); return $c['response']->withStatus(500)->withHeader('Content-Type', 'application/json')->write('{ message: "Internal Server Error", error: "' . $exception->getMessage() . '" }'); }; }; // Routes ending in '/' use route without '/' $app->add(function ($request, $response, $next) { $uri = $request->getUri(); $path = $uri->getPath(); if (strlen($path) > 1 && substr($path, -1) === '/') { $path = substr($path, 0, -1); } if ($uri->getPath() !== $path) { return $next($request->withUri($uri->withPath($path)), $response); } return $next($request, $response); }); // Create RSS on first run if (!file_exists('../rss/rss.xml')) { $rss = new RssGenerator(); $rss->updateRss(); }
} # Include require $config['lychee'] . 'php/define.php'; require $config['lychee'] . 'php/autoload.php'; require $config['lychee'] . 'data/config.php'; require 'RssGenerator.php'; require 'JsonGenerator.php'; require 'DataProvider.php'; require 'vendor/autoload.php'; # Set Mime Type if (!empty($_GET['format']) && $_GET['format'] === "json") { header('Content-Type: application/json'); } else { header('Content-type: application/rss+xml'); } $rssGenerator = new RssGenerator($config); $jsonGenerator = new JsonGenerator($config); $dataProvider = new DataProvider($dbHost, $dbUser, $dbPassword, $dbName, $dbTablePrefix); # If a album name is provided, we'll create a feed only for this album if (!empty($_GET['album'])) { $albums = $dataProvider->getPublicAlbums(); $albumId = getAlbumIdByName($albums, $_GET['album']); if (empty($albumId)) { die('Could not find a public album with title: ' . $_GET['album'] . '. Please make sure that this album exists and that it is public!'); } $photos = $dataProvider->getPhotosByAlbum($albumId); if (!empty($_GET['format']) && $_GET['format'] === "json") { # Generate RSS as JSON echo $jsonGenerator->buildJsonFeedForAlbum($_GET['album'], $photos); } else { # Generate RSS
<?php include_once "rssGenerator.php"; $rss = new RssGenerator("Liftoff News", "http://liftoff.msfc.nasa.gov/", "Liftoff to Space Exploration.", strtotime("Tue, 10 Jun 2003 04:00:00 GMT"), strtotime("Tue, 10 Jun 2003 09:41:01 GMT"), array("docs" => "http://blogs.law.harvard.edu/tech/rss", "generator" => "Weblog Editor 2.0", "managingEditor" => "*****@*****.**", "webMaster" => "*****@*****.**")); $rss->addItem(array("title" => "Star City", "link" => "http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp", "description" => "How do Americans get ready to work with Russians aboard the International Space Station? They take a crash course in culture, language and protocol at Russia's <a href=\"http://howe.iki.rssi.ru/GCTC/gctc_e.htm\">Star City</a>.", "pubDate" => "Tue, 03 Jun 2003 09:39:21 GMT", "guid" => "http://liftoff.msfc.nasa.gov/2003/06/03.html#item573")); $rss->publish();
public function unpublishPost($request, $response, $args) { $status = $this->secureRoute($request, $response); if ($status !== 200) { return $this->jsonResponse($response, $status); } $user = Auth::GetUser($request); $post = $this->loadPost($args['id']); if (!$post) { return $this->jsonResponse($response, 400); } if ($post->user_id !== $user->id && !$user->is_admin) { $this->apiJson->addAlert('error', 'You cannot unpublish this post.'); return $this->jsonResponse($response, 403); } $post->is_published = false; $post->publish_date = null; R::store($post); $rss = new RssGenerator(); $rss->updateRss(); $this->apiJson->setSuccess(); $this->apiJson->addAlert('success', 'Post ' . $post->title . ' unpublished.'); $this->apiJson->addData($post->export()); return $this->jsonResponse($response); }