| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
Plugin Name:Zoho Forms |
| 5 |
Plugin URI: http://wordpress.org/extend/plugins/zohoforms |
| 6 |
Description: Embed forms just about anywhere on your WordPress website. Concentrate on just your content and let us take care of the coding for you. |
| 7 |
Version: 3.0 |
| 8 |
Author: Zoho Forms |
| 9 |
Author URI: https://forms.zoho.com |
| 10 |
*/ |
| 11 |
|
| 12 |
//Shortcode for embeding the form |
| 13 |
|
| 14 |
add_shortcode('zohoForms', 'zohoForms'); |
| 15 |
|
| 16 |
|
| 17 |
function zohoForms($atts, $content = null) { |
| 18 |
extract(shortcode_atts(array( |
| 19 |
'src' => '', |
| 20 |
'width' => '', |
| 21 |
'height' => '', |
| 22 |
'autoheight' => '', |
| 23 |
'type' => '', |
| 24 |
'urlparams' =>'' |
| 25 |
), $atts)); |
| 26 |
|
| 27 |
$src=$atts['src']; |
| 28 |
$height = "600px"; |
| 29 |
$width = "100%"; |
| 30 |
$urlParams = ''; |
| 31 |
if(!empty($atts['height'])){ |
| 32 |
$height = $atts['height']; |
| 33 |
} |
| 34 |
if(!empty($atts['width'])){ |
| 35 |
$width = $atts['width']; |
| 36 |
} |
| 37 |
if(!empty($atts['urlparams'])){ |
| 38 |
$urlParams = $atts['urlparams']; |
| 39 |
} |
| 40 |
if(!empty($atts['type']) &&$atts['type'] == "js"){ |
| 41 |
$idx= strpos($src, "/formperma/"); |
| 42 |
$perma = substr($src, $idx+11); |
| 43 |
|
| 44 |
if(!empty($atts['autoheight']) && $atts['autoheight'] === 'true'){ |
| 45 |
$src.='?zf_rszfm=1'; |
| 46 |
if(!empty($urlParams)){ |
| 47 |
$src.='&'.$urlParams; |
| 48 |
} |
| 49 |
}else { |
| 50 |
if(!empty($urlParams)){ |
| 51 |
$src.='?'.$urlParams; |
| 52 |
} |
| 53 |
} |
| 54 |
$iframeJsCode = 'var f = document.createElement("iframe"); |
| 55 |
f.src = "'.$src.'"; |
| 56 |
f.style.border="none"; |
| 57 |
f.style.height="'.$height.'"; |
| 58 |
f.style.width="'.$width.'"; |
| 59 |
f.style.transition="all 0.5s ease"; |
| 60 |
var d = document.getElementById("zf_div_'.$perma.'"); |
| 61 |
d.appendChild(f);'; |
| 62 |
if(!empty($atts['autoheight']) && $atts['autoheight'] === 'true'){ |
| 63 |
$iframeJsCode.= 'window.addEventListener("message", function () |
| 64 |
{ |
| 65 |
var zf_ifrm_data = event.data.split("|"); |
| 66 |
var zf_perma = zf_ifrm_data[0]; |
| 67 |
var zf_ifrm_ht_nw = ( parseInt(zf_ifrm_data[1], 10) + 15 ) + "px"; |
| 68 |
var iframe = document.getElementById("zf_div_'.$perma.'").getElementsByTagName("iframe")[0]; |
| 69 |
if ( (iframe.src).indexOf("formperma") > 0 && (iframe.src).indexOf(zf_perma) > 0 ) { |
| 70 |
var prevIframeHeight = iframe.style.height; |
| 71 |
if ( prevIframeHeight != zf_ifrm_ht_nw ) { |
| 72 |
iframe.style.height = zf_ifrm_ht_nw; |
| 73 |
} |
| 74 |
} |
| 75 |
}, false);'; |
| 76 |
} |
| 77 |
$jsCodeToEmbed = '<div id="zf_div_'.$perma.'"></div> |
| 78 |
<script type="text/javascript"> |
| 79 |
(function() |
| 80 |
{ |
| 81 |
try{'.$iframeJsCode.'}catch(e){} |
| 82 |
})(); |
| 83 |
</script>'; |
| 84 |
return str_replace('&','&',$jsCodeToEmbed); |
| 85 |
} |
| 86 |
if(!empty($urlParams)){ |
| 87 |
$src.='?'.$urlParams; |
| 88 |
} |
| 89 |
return '<iframe height="'.$height.'" width="'.$width.'" frameborder="0" allowTransparency="true" scrolling="auto" src="'.$src.'"> </iframe>'; |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
// Creation of TinyMCE button |
| 94 |
|
| 95 |
add_action('init', 'add_zohoforms_button'); |
| 96 |
|
| 97 |
// Adding filters for the external plugins. |
| 98 |
|
| 99 |
function add_zohoforms_button() { |
| 100 |
|
| 101 |
add_filter('mce_external_plugins', 'add_zohoForms_plugin'); |
| 102 |
add_filter('mce_buttons', 'register_zohoForms_button'); |
| 103 |
|
| 104 |
} |
| 105 |
|
| 106 |
// Registering the TinyMCE button. |
| 107 |
|
| 108 |
function register_zohoForms_button($buttons) { |
| 109 |
array_push($buttons, "zohoForms"); |
| 110 |
return $buttons; |
| 111 |
} |
| 112 |
|
| 113 |
// Returns the plugin_array which contains the values for the shortcode. |
| 114 |
|
| 115 |
function add_zohoForms_plugin($plugin_array) { |
| 116 |
$plugin_array['zohoForms'] = plugin_dir_url( __FILE__ ) . 'tinymce/zforms_editor_plugin.js'; |
| 117 |
return $plugin_array; |
| 118 |
} |
| 119 |
|
| 120 |
//Including block files |
| 121 |
function loadZohoFormsBlockFiles() { |
| 122 |
wp_enqueue_script( |
| 123 |
'zoho-forms-block-js', |
| 124 |
plugin_dir_url(__FILE__) . 'zohoforms-block.js', |
| 125 |
array('wp-blocks', 'wp-i18n', 'wp-editor'), |
| 126 |
true |
| 127 |
); |
| 128 |
wp_localize_script( 'zoho-forms-block-js', 'zohoFormsBlock', array( |
| 129 |
'blockCSS' => plugin_dir_url(__FILE__) . 'zohoforms-block.css', |
| 130 |
'favIconPath' => plugin_dir_url(__FILE__) . 'tinymce/zFormsIcon.png', |
| 131 |
'footerIcon' => plugin_dir_url(__FILE__) . 'tinymce/zoho-logo.png' |
| 132 |
) ); |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
add_action('enqueue_block_editor_assets', 'loadZohoFormsBlockFiles'); |
| 138 |
|
| 139 |
?> |
| 140 |
|