'',
'text' => __( 'Download', 'tarkle-send' ),
'class' => '',
'nocache' => '0',
),
$atts,
'tsend_download'
);
$slug = tarkle_send_sanitize_slug( $atts['slug'] );
if ( empty( $slug ) ) {
return '';
}
// Get signed URL (includes signature that expires in 10 minutes)
$error_message = null;
$skip_cache = '1' === $atts['nocache'];
$signed_url = tarkle_send_get_signed_url( $slug, 'download', $error_message, $skip_cache );
if ( empty( $signed_url ) ) {
if ( current_user_can( 'manage_options' ) ) {
return sprintf(
'
%s
',
esc_html( $error_message ?: __( 'Failed to get signed URL', 'tarkle-send' ) )
);
}
return '';
}
$text = sanitize_text_field( $atts['text'] );
$classes = tarkle_send_sanitize_classes( $atts['class'] );
// Apply default Tarkle button styling if no custom classes provided
if ( empty( $classes ) ) {
$classes = 'tarkle-send-button-primary';
// Get workspace accent color for button styling
$accent_color = tarkle_send_get_accent_color( $slug );
$style = sprintf( ' style="background-color: %s;"', esc_attr( $accent_color ) );
} else {
$style = '';
}
$class = sprintf( ' class="%s"', esc_attr( $classes ) );
return sprintf(
'%s',
esc_url( $signed_url ),
$class,
$style,
esc_html( $text )
);
}
/**
* [tsend_transfer] shortcode handler.
*
* Renders a transfer page in an iframe using the embedded route.
*
* Attributes:
* - slug (required): Transfer slug
* - width (optional): Iframe width, default "100%"
* - height (optional): Iframe height, default "auto"
* - header (optional): Show header with logo and description, default "false"
* - nocache (optional): Bypass cache, default "0"
*
* @param array $atts Shortcode attributes.
* @param string $content Shortcode content (unused).
* @return string HTML output.
*/
function tarkle_send_shortcode_transfer( $atts, $content = '' ) {
if ( ! tarkle_send_is_configured() ) {
return tarkle_send_missing_config_notice();
}
$atts = shortcode_atts(
array(
'slug' => '',
'width' => '100%',
'height' => 'auto',
'header' => 'false',
'download' => 'true',
'copy_link' => 'true',
'booking' => 'true',
'nocache' => '0',
),
$atts,
'tsend_transfer'
);
$slug = tarkle_send_sanitize_slug( $atts['slug'] );
if ( empty( $slug ) ) {
return '';
}
$error_message = null;
$skip_cache = '1' === $atts['nocache'];
$signed_url = tarkle_send_get_signed_url( $slug, 'transfer', $error_message, $skip_cache );
if ( empty( $signed_url ) ) {
if ( current_user_can( 'manage_options' ) ) {
return sprintf(
'%s
',
esc_html( $error_message ?: __( 'Failed to get signed URL', 'tarkle-send' ) )
);
}
return '';
}
$width = tarkle_send_sanitize_dimension( $atts['width'] );
$height = sanitize_text_field( $atts['height'] );
$show_header = 'true' === $atts['header'] ? 'true' : 'false';
$show_download = 'true' === $atts['download'] ? 'true' : 'false';
$show_copy_link = 'true' === $atts['copy_link'] ? 'true' : 'false';
$show_booking = 'true' === $atts['booking'] ? 'true' : 'false';
// Swap /t/ for /embed/t/ in the path only, before touching the query string.
$parsed = wp_parse_url( $signed_url );
$path = isset( $parsed['path'] ) ? str_replace( '/t/', '/embed/t/', $parsed['path'] ) : '';
// Merge existing query params with the new UI-toggle params in one array,
// then rebuild the query string once. This is the fix: add_query_arg()
// chained repeatedly against a URL with 6 existing params was corrupting
// the query string down to just the first param.
$query_params = array();
if ( isset( $parsed['query'] ) ) {
parse_str( $parsed['query'], $query_params );
}
$query_params['header'] = $show_header;
$query_params['download'] = $show_download;
$query_params['copy_link'] = $show_copy_link;
$query_params['booking'] = $show_booking;
$embed_url = $parsed['scheme'] . '://' . $parsed['host'] . $path . '?' . http_build_query( $query_params );
$iframe_id = 'tarkle-transfer-' . sanitize_key( $slug ) . '-' . wp_rand( 1000, 9999 );
$height_style = 'auto' === $height
? 'style="border: none; border-radius: 12px; display: block; height: 600px; width: 100%; overflow: hidden;"'
: sprintf( 'style="border: none; border-radius: 12px; display: block; height: %s; width: 100%%; overflow: hidden;"', esc_attr( $height ) );
$iframe_html = sprintf(
'',
esc_attr( $iframe_id ),
esc_url( $embed_url ),
$height_style
);
$script_code = sprintf(
'(function() {
var iframe = document.getElementById("%s");
if (!iframe) return;
var handleMessage = function(event) {
if (event.source !== iframe.contentWindow) return;
if (event.data && event.data.type === "sb-height" && event.data.height) {
var newHeight = Math.max(parseInt(event.data.height), 400);
iframe.style.height = newHeight + "px";
iframe.style.minHeight = newHeight + "px";
}
};
window.addEventListener("message", handleMessage);
})();',
esc_attr( $iframe_id )
);
wp_add_inline_script( 'jquery', $script_code );
return $iframe_html;
}
/**
* Extract query parameter from URL.
*
* @param string $url The URL.
* @param string $param The parameter name.
* @return string The parameter value, or empty string if not found.
*/
function tarkle_send_extract_param( $url, $param ) {
$parsed = wp_parse_url( $url );
if ( ! isset( $parsed['query'] ) ) {
return '';
}
parse_str( $parsed['query'], $query_params );
return isset( $query_params[ $param ] ) ? $query_params[ $param ] : '';
}
/**
* [tsend_file_request] shortcode handler.
*
* Renders a file request form in an iframe.
*
* Attributes:
* - slug (required): File request slug
* - width (optional): Iframe width, default "100%"
* - height (optional): Iframe height, default "700px"
*
* @param array $atts Shortcode attributes.
* @param string $content Shortcode content (unused).
* @return string HTML output.
*/
function tarkle_send_shortcode_file_request( $atts, $content = '' ) {
if ( ! tarkle_send_is_configured() ) {
return tarkle_send_missing_config_notice();
}
$atts = shortcode_atts(
array(
'slug' => '',
'width' => '100%',
'height' => '700px',
),
$atts,
'tsend_file_request'
);
$slug = tarkle_send_sanitize_slug( $atts['slug'] );
if ( empty( $slug ) ) {
return '';
}
$base_url = tarkle_send_get_base_url();
$url = sprintf(
'%s/r/%s/embed',
$base_url,
esc_attr( $slug )
);
$width = tarkle_send_sanitize_dimension( $atts['width'] );
$height = tarkle_send_sanitize_dimension( $atts['height'] );
return sprintf(
'',
esc_url( $url ),
esc_attr( $width ),
esc_attr( $height )
);
}