Пример #1
0
 public function render()
 {
     if (!is_null($uri = $this->_obj->getValue())) {
         return sprintf('<a href="%s" target="_blank">%s</a>', MediaElement::getDownloadUrl($uri), 'Télécharger');
     } else {
         return 'Pas de fichier lié';
     }
 }
Пример #2
0
 public function render()
 {
     // set correct name for field name value depending on 'mode' parameter value
     $name = $this->_obj->getId();
     $prefix = Core::getController('medias');
     if (!$prefix) {
         $prefix = '/t41/medias/';
     }
     $uri = $prefix . 'upload';
     View::addCoreLib(array('core.js', 'locale.js', 'view.js', 'uploader.css', 'view:action:upload.js'));
     View::addEvent(sprintf("t41.view.register('%s_ul', new t41.view.action.upload(jQuery('#%s_ul'),'%s'))", $name, $name, $uri), 'js');
     $html = '';
     // @todo code media deletion JS
     if ($this->_obj->getValue() != null) {
         $html .= sprintf('<span><a href="%s" target="_blank">%s %s</a> | <a href="#" onclick="t41.view.get(\'%s_ul\').reset(this)">%s</a></span>', MediaElement::getDownloadUrl($this->_obj->getValue()->getUri()), 'Télécharger', $this->_obj->getValue()->getLabel(), $name, 'Supprimer');
     }
     $html .= sprintf('<div id="%s_ul" class="qq-upload-list"></div>', $this->_nametoDomId($name));
     $html .= sprintf('<input type="hidden" name="%s" id="%s" value="%s" class="hiddenfilename"/>', $name, $this->_nametoDomId($name), $this->_obj->getValue() ? $this->_obj->getValue()->getIdentifier() : null);
     return $html;
     $action = new UploadAction($this->_obj);
     $deco = View\Decorator::factory($action);
     $deco->render();
     return $html . "\n";
 }
Пример #3
0
 /**
  * Parse given tags against current template
  * 
  * @param array $tags
  */
 protected function _parseTags($tags)
 {
     foreach ($tags as $tag) {
         $value = null;
         switch ($tag[1]) {
             case 'var':
                 $keys = explode('.', $tag[2]);
                 $value = $this->_obj->getVariable($keys[0]);
                 if (count($keys) > 1) {
                     $value = $value[$keys[1]];
                 }
                 break;
             case 'env':
                 $value = View::getEnvData($tag[2]);
                 break;
             case 'container':
                 if (($templates = $this->_obj->getSubtemplates($tag[2])) !== false) {
                     $value = '';
                     foreach ($templates as $template) {
                         $deco = Decorator::factory($template);
                         $value .= $deco->render();
                     }
                 }
                 break;
             default:
                 // obj:
                 $tmp = explode('.', $tag[2]);
                 $obj = $this->_obj->getVariable($tmp[0]);
                 if ($obj instanceof MediaObject && isset($tmp[1])) {
                     // meta properties handling
                     switch ($tmp[1]) {
                         case '_base64':
                             $value = sprintf('data:%s;base64,%s', $obj->getMime(), base64_encode($obj->loadBlob('media')));
                             break;
                         case '_icon':
                             $value = 'file-' . $obj->getExtension();
                             break;
                         case '_size':
                             $value = MediaElement::getDisplaySize($obj->getSize());
                             break;
                         case '_url':
                             $value = MediaElement::getDownloadUrl($obj->getUri());
                         default:
                             break;
                     }
                 }
                 if (!$value) {
                     if ($obj instanceof BaseObject) {
                         $value = isset($tmp[1]) && $tmp[1] == ObjectUri::IDENTIFIER ? $obj->getIdentifier() : $obj->getProperty($tmp[1]);
                         $value = $value instanceof AbstractProperty ? $value->getDisplayValue() : $value;
                     } else {
                         $value = Core::$env == Core::ENV_DEV ? sprintf("Can't substitute any value to '%s'", $tag[0]) : null;
                     }
                 }
                 break;
         }
         if ($value instanceof ViewObject) {
             $deco = Decorator::factory($value);
             $value = $deco->render();
         } else {
             //$value = $this->_escape($value);
         }
         $this->_template = str_replace($tag[0], $value, $this->_template);
     }
 }