insightdes

splitImageText.php

Jul 18th, 2018
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.69 KB | None | 0 0
  1. <?php
  2.  
  3. class splitImageText extends ET_Builder_Module {
  4.     function init() {
  5.         $this->name       = esc_html__( 'Split Image Text', 'et_builder' );
  6.         $this->slug       = 'insightdesign_split_image_text';
  7.         $this->vb_support = 'on';
  8.  
  9.         $this->main_css_element = '%%order_class%%.insightdesign_split_image_text';
  10.  
  11.         $this->settings_modal_toggles = array(
  12.             'general'  => array(
  13.                 'toggles' => array(
  14.                     'main_content'  => esc_html__( 'Text', 'et_builder' ),
  15.                     'image'         => esc_html__( 'Image', 'et_builder' ),
  16.                 ),
  17.             ),
  18.             'advanced' => array(
  19.                 'toggles' => array(
  20.                     'image' => esc_html__( 'Image', 'et_builder' ),
  21.                     'text'  => array(
  22.                         'title'    => esc_html__( 'Text', 'et_builder' ),
  23.                         'priority' => 49,
  24.                     ),
  25.                     'color'  => esc_html__( 'Color', 'et_builder' ),
  26.                 ),
  27.             ),
  28.             'custom_css' => array(
  29.                 'toggles' => array(
  30.                     'animation' => array(
  31.                         'title'    => esc_html__( 'Animation', 'et_builder' ),
  32.                         'priority' => 90,
  33.                     ),
  34.                 ),
  35.             ),
  36.         );
  37.  
  38.         $this->advanced_fields = array(
  39.             'background'            => array(
  40.                 'settings' => array(
  41.                     'color' => 'alpha',
  42.                 ),
  43.             ),
  44.             'image'                 => array(
  45.                 'css' => array(
  46.                     'main' => '%%order_class%% .et_insightdesign_split_image',
  47.                 ),
  48.             ),
  49.             'button'                => false,
  50.         );
  51.     }  
  52.  
  53.     function get_fields() {
  54.         $fields = array(
  55.             'sit_title' => array(
  56.                 'label'           => esc_html__( 'Title', 'et_builder' ),
  57.                 'type'            => 'text',
  58.                 'option_category' => 'basic_option',
  59.                 'description'     => esc_html__( 'Input the title of the section', 'et_builder' ),
  60.                 'toggle_slug'     => 'main_content',
  61.             ),
  62.             'sit_date' => array(
  63.                 'label'           => esc_html__( 'Date to display', 'et_builder' ),
  64.                 'type'            => 'text',
  65.                 'option_category' => 'basic_option',
  66.                 'description'     => esc_html__( 'Input the date for your module here.', 'et_builder' ),
  67.                 'toggle_slug'     => 'main_content',
  68.             ),
  69.             'sit_text_color' => array(
  70.                 'label'           => esc_html__( 'Text Colour', 'et_builder'),
  71.                 'type'            => 'text_color',
  72.                 'option_category' => 'basic_option',
  73.                 'description'     => esc_html__( 'Input the color of the text', 'et_builder' ),
  74.                 'toggle_slug'     => 'main_content',
  75.             ),
  76.             'sit_link' => array(
  77.                 'label'           => esc_html__( 'Link', 'et_builder' ),
  78.                 'type'            => 'text',
  79.                 'option_category' => 'basic_option',
  80.                 'description'     => esc_html__( "What URL does this module link to?", 'et_builder' ),
  81.                 'toggle_slug'     => 'main_content',
  82.             ),
  83.             'sit_image' => array(
  84.                 'label'              => esc_html__( 'Image URL', 'et_builder' ),
  85.                 'type'               => 'upload',
  86.                 'option_category'    => 'basic_option',
  87.                 'upload_button_text' => esc_attr__( 'Upload an image', 'et_builder' ),
  88.                 'choose_text'        => esc_attr__( 'Choose an Image', 'et_builder' ),
  89.                 'update_text'        => esc_attr__( 'Set As Image', 'et_builder' ),
  90.                 'description'        => esc_html__( 'Upload your desired image, or type in the URL to the image you would like to display.', 'et_builder' ),
  91.                 'toggle_slug'        => 'image',
  92.                 'affects'            => array('sit_color',),
  93.             ),
  94.             'sit_color' => array(
  95.                 'default'         => et_builder_accent_color(),
  96.                 'label'           => esc_html__( 'Text Background Color', 'et_builder' ),
  97.                 'type'            => 'color-alpha',
  98.                 'description'     => esc_html__( 'This will adjust the background color to the text.', 'et_builder' ),
  99.                 'depends_show_if' => 'on',
  100.                 'toggle_slug'     => 'main_content',
  101.             ),                 
  102.         );
  103.  
  104.         return $fields;
  105.     }
  106.  
  107.     function render( $attrs, $content = null, $render_slug ) {
  108.         $link              = $this->props['sit_link'];
  109.         $title             = $this->props['sit_title'];
  110.         $text_color        = $this->props['sit_text_color'];
  111.         $date              = $this->props['sit_date'];
  112.         $image             = $this->props['sit_image'];
  113.         $color             = $this->props['sit_color'];
  114.  
  115.         // Added for backward compatibility
  116.         if ( empty( $animation ) ) {
  117.             $animation = 'top';
  118.         }
  119.  
  120.         $output = sprintf(
  121.             '<div class="splitIT-bgimage" style="background: url(%4$s) center center no-repeat; background-size:cover; width: 100%%; height: 340px;">
  122.                 <div class="splitIT-text" style="position: absolute; bottom: 0; background-color: %5$s; width: 100%%; padding: 1em;">
  123.                     <h3 style="color: %6$s;"><a href="%1$s">%2$s</a></h3>
  124.                     <p style="color: %6$s;"><a href="%1$s">%3$s</a></p>
  125.                 </div>
  126.             </div>',
  127.             $link,
  128.             $title,
  129.             $date,
  130.             $image,
  131.             $color,
  132.             $text_color
  133.         );        
  134.  
  135.         return $output;
  136.     }
  137. }
  138.  
  139. new splitImageText;
Advertisement
Add Comment
Please, Sign In to add comment