PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.5
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.5
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 28.5, at src/models/indexable.php

226 lines 5.4 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 $inclusive_language_score
43 *
44 * @property int $seo_title_score
45 * @property int $meta_description_score
46 *
47 * @property int $link_count
48 * @property int $incoming_link_count
49 * @property int $number_of_pages
50 *
51 * @property string $open_graph_title
52 * @property string $open_graph_description
53 * @property string $open_graph_image
54 * @property string $open_graph_image_id
55 * @property string $open_graph_image_source
56 * @property string $open_graph_image_meta
57 *
58 * @property string $twitter_title
59 * @property string $twitter_description
60 * @property string $twitter_image
61 * @property string $twitter_image_id
62 * @property string $twitter_image_source
63 * @property string $twitter_card
64 *
65 * @property int $prominent_words_version
66 *
67 * @property bool $is_public
68 * @property bool $is_protected
69 * @property string $post_status
70 * @property bool $has_public_posts
71 *
72 * @property int $blog_id
73 *
74 * @property string $language
75 * @property string $region
76 *
77 * @property string $schema_page_type
78 * @property string $schema_article_type
79 *
80 * @property bool $has_ancestors
81 *
82 * @property int $estimated_reading_time_minutes
83 *
84 * @property string $object_last_modified
85 * @property string $object_published_at
86 *
87 * @property int $version
88 */
89 class Indexable extends Model {
90
91 /**
92 * Holds the ancestors.
93 *
94 * @var Indexable[]
95 */
96 public $ancestors = [];
97
98 /**
99 * Whether nor this model uses timestamps.
100 *
101 * @var bool
102 */
103 protected $uses_timestamps = true;
104
105 /**
106 * Which columns contain boolean values.
107 *
108 * @var array
109 */
110 protected $boolean_columns = [
111 'is_robots_noindex',
112 'is_robots_nofollow',
113 'is_robots_noarchive',
114 'is_robots_noimageindex',
115 'is_robots_nosnippet',
116 'is_cornerstone',
117 'is_public',
118 'is_protected',
119 'has_public_posts',
120 'has_ancestors',
121 ];
122
123 /**
124 * Which columns contain int values.
125 *
126 * @var array
127 */
128 protected $int_columns = [
129 'id',
130 'object_id',
131 'author_id',
132 'post_parent',
133 'primary_focus_keyword_score',
134 'readability_score',
135 'inclusive_language_score',
136 'seo_title_score',
137 'meta_description_score',
138 'link_count',
139 'incoming_link_count',
140 'number_of_pages',
141 'prominent_words_version',
142 'blog_id',
143 'estimated_reading_time_minutes',
144 'version',
145 ];
146
147 /**
148 * The loaded indexable extensions.
149 *
150 * @var Indexable_Extension[]
151 */
152 protected $loaded_extensions = [];
153
154 /**
155 * Returns an Indexable_Extension by its name.
156 *
157 * @param string $class_name The class name of the extension to load.
158 *
159 * @return Indexable_Extension|bool The extension.
160 */
161 public function get_extension( $class_name ) {
162 if ( ! $this->loaded_extensions[ $class_name ] ) {
163 $this->loaded_extensions[ $class_name ] = $this->has_one( $class_name, 'indexable_id', 'id' )->find_one();
164 }
165
166 return $this->loaded_extensions[ $class_name ];
167 }
168
169 /**
170 * Enhances the save method.
171 *
172 * @return bool True on success.
173 */
174 public function save() {
175 if ( $this->permalink ) {
176 $this->sanitize_permalink();
177 $this->permalink_hash = \strlen( $this->permalink ) . ':' . \md5( $this->permalink );
178 }
179 if ( \is_string( $this->primary_focus_keyword ) && \mb_strlen( $this->primary_focus_keyword ) > 191 ) {
180 $this->primary_focus_keyword = \mb_substr( $this->primary_focus_keyword, 0, 191, 'UTF-8' );
181 }
182
183 return parent::save();
184 }
185
186 /**
187 * Sanitizes the permalink.
188 *
189 * @return void
190 */
191 protected function sanitize_permalink() {
192 if ( $this->permalink === 'unindexed' ) {
193 return;
194 }
195
196 $permalink_structure = \get_option( 'permalink_structure' );
197 $permalink_parts = \wp_parse_url( $this->permalink );
198
199 if ( ! isset( $permalink_parts['path'] ) ) {
200 $permalink_parts['path'] = '/';
201 }
202 if ( \substr( $permalink_structure, -1, 1 ) === '/' && \strpos( \substr( $permalink_parts['path'], -5 ), '.' ) === false ) {
203 $permalink_parts['path'] = \trailingslashit( $permalink_parts['path'] );
204 }
205
206 $permalink = '';
207 if ( isset( $permalink_parts['scheme'] ) ) {
208 $permalink .= $permalink_parts['scheme'] . '://';
209 }
210 if ( isset( $permalink_parts['host'] ) ) {
211 $permalink .= $permalink_parts['host'];
212 }
213 if ( isset( $permalink_parts['port'] ) ) {
214 $permalink .= ':' . $permalink_parts['port'];
215 }
216 if ( isset( $permalink_parts['path'] ) ) {
217 $permalink .= $permalink_parts['path'];
218 }
219 if ( isset( $permalink_parts['query'] ) ) {
220 $permalink .= '?' . $permalink_parts['query'];
221 }
222 // We never set the fragment as the fragment is intended to be client-only.
223 $this->permalink = $permalink;
224 }
225 }
226