| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /** |
|---|
| 4 | * aMediaItem |
|---|
| 5 | * |
|---|
| 6 | * This class has been auto-generated by the Doctrine ORM Framework |
|---|
| 7 | * |
|---|
| 8 | * @package asandbox |
|---|
| 9 | * @subpackage model |
|---|
| 10 | * @author Your name here |
|---|
| 11 | * @version SVN: $Id: Builder.php 7021 2010-01-12 20:39:49Z lsmith $ |
|---|
| 12 | */ |
|---|
| 13 | class aMediaItem extends PluginaMediaItem |
|---|
| 14 | { |
|---|
| 15 | |
|---|
| 16 | public function getEmbedCode($width, $height, $resizeType, $format = 'jpg', $absolute = false, $wmode = 'opaque') |
|---|
| 17 | { |
|---|
| 18 | if ($height === false) |
|---|
| 19 | { |
|---|
| 20 | // Scale the height. I had this backwards |
|---|
| 21 | $height = floor(($width * $this->height / $this->width) + 0.5); |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | // Accessible alt title |
|---|
| 25 | $title = htmlspecialchars($this->getTitle()); |
|---|
| 26 | // It would be nice if partials could be used for this. |
|---|
| 27 | // Think about whether that's possible. |
|---|
| 28 | if ($this->getType() === 'video') |
|---|
| 29 | { |
|---|
| 30 | if ($this->embed) |
|---|
| 31 | { |
|---|
| 32 | // Solution for non-YouTube videos based on a manually |
|---|
| 33 | // provided thumbnail and embed code |
|---|
| 34 | return str_replace(array('_TITLE_', '_WIDTH_', '_HEIGHT_'), |
|---|
| 35 | array($title, $width, $height), $this->embed); |
|---|
| 36 | } |
|---|
| 37 | // TODO: less YouTube-specific |
|---|
| 38 | $serviceUrl = $this->getServiceUrl(); |
|---|
| 39 | $embeddedUrl = $this->youtubeUrlToEmbeddedUrl($serviceUrl); |
|---|
| 40 | return <<<EOM |
|---|
| 41 | <object alt="$title" width="$width" height="$height"> |
|---|
| 42 | <param name="movie" value="$embeddedUrl"></param> |
|---|
| 43 | <param name="allowFullScreen" value="true"></param> |
|---|
| 44 | <param name="allowscriptaccess" value="always"></param> |
|---|
| 45 | <param name="wmode" value="$wmode"></param> |
|---|
| 46 | <embed alt="$title" src="$embeddedUrl" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="$width" height="$height" wmode="$wmode"></embed> |
|---|
| 47 | </object> |
|---|
| 48 | EOM |
|---|
| 49 | ; |
|---|
| 50 | } |
|---|
| 51 | elseif (($this->getType() == 'image') || ($this->getType() == 'pdf')) |
|---|
| 52 | { |
|---|
| 53 | $src = $this->getImageSrc($width, $height, $resizeType, $format, $absolute); |
|---|
| 54 | // Use named routing rule to ensure the desired result (and for speed) |
|---|
| 55 | return "<img alt=\"$title\" src='" . $src . "' />"; |
|---|
| 56 | } |
|---|
| 57 | else |
|---|
| 58 | { |
|---|
| 59 | throw new Exception("Unknown media type in getEmbedCode: " . $this->getType() . " id is " . $this->id . " is new? " . $this->isNew()); |
|---|
| 60 | } |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | public function getImageSrc($width, $height, $resizeType, $format = 'jpg', $absolute = false) |
|---|
| 64 | { |
|---|
| 65 | $controller = sfContext::getInstance()->getController(); |
|---|
| 66 | $slug = $this->getSlug(); |
|---|
| 67 | return $controller->genUrl("@a_media_image?" . http_build_query( array("slug" => $slug, "width" => $width, "height" => $height, "resizeType" => $resizeType, "format" => $format)), $absolute); |
|---|
| 68 | } |
|---|
| 69 | } |
|---|