App.class.php5 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. private $_componentFile = null;
  18. private $_componentPath = null;
  19. private $_component = null;
  20. private $_componentI18NFile = null;
  21. protected function __construct($p_componentFile = null) {
  22. parent::__construct();
  23. $this->_componentFile = $p_componentFile;
  24. $this->_componentPath = dirname($p_componentFile);
  25. $this->_component = array_shift(explode(".",basename($p_componentFile)));
  26. $this->_componentPath .= "/";
  27. if(file_exists($this->_componentPath.$this->_component.".i18n.xml"))
  28. $this->componentI18NFile = $this->_componentPath.$this->_component.".i18n.xml";
  29. }
  30. /* OLD FUNCTIONS */
  31. protected function Template(){
  32. if(!isset($this->Template)) {
  33. $this->Template = new Smarty();
  34. $this->Template->left_delimiter = "{[";
  35. $this->Template->right_delimiter = "]}";
  36. $this->Template->compile_dir = $this->_componentPath."compiled";
  37. $this->Template->cache_dir = dirname(__FILE__)."/Smarty/cached";
  38. $this->Template->config_dir = $this->_componentPath."configs";
  39. $this->Template->template_dir = $this->_componentPath."templates";
  40. $this->Template->error_reporting = true;
  41. }
  42. return $this->Template;
  43. }
  44. protected function __COMPONENT() {
  45. ob_start();
  46. if(file_exists($this->_componentPath.$this->_component.".js"))
  47. include($this->_componentPath.$this->_component.".js");
  48. $js = ob_get_contents();
  49. ob_clean();
  50. if(file_exists($this->_componentPath.$this->_component.".css"))
  51. include($this->_componentPath.$this->_component.".css");
  52. $css = ob_get_contents();
  53. ob_end_clean();
  54. $eval = "";//CMgr.setCOMPONENT(".$_component.");".$p_eval;
  55. return array($js,$css,$eval);
  56. }
  57. protected function __MODEL() {
  58. ob_start();
  59. if(file_exists($this->_componentPath.$this->_component.".js"))
  60. include($this->_componentPath.$this->_component.".js");
  61. $js = ob_get_contents();
  62. ob_clean();
  63. if(file_exists($this->_componentPath.$this->_component.".css"))
  64. include($this->_componentPath.$this->_component.".css");
  65. $css = ob_get_contents();
  66. ob_end_clean();
  67. $eval = "CMgr.setMODEL(".$this->_component.");";
  68. return array($js,$css,$eval);
  69. }
  70. protected function __AUTH($p_componentFile = null) {
  71. ob_start();
  72. if(file_exists($this->_componentPath.$this->_component.".js"))
  73. include($this->_componentPath.$this->_component.".js");
  74. $js = ob_get_contents();
  75. ob_clean();
  76. if(file_exists($this->_componentPath.$this->_component.".css"))
  77. include($this->_componentPath.$this->_component.".css");
  78. $css = ob_get_contents();
  79. ob_end_clean();
  80. $eval = "CMgr.setAUTH(".$this->_component.");";
  81. return array($js,$css,$eval);
  82. }
  83. protected function _getI18N($p_node) {
  84. $MISConfig = new MISConfig();
  85. if($this->componentI18NFile != null) {
  86. $i18nDOM = new DOMDocument('1.0', 'utf-8');
  87. $i18nDOM->load($this->componentI18NFile);
  88. $i18nXpath = new DOMXpath($i18nDOM);
  89. $i18nNodeList = $i18nXpath->query("/i18n/".$p_node."/".$this->_getLang());
  90. $i18nNodeList2 = $i18nXpath->query("/i18n/".$p_node."");
  91. if($count = $i18nNodeList->length > 0 && $i18nNodeList->item(0)->nodeValue != "") {
  92. return $i18nNodeList->item(0)->nodeValue;
  93. }elseif ($i18nNodeList2->length == 0) {
  94. $MISConfig->setNodeValue($p_node,"",$i18nDOM,$i18nXpath->query("/i18n")->item(0));
  95. $i18nDOM->save($this->componentI18NFile);
  96. return "[".$this->_component.":".$this->_getLang().":".$p_node."=!]";
  97. } else {
  98. return "[".$this->_component.":".$this->_getLang().":".$p_node."=?]";
  99. }
  100. } else {
  101. return "[".$this->_component.":".$this->_getLang().":".$p_node.": NO LANGUAGE PACK INSTALLED]";
  102. }
  103. }
  104. // USER
  105. final protected function _getLang(){
  106. $p_username = $this->getUsername();
  107. $userDOM = new DOMDocument('1.0', 'utf-8');
  108. $userDOM->load($this->authFile);
  109. $userXpath = new DOMXpath($userDOM);
  110. $UU = $userXpath->query("/auth/users/user[./@username='".utf8_encode($p_username)."']")->item(0);
  111. if(!$UU) {
  112. $MISConfig = new MISConfig();
  113. $projectDOM = new DOMDocument('1.0', 'utf-8');
  114. $projectDOM->load($MISConfig->getConfigFile());
  115. $projectXpath = new DOMXpath($projectDOM);
  116. return $projectXpath->query("/Configuration/General/Language")->item(0)->nodeValue;
  117. }
  118. return $UU->getAttribute("lang");
  119. }
  120. final protected function _getView($p_username=null){
  121. if($p_username==null) $p_username = utf8_decode($this->getUsername());
  122. $userDOM = new DOMDocument('1.0', 'utf-8');
  123. $userDOM->load($this->authFile);
  124. $userXpath = new DOMXpath($userDOM);
  125. $UU = $userXpath->query("/auth/users/user[./@username='".utf8_encode($p_username)."']")->item(0);
  126. return $UU->getAttribute("view");
  127. }
  128. }
  129. ?>