JSResourceLocator.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bart Visscher <bartv@thisnet.nl>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Thomas Müller <thomas.mueller@tmit.eu>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OC\Template;
  26. class JSResourceLocator extends ResourceLocator {
  27. /**
  28. * @param string $script
  29. */
  30. public function doFind($script) {
  31. $theme_dir = 'themes/'.$this->theme.'/';
  32. if (strpos($script, '3rdparty') === 0
  33. && $this->appendIfExist($this->thirdpartyroot, $script.'.js')) {
  34. return;
  35. }
  36. if (strpos($script, '/l10n/') !== false) {
  37. // For language files we try to load them all, so themes can overwrite
  38. // single l10n strings without having to translate all of them.
  39. $found = 0;
  40. $found += $this->appendIfExist($this->serverroot, 'core/'.$script.'.js');
  41. $found += $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js');
  42. $found += $this->appendIfExist($this->serverroot, $script.'.js');
  43. $found += $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js');
  44. $found += $this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js');
  45. if ($found) {
  46. return;
  47. }
  48. } else if ($this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js')
  49. || $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js')
  50. || $this->appendIfExist($this->serverroot, $script.'.js')
  51. || $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js')
  52. || $this->appendIfExist($this->serverroot, 'core/'.$script.'.js')
  53. ) {
  54. return;
  55. }
  56. $app = substr($script, 0, strpos($script, '/'));
  57. $script = substr($script, strpos($script, '/')+1);
  58. $app_path = \OC_App::getAppPath($app);
  59. $app_url = \OC_App::getAppWebPath($app);
  60. // missing translations files fill be ignored
  61. if (strpos($script, 'l10n/') === 0) {
  62. $this->appendIfExist($app_path, $script . '.js', $app_url);
  63. return;
  64. }
  65. $this->append($app_path, $script . '.js', $app_url);
  66. }
  67. /**
  68. * @param string $script
  69. */
  70. public function doFindTheme($script) {
  71. }
  72. }