PageRenderTime 54ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/templatelayout.php

https://github.com/sezuan/core
PHP | 207 lines | 150 code | 24 blank | 33 comment | 30 complexity | a24e47774929c8c7b0cb01b8c41204d4 MD5 | raw file
Possible License(s): AGPL-3.0, AGPL-1.0, MPL-2.0-no-copyleft-exception
  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. // Update notification
  19. if(OC_Config::getValue('updatechecker', true) === true) {
  20. $data=OC_Updater::check();
  21. if(isset($data['version']) && $data['version'] != '' and $data['version'] !== Array() && OC_User::isAdminUser(OC_User::getUser())) {
  22. $this->assign('updateAvailable', true);
  23. $this->assign('updateVersion', $data['versionstring']);
  24. $this->assign('updateLink', $data['web']);
  25. } else {
  26. $this->assign('updateAvailable', false); // No update available or not an admin user
  27. }
  28. } else {
  29. $this->assign('updateAvailable', false); // Update check is disabled
  30. }
  31. // Add navigation entry
  32. $this->assign( 'application', '', false );
  33. $navigation = OC_App::getNavigation();
  34. $this->assign( 'navigation', $navigation);
  35. $this->assign( 'settingsnavigation', OC_App::getSettingsNavigation());
  36. foreach($navigation as $entry) {
  37. if ($entry['active']) {
  38. $this->assign( 'application', $entry['name'] );
  39. break;
  40. }
  41. }
  42. $user_displayname = OC_User::getDisplayName();
  43. $this->assign( 'user_displayname', $user_displayname );
  44. $this->assign( 'user_uid', OC_User::getUser() );
  45. } else if ($renderas == 'guest' || $renderas == 'error') {
  46. parent::__construct('core', 'layout.guest');
  47. } else {
  48. parent::__construct('core', 'layout.base');
  49. }
  50. $versionParameter = '?v=' . md5(implode(OC_Util::getVersion()));
  51. // Add the js files
  52. $jsfiles = self::findJavascriptFiles(OC_Util::$scripts);
  53. $this->assign('jsfiles', array(), false);
  54. if (OC_Config::getValue('installed', false) && $renderas!='error') {
  55. $this->append( 'jsfiles', OC_Helper::linkToRoute('js_config') . $versionParameter);
  56. }
  57. if (!empty(OC_Util::$core_scripts)) {
  58. $this->append( 'jsfiles', OC_Helper::linkToRemoteBase('core.js', false) . $versionParameter);
  59. }
  60. foreach($jsfiles as $info) {
  61. $root = $info[0];
  62. $web = $info[1];
  63. $file = $info[2];
  64. $this->append( 'jsfiles', $web.'/'.$file . $versionParameter);
  65. }
  66. // Add the css files
  67. $cssfiles = self::findStylesheetFiles(OC_Util::$styles);
  68. $this->assign('cssfiles', array());
  69. if (!empty(OC_Util::$core_styles)) {
  70. $this->append( 'cssfiles', OC_Helper::linkToRemoteBase('core.css', false) . $versionParameter);
  71. }
  72. foreach($cssfiles as $info) {
  73. $root = $info[0];
  74. $web = $info[1];
  75. $file = $info[2];
  76. $this->append( 'cssfiles', $web.'/'.$file . $versionParameter);
  77. }
  78. }
  79. /*
  80. * @brief append the $file-url if exist at $root
  81. * @param $files array to append file info to
  82. * @param $root path to check
  83. * @param $web base for path
  84. * @param $file the filename
  85. */
  86. static public function appendIfExist(&$files, $root, $webroot, $file) {
  87. if (is_file($root.'/'.$file)) {
  88. $files[] = array($root, $webroot, $file);
  89. return true;
  90. }
  91. return false;
  92. }
  93. static public function findStylesheetFiles($styles) {
  94. // Read the selected theme from the config file
  95. $theme = OC_Util::getTheme();
  96. // Read the detected formfactor and use the right file name.
  97. $fext = self::getFormFactorExtension();
  98. $files = array();
  99. foreach($styles as $style) {
  100. // is it in 3rdparty?
  101. if(strpos($style, '3rdparty') === 0 &&
  102. self::appendIfExist($files, OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $style.'.css')) {
  103. // or in the owncloud root?
  104. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$style$fext.css" )) {
  105. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$style.css" )) {
  106. // or in core ?
  107. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$style$fext.css" )) {
  108. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$style.css" )) {
  109. }else{
  110. $app = substr($style, 0, strpos($style, '/'));
  111. $style = substr($style, strpos($style, '/')+1);
  112. $app_path = OC_App::getAppPath($app);
  113. $app_url = OC::$WEBROOT . '/index.php/apps/' . $app;
  114. if(self::appendIfExist($files, $app_path, $app_url, "$style$fext.css")) {
  115. }
  116. elseif(self::appendIfExist($files, $app_path, $app_url, "$style.css")) {
  117. }
  118. else {
  119. echo('css file not found: style:'.$style.' formfactor:'.$fext
  120. .' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT);
  121. die();
  122. }
  123. }
  124. }
  125. // Add the theme css files. you can override the default values here
  126. if(!empty($theme)) {
  127. foreach($styles as $style) {
  128. if(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style$fext.css" )) {
  129. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$style.css" )) {
  130. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style$fext.css" )) {
  131. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$style.css" )) {
  132. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style$fext.css" )) {
  133. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$style.css" )) {
  134. }
  135. }
  136. }
  137. return $files;
  138. }
  139. static public function findJavascriptFiles($scripts) {
  140. // Read the selected theme from the config file
  141. $theme = OC_Util::getTheme();
  142. // Read the detected formfactor and use the right file name.
  143. $fext = self::getFormFactorExtension();
  144. $files = array();
  145. foreach($scripts as $script) {
  146. // Is it in 3rd party?
  147. if(strpos($script, '3rdparty') === 0 &&
  148. self::appendIfExist($files, OC::$THIRDPARTYROOT, OC::$THIRDPARTYWEBROOT, $script.'.js')) {
  149. // Is it in apps and overwritten by the theme?
  150. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script$fext.js" )) {
  151. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/apps/$script.js" )) {
  152. // Is it in the owncloud root but overwritten by the theme?
  153. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script$fext.js" )) {
  154. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/$script.js" )) {
  155. // Is it in the owncloud root ?
  156. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$script$fext.js" )) {
  157. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "$script.js" )) {
  158. // Is in core but overwritten by a theme?
  159. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$script$fext.js" )) {
  160. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "themes/$theme/core/$script.js" )) {
  161. // Is it in core?
  162. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$script$fext.js" )) {
  163. }elseif(self::appendIfExist($files, OC::$SERVERROOT, OC::$WEBROOT, "core/$script.js" )) {
  164. }else{
  165. // Is it part of an app?
  166. $app = substr($script, 0, strpos($script, '/'));
  167. $script = substr($script, strpos($script, '/')+1);
  168. $app_path = OC_App::getAppPath($app);
  169. $app_url = OC_App::getAppWebPath($app);
  170. if(self::appendIfExist($files, $app_path, $app_url, "$script$fext.js")) {
  171. }
  172. elseif(self::appendIfExist($files, $app_path, $app_url, "$script.js")) {
  173. }
  174. else {
  175. echo('js file not found: script:'.$script.' formfactor:'.$fext
  176. .' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT);
  177. die();
  178. }
  179. }
  180. }
  181. return $files;
  182. }
  183. }