/**
  * Show a list of all the blog posts.
  *
  * @return View
  */
 public function index()
 {
     // Title
     $title = Lang::get('admin.blogs.title.blog_management');
     // Grab all the blog posts
     $posts = $this->blogRepository->getAll();
     // Show the page
     $this->render('admin.blogs.index', compact('posts', 'title'));
 }
Example #2
0
 public function showAllPosts()
 {
     $post = new Post();
     $posts = $post->getAll();
     $view = new PostView();
     $view->renderPosts($posts);
 }
 public function controlerJob($maincont)
 {
     // récupération des données
     if (!$maincont->isLoggued()) {
         $maincont->goModule("home", "display");
     }
     // récupération de tous les tags pour le nuage
     $at = Tag::getAll();
     $alltags = array();
     foreach ($at as $ta) {
         $alltags[] = $ta->getTag();
     }
     // récupération des années
     $ay = Post::getAll();
     $allyears = array();
     foreach ($ay as $ye) {
         $couranty = explode("-", $ye->getDate());
         $couranty = $couranty[0];
         if (!in_array($couranty, $allyears)) {
             $allyears[] = $couranty;
         }
     }
     // login
     if ($maincont->isLoggued()) {
         $login = $_SESSION["login"];
     } else {
         $login = "******";
     }
     // edition d'un article existant
     if (isset($_GET['id']) && $_GET['id'] >= 0) {
         $id = $_GET['id'];
         $mode = "update";
         $title = "Edition d'un article";
         $post = Post::getById($id);
         $post = $post[0];
         // récupération des tags
         $tags = array();
         if ($mode == "update") {
             $listTag = $post->getTags();
             for ($i = 0; $i < count($post->getTags()); $i++) {
                 $t = Tag::getById($listTag[$i]->id);
                 $tags[$i] = $t[0]->getTag();
             }
         }
         $posttitle = $post->getTitle();
         $postbody = $post->getBody();
     } else {
         $id = "-1";
         $mode = "create";
         $title = "Création d'un article";
         $tags = array("tag1", "tag2", "tag3");
         $posttitle = "Votre titre";
         $postbody = "Votre contenu";
     }
     // affichage de la vue édition
     include_once "view.php";
     $v = new PostEditorView();
     $v->display($login, $alltags, $allyears, $posttitle, $postbody, $tags, $mode, $title, $id);
 }
 public function controlerJob($maincont)
 {
     // récupération des données
     if (isset($_GET['id']) && $_GET['id'] >= 0) {
         $id = $_GET['id'];
     } else {
         $maincont->goModule('home', 'display');
         return;
     }
     $post = Post::getById($id);
     $post = $post[0];
     $tags = array();
     $listTag = $post->getTags();
     for ($i = 0; $i < count($post->getTags()); $i++) {
         $t = Tag::getById($listTag[$i]->id);
         $tags[$i] = $t[0]->getTag();
     }
     $comments = $post->getComments();
     $coms = array();
     $i = 0;
     foreach ($comments as $c) {
         if ($c->getPublished() != 0) {
             $coms[$i] = array('author' => $c->getAuthor(), 'date' => $c->getDate() . " " . $c->getHour(), 'content' => $c->getBody());
             $i++;
         }
     }
     // récupération de tous les tags pour le nuage
     $at = Tag::getAll();
     $alltags = array();
     foreach ($at as $ta) {
         $alltags[] = $ta->getTag();
     }
     // récupération des années
     $ay = Post::getAll();
     $allyears = array();
     foreach ($ay as $ye) {
         $couranty = explode("-", $ye->getDate());
         $couranty = $couranty[0];
         if (!in_array($couranty, $allyears)) {
             $allyears[] = $couranty;
         }
     }
     // login
     if ($maincont->isLoggued()) {
         $login = $_SESSION["login"];
     } else {
         $login = "******";
     }
     // affichage de la vue
     include_once "view.php";
     $v = new PostViewView();
     $v->display($login, $alltags, $allyears, $post->getTitle(), $post->getDate(), $post->getBody(), $tags, $coms, $_GET["id"]);
 }
 public function controlerJob($maincont)
 {
     // récupération des données
     if (!$maincont->isLoggued()) {
         $maincont->goModule("home", "display");
     }
     $liste = Comment::getByPublished("0");
     // on récupère les commentaires non validés
     // récupération des données des commentaires
     $coms = array();
     for ($i = 0; $i < count($liste); $i++) {
         $c = Comment::getById($liste[$i]->id);
         $c = $c[0];
         /*$coms[$i] = array('date'=>"Le ".$c->getDate()." à ".$c->getHour(),
         		 'author'=>$c->getAuthor(),
         		 'content'=>$c->getBody(),
         			 'postitle'=>''.$c->getPost()->getTitle()
         		);*/
         $coms[$i] = array("contenu" => "De : " . $c->getAuthor() . ", contenu : \"" . $c->getBody() . "\", sur l'article : " . $c->getPost()->getTitle(), "id" => $c->id);
     }
     // récupération de tous les tags pour le nuage
     $at = Tag::getAll();
     $alltags = array();
     foreach ($at as $ta) {
         $alltags[] = $ta->getTag();
     }
     // récupération des années
     $ay = Post::getAll();
     $allyears = array();
     foreach ($ay as $ye) {
         $couranty = explode("-", $ye->getDate());
         $couranty = $couranty[0];
         if (!in_array($couranty, $allyears)) {
             $allyears[] = $couranty;
         }
     }
     // login
     if ($maincont->isLoggued()) {
         $login = $_SESSION["login"];
     } else {
         $login = "******";
     }
     // affichage de la vue
     include_once "view.php";
     $v = new CommentAdminView();
     $v->display($login, $alltags, $allyears, $coms);
 }
 public function controlerJob($maincont)
 {
     // récupération des données
     if (!$maincont->isLoggued()) {
         $maincont->goModule("home", "display");
     }
     $liste = Post::getAll();
     // on récupère les posts
     // récupération des données des articles
     $articles = array();
     for ($i = 0; $i < count($liste); $i++) {
         $p = Post::getById($liste[$i]->id);
         $p = $p[0];
         $articles[$i] = array("contenu" => $p->getTitle() . ", publié le " . $p->getDate() . " à " . $p->getHour(), "id" => $p->id);
     }
     // récupération de tous les tags pour le nuage
     $at = Tag::getAll();
     $alltags = array();
     foreach ($at as $ta) {
         $alltags[] = $ta->getTag();
     }
     // récupération des années
     $ay = Post::getAll();
     $allyears = array();
     foreach ($ay as $ye) {
         $couranty = explode("-", $ye->getDate());
         $couranty = $couranty[0];
         if (!in_array($couranty, $allyears)) {
             $allyears[] = $couranty;
         }
     }
     // login
     if ($maincont->isLoggued()) {
         $login = $_SESSION["login"];
     } else {
         $login = "******";
     }
     // affichage de la vue
     include_once "view.php";
     $v = new PostAdminView();
     $v->display($login, $alltags, $allyears, $articles);
 }
Example #7
0
 public function find($string = "")
 {
     if (!is_dir('index')) {
         throw new Exception("No search index.");
     }
     $index = scandir('index');
     $hits = array();
     foreach ($index as $pif) {
         if ($pif != '.' and $pif != '..') {
             $content = file_get_contents("index/" . $pif);
             $string = strtolower($string);
             if (preg_match("/{$string}/", $content)) {
                 $hits[] = $pif;
             }
         }
     }
     if (empty($hits)) {
         return false;
     }
     $hits = Post::getAll($hits);
     return $hits;
 }
Example #8
0
 public static function _list()
 {
     $warning = "";
     if (isset($_POST['delete_post'])) {
         ///check if a user is logged in and if the logged in user is the one that wrote the blog post
         if (isset($_SESSION['user_id']) && $_SESSION['user_id'] == $_POST['user_id']) {
             Post::destroy($_POST['id']);
         } else {
             $warning = 'Sorry, you do not have permissions to delete that post';
         }
     }
     if (isset($_POST['update_post'])) {
         ///check if a user is logged in and if the logged in user is the one that wrote the blog post
         if (isset($_SESSION['user_id']) && $_SESSION['user_id'] == $_POST['user_id']) {
             Post::edit($_POST, $_POST['id']);
         } else {
             $warning = 'Sorry, you do not have permissions to edit that post';
         }
     }
     if (isset($_POST['create_post'])) {
         ///check if a user is logged in
         if (isset($_SESSION['user_id'])) {
             $_POST['user_id'] = $_SESSION['user_id'];
             Post::create($_POST);
         } else {
             $warning = 'Sorry, you must be logged in to submit a post';
         }
     }
     $posts_array = Post::getAll();
     if ($posts_array) {
         foreach ($posts_array as $post) {
             $blogger = Blogger::getOne($post['user_id']);
             $post['username'] = $blogger['username'];
         }
     }
     return array('posts' => $posts_array, 'warning' => $warning);
 }
Example #9
0
 function getPage()
 {
     //Create instances
     $language = new Language();
     $template = new Template();
     $post = new Post();
     $user = new User();
     //getAvailableLanguages
     $availableLanguages = $language->getAvailableLanguages();
     //getAvailableTemplates
     $availableTemplates = $template->getAvailableTemplates();
     //Get requestedLanguage & requestedTemplate
     $urlParts = explode('/', $_GET['__cap']);
     //Set requestedLanguage
     if (!isset($urlParts[2]) || $urlParts[2] === 'index.php' || $urlParts[2] === '') {
         //Get browserLanguage
         $browserLanguage = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
         if (in_array($browserLanguage, $availableLanguages, true)) {
             header('Location: ' . PROTOCOL . '://' . $_SERVER['HTTP_HOST'] . PATH_OFFSET . '/' . $browserLanguage);
         } else {
             header('Location: ' . PROTOCOL . '://' . $_SERVER['HTTP_HOST'] . PATH_OFFSET . '/' . $availableLanguages[0]);
         }
     } else {
         if (in_array($urlParts[2], $availableLanguages, true)) {
             $requestedLanguage = $urlParts[2];
         } else {
             header('Location: ' . PROTOCOL . '://' . $_SERVER['HTTP_HOST'] . PATH_OFFSET . '/' . $availableLanguages[0]);
         }
     }
     //Set default site
     $defaultSite = 'Location: ' . PROTOCOL . '://' . $_SERVER['HTTP_HOST'] . PATH_OFFSET . '/' . $requestedLanguage . '/' . $availableTemplates[0];
     //Set requestedTemplate
     if (isset($urlParts[3])) {
         if (in_array($urlParts[3], $availableTemplates, true)) {
             $requestedTemplate = $urlParts[3];
         } else {
             header($defaultSite);
         }
     } else {
         header($defaultSite);
     }
     //Set requestedParameter
     if (isset($urlParts[4])) {
         $requestedParameter = $urlParts[4];
     }
     //getLanguageArray by requestedLanguage
     $languageArray = $language->getLanguageArray($requestedLanguage);
     //getTemplate by requestedTemplate
     $page = $template->getTemplate($requestedTemplate);
     switch ($requestedTemplate) {
         case 'Admin':
             Bloggy::checkSessionRedirect($defaultSite);
             Bloggy::checkAdminRedirect($defaultSite);
             $contentAccounts = null;
             $users = $user->getAll();
             foreach ($users as $key => $value) {
                 $entry = file_get_contents(DOCUMENT_ROOT . '/template/account_entry.html');
                 $entry = str_replace('{ACCOUNT_DELETE_HREF}', 'DoDeleteAccount/' . $value['id'], $entry);
                 $entry = str_replace('{TXT_ACCOUNT_NAME}', $value['name'], $entry);
                 $entry = str_replace('{TXT_ACCOUNT_ISADMIN}', $value['isAdmin'], $entry);
                 $contentAccounts = $contentAccounts . $entry;
             }
             $page = str_replace('{ACCOUNT_ENTRIES}', $contentAccounts, $page);
             $contentPosts = null;
             $posts = $post->getAll();
             foreach ($posts as $key => $value) {
                 $entry = file_get_contents(DOCUMENT_ROOT . '/template/posts_entry.html');
                 $entry = str_replace('{POSTS_EDIT_HREF}', 'Edit/' . $value['id'], $entry);
                 $entry = str_replace('{POSTS_LINK_HREF}', 'Detail/' . $value['id'], $entry);
                 $entry = str_replace('{POSTS_DELETE_HREF}', 'DoDeletePost/' . $value['id'], $entry);
                 $entry = str_replace('{TXT_POSTS_TITLE}', $value['title'], $entry);
                 $entry = str_replace('{TXT_POSTS_SUBTITLE}', $value['subTitle'], $entry);
                 $entry = str_replace('{TXT_POSTS_MODIFIED}', $value['modifiedDate'], $entry);
                 $contentPosts = $contentPosts . $entry;
             }
             $page = str_replace('{POST_ENTRIES}', $contentPosts, $page);
             break;
         case 'Account':
             Bloggy::checkSessionRedirect($defaultSite);
             $content = null;
             $user = $user->getEntryById($_SESSION['userId']);
             $entry = file_get_contents(DOCUMENT_ROOT . '/template/account_entry.html');
             $entry = str_replace('{ACCOUNT_DELETE_HREF}', 'DoDeleteAccount/' . $user['id'], $entry);
             $entry = str_replace('{TXT_ACCOUNT_NAME}', $user['name'], $entry);
             $entry = str_replace('{TXT_ACCOUNT_ISADMIN}', $user['isAdmin'], $entry);
             $content = $content . $entry;
             $page = str_replace('{ACCOUNT_ENTRIES}', $content, $page);
             break;
         case 'Create':
             Bloggy::checkSessionRedirect($defaultSite);
             break;
         case 'Detail':
             $entry = $post->getEntryById($requestedParameter);
             $page = str_replace('{TXT_POST_IMAGE}', $entry['imagePath'], $page);
             $page = str_replace('{TXT_POST_AUTHOR}', $post->getAuthorNameById($entry['author']), $page);
             $page = str_replace('{TXT_POST_DATE}', $entry['creationDate'], $page);
             $page = str_replace('{TXT_POST_TITLE}', $entry['title'], $page);
             $page = str_replace('{TXT_POST_SUBTITLE}', $entry['subTitle'], $page);
             $page = str_replace('{TXT_POST_CONTENT}', $entry['content'], $page);
             break;
         case 'DoCreatePost':
             Bloggy::checkSessionRedirect($defaultSite);
             if (isset($_POST)) {
                 $request = [];
                 $request['author'] = $_SESSION['userId'];
                 $request['title'] = $_POST['title'];
                 $request['subTitle'] = $_POST['subTitle'];
                 $request['content'] = $_POST['content'];
                 $request['creationDate'] = date('Y-m-d h:i:s');
                 $request['modifiedDate'] = date('Y-m-d h:i:s');
                 $_POST = [];
                 if (isset($_FILES)) {
                     $file = $_FILES['image']['name'];
                     $fileExt = pathinfo($file, PATHINFO_EXTENSION);
                     $tempFile = $_FILES['image']['tmp_name'];
                     $storeFolder = '/data/media/';
                     $existingFiles = scandir($storeFolder, 1);
                     do {
                         $randomString = $post->generateRandomString();
                     } while (in_array($randomString, $existingFiles, false));
                     $targetFile = DOCUMENT_ROOT . $storeFolder . $randomString . '.' . $fileExt;
                     move_uploaded_file($tempFile, $targetFile);
                     $request['image'] = $storeFolder . $randomString . '.' . $fileExt;
                 }
                 $post->createPost($request);
                 header('Location: ' . PROTOCOL . '://' . $_SERVER['HTTP_HOST'] . PATH_OFFSET . '/' . $requestedLanguage . '/' . $availableTemplates[1]);
             }
             break;
         case 'DoDeleteAccount':
             Bloggy::checkSessionRedirect($defaultSite);
             $user->checkIfOwnAccountRedirect($_SESSION['userId'], $requestedParameter, $defaultSite);
             $user->deleteUserById($requestedParameter);
             header('Location: ' . $_SERVER['HTTP_REFERER']);
             break;
         case 'DoDeletePost':
             Bloggy::checkSessionRedirect($defaultSite);
             $post->checkIfOwnPostRedirect($_SESSION['userId'], $requestedParameter, $defaultSite);
             $post->deletePostById($requestedParameter);
             header('Location: ' . $_SERVER['HTTP_REFERER']);
             break;
         case 'DoEditPost':
             Bloggy::checkSessionRedirect($defaultSite);
             $post->checkIfOwnPostRedirect($_SESSION['userId'], $requestedParameter, $defaultSite);
             if (isset($_POST)) {
                 $request = [];
                 $request['id'] = $requestedParameter;
                 $request['title'] = $_POST['title'];
                 $request['subTitle'] = $_POST['subTitle'];
                 $request['content'] = $_POST['content'];
                 $request['modifiedDate'] = date('Y-m-d h:i:s');
                 $_POST = [];
                 $entry = $post->getEntryById($requestedParameter);
                 $file = $_FILES['image']['name'];
                 $fileExt = pathinfo($file, PATHINFO_EXTENSION);
                 $allowedFileExt = ['png', 'jpg', 'jpeg', 'gif'];
                 if (in_array(strtolower($fileExt), $allowedFileExt, true)) {
                     $tempFile = $_FILES['image']['tmp_name'];
                     $storeFolder = '/data/media/';
                     $existingFiles = scandir($storeFolder, 1);
                     do {
                         $randomString = $post->generateRandomString();
                     } while (in_array($randomString, $existingFiles, false));
                     $targetFile = DOCUMENT_ROOT . $storeFolder . $randomString . '.' . $fileExt;
                     move_uploaded_file($tempFile, $targetFile);
                     $request['image'] = $storeFolder . $randomString . '.' . $fileExt;
                     //Unlink (delete) outdated image
                     $unlinkFile = $entry['imagePath'];
                     unlink(DOCUMENT_ROOT . $unlinkFile);
                 } else {
                     $request['image'] = $entry['imagePath'];
                 }
                 $post->editPost($request);
                 header('Location: ' . PROTOCOL . '://' . $_SERVER['HTTP_HOST'] . PATH_OFFSET . '/' . $requestedLanguage . '/' . $availableTemplates[12]);
             }
             break;
         case 'DoLogin':
             if (isset($_POST)) {
                 $id = $user->getIdByName('\'' . $_POST['Username'] . '\'');
                 $hash = $user->getHashById($id);
                 if (password_verify($_POST['Password'], $hash)) {
                     $request = [];
                     $request['username'] = $_POST['Username'];
                     $request['password'] = $_POST['Password'];
                     $_POST = [];
                     $id = $user->getIdByName('\'' . $request['username'] . '\'');
                     $_SESSION['userId'] = $id;
                     $_SESSION['hash'] = $hash;
                     header('Location: ' . PROTOCOL . '://' . $_SERVER['HTTP_HOST'] . PATH_OFFSET . '/' . $requestedLanguage . '/' . $availableTemplates[0]);
                 } else {
                     header('Location: ' . PROTOCOL . '://' . $_SERVER['HTTP_HOST'] . PATH_OFFSET . '/' . $requestedLanguage . '/' . $availableTemplates[3]);
                 }
             } else {
                 header('Location: ' . PROTOCOL . '://' . $_SERVER['HTTP_HOST'] . PATH_OFFSET . '/' . $requestedLanguage . '/' . $availableTemplates[3]);
             }
             break;
         case 'DoSignup':
             if (isset($_POST)) {
                 $id = $user->getIdByName('\'' . $_POST['Username'] . '\'');
                 if ($id === null || $id === '') {
                     $request = [];
                     $request['username'] = $_POST['Username'];
                     $request['password'] = $_POST['Password'];
                     $request['passwordRepeat'] = $_POST['PasswordRepeat'];
                     $_POST = [];
                     $user->createUser($request);
                     $id = $user->getIdByName('\'' . $request['username'] . '\'');
                     $hash = $user->getHashById($id);
                     $_SESSION['userId'] = $id;
                     $_SESSION['hash'] = $hash;
                     header('Location: ' . PROTOCOL . '://' . $_SERVER['HTTP_HOST'] . PATH_OFFSET . '/' . $requestedLanguage . '/' . $availableTemplates[5]);
                 } else {
                     header('Location: ' . PROTOCOL . '://' . $_SERVER['HTTP_HOST'] . PATH_OFFSET . '/' . $requestedLanguage . '/' . $availableTemplates[4]);
                 }
             } else {
                 header('Location: ' . PROTOCOL . '://' . $_SERVER['HTTP_HOST'] . PATH_OFFSET . '/' . $requestedLanguage . '/' . $availableTemplates[3]);
             }
             break;
         case 'Edit':
             Bloggy::checkSessionRedirect($defaultSite);
             $post->checkIfOwnPostRedirect($_SESSION['userId'], $requestedParameter, $defaultSite);
             $entry = $post->getEntryById($requestedParameter);
             $page = str_replace('{TXT_EDIT_ID}', $entry['id'], $page);
             $page = str_replace('{TXT_EDIT_TITLE}', $entry['title'], $page);
             $page = str_replace('{TXT_EDIT_SUBTITLE}', $entry['subTitle'], $page);
             $page = str_replace('{TXT_EDIT_CONTENT}', $entry['content'], $page);
             break;
         case 'Home':
             $content = null;
             $posts = $post->getAll();
             foreach ($posts as $key => $value) {
                 $entry = file_get_contents(DOCUMENT_ROOT . '/template/home_entry.html');
                 $entry = str_replace('{POST_LINK_HREF}', 'Detail/' . $value['id'], $entry);
                 $entry = str_replace('{TXT_POST_TITLE}', $value['title'], $entry);
                 $entry = str_replace('{TXT_POST_SUBTITLE}', $value['subTitle'], $entry);
                 $entry = str_replace('{TXT_POST_AUTHOR}', $post->getAuthorNameById($value['author']), $entry);
                 $entry = str_replace('{TXT_POST_DATE}', $value['creationDate'], $entry);
                 $content = $content . $entry;
             }
             $page = str_replace('{POST_ENTRIES}', $content, $page);
             break;
         case 'Logout':
             session_destroy();
             header($defaultSite);
             break;
         case 'Posts':
             Bloggy::checkSessionRedirect($defaultSite);
             $content = null;
             $posts = $post->getAllByAuthor($_SESSION['userId']);
             foreach ($posts as $key => $value) {
                 $entry = file_get_contents(DOCUMENT_ROOT . '/template/posts_entry.html');
                 $entry = str_replace('{POSTS_EDIT_HREF}', 'Edit/' . $value['id'], $entry);
                 $entry = str_replace('{POSTS_LINK_HREF}', 'Detail/' . $value['id'], $entry);
                 $entry = str_replace('{POSTS_DELETE_HREF}', 'DoDeletePost/' . $value['id'], $entry);
                 $entry = str_replace('{TXT_POSTS_TITLE}', $value['title'], $entry);
                 $entry = str_replace('{TXT_POSTS_SUBTITLE}', $value['subTitle'], $entry);
                 $entry = str_replace('{TXT_POSTS_MODIFIED}', $value['modifiedDate'], $entry);
                 $content = $content . $entry;
             }
             $page = str_replace('{POST_ENTRIES}', $content, $page);
             break;
         default:
     }
     $page = str_replace('{DEFAULT_SITE}', PROTOCOL . '://' . $_SERVER['HTTP_HOST'] . PATH_OFFSET . '/' . $requestedLanguage . '/' . $availableTemplates[0], $page);
     $page = str_replace('{NAVIGATION}', $template->getNavigation(), $page);
     $page = str_replace('{PATH_OFFSET}', PATH_OFFSET, $page);
     $page = str_replace('{LANGUAGE}', $requestedLanguage, $page);
     //Replace placeholder through requestedLanguage
     foreach ($languageArray as $key => $value) {
         $page = str_replace('{' . $key . '}', $value, $page);
     }
     //return page
     echo $page;
 }
Example #10
0
<?php

require_once 'includes/config.inc.php';
$posts = Post::getAll();
require_once VIEW_PATH . 'index.view.php';
Example #11
0
require_once __DIR__ . '/../models/Author.php';
use Symfony\Component\HttpFoundation\Request;
//Symfony2 namespace,
// needed for post requests
$app = new Silex\Application();
// Create the Silex application, in which all
//configuration is going to go
// Section A
$app['debug'] = true;
$app->register(new Silex\Provider\DoctrineServiceProvider(), array('db.options' => array('driver' => 'pdo_mysql', 'host' => 'localhost', 'dbname' => 'starappleblog', 'username' => 'root', 'password' => 'root')));
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
//$twig = new Twig_Environment($loader, array('debug' => true));
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../templates', 'twig.options' => array('cache' => false)));
$app->get('/', function () use($app) {
    $postModel = new Post($app['db']);
    $postsToDisplay = $postModel->getAll();
    return $app['twig']->render('post_index.html.twig', array('posts' => $postsToDisplay));
})->bind('post_index');
// name the route so it can be referred to
$app->get('/post/{post_id}', function ($post_id) use($app) {
    $postModel = new Post($app['db']);
    $postToDisplay = $postModel->get($post_id);
    if (!$postToDisplay) {
        $app->abort(404, 'The article could not be found');
    }
    return $app['twig']->render('post_single.html.twig', array('post' => $postToDisplay));
})->assert('post_id', '\\d+')->bind('post_single');
$app->get('/post/new', function () use($app) {
    $authorModel = new Author($app['db']);
    $authorsToDisplay = $authorModel->getAll();
    return $app['twig']->render('post_new.html.twig', array('authors' => $authorsToDisplay));
Example #12
0
<?php

//获取分享帖子的列表,输入deleted参数值为true时,返回回收站中的帖子,值为false时,返回未删除的帖子
require_once "Post.class.php";
$deleted = $_GET["deleted"];
$post = new Post();
if ($deleted == "true") {
    $result = $post->getTrash();
} else {
    $result = $post->getAll();
}
$post->closeDB();
echo json_encode($result);
Example #13
0
 public function controlerJob($maincont)
 {
     // récupération des données
     // par tags
     if (isset($_GET["tag"])) {
         $t = $_GET["tag"];
         // récupération de l'objet tag
         $thetag = Tag::getByTag("{$t}");
         $thetag = $thetag[0];
         $title = "Liste des posts avec le tag {$t}";
         // récupération de la liste des posts ayant ce tag
         $liste = $thetag->getPosts();
     } else {
         if (isset($_GET["datem"]) && isset($_GET["datey"])) {
             $y = $_GET["datey"];
             $mo = $_GET["datem"];
             // titre
             if ($mo != "-1") {
                 $moenlettre = array("Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre");
                 $moenlettre = $moenlettre[intval($mo) - 1];
                 $title = "Liste des posts de {$moenlettre} {$y}";
             } else {
                 $title = "Liste des posts de {$y}";
             }
             $liste = array();
             $po = Post::getAll();
             foreach ($po as $lol) {
                 $date = $lol->getDate();
                 if ($mo != "-1") {
                     if (substr($date, 0, 7) == "{$y}-{$mo}") {
                         // vérifie que l'article correspond au mois/année
                         $liste[] = $lol;
                     }
                 } else {
                     if (substr($date, 0, 4) == "{$y}") {
                         // vérifie que l'article correspond au mois/année
                         $liste[] = $lol;
                     }
                 }
             }
         } else {
             $title = "Liste des derniers posts";
             $liste = Post::getAllOrderBy("id DESC");
         }
     }
     // récupération des données des articles
     $articles = array();
     for ($i = 0; $i < count($liste); $i++) {
         $p = Post::getById($liste[$i]->id);
         $p = $p[0];
         $articles[$i] = array('date' => "Le " . $p->getDate() . " à " . $p->getHour(), 'title' => $p->getTitle(), 'content' => $p->getBody(), 'nbComments' => $p->getNbComments(), 'link' => 'index.php?module=post&action=view&id=' . $p->id);
     }
     // récupération de tous les tags pour le nuage
     $at = Tag::getAll();
     $alltags = array();
     foreach ($at as $ta) {
         $alltags[] = $ta->getTag();
     }
     // récupération des années
     $ay = Post::getAll();
     $allyears = array();
     foreach ($ay as $ye) {
         $couranty = explode("-", $ye->getDate());
         $couranty = $couranty[0];
         if (!in_array($couranty, $allyears)) {
             $allyears[] = $couranty;
         }
     }
     // login
     if ($maincont->isLoggued()) {
         $login = $_SESSION["login"];
     } else {
         $login = "******";
     }
     // affichage de la vue
     include_once "view.php";
     $v = new HomeDisplayView();
     $v->display($login, $alltags, $allyears, $title, $articles);
 }
Example #14
0
 public function upload()
 {
     if (func_num_args() != 0) {
         return false;
     }
     // Check that the function is called with correct number of arguments
     if ($_SESSION['auth'] == 'true' && $_SESSION['id'] == '1') {
         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
             $files = array();
             $fdata = $_FILES['upload'];
             $post_id = $_POST['post_id'];
             $finalDir = "uploads/{$post_id}/";
             if (is_array($fdata['name'])) {
                 for ($i = 0; $i < count($fdata['name']); ++$i) {
                     $files[] = array('name' => $fdata['name'][$i], 'tmp_name' => $fdata['tmp_name'][$i]);
                 }
             } else {
                 $files[] = $fdata;
             }
             $i = 0;
             foreach ($files as $file) {
                 // each uploaded file
                 try {
                     $error = $_FILES["upload"]["error"][$i];
                     if ($errors[$i] != 0) {
                         throw new Exception(Tools::file_upload_error_message($errors[$i]));
                     }
                     // Sets all the accepded file formats.
                     $accepted_filetypes = array('image/gif', 'image/jpg', 'image/jpeg', 'image/pjpeg', 'application/msword', 'application/pdf', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/x-pdf', 'application/vnd.oasis.opendocument.text');
                     // Checks if the uploaded file is of a approved format
                     if (!in_array($_FILES["upload"]["type"][$i], $accepted_filetypes)) {
                         throw new Exception("Ikke godkjent filtype! Godkjente filtyper: .gif, .jpeg, .doc, .pdf, .docx, .odt");
                     }
                     // Checks if the uploaded file is of a approved size
                     //var_dump($_FILES["upload"]["size"][$i]);
                     if ($_FILES["upload"]["size"][$i] > 5242880) {
                         throw new Exception("Filen din er for stor! Filen er st&oslash;rre enn 5MB!");
                     }
                     // Checks if the uploaded file already is uploaded at the post
                     if (file_exists("uploads/{$post_id}/" . $file["name"])) {
                         throw new Exception($file["name"] . " fins allerede. ");
                     }
                 } catch (Exception $e) {
                     $vars = array('error' => $e->getMessage());
                     new View('upload.tpl', $vars);
                     return true;
                 }
                 // Checks if the folder for the post exists, if not it creates the folder
                 if (!file_exists($finalDir)) {
                     @mkdir($finalDir);
                 }
                 move_uploaded_file($file["tmp_name"], "uploads/{$post_id}/" . $file["name"]);
                 Router::redirect("post/{$post_id}");
                 //							echo "Stored in: " . "uploads/$post_id/" . $file["name"];
                 $i++;
             }
             // each uploaded file end
         } else {
             // POST REQUEST end
             $posts = Post::getAll();
             new View('upload.tpl', array('posts' => $posts));
         }
         // other REQUEST end
         return true;
         // Router feedback
     }
     // upload function end
 }