App.class.php5 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /*
  3. * DON'T REMOVE THE FOLLOWING LICENSE
  4. * INFORMATION!
  5. * ----------------------------------
  6. * Copyright by
  7. * Dennis Ritz
  8. * Author: Dennis Ritz
  9. * dennis.ritz@gmx.net
  10. * 2007-2008
  11. * ----------------------------------
  12. */
  13. class App extends User {
  14. protected $HTML;
  15. protected $JS;
  16. protected $CSS;
  17. protected $Template = null;
  18. private $_componentFile = null;
  19. private $_componentPath = null;
  20. private $_component = null;
  21. private $_componentI18NFile = null;
  22. protected function __construct($p_componentFile = null) {
  23. parent::__construct();
  24. $this->_componentFile = $p_componentFile;
  25. $this->_componentPath = dirname($p_componentFile);
  26. $this->_component = explode(".",basename($p_componentFile))[0];
  27. $this->_componentPath .= "/";
  28. if(file_exists($this->_componentPath.$this->_component.".i18n.xml"))
  29. $this->_componentI18NFile = $this->_componentPath.$this->_component.".i18n.xml";
  30. }
  31. /* OLD FUNCTIONS */
  32. protected function Template(){
  33. if($this->Template == null) {
  34. $this->Template = new Smarty();
  35. $this->Template->left_delimiter = "{[";
  36. $this->Template->right_delimiter = "]}";
  37. $this->Template->compile_dir = $this->_componentPath."compiled";
  38. $this->Template->cache_dir = dirname(__FILE__)."/Smarty/cached";
  39. $this->Template->config_dir = $this->_componentPath."configs";
  40. $this->Template->template_dir = $this->_componentPath."templates";
  41. $this->Template->error_reporting = true;
  42. }
  43. return $this->Template;
  44. }
  45. protected function __COMPONENT() {
  46. ob_start();
  47. if(file_exists($this->_componentPath.$this->_component.".js"))
  48. include($this->_componentPath.$this->_component.".js");
  49. $js = ob_get_contents();
  50. ob_clean();
  51. if(file_exists($this->_componentPath.$this->_component.".css"))
  52. include($this->_componentPath.$this->_component.".css");
  53. $css = ob_get_contents();
  54. ob_end_clean();
  55. $eval = "";//CMgr.setCOMPONENT(".$_component.");".$p_eval;
  56. return array($js,$css,$eval);
  57. }
  58. protected function __MODEL() {
  59. ob_start();
  60. if(file_exists($this->_componentPath.$this->_component.".js"))
  61. include($this->_componentPath.$this->_component.".js");
  62. $js = ob_get_contents();
  63. ob_clean();
  64. if(file_exists($this->_componentPath.$this->_component.".css"))
  65. include($this->_componentPath.$this->_component.".css");
  66. $css = ob_get_contents();
  67. ob_end_clean();
  68. $eval = "CMgr.setMODEL(".$this->_component.");";
  69. return array($js,$css,$eval);
  70. }
  71. protected function __AUTH($p_componentFile = null) {
  72. ob_start();
  73. if(file_exists($this->_componentPath.$this->_component.".js"))
  74. include($this->_componentPath.$this->_component.".js");
  75. $js = ob_get_contents();
  76. ob_clean();
  77. if(file_exists($this->_componentPath.$this->_component.".css"))
  78. include($this->_componentPath.$this->_component.".css");
  79. $css = ob_get_contents();
  80. ob_end_clean();
  81. $eval = "CMgr.setAUTH(".$this->_component.");";
  82. return array($js,$css,$eval);
  83. }
  84. protected function _getI18N($p_node) {
  85. $MISConfig = new MISConfig();
  86. if($this->_componentI18NFile != null) {
  87. $i18nDOM = new DOMDocument('1.0', 'utf-8');
  88. $i18nDOM->load($this->_componentI18NFile);
  89. $i18nXpath = new DOMXpath($i18nDOM);
  90. $i18nNodeList = $i18nXpath->query("/i18n/".$p_node."/".$this->_getLang());
  91. $i18nNodeList2 = $i18nXpath->query("/i18n/".$p_node."");
  92. if($count = $i18nNodeList->length > 0 && $i18nNodeList->item(0)->nodeValue != "") {
  93. return $i18nNodeList->item(0)->nodeValue;
  94. }elseif ($i18nNodeList2->length == 0) {
  95. $MISConfig->setNodeValue($p_node,"",$i18nDOM,$i18nXpath->query("/i18n")->item(0));
  96. $i18nDOM->save($this->_componentI18NFile);
  97. return "[".$this->_component.":".$this->_getLang().":".$p_node."=!]";
  98. } else {
  99. return "[".$this->_component.":".$this->_getLang().":".$p_node."=?]";
  100. }
  101. } else {
  102. return "[".$this->_component.":".$this->_getLang().":".$p_node.": NO LANGUAGE PACK INSTALLED]";
  103. }
  104. }
  105. // USER
  106. final protected function _getLang(){
  107. $p_username = $this->getUsername();
  108. $userDOM = new DOMDocument('1.0', 'utf-8');
  109. $userDOM->load($this->authFile);
  110. $userXpath = new DOMXpath($userDOM);
  111. $UU = $userXpath->query("/auth/users/user[./@username='".utf8_to_latin1($p_username)."']");
  112. if ($UU->count() > 0) {
  113. $userNode = $UU->item(0);
  114. if ($userNode instanceof DOMElement) {
  115. return $userNode->getAttribute("lang");
  116. }
  117. }
  118. $MISConfig = new MISConfig();
  119. $projectDOM = new DOMDocument('1.0', 'utf-8');
  120. $projectDOM->load($MISConfig->getConfigFile());
  121. $projectXpath = new DOMXpath($projectDOM);
  122. return $projectXpath->query("/Configuration/General/Language")->item(0)->nodeValue;
  123. }
  124. final protected function _getView($p_username=null){
  125. if($p_username==null) $p_username = latin1_to_utf8($this->getUsername());
  126. $userDOM = new DOMDocument('1.0', 'utf-8');
  127. $userDOM->load($this->authFile);
  128. $userXpath = new DOMXpath($userDOM);
  129. $UU = $userXpath->query("/auth/users/user[./@username='".utf8_to_latin1($p_username)."']")->item(0);
  130. if ($UU instanceof DOMElement) {
  131. return $UU->getAttribute("view");
  132. }
  133. return null;
  134. }
  135. }
  136. ?>