-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.php
52 lines (40 loc) · 1.34 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
<?php
define('ROOT_PATH', dirname(__FILE__));
define('VIEW_PATH', ROOT_PATH . '/views');
define('PUBLIC_PATH', determinePublicPath());
require_once ROOT_PATH . '/../samurai-client-php/lib/Samurai.php';
Samurai::setup(array(
'merchantKey' => 'a1ebafb6da5238fb8a3ac9f6',
'merchantPassword' => 'ae1aa640f6b735c4730fbb56',
'processorToken' => '5a0e1ca1e5a11a2997bbf912'
));
function debug($var) {
echo '<pre>' . print_r($var, true) . '</pre>';
}
function render($view, $vars = array()) {
if (is_array($vars)) {
extract($vars);
}
ob_start();
include_once VIEW_PATH . '/' . $view . '.php';
$_body = ob_get_clean();
include_once VIEW_PATH . '/layout.php';
}
function redirect($path, $query='') {
header('Location: ' . urlFor($path, false, $query));
}
function urlFor($path, $full = false, $query = '') {
$url = ($full ? 'http://' . $_SERVER['SERVER_NAME'] : '') . PUBLIC_PATH . '/' . $path . '.php';
if (!empty($query)) {
$url .= '?' . $query;
}
return $url;
}
function determinePublicPath() {
$scriptPath = realpath($_SERVER['SCRIPT_FILENAME']);
$configPath = realpath(dirname(__FILE__));
$requestPath = str_replace('?'.$_SERVER['QUERY_STRING'], '', $_SERVER['REQUEST_URI']);
$scriptRelativePath = str_replace($configPath, '', $scriptPath);
$publicPath = str_replace($scriptRelativePath, '', $requestPath);
return $publicPath;
}