PluginProbe ʕ •ᴥ•ʔ
Event Tickets with Ticket Scanner / 2.8.4
Event Tickets with Ticket Scanner v2.8.4
3.1.2 3.1.1 3.1.0 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.4 trunk 2.6.0 2.7.0 2.7.1 2.7.10 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.10 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.0 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 2.9.9 3.0.0 3.0.1 3.0.2 3.0.3
event-tickets-with-ticket-scanner / SASO_EVENTTICKETS.php
event-tickets-with-ticket-scanner Last commit date
3rd 5 months ago css 5 months ago img 5 months ago includes 5 months ago js 5 months ago languages 5 months ago ticket 5 months ago vendors 5 months ago .gitignore 5 months ago SASO_EVENTTICKETS.php 5 months ago backend.js 5 months ago changelog.txt 5 months ago db.php 5 months ago index.php 5 months ago init_file.php 5 months ago order_details.js 5 months ago readme.txt 5 months ago saso-eventtickets-validator.js 5 months ago sasoEventtickets_AdminSettings.php 5 months ago sasoEventtickets_Authtoken.php 5 months ago sasoEventtickets_Base.php 5 months ago sasoEventtickets_Core.php 5 months ago sasoEventtickets_Frontend.php 5 months ago sasoEventtickets_Messenger.php 5 months ago sasoEventtickets_Options.php 5 months ago sasoEventtickets_PDF.php 5 months ago sasoEventtickets_Seating.php 5 months ago sasoEventtickets_Ticket.php 5 months ago sasoEventtickets_TicketBadge.php 5 months ago sasoEventtickets_TicketDesigner.php 5 months ago sasoEventtickets_TicketQR.php 5 months ago ticket_events.js 5 months ago ticket_scanner.js 5 months ago validator.js 5 months ago wc_backend.js 5 months ago wc_frontend.js 5 months ago woocommerce-hooks.php 5 months ago
SASO_EVENTTICKETS.php
376 lines
1 <?php
2 include_once(plugin_dir_path(__FILE__)."init_file.php");
3 if (!class_exists('SASO_EVENTTICKETS', false)) {
4 class SASO_EVENTTICKETS {
5 static $DB;
6 static $REQUEST_DATA;
7 /**
8 * @param $plugin_dir_path plugin_dir_path(__FILE__)
9 */
10 public static function getDB($plugin_dir_path, $className, $MAIN) {
11 if (self::$DB == null) {
12 if (!class_exists($className)) {
13 include_once $plugin_dir_path."db.php";
14 }
15 self::$DB = new $className($MAIN);
16 self::$DB->installiereTabellen(); // schützt sich selbst mit eigener option-var
17 }
18 return self::$DB;
19 }
20 public static function getMediaData($mediaid) {
21 $mediaid = intval($mediaid);
22 $filelocation = wp_get_original_image_path($mediaid, true);
23 $meta = wp_get_attachment_metadata( $mediaid );
24 $url = wp_get_attachment_url($mediaid);
25 $titel = get_the_title($mediaid);
26 $suffix = strtolower(substr(strrchr($url, '.'),1));
27 if ($suffix == "pdf") {
28 $filelocation = get_attached_file($mediaid);
29 }
30 // check file location
31 $for_pdf = $filelocation;
32 if (empty($for_pdf) || !file_exists($for_pdf)) {
33 $for_pdf = $url;
34 }
35 return ['title'=>$titel,'location'=>$filelocation,'meta'=>$meta,'url'=>$url, "suffix"=>$suffix, "for_pdf"=>$for_pdf];
36 }
37 public static function getRESTPrefixURL() {
38 return basename(dirname(__FILE__));
39 }
40 // use SASO_EVENTTICKETS::getRequestPara(
41 public static function getRequestPara($name, $def=null) {
42 $request = self::getRequest();
43 return isset($request[$name]) ? $request[$name] : $def;
44 }
45 public static function getRequest() {
46 if (self::$REQUEST_DATA == null) {
47 $ret = null;
48 switch ($_SERVER['REQUEST_METHOD']) {
49 case 'POST':
50 $ret = $_POST;
51 if (empty($ret)) {
52 $ret = $_GET;
53 } else {
54 $ret = array_merge($ret, $_GET);
55 }
56 break;
57 case 'GET':
58 $ret = $_GET;
59 break;
60 case 'PUT':
61 $putdata = file_get_contents("php://input");
62 parse_str($putdata, $ret);
63 break;
64 }
65 self::$REQUEST_DATA = $ret;
66 }
67 return self::$REQUEST_DATA;
68 }
69 // use SASO_EVENTTICKETS::issetRPara(
70 public static function issetRPara($name) {
71 if ($_SERVER['REQUEST_METHOD'] === 'POST') {
72 if (isset($_POST[$name])) return true;
73 if (isset($_GET[$name])) return true;
74 return false;
75 }
76 if ($_SERVER['REQUEST_METHOD'] === 'GET') {
77 if (isset($_GET[$name])) return true;
78 return false;
79 }
80 return false;
81 }
82 public static function PasswortGenerieren($anzahl=8) {
83 $werte = array_merge(array(2,3,4,5,6,7,8,9), array("a","b","c","d","e","f","g","h","j","k","m","n","p","q","r","s","t","w","x","y","z"));
84 $pw = "";
85 for ($a=0;$a<$anzahl;$a++):
86 shuffle($werte);
87 $zufallszahl = rand(0, count($werte)-1);
88 $buchstabe = $werte[$zufallszahl];
89 if ($a == 0 && $buchstabe == ".")
90 $buchstabe = "a"; // weil man den Punkt am Anfang nicht sieht
91 $pw .= $buchstabe;
92 endfor;
93 return $pw;
94 }
95 public static function _basics_sendeDateiCSVvonDBdaten($daten, $filename, $delimiter=";") {
96 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
97 header('Content-Description: File Transfer');
98 header('Content-type: text/csv');
99 header('Content-Disposition: attachment; filename="'.$filename.'"');
100 header('Expires: 0');
101 header('Pragma: public');
102
103 ob_end_clean();
104 $out = fopen('php://output', 'w');
105
106 if (count($daten) > 0) {
107 fputcsv($out, array_keys($daten[0]), $delimiter);
108 foreach($daten as $value) {
109 fputcsv($out, array_values($value), $delimiter);
110 }
111 } else {
112 fputcsv($out, array("no data"), $delimiter);
113 }
114 fclose($out);
115 }
116 public static function sendeDaten($daten, $name, $type)
117 {
118 header('Content-type: '.$type);
119 header('Content-Disposition: inline; filename="'.$name.'"');
120 header('Expires: 0');
121 header('Pragma: public');
122 echo $daten;
123 }
124 public static function sendeDatei($datei, $bandbreitekontrolle=1, $bandbreite=256, $contenttype=false, $range_start=0, $range_stop=0) {
125 if (!file_exists($datei)) {
126 return false;
127 }
128
129 header("Accept-Ranges: bytes");
130
131 if (is_array($contenttype)) {
132 if (isset($contenttype['Content-Type'])) {
133 header ("Content-Type: ".$contenttype['Content-Type']);
134 }
135 } else if ($contenttype) {
136 $vdatei = $datei;
137 switch(substr($vdatei,0,1)){
138 case "/":
139 case "\\":
140 break;
141 default:
142 switch(substr($vdatei,0,2)){
143 case "./":
144 case ".\\":
145 $vdatei = substr($vdatei,1);
146 }
147 $vdatei = dirslash(dirname(__FILE__)).$vdatei;
148 }
149
150 if (function_exists("finfo_open")){
151 $finfo = finfo_open(FILEINFO_MIME_TYPE);
152 $mime = finfo_file($finfo, $vdatei);
153 } else {
154 $mime = "application/octet-stream";
155 }
156 header ("Content-Type: ".$mime);
157 }
158
159 // range_start und range_stop legen die virtuelle dateigrösse fest
160 $von = 0;
161 $size = filesize($datei);
162 if ($range_start > 0)
163 $size -= $range_start;
164 if ($range_stop > $size)
165 $range_stop = 0;
166 if ($range_stop > 0)
167 $size = $range_stop-$range_start + 1;
168
169 //check if http_range is sent by browser (or download manager)
170 if(isset($_SERVER['HTTP_RANGE'])) {
171 list($a, $range)=explode("=",$_SERVER['HTTP_RANGE']);
172 //if yes, download missing part
173 list($von,$bis)=explode("-",$range);
174 $bis = intval($bis);
175 $von = intval($von);
176 if ($bis == 0 || $bis < $von || $bis > $size)
177 $bis = $size - 1; // bis zum ende
178 $range_stop = $bis;
179 $new_length = $bis - $von + 1;
180 header("HTTP/1.1 206 Partial Content");
181 header("Content-Length: $new_length");
182 header("Content-Range: bytes ".$von."-".$bis."/".$size);
183 } else {
184 $size2=$size;
185 $range_stop = $size - 1;
186 //header("Content-Range: bytes 0-".$size2."/".$size);
187 header("Content-Length: ".$size2);
188 }
189 header("Content-Transfer-Encoding: binary");
190 //open the file
191 $fp=fopen($datei,"rb");
192 if (!$fp)
193 return false;
194
195 if ($range_start > 0)
196 $von += $range_start;
197
198 fseek($fp,$von);
199
200 //start buffered download
201 $a=0;
202 $buffersize = 4096;
203 $bandbreite = intval($bandbreite);
204 if ($bandbreite < 1)
205 $bandbreite = 128; // 32*4*1024 = 128kb
206 $wartezeit = $bandbreite * 1000 / $buffersize;
207
208 $gesendetbytes = 0;
209 while(!feof($fp)) {
210 if (connection_aborted()) {
211 fclose($fp);
212 return false;
213 }
214 //reset time limit for big files
215 @set_time_limit(0);
216 echo (fread($fp, $buffersize));
217 $gesendetbytes += $buffersize;
218 if ($range_stop > 0 && $gesendetbytes >= $size)
219 break; // vorzeitig fertig;
220 if ($bandbreitekontrolle == 1):
221 if ($a<1):
222 sleep(1);
223 $a=$wartezeit; // wartezeit bevor ich wieder ne sekunde warte
224 endif;
225 $a--;
226 endif;
227 }
228 fclose($fp);
229 return true;
230 }
231
232 public static function setRestRoutesTicket() {
233 $prefix = SASO_EVENTTICKETS::getRESTPrefixURL();
234 register_rest_route($prefix.'/ticket/scanner', '/ping', [
235 ['methods'=>WP_REST_SERVER::READABLE, 'callback'=>'SASO_EVENTTICKETS::rest_ping', 'permission_callback'=>function(){return true;}]
236 ]);
237 register_rest_route($prefix.'/ticket/scanner', '/retrieve_ticket', [
238 ['methods'=>WP_REST_SERVER::READABLE, 'callback'=>'SASO_EVENTTICKETS::rest_retrieve_ticket', 'args'=>['code'=>['required'=>true]], 'permission_callback'=>'SASO_EVENTTICKETS::rest_permission_callback']
239 ]);
240 register_rest_route($prefix.'/ticket/scanner', '/redeem_ticket', [
241 ['methods'=>WP_REST_SERVER::READABLE, 'callback'=>'SASO_EVENTTICKETS::rest_redeem_ticket', 'args'=>['code'=>['required'=>true]], 'permission_callback'=>'SASO_EVENTTICKETS::rest_permission_callback']
242 ]);
243 register_rest_route($prefix.'/ticket/scanner', '/downloadPDFTicketBadge', [
244 ['methods'=>WP_REST_SERVER::READABLE, 'callback'=>'SASO_EVENTTICKETS::rest_downloadPDFTicketBadge', 'args'=>['code'=>['required'=>true]], 'permission_callback'=>'SASO_EVENTTICKETS::rest_permission_callback']
245 ]);
246 register_rest_route($prefix.'/ticket/scanner', '/seating_plan', [
247 ['methods'=>WP_REST_SERVER::READABLE, 'callback'=>'SASO_EVENTTICKETS::rest_seating_plan', 'args'=>['plan_id'=>['required'=>true], 'seat_id'=>['required'=>false]], 'permission_callback'=>'SASO_EVENTTICKETS::rest_permission_callback']
248 ]);
249 }
250 public static function rest_permission_callback($web_request) {
251 try {
252 include_once plugin_dir_path(__FILE__)."sasoEventtickets_Ticket.php";
253 $ticket = sasoEventtickets_Ticket::Instance($_SERVER["REQUEST_URI"]);
254 wp_create_nonce( 'wp_rest' );
255 return $ticket->rest_permission_callback($web_request);
256 } catch (Exception $e) {
257 wp_send_json_error($e->getMessage());
258 }
259 return false;
260 }
261 public static function rest_ping($web_request) {
262 try {
263 include_once plugin_dir_path(__FILE__)."sasoEventtickets_Ticket.php";
264 $ticket = sasoEventtickets_Ticket::Instance($_SERVER["REQUEST_URI"]);
265 $ret = $ticket->rest_ping($web_request);
266 $ret['nonce'] = wp_create_nonce( 'wp_rest' );
267 wp_send_json_success($ret);
268 } catch (Exception $e) {
269 wp_send_json_error($e->getMessage());
270 }
271 }
272 public static function rest_retrieve_ticket($web_request) {
273 try {
274 include_once plugin_dir_path(__FILE__)."sasoEventtickets_Ticket.php";
275 $ticket = sasoEventtickets_Ticket::Instance($_SERVER["REQUEST_URI"]);
276 $ret = $ticket->rest_retrieve_ticket($web_request);
277 $ret['nonce'] = wp_create_nonce( 'wp_rest' );
278 wp_send_json_success($ret);
279 } catch (Exception $e) {
280 wp_send_json_error($e->getMessage());
281 }
282 }
283 public static function rest_redeem_ticket($web_request) {
284 try {
285 include_once plugin_dir_path(__FILE__)."sasoEventtickets_Ticket.php";
286 $ticket = sasoEventtickets_Ticket::Instance($_SERVER["REQUEST_URI"]);
287 $ret = $ticket->rest_redeem_ticket($web_request);
288 $ret['nonce'] = wp_create_nonce( 'wp_rest' );
289 wp_send_json_success($ret);
290 } catch (Exception $e) {
291 wp_send_json_error($e->getMessage());
292 }
293 }
294 public static function rest_downloadPDFTicketBadge($web_request) {
295 try {
296 $a = SASO_EVENTTICKETS::issetRPara('action') ? SASO_EVENTTICKETS::getRequestPara('action') : "";
297 global $sasoEventtickets;
298 if ($_SERVER['REQUEST_METHOD'] === 'POST') {
299 $sasoEventtickets->getAdmin()->executeJSON($a, $_POST, true, false);
300 } else {
301 $sasoEventtickets->getAdmin()->executeJSON($a, $_GET, true, false);
302 }
303 } catch (Exception $e) {
304 wp_send_json_error($e->getMessage());
305 }
306 }
307 public static function rest_seating_plan($web_request) {
308 try {
309 include_once plugin_dir_path(__FILE__)."sasoEventtickets_Ticket.php";
310 $ticket = sasoEventtickets_Ticket::Instance($_SERVER["REQUEST_URI"]);
311 $ret = $ticket->rest_seating_plan($web_request);
312 $ret['nonce'] = wp_create_nonce( 'wp_rest' );
313 wp_send_json_success($ret);
314 } catch (Exception $e) {
315 wp_send_json_error($e->getMessage());
316 }
317 }
318 public static function isOrderPaid($order) {
319 if ($order === null || !is_object($order) || !is_a($order, 'WC_Order')) {
320 return false;
321 }
322 $order_status = $order->get_status();
323 $ok_order_statuses = wc_get_is_paid_statuses(); // array( 'processing', 'completed' )
324 return in_array($order_status, $ok_order_statuses);
325 }
326
327 /**
328 * @deprecated Since 2.8.0 - Use current_time('timestamp') or time() instead
329 * Kept for backward compatibility with older premium plugin versions
330 */
331 public static function time(): int {
332 return current_time('timestamp');
333 }
334
335 /**
336 * @deprecated Since 2.8.0 - Use wp_date() instead
337 * Kept for backward compatibility with older premium plugin versions
338 */
339 public static function date(string $format, int $timestamp = 0, $timezone = null): string {
340 if (empty($timezone)) {
341 $timezone = wp_timezone();
342 }
343 $datetime = new DateTime('now', $timezone);
344 if ($timestamp > 0) {
345 $datetime->setTimestamp($timestamp);
346 }
347 return $datetime->format($format);
348 }
349
350 public static function is_assoc_array($array) {
351 if (!is_array($array)) {
352 return false;
353 }
354 if ($array === []) {
355 return true;
356 }
357 if (function_exists('array_is_list')) {
358 // PHP 8.1+
359 return !array_is_list($array);
360 } else {
361 return count(array_filter(array_keys($array), 'is_string')) > 0;
362 /*
363 return array_keys($array) === range(0, count($array) - 1);
364 */
365 }
366 }
367
368 /** Sichere Sanitisierung: nur YYYY-MM-DD zulassen */
369 public static function sanitize_date_from_datepicker($date) {
370 $date = substr((string)$date, 0, 10);
371 return preg_match('/^\d{4}-\d{2}-\d{2}$/', $date) ? $date : '';
372 }
373
374 }
375 }
376 ?>