GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 0392a4...4f7518 )
by Christian
02:13
created

model/button.php (2 issues)

1
<?php
2
namespace PodloveSubscribeButton\Model;
3
4
class Button extends Base {
5
6
	public static $properties = array(
7
		// $property => $default value
8
		'size'      => 'big',
9
		'color'     => '#599677',
10
		'autowidth' => 'on',
11
		'style'     => 'filled',
12
		'format'    => 'rectangle',
13
		'hide'      => 'false',
14
		'buttonid'  => ''
15
		// Note: the fields 'language' and 'json-data' cannot be set here (No function call allowed within class variables)
16
	);
17
18
	public static $style = array(
19
		'filled'    => 'Filled',
20
		'outline'   => 'Outline',
21
		'frameless' => 'Frameless'
22
	);
23
24
	public static $format = array(
25
		'rectangle' => 'Rectangle',
26
		'square'    => 'Square',
27
		'cover'     => 'Cover'
28
	);
29
30
	public static $width = array(
31
		'on'  => 'Yes',
32
		'off' => 'No'
33
	);
34
35
	public static $size = array(
36
		'small'  => 'Small',
37
		'medium' => 'Medium',
38
		'big'    => 'Big'
39
	);
40
41
42
	/**
43
	 * Fetches a Button or Network Button with a specific name
44
	 * @param  string $name
45
	 * @return object||FALSE
46
	 */
47
	public static function get_button_by_name( $name ) {
48
		if ( $button = \PodloveSubscribeButton\Model\Button::find_one_by_property( 'name', $name ) ) {
49
			return $button;
50
		}
51
52
		if ( $network_button = \PodloveSubscribeButton\Model\NetworkButton::find_one_by_property( 'name', $name ) ) {
53
			$network_button->id = $network_button->id . 'N';
54
			return $network_button;
55
		}
56
57
		return false;
58
59
	}
60
61
	/**
62
	 * Returns either global buttons settings or the default settings
63
	 * @param  array
64
	 * @return array
65
	 */
66
	public static function get_global_setting_with_fallback( $settings = array() ) {
67
		foreach ( self::$properties as $property => $default ) {
68
			$settings[ $property ] = ( get_option( 'podlove_subscribe_button_default_' . $property ) ? get_option( 'podlove_subscribe_button_default_' . $property ) : $default );
69
		}
70
71
		return $settings;
72
	}
73
74
	/**
75
	 * Gathers all information and renders the Subscribe button.
76
	 * @param  string  $size
77
	 * @param  string  $autowidth
78
	 * @param  string  $style
79
	 * @param  string  $format
80
	 * @param  string  $color
81
	 * @param  boolean $hide
82
	 * @param  boolean $buttonid
83
	 * @return string
84
	 */
85
	public function render( $size = 'big', $autowidth = 'on', $style = 'filled', $format = 'rectangle', $color = '#599677', $hide = false, $buttonid = false, $language = 'en' ) {
86
		$button_styling = array_merge(
87
			$this->get_button_styling( $size, $autowidth, $style, $format, $color ),
88
			array(
89
				'hide'     => $hide,
90
				'buttonid' => $buttonid,
91
				'language' => $language
92
			)
93
		);
94
95
		return $this->provide_button_html(
96
			array(
97
				'title'       => $this->title,
98
				'subtitle'    => $this->subtitle,
99
				'description' => $this->description,
100
				'cover'       => $this->cover,
101
				'feeds'       => $this->get_feeds_as_array( $this->feeds )
102
			),
103
			$button_styling
104
		);
105
	}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
106
107
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$feeds" missing
Loading history...
108
	 * Provides the feed as an array in the required format
109
	 * @return array
110
	 */
111
	private function get_feeds_as_array( $feeds = array() ) {
112
		foreach ( $feeds as $feed ) {
113
			if ( isset( \PodloveSubscribeButton\MediaTypes::$audio[ $feed[ 'format' ] ][ 'extension' ] ) ) {
114
				$new_feed = array(
115
					'type'    => 'audio',
116
					'format'  => \PodloveSubscribeButton\MediaTypes::$audio[ $feed['format'] ]['extension'],
117
					'url'     => $feed['url'],
118
					'variant' => 'high',
119
				);
120
121
				if ( isset( $feed[ 'itunesfeedid' ] ) && $feed[ 'itunesfeedid' ] > 0 ) {
122
					$new_feed['directory-url-itunes'] = "https://itunes.apple.com/podcast/id" . $feed['itunesfeedid'];
123
				}
124
125
				$feeds[] = $new_feed;
126
127
			}
128
		}
129
130
		return $feeds;
131
	}
132
133
	/**
134
	 * Provides the HTML source of the Subscribe Button
135
	 * @param  array $podcast_data
136
	 * @param  array $button_styling
137
	 * @param  string $data_attributes
138
	 * @return string
139
	 */
140
	private function provide_button_html( $podcast_data, $button_styling, $data_attributes = "" ) {
141
		// Create data attributes for Button
142
		foreach ( $button_styling as $attribute => $value ) {
143
			$data_attributes .= 'data-' . $attribute . '="' . $value . '" ';
144
		}
145
146
		return"
147
			<script>
148
				podcastData".$this->id . " = " . json_encode( $podcast_data ) . "
149
			</script>
150
			<script 
151
				class=\"podlove-subscribe-button\" 
152
				src=\"https://cdn.podlove.org/subscribe-button/javascripts/app.js\" " . $data_attributes . ">
153
			</script>
154
		";
155
	}
156
157
	/**
158
	 * Returns an array with either the set or default values
159
	 * @param  string $size
160
	 * @param  string $autowidth
161
	 * @param  string $style
162
	 * @param  string $format
163
	 * @param  string $color
164
	 * @return array
165
	 */
166
	public function get_button_styling( $size, $autowidth, $style, $format, $color ) {
167
168
		return array(
169
				// $attribute => $value
170
				'size' => ( $size == 'default' ? get_option( 'podlove_subscribe_button_default_size', $size ) : $size )
171
			 	. self::interpret_autowidth_attribute( $autowidth ),
172
				'style' => ( $style == 'default' ? get_option( 'podlove_subscribe_button_default_style', $style ) : $style ),
173
				'format' => ( $format == 'default' ? get_option( 'podlove_subscribe_button_default_format', $format ) : $format ),
174
				'color' => ( isset( $color ) ? $color : get_option( 'podlove_subscribe_button_default_color', $color ) ),
175
				'json-data' => 'podcastData' . $this->id
176
			);
177
	}
178
179
	/**
180
	 * Helper function to interpret the given $autowidth value correctly
181
	 * @param  string $autowidth
182
	 * @return string
183
	 */
184
	private static function interpret_autowidth_attribute( $autowidth ) {
185
		if ( $autowidth == 'default' && get_option( 'podlove_subscribe_button_default_autowidth' ) !== 'on' )
186
			return '';
187
188
		if ( $autowidth !== 'default' && $autowidth !== 'on' )
189
			return '';
190
191
		return ' auto';
192
	}
193
}
194
195
Button::property( 'id', 'INT NOT NULL AUTO_INCREMENT PRIMARY KEY' );
196
Button::property( 'name', 'VARCHAR(255)' );
197
Button::property( 'title', 'VARCHAR(255)' );
198
Button::property( 'subtitle', 'VARCHAR(255)' );
199
Button::property( 'description', 'TEXT' );
200
Button::property( 'cover', 'VARCHAR(255)' );
201
Button::property( 'feeds', 'TEXT' );