| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package VikBooking - Libraries |
| 4 |
* @subpackage html.rss |
| 5 |
* @author E4J s.r.l. |
| 6 |
* @copyright Copyright (C) 2018 E4J s.r.l. All Rights Reserved. |
| 7 |
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 |
* @link https://vikwp.com |
| 9 |
*/ |
| 10 |
|
| 11 |
// No direct access |
| 12 |
defined('ABSPATH') or die('No script kiddies please!'); |
| 13 |
|
| 14 |
$feed = !empty($displayData['feed']) ? $displayData['feed'] : null; |
| 15 |
|
| 16 |
// prepare modal footer |
| 17 |
$footer = '<div style="float: left;">'; |
| 18 |
$footer .= '<input type="checkbox" value="1" id="rss-feed-remind">'; |
| 19 |
$footer .= '<label for="rss-feed-remind" style="line-height: 13px;">' . __('Remind me later') . '</label>'; |
| 20 |
$footer .= '</div>'; |
| 21 |
$footer .= '<button type="button" class="btn btn-danger" id="rss-feed-dismiss">' . __('Don\'t show again', 'vikbooking') . '</button>'; |
| 22 |
|
| 23 |
// prepare modal to display opt-in |
| 24 |
echo JHtml::fetch( |
| 25 |
'bootstrap.renderModal', |
| 26 |
'jmodal-rss-feed', |
| 27 |
array( |
| 28 |
'title' => '<i class="' . VikBookingIcons::i('rss-square') . '"></i> ' . $feed->category . ' - ' . $feed->title, |
| 29 |
'closeButton' => true, |
| 30 |
'keyboard' => false, |
| 31 |
'top' => true, |
| 32 |
'width' => 70, |
| 33 |
'height' => 80, |
| 34 |
'footer' => $footer, |
| 35 |
), |
| 36 |
$feed->content |
| 37 |
); |
| 38 |
|
| 39 |
?> |
| 40 |
|
| 41 |
<style> |
| 42 |
#jmodal-rss-feed img { |
| 43 |
max-width: 100%; |
| 44 |
} |
| 45 |
</style> |
| 46 |
|
| 47 |
<script> |
| 48 |
|
| 49 |
jQuery(function() { |
| 50 |
|
| 51 |
var dismissed = false; |
| 52 |
|
| 53 |
if (typeof localStorage !== 'undefined') { |
| 54 |
dismissed = localStorage.getItem('vikbooking.rss.dismissed.<?php echo $feed->id; ?>') ? true : false; |
| 55 |
} |
| 56 |
|
| 57 |
if (!dismissed) { |
| 58 |
// open modal with a short delay |
| 59 |
setTimeout(function() { |
| 60 |
wpOpenJModal('rss-feed'); |
| 61 |
}, 1500); |
| 62 |
} |
| 63 |
|
| 64 |
jQuery('#rss-feed-remind').on('change', function() { |
| 65 |
var btn = jQuery('#rss-feed-dismiss'); |
| 66 |
|
| 67 |
if (jQuery(this).is(':checked')) { |
| 68 |
btn.removeClass('btn-danger').addClass('btn-success'); |
| 69 |
btn.text('<?php echo addslashes(__('Close')); ?>'); |
| 70 |
} else { |
| 71 |
btn.removeClass('btn-success').addClass('btn-danger'); |
| 72 |
btn.text('<?php echo addslashes(__('Don\'t show again', 'vikbooking')); ?>'); |
| 73 |
} |
| 74 |
}); |
| 75 |
|
| 76 |
jQuery('#rss-feed-dismiss').on('click', function() { |
| 77 |
if (jQuery(this).prop('disabled')) { |
| 78 |
// already submitted |
| 79 |
return false; |
| 80 |
} |
| 81 |
|
| 82 |
jQuery(this).prop('disabled', true); |
| 83 |
|
| 84 |
// prepare request |
| 85 |
var url = 'admin-ajax.php?action=vikbooking&task=rss.'; |
| 86 |
var data = { |
| 87 |
id: '<?php echo $feed->id; ?>', |
| 88 |
}; |
| 89 |
|
| 90 |
// look for reminder option |
| 91 |
if (jQuery('#rss-feed-remind').is(':checked')) { |
| 92 |
url += 'remind'; |
| 93 |
// show again in 2 hours |
| 94 |
data.delay = 120; |
| 95 |
} else { |
| 96 |
url += 'dismiss'; |
| 97 |
} |
| 98 |
|
| 99 |
doAjax( |
| 100 |
url, |
| 101 |
data, |
| 102 |
function(resp) { |
| 103 |
// auto-dismiss on save |
| 104 |
wpCloseJModal('rss-feed'); |
| 105 |
}, |
| 106 |
function(error) { |
| 107 |
if (!error.responseText) { |
| 108 |
// use default connection lost error |
| 109 |
error.responseText = Joomla.JText._('CONNECTION_LOST'); |
| 110 |
} |
| 111 |
|
| 112 |
// alert error message |
| 113 |
alert(error.responseText); |
| 114 |
|
| 115 |
// avoid to spam the dialog again and again at every page load |
| 116 |
if (typeof localStorage !== 'undefined') { |
| 117 |
localStorage.setItem('vikbooking.rss.dismissed.<?php echo $feed->id; ?>', 1); |
| 118 |
} |
| 119 |
|
| 120 |
// auto-dismiss on failure |
| 121 |
wpCloseJModal('rss-feed'); |
| 122 |
} |
| 123 |
); |
| 124 |
}); |
| 125 |
}); |
| 126 |
|
| 127 |
</script> |
| 128 |
|