| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Presenters\Slack; |
| 4 |
|
| 5 |
use Yoast\WP\SEO\Presentations\Indexable_Presentation; |
| 6 |
use Yoast\WP\SEO\Presenters\Abstract_Indexable_Presenter; |
| 7 |
|
| 8 |
/** |
| 9 |
* Presenter class for the Slack enhanced data. |
| 10 |
*/ |
| 11 |
class Enhanced_Data_Presenter extends Abstract_Indexable_Presenter { |
| 12 |
|
| 13 |
/** |
| 14 |
* The tag key name. |
| 15 |
* |
| 16 |
* @var string |
| 17 |
*/ |
| 18 |
protected $key = 'twitter:misc'; |
| 19 |
|
| 20 |
/** |
| 21 |
* Presents the enhanced data for Slack |
| 22 |
* |
| 23 |
* @return string The Twitter tags for Slack. |
| 24 |
*/ |
| 25 |
public function present() { |
| 26 |
$enhanced_data = $this->get(); |
| 27 |
$twitter_tags = ''; |
| 28 |
$i = 1; |
| 29 |
foreach ( $enhanced_data as $label => $value ) { |
| 30 |
$twitter_tags .= \sprintf( "\t" . '<meta name="twitter:label%1$d" content="%2$s" />' . "\n", $i, $label ); |
| 31 |
$twitter_tags .= \sprintf( "\t" . '<meta name="twitter:data%1$d" content="%2$s" />' . "\n", $i, $value ); |
| 32 |
++$i; |
| 33 |
} |
| 34 |
return \trim( $twitter_tags ); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Gets the enhanced data array. |
| 39 |
* |
| 40 |
* @return array The enhanced data array |
| 41 |
*/ |
| 42 |
public function get() { |
| 43 |
$data = []; |
| 44 |
$author_id = $this->presentation->source->post_author; |
| 45 |
$estimated_reading_time = $this->presentation->estimated_reading_time_minutes; |
| 46 |
|
| 47 |
if ( $this->presentation->model->object_sub_type === 'post' && $author_id ) { |
| 48 |
$data[ \__( 'Written by', 'wordpress-seo' ) ] = \get_the_author_meta( 'display_name', $author_id ); |
| 49 |
} |
| 50 |
|
| 51 |
if ( ! empty( $estimated_reading_time ) ) { |
| 52 |
/* translators: %s expands to the reading time number, in minutes */ |
| 53 |
$data[ \__( 'Est. reading time', 'wordpress-seo' ) ] = \sprintf( \_n( '%s minute', '%s minutes', $estimated_reading_time, 'default' ), $estimated_reading_time ); |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Filter: 'wpseo_enhanced_slack_data' - Allows filtering of the enhanced data for sharing on Slack. |
| 58 |
* |
| 59 |
* @api array $data The enhanced Slack sharing data. |
| 60 |
* |
| 61 |
* @param Indexable_Presentation $presentation The presentation of an indexable. |
| 62 |
*/ |
| 63 |
return \apply_filters( 'wpseo_enhanced_slack_data', $data, $this->presentation ); |
| 64 |
} |
| 65 |
} |
| 66 |
|