.psswiggleplayer_alignleft {display: inline; float: left;} .psswiggleplayer_aligncenter {display: block; margin-right: auto; margin-left: auto;} .psswiggleplayer_alignright {display: inline; float: right;} ";
return $style . preg_replace_callback("/
]+)+\\/>/", array($this, 'replaceWrapper'), $content);
}
function replaceWrapper($matches)
{
wp_enqueue_script('psswiggleplayer');
return $this->generateDiv($matches[0], $matches[1]);
}
function generateDiv($original, $attrs)
{
$duration = $this->getAttribute("data-psswiggleplayer-duration", $attrs);
if (!$this->isValidAndInRange($duration, self::DURATION_MIN, self::DURATION_MAX)) {
return $original;
}
$effect = $this->getAttribute("data-psswiggleplayer-effect", $attrs);
if (!$this->isValidAndInRange($effect, self::EFFECT_MIN, self::EFFECT_MAX)) {
return $original;
}
$balance = $this->getAttribute("data-psswiggleplayer-balance", $attrs);
if (!$this->isValidAndInRange($balance, self::EFFECTBALANCE_MIN, self::EFFECTBALANCE_MAX)) {
return $original;
}
$autoplay = $this->getAttribute("data-psswiggleplayer-autoplay", $attrs);
$autostop = $this->getAttribute("data-psswiggleplayer-autostop", $attrs);
$src = $this->getAttribute('src', $attrs);
$width = $this->getAttribute("width", $attrs);
$height = $this->getAttribute("height", $attrs);
$classes = $this->getAttribute("class", $attrs);
if (in_array(null, array($src, $width, $height, $classes))) {
return $original;
}
$alignmentClass = null;
foreach (explode(' ', $classes) as $class) {
if (in_array($class, array('alignleft', 'aligncenter', 'alignright'))) { //, 'alignnone'
$alignmentClass = 'psswiggleplayer_' . $class;
}
}
$halfWidth = $width / 2;
$animation_pause = AnimationParams::effectToPause($effect);
$balance = AnimationParams::effectBalanceToPauseBalance($balance);
$imageId = self::$counter++;
$imgTag = $this->buildImgTag($imageId, $src, $width, $height, $this->getAttribute('alt', $attrs), $this->getAttribute('title', $attrs), $autoplay, $autostop);
$animationStyle = AnimationParams::paramsToCSS($duration, $animation_pause, $balance);
return <<
figure#attachment_{$imageId} { width: {$halfWidth}px !important; }
@-webkit-keyframes psswiggleplayer_{$imageId}_animation {
{$animationStyle}
}
@keyframes psswiggleplayer_{$imageId}_animation {
{$animationStyle}
}
#psswiggleplayer_{$imageId} { overflow: hidden; width: {$halfWidth}px; height: {$height}px; background-image: url({$src}); background-position: 0; background-size: {$width}px {$height}px; }
#psswiggleplayer_{$imageId} img { border: none; margin-left: -{$halfWidth}px; max-width: none; }
#psswiggleplayer_{$imageId} img.hover {
-webkit-animation-name: psswiggleplayer_{$imageId}_animation;
-webkit-animation-timing-function: linear;
-webkit-animation-iteration-count: infinite;
-webkit-animation-duration: {$duration}ms;
-webkit-animation-direction: alternate;
animation-name: psswiggleplayer_{$imageId}_animation;
animation-timing-function: linear;
animation-iteration-count: infinite;
animation-duration: {$duration}ms;
animation-direction: alternate;
}
{$imgTag}
TEMPLATE;
}
function getAttribute($name, $attrs)
{
$re = "/{$name}=\\\"([^\\\"]+)\"/";
preg_match($re, $attrs, $matches);
if (count($matches) > 0) {
return $matches[1];
}
return null;
}
function isValidAndInRange($value, $min, $max)
{
return ($value !== null && is_numeric($value) && $min <= $value && $max >= $value);
}
private function buildImgTag($imageId, $src, $width, $height, $alt, $title, $autoplay, $autostop)
{
$res = sprintf('
';
}
}