/var/www/(Del)hsihk.com/wp-content/themes/flatsome/inc/builder/flatsome-builder.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
// Flatsome Builder Metaboxes
function ux_drag_drop_box() {
  
$screens = array('page','blocks','product','featured_item');
  foreach ( 
$screens as $screen ) {
    
// add styles and scripts
    
add_meta_box(
      
'ux_drag_and_drop',
      
__'Flatsome Page Builder <em>Beta</em>''flatsome' ),
      
'ux_drag_and_drop_box',
      
$screen'normal''high'
    
);

    
add_meta_box(
      
'ux_drag_and_drop_enable',
      
__'Flatsome Page Builder <em>Beta</em>''flatsome' ),
      
'ux_drag_and_drop_box_enable',
      
$screen'side''high'
    
);
  }  
}
add_action'add_meta_boxes''ux_drag_drop_box' );


// Enable / disable box
function ux_drag_and_drop_box_enable$post ) { ?>
<div id="uxbuilder-enable-disable" class="button-group">
        <a id="enable-uxbuilder" class="button" href="#">Enabled</a>
        <a id="disable-uxbuilder" class="button" href="#">Disabled</a>
</div>
<?php



// Build layout
function ux_drag_and_drop_box$post ) { 
    
// load scripts
    
wp_enqueue_script('ux_builder_app'get_template_directory_uri().'/inc/builder/app.js', array('wp-color-picker' ), falsetrue );
    
wp_enqueue_script('ux_builder_editable'get_template_directory_uri().'/inc/builder/editable.js');

    
wp_enqueue_style('ux_builder_style',get_template_directory_uri().'/inc/builder/builder_style.css');
    
wp_enqueue_style('wp-color-picker');

  
?>
  <style>#ux_drag_and_drop, #postdivrich{display: none!important;}</style>
  <div id="drag-and-drop">
   
  <div class="ux-add-elements-wrap" data-id="root">
          <div class="ux-g-add top"></div>
  </div>

    <!-- MAIN CONTENT -->
        <div class="drag-drop-content ux-g-group" data-group="root"></div><!-- .drag-drop-content -->
    <!-- END MAIN CONTENT -->

  <div class="ux-add-elements-wrap" data-id="root">
          <div class="ux-g-add bottom"></div>
  </div>
  </div><!-- #drag-and-drop -->

  <p class="ux-builder-footer small">This is an early BETA version of Flatsome Page Builder. Always keep a backup of your page or enable revisions. You can disable it in Theme Options > Global. Got any feedback? Email: <a href="mailto:support@uxthemes.com?subject=[BUILDER] < Please keep [builder] in subject...">support@uxthemes.com</a></p>

  <!-- Include shortcodes adder -->
  <?php include_once('shortcodes_insert.php'); ?>

  <!-- Shortcode Editor -->
  <div  data-edit="shortcode" class="ux-lightbox">
    <div class="ux-lightbox-inner">

      <div class="edit-shortcode-container"></div>
      <div class="ux-current-shortcode">
        <textarea id="new_shortcode"></textarea>
      </div>

      <div class="lightbox-tools bottom">
          <a href="#" class="close-lightbox button media-button button-secondary button-large">Cancel</a>
          <a href="#" class="save close-lightbox button media-button button-primary button-large">Save</a>
      </div>
    </div>
  </div>

  <!-- text editor -->
  <div data-edit="text" class="ux-lightbox">
      <div class="ux-lightbox-inner">

        <?php 
          $content 
'';
          
$editor_id 'ux_edit_content';
          
$settings = array('wpautop' => 'false');
          
wp_editor$content$editor_id$settings );
        
?>

        <div class="lightbox-tools bottom">
        <a href="#" class="close-lightbox button media-button button-secondary button-large">Cancel</a>
        <a href="#" class="save close-lightbox button media-button button-primary button-large">Save</a>
      </div>
    </div>
  </div>
  
  <!-- New content fixer temp-->
  <div id="new-content" style="display:none;"></div>
  
  
<?php


// tempoary text shortcode
function add_ux_text_shortcode(){}
add_shortcode('text''add_ux_text_shortcode');

// Get shortcode editor ajax
add_action('wp_ajax_get_shortcode_editor''get_shortcode_editor');
function 
get_shortcode_editor(){
    
$shortcode_id =  $_POST["shortcode"];
      include_once(
'shortcodes_editor.php');
    die;
}

// get content ajax
add_action('wp_ajax_ux_get_content_shortcodes''ux_get_content_shortcodes');

/** Get Shortcodes **/
function ux_get_content_shortcodes() {

      if(!isset(
$_POST["content"])) die;
      
      
$new_content =  stripslashes($_POST["content"]);

      
// wrap [text] around texts
      
$new_content preg_replace('/(\[text\])/',""$new_content);
      
$new_content preg_replace('/(\[\/text\])/',""$new_content);
      
$new_content preg_replace('/(\[[^\]]*\])/',"[/text]$1[text]"$new_content);
      
$new_content '[text]'.$new_content.'[/text]';
      
$new_content preg_replace('/(\[text\])(^\s+|\s+)(\[\/text\])/',""$new_content);
      
$new_content preg_replace('/(\[text\])(\[\/text\])/',""$new_content);

      
$new_content preg_replace('/\[background/',"[section"$new_content);
      
$new_content preg_replace('/\[\/background\]/',"[/section]"$new_content);

      
// remove spaces inside shortcodes
      
$new_content preg_replace('/\s+(?=[^[\]]*\])/'," "$new_content);

  
      
// shortcode tools
      
$tools '<div class="ux-g-tools"><a data-action="edit" href="#" title="Edit">Edit</a><a data-action="duplicate" href="#" title="Duplicate">Duplicate</a><a data-action="delete" href="#" title="Delete">Delete</a></div>';
      
      
// build content
      
global $shortcode_tags;
      
$tagnames array_keys($shortcode_tags);
      
      
// create elements
      
foreach($tagnames as $name){
        
preg_match('/\[(\[?)('.$name.')(?![\w-])([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*(?:\[(?!\/\2\])[^\[]*)*)(\[\/\2\]))?)(\]?)/'$new_content$matches);
        if(isset(
$matches[6]) && $matches[6] && $matches[6] != '[/text]'){
            
// shortcodes with ending
            
$new_content preg_replace('/\[(\[?)('.$name.')(?![\w-])([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*(?:\[(?!\/\2\])[^\[]*)*)(\[\/\2\]))?)(\]?)/''<div class="ux-g  ux-g-'.$name.'" data-id="'.$name.'"><s>[${2} <em class="ux-edit">${3}</em>]</s><div class="ux-g-group" data-group="'.$name.'">${5}</div> '.$tools.'<div class="ux-g-add"></div><s>${6}</s></div>'$new_content);
         } else if(
$name == 'embed' || $name == 'wp_caption' || $name == 'caption' || $name == 'gallery' || $name == 'playlist' || $name == 'audio' || $name == 'video'){
            
// shortcodes as text
            
$new_content preg_replace('/\[(\[?)('.$name.')(?![\w-])([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*(?:\[(?!\/\2\])[^\[]*)*)(\[\/\2\]))?)(\]?)/''<div class="ux-g ux-g-text" data-id="text"><div class="ux-g-text-inner">${0}</div>'.$tools.'</div>'$new_content);
        } else if(isset(
$matches[6]) && $matches[6] == '[/text]'){
            
// text shortcodes
            
$new_content preg_replace('/\[(\[?)('.$name.')(?![\w-])([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*(?:\[(?!\/\2\])[^\[]*)*)(\[\/\2\]))?)(\]?)/''<div class="ux-g ux-g-text" data-id="text"><div class="ux-g-text-inner">${5}</div>'.$tools.'</div>'$new_content);
        } else {
            
// shortcodes with no ending
            
$new_content preg_replace('/\[(\[?)('.$name.')(?![\w-])([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*(?:\[(?!\/\2\])[^\[]*)*)(\[\/\2\]))?)(\]?)/''<div class="ux-g ux-g-small ux-g-'.$name.'" data-id="'.$name.'"><s>[${2} <em class="ux-edit">${3}</em>]</s>'.$tools.'</div>'$new_content);
        }
      }
      

      echo 
$new_content;
      die;
// End ajax content