public function get_conf() { $apiEndpoint = $this->app->config('prismic.url'); $apiConfEndpoint = mb_substr($apiEndpoint, 0, count($apiEndpoint) - 4) . 'conf'; $token = $this->app->config('prismic.token'); if ($token && is_null($this->conf)) { try { $httpClient = \Prismic\Api::defaultHttpAdapter(); $queryString = http_build_query(array("access_token" => $token)); $response = $httpClient->get($apiConfEndpoint . '?' . $queryString); $this->conf = json_decode($response->getBody(), true); } catch (\Ivory\HttpAdapter\HttpAdapterException $e) { } } return $this->conf; }
} } else { $app->response->setStatus(400); } }); $app->get('/disqus/posts/list', function () use($app, $prismic) { $cursor = $app->request->get('cursor'); $limit = $app->request->get('limit'); $threadIds = $app->request->get('thread'); $order = $app->request->get('order'); $apiKey = $prismic->config('disqus.apikey'); $apiSecret = $prismic->config('disqus.apisecret'); $accessToken = $prismic->config('disqus.accesstoken'); $forum = $prismic->config('disqus.forum'); if ($apiKey && $apiSecret && $accessToken && $forum) { $httpClient = \Prismic\Api::defaultHttpAdapter(); $param = array('api_key' => $apiKey, 'api_secret' => $apiSecret, 'access_token' => $accessToken, 'cursor' => $cursor, 'limit' => $limit, 'thread' => $threadIds, 'order' => $order, 'forum' => $forum); $queryString = http_build_query($param); $url = 'https://disqus.com/api/3.0/posts/list.json?' . $queryString; $url = preg_replace('/%5B[0-9]+%5D/simU', '%5B%5D', $url); $app->response->headers->set('Content-Type', 'application/json'); try { $response = $httpClient->get($url); $json = json_decode($response->getBody()); $app->response->setStatus($response->getStatusCode()); $app->response->setBody(json_encode($json)); } catch (\Ivory\HttpAdapter\HttpAdapterException $e) { $app->response->setStatus($e->getResponse()->getStatusCode()); } } });