Example #1
0
 public function create($f3, $param)
 {
     $table = $param['table'];
     $db_table_name = MyConst::$tables[$table];
     if ($this->f3->exists('POST.addArticle')) {
         if (isset($_POST['description'])) {
             //$_POST['description'] = str_replace(array('.', ' ', "\n", "\t", "\r"), '', $_POST['description'] );
             $_POST['description'] = str_replace(array("\n", "\t", "\r"), '', $_POST['description']);
         }
         $article = new Article($this->db, $db_table_name, MyConst::$cols[$table]);
         $article->add();
         $id = $article->id;
         $this->f3->set('POST.id', $id);
         $this->f3->set('VIEWTABLE', $param['table']);
         $this->updateAttachment($db_table_name);
         $this->f3->reroute('/list/' . $table);
     } else {
         $this->f3->set('view', 'articles/list.html');
         echo Template::instance()->render('layout.htm');
     }
 }
Example #2
0
File: post.php Project: bsamel/bavn
<?php

session_start();
if (!isset($_SESSION['login'])) {
    header('location: accueil.php');
} else {
    if (!empty($_FILES['picture']) && !($_FILES['picture']['error'] > 0) || empty($_FILES['picture']['name'])) {
        include_once './class/ManagerMember.php';
        include_once './class/Article.php';
        $pseudo_receiver = $_POST['where'];
        $id_receiver = ManagerMember::get_member($pseudo_receiver)['ID'];
        $title = $_POST['article_title'];
        $content = $_POST['my_article'];
        $id_author = ManagerMember::get_member($_SESSION['login'])['ID'];
        if (!empty($_FILES['picture']['name'])) {
            echo 'ici';
            $new_article = new Article($title, $content, $id_receiver, $id_author, 1, 0, 0, 0);
            $new_article->add();
            move_uploaded_file($_FILES['picture']['tmp_name'], "./articles/pictures/" . $new_article->get_id());
        } else {
            echo 'la';
            $new_article = new Article($title, $content, $id_receiver, $id_author, 0, 0, 0, 0);
            $new_article->add();
        }
        unset($new_article);
        header('location: ./users/' . $pseudo_receiver . '.php');
        //redirection vers le mur où on a posté l'article
    }
}
Example #3
0
        $user_name = $_COOKIE['login'];
        return $app->render('posts_input.html', array('action_name' => 'Add', 'action_url' => '/newtest/posts/add', 'isLoginned' => $isLoginned, 'User_name' => $user_name));
    } else {
        return $app->redirect('/newtest/feed');
    }
});
// Posts Add - POST.
$app->post('/posts/add', function () use($app) {
    $isLoginned = User::isLoginned();
    if ($isLoginned) {
        $title = $app->request()->post('title');
        $author = $_COOKIE['login'];
        $summary = $app->request()->post('summary');
        $content = $app->request()->post('content');
        $timestamp = date('Y-m-d H:i:s');
        Article::add($title, $author, $summary, $content, $timestamp);
    }
    $app->redirect('/newtest');
});
// Posts Delete.
$app->get('/posts/delete/(:id)', function ($id) use($app) {
    $isLoginned = User::isLoginned();
    if ($isLoginned) {
        $article = Model::factory('Article')->find_one($id);
        if ($article->author == $_COOKIE['login']) {
            if ($article instanceof Article) {
                $article->delete();
            }
        }
        return $app->redirect('/newtest/user/' . $_COOKIE['login']);
    }