PageRenderTime 38ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/h-source/Library/Theme.php

https://gitlab.com/7slayer/h-node
PHP | 122 lines | 79 code | 22 blank | 21 comment | 17 complexity | f86416b81de638d34cf9895603bfb1ba MD5 | raw file
  1. <?php
  2. // EasyGiant is a PHP framework for creating and managing dynamic content
  3. //
  4. // Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com)
  5. // See COPYRIGHT.txt and LICENSE.txt.
  6. //
  7. // This file is part of EasyGiant
  8. //
  9. // EasyGiant is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU General Public License as published by
  11. // the Free Software Foundation, either version 3 of the License, or
  12. // (at your option) any later version.
  13. //
  14. // EasyGiant is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. // GNU General Public License for more details.
  18. //
  19. // You should have received a copy of the GNU General Public License
  20. // along with EasyGiant. If not, see <http://www.gnu.org/licenses/>.
  21. if (!defined('EG')) die('Direct access not allowed!');
  22. class Theme {
  23. protected $_data = array();
  24. protected $_viewFiles = array(); //view files to require
  25. protected $_lastView = null;
  26. public $baseUrl = null; //the base url of the website: http://domainname
  27. public $baseUrlSrc = null; //the base url of the website (http://domainname) in the case MOD_REWRITE_MODULE has been set to false
  28. public $viewArgs = array();
  29. public $viewStatus = '';
  30. public $controller = 'controller';
  31. public $application = null;
  32. public $action = '';
  33. public $currPage; //the URL of the current page
  34. function __construct($application, $controller) {
  35. $this->controller = $controller;
  36. $this->application = $application;
  37. $langUrl = isset(Params::$lang) ? "/".Params::$lang : null;
  38. $protocol = Params::$useHttps ? "https" : "http";
  39. $this->baseUrl = MOD_REWRITE_MODULE === true ? "$protocol://" . DOMAIN_NAME . $langUrl : "$protocol://" . DOMAIN_NAME . '/index.php' . $langUrl;
  40. $this->baseUrlSrc = "$protocol://" . DOMAIN_NAME;
  41. }
  42. public function set($values)
  43. {
  44. $this->_data = $values;
  45. }
  46. public function append($values)
  47. {
  48. $this->_data = array_merge($this->_data,$values);
  49. }
  50. //clean the $this->viewFiles array
  51. public function clean() {
  52. $this->_viewFiles = array();
  53. $this->_lastView = null;
  54. }
  55. public function load($fileName,$option = 'none') {
  56. if ((strcmp($option,'last') !== 0) and (strcmp($option,'none') !== 0)) {
  57. throw new Exception('"'.$option. '" argument not allowed in '.__METHOD__.' method');
  58. }
  59. if ($option === 'last') {
  60. $this->_lastView = $fileName;
  61. } else {
  62. $this->_viewFiles[] = $fileName;
  63. }
  64. }
  65. public function render() {
  66. extract($this->_data);
  67. //find the View subfolder where to look for view files
  68. $subfolder = isset(Params::$viewSubfolder) ? Params::$viewSubfolder . DS : null;
  69. foreach ($this->_viewFiles as $file) {
  70. if (isset($this->application) and file_exists(ROOT . DS . APPLICATION_PATH . DS . "Apps" . DS . ucfirst($this->application). DS . 'Views' . DS .$subfolder. ucwords($this->controller) . DS . $file . '.php'))
  71. {
  72. include (ROOT . DS . APPLICATION_PATH . DS . "Apps" . DS . ucfirst($this->application). DS . 'Views' . DS . $subfolder. ucwords($this->controller) . DS . $file . '.php');
  73. }
  74. else if (isset($this->application) and file_exists(ROOT . DS . APPLICATION_PATH . DS . "Apps" . DS . ucfirst($this->application). DS . 'Views' . DS . $subfolder. $file . '.php'))
  75. {
  76. include (ROOT . DS . APPLICATION_PATH . DS . "Apps" . DS . ucfirst($this->application). DS . 'Views' . DS .$subfolder. $file . '.php');
  77. }
  78. else if (file_exists(ROOT . DS . APPLICATION_PATH . DS . 'Views' . DS .$subfolder. ucwords($this->controller) . DS . $file . '.php')) {
  79. include (ROOT . DS . APPLICATION_PATH . DS . 'Views' . DS .$subfolder. ucwords($this->controller) . DS . $file . '.php');
  80. } else {
  81. include (ROOT . DS . APPLICATION_PATH . DS . 'Views' . DS .$subfolder. $file . '.php');
  82. }
  83. }
  84. if (isset($this->_lastView)) {
  85. if (isset($this->application) and file_exists(ROOT . DS . APPLICATION_PATH . DS . "Apps" . DS . ucfirst($this->application). DS . 'Views' . DS .$subfolder. ucwords($this->controller) . DS . $this->_lastView . '.php'))
  86. {
  87. include (ROOT . DS . APPLICATION_PATH . DS . "Apps" . DS . ucfirst($this->application). DS . 'Views' . DS .$subfolder. ucwords($this->controller) . DS . $this->_lastView . '.php');
  88. }
  89. else if (isset($this->application) and file_exists(ROOT . DS . APPLICATION_PATH . DS . "Apps" . DS . ucfirst($this->application). DS . 'Views' . DS . $subfolder . $this->_lastView . '.php'))
  90. {
  91. include (ROOT . DS . APPLICATION_PATH . DS . "Apps" . DS . ucfirst($this->application). DS . 'Views' . DS .$subfolder . $this->_lastView . '.php');
  92. }
  93. else if (file_exists(ROOT . DS . APPLICATION_PATH . DS . 'Views' . DS .$subfolder. ucwords($this->controller) . DS . $this->_lastView . '.php')) {
  94. include (ROOT . DS . APPLICATION_PATH . DS . 'Views' . DS .$subfolder. ucwords($this->controller) . DS . $this->_lastView . '.php');
  95. } else {
  96. include (ROOT . DS . APPLICATION_PATH . DS . 'Views' . DS .$subfolder. $this->_lastView . '.php');
  97. }
  98. }
  99. }
  100. }