Esempio n. 1
0
<?php

use Katanium\Models\Post;
$app->get('/write', $registered(), function () use($app) {
    $session['key'] = $app->config->get('auth.session');
    $session['value'] = $_SESSION[$app->config->get('auth.session')];
    $app->view()->appendData(['write' => true, 'session' => $session]);
    $app->render('write.twig');
})->name('write');
// Create the post!
$app->post('/write', $registered(), function () use($app) {
    // Add custom functions!
    require_once 'app/functions/slugify.php';
    $req = $app->req;
    $user_id = $_SESSION[$app->config->get('auth.session')];
    $post = new Post();
    $post->title = $req->title;
    $post->content = $req->content;
    $post->content_text = $req->content_text;
    $post->author = $user_id;
    $post->slug = slugify($req->title);
    $post->status = 'published';
    if (isset($_FILES['file'])) {
        // Upload photo first
        $storage = new \Upload\Storage\FileSystem($_SERVER['DOCUMENT_ROOT'] . '/user-uploads/' . $user_id);
        $file = new \Upload\File('file', $storage);
        // Optionally you can rename the file on upload
        $new_filename = uniqid();
        $file->setName($new_filename);
        // Validate file upload
        // MimeType List => http://www.iana.org/assignments/media-types/media-types.xhtml
Esempio n. 2
0
     }
     require_once 'app/functions/slugify.php';
     $post->title = $req->title;
     $post->slug = slugify($req->title);
     $post->content = $req->content;
     $post->author = $user_id;
     // Yang gambar beloman, nanti aja ya..
 })->setName('post.edit');
 /**
  * DELETE POST
  * delete a single post, can only be done by registered users only
  *
  * @param [int] post ID
  */
 $app->delete('/:postID/delete', $registered(), function ($req, $res, $args = []) {
     $post = Post::find($postID);
     if (!$post) {
         // No post, display 404
         return $app->notFound();
     }
     if ($post->author !== $_SESSION[$app->config->get('auth.session')]) {
         // Check if the post is his own
         throw new \Exception('Oops! You don\'t have access to other\'s post');
     }
     $post->delete();
 })->setName('post.delete');
 /**
  * COMMENT
  * comment system, how the app handle comments inputted by other users
  *
  * @param post ID