PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.2
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.2
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 / presentations / indexable-date-archive-presentation.php

indexable-date-archive-presentation.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.2, at src/presentations/indexable-date-archive-presentation.php

124 lines 2.8 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\Presentations;
4
5 use Yoast\WP\SEO\Helpers\Pagination_Helper;
6
7 /**
8 * Class Indexable_Date_Archive_Presentation.
9 *
10 * Presentation object for indexables.
11 */
12 class Indexable_Date_Archive_Presentation extends Indexable_Presentation {
13
14 /**
15 * Holds the Pagination_Helper instance.
16 *
17 * @var Pagination_Helper
18 */
19 protected $pagination;
20
21 /**
22 * Indexable_Date_Archive_Presentation constructor.
23 *
24 * @param Pagination_Helper $pagination The pagination helper.
25 */
26 public function __construct( Pagination_Helper $pagination ) {
27 $this->pagination = $pagination;
28 }
29
30 /**
31 * Generates the canonical.
32 *
33 * @return string The canonical.
34 */
35 public function generate_canonical() {
36 $canonical = $this->current_page->get_date_archive_permalink();
37
38 $current_page = $this->pagination->get_current_archive_page_number();
39 if ( $current_page > 1 ) {
40 return $this->pagination->get_paginated_url( $canonical, $current_page );
41 }
42
43 return $canonical;
44 }
45
46 /**
47 * Generates the robots value.
48 *
49 * @return array The robots value.
50 */
51 public function generate_robots() {
52 $robots = $this->get_base_robots();
53
54 if ( $this->options->get( 'noindex-archive-wpseo', false ) ) {
55 $robots['index'] = 'noindex';
56 }
57
58 return $this->filter_robots( $robots );
59 }
60
61 /**
62 * Generates the title.
63 *
64 * @return string The title.
65 */
66 public function generate_title() {
67 if ( $this->model->title ) {
68 return $this->model->title;
69 }
70
71 return $this->options->get_title_default( 'title-archive-wpseo' );
72 }
73
74 /**
75 * Generates the rel prev.
76 *
77 * @return string The rel prev value.
78 */
79 public function generate_rel_prev() {
80 if ( $this->pagination->is_rel_adjacent_disabled() ) {
81 return '';
82 }
83
84 $current_page = \max( 1, $this->pagination->get_current_archive_page_number() );
85 // Check if there is a previous page.
86 if ( $current_page === 1 ) {
87 return '';
88 }
89 // Check if the previous page is the first page.
90 if ( $current_page === 2 ) {
91 return $this->current_page->get_date_archive_permalink();
92 }
93
94 return $this->pagination->get_paginated_url( $this->current_page->get_date_archive_permalink(), ( $current_page - 1 ) );
95 }
96
97 /**
98 * Generates the rel next.
99 *
100 * @return string The rel prev next.
101 */
102 public function generate_rel_next() {
103 if ( $this->pagination->is_rel_adjacent_disabled() ) {
104 return '';
105 }
106
107 $current_page = \max( 1, $this->pagination->get_current_archive_page_number() );
108 if ( $this->pagination->get_number_of_archive_pages() <= $current_page ) {
109 return '';
110 }
111
112 return $this->pagination->get_paginated_url( $this->current_page->get_date_archive_permalink(), ( $current_page + 1 ) );
113 }
114
115 /**
116 * Generates the open graph url.
117 *
118 * @return string The open graph url.
119 */
120 public function generate_open_graph_url() {
121 return $this->current_page->get_date_archive_permalink();
122 }
123 }
124