PluginProbe
WPSSO Core – Complete Schema Markup and Meta Tags / 22.7.0
WPSSO Core – Complete Schema Markup and Meta Tags v22.7.0
22.7.0 22.6.1 22.6.0 22.5.3 22.5.2 22.5.1 22.4.0 22.3.0 22.2.1 22.2.0 22.1.3 22.1.2 22.1.1 22.1.0 22.0.0 21.13.3 21.13.2 trunk 21.13.1
wpsso / lib / edit-prev.php

edit-prev.php in WPSSO Core – Complete Schema Markup and Meta Tags 22.7.0, at lib/edit-prev.php

169 lines 6.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * License: GPLv3
4 * License URI: https://www.gnu.org/licenses/gpl.txt
5 * Copyright 2020-2026 Jean-Sebastien Morisset (https://wpsso.com/)
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9
10 die( 'These aren\'t the droids you\'re looking for.' );
11 }
12
13 if ( ! defined( 'WPSSO_PLUGINDIR' ) ) {
14
15 die( 'Do. Or do not. There is no try.' );
16 }
17
18 if ( ! class_exists( 'WpssoEditPrev' ) ) {
19
20 class WpssoEditPrev {
21
22 private $p; // Wpsso class object.
23
24 public function __construct( &$plugin ) {
25
26 $this->p =& $plugin;
27
28 if ( $this->p->debug->enabled ) {
29
30 $this->p->debug->mark();
31 }
32
33 /*
34 * See WpssoAbstractWpMeta->get_document_sso_tabs().
35 */
36 $this->p->util->add_plugin_filters( $this, array(
37 'mb_sso_prev_social_rows' => 4,
38 'mb_sso_prev_oembed_rows' => 4,
39 ), PHP_INT_MIN ); // Run before any add-on filters.
40 }
41
42 public function filter_mb_sso_prev_social_rows( $table_rows, $form, $head_info, $mod ) {
43
44 $og_prev_width = 600;
45 $og_prev_height = 315;
46 $og_prev_img_html = '';
47
48 $image_url = SucomUtil::get_first_mt_media_url( $head_info );
49 $canonical_url = $this->p->util->get_canonical_url( $mod, $add_page = false );
50 $shortlink_url = $mod[ 'is_post' ] ?
51 $this->p->util->get_shortlink( $mod, $context = 'post' ) :
52 $this->p->util->shorten_url( $canonical_url, $mod );
53
54 $have_sizes = isset( $head_info[ 'og:image:width' ] ) && $head_info[ 'og:image:width' ] > 0 &&
55 isset( $head_info[ 'og:image:height' ] ) && $head_info[ 'og:image:height' ] > 0 ? true : false;
56
57 $is_sufficient = true === $have_sizes && $head_info[ 'og:image:width' ] >= $og_prev_width &&
58 $head_info[ 'og:image:height' ] >= $og_prev_height ? true : false;
59
60 if ( ! empty( $image_url ) ) {
61
62 if ( $have_sizes ) {
63
64 $og_prev_img_html .= '<div class="fb_preview_img" style=" background-size:' ;
65
66 if ( $is_sufficient ) {
67
68 $og_prev_img_html .= 'cover';
69
70 } else {
71
72 $og_prev_img_html .= $head_info[ 'og:image:width' ] . 'px ' . $head_info[ 'og:image:height' ] . 'px';
73 }
74
75 $og_prev_img_html .= '; background-image:url(' . $image_url . ');" />';
76
77 if ( ! $is_sufficient ) {
78
79 $og_prev_img_html .= '<p>' . sprintf( _x( 'Image Size Smaller<br/>than Suggested Minimum<br/>of %s',
80 'preview image error', 'wpsso' ), $og_prev_width . 'x' . $og_prev_height . 'px' ) . '</p>';
81 }
82
83 $og_prev_img_html .= '</div>';
84
85 } else {
86
87 $og_prev_img_html .= '<div class="fb_preview_img" style="background-image:url(' . $image_url . ');" />';
88 $og_prev_img_html .= '<p>' . _x( 'Image Size Unknown<br/>or Not Available', 'preview image error', 'wpsso' ) . '</p>';
89 $og_prev_img_html .= '</div>';
90 }
91
92 } else {
93
94 $og_prev_img_html .= '<div class="fb_preview_img">';
95 $og_prev_img_html .= '<p>' . _x( 'No Open Graph Image Found', 'preview image error', 'wpsso' ) . '</p>';
96 $og_prev_img_html .= '</div>';
97 }
98
99 $table_rows[ 'prev_canonical_url' ] = '' .
100 $form->get_th_html( _x( 'Canonical URL', 'option label', 'wpsso' ), $css_class = 'medium nowrap' ) .
101 '<td>' . $form->get_no_input_clipboard( $canonical_url ) . '</td>';
102
103 $table_rows[ 'prev_shortlink_url' ] = '' .
104 $form->get_th_html( _x( 'Shortlink URL', 'option label', 'wpsso' ), $css_class = 'medium nowrap' ) .
105 '<td>' . $form->get_no_input_clipboard( $shortlink_url ) . '</td>';
106
107 $table_rows[ 'subsection_prev_og' ] = '<td colspan="2" class="subsection"><h4>' .
108 _x( 'Facebook / Open Graph Example', 'metabox title', 'wpsso' ) . '</h4></td>';
109
110 $table_rows[ 'prev_og' ] = '' .
111 '<td colspan="2" class="fb_preview_container">
112 <div class="fb_preview_box_border">
113 <div class="fb_preview_box">
114 ' . $og_prev_img_html . '
115 <div class="fb_preview_text">
116 <div class="fb_preview_title">' .
117 ( empty( $head_info[ 'og:title' ] ) ? '' : $head_info[ 'og:title' ] ) .
118 '</div><!-- .fb_preview_title -->
119 <div class="fb_preview_desc">' .
120 ( empty( $head_info[ 'og:description' ] ) ? '' : $head_info[ 'og:description' ] ) .
121 '</div><!-- .fb_preview_desc -->
122 <div class="fb_preview_by">' .
123 $_SERVER[ 'SERVER_NAME' ] .
124 ( empty( $this->p->options[ 'add_meta_property_article:author' ] ) ||
125 empty( $head_info[ 'article:author:name' ] ) ?
126 '' : ' | By ' . $head_info[ 'article:author:name' ] ) .
127 '</div><!-- .fb_preview_by -->
128 </div><!-- .fb_preview_text -->
129 </div><!-- .fb_preview_box -->
130 </div><!-- .fb_preview_box_border -->
131 </td><!-- .fb_preview_container -->';
132
133 $table_rows[ 'prev_og_footer' ] = '<td colspan="2">' . $this->p->msgs->get( 'info-meta-social-preview' ) . '</td>';
134
135 return $table_rows;
136 }
137
138 public function filter_mb_sso_prev_oembed_rows( $table_rows, $form, $head_info, $mod ) {
139
140 $json_url = $this->p->util->get_oembed_url( $mod, 'json' );
141 $xml_url = $this->p->util->get_oembed_url( $mod, 'xml' );
142 $data = $this->p->util->get_oembed_data( $mod, $oembed_width = 600 ); // Returns false on error.
143
144 $table_rows[ 'oembed_json_url' ] = '' .
145 $form->get_th_html( _x( 'oEmbed JSON URL', 'option label', 'wpsso' ), $css_class = 'medium' ) .
146 '<td>' . $form->get_no_input_clipboard( $json_url ) . '</td>';
147
148 $table_rows[ 'oembed_xml_url' ] = '' .
149 $form->get_th_html( _x( 'oEmbed XML URL', 'option label', 'wpsso' ), $css_class = 'medium' ) .
150 '<td>' . $form->get_no_input_clipboard( $xml_url ) . '</td>';
151
152 $table_rows[ 'subsection_oembed_html' ] = '<td colspan="2" class="subsection"><h4>' .
153 _x( 'oEmbed HTML', 'metabox title', 'wpsso' ) . '</h4></td>';
154
155 if ( ! empty( $data[ 'html' ] ) ) {
156
157 $table_rows[ 'oembed_html' ] = '<td colspan="2" class="oembed_container">' . $data[ 'html' ] . '</td><!-- .oembed_container -->';
158 $table_rows[ 'oembed_footer' ] = '<td colspan="2">' . $this->p->msgs->get( 'info-meta-oembed-footer' ) . '</td>';
159
160 } else {
161
162 $table_rows[ 'no_oembed_html' ] = '<td colspan="2"><p class="status-msg">' . __( 'oEmbed HTML Not Available.', 'wpsso' ) . '</p></td>';
163 }
164
165 return $table_rows;
166 }
167 }
168 }
169