/var/www/hkosl.com/aga/wp-content/plugins/wordpress-seo/frontend/schema/class-schema-webpage.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
<?php
/**
 * WPSEO plugin file.
 *
 * @package WPSEO\Frontend\Schema
 */

/**
 * Returns schema WebPage data.
 *
 * @since 10.2
 */
class WPSEO_Schema_WebPage implements WPSEO_Graph_Piece {

    
/**
     * A value object with context variables.
     *
     * @var WPSEO_Schema_Context
     */
    
private $context;

    
/**
     * WPSEO_Schema_WebPage constructor.
     *
     * @param WPSEO_Schema_Context $context A value object with context variables.
     */
    
public function __constructWPSEO_Schema_Context $context ) {
        
$this->context $context;
    }

    
/**
     * Determines whether or not a piece should be added to the graph.
     *
     * @return bool
     */
    
public function is_needed() {
        if ( 
is_404() ) {
            return 
false;
        }

        return 
true;
    }

    
/**
     * Returns WebPage schema data.
     *
     * @return array WebPage schema data.
     */
    
public function generate() {
        
$data = array(
            
'@type'      => $this->determine_page_type(),
            
'@id'        => $this->context->canonical WPSEO_Schema_IDs::WEBPAGE_HASH,
            
'url'        => $this->context->canonical,
            
'inLanguage' => get_bloginfo'language' ),
            
'name'       => $this->context->title,
            
'isPartOf'   => array(
                
'@id' => $this->context->site_url WPSEO_Schema_IDs::WEBSITE_HASH,
            ),
        );

        if ( 
is_front_page() ) {
            if ( 
$this->context->site_represents_reference ) {
                
$data['about'] = $this->context->site_represents_reference;
            }
        }

        if ( 
is_singular() ) {
            
$this->add_image$data );

            
$post get_post$this->context->id );
            
$data['datePublished'] = mysql2dateDATE_W3C$post->post_date_gmtfalse );
            
$data['dateModified']  = mysql2dateDATE_W3C$post->post_modified_gmtfalse );

            if ( 
get_post_type$post ) === 'post' ) {
                
$data $this->add_author$data$post );
            }
        }

        if ( ! empty( 
$this->context->description ) ) {
            
$data['description'] = $this->context->description;
        }

        if ( 
$this->add_breadcrumbs() ) {
            
$data['breadcrumb'] = array(
                
'@id' => $this->context->canonical WPSEO_Schema_IDs::BREADCRUMB_HASH,
            );
        }

        return 
$data;
    }

    
/**
     * Adds an author property to the $data if the WebPage is not represented.
     *
     * @param array   $data The WebPage schema.
     * @param WP_Post $post The post the context is representing.
     *
     * @return array The WebPage schema.
     */
    
public function add_author$data$post ) {
        if ( 
$this->context->site_represents === false ) {
            
$data['author'] = array( '@id' => WPSEO_Schema_Utils::get_user_schema_id$post->post_author$this->context ) );
        }
        return 
$data;
    }

    
/**
     * If we have an image, make it the primary image of the page.
     *
     * @param array $data WebPage schema data.
     */
    
public function add_image( &$data ) {
        if ( 
$this->context->has_image ) {
            
$data['primaryImageOfPage'] = array( '@id' => $this->context->canonical WPSEO_Schema_IDs::PRIMARY_IMAGE_HASH );
        }
    }

    
/**
     * Determine if we should add a breadcrumb attribute.
     *
     * @return bool
     */
    
private function add_breadcrumbs() {
        if ( 
is_front_page() ) {
            return 
false;
        }

        if ( 
$this->context->breadcrumbs_enabled ) {
            return 
true;
        }

        return 
false;
    }

    
/**
     * Determine the page type for the current page.
     *
     * @return string
     */
    
private function determine_page_type() {
        switch ( 
true ) {
            case 
is_search():
                
$type 'SearchResultsPage';
                break;
            case 
is_author():
                
$type 'ProfilePage';
                break;
            case 
WPSEO_Frontend_Page_Type::is_posts_page():
            case 
WPSEO_Frontend_Page_Type::is_home_posts_page():
            case 
is_archive():
                
$type 'CollectionPage';
                break;
            default:
                
$type 'WebPage';
        }

        
/**
         * Filter: 'wpseo_schema_webpage_type' - Allow changing the WebPage type.
         *
         * @api string $type The WebPage type.
         */
        
return apply_filters'wpseo_schema_webpage_type'$type );
    }
}