Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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