templatelayout.php 7.5 KB

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