html.init.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. if (!defined('IS_INITPHP')) exit('Access Denied!');
  3. /*********************************************************************************
  4. * InitPHP 3.8.2 国产PHP开发框架 扩展类库-静态页面生成
  5. *-------------------------------------------------------------------------------
  6. * 版权所有: CopyRight By initphp.com
  7. * 您可以自由使用该源码,但是在使用过程中,请保留作者信息。尊重他人劳动成果就是尊重自己
  8. *-------------------------------------------------------------------------------
  9. * Author:zhuli Dtime:2014-11-25
  10. ***********************************************************************************/
  11. class htmlInit {
  12. private $html_path = 'data/html/'; //静态页面目录
  13. private $key; //生成的HTML静态页面对应的KEY值
  14. private $ismd5 = false; //生成的文件名是否MD5加密
  15. /**
  16. * 静态页面-开启ob_start(),打开缓冲区
  17. * @return
  18. */
  19. public function start() {
  20. return ob_start();
  21. }
  22. /**
  23. * 静态页面-生成静态页面,$key值是生成页面的唯一标识符
  24. * @param string $key 静态页面标识符,可以用id代替
  25. * @return
  26. */
  27. public function end($key) {
  28. $this->key = $key;
  29. $this->html(); //生成HTML文件
  30. return ob_end_clean(); //清空缓冲
  31. }
  32. /**
  33. * 静态页面-获取静态页面
  34. * @param string $key 静态页面标识符,可以用id代替
  35. * @return
  36. */
  37. public function get($key) {
  38. $filename = $this->get_filename($key);
  39. if (!$filename || !file_exists($filename)) return false;
  40. include($filename);
  41. return true;
  42. }
  43. /**
  44. * 静态页面-生成静态页面
  45. * @return
  46. */
  47. private function html() {
  48. $filename = $this->get_filename($this->key);
  49. if (!$filename) return false;
  50. return @file_put_contents($filename, ob_get_contents());
  51. }
  52. /**
  53. * 静态页面-静态页面文件
  54. * @return
  55. */
  56. private function get_filename($key) {
  57. $filename = ($this->ismd5 == true) ? md5($key) : $key;
  58. if (!is_dir($this->html_path)) return false;
  59. return $this->html_path . '/' . $filename . '.htm';
  60. }
  61. }