Current File : /home/bqrcodec/contact.ucceurope.co/wp-content/plugins/proid-helpers//proid-helpers.php
<?php
/**
* Plugin Name: Proid Helpers
* Description: Proid Helpers
* Plugin URI: https://wordpress.org
* Author: WordPress
* Author URI: https://wordpress.org
* Version: 1.0.0
* License: GPL2
* Text Domain: proid-helpers
*/
function proid_generate_vcf_for_network( $post_id ) {
require_once trailingslashit( dirname(__FILE__) ) . 'vendor/autoload.php';
$vcard = new JeroenDesloovere\VCard\VCard();
$name = get_post_meta( $post_id, 'ho-ten-nw', true );
$email = get_post_meta( $post_id, 'email-nw', true );
$phone = get_post_meta( $post_id, 'so-dien-thoai-nw', true );
$website = get_post_meta( $post_id, 'website-nw', true );
$image = get_post_meta( $post_id, 'profile-nw', true );
$vcard->addName( $name, '', '', '', '' );
if ( ! empty( $email ) ) {
$vcard->addEmail( $email );
}
if ( ! empty( $phone ) ) {
$vcard->addPhoneNumber( $phone, 'WORK' );
}
if ( ! empty( $image ) ) {
$image = get_attached_file( $image['id'] );
$vcard->addPhoto( $image );
}
$vcf_location = trailingslashit( ABSPATH ) . 'wp-content/uploads/vcf-' . $post_id;
$vcard->setSavePath( $vcf_location );
$vcard->save();
update_post_meta( $post_id, '_vcf', $vcf_location );
return $vcf_location;
}
add_action( 'init', function() {
if ( isset( $_GET['download-vcf'] ) ) {
proid_generate_vcf_for_network( 9824 );
die();
}
} );
add_action( 'x_wp_insert_post', function( $post_id, $post, $update ) {
if ( $post->post_type !== 'my-network' ) {
return;
}
$email = get_post_meta( $post_id, 'nguoi-nhan-nw', true );
$vcf_file = proid_generate_vcf_for_network( $post_id );
$attachments = array(
$vcf_file
);
$subject = 'VCF ProID';
$headers = '';
$message = 'See attachment for VCard.';
if ( ! empty( $email ) ) {
wp_mail( $email, $subject, $message, $headers, $attachments );
}
}, 10, 3 );
add_action( 'elementor_pro/forms/new_record', function( $record, $handler ) {
if ( isset( $GLOBALS['___network_created_post_id'] ) ) {
$raw_fields = $record->get( 'fields' );
if ( isset( $raw_fields['field_b5025ea'] ) && ! empty( $raw_fields['field_b5025ea']['value'] ) ) {
$image = $raw_fields['field_b5025ea']['value'];
$image_id = attachment_url_to_postid( $image );
if ( $image && $image_id ) {
update_post_meta( $GLOBALS['___network_created_post_id'], 'profile-nw', array(
'id' => '' . $image_id,
'url' => $image
) );
} elseif( $image ) {
update_post_meta( $GLOBALS['___network_created_post_id'], 'profile-nw', array(
'id' => '' . 0,
'url' => $image
) );
}
}
}
}, 10, 2 );
add_action( 'elementor_pro/forms/form_submitted', function( $module ) {
if ( isset( $_POST['form_id'] ) && $_POST['form_id'] == '03f526f' && isset( $_POST['form_fields'] ) ) {
$form_fields = $_POST['form_fields'];
if ( ! isset( $form_fields['field_05ba870'] ) ) {
return;
}
$name = $form_fields['field_05ba870'];
$receiver_email = $form_fields['email1'];
$email = $form_fields['email_field_1'];
$phone = $form_fields['phone_field_1'];
$website = $form_fields['website1'];
$image = 0;
$proid_post_id = (int) $_POST['queried_id'];
if ( ! empty( $proid_post_id ) ) {
$skip_post = false;
$proid_post = get_post( $proid_post_id );
$author = $proid_post->post_author;
$author = get_user_by( 'id', $author );
if ( in_array( 'pro_id_premium_member', (array) $author->roles ) ) {
$skip_post = true;
}
if ( ! $skip_post ) {
$args = array(
'post_type' => 'my-network',
'post_title' => $name,
'post_status' => 'publish'
);
if ( filter_var( $receiver_email, FILTER_VALIDATE_EMAIL ) && email_exists( $receiver_email ) ) {
$network_author = get_user_by( 'email', $receiver_email );
$args['post_author'] = $network_author->ID;
}
$post_id = wp_insert_post( $args );
if ( ! is_wp_error( $post_id ) ) {
update_post_meta( $post_id, 'so-dien-thoai-nw', $phone );
update_post_meta( $post_id, 'email-nw', $email );
update_post_meta( $post_id, 'ho-ten-nw', $name );
update_post_meta( $post_id, 'website-nw', $website );
// update_post_meta( $post_id, 'profile-nw', $name ); // picture
$GLOBALS['___network_created_post_id'] = $post_id;
}
}
}
require_once trailingslashit( dirname(__FILE__) ) . 'vendor/autoload.php';
$vcard = new JeroenDesloovere\VCard\VCard();
$vcard->addName( $name, '', '', '', '' );
if ( ! empty( $email ) ) {
$vcard->addEmail( $email );
}
if ( ! empty( $phone ) ) {
$vcard->addPhoneNumber( $phone, 'WORK' );
}
if ( ! empty( $website ) ) {
if ( ! stristr($website, 'http') ) {
$website = 'https://' . $website;
}
$vcard->addURL( $website );
}
// var_dump( $_FILES );
// die();
if ( isset( $_FILES['form_fields'] ) && ! empty( $_FILES['form_fields'] ) && isset( $_FILES['form_fields']['tmp_name'] ) && ! empty( $_FILES['form_fields']['tmp_name'] ) ) {
$image = $_FILES['form_fields']['tmp_name'];
$image = array_shift($image);
// var_dump($image);
// $image = get_attached_file( $image['id'] );
if ( ! empty( $image ) ) {
$vcard->addPhoto( $image );
}
}
$vcf_location = trailingslashit( ABSPATH ) . 'wp-content/uploads/'; //vcf-' . sanitize_title( $name ) .'.vcf';
$file_name = sanitize_title( $name ) .'.vcf';
$vcard->setSavePath( $vcf_location );
$vcard->setFilename( $file_name );
$vcard->save();
$vcard_contents = $vcard->getOutput();
$vcf_location = $vcf_location . $file_name;
file_put_contents( $vcf_location, $vcard_contents );
// die('h');
$attachments = array(
$vcf_location
);
$subject = 'Bạn nhận được liên hệ mới từ [sender]';
$headers = '';
$message = 'Xin hãy tải liên hệ của [sender] về';
$sender_name = $name;
$subject = str_replace('[sender]', $sender_name, $subject);
$message = str_replace('[sender]', $sender_name, $message);
// $receiver_email = 'johndoe@example.com';
if ( ! empty( $receiver_email ) ) {
wp_mail( $receiver_email, $subject, $message, $headers, $attachments );
}
}
return $module;
}, 999 );
// Prevent video upload
function restrict_upload_types_in_media( $types ) {
$prevent = true;
if ( is_user_logged_in() ) {
$roles = array(
'administrator',
);
$user = wp_get_current_user();
$my_roles = (array) $user->roles;
foreach ( $roles as $role ) {
if ( in_array( $my_roles, $role ) ) {
$prevent = false;
break;
}
}
}
if ( $prevent ) {
foreach ( $types as $index => $type ) {
if ( stristr( $type, 'video' ) ) {
unset( $types[ $index ] );
}
}
}
return $types;
}
add_filter( 'upload_mimes', 'restrict_upload_types_in_media' );
/* Fix Gallery for Older Posts */
if ( isset( $_GET['fix-gallery'] ) ) {
add_action( 'init', function() {
global $wpdb;
$q = "SELECT post_id, meta_value FROM `wpca_postmeta`, wpca_posts WHERE meta_key='gallery' AND meta_value <> '' AND meta_value NOT LIKE 'a:%' AND ID=post_id AND post_type='my-pro-id'";
$items = $wpdb->get_results( $q );
foreach ( $items as $item ) {
$gallery = get_post_meta( $item->post_id, 'gallery', true );
$gallery_items = explode(',', $gallery );
$modified_items = array();
foreach ( $gallery_items as $index => $attach ) {
$modified_items[ 'item-' . $index ] = array(
'id' => $attach,
'url' => wp_get_attachment_image_url( $attach, 'full' ),
);
}
update_post_meta( $item->post_id, 'gallery', $modified_items );
// update_post_meta( $item->post_id, 'gallery_backup', $gallery );
}
} );
}
/* Fix Gallery for Older Posts */
if ( isset( $_GET['fix-qr-codes'] ) ) {
add_action( 'init', function() {
global $wpdb;
$q = "SELECT post_id, meta_value FROM `wpca_postmeta`, wpca_posts WHERE meta_key='bank-qr-1' AND meta_value <> '' AND meta_value NOT LIKE 'a:%' AND ID=post_id AND post_type='my-pro-id'";
$items = $wpdb->get_results( $q );
foreach ( $items as $item ) {
$gallery = get_post_meta( $item->post_id, 'bank-qr-1', true );
$gallery_items = explode(',', $gallery );
$modified_items = array();
$new_item = array();
foreach ( $gallery_items as $index => $attach ) {
$new_item = array(
'id' => $attach,
'url' => wp_get_attachment_image_url( $attach, 'full' ),
);
}
update_post_meta( $item->post_id, 'bank-qr-1', $new_item );
update_post_meta( $item->post_id, 'bank-qr-1-bk', $gallery );
}
} );
}