/var/www/hkosl.com/aga/wp-content/plugins/wordpress-seo/src/models/indexable.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
<?php
/**
 * Model for the Indexable table.
 *
 * @package Yoast\YoastSEO\Models
 */

namespace Yoast\WP\Free\Models;

use 
Yoast\WP\Free\Exceptions\No_Indexable_Found;
use 
Yoast\WP\Free\Loggers\Logger;
use 
Yoast\WP\Free\Yoast_Model;

/**
 * Indexable table definition.
 *
 * @property int     $id
 * @property int     $object_id
 * @property string  $object_type
 * @property string  $object_sub_type
 *
 * @property string  $created_at
 * @property string  $updated_at
 *
 * @property string  $permalink
 * @property string  $canonical
 * @property int     $content_score
 *
 * @property boolean $is_robots_noindex
 * @property boolean $is_robots_nofollow
 * @property boolean $is_robots_noarchive
 * @property boolean $is_robots_noimageindex
 * @property boolean $is_robots_nosnippet
 *
 * @property string  $title
 * @property string  $description
 * @property string  $breadcrumb_title
 *
 * @property boolean $is_cornerstone
 *
 * @property string  $primary_focus_keyword
 * @property int     $primary_focus_keyword_score
 *
 * @property int     $readability_score
 *
 * @property int     $link_count
 * @property int     $incoming_link_count
 */
class Indexable extends Yoast_Model {

    
/**
     * The Indexable meta data.
     *
     * @var \Yoast\WP\Free\Models\Indexable_Meta[]
     */
    
protected $meta_data;

    
/**
     * Retrieves an indexable by its ID and type.
     *
     * @param int    $object_id   The indexable object ID.
     * @param string $object_type The indexable object type.
     * @param bool   $auto_create Optional. Create the indexable if it does not exist.
     *
     * @return bool|\Yoast\WP\Free\Models\Indexable Instance of indexable.
     */
    
public static function find_by_id_and_type$object_id$object_type$auto_create true ) {
        
$indexable Yoast_Model::of_type'Indexable' )
            ->
where'object_id'$object_id )
            ->
where'object_type'$object_type )
            ->
find_one();

        if ( 
$auto_create && ! $indexable ) {
            
$indexable self::create_for_id_and_type$object_id$object_type );
        }

        return 
$indexable;
    }

    
/**
     * Creates an indexable by its ID and type.
     *
     * @param int    $object_id   The indexable object ID.
     * @param string $object_type The indexable object type.
     *
     * @return bool|\Yoast\WP\Free\Models\Indexable Instance of indexable.
     */
    
public static function create_for_id_and_type$object_id$object_type ) {
        
/*
         * Indexable instance.
         *
         * @var \Yoast\WP\Free\Models\Indexable $indexable
         */
        
$indexable              Yoast_Model::of_type'Indexable' )->create();
        
$indexable->object_id   $object_id;
        
$indexable->object_type $object_type;

        
Logger::get_logger()->debug(
            \
sprintf(
                
/* translators: 1: object ID; 2: object type. */
                
\__'Indexable created for object %1$s with type %2$s''wordpress-seo' ),
                
$object_id,
                
$object_type
            
),
            \
get_object_vars$indexable )
        );

        return 
$indexable;
    }

    
/**
     * Returns the related meta model.
     *
     * @return \Yoast\WP\Free\Models\Indexable_Meta Array of meta objects.
     */
    
public function meta() {
        try {
            return 
$this->has_many'Indexable_Meta''indexable_id''id' );
        }
        catch ( \
Exception $exception ) {
            
Logger::get_logger()->info$exception->getMessage() );
        }

        return 
null;
    }

    
/**
     * Enhances the save method.
     *
     * @return boolean True on succes.
     */
    
public function save() {
        if ( ! 
$this->created_at ) {
            
$this->created_at = \gmdate'Y-m-d H:i:s' );
        }

        if ( 
$this->updated_at ) {
            
$this->updated_at = \gmdate'Y-m-d H:i:s' );
        }

        
$saved parent::save();

        if ( 
$saved ) {
            
Logger::get_logger()->debug(
                \
sprintf(
                    
/* translators: 1: object ID; 2: object type. */
                    
\__'Indexable saved for object %1$s with type %2$s''wordpress-seo' ),
                    
$this->object_id,
                    
$this->object_type
                
),
                \
get_object_vars$this )
            );

            
$this->save_meta();

            \
do_action'wpseo_indexable_saved'$this );
        }

        return 
$saved;
    }

    
/**
     * Enhances the delete method.
     *
     * @return boolean True on success.
     */
    
public function delete() {
        
$deleted parent::delete();

        if ( 
$deleted ) {
            
Logger::get_logger()->debug(
                \
sprintf(
                    
/* translators: 1: object ID; 2: object type. */
                    
\__'Indexable deleted for object %1$s with type %2$s''wordpress-seo' ),
                    
$this->object_id,
                    
$this->object_type
                
),
                \
get_object_vars$this )
            );

            \
do_action'wpseo_indexable_deleted'$this );
        }

        return 
$deleted;
    }

    
/**
     * Removes the indexable meta.
     *
     * @return void
     */
    
public function delete_meta() {
        
$meta_data $this->meta();
        
$meta_data = (array) $meta_data->find_many();
        foreach ( 
$meta_data as $indexable_meta ) {
            
$indexable_meta->delete();
        }
    }

    
/**
     * Sets specific meta data for an indexable.
     *
     * @param string $meta_key    The key to set.
     * @param string $meta_value  The value to set.
     * @param bool   $auto_create Optional. Create the indexable if it does not exist.
     *
     * @return void
     */
    
public function set_meta$meta_key$meta_value$auto_create true ) {
        
$meta             $this->get_meta$meta_key$auto_create );
        
$meta->meta_value $meta_value;
    }

    
/**
     * Saves the meta data.
     *
     * @return void
     */
    
protected function save_meta() {
        if ( empty( 
$this->meta_data ) ) {
            return;
        }

        foreach ( 
$this->meta_data as $meta ) {
            
$meta->indexable_id $this->id;
            
$meta->save();
        }
    }

    
/**
     * Fetches the indexable meta for a metafield and indexable.
     *
     * @param string $meta_key    The meta key to get object for.
     * @param bool   $auto_create Optional. Create the indexable if it does not exist.
     *
     * @return \Yoast\WP\Free\Models\Indexable_Meta
     *
     * @throws \Yoast\WP\Free\Exceptions\No_Indexable_Found Exception when no Indexable entry could be found.
     */
    
protected function get_meta$meta_key$auto_create true ) {
        
$this->initialize_meta();

        if ( \
array_key_exists$meta_key$this->meta_data ) ) {
            return 
$this->meta_data$meta_key ];
        }

        if ( 
$auto_create ) {
            
$this->meta_data$meta_key ] = Indexable_Meta::create_meta_for_indexable$this->id$meta_key );

            return 
$this->meta_data$meta_key ];
        }

        throw 
No_Indexable_Found::from_meta_key$meta_key$this->id );
    }

    
/**
     * Initializes the meta data.
     *
     * @return void
     */
    
protected function initialize_meta() {
        if ( 
$this->meta_data !== null ) {
            return;
        }

        
$this->meta_data = array();

        
$meta_data $this->meta();
        if ( ! 
$meta_data ) {
            return;
        }

        try {
            
$meta_data = (array) $meta_data->find_many();
            foreach ( 
$meta_data as $meta ) {
                
$this->meta_data$meta->meta_key ] = $meta;
            }
        }
        catch ( \
Exception $exception ) {
            
Logger::get_logger()->info$exception->getMessage() );
        }
    }
}