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.

edit_podcast.php 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. require_once('../includes/config.php');
  3. $userID = 0;
  4. $postID = 0;
  5. $authorID = 0;
  6. $title = "";
  7. $post = "";
  8. //check to see that the form has been submitted
  9. if(isset($_POST))
  10. {
  11. //retrieve the $_POST variables
  12. $userID = rawurldecode($_POST['userID']);
  13. $postID = rawurldecode($_POST['postID']);
  14. $title = rawurldecode($_POST['title']);
  15. $post = rawurldecode($_POST['post']);
  16. $file = rawurldecode($_POST['file']);
  17. $post_select = $db->select('podcast', "id=? LIMIT 1", array($postID));
  18. if ($post_select)
  19. {
  20. $orig_title = $post_select['title'];
  21. $filename = $post_select['file_name'];
  22. //initialize variables for form validation
  23. $success = true;
  24. if($success && !$logged_in)
  25. {
  26. $error = "You must be logged in to edit this podcast post.";
  27. $success = false;
  28. }
  29. if($success && empty($title))
  30. {
  31. $error = "You need to submit a title with your podcast.";
  32. $success = false;
  33. }
  34. if($success && strlen($title) > 140)
  35. {
  36. $error = "The maximum length for your title is 140 characters.";
  37. $success = false;
  38. }
  39. if($success && empty($post))
  40. {
  41. $error = "You need to submit an actual description.";
  42. $success = false;
  43. }
  44. if($success && empty($file))
  45. {
  46. $error = "You need to upload a file for the podcast.";
  47. $success = false;
  48. }
  49. if ($success && !$user->admin)
  50. {
  51. $error = "You are not allowed to edit this podcast.";
  52. $success = false;
  53. }
  54. if($success)
  55. {
  56. $podcast_dir = $CONF['podcast_dir'].$orig_title."\\";
  57. if ($orig_title != $title)
  58. {
  59. mkdir($CONF['podcast_dir'].$title, 0777, true);
  60. $podcast_dir = $CONF['podcast_dir'].$title."\\";
  61. }
  62. $files = explode(',', $file);
  63. $oldFiles = explode(',', $filename);
  64. // Delete Removed Files
  65. $diff = array_diff($oldFiles, $files);
  66. foreach ($diff as $single)
  67. {
  68. unlink($podcast_dir.$single);
  69. }
  70. if ($orig_title != $title)
  71. {
  72. // Move Old Files to new Directory
  73. $toMove = scandir($CONF['podcast_dir'].$orig_title);
  74. foreach ($toMove as $single)
  75. {
  76. if (file_exists($CONF['podcast_dir'].$orig_title."\\".$single) && is_file($CONF['podcast_dir'].$orig_title."\\".$single))
  77. {
  78. rename($CONF['podcast_dir'].$orig_title."\\".$single, $podcast_dir.$single);
  79. }
  80. }
  81. rmdir($CONF['podcast_dir'].$orig_title);
  82. }
  83. // Move all new files
  84. $diff = array_diff($files, $oldFiles);
  85. foreach ($files as $single)
  86. {
  87. if (file_exists($CONF['podcast_dir'].$single))
  88. {
  89. rename($CONF['podcast_dir'].$single, $podcast_dir.$single);
  90. }
  91. }
  92. $data = array(
  93. "title" => $title,
  94. "tags" => "",
  95. "file_name" => $file,
  96. "description" => $post
  97. );
  98. $post_id = $db->update($data, 'podcast', 'id=?', array($postID));
  99. unset($_POST);
  100. echo "true";
  101. }
  102. else
  103. {
  104. unset($_POST);
  105. echo $error;
  106. }
  107. }
  108. else
  109. {
  110. echo "That podcast post does not exist.";
  111. }
  112. }
  113. else
  114. {
  115. echo "$_POST is not set.";
  116. }
  117. ?>