Merge pull request #12019 from nextcloud/icons-svg-api-fixes
Move svg api endpoint
This commit is contained in:
commit
c05e8acdb1
|
@ -258,7 +258,7 @@ class AccessibilityController extends Controller {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function invertSvgIconsColor(string $css) {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -47,9 +47,9 @@
|
||||||
@function icon-color-path($icon, $dir, $color, $version: 1, $core: false) {
|
@function icon-color-path($icon, $dir, $color, $version: 1, $core: false) {
|
||||||
$color: remove-hash-from-color($color);
|
$color: remove-hash-from-color($color);
|
||||||
@if $core {
|
@if $core {
|
||||||
@return '#{$webroot}/svg/core/#{$dir}/#{$icon}/#{$color}?v=#{$version}';
|
@return '#{$webroot}/svg/core/#{$dir}/#{$icon}?color=#{$color}&v=#{$version}';
|
||||||
} @else {
|
} @else {
|
||||||
@return '#{$webroot}/svg/#{$dir}/#{$icon}/#{$color}?v=#{$version}';
|
@return '#{$webroot}/svg/#{$dir}/#{$icon}?color=#{$color}&v=#{$version}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,9 +61,9 @@ $application->registerRoutes($this, [
|
||||||
['name' => 'OCJS#getConfig', 'url' => '/core/js/oc.js', 'verb' => 'GET'],
|
['name' => 'OCJS#getConfig', 'url' => '/core/js/oc.js', 'verb' => 'GET'],
|
||||||
['name' => 'Preview#getPreviewByFileId', 'url' => '/core/preview', 'verb' => 'GET'],
|
['name' => 'Preview#getPreviewByFileId', 'url' => '/core/preview', 'verb' => 'GET'],
|
||||||
['name' => 'Preview#getPreview', 'url' => '/core/preview.png', 'verb' => 'GET'],
|
['name' => 'Preview#getPreview', 'url' => '/core/preview.png', 'verb' => 'GET'],
|
||||||
['name' => 'Svg#getSvgFromCore', 'url' => '/svg/core/{folder}/{fileName}/{color}', 'verb' => 'GET'],
|
['name' => 'Svg#getSvgFromCore', 'url' => '/svg/core/{folder}/{fileName}', 'verb' => 'GET'],
|
||||||
['name' => 'Svg#getSvgFromSettings', 'url' => '/svg/settings/{folder}/{fileName}/{color}', 'verb' => 'GET'],
|
['name' => 'Svg#getSvgFromSettings', 'url' => '/svg/settings/{folder}/{fileName}', 'verb' => 'GET'],
|
||||||
['name' => 'Svg#getSvgFromApp', 'url' => '/svg/{app}/{fileName}/{color}', 'verb' => 'GET'],
|
['name' => 'Svg#getSvgFromApp', 'url' => '/svg/{app}/{fileName}', 'verb' => 'GET'],
|
||||||
['name' => 'Css#getCss', 'url' => '/css/{appName}/{fileName}', 'verb' => 'GET'],
|
['name' => 'Css#getCss', 'url' => '/css/{appName}/{fileName}', 'verb' => 'GET'],
|
||||||
['name' => 'Js#getJs', 'url' => '/js/{appName}/{fileName}', 'verb' => 'GET'],
|
['name' => 'Js#getJs', 'url' => '/js/{appName}/{fileName}', 'verb' => 'GET'],
|
||||||
['name' => 'contactsMenu#index', 'url' => '/contactsmenu/contacts', 'verb' => 'POST'],
|
['name' => 'contactsMenu#index', 'url' => '/contactsmenu/contacts', 'verb' => 'POST'],
|
||||||
|
|
|
@ -47,7 +47,7 @@ class IconsCacher {
|
||||||
protected $urlGenerator;
|
protected $urlGenerator;
|
||||||
|
|
||||||
/** @var string */
|
/** @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 */
|
/** @var string */
|
||||||
private $fileName = 'icons-vars.css';
|
private $fileName = 'icons-vars.css';
|
||||||
|
@ -112,7 +112,10 @@ class IconsCacher {
|
||||||
foreach ($icons as $icon => $url) {
|
foreach ($icons as $icon => $url) {
|
||||||
$list .= "--$icon: url('$url');";
|
$list .= "--$icon: url('$url');";
|
||||||
list($location,$color) = $this->parseUrl($url);
|
list($location,$color) = $this->parseUrl($url);
|
||||||
|
$svg = false;
|
||||||
|
if ($location !== '') {
|
||||||
$svg = file_get_contents($location);
|
$svg = file_get_contents($location);
|
||||||
|
}
|
||||||
if ($svg === false) {
|
if ($svg === false) {
|
||||||
$this->logger->debug('Failed to get icon file ' . $location);
|
$this->logger->debug('Failed to get icon file ' . $location);
|
||||||
$data .= "--$icon: url('$url');";
|
$data .= "--$icon: url('$url');";
|
||||||
|
@ -142,22 +145,21 @@ class IconsCacher {
|
||||||
$base = $this->getRoutePrefix() . '/svg/';
|
$base = $this->getRoutePrefix() . '/svg/';
|
||||||
$cleanUrl = \substr($url, \strlen($base));
|
$cleanUrl = \substr($url, \strlen($base));
|
||||||
if (\strpos($url, $base . 'core') === 0) {
|
if (\strpos($url, $base . 'core') === 0) {
|
||||||
$cleanUrl = \substr($cleanUrl, \strlen('core'), \strpos($cleanUrl, '?')-\strlen('core'));
|
$cleanUrl = \substr($cleanUrl, \strlen('core'));
|
||||||
$parts = \explode('/', $cleanUrl);
|
if (\preg_match('/\/([a-zA-Z0-9-_\~\/\.\=\:\;\+\,]+)\?color=([0-9a-fA-F]{3,6})/', $cleanUrl, $matches)) {
|
||||||
$color = \array_pop($parts);
|
list(,$cleanUrl,$color) = $matches;
|
||||||
$cleanUrl = \implode('/', $parts);
|
|
||||||
$location = \OC::$SERVERROOT . '/core/img/' . $cleanUrl . '.svg';
|
$location = \OC::$SERVERROOT . '/core/img/' . $cleanUrl . '.svg';
|
||||||
|
}
|
||||||
} elseif (\strpos($url, $base) === 0) {
|
} elseif (\strpos($url, $base) === 0) {
|
||||||
$cleanUrl = \substr($cleanUrl, 0, \strpos($cleanUrl, '?'));
|
if(\preg_match('/([A-z0-9\_\-]+)\/([a-zA-Z0-9-_\~\/\.\=\:\;\+\,]+)\?color=([0-9a-fA-F]{3,6})/', $cleanUrl, $matches)) {
|
||||||
$parts = \explode('/', $cleanUrl);
|
list(,$app,$cleanUrl, $color) = $matches;
|
||||||
$app = \array_shift($parts);
|
|
||||||
$color = \array_pop($parts);
|
|
||||||
$cleanUrl = \implode('/', $parts);
|
|
||||||
$location = \OC_App::getAppPath($app) . '/img/' . $cleanUrl . '.svg';
|
$location = \OC_App::getAppPath($app) . '/img/' . $cleanUrl . '.svg';
|
||||||
if ($app === 'settings') {
|
if ($app === 'settings') {
|
||||||
$location = \OC::$SERVERROOT . '/settings/img/' . $cleanUrl . '.svg';
|
$location = \OC::$SERVERROOT . '/settings/img/' . $cleanUrl . '.svg';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
return [
|
return [
|
||||||
$location,
|
$location,
|
||||||
$color
|
$color
|
||||||
|
|
|
@ -104,7 +104,7 @@ class IconsCacherTest extends \Test\TestCase {
|
||||||
public function testSetIconsFromValidCss() {
|
public function testSetIconsFromValidCss() {
|
||||||
$css = "
|
$css = "
|
||||||
icon.test {
|
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);
|
background-image: var(--icon-test);
|
||||||
}
|
}
|
||||||
";
|
";
|
||||||
|
@ -127,7 +127,7 @@ class IconsCacherTest extends \Test\TestCase {
|
||||||
public function testSetIconsFromValidCssMultipleTimes() {
|
public function testSetIconsFromValidCssMultipleTimes() {
|
||||||
$css = "
|
$css = "
|
||||||
icon.test {
|
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);
|
background-image: var(--icon-test);
|
||||||
}
|
}
|
||||||
";
|
";
|
||||||
|
|
Loading…
Reference in New Issue