%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/casasmonvl/newges4t/wp-content/plugins/chaty/frontend/
Upload File :
Create Path :
Current File : /home/casasmonvl/newges4t/wp-content/plugins/chaty/frontend/class-frontend.php

<?php

namespace CHT\frontend;

use CHT\admin\CHT_Admin_Base;
use CHT\admin\CHT_Social_Icons;

$admin_base = CHT_ADMIN_INC . '/class-admin-base.php';
require_once($admin_base);

$social_icons = CHT_ADMIN_INC . '/class-social-icons.php';
require_once($social_icons);

class CHT_Frontend extends CHT_Admin_Base
{
    /**
     * CHT_Frontend constructor.
     */
    public function __construct()
    {
        $this->socials = CHT_Social_Icons::get_instance()->get_icons_list();
        if (wp_doing_ajax()) {
            add_action('wp_ajax_choose_social', array($this, 'choose_social_handler'));
            add_action('wp_ajax_add_token', array($this, 'add_token'));
            add_action('wp_ajax_del_token', array($this, 'del_token'));
        }
        add_action('wp_head', array($this, 'insert_widget'));

        add_action('wp_ajax_chaty_check_for_mobile', array($this, 'chaty_check_for_mobile'));                             // initialize widget in footer
        add_action('wp_ajax_nopriv_chaty_check_for_mobile', array($this, 'chaty_check_for_mobile'));

        add_action('wp_ajax_nopriv_chaty_update_counter', array($this, 'chaty_update_counter'));
        add_action('wp_ajax_chaty_update_counter', array($this, 'chaty_update_counter'));
    }

    public function chaty_update_counter() {
        $current_count = get_option("chaty_total_channel_click");
        if($current_count === false || empty($current_count)) {
            $current_count = 1;
            add_option("chaty_total_channel_click", $current_count);
        } else {
            $current_count = intval($current_count);
            $current_count++;
            update_option("chaty_total_channel_click", $current_count);
        }
        echo "true";
        die;
    }

    public function chaty_check_for_mobile() {
        if(wp_is_mobile()) {
            echo "yes";
        } else {
            echo "no";
        }
        wp_die();
    }

    /**
     * Function add token
     */
    public function add_token()
    {
        check_ajax_referer('cht_nonce_ajax', 'nonce_code');
        $token = filter_input(INPUT_POST, 'token', FILTER_SANITIZE_STRING);

        if ($token !== null) {
            if ($this->is_pro($token)) {
                update_option('cht_license_key', $token, 'no');
                esc_html_e('true');
                wp_die();
            }
        }
        esc_html_e('');
        wp_die();
    }

    /**
     * Function add token
     */
    public function del_token()
    {
        check_ajax_referer('cht_nonce_ajax', 'nonce_code');
        if (!$this->is_pro()) {
            update_option('cht_license_key', '', '');
        }
        esc_html_e('');
        wp_die();
    }

    /**
     *
     */
    public function choose_social_handler()
    {
        check_ajax_referer('cht_nonce_ajax', 'nonce_code');
        $social = filter_input(INPUT_POST, 'social', FILTER_SANITIZE_STRING);

        if (!is_null($social) && !empty($social)) {
            foreach ($this->socials as $item) {
                if ($item['slug'] == $social) {
                    break;
                }
            }
            if (!$item) {
                return;
            }
            $social_opt = get_option('cht_social_' . $social);
            if (empty($social_opt)) {
                $social_opt = [
                    'value' => '',
                    'is_mobile' => 'checked',
                    'is_desktop' => 'checked'
                ];
            }

            $social_opt['is_desktop'] = isset($social_opt['is_desktop']) ? $social_opt['is_desktop'] : '';
            $social_opt['is_mobile'] = isset($social_opt['is_mobile']) ? $social_opt['is_mobile'] : '';

            $social_opt['title'] = $item['title'];
            ob_start();
            $status = 0;
            $is_pro = $this->is_pro();
            $class_name = $is_pro?"pro":"free";
            ?>
            <li data-id="<?php echo esc_attr($item['slug']) ?>" id="chaty-social-<?php echo esc_attr($item['slug']) ?>">
                <div class="channels-selected__item <?php esc_attr_e(($status)?"img-active":"") ?> <?php esc_attr_e($class_name) ?> 1 available">
                    <div class="chaty-default-settings">
                        <div class="move-icon">
                            <?php $image_url = plugin_dir_url("")."/chaty/assets/images/move-icon.png"; ?>
                            <img src="<?php echo esc_url($image_url) ?>" />
                        </div>
                        <div class="icon icon-md active" data-title="<?php esc_attr_e($item['title']); ?>">
                                <span class="default-chaty-icon custom-icon-<?php echo esc_attr($item['slug']) ?> default_image_<?php echo esc_attr($item['slug']) ?>" >
                                    <svg width="39" height="39" viewBox="0 0 39 39" fill="none" xmlns="http://www.w3.org/2000/svg">
                                        <?php echo $item['svg']; ?>
                                    </svg>
                                </span>
                        </div>
                        <div class="channels__input-box">
                            <input type="text"
                                   class="channels__input"
                                   name="cht_social_<?php echo esc_attr($item['slug']); ?>[value]"
                                   value="<?php esc_attr_e($social_opt['value']); ?>"
                                   data-gramm_editor="false"
                                   id="<?php echo esc_attr($item['slug']); ?>"
                                >
                        </div>
                        <div>
                            <?php
                            $channel_id = $this->del_space($item['slug']);
                            $channel_id = str_replace(' ', '_', $channel_id);
                            $channel_slug = strtolower($channel_id);
                            ?>
                            <label class="channels__view" for="<?php echo esc_attr($channel_id); ?>Desktop">
                                <input type="checkbox" id="<?php echo esc_attr($channel_id); ?>Desktop" class="channels__view-check js-chanel-icon js-chanel-desktop" data-type="<?php echo esc_attr($item['title']); ?>"
                                       name="cht_social_<?php echo esc_attr($item['slug']); ?>[is_desktop]" value="checked" data-gramm_editor="false" <?php esc_attr_e($social_opt['is_desktop']) ?> >
                                <span class="channels__view-txt">Desktop</label>
                            </label>
                            <label class="channels__view"
                                   for="<?php echo esc_attr($channel_id); ?>Mobile">
                                <input type="checkbox" id="<?php echo esc_attr($channel_id); ?>Mobile" class="channels__view-check js-chanel-icon js-chanel-mobile"
                                       data-type="<?php echo esc_attr($item['title']); ?>" name="cht_social_<?php echo esc_attr($item['slug']); ?>[is_mobile]" value="checked" data-gramm_editor="false" <?php esc_attr_e($social_opt['is_mobile']) ?> >
                                <span class="channels__view-txt">Mobile</span>
                            </label>
                        </div>
                        <div class="chaty-settings" onclick="toggle_chaty_setting('<?php echo esc_attr($item['slug']); ?>')">
                            <a href="javascript:;"><span class="dashicons dashicons-admin-generic"></span></a>
                        </div>
                        <div class="input-example">
                            <?php esc_attr_e('For example', CHT_OPT); ?>: <?php esc_attr_e($item['example']); ?>
                        </div>
                        <!-- checking for extra help message for social media -->
                        <?php if((isset($item['help']) && !empty($item['help'])) || isset($item['help_link'])) { ?>
                            <div class="viber-help">
                                <?php if(isset($item['help_link'])) { ?>
                                    <?php $help_text = isset($item['help_title'])?$item['help_title']:"Doesn't work?"; ?>
                                    <a href="<?php echo esc_url($item['help_link']) ?>" target="_blank"><?php esc_attr_e($help_text); ?></a>
                                <?php } else { ?>
                                    <?php $help_title = isset($item['help_title'])?$item['help_title']:"Doesn't work?" ?>
                                    <span><?php echo $item['help']; ?></span>
                                    <?php esc_attr_e($help_title) ?>
                                <?php } ?>
                            </div>
                        <?php } ?>
                    </div>
                    <div class="chaty-advance-settings">
                        <div class="chaty-setting-col">
                            <label>Icon Appearance</label>
                            <div>
                                <input readonly type="text" name="" class="chaty-color-field" value="" style="background-color: <?php esc_attr_e($item['color']) ?>" />
                                <a href="javascript:;" class="upload-chaty-icon"><span class="dashicons dashicons-upload"></span> Custom Image</a>
                            </div>
                        </div>
                        <div class="clear clearfix"></div>
                        <div class="chaty-setting-col">
                            <label>On Hover Text</label>
                            <div>
                                <input readonly type="text" name="" value="<?php esc_attr_e($social_opt['title']) ?>">
                            </div>
                        </div>
                        <div class="clear clearfix"></div>
                        <?php if($item['slug'] == "Whatsapp") { ?>
                            <div class="clear clearfix"></div>
                            <div class="chaty-setting-col">
                                <label>Pre Set Message</label>
                                <div>
                                    <input id="cht_social_message_<?php echo esc_attr($item['slug']); ?>" type="text" name="" value="" >
                                </div>
                            </div>
                        <?php } else if($item['slug'] == "Email") { ?>
                            <div class="clear clearfix"></div>
                            <div class="chaty-setting-col">
                                <label>Mail Subject</label>
                                <div>
                                    <input id="cht_social_message_<?php echo esc_attr($item['slug']); ?>" type="text" name="" value="" >
                                </div>
                            </div>
                        <?php } else if($item['slug'] == "WeChat") { ?>
                            <div class="clear clearfix"></div>
                            <div class="chaty-setting-col">
                                <label>Upload QR Code</label>
                                <div>
                                    <a class="cht-upload-image " id="upload_qr_code" href="javascript:;" >
                                        <span class="dashicons dashicons-upload"></span>
                                    </a>
                                </div>
                            </div>
                        <?php } else if($item['slug'] == "Link" || $item['slug'] == "Custom_Link") { ?>
                            <div class="clear clearfix"></div>
                            <div class="chaty-setting-col">
                                <label >Open In a New Tab</label>
                                <div>
                                    <input type="hidden" name="cht_social_<?php echo esc_attr($item['slug']); ?>[new_window]" value="0" >
                                    <label class="channels__view" for="cht_social_window_<?php echo esc_attr($item['slug']); ?>">
                                        <input id="cht_social_window_<?php echo esc_attr($item['slug']); ?>" type="checkbox" class="channels__view-check" name="cht_social_<?php echo esc_attr($item['slug']); ?>[new_window]" value="1" checked >
                                        <span class="channels__view-txt">&nbsp;</span>
                                    </label>
                                </div>
                            </div>
                        <?php } else if($item['slug'] == "Linkedin") {
                            $is_checked = "personal";
                            ?>
                            <!-- Advance setting for Custom Link -->
                            <div class="clear clearfix"></div>
                            <div class="chaty-setting-col">
                                <label >LinkedIn</label>
                                <div>
                                    <label>
                                        <input type="radio" <?php checked($is_checked, "personal") ?> name="cht_social_<?php echo esc_attr($item['slug']); ?>[link_type]" value="personal">
                                        Personal
                                    </label>
                                    <label>
                                        <input type="radio" <?php checked($is_checked, "company") ?> name="cht_social_<?php echo esc_attr($item['slug']); ?>[link_type]" value="company">
                                        Company
                                    </label>
                                </div>
                            </div>
                        <?php } ?>
                        <div class="chaty-pro-feature">
                            <a target="_blank" href="<?php echo esc_url($this->getUpgradeMenuItemUrl());?>">
                                <?php esc_attr_e('Upgrade to Pro', CHT_OPT);?>
                            </a>
                        </div>
                    </div>
                    <button class="btn-cancel" data-social="<?php echo esc_attr($item['slug']); ?>">
                        <svg width="14" height="13" viewBox="0 0 14 13" fill="none"
                             xmlns="http://www.w3.org/2000/svg">
                            <rect width="15.6301" height="2.24494" rx="1.12247"
                                  transform="translate(2.26764 0.0615997) rotate(45)" fill="white"/>
                            <rect width="15.6301" height="2.24494" rx="1.12247"
                                  transform="translate(13.3198 1.649) rotate(135)" fill="white"/>
                        </svg>
                    </button>
                </div>
            </li>
            <?php
            $html = ob_get_clean();
            echo json_encode($html);
        }
        wp_die();
    }

    public function int_arr()
    {
        $social = get_option('cht_numb_slug');
        $social = explode(",", $social);

        $arr = array();
        $output = array();
        foreach ($social as $key_soc):
            foreach ($this->socials as $social) :
                if ($social['slug'] != $key_soc) {
                    continue;
                }
                if ($value = get_option('cht_social_' . $social['slug'])) {
                    if ($value) {
                        $desktop_target = "";
                        $mobile_target = "";
                        $arr[strtolower($social['slug'])] = $value['value'];
                        if($social['slug'] == "Viber") {
                            $val = $value['value'];
                            $fc = substr($val, 0, 1);
                            if ($fc == "+") {
                                $length = -1 * (strlen($val) - 1);
                                $val = substr($val, $length);
                            }
                            if (!wp_is_mobile()) {
                                $val = "+" . $val;
                            }
                            $arr[strtolower($social['slug'])] = $val;
                        } else if($social['slug'] == "Whatsapp") {
                            $val = $value['value'];
                            $val = str_replace("+","", $val);
                            $arr[strtolower($social['slug'])] = $val;
                            if(wp_is_mobile()) {
                                $mobile_target = "";
                            } else {
                                $desktop_target = "_blank";
                            }
                        } else if($social['slug'] == "Facebook_Messenger") {
                            $val = $value['value'];
                            $val = str_replace("facebook.com","m.me", $val);
                            $val = str_replace("www.","", $val);
                            $val = esc_url($val);
                            $val = str_replace("http:", "https:", $val);
                            $value['value'] = $val;
                            $arr[strtolower($social['slug'])] = $value['value'];

                            $val = trim($val, "/");
                            $val_array = explode("/", $val);
                            $total = count($val_array)-1;
                            $last_value = $val_array[$total];
                            $last_value = explode("-", $last_value);
                            $total_text = count($last_value)-1;
                            $total_text = $last_value[$total_text];

                            if(is_numeric($total_text)) {
                                $val_array[$total] = $total_text;
                                $val = implode("/", $val_array);
                                $value['value'] = $val;
                            }
                        } else if($social['slug'] == "Link" || $social['slug'] == "Custom_Link") {
                            echo $is_exist = strpos($value['value'], "javascript");
                            if(strpos($value['value'], "javascript") === false) {
                                $value['value'] = esc_url($value['value']);
                            }
                            $arr[strtolower($social['slug'])] = $value['value'];
                        }
                        $value['value'] = $value['value'];

                        $slug = strtolower($social['slug']);
                        if(in_array($slug, array("telegram", "line", "link", "custom_link", "google_maps", "waze", "poptin", "snapchat", "vkontakte", "twitter", "instagram", "linkedin", "facebook_messenger", "whatsapp"))) {
                            $desktop_target = "_blank";
                            $mobile_target = "_blank";
                        }

                        if(in_array($social['slug'], array("facebook_messenger", "whatsapp")) && wp_is_mobile()) {
                            $mobile_target = "";
                        }

                        $is_mobile = isset($value['is_mobile']) ? "is-in-mobile" : 0;
                        $is_desktop = isset($value['is_desktop']) ? "is-in-desktop" : 0;

                        if(!empty($value['value'])) {
                            $data = array(
                                "value" => $value['value'],
                                "is_mobile" => $is_mobile,
                                "is_desktop" => $is_desktop,
                                "desktop_target" => $desktop_target,
                                "mobile_target" => $mobile_target,
                            );
                            $output[strtolower($social['slug'])] = $data;
                        }
                    }
                };
            endforeach;
        endforeach;
//        echo "<pre>"; print_r($output); die;
        return $output;
    }

    public function insert_widget()
    {
        if ($this->canInsertWidget()):
            include_once CHT_DIR . '/views/widget.php';
        endif;
    }

    private function canInsertWidget()
    {
        return get_option('cht_active') && $this->checkChannels();
    }

    private function checkChannels()
    {
        $social = explode(",", get_option('cht_numb_slug'));
        $res = false;
        foreach ($social as $name) {
            $value = get_option('cht_social_' . strtolower($name));
            $res = $res || !empty($value['value']);
        }
        return $res;
    }
}

return new CHT_Frontend();

Zerion Mini Shell 1.0