From cac1b8c84eef9d07ec7691509b46192459a09660 Mon Sep 17 00:00:00 2001
From: Grzegorz Rola <grola@seostudio.pl>
Date: Sat, 22 Jan 2022 18:33:40 +0100
Subject: [PATCH] feature(petition): added text petition

---
 CHANGELOG.md                                  |  4 ++
 composer.json                                 |  5 +-
 src/DisplayStrategy/DisplayDecision.php       | 17 +++++++
 .../GetParametersDisplayDecision.php          | 46 +++++++++++++++++++
 src/TextPetition.php                          | 33 +++++++++++++
 src/views/html-text-petition.php              | 15 ++++++
 6 files changed, 118 insertions(+), 2 deletions(-)
 create mode 100644 src/DisplayStrategy/DisplayDecision.php
 create mode 100644 src/DisplayStrategy/GetParametersDisplayDecision.php
 create mode 100644 src/TextPetition.php
 create mode 100644 src/views/html-text-petition.php

diff --git a/CHANGELOG.md b/CHANGELOG.md
index d78b275..d564d5f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## [1.2.0] - 2022-01-24
+### Changes
+- Added TextPetition
+
 ## [1.1.0] - 2019-12-02
 ### Changes
 - RatingPetitionNotice can get url to redirect user when wants to rate
diff --git a/composer.json b/composer.json
index 12d2005..bb88d1d 100644
--- a/composer.json
+++ b/composer.json
@@ -7,8 +7,9 @@
         }
     ],
     "require": {
-        "php": ">=5.6",
-        "wpdesk/wp-notice": "^3.1"
+        "php": ">=7.0",
+        "wpdesk/wp-notice": "^3.1",
+        "wpdesk/wp-plugin-flow": "^3.1"
     },
     "require-dev": {
         "phpunit/phpunit": "<7",
diff --git a/src/DisplayStrategy/DisplayDecision.php b/src/DisplayStrategy/DisplayDecision.php
new file mode 100644
index 0000000..c12d45f
--- /dev/null
+++ b/src/DisplayStrategy/DisplayDecision.php
@@ -0,0 +1,17 @@
+<?php
+
+namespace WPDesk\RepositoryRating\DisplayStrategy;
+
+/**
+ * ShouldDisplay interface.
+ */
+interface DisplayDecision {
+
+	/**
+	 * Returns true when element should be displayed.
+	 *
+	 * @return bool
+	 */
+	public function should_display();
+
+}
\ No newline at end of file
diff --git a/src/DisplayStrategy/GetParametersDisplayDecision.php b/src/DisplayStrategy/GetParametersDisplayDecision.php
new file mode 100644
index 0000000..a96f42e
--- /dev/null
+++ b/src/DisplayStrategy/GetParametersDisplayDecision.php
@@ -0,0 +1,46 @@
+<?php
+
+namespace WPDesk\RepositoryRating\DisplayStrategy;
+
+/**
+ * DisplayDecision based on GET parameters.
+ */
+class GetParametersDisplayDecision implements DisplayDecision {
+
+	/**
+	 * Whether to show beacon on the page or not. Array of arrays with condition for _GET.
+	 * Inner arrays mean AND, outer arrays mean OR conditions.
+	 *
+	 * ie. [ [ ... and ... and ... ] or [ ... and ... and ... ] or ... ]
+	 *
+	 * @var array
+	 */
+	private $conditions;
+
+	public function __construct( array $conditions ) {
+		$this->conditions = $conditions;
+	}
+
+	/**
+	 * Should Beacon be visible?
+	 *
+	 * @return bool
+	 */
+	public function should_display(): bool {
+		foreach ( $this->conditions as $or_conditions ) {
+			$display = true;
+			foreach ( $or_conditions as $parameter => $value ) {
+				if ( ! isset( $_GET[ $parameter ] ) || $_GET[ $parameter ] !== $value ) {
+					$display = false;
+				}
+			}
+			if ( $display ) {
+
+				return $display;
+			}
+		}
+
+		return false;
+	}
+
+}
\ No newline at end of file
diff --git a/src/TextPetition.php b/src/TextPetition.php
new file mode 100644
index 0000000..04c4d88
--- /dev/null
+++ b/src/TextPetition.php
@@ -0,0 +1,33 @@
+<?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;
+
+	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() ) {
+
+		}
+	}
+
+}
\ No newline at end of file
diff --git a/src/views/html-text-petition.php b/src/views/html-text-petition.php
new file mode 100644
index 0000000..18e89ed
--- /dev/null
+++ b/src/views/html-text-petition.php
@@ -0,0 +1,15 @@
+<?php
+
+?><div class="aligncenter">
+	Created with
+	<span class="fcfSettings__footerIcon fcfSettings__footerIcon--heart"></span>
+	by Rangers from <a href="https://wpde.sk/fcf-settings-footer-wpdesk-link-pl" target="_blank">WP Desk</a>
+	- if you like FCF
+	<a href="https://wpde.sk/fcf-settings-footer-review-link-pl" target="_blank">rate us
+		<span class="fcfSettings__footerIcon fcfSettings__footerIcon--star"></span>
+		<span class="fcfSettings__footerIcon fcfSettings__footerIcon--star"></span>
+		<span class="fcfSettings__footerIcon fcfSettings__footerIcon--star"></span>
+		<span class="fcfSettings__footerIcon fcfSettings__footerIcon--star"></span>
+		<span class="fcfSettings__footerIcon fcfSettings__footerIcon--star"></span>
+	</a>
+</div>
\ No newline at end of file
-- 
GitLab