| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPDeveloper\BetterDocs\Shortcodes; |
| 4 |
|
| 5 |
use WPDeveloper\BetterDocs\Core\Shortcode; |
| 6 |
|
| 7 |
class Reactions extends Shortcode { |
| 8 |
public $view_wrapper = 'betterdocs-article-reactions'; |
| 9 |
|
| 10 |
public function get_name() { |
| 11 |
return 'betterdocs_article_reactions'; |
| 12 |
} |
| 13 |
|
| 14 |
public function get_style_depends() { |
| 15 |
return [ 'betterdocs-reactions' ]; |
| 16 |
} |
| 17 |
|
| 18 |
public function get_script_depends() { |
| 19 |
return [ 'betterdocs-reactions' ]; |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Summary of default_attributes |
| 24 |
* @return array |
| 25 |
*/ |
| 26 |
public function default_attributes() { |
| 27 |
return [ |
| 28 |
'text' => '', |
| 29 |
'text_tag' => 'h5', |
| 30 |
'layout' => 'layout-1', |
| 31 |
'happy' => true, |
| 32 |
'happy_icon' => '', |
| 33 |
'normal' => true, |
| 34 |
'normal_icon' => '', |
| 35 |
'sad' => true, |
| 36 |
'sad_icon' => '', |
| 37 |
]; |
| 38 |
} |
| 39 |
|
| 40 |
public function generate_attributes() { |
| 41 |
$attributes = [ |
| 42 |
'class' => [ |
| 43 |
$this->attributes['layout'] |
| 44 |
] |
| 45 |
]; |
| 46 |
|
| 47 |
return $attributes; |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Summary of render |
| 52 |
* |
| 53 |
* @param mixed $atts |
| 54 |
* @param mixed $content |
| 55 |
* @return mixed |
| 56 |
*/ |
| 57 |
public function render( $atts, $content = null ) { |
| 58 |
$args = [ |
| 59 |
'happy' => $atts['happy'], |
| 60 |
'happy_icon' => $atts['happy_icon'], |
| 61 |
'normal' => $atts['normal'], |
| 62 |
'normal_icon' => $atts['normal_icon'], |
| 63 |
'sad' => $atts['sad'], |
| 64 |
'sad_icon' => $atts['sad_icon'] |
| 65 |
]; |
| 66 |
|
| 67 |
if ( isset( $atts['layout'] ) && $atts['layout'] == 'layout-2' ) { |
| 68 |
$this->views( 'widgets/reactions-2', $args ); |
| 69 |
} elseif ( isset( $atts['layout'] ) && $atts['layout'] == 'layout-3' ) { |
| 70 |
$this->views( 'widgets/reactions-3', $args ); |
| 71 |
} else { |
| 72 |
$this->views( 'widgets/reactions', $args ); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
public function view_params() { |
| 77 |
$wrapper_attr = $this->generate_attributes(); |
| 78 |
$reactions_text = ! empty( $this->attributes['text'] ) ? $this->attributes['text'] : $this->customizer->get( |
| 79 |
'betterdocs_post_reactions_text', |
| 80 |
__( 'What are your Feelings', 'betterdocs' ) |
| 81 |
); |
| 82 |
$text_tag = ! empty( $this->attributes['text_tag'] ) ? $this->attributes['text_tag'] : $this->customizer->get( |
| 83 |
'betterdocs_reactions_title_tag', |
| 84 |
'h5' |
| 85 |
); |
| 86 |
|
| 87 |
return [ |
| 88 |
'wrapper_attr' => $wrapper_attr, |
| 89 |
'reactions_text' => $reactions_text, |
| 90 |
'text_tag' => $text_tag |
| 91 |
]; |
| 92 |
} |
| 93 |
} |
| 94 |
|