public function widget($args, $instance) { $this->instance = $instance; $register = hocwp_get_value_by_key($instance, 'register', hocwp_get_value_by_key($this->args, 'register')); $button_text = hocwp_get_value_by_key($instance, 'button_text', hocwp_get_value_by_key($this->args, 'button_text')); $captcha = (bool) hocwp_get_value_by_key($instance, 'captcha', hocwp_get_value_by_key($this->args, 'captcha')); if ($captcha) { add_filter('hocwp_use_session', '__return_true'); } $description = hocwp_get_value_by_key($instance, 'description', hocwp_get_value_by_key($this->args, 'description')); $desc_position = hocwp_get_value_by_key($instance, 'desc_position', hocwp_get_value_by_key($this->args, 'desc_position')); $fields = $this->get_value_fields($instance); $all_fields = explode(',', $fields); hocwp_widget_before($args, $instance); ob_start(); ?> <form class="subscribe-form hocwp-subscribe-form" method="post" data-captcha="<?php echo hocwp_bool_to_int($captcha); ?> " data-register="<?php echo hocwp_bool_to_int($register); ?> "> <?php echo '<div class="messages"></div>'; if (!empty($description) && 'before' == $desc_position) { echo '<p class="description">' . $description . '</p>'; } foreach ($all_fields as $field_name) { $field = hocwp_get_value_by_key($this->args['fields'], $field_name); if (hocwp_array_has_value($field)) { $label = $this->get_value_field($instance, $field_name, 'label'); $placeholder = $this->get_value_field($instance, $field_name, 'placeholder'); $required = $this->get_value_field($instance, $field_name, 'required'); $class = hocwp_sanitize_html_class($field_name); $field_args = array('id' => $this->get_field_id('subscribe_' . $field_name), 'name' => $this->get_field_name('subscribe_' . $field_name), 'value' => '', 'label' => $label, 'placeholder' => $placeholder, 'required' => $required, 'class' => 'form-control input-' . $class, 'before' => '<div class="form-group field-' . $class . '">', 'after' => '</div>'); hocwp_field_input($field_args); } } if (!empty($description) && 'after' == $desc_position) { echo '<p class="description">' . $description . '</p>'; } if ($captcha) { $captcha_label = hocwp_get_value_by_key($instance, 'captcha_label', hocwp_get_value_by_key($this->args, 'captcha_label')); $captcha_placeholder = hocwp_get_value_by_key($instance, 'captcha_placeholder', hocwp_get_value_by_key($this->args, 'captcha_placeholder')); $field_args = array('id' => $this->get_field_id('captcha'), 'name' => $this->get_field_name('captcha'), 'input_width' => '100%', 'class' => 'form-control', 'label' => $captcha_label, 'placeholder' => $captcha_placeholder, 'before' => '<div class="form-group field-captcha">', 'after' => '</div>'); hocwp_field_captcha($field_args); } $field_args = array('type' => 'submit', 'name' => 'submit', 'value' => $button_text, 'class' => 'form-control', 'before' => '<div class="form-group field-submit">', 'after' => '</div>'); hocwp_field_input($field_args); hocwp_loading_image(array('name' => 'icon-loading-long.gif')); ?> </form> <?php $widget_html = ob_get_clean(); $widget_html = apply_filters('hocwp_widget_subscribe_html', $widget_html, $args, $instance, $this); echo $widget_html; hocwp_widget_after($args, $instance); }
function hocwp_facebook_login_script($args = array()) { $connect = hocwp_get_value_by_key($args, 'connect'); if (is_user_logged_in() && !$connect) { return; } $lang = hocwp_get_language(); $language = hocwp_get_value_by_key($args, 'language'); if (empty($language) && 'vi' === $lang) { $language = 'vi_VN'; } $app_id = hocwp_get_wpseo_social_facebook_app_id(); if (empty($app_id)) { hocwp_debug_log(__('Please set your Facebook APP ID first.', 'hocwp-theme')); return; } ?> <script type="text/javascript"> window.hocwp = window.hocwp || {}; function hocwp_facebook_login_status_callback(response) { if (response.status === 'connected') { hocwp_facebook_login_connected_callback(); } else if (response.status === 'not_authorized') { } else { } } function hocwp_facebook_login() { FB.login(function (response) { hocwp_facebook_login_status_callback(response); }, {scope: 'email,public_profile,user_friends'}); } window.fbAsyncInit = function () { FB.init({ appId: '<?php echo $app_id; ?> ', cookie: true, xfbml: true, version: 'v<?php echo HOCWP_FACEBOOK_GRAPH_API_VERSION; ?> ' }); }; if (typeof FB === 'undefined') { (function (d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/<?php echo $language; ?> /sdk.js"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); } function hocwp_facebook_login_connected_callback() { FB.api('/me', {fields: 'id,name,first_name,last_name,picture,verified,email'}, function (response) { (function ($) { $.ajax({ type: 'POST', dataType: 'json', url: hocwp.ajax_url, cache: true, data: { action: 'hocwp_social_login_facebook', data: JSON.stringify(response), connect: <?php echo hocwp_bool_to_int($connect); ?> }, success: function (response) { var href = window.location.href; if ($.trim(response.redirect_to)) { href = response.redirect_to; } if (response.logged_in) { window.location.href = href; } } }); })(jQuery); }); } </script> <?php }
function hocwp_default_script_localize_object() { $datepicker_icon = apply_filters('hocwp_datepicker_icon', HOCWP_URL . '/images/icon-datepicker-calendar.gif'); $shortcodes = hocwp_get_all_shortcodes(); $args = array('ajax_url' => admin_url('admin-ajax.php'), 'security' => wp_create_nonce('hocwp_nonce'), 'datepicker_icon' => $datepicker_icon, 'shortcodes' => $shortcodes, 'logged_in' => hocwp_bool_to_int(is_user_logged_in()), 'i18n' => array('jquery_undefined_error' => __('HocWP\'s JavaScript requires jQuery', 'hocwp-theme'), 'jquery_version_error' => sprintf(__('HocWP\'s JavaScript requires jQuery version %s or higher', 'hocwp-theme'), HOCWP_MINIMUM_JQUERY_VERSION), 'insert_media_title' => __('Insert media', 'hocwp-theme'), 'insert_media_button_text' => __('Use this media', 'hocwp-theme'), 'insert_media_button_texts' => __('Use these medias', 'hocwp-theme'), 'confirm_message' => __('Are you sure?', 'hocwp-theme'), 'disconnect_confirm_message' => __('Are you sure you want to disconnect?', 'hocwp-theme'), 'delete_confirm_message' => __('Are you sure you want to delete this?', 'hocwp-theme'), 'processing_text' => __('Processing...', 'hocwp-theme'), 'max_file_item_select_error' => __('You can not select more than %s files.', 'hocwp-theme')), 'ajax_loading' => '<p class="ajax-wrap"><img class="ajax-loading" src="' . hocwp_get_image_url('icon-loading-circle-light-full.gif') . '" alt=""></p>'); return apply_filters('hocwp_default_script_object', $args); }
function hocwp_field_google_maps($args = array()) { hocwp_field_sanitize_args($args); $lat_lng = hocwp_get_default_lat_long(); $id = hocwp_get_value_by_key($args, 'id', 'maps_content'); if (empty($id)) { $id = 'maps_content'; } $address = hocwp_get_value_by_key($args, 'address'); $long = hocwp_get_value_by_key($args, 'long'); $lat = hocwp_get_value_by_key($args, 'lat'); $lang = hocwp_get_language(); $zoom = hocwp_get_value_by_key($args, 'zoom', 15); $google_maps = hocwp_get_value_by_key($args, 'google_maps'); if (empty($long) || empty($lat)) { $lat = $lat_lng['lat']; $long = $lat_lng['lng']; $zoom = 5; } if (empty($google_maps)) { $google_maps = json_encode(array('lat' => $lat, 'lng' => $long)); } $draggable = hocwp_get_value_by_key($args, 'draggable', false); $marker_title = hocwp_get_value_by_key($args, 'marker_title'); $post_id = hocwp_get_value_by_key($args, 'post_id'); $scrollwheel = hocwp_get_value_by_key($args, 'scrollwheel', false); if (empty($marker_title)) { $marker_title = __('Drag to find address!', 'hocwp-theme'); } hocwp_field_before($args); ?> <div id="<?php echo $id; ?> " class="hocwp-field-maps" data-scrollwheel="<?php echo hocwp_bool_to_int($scrollwheel); ?> " data-post-id="<?php echo $post_id; ?> " data-zoom="<?php echo $zoom; ?> " data-marker-title="<?php echo $marker_title; ?> " data-draggable="<?php echo hocwp_bool_to_int($draggable); ?> " data-address="<?php echo $address; ?> " data-long="<?php echo $long; ?> " data-lat="<?php echo $lat; ?> " style="width: 100%; height: 350px; position: relative; background-color: rgb(229, 227, 223); overflow: hidden;"></div> <?php hocwp_field_input_hidden(array('id' => 'google_maps', 'label' => '', 'field_callback' => 'hocwp_field_input_hidden', 'value' => $google_maps)); hocwp_field_after($args); }