acl.php
2 days ago
feedback.php
2 days ago
license.php
2 days ago
override.php
2 days ago
rss.php
2 days ago
shortcode.php
2 days ago
shortcodes.php
2 days ago
feedback.php
177 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package VikAppointments |
| 4 | * @subpackage core |
| 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 | VAPLoader::import('libraries.mvc.controllers.admin'); |
| 15 | |
| 16 | /** |
| 17 | * VikAppointments plugin Feedback controller. |
| 18 | * |
| 19 | * @since 1.1.2 |
| 20 | */ |
| 21 | class VikAppointmentsControllerFeedback extends VAPControllerAdmin |
| 22 | { |
| 23 | /** |
| 24 | * Submits a feedback to VikWP servers after deactivating the plugin. |
| 25 | * |
| 26 | * @return void |
| 27 | */ |
| 28 | public function submit() |
| 29 | { |
| 30 | if (!JFactory::getUser()->authorise('core.admin', 'com_vikappointments')) |
| 31 | { |
| 32 | // not authorised to view this resource |
| 33 | throw new Exception(JText::translate('RESOURCE_AUTH_ERROR'), 403); |
| 34 | } |
| 35 | |
| 36 | $input = JFactory::getApplication()->input; |
| 37 | |
| 38 | // validation end-points |
| 39 | $url = 'https://vikwp.com/api/?task=logs.track'; |
| 40 | |
| 41 | $version = new JVersion(); |
| 42 | |
| 43 | $env = array( |
| 44 | 'ipaddr' => $input->server->getString('REMOTE_ADDR'), |
| 45 | 'wpver' => $version->getLongVersion(), |
| 46 | 'version' => VIKAPPOINTMENTS_SOFTWARE_VERSION, |
| 47 | 'phpver' => phpversion(), |
| 48 | ); |
| 49 | |
| 50 | $body = print_r($env, true); |
| 51 | |
| 52 | $notes = $input->getString('notes'); |
| 53 | |
| 54 | if ($notes) |
| 55 | { |
| 56 | $body = $notes . "\n\n" . $body; |
| 57 | } |
| 58 | |
| 59 | // init HTTP transport |
| 60 | $http = new JHttp(); |
| 61 | |
| 62 | // build post data |
| 63 | $data = array( |
| 64 | 'type' => 'feedback.vikappointments', |
| 65 | 'desc' => $input->getString('type'), |
| 66 | 'body' => $body, |
| 67 | ); |
| 68 | |
| 69 | // build headers |
| 70 | $headers = array( |
| 71 | /** |
| 72 | * Always bypass SSL validation while reaching our end-point. |
| 73 | * |
| 74 | * @since 1.2 |
| 75 | */ |
| 76 | 'sslverify' => false, |
| 77 | ); |
| 78 | |
| 79 | // make connection with VikWP server |
| 80 | $response = $http->post($url, $data, $headers); |
| 81 | |
| 82 | if ($response->code != 200) |
| 83 | { |
| 84 | // raise error returned by VikWP |
| 85 | throw new Exception($response->body, $response->code); |
| 86 | } |
| 87 | |
| 88 | echo $response->body; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Submits a survey to VikWP servers. |
| 93 | * |
| 94 | * @return void |
| 95 | */ |
| 96 | public function survey() |
| 97 | { |
| 98 | if (!JFactory::getUser()->authorise('core.admin', 'com_vikappointments')) |
| 99 | { |
| 100 | // not authorised to view this resource |
| 101 | throw new Exception(JText::translate('RESOURCE_AUTH_ERROR'), 403); |
| 102 | } |
| 103 | |
| 104 | $input = JFactory::getApplication()->input; |
| 105 | |
| 106 | // validation end-points |
| 107 | $url = 'https://vikwp.com/api/?task=logs.track'; |
| 108 | |
| 109 | $version = new JVersion(); |
| 110 | |
| 111 | $env = array( |
| 112 | 'wpver' => $version->getLongVersion(), |
| 113 | 'version' => VIKAPPOINTMENTS_SOFTWARE_VERSION, |
| 114 | 'phpver' => phpversion(), |
| 115 | ); |
| 116 | |
| 117 | // include environment details |
| 118 | $body = print_r($env, true); |
| 119 | |
| 120 | // get form from request |
| 121 | $form = $input->get('survey', array(), 'array'); |
| 122 | |
| 123 | // filter form to exclude empty data, then reset keys |
| 124 | $form = array_values(array_filter($form)); |
| 125 | |
| 126 | if (!$form) |
| 127 | { |
| 128 | // the survey doesn't contain data |
| 129 | throw new Exception('Empty survey', 400); |
| 130 | } |
| 131 | |
| 132 | // map array to indent new lines |
| 133 | $form = array_map(function($str) |
| 134 | { |
| 135 | // add 2 white spaces after every new line |
| 136 | return preg_replace("/\R/", "\n ", $str); |
| 137 | }, $form); |
| 138 | |
| 139 | // prepend survey |
| 140 | $body = '* ' . implode("\n* ", $form) . "\n\n" . $body; |
| 141 | |
| 142 | // retrieve subject from request |
| 143 | $subject = $input->get('subject', 'Survey', 'string'); |
| 144 | |
| 145 | // init HTTP transport |
| 146 | $http = new JHttp(); |
| 147 | |
| 148 | // build post data |
| 149 | $data = array( |
| 150 | 'type' => 'survey.vikappointments', |
| 151 | 'desc' => $subject, |
| 152 | 'body' => $body, |
| 153 | ); |
| 154 | |
| 155 | // build headers |
| 156 | $headers = array( |
| 157 | /** |
| 158 | * Always bypass SSL validation while reaching our end-point. |
| 159 | * |
| 160 | * @since 1.2 |
| 161 | */ |
| 162 | 'sslverify' => false, |
| 163 | ); |
| 164 | |
| 165 | // make connection with VikWP server |
| 166 | $response = $http->post($url, $data, $headers); |
| 167 | |
| 168 | if ($response->code != 200) |
| 169 | { |
| 170 | // raise error returned by VikWP |
| 171 | throw new Exception($response->body, $response->code); |
| 172 | } |
| 173 | |
| 174 | echo $response->body; |
| 175 | } |
| 176 | } |
| 177 |