aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/util.php
diff options
context:
space:
mode:
authorIndividual IT Services <info@individual-it.net>2015-09-30 09:54:29 +0545
committerMorris Jobke <hey@morrisjobke.de>2015-11-23 11:02:46 +0100
commit1835462ec4b37f256390785a3cf3531699a996cb (patch)
tree45ca9f3efdce47dc8c3585798e5401d5e325a219 /lib/private/util.php
parent79bbda994bb8dd2231f68f57785237f79f86f6c7 (diff)
downloadnextcloud-server-1835462ec4b37f256390785a3cf3531699a996cb.tar.gz
nextcloud-server-1835462ec4b37f256390785a3cf3531699a996cb.zip
reuse code
Diffstat (limited to 'lib/private/util.php')
-rw-r--r--lib/private/util.php81
1 files changed, 38 insertions, 43 deletions
diff --git a/lib/private/util.php b/lib/private/util.php
index 69f01c22be9..0bbb92a9607 100644
--- a/lib/private/util.php
+++ b/lib/private/util.php
@@ -457,19 +457,12 @@ class OC_Util {
*/
public static function addScript($application, $file = null, $prepend = false) {
$path = OC_Util::generatePath($application, 'js', $file);
- //TODO eliminate double code
- if (!in_array($path, self::$scripts)) {
- // core js files need separate handling
- if ($application !== 'core' && $file !== null) {
- self::addTranslations($application);
- }
- if ($prepend===true) {
- array_unshift(self::$scripts, $path);
- }
- else {
- self::$scripts[] = $path;
- }
+
+ // core js files need separate handling
+ if ($application !== 'core' && $file !== null) {
+ self::addTranslations ( $application );
}
+ self::addExternalResource($application, $prepend, $path, "script");
}
/**
@@ -482,14 +475,7 @@ class OC_Util {
*/
public static function addVendorScript($application, $file = null, $prepend = false) {
$path = OC_Util::generatePath($application, 'vendor', $file);
- //TODO eliminate double code
- if (! in_array ( $path, self::$scripts )) {
- if ($prepend === true) {
- array_unshift ( self::$scripts, $path );
- } else {
- self::$scripts [] = $path;
- }
- }
+ self::addExternalResource($application, $prepend, $path, "script");
}
/**
@@ -508,14 +494,7 @@ class OC_Util {
} else {
$path = "l10n/$languageCode";
}
- //TODO eliminate double code
- if (!in_array($path, self::$scripts)) {
- if ($prepend === true) {
- array_unshift ( self::$scripts, $path );
- } else {
- self::$scripts [] = $path;
- }
- }
+ self::addExternalResource($application, $prepend, $path, "script");
}
/**
@@ -528,14 +507,7 @@ class OC_Util {
*/
public static function addStyle($application, $file = null, $prepend = false) {
$path = OC_Util::generatePath($application, 'css', $file);
- //TODO eliminate double code
- if (!in_array($path, self::$styles)) {
- if ($prepend === true) {
- array_unshift ( self::$styles, $path );
- } else {
- self::$styles[] = $path;
- }
- }
+ self::addExternalResource($application, $prepend, $path, "style");
}
/**
@@ -548,13 +520,36 @@ class OC_Util {
*/
public static function addVendorStyle($application, $file = null, $prepend = false) {
$path = OC_Util::generatePath($application, 'vendor', $file);
- //TODO eliminate double code
- if (!in_array($path, self::$styles)) {
- if ($prepend === true) {
- array_unshift ( self::$styles, $path );
- } else {
- self::$styles[] = $path;
- }
+ self::addExternalResource($application, $prepend, $path, "style");
+ }
+
+ /**
+ * add an external resource css/js file
+ *
+ * @param string $application application id
+ * @param bool $prepend prepend the file to the beginning of the list
+ * @param string $path
+ * @param string $type (script or style)
+ * @return void
+ */
+ private static function addExternalResource($application, $prepend, $path, $type = "script") {
+
+ if ($type === "style") {
+ if (!in_array($path, self::$styles)) {
+ if ($prepend === true) {
+ array_unshift ( self::$styles, $path );
+ } else {
+ self::$styles[] = $path;
+ }
+ }
+ } elseif ($type === "script") {
+ if (!in_array($path, self::$scripts)) {
+ if ($prepend === true) {
+ array_unshift ( self::$scripts, $path );
+ } else {
+ self::$scripts [] = $path;
+ }
+ }
}
}