admin
10 months ago
core
10 months ago
class-activator.php
10 months ago
class-assets.php
11 months ago
class-builder-page.php
1 year ago
class-deactivator.php
3 years ago
class-debug-info.php
2 years ago
class-feed-ajax.php
1 year ago
class-feed-block.php
1 year ago
class-feed-deserializer.php
11 months ago
class-feed-old.php
4 years ago
class-feed-page.php
11 months ago
class-feed-serializer.php
2 years ago
class-feed-shortcode.php
2 years ago
class-feed-widget.php
4 years ago
class-plugin-overview-ajax.php
1 year ago
class-plugin-overview.php
11 months ago
class-plugin-settings.php
10 months ago
class-plugin-support.php
1 year ago
class-plugin.php
11 months ago
class-post-types.php
3 years ago
class-reviews-cron.php
1 year ago
class-settings-save.php
1 year ago
class-view.php
10 months ago
index.php
4 years ago
page-setting-advance.php
1 year ago
page-setting-fig.php
1 year ago
page-setting-support.php
4 years ago
class-feed-widget.php
134 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WP_Rplg_Google_Reviews\Includes; |
| 4 | |
| 5 | use WP_Rplg_Google_Reviews\Includes\Core\Core; |
| 6 | |
| 7 | class Feed_Widget extends \WP_Widget { |
| 8 | |
| 9 | public static $static_core; |
| 10 | |
| 11 | public static $static_view; |
| 12 | |
| 13 | public static $static_assets; |
| 14 | |
| 15 | public static $static_feed_deserializer; |
| 16 | |
| 17 | public static $static_feed_old; |
| 18 | |
| 19 | public function __construct() { |
| 20 | parent::__construct( |
| 21 | 'grw_widget', |
| 22 | __('Google Reviews Widget', 'widget-google-reviews'), |
| 23 | array( |
| 24 | 'classname' => 'google-reviews-widget', |
| 25 | 'description' => __('Display Google Places Reviews on your website.', 'widget-google-reviews'), |
| 26 | ) |
| 27 | ); |
| 28 | |
| 29 | $this->core = self::$static_core; |
| 30 | $this->view = self::$static_view; |
| 31 | $this->assets = self::$static_assets; |
| 32 | $this->feed_deserializer = self::$static_feed_deserializer; |
| 33 | $this->feed_old = self::$static_feed_old; |
| 34 | } |
| 35 | |
| 36 | public function widget($args, $instance) { |
| 37 | if (get_option('grw_active') === '0') { |
| 38 | return; |
| 39 | } |
| 40 | |
| 41 | if (isset($instance['place_id']) && strlen($instance['place_id']) > 0) { |
| 42 | $feed = $this->feed_old->get_feed($this->id, $instance); |
| 43 | |
| 44 | } else { |
| 45 | if (!isset($instance['feed_id']) || strlen($instance['feed_id']) < 1) { |
| 46 | return null; |
| 47 | } |
| 48 | |
| 49 | $feed = $this->feed_deserializer->get_feed($instance['feed_id']); |
| 50 | |
| 51 | if (!$feed) { |
| 52 | return null; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | $grw_demand_assets = get_option('grw_demand_assets'); |
| 57 | if ($grw_demand_assets || $grw_demand_assets == 'true') { |
| 58 | $this->assets->enqueue_public_styles(); |
| 59 | $this->assets->enqueue_public_scripts(); |
| 60 | } |
| 61 | |
| 62 | $data = $this->core->get_reviews($feed); |
| 63 | |
| 64 | echo $args['before_widget']; |
| 65 | |
| 66 | if (!empty($instance['title'])) { |
| 67 | echo $args['before_title'] . esc_html($instance['title']) . $args['after_title']; |
| 68 | } |
| 69 | |
| 70 | $businesses = $data['businesses']; |
| 71 | $reviews = $data['reviews']; |
| 72 | $options = $data['options']; |
| 73 | if (count($businesses) > 0 || count($reviews) > 0) { |
| 74 | echo $this->view->render($feed->ID, $businesses, $reviews, $options); |
| 75 | } |
| 76 | |
| 77 | echo $args['after_widget']; |
| 78 | } |
| 79 | |
| 80 | public function form($instance) { |
| 81 | $wp_query = new \WP_Query(); |
| 82 | $wp_query->query(array( |
| 83 | 'post_type' => Post_Types::FEED_POST_TYPE, |
| 84 | 'posts_per_page' => 100, |
| 85 | 'no_found_rows' => true, |
| 86 | )); |
| 87 | $feeds = $wp_query->posts; |
| 88 | |
| 89 | ?> |
| 90 | <p> |
| 91 | <label for="<?php echo esc_attr($this->get_field_id('title')); ?>"> |
| 92 | <?php esc_html_e('Title:', 'grw'); ?> |
| 93 | </label> |
| 94 | <input |
| 95 | type="text" |
| 96 | id="<?php echo esc_attr($this->get_field_id('title')); ?>" |
| 97 | class="widefat" |
| 98 | name="<?php echo esc_attr($this->get_field_name('title')); ?>" |
| 99 | value="<?php if (isset($instance['title'])) { echo esc_attr($instance['title']); } ?>" |
| 100 | > |
| 101 | </p> |
| 102 | <p> |
| 103 | <label for="<?php echo esc_attr($this->get_field_id('feed_id')); ?>"> |
| 104 | <?php esc_html_e('Feed:', 'grw'); ?> |
| 105 | </label> |
| 106 | |
| 107 | <select |
| 108 | id="<?php echo esc_attr($this->get_field_id('feed_id')); ?>" |
| 109 | name="<?php echo esc_attr($this->get_field_name('feed_id')); ?>" |
| 110 | style="display:block;width:100%" |
| 111 | > |
| 112 | <option value="">Select Feed</option> |
| 113 | <?php foreach ($feeds as $feed) : ?> |
| 114 | <option |
| 115 | value="<?php echo esc_attr($feed->ID); ?>" |
| 116 | <?php if (isset($instance['feed_id'])) { selected($feed->ID, $instance['feed_id']); } ?> |
| 117 | > |
| 118 | <?php echo esc_html('ID ' . $feed->ID . ': ' . $feed->post_title); ?> |
| 119 | </option> |
| 120 | <?php endforeach; ?> |
| 121 | |
| 122 | </select> |
| 123 | </p> |
| 124 | <?php |
| 125 | } |
| 126 | |
| 127 | public function update($new_instance, $old_instance) { |
| 128 | $instance = $old_instance; |
| 129 | $instance['title'] = sanitize_text_field($new_instance['title']); |
| 130 | $instance['feed_id'] = sanitize_text_field($new_instance['feed_id']); |
| 131 | return $instance; |
| 132 | } |
| 133 | } |
| 134 |