Test Setup Failed
Branch master (a086b2)
by eertheertyerery
02:07
created
www/upnp/control/ContentDirectory.php 3 patches
Indentation   +615 added lines, -615 removed lines patch added patch discarded remove patch
@@ -49,60 +49,60 @@  discard block
 block discarded – undo
49 49
 
50 50
 /* File types. */
51 51
 $file_class = array (
52
-	'm3u' => 'object.container.storageFolder',
53
-	'xspf' => 'object.container.storageFolder',
54
-	'xml' => 'object.container.storageFolder',
55
-
56
-	'bmp' => 'object.item.imageItem.photo',
57
-	'gif' => 'object.item.imageItem.photo',
58
-	'ico' => 'object.item.imageItem.photo',
59
-	'png' => 'object.item.imageItem.photo',
60
-	'jpe' => 'object.item.imageItem.photo',
61
-	'jpg' => 'object.item.imageItem.photo',
62
-	'jpeg' => 'object.item.imageItem.photo',
63
-	'tif' => 'object.item.imageItem.photo',
64
-	'tiff' => 'object.item.imageItem.photo',
65
-	'svg' => 'object.item.imageItem.photo',
66
-	'svgz' => 'object.item.imageItem.photo',
67
-
68
-	'flac' => 'object.item.audioItem.musicTrack',
69
-	'mp3' => 'object.item.audioItem.musicTrack', 
70
-	'wav' => 'object.item.audioItem.musicTrack',
71
-	'wma' => 'object.item.audioItem.musicTrack',
72
-
73
-	'flv' => 'object.item.videoItem',
74
-	'f4v' => 'object.item.videoItem',
75
-	'3g2' => 'object.item.videoItem',
76
-	'3gp' => 'object.item.videoItem',
77
-	'3gp2' => 'object.item.videoItem',
78
-	'3gpp' => 'object.item.videoItem',
79
-	'asf' => 'object.item.videoItem',
80
-	'asx' => 'object.item.videoItem',
81
-	'avi' => 'object.item.videoItem.movie',
82
-	'dat' => 'object.item.videoItem',
83
-	'iso' => 'object.item.videoItem',
84
-	'm2t' => 'object.item.videoItem',
85
-	'm2ts' => 'object.item.videoItem',
86
-	'm2v' => 'object.item.videoItem',
87
-	'm4v' => 'object.item.videoItem',
88
-	'mp2v' => 'object.item.videoItem',
89
-	'mp4' => 'object.item.videoItem',
90
-	'mp4v' => 'object.item.videoItem',
91
-	'mpe' => 'object.item.videoItem',
92
-	'mpeg' => 'object.item.videoItem',
93
-	'mpg' => 'object.item.videoItem',
94
-	'mod' => 'object.item.videoItem',
95
-	'mov' => 'object.item.videoItem',
96
-	'mkv' => 'object.item.videoItem.videoBroadcast',
97
-	'mts' => 'object.item.videoItem',
98
-	'ogg' => 'object.item.videoItem',
99
-	'swf' => 'object.item.videoItem',
100
-	'vob' => 'object.item.videoItem',
101
-	'ts' => 'object.item.videoItem',
102
-	'webm' => 'object.item.videoItem',
103
-	'wm' => 'object.item.videoItem',
104
-	'wmv' => 'object.item.videoItem',
105
-	'wmx' => 'object.item.videoItem',
52
+    'm3u' => 'object.container.storageFolder',
53
+    'xspf' => 'object.container.storageFolder',
54
+    'xml' => 'object.container.storageFolder',
55
+
56
+    'bmp' => 'object.item.imageItem.photo',
57
+    'gif' => 'object.item.imageItem.photo',
58
+    'ico' => 'object.item.imageItem.photo',
59
+    'png' => 'object.item.imageItem.photo',
60
+    'jpe' => 'object.item.imageItem.photo',
61
+    'jpg' => 'object.item.imageItem.photo',
62
+    'jpeg' => 'object.item.imageItem.photo',
63
+    'tif' => 'object.item.imageItem.photo',
64
+    'tiff' => 'object.item.imageItem.photo',
65
+    'svg' => 'object.item.imageItem.photo',
66
+    'svgz' => 'object.item.imageItem.photo',
67
+
68
+    'flac' => 'object.item.audioItem.musicTrack',
69
+    'mp3' => 'object.item.audioItem.musicTrack', 
70
+    'wav' => 'object.item.audioItem.musicTrack',
71
+    'wma' => 'object.item.audioItem.musicTrack',
72
+
73
+    'flv' => 'object.item.videoItem',
74
+    'f4v' => 'object.item.videoItem',
75
+    '3g2' => 'object.item.videoItem',
76
+    '3gp' => 'object.item.videoItem',
77
+    '3gp2' => 'object.item.videoItem',
78
+    '3gpp' => 'object.item.videoItem',
79
+    'asf' => 'object.item.videoItem',
80
+    'asx' => 'object.item.videoItem',
81
+    'avi' => 'object.item.videoItem.movie',
82
+    'dat' => 'object.item.videoItem',
83
+    'iso' => 'object.item.videoItem',
84
+    'm2t' => 'object.item.videoItem',
85
+    'm2ts' => 'object.item.videoItem',
86
+    'm2v' => 'object.item.videoItem',
87
+    'm4v' => 'object.item.videoItem',
88
+    'mp2v' => 'object.item.videoItem',
89
+    'mp4' => 'object.item.videoItem',
90
+    'mp4v' => 'object.item.videoItem',
91
+    'mpe' => 'object.item.videoItem',
92
+    'mpeg' => 'object.item.videoItem',
93
+    'mpg' => 'object.item.videoItem',
94
+    'mod' => 'object.item.videoItem',
95
+    'mov' => 'object.item.videoItem',
96
+    'mkv' => 'object.item.videoItem.videoBroadcast',
97
+    'mts' => 'object.item.videoItem',
98
+    'ogg' => 'object.item.videoItem',
99
+    'swf' => 'object.item.videoItem',
100
+    'vob' => 'object.item.videoItem',
101
+    'ts' => 'object.item.videoItem',
102
+    'webm' => 'object.item.videoItem',
103
+    'wm' => 'object.item.videoItem',
104
+    'wmv' => 'object.item.videoItem',
105
+    'wmx' => 'object.item.videoItem',
106 106
 );
107 107
 
108 108
 
@@ -112,18 +112,18 @@  discard block
 block discarded – undo
112 112
 $http_hdr_soapact = $_SERVER['HTTP_SOAPACTION'];
113 113
 $soap_shemas = strpos($http_hdr_soapact, 'urn:schemas-upnp-org:service:ContentDirectory:');
114 114
 if (false === $soap_shemas)
115
-	return (500);
115
+    return (500);
116 116
 $soap_service_ver = substr($http_hdr_soapact, ($soap_shemas + 46), 1);
117 117
 $soap_service_func = substr($http_hdr_soapact, ($soap_shemas + 48), -1);
118 118
 
119 119
 
120 120
 if (substr($basedir, -1, 1) !== '/') {
121
-	$basedir = $basedir . '/';
121
+    $basedir = $basedir . '/';
122 122
 }
123 123
 $baseurl = implode('/', array_map('rawurlencode', explode('/', $baseurl)));
124 124
 $baseurlpatch = 'http://' . $_SERVER['HTTP_HOST'] . $baseurl;
125 125
 if ('/' !== substr($baseurlpatch, -1, 1)) {
126
-	$baseurlpatch = $baseurlpatch . '/';
126
+    $baseurlpatch = $baseurlpatch . '/';
127 127
 }
128 128
 /**
129 129
  * Apply workaround for the libxml PHP bugs:
@@ -131,168 +131,168 @@  discard block
 block discarded – undo
131 131
  * @link https://bugs.php.net/bug.php?id=64938
132 132
  */
133 133
 if (function_exists('libxml_disable_entity_loader')) {
134
-	libxml_disable_entity_loader(false);
134
+    libxml_disable_entity_loader(false);
135 135
 }
136 136
 
137 137
 # $server = new SoapServer(null, array('uri' => "urn:schemas-upnp-org:service:ContentDirectory:3"));
138 138
 $server = new SoapServer(dirname(__FILE__)."/../descr/ContentDirectory.wdsl",
139
-		array(	'cache_wsdl' => WSDL_CACHE_MEMORY,
140
-			'soap_version' => SOAP_1_2,
141
-			'trace' => true
142
-		));
139
+        array(	'cache_wsdl' => WSDL_CACHE_MEMORY,
140
+            'soap_version' => SOAP_1_2,
141
+            'trace' => true
142
+        ));
143 143
 
144 144
 
145 145
 function xml_encode($string) {
146 146
 
147
-	return (str_replace(
148
-	    array("&",		"<",	">",	/*'"',*/	"'"),
149
-	    array("&amp;",	"&lt;",	"&gt;",	/*"&quot;",*/	"&apos;"), 
150
-	    $string));
147
+    return (str_replace(
148
+        array("&",		"<",	">",	/*'"',*/	"'"),
149
+        array("&amp;",	"&lt;",	"&gt;",	/*"&quot;",*/	"&apos;"), 
150
+        $string));
151 151
 }
152 152
 
153 153
 function xml_decode($string) {
154 154
 
155
-	return (str_replace(
156
-	    array("&amp;",	"&lt;",	"&gt;",	"&quot;",	"&apos;"), 
157
-	    array("&",		"<",	">",	'"',		"'"),
158
-	    $string));
155
+    return (str_replace(
156
+        array("&amp;",	"&lt;",	"&gt;",	"&quot;",	"&apos;"), 
157
+        array("&",		"<",	">",	'"',		"'"),
158
+        $string));
159 159
 }
160 160
 
161 161
 
162 162
 function upnp_url_encode($url) {
163 163
 
164
-	if ('http://' !== substr($url, 0, 7) ||
165
-	    false === ($url_path_off = strrpos($url, '/', 8)))
166
-		return (implode('/', array_map('rawurlencode', explode('/', $url))));
167
-		//return (xml_encode(implode('/', array_map('rawurlencode', explode('/', $url)))));
168
-		//return (xml_encode($url));
169
-		//return ('<![CDATA[' . xml_encode($url) . ']]');
170
-
171
-	return (substr($url, 0, $url_path_off) . implode('/', array_map('rawurlencode', explode('/', substr($url, $url_path_off)))));
172
-	//return (substr($url, 0, $url_path_off) . xml_encode(implode('/', array_map('rawurlencode', explode('/', substr($url, $url_path_off))))));
173
-	//return (substr($url, 0, $url_path_off) . xml_encode(substr($url, $url_path_off)));
174
-	//return ('<![CDATA[$url]]');
164
+    if ('http://' !== substr($url, 0, 7) ||
165
+        false === ($url_path_off = strrpos($url, '/', 8)))
166
+        return (implode('/', array_map('rawurlencode', explode('/', $url))));
167
+        //return (xml_encode(implode('/', array_map('rawurlencode', explode('/', $url)))));
168
+        //return (xml_encode($url));
169
+        //return ('<![CDATA[' . xml_encode($url) . ']]');
170
+
171
+    return (substr($url, 0, $url_path_off) . implode('/', array_map('rawurlencode', explode('/', substr($url, $url_path_off)))));
172
+    //return (substr($url, 0, $url_path_off) . xml_encode(implode('/', array_map('rawurlencode', explode('/', substr($url, $url_path_off))))));
173
+    //return (substr($url, 0, $url_path_off) . xml_encode(substr($url, $url_path_off)));
174
+    //return ('<![CDATA[$url]]');
175 175
 }
176 176
 
177 177
 
178 178
 function upnp_get_class($file, $def) {
179
-	global $file_class;
180
-
181
-	if (!isset($file))
182
-		return ($def);
183
-	$dot = strrpos($file, '.');
184
-	if (false === $dot)
185
-		return ($def);
186
-	$ext = strtolower(substr($file, ($dot + 1)));
187
-	if (isset($file_class[$ext])) /* Skip unsupported file type. */
188
-		return ($file_class[$ext]);
189
-
190
-	return ($def);
179
+    global $file_class;
180
+
181
+    if (!isset($file))
182
+        return ($def);
183
+    $dot = strrpos($file, '.');
184
+    if (false === $dot)
185
+        return ($def);
186
+    $ext = strtolower(substr($file, ($dot + 1)));
187
+    if (isset($file_class[$ext])) /* Skip unsupported file type. */
188
+        return ($file_class[$ext]);
189
+
190
+    return ($def);
191 191
 }
192 192
 
193 193
 
194 194
 function get_named_val($name, $buf) { /* ...val_name="value"... */
195 195
 
196
-	$st_off = strpos($buf, $name);
197
-	if (false === $st_off)
198
-		return (null);
199
-	$st_off += strlen($name);
200
-	if ('="' !== substr($buf, $st_off, 2))
201
-		return (null);
202
-	$st_off += 2;
203
-	$en_off = strpos($buf, '"', $st_off);
204
-	if (false === $en_off)
205
-		return (null);
206
-
207
-	return (substr($buf, $st_off, ($en_off - $st_off)));
196
+    $st_off = strpos($buf, $name);
197
+    if (false === $st_off)
198
+        return (null);
199
+    $st_off += strlen($name);
200
+    if ('="' !== substr($buf, $st_off, 2))
201
+        return (null);
202
+    $st_off += 2;
203
+    $en_off = strpos($buf, '"', $st_off);
204
+    if (false === $en_off)
205
+        return (null);
206
+
207
+    return (substr($buf, $st_off, ($en_off - $st_off)));
208 208
 }
209 209
 
210 210
 
211 211
 function m3u_calc_items_count($filename) {
212 212
 
213
-	$items_count = 0;
214
-	$fd = fopen($filename, 'r');
215
-	if (false === $fd)
216
-		return ($items_count);
217
-	while (!feof($fd)) { /* Read the file line by line... */
218
-		$buffer = trim(fgets($fd));
219
-		if (false === strpos($buffer, '#EXTINF:')) /* Skip empty/bad lines. */
220
-			continue;
221
-		$entry = trim(fgets($fd));
222
-		if (false === strpos($entry, '://'))
223
-			continue;
224
-		$items_count ++;
225
-	} 
226
-	fclose ($fd);
227
-
228
-	return ($items_count);
213
+    $items_count = 0;
214
+    $fd = fopen($filename, 'r');
215
+    if (false === $fd)
216
+        return ($items_count);
217
+    while (!feof($fd)) { /* Read the file line by line... */
218
+        $buffer = trim(fgets($fd));
219
+        if (false === strpos($buffer, '#EXTINF:')) /* Skip empty/bad lines. */
220
+            continue;
221
+        $entry = trim(fgets($fd));
222
+        if (false === strpos($entry, '://'))
223
+            continue;
224
+        $items_count ++;
225
+    } 
226
+    fclose ($fd);
227
+
228
+    return ($items_count);
229 229
 }
230 230
 
231 231
 
232 232
 function upnp_mime_content_type($filename) {
233 233
 
234
-	$def = 'video/mpeg';
235
-	$mime_types = array(
236
-		'txt' => 'text/plain',
237
-		'htm' => 'text/html',
238
-		'html' => 'text/html',
239
-		'php' => 'text/html',
240
-		'css' => 'text/css',
241
-		'js' => 'application/javascript',
242
-		'json' => 'application/json',
243
-		'xml' => 'application/xml',
244
-		'swf' => 'application/x-shockwave-flash',
245
-
246
-		/* Images. */
247
-		'png' => 'image/png',
248
-		'jpe' => 'image/jpeg',
249
-		'jpeg' => 'image/jpeg',
250
-		'jpg' => 'image/jpeg',
251
-		'gif' => 'image/gif',
252
-		'bmp' => 'image/bmp',
253
-		'ico' => 'image/vnd.microsoft.icon',
254
-		'tiff' => 'image/tiff',
255
-		'tif' => 'image/tiff',
256
-		'svg' => 'image/svg+xml',
257
-		'svgz' => 'image/svg+xml',
258
-
259
-		/* Audio. */
260
-		'flac' => 'audio/ogg',
261
-		'mp3' => 'audio/mpeg', 
262
-		'wav' => 'audio/vnd.wave',
263
-		'wma' => 'audio/x-ms-wma',
264
-
265
-		/* Video. */
266
-		'3gp' => 'video/3gpp',
267
-		'3gpp' => 'video/3gpp',
268
-		'3g2' => 'video/3gpp2',
269
-		'3gpp2' => 'video/3gpp2',
270
-		'flv' => 'video/x-flv',
271
-		'qt' => 'video/quicktime',
272
-		'ogg' => 'video/ogg',
273
-		'mov' => 'video/mpeg',
274
-		'mp4' => 'video/mp4',
275
-		'mkv' => 'video/x-mkv',
276
-		'm2ts' => 'video/MP2T',
277
-		'ts' => 'video/MP2T',
278
-		'webm' => 'video/webm',
279
-	);
280
-	if (!isset($filename))
281
-		return ($def);
282
-	$dot = strrpos($filename, '.');
283
-	if (false === $dot)
284
-		return ($def);
285
-	$ext = strtolower(substr($filename, ($dot + 1)));
286
-	if (array_key_exists($ext, $mime_types)) {
287
-		return ($mime_types[$ext]);
288
-	} elseif (function_exists('finfo_open')) {
289
-		$finfo = finfo_open(FILEINFO_MIME);
290
-		$mimetype = finfo_file($finfo, $filename);
291
-		finfo_close($finfo);
292
-		return ($mimetype);
293
-	}
294
-
295
-	return ($def);
234
+    $def = 'video/mpeg';
235
+    $mime_types = array(
236
+        'txt' => 'text/plain',
237
+        'htm' => 'text/html',
238
+        'html' => 'text/html',
239
+        'php' => 'text/html',
240
+        'css' => 'text/css',
241
+        'js' => 'application/javascript',
242
+        'json' => 'application/json',
243
+        'xml' => 'application/xml',
244
+        'swf' => 'application/x-shockwave-flash',
245
+
246
+        /* Images. */
247
+        'png' => 'image/png',
248
+        'jpe' => 'image/jpeg',
249
+        'jpeg' => 'image/jpeg',
250
+        'jpg' => 'image/jpeg',
251
+        'gif' => 'image/gif',
252
+        'bmp' => 'image/bmp',
253
+        'ico' => 'image/vnd.microsoft.icon',
254
+        'tiff' => 'image/tiff',
255
+        'tif' => 'image/tiff',
256
+        'svg' => 'image/svg+xml',
257
+        'svgz' => 'image/svg+xml',
258
+
259
+        /* Audio. */
260
+        'flac' => 'audio/ogg',
261
+        'mp3' => 'audio/mpeg', 
262
+        'wav' => 'audio/vnd.wave',
263
+        'wma' => 'audio/x-ms-wma',
264
+
265
+        /* Video. */
266
+        '3gp' => 'video/3gpp',
267
+        '3gpp' => 'video/3gpp',
268
+        '3g2' => 'video/3gpp2',
269
+        '3gpp2' => 'video/3gpp2',
270
+        'flv' => 'video/x-flv',
271
+        'qt' => 'video/quicktime',
272
+        'ogg' => 'video/ogg',
273
+        'mov' => 'video/mpeg',
274
+        'mp4' => 'video/mp4',
275
+        'mkv' => 'video/x-mkv',
276
+        'm2ts' => 'video/MP2T',
277
+        'ts' => 'video/MP2T',
278
+        'webm' => 'video/webm',
279
+    );
280
+    if (!isset($filename))
281
+        return ($def);
282
+    $dot = strrpos($filename, '.');
283
+    if (false === $dot)
284
+        return ($def);
285
+    $ext = strtolower(substr($filename, ($dot + 1)));
286
+    if (array_key_exists($ext, $mime_types)) {
287
+        return ($mime_types[$ext]);
288
+    } elseif (function_exists('finfo_open')) {
289
+        $finfo = finfo_open(FILEINFO_MIME);
290
+        $mimetype = finfo_file($finfo, $filename);
291
+        finfo_close($finfo);
292
+        return ($mimetype);
293
+    }
294
+
295
+    return ($def);
296 296
 }
297 297
 
298 298
 /* Format:
@@ -300,241 +300,241 @@  discard block
 block discarded – undo
300 300
  * 1: 2004-05-08T10:00:00
301 301
  * */
302 302
 function upnp_date($timedate, $format) {
303
-	$res = date('Y-m-d', $timedate);
303
+    $res = date('Y-m-d', $timedate);
304 304
 
305
-	if (1 === $format) {
306
-		$res = $res . 'T' . date('H:i:s', $timedate);
307
-	}
305
+    if (1 === $format) {
306
+        $res = $res . 'T' . date('H:i:s', $timedate);
307
+    }
308 308
 
309
-	return ($res);
309
+    return ($res);
310 310
 }
311 311
 
312 312
 
313 313
 /* ContentDirectory funcs */
314 314
 
315 315
 function GetSearchCapabilities() {
316
-	// 'upnp:class'; /* dc:title,upnp:class,upnp:artist */
317
-	//$SearchCaps = 'dc:creator,dc:date,dc:title,upnp:album,upnp:actor,upnp:artist,upnp:class,upnp:genre,@id,@parentID,@refID';
318
-	$SearchCaps = 'dc:title';
316
+    // 'upnp:class'; /* dc:title,upnp:class,upnp:artist */
317
+    //$SearchCaps = 'dc:creator,dc:date,dc:title,upnp:album,upnp:actor,upnp:artist,upnp:class,upnp:genre,@id,@parentID,@refID';
318
+    $SearchCaps = 'dc:title';
319 319
 
320
-	return ($SearchCaps);
320
+    return ($SearchCaps);
321 321
 }
322 322
 
323 323
 
324 324
 function GetSortCapabilities() {
325
-	$SortCaps = 'dc:title';
326
-	/* dc:title,upnp:genre,upnp:album,dc:creator,res@size,
325
+    $SortCaps = 'dc:title';
326
+    /* dc:title,upnp:genre,upnp:album,dc:creator,res@size,
327 327
 	 * res@duration,res@bitrate,dc:publisher,
328 328
 	 * upnp:originalTrackNumber,dc:date,upnp:producer,upnp:rating,
329 329
 	 * upnp:actor,upnp:director,dc:description
330 330
 	 */
331 331
 
332
-	return ($SortCaps);
332
+    return ($SortCaps);
333 333
 }
334 334
 
335 335
 
336 336
 function GetSortExtensionCapabilities() {
337
-	$SortExtensionCaps = '';
337
+    $SortExtensionCaps = '';
338 338
 
339
-	return ($SortExtensionCaps);
339
+    return ($SortExtensionCaps);
340 340
 }
341 341
 
342 342
 
343 343
 function GetFeatureList() {
344
-	$FeatureList = '';
344
+    $FeatureList = '';
345 345
 
346
-	return ($FeatureList);
346
+    return ($FeatureList);
347 347
 }
348 348
 
349 349
 
350 350
 function GetSystemUpdateID() {
351
-	$Id = '1';
351
+    $Id = '1';
352 352
 
353
-	return ($Id);
353
+    return ($Id);
354 354
 }
355 355
 
356 356
 
357 357
 function GetServiceResetToken() {
358
-	$ResetToken = '1';
358
+    $ResetToken = '1';
359 359
 
360
-	return ($ResetToken);
360
+    return ($ResetToken);
361 361
 }
362 362
 
363 363
 
364 364
 function Browse($ObjectID, $BrowseFlag, $Filter, $StartingIndex,
365 365
     $RequestedCount, $SortCriteria) {
366
-	global $basedir, $baseurl, $baseurlpatch;
367
-	$Result =   '<DIDL-Lite' .
368
-		    ' xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"' .
369
-		    ' xmlns:dlna="urn:schemas-dlna-org:metadata-1-0/"' .
370
-		    ' xmlns:dc="http://purl.org/dc/elements/1.1/"' .
371
-		    ' xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/"' .
372
-		    ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' .
373
-		    ' xsi:schemaLocation="' .
374
-			'urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/ http://www.upnp.org/schemas/av/didl-lite.xsd ' .
375
-			'urn:schemas-upnp-org:metadata-1-0/upnp/ http://www.upnp.org/schemas/av/upnp.xsd">';
376
-	$ParentID = '-1';
377
-	$NumberReturned = 0;
378
-	$TotalMatches = 0;
379
-	$UpdateID = 1;
380
-
381
-	/* Check input param. */
382
-	if (isset($ObjectID)) {
383
-		if ((1 === strlen($ObjectID) ||
384
-		     (3 === strlen($ObjectID) && '_T' === substr($ObjectID, 1, 2)) ||
385
-		     (3 === strlen($ObjectID) && '_D' === substr($ObjectID, 1, 2)) ||
386
-		     (3 === strlen($ObjectID) && '_L' === substr($ObjectID, 1, 2))) && (
387
-		    '0' === substr($ObjectID, 0, 1) ||
388
-		    'A' === substr($ObjectID, 0, 1) ||
389
-		    'I' === substr($ObjectID, 0, 1) ||
390
-		    'V' === substr($ObjectID, 0, 1) ||
391
-		    'P' === substr($ObjectID, 0, 1) ||
392
-		    'T' === substr($ObjectID, 0, 1))) { /* V, I, A, P, T - from X_GetFeatureList() */
393
-			$ObjectID = '0';
394
-			$dir = '';
395
-		} else {
396
-			$dir = rawurldecode(xml_decode($ObjectID));
397
-			if ('/' !== substr($dir, -1, 1)) {
398
-				$dir = $dir . '/';
399
-			}
400
-			/* Sec check: .. in path */
401
-			$dotdotdir = '';
402
-			$dirnames = explode('/', $dir);
403
-			for ($di = 0; $di < sizeof($dirnames); $di ++) {
404
-				if ('.' === $dirnames[$di])
405
-					continue;
406
-				if ('..' === $dirnames[$di]) {
407
-					$dir = '';
408
-					break;
409
-				}
410
-				if ((sizeof($dirnames) - 1) > $di) {
411
-					$dotdotdir = $dotdotdir . $dirnames[$di] . '/';
412
-				}
413
-			}
414
-			$dir = $dotdotdir;
415
-			if ('/' === substr($dir, 0, 1) /*|| !is_dir($basedir.$dir)*/) {
416
-				$dir = '';
417
-			}
418
-			/* Remove tail slash from file name. */
419
-			if (!is_dir($basedir.$dir) &&
420
-			    '/' === substr($dir, -1, 1)) {
421
-				$dir = substr($dir, 0, -1);
422
-			}
423
-		}
424
-	} else {
425
-		$ObjectID = '0';
426
-		$dir = '';
427
-	}
428
-
429
-	if ('BrowseMetadata' === $BrowseFlag) {
430
-		$filename = $basedir.$dir;
431
-		/* Is file/dir exist? */
432
-		$stat = stat($filename);
433
-		if (false === $stat) { /* No such file/dir. */
434
-			return (array(	'Result' => '',
435
-					'NumberReturned' => 0,
436
-					'TotalMatches' => 0,
437
-					'UpdateID' => $UpdateID));
438
-		}
439
-
440
-		/* Collect data. */
441
-		if (is_writable($filename)) {
442
-			$WriteStatus = 'WRITABLE';
443
-			$Restricted = '0';
444
-		} else {
445
-			$WriteStatus = 'NOT_WRITABLE';
446
-			$Restricted = '1';
447
-		}
448
-		$basefilename = basename($dir);
449
-		if ('0' === $ObjectID) {
450
-			$title = 'root';
451
-			$ParentID = '-1';
452
-		} else {
453
-			$title = xml_encode($basefilename);
454
-			$ParentID = upnp_url_encode(dirname($dir));
455
-		}
456
-
457
-		if (is_dir($filename)) { /* Dir. */
458
-			$StorageTotal = disk_total_space($filename);
459
-			$StorageFree = disk_free_space($filename);
460
-			$StorageUsed = ($StorageTotal - $StorageFree);
461
-			$ChildCount = (count(scandir($filename)) - 2);
462
-			$Result = $Result .
463
-			    "<container id=\"$ObjectID\" parentID=\"$ParentID\" restricted=\"$Restricted\" searchable=\"1\" childCount=\"$ChildCount\">" .
464
-				"<dc:title>$title</dc:title>" .
465
-				'<upnp:class>object.container.storageFolder</upnp:class>' .
466
-				"<upnp:storageTotal>$StorageTotal</upnp:storageTotal>" .
467
-				"<upnp:storageFree>$StorageFree</upnp:storageFree>" .
468
-				"<upnp:storageUsed>$StorageUsed</upnp:storageUsed>" .
469
-				"<upnp:writeStatus>$WriteStatus</upnp:writeStatus>";
470
-			if ('0' === $ObjectID) {
471
-				$Result = $Result .
472
-					'<upnp:searchClass includeDerived="1">object.item.audioItem</upnp:searchClass>' .
473
-					'<upnp:searchClass includeDerived="1">object.item.imageItem</upnp:searchClass>' .
474
-					'<upnp:searchClass includeDerived="1">object.item.videoItem</upnp:searchClass>';
475
-			}
476
-			$Result = $Result . '</container>';
477
-		} else { /* File or playlist. */
478
-			$iclass = upnp_get_class($basefilename, 'object.item.videoItem');
479
-			if ('object.container.storageFolder' === $iclass) { /* Play list as folder! */
480
-				$ChildCount = m3u_calc_items_count($filename);
481
-				$Result = $Result .
482
-				    "<container id=\"$ObjectID\" parentID=\"$ParentID\" restricted=\"$Restricted\" searchable=\"1\" childCount=\"$ChildCount\">" .
483
-					"<dc:title>$title</dc:title>" .
484
-					'<upnp:class>object.container.storageFolder</upnp:class>' .
485
-				    '</container>';
486
-			} else {
487
-				$date = upnp_date(filectime($filename), 1);
488
-				$size = filesize($filename);
489
-				$mimetype = upnp_mime_content_type($filename);
490
-				$Result = $Result .
491
-				    "<item id=\"$ObjectID\" parentID=\"$ParentID\" restricted=\"$Restricted\">" .
492
-					"<dc:title>$title</dc:title>" .
493
-					"<dc:date>$date</dc:date>" .
494
-					"<upnp:class>$iclass</upnp:class>" .
495
-					"<res size=\"$size\" protocolInfo=\"http-get:*:$mimetype:*\">$ObjectID</res>" .
496
-				    '</item>';
497
-			}
498
-		}
499
-		$Result = $Result . '</DIDL-Lite>';
500
-		return (array(	'Result' => $Result,
501
-				'NumberReturned' => 1,
502
-				'TotalMatches' => 1,
503
-				'UpdateID' => $UpdateID));
504
-	}
505
-
506
-	if (!isset($StartingIndex)) {
507
-		$StartingIndex = 0;
508
-	}
509
-	if (!isset($RequestedCount)) {
510
-		$RequestedCount = 0;
511
-	}
512
-
513
-	if (!is_dir($basedir.$dir)) { /* Play list file? */
514
-		/* Open the file. */
515
-		$filename = $basedir.$dir;
516
-		$fd = fopen($filename, 'r');
517
-		if (false === $fd) {
518
-			return (array(	'Result' => '',
519
-					'NumberReturned' => 0,
520
-					'TotalMatches' => 0,
521
-					'UpdateID' => $UpdateID));
522
-		}
523
-		$date = upnp_date(filectime($filename), 1);
524
-		if (is_writable($filename)) {
525
-			$Restricted = '0';
526
-		} else {
527
-			$Restricted = '1';
528
-		}
529
-
530
-		//$logo_url_path = 'http://iptvremote.ru/channels/android/160/';
531
-		//$logo_url_path = 'http://172.16.0.254/download/tmp/image/';
532
-		while (!feof($fd)) { /* Read the file line by line... */
533
-			$buffer = trim(fgets($fd));
534
-			//if($buffer === false)
535
-			//	break;
536
-			if (false === strpos($buffer, '#EXTINF:')) { /* Skip empty/bad lines. */
537
-				/*if (false !== strpos($buffer, '#EXTM3U')) {
366
+    global $basedir, $baseurl, $baseurlpatch;
367
+    $Result =   '<DIDL-Lite' .
368
+            ' xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"' .
369
+            ' xmlns:dlna="urn:schemas-dlna-org:metadata-1-0/"' .
370
+            ' xmlns:dc="http://purl.org/dc/elements/1.1/"' .
371
+            ' xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/"' .
372
+            ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' .
373
+            ' xsi:schemaLocation="' .
374
+            'urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/ http://www.upnp.org/schemas/av/didl-lite.xsd ' .
375
+            'urn:schemas-upnp-org:metadata-1-0/upnp/ http://www.upnp.org/schemas/av/upnp.xsd">';
376
+    $ParentID = '-1';
377
+    $NumberReturned = 0;
378
+    $TotalMatches = 0;
379
+    $UpdateID = 1;
380
+
381
+    /* Check input param. */
382
+    if (isset($ObjectID)) {
383
+        if ((1 === strlen($ObjectID) ||
384
+             (3 === strlen($ObjectID) && '_T' === substr($ObjectID, 1, 2)) ||
385
+             (3 === strlen($ObjectID) && '_D' === substr($ObjectID, 1, 2)) ||
386
+             (3 === strlen($ObjectID) && '_L' === substr($ObjectID, 1, 2))) && (
387
+            '0' === substr($ObjectID, 0, 1) ||
388
+            'A' === substr($ObjectID, 0, 1) ||
389
+            'I' === substr($ObjectID, 0, 1) ||
390
+            'V' === substr($ObjectID, 0, 1) ||
391
+            'P' === substr($ObjectID, 0, 1) ||
392
+            'T' === substr($ObjectID, 0, 1))) { /* V, I, A, P, T - from X_GetFeatureList() */
393
+            $ObjectID = '0';
394
+            $dir = '';
395
+        } else {
396
+            $dir = rawurldecode(xml_decode($ObjectID));
397
+            if ('/' !== substr($dir, -1, 1)) {
398
+                $dir = $dir . '/';
399
+            }
400
+            /* Sec check: .. in path */
401
+            $dotdotdir = '';
402
+            $dirnames = explode('/', $dir);
403
+            for ($di = 0; $di < sizeof($dirnames); $di ++) {
404
+                if ('.' === $dirnames[$di])
405
+                    continue;
406
+                if ('..' === $dirnames[$di]) {
407
+                    $dir = '';
408
+                    break;
409
+                }
410
+                if ((sizeof($dirnames) - 1) > $di) {
411
+                    $dotdotdir = $dotdotdir . $dirnames[$di] . '/';
412
+                }
413
+            }
414
+            $dir = $dotdotdir;
415
+            if ('/' === substr($dir, 0, 1) /*|| !is_dir($basedir.$dir)*/) {
416
+                $dir = '';
417
+            }
418
+            /* Remove tail slash from file name. */
419
+            if (!is_dir($basedir.$dir) &&
420
+                '/' === substr($dir, -1, 1)) {
421
+                $dir = substr($dir, 0, -1);
422
+            }
423
+        }
424
+    } else {
425
+        $ObjectID = '0';
426
+        $dir = '';
427
+    }
428
+
429
+    if ('BrowseMetadata' === $BrowseFlag) {
430
+        $filename = $basedir.$dir;
431
+        /* Is file/dir exist? */
432
+        $stat = stat($filename);
433
+        if (false === $stat) { /* No such file/dir. */
434
+            return (array(	'Result' => '',
435
+                    'NumberReturned' => 0,
436
+                    'TotalMatches' => 0,
437
+                    'UpdateID' => $UpdateID));
438
+        }
439
+
440
+        /* Collect data. */
441
+        if (is_writable($filename)) {
442
+            $WriteStatus = 'WRITABLE';
443
+            $Restricted = '0';
444
+        } else {
445
+            $WriteStatus = 'NOT_WRITABLE';
446
+            $Restricted = '1';
447
+        }
448
+        $basefilename = basename($dir);
449
+        if ('0' === $ObjectID) {
450
+            $title = 'root';
451
+            $ParentID = '-1';
452
+        } else {
453
+            $title = xml_encode($basefilename);
454
+            $ParentID = upnp_url_encode(dirname($dir));
455
+        }
456
+
457
+        if (is_dir($filename)) { /* Dir. */
458
+            $StorageTotal = disk_total_space($filename);
459
+            $StorageFree = disk_free_space($filename);
460
+            $StorageUsed = ($StorageTotal - $StorageFree);
461
+            $ChildCount = (count(scandir($filename)) - 2);
462
+            $Result = $Result .
463
+                "<container id=\"$ObjectID\" parentID=\"$ParentID\" restricted=\"$Restricted\" searchable=\"1\" childCount=\"$ChildCount\">" .
464
+                "<dc:title>$title</dc:title>" .
465
+                '<upnp:class>object.container.storageFolder</upnp:class>' .
466
+                "<upnp:storageTotal>$StorageTotal</upnp:storageTotal>" .
467
+                "<upnp:storageFree>$StorageFree</upnp:storageFree>" .
468
+                "<upnp:storageUsed>$StorageUsed</upnp:storageUsed>" .
469
+                "<upnp:writeStatus>$WriteStatus</upnp:writeStatus>";
470
+            if ('0' === $ObjectID) {
471
+                $Result = $Result .
472
+                    '<upnp:searchClass includeDerived="1">object.item.audioItem</upnp:searchClass>' .
473
+                    '<upnp:searchClass includeDerived="1">object.item.imageItem</upnp:searchClass>' .
474
+                    '<upnp:searchClass includeDerived="1">object.item.videoItem</upnp:searchClass>';
475
+            }
476
+            $Result = $Result . '</container>';
477
+        } else { /* File or playlist. */
478
+            $iclass = upnp_get_class($basefilename, 'object.item.videoItem');
479
+            if ('object.container.storageFolder' === $iclass) { /* Play list as folder! */
480
+                $ChildCount = m3u_calc_items_count($filename);
481
+                $Result = $Result .
482
+                    "<container id=\"$ObjectID\" parentID=\"$ParentID\" restricted=\"$Restricted\" searchable=\"1\" childCount=\"$ChildCount\">" .
483
+                    "<dc:title>$title</dc:title>" .
484
+                    '<upnp:class>object.container.storageFolder</upnp:class>' .
485
+                    '</container>';
486
+            } else {
487
+                $date = upnp_date(filectime($filename), 1);
488
+                $size = filesize($filename);
489
+                $mimetype = upnp_mime_content_type($filename);
490
+                $Result = $Result .
491
+                    "<item id=\"$ObjectID\" parentID=\"$ParentID\" restricted=\"$Restricted\">" .
492
+                    "<dc:title>$title</dc:title>" .
493
+                    "<dc:date>$date</dc:date>" .
494
+                    "<upnp:class>$iclass</upnp:class>" .
495
+                    "<res size=\"$size\" protocolInfo=\"http-get:*:$mimetype:*\">$ObjectID</res>" .
496
+                    '</item>';
497
+            }
498
+        }
499
+        $Result = $Result . '</DIDL-Lite>';
500
+        return (array(	'Result' => $Result,
501
+                'NumberReturned' => 1,
502
+                'TotalMatches' => 1,
503
+                'UpdateID' => $UpdateID));
504
+    }
505
+
506
+    if (!isset($StartingIndex)) {
507
+        $StartingIndex = 0;
508
+    }
509
+    if (!isset($RequestedCount)) {
510
+        $RequestedCount = 0;
511
+    }
512
+
513
+    if (!is_dir($basedir.$dir)) { /* Play list file? */
514
+        /* Open the file. */
515
+        $filename = $basedir.$dir;
516
+        $fd = fopen($filename, 'r');
517
+        if (false === $fd) {
518
+            return (array(	'Result' => '',
519
+                    'NumberReturned' => 0,
520
+                    'TotalMatches' => 0,
521
+                    'UpdateID' => $UpdateID));
522
+        }
523
+        $date = upnp_date(filectime($filename), 1);
524
+        if (is_writable($filename)) {
525
+            $Restricted = '0';
526
+        } else {
527
+            $Restricted = '1';
528
+        }
529
+
530
+        //$logo_url_path = 'http://iptvremote.ru/channels/android/160/';
531
+        //$logo_url_path = 'http://172.16.0.254/download/tmp/image/';
532
+        while (!feof($fd)) { /* Read the file line by line... */
533
+            $buffer = trim(fgets($fd));
534
+            //if($buffer === false)
535
+            //	break;
536
+            if (false === strpos($buffer, '#EXTINF:')) { /* Skip empty/bad lines. */
537
+                /*if (false !== strpos($buffer, '#EXTM3U')) {
538 538
 					$logo_url_path = get_named_val('url-tvg-logo', $buffer);
539 539
 					if (null !== $logo_url_path) {
540 540
 						if ('/' !== substr($logo_url_path, -1, 1))
@@ -544,186 +544,186 @@  discard block
 block discarded – undo
544 544
 						$logo_url_path = 'http://172.16.0.254/download/tmp/image/';
545 545
 					}
546 546
 				}*/
547
-				continue;
548
-			}
549
-			$entry = trim(fgets($fd));
550
-			if (false === strpos($entry, '://'))
551
-				continue;
552
-			/* Ok, item matched and may be returned. */
553
-			$TotalMatches ++;
554
-			if (0 < $StartingIndex &&
555
-			    $TotalMatches < $StartingIndex)
556
-				continue; /* Skip first items. */
557
-			if (0 < $RequestedCount &&
558
-			    $NumberReturned >= $RequestedCount)
559
-				continue; /* Do not add more than requested. */
560
-			$NumberReturned ++;
561
-			/* Add item to result. */
562
-			$title = xml_encode(trim(substr($buffer, (strpos($buffer, ',') + 1))));
563
-			//$en_entry = upnp_url_encode($entry);
564
-			$en_entry = xml_encode($entry);
565
-			$iclass = upnp_get_class($entry, 'object.item.videoItem.videoBroadcast');
566
-			$mimetype = 'video/mpeg';
567
-			if ('object.container.storageFolder' === $iclass) { /* Play list as folder! */
568
-				$Result = $Result .
569
-				    "<container id=\"$en_entry\" parentID=\"$ObjectID\" restricted=\"$Restricted\">" .
570
-					"<dc:title>$title</dc:title>" .
571
-					'<upnp:class>object.container.storageFolder</upnp:class>' .
572
-				    '</container>';
573
-			} else {
574
-				//$logo = get_named_val("tvg-logo", $buffer);
575
-				//if (null === $logo) {
576
-				//	$logo = trim(substr($buffer, (strpos($buffer, ',') + 1)));
577
-				//}
578
-				//$icon_url = upnp_url_encode($logo_url_path . mb_convert_case($logo, MB_CASE_LOWER, "UTF-8") . '.png');
579
-				$Result = $Result .
580
-				    "<item id=\"$en_entry\" parentID=\"$ObjectID\" restricted=\"$Restricted\">" .
581
-					"<dc:title>$title</dc:title>" .
582
-					"<dc:date>$date</dc:date>" .
583
-					//"<upnp:albumArtURI dlna:profileID=\"JPEG_TN\" xmlns:dlna=\"urn:schemas-dlna-org:metadata-1-0\">$icon_url</upnp:albumArtURI>" .
584
-					//"<upnp:icon>$icon_url</upnp:icon>" .
585
-					"<upnp:class>$iclass</upnp:class>" .
586
-					"<res protocolInfo=\"http-get:*:$mimetype:*\">$en_entry</res>" .
587
-				    '</item>';
588
-			}
589
-		} 
590
-		fclose ($fd);
591
-
592
-		$Result = $Result . '</DIDL-Lite>';
593
-		return (array(	'Result' => $Result,
594
-				'NumberReturned' => $NumberReturned,
595
-				'TotalMatches' => $TotalMatches,
596
-				'UpdateID' => $UpdateID));
597
-	}
598
-
599
-	/* Scan directory and add to play list.*/
600
-	$entries = scandir($basedir.$dir);
601
-	/* Add dirs to play list. */
602
-	foreach ($entries as $entry) {
603
-		$filename = $basedir.$dir.$entry;
604
-		if ('.' === substr($entry, 0, 1) ||
605
-		    !is_dir($filename)) /* Skip files. */
606
-			continue;
607
-		/* Ok, item matched and may be returned. */
608
-		$TotalMatches ++;
609
-		if (0 < $StartingIndex &&
610
-		    $TotalMatches < $StartingIndex)
611
-			continue; /* Skip first items. */
612
-		if (0 < $RequestedCount &&
613
-		    $NumberReturned >= $RequestedCount)
614
-			continue; /* Do not add more than requested. */
615
-		$NumberReturned ++;
616
-		/* Add item to result. */
617
-		if (is_writable($filename)) {
618
-			$Restricted = '0';
619
-		} else {
620
-			$Restricted = '1';
621
-		}
622
-		$title = xml_encode($entry);
623
-		$en_entry = upnp_url_encode($dir.$entry);
624
-		$ChildCount = (count(scandir($filename)) - 2);
625
-		$Result = $Result .
626
-		    "<container id=\"$en_entry\" parentID=\"$ObjectID\" restricted=\"$Restricted\" searchable=\"1\" childCount=\"$ChildCount\">" .
627
-			"<dc:title>$title</dc:title>" .
628
-			'<upnp:class>object.container.storageFolder</upnp:class>' .
629
-		    '</container>';
630
-	}
631
-	/* Add files to play list. */
632
-	foreach ($entries as $entry) {
633
-		$filename = $basedir.$dir.$entry;
634
-		if (is_dir($filename)) /* Skip dirs. */
635
-			continue;
636
-		$iclass = upnp_get_class($entry, null);
637
-		if (null === $iclass) /* Skip unsupported file type. */
638
-			continue;
639
-		/* Ok, item matched and may be returned. */
640
-		$TotalMatches ++;
641
-		if (0 < $StartingIndex &&
642
-		    $TotalMatches < $StartingIndex)
643
-			continue; /* Skip first items. */
644
-		if (0 < $RequestedCount &&
645
-		    $NumberReturned >= $RequestedCount)
646
-			continue; /* Do not add more than requested. */
647
-		$NumberReturned ++;
648
-		/* Add item to result. */
649
-		if (is_writable($filename)) {
650
-			$Restricted = '0';
651
-		} else {
652
-			$Restricted = '1';
653
-		}
654
-		$title = xml_encode($entry);
655
-		$en_entry = upnp_url_encode($dir.$entry);
656
-		if ('object.container.storageFolder' === $iclass) { /* Play list as folder! */
657
-			$ChildCount = m3u_calc_items_count($filename);
658
-			$Result = $Result .
659
-			    "<container id=\"$en_entry\" parentID=\"$ObjectID\" restricted=\"$Restricted\" searchable=\"1\" childCount=\"$ChildCount\">" .
660
-				"<dc:title>$title</dc:title>" .
661
-				'<upnp:class>object.container.storageFolder</upnp:class>' .
662
-			    '</container>';
663
-		} else {
664
-			$date = upnp_date(filectime($filename), 1);
665
-			$size = filesize($filename);
666
-			$mimetype = upnp_mime_content_type($filename);
667
-			$res_info_ex = '';
668
-			$Result = $Result .
669
-			    "<item id=\"$en_entry\" parentID=\"$ObjectID\" restricted=\"$Restricted\">" .
670
-				"<dc:title>$title</dc:title>" .
671
-				"<dc:date>$date</dc:date>" .
672
-				"<upnp:class>$iclass</upnp:class>";
673
-			if ('object.item.imageItem' === substr($iclass, 0, 21)) {
674
-				$Result = $Result .
675
-				    "<upnp:albumArtURI>$baseurlpatch$en_entry</upnp:albumArtURI>" .
676
-				    "<upnp:icon>$baseurlpatch$en_entry</upnp:icon>";
677
-				$img_info = getimagesize($filename);
678
-				if (false !== $img_info) {
679
-					$res_info_ex = ' resolution="' . $img_info[0] . 'x' . $img_info[1] . '"';
680
-				}
681
-			}
682
-			$Result = $Result .
683
-				"<res size=\"$size\"$res_info_ex protocolInfo=\"http-get:*:$mimetype:*\">$baseurlpatch$en_entry</res>" .
684
-			    '</item>';
685
-		}
686
-	}
687
-
688
-	$Result = $Result . '</DIDL-Lite>';
689
-	return (array(	'Result' => $Result,
690
-			'NumberReturned' => $NumberReturned,
691
-			'TotalMatches' => $TotalMatches,
692
-			'UpdateID' => $UpdateID));
547
+                continue;
548
+            }
549
+            $entry = trim(fgets($fd));
550
+            if (false === strpos($entry, '://'))
551
+                continue;
552
+            /* Ok, item matched and may be returned. */
553
+            $TotalMatches ++;
554
+            if (0 < $StartingIndex &&
555
+                $TotalMatches < $StartingIndex)
556
+                continue; /* Skip first items. */
557
+            if (0 < $RequestedCount &&
558
+                $NumberReturned >= $RequestedCount)
559
+                continue; /* Do not add more than requested. */
560
+            $NumberReturned ++;
561
+            /* Add item to result. */
562
+            $title = xml_encode(trim(substr($buffer, (strpos($buffer, ',') + 1))));
563
+            //$en_entry = upnp_url_encode($entry);
564
+            $en_entry = xml_encode($entry);
565
+            $iclass = upnp_get_class($entry, 'object.item.videoItem.videoBroadcast');
566
+            $mimetype = 'video/mpeg';
567
+            if ('object.container.storageFolder' === $iclass) { /* Play list as folder! */
568
+                $Result = $Result .
569
+                    "<container id=\"$en_entry\" parentID=\"$ObjectID\" restricted=\"$Restricted\">" .
570
+                    "<dc:title>$title</dc:title>" .
571
+                    '<upnp:class>object.container.storageFolder</upnp:class>' .
572
+                    '</container>';
573
+            } else {
574
+                //$logo = get_named_val("tvg-logo", $buffer);
575
+                //if (null === $logo) {
576
+                //	$logo = trim(substr($buffer, (strpos($buffer, ',') + 1)));
577
+                //}
578
+                //$icon_url = upnp_url_encode($logo_url_path . mb_convert_case($logo, MB_CASE_LOWER, "UTF-8") . '.png');
579
+                $Result = $Result .
580
+                    "<item id=\"$en_entry\" parentID=\"$ObjectID\" restricted=\"$Restricted\">" .
581
+                    "<dc:title>$title</dc:title>" .
582
+                    "<dc:date>$date</dc:date>" .
583
+                    //"<upnp:albumArtURI dlna:profileID=\"JPEG_TN\" xmlns:dlna=\"urn:schemas-dlna-org:metadata-1-0\">$icon_url</upnp:albumArtURI>" .
584
+                    //"<upnp:icon>$icon_url</upnp:icon>" .
585
+                    "<upnp:class>$iclass</upnp:class>" .
586
+                    "<res protocolInfo=\"http-get:*:$mimetype:*\">$en_entry</res>" .
587
+                    '</item>';
588
+            }
589
+        } 
590
+        fclose ($fd);
591
+
592
+        $Result = $Result . '</DIDL-Lite>';
593
+        return (array(	'Result' => $Result,
594
+                'NumberReturned' => $NumberReturned,
595
+                'TotalMatches' => $TotalMatches,
596
+                'UpdateID' => $UpdateID));
597
+    }
598
+
599
+    /* Scan directory and add to play list.*/
600
+    $entries = scandir($basedir.$dir);
601
+    /* Add dirs to play list. */
602
+    foreach ($entries as $entry) {
603
+        $filename = $basedir.$dir.$entry;
604
+        if ('.' === substr($entry, 0, 1) ||
605
+            !is_dir($filename)) /* Skip files. */
606
+            continue;
607
+        /* Ok, item matched and may be returned. */
608
+        $TotalMatches ++;
609
+        if (0 < $StartingIndex &&
610
+            $TotalMatches < $StartingIndex)
611
+            continue; /* Skip first items. */
612
+        if (0 < $RequestedCount &&
613
+            $NumberReturned >= $RequestedCount)
614
+            continue; /* Do not add more than requested. */
615
+        $NumberReturned ++;
616
+        /* Add item to result. */
617
+        if (is_writable($filename)) {
618
+            $Restricted = '0';
619
+        } else {
620
+            $Restricted = '1';
621
+        }
622
+        $title = xml_encode($entry);
623
+        $en_entry = upnp_url_encode($dir.$entry);
624
+        $ChildCount = (count(scandir($filename)) - 2);
625
+        $Result = $Result .
626
+            "<container id=\"$en_entry\" parentID=\"$ObjectID\" restricted=\"$Restricted\" searchable=\"1\" childCount=\"$ChildCount\">" .
627
+            "<dc:title>$title</dc:title>" .
628
+            '<upnp:class>object.container.storageFolder</upnp:class>' .
629
+            '</container>';
630
+    }
631
+    /* Add files to play list. */
632
+    foreach ($entries as $entry) {
633
+        $filename = $basedir.$dir.$entry;
634
+        if (is_dir($filename)) /* Skip dirs. */
635
+            continue;
636
+        $iclass = upnp_get_class($entry, null);
637
+        if (null === $iclass) /* Skip unsupported file type. */
638
+            continue;
639
+        /* Ok, item matched and may be returned. */
640
+        $TotalMatches ++;
641
+        if (0 < $StartingIndex &&
642
+            $TotalMatches < $StartingIndex)
643
+            continue; /* Skip first items. */
644
+        if (0 < $RequestedCount &&
645
+            $NumberReturned >= $RequestedCount)
646
+            continue; /* Do not add more than requested. */
647
+        $NumberReturned ++;
648
+        /* Add item to result. */
649
+        if (is_writable($filename)) {
650
+            $Restricted = '0';
651
+        } else {
652
+            $Restricted = '1';
653
+        }
654
+        $title = xml_encode($entry);
655
+        $en_entry = upnp_url_encode($dir.$entry);
656
+        if ('object.container.storageFolder' === $iclass) { /* Play list as folder! */
657
+            $ChildCount = m3u_calc_items_count($filename);
658
+            $Result = $Result .
659
+                "<container id=\"$en_entry\" parentID=\"$ObjectID\" restricted=\"$Restricted\" searchable=\"1\" childCount=\"$ChildCount\">" .
660
+                "<dc:title>$title</dc:title>" .
661
+                '<upnp:class>object.container.storageFolder</upnp:class>' .
662
+                '</container>';
663
+        } else {
664
+            $date = upnp_date(filectime($filename), 1);
665
+            $size = filesize($filename);
666
+            $mimetype = upnp_mime_content_type($filename);
667
+            $res_info_ex = '';
668
+            $Result = $Result .
669
+                "<item id=\"$en_entry\" parentID=\"$ObjectID\" restricted=\"$Restricted\">" .
670
+                "<dc:title>$title</dc:title>" .
671
+                "<dc:date>$date</dc:date>" .
672
+                "<upnp:class>$iclass</upnp:class>";
673
+            if ('object.item.imageItem' === substr($iclass, 0, 21)) {
674
+                $Result = $Result .
675
+                    "<upnp:albumArtURI>$baseurlpatch$en_entry</upnp:albumArtURI>" .
676
+                    "<upnp:icon>$baseurlpatch$en_entry</upnp:icon>";
677
+                $img_info = getimagesize($filename);
678
+                if (false !== $img_info) {
679
+                    $res_info_ex = ' resolution="' . $img_info[0] . 'x' . $img_info[1] . '"';
680
+                }
681
+            }
682
+            $Result = $Result .
683
+                "<res size=\"$size\"$res_info_ex protocolInfo=\"http-get:*:$mimetype:*\">$baseurlpatch$en_entry</res>" .
684
+                '</item>';
685
+        }
686
+    }
687
+
688
+    $Result = $Result . '</DIDL-Lite>';
689
+    return (array(	'Result' => $Result,
690
+            'NumberReturned' => $NumberReturned,
691
+            'TotalMatches' => $TotalMatches,
692
+            'UpdateID' => $UpdateID));
693 693
 }
694 694
 
695 695
 
696 696
 function Search($ContainerID, $SearchCriteria, $Filter, $StartingIndex,
697 697
     $RequestedCount, $SortCriteria) {
698
-	global $basedir, $baseurl, $baseurlpatch;
699
-	$Result =   '<DIDL-Lite' .
700
-		    ' xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"' .
701
-		    ' xmlns:dlna="urn:schemas-dlna-org:metadata-1-0/"' .
702
-		    ' xmlns:dc="http://purl.org/dc/elements/1.1/"' .
703
-		    ' xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/"' .
704
-		    ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' .
705
-		    ' xsi:schemaLocation="' .
706
-			'urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/ http://www.upnp.org/schemas/av/didl-lite.xsd ' .
707
-			'urn:schemas-upnp-org:metadata-1-0/upnp/ http://www.upnp.org/schemas/av/upnp.xsd">';
708
-	$NumberReturned = 0;
709
-	$TotalMatches = 0;
710
-	$UpdateID = 1;
711
-
712
-	$Result = $Result . '</DIDL-Lite>';
713
-
714
-	return (array(	'Result' => $Result,
715
-			'NumberReturned' => $NumberReturned,
716
-			'TotalMatches' => $TotalMatches,
717
-			'UpdateID' => $UpdateID));
698
+    global $basedir, $baseurl, $baseurlpatch;
699
+    $Result =   '<DIDL-Lite' .
700
+            ' xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"' .
701
+            ' xmlns:dlna="urn:schemas-dlna-org:metadata-1-0/"' .
702
+            ' xmlns:dc="http://purl.org/dc/elements/1.1/"' .
703
+            ' xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/"' .
704
+            ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' .
705
+            ' xsi:schemaLocation="' .
706
+            'urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/ http://www.upnp.org/schemas/av/didl-lite.xsd ' .
707
+            'urn:schemas-upnp-org:metadata-1-0/upnp/ http://www.upnp.org/schemas/av/upnp.xsd">';
708
+    $NumberReturned = 0;
709
+    $TotalMatches = 0;
710
+    $UpdateID = 1;
711
+
712
+    $Result = $Result . '</DIDL-Lite>';
713
+
714
+    return (array(	'Result' => $Result,
715
+            'NumberReturned' => $NumberReturned,
716
+            'TotalMatches' => $TotalMatches,
717
+            'UpdateID' => $UpdateID));
718 718
 }
719 719
 
720 720
 
721 721
 function CreateObject($ContainerID, $Elements) {
722
-	$ObjectID = '';
723
-	$Result = '';
722
+    $ObjectID = '';
723
+    $Result = '';
724 724
 
725
-	return (array(	'ObjectID' => $ObjectID,
726
-			'Result' => $Result));
725
+    return (array(	'ObjectID' => $ObjectID,
726
+            'Result' => $Result));
727 727
 }
728 728
 
729 729
 
@@ -741,27 +741,27 @@  discard block
 block discarded – undo
741 741
 
742 742
 /* Samsung private. */
743 743
 function X_GetFeatureList() {
744
-	$FeatureList = 
745
-		'<?xml version="1.0" encoding="UTF-8"?>' .
746
-		'<Features' .
747
-		' xmlns="urn:schemas-upnp-org:av:avs"' .
748
-		' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' .
749
-		' xmlns:sec="http://www.sec.co.kr/dlna"' .
750
-		' xsi:schemaLocation="urn:schemas-upnp-org:av:avs http://www.upnp.org/schemas/av/avs.xsd">' .
751
-			'<Feature name="samsung.com_BASICVIEW" version="1">' .
752
-			    '<container id="A" type="object.item.audioItem"/>' .
753
-			    '<container id="I" type="object.item.imageItem"/>' .
754
-			    '<container id="V" type="object.item.videoItem"/>' .
755
-			    '<container id="P" type="object.item.playlistItem"/>' .
756
-			    '<container id="T" type="object.item.textItem"/>' .
757
-			'</Feature>' .
758
-		'</Features>';
759
-
760
-	return ($FeatureList);
744
+    $FeatureList = 
745
+        '<?xml version="1.0" encoding="UTF-8"?>' .
746
+        '<Features' .
747
+        ' xmlns="urn:schemas-upnp-org:av:avs"' .
748
+        ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' .
749
+        ' xmlns:sec="http://www.sec.co.kr/dlna"' .
750
+        ' xsi:schemaLocation="urn:schemas-upnp-org:av:avs http://www.upnp.org/schemas/av/avs.xsd">' .
751
+            '<Feature name="samsung.com_BASICVIEW" version="1">' .
752
+                '<container id="A" type="object.item.audioItem"/>' .
753
+                '<container id="I" type="object.item.imageItem"/>' .
754
+                '<container id="V" type="object.item.videoItem"/>' .
755
+                '<container id="P" type="object.item.playlistItem"/>' .
756
+                '<container id="T" type="object.item.textItem"/>' .
757
+            '</Feature>' .
758
+        '</Features>';
759
+
760
+    return ($FeatureList);
761 761
 }
762 762
 
763 763
 function X_SetBookmark($CategoryType, $RID, $ObjectID, $PosSecond) {
764
-	/* Return:
764
+    /* Return:
765 765
 	 * <sec:dcmInfo>BM=number of seconds</sec:dcmInfo>
766 766
 	 * <upnp:lastPlaybackPosition>HH:MM:SS</upnp:lastPlaybackPosition>
767 767
 	 */
@@ -773,27 +773,27 @@  discard block
 block discarded – undo
773 773
 
774 774
 $request_body = @file_get_contents('php://input');
775 775
 try {
776
-	$server->addFunction(array(	'GetSearchCapabilities',
777
-					'GetSortCapabilities',
778
-					'GetSortExtensionCapabilities',
779
-					'GetFeatureList',
780
-					'GetSystemUpdateID',
781
-					'GetServiceResetToken',
782
-					'Browse',
783
-					'Search',
784
-					'CreateObject',
785
-					'DestroyObject',
786
-					'UpdateObject',
787
-					'MoveObject',
788
-					'X_GetFeatureList',
789
-					'X_SetBookmark'
790
-				));
791
-	ob_start();
792
-	$server->handle($request_body); 
793
-	$soapXml = ob_get_clean();
776
+    $server->addFunction(array(	'GetSearchCapabilities',
777
+                    'GetSortCapabilities',
778
+                    'GetSortExtensionCapabilities',
779
+                    'GetFeatureList',
780
+                    'GetSystemUpdateID',
781
+                    'GetServiceResetToken',
782
+                    'Browse',
783
+                    'Search',
784
+                    'CreateObject',
785
+                    'DestroyObject',
786
+                    'UpdateObject',
787
+                    'MoveObject',
788
+                    'X_GetFeatureList',
789
+                    'X_SetBookmark'
790
+                ));
791
+    ob_start();
792
+    $server->handle($request_body); 
793
+    $soapXml = ob_get_clean();
794 794
 } catch (Exception $e) {
795
-	$server->fault($e->getCode(), $e->getMessage());
796
-	throw $e;
795
+    $server->fault($e->getCode(), $e->getMessage());
796
+    throw $e;
797 797
 }
798 798
 
799 799
 
@@ -801,44 +801,44 @@  discard block
 block discarded – undo
801 801
 
802 802
 
803 803
 function get_resp_tag_name($sxml) {
804
-	$tag_st = strpos($sxml, '<SOAP-ENV:Body><SOAP-ENV:');
805
-	if (false === $tag_st)
806
-		return (false);
807
-	$tag_st += 25;
808
-	$tag_end = strpos($sxml, '>', $tag_st);
809
-	if (false === $tag_end)
810
-		return (false);
811
-	return (substr($sxml, $tag_st, ($tag_end - $tag_st)));
804
+    $tag_st = strpos($sxml, '<SOAP-ENV:Body><SOAP-ENV:');
805
+    if (false === $tag_st)
806
+        return (false);
807
+    $tag_st += 25;
808
+    $tag_end = strpos($sxml, '>', $tag_st);
809
+    if (false === $tag_end)
810
+        return (false);
811
+    return (substr($sxml, $tag_st, ($tag_end - $tag_st)));
812 812
 }
813 813
 
814 814
 function get_tag_ns($req, $tag) {
815
-	$rreq = strrev($req);
816
-	$ns_st = strpos($rreq, strrev(":$tag>"));
817
-	if (false === $ns_st)
818
-		return (false);
819
-	$ns_st += (strlen($tag) + 2);
820
-	$ns_end = strpos($rreq, '/<', $ns_st);
821
-	if (false === $ns_end)
822
-		return (false);
823
-	return (strrev(substr($rreq, $ns_st, ($ns_end - $ns_st))));
815
+    $rreq = strrev($req);
816
+    $ns_st = strpos($rreq, strrev(":$tag>"));
817
+    if (false === $ns_st)
818
+        return (false);
819
+    $ns_st += (strlen($tag) + 2);
820
+    $ns_end = strpos($rreq, '/<', $ns_st);
821
+    if (false === $ns_end)
822
+        return (false);
823
+    return (strrev(substr($rreq, $ns_st, ($ns_end - $ns_st))));
824 824
 }
825 825
 
826 826
 function tag_ns_replace($req, $sxml, $tag, $ns=false) {
827
-	if (false === $tag)
828
-		return ($sxml);
829
-	if (false === $ns)
830
-		$ns = get_tag_ns($req, $tag);
831
-	if (false === $ns)
832
-		return ($sxml);
833
-	while ($tag_st = strpos($sxml, "<SOAP-ENV:$tag")) {
834
-		$tag_end = strpos($sxml, '>', $tag_st);
835
-		if (false === $tag_end)
836
-			return ($sxml);
837
-		$old_tag_data = substr($sxml, $tag_st, ($tag_end - $tag_st));
838
-		$new_tag_data = str_replace('SOAP-ENV', $ns, $old_tag_data);
839
-		$sxml = str_replace($old_tag_data, $new_tag_data, $sxml);
840
-	}
841
-	return (str_replace("</SOAP-ENV:$tag>", "</$ns:$tag>", $sxml));
827
+    if (false === $tag)
828
+        return ($sxml);
829
+    if (false === $ns)
830
+        $ns = get_tag_ns($req, $tag);
831
+    if (false === $ns)
832
+        return ($sxml);
833
+    while ($tag_st = strpos($sxml, "<SOAP-ENV:$tag")) {
834
+        $tag_end = strpos($sxml, '>', $tag_st);
835
+        if (false === $tag_end)
836
+            return ($sxml);
837
+        $old_tag_data = substr($sxml, $tag_st, ($tag_end - $tag_st));
838
+        $new_tag_data = str_replace('SOAP-ENV', $ns, $old_tag_data);
839
+        $sxml = str_replace($old_tag_data, $new_tag_data, $sxml);
840
+    }
841
+    return (str_replace("</SOAP-ENV:$tag>", "</$ns:$tag>", $sxml));
842 842
 }
843 843
 
844 844
 
Please login to merge, or discard this patch.
Spacing   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -41,14 +41,14 @@  discard block
 block discarded – undo
41 41
 
42 42
  
43 43
 /* Config.*/
44
-$basedir = dirname(__FILE__) . '/../../upnpdata'; /* File system path. */
45
-$baseurl = '/upnpdata';				/* WEB URL path. */
44
+$basedir = dirname(__FILE__).'/../../upnpdata'; /* File system path. */
45
+$baseurl = '/upnpdata'; /* WEB URL path. */
46 46
 
47 47
 date_default_timezone_set('UTC');
48 48
 
49 49
 
50 50
 /* File types. */
51
-$file_class = array (
51
+$file_class = array(
52 52
 	'm3u' => 'object.container.storageFolder',
53 53
 	'xspf' => 'object.container.storageFolder',
54 54
 	'xml' => 'object.container.storageFolder',
@@ -118,12 +118,12 @@  discard block
 block discarded – undo
118 118
 
119 119
 
120 120
 if (substr($basedir, -1, 1) !== '/') {
121
-	$basedir = $basedir . '/';
121
+	$basedir = $basedir.'/';
122 122
 }
123 123
 $baseurl = implode('/', array_map('rawurlencode', explode('/', $baseurl)));
124
-$baseurlpatch = 'http://' . $_SERVER['HTTP_HOST'] . $baseurl;
124
+$baseurlpatch = 'http://'.$_SERVER['HTTP_HOST'].$baseurl;
125 125
 if ('/' !== substr($baseurlpatch, -1, 1)) {
126
-	$baseurlpatch = $baseurlpatch . '/';
126
+	$baseurlpatch = $baseurlpatch.'/';
127 127
 }
128 128
 /**
129 129
  * Apply workaround for the libxml PHP bugs:
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 
137 137
 # $server = new SoapServer(null, array('uri' => "urn:schemas-upnp-org:service:ContentDirectory:3"));
138 138
 $server = new SoapServer(dirname(__FILE__)."/../descr/ContentDirectory.wdsl",
139
-		array(	'cache_wsdl' => WSDL_CACHE_MEMORY,
139
+		array('cache_wsdl' => WSDL_CACHE_MEMORY,
140 140
 			'soap_version' => SOAP_1_2,
141 141
 			'trace' => true
142 142
 		));
@@ -145,16 +145,16 @@  discard block
 block discarded – undo
145 145
 function xml_encode($string) {
146 146
 
147 147
 	return (str_replace(
148
-	    array("&",		"<",	">",	/*'"',*/	"'"),
149
-	    array("&amp;",	"&lt;",	"&gt;",	/*"&quot;",*/	"&apos;"), 
148
+	    array("&", "<", ">", /*'"',*/	"'"),
149
+	    array("&amp;", "&lt;", "&gt;", /*"&quot;",*/	"&apos;"), 
150 150
 	    $string));
151 151
 }
152 152
 
153 153
 function xml_decode($string) {
154 154
 
155 155
 	return (str_replace(
156
-	    array("&amp;",	"&lt;",	"&gt;",	"&quot;",	"&apos;"), 
157
-	    array("&",		"<",	">",	'"',		"'"),
156
+	    array("&amp;", "&lt;", "&gt;", "&quot;", "&apos;"), 
157
+	    array("&", "<", ">", '"', "'"),
158 158
 	    $string));
159 159
 }
160 160
 
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 		//return (xml_encode($url));
169 169
 		//return ('<![CDATA[' . xml_encode($url) . ']]');
170 170
 
171
-	return (substr($url, 0, $url_path_off) . implode('/', array_map('rawurlencode', explode('/', substr($url, $url_path_off)))));
171
+	return (substr($url, 0, $url_path_off).implode('/', array_map('rawurlencode', explode('/', substr($url, $url_path_off)))));
172 172
 	//return (substr($url, 0, $url_path_off) . xml_encode(implode('/', array_map('rawurlencode', explode('/', substr($url, $url_path_off))))));
173 173
 	//return (substr($url, 0, $url_path_off) . xml_encode(substr($url, $url_path_off)));
174 174
 	//return ('<![CDATA[$url]]');
@@ -221,9 +221,9 @@  discard block
 block discarded – undo
221 221
 		$entry = trim(fgets($fd));
222 222
 		if (false === strpos($entry, '://'))
223 223
 			continue;
224
-		$items_count ++;
224
+		$items_count++;
225 225
 	} 
226
-	fclose ($fd);
226
+	fclose($fd);
227 227
 
228 228
 	return ($items_count);
229 229
 }
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
 	$res = date('Y-m-d', $timedate);
304 304
 
305 305
 	if (1 === $format) {
306
-		$res = $res . 'T' . date('H:i:s', $timedate);
306
+		$res = $res.'T'.date('H:i:s', $timedate);
307 307
 	}
308 308
 
309 309
 	return ($res);
@@ -364,14 +364,14 @@  discard block
 block discarded – undo
364 364
 function Browse($ObjectID, $BrowseFlag, $Filter, $StartingIndex,
365 365
     $RequestedCount, $SortCriteria) {
366 366
 	global $basedir, $baseurl, $baseurlpatch;
367
-	$Result =   '<DIDL-Lite' .
368
-		    ' xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"' .
369
-		    ' xmlns:dlna="urn:schemas-dlna-org:metadata-1-0/"' .
370
-		    ' xmlns:dc="http://purl.org/dc/elements/1.1/"' .
371
-		    ' xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/"' .
372
-		    ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' .
373
-		    ' xsi:schemaLocation="' .
374
-			'urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/ http://www.upnp.org/schemas/av/didl-lite.xsd ' .
367
+	$Result = '<DIDL-Lite'.
368
+		    ' xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"'.
369
+		    ' xmlns:dlna="urn:schemas-dlna-org:metadata-1-0/"'.
370
+		    ' xmlns:dc="http://purl.org/dc/elements/1.1/"'.
371
+		    ' xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/"'.
372
+		    ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'.
373
+		    ' xsi:schemaLocation="'.
374
+			'urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/ http://www.upnp.org/schemas/av/didl-lite.xsd '.
375 375
 			'urn:schemas-upnp-org:metadata-1-0/upnp/ http://www.upnp.org/schemas/av/upnp.xsd">';
376 376
 	$ParentID = '-1';
377 377
 	$NumberReturned = 0;
@@ -395,12 +395,12 @@  discard block
 block discarded – undo
395 395
 		} else {
396 396
 			$dir = rawurldecode(xml_decode($ObjectID));
397 397
 			if ('/' !== substr($dir, -1, 1)) {
398
-				$dir = $dir . '/';
398
+				$dir = $dir.'/';
399 399
 			}
400 400
 			/* Sec check: .. in path */
401 401
 			$dotdotdir = '';
402 402
 			$dirnames = explode('/', $dir);
403
-			for ($di = 0; $di < sizeof($dirnames); $di ++) {
403
+			for ($di = 0; $di < sizeof($dirnames); $di++) {
404 404
 				if ('.' === $dirnames[$di])
405 405
 					continue;
406 406
 				if ('..' === $dirnames[$di]) {
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
 					break;
409 409
 				}
410 410
 				if ((sizeof($dirnames) - 1) > $di) {
411
-					$dotdotdir = $dotdotdir . $dirnames[$di] . '/';
411
+					$dotdotdir = $dotdotdir.$dirnames[$di].'/';
412 412
 				}
413 413
 			}
414 414
 			$dir = $dotdotdir;
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
 		/* Is file/dir exist? */
432 432
 		$stat = stat($filename);
433 433
 		if (false === $stat) { /* No such file/dir. */
434
-			return (array(	'Result' => '',
434
+			return (array('Result' => '',
435 435
 					'NumberReturned' => 0,
436 436
 					'TotalMatches' => 0,
437 437
 					'UpdateID' => $UpdateID));
@@ -459,45 +459,45 @@  discard block
 block discarded – undo
459 459
 			$StorageFree = disk_free_space($filename);
460 460
 			$StorageUsed = ($StorageTotal - $StorageFree);
461 461
 			$ChildCount = (count(scandir($filename)) - 2);
462
-			$Result = $Result .
463
-			    "<container id=\"$ObjectID\" parentID=\"$ParentID\" restricted=\"$Restricted\" searchable=\"1\" childCount=\"$ChildCount\">" .
464
-				"<dc:title>$title</dc:title>" .
465
-				'<upnp:class>object.container.storageFolder</upnp:class>' .
466
-				"<upnp:storageTotal>$StorageTotal</upnp:storageTotal>" .
467
-				"<upnp:storageFree>$StorageFree</upnp:storageFree>" .
468
-				"<upnp:storageUsed>$StorageUsed</upnp:storageUsed>" .
462
+			$Result = $Result.
463
+			    "<container id=\"$ObjectID\" parentID=\"$ParentID\" restricted=\"$Restricted\" searchable=\"1\" childCount=\"$ChildCount\">".
464
+				"<dc:title>$title</dc:title>".
465
+				'<upnp:class>object.container.storageFolder</upnp:class>'.
466
+				"<upnp:storageTotal>$StorageTotal</upnp:storageTotal>".
467
+				"<upnp:storageFree>$StorageFree</upnp:storageFree>".
468
+				"<upnp:storageUsed>$StorageUsed</upnp:storageUsed>".
469 469
 				"<upnp:writeStatus>$WriteStatus</upnp:writeStatus>";
470 470
 			if ('0' === $ObjectID) {
471
-				$Result = $Result .
472
-					'<upnp:searchClass includeDerived="1">object.item.audioItem</upnp:searchClass>' .
473
-					'<upnp:searchClass includeDerived="1">object.item.imageItem</upnp:searchClass>' .
471
+				$Result = $Result.
472
+					'<upnp:searchClass includeDerived="1">object.item.audioItem</upnp:searchClass>'.
473
+					'<upnp:searchClass includeDerived="1">object.item.imageItem</upnp:searchClass>'.
474 474
 					'<upnp:searchClass includeDerived="1">object.item.videoItem</upnp:searchClass>';
475 475
 			}
476
-			$Result = $Result . '</container>';
476
+			$Result = $Result.'</container>';
477 477
 		} else { /* File or playlist. */
478 478
 			$iclass = upnp_get_class($basefilename, 'object.item.videoItem');
479 479
 			if ('object.container.storageFolder' === $iclass) { /* Play list as folder! */
480 480
 				$ChildCount = m3u_calc_items_count($filename);
481
-				$Result = $Result .
482
-				    "<container id=\"$ObjectID\" parentID=\"$ParentID\" restricted=\"$Restricted\" searchable=\"1\" childCount=\"$ChildCount\">" .
483
-					"<dc:title>$title</dc:title>" .
484
-					'<upnp:class>object.container.storageFolder</upnp:class>' .
481
+				$Result = $Result.
482
+				    "<container id=\"$ObjectID\" parentID=\"$ParentID\" restricted=\"$Restricted\" searchable=\"1\" childCount=\"$ChildCount\">".
483
+					"<dc:title>$title</dc:title>".
484
+					'<upnp:class>object.container.storageFolder</upnp:class>'.
485 485
 				    '</container>';
486 486
 			} else {
487 487
 				$date = upnp_date(filectime($filename), 1);
488 488
 				$size = filesize($filename);
489 489
 				$mimetype = upnp_mime_content_type($filename);
490
-				$Result = $Result .
491
-				    "<item id=\"$ObjectID\" parentID=\"$ParentID\" restricted=\"$Restricted\">" .
492
-					"<dc:title>$title</dc:title>" .
493
-					"<dc:date>$date</dc:date>" .
494
-					"<upnp:class>$iclass</upnp:class>" .
495
-					"<res size=\"$size\" protocolInfo=\"http-get:*:$mimetype:*\">$ObjectID</res>" .
490
+				$Result = $Result.
491
+				    "<item id=\"$ObjectID\" parentID=\"$ParentID\" restricted=\"$Restricted\">".
492
+					"<dc:title>$title</dc:title>".
493
+					"<dc:date>$date</dc:date>".
494
+					"<upnp:class>$iclass</upnp:class>".
495
+					"<res size=\"$size\" protocolInfo=\"http-get:*:$mimetype:*\">$ObjectID</res>".
496 496
 				    '</item>';
497 497
 			}
498 498
 		}
499
-		$Result = $Result . '</DIDL-Lite>';
500
-		return (array(	'Result' => $Result,
499
+		$Result = $Result.'</DIDL-Lite>';
500
+		return (array('Result' => $Result,
501 501
 				'NumberReturned' => 1,
502 502
 				'TotalMatches' => 1,
503 503
 				'UpdateID' => $UpdateID));
@@ -515,7 +515,7 @@  discard block
 block discarded – undo
515 515
 		$filename = $basedir.$dir;
516 516
 		$fd = fopen($filename, 'r');
517 517
 		if (false === $fd) {
518
-			return (array(	'Result' => '',
518
+			return (array('Result' => '',
519 519
 					'NumberReturned' => 0,
520 520
 					'TotalMatches' => 0,
521 521
 					'UpdateID' => $UpdateID));
@@ -550,14 +550,14 @@  discard block
 block discarded – undo
550 550
 			if (false === strpos($entry, '://'))
551 551
 				continue;
552 552
 			/* Ok, item matched and may be returned. */
553
-			$TotalMatches ++;
553
+			$TotalMatches++;
554 554
 			if (0 < $StartingIndex &&
555 555
 			    $TotalMatches < $StartingIndex)
556 556
 				continue; /* Skip first items. */
557 557
 			if (0 < $RequestedCount &&
558 558
 			    $NumberReturned >= $RequestedCount)
559 559
 				continue; /* Do not add more than requested. */
560
-			$NumberReturned ++;
560
+			$NumberReturned++;
561 561
 			/* Add item to result. */
562 562
 			$title = xml_encode(trim(substr($buffer, (strpos($buffer, ',') + 1))));
563 563
 			//$en_entry = upnp_url_encode($entry);
@@ -565,10 +565,10 @@  discard block
 block discarded – undo
565 565
 			$iclass = upnp_get_class($entry, 'object.item.videoItem.videoBroadcast');
566 566
 			$mimetype = 'video/mpeg';
567 567
 			if ('object.container.storageFolder' === $iclass) { /* Play list as folder! */
568
-				$Result = $Result .
569
-				    "<container id=\"$en_entry\" parentID=\"$ObjectID\" restricted=\"$Restricted\">" .
570
-					"<dc:title>$title</dc:title>" .
571
-					'<upnp:class>object.container.storageFolder</upnp:class>' .
568
+				$Result = $Result.
569
+				    "<container id=\"$en_entry\" parentID=\"$ObjectID\" restricted=\"$Restricted\">".
570
+					"<dc:title>$title</dc:title>".
571
+					'<upnp:class>object.container.storageFolder</upnp:class>'.
572 572
 				    '</container>';
573 573
 			} else {
574 574
 				//$logo = get_named_val("tvg-logo", $buffer);
@@ -576,21 +576,21 @@  discard block
 block discarded – undo
576 576
 				//	$logo = trim(substr($buffer, (strpos($buffer, ',') + 1)));
577 577
 				//}
578 578
 				//$icon_url = upnp_url_encode($logo_url_path . mb_convert_case($logo, MB_CASE_LOWER, "UTF-8") . '.png');
579
-				$Result = $Result .
580
-				    "<item id=\"$en_entry\" parentID=\"$ObjectID\" restricted=\"$Restricted\">" .
581
-					"<dc:title>$title</dc:title>" .
582
-					"<dc:date>$date</dc:date>" .
579
+				$Result = $Result.
580
+				    "<item id=\"$en_entry\" parentID=\"$ObjectID\" restricted=\"$Restricted\">".
581
+					"<dc:title>$title</dc:title>".
582
+					"<dc:date>$date</dc:date>".
583 583
 					//"<upnp:albumArtURI dlna:profileID=\"JPEG_TN\" xmlns:dlna=\"urn:schemas-dlna-org:metadata-1-0\">$icon_url</upnp:albumArtURI>" .
584 584
 					//"<upnp:icon>$icon_url</upnp:icon>" .
585
-					"<upnp:class>$iclass</upnp:class>" .
586
-					"<res protocolInfo=\"http-get:*:$mimetype:*\">$en_entry</res>" .
585
+					"<upnp:class>$iclass</upnp:class>".
586
+					"<res protocolInfo=\"http-get:*:$mimetype:*\">$en_entry</res>".
587 587
 				    '</item>';
588 588
 			}
589 589
 		} 
590
-		fclose ($fd);
590
+		fclose($fd);
591 591
 
592
-		$Result = $Result . '</DIDL-Lite>';
593
-		return (array(	'Result' => $Result,
592
+		$Result = $Result.'</DIDL-Lite>';
593
+		return (array('Result' => $Result,
594 594
 				'NumberReturned' => $NumberReturned,
595 595
 				'TotalMatches' => $TotalMatches,
596 596
 				'UpdateID' => $UpdateID));
@@ -605,14 +605,14 @@  discard block
 block discarded – undo
605 605
 		    !is_dir($filename)) /* Skip files. */
606 606
 			continue;
607 607
 		/* Ok, item matched and may be returned. */
608
-		$TotalMatches ++;
608
+		$TotalMatches++;
609 609
 		if (0 < $StartingIndex &&
610 610
 		    $TotalMatches < $StartingIndex)
611 611
 			continue; /* Skip first items. */
612 612
 		if (0 < $RequestedCount &&
613 613
 		    $NumberReturned >= $RequestedCount)
614 614
 			continue; /* Do not add more than requested. */
615
-		$NumberReturned ++;
615
+		$NumberReturned++;
616 616
 		/* Add item to result. */
617 617
 		if (is_writable($filename)) {
618 618
 			$Restricted = '0';
@@ -622,10 +622,10 @@  discard block
 block discarded – undo
622 622
 		$title = xml_encode($entry);
623 623
 		$en_entry = upnp_url_encode($dir.$entry);
624 624
 		$ChildCount = (count(scandir($filename)) - 2);
625
-		$Result = $Result .
626
-		    "<container id=\"$en_entry\" parentID=\"$ObjectID\" restricted=\"$Restricted\" searchable=\"1\" childCount=\"$ChildCount\">" .
627
-			"<dc:title>$title</dc:title>" .
628
-			'<upnp:class>object.container.storageFolder</upnp:class>' .
625
+		$Result = $Result.
626
+		    "<container id=\"$en_entry\" parentID=\"$ObjectID\" restricted=\"$Restricted\" searchable=\"1\" childCount=\"$ChildCount\">".
627
+			"<dc:title>$title</dc:title>".
628
+			'<upnp:class>object.container.storageFolder</upnp:class>'.
629 629
 		    '</container>';
630 630
 	}
631 631
 	/* Add files to play list. */
@@ -637,14 +637,14 @@  discard block
 block discarded – undo
637 637
 		if (null === $iclass) /* Skip unsupported file type. */
638 638
 			continue;
639 639
 		/* Ok, item matched and may be returned. */
640
-		$TotalMatches ++;
640
+		$TotalMatches++;
641 641
 		if (0 < $StartingIndex &&
642 642
 		    $TotalMatches < $StartingIndex)
643 643
 			continue; /* Skip first items. */
644 644
 		if (0 < $RequestedCount &&
645 645
 		    $NumberReturned >= $RequestedCount)
646 646
 			continue; /* Do not add more than requested. */
647
-		$NumberReturned ++;
647
+		$NumberReturned++;
648 648
 		/* Add item to result. */
649 649
 		if (is_writable($filename)) {
650 650
 			$Restricted = '0';
@@ -655,38 +655,38 @@  discard block
 block discarded – undo
655 655
 		$en_entry = upnp_url_encode($dir.$entry);
656 656
 		if ('object.container.storageFolder' === $iclass) { /* Play list as folder! */
657 657
 			$ChildCount = m3u_calc_items_count($filename);
658
-			$Result = $Result .
659
-			    "<container id=\"$en_entry\" parentID=\"$ObjectID\" restricted=\"$Restricted\" searchable=\"1\" childCount=\"$ChildCount\">" .
660
-				"<dc:title>$title</dc:title>" .
661
-				'<upnp:class>object.container.storageFolder</upnp:class>' .
658
+			$Result = $Result.
659
+			    "<container id=\"$en_entry\" parentID=\"$ObjectID\" restricted=\"$Restricted\" searchable=\"1\" childCount=\"$ChildCount\">".
660
+				"<dc:title>$title</dc:title>".
661
+				'<upnp:class>object.container.storageFolder</upnp:class>'.
662 662
 			    '</container>';
663 663
 		} else {
664 664
 			$date = upnp_date(filectime($filename), 1);
665 665
 			$size = filesize($filename);
666 666
 			$mimetype = upnp_mime_content_type($filename);
667 667
 			$res_info_ex = '';
668
-			$Result = $Result .
669
-			    "<item id=\"$en_entry\" parentID=\"$ObjectID\" restricted=\"$Restricted\">" .
670
-				"<dc:title>$title</dc:title>" .
671
-				"<dc:date>$date</dc:date>" .
668
+			$Result = $Result.
669
+			    "<item id=\"$en_entry\" parentID=\"$ObjectID\" restricted=\"$Restricted\">".
670
+				"<dc:title>$title</dc:title>".
671
+				"<dc:date>$date</dc:date>".
672 672
 				"<upnp:class>$iclass</upnp:class>";
673 673
 			if ('object.item.imageItem' === substr($iclass, 0, 21)) {
674
-				$Result = $Result .
675
-				    "<upnp:albumArtURI>$baseurlpatch$en_entry</upnp:albumArtURI>" .
674
+				$Result = $Result.
675
+				    "<upnp:albumArtURI>$baseurlpatch$en_entry</upnp:albumArtURI>".
676 676
 				    "<upnp:icon>$baseurlpatch$en_entry</upnp:icon>";
677 677
 				$img_info = getimagesize($filename);
678 678
 				if (false !== $img_info) {
679
-					$res_info_ex = ' resolution="' . $img_info[0] . 'x' . $img_info[1] . '"';
679
+					$res_info_ex = ' resolution="'.$img_info[0].'x'.$img_info[1].'"';
680 680
 				}
681 681
 			}
682
-			$Result = $Result .
683
-				"<res size=\"$size\"$res_info_ex protocolInfo=\"http-get:*:$mimetype:*\">$baseurlpatch$en_entry</res>" .
682
+			$Result = $Result.
683
+				"<res size=\"$size\"$res_info_ex protocolInfo=\"http-get:*:$mimetype:*\">$baseurlpatch$en_entry</res>".
684 684
 			    '</item>';
685 685
 		}
686 686
 	}
687 687
 
688
-	$Result = $Result . '</DIDL-Lite>';
689
-	return (array(	'Result' => $Result,
688
+	$Result = $Result.'</DIDL-Lite>';
689
+	return (array('Result' => $Result,
690 690
 			'NumberReturned' => $NumberReturned,
691 691
 			'TotalMatches' => $TotalMatches,
692 692
 			'UpdateID' => $UpdateID));
@@ -696,22 +696,22 @@  discard block
 block discarded – undo
696 696
 function Search($ContainerID, $SearchCriteria, $Filter, $StartingIndex,
697 697
     $RequestedCount, $SortCriteria) {
698 698
 	global $basedir, $baseurl, $baseurlpatch;
699
-	$Result =   '<DIDL-Lite' .
700
-		    ' xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"' .
701
-		    ' xmlns:dlna="urn:schemas-dlna-org:metadata-1-0/"' .
702
-		    ' xmlns:dc="http://purl.org/dc/elements/1.1/"' .
703
-		    ' xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/"' .
704
-		    ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' .
705
-		    ' xsi:schemaLocation="' .
706
-			'urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/ http://www.upnp.org/schemas/av/didl-lite.xsd ' .
699
+	$Result = '<DIDL-Lite'.
700
+		    ' xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"'.
701
+		    ' xmlns:dlna="urn:schemas-dlna-org:metadata-1-0/"'.
702
+		    ' xmlns:dc="http://purl.org/dc/elements/1.1/"'.
703
+		    ' xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/"'.
704
+		    ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'.
705
+		    ' xsi:schemaLocation="'.
706
+			'urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/ http://www.upnp.org/schemas/av/didl-lite.xsd '.
707 707
 			'urn:schemas-upnp-org:metadata-1-0/upnp/ http://www.upnp.org/schemas/av/upnp.xsd">';
708 708
 	$NumberReturned = 0;
709 709
 	$TotalMatches = 0;
710 710
 	$UpdateID = 1;
711 711
 
712
-	$Result = $Result . '</DIDL-Lite>';
712
+	$Result = $Result.'</DIDL-Lite>';
713 713
 
714
-	return (array(	'Result' => $Result,
714
+	return (array('Result' => $Result,
715 715
 			'NumberReturned' => $NumberReturned,
716 716
 			'TotalMatches' => $TotalMatches,
717 717
 			'UpdateID' => $UpdateID));
@@ -722,7 +722,7 @@  discard block
 block discarded – undo
722 722
 	$ObjectID = '';
723 723
 	$Result = '';
724 724
 
725
-	return (array(	'ObjectID' => $ObjectID,
725
+	return (array('ObjectID' => $ObjectID,
726 726
 			'Result' => $Result));
727 727
 }
728 728
 
@@ -742,19 +742,19 @@  discard block
 block discarded – undo
742 742
 /* Samsung private. */
743 743
 function X_GetFeatureList() {
744 744
 	$FeatureList = 
745
-		'<?xml version="1.0" encoding="UTF-8"?>' .
746
-		'<Features' .
747
-		' xmlns="urn:schemas-upnp-org:av:avs"' .
748
-		' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' .
749
-		' xmlns:sec="http://www.sec.co.kr/dlna"' .
750
-		' xsi:schemaLocation="urn:schemas-upnp-org:av:avs http://www.upnp.org/schemas/av/avs.xsd">' .
751
-			'<Feature name="samsung.com_BASICVIEW" version="1">' .
752
-			    '<container id="A" type="object.item.audioItem"/>' .
753
-			    '<container id="I" type="object.item.imageItem"/>' .
754
-			    '<container id="V" type="object.item.videoItem"/>' .
755
-			    '<container id="P" type="object.item.playlistItem"/>' .
756
-			    '<container id="T" type="object.item.textItem"/>' .
757
-			'</Feature>' .
745
+		'<?xml version="1.0" encoding="UTF-8"?>'.
746
+		'<Features'.
747
+		' xmlns="urn:schemas-upnp-org:av:avs"'.
748
+		' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'.
749
+		' xmlns:sec="http://www.sec.co.kr/dlna"'.
750
+		' xsi:schemaLocation="urn:schemas-upnp-org:av:avs http://www.upnp.org/schemas/av/avs.xsd">'.
751
+			'<Feature name="samsung.com_BASICVIEW" version="1">'.
752
+			    '<container id="A" type="object.item.audioItem"/>'.
753
+			    '<container id="I" type="object.item.imageItem"/>'.
754
+			    '<container id="V" type="object.item.videoItem"/>'.
755
+			    '<container id="P" type="object.item.playlistItem"/>'.
756
+			    '<container id="T" type="object.item.textItem"/>'.
757
+			'</Feature>'.
758 758
 		'</Features>';
759 759
 
760 760
 	return ($FeatureList);
@@ -773,7 +773,7 @@  discard block
 block discarded – undo
773 773
 
774 774
 $request_body = @file_get_contents('php://input');
775 775
 try {
776
-	$server->addFunction(array(	'GetSearchCapabilities',
776
+	$server->addFunction(array('GetSearchCapabilities',
777 777
 					'GetSortCapabilities',
778 778
 					'GetSortExtensionCapabilities',
779 779
 					'GetFeatureList',
@@ -823,7 +823,7 @@  discard block
 block discarded – undo
823 823
 	return (strrev(substr($rreq, $ns_st, ($ns_end - $ns_st))));
824 824
 }
825 825
 
826
-function tag_ns_replace($req, $sxml, $tag, $ns=false) {
826
+function tag_ns_replace($req, $sxml, $tag, $ns = false) {
827 827
 	if (false === $tag)
828 828
 		return ($sxml);
829 829
 	if (false === $ns)
@@ -855,7 +855,7 @@  discard block
 block discarded – undo
855 855
 $soapXml = tag_ns_replace($request_body, $soapXml, $soap_act_resp_tag, get_tag_ns($request_body, $soap_service_func));
856 856
 
857 857
 $length = strlen($soapXml);
858
-header('Content-Length: ' . $length);
858
+header('Content-Length: '.$length);
859 859
 echo $soapXml;
860 860
 
861 861
 ?>
Please login to merge, or discard this patch.
Braces   +101 added lines, -58 removed lines patch added patch discarded remove patch
@@ -111,8 +111,9 @@  discard block
 block discarded – undo
111 111
 /* "urn:schemas-upnp-org:service:ContentDirectory:1#Browse" */
112 112
 $http_hdr_soapact = $_SERVER['HTTP_SOAPACTION'];
113 113
 $soap_shemas = strpos($http_hdr_soapact, 'urn:schemas-upnp-org:service:ContentDirectory:');
114
-if (false === $soap_shemas)
114
+if (false === $soap_shemas) {
115 115
 	return (500);
116
+}
116 117
 $soap_service_ver = substr($http_hdr_soapact, ($soap_shemas + 46), 1);
117 118
 $soap_service_func = substr($http_hdr_soapact, ($soap_shemas + 48), -1);
118 119
 
@@ -162,8 +163,9 @@  discard block
 block discarded – undo
162 163
 function upnp_url_encode($url) {
163 164
 
164 165
 	if ('http://' !== substr($url, 0, 7) ||
165
-	    false === ($url_path_off = strrpos($url, '/', 8)))
166
-		return (implode('/', array_map('rawurlencode', explode('/', $url))));
166
+	    false === ($url_path_off = strrpos($url, '/', 8))) {
167
+			return (implode('/', array_map('rawurlencode', explode('/', $url))));
168
+	}
167 169
 		//return (xml_encode(implode('/', array_map('rawurlencode', explode('/', $url)))));
168 170
 		//return (xml_encode($url));
169 171
 		//return ('<![CDATA[' . xml_encode($url) . ']]');
@@ -178,14 +180,18 @@  discard block
 block discarded – undo
178 180
 function upnp_get_class($file, $def) {
179 181
 	global $file_class;
180 182
 
181
-	if (!isset($file))
182
-		return ($def);
183
+	if (!isset($file)) {
184
+			return ($def);
185
+	}
183 186
 	$dot = strrpos($file, '.');
184
-	if (false === $dot)
185
-		return ($def);
187
+	if (false === $dot) {
188
+			return ($def);
189
+	}
186 190
 	$ext = strtolower(substr($file, ($dot + 1)));
187
-	if (isset($file_class[$ext])) /* Skip unsupported file type. */
191
+	if (isset($file_class[$ext])) {
192
+	    /* Skip unsupported file type. */
188 193
 		return ($file_class[$ext]);
194
+	}
189 195
 
190 196
 	return ($def);
191 197
 }
@@ -194,15 +200,18 @@  discard block
 block discarded – undo
194 200
 function get_named_val($name, $buf) { /* ...val_name="value"... */
195 201
 
196 202
 	$st_off = strpos($buf, $name);
197
-	if (false === $st_off)
198
-		return (null);
203
+	if (false === $st_off) {
204
+			return (null);
205
+	}
199 206
 	$st_off += strlen($name);
200
-	if ('="' !== substr($buf, $st_off, 2))
201
-		return (null);
207
+	if ('="' !== substr($buf, $st_off, 2)) {
208
+			return (null);
209
+	}
202 210
 	$st_off += 2;
203 211
 	$en_off = strpos($buf, '"', $st_off);
204
-	if (false === $en_off)
205
-		return (null);
212
+	if (false === $en_off) {
213
+			return (null);
214
+	}
206 215
 
207 216
 	return (substr($buf, $st_off, ($en_off - $st_off)));
208 217
 }
@@ -212,15 +221,19 @@  discard block
 block discarded – undo
212 221
 
213 222
 	$items_count = 0;
214 223
 	$fd = fopen($filename, 'r');
215
-	if (false === $fd)
216
-		return ($items_count);
224
+	if (false === $fd) {
225
+			return ($items_count);
226
+	}
217 227
 	while (!feof($fd)) { /* Read the file line by line... */
218 228
 		$buffer = trim(fgets($fd));
219
-		if (false === strpos($buffer, '#EXTINF:')) /* Skip empty/bad lines. */
229
+		if (false === strpos($buffer, '#EXTINF:')) {
230
+		    /* Skip empty/bad lines. */
220 231
 			continue;
232
+		}
221 233
 		$entry = trim(fgets($fd));
222
-		if (false === strpos($entry, '://'))
223
-			continue;
234
+		if (false === strpos($entry, '://')) {
235
+					continue;
236
+		}
224 237
 		$items_count ++;
225 238
 	} 
226 239
 	fclose ($fd);
@@ -277,11 +290,13 @@  discard block
 block discarded – undo
277 290
 		'ts' => 'video/MP2T',
278 291
 		'webm' => 'video/webm',
279 292
 	);
280
-	if (!isset($filename))
281
-		return ($def);
293
+	if (!isset($filename)) {
294
+			return ($def);
295
+	}
282 296
 	$dot = strrpos($filename, '.');
283
-	if (false === $dot)
284
-		return ($def);
297
+	if (false === $dot) {
298
+			return ($def);
299
+	}
285 300
 	$ext = strtolower(substr($filename, ($dot + 1)));
286 301
 	if (array_key_exists($ext, $mime_types)) {
287 302
 		return ($mime_types[$ext]);
@@ -401,8 +416,9 @@  discard block
 block discarded – undo
401 416
 			$dotdotdir = '';
402 417
 			$dirnames = explode('/', $dir);
403 418
 			for ($di = 0; $di < sizeof($dirnames); $di ++) {
404
-				if ('.' === $dirnames[$di])
405
-					continue;
419
+				if ('.' === $dirnames[$di]) {
420
+									continue;
421
+				}
406 422
 				if ('..' === $dirnames[$di]) {
407 423
 					$dir = '';
408 424
 					break;
@@ -547,16 +563,21 @@  discard block
 block discarded – undo
547 563
 				continue;
548 564
 			}
549 565
 			$entry = trim(fgets($fd));
550
-			if (false === strpos($entry, '://'))
551
-				continue;
566
+			if (false === strpos($entry, '://')) {
567
+							continue;
568
+			}
552 569
 			/* Ok, item matched and may be returned. */
553 570
 			$TotalMatches ++;
554 571
 			if (0 < $StartingIndex &&
555
-			    $TotalMatches < $StartingIndex)
556
-				continue; /* Skip first items. */
572
+			    $TotalMatches < $StartingIndex) {
573
+							continue;
574
+			}
575
+			/* Skip first items. */
557 576
 			if (0 < $RequestedCount &&
558
-			    $NumberReturned >= $RequestedCount)
559
-				continue; /* Do not add more than requested. */
577
+			    $NumberReturned >= $RequestedCount) {
578
+							continue;
579
+			}
580
+			/* Do not add more than requested. */
560 581
 			$NumberReturned ++;
561 582
 			/* Add item to result. */
562 583
 			$title = xml_encode(trim(substr($buffer, (strpos($buffer, ',') + 1))));
@@ -602,16 +623,22 @@  discard block
 block discarded – undo
602 623
 	foreach ($entries as $entry) {
603 624
 		$filename = $basedir.$dir.$entry;
604 625
 		if ('.' === substr($entry, 0, 1) ||
605
-		    !is_dir($filename)) /* Skip files. */
626
+		    !is_dir($filename)) {
627
+		    /* Skip files. */
606 628
 			continue;
629
+		}
607 630
 		/* Ok, item matched and may be returned. */
608 631
 		$TotalMatches ++;
609 632
 		if (0 < $StartingIndex &&
610
-		    $TotalMatches < $StartingIndex)
611
-			continue; /* Skip first items. */
633
+		    $TotalMatches < $StartingIndex) {
634
+					continue;
635
+		}
636
+		/* Skip first items. */
612 637
 		if (0 < $RequestedCount &&
613
-		    $NumberReturned >= $RequestedCount)
614
-			continue; /* Do not add more than requested. */
638
+		    $NumberReturned >= $RequestedCount) {
639
+					continue;
640
+		}
641
+		/* Do not add more than requested. */
615 642
 		$NumberReturned ++;
616 643
 		/* Add item to result. */
617 644
 		if (is_writable($filename)) {
@@ -631,19 +658,27 @@  discard block
 block discarded – undo
631 658
 	/* Add files to play list. */
632 659
 	foreach ($entries as $entry) {
633 660
 		$filename = $basedir.$dir.$entry;
634
-		if (is_dir($filename)) /* Skip dirs. */
661
+		if (is_dir($filename)) {
662
+		    /* Skip dirs. */
635 663
 			continue;
664
+		}
636 665
 		$iclass = upnp_get_class($entry, null);
637
-		if (null === $iclass) /* Skip unsupported file type. */
666
+		if (null === $iclass) {
667
+		    /* Skip unsupported file type. */
638 668
 			continue;
669
+		}
639 670
 		/* Ok, item matched and may be returned. */
640 671
 		$TotalMatches ++;
641 672
 		if (0 < $StartingIndex &&
642
-		    $TotalMatches < $StartingIndex)
643
-			continue; /* Skip first items. */
673
+		    $TotalMatches < $StartingIndex) {
674
+					continue;
675
+		}
676
+		/* Skip first items. */
644 677
 		if (0 < $RequestedCount &&
645
-		    $NumberReturned >= $RequestedCount)
646
-			continue; /* Do not add more than requested. */
678
+		    $NumberReturned >= $RequestedCount) {
679
+					continue;
680
+		}
681
+		/* Do not add more than requested. */
647 682
 		$NumberReturned ++;
648 683
 		/* Add item to result. */
649 684
 		if (is_writable($filename)) {
@@ -802,38 +837,46 @@  discard block
 block discarded – undo
802 837
 
803 838
 function get_resp_tag_name($sxml) {
804 839
 	$tag_st = strpos($sxml, '<SOAP-ENV:Body><SOAP-ENV:');
805
-	if (false === $tag_st)
806
-		return (false);
840
+	if (false === $tag_st) {
841
+			return (false);
842
+	}
807 843
 	$tag_st += 25;
808 844
 	$tag_end = strpos($sxml, '>', $tag_st);
809
-	if (false === $tag_end)
810
-		return (false);
845
+	if (false === $tag_end) {
846
+			return (false);
847
+	}
811 848
 	return (substr($sxml, $tag_st, ($tag_end - $tag_st)));
812 849
 }
813 850
 
814 851
 function get_tag_ns($req, $tag) {
815 852
 	$rreq = strrev($req);
816 853
 	$ns_st = strpos($rreq, strrev(":$tag>"));
817
-	if (false === $ns_st)
818
-		return (false);
854
+	if (false === $ns_st) {
855
+			return (false);
856
+	}
819 857
 	$ns_st += (strlen($tag) + 2);
820 858
 	$ns_end = strpos($rreq, '/<', $ns_st);
821
-	if (false === $ns_end)
822
-		return (false);
859
+	if (false === $ns_end) {
860
+			return (false);
861
+	}
823 862
 	return (strrev(substr($rreq, $ns_st, ($ns_end - $ns_st))));
824 863
 }
825 864
 
826 865
 function tag_ns_replace($req, $sxml, $tag, $ns=false) {
827
-	if (false === $tag)
828
-		return ($sxml);
829
-	if (false === $ns)
830
-		$ns = get_tag_ns($req, $tag);
831
-	if (false === $ns)
832
-		return ($sxml);
866
+	if (false === $tag) {
867
+			return ($sxml);
868
+	}
869
+	if (false === $ns) {
870
+			$ns = get_tag_ns($req, $tag);
871
+	}
872
+	if (false === $ns) {
873
+			return ($sxml);
874
+	}
833 875
 	while ($tag_st = strpos($sxml, "<SOAP-ENV:$tag")) {
834 876
 		$tag_end = strpos($sxml, '>', $tag_st);
835
-		if (false === $tag_end)
836
-			return ($sxml);
877
+		if (false === $tag_end) {
878
+					return ($sxml);
879
+		}
837 880
 		$old_tag_data = substr($sxml, $tag_st, ($tag_end - $tag_st));
838 881
 		$new_tag_data = str_replace('SOAP-ENV', $ns, $old_tag_data);
839 882
 		$sxml = str_replace($old_tag_data, $new_tag_data, $sxml);
Please login to merge, or discard this patch.