<?php
/**
  * Ahead WebSoft Technologies Pvt Ltd.
  * @copyright  Copyright 2006-2026 Ahead WebSoft Technologies Pvt Ltd.
  * @license    https://www.socialengine.com/policies
*/

class Engine_Form_Decorator_FormMediaUpload extends Zend_Form_Decorator_Abstract implements Zend_Form_Decorator_Marker_File_Interface
{
  protected $_placement = self::APPEND;

  public function render($content)
  {
    $element = $this->getElement();
    if( !$element instanceof Zend_Form_Element )
    {
      return $content;
    }

    $view = $element->getView();
    if( !$view instanceof Zend_View_Interface )
    {
      return $content;
    }

    $staticBaseUrl = '';
    try {
      $layout = $view->layout();
      if( $layout && isset($layout->staticBaseUrl) ) {
        $staticBaseUrl = $layout->staticBaseUrl;
      }
    } catch( Exception $e ) {
			// Silence
		}

    $mediauploadfile = $view->partial('upload/media-upload.tpl', 'core', array('element' => $element, 'staticBaseUrl' => $staticBaseUrl));

    $separator = $this->getSeparator();
    switch( $this->getPlacement() )
    {
      case self::PREPEND:
        return $mediauploadfile . $separator . $content;
      case self::APPEND:
      default:
        return $content . $separator . $mediauploadfile;
    }
  }
}
