| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPSEO plugin file. |
| 4 |
* |
| 5 |
* @package WPSEO\Admin\Views |
| 6 |
*/ |
| 7 |
|
| 8 |
use Yoast\WP\SEO\Presenters\Admin\Alert_Presenter; |
| 9 |
|
| 10 |
/** |
| 11 |
* Class Yoast_View_Utils. |
| 12 |
*/ |
| 13 |
class Yoast_View_Utils { |
| 14 |
|
| 15 |
/** |
| 16 |
* Form to use. |
| 17 |
* |
| 18 |
* @var Yoast_Form |
| 19 |
*/ |
| 20 |
protected $form; |
| 21 |
|
| 22 |
/** |
| 23 |
* Yoast_View_Utils constructor. |
| 24 |
*/ |
| 25 |
public function __construct() { |
| 26 |
$this->form = Yoast_Form::get_instance(); |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Shows the search results help question mark and help section. |
| 31 |
* |
| 32 |
* Used for all the Help sections for indexable objects like post types, taxonomies, or archives. |
| 33 |
* |
| 34 |
* @param string|object $post_type The post type to show the search results help for. |
| 35 |
* @param string $help_text_switch Switch the help text to one that's more appropriate |
| 36 |
* for the indexable object type the help section is for. |
| 37 |
* |
| 38 |
* @return object The help panel instance. |
| 39 |
*/ |
| 40 |
public function search_results_setting_help( $post_type, $help_text_switch = '' ) { |
| 41 |
if ( ! is_object( $post_type ) ) { |
| 42 |
$post_type = get_post_type_object( $post_type ); |
| 43 |
} |
| 44 |
|
| 45 |
/* translators: 1: expands to an indexable object's name, like a post type or taxonomy; 2: expands to <code>noindex</code>; 3: link open tag; 4: link close tag. */ |
| 46 |
$help_text = esc_html__( 'Not showing %1$s in the search results technically means those will have a %2$s robots meta and will be excluded from XML sitemaps. %3$sMore info on the search results settings%4$s.', 'wordpress-seo' ); |
| 47 |
|
| 48 |
if ( $help_text_switch === 'archive' ) { |
| 49 |
/* translators: 1: expands to an indexable object's name, like a post type or taxonomy; 2: expands to <code>noindex</code>; 3: link open tag; 4: link close tag. */ |
| 50 |
$help_text = esc_html__( 'Not showing the archive for %1$s in the search results technically means those will have a %2$s robots meta and will be excluded from XML sitemaps. %3$sMore info on the search results settings%4$s.', 'wordpress-seo' ); |
| 51 |
} |
| 52 |
|
| 53 |
$help_panel = new WPSEO_Admin_Help_Panel( |
| 54 |
// Sometimes the same post type is used more than once in the same page, we need a unique ID though. |
| 55 |
uniqid( 'noindex-' . $post_type->name ), |
| 56 |
esc_html__( 'Help on this search results setting', 'wordpress-seo' ), |
| 57 |
sprintf( |
| 58 |
$help_text, |
| 59 |
$post_type->labels->name, |
| 60 |
'<code>noindex</code>', |
| 61 |
'<a href="' . esc_url( WPSEO_Shortlinker::get( 'https://yoa.st/show-x' ) ) . '" target="_blank" rel="noopener noreferrer">', |
| 62 |
'</a>' |
| 63 |
) |
| 64 |
); |
| 65 |
|
| 66 |
return $help_panel; |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Generates the OpenGraph disabled alert, depending on whether the OpenGraph feature is disabled. |
| 71 |
* |
| 72 |
* @param string $type The type of message. Can be altered to homepage, taxonomies or archives. Empty string by default. |
| 73 |
* |
| 74 |
* @return string The alert. Returns an empty string if the setting is enabled. |
| 75 |
*/ |
| 76 |
public function generate_opengraph_disabled_alert( $type = '' ) { |
| 77 |
$is_enabled = WPSEO_Options::get( 'opengraph', true ); |
| 78 |
|
| 79 |
if ( $is_enabled ) { |
| 80 |
return ''; |
| 81 |
} |
| 82 |
|
| 83 |
$message = $this->generate_opengraph_disabled_alert_text( $type ); |
| 84 |
|
| 85 |
if ( empty( $message ) ) { |
| 86 |
return ''; |
| 87 |
} |
| 88 |
|
| 89 |
$alert = new Alert_Presenter( $message, 'info' ); |
| 90 |
|
| 91 |
return sprintf( |
| 92 |
'<div class="yoast-measure padded">%s</div>', |
| 93 |
$alert->present() |
| 94 |
); |
| 95 |
} |
| 96 |
|
| 97 |
/** |
| 98 |
* Generates the OpenGraph disabled alert text. |
| 99 |
* |
| 100 |
* @param string $type The type of message. Can be altered to homepage, taxonomies or archives. Empty string by default. |
| 101 |
* |
| 102 |
* @return string The alert. Returns an empty string if the setting is enabled. |
| 103 |
*/ |
| 104 |
private function generate_opengraph_disabled_alert_text( $type ) { |
| 105 |
if ( $type === 'homepage' ) { |
| 106 |
return sprintf( |
| 107 |
/* translators: 1: link open tag; 2: link close tag. */ |
| 108 |
esc_html__( |
| 109 |
'The social appearance settings for your homepage require Open Graph metadata (which is currently disabled). You can enable this in the %1$s‘Social’ settings under the ‘Facebook’ tab%2$s.', |
| 110 |
'wordpress-seo' |
| 111 |
), |
| 112 |
'<a href="' . esc_url( admin_url( 'admin.php?page=wpseo_social#top#facebook' ) ) . '">', |
| 113 |
'</a>' |
| 114 |
); |
| 115 |
} |
| 116 |
|
| 117 |
if ( ! YoastSEO()->helpers->product->is_premium() ) { |
| 118 |
return ''; |
| 119 |
} |
| 120 |
|
| 121 |
if ( $type === '' ) { |
| 122 |
return sprintf( |
| 123 |
/* translators: 1: link open tag; 2: link close tag. */ |
| 124 |
esc_html__( |
| 125 |
'The social appearance settings for content types require Open Graph metadata (which is currently disabled). You can enable this in the %1$s‘Social’ settings under the ‘Facebook’ tab%2$s.', |
| 126 |
'wordpress-seo' |
| 127 |
), |
| 128 |
'<a href="' . esc_url( admin_url( 'admin.php?page=wpseo_social#top#facebook' ) ) . '">', |
| 129 |
'</a>' |
| 130 |
); |
| 131 |
} |
| 132 |
|
| 133 |
if ( $type === 'taxonomies' ) { |
| 134 |
return sprintf( |
| 135 |
/* translators: 1: link open tag; 2: link close tag. */ |
| 136 |
esc_html__( |
| 137 |
'The social appearance settings for taxonomies require Open Graph metadata (which is currently disabled). You can enable this in the %1$s‘Social’ settings under the ‘Facebook’ tab%2$s.', |
| 138 |
'wordpress-seo' |
| 139 |
), |
| 140 |
'<a href="' . esc_url( admin_url( 'admin.php?page=wpseo_social#top#facebook' ) ) . '">', |
| 141 |
'</a>' |
| 142 |
); |
| 143 |
} |
| 144 |
|
| 145 |
if ( $type === 'archives' ) { |
| 146 |
return sprintf( |
| 147 |
/* translators: 1: link open tag; 2: link close tag. */ |
| 148 |
esc_html__( |
| 149 |
'The social appearance settings for archives require Open Graph metadata (which is currently disabled). You can enable this in the %1$s‘Social’ settings under the ‘Facebook’ tab%2$s.', |
| 150 |
'wordpress-seo' |
| 151 |
), |
| 152 |
'<a href="' . esc_url( admin_url( 'admin.php?page=wpseo_social#top#facebook' ) ) . '">', |
| 153 |
'</a>' |
| 154 |
); |
| 155 |
} |
| 156 |
|
| 157 |
return ''; |
| 158 |
} |
| 159 |
} |
| 160 |
|