WordPress Page Builder – Beaver Builder - Version 1.5.6

Version Description

Download this release

Release Info

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

Code changes from version 1.5.5 to 1.5.6

Files changed (101) hide show
  1. changelog.txt +21 -0
  2. classes/class-fl-builder-admin-posts.php +89 -89
  3. classes/class-fl-builder-admin-settings.php +452 -441
  4. classes/class-fl-builder-admin.php +232 -185
  5. classes/class-fl-builder-auto-suggest.php +230 -192
  6. classes/class-fl-builder-color.php +53 -37
  7. classes/class-fl-builder-icons.php +373 -328
  8. classes/class-fl-builder-loop.php +182 -160
  9. classes/class-fl-builder-model.php +2883 -2450
  10. classes/class-fl-builder-module.php +240 -220
  11. classes/class-fl-builder-photo.php +84 -67
  12. classes/class-fl-builder-service-aweber.php +166 -166
  13. classes/class-fl-builder-service-campaign-monitor.php +172 -172
  14. classes/class-fl-builder-service-constant-contact.php +216 -216
  15. classes/class-fl-builder-service-getresponse.php +133 -133
  16. classes/class-fl-builder-service-icontact.php +193 -193
  17. classes/class-fl-builder-service-madmimi.php +156 -156
  18. classes/class-fl-builder-service-mailchimp.php +143 -141
  19. classes/class-fl-builder-service-mailpoet.php +85 -85
  20. classes/class-fl-builder-service-sendinblue.php +229 -0
  21. classes/class-fl-builder-service.php +27 -27
  22. classes/class-fl-builder-services.php +220 -220
  23. classes/class-fl-builder-update.php +379 -345
  24. classes/class-fl-builder-utils.php +92 -36
  25. classes/class-fl-builder.php +1654 -1409
  26. classes/class-fl-jsmin.php +238 -238
  27. css/colorpicker.css +4 -4
  28. css/editor.css +1 -1
  29. css/fl-builder-admin-posts-legacy.css +12 -12
  30. css/fl-builder-admin-posts.css +56 -56
  31. css/fl-builder-admin-settings.css +59 -59
  32. css/fl-builder-layout-auto-spacing.css +12 -12
  33. css/fl-builder-layout-medium.css +2 -2
  34. css/fl-builder-layout-responsive.css +11 -11
  35. css/fl-builder-layout.css +185 -185
  36. css/fl-builder-rtl.css +14 -14
  37. css/fl-builder.css +694 -693
  38. css/fl-icon-selector.css +36 -36
  39. css/fl-lightbox.css +64 -64
  40. css/fl-slideshow.css +41 -41
  41. css/font-awesome.min.css +2 -2
  42. css/foundation-icons.css +17 -17
  43. css/jquery.bxslider.css +3 -3
  44. css/jquery.magnificpopup.css +286 -286
  45. css/jquery.nanoscroller.css +33 -33
  46. css/jquery.tiptip.css +1 -1
  47. fl-builder.php +7 -7
  48. fonts/FontAwesome.otf +0 -0
  49. fonts/fontawesome-webfont.eot +0 -0
  50. fonts/fontawesome-webfont.svg +53 -8
  51. fonts/fontawesome-webfont.ttf +0 -0
  52. fonts/fontawesome-webfont.woff +0 -0
  53. fonts/fontawesome-webfont.woff2 +0 -0
  54. includes/admin-posts.php +8 -8
  55. includes/admin-settings-cache.php +15 -15
  56. includes/admin-settings-editing.php +16 -16
  57. includes/admin-settings-js-config.php +2 -2
  58. includes/admin-settings-modules.php +43 -43
  59. includes/admin-settings-post-types.php +59 -59
  60. includes/admin-settings-uninstall.php +11 -11
  61. includes/admin-settings-upgrade.php +4 -4
  62. includes/admin-settings.php +7 -7
  63. includes/column-css.php +28 -28
  64. includes/column-group.php +7 -7
  65. includes/column-settings.php +369 -369
  66. includes/compatibility.php +27 -27
  67. includes/field-code.php +12 -12
  68. includes/field-color.php +5 -5
  69. includes/field-editor.php +56 -56
  70. includes/field-form.php +25 -25
  71. includes/field-icon.php +9 -9
  72. includes/field-layout.php +7 -7
  73. includes/field-link.php +6 -6
  74. includes/field-multiple-photos.php +9 -9
  75. includes/field-photo-sizes.php +7 -7
  76. includes/field-photo.php +14 -14
  77. includes/field-post-type.php +3 -3
  78. includes/field-select.php +13 -13
  79. includes/field-video.php +18 -18
  80. includes/field.php +38 -38
  81. includes/global-settings.php +147 -147
  82. includes/icon-selector.php +22 -22
  83. includes/jquery.php +2 -2
  84. includes/js-config.php +98 -98
  85. includes/loop-settings.php +93 -93
  86. includes/module-settings.php +130 -130
  87. includes/module.php +3 -3
  88. includes/row-css.php +24 -24
  89. includes/row-js.php +23 -23
  90. includes/row-settings.php +620 -620
  91. includes/row-video.php +5 -5
  92. includes/row.php +12 -12
  93. includes/service-settings.php +11 -11
  94. includes/settings.php +63 -63
  95. includes/ui.php +103 -103
  96. includes/updater-config.php +6 -6
  97. includes/updater/classes/class-fl-updater.php +211 -152
  98. includes/updater/includes/config.php +4 -4
  99. includes/updater/includes/form.php +23 -23
  100. includes/user-template-settings.php +18 -18
  101. includes/vendor/sendinblue/Mailin.php +173 -0
changelog.txt CHANGED
@@ -1,3 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <h4>1.5.5 - 04/12/2015</h4>
2
  <p><strong>Enhancements</strong></p>
3
  <ul>
1
+ <h4>1.5.6 - 04/26/2015</h4>
2
+ <p><strong>Enhancements</strong></p>
3
+ <ul>
4
+ <li>Added SendinBlue integration.</li>
5
+ <li>Added filters for MailChimp single optin and disabling the welcome message.</li>
6
+ <li>Most of the builder's PHP and JavaScript files now have much better inline documentation of classes, properties and methods (we still need to do the modules).</li>
7
+ </ul>
8
+ <p><strong>Tweaks</strong></p>
9
+ <ul>
10
+ <li>Removed phone number validation from the Contact Form module to support international phone numbers.</li>
11
+ <li>Updated FontAwesome.</li>
12
+ <li>Tweaked the Heading module CSS to prevent Dynamik from overriding our styles.</li>
13
+ <li>Added CSS to fix margins issue with the WordPress editor link lightbox and some third party themes.</li>
14
+ </ul>
15
+ <p><strong>Bug Fixes</strong></p>
16
+ <ul>
17
+ <li>Fixed a bug that didn't allow backslashes to be saved.</li>
18
+ <li>Fixed a bug that prevented namespaced widgets from working.</li>
19
+ <li>Fixed a bug with the Posts module that prevented the date from being hidden in the gallery layout.</li>
20
+ </ul>
21
+
22
  <h4>1.5.5 - 04/12/2015</h4>
23
  <p><strong>Enhancements</strong></p>
24
  <ul>
classes/class-fl-builder-admin-posts.php CHANGED
@@ -3,51 +3,51 @@
3
  /**
4
  * Handles logic for the post edit screen.
5
  *
6
- * @since 1.5.0
7
  */
8
  final class FLBuilderAdminPosts {
9
-
10
- /**
11
  * Sets the body class, loads assets and renders the UI
12
  * if we are on a post type that supports the builder.
13
  *
14
- * @since 1.5.0
15
- * @return void
16
- */
17
- static public function init()
18
- {
19
- global $pagenow;
20
-
21
- if ( in_array( $pagenow, array( 'post.php', 'post-new.php') ) ) {
22
-
23
- $post_types = FLBuilderModel::get_post_types();
24
- $screen = get_current_screen();
25
 
26
- if ( in_array( $screen->post_type, $post_types ) ) {
27
- add_filter( 'admin_body_class', 'FLBuilderAdminPosts::body_class' );
28
- add_action( 'admin_enqueue_scripts', 'FLBuilderAdminPosts::styles_scripts' );
29
- add_action( 'edit_form_after_title', 'FLBuilderAdminPosts::render' );
30
- }
31
- }
32
- }
33
 
34
  /**
35
- * Enqueues the CSS/JS for the post edit screen.
36
- *
37
- * @since 1.5.0
38
- * @return void
39
- */
40
  static public function styles_scripts()
41
  {
42
- global $wp_version;
43
-
44
- // Styles
45
  wp_enqueue_style( 'fl-builder-admin-posts', FL_BUILDER_URL . 'css/fl-builder-admin-posts.css', array(), FL_BUILDER_VERSION );
46
 
47
  // Legacy WP Styles (3.7 and below)
48
- if ( version_compare( $wp_version, '3.7', '<=' ) ) {
49
- wp_enqueue_style( 'fl-builder-admin-posts-legacy', FL_BUILDER_URL . 'css/fl-builder-admin-posts-legacy.css', array(), FL_BUILDER_VERSION );
50
- }
51
 
52
  // Scripts
53
  wp_enqueue_script( 'json2' );
@@ -55,80 +55,80 @@ final class FLBuilderAdminPosts {
55
  }
56
 
57
  /**
58
- * Adds classes to the post edit screen body class.
59
- *
60
- * @since 1.5.0
61
  * @param string $classes The existing body classes.
62
- * @return string The body classes.
63
- */
64
  static public function body_class( $classes = '' )
65
  {
66
- global $wp_version;
67
-
68
- // Builder body class
69
- if ( FLBuilderModel::is_builder_enabled() ) {
70
- $classes .= ' fl-builder-enabled';
71
- }
72
-
73
- // Pre WP 3.8 body class
74
- if ( version_compare( $wp_version, '3.8', '<' ) ) {
75
- $classes .= ' fl-pre-wp-3-8';
76
- }
77
-
78
- return $classes;
79
  }
80
 
81
  /**
82
- * Renders the HTML for the post edit screen.
83
- *
84
- * @since 1.5.0
85
- * @return void
86
- */
87
  static public function render()
88
  {
89
- global $post;
90
-
91
- $enabled = FLBuilderModel::is_builder_enabled();
92
-
93
  include FL_BUILDER_DIR . 'includes/admin-posts.php';
94
  }
95
 
96
  /**
97
- * Renders the action link for post listing pages.
98
- *
99
- * @since 1.5.0
100
  * @param array $actions
101
- * @return array The array of action data.
102
- */
103
  static public function render_row_actions_link( $actions = array() )
104
- {
105
- global $post;
106
-
107
- if ( current_user_can( 'edit_post', $post->ID ) && wp_check_post_lock( $post->ID ) === false ) {
108
-
109
- $post_types = FLBuilderModel::get_post_types();
110
 
111
- if ( in_array( $post->post_type, $post_types ) ) {
112
- $actions['fl-builder'] = '<a href="' . FLBuilderModel::get_edit_url() . '">' . FLBuilderModel::get_branding() . '</a>';
113
- }
114
- }
115
-
116
- return $actions;
117
- }
118
 
119
  /**
120
- * Where to redirect this post on save.
121
- *
122
- * @since 1.5.0
123
  * @param string $location
124
- * @return string The location to redirect this post on save.
125
- */
126
  static public function redirect_post_location( $location )
127
- {
128
- if ( isset( $_POST['fl-builder-redirect'] ) ) {
129
- $location = $_POST['fl-builder-redirect'];
130
- }
131
-
132
- return $location;
133
- }
134
  }
3
  /**
4
  * Handles logic for the post edit screen.
5
  *
6
+ * @since 1.0
7
  */
8
  final class FLBuilderAdminPosts {
9
+
10
+ /**
11
  * Sets the body class, loads assets and renders the UI
12
  * if we are on a post type that supports the builder.
13
  *
14
+ * @since 1.0
15
+ * @return void
16
+ */
17
+ static public function init()
18
+ {
19
+ global $pagenow;
20
+
21
+ if ( in_array( $pagenow, array( 'post.php', 'post-new.php') ) ) {
22
+
23
+ $post_types = FLBuilderModel::get_post_types();
24
+ $screen = get_current_screen();
25
 
26
+ if ( in_array( $screen->post_type, $post_types ) ) {
27
+ add_filter( 'admin_body_class', 'FLBuilderAdminPosts::body_class' );
28
+ add_action( 'admin_enqueue_scripts', 'FLBuilderAdminPosts::styles_scripts' );
29
+ add_action( 'edit_form_after_title', 'FLBuilderAdminPosts::render' );
30
+ }
31
+ }
32
+ }
33
 
34
  /**
35
+ * Enqueues the CSS/JS for the post edit screen.
36
+ *
37
+ * @since 1.0
38
+ * @return void
39
+ */
40
  static public function styles_scripts()
41
  {
42
+ global $wp_version;
43
+
44
+ // Styles
45
  wp_enqueue_style( 'fl-builder-admin-posts', FL_BUILDER_URL . 'css/fl-builder-admin-posts.css', array(), FL_BUILDER_VERSION );
46
 
47
  // Legacy WP Styles (3.7 and below)
48
+ if ( version_compare( $wp_version, '3.7', '<=' ) ) {
49
+ wp_enqueue_style( 'fl-builder-admin-posts-legacy', FL_BUILDER_URL . 'css/fl-builder-admin-posts-legacy.css', array(), FL_BUILDER_VERSION );
50
+ }
51
 
52
  // Scripts
53
  wp_enqueue_script( 'json2' );
55
  }
56
 
57
  /**
58
+ * Adds classes to the post edit screen body class.
59
+ *
60
+ * @since 1.0
61
  * @param string $classes The existing body classes.
62
+ * @return string The body classes.
63
+ */
64
  static public function body_class( $classes = '' )
65
  {
66
+ global $wp_version;
67
+
68
+ // Builder body class
69
+ if ( FLBuilderModel::is_builder_enabled() ) {
70
+ $classes .= ' fl-builder-enabled';
71
+ }
72
+
73
+ // Pre WP 3.8 body class
74
+ if ( version_compare( $wp_version, '3.8', '<' ) ) {
75
+ $classes .= ' fl-pre-wp-3-8';
76
+ }
77
+
78
+ return $classes;
79
  }
80
 
81
  /**
82
+ * Renders the HTML for the post edit screen.
83
+ *
84
+ * @since 1.0
85
+ * @return void
86
+ */
87
  static public function render()
88
  {
89
+ global $post;
90
+
91
+ $enabled = FLBuilderModel::is_builder_enabled();
92
+
93
  include FL_BUILDER_DIR . 'includes/admin-posts.php';
94
  }
95
 
96
  /**
97
+ * Renders the action link for post listing pages.
98
+ *
99
+ * @since 1.0
100
  * @param array $actions
101
+ * @return array The array of action data.
102
+ */
103
  static public function render_row_actions_link( $actions = array() )
104
+ {
105
+ global $post;
106
+
107
+ if ( current_user_can( 'edit_post', $post->ID ) && wp_check_post_lock( $post->ID ) === false ) {
108
+
109
+ $post_types = FLBuilderModel::get_post_types();
110
 
111
+ if ( in_array( $post->post_type, $post_types ) ) {
112
+ $actions['fl-builder'] = '<a href="' . FLBuilderModel::get_edit_url() . '">' . FLBuilderModel::get_branding() . '</a>';
113
+ }
114
+ }
115
+
116
+ return $actions;
117
+ }
118
 
119
  /**
120
+ * Where to redirect this post on save.
121
+ *
122
+ * @since 1.0
123
  * @param string $location
124
+ * @return string The location to redirect this post on save.
125
+ */
126
  static public function redirect_post_location( $location )
127
+ {
128
+ if ( isset( $_POST['fl-builder-redirect'] ) ) {
129
+ $location = $_POST['fl-builder-redirect'];
130
+ }
131
+
132
+ return $location;
133
+ }
134
  }
classes/class-fl-builder-admin-settings.php CHANGED
@@ -3,7 +3,7 @@
3
  /**
4
  * Handles logic for the admin settings page.
5
  *
6
- * @since 1.5.0
7
  */
8
  final class FLBuilderAdminSettings {
9
 
@@ -11,37 +11,37 @@ final class FLBuilderAdminSettings {
11
  * Holds any errors that may arise from
12
  * saving admin settings.
13
  *
14
- * @since 1.5.0
15
  * @var array $errors
16
  */
17
  static public $errors = array();
18
-
19
- /**
20
  * Adds the admin menu and enqueues CSS/JS if we are on
21
  * the builder admin settings page.
22
  *
23
- * @since 1.5.0
24
- * @return void
25
- */
26
- static public function init()
27
- {
28
- add_action( 'admin_menu', 'FLBuilderAdminSettings::menu' );
29
-
30
- if ( isset( $_REQUEST['page'] ) && 'fl-builder-settings' == $_REQUEST['page'] ) {
31
- add_action( 'admin_enqueue_scripts', 'FLBuilderAdminSettings::styles_scripts' );
32
- self::save();
33
- }
34
- }
35
-
36
- /**
37
  * Enqueues the needed CSS/JS for the builder's admin settings page.
38
  *
39
- * @since 1.5.0
40
- * @return void
41
- */
42
  static public function styles_scripts()
43
  {
44
- // Styles
45
  wp_enqueue_style( 'fl-builder-admin-settings', FL_BUILDER_URL . 'css/fl-builder-admin-settings.css', array(), FL_BUILDER_VERSION );
46
 
47
  // Scripts
@@ -50,44 +50,44 @@ final class FLBuilderAdminSettings {
50
  // Media Uploader
51
  wp_enqueue_media();
52
  }
53
-
54
- /**
55
  * Renders the admin settings menu.
56
  *
57
- * @since 1.5.0
58
- * @return void
59
- */
60
  static public function menu()
61
  {
62
- if ( current_user_can( 'delete_plugins' ) ) {
63
-
64
- $title = FLBuilderModel::get_branding();
65
- $cap = 'delete_plugins';
66
- $slug = 'fl-builder-settings';
67
- $func = 'FLBuilderAdminSettings::render';
68
-
69
- add_submenu_page( 'options-general.php', $title, $title, $cap, $slug, $func );
70
  }
71
  }
72
-
73
- /**
74
  * Renders the admin settings.
75
  *
76
- * @since 1.5.0
77
- * @return void
78
- */
79
  static public function render()
80
  {
81
- include FL_BUILDER_DIR . 'includes/admin-settings-js-config.php';
82
  include FL_BUILDER_DIR . 'includes/admin-settings.php';
83
  }
84
-
85
- /**
86
  * Renders the page class for network installs and single site installs.
87
  *
88
- * @since 1.5.0
89
- * @return void
90
- */
91
  static public function render_page_class()
92
  {
93
  if ( self::multisite_support() ) {
@@ -97,13 +97,13 @@ final class FLBuilderAdminSettings {
97
  echo 'fl-settings-single-install';
98
  }
99
  }
100
-
101
- /**
102
  * Renders the admin settings page heading.
103
  *
104
- * @since 1.5.0
105
- * @return void
106
- */
107
  static public function render_page_heading()
108
  {
109
  $icon = FLBuilderModel::get_branding_icon();
@@ -115,13 +115,13 @@ final class FLBuilderAdminSettings {
115
 
116
  echo '<span>' . sprintf( _x( '%s Settings', '%s stands for custom branded "Page Builder" name.', 'fl-builder' ), FLBuilderModel::get_branding() ) . '</span>';
117
  }
118
-
119
- /**
120
  * Renders the update message.
121
  *
122
- * @since 1.5.0
123
- * @return void
124
- */
125
  static public function render_update_message()
126
  {
127
  if ( ! empty( self::$errors ) ) {
@@ -133,58 +133,58 @@ final class FLBuilderAdminSettings {
133
  echo '<div class="updated"><p>' . __( 'Settings updated!', 'fl-builder' ) . '</p></div>';
134
  }
135
  }
136
-
137
- /**
138
  * Renders the nav items for the admin settings menu.
139
  *
140
- * @since 1.5.0
141
- * @return void
142
- */
143
  static public function render_nav_items()
144
  {
145
  $item_data = array(
146
  'license' => array(
147
- 'title' => __( 'License', 'fl-builder' ),
148
  'show' => FL_BUILDER_LITE !== true && ( is_network_admin() || ! self::multisite_support() )
149
  ),
150
  'upgrade' => array(
151
- 'title' => __( 'Upgrade', 'fl-builder' ),
152
  'show' => FL_BUILDER_LITE === true
153
  ),
154
  'modules' => array(
155
- 'title' => __( 'Modules', 'fl-builder' ),
156
  'show' => true
157
  ),
158
  'templates' => array(
159
- 'title' => __( 'Templates', 'fl-builder' ),
160
  'show' => FL_BUILDER_LITE !== true
161
  ),
162
  'post-types' => array(
163
- 'title' => __( 'Post Types', 'fl-builder' ),
164
  'show' => true
165
  ),
166
  'icons' => array(
167
- 'title' => __( 'Icons', 'fl-builder' ),
168
  'show' => FL_BUILDER_LITE !== true
169
  ),
170
  'editing' => array(
171
- 'title' => __( 'Editing', 'fl-builder' ),
172
  'show' => true
173
  ),
174
  'branding' => array(
175
- 'title' => __( 'Branding', 'fl-builder' ),
176
  'show' => self::has_support( 'branding' ) && ( is_network_admin() || ! self::multisite_support() )
177
  ),
178
  'help-button' => array(
179
- 'title' => __( 'Help Button', 'fl-builder' ),
180
  'show' => self::has_support( 'help-button' ) && ( is_network_admin() || ! self::multisite_support() )
181
  ),
182
  'cache' => array(
183
- 'title' => __( 'Cache', 'fl-builder' ),
184
  'show' => true
185
  ),
186
  'uninstall' => array(
187
- 'title' => __( 'Uninstall', 'fl-builder' ),
188
  'show' => is_network_admin() || ! self::multisite_support()
189
  ),
190
  );
@@ -195,13 +195,13 @@ final class FLBuilderAdminSettings {
195
  }
196
  }
197
  }
198
-
199
- /**
200
  * Renders the admin settings forms.
201
  *
202
- * @since 1.5.0
203
- * @return void
204
- */
205
  static public function render_forms()
206
  {
207
  // License
@@ -210,7 +210,7 @@ final class FLBuilderAdminSettings {
210
  }
211
 
212
  // Upgrade
213
- if ( FL_BUILDER_LITE === true ) {
214
  self::render_form( 'upgrade' );
215
  }
216
 
@@ -241,28 +241,28 @@ final class FLBuilderAdminSettings {
241
  // Uninstall
242
  self::render_form( 'uninstall' );
243
  }
244
-
245
- /**
246
  * Renders an admin settings form based on the type specified.
247
  *
248
- * @since 1.5.0
249
  * @param string $type The type of form to render.
250
- * @return void
251
- */
252
  static public function render_form( $type )
253
  {
254
  if ( self::has_support( $type ) ) {
255
  include FL_BUILDER_DIR . 'includes/admin-settings-' . $type . '.php';
256
  }
257
  }
258
-
259
- /**
260
  * Renders the action for a form.
261
  *
262
- * @since 1.5.0
263
  * @param string $type The type of form being rendered.
264
- * @return void
265
- */
266
  static public function render_form_action( $type = '' )
267
  {
268
  if ( is_network_admin() ) {
@@ -272,14 +272,14 @@ final class FLBuilderAdminSettings {
272
  echo admin_url( '/options-general.php?page=fl-builder-settings#' . $type );
273
  }
274
  }
275
-
276
- /**
277
  * Returns the action for a form.
278
  *
279
- * @since 1.5.0
280
  * @param string $type The type of form being rendered.
281
- * @return string The URL for the form action.
282
- */
283
  static public function get_form_action( $type = '' )
284
  {
285
  if ( is_network_admin() ) {
@@ -289,55 +289,55 @@ final class FLBuilderAdminSettings {
289
  return admin_url( '/options-general.php?page=fl-builder-settings#' . $type );
290
  }
291
  }
292
-
293
- /**
294
  * Checks to see if a settings form is supported.
295
  *
296
- * @since 1.5.0
297
  * @param string $type The type of form to check.
298
- * @return bool
299
- */
300
  static public function has_support( $type )
301
  {
302
  return file_exists( FL_BUILDER_DIR . 'includes/admin-settings-' . $type . '.php' );
303
  }
304
-
305
- /**
306
  * Checks to see if multisite is supported.
307
  *
308
- * @since 1.5.0
309
- * @return bool
310
- */
311
  static public function multisite_support()
312
  {
313
  return is_multisite() && class_exists( 'FLBuilderMultisiteSettings' );
314
  }
315
-
316
- /**
317
  * Adds an error message to be rendered.
318
  *
319
- * @since 1.5.0
320
  * @param string $message The error message to add.
321
- * @return void
322
- */
323
  static public function add_error( $message )
324
  {
325
  self::$errors[] = $message;
326
  }
327
-
328
- /**
329
  * Saves the admin settings.
330
  *
331
- * @since 1.5.0
332
- * @return void
333
- */
334
  static public function save()
335
  {
336
- // Only admins can save settings.
337
- if(!current_user_can('delete_plugins')) {
338
- return;
339
- }
340
-
341
  self::save_enabled_modules();
342
  self::save_enabled_templates();
343
  self::save_enabled_post_types();
@@ -348,401 +348,412 @@ final class FLBuilderAdminSettings {
348
  self::clear_cache();
349
  self::uninstall();
350
  }
351
-
352
- /**
353
  * Saves the enabled modules.
354
  *
355
- * @since 1.5.0
356
- * @return void
357
- */
 
358
  static private function save_enabled_modules()
359
  {
360
- if ( isset( $_POST['fl-modules-nonce'] ) && wp_verify_nonce( $_POST['fl-modules-nonce'], 'modules' ) ) {
361
-
362
- $modules = array();
363
-
364
- if ( is_array( $_POST['fl-modules'] ) ) {
365
- $modules = array_map( 'sanitize_text_field', $_POST['fl-modules'] );
366
- }
367
-
368
- if ( is_network_admin() ) {
369
- update_site_option( '_fl_builder_enabled_modules', $modules );
370
- }
371
- else if ( self::multisite_support() && ! isset( $_POST['fl-override-ms'] ) ) {
372
- delete_option( '_fl_builder_enabled_modules' );
373
- }
374
- else {
375
- update_option( '_fl_builder_enabled_modules', $modules );
376
- }
377
- }
378
- }
379
-
380
- /**
381
  * Saves the enabled templates.
382
  *
383
- * @since 1.5.0
384
- * @return void
385
- */
 
386
  static private function save_enabled_templates()
387
  {
388
- if ( isset( $_POST['fl-templates-nonce'] ) && wp_verify_nonce( $_POST['fl-templates-nonce'], 'templates' ) ) {
389
-
390
- $enabled_templates = sanitize_text_field( $_POST['fl-template-settings'] );
391
-
392
- if ( is_network_admin() ) {
393
- update_site_option( '_fl_builder_enabled_templates', $enabled_templates );
394
- }
395
- else if ( self::multisite_support() && ! isset( $_POST['fl-override-ms'] ) ) {
396
- delete_option( '_fl_builder_enabled_templates' );
397
- }
398
- else {
399
- update_option( '_fl_builder_enabled_templates', $enabled_templates );
400
- }
401
- }
402
- }
403
-
404
- /**
405
  * Saves the enabled post types.
406
  *
407
- * @since 1.5.0
408
- * @return void
409
- */
 
410
  static private function save_enabled_post_types()
411
  {
412
- if ( isset( $_POST['fl-post-types-nonce'] ) && wp_verify_nonce( $_POST['fl-post-types-nonce'], 'post-types' ) ) {
413
-
414
- if ( is_network_admin() ) {
415
-
416
- $post_types = sanitize_text_field( $_POST['fl-post-types'] );
417
- $post_types = str_replace( ' ', '', $post_types );
418
- $post_types = explode( ',', $post_types );
419
-
420
- update_site_option( '_fl_builder_post_types', $post_types );
421
- }
422
- else if ( self::multisite_support() && ! isset($_POST['fl-override-ms'] ) ) {
423
- delete_option( '_fl_builder_post_types' );
424
- }
425
- else {
426
-
427
- $post_types = array();
428
-
429
- if ( is_array( $_POST['fl-post-types'] ) ) {
430
- $post_types = array_map( 'sanitize_text_field', $_POST['fl-post-types'] );
431
- }
432
-
433
- update_option( '_fl_builder_post_types', $post_types );
434
- }
435
- }
436
- }
437
-
438
- /**
439
  * Saves the enabled icons.
440
  *
441
- * @since 1.5.0
442
- * @return void
443
- */
 
444
  static private function save_enabled_icons()
445
  {
446
- if ( isset( $_POST['fl-icons-nonce'] ) && wp_verify_nonce( $_POST['fl-icons-nonce'], 'icons' ) ) {
447
 
448
  // Make sure we have at least one enabled icon set.
449
  if ( ! isset( $_POST['fl-enabled-icons'] ) && empty( $_POST['fl-new-icon-set'] ) ) {
450
  self::add_error( __( "Error! You must have at least one icon set enabled.", 'fl-builder' ) );
451
- return;
452
  }
453
-
454
- $filesystem = FLBuilderUtils::get_filesystem();
455
  $enabled_icons = array();
456
 
457
  // Sanitize the enabled icons.
458
  if ( isset( $_POST['fl-enabled-icons'] ) && is_array( $_POST['fl-enabled-icons'] ) ) {
459
- $enabled_icons = array_map( 'sanitize_text_field', $_POST['fl-enabled-icons'] );
460
- }
461
-
462
- // Update the enabled sets.
463
- self::update_enabled_icons( $enabled_icons );
464
-
465
- // Delete a set?
466
- if ( ! empty( $_POST['fl-delete-icon-set'] ) ) {
467
-
468
- $sets = FLBuilderIcons::get_sets();
469
- $key = sanitize_text_field( $_POST['fl-delete-icon-set'] );
470
- $index = array_search( $key, $enabled_icons );
471
-
472
- if ( false !== $index ) {
473
- unset( $enabled_icons[ $index ] );
474
- }
475
- if ( isset( $sets[ $key ] ) ) {
476
- $filesystem->rmdir( $sets[ $key ]['path'], true );
477
- FLBuilderIcons::remove_set( $key );
478
- }
479
- }
480
-
481
- // Upload a new set?
482
- if ( ! empty( $_POST['fl-new-icon-set'] ) ) {
483
 
484
- $dir = FLBuilderModel::get_cache_dir( 'icons' );
485
- $id = (int) $_POST['fl-new-icon-set'];
486
- $path = get_attached_file( $id );
487
- $new_path = $dir['path'] . 'icon-' . time() . '/';
488
- $unzipped = unzip_file( $path, $new_path );
489
-
490
- // Unzip failed.
491
- if ( ! $unzipped ) {
492
- self::add_error( __( "Error! Could not unzip file.", 'fl-builder' ) );
493
- return;
494
- }
495
-
496
- // Move files if unzipped into a subfolder.
497
- $files = $filesystem->dirlist( $new_path );
498
-
499
- if ( 1 == count( $files ) ) {
500
 
501
  $values = array_values( $files );
502
  $subfolder_info = array_shift( $values );
503
- $subfolder = $new_path . $subfolder_info['name'] . '/';
504
 
505
  if ( file_exists( $subfolder ) && is_dir( $subfolder ) ) {
506
 
507
- $files = $filesystem->dirlist( $subfolder );
508
-
509
- if ( $files ) {
510
- foreach ( $files as $file ) {
511
- $filesystem->move( $subfolder . $file['name'], $new_path . $file['name'] );
512
- }
513
- }
514
-
515
- $filesystem->rmdir( $subfolder );
516
  }
517
- }
518
-
519
- // Check for supported sets.
520
- $is_icomoon = file_exists( $new_path . 'selection.json' );
521
- $is_fontello = file_exists( $new_path . 'config.json' );
522
-
523
- // Show an error if we don't have a supported icon set.
524
- if ( ! $is_icomoon && ! $is_fontello ) {
525
- $filesystem->rmdir( $new_path, true );
526
- self::add_error( __( "Error! Please upload an icon set from either Icomoon or Fontello.", 'fl-builder' ) );
527
- return;
528
- }
529
-
530
- // Enable the new set.
531
- if ( is_array( $enabled_icons ) ) {
532
- $key = FLBuilderIcons::get_key_from_path( $new_path );
533
- $enabled_icons[] = $key;
534
- }
535
- }
536
-
537
- // Update the enabled sets again in case they have changed.
538
- self::update_enabled_icons( $enabled_icons );
539
- }
540
- }
541
-
542
- /**
543
  * Updates the enabled icons in the database.
544
  *
545
- * @since 1.5.0
546
- * @return void
547
- */
 
548
  static private function update_enabled_icons( $enabled_icons = array() )
549
  {
550
  if ( is_network_admin() ) {
551
- update_site_option( '_fl_builder_enabled_icons', $enabled_icons );
552
- update_option( '_fl_builder_enabled_icons', $enabled_icons );
553
- }
554
- else if ( self::multisite_support() && ! isset( $_POST['fl-override-ms'] ) ) {
555
- delete_option( '_fl_builder_enabled_icons' );
556
- }
557
- else {
558
- update_option( '_fl_builder_enabled_icons', $enabled_icons );
559
- }
560
  }
561
-
562
- /**
563
  * Saves the editing capability.
564
  *
565
- * @since 1.5.0
566
- * @return void
567
- */
 
568
  static private function save_editing_capability()
569
  {
570
- if ( isset( $_POST['fl-editing-nonce'] ) && wp_verify_nonce( $_POST['fl-editing-nonce'], 'editing' ) ) {
571
-
572
- $capability = sanitize_text_field( $_POST['fl-editing-capability'] );
573
-
574
- if ( is_network_admin() ) {
575
- update_site_option( '_fl_builder_editing_capability', $capability );
576
- }
577
- else if ( self::multisite_support() && ! isset( $_POST['fl-override-ms'] ) ) {
578
- delete_option( '_fl_builder_editing_capability' );
579
- }
580
- else {
581
- update_option( '_fl_builder_editing_capability', $capability );
582
- }
583
- }
584
- }
585
-
586
- /**
587
  * Saves the branding settings.
588
  *
589
- * @since 1.5.0
590
- * @return void
591
- */
 
592
  static private function save_branding()
593
  {
594
- if ( isset( $_POST['fl-branding-nonce'] ) && wp_verify_nonce( $_POST['fl-branding-nonce'], 'branding' ) ) {
595
-
596
- $branding = wp_kses_post( $_POST['fl-branding'] );
597
- $branding_icon = sanitize_text_field( $_POST['fl-branding-icon'] );
598
-
599
- if ( is_network_admin() ) {
600
  update_site_option( '_fl_builder_branding', $branding );
601
  update_site_option( '_fl_builder_branding_icon', $branding_icon );
602
- }
603
- else {
604
  update_option( '_fl_builder_branding', $branding );
605
  update_option( '_fl_builder_branding_icon', $branding_icon );
606
- }
607
- }
608
- }
609
-
610
- /**
611
  * Saves the help button settings.
612
  *
613
- * @since 1.5.0
614
- * @return void
615
- */
 
616
  static private function save_help_button()
617
  {
618
- if ( isset( $_POST['fl-help-button-nonce'] ) && wp_verify_nonce( $_POST['fl-help-button-nonce'], 'help-button' ) ) {
619
-
620
- $settings = FLBuilderModel::get_help_button_defaults();
621
- $settings['enabled'] = isset( $_POST['fl-help-button-enabled'] ) ? true : false;
622
- $settings['tour'] = isset( $_POST['fl-help-tour-enabled'] ) ? true : false;
623
- $settings['video'] = isset( $_POST['fl-help-video-enabled'] ) ? true : false;
624
- $settings['knowledge_base'] = isset( $_POST['fl-knowledge-base-enabled'] ) ? true : false;
625
- $settings['forums'] = isset( $_POST['fl-forums-enabled'] ) ? true : false;
626
-
627
- // Disable everything if the main button is disabled.
628
- if ( ! $settings['enabled'] ) {
629
- $settings['tour'] = false;
630
- $settings['video'] = false;
631
- $settings['knowledge_base'] = false;
632
- $settings['forums'] = false;
633
- }
634
-
635
- // Clean the video embed.
636
- $video_embed = wp_kses( $_POST['fl-help-video-embed'], array(
637
- 'iframe' => array(
638
- 'src' => array(),
639
- 'frameborder' => array(),
640
- 'webkitallowfullscreen' => array(),
641
- 'mozallowfullscreen' => array(),
642
- 'allowfullscreen' => array()
643
- )
644
- ));
645
-
646
- // Save the video embed.
647
- if ( ! empty( $video_embed ) && ! stristr( $video_embed, 'iframe' ) ) {
648
- self::add_error( __( "Error! Please enter an iframe for the video embed code.", 'fl-builder' ) );
649
- }
650
- else if ( ! empty( $video_embed ) ) {
651
- $settings['video_embed'] = $video_embed;
652
- }
653
-
654
- // Save the knowledge base URL.
655
- if ( ! empty( $_POST['fl-knowledge-base-url'] ) ) {
656
- $settings['knowledge_base_url'] = sanitize_text_field( $_POST['fl-knowledge-base-url'] );
657
- }
658
-
659
- // Save the forums URL.
660
- if ( ! empty( $_POST['fl-forums-url'] ) ) {
661
- $settings['forums_url'] = sanitize_text_field( $_POST['fl-forums-url'] );
662
- }
663
-
664
- // Make sure we have at least one help feature enabled.
665
- if ( $settings['enabled'] && ! $settings['tour'] && ! $settings['video'] && ! $settings['knowledge_base'] && ! $settings['forums'] ) {
666
- self::add_error( __( "Error! You must have at least one feature of the help button enabled.", 'fl-builder' ) );
667
- return;
668
- }
669
-
670
- // Save the settings.
671
- if ( is_network_admin() ) {
672
  update_site_option( '_fl_builder_help_button', $settings );
673
- }
674
- else {
675
  update_option( '_fl_builder_help_button', $settings );
676
- }
677
- }
678
- }
679
 
680
- /**
681
  * Clears the builder cache.
682
  *
683
  * @since 1.5.3
684
- * @return void
685
- */
 
686
  static private function clear_cache()
687
  {
688
- if ( ! current_user_can( 'delete_plugins' ) ) {
689
- return;
690
- }
691
- else if ( isset( $_POST['fl-cache-nonce'] ) && wp_verify_nonce( $_POST['fl-cache-nonce'], 'cache' ) ) {
692
- if ( is_network_admin() ) {
693
- self::clear_cache_for_all_sites();
694
- }
695
- else {
696
- FLBuilderModel::delete_all_asset_cache();
697
- }
698
- }
699
- }
700
 
701
- /**
702
  * Clears the builder cache for all sites on a network.
703
  *
704
  * @since 1.5.3
705
- * @return void
706
- */
 
707
  static private function clear_cache_for_all_sites()
708
  {
709
- global $blog_id;
710
- global $wpdb;
711
-
712
- // Save the original blog id.
713
- $original_blog_id = $blog_id;
714
-
715
- // Get all blog ids.
716
- $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
717
-
718
- // Loop through the blog ids and clear the cache.
719
- foreach ( $blog_ids as $id ) {
720
- switch_to_blog( $id );
721
- FLBuilderModel::delete_all_asset_cache();
722
- }
723
-
724
- // Revert to the original blog.
725
- switch_to_blog( $original_blog_id );
726
- }
727
 
728
- /**
729
  * Uninstalls the builder and all of its data.
730
  *
731
- * @since 1.5.0
732
- * @return void
733
- */
 
734
  static private function uninstall()
735
  {
736
- if ( ! current_user_can( 'delete_plugins' ) ) {
737
- return;
738
- }
739
- else if ( isset( $_POST['fl-uninstall'] ) && wp_verify_nonce( $_POST['fl-uninstall'], 'uninstall' ) ) {
740
- if ( is_multisite() && class_exists( 'FLBuilderMultisite' ) ) {
741
- FLBuilderMultisite::uninstall();
742
- }
743
- else {
744
- FLBuilderAdmin::uninstall();
745
- }
746
- }
747
- }
748
  }
3
  /**
4
  * Handles logic for the admin settings page.
5
  *
6
+ * @since 1.0
7
  */
8
  final class FLBuilderAdminSettings {
9
 
11
  * Holds any errors that may arise from
12
  * saving admin settings.
13
  *
14
+ * @since 1.0
15
  * @var array $errors
16
  */
17
  static public $errors = array();
18
+
19
+ /**
20
  * Adds the admin menu and enqueues CSS/JS if we are on
21
  * the builder admin settings page.
22
  *
23
+ * @since 1.0
24
+ * @return void
25
+ */
26
+ static public function init()
27
+ {
28
+ add_action( 'admin_menu', 'FLBuilderAdminSettings::menu' );
29
+
30
+ if ( isset( $_REQUEST['page'] ) && 'fl-builder-settings' == $_REQUEST['page'] ) {
31
+ add_action( 'admin_enqueue_scripts', 'FLBuilderAdminSettings::styles_scripts' );
32
+ self::save();
33
+ }
34
+ }
35
+
36
+ /**
37
  * Enqueues the needed CSS/JS for the builder's admin settings page.
38
  *
39
+ * @since 1.0
40
+ * @return void
41
+ */
42
  static public function styles_scripts()
43
  {
44
+ // Styles
45
  wp_enqueue_style( 'fl-builder-admin-settings', FL_BUILDER_URL . 'css/fl-builder-admin-settings.css', array(), FL_BUILDER_VERSION );
46
 
47
  // Scripts
50
  // Media Uploader
51
  wp_enqueue_media();
52
  }
53
+
54
+ /**
55
  * Renders the admin settings menu.
56
  *
57
+ * @since 1.0
58
+ * @return void
59
+ */
60
  static public function menu()
61
  {
62
+ if ( current_user_can( 'delete_plugins' ) ) {
63
+
64
+ $title = FLBuilderModel::get_branding();
65
+ $cap = 'delete_plugins';
66
+ $slug = 'fl-builder-settings';
67
+ $func = 'FLBuilderAdminSettings::render';
68
+
69
+ add_submenu_page( 'options-general.php', $title, $title, $cap, $slug, $func );
70
  }
71
  }
72
+
73
+ /**
74
  * Renders the admin settings.
75
  *
76
+ * @since 1.0
77
+ * @return void
78
+ */
79
  static public function render()
80
  {
81
+ include FL_BUILDER_DIR . 'includes/admin-settings-js-config.php';
82
  include FL_BUILDER_DIR . 'includes/admin-settings.php';
83
  }
84
+
85
+ /**
86
  * Renders the page class for network installs and single site installs.
87
  *
88
+ * @since 1.0
89
+ * @return void
90
+ */
91
  static public function render_page_class()
92
  {
93
  if ( self::multisite_support() ) {
97
  echo 'fl-settings-single-install';
98
  }
99
  }
100
+
101
+ /**
102
  * Renders the admin settings page heading.
103
  *
104
+ * @since 1.0
105
+ * @return void
106
+ */
107
  static public function render_page_heading()
108
  {
109
  $icon = FLBuilderModel::get_branding_icon();
115
 
116
  echo '<span>' . sprintf( _x( '%s Settings', '%s stands for custom branded "Page Builder" name.', 'fl-builder' ), FLBuilderModel::get_branding() ) . '</span>';
117
  }
118
+
119
+ /**
120
  * Renders the update message.
121
  *
122
+ * @since 1.0
123
+ * @return void
124
+ */
125
  static public function render_update_message()
126
  {
127
  if ( ! empty( self::$errors ) ) {
133
  echo '<div class="updated"><p>' . __( 'Settings updated!', 'fl-builder' ) . '</p></div>';
134
  }
135
  }
136
+
137
+ /**
138
  * Renders the nav items for the admin settings menu.
139
  *
140
+ * @since 1.0
141
+ * @return void
142
+ */
143
  static public function render_nav_items()
144
  {
145
  $item_data = array(
146
  'license' => array(
147
+ 'title' => __( 'License', 'fl-builder' ),
148
  'show' => FL_BUILDER_LITE !== true && ( is_network_admin() || ! self::multisite_support() )
149
  ),
150
  'upgrade' => array(
151
+ 'title' => __( 'Upgrade', 'fl-builder' ),
152
  'show' => FL_BUILDER_LITE === true
153
  ),
154
  'modules' => array(
155
+ 'title' => __( 'Modules', 'fl-builder' ),
156
  'show' => true
157
  ),
158
  'templates' => array(
159
+ 'title' => __( 'Templates', 'fl-builder' ),
160
  'show' => FL_BUILDER_LITE !== true
161
  ),
162
  'post-types' => array(
163
+ 'title' => __( 'Post Types', 'fl-builder' ),
164
  'show' => true
165
  ),
166
  'icons' => array(
167
+ 'title' => __( 'Icons', 'fl-builder' ),
168
  'show' => FL_BUILDER_LITE !== true
169
  ),
170
  'editing' => array(
171
+ 'title' => __( 'Editing', 'fl-builder' ),
172
  'show' => true
173
  ),
174
  'branding' => array(
175
+ 'title' => __( 'Branding', 'fl-builder' ),
176
  'show' => self::has_support( 'branding' ) && ( is_network_admin() || ! self::multisite_support() )
177
  ),
178
  'help-button' => array(
179
+ 'title' => __( 'Help Button', 'fl-builder' ),
180
  'show' => self::has_support( 'help-button' ) && ( is_network_admin() || ! self::multisite_support() )
181
  ),
182
  'cache' => array(
183
+ 'title' => __( 'Cache', 'fl-builder' ),
184
  'show' => true
185
  ),
186
  'uninstall' => array(
187
+ 'title' => __( 'Uninstall', 'fl-builder' ),
188
  'show' => is_network_admin() || ! self::multisite_support()
189
  ),
190
  );
195
  }
196
  }
197
  }
198
+
199
+ /**
200
  * Renders the admin settings forms.
201
  *
202
+ * @since 1.0
203
+ * @return void
204
+ */
205
  static public function render_forms()
206
  {
207
  // License
210
  }
211
 
212
  // Upgrade
213
+ if ( FL_BUILDER_LITE === true ) {
214
  self::render_form( 'upgrade' );
215
  }
216
 
241
  // Uninstall
242
  self::render_form( 'uninstall' );
243
  }
244
+
245
+ /**
246
  * Renders an admin settings form based on the type specified.
247
  *
248
+ * @since 1.0
249
  * @param string $type The type of form to render.
250
+ * @return void
251
+ */
252
  static public function render_form( $type )
253
  {
254
  if ( self::has_support( $type ) ) {
255
  include FL_BUILDER_DIR . 'includes/admin-settings-' . $type . '.php';
256
  }
257
  }
258
+
259
+ /**
260
  * Renders the action for a form.
261
  *
262
+ * @since 1.0
263
  * @param string $type The type of form being rendered.
264
+ * @return void
265
+ */
266
  static public function render_form_action( $type = '' )
267
  {
268
  if ( is_network_admin() ) {
272
  echo admin_url( '/options-general.php?page=fl-builder-settings#' . $type );
273
  }
274
  }
275
+
276
+ /**
277
  * Returns the action for a form.
278
  *
279
+ * @since 1.0
280
  * @param string $type The type of form being rendered.
281
+ * @return string The URL for the form action.
282
+ */
283
  static public function get_form_action( $type = '' )
284
  {
285
  if ( is_network_admin() ) {
289
  return admin_url( '/options-general.php?page=fl-builder-settings#' . $type );
290
  }
291
  }
292
+
293
+ /**
294
  * Checks to see if a settings form is supported.
295
  *
296
+ * @since 1.0
297
  * @param string $type The type of form to check.
298
+ * @return bool
299
+ */
300
  static public function has_support( $type )
301
  {
302
  return file_exists( FL_BUILDER_DIR . 'includes/admin-settings-' . $type . '.php' );
303
  }
304
+
305
+ /**
306
  * Checks to see if multisite is supported.
307
  *
308
+ * @since 1.0
309
+ * @return bool
310
+ */
311
  static public function multisite_support()
312
  {
313
  return is_multisite() && class_exists( 'FLBuilderMultisiteSettings' );
314
  }
315
+
316
+ /**
317
  * Adds an error message to be rendered.
318
  *
319
+ * @since 1.0
320
  * @param string $message The error message to add.
321
+ * @return void
322
+ */
323
  static public function add_error( $message )
324
  {
325
  self::$errors[] = $message;
326
  }
327
+
328
+ /**
329
  * Saves the admin settings.
330
  *
331
+ * @since 1.0
332
+ * @return void
333
+ */
334
  static public function save()
335
  {
336
+ // Only admins can save settings.
337
+ if(!current_user_can('delete_plugins')) {
338
+ return;
339
+ }
340
+
341
  self::save_enabled_modules();
342
  self::save_enabled_templates();
343
  self::save_enabled_post_types();
348
  self::clear_cache();
349
  self::uninstall();
350
  }
351
+
352
+ /**
353
  * Saves the enabled modules.
354
  *
355
+ * @since 1.0
356
+ * @access private
357
+ * @return void
358
+ */
359
  static private function save_enabled_modules()
360
  {
361
+ if ( isset( $_POST['fl-modules-nonce'] ) && wp_verify_nonce( $_POST['fl-modules-nonce'], 'modules' ) ) {
362
+
363
+ $modules = array();
364
+
365
+ if ( is_array( $_POST['fl-modules'] ) ) {
366
+ $modules = array_map( 'sanitize_text_field', $_POST['fl-modules'] );
367
+ }
368
+
369
+ if ( is_network_admin() ) {
370
+ update_site_option( '_fl_builder_enabled_modules', $modules );
371
+ }
372
+ else if ( self::multisite_support() && ! isset( $_POST['fl-override-ms'] ) ) {
373
+ delete_option( '_fl_builder_enabled_modules' );
374
+ }
375
+ else {
376
+ update_option( '_fl_builder_enabled_modules', $modules );
377
+ }
378
+ }
379
+ }
380
+
381
+ /**
382
  * Saves the enabled templates.
383
  *
384
+ * @since 1.0
385
+ * @access private
386
+ * @return void
387
+ */
388
  static private function save_enabled_templates()
389
  {
390
+ if ( isset( $_POST['fl-templates-nonce'] ) && wp_verify_nonce( $_POST['fl-templates-nonce'], 'templates' ) ) {
391
+
392
+ $enabled_templates = sanitize_text_field( $_POST['fl-template-settings'] );
393
+
394
+ if ( is_network_admin() ) {
395
+ update_site_option( '_fl_builder_enabled_templates', $enabled_templates );
396
+ }
397
+ else if ( self::multisite_support() && ! isset( $_POST['fl-override-ms'] ) ) {
398
+ delete_option( '_fl_builder_enabled_templates' );
399
+ }
400
+ else {
401
+ update_option( '_fl_builder_enabled_templates', $enabled_templates );
402
+ }
403
+ }
404
+ }
405
+
406
+ /**
407
  * Saves the enabled post types.
408
  *
409
+ * @since 1.0
410
+ * @access private
411
+ * @return void
412
+ */
413
  static private function save_enabled_post_types()
414
  {
415
+ if ( isset( $_POST['fl-post-types-nonce'] ) && wp_verify_nonce( $_POST['fl-post-types-nonce'], 'post-types' ) ) {
416
+
417
+ if ( is_network_admin() ) {
418
+
419
+ $post_types = sanitize_text_field( $_POST['fl-post-types'] );
420
+ $post_types = str_replace( ' ', '', $post_types );
421
+ $post_types = explode( ',', $post_types );
422
+
423
+ update_site_option( '_fl_builder_post_types', $post_types );
424
+ }
425
+ else if ( self::multisite_support() && ! isset($_POST['fl-override-ms'] ) ) {
426
+ delete_option( '_fl_builder_post_types' );
427
+ }
428
+ else {
429
+
430
+ $post_types = array();
431
+
432
+ if ( is_array( $_POST['fl-post-types'] ) ) {
433
+ $post_types = array_map( 'sanitize_text_field', $_POST['fl-post-types'] );
434
+ }
435
+
436
+ update_option( '_fl_builder_post_types', $post_types );
437
+ }
438
+ }
439
+ }
440
+
441
+ /**
442
  * Saves the enabled icons.
443
  *
444
+ * @since 1.0
445
+ * @access private
446
+ * @return void
447
+ */
448
  static private function save_enabled_icons()
449
  {
450
+ if ( isset( $_POST['fl-icons-nonce'] ) && wp_verify_nonce( $_POST['fl-icons-nonce'], 'icons' ) ) {
451
 
452
  // Make sure we have at least one enabled icon set.
453
  if ( ! isset( $_POST['fl-enabled-icons'] ) && empty( $_POST['fl-new-icon-set'] ) ) {
454
  self::add_error( __( "Error! You must have at least one icon set enabled.", 'fl-builder' ) );
455
+ return;
456
  }
457
+
458
+ $filesystem = FLBuilderUtils::get_filesystem();
459
  $enabled_icons = array();
460
 
461
  // Sanitize the enabled icons.
462
  if ( isset( $_POST['fl-enabled-icons'] ) && is_array( $_POST['fl-enabled-icons'] ) ) {
463
+ $enabled_icons = array_map( 'sanitize_text_field', $_POST['fl-enabled-icons'] );
464
+ }
465
+
466
+ // Update the enabled sets.
467
+ self::update_enabled_icons( $enabled_icons );
468
+
469
+ // Delete a set?
470
+ if ( ! empty( $_POST['fl-delete-icon-set'] ) ) {
471
+
472
+ $sets = FLBuilderIcons::get_sets();
473
+ $key = sanitize_text_field( $_POST['fl-delete-icon-set'] );
474
+ $index = array_search( $key, $enabled_icons );
475
+
476
+ if ( false !== $index ) {
477
+ unset( $enabled_icons[ $index ] );
478
+ }
479
+ if ( isset( $sets[ $key ] ) ) {
480
+ $filesystem->rmdir( $sets[ $key ]['path'], true );
481
+ FLBuilderIcons::remove_set( $key );
482
+ }
483
+ }
484
+
485
+ // Upload a new set?
486
+ if ( ! empty( $_POST['fl-new-icon-set'] ) ) {
487
 
488
+ $dir = FLBuilderModel::get_cache_dir( 'icons' );
489
+ $id = (int) $_POST['fl-new-icon-set'];
490
+ $path = get_attached_file( $id );
491
+ $new_path = $dir['path'] . 'icon-' . time() . '/';
492
+ $unzipped = unzip_file( $path, $new_path );
493
+
494
+ // Unzip failed.
495
+ if ( ! $unzipped ) {
496
+ self::add_error( __( "Error! Could not unzip file.", 'fl-builder' ) );
497
+ return;
498
+ }
499
+
500
+ // Move files if unzipped into a subfolder.
501
+ $files = $filesystem->dirlist( $new_path );
502
+
503
+ if ( 1 == count( $files ) ) {
504
 
505
  $values = array_values( $files );
506
  $subfolder_info = array_shift( $values );
507
+ $subfolder = $new_path . $subfolder_info['name'] . '/';
508
 
509
  if ( file_exists( $subfolder ) && is_dir( $subfolder ) ) {
510
 
511
+ $files = $filesystem->dirlist( $subfolder );
512
+
513
+ if ( $files ) {
514
+ foreach ( $files as $file ) {
515
+ $filesystem->move( $subfolder . $file['name'], $new_path . $file['name'] );
516
+ }
517
+ }
518
+
519
+ $filesystem->rmdir( $subfolder );
520
  }
521
+ }
522
+
523
+ // Check for supported sets.
524
+ $is_icomoon = file_exists( $new_path . 'selection.json' );
525
+ $is_fontello = file_exists( $new_path . 'config.json' );
526
+
527
+ // Show an error if we don't have a supported icon set.
528
+ if ( ! $is_icomoon && ! $is_fontello ) {
529
+ $filesystem->rmdir( $new_path, true );
530
+ self::add_error( __( "Error! Please upload an icon set from either Icomoon or Fontello.", 'fl-builder' ) );
531
+ return;
532
+ }
533
+
534
+ // Enable the new set.
535
+ if ( is_array( $enabled_icons ) ) {
536
+ $key = FLBuilderIcons::get_key_from_path( $new_path );
537
+ $enabled_icons[] = $key;
538
+ }
539
+ }
540
+
541
+ // Update the enabled sets again in case they have changed.
542
+ self::update_enabled_icons( $enabled_icons );
543
+ }
544
+ }
545
+
546
+ /**
547
  * Updates the enabled icons in the database.
548
  *
549
+ * @since 1.0
550
+ * @access private
551
+ * @return void
552
+ */
553
  static private function update_enabled_icons( $enabled_icons = array() )
554
  {
555
  if ( is_network_admin() ) {
556
+ update_site_option( '_fl_builder_enabled_icons', $enabled_icons );
557
+ update_option( '_fl_builder_enabled_icons', $enabled_icons );
558
+ }
559
+ else if ( self::multisite_support() && ! isset( $_POST['fl-override-ms'] ) ) {
560
+ delete_option( '_fl_builder_enabled_icons' );
561
+ }
562
+ else {
563
+ update_option( '_fl_builder_enabled_icons', $enabled_icons );
564
+ }
565
  }
566
+
567
+ /**
568
  * Saves the editing capability.
569
  *
570
+ * @since 1.0
571
+ * @access private
572
+ * @return void
573
+ */
574
  static private function save_editing_capability()
575
  {
576
+ if ( isset( $_POST['fl-editing-nonce'] ) && wp_verify_nonce( $_POST['fl-editing-nonce'], 'editing' ) ) {
577
+
578
+ $capability = sanitize_text_field( $_POST['fl-editing-capability'] );
579
+
580
+ if ( is_network_admin() ) {
581
+ update_site_option( '_fl_builder_editing_capability', $capability );
582
+ }
583
+ else if ( self::multisite_support() && ! isset( $_POST['fl-override-ms'] ) ) {
584
+ delete_option( '_fl_builder_editing_capability' );
585
+ }
586
+ else {
587
+ update_option( '_fl_builder_editing_capability', $capability );
588
+ }
589
+ }
590
+ }
591
+
592
+ /**
593
  * Saves the branding settings.
594
  *
595
+ * @since 1.0
596
+ * @access private
597
+ * @return void
598
+ */
599
  static private function save_branding()
600
  {
601
+ if ( isset( $_POST['fl-branding-nonce'] ) && wp_verify_nonce( $_POST['fl-branding-nonce'], 'branding' ) ) {
602
+
603
+ $branding = wp_kses_post( $_POST['fl-branding'] );
604
+ $branding_icon = sanitize_text_field( $_POST['fl-branding-icon'] );
605
+
606
+ if ( is_network_admin() ) {
607
  update_site_option( '_fl_builder_branding', $branding );
608
  update_site_option( '_fl_builder_branding_icon', $branding_icon );
609
+ }
610
+ else {
611
  update_option( '_fl_builder_branding', $branding );
612
  update_option( '_fl_builder_branding_icon', $branding_icon );
613
+ }
614
+ }
615
+ }
616
+
617
+ /**
618
  * Saves the help button settings.
619
  *
620
+ * @since 1.0
621
+ * @access private
622
+ * @return void
623
+ */
624
  static private function save_help_button()
625
  {
626
+ if ( isset( $_POST['fl-help-button-nonce'] ) && wp_verify_nonce( $_POST['fl-help-button-nonce'], 'help-button' ) ) {
627
+
628
+ $settings = FLBuilderModel::get_help_button_defaults();
629
+ $settings['enabled'] = isset( $_POST['fl-help-button-enabled'] ) ? true : false;
630
+ $settings['tour'] = isset( $_POST['fl-help-tour-enabled'] ) ? true : false;
631
+ $settings['video'] = isset( $_POST['fl-help-video-enabled'] ) ? true : false;
632
+ $settings['knowledge_base'] = isset( $_POST['fl-knowledge-base-enabled'] ) ? true : false;
633
+ $settings['forums'] = isset( $_POST['fl-forums-enabled'] ) ? true : false;
634
+
635
+ // Disable everything if the main button is disabled.
636
+ if ( ! $settings['enabled'] ) {
637
+ $settings['tour'] = false;
638
+ $settings['video'] = false;
639
+ $settings['knowledge_base'] = false;
640
+ $settings['forums'] = false;
641
+ }
642
+
643
+ // Clean the video embed.
644
+ $video_embed = wp_kses( $_POST['fl-help-video-embed'], array(
645
+ 'iframe' => array(
646
+ 'src' => array(),
647
+ 'frameborder' => array(),
648
+ 'webkitallowfullscreen' => array(),
649
+ 'mozallowfullscreen' => array(),
650
+ 'allowfullscreen' => array()
651
+ )
652
+ ));
653
+
654
+ // Save the video embed.
655
+ if ( ! empty( $video_embed ) && ! stristr( $video_embed, 'iframe' ) ) {
656
+ self::add_error( __( "Error! Please enter an iframe for the video embed code.", 'fl-builder' ) );
657
+ }
658
+ else if ( ! empty( $video_embed ) ) {
659
+ $settings['video_embed'] = $video_embed;
660
+ }
661
+
662
+ // Save the knowledge base URL.
663
+ if ( ! empty( $_POST['fl-knowledge-base-url'] ) ) {
664
+ $settings['knowledge_base_url'] = sanitize_text_field( $_POST['fl-knowledge-base-url'] );
665
+ }
666
+
667
+ // Save the forums URL.
668
+ if ( ! empty( $_POST['fl-forums-url'] ) ) {
669
+ $settings['forums_url'] = sanitize_text_field( $_POST['fl-forums-url'] );
670
+ }
671
+
672
+ // Make sure we have at least one help feature enabled.
673
+ if ( $settings['enabled'] && ! $settings['tour'] && ! $settings['video'] && ! $settings['knowledge_base'] && ! $settings['forums'] ) {
674
+ self::add_error( __( "Error! You must have at least one feature of the help button enabled.", 'fl-builder' ) );
675
+ return;
676
+ }
677
+
678
+ // Save the settings.
679
+ if ( is_network_admin() ) {
680
  update_site_option( '_fl_builder_help_button', $settings );
681
+ }
682
+ else {
683
  update_option( '_fl_builder_help_button', $settings );
684
+ }
685
+ }
686
+ }
687
 
688
+ /**
689
  * Clears the builder cache.
690
  *
691
  * @since 1.5.3
692
+ * @access private
693
+ * @return void
694
+ */
695
  static private function clear_cache()
696
  {
697
+ if ( ! current_user_can( 'delete_plugins' ) ) {
698
+ return;
699
+ }
700
+ else if ( isset( $_POST['fl-cache-nonce'] ) && wp_verify_nonce( $_POST['fl-cache-nonce'], 'cache' ) ) {
701
+ if ( is_network_admin() ) {
702
+ self::clear_cache_for_all_sites();
703
+ }
704
+ else {
705
+ FLBuilderModel::delete_all_asset_cache();
706
+ }
707
+ }
708
+ }
709
 
710
+ /**
711
  * Clears the builder cache for all sites on a network.
712
  *
713
  * @since 1.5.3
714
+ * @access private
715
+ * @return void
716
+ */
717
  static private function clear_cache_for_all_sites()
718
  {
719
+ global $blog_id;
720
+ global $wpdb;
721
+
722
+ // Save the original blog id.
723
+ $original_blog_id = $blog_id;
724
+
725
+ // Get all blog ids.
726
+ $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
727
+
728
+ // Loop through the blog ids and clear the cache.
729
+ foreach ( $blog_ids as $id ) {
730
+ switch_to_blog( $id );
731
+ FLBuilderModel::delete_all_asset_cache();
732
+ }
733
+
734
+ // Revert to the original blog.
735
+ switch_to_blog( $original_blog_id );
736
+ }
737
 
738
+ /**
739
  * Uninstalls the builder and all of its data.
740
  *
741
+ * @since 1.0
742
+ * @access private
743
+ * @return void
744
+ */
745
  static private function uninstall()
746
  {
747
+ if ( ! current_user_can( 'delete_plugins' ) ) {
748
+ return;
749
+ }
750
+ else if ( isset( $_POST['fl-uninstall'] ) && wp_verify_nonce( $_POST['fl-uninstall'], 'uninstall' ) ) {
751
+ if ( is_multisite() && class_exists( 'FLBuilderMultisite' ) ) {
752
+ FLBuilderMultisite::uninstall();
753
+ }
754
+ else {
755
+ FLBuilderAdmin::uninstall();
756
+ }
757
+ }
758
+ }
759
  }
classes/class-fl-builder-admin.php CHANGED
@@ -3,214 +3,261 @@
3
  /**
4
  * Main builder admin class.
5
  *
6
- * @class FLBuilderAdmin
7
  */
8
  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
- }
33
- else {
34
- self::install();
35
- }
36
- }
37
- // This version doesn't have multisite support.
38
- else {
39
- $url = FLBuilderModel::get_upgrade_url( array( 'utm_source' => 'external', 'utm_medium' => 'builder', 'utm_campaign' => 'no-multisite-support' ) );
 
 
 
 
 
40
  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="' . $url . '" target="_blank"' ) );
41
- }
42
- }
43
- // No multisite, standard install.
44
- else {
45
- self::install();
46
- }
47
- }
48
- // Wrong WordPress version.
49
- else {
50
- 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'));
51
- }
52
-
53
- // Success! Trigger the activation notice.
54
- if(FL_BUILDER_LITE !== true) {
55
- update_site_option('_fl_builder_activation_admin_notice', true);
56
- }
57
- }
58
 
59
  /**
60
- * @method show_activate_error
61
- */
62
- static public function show_activate_error($message)
63
- {
64
- deactivate_plugins( FLBuilderModel::plugin_basename(), false, is_network_admin() );
 
 
 
 
 
65
 
66
- die( $message );
67
- }
68
 
69
  /**
70
- * @method show_activate_notice
71
- */
72
- static public function show_activate_notice()
73
- {
74
- $notice = get_site_option('_fl_builder_activation_admin_notice');
75
-
76
- if($notice) {
77
- add_action('admin_notices', 'FLBuilderAdmin::activate_notice');
78
- add_action('network_admin_notices', 'FLBuilderAdmin::activate_notice');
79
- delete_site_option('_fl_builder_activation_admin_notice');
80
- }
81
- }
 
 
 
82
 
83
  /**
84
- * @method activate_notice
85
- */
86
- static public function activate_notice()
87
- {
88
- if ( class_exists('FLBuilderMultisiteSettings') && is_multisite() && current_user_can( 'manage_network_plugins' ) ) {
89
- $href = esc_url( network_admin_url( '/settings.php?page=fl-builder-multisite-settings#license' ) );
90
- }
91
- else {
92
- $href = esc_url( admin_url( '/options-general.php?page=fl-builder-settings#license' ) );
93
- }
94
-
95
- echo '<div class="updated" style="background: #d3ebc1;">';
 
 
 
96
  echo '<p><strong>' . sprintf( __( 'Page Builder activated! <a%s>Click here</a> to enable remote updates.', 'fl-builder' ), ' href="' . esc_url( $href ) . '"' ) . '</strong></p>';
97
- echo '</div>';
98
- }
 
 
 
 
 
 
 
 
 
99
 
100
  /**
101
- * @method install
102
- */
103
- static public function install() {}
 
 
 
 
 
 
104
 
105
  /**
106
- * @method uninstall
107
- */
108
- static public function uninstall()
109
- {
110
- FLBuilderModel::uninstall_database();
111
- }
112
-
113
- /**
114
- * @method init
115
- */
116
- static public function init()
117
- {
118
- self::init_classes();
119
- self::init_settings();
120
- self::init_multisite();
121
- self::init_templates();
122
- self::show_activate_notice();
123
- }
124
-
125
- /**
126
- * @method init_classes
127
- */
128
- static public function init_classes()
129
- {
130
- $templates_class = FL_BUILDER_DIR . 'classes/class-fl-builder-templates.php';
131
- $ms_class = FL_BUILDER_DIR . 'classes/class-fl-builder-multisite.php';
132
- $ms_settings_class = FL_BUILDER_DIR . 'classes/class-fl-builder-multisite-settings.php';
133
-
134
- if(file_exists($templates_class)) {
135
- require_once $templates_class;
136
- }
137
- if(is_multisite()) {
138
-
139
- if(file_exists($ms_class)) {
140
- require_once $ms_class;
141
- }
142
- if(file_exists($ms_settings_class)) {
143
- require_once $ms_settings_class;
144
- }
145
- }
146
-
147
- require_once FL_BUILDER_DIR . 'classes/class-fl-builder-admin-settings.php';
148
- }
149
-
150
- /**
151
- * @method init_settings
152
- */
153
- static public function init_settings()
154
- {
155
- FLBuilderAdminSettings::init();
156
- }
157
-
158
- /**
159
- * @method init_multisite
160
- */
161
- static public function init_multisite()
162
- {
163
- if(is_multisite()) {
164
-
165
- if(class_exists('FLBuilderMultisite')) {
166
- FLBuilderMultisite::init();
167
- }
168
- if(class_exists('FLBuilderMultisiteSettings')) {
169
- FLBuilderMultisiteSettings::init();
170
- }
171
- }
172
- }
173
-
174
- /**
175
- * @method init_templates
176
- */
177
- static public function init_templates()
178
- {
179
- if(class_exists('FLBuilderTemplates')) {
180
- FLBuilderTemplates::init();
181
- }
182
- }
183
 
184
  /**
185
- * @method render_plugin_action_links
186
- */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
  static public function render_plugin_action_links($actions)
188
- {
189
- if(FL_BUILDER_LITE === true) {
190
- $url = FLBuilderModel::get_upgrade_url( array( 'utm_source' => 'external', 'utm_medium' => 'builder', 'utm_campaign' => 'plugins-page' ) );
191
  $actions[] = '<a href="' . $url . '" style="color:#3db634;" target="_blank">' . _x( 'Upgrade', 'Plugin action link label.', 'fl-builder' ) . '</a>';
192
- }
193
 
194
- return $actions;
195
- }
196
 
197
  /**
198
- * @method white_label_plugins_page
199
- */
 
 
 
 
200
  static public function white_label_plugins_page($plugins)
201
- {
202
- $default = __( 'Page Builder', 'fl-builder' );
203
- $branding = FLBuilderModel::get_branding();
204
- $key = FLBuilderModel::plugin_basename();
205
-
206
- if ( isset( $plugins[ $key ] ) && $branding != $default ) {
207
- $plugins[ $key ]['Name'] = $branding;
208
- $plugins[ $key ]['Title'] = $branding;
209
- $plugins[ $key ]['Author'] = '';
210
- $plugins[ $key ]['AuthorName'] = '';
211
- $plugins[ $key ]['PluginURI'] = '';
212
- }
213
-
214
- return $plugins;
215
- }
216
  }
3
  /**
4
  * Main builder admin class.
5
  *
6
+ * @since 1.0
7
  */
8
  final class FLBuilderAdmin {
9
 
10
  /**
11
+ * Called on plugin activation and checks to see if the correct
12
+ * WordPress version is installed and multisite is supported. If
13
+ * all checks are passed the install method is called.
14
+ *
15
+ * @since 1.0
16
+ * @return void
17
+ */
18
+ static public function activate()
19
+ {
20
+ global $wp_version;
21
+
22
+ // Check for WordPress 3.5 and above.
23
+ if(version_compare($wp_version, '3.5', '>=')) {
24
+
25
+ // Check for multisite.
26
+ if(is_multisite()) {
27
+
28
+ // Init multisite support.
29
+ self::init_classes();
30
+ self::init_multisite();
31
+
32
+ // This version has multisite support.
33
+ if(class_exists('FLBuilderMultisite')) {
34
+
35
+ if(is_network_admin()) {
36
+ FLBuilderMultisite::install();
37
+ }
38
+ else {
39
+ self::install();
40
+ }
41
+ }
42
+ // This version doesn't have multisite support.
43
+ else {
44
+ $url = FLBuilderModel::get_upgrade_url( array( 'utm_source' => 'external', 'utm_medium' => 'builder', 'utm_campaign' => 'no-multisite-support' ) );
45
  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="' . $url . '" target="_blank"' ) );
46
+ }
47
+ }
48
+ // No multisite, standard install.
49
+ else {
50
+ self::install();
51
+ }
52
+ }
53
+ // Wrong WordPress version.
54
+ else {
55
+ 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'));
56
+ }
57
+
58
+ // Success! Trigger the activation notice.
59
+ if(FL_BUILDER_LITE !== true) {
60
+ update_site_option('_fl_builder_activation_admin_notice', true);
61
+ }
62
+ }
63
 
64
  /**
65
+ * Show a message if there is an activation error and
66
+ * deactivates the plugin.
67
+ *
68
+ * @since 1.0
69
+ * @param string $message The message to show.
70
+ * @return void
71
+ */
72
+ static public function show_activate_error($message)
73
+ {
74
+ deactivate_plugins( FLBuilderModel::plugin_basename(), false, is_network_admin() );
75
 
76
+ die( $message );
77
+ }
78
 
79
  /**
80
+ * Sets the action to show the activation success message.
81
+ *
82
+ * @since 1.0
83
+ * @return void
84
+ */
85
+ static public function show_activate_notice()
86
+ {
87
+ $notice = get_site_option('_fl_builder_activation_admin_notice');
88
+
89
+ if($notice) {
90
+ add_action('admin_notices', 'FLBuilderAdmin::activate_notice');
91
+ add_action('network_admin_notices', 'FLBuilderAdmin::activate_notice');
92
+ delete_site_option('_fl_builder_activation_admin_notice');
93
+ }
94
+ }
95
 
96
  /**
97
+ * Shows the activation success message.
98
+ *
99
+ * @since 1.0
100
+ * @return void
101
+ */
102
+ static public function activate_notice()
103
+ {
104
+ if ( class_exists('FLBuilderMultisiteSettings') && is_multisite() && current_user_can( 'manage_network_plugins' ) ) {
105
+ $href = esc_url( network_admin_url( '/settings.php?page=fl-builder-multisite-settings#license' ) );
106
+ }
107
+ else {
108
+ $href = esc_url( admin_url( '/options-general.php?page=fl-builder-settings#license' ) );
109
+ }
110
+
111
+ echo '<div class="updated" style="background: #d3ebc1;">';
112
  echo '<p><strong>' . sprintf( __( 'Page Builder activated! <a%s>Click here</a> to enable remote updates.', 'fl-builder' ), ' href="' . esc_url( $href ) . '"' ) . '</strong></p>';
113
+ echo '</div>';
114
+ }
115
+
116
+ /**
117
+ * Installs the builder upon successful activation.
118
+ * Currently not used but may be in the future.
119
+ *
120
+ * @since 1.0
121
+ * @return void
122
+ */
123
+ static public function install() {}
124
 
125
  /**
126
+ * Uninstalls the builder.
127
+ *
128
+ * @since 1.0
129
+ * @return void
130
+ */
131
+ static public function uninstall()
132
+ {
133
+ FLBuilderModel::uninstall_database();
134
+ }
135
 
136
  /**
137
+ * Initializes builder logic for wp-admin.
138
+ *
139
+ * @since 1.0
140
+ * @return void
141
+ */
142
+ static public function init()
143
+ {
144
+ self::init_classes();
145
+ self::init_settings();
146
+ self::init_multisite();
147
+ self::init_templates();
148
+ self::show_activate_notice();
149
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
 
151
  /**
152
+ * Loads builder classes for wp-admin.
153
+ *
154
+ * @since 1.0
155
+ * @return void
156
+ */
157
+ static public function init_classes()
158
+ {
159
+ $templates_class = FL_BUILDER_DIR . 'classes/class-fl-builder-templates.php';
160
+ $ms_class = FL_BUILDER_DIR . 'classes/class-fl-builder-multisite.php';
161
+ $ms_settings_class = FL_BUILDER_DIR . 'classes/class-fl-builder-multisite-settings.php';
162
+
163
+ if(file_exists($templates_class)) {
164
+ require_once $templates_class;
165
+ }
166
+ if(is_multisite()) {
167
+
168
+ if(file_exists($ms_class)) {
169
+ require_once $ms_class;
170
+ }
171
+ if(file_exists($ms_settings_class)) {
172
+ require_once $ms_settings_class;
173
+ }
174
+ }
175
+
176
+ require_once FL_BUILDER_DIR . 'classes/class-fl-builder-admin-settings.php';
177
+ }
178
+
179
+ /**
180
+ * Initializes the builder admin settings page.
181
+ *
182
+ * @since 1.0
183
+ * @return void
184
+ */
185
+ static public function init_settings()
186
+ {
187
+ FLBuilderAdminSettings::init();
188
+ }
189
+
190
+ /**
191
+ * Initializes the builder network admin settings page
192
+ * and additional multisite logic.
193
+ *
194
+ * @since 1.0
195
+ * @return void
196
+ */
197
+ static public function init_multisite()
198
+ {
199
+ if(is_multisite()) {
200
+
201
+ if(class_exists('FLBuilderMultisite')) {
202
+ FLBuilderMultisite::init();
203
+ }
204
+ if(class_exists('FLBuilderMultisiteSettings')) {
205
+ FLBuilderMultisiteSettings::init();
206
+ }
207
+ }
208
+ }
209
+
210
+ /**
211
+ * Initializes the interface for core builder templates.
212
+ *
213
+ * @since 1.0
214
+ * @return void
215
+ */
216
+ static public function init_templates()
217
+ {
218
+ if(class_exists('FLBuilderTemplates')) {
219
+ FLBuilderTemplates::init();
220
+ }
221
+ }
222
+
223
+ /**
224
+ * Renders the link for the row actions on the plugins page.
225
+ *
226
+ * @since 1.0
227
+ * @param array $actions An array of row action links.
228
+ * @return array
229
+ */
230
  static public function render_plugin_action_links($actions)
231
+ {
232
+ if(FL_BUILDER_LITE === true) {
233
+ $url = FLBuilderModel::get_upgrade_url( array( 'utm_source' => 'external', 'utm_medium' => 'builder', 'utm_campaign' => 'plugins-page' ) );
234
  $actions[] = '<a href="' . $url . '" style="color:#3db634;" target="_blank">' . _x( 'Upgrade', 'Plugin action link label.', 'fl-builder' ) . '</a>';
235
+ }
236
 
237
+ return $actions;
238
+ }
239
 
240
  /**
241
+ * White labels the builder on the plugins page.
242
+ *
243
+ * @since 1.0
244
+ * @param array $plugins An array data for each plugin.
245
+ * @return array
246
+ */
247
  static public function white_label_plugins_page($plugins)
248
+ {
249
+ $default = __( 'Page Builder', 'fl-builder' );
250
+ $branding = FLBuilderModel::get_branding();
251
+ $key = FLBuilderModel::plugin_basename();
252
+
253
+ if ( isset( $plugins[ $key ] ) && $branding != $default ) {
254
+ $plugins[ $key ]['Name'] = $branding;
255
+ $plugins[ $key ]['Title'] = $branding;
256
+ $plugins[ $key ]['Author'] = '';
257
+ $plugins[ $key ]['AuthorName'] = '';
258
+ $plugins[ $key ]['PluginURI'] = '';
259
+ }
260
+
261
+ return $plugins;
262
+ }
263
  }
classes/class-fl-builder-auto-suggest.php CHANGED
@@ -1,79 +1,92 @@
1
  <?php
2
 
3
  /**
4
- * A class for working with auto suggest requests.
5
  *
6
- * @class FLBuilderAutoSuggest
7
  */
8
  final class FLBuilderAutoSuggest {
9
 
10
- /**
11
- * @method init
12
- */
 
 
 
 
13
  static public function init()
14
  {
15
- if(isset($_REQUEST['fl_as_action']) && isset($_REQUEST['fl_as_query'])) {
16
-
17
- switch($_REQUEST['fl_as_action']) {
18
-
19
- case 'fl_as_posts':
20
- $data = self::posts();
21
- break;
22
-
23
- case 'fl_as_terms':
24
- $data = self::terms();
25
- break;
26
-
27
- case 'fl_as_users':
28
- $data = self::users();
29
- break;
30
-
31
- case 'fl_as_links':
32
- $data = self::links();
33
- break;
34
- }
35
-
36
- if(isset($data)) {
37
- echo json_encode($data);
38
- die();
39
- }
40
- }
41
  }
42
 
43
  /**
44
- * @method init
45
- */
 
 
 
 
 
 
46
  static public function get_value($action = '', $value = '', $data = '')
47
  {
48
- switch($action) {
49
-
50
- case 'fl_as_posts':
51
- $data = self::posts_value($value, $data);
52
- break;
53
-
54
- case 'fl_as_terms':
55
- $data = self::terms_value($value, $data);
56
- break;
57
-
58
- case 'fl_as_users':
59
- $data = self::users_value($value);
60
- break;
61
-
62
- default :
63
-
64
- if(function_exists($action . '_value')) {
65
- $data = call_user_func_array($action . '_value', array($value, $data));
66
- }
67
-
68
- break;
69
- }
70
-
71
- return isset($data) ? json_encode($data) : '';
72
  }
73
 
74
  /**
75
- * @method get_like
76
- */
 
 
 
77
  static public function get_like()
78
  {
79
  global $wpdb;
@@ -81,168 +94,193 @@ final class FLBuilderAutoSuggest {
81
  $like = urldecode( $_REQUEST['fl_as_query'] );
82
 
83
  if ( method_exists( $wpdb, 'esc_like' ) ) {
84
- $like = esc_sql( $wpdb->esc_like( $like ) );
85
- }
86
- else {
87
  $like = like_escape( esc_sql( $like ) );
88
- }
89
-
90
- return $like;
91
  }
92
 
93
- /**
94
- * @method posts
95
- */
 
 
 
96
  static public function posts()
97
  {
98
- global $wpdb;
99
-
100
- $data = array();
101
- $like = self::get_like();
102
- $type = esc_sql($_REQUEST['fl_as_action_data']);
103
-
104
- $posts = $wpdb->get_results("
105
- SELECT ID, post_title FROM {$wpdb->posts}
106
- WHERE post_title LIKE '%{$like}%'
107
- AND post_type = '{$type}'
108
- AND post_status = 'publish'
109
- ");
110
-
111
- foreach($posts as $post) {
112
- $data[] = array('name' => $post->post_title, 'value' => $post->ID);
113
- }
114
-
115
- return $data;
116
  }
117
 
118
- /**
119
- * @method posts_value
120
- */
121
- static public function posts_value($ids, $type)
 
 
 
 
122
  {
123
- global $wpdb;
124
-
125
- $data = array();
126
-
127
- if(!empty($ids)) {
128
-
129
- $posts = $wpdb->get_results("SELECT ID, post_title FROM {$wpdb->posts} WHERE ID IN ({$ids})");
130
-
131
- foreach($posts as $post) {
132
- $data[] = array('name' => $post->post_title, 'value' => $post->ID);
133
- }
134
- }
135
-
136
- return $data;
137
  }
138
 
139
- /**
140
- * @method terms
141
- */
 
 
 
142
  static public function terms()
143
  {
144
- $data = array();
145
- $cats = get_categories(array(
146
- 'hide_empty' => 0,
147
- 'taxonomy' => $_REQUEST['fl_as_action_data']
148
- ));
149
-
150
- foreach($cats as $cat) {
151
- $data[] = array('name' => $cat->name, 'value' => $cat->term_id);
152
- }
153
-
154
- return $data;
155
  }
156
 
157
- /**
158
- * @method terms_value
159
- */
 
 
 
 
 
160
  static public function terms_value($ids, $taxonomy)
161
  {
162
- $data = array();
163
-
164
- if(!empty($ids)) {
165
 
166
- $cats = get_categories(array(
167
- 'hide_empty' => 0,
168
- 'taxonomy' => $taxonomy,
169
- 'include' => $ids
170
- ));
171
-
172
- foreach($cats as $cat) {
173
- $data[] = array('name' => $cat->name, 'value' => $cat->term_id);
174
- }
175
- }
176
-
177
- return $data;
178
  }
179
 
180
- /**
181
- * @method users
182
- */
 
 
 
183
  static public function users()
184
  {
185
- global $wpdb;
186
-
187
- $data = array();
188
- $like = self::get_like();
189
- $users = $wpdb->get_results("SELECT * FROM {$wpdb->users} WHERE user_login LIKE '%{$like}%'");
190
-
191
- foreach($users as $user) {
192
- $data[] = array('name' => $user->user_login, 'value' => $user->ID);
193
- }
194
-
195
- return $data;
196
  }
197
 
198
- /**
199
- * @method users_value
200
- */
 
 
 
 
201
  static public function users_value($ids)
202
  {
203
- global $wpdb;
204
-
205
- $data = array();
206
-
207
- if(!empty($ids)) {
208
-
209
- $users = $wpdb->get_results("SELECT * FROM {$wpdb->users} WHERE ID IN ({$ids})");
210
-
211
- foreach($users as $user) {
212
- $data[] = array('name' => $user->user_login, 'value' => $user->ID);
213
- }
214
- }
215
-
216
- return $data;
217
  }
218
 
219
- /**
220
- * @method links
221
- */
 
 
 
222
  static public function links()
223
  {
224
- global $wpdb;
225
-
226
- $data = array();
227
- $like = self::get_like();
228
- $types = FLBuilderLoop::post_types();
229
- $slugs = array();
230
 
231
- foreach($types as $slug => $type) {
232
- $slugs[] = esc_sql($slug);
233
- }
234
-
235
- $posts = $wpdb->get_results("
236
- SELECT ID, post_title FROM {$wpdb->posts}
237
- WHERE post_title LIKE '%{$like}%'
238
- AND post_type IN ('" . implode("','", $slugs) . "')
239
- AND post_status = 'publish'
240
- ");
241
-
242
- foreach($posts as $post) {
243
- $data[] = array('name' => $post->post_title, 'value' => get_permalink($post->ID));
244
- }
245
-
246
- return $data;
247
  }
248
  }
1
  <?php
2
 
3
  /**
4
+ * A class for working with auto suggest AJAX requests.
5
  *
6
+ * @since 1.2.3
7
  */
8
  final class FLBuilderAutoSuggest {
9
 
10
+ /**
11
+ * Checks for an auto suggest request. If one is found
12
+ * the data will be echoed as a JSON response.
13
+ *
14
+ * @since 1.2.3
15
+ * @return void
16
+ */
17
  static public function init()
18
  {
19
+ if(isset($_REQUEST['fl_as_action']) && isset($_REQUEST['fl_as_query'])) {
20
+
21
+ switch($_REQUEST['fl_as_action']) {
22
+
23
+ case 'fl_as_posts':
24
+ $data = self::posts();
25
+ break;
26
+
27
+ case 'fl_as_terms':
28
+ $data = self::terms();
29
+ break;
30
+
31
+ case 'fl_as_users':
32
+ $data = self::users();
33
+ break;
34
+
35
+ case 'fl_as_links':
36
+ $data = self::links();
37
+ break;