Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. Class Layout {
  3. public $locale;
  4. protected $config;
  5. protected $settings;
  6. function __construct() {
  7. global $locale, $config;
  8. $this->locale = $locale;
  9. $this->config = $config;
  10. $this->settings = $this->config['settings'];
  11. }
  12. public function getPage($file) {
  13. $cache = $this->settings['cache-layout'];
  14. $file_path = LAYOUTS_DIR.$file.'.php';
  15. if (file_exists($file_path)) {
  16. if ($cache) {
  17. return $this->cacheFile($file, $this->requireFile($file_path));
  18. } else {
  19. return $this->requireFile($file_path);
  20. }
  21. } else {
  22. return 'Layout file not found in '.LAYOUTS_DIR;
  23. }
  24. }
  25. public function setFileTimestamp() {
  26. $ts = '';
  27. if ($this->settings['debug']) {
  28. $ts = '?t='.time();
  29. }
  30. return $ts;
  31. }
  32. public function getPublicUri() {
  33. $protocol = $this->settings['http-protocol'];
  34. $domain = $_SERVER['SERVER_NAME'];
  35. return $protocol.$domain.'/';
  36. }
  37. private function requireFile($file_path) {
  38. $ob_string = $this->config['settings']['gzip-content'] ? 'ob_gzhandler' : '';
  39. ob_start($ob_string);
  40. require($file_path);
  41. return ob_get_clean();
  42. }
  43. private function cacheFile($file_name, $file_data=null) {
  44. $cache_dir = CACHE_DIR.'Layouts/';
  45. if (is_writable($cache_dir)) {
  46. $file_path = $cache_dir.$file_name.'-cache.html';
  47. if (!file_exists($file_path)) {
  48. file_put_contents($file_path, $file_data);
  49. }
  50. return file_get_contents($file_path);
  51. } else {
  52. return 'Layout cache directory is not writable.';
  53. }
  54. }
  55. }