Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###### VOIR LES NEWS (Avoir Bootstrap et FontAwesome) #######
- $db_host = 'localhost';
- $db_name = '';
- $db_username = '';
- $db_password = '';
- try {
- $bdd = new PDO('mysql:host='.$db_host.';dbname='.$db_name.';charset=utf8', $db_username, $db_password);
- } catch (Exception $e) {
- echo "Erreur connexion base de donnée";
- }
- $articles = $bdd->query('SELECT * FROM articles ORDER BY date_time_publication DESC');
- while($a = $articles->fetch()) {
- $id = $a['id'];
- $reqcom = $bdd->prepare('SELECT id FROM commentaires WHERE article_id=:id');
- $reqcom->execute(array('id' => $id));
- $comcount = $reqcom->rowCount();
- $reqlikes = $bdd->prepare('SELECT id FROM likes WHERE id_article=:id');
- $reqlikes->execute(array('id' => $id));
- $likescount = $reqlikes->rowCount();
- $message = substr($a['contenu'], 0, 400) . " ...";
- echo '<div class="panel panel-default">
- <div class="panel-heading" style="overflow: hidden;">
- <a style="white-space: nowrap;" href="index.php?view='. $id .'"><h1 class="panel-title"><i class="fa fa-newspaper-o"></i> '. $a['titre'] .'</h1></a>
- </div>
- <div class="panel-body">
- '. $message .'
- </div>
- <div class="panel-footer">
- <p>Article rédigé par <span class="label label-warning">'. $a['auteur'] .'</span></p>
- <i class="fa fa-calendar"></i> '.$a['date_time_publication'] .'
- <i class="fa fa-comment"></i> '. $comcount .'
- <i class="fa fa-thumbs-up"></i> 0
- <a class="pull-right" href="index.php?view='. $id .'"> <i class="fa fa-plus-circle"></i> Lire la suite</a>
- </div>
- </div>';
- ############################ AJOUTER UNE NEWS ################################
- <?php
- $db_host = 'localhost';
- $db_name = '';
- $db_username = '';
- $db_password = '';
- try {
- $bdd = new PDO('mysql:host='.$db_host.';dbname='.$db_name.';charset=utf8', $db_username, $db_password);
- } catch (Exception $e) {
- echo "Erreur connexion base de donnée";
- }
- if(isset($_POST['article_titre'], $_POST['article_contenu'])) {
- if(!empty($_POST['article_titre']) AND !empty($_POST['article_contenu'])) {
- $article_titre = htmlspecialchars($_POST['article_titre']);
- $article_contenu = $_POST['article_contenu'];
- $ins = $bdd->prepare('INSERT INTO articles (titre, contenu, auteur, date_time_publication) VALUES (?, ?, ?, NOW())');
- $ins->execute(array($article_titre, $article_contenu, $data['pseudo']));
- $message = '1';
- } else {
- $message = '0';
- }
- }
- ?>
- <head>
- <meta charset="utf-8">
- <script src="//cdn.ckeditor.com/4.6.2/standard/ckeditor.js"></script>
- </head>
- <!-- Content Wrapper. Contains page content -->
- <div class="content-wrapper">
- <!-- Content Header (Page header) -->
- <section class="content-header">
- <h1>
- Rédaction
- </h1>
- </section>
- <div class="col-md-6">
- <div class="box box-primary">
- <div class="box-header with-border">
- <h3 class="box-title">Rédiger un article</h3>
- </div>
- <?php
- if(isset($message)) {
- if($message == 0) {
- echo '<div class="callout callout-danger">
- <h4>Erreur !</h4>
- <p>Veuillez remplir tout les champs</p>
- </div>';
- }
- if($message == 1) {
- echo '<div class="callout callout-success">
- <h4>Succès !</h4>
- <p>L\'article a bien été publié.</p>
- </div>';
- }
- } ?>
- <form method="POST">
- <div class="form-group">
- <label>Titre de l'article</label>
- <input name="article_titre" class="form-control" type="text">
- </div>
- <div class="form-group">
- <label>URL de la miniature</label>
- <input name="article_image" class="form-control" type="text">
- </div>
- <label>Contenu</label>
- <textarea name="article_contenu"></textarea>
- <script>
- CKEDITOR.replace( 'article_contenu' );
- config.htmlEncodeOutput = false;
- config.entities = false;
- </script>
- <div class="box-footer">
- <button type="submit" class="btn btn-info pull-right">Valider</button>
- </div>
- </form>
- </div>
- </div>
- </section>
- <!-- /.content -->
- </div>
- <!-- /.content-wrapper -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement