templatelayout.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. static public function findStylesheetFiles($styles) {
  80. // Read the selected theme from the config file
  81. $theme = OC_Util::getTheme();
  82. // Read the detected formfactor and use the right file name.
  83. $fext = self::getFormFactorExtension();
  84. $locator = new \OC\Template\CSSResourceLocator( $theme, $fext,
  85. array( OC::$SERVERROOT => OC::$WEBROOT ),
  86. array( OC::$THIRDPARTYROOT => OC::$THIRDPARTYWEBROOT ));
  87. $locator->find($styles);
  88. return $locator->getResources();
  89. }
  90. static public function findJavascriptFiles($scripts) {
  91. // Read the selected theme from the config file
  92. $theme = OC_Util::getTheme();
  93. // Read the detected formfactor and use the right file name.
  94. $fext = self::getFormFactorExtension();
  95. $locator = new \OC\Template\JSResourceLocator( $theme, $fext,
  96. array( OC::$SERVERROOT => OC::$WEBROOT ),
  97. array( OC::$THIRDPARTYROOT => OC::$THIRDPARTYWEBROOT ));
  98. $locator->find($scripts);
  99. return $locator->getResources();
  100. }
  101. }