refining kit press behaviour

This commit is contained in:
Antoine M 2023-11-27 10:55:36 +01:00
parent f668e21b3a
commit 666a556ff0
2 changed files with 32 additions and 12 deletions

View File

@ -6,6 +6,8 @@ if (!function_exists('getRessourceIcon')) {
function getRessourceIcon($ressource_type) function getRessourceIcon($ressource_type)
{ {
switch ($ressource_type) { switch ($ressource_type) {
case 'image/svg+xml':
case 'image/png':
case 'image/jpeg': case 'image/jpeg':
return plugin_dir_url(__DIR__) . "src/img/homegrade_image.svg"; return plugin_dir_url(__DIR__) . "src/img/homegrade_image.svg";
@ -17,6 +19,17 @@ if (!function_exists('getRessourceIcon')) {
} }
} }
} }
if (!function_exists('getRessourceTypeName')) {
function getRessourceTypeName($subtype)
{
switch ($subtype) {
case 'svg+xml':
return "svg";
default:
return $subtype;
}
}
}
?> ?>
<section <?php echo get_block_wrapper_attributes(["class" => "homegrade-blocks-kit-presse"]); ?>> <section <?php echo get_block_wrapper_attributes(["class" => "homegrade-blocks-kit-presse"]); ?>>
@ -34,22 +47,19 @@ if (!function_exists('getRessourceIcon')) {
$ressourceType = $data['mime_type']; $ressourceType = $data['mime_type'];
$ressourceIcon = getRessourceIcon($ressourceType); $ressourceIcon = getRessourceIcon($ressourceType);
setlocale(LC_TIME, 'fr_FR'); setlocale(LC_TIME, 'fr_FR');
$timestamp = strtotime($data['modified']); $timestamp = strtotime($data['modified']);
$formatted_date = strftime("%B %Y", $timestamp); $formatted_date = strftime("%B %Y", $timestamp);
// echo '<pre>';
// print_r($data);
// echo '</pre>';
?> ?>
<li class="homegrade-blocks-kit-presse__press-ressource"> <li class="homegrade-blocks-kit-presse__press-ressource">
<div class="homegrade-blocks-kit-presse__ressource-icon"> <div class="homegrade-blocks-kit-presse__ressource-icon">
<img src="<?php echo $ressourceIcon ?>" alt=""> <img src="<?php echo $ressourceIcon ?>" alt="">
</div> </div>
<p class="homegrade-blocks-kit-presse__ressource-title"><?php echo $data['title'] ?></p> <p class="homegrade-blocks-kit-presse__ressource-title"><?php echo $data['title'] ?></p>
<p class="homegrade-blocks-kit-presse__ressource-type"><?php echo $data['subtype'] ?></p> <p class="homegrade-blocks-kit-presse__ressource-type"><?php echo getRessourceTypeName($data['subtype']) ?></p>
<p class="homegrade-blocks-kit-presse__ressource-date"><?php echo $formatted_date ?></p> <p class="homegrade-blocks-kit-presse__ressource-date"><?php echo $formatted_date ?></p>
<a class="homegrade-blocks-kit-presse__ressource-download cta cta--secondary cta--button" href=""><?php echo __('Télécharger') ?></a> <a class="homegrade-blocks-kit-presse__ressource-download cta cta--secondary cta--button" href="<?php echo $data['url'] ?>" download><?php echo __('Télécharger', "homegrade-blocks__texte-fonctionnel") ?></a>
</li> </li>

View File

@ -6,6 +6,8 @@ if (!function_exists('getRessourceIcon')) {
function getRessourceIcon($ressource_type) function getRessourceIcon($ressource_type)
{ {
switch ($ressource_type) { switch ($ressource_type) {
case 'image/svg+xml':
case 'image/png':
case 'image/jpeg': case 'image/jpeg':
return plugin_dir_url(__DIR__) . "src/img/homegrade_image.svg"; return plugin_dir_url(__DIR__) . "src/img/homegrade_image.svg";
@ -17,6 +19,17 @@ if (!function_exists('getRessourceIcon')) {
} }
} }
} }
if (!function_exists('getRessourceTypeName')) {
function getRessourceTypeName($subtype)
{
switch ($subtype) {
case 'svg+xml':
return "svg";
default:
return $subtype;
}
}
}
?> ?>
<section <?php echo get_block_wrapper_attributes(["class" => "homegrade-blocks-kit-presse"]); ?>> <section <?php echo get_block_wrapper_attributes(["class" => "homegrade-blocks-kit-presse"]); ?>>
@ -34,22 +47,19 @@ if (!function_exists('getRessourceIcon')) {
$ressourceType = $data['mime_type']; $ressourceType = $data['mime_type'];
$ressourceIcon = getRessourceIcon($ressourceType); $ressourceIcon = getRessourceIcon($ressourceType);
setlocale(LC_TIME, 'fr_FR'); setlocale(LC_TIME, 'fr_FR');
$timestamp = strtotime($data['modified']); $timestamp = strtotime($data['modified']);
$formatted_date = strftime("%B %Y", $timestamp); $formatted_date = strftime("%B %Y", $timestamp);
// echo '<pre>';
// print_r($data);
// echo '</pre>';
?> ?>
<li class="homegrade-blocks-kit-presse__press-ressource"> <li class="homegrade-blocks-kit-presse__press-ressource">
<div class="homegrade-blocks-kit-presse__ressource-icon"> <div class="homegrade-blocks-kit-presse__ressource-icon">
<img src="<?php echo $ressourceIcon ?>" alt=""> <img src="<?php echo $ressourceIcon ?>" alt="">
</div> </div>
<p class="homegrade-blocks-kit-presse__ressource-title"><?php echo $data['title'] ?></p> <p class="homegrade-blocks-kit-presse__ressource-title"><?php echo $data['title'] ?></p>
<p class="homegrade-blocks-kit-presse__ressource-type"><?php echo $data['subtype'] ?></p> <p class="homegrade-blocks-kit-presse__ressource-type"><?php echo getRessourceTypeName($data['subtype']) ?></p>
<p class="homegrade-blocks-kit-presse__ressource-date"><?php echo $formatted_date ?></p> <p class="homegrade-blocks-kit-presse__ressource-date"><?php echo $formatted_date ?></p>
<a class="homegrade-blocks-kit-presse__ressource-download cta cta--secondary cta--button" href=""><?php echo __('Télécharger', "homegrade-blocks__texte-fonctionnel") ?></a> <a class="homegrade-blocks-kit-presse__ressource-download cta cta--secondary cta--button" href="<?php echo $data['url'] ?>" download><?php echo __('Télécharger', "homegrade-blocks__texte-fonctionnel") ?></a>
</li> </li>