Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Elementor;
- if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
- class Widget_Themeum_Donation extends Widget_Base {
- public function get_name() {
- return 'thm-donation';
- }
- public function get_title() {
- return __( 'Themeum Donation', 'backer' );
- }
- public function get_icon() {
- return 'eicon-apps wts-eae-pe';
- }
- public function get_categories() {
- return [ 'themeum-elementor' ];
- }
- protected function _register_controls() {
- $this->start_controls_section(
- 'section_title',
- [
- 'label' => __( 'Title Element', 'backer' )
- ]
- );
- $this->add_control(
- 'currency',
- [
- 'label' => __( 'Currency List', 'backer' ),
- 'type' => Controls_Manager::SELECT,
- 'options' => getCurrencyList(),
- 'multiple' => true,
- ]
- );
- $this->add_control(
- 'paypalid',
- [
- 'label' => __( 'Paypal ID', 'backer' ),
- 'type' => Controls_Manager::TEXT,
- 'label_block' => true,
- 'placeholder' => __( 'Enter your Paypal ID', 'backer' ),
- 'default' => __( 'Enter your Paypal ID', 'backer' ),
- ]
- );
- $this->add_control(
- 'bg_color',
- [
- 'label' => __( 'Background Color', 'backer' ),
- 'type' => Controls_Manager::COLOR,
- 'scheme' => [
- 'type' => Scheme_Color::get_type(),
- 'value' => Scheme_Color::COLOR_1,
- ],
- 'selectors' => [
- '{{WRAPPER}} h2.bordered span' => 'background: {{VALUE}};',
- ],
- 'condition' => [
- 'title_border' => 'yes',
- ],
- ]
- );
- $this->add_control(
- 'target',
- [
- 'label' => __( 'Target', 'backer' ),
- 'type' => Controls_Manager::SELECT,
- 'default' => '_self',
- 'options' => [
- '_self' => 'Same Window',
- '_blank' => 'New Window',
- ],
- ]
- );
- $this->add_control(
- 'more',
- [
- 'label' => __( 'Target', 'backer' ),
- 'type' => Controls_Manager::SELECT,
- 'default' => '_self',
- 'options' => [
- '1' => 'Yes',
- '0' => 'No',
- ],
- ]
- );
- $this->add_control(
- 'amount1',
- [
- 'label' => __( 'Amount - 1', 'backer' ),
- 'type' => Controls_Manager::TEXT,
- 'label_block' => true,
- 'placeholder' => __( 'Enter your Amount', 'backer' ),
- 'default' => __( 'Enter your Amount', 'backer' ),
- ]
- );
- $this->add_control(
- 'amount2',
- [
- 'label' => __( 'Amount - 2', 'backer' ),
- 'type' => Controls_Manager::TEXT,
- 'label_block' => true,
- 'placeholder' => __( 'Enter your Amount', 'backer' ),
- 'default' => __( 'Enter your Amount', 'backer' ),
- ]
- );
- $this->add_control(
- 'amount3',
- [
- 'label' => __( 'Amount - 3', 'backer' ),
- 'type' => Controls_Manager::TEXT,
- 'label_block' => true,
- 'placeholder' => __( 'Enter your Amount', 'backer' ),
- 'default' => __( 'Enter your Amount', 'backer' ),
- ]
- );
- $this->add_control(
- 'amount4',
- [
- 'label' => __( 'Amount - 4', 'backer' ),
- 'type' => Controls_Manager::TEXT,
- 'label_block' => true,
- 'placeholder' => __( 'Enter your Amount', 'backer' ),
- 'default' => __( 'Enter your Amount', 'backer' ),
- ]
- );
- $this->add_control(
- 'btn_name',
- [
- 'label' => __( 'Button name: Ex. Donate Now', 'backer' ),
- 'type' => Controls_Manager::TEXT,
- 'label_block' => true,
- 'placeholder' => __( 'Donate Now', 'backer' ),
- 'default' => __( 'Donate Now', 'backer' ),
- ]
- );
- }
- protected function render( ) {
- $settings = $this->get_settings();
- $currency = $settings['currency'];
- $paypalid = $settings['paypalid'];
- $target = $settings['target'];
- $more = $settings['more'];
- $bg_color = $settings['bg_color'];
- $amount1 = $settings['amount1'];
- $amount2 = $settings['amount2'];
- $amount3 = $settings['amount3'];
- $amount4 = $settings['amount4'];
- $btn_name = $settings['btn_name'];
- $b_color = 'style="background:'. esc_attr( $bg_color ) .'"';
- $amounts = 0;
- $donations = array(intval($amount1), intval($amount2), intval($amount3), intval($amount4));
- $output = '<div class="politist-addon-donation">';
- $output .= '<div class="donation-ammount-wrap donate-buttons" data-currency="'.$currency.'" data-pid="'.$paypalid.'">';
- $crcy_code = explode(':', $currency);
- print_r($crcy_code[0]);
- foreach ($donations as $key => $donation) {
- $active = ( $key > 1 && ((count($donations)/$key) == $key) ) ? 'active' : '' ;
- if($key==2){
- $output .= '<input class="donation-input '.$active.'" type="text" name="amount" value="'.$crcy_code[1].$donation.'" readonly>';
- $amounts = $donation;
- }else{
- $output .= '<input class="donation-input" type="text" name="amount" value="'.$crcy_code[1].$donation.'" readonly>';
- }
- }
- if ( $more ) {
- $output .= '<input class="donation-input input-text" type="number" name="amount" autocomplete="off" placeholder="'.esc_html__( 'More', 'politist' ).'" min="1">';
- }
- $output .= '</div>'; //.donation-ammount
- $output .= '<div class="donation-button">';
- $output .= '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business='.$paypalid.'&item_name=donation&amount='.$amounts.'¤cy_code='.$crcy_code[0].'" target="' . $target . '" class="filled-button donation-button-link" '.$b_color.'>' . $btn_name . '</a>';
- $output .= '</div>'; //.donation-button
- $output .= '</div>'; //.politist-addon-donation
- print $output;
- }
- protected function _content_template() {
- }
- }
- Plugin::instance()->widgets_manager->register_widget_type( new Widget_Themeum_Donation() );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement