国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dedeatt.class.php 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <?php
  2. /**
  3. * 属性的数据描述
  4. *
  5. * @version $Id: dedeatt.class.php 1 13:50 2010年7月6日Z tianya $
  6. * @package DedeCMS.Libraries
  7. * @copyright Copyright (c) 2007 - 2020, DesDev, Inc.
  8. * @license http://help.dedecms.com/usersguide/license.html
  9. * @link http://www.dedecms.com
  10. */
  11. // ------------------------------------------------------------------------
  12. /**
  13. * 属性的数据描述
  14. * function c____DedeAtt();
  15. *
  16. * @package DedeAtt
  17. * @subpackage DedeCMS.Libraries
  18. * @link http://www.dedecms.com
  19. */
  20. class DedeAtt
  21. {
  22. var $Count = -1;
  23. var $Items = ""; //属性元素的集合
  24. /**
  25. * //获得某个属性
  26. *
  27. * @access public
  28. * @param string $str 名称
  29. * @return string
  30. */
  31. function GetAtt($str)
  32. {
  33. if($str=="")
  34. {
  35. return "";
  36. }
  37. if(isset($this->Items[$str]))
  38. {
  39. return $this->Items[$str];
  40. }
  41. else
  42. {
  43. return "";
  44. }
  45. }
  46. //同上
  47. function GetAttribute($str)
  48. {
  49. return $this->GetAtt($str);
  50. }
  51. /**
  52. * 判断属性是否存在
  53. *
  54. * @access public
  55. * @param string $str 属性名称
  56. * @return string
  57. */
  58. function IsAttribute($str)
  59. {
  60. return isset($this->Items[$str]) ? TRUE : FALSE;
  61. }
  62. /**
  63. * 获得标记名称
  64. *
  65. * @access public
  66. * @return string
  67. */
  68. function GetTagName()
  69. {
  70. return $this->GetAtt("tagname");
  71. }
  72. /**
  73. * 获得属性个数
  74. *
  75. * @access public
  76. * @return int
  77. */
  78. function GetCount()
  79. {
  80. return $this->Count+1;
  81. }
  82. }//End DedeAtt
  83. /**
  84. * 属性解析器
  85. * function c____DedeAttParse();
  86. *
  87. * @package DedeAtt
  88. * @subpackage DedeCMS.Libraries
  89. * @link http://www.dedecms.com
  90. */
  91. class DedeAttParse
  92. {
  93. var $SourceString = "";
  94. var $SourceMaxSize = 1024;
  95. var $CAtt = ""; //属性的数据描述类
  96. var $CharToLow = TRUE;
  97. /**
  98. * 设置属性解析器源字符串
  99. *
  100. * @access public
  101. * @param string $str 需要解析的字符串
  102. * @return string
  103. */
  104. function SetSource($str="")
  105. {
  106. $this->CAtt = new DedeAtt();
  107. $strLen = 0;
  108. $this->SourceString = trim(preg_replace("/[ \t\r\n]{1,}/"," ",$str));
  109. $strLen = strlen($this->SourceString);
  110. if($strLen>0&&$strLen<=$this->SourceMaxSize)
  111. {
  112. $this->ParseAtt();
  113. }
  114. }
  115. /**
  116. * 解析属性(私有成员,仅给SetSource调用)
  117. *
  118. * @access private
  119. * @return void
  120. */
  121. function ParseAtt()
  122. {
  123. $d = "";
  124. $tmpatt="";
  125. $tmpvalue="";
  126. $startdd=-1;
  127. $ddtag="";
  128. $notAttribute=TRUE;
  129. $strLen = strlen($this->SourceString);
  130. // 这里是获得Tag的名称,可视情况是否需要
  131. // 如果不在这个里解析,则在解析整个Tag时解析
  132. // 属性中不应该存在tagname这个名称
  133. for($i=0;$i<$strLen;$i++)
  134. {
  135. $d = substr($this->SourceString,$i,1);
  136. if($d==' ')
  137. {
  138. $this->CAtt->Count++;
  139. if($this->CharToLow)
  140. {
  141. $this->CAtt->Items["tagname"]=strtolower(trim($tmpvalue));
  142. }
  143. else
  144. {
  145. $this->CAtt->Items["tagname"]=trim($tmpvalue);
  146. }
  147. $tmpvalue = "";
  148. $notAttribute = FALSE;
  149. break;
  150. }
  151. else
  152. {
  153. $tmpvalue .= $d;
  154. }
  155. }
  156. //不存在属性列表的情况
  157. if($notAttribute)
  158. {
  159. $this->CAtt->Count++;
  160. $this->CAtt->Items["tagname"]= ($this->CharToLow ? strtolower(trim($tmpvalue)) : trim($tmpvalue));
  161. }
  162. //如果字符串含有属性值,遍历源字符串,并获得各属性
  163. if(!$notAttribute)
  164. {
  165. for($i;$i<$strLen;$i++)
  166. {
  167. $d = substr($this->SourceString,$i,1);
  168. if($startdd==-1)
  169. {
  170. if($d!="=")
  171. {
  172. $tmpatt .= $d;
  173. }
  174. else
  175. {
  176. if($this->CharToLow)
  177. {
  178. $tmpatt = strtolower(trim($tmpatt));
  179. }
  180. else
  181. {
  182. $tmpatt = trim($tmpatt);
  183. }
  184. $startdd=0;
  185. }
  186. }
  187. else if($startdd==0)
  188. {
  189. switch($d)
  190. {
  191. case ' ':
  192. // continue;
  193. break;
  194. case '\'':
  195. $ddtag='\'';
  196. $startdd=1;
  197. break;
  198. case '"':
  199. $ddtag='"';
  200. $startdd=1;
  201. break;
  202. default:
  203. $tmpvalue.=$d;
  204. $ddtag=' ';
  205. $startdd=1;
  206. break;
  207. }
  208. }
  209. else if($startdd==1)
  210. {
  211. if($d==$ddtag)
  212. {
  213. $this->CAtt->Count++;
  214. $this->CAtt->Items[$tmpatt] = trim($tmpvalue);//strtolower(trim($tmpvalue));
  215. $tmpatt = "";
  216. $tmpvalue = "";
  217. $startdd=-1;
  218. }
  219. else
  220. {
  221. $tmpvalue.=$d;
  222. }
  223. }
  224. }
  225. if($tmpatt!="")
  226. {
  227. $this->CAtt->Count++;
  228. $this->CAtt->Items[$tmpatt]=trim($tmpvalue);//strtolower(trim($tmpvalue));
  229. }//完成属性解析
  230. }//for
  231. }//has Attribute
  232. }//End DedeAttParse