From 092f4acb74145ae88b39debcd84d9b5b799b997b Mon Sep 17 00:00:00 2001 From: Nikolai Shcherbin Date: Tue, 12 Sep 2023 06:14:52 +0300 Subject: [PATCH] Added option to show logo image on the topbar --- README.md | 1 + .../{SettingsAction.php => CoverAction.php} | 2 +- classes/wZm/ElggTheme/Actions/LogoAction.php | 38 ++++++++++++++++++ classes/wZm/ElggTheme/Menus/SettingsManu.php | 16 ++++++++ elgg-plugin.php | 11 +++-- languages/en.php | 9 +++++ views/default/admin/elgg_theme/logo.php | 5 +++ views/default/forms/admin/elgg_theme/logo.php | 30 ++++++++++++++ views/default/graphics/logo.png | Bin 0 -> 1942 bytes views/default/page/elements/header_logo.php | 31 ++++++++++++++ views/default/plugins/elgg_theme/settings.php | 9 +++++ 11 files changed, 148 insertions(+), 4 deletions(-) rename classes/wZm/ElggTheme/Actions/{SettingsAction.php => CoverAction.php} (97%) create mode 100644 classes/wZm/ElggTheme/Actions/LogoAction.php create mode 100644 views/default/admin/elgg_theme/logo.php create mode 100644 views/default/forms/admin/elgg_theme/logo.php create mode 100644 views/default/graphics/logo.png create mode 100644 views/default/page/elements/header_logo.php diff --git a/README.md b/README.md index 9954d6b..aa1ddfc 100644 --- a/README.md +++ b/README.md @@ -11,3 +11,4 @@ Based on [Elgg Connect plugin](https://github.com/PerJensen/elgg_connect) * Landing page with cover photo, latest users and groups * Optional sidebar with content on the activity page * New standard icons for groups and users that match the color scheme +* Logo image on the topbar diff --git a/classes/wZm/ElggTheme/Actions/SettingsAction.php b/classes/wZm/ElggTheme/Actions/CoverAction.php similarity index 97% rename from classes/wZm/ElggTheme/Actions/SettingsAction.php rename to classes/wZm/ElggTheme/Actions/CoverAction.php index 9720437..c915ec7 100644 --- a/classes/wZm/ElggTheme/Actions/SettingsAction.php +++ b/classes/wZm/ElggTheme/Actions/CoverAction.php @@ -4,7 +4,7 @@ use Symfony\Component\HttpFoundation\File\UploadedFile; -class SettingsAction { +class CoverAction { public function __invoke(\Elgg\Request $request) { $asset = 'cover'; diff --git a/classes/wZm/ElggTheme/Actions/LogoAction.php b/classes/wZm/ElggTheme/Actions/LogoAction.php new file mode 100644 index 0000000..6509649 --- /dev/null +++ b/classes/wZm/ElggTheme/Actions/LogoAction.php @@ -0,0 +1,38 @@ +isValid()) { + return elgg_error_response(elgg_echo('elgg_theme:settings:cover:invalid')); + } + + $assets_dir = elgg_get_data_path() . '/elgg_theme/'; + + if (!is_dir($assets_dir)) { + mkdir($assets_dir, 0755, true); + } + + $target = elgg_get_data_path() . 'elgg_theme/' . $asset . '.png'; + if (file_exists($target)) { + unlink($target); + } + + try { + $upload->move(elgg_get_data_path() . 'elgg_theme/', $asset . '.png'); + elgg_invalidate_caches(); + elgg_clear_caches(); + } catch (\Exception $ex) { + return false; + } + + return elgg_ok_response('', elgg_echo('elgg_theme:settings:cover:success')); + } +} \ No newline at end of file diff --git a/classes/wZm/ElggTheme/Menus/SettingsManu.php b/classes/wZm/ElggTheme/Menus/SettingsManu.php index cf8d63d..3cc5f14 100644 --- a/classes/wZm/ElggTheme/Menus/SettingsManu.php +++ b/classes/wZm/ElggTheme/Menus/SettingsManu.php @@ -16,6 +16,14 @@ public function __invoke(\Elgg\Event $event) { $menu = $event->getValue(); /* @var $menu \Elgg\Collections\Collection */ + + $menu->add(\ElggMenuItem::factory([ + 'name' => 'elgg_theme:config', + 'text' => elgg_echo('admin:elgg_theme:config'), + 'href' => elgg_normalize_url('admin/plugin_settings/elgg_theme'), + 'parent_name' => 'plugin:settings:elgg_theme', + 'section' => 'plugin_settings', + ])); $menu->add(\ElggMenuItem::factory([ 'name' => 'elgg_theme:cover', @@ -25,6 +33,14 @@ public function __invoke(\Elgg\Event $event) { 'section' => 'plugin_settings', ])); + $menu->add(\ElggMenuItem::factory([ + 'name' => 'elgg_theme:logo', + 'text' => elgg_echo('admin:elgg_theme:logo'), + 'href' => elgg_normalize_url('admin/elgg_theme/logo'), + 'parent_name' => 'plugin:settings:elgg_theme', + 'section' => 'plugin_settings', + ])); + return $menu; } } diff --git a/elgg-plugin.php b/elgg-plugin.php index a267d90..dbf2c6f 100644 --- a/elgg-plugin.php +++ b/elgg-plugin.php @@ -10,7 +10,7 @@ return [ 'plugin' => [ 'name' => 'Elgg Landing Theme', - 'version' => '2.0.0', + 'version' => '2.1.0', 'dependencies' => [ 'activity' => [ 'position' => 'after', @@ -25,9 +25,13 @@ ], 'actions' => [ - //admin 'admin/elgg_theme/cover' => [ - 'controller' => \wZm\ElggTheme\Actions\SettingsAction::class, + 'controller' => \wZm\ElggTheme\Actions\CoverAction::class, + 'access' => 'admin', + ], + + 'admin/elgg_theme/logo' => [ + 'controller' => \wZm\ElggTheme\Actions\LogoAction::class, 'access' => 'admin', ], ], @@ -63,6 +67,7 @@ ], 'settings' => [ + 'topbar_logo_text' => true, 'landing_action' => true, 'display_members' => true, 'display_groups' => false, diff --git a/languages/en.php b/languages/en.php index 3b5948c..59fb6e3 100644 --- a/languages/en.php +++ b/languages/en.php @@ -25,11 +25,20 @@ 'elgg_theme:settings:activity_sidebar:friends' => 'Show friends', 'admin:elgg_theme' => 'Elgg Landing Theme', + 'admin:elgg_theme:config' => 'Settings', + 'admin:elgg_theme:cover' => 'Cover image', 'elgg_theme:settings:cover' => 'Cover image (PNG format)', 'elgg_theme:settings:cover:help' => 'Recommend an image with minimal width 2100px.', 'elgg_theme:settings:cover:success' => 'Cover image has been saved.', 'elgg_theme:settings:cover:invalid' => 'No cover image found.', + 'elgg_theme:settings:topbar_logo_text' => 'Show only site name on the topbar instead of logo image', + 'admin:elgg_theme:logo' => 'Logo image', + 'elgg_theme:settings:logo' => 'Logo image (PNG format)', + 'elgg_theme:settings:logo:help' => "Disable 'Show only site name' option via Elgg Landing Theme settings to display logo image on the topbar. Recommend an image with maximum width 40px.", + 'elgg_theme:settings:logo:success' => 'Logo image has been saved.', + 'elgg_theme:settings:logo:invalid' => 'No logo image found.', + 'index:content' => '

Many sites use the additional plugins for this theme to place the custom modules on this landing page.

Contact with our developers to make beautiful and modern design for your site: lab@wzm.me

', ]; diff --git a/views/default/admin/elgg_theme/logo.php b/views/default/admin/elgg_theme/logo.php new file mode 100644 index 0000000..2f58897 --- /dev/null +++ b/views/default/admin/elgg_theme/logo.php @@ -0,0 +1,5 @@ + 'multipart/form-data' +], []); diff --git a/views/default/forms/admin/elgg_theme/logo.php b/views/default/forms/admin/elgg_theme/logo.php new file mode 100644 index 0000000..3c518fe --- /dev/null +++ b/views/default/forms/admin/elgg_theme/logo.php @@ -0,0 +1,30 @@ + $asset_src, + 'class' => 'elgg-theme-logo__preview mbl', +]); + +echo elgg_view_field([ + '#type' => 'file', + '#label' => elgg_echo('elgg_theme:settings:logo'), + 'name' => 'logo', + 'accept' => 'image/png', + '#help' => elgg_echo('elgg_theme:settings:logo:help'), +]); + +$footer = elgg_view_field([ + '#type' => 'submit', + 'value' => elgg_echo('save'), +]); + +elgg_set_form_footer($footer); diff --git a/views/default/graphics/logo.png b/views/default/graphics/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..8b98f05214b1e2399450d61d75cc2a7dae1761db GIT binary patch literal 1942 zcmV;H2Wj|;P)NpMX?jL!fPJB^03@p&*D>2v)(SGZnOD zu5A;9XUQ0kj zvzOIz3W`@*%YhS#%;58y&K(QT%!Sp)03`VM@qiX^5-Tl10lI-% zz;vJk7y|wQ3;<692NQrDx104kV-8g?u=M;Uk;+A?da1C&lgZn!08;;{YNt*_| z8~6}#J@6Lbo4`LA?Fu8-@|LcWCMei^$?sH1@V+eh9s5^FdPvfG zNv9M*;^1B{X{v*q;?J!r0U9UHkaU-%ZITvwUp28*R+!xC@6*04xyRqD+_Gy*fJPmi zlFpDctwbi08hmsm(BuC2ko)g&;ww2Y4_F4g5jfS~4*-t?+px3}11ILx?_t669^f(H z&Vs*28BJS^`h~!az)mcPqNB(ABw!WrJ}f%-WBD@x6S2rY1pETnh~-xjK+}P>Sg@|d zvPK$AY2cJ6b~o)BNe@VxpDbNmqREnOlGG>ZJCc@oUtG53k~YbLZ-=C_3T_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hr>Xv!wNfuHM4Ht8!@ zZ&t0gL()Z3K0+5GagIUJj_n>V#u!tqD$!D9M3+K;toL($h2{a@$C7=tcC^w=LRig< z19N!lQPFvNV9wctNb3n zcSD$U^TNDWJo6k+dnKSF;}Ye^vrwdKCwidU9KaZXHq0sM`>+28G@hgJ*j|-Crd~^b cHZ*Pj1}3+c2E&iKmH+?%07*qoM6N<$f;DEFy8r+H literal 0 HcmV?d00001 diff --git a/views/default/page/elements/header_logo.php b/views/default/page/elements/header_logo.php new file mode 100644 index 0000000..e5cf71e --- /dev/null +++ b/views/default/page/elements/header_logo.php @@ -0,0 +1,31 @@ +getDisplayName(); + +$asset_src = false; + +$file_src = elgg_get_data_path() . 'elgg_theme/logo.png'; + +if (file_exists($file_src)) { + $asset_src = elgg_get_simplecache_url('elgg_theme/logo.png'); + + $text = elgg_format_element('img', [ + 'src' => $asset_src, + 'alt' => elgg_get_site_entity()->getDisplayName(), + ]); +} + +if ((bool) elgg_get_plugin_setting('topbar_logo_text', 'elgg_theme')) { + $text = elgg_get_site_entity()->getDisplayName(); +} + +echo elgg_format_element('div', [ + 'class' => 'elgg-heading-site elgg-loud' +], elgg_view('output/url', [ + 'text' => $text, + 'href' => elgg_get_site_entity()->getURL(), + 'title' => elgg_get_site_entity()->getDisplayName(), +])); diff --git a/views/default/plugins/elgg_theme/settings.php b/views/default/plugins/elgg_theme/settings.php index 2a8e284..62bfa13 100644 --- a/views/default/plugins/elgg_theme/settings.php +++ b/views/default/plugins/elgg_theme/settings.php @@ -13,6 +13,15 @@ 'switch' => true, ]); +// logo +echo elgg_view_field([ + '#type' => 'checkbox', + '#label' => elgg_echo('elgg_theme:settings:topbar_logo_text'), + 'name' => 'params[topbar_logo_text]', + 'checked' => (bool) $entity->topbar_logo_text, + 'switch' => true, +]); + //landing page echo elgg_view_field([ '#type' => 'fieldset',