event-tickets-with-ticket-scanner
Last commit date
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
sasoEventtickets_Core.php
804 lines
| 1 | <?php |
| 2 | include_once(plugin_dir_path(__FILE__)."init_file.php"); |
| 3 | class sasoEventtickets_Core { |
| 4 | private $MAIN; |
| 5 | |
| 6 | private $_CACHE_list = []; |
| 7 | |
| 8 | public $ticket_url_path_part = "ticket"; |
| 9 | |
| 10 | public function __construct($MAIN) { |
| 11 | if ($MAIN->getDB() == null) throw new Exception("#9999 DB needed"); |
| 12 | $this->MAIN = $MAIN; |
| 13 | } |
| 14 | |
| 15 | private function getBase() { |
| 16 | return $this->MAIN->getBase(); |
| 17 | } |
| 18 | private function getDB() { |
| 19 | return $this->MAIN->getDB(); |
| 20 | } |
| 21 | |
| 22 | public function clearCode($code) { |
| 23 | $ret = trim(urldecode(strip_tags(str_replace(" ","",str_replace(":","",str_replace("-", "", $code)))))); |
| 24 | $ret = apply_filters( $this->MAIN->_add_filter_prefix.'core_clearCode', $ret ); |
| 25 | return $ret; |
| 26 | } |
| 27 | |
| 28 | public function getListById($id) { |
| 29 | $sql = "select * from ".$this->getDB()->getTabelle("lists")." where id = ".intval($id); |
| 30 | $ret = $this->getDB()->_db_datenholen($sql); |
| 31 | if (count($ret) == 0) throw new Exception("#9232 ticket list not found"); |
| 32 | return $ret[0]; |
| 33 | } |
| 34 | |
| 35 | public function getCodesByRegUserId($user_id) { |
| 36 | $user_id = intval($user_id); |
| 37 | if ($user_id <= 0) return []; |
| 38 | $sql = "select a.* from ".$this->getDB()->getTabelle("codes")." a where user_id = ".$user_id; |
| 39 | return $this->getDB()->_db_datenholen($sql); |
| 40 | } |
| 41 | |
| 42 | public function retrieveCodeByCode($code, $mitListe=false) { |
| 43 | $code = $this->clearCode($code); |
| 44 | $code = $this->getDB()->reinigen_in($code); |
| 45 | if (empty($code)) throw new Exception("#203 tiket number empty"); |
| 46 | if ($mitListe) { |
| 47 | $sql = "select a.*, b.name as list_name from ".$this->getDB()->getTabelle("codes")." a |
| 48 | left join ".$this->getDB()->getTabelle("lists")." b on a.list_id = b.id |
| 49 | where code = '".$code."'"; |
| 50 | } else { |
| 51 | $sql = "select a.* from ".$this->getDB()->getTabelle("codes")." a where code = '".$code."'"; |
| 52 | } |
| 53 | $ret = $this->getDB()->_db_datenholen($sql); |
| 54 | if (count($ret) == 0) throw new Exception("#204 ticket with ".$code." not found"); |
| 55 | return $ret[0]; |
| 56 | } |
| 57 | |
| 58 | public function checkCodesSize() { |
| 59 | if ($this->isCodeSizeExceeded()) throw new Exception("#208 too many tickets. Unlimited tickets only with premium"); |
| 60 | } |
| 61 | public function isCodeSizeExceeded() { |
| 62 | return $this->getBase()->_isMaxReachedForTickets($this->getDB()->getCodesSize()) == false; |
| 63 | } |
| 64 | |
| 65 | public function retrieveCodeById($id, $mitListe=false) { |
| 66 | $id = intval($id); |
| 67 | if ($id == 0) throw new Exception("#220 id is wrong"); |
| 68 | if ($mitListe) { |
| 69 | $sql = "select a.*, b.name as list_name from ".$this->getDB()->getTabelle("codes")." a |
| 70 | left join ".$this->getDB()->getTabelle("lists")." b on a.list_id = b.id |
| 71 | where a.id = ".$id; |
| 72 | } else { |
| 73 | $sql = "select a.* from ".$this->getDB()->getTabelle("codes")." a where a.id = ".$id; |
| 74 | } |
| 75 | $ret = $this->getDB()->_db_datenholen($sql); |
| 76 | if (count($ret) == 0) throw new Exception("#221 ticket not found"); |
| 77 | return $ret[0]; |
| 78 | } |
| 79 | |
| 80 | public function getMetaObject() { |
| 81 | $metaObj = [ |
| 82 | 'validation'=>[ |
| 83 | 'first_success'=>'', |
| 84 | 'first_success_tz'=>'', |
| 85 | 'first_ip'=>'', |
| 86 | 'last_success'=>'', |
| 87 | 'last_success_tz'=>'', |
| 88 | 'last_ip'=>'' |
| 89 | ] |
| 90 | ,'user'=>[ |
| 91 | 'reg_approved'=>0, |
| 92 | 'reg_request'=>'', |
| 93 | 'reg_request_tz'=>'', |
| 94 | 'value'=>'', |
| 95 | 'reg_ip'=>'', |
| 96 | 'reg_userid'=>0, |
| 97 | '_reg_username'=>''] |
| 98 | ,'used'=>[ |
| 99 | 'reg_ip'=>'', |
| 100 | 'reg_request'=>'', |
| 101 | 'reg_request_tz'=>'', |
| 102 | 'reg_userid'=>0, |
| 103 | '_reg_username'=>''] |
| 104 | ,'confirmedCount'=>0 |
| 105 | ,'woocommerce'=>[ |
| 106 | 'order_id'=>0, |
| 107 | 'product_id'=>0, |
| 108 | 'creation_date'=>0, |
| 109 | 'creation_date_tz'=>'', |
| 110 | 'item_id'=>0, |
| 111 | 'user_id'=>0 |
| 112 | ] // product code for sale |
| 113 | ,'wc_rp'=>[ |
| 114 | 'order_id'=>0, |
| 115 | 'product_id'=>0, |
| 116 | 'creation_date'=>0, |
| 117 | 'creation_date_tz'=>'', |
| 118 | 'item_id'=>0 |
| 119 | ] // restriction purchase used |
| 120 | ,'wc_ticket'=>[ |
| 121 | 'is_ticket'=>0, |
| 122 | 'ip'=>'', |
| 123 | 'userid'=>0, |
| 124 | '_username'=>'', |
| 125 | 'redeemed_date'=>'', |
| 126 | 'redeemed_date_tz'=>'', |
| 127 | 'redeemed_by_admin'=>0, |
| 128 | 'set_by_admin'=>0, |
| 129 | 'set_by_admin_date'=>'', |
| 130 | 'set_by_admin_date_tz'=>'', |
| 131 | 'idcode'=>'', |
| 132 | '_url'=>'', |
| 133 | '_public_ticket_id'=>'', |
| 134 | 'stats_redeemed'=>[], |
| 135 | 'name_per_ticket'=>'', |
| 136 | 'value_per_ticket'=>'', |
| 137 | 'is_daychooser'=>0, |
| 138 | 'day_per_ticket'=>'', |
| 139 | '_qr_content'=>'' |
| 140 | ] // ticket purchase ; stats_redeemed is only used if the ticket can be redeemed more than once |
| 141 | ]; |
| 142 | |
| 143 | if ($this->MAIN->isPremium() && method_exists($this->MAIN->getPremiumFunctions(), 'getMetaObject')) { |
| 144 | $metaObj = $this->MAIN->getPremiumFunctions()->getMetaObject($metaObj); |
| 145 | } |
| 146 | |
| 147 | return $metaObj; |
| 148 | } |
| 149 | public function encodeMetaValuesAndFillObject($metaValuesString, $codeObj=null) { |
| 150 | $metaObj = $this->getMetaObject(); |
| 151 | if (!empty($metaValuesString)) { |
| 152 | $metaObj = array_replace_recursive($metaObj, json_decode($metaValuesString, true)); |
| 153 | } |
| 154 | if (isset($metaObj['user']['reg_userid']) && $metaObj['user']['reg_userid'] > 0) { |
| 155 | $u = get_userdata($metaObj['user']['reg_userid']); |
| 156 | if ($u === false) { |
| 157 | $metaObj['user']['_reg_username'] = esc_html__("USERID DO NOT EXISTS", 'event-tickets-with-ticket-scanner'); |
| 158 | } else { |
| 159 | $metaObj['user']['_reg_username'] = $u->first_name." ".$u->last_name." (".$u->user_login.")"; |
| 160 | } |
| 161 | } else { |
| 162 | $metaObj['user']['_reg_username'] = ""; |
| 163 | } |
| 164 | if (isset($metaObj['used']['reg_userid']) && $metaObj['used']['reg_userid'] > 0) { |
| 165 | $u = get_userdata($metaObj['used']['reg_userid']); |
| 166 | if ($u === false) { |
| 167 | $metaObj['used']['_reg_username'] = esc_html__("USERID DO NOT EXISTS", 'event-tickets-with-ticket-scanner'); |
| 168 | } else { |
| 169 | $metaObj['used']['_reg_username'] = $u->first_name." ".$u->last_name." (".$u->user_login.")"; |
| 170 | } |
| 171 | } else { |
| 172 | $metaObj['used']['_reg_username'] = ""; |
| 173 | } |
| 174 | if (isset($metaObj['wc_ticket']['userid']) && $metaObj['wc_ticket']['userid'] > 0) { |
| 175 | $u = get_userdata($metaObj['wc_ticket']['userid']); |
| 176 | if ($u === false) { |
| 177 | $metaObj['wc_ticket']['_username'] = esc_html__("USERID DO NOT EXISTS", 'event-tickets-with-ticket-scanner'); |
| 178 | } else { |
| 179 | $metaObj['wc_ticket']['_username'] = $u->first_name." ".$u->last_name." (".$u->user_login.")"; |
| 180 | } |
| 181 | } else { |
| 182 | $metaObj['wc_ticket']['_username'] = ""; |
| 183 | } |
| 184 | if (isset($metaObj['wc_ticket']['redeemed_by_admin']) && $metaObj['wc_ticket']['redeemed_by_admin'] > 0) { |
| 185 | $u = get_userdata($metaObj['wc_ticket']['redeemed_by_admin']); |
| 186 | if ($u === false) { |
| 187 | $metaObj['wc_ticket']['_redeemed_by_admin_username'] = esc_html__("USERID DO NOT EXISTS", 'event-tickets-with-ticket-scanner'); |
| 188 | } else { |
| 189 | $metaObj['wc_ticket']['_redeemed_by_admin_username'] = $u->first_name." ".$u->last_name." (".$u->user_login.")"; |
| 190 | } |
| 191 | } else { |
| 192 | $metaObj['wc_ticket']['_redeemed_by_admin_username'] = ""; |
| 193 | } |
| 194 | if (isset($metaObj['wc_ticket']['set_by_admin']) && $metaObj['wc_ticket']['set_by_admin'] > 0) { |
| 195 | $u = get_userdata($metaObj['wc_ticket']['set_by_admin']); |
| 196 | if ($u === false) { |
| 197 | $metaObj['wc_ticket']['_set_by_admin_username'] = esc_html__("USERID DO NOT EXISTS", 'event-tickets-with-ticket-scanner'); |
| 198 | } else { |
| 199 | $metaObj['wc_ticket']['_set_by_admin_username'] = $u->first_name." ".$u->last_name." (".$u->user_login.")"; |
| 200 | } |
| 201 | } else { |
| 202 | $metaObj['wc_ticket']['_set_by_admin_username'] = ""; |
| 203 | } |
| 204 | if ($metaObj['wc_ticket']['is_ticket'] == 1 && $codeObj != null && is_array($codeObj)) { |
| 205 | if (empty($metaObj['wc_ticket']['idcode'])) $metaObj['wc_ticket']['idcode'] = crc32($codeObj['id']."-".current_time("timestamp")); |
| 206 | if (empty($metaObj['wc_ticket']['_public_ticket_id'])) $metaObj['wc_ticket']['_public_ticket_id'] = $this->getTicketId($codeObj, $metaObj); |
| 207 | if (empty($metaObj['wc_ticket']['_qr_content'])) $metaObj['wc_ticket']['_qr_content'] = $this->getQRCodeContent($codeObj, $metaObj); |
| 208 | $metaObj['wc_ticket']['_url'] = $this->getTicketURL($codeObj, $metaObj); |
| 209 | } |
| 210 | |
| 211 | // update validation fields |
| 212 | if ($metaObj['confirmedCount'] > 0) { |
| 213 | if (empty($metaObj['validation']['first_success'])) { |
| 214 | // check used wert |
| 215 | if ( !empty($metaObj['used']['reg_request']) ) { |
| 216 | if (empty($metaObj['validation']['first_success'])) $metaObj['validation']['first_success'] = $metaObj['used']['reg_request']; |
| 217 | if (empty($metaObj['validation']['first_success_tz'])) $metaObj['validation']['first_success_tz'] = $metaObj['used']['reg_request_tz']; |
| 218 | if (empty($metaObj['validation']['first_ip'])) $metaObj['validation']['first_ip'] = $metaObj['used']['reg_ip']; |
| 219 | } elseif (!empty($metaObj['user']['reg_request'])) { // check user reg wert |
| 220 | if (empty($metaObj['validation']['first_success'])) $metaObj['validation']['first_success'] = $metaObj['user']['reg_request']; |
| 221 | if (empty($metaObj['validation']['first_success_tz'])) $metaObj['validation']['first_success_tz'] = $metaObj['user']['reg_request_tz']; |
| 222 | if (empty($metaObj['validation']['first_ip'])) $metaObj['validation']['first_ip'] = $metaObj['user']['reg_ip']; |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | if ($this->MAIN->isPremium() && method_exists($this->MAIN->getPremiumFunctions(), 'encodeMetaValuesAndFillObject')) { |
| 228 | $metaObj = $this->MAIN->getPremiumFunctions()->encodeMetaValuesAndFillObject($metaObj, $codeObj); |
| 229 | } |
| 230 | return $metaObj; |
| 231 | } |
| 232 | |
| 233 | public function getMetaObjectKeyList($metaObj, $prefix="META_") { |
| 234 | $keys = []; |
| 235 | $prefix = strtoupper(trim($prefix)); |
| 236 | foreach(array_keys($metaObj) as $key) { |
| 237 | $tag = $prefix.strtoupper($key); |
| 238 | if (is_array($metaObj[$key])) { |
| 239 | $_keys = $this->getMetaObjectKeyList($metaObj[$key], $tag."_"); |
| 240 | $keys = array_merge($keys, $_keys); |
| 241 | } else { |
| 242 | $keys[] = $tag; |
| 243 | } |
| 244 | } |
| 245 | return $keys; |
| 246 | } |
| 247 | |
| 248 | public function getMetaObjectAllowedReplacementTags() { |
| 249 | $tags = []; |
| 250 | $allowed_tags = [ |
| 251 | "USER_VALUE"=>esc_html__("Value given by the user during the code registration.", 'event-tickets-with-ticket-scanner'), |
| 252 | "USER_REG_IP"=>esc_html__("IP address of the user, register to a code.", 'event-tickets-with-ticket-scanner'), |
| 253 | "USER_REG_USERID"=>esc_html__("User id of the registered user to a code. Default will be 0.", 'event-tickets-with-ticket-scanner'), |
| 254 | "USED_REG_IP"=>esc_html__("IP addres of the user that used the code.", 'event-tickets-with-ticket-scanner'), |
| 255 | "CONFIRMEDCOUNT"=>esc_html__("Amount of how many times the code was validated successfully.", 'event-tickets-with-ticket-scanner'), |
| 256 | "WOOCOMMERCE_ORDER_ID"=>esc_html__("WooCommerce order id assigned to the code.", 'event-tickets-with-ticket-scanner'), |
| 257 | "WOOCOMMERCE_PRODUCT_ID"=>esc_html__("WooCommerce product id assigned to the code.", 'event-tickets-with-ticket-scanner'), |
| 258 | "WOOCOMMERCE_CREATION_DATE"=>esc_html__("Creation date of the WooCommerce sales date.", 'event-tickets-with-ticket-scanner'), |
| 259 | "WOOCOMMERCE_CREATION_DATE_TZ"=>esc_html__("Creation date of the WooCommerce sales date timezone.", 'event-tickets-with-ticket-scanner'), |
| 260 | "WOOCOMMERCE_USER_ID"=>esc_html__("User id of the WooCommerce sales.", 'event-tickets-with-ticket-scanner'), |
| 261 | "WC_RP_ORDER_ID"=>esc_html__("WooCommerce order id, that was purchases using this code as an allowance to purchase a restricted product.", 'event-tickets-with-ticket-scanner'), |
| 262 | "WC_RP_PRODUCT_ID"=>esc_html__("WooCommerce product id that was restricted with this code.", 'event-tickets-with-ticket-scanner'), |
| 263 | "WC_RP_CREATION_DATE"=>esc_html__("Creation date of the WooCommerce purchase using the allowance code.", 'event-tickets-with-ticket-scanner'), |
| 264 | "WC_RP_CREATION_DATE_TZ"=>esc_html__("Creation date timezone of the WooCommerce purchase using the allowance code.", 'event-tickets-with-ticket-scanner'), |
| 265 | "WC_TICKET__PUBLIC_TICKET_ID"=>esc_html__("The public ticket number", 'event-tickets-with-ticket-scanner') |
| 266 | ]; |
| 267 | $allowed_tags = apply_filters( $this->MAIN->_add_filter_prefix.'core_getMetaObjectAllowedReplacementTags', $allowed_tags ); |
| 268 | foreach($allowed_tags as $key => $value) { |
| 269 | $tags[] = ["key"=>$key, "label"=>$value]; |
| 270 | } |
| 271 | return $tags; |
| 272 | } |
| 273 | |
| 274 | public function getMetaObjectList() { |
| 275 | $metaObj = [ |
| 276 | 'desc'=>'', |
| 277 | 'redirect'=>['url'=>''], |
| 278 | 'formatter'=>[ |
| 279 | 'active'=>1, |
| 280 | 'format'=>'' // JSON mit den Format Werten |
| 281 | ], |
| 282 | 'webhooks'=>[ |
| 283 | 'webhookURLaddwcticketsold'=>'' |
| 284 | ] |
| 285 | ]; |
| 286 | if ($this->MAIN->isPremium() && method_exists($this->MAIN->getPremiumFunctions(), 'getMetaObjectList')) { |
| 287 | $metaObj = $this->MAIN->getPremiumFunctions()->getMetaObjectList($metaObj); |
| 288 | } |
| 289 | return $metaObj; |
| 290 | } |
| 291 | |
| 292 | public function encodeMetaValuesAndFillObjectList($metaValuesString) { |
| 293 | $metaObj = $this->getMetaObjectList(); |
| 294 | if (!empty($metaValuesString)) { |
| 295 | $metaObj = array_replace_recursive($metaObj, json_decode($metaValuesString, true)); |
| 296 | } |
| 297 | return $metaObj; |
| 298 | } |
| 299 | |
| 300 | public function setMetaObj($codeObj) { |
| 301 | if (!isset($codeObj["metaObj"])) { |
| 302 | $metaObj = $this->encodeMetaValuesAndFillObject($codeObj['meta'], $codeObj); |
| 303 | $codeObj["metaObj"] = $metaObj; |
| 304 | } |
| 305 | return $codeObj; |
| 306 | } |
| 307 | |
| 308 | public function getQRCodeContent($codeObj, $metaObj=null) { |
| 309 | if (!isset($codeObj['metaObj']) || $codeObj['metaObj'] == null) { |
| 310 | if ($metaObj != null) { |
| 311 | $codeObj['metaObj'] = $metaObj; |
| 312 | } else { |
| 313 | $codeObj = $this->setMetaObj($codeObj); |
| 314 | } |
| 315 | } |
| 316 | $metaObj = $codeObj['metaObj']; |
| 317 | $ticket_id = $this->getTicketId($codeObj, $metaObj); |
| 318 | $qrCodeContent = $ticket_id; |
| 319 | if ($this->MAIN->getOptions()->isOptionCheckboxActive('ticketQRUseURLToTicketScanner')) { |
| 320 | $qrCodeContent = $this->getTicketScannerURL($ticket_id); |
| 321 | } |
| 322 | if ($this->MAIN->getOptions()->isOptionCheckboxActive('qrUseOwnQRContent')) { |
| 323 | $qr_content = $this->MAIN->getAdmin()->getOptionValue('qrOwnQRContent'); |
| 324 | if (!empty($qr_content)) { |
| 325 | $qrCodeContent = $this->replaceURLParameters($qr_content, $codeObj); |
| 326 | } |
| 327 | } |
| 328 | $qrCodeContent = apply_filters( $this->MAIN->_add_filter_prefix.'core_getQRCodeContent', $qrCodeContent ); |
| 329 | return $qrCodeContent; |
| 330 | } |
| 331 | |
| 332 | public function getMetaObjectAuthtoken() { |
| 333 | $metaObj = [ |
| 334 | 'desc'=>'', |
| 335 | 'ticketscanner'=>["bound_to_products"=>""] |
| 336 | ]; |
| 337 | if ($this->MAIN->isPremium() && method_exists($this->MAIN->getPremiumFunctions(), 'getMetaObjectAuthtoken')) { |
| 338 | $metaObj = $this->MAIN->getPremiumFunctions()->getMetaObjectAuthtoken($metaObj); |
| 339 | } |
| 340 | return $metaObj; |
| 341 | } |
| 342 | |
| 343 | public function encodeMetaValuesAndFillObjectAuthtoken($metaValuesString) { |
| 344 | $metaObj = $this->getMetaObjectAuthtoken(); |
| 345 | if (!empty($metaValuesString)) { |
| 346 | $metaObj = array_replace_recursive($metaObj, json_decode($metaValuesString, true)); |
| 347 | } |
| 348 | return $metaObj; |
| 349 | } |
| 350 | |
| 351 | public function alignArrays(&$array1, &$array2) { |
| 352 | // Füge fehlende Schlüssel von array1 zu array2 hinzu |
| 353 | foreach ($array1 as $key => $value) { |
| 354 | if (!array_key_exists($key, $array2)) { |
| 355 | $array2[$key] = is_array($value) ? [] : null; |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | // Entferne überschüssige Schlüssel aus array2 |
| 360 | foreach ($array2 as $key => $value) { |
| 361 | if (!array_key_exists($key, $array1)) { |
| 362 | unset($array2[$key]); |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | // Rekursiver Aufruf für Subarrays |
| 367 | foreach ($array1 as $key => &$value) { |
| 368 | if (is_array($value) && array_key_exists($key, $array2) && is_array($array2[$key])) { |
| 369 | $this->alignArrays($value, $array2[$key]); |
| 370 | } |
| 371 | } |
| 372 | unset($value); // Referenz aufheben |
| 373 | } |
| 374 | |
| 375 | public function getUserIdsForCustomerName($search_query) { |
| 376 | $ret = []; |
| 377 | $search_query = trim($search_query); |
| 378 | if (empty($search_query)) return $ret; |
| 379 | $args = array( |
| 380 | 'meta_query' => array( |
| 381 | 'relation' => 'OR', |
| 382 | array( |
| 383 | 'key' => 'first_name', |
| 384 | 'value' => $search_query, |
| 385 | 'compare' => 'LIKE', |
| 386 | ), |
| 387 | array( |
| 388 | 'key' => 'last_name', |
| 389 | 'value' => $search_query, |
| 390 | 'compare' => 'LIKE', |
| 391 | ), |
| 392 | ), |
| 393 | ); |
| 394 | |
| 395 | $user_query = new WP_User_Query($args); |
| 396 | if (!empty($user_query->get_results())) { |
| 397 | foreach ($user_query->get_results() as $user) { |
| 398 | $ret[] = $user->ID; |
| 399 | } |
| 400 | } |
| 401 | return $ret; |
| 402 | } |
| 403 | |
| 404 | public function json_encode_with_error_handling($object, $depth=512) { |
| 405 | $json = json_encode($object, JSON_NUMERIC_CHECK, $depth); |
| 406 | if (json_last_error() !== JSON_ERROR_NONE) { |
| 407 | throw new Exception(json_last_error_msg()); |
| 408 | } |
| 409 | return $json; |
| 410 | } |
| 411 | |
| 412 | public function getRealIpAddr() { |
| 413 | if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet |
| 414 | { |
| 415 | $ip=sanitize_text_field($_SERVER['HTTP_CLIENT_IP']); |
| 416 | } |
| 417 | elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy |
| 418 | { |
| 419 | $ip=sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']); |
| 420 | } |
| 421 | else |
| 422 | { |
| 423 | $ip=sanitize_text_field($_SERVER['REMOTE_ADDR']); |
| 424 | } |
| 425 | return $ip; |
| 426 | } |
| 427 | |
| 428 | public function triggerWebhooks($status, $codeObj) { |
| 429 | $options = $this->MAIN->getOptions(); |
| 430 | if ($options->isOptionCheckboxActive('webhooksActiv')) { |
| 431 | $optionname = ""; |
| 432 | switch($status) { |
| 433 | case 0: |
| 434 | $optionname = "webhookURLinvalid"; |
| 435 | break; |
| 436 | case 1: |
| 437 | $optionname = "webhookURLvalid"; |
| 438 | break; |
| 439 | case 2: |
| 440 | $optionname = "webhookURLinactive"; |
| 441 | break; |
| 442 | case 3: |
| 443 | $optionname = "webhookURLisregistered"; |
| 444 | break; |
| 445 | case 4: |
| 446 | $optionname = "webhookURLexpired"; |
| 447 | break; |
| 448 | case 5: |
| 449 | $optionname = "webhookURLmarkedused"; |
| 450 | break; |
| 451 | case 6: |
| 452 | $optionname = "webhookURLsetused"; |
| 453 | break; |
| 454 | case 7: |
| 455 | $optionname = "webhookURLregister"; |
| 456 | break; |
| 457 | case 8: |
| 458 | $optionname = "webhookURLipblocking"; |
| 459 | break; |
| 460 | case 9: |
| 461 | $optionname = "webhookURLipblocked"; |
| 462 | break; |
| 463 | case 10: |
| 464 | $optionname = "webhookURLaddwcinfotocode"; |
| 465 | break; |
| 466 | case 11: |
| 467 | $optionname = "webhookURLwcremove"; |
| 468 | break; |
| 469 | case 12: |
| 470 | $optionname = "webhookURLaddwcticketinfoset"; |
| 471 | break; |
| 472 | case 13: |
| 473 | $optionname = "webhookURLaddwcticketredeemed"; |
| 474 | break; |
| 475 | case 14: |
| 476 | $optionname = "webhookURLaddwcticketunredeemed"; |
| 477 | break; |
| 478 | case 15: |
| 479 | $optionname = "webhookURLaddwcticketinforemoved"; |
| 480 | break; |
| 481 | case 16: |
| 482 | $optionname = "webhookURLrestrictioncodeused"; |
| 483 | break; |
| 484 | case 17: |
| 485 | $optionname = "webhookURLaddwcticketsold"; |
| 486 | break; |
| 487 | } |
| 488 | if (!empty($optionname)) { |
| 489 | $url = $options->getOption($optionname)['value']; |
| 490 | |
| 491 | if ($optionname == "webhookURLaddwcticketsold") { |
| 492 | $list_id = intval($codeObj['list_id']); |
| 493 | if ($list_id > 0) { |
| 494 | try { |
| 495 | $listObj = $this->MAIN->getAdmin()->getList(['id'=>$list_id]); |
| 496 | $metaObj = $this->encodeMetaValuesAndFillObjectList($listObj['meta']); |
| 497 | if (isset($metaObj['webhooks']) && isset($metaObj['webhooks']['webhookURLaddwcticketsold'])) { |
| 498 | if (!empty(trim($metaObj['webhooks']['webhookURLaddwcticketsold']))) { |
| 499 | $url = trim($metaObj['webhooks']['webhookURLaddwcticketsold']); |
| 500 | } |
| 501 | } |
| 502 | } catch(Exception $e) { |
| 503 | $this->MAIN->getAdmin()->logErrorToDB($e); |
| 504 | } |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | if (!empty($url)) { |
| 509 | $url = $this->replaceURLParameters($url, $codeObj); |
| 510 | wp_remote_get($url); |
| 511 | do_action( $this->MAIN->_do_action_prefix.'core_triggerWebhooks', $status, $codeObj, $url ); |
| 512 | } |
| 513 | } |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | private function _getCachedList($list_id) { |
| 518 | if (isset($this->_CACHE_list[$list_id])) return $this->_CACHE_list[$list_id]; |
| 519 | $this->_CACHE_list[$list_id] = $this->getListById($list_id); |
| 520 | return $this->_CACHE_list[$list_id]; |
| 521 | } |
| 522 | |
| 523 | public function replaceURLParameters($url, $codeObj) { |
| 524 | $url = str_replace("{CODE}", isset($codeObj['code']) ? $codeObj['code'] : '', $url); |
| 525 | $url = str_replace("{CODEDISPLAY}", isset($codeObj['code_display']) ? $codeObj['code_display'] : '', $url); |
| 526 | $url = str_replace("{IP}", $this->getRealIpAddr(), $url); |
| 527 | $userid = ''; |
| 528 | if (is_user_logged_in()) { |
| 529 | $userid = get_current_user_id(); |
| 530 | } |
| 531 | $url = str_replace("{USERID}", $userid, $url); |
| 532 | |
| 533 | $listname = ""; |
| 534 | if (isset($codeObj['list_id']) && $codeObj['list_id'] > 0 && strpos(" ".$url, "{LIST}") !== false) { |
| 535 | try { |
| 536 | $listObj = $this->_getCachedList($codeObj['list_id']); |
| 537 | $listname = $listObj['name']; |
| 538 | } catch (Exception $e) { |
| 539 | } |
| 540 | } |
| 541 | $url = str_replace("{LIST}", urlencode($listname), $url); |
| 542 | |
| 543 | $listdesc = ""; |
| 544 | if (isset($codeObj['list_id']) && $codeObj['list_id'] > 0 && strpos(" ".$url, "{LIST_DESC}") !== false) { |
| 545 | try { |
| 546 | $listObj = $this->_getCachedList($codeObj['list_id']); |
| 547 | $metaObj = []; |
| 548 | if (!empty($listObj['meta'])) $metaObj = $this->encodeMetaValuesAndFillObjectList($listObj['meta']); |
| 549 | if (isset($metaObj['desc'])) $listdesc = $metaObj['desc']; |
| 550 | } catch (Exception $e) { |
| 551 | } |
| 552 | } |
| 553 | $url = str_replace("{LIST_DESC}", urlencode($listdesc), $url); |
| 554 | |
| 555 | $metaObj = []; |
| 556 | if (!isset($codeObj['metaObj'])) { |
| 557 | if (!empty($codeObj['meta'])) $metaObj = $this->encodeMetaValuesAndFillObject($codeObj['meta'], $codeObj); |
| 558 | } else { |
| 559 | $metaObj = $codeObj['metaObj']; |
| 560 | } |
| 561 | if (count($metaObj) > 0) $url = $this->_replaceTagsInTextWithMetaObjectsValues($url, $metaObj, "META_"); |
| 562 | if (count($metaObj) > 0) $url = $this->_replaceTagsInTextWithMetaObjectsValues($url, $metaObj, ""); |
| 563 | |
| 564 | $url = apply_filters( $this->MAIN->_add_filter_prefix.'core_replaceURLParameters', $url, $codeObj, $metaObj ); |
| 565 | |
| 566 | return $url; |
| 567 | } |
| 568 | |
| 569 | private function _replaceTagsInTextWithMetaObjectsValues($text, $metaObj, $prefix="") { |
| 570 | $prefix = strtoupper(trim($prefix)); |
| 571 | foreach(array_keys($metaObj) as $key) { |
| 572 | $tag = $prefix.strtoupper($key); |
| 573 | if (is_array($metaObj[$key])) { |
| 574 | $text = $this->_replaceTagsInTextWithMetaObjectsValues($text, $metaObj[$key], $tag."_"); |
| 575 | } else { |
| 576 | $text = str_replace("{".$tag."}", urlencode($metaObj[$key]), $text); |
| 577 | } |
| 578 | } |
| 579 | return $text; |
| 580 | } |
| 581 | |
| 582 | public function checkCodeExpired($codeObj) { |
| 583 | if ($this->MAIN->isPremium() && method_exists($this->MAIN->getPremiumFunctions(), 'checkCodeExpired')) { |
| 584 | if ($this->MAIN->getPremiumFunctions()->checkCodeExpired($codeObj)) { |
| 585 | return true; |
| 586 | } |
| 587 | } |
| 588 | return false; |
| 589 | } |
| 590 | public function isCodeIsRegistered($codeObj) { |
| 591 | $meta = []; |
| 592 | if (!empty($codeObj['meta'])) $meta = $this->encodeMetaValuesAndFillObject($codeObj['meta'], $codeObj); |
| 593 | if (isset($meta['user']) && isset($meta['user']['value']) && !empty($meta['user']['value'])) { |
| 594 | return true; |
| 595 | } |
| 596 | return false; |
| 597 | } |
| 598 | |
| 599 | public function getTicketURLBase($defaultPath=false) { |
| 600 | $path = plugin_dir_url(__FILE__).$this->ticket_url_path_part; |
| 601 | if ($defaultPath == false) { |
| 602 | $wcTicketCompatibilityModeURLPath = trim($this->MAIN->getOptions()->getOptionValue('wcTicketCompatibilityModeURLPath')); |
| 603 | $wcTicketCompatibilityModeURLPath = trim(trim($wcTicketCompatibilityModeURLPath, "/")); |
| 604 | if (!empty($wcTicketCompatibilityModeURLPath)) { |
| 605 | $path = site_url()."/".$wcTicketCompatibilityModeURLPath; |
| 606 | } |
| 607 | } |
| 608 | $ret = $path."/"; |
| 609 | $ret = apply_filters( $this->MAIN->_add_filter_prefix.'core_getTicketURLBase', $ret ); |
| 610 | return $ret; |
| 611 | } |
| 612 | public function getTicketId($codeObj, $metaObj) { |
| 613 | $ret = ""; |
| 614 | if (isset($codeObj['code']) && isset($codeObj['order_id']) && isset($metaObj['wc_ticket']['idcode'])) { |
| 615 | $ret = $metaObj['wc_ticket']['idcode']."-".$codeObj['order_id']."-".$codeObj['code']; |
| 616 | } |
| 617 | $ret = apply_filters( $this->MAIN->_add_filter_prefix.'core_getTicketId', $ret, $codeObj, $metaObj ); |
| 618 | return $ret; |
| 619 | } |
| 620 | public function getTicketURL($codeObj, $metaObj) { |
| 621 | $ticket_id = $this->getTicketId($codeObj, $metaObj); |
| 622 | $baseURL = $this->getTicketURLBase(); |
| 623 | $url = $baseURL.$ticket_id; |
| 624 | if ($this->MAIN->getOptions()->isOptionCheckboxActive('wcTicketCompatibilityMode')) { |
| 625 | $url = $baseURL."?code=".$ticket_id; |
| 626 | } |
| 627 | $url = apply_filters( $this->MAIN->_add_filter_prefix.'core_getTicketURL', $url, $codeObj, $metaObj ); |
| 628 | return $url; |
| 629 | } |
| 630 | public function getOrderTicketIDCode($order) { |
| 631 | $order_id = $order->get_id(); |
| 632 | $idcode = $order->get_meta('_saso_eventtickets_order_idcode'); |
| 633 | if (empty($idcode)) { |
| 634 | $idcode = strtoupper(md5($order_id."-".current_time("timestamp")."-".uniqid())); |
| 635 | $order->update_meta_data( '_saso_eventtickets_order_idcode', $idcode ); |
| 636 | $order->save(); |
| 637 | } |
| 638 | return $idcode; |
| 639 | } |
| 640 | public function getOrderTicketId($order, $ticket_id_prefix="order-") { |
| 641 | $order_id = $order->get_id(); |
| 642 | $idcode = $this->getOrderTicketIDCode($order); |
| 643 | $ticket_id = trim($ticket_id_prefix).$order_id."-".$idcode; |
| 644 | return $ticket_id; |
| 645 | } |
| 646 | public function getOrderTicketsURL($order, $ticket_id_prefix="order-") { |
| 647 | if ($order == null) throw new Exception("Order empty - no order tickets PDF url created"); |
| 648 | $ticket_id = $this->getOrderTicketId($order, $ticket_id_prefix); |
| 649 | $baseURL = $this->getTicketURLBase(); |
| 650 | $url = $baseURL.$ticket_id; |
| 651 | if ($this->MAIN->getOptions()->isOptionCheckboxActive('wcTicketCompatibilityMode')) { |
| 652 | $url = $baseURL."?code=".$ticket_id; |
| 653 | } |
| 654 | $url = apply_filters( $this->MAIN->_add_filter_prefix.'core_getOrderTicketsURL', $url, $order, $ticket_id_prefix ); |
| 655 | return $url; |
| 656 | } |
| 657 | public function getTicketScannerURL($ticket_id) { |
| 658 | $baseURL = $this->getTicketURLBase(); |
| 659 | $url = $baseURL."scanner/?code=".urlencode($ticket_id); |
| 660 | $url = apply_filters( $this->MAIN->_add_filter_prefix.'core_getTicketScannerURL', $url, $ticket_id ); |
| 661 | return $url; |
| 662 | } |
| 663 | public function getTicketURLPath($defaultPath=false) { |
| 664 | $p = $this->getTicketURLBase($defaultPath); |
| 665 | $teile = parse_url($p); |
| 666 | $ret = $teile['path']; |
| 667 | $ret = apply_filters( $this->MAIN->_add_filter_prefix.'core_getTicketURLPath', $ret, $defaultPath ); |
| 668 | return $ret; |
| 669 | } |
| 670 | public function getTicketURLComponents($url) { |
| 671 | $teile = explode("/", $url); |
| 672 | $teile = array_reverse($teile); |
| 673 | $request = ""; |
| 674 | $is_pdf_request = false; |
| 675 | $is_ics_request = false; |
| 676 | $is_badge_request = false; |
| 677 | $foundcode = ""; |
| 678 | foreach($teile as $teil) { |
| 679 | $teil = trim($teil); |
| 680 | if (empty($teil)) continue; |
| 681 | if (strtolower($teil) == "?pdf") continue; |
| 682 | if (strtolower($teil) == "?ics") continue; |
| 683 | if ($teil == $this->ticket_url_path_part) break; |
| 684 | $foundcode = $teil; |
| 685 | break; |
| 686 | } |
| 687 | if (SASO_EVENTTICKETS::issetRPara('code')) { // overwrites any found code, if parameter is available |
| 688 | $foundcode = trim(SASO_EVENTTICKETS::getRequestPara('code')); |
| 689 | if (strpos($foundcode, "'") === false) { |
| 690 | $parts = explode("-", $foundcode); |
| 691 | } else { |
| 692 | $parts = explode("'", $foundcode); |
| 693 | } |
| 694 | $t = explode("?", $url); |
| 695 | if (count($t) > 1) { |
| 696 | unset($t[0]); |
| 697 | $tt = []; |
| 698 | foreach($t as $tp){ |
| 699 | $ttt = explode("&", $tp); |
| 700 | $tt = array_merge($tt, $ttt); |
| 701 | } |
| 702 | $t = $tt; |
| 703 | $request = join("&", $t); |
| 704 | } |
| 705 | $is_pdf_request = in_array("pdf", $t); |
| 706 | $is_ics_request = in_array("ics", $t); |
| 707 | $is_badge_request = in_array("badge", $t); |
| 708 | } else { |
| 709 | if (empty($foundcode)) throw new Exception("#9301 ticket id not found from ticket url"); |
| 710 | $parts = explode("-", $foundcode); |
| 711 | if (count($parts) < 3) throw new Exception("#9303 ticket id is wrong"); |
| 712 | $t = explode("?", $parts[2]); |
| 713 | $parts[2] = $t[0]; |
| 714 | if (count($t) > 1) { |
| 715 | unset($t[0]); |
| 716 | $request = join("&", $t); |
| 717 | } |
| 718 | $is_pdf_request = in_array("pdf", $t) || SASO_EVENTTICKETS::issetRPara('pdf'); |
| 719 | $is_ics_request = in_array("ics", $t) || SASO_EVENTTICKETS::issetRPara('ics'); |
| 720 | $is_badge_request = in_array("badge", $t) || SASO_EVENTTICKETS::issetRPara('badge'); |
| 721 | } |
| 722 | if (count($parts) != 3) throw new Exception("#9302 ticket id not correct - cannot create ticket url components"); |
| 723 | $parts[2] = str_replace("?pdf", "", $parts[2]); |
| 724 | $parts[2] = str_replace("?ics", "", $parts[2]); |
| 725 | $parts_assoc = [ |
| 726 | "foundcode"=>$foundcode, |
| 727 | "idcode"=>$parts[0], |
| 728 | "order_id"=>$parts[1], |
| 729 | "code"=>$parts[2], |
| 730 | "_request"=>$request, |
| 731 | "_isPDFRequest"=>$is_pdf_request, |
| 732 | "_isICSRequest"=>$is_ics_request, |
| 733 | "_isBadgeRequest"=>$is_badge_request |
| 734 | ]; |
| 735 | $parts_assoc = apply_filters( $this->MAIN->_add_filter_prefix.'core_getTicketURLComponents', $parts_assoc, $url ); |
| 736 | return $parts_assoc; |
| 737 | } |
| 738 | |
| 739 | public function mergePDFs($filepaths, $filename, $filemode="I", $deleteFilesAfterMerge=true) { |
| 740 | if (count($filepaths) > 0) { |
| 741 | $pdf = $this->MAIN->getNewPDFObject(); |
| 742 | $pdf->setFilemode($filemode); |
| 743 | $pdf->setFilename($filename); |
| 744 | try { |
| 745 | $pdf->mergeFiles($filepaths); // send file to browser if,filemode is I |
| 746 | } catch(Exception $e) { |
| 747 | $this->MAIN->getAdmin()->logErrorToDB($e, null, "tried to merge PDFs together. Filepaths: (".join(", ", $filepaths).")"); |
| 748 | } |
| 749 | |
| 750 | // clean up temp files |
| 751 | if ($deleteFilesAfterMerge) { |
| 752 | foreach($filepaths as $filepath) { |
| 753 | if (file_exists($filepath)) { |
| 754 | @unlink($filepath); |
| 755 | } |
| 756 | } |
| 757 | } |
| 758 | if ($pdf->getFilemode() == "F") { |
| 759 | return $pdf->getFullFilePath(); |
| 760 | } else { |
| 761 | exit; |
| 762 | } |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | public function parser_search_loop($text) { |
| 767 | // search for loop |
| 768 | // {{LOOP ORDER.items AS item}} loop-content {{LOOPEND}} |
| 769 | if (empty($text)) return false; |
| 770 | $pos = strpos($text, "{{LOOP "); |
| 771 | if ($pos !== false) { |
| 772 | $pos_end = strpos($text, "{{LOOPEND}}", $pos); |
| 773 | if ($pos_end !== false) { |
| 774 | $pos_end += 11; |
| 775 | $html_part = substr($text, $pos, $pos_end - $pos); |
| 776 | //echo $html_part; |
| 777 | |
| 778 | $matches = []; |
| 779 | |
| 780 | $collection = null; |
| 781 | $item_var = null; |
| 782 | $loop_part = null; |
| 783 | // finde loop collection and item var |
| 784 | $pattern = '/{{\s?LOOP\s(.*?)\sAS\s(.*?)\s?}}(.*?){{\s?LOOPEND\s?}}/is'; |
| 785 | if (preg_match($pattern, $html_part, $matches)) { |
| 786 | $collection = trim($matches[1]); |
| 787 | $item_var = trim($matches[2]); |
| 788 | $loop_part = trim($matches[3]); |
| 789 | } |
| 790 | |
| 791 | return [ |
| 792 | "collection"=>$collection, |
| 793 | "item_var"=>$item_var, |
| 794 | "loop_part"=>$loop_part, |
| 795 | "pos_start"=>$pos, |
| 796 | "pos_end"=>$pos_end, |
| 797 | "found_str"=>$matches[0] |
| 798 | ]; |
| 799 | } |
| 800 | } |
| 801 | return false; |
| 802 | } |
| 803 | } |
| 804 | ?> |