theme-elements
2 years ago
accordion.php
4 years ago
audio.php
4 years ago
before-after.php
3 years ago
button.php
4 years ago
carousel-navigation.php
4 years ago
circle-chart.php
3 years ago
contact-box.php
4 years ago
contact-form.php
4 years ago
custom-list.php
4 years ago
divider.php
4 years ago
gallery.php
2 years ago
gmap.php
4 years ago
heading-modern.php
3 years ago
icon.php
3 years ago
image.php
4 years ago
mailchimp.php
4 years ago
modern-button.php
4 years ago
products-grid.php
3 years ago
quote.php
4 years ago
recent-comments.php
3 years ago
recent-posts-grid-carousel.php
4 years ago
recent-posts-land-style.php
4 years ago
recent-posts-masonry.php
4 years ago
recent-posts-tiles-carousel.php
4 years ago
recent-posts-tiles.php
4 years ago
recent-posts-timeline.php
4 years ago
recent-products.php
4 years ago
responsive-table.php
3 years ago
search.php
4 years ago
staff.php
4 years ago
svg.php
3 years ago
tabs.php
3 years ago
testimonial.php
4 years ago
text.php
4 years ago
touch-slider.php
4 years ago
video.php
4 years ago
recent-comments.php
445 lines
| 1 | <?php |
| 2 | namespace Auxin\Plugin\CoreElements\Elementor\Elements; |
| 3 | |
| 4 | use Elementor\Plugin; |
| 5 | use Elementor\Widget_Base; |
| 6 | use Elementor\Controls_Manager; |
| 7 | use Elementor\Group_Control_Typography; |
| 8 | use Elementor\Core\Schemes\Typography; |
| 9 | |
| 10 | |
| 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | exit; // Exit if accessed directly. |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * Elementor 'RecentComments' widget. |
| 17 | * |
| 18 | * Elementor widget that displays an 'RecentComments' with lightbox. |
| 19 | * |
| 20 | * @since 1.0.0 |
| 21 | */ |
| 22 | class RecentComments extends Widget_Base { |
| 23 | |
| 24 | /** |
| 25 | * Get widget name. |
| 26 | * |
| 27 | * Retrieve 'RecentComments' widget name. |
| 28 | * |
| 29 | * @since 1.0.0 |
| 30 | * @access public |
| 31 | * |
| 32 | * @return string Widget name. |
| 33 | */ |
| 34 | public function get_name() { |
| 35 | return 'aux_recentcomments'; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Get widget title. |
| 40 | * |
| 41 | * Retrieve 'RecentComments' widget title. |
| 42 | * |
| 43 | * @since 1.0.0 |
| 44 | * @access public |
| 45 | * |
| 46 | * @return string Widget title. |
| 47 | */ |
| 48 | public function get_title() { |
| 49 | return __('Recent Commented Posts', 'auxin-elements' ); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Get widget icon. |
| 54 | * |
| 55 | * Retrieve 'RecentComments' widget icon. |
| 56 | * |
| 57 | * @since 1.0.0 |
| 58 | * @access public |
| 59 | * |
| 60 | * @return string Widget icon. |
| 61 | */ |
| 62 | public function get_icon() { |
| 63 | return 'eicon-comments auxin-badge'; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Get recent comments. |
| 68 | * |
| 69 | * Retrieve 'RecentComments' widget query. |
| 70 | * |
| 71 | * @since 1.0.0 |
| 72 | * @access public |
| 73 | * |
| 74 | * @return array Query. |
| 75 | */ |
| 76 | public function get_post_types( $args = array() ) { |
| 77 | // Result variable |
| 78 | $result = array( 'all' => __( 'All Post Types', 'auxin-elements' ) ); |
| 79 | // Get all public post types |
| 80 | $get_post_types = get_post_types( array( |
| 81 | 'public' => true, |
| 82 | 'exclude_from_search' => false |
| 83 | ) |
| 84 | ); |
| 85 | foreach ( $get_post_types as $key => $value ) { |
| 86 | $result[ $key ] = ucfirst( $value ); |
| 87 | } |
| 88 | |
| 89 | return $result; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Get widget categories. |
| 94 | * |
| 95 | * Retrieve 'RecentComments' widget icon. |
| 96 | * |
| 97 | * @since 1.0.0 |
| 98 | * @access public |
| 99 | * |
| 100 | * @return string Widget icon. |
| 101 | */ |
| 102 | public function get_categories() { |
| 103 | return array( 'auxin-core' ); |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Register 'RecentComments' widget controls. |
| 108 | * |
| 109 | * Adds different input fields to allow the user to change and customize the widget settings. |
| 110 | * |
| 111 | * @since 1.0.0 |
| 112 | * @access protected |
| 113 | */ |
| 114 | protected function register_controls() { |
| 115 | |
| 116 | /*-----------------------------------------------------------------------------------*/ |
| 117 | /* Content TAB |
| 118 | /*-----------------------------------------------------------------------------------*/ |
| 119 | |
| 120 | $this->start_controls_section( |
| 121 | 'general', |
| 122 | array( |
| 123 | 'label' => __('General', 'auxin-elements' ), |
| 124 | ) |
| 125 | ); |
| 126 | |
| 127 | $this->add_control( |
| 128 | 'post_types', |
| 129 | array( |
| 130 | 'label' => __( 'Post Types', 'auxin-elements' ), |
| 131 | 'label_block' => true, |
| 132 | 'type' => Controls_Manager::SELECT, |
| 133 | 'default' => 0, |
| 134 | 'options' => $this->get_post_types() |
| 135 | ) |
| 136 | ); |
| 137 | |
| 138 | $this->add_control( |
| 139 | 'number', |
| 140 | array( |
| 141 | 'label' => __('Number of comments to show', 'auxin-elements'), |
| 142 | 'label_block' => true, |
| 143 | 'type' => Controls_Manager::NUMBER, |
| 144 | 'default' => '8', |
| 145 | 'min' => 1, |
| 146 | 'step' => 1 |
| 147 | ) |
| 148 | ); |
| 149 | |
| 150 | $this->add_control( |
| 151 | 'show_info', |
| 152 | array( |
| 153 | 'label' => __('Display info','auxin-elements' ), |
| 154 | 'type' => Controls_Manager::SWITCHER, |
| 155 | 'label_on' => __( 'On', 'auxin-elements' ), |
| 156 | 'label_off' => __( 'Off', 'auxin-elements' ), |
| 157 | 'return_value' => 'yes', |
| 158 | 'default' => 'yes' |
| 159 | ) |
| 160 | ); |
| 161 | |
| 162 | $this->end_controls_section(); |
| 163 | |
| 164 | /*-----------------------------------------------------------------------------------*/ |
| 165 | /* title_style_section |
| 166 | /*-----------------------------------------------------------------------------------*/ |
| 167 | |
| 168 | $this->start_controls_section( |
| 169 | 'title_style_section', |
| 170 | array( |
| 171 | 'label' => __( 'Title', 'auxin-elements' ), |
| 172 | 'tab' => Controls_Manager::TAB_STYLE |
| 173 | ) |
| 174 | ); |
| 175 | |
| 176 | $this->start_controls_tabs( 'title_colors' ); |
| 177 | |
| 178 | $this->start_controls_tab( |
| 179 | 'title_color_normal', |
| 180 | array( |
| 181 | 'label' => __( 'Normal' , 'auxin-elements' ) |
| 182 | ) |
| 183 | ); |
| 184 | |
| 185 | $this->add_control( |
| 186 | 'title_color', |
| 187 | array( |
| 188 | 'label' => __( 'Color', 'auxin-elements' ), |
| 189 | 'type' => Controls_Manager::COLOR, |
| 190 | 'selectors' => array( |
| 191 | '{{WRAPPER}} .entry-title a' => 'color: {{VALUE}};', |
| 192 | ) |
| 193 | ) |
| 194 | ); |
| 195 | |
| 196 | $this->end_controls_tab(); |
| 197 | |
| 198 | $this->start_controls_tab( |
| 199 | 'title_color_hover', |
| 200 | array( |
| 201 | 'label' => __( 'Hover' , 'auxin-elements' ) |
| 202 | ) |
| 203 | ); |
| 204 | |
| 205 | $this->add_control( |
| 206 | 'title_hover_color', |
| 207 | array( |
| 208 | 'label' => __( 'Color', 'auxin-elements' ), |
| 209 | 'type' => Controls_Manager::COLOR, |
| 210 | 'selectors' => array( |
| 211 | '{{WRAPPER}} .entry-title a:hover' => 'color: {{VALUE}};', |
| 212 | ) |
| 213 | ) |
| 214 | ); |
| 215 | |
| 216 | $this->end_controls_tab(); |
| 217 | |
| 218 | $this->end_controls_tabs(); |
| 219 | |
| 220 | $this->add_group_control( |
| 221 | Group_Control_Typography::get_type(), |
| 222 | array( |
| 223 | 'name' => 'title_typography', |
| 224 | 'scheme' => Typography::TYPOGRAPHY_1, |
| 225 | 'selector' => '{{WRAPPER}} .entry-title' |
| 226 | ) |
| 227 | ); |
| 228 | |
| 229 | $this->add_responsive_control( |
| 230 | 'title_margin_bottom', |
| 231 | array( |
| 232 | 'label' => __( 'Bottom space', 'auxin-elements' ), |
| 233 | 'type' => Controls_Manager::SLIDER, |
| 234 | 'range' => array( |
| 235 | 'px' => array( |
| 236 | 'max' => 100, |
| 237 | ), |
| 238 | ), |
| 239 | 'selectors' => array( |
| 240 | '{{WRAPPER}} .entry-title' => 'margin-bottom: {{SIZE}}{{UNIT}};', |
| 241 | ) |
| 242 | ) |
| 243 | ); |
| 244 | |
| 245 | $this->end_controls_section(); |
| 246 | |
| 247 | /*-----------------------------------------------------------------------------------*/ |
| 248 | /* info_style_section |
| 249 | /*-----------------------------------------------------------------------------------*/ |
| 250 | |
| 251 | $this->start_controls_section( |
| 252 | 'info_style_section', |
| 253 | array( |
| 254 | 'label' => __( 'Meta Info', 'auxin-elements' ), |
| 255 | 'tab' => Controls_Manager::TAB_STYLE |
| 256 | ) |
| 257 | ); |
| 258 | |
| 259 | $this->start_controls_tabs( 'info_colors' ); |
| 260 | |
| 261 | $this->start_controls_tab( |
| 262 | 'info_color_normal', |
| 263 | array( |
| 264 | 'label' => __( 'Normal' , 'auxin-elements' ) |
| 265 | ) |
| 266 | ); |
| 267 | |
| 268 | $this->add_control( |
| 269 | 'info_color', |
| 270 | array( |
| 271 | 'label' => __( 'Color', 'auxin-elements' ), |
| 272 | 'type' => Controls_Manager::COLOR, |
| 273 | 'selectors' => array( |
| 274 | '{{WRAPPER}} .entry-info a, {{WRAPPER}} .entry-info' => 'color: {{VALUE}};', |
| 275 | ) |
| 276 | ) |
| 277 | ); |
| 278 | |
| 279 | $this->end_controls_tab(); |
| 280 | |
| 281 | $this->start_controls_tab( |
| 282 | 'info_color_hover', |
| 283 | array( |
| 284 | 'label' => __( 'Hover' , 'auxin-elements' ) |
| 285 | ) |
| 286 | ); |
| 287 | |
| 288 | $this->add_control( |
| 289 | 'info_hover_color', |
| 290 | array( |
| 291 | 'label' => __( 'Color', 'auxin-elements' ), |
| 292 | 'type' => Controls_Manager::COLOR, |
| 293 | 'selectors' => array( |
| 294 | '{{WRAPPER}} .entry-info a:hover' => 'color: {{VALUE}};', |
| 295 | ) |
| 296 | ) |
| 297 | ); |
| 298 | |
| 299 | $this->end_controls_tab(); |
| 300 | |
| 301 | $this->end_controls_tabs(); |
| 302 | |
| 303 | $this->add_group_control( |
| 304 | Group_Control_Typography::get_type(), |
| 305 | array( |
| 306 | 'name' => 'info_typography', |
| 307 | 'scheme' => Typography::TYPOGRAPHY_1, |
| 308 | 'selector' => '{{WRAPPER}} .entry-info, {{WRAPPER}} .entry-info a' |
| 309 | ) |
| 310 | ); |
| 311 | |
| 312 | $this->add_responsive_control( |
| 313 | 'info_margin_bottom', |
| 314 | array( |
| 315 | 'label' => __( 'Bottom space', 'auxin-elements' ), |
| 316 | 'type' => Controls_Manager::SLIDER, |
| 317 | 'range' => array( |
| 318 | 'px' => array( |
| 319 | 'max' => 100 |
| 320 | ) |
| 321 | ), |
| 322 | 'selectors' => array( |
| 323 | '{{WRAPPER}} .entry-info' => 'margin-bottom: {{SIZE}}{{UNIT}};' |
| 324 | ) |
| 325 | ) |
| 326 | ); |
| 327 | |
| 328 | $this->add_responsive_control( |
| 329 | 'info_spacing_between', |
| 330 | array( |
| 331 | 'label' => __( 'Space between metas', 'auxin-elements' ), |
| 332 | 'type' => Controls_Manager::SLIDER, |
| 333 | 'range' => array( |
| 334 | 'px' => array( |
| 335 | 'max' => 30 |
| 336 | ) |
| 337 | ), |
| 338 | 'selectors' => array( |
| 339 | '{{WRAPPER}} .entry-info [class^="entry-"] + [class^="entry-"]:before, {{WRAPPER}} .entry-info .entry-tax a:after' => |
| 340 | 'margin-right: {{SIZE}}{{UNIT}}; margin-left: {{SIZE}}{{UNIT}};' |
| 341 | ) |
| 342 | ) |
| 343 | ); |
| 344 | |
| 345 | $this->end_controls_section(); |
| 346 | |
| 347 | } |
| 348 | |
| 349 | |
| 350 | /** |
| 351 | * Get recent comments. |
| 352 | * |
| 353 | * Retrieve 'RecentComments' widget query. |
| 354 | * |
| 355 | * @since 1.0.0 |
| 356 | * @access public |
| 357 | * |
| 358 | * @return array Query. |
| 359 | */ |
| 360 | public function get_comments( $args = array() ) { |
| 361 | // The Query |
| 362 | $comments_query = new WP_Comment_Query; |
| 363 | $comments = $comments_query->query( $args ); |
| 364 | return $comments; |
| 365 | } |
| 366 | |
| 367 | /** |
| 368 | * Render recentcomments widget output on the frontend. |
| 369 | * |
| 370 | * Written in PHP and used to generate the final HTML. |
| 371 | * |
| 372 | * @since 1.0.0 |
| 373 | * @access protected |
| 374 | */ |
| 375 | protected function render() { |
| 376 | $settings = $this->get_settings_for_display(); |
| 377 | $query_args = array(); |
| 378 | |
| 379 | if( $settings['post_types'] !== 'all' ){ |
| 380 | $query_args['post_type'] = $settings['post_types']; |
| 381 | } |
| 382 | |
| 383 | if( isset( $settings['number'] ) ){ |
| 384 | $query_args['number'] = $settings['number']; |
| 385 | } |
| 386 | |
| 387 | $comments = auxin_get_comments( $query_args ); |
| 388 | |
| 389 | // Defining default attributes |
| 390 | $default_atts = array( |
| 391 | 'title' => '', |
| 392 | 'direction' => 'horizontal', |
| 393 | 'size' => 'medium', |
| 394 | |
| 395 | 'extra_classes' => '', |
| 396 | 'custom_el_id' => '', |
| 397 | 'base_class' => 'aux-widget-recent-comments' |
| 398 | ); |
| 399 | |
| 400 | $result = auxin_get_widget_scafold( array(), $default_atts ); |
| 401 | extract( $result['parsed_atts'] ); |
| 402 | |
| 403 | // widget header ------------------------------ |
| 404 | echo wp_kses_post( $result['widget_header'] ); |
| 405 | echo wp_kses_post( $result['widget_title'] ); |
| 406 | |
| 407 | if( empty( $comments ) ){ |
| 408 | echo sprintf( '<p>%s<p>', esc_html__( 'No comments found!', 'auxin-elements' ) ); |
| 409 | } else { |
| 410 | // widget output ----------------------- |
| 411 | ob_start(); |
| 412 | foreach ( $comments as $key => $comment ): |
| 413 | ?> |
| 414 | <div id="aux-comment-<?php echo esc_attr( $comment->comment_ID ); ?>" class="aux-comment"> |
| 415 | <div class="entry-header"> |
| 416 | <h3 class="entry-title aux-h3"> |
| 417 | <a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>" title="<?php echo esc_attr( get_the_title( $comment->comment_post_ID ) ); ?>"> |
| 418 | <?php echo wp_kses_post( get_the_title( $comment->comment_post_ID ) ); ?> |
| 419 | </a> |
| 420 | </h3> |
| 421 | </div> |
| 422 | <?php if( isset( $settings['show_info'] ) && auxin_is_true( $settings['show_info'] ) ) : ?> |
| 423 | <div class="entry-info"> |
| 424 | <div class="entry-date"> |
| 425 | <?php echo human_time_diff( strtotime( $comment->comment_date_gmt ) ) . ' ' . esc_html__( 'Ago', 'auxin-elements' ); ?> |
| 426 | </div> |
| 427 | <div class="entry-author"> |
| 428 | <span class="meta-sep"><?php echo esc_html__( 'By', 'auxin-elements' ); ?></span> |
| 429 | <span class="author vcard"><?php echo esc_html( $comment->comment_author ); ?></span> |
| 430 | </div> |
| 431 | </div> |
| 432 | <?php endif; ?> |
| 433 | </div> |
| 434 | <?php |
| 435 | endforeach; |
| 436 | echo ob_get_clean(); |
| 437 | } |
| 438 | |
| 439 | // widget footer ------------------------------ |
| 440 | echo wp_kses_post( $result['widget_footer'] ); |
| 441 | |
| 442 | } |
| 443 | |
| 444 | } |
| 445 |