templatelayout.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. $this->assign('enableAvatars', \OC_Config::getValue('enable_avatars', true));
  46. } else if ($renderas == 'guest' || $renderas == 'error') {
  47. parent::__construct('core', 'layout.guest');
  48. } else {
  49. parent::__construct('core', 'layout.base');
  50. }
  51. $versionParameter = '?v=' . md5(implode(OC_Util::getVersion()));
  52. // Add the js files
  53. $jsfiles = self::findJavascriptFiles(OC_Util::$scripts);
  54. $this->assign('jsfiles', array(), false);
  55. if (OC_Config::getValue('installed', false) && $renderas!='error') {
  56. $this->append( 'jsfiles', OC_Helper::linkToRoute('js_config') . $versionParameter);
  57. }
  58. if (!empty(OC_Util::$coreScripts)) {
  59. $this->append( 'jsfiles', OC_Helper::linkToRemoteBase('core.js', false) . $versionParameter);
  60. }
  61. foreach($jsfiles as $info) {
  62. $root = $info[0];
  63. $web = $info[1];
  64. $file = $info[2];
  65. $this->append( 'jsfiles', $web.'/'.$file . $versionParameter);
  66. }
  67. // Add the css files
  68. $cssfiles = self::findStylesheetFiles(OC_Util::$styles);
  69. $this->assign('cssfiles', array());
  70. if (!empty(OC_Util::$coreStyles)) {
  71. $this->append( 'cssfiles', OC_Helper::linkToRemoteBase('core.css', false) . $versionParameter);
  72. }
  73. foreach($cssfiles as $info) {
  74. $root = $info[0];
  75. $web = $info[1];
  76. $file = $info[2];
  77. $this->append( 'cssfiles', $web.'/'.$file . $versionParameter);
  78. }
  79. }
  80. static public function findStylesheetFiles($styles) {
  81. // Read the selected theme from the config file
  82. $theme = OC_Util::getTheme();
  83. // Read the detected formfactor and use the right file name.
  84. $fext = self::getFormFactorExtension();
  85. $locator = new \OC\Template\CSSResourceLocator( $theme, $fext,
  86. array( OC::$SERVERROOT => OC::$WEBROOT ),
  87. array( OC::$THIRDPARTYROOT => OC::$THIRDPARTYWEBROOT ));
  88. $locator->find($styles);
  89. return $locator->getResources();
  90. }
  91. static public function findJavascriptFiles($scripts) {
  92. // Read the selected theme from the config file
  93. $theme = OC_Util::getTheme();
  94. // Read the detected formfactor and use the right file name.
  95. $fext = self::getFormFactorExtension();
  96. $locator = new \OC\Template\JSResourceLocator( $theme, $fext,
  97. array( OC::$SERVERROOT => OC::$WEBROOT ),
  98. array( OC::$THIRDPARTYROOT => OC::$THIRDPARTYWEBROOT ));
  99. $locator->find($scripts);
  100. return $locator->getResources();
  101. }
  102. }