$stt,
'imgPoint' => $pins_image,
'top' => $point['top'],
'left' => $point['left'],
'linkpins' => isset($point['linkpins'])?esc_url($point['linkpins']):'',
'link_target' => isset($point['link_target'])?esc_attr($point['link_target']):'_self',
'pins_image_custom' => isset($point['pins_image_custom'])?$point['pins_image_custom']:'',
'pins_image_hover_custom' => isset($point['pins_image_hover_custom'])?$point['pins_image_hover_custom']:'',
'placement' => isset($point['placement'])?$point['placement']:'',
'pins_id' => isset($point['pins_id'])?$point['pins_id']:'',
'pins_class' => isset($point['pins_class'])?$point['pins_class']:'',
'pinsalt' => isset($point['pinsalt'])?$point['pinsalt']:''
);
echo devvn_ihotspot_get_pins_default($data_input); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
$stt,
'content' => $point['content'],
'left' => $point['left'],
'top' => $point['top'],
'linkpins' => isset($point['linkpins'])?esc_url($point['linkpins']):'',
'link_target' => isset($point['link_target'])?esc_attr($point['link_target']):'_self',
'pins_image_custom' => isset($point['pins_image_custom'])?$point['pins_image_custom']:'',
'pins_image_hover_custom' => isset($point['pins_image_hover_custom'])?$point['pins_image_hover_custom']:'',
'placement' => isset($point['placement'])?$point['placement']:'',
'pins_id' => isset($point['pins_id'])?$point['pins_id']:'',
'pins_class' => isset($point['pins_class'])?$point['pins_class']:'',
'pinsalt' => isset($point['pinsalt'])?$point['pinsalt']:''
);
echo devvn_ihotspot_get_input_point_default($data_input);//phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped?>
ID) == "publish"):
?>
$choose_type,
'custom_top' => $custom_top,
'custom_left' => $custom_left,
'custom_hover_top' => $custom_hover_top,
'custom_hover_left' => $custom_hover_left,
'pins_animation' => $pins_animation
);
if(is_array($pointdata)){
$dataPoints = devvn_ihotspot_convert_array_data($pointdata);
}
$data_post = array(
'maps_images' => $my_data,
'pins_image' => sanitize_text_field( (isset($_POST['pins_image']))?$_POST['pins_image']:'' ),
'pins_image_hover' => sanitize_text_field(isset($_POST['pins_image_hover'])?$_POST['pins_image_hover']:''),
'pins_more_option' => $pins_more_option,
'data_points' => $dataPoints
);
update_post_meta($post_id, 'hotspot_content', json_encode($data_post));
/*remove_action( 'save_post', 'devvn_ihotspot_save_meta_box_data' );
wp_update_post(array(
'ID' => $post_id,
'post_content' => maybe_serialize(wp_unslash($data_post)),
'post_type' => 'points_image'
));
add_action( 'save_post', 'devvn_ihotspot_save_meta_box_data' );*/
}
add_action( 'save_post', 'devvn_ihotspot_save_meta_box_data' );
function devvn_ihotspot_editor_styles(){
global $wp_version;
$baseurl = includes_url( 'js/tinymce' );
$suffix = SCRIPT_DEBUG ? '' : '.min';
$version = 'ver=' . $wp_version;
$dashicons = includes_url( "css/dashicons$suffix.css?$version" );
// WordPress default stylesheet and dashicons
$mce_css = array(
$dashicons,
$baseurl . '/skins/wordpress/wp-content.css?' . $version
);
$editor_styles = get_editor_stylesheets();
if ( ! empty( $editor_styles ) ) {
foreach ( $editor_styles as $style ) {
$mce_css[] = $style;
}
}
$mce_css = trim( apply_filters( 'devvn_ihotspot_mce_css', implode( ',', $mce_css ) ), ' ,' );
if ( ! empty($mce_css) )
return $mce_css;
else
return false;
}
/*Add admin script*/
function devvn_ihotspot_admin_script() {
global $typenow;
if( $typenow == 'points_image' ) {
wp_enqueue_media();
wp_enqueue_script( 'jquery-ui-core' );
wp_enqueue_script('jquery-ui-droppable');
wp_register_script( 'devvn-tinymce', home_url('/wp-includes/js/tinymce/wp-tinymce.js'), array(), DEVVN_IHOTSPOT_VER, true );
wp_register_script( 'maps_points', plugin_dir_url( __FILE__ ) . 'admin/js/maps_points.js', array( 'jquery', 'quicktags', 'devvn-tinymce', 'editor'), DEVVN_IHOTSPOT_VER, true );
wp_localize_script( 'maps_points', 'meta_image',
array(
'title' => __( 'Select image', 'devvn-image-hotspot' ),
'button' => __( 'Select', 'devvn-image-hotspot' ),
'site_url' => home_url(),
'ajaxurl' => admin_url('admin-ajax.php'),
'editor_style' => devvn_ihotspot_editor_styles()
)
);
wp_enqueue_script( 'maps_points' );
}
}
add_action( 'admin_enqueue_scripts','devvn_ihotspot_admin_script' );
/*Add admin style*/
function devvn_ihotspot_admin_styles(){
global $typenow;
if( $typenow == 'points_image' ) {
wp_enqueue_style( 'bootstrap', plugin_dir_url( __FILE__ ) . 'admin/css/bootstrap.css', array(), DEVVN_IHOTSPOT_VER, 'all' );
wp_enqueue_style( 'maps_points', plugin_dir_url( __FILE__ ) . 'admin/css/maps_points_style.css', array(),DEVVN_IHOTSPOT_VER, 'all' );
}
}
add_action( 'admin_print_styles', 'devvn_ihotspot_admin_styles' );
/*Add frontend scripts*/
function devvn_ihotspot_frontend_scripts() {
if(DEVVN_IHOTSPOT_DEV_MOD){
wp_enqueue_style('powertip',plugin_dir_url( __FILE__ ) . 'frontend/css/jquery.powertip.min.css',array(),'1.2.0','all');
wp_enqueue_script( 'powertip', plugin_dir_url( __FILE__ ) . 'frontend/js/jquery.powertip.min.js', array('jquery'), '1.2.0', true );
wp_enqueue_style('maps-points',plugin_dir_url( __FILE__ ) . 'frontend/css/maps_points.css',array(), DEVVN_IHOTSPOT_VER,'all');
wp_enqueue_script( 'maps-points', plugin_dir_url( __FILE__ ) . 'frontend/js/maps_points.js', array('jquery'), DEVVN_IHOTSPOT_VER, true );
}else{
wp_enqueue_style('ihotspot',plugin_dir_url( __FILE__ ) . 'frontend/css/ihotspot.min.css',array(),DEVVN_IHOTSPOT_VER,'all');
wp_enqueue_script( 'ihotspot-js', plugin_dir_url( __FILE__ ) . 'frontend/js/jquery.ihotspot.min.js', array('jquery'), DEVVN_IHOTSPOT_VER, true );
}
}
add_action( 'wp_enqueue_scripts', 'devvn_ihotspot_frontend_scripts' );
function devvn_ihotspot_get_input_point_default($data = array()){
if(!is_array($data)) $data = array();
$data = wp_parse_args($data, json_decode(DEVVN_IHOTSPOT_POINT_DEFAULT, true));
$countPoint = isset($data['countPoint'])?$data['countPoint']:'';
$pointContent = isset($data['content'])?$data['content']:'';
$pointLeft = isset($data['left'])?$data['left']:'';
$pointTop = isset($data['top'])?$data['top']:'';
$pointLink = isset($data['linkpins'])?$data['linkpins']:'';
$link_target = isset($data['link_target'])?$data['link_target']:'_self';
$pins_image_custom = isset($data['pins_image_custom'])?$data['pins_image_custom']:'';
$pins_image_hover_custom = isset($data['pins_image_hover_custom'])?$data['pins_image_hover_custom']:'';
$placement = isset($data['placement'])?$data['placement']:'';
$pins_id = isset($data['pins_id'])?$data['pins_id']:'';
$pins_class = isset($data['pins_class'])?$data['pins_class']:'';
$pinsalt = isset($data['pinsalt'])?$data['pinsalt']:'';
$pointContent = str_replace('\"', '"', $pointContent);
ob_start();
?>
$countPoint,
'imgPoint' => $imgPin
);
$data_input = array(
'countPoint' => $countPoint,
);
wp_send_json_success(array(
'point_pins' => devvn_ihotspot_get_pins_default($datapin),
'point_data' => devvn_ihotspot_get_input_point_default($data_input)
));
die();
}
/*
* by TanND
* https://gist.github.com/levantoan/2a66dafad7a9a3a88468170ecce0cdab
* */
function devvn_ihotspot_convert_array_data($inputArray = array()){
$aOutput = array();
$firstKey = null;
foreach ($inputArray as $key => $value){
$firstKey = $key;
break;
}
$nCountKey = count($inputArray[$firstKey]);
for ($i =0; $i<$nCountKey;$i++){
$element = array();
foreach ($inputArray as $key => $value){
//$element[$key] = base64_encode(wp_kses_post($value[$i]));
$allowed_tags = wp_kses_allowed_html( 'post' );
$allowed_tags['iframe'] = array(
'src' => array(),
'width' => array(),
'height' => array(),
'frameborder' => array(),
'scrolling' => array(),
'allowfullscreen' => array()
);
$element[$key] = base64_encode(wp_kses($value[$i], apply_filters('devvn_ihotspot_allowed_tags', $allowed_tags)));
}
array_push($aOutput,$element);
}
return $aOutput;
}
if(!function_exists('get_image_info_from_url')){
function get_image_info_from_url($image_url) {
global $wpdb;
$upload_dir = wp_upload_dir();
$relative_path = str_replace($upload_dir['baseurl'] . '/', '', $image_url);
$attachment_id = $wpdb->get_var( $wpdb->prepare( "
SELECT post_id FROM {$wpdb->postmeta}
WHERE meta_key = '_wp_attached_file'
AND meta_value = %s
LIMIT 1
", $relative_path ) );
if (!$attachment_id) return false;
$alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
$title = get_the_title($attachment_id);
$caption = wp_get_attachment_caption($attachment_id);
$desc = get_post_field('post_content', $attachment_id);
return [
'ID' => $attachment_id,
'alt' => $alt,
'title' => $title,
'caption' => $caption,
'desc' => $desc,
];
}
}