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-view.php
561 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WP_Rplg_Google_Reviews\Includes; |
| 4 | |
| 5 | class View { |
| 6 | |
| 7 | const G_AVA_SIZE = 's120'; |
| 8 | |
| 9 | public function render($feed_id, $businesses, $reviews, $options, $is_admin = false) { |
| 10 | ob_start(); |
| 11 | |
| 12 | $max_width = $options->max_width; |
| 13 | if (is_numeric($max_width)) { |
| 14 | $max_width = $max_width . 'px'; |
| 15 | } |
| 16 | $max_height = $options->max_height; |
| 17 | if (is_numeric($max_height)) { |
| 18 | $max_height = $max_height . 'px'; |
| 19 | } |
| 20 | |
| 21 | $style = ''; |
| 22 | if (isset($max_width) && strlen($max_width) > 0) { |
| 23 | $style .= 'width:' . $max_width . '!important;'; |
| 24 | } |
| 25 | if (isset($max_height) && strlen($max_height) > 0) { |
| 26 | $style .= 'height:' . $max_height . '!important;overflow-y:auto!important;'; |
| 27 | } |
| 28 | if ($options->centered) { |
| 29 | $style .= 'margin:0 auto!important;'; |
| 30 | } |
| 31 | if (isset($options->style_vars) && strlen($options->style_vars) > 0) { |
| 32 | $style .= $options->style_vars; |
| 33 | } |
| 34 | |
| 35 | ?> |
| 36 | <div class="wp-gr wpac<?php if ($options->dark_theme) { ?> wp-dark<?php } ?>"<?php if ($style) { ?> style="<?php echo $style;?>"<?php } ?> data-id="<?php echo $feed_id; ?>" data-layout="<?php echo $options->view_mode; ?>" data-exec="false" data-options='<?php echo $this->options($options); ?>'> |
| 37 | <svg xmlns="http://www.w3.org/2000/svg" style="display:none"> |
| 38 | <symbol id="grw-star" viewBox="0 0 1792 1792"> |
| 39 | <path d="M1728 647q0 22-26 48l-363 354 86 500q1 7 1 20 0 21-10.5 35.5t-30.5 14.5q-19 0-40-12l-449-236-449 236q-22 12-40 12-21 0-31.5-14.5t-10.5-35.5q0-6 2-20l86-500-364-354q-25-27-25-48 0-37 56-46l502-73 225-455q19-41 49-41t49 41l225 455 502 73q56 9 56 46z"></path> |
| 40 | </symbol> |
| 41 | <symbol id="grw-star-h" viewBox="0 0 1792 1792"> |
| 42 | <path d="M1250 957l257-250-356-52-66-10-30-60-159-322v963l59 31 318 168-60-355-12-66zm452-262l-363 354 86 500q5 33-6 51.5t-34 18.5q-17 0-40-12l-449-236-449 236q-23 12-40 12-23 0-34-18.5t-6-51.5l86-500-364-354q-32-32-23-59.5t54-34.5l502-73 225-455q20-41 49-41 28 0 49 41l225 455 502 73q45 7 54 34.5t-24 59.5z"></path> |
| 43 | </symbol> |
| 44 | <symbol id="grw-star-o" viewBox="0 0 1792 1792"> |
| 45 | <path d="M1201 1004l306-297-422-62-189-382-189 382-422 62 306 297-73 421 378-199 377 199zm527-357q0 22-26 48l-363 354 86 500q1 7 1 20 0 50-41 50-19 0-40-12l-449-236-449 236q-22 12-40 12-21 0-31.5-14.5t-10.5-35.5q0-6 2-20l86-500-364-354q-25-27-25-48 0-37 56-46l502-73 225-455q19-41 49-41t49 41l225 455 502 73q56 9 56 46z" fill="#ccc"></path> |
| 46 | </symbol> |
| 47 | <symbol id="grw-tripadvisor" viewBox="0 0 713.496 713.496"> |
| 48 | <g><circle fill="#34E0A1" cx="356.749" cy="356.748" r="356.748"/><path d="M577.095,287.152l43.049-46.836h-95.465c-47.792-32.646-105.51-51.659-167.931-51.659 c-62.342,0-119.899,19.054-167.612,51.659H93.432l43.049,46.836c-26.387,24.075-42.929,58.754-42.929,97.259 c0,72.665,58.914,131.578,131.579,131.578c34.519,0,65.968-13.313,89.446-35.077l42.172,45.919l42.172-45.879 c23.478,21.764,54.887,35.037,89.406,35.037c72.665,0,131.658-58.913,131.658-131.578 C620.024,345.866,603.483,311.188,577.095,287.152z M225.17,473.458c-49.188,0-89.047-39.859-89.047-89.047 s39.86-89.048,89.047-89.048c49.187,0,89.047,39.86,89.047,89.048S274.357,473.458,225.17,473.458z M356.788,381.82 c0-58.595-42.61-108.898-98.853-130.383c30.413-12.716,63.776-19.771,98.813-19.771s68.439,7.055,98.853,19.771 C399.399,272.962,356.788,323.226,356.788,381.82z M488.367,473.458c-49.188,0-89.048-39.859-89.048-89.047 s39.86-89.048,89.048-89.048s89.047,39.86,89.047,89.048S537.554,473.458,488.367,473.458z M488.367,337.694 c-25.79,0-46.677,20.887-46.677,46.677c0,25.789,20.887,46.676,46.677,46.676c25.789,0,46.676-20.887,46.676-46.676 C535.042,358.621,514.156,337.694,488.367,337.694z M271.846,384.411c0,25.789-20.887,46.676-46.676,46.676 s-46.676-20.887-46.676-46.676c0-25.79,20.887-46.677,46.676-46.677C250.959,337.694,271.846,358.621,271.846,384.411z"/></g> |
| 49 | </symbol> |
| 50 | <symbol id="grw-google" viewBox="0 0 512 512"> |
| 51 | <g fill="none" fill-rule="evenodd"><path d="M482.56 261.36c0-16.73-1.5-32.83-4.29-48.27H256v91.29h127.01c-5.47 29.5-22.1 54.49-47.09 71.23v59.21h76.27c44.63-41.09 70.37-101.59 70.37-173.46z" fill="#4285f4"/><path d="M256 492c63.72 0 117.14-21.13 156.19-57.18l-76.27-59.21c-21.13 14.16-48.17 22.53-79.92 22.53-61.47 0-113.49-41.51-132.05-97.3H45.1v61.15c38.83 77.13 118.64 130.01 210.9 130.01z" fill="#34a853"/><path d="M123.95 300.84c-4.72-14.16-7.4-29.29-7.4-44.84s2.68-30.68 7.4-44.84V150.01H45.1C29.12 181.87 20 217.92 20 256c0 38.08 9.12 74.13 25.1 105.99l78.85-61.15z" fill="#fbbc05"/><path d="M256 113.86c34.65 0 65.76 11.91 90.22 35.29l67.69-67.69C373.03 43.39 319.61 20 256 20c-92.25 0-172.07 52.89-210.9 130.01l78.85 61.15c18.56-55.78 70.59-97.3 132.05-97.3z" fill="#ea4335"/><path d="M20 20h472v472H20V20z"/></g> |
| 52 | </symbol> |
| 53 | </svg> |
| 54 | <?php |
| 55 | switch ($options->view_mode) { |
| 56 | case 'slider': |
| 57 | $this->render_slider($businesses, $reviews, $options, $is_admin); |
| 58 | break; |
| 59 | case 'grid': |
| 60 | $this->render_grid($businesses, $reviews, $options, $is_admin); |
| 61 | break; |
| 62 | case 'list': |
| 63 | $this->render_list($businesses, $reviews, $options, $is_admin); |
| 64 | break; |
| 65 | case 'rating': |
| 66 | $this->render_rating($businesses, $reviews, $options); |
| 67 | break; |
| 68 | case 'badge': |
| 69 | $this->render_badge($businesses, $reviews, $options); |
| 70 | break; |
| 71 | default: |
| 72 | $this->render_list($businesses, $reviews, $options, $is_admin); |
| 73 | } |
| 74 | ?> |
| 75 | </div> |
| 76 | <?php |
| 77 | return preg_replace('/[\n\r]|(>)\s+(<)/', '$1$2', ob_get_clean()); |
| 78 | } |
| 79 | |
| 80 | private function options($options) { |
| 81 | return json_encode( |
| 82 | array( |
| 83 | 'text_size' => $options->text_size, |
| 84 | 'trans' => array( |
| 85 | 'read more' => __('read more', 'widget-google-reviews') |
| 86 | ) |
| 87 | ) |
| 88 | ); |
| 89 | } |
| 90 | |
| 91 | private function render_slider($businesses, $reviews, $options, $is_admin = false) { |
| 92 | ?> |
| 93 | <div class="grw-row grw-row-m" data-options='<?php |
| 94 | echo json_encode( |
| 95 | array( |
| 96 | 'speed' => $options->slider_speed ? $options->slider_speed : 3, |
| 97 | 'autoplay' => $options->slider_autoplay, |
| 98 | 'mousestop' => $options->slider_mousestop, |
| 99 | 'breakpoints' => $options->slider_breakpoints |
| 100 | ) |
| 101 | ); ?>'> |
| 102 | <?php if (count($businesses) > 0) { ?> |
| 103 | <div class="grw-header"> |
| 104 | <div class="grw-header-inner"> |
| 105 | <div class="wp-google-place<?php if ($options->header_center) { ?> wp-place-center<?php } ?>"> |
| 106 | <?php $this->grw_place( |
| 107 | $businesses[0]->rating, |
| 108 | $businesses[0], |
| 109 | $businesses[0]->photo, |
| 110 | $reviews, |
| 111 | $options, |
| 112 | true, |
| 113 | true |
| 114 | ); ?> |
| 115 | </div> |
| 116 | </div> |
| 117 | </div> |
| 118 | <?php } |
| 119 | $count = count($reviews); |
| 120 | if ($count > 0) { ?> |
| 121 | <div class="grw-content"> |
| 122 | <div class="grw-content-inner"> |
| 123 | <?php if (!$options->slider_hide_prevnext) { ?> |
| 124 | <div class="grw-btns grw-prev" tabindex="0"> |
| 125 | <svg viewBox="0 0 24 24" role="none"><path d="M14.6,18.4L8.3,12l6.4-6.4l0.7,0.7L9.7,12l5.6,5.6L14.6,18.4z"></path></svg> |
| 126 | </div> |
| 127 | <?php } ?> |
| 128 | <div class="grw-reviews" data-count="<?php echo $count; ?>" data-offset="<?php echo $count; ?>"> |
| 129 | <?php foreach ($reviews as $review) { $this->grw_slider_review($review, false, $options, $is_admin); } ?> |
| 130 | </div> |
| 131 | <?php if (!$options->slider_hide_prevnext) { ?> |
| 132 | <div class="grw-btns grw-next" tabindex="0"> |
| 133 | <svg viewBox="0 0 24 24" role="none"><path d="M9.4,18.4l-0.7-0.7l5.6-5.6L8.6,6.4l0.7-0.7l6.4,6.4L9.4,18.4z"></path></svg> |
| 134 | </div> |
| 135 | <?php } ?> |
| 136 | <?php if (!$options->slider_hide_dots) { ?><div class="rpi-dots-wrap"><div class="rpi-dots"></div></div><?php } ?> |
| 137 | </div> |
| 138 | |
| 139 | </div> |
| 140 | <?php } ?> |
| 141 | </div> |
| 142 | <?php $this->js_loader('grw_init', '\'slider\''); |
| 143 | } |
| 144 | |
| 145 | private function render_grid($businesses, $reviews, $options, $is_admin = false) { |
| 146 | $hr = false; |
| 147 | if (count($businesses) > 0) { ?> |
| 148 | <div class="grw-header<?php if ($options->header_center) { ?> wp-place-center<?php } ?>"> |
| 149 | <div class="grw-header-inner"> |
| 150 | <div class="wp-google-place"> |
| 151 | <?php $this->grw_place( |
| 152 | $businesses[0]->rating, |
| 153 | $businesses[0], |
| 154 | $businesses[0]->photo, |
| 155 | $reviews, |
| 156 | $options, |
| 157 | true, |
| 158 | true |
| 159 | ); ?> |
| 160 | </div> |
| 161 | </div> |
| 162 | </div> |
| 163 | <?php } ?> |
| 164 | <div class="grw-row grw-row-m" data-options='<?php |
| 165 | echo json_encode( |
| 166 | array( |
| 167 | 'breakpoints' => $options->slider_breakpoints |
| 168 | ) |
| 169 | ); ?>'> |
| 170 | <?php if (count($reviews) > 0) { ?> |
| 171 | <div class="grw-content"> |
| 172 | <div class="grw-content-inner"> |
| 173 | <div class="grw-reviews"> |
| 174 | <?php |
| 175 | if (count($reviews) > 0) { |
| 176 | $i = 0; |
| 177 | foreach ($reviews as $review) { |
| 178 | if ($options->pagination > 0 && $options->pagination <= $i++) { |
| 179 | $hr = true; |
| 180 | } |
| 181 | $this->grw_slider_review($review, $hr, $options, $is_admin); |
| 182 | } |
| 183 | } |
| 184 | ?> |
| 185 | </div> |
| 186 | </div> |
| 187 | <?php if ($options->pagination > 0 && $hr) { ?> |
| 188 | <a class="wp-google-url" href="#" onclick="return rplg_next_reviews.call(this, 'grw', <?php echo $options->pagination; ?>);"> |
| 189 | <?php echo __('More reviews', 'widget-google-reviews'); ?> |
| 190 | </a> |
| 191 | <?php } ?> |
| 192 | </div> |
| 193 | <?php } ?> |
| 194 | </div> |
| 195 | <?php $this->js_loader('grw_init', '\'grid\''); |
| 196 | } |
| 197 | |
| 198 | private function render_list($businesses, $reviews, $options, $is_admin = false) { |
| 199 | ?> |
| 200 | <div class="wp-google-list"> |
| 201 | <?php foreach ($businesses as $business) { ?> |
| 202 | <div class="wp-google-place<?php if ($options->header_center) { ?> wp-place-center<?php } ?>"> |
| 203 | <?php $this->grw_place( |
| 204 | $business->rating, |
| 205 | $business, |
| 206 | $business->photo, |
| 207 | $reviews, |
| 208 | $options |
| 209 | ); ?> |
| 210 | </div> |
| 211 | <?php } |
| 212 | if (!$options->hide_reviews) { ?> |
| 213 | <div class="wp-google-content-inner"> |
| 214 | <?php $this->grw_place_reviews($reviews, $options, $is_admin); ?> |
| 215 | </div> |
| 216 | <?php } ?> |
| 217 | </div> |
| 218 | <?php $this->js_loader('grw_init'); |
| 219 | } |
| 220 | |
| 221 | private function render_rating($businesses, $reviews, $options, $is_admin = false) { |
| 222 | ?> |
| 223 | <div class="wp-google-list"> |
| 224 | <?php foreach ($businesses as $business) { ?> |
| 225 | <div class="wp-google-place<?php if ($options->header_center) { ?> wp-place-center<?php } ?>"> |
| 226 | <?php $this->grw_place( |
| 227 | $business->rating, |
| 228 | $business, |
| 229 | $business->photo, |
| 230 | $reviews, |
| 231 | $options |
| 232 | ); ?> |
| 233 | </div> |
| 234 | <?php } ?> |
| 235 | </div> |
| 236 | <?php $this->js_loader('grw_init'); |
| 237 | } |
| 238 | |
| 239 | private function render_badge($businesses, $reviews, $options) { |
| 240 | ?> |
| 241 | <script type="text/javascript"> |
| 242 | function grw_badge_init(el) { |
| 243 | var btn = el.querySelector('.wp-google-badge'), |
| 244 | form = el.querySelector('.wp-google-form'); |
| 245 | |
| 246 | var wpac = document.createElement('div'); |
| 247 | wpac.className = 'wp-gr wpac'; |
| 248 | wpac.appendChild(form); |
| 249 | document.body.appendChild(wpac); |
| 250 | |
| 251 | btn.onclick = function() { |
| 252 | form.style.display='block'; |
| 253 | }; |
| 254 | } |
| 255 | </script> |
| 256 | <?php foreach ($businesses as $business) { ?> |
| 257 | <div class="wp-google-badge<?php if ($options->view_mode == 'badge') { ?> wp-google-badge-fixed<?php } ?>"> |
| 258 | <div class="wp-google-border"></div> |
| 259 | <div class="wp-google-badge-btn"> |
| 260 | <svg height="44" width="44" role="none"><use href="#grw-google"></use></svg> |
| 261 | <div class="wp-google-badge-score"> |
| 262 | <div><?php echo __('Google Rating', 'widget-google-reviews'); ?></div> |
| 263 | <span class="wp-google-rating"><?php echo $business->rating; ?></span> |
| 264 | <span class="wp-google-stars"><?php $this->grw_stars($business->rating); ?></span> |
| 265 | </div> |
| 266 | </div> |
| 267 | </div> |
| 268 | <?php } ?> |
| 269 | <div class="wp-google-form" style="display:none"> |
| 270 | <?php foreach ($businesses as $business) { ?> |
| 271 | <div class="wp-google-head"> |
| 272 | <div class="wp-google-head-inner"> |
| 273 | <?php |
| 274 | $this->grw_place( |
| 275 | $business->rating, |
| 276 | $business, |
| 277 | $business->photo, |
| 278 | $reviews, |
| 279 | $options, |
| 280 | false |
| 281 | ); ?> |
| 282 | </div> |
| 283 | <button class="wp-google-close" type="button" onclick="this.parentNode.parentNode.style.display='none'">×</button> |
| 284 | </div> |
| 285 | <?php } ?> |
| 286 | <div class="wp-google-body"></div> |
| 287 | <div class="wp-google-content"> |
| 288 | <div class="wp-google-content-inner"> |
| 289 | <?php $this->grw_place_reviews($reviews, $options); ?> |
| 290 | </div> |
| 291 | </div> |
| 292 | <?php $this->grw_powered(); ?> |
| 293 | </div> |
| 294 | <?php $this->js_loader('grw_badge_init'); |
| 295 | } |
| 296 | |
| 297 | function grw_place($rating, $place, $place_img, $reviews, $options, $show_powered = true, $show_writereview = false) { |
| 298 | if (!$options->header_hide_photo) { |
| 299 | $img_alt = $options->header_hide_name ? $place->name : ''; ?> |
| 300 | <div class="wp-google-left"> |
| 301 | <img src="<?php echo $place_img; ?>" alt="<?php echo $img_alt; ?>" width="50" height="50"> |
| 302 | </div> |
| 303 | <?php } ?> |
| 304 | <div class="wp-google-right"> |
| 305 | <?php if (!$options->header_hide_name) { ?> |
| 306 | <div class="wp-google-name"> |
| 307 | <?php $place_name_content = '<span>' . $place->name . '</span>'; |
| 308 | echo $this->grw_anchor($place->url, '', $place_name_content, $options, sprintf(__('%s place profile', 'widget-google-reviews'), $place->name)); ?> |
| 309 | </div><?php |
| 310 | } |
| 311 | $this->grw_place_rating($rating, $place->review_count, $options); |
| 312 | if ($show_powered) { |
| 313 | $this->grw_powered(); |
| 314 | } |
| 315 | if (!$options->hide_writereview) { ?> |
| 316 | <div class="wp-google-wr"> |
| 317 | <?php echo $this->grw_anchor( |
| 318 | 'https://search.google.com/local/writereview?placeid=' . $place->id, |
| 319 | '', |
| 320 | __('review us on', 'widget-google-reviews') . '<svg height="18" width="18" role="none"><use href="#grw-google"></use></svg>', |
| 321 | $options, |
| 322 | __('review us on Google', 'widget-google-reviews'), |
| 323 | 'return rplg_leave_review_window.call(this)' |
| 324 | ); ?> |
| 325 | </div> |
| 326 | <?php } ?> |
| 327 | </div> |
| 328 | <?php |
| 329 | } |
| 330 | |
| 331 | function grw_place_rating($rating, $review_count, $opts) { |
| 332 | $aria_label = isset($opts->aria_label) && $opts->aria_label ? |
| 333 | ' aria-label="' . sprintf(__('Rating: %s out of 5', 'widget-google-reviews'), $rating) . '"' : ''; |
| 334 | ?> |
| 335 | <div> |
| 336 | <span class="wp-google-rating"<?php echo $aria_label; ?>><?php echo $rating; ?></span> |
| 337 | <span class="wp-google-stars"><?php $this->grw_stars($rating); ?></span> |
| 338 | </div> |
| 339 | <?php if (!$opts->hide_based_on && isset($review_count)) { ?> |
| 340 | <div class="wp-google-based"><?php echo vsprintf(__('Based on %s reviews', 'widget-google-reviews'), $this->grw_array($review_count)); ?></div> |
| 341 | <?php } |
| 342 | } |
| 343 | |
| 344 | function grw_powered() { |
| 345 | ?><div class="wp-google-powered">powered by <span><span style="color:#3c6df0!important">G</span><span style="color:#d93025!important">o</span><span style="color:#fb8e28!important">o</span><span style="color:#3c6df0!important">g</span><span style="color:#188038!important">l</span><span style="color:#d93025!important">e</span></span></div><?php |
| 346 | } |
| 347 | |
| 348 | function grw_place_reviews($reviews, $options, $is_admin = false) { |
| 349 | ?> |
| 350 | <div class="wp-google-reviews"> |
| 351 | <?php |
| 352 | $place_id = null; |
| 353 | $place_url = null; |
| 354 | |
| 355 | $hr = false; |
| 356 | if (count($reviews) > 0) { |
| 357 | $i = 0; |
| 358 | foreach ($reviews as $review) { |
| 359 | if (!$place_id) { |
| 360 | $place_id = $review->biz_id; |
| 361 | $place_url = $review->biz_url; |
| 362 | } |
| 363 | if ($options->pagination > 0 && $options->pagination <= $i++) { |
| 364 | $hr = true; |
| 365 | } |
| 366 | $this->grw_place_review($review, $hr, $options, $is_admin); |
| 367 | } |
| 368 | } |
| 369 | ?> |
| 370 | </div> |
| 371 | <?php if ($options->pagination > 0 && $hr) { ?> |
| 372 | <a class="wp-google-url" href="#" onclick="return rplg_next_reviews.call(this, 'wp-google', <?php echo $options->pagination; ?>);"> |
| 373 | <?php echo __('More reviews', 'widget-google-reviews'); ?> |
| 374 | </a> |
| 375 | <?php |
| 376 | } else { |
| 377 | $reviews_link = $options->google_def_rev_link ? $place_url : 'https://search.google.com/local/reviews?placeid=' . $place_id; |
| 378 | $this->grw_anchor($reviews_link, 'wp-google-url', __('See All Reviews', 'widget-google-reviews'), $options, __('All reviews', 'widget-google-reviews')); |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | function grw_place_review($review, $hr, $options, $is_admin = false) { |
| 383 | ?> |
| 384 | <div class="wp-google-review<?php if ($hr) { echo ' wp-google-hide'; } if ($is_admin && $review->hide != '') { echo ' wp-review-hidden'; } ?>"> |
| 385 | <?php if (!$options->hide_avatar) { ?> |
| 386 | <div class="wp-google-left"> |
| 387 | <?php |
| 388 | $default_avatar = GRW_ASSETS_URL . 'img/guest.png'; |
| 389 | if (strlen($review->author_avatar) > 0) { |
| 390 | $author_avatar = $review->author_avatar; |
| 391 | } else { |
| 392 | $author_avatar = $default_avatar; |
| 393 | } |
| 394 | if (isset($options->reviewer_avatar_size)) { |
| 395 | $author_avatar = str_replace(self::G_AVA_SIZE, 's' . $options->reviewer_avatar_size, $author_avatar); |
| 396 | $default_avatar = str_replace(self::G_AVA_SIZE, 's' . $options->reviewer_avatar_size, $default_avatar); |
| 397 | } |
| 398 | $this->grw_image($author_avatar, '', $options->lazy_load_img, $default_avatar); |
| 399 | ?> |
| 400 | </div> |
| 401 | <?php } ?> |
| 402 | <div class="wp-google-right"> |
| 403 | <?php |
| 404 | if (strlen($review->author_url) > 0) { |
| 405 | $this->grw_anchor($review->author_url, 'wp-google-name', $review->author_name, $options, sprintf(__('%s user profile', 'widget-google-reviews'), $review->author_name)); |
| 406 | } else { |
| 407 | if (strlen($review->author_name) > 0) { |
| 408 | $author_name = $review->author_name; |
| 409 | } else { |
| 410 | $author_name = __('Google User', 'widget-google-reviews'); |
| 411 | } |
| 412 | ?><div class="wp-google-name"><?php echo $author_name; ?></div><?php |
| 413 | } |
| 414 | ?> |
| 415 | <div class="wp-google-time" data-time="<?php echo $review->time; ?>"><?php echo gmdate("H:i d M y", $review->time); ?></div> |
| 416 | <div class="wp-google-feedback"> |
| 417 | <span class="wp-google-stars"><?php echo $this->grw_stars($review->rating); ?></span> |
| 418 | <span class="wp-google-text"><?php echo $review->text; ?></span> |
| 419 | </div> |
| 420 | <?php if ($is_admin) { |
| 421 | echo '<a href="#" class="wp-review-hide" data-id=' . $review->id . '>' . ($review->hide == '' ? 'Hide' : 'Show') . ' review</a>'; |
| 422 | } ?> |
| 423 | </div> |
| 424 | </div> |
| 425 | <?php |
| 426 | } |
| 427 | |
| 428 | function grw_slider_review($review, $hr, $options, $is_admin = false) { |
| 429 | $addcls = $options->hide_backgnd ? "" : " grw-backgnd"; |
| 430 | $addcls .= $options->show_round ? " grw-round" : ""; |
| 431 | $addcls .= $options->show_shadow ? " grw-shadow" : ""; |
| 432 | ?><div class="grw-review<?php if ($hr) { echo ' grw-hide'; } ?><?php if ($is_admin && $review->hide != '') { echo ' wp-review-hidden'; } ?>"> |
| 433 | <div class="grw-review-inner<?php echo $addcls; ?>"> |
| 434 | <div class="wp-google-left"> |
| 435 | <?php |
| 436 | // Google reviewer avatar |
| 437 | $default_avatar = GRW_ASSETS_URL . 'img/guest.png'; |
| 438 | if (strlen($review->author_avatar) > 0) { |
| 439 | $author_avatar = $review->author_avatar; |
| 440 | } else { |
| 441 | $author_avatar = $default_avatar; |
| 442 | } |
| 443 | if (isset($options->reviewer_avatar_size)) { |
| 444 | $author_avatar = str_replace(self::G_AVA_SIZE, 's' . $options->reviewer_avatar_size, $author_avatar); |
| 445 | $default_avatar = str_replace(self::G_AVA_SIZE, 's' . $options->reviewer_avatar_size, $default_avatar); |
| 446 | } |
| 447 | $this->grw_image($author_avatar, '', $options->lazy_load_img, $default_avatar); |
| 448 | |
| 449 | // Google reviewer name |
| 450 | if (!empty($review->author_url) || !empty($review->url)) { |
| 451 | $url = empty($review->author_url) ? $review->url : $review->author_url; |
| 452 | $this->grw_anchor($url, 'wp-google-name', $review->author_name, $options, sprintf(__('%s user profile', 'widget-google-reviews'), $review->author_name)); |
| 453 | } else { |
| 454 | if (strlen($review->author_name) > 0) { |
| 455 | $author_name = $review->author_name; |
| 456 | } else { |
| 457 | $author_name = __('Google User', 'widget-google-reviews'); |
| 458 | } |
| 459 | ?><div class="wp-google-name"><?php echo $author_name; ?></div><?php |
| 460 | } |
| 461 | ?> |
| 462 | <div class="wp-google-time" data-time="<?php echo $review->time; ?>"><?php echo gmdate("H:i d M y", $review->time); ?></div> |
| 463 | </div> |
| 464 | <div class="wp-google-stars"><?php echo $this->grw_stars($review->rating); ?></div> |
| 465 | <div class="wp-google-wrap"> |
| 466 | <div class="wp-google-feedback grw-scroll" <?php if (strlen($options->slider_text_height) > 0) {?> style="height:<?php echo $options->slider_text_height; ?>!important"<?php } ?>> |
| 467 | <?php if (strlen($review->text) > 0) { ?> |
| 468 | <span class="wp-google-text"><?php echo $review->text; ?></span> |
| 469 | <?php } ?> |
| 470 | </div><?php |
| 471 | if (isset($options->media) && $options->media && isset($review->images) && strlen($review->images) > 0) { |
| 472 | ?><div class="wp-google-img"><?php |
| 473 | $images = explode(';', $review->images); |
| 474 | foreach ($images as $img) { |
| 475 | ?><img class="rpi-thumb" src="<?php echo preg_replace('/(=.*)s\d{2,3}/', '$1s50', $img); ?>" alt="" loading="lazy"><?php |
| 476 | } |
| 477 | ?></div><?php |
| 478 | } |
| 479 | ?></div><?php |
| 480 | if (isset($options->reply) && $options->reply && isset($review->reply) && strlen($review->reply) > 0) { |
| 481 | ?><div class="wp-google-reply grw-scroll"> |
| 482 | <div> |
| 483 | <span class="grw-b"><?php echo __('Response from the owner', 'widget-google-reviews'); ?></span> |
| 484 | <span class="wp-google-time" data-time="<?php echo $review->reply_time; ?>"> |
| 485 | <?php echo gmdate("H:i d M y", $review->reply_time); ?> |
| 486 | </span> |
| 487 | </div> |
| 488 | <?php echo $review->reply; ?> |
| 489 | </div><?php |
| 490 | } |
| 491 | if ($is_admin) { |
| 492 | echo '<a href="#" class="wp-review-hide" data-id=' . $review->id . '>' . ($review->hide == '' ? 'hide' : 'show') . ' review</a>'; |
| 493 | } |
| 494 | $this->grw_provider($review); |
| 495 | ?></div> |
| 496 | </div><?php |
| 497 | } |
| 498 | |
| 499 | function grw_provider($review) { |
| 500 | ?><svg height="18" width="18" role="none"><use href="#grw-<?php echo $review->provider; ?>"/></svg><?php |
| 501 | } |
| 502 | |
| 503 | function grw_stars($rating) { |
| 504 | ?><span class="wp-stars"><?php |
| 505 | for ($i = 0; $i < 5; $i++) { |
| 506 | $score = $rating - $i; |
| 507 | if ($score <= 0) { |
| 508 | $this->star_o(); |
| 509 | } elseif ($score > 0 && $score < 1) { |
| 510 | if ($score < 0.25) { |
| 511 | $this->star_o(); |
| 512 | } elseif ($score > 0.75) { |
| 513 | $this->star(); |
| 514 | } else { |
| 515 | $this->star_h(); |
| 516 | } |
| 517 | } else { |
| 518 | $this->star(); |
| 519 | } |
| 520 | } |
| 521 | ?></span><?php |
| 522 | } |
| 523 | |
| 524 | function star() { |
| 525 | ?><span class="wp-star"><svg height="18" width="18" role="none"><use href="#grw-star"/></svg></span><?php |
| 526 | } |
| 527 | |
| 528 | function star_h() { |
| 529 | ?><span class="wp-star"><svg height="18" width="18" role="none"><use href="#grw-star-h"/></svg></span><?php |
| 530 | } |
| 531 | |
| 532 | function star_o() { |
| 533 | ?><span class="wp-star"><svg height="18" width="18" role="none"><use href="#grw-star-o"/></svg></span><?php |
| 534 | } |
| 535 | |
| 536 | function grw_anchor($url, $class, $text, $options, $aria_label = '', $onclick = '') { |
| 537 | echo '<a href="' . $url . '"' . ($class ? ' class="' . $class . '"' : '') . ($options->open_link ? ' target="_blank"' : '') . ' rel="' . ($options->nofollow_link ? 'nofollow ' : '') . 'noopener"' . $this->grw_aria_label($options, $aria_label) . (empty($onclick) ? '' : ' onclick="' . $onclick . '"') . '>' . $text . '</a>'; |
| 538 | } |
| 539 | |
| 540 | function grw_aria_label($options, $aria_label = '') { |
| 541 | return isset($options->aria_label) && $options->aria_label && !empty($aria_label) ? |
| 542 | ' role="link" aria-label="' . $aria_label . ' - ' . __('opens in a new window', 'widget-google-reviews') . '"' : ''; |
| 543 | } |
| 544 | |
| 545 | function grw_image($src, $alt, $lazy, $def_ava = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7', $atts = '') { |
| 546 | ?><img src="<?php echo $src; ?>"<?php if ($lazy) { ?> loading="lazy"<?php } ?> class="grw-review-avatar" alt="<?php echo $alt; ?>" width="50" height="50" onerror="if(this.src!='<?php echo $def_ava; ?>')this.src='<?php echo $def_ava; ?>';" <?php echo $atts; ?>><?php |
| 547 | } |
| 548 | |
| 549 | function js_loader($func, $data = '') { |
| 550 | ?><img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" alt="" onload="(function(el, data) {var f = function() { window.<?php echo $func; ?> ? <?php echo $func; ?>(el, data) : setTimeout(f, 400) }; f() })(this<?php if (strlen($data) > 0) { ?>, <?php echo str_replace('"', '\'', $data); } ?>);" width="1" height="1" style="display:none"><?php |
| 551 | } |
| 552 | |
| 553 | function grw_array($params=null) { |
| 554 | if (!is_array($params)) { |
| 555 | $params = func_get_args(); |
| 556 | $params = array_slice($params, 0); |
| 557 | } |
| 558 | return $params; |
| 559 | } |
| 560 | } |
| 561 |