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.

sitehistory.class.php 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <?php
  2. #declare(strict_types=1);
  3. class SiteHistory
  4. {
  5. private static $Categories = array(1 => "Code", "Event", "Milestone", "Policy", "Release", "Staff Change");
  6. private static $SubCategories = array(1 => "Announcement", "Blog Post", "Forum Post", "Wiki", "Other", "External Source");
  7. private static $Tags = array(
  8. "api",
  9. "celebration",
  10. "class.primary",
  11. "class.secondary",
  12. "collage",
  13. "community",
  14. "conclusion",
  15. "contest",
  16. "design",
  17. "donate",
  18. "editing",
  19. "editorial",
  20. "feature",
  21. "featured.article",
  22. "featured.album",
  23. "featured.product",
  24. "finances",
  25. "format",
  26. "forum",
  27. "freeleech",
  28. "freeleech.tokens",
  29. "gazelle",
  30. "hierarchy",
  31. "inbox",
  32. "infrastructure",
  33. "interview",
  34. "irc",
  35. "log",
  36. "neutral.leech",
  37. "notifications",
  38. "ocelot",
  39. "paranoia",
  40. "picks.guest",
  41. "picks.staff",
  42. "promotion",
  43. "ratio",
  44. "record",
  45. "report",
  46. "request",
  47. "requirement",
  48. "retirement",
  49. "rippy",
  50. "search",
  51. "settings",
  52. "start",
  53. "stats",
  54. "store",
  55. "stylesheet",
  56. "tagging",
  57. "transcode",
  58. "toolbox",
  59. "top.10",
  60. "torrent",
  61. "torrent.group",
  62. "upload",
  63. "vanity.house",
  64. "voting",
  65. "whitelist",
  66. "wiki"
  67. );
  68. public static function get_months()
  69. {
  70. $Results = G::$Cache->get_value("site_history_months");
  71. if (!$Results) {
  72. $QueryID = G::$DB->get_query_id();
  73. G::$DB->query("
  74. SELECT DISTINCT
  75. YEAR(DATE) AS Year, MONTH(Date) AS Month, MONTHNAME(Date) AS MonthName
  76. FROM site_history
  77. ORDER BY Date DESC");
  78. $Results = G::$DB->to_array();
  79. G::$DB->set_query_id($QueryID);
  80. G::$Cache->cache_value("site_history_months", $Results, 0);
  81. }
  82. return $Results;
  83. }
  84. public static function get_event($ID)
  85. {
  86. if (!empty($ID)) {
  87. $QueryID = G::$DB->get_query_id();
  88. G::$DB->query("
  89. SELECT
  90. ID, Title, Url, Category, SubCategory, Tags, Body, AddedBy, Date
  91. FROM site_history
  92. WHERE ID = '$ID'
  93. ORDER BY Date DESC");
  94. $Event = G::$DB->next_record();
  95. G::$DB->set_query_id($QueryID);
  96. return $Event;
  97. }
  98. }
  99. public static function get_latest_events($Limit)
  100. {
  101. self::get_events(null, null, null, null, null, null, $Limit);
  102. }
  103. public static function get_events($Month, $Year, $Title, $Category, $SubCategory, $Tags, $Limit)
  104. {
  105. $Month = (int)$Month;
  106. $Year = (int)$Year;
  107. $Title = db_string($Title);
  108. $Category = (int)$Category;
  109. $SubCategory = (int)$SubCategory;
  110. $Tags = db_string($Tags);
  111. $Limit = (int)$Limit;
  112. $Where = [];
  113. if (!empty($Month)) {
  114. $Where[] = " MONTH(Date) = '$Month' ";
  115. }
  116. if (!empty($Year)) {
  117. $Where[] = " YEAR(Date) = '$Year' ";
  118. }
  119. if (!empty($Title)) {
  120. $Where[] = " Title LIKE '%$Title%' ";
  121. }
  122. if (!empty($Category)) {
  123. $Where[] = " Category = '$Category '";
  124. }
  125. if (!empty($SubCategory)) {
  126. $Where[] = " SubCategory = '$SubCategory '";
  127. }
  128. if (!empty($Tags)) {
  129. $Tags = explode(',', $Tags);
  130. $Or = '(';
  131. foreach ($Tags as $Tag) {
  132. $Tag = trim($Tag);
  133. $Or .= " Tags LIKE '%$Tag%' OR ";
  134. }
  135. if (strlen($Or) > 1) {
  136. $Or = rtrim($Or, 'OR ');
  137. $Or .= ')';
  138. $Where[] = $Or;
  139. }
  140. }
  141. if (!empty($Limit)) {
  142. $Limit = " LIMIT $Limit";
  143. } else {
  144. $Limit = '';
  145. }
  146. if (count($Where) > 0) {
  147. $Query = ' WHERE ' . implode('AND', $Where);
  148. } else {
  149. $Query = '';
  150. }
  151. $QueryID = G::$DB->get_query_id();
  152. G::$DB->query("
  153. SELECT
  154. ID, Title, Url, Category, SubCategory, Tags, Body, AddedBy, Date
  155. FROM site_history
  156. $Query
  157. ORDER BY Date DESC
  158. $Limit");
  159. $Events = G::$DB->to_array();
  160. G::$DB->set_query_id($QueryID);
  161. return $Events;
  162. }
  163. public static function add_event($Date, $Title, $Link, $Category, $SubCategory, $Tags, $Body, $UserID)
  164. {
  165. if (empty($Date)) {
  166. $Date = sqltime();
  167. } else {
  168. list($Y, $M, $D) = explode('-', $Date);
  169. if (!checkdate($M, $D, $Y)) {
  170. error("Error");
  171. }
  172. }
  173. $Title = db_string($Title);
  174. $Link = db_string($Link);
  175. $Category = (int)$Category;
  176. $SubCategory = (int)$SubCategory;
  177. $Tags = db_string(strtolower((preg_replace('/\s+/', '', $Tags))));
  178. $ExplodedTags = explode(',', $Tags);
  179. foreach ($ExplodedTags as $Tag) {
  180. if (!in_array($Tag, self::get_tags())) {
  181. error("Invalid tag");
  182. }
  183. }
  184. $Body = db_string($Body);
  185. $UserID = (int)$UserID;
  186. if (empty($Title) || empty($Category) || empty($SubCategory)) {
  187. error("Error");
  188. }
  189. $QueryID = G::$DB->get_query_id();
  190. G::$DB->query("
  191. INSERT INTO site_history
  192. (Title, Url, Category, SubCategory, Tags, Body, AddedBy, Date)
  193. VALUES
  194. ('$Title', '$Link', '$Category', '$SubCategory', '$Tags', '$Body', '$UserID', '$Date')");
  195. G::$DB->set_query_id($QueryID);
  196. G::$Cache->delete_value("site_history_months");
  197. }
  198. public static function update_event($ID, $Date, $Title, $Link, $Category, $SubCategory, $Tags, $Body, $UserID)
  199. {
  200. if (empty($Date)) {
  201. $Date = sqltime();
  202. } else {
  203. $Date = db_string($Date);
  204. list($Y, $M, $D) = explode('-', $Date);
  205. if (!checkdate($M, $D, $Y)) {
  206. error("Error");
  207. }
  208. }
  209. $ID = (int)$ID;
  210. $Title = db_string($Title);
  211. $Link = db_string($Link);
  212. $Category = (int)$Category;
  213. $SubCategory = (int)$SubCategory;
  214. $Tags = db_string(strtolower((preg_replace('/\s+/', '', $Tags))));
  215. $ExplodedTags = explode(",", $Tags);
  216. foreach ($ExplodedTags as $Tag) {
  217. if (!in_array($Tag, self::get_tags())) {
  218. error("Invalid tag");
  219. }
  220. }
  221. $Body = db_string($Body);
  222. $UserID = (int)$UserID;
  223. if (empty($ID) || empty($Title) || empty($Category) || empty($SubCategory)) {
  224. error("Error");
  225. }
  226. $QueryID = G::$DB->get_query_id();
  227. G::$DB->query("
  228. UPDATE site_history
  229. SET
  230. Title = '$Title',
  231. Url = '$Link',
  232. Category = '$Category',
  233. SubCategory = '$SubCategory',
  234. Tags = '$Tags',
  235. Body = '$Body',
  236. AddedBy = '$UserID',
  237. Date = '$Date'
  238. WHERE ID = '$ID'");
  239. G::$DB->set_query_id($QueryID);
  240. G::$Cache->delete_value("site_history_months");
  241. }
  242. public static function delete_event($ID)
  243. {
  244. if (!is_numeric($ID)) {
  245. error(404);
  246. }
  247. $QueryID = G::$DB->get_query_id();
  248. G::$DB->query("
  249. DELETE FROM site_history
  250. WHERE ID = '$ID'");
  251. G::$DB->set_query_id($QueryID);
  252. G::$Cache->delete_value("site_history_months");
  253. }
  254. public static function get_categories()
  255. {
  256. return self::$Categories;
  257. }
  258. public static function get_sub_categories()
  259. {
  260. return self::$SubCategories;
  261. }
  262. public static function get_tags()
  263. {
  264. return self::$Tags;
  265. }
  266. }