-
Notifications
You must be signed in to change notification settings - Fork 43
/
common.inc.php
146 lines (125 loc) · 4.17 KB
/
common.inc.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
/**
* Common functionality needed by the site.
*
* Do not change this file unless you know exactly what you are doing!
*/
// Compression
ob_start("ob_gzhandler");
// UTF8 header
header('Content-type: text/html; charset=utf-8');
// Start session
session_start();
// Local path
$loc = dirname(__FILE__) . "/";
// Correct PHP version check
if(PHP_VERSION_ID < 50307) {
echo "<h1>Error</h1><p>php4dvd requires at least PHP 5.3.7. You are running PHP " . PHP_VERSION . ". Please upgrade.</p>";
exit();
}
// Load the default config file
if(!file_exists($loc . "config/config.default.php")) {
echo "<h1>Error</h1>The file <tt>config/config.default.php</tt> is missing.";
exit();
}
require_once($loc . "config/config.default.php");
$default_settings = $settings;
// Load Parental Guidance config file
require_once($loc . "config/parental.guidance.php");
// Load the config file
if(file_exists($loc . "config/config.php")) {
require_once($loc . "config/config.php");
$custom_settings = $settings;
// When installing, reset all to default settings, except the database
if(isset($installer) && $installer) {
$settings = $default_settings;
foreach($custom_settings["db"] as $key=>$value) {
$settings["db"][$key] = $value;
}
$settings["user"] = $custom_settings["user"];
}
// Load usertheme
else {
if(isset($settings["template"]))
$settings["smarty"]["template"] = $settings["template"];
}
}
// Base url
$protocol = "http";
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']) {
$protocol = "https";
}
if(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
$protocol = "https";
}
// Force the use of HTTPS
if(
isset($settings["url"]["HTTPS"]) && $settings["url"]["HTTPS"] && $protocol !== 'https'
) {
header('Location: https://'. $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"], true, 301);
exit();
}
// Load smarty template parser
require_once($loc . "lib/Website.class.php");
$Website = new Website($settings);
$baseurl = $protocol . "://" . $_SERVER["HTTP_HOST"];
$Website->assign("baseurl", $baseurl);
// Current URL
$currentUrl = $baseurl . $_SERVER["REQUEST_URI"];
$Website->assign("currentUrl", $currentUrl);
// Webroot
$basepath = $settings["url"]["base"];
if(strlen($basepath) > 0 && !preg_match("/\/$/", $basepath)) {
$basepath .= "/";
}
$webroot = $baseurl . "/" . $basepath;
$Website->assign("webroot", $webroot);
// Include util functions
require_once($loc . "lib/util.inc.php");
// Pretty URL
$pretty_url = $settings["pretty_url"];
if($pretty_url && !isset($_GET['go']) && !isset($installer)) {
parsePrettyUrl();
}
// YouTube API
$youtubeKey = $settings["youtube_key"];
$Website->assign("youtubeKey", $youtubeKey?true:false);
// Template directory
$tpl = $settings["smarty"]["template"] . '/';
$tpl_dir = $settings["smarty"]["template_dir"];
$tpl_include = $webroot . $tpl_dir . $tpl;
$Website->assign("tpl_include", $tpl_include);
// Template
$tpl_name = $settings["smarty"]["template"];
$tpl_skin = 'skin-'.$settings["template_skin"];
$tpl_skin_light = $settings["template_skin_light"];
$tpl_movie_collection = $settings["template_movie_collection"];
$tpl_poster_icons = $settings["template_poster_icons"];
if($tpl_skin_light) {
$tpl_skin .= '-light';
$tpl_name .= '-light';
}
$Website->assign("template", $tpl_name);
$Website->assign("template_skin", $tpl_skin);
$Website->assign("template_colour", $settings["template_skin"]);
$Website->assign("template_light", $settings["template_skin_light"]);
$Website->assign("poster_icons", $tpl_poster_icons);
// Template for movie collection
$templateName = isset($_COOKIE['layout']) ? $_COOKIE['layout'] : '';
if(!in_array($templateName,array('poster','postertitle','posterlist','list','listplot'),true))
$templateName = ($tpl_movie_collection)?$tpl_movie_collection:'postertitle';
$Website->assign("templateName", $templateName);
// Version
require_once($loc . "config/version.default.inc.php");
$Website->assign("newversion", NEW_VERSION);
if(file_exists($loc . "config/version.inc.php")) {
require_once($loc . "config/version.inc.php");
$Website->assign("version", VERSION);
if(!defined('DB_VERSION')) {
define('DB_VERSION', VERSION);
}
} else {
define('VERSION', '0');
define('DB_VERSION', '0');
}
?>