|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 /* vim: set expandtab tabstop=4 shiftwidth=4: */ 00003 // +----------------------------------------------------------------------+ 00004 // | PHP Version 4 | 00005 // +----------------------------------------------------------------------+ 00006 // | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group | 00007 // +----------------------------------------------------------------------+ 00008 // | This source file is subject to version 2.0 of the PHP license, | 00009 // | that is bundled with this package in the file LICENSE, and is | 00010 // | available at through the world-wide-web at | 00011 // | http://www.php.net/license/2_02.txt. | 00012 // | If you did not receive a copy of the PHP license and are unable to | 00013 // | obtain it through the world-wide-web, please send a note to | 00014 // | license@php.net so we can mail you a copy immediately. | 00015 // +----------------------------------------------------------------------+ 00016 // | Author: Adam Daniel <adaniel1@eesus.jnj.com> | 00017 // +----------------------------------------------------------------------+ 00018 // 00019 // $Id: Common.php,v 1.2 2010/12/14 17:36:06 moodlerobot Exp $ 00020 00039 class HTML_Common { 00040 00046 var $_attributes = array(); 00047 00053 var $_tabOffset = 0; 00054 00061 var $_tab = "\11"; 00062 00069 var $_lineEnd = "\12"; 00070 00077 var $_comment = ''; 00078 00086 function HTML_Common($attributes = null, $tabOffset = 0) 00087 { 00088 $this->setAttributes($attributes); 00089 $this->setTabOffset($tabOffset); 00090 } // end constructor 00091 00097 function apiVersion() 00098 { 00099 return 1.7; 00100 } // end func apiVersion 00101 00110 function _getLineEnd() 00111 { 00112 return $this->_lineEnd; 00113 } // end func getLineEnd 00114 00122 function _getTab() 00123 { 00124 return $this->_tab; 00125 } // end func _getTab 00126 00133 function _getTabs() 00134 { 00135 return str_repeat($this->_getTab(), $this->_tabOffset); 00136 } // end func _getTabs 00137 00144 function _getAttrString($attributes) 00145 { 00146 $strAttr = ''; 00147 00148 if (is_array($attributes)) { 00149 foreach ($attributes as $key => $value) { 00150 $strAttr .= ' ' . $key . '="' . htmlspecialchars($value) . '"'; 00151 } 00152 } 00153 return $strAttr; 00154 } // end func _getAttrString 00155 00161 function _parseAttributes($attributes) 00162 { 00163 if (is_array($attributes)) { 00164 $ret = array(); 00165 foreach ($attributes as $key => $value) { 00166 if (is_int($key)) { 00167 $key = $value = strtolower($value); 00168 } else { 00169 $key = strtolower($key); 00170 } 00171 $ret[$key] = $value; 00172 } 00173 return $ret; 00174 00175 } elseif (is_string($attributes)) { 00176 $preg = "/(([A-Za-z_:]|[^\\x00-\\x7F])([A-Za-z0-9_:.-]|[^\\x00-\\x7F])*)" . 00177 "([ \\n\\t\\r]+)?(=([ \\n\\t\\r]+)?(\"[^\"]*\"|'[^']*'|[^ \\n\\t\\r]*))?/"; 00178 if (preg_match_all($preg, $attributes, $regs)) { 00179 for ($counter=0; $counter<count($regs[1]); $counter++) { 00180 $name = $regs[1][$counter]; 00181 $check = $regs[0][$counter]; 00182 $value = $regs[7][$counter]; 00183 if (trim($name) == trim($check)) { 00184 $arrAttr[strtolower(trim($name))] = strtolower(trim($name)); 00185 } else { 00186 if (substr($value, 0, 1) == "\"" || substr($value, 0, 1) == "'") { 00187 $value = substr($value, 1, -1); 00188 } 00189 $arrAttr[strtolower(trim($name))] = trim($value); 00190 } 00191 } 00192 return $arrAttr; 00193 } 00194 } 00195 } // end func _parseAttributes 00196 00207 function _getAttrKey($attr, $attributes) 00208 { 00209 if (isset($attributes[strtolower($attr)])) { 00210 return true; 00211 } else { 00212 return null; 00213 } 00214 } //end func _getAttrKey 00215 00222 function _updateAttrArray(&$attr1, $attr2) 00223 { 00224 if (!is_array($attr2)) { 00225 return false; 00226 } 00227 foreach ($attr2 as $key => $value) { 00228 $attr1[$key] = $value; 00229 } 00230 } // end func _updateAtrrArray 00231 00242 function _removeAttr($attr, &$attributes) 00243 { 00244 $attr = strtolower($attr); 00245 if (isset($attributes[$attr])) { 00246 unset($attributes[$attr]); 00247 } 00248 } //end func _removeAttr 00249 00259 function getAttribute($attr) 00260 { 00261 $attr = strtolower($attr); 00262 if (isset($this->_attributes[$attr])) { 00263 return $this->_attributes[$attr]; 00264 } 00265 return null; 00266 } //end func getAttribute 00267 00273 function setAttributes($attributes) 00274 { 00275 $this->_attributes = $this->_parseAttributes($attributes); 00276 } // end func setAttributes 00277 00286 function getAttributes($asString = false) 00287 { 00288 if ($asString) { 00289 return $this->_getAttrString($this->_attributes); 00290 } else { 00291 return $this->_attributes; 00292 } 00293 } //end func getAttributes 00294 00300 function updateAttributes($attributes) 00301 { 00302 $this->_updateAttrArray($this->_attributes, $this->_parseAttributes($attributes)); 00303 } // end func updateAttributes 00304 00314 function removeAttribute($attr) 00315 { 00316 $this->_removeAttr($attr, $this->_attributes); 00317 } //end func removeAttribute 00318 00327 function setLineEnd($style) 00328 { 00329 switch ($style) { 00330 case 'win': 00331 $this->_lineEnd = "\15\12"; 00332 break; 00333 case 'unix': 00334 $this->_lineEnd = "\12"; 00335 break; 00336 case 'mac': 00337 $this->_lineEnd = "\15"; 00338 break; 00339 default: 00340 $this->_lineEnd = $style; 00341 } 00342 } // end func setLineEnd 00343 00350 function setTabOffset($offset) 00351 { 00352 $this->_tabOffset = $offset; 00353 } // end func setTabOffset 00354 00362 function getTabOffset() 00363 { 00364 return $this->_tabOffset; 00365 } //end func getTabOffset 00366 00375 function setTab($string) 00376 { 00377 $this->_tab = $string; 00378 } // end func setTab 00379 00388 function setComment($comment) 00389 { 00390 $this->_comment = $comment; 00391 } // end func setHtmlComment 00392 00400 function getComment() 00401 { 00402 return $this->_comment; 00403 } //end func getComment 00404 00412 function toHtml() 00413 { 00414 return ''; 00415 } // end func toHtml 00416 00422 function display() 00423 { 00424 print $this->toHtml(); 00425 } // end func display 00426 00427 } // end class HTML_Common 00428 ?>