Completed
Push — master ( 1623b2...baa8b6 )
by Morris
28:41 queued 10:43
created
lib/private/Template/JSResourceLocator.php 1 patch
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -28,103 +28,103 @@
 block discarded – undo
28 28
 
29 29
 class JSResourceLocator extends ResourceLocator {
30 30
 
31
-	/** @var JSCombiner */
32
-	protected $jsCombiner;
33
-
34
-	public function __construct(\OCP\ILogger $logger, $theme, array $core_map, array $party_map, JSCombiner $JSCombiner) {
35
-		parent::__construct($logger, $theme, $core_map, $party_map);
36
-
37
-		$this->jsCombiner = $JSCombiner;
38
-	}
39
-
40
-	/**
41
-	 * @param string $script
42
-	 */
43
-	public function doFind($script) {
44
-		$theme_dir = 'themes/'.$this->theme.'/';
45
-		if (strpos($script, '3rdparty') === 0
46
-			&& $this->appendIfExist($this->thirdpartyroot, $script.'.js')) {
47
-			return;
48
-		}
49
-
50
-		if (strpos($script, '/l10n/') !== false) {
51
-			// For language files we try to load them all, so themes can overwrite
52
-			// single l10n strings without having to translate all of them.
53
-			$found = 0;
54
-			$found += $this->appendIfExist($this->serverroot, 'core/'.$script.'.js');
55
-			$found += $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js');
56
-			$found += $this->appendIfExist($this->serverroot, $script.'.js');
57
-			$found += $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js');
58
-			$found += $this->appendIfExist($this->serverroot, 'apps/'.$script.'.js');
59
-			$found += $this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js');
60
-
61
-			if ($found) {
62
-				return;
63
-			}
64
-		} else if ($this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js')
65
-			|| $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js')
66
-			|| $this->appendIfExist($this->serverroot, $script.'.js')
67
-			|| $this->cacheAndAppendCombineJsonIfExist($this->serverroot, $script.'.json')
68
-			|| $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js')
69
-			|| $this->appendIfExist($this->serverroot, 'core/'.$script.'.js')
70
-			|| $this->cacheAndAppendCombineJsonIfExist($this->serverroot, 'core/'.$script.'.json')
71
-		) {
72
-			return;
73
-		}
74
-
75
-		$app = substr($script, 0, strpos($script, '/'));
76
-		$script = substr($script, strpos($script, '/')+1);
77
-		$app_path = \OC_App::getAppPath($app);
78
-		$app_url = \OC_App::getAppWebPath($app);
79
-
80
-		if ($app_path !== false) {
81
-			// Account for the possibility of having symlinks in app path. Only
82
-			// do this if $app_path is set, because an empty argument to realpath
83
-			// gets turned into cwd.
84
-			$app_path = realpath($app_path);
85
-		}
86
-
87
-		// missing translations files fill be ignored
88
-		if (strpos($script, 'l10n/') === 0) {
89
-			$this->appendIfExist($app_path, $script . '.js', $app_url);
90
-			return;
91
-		}
92
-
93
-		if ($app_path === false && $app_url === false) {
94
-			$this->logger->error('Could not find resource {resource} to load', [
95
-				'resource' => $app . '/' . $script . '.js',
96
-				'app' => 'jsresourceloader',
97
-			]);
98
-			return;
99
-		}
100
-
101
-		if (!$this->cacheAndAppendCombineJsonIfExist($app_path, $script.'.json', $app)) {
102
-			$this->append($app_path, $script . '.js', $app_url);
103
-		}
104
-	}
105
-
106
-	/**
107
-	 * @param string $script
108
-	 */
109
-	public function doFindTheme($script) {
110
-	}
111
-
112
-	protected function cacheAndAppendCombineJsonIfExist($root, $file, $app = 'core') {
113
-		if (is_file($root.'/'.$file)) {
114
-			if ($this->jsCombiner->process($root, $file, $app)) {
115
-				$this->append($this->serverroot, $this->jsCombiner->getCachedJS($app, $file), false, false);
116
-			} else {
117
-				// Add all the files from the json
118
-				$files = $this->jsCombiner->getContent($root, $file);
119
-				$app_url = \OC_App::getAppWebPath($app);
120
-
121
-				foreach ($files as $jsFile) {
122
-					$this->append($root, $jsFile, $app_url);
123
-				}
124
-			}
125
-			return true;
126
-		}
127
-
128
-		return false;
129
-	}
31
+    /** @var JSCombiner */
32
+    protected $jsCombiner;
33
+
34
+    public function __construct(\OCP\ILogger $logger, $theme, array $core_map, array $party_map, JSCombiner $JSCombiner) {
35
+        parent::__construct($logger, $theme, $core_map, $party_map);
36
+
37
+        $this->jsCombiner = $JSCombiner;
38
+    }
39
+
40
+    /**
41
+     * @param string $script
42
+     */
43
+    public function doFind($script) {
44
+        $theme_dir = 'themes/'.$this->theme.'/';
45
+        if (strpos($script, '3rdparty') === 0
46
+            && $this->appendIfExist($this->thirdpartyroot, $script.'.js')) {
47
+            return;
48
+        }
49
+
50
+        if (strpos($script, '/l10n/') !== false) {
51
+            // For language files we try to load them all, so themes can overwrite
52
+            // single l10n strings without having to translate all of them.
53
+            $found = 0;
54
+            $found += $this->appendIfExist($this->serverroot, 'core/'.$script.'.js');
55
+            $found += $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js');
56
+            $found += $this->appendIfExist($this->serverroot, $script.'.js');
57
+            $found += $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js');
58
+            $found += $this->appendIfExist($this->serverroot, 'apps/'.$script.'.js');
59
+            $found += $this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js');
60
+
61
+            if ($found) {
62
+                return;
63
+            }
64
+        } else if ($this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$script.'.js')
65
+            || $this->appendIfExist($this->serverroot, $theme_dir.$script.'.js')
66
+            || $this->appendIfExist($this->serverroot, $script.'.js')
67
+            || $this->cacheAndAppendCombineJsonIfExist($this->serverroot, $script.'.json')
68
+            || $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$script.'.js')
69
+            || $this->appendIfExist($this->serverroot, 'core/'.$script.'.js')
70
+            || $this->cacheAndAppendCombineJsonIfExist($this->serverroot, 'core/'.$script.'.json')
71
+        ) {
72
+            return;
73
+        }
74
+
75
+        $app = substr($script, 0, strpos($script, '/'));
76
+        $script = substr($script, strpos($script, '/')+1);
77
+        $app_path = \OC_App::getAppPath($app);
78
+        $app_url = \OC_App::getAppWebPath($app);
79
+
80
+        if ($app_path !== false) {
81
+            // Account for the possibility of having symlinks in app path. Only
82
+            // do this if $app_path is set, because an empty argument to realpath
83
+            // gets turned into cwd.
84
+            $app_path = realpath($app_path);
85
+        }
86
+
87
+        // missing translations files fill be ignored
88
+        if (strpos($script, 'l10n/') === 0) {
89
+            $this->appendIfExist($app_path, $script . '.js', $app_url);
90
+            return;
91
+        }
92
+
93
+        if ($app_path === false && $app_url === false) {
94
+            $this->logger->error('Could not find resource {resource} to load', [
95
+                'resource' => $app . '/' . $script . '.js',
96
+                'app' => 'jsresourceloader',
97
+            ]);
98
+            return;
99
+        }
100
+
101
+        if (!$this->cacheAndAppendCombineJsonIfExist($app_path, $script.'.json', $app)) {
102
+            $this->append($app_path, $script . '.js', $app_url);
103
+        }
104
+    }
105
+
106
+    /**
107
+     * @param string $script
108
+     */
109
+    public function doFindTheme($script) {
110
+    }
111
+
112
+    protected function cacheAndAppendCombineJsonIfExist($root, $file, $app = 'core') {
113
+        if (is_file($root.'/'.$file)) {
114
+            if ($this->jsCombiner->process($root, $file, $app)) {
115
+                $this->append($this->serverroot, $this->jsCombiner->getCachedJS($app, $file), false, false);
116
+            } else {
117
+                // Add all the files from the json
118
+                $files = $this->jsCombiner->getContent($root, $file);
119
+                $app_url = \OC_App::getAppWebPath($app);
120
+
121
+                foreach ($files as $jsFile) {
122
+                    $this->append($root, $jsFile, $app_url);
123
+                }
124
+            }
125
+            return true;
126
+        }
127
+
128
+        return false;
129
+    }
130 130
 }
Please login to merge, or discard this patch.