templatelayout.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. /**
  3. * Copyright (c) 2012 Bart Visscher <bartv@thisnet.nl>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. class OC_TemplateLayout extends OC_Template {
  9. public function __construct( $renderas ){
  10. // Decide which page we show
  11. if( $renderas == 'user' ){
  12. parent::__construct( 'core', 'layout.user' );
  13. $this->assign('searchurl',OC_Helper::linkTo( 'search', 'index.php' ), false);
  14. if(array_search(OC_APP::getCurrentApp(),array('settings','admin','help'))!==false){
  15. $this->assign('bodyid','body-settings', false);
  16. }else{
  17. $this->assign('bodyid','body-user', false);
  18. }
  19. // Add navigation entry
  20. $navigation = OC_App::getNavigation();
  21. $this->assign( 'navigation', $navigation, false);
  22. $this->assign( 'settingsnavigation', OC_App::getSettingsNavigation(), false);
  23. foreach($navigation as $entry) {
  24. if ($entry['active']) {
  25. $this->assign( 'application', $entry['name'], false );
  26. break;
  27. }
  28. }
  29. }else{
  30. parent::__construct( 'core', 'layout.guest' );
  31. }
  32. // Add the js files
  33. $jsfiles = self::findJavascriptFiles(OC_Util::$scripts);
  34. $this->assign('jsfiles', array(), false);
  35. foreach($jsfiles as $info) {
  36. $root = $info[0];
  37. $web = $info[1];
  38. $file = $info[2];
  39. $this->append( 'jsfiles', $web.'/'.$file);
  40. }
  41. // Add the css files
  42. $cssfiles = self::findStylesheetFiles(OC_Util::$styles);
  43. $this->assign('cssfiles', array());
  44. foreach($cssfiles as $info) {
  45. $root = $info[0];
  46. $web = $info[1];
  47. $file = $info[2];
  48. $paths = explode('/', $file);
  49. if($root == OC::$APPSROOT && $paths[0] == 'apps'){
  50. $app = $paths[1];
  51. unset($paths[0]);
  52. unset($paths[1]);
  53. $path = implode('/', $paths);
  54. $this->append( 'cssfiles', OC_Helper::linkTo($app, $path));
  55. }else{
  56. $this->append( 'cssfiles', $web.'/'.$file);
  57. }
  58. }
  59. }
  60. /*
  61. * @brief append the $file-url if exist at $root
  62. * @param $files array to append file info to
  63. * @param $root path to check
  64. * @param $web base for path
  65. * @param $file the filename
  66. */
  67. static public function appendIfExist(&$files, $root, $webroot, $file) {
  68. if (is_file($root.'/'.$file)) {
  69. $files[] = array($root, $webroot, $file);
  70. return true;
  71. }
  72. return false;
  73. }
  74. static public function findStylesheetFiles($styles){
  75. // Read the selected theme from the config file
  76. $theme=OC_Config::getValue( 'theme' );
  77. // Read the detected formfactor and use the right file name.
  78. $fext = self::getFormFactorExtension();
  79. $files = array();
  80. foreach($styles as $style){
  81. // is it in 3rdparty?
  82. if(self::appendIfExist($files, OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $style.'.css')) {
  83. // or in apps?
  84. }elseif(self::appendIfExist($files, OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$style$fext.css" )) {
  85. }elseif(self::appendIfExist($files, OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$style.css" )) {
  86. // or in the owncloud root?
  87. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$style$fext.css" )) {
  88. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$style.css" )) {
  89. // or in core ?
  90. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$style$fext.css" )) {
  91. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$style.css" )) {
  92. }else{
  93. echo('css file not found: style:'.$style.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT);
  94. die();
  95. }
  96. }
  97. // Add the theme css files. you can override the default values here
  98. if(!empty($theme)) {
  99. foreach($styles as $style){
  100. if(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style$fext.css" )) {
  101. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style.css" )) {
  102. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style$fext.css" )) {
  103. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style.css" )) {
  104. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style$fext.css" )) {
  105. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style.css" )) {
  106. }
  107. }
  108. }
  109. return $files;
  110. }
  111. static public function findJavascriptFiles($scripts){
  112. // Read the selected theme from the config file
  113. $theme=OC_Config::getValue( 'theme' );
  114. // Read the detected formfactor and use the right file name.
  115. $fext = self::getFormFactorExtension();
  116. $files = array();
  117. foreach($scripts as $script){
  118. // Is it in 3rd party?
  119. if(self::appendIfExist($files, OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $script.'.js')) {
  120. // Is it in apps and overwritten by the theme?
  121. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script$fext.js" )) {
  122. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script.js" )) {
  123. // Is it part of an app?
  124. }elseif(self::appendIfExist($files, OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$script$fext.js" )) {
  125. }elseif(self::appendIfExist($files, OC::$APPSROOT, OC::$APPSWEBROOT, "apps/$script.js" )) {
  126. // Is it in the owncloud root but overwritten by the theme?
  127. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script$fext.js" )) {
  128. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script.js" )) {
  129. // Is it in the owncloud root ?
  130. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$script$fext.js" )) {
  131. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$script.js" )) {
  132. // Is in core but overwritten by a theme?
  133. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$script$fext.js" )) {
  134. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$script.js" )) {
  135. // Is it in core?
  136. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$script$fext.js" )) {
  137. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$script.js" )) {
  138. }else{
  139. echo('js file not found: script:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT);
  140. die();
  141. }
  142. }
  143. return $files;
  144. }
  145. }