1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
<?php
namespace Yoast\WP\SEO\Generators;
use Yoast\WP\SEO\Context\Meta_Tags_Context; use Yoast\WP\SEO\Generators\Generator_Interface; use Yoast\WP\SEO\Helpers\Image_Helper; use Yoast\WP\SEO\Helpers\Twitter\Image_Helper as Twitter_Image_Helper; use Yoast\WP\SEO\Helpers\Url_Helper; use Yoast\WP\SEO\Models\Indexable; use Yoast\WP\SEO\Values\Images;
/** * Represents the generator class for the Twitter images. */ class Twitter_Image_Generator implements Generator_Interface {
/** * The image helper. * * @var Image_Helper */ protected $image;
/** * The URL helper. * * @var Url_Helper */ protected $url;
/** * The Twitter image helper. * * @var Twitter_Image_Helper */ protected $twitter_image;
/** * Twitter_Image_Generator constructor. * * @codeCoverageIgnore * * @param Image_Helper $image The image helper. * @param Url_Helper $url The url helper. * @param Twitter_Image_Helper $twitter_image The Twitter image helper. */ public function __construct( Image_Helper $image, Url_Helper $url, Twitter_Image_Helper $twitter_image ) { $this->image = $image; $this->url = $url; $this->twitter_image = $twitter_image; }
/** * Retrieves the images for an indexable. * * @param Meta_Tags_Context $context The context. * * @return array The images. */ public function generate( Meta_Tags_Context $context ) { $image_container = $this->get_image_container();
$this->add_from_indexable( $context->indexable, $image_container );
return $image_container->get_images(); }
/** * Adds an image based on the given indexable. * * @param Indexable $indexable The indexable. * @param Images $image_container The image container. */ protected function add_from_indexable( Indexable $indexable, Images $image_container ) { if ( $indexable->twitter_image_id ) { $image_container->add_image_by_id( $indexable->twitter_image_id ); return; }
if ( $indexable->twitter_image ) { $image_container->add_image_by_url( $indexable->twitter_image ); } }
/** * Retrieves an instance of the image container. * * @codeCoverageIgnore * * @return Images The image container. */ protected function get_image_container() { $image_container = new Images( $this->image, $this->url ); $image_container->image_size = $this->twitter_image->get_image_size();
return $image_container; } }
|