private function respondHtmlTemplate($template, array $data) { Logger::debug(__METHOD__, self::$logfile); if (isset($data['0'])) { $item = $data[0]; $image = null; if (isset($item['albumArtURI'])) { $image = $item['albumArtURI']; } $item = (object) $item; $file = 'ajax-templates' . DIRECTORY_SEPARATOR . $template . '.php'; if (file_exists($file)) { ob_start(); require_once $file; $response = ob_get_clean(); if (isset($_GET['print'])) { echo $response; exit; } $response = utf8_decode($response); $response = rtrim(base64_encode($response), '=') . '=='; echo $response; } } exit; }
public function receivedEvent($transportState) { Logger::debug('Reveived transportState event: ' . $transportState, 'event'); if ($this->ignoreStops && $transportState == 'PLAYING') { Logger::debug('Finished ignoring STOPPED state', 'event'); $this->ignoreStops = false; $this->saveToCache(); } if ($this->ignoreStops && $transportState == 'STOPPED') { Logger::debug('Ignoring STOPPED state', 'event'); return; } switch ($transportState) { case 'STOPPED': Logger::debug('Try to play next', 'event'); $playlist = new Playlist($this->getId()); $next = $playlist->next(); break; } }
private function save() { $file = $this->getFile(); $data = array('current' => $this->currentPlaying, 'items' => $this->items); Logger::debug('Saving to ' . $file, self::$logfile); $res = file_put_contents($file, serialize($data)); if (!$res) { Logger::error('Not able to write ' . $file, self::$logfile); } }
/** * Transforms response XML to Array * * @access private * * @param string $method Method name * @param string $xml Response XML * * @return array */ private function parseResponse($method, $xml) { if ($xml == '') { return array(); } $hideLogs = $this->hideLogs; $original_xml = $xml; // Bad hack if (strstr($xml, 'parentID') !== false) { $xml = preg_replace('/ parentID="(.*)"/Uis', ' parentID="' . rand(1000, 9999) . '"', $xml); } $result = array(); $action = $this->getAction($method); $params = $action['out']; if (!$hideLogs) { Logger::debug('Expected response params: ' . print_r($params, true), self::$logfile); } foreach ($params as $param) { $name = $param['name']; $regex = sprintf('/<%s>(.*)<\\/%s>/Uis', $name, $name); preg_match($regex, $xml, $tmp); if (count($tmp) == 2) { if (!$hideLogs) { Logger::debug('Found ' . $name, self::$logfile); } $result[$name] = $tmp[1]; } else { if (!$hideLogs) { Logger::warn('Unable to find ' . $name . ' in response', self::$logfile); } throw new UPnPException('Missing response value: ' . $name); } } if ($method == 'Browse' || $method == 'GetPositionInfo' || $method == 'Search') { if (!$hideLogs) { Logger::debug('Detected "Browse", "Search" or "GetPositionInfo" - begin parsing didl', self::$logfile); } switch ($method) { case 'Browse': $tagname = 'Result'; break; case 'Search': $tagname = 'Result'; break; case 'GetPositionInfo': $tagname = 'TrackMetaData'; break; } if (!$hideLogs) { Logger::debug('Name of didl tag: "' . $tagname . '"', self::$logfile); } $data = array(); $xml = html_entity_decode($result[$tagname]); if (!$hideLogs) { Logger::debug($xml, self::$logfile); } if (strstr($xml, '<') !== false) { if (!$hideLogs) { Logger::debug('Didl contains "<" -> htmlspecialchars_decode();', self::$logfile); } $xml = htmlspecialchars_decode($xml); } $dom = new DOMDocument(); $dom->loadXML($xml); $root = $dom->childNodes->item(0); foreach ($root->childNodes as $node) { if (get_class($node) == 'DOMText') { continue; } $element = array(); $element['type'] = $node->tagName; if ($node->hasAttributes()) { $element['attributes'] = array(); foreach ($node->attributes as $attr) { $element['attributes'][$attr->name] = $attr->textContent; } } if ($node->hasChildNodes()) { $element['data'] = array(); $i = 0; foreach ($node->childNodes as $childNode) { $tmp = array(); $tmp['value'] = $childNode->textContent; if ($childNode->hasAttributes()) { foreach ($childNode->attributes as $attr) { $tmp['attributes'][$attr->name] = $attr->textContent; } } $t = explode(':', $childNode->tagName); $tagName = array_pop($t); $element['data'][$tagName][] = $tmp; } } $data[] = $element; } if (!$hideLogs) { Logger::debug($data, self::$logfile); } if (!$hideLogs) { Logger::debug('Move ' . $tagname . ' to ' . $tagname . '_XML in response', self::$logfile); } if (!$hideLogs) { Logger::debug('Add result as ' . $tagname . ' to response', self::$logfile); } $result[$tagname . '_XML'] = $result[$tagname]; $result[$tagname] = $data; } return $result; }
use at\mkweb\upnp\Logger; use DOMDocument; require_once 'src/at/mkweb/upnp/init.php'; $sid = 'uuid:daff8928-07f5-64d2-d666-4cede51e62f4'; $instanceId = 0; $transportState = 'STOPPED'; error_reporting(E_ALL); ini_set('display_errors', true); $request = ''; $headers = getallheaders(); $header = ''; foreach ($headers as $key => $value) { $header .= $key . ": " . $value . "\r\n"; } $request = file_get_contents('php://input'); Logger::debug($header . "\r\n\r\n" . $request . "\n\n", 'event'); $doc = new DomDocument(); $doc->loadXML($request); $root = $doc->childNodes->item(0); if ($root->localName == 'propertyset') { $property = $root->childNodes->item(0); if ($property->localName == 'property') { $data = $property->textContent; $doc = new DOMDocument(); $doc->loadXML($data); $root = $doc->childNodes->item(0); if ($root->localName == 'Event') { $instance = $root->childNodes->item(0); if ($instance->localName == 'InstanceID') { $instanceId = 0; $transportState = null;