To participate you must create an account on apostrophenow.org. If you have already done so, click Login.

Ticket #370 (closed enhancement: fixed)

Opened 21 months ago

Last modified 20 months ago

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

aMediaItem.class.php Download (2.5 KB) - added by johnnyoffline 21 months ago.
Overridden getEmbedCode and getImageSrc

Change History

Changed 21 months ago by boutell

  • milestone changed from 1.4 to 1.5

Changed 21 months ago by johnnyoffline

I really want this

Changed 21 months ago by johnnyoffline

  • milestone changed from 1.5 to 1.4.1

Chrome and Safari

Changed 21 months ago by johnnyoffline

Sorry, to validate what I mean. I need this feature to fix a bug that is unavoidable with slideshow slots in webkit browsers on the mac unless I have this functionality. A current client project depends on it.

Changed 21 months ago by johnnyoffline

  • priority changed from major to critical

Changed 21 months ago by johnnyoffline

Ran into another scenario where I could use this just now

Changed 21 months ago by johnnyoffline

Overridden getEmbedCode and getImageSrc

Changed 21 months ago by johnnyoffline

Tom, I'm not sure if this is how you would have done this, but I created what I needed at the project level.

I attached the aMediaItem.class.php that extends pluginaMediaItem.class.php..

If this looks good, then feel free to stick it into the plugin.

I'll be using this in my client projects until further notice.

Changed 21 months ago by johnnyoffline

  • priority changed from critical to major

Changed 20 months ago by boutell

  • status changed from new to closed
  • resolution set to fixed

Oy veh... I just refactored and added getImgSrcUrl as a quick before work Apostrophe thing, and how I see that you have your own version, sorry, I missed those updates. Have a look and see whether you like my version worse/better.

Note: See TracTickets for help on using tickets.