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

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