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

218 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 'has_ancestors',
116 ];
117
118 /**
119 * Which columns contain int values.
120 *
121 * @var array
122 */
123 protected $int_columns = [
124 'id',
125 'object_id',
126 'author_id',
127 'post_parent',
128 'primary_focus_keyword_score',
129 'readability_score',
130 'link_count',
131 'incoming_link_count',
132 'number_of_pages',
133 'prominent_words_version',
134 'blog_id',
135 'estimated_reading_time_minutes',
136 'version',
137 ];
138
139 /**
140 * The loaded indexable extensions.
141 *
142 * @var Indexable_Extension[]
143 */
144 protected $loaded_extensions = [];
145
146 /**
147 * Returns an Indexable_Extension by its name.
148 *
149 * @param string $class_name The class name of the extension to load.
150 *
151 * @return Indexable_Extension|bool The extension.
152 */
153 public function get_extension( $class_name ) {
154 if ( ! $this->loaded_extensions[ $class_name ] ) {
155 $this->loaded_extensions[ $class_name ] = $this->has_one( $class_name, 'indexable_id', 'id' )->find_one();
156 }
157
158 return $this->loaded_extensions[ $class_name ];
159 }
160
161 /**
162 * Enhances the save method.
163 *
164 * @return bool True on success.
165 */
166 public function save() {
167 if ( $this->permalink ) {
168 $this->sanitize_permalink();
169 $this->permalink_hash = \strlen( $this->permalink ) . ':' . \md5( $this->permalink );
170 }
171 if ( \is_string( $this->primary_focus_keyword ) && \mb_strlen( $this->primary_focus_keyword ) > 191 ) {
172 $this->primary_focus_keyword = \mb_substr( $this->primary_focus_keyword, 0, 191, 'UTF-8' );
173 }
174
175 return parent::save();
176 }
177
178 /**
179 * Sanitizes the permalink.
180 *
181 * @return void
182 */
183 protected function sanitize_permalink() {
184 if ( $this->permalink === 'unindexed' ) {
185 return;
186 }
187
188 $permalink_structure = \get_option( 'permalink_structure' );
189 $permalink_parts = \wp_parse_url( $this->permalink );
190
191 if ( ! isset( $permalink_parts['path'] ) ) {
192 $permalink_parts['path'] = '/';
193 }
194 if ( \substr( $permalink_structure, -1, 1 ) === '/' && \strpos( \substr( $permalink_parts['path'], -5 ), '.' ) === false ) {
195 $permalink_parts['path'] = \trailingslashit( $permalink_parts['path'] );
196 }
197
198 $permalink = '';
199 if ( isset( $permalink_parts['scheme'] ) ) {
200 $permalink .= $permalink_parts['scheme'] . '://';
201 }
202 if ( isset( $permalink_parts['host'] ) ) {
203 $permalink .= $permalink_parts['host'];
204 }
205 if ( isset( $permalink_parts['port'] ) ) {
206 $permalink .= ':' . $permalink_parts['port'];
207 }
208 if ( isset( $permalink_parts['path'] ) ) {
209 $permalink .= $permalink_parts['path'];
210 }
211 if ( isset( $permalink_parts['query'] ) ) {
212 $permalink .= '?' . $permalink_parts['query'];
213 }
214 // We never set the fragment as the fragment is intended to be client-only.
215 $this->permalink = $permalink;
216 }
217 }
218