Teknik is a suite of services with attractive and functional interfaces. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

publish_blog.php 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. require_once('../includes/config.php');
  3. $userID = 0;
  4. $authorID = 0;
  5. $title = "";
  6. $post = "";
  7. //check to see that the form has been submitted
  8. if(isset($_POST))
  9. {
  10. //retrieve the $_POST variables
  11. $userID = rawurldecode($_POST['userID']);
  12. $title = rawurldecode($_POST['title']);
  13. $post = rawurldecode($_POST['post']);
  14. //initialize variables for form validation
  15. $success = true;
  16. if($success && !$logged_in)
  17. {
  18. $error = "You must be logged in to make a blog post.";
  19. $success = false;
  20. }
  21. if($success && empty($title))
  22. {
  23. $error = "You need to submit a title with your post.";
  24. $success = false;
  25. }
  26. if($success && strlen($title) > 140)
  27. {
  28. $error = "The maximum length for your title is 140 characters.";
  29. $success = false;
  30. }
  31. if($success && empty($post))
  32. {
  33. $error = "You need to submit an actual post.";
  34. $success = false;
  35. }
  36. if($success && (($userID == 0 && !$user->admin) || ($userID != 0 && $user->id != $userID)))
  37. {
  38. $error = "You are not allowed to post to this blog.";
  39. $success = false;
  40. }
  41. if($success)
  42. {
  43. $data = array(
  44. "user_id" => $userID,
  45. "author_id" => $user->id,
  46. "title" => $title,
  47. "tags" => "",
  48. "post" => $post,
  49. "date_posted" => date("Y-m-d H:i:s",time())
  50. );
  51. $post_id = $db->insert($data, 'blog');
  52. unset($_POST);
  53. echo "true";
  54. }
  55. else
  56. {
  57. unset($_POST);
  58. echo $error;
  59. }
  60. }
  61. else
  62. {
  63. echo "$_POST is not set.";
  64. }
  65. ?>