下一篇 ?? 上一篇提示:鼠标放在图片上用鼠标中键即可控制图片大小

文章标题:PHP静态类2

作者: ???时间:2008-04-07??? 翻译网站:??? 点击:44318 ???本文共1篇文章
发表评论 | 查看评论 | 加入收藏 | Email给朋友 | 打印本文 | 字体:[ ]

PHP代码
  1. class?Shtml? ??
  2. ??{? ??
  3. ????var?$Templet;? ??
  4. ????var?$DataSource;? ??
  5. ????var?$Dir;? ??
  6. ? ??
  7. ????var?$fileName;? ??
  8. ????var?$mod;? ??
  9. ????var?$handle;? ??
  10. ? ??
  11. ????function?Shtml($fileName="")? ??
  12. ????{? ??
  13. ??????$this->fileName=$fileName;? ??
  14. ??????$this->mod="wb";? ??
  15. ??????$this->handle=false;? ??
  16. ? ??
  17. ??????$this->Templet????=?"";? ??
  18. ??????$this->DataSource??=?array();? ??
  19. ??????$this->Dir??????=?"";? ??
  20. ????}? ??
  21. ????? ??
  22. ????///??<描述>? ??
  23. ????///??绑定数据源,参数为一数组。? ??
  24. ????///??? ??
  25. ????function?BindData($arr)? ??
  26. ????{? ??
  27. ??????$this->DataSource?=?$arr;? ??
  28. ????}? ??
  29. ????? ??
  30. ????///??<描述>? ??
  31. ????///??设置文件存放路径。? ??
  32. ????///??? ??
  33. ????function?SetDir($dir)? ??
  34. ????{? ??
  35. ??????$this->Dir?=?$dir;? ??
  36. ????}? ??
  37. ????function?SetFileName($fileName)? ??
  38. ????{? ??
  39. ??????return?$this->fileName=$fileName;? ??
  40. ????}? ??
  41. ? ??
  42. ????function?GetMod()? ??
  43. ????{? ??
  44. ??????return?$this->mod;? ??
  45. ????}? ??
  46. ????function?SetMod($mod)? ??
  47. ????{? ??
  48. ??????return?$this->mod=$mod;? ??
  49. ????}? ??
  50. ????function?Open()? ??
  51. ????{? ??
  52. ??????if(substr($this->fileName,0,1)=="/")? ??
  53. ????????$this->fileName?=?$_SERVER['DOCUMENT_ROOT']?.?$this->fileName;? ??
  54. ??????if($this->handle=fopen($this->fileName,?$this->mod))? ??
  55. ????????return?$this->handle;? ??
  56. ??????else? ??
  57. ????????return?false;? ??
  58. ????}? ??
  59. ????function?Close()? ??
  60. ????{? ??
  61. ??????return?fclose($this->handle);? ??
  62. ????}? ??
  63. ????function?Write($content)? ??
  64. ????{? ??
  65. ??????return?fwrite($this->handle,$content);? ??
  66. ????}? ??
  67. ????function?MkDir($pathname)? ??
  68. ????{? ??
  69. ??????$currentPath="";? ??
  70. ??????str_replace("\","/",$pathname);? ?
  71. ??????$pathArr?=?split("/",$pathname);? ?
  72. ??????if($pathArr[0]?==?"")????//使用绝对路径? ?
  73. ??????{? ?
  74. ????????$currentPath?=?$_SERVER['DOCUMENT_ROOT'];? ?
  75. ??????}? ?
  76. ??????else? ?
  77. ??????{? ?
  78. ????????$currentPath?=?$_SERVER['DOCUMENT_ROOT']?.?dirname($_SERVER['PHP_SELF']);? ?
  79. ??????}? ?
  80. ??????for($i=0;?$i?
  81. ??????{? ?
  82. ????????if($pathArr[$i]=="")? ?
  83. ??????????continue;? ?
  84. ????????else? ?
  85. ??????????if(is_dir($currentPath?.?"/"?.?$pathArr[$i]))? ?
  86. ????????????$currentPath?=?$currentPath?.?"/"?.?$pathArr[$i];? ?
  87. ??????????else? ?
  88. ????????????mkdir($currentPath?=?$currentPath?.?"/"?.?$pathArr[$i]);? ?
  89. ??????}? ?
  90. ????}? ?
  91. ? ?
  92. ????///??<描述>? ?
  93. ????///??生成静态文件。? ?
  94. ????///??? ?
  95. ????function?Create()? ?
  96. ????{? ?
  97. ??????$tmp?=?$this->Templet;? ?
  98. ??????foreach($this->DataSource?as?$key=>$value)? ?
  99. ??????{? ?
  100. ????????$tmp?=?str_replace("<>"?.?$key?.?">",?$value,?$tmp);? ?
  101. ??????}? ?
  102. ??????$this->MkDir(dirname($this->fileName));? ?
  103. ??????$this->Open();? ?
  104. ??????$this->Write($tmp);? ?
  105. ??????$this->Close();? ?
  106. ????}? ?
  107. ??}? ?
  108. ? ?
  109. ??function?CreateShtml()? ?
  110. ??{? ?
  111. ????ob_start("callback_CteateShtml");? ?
  112. ??}? ?
  113. ??function?callback_CteateShtml($buffer)? ?
  114. ??{? ?
  115. ????$page?=?intval(@$_REQUEST["page"]);? ?
  116. ????$shtml?=?new?Shtml();? ?
  117. ????$shtml->SetFileName($_SERVER['DOCUMENT_ROOT']?.?dirname($_SERVER['PHP_SELF'])?.?"/"?.?basename($_SERVER['PHP_SELF'],".php")?.?($page==0???""?:?"_"?.?strval($page))?.?".htm");? ??
  118. ????$shtml->Templet?=?$buffer;? ??
  119. ????$shtml->Create();? ??
  120. ????return?$buffer;? ??
  121. ??} ??
  122. ?> ??
责任编辑:semirock
发表评论
密码: (游客不需要密码)
记住我【Alt+S 或 Ctrl+Enter 快速提交】