[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php // $Id$ 2 /* 3 +----------------------------------------------------------------------+ 4 | Copyright (c) 2002-2007 Christian Stocker, Hartmut Holzgraefe | 5 | All rights reserved | 6 | | 7 | Redistribution and use in source and binary forms, with or without | 8 | modification, are permitted provided that the following conditions | 9 | are met: | 10 | | 11 | 1. Redistributions of source code must retain the above copyright | 12 | notice, this list of conditions and the following disclaimer. | 13 | 2. Redistributions in binary form must reproduce the above copyright | 14 | notice, this list of conditions and the following disclaimer in | 15 | the documentation and/or other materials provided with the | 16 | distribution. | 17 | 3. The names of the authors may not be used to endorse or promote | 18 | products derived from this software without specific prior | 19 | written permission. | 20 | | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 22 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 23 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | 24 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | 25 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | 26 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | 27 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 30 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | 31 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 32 | POSSIBILITY OF SUCH DAMAGE. | 33 +----------------------------------------------------------------------+ 34 */ 35 36 37 /** 38 * helper class for parsing PROPPATCH request bodies 39 * 40 * @package HTTP_WebDAV_Server 41 * @author Hartmut Holzgraefe <[email protected]> 42 * @version @package-version@ 43 */ 44 class _parse_proppatch 45 { 46 /** 47 * 48 * 49 * @var 50 * @access 51 */ 52 var $success; 53 54 /** 55 * 56 * 57 * @var 58 * @access 59 */ 60 var $props; 61 62 /** 63 * 64 * 65 * @var 66 * @access 67 */ 68 var $depth; 69 70 /** 71 * 72 * 73 * @var 74 * @access 75 */ 76 var $mode; 77 78 /** 79 * 80 * 81 * @var 82 * @access 83 */ 84 var $current; 85 86 /** 87 * constructor 88 * 89 * @param string path of input stream 90 * @access public 91 */ 92 function _parse_proppatch($path) 93 { 94 $this->success = true; 95 96 $this->depth = 0; 97 $this->props = array(); 98 $had_input = false; 99 100 $f_in = fopen($path, "r"); 101 if (!$f_in) { 102 $this->success = false; 103 return; 104 } 105 106 $xml_parser = xml_parser_create_ns("UTF-8", " "); 107 108 xml_set_element_handler($xml_parser, 109 array(&$this, "_startElement"), 110 array(&$this, "_endElement")); 111 112 xml_set_character_data_handler($xml_parser, 113 array(&$this, "_data")); 114 115 xml_parser_set_option($xml_parser, 116 XML_OPTION_CASE_FOLDING, false); 117 118 while($this->success && !feof($f_in)) { 119 $line = fgets($f_in); 120 if (is_string($line)) { 121 $had_input = true; 122 $this->success &= xml_parse($xml_parser, $line, false); 123 } 124 } 125 126 if($had_input) { 127 $this->success &= xml_parse($xml_parser, "", true); 128 } 129 130 xml_parser_free($xml_parser); 131 132 fclose($f_in); 133 } 134 135 /** 136 * tag start handler 137 * 138 * @param resource parser 139 * @param string tag name 140 * @param array tag attributes 141 * @return void 142 * @access private 143 */ 144 function _startElement($parser, $name, $attrs) 145 { 146 if (strstr($name, " ")) { 147 list($ns, $tag) = explode(" ", $name); 148 if ($ns == "") 149 $this->success = false; 150 } else { 151 $ns = ""; 152 $tag = $name; 153 } 154 155 if ($this->depth == 1) { 156 $this->mode = $tag; 157 } 158 159 if ($this->depth == 3) { 160 $prop = array("name" => $tag); 161 $this->current = array("name" => $tag, "ns" => $ns, "status"=> 200); 162 if ($this->mode == "set") { 163 $this->current["val"] = ""; // default set val 164 } 165 } 166 167 if ($this->depth >= 4) { 168 $this->current["val"] .= "<$tag"; 169 if (isset($attr)) { 170 foreach ($attr as $key => $val) { 171 $this->current["val"] .= ' '.$key.'="'.str_replace('"','"', $val).'"'; 172 } 173 } 174 $this->current["val"] .= ">"; 175 } 176 177 178 179 $this->depth++; 180 } 181 182 /** 183 * tag end handler 184 * 185 * @param resource parser 186 * @param string tag name 187 * @return void 188 * @access private 189 */ 190 function _endElement($parser, $name) 191 { 192 if (strstr($name, " ")) { 193 list($ns, $tag) = explode(" ", $name); 194 if ($ns == "") 195 $this->success = false; 196 } else { 197 $ns = ""; 198 $tag = $name; 199 } 200 201 $this->depth--; 202 203 if ($this->depth >= 4) { 204 $this->current["val"] .= "</$tag>"; 205 } 206 207 if ($this->depth == 3) { 208 if (isset($this->current)) { 209 $this->props[] = $this->current; 210 unset($this->current); 211 } 212 } 213 } 214 215 /** 216 * input data handler 217 * 218 * @param resource parser 219 * @param string data 220 * @return void 221 * @access private 222 */ 223 function _data($parser, $data) 224 { 225 if (isset($this->current)) { 226 $this->current["val"] .= $data; 227 } 228 } 229 } 230 231 /* 232 * Local variables: 233 * tab-width: 4 234 * c-basic-offset: 4 235 * indent-tabs-mode:nil 236 * End: 237 */
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |