/** * Share list via email * * @since 1.0 */ function edd_wl_modal_share_via_email() { $messages = edd_wl_messages(); // only load on view page, when email sharing is present if (!(edd_wl_is_view_page() && edd_wl_sharing_is_enabled('email'))) { return; } $list_id = get_query_var('wl_view'); ?> <form class="wish-list-form" id="edd-wl-share-email-form" method="get" action=""> <div class="modal-header"> <h2 id="edd-wl-modal-label"> <?php echo $messages['modal_share_title']; ?> </h2> <a class="edd-wl-close" href="#" data-dismiss="modal"> <i class="glyphicon glyphicon-remove"></i> <span class="hide-text"><?php _e('Close', 'edd-wish-lists'); ?> </span> </a> </div> <div class="modal-body"> <?php // get template edd_get_template_part('wish-list-email-share'); ?> <input type="hidden" name="submitted" id="submitted" value="true"> <input name="referrer" type="hidden" value="<?php echo get_the_ID(); ?> "> <?php wp_nonce_field('share_via_email_nonce', 'share_via_email_nonce_field'); ?> </div> <div class="modal-footer"> <a href="#" data-action="edd_wl_share_via_email" data-post-id="<?php echo $list_id; ?> " class="edd-wl-button edd-wl-action edd-wl-share-via-email"> <span class="label"><?php _e('Send Now', 'edd-wish-lists'); ?> </span> <span class="edd-loading"><i class="edd-icon-spinner edd-icon-spin"></i></span> </a> </div> </form> <?php }
/** * Get a wish list * * @param int $wish_list_id the ID of the wish list * @return array the contents of the wish list * @since 1.0 * @todo remove favorites code */ function edd_wl_get_wish_list($list_id = '') { // use query var for list if on view page if (edd_wl_is_view_page()) { $list_id = get_query_var('view'); } // retrieve the wish list return apply_filters('edd_wl_get_wish_list', get_post_meta($list_id, 'edd_wish_list', true)); }
/** * Print scripts * * @since 1.0 */ function edd_wl_sharing_print_scripts() { global $edd_options; if (!edd_wl_is_view_page()) { return; } ?> <script type="text/javascript"> <?php /** * Twitter * * @since 1.0 */ if (edd_wl_sharing_is_enabled('twitter')) { ?> window.twttr = (function (d,s,id) { var t, js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js=d.createElement(s); js.id=id; js.src="https://platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs); return window.twttr || (t = { _e: [], ready: function(f){ t._e.push(f) } }); }(document, "script", "twitter-wjs")); twttr.ready(function (twttr) { twttr.events.bind('tweet', function (event) { jQuery.event.trigger({ type: "listShared", url: event.target.baseURI }); }); }); <?php } ?> <?php /** * Google + * * @since 1.0 */ if (edd_wl_sharing_is_enabled('googleplus')) { $locale = apply_filters('edd_wl_googleplus_locale', 'en-US'); ?> window.___gcfg = { lang: '<?php echo $locale; ?> ', parsetags: 'onload' }; (function() { var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; po.src = 'https://apis.google.com/js/plusone.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); })(); function plusOned(obj) { console.log(obj); jQuery.event.trigger({ type: "listShared", url: obj.href }); } <?php } ?> <?php /** * LinkedIn * * @since 1.0 */ if (edd_wl_sharing_is_enabled('linkedin')) { ?> function share(url) { console.log(url); jQuery.event.trigger({ type: "listShared", url: url }); } <?php } ?> <?php /** * Facebook * * @since 1.0 */ if (edd_wl_sharing_is_enabled('facebook')) { // defaults to en_US if left blank $locale = apply_filters('edd_wl_facebook_locale', 'en_US'); ?> (function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) {return;} js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/<?php echo $locale; ?> /all.js"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); window.fbAsyncInit = function() { // init the FB JS SDK FB.init({ status : true, cookie : true, xfbml : true }); FB.Event.subscribe('edge.create', function(href, widget) { jQuery.event.trigger({ type: "listShared", url: href }); }); }; <?php } ?> <?php /** * Listen for the productShared event * * @since 1.0 */ if (edd_wl_sharing_is_enabled()) { ?> jQuery(document).ready(function ($) { jQuery(document).on( 'listShared', function(e) { if( e.url == window.location.href ) { var postData = { action: 'share_list', list_id: <?php echo get_the_ID(); ?> , nonce: edd_wl_scripts.ajax_nonce }; $.ajax({ type: "POST", data: postData, dataType: "json", url: edd_wl_vars.ajaxurl, success: function ( share_response ) { } }).fail(function (data) { console.log( data ); }); } }); }); <?php } ?> </script> <?php }
/** * Filter the page titles * * @since 1.0 */ function edd_wl_the_title($title, $id = '') { // prevent the title from changing if (edd_wl_is_private_list()) { return $title; } // View page - replace the main page title with the name of the list if (edd_wl_is_view_page() && get_query_var('view') && in_the_loop() && $id == get_the_ID()) { $title = get_the_title(get_query_var('view')); } return $title; }
/** * Load validation on view page */ function edd_wl_validate() { if (!(edd_wl_is_view_page() && edd_wl_sharing_is_enabled('email'))) { return; } ?> <script> jQuery(document).ready(function ($) { var clone = $('#edd-wl-modal .modal-content').clone(); // replace modal with clone when closed // jQuery('#edd-wl-modal').on('hidden.bs.modal', function (e) { // jQuery("#edd-wl-modal .modal-content").replaceWith( clone ); // console.log('modal closed'); // }); $('body').on('click.eddwlShareViaEmail', '.edd-wl-share-via-email', function (e) { e.preventDefault(); // submit form $('#edd-wl-share-email-form').submit(); }); // multi email validation jQuery.validator.addMethod( "multiemail", function (value, element) { var email = value.split(/[;,]+/); // split element by , and ; valid = true; for (var i in email) { value = email[i]; valid = valid && jQuery.validator.methods.email.call(this, $.trim(value), element); } return valid; }, jQuery.validator.messages.multiemail ); $("#edd-wl-share-email-form").validate({ errorClass: "edd_errors", highlight: function(element, errorClass) { $(element).removeClass(errorClass); }, submitHandler: function(form) { console.log('form submitted'); var $spinner = $('.edd-wl-share-via-email').find('.edd-loading'), spinnerWidth = $spinner.width(), spinnerHeight = $spinner.height(), submitButton = $('.edd-wl-share-via-email'); // Show the spinner submitButton.attr('data-edd-loading', ''); $spinner.css({ 'margin-left': spinnerWidth / -2, 'margin-top' : spinnerHeight / -2 }); var data = { action: submitButton.data('action'), post_id: submitButton.data('post-id'), from_name: $('input[name=edd_wl_from_name]').val(), from_email: $('input[name=edd_wl_from_email]').val(), emails: $('input[name=edd_wl_share_emails]').val(), message: $('textarea[name=edd_wl_share_message]').val(), referrer: $('input[name=referrer]').val(), nonce: edd_wl_scripts.ajax_nonce }; $.ajax({ type: "POST", data: data, dataType: "json", url: edd_scripts.ajaxurl, success: function (response) { $('.edd-wl-share-via-email').removeAttr('data-edd-loading'); $('a.edd-wl-share-via-email').addClass('edd-has-js'); $('.edd-no-js').hide(); // clear form $('input[type=text], textarea', form).val(''); // replace modal contents with success contents $('#edd-wl-modal .modal-content').empty().append( response.success ); } }) .fail(function (response) { console.log(response); }) .done(function (response) { console.log(response); }); } }); }); </script> <?php }