event-tickets-with-ticket-scanner
Last commit date
2.7.0
1 year ago
3rd
1 year ago
css
1 year ago
img
1 year ago
languages
1 year ago
ticket
1 year ago
vendors
1 year ago
SASO_EVENTTICKETS.php
1 year ago
backend.js
1 year ago
changelog.txt
1 year ago
db.php
1 year ago
index.php
1 year ago
init_file.php
1 year ago
js_seatingplan.js
1 year ago
order_details.js
1 year ago
readme.txt
1 year ago
saso-eventtickets-validator.js
1 year ago
sasoEventtickets_AdminSettings.php
1 year ago
sasoEventtickets_Authtoken.php
1 year ago
sasoEventtickets_Base.php
1 year ago
sasoEventtickets_Core.php
1 year ago
sasoEventtickets_Frontend.php
1 year ago
sasoEventtickets_Messenger.php
1 year ago
sasoEventtickets_Options.php
1 year ago
sasoEventtickets_PDF.php
1 year ago
sasoEventtickets_Ticket.php
1 year ago
sasoEventtickets_TicketBadge.php
1 year ago
sasoEventtickets_TicketDesigner.php
1 year ago
sasoEventtickets_TicketQR.php
1 year ago
ticket_events.js
1 year ago
ticket_scanner.js
1 year ago
validator.js
1 year ago
wc_backend.js
1 year ago
wc_frontend.js
1 year ago
woocommerce-hooks.php
1 year ago
SASO_EVENTTICKETS.php
346 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 | } |
| 247 | public static function rest_permission_callback($web_request) { |
| 248 | try { |
| 249 | include_once plugin_dir_path(__FILE__)."sasoEventtickets_Ticket.php"; |
| 250 | $ticket = sasoEventtickets_Ticket::Instance($_SERVER["REQUEST_URI"]); |
| 251 | wp_create_nonce( 'wp_rest' ); |
| 252 | return $ticket->rest_permission_callback($web_request); |
| 253 | } catch (Exception $e) { |
| 254 | wp_send_json_error($e->getMessage()); |
| 255 | } |
| 256 | return false; |
| 257 | } |
| 258 | public static function rest_ping($web_request) { |
| 259 | try { |
| 260 | include_once plugin_dir_path(__FILE__)."sasoEventtickets_Ticket.php"; |
| 261 | $ticket = sasoEventtickets_Ticket::Instance($_SERVER["REQUEST_URI"]); |
| 262 | $ret = $ticket->rest_ping($web_request); |
| 263 | $ret['nonce'] = wp_create_nonce( 'wp_rest' ); |
| 264 | wp_send_json_success($ret); |
| 265 | } catch (Exception $e) { |
| 266 | wp_send_json_error($e->getMessage()); |
| 267 | } |
| 268 | } |
| 269 | public static function rest_retrieve_ticket($web_request) { |
| 270 | try { |
| 271 | include_once plugin_dir_path(__FILE__)."sasoEventtickets_Ticket.php"; |
| 272 | $ticket = sasoEventtickets_Ticket::Instance($_SERVER["REQUEST_URI"]); |
| 273 | $ret = $ticket->rest_retrieve_ticket($web_request); |
| 274 | $ret['nonce'] = wp_create_nonce( 'wp_rest' ); |
| 275 | wp_send_json_success($ret); |
| 276 | } catch (Exception $e) { |
| 277 | wp_send_json_error($e->getMessage()); |
| 278 | } |
| 279 | } |
| 280 | public static function rest_redeem_ticket($web_request) { |
| 281 | try { |
| 282 | include_once plugin_dir_path(__FILE__)."sasoEventtickets_Ticket.php"; |
| 283 | $ticket = sasoEventtickets_Ticket::Instance($_SERVER["REQUEST_URI"]); |
| 284 | $ret = $ticket->rest_redeem_ticket($web_request); |
| 285 | $ret['nonce'] = wp_create_nonce( 'wp_rest' ); |
| 286 | wp_send_json_success($ret); |
| 287 | } catch (Exception $e) { |
| 288 | wp_send_json_error($e->getMessage()); |
| 289 | } |
| 290 | } |
| 291 | public static function rest_downloadPDFTicketBadge($web_request) { |
| 292 | try { |
| 293 | $a = SASO_EVENTTICKETS::issetRPara('action') ? SASO_EVENTTICKETS::getRequestPara('action') : ""; |
| 294 | global $sasoEventtickets; |
| 295 | if ($_SERVER['REQUEST_METHOD'] === 'POST') { |
| 296 | $sasoEventtickets->getAdmin()->executeJSON($a, $_POST, true, false); |
| 297 | } else { |
| 298 | $sasoEventtickets->getAdmin()->executeJSON($a, $_GET, true, false); |
| 299 | } |
| 300 | } catch (Exception $e) { |
| 301 | wp_send_json_error($e->getMessage()); |
| 302 | } |
| 303 | } |
| 304 | public static function isOrderPaid($order) { |
| 305 | if ($order === null || !is_object($order) || !is_a($order, 'WC_Order')) { |
| 306 | return false; |
| 307 | } |
| 308 | $order_status = $order->get_status(); |
| 309 | $ok_order_statuses = wc_get_is_paid_statuses(); // array( 'processing', 'completed' ) |
| 310 | return in_array($order_status, $ok_order_statuses); |
| 311 | } |
| 312 | public static function time() { |
| 313 | //return current_time("timestamp"); |
| 314 | $timezone = wp_timezone(); |
| 315 | $datetime = new DateTime( 'now', $timezone ); |
| 316 | return $datetime->getTimestamp(); |
| 317 | } |
| 318 | public static function date($format, $timestamp=0, $timezone=null) { |
| 319 | // wp_date( $format, $timestamp, $timezone ); |
| 320 | if (empty($timezone)) $timezone = wp_timezone(); |
| 321 | $datetime = new DateTime( 'now', $timezone ); |
| 322 | if ($timestamp > 1) { |
| 323 | $datetime->setTimestamp($timestamp); |
| 324 | } |
| 325 | return $datetime->format( $format ); |
| 326 | } |
| 327 | public static function is_assoc_array($array) { |
| 328 | if (!is_array($array)) { |
| 329 | return false; |
| 330 | } |
| 331 | if ($array === []) { |
| 332 | return true; |
| 333 | } |
| 334 | if (function_exists('array_is_list')) { |
| 335 | // PHP 8.1+ |
| 336 | return !array_is_list($array); |
| 337 | } else { |
| 338 | return count(array_filter(array_keys($array), 'is_string')) > 0; |
| 339 | /* |
| 340 | return array_keys($array) === range(0, count($array) - 1); |
| 341 | */ |
| 342 | } |
| 343 | } |
| 344 | } |
| 345 | } |
| 346 | ?> |