templatelayout.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 if ($renderas == 'guest') {
  30. parent::__construct('core', 'layout.guest');
  31. } else {
  32. parent::__construct('core', 'layout.base');
  33. }
  34. $apps_paths = array();
  35. foreach(OC_App::getEnabledApps() as $app){
  36. $apps_paths[$app] = OC_App::getAppWebPath($app);
  37. }
  38. $this->assign( 'apps_paths', str_replace('\\/', '/',json_encode($apps_paths)),false ); // Ugly unescape slashes waiting for better solution
  39. // Add the js files
  40. $jsfiles = self::findJavascriptFiles(OC_Util::$scripts);
  41. $this->assign('jsfiles', array(), false);
  42. foreach($jsfiles as $info) {
  43. $root = $info[0];
  44. $web = $info[1];
  45. $file = $info[2];
  46. $this->append( 'jsfiles', $web.'/'.$file);
  47. }
  48. // Add the css files
  49. $cssfiles = self::findStylesheetFiles(OC_Util::$styles);
  50. $this->assign('cssfiles', array());
  51. foreach($cssfiles as $info) {
  52. $root = $info[0];
  53. $web = $info[1];
  54. $file = $info[2];
  55. $paths = explode('/', $file);
  56. $in_root = false;
  57. foreach(OC::$APPSROOTS as $app_root) {
  58. if($root == $app_root['path']) {
  59. $in_root = true;
  60. break;
  61. }
  62. }
  63. if($in_root ) {
  64. $app = $paths[0];
  65. unset($paths[0]);
  66. $path = implode('/', $paths);
  67. $this->append( 'cssfiles', OC_Helper::linkTo($app, $path));
  68. }
  69. else {
  70. $this->append( 'cssfiles', $web.'/'.$file);
  71. }
  72. }
  73. }
  74. /*
  75. * @brief append the $file-url if exist at $root
  76. * @param $files array to append file info to
  77. * @param $root path to check
  78. * @param $web base for path
  79. * @param $file the filename
  80. */
  81. static public function appendIfExist(&$files, $root, $webroot, $file) {
  82. if (is_file($root.'/'.$file)) {
  83. $files[] = array($root, $webroot, $file);
  84. return true;
  85. }
  86. return false;
  87. }
  88. static public function findStylesheetFiles($styles){
  89. // Read the selected theme from the config file
  90. $theme=OC_Config::getValue( 'theme' );
  91. // Read the detected formfactor and use the right file name.
  92. $fext = self::getFormFactorExtension();
  93. $files = array();
  94. foreach($styles as $style){
  95. // is it in 3rdparty?
  96. if(self::appendIfExist($files, OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $style.'.css')) {
  97. // or in the owncloud root?
  98. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$style$fext.css" )) {
  99. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$style.css" )) {
  100. // or in core ?
  101. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$style$fext.css" )) {
  102. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$style.css" )) {
  103. }else{
  104. $append = false;
  105. // or in apps?
  106. foreach( OC::$APPSROOTS as $apps_dir)
  107. {
  108. if(self::appendIfExist($files, $apps_dir['path'], $apps_dir['url'], "$style$fext.css")) { $append =true; break; }
  109. elseif(self::appendIfExist($files, $apps_dir['path'], $apps_dir['url'], "$style.css")) { $append =true; break; }
  110. }
  111. if(! $append) {
  112. echo('css file not found: style:'.$style.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT);
  113. die();
  114. }
  115. }
  116. }
  117. // Add the theme css files. you can override the default values here
  118. if(!empty($theme)) {
  119. foreach($styles as $style){
  120. if(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style$fext.css" )) {
  121. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style.css" )) {
  122. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style$fext.css" )) {
  123. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style.css" )) {
  124. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style$fext.css" )) {
  125. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style.css" )) {
  126. }
  127. }
  128. }
  129. return $files;
  130. }
  131. static public function findJavascriptFiles($scripts){
  132. // Read the selected theme from the config file
  133. $theme=OC_Config::getValue( 'theme' );
  134. // Read the detected formfactor and use the right file name.
  135. $fext = self::getFormFactorExtension();
  136. $files = array();
  137. foreach($scripts as $script){
  138. // Is it in 3rd party?
  139. if(self::appendIfExist($files, OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $script.'.js')) {
  140. // Is it in apps and overwritten by the theme?
  141. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script$fext.js" )) {
  142. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script.js" )) {
  143. // Is it in the owncloud root but overwritten by the theme?
  144. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script$fext.js" )) {
  145. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script.js" )) {
  146. // Is it in the owncloud root ?
  147. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$script$fext.js" )) {
  148. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$script.js" )) {
  149. // Is in core but overwritten by a theme?
  150. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$script$fext.js" )) {
  151. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$script.js" )) {
  152. // Is it in core?
  153. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$script$fext.js" )) {
  154. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$script.js" )) {
  155. }else{
  156. // Is it part of an app?
  157. $append = false;
  158. foreach( OC::$APPSROOTS as $apps_dir) {
  159. if(self::appendIfExist($files, $apps_dir['path'], OC::$WEBROOT.$apps_dir['url'], "$script$fext.js")) { $append =true; break; }
  160. elseif(self::appendIfExist($files, $apps_dir['path'], OC::$WEBROOT.$apps_dir['url'], "$script.js")) { $append =true; break; }
  161. }
  162. if(! $append) {
  163. echo('js file not found: script:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT);
  164. die();
  165. }
  166. }
  167. }
  168. return $files;
  169. }
  170. }