| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Presenters; |
| 4 |
|
| 5 |
use WPSEO_Replace_Vars; |
| 6 |
use Yoast\WP\SEO\Presentations\Indexable_Presentation; |
| 7 |
use Yoast\WP\SEO\Surfaces\Helpers_Surface; |
| 8 |
|
| 9 |
/** |
| 10 |
* Abstract presenter class for indexable presentations. |
| 11 |
*/ |
| 12 |
abstract class Abstract_Indexable_Presenter extends Abstract_Presenter { |
| 13 |
|
| 14 |
/** |
| 15 |
* The WPSEO Replace Vars object. |
| 16 |
* |
| 17 |
* @var WPSEO_Replace_Vars |
| 18 |
*/ |
| 19 |
public $replace_vars; |
| 20 |
|
| 21 |
/** |
| 22 |
* The indexable presentation. |
| 23 |
* |
| 24 |
* @var Indexable_Presentation |
| 25 |
*/ |
| 26 |
public $presentation; |
| 27 |
|
| 28 |
/** |
| 29 |
* The helpers surface |
| 30 |
* |
| 31 |
* @var Helpers_Surface |
| 32 |
*/ |
| 33 |
public $helpers; |
| 34 |
|
| 35 |
/** |
| 36 |
* The tag key name. |
| 37 |
* |
| 38 |
* @var string |
| 39 |
*/ |
| 40 |
protected $key = 'NO KEY PROVIDED'; |
| 41 |
|
| 42 |
/** |
| 43 |
* Gets the raw value of a presentation. |
| 44 |
* |
| 45 |
* @return string|array The raw value. |
| 46 |
*/ |
| 47 |
abstract public function get(); |
| 48 |
|
| 49 |
/** |
| 50 |
* Transforms an indexable presenter's key to a json safe key string. |
| 51 |
* |
| 52 |
* @return string|null |
| 53 |
*/ |
| 54 |
public function escape_key() { |
| 55 |
if ( $this->key === 'NO KEY PROVIDED' ) { |
| 56 |
return null; |
| 57 |
} |
| 58 |
return \str_replace( [ ':', ' ', '-' ], '_', $this->key ); |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Returns the metafield's property key. |
| 63 |
* |
| 64 |
* @return string The property key. |
| 65 |
*/ |
| 66 |
public function get_key() { |
| 67 |
return $this->key; |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Replace replacement variables in a string. |
| 72 |
* |
| 73 |
* @param string $string The string. |
| 74 |
* |
| 75 |
* @return string The string with replacement variables replaced. |
| 76 |
*/ |
| 77 |
protected function replace_vars( $string ) { |
| 78 |
return $this->replace_vars->replace( $string, $this->presentation->source ); |
| 79 |
} |
| 80 |
} |
| 81 |
|