| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Description of ReviewFrontendController |
| 5 |
* |
| 6 |
* @author MA_GROUP |
| 7 |
* |
| 8 |
* @autoload: init |
| 9 |
*/ |
| 10 |
|
| 11 |
namespace AliNext_Lite;; |
| 12 |
|
| 13 |
class ReviewFrontendController |
| 14 |
{ |
| 15 |
|
| 16 |
function __construct() { |
| 17 |
add_action('wp_enqueue_scripts', [$this, 'assets']); |
| 18 |
add_filter('comment_text', [$this, 'comment_text'], 10, 2); |
| 19 |
add_filter('get_avatar_url', array($this, 'get_avatar_url'), 1, 3); |
| 20 |
} |
| 21 |
|
| 22 |
function assets(): void |
| 23 |
{ |
| 24 |
if (function_exists('is_product') && is_product()) { |
| 25 |
wp_enqueue_style( |
| 26 |
'a2wl-review--frontend-style', |
| 27 |
A2WL()->plugin_url() . '/assets/css/review/frontend_style.css', |
| 28 |
[], A2WL()->version |
| 29 |
); |
| 30 |
|
| 31 |
wp_enqueue_script( |
| 32 |
'a2wl-fancybox', |
| 33 |
A2WL()->plugin_url() . '/assets/js/fancybox/fancybox.umd.js', |
| 34 |
[], A2WL()->version, true |
| 35 |
); |
| 36 |
|
| 37 |
wp_enqueue_style( |
| 38 |
'a2wl-fancybox-style', |
| 39 |
A2WL()->plugin_url() . '/assets/css/fancybox/fancybox.css', |
| 40 |
[], A2WL()->version |
| 41 |
); |
| 42 |
|
| 43 |
wp_enqueue_script( |
| 44 |
'a2wl-review-frontend-script', |
| 45 |
A2WL()->plugin_url() . '/assets/js/review/frontend_script.js', |
| 46 |
[], A2WL()->version, true |
| 47 |
); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
function comment_text($comment_text, $comment = null) { |
| 52 |
if (is_null($comment)) { |
| 53 |
return $comment_text; |
| 54 |
} |
| 55 |
|
| 56 |
if (get_setting('review_show_image_list')) { |
| 57 |
$thumb_width = get_setting('review_thumb_width') . "px"; |
| 58 |
$image_list = Review::get_comment_photos($comment->comment_ID); |
| 59 |
|
| 60 |
if ($image_list) { |
| 61 |
$comment_text .= "<div class='a2wl_review_images'>"; |
| 62 |
foreach ($image_list as $img) { |
| 63 |
if (is_array($img)) { |
| 64 |
$comment_text .= "<a class='fancybox' data-fancybox-group='group{$comment->comment_ID}' href='{$img['image']}'><img width='{$thumb_width}' src='{$img['thumb']}'/></a>"; |
| 65 |
} else{ |
| 66 |
$comment_text .= "<a class='fancybox' data-fancybox-group='group{$comment->comment_ID}' href='{$img}'><img width='{$thumb_width}' src='{$img}'/></a>"; |
| 67 |
} |
| 68 |
} |
| 69 |
$comment_text .= "</div>"; |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
return $comment_text; |
| 74 |
} |
| 75 |
|
| 76 |
function get_avatar_url($url, $id_or_email, $args) { |
| 77 |
|
| 78 |
if ($id_or_email instanceof \WP_Comment) { |
| 79 |
$comment = $id_or_email; |
| 80 |
$comment_id = $comment->comment_ID; |
| 81 |
$image_path = get_comment_meta($comment_id, 'a2wl_avatar', true); |
| 82 |
|
| 83 |
$no_avatar_image = get_setting('review_noavatar_photo', A2WL()->plugin_url() . '/assets/img/noavatar.png'); |
| 84 |
|
| 85 |
if (empty($image_path) || is_null($image_path)) { |
| 86 |
$image_path = $no_avatar_image; |
| 87 |
}else{ |
| 88 |
|
| 89 |
if (is_numeric($image_path)){ |
| 90 |
//todo: maybe check url scheme too? |
| 91 |
$photo_id = $image_path; |
| 92 |
$image_path = wp_get_attachment_image_src($photo_id, 'thumbnail'); |
| 93 |
$image_path = $image_path ? $image_path[0] : $no_avatar_image; |
| 94 |
} else { |
| 95 |
$image_path = set_url_scheme($image_path, 'https'); |
| 96 |
} |
| 97 |
|
| 98 |
} |
| 99 |
|
| 100 |
return $image_path; |
| 101 |
} |
| 102 |
|
| 103 |
return $url; |
| 104 |
} |
| 105 |
|
| 106 |
} |
| 107 |
|