C:\xampp\htdocs\landing\wp-content\plugins\wordpress-seo\src\helpers\schema\image-helper.php


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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php

namespace Yoast\WP\SEO\Helpers\Schema;

use 
Yoast\WP\SEO\Helpers\Image_Helper as Main_Image_Helper;

/**
 * Class Image_Helper.
 */
class Image_Helper {

    
/**
     * The HTML helper.
     *
     * @var HTML_Helper
     */
    
private $html;

    
/**
     * The language helper.
     *
     * @var Language_Helper
     */
    
private $language;

    
/**
     * Represents the main image helper.
     *
     * @var Main_Image_Helper
     */
    
private $image;

    
/**
     * Image_Helper constructor.
     *
     * @param HTML_Helper       $html     The HTML helper.
     * @param Language_Helper   $language The language helper.
     * @param Main_Image_Helper $image    The 'main' image helper.
     *
     * @codeCoverageIgnore It handles dependencies.
     */
    
public function __constructHTML_Helper $htmlLanguage_Helper $languageMain_Image_Helper $image ) {
        
$this->html     $html;
        
$this->language $language;
        
$this->image    $image;
    }

    
/**
     * Find an image based on its URL and generate a Schema object for it.
     *
     * @param string $schema_id The `@id` to use for the returned image.
     * @param string $url       The image URL to base our object on.
     * @param string $caption   An optional caption.
     *
     * @return array Schema ImageObject array.
     */
    
public function generate_from_url$schema_id$url$caption '' ) {
        
$attachment_id $this->image->get_attachment_by_url$url );
        if ( 
$attachment_id ) {
            return 
$this->generate_from_attachment_id$schema_id$attachment_id$caption );
        }

        return 
$this->simple_image_object$schema_id$url$caption );
    }

    
/**
     * Retrieve data about an image from the database and use it to generate a Schema object.
     *
     * @param string $schema_id     The `@id` to use for the returned image.
     * @param int    $attachment_id The attachment to retrieve data from.
     * @param string $caption       The caption string, if there is one.
     *
     * @return array Schema ImageObject array.
     */
    
public function generate_from_attachment_id$schema_id$attachment_id$caption '' ) {
        
$data $this->generate_object$schema_id );

        
$data['url'] = $this->image->get_attachment_image_url$attachment_id'full' );
        
$data        $this->add_image_size$data$attachment_id );
        
$data        $this->add_caption$data$attachment_id$caption );

        return 
$data;
    }

    
/**
     * If we can't find $url in our database, we output a simple ImageObject.
     *
     * @param string $schema_id The `@id` to use for the returned image.
     * @param string $url       The image URL.
     * @param string $caption   A caption, if set.
     *
     * @return array $data Schema ImageObject array.
     */
    
public function simple_image_object$schema_id$url$caption '' ) {
        
$data $this->generate_object$schema_id );

        
$data['url'] = $url;

        if ( ! empty( 
$caption ) ) {
            
$data['caption'] = $this->html->smart_strip_tags$caption );
        }

        return 
$data;
    }

    
/**
     * Retrieves an image's caption if set, or uses the alt tag if that's set.
     *
     * @param array  $data          An ImageObject Schema array.
     * @param int    $attachment_id Attachment ID.
     * @param string $caption       The caption string, if there is one.
     *
     * @return array An imageObject with width and height set if available.
     */
    
private function add_caption$data$attachment_id$caption '' ) {
        if ( 
$caption !== '' ) {
            
$data['caption'] = $caption;

            return 
$data;
        }

        
$caption $this->image->get_caption$attachment_id );
        if ( ! empty( 
$caption ) ) {
            
$data['caption'] = $this->html->smart_strip_tags$caption );

            return 
$data;
        }

        return 
$data;
    }

    
/**
     * Generates our bare bone ImageObject.
     *
     * @param string $schema_id The `@id` to use for the returned image.
     *
     * @return array an empty ImageObject
     */
    
private function generate_object$schema_id ) {
        
$data = [
            
'@type' => 'ImageObject',
            
'@id'   => $schema_id,
        ];

        
$data $this->language->add_piece_language$data );

        return 
$data;
    }

    
/**
     * Adds image's width and height.
     *
     * @param array $data          An ImageObject Schema array.
     * @param int   $attachment_id Attachment ID.
     *
     * @return array An imageObject with width and height set if available.
     */
    
private function add_image_size$data$attachment_id ) {
        
$image_meta $this->image->get_metadata$attachment_id );
        if ( empty( 
$image_meta['width'] ) || empty( $image_meta['height'] ) ) {
            return 
$data;
        }
        
$data['width']  = $image_meta['width'];
        
$data['height'] = $image_meta['height'];

        return 
$data;
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586