assets.php
1 month ago
body.php
4 years ago
builder.php
1 month ago
cron.php
4 years ago
feedback.php
4 years ago
gutenberg.php
2 years ago
install.php
1 month ago
mce.php
4 years ago
rssfeeds.php
5 months ago
screen.php
4 years ago
feedback.php
102 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package VikAppointments - Libraries |
| 4 | * @subpackage system |
| 5 | * @author E4J s.r.l. |
| 6 | * @copyright Copyright (C) 2021 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 | /** |
| 15 | * Helper class used to collect the feedback of the users. |
| 16 | * Should be attached to `plugin_action_links` WordPress filter. |
| 17 | * |
| 18 | * @since 1.1.2 |
| 19 | */ |
| 20 | class VikAppointmentsFeedback |
| 21 | { |
| 22 | /** |
| 23 | * Attaches a feeback modal to the deactivation button. |
| 24 | * |
| 25 | * @param array $actions An array of plugin action links. |
| 26 | * @param string $plugin Path to the plugin file relative to the plugins directory. |
| 27 | * |
| 28 | * @return array The filtered actions. |
| 29 | */ |
| 30 | public static function deactivate($actions, $plugin) |
| 31 | { |
| 32 | // make sure the plugin is recaptcha and the deactivation link is available |
| 33 | if ($plugin != 'vikappointments/vikappointments.php' || !isset($actions['deactivate'])) |
| 34 | { |
| 35 | return $actions; |
| 36 | } |
| 37 | |
| 38 | $input = JFactory::getApplication()->input; |
| 39 | |
| 40 | // check whether the safe-word is set in the request |
| 41 | if ($input->getUint('feedback', 1) === 0) |
| 42 | { |
| 43 | // skip deactivation feedback |
| 44 | return $actions; |
| 45 | } |
| 46 | |
| 47 | // check if the user already submitted the feedback in the last week |
| 48 | if ($input->cookie->getBool('vikappointments_feedback')) |
| 49 | { |
| 50 | // feedback already done, avoid to ask for it one more time |
| 51 | return $actions; |
| 52 | } |
| 53 | |
| 54 | // extract deactivation URL from link |
| 55 | if (!preg_match("/href=\"([^\"]*)\"/i", $actions['deactivate'], $match)) |
| 56 | { |
| 57 | // unable to extract URL from deactivation link |
| 58 | return $actions; |
| 59 | } |
| 60 | |
| 61 | $deactivate_url = end($match); |
| 62 | |
| 63 | // define URL to popup thickbox |
| 64 | $url = '#TB_inline?width=500&height=400&inlineId=vikappointments-feedback'; |
| 65 | |
| 66 | $__title = __('Feedback', 'vikappointments'); |
| 67 | |
| 68 | // add support for feedback |
| 69 | $actions['deactivate'] = sprintf( |
| 70 | '<a href="%s" class="thickbox" aria-label="%s" data-name="%s">%s</a>', |
| 71 | esc_attr($url), |
| 72 | esc_attr(sprintf(__('Deactivate %s', 'plugin'), 'VikAppointments')), |
| 73 | esc_attr($__title), |
| 74 | __('Deactivate') |
| 75 | ); |
| 76 | |
| 77 | // append thickbox to admin footer |
| 78 | add_action('admin_footer', function() use ($deactivate_url) |
| 79 | { |
| 80 | // make URL safe for JS |
| 81 | $deactivate_url_js = str_replace('&', '&', $deactivate_url); |
| 82 | |
| 83 | VikAppointmentsLoader::import('update.license'); |
| 84 | |
| 85 | $data = array( |
| 86 | 'url' => $deactivate_url_js, |
| 87 | 'pro' => (bool) VikAppointmentsLicense::isPro(), |
| 88 | ); |
| 89 | |
| 90 | // display feedback thickbox |
| 91 | echo JLayoutHelper::render( |
| 92 | 'html.feedback.thickbox', |
| 93 | $data, |
| 94 | null, |
| 95 | array('component' => 'com_vikappointments') |
| 96 | ); |
| 97 | }); |
| 98 | |
| 99 | return $actions; |
| 100 | } |
| 101 | } |
| 102 |