PluginProbe
Smart Grid-Layout Design for Contact Form 7 / 4.5
Smart Grid-Layout Design for Contact Form 7 v4.5
4.18.0 4.17.0 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 4.0.0 4.0.1 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.10 4.11 4.12 4.13 4.14 All 119 releases
← All changes | admin/class-cf7-grid-layout-admin.php +493 -62 3.3.54.5 View file →
@@ -23,8 +23,24 @@
23 23 class Cf7_Grid_Layout_Admin {
24 24 /**
25 25 * The ID of this plugin.
26 26 *
27 + * @since 4.2.1
28 + * @access private
29 + * @var string $plugin_name The ID of this plugin.
30 + */
31 + private static $admin_notice_pages = array(
32 + 'admin.php'=>array('cf7sg_help'=>'page'),
33 + 'edit.php'=>array('wpcf7_contact_form'=>'post_type'),
34 + 'post.php'=> 'wpcf7_contact_form',
35 + 'edit-tags.php'=>array('wpcf7_contact_form'=>'post_type'),
36 + 'index.php'=>'',//dashboard ,
37 + 'plugins.php'=>'',
38 + //'options-general.php'=>'page=',
39 + );
40 + /**
41 + * The ID of this plugin.
42 + *
27 43 * @since 1.0.0
28 44 * @access private
29 45 * @var string $plugin_name The ID of this plugin.
30 46 */
@@ -107,15 +123,21 @@
107 123 *
108 124 * @since 1.0.0
109 125 */
110 126 public function enqueue_styles($page) {
127 +
111 128 if( in_array($page, array('toplevel_page_wpcf7', 'contact_page_wpcf7-new')) ) return;
112 129
113 130 $screen = get_current_screen();
131 + $plugin_dir = plugin_dir_url( __DIR__ );
132 + if('plugins'==$screen->base){
133 + /** @since 4.1.0 */
134 + wp_enqueue_style('plugin-update',$plugin_dir . 'admin/css/cf7sg-plugin-update.css', array(), $this->version, 'all');
135 + return;
136 + }
114 137 if (empty($screen) || $this->cf7_post_type() != $screen->post_type){
115 138 return;
116 139 }
117 - $plugin_dir = plugin_dir_url( __DIR__ );
118 140 switch( $screen->base ){
119 141 case 'post':
120 142 wp_enqueue_style( "cf7-grid-post-css", $plugin_dir . 'admin/css/cf7-grid-layout-post.css', array(), $this->version, 'all' );
121 143 //dynamic tag
@@ -123,9 +145,11 @@
123 145 //benchmark tag
124 146 wp_enqueue_style('cf7sg-benchmark-tag-css', $plugin_dir . 'admin/css/cf7sg-benchmark-tag.css', array(), $this->version, 'all' );
125 147 //codemirror
126 148 wp_enqueue_style( "codemirror-css", $plugin_dir . 'assets/codemirror/codemirror.css', array(), $this->version, 'all' );
127 - wp_enqueue_style( "codemirror-theme-css", $plugin_dir . 'assets/codemirror/theme/paraiso-light.css', array(), $this->version, 'all' );
149 + /** @since 4.0 enable dark theme */
150 + wp_enqueue_style( "codemirror-theme-light-css", $plugin_dir . 'assets/codemirror/theme/paraiso-light.css', array(), $this->version, 'all' );
151 + wp_enqueue_style( "codemirror-theme-dark-css", $plugin_dir . 'assets/codemirror/theme/material-ocean.css', array(), $this->version, 'all' );
128 152 wp_enqueue_style( "codemirror-foldgutter-css", $plugin_dir . 'assets/codemirror/addon/fold/foldgutter.css', array(), $this->version, 'all' );
129 153 wp_enqueue_style( "codemirror-dialog-css", $plugin_dir . 'assets/codemirror/addon/dialog/dialog.css', array(), $this->version, 'all' );
130 154 wp_enqueue_style( "codemirror-matchesonscrollbar-css", $plugin_dir . 'assets/codemirror/addon/search/matchesonscrollbar.css', array(), $this->version, 'all' );
131 155 wp_enqueue_style( 'smart-grid-css', $plugin_dir . 'assets/css.gs/smart-grid.admin.css', array(), $this->version, 'all');
@@ -130,12 +154,15 @@
130 154 wp_enqueue_style( "codemirror-matchesonscrollbar-css", $plugin_dir . 'assets/codemirror/addon/search/matchesonscrollbar.css', array(), $this->version, 'all' );
131 155 wp_enqueue_style( 'smart-grid-css', $plugin_dir . 'assets/css.gs/smart-grid.admin.css', array(), $this->version, 'all');
132 156 wp_enqueue_style('dashicons');
133 157 wp_enqueue_style('select2-style', $plugin_dir . 'assets/select2/css/select2.min.css', array(), $this->version, 'all' );
158 + /** @since 4.4.0 Enabled user style enqueue */
159 + do_action('cf7sg_enqueue_admin_editor_styles');
134 160 break;
135 161 case 'edit': //table.
136 162 wp_enqueue_style( $this->plugin_name, $plugin_dir . 'admin/css/cf7-grid-layout-admin.css', array(), $this->version, 'all' );
137 -
163 + /** @since 4.4.0 Enabled user style enqueue */
164 + do_action('cf7sg_enqueue_admin_table_styles');
138 165 break;
139 166 }
140 167
141 168 }
@@ -145,10 +172,9 @@
145 172 *
146 173 * @since 1.0.0
147 174 */
148 175 public function enqueue_scripts($page) {
149 - global $post;
150 - //debug_msg($screen, $this->custom_type );
176 +
151 177 $plugin_dir = plugin_dir_url( __DIR__ );
152 178 if( in_array($page, array('toplevel_page_wpcf7', 'contact_page_wpcf7-new')) ){
153 179 wp_enqueue_script( $this->plugin_name, $plugin_dir . 'admin/js/cf7-grid-layout-admin.js', array( 'jquery' ), $this->version, true );
154 180 return;
@@ -153,11 +179,23 @@
153 179 wp_enqueue_script( $this->plugin_name, $plugin_dir . 'admin/js/cf7-grid-layout-admin.js', array( 'jquery' ), $this->version, true );
154 180 return;
155 181 }
156 182 $screen = get_current_screen();
183 + if('plugins'==$screen->base){
184 + /** @since 4.1.0 */
185 + wp_enqueue_script('cf7sg-plugin-update', $plugin_dir . 'admin/js/cf7sg-plugin-update.js', array('jquery'));
186 + /* translators: message displayed when succesful update to validate new version */
187 + wp_localize_script('cf7sg-plugin-update', 'cf7sg',array(
188 + 'msg'=> __('Validating your update...','cf7-grid-layout'),
189 + 'nonce'=> wp_create_nonce( 'cf7sg_udpate_plugin' ),
190 + 'error'=>__('Unable to validate, please reload!', 'cf7-grid-layout')
191 + ));
192 + return;
193 + }
157 194 if ($this->cf7_post_type() != $screen->post_type){
158 195 return;
159 196 }
197 +
160 198 switch( $screen->base ){
161 199 case 'post':
162 200 /* register codemirror editor & addons. */
163 201 //codemirror script
@@ -166,23 +204,24 @@
166 204 null, "5.32", true
167 205 );
168 206 /** @since 3.1.2 initialise codemirror after library load and parse as attribute to anonymous functtion in cf7-grid-codemirror.js */
169 207 wp_add_inline_script('cf7-codemirror-js',
170 - 'var codeMirror_5_32 = CodeMirror(document.getElementById("cf7-codemirror"),
171 - {
172 - value: "",
173 - extraKeys: {"Ctrl-Space": "autocomplete"},
174 - lineNumbers: true,
175 - styleActiveLine: true,
176 - matchBrackets: true,
177 - tabSize:2,
178 - mode: "htmlmixed",
179 - lineWrapping: true,
180 - addModeClass: true,
181 - foldGutter: true,
182 - autofocus:false,
208 + 'const cmInitialSettings = {
209 + value:"",autoCloseTags:true,
210 + extraKeys: {"Ctrl-Space": "autocomplete", "Ctrl-/": "toggleComment", "Ctrl-J": "toMatchingTag"},
211 + lineNumbers: true, styleActiveLine: true,
212 + matchBrackets: true, tabSize:2, lineWrapping: true, addModeClass: true,
213 + foldGutter: true, autofocus:false,
183 214 gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]
184 - });');
215 + }
216 + const codeMirror_5_32 = CodeMirror(document.getElementById("cf7-codemirror"),cmInitialSettings);
217 + const cssCodeMirror_5_32 = CodeMirror(document.getElementById("cf7-css-codemirror"),cmInitialSettings);
218 + const jsCodeMirror_5_32 = CodeMirror(document.getElementById("cf7-js-codemirror"),cmInitialSettings);');
219 + //matchtags.
220 + wp_enqueue_script( 'codemirror-closetag-js',
221 + $plugin_dir . 'assets/codemirror/edit/closetag.js',
222 + array('cf7-codemirror-js'), $this->version, true
223 + );
185 224 //fold code
186 225 wp_enqueue_script( 'codemirror-foldcode-js',
187 226 $plugin_dir . 'assets/codemirror/addon/fold/foldcode.js',
188 227 array('cf7-codemirror-js'), $this->version, true
@@ -198,8 +237,12 @@
198 237 wp_enqueue_script( 'codemirror-xml-fold-js',
199 238 $plugin_dir . 'assets/codemirror/addon/fold/xml-fold.js',
200 239 array('cf7-codemirror-js'), $this->version, true
201 240 );
241 + wp_enqueue_script( 'codemirror-matchtag-js',
242 + $plugin_dir . 'assets/codemirror/addon/edit/matchtags.js',
243 + array('cf7-codemirror-js','codemirror-xml-fold-js'), $this->version, true
244 + );
202 245 wp_enqueue_script( 'codemirror-brace-fold-js',
203 246 $plugin_dir . 'assets/codemirror/addon/fold/brace-fold.js',
204 247 array('cf7-codemirror-js'), $this->version, true
205 248 );
@@ -266,9 +309,51 @@
266 309 $plugin_dir . 'assets/beautify/beautify-html.js',
267 310 array('beautify-js'), $this->version, true
268 311 );
269 312 wp_enqueue_script('jquery-select2', $plugin_dir . 'assets/select2/js/select2.min.js', array( 'jquery' ), $this->version, true );
270 -
313 + /** @since 4.0 enable dark theme */
314 + $cm_light = apply_filters('cf7sg_admin_editor_theme', '');
315 + $user_theme = get_user_meta(get_current_user_id(),'_cf7sg_cm_theme', true);
316 + if(!empty($cm_light) && file_exists(get_stylesheet_directory().'/'.$cm_light) ){
317 + wp_enqueue_style( "codemirror-theme-css", get_stylesheet_directory_uri().'/'.$cm_light, array(), $this->version, 'all' );
318 + $user_theme = basename($cm_light, '.css');
319 + update_user_meta(get_current_user_id(),'_cf7sg_cm_theme', '');
320 + }else{
321 + if(empty($user_theme)){
322 + $user_theme = 'paraiso-light';
323 + update_user_meta(get_current_user_id(),'_cf7sg_cm_theme', 'light');
324 + }else{
325 + $user_theme = ('light'==$user_theme ? 'paraiso-light' : 'material-ocean');
326 + }
327 + }
328 + $cm_js_light = apply_filters('cf7sg_admin_js_editor_theme', '');
329 + $user_js_theme = get_user_meta(get_current_user_id(),'_cf7sg_js_cm_theme', true);
330 + if(!empty($cm_js_light) && file_exists(get_stylesheet_directory().'/'.$cm_js_light) ){
331 + wp_enqueue_style( "codemirror-js-theme-css", get_stylesheet_directory_uri().'/'.$cm_js_light, array(), $this->version, 'all' );
332 + $user_js_theme = basename($cm_js_light, '.css');
333 + update_user_meta(get_current_user_id(),'_cf7sg_js_cm_theme', '');
334 + }else{
335 + if(empty($user_js_theme)){
336 + $user_js_theme = 'paraiso-light';
337 + update_user_meta(get_current_user_id(),'_cf7sg_js_cm_theme', 'light');
338 + }else{
339 + $user_js_theme = ('light'==$user_js_theme ? 'paraiso-light' : 'material-ocean');
340 + }
341 + }
342 + $cm_css_light = apply_filters('cf7sg_admin_css_editor_theme', '');
343 + $user_css_theme = get_user_meta(get_current_user_id(),'_cf7sg_css_cm_theme', true);
344 + if(!empty($cm_css_light) && file_exists(get_stylesheet_directory().'/'.$cm_css_light) ){
345 + wp_enqueue_style( "codemirror-css-theme-css", get_stylesheet_directory_uri().'/'.$cm_css_light, array(), $this->version, 'all' );
346 + $user_css_theme = basename($cm_css_light, '.css');
347 + update_user_meta(get_current_user_id(),'_cf7sg_css_cm_theme', '');
348 + }else{
349 + if(empty($user_css_theme)){
350 + $user_css_theme = 'paraiso-light';
351 + update_user_meta(get_current_user_id(),'_cf7sg_css_cm_theme', 'light');
352 + }else{
353 + $user_css_theme = ('light'==$user_css_theme ? 'paraiso-light' : 'material-ocean');
354 + }
355 + }
271 356 //enqueue the cf7 scripts.
272 357 wpcf7_admin_enqueue_scripts( 'wpcf7' );
273 358 wp_enqueue_script('jquery-clibboard', $plugin_dir . 'assets/clipboard/clipboard.min.js', array('jquery'),$this->version,true);
274 359 wp_enqueue_script( 'cf7-grid-codemirror-js', $plugin_dir . 'admin/js/cf7-grid-codemirror.js', array( 'jquery', 'jquery-ui-tabs', 'cf7-codemirror-js' ), $this->version, true );
@@ -275,12 +360,30 @@
275 360 wp_localize_script(
276 361 'cf7-grid-codemirror-js',
277 362 'cf7sgeditor',
278 363 array(
279 - 'mode' => apply_filters('cf7sg_admin_editor_mode', 'shortcode', $post->post_name),
280 - 'theme' => apply_filters('cf7sg_admin_editor_theme', 'paraiso-light', $post->post_name)
364 + 'mode' => 'shortcode',
365 + 'theme' => array(
366 + 'light'=>'paraiso-light',
367 + 'dark'=>'material-ocean',
368 + 'user'=>$user_theme
369 + ),
370 + 'jstheme' => array(
371 + 'light'=>'paraiso-light',
372 + 'dark'=>'material-ocean',
373 + 'user'=>$user_js_theme
374 + ),
375 + 'csstheme' => array(
376 + 'light'=>'paraiso-light',
377 + 'dark'=>'material-ocean',
378 + 'user'=>$user_css_theme
379 + ),
380 + 'jserror'=>__('There is a <strong>Javascript error on the page</strong> which prevents the editor from loading properly.', 'cf7-grid-layout'),
381 + 'fixhtmlform'=>__('The editor failed to load. You may recover your form by copying it into a new form editor, do you wish to continue?', 'cf7-grid-layout'),
281 382 )
282 383 );
384 + global $post;
385 +
283 386 wp_enqueue_script( $this->plugin_name, $plugin_dir . 'admin/js/cf7-grid-layout-admin.js', array('cf7-grid-codemirror-js', 'jquery-ui-sortable' ), $this->version, true );
284 387 wp_localize_script(
285 388 $this->plugin_name,
286 389 'cf7grid',
@@ -300,15 +403,16 @@
300 403 'msg'=>__('Click to copy!','cf7-grid-layout'),
301 404 'filter'=> __('Filter mailTag %s', 'cf7-grid-layout')
302 405 )
303 406 );
304 - /** @since 3.3.0enqueue ui-grid helpers js */
407 + /** @since 3.3.0 enqueue ui-grid helpers js */
305 408 wp_enqueue_script('ui-grid-helpers-js', $plugin_dir.'admin/js/ui-custom-helper.js', array('jquery'));
306 409 do_action('cf7sg_enqueue_admin_editor_scripts');
307 410 break;
308 411 case 'edit':
309 412 //wp_enqueue_script( $this->plugin_name.'-quick-edit', plugin_dir_url( __FILE__ ) . 'js/cf7-grid-layout-quick-edit.js', false, $this->version, true );
310 -
413 + /** @since 4.4.0 Enabled user script enqueue */
414 + do_action('cf7sg_enqueue_admin_table_scripts');
311 415 break;
312 416 }
313 417 }
314 418
@@ -326,9 +430,9 @@
326 430 'wpcf7_edit_contact_forms',
327 431 'post-new.php?post_type=wpcf7_contact_form'
328 432 );
329 433 //initial cf7 object when creating new form
330 - add_action( 'load-' . $hook, array($this, 'setup_cf7_object'));
434 + //add_action( 'load-' . $hook, array($this, 'setup_cf7_object'));
331 435 //remove_submenu_page( $menu_slug, $submenu_slug );
332 436 remove_submenu_page( 'wpcf7', 'wpcf7-new' );
333 437 remove_meta_box('slugdiv', $this->cf7_post_type(), 'normal');
334 438 }
@@ -465,38 +569,10 @@
465 569 'high'
466 570 );
467 571 }
468 572 }
573 +
469 574 /**
470 - * Function called on page load when new form is created
471 - * hooked to 'load-{page-hook}'
472 - * @since 1.0.0
473 - **/
474 - public function setup_cf7_object(){
475 - $args = array();
476 - /**
477 - * Fix locale setup for new forms using polylang.
478 - * @since 2.1.4
479 - */
480 - if(isset($_GET['locale'])){
481 - $args['locale'] = $_GET['locale'];
482 - }else if(isset($_GET['new_lang'])){
483 - //check for polylang
484 - $locale = $_GET['new_lang'];
485 - if(function_exists('pll_languages_list')){
486 - $langs = pll_languages_list();
487 - $locales = pll_languages_list(array('fields'=>'locale'));
488 - foreach($langs as $idx => $lang){
489 - if($lang == $locale){
490 - $locale = $locales[$idx];
491 - }
492 - }
493 - }
494 - $args['locale'] =$locale;
495 - }else $args['locale'] = get_locale();
496 - WPCF7_ContactForm::get_template( $args);
497 - }
498 - /**
499 575 * Callback function to disolay the main editor meta box
500 576 * @since 1.0.0
501 577 */
502 578 public function main_editor_metabox_display($post){
@@ -504,11 +580,11 @@
504 580 wpcf7_contact_form($post); //set the post
505 581 }
506 582 $post_id = $post->ID;
507 583 $cf7_form = wpcf7_get_current_contact_form();
508 -
509 584 if ( ! $cf7_form ) {
510 - $cf7_form = WPCF7_ContactForm::get_template();
585 + $args = apply_filters('cf7sg_new_cf7_form_template_arguments', array());
586 + $cf7_form = WPCF7_ContactForm::get_template($args);
511 587 }
512 588
513 589 // if(empty($post)){
514 590 // $post_id = -1;
@@ -588,8 +664,21 @@
588 664 public function grid_editor_panel($form_post){
589 665 require_once plugin_dir_path( __FILE__ ) . '/partials/cf7-grid-layout-admin-display.php';
590 666 }
591 667 /**
668 + * Clean up post meta, delete sgcf7 corresponding view post.
669 + * Hooked to action 'before_delete_post'.
670 + *@since 4.3.0
671 + *@param int $post_id post ID.
672 + *@param WP_Post post object.
673 + */
674 + public function delete_post($post_id){
675 + if(get_post_type($post_id) != WPCF7_ContactForm::post_type) return;
676 + //remove viwing post.
677 + $preview_id = get_post_meta($post_id, '_cf7sg_form_page',true);
678 + if(!empty($preview_id)) wp_delete_post($preview_id);
679 + }
680 + /**
592 681 * Save cf7 post using ajax
593 682 * Hooked to 'save_post_wpcf7_contact_form'
594 683 * @since 1.0.0
595 684 **/
@@ -629,9 +718,10 @@
629 718 'value'=>1,
630 719 'data-*'=>1,
631 720 );
632 721 $allowed_tags['script']=array('type'=>1);
633 - $allowed_tags = apply_filters('cf7sg_kses_allowed_html',$allowed_tags, $_POST['post_name']);
722 + $cf7_key = $post->post_name;
723 + $allowed_tags = apply_filters('cf7sg_kses_allowed_html',$allowed_tags, $cf7_key);
634 724 if(isset( $_POST['wpcf7-form'] )){
635 725 $args['form'] = wp_kses($_POST['wpcf7-form'], $allowed_tags);
636 726 }
637 727 $args['mail'] = isset( $_POST['wpcf7-mail'] ) ? wpcf7_sanitize_mail( $_POST['wpcf7-mail'] ): array();
@@ -706,8 +796,19 @@
706 796 foreach($tgg_field as $field) $sanitised_toggled_fields[$tgg][] = sanitize_text_field($field);
707 797 }else $sanitised_toggled_fields[] = sanitize_text_field($tgg_field);
708 798 }
709 799 update_post_meta($post_id, '_cf7sg_grid_toggled_names', $sanitised_toggled_fields);
800 + /** @since 4.0.0 track tabbed toggles */
801 + $ttgls = json_decode(stripslashes($_POST['cf7sg-tabbed-toggles']));
802 + if(empty($ttgls)) $ttgls = array();
803 + if(!is_array($ttgls)) $ttgls = array($ttgls);
804 + update_post_meta($post_id, '_cf7sg_grid_tabbed_toggles', $ttgls);
805 + /** @since 4.0.0 track grouped toggles */
806 + $ttgls = json_decode(stripslashes($_POST['cf7sg-grouped-toggles']));
807 + if(empty($ttgls)) $ttgls = array();
808 + if(is_object($ttgls)) $ttgls = get_object_vars($ttgls); //convert to array.
809 + else $ttgls = array();
810 + update_post_meta($post_id, '_cf7sg_grid_grouped_toggles', $ttgls);
710 811 //flag tab & tables for more efficient front-end display.
711 812 $has_tabs = ( 'true' === $_POST['cf7sg-has-tabs']) ? true : false;
712 813 update_post_meta($post_id, '_cf7sg_has_tabs', $has_tabs);
713 814 $has_tables = ( 'true' === $_POST['cf7sg-has-tables']) ? true : false;
@@ -714,12 +815,12 @@
714 815 update_post_meta($post_id, '_cf7sg_has_tables', $has_tables);
715 816 $has_toggles = ( 'true' === $_POST['cf7sg-has-toggles']) ? true : false;
716 817 update_post_meta($post_id, '_cf7sg_has_toggles', $has_toggles);
717 818 /** @since 3.3.5 track toggles in tabs */
718 - $toggle_in_tabs = json_decode(stripslashes($_POST['cf7sg-toggle-in-tabs']));
719 - if(empty($toggle_in_tabs)) $toggle_in_tabs = array();
720 - if(!is_array($toggle_in_tabs)) $toggle_in_tabs = array($toggle_in_tabs);
721 - update_post_meta($post_id, '_cf7sg_grid_toggle_in_tabs', $toggle_in_tabs);
819 + // $toggle_in_tabs = json_decode(stripslashes($_POST['cf7sg-toggle-in-tabs']));
820 + // if(empty($toggle_in_tabs)) $toggle_in_tabs = array();
821 + // if(!is_array($toggle_in_tabs)) $toggle_in_tabs = array($toggle_in_tabs);
822 + // update_post_meta($post_id, '_cf7sg_grid_toggle_in_tabs', $toggle_in_tabs);
722 823 /**
723 824 * @since 1.2.3 disable cf7sg styling/js for non-cf7sg forms.
724 825 */
725 826 $is_cf7sg = ( 'true' === $_POST['is_cf7sg_form']) ? true : false;
@@ -730,12 +831,74 @@
730 831 $classes = explode(',', trim($classes, ','));
731 832 // debug_msg($classes, 'script classes');
732 833 update_post_meta($post_id, '_cf7sg_script_classes', $classes);
733 834 /**
734 - *@since 2.3.0 the duplicate functionality has been isntored and therefore any new meta fields added to this plugin needs to be added to the duplication properties too.
835 + *@since 2.3.0 the duplicate functionality has been instored and therefore any new meta fields added to this plugin needs to be added to the duplication properties too.
735 836 */
837 + /** @since 4.0.0 save user theme pref */
838 + if(isset($_POST['cf7sg_codemirror_theme'])){
839 + update_user_meta(get_current_user_id(),'_cf7sg_cm_theme', $_POST['cf7sg_codemirror_theme']);
840 + }
841 + if(isset($_POST['cf7sg_js_codemirror_theme'])){
842 + update_user_meta(get_current_user_id(),'_cf7sg_js_cm_theme', $_POST['cf7sg_js_codemirror_theme']);
843 + }
844 + //save js file if used.
845 + $path = get_stylesheet_directory();
846 + if(!empty($_POST['cf7sg_js_file'])){
847 + //check if the file name is changed.
848 + if(!empty($_POST['cf7sg_prev_js_file']) && file_exists(ABSPATH. $_POST['cf7sg_prev_js_file'])){
849 + if( !unlink(ABSPATH.$_POST['cf7sg_prev_js_file']) ) debug_msg('CF7SG ADMIN: unable to delete file '.$_POST['cf7sg_prev_js_file']);
850 + }
851 + if( !is_dir("$path/js/") ) mkdir("$path/js/");
852 + file_put_contents( "$path/js/{$cf7_key}.js", stripslashes($_POST['cf7sg_js_file']) );
853 + }else if( isset($_POST['cf7sg_js_file']) && file_exists("$path/js/{$cf7_key}.js") ) { //delete file.
854 + if( !unlink("$path/js/{$cf7_key}.js") ) debug_msg("CF7SG ADMIN: unable to delete file $path/js/{$cf7_key}.js");
855 + }
856 + //save css file.
857 + if(!empty($_POST['cf7sg_css_file'])){
858 + //check if the file is changed.
859 + if(!empty($_POST['cf7sg_prev_css_file']) && file_exists(ABSPATH.$_POST['cf7sg_prev_css_file'])){
860 + if( !unlink(ABSPATH.$_POST['cf7sg_prev_css_file']) ) debug_msg('CF7SG ADMIN: unable to delete file '.$_POST['cf7sg_prev_css_file']);
861 + }
862 + if( !is_dir("$path/css/") ) mkdir("$path/css/");
863 + file_put_contents( $path."/css/{$cf7_key}.css", stripslashes($_POST['cf7sg_css_file']));
864 + }else if( isset($_POST['cf7sg_css_file']) && file_exists("$path/css/{$cf7_key}.css") ) { //delete file.
865 + if( !unlink("$path/css/{$cf7_key}.css") ) debug_msg("CF7SG ADMIN: unable to delete file $path/css/{$cf7_key}.css");
866 + }
867 + //jstags comments.
868 + if(empty($_POST['cf7sg_jstags_comments'])) update_post_meta($post->ID, '_cf7sg_disable_jstags_comments',1);
869 + else update_post_meta($post->ID, '_cf7sg_disable_jstags_comments',0);
870 + /** @since 4.3.0 create/update a preview form post for this form */
871 + $preview_id = get_post_meta($post->ID, '_cf7sg_form_page',true);
872 + $content = '[cf7form cf7key="'.$cf7_key.'"';
873 + $content .= isset($_POST['post_lang_choice']) ? ' lang="'.$_POST['post_lang_choice'].'"]':']';
874 + $prev_page = array(
875 + 'post_title'=>sanitize_text_field($_POST['post_title']),
876 + 'post_content'=>$content,
877 + 'post_status'=>'draft',
878 + 'post_type'=>'cf7sg_page',
879 + // 'post_name' => sanitize_title( $title ),
880 + );
881 + if(empty($cf7_key)) $prev_page['post_content'] = '[contact-form-7 id="'.$post->ID.'"]';
882 + if( !empty($preview_id) ){
883 + $prev_page['ID'] = $preview_id;
884 + }
885 + $preview_id = wp_insert_post($prev_page, true);
886 + if(!is_wp_error($preview_id)){
887 + update_post_meta($post->ID, '_cf7sg_form_page',$preview_id);
888 + }
736 889 }
737 890 /**
891 + * Print default js template,
892 + * Hooked to 'cf7sg_default_custom_js_template'
893 + *@since 4.0.0
894 + *@param string $form_key form key.
895 + */
896 + public function print_default_js($form_key){
897 + $js_file = str_replace(ABSPATH, '', get_stylesheet_directory()."/js/{$form_key}.js");
898 + include_once 'partials/cf7-default-js.php';
899 + }
900 + /**
738 901 *
739 902 *
740 903 *@since 2.3.0
741 904 *@param string $new_form_id new form id to duplciate to.
@@ -1108,8 +1271,18 @@
1108 1271 ob_start();
1109 1272 include_once 'partials/pointers/cf7sg-pointer-update-forms.php';
1110 1273 $content =ob_get_contents();
1111 1274 $pointers['update_forms_pointer'] = array($content, 'left', 'center','');
1275 + /* tutorials */
1276 + ob_clean();
1277 + include_once 'partials/pointers/cf7sg-pointer-tutorials.php';
1278 + $content =ob_get_contents();
1279 + $pointers['tutorials_pointer'] = array($content, 'left', 'center','a[href="admin.php?page=cf7sg_help"]');
1280 + /* new tutorials */
1281 + ob_clean();
1282 + include_once 'partials/pointers/cf7sg-pointer-tutorial-advance.php';
1283 + $content =ob_get_contents();
1284 + $pointers['new_tutorials_pointer'] = array($content, 'left', 'center','a[href="admin.php?page=cf7sg_help"]');
1112 1285 /* shortcodes */
1113 1286 ob_clean();
1114 1287 include_once 'partials/pointers/cf7sg-pointer-shortcodes.php';
1115 1288 $content = ob_get_clean();
@@ -1141,8 +1314,16 @@
1141 1314 if(!empty($content)){
1142 1315 $pointers['row_controls'] = array($content, 'right', 'center','#grid-form>.container>.row>.row-controls');
1143 1316 ob_clean();
1144 1317 }
1318 + /* preview form */
1319 + ob_clean();
1320 + include_once 'partials/pointers/cf7sg-pointer-editor-preview-form.php';
1321 + $content = ob_get_contents();
1322 + if(!empty($content)){
1323 + $pointers['preview_form'] = array($content, 'right', 'center','#preview-form-link');
1324 + ob_clean();
1325 + }
1145 1326 include_once 'partials/pointers/cf7sg-pointer-editor-column-control.php';
1146 1327 $content = ob_get_contents();
1147 1328 if(!empty($content)){
1148 1329 $pointers['column_controls'] = array($content, 'left', 'center','#grid-form>.container>.row>.columns:first-child>.grid-column>span.icon-code');
@@ -1151,8 +1332,13 @@
1151 1332 include_once 'partials/pointers/cf7sg-pointer-tag-dynamic-dropdown.php';
1152 1333 $content = ob_get_contents();
1153 1334 $pointers['dynamic_dropdown'] = array($content, 'left', 'center','#top-tags>#tag-generator-list > a[title*="dynamic-dropdown"]');
1154 1335 ob_clean();
1336 + /* #optional-editors */
1337 + include_once 'partials/pointers/cf7sg-pointers-editor-optional-js-css.php';
1338 + $content = ob_get_contents();
1339 + $pointers['js_css_editors'] = array($content, 'left', 'center','#optional-editors');
1340 + ob_clean();
1155 1341 include_once 'partials/pointers/cf7sg-pointer-tag-benchmark.php';
1156 1342 $content = ob_get_clean();
1157 1343 $pointers['benchmark'] = array($content, 'left', 'center','#top-tags>#tag-generator-list > a[title*="benchmark"]');
1158 1344 return $pointers;
@@ -1242,6 +1428,251 @@
1242 1428 *@since 3.3.0
1243 1429 */
1244 1430 public function print_helper_hooks(){
1245 1431 require_once plugin_dir_path( __FILE__ ) .'partials/helpers/cf7sg-form-fields.php';
1432 + }
1433 + /**
1434 + * Setup mailtags or toggles.
1435 + *
1436 + *@since 4.0.0
1437 + *@param string $param text_description
1438 + *@return string text_description
1439 + */
1440 + public function setup_cf7_mailtags($mailtags = array()){
1441 + // return $mailtags;
1442 + $contact_form = WPCF7_ContactForm::get_current();
1443 + $fields = get_post_meta($contact_form->id(), '_cf7sg_grid_toggled_names', true);
1444 + //update_post_meta($post_id, '_cf7sg_grid_tabbed_toggles', $ttgls);
1445 + if(!empty($fields)){
1446 + $toggles = array_keys($fields);
1447 + $groups = get_post_meta($contact_form->id(), '_cf7sg_grid_grouped_toggles', true);
1448 + if(!empty($groups)){
1449 + foreach($groups as $group=>$grp_toggles){
1450 + $toggles = array_diff($toggles, $grp_toggles);
1451 + array_push($toggles, $group);
1452 + }
1453 + }
1454 + foreach($toggles as $tgl) $mailtags[]= 'cf7sg-toggle-'.$tgl;
1455 + }
1456 + //add a general form tag.
1457 + $mailtags[]= 'cf7sg-form-'.get_cf7form_key($contact_form->id());
1458 + return $mailtags;
1459 + }
1460 + /**
1461 + * Funciton to to initialise admin notices.
1462 + * hooked on 'admin_init'
1463 + *@since 4.1.0
1464 + */
1465 + public function init_notices(){
1466 + $grid_settings = get_option( 'cf7sg-plugin-version', array());
1467 + //if plugin settings exists and this is not an update, then no need to run.
1468 + if( !empty($grid_settings) and !isset($grid_settings['update']) ) return;
1469 +
1470 + $warning = false;
1471 + $notices = array();
1472 +
1473 + if(isset($grid_settings['update']) and CF7SG_VERSION_FORM_UPDATE==CF7_GRID_VERSION){
1474 + $warning = true;
1475 + }else if(isset($grid_settings['fv']) ) {
1476 + if(version_compare($grid_settings['fv'], CF7SG_VERSION_FORM_UPDATE, '<') ) $warning = true;
1477 + }else{ //check the forms directly
1478 + global $wpdb;
1479 + $post_type = $this->cf7_post_type();
1480 + $result = $wpdb->get_col("SELECT pm.meta_value FROM {$wpdb->postmeta} as pm
1481 + INNER JOIN {$wpdb->posts} as p on p.ID = pm.post_id
1482 + WHERE p.post_type = '{$post_type}'
1483 + AND pm.meta_key = '_cf7sg_version'
1484 + ORDER BY pm.meta_key
1485 + ");
1486 + if(!empty($result) and version_compare($result[0], CF7SG_VERSION_FORM_UPDATE, '<') ) $warning = true;
1487 + }
1488 +
1489 + if($warning){
1490 + $link = admin_url('edit.php?post_type=wpcf7_contact_form');
1491 + /* translators: %s is the url to the forms admin table */
1492 + $msg = __('You need to <strong>update</strong> your <a href="%s">forms</a>','cf7-grid-layout');
1493 + $notices['cf7sg_notice-'.CF7_GRID_VERSION] = array(
1494 + 'type'=>'notice-warning', //[notice-update|notice-error]
1495 + 'msg'=>sprintf($msg , $link),
1496 + 'pages'=>array('plugins.php','edit.php')
1497 + );
1498 + }
1499 + /** @since 4.2.0 new sliders tutorial */
1500 + if( isset($grid_settings['update']) ){
1501 + $notices['cf7sg_sliders_tutorial'] = array(
1502 + 'type'=>'notice-update', //[notice-update|notice-error]
1503 + /* translators: %s is the link to the tuorial page*/
1504 + 'msg'=>sprintf( __('There is a new tutorial for <a href="%s">multistep slider forms</a>','cf7-grid-layout'), admin_url('admin.php?page=cf7sg_help')),
1505 + 'html'=>'<div class="inline-top"><iframe width="230" height="130" src="https://www.youtube.com/embed/WiweQRhOr0g" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div><div class="inline-top"><strong>Learn how to create multi-step multi-slide CF7 forms using a slider construct functionality of the Smart Grid-layout extension plugin.</strong></div>',
1506 + 'pages'=>array('plugins.php','edit.php')
1507 + );
1508 + $notices['cf7sg_modular_tutorial'] = array(
1509 + 'type'=>'notice-update', //[notice-update|notice-error]
1510 + /* translators: %s is the link to the tuorial page*/
1511 + 'msg'=>sprintf( __('There is a new tutorial for <a href="%s">modular form construct</a>','cf7-grid-layout'), admin_url('admin.php?page=cf7sg_help')),
1512 + 'html'=>'<div class="inline-top"><iframe width="230" height="130" src="https://www.youtube.com/embed/vPc3M5Emro4" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div><div class="inline-top"><strong>Learn how to use modular form construct functionality allowing complex forms to be assembled from other child forms.</strong></div>',
1513 + 'pages'=>array('plugins.php','edit.php')
1514 + );
1515 + }
1516 + if(!empty($notices)) update_option('cf7sg-admin-notices', $notices);
1517 +
1518 + update_option('cf7sg-plugin-version', array(
1519 + 'gv'=>CF7_GRID_VERSION,
1520 + 'fv'=>CF7SG_VERSION_FORM_UPDATE
1521 + ));
1522 + }
1523 + /**
1524 + * Display admin notices
1525 + * Hooked on 'admin_notices'
1526 + *@since 4.1.0
1527 + */
1528 + public function admin_notices(){
1529 + //check if we have any notices.
1530 + global $pagenow;
1531 + $notices = get_option('cf7sg-admin-notices', array());
1532 + if(empty($notices)) return;
1533 +
1534 + if(!isset(self::$admin_notice_pages[$pagenow])) return;
1535 +
1536 + $notify=false;
1537 + $rule = self::$admin_notice_pages[$pagenow];
1538 + // debug_msg($rule, 'notice rules ');
1539 + if($pagenow=='post.php'){
1540 + $screen = get_current_screen();
1541 + if($this->cf7_post_type() == $screen->post_type) $notify=true;
1542 + }else if( !empty($rule) and is_array($rule) ){
1543 + foreach($rule as $key=>$type){
1544 + if( isset($_GET[$type]) and $_GET[$type]==$key ) $notify=true;
1545 + }
1546 + }else $notify = true; //default.
1547 +
1548 + if(!$notify) return; //rules don't match;
1549 +
1550 + //do we have any notices to display?
1551 + foreach($notices as $id=>$notice){
1552 + if( isset($notice['pages']) and !in_array($pagenow, $notice['pages'])) continue;
1553 + $time = isset($notice['time']) ? $notice['time']: 'forever';
1554 + $dismiss = "$id-$time";
1555 + if ( ! PAnD::is_admin_notice_active( $dismiss ) ) {
1556 + unset($notices[$id]);
1557 + update_option('cf7sg-admin-notices', $notices);
1558 + continue ; //continue foreach loop.
1559 + }
1560 + if(!isset($notice['html'])) $notice['html'] = '';
1561 + ?>
1562 + <style>.notice .inline-top{display: inline-block;vertical-align: top;margin-right: 10px;max-width: 300px;}</style>
1563 + <div data-dismissible="<?=$dismiss?>" class="notice <?=$notice['type']?> is-dismissible"><p><?=$notice['msg']?></p><?=$notice['html']?></div>
1564 + <?php
1565 + }
1566 + }
1567 + /**
1568 + * ajax request to validate plugin update.
1569 + * Hooked on 'wp_ajax_validate_cf7sg_version_update'
1570 + * @since 4.1.0
1571 + */
1572 + public function validate_cf7sg_version_update(){
1573 + if( !isset($_POST['nonce']) or !wp_verify_nonce($_POST['nonce'], 'cf7sg_udpate_plugin') ){
1574 + echo 'error, nonce failed, try to reload the page.';
1575 + wp_die();
1576 + }
1577 + $grid_settings = get_option('cf7sg-plugin-version', array());
1578 + $warning = false;
1579 + if(isset($grid_settings['fv']) ) {
1580 + if(version_compare($grid_settings['fv'], CF7SG_VERSION_FORM_UPDATE, '<') ) $warning = true;
1581 + }
1582 + $grid_settings['fv'] = CF7SG_VERSION_FORM_UPDATE;
1583 + $grid_settings['gv'] = CF7_GRID_VERSION;
1584 + $grid_settings['update'] = true;
1585 + update_option('cf7sg-plugin-version', $grid_settings);
1586 + $update_msg = __('Version validated, thank you!','cf7-grid-layout');
1587 + if($warning){
1588 + $link = admin_url('edit.php?post_type=wpcf7_contact_form');
1589 + /* translators: %s link to form table */
1590 + $update_msg = __('You need to <strong>update</strong> your <a href="%s">forms</a>','cf7-grid-layout');
1591 + $update_msg = sprintf( $update_msg, $link);
1592 + }
1593 + echo $update_msg;
1594 + wp_die();
1595 + }
1596 + /**
1597 + * Check if plugin is getting updated.
1598 + * Hooked to 'upgrader_post_install'.
1599 + *@since 4.1.0
1600 + *@param array $param text_description
1601 + *@param array $extras text_description
1602 + *@param array $result text_description
1603 + *@return array responses for the upgrade process
1604 + */
1605 + public function post_plugin_upgrade($response, $extras, $result){
1606 + if( ( isset($response['destination_name']) and 'cf7-grid-layout' == $response['destination_name'] )
1607 + or ( isset($extras['plugin']) and 'cf7-grid-layout/cf7-grid-layout.php' == $extras['plugin'] ) ){
1608 + $grid_settings = get_option('cf7sg-plugin-version', array());
1609 + $grid_settings['update'] = true;
1610 + update_option('cf7sg-plugin-version', $grid_settings);
1611 + }
1612 + return $response;
1613 + }
1614 + /**
1615 + * Preview form post type creation.
1616 + * hooked on action 'init'.
1617 + *@since 4.3.0
1618 + *@param string $param text_description
1619 + *@return string text_description
1620 + */
1621 + // Register Custom Post Type
1622 + function register_form_preview_posttype() {
1623 +
1624 + $labels = array(
1625 + 'name' => _x( 'CF7 Forms', 'Post Type General Name', 'cf7-grid-layout' ),
1626 + 'singular_name' => _x( 'CF7 Form', 'Post Type Singular Name', 'cf7-grid-layout' ),
1627 + 'menu_name' => __( 'CF7 Forms', 'cf7-grid-layout' ),
1628 + 'name_admin_bar' => __( 'CF7 Form', 'cf7-grid-layout' ),
1629 + 'parent_item_colon' => __( 'Parent Item:', 'cf7-grid-layout' ),
1630 + 'all_items' => __( 'All Form Pages', 'cf7-grid-layout' ),
1631 + 'add_new_item' => __( 'Add New Form Page', 'cf7-grid-layout' ),
1632 + 'add_new' => __( 'Add New', 'cf7-grid-layout' ),
1633 + 'new_item' => __( 'New Form Page', 'cf7-grid-layout' ),
1634 + 'edit_item' => __( 'Edit Form Page', 'cf7-grid-layout' ),
1635 + 'update_item' => __( 'Update Form Page', 'cf7-grid-layout' ),
1636 + 'view_item' => __( 'View Form Page', 'cf7-grid-layout' ),
1637 + 'view_items' => __( 'View Form Pages', 'cf7-grid-layout' ),
1638 + 'search_items' => __( 'Search Form Page', 'cf7-grid-layout' ),
1639 + 'not_found' => __( 'Not found', 'cf7-grid-layout' ),
1640 + 'not_found_in_trash' => __( 'Not found in Trash', 'cf7-grid-layout' ),
1641 + );
1642 + $rewrite = array(
1643 + 'slug' => 'sgform',
1644 + 'with_front' => true,
1645 + 'pages' => true,
1646 + 'feeds' => false,
1647 + );
1648 + $args = array(
1649 + 'label' => __( 'CF7 Form', 'cf7-grid-layout' ),
1650 + 'description' => __( 'Preview/View CF7 forms on the front-end', 'cf7-grid-layout' ),
1651 + 'labels' => $labels,
1652 + 'public' => true,
1653 + 'show_ui' => false,
1654 + 'show_in_menu' => false,
1655 + 'show_in_admin_bar' => false,
1656 + 'show_in_nav_menus' => false,
1657 + 'can_export' => false,
1658 + 'has_archive' => false,
1659 + 'exclude_from_search' => true,
1660 + 'publicly_queryable' => true,
1661 + // 'query_var' => 'sgcf7',
1662 + 'rewrite' => $rewrite,
1663 + );
1664 + register_post_type( 'cf7sg_page', $args );
1665 +
1666 + }
1667 + /**
1668 + * Load translation files for the CF7 Polylang extension.
1669 + * Hoooked to ''
1670 + *@since 4.4.0
1671 + *@param string $param text_description
1672 + *@return string text_description
1673 + */
1674 + public function load_translation_files($trans){
1675 + $trans[$this->plugin_name]=CF7SG_TRANSLATED_VERSION;
1676 + return $trans;
1246 1677 }
1247 1678 }