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

Changeset 4536

Show
Ignore:
Timestamp:
02/02/12 10:46:07 (4 months ago)
Author:
tboutell
Message:

Refactored getEmbedCode() so it doesn't instantiate embed services twice and doesn't crash if the service URL is bogus and the width and height aren't known

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • plugins/apostrophePlugin/branches/1.5/lib/model/doctrine/PluginaMediaItem.class.php

    r4503 r4536  
    278278  public function getEmbedCode($width, $height, $resizeType, $format = 'jpg', $absolute = false, $wmode = 'opaque', $autoplay = false, $options = array()) 
    279279  { 
     280    $embeddable = $this->getEmbeddable(); 
     281    $service = null; 
     282    // A little bit of refactoring to avoid instantiating the service twice. 
     283    // We need an embed service to handle anything embeddable with a service URL, so 
     284    // check early 
     285    if ($embeddable && strlen($this->service_url)) 
     286    { 
     287      $service = aMediaTools::getEmbedService($this->service_url); 
     288      if (!$service) 
     289      { 
     290        // Most likely explanation: this service was configured, now it's not. 
     291        // Don't crash 
     292        return '<div>Video Service Not Available</div>'; 
     293      } 
     294    } 
     295     
    280296    if ($height === false) 
    281297    { 
     
    284300      { 
    285301        // Not known yet. This comes up when previewing a video with a service URL that we haven't saved yet 
    286         if ($this->service_url) 
     302        if (isset($service)) 
    287303        { 
    288           $service = aMediaTools::getEmbedService($this->service_url); 
    289304          $thumbnail = $service->getThumbnail($service->getIdFromUrl($this->service_url)); 
    290305          if ($thumbnail) 
     
    311326      $title = aHtml::entities($this->getTitle()); 
    312327    } 
    313     if ($this->getEmbeddable()) 
    314     { 
    315       if ($this->service_url) 
    316       { 
    317         $service = aMediaTools::getEmbedService($this->service_url); 
    318         if (!$service) 
    319         { 
    320           // Most likely explanation: this service was configured, now it's not. 
    321           // Don't crash 
    322           return '<div>Video Service Not Available</div>'; 
    323         } 
     328    if ($embeddable) 
     329    { 
     330      if ($service) 
     331      { 
    324332        return $service->embed($service->getIdFromUrl($this->service_url), $width, $height, $title, $wmode, $autoplay); 
    325333      }