Skip to content

Commit

Permalink
Added option to show logo image on the topbar
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolai Shcherbin committed Sep 12, 2023
1 parent 244697c commit 092f4ac
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Symfony\Component\HttpFoundation\File\UploadedFile;

class SettingsAction {
class CoverAction {

public function __invoke(\Elgg\Request $request) {
$asset = 'cover';
Expand Down
38 changes: 38 additions & 0 deletions classes/wZm/ElggTheme/Actions/LogoAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace wZm\ElggTheme\Actions;

use Symfony\Component\HttpFoundation\File\UploadedFile;

class LogoAction {

public function __invoke(\Elgg\Request $request) {
$asset = 'logo';
$upload = elgg_get_uploaded_file($asset);

if (!$upload instanceof UploadedFile || !$upload->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'));
}
}
16 changes: 16 additions & 0 deletions classes/wZm/ElggTheme/Menus/SettingsManu.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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;
}
}
11 changes: 8 additions & 3 deletions elgg-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
return [
'plugin' => [
'name' => 'Elgg Landing Theme',
'version' => '2.0.0',
'version' => '2.1.0',
'dependencies' => [
'activity' => [
'position' => 'after',
Expand All @@ -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',
],
],
Expand Down Expand Up @@ -63,6 +67,7 @@
],

'settings' => [
'topbar_logo_text' => true,
'landing_action' => true,
'display_members' => true,
'display_groups' => false,
Expand Down
9 changes: 9 additions & 0 deletions languages/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '<p>Many sites use <a href="https://es.wzm.me">the additional plugins</a> for this theme to place the custom modules on this landing page.</p><p>Contact with our developers to make beautiful and modern design for your site: <a href="mailto:[email protected]">[email protected]</a></p>',
];
5 changes: 5 additions & 0 deletions views/default/admin/elgg_theme/logo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

echo elgg_view_form('admin/elgg_theme/logo', [
'enctype' => 'multipart/form-data'
], []);
30 changes: 30 additions & 0 deletions views/default/forms/admin/elgg_theme/logo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

//logo
$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');
} else {
$asset_src = elgg_get_simplecache_url('graphics/logo.png');
}

echo elgg_view('output/img', [
'src' => $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);
Binary file added views/default/graphics/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions views/default/page/elements/header_logo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Elgg header logo
*/

$text = elgg_get_site_entity()->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(),
]));
9 changes: 9 additions & 0 deletions views/default/plugins/elgg_theme/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 092f4ac

Please sign in to comment.