Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.68 KB | None | 0 0
  1. ###### VOIR LES NEWS (Avoir Bootstrap et FontAwesome) #######
  2. $db_host = 'localhost';
  3. $db_name = '';
  4. $db_username = '';
  5. $db_password = '';
  6.  
  7. try {
  8. $bdd = new PDO('mysql:host='.$db_host.';dbname='.$db_name.';charset=utf8', $db_username, $db_password);
  9. } catch (Exception $e) {
  10. echo "Erreur connexion base de donnée";
  11. }
  12.  
  13. $articles = $bdd->query('SELECT * FROM articles ORDER BY date_time_publication DESC');
  14. while($a = $articles->fetch()) {
  15. $id = $a['id'];
  16.  
  17. $reqcom = $bdd->prepare('SELECT id FROM commentaires WHERE article_id=:id');
  18. $reqcom->execute(array('id' => $id));
  19. $comcount = $reqcom->rowCount();
  20.  
  21. $reqlikes = $bdd->prepare('SELECT id FROM likes WHERE id_article=:id');
  22. $reqlikes->execute(array('id' => $id));
  23. $likescount = $reqlikes->rowCount();
  24.  
  25. $message = substr($a['contenu'], 0, 400) . " ...";
  26. echo '<div class="panel panel-default">
  27. <div class="panel-heading" style="overflow: hidden;">
  28. <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>
  29. </div>
  30. <div class="panel-body">
  31. '. $message .'
  32. </div>
  33. <div class="panel-footer">
  34. <p>Article rédigé par <span class="label label-warning">'. $a['auteur'] .'</span></p>
  35. <i class="fa fa-calendar"></i> '.$a['date_time_publication'] .'
  36. <i class="fa fa-comment"></i> '. $comcount .'
  37. <i class="fa fa-thumbs-up"></i> 0
  38. <a class="pull-right" href="index.php?view='. $id .'"> <i class="fa fa-plus-circle"></i> Lire la suite</a>
  39. </div>
  40. </div>';
  41. ############################ AJOUTER UNE NEWS ################################
  42.  
  43. <?php
  44.  
  45. $db_host = 'localhost';
  46. $db_name = '';
  47. $db_username = '';
  48. $db_password = '';
  49.  
  50.  
  51. try {
  52. $bdd = new PDO('mysql:host='.$db_host.';dbname='.$db_name.';charset=utf8', $db_username, $db_password);
  53. } catch (Exception $e) {
  54. echo "Erreur connexion base de donnée";
  55. }
  56.  
  57. if(isset($_POST['article_titre'], $_POST['article_contenu'])) {
  58. if(!empty($_POST['article_titre']) AND !empty($_POST['article_contenu'])) {
  59. $article_titre = htmlspecialchars($_POST['article_titre']);
  60. $article_contenu = $_POST['article_contenu'];
  61. $ins = $bdd->prepare('INSERT INTO articles (titre, contenu, auteur, date_time_publication) VALUES (?, ?, ?, NOW())');
  62. $ins->execute(array($article_titre, $article_contenu, $data['pseudo']));
  63. $message = '1';
  64. } else {
  65. $message = '0';
  66. }
  67. }
  68. ?>
  69. <head>
  70. <meta charset="utf-8">
  71. <script src="//cdn.ckeditor.com/4.6.2/standard/ckeditor.js"></script>
  72. </head>
  73.  
  74. <!-- Content Wrapper. Contains page content -->
  75. <div class="content-wrapper">
  76. <!-- Content Header (Page header) -->
  77. <section class="content-header">
  78. <h1>
  79. Rédaction
  80. </h1>
  81. </section>
  82.  
  83. <div class="col-md-6">
  84. <div class="box box-primary">
  85. <div class="box-header with-border">
  86. <h3 class="box-title">Rédiger un article</h3>
  87. </div>
  88. <?php
  89. if(isset($message)) {
  90. if($message == 0) {
  91. echo '<div class="callout callout-danger">
  92. <h4>Erreur !</h4>
  93. <p>Veuillez remplir tout les champs</p>
  94. </div>';
  95. }
  96. if($message == 1) {
  97. echo '<div class="callout callout-success">
  98. <h4>Succès !</h4>
  99. <p>L\'article a bien été publié.</p>
  100. </div>';
  101. }
  102. } ?>
  103. <form method="POST">
  104. <div class="form-group">
  105. <label>Titre de l'article</label>
  106. <input name="article_titre" class="form-control" type="text">
  107. </div>
  108. <div class="form-group">
  109. <label>URL de la miniature</label>
  110. <input name="article_image" class="form-control" type="text">
  111. </div>
  112. <label>Contenu</label>
  113. <textarea name="article_contenu"></textarea>
  114. <script>
  115. CKEDITOR.replace( 'article_contenu' );
  116. config.htmlEncodeOutput = false;
  117. config.entities = false;
  118. </script>
  119. <div class="box-footer">
  120. <button type="submit" class="btn btn-info pull-right">Valider</button>
  121. </div>
  122. </form>
  123. </div>
  124. </div>
  125.  
  126. </section>
  127. <!-- /.content -->
  128. </div>
  129. <!-- /.content-wrapper -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement