Oppaitime'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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?
  2. enforce_login();
  3. // Why
  4. // define('ANNOUNCEMENT_FORUM_ID', 19);
  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(ANNOUNCEMENT_FORUM_ID, $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. NotificationsManager::send_push(NotificationsManager::get_push_enabled_users(), $_POST['title'], $_POST['body'], site_url() . 'index.php', NotificationsManager::BLOG);
  97. header('Location: blog.php');
  98. break;
  99. }
  100. }
  101. ?>
  102. <div class="box thin">
  103. <div class="head">
  104. <?=empty($_GET['action']) ? 'Create a blog post' : 'Edit blog post'?>
  105. </div>
  106. <form class="<?=empty($_GET['action']) ? 'create_form' : 'edit_form'?>" name="blog_post" action="blog.php" method="post">
  107. <div class="pad">
  108. <input type="hidden" name="action" value="<?=empty($_GET['action']) ? 'takenewblog' : 'takeeditblog'?>" />
  109. <input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" />
  110. <? if (!empty($_GET['action']) && $_GET['action'] == 'editblog') { ?>
  111. <input type="hidden" name="blogid" value="<?=$BlogID; ?>" />
  112. <? } ?>
  113. <h3>Title</h3>
  114. <input type="text" name="title" size="95"<?=!empty($Title) ? ' value="'.display_str($Title).'"' : '';?> /><br />
  115. <h3>Body</h3>
  116. <textarea name="body" cols="95" rows="15"><?=!empty($Body) ? display_str($Body) : '';?></textarea> <br />
  117. <input type="checkbox" value="1" name="important" id="important" checked="checked" /><label for="important">Important</label><br />
  118. <h3>Thread ID</h3>
  119. <input type="text" name="thread" size="8"<?=!empty($ThreadID) ? ' value="'.display_str($ThreadID).'"' : '';?> />
  120. (Leave blank to create thread automatically)
  121. <br /><br />
  122. <input id="subscribebox" type="checkbox" name="subscribe"<?=!empty($HeavyInfo['AutoSubscribe']) ? ' checked="checked"' : '';?> tabindex="2" />
  123. <label for="subscribebox">Subscribe</label>
  124. <div class="center">
  125. <input type="submit" value="<?=!isset($_GET['action']) ? 'Create blog post' : 'Edit blog post';?>" />
  126. </div>
  127. </div>
  128. </form>
  129. </div>
  130. <br />
  131. <?
  132. }
  133. ?>
  134. <div class="thin">
  135. <?
  136. if (!$Blog = $Cache->get_value('blog')) {
  137. $DB->query("
  138. SELECT
  139. b.ID,
  140. um.Username,
  141. b.UserID,
  142. b.Title,
  143. b.Body,
  144. b.Time,
  145. b.ThreadID
  146. FROM blog AS b
  147. LEFT JOIN users_main AS um ON b.UserID = um.ID
  148. ORDER BY Time DESC
  149. LIMIT 20");
  150. $Blog = $DB->to_array();
  151. $Cache->cache_value('blog', $Blog, 1209600);
  152. }
  153. if ($LoggedUser['LastReadBlog'] < $Blog[0][0]) {
  154. $Cache->begin_transaction('user_info_heavy_'.$LoggedUser['ID']);
  155. $Cache->update_row(false, array('LastReadBlog' => $Blog[0][0]));
  156. $Cache->commit_transaction(0);
  157. $DB->query("
  158. UPDATE users_info
  159. SET LastReadBlog = '".$Blog[0][0]."'
  160. WHERE UserID = ".$LoggedUser['ID']);
  161. $LoggedUser['LastReadBlog'] = $Blog[0][0];
  162. }
  163. foreach ($Blog as $BlogItem) {
  164. list($BlogID, $Author, $AuthorID, $Title, $Body, $BlogTime, $ThreadID) = $BlogItem;
  165. ?>
  166. <div id="blog<?=$BlogID?>" class="box blog_post">
  167. <div class="head">
  168. <strong><?=$Title?></strong> - posted <?=time_diff($BlogTime);?> by <a href="user.php?id=<?=$AuthorID?>"><?=$Author?></a>
  169. <? if (check_perms('admin_manage_blog')) { ?>
  170. - <a href="blog.php?action=editblog&amp;id=<?=$BlogID?>" class="brackets">Edit</a>
  171. <a href="blog.php?action=deleteblog&amp;id=<?=$BlogID?>&amp;auth=<?=$LoggedUser['AuthKey']?>" class="brackets">Delete</a>
  172. <? } ?>
  173. </div>
  174. <div class="pad">
  175. <?=Text::full_format($Body)?>
  176. <? if ($ThreadID) { ?>
  177. <br /><br />
  178. <em><a href="forums.php?action=viewthread&amp;threadid=<?=$ThreadID?>">Discuss this post here</a></em>
  179. <? if (check_perms('admin_manage_blog')) { ?>
  180. <a href="blog.php?action=deadthread&amp;id=<?=$BlogID?>&amp;auth=<?=$LoggedUser['AuthKey']?>" class="brackets">Remove link</a>
  181. <?
  182. }
  183. }
  184. ?>
  185. </div>
  186. </div>
  187. <br />
  188. <?
  189. }
  190. ?>
  191. </div>
  192. <?
  193. View::show_footer();
  194. ?>