BioTorrents.de’s version of Gazelle
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.

index.php 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php
  2. #declare(strict_types=1);
  3. enforce_login();
  4. $ENV = ENV::go();
  5. View::show_header('Blog', 'bbcode');
  6. if (check_perms('admin_manage_blog')) {
  7. if (!empty($_REQUEST['action'])) {
  8. switch ($_REQUEST['action']) {
  9. case 'deadthread':
  10. if (is_number($_GET['id'])) {
  11. $DB->query("
  12. UPDATE blog
  13. SET ThreadID = NULL
  14. WHERE ID = ".$_GET['id']);
  15. $Cache->delete_value('blog');
  16. $Cache->delete_value('feed_blog');
  17. }
  18. header('Location: blog.php');
  19. break;
  20. case 'takeeditblog':
  21. authorize();
  22. if (is_number($_POST['blogid']) && is_number($_POST['thread'])) {
  23. $DB->query("
  24. UPDATE blog
  25. SET
  26. Title = '".db_string($_POST['title'])."',
  27. Body = '".db_string($_POST['body'])."',
  28. ThreadID = ".$_POST['thread']."
  29. WHERE ID = '".db_string($_POST['blogid'])."'");
  30. $Cache->delete_value('blog');
  31. $Cache->delete_value('feed_blog');
  32. }
  33. header('Location: blog.php');
  34. break;
  35. case 'editblog':
  36. if (is_number($_GET['id'])) {
  37. $BlogID = $_GET['id'];
  38. $DB->query("
  39. SELECT Title, Body, ThreadID
  40. FROM blog
  41. WHERE ID = $BlogID");
  42. list($Title, $Body, $ThreadID) = $DB->next_record();
  43. }
  44. break;
  45. case 'deleteblog':
  46. if (is_number($_GET['id'])) {
  47. authorize();
  48. $DB->query("
  49. DELETE FROM blog
  50. WHERE ID = '".db_string($_GET['id'])."'");
  51. $Cache->delete_value('blog');
  52. $Cache->delete_value('feed_blog');
  53. }
  54. header('Location: blog.php');
  55. break;
  56. case 'takenewblog':
  57. authorize();
  58. $Title = db_string($_POST['title']);
  59. $Body = db_string($_POST['body']);
  60. $ThreadID = $_POST['thread'];
  61. if ($ThreadID && is_number($ThreadID)) {
  62. $DB->query("
  63. SELECT ForumID
  64. FROM forums_topics
  65. WHERE ID = $ThreadID");
  66. if (!$DB->has_results()) {
  67. error('No such thread exists!');
  68. header('Location: blog.php');
  69. }
  70. } else {
  71. $ThreadID = Misc::create_thread($ENV->ANNOUNCEMENT_FORUM, $LoggedUser['ID'], $Title, $Body);
  72. if ($ThreadID < 1) {
  73. error(0);
  74. }
  75. }
  76. $DB->query("
  77. INSERT INTO blog
  78. (UserID, Title, Body, Time, ThreadID, Important)
  79. VALUES
  80. ('".$LoggedUser['ID']."',
  81. '".db_string($_POST['title'])."',
  82. '".db_string($_POST['body'])."',
  83. NOW(),
  84. $ThreadID,
  85. '".((isset($_POST['important']) && $_POST['important'] == '1') ? '1' : '0')."')");
  86. $Cache->delete_value('blog');
  87. if ($_POST['important'] == '1') {
  88. $Cache->delete_value('blog_latest_id');
  89. }
  90. if (isset($_POST['subscribe'])) {
  91. $DB->query("
  92. INSERT IGNORE INTO users_subscriptions
  93. VALUES ('$LoggedUser[ID]', $ThreadID)");
  94. $Cache->delete_value('subscriptions_user_'.$LoggedUser['ID']);
  95. }
  96. header('Location: blog.php');
  97. break;
  98. }
  99. } ?>
  100. <div class="box">
  101. <div class="head">
  102. <?=empty($_GET['action']) ? 'Create a blog post' : 'Edit blog post'?>
  103. </div>
  104. <form
  105. class="<?=empty($_GET['action']) ? 'create_form' : 'edit_form'?>"
  106. name="blog_post" action="blog.php" method="post">
  107. <div class="pad">
  108. <input type="hidden" name="action"
  109. value="<?=empty($_GET['action']) ? 'takenewblog' : 'takeeditblog'?>" />
  110. <input type="hidden" name="auth"
  111. value="<?=$LoggedUser['AuthKey']?>" />
  112. <?php if (!empty($_GET['action']) && $_GET['action'] == 'editblog') { ?>
  113. <input type="hidden" name="blogid" value="<?=$BlogID; ?>" />
  114. <?php } ?>
  115. <h3>Title</h3>
  116. <input type="text" name="title" size="95" <?=!empty($Title) ? ' value="'.display_str($Title).'"' : ''; ?>
  117. /><br />
  118. <h3>Body</h3>
  119. <textarea name="body" cols="95"
  120. rows="15"><?=!empty($Body) ? display_str($Body) : ''; ?></textarea>
  121. <br />
  122. <input type="checkbox" value="1" name="important" id="important" checked="checked" /><label
  123. for="important">Important</label><br />
  124. <h3>Thread ID</h3>
  125. <input type="text" name="thread" size="8" <?=!empty($ThreadID) ? ' value="'.display_str($ThreadID).'"' : ''; ?>
  126. />
  127. (Leave blank to create thread automatically)
  128. <br /><br />
  129. <input id="subscribebox" type="checkbox" name="subscribe" <?=!empty($HeavyInfo['AutoSubscribe']) ? ' checked="checked"' : ''; ?>
  130. tabindex="2" />
  131. <label for="subscribebox">Subscribe</label>
  132. <div class="center">
  133. <input type="submit"
  134. value="<?=!isset($_GET['action']) ? 'Create blog post' : 'Edit blog post'; ?>" />
  135. </div>
  136. </div>
  137. </form>
  138. </div>
  139. <br />
  140. <?php
  141. }
  142. ?>
  143. <div>
  144. <?php
  145. if (!$Blog = $Cache->get_value('blog')) {
  146. $DB->query("
  147. SELECT
  148. b.ID,
  149. um.Username,
  150. b.UserID,
  151. b.Title,
  152. b.Body,
  153. b.Time,
  154. b.ThreadID
  155. FROM blog AS b
  156. LEFT JOIN users_main AS um ON b.UserID = um.ID
  157. ORDER BY Time DESC
  158. LIMIT 20");
  159. $Blog = $DB->to_array();
  160. $Cache->cache_value('blog', $Blog, 1209600);
  161. }
  162. if ($LoggedUser['LastReadBlog'] < $Blog[0][0]) {
  163. $Cache->begin_transaction('user_info_heavy_'.$LoggedUser['ID']);
  164. $Cache->update_row(false, array('LastReadBlog' => $Blog[0][0]));
  165. $Cache->commit_transaction(0);
  166. $DB->query("
  167. UPDATE users_info
  168. SET LastReadBlog = '".$Blog[0][0]."'
  169. WHERE UserID = ".$LoggedUser['ID']);
  170. $LoggedUser['LastReadBlog'] = $Blog[0][0];
  171. }
  172. foreach ($Blog as $BlogItem) {
  173. list($BlogID, $Author, $AuthorID, $Title, $Body, $BlogTime, $ThreadID) = $BlogItem; ?>
  174. <div id="blog<?=$BlogID?>" class="box blog_post">
  175. <div class="head">
  176. <strong><?=$Title?></strong> - posted <?=time_diff($BlogTime); ?> by <a
  177. href="user.php?id=<?=$AuthorID?>"><?=$Author?></a>
  178. <?php if (check_perms('admin_manage_blog')) { ?>
  179. - <a href="blog.php?action=editblog&amp;id=<?=$BlogID?>"
  180. class="brackets">Edit</a>
  181. <a href="blog.php?action=deleteblog&amp;id=<?=$BlogID?>&amp;auth=<?=$LoggedUser['AuthKey']?>"
  182. class="brackets">Delete</a>
  183. <?php } ?>
  184. </div>
  185. <div class="pad">
  186. <?=Text::full_format($Body)?>
  187. <?php if ($ThreadID) { ?>
  188. <br /><br />
  189. <em><a
  190. href="forums.php?action=viewthread&amp;threadid=<?=$ThreadID?>">Discuss
  191. this post here</a></em>
  192. <?php if (check_perms('admin_manage_blog')) { ?>
  193. <a href="blog.php?action=deadthread&amp;id=<?=$BlogID?>&amp;auth=<?=$LoggedUser['AuthKey']?>"
  194. class="brackets">Remove link</a>
  195. <?php
  196. }
  197. } ?>
  198. </div>
  199. </div>
  200. <br />
  201. <?php
  202. }
  203. ?>
  204. </div>
  205. <?php
  206. View::show_footer();