Ticket #370 (closed enhancement: fixed)
PluginaMediaItem.class.php getEmbedCode refactoring
| Reported by: | johnnyoffline | Owned by: | boutell |
|---|---|---|---|
| Priority: | major | Milestone: | 1.4.1 |
| Component: | apostrophePlugin: Media | Version: | trunk |
| Keywords: | media | Cc: | rickybanister, johnnyoffline, boutell, agilbert, dordille, geoffd |
| Symfony version: | 1.4 |
Description
Tom,.
I need you to refactor getEmbedCode to return simply the URL of an image if I pass it a flag
OR just give me a new static method for getting the media url $item->getMediaItemURL();
It doesn't have to be an extension of getEmbedCode.
I just need flexibility in tossing around images for when I don't want them to be image tags.
// Something like this?
$item->getEmbedCode(array('get_url'=> true));
// Here's the function from PluginaMediaItem?.class.php
public function getEmbedCode($width, $height, $resizeType, $format = 'jpg', $absolute = false, $wmode = 'opaque')
{
if ($height === false)
{
// Scale the height. I had this backwards
$height = floor(($width * $this->height / $this->width) + 0.5);
}
// Accessible alt title
$title = htmlspecialchars($this->getTitle());
// It would be nice if partials could be used for this.
// Think about whether that's possible.
if ($this->getType() === 'video')
{
if ($this->embed)
{
// Solution for non-YouTube videos based on a manually
// provided thumbnail and embed code
return str_replace(array('_TITLE_', '_WIDTH_', '_HEIGHT_'),
array($title, $width, $height), $this->embed);
}
// TODO: less YouTube-specific
$serviceUrl = $this->getServiceUrl();
$embeddedUrl = $this->youtubeUrlToEmbeddedUrl($serviceUrl);
return <<<EOM
<object alt="$title" width="$width" height="$height">
<param name="movie" value="$embeddedUrl"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<param name="wmode" value="$wmode"></param>
<embed alt="$title" src="$embeddedUrl" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="$width" height="$height" wmode="$wmode"></embed>
</object>
EOM
;
}
elseif (($this->getType() == 'image') || ($this->getType() == 'pdf'))
{
$controller = sfContext::getInstance()->getController();
$slug = $this->getSlug();
$imageUrl = $controller->genUrl("@a_media_image?" . http_build_query(array("slug" => $slug, "width" => $width, "height" => $height, "resizeType" => $resizeType, "format" => $format)), $absolute);
// Use named routing rule to ensure the desired result (and for speed)
return "<img alt=\"$title\" src='".$imageUrl."' />";
}
else
{
throw new Exception("Unknown media type in getEmbedCode: " . $this->getType() . " id is " . $this->id . " is new? " . $this->isNew());
}
}
Attachments
Change History
Note: See
TracTickets for help on using
tickets.


