You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
7.0 KiB

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