public function gen_afterPageBuild(X_Page_ItemList_PItem $list, Zend_Controller_Action $controller) { if (!$this->isDefaultRenderer()) { return; } X_Debug::i("Plugin triggered"); $request = $controller->getRequest(); $responseType = 'u:BrowseResponse'; $num = count($list->getItems()); if ($this->request['browseflag'] == 'BrowseMetadata') { $parentID = $this->_getParent($controller->getRequest()); $item = new X_Page_Item_PItem('fake-item', "Container"); $item->setLink(array_merge(array('controller' => $controller->getRequest()->getControllerName(), 'action' => $controller->getRequest()->getActionName()), $controller->getRequest()->getParams())); $item->setDescription("Fake description"); $didl = X_Upnp::createMetaDIDL($item, $parentID, $num, $controller->getRequest()->getControllerName(), $controller->getRequest()->getActionName(), $controller->getRequest()->getParam('p', 'null')); } elseif ($this->request['browseflag'] == 'BrowseDirectChildren') { $parentID = $this->request['objectid']; $didl = X_Upnp::createDIDL($list->getItems(), $parentID, $num, $controller->getRequest()->getControllerName(), $controller->getRequest()->getActionName(), $controller->getRequest()->getParam('p', 'null')); } $xmlDIDL = $didl->saveXML(); X_Debug::i("DIDL response: {$xmlDIDL}"); // Build SOAP-XML reply from DIDL-XML and send it to upnp device $domSOAP = X_Upnp::createSOAPEnvelope($xmlDIDL, $num, $num, $responseType, $parentID); $soapXML = $domSOAP->saveXML(); // turn off viewRenderer and Layout, add Content-Type and set response body $this->_render($soapXML, $controller); }
function controlAction() { $this->getResponse()->setHeader("Content-Type", "text/xml; charset=UTF-8"); $this->_helper->viewRenderer->setNoRender(true); $this->_helper->layout->disableLayout(); // control point for Upnp Devices. This url is referenced by service-desc manifest action //X_Debug::i("CONTROL ACTION REQUIRED!!!"); $requestRaw = file_get_contents('php://input'); X_Debug::i("Raw request: {$requestRaw}"); $parsed = X_Upnp::parseUPnPRequest($requestRaw); X_Debug::i("SOAP Request: " . print_r($parsed, true)); // define a one time control flag, this will // be catched by UpnpPlugin to force rendering and // ignore DevicesPlugin settings if (!defined('_X_UPNP_ORIGINAL_REQUEST_UPNP')) { define('_X_UPNP_ORIGINAL_REQUEST_UPNP', true); } $this->plugin->setSOAPRequest($parsed); //$case = "{$parsed['action']}/{$parsed['browseflag']}"; // if browseflag == BrowseMetadata I have to give back only // basic information about the container // if browseflag == BrowseDirectChildren I have to give back children if ($parsed['action'] == 'browse') { // delegate rendering and items creation to normal LVL1 API if ($parsed['objectid'] == '0' || $parsed['objectid'] == '-1') { $this->_helper->actionStack->actionToStack('collections', 'index'); } else { // need to parse the request $objectId = $parsed['objectid']; /* // decode ObjectId $requestDecoded = X_Env::decode($objectId); $args = array(); parse_str($requestDecoded, $args); // get the controller if ( isset($args['controller']) ) { $controller = $args['controller']; unset($args['controller']); } else { $controller = 'index'; } // get the action if ( isset($args['action']) ) { $action = $args['action']; unset($args['action']); } else { $action = 'collections'; } // get the module (for vlcs 0.6/2) if ( isset($args['module']) ) { $module = $args['module']; unset($args['module']); } else { $module = 'default'; } */ // normal objectid format is: // controller/action/provider/location#/ca1key/ca1value/ca2key/ca2value/.... // first split main string part from customs args @(list($mainArgs, $customArgs) = @explode('#', $objectId, 2)); // split main params @(list($controller, $action, $provider, $location) = @explode('/', $mainArgs, 4)); $args = array(); // check if custom args and populate $args if ($customArgs) { // explode all $exploded = explode('/', ltrim($customArgs, '/')); // params are: // key = 2k // values = 2k + 1 // the loop automatically skips key-only pair for ($i = 0; $i + 1 < count($exploded); $i = $i + 2) { $args[$exploded[$i]] = $exploded[$i + 1]; } } // provider and location in main params overwrite the same in customs (if any) if ($provider && $provider != 'null') { $args['p'] = $provider; } if ($location) { $args['l'] = $location; } X_Debug::i("Proxying request to {$controller}/{$action} with params: " . print_r($args, true)); // proxy request to normal LVL1 API $this->_helper->actionStack->actionToStack($action, $controller, 'default', $args); } } // else ignore request }
static function setDeviceName($deviceName) { self::$deviceName = $deviceName; }