示例#1
0
<?php

include '../inc/header.php';
writePosts('txt', 3, NULL, NULL);
include '../inc/footer.php';
示例#2
0
<?php

require 'vendor/autoload.php';
$posts = array();
$postDir = __DIR__ . '/views/posts/';
foreach (scandir($postDir) as $filename) {
    $post = parsePost($postDir, $filename);
    if ($post != null) {
        $posts[$post->posted->timestamp] = $post;
    }
}
ksort($posts);
writePosts($posts, __DIR__ . '/posts.php');
function parsePost($dir, $filename)
{
    $posts = array();
    if (preg_match('/^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})-(.+)\\.php$/', $filename, $matches) === 1) {
        $posted = \Carbon\Carbon::create($matches[1], $matches[2], $matches[3], 12);
        $slug = $matches[4];
        $title = getPostTitle($dir . $filename);
        if (strlen($title) > 0) {
            return new Post($title, $slug, $posted);
        }
    }
    return null;
}
function getPostTitle($file)
{
    $lines = file($file);
    if (preg_match('@^\\<\\?\\/\\*(.+)\\*\\/\\?\\>$@', trim($lines[0]), $matches) === 1) {
        return $matches[1];
示例#3
0
<?php

$url_base = "https://api.tumblr.com/v2/blog/";
$blog_url = "staff.tumblr.com";
$api_key = "";
$post_num = 10;
$full_url = $url_base . $blog_url . "/posts/?api_key=" . $api_key . "&limit=" . $post_num;
$json_str = file_get_contents($full_url);
$json = json_decode($json_str, false, 100);
writePosts($json->response->posts);
function writePosts($posts)
{
    foreach ($posts as &$post) {
        echo writeBasePost($post);
    }
    //TODO add a "see more at my blog" button at the bottom
}
function writeBasePost($post)
{
    // should make a basic html div with a title span containing post title that links to the tumblr post and a div to contain the content
    $body = "<div class=\"tumblr-content\">";
    if ($post->type === "text") {
        $body = $body . writeTextPost($post);
    } else {
        if ($post->type === "photo") {
            $body = $body . writePhotoPost($post);
        } else {
            if ($post->type === "quote") {
                $body = $body . writeQuotePost($post);
            } else {
                if ($post->type === "link") {
示例#4
0
<?php

include '../inc/header.php';
?>
<header class="col-2-3 center"><a href="/blog/" class="icon icon-logo-both"><h2 class="subheading">Comments On Code</h2></a></header>
<?php 
writePosts('txt', 5, true, true);
include '../inc/footer.php';