Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * replace 2 sections
  5. */
  6.  
  7. namespace news2\views;
  8.  
  9. use framework2\lib\html_view\CreateHtml;
  10.  
  11. class Create2sec1 extends CreateHtml
  12. {
  13. //replacement mark
  14. const REPLACE1 = "#c1#";
  15. const REPLACE2 = "#c2#";
  16.  
  17. /**
  18. * display html page
  19. *
  20. * @param array $contents
  21. * @return void
  22. */
  23. public function view (array $contents=null) : void
  24. {
  25. $tempfile_path = $this->retTempFilePath();
  26.  
  27. //create filename for rendering use template file path
  28. $cache = $this->createCacheFilename($tempfile_path);
  29.  
  30. if (!is_file($cache) ) { # that is new create file
  31. $temp_html = file_get_contents($tempfile_path);
  32. if (empty($contents)) { # for no argument that is case of third demension data processing
  33. $contents = $this->getCreatehtmls();
  34. }
  35.  
  36. //replace processing use template file
  37. $search = array( parent::TITLE,
  38. parent::PAGE,
  39. self::REPLACE1,
  40. self::REPLACE2
  41. );
  42. $replace = array($this->title, $this->id_name, $contents[0], $contents[1]);
  43. $new = str_replace($search, $replace, $temp_html);
  44.  
  45. file_put_contents($cache, $new,LOCK_EX);
  46. }
  47.  
  48. //else if alredy created cache file then excute cached file
  49. require $cache;
  50.  
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement