Completed
Push — stable8.1 ( 7a1b8f...6080a3 )
by
unknown
107:52
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', 'jquery.iframe-transport');
42
OCP\Util::addscript('files', 'jquery.fileupload');
43
OCP\Util::addscript('files', 'jquery-visibility');
44
OCP\Util::addscript('files', 'filesummary');
45
OCP\Util::addscript('files', 'breadcrumb');
46
OCP\Util::addscript('files', 'filelist');
47
OCP\Util::addscript('files', 'search');
48
49
\OCP\Util::addScript('files', 'favoritesfilelist');
50
\OCP\Util::addScript('files', 'tagsplugin');
51
\OCP\Util::addScript('files', 'favoritesplugin');
52
53
\OC_Util::addVendorScript('core', 'handlebars/handlebars');
54
55
OCP\App::setActiveNavigationEntry('files_index');
56
57
$l = \OC::$server->getL10N('files');
58
59
$isIE8 = false;
60
preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $matches);
61 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...
62
	$isIE8 = true;
63
}
64
65
// if IE8 and "?dir=path&view=someview" was specified, reformat the URL to use a hash like "#?dir=path&view=someview"
66
if ($isIE8 && (isset($_GET['dir']) || isset($_GET['view']))) {
67
	$hash = '#?';
68
	$dir = isset($_GET['dir']) ? $_GET['dir'] : '/';
69
	$view = isset($_GET['view']) ? $_GET['view'] : 'files';
70
	$hash = '#?dir=' . \OCP\Util::encodePath($dir);
71
	if ($view !== 'files') {
72
		$hash .= '&view=' . urlencode($view);
73
	}
74
	header('Location: ' . OCP\Util::linkTo('files', 'index.php') . $hash);
75
	exit();
76
}
77
78
$user = OC_User::getUser();
79
80
$config = \OC::$server->getConfig();
81
82
// mostly for the home storage's free space
83
$dirInfo = \OC\Files\Filesystem::getFileInfo('/', false);
84
$storageInfo=OC_Helper::getStorageInfo('/', $dirInfo);
85
86
$nav = new OCP\Template('files', 'appnavigation', '');
87
88
function sortNavigationItems($item1, $item2) {
89
	return $item1['order'] - $item2['order'];
90
}
91
92
\OCA\Files\App::getNavigationManager()->add(
93
	array(
94
		'id' => 'favorites',
95
		'appname' => 'files',
96
		'script' => 'simplelist.php',
97
		'order' => 5,
98
		'name' => $l->t('Favorites')
99
	)
100
);
101
102
$navItems = \OCA\Files\App::getNavigationManager()->getAll();
103
usort($navItems, 'sortNavigationItems');
104
$nav->assign('navigationItems', $navItems);
105
106
$contentItems = array();
107
108
function renderScript($appName, $scriptName) {
109
	$content = '';
110
	$appPath = OC_App::getAppPath($appName);
111
	$scriptPath = $appPath . '/' . $scriptName;
112
	if (file_exists($scriptPath)) {
113
		// TODO: sanitize path / script name ?
114
		ob_start();
115
		include $scriptPath;
116
		$content = ob_get_contents();
117
		@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...
118
	}
119
	return $content;
120
}
121
122
// render the container content for every navigation item
123
foreach ($navItems as $item) {
124
	$content = '';
125
	if (isset($item['script'])) {
126
		$content = renderScript($item['appname'], $item['script']);
127
	}
128
	$contentItem = array();
129
	$contentItem['id'] = $item['id'];
130
	$contentItem['content'] = $content;
131
	$contentItems[] = $contentItem;
132
}
133
134
OCP\Util::addscript('files', 'fileactions');
135
OCP\Util::addscript('files', 'files');
136
OCP\Util::addscript('files', 'navigation');
137
OCP\Util::addscript('files', 'keyboardshortcuts');
138
$tmpl = new OCP\Template('files', 'index', 'user');
139
$tmpl->assign('usedSpacePercent', (int)$storageInfo['relative']);
140
$tmpl->assign('owner', $storageInfo['owner']);
141
$tmpl->assign('ownerDisplayName', $storageInfo['ownerDisplayName']);
142
$tmpl->assign('isPublic', false);
143
$tmpl->assign("mailNotificationEnabled", $config->getAppValue('core', 'shareapi_allow_mail_notification', 'no'));
144
$tmpl->assign("mailPublicNotificationEnabled", $config->getAppValue('core', 'shareapi_allow_public_notification', 'no'));
145
$tmpl->assign("allowShareWithLink", $config->getAppValue('core', 'shareapi_allow_links', 'yes'));
146
$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...
147
$tmpl->assign('appContents', $contentItems);
148
149
$tmpl->printPage();
150