diff options
author | Individual IT Services <info@individual-it.net> | 2015-09-17 12:59:04 +0545 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-09-23 11:57:10 +0200 |
commit | bf1cb20e908d6cc6d84be733f7137a6edf92697b (patch) | |
tree | ab92da0889ed2cf76909954a619db59f76ac2fbc /lib/private | |
parent | d0b17ec8d68396268d880b8e2d163f65da447c77 (diff) | |
download | nextcloud-server-bf1cb20e908d6cc6d84be733f7137a6edf92697b.tar.gz nextcloud-server-bf1cb20e908d6cc6d84be733f7137a6edf92697b.zip |
do not load unnecessary code in case of webdav
changing from "protected static" to "protected"
as suggested by @nickvergessen
https://github.com/owncloud/core/pull/19114#discussion_r39719851
moving initTemplate() into template constr.
reduce to move initTemplate only
cleanup spaces
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/server.php | 21 | ||||
-rw-r--r-- | lib/private/template.php | 77 | ||||
-rw-r--r-- | lib/private/util.php | 30 |
3 files changed, 121 insertions, 7 deletions
diff --git a/lib/private/server.php b/lib/private/server.php index 9f99ead849b..2e77eeb91c5 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -76,6 +76,9 @@ class Server extends SimpleContainer implements IServerContainer { /** @var string */ private $webRoot; + /** @var string */ + protected $service = null; + /** * @param string $webRoot */ @@ -1068,6 +1071,23 @@ class Server extends SimpleContainer implements IServerContainer { } /** + * @return requested service + */ + public function getService() { + if (! isset ($this->service )) { + $pathInfo = self::getRequest ()->getPathInfo (); + if ($pathInfo === false || $pathInfo === '') { + return; + } + if (! $pos = strpos ( $pathInfo, '/', 1 )) { + $pos = strlen ( $pathInfo ); + } + $this->service=substr ( $pathInfo, 1, $pos - 1 ); + } + return $this->service; + } + + /** * Not a public API as of 8.2, wait for 9.0 * @return \OCA\Files_External\Service\BackendService */ @@ -1098,4 +1118,5 @@ class Server extends SimpleContainer implements IServerContainer { public function getUserStoragesService() { return \OC_Mount_Config::$app->getContainer()->query('OCA\\Files_External\\Service\\UserStoragesService'); } + } diff --git a/lib/private/template.php b/lib/private/template.php index 920be71abbf..ef2f71b7f86 100644 --- a/lib/private/template.php +++ b/lib/private/template.php @@ -56,8 +56,13 @@ class OC_Template extends \OC\Template\Base { * according layout. For now, renderas can be set to "guest", "user" or * "admin". */ + + protected static $initTemplateEngineFirstrun = true; + public function __construct( $app, $name, $renderas = "", $registerCall = true ) { // Read the selected theme from the config file + $this->initTemplateEngine(); + $theme = OC_Util::getTheme(); $requesttoken = (OC::$server->getSession() and $registerCall) ? OC_Util::callRegister() : ''; @@ -76,6 +81,78 @@ class OC_Template extends \OC\Template\Base { parent::__construct($template, $requesttoken, $l10n, $themeDefaults); } + public static function initTemplateEngine() { + if (self::$initTemplateEngineFirstrun){ + + //apps that started before the template initialization can load their own scripts + //so to make sure this scripts here are loaded first we use OC_Util::addScript() with $prepend=true + //meaning the last scripts in this list will be loaded first + if (\OC::$server->getSystemConfig ()->getValue ( 'installed', false ) && ! \OCP\Util::needUpgrade ()) { + if (\OC::$server->getConfig ()->getAppValue ( 'core', 'backgroundjobs_mode', 'ajax' ) == 'ajax') { + OC_Util::addScript ( 'backgroundjobs', null, true ); + } + } + + OC_Util::addStyle ( "styles" ); + OC_Util::addStyle ( "header" ); + OC_Util::addStyle ( "mobile" ); + OC_Util::addStyle ( "icons" ); + OC_Util::addStyle ( "fonts" ); + OC_Util::addStyle ( "apps" ); + OC_Util::addStyle ( "fixes" ); + OC_Util::addStyle ( "multiselect" ); + OC_Util::addVendorStyle ( 'jquery-ui/themes/base/jquery-ui'); + OC_Util::addStyle ( 'jquery-ui-fixes' ); + OC_Util::addStyle ( "tooltip" ); + + // avatars + if (\OC::$server->getSystemConfig ()->getValue ( 'enable_avatars', true ) === true) { + \OC_Util::addScript ( 'avatar', null, true ); + \OC_Util::addScript ( 'jquery.avatar', null, true ); + \OC_Util::addScript ( 'placeholder', null, true ); + } + + OC_Util::addScript ( 'oc-backbone', null, true ); + OC_Util::addVendorScript ( 'core', 'backbone/backbone', null, true ); + OC_Util::addVendorScript ( 'snapjs/dist/latest/snap', null, true ); + OC_Util::addScript ( 'mimetypelist', null, true ); + OC_Util::addScript ( 'mimetype', null, true ); + OC_Util::addScript ( "apps", null, true ); + OC_Util::addScript ( "oc-requesttoken", null, true ); + OC_Util::addScript ( 'search', 'search', true ); + OC_Util::addScript ( "config", null, true ); + OC_Util::addScript ( "eventsource", null, true ); + OC_Util::addScript ( "octemplate", null, true ); + OC_Util::addTranslations ( "core", null, true ); + OC_Util::addScript ( "l10n", null, true ); + OC_Util::addScript ( "js", null, true ); + OC_Util::addScript ( "oc-dialogs", null, true ); + OC_Util::addScript ( "jquery.ocdialog", null, true ); + OC_Util::addStyle ( "jquery.ocdialog" ); + OC_Util::addScript ( "compatibility", null, true ); + OC_Util::addScript ( "placeholders", null, true ); + + // Add the stuff we need always + // following logic will import all vendor libraries that are + // specified in core/js/core.json + $fileContent = file_get_contents(OC::$SERVERROOT . '/core/js/core.json'); + if($fileContent !== false) { + $coreDependencies = json_decode($fileContent, true); + foreach(array_reverse($coreDependencies['vendor']) as $vendorLibrary) { + // remove trailing ".js" as addVendorScript will append it + OC_Util::addVendorScript( + substr($vendorLibrary, 0, strlen($vendorLibrary) - 3),null,true); + } + } else { + throw new \Exception('Cannot read core/js/core.json'); + } + + self::$initTemplateEngineFirstrun = false; + } + + } + + /** * find the template with the given name * @param string $name of the template file (without suffix) diff --git a/lib/private/util.php b/lib/private/util.php index eb1de5be5a4..117e57f66d7 100644 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -439,16 +439,22 @@ class OC_Util { * * @param string $application application id * @param string|null $file filename + * @param bool $prepend prepend the Script to the beginning of the list * @return void */ - public static function addScript($application, $file = null) { + public static function addScript($application, $file = null, $prepend = false) { $path = OC_Util::generatePath($application, 'js', $file); if (!in_array($path, self::$scripts)) { // core js files need separate handling if ($application !== 'core' && $file !== null) { self::addTranslations($application); } - self::$scripts[] = $path; + if ($prepend===true) { + array_unshift(self::$scripts, $path); + } + else { + self::$scripts[] = $path; + } } } @@ -457,12 +463,17 @@ class OC_Util { * * @param string $application application id * @param string|null $file filename + * @param bool $prepend prepend the Script to the beginning of the list * @return void */ - public static function addVendorScript($application, $file = null) { + public static function addVendorScript($application, $file = null, $prepend = false) { $path = OC_Util::generatePath($application, 'vendor', $file); - if (!in_array($path, self::$scripts)) { - self::$scripts[] = $path; + if (! in_array ( $path, self::$scripts )) { + if ($prepend === true) { + array_unshift ( self::$scripts, $path ); + } else { + self::$scripts [] = $path; + } } } @@ -471,8 +482,9 @@ class OC_Util { * * @param string $application application id * @param string $languageCode language code, defaults to the current language + * @param bool $prepend prepend the Script to the beginning of the list */ - public static function addTranslations($application, $languageCode = null) { + public static function addTranslations($application, $languageCode = null, $prepend = false) { if (is_null($languageCode)) { $languageCode = \OC_L10N::findLanguage($application); } @@ -482,7 +494,11 @@ class OC_Util { $path = "l10n/$languageCode"; } if (!in_array($path, self::$scripts)) { - self::$scripts[] = $path; + if ($prepend === true) { + array_unshift ( self::$scripts, $path ); + } else { + self::$scripts [] = $path; + } } } |