Exemplo n.º 1
0
function posts_to_json(array $posts)
{
    $out = array();
    foreach ($posts as $p_in) {
        $out[] = post_to_json($p_in);
    }
    return $out;
}
Exemplo n.º 2
0
    exit(json_encode(array('error' => 'Nibbleblog: Error key for sync')));
}
// Prevent flood requests
// $_DB_USERS->set_blacklist();
if ($url['other'] == 'status') {
    $posts = $_DB_POST->get_list_by_page(array('page' => 0, 'amount' => $POSTS_TO_SYNC));
    $posts = array_reverse($posts);
    $tmp = array('posts' => array(), 'mark' => $mark);
    foreach ($posts as $post) {
        $time = max($post['pub_date_unix'], $post['mod_date_unix']);
        $sync = array();
        $sync['id'] = $post['id'];
        $sync['time'] = $time;
        $sync['hash'] = Crypt::get_hash(json_encode($post));
        $sync['post'] = post_to_json($post, false);
        array_push($tmp['posts'], $sync);
    }
    echo json_encode($tmp);
} elseif ($url['other'] == 'post') {
    // Get the post
    $post = $_DB_POST->get(array('id' => $url['id_post']));
    // Post to Json
    echo post_to_json($post);
} elseif ($url['other'] == 'latest') {
    $list = $_DB_POST->get_list_by_page(array('page' => 0, 'amount' => 5));
    $tmp = array();
    foreach ($list as $post) {
        array_push($tmp, post_to_json($post, false));
    }
    echo json_encode($tmp);
}