Beispiel #1
0
<?php

$app->get('/', function ($format = 'html') use($app) {
    $res = $app->response();
    if (!is_logged_in()) {
        $html = render('index-public', array('title' => 'Monocle', 'meta' => ''));
        $res->body($html);
    } else {
        $channels = db\get_user_channels($_SESSION['user_id']);
        $main_channel = ORM::for_table('channels')->where('user_id', $_SESSION['user_id'])->where('type', 'default')->find_one();
        $entries = db\get_entries_for_channel($main_channel->id);
        $html = render('channel', array('title' => 'Monocle', 'meta' => '', 'channel' => $main_channel, 'channels' => $channels, 'entries' => $entries));
        $res->body($html);
    }
});
$app->get('/docs/?', function ($format = 'html') use($app) {
    $res = $app->response();
    $html = render('docs', array('title' => 'Docs', 'meta' => ''));
    $res->body($html);
});
$app->get('/preview', function () use($app) {
    $params = $app->request()->params();
    $res = $app->response();
    $entry = ORM::for_table('entries')->where('url', $params['url'])->find_one();
    $html = render('preview-entry', ['title' => 'Preview', 'entry' => $entry]);
    $res->body($html);
});
Beispiel #2
0
        foreach ($channels as $ch) {
            $ch['sources'] = ORM::for_table('channel_sources')->join('feeds', ['channel_sources.feed_id', '=', 'feeds.id'])->where('channel_id', $ch['id'])->count();
        }
        $html = render('channels', ['title' => 'Channels', 'meta' => '', 'channels' => $channels]);
        $res->body($html);
    }
});
$app->get('/channel/:id', function ($id) use($app) {
    if ($user = require_login($app)) {
        $params = $app->request()->params();
        $res = $app->response();
        $channel = db\get_channel(user_id(), $id);
        if (!$channel) {
            $app->notFound();
        }
        $channels = db\get_user_channels(user_id());
        $entries = db\get_entries_for_channel($channel->id);
        $html = render('channel', ['title' => 'Channel', 'meta' => '', 'channel' => $channel, 'channels' => $channels, 'entries' => $entries]);
        $res->body($html);
    }
});
$app->post('/channels/new', function () use($app) {
    if ($user = require_login_json($app)) {
        $params = $app->request()->params();
        $channel = ORM::for_table('channels')->create();
        $channel->user_id = user_id();
        $channel->name = $params['name'];
        $channel->date_created = date('Y-m-d H:i:s');
        $channel->type = 'feeds';
        $channel->save();
        json_response($app, ['result' => 'ok']);