Advertisement
Guest User

Untitled

a guest
Nov 25th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.36 KB | None | 0 0
  1. <?php
  2.  
  3. class Servers
  4. {
  5. private $order_by;
  6. private $additional_join = null;
  7. private $where;
  8.  
  9. public $pagination;
  10. public $server_results;
  11. public $affix;
  12. public $country_options;
  13. public $version_options;
  14. public $no_servers;
  15.  
  16. public function __construct($category_id = false)
  17. {
  18. global $database;
  19. global $settings;
  20. global $language;
  21.  
  22. /* Initiate the affix and start generating it */
  23. $this->affix = '';
  24.  
  25. /* Order by system */
  26. $order_by_options = array(
  27. 'online_players',
  28. 'votes',
  29. 'favorites',
  30. 'server_id'
  31. );
  32. $order_by_column = (isset($_GET['order_by']) && in_array(strtolower($_GET['order_by']), $order_by_options)) ? strtolower($_GET['order_by']) : false;
  33. $this->order_by = 'ORDER BY `servers`.`highlight` DESC, ';
  34. $this->order_by .= ($order_by_column !== false) ? '`servers`.`' . $order_by_column . '` DESC' : '`servers`.`votes` DESC';
  35. $this->affix .= ($order_by_column !== false) ? '&order_by=' . $order_by_column : '';
  36.  
  37. /* Filtering system */
  38. $category_where = ($category_id !== false) ? 'AND `servers`.`category_id` = ' . (int) $category_id : null;
  39.  
  40. /* Process $_GET filters, build the affix */
  41. $highlight_options = array(
  42. 0,
  43. 1
  44. );
  45. $highlight_value = (isset($_GET['filter_highlight']) && in_array($_GET['filter_highlight'], $highlight_options)) ? (int) $_GET['filter_highlight'] : false;
  46. $highlight_where = ($highlight_value !== false) ? 'AND `servers`.`highlight` = ' . $highlight_value : null;
  47. $this->affix .= ($highlight_value !== false) ? '&filter_highlight=' . $highlight_value : '';
  48.  
  49. $status_options = array(
  50. 0,
  51. 1
  52. );
  53. $status_value = (isset($_GET['filter_status']) && in_array($_GET['filter_status'], $status_options)) ? (int) $_GET['filter_status'] : false;
  54. $status_where = ($status_value !== false) ? 'AND `servers`.`status` = ' . $status_value : null;
  55. $this->affix .= ($status_value !== false) ? '&filter_status=' . $status_value : '';
  56.  
  57. /* The default status filtering ( when there are no status filter active ) */
  58. $default_status_where = (!$status_value && !$settings->display_offline_servers) ? 'AND `servers` . `status` = \'1\'' : null;
  59.  
  60. /* Add the possible countries from the database into an array */
  61. $result = $database->query("SELECT DISTINCT `country_code` FROM `servers` WHERE 1=1 {$category_where}");
  62. $this->country_options = array();
  63. while ($country_code = $result->fetch_object())
  64. $this->country_options[] = $country_code->country_code;
  65.  
  66. /* Processing again */
  67. $country_value = (isset($_GET['filter_country']) && in_array($_GET['filter_country'], $this->country_options)) ? $_GET['filter_country'] : false;
  68. $country_where = ($country_value !== false) ? 'AND `servers`.`country_code` = \'' . $country_value . '\'' : null;
  69. $this->affix .= ($country_value !== false) ? '&filter_country=' . $country_value : '';
  70.  
  71. /* Add the possible server versions into an array */
  72. $result = $database->query("SELECT DISTINCT `server_version` FROM `servers` WHERE `server_version` IS NOT NULL AND `private` = '0' AND `active` = '1'");
  73. $this->version_options = array();
  74. while ($version = $result->fetch_object())
  75. $this->version_options[] = $version->server_version;
  76.  
  77. /* Processing again */
  78. $version_value = (isset($_GET['filter_version']) && in_array($_GET['filter_version'], $this->version_options)) ? $_GET['filter_version'] : false;
  79. $version_where = ($version_value !== false) ? 'AND `servers`.`server_version` = \'' . $version_value . '\'' : null;
  80. $this->affix .= ($version_value !== false) ? '&filter_version=' . $version_value : '';
  81.  
  82. /* If affix isn't empty prepend the ? sign so it can be processed */
  83. $this->affix = (!empty($this->affix)) ? '?' . $this->affix : null;
  84.  
  85. /* Create the maine $where variable */
  86. $this->where = "WHERE 1=1 {$category_where} {$default_status_where} {$highlight_where} {$status_where} {$country_where} {$version_where}";
  87.  
  88. /* Generate pagination */
  89. $this->pagination = new Pagination($settings->servers_pagination, $this->where);
  90.  
  91. /* Set the default no servers message */
  92. $this->no_servers = $language['messages']['no_servers'];
  93.  
  94. }
  95.  
  96. public function additional_where($where)
  97. {
  98. global $settings;
  99.  
  100. /* Remake the where with the additional condition */
  101. $this->where = $this->where . ' ' . $where;
  102.  
  103. /* Remake the pagination */
  104. $this->pagination = new Pagination($settings->servers_pagination, $this->where);
  105.  
  106. }
  107.  
  108. public function additional_join($join)
  109. {
  110. global $settings;
  111.  
  112. /* This is mainly so we can gather the data based on the favorite servers */
  113. $this->additional_join = $join;
  114.  
  115. /* Remake the pagination with the true condition so it counts the servers correctly */
  116. $this->pagination = new Pagination($settings->servers_pagination, $this->where, true);
  117.  
  118. }
  119.  
  120. public function remove_pagination()
  121. {
  122.  
  123. /* Make the pagination null */
  124. $this->pagination->limit = null;
  125.  
  126. }
  127.  
  128. public function display()
  129. {
  130. global $database;
  131. global $language;
  132. global $account_user_id;
  133.  
  134. /* Quickly verify the remaining of highlighted days remaining */
  135. $database->query("UPDATE `servers` JOIN `payments` ON `servers`.`server_id` = `payments`.`server_id` SET `servers`.`highlight` = '0' WHERE `payments`.`date` + INTERVAL `payments`.`highlighted_days` DAY < CURDATE()");
  136.  
  137. if (Plugin::get('bidding-system', 'update-servers.php'))
  138. include_once Plugin::get('bidding-system', 'update-servers.php');
  139.  
  140. /* Retrieve servers information */
  141. $result = $database->query("SELECT * FROM `servers` {$this->additional_join} {$this->where} {$this->order_by} {$this->pagination->limit}");
  142.  
  143. /* Check if there is any result */
  144. $this->server_results = $result->num_rows;
  145. if ($this->server_results < 1)
  146. $_SESSION['info'][] = $this->no_servers;
  147.  
  148. /* Display the servers */
  149. while ($server = $result->fetch_object()) {
  150.  
  151. /* Get category information for the servers */
  152. $category_result = $database->query("SELECT `name`, `url` FROM `categories` WHERE `category_id` = {$server->category_id}");
  153. $category = $category_result->fetch_object();
  154.  
  155. /* Store the status into a variable */
  156. $server->status_text = ($server->status) ? $language['server']['status_online'] : $language['server']['status_offline'];
  157.  
  158. /* Check if there is any image uploaded, if not, display default */
  159. $server->image = (empty($server->image)) ? 'default.jpg' : $server->image;
  160.  
  161. ?>
  162.  
  163. <div class="panel panel-default">
  164. <div class="panel-body<?php
  165. if ($server->highlight)
  166. echo ' vip-shadow';
  167. ?>" style="padding: 10px;">
  168.  
  169. <table class="server">
  170. <tr>
  171. <td rowspan="2">
  172. <a href="server/<?php
  173. echo $server->server_id;
  174. ?>">
  175. <img src="user_data/server_banners/<?php
  176. echo $server->image;
  177. ?>" class=" hidden-xs hidden-sm banner"/>
  178. </a>
  179. </td>
  180. <td class="header">
  181. <div class="pull-right inline" style="position: relative;top: -2px;">
  182. <?php
  183. if (User::x_to_y('server_id', 'user_id', $server->server_id, 'servers') == $account_user_id)
  184. echo '<a href="edit-server/' . $server->server_id . '"<span class="label label-primary">' . $language['forms']['server_edit'] . '</span></a>';
  185. ?>
  186.  
  187. <?php
  188. if ($server->status && $server->maximum_online_players !== 0)
  189. echo '<span data-toggle="tooltip" title="' . $language['server']['tab_players'] . '" class="label label-success tooltipz"><i class="fa fa-user"></i> ' . $server->online_players . '/' . $server->maximum_online_players . '</span>';
  190. ?>
  191. </div>
  192. <h4 class="no-margin"><a href="server/<?php
  193. echo $server->server_id;
  194. ?>"><?php
  195. echo $server->name;
  196. ?></a></h4>
  197. </td>
  198. </tr>
  199. <tr>
  200. <td class="footer">
  201. <?php
  202. if (!$server->active) {
  203. echo $language['server']['not_active'];
  204. } else {
  205.  
  206. if ($server->private)
  207. echo $language['server']['private'];
  208.  
  209. echo '<div class="input-group input-group-sm" style="width: 100%;">';
  210. echo '<span class="input-group-addon input-label-' . strtolower($server->status_text) . '">' . $server->status_text . '</span>';
  211. echo '<input type="text" onclick="this.select()" class="form-control" value="' . $server->address . (($server->connection_port != '25565') ? ":" . $server->connection_port : null) . '">';
  212. echo '</div>';
  213.  
  214. }
  215. ?>
  216. </td>
  217. </tr>
  218. </table>
  219.  
  220. </div>
  221. </div>
  222.  
  223. <div style="margin-bottom: 15px;">
  224. <?php
  225. if (strlen(trim($server->server_version)) > 0):
  226. ?><span href="#" data-toggle="tooltip" title="<?php
  227. echo $language['server']['server_version'];
  228. ?>" class="tag tooltipz"><i class="fa fa-wrench"></i> <?php
  229. echo $server->server_version;
  230. ?></span><?php
  231. endif;
  232. ?>
  233. <span href="#" data-toggle="tooltip" title="<?php
  234. echo $language['server']['general_country'];
  235. ?>" class="tag tooltipz"><i class="fa fa-globe"></i> <?php
  236. echo country_check(2, $server->country_code);
  237. ?></span>
  238. <span data-toggle="tooltip" title="<?php
  239. echo $language['server']['general_votes'];
  240. ?>" class="tag tooltipz"><i class="fa fa-thumbs-up"></i> <?php
  241. echo $server->votes;
  242. ?></span>
  243. <span data-toggle="tooltip" title="<?php
  244. echo $language['server']['general_favorites'];
  245. ?>" class="tag tooltipz"><i class="fa fa-star"></i> <?php
  246. echo $server->favorites;
  247. ?></span>
  248. <a href="category/<?php
  249. echo $category->url;
  250. ?>"><span data-toggle="tooltip" title="<?php
  251. echo $language['server']['general_category'];
  252. ?>" class="tag tooltipz"><span class="fa fa-tags"></span> <?php
  253. echo $category->name;
  254. ?></span></a>
  255. <?php
  256. if (Plugin::get('bump', 'bump.php') && User::x_to_y('server_id', 'user_id', $server->server_id, 'servers') == $account_user_id):
  257. ?>
  258. <a href="bump/<?php
  259. echo $server->server_id;
  260. ?>"><span class="tag"><span class="fa fa-level-up"></span> <?php
  261. echo $language['server']['bump'];
  262. ?></span></a>
  263. <?php
  264. endif;
  265. ?>
  266. </div>
  267.  
  268. <?php
  269. }
  270. }
  271.  
  272. public function display_pagination($current_page)
  273. {
  274.  
  275. /* If there are results, display pagination */
  276. if ($this->server_results > 0) {
  277.  
  278. /* Establish the current page link */
  279. $this->pagination->set_current_page_link($current_page);
  280.  
  281. /* Display */
  282. $this->pagination->display($this->affix);
  283. }
  284. }
  285.  
  286.  
  287. public function filters_display()
  288. {
  289. global $language;
  290. global $database;
  291.  
  292. if ($this->server_results > 0) {
  293.  
  294. /* Generating the link again for every filter so it doesn't mess the url */
  295. $order_by_link = (isset($_GET['order_by'])) ? preg_replace('/&order_by=[A-Za-z0-9_]+/', '', $this->affix) : $this->affix;
  296. $filter_highlight = (isset($_GET['filter_highlight'])) ? preg_replace('/&filter_highlight=[01]+/', '', $this->affix) : $this->affix;
  297. $filter_status = (isset($_GET['filter_status'])) ? preg_replace('/&filter_status=[01]+/', '', $this->affix) : $this->affix;
  298. $filter_country = (isset($_GET['filter_country'])) ? preg_replace('/&filter_country=[A-Za-z]+/', '', $this->affix) : $this->affix;
  299. $filter_version = (isset($_GET['filter_version'])) ? preg_replace('/&filter_version=[A-Za-z]+/', '', $this->affix) : $this->affix;
  300. ?>
  301.  
  302. <h4><?php
  303. echo $language['misc']['filters'];
  304. ?></h4>
  305.  
  306.  
  307. <ul class="nav nav-pills nav-stacked">
  308.  
  309. <?php
  310. if (!empty($this->affix)) {
  311. ?>
  312. <li class="dropdown active">
  313. <a href="<?php
  314. echo $this->pagination->link;
  315. ?>"><?php
  316. echo $language['misc']['reset_filters'];
  317. ?></a>
  318. </li>
  319. <?php
  320. }
  321. ?>
  322.  
  323. <li class="dropdown active">
  324. <a class="dropdown-toggle" data-toggle="dropdown" href="#"><?php
  325. echo $language['misc']['order_by'];
  326. ?><b class="caret"></b></a>
  327. <ul class="dropdown-menu">
  328. <li><a href="<?php
  329. echo $this->pagination->link . $order_by_link . '&order_by=online_players';
  330. ?>"><?php
  331. echo $language['misc']['order_by_players'];
  332. ?></a></li>
  333. <li><a href="<?php
  334. echo $this->pagination->link . $order_by_link . '&order_by=votes';
  335. ?>"><?php
  336. echo $language['misc']['order_by_votes'];
  337. ?></a></li>
  338. <li><a href="<?php
  339. echo $this->pagination->link . $order_by_link . '&order_by=favorites';
  340. ?>"><?php
  341. echo $language['misc']['order_by_favorites'];
  342. ?></a></li>
  343. <li><a href="<?php
  344. echo $this->pagination->link . $order_by_link . '&order_by=server_id';
  345. ?>"><?php
  346. echo $language['misc']['order_by_latest'];
  347. ?></a></li>
  348. </ul>
  349. </li>
  350.  
  351. <li class="dropdown active">
  352. <a class="dropdown-toggle" data-toggle="dropdown" href="#"><?php
  353. echo $language['misc']['filter_highlight'];
  354. ?><b class="caret"></b></a>
  355. <ul class="dropdown-menu">
  356. <li><a href="<?php
  357. echo $this->pagination->link . $filter_highlight . '&filter_highlight=1';
  358. ?>"><?php
  359. echo $language['misc']['filter_yes'];
  360. ?></a></li>
  361. <li><a href="<?php
  362. echo $this->pagination->link . $filter_highlight . '&filter_highlight=0';
  363. ?>"><?php
  364. echo $language['misc']['filter_no'];
  365. ?></a></li>
  366. </ul>
  367. </li>
  368.  
  369. <li class="dropdown active">
  370. <a class="dropdown-toggle" data-toggle="dropdown" href="#"><?php
  371. echo $language['misc']['filter_status'];
  372. ?><b class="caret"></b></a>
  373. <ul class="dropdown-menu">
  374. <li><a href="<?php
  375. echo $this->pagination->link . $filter_status . '&filter_status=1';
  376. ?>"><?php
  377. echo $language['misc']['filter_online'];
  378. ?></a></li>
  379. <li><a href="<?php
  380. echo $this->pagination->link . $filter_status . '&filter_status=0';
  381. ?>"><?php
  382. echo $language['misc']['filter_offline'];
  383. ?></a></li>
  384. </ul>
  385. </li>
  386.  
  387. <li class="dropdown active">
  388. <a class="dropdown-toggle" data-toggle="dropdown" href="#"><?php
  389. echo $language['misc']['filter_country'];
  390. ?><b class="caret"></b></a>
  391. <ul class="dropdown-menu">
  392. <?php
  393. foreach ($this->country_options as $country) {
  394. echo '<li><a href="' . $this->pagination->link . $filter_country . '&filter_country=' . $country . '">' . country_check(2, $country) . '</a></li>';
  395. }
  396. ?>
  397. </ul>
  398. </li>
  399.  
  400. <li class="dropdown active">
  401. <a class="dropdown-toggle" data-toggle="dropdown" href="#"><?php
  402. echo $language['misc']['filter_version'];
  403. ?><b class="caret"></b></a>
  404. <ul class="dropdown-menu">
  405. <?php
  406. foreach ($this->version_options as $version) {
  407. echo '<li><a href="' . $this->pagination->link . $filter_version . '&filter_version=' . $version . '">' . $version . '</a></li>';
  408. }
  409. ?>
  410. </ul>
  411. </li>
  412.  
  413. </ul><br />
  414. <?php
  415. }
  416. }
  417.  
  418. }
  419. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement