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.

sitehistory.class.php 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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", "Change Log", "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. public static function get_months()
  67. {
  68. $Results = G::$Cache->get_value("site_history_months");
  69. if (!$Results) {
  70. $QueryID = G::$DB->get_query_id();
  71. G::$DB->query("
  72. SELECT DISTINCT
  73. YEAR(DATE) AS Year, MONTH(Date) AS Month, MONTHNAME(Date) AS MonthName
  74. FROM site_history
  75. ORDER BY Date DESC");
  76. $Results = G::$DB->to_array();
  77. G::$DB->set_query_id($QueryID);
  78. G::$Cache->cache_value("site_history_months", $Results, 0);
  79. }
  80. return $Results;
  81. }
  82. public static function get_event($ID)
  83. {
  84. if (!empty($ID)) {
  85. $QueryID = G::$DB->get_query_id();
  86. G::$DB->query("
  87. SELECT
  88. ID, Title, Url, Category, SubCategory, Tags, Body, AddedBy, Date
  89. FROM site_history
  90. WHERE ID = '$ID'
  91. ORDER BY Date DESC");
  92. $Event = G::$DB->next_record();
  93. G::$DB->set_query_id($QueryID);
  94. return $Event;
  95. }
  96. }
  97. public static function get_latest_events($Limit)
  98. {
  99. self::get_events(null, null, null, null, null, null, $Limit);
  100. }
  101. public static function get_events($Month, $Year, $Title, $Category, $SubCategory, $Tags, $Limit)
  102. {
  103. $Month = (int)$Month;
  104. $Year = (int)$Year;
  105. $Title = db_string($Title);
  106. $Category = (int)$Category;
  107. $SubCategory = (int)$SubCategory;
  108. $Tags = db_string($Tags);
  109. $Limit = (int)$Limit;
  110. $Where = [];
  111. if (!empty($Month)) {
  112. $Where[] = " MONTH(Date) = '$Month' ";
  113. }
  114. if (!empty($Year)) {
  115. $Where[] = " YEAR(Date) = '$Year' ";
  116. }
  117. if (!empty($Title)) {
  118. $Where[] = " Title LIKE '%$Title%' ";
  119. }
  120. if (!empty($Category)) {
  121. $Where[] = " Category = '$Category '";
  122. }
  123. if (!empty($SubCategory)) {
  124. $Where[] = " SubCategory = '$SubCategory '";
  125. }
  126. if (!empty($Tags)) {
  127. $Tags = explode(',', $Tags);
  128. $Or = '(';
  129. foreach ($Tags as $Tag) {
  130. $Tag = trim($Tag);
  131. $Or .= " Tags LIKE '%$Tag%' OR ";
  132. }
  133. if (strlen($Or) > 1) {
  134. $Or = rtrim($Or, 'OR ');
  135. $Or .= ')';
  136. $Where[] = $Or;
  137. }
  138. }
  139. if (!empty($Limit)) {
  140. $Limit = " LIMIT $Limit";
  141. } else {
  142. $Limit = '';
  143. }
  144. if (count($Where) > 0) {
  145. $Query = ' WHERE ' . implode('AND', $Where);
  146. } else {
  147. $Query = '';
  148. }
  149. $QueryID = G::$DB->get_query_id();
  150. G::$DB->query("
  151. SELECT
  152. ID, Title, Url, Category, SubCategory, Tags, Body, AddedBy, Date
  153. FROM site_history
  154. $Query
  155. ORDER BY Date DESC
  156. $Limit");
  157. $Events = G::$DB->to_array();
  158. G::$DB->set_query_id($QueryID);
  159. return $Events;
  160. }
  161. public static function add_event($Date, $Title, $Link, $Category, $SubCategory, $Tags, $Body, $UserID)
  162. {
  163. if (empty($Date)) {
  164. $Date = sqltime();
  165. } else {
  166. list($Y, $M, $D) = explode('-', $Date);
  167. if (!checkdate($M, $D, $Y)) {
  168. error("Error");
  169. }
  170. }
  171. $Title = db_string($Title);
  172. $Link = db_string($Link);
  173. $Category = (int)$Category;
  174. $SubCategory = (int)$SubCategory;
  175. $Tags = db_string(strtolower((preg_replace('/\s+/', '', $Tags))));
  176. $ExplodedTags = explode(',', $Tags);
  177. foreach ($ExplodedTags as $Tag) {
  178. if (!in_array($Tag, self::get_tags())) {
  179. error("Invalid tag");
  180. }
  181. }
  182. $Body = db_string($Body);
  183. $UserID = (int)$UserID;
  184. if (empty($Title) || empty($Category) || empty($SubCategory)) {
  185. error("Error");
  186. }
  187. $QueryID = G::$DB->get_query_id();
  188. G::$DB->query("
  189. INSERT INTO site_history
  190. (Title, Url, Category, SubCategory, Tags, Body, AddedBy, Date)
  191. VALUES
  192. ('$Title', '$Link', '$Category', '$SubCategory', '$Tags', '$Body', '$UserID', '$Date')");
  193. G::$DB->set_query_id($QueryID);
  194. G::$Cache->delete_value("site_history_months");
  195. }
  196. public static function update_event($ID, $Date, $Title, $Link, $Category, $SubCategory, $Tags, $Body, $UserID)
  197. {
  198. if (empty($Date)) {
  199. $Date = sqltime();
  200. } else {
  201. $Date = db_string($Date);
  202. list($Y, $M, $D) = explode('-', $Date);
  203. if (!checkdate($M, $D, $Y)) {
  204. error("Error");
  205. }
  206. }
  207. $ID = (int)$ID;
  208. $Title = db_string($Title);
  209. $Link = db_string($Link);
  210. $Category = (int)$Category;
  211. $SubCategory = (int)$SubCategory;
  212. $Tags = db_string(strtolower((preg_replace('/\s+/', '', $Tags))));
  213. $ExplodedTags = explode(",", $Tags);
  214. foreach ($ExplodedTags as $Tag) {
  215. if (!in_array($Tag, self::get_tags())) {
  216. error("Invalid tag");
  217. }
  218. }
  219. $Body = db_string($Body);
  220. $UserID = (int)$UserID;
  221. if (empty($ID) || empty($Title) || empty($Category) || empty($SubCategory)) {
  222. error("Error");
  223. }
  224. $QueryID = G::$DB->get_query_id();
  225. G::$DB->query("
  226. UPDATE site_history
  227. SET
  228. Title = '$Title',
  229. Url = '$Link',
  230. Category = '$Category',
  231. SubCategory = '$SubCategory',
  232. Tags = '$Tags',
  233. Body = '$Body',
  234. AddedBy = '$UserID',
  235. Date = '$Date'
  236. WHERE ID = '$ID'");
  237. G::$DB->set_query_id($QueryID);
  238. G::$Cache->delete_value("site_history_months");
  239. }
  240. public static function delete_event($ID)
  241. {
  242. if (!is_numeric($ID)) {
  243. error(404);
  244. }
  245. $QueryID = G::$DB->get_query_id();
  246. G::$DB->query("
  247. DELETE FROM site_history
  248. WHERE ID = '$ID'");
  249. G::$DB->set_query_id($QueryID);
  250. G::$Cache->delete_value("site_history_months");
  251. }
  252. public static function get_categories()
  253. {
  254. return self::$Categories;
  255. }
  256. public static function get_sub_categories()
  257. {
  258. return self::$SubCategories;
  259. }
  260. public static function get_tags()
  261. {
  262. return self::$Tags;
  263. }
  264. }