mirror of
https://git.sekbaer.de/Friendica/friendica.git
synced 2025-06-17 04:15:15 +02:00
Merge pull request #8315 from MrPetovan/task/8310-improve-manifest
Update manifest output with config/theme info
This commit is contained in:
commit
b6b567fc97
8 changed files with 212 additions and 22 deletions
|
@ -257,4 +257,56 @@ class Theme
|
|||
|
||||
return 'view/theme/' . $theme . '/style.pcss' . (!empty($query_params) ? '?' . http_build_query($query_params) : '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the background color of the provided theme if available.
|
||||
*
|
||||
* @param string $theme
|
||||
* @param int|null $uid Current logged-in user id
|
||||
* @return string|null
|
||||
*/
|
||||
public static function getBackgroundColor(string $theme, $uid = null)
|
||||
{
|
||||
$theme = Strings::sanitizeFilePathItem($theme);
|
||||
|
||||
$return = null;
|
||||
|
||||
// silently fail if theme was removed or if $theme is funky
|
||||
if (file_exists("view/theme/$theme/theme.php")) {
|
||||
include_once "view/theme/$theme/theme.php";
|
||||
|
||||
$func = "{$theme}_get_background_color";
|
||||
if (function_exists($func)) {
|
||||
$return = $func($uid);
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the theme color of the provided theme if available.
|
||||
*
|
||||
* @param string $theme
|
||||
* @param int|null $uid Current logged-in user id
|
||||
* @return string|null
|
||||
*/
|
||||
public static function getThemeColor(string $theme, int $uid = null)
|
||||
{
|
||||
$theme = Strings::sanitizeFilePathItem($theme);
|
||||
|
||||
$return = null;
|
||||
|
||||
// silently fail if theme was removed or if $theme is funky
|
||||
if (file_exists("view/theme/$theme/theme.php")) {
|
||||
include_once "view/theme/$theme/theme.php";
|
||||
|
||||
$func = "{$theme}_get_theme_color";
|
||||
if (function_exists($func)) {
|
||||
$return = $func($uid);
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
namespace Friendica\Module;
|
||||
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core;
|
||||
use Friendica\DI;
|
||||
|
||||
class Manifest extends BaseModule
|
||||
|
@ -31,22 +31,33 @@ class Manifest extends BaseModule
|
|||
{
|
||||
$config = DI::config();
|
||||
|
||||
$tpl = Renderer::getMarkupTemplate('manifest.tpl');
|
||||
$touch_icon = $config->get('system', 'touch_icon') ?: 'images/friendica-128.png';
|
||||
|
||||
header('Content-type: application/manifest+json');
|
||||
$theme = DI::config()->get('system', 'theme');
|
||||
|
||||
$touch_icon = $config->get('system', 'touch_icon', 'images/friendica-128.png');
|
||||
if ($touch_icon == '') {
|
||||
$touch_icon = 'images/friendica-128.png';
|
||||
$manifest = [
|
||||
'name' => $config->get('config', 'sitename', 'Friendica'),
|
||||
'start_url' => DI::baseUrl()->get(),
|
||||
'display' => 'standalone',
|
||||
'description' => $config->get('config', 'info', DI::l10n()->t('A Decentralized Social Network')),
|
||||
'short_name' => 'Friendica',
|
||||
'icons' => [
|
||||
[
|
||||
'src' => DI::baseUrl()->get() . '/' . $touch_icon,
|
||||
'sizes' => '128x128',
|
||||
'type' => 'image/png',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
if ($background_color = Core\Theme::getBackgroundColor($theme)) {
|
||||
$manifest['background_color'] = $background_color;
|
||||
}
|
||||
|
||||
$output = Renderer::replaceMacros($tpl, [
|
||||
'$touch_icon' => $touch_icon,
|
||||
'$title' => $config->get('config', 'sitename', 'Friendica'),
|
||||
]);
|
||||
if ($theme_color = Core\Theme::getThemeColor($theme)) {
|
||||
$manifest['theme_color'] = $theme_color;
|
||||
}
|
||||
|
||||
echo $output;
|
||||
|
||||
exit();
|
||||
Core\System::jsonExit($manifest, 'application/manifest+json');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue