From 07f89ac06b7aa57c603acfef52c7b138e9f36eaf Mon Sep 17 00:00:00 2001 From: Grzegorz Rola <grola@seostudio.pl> Date: Sun, 23 Jan 2022 12:51:25 +0100 Subject: [PATCH] feature(petition): added text petition --- src/PetitionText.php | 17 +++++++ src/RepositoryRatingPetitionText.php | 53 +++++++++++++++++++ src/TextPetition.php | 76 ---------------------------- src/TextPetitionDisplayer.php | 49 ++++++++++++++++++ 4 files changed, 119 insertions(+), 76 deletions(-) create mode 100644 src/PetitionText.php create mode 100644 src/RepositoryRatingPetitionText.php delete mode 100644 src/TextPetition.php create mode 100644 src/TextPetitionDisplayer.php diff --git a/src/PetitionText.php b/src/PetitionText.php new file mode 100644 index 0000000..8026d6c --- /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 0000000..9a206aa --- /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 661ee25..0000000 --- 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 0000000..3fd0f1f --- /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() ); + } + } + +} -- GitLab