event-tickets-with-ticket-scanner
Last commit date
3rd
1 week ago
css
1 week ago
img
1 week ago
includes
1 week ago
js
1 week ago
languages
1 week ago
ticket
1 week ago
vendors
1 week ago
SASO_EVENTTICKETS.php
1 week ago
backend.js
1 week ago
changelog-features.json
1 week ago
changelog.txt
1 week ago
db.php
1 week ago
index.php
1 week ago
init_file.php
1 week ago
order_details.js
1 week ago
pwa-sw.js
1 week ago
readme.txt
1 week ago
saso-eventtickets-validator.js
1 week ago
sasoEventtickets_AdminSettings.php
1 week ago
sasoEventtickets_Authtoken.php
1 week ago
sasoEventtickets_Base.php
1 week ago
sasoEventtickets_Core.php
1 week ago
sasoEventtickets_Frontend.php
1 week ago
sasoEventtickets_Messenger.php
1 week ago
sasoEventtickets_Options.php
1 week ago
sasoEventtickets_PDF.php
1 week ago
sasoEventtickets_Seating.php
1 week ago
sasoEventtickets_Ticket.php
1 week ago
sasoEventtickets_TicketBadge.php
1 week ago
sasoEventtickets_TicketDesigner.php
1 week ago
sasoEventtickets_TicketQR.php
1 week ago
ticket_events.js
1 week ago
ticket_scanner.js
1 week ago
validator.js
1 week ago
version-notices.json
1 week ago
vollstart-cross-promo.php
1 week ago
wc_backend.js
1 week ago
wc_frontend.js
1 week ago
woocommerce-hooks.php
1 week ago
SASO_EVENTTICKETS.php
430 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'] ?? 'GET') { |
| 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 | $method = $_SERVER['REQUEST_METHOD'] ?? ''; |
| 72 | if ($method === 'POST') { |
| 73 | if (isset($_POST[$name])) return true; |
| 74 | if (isset($_GET[$name])) return true; |
| 75 | return false; |
| 76 | } |
| 77 | if ($method === 'GET') { |
| 78 | if (isset($_GET[$name])) return true; |
| 79 | return false; |
| 80 | } |
| 81 | return false; |
| 82 | } |
| 83 | public static function PasswortGenerieren($anzahl=8) { |
| 84 | $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")); |
| 85 | $pw = ""; |
| 86 | for ($a=0;$a<$anzahl;$a++): |
| 87 | shuffle($werte); |
| 88 | $zufallszahl = rand(0, count($werte)-1); |
| 89 | $buchstabe = $werte[$zufallszahl]; |
| 90 | if ($a == 0 && $buchstabe == ".") |
| 91 | $buchstabe = "a"; // weil man den Punkt am Anfang nicht sieht |
| 92 | $pw .= $buchstabe; |
| 93 | endfor; |
| 94 | return $pw; |
| 95 | } |
| 96 | public static function _basics_sendeDateiCSVvonDBdaten($daten, $filename, $delimiter=";") { |
| 97 | header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
| 98 | header('Content-Description: File Transfer'); |
| 99 | header('Content-type: text/csv'); |
| 100 | header('Content-Disposition: attachment; filename="'.$filename.'"'); |
| 101 | header('Expires: 0'); |
| 102 | header('Pragma: public'); |
| 103 | |
| 104 | ob_end_clean(); |
| 105 | $out = fopen('php://output', 'w'); |
| 106 | |
| 107 | if (count($daten) > 0) { |
| 108 | fputcsv($out, array_keys($daten[0]), $delimiter); |
| 109 | foreach($daten as $value) { |
| 110 | fputcsv($out, array_values($value), $delimiter); |
| 111 | } |
| 112 | } else { |
| 113 | fputcsv($out, array("no data"), $delimiter); |
| 114 | } |
| 115 | fclose($out); |
| 116 | } |
| 117 | public static function sendeDaten($daten, $name, $type) |
| 118 | { |
| 119 | header('Content-type: '.$type); |
| 120 | header('Content-Disposition: inline; filename="'.$name.'"'); |
| 121 | header('Expires: 0'); |
| 122 | header('Pragma: public'); |
| 123 | echo $daten; |
| 124 | } |
| 125 | public static function sendeDatei($datei, $bandbreitekontrolle=1, $bandbreite=256, $contenttype=false, $range_start=0, $range_stop=0) { |
| 126 | if (!file_exists($datei)) { |
| 127 | return false; |
| 128 | } |
| 129 | |
| 130 | header("Accept-Ranges: bytes"); |
| 131 | |
| 132 | if (is_array($contenttype)) { |
| 133 | if (isset($contenttype['Content-Type'])) { |
| 134 | header ("Content-Type: ".$contenttype['Content-Type']); |
| 135 | } |
| 136 | } else if ($contenttype) { |
| 137 | $vdatei = $datei; |
| 138 | switch(substr($vdatei,0,1)){ |
| 139 | case "/": |
| 140 | case "\\": |
| 141 | break; |
| 142 | default: |
| 143 | switch(substr($vdatei,0,2)){ |
| 144 | case "./": |
| 145 | case ".\\": |
| 146 | $vdatei = substr($vdatei,1); |
| 147 | } |
| 148 | $vdatei = dirslash(dirname(__FILE__)).$vdatei; |
| 149 | } |
| 150 | |
| 151 | if (function_exists("finfo_open")){ |
| 152 | $finfo = finfo_open(FILEINFO_MIME_TYPE); |
| 153 | $mime = finfo_file($finfo, $vdatei); |
| 154 | } else { |
| 155 | $mime = "application/octet-stream"; |
| 156 | } |
| 157 | header ("Content-Type: ".$mime); |
| 158 | } |
| 159 | |
| 160 | // range_start und range_stop legen die virtuelle dateigrösse fest |
| 161 | $von = 0; |
| 162 | $size = filesize($datei); |
| 163 | if ($range_start > 0) |
| 164 | $size -= $range_start; |
| 165 | if ($range_stop > $size) |
| 166 | $range_stop = 0; |
| 167 | if ($range_stop > 0) |
| 168 | $size = $range_stop-$range_start + 1; |
| 169 | |
| 170 | //check if http_range is sent by browser (or download manager) |
| 171 | if(isset($_SERVER['HTTP_RANGE'])) { |
| 172 | list($a, $range)=explode("=",$_SERVER['HTTP_RANGE']); |
| 173 | //if yes, download missing part |
| 174 | list($von,$bis)=explode("-",$range); |
| 175 | $bis = intval($bis); |
| 176 | $von = intval($von); |
| 177 | if ($bis == 0 || $bis < $von || $bis > $size) |
| 178 | $bis = $size - 1; // bis zum ende |
| 179 | $range_stop = $bis; |
| 180 | $new_length = $bis - $von + 1; |
| 181 | header("HTTP/1.1 206 Partial Content"); |
| 182 | header("Content-Length: $new_length"); |
| 183 | header("Content-Range: bytes ".$von."-".$bis."/".$size); |
| 184 | } else { |
| 185 | $size2=$size; |
| 186 | $range_stop = $size - 1; |
| 187 | //header("Content-Range: bytes 0-".$size2."/".$size); |
| 188 | header("Content-Length: ".$size2); |
| 189 | } |
| 190 | header("Content-Transfer-Encoding: binary"); |
| 191 | //open the file |
| 192 | $fp=fopen($datei,"rb"); |
| 193 | if (!$fp) |
| 194 | return false; |
| 195 | |
| 196 | if ($range_start > 0) |
| 197 | $von += $range_start; |
| 198 | |
| 199 | fseek($fp,$von); |
| 200 | |
| 201 | //start buffered download |
| 202 | $a=0; |
| 203 | $buffersize = 4096; |
| 204 | $bandbreite = intval($bandbreite); |
| 205 | if ($bandbreite < 1) |
| 206 | $bandbreite = 128; // 32*4*1024 = 128kb |
| 207 | $wartezeit = $bandbreite * 1000 / $buffersize; |
| 208 | |
| 209 | $gesendetbytes = 0; |
| 210 | while(!feof($fp)) { |
| 211 | if (connection_aborted()) { |
| 212 | fclose($fp); |
| 213 | return false; |
| 214 | } |
| 215 | //reset time limit for big files |
| 216 | @set_time_limit(0); |
| 217 | echo (fread($fp, $buffersize)); |
| 218 | $gesendetbytes += $buffersize; |
| 219 | if ($range_stop > 0 && $gesendetbytes >= $size) |
| 220 | break; // vorzeitig fertig; |
| 221 | if ($bandbreitekontrolle == 1): |
| 222 | if ($a<1): |
| 223 | sleep(1); |
| 224 | $a=$wartezeit; // wartezeit bevor ich wieder ne sekunde warte |
| 225 | endif; |
| 226 | $a--; |
| 227 | endif; |
| 228 | } |
| 229 | fclose($fp); |
| 230 | return true; |
| 231 | } |
| 232 | |
| 233 | public static function setRestRoutesTicket() { |
| 234 | $prefix = SASO_EVENTTICKETS::getRESTPrefixURL(); |
| 235 | register_rest_route($prefix.'/ticket/scanner', '/pwa-manifest', [ |
| 236 | ['methods'=>WP_REST_SERVER::READABLE, 'callback'=>'SASO_EVENTTICKETS::rest_pwa_manifest', 'permission_callback'=>function(){return true;}] |
| 237 | ]); |
| 238 | register_rest_route($prefix.'/ticket/scanner', '/pwa-sw', [ |
| 239 | ['methods'=>WP_REST_SERVER::READABLE, 'callback'=>'SASO_EVENTTICKETS::rest_pwa_sw', 'permission_callback'=>function(){return true;}] |
| 240 | ]); |
| 241 | register_rest_route($prefix.'/ticket/scanner', '/ping', [ |
| 242 | ['methods'=>WP_REST_SERVER::READABLE, 'callback'=>'SASO_EVENTTICKETS::rest_ping', 'permission_callback'=>function(){return true;}] |
| 243 | ]); |
| 244 | register_rest_route($prefix.'/ticket/scanner', '/retrieve_ticket', [ |
| 245 | ['methods'=>WP_REST_SERVER::READABLE, 'callback'=>'SASO_EVENTTICKETS::rest_retrieve_ticket', 'args'=>['code'=>['required'=>true]], 'permission_callback'=>'SASO_EVENTTICKETS::rest_permission_callback'] |
| 246 | ]); |
| 247 | register_rest_route($prefix.'/ticket/scanner', '/redeem_ticket', [ |
| 248 | ['methods'=>WP_REST_SERVER::READABLE, 'callback'=>'SASO_EVENTTICKETS::rest_redeem_ticket', 'args'=>['code'=>['required'=>true]], 'permission_callback'=>'SASO_EVENTTICKETS::rest_permission_callback'] |
| 249 | ]); |
| 250 | register_rest_route($prefix.'/ticket/scanner', '/downloadPDFTicketBadge', [ |
| 251 | ['methods'=>WP_REST_SERVER::READABLE, 'callback'=>'SASO_EVENTTICKETS::rest_downloadPDFTicketBadge', 'args'=>['code'=>['required'=>true]], 'permission_callback'=>'SASO_EVENTTICKETS::rest_permission_callback'] |
| 252 | ]); |
| 253 | register_rest_route($prefix.'/ticket/scanner', '/seating_plan', [ |
| 254 | ['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'] |
| 255 | ]); |
| 256 | } |
| 257 | public static function rest_permission_callback($web_request) { |
| 258 | try { |
| 259 | include_once plugin_dir_path(__FILE__)."sasoEventtickets_Ticket.php"; |
| 260 | $ticket = sasoEventtickets_Ticket::Instance($_SERVER["REQUEST_URI"]); |
| 261 | wp_create_nonce( 'wp_rest' ); |
| 262 | return $ticket->rest_permission_callback($web_request); |
| 263 | } catch (Exception $e) { |
| 264 | wp_send_json_error($e->getMessage()); |
| 265 | } |
| 266 | return false; |
| 267 | } |
| 268 | public static function rest_ping($web_request) { |
| 269 | try { |
| 270 | include_once plugin_dir_path(__FILE__)."sasoEventtickets_Ticket.php"; |
| 271 | $ticket = sasoEventtickets_Ticket::Instance($_SERVER["REQUEST_URI"]); |
| 272 | $ret = $ticket->rest_ping($web_request); |
| 273 | $ret['nonce'] = wp_create_nonce( 'wp_rest' ); |
| 274 | wp_send_json_success($ret); |
| 275 | } catch (Exception $e) { |
| 276 | wp_send_json_error($e->getMessage()); |
| 277 | } |
| 278 | } |
| 279 | public static function rest_retrieve_ticket($web_request) { |
| 280 | try { |
| 281 | include_once plugin_dir_path(__FILE__)."sasoEventtickets_Ticket.php"; |
| 282 | $ticket = sasoEventtickets_Ticket::Instance($_SERVER["REQUEST_URI"]); |
| 283 | $ret = $ticket->rest_retrieve_ticket($web_request); |
| 284 | $ret['nonce'] = wp_create_nonce( 'wp_rest' ); |
| 285 | wp_send_json_success($ret); |
| 286 | } catch (Exception $e) { |
| 287 | wp_send_json_error($e->getMessage()); |
| 288 | } |
| 289 | } |
| 290 | public static function rest_redeem_ticket($web_request) { |
| 291 | try { |
| 292 | include_once plugin_dir_path(__FILE__)."sasoEventtickets_Ticket.php"; |
| 293 | $ticket = sasoEventtickets_Ticket::Instance($_SERVER["REQUEST_URI"]); |
| 294 | $ret = $ticket->rest_redeem_ticket($web_request); |
| 295 | $ret['nonce'] = wp_create_nonce( 'wp_rest' ); |
| 296 | wp_send_json_success($ret); |
| 297 | } catch (Exception $e) { |
| 298 | wp_send_json_error($e->getMessage()); |
| 299 | } |
| 300 | } |
| 301 | public static function rest_downloadPDFTicketBadge($web_request) { |
| 302 | try { |
| 303 | global $sasoEventtickets; |
| 304 | $code = $web_request->get_param('code'); |
| 305 | if (empty($code)) { |
| 306 | throw new Exception("#6100 ticket code parameter is missing"); |
| 307 | } |
| 308 | $codeObj = $sasoEventtickets->getCore()->retrieveCodeByCode($code); |
| 309 | if (empty($codeObj)) { |
| 310 | throw new Exception("#6101 ticket code not found"); |
| 311 | } |
| 312 | $badgeHandler = $sasoEventtickets->getTicketBadgeHandler(); |
| 313 | $badgeHandler->downloadPDFTicketBadge($codeObj); |
| 314 | exit; |
| 315 | } catch (Exception $e) { |
| 316 | wp_send_json_error($e->getMessage()); |
| 317 | } |
| 318 | } |
| 319 | public static function rest_seating_plan($web_request) { |
| 320 | try { |
| 321 | include_once plugin_dir_path(__FILE__)."sasoEventtickets_Ticket.php"; |
| 322 | $ticket = sasoEventtickets_Ticket::Instance($_SERVER["REQUEST_URI"]); |
| 323 | $ret = $ticket->rest_seating_plan($web_request); |
| 324 | $ret['nonce'] = wp_create_nonce( 'wp_rest' ); |
| 325 | wp_send_json_success($ret); |
| 326 | } catch (Exception $e) { |
| 327 | wp_send_json_error($e->getMessage()); |
| 328 | } |
| 329 | } |
| 330 | public static function rest_pwa_manifest($web_request) { |
| 331 | global $sasoEventtickets; |
| 332 | $scannerUrl = $sasoEventtickets->getCore()->getTicketURLBase() . 'scanner/'; |
| 333 | $scope = wp_parse_url($scannerUrl, PHP_URL_PATH); |
| 334 | $iconBase = plugins_url('img/', __FILE__); |
| 335 | $themeColor = $sasoEventtickets->getOptions()->getOptionValue('ticketScannerThemeColor', '#2e74b5'); |
| 336 | if (empty($themeColor)) $themeColor = '#2e74b5'; |
| 337 | $manifest = [ |
| 338 | 'name' => 'Ticket Scanner', |
| 339 | 'short_name' => 'Scanner', |
| 340 | 'display' => 'standalone', |
| 341 | 'orientation' => 'portrait', |
| 342 | 'theme_color' => $themeColor, |
| 343 | 'background_color' => '#ffffff', |
| 344 | 'start_url' => $scannerUrl, |
| 345 | 'scope' => $scope, |
| 346 | 'icons' => [ |
| 347 | ['src' => $iconBase . 'pwa-icon-192.png', 'sizes' => '192x192', 'type' => 'image/png'], |
| 348 | ['src' => $iconBase . 'pwa-icon-512.png', 'sizes' => '512x512', 'type' => 'image/png'], |
| 349 | ], |
| 350 | ]; |
| 351 | return new WP_REST_Response($manifest, 200, ['Content-Type' => 'application/manifest+json']); |
| 352 | } |
| 353 | |
| 354 | public static function rest_pwa_sw($web_request) { |
| 355 | global $sasoEventtickets; |
| 356 | $swFile = plugin_dir_path(__FILE__) . 'pwa-sw.js'; |
| 357 | if (!file_exists($swFile)) { |
| 358 | return new WP_Error('not_found', 'Service worker not found', ['status' => 404]); |
| 359 | } |
| 360 | $js = file_get_contents($swFile); |
| 361 | $version = defined('SASO_EVENTTICKETS_PLUGIN_VERSION') ? SASO_EVENTTICKETS_PLUGIN_VERSION : '1'; |
| 362 | $js = str_replace('ticket-scanner-v1', 'ticket-scanner-' . $version, $js); |
| 363 | $scannerUrl = $sasoEventtickets->getCore()->getTicketURLBase() . 'scanner/'; |
| 364 | $scope = wp_parse_url($scannerUrl, PHP_URL_PATH); |
| 365 | header('Content-Type: application/javascript'); |
| 366 | header('Service-Worker-Allowed: ' . $scope); |
| 367 | header('Cache-Control: no-cache'); |
| 368 | echo $js; |
| 369 | exit; |
| 370 | } |
| 371 | |
| 372 | public static function isOrderPaid($order) { |
| 373 | if ($order === null || !is_object($order) || !is_a($order, 'WC_Order')) { |
| 374 | return false; |
| 375 | } |
| 376 | $order_status = $order->get_status(); |
| 377 | $ok_order_statuses = wc_get_is_paid_statuses(); // array( 'processing', 'completed' ) |
| 378 | return in_array($order_status, $ok_order_statuses); |
| 379 | } |
| 380 | |
| 381 | /** |
| 382 | * @deprecated Since 2.8.0 - Use current_time('timestamp') or time() instead |
| 383 | * Kept for backward compatibility with older premium plugin versions |
| 384 | */ |
| 385 | public static function time(): int { |
| 386 | return current_time('timestamp'); |
| 387 | } |
| 388 | |
| 389 | /** |
| 390 | * @deprecated Since 2.8.0 - Use wp_date() instead |
| 391 | * Kept for backward compatibility with older premium plugin versions |
| 392 | */ |
| 393 | public static function date(string $format, int $timestamp = 0, ?\DateTimeZone $timezone = null): string { |
| 394 | if (empty($timezone)) { |
| 395 | $timezone = wp_timezone(); |
| 396 | } |
| 397 | $datetime = new DateTime('now', $timezone); |
| 398 | if ($timestamp > 0) { |
| 399 | $datetime->setTimestamp($timestamp); |
| 400 | } |
| 401 | return $datetime->format($format); |
| 402 | } |
| 403 | |
| 404 | public static function is_assoc_array($array) { |
| 405 | if (!is_array($array)) { |
| 406 | return false; |
| 407 | } |
| 408 | if ($array === []) { |
| 409 | return true; |
| 410 | } |
| 411 | if (function_exists('array_is_list')) { |
| 412 | // PHP 8.1+ |
| 413 | return !array_is_list($array); |
| 414 | } else { |
| 415 | return count(array_filter(array_keys($array), 'is_string')) > 0; |
| 416 | /* |
| 417 | return array_keys($array) === range(0, count($array) - 1); |
| 418 | */ |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | /** Sichere Sanitisierung: nur YYYY-MM-DD zulassen */ |
| 423 | public static function sanitize_date_from_datepicker($date) { |
| 424 | $date = substr((string)$date, 0, 10); |
| 425 | return preg_match('/^\d{4}-\d{2}-\d{2}$/', $date) ? $date : ''; |
| 426 | } |
| 427 | |
| 428 | } |
| 429 | } |
| 430 | ?> |