/var/www/html_us/wp-content/plugins/dream-team/admin/ajax-functions.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
add_action
'wp_ajax_dreamteam_get_update''dreamteam_ajax_get_update' );
function 
dreamteam_ajax_get_update() {
    
check_ajax_referer'dream-team''security' );
    
delete_transient('dreamteam_update_checker');
    
$checkData get_transient('dreamteam_update_checker');
    
wp_send_json(array(
        
'status' => 'success',
        
'body' => $checkData
    
));
}

function 
dreamteamCreateSlug($str$delimiter '-'){
    
$slug strtolower(trim(preg_replace('/[\s-]+/'$delimiterpreg_replace('/[^A-Za-z0-9-]+/'$delimiterpreg_replace('/[&]/''and'preg_replace('/[\']/'''iconv('UTF-8''ASCII//TRANSLIT'$str))))), $delimiter));
    return 
$slug;


function 
dreamteamGenerateLogo($text) {
    
$upload_dir   wp_upload_dir();
    if (empty( 
$upload_dir['basedir'] )) return false;

    
$plugin_dirname $upload_dir['basedir'] . '/dreamteam';
    if ( ! 
file_exists$plugin_dirname ) ) {
        
wp_mkdir_p$plugin_dirname );
    }
    
$logo_file $plugin_dirname '/logo-' dreamteamCreateSlug($text) . '.png';
    if (
file_exists($logo_file)) {
        return 
$upload_dir['baseurl'] . '/dreamteam/logo-' dreamteamCreateSlug($text) . '.png';
    }

    
$font_size 40// Font size is in pixels.
    
$rand rand(12);
    
$font_file DREAMTEAM_CORE_PLUGIN_PATH 'assets/css/logo-font-' $rand '.ttf'// This is the path to your font file.

    // Retrieve bounding box:
    
$type_space imagettfbbox($font_size0$font_file$text);

    
// Determine image width and height, 10 pixels are added for 5 pixels padding:
    
$image_width abs($type_space[4] - $type_space[0]) + 4;
    
$image_height abs($type_space[5] - $type_space[1]) + 10;

    
// Create image:
    
$image imagecreatetruecolor($image_width$image_height);

    
// Allocate text and background colors (RGB format):
    
$text_color imagecolorallocate($image247107106);
    
$bg_color imagecolorallocate($image255255255);

    
// Fill image:
    
imagefill($image00$bg_color);

    
// Fix starting x and y coordinates for the text:
    
$x 0// Padding of 5 pixels.
    
$y $image_height 12// So that the text is vertically centered.

    // Add TrueType text to image:
    
imagettftext($image$font_size0$x$y$text_color$font_file$text);

    
    
imagepng($image$logo_file);
    
$return $upload_dir['baseurl'] . '/dreamteam/logo-' dreamteamCreateSlug($text) . '.png';
    
    
// Destroy image in memory to free-up resources:
    
imagedestroy($image);

    return 
$return;
}


add_action'wp_ajax_dreamteam_sync_business_data''dreamteam_sync_business_data' );
add_action'wp_ajax_nopriv_dreamteam_sync_business_data''dreamteam_sync_business_data' );
function 
dreamteam_sync_business_data() {
    
$entityBody file_get_contents('php://input');
    
$request json_decode($entityBody);

    
$func = function($item) {
        return (array) 
$item;
    };
    
$dataPrepare array_map($func$request->data);

    foreach(
$dataPrepare as $i => $business) {
        
$text $business['brand'];
        
$logo_url dreamteamGenerateLogo($text);
        if (
$logo_url) {
            
$logo_url_obj parse_url($logo_url);
            
$logo_url_conpleted 'https://' $business['domain'] . $logo_url_obj['path'];
            
$dataPrepare[$i]['logo'] = $logo_url_conpleted;
            
$dataPrepare[$i]['logo_retina'] = $logo_url_conpleted;
        }
    }

    
$dreamteam_business_data update_option('dreamteam_business_data'$dataPrepare);
    
wp_send_json($dataPrepare);
}