/** * server received data * decodes the request * * @access private * @param integer $clientId id of the client that sent the data * @param string $xml xml data */ function onReceiveData($clientId, $xml) { // create dom tree $xmldoc = @xmldoc(trim($xml)); if (!is_object($xmldoc)) { $this->sendDebugMessage("Invalid XML received from {$clientId}"); return false; } // get root element (type of request) $root = $xmldoc->root(); $requestType = $root->node_name(); // extract request parameters $requestParams = array(); foreach ($root->children() as $child) { if ($child->node_type() != XML_ELEMENT_NODE) { continue; } $content = ""; foreach ($child->children() as $tmp) { if ($tmp->node_type() != XML_TEXT_NODE && $tmp->node_type() != XML_CDATA_SECTION_NODE) { continue; } $content .= $tmp->node_value(); } $requestParams[$child->node_name()] = $content; } // if introspection is allowed, check for // introspection method if ($this->allowIntrospection) { // check for requestType pat_* $regs = array(); if (preg_match('/^pat_(.+)$/', $requestType, $regs)) { $method = "_internal_" . $regs[1]; $this->sendDebugMessage("trying to call introspection method {$method}."); if (method_exists($this, $method)) { $this->sendDebugMessage("calling introspection method {$method}."); $this->{$method}($clientId, $requestParams); } return true; } } if (method_exists($this, "onReceiveRequest")) { $this->onReceiveRequest($clientId, $requestType, $requestParams); } }
/** * Returns additional menu informations decoded in the file that appears in the menu. * * You should subclass this method to make it work with your own * file formats. I used a simple XML format to store the content. * * @param string filename */ function exploreFile($file) { $xml = join('', @file($file)); if (!$xml) { return array(); } $doc = xmldoc($xml); $xpc = xpath_new_context($doc); $menu = xpath_eval($xpc, '//menu'); $node =& $menu->nodeset[0]; return array('title' => $node->content); }
function load($xml) { if (strncmp($xml, "<?xml", 5) == 0) { $n0 = xmldoc($xml); } else { $n0 = xmldocfile($xml); } $n1 = $n0->children(); foreach ($n1 as $j) { $n2 = $j->children(); foreach ($n2 as $i) { if ($i->type == XML_ELEMENT_NODE and $i->tagname == "t") { $ia = $i->attributes(); if ($ia[0]->name == "name" or $ia[0]->name == "form") { $this->template[$ia[0]->value] = $i; } } } } }
/** * Adds a xml string to $this->xmldoc. * It's inserted on the same level as a "normal" resultset, means just as a children of <root> * if a xpath expression is supplied, it takes that for selecting only part of the xml-file * * @param string xml string * @param mixed xpath either a string with the xpath expression or an array with * "xpath"=>xpath expression and "root"=tag/subtag/etc, * which are the tags to be inserted before the result * @access private */ function doXmlString2Xml($string, $xpath = null) { $MainXmlString = $this->xmldoc->dumpmem(); $string = preg_replace("/<\\?xml.*\\?>/", "", $string); $MainXmlString = preg_replace("/<" . $this->xmlroot->{$this->tagname} . "\\/>/", "<" . $this->xmlroot->{$this->tagname} . "></" . $this->xmlroot->{$this->tagname} . ">", $MainXmlString); $MainXmlString = preg_replace("/<\\/" . $this->xmlroot->{$this->tagname} . ">/", $string . "</" . $this->xmlroot->{$this->tagname} . ">", $MainXmlString); $this->xmldoc = xmldoc($MainXmlString); $this->xmlroot = $this->xmldoc->root(); }
function _count_var($expr) { $result = ''; // If it is a var is $name/expr $parts = explode("/", $expr, 2); $var_name = substr($parts[0], 1); if (strlen($parts[1]) > 0) { $path = "/" . $parts[1]; } $data = $this->bindings[$var_name]; if (strlen($data) == 0) { return ''; } if (strlen($path) > 0) { $doc = xmldoc($data); $rootname = $this->_get_root_name($doc->document_element()); $path = '/' . $rootname . $path; if (!$doc) { trigger_error("cannot evaluate a xpath expression because {$data} is not xml ", E_USER_WARNING); } $xpath = $doc->xpath_init(); $ctx = $doc->xpath_new_context(); $result_xp = $ctx->xpath_eval($path); $nodes = $result_xp->nodeset; unset($xpath); unset($ctx); unset($result_xp); unset($doc); return count($nodes); } else { return 1; //$result=$data; /* $doc=xmldoc($data); $root=$doc->document_element($doc); if($norm) { $result=_normalize_elements($root); } else { print("El resultado es el dump simple <br />"); if($root->node_type()==XML_ATTRIBUTE_NODE) { print("dumping an attribute <br/>"); $result=$root->value; } else { $result=$root->dump_node($root); } } */ } return $result; }