HTTP_WebDAV_Client
[ class tree: HTTP_WebDAV_Client ] [ index: HTTP_WebDAV_Client ] [ all elements ]

Source for file _parse_propfind_response.php

Documentation is available at _parse_propfind_response.php

  1. <?php
  2.  
  3. // helper class for parsing PROPFIND response bodies
  4. class HTTP_WebDAV_Client_parse_propfind_response
  5. {
  6.     // get requested properties as array containing name/namespace pairs
  7.     function HTTP_WebDAV_Client_parse_propfind_response($response)
  8.     {
  9.         $this->urls = array();
  10.  
  11.         $this->_depth = 0;
  12.  
  13.         $xml_parser xml_parser_create_ns("UTF-8"" ");
  14.         xml_set_element_handler($xml_parser,
  15.                                 array(&$this"_startElement"),
  16.                                 array(&$this"_endElement"));
  17.         xml_set_character_data_handler($xml_parser,
  18.                                        array(&$this"_data"));
  19.         xml_parser_set_option($xml_parserXML_OPTION_CASE_FOLDING,
  20.                               false);
  21.         $this->success xml_parse($xml_parser$responsetrue);
  22.         xml_parser_free($xml_parser);
  23.  
  24.         unset($this->_depth);
  25.     }
  26.  
  27.  
  28.     function _startElement($parser$name$attrs)
  29.     {
  30.         if (strstr($name" ")) {
  31.             list($ns$tagexplode(" "$name);
  32.             if ($ns == "")
  33.                 $this->success = false;
  34.         else {
  35.             $ns  "";
  36.             $tag $name;
  37.         }
  38.  
  39.         switch ($this->_depth{
  40.         case '2':
  41.             switch ($tag{
  42.             case 'propstat':
  43.                 // TODO check is_executable, lockinfo ...
  44.                 $this->_tmpprop = array("mode" => 0100666 /* all may read and write (for now) */);
  45.                 break;
  46.             }
  47.         }
  48.  
  49.         $this->_depth++;
  50.     }
  51.  
  52.     function _endElement($parser$name)
  53.     {
  54.         if (strstr($name" ")) {
  55.             list($ns$tagexplode(" "$name);
  56.             if ($ns == "")
  57.                 $this->success = false;
  58.         else {
  59.             $ns  "";
  60.             $tag $name;
  61.         }
  62.  
  63.         $this->_depth--;
  64.  
  65.         switch ($this->_depth{
  66.         case '1':
  67.             switch ($tag{
  68.             case 'response':
  69.                 $this->urls[$this->_tmphref$this->_tmpvals;
  70.                 unset($this->_tmphref);
  71.                 unset($this->_tmpvals);
  72.                 break;
  73.             }
  74.             break;
  75.         case '2':
  76.             switch ($tag{
  77.             case 'href':
  78.                 $this->_tmphref $this->_tmpdata;
  79.                 break;
  80.             }
  81.         case 'propstat':
  82.             if (isset($this->_tmpstat&& strstr($this->_tmpstat" 200 ")) {
  83.                 $this->_tmpvals $this->_tmpprop;
  84.             }
  85.             unset($this->_tmpstat);
  86.             unset($this->_tmpprop);
  87.             break;
  88.         case '3':
  89.             switch ($tag{
  90.             case 'status':
  91.                 $this->_tmpstat $this->_tmpdata;
  92.                 break;
  93.             }
  94.         case '4':
  95.             switch ($tag{
  96.             case 'getlastmodified':
  97.                 $this->_tmpprop['atime'strtotime($this->_tmpdata);
  98.                 $this->_tmpprop['mtime'strtotime($this->_tmpdata);
  99.                 break;
  100.             case 'creationdate':
  101.                 $t preg_split("/[^[:digit:]]/"$this->_tmpdata);
  102.                 $this->_tmpprop['ctime'mktime($t[3]$t[4]$t[5]$t[1]$t[2]$t[0]);
  103.                 unset($t);
  104.                 break;
  105.             case 'getcontentlength':
  106.                 $this->_tmpprop['size'$this->_tmpdata;
  107.                 break;
  108.             }
  109.         case '5':
  110.             switch ($tag{
  111.             case 'collection':
  112.                 $this->_tmpprop['mode'&= ~0100000; // clear S_IFREG
  113.                 $this->_tmpprop['mode'|= 040000; // set S_IFDIR
  114.                 break;
  115.             }
  116.         }
  117.  
  118.         unset($this->_tmpdata);
  119.     }
  120.  
  121.     function _data($parser$data)
  122.     {
  123.         $this->_tmpdata $data;
  124.     }
  125.  
  126.     function stat($href = false)
  127.     {
  128.         if ($href{
  129.             // TODO
  130.         else {
  131.             reset($this->urls);
  132.             return current($this->urls);
  133.         }
  134.     }
  135. }
  136.  
  137.  
  138. /*
  139.  * Local variables:
  140.  * tab-width: 4
  141.  * c-basic-offset: 4
  142.  * indent-tabs-mode:nil
  143.  * End:
  144.  */

Documentation generated on Mon, 11 Mar 2019 15:46:45 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.