Changeset 1416418
- Timestamp:
- 05/13/2016 04:50:36 PM (10 years ago)
- Location:
- podlove-subscribe-button
- Files:
-
- 33 added
- 12 edited
-
assets/banner-1544x500.jpg (added)
-
assets/banner-772x250.jpg (added)
-
assets/icon-128x128.jpg (modified) (previous)
-
assets/icon-256x256.jpg (modified) (previous)
-
assets/screenshot-1.png (modified) (previous)
-
assets/screenshot-2.png (modified) (previous)
-
assets/screenshot-3.png (modified) (previous)
-
assets/screenshot-4.png (modified) (previous)
-
tags/1.2 (added)
-
tags/1.2/LICENSE (added)
-
tags/1.2/README.md (added)
-
tags/1.2/fonts (added)
-
tags/1.2/fonts/Podlove.dev.svg (added)
-
tags/1.2/fonts/Podlove.eot (added)
-
tags/1.2/fonts/Podlove.svg (added)
-
tags/1.2/fonts/Podlove.ttf (added)
-
tags/1.2/fonts/Podlove.woff (added)
-
tags/1.2/js (added)
-
tags/1.2/js/admin.js (added)
-
tags/1.2/js/spectrum (added)
-
tags/1.2/js/spectrum/spectrum.css (added)
-
tags/1.2/js/spectrum/spectrum.js (added)
-
tags/1.2/media_types.php (added)
-
tags/1.2/model (added)
-
tags/1.2/model/base.php (added)
-
tags/1.2/model/button.php (added)
-
tags/1.2/model/network_button.php (added)
-
tags/1.2/podlove.php (added)
-
tags/1.2/readme.txt (added)
-
tags/1.2/settings (added)
-
tags/1.2/settings/buttons.php (added)
-
tags/1.2/settings/buttons_list_table.php (added)
-
tags/1.2/style.css (added)
-
tags/1.2/widget.php (added)
-
trunk/js (added)
-
trunk/js/admin.js (added)
-
trunk/js/spectrum (added)
-
trunk/js/spectrum/spectrum.css (added)
-
trunk/js/spectrum/spectrum.js (added)
-
trunk/model/button.php (modified) (1 diff)
-
trunk/podlove.php (modified) (3 diffs)
-
trunk/readme.txt (modified) (7 diffs)
-
trunk/settings/buttons.php (modified) (6 diffs)
-
trunk/settings/buttons_list_table.php (modified) (1 diff)
-
trunk/widget.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
podlove-subscribe-button/trunk/model/button.php
r1190247 r1416418 4 4 class Button extends Base { 5 5 6 public function render( $style='big-logo', $autowidth='on' ) { 7 $feeds = array(); 8 foreach ($this->feeds as $feed) { 9 $feeds[] = array( 10 'type' => 'audio', 11 'format' => \PodloveSubscribeButton\MediaTypes::$audio[$feed['format']]['extension'], 12 'url' => $feed['url'], 13 'variant' => 'high' 14 ); 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; 15 50 } 16 51 17 $podcast_data = array( 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 * Returns either global buttons settings or the default settings 62 * @param array 63 * @return array 64 */ 65 public static function get_global_setting_with_fallback( $settings=array() ) { 66 foreach (self::$properties as $property => $default) { 67 $settings[$property] = ( get_option('podlove_subscribe_button_default_' . $property) ? get_option('podlove_subscribe_button_default_' . $property) : $default ); 68 } 69 70 return $settings; 71 } 72 73 /** 74 * Gathers all information and renders the Subscribe button. 75 * @param string $size 76 * @param string $autowidth 77 * @param string $style 78 * @param string $format 79 * @param string $color 80 * @param boolean $hide 81 * @param boolean $buttonid 82 * @return string 83 */ 84 public function render( $size='big', $autowidth='on', $style='filled', $format='rectangle', $color='#599677', $hide = FALSE, $buttonid = FALSE ) { 85 return $this->provide_button_html( 86 array( 18 87 'title' => $this->title, 19 88 'subtitle' => $this->subtitle, 20 89 'description' => $this->description, 21 90 'cover' => $this->cover, 22 'feeds' => $feeds 23 ); 91 'feeds' => $this->get_feeds_as_array($this->feeds) 92 ), $this->get_button_styling($size, $autowidth, $style, $format, $color) ); 93 } 24 94 25 $apply_autowidth = function ($autowidth) { 26 if ( $autowidth == 'default' && get_option('podlove_subscribe_button_default_autowidth') == 'on' ) { 27 return ' auto'; 28 } elseif ( $autowidth == 'on' ) { 29 return ' auto'; 95 /** 96 * Provides the feed as an array in the required format 97 * @return array 98 */ 99 private function get_feeds_as_array( $feeds=array() ) { 100 foreach ($feeds as $feed) { 101 if ( isset(\PodloveSubscribeButton\MediaTypes::$audio[$feed['format']]['extension']) ) { 102 $new_feed = array( 103 'type' => 'audio', 104 'format' => \PodloveSubscribeButton\MediaTypes::$audio[$feed['format']]['extension'], 105 'url' => $feed['url'], 106 'variant' => 'high' 107 ); 108 109 if ( isset($feed['itunesfeedid']) && $feed['itunesfeedid'] > 0 ) 110 $new_feed['directory-url-itunes'] = "https://itunes.apple.com/podcast/id" . $feed['itunesfeedid']; 111 112 $feeds[] = $new_feed; 30 113 } 114 } 31 115 32 return '';33 };116 return $feeds; 117 } 34 118 35 $default_autowidth = get_option('podlove_subscribe_button_default_autowidth', 'on'); 119 /** 120 * Provides the HTML source of the Subscribe Button 121 * @param array $podcast_data 122 * @param array $button_styling 123 * @param string $data_attributes 124 * @return string 125 */ 126 private function provide_button_html($podcast_data, $button_styling, $data_attributes="") { 127 // Create data attributes for Button 128 foreach ($button_styling as $attribute => $value) { 129 $data_attributes .= 'data-' . $attribute . '="' . $value . '" '; 130 } 36 131 37 132 return" 38 133 <script> 39 podcastData".$this->id ." =".json_encode($podcast_data)."134 podcastData".$this->id . " = ".json_encode($podcast_data)." 40 135 </script> 41 <script class=\"podlove-subscribe-button\" src=\"https://cdn.podlove.org/subscribe-button/javascripts/app.js\" 42 data-language=\"".get_bloginfo('language')."\" data-size=\"" 43 . ( $style == 'default' ? get_option('podlove_subscribe_button_default_style', $style) : $style ) 44 . $apply_autowidth($autowidth) 45 . "\" data-json-data=\"podcastData".$this->id."\"></script> 136 <script 137 class=\"podlove-subscribe-button\" 138 src=\"https://cdn.podlove.org/subscribe-button/javascripts/app.js\" " . $data_attributes . "> 139 </script> 46 140 "; 47 141 } 48 142 143 /** 144 * Returns an array with either the set or default values 145 * @param string $size 146 * @param string $autowidth 147 * @param string $style 148 * @param string $format 149 * @param string $color 150 * @return array 151 */ 152 private function get_button_styling($size, $autowidth, $style, $format, $color) { 153 return array( 154 // $attribute => $value 155 'language' => get_bloginfo('language'), 156 'size' => ( $size == 'default' ? get_option('podlove_subscribe_button_default_size', $size) : $size ) 157 . self::interpret_autowidth_attribute($autowidth), 158 'style' => ( $style == 'default' ? get_option('podlove_subscribe_button_default_style', $style) : $style ), 159 'format' => ( $format == 'default' ? get_option('podlove_subscribe_button_default_format', $format) : $format ), 160 'color' => ( $color == 'default' ? get_option('podlove_subscribe_button_default_color', $color) : $color ), 161 'json-data' => 'podcastData' . $this->id 162 ); 163 } 164 165 /** 166 * Helper function to interpret the given $autowidth value correctly 167 * @param string $autowidth 168 * @return string 169 */ 170 private static function interpret_autowidth_attribute($autowidth) { 171 if ( $autowidth == 'default' && get_option('podlove_subscribe_button_default_autowidth') !== 'on' ) 172 return ''; 173 174 if ( $autowidth !== 'default' && $autowidth !== 'on' ) 175 return ''; 176 177 return ' auto'; 178 } 49 179 } 50 180 -
podlove-subscribe-button/trunk/podlove.php
r1190247 r1416418 4 4 * Plugin URI: http://wordpress.org/extend/plugins/podlove-subscribe-button/ 5 5 * Description: Brings the Podlove Subscribe Button to your WordPress installation. 6 * Version: 1. 1.36 * Version: 1.2 7 7 * Author: Podlove 8 8 * Author URI: http://podlove.org … … 42 42 wp_register_style( 'podlove-subscribe-button', plugin_dir_url(__FILE__).'style.css' ); 43 43 wp_enqueue_style( 'podlove-subscribe-button' ); 44 45 wp_enqueue_style('podlove-subscribe-button-spectrum', plugin_dir_url(__FILE__). 'js/spectrum/spectrum.css'); 46 wp_enqueue_script('podlove-subscribe-button-spectrum', plugin_dir_url(__FILE__). 'js/spectrum/spectrum.js', array('jquery')); 47 wp_enqueue_script('podlove-subscribe-button-admin-tools', plugin_dir_url(__FILE__). 'js/admin.js', array('jquery')); 44 48 } ); 45 49 46 50 // Register Settings 47 51 add_action( 'admin_init', function () { 48 register_setting( 'podlove-subscribe-button', 'podlove_subscribe_button_default_style' ); 49 register_setting( 'podlove-subscribe-button', 'podlove_subscribe_button_default_autowidth' ); 52 $settings = array('size', 'autowidth', 'style', 'format', 'color'); 53 54 foreach ($settings as $setting) { 55 register_setting( 'podlove-subscribe-button', 'podlove_subscribe_button_default_' . $setting ); 56 } 50 57 } ); 51 58 … … 82 89 83 90 public static function shortcode( $args ) { 84 if ( ! $args || ! isset($args['button']) ) 91 if ( ! $args || ! isset($args['button']) ) { 85 92 return __('You need to create a Button first and provide its ID.', 'podlove'); 93 } else { 94 $buttonid = $args['button']; 95 } 86 96 87 if ( ! $button = ( \PodloveSubscribeButton\Model\Button::find_one_by_property('name', $args['button']) ? \PodloveSubscribeButton\Model\Button::find_one_by_property('name', $args['button']) : \PodloveSubscribeButton\Model\NetworkButton::find_one_by_property('name', $args['button']) ) ) 97 // Fetch the (network)button by it's name 98 if ( ! $button = \PodloveSubscribeButton\Model\Button::get_button_by_name($args['button']) ) 88 99 return sprintf( __('Oops. There is no button with the ID "%s".', 'podlove'), $args['button'] ); 89 100 90 if ( isset($args['width']) && $args['width'] == 'auto' ) { 91 $autowidth = 'on'; 101 // Get button styling 102 $autowidth = self::interpret_width_attribute($args['width']); 103 $size = self::get_attribute('size', $args['size']); 104 $style = self::get_attribute('style', $args['style']); 105 $format = self::get_attribute('format', $args['format']); 106 107 if ( isset($args['color']) ) { 108 $color = $args['color']; 92 109 } else { 93 $ autowidth = get_option('podlove_subscribe_button_default_autowidth', 'on');110 $color = get_option('podlove_subscribe_button_default_color', '#599677'); 94 111 } 95 112 96 if ( isset($args['size']) && in_array($args['size'], array('small', 'medium', 'big', 'big-logo')) ) { 97 $size = $args['size']; 98 } else { 99 $size = get_option('podlove_subscribe_button_default_style', 'big-logo'); 113 if ( isset($args['hide']) && $args['hide'] == 'true' ) { 114 $hide = TRUE; 100 115 } 101 116 102 return $button->render( $size, $autowidth ); 117 // Render button 118 return $button->render($size, $autowidth, $style, $format, $color, $hide, $buttonid); 103 119 } 104 120 121 /** 122 * 123 * @param string $attribute 124 * @param string $attribute_value 125 * @return string 126 */ 127 private static function get_attribute($attribute, $attribute_value) { 128 if ( isset($attribute_value) && key_exists( $attribute_value, \PodloveSubscribeButton\Model\Button::$$attribute ) ) { 129 return $attribute_value; 130 } else { 131 return get_option('podlove_subscribe_button_default_' . $attribute, \PodloveSubscribeButton\Model\Button::$properties[$attribute]); 132 } 133 } 134 135 /** 136 * Interprets the provided width attribute and return either auto- or a specific width 137 * @param string $width_attribute 138 * @return string 139 */ 140 private static function interpret_width_attribute( $width_attribute = NULL ) { 141 if ( $width_attribute == 'auto' ) 142 return 'on'; 143 if ( $width_attribute && $width_attribute !== 'auto' ) 144 return 'off'; 145 146 return get_option('podlove_subscribe_button_default_autowidth', 'on'); 147 } 105 148 } -
podlove-subscribe-button/trunk/readme.txt
r1217945 r1416418 4 4 Tags: button, podlove, podcast, feed, subscribe, widget, network 5 5 Requires at least: 3.0.1 6 Tested up to: 4. 37 Stable tag: 1. 1.36 Tested up to: 4.5.1 7 Stable tag: 1.2 8 8 License: MIT 9 9 License URI: http://opensource.org/licenses/MIT … … 42 42 * Donate: http://podlove.org/donations/ 43 43 44 45 46 47 44 == Installation == 48 45 … … 62 59 Go to `Appearance -> Widgets` and drag the "Podlove Subscribe Button" widget to your sidebar configuration. Select the pre-configured button from the list and determine which style you want. That's it. The button should show up in your sidebar. Optionally add a title and description for your widget. 63 60 64 This is the easiest and recommended way of using this plugin especially if you ony want to display a button for a single podcast. For best visibility choose size "big -logo" to make your Subscribe Button stand out and easily locatable.61 This is the easiest and recommended way of using this plugin especially if you ony want to display a button for a single podcast. For best visibility choose size "big" and format "cover" to make your Subscribe Button stand out and easily locatable. 65 62 66 63 … … 70 67 71 68 * `button` - the ID of one of your preconfigured buttons 72 * `size` - one of 'small', 'medium', 'big' , 'big-logo'69 * `size` - one of 'small', 'medium', 'big' 73 70 * `width` - specify desired button width in CSS compatibles values or 'auto' automatic width depending on context. 71 * `color` - specify the color of the button in a CSS compatible format (keyword, rgb-hex, rgb, rgba, hsl, hsla) 72 * `style` - default is filled, options are 'outline' and 'frameless' 73 * `format` - default is a rectangle, options are 'square' and 'cover' (**Note**: 'cover' has a max size of 300px) 74 * `hide` - if set to `true` the button will not be shown (useful if you want to use your own element) 75 * `buttonid` - you can use this to open the popup from another element on the same page 74 76 77 Note that if you do not provide one of the attributes the subscribe button will use the globally set default. 75 78 76 79 ### Shortcode Examples 77 80 78 `[podlove-subscribe-button button="mybutton1" size="big -logo"]`79 Displays a large button with the podcast logo on top using data from button configuration with id "mybutton1" 81 `[podlove-subscribe-button button="mybutton1" size="big"]` 82 Displays a large button with the podcast logo on top using data from button configuration with id "mybutton1". All other options will be set to the globally set default values. 80 83 81 84 `[podlove-subscribe-button button="mybutton2" size="medium" width="100pt"]` 82 Displays a small button with a width of 100pt using data from button configuration with id "mybutton2" 85 Displays a small button with a width of 100pt using data from button configuration with id "mybutton2". All other options will be set to the globally set default values. 83 86 87 `[podlove-subscribe-button button="mybutton3" size="big" width="auto" format="cover"]` 88 Displays a big button with a the podcast cover and automatically adjusted using data from button configuration with id "mybutton3". All other options will be set to the globally set default values. 84 89 85 86 90 `[podlove-subscribe-button button="mybutton4" format="square" style="frameless"]` 91 Displays a small, frameless square button with using data from button configuration with id "mybutton4". All other options will be set to the globally set default values. 87 92 88 93 == Frequently Asked Questions == … … 119 124 == Upgrade Notice == 120 125 126 ### 1.2 127 * Due to internal changes the Subscribe Button widget might be removed from your sidebar. If this happened just readd it to the sidebar. 128 121 129 ### 1.0.1 122 130 * Shortcodes: The `id` attribute was changed to `button`. Please adjust your shortcodes. … … 124 132 125 133 == Changelog == 134 135 ### 1.2 136 * Added various options that allow customization of the Subscribe button 137 * Various bugfixes 126 138 127 139 ### 1.1.3 … … 146 158 147 159 ### 1.0 148 149 160 * Initial Release 150 161 * Settings page to allow definition of preconfigured buttons -
podlove-subscribe-button/trunk/settings/buttons.php
r1173507 r1416418 154 154 $table->display(); 155 155 156 $default_styles = array( 157 'small' => __('Small', 'podlove'), 158 'medium' => __('Medium', 'podlove'), 159 'big' => __('Big', 'podlove'), 160 'big-logo' => __('Big with logo', 'podlove') 161 ); 162 $selected_style = ( get_option('podlove_subscribe_button_default_style') ? get_option('podlove_subscribe_button_default_style') : 'big-logo' ); 163 $autowidth = ( get_option('podlove_subscribe_button_default_autowidth') === FALSE ? 'on' : get_option('podlove_subscribe_button_default_autowidth') ); 156 // Get the global button settings (with fallback to default values) 157 $settings = \PodloveSubscribeButton\Model\Button::get_global_setting_with_fallback(); 164 158 165 159 if ( ! $is_network ) : … … 171 165 <table class="form-table"> 172 166 <tr valign="top"> 173 <th scope="row"><label for="podlove_subscribe_button_default_s tyle"><?php _e('Style', 'podlove'); ?></label></th>174 <td> 175 <select name="podlove_subscribe_button_default_s tyle" id="podlove_subscribe_button_default_style">176 <?php foreach ( $default_stylesas $value => $description) : ?>177 <option value="<?php echo $value; ?>" <?php echo ( $se lected_style== $value ? "selected" : '' ); ?>><?php echo $description; ?></option>167 <th scope="row"><label for="podlove_subscribe_button_default_size"><?php _e('Size', 'podlove'); ?></label></th> 168 <td> 169 <select name="podlove_subscribe_button_default_size" id="podlove_subscribe_button_default_size"> 170 <?php foreach (\PodloveSubscribeButton\Model\Button::$size as $value => $description) : ?> 171 <option value="<?php echo $value; ?>" <?php echo ( $settings['size'] == $value ? "selected" : '' ); ?>><?php echo $description; ?></option> 178 172 <?php endforeach; ?> 179 173 </select> … … 183 177 <th scope="row"><label for="podlove_subscribe_button_default_autowidth"><?php _e('Autowidth', 'podlove'); ?></label></th> 184 178 <td> 185 <input type="checkbox" name="podlove_subscribe_button_default_autowidth" id="podlove_subscribe_button_default_autowidth" <?php echo ( $autowidth == 'on' ? 'checked' : '' ) ?> /> 179 <input type="checkbox" name="podlove_subscribe_button_default_autowidth" id="podlove_subscribe_button_default_autowidth" <?php echo ( $settings['autowidth'] == 'on' ? 'checked' : '' ) ?> /> 180 </td> 181 </tr> 182 <tr valign="top"> 183 <th scope="row"><label for="podlove_subscribe_button_default_color"><?php _e('Color', 'podlove'); ?></label></th> 184 <td> 185 <input id="podlove_subscribe_button_default_color" name="podlove_subscribe_button_default_color" class="podlove_subscribe_button_color" value="<?php echo $settings['color'] ?>" /> 186 </td> 187 </tr> 188 <tr valign="top"> 189 <th scope="row"><label for="podlove_subscribe_button_default_style"><?php _e('Style', 'podlove'); ?></label></th> 190 <td> 191 <select name="podlove_subscribe_button_default_style" id="podlove_subscribe_button_default_style"> 192 <?php foreach (\PodloveSubscribeButton\Model\Button::$style as $value => $description) : ?> 193 <option value="<?php echo $value; ?>" <?php echo ( $settings['style'] == $value ? "selected" : '' ); ?>><?php echo $description; ?></option> 194 <?php endforeach; ?> 195 </select> 196 </td> 197 </tr> 198 <tr valign="top"> 199 <th scope="row"><label for="podlove_subscribe_button_default_format"><?php _e('Format', 'podlove'); ?></label></th> 200 <td> 201 <select name="podlove_subscribe_button_default_format" id="podlove_subscribe_button_default_format"> 202 <?php foreach (\PodloveSubscribeButton\Model\Button::$format as $value => $description) : ?> 203 <option value="<?php echo $value; ?>" <?php echo ( $settings['format'] == $value ? "selected" : '' ); ?>><?php echo $description; ?></option> 204 <?php endforeach; ?> 205 </select> 186 206 </td> 187 207 </tr> … … 259 279 <tr> 260 280 <th><?php _e('URL', 'podlove'); ?></th> 281 <th><?php _e('iTunes feed ID', 'podlove'); ?></th> 261 282 <th><?php _e('Media format', 'podlove'); ?></th> 262 283 <th><?php _e('Actions', 'podlove'); ?></th> … … 281 302 </td> 282 303 <td> 304 <input type="text" class="regular-text" name="podlove_button[feeds][{{id}}][itunesfeedid]" value="{{itunesfeedid}}" /> 305 </td> 306 <td> 283 307 <select class="regular-text podlove-media-format" name="podlove_button[feeds][{{id}}][format]"> 284 308 <?php … … 293 317 </script> 294 318 <script type="text/javascript"> 295 var feed_counter = 0;296 319 var feeds = <?php echo json_encode($button->feeds); ?>; 297 298 (function($) {299 $( document ).ready( function() {300 var source = $("#feed_line_template").html();301 302 $(".add_feed").on( 'click', function () {303 add_new_feed();304 } );305 306 $.each( feeds, function (index, feed) {307 add_existing_feed(feed);308 } );309 310 function add_new_feed() {311 row = source.replace( /\{\{url\}\}/g, '' );312 row = row.replace( /\{\{id\}\}/g, feed_counter );313 314 $("#feeds_table_body").append(row);315 316 new_row = $("#feeds_table_body tr:last");317 new_row.find("input:first").focus();318 319 $(".podlove-icon-remove").on( 'click', function () {320 $(this).closest("tr").remove();321 } );322 323 feed_counter++;324 }325 326 function add_existing_feed( feed ) {327 row = source.replace( /\{\{url\}\}/g, feed.url );328 row = row.replace( /\{\{id\}\}/g, feed_counter );329 330 $("#feeds_table_body").append(row);331 332 new_row = $("#feeds_table_body tr:last");333 new_row.find('select.podlove-media-format option[value="' + feed.format + '"]').attr('selected',true);334 335 $(".podlove-icon-remove").on( 'click', function () {336 $(this).closest("tr").remove();337 } );338 339 feed_counter++;340 }341 342 } );343 }(jQuery));344 320 </script> 345 321 </form> -
podlove-subscribe-button/trunk/settings/buttons_list_table.php
r1139561 r1416418 39 39 40 40 return "<div class='podlove-button-preview-container'>" . $button->render( 41 ( $is_network ? 'big -logo' : get_option('podlove_subscribe_button_default_style', 'big-logo') ),41 ( $is_network ? 'big' : get_option('podlove_subscribe_button_default_size', 'big') ), 42 42 ( $is_network ? FALSE : get_option('podlove_subscribe_button_default_autowidth', 'on') ) 43 43 ) . "</div>"; -
podlove-subscribe-button/trunk/widget.php
r1139561 r1416418 2 2 3 3 namespace PodloveSubscribeButton; 4 5 include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); 4 6 5 7 class Podlove_Subscribe_Button_Widget extends \WP_Widget { … … 7 9 public function __construct() { 8 10 parent::__construct( 9 'podlove_subscribe_button_w idget',10 'Podlove Subscribe Button',11 'podlove_subscribe_button_wp_plugin_widget', 12 ( self::is_podlove_publisher_active() ? 'Podlove Subscribe Button' : 'Podlove Subscribe Button (WordPress plugin)' ), 11 13 array( 'description' => __( 'Adds a Podlove Subscribe Button to your Sidebar', 'podlove' ), ) 12 14 ); 13 15 } 14 16 17 public static $widget_settings = array('infotext', 'title', 'size', 'style', 'format', 'autowidth', 'button'); 18 19 public static function is_podlove_publisher_active() { 20 if ( is_plugin_active("podlove-publisher/plugin.php") ) 21 return true; 22 23 return false; 24 } 25 15 26 public function widget( $args, $instance ) { 16 $button = ( \PodloveSubscribeButton\Model\Button::find_by_id($instance['button']) ? \PodloveSubscribeButton\Model\Button::find_by_id($instance['button']) : \PodloveSubscribeButton\Model\NetworkButton::find_by_id($instance['button']) ); 27 // Fetch the (network)button by it's name 28 if ( ! $button = \PodloveSubscribeButton\Model\Button::get_button_by_name($instance['button']) ) 29 return sprintf( __('Oops. There is no button with the ID "%s".', 'podlove'), $args['button'] ); 17 30 18 31 echo $args['before_widget']; 19 32 echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title']; 20 33 21 echo $button->render($instance['s tyle'], $instance['autowidth']);34 echo $button->render($instance['size'], $instance['autowidth'], $instance['style'], $instance['format'], $instance['color']); 22 35 23 36 if ( strlen($instance['infotext']) ) … … 28 41 29 42 public function form( $instance ) { 30 $title = isset( $instance[ 'title' ] ) ? $instance[ 'title' ] : ''; 31 $button = isset( $instance[ 'button' ] ) ? $instance[ 'button' ] : ''; 32 $style = isset( $instance[ 'style' ] ) ? $instance[ 'style' ] : ''; 33 $autowidth = isset( $instance[ 'autowidth' ] ) ? $instance[ 'autowidth' ] : 0; 34 $infotext = isset( $instance[ 'infotext' ] ) ? $instance[ 'infotext' ] : ''; 43 foreach (self::$widget_settings as $setting) { 44 $$setting = isset( $instance[$setting] ) ? $instance[$setting] : ''; 45 } 46 35 47 $buttons = \PodloveSubscribeButton\Model\Button::all(); 36 48 $network_buttons = \PodloveSubscribeButton\Model\NetworkButton::all(); … … 38 50 $buttons_as_options = function ($buttons) { 39 51 foreach ($buttons as $subscribebutton) { 40 echo "<option value='".$subscribebutton-> id."' ".( $subscribebutton->id== $button ? 'selected=\"selected\"' : '' )." >".$subscribebutton->title." (".$subscribebutton->name.")</option>";52 echo "<option value='".$subscribebutton->name."' ".( $subscribebutton->name == $button ? 'selected=\"selected\"' : '' )." >".$subscribebutton->title." (".$subscribebutton->name.")</option>"; 41 53 } 42 54 } … … 61 73 </select> 62 74 63 <label for="<?php echo $this->get_field_id( 'style' ); ?>"><?php _e( 'Style', 'podlove' ); ?></label> 64 <select class="widefat" id="<?php echo $this->get_field_id( 'style' ); ?>" name="<?php echo $this->get_field_name( 'style' ); ?>"> 65 <option value="default" <?php echo ( $style == 'default' ? 'selected=\"selected\"' : '' ); ?>><?php _e( 'Default Style', 'podlove' ) ?></option> 66 <optgroup> 67 <option value="small" <?php echo ( $style == 'small' ? 'selected=\"selected\"' : '' ); ?>><?php _e( 'Small', 'podlove' ) ?></option> 68 <option value="medium" <?php echo ( $style == 'medium' ? 'selected=\"selected\"' : '' ); ?>><?php _e( 'medium', 'podlove' ) ?></option> 69 <option value="big" <?php echo ( $style == 'big' ? 'selected=\"selected\"' : '' ); ?>><?php _e( 'Big', 'podlove' ) ?></option> 70 <option value="big-logo" <?php echo ( $style == 'big-logo' ? 'selected=\"selected\"' : '' ); ?>><?php _e( 'Big with logo', 'podlove' ) ?></option> 71 </optgroup> 72 </select> 75 <?php 76 $customize_options = array( 77 'size' => array( 78 'name' => 'Size', 79 'options' => \PodloveSubscribeButton\Model\Button::$size 80 ), 81 'style' => array( 82 'name' => 'Style', 83 'options' => \PodloveSubscribeButton\Model\Button::$style 84 ), 85 'format' => array( 86 'name' => 'Format', 87 'options' => \PodloveSubscribeButton\Model\Button::$format 88 ), 89 'autowidth' => array( 90 'name' => 'Autowidth', 91 'options' => \PodloveSubscribeButton\Model\Button::$width 92 ) 93 ); 73 94 74 <label for="<?php echo $this->get_field_id( 'autowidth' ); ?>"><?php _e( 'Autowidth', 'podlove' ); ?></label> 75 <select class="widefat" id="<?php echo $this->get_field_id( 'autowidth' ); ?>" name="<?php echo $this->get_field_name( 'autowidth' ); ?>"> 76 <option value="default" <?php echo ( $autowidth == 'default' ? 'selected=\"selected\"' : '' ); ?>><?php _e( 'Default Autowidth', 'podlove' ) ?></option> 77 <optgroup> 78 <option value="on" <?php echo ( $autowidth == 'on' ? 'selected=\"selected\"' : '' ); ?>><?php _e( 'Yes', 'podlove' ) ?></option> 79 <option value="" <?php echo ( $autowidth == '' ? 'selected=\"selected\"' : '' ); ?>><?php _e( 'No', 'podlove' ) ?></option> 80 </optgroup> 81 </select> 95 foreach ($customize_options as $slug => $properties) : ?> 96 <label for="<?php echo $this->get_field_id( $slug ); ?>"><?php _e( $properties['name'], 'podlove' ); ?></label> 97 <select class="widefat" id="<?php echo $this->get_field_id( $slug ); ?>" name="<?php echo $this->get_field_name( $slug ); ?>"> 98 <option value="default" <?php echo ( $$slug == 'default' ? 'selected="selected"' : '' ); ?>><?php _e( 'Default ' . $properties['name'], 'podlove' ) ?></option> 99 <optgroup> 100 <?php foreach ( $properties['options'] as $property => $name ) : ?> 101 <option value="<?php echo $property; ?>" <?php echo ( $$slug == $property ? 'selected="selected"' : '' ); ?>><?php _e( $name, 'podlove' ) ?></option> 102 <?php endforeach; ?> 103 </optgroup> 104 </select> 105 <?php endforeach; ?> 82 106 83 107 <label for="<?php echo $this->get_field_id( 'infotext' ); ?>"><?php _e( 'Description', 'podlove' ); ?></label> … … 89 113 public function update( $new_instance, $old_instance ) { 90 114 $instance = array(); 91 $instance['infotext'] = ( ! empty( $new_instance['infotext'] ) ) ? $new_instance['infotext'] : ''; 92 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';93 $instance['style'] = ( ! empty( $new_instance['style'] ) ) ? strip_tags( $new_instance['style'] ): '';94 $instance['autowidth'] = ( ! empty( $new_instance['autowidth'] ) ) ? strip_tags( $new_instance['autowidth'] ) : 0;95 $instance['button'] = ( ! empty( $new_instance['button'] ) ) ? strip_tags( $new_instance['button'] ) : ''; 115 116 foreach (self::$widget_settings as $setting) { 117 $instance[$setting] = ( ! empty( $new_instance[$setting] ) ) ? strip_tags( $new_instance[$setting] ) : ''; 118 } 119 96 120 return $instance; 97 121 }
Note: See TracChangeset
for help on using the changeset viewer.