admin
8 months ago
compatibility
8 months ago
extensions
8 months ago
foopluginbase
8 months ago
public
8 months ago
thumbs
8 months ago
.DS_Store
8 months ago
class-attachment-filters.php
8 months ago
class-foogallery-animated-gif-support.php
8 months ago
class-foogallery-attachment-custom-class.php
8 months ago
class-foogallery-attachment-type.php
8 months ago
class-foogallery-attachment.php
8 months ago
class-foogallery-cache.php
8 months ago
class-foogallery-common-fields.php
8 months ago
class-foogallery-crop-position.php
8 months ago
class-foogallery-datasource-media_library.php
8 months ago
class-foogallery-debug.php
8 months ago
class-foogallery-extensions-compatibility.php
8 months ago
class-foogallery-force-https.php
8 months ago
class-foogallery-lazyload.php
8 months ago
class-foogallery-lightbox.php
8 months ago
class-foogallery-paging.php
8 months ago
class-foogallery-password-protect.php
8 months ago
class-foogallery-sitemaps.php
8 months ago
class-foogallery-widget.php
8 months ago
class-foogallery.php
8 months ago
class-gallery-advanced-settings.php
8 months ago
class-il8n.php
8 months ago
class-override-thumbnail.php
8 months ago
class-posttypes.php
8 months ago
class-retina.php
8 months ago
class-thumbnail-dimensions.php
8 months ago
class-thumbnails.php
8 months ago
class-version-check.php
8 months ago
constants.php
8 months ago
functions.php
8 months ago
includes.php
8 months ago
index.php
12 years ago
render-functions.php
8 months ago
class-foogallery-widget.php
112 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Widget to insert a FooGallery |
| 4 | */ |
| 5 | |
| 6 | if ( ! class_exists( 'FooGallery_Widget_Init' ) ) { |
| 7 | class FooGallery_Widget_Init |
| 8 | { |
| 9 | public function __construct() |
| 10 | { |
| 11 | add_action('widgets_init', array($this, 'register_widget')); |
| 12 | } |
| 13 | |
| 14 | public function register_widget() |
| 15 | { |
| 16 | register_widget('FooGallery_Widget'); |
| 17 | } |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | if ( ! class_exists( 'FooGallery_Widget' ) ) { |
| 22 | class FooGallery_Widget extends WP_Widget |
| 23 | { |
| 24 | |
| 25 | /** |
| 26 | * Sets up the widgets name etc |
| 27 | */ |
| 28 | public function __construct() |
| 29 | { |
| 30 | $widget_ops = array( |
| 31 | 'classname' => 'foogallery_widget', |
| 32 | 'description' => __('Insert a FooGallery', 'foogallery'), |
| 33 | ); |
| 34 | |
| 35 | parent::__construct('foogallery_widget', __('FooGallery Widget', 'foogallery'), $widget_ops); |
| 36 | } |
| 37 | |
| 38 | |
| 39 | /** |
| 40 | * Outputs the content of the widget |
| 41 | * |
| 42 | * @param array $args |
| 43 | * @param array $instance |
| 44 | */ |
| 45 | public function widget($args, $instance) |
| 46 | { |
| 47 | // outputs the content of the widget |
| 48 | echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 49 | if (!empty($instance['title'])) { |
| 50 | echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 51 | } |
| 52 | //output the gallery here |
| 53 | $foogallery_id = isset( $instance['foogallery_id'] ) ? intval( $instance['foogallery_id'] ) : 0; |
| 54 | if ( $foogallery_id > 0 ) { |
| 55 | foogallery_render_gallery( $foogallery_id ); |
| 56 | } |
| 57 | |
| 58 | echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 59 | } |
| 60 | |
| 61 | |
| 62 | /** |
| 63 | * Outputs the options form on admin |
| 64 | * |
| 65 | * @param array $instance The widget options |
| 66 | * @return string|void |
| 67 | */ |
| 68 | public function form($instance) |
| 69 | { |
| 70 | // outputs the options form on admin |
| 71 | $title = !empty($instance['title']) ? $instance['title'] : __('New title', 'foogallery'); |
| 72 | $foogallery_id = !empty($instance['foogallery_id']) ? intval($instance['foogallery_id']) : 0; |
| 73 | $galleries = foogallery_get_all_galleries(); |
| 74 | ?> |
| 75 | <p> |
| 76 | <label for="<?php echo esc_attr( $this->get_field_id('title') ); ?>"><?php esc_html_e('Title:', 'foogallery'); ?></label> |
| 77 | <input class="widefat" id="<?php echo esc_attr( $this->get_field_id('title') ); ?>" |
| 78 | name="<?php echo esc_attr( $this->get_field_name('title') ); ?>" type="text" |
| 79 | value="<?php echo esc_attr($title); ?>"> |
| 80 | </p> |
| 81 | <p> |
| 82 | <label for="<?php echo esc_attr( $this->get_field_id('foogallery_id') ); ?>"><?php esc_html_e('Select Gallery:', 'foogallery'); ?></label> |
| 83 | <select class="widefat" id="<?php echo esc_attr( $this->get_field_id('foogallery_id') ); ?>" |
| 84 | name="<?php echo esc_attr( $this->get_field_name('foogallery_id') ); ?>" |
| 85 | value="<?php echo esc_attr($title); ?>"> |
| 86 | <?php foreach ( $galleries as $gallery ) {?> |
| 87 | <option <?php echo $gallery->ID == $foogallery_id ? 'selected="selected"' : ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> value="<?php echo esc_attr( $gallery->ID ); ?>"><?php echo esc_html( $gallery->name . ' [' . $gallery->ID . ']' ); ?></option> |
| 88 | <?php } ?> |
| 89 | </select> |
| 90 | </p> |
| 91 | <?php |
| 92 | } |
| 93 | |
| 94 | |
| 95 | /** |
| 96 | * Processing widget options on save |
| 97 | * |
| 98 | * @param array $new_instance The new options |
| 99 | * @param array $old_instance The previous options |
| 100 | * @return array|mixed |
| 101 | */ |
| 102 | public function update($new_instance, $old_instance) |
| 103 | { |
| 104 | // processes widget options to be saved |
| 105 | foreach ($new_instance as $key => $value) { |
| 106 | $updated_instance[$key] = sanitize_text_field($value); |
| 107 | } |
| 108 | |
| 109 | return $updated_instance; |
| 110 | } |
| 111 | } |
| 112 | } |