From 88f14575dc73f8776f8a46ea06c5ca82d43c65d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jakes=CC=8C?= Date: Mon, 7 Jan 2019 18:07:23 +0100 Subject: [PATCH] Use image alignment from
or [MAILPOET-1684] --- lib/Newsletter/Editor/PostContentManager.php | 2 +- .../Editor/StructureTransformer.php | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/Newsletter/Editor/PostContentManager.php b/lib/Newsletter/Editor/PostContentManager.php index 59f962b977..f958013e0d 100644 --- a/lib/Newsletter/Editor/PostContentManager.php +++ b/lib/Newsletter/Editor/PostContentManager.php @@ -49,7 +49,7 @@ class PostContentManager { '', '
    ', '
      ', '
    1. ', '
      ', '
      ' ); if($display_type === 'full') { - $tags_not_being_stripped = array_merge($tags_not_being_stripped, array('', '

      ', '

      ', '

      ')); + $tags_not_being_stripped = array_merge($tags_not_being_stripped, array('
      ', '', '

      ', '

      ', '

      ')); } $content = strip_tags($content, implode('', $tags_not_being_stripped)); diff --git a/lib/Newsletter/Editor/StructureTransformer.php b/lib/Newsletter/Editor/StructureTransformer.php index 33e021de16..47747f81ba 100644 --- a/lib/Newsletter/Editor/StructureTransformer.php +++ b/lib/Newsletter/Editor/StructureTransformer.php @@ -26,7 +26,7 @@ class StructureTransformer { $top_ancestor = DOMUtil::findTopAncestor($item); $offset = $top_ancestor->index(); - if($item->hasParent('a')) { + if($item->hasParent('a') || $item->hasParent('figure')) { $item = $item->parent; } @@ -40,8 +40,21 @@ class StructureTransformer { */ private function transformTagsToBlocks($root, $image_full_width) { return array_map(function($item) use ($image_full_width) { - if($item->tag === 'img' || $item->tag === 'a' && $item->query('img')) { + if($item->tag === 'img' || in_array($item->tag, ['a', 'figure'], true) && $item->query('img')) { $image = $item->tag === 'img' ? $item : $item->query('img')[0]; + + // when
      exist, it carries align class, otherwise it's on + $alignItem = $item->tag === 'figure' ? $item : $image; + if($alignItem->hasClass('aligncenter')) { + $align = 'center'; + } elseif($alignItem->hasClass('alignleft')) { + $align = 'left'; + } elseif($alignItem->hasClass('alignright')) { + $align = 'right'; + } else { + $align = 'left'; + } + $width = $image->getAttribute('width'); $height = $image->getAttribute('height'); return array( @@ -54,7 +67,7 @@ class StructureTransformer { 'height' => $height === null ? 'auto' : $height, 'styles' => array( 'block' => array( - 'textAlign' => 'center', + 'textAlign' => $align, ), ), );