Guest
Public paste!

Untitled

By: a guest | Oct 19th, 2009 | Syntax: None | Size: 11.34 KB | Hits: 158 | Expires: Never
Copy text to clipboard
  1. <?php
  2.  
  3.         $results = 5; //How many news articles per page?
  4.         $newspass = "12292"; //The password for the news editing/deleting/adding
  5.         if ($_COOKIE['news'] == $newspass) {setcookie("news", $newspass, time()+3600);}
  6.  
  7.         //What is displayed if an ID is not defined
  8.         if (!$_GET['do']) {    
  9.                 include("db_connect.php"); //Initiate a connection to the database
  10.                 $result = mysql_query("SELECT * FROM news ORDER BY id DESC LIMIT $results"); //The query
  11.                
  12.         include ('./fix.php');
  13.                
  14.                 //Split up the result into rows
  15.                 while ($row = mysql_fetch_array($result)) {
  16.                         echo "<a href='index.php?do=article&id=" . $row['id'] . "'><h1><font color='#009900'>" . $row['subject'] . "</font> </h1></a>";
  17.                         echo "<center><h3><b><font color='#666666'> Posted by " . $row['author'] . " on " . date("D jS F Y", $row['time']) . " </font></b></h3></center>";     
  18. if ($_COOKIE['news'] == $newspass) {echo ("<p>(<a href='index.php?do=edit&id=" . $row['id'] . "'>edit</a>)(<a href='index.php?do=delete&id=" . $row['id'] . "'>delete</a>) ");}
  19.                         echo "<table style='border-style: none;'><tr><td><div style='padding-left: 3em'><p>" . $row['body'] . "</p></div></td></tr></table>";
  20.                         echo "<hr><br />";
  21.                 }
  22.         }
  23.  
  24.         //Shows the page for a particular news article
  25.         elseif ($_GET['do'] == "article") {
  26.  
  27.        
  28.         include ('./fix.php');
  29.  
  30.                 $id = $_GET['id'];     
  31.                 include("db_connect.php"); //Initiate a connection to the database
  32.                 $article = mysql_query("SELECT * FROM news WHERE id LIKE $id"); //The query for the article    
  33.                 $comments = mysql_query("SELECT * FROM comments WHERE article_id LIKE $id ORDER BY id"); //The query for the comments          
  34.                
  35.                 while ($row = mysql_fetch_array($article)) {
  36.                         echo "<a href='index.php?do=article&id=" . $row['id'] . "'><h1><font color='#009900'>" . $row['subject'] . "</font> </h1></a>";        
  37.                         echo "<center><h3><b><font color='#666666'> Posted by " . $row['author'] . " on " . date("D jS F Y", $row['time']) . " </font></b></h3></center>";                              if ($_COOKIE['news'] == $newspass) {echo ("<p>(<a href='index.php?do=edit&id=" . $row['id'] . "'>edit</a>)(<a href='index.php?do=delete&id=" . $row['id'] . "'>delete</a>) ");}
  38.                         echo "<table style='border-style: none;'><tr><td><div style='padding-left: 3em'><p>" . $row['body'] . "</p></div></td></tr></table>";
  39.                         echo "<hr><br /><h2>Comments.</h2>";
  40.                 }
  41.                 while ($row = mysql_fetch_array($comments)) {
  42.                         echo "<strong><h2><a href='" . $row['subject'] . "'/>" . $row['author'] . "</a></h2></strong>";
  43.                         if ($_COOKIE['news'] == $newspass) {echo ("<p>(<a href='index.php?do=deletereply&id=" . $row['id'] . "'>delete</a>) ");}
  44.                         echo "<p>" . $row['body'] . "</p>";
  45.                         echo "<p>" . date("D jS F Y", $row['time']) . "</p>";
  46.                         echo "<br />";
  47.                 }
  48.                 if (mysql_num_rows($article)>0) {
  49.  
  50.                         echo ("<form action='index.php?do=reply&id=$id' method='post'><br /><input type='text' name='subject' value='http://' /> Your website.<br /><br />
  51.                                                 <input type='text' name='author' value='' /> Name (required)<br /><br />
  52.                                                 <textarea class='body1' name='body' rows='4' cols='20'></textarea><br /><br />");
  53.  
  54.                                 require_once('recaptchalib.php');
  55.                                 $publickey = "6Lc45ggAAAAAAG_5x1oikf1m8Akfq5Vv57TCaU2C"; // you got this from the signup page
  56.                                 echo recaptcha_get_html($publickey);   
  57.                                        
  58.                         echo ("<input type='submit' value='Reply' />");
  59.  
  60.                 }
  61.                 else {
  62.                         echo "There is no article with the ID $id, sorry.";
  63.                 }
  64.         }
  65.        
  66.  
  67.         //Handles posting POST NEWS
  68.         elseif ($_GET['do'] == "post") {
  69.  
  70.        
  71.         include ('./fix.php');
  72.  
  73. echo (' Notes: <br /> Newline <b> &#60;br /> </b> <br /> Paragraph <b> &#60;p> text &#60;/p> </b> <br /> Image <b> &#60;img src="www.linktotheimage.com/thepic.png" /> </b> <br /> Bold <b> &#60;b>This text is entirely BOLD!&#60;/b> </b> <br /> Italics <b> &#60;i>Sean is awesome&#60;/i> </b> <br /> Underlined <b> I want&#60;u> this &#60;/u> word to be underlined! </b> <br /> Hyperlink <b> &#60;a href="http://www.website.com" />Click here to go to website.com&#60;/a> ');
  74.                 if ($_COOKIE['news'] == $newspass) {
  75.                         if (!($_POST['author'] == "") && !($_POST['subject'] == "") && !($_POST['body'] == "")) {
  76.                                 $author = $_POST['author'];
  77.                                 $subject = $_POST['subject'];
  78.                                 $body = $_POST['body'];
  79.                                 $time = time();
  80.                                
  81.                                 include("db_connect.php"); //Initiate a connection to the database
  82.                                 mysql_query("INSERT INTO news (`author`, `subject`, `body`, `time`) VALUES ('$author', '$subject', '$body', '$time')") or die("Sorry! It failed! Please try again.<br />" . mysql_error()); //The query for the article
  83.                                 echo ("<h1>POSTED!! :D</h1><br /><a href='index.php'>News</a>");
  84.                         }
  85.                         else {
  86.                                 echo ("<form action='index.php?do=post' method='post'><input type='text' name='subject' value='subject' /><br />
  87.                                                 <textarea class='body' name='body' rows='4' cols='20'></textarea> <br />
  88.                                                 <input type='text' name='author' value='author' /><br />
  89.                                                 <input type='submit' value='Submit' />");
  90.                         }
  91.                 }
  92.                 else {
  93.                         echo ("<h1>YOU ARE NOT LOGGED IN OMG</h1>");
  94.                         echo ("<form action='index.php?do=login' method='post'><input type='password' name='pass' /><input type='submit' value='Submit' />");                  
  95.                 }
  96.         }
  97.  
  98.         //Handles commenting an article
  99.         elseif ($_GET['do'] == "reply") {
  100.                 if (!$_POST['author'] or !$_POST['subject'] or !$_POST['body']) {
  101.                         $id = $_GET['id'];
  102.                        
  103.                         echo ("<form action='index.php?do=reply&id=$id' method='post'><input type='text' name='subject' value='title' /><br />
  104.                                         <input type='text' name='author' value='author' /><br />
  105.                                         <input type='text' name='body' value='body' /><br />
  106.                                         <input type='submit' value='Submit' />");
  107.                 }
  108.                 else {
  109.                         include("db_connect.php"); //Initiate a connection to the database
  110.                         //$result = mysql_query("SELECT * FROM news WHERE
  111.                         $author = htmlspecialchars($_POST['author']);
  112.                         $subject = htmlspecialchars($_POST['subject']);
  113.                         $body = htmlspecialchars($_POST['body']);
  114.                         $time = time();
  115.                         $id = $_GET['id'];
  116.  
  117.                         require_once('recaptchalib.php');
  118. $privatekey = "6Lc45ggAAAAAAPZBWVMBpxK_XdGhAIm1TnToh9V5";
  119. $resp = recaptcha_check_answer ($privatekey,
  120.                                 $_SERVER["REMOTE_ADDR"],
  121.                                 $_POST["recaptcha_challenge_field"],
  122.                                 $_POST["recaptcha_response_field"]);
  123.  
  124. if (!$resp->is_valid) {
  125.   die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
  126.        "(reCAPTCHA said: " . $resp->error . ")");
  127. }
  128.  
  129.                                
  130.                         mysql_query("INSERT INTO comments (`author`, `subject`, `body`, `time`, `article_id`) VALUES ('$author', '$subject', '$body', '$time', '$id')") or die("Sorry! It failed! Please try again.<br />" . mysql_error()); //The query for the article
  131.                         echo ("<h1>Comment posted.</h1><br /><a href='index.php?do=article&id=$id'>Back to article</a>");
  132.  
  133.  
  134.  
  135.                 }
  136.         }
  137.        
  138.         //Handles editing article
  139.         elseif ($_GET['do'] == "edit") {
  140.  
  141.        
  142.         include ('./fix.php');
  143.  
  144.                 if ($_COOKIE['news'] == $newspass) {
  145.                         if (!$_POST['author']) {
  146.                                 $id = $_GET['id'];
  147.                                 include("db_connect.php"); //Initiate a connection to the database
  148.                                 $article = mysql_query("SELECT * FROM news WHERE id LIKE $id"); //The query for the article
  149.                                 while ($row = mysql_fetch_array($article)) {
  150.                                         echo ("<form action='index.php?do=edit&id=" . $row['id'] . "' method='post'><input type='text' name='subject' value='" . $row['subject'] . "' /><br />
  151.                                                 <textarea class='body' name='body' rows='4' cols='20'>" . $row['body'] . "</textarea> <br />
  152.                                                 <input type='text' name='author' value='" . $row['author'] . "' /><br />
  153.                                                 <input type='submit' value='Submit' />");
  154.                                 }
  155.                         }
  156.                         else {
  157.                                 $author = $_POST['author'];
  158.                                 $subject = $_POST['subject'];
  159.                                 $body = $_POST['body'];
  160.                                 $time = time();
  161.                                 $id = $_GET['id'];
  162.                                
  163.                                 include("db_connect.php"); //Initiate a connection to the database
  164.                                 mysql_query("UPDATE news SET author='$author', subject='$subject', body='$body', time='$time' WHERE id LIKE $id") or die("Sorry! It failed! Please try again.<br />" . mysql_error()); //The query for the article
  165.                                 echo ("<h2>Article sucessfully edited.</h2><br /><a href='index.php'>Back to News</a>");
  166.                         }
  167.                 }
  168.                 else {
  169.                         echo ("<h1>Please Login.</h1>");
  170.                         echo ("<form action='index.php?do=login' method='post'><input type='password' name='pass' /><input type='submit' value='Submit' />");                  
  171.                 }
  172.         }
  173.         //Handles deleting article
  174.         elseif ($_GET['do'] == "delete") {
  175.  
  176.        
  177.         include ('./fix.php');
  178.  
  179.                 if ($_COOKIE['news'] == $newspass) {
  180.                         if (!$_GET['sure']) {
  181.  
  182.                                 $id = $_GET['id'];
  183.                                         echo ("<h1>Are you sure you want to DELETE post ID $id</h1>");
  184.                                         echo ("<h1>This action CANNOT be undone.</h1>");
  185.                                         echo ("<a href='index.php?do=delete&id=$id&sure=yes'><h1>Yes</h1></a><a href='index.php'><h1>No</h1></a>");
  186.                         }
  187.                         else {
  188.                                 if ($_GET['sure'] == "yes") {
  189.  
  190.                                         $id = $_GET['id'];
  191.                                        
  192.                                         include("db_connect.php"); //Initiate a connection to the database
  193.                                         mysql_query("DELETE FROM news WHERE id LIKE $id") or die("Sorry! It failed! Please try again.<br />" . mysql_error()); //The query for the article
  194.                                         echo ("<h1>Artcle Deleted</h1><br /><a href='index.php'>News</a>");
  195.                                 }
  196.                         }
  197.                 }
  198.                 else {
  199.                         echo ("<h1>Please Login.</h1>");
  200.                         echo ("<form action='index.php?do=login' method='post'><input type='password' name='pass' /><input type='submit' value='Submit' />");                  
  201.                 }
  202.         }
  203.         //Handles deleting comments
  204.         elseif ($_GET['do'] == "deletereply") {
  205.  
  206.        
  207.         include ('./fix.php');
  208.  
  209.                 if ($_COOKIE['news'] == $newspass) {
  210.                         if (!$_GET['sure']) {
  211.  
  212.                                 $id = $_GET['id'];
  213.                                         echo ("<h1>Are you sure you want to DELETE reply ID $id</h1>");
  214.                                         echo ("<h1>This action CANNOT be undone.</h1>");
  215.                                         echo ("<a href='index.php?do=deletereply&id=$id&sure=yes'><h1>Yes</h1></a><a href='index.php'><h1>No</h1></a>");
  216.                         }
  217.                         else {
  218.                                 if ($_GET['sure'] == "yes") {
  219.  
  220.                                         $id = $_GET['id'];
  221.                                        
  222.                                         include("db_connect.php"); //Initiate a connection to the database
  223.                                         mysql_query("DELETE FROM comments WHERE id LIKE $id") or die("Sorry! It failed! Please try again.<br />" . mysql_error()); //The query for the article
  224.                                         echo ("<h1>Reply Deleted</h1><br /><a href='index.php'>News</a>");
  225.                                 }
  226.                         }
  227.                 }
  228.                 else {
  229.                         echo ("<h1>Please Login.</h1>");
  230.                         echo ("<form action='index.php?do=login' method='post'><input type='password' name='pass' /><input type='submit' value='Submit' />");                  
  231.                 }
  232.         }
  233.         //Log in
  234.         elseif ($_GET['do'] == "login") {
  235.                 if (!$_POST['pass']) {
  236.                         echo ("<center><h1>Admin Login</h1>");
  237.                         echo ("<form action='index.php?do=login' method='post'><input type='password' name='pass' /><input type='submit' value='Submit' />");  
  238.                 }
  239.                 else {
  240.                         if ($_COOKIE['news'] == $newspass) {
  241.                                 echo ("<h1>Sorry But You Are Already Logged In.</h1><br /><a href='index.php'>News</a>");
  242.                         }
  243.                         else {
  244.                                 if ($_POST['pass'] == $newspass) {
  245.                                         setcookie("news", $newspass, time()+3600);
  246.                                         echo ("<h1>Thank You For Logging In, You Will Automatically Logged Out After 1 Hour Of Inactivity.</h1><br /><a href='index.php'>News</a>");
  247.                                 }
  248.                                 else {
  249.                                         echo ("<h1>Incorrect PASSWORD.</h1><br /><a href='index.php'>News</a></center>");
  250.                                 }
  251.                         }
  252.                 }
  253.         }
  254.         elseif ($_GET['do'] == "logout") {
  255.  
  256.                 if ($_COOKIE['news'] == $newspass) {
  257.                         setcookie("news", $newspass, time());
  258.                         echo ("<h1>Thank You, You Are Now Logged Out.</h1><br /><a href='index.php'>News</a>");
  259.                 }
  260.                 else {
  261.                         echo ("<h1>You aren't Logged In to Logout...</h1><br /><a href='index.php'>News</a>");
  262.                 }
  263.         }
  264. ?>
  265. </div>
  266. </div>
  267. </body>
  268. </center>
  269. </html>