Esempio n. 1
0
 public function call($method, $params)
 {
     Logger::debug('New Request for method "' . $method . '" with params: ' . print_r($params, true), self::$logfile);
     if (isset($params['callback'])) {
         Logger::debug('Got callback: ' . $params['callback'], self::$logfile);
         $this->callback = $params['callback'];
         unset($params['callback']);
     }
     $device = isset($params['device']) ? $params['device'] : null;
     Logger::debug('Device: ' . var_export($device, true), self::$logfile);
     try {
         if (method_exists($this, $method)) {
             if (!is_null($device)) {
                 Logger::debug('Triggering "' . $method . '" with device and params', self::$logfile);
                 $this->{$method}($device, $params);
             } else {
                 Logger::debug('Triggering "' . $method . '" without device', self::$logfile);
                 $this->{$method}($params);
             }
         } else {
             Logger::warn('Unknown method: ' . $method, self::$logfile);
         }
     } catch (UPnPException $e) {
         Logger::error('Exception occured: ' . $e->getMessage(), self::$logfile);
     }
 }
Esempio n. 2
0
 /**
  * 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, '&lt;') !== false) {
             if (!$hideLogs) {
                 Logger::debug('Didl contains "&lt;" -> 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;
 }
Esempio n. 3
0
 /**
  * Removes an item from playlist
  *
  * @access public
  *
  * @param str $itemId
  */
 public function removeItem($itemId)
 {
     Logger::debug(__METHOD__, self::$logfile);
     if (isset($this->items[$itemId])) {
         Logger::debug('Item: ' . print_r($this->items[$itemId], true), self::$logfile);
         unset($this->items[$itemId]);
     } else {
         Logger::warn('Unable to find ' . $itemId, self::$logfile);
     }
     $this->save();
 }