Ejemplo n.º 1
0
 static function getHTML($articleid, $fieldsid, $category = false, $write = false)
 {
     global $globalreturn;
     //$str  = fieldattach::getFileDownload($articleid, $fieldsid, $category );
     //GET Extras ***************************
     $fieldsids = $fieldsid;
     $extras = fieldattach::getExtra($fieldsid);
     $html = "";
     if (!empty($extras)) {
         if (count($extras) > 0) {
             $selectable = $extras[0];
         }
     }
     //GET Values ***************************
     if (method_exists('fieldattach', 'getFieldValues')) {
         $jsonValues = fieldattach::getFieldValues($articleid, $fieldsid, $category);
         $jsonValuesArray = json_decode($jsonValues);
         $valor = $jsonValuesArray->value;
         $title = $jsonValuesArray->title;
         $published = $jsonValuesArray->published;
         $showTitle = $jsonValuesArray->showtitle;
     } else {
         $valor = fieldattach::getValue($articleid, $fieldsids, $category);
         $title = fieldattach::getName($articleid, $fieldsids);
         $published = plgfieldsattachment_file::getPublished($fieldsid);
         $showTitle = fieldattach::getShowTitle($fieldid);
     }
     $directorio = "documents";
     $tmpfile = explode("|", $valor);
     $file = $tmpfile[0];
     $titlefile = JText::_("DOWNLOAD");
     if (count($tmpfile) > 1) {
         $titlefile = $tmpfile[1];
     }
     if ($category) {
         $directorio = 'documentscategories';
     }
     //Build url link
     if ($selectable == "selectable") {
         $file_absolute = fieldsattachHelper::getabsoluteURL() . $file;
     } else {
         $file_absolute = 'images/' . $directorio . '/' . $articleid . '/' . $file;
     }
     if (!empty($valor) && $published) {
         //$title = fieldattach::getName($articleid, $fieldsid, $category);
         $html = plgfieldsattachment_file::getTemplate($fieldsid, "file");
         /*
                         Templating Laouyt *****************************
             [TITLE] - Title of field
                         [FIELD_ID] - Field id 
                         [VALUE] - Value of input
                         [ARTICLE_ID] - Article id
         */
         if ($showTitle) {
             $html = str_replace("[TITLE]", $title, $html);
         } else {
             $html = str_replace("[TITLE]", "", $html);
         }
         $html = str_replace("[FIELD_ID]", $fieldsid, $html);
         $html = str_replace("[ARTICLE_ID]", $articleid, $html);
         $html = str_replace("[TITLE_FILE]", $titlefile, $html);
         $html = str_replace("[URL]", $file_absolute, $html);
         if ($selectable == "selectable") {
         } else {
             if (!JFile::exists(JPATH_SITE . DS . "images" . DS . $directorio . DS . $articleid . DS . $file)) {
                 $html = "";
             }
         }
         /*$html .= '<div class="download">';
           if($selectable=="selectable"){
               if(fieldattach::getShowTitle(   $fieldsids  ))  $html .= '<span class="title">'.$title.' </span>';
               $html .=  '<a href="'.$file_absolute.'"   alt="'.$titlefile.'" class="downloads" target="_blank" />'.$titlefile.'</a>';
             
           }else{
               if (JFile::exists( JPATH_SITE .DS."images".DS.$directorio.DS. $articleid .DS. $file)  )
               {
                   if(fieldattach::getShowTitle(   $fieldsids  ))  $html .= '<span class="title">'.$title.' </span>';
                       $html .=  '<a href="'.$file_absolute.'"   alt="'.$titlefile.'" class="downloads" target="_blank" />'.$titlefile.'</a>';
               }
           }
           $html .= '</div>';*/
     }
     //WRITE THE RESULT
     if ($write) {
         echo $html;
     } else {
         $globalreturn = $html;
         return $html;
     }
 }