Skip to content

Commit

Permalink
feat: use/prefer module keys
Browse files Browse the repository at this point in the history
  • Loading branch information
eaCe committed May 13, 2022
1 parent 8b443ea commit 38a070c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
7 changes: 6 additions & 1 deletion lib/module_preview.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,16 @@ public function getModules(): string {

if (rex::getUser()->getComplexPerm('modules')->hasPerm($m['id'])) {
if (rex_template::hasModule($this->template_attributes, $ctId, $m['id'])) {
$image = rex_url::assets('addons/module_preview_modules/'.$m['id'].'.jpg');
$moduleList .= '<li class="column">';
$moduleList .= '<a href="'.$context->getUrl(['module_id' => $m['id']]).'" data-href="'.$context->getUrl(['module_id' => $m['id']]).'" class="module" data-name="'.$m['id'].'.jpg">';
$moduleList .= '<div class="header">'.rex_i18n::translate($m['name'], false).'</div>';
if(!$hideImages) {
$image = rex_url::assets('addons/module_preview_modules/'.$m['id'].'.jpg');

if(array_key_exists('key', $m) && isset($m['key'])) {
$image = rex_url::assets('addons/module_preview_modules/'.$m['key'].'.jpg');
}

$moduleList .= '<div class="image"><div>';
if(file_exists($image)) {
$moduleList .= '<img src="'.$image.'" alt="'.rex_i18n::translate($m['name'], false).'">';
Expand Down
19 changes: 16 additions & 3 deletions pages/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
foreach ($moduleIds as $moduleId) {
$tmpImage = rex_files('module_'.$moduleId['id']);

if(!$tmpImage || !$tmpImage['tmp_name'] && $tmpImage['error'] !== 0) {
if(!$tmpImage || (!$tmpImage['tmp_name'] && $tmpImage['error'] !== 0)) {
continue;
}

Expand All @@ -42,8 +42,16 @@
continue;
}

$uploadedImage = new UploadedFile($tmpImage['tmp_name'], $tmpImage['name'], $tmpImage['type'], $tmpImage['error']);
$uploadedImage->move($targetDir, $moduleId['id'].'.jpg');
$module = rex_sql::factory();
$module = $module->getArray('select * from ' . rex::getTable('module') . ' WHERE id = :id LIMIT 1', ['id' => $moduleId['id']]);
$fileName = $moduleId['id'];

if(array_key_exists('key', $module[0]) && isset($module[0]['key'])) {
$fileName = $module[0]['key'];
}

$uploadedImage = new UploadedFile($tmpImage['tmp_name'], $tmpImage['name'], $tmpImage['type'], $tmpImage['error']);
$uploadedImage->move($targetDir, $fileName.'.jpg');
$imageCount++;
}

Expand Down Expand Up @@ -82,6 +90,11 @@
foreach ($modules as $module)
{
$image = rex_url::assets('addons/module_preview_modules/'.$module['id'].'.jpg');

if(array_key_exists('key', $module) && isset($module['key'])) {
$image = rex_url::assets('addons/module_preview_modules/'.$module['key'].'.jpg');
}

$content .= '<div class="module-col">';
$content .= '<div class="name"><strong>'.$module['name'].'</strong> <span>['.$module['id'].']</span></div>';
$content .= '<div class="module rex-form-group form-group">';
Expand Down

0 comments on commit 38a070c

Please sign in to comment.