| | |
| | | <?php |
| | | namespace JVBase\blocks; |
| | | |
| | | use JVBase\managers\Cache; |
| | | use Exception; |
| | | use JVBase\base\Site; |
| | | use JVBase\integrations\services\GoogleMyBusiness; |
| | | //use JVBase\managers\Cache; |
| | | use WP_Block; |
| | | |
| | | if (!defined('ABSPATH')) { |
| | | exit; |
| | | } |
| | | class GMBReviewBlock { |
| | | protected Cache $cache; |
| | | // protected Cache $cache; |
| | | public function __construct() |
| | | { |
| | | if (!Site::hasIntegration('gmb')){ |
| | | return; |
| | | } |
| | | add_action('init', [ $this, 'registerBlock' ]); |
| | | } |
| | | |
| | |
| | | */ |
| | | public function render(array $attributes, string $content, WP_Block $block):string |
| | | { |
| | | if (!Site::hasIntegration('gmb')) { |
| | | return ''; |
| | | } |
| | | $count = $attributes['count'] ?? 5; |
| | | $showRating = $attributes['showRating'] ?? true; |
| | | $showDate = $attributes['showDate'] ?? true; |
| | |
| | | $inheritUser = null; |
| | | } |
| | | try { |
| | | $gmb = JVB()->connect('gmb', $inheritUser); |
| | | if (!$gmb->isSetUp()) { |
| | | $gmb = GoogleMyBusiness::getInstance(); |
| | | $gmb->switchUser($inheritUser); |
| | | if (!$gmb->isSetUp() |
| | | || !method_exists($gmb, 'getReviews') |
| | | || !method_exists($gmb, 'getReviewsViewUrl') |
| | | || !method_exists($gmb, 'getReviewUrl')) { |
| | | error_log('GMB Not set up for: '.(int)$inheritUser); |
| | | return ''; |
| | | } |
| | | |
| | | $gotReviews = $gmb->getReviews(); |
| | | // Get all data |
| | | $allReviews = $gotReviews['reviews']??[]; |
| | |
| | | } ?> |
| | | </div> |
| | | <?php } ?> |
| | | <p><?= esc_html($reviewer)?></p> |
| | | <?php |
| | | // Date |
| | | if ($showDate && !empty($date)) { |
| | | $formatted_date = human_time_diff(strtotime($date), current_time('timestamp')) . ' ago'; |
| | | ?> |
| | | <time datetime="<?=esc_attr($date)?>"> |
| | | <?= esc_html($formatted_date) ?> |
| | | </time> |
| | | <?php } ?> |
| | | <div class="row left wrap"> |
| | | <p><?= esc_html($reviewer)?></p> |
| | | <?php |
| | | // Date |
| | | if ($showDate && !empty($date)) { |
| | | $formatted_date = human_time_diff(strtotime($date), current_time('timestamp')) . ' ago'; |
| | | ?> |
| | | <time datetime="<?=esc_attr($date)?>"> |
| | | <?= esc_html($formatted_date) ?> |
| | | </time> |
| | | <?php } ?> |
| | | </div> |
| | | |
| | | </div> |
| | | </cite> |
| | |
| | | <?php |
| | | return ob_get_clean(); |
| | | |
| | | } catch (\Exception $e) { |
| | | } catch (Exception $e) { |
| | | error_log('[GMB Reviews Block] Error: ' . $e->getMessage()); |
| | | return ''; |
| | | } |