diff --git a/core/class/helper.class.php b/core/class/helper.class.php index 1753918e..09365b25 100644 --- a/core/class/helper.class.php +++ b/core/class/helper.class.php @@ -673,12 +673,34 @@ class helper public static function subword($text, $start, $length) { $text = trim($text); - if (strlen($text) > $length) { + + // Vérifier si la longueur du texte sans les balises dépasse la longueur souhaitée + if (mb_strlen(strip_tags($text)) > $length) { + // Utiliser mb_substr pour couper le texte $text = mb_substr($text, $start, $length); - $text = mb_substr($text, 0, min(mb_strlen($text), mb_strrpos($text, ' '))); + + // S'assurer que le texte ne se termine pas au milieu d'un mot + $lastSpace = mb_strrpos($text, ' '); + if ($lastSpace !== false) { + $text = mb_substr($text, 0, $lastSpace); + } + + // Fermer les balises HTML ouvertes + $dom = new DOMDocument(); + @$dom->loadHTML('
' . $text . '
', LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); + $text = $dom->saveHTML(); + + // Retirer la balise de conteneur ajoutée + $text = preg_replace('~^
(.*)
$~s', '$1', $text); + + // Ajouter des points de suspension si le texte a été coupé + $text .= '...'; } + return $text; } + + /** * Cryptage diff --git a/module/blog/view/index/index.php b/module/blog/view/index/index.php index 6b04b737..94d9c555 100755 --- a/module/blog/view/index/index.php +++ b/module/blog/view/index/index.php @@ -103,18 +103,18 @@ file_exists(self::FILE_DIR . 'source/' . $article['picture']) ): ?>
- getData(['module', $this->getUrl(0), 'posts', $articleId, 'picture'])); - $thumb = 'mini_' . $parts['basename']; - // Créer la miniature si manquante - if (!file_exists(self::FILE_DIR . 'thumb/' . $thumb)) { - $this->makeThumb( - self::FILE_DIR . 'source/' . $article['picture'], - self::FILE_DIR . 'thumb/' . $thumb, - self::THUMBS_WIDTH - ); - } + $parts = pathinfo($this->getData(['module', $this->getUrl(0), 'posts', $articleId, 'picture'])); + $thumb = 'mini_' . $parts['basename']; + // Créer la miniature si manquante + if (!file_exists(self::FILE_DIR . 'thumb/' . $thumb)) { + $this->makeThumb( + self::FILE_DIR . 'source/' . $article['picture'], + self::FILE_DIR . 'thumb/' . $thumb, + self::THUMBS_WIDTH + ); + } ?>
- -
- -

- - - -

- -
- - - signature($this->getData(['module', $this->getUrl(0), 'posts', $articleId, 'userId'])); ?> - - getData(['module', $this->getUrl(0), 'posts', $articleId, 'publishedOn']), self::$i18nUI) . ' ' . helper::dateUTF8($module::$timeFormat, $this->getData(['module', $this->getUrl(0), 'posts', $articleId, 'publishedOn']), self::$i18nUI); ?> -
-
- getData(['module', $this->getUrl(0), 'config', 'articlesLenght']) !== 0 ? $this->getData(['module', $this->getUrl(0), 'config', 'articlesLenght']) : 500 ?> -

'), 0, $lenght); ?>... -

+ +
+ +

- + +

+ +
+ + + signature($this->getData(['module', $this->getUrl(0), 'posts', $articleId, 'userId'])); ?> + + getData(['module', $this->getUrl(0), 'posts', $articleId, 'publishedOn']), self::$i18nUI) . ' ' . helper::dateUTF8($module::$timeFormat, $this->getData(['module', $this->getUrl(0), 'posts', $articleId, 'publishedOn']), self::$i18nUI); ?> +
+
+ getData(['module', $this->getUrl(0), 'config', 'articlesLenght']); ?> + 0): ?> + + ... + + + +
-
- - + +