Esempio n. 1
0
function recent_posts($pageSize)
{
    global $WPGLOBAL, $loop;
    $prismic = $WPGLOBAL['prismic'];
    $pageSize = $pageSize ? $pageSize->getValue() : 5;
    $posts = $prismic->form()->query(Predicates::at('document.type', 'post'))->pageSize($pageSize)->fetchLinks('post.date', 'category.name', 'author.full_name', 'author.first_name', 'author.surname', 'author.company')->orderings('my.post.date desc')->submit();
    $loop->setResponse($posts);
}
Esempio n. 2
0
File: Api.php Progetto: lamenath/fbp
 /**
  * Return the URL to display a given preview
  * @param string $token as received from Prismic server to identify the content to preview
  * @param \Prismic\LinkResolver $linkResolver the link resolver to build URL for your site
  * @param string $defaultUrl the URL to default to return if the preview doesn't correspond to a document
  *                (usually the home page of your site)
  * @return string the URL you should redirect the user to preview the requested change
  */
 public function previewSession($token, $linkResolver, $defaultUrl)
 {
     $response = $this->getHttpAdapter()->get($token);
     $response = json_decode($response->getBody(true));
     if (isset($response->mainDocument)) {
         $documents = $this->forms()->everything->query(Predicates::at("document.id", $response->mainDocument))->ref($token)->submit()->getResults();
         if (count($documents) > 0) {
             return $linkResolver->resolveDocument($documents[0]);
         }
     }
     return $defaultUrl;
 }
    $homeId = $prismic->get_api()->bookmark('home');
    $blogHomeId = $prismic->get_api()->bookmark('bloghome');
    if ($blogHomeId == null) {
        not_found($app);
    } else {
        if ($blogHomeId == $homeId) {
            redirect('/');
            return;
        }
    }
    $blogHome = $prismic->get_page($blogHomeId);
    if ($blogHome == null) {
        not_found($app);
        return;
    }
    $posts = $prismic->form()->query(Predicates::at('document.type', 'post'))->fetchLinks('post.date', 'category.name', 'author.full_name', 'author.first_name', 'author.surname', 'author.company')->page(current_page($app))->orderings('[my.post.date desc]')->submit();
    $skin = $prismic->get_skin();
    render($app, 'bloghome', array('bloghome' => $blogHome, 'posts' => $posts, 'skin' => $skin));
});
// Archive
$app->get('/archive/:year(/:month(/:day))', function ($year, $month = null, $day = null) use($app, $prismic) {
    global $WPGLOBAL;
    $posts = $prismic->archives(array('year' => $year, 'month' => $month, 'day' => $day), current_page($app));
    $date = array('year' => $year, 'month' => $month, 'day' => $day);
    $skin = $prismic->get_skin();
    render($app, 'archive', array('posts' => $posts, 'date' => $date, 'skin' => $skin));
});
// Previews
$app->get('/preview', function () use($app, $prismic) {
    $token = $app->request()->params('token');
    $url = $prismic->get_api()->previewSession($token, $prismic->linkResolver, '/');
Esempio n. 4
0
 public function testGeoPoint()
 {
     $json = "{\"id\":\"abcd\",\"type\":\"article\",\"href\":\"\",\"slugs\":[],\"tags\":[],\"data\":{\"article\":{\"location\":{\"type\":\"GeoPoint\",\"value\":{\"latitude\":48.877108,\"longitude\":2.333879}}}}}";
     $doc = Document::parse(json_decode($json));
     // startgist:4a4024327fc8454bc809:prismic-geopoint.php
     // "near" predicate for GeoPoint fragments
     $near = Predicates::near("my.store.location", 48.8768767, 2.3338802, 10);
     // Accessing GeoPoint fragments
     $place = $doc->getGeoPoint("article.location");
     $coordinates = "";
     if ($place) {
         $coordinates = $place->getLatitude() . "," . $place->getLongitude();
     }
     // endgist
     $this->assertEquals("48.877108,2.333879", $coordinates);
 }
Esempio n. 5
0
 public function testImage()
 {
     $api = Api::get("https://lesbonneschoses.cdn.prismic.io/api");
     $documents = $api->forms()->everything->query(Predicates::at("document.id", "UlfoxUnM0wkXYXbO"))->ref($api->master())->submit()->getResults();
     $doc = $documents[0];
     // startgist:c202e1c27ddedf88aa7f:prismic-images.php
     // Accessing image fields
     $image = $doc->getImage("product.image");
     // Most of the time you will be using the "main" view
     $url = $image->getView("main")->getUrl();
     // endgist
     $this->assertEquals("https://d2aw36oac6sa9o.cloudfront.net/lesbonneschoses/f606ad513fcc2a73b909817119b84d6fd0d61a6d.png", $url);
 }
 public function testFetchLinks()
 {
     $api = Api::get(self::$testRepository);
     $masterRef = $api->master()->getRef();
     $documents = $api->forms()->everything->ref($masterRef)->fetchLinks('blog-post.author')->query(Predicates::at('document.id', 'UlfoxUnM0wkXYXbt'))->submit()->getResults();
     $link = $documents[0]->getLink('blog-post.relatedpost[0]');
     $this->assertEquals('John M. Martelle, Fine Pastry Magazine', $link->getText('blog-post.author'));
 }
 /**
  * Return the prismic response containing the documents in the given page
  * @param  int      $page
  * @return Response
  */
 protected function retrieveDocumentsByPage($page)
 {
     $api = $this->getPrismicApi();
     $ref = $this->getContext()->getRef();
     $predicates = array(Predicates::any("document.type", $this->documentTypes));
     $form = $api->forms()->everything->ref($ref)->pageSize($this->pageSize)->page($page)->query($predicates);
     return $form->submit();
 }
Esempio n. 8
0
 public function testGeopointNear()
 {
     $p = Predicates::near("my.store.coordinates", 40.689757, -74.0451453, 15);
     $this->assertEquals("[:d = geopoint.near(my.store.coordinates, 40.689757, -74.0451453, 15)]", $p->q());
 }
Esempio n. 9
0
 public function get_all_pages()
 {
     if ($this->allPages == null) {
         $has_more = true;
         $this->allPages = array();
         $p = 0;
         while ($has_more) {
             $response = $this->form(20)->query(Predicates::any('document.type', array('page', 'bloghome')))->page($p++)->submit();
             foreach ($response->getResults() as $page) {
                 $this->allPages[$page->getId()] = $page;
             }
             $has_more = $response->getNextPage() != null;
         }
     }
     return $this->allPages;
 }
Esempio n. 10
0
 public function getDocumentByUidAndMask($uid, $mask)
 {
     if (!isset($this->byUidAndMask[$mask])) {
         $this->byUidAndMask[$mask] = array();
     }
     if (isset($this->byUidAndMask[$mask][$uid])) {
         return $this->byUidAndMask[$mask][$uid];
     }
     $query = [Predicates::at("document.type", $mask), Predicates::at("my.{$mask}.uid", $uid)];
     $api = $this->getPrismicApi();
     $documents = $api->forms()->everything->query($query)->ref($this->getRefAsString())->submit();
     if (count($documents->getResults())) {
         // There should be only one!
         $this->byUidAndMask[$mask][$uid] = current($documents->getResults());
         return $this->byUidAndMask[$mask][$uid];
     }
     return null;
 }
Esempio n. 11
0
 /**
  * Return a set of document from their ids
  *
  * @param array   $ids          array of strings, the requested ids
  *
  * @return \Prismic\Response   the response, including documents and pagination information
  */
 public function getByIDs($ids)
 {
     return $this->query(Predicates::in("document.id", $ids));
 }