";
$out .= __( 'This slideshow could not be started. Try refreshing the page or viewing it in another browser.', 'jetpack' ) . '
';
$out .= sprintf(
'',
esc_attr( $duration ),
esc_attr( $autoplay ),
esc_attr( $style )
);
$out .= "
";
$out .= "
";
$out .= "
";
if ( $autoplay ) {
$out .= '
';
$out .= __( 'Click to autoplay the presentation!', 'jetpack' );
$out .= '
';
}
$out .= do_shortcode( $content );
$out .= '';
$this->presentation_initialized = false;
return $out;
}
/**
* Slide shortcode.
*
* @param array $atts Shortcode attributes.
* @param string $content Post content.
*/
public function slide_shortcode( $atts, $content = '' ) {
// Bail out unless wrapped by a [presentation] shortcode.
if ( ! $this->presentation_initialized ) {
return $content;
}
$atts = shortcode_atts(
array(
'transition' => '',
'scale' => '',
'rotate' => '',
'fade' => '',
'fadebullets' => '',
'bgcolor' => '',
'bgimg' => '',
),
$atts,
'slide'
);
// Determine positioning based on transition.
if ( '' === trim( $atts['transition'] ) ) {
$atts['transition'] = $this->presentation_settings['transition'];
}
// Setting the content scale.
if ( '' === trim( $atts['scale'] ) ) {
$atts['scale'] = $this->presentation_settings['scale'];
}
if ( '' === trim( $atts['scale'] ) ) {
$scale = 1;
} else {
$scale = (float) $atts['scale'];
}
if ( $scale < 0 ) {
$scale *= -1;
}
// Setting the content rotation.
if ( '' === trim( $atts['rotate'] ) ) {
$atts['rotate'] = $this->presentation_settings['rotate'];
}
if ( '' === trim( $atts['rotate'] ) ) {
$rotate = 0;
} else {
$rotate = (float) $atts['rotate'];
}
// Setting if the content should fade.
if ( '' === trim( $atts['fade'] ) ) {
$atts['fade'] = $this->presentation_settings['fade'];
}
if ( 'on' === $atts['fade'] || 'true' === $atts['fade'] ) {
$fade = 'fade';
} else {
$fade = '';
}
// Setting if bullets should fade on step changes.
if ( '' === trim( $atts['fadebullets'] ) ) {
$atts['fadebullets'] = $this->presentation_settings['fadebullets'];
}
if ( 'on' === $atts['fadebullets'] || 'true' === $atts['fadebullets'] ) {
$fadebullets = 'fadebullets';
} else {
$fadebullets = '';
}
$coords = $this->get_coords(
array(
'transition' => $atts['transition'],
'scale' => $scale,
'rotate' => $rotate,
)
);
$x = $coords['x'];
$y = $coords['y'];
/*
* Check for background color XOR background image
* Use a white background if nothing specified
*/
if ( preg_match( '/https?\:\/\/[^\'"\s]*/', $atts['bgimg'], $matches ) ) {
$style = 'background-image: url("' . esc_url( $matches[0] ) . '");';
} elseif ( '' !== trim( $atts['bgcolor'] ) ) {
$style = 'background-color: ' . esc_attr( $atts['bgcolor'] ) . ';';
} else {
$style = '';
}
// Put everything together and let jmpress do the magic!
$out = sprintf(
'
',
esc_attr( $fade ),
esc_attr( $fadebullets ),
esc_attr( $x ),
esc_attr( $y ),
esc_attr( $scale ),
esc_attr( $rotate ),
esc_attr( $style )
);
$out .= '
';
$out .= do_shortcode( $content );
$out .= '
';
return $out;
}
/**
* Determines the position of the next slide based on the position and scaling of the previous slide.
*
* @param array $args {
* Array of key-value pairs.
*
* @type string $transition: the transition name, "up", "down", "left", or "right".
* @type float $scale: the scale of the next slide (used to determine the position of the slide after that).
* }
*
* @return array with the 'x' and 'y' coordinates of the slide.
*/
private function get_coords( $args ) {
if ( 0 === $args['scale'] ) {
$args['scale'] = 1;
}
$width = $this->presentation_settings['width'];
$height = $this->presentation_settings['height'];
$last = $this->presentation_settings['last'];
$scale = $last['scale'];
$next = array(
'x' => $last['x'],
'y' => $last['y'],
'scale' => $args['scale'],
'rotate' => $args['rotate'],
);
// All angles are measured from the vertical axis, so everything is backwards!
$diag_angle = atan2( $width, $height );
$diagonal = sqrt( pow( $width, 2 ) + pow( $height, 2 ) );
/*
* We offset the angles by the angle formed by the diagonal so that
* we can multiply the sines directly against the diagonal length
*/
$theta = deg2rad( $last['rotate'] ) - $diag_angle;
$phi = deg2rad( $next['rotate'] ) - $diag_angle;
// We start by displacing by the slide dimensions.
$total_horiz_disp = $width * $scale;
$total_vert_disp = $height * $scale;
/*
* If the previous slide was rotated, we add the incremental offset from the rotation
* Namely the difference between the regular dimension (no rotation) and the component
* of the diagonal for that angle
*/
$total_horiz_disp += ( ( ( abs( sin( $theta ) ) * $diagonal ) - $width ) / 2 ) * $scale;
$total_vert_disp += ( ( ( abs( cos( $theta ) ) * $diagonal ) - $height ) / 2 ) * $scale;
/*
* Similarly, we check if the current slide has been rotated and add whatever additional
* offset has been added. This is so that two rotated corners don't clash with each other.
* Note: we are checking the raw angle relative to the vertical axis, NOT the diagonal angle.
*/
if ( 0 !== $next['rotate'] % 180 ) {
$total_horiz_disp += ( abs( ( sin( $phi ) * $diagonal ) - $width ) / 2 ) * $next['scale'];
$total_vert_disp += ( abs( ( cos( $phi ) * $diagonal ) - $height ) / 2 ) * $next['scale'];
}
switch ( trim( $args['transition'] ) ) {
case 'none':
break;
case 'left':
$next['x'] -= $total_horiz_disp;
break;
case 'right':
$next['x'] += $total_horiz_disp;
break;
case 'up':
$next['y'] -= $total_vert_disp;
break;
case 'down':
default:
$next['y'] += $total_vert_disp;
break;
}
$this->presentation_settings['last'] = $next;
return $next;
}
}
$GLOBALS['presentations'] = new Presentations();
endif;