templates
1 year ago
SendinblueAccount.php
1 year ago
SendinblueApiClient.php
1 year ago
function.wp_mail.php
8 years ago
http-build-url.php
1 year ago
index.php
8 years ago
mailin.php
3 years ago
push-admin.php
1 year ago
push-amp.php
1 year ago
push-api.php
1 year ago
push-httpclient.php
1 year ago
push-public.php
1 year ago
push-settings.php
1 year ago
push-utils.php
1 year ago
push-woocommerce.php
1 year ago
sendinblue.php
3 years ago
sib-api-manager.php
1 year ago
sib-form-preview.php
2 years ago
sib-sms-code.php
3 years ago
table-forms.php
1 year ago
push-public.php
120 lines
| 1 | <?php |
| 2 | if (!defined( 'ABSPATH' )) { http_response_code(403); exit(); } |
| 3 | |
| 4 | if ( ! class_exists( 'SIB_Push_Public' ) ) { |
| 5 | class SIB_Push_Public { |
| 6 | const INSTALLATION_ID_COOKIE_NAME = 'sbjs_installation_id'; |
| 7 | static function init() { |
| 8 | |
| 9 | // For AMP |
| 10 | add_filter( 'the_content', array(__CLASS__, 'the_content'), 10); |
| 11 | |
| 12 | // Cookie |
| 13 | try { |
| 14 | if (SIB_Push_Utils::get_woocommerce() |
| 15 | && SIB_Push_WooCommerce::cart_reminder_enabled()) { |
| 16 | add_action('wp_head', array(__CLASS__, 'sib_push_cookie'), 10); |
| 17 | } |
| 18 | } catch ( SIB_Push_MissingCredentialsException $e ) { |
| 19 | // Ignore |
| 20 | } catch ( Exception $e ) { |
| 21 | SIB_Push_Utils::log_error($e); |
| 22 | } |
| 23 | |
| 24 | |
| 25 | // AMP support through official plugin (https://amp-wp.org/): |
| 26 | // https://wordpress.org/plugins/amp/ |
| 27 | // Display the snippet and top button |
| 28 | add_action('amp_post_template_body_open', array(__CLASS__, 'amp_post_template_body_open')); |
| 29 | |
| 30 | // AMP support through alternative plugin (AMP for WP, https://ampforwp.com/): |
| 31 | // https://wordpress.org/plugins/accelerated-mobile-pages/ |
| 32 | // Display the snippet and top button |
| 33 | add_filter('ampforwp_after_header', array(__CLASS__, 'ampforwp_after_header'), 10, 3); |
| 34 | |
| 35 | // AMP support, common to both plugins |
| 36 | // Add the official support for web push in AMP |
| 37 | add_filter('amp_post_template_head', array(__CLASS__, 'amp_post_template_head'), 10, 3); |
| 38 | // Add the css |
| 39 | add_action('amp_post_template_css', array(__CLASS__, 'amp_post_template_css')); |
| 40 | // Display the bottom button |
| 41 | add_action('amp_post_template_footer', array(__CLASS__, 'amp_post_template_footer')); |
| 42 | } |
| 43 | |
| 44 | public static function amp_post_template_head() { |
| 45 | if (SIB_Push_Settings::getSettings()->getDisableAmpTopSubscribeButton() |
| 46 | && SIB_Push_Settings::getSettings()->getDisableAmpBottomSubscribeButton()) { |
| 47 | return; |
| 48 | } |
| 49 | ?><script type='text/javascript' src='https://cdn.ampproject.org/v0/amp-web-push-0.1.js' async custom-element="amp-web-push"></script><?php |
| 50 | } |
| 51 | public static function amp_post_template_body_open() { |
| 52 | if (!SIB_Push_Settings::getSettings()->getDisableAmpTopSubscribeButton() |
| 53 | || !SIB_Push_Settings::getSettings()->getDisableAmpBottomSubscribeButton()) { |
| 54 | echo SIB_Push_Amp::snippet(); |
| 55 | } |
| 56 | if (!SIB_Push_Settings::getSettings()->getDisableAmpTopSubscribeButton()) { |
| 57 | echo SIB_Push_Amp::widget(); |
| 58 | } |
| 59 | } |
| 60 | public static function amp_post_template_footer() { |
| 61 | if (SIB_Push_Settings::getSettings()->getDisableAmpBottomSubscribeButton()) { |
| 62 | return; |
| 63 | } |
| 64 | echo SIB_Push_Amp::widget(); |
| 65 | } |
| 66 | public static function amp_post_template_css() { |
| 67 | $plugin_dir_path = plugin_dir_path(__FILE__); |
| 68 | $real_path = realpath($plugin_dir_path . '/../css'); |
| 69 | include ($real_path . '/push-amp.css'); |
| 70 | } |
| 71 | public static function ampforwp_after_header() { |
| 72 | if (!SIB_Push_Settings::getSettings()->getDisableAmpTopSubscribeButton() |
| 73 | || !SIB_Push_Settings::getSettings()->getDisableAmpBottomSubscribeButton()) { |
| 74 | echo SIB_Push_Amp::snippet(); |
| 75 | } |
| 76 | if (!SIB_Push_Settings::getSettings()->getDisableAmpTopSubscribeButton()) { |
| 77 | echo SIB_Push_Amp::widget(); |
| 78 | } |
| 79 | } |
| 80 | public static function the_content($content) { |
| 81 | // Support for transitional mode of the official AMP plugin |
| 82 | // Only single post, attachment, page, custom post types |
| 83 | if ( |
| 84 | is_main_query() |
| 85 | && in_the_loop() |
| 86 | && is_singular() // post, attachment, page, custom post types |
| 87 | ) { |
| 88 | if (SIB_Push_Utils::is_amp_request()) { |
| 89 | $disableTop = SIB_Push_Settings::getSettings()->getDisableAmpTopSubscribeButton(); |
| 90 | $disableBottom = SIB_Push_Settings::getSettings()->getDisableAmpBottomSubscribeButton(); |
| 91 | if ($disableBottom && $disableTop) return $content; |
| 92 | $file_content = SIB_Push_Amp::widget(); |
| 93 | return ($disableTop ? '' : $file_content) . $content . ($disableBottom ? '' : $file_content); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | return $content; |
| 98 | } |
| 99 | |
| 100 | public static function sib_push_cookie() { |
| 101 | if (!SIB_Push_Utils::is_push_active()) return; |
| 102 | ?> |
| 103 | <script> |
| 104 | (function() { |
| 105 | window.addEventListener('WonderPushEvent', function(event) { |
| 106 | if (event.detail.name === 'session') { |
| 107 | window.WonderPush.push(function() { |
| 108 | window.WonderPush.getInstallationId() |
| 109 | .then(function(installationId) { |
| 110 | document.cookie = '<?php echo self::INSTALLATION_ID_COOKIE_NAME ?>=' + encodeURIComponent(installationId || '') + '; expires=' + new Date(new Date().getTime() + 86400000).toGMTString() + '; path=/'; |
| 111 | }); |
| 112 | }); |
| 113 | } |
| 114 | }); |
| 115 | })(); |
| 116 | </script> |
| 117 | <?php |
| 118 | } |
| 119 | } |
| 120 | } |