Guest User

Custom enfold element

a guest
Feb 28th, 2022
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.30 KB | None | 0 0
  1. <?php
  2.  
  3. // Don't load directly
  4. if (!defined('ABSPATH')) {
  5.     die('-1');
  6. }
  7.  
  8. if (!class_exists('res_aufklappbarer_text')) {
  9.     class res_aufklappbarer_text extends aviaShortcodeTemplate
  10.     {
  11.  
  12.         /**
  13.          * Create the config array for the shortcode button
  14.          */
  15.         function shortcode_insert_button()
  16.         {
  17.             $this->config['version'] = '1.0';
  18.             $this->config['self_closing'] = 'yes';
  19.  
  20.             $this->config['name'] = __('Aufklappbarer Text', 'avia_framework');
  21.             $this->config['tab'] = __('Custom', 'avia_framework');
  22.             $this->config['icon'] = AviaBuilder::$path['imagesURL'] . 'sc-text_block.png';
  23.             $this->config['order'] = 93;
  24.             $this->config['target'] = 'avia-target-insert';
  25.             $this->config['shortcode'] = 'res_aufklappbarer_text';
  26.             $this->config['modal_data'] = array('modal_class' => 'mediumscreen');
  27.             $this->config['tooltip'] = __('', 'avia_framework');
  28.             $this->config['preview'] = false;
  29.             $this->config['disabling_allowed'] = true;
  30.             $this->config['id_name'] = 'id';
  31.             $this->config['id_show'] = 'yes';
  32.         }
  33.  
  34.         function extra_assets()
  35.         {
  36.             wp_enqueue_script( 'res_aufklappbarer-text', get_stylesheet_directory_uri() . '/avia-shortcodes/aufklappbarer_text/aufklappbarer-text.js', array( 'jquery' ), false, true );
  37.         }
  38.  
  39.         /**
  40.          * Popup Elements
  41.          *
  42.          * If this function is defined in a child class the element automatically gets an edit button, that, when pressed
  43.          * opens a modal window that allows to edit the element properties
  44.          *
  45.          * @return void
  46.          */
  47.         function popup_elements()
  48.         {
  49.  
  50.             $this->elements = array(
  51.  
  52.                 array(
  53.                     'type' => 'tab_container',
  54.                     'nodescription' => true
  55.                 ),
  56.  
  57.                 array(
  58.                     'type' => 'tab',
  59.                     'name' => __('Content', 'avia_framework'),
  60.                     'nodescription' => true
  61.                 ),
  62.  
  63.                 array(
  64.                     'type' => 'template',
  65.                     'template_id' => $this->popup_key('content_faq')
  66.                 ),
  67.  
  68.                 array(
  69.                     'type' => 'tab_close',
  70.                     'nodescription' => true
  71.                 ),
  72.  
  73.                 array(
  74.                     'type' => 'tab',
  75.                     'name' => __('Advanced', 'avia_framework'),
  76.                     'nodescription' => true
  77.                 ),
  78.  
  79.                 array(
  80.                     'type' => 'toggle_container',
  81.                     'nodescription' => true
  82.                 ),
  83.  
  84.                 array(
  85.                     'type' => 'template',
  86.                     'template_id' => $this->popup_key('layout_spacing')
  87.                 ),
  88.  
  89.                 array(
  90.                     'type' => 'template',
  91.                     'template_id' => 'developer_options_toggle',
  92.                     'args' => array('sc' => $this)
  93.                 ),
  94.  
  95.                 array(
  96.                     'type' => 'toggle_container_close',
  97.                     'nodescription' => true
  98.                 ),
  99.  
  100.                 array(
  101.                     'type' => 'tab_close',
  102.                     'nodescription' => true
  103.                 ),
  104.  
  105.                 array(
  106.                     'type' => 'tab_container_close',
  107.                     'nodescription' => true
  108.                 )
  109.  
  110.             );
  111.  
  112.         }
  113.  
  114.         /**
  115.          * Create and register templates for easier maintainance
  116.          *
  117.          * @since 4.6.4
  118.          */
  119.         protected function register_dynamic_templates()
  120.         {
  121.  
  122.             /**
  123.              * Content Tab
  124.              * ===========
  125.              */
  126.  
  127.             $c = array(
  128.                 array(
  129.                     'name' => __('Immer sichtbarer Text', 'avia_framework'),
  130.                     'desc' => __('Enter some content for this textblock', 'avia_framework'),
  131.                     'id' => 'visible_text',
  132.                     'type' => 'tiny_mce',
  133.                     'std' => __('', 'avia_framework'),
  134.                     'tmpl_set_default' => false
  135.                 ),
  136.  
  137.                 array(
  138.                     'name' => __('Eingeklappter Text', 'avia_framework'),
  139.                     'desc' => __('Enter some content for this textblock', 'avia_framework'),
  140.                     'id' => 'hidden_text',
  141.                     'type' => 'tiny_mce',
  142.                     'std' => __('', 'avia_framework'),
  143.                     'tmpl_set_default' => false
  144.                 ),
  145.             );
  146.  
  147.             AviaPopupTemplates()->register_dynamic_template($this->popup_key('content_faq'), $c);
  148.  
  149.             $c = array(
  150.                 array(
  151.                     'name' => __('Custom top and bottom margin', 'avia_framework'),
  152.                     'desc' => __('If checked allows you to set a custom top and bottom margin. Otherwise the margin is calculated by the theme based on surrounding elements', 'avia_framework'),
  153.                     'id' => 'margin',
  154.                     'type' => 'checkbox',
  155.                     'std' => '',
  156.                     'lockable' => true,
  157.                 ),
  158.  
  159.                 array(
  160.                     'name' => __('Custom top and bottom margin', 'avia_framework'),
  161.                     'desc' => __('Set a custom top or bottom margin. Both pixel and &percnt; based values are accepted. eg: 30px, 5&percnt;', 'avia_framework'),
  162.                     'id' => 'custom_margin',
  163.                     'type' => 'multi_input',
  164.                     'sync' => true,
  165.                     'std' => '0px',
  166.                     'lockable' => true,
  167.                     'required' => array('margin', 'not', ''),
  168.                     'multi' => array(
  169.                         'top' => __('Margin-Top', 'avia_framework'),
  170.                         'bottom' => __('Margin-Bottom', 'avia_framework'),
  171.                     )
  172.                 )
  173.  
  174.             );
  175.  
  176.             $template = array(
  177.                 array(
  178.                     'type' => 'template',
  179.                     'template_id' => 'toggle',
  180.                     'title' => __('Spacing', 'avia_framework'),
  181.                     'content' => $c
  182.                 ),
  183.             );
  184.  
  185.             AviaPopupTemplates()->register_dynamic_template($this->popup_key('layout_spacing'), $template);
  186.  
  187.         }
  188.  
  189.  
  190.         /**
  191.          * Editor Element - this function defines the visual appearance of an element on the AviaBuilder Canvas
  192.          * Most common usage is to define some markup in the $params['innerHtml'] which is then inserted into the drag and drop container
  193.          * Less often used: $params['data'] to add data attributes, $params['class'] to modify the className
  194.          *
  195.          *
  196.          * @param array $params this array holds the default values for $content and $args.
  197.          * @return $params the return array usually holds an innerHtml key that holds item specific markup.
  198.          */
  199.         function editor_element($params)
  200.         {
  201.             $params = parent::editor_element($params);
  202.             $params['content'] = null; //remove to allow content elements
  203.             return $params;
  204.         }
  205.  
  206.         /**
  207.          * Frontend Shortcode Handler
  208.          *
  209.          * @param array $atts array of attributes
  210.          * @param string $content text within enclosing form of shortcode element
  211.          * @param string $shortcodename the shortcode found, when == callback name
  212.          * @return string $output returns the modified html string
  213.          */
  214.         function shortcode_handler($atts, $content = '', $shortcodename = '', $meta = '')
  215.         {
  216.  
  217.             extract($atts);
  218.  
  219.             /* custom margin */
  220.             if (!empty($atts['margin'])) {
  221.                 $explode_custom_margin = explode(',', $atts['custom_margin']);
  222.                 if (count($explode_custom_margin) > 1) {
  223.                     $atts['margin-top'] = $explode_custom_margin['0'];
  224.                     $atts['margin-bottom'] = $explode_custom_margin['1'];
  225.                 } else {
  226.                     $atts['margin-top'] = $atts['custom_margin'];
  227.                     $atts['margin-bottom'] = $atts['custom_margin'];
  228.                 }
  229.             }
  230.  
  231.             $custom_margin_style = '';
  232.             $custom_margin_style .= AviaHelper::style_string($atts, 'margin-top');
  233.             $custom_margin_style .= AviaHelper::style_string($atts, 'margin-bottom');
  234.  
  235.             $output = "";
  236.  
  237.             $output .= "<div class='res_aufklappbarer_text'>";
  238.             $output .= "<div class='res_aufklappbarer_text__vissible'>";
  239.             $output .= ShortcodeHelper::avia_apply_autop(ShortcodeHelper::avia_remove_autop($visible_text));
  240.             $output .= "</div>";
  241.             if ( $hidden_text ) {
  242.                 $output .= "<div class='res_aufklappbarer_text__hidden'>";
  243.                 $output .= ShortcodeHelper::avia_apply_autop(ShortcodeHelper::avia_remove_autop($hidden_text));
  244.                 $output .= "</div>";
  245.                 $output .= "<a class='res_aufklappbarer_text__btn avia-button avia-size-medium avia-color-dark' href='#'>Mehr lesen</a>";
  246.             }
  247.             $output .= "</div>";
  248.  
  249.             return $output;
  250.         }
  251.     }
  252. }
  253.  
Advertisement
Add Comment
Please, Sign In to add comment