PluginProbe
VikBooking Hotel Booking Engine & PMS / trunk
VikBooking Hotel Booking Engine & PMS vtrunk
1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 All 35 releases
vikbooking / admin / controllers / feedback.php

feedback.php in VikBooking Hotel Booking Engine & PMS trunk, at admin/controllers/feedback.php

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