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-block.php
76 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_Block { |
| 8 | |
| 9 | static $name = 'grw-reviews-block'; |
| 10 | |
| 11 | private $core; |
| 12 | private $view; |
| 13 | private $assets; |
| 14 | private $feed_deserializer; |
| 15 | |
| 16 | public function __construct(Feed_Deserializer $feed_deserializer, Core $core, View $view, Assets $assets) { |
| 17 | $this->core = $core; |
| 18 | $this->view = $view; |
| 19 | $this->assets = $assets; |
| 20 | $this->feed_deserializer = $feed_deserializer; |
| 21 | } |
| 22 | |
| 23 | public function register() { |
| 24 | add_action('enqueue_block_editor_assets', [$this, 'enqueue_assets']); |
| 25 | add_action('init', [$this, 'register_block'], 999); |
| 26 | add_action('block_categories_all', [$this, 'register_category']); |
| 27 | } |
| 28 | |
| 29 | public function enqueue_assets() { |
| 30 | $assets = require(GRW_PLUGIN_PATH . 'build/index.asset.php'); |
| 31 | |
| 32 | wp_register_script( |
| 33 | self::$name, |
| 34 | plugins_url('build/index.js', GRW_PLUGIN_FILE), |
| 35 | array('wp-block-editor', 'wp-blocks'), |
| 36 | $this->assets->version() |
| 37 | ); |
| 38 | |
| 39 | wp_localize_script( |
| 40 | self::$name, |
| 41 | 'grwBlockData', |
| 42 | array( |
| 43 | 'feeds' => $this->feed_deserializer->get_all_feeds_short(), |
| 44 | 'builderUrl' => admin_url('admin.php?page=grw-builder') |
| 45 | ) |
| 46 | ); |
| 47 | |
| 48 | wp_enqueue_script(self::$name); |
| 49 | } |
| 50 | |
| 51 | public function register_block() { |
| 52 | register_block_type(GRW_PLUGIN_PATH, [ |
| 53 | 'editor_script' => self::$name, |
| 54 | 'render_callback' => [$this, 'render'], |
| 55 | 'attributes' => ['id' => ['type' => 'string']] |
| 56 | ]); |
| 57 | } |
| 58 | |
| 59 | public function register_category($cats) { |
| 60 | return array_merge($cats, [['slug' => 'grw', 'title' => 'Google Reviews Block']]); |
| 61 | } |
| 62 | |
| 63 | public function render($atts) { |
| 64 | if (isset($atts['id'])) { |
| 65 | |
| 66 | $feed = $this->feed_deserializer->get_feed($atts['id']); |
| 67 | if (!$feed) { |
| 68 | return null; |
| 69 | } |
| 70 | |
| 71 | $data = $this->core->get_reviews($feed); |
| 72 | return $this->view->render($feed->ID, $data['businesses'], $data['reviews'], $data['options']); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 |