Completed
Push — stable8.2 ( ec0a29...f5c39b )
by
unknown
18:21
created

index.php ➔ renderScript()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6
Metric Value
cc 2
eloc 10
nc 2
nop 2
dl 0
loc 13
ccs 0
cts 11
cp 0
crap 6
rs 9.4285
1
<?php
2
/**
3
 * @author Björn Schießle <[email protected]>
4
 * @author Frank Karlitschek <[email protected]>
5
 * @author Jakob Sack <[email protected]>
6
 * @author Jan-Christoph Borchardt <[email protected]>
7
 * @author Joas Schilling <[email protected]>
8
 * @author Jörn Friedrich Dreyer <[email protected]>
9
 * @author Morris Jobke <[email protected]>
10
 * @author Robin Appelman <[email protected]>
11
 * @author Roman Geber <[email protected]>
12
 * @author Thomas Müller <[email protected]>
13
 * @author Vincent Petry <[email protected]>
14
 *
15
 * @copyright Copyright (c) 2015, ownCloud, Inc.
16
 * @license AGPL-3.0
17
 *
18
 * This code is free software: you can redistribute it and/or modify
19
 * it under the terms of the GNU Affero General Public License, version 3,
20
 * as published by the Free Software Foundation.
21
 *
22
 * This program is distributed in the hope that it will be useful,
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
 * GNU Affero General Public License for more details.
26
 *
27
 * You should have received a copy of the GNU Affero General Public License, version 3,
28
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
29
 *
30
 */
31
32
// Check if we are a user
33
OCP\User::checkLoggedIn();
34
35
// Load the files we need
36
OCP\Util::addStyle('files', 'files');
37
OCP\Util::addStyle('files', 'upload');
38
OCP\Util::addStyle('files', 'mobile');
39
OCP\Util::addscript('files', 'app');
40
OCP\Util::addscript('files', 'file-upload');
41
OCP\Util::addscript('files', 'newfilemenu');
42
OCP\Util::addscript('files', 'jquery.iframe-transport');
43
OCP\Util::addscript('files', 'jquery.fileupload');
44
OCP\Util::addscript('files', 'jquery-visibility');
45
OCP\Util::addscript('files', 'fileinfomodel');
46
OCP\Util::addscript('files', 'filesummary');
47
OCP\Util::addscript('files', 'breadcrumb');
48
OCP\Util::addscript('files', 'filelist');
49
OCP\Util::addscript('files', 'search');
50
51
\OCP\Util::addScript('files', 'favoritesfilelist');
52
\OCP\Util::addScript('files', 'tagsplugin');
53
\OCP\Util::addScript('files', 'favoritesplugin');
54
55
\OCP\Util::addScript('files', 'detailfileinfoview');
56
\OCP\Util::addScript('files', 'detailtabview');
57
\OCP\Util::addScript('files', 'mainfileinfodetailview');
58
\OCP\Util::addScript('files', 'detailsview');
59
\OCP\Util::addStyle('files', 'detailsView');
60
61
\OC_Util::addVendorScript('core', 'handlebars/handlebars');
62
63
OCP\App::setActiveNavigationEntry('files_index');
64
65
$l = \OC::$server->getL10N('files');
66
67
$isIE8 = false;
68
preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $matches);
69 View Code Duplication
if (count($matches) > 0 && $matches[1] <= 9) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
70
	$isIE8 = true;
71
}
72
73
// if IE8 and "?dir=path&view=someview" was specified, reformat the URL to use a hash like "#?dir=path&view=someview"
74
if ($isIE8 && (isset($_GET['dir']) || isset($_GET['view']))) {
75
	$hash = '#?';
76
	$dir = isset($_GET['dir']) ? $_GET['dir'] : '/';
77
	$view = isset($_GET['view']) ? $_GET['view'] : 'files';
78
	$hash = '#?dir=' . \OCP\Util::encodePath($dir);
79
	if ($view !== 'files') {
80
		$hash .= '&view=' . urlencode($view);
81
	}
82
	header('Location: ' . OCP\Util::linkTo('files', 'index.php') . $hash);
83
	exit();
84
}
85
86
$user = OC_User::getUser();
87
88
$config = \OC::$server->getConfig();
89
90
// mostly for the home storage's free space
91
$dirInfo = \OC\Files\Filesystem::getFileInfo('/', false);
92
$storageInfo=OC_Helper::getStorageInfo('/', $dirInfo);
93
94
$nav = new OCP\Template('files', 'appnavigation', '');
95
96
function sortNavigationItems($item1, $item2) {
97
	return $item1['order'] - $item2['order'];
98
}
99
100
\OCA\Files\App::getNavigationManager()->add(
101
	array(
102
		'id' => 'favorites',
103
		'appname' => 'files',
104
		'script' => 'simplelist.php',
105
		'order' => 5,
106
		'name' => $l->t('Favorites')
107
	)
108
);
109
110
$navItems = \OCA\Files\App::getNavigationManager()->getAll();
111
usort($navItems, 'sortNavigationItems');
112
$nav->assign('navigationItems', $navItems);
113
114
$contentItems = array();
115
116
function renderScript($appName, $scriptName) {
117
	$content = '';
118
	$appPath = OC_App::getAppPath($appName);
119
	$scriptPath = $appPath . '/' . $scriptName;
120
	if (file_exists($scriptPath)) {
121
		// TODO: sanitize path / script name ?
122
		ob_start();
123
		include $scriptPath;
124
		$content = ob_get_contents();
125
		@ob_end_clean();
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
126
	}
127
	return $content;
128
}
129
130
// render the container content for every navigation item
131
foreach ($navItems as $item) {
132
	$content = '';
133
	if (isset($item['script'])) {
134
		$content = renderScript($item['appname'], $item['script']);
135
	}
136
	$contentItem = array();
137
	$contentItem['id'] = $item['id'];
138
	$contentItem['content'] = $content;
139
	$contentItems[] = $contentItem;
140
}
141
142
OCP\Util::addscript('files', 'fileactions');
143
OCP\Util::addscript('files', 'fileactionsmenu');
144
OCP\Util::addscript('files', 'files');
145
OCP\Util::addscript('files', 'navigation');
146
OCP\Util::addscript('files', 'keyboardshortcuts');
147
148
\OC::$server->getEventDispatcher()->dispatch('OCA\Files::loadAdditionalScripts');
149
150
$tmpl = new OCP\Template('files', 'index', 'user');
151
$tmpl->assign('usedSpacePercent', (int)$storageInfo['relative']);
152
$tmpl->assign('owner', $storageInfo['owner']);
153
$tmpl->assign('ownerDisplayName', $storageInfo['ownerDisplayName']);
154
$tmpl->assign('isPublic', false);
155
$tmpl->assign("mailNotificationEnabled", $config->getAppValue('core', 'shareapi_allow_mail_notification', 'no'));
156
$tmpl->assign("mailPublicNotificationEnabled", $config->getAppValue('core', 'shareapi_allow_public_notification', 'no'));
157
$tmpl->assign("allowShareWithLink", $config->getAppValue('core', 'shareapi_allow_links', 'yes'));
158
$tmpl->assign('appNavigation', $nav);
0 ignored issues
show
Documentation introduced by
$nav is of type object<OCP\Template>, but the function expects a array|boolean|integer|string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
159
$tmpl->assign('appContents', $contentItems);
160
161
$tmpl->printPage();
162