| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * @author Bart Visscher <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * @author Joas Schilling <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @author Michael Jobst <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @author Morris Jobke <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @author Philipp Schaffrath <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @author Thomas Müller <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @copyright Copyright (c) 2018, ownCloud GmbH | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @license AGPL-3.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * This code is free software: you can redistribute it and/or modify | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * it under the terms of the GNU Affero General Public License, version 3, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * as published by the Free Software Foundation. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * This program is distributed in the hope that it will be useful, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * GNU Affero General Public License for more details. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * You should have received a copy of the GNU Affero General Public License, version 3, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * along with this program.  If not, see <http://www.gnu.org/licenses/> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | namespace OC\Template; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | class JSResourceLocator extends ResourceLocator { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 	 * @param string $script | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 	public function doFind($script) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 		$fullScript = $this->addExtension($script); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 		$themeDirectory = $this->theme->getDirectory(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 		$baseDirectory = $this->theme->getBaseDirectory(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 		$webRoot = ''; | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 38 |  | View Code Duplication | 		if ($baseDirectory !== $this->serverroot) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 			$webRoot = substr($this->theme->getWebPath(), 0, -strlen($themeDirectory)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 		if (strpos($script, '/l10n/') !== false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 			// For language files we try to load them all, so themes can overwrite | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 			// single l10n strings without having to translate all of them. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 			$found = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 			$found += $this->appendOnceIfExist($this->serverroot, 'core/'.$fullScript); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 			$found += $this->appendOnceIfExist($baseDirectory, $themeDirectory.'/core/'.$fullScript, $webRoot); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 			$found += $this->appendOnceIfExist($this->serverroot, $fullScript); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 			$found += $this->appendOnceIfExist($baseDirectory, $themeDirectory.'/'.$fullScript, $webRoot); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 			$found += $this->appendOnceIfExist($baseDirectory, $themeDirectory.'/apps/'.$fullScript, $webRoot); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 			if ($found) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 				return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 		} else if ($this->appendOnceIfExist($baseDirectory, $themeDirectory.'/apps/'.$fullScript, $webRoot) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 			|| $this->appendOnceIfExist($baseDirectory, $themeDirectory.'/'.$fullScript, $webRoot) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 			|| $this->appendOnceIfExist($this->serverroot, $fullScript) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 			|| $this->appendOnceIfExist($baseDirectory, $themeDirectory.'/core/'.$fullScript, $webRoot) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 			|| $this->appendOnceIfExist($this->serverroot, 'core/'.$fullScript) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 		) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 			return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 		$app = substr($fullScript, 0, strpos($fullScript, '/')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 		$fullScript = substr($fullScript, strpos($fullScript, '/')+1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 		$app_path = $this->appManager->getAppPath($app); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 		if( $app_path === false ) { return; } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 		$app_url = $this->appManager->getAppWebPath($app); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 		$app_url = ($app_url !== false) ? $app_url : null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 		// missing translations files will be ignored | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 		$this->appendOnceIfExist($app_path, $fullScript, $app_url); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 	 * @param string $script | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 	public function doFindTheme($script) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 	 * @param string $path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 	 * @return string | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 84 |  |  | 	 */ | 
            
                                                        
            
                                    
            
            
                | 85 |  |  | 	protected function addExtension($path) { | 
            
                                                        
            
                                    
            
            
                | 86 |  |  | 		return $path . '.js'; | 
            
                                                        
            
                                    
            
            
                | 87 |  |  | 	} | 
            
                                                        
            
                                    
            
            
                | 88 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 89 |  |  |  | 
            
                        
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.