Advertisement
Guest User

Untitled

a guest
Apr 17th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.81 KB | None | 0 0
  1. <?php
  2.  
  3. final class Settings {
  4. public static $TRUE = "1", $FALSE = "0";
  5.  
  6. public function __construct($connect = true) {
  7. // Server name, shown on the main page and on the header
  8. $this->name = 'HybridPrison';
  9.  
  10. // Clicking on the header name will send you to this address.
  11. $this->name_link = 'http://hybridprison.org/forums';
  12.  
  13. // Database information
  14. $host = '168.235.70.240';
  15. $port = 3306;
  16.  
  17. $database = 'mc_474';
  18.  
  19. $username = 'mc_474';
  20. $password = 'b8e5e11932';
  21.  
  22. // If you set a table prefix in config.yml, set it here as well
  23. $table_prefix = "litebans_";
  24.  
  25. // Supported drivers: mysql, pgsql
  26. $driver = 'mysql';
  27.  
  28. // Show inactive bans? Removed bans will show (Unbanned), mutes will show (Unmuted), warnings will show (Expired).
  29. $this->show_inactive_bans = true;
  30.  
  31. // Show pager? This allows users to page through the list of bans.
  32. $this->show_pager = true;
  33.  
  34. // Amount of bans/mutes/warnings to show on each page
  35. $this->limit_per_page = 10;
  36.  
  37. // The server console will be identified by any of these names.
  38. // It will be given a standard name and avatar image.
  39. $this->console_aliases = array(
  40. "CONSOLE", "Console",
  41. );
  42. $this->console_name = "Console";
  43. $this->console_image = "inc/img/console.png";
  44.  
  45. // Avatar images for all players will be fetched from this URL.
  46. // Examples:
  47. /* 'https://cravatar.eu/avatar/$UUID/25'
  48. * 'https://crafatar.com/avatars/$UUID?size=25'
  49. * 'https://minotar.net/avatar/$NAME/25'
  50. */
  51. $this->avatar_source = 'https://cravatar.eu/avatar/$UUID/25';
  52.  
  53. // If enabled, names will be shown below avatars instead of being shown next to them.
  54. $this->avatar_names_below = true;
  55.  
  56. // If enabled, the total amount of bans, mutes, warnings, and kicks will be shown next to the buttons in the header.
  57. $this->header_show_totals = true;
  58.  
  59. // The date format can be changed here.
  60. // https://secure.php.net/manual/en/function.date.php
  61. // Example of default: July 2, 2015, 9:19 PM
  62. $this->date_format = 'F j, Y, g:i A';
  63. date_default_timezone_set("CST");
  64.  
  65. // Enable PHP error reporting.
  66. $error_reporting = true;
  67.  
  68. // Enable error pages.
  69. $this->error_pages = true;
  70.  
  71. /*** End of configuration ***/
  72.  
  73. if ($error_reporting) {
  74. error_reporting(E_ALL);
  75. ini_set("display_errors", 1);
  76. }
  77.  
  78. $this->table = array(
  79. 'bans' => "${table_prefix}bans",
  80. 'mutes' => "${table_prefix}mutes",
  81. 'warnings' => "${table_prefix}warnings",
  82. 'kicks' => "${table_prefix}kicks",
  83. 'history' => "${table_prefix}history",
  84. );
  85.  
  86. $this->active_query = "";
  87.  
  88. if ($driver === "pgsql") {
  89. Settings::$TRUE = "B'1'";
  90. Settings::$FALSE = "B'0'";
  91. }
  92.  
  93. if (!$this->show_inactive_bans) {
  94. $this->active_query = "WHERE active=" . Settings::$TRUE;
  95. }
  96.  
  97. $this->driver = $driver;
  98. if ($connect) {
  99. if ($username === "" && $password === "") {
  100. $this->redirect("error/unconfigured.php");
  101. }
  102.  
  103. $dsn = "$driver:dbname=$database;host=$host;port=$port";
  104. if ($driver === 'mysql') {
  105. $dsn .= ';charset=utf8';
  106. }
  107.  
  108. try {
  109. $this->conn = new PDO($dsn, $username, $password);
  110. $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  111. $this->conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
  112. } catch (PDOException $e) {
  113. Settings::handle_database_error($this, $e);
  114. }
  115. if ($driver === 'pgsql') {
  116. $this->conn->query("SET NAMES 'UTF8';");
  117. }
  118. }
  119. }
  120.  
  121.  
  122. /**
  123. * @param $settings Settings
  124. * @param $e Exception
  125. */
  126. static function handle_database_error($settings, $e) {
  127. $message = $e->getMessage();
  128. if ($settings->error_pages) {
  129. if (strstr($message, "Access denied for user")) {
  130. $settings->redirect("error/access-denied.php");
  131. }
  132. if (strstr($message, "Base table or view not found:")) {
  133. $settings->redirect("error/tables-not-found.php");
  134. }
  135. }
  136. die('Database error: ' . $message);
  137. }
  138.  
  139.  
  140. function redirect($url) {
  141. echo "<a href=\"$url\">Redirecting...</a>";
  142.  
  143. echo "<script type=\"text/javascript\">document.location=\"$url\";</script>";
  144.  
  145. die;
  146. }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement