Collection
5 months ago
Comment
5 months ago
Date
5 months ago
Media
5 months ago
Post
5 months ago
Term
5 months ago
User
5 months ago
Wrap
5 months ago
Actions.php
5 months ago
Aggregate.php
5 months ago
Append.php
5 months ago
ArrayToCollection.php
5 months ago
Avatar.php
5 months ago
AvatarUrl.php
5 months ago
BeforeAfter.php
5 months ago
BooleanLabel.php
5 months ago
CharacterLimit.php
5 months ago
CodeBlock.php
5 months ago
Color.php
5 months ago
ColumnFilter.php
5 months ago
Composite.php
5 months ago
ConditionalValue.php
5 months ago
ContentTypeLink.php
5 months ago
Count.php
5 months ago
CountLabelFormatter.php
5 months ago
DottedPassword.php
5 months ago
EmptyValue.php
5 months ago
ExplodeToCollection.php
5 months ago
ExtendedValueLink.php
5 months ago
FallBack.php
5 months ago
FallBackFormatter.php
5 months ago
FileLink.php
5 months ago
FileSizeReadable.php
5 months ago
ForeignId.php
5 months ago
FormattedJson.php
5 months ago
GroupedIdsToCollection.php
5 months ago
HasValue.php
5 months ago
HumanReadableTime.php
5 months ago
HumanTimeDifference.php
5 months ago
Id.php
5 months ago
IdsToCollection.php
5 months ago
Image.php
5 months ago
ImageSize.php
5 months ago
ImageToCollection.php
5 months ago
ImageUrl.php
5 months ago
ImageUrlsFromContent.php
5 months ago
Implode.php
5 months ago
ImplodeRecursive.php
5 months ago
Kses.php
5 months ago
Latest.php
5 months ago
Linkable.php
5 months ago
Links.php
5 months ago
MapOptionLabel.php
5 months ago
MapToId.php
5 months ago
MapToLabel.php
5 months ago
MenuLink.php
5 months ago
Message.php
5 months ago
Meta.php
5 months ago
MetaCollection.php
5 months ago
NoIcon.php
5 months ago
NullFormatter.php
5 months ago
NumberFormat.php
5 months ago
PathScope.php
5 months ago
PregReplace.php
5 months ago
Prepend.php
5 months ago
ReadingTime.php
5 months ago
RelationIdsCollection.php
5 months ago
SelectOptionMapper.php
5 months ago
SmallBlocks.php
5 months ago
StringSanitizer.php
5 months ago
StripTags.php
5 months ago
Suffix.php
5 months ago
TableRender.php
5 months ago
ToArray.php
5 months ago
TotalSum.php
5 months ago
Trim.php
5 months ago
UrlDecode.php
5 months ago
UsedByMenu.php
5 months ago
WordCount.php
5 months ago
WordLimit.php
5 months ago
Wrapper.php
5 months ago
YesIcon.php
5 months ago
YesNoIcon.php
5 months ago
ImageUrlsFromContent.php
46 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Formatter; |
| 6 | |
| 7 | use AC; |
| 8 | use AC\Helper; |
| 9 | use AC\Type\Value; |
| 10 | use AC\Type\ValueCollection; |
| 11 | |
| 12 | class ImageUrlsFromContent implements AC\Formatter |
| 13 | { |
| 14 | |
| 15 | private AC\Column\Context $context; |
| 16 | |
| 17 | public function __construct(AC\Column\Context $context) |
| 18 | { |
| 19 | $this->context = $context; |
| 20 | } |
| 21 | |
| 22 | public function format(Value $value) |
| 23 | { |
| 24 | $string = (string)apply_filters( |
| 25 | 'ac/column/images/content', |
| 26 | (string)$value, |
| 27 | $value->get_id(), |
| 28 | $this->context |
| 29 | ); |
| 30 | |
| 31 | $urls = array_unique(Helper\Image::create()->get_image_urls_from_string($string)); |
| 32 | |
| 33 | if (empty($urls)) { |
| 34 | throw AC\Exception\ValueNotFoundException::from_id($value->get_id()); |
| 35 | } |
| 36 | |
| 37 | $collection = new ValueCollection($value->get_id()); |
| 38 | |
| 39 | foreach ($urls as $url) { |
| 40 | $collection->add(new Value($url)); |
| 41 | } |
| 42 | |
| 43 | return $collection; |
| 44 | } |
| 45 | |
| 46 | } |