Merge pull request #12019 from nextcloud/icons-svg-api-fixes

Move svg api endpoint
This commit is contained in:
John Molakvoæ 2018-10-29 15:45:45 +01:00 committed by GitHub
commit c05e8acdb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 24 deletions

View File

@ -258,7 +258,7 @@ class AccessibilityController extends Controller {
* @return string
*/
private function invertSvgIconsColor(string $css) {
return str_replace(['/000', '/fff', '/***'], ['/***', '/000', '/fff'], $css);
return str_replace(['color=000', 'color=fff', 'color=***'], ['color=***', 'color=000', 'color=fff'], $css);
}
/**

View File

@ -47,9 +47,9 @@
@function icon-color-path($icon, $dir, $color, $version: 1, $core: false) {
$color: remove-hash-from-color($color);
@if $core {
@return '#{$webroot}/svg/core/#{$dir}/#{$icon}/#{$color}?v=#{$version}';
@return '#{$webroot}/svg/core/#{$dir}/#{$icon}?color=#{$color}&v=#{$version}';
} @else {
@return '#{$webroot}/svg/#{$dir}/#{$icon}/#{$color}?v=#{$version}';
@return '#{$webroot}/svg/#{$dir}/#{$icon}?color=#{$color}&v=#{$version}';
}
}

View File

@ -61,9 +61,9 @@ $application->registerRoutes($this, [
['name' => 'OCJS#getConfig', 'url' => '/core/js/oc.js', 'verb' => 'GET'],
['name' => 'Preview#getPreviewByFileId', 'url' => '/core/preview', 'verb' => 'GET'],
['name' => 'Preview#getPreview', 'url' => '/core/preview.png', 'verb' => 'GET'],
['name' => 'Svg#getSvgFromCore', 'url' => '/svg/core/{folder}/{fileName}/{color}', 'verb' => 'GET'],
['name' => 'Svg#getSvgFromSettings', 'url' => '/svg/settings/{folder}/{fileName}/{color}', 'verb' => 'GET'],
['name' => 'Svg#getSvgFromApp', 'url' => '/svg/{app}/{fileName}/{color}', 'verb' => 'GET'],
['name' => 'Svg#getSvgFromCore', 'url' => '/svg/core/{folder}/{fileName}', 'verb' => 'GET'],
['name' => 'Svg#getSvgFromSettings', 'url' => '/svg/settings/{folder}/{fileName}', 'verb' => 'GET'],
['name' => 'Svg#getSvgFromApp', 'url' => '/svg/{app}/{fileName}', 'verb' => 'GET'],
['name' => 'Css#getCss', 'url' => '/css/{appName}/{fileName}', 'verb' => 'GET'],
['name' => 'Js#getJs', 'url' => '/js/{appName}/{fileName}', 'verb' => 'GET'],
['name' => 'contactsMenu#index', 'url' => '/contactsmenu/contacts', 'verb' => 'POST'],

View File

@ -47,7 +47,7 @@ class IconsCacher {
protected $urlGenerator;
/** @var string */
private $iconVarRE = '/--(icon-[a-zA-Z0-9-]+):\s?url\(["\']?([a-zA-Z0-9-_\~\/\.\?\=\:\;\+\,]+)[^;]+;/m';
private $iconVarRE = '/--(icon-[a-zA-Z0-9-]+):\s?url\(["\']?([a-zA-Z0-9-_\~\/\.\?\&\=\:\;\+\,]+)[^;]+;/m';
/** @var string */
private $fileName = 'icons-vars.css';
@ -112,7 +112,10 @@ class IconsCacher {
foreach ($icons as $icon => $url) {
$list .= "--$icon: url('$url');";
list($location,$color) = $this->parseUrl($url);
$svg = file_get_contents($location);
$svg = false;
if ($location !== '') {
$svg = file_get_contents($location);
}
if ($svg === false) {
$this->logger->debug('Failed to get icon file ' . $location);
$data .= "--$icon: url('$url');";
@ -142,21 +145,20 @@ class IconsCacher {
$base = $this->getRoutePrefix() . '/svg/';
$cleanUrl = \substr($url, \strlen($base));
if (\strpos($url, $base . 'core') === 0) {
$cleanUrl = \substr($cleanUrl, \strlen('core'), \strpos($cleanUrl, '?')-\strlen('core'));
$parts = \explode('/', $cleanUrl);
$color = \array_pop($parts);
$cleanUrl = \implode('/', $parts);
$location = \OC::$SERVERROOT . '/core/img/' . $cleanUrl . '.svg';
} elseif (\strpos($url, $base) === 0) {
$cleanUrl = \substr($cleanUrl, 0, \strpos($cleanUrl, '?'));
$parts = \explode('/', $cleanUrl);
$app = \array_shift($parts);
$color = \array_pop($parts);
$cleanUrl = \implode('/', $parts);
$location = \OC_App::getAppPath($app) . '/img/' . $cleanUrl . '.svg';
if ($app === 'settings') {
$location = \OC::$SERVERROOT . '/settings/img/' . $cleanUrl . '.svg';
$cleanUrl = \substr($cleanUrl, \strlen('core'));
if (\preg_match('/\/([a-zA-Z0-9-_\~\/\.\=\:\;\+\,]+)\?color=([0-9a-fA-F]{3,6})/', $cleanUrl, $matches)) {
list(,$cleanUrl,$color) = $matches;
$location = \OC::$SERVERROOT . '/core/img/' . $cleanUrl . '.svg';
}
} elseif (\strpos($url, $base) === 0) {
if(\preg_match('/([A-z0-9\_\-]+)\/([a-zA-Z0-9-_\~\/\.\=\:\;\+\,]+)\?color=([0-9a-fA-F]{3,6})/', $cleanUrl, $matches)) {
list(,$app,$cleanUrl, $color) = $matches;
$location = \OC_App::getAppPath($app) . '/img/' . $cleanUrl . '.svg';
if ($app === 'settings') {
$location = \OC::$SERVERROOT . '/settings/img/' . $cleanUrl . '.svg';
}
}
}
return [
$location,

View File

@ -104,7 +104,7 @@ class IconsCacherTest extends \Test\TestCase {
public function testSetIconsFromValidCss() {
$css = "
icon.test {
--icon-test: url('/index.php/svg/core/actions/add/000?v=1');
--icon-test: url('/index.php/svg/core/actions/add?color=000&v=1');
background-image: var(--icon-test);
}
";
@ -127,7 +127,7 @@ class IconsCacherTest extends \Test\TestCase {
public function testSetIconsFromValidCssMultipleTimes() {
$css = "
icon.test {
--icon-test: url('/index.php/svg/core/actions/add/000?v=1');
--icon-test: url('/index.php/svg/core/actions/add?color=000&v=1');
background-image: var(--icon-test);
}
";