PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 7.1.4
Admin Columns v7.1.4
7.1.4 7.0.19 2.3.5 2.4 2.4.1 2.4.10 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.6.1 2.5.6.2 2.5.6.3 2.5.6.4 3.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.7 3.1 3.1.1 3.1.10 3.1.2 3.1.3 3.1.5 3.2.3 3.2.7 3.3.1 3.4.1 3.4.6 3.4.8 4.0.1 4.0.3 4.1.6 4.2.2 4.2.5 4.3 4.3.2 4.4.1 4.4.4 4.4.5 4.5.5 4.6.1 4.7.18 4.7.19 4.7.20 4.7.7 7.0.13 7.0.14 7.0.16 trunk 1.0 1.1 1.1.3 1.2 1.2.1 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.5.1 1.4.6 1.4.6.1 1.4.6.2 1.4.6.3 1.4.6.4 1.4.7 1.4.8 1.4.9 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2 2.2.1 2.2.1.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.5.1 2.2.6 2.2.6.1 2.2.6.2 2.2.6.3 2.2.6.4 2.2.7 2.2.8 2.2.8.1 2.2.9 2.3.1 2.3.2 2.3.3
codepress-admin-columns / classes / Formatter / ImageToCollection.php
codepress-admin-columns / classes / Formatter Last commit date
Collection 2 days ago Comment 2 days ago Date 2 days ago Media 2 days ago Post 2 days ago Term 2 days ago User 2 days ago Wrap 2 days ago Actions.php 2 days ago Aggregate.php 2 days ago Append.php 2 days ago ArrayToCollection.php 2 days ago Avatar.php 2 days ago AvatarUrl.php 2 days ago BeforeAfter.php 2 days ago BooleanLabel.php 2 days ago CharacterLimit.php 2 days ago CodeBlock.php 2 days ago Color.php 2 days ago ColumnFilter.php 2 days ago Composite.php 2 days ago ConditionalValue.php 2 days ago ContentTypeLink.php 2 days ago Count.php 2 days ago CountLabelFormatter.php 2 days ago DottedPassword.php 2 days ago EmptyValue.php 2 days ago ExplodeToCollection.php 2 days ago ExtendedValueLink.php 2 days ago FallBack.php 2 days ago FallBackFormatter.php 2 days ago FileLink.php 2 days ago FileSizeReadable.php 2 days ago ForeignId.php 2 days ago FormattedJson.php 2 days ago GroupedIdsToCollection.php 2 days ago HasValue.php 2 days ago HtmlEntityDecode.php 2 days ago HumanReadableTime.php 2 days ago HumanTimeDifference.php 2 days ago Id.php 2 days ago IdsToCollection.php 2 days ago Image.php 2 days ago ImageSize.php 2 days ago ImageToCollection.php 2 days ago ImageUrl.php 2 days ago ImageUrlsFromContent.php 2 days ago Implode.php 2 days ago ImplodeRecursive.php 2 days ago Kses.php 2 days ago Latest.php 2 days ago Linkable.php 2 days ago Links.php 2 days ago MapOptionLabel.php 2 days ago MapToId.php 2 days ago MapToLabel.php 2 days ago MenuLink.php 2 days ago Message.php 2 days ago Meta.php 2 days ago MetaCollection.php 2 days ago MetaCount.php 2 days ago MetaValueCollection.php 2 days ago NoIcon.php 2 days ago NullFormatter.php 2 days ago NumberFormat.php 2 days ago PathScope.php 2 days ago PregReplace.php 2 days ago Prepend.php 2 days ago ReadingTime.php 2 days ago RelationIdsCollection.php 2 days ago SelectOptionMapper.php 2 days ago SmallBlocks.php 2 days ago StringSanitizer.php 2 days ago StripTags.php 2 days ago Suffix.php 2 days ago TableRender.php 2 days ago ToArray.php 2 days ago ToggleValue.php 2 days ago TotalSum.php 2 days ago Trim.php 2 days ago UrlDecode.php 2 days ago UsedByMenu.php 2 days ago WordCount.php 2 days ago WordLimit.php 2 days ago Wrapper.php 2 days ago YesIcon.php 2 days ago YesNoIcon.php 2 days ago
ImageToCollection.php
80 lines
1 <?php
2
3 declare(strict_types=1);
4
5 namespace AC\Formatter;
6
7 use AC\Exception\ValueNotFoundException;
8 use AC\Formatter;
9 use AC\Helper;
10 use AC\Type\Value;
11 use AC\Type\ValueCollection;
12
13 /**
14 * Takes various raw values that represent one or more image attachments and formats them into a ValueCollection of
15 * attachment IDs or URLs. It prioritizes parsing for attachment IDs first. If no valid IDs are found, it will then
16 * attempt to parse for image URLs.
17 * Supported input value types:
18 * - A single attachment ID (integer or string) or a single image URL (string)
19 * - A comma-separated string of attachment IDs or image URLs
20 * - An array of attachment IDs and/or image URLs
21 */
22 class ImageToCollection implements Formatter
23 {
24 public function format(Value $value): ValueCollection
25 {
26 $source = $value->get_value();
27
28 if (! $source) {
29 throw ValueNotFoundException::from_id($value->get_id());
30 }
31
32 if (is_string($source)) {
33 $source = $this->parse_string($source);
34 }
35
36 if (! is_array($source)) {
37 throw ValueNotFoundException::from_id($value->get_id());
38 }
39
40 $ids = $this->filter_ids($source);
41
42 if ($ids) {
43 return ValueCollection::from_ids($value->get_id(), $ids);
44 }
45
46 $urls = $this->filter_urls($source);
47
48 if ($urls) {
49 return new ValueCollection($value->get_id(), array_map([$this, 'create_value'], $urls));
50 }
51
52 throw ValueNotFoundException::from_id($value->get_id());
53 }
54
55 private function filter_ids(array $ids): array
56 {
57 return array_map('absint', array_filter($ids, 'is_numeric'));
58 }
59
60 private function filter_urls(array $urls): array
61 {
62 return array_filter($urls, [Helper\Strings::create(), 'is_image']);
63 }
64
65 private function parse_string(string $value): array
66 {
67 if (str_contains($value, ',')) {
68 return explode(',', $value);
69 }
70
71 return [$value];
72 }
73
74 private function create_value(string $value): Value
75 {
76 return new Value($value);
77 }
78
79 }
80