Skip to content

Commit e13d11a

Browse files
committed
[stable10] Allow non hardcoded icons for apps
This change helps users to provide their own custom icons for the apps which work with ownCloud. Signed-off-by: Sujith H <sharidasan@owncloud.com>
1 parent cbd3bcc commit e13d11a

3 files changed

Lines changed: 48 additions & 31 deletions

File tree

lib/private/Settings/SettingsManager.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ private function getBuiltInSections($type) {
205205
new Section('workflow', $this->l->t('Workflows & Tags'), 85, 'workflows'),
206206
new Section('sharing', $this->l->t('Sharing'), 80, 'share'),
207207
new Section('search', $this->l->t('Search'), 75, 'search'),
208-
new Section('updates', $this->l->t('Updates'), 20, 'update'),
209208
new Section('help', $this->l->t('Help & Tips'), -5, 'info'),
210209
new Section('additional', $this->l->t('Additional'), -10, 'more'),
211210
];

settings/Controller/SettingsPageController.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,30 @@ public function getAdmin($sectionid='general') {
106106
return $response;
107107
}
108108

109+
/**
110+
* Gets the icon for the settings panel. The idea is
111+
* to get either URL or the icon name ( for backward
112+
* compatibility ). The icons returned will be svg
113+
* format and no other formats are supported.
114+
*
115+
* @param \OCP\Settings\ISection $section
116+
* @return string
117+
*/
118+
119+
protected function getIconForSettingsPanel($section) {
120+
121+
$icon = $section->getIconName() . '.svg';
122+
$appPath = \OC_App::getAppPath($section->getID());
123+
124+
if (file_exists($appPath . '/img/' . $icon)) {
125+
$icon = $this->urlGenerator->imagePath($section->getID(), $icon);
126+
} else {
127+
$icon = $section->getIconName();
128+
}
129+
130+
return $icon;
131+
}
132+
109133
/**
110134
* Gets an array used to generate the navigation in the UI
111135
* @param array $sections array of ISections
@@ -117,6 +141,9 @@ protected function getNavigation($sections, $currentSectionID, $type) {
117141
$nav = [];
118142
// Iterate through sections and get id, name and see if currently active
119143
foreach($sections as $section) {
144+
145+
$icon = $this->getIconForSettingsPanel($section);
146+
120147
$nav[] = [
121148
'id' => $section->getID(),
122149
'link' => $this->urlGenerator->linkToRoute(
@@ -125,7 +152,7 @@ protected function getNavigation($sections, $currentSectionID, $type) {
125152
),
126153
'name' => ucfirst($section->getName()),
127154
'active' => $section->getID() === $currentSectionID,
128-
'icon' => $section->getIconName()
155+
'icon' => $icon
129156
];
130157
}
131158
return $nav;

settings/templates/settingsPage.php

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,28 @@
2121
<div id="app-navigation">
2222
<ul class="with-icon">
2323
<li class="divider"><?php p($l->t('Personal')); ?></li>
24-
<?php foreach($_['personalNav'] as $item) {
25-
$active = $item['active'] ? ' active ' : '';
26-
print_unescaped(
27-
sprintf(
28-
"<li><a class=\"svg %s %s\" href='%s'>%s</a></li>",
29-
$active,
30-
'icon-'.\OCP\Util::sanitizeHTML($item['icon']),
31-
\OCP\Util::sanitizeHTML($item['link']),
32-
\OCP\Util::sanitizeHTML($item['name'])
33-
)
34-
);
35-
}
36-
if(!empty($_['adminNav'])) { ?>
24+
<?php foreach($_['personalNav'] as $item): ?>
25+
<li>
26+
<?php if (strpos($item['icon'], '/', 1) !== false): ?>
27+
<a class="svg <?php $item['active'] ? p(' active ') : p('') ?>" style="background-image: url(<?php p($item['icon']) ?>)" href='<?php p($item['link']); ?>'><?php p($item['name']) ?></a>
28+
<?php else: ?>
29+
<a class="svg <?php $item['active'] ? p(' active ') : p('') ?> icon-<?php p($item['icon']) ?>" href='<?php p($item['link']); ?>'><?php p($item['name']) ?></a>
30+
<?php endif; ?>
31+
</li>
32+
<?php endforeach; ?>
3733

34+
<?php if (!empty($_['adminNav'])): ?>
3835
<li class="divider"><?php p($l->t('Admin')); ?></li>
39-
<?php
40-
41-
foreach ($_['adminNav'] as $item) {
42-
$active = $item['active'] ? ' active ' : '';
43-
print_unescaped(
44-
sprintf(
45-
"<li><a class=\"svg %s %s\" href='%s'>%s</a></li>",
46-
$active,
47-
'icon-'.\OCP\Util::sanitizeHTML($item['icon']),
48-
\OCP\Util::sanitizeHTML($item['link']),
49-
\OCP\Util::sanitizeHTML($item['name'])
50-
)
51-
);
52-
}
53-
}
54-
?>
36+
<?php foreach($_['adminNav'] as $item): ?>
37+
<li>
38+
<?php if (strpos($item['icon'], '/', 1) !== false): ?>
39+
<a class="svg <?php $item['active'] ? p(' active ') : p('') ?>" style="background-image: url(<?php p($item['icon']) ?>)" href='<?php p($item['link']); ?>'><?php p($item['name']) ?></a>
40+
<?php else: ?>
41+
<a class="svg <?php $item['active'] ? p(' active ') : p('') ?> icon-<?php p($item['icon']) ?>" href='<?php p($item['link']); ?>'><?php p($item['name']) ?></a>
42+
<?php endif; ?>
43+
</li>
44+
<?php endforeach; ?>
45+
<?php endif; ?>
5546
</ul>
5647
</div>
5748
<div id="app-content">

0 commit comments

Comments
 (0)