| 1 |
<?php |
| 2 |
namespace ULTP\blocks; |
| 3 |
|
| 4 |
defined('ABSPATH') || exit; |
| 5 |
|
| 6 |
class Post_Comments{ |
| 7 |
public function __construct() { |
| 8 |
add_action('init', array($this, 'register')); |
| 9 |
} |
| 10 |
public function get_attributes() { |
| 11 |
|
| 12 |
return array( |
| 13 |
'blockId' => '', |
| 14 |
'layout' => 'layout1', |
| 15 |
/*============================ |
| 16 |
Post Comment Settings |
| 17 |
============================*/ |
| 18 |
// Comments Form Heading |
| 19 |
'replyHeading' => true, |
| 20 |
'leaveRepText' => 'Leave a Reply', |
| 21 |
|
| 22 |
/*============================ |
| 23 |
Comments Form Input |
| 24 |
============================*/ |
| 25 |
"inputPlaceHolder" => "Express your thoughts, idea or write a feedback by clicking here & start an awesome comment", |
| 26 |
|
| 27 |
/*============================ |
| 28 |
Comments Form label style |
| 29 |
============================*/ |
| 30 |
'inputLabel' => true, |
| 31 |
"cmntInputText" => "Comment's", |
| 32 |
"nameInputText" => "Name", |
| 33 |
"emailInputText" => "Email", |
| 34 |
"webInputText" => "Website Url", |
| 35 |
'cookiesEnable' => true, |
| 36 |
'cookiesText' => "Save my name, email, and website in this browser for the next time I comment.", |
| 37 |
|
| 38 |
/*============================ |
| 39 |
Submit Button Style |
| 40 |
============================*/ |
| 41 |
'subBtnText' => 'Post Comment', |
| 42 |
|
| 43 |
/*============================ |
| 44 |
Comment Reply Style |
| 45 |
============================*/ |
| 46 |
// Title and total Comment Count |
| 47 |
'replyText' => 'Comments Text', |
| 48 |
'commentCount' => true, |
| 49 |
|
| 50 |
//-------------------------- |
| 51 |
// Advanced Settings |
| 52 |
//-------------------------- |
| 53 |
'advanceId' => '', |
| 54 |
'advanceZindex' => '', |
| 55 |
'hideExtraLarge' => false, |
| 56 |
'hideDesktop' => false, |
| 57 |
'hideTablet' => false, |
| 58 |
'hideMobile' => false, |
| 59 |
'advanceCss' => '', |
| 60 |
); |
| 61 |
} |
| 62 |
|
| 63 |
public function register() { |
| 64 |
register_block_type( 'ultimate-post/post-comments', |
| 65 |
array( |
| 66 |
'editor_script' => 'ultp-blocks-editor-script', |
| 67 |
'editor_style'=> 'ultp-blocks-editor-css', |
| 68 |
'render_callback' => array($this, 'content') |
| 69 |
) |
| 70 |
); |
| 71 |
} |
| 72 |
|
| 73 |
public function content($attr, $noAjax) { |
| 74 |
$attr = wp_parse_args($attr, $this->get_attributes()); |
| 75 |
$block_name = 'post-comments'; |
| 76 |
$wrapper_before = $wrapper_after = $wrapper_content = ''; |
| 77 |
|
| 78 |
if(is_single()){ |
| 79 |
|
| 80 |
$attr['className'] = isset($attr['className']) && $attr['className'] ? preg_replace('/[^A-Za-z0-9_ -]/', '', $attr['className']) : ''; |
| 81 |
$attr['align'] = isset($attr['align']) && $attr['align'] ? preg_replace('/[^A-Za-z0-9_ -]/', '', $attr['align']) : ''; |
| 82 |
$attr['advanceId'] = isset($attr['advanceId']) ? sanitize_html_class( $attr['advanceId'] ) : ''; |
| 83 |
$attr['blockId'] = isset($attr['blockId']) ? sanitize_html_class( $attr['blockId'] ) : ''; |
| 84 |
$attr['layout'] = sanitize_html_class( $attr['layout'] ); |
| 85 |
|
| 86 |
$allowed_html_tags = ultimate_post()->ultp_allowed_html_tags(); |
| 87 |
$attr['nameInputText'] = wp_kses($attr['nameInputText'], $allowed_html_tags); |
| 88 |
$attr['emailInputText'] = wp_kses($attr['emailInputText'], $allowed_html_tags); |
| 89 |
$attr['webInputText'] = wp_kses($attr['webInputText'], $allowed_html_tags); |
| 90 |
$attr['cmntInputText'] = wp_kses($attr['cmntInputText'], $allowed_html_tags); |
| 91 |
$attr['cookiesText'] = wp_kses($attr['cookiesText'], $allowed_html_tags); |
| 92 |
$attr['inputPlaceHolder'] = wp_kses($attr['inputPlaceHolder'], $allowed_html_tags); |
| 93 |
$attr['subBtnText'] = wp_kses($attr['subBtnText'], $allowed_html_tags); |
| 94 |
$attr['leaveRepText'] = wp_kses($attr['leaveRepText'], $allowed_html_tags); |
| 95 |
$attr['replyText'] = wp_kses($attr['replyText'], $allowed_html_tags); |
| 96 |
|
| 97 |
|
| 98 |
$commenter = wp_get_current_commenter(); |
| 99 |
$req = get_option( 'require_name_email' ); |
| 100 |
$aria_req = ( $req ? " aria-required='true'" : '' ); |
| 101 |
|
| 102 |
$auth_label = $attr['inputLabel'] ? '<label for="author">' . __( ''.$attr["nameInputText"].'' ) . '' .( $req ? '<span class="required">*</span>' : '' ) . '</label>' : ''; |
| 103 |
$email_label = $attr['inputLabel'] ? '<label for="email">' . __( ''.$attr["emailInputText"].'' ) . '' . ( $req ? '<span class="required">*</span>' : '' ).'</label>' : ''; |
| 104 |
$url_label = $attr['inputLabel'] ? '<label for="url">' . __( ''.$attr["webInputText"].'', 'domainreference' ) . '</label>' : ''; |
| 105 |
$comment_label = $attr['inputLabel'] ? '<label for="comment">' . __( ''.$attr["cmntInputText"].'' ) . '</label>' : ''; |
| 106 |
$cookies_label = $attr['cookiesEnable'] ? '<p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"/><label for="wp-comment-cookies-consent">'.$attr["cookiesText"].'</label></p>' : ''; |
| 107 |
|
| 108 |
$comments_args = array( |
| 109 |
'comment_field' => '<div class="comment-form-comment ultp-comment-input ultp-field-control">' .$comment_label.'<textarea class="hi" id="comment" name="comment" placeholder="'.$attr["inputPlaceHolder"].'" cols="45" rows="8" aria-required="true"></textarea></div>', |
| 110 |
'fields' => apply_filters( 'comment_form_default_fields', array( |
| 111 |
'author' =>'<div class="ultp-field-control ultp-comment-name">'.$auth_label.'<input id="author" placeholder="Your Name (No Keywords)" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></div>', |
| 112 |
'email'=> '<div class="ultp-field-control ultp-comment-email">'.$email_label.'<input id="email" placeholder="your-real-email@example.com" name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ).'" size="30"' . $aria_req . ' /></div>', |
| 113 |
'url' => '<div class="ultp-field-control ultp-comment-website">'.$url_label.'<input id="url" name="url" placeholder="http://your-site-name.com" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></div>', |
| 114 |
'cookies'=> $cookies_label |
| 115 |
) |
| 116 |
), |
| 117 |
'class_submit' => 'ultp-comment-btn', |
| 118 |
'comment_notes_after' => '', |
| 119 |
'submit_button' => '<input name="%1$s" type="submit" id="%2$s" className="%3$s ultp-comment-btn" value="'.$attr['subBtnText'].'" />', |
| 120 |
'class_form' => 'ultp-comment-form', |
| 121 |
'title_reply' => ($attr['replyHeading'] ? '<div class="crunchify-text ultp-comments-title">'.$attr['leaveRepText'].'</div>' : ''), |
| 122 |
'class_container' => 'ultp-comment-form-container' |
| 123 |
); |
| 124 |
|
| 125 |
$arg = array( |
| 126 |
'walker' => null, |
| 127 |
'max_depth' => '', |
| 128 |
'style' => 'ul', |
| 129 |
'callback' => null, |
| 130 |
'end-callback' => null, |
| 131 |
'type' => 'comment', |
| 132 |
'page' => '', |
| 133 |
'per_page' => '', |
| 134 |
'avatar_size' => 32, |
| 135 |
'reverse_top_level' => true, |
| 136 |
'reverse_children' => '', |
| 137 |
'format' => current_theme_supports( 'html5', 'comment-list' ) ? 'html5' : 'xhtml', |
| 138 |
'short_ping' => false, |
| 139 |
'echo' => true, |
| 140 |
); |
| 141 |
|
| 142 |
$comments = get_comments(array( 'post_id' => get_the_ID() )); |
| 143 |
|
| 144 |
$wrapper_before .= '<div '.($attr['advanceId'] ? 'id="'.$attr['advanceId'].'" ':'').' class="wp-block-ultimate-post-'.$block_name.' ultp-block-'.$attr["blockId"].( $attr["className"] ?' '.$attr["className"]:'').''.( $attr["align"] ? ' align' .$attr["align"]:'').'">'; |
| 145 |
$wrapper_before .= '<div class="ultp-block-wrapper ultp-block-comments ultp-comments-'.$attr['layout'].'">'; |
| 146 |
if ($attr["commentCount"] && count($comments) > 0) { |
| 147 |
$wrapper_content .= '<div class="ultp-comment-reply-heading">'; |
| 148 |
$wrapper_content .= count($comments).' '.$attr['replyText']; |
| 149 |
$wrapper_content .= '</div>'; |
| 150 |
} |
| 151 |
$wrapper_content.= '<div class="ultp-builder-comment-reply">'; |
| 152 |
ob_start(); |
| 153 |
wp_list_comments($arg, $comments); |
| 154 |
$wrapper_content .= ob_get_clean(); |
| 155 |
$wrapper_content .= '</div>'; |
| 156 |
$wrapper_content .= '<div class="ultp-builder-comments">'; |
| 157 |
ob_start(); |
| 158 |
comment_form( $comments_args ); |
| 159 |
$wrapper_content .= ob_get_clean(); |
| 160 |
$wrapper_content .= '</div>'; |
| 161 |
$wrapper_after .= '</div>'; |
| 162 |
$wrapper_after .= '</div>'; |
| 163 |
} |
| 164 |
|
| 165 |
return $wrapper_before.$wrapper_content.$wrapper_after; |
| 166 |
} |
| 167 |
} |