mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 01:36:00 -04:00
Integrated favicon handler with correct files & actions
Format does not look 100% correct though, won't show in Firefox/gimp.
This commit is contained in:
parent
420f89af99
commit
1a189640f1
@ -51,6 +51,8 @@ class AppSettingsStore
|
|||||||
$this->destroyExistingSettingImage('app-icon-' . $size);
|
$this->destroyExistingSettingImage('app-icon-' . $size);
|
||||||
setting()->remove('app-icon-' . $size);
|
setting()->remove('app-icon-' . $size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->faviconHandler->restoreOriginal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,19 +17,32 @@ class FaviconHandler
|
|||||||
*/
|
*/
|
||||||
public function saveForUploadedImage(UploadedFile $file): void
|
public function saveForUploadedImage(UploadedFile $file): void
|
||||||
{
|
{
|
||||||
|
$targetPath = public_path('favicon.ico');
|
||||||
|
if (!is_writeable($targetPath)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$imageData = file_get_contents($file->getRealPath());
|
$imageData = file_get_contents($file->getRealPath());
|
||||||
$image = $this->imageTool->make($imageData);
|
$image = $this->imageTool->make($imageData);
|
||||||
$image->resize(32, 32);
|
$image->resize(32, 32);
|
||||||
$bmpData = $image->encode('bmp');
|
$bmpData = $image->encode('bmp');
|
||||||
$icoData = $this->bmpToIco($bmpData, 32, 32);
|
$icoData = $this->bmpToIco($bmpData, 32, 32);
|
||||||
|
|
||||||
// TODO - Below are test paths
|
file_put_contents($targetPath, $icoData);
|
||||||
file_put_contents(public_path('uploads/test.ico'), $icoData);
|
}
|
||||||
file_put_contents(public_path('uploads/test.bmp'), $bmpData);
|
|
||||||
|
|
||||||
// TODO - Permission check for icon overwrite
|
/**
|
||||||
// TODO - Write to correct location
|
* Restore the original favicon image.
|
||||||
// TODO - Handle deletion and restore of original icon on user icon clear
|
*/
|
||||||
|
public function restoreOriginal(): void
|
||||||
|
{
|
||||||
|
$targetPath = public_path('favicon.ico');
|
||||||
|
$original = public_path('icon.ico');
|
||||||
|
if (!is_writeable($targetPath)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
copy($original, $targetPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 3.1 KiB |
BIN
public/icon.ico
Normal file
BIN
public/icon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
@ -52,6 +52,10 @@ class SettingsTest extends TestCase
|
|||||||
$this->assertFalse(setting()->get('app-icon-128'));
|
$this->assertFalse(setting()->get('app-icon-128'));
|
||||||
$this->assertFalse(setting()->get('app-icon-64'));
|
$this->assertFalse(setting()->get('app-icon-64'));
|
||||||
$this->assertFalse(setting()->get('app-icon-32'));
|
$this->assertFalse(setting()->get('app-icon-32'));
|
||||||
|
$this->assertEquals(
|
||||||
|
file_get_contents(public_path('icon.ico')),
|
||||||
|
file_get_contents(public_path('favicon.ico')),
|
||||||
|
);
|
||||||
|
|
||||||
$prevFileCount = count(glob(dirname($expectedPath) . DIRECTORY_SEPARATOR . '*.png'));
|
$prevFileCount = count(glob(dirname($expectedPath) . DIRECTORY_SEPARATOR . '*.png'));
|
||||||
|
|
||||||
@ -71,6 +75,11 @@ class SettingsTest extends TestCase
|
|||||||
$resp = $this->get('/');
|
$resp = $this->get('/');
|
||||||
$this->withHtml($resp)->assertElementCount('link[sizes][href*="my-app-icon"]', 6);
|
$this->withHtml($resp)->assertElementCount('link[sizes][href*="my-app-icon"]', 6);
|
||||||
|
|
||||||
|
$this->assertNotEquals(
|
||||||
|
file_get_contents(public_path('icon.ico')),
|
||||||
|
file_get_contents(public_path('favicon.ico')),
|
||||||
|
);
|
||||||
|
|
||||||
$reset = $this->post('/settings/customization', ['app_icon_reset' => 'true']);
|
$reset = $this->post('/settings/customization', ['app_icon_reset' => 'true']);
|
||||||
$reset->assertRedirect('/settings/customization');
|
$reset->assertRedirect('/settings/customization');
|
||||||
|
|
||||||
@ -81,5 +90,10 @@ class SettingsTest extends TestCase
|
|||||||
$this->assertFalse(setting()->get('app-icon-128'));
|
$this->assertFalse(setting()->get('app-icon-128'));
|
||||||
$this->assertFalse(setting()->get('app-icon-64'));
|
$this->assertFalse(setting()->get('app-icon-64'));
|
||||||
$this->assertFalse(setting()->get('app-icon-32'));
|
$this->assertFalse(setting()->get('app-icon-32'));
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
file_get_contents(public_path('icon.ico')),
|
||||||
|
file_get_contents(public_path('favicon.ico')),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user