This repository was archived by the owner on Jan 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.php
120 lines (108 loc) · 3.74 KB
/
config.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
use Monolog\{
ErrorHandler,
Handler\SlackHandler,
Logger
};
use Sizzle\Bacon\{
Connection,
Database\WebRequest
};
// set release version in /version file
define('VERSION', trim(file_get_contents(__DIR__.'/version')));
// autoload classes
require_once __DIR__.'/src/autoload.php';
require_once __DIR__.'/vendor/autoload.php';
//load functions
require_once __DIR__.'/util.php';
// Determine environment & fix URL as needed
$server = $_SERVER['SERVER_NAME'] ?? null;
if ('gosizzle.io' == strtolower($server) || 'givetoken.com' == strtolower($server) || 'www.givetoken.com' == strtolower($server)) {
$url = 'https://www.gosizzle.io'.$_SERVER['REQUEST_URI'];
header("Location: $url ", true, 301);
}
if (!defined('ENVIRONMENT')) {
define('ENVIRONMENT', 'www.gosizzle.io' == $server ? 'production' : ('127.0.0.1' == $_SERVER['SERVER_ADDR'] ? 'local' : 'development'));
}
// setup Monolog error handler to report to Slack
// this causes a 500 error on AWS (is PHP 7 issue?)
if (!defined('SLACK_TOKEN')) {
define('SLACK_TOKEN', 'xoxb-17521146128-nHU6t4aSx7NE0PYLxKRYqmjG');
}
$logger = new Logger('bugs');
if (ENVIRONMENT != 'local') {
if (ENVIRONMENT != 'production') {
$name = 'Dev Application: '.$_SERVER['REQUEST_URI'];
$slackHandler = new SlackHandler(SLACK_TOKEN, '#bugs-staging', $name, false);
} else {
$name = 'Web Application: '.$_SERVER['REQUEST_URI'];
$slackHandler = new SlackHandler(SLACK_TOKEN, '#bugs', $name, false);
}
$slackHandler->setLevel(Logger::DEBUG);
$logger->pushHandler($slackHandler);
ErrorHandler::register($logger);
}
$prefix = "http://";
$use_https = false;
$socket = null;
if (ENVIRONMENT == 'production') {
$stripe_secret_key = 'sk_live_MuUj2k3WOTpvIgw8oIHaON2X';
$stripe_publishable_key = 'pk_live_AbtrrWvSZZCvLYdiLohHC2Kz';
} else {
$stripe_secret_key = 'sk_test_RTcVNjcQVfYNiPCiY5O9CevV';
$stripe_publishable_key = 'pk_test_Gawg5LhHJ934MPXlvglZrdnL';
}
if (isset($_SERVER['HTTPS'])) {
if ($_SERVER['HTTPS'] === "on") {
$prefix = "https://";
$use_https = true;
} else {
if('www.gosizzle.io' == $server) {
$url = 'https://www.gosizzle.io'.$_SERVER['REQUEST_URI'];
header("Location: $url ", true, 301);
}
}
}
$file_storage_path = 'uploads/';
if (!defined('STRIPE_SECRET_KEY')) {
define('STRIPE_SECRET_KEY', $stripe_secret_key);
}
if (!defined('STRIPE_PUBLISHABLE_KEY')) {
define('STRIPE_PUBLISHABLE_KEY', $stripe_publishable_key);
}
if (!defined('FILE_STORAGE_PATH')) {
define('FILE_STORAGE_PATH', $file_storage_path);
}
if (!defined('APP_URL')) {
define('APP_URL', $prefix.$server.'/');
}
// connect to database
include __DIR__.'/config/credentials.php';
$mysqli = new mysqli($mysql_server, $user, $password, $database);
if ($mysqli->connect_error) {
die('Connect Error (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error);
}
new Connection($mysqli);
// start session
session_start();
// record website hit
if (isset($_COOKIE, $_COOKIE['visitor'])) {
$visitor_cookie = $_COOKIE['visitor'];
} else {
$visitor_cookie = substr(md5(microtime()), rand(0, 26), 20);
}
// set or reset cookie to expire in a year
setcookie('visitor', $visitor_cookie, time()+60*60*24*365);
$webRequest = new WebRequest();
$webRequest->visitor_cookie = $visitor_cookie;
if (isset($_SESSION, $_SESSION['user_id'])) {
$webRequest->user_id = $_SESSION['user_id'];
}
if (isset($_SERVER)) {
$webRequest->host = ($_SERVER['HTTP_HOST'] ?? '');
$webRequest->user_agent = ($_SERVER['HTTP_USER_AGENT'] ?? '');
$webRequest->uri = ($_SERVER['REQUEST_URI'] ?? '');
$webRequest->remote_ip = ($_SERVER['REMOTE_ADDR'] ?? '');
$webRequest->script = ($_SERVER['SCRIPT_NAME'] ?? '');
$webRequest->save();
}