コード例 #1
0
 /**
  * Fetches a Button or Network Button with a specific name
  * @param  string $name
  * @return object||FALSE
  */
 public static function get_button_by_name($name)
 {
     if ($button = \PodloveSubscribeButton\Model\Button::find_one_by_property('name', $name)) {
         return $button;
     }
     if ($network_button = \PodloveSubscribeButton\Model\NetworkButton::find_one_by_property('name', $name)) {
         $network_button->id = $network_button->id . 'N';
         return $network_button;
     }
     return FALSE;
 }
コード例 #2
0
    public function form($instance)
    {
        foreach (self::$widget_settings as $setting) {
            ${$setting} = isset($instance[$setting]) ? $instance[$setting] : '';
        }
        $buttons = \PodloveSubscribeButton\Model\Button::all();
        if (is_multisite()) {
            $network_buttons = \PodloveSubscribeButton\Model\NetworkButton::all();
        }
        $buttons_as_options = function ($buttons) {
            foreach ($buttons as $subscribebutton) {
                echo "<option value='" . $subscribebutton->name . "' " . ($subscribebutton->name == $button ? 'selected=\\"selected\\"' : '') . " >" . $subscribebutton->title . " (" . $subscribebutton->name . ")</option>";
            }
        };
        ?>
		<p>
			<label for="<?php 
        echo $this->get_field_id('title');
        ?>
"><?php 
        _e('Title', 'podlove');
        ?>
</label> 
			<input class="widefat" id="<?php 
        echo $this->get_field_id('title');
        ?>
" name="<?php 
        echo $this->get_field_name('title');
        ?>
" value="<?php 
        echo $title;
        ?>
" />

			<label for="<?php 
        echo $this->get_field_id('color');
        ?>
"><?php 
        _e('Color', 'podlove');
        ?>
</label>
			<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;
        ?>
" />
			<style type="text/css">
				.sp-replacer {
					display: flex;
				}
				.sp-preview {
					flex-grow: 10;
				}
			</style>

			<label for="<?php 
        echo $this->get_field_id('button');
        ?>
"><?php 
        _e('Button', 'podlove');
        ?>
</label> 
			<select class="widefat" id="<?php 
        echo $this->get_field_id('button');
        ?>
"
				      name="<?php 
        echo $this->get_field_name('button');
        ?>
">
				<?php 
        if (isset($network_buttons) && count($network_buttons) > 0) {
            ?>
					<optgroup label="<?php 
            _e('Local', 'podlove');
            ?>
">
						<?php 
            $buttons_as_options($buttons);
            ?>
					</optgroup>
					<optgroup label="<?php 
            _e('Network', 'podlove');
            ?>
">
						<?php 
            $buttons_as_options($network_buttons);
            ?>
					</optgroup>
				<?php 
        } else {
            $buttons_as_options($buttons);
        }
        ?>
			</select>

			<?php 
        $customize_options = array('size' => array('name' => 'Size', 'options' => \PodloveSubscribeButton\Model\Button::$size), 'style' => array('name' => 'Style', 'options' => \PodloveSubscribeButton\Model\Button::$style), 'format' => array('name' => 'Format', 'options' => \PodloveSubscribeButton\Model\Button::$format), 'autowidth' => array('name' => 'Autowidth', 'options' => \PodloveSubscribeButton\Model\Button::$width));
        foreach ($customize_options as $slug => $properties) {
            ?>
				<label for="<?php 
            echo $this->get_field_id($slug);
            ?>
"><?php 
            _e($properties['name'], 'podlove');
            ?>
</label> 
				<select class="widefat" id="<?php 
            echo $this->get_field_id($slug);
            ?>
" name="<?php 
            echo $this->get_field_name($slug);
            ?>
">
					<option value="default" <?php 
            echo ${$slug} == 'default' ? 'selected="selected"' : '';
            ?>
><?php 
            _e('Default ' . $properties['name'], 'podlove');
            ?>
</option>
					<optgroup>
						<?php 
            foreach ($properties['options'] as $property => $name) {
                ?>
						<option value="<?php 
                echo $property;
                ?>
" <?php 
                echo ${$slug} == $property ? 'selected="selected"' : '';
                ?>
><?php 
                _e($name, 'podlove');
                ?>
</option>
						<?php 
            }
            ?>
					</optgroup>
				</select>
			<?php 
        }
        ?>
		
			<label for="<?php 
        echo $this->get_field_id('infotext');
        ?>
"><?php 
        _e('Description', 'podlove');
        ?>
</label> 
			<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>
		</p>
		<?php 
    }
コード例 #3
0
    public static function view_template()
    {
        $is_network = get_current_screen()->is_network;
        ?>
		<p><?php 
        _e('This plugin allows easy inclusion of the Podlove Subscribe Button. Put it in your sidebar with a simple widget or include the button in pages and/or posts with a simple shortcode.', 'podlove');
        ?>
</p>
		<p><?php 
        _e('Start by adding a button for each of your podcasts here. You can then add the button to your sidebar by adding the <a href="widgets.php">Podlove Subscribe Button widget</a>.', 'podlove');
        ?>
</p>
		<p><?php 
        _e('If you want to display the button inside a page or article, you can also use the <code>[podlove-subscribe-button]</code> shortcode anywhere.', 'podlove');
        ?>
</p>
		<?php 
        $table = new \PodloveSubscribeButton\Button_List_Table();
        $table->prepare_items();
        $table->display();
        // Get the global button settings (with fallback to default values)
        $settings = \PodloveSubscribeButton\Model\Button::get_global_setting_with_fallback();
        if (!$is_network) {
            ?>
		<h3><?php 
            _e('Default Settings', 'podlove');
            ?>
</h3>
		<form method="post" action="options.php">
			<?php 
            settings_fields('podlove-subscribe-button');
            ?>
			<?php 
            do_settings_sections('podlove-subscribe-button');
            ?>
			<table class="form-table">
				<tr valign="top">
				<th scope="row"><label for="podlove_subscribe_button_default_size"><?php 
            _e('Size', 'podlove');
            ?>
</label></th>
				<td>
					<select name="podlove_subscribe_button_default_size" id="podlove_subscribe_button_default_size">
						<?php 
            foreach (\PodloveSubscribeButton\Model\Button::$size as $value => $description) {
                ?>
							<option value="<?php 
                echo $value;
                ?>
" <?php 
                echo $settings['size'] == $value ? "selected" : '';
                ?>
><?php 
                echo $description;
                ?>
</option>
						<?php 
            }
            ?>
					</select>
				</td>
				</tr>
				<tr valign="top">
				<th scope="row"><label for="podlove_subscribe_button_default_autowidth"><?php 
            _e('Autowidth', 'podlove');
            ?>
</label></th>
				<td>
					<input type="checkbox" name="podlove_subscribe_button_default_autowidth" id="podlove_subscribe_button_default_autowidth" <?php 
            echo $settings['autowidth'] == 'on' ? 'checked' : '';
            ?>
 />
				</td>
				</tr>
				<tr valign="top">
				<th scope="row"><label for="podlove_subscribe_button_default_color"><?php 
            _e('Color', 'podlove');
            ?>
</label></th>
				<td>
					<input id="podlove_subscribe_button_default_color" name="podlove_subscribe_button_default_color" class="podlove_subscribe_button_color" value="<?php 
            echo $settings['color'];
            ?>
" />
				</td>
				</tr>
				<tr valign="top">
				<th scope="row"><label for="podlove_subscribe_button_default_style"><?php 
            _e('Style', 'podlove');
            ?>
</label></th>
				<td>
					<select name="podlove_subscribe_button_default_style" id="podlove_subscribe_button_default_style">
						<?php 
            foreach (\PodloveSubscribeButton\Model\Button::$style as $value => $description) {
                ?>
							<option value="<?php 
                echo $value;
                ?>
" <?php 
                echo $settings['style'] == $value ? "selected" : '';
                ?>
><?php 
                echo $description;
                ?>
</option>
						<?php 
            }
            ?>
					</select>
				</td>
				</tr>
				<tr valign="top">
				<th scope="row"><label for="podlove_subscribe_button_default_format"><?php 
            _e('Format', 'podlove');
            ?>
</label></th>
				<td>
					<select name="podlove_subscribe_button_default_format" id="podlove_subscribe_button_default_format">
						<?php 
            foreach (\PodloveSubscribeButton\Model\Button::$format as $value => $description) {
                ?>
							<option value="<?php 
                echo $value;
                ?>
" <?php 
                echo $settings['format'] == $value ? "selected" : '';
                ?>
><?php 
                echo $description;
                ?>
</option>
						<?php 
            }
            ?>
					</select>
				</td>
				</tr>
			</table>
			<?php 
            submit_button();
            ?>
		</form>
		<?php 
        }
    }
コード例 #4
0
 public static function shortcode($args)
 {
     if (!$args || !isset($args['button'])) {
         return __('You need to create a Button first and provide its ID.', 'podlove');
     } else {
         $buttonid = $args['button'];
     }
     // Fetch the (network)button by it's name
     if (!($button = \PodloveSubscribeButton\Model\Button::get_button_by_name($args['button']))) {
         return sprintf(__('Oops. There is no button with the ID "%s".', 'podlove'), $args['button']);
     }
     // Get button styling and options
     $autowidth = self::interpret_width_attribute(self::get_array_value_with_fallback($args, 'width'));
     $size = self::get_attribute('size', self::get_array_value_with_fallback($args, 'size'));
     $style = self::get_attribute('style', self::get_array_value_with_fallback($args, 'style'));
     $format = self::get_attribute('format', self::get_array_value_with_fallback($args, 'format'));
     $color = self::get_attribute('color', self::get_array_value_with_fallback($args, 'color'));
     if (isset($args['language'])) {
         $language = $args['language'];
     } else {
         $language = 'en';
     }
     if (isset($args['color'])) {
         $color = $args['color'];
     } else {
         $color = get_option('podlove_subscribe_button_default_color', '#599677');
     }
     if (isset($args['hide']) && $args['hide'] == 'true') {
         $hide = TRUE;
     } else {
         $hide = FALSE;
     }
     // Render button
     return $button->render($size, $autowidth, $style, $format, $color, $hide, $buttonid, $language);
 }