'basic', 'buttonText' => 'Summarise with AI', 'qPrefix' => 'Read and summarise this', 'qSuffix' => 'so I can ask questions about it.', 'noun' => 'page', 'provider' => 'chatgpt', 'bgColor' => '', 'textColor' => '', 'borderColor' => '', 'borderRadius'=> 8, 'paddingX' => 10, 'paddingY' => 6, 'isFullWidth' => false, 'iconPosition'=> 'left', 'justify' => 'left', 'logoSize' => 15, 'maxWidth' => 200, 'maxHeight' => 32, 'preset' => 'chatgpt', 'openInNewTab'=> true, 'relNoFollow' => true, 'align' => '', ); $a = wp_parse_args( $attributes, $defaults ); $title = function_exists( 'wp_get_document_title' ) ? wp_get_document_title() : get_bloginfo( 'name' ); $url = home_url( '/' ); if ( function_exists( 'is_singular' ) && is_singular() ) { $t = get_the_title(); if ( $t ) $title = $t; $p = get_permalink(); if ( $p ) $url = $p; } $q = aisubu_build_q( $title, $url, array( 'qPrefix' => $a['qPrefix'], 'qSuffix' => $a['qSuffix'], 'noun' => $a['noun'] ) ); $bg = $a['bgColor']; $fg = $a['textColor']; $bd = $a['borderColor']; if ( $a['preset'] !== 'custom' && ( ! $bg && ! $fg && ! $bd ) ) { if ( $a['preset'] === 'chatgpt' ) { $bg = '#10A37F'; $fg = '#ffffff'; $bd = '#0D8667'; } elseif ( $a['preset'] === 'outline' ) { $bg = '#ffffff'; $fg = '#111827'; $bd = '#D1D5DB'; } elseif ( $a['preset'] === 'dark' ) { $bg = '#111827'; $fg = '#ffffff'; $bd = '#1F2937'; } elseif ( $a['preset'] === 'blue' ) { $bg = '#2563EB'; $fg = '#ffffff'; $bd = '#1E40AF'; } } if ( ! $bg ) $bg = '#10A37F'; if ( ! $fg ) $fg = '#ffffff'; if ( ! $bd ) $bd = 'rgba(0,0,0,.08)'; $rel = 'noopener'; if ( $a['relNoFollow'] ) $rel .= ' nofollow'; $target = $a['openInNewTab'] ? '_blank' : '_self'; $jc = 'flex-start'; $ta = 'left'; $auto = ''; if ( $a['justify'] === 'center' ) { $jc='center'; $ta='center'; $auto='margin-left:auto;margin-right:auto;'; } elseif ( $a['justify'] === 'right' ) { $jc='flex-end'; $ta='right'; $auto='margin-left:auto;'; } $wrap_style = 'width:100%;display:flex;align-items:center;gap:.5rem;margin:.5rem 0;justify-content:'.$jc.';text-align:'.$ta.';'; $btn_style = $auto.'display:inline-flex;align-items:center;gap:0;border:1px solid '.esc_attr($bd).';border-radius:'.intval($a['borderRadius']).'px;' . 'background:'.esc_attr($bg).';color:'.esc_attr($fg).';text-decoration:none;line-height:1;' . 'max-width:'.intval($a['maxWidth']).'px;height:'.intval($a['maxHeight']).'px;' . 'padding:'.intval($a['paddingY']).'px '.intval($a['paddingX']).'px;white-space:nowrap;overflow:hidden;'; if ( $a['isFullWidth'] ) $btn_style .= 'width:100%;justify-content:center;'; $icon_class = 'ai-summarise-logo' . ( $a['iconPosition'] === 'right' ? ' right' : '' ); $icon_html = ''; $label_html = ''; $inner = ( $a['iconPosition'] === 'right' ) ? ( $label_html.$icon_html ) : ( $icon_html.$label_html ); if ( $a['mode'] === 'basic' ) { $href = aisubu_provider_url( 'chatgpt', $q ); return '
'; } else { return ''; } } } if ( ! function_exists( 'aisubu_shortcode' ) ) { function aisubu_shortcode( $atts ) { $map = array( 'mode'=>'basic','text'=>'Summarise with AI','preset'=>'chatgpt','align'=>'left','width'=>'200','height'=>'32','logosize'=>'15', 'qprefix'=>'Read and summarise this','qsuffix'=>'so I can ask questions about it.','noun'=>'page', 'provider'=>'chatgpt','newtab'=>'1','nofollow'=>'1','bgcolor'=>'','textcolor'=>'','bordercolor'=>'' ); $atts = shortcode_atts( $map, $atts, 'aisubu_summarise_button' ); $attributes = array( 'mode' => $atts['mode'], 'buttonText' => $atts['text'], 'preset' => $atts['preset'], 'justify' => $atts['align'], 'maxWidth' => intval($atts['width']), 'maxHeight' => intval($atts['height']), 'logoSize' => intval($atts['logosize']), 'qPrefix' => $atts['qprefix'], 'qSuffix' => $atts['qsuffix'], 'noun' => $atts['noun'], 'provider' => $atts['provider'], 'openInNewTab'=> ( $atts['newtab'] === '1' ), 'relNoFollow' => ( $atts['nofollow'] === '1' ), 'bgColor' => $atts['bgcolor'], 'textColor' => $atts['textcolor'], 'borderColor' => $atts['bordercolor'], ); return aisubu_render_button( $attributes ); } add_shortcode( 'aisubu_summarise_button', 'aisubu_shortcode' ); } if ( ! function_exists( 'aisubu_register_block' ) ) { function aisubu_register_block() { if ( ! function_exists( 'register_block_type' ) ) return; wp_register_script( 'aisubu-block', plugins_url( 'block.js', __FILE__ ), array( 'wp-blocks','wp-element','wp-components','wp-block-editor','wp-i18n' ), AISUBU_VER, true ); register_block_type( 'ai/summarise-button', array( 'api_version' => 2, 'editor_script' => 'aisubu-block', 'render_callback'=> 'aisubu_render_button', 'attributes' => array( 'mode' => array('type'=>'string','default'=>'basic'), 'buttonText' => array('type'=>'string','default'=>'Summarise with AI'), 'preset' => array('type'=>'string','default'=>'chatgpt'), 'justify' => array('type'=>'string','default'=>'left'), 'align' => array('type'=>'string'), 'maxWidth' => array('type'=>'number','default'=>200), 'maxHeight'=> array('type'=>'number','default'=>32), 'logoSize' => array('type'=>'number','default'=>15), 'qPrefix' => array('type'=>'string','default'=>'Read and summarise this'), 'qSuffix' => array('type'=>'string','default'=>'so I can ask questions about it.'), 'noun' => array('type'=>'string','default'=>'page'), 'provider' => array('type'=>'string','default'=>'chatgpt'), 'openInNewTab'=> array('type'=>'boolean','default'=>true), 'relNoFollow' => array('type'=>'boolean','default'=>true), 'iconPosition'=> array('type'=>'string','default'=>'left'), 'isFullWidth' => array('type'=>'boolean','default'=>false), 'borderRadius'=> array('type'=>'number','default'=>8), 'paddingX' => array('type'=>'number','default'=>10), 'paddingY' => array('type'=>'number','default'=>6), 'bgColor' => array('type'=>'string','default'=>''), 'textColor' => array('type'=>'string','default'=>''), 'borderColor' => array('type'=>'string','default'=>''), ), 'supports' => array( 'html' => false, 'align' => array( 'left', 'center', 'right' ) ) ) ); } add_action( 'init', 'aisubu_register_block' ); }