-
Notifications
You must be signed in to change notification settings - Fork 1
/
CONSTANTS.php
executable file
·220 lines (185 loc) · 6.18 KB
/
CONSTANTS.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<?php
require("classes/roku.class.php");
require("classes/http_response.class.php");
require("classes/scan.class.php");
require("classes/rokuXML.class.php");
require("classes/externalcontrol.class.php");
require("classes/movie.class.php");
require("classes/videoMetaData.class.php");
require("classes/playlistXML.class.php");
require("classes/movieXML.class.php");
require("classes/aliases.class.php");
define('DIR_PREFIX', dirname(__FILE__).'/xml/');
define('ROKU_XML', dirname(__FILE__).'/xml/rokus.xml');
define('ALL_XML', dirname(__FILE__).'/xml/all.xml');
define('PLAYLIST_XML', dirname(__FILE__).'/xml/playlist.xml');
define('ROKU_CHANNEL', 'roConnect.zip');
define('MEDIA_INFO', dirname(__FILE__).'/mediainfo');
define('PROGRESS_XML', dirname(__FILE__).'/xml/progress.xml');
/**
* Path to apache apachectl file to gracefully restart server
*/
define('APACHECTL', '/Applications/MAMP/Library/bin/apachectl');
define('APACHECTL_LIN', '/usr/sbin/apachectl');
class globals {
private $xml;
private $xmlVars;
public $movieMeta;
private $plXml;
function __construct ($regular = true) {
$this->xml = simplexml_load_file(dirname(__FILE__)."/xml/rokuConfig.xml");
$this->xmlVars = get_object_vars($this->xml);
if($regular)
$this->initialize();
}
function initialize() {
$this->movieMeta = new videoMetaData();
$this->plXml = new playlistXML();
}
function setup($serverConf, $videoPath, $ip) {
$this->initialize();
$this->setServerConf($serverConf);
$this->xml->videoPath = $videoPath;
$this->setIp($ip);
$this->refreshXml();
}
function getVersion() {
return $this->xmlVars['version'];
}
function getServerId() {
$serverId = $this->xmlVars['serverId'];
if($serverId == "") {
$serverId = uniqid();
$this->xml->serverId = $serverId;
$this->refreshXml();
}
return $serverId;
}
function getIp() {
return "http://" . $this->xmlVars['myIp'] ."/";
}
function getPureIp() {
return $this->xmlVars['myIp'];
}
function getVideoPath() {
return $this->xmlVars['videoPath'];
}
function getServerConf() {
return $this->xmlVars['serverConf'];
}
function getIMDb() {
return $this->xmlVars['IMDb'];
}
function getRecursive() {
return $this->xmlVars['recursive'];
}
function isNew() {
if($this->xmlVars['new'] == "true") {
$this->xml->new = "false";
$this->refreshXml();
return true;
} else
return false;
}
function refreshXml() {
file_put_contents(dirname(__FILE__)."/xml/rokuConfig.xml", $this->xml->asXML());
$this->xml = simplexml_load_file(dirname(__FILE__)."/xml/rokuConfig.xml");
$this->xmlVars = get_object_vars($this->xml);
}
function setIp($ip) {
$this->xml->myIp = $ip;
$this->refreshXml();
}
function setVideoPath($path) {
$this->xml->videoPath = $path;
$this->refreshXml();
//$this->movieMeta->indexMovies();
error_log("Video Path");
}
function setServerConf($path) {
$this->xml->serverConf = $path;
$this->refreshXml();
$this->addAliasInclude($path);
}
function setIMDb($bool) {
$this->xml->IMDb = $bool;
$this->refreshXml();
}
function setRecursive($bool) {
$this->xml->recursive = $bool;
$this->refreshXml();
}
function rootDir() {
return dirname(__FILE__);
}
function writeAliases($aliases) {
// alias file we are writing to
$myFile = "movies.conf";
$temp = "";
// opens file
$fh = @fopen($myFile, 'w') or die("Could not add alias to server configuration file, please see user guide to do this manually, sorry.");
// loops through each alias passed and create alias for apache
foreach($aliases as $alias) {
$temp .= 'Alias "'.$alias->name.'" "'.$alias->path.'"
<Directory "'.$alias->path.'">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
</Directory>
';
}
// writes to file
@fwrite($fh, $temp);
fclose($fh);
error_log("Aliases written to movies.conf");
// restart server so aliases take effect
if(count($aliases) > 0)
$this->restartServer();
}
function addAliasInclude($serverConf) {
$test = "";
$text = "Include '".dirname(__FILE__)."/movies.conf'";
$fh = @fopen($serverConf, 'a+') or die("Could not add alias to server configuration file, please see user guide to do this manually, sorry.");
$data = fread($fh, filesize($serverConf));
if(preg_match("~$text~", $data) < 1) {
@fwrite($fh, "\n".$text);
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')
$this->restartServer();
error_log("Alias include ADDED to $serverConf");
} else {
error_log("Include statement, $text FOUND in $serverConf");
}
fclose($fh);
}
function restartServer() {
//Linux machine
if (strtoupper(substr(PHP_OS, 0, 3)) === 'LIN') {
exec(APACHECTL_LIN . " -k graceful");
}
//Mac Machine
if (strtoupper(substr(PHP_OS, 0, 3)) === 'DAR') {
exec(APACHECTL . " -k graceful");
}
//Windows Machine
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
exec("net stop wampapache & net start wampapache");
}
error_log("Server Restarted");
}
function getMediaInfo() {
//Linux Machine
if (strtoupper(substr(PHP_OS, 0, 3)) === 'LIN') {
return '/usr/bin/mediainfo';
}
//Mac Machine
if (strtoupper(substr(PHP_OS, 0, 3)) === 'DAR') {
return dirname(__FILE__).'/mediainfo';
}
//Windows Machine
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
return dirname(__FILE__).'\MediaInfo.exe';
}
}
}
?>