diff --git a/src/PetitionText.php b/src/PetitionText.php new file mode 100644 index 0000000000000000000000000000000000000000..8026d6c24b50d69a8cb449c5bc12dfe5e480d990 --- /dev/null +++ b/src/PetitionText.php @@ -0,0 +1,17 @@ +<?php + +namespace WPDesk\RepositoryRating; + +/** + * Petition text generator. + */ +interface PetitionText { + + /** + * Returns petition text. + * + * @return string + */ + public function get_petition_text(): string; + +} \ No newline at end of file diff --git a/src/RepositoryRatingPetitionText.php b/src/RepositoryRatingPetitionText.php new file mode 100644 index 0000000000000000000000000000000000000000..9a206aa22b57892f127d92e1e6dd58d9cf719ad9 --- /dev/null +++ b/src/RepositoryRatingPetitionText.php @@ -0,0 +1,53 @@ +<?php + +namespace WPDesk\RepositoryRating; + +class RepositoryRatingPetitionText implements PetitionText { + + /** + * @var string + */ + private $plugin_author; + + /** + * @var string + */ + private $plugin_title; + + /** + * @var string + */ + private $rating_url; + + /** + * @var string + */ + private $text_align; + + /** + * @param string $plugin_author + * @param string $plugin_title + * @param string $rating_url + * @param string $text_align + */ + public function __construct( string $plugin_author, string $plugin_title, string $rating_url, string $text_align ) { + $this->plugin_author = $plugin_author; + $this->plugin_title = $plugin_title; + $this->rating_url = $rating_url; + $this->text_align = $text_align; + } + + /** + * @inheritDoc + */ + public function get_petition_text(): string { + ob_start(); + $plugin_author = $this->plugin_author; + $plugin_title = $this->plugin_title; + $rating_url = $this->rating_url; + $text_align = $this->text_align; + include __DIR__ . '/views/html-text-petition.php'; + + return ob_get_clean(); + } +} \ No newline at end of file diff --git a/src/TextPetition.php b/src/TextPetition.php deleted file mode 100644 index 661ee2512897fa70614737d51bb6cd5643ebb8aa..0000000000000000000000000000000000000000 --- a/src/TextPetition.php +++ /dev/null @@ -1,76 +0,0 @@ -<?php - -namespace WPDesk\RepositoryRating; - -use WPDesk\PluginBuilder\Plugin\Hookable; -use WPDesk\RepositoryRating\DisplayStrategy\DisplayDecision; - -/** - * Can display text petition. - */ -class TextPetition implements Hookable { - - /** - * @var string - */ - private $display_on_action; - - /** - * @var DisplayDecision - */ - private $display_decision; - - - /** - * @var string - */ - private $text_align; - - /** - * @var string - */ - private $plugin_author; - - /** - * @var string - */ - private $plugin_title; - - /** - * @var string - */ - private $rating_url; - - /** - * @param string $display_on_action - * @param DisplayDecision $display_decision - * @param string $plugin_author - * @param string $plugin_title - * @param string $rating_url - * @param string $text_align - */ - public function __construct( string $display_on_action, DisplayDecision $display_decision, string $plugin_author, string $plugin_title, string $rating_url, string $text_align = 'center' ) { - $this->display_on_action = $display_on_action; - $this->display_decision = $display_decision; - $this->text_align = $text_align; - $this->plugin_author = $plugin_author; - $this->plugin_title = $plugin_title; - $this->rating_url = $rating_url; - } - - - public function hooks() { - add_action( $this->display_on_action, [ $this, 'display_petition_if_should' ] ); - } - - public function display_petition_if_should() { - if ( $this->display_decision->should_display() ) { - $text_align = $this->text_align; - $plugin_author = $this->plugin_author; - $plugin_title = $this->plugin_title; - $rating_url = $this->rating_url; - include __DIR__ . '/views/html-text-petition.php'; - } - } - -} diff --git a/src/TextPetitionDisplayer.php b/src/TextPetitionDisplayer.php new file mode 100644 index 0000000000000000000000000000000000000000..3fd0f1fbaff94fbf6ca9561d7ae02ce5daf419a7 --- /dev/null +++ b/src/TextPetitionDisplayer.php @@ -0,0 +1,49 @@ +<?php + +namespace WPDesk\RepositoryRating; + +use WPDesk\PluginBuilder\Plugin\Hookable; +use WPDesk\RepositoryRating\DisplayStrategy\DisplayDecision; + +/** + * Can display text petition. + */ +class TextPetitionDisplayer implements Hookable { + + /** + * @var string + */ + private $display_on_action; + + /** + * @var DisplayDecision + */ + private $display_decision; + + /** + * @var PetitionText + */ + private $petition_text_generator; + + /** + * @param string $display_on_action + * @param DisplayDecision $display_decision + * @param PetitionText $petition_text_generator + */ + public function __construct( string $display_on_action, DisplayDecision $display_decision, PetitionText $petition_text_generator ) { + $this->display_on_action = $display_on_action; + $this->display_decision = $display_decision; + $this->petition_text_generator = $petition_text_generator; + } + + public function hooks() { + add_action( $this->display_on_action, [ $this, 'display_petition_if_should' ] ); + } + + public function display_petition_if_should() { + if ( $this->display_decision->should_display() ) { + echo wp_kses_post( $this->petition_text_generator->get_petition_text() ); + } + } + +}