diff --git a/src/snippets/172_registration_maxlength.php b/src/snippets/172_registration_maxlength.php new file mode 100644 index 0000000..000f32f --- /dev/null +++ b/src/snippets/172_registration_maxlength.php @@ -0,0 +1,43 @@ +?> + + + ?> + + + + + + + + + + + + + +
Bei Premium-Snipes werden dir deine FastCoins wieder gutgeschrieben.', 'Ja', 'Abbrechen', '_self'); + } + } + if(page_id() === 978) { // inaktive-snipes + if (isset($_GET["d"])) { + $category = 'expired'; + [$bool, $redirect] = db_delete_own_post_by_requestid_category($category, $_GET["d"]); + if ($redirect) + redirect($redirect); + else + redirect('.'); + } + else { + show_button_container(); + confirm_modal('#button-delete-appointment', 'id', 'Löschen', 'Termin wirklich löschen?

Bei Premium-Snipes werden dir deine FastCoins wieder gutgeschrieben.', 'Ja', 'Abbrechen', '_self'); + } + } + if(page_id() === 965) { // meine-snipes + if (isset($_GET["d"])) { + $category = 'appointment'; + db_delete_own_post_by_requestid_category($category, $_GET["d"]); + redirect('.'); + } + else { + show_button_container(); + confirm_modal('#button-delete-appointment', 'id', 'Löschen', 'Termin wirklich löschen?

Bei erfolgreichen Premium-Snipes werden keine FastCoins gutgeschrieben.', 'Ja', 'Abbrechen', '_self'); + } + } + if(page_id() === 986) { // account + if (isset($_GET["d"])) { + php_console_log('deleting account...'); + api_delete_account(); + wp_logout(); + } + else { + button_change_account(); + //show_button_container(); + confirm_modal('#button-delete-account', 'id', 'Account löschen', 'Account endgültig löschen?

Bitte beachte, dass alle deine Daten, sowie alle aktiven Suchen und erfolgreiche Snipes gelöscht werden.

FastCoins kannst du ggfs. vorher an Freunde senden, da sie sonst verloren gehen.
Rückerstattungen sind nicht möglich.', 'Ja', 'Abbrechen', '_self'); + } + } +} + +function button_change_account() { + ?> + + $user->ID, + 'event' => 'restapi-delete-user', + ); + + // Create the context for the request + $context = stream_context_create(array( + 'http' => array( + 'method' => 'POST', + 'header' => "Content-Type: application/json\r\n", + 'content' => json_encode($postData) + ) + )); + + // Send the request + $response = file_get_contents('https://terminsnipe:y9aFwUO7htuyKMaaPQWu@service.berlin.de.zinomedia.de/www/src/terminsnipe_controller.pl', FALSE, $context); + + // Check for errors + if($response === FALSE){ + die('Error'); + } + + // Decode the response + $responseData = json_decode($response, TRUE); + + // Print the date from the response + echo $responseData['published']; + dump_to_file('/var/www/lab/newfile.txt', $responseData); + +} + +function show_button_container() { + ?> + + $request_id, + 'category' => $category, + ); + $postslist = get_own_posts_by_tag_and_category($data); + + if (!empty($postslist)) { + php_console_log('Post belongs to user'); + + // DELETE FROM DB + if ($category === 'requests') { + $table = 'request'; + } + else if ($category === 'expired') { + $table = 'request'; + } + else if ($category === 'appointment') { + $table = 'appointments'; + } + + $wpdb = connect_to_server('zinomedia'); + $status = $wpdb->delete( $table, array( 'ID' => $_GET["d"] ) ); + + if ($category === 'requests' || $category === 'expired') { + [$bool, $redirect] = refund_coins($postslist, $user); + return [$bool, $redirect]; + } + } + else if (empty($postslist)) { + php_console_log('Post does NOT belong to user'); + + return [0, null]; + } +} + +function refund_coins($postslist, $user) { + $postmeta = get_post_meta( $postslist[0]->ID ); + if( $postmeta['is_premium'][0] ) { + $balance_before_refund = mycred_return_users_balance(); + mycred_add( 'booking_manually_cancelled', $user->ID, $postmeta['price'][0], 'Cancellation by user, refund points' ); + $redirect = 'http://zinomedia.de/terminsnipe/?uccr&price=' . $postmeta['price'][0] . '&bbr=' . $balance_before_refund; + return [1, $redirect]; + } + else { + return [0, null]; + } +} + +function confirm_modal($button_id, $data_attribute, $title, $msg, $true, $false, $open) { + ?> + + array( + 'relation' => 'AND', + array( + 'taxonomy' => 'post_tag', + 'field' => 'slug', + 'terms' => $data['tag1'], + 'include_children' => false + ), + array( + 'taxonomy' => 'post_tag', + 'field' => 'slug', + 'terms' => $user->user_nicename, + 'include_children' => false + ), + array( + 'taxonomy' => 'category', + 'field' => 'slug', + 'terms' => $data['category'], + ), + ) + ); + $postslist = get_posts( $args ); + + return $postslist; +} \ No newline at end of file diff --git a/src/snippets/confetti.php b/src/snippets/confetti.php new file mode 100644 index 0000000..755f847 --- /dev/null +++ b/src/snippets/confetti.php @@ -0,0 +1,20 @@ +?> + + + + + +

Willkommen bei den Terminsnipern, ' . $matches_name[1] . '!

+

Klicke auf den unten stehenden Link, erstelle dein Passwort und werde Teil des Snipe-Hypes! Ab jetzt nie wieder Warteschleife am Bürgertelefon. Nie wieder außerhalb der Telefonzeiten. Nie wieder Chatbot Bobbi. Du bestimmst die Regeln, wir erledigen den Rest.

+

Hier legst du ein Passwort fest: Jetzt Passwort erstellen

+

Übrigens: FastCoins sind unsere smarte und sichere Bezahlmethode für Premium-Zeiträume. Hast du es nicht so eilig? Dann schnappe dir einen Free-Termin. Du bestimmst die Regeln, wir erledigen den Rest.

+ + '; + } + else if ( strpos( $subject, 'Du hast dein Passwort erfolgreich geändert') !== false ) { + $matches = array(); + preg_match('/You can now login here: (.+?) + High Five, ' . trim($matches_name[1]) . '! +

+ Du hast dein Passwort erfolgreich geändert:

+

+ Benutzername: ' . $matches_email[1] . '
+ Password: *** Erfolgreich geändert ***

+

Hier kannst du dich direkt einloggen: Jetzt einloggen

'; + } + + return $message; +}, 11, 4 ); \ No newline at end of file diff --git a/src/snippets/failed_request_creation_logged_out.php b/src/snippets/failed_request_creation_logged_out.php new file mode 100644 index 0000000..c290359 --- /dev/null +++ b/src/snippets/failed_request_creation_logged_out.php @@ -0,0 +1,240 @@ +?> +$v) { + php_console_log('k: ' . $k . ' v: ' . $v); + } + + // DIENSTLEISTUNG + $wpdb = connect_to_server('zinomedia'); + $dienstleistung = $wpdb->get_var('SELECT NAME FROM services WHERE ID = ' . $_GET['SERVICE_ID']); + php_console_log('Dienstleistung: ' . $dienstleistung ); + + // DATETIMES + if (isset($_GET['SWITCH_TERMINTYPE']) && $_GET['SWITCH_TERMINTYPE'] == 'zeitraum') { + $datetime_from = create_date($_GET['WOCHENTAG_START'], $_GET['UHRZEIT_START']); + $datetime_to = create_date($_GET['WOCHENTAG_END'], $_GET['UHRZEIT_END']); + } + else if (isset($_GET['SWITCH_TERMINTYPE']) && $_GET['SWITCH_TERMINTYPE'] == 'sofort') { + $timestamp = time(); + $dt = new DateTime("now", new DateTimeZone('Europe/Berlin')); + $dt->setTimestamp($timestamp); + $datetime_from = $dt->format('Y-m-d H:i:s'); + $datetime_to = create_date($_GET['WOCHENTAG_END'], $_GET['UHRZEIT_END']); + } + + // BUERGERAEMTER + $buergeraemter = create_buergeraemter(); + + // CREATE APPOINTMENT + php_console_log('datetime_from after: ' . $datetime_from); + php_console_log('datetime_to after: ' . $datetime_to); + $data = array( + 'category' => 'request-failed-logged-out', + 'request' => array( + 'BUERGERAEMTER' => $buergeraemter, + 'WP_ID' => $_GET['WP_ID'], + 'SERVICE_ID' => $_GET['SERVICE_ID'], + 'DIENSTLEISTUNG' => $dienstleistung, + 'DATETIME_FROM' => $datetime_from, + 'DATETIME_TO' => $datetime_to, + ), + ); + $post_content = create_post_content($data); + $post_content = trim(preg_replace('/\s+/', ' ', $post_content)); + + // PUT APPOINTMENT ON PAGE + js_manipulate_html($post_content); + } + else { + php_console_log('Not all GET data present'); + close_modal(); + } + } +} + +function close_modal() { + ?> + + get_results( " + Select + venues.NAME + From + services Inner Join + mapping_services On mapping_services.SERVICE_ID = services.ID Inner Join + venues On mapping_services.VENUE_ID = venues.ID + Where + services.ID = $_GET[SERVICE_ID] + ", ARRAY_N ); + + // ACCUMULATE TO ONE ARRAY + $buergeraemter = array(); + foreach ($rows as $array) { + array_push($buergeraemter, $array[0]); + } + } + else if (isset($_GET['SWITCH_STANDORTE']) && $_GET['SWITCH_STANDORTE'] == 'standorte-auswaehlen') { + // CREATE ARRAY WITH VENUE_IDs FROM STRING + $buergeraemter_get = explode(',',$_GET['STANDORTE']); + + // CREATE SQL QUERY STRING WITH VENUE IDs + $i = 0; + $len = count($buergeraemter_get); + foreach ($buergeraemter_get as $venue_id) { + $venue_query .= 'venues.ID = ' . $venue_id; + if ($i !== $len - 1) { + // last + $venue_query .= ' Or '; + } + $i++; + } + + // GET VENUE NAMES FROM DB + $rows = $wpdb->get_results( " + Select venues.NAME From venues Where ($venue_query) + ", ARRAY_N ); + + // ACCUMULATE TO ONE ARRAY + $buergeraemter = array(); + foreach ($rows as $array) { + array_push($buergeraemter, $array[0]); + } + } + + return $buergeraemter; +} + +function create_date($day, $time) { + $datetime = $day . ' ' . $time; + if (strpos($time, '-') !== false) { + $format = 'Y-m-d H-i'; + } + else { + $format = 'Y-m-d H'; + } + $datetime = DateTime::createFromFormat($format, $datetime); + $datetime = $datetime->format('Y-m-d H:i:s'); + + return $datetime; +} + +function js_manipulate_html($post_content) { + ?> + + + array ( $user->user_nicename ), + 'category' => 'requests', + 'meta_key' => 'is_premium', + 'meta_value' => 0, + ); + + return get_posts_by_tag_category_postmeta($data); + } + + function get_own_premium_requests() { + $user = wp_get_current_user(); + $data = array( + 'tags' => array ( $user->user_nicename ), + 'category' => 'requests', + 'meta_key' => 'is_premium', + 'meta_value' => 1, + ); + + return get_posts_by_tag_category_postmeta($data); + } + + function get_posts_by_tag_category_postmeta($data) { + $args = array( + 'tax_query' => array( + 'relation' => 'AND', + array( + 'taxonomy' => 'post_tag', + 'field' => 'slug', + 'terms' => $data['tags'], + 'include_children' => false + ), + array( + 'taxonomy' => 'category', + 'field' => 'slug', + 'terms' => $data['category'], + ), + ), + 'meta_query' => array( + array( + 'key' => $data['meta_key'], + 'value' => $data['meta_value'], + 'compare' => '=', + ) + ) + ); + $postslist = get_posts( $args ); + + return $postslist; + } + + function get_fastsnipeObj() { + return array( + 1 => array( + 'price' => 2250, + 'day_end' => 7, + 'color' => '#f8dd4d', + ), + 2 => array( + 'price' => 1800, + 'day_end' => 14, + 'color' => 'hotpink', + ), + 3 => array( + 'price' => 1100, + 'day_end' => 21, + 'color' => '#fd9f02', + ), + 4 => array( + 'price' => 500, + 'day_end' => 35, + 'color' => '#87cefa', + ), + ); + } + + function subtract_fastcoins_by_start_date( $fastsnipeObj, $termintype_switch, $wochentag_start_text = null ) { + [$bool, $user_balance, $price, $is_premium] = check_premium( $fastsnipeObj, $termintype_switch, $wochentag_start_text ); + // bool 1 - enough coins for booking + // bool 0 - not enough cons for booking + // bool null - no premium date + + if ( $bool ) { + $user_id = get_current_user_id(); + mycred_subtract( 'fastsnipe', $user_id, $price, 'Forms booking completed' ); + } + + return [$bool, $user_balance, $price, $is_premium]; + } + + function check_premium( $fastsnipeObj, $fswitch, $wochentag_start_text ) { + $user_id = get_current_user_id(); + $user_balance = mycred_get_users_balance( $user_id ); + + if ( $fswitch == 'zeitraum' ) { + $i = DateDiffFromNow($wochentag_start_text); + } + else if ( $fswitch == 'sofort' ) { + $i = 0; + } + + if( $price = get_premium_price($fastsnipeObj, $i) ) { + $is_premium = 1; + if ( can_afford($user_balance, $price) ) { + $bool = 1; + } + else { + $bool = 0; + } + } + else { + $is_premium = 0; + $bool = null; + } + + return array($bool, $user_balance, $price, $is_premium); + } + + function can_afford($user_balance, $price) { + $can_afford = 0; + $diff = $user_balance-$price; + if( $diff >= 0 ) { + $can_afford = 1; + } + + return $can_afford; + } + + function get_premium_price($fastsnipeObj, $i) { + $price = 0; + foreach ($fastsnipeObj as $key => $value) { + $day_end = $fastsnipeObj[$key]['day_end'] - 2; + if ($i <= $day_end) { + $price = $fastsnipeObj[$key]['price']; + break; + } + } + return $price; + } + + function DateDiffFromNow($d2) { + $d1 = new DateTime(); + $d2 = new DateTime($d2); + $dDiff = $d1->diff($d2); + return $dDiff->format('%r%a'); + } + + function user_has_snipes_in_category($category) { + $user = wp_get_current_user(); + $data = array( + 'tags' => array ( $user->user_nicename ), + 'category' => $category, + ); + $postslist = get_posts_by_tag_and_category($data); + return count($postslist); + } + + function remove_url_parameter() { + ?> + + Terminsuche läuft ...

'; + $buttons = ' +
+ Löschen & FastCoins zurückerhalten +
+ '; + } + else if ($data[category] == 'expired') { + $date = createDate($data[request][DATETIME_FROM], $data[request][DATETIME_TO], $data[category]); + $status = '

Terminsuche abgelaufen

'; + $buttons = ' +
+ Löschen & FastCoins zurückerhalten +
+ '; + } + else if ($data[category] == 'appointment') { + $date = createDate($data[request][DATETIME], null, $data[category]); + $status = '

Termin gefunden & gebucht

'; + $buttons = ' +
+ Termin selbst absagen + Löschen +
+ '; + + //TERMINDETAILS PROCESS ID & AUTH KEY + $termindetails = '' . + '' . + '' . + ''; + $count_buergeraemter = count($data['request']['BUERGERAEMTER']); + foreach($data[request]['BUERGERAEMTER'] as $buergeramt) { + $buergeraemter .= ""; + } + $buergeraemter = $buergeraemter . '
Vorgangsnummer:' . + $data[request]['PROCESS_ID'] . + '
$buergeramt
'; + + // DIENSTLEISTUNG + $dienstleistung = $data[request]['DIENSTLEISTUNG']; + + // CHECK IF PREMIUM POST + $fastsnipeObj = get_fastsnipeObj(); + [$bool, $user_balance, $price, $is_premium] = check_premium( $fastsnipeObj, 'zeitraum', $data['request']['DATETIME_FROM'] ); + + // RESTRICT ACCESS TO POST BY USER + $post_content = add_rule_id($data, $post_content, 'beginning'); + + // CONTENT CONCATENATE + if ($buttons) { + $post_content .= $buttons; + } + + $post_content .= "

Status

+
$status
"; + + if (strcmp('request-failed-logged-out', $data['category']) !== 0) { + $post_content .= "

Preis

+
$price \"fastcoin\"
"; + } + + $post_content .= "

Was?

+
$dienstleistung
"; + + if ($termindetails) { + $post_content .= + "

Termindetails

+
$termindetails
"; + } + + $post_content .= + "

Wann?

+
$date
+

Wo?

+
+

Insgesamt $count_buergeraemter Bürgerämter

+ $buergeraemter + « zurückweiter » +
"; + + // RESTRICT ACCESS TO POST BY USER + $post_content = add_rule_id($data, $post_content, 'ending'); + + return $post_content; + } + + function createDate($dateTimeString_from, $dateTimeString_to, $category) { + $monthDayNames = array ( + 'Jan' => 'Januar', + 'Feb' => 'Februar', + 'Mar' => 'März', + 'Apr' => 'April', + 'May' => 'Mai', + 'Jun' => 'Juni', + 'Jul' => 'Juli', + 'Aug' => 'August', + 'Sep' => 'September', + 'Oct' => 'Oktober', + 'Nov' => 'November', + 'Dec' => 'Dezember', + 'Mon' => 'Montag', + 'Tue' => 'Dienstag', + 'Wed' => 'Mittwoch', + 'Thu' => 'Donnerstag', + 'Fri' => 'Freitag', + 'Sat' => 'Samstag', + 'Sun' => 'Sonntag', + ); + + // CREATE DATE STRING + $datetime_from = new DateTime($dateTimeString_from); + if ($category == 'requests' || $category == 'expired' || $category == 'request-failed-logged-out') { + $datetime_to = new DateTime($dateTimeString_to); + if($datetime_from->format('d') == $datetime_to->format('d') && // SAME DAY BOOKINGS + $datetime_from->format('m') == $datetime_to->format('m') && + $datetime_from->format('y') == $datetime_to->format('y')) { + $date = $monthDayNames[$datetime_from->format('D')] . ', ' . + $datetime_from->format('d') . '. ' . + $monthDayNames[$datetime_from->format('M')] . ' ' . + $datetime_from->format('Y') . ' von ' . + $datetime_from->format('H') . ':' . + $datetime_from->format('i') . ' Uhr bis ' . + $datetime_to->format('H') . ':' . + $datetime_to->format('i') . ' Uhr'; + } + else { # TWO DIFFERENT DATETIME BOOKINGS + $date = '' . + '' . + '' . + '' . + '' . + '
Von:' . + $monthDayNames[$datetime_from->format('D')] . ', ' . + $datetime_from->format('d') . '. ' . + $monthDayNames[$datetime_from->format('M')] . ' ' . + $datetime_from->format('Y') . ' ' . + $datetime_from->format('H') . ':' . + $datetime_from->format('i') . ' Uhr' . + '
Bis:' . + $monthDayNames[$datetime_to->format('D')] . ', ' . + $datetime_to->format('d') . '. ' . + $monthDayNames[$datetime_to->format('M')] . ' ' . + $datetime_to->format('Y') . ' ' . + $datetime_to->format('H') . ':' . + $datetime_to->format('i') . ' Uhr' . + '
'; + } + } + else if ($category == 'appointment') { + $date = 'pao'; + $date = $monthDayNames[$datetime_from->format('D')] . ', ' . + $datetime_from->format('d') . '. ' . + $monthDayNames[$datetime_from->format('M')] . ' ' . + $datetime_from->format('Y') . ' um ' . + $datetime_from->format('H') . ':' . + $datetime_from->format('i') . ' Uhr'; + } + + return $date; + } + + function add_rule_id($data, $post_content, $switch) { + if ($data['category'] == 'requests' || $data['category'] == 'expired' || $data['category'] == 'appointment') { + if ($switch == 'beginning') { + $rule_id = mpr_get_user_rule_id($data); + $post_content = '[mepr-show if="rule: ' . $rule_id . '"]'; + } + else if ($switch == 'ending') { + $post_content .= '[/mepr-show]'; + } + } + + return $post_content; + } + + function mpr_get_user_rule_id($data) { + global $wpdb; + $user_email = $data[user]->user_email; + $rule_id = $wpdb->get_var( "SELECT rule_id FROM wp_6_mepr_rule_access_conditions WHERE access_condition = '$user_email'" ); + + return $rule_id; + } + + function is_child_of( $id ) { + return ( is_page() && $id === get_post()->post_parent ); + } + + function is_menu_page() { + $id = 980; + //return ( is_page() && $id === get_post()->post_parent || page_id() === $id ); + if ( is_page() && $id === get_post()->post_parent || page_id() === $id ) { + return 1; + } + else { + return 0; + } + } + + function set_filter_tag($settings) { + // CURRENT USER OBJECT + $user = wp_get_current_user(); + + // SET RIGHT CATEGORY + if(page_id() === 975) { + $category = 'requests'; + } + else if(page_id() === 978) { + $category = 'expired'; + } + else if(page_id() === 965) { + $category = 'appointment'; + } + + // CREATE TAG TO DISPLAY RIGHT CONTENT IN CONTENT GRID POSTS MODULE + $filter_tags = get_user_filter_tags($user); + $filter_tag = $filter_tags[$category]; + + // GET TERM ID BY TAG SLUG AND CHANGE tax_post_post_tag of CONTENT GRID + $tag = get_term_by('slug', $filter_tag, 'post_tag'); + $settings->tax_post_post_tag = $tag->term_id; + } + + function page_id() { + global $wp_query; + return $wp_query->post->ID; + } + + function php_console_log($data) { + $output = $data; + if (is_array($output)) { + $output = implode(',', $output); + } + echo ""; + } + + function current_url() { + return (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; + } + + function redirect($url, $statusCode = 303) { + header('Location: ' . $url, true, $statusCode); + die(); + } + + function connect_to_server($server) { + if ($server == 'zinomedia') { + return new wpdb('terminsnipe','dIHB6JLk0CBBx1p7','terminsnipe','localhost'); + } + } + + function dump_to_file($file, $data, $method = '') { + if ($method == 'clear') { + $f = @fopen($file, "r+"); + if ($f !== false) { + ftruncate($f, 0); + fclose($f); + } + + $timestamp = "\n[" . date('m/d/Y h:i:sa', time()) . "]\n"; + file_put_contents($file, $timestamp, FILE_APPEND | LOCK_EX); + } + + if (is_array($data) || is_object($data)) { + $data = print_r($data, true); + } + + file_put_contents($file, $data.PHP_EOL , FILE_APPEND | LOCK_EX); + } + + function sort_aoa_by_value($array, $value) { + $arr = array(); + foreach ($array as $key => $item) { + $arr[$item[$value]][$key] = $item; + } + ksort($arr, SORT_NUMERIC); + return $arr; + } + + function json_request($url, $data = array(), $method = 'POST', $header = '') { + $options = array( + 'http' => array( + 'method' => $method, + 'content' => json_encode( $data ), + 'header'=> $header + ) + ); + $context = stream_context_create( $options ); + $result = file_get_contents( $url, false, $context ); + //$response = json_decode( $result ); + + return $result; + } + + function mbpr_restapi_delete_rule_by_title($data) { + $rule = get_page_by_title( $data[post_title], OBJECT, $data[post_type] ); + if ($rule) { + $url = 'http://zinomedia.de/terminsnipe/wp-json/mp/v1/rules/' . $rule->ID; + $response = json_request( $url, + array(), + 'DELETE', + "Content-Type: application/json\r\nAccept: application/json\r\nAuthorization: sKjdz2pUHx" + ); + return $response; + } + } + + function mbpr_restapi_add_rule($data) { + global $wpdb; + + $data_request = array( 'rule_type' => $data[rule_type], + 'unauth_excerpt_type' => $data[unauth_excerpt_type], + 'rule_content' => $data[rule_content], + ); + $response = json_request( 'http://zinomedia.de/terminsnipe/wp-json/mp/v1/rules', + $data_request, + 'POST', + "Content-Type: application/json\r\nAccept: application/json\r\nAuthorization: sKjdz2pUHx" + ); + $response_decoded = json_decode($response); + + // RENAME POST BECAUSE API SETS NO TITLE + $wpdb->update( + 'wp_6_posts', + array( + 'post_title' => $data[post_title], + ), + array( 'ID' => $response_decoded->id ) + ); + + // FIX: MANUALLY ADD CORRECT RULE CONDITIONS + $wpdb->insert( + 'wp_6_mepr_rule_access_conditions', + array( + 'rule_id' => $response_decoded->id, + 'access_type' => $data[access_type], + 'access_operator' => $data[access_operator], + 'access_condition' => $data[access_condition] + ) + ); + + return $response; + } + + function get_posts_by_tag_and_category($data) { + $args = array( + 'tax_query' => array( + 'relation' => 'AND', + array( + 'taxonomy' => 'post_tag', + 'field' => 'slug', + 'terms' => $data[tags], + 'include_children' => false + ), + array( + 'taxonomy' => 'category', + 'field' => 'slug', + 'terms' => $data[category], + ), + ) + ); + $postslist = get_posts( $args ); + + return $postslist; + } + + function get_posts_by_tag($data) { + $args = array( + 'post_status' => $data[post_status], + 'tax_query' => array( + 'relation' => 'AND', + array( + 'taxonomy' => 'post_tag', + 'field' => 'slug', + 'terms' => $data[tags], + 'include_children' => false + ) + ) + ); + $postslist = get_posts( $args ); + + return $postslist; + } + + function delete_posts_by_tag_and_category($data) { + $postslist = get_posts_by_tag_and_category($data); + foreach ($postslist as $post) { + wp_delete_post( $post->ID, true ); + } + } + + function delete_posts_by_tag($data) { + // Rework to use get_posts_by_tag if possible + $args = array( + 'post_status' => 'any', + 'tax_query' => array( + array( + 'taxonomy' => 'post_tag', + 'field' => 'slug', + 'terms' => $data[tags], + 'include_children' => true + ), + ) + ); + $postslist = get_posts( $args ); + + foreach ($postslist as $post) { + wp_delete_post( $post->ID, true ); + } + } + + function delete_tag_by_slug($slug) { + $term = get_term_by('slug', $slug, 'post_tag'); + wp_delete_term($term->term_id, 'post_tag'); + } + + function get_user_filter_tags($user) { + $filter_tag = array(); + $filter_tag[requests] = $user->user_nicename . '-r'; + $filter_tag[expired] = $user->user_nicename . '-e'; + $filter_tag[appointment] = $user->user_nicename . '-a'; + return $filter_tag; + } +} +} + +$ob = new HelperFunctions(); +$ob->declareGlobalsFn(); \ No newline at end of file diff --git a/src/snippets/global_helper_functions_js.php b/src/snippets/global_helper_functions_js.php new file mode 100644 index 0000000..148c48e --- /dev/null +++ b/src/snippets/global_helper_functions_js.php @@ -0,0 +1,209 @@ +?> + + + + + + array( + 'price' => 2250, + 'day_end' => 7, + 'color' => '#f8dd4d', + ), + 2 => array( + 'price' => 1800, + 'day_end' => 14, + 'color' => 'hotpink', + ), + 3 => array( + 'price' => 1100, + 'day_end' => 21, + 'color' => '#fd9f02', + ), + 4 => array( + 'price' => 500, + 'day_end' => 35, + 'color' => '#87cefa', + ), + ); + + $form_id = $form_data[ 'form_id' ]; + $form_settings = $form_data[ 'settings' ]; + $form_title = $form_data[ 'settings' ][ 'title' ]; + $form_fields = $form_data[ 'fields' ]; + + foreach( $form_fields as $field ){ + $field_id = $field[ 'id' ]; + $field_key = $field[ 'key' ]; + $field_value = $field[ 'value' ]; + + if( 'ich_brauche_einen_termin_1579378475182' == $field[ 'key' ] ) { + if( $field_value == 'sofort' ) { + $switch_termintype = 'sofort'; + } + else if ( $field_value == 'zeitraum' ) { + $switch_termintype = 'zeitraum'; + } + } + else if( 'wochentag_start_text' == $field[ 'key' ] ) { + $wochentag_start_text = $field_value; + } + + } + call_user_func('dump_to_file_local', '/var/www/lab/newfile.txt', 'switch_termintype: ' . $switch_termintype); + + if ( $switch_termintype == 'sofort' ) { + [$bool, $user_balance, $price, $is_premium] = subtract_fastcoins_by_start_date_local( $fastsnipeObj, 'sofort' ); + } + else if ( $switch_termintype == 'zeitraum' ) { + call_user_func('dump_to_file_local', '/var/www/lab/newfile.txt', 'wochentag_start_text: ' . $wochentag_start_text); + [$bool, $user_balance, $price, $is_premium] = subtract_fastcoins_by_start_date_local( $fastsnipeObj, 'zeitraum', $wochentag_start_text ); + } +} + +function subtract_fastcoins_by_start_date_local( $fastsnipeObj, $termintype_switch, $wochentag_start_text = null ) { + [$bool, $user_balance, $price, $is_premium] = check_premium_local( $fastsnipeObj, $termintype_switch, $wochentag_start_text ); + + if ( $bool ) { + call_user_func('dump_to_file_local', '/var/www/lab/newfile.txt', 'transfer legit. subtracting amount...'); + $user_id = get_current_user_id(); + mycred_subtract( 'fastsnipe', $user_id, $price, 'Forms booking completed' ); + call_user_func('dump_to_file_local', '/var/www/lab/newfile.txt', 'subtracted ' . $price . ' from ' . $user_balance); + } + else if ( $bool === 0 ) { + call_user_func('dump_to_file_local', '/var/www/lab/newfile.txt', 'not enough coins for transfer'); + } + else if ( $bool === null ) { + call_user_func('dump_to_file_local', '/var/www/lab/newfile.txt', 'no premium day'); + } + + return $rArr; +} + +function DateDiffFromNow_local($d2) { + $d1 = new DateTime(); + $d2 = new DateTime($d2); + $dDiff = $d1->diff($d2); + return $dDiff->format('%r%a'); +} + +function check_premium_local( $fastsnipeObj, $fswitch, $wochentag_start_text ) { + $user_id = get_current_user_id(); + $user_balance = mycred_get_users_balance( $user_id ); + call_user_func('dump_to_file_local', '/var/www/lab/newfile.txt', 'Balance: ' . $user_balance); + + if ( $fswitch == 'zeitraum' ) { + $i = DateDiffFromNow_local($wochentag_start_text); + } + else if ( $fswitch == 'sofort' ) { + $i = 0; + } + call_user_func('dump_to_file_local', '/var/www/lab/newfile.txt', 'i: ' . $i); + + if( $price = get_premium_price_local($fastsnipeObj, $i) ) { + $is_premium = 1; + call_user_func('dump_to_file_local', '/var/www/lab/newfile.txt', 'price: ' . $price); + if ( can_afford_local($user_balance, $price) ) { + $bool = 1; + } + else { + $bool = 0; + } + } + else { + $is_premium = 0; + $bool = null; + } + + return array($bool, $user_balance, $price, $is_premium); +} + +function can_afford_local($user_balance, $price) { + $can_afford = 0; + $diff = $user_balance-$price; + call_user_func('dump_to_file_local', '/var/www/lab/newfile.txt', 'price diff: ' . $diff); + if( $diff >= 0 ) { + $can_afford = 1; + } + + return $can_afford; +} + +function get_premium_price_local($fastsnipeObj, $i) { + $price = 0; + foreach ($fastsnipeObj as $key => $value) { + $day_end = $fastsnipeObj[$key]['day_end'] - 2; + if ($i <= $day_end) { + $price = $fastsnipeObj[$key]['price']; + break; + } + } + return $price; +} + +function dump_to_file_local($file, $data, $method = '') { + if ($method == 'clear') { + $f = @fopen($file, "r+"); + if ($f !== false) { + ftruncate($f, 0); + fclose($f); + } + + $timestamp = "\n[" . date('m/d/Y h:i:sa', time()) . "]\n"; + file_put_contents($file, $timestamp, FILE_APPEND | LOCK_EX); + } + + if (is_array($data) || is_object($data)) { + $data = print_r($data, true); + } + + file_put_contents($file, $data.PHP_EOL , FILE_APPEND | LOCK_EX); +} \ No newline at end of file diff --git a/src/snippets/inactivity_refresh.php b/src/snippets/inactivity_refresh.php new file mode 100644 index 0000000..1a5f462 --- /dev/null +++ b/src/snippets/inactivity_refresh.php @@ -0,0 +1,31 @@ +?> + 0 ) { + ?> + + + + + +ID, 'user_login_count', true ); + $user_login_count++; + update_user_meta( $user->ID, 'user_login_count', $user_login_count ); +} + +add_action('clear_auth_cookie', 'my_wp_logout', 10); +function my_wp_logout() { + $user_id = get_current_user_id(); + $user_login_count = get_user_meta( $user_id, 'user_login_count', true ); + if ( $user_login_count == 1 ) { + redirect('http://zinomedia.de/terminsnipe/?ty=1'); + } +} \ No newline at end of file diff --git a/src/snippets/menu_indicator_appointment_check.php b/src/snippets/menu_indicator_appointment_check.php new file mode 100644 index 0000000..498577f --- /dev/null +++ b/src/snippets/menu_indicator_appointment_check.php @@ -0,0 +1,99 @@ +?> + 984, + 'expired' => 983, + 'appointment' => 1812, + ); + + $user = wp_get_current_user(); + $rows = db_count_snipes($user); + + // APPOINTMENTS_OLD TO COMPARE + $appointments_old = get_user_meta( $user->ID, 'appointments_old', true ); + php_console_log('appointments_old: ' . $appointments_old); + + foreach ($menu_mapping as $category => $menu_id) { + $indicator = $rows[0][$category]; + + // NEW APPOINTMENT MODAL CHECK + if ($category === 'appointment') { + // NEW APPOINTMENT? + if ($indicator > $appointments_old) { + php_console_log('We have a new appointment'); + + // SAVE NUMBER OF APPOINTMENTS + update_user_meta( $user->ID, 'appointments_old', $indicator ); + + // NEW APPOINTMENT MODAL + redirect('http://zinomedia.de/terminsnipe/?fa=1'); + } + else { + php_console_log('No new appointment'); + + // SAVE NUMBER OF APPOINTMENTS + update_user_meta( $user->ID, 'appointments_old', $indicator ); + } + } + + append_indicator($menu_id, $indicator); + } + } +} + +function db_count_snipes($user) { + $wpdb = connect_to_server('zinomedia'); + $rows = $wpdb->get_results( " + SELECT + ( + SELECT + COUNT(*) + FROM + reg_users + INNER JOIN request ON request.USER_ID = reg_users.ID + WHERE + reg_users.WP_ID = $user->ID AND + request.EXPIRED = 0 + ) AS requests, + ( + SELECT + COUNT(*) + FROM + reg_users + INNER JOIN request ON request.USER_ID = reg_users.ID + WHERE + reg_users.WP_ID = $user->ID AND + request.EXPIRED = 1 + ) AS expired, + ( + SELECT + COUNT(*) + FROM + reg_users + INNER JOIN appointments ON appointments.USER_ID = reg_users.ID + WHERE + reg_users.WP_ID = $user->ID + ) AS appointment + ", ARRAY_A ); + return $rows; +} + +function append_indicator($menu_id, $indicator) { + ?> + + + + [mepr-logout-link class="mp-login-logout"] + '; + + if( strpos($items, '
  • + + +
  • '; + + $items = $avatar . $items;$login_logout; + } + } + else if( strpos($items, '