1 | <?php |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
2 | /** |
||
0 ignored issues
–
show
|
|||
3 | * @author Podlove <[email protected]> |
||
4 | * @copyright Copyright (c) 2014-2018, Podlove |
||
5 | * @license https://github.com/podlove/podlove-subscribe-button-wp-plugin/blob/master/LICENSE MIT |
||
6 | * @package Podlove\PodloveSubscribeButton |
||
7 | */ |
||
8 | |||
9 | namespace PodloveSubscribeButton; |
||
10 | |||
11 | include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
||
0 ignored issues
–
show
|
|||
12 | |||
13 | class Widget extends \WP_Widget { |
||
0 ignored issues
–
show
|
|||
14 | |||
15 | public static $widget_settings = array( |
||
0 ignored issues
–
show
|
|||
16 | 'infotext', |
||
17 | 'title', |
||
18 | 'size', |
||
19 | 'style', |
||
20 | 'format', |
||
21 | 'autowidth', |
||
22 | 'button', |
||
23 | 'color', |
||
24 | ); |
||
25 | |||
26 | public function __construct() { |
||
0 ignored issues
–
show
|
|||
27 | parent::__construct( |
||
28 | 'podlove_subscribe_button_wp_plugin_widget', |
||
29 | ( \PodloveSubscribeButton\is_podlove_publisher_active() ? 'Podlove Subscribe Button (WordPress plugin)' : 'Podlove Subscribe Button' ), |
||
30 | array( 'description' => __( 'Adds a Podlove Subscribe Button to your Sidebar', 'podlove-subscribe-button' ), ) |
||
0 ignored issues
–
show
|
|||
31 | ); |
||
32 | |||
33 | } |
||
34 | |||
35 | public function widget( $args, $instance ) { |
||
0 ignored issues
–
show
|
|||
36 | // Fetch the (network)button by it's name |
||
0 ignored issues
–
show
|
|||
37 | if ( ! $button = \PodloveSubscribeButton\Model\Button::get_button_by_name( $instance[ 'button' ] ) ) { |
||
0 ignored issues
–
show
|
|||
38 | return sprintf( __( 'Oops. There is no button with the ID "%s".', 'podlove-subscribe-button' ), $args['button'] ); |
||
0 ignored issues
–
show
|
|||
39 | } |
||
40 | |||
41 | echo $args[ 'before_widget' ]; |
||
0 ignored issues
–
show
|
|||
42 | echo $args[ 'before_title' ] . apply_filters( 'widget_title', $instance[ 'title' ] ) . $args[ 'after_title' ]; |
||
0 ignored issues
–
show
|
|||
43 | |||
44 | echo $button->render( |
||
0 ignored issues
–
show
|
|||
45 | \PodloveSubscribeButton::get_array_value_with_fallback( $instance, 'size' ), |
||
46 | \PodloveSubscribeButton::get_array_value_with_fallback( $instance, 'autowidth' ), |
||
0 ignored issues
–
show
|
|||
47 | \PodloveSubscribeButton::get_array_value_with_fallback( $instance, 'style' ), |
||
0 ignored issues
–
show
|
|||
48 | \PodloveSubscribeButton::get_array_value_with_fallback( $instance, 'format' ), |
||
0 ignored issues
–
show
|
|||
49 | \PodloveSubscribeButton::get_array_value_with_fallback( $instance, 'color' ) |
||
0 ignored issues
–
show
|
|||
50 | ); |
||
51 | |||
52 | if ( strlen( $instance[ 'infotext' ] ) ) { |
||
0 ignored issues
–
show
|
|||
53 | echo wpautop( $instance[ 'infotext' ] ); |
||
0 ignored issues
–
show
|
|||
54 | } |
||
55 | |||
56 | echo $args[ 'after_widget' ]; |
||
0 ignored issues
–
show
|
|||
57 | |||
58 | } |
||
59 | |||
60 | public function form( $instance ) { |
||
0 ignored issues
–
show
|
|||
61 | $title = isset( $instance[ 'title' ] ) ? $instance[ 'title' ] : ''; |
||
0 ignored issues
–
show
|
|||
62 | $button = isset( $instance[ 'button' ] ) ? $instance[ 'button' ] : ''; |
||
0 ignored issues
–
show
|
|||
63 | $size = isset( $instance[ 'size' ] ) ? $instance[ 'size' ] : 'big'; |
||
0 ignored issues
–
show
|
|||
64 | $style = isset( $instance[ 'style' ] ) ? $instance[ 'style' ] : 'filled'; |
||
0 ignored issues
–
show
|
|||
65 | $format = isset( $instance[ 'format' ] ) ? $instance[ 'format' ] : 'cover'; |
||
0 ignored issues
–
show
|
|||
66 | $autowidth = isset( $instance[ 'autowidth' ] ) ? $instance[ 'autowidth' ] : true; |
||
0 ignored issues
–
show
|
|||
67 | $infotext = isset( $instance[ 'infotext' ] ) ? $instance[ 'infotext' ] : ''; |
||
0 ignored issues
–
show
|
|||
68 | $color = isset( $instance[ 'color' ] ) ? $instance[ 'color' ] : '#75ad91'; |
||
0 ignored issues
–
show
|
|||
69 | |||
70 | $buttons = \PodloveSubscribeButton\Model\Button::all(); |
||
71 | if ( is_multisite() ) { |
||
72 | $network_buttons = \PodloveSubscribeButton\Model\NetworkButton::all(); |
||
73 | } |
||
74 | ?> |
||
75 | <p> |
||
76 | <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title', 'podlove-subscribe-button' ); ?></label> |
||
0 ignored issues
–
show
|
|||
77 | <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $title; ?>" /> |
||
0 ignored issues
–
show
|
|||
78 | <label for="<?php echo $this->get_field_id( 'color' ); ?>"><?php _e( 'Color', 'podlove-subscribe-button' ); ?></label> |
||
0 ignored issues
–
show
|
|||
79 | <input class="podlove_subscribe_button_color" id="<?php echo $this->get_field_id( 'color' ); ?>" name="<?php echo $this->get_field_name( 'color' ); ?>" value="<?php echo $color; ?>" /> |
||
0 ignored issues
–
show
|
|||
80 | <style type="text/css"> |
||
81 | .sp-replacer { |
||
82 | display: flex; |
||
83 | } |
||
84 | .sp-preview { |
||
85 | flex-grow: 10; |
||
86 | } |
||
87 | </style> |
||
88 | <label for="<?php echo $this->get_field_id( 'button' ); ?>"><?php _e( 'Button', 'podlove-subscribe-button' ); ?></label> |
||
0 ignored issues
–
show
|
|||
89 | <select class="widefat" id="<?php echo $this->get_field_id( 'button' ); ?>" |
||
0 ignored issues
–
show
|
|||
90 | name="<?php echo $this->get_field_name( 'button' ); ?>"> |
||
0 ignored issues
–
show
|
|||
91 | <?php if ( isset( $network_buttons ) && count( $network_buttons ) > 0 ) : ?> |
||
92 | <optgroup label="<?php _e( 'Local', 'podlove-subscribe-button' ); ?>"> |
||
0 ignored issues
–
show
|
|||
93 | <?php |
||
94 | foreach ( $buttons as $subscribebutton ) { |
||
95 | echo "<option value='" . $subscribebutton->name . "' " . selected( $subscribebutton->name, $button ) . " >" . $subscribebutton->title . " (" . $subscribebutton->name . ")</option>"; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
> does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() Coding Style
Comprehensibility
introduced
by
The string literal
( does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() Coding Style
Comprehensibility
introduced
by
The string literal
)</option> does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||
96 | } ?> |
||
0 ignored issues
–
show
|
|||
97 | </optgroup> |
||
98 | <optgroup label="<?php _e( 'Network', 'podlove-subscribe-button' ); ?>"> |
||
0 ignored issues
–
show
|
|||
99 | <?php |
||
100 | foreach ( $network_buttons as $subscribebutton ) { |
||
101 | echo "<option value='" . $subscribebutton->name . "' " . selected( $subscribebutton->name, $button ) . " >" . $subscribebutton->title . " (" . $subscribebutton->name . ")</option>"; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
> does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() Coding Style
Comprehensibility
introduced
by
The string literal
( does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() Coding Style
Comprehensibility
introduced
by
The string literal
)</option> does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||
102 | } ?> |
||
0 ignored issues
–
show
|
|||
103 | </optgroup> |
||
104 | <?php else : |
||
0 ignored issues
–
show
|
|||
105 | foreach ( $buttons as $subscribebutton ) { |
||
106 | echo "<option value='" . $subscribebutton->name . "' " . selected( $subscribebutton->name, $button ) . " >" . $subscribebutton->title . " (" . $subscribebutton->name . ")</option>"; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
> does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() Coding Style
Comprehensibility
introduced
by
The string literal
( does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() Coding Style
Comprehensibility
introduced
by
The string literal
)</option> does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||
107 | } |
||
108 | endif; ?> |
||
0 ignored issues
–
show
|
|||
109 | </select> |
||
110 | <?php |
||
111 | $customize_options = array( |
||
112 | 'size' => array( |
||
113 | 'name' => __( 'Size', 'podlove-subscribe-button' ), |
||
114 | 'options' => \PodloveSubscribeButton\Model\Button::$size |
||
0 ignored issues
–
show
|
|||
115 | ), |
||
116 | 'style' => array( |
||
117 | 'name' => __( 'Style', 'podlove-subscribe-button' ), |
||
118 | 'options' => \PodloveSubscribeButton\Model\Button::$style |
||
0 ignored issues
–
show
|
|||
119 | ), |
||
120 | 'format' => array( |
||
121 | 'name' => __( 'Format', 'podlove-subscribe-button' ), |
||
122 | 'options' => \PodloveSubscribeButton\Model\Button::$format |
||
0 ignored issues
–
show
|
|||
123 | ), |
||
124 | 'autowidth' => array( |
||
125 | 'name' => __( 'Autowidth', 'podlove-subscribe-button' ), |
||
126 | 'options' => \PodloveSubscribeButton\Model\Button::$width |
||
0 ignored issues
–
show
|
|||
127 | ) |
||
0 ignored issues
–
show
|
|||
128 | ); |
||
129 | |||
130 | foreach ( $customize_options as $slug => $properties ) : ?> |
||
0 ignored issues
–
show
|
|||
131 | <label for="<?php echo $this->get_field_id( $slug ); ?>"><?php echo $properties[ 'name' ]; ?></label> |
||
0 ignored issues
–
show
|
|||
132 | <select class="widefat" id="<?php echo $this->get_field_id( $slug ); ?>" name="<?php echo $this->get_field_name( $slug ); ?>"> |
||
0 ignored issues
–
show
|
|||
133 | <option value="default" <?php echo ( $$slug == 'default' ? 'selected="selected"' : '' ); ?>><?php printf( __( 'Default %s', 'podlove-subscribe-button' ), $properties[ 'name' ] ) ?></option> |
||
0 ignored issues
–
show
|
|||
134 | <optgroup> |
||
135 | <?php foreach ( $properties[ 'options' ] as $property => $name ) : ?> |
||
0 ignored issues
–
show
|
|||
136 | <option value="<?php echo $property; ?>" <?php echo ( $$slug == $property ? 'selected="selected"' : '' ); ?>><?php echo $name; ?></option> |
||
0 ignored issues
–
show
|
|||
137 | <?php endforeach; ?> |
||
138 | </optgroup> |
||
139 | </select> |
||
140 | <?php endforeach; ?> |
||
141 | <label for="<?php echo $this->get_field_id( 'infotext' ); ?>"><?php _e( 'Description', 'podlove-subscribe-button' ); ?></label> |
||
0 ignored issues
–
show
|
|||
142 | <textarea class="widefat" rows="10" id="<?php echo $this->get_field_id( 'infotext' ); ?>" name="<?php echo $this->get_field_name( 'infotext' ); ?>"><?php echo $infotext; ?></textarea> |
||
0 ignored issues
–
show
|
|||
143 | </p> |
||
144 | <?php |
||
145 | |||
146 | } |
||
147 | |||
148 | public function update( $new_instance, $old_instance ) { |
||
0 ignored issues
–
show
|
|||
149 | $instance = array(); |
||
150 | |||
151 | foreach ( self::$widget_settings as $setting ) { |
||
152 | $instance[ $setting ] = ( ! empty( $new_instance[ $setting ] ) ) ? strip_tags( $new_instance[ $setting ] ) : ''; |
||
0 ignored issues
–
show
|
|||
153 | } |
||
154 | |||
155 | return $instance; |
||
156 | |||
157 | } |
||
158 | |||
159 | } // END class |
||
160 |