WordPress Page Builder – Beaver Builder - Version 1.4.5

Version Description

Download this release

Release Info

Developer justinbusa
Plugin Icon 128x128 WordPress Page Builder – Beaver Builder
Version 1.4.5
Comparing to
See all releases

Code changes from version 1.4.3 to 1.4.5

Files changed (57) hide show
  1. changelog.txt +28 -1
  2. classes/{FLBuilderAdminPosts.php → class-fl-builder-admin-posts.php} +0 -0
  3. classes/{FLBuilderAdminSettings.php → class-fl-builder-admin-settings.php} +0 -0
  4. classes/{FLBuilderAdmin.php → class-fl-builder-admin.php} +47 -47
  5. classes/{FLBuilderAutoSuggest.php → class-fl-builder-auto-suggest.php} +0 -0
  6. classes/{FLBuilderColor.php → class-fl-builder-color.php} +0 -0
  7. classes/{FLBuilderIcons.php → class-fl-builder-icons.php} +0 -0
  8. classes/{FLBuilderLoop.php → class-fl-builder-loop.php} +0 -0
  9. classes/{FLBuilderModel.php → class-fl-builder-model.php} +571 -552
  10. classes/{FLBuilderModule.php → class-fl-builder-module.php} +7 -4
  11. classes/{FLBuilderPhoto.php → class-fl-builder-photo.php} +8 -8
  12. classes/{FLBuilderUpdate.php → class-fl-builder-update.php} +0 -0
  13. classes/{FLBuilderUtils.php → class-fl-builder-utils.php} +0 -0
  14. classes/{FLBuilder.php → class-fl-builder.php} +352 -330
  15. classes/{FLJSMin.php → class-fl-jsmin.php} +0 -0
  16. css/fl-builder-layout.css +3 -0
  17. css/fl-builder.css +17 -5
  18. css/fl-icon-selector.css +12 -1
  19. fl-builder.php +16 -16
  20. includes/admin-posts.php +2 -2
  21. includes/admin-settings.php +80 -80
  22. includes/column-settings.php +36 -36
  23. includes/field-form.php +3 -3
  24. includes/field-link.php +1 -1
  25. includes/field-multiple-photos.php +6 -11
  26. includes/field-suggest.php +2 -2
  27. includes/global-settings.php +10 -10
  28. includes/icon-selector.php +4 -3
  29. includes/js-config.php +5 -4
  30. includes/module-settings.php +17 -17
  31. includes/row-settings.php +41 -41
  32. includes/ui.php +5 -15
  33. includes/updater-config.php +1 -1
  34. includes/updater/classes/{FLUpdater.php → class-fl-updater.php} +55 -43
  35. includes/updater/includes/form.php +10 -10
  36. includes/updater/updater.php +1 -1
  37. includes/user-template-settings.php +3 -3
  38. js/fl-builder.js +11 -11
  39. js/fl-icon-selector.js +38 -12
  40. lang/fl-builder-it_IT.mo +0 -0
  41. lang/fl-builder-it_IT.po +0 -3506
  42. lang/fl-builder-pt_BR.mo +0 -0
  43. lang/fl-builder-pt_BR.po +0 -2958
  44. lang/fl-builder-sv_SE.mo +0 -0
  45. lang/fl-builder-sv_SE.po +0 -3086
  46. lang/fl-builder-xx_XX.mo +0 -0
  47. lang/fl-builder-xx_XX.pot +0 -3153
  48. languages/readme.md +14 -0
  49. languages/sk_SK.mo +0 -0
  50. languages/sk_SK.po +3558 -0
  51. languages/xx_XX.pot +3381 -0
  52. modules/photo/js/settings.js +7 -7
  53. modules/photo/photo.php +74 -74
  54. modules/video/video.php +15 -15
  55. modules/widget/includes/frontend.php +9 -8
  56. modules/widget/includes/settings-general.php +8 -8
  57. modules/widget/widget.php +37 -0
changelog.txt CHANGED
@@ -1,4 +1,31 @@
1
- <h4>1.4.3</h4>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  <p><strong>Enhancements</strong></p>
3
  <ul>
4
  <li>Added Foundation Icons and WordPress Dashicons to the icon selector.</li>
1
+ <h4>1.4.5 - 01/26/2015</h4>
2
+ <p><strong>Enhancements</strong></p>
3
+ <ul>
4
+ <li>Added a search field to the icon selector.</li>
5
+ </ul>
6
+ <p><strong>Bug Fixes</strong></p>
7
+ <ul>
8
+ <li>Fixed a bug introduced in 1.4.4 that caused PHP warnings when creating new pages.</li>
9
+ </ul>
10
+
11
+ <h4>1.4.4 - 01/26/2015</h4>
12
+ <p><strong>Enhancements</strong></p>
13
+ <ul>
14
+ <li>Major improvements to how translations are handled. A huge thanks to Oliver Juhas of <a href="http://www.webmandesign.eu/" target="_blank">WebMan Design</a> for making that happen. <strong>Please Note:</strong> Older translations are not compatible with this update need to be redone. Please get in touch with us if you're interested in helping with that.</li>
15
+ <li>Widgets in the builder now run the widget update method.</li>
16
+ <li>Content for the tabs module now scrolls into view on smaller devices.</li>
17
+ <li>Added filters for working with custom css classes on rows, columns and modules.</li>
18
+ <li>Updated class filenames to follow WordPress standards.</li>
19
+ </ul>
20
+ <p><strong>Bug Fixes</strong></p>
21
+ <ul>
22
+ <li>Fixed icon hover color.</li>
23
+ <li>Fixed a bug with slideshows showing up in the header on archive pages.</li>
24
+ <li>Fixed a bug causing the heading module color to not work when linked.</li>
25
+ <li>Fixed a bug with overriding modules in a theme when the name of the wp-content directory is changed.</li>
26
+ </ul>
27
+
28
+ <h4>1.4.3 - 01/11/2015</h4>
29
  <p><strong>Enhancements</strong></p>
30
  <ul>
31
  <li>Added Foundation Icons and WordPress Dashicons to the icon selector.</li>
classes/{FLBuilderAdminPosts.php → class-fl-builder-admin-posts.php} RENAMED
File without changes
classes/{FLBuilderAdminSettings.php → class-fl-builder-admin-settings.php} RENAMED
File without changes
classes/{FLBuilderAdmin.php → class-fl-builder-admin.php} RENAMED
@@ -9,24 +9,24 @@ final class FLBuilderAdmin {
9
 
10
  /**
11
  * @method activate
12
- */
13
- static public function activate()
14
  {
15
  global $wp_version;
16
-
17
  // Check for WordPress 3.5 and above.
18
  if(version_compare($wp_version, '3.5', '>=')) {
19
-
20
  // Check for multisite.
21
  if(is_multisite()) {
22
-
23
  // Init multisite support.
24
  self::init_classes();
25
  self::init_multisite();
26
-
27
  // This version has multisite support.
28
  if(class_exists('FLBuilderMultisite')) {
29
-
30
  if(is_network_admin()) {
31
  FLBuilderMultisite::install();
32
  }
@@ -36,7 +36,7 @@ final class FLBuilderAdmin {
36
  }
37
  // This version doesn't have multisite support.
38
  else {
39
- self::show_activate_error(sprintf(__('This version of the <strong>Page Builder</strong> plugin is not compatible with WordPress Multisite. <a href="%s" target="_blank">Please upgrade</a> to the Multisite version of this plugin.', 'fl-builder'), FL_BUILDER_UPGRADE_URL));
40
  }
41
  }
42
  // No multisite, standard install.
@@ -48,7 +48,7 @@ final class FLBuilderAdmin {
48
  else {
49
  self::show_activate_error(__('The <strong>Page Builder</strong> plugin requires WordPress version 3.5 or greater. Please update WordPress before activating the plugin.', 'fl-builder'));
50
  }
51
-
52
  // Success! Trigger the activation notice.
53
  if(FL_BUILDER_LITE !== true) {
54
  update_site_option('_fl_builder_activation_admin_notice', true);
@@ -57,21 +57,21 @@ final class FLBuilderAdmin {
57
 
58
  /**
59
  * @method show_activate_error
60
- */
61
- static public function show_activate_error($message)
62
  {
63
  deactivate_plugins(plugin_basename(FL_BUILDER_DIR . 'fl-builder.php'), false, is_network_admin());
64
-
65
  die($message);
66
  }
67
 
68
  /**
69
  * @method show_activate_notice
70
- */
71
- static public function show_activate_notice()
72
  {
73
  $notice = get_site_option('_fl_builder_activation_admin_notice');
74
-
75
  if($notice) {
76
  add_action('admin_notices', 'FLBuilderAdmin::activate_notice');
77
  add_action('network_admin_notices', 'FLBuilderAdmin::activate_notice');
@@ -81,30 +81,30 @@ final class FLBuilderAdmin {
81
 
82
  /**
83
  * @method activate_notice
84
- */
85
- static public function activate_notice()
86
  {
87
  $href = esc_url(admin_url('/options-general.php?page=fl-builder-settings#license'));
88
-
89
  echo '<div class="updated" style="background: #d3ebc1;">';
90
- echo '<p><strong>' . sprintf(__( 'Page Builder activated! <a href="%s">Click here</a> to enable remote updates.', 'fl-builder'), $href) . '</strong></p>';
91
  echo '</div>';
92
  }
93
 
94
  /**
95
  * @method install
96
- */
97
  static public function install() {}
98
 
99
  /**
100
  * @method uninstall
101
- */
102
- static public function uninstall()
103
  {
104
  FLBuilderModel::uninstall_database();
105
  }
106
-
107
- /**
108
  * @method init
109
  */
110
  static public function init()
@@ -116,20 +116,20 @@ final class FLBuilderAdmin {
116
  self::init_templates();
117
  }
118
 
119
- /**
120
  * @method init_classes
121
  */
122
  static public function init_classes()
123
  {
124
- $templates_class = FL_BUILDER_DIR . 'classes/FLBuilderTemplates.php';
125
- $ms_class = FL_BUILDER_DIR . 'classes/FLBuilderMultisite.php';
126
- $ms_settings_class = FL_BUILDER_DIR . 'classes/FLBuilderMultisiteSettings.php';
127
-
128
  if(file_exists($templates_class)) {
129
  require_once $templates_class;
130
  }
131
  if(is_multisite()) {
132
-
133
  if(file_exists($ms_class)) {
134
  require_once $ms_class;
135
  }
@@ -137,11 +137,11 @@ final class FLBuilderAdmin {
137
  require_once $ms_settings_class;
138
  }
139
  }
140
-
141
- require_once FL_BUILDER_DIR . 'classes/FLBuilderAdminSettings.php';
142
  }
143
 
144
- /**
145
  * @method init_settings
146
  */
147
  static public function init_settings()
@@ -149,13 +149,13 @@ final class FLBuilderAdmin {
149
  FLBuilderAdminSettings::init();
150
  }
151
 
152
- /**
153
  * @method init_multisite
154
  */
155
  static public function init_multisite()
156
  {
157
  if(is_multisite()) {
158
-
159
  if(class_exists('FLBuilderMultisite')) {
160
  FLBuilderMultisite::init();
161
  }
@@ -165,7 +165,7 @@ final class FLBuilderAdmin {
165
  }
166
  }
167
 
168
- /**
169
  * @method init_templates
170
  */
171
  static public function init_templates()
@@ -174,28 +174,28 @@ final class FLBuilderAdmin {
174
  FLBuilderTemplates::init();
175
  }
176
  }
177
-
178
  /**
179
  * @method render_plugin_action_links
180
- */
181
- static public function render_plugin_action_links($actions)
182
  {
183
  if(FL_BUILDER_LITE === true) {
184
- $actions[] = '<a href="' . FL_BUILDER_UPGRADE_URL . '" style="color:#3db634;" target="_blank">' . __('Upgrade', 'fl-builder') . '</a>';
185
  }
186
-
187
  return $actions;
188
  }
189
-
190
  /**
191
  * @method white_label_plugins_page
192
- */
193
- static public function white_label_plugins_page($plugins)
194
  {
195
  $branding = FLBuilderModel::get_branding();
196
-
197
  if($branding != __('Page Builder', 'fl-builder')) {
198
-
199
  if(isset($plugins['fl-builder/fl-builder.php'])) {
200
  $plugins['fl-builder/fl-builder.php']['Name'] = $branding;
201
  $plugins['fl-builder/fl-builder.php']['Title'] = $branding;
@@ -211,7 +211,7 @@ final class FLBuilderAdmin {
211
  $plugins['bb-plugin/fl-builder.php']['PluginURI'] = '';
212
  }
213
  }
214
-
215
  return $plugins;
216
  }
217
  }
9
 
10
  /**
11
  * @method activate
12
+ */
13
+ static public function activate()
14
  {
15
  global $wp_version;
16
+
17
  // Check for WordPress 3.5 and above.
18
  if(version_compare($wp_version, '3.5', '>=')) {
19
+
20
  // Check for multisite.
21
  if(is_multisite()) {
22
+
23
  // Init multisite support.
24
  self::init_classes();
25
  self::init_multisite();
26
+
27
  // This version has multisite support.
28
  if(class_exists('FLBuilderMultisite')) {
29
+
30
  if(is_network_admin()) {
31
  FLBuilderMultisite::install();
32
  }
36
  }
37
  // This version doesn't have multisite support.
38
  else {
39
+ self::show_activate_error( sprintf( __( 'This version of the <strong>Page Builder</strong> plugin is not compatible with WordPress Multisite. <a%s>Please upgrade</a> to the Multisite version of this plugin.', 'fl-builder' ), ' href="' . esc_url( FL_BUILDER_UPGRADE_URL ) . '" target="_blank"' ) );
40
  }
41
  }
42
  // No multisite, standard install.
48
  else {
49
  self::show_activate_error(__('The <strong>Page Builder</strong> plugin requires WordPress version 3.5 or greater. Please update WordPress before activating the plugin.', 'fl-builder'));
50
  }
51
+
52
  // Success! Trigger the activation notice.
53
  if(FL_BUILDER_LITE !== true) {
54
  update_site_option('_fl_builder_activation_admin_notice', true);
57
 
58
  /**
59
  * @method show_activate_error
60
+ */
61
+ static public function show_activate_error($message)
62
  {
63
  deactivate_plugins(plugin_basename(FL_BUILDER_DIR . 'fl-builder.php'), false, is_network_admin());
64
+
65
  die($message);
66
  }
67
 
68
  /**
69
  * @method show_activate_notice
70
+ */
71
+ static public function show_activate_notice()
72
  {
73
  $notice = get_site_option('_fl_builder_activation_admin_notice');
74
+
75
  if($notice) {
76
  add_action('admin_notices', 'FLBuilderAdmin::activate_notice');
77
  add_action('network_admin_notices', 'FLBuilderAdmin::activate_notice');
81
 
82
  /**
83
  * @method activate_notice
84
+ */
85
+ static public function activate_notice()
86
  {
87
  $href = esc_url(admin_url('/options-general.php?page=fl-builder-settings#license'));
88
+
89
  echo '<div class="updated" style="background: #d3ebc1;">';
90
+ echo '<p><strong>' . sprintf( __( 'Page Builder activated! <a%s>Click here</a> to enable remote updates.', 'fl-builder' ), ' href="' . esc_url( $href ) . '"' ) . '</strong></p>';
91
  echo '</div>';
92
  }
93
 
94
  /**
95
  * @method install
96
+ */
97
  static public function install() {}
98
 
99
  /**
100
  * @method uninstall
101
+ */
102
+ static public function uninstall()
103
  {
104
  FLBuilderModel::uninstall_database();
105
  }
106
+
107
+ /**
108
  * @method init
109
  */
110
  static public function init()
116
  self::init_templates();
117
  }
118
 
119
+ /**
120
  * @method init_classes
121
  */
122
  static public function init_classes()
123
  {
124
+ $templates_class = FL_BUILDER_DIR . 'classes/class-fl-builder-templates.php';
125
+ $ms_class = FL_BUILDER_DIR . 'classes/class-fl-builder-multisite.php';
126
+ $ms_settings_class = FL_BUILDER_DIR . 'classes/class-fl-builder-multisite-settings.php';
127
+
128
  if(file_exists($templates_class)) {
129
  require_once $templates_class;
130
  }
131
  if(is_multisite()) {
132
+
133
  if(file_exists($ms_class)) {
134
  require_once $ms_class;
135
  }
137
  require_once $ms_settings_class;
138
  }
139
  }
140
+
141
+ require_once FL_BUILDER_DIR . 'classes/class-fl-builder-admin-settings.php';
142
  }
143
 
144
+ /**
145
  * @method init_settings
146
  */
147
  static public function init_settings()
149
  FLBuilderAdminSettings::init();
150
  }
151
 
152
+ /**
153
  * @method init_multisite
154
  */
155
  static public function init_multisite()
156
  {
157
  if(is_multisite()) {
158
+
159
  if(class_exists('FLBuilderMultisite')) {
160
  FLBuilderMultisite::init();
161
  }
165
  }
166
  }
167
 
168
+ /**
169
  * @method init_templates
170
  */
171
  static public function init_templates()
174
  FLBuilderTemplates::init();
175
  }
176
  }
177
+
178
  /**
179
  * @method render_plugin_action_links
180
+ */
181
+ static public function render_plugin_action_links($actions)
182
  {
183
  if(FL_BUILDER_LITE === true) {
184
+ $actions[] = '<a href="' . FL_BUILDER_UPGRADE_URL . '" style="color:#3db634;" target="_blank">' . _x( 'Upgrade', 'Plugin action link label.', 'fl-builder' ) . '</a>';
185
  }
186
+
187
  return $actions;
188
  }
189
+
190
  /**
191
  * @method white_label_plugins_page
192
+ */
193
+ static public function white_label_plugins_page($plugins)
194
  {
195
  $branding = FLBuilderModel::get_branding();
196
+
197
  if($branding != __('Page Builder', 'fl-builder')) {
198
+
199
  if(isset($plugins['fl-builder/fl-builder.php'])) {
200
  $plugins['fl-builder/fl-builder.php']['Name'] = $branding;
201
  $plugins['fl-builder/fl-builder.php']['Title'] = $branding;
211
  $plugins['bb-plugin/fl-builder.php']['PluginURI'] = '';
212
  }
213
  }
214
+
215
  return $plugins;
216
  }
217
  }
classes/{FLBuilderAutoSuggest.php → class-fl-builder-auto-suggest.php} RENAMED
File without changes
classes/{FLBuilderColor.php → class-fl-builder-color.php} RENAMED
File without changes
classes/{FLBuilderIcons.php → class-fl-builder-icons.php} RENAMED
File without changes
classes/{FLBuilderLoop.php → class-fl-builder-loop.php} RENAMED
File without changes
classes/{FLBuilderModel.php → class-fl-builder-model.php} RENAMED
@@ -11,7 +11,7 @@ final class FLBuilderModel {
11
  /**
12
  * @property $row_layouts
13
  * @type array
14
- */
15
  static public $row_layouts = array(
16
  '1-col' => array(100),
17
  '2-cols' => array(50, 50),
@@ -24,19 +24,19 @@ final class FLBuilderModel {
24
  'left-right-sidebar' => array(25, 50, 25)
25
  );
26
 
27
- /**
28
  * @property $settings_forms
29
  * @type array
30
  */
31
  static public $settings_forms = array();
32
 
33
- /**
34
  * @property $modules
35
  * @type array
36
  */
37
  static public $modules = array();
38
-
39
- /**
40
  * The last node id that was generated by the builder.
41
  * This is saved to ensure the next node id is unique.
42
  *
@@ -45,8 +45,8 @@ final class FLBuilderModel {
45
  * @private
46
  */
47
  static private $last_generated_node_id = null;
48
-
49
- /**
50
  * Cached post data from either the $_POST array
51
  * or from the json decoded fl_builder_data post variable.
52
  *
@@ -55,8 +55,8 @@ final class FLBuilderModel {
55
  * @private
56
  */
57
  static private $post_data = null;
58
-
59
- /**
60
  * An array of cached published layout data by post_id.
61
  *
62
  * @property $published_layout_data
@@ -64,8 +64,8 @@ final class FLBuilderModel {
64
  * @private
65
  */
66
  static private $published_layout_data = array();
67
-
68
- /**
69
  * An array of cached draft layout data by post_id.
70
  *
71
  * @property $draft_layout_data
@@ -73,41 +73,41 @@ final class FLBuilderModel {
73
  * @private
74
  */
75
  static private $draft_layout_data = array();
76
-
77
  /**
78
- * All database updates should be made through
79
  * this method for security.
80
  *
81
  * @method update
82
- */
83
  static public function update($method = null, $params = array())
84
  {
85
  $post_data = self::get_post_data();
86
  $method = isset($post_data['method']) ? $post_data['method'] : $method;
87
  $post_id = self::get_post_id();
88
-
89
  // User can't edit this post.
90
  if($post_id && !current_user_can('edit_post', $post_id)) {
91
  return false;
92
  }
93
-
94
- // Method doesn't exist.
95
  else if(!$method) {
96
  return false;
97
  }
98
-
99
  // Method exists.
100
  else if(method_exists('FLBuilderModel', $method)) {
101
-
102
  // Call the method.
103
  $result = call_user_func_array('FLBuilderModel::' . $method, $params);
104
-
105
- // Render new assets.
106
  if(!isset($post_data['render_assets']) || $post_data['render_assets'] == 1) {
107
  FLBuilder::render_css();
108
  FLBuilder::render_js();
109
  }
110
-
111
  // Return the result.
112
  if(defined('DOING_AJAX')) {
113
  echo json_encode($result);
@@ -117,76 +117,76 @@ final class FLBuilderModel {
117
  return $result;
118
  }
119
  }
120
-
121
  return false;
122
  }
123
-
124
  /**
125
  * @method get_edit_url
126
  */
127
  static public function get_edit_url( $post_id = false )
128
  {
129
  global $post;
130
-
131
  if ( false === $post_id ) {
132
  $post_id = $post->ID;
133
  }
134
-
135
  $url = add_query_arg( 'fl_builder', '', get_permalink( $post_id ) );
136
 
137
  if ( class_exists( 'WPMinify' ) ) {
138
  $url = add_query_arg( 'wp-minify-off', '1', $url );
139
  }
140
-
141
  return set_url_scheme( $url );
142
  }
143
-
144
  /**
145
  * @method get_post_data
146
- */
147
  static public function get_post_data()
148
  {
149
  if(!self::$post_data) {
150
-
151
  self::$post_data = array();
152
-
153
  if(isset($_POST['fl_builder_data'])) {
154
-
155
  $data = self::json_decode_settings($_POST['fl_builder_data']);
156
-
157
  foreach($data as $key => $val) {
158
  self::$post_data[$key] = $val;
159
  }
160
  }
161
  else if(isset($_POST)) {
162
-
163
  foreach($_POST as $key => $val) {
164
  self::$post_data[$key] = $val;
165
  }
166
  }
167
  }
168
-
169
  return self::$post_data;
170
  }
171
-
172
  /**
173
  * @method update_post_data
174
- */
175
  static public function update_post_data($key, $value)
176
  {
177
  $post_data = self::get_post_data();
178
  $post_data[$key] = $value;
179
  self::$post_data = $post_data;
180
  }
181
-
182
  /**
183
  * @method get_post_types
184
- */
185
  static public function get_post_types()
186
  {
187
  $key = '_fl_builder_post_types';
188
  $default = array('page', 'fl-builder-template');
189
-
190
  // Get the value.
191
  if(is_network_admin()) {
192
  $value = get_site_option($key);
@@ -198,7 +198,7 @@ final class FLBuilderModel {
198
  else {
199
  $value = get_option($key);
200
  }
201
-
202
  // Return the value.
203
  if(!$value) {
204
  return $default;
@@ -208,24 +208,24 @@ final class FLBuilderModel {
208
  return $value;
209
  }
210
  }
211
-
212
  /**
213
  * @method get_global_posts
214
- */
215
  static public function get_global_posts()
216
  {
217
  return apply_filters('fl_builder_global_posts', array());
218
  }
219
-
220
  /**
221
  * @method get_post_id
222
- */
223
  static public function get_post_id()
224
  {
225
  global $post;
226
-
227
  $post_data = self::get_post_data();
228
-
229
  if(isset($post_data['post_id'])) {
230
  return $post_data['post_id'];
231
  }
@@ -236,41 +236,41 @@ final class FLBuilderModel {
236
  return false;
237
  }
238
  }
239
-
240
  /**
241
  * @method is_ssl
242
  */
243
  static public function is_ssl()
244
- {
245
  return is_ssl() || 0 === stripos( get_option( 'siteurl' ), 'https://' );
246
  }
247
-
248
  /**
249
- * Checks to see if the builder can be enabled for
250
  * the current post in the main query.
251
  *
252
  * @method is_post_editable
253
  */
254
  static public function is_post_editable()
255
- {
256
  global $wp_the_query;
257
-
258
  if ( is_singular() && isset( $wp_the_query->post ) ) {
259
-
260
  $post = $wp_the_query->post;
261
  $post_types = self::get_post_types();
262
  $user_can = current_user_can( 'edit_post', $post->ID );
263
-
264
  if ( in_array( $post->post_type, $post_types ) && $user_can ) {
265
  return true;
266
  }
267
  }
268
-
269
  return false;
270
  }
271
-
272
  /**
273
- * Called by the heartbeat API. Lock the current post
274
  * so only the current user can edit it.
275
  *
276
  * @method lock_post
@@ -278,19 +278,19 @@ final class FLBuilderModel {
278
  static public function lock_post($response, $data)
279
  {
280
  if(isset($data['fl_builder_post_lock'])) {
281
-
282
  require_once ABSPATH . 'wp-admin/includes/post.php';
283
-
284
  wp_set_post_lock($data['fl_builder_post_lock']['post_id']);
285
  }
286
  }
287
-
288
  /**
289
  * Checks to see if the builder layout is enabled
290
  * for the current post.
291
  *
292
  * @method is_builder_enabled
293
- */
294
  static public function is_builder_enabled()
295
  {
296
  if(!is_admin() && post_password_required()) {
@@ -300,30 +300,30 @@ final class FLBuilderModel {
300
  return true;
301
  }
302
  else {
303
-
304
  $post_types = self::get_post_types();
305
  $post = get_post(self::get_post_id());
306
-
307
  if($post && in_array($post->post_type, $post_types)) {
308
  return get_post_meta(self::get_post_id(), '_fl_builder_enabled', true);
309
  }
310
  }
311
-
312
  return false;
313
  }
314
-
315
  /**
316
- * Checks to see if the builder UI is active for
317
  * the current post in the main query.
318
  *
319
  * @method is_builder_active
320
- */
321
  static public function is_builder_active()
322
  {
323
  if ( self::is_post_editable() && ! is_admin() && ! post_password_required() ) {
324
-
325
  $post_data = self::get_post_data();
326
-
327
  if ( isset( $_GET['fl_builder'] ) ) {
328
  return true;
329
  }
@@ -331,116 +331,116 @@ final class FLBuilderModel {
331
  return true;
332
  }
333
  }
334
-
335
  return false;
336
  }
337
-
338
  /**
339
- * Gets the status to use for working with nodes in
340
- * the database. Returns draft if the builder is active,
341
- * otherwise it returns published.
342
  *
343
  * @method get_node_status
344
- */
345
  static public function get_node_status()
346
  {
347
  return self::is_builder_active() ? 'draft' : 'published';
348
  }
349
-
350
  /**
351
  * Enable the builder layout for the current post.
352
  *
353
  * @method enable
354
- */
355
  static public function enable()
356
  {
357
  update_post_meta(self::get_post_id(), '_fl_builder_enabled', true);
358
  }
359
-
360
  /**
361
  * Disable the builder layout for the current post.
362
  *
363
  * @method disable
364
- */
365
  static public function disable()
366
  {
367
  update_post_meta(self::get_post_id(), '_fl_builder_enabled', false);
368
  }
369
-
370
  /**
371
  * Enable the builder editor for the main post in the query.
372
  *
373
  * @method enable_editing
374
- */
375
  static public function enable_editing()
376
  {
377
  global $wp_the_query;
378
-
379
  if ( self::is_post_editable() ) {
380
-
381
- $post = $wp_the_query->post;
382
  $published = self::get_layout_data( 'published' );
383
  $draft = self::get_layout_data( 'draft' );
384
-
385
  // Migrate existing post content to the builder?
386
  if ( empty( $published ) && empty( $draft ) && ! empty( $post->post_content ) ) {
387
-
388
  $row = self::add_row();
389
  $cols = self::get_nodes( 'column' );
390
- $col = array_shift( $cols );
391
  $settings = self::get_module_defaults( 'rich-text' );
392
  $settings->text = wpautop( $post->post_content );
393
-
394
- self::add_module( 'rich-text', $settings, $col->node );
395
  }
396
  // Create a new draft?
397
  else if ( empty( $draft ) ) {
398
  self::update_layout_data( $published, 'draft', $post->ID );
399
  }
400
-
401
  // Delete old draft asset cache.
402
  self::delete_asset_cache();
403
-
404
  // Lock the post.
405
  require_once ABSPATH . 'wp-admin/includes/post.php';
406
  wp_set_post_lock( $post->ID );
407
  }
408
  }
409
-
410
  /**
411
  * @method get_cache_dir
412
- */
413
  static public function get_cache_dir()
414
  {
415
  $wp_info = wp_upload_dir();
416
-
417
  // SSL workaround.
418
  if(self::is_ssl()) {
419
  $wp_info['baseurl'] = str_ireplace('http://', 'https://', $wp_info['baseurl']);
420
  }
421
-
422
  // Build the paths.
423
  $dir_info = array(
424
  'path' => $wp_info['basedir'] . '/fl-builder/',
425
  'url' => $wp_info['baseurl'] . '/fl-builder/'
426
  );
427
-
428
  // Create the cache dir if it doesn't exist.
429
  if(!file_exists($dir_info['path'])) {
430
  mkdir($dir_info['path']);
431
  }
432
-
433
  return $dir_info;
434
  }
435
-
436
  /**
437
  * @method get_asset_version
438
- */
439
  static public function get_asset_version()
440
  {
441
  $post_id = self::get_post_id();
442
  $active = self::is_builder_active();
443
-
444
  if($active) {
445
  return md5(uniqid());
446
  }
@@ -448,43 +448,43 @@ final class FLBuilderModel {
448
  return md5(get_post_modified_time('U', false, $post_id));
449
  }
450
  }
451
-
452
  /**
453
  * @method get_asset_info
454
- */
455
  static public function get_asset_info()
456
  {
457
  $post_data = self::get_post_data();
458
  $post_id = self::get_post_id();
459
  $cache_dir = self::get_cache_dir();
460
-
461
  if(isset($post_data['node_preview'])) {
462
- $suffix = '-layout-preview';
463
  }
464
  else if(self::is_builder_active()) {
465
- $suffix = '-layout-draft';
466
  }
467
  else {
468
  $suffix = '-layout';
469
  }
470
-
471
  $info = array(
472
  'css' => $cache_dir['path'] . $post_id . $suffix . '.css',
473
  'css_url' => $cache_dir['url'] . $post_id . $suffix . '.css',
474
  'js' => $cache_dir['path'] . $post_id . $suffix . '.js',
475
  'js_url' => $cache_dir['url'] . $post_id . $suffix . '.js'
476
  );
477
-
478
  return $info;
479
  }
480
-
481
  /**
482
  * @method delete_asset_cache
483
- */
484
  static public function delete_asset_cache($type = 'all')
485
  {
486
  $info = self::get_asset_info();
487
-
488
  if(($type == 'css' || $type == 'all') && file_exists($info['css'])) {
489
  unlink($info['css']);
490
  }
@@ -492,27 +492,27 @@ final class FLBuilderModel {
492
  unlink($info['js']);
493
  }
494
  }
495
-
496
  /**
497
  * @method delete_all_asset_cache
498
- */
499
  static public function delete_all_asset_cache($post_id = null)
500
  {
501
  $post_id = $post_id == null ? self::get_post_id() : $post_id;
502
  $cache_dir = self::get_cache_dir();
503
-
504
  if($post_id == null) {
505
  array_map('unlink', glob($cache_dir['path'] . '*.css'));
506
  array_map('unlink', glob($cache_dir['path'] . '*.js'));
507
  }
508
- else {
509
  $css = $cache_dir['path'] . $post_id . '-layout.css';
510
  $css_draft = $cache_dir['path'] . $post_id . '-layout-draft.css';
511
  $css_preview = $cache_dir['path'] . $post_id . '-layout-preview.css';
512
  $js = $cache_dir['path'] . $post_id . '-layout.js';
513
  $js_draft = $cache_dir['path'] . $post_id . '-layout-draft.js';
514
  $js_preview = $cache_dir['path'] . $post_id . '-layout-preview.js';
515
-
516
  if(file_exists($css)) {
517
  unlink($css);
518
  }
@@ -533,90 +533,90 @@ final class FLBuilderModel {
533
  }
534
  }
535
  }
536
-
537
  /**
538
  * @method generate_node_id
539
- */
540
  static public function generate_node_id()
541
  {
542
  $node_id = uniqid();
543
-
544
  if($node_id == self::$last_generated_node_id) {
545
  return self::generate_node_id();
546
  }
547
-
548
  self::$last_generated_node_id = $node_id;
549
-
550
  return $node_id;
551
  }
552
-
553
  /**
554
  * @method generate_new_node_ids
555
- */
556
  static public function generate_new_node_ids($data)
557
  {
558
  $map = array();
559
  $nodes = array();
560
-
561
  // Map the new node ids to the old.
562
  foreach($data as $node_id => $node) {
563
  $map[$node_id] = self::generate_node_id();
564
  }
565
-
566
  // Replace the old node ids.
567
  foreach($data as $node_id => $node) {
568
-
569
  $nodes[$map[$node_id]] = $node;
570
  $nodes[$map[$node_id]]->node = $map[$node_id];
571
-
572
  if(!empty($node->parent) && isset($map[$node->parent])) {
573
  $nodes[$map[$node_id]]->parent = $map[$node->parent];
574
  }
575
  }
576
-
577
  return $nodes;
578
  }
579
-
580
  /**
581
  * @method get_node
582
- */
583
  static public function get_node($node_id = null, $status = null)
584
  {
585
  $data = self::get_layout_data($status);
586
  $node = $data[$node_id];
587
-
588
  if(isset($node) && !empty($node->settings)) {
589
  $node->settings = self::get_node_settings($node);
590
  }
591
-
592
  return $node;
593
  }
594
-
595
  /**
596
  * @method get_child_nodes
597
- */
598
  static public function get_child_nodes($parent_id, $status = null)
599
  {
600
  $data = self::get_layout_data($status);
601
  $nodes = array();
602
-
603
  foreach($data as $node_id => $node) {
604
-
605
  if($node->parent == $parent_id) {
606
  $nodes[$node_id] = $node;
607
  }
608
  }
609
-
610
  return $nodes;
611
  }
612
-
613
  /**
614
  * @method get_nodes
615
- */
616
  static public function get_nodes($type = null, $parent_id = null, $status = null)
617
  {
618
  $nodes = array();
619
-
620
  // Get the layout data.
621
  if($parent_id == null) {
622
  $data = self::get_layout_data($status);
@@ -624,45 +624,45 @@ final class FLBuilderModel {
624
  else {
625
  $data = self::get_child_nodes($parent_id, $status);
626
  }
627
-
628
  // Return all nodes?
629
  if($type == null) {
630
  $nodes = $data;
631
  }
632
  // Return nodes of a certain type.
633
  else {
634
-
635
  foreach($data as $node_id => $node) {
636
-
637
  if($node->type == $type) {
638
  $nodes[$node_id] = $node;
639
  }
640
  }
641
-
642
  uasort($nodes, array('FLBuilderModel', 'order_nodes'));
643
  }
644
-
645
  // Merge default settings.
646
  foreach($nodes as $node_id => $node) {
647
-
648
  if(!empty($node->settings)) {
649
  $nodes[$node_id]->settings = self::get_node_settings($nodes[$node_id]);
650
  }
651
  }
652
-
653
  // Return the nodes.
654
  return $nodes;
655
  }
656
-
657
  /**
658
  * @method get_node_settings
659
- */
660
  static public function get_node_settings($node)
661
  {
662
  $post_data = self::get_post_data();
663
-
664
  if(isset($post_data['node_preview']) && isset($post_data['node_id']) && $post_data['node_id'] == $node->node) {
665
-
666
  if(!isset($post_data['node_preview_processed_settings'])) {
667
  $settings = $post_data['node_preview'];
668
  $settings = (object)array_merge((array)$node->settings, (array)$settings);
@@ -677,13 +677,13 @@ final class FLBuilderModel {
677
  $defaults = self::get_node_defaults($node);
678
  $settings = (object)array_merge((array)$defaults, (array)$node->settings);
679
  }
680
-
681
  return $settings;
682
  }
683
-
684
  /**
685
  * @method process_node_settings
686
- */
687
  static public function process_node_settings($node, $new_settings)
688
  {
689
  if($node->type == 'row') {
@@ -695,17 +695,17 @@ final class FLBuilderModel {
695
  if($node->type == 'module') {
696
  $new_settings = self::process_module_settings($node, $new_settings);
697
  }
698
-
699
  return $new_settings;
700
  }
701
-
702
  /**
703
  * @method get_node_defaults
704
- */
705
  static public function get_node_defaults($node)
706
  {
707
  $defaults = array();
708
-
709
  if($node->type == 'row') {
710
  $defaults = self::get_row_defaults();
711
  }
@@ -715,13 +715,13 @@ final class FLBuilderModel {
715
  else if($node->type == 'module') {
716
  $defaults = self::get_module_defaults($node->settings->type);
717
  }
718
-
719
  return $defaults;
720
  }
721
-
722
  /**
723
  * @method order_nodes
724
- */
725
  static public function order_nodes($a, $b)
726
  {
727
  return (int)$a->position - (int)$b->position;
@@ -729,7 +729,7 @@ final class FLBuilderModel {
729
 
730
  /**
731
  * @method count_nodes
732
- */
733
  static public function count_nodes($type = 'row', $parent_id = null)
734
  {
735
  return count(self::get_nodes($type, $parent_id));
@@ -737,70 +737,70 @@ final class FLBuilderModel {
737
 
738
  /**
739
  * @method next_node_position
740
- */
741
  static public function next_node_position($type = 'row', $parent_id = null)
742
  {
743
  $nodes = self::get_nodes($type, $parent_id);
744
  $last = array_pop($nodes);
745
-
746
  return $last ? $last->position + 1 : 0;
747
  }
748
-
749
  /**
750
  * @method delete_node
751
- */
752
  static public function delete_node($node_id = null)
753
  {
754
  // Get the post data.
755
  $post_data = self::get_post_data();
756
-
757
  // Get the layout data.
758
  $data = self::get_layout_data();
759
-
760
  // Get the node id.
761
  if(!$node_id && isset($post_data['node_id'])) {
762
  $node_id = $post_data['node_id'];
763
  }
764
-
765
  // Return if the node doesn't exist.
766
  if(!isset($data[$node_id])) {
767
  return;
768
  }
769
-
770
  // Get the node.
771
- $node = $data[$node_id];
772
-
773
  // Call the delete method if we're deleting a module.
774
  self::call_module_delete($node);
775
-
776
  // Delete the node.
777
  unset($data[$node_id]);
778
-
779
  // Update the layout data.
780
  self::update_layout_data($data);
781
-
782
  // Reorder existing nodes.
783
  self::reorder_nodes($node->type, $node->parent);
784
-
785
  // Delete the node's children.
786
  self::delete_child_nodes($node_id);
787
  }
788
-
789
  /**
790
  * @method delete_child_nodes
791
- */
792
  static public function delete_child_nodes($parent_id = null)
793
  {
794
  $children = self::get_nodes(null, $parent_id);
795
-
796
  foreach($children as $child) {
797
  self::delete_node($child->node);
798
  }
799
  }
800
-
801
  /**
802
  * @method call_module_delete
803
- */
804
  static public function call_module_delete($node)
805
  {
806
  if($node->type == 'module' && isset(self::$modules[$node->settings->type])) {
@@ -810,10 +810,10 @@ final class FLBuilderModel {
810
  $instance->delete();
811
  }
812
  }
813
-
814
  /**
815
  * @method reorder_node
816
- */
817
  static public function reorder_node($node_id = null, $position = 0)
818
  {
819
  $post_data = self::get_post_data();
@@ -823,18 +823,18 @@ final class FLBuilderModel {
823
  $nodes = self::get_nodes($node->type, $node->parent);
824
  $position = isset($post_data['position']) ? (int)$post_data['position'] : $position;
825
  $new_pos = 0;
826
-
827
  // Make sure node positions start at zero.
828
  foreach($nodes as $node) {
829
  $data[$node->node]->position = $new_pos;
830
  $new_pos++;
831
  }
832
-
833
  // Get the node and remove it from the array.
834
  $node = $data[$node_id];
835
  $removed = array_splice($nodes, $node->position, 1);
836
  $new_pos = 0;
837
-
838
  // Reposition it in the array.
839
  array_splice($nodes, $position, 0, $removed);
840
 
@@ -843,54 +843,54 @@ final class FLBuilderModel {
843
  $data[$node->node]->position = $new_pos;
844
  $new_pos++;
845
  }
846
-
847
  // Update the layout data.
848
  self::update_layout_data($data);
849
  }
850
-
851
  /**
852
  * @method reorder_nodes
853
- */
854
  static public function reorder_nodes($type = 'row', $parent_id = null)
855
  {
856
  $data = self::get_layout_data();
857
  $nodes = self::get_nodes($type, $parent_id);
858
  $pos = 0;
859
-
860
  foreach($nodes as $node_id => $node) {
861
  $data[$node_id]->position = $pos;
862
  $pos++;
863
  }
864
-
865
  self::update_layout_data($data);
866
  }
867
-
868
  /**
869
  * @method move_node
870
- */
871
  static public function move_node($node_id = null, $new_parent_id = null, $position = 0)
872
- {
873
  $post_data = self::get_post_data();
874
  $data = self::get_layout_data();
875
  $node_id = isset($post_data['node_id']) ? $post_data['node_id'] : $node_id;
876
- $new_parent_id = isset($post_data['new_parent']) ? $post_data['new_parent'] : $new_parent_id;
877
  $position = isset($post_data['position']) ? $post_data['position'] : $position;
878
  $new_parent = self::get_node($new_parent_id);
879
  $node = self::get_node($node_id);
880
-
881
  // Set the node's new parent.
882
  $data[$node_id]->parent = $new_parent->node;
883
-
884
  // Update the layout data.
885
  self::update_layout_data($data);
886
-
887
  // Set the node's new order.
888
  self::reorder_node($node_id, $position);
889
  }
890
-
891
  /**
892
  * @method add_row
893
- */
894
  static public function add_row($cols = '1-col', $position = false)
895
  {
896
  $post_data = self::get_post_data();
@@ -899,7 +899,7 @@ final class FLBuilderModel {
899
  $position = isset($post_data['position']) ? (int)$post_data['position'] : $position;
900
  $settings = self::get_row_defaults();
901
  $row_node_id = self::generate_node_id();
902
-
903
  // Add the row.
904
  $data[$row_node_id] = new StdClass();
905
  $data[$row_node_id]->node = $row_node_id;
@@ -907,25 +907,25 @@ final class FLBuilderModel {
907
  $data[$row_node_id]->parent = null;
908
  $data[$row_node_id]->position = self::next_node_position('row');
909
  $data[$row_node_id]->settings = $settings;
910
-
911
  // Update the layout data.
912
  self::update_layout_data($data);
913
-
914
  // Position the row.
915
  if($position !== false) {
916
  self::reorder_node($row_node_id, $position);
917
  }
918
-
919
  // Add a column group.
920
  self::add_col_group($row_node_id, $cols, 0);
921
-
922
  // Return the updated row.
923
  return self::get_node($row_node_id);
924
  }
925
-
926
  /**
927
  * @method copy_row
928
- */
929
  static public function copy_row($node_id = null)
930
  {
931
  $post_data = self::get_post_data();
@@ -935,77 +935,77 @@ final class FLBuilderModel {
935
  $new_row_id = self::generate_node_id();
936
  $col_groups = self::get_child_nodes($node_id);
937
  $new_nodes = array();
938
-
939
  // Add the new row.
940
  $layout_data[$new_row_id] = clone $row;
941
  $layout_data[$new_row_id]->settings = clone $row->settings;
942
- $layout_data[$new_row_id]->node = $new_row_id;
943
-
944
  // Get the new child nodes.
945
  foreach($col_groups as $col_group_id => $col_group) {
946
-
947
  $new_nodes[$col_group_id] = clone $col_group;
948
  $cols = self::get_child_nodes($col_group_id);
949
-
950
  foreach($cols as $col_id => $col) {
951
-
952
  $new_nodes[$col_id] = clone $col;
953
  $new_nodes[$col_id]->settings = clone $col->settings;
954
  $modules = self::get_child_nodes($col_id);
955
-
956
  foreach($modules as $module_id => $module) {
957
  $new_nodes[$module_id] = clone $module;
958
  $new_nodes[$module_id]->settings = clone $module->settings;
959
  }
960
  }
961
  }
962
-
963
  // Generate new child ids.
964
  $new_nodes = self::generate_new_node_ids($new_nodes);
965
-
966
  // Set col group parent ids to the new row id.
967
  foreach($new_nodes as $child_node_id => $child) {
968
  if($child->type == 'column-group') {
969
  $new_nodes[$child_node_id]->parent = $new_row_id;
970
  }
971
  }
972
-
973
  // Merge the child data.
974
  $layout_data = array_merge($layout_data, $new_nodes);
975
-
976
  // Update the layout data.
977
  self::update_layout_data($layout_data);
978
-
979
  // Position the new row.
980
  self::reorder_node($new_row_id, $row->position + 1);
981
  }
982
-
983
- /**
984
  * @method get_row_defaults
985
  */
986
  static public function get_row_defaults()
987
  {
988
  return self::get_settings_form_defaults(self::$settings_forms['row']['tabs']);
989
  }
990
-
991
  /**
992
  * @method process_row_settings
993
  */
994
- static public function process_row_settings($row, $new_settings)
995
  {
996
  // Cache background video data.
997
  if($new_settings->bg_type == 'video') {
998
-
999
  // Video
1000
  $video = FLBuilderPhoto::get_attachment_data($new_settings->bg_video);
1001
-
1002
  if($video) {
1003
-
1004
  $parts = explode('.', $video->filename);
1005
  $video->extension = array_pop($parts);
1006
  $new_settings->bg_video_data = $video;
1007
-
1008
- // Fallback
1009
  if(!empty($new_settings->bg_video_fallback_src)) {
1010
  $new_settings->bg_video_data->fallback = $new_settings->bg_video_fallback_src;
1011
  }
@@ -1014,15 +1014,15 @@ final class FLBuilderModel {
1014
  }
1015
  }
1016
  }
1017
-
1018
  // Cache background slideshow data.
1019
  if($new_settings->bg_type == 'slideshow' && $new_settings->ss_source == 'wordpress') {
1020
-
1021
  // Make sure we have a photo data object.
1022
  if(!isset($row->settings->ss_photo_data)) {
1023
  $row->settings->ss_photo_data = new StdClass();
1024
  }
1025
-
1026
  // Hijack the slideshow module to get WordPress photo data.
1027
  $ss = new FLSlideshowModule();
1028
  $ss->settings = new StdClass();
@@ -1030,40 +1030,40 @@ final class FLBuilderModel {
1030
  $ss->settings->photo_data = $row->settings->ss_photo_data;
1031
  $new_settings->ss_photo_data = $ss->get_wordpress_photos();
1032
  }
1033
-
1034
  return $new_settings;
1035
  }
1036
-
1037
  /**
1038
  * @method get_row_bg_data
1039
  */
1040
- static public function get_row_bg_data($row)
1041
  {
1042
  $data = null;
1043
-
1044
  // Background Video
1045
  if($row->settings->bg_type == 'video' && isset($row->settings->bg_video_data)) {
1046
  $data = $row->settings->bg_video_data;
1047
  }
1048
-
1049
  // Background Slideshow
1050
  else if($row->settings->bg_type == 'slideshow' && isset($row->settings->ss_photo_data)) {
1051
  $data = $row->settings->ss_photo_data;
1052
  }
1053
-
1054
  return $data;
1055
  }
1056
-
1057
  /**
1058
  * @method get_row_slideshow_source
1059
  */
1060
- static public function get_row_slideshow_source($row)
1061
  {
1062
  // Make sure we have a photo data object.
1063
  if(!isset($row->settings->ss_photo_data)) {
1064
  $row->settings->ss_photo_data = new StdClass();
1065
  }
1066
-
1067
  // Hijack the slideshow module to get the source.
1068
  $ss = new FLSlideshowModule();
1069
  $ss->settings = new StdClass();
@@ -1071,11 +1071,11 @@ final class FLBuilderModel {
1071
  $ss->settings->photos = $row->settings->ss_photos;
1072
  $ss->settings->feed_url = $row->settings->ss_feed_url;
1073
  $ss->settings->photo_data = $row->settings->ss_photo_data;
1074
-
1075
  // Return the slideshow source.
1076
  return $ss->get_source();
1077
  }
1078
-
1079
  /**
1080
  * @method add_col_group
1081
  */
@@ -1087,7 +1087,7 @@ final class FLBuilderModel {
1087
  $cols = isset($post_data['cols']) ? $post_data['cols'] : $cols;
1088
  $position = isset($post_data['position']) ? (int)$post_data['position'] : $position;
1089
  $group_node_id = self::generate_node_id();
1090
-
1091
  // Add the column group.
1092
  $data[$group_node_id] = new StdClass();
1093
  $data[$group_node_id]->node = $group_node_id;
@@ -1095,10 +1095,10 @@ final class FLBuilderModel {
1095
  $data[$group_node_id]->parent = $node_id;
1096
  $data[$group_node_id]->position = self::next_node_position('column-group', $node_id);
1097
  $data[$group_node_id]->settings = '';
1098
-
1099
  // Add the columns.
1100
  for($i = 0; $i < count(self::$row_layouts[$cols]); $i++) {
1101
-
1102
  $col_node_id = self::generate_node_id();
1103
  $data[$col_node_id] = new StdClass();
1104
  $data[$col_node_id]->node = $col_node_id;
@@ -1108,29 +1108,29 @@ final class FLBuilderModel {
1108
  $data[$col_node_id]->settings = new StdClass();
1109
  $data[$col_node_id]->settings->size = self::$row_layouts[$cols][$i];
1110
  }
1111
-
1112
  // Update the layout data.
1113
  self::update_layout_data($data);
1114
-
1115
  // Position the column group.
1116
  if($position !== false) {
1117
  self::reorder_node($group_node_id, $position);
1118
  }
1119
-
1120
  // Return the column group.
1121
  return self::get_node($group_node_id);
1122
  }
1123
-
1124
  /**
1125
  * @method process_col_settings
1126
  */
1127
  static public function process_col_settings($col, $new_settings)
1128
  {
1129
  $new_settings->size = self::resize_col($col->node, $new_settings->size);
1130
-
1131
  return $new_settings;
1132
  }
1133
-
1134
  /**
1135
  * @method delete_col
1136
  */
@@ -1140,39 +1140,39 @@ final class FLBuilderModel {
1140
  $node_id = isset($post_data['node_id']) ? $post_data['node_id'] : $node_id;
1141
  $new_width = isset($post_data['new_width']) ? $post_data['new_width'] : $new_width;
1142
  $col = self::get_node($node_id);
1143
-
1144
  // Delete the column.
1145
  self::delete_node($node_id);
1146
-
1147
  // Get the group
1148
  $group = self::get_node($col->parent);
1149
-
1150
  // Get the group children.
1151
  $cols = self::get_nodes('column', $group->node);
1152
-
1153
  // Delete the group if empty.
1154
  if(count($cols) === 0) {
1155
  self::delete_node($group->node);
1156
  }
1157
-
1158
  // Resize the remaining columns.
1159
  else {
1160
-
1161
  // Get the layout data.
1162
  $data = self::get_layout_data();
1163
-
1164
  // Loop through the columns.
1165
  foreach($cols as $col_id => $col) {
1166
-
1167
  // Set the new size.
1168
  $data[$col_id]->settings->size = round($new_width, 2);
1169
- }
1170
-
1171
  // Update the layout data.
1172
  self::update_layout_data($data);
1173
  }
1174
  }
1175
-
1176
  /**
1177
  * @method resize_col
1178
  */
@@ -1188,12 +1188,12 @@ final class FLBuilderModel {
1188
  $num_cols = count($cols);
1189
  $min_width = 10;
1190
  $max_width = 100 - $min_width;
1191
-
1192
  // Don't resize if only one column or width isn't a number.
1193
  if($num_cols == 1 || !is_numeric($new_width)) {
1194
  return $col->settings->size;
1195
  }
1196
-
1197
  // Find the sibling column to absorb this resize.
1198
  if($pos === 0) {
1199
  $sibling = $cols[1];
@@ -1204,123 +1204,123 @@ final class FLBuilderModel {
1204
  else {
1205
  $sibling = $cols[$pos + 1];
1206
  }
1207
-
1208
  // Find other siblings.
1209
  foreach($cols as $c) {
1210
-
1211
  if($col->node == $c->node) {
1212
  continue;
1213
  }
1214
  if($sibling->node == $c->node) {
1215
  continue;
1216
  }
1217
-
1218
  $siblings[] = $c;
1219
  $max_width -= $c->settings->size;
1220
  $siblings_width += $c->settings->size;
1221
  }
1222
-
1223
  // Make sure the new width isn't too small.
1224
  if($new_width < $min_width) {
1225
  $new_width = $min_width;
1226
  }
1227
-
1228
  // Make sure the new width isn't too big.
1229
  if($new_width > $max_width) {
1230
  $new_width = $max_width;
1231
  }
1232
-
1233
  // Save new sibling size.
1234
  $data[$sibling->node]->settings->size = round(100 - $siblings_width - $new_width, 2);
1235
-
1236
  // Save new column size.
1237
  $data[$col->node]->settings->size = $new_width;
1238
-
1239
  // Update the layout data.
1240
  self::update_layout_data($data);
1241
-
1242
  // Return the new size.
1243
  return $new_width;
1244
  }
1245
-
1246
- /**
1247
  * @method get_col_defaults
1248
  */
1249
  static public function get_col_defaults()
1250
  {
1251
  return self::get_settings_form_defaults(self::$settings_forms['col']['tabs']);
1252
  }
1253
-
1254
  /**
1255
  * @method load_modules
1256
- */
1257
  static public function load_modules()
1258
  {
1259
  $path = FL_BUILDER_DIR . 'modules/';
1260
  $dir = dir($path);
1261
  $module_path = '';
1262
-
1263
  while(false !== ($entry = $dir->read())) {
1264
-
1265
  if(!is_dir($path . $entry) || $entry == '.' || $entry == '..') {
1266
  continue;
1267
  }
1268
-
1269
  // Paths to check.
1270
  $module_path = $entry . '/' . $entry . '.php';
1271
  $child_path = get_stylesheet_directory() . '/fl-builder/modules/' . $module_path;
1272
  $theme_path = get_template_directory() . '/fl-builder/modules/' . $module_path;
1273
  $builder_path = FL_BUILDER_DIR . 'modules/' . $module_path;
1274
-
1275
  // Check for the module class in a child theme.
1276
  if(is_child_theme() && file_exists($child_path)) {
1277
  require_once $child_path;
1278
  }
1279
-
1280
  // Check for the module class in a parent theme.
1281
  else if(file_exists($theme_path)) {
1282
  require_once $theme_path;
1283
  }
1284
-
1285
  // Check for the module class in the builder directory.
1286
  else if(file_exists($builder_path)) {
1287
  require_once $builder_path;
1288
  }
1289
  }
1290
  }
1291
-
1292
  /**
1293
  * @method register_module
1294
- */
1295
  static public function register_module($class, $form)
1296
  {
1297
  if(class_exists($class)) {
1298
-
1299
  // Create a new instance of the module.
1300
  $instance = new $class();
1301
-
1302
  // Only register modules that are enabled.
1303
  if($instance->enabled) {
1304
 
1305
  // Save the instance in the modules array.
1306
  self::$modules[$instance->slug] = $instance;
1307
-
1308
  // Add the form to the instance.
1309
  self::$modules[$instance->slug]->form = $form;
1310
- self::$modules[$instance->slug]->form['advanced'] = self::$settings_forms['module-advanced'];
1311
  }
1312
  }
1313
  }
1314
-
1315
  /**
1316
  * @method get_enabled_modules
1317
- */
1318
  static public function get_enabled_modules()
1319
  {
1320
  $key = '_fl_builder_enabled_modules';
1321
  $default = array_keys(self::$modules);
1322
  $default[] = 'all';
1323
-
1324
  // Get the value.
1325
  if(is_network_admin()) {
1326
  $value = get_site_option($key);
@@ -1332,7 +1332,7 @@ final class FLBuilderModel {
1332
  else {
1333
  $value = get_option($key);
1334
  }
1335
-
1336
  // Return the value.
1337
  if(!$value || in_array('all', $value)) {
1338
  return $default;
@@ -1341,23 +1341,23 @@ final class FLBuilderModel {
1341
  return $value;
1342
  }
1343
  }
1344
-
1345
  /**
1346
  * @method get_categorized_modules
1347
- */
1348
  static public function get_categorized_modules()
1349
  {
1350
  $enabled_modules = self::get_enabled_modules();
1351
-
1352
  $categories = array(
1353
  'Basic Modules' => array(),
1354
  'Advanced Modules' => array(),
1355
  'Other' => array()
1356
  );
1357
-
1358
  // Build the categories array.
1359
  foreach(self::$modules as $module) {
1360
-
1361
  if(!in_array($module->slug, $enabled_modules)) {
1362
  continue;
1363
  }
@@ -1365,18 +1365,18 @@ final class FLBuilderModel {
1365
  $categories[$module->category] = self::get_wp_widgets();
1366
  }
1367
  else if(isset($module->category)) {
1368
-
1369
  if(!isset($categories[$module->category])) {
1370
  $categories[$module->category] = array();
1371
  }
1372
-
1373
  $categories[$module->category][$module->name] = $module;
1374
  }
1375
  else {
1376
  $categories['Other'][$module->name] = $module;
1377
  }
1378
  }
1379
-
1380
  // Sort the modules.
1381
  foreach($categories as $title => $modules) {
1382
  if(count($categories[$title]) == 0) {
@@ -1386,7 +1386,7 @@ final class FLBuilderModel {
1386
  ksort($categories[$title]);
1387
  }
1388
  }
1389
-
1390
  // Return sorted categories.
1391
  return $categories;
1392
  }
@@ -1396,10 +1396,10 @@ final class FLBuilderModel {
1396
  */
1397
  static public function get_module($node_id)
1398
  {
1399
- $module = self::get_node($node_id);
1400
-
1401
  if(isset(self::$modules[$module->settings->type])) {
1402
-
1403
  $class = get_class(self::$modules[$module->settings->type]);
1404
  $instance = new $class();
1405
  $instance->node = $module->node;
@@ -1408,10 +1408,10 @@ final class FLBuilderModel {
1408
  $instance->settings = $module->settings;
1409
  $instance->type = 'module';
1410
  $instance->form = self::$modules[$module->settings->type]->form;
1411
-
1412
  return $instance;
1413
  }
1414
-
1415
  return false;
1416
  }
1417
 
@@ -1423,11 +1423,11 @@ final class FLBuilderModel {
1423
  $modules = self::get_nodes('module', $col_id);
1424
  $instances = array();
1425
  $i = 0;
1426
-
1427
  foreach($modules as $module) {
1428
-
1429
  if(isset(self::$modules[$module->settings->type])) {
1430
-
1431
  $class = get_class(self::$modules[$module->settings->type]);
1432
  $instances[$i] = new $class();
1433
  $instances[$i]->node = $module->node;
@@ -1439,7 +1439,7 @@ final class FLBuilderModel {
1439
  $i++;
1440
  }
1441
  }
1442
-
1443
  return $instances;
1444
  }
1445
 
@@ -1450,7 +1450,7 @@ final class FLBuilderModel {
1450
  {
1451
  return self::get_modules();
1452
  }
1453
-
1454
  /**
1455
  * @method add_module
1456
  */
@@ -1464,13 +1464,13 @@ final class FLBuilderModel {
1464
  $position = isset($post_data['position']) ? (int)$post_data['position'] : $position;
1465
  $module_node_id = self::generate_node_id();
1466
  $settings->type = $type;
1467
-
1468
  // Run module update method.
1469
  $class = get_class(self::$modules[$type]);
1470
  $instance = new $class();
1471
  $instance->settings = $settings;
1472
  $settings = $instance->update($settings);
1473
-
1474
  // Save the module.
1475
  $data[$module_node_id] = new StdClass();
1476
  $data[$module_node_id]->node = $module_node_id;
@@ -1478,19 +1478,19 @@ final class FLBuilderModel {
1478
  $data[$module_node_id]->parent = $parent_id;
1479
  $data[$module_node_id]->position = self::next_node_position('module', $parent_id);
1480
  $data[$module_node_id]->settings = $settings;
1481
-
1482
  // Update the layout data.
1483
  self::update_layout_data($data);
1484
-
1485
  // Position the module.
1486
  if($position !== false) {
1487
  self::reorder_node($module_node_id, $position);
1488
  }
1489
-
1490
  // Send back the inserted module.
1491
  return self::get_module($module_node_id);
1492
  }
1493
-
1494
  /**
1495
  * @method add_default_module
1496
  */
@@ -1503,8 +1503,8 @@ final class FLBuilderModel {
1503
  $position = isset($post_data['position']) ? (int)$post_data['position'] : $position;
1504
  $settings = self::get_module_defaults($type);
1505
  $module_node_id = self::generate_node_id();
1506
-
1507
- // Add a new row if we don't have a parent.
1508
  if(!$parent) {
1509
  $row = self::add_row('1-col', $position);
1510
  $col_groups = self::get_nodes('column-group', $row->node);
@@ -1514,7 +1514,7 @@ final class FLBuilderModel {
1514
  $parent_id = $parent->node;
1515
  $position = null;
1516
  }
1517
-
1518
  // Add a new column if the parent is a row.
1519
  else if($parent->type == 'row') {
1520
  $col_group = self::add_col_group($parent->node, '1-col', $position);
@@ -1523,13 +1523,13 @@ final class FLBuilderModel {
1523
  $parent_id = $parent->node;
1524
  $position = null;
1525
  }
1526
-
1527
  // Run module update method.
1528
  $class = get_class(self::$modules[$type]);
1529
  $instance = new $class();
1530
  $instance->settings = $settings;
1531
  $settings = $instance->update($settings);
1532
-
1533
  // Save the module.
1534
  $data = self::get_layout_data();
1535
  $data[$module_node_id] = new StdClass();
@@ -1538,106 +1538,106 @@ final class FLBuilderModel {
1538
  $data[$module_node_id]->parent = $parent_id;
1539
  $data[$module_node_id]->position = self::next_node_position('module', $parent_id);
1540
  $data[$module_node_id]->settings = $settings;
1541
-
1542
  // Update the layout data.
1543
  self::update_layout_data($data);
1544
-
1545
  // Position the module.
1546
  if($position !== false) {
1547
  self::reorder_node($module_node_id, $position);
1548
  }
1549
-
1550
  // Send back the inserted module.
1551
  return self::get_module($module_node_id);
1552
  }
1553
-
1554
  /**
1555
  * @method copy_module
1556
- */
1557
  static public function copy_module($node_id = null)
1558
  {
1559
  $post_data = self::get_post_data();
1560
  $node_id = isset($post_data['node_id']) ? $post_data['node_id'] : $node_id;
1561
  $module = self::get_module($node_id);
1562
-
1563
  return self::add_module($module->settings->type, $module->settings, $module->parent, $module->position + 1);
1564
  }
1565
-
1566
  /**
1567
  * @method process_module_settings
1568
- */
1569
  static public function process_module_settings($module, $new_settings)
1570
  {
1571
  // Get a new node instance to work with.
1572
  $class = get_class(self::$modules[$module->settings->type]);
1573
  $instance = new $class();
1574
-
1575
  // Run node delete to clear any cache.
1576
  $instance->settings = $module->settings;
1577
  $instance->delete();
1578
-
1579
  // Run node update.
1580
  $instance->settings = $new_settings;
1581
  $new_settings = $instance->update($new_settings);
1582
-
1583
  return $new_settings;
1584
  }
1585
-
1586
  /**
1587
  * @method get_module_defaults
1588
  */
1589
  static public function get_module_defaults($type)
1590
  {
1591
  $defaults = new StdClass();
1592
-
1593
  if(isset(self::$modules[$type]->form)) {
1594
  $defaults = self::get_settings_form_defaults(self::$modules[$type]->form);
1595
  $defaults->type = $type;
1596
  }
1597
-
1598
  return $defaults;
1599
  }
1600
-
1601
  /**
1602
  * @method get_wp_widgets
1603
  */
1604
  static public function get_wp_widgets()
1605
  {
1606
  global $wp_widget_factory;
1607
-
1608
  $widgets = array();
1609
-
1610
  foreach($wp_widget_factory->widgets as $class => $widget) {
1611
  $widget->class = $class;
1612
  $widgets[$widget->name] = $widget;
1613
  }
1614
-
1615
  ksort($widgets);
1616
-
1617
  return $widgets;
1618
  }
1619
-
1620
  /**
1621
  * @method get_wp_sidebars
1622
  */
1623
  static public function get_wp_sidebars()
1624
  {
1625
  global $wp_registered_sidebars;
1626
-
1627
  $sidebars = array();
1628
-
1629
  foreach($wp_registered_sidebars as $sidebar) {
1630
  $sidebars[$sidebar['name']] = $sidebar;
1631
  }
1632
-
1633
  ksort($sidebars);
1634
-
1635
  return $sidebars;
1636
  }
1637
-
1638
  /**
1639
  * @method load_settings
1640
- */
1641
  static public function load_settings()
1642
  {
1643
  require_once FL_BUILDER_DIR . 'includes/global-settings.php';
@@ -1646,22 +1646,22 @@ final class FLBuilderModel {
1646
  require_once FL_BUILDER_DIR . 'includes/module-settings.php';
1647
  require_once FL_BUILDER_DIR . 'includes/user-template-settings.php';
1648
  }
1649
-
1650
  /**
1651
  * @method register_settings_form
1652
- */
1653
  static public function register_settings_form($id, $form)
1654
  {
1655
  self::$settings_forms[$id] = $form;
1656
  }
1657
-
1658
  /**
1659
  * @method get_settings_form_fields
1660
- */
1661
  static public function get_settings_form_fields($form)
1662
  {
1663
  $fields = array();
1664
-
1665
  foreach ( $form as $tab ) {
1666
  if ( isset( $tab['sections'] ) ) {
1667
  foreach ( $tab['sections'] as $section ) {
@@ -1673,27 +1673,27 @@ final class FLBuilderModel {
1673
  }
1674
  }
1675
  }
1676
-
1677
  return $fields;
1678
  }
1679
-
1680
  /**
1681
  * @method get_settings_form_defaults
1682
  */
1683
  static public function get_settings_form_defaults($tabs = array())
1684
  {
1685
  $defaults = new StdClass();
1686
-
1687
  foreach($tabs as $tab) {
1688
  if(isset($tab['sections'])) {
1689
  foreach($tab['sections'] as $section) {
1690
  if(isset($section['fields'])) {
1691
  foreach($section['fields'] as $name => $field) {
1692
-
1693
  $default = isset($field['default']) ? $field['default'] : '';
1694
  $is_multiple = isset($field['multiple']) && $field['multiple'] === true;
1695
  $supports_multiple = $field['type'] != 'editor' && $field['type'] != 'photo';
1696
-
1697
  if($is_multiple && $supports_multiple) {
1698
  $defaults->$name = array($default);
1699
  }
@@ -1705,10 +1705,10 @@ final class FLBuilderModel {
1705
  }
1706
  }
1707
  }
1708
-
1709
  return $defaults;
1710
  }
1711
-
1712
  /**
1713
  * @method save_settings
1714
  */
@@ -1719,17 +1719,17 @@ final class FLBuilderModel {
1719
  $settings = isset($post_data['settings']) ? $post_data['settings'] : $settings;
1720
  $node = self::get_node($node_id);
1721
  $new_settings = (object)array_merge((array)$node->settings, (array)$settings);
1722
-
1723
  // Process the settings.
1724
  $new_settings = self::process_node_settings($node, $new_settings);
1725
 
1726
  // Save the settings to the node.
1727
  $data = self::get_layout_data();
1728
  $data[$node_id]->settings = $new_settings;
1729
-
1730
  // Update the layout data.
1731
  self::update_layout_data($data);
1732
-
1733
  // Return the new layout.
1734
  if(defined('DOING_AJAX')) {
1735
  FLBuilder::render_css();
@@ -1737,7 +1737,7 @@ final class FLBuilderModel {
1737
  FLBuilder::render_layout();
1738
  }
1739
  }
1740
-
1741
  /**
1742
  * @method json_decode_settings
1743
  */
@@ -1747,15 +1747,15 @@ final class FLBuilderModel {
1747
  $data = json_decode(stripcslashes($data));
1748
  }
1749
  if(is_object($data) || is_array($data)) {
1750
-
1751
  foreach($data as $key => $val) {
1752
-
1753
  $new_val = null;
1754
-
1755
  if(is_string($val)) {
1756
-
1757
  $decoded = json_decode(stripcslashes($val));
1758
-
1759
  if(is_object($decoded) || is_array($decoded)) {
1760
  $new_val = $decoded;
1761
  }
@@ -1763,9 +1763,9 @@ final class FLBuilderModel {
1763
  else if(is_object($val) || is_array($val)) {
1764
  $new_val = self::json_decode_settings($val);
1765
  }
1766
-
1767
  if($new_val) {
1768
-
1769
  if(is_object($data)) {
1770
  $data->{$key} = $new_val;
1771
  }
@@ -1775,10 +1775,10 @@ final class FLBuilderModel {
1775
  }
1776
  }
1777
  }
1778
-
1779
  return $data;
1780
  }
1781
-
1782
  /**
1783
  * @method default_settings
1784
  */
@@ -1790,15 +1790,15 @@ final class FLBuilderModel {
1790
  }
1791
  }
1792
  }
1793
-
1794
- /**
1795
  * @method get_global_defaults
1796
  */
1797
  static public function get_global_defaults()
1798
  {
1799
  return self::get_settings_form_defaults(self::$settings_forms['global']['tabs']);
1800
  }
1801
-
1802
  /**
1803
  * @method get_global_settings
1804
  */
@@ -1806,14 +1806,14 @@ final class FLBuilderModel {
1806
  {
1807
  $settings = get_option('_fl_builder_settings');
1808
  $defaults = self::get_global_defaults();
1809
-
1810
  if(!$settings) {
1811
  $settings = new StdClass();
1812
  }
1813
-
1814
  return (object)array_merge((array)$defaults, (array)$settings);
1815
  }
1816
-
1817
  /**
1818
  * @method save_global_settings
1819
  */
@@ -1823,126 +1823,126 @@ final class FLBuilderModel {
1823
  $settings = isset($post_data['settings']) ? $post_data['settings'] : $settings;
1824
  $old_settings = self::get_global_settings();
1825
  $new_settings = (object)array_merge((array)$old_settings, (array)$settings);
1826
-
1827
  return update_option('_fl_builder_settings', $settings);
1828
  }
1829
 
1830
  /**
1831
  * @method duplicate_post
1832
- */
1833
  static public function duplicate_post()
1834
  {
1835
  global $wpdb;
1836
-
1837
  $post_id = self::get_post_id();
1838
  $post = get_post($post_id);
1839
  $current_user = wp_get_current_user();
1840
-
1841
- // Duplicate the post.
1842
- $data = array(
1843
- 'comment_status' => $post->comment_status,
1844
- 'ping_status' => $post->ping_status,
1845
- 'post_author' => $current_user->ID,
1846
- 'post_content' => $post->post_content,
1847
- 'post_excerpt' => $post->post_excerpt,
1848
- 'post_name' => $post->post_name,
1849
- 'post_parent' => $post->post_parent,
1850
- 'post_password' => $post->post_password,
1851
- 'post_status' => 'draft',
1852
- 'post_title' => __('Copy of ', 'fl-builder') . $post->post_title,
1853
- 'post_type' => $post->post_type,
1854
- 'to_ping' => $post->to_ping,
1855
- 'menu_order' => $post->menu_order
1856
- );
1857
-
1858
  // Get the new post id.
1859
  $new_post_id = wp_insert_post($data);
1860
-
1861
  // Duplicate post meta.
1862
  $post_meta = $wpdb->get_results("SELECT meta_key, meta_value FROM {$wpdb->postmeta} WHERE post_id= {$post_id}");
1863
-
1864
  if(count($post_meta) !== 0) {
1865
-
1866
  $sql = "INSERT INTO {$wpdb->postmeta} (post_id, meta_key, meta_value) ";
1867
-
1868
  foreach($post_meta as $meta_info) {
1869
  $meta_key = $meta_info->meta_key;
1870
  $meta_value = addslashes($meta_info->meta_value);
1871
  $sql_select[] = "SELECT {$new_post_id}, '{$meta_key}', '{$meta_value}'";
1872
  }
1873
-
1874
  $sql .= implode(" UNION ALL ", $sql_select);
1875
  $wpdb->query($sql);
1876
  }
1877
-
1878
  // Duplicate post terms.
1879
  $taxonomies = get_object_taxonomies($post->post_type);
1880
-
1881
  foreach($taxonomies as $taxonomy) {
1882
-
1883
  $post_terms = wp_get_object_terms($post_id, $taxonomy);
1884
-
1885
  for($i = 0; $i < count($post_terms); $i++) {
1886
  wp_set_object_terms($new_post_id, $post_terms[$i]->slug, $taxonomy, true);
1887
  }
1888
  }
1889
-
1890
  // Get the duplicated layout data.
1891
  $data = self::get_layout_data('published', $new_post_id);
1892
-
1893
  // Generate new node ids.
1894
  $data = self::generate_new_node_ids($data);
1895
-
1896
  // Save the duplicated layout data.
1897
  self::update_layout_data($data, 'published', $new_post_id);
1898
-
1899
  // Return the new post id.
1900
  return $new_post_id;
1901
  }
1902
-
1903
  /**
1904
  * @method delete_post
1905
- */
1906
  static public function delete_post($post_id)
1907
  {
1908
  // Delete all published and draft data.
1909
  self::delete_layout_data('published', $post_id);
1910
  self::delete_layout_data('draft', $post_id);
1911
-
1912
  // Delete all css and js.
1913
  self::delete_all_asset_cache($post_id);
1914
  }
1915
-
1916
  /**
1917
  * @method save_revision
1918
- */
1919
  static public function save_revision($post_id)
1920
  {
1921
  $parent_id = wp_is_post_revision($post_id);
1922
-
1923
  if($parent_id) {
1924
-
1925
  $parent = get_post($parent_id);
1926
  $data = self::get_layout_data('published', $parent->ID);
1927
-
1928
  if(!empty($data)) {
1929
  self::update_layout_data($data, 'published', $post_id);
1930
  }
1931
  }
1932
  }
1933
-
1934
  /**
1935
  * @method restore_revision
1936
- */
1937
  static public function restore_revision($post_id, $revision_id)
1938
  {
1939
  $post = get_post($post_id);
1940
  $revision = get_post($revision_id);
1941
-
1942
  if($revision) {
1943
-
1944
  $data = self::get_layout_data('published', $revision->ID);
1945
-
1946
  if(!empty($data)) {
1947
  self::update_layout_data($data, 'published', $post_id);
1948
  self::update_layout_data($data, 'draft', $post_id);
@@ -1951,22 +1951,22 @@ final class FLBuilderModel {
1951
  self::delete_layout_data('published', $post_id);
1952
  self::delete_layout_data('draft', $post_id);
1953
  }
1954
-
1955
  self::delete_all_asset_cache();
1956
  }
1957
  }
1958
-
1959
  /**
1960
  * We use get_metadata here instead of get_post_meta,
1961
- * to ensure revisions are queried accordingly.
1962
  *
1963
  * @method get_layout_data
1964
- */
1965
  static public function get_layout_data($status = null, $post_id = null)
1966
  {
1967
  $post_id = !$post_id ? self::get_post_id() : $post_id;
1968
  $status = !$status ? self::get_node_status() : $status;
1969
-
1970
  // Get published data?
1971
  if($status == 'published') {
1972
  if(isset(self::$published_layout_data[$post_id])) {
@@ -1974,7 +1974,7 @@ final class FLBuilderModel {
1974
  }
1975
  else {
1976
  $data = get_metadata('post', $post_id, '_fl_builder_data', true);
1977
- self::$published_layout_data[$post_id] = $data;
1978
  }
1979
  }
1980
  // Get draft data?
@@ -1984,15 +1984,15 @@ final class FLBuilderModel {
1984
  }
1985
  else {
1986
  $data = get_metadata('post', $post_id, '_fl_builder_draft', true);
1987
- self::$draft_layout_data[$post_id] = $data;
1988
  }
1989
  }
1990
-
1991
  // Make sure we have an array.
1992
  if(empty($data)) {
1993
  $data = array();
1994
  }
1995
-
1996
  // Clone the layout data to ensure the cache remains intact.
1997
  foreach($data as $node_id => $node) {
1998
  $data[$node_id] = clone $node;
@@ -2001,18 +2001,19 @@ final class FLBuilderModel {
2001
  // Return the data.
2002
  return $data;
2003
  }
2004
-
2005
  /**
2006
  * We use update_metadata here instead of update_post_meta,
2007
- * to ensure revisions are updated accordingly.
2008
- *
2009
  * @method update_layout_data
2010
- */
2011
  static public function update_layout_data($data, $status = null, $post_id = null)
2012
  {
2013
  $post_id = !$post_id ? self::get_post_id() : $post_id;
2014
  $status = !$status ? self::get_node_status() : $status;
2015
-
 
2016
  // Update published data?
2017
  if($status == 'published') {
2018
  update_metadata('post', $post_id, '_fl_builder_data', $data);
@@ -2024,75 +2025,93 @@ final class FLBuilderModel {
2024
  self::$draft_layout_data[$post_id] = $data;
2025
  }
2026
  }
2027
-
2028
  /**
2029
  * @method delete_layout_data
2030
- */
2031
  static public function delete_layout_data($status = null, $post_id = null)
2032
  {
2033
  // Make sure we have a status to delete.
2034
  if(!$status) {
2035
  return;
2036
  }
2037
-
2038
  // Get the post id.
2039
  $post_id = !$post_id ? self::get_post_id() : $post_id;
2040
-
2041
  // Get the data to delete.
2042
  $data = self::get_layout_data($status, $post_id);
2043
-
2044
  // Delete the nodes.
2045
  foreach($data as $node) {
2046
  self::call_module_delete($node);
2047
  }
2048
-
2049
  // Update the layout data.
2050
  self::update_layout_data(array(), $status, $post_id);
2051
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2052
 
2053
  /**
2054
  * @method clear_draft_layout
2055
- */
2056
  static public function clear_draft_layout()
2057
  {
2058
  $post_id = self::get_post_id();
2059
  $data = self::get_layout_data('published', $post_id);
2060
-
2061
  // Delete the old draft layout.
2062
  self::delete_layout_data('draft');
2063
-
2064
  // Save the new draft layout.
2065
  self::update_layout_data($data, 'draft', $post_id);
2066
-
2067
- // Clear the asset cache.
2068
  self::delete_all_asset_cache($post_id);
2069
  }
2070
-
2071
  /**
2072
  * @method save_layout
2073
- */
2074
  static public function save_layout()
2075
  {
2076
  $editor_content = FLBuilder::render_editor_content();
2077
  $post_id = self::get_post_id();
2078
  $data = self::get_layout_data('draft', $post_id);
2079
-
2080
  // Delete the old published layout.
2081
  self::delete_layout_data('published', $post_id);
2082
-
2083
  // Save the new published layout.
2084
  self::update_layout_data($data, 'published', $post_id);
2085
-
2086
- // Clear the asset cache.
2087
  self::delete_all_asset_cache($post_id);
2088
-
2089
  // Enable the builder to take over the post content.
2090
  self::enable();
2091
-
2092
  // Get the post status.
2093
  $post_status = get_post_status($post_id);
2094
  $post_status = strstr($post_status, 'draft') ? 'publish' : $post_status;
2095
-
2096
  // Update the post with stripped down content.
2097
  wp_update_post(array(
2098
  'ID' => self::get_post_id(),
@@ -2100,13 +2119,13 @@ final class FLBuilderModel {
2100
  'post_content' => $editor_content
2101
  ));
2102
  }
2103
-
2104
  /**
2105
  * Duplicates a layout for WPML when the copy from original
2106
  * button has been clicked.
2107
- *
2108
  * @method duplicate_wpml_layout
2109
- */
2110
  static public function duplicate_wpml_layout($original_post_id = null, $new_post_id = null)
2111
  {
2112
  $post_data = self::get_post_data();
@@ -2115,12 +2134,12 @@ final class FLBuilderModel {
2115
  $enabled = get_post_meta($original_post_id, '_fl_builder_enabled', true);
2116
  $published = self::get_layout_data('published', $original_post_id);
2117
  $draft = self::get_layout_data('draft', $original_post_id);
2118
-
2119
  $response = array(
2120
  'enabled' => false,
2121
  'has_layout' => false
2122
  );
2123
-
2124
  if(!empty($enabled)) {
2125
  update_post_meta($new_post_id, '_fl_builder_enabled', true);
2126
  $response['enabled'] = true;
@@ -2133,18 +2152,18 @@ final class FLBuilderModel {
2133
  self::update_layout_data($draft, 'draft', $new_post_id);
2134
  $response['has_layout'] = true;
2135
  }
2136
-
2137
  return $response;
2138
  }
2139
-
2140
  /**
2141
  * @method get_enabled_templates
2142
- */
2143
  static public function get_enabled_templates()
2144
  {
2145
  $key = '_fl_builder_enabled_templates';
2146
  $default = 'enabled';
2147
-
2148
  // Get the value.
2149
  if(is_network_admin()) {
2150
  $value = get_site_option($key);
@@ -2156,7 +2175,7 @@ final class FLBuilderModel {
2156
  else {
2157
  $value = get_option($key);
2158
  }
2159
-
2160
  // Return the value.
2161
  if(!$value) {
2162
  return $default;
@@ -2165,14 +2184,14 @@ final class FLBuilderModel {
2165
  return $value;
2166
  }
2167
  }
2168
-
2169
  /**
2170
  * @method save_user_template
2171
- */
2172
  static public function save_user_template()
2173
  {
2174
  $post_data = self::get_post_data();
2175
-
2176
  $post_id = wp_insert_post(array(
2177
  'post_title' => $post_data['template_name'],
2178
  'post_type' => 'fl-builder-template',
@@ -2180,41 +2199,41 @@ final class FLBuilderModel {
2180
  'ping_status' => 'closed',
2181
  'comment_status' => 'closed'
2182
  ));
2183
-
2184
  // Get the layout data to copy.
2185
  $data = self::get_layout_data();
2186
-
2187
  // Generate new node ids.
2188
  $data = self::generate_new_node_ids($data);
2189
-
2190
  // Save the template layout data.
2191
  self::update_layout_data($data, 'published', $post_id);
2192
  }
2193
-
2194
  /**
2195
  * @method get_user_templates
2196
- */
2197
  static public function get_user_templates()
2198
  {
2199
  return get_posts('post_type=fl-builder-template&orderby=title&order=ASC&posts_per_page=-1');
2200
  }
2201
-
2202
  /**
2203
  * @method delete_user_template
2204
- */
2205
  static public function delete_user_template($template_id = null)
2206
  {
2207
  $post_data = self::get_post_data();
2208
  $template_id = isset($post_data['template_id']) ? $post_data['template_id'] : $template_id;
2209
-
2210
  if(isset($template_id)) {
2211
  wp_delete_post($template_id, true);
2212
  }
2213
  }
2214
-
2215
  /**
2216
  * @method apply_user_template
2217
- */
2218
  static public function apply_user_template($template_id = null, $append = false)
2219
  {
2220
  $post_data = self::get_post_data();
@@ -2223,109 +2242,109 @@ final class FLBuilderModel {
2223
  $row_position = self::next_node_position('row');
2224
 
2225
  if(isset($template_id)) {
2226
-
2227
  // Delete existing nodes?
2228
  if(!$append) {
2229
  self::delete_layout_data('draft');
2230
  }
2231
-
2232
  // Insert new nodes if this is not a blank template.
2233
  if($template_id != 'blank') {
2234
-
2235
  // Get the template data.
2236
  $template_data = self::get_layout_data('published', $template_id);
2237
-
2238
  // Get new ids for the template nodes.
2239
  $template_data = self::generate_new_node_ids($template_data);
2240
-
2241
  // Get the existing layout data.
2242
  $layout_data = self::get_layout_data();
2243
-
2244
  // Reposition rows?
2245
  if($append) {
2246
-
2247
  foreach($template_data as $node_id => $node) {
2248
-
2249
  if($node->type == 'row') {
2250
  $template_data[$node_id]->position += $row_position;
2251
- }
2252
  }
2253
  }
2254
-
2255
  // Merge the data.
2256
  $data = array_merge($layout_data, $template_data);
2257
-
2258
  // Update the layout data.
2259
  self::update_layout_data($data);
2260
  }
2261
-
2262
  // Delete old asset cache.
2263
  self::delete_all_asset_cache();
2264
  }
2265
  }
2266
-
2267
  /**
2268
  * @method save_template
2269
- */
2270
  static public function save_template($settings)
2271
  {
2272
  // Get the layout data.
2273
  $data = self::get_layout_data();
2274
-
2275
  // Get the templates array.
2276
  $templates = self::get_templates();
2277
-
2278
  // Get new ids for the nodes.
2279
  $settings->nodes = self::generate_new_node_ids($data);
2280
 
2281
  // Insert the template into the templates array.
2282
  array_splice($templates, $settings->index, 0, array($settings));
2283
-
2284
  // Save the templates array.
2285
  self::save_templates($templates);
2286
  }
2287
-
2288
  /**
2289
  * @method update_template
2290
- */
2291
  static public function update_template($old_index, $settings)
2292
  {
2293
  // Get the templates array.
2294
  $templates = self::get_templates();
2295
-
2296
  // Remove the template from its old position.
2297
  $template = array_splice($templates, $old_index, 1);
2298
-
2299
  // Update the settings
2300
  foreach($settings as $key => $val) {
2301
  $template[0]->$key = $val;
2302
  }
2303
-
2304
- // Add the template to its new position.
2305
  array_splice($templates, $settings->index, 0, $template);
2306
-
2307
  // Save the templates array.
2308
  self::save_templates($templates);
2309
  }
2310
-
2311
  /**
2312
  * @method delete_template
2313
- */
2314
  static public function delete_template($index)
2315
  {
2316
  // Get the templates array.
2317
  $templates = self::get_templates();
2318
-
2319
  // Remove the template.
2320
  array_splice($templates, $index, 1);
2321
-
2322
  // Save the templates array.
2323
  self::save_templates($templates);
2324
  }
2325
-
2326
  /**
2327
  * @method apply_template
2328
- */
2329
  static public function apply_template($index = 0, $append = false)
2330
  {
2331
  $post_data = self::get_post_data();
@@ -2333,90 +2352,90 @@ final class FLBuilderModel {
2333
  $append = isset($post_data['append']) ? $post_data['append'] : $append;
2334
  $template = self::get_template($index);
2335
  $row_position = self::next_node_position('row');
2336
-
2337
  // Delete existing nodes?
2338
  if(!$append) {
2339
  self::delete_layout_data('draft');
2340
  }
2341
-
2342
  // Only move forward if we have template nodes.
2343
  if(isset($template->nodes)) {
2344
-
2345
  // Get new ids for the template nodes.
2346
  $template_data = self::generate_new_node_ids($template->nodes);
2347
-
2348
  // Get the existing layout data.
2349
  $layout_data = self::get_layout_data();
2350
-
2351
  // Reposition rows?
2352
  if($append) {
2353
-
2354
  foreach($template_data as $node_id => $node) {
2355
-
2356
  if($node->type == 'row') {
2357
  $template_data[$node_id]->position += $row_position;
2358
- }
2359
  }
2360
  }
2361
-
2362
  // Merge the data.
2363
  $data = array_merge($layout_data, $template_data);
2364
-
2365
  // Update the layout data.
2366
  self::update_layout_data($data);
2367
  }
2368
-
2369
  // Delete old asset cache.
2370
  self::delete_all_asset_cache();
2371
  }
2372
-
2373
  /**
2374
  * @method get_template
2375
- */
2376
  static public function get_template($index)
2377
  {
2378
  $templates = self::get_templates();
2379
-
2380
  return $templates[$index];
2381
  }
2382
 
2383
  /**
2384
  * @method get_templates
2385
- */
2386
  static public function get_templates()
2387
  {
2388
  $templates = unserialize(file_get_contents(FL_BUILDER_DIR . 'data/templates.dat'));
2389
-
2390
  return is_array($templates) ? $templates : array();
2391
  }
2392
-
2393
  /**
2394
  * @method save_templates
2395
- */
2396
  static public function save_templates($templates = array())
2397
  {
2398
  // Update the indexes for proper positioning.
2399
  $i = 0;
2400
  $updated = array();
2401
-
2402
  foreach($templates as $template) {
2403
  $template->index = $i;
2404
  $updated[$i] = $template;
2405
  $i++;
2406
  }
2407
-
2408
  // Save the templates array.
2409
  file_put_contents(FL_BUILDER_DIR . 'data/templates.dat', serialize($updated));
2410
  }
2411
-
2412
  /**
2413
  * @method get_branding
2414
- */
2415
  static public function get_branding()
2416
  {
2417
  $key = '_fl_builder_branding';
2418
  $default = __('Page Builder', 'fl-builder');
2419
-
2420
  // Get the value.
2421
  if(is_network_admin() || class_exists('FLBuilderMultisiteSettings')) {
2422
  $value = get_site_option($key);
@@ -2424,7 +2443,7 @@ final class FLBuilderModel {
2424
  else {
2425
  $value = get_option($key);
2426
  }
2427
-
2428
  // Return the value.
2429
  if(!$value) {
2430
  return $default;
@@ -2433,15 +2452,15 @@ final class FLBuilderModel {
2433
  return stripcslashes($value);
2434
  }
2435
  }
2436
-
2437
  /**
2438
  * @method get_branding_icon
2439
- */
2440
  static public function get_branding_icon()
2441
  {
2442
  $key = '_fl_builder_branding_icon';
2443
  $default = FL_BUILDER_URL . 'img/beaver.png';
2444
-
2445
  // Get the value.
2446
  if(is_network_admin() || class_exists('FLBuilderMultisiteSettings')) {
2447
  $value = get_site_option($key);
@@ -2449,7 +2468,7 @@ final class FLBuilderModel {
2449
  else {
2450
  $value = get_option($key);
2451
  }
2452
-
2453
  // Return the value.
2454
  if($value === false) {
2455
  return $default;
@@ -2458,15 +2477,15 @@ final class FLBuilderModel {
2458
  return $value;
2459
  }
2460
  }
2461
-
2462
  /**
2463
  * @method get_editing_capability
2464
- */
2465
  static public function get_editing_capability()
2466
  {
2467
  $key = '_fl_builder_editing_capability';
2468
  $default = 'edit_posts';
2469
-
2470
  // Get the value.
2471
  if(is_network_admin()) {
2472
  $value = get_site_option($key);
@@ -2478,7 +2497,7 @@ final class FLBuilderModel {
2478
  else {
2479
  $value = get_option($key);
2480
  }
2481
-
2482
  // Return the value.
2483
  if(!$value) {
2484
  return $default;
@@ -2487,17 +2506,17 @@ final class FLBuilderModel {
2487
  return $value;
2488
  }
2489
  }
2490
-
2491
  /**
2492
- * We don't delete _fl_builder_enabled, _fl_builder_data and _fl_builder_draft
2493
  * so layouts can be recovered should the plugin be installed again.
2494
  *
2495
  * @method uninstall_database
2496
- */
2497
  static public function uninstall_database()
2498
  {
2499
  if(current_user_can('delete_plugins')) {
2500
-
2501
  // Delete builder settings.
2502
  delete_option('_fl_builder_settings');
2503
  delete_option('_fl_builder_enabled_modules');
@@ -2513,13 +2532,13 @@ final class FLBuilderModel {
2513
  foreach($cache_files as $file) {
2514
  unlink($file);
2515
  }
2516
-
2517
  rmdir($cache_dir['path']);
2518
 
2519
  // Deactivate and delete the plugin.
2520
  deactivate_plugins(array('fl-builder/fl-builder.php'), false, is_network_admin());
2521
  delete_plugins(array('fl-builder/fl-builder.php'));
2522
-
2523
  // Redirect to the plugins page.
2524
  wp_redirect(admin_url('plugins.php?deleted=true&plugin_status=all&paged=1&s='));
2525
  }
11
  /**
12
  * @property $row_layouts
13
  * @type array
14
+ */
15
  static public $row_layouts = array(
16
  '1-col' => array(100),
17
  '2-cols' => array(50, 50),
24
  'left-right-sidebar' => array(25, 50, 25)
25
  );
26
 
27
+ /**
28
  * @property $settings_forms
29
  * @type array
30
  */
31
  static public $settings_forms = array();
32
 
33
+ /**
34
  * @property $modules
35
  * @type array
36
  */
37
  static public $modules = array();
38
+
39
+ /**
40
  * The last node id that was generated by the builder.
41
  * This is saved to ensure the next node id is unique.
42
  *
45
  * @private
46
  */
47
  static private $last_generated_node_id = null;
48
+
49
+ /**
50
  * Cached post data from either the $_POST array
51
  * or from the json decoded fl_builder_data post variable.
52
  *
55
  * @private
56
  */
57
  static private $post_data = null;
58
+
59
+ /**
60
  * An array of cached published layout data by post_id.
61
  *
62
  * @property $published_layout_data
64
  * @private
65
  */
66
  static private $published_layout_data = array();
67
+
68
+ /**
69
  * An array of cached draft layout data by post_id.
70
  *
71
  * @property $draft_layout_data
73
  * @private
74
  */
75
  static private $draft_layout_data = array();
76
+
77
  /**
78
+ * All database updates should be made through
79
  * this method for security.
80
  *
81
  * @method update
82
+ */
83
  static public function update($method = null, $params = array())
84
  {
85
  $post_data = self::get_post_data();
86
  $method = isset($post_data['method']) ? $post_data['method'] : $method;
87
  $post_id = self::get_post_id();
88
+
89
  // User can't edit this post.
90
  if($post_id && !current_user_can('edit_post', $post_id)) {
91
  return false;
92
  }
93
+
94
+ // Method doesn't exist.
95
  else if(!$method) {
96
  return false;
97
  }
98
+
99
  // Method exists.
100
  else if(method_exists('FLBuilderModel', $method)) {
101
+
102
  // Call the method.
103
  $result = call_user_func_array('FLBuilderModel::' . $method, $params);
104
+
105
+ // Render new assets.
106
  if(!isset($post_data['render_assets']) || $post_data['render_assets'] == 1) {
107
  FLBuilder::render_css();
108
  FLBuilder::render_js();
109
  }
110
+
111
  // Return the result.
112
  if(defined('DOING_AJAX')) {
113
  echo json_encode($result);
117
  return $result;
118
  }
119
  }
120
+
121
  return false;
122
  }
123
+
124
  /**
125
  * @method get_edit_url
126
  */
127
  static public function get_edit_url( $post_id = false )
128
  {
129
  global $post;
130
+
131
  if ( false === $post_id ) {
132
  $post_id = $post->ID;
133
  }
134
+
135
  $url = add_query_arg( 'fl_builder', '', get_permalink( $post_id ) );
136
 
137
  if ( class_exists( 'WPMinify' ) ) {
138
  $url = add_query_arg( 'wp-minify-off', '1', $url );
139
  }
140
+
141
  return set_url_scheme( $url );
142
  }
143
+
144
  /**
145
  * @method get_post_data
146
+ */
147
  static public function get_post_data()
148
  {
149
  if(!self::$post_data) {
150
+
151
  self::$post_data = array();
152
+
153
  if(isset($_POST['fl_builder_data'])) {
154
+
155
  $data = self::json_decode_settings($_POST['fl_builder_data']);
156
+
157
  foreach($data as $key => $val) {
158
  self::$post_data[$key] = $val;
159
  }
160
  }
161
  else if(isset($_POST)) {