html.init.php 2.1 KB

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