Test Setup Failed
Branch master (a086b2)
by eertheertyerery
02:07
created
www/upnp/control/ContentDirectory.php 2 patches
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.