Plugin Directory

Changeset 1416418


Ignore:
Timestamp:
05/13/2016 04:50:36 PM (10 years ago)
Author:
chemiker
Message:

Version 1.2

Location:
podlove-subscribe-button
Files:
33 added
12 edited

Legend:

Unmodified
Added
Removed
  • podlove-subscribe-button/trunk/model/button.php

    r1190247 r1416418  
    44class Button extends Base {
    55
    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;
    1550        }
    1651
    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(
    1887                'title' => $this->title,
    1988                'subtitle' => $this->subtitle,
    2089                'description' => $this->description,
    2190                '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    }
    2494
    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;
    30113            }
     114        }
    31115
    32             return '';
    33         };
     116        return $feeds;
     117    }
    34118
    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        }
    36131
    37132        return"
    38133            <script>
    39                 podcastData".$this->id." =".json_encode($podcast_data)."
     134                podcastData".$this->id . " = ".json_encode($podcast_data)."
    40135            </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>
    46140        ";
    47141    }
    48142
     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    }
    49179}
    50180
  • podlove-subscribe-button/trunk/podlove.php

    r1190247 r1416418  
    44 * Plugin URI:  http://wordpress.org/extend/plugins/podlove-subscribe-button/
    55 * Description: Brings the Podlove Subscribe Button to your WordPress installation.
    6  * Version:     1.1.3
     6 * Version:     1.2
    77 * Author:      Podlove
    88 * Author URI:  http://podlove.org
     
    4242    wp_register_style( 'podlove-subscribe-button', plugin_dir_url(__FILE__).'style.css' );
    4343    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'));
    4448} );
    4549
    4650// Register Settings
    4751add_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    }
    5057} );
    5158
     
    8289
    8390    public static function shortcode( $args ) {
    84         if ( ! $args || ! isset($args['button']) )
     91        if ( ! $args || ! isset($args['button']) ) {
    8592            return __('You need to create a Button first and provide its ID.', 'podlove');
     93        } else {
     94            $buttonid = $args['button'];
     95        }
    8696
    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']) )
    8899            return sprintf( __('Oops. There is no button with the ID "%s".', 'podlove'), $args['button'] );
    89100
    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'];
    92109        } else {
    93             $autowidth = get_option('podlove_subscribe_button_default_autowidth', 'on');
     110            $color = get_option('podlove_subscribe_button_default_color', '#599677');
    94111        }
    95112
    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;
    100115        }
    101116
    102         return $button->render( $size, $autowidth );
     117        // Render button
     118        return $button->render($size, $autowidth, $style, $format, $color, $hide, $buttonid);
    103119    }
    104120
     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    }
    105148}
  • podlove-subscribe-button/trunk/readme.txt

    r1217945 r1416418  
    44Tags: button, podlove, podcast, feed, subscribe, widget, network
    55Requires at least: 3.0.1
    6 Tested up to: 4.3
    7 Stable tag: 1.1.3
     6Tested up to: 4.5.1
     7Stable tag: 1.2
    88License: MIT
    99License URI: http://opensource.org/licenses/MIT
     
    4242* Donate: http://podlove.org/donations/
    4343
    44 
    45 
    46 
    4744== Installation ==
    4845
     
    6259Go 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.
    6360
    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.
     61This 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.
    6562
    6663
     
    7067
    7168* `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'
    7370* `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
    7476
     77Note that if you do not provide one of the attributes the subscribe button will use the globally set default.
    7578
    7679### Shortcode Examples
    7780
    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"]`
     82Displays 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.
    8083
    8184`[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"
     85Displays 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.
    8386
     87`[podlove-subscribe-button button="mybutton3" size="big" width="auto" format="cover"]`
     88Displays 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.
    8489
    85 
    86 
     90`[podlove-subscribe-button button="mybutton4" format="square" style="frameless"]`
     91Displays 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.
    8792
    8893== Frequently Asked Questions ==
     
    119124== Upgrade Notice ==
    120125
     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
    121129### 1.0.1
    122130* Shortcodes: The `id` attribute was changed to `button`. Please adjust your shortcodes.
     
    124132
    125133== Changelog ==
     134
     135### 1.2
     136* Added various options that allow customization of the Subscribe button
     137* Various bugfixes
    126138
    127139### 1.1.3
     
    146158
    147159### 1.0
    148 
    149160* Initial Release
    150161* Settings page to allow definition of preconfigured buttons
  • podlove-subscribe-button/trunk/settings/buttons.php

    r1173507 r1416418  
    154154        $table->display();
    155155
    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();
    164158       
    165159        if ( ! $is_network ) :
     
    171165            <table class="form-table">
    172166                <tr valign="top">
    173                 <th scope="row"><label for="podlove_subscribe_button_default_style"><?php _e('Style', 'podlove'); ?></label></th>
    174                 <td>
    175                     <select name="podlove_subscribe_button_default_style" id="podlove_subscribe_button_default_style">
    176                         <?php foreach ($default_styles as $value => $description) : ?>
    177                             <option value="<?php echo $value; ?>" <?php echo ( $selected_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>
    178172                        <?php endforeach; ?>
    179173                    </select>
     
    183177                <th scope="row"><label for="podlove_subscribe_button_default_autowidth"><?php _e('Autowidth', 'podlove'); ?></label></th>
    184178                <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>
    186206                </td>
    187207                </tr>
     
    259279                                    <tr>
    260280                                        <th><?php _e('URL', 'podlove'); ?></th>
     281                                        <th><?php _e('iTunes feed ID', 'podlove'); ?></th>
    261282                                        <th><?php _e('Media format', 'podlove'); ?></th>
    262283                                        <th><?php _e('Actions', 'podlove'); ?></th>
     
    281302                        </td>
    282303                        <td>
     304                        <input type="text" class="regular-text" name="podlove_button[feeds][{{id}}][itunesfeedid]" value="{{itunesfeedid}}" />
     305                        </td>
     306                        <td>
    283307                            <select class="regular-text podlove-media-format" name="podlove_button[feeds][{{id}}][format]">
    284308                                <?php
     
    293317                </script>
    294318                <script type="text/javascript">
    295                     var feed_counter = 0;
    296319                    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));
    344320                </script>
    345321        </form>
  • podlove-subscribe-button/trunk/settings/buttons_list_table.php

    r1139561 r1416418  
    3939
    4040        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') ),
    4242                ( $is_network ? FALSE : get_option('podlove_subscribe_button_default_autowidth', 'on') )
    4343             ) . "</div>";
  • podlove-subscribe-button/trunk/widget.php

    r1139561 r1416418  
    22
    33namespace PodloveSubscribeButton;
     4
     5include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
    46
    57class Podlove_Subscribe_Button_Widget extends \WP_Widget {
     
    79    public function __construct() {
    810        parent::__construct(
    9                     'podlove_subscribe_button_widget',
    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)' ),
    1113                    array( 'description' => __( 'Adds a Podlove Subscribe Button to your Sidebar', 'podlove' ), )
    1214                );
    1315    }
    1416
     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
    1526    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'] );
    1730
    1831        echo $args['before_widget'];
    1932        echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title'];
    2033
    21         echo $button->render($instance['style'], $instance['autowidth']);
     34        echo $button->render($instance['size'], $instance['autowidth'], $instance['style'], $instance['format'], $instance['color']);
    2235       
    2336        if ( strlen($instance['infotext']) )
     
    2841
    2942    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
    3547        $buttons = \PodloveSubscribeButton\Model\Button::all();
    3648        $network_buttons = \PodloveSubscribeButton\Model\NetworkButton::all();
     
    3850        $buttons_as_options = function ($buttons) {
    3951            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>";
    4153            }
    4254        }
     
    6173            </select>
    6274
    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                );
    7394
    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; ?>
    82106       
    83107            <label for="<?php echo $this->get_field_id( 'infotext' ); ?>"><?php _e( 'Description', 'podlove' ); ?></label>
     
    89113    public function update( $new_instance, $old_instance ) {
    90114        $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
    96120        return $instance;
    97121    }
Note: See TracChangeset for help on using the changeset viewer.