'DreamsWorld', 'mostra_titolo' => 1, 'titolo' => __( 'Chat online', 'amicachat-widget' ), 'pulsante' => __( 'Enter chat', 'amicachat-widget' ), 'larghezza' => 520, 'piena' => 0, 'allinea' => 'c', 'angoli' => 'r', 'ombra' => 1, 'bordo' => 0, 'bg' => '#ffffff', 'tx' => '#333333', 'c1' => '#da4e49', 'c2' => '#2384d1', 'bd' => '#dde1ea', 'nuova_scheda' => 1, 'credito' => 0, ); } function amicachat_widget_testo( $raw, $chiave, $max, $predefinito ) { $t = isset( $raw[ $chiave ] ) ? sanitize_text_field( (string) $raw[ $chiave ] ) : ''; $t = function_exists( 'mb_substr' ) ? mb_substr( $t, 0, $max ) : substr( $t, 0, $max ); return '' !== $t ? $t : $predefinito; } function amicachat_widget_sanitize( $raw ) { $d = amicachat_widget_defaults(); $raw = is_array( $raw ) ? $raw : array(); $o = array(); $canale = isset( $raw['canale'] ) ? (string) $raw['canale'] : ''; $canale = preg_replace( '/^#+/', '', trim( $canale ) ); $canale = substr( preg_replace( '/[^A-Za-z0-9_-]/', '', $canale ), 0, 31 ); $o['canale'] = '' !== $canale ? $canale : $d['canale']; $o['titolo'] = amicachat_widget_testo( $raw, 'titolo', 60, $d['titolo'] ); $o['pulsante'] = amicachat_widget_testo( $raw, 'pulsante', 30, $d['pulsante'] ); $w = isset( $raw['larghezza'] ) ? absint( $raw['larghezza'] ) : 0; $o['larghezza'] = $w ? min( 800, max( 240, $w ) ) : $d['larghezza']; foreach ( array( 'mostra_titolo', 'piena', 'ombra', 'bordo', 'nuova_scheda', 'credito' ) as $k ) { $o[ $k ] = empty( $raw[ $k ] ) ? 0 : 1; } $o['allinea'] = ( isset( $raw['allinea'] ) && in_array( $raw['allinea'], array( 'c', 'sx', 'dx' ), true ) ) ? $raw['allinea'] : $d['allinea']; $o['angoli'] = ( isset( $raw['angoli'] ) && in_array( $raw['angoli'], array( 'r', 'sq' ), true ) ) ? $raw['angoli'] : $d['angoli']; foreach ( array( 'bg', 'tx', 'c1', 'c2', 'bd' ) as $k ) { $c = isset( $raw[ $k ] ) ? sanitize_hex_color( (string) $raw[ $k ] ) : ''; $o[ $k ] = $c ? strtolower( $c ) : $d[ $k ]; } return $o; } function amicachat_widget_get_options() { $salvate = get_option( 'amicachat_widget_options', array() ); return amicachat_widget_sanitize( wp_parse_args( is_array( $salvate ) ? $salvate : array(), amicachat_widget_defaults() ) ); } function amicachat_widget_sino( $v ) { $v = trim( (string) $v ); $v = function_exists( 'mb_strtolower' ) ? mb_strtolower( $v ) : strtolower( $v ); if ( in_array( $v, array( 'si', 'sì', 'yes', '1', 'true' ), true ) ) { return 1; } if ( in_array( $v, array( 'no', '0', 'false' ), true ) ) { return 0; } return null; } function amicachat_widget_render( $o ) { wp_enqueue_style( 'amicachat-widget' ); $d = amicachat_widget_defaults(); $classi = array( 'acw' ); if ( 'sx' === $o['allinea'] || 'dx' === $o['allinea'] ) { $classi[] = 'acw-' . $o['allinea']; } if ( 'sq' === $o['angoli'] ) { $classi[] = 'acw-sq'; } if ( ! $o['ombra'] ) { $classi[] = 'acw-flat'; } if ( $o['bordo'] ) { $classi[] = 'acw-bd'; } $stili = array(); $mappa = array( 'bg' => '--acw-bg', 'tx' => '--acw-tx', 'c1' => '--acw-c1', 'c2' => '--acw-c2', ); foreach ( $mappa as $k => $variabile ) { if ( $o[ $k ] !== $d[ $k ] ) { $stili[] = $variabile . ':' . $o[ $k ]; } } if ( $o['bordo'] && $o['bd'] !== $d['bd'] ) { $stili[] = '--acw-bd:' . $o['bd']; } if ( $o['piena'] ) { $stili[] = 'max-width:none'; } elseif ( (int) $o['larghezza'] !== (int) $d['larghezza'] ) { $stili[] = 'max-width:' . (int) $o['larghezza'] . 'px'; } $link = '' . esc_html__( 'terms and privacy policy', 'amicachat-widget' ) . ''; $html = '
'; return $html; } function amicachat_widget_shortcode( $atts ) { $o = amicachat_widget_get_options(); $alias = array( 'canale' => 'room', 'titolo' => 'title', 'mostra_titolo' => 'show_title', 'pulsante' => 'button', 'larghezza' => 'width', 'allinea' => 'align', 'angoli' => 'corners', 'ombra' => 'shadow', 'bordo' => 'border', 'sfondo' => 'background', 'testo' => 'text', 'pulsante1' => 'button1', 'pulsante2' => 'button2', 'colore_bordo' => 'border_color', 'nuova_scheda' => 'new_tab', ); $vuoti = array(); foreach ( $alias as $it => $en ) { $vuoti[ $it ] = ''; $vuoti[ $en ] = ''; } $a = shortcode_atts( $vuoti, $atts, 'amicachat' ); foreach ( $alias as $it => $en ) { if ( '' === $a[ $it ] && '' !== $a[ $en ] ) { $a[ $it ] = $a[ $en ]; } } $diretti = array( 'canale' => 'canale', 'titolo' => 'titolo', 'pulsante' => 'pulsante', 'sfondo' => 'bg', 'testo' => 'tx', 'pulsante1' => 'c1', 'pulsante2' => 'c2', 'colore_bordo' => 'bd', ); foreach ( $diretti as $att => $k ) { if ( '' !== $a[ $att ] ) { $o[ $k ] = $a[ $att ]; } } foreach ( array( 'mostra_titolo', 'ombra', 'bordo', 'nuova_scheda' ) as $k ) { $s = amicachat_widget_sino( $a[ $k ] ); if ( null !== $s ) { $o[ $k ] = $s; } } $l = strtolower( trim( $a['larghezza'] ) ); if ( in_array( $l, array( '100%', 'piena', 'full' ), true ) ) { $o['piena'] = 1; } elseif ( '' !== $l && ctype_digit( rtrim( $l, 'px' ) ) ) { $o['piena'] = 0; $o['larghezza'] = (int) rtrim( $l, 'px' ); } $allinea = array( 'centro' => 'c', 'center' => 'c', 'sinistra' => 'sx', 'left' => 'sx', 'destra' => 'dx', 'right' => 'dx', ); $v = strtolower( trim( $a['allinea'] ) ); if ( isset( $allinea[ $v ] ) ) { $o['allinea'] = $allinea[ $v ]; } $angoli = array( 'arrotondati' => 'r', 'rounded' => 'r', 'squadrati' => 'sq', 'square' => 'sq', ); $v = strtolower( trim( $a['angoli'] ) ); if ( isset( $angoli[ $v ] ) ) { $o['angoli'] = $angoli[ $v ]; } return amicachat_widget_render( amicachat_widget_sanitize( $o ) ); } add_shortcode( 'amicachat', 'amicachat_widget_shortcode' ); function amicachat_widget_assets() { wp_register_style( 'amicachat-widget', AMICACHAT_WIDGET_URL . 'assets/widget-chat.css', array(), AMICACHAT_WIDGET_VERSION ); $post = get_post(); if ( is_active_widget( false, false, 'amicachat_widget', true ) || ( is_singular() && $post && has_shortcode( $post->post_content, 'amicachat' ) ) ) { wp_enqueue_style( 'amicachat-widget' ); } } add_action( 'wp_enqueue_scripts', 'amicachat_widget_assets' ); require_once AMICACHAT_WIDGET_DIR . 'includes/class-amicachat-widget.php'; if ( is_admin() ) { require_once AMICACHAT_WIDGET_DIR . 'includes/admin.php'; }