Skip to content

Commit

Permalink
Added option to change the cover image
Browse files Browse the repository at this point in the history
  • Loading branch information
RiverVanRain committed Jun 10, 2023
1 parent bf0eb87 commit 244697c
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 8 deletions.
38 changes: 38 additions & 0 deletions classes/wZm/ElggTheme/Actions/SettingsAction.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 SettingsAction {

public function __invoke(\Elgg\Request $request) {
$asset = 'cover';
$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'));
}
}
30 changes: 30 additions & 0 deletions classes/wZm/ElggTheme/Menus/SettingsManu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace wZm\ElggTheme\Menus;

class SettingsManu {

public function __invoke(\Elgg\Event $event) {
if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) {
return;
}

$current_route = elgg_get_current_route();
if (elgg_extract('segments', $current_route->getMatchedParameters()) !== 'plugins' && $current_route->getName() !== 'admin:plugin_settings') {
return;
}

$menu = $event->getValue();
/* @var $menu \Elgg\Collections\Collection */

$menu->add(\ElggMenuItem::factory([
'name' => 'elgg_theme:cover',
'text' => elgg_echo('admin:elgg_theme:cover'),
'href' => elgg_normalize_url('admin/elgg_theme/cover'),
'parent_name' => 'plugin:settings:elgg_theme',
'section' => 'plugin_settings',
]));

return $menu;
}
}
31 changes: 30 additions & 1 deletion elgg-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,44 @@
],
'activate_on_install' => true,
],

'actions' => [
//admin
'admin/elgg_theme/cover' => [
'controller' => \wZm\ElggTheme\Actions\SettingsAction::class,
'access' => 'admin',
],
],

'events' => [
'register' => [
'menu:page' => [
\wZm\ElggTheme\Menus\SettingsManu::class => [],
],
],
],

'view_extensions' => [
'elgg.css' => [
'admin.css' => [
'elgg_theme/elgg_theme_admin.css' => [],
],
'elgg.css' => [
'elgg_theme/elgg_theme.css' => [],
],
'river/sidebar' => [
'elgg_theme/sidebar' => [],
],
],

'view_options' => [
'graphics/cover.jpg' => ['simplecache' => true],
],

'views' => [
'default' => [
'elgg_theme/' => elgg_get_data_path() . 'elgg_theme/',
],
],

'settings' => [
'landing_action' => true,
Expand Down
7 changes: 7 additions & 0 deletions languages/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,12 @@
'elgg_theme:settings:activity_sidebar:profile_icon' => 'Show profile icon',
'elgg_theme:settings:activity_sidebar:friends' => 'Show friends',

'admin:elgg_theme' => 'Elgg Landing Theme',
'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.',

'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/cover.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

echo elgg_view_form('admin/elgg_theme/cover', [
'enctype' => 'multipart/form-data'
], []);
10 changes: 8 additions & 2 deletions views/default/elgg_theme/elements/featured.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
$entity = elgg_get_plugin_from_id('elgg_theme');

// Get the image
$img = elgg_get_simplecache_url('graphics/cover.jpg');
$file_src = elgg_get_data_path() . 'elgg_theme/cover.png';

if (file_exists($file_src)) {
$img = elgg_get_simplecache_url('elgg_theme/cover.png');
} else {
$img = elgg_get_simplecache_url('graphics/cover.jpg');
}

$cover = elgg_format_element('div', [
'class' => 'slide',
'class' => 'elgg-featured-cover',
'style' => "background-image: url('{$img}');"
]);

Expand Down
13 changes: 8 additions & 5 deletions views/default/elgg_theme/elgg_theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ legend {
}
.elgg-landing-page {
.elgg-page-body {
padding: 0;
padding: 0 !important;

> .elgg-inner {
padding: 0;
padding: 0 !important;
max-width: none;
}
}
Expand Down Expand Up @@ -80,12 +80,14 @@ legend {
height: 32.5rem;
transition: all 0.3s;

.slide {
.elgg-featured-cover {
background-repeat: no-repeat;
background-position: center center;
background-size: cover;
height: 32.5rem;
transition: all 0.3s;
background-color: rgba(0,0,0,.4);
background-blend-mode: multiply;
}

.elgg-caption {
Expand Down Expand Up @@ -148,7 +150,7 @@ legend {
.elgg-featured-container {
height: 21rem;

.slide {
.elgg-featured-cover {
height: 21rem;
}

Expand Down Expand Up @@ -177,7 +179,7 @@ legend {
.elgg-featured-container {
height: 15rem;

.slide {
.elgg-featured-cover {
height: 15rem;
}

Expand Down Expand Up @@ -218,3 +220,4 @@ legend {
}
}
}

5 changes: 5 additions & 0 deletions views/default/elgg_theme/elgg_theme_admin.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

img.elgg-theme-cover__preview {
width: 320px !important;
max-width: 320px !important;
}
30 changes: 30 additions & 0 deletions views/default/forms/admin/elgg_theme/cover.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

//cover
$file_src = elgg_get_data_path() . 'elgg_theme/cover.png';

if (file_exists($file_src)) {
$asset_src = elgg_get_simplecache_url('elgg_theme/cover.png');
} else {
$asset_src = elgg_get_simplecache_url('graphics/cover.jpg');
}

echo elgg_view('output/img', [
'src' => $asset_src,
'class' => 'elgg-theme-cover__preview mbl',
]);

echo elgg_view_field([
'#type' => 'file',
'#label' => elgg_echo('elgg_theme:settings:cover'),
'name' => 'cover',
'accept' => 'image/png',
'#help' => elgg_echo('elgg_theme:settings:cover:help'),
]);

$footer = elgg_view_field([
'#type' => 'submit',
'value' => elgg_echo('save'),
]);

elgg_set_form_footer($footer);

0 comments on commit 244697c

Please sign in to comment.