CustomFonts.php
3 years ago
Export.php
2 months ago
FieldNameObfuscator.php
3 years ago
Styles.php
3 years ago
index.php
3 years ago
Export.php
114 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\Form\Util; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Config\Env; |
| 9 | use MailPoet\Form\Widget; |
| 10 | use MailPoet\Settings\SettingsController; |
| 11 | use MailPoet\WP\Functions as WPFunctions; |
| 12 | |
| 13 | class Export { |
| 14 | public static function getAll() { |
| 15 | return [ |
| 16 | 'html' => static::get('html'), |
| 17 | 'php' => static::get('php'), |
| 18 | 'iframe' => static::get('iframe'), |
| 19 | 'shortcode' => static::get('shortcode'), |
| 20 | ]; |
| 21 | } |
| 22 | |
| 23 | public static function get($type = 'html') { |
| 24 | switch ($type) { |
| 25 | case 'iframe': |
| 26 | // generate url to load iframe's content |
| 27 | $iframeUrl = WPFunctions::get()->addQueryArg([ |
| 28 | 'mailpoet_form_iframe' => ':form_id:', |
| 29 | ], WPFunctions::get()->trailingslashit(WPFunctions::get()->siteUrl())); |
| 30 | |
| 31 | $onload = "var _this = this; window.addEventListener('message', function(e) {if(e.data.MailPoetIframeHeight){_this.style.height = e.data.MailPoetIframeHeight;}})"; |
| 32 | // generate iframe |
| 33 | return join(' ', [ |
| 34 | '<iframe', |
| 35 | 'width="100%"', |
| 36 | 'height="100%"', |
| 37 | 'scrolling="no"', |
| 38 | 'frameborder="0"', |
| 39 | 'src="' . WPFunctions::get()->escUrl($iframeUrl) . '"', |
| 40 | 'class="mailpoet_form_iframe"', |
| 41 | 'id="mailpoet_form_iframe"', |
| 42 | 'vspace="0"', |
| 43 | 'tabindex="0"', |
| 44 | sprintf('onload="%s"', $onload), |
| 45 | 'marginwidth="0"', |
| 46 | 'marginheight="0"', |
| 47 | 'hspace="0"', |
| 48 | 'allowtransparency="true"></iframe>', |
| 49 | ]); |
| 50 | |
| 51 | case 'php': |
| 52 | $output = [ |
| 53 | '$form_widget = new \MailPoet\Form\Widget();', |
| 54 | 'echo $form_widget->widget(array(\'form\' => ' . |
| 55 | ':form_id:' . |
| 56 | ', \'form_type\' => \'php\'));', |
| 57 | ]; |
| 58 | return join("\n", $output); |
| 59 | |
| 60 | case 'html': |
| 61 | $output = []; |
| 62 | |
| 63 | $output[] = '<!-- ' . |
| 64 | __( |
| 65 | 'BEGIN Scripts: you should place them in the header of your theme', |
| 66 | 'mailpoet' |
| 67 | ) . |
| 68 | ' -->'; |
| 69 | |
| 70 | // CSS |
| 71 | $output[] = '<link rel="stylesheet" type="text/css" href="' . |
| 72 | Env::$assetsUrl . '/dist/css/mailpoet-public.css?mp_ver=' . MAILPOET_VERSION . |
| 73 | '" />'; |
| 74 | |
| 75 | // jQuery |
| 76 | $output[] = '<script type="text/javascript" src="' . |
| 77 | WPFunctions::get()->includesUrl() . 'js/jquery/jquery.js?mp_ver' . MAILPOET_VERSION . |
| 78 | '"></script>'; |
| 79 | |
| 80 | // JS |
| 81 | $output[] = '<script type="text/javascript" src="' . |
| 82 | Env::$assetsUrl . '/dist/js/vendor.js?mp_ver=' . MAILPOET_VERSION . |
| 83 | '"></script>'; |
| 84 | $output[] = '<script type="text/javascript" src="' . |
| 85 | Env::$assetsUrl . '/dist/js/public.js?mp_ver=' . MAILPOET_VERSION . |
| 86 | '"></script>'; |
| 87 | |
| 88 | $collectSubscriberTimeZones = SettingsController::getInstance()->isSettingEnabled( |
| 89 | 'collect_subscriber_timezones.enabled' |
| 90 | ); |
| 91 | $output[] = '<script type="text/javascript">'; |
| 92 | $output[] = ' var MailPoetForm = MailPoetForm || {'; |
| 93 | $output[] = ' is_rtl: ' . ((int)is_rtl()) . ","; |
| 94 | $output[] = ' collect_subscriber_timezones: ' . ($collectSubscriberTimeZones ? 'true' : 'false') . ','; |
| 95 | $output[] = ' ajax_url: "' . admin_url('admin-ajax.php') . '"'; |
| 96 | $output[] = ' };'; |
| 97 | $output[] = '</script>'; |
| 98 | $output[] = '<!-- ' . |
| 99 | __('END Scripts', 'mailpoet') . |
| 100 | '-->'; |
| 101 | |
| 102 | $formWidget = new Widget(); |
| 103 | $output[] = $formWidget->widget([ |
| 104 | 'form' => ':form_id:', |
| 105 | 'form_type' => 'php', |
| 106 | ]); |
| 107 | return join("\n", $output); |
| 108 | |
| 109 | case 'shortcode': |
| 110 | return '[mailpoet_form id=":form_id:"]'; |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 |