This repository has been archived by the owner on May 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
prismic-levi
committed
Nov 2, 2016
0 parents
commit 6124801
Showing
31 changed files
with
3,240 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.DS_Store | ||
vendor | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
language: php | ||
|
||
php: | ||
- 5.5 | ||
- 5.6 | ||
|
||
before_script: | ||
- chmod +x ./tests/install-apcu.sh | ||
- ./tests/install-apcu.sh | ||
- phpenv config-add tests/$TRAVIS_PHP_VERSION.ini | ||
- phpenv config-add tests/apc.ini | ||
- composer self-update | ||
- composer install | ||
|
||
script: phpunit | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: vendor/bin/heroku-php-apache2 public |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
## Sample Blog with API-based CMS | ||
|
||
This is a sample blog template in PHP with content managed in prismic.io (an API-based CMS). | ||
|
||
#### Getting started | ||
|
||
Read [this guide](https://prismic.io/docs/examples/blog#?lang=php) for instructions to create your repository and use the sample blog. | ||
|
||
#### Deploy your PHP blog | ||
|
||
An easy way to deploy your blog is to use [Heroku](http://www.heroku.com). Just follow these few simple steps once you have successfully [signed up](https://id.heroku.com/signup/www-header) and [installed the Heroku toolbelt](https://toolbelt.heroku.com/): | ||
|
||
Create a new Heroku application | ||
|
||
``` | ||
$ heroku create | ||
``` | ||
|
||
Initialize a new Git repository: | ||
|
||
``` | ||
$ git init | ||
$ heroku git:remote -a your-heroku-app-name | ||
``` | ||
|
||
Commit your code to the Git repository and deploy it to Heroku: | ||
|
||
``` | ||
$ git add . | ||
$ git commit -am "make it better" | ||
$ git push heroku master | ||
``` | ||
|
||
Ensure you have at least one node running: | ||
|
||
``` | ||
$ heroku ps:scale web=1 | ||
``` | ||
|
||
You can now browse your application online: | ||
|
||
``` | ||
$ heroku open | ||
``` | ||
|
||
### Licence | ||
|
||
This software is licensed under the Apache 2 license, quoted below. | ||
|
||
Copyright 2013 Zengularity (http://www.zengularity.com). | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this project except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. | ||
|
||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
use Prismic\LinkResolver; | ||
|
||
/** | ||
* The link resolver is the code building URLs for pages corresponding to | ||
* a Prismic document. | ||
* | ||
* If you want to change the URLs of your site, you need to update this class | ||
* as well as the routes in app.php. | ||
*/ | ||
class PrismicLinkResolver extends LinkResolver | ||
{ | ||
private $prismic; | ||
|
||
public function __construct($prismic) | ||
{ | ||
$this->prismic = $prismic; | ||
} | ||
|
||
public function resolve($link) | ||
{ | ||
// Post custom type | ||
if ($link->getType() == 'post') { | ||
return '/blog/' . $link->getUid(); | ||
} | ||
|
||
// Default case returns the homepage | ||
return '/'; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
/* | ||
* This is the main file of the application, including routing and controllers. | ||
* | ||
* $app is a Slim application instance, see the framework documentation for more details: | ||
* http://docs.slimframework.com/ | ||
* | ||
* The order of the routes matter, as it will define the priority of routes. For that reason we | ||
* need to keep the more "generic" routes, such as the pages route, at the end of the file. | ||
* | ||
* If you decide to change the URLs, make sure to change PrismicLinkResolver in LinkResolver.php | ||
* as well to make sures links in your site are correctly generated. | ||
*/ | ||
|
||
use Prismic\Api; | ||
use Prismic\LinkResolver; | ||
use Prismic\Predicates; | ||
|
||
require_once 'includes/http.php'; | ||
|
||
// Index page | ||
$app->get('/{route:|blog|blog/}', function ($request, $response) use ($app, $prismic) { | ||
|
||
// Query the API for the homepage content and all the posts | ||
$api = $prismic->get_api(); | ||
$bloghomeContent = $api->getSingle('bloghome'); | ||
$posts = $api->query(Predicates::at("document.type", "post")); | ||
|
||
// If there is no bloghome content, display 404 page | ||
if ( $bloghomeContent == null ) { | ||
not_found($app); | ||
return; | ||
} | ||
|
||
// Render the homepage | ||
render($app, 'bloghome', array('bloghome' => $bloghomeContent, 'posts' => $posts->getResults())); | ||
|
||
}); | ||
|
||
|
||
// Previews | ||
$app->get('/{route:preview|preview/}', function ($request, $response) use ($app, $prismic) { | ||
$token = $request->getParam('token'); | ||
$url = $prismic->get_api()->previewSession($token, $prismic->linkResolver, '/'); | ||
setcookie(Prismic\PREVIEW_COOKIE, $token, time() + 1800, '/', null, false, false); | ||
return $response->withStatus(302)->withHeader('Location', $url); | ||
}); | ||
|
||
|
||
// Pages by UID | ||
$app->get('/blog/{uid}', function ($request, $response, $args) use ($app, $prismic) { | ||
|
||
// Retrieve the uid from the url | ||
$uid = $args['uid']; | ||
|
||
// Query the API by the uid | ||
$api = $prismic->get_api(); | ||
$post = $api->getByUID('post', $uid); | ||
|
||
// If there is no post content, display the 404 page | ||
if (!$post) { | ||
not_found($app); | ||
return; | ||
} | ||
|
||
// Render the post page | ||
render($app, 'post', array('post' => $post)); | ||
}); | ||
|
||
|
||
// Display the 404 page for any other url | ||
$app->get('/{uid}', function ($request, $response, $args) use ($app, $prismic) { | ||
render($app, '404'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
use Prismic\Api; | ||
use Prismic\Predicates; | ||
|
||
/** | ||
* This class contains helpers for the Prismic API. | ||
*/ | ||
class PrismicHelper | ||
{ | ||
private $app; | ||
public $linkResolver; | ||
|
||
public function __construct($app) | ||
{ | ||
$this->app = $app; | ||
$this->linkResolver = new PrismicLinkResolver($this); | ||
} | ||
|
||
private $api = null; | ||
|
||
public function get_api() | ||
{ | ||
$container = $this->app->getContainer(); | ||
$url = $container->get('settings')['prismic.url']; | ||
$token = $container->get('settings')['prismic.token']; | ||
if ($this->api == null) { | ||
$this->api = Api::get($url, $token); | ||
} | ||
|
||
return $this->api; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
function views_dir() | ||
{ | ||
return __DIR__.'/../views/'; | ||
} | ||
|
||
function render($app, $page, $data = array()) | ||
{ | ||
global $WPGLOBAL; | ||
|
||
foreach ($data as $key => $value) { | ||
$WPGLOBAL[$key] = $value; | ||
} | ||
|
||
$file_path = views_dir().'/'.$page.'.php'; | ||
if (file_exists($file_path)) { | ||
require $file_path; | ||
} else { | ||
not_found($app); | ||
} | ||
} | ||
|
||
function not_found($app) | ||
{ | ||
$file_path = views_dir().'/404.php'; | ||
if (file_exists($file_path)) { // Avoid an infinite loop | ||
render($app, '404'); | ||
} else { | ||
echo '<h1>404 Not found</h1>'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta content="text/html; Charset=UTF-8" http-equiv="Content-Type" /> | ||
<title>TODO</title> | ||
<link rel="stylesheet" href="/stylesheets/reset.css"> | ||
<link rel="stylesheet" href="/stylesheets/common.css"> | ||
<link rel="stylesheet" href="/stylesheets/blog.css"> | ||
<link href="https://fonts.googleapis.com/css?family=Lato:300,400,700,900" rel="stylesheet" type="text/css"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="icon" type="image/png" href="/images/punch.png" /> | ||
</head> | ||
<body> | ||
<div class="home"> | ||
<h1>You're almost there!</h1> | ||
<p>Follow the instructions on the <a href="https://prismic.io/docs/examples/blog#?lang=php" target="_blank" style="text-decoration: underline;">example blog page</a> to get started</p> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta content="text/html; Charset=UTF-8" http-equiv="Content-Type" /> | ||
<title>Sample Blog</title> | ||
<link rel="stylesheet" href="/stylesheets/reset.css"> | ||
<link rel="stylesheet" href="/stylesheets/common.css"> | ||
<link rel="stylesheet" href="/stylesheets/blog.css"> | ||
<link href="https://fonts.googleapis.com/css?family=Lato:300,400,700,900" rel="stylesheet" type="text/css"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="icon" type="image/png" href="/images/punch.png" /> | ||
</head> | ||
<body> | ||
<div class="blog-main"> | ||
<h1>Page not found</h1> | ||
<p>Sorry we were unable to find the page you are looking for.</p> | ||
<p><a href="/" style="text-decoration: underline;">Return to home</a></p> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
$prismic = $WPGLOBAL['prismic']; | ||
$bloghome = $WPGLOBAL['bloghome']; | ||
$posts = $WPGLOBAL['posts']; | ||
|
||
$title = $bloghome->getText("bloghome.headline"); | ||
$isBloghome = true; | ||
|
||
$imageUrl = $bloghome->getImage('bloghome.image') ? $bloghome->getImage('bloghome.image')->getUrl() : ''; | ||
|
||
?> | ||
|
||
<?php include 'header.php'; ?> | ||
|
||
<div class="home"> | ||
<div class='blog-avatar' style='background-image: url("<?= $imageUrl ?>");'></div> | ||
<h1 class='blog-title'><?= $title ?></h1> | ||
<p class='blog-description'><?= $bloghome->getText('bloghome.description') ?></p> | ||
</div> | ||
|
||
<div class="blog-main"> | ||
<?php foreach ($posts as $post) { ?> | ||
|
||
<div class="blog-post" data-wio-id=<?= $post->getId() ?>> | ||
<h2> | ||
<a href="<?= $prismic->linkResolver->resolve($post) ?>"><?= $post->getText('post.title') ?></a> | ||
</h2> | ||
|
||
<p class="blog-post-meta"> | ||
<span class="created-at"><?= $post->getDate("post.date") ? $post->getDate("post.date")->formatted('M d Y') : "" ?></span> | ||
</p> | ||
|
||
<?php include 'slices/firstParagraph.php'; ?> | ||
|
||
</div> | ||
<?php } ?> | ||
</div> | ||
|
||
<?php include 'footer.php'; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<footer> | ||
<p> | ||
Proudly published with <a href="https://prismic.io" target="_blank">prismic.io</a> | ||
<br/> | ||
<a href="https://prismic.io" target="_blank"><img class="footer-logo" src="/images/logo-prismic.svg"/></a> | ||
</p> | ||
</footer> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
if (!isset($title)) { | ||
$title = SITE_TITLE; | ||
} | ||
if (!isset($description)) { | ||
$description = SITE_DESCRIPTION; | ||
} | ||
if (!isset($isBloghome)) { | ||
$isBloghome = false; | ||
} | ||
|
||
?> | ||
|
||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta content="text/html; Charset=UTF-8" http-equiv="Content-Type" /> | ||
<title><?= $title ?></title> | ||
<meta name="description" content="<?= $description; ?>"> | ||
<link rel="stylesheet" href="/stylesheets/reset.css"> | ||
<link rel="stylesheet" href="/stylesheets/common.css"> | ||
<link rel="stylesheet" href="/stylesheets/blog.css"> | ||
<link href="https://fonts.googleapis.com/css?family=Lato:300,400,700,900" rel="stylesheet" type="text/css"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="icon" type="image/png" href="/images/punch.png" /> | ||
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script> | ||
<? /* Required for previews and experiments */ ?> | ||
<script> | ||
window.prismic = { | ||
endpoint: '<?= PRISMIC_URL ?>' | ||
}; | ||
</script> | ||
<script src="//static.cdn.prismic.io/prismic.js"></script> | ||
</head> | ||
<body class="<?= $isBloghome ? "page" : "" ?>"> |
Oops, something went wrong.