PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.3
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.3
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / models / indexable.php

indexable.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.3, at src/models/indexable.php

217 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yoast\WP\SEO\Models;
4
5 use Yoast\WP\Lib\Model;
6
7 /**
8 * Indexable table definition.
9 *
10 * @property int $id
11 * @property int $object_id
12 * @property string $object_type
13 * @property string $object_sub_type
14 *
15 * @property int $author_id
16 * @property int $post_parent
17 *
18 * @property string $created_at
19 * @property string $updated_at
20 *
21 * @property string $permalink
22 * @property string $permalink_hash
23 * @property string $canonical
24 *
25 * @property bool $is_robots_noindex
26 * @property bool $is_robots_nofollow
27 * @property bool $is_robots_noarchive
28 * @property bool $is_robots_noimageindex
29 * @property bool $is_robots_nosnippet
30 *
31 * @property string $title
32 * @property string $description
33 * @property string $breadcrumb_title
34 *
35 * @property bool $is_cornerstone
36 *
37 * @property string $primary_focus_keyword
38 * @property int $primary_focus_keyword_score
39 *
40 * @property int $readability_score
41 *
42 * @property int $link_count
43 * @property int $incoming_link_count
44 * @property int $number_of_pages
45 *
46 * @property string $open_graph_title
47 * @property string $open_graph_description
48 * @property string $open_graph_image
49 * @property string $open_graph_image_id
50 * @property string $open_graph_image_source
51 * @property string $open_graph_image_meta
52 *
53 * @property string $twitter_title
54 * @property string $twitter_description
55 * @property string $twitter_image
56 * @property string $twitter_image_id
57 * @property string $twitter_image_source
58 * @property string $twitter_card
59 *
60 * @property int $prominent_words_version
61 *
62 * @property bool $is_public
63 * @property bool $is_protected
64 * @property string $post_status
65 * @property bool $has_public_posts
66 *
67 * @property int $blog_id
68 *
69 * @property string $language
70 * @property string $region
71 *
72 * @property string $schema_page_type
73 * @property string $schema_article_type
74 *
75 * @property bool $has_ancestors
76 *
77 * @property int $estimated_reading_time_minutes
78 *
79 * @property string $object_last_modified
80 * @property string $object_published_at
81 *
82 * @property int $version
83 */
84 class Indexable extends Model {
85
86 /**
87 * Holds the ancestors.
88 *
89 * @var Indexable[]
90 */
91 public $ancestors = [];
92
93 /**
94 * Whether nor this model uses timestamps.
95 *
96 * @var bool
97 */
98 protected $uses_timestamps = true;
99
100 /**
101 * Which columns contain boolean values.
102 *
103 * @var array
104 */
105 protected $boolean_columns = [
106 'is_robots_noindex',
107 'is_robots_nofollow',
108 'is_robots_noarchive',
109 'is_robots_noimageindex',
110 'is_robots_nosnippet',
111 'is_cornerstone',
112 'is_public',
113 'is_protected',
114 'has_public_posts',
115 ];
116
117 /**
118 * Which columns contain int values.
119 *
120 * @var array
121 */
122 protected $int_columns = [
123 'id',
124 'object_id',
125 'author_id',
126 'post_parent',
127 'primary_focus_keyword_score',
128 'readability_score',
129 'link_count',
130 'incoming_link_count',
131 'number_of_pages',
132 'prominent_words_version',
133 'blog_id',
134 'estimated_reading_time_minutes',
135 'version',
136 ];
137
138 /**
139 * The loaded indexable extensions.
140 *
141 * @var Indexable_Extension[]
142 */
143 protected $loaded_extensions = [];
144
145 /**
146 * Returns an Indexable_Extension by its name.
147 *
148 * @param string $class_name The class name of the extension to load.
149 *
150 * @return Indexable_Extension|bool The extension.
151 */
152 public function get_extension( $class_name ) {
153 if ( ! $this->loaded_extensions[ $class_name ] ) {
154 $this->loaded_extensions[ $class_name ] = $this->has_one( $class_name, 'indexable_id', 'id' )->find_one();
155 }
156
157 return $this->loaded_extensions[ $class_name ];
158 }
159
160 /**
161 * Enhances the save method.
162 *
163 * @return bool True on success.
164 */
165 public function save() {
166 if ( $this->permalink ) {
167 $this->sanitize_permalink();
168 $this->permalink_hash = \strlen( $this->permalink ) . ':' . \md5( $this->permalink );
169 }
170 if ( is_string( $this->primary_focus_keyword ) && \mb_strlen( $this->primary_focus_keyword ) > 191 ) {
171 $this->primary_focus_keyword = \mb_substr( $this->primary_focus_keyword, 0, 191, 'UTF-8' );
172 }
173
174 return parent::save();
175 }
176
177 /**
178 * Sanitizes the permalink.
179 *
180 * @return void
181 */
182 protected function sanitize_permalink() {
183 if ( $this->permalink === 'unindexed' ) {
184 return;
185 }
186
187 $permalink_structure = \get_option( 'permalink_structure' );
188 $permalink_parts = \wp_parse_url( $this->permalink );
189
190 if ( ! isset( $permalink_parts['path'] ) ) {
191 $permalink_parts['path'] = '/';
192 }
193 if ( \substr( $permalink_structure, -1, 1 ) === '/' && \strpos( \substr( $permalink_parts['path'], -5 ), '.' ) === false ) {
194 $permalink_parts['path'] = \trailingslashit( $permalink_parts['path'] );
195 }
196
197 $permalink = '';
198 if ( isset( $permalink_parts['scheme'] ) ) {
199 $permalink .= $permalink_parts['scheme'] . '://';
200 }
201 if ( isset( $permalink_parts['host'] ) ) {
202 $permalink .= $permalink_parts['host'];
203 }
204 if ( isset( $permalink_parts['port'] ) ) {
205 $permalink .= ':' . $permalink_parts['port'];
206 }
207 if ( isset( $permalink_parts['path'] ) ) {
208 $permalink .= $permalink_parts['path'];
209 }
210 if ( isset( $permalink_parts['query'] ) ) {
211 $permalink .= '?' . $permalink_parts['query'];
212 }
213 // We never set the fragment as the fragment is intended to be client-only.
214 $this->permalink = $permalink;
215 }
216 }
217