Advertisement
silentdigger

wCMS v. 0.00001

Jan 31st, 2015
599
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. --------------------------------------------------------------------------------------
  2. /index.php
  3. --------------------------------------------------------------------------------------
  4. <?php
  5. /**
  6. * Created by PhpStorm.
  7. * User: Adrian
  8. * Date: 2015-01-30
  9. * Time: 12:16
  10. */
  11.  
  12.  
  13. include_once ('includes/connection.php');
  14. include_once ('includes/article.php');
  15.  
  16. $pagetitle = "wCMS";
  17. $article = new Article;
  18. $articles = $article->fetch_all();
  19.  
  20. ?>
  21.  
  22. <html>
  23. <head>
  24.  
  25. <title><?php echo $pagetitle ?></title>
  26. <link rel="stylesheet" href="includes/templates/default/style.css" />
  27. </head>
  28. <body>
  29. <div class="container">
  30.  
  31. <a href="index.php" id="Logo"><?php echo $pagetitle ?></a>
  32. <ol>
  33. <?php foreach ($articles as $article) { ?>
  34. <li>
  35. <a href="article.php?id=<?php echo $article['article_id']; ?>">
  36. <?php echo $article['article_title']; ?>
  37. </a>
  38. - <small>
  39. dodano <?php echo date('l jS', $article['article_timestamp']); ?>
  40. </small>
  41. </li>
  42. <?php } ?>
  43. </ol>
  44. </div>
  45.  
  46.  
  47.  
  48.  
  49.  
  50. </body>
  51. </html>
  52. --------------------------------------------------------------------------------------
  53. /article.php
  54. --------------------------------------------------------------------------------------
  55. <?php
  56. /**
  57. * Created by PhpStorm.
  58. * User: Adrian
  59. * Date: 2015-01-30
  60. * Time: 15:33
  61. */
  62. $pagetitle = "wCMS";
  63.  
  64. include_once ('includes/connection.php');
  65. include_once ('includes/article.php');
  66.  
  67. $article = new Article();
  68.  
  69. if (isset($_GET['id'])) {
  70. $id = $_GET['id'];
  71. $data = $article->fetch_data($id);
  72.  
  73. ?>
  74. <html>
  75. <head>
  76.  
  77. <title><?php echo $pagetitle ?></title>
  78. <link rel="stylesheet" href="includes/templates/default/style.css" />
  79. </head>
  80. <body>
  81. <div class="container">
  82.  
  83. <a href="index.php" id="Logo"><?php echo $pagetitle ?></a>
  84.  
  85. <h4><?php echo $data['article_title'] ?> -
  86. <small>
  87. <?php echo date('l jS', $data['article_timestamp']) ?>
  88. </small>
  89.  
  90. </h4>
  91.  
  92. <p><?php echo $data['article_content']; ?></p>
  93.  
  94. <a href="index.php">&larr; Wstecz</a>
  95.  
  96. </div>
  97.  
  98.  
  99.  
  100.  
  101.  
  102. </body>
  103. </html>
  104.  
  105.  
  106.  
  107. <?php
  108.  
  109. } else {
  110. header('Location: index.php');
  111. exit();
  112.  
  113. }
  114.  
  115. --------------------------------------------------------------------------------------
  116. /includes/article.php
  117. --------------------------------------------------------------------------------------
  118. <?php
  119. /**
  120. * Created by PhpStorm.
  121. * User: Adrian
  122. * Date: 2015-01-30
  123. * Time: 15:02
  124. */
  125. class Article {
  126. public function fetch_all() {
  127. global $pdo;
  128.  
  129. $query = $pdo->prepare("SELECT * FROM articles");
  130. $query->execute();
  131.  
  132.  
  133. return $query->fetchAll();
  134. }
  135. public function fetch_data($article_id) {
  136. global $pdo;
  137.  
  138. $query = $pdo->prepare("SELECT * FROM articles WHERE article_id = ?");
  139. $query->bindValue(1, $article_id);
  140. $query->execute();
  141.  
  142. return $query->fetch();
  143. }
  144. }
  145.  
  146. ?>
  147. --------------------------------------------------------------------------------------
  148. /includes/connection.php
  149. --------------------------------------------------------------------------------------
  150. <?php
  151. /**
  152. * Created by PhpStorm.
  153. * User: Adrian
  154. * Date: 2015-01-30
  155. * Time: 14:38
  156. */
  157.  
  158. try {
  159.  
  160.  
  161. $pdo = new PDO('mysql:host=localhost;dbname=wcms', 'root', 'moje_haslo');
  162. } catch (PDOException $e) {
  163. exit('Brak połączenia z bazą');
  164. }
  165.  
  166. --------------------------------------------------------------------------------------
  167. includes/templates/default/style.css
  168. --------------------------------------------------------------------------------------
  169. body {
  170.  
  171. padding-top: 120px;
  172. font-family: Arial;
  173. }
  174.  
  175. .containter {
  176. width: 500px;
  177. margin: 0 auto;
  178. }
  179.  
  180. a:link, a:visited {
  181. color: slategray;
  182. text-decoration: none;
  183. border-bottom: 1px dotted slategray;
  184. }
  185.  
  186. a:hover {
  187. color: #444;
  188. border-bottom-color: #444;
  189. }
  190. small {
  191. color: #999;
  192. font-style: italic;
  193. }
  194.  
  195. p {
  196. line-height: 30px;
  197.  
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement