forked from PerJensen/elgg_connect
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added option to change the cover image
- Loading branch information
1 parent
bf0eb87
commit 244697c
Showing
9 changed files
with
161 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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>', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
], []); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |