Completed
Push — stable8 ( f0fddd...5d5dda )
by
unknown
27:14
created

index.php ➔ renderScript()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 2
eloc 10
nc 2
nop 2
dl 0
loc 13
rs 9.4285
1
<?php
2
3
/**
4
 * ownCloud - ajax frontend
5
 *
6
 * @author Robin Appelman
7
 * @copyright 2010 Robin Appelman [email protected]
8
 *
9
 * This library is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
11
 * License as published by the Free Software Foundation; either
12
 * version 3 of the License, or any later version.
13
 *
14
 * This library is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public
20
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
use OCA\Files\Appinfo\Application;
24
25
// Check if we are a user
26
OCP\User::checkLoggedIn();
27
28
// Load the files we need
29
OCP\Util::addStyle('files', 'files');
30
OCP\Util::addStyle('files', 'upload');
31
OCP\Util::addStyle('files', 'mobile');
32
OCP\Util::addscript('files', 'app');
33
OCP\Util::addscript('files', 'file-upload');
34
OCP\Util::addscript('files', 'jquery.iframe-transport');
35
OCP\Util::addscript('files', 'jquery.fileupload');
36
OCP\Util::addscript('files', 'jquery-visibility');
37
OCP\Util::addscript('files', 'filesummary');
38
OCP\Util::addscript('files', 'breadcrumb');
39
OCP\Util::addscript('files', 'filelist');
40
OCP\Util::addscript('files', 'search');
41
42
\OCP\Util::addScript('files', 'favoritesfilelist');
43
\OCP\Util::addScript('files', 'tagsplugin');
44
\OCP\Util::addScript('files', 'favoritesplugin');
45
46
\OC_Util::addVendorScript('core', 'handlebars/handlebars');
47
48
OCP\App::setActiveNavigationEntry('files_index');
49
50
$l = \OC::$server->getL10N('files');
51
52
$isIE8 = false;
53
preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $matches);
54
if (count($matches) > 0 && $matches[1] <= 9) {
55
	$isIE8 = true;
56
}
57
58
// if IE8 and "?dir=path&view=someview" was specified, reformat the URL to use a hash like "#?dir=path&view=someview"
59
if ($isIE8 && (isset($_GET['dir']) || isset($_GET['view']))) {
60
	$hash = '#?';
61
	$dir = isset($_GET['dir']) ? $_GET['dir'] : '/';
62
	$view = isset($_GET['view']) ? $_GET['view'] : 'files';
63
	$hash = '#?dir=' . \OCP\Util::encodePath($dir);
64
	if ($view !== 'files') {
65
		$hash .= '&view=' . urlencode($view);
66
	}
67
	header('Location: ' . OCP\Util::linkTo('files', 'index.php') . $hash);
68
	exit();
69
}
70
71
$user = OC_User::getUser();
72
73
$config = \OC::$server->getConfig();
74
75
// mostly for the home storage's free space
76
$dirInfo = \OC\Files\Filesystem::getFileInfo('/', false);
77
$storageInfo=OC_Helper::getStorageInfo('/', $dirInfo);
78
// if the encryption app is disabled, than everything is fine (INIT_SUCCESSFUL status code)
79
$encryptionInitStatus = 2;
80
if (OC_App::isEnabled('files_encryption')) {
81
	$session = new \OCA\Files_Encryption\Session(new \OC\Files\View('/'));
82
	$encryptionInitStatus = $session->getInitialized();
83
}
84
85
$nav = new OCP\Template('files', 'appnavigation', '');
86
87
function sortNavigationItems($item1, $item2) {
88
	return $item1['order'] - $item2['order'];
89
}
90
91
\OCA\Files\App::getNavigationManager()->add(
92
	array(
93
		'id' => 'favorites',
94
		'appname' => 'files',
95
		'script' => 'simplelist.php',
96
		'order' => 5,
97
		'name' => $l->t('Favorites')
98
	)
99
);
100
101
$navItems = \OCA\Files\App::getNavigationManager()->getAll();
102
usort($navItems, 'sortNavigationItems');
103
$nav->assign('navigationItems', $navItems);
104
105
$contentItems = array();
106
107
function renderScript($appName, $scriptName) {
108
	$content = '';
109
	$appPath = OC_App::getAppPath($appName);
110
	$scriptPath = $appPath . '/' . $scriptName;
111
	if (file_exists($scriptPath)) {
112
		// TODO: sanitize path / script name ?
113
		ob_start();
114
		include $scriptPath;
115
		$content = ob_get_contents();
116
		@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...
117
	}
118
	return $content;
119
}
120
121
// render the container content for every navigation item
122
foreach ($navItems as $item) {
123
	$content = '';
124
	if (isset($item['script'])) {
125
		$content = renderScript($item['appname'], $item['script']);
126
	}
127
	$contentItem = array();
128
	$contentItem['id'] = $item['id'];
129
	$contentItem['content'] = $content;
130
	$contentItems[] = $contentItem;
131
}
132
133
OCP\Util::addscript('files', 'fileactions');
134
OCP\Util::addscript('files', 'files');
135
OCP\Util::addscript('files', 'navigation');
136
OCP\Util::addscript('files', 'keyboardshortcuts');
137
$tmpl = new OCP\Template('files', 'index', 'user');
138
$tmpl->assign('usedSpacePercent', (int)$storageInfo['relative']);
139
$tmpl->assign('isPublic', false);
140
$tmpl->assign("encryptedFiles", \OCP\Util::encryptedFiles());
141
$tmpl->assign("mailNotificationEnabled", $config->getAppValue('core', 'shareapi_allow_mail_notification', 'no'));
142
$tmpl->assign("mailPublicNotificationEnabled", $config->getAppValue('core', 'shareapi_allow_public_notification', 'no'));
143
$tmpl->assign("allowShareWithLink", $config->getAppValue('core', 'shareapi_allow_links', 'yes'));
144
$tmpl->assign("encryptionInitStatus", $encryptionInitStatus);
145
$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...
146
$tmpl->assign('appContents', $contentItems);
147
148
$tmpl->printPage();
149