Skip to content
Snippets Groups Projects
Commit c484c8ec authored by Grzegorz Rola's avatar Grzegorz Rola
Browse files

feature(petition): added text petition

parent 0dbc54c4
No related branches found
No related tags found
1 merge request!1feature(petition): added text petition
## [1.2.0] - 2022-01-24
### Changes
- Added TextPetition
## [1.1.0] - 2019-12-02 ## [1.1.0] - 2019-12-02
### Changes ### Changes
- RatingPetitionNotice can get url to redirect user when wants to rate - RatingPetitionNotice can get url to redirect user when wants to rate
......
.wpdesk-rating-petition {
font-size: 15px;
width: 100%;
}
.wpdesk-rating-petition a {
text-decoration: none;
color: inherit;
font-weight: 600;
}
.wpdesk-rating-petition span.plugin-title {
font-weight: 600;
}
.wpdesk-rating-petition span.heart {
speak: none;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
color: #dc3232;
font-size: 16px;
font-style: normal;
font-variant: normal;
font-weight: 400;
text-transform: none;
}
.wpdesk-rating-petition span.star {
speak: none;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
color: #ffb900;
font-size: 16px;
font-style: normal;
font-variant: normal;
font-weight: 400;
text-transform: none;
text-decoration: none;
}
...@@ -7,8 +7,9 @@ ...@@ -7,8 +7,9 @@
} }
], ],
"require": { "require": {
"php": ">=5.6", "php": ">=7.0",
"wpdesk/wp-notice": "^3.1" "wpdesk/wp-notice": "^3.1",
"wpdesk/wp-plugin-flow": "^3.1"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "<7", "phpunit/phpunit": "<7",
......
<?php
namespace WPDesk\RepositoryRating\DisplayStrategy;
/**
* DisplayDecision - always display.
*/
class AlwaysDisplayDisplayDecision implements DisplayDecision {
/**
* Should display?
*
* @return bool
*/
public function should_display(): bool {
return true;
}
}
\ No newline at end of file
<?php
namespace WPDesk\RepositoryRating\DisplayStrategy;
/**
* ShouldDisplay interface.
*/
interface DisplayDecision {
/**
* Returns true when element should be displayed.
*
* @return bool
*/
public function should_display(): bool;
}
\ No newline at end of file
<?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 display?
*
* @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
<?php
namespace WPDesk\RepositoryRating\DisplayStrategy;
class ShippingMethodDisplayDecision implements DisplayDecision {
/**
* @var \WC_Shipping_Zones
*/
private $shipping_zones;
/**
* @var string
*/
private $shipping_method_id;
/**
* @param \WC_Shipping_Zones $shipping_zones
* @param string $shipping_method_id
*/
public function __construct( \WC_Shipping_Zones $shipping_zones, string $shipping_method_id ) {
$this->shipping_zones = $shipping_zones;
$this->shipping_method_id = $shipping_method_id;
}
/**
* @inheritDoc
*/
public function should_display(): bool {
if ( $this->is_in_shipping_settings() ) {
if ( $this->is_get_parameter_with_value( 'section', $this->shipping_method_id ) ) {
return true;
}
if ( isset( $_GET['instance_id'] ) ) {
$shipping_method = $this->shipping_zones::get_shipping_method( sanitize_key( $_GET['instance_id'] ) );
if ( $shipping_method instanceof \WC_Shipping_Method ) {
return $shipping_method->id === $this->shipping_method_id;
}
}
}
return false;
}
private function is_in_shipping_settings(): bool {
if ( $this->is_get_parameter_with_value( 'page', 'wc-settings' ) && $this->is_get_parameter_with_value( 'tab', 'shipping' ) ) {
return true;
}
return false;
}
private function is_get_parameter_with_value( string $parameter, string $value ): bool {
return isset( $_GET[ $parameter ] ) && $_GET[ $parameter ] === $value;
}
}
\ No newline at end of file
<?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
<?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
<?php
namespace WPDesk\RepositoryRating;
use WPDesk\PluginBuilder\Plugin\Hookable;
use WPDesk\RepositoryRating\DisplayStrategy\DisplayDecision;
/**
* Can display text petition.
*/
class TextPetitionDisplayer implements Hookable {
const SCRIPTS_VERSION = '2';
/**
* @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' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_css_if_should' ] );
}
/**
* @internal
*/
public function enqueue_css_if_should() {
if ( $this->display_decision->should_display() ) {
wp_enqueue_style( 'wpdesk-rating-petition', plugin_dir_url( __DIR__ . '/../assets/css/style.css' ) . 'style.css', array(), self::SCRIPTS_VERSION );
}
}
/**
* @internal
*/
public function display_petition_if_should() {
if ( $this->display_decision->should_display() ) {
echo wp_kses_post( $this->petition_text_generator->get_petition_text() );
}
}
}
<?php
/**
* @var string $text_align
* @var string $plugin_author
* @var string $plugin_title
* @var string $rating_url
*/
?><div class="wpdesk-rating-petition" style="text-align: <?php echo esc_attr( $text_align ); ?>;">
<?php echo wp_kses_post(
sprintf(
__( 'Created with %1$s by %2$s - If you like %3$s you can %4$srate us %5$s in plugins repository%6$s', 'wp-wpdesk-rating-petition' ),
'<span class="heart">&hearts;</span>',
$plugin_author,
'<span class="plugin-title">' . $plugin_title . '</span>',
'<a href="' . $rating_url . '" target="_blank">',
'<span class="star">&#9733;&#9733;&#9733;&#9733;&#9733;</span>',
'</a>'
)
); ?>
</div>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment