Advertisement
rejuancse

thm-donate

Sep 19th, 2018
1,298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.29 KB | None | 0 0
  1. <?php
  2. namespace Elementor;
  3.  
  4. if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
  5.  
  6. class Widget_Themeum_Donation extends Widget_Base {
  7.     public function get_name() {
  8.         return 'thm-donation';
  9.     }
  10.  
  11.     public function get_title() {
  12.         return __( 'Themeum Donation', 'backer' );
  13.     }
  14.  
  15.     public function get_icon() {
  16.         return 'eicon-apps wts-eae-pe';
  17.     }
  18.  
  19.     public function get_categories() {
  20.         return [ 'themeum-elementor' ];
  21.     }
  22.  
  23.     protected function _register_controls() {
  24.         $this->start_controls_section(
  25.             'section_title',
  26.             [
  27.                 'label' => __( 'Title Element', 'backer' )
  28.             ]
  29.         );
  30.  
  31.         $this->add_control(
  32.             'currency',
  33.             [
  34.                 'label' => __( 'Currency List', 'backer' ),
  35.                 'type' => Controls_Manager::SELECT,
  36.                 'options' => getCurrencyList(),
  37.                 'multiple' => true,
  38.             ]
  39.         );
  40.  
  41.         $this->add_control(
  42.             'paypalid',
  43.             [
  44.                 'label' => __( 'Paypal ID', 'backer' ),
  45.                 'type' => Controls_Manager::TEXT,
  46.                 'label_block' => true,
  47.                 'placeholder' => __( 'Enter your Paypal ID', 'backer' ),
  48.                 'default' => __( 'Enter your Paypal ID', 'backer' ),
  49.             ]
  50.         );
  51.  
  52.         $this->add_control(
  53.             'bg_color',
  54.             [
  55.                 'label'     => __( 'Background Color', 'backer' ),
  56.                 'type'      => Controls_Manager::COLOR,
  57.                 'scheme'    => [
  58.                     'type'  => Scheme_Color::get_type(),
  59.                     'value' => Scheme_Color::COLOR_1,
  60.                 ],
  61.                 'selectors' => [
  62.                     '{{WRAPPER}} h2.bordered span' => 'background: {{VALUE}};',
  63.                 ],
  64.                 'condition' => [
  65.                     'title_border' => 'yes',
  66.                 ],
  67.             ]
  68.         );
  69.  
  70.         $this->add_control(
  71.             'target',
  72.             [
  73.                 'label'     => __( 'Target', 'backer' ),
  74.                 'type'      => Controls_Manager::SELECT,
  75.                 'default'   => '_self',
  76.                 'options'   => [
  77.                         '_self'     => 'Same Window',
  78.                         '_blank'    => 'New Window',
  79.                     ],
  80.             ]
  81.         );
  82.  
  83.         $this->add_control(
  84.             'more',
  85.             [
  86.                 'label'     => __( 'Target', 'backer' ),
  87.                 'type'      => Controls_Manager::SELECT,
  88.                 'default'   => '_self',
  89.                 'options'   => [
  90.                         '1'     => 'Yes',
  91.                         '0'     => 'No',
  92.                     ],
  93.             ]
  94.         );
  95.  
  96.         $this->add_control(
  97.             'amount1',
  98.             [
  99.                 'label' => __( 'Amount - 1', 'backer' ),
  100.                 'type' => Controls_Manager::TEXT,
  101.                 'label_block' => true,
  102.                 'placeholder' => __( 'Enter your Amount', 'backer' ),
  103.                 'default' => __( 'Enter your Amount', 'backer' ),
  104.             ]
  105.         );
  106.  
  107.         $this->add_control(
  108.             'amount2',
  109.             [
  110.                 'label' => __( 'Amount - 2', 'backer' ),
  111.                 'type' => Controls_Manager::TEXT,
  112.                 'label_block' => true,
  113.                 'placeholder' => __( 'Enter your Amount', 'backer' ),
  114.                 'default' => __( 'Enter your Amount', 'backer' ),
  115.             ]
  116.         );
  117.  
  118.         $this->add_control(
  119.             'amount3',
  120.             [
  121.                 'label' => __( 'Amount - 3', 'backer' ),
  122.                 'type' => Controls_Manager::TEXT,
  123.                 'label_block' => true,
  124.                 'placeholder' => __( 'Enter your Amount', 'backer' ),
  125.                 'default' => __( 'Enter your Amount', 'backer' ),
  126.             ]
  127.         );
  128.  
  129.         $this->add_control(
  130.             'amount4',
  131.             [
  132.                 'label' => __( 'Amount - 4', 'backer' ),
  133.                 'type' => Controls_Manager::TEXT,
  134.                 'label_block' => true,
  135.                 'placeholder' => __( 'Enter your Amount', 'backer' ),
  136.                 'default' => __( 'Enter your Amount', 'backer' ),
  137.             ]
  138.         );
  139.  
  140.         $this->add_control(
  141.             'btn_name',
  142.             [
  143.                 'label' => __( 'Button name: Ex. Donate Now', 'backer' ),
  144.                 'type' => Controls_Manager::TEXT,
  145.                 'label_block' => true,
  146.                 'placeholder' => __( 'Donate Now', 'backer' ),
  147.                 'default' => __( 'Donate Now', 'backer' ),
  148.             ]
  149.         );
  150.        
  151.  
  152.  
  153.  
  154.     }
  155.  
  156.     protected function render( ) {
  157.         $settings = $this->get_settings();
  158.         $currency   = $settings['currency'];
  159.         $paypalid   = $settings['paypalid'];
  160.         $target     = $settings['target'];
  161.         $more       = $settings['more'];
  162.         $bg_color   = $settings['bg_color'];
  163.         $amount1    = $settings['amount1'];
  164.         $amount2    = $settings['amount2'];
  165.         $amount3    = $settings['amount3'];
  166.         $amount4    = $settings['amount4'];
  167.         $btn_name   = $settings['btn_name'];
  168.  
  169.         $b_color = 'style="background:'. esc_attr( $bg_color ) .'"';
  170.  
  171.         $amounts = 0;
  172.         $donations = array(intval($amount1), intval($amount2), intval($amount3), intval($amount4));
  173.         $output  = '<div class="politist-addon-donation">';
  174.         $output .= '<div class="donation-ammount-wrap donate-buttons" data-currency="'.$currency.'" data-pid="'.$paypalid.'">';
  175.  
  176.         $crcy_code = explode(':', $currency);
  177.         print_r($crcy_code[0]);
  178.  
  179.  
  180.             foreach ($donations as $key => $donation) {
  181.  
  182.  
  183.  
  184.                 $active = ( $key > 1 && ((count($donations)/$key) == $key) ) ? 'active' : '' ;
  185.                 if($key==2){
  186.                     $output .= '<input class="donation-input '.$active.'" type="text" name="amount" value="'.$crcy_code[1].$donation.'" readonly>';
  187.                     $amounts = $donation;
  188.                 }else{
  189.                     $output .= '<input class="donation-input" type="text" name="amount" value="'.$crcy_code[1].$donation.'" readonly>';                
  190.                 }
  191.             }
  192.             if ( $more ) {
  193.                 $output .= '<input class="donation-input input-text" type="number" name="amount" autocomplete="off" placeholder="'.esc_html__( 'More', 'politist' ).'" min="1">';
  194.             }
  195.         $output .= '</div>'; //.donation-ammount
  196.         $output .= '<div class="donation-button">';
  197.             $output .= '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business='.$paypalid.'&item_name=donation&amount='.$amounts.'&currency_code='.$crcy_code[0].'" target="' . $target . '" class="filled-button donation-button-link" '.$b_color.'>' . $btn_name . '</a>';
  198.         $output .= '</div>'; //.donation-button
  199.         $output .= '</div>'; //.politist-addon-donation
  200.  
  201.         print $output;
  202.     }
  203.  
  204.     protected function _content_template() {
  205.        
  206.     }
  207. }
  208.  
  209. Plugin::instance()->widgets_manager->register_widget_type( new Widget_Themeum_Donation() );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement