|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Library more info view file. |
|
5
|
|
|
* |
|
6
|
|
|
* @package View |
|
7
|
|
|
* |
|
8
|
|
|
* @copyright YetiForce Sp. z o.o |
|
9
|
|
|
* @license YetiForce Public License 3.0 (licenses/LicenseEN.txt or yetiforce.com) |
|
10
|
|
|
* @author Arkadiusz Sołek <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace YF\Modules\YetiForce\View; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Library more info view class. |
|
17
|
|
|
*/ |
|
18
|
|
|
class LibraryMoreInfo extends \App\Controller\Modal |
|
19
|
|
|
{ |
|
20
|
|
|
/** @var array Public libraries package files. */ |
|
21
|
|
|
public $packageFiles = ['package.json', 'composer.json', 'bower.json']; |
|
22
|
|
|
|
|
23
|
|
|
/** {@inheritdoc} */ |
|
24
|
|
|
public function checkPermission(): void |
|
25
|
|
|
{ |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** {@inheritdoc} */ |
|
29
|
|
|
public function getTitle(): string |
|
30
|
|
|
{ |
|
31
|
|
|
return \App\Language::translate('LBL_MORE_LIBRARY_INFO', $this->moduleName); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** {@inheritdoc} */ |
|
35
|
|
|
public function getModalIcon(): string |
|
36
|
|
|
{ |
|
37
|
|
|
return 'fas fa-info-circle'; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** {@inheritdoc} */ |
|
41
|
|
|
public function validateRequest(): void |
|
42
|
|
|
{ |
|
43
|
|
|
$this->request->validateWriteAccess(); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** {@inheritdoc} */ |
|
47
|
|
|
public function process(): void |
|
48
|
|
|
{ |
|
49
|
|
|
$result = false; |
|
50
|
|
|
$fileContent = ''; |
|
51
|
|
|
if ($this->request->isEmpty('type') || $this->request->isEmpty('libraryName')) { |
|
52
|
|
|
$result = false; |
|
53
|
|
|
} else { |
|
54
|
|
|
if ('public' === $this->request->get('type')) { |
|
55
|
|
|
$dir = ROOT_DIRECTORY . \DIRECTORY_SEPARATOR . 'public_html' . \DIRECTORY_SEPARATOR . 'libraries' . \DIRECTORY_SEPARATOR; |
|
56
|
|
|
$libraryName = $this->request->get('libraryName'); |
|
57
|
|
|
foreach ($this->packageFiles as $file) { |
|
58
|
|
|
$packageFile = $dir . $libraryName . \DIRECTORY_SEPARATOR . $file; |
|
59
|
|
|
if ($fileContent) { |
|
60
|
|
|
continue; |
|
61
|
|
|
} |
|
62
|
|
View Code Duplication |
if (file_exists($packageFile)) { |
|
|
|
|
|
|
63
|
|
|
$fileContent = file_get_contents($packageFile); |
|
64
|
|
|
$result = true; |
|
65
|
|
|
} else { |
|
66
|
|
|
$result = false; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
} elseif ('vendor' === $this->request->get('type')) { |
|
70
|
|
|
$filePath = 'vendor' . \DIRECTORY_SEPARATOR . $this->request->get('libraryName') . \DIRECTORY_SEPARATOR . 'composer.json'; |
|
71
|
|
|
|
|
72
|
|
View Code Duplication |
if (file_exists($filePath)) { |
|
|
|
|
|
|
73
|
|
|
$fileContent = file_get_contents($filePath); |
|
74
|
|
|
$result = true; |
|
75
|
|
|
} else { |
|
76
|
|
|
$result = false; |
|
77
|
|
|
} |
|
78
|
|
|
} else { |
|
79
|
|
|
$result = false; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
$moduleName = $this->request->getModule(false); |
|
|
|
|
|
|
83
|
|
|
$this->viewer->assign('QUALIFIED_MODULE', $moduleName); |
|
84
|
|
|
$this->viewer->assign('RESULT', $result); |
|
85
|
|
|
$this->viewer->assign('FILE_CONTENT', $fileContent); |
|
86
|
|
|
$this->viewer->view('LibraryMoreInfo.tpl', $moduleName); |
|
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.