PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.3
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.3
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 19.1 All 128 releases
wordpress-seo / admin / class-paper-presenter.php

class-paper-presenter.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.3, at admin/class-paper-presenter.php

142 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPSEO plugin file.
4 *
5 * @package WPSEO\Admin
6 */
7
8 /**
9 * Class WPSEO_presenter_paper.
10 */
11 class WPSEO_Paper_Presenter {
12
13 /**
14 * Title of the paper.
15 *
16 * @var string
17 */
18 private $title;
19
20 /**
21 * The view variables.
22 *
23 * @var array
24 */
25 private $settings;
26
27 /**
28 * The path to the view file.
29 *
30 * @var string
31 */
32 private $view_file;
33
34 /**
35 * WPSEO_presenter_paper constructor.
36 *
37 * @param string $title The title of the paper.
38 * @param string|null $view_file Optional. The path to the view file. Use the content setting
39 * if do not wish to use a view file.
40 * @param array $settings Optional. Settings for the paper.
41 */
42 public function __construct( $title, $view_file = null, array $settings = [] ) {
43 $defaults = [
44 'paper_id' => null,
45 'paper_id_prefix' => 'wpseo-',
46 'collapsible' => false,
47 'collapsible_header_class' => '',
48 'expanded' => false,
49 'help_text' => '',
50 'title_after' => '',
51 'class' => '',
52 'content' => '',
53 'view_data' => [],
54 ];
55
56 $this->settings = wp_parse_args( $settings, $defaults );
57 $this->title = $title;
58 $this->view_file = $view_file;
59 }
60
61 /**
62 * Renders the collapsible paper and returns it as a string.
63 *
64 * @return string The rendered paper.
65 */
66 public function get_output() {
67 $view_variables = $this->get_view_variables();
68
69 extract( $view_variables, EXTR_SKIP );
70
71 $content = $this->settings['content'];
72
73 if ( $this->view_file !== null ) {
74 ob_start();
75 require $this->view_file;
76 $content = ob_get_clean();
77 }
78
79 ob_start();
80 require WPSEO_PATH . 'admin/views/paper-collapsible.php';
81 $rendered_output = ob_get_clean();
82
83 return $rendered_output;
84 }
85
86 /**
87 * Retrieves the view variables.
88 *
89 * @return array The view variables.
90 */
91 private function get_view_variables() {
92 if ( $this->settings['help_text'] instanceof WPSEO_Admin_Help_Panel === false ) {
93 $this->settings['help_text'] = new WPSEO_Admin_Help_Panel( '', '', '' );
94 }
95
96 $view_variables = [
97 'class' => $this->settings['class'],
98 'collapsible' => $this->settings['collapsible'],
99 'collapsible_config' => $this->collapsible_config(),
100 'collapsible_header_class' => $this->settings['collapsible_header_class'],
101 'title_after' => $this->settings['title_after'],
102 'help_text' => $this->settings['help_text'],
103 'view_file' => $this->view_file,
104 'title' => $this->title,
105 'paper_id' => $this->settings['paper_id'],
106 'paper_id_prefix' => $this->settings['paper_id_prefix'],
107 'yform' => Yoast_Form::get_instance(),
108 ];
109
110 return array_merge( $this->settings['view_data'], $view_variables );
111 }
112
113 /**
114 * Retrieves the collapsible config based on the settings.
115 *
116 * @return array The config.
117 */
118 protected function collapsible_config() {
119 if ( empty( $this->settings['collapsible'] ) ) {
120 return [
121 'toggle_icon' => '',
122 'class' => '',
123 'expanded' => '',
124 ];
125 }
126
127 if ( ! empty( $this->settings['expanded'] ) ) {
128 return [
129 'toggle_icon' => 'dashicons-arrow-up-alt2',
130 'class' => 'toggleable-container',
131 'expanded' => 'true',
132 ];
133 }
134
135 return [
136 'toggle_icon' => 'dashicons-arrow-down-alt2',
137 'class' => 'toggleable-container toggleable-container-hidden',
138 'expanded' => 'false',
139 ];
140 }
141 }
142