static function listar($id, $text, $params) { $doc = JFactory::getDocument(); $doc->addScriptDeclaration(' function mostrarInfo(el, event) { event.preventDefault(); var el = $$(el); var file = el.get("data-file"); var hash = el.get("data-hash"); var size = el.get("data-size"); var mime = el.get("data-mime"); info = new Element("div"); info.appendHTML("<h2>Información de Archivo</h2>"); info.appendHTML("<hr />"); info.appendHTML("<h3>Nombre:</h3>"); info.appendHTML("<p>"+el.get("data-file")+"</p>"); info.appendHTML("<h3>Hash:</h3>"); info.appendHTML("<p>"+el.get("data-hash")+"</p>"); info.appendHTML("<h3>Tamaño:</h3>"); info.appendHTML("<p>"+el.get("data-size")+"</p>"); info.appendHTML("<h3>Tipo Mime:</h3>"); info.appendHTML("<p>"+el.get("data-mime")+"</p>"); info.appendHTML("<h3>Icono:</h3>"); info.appendHTML("<img src="+el.get("data-mime-icon")+" />"); SqueezeBox.resize({x:320, y:450}); SqueezeBox.setContent("adopt", info); }'); $db = JFactory::getDbo(); $query = $db->getQuery(true); $columnas = array('propietario_id', 'nombre_archivo', 'hash', 'ruta', 'mime_type'); $query->select($db->quoteName($columnas))->from($db->quoteName('#__adjuntos'))->where($db->quoteName('propietario_id') . ' = ' . $id); $db->setQuery($query); $adjuntos = $db->loadObjectList(); // verificar que el artículo tenga archivos adjuntos if (empty($adjuntos)) { return; } // construir la tabla html $html = ""; $html .= "<table>"; $html .= " <thead>"; $html .= " <tr>"; $html .= " <td>Tipo</td>"; $html .= " <td>Nombre de Archivo</td>"; $html .= " <td>Info</td>"; $html .= " </tr>"; $html .= " </thead>"; $html .= " <tbody>"; foreach ($adjuntos as $adjunto) { $mimeIcon = JMime::checkIcon($adjunto->mime_type); $rutaArchivo = self::obtenerRutaArchivo($adjunto->hash, $adjunto->nombre_archivo); $fileSize = JFile::getSize(self::obtenerRutaArchivo($adjunto->hash, $adjunto->nombre_archivo, true)); $html .= " <tr>"; $html .= " <td>"; $html .= " <img src='" . $mimeIcon . "'"; $html .= " alt='" . $adjunto->mime_type . "'"; $html .= " title='" . $adjunto->mime_type . "'/>"; $html .= " </td>"; $html .= " <td>"; $html .= " <a href='" . $rutaArchivo . "'"; $html .= " title='" . $adjunto->nombre_archivo . "'>"; $html .= " " . $adjunto->nombre_archivo; $html .= " </a>"; $html .= " </td>"; $html .= " <td>"; $html .= " <a href='javascript:void(0)' class='modal' onClick='mostrarInfo(this, event)' data-file='" . $adjunto->nombre_archivo . "' data-mime-icon='" . $mimeIcon . "' data-hash='" . $adjunto->hash . "' data-size='" . $fileSize . "' data-mime='" . $adjunto->mime_type . "'>"; $html .= " <img src='" . JURI::root() . "media/adjuntos/file-info-icon.png'"; $html .= " title='Información'/>"; $html .= " </a>"; $html .= " </td>"; $html .= " </tr>"; } $html .= " </tbody>"; $html .= "</table>"; return $html; }
function onBeforeRender() { $app = self::$app; $reqParams = self::$reqParams; $id = $reqParams['id']; if (!$app->isAdmin()) { return; } $user = self::$user; if (!$user->authorise('core.edit', 'com_content')) { return; } // termina la ejecución del plugin si los parametros recibidos no cumplen // con las condiciones preestablecidas para modificar el contexto de edición de // artículos if ($reqParams["view"] != "article" || $reqParams["layout"] != "edit") { return; } $doc = JFactory::getDocument(); $doc->addStyleSheet(JURI::root() . 'plugins/system/jokte_adjuntos/assets/css/estilos.css'); // obtiene el buffer del documento que será renderizado $buffer = mb_convert_encoding($doc->getBuffer('component'), 'html-entities', 'utf-8'); // inicializa la manipulación del DOM para el buffer del documento $dom = new DomDocument(); $dom->validateOnParse = true; $dom->loadHTML($buffer); // obtiene los datos de los adjuntos $data = self::getAttachmentsData($id); // selecciona elemento del DOM que contendrá los registros de los archivos adjuntos $contenedor = $dom->getElementById("adjuntos"); // realiza la construcción de la tabla con el listado de adjuntos $wrap = $dom->createElement("div"); $wrap->setAttribute("class", "wrap"); $tabla = $dom->createElement("table"); $tbody = $dom->createElement("tbody"); $c = 0; foreach ($data as $item) { $itemId = 'item-' . $c; $rutaArchivo = '/uploads' . DS . $item->hash . '-' . $item->nombre_archivo; $iconSrc = JMime::checkIcon($item->mime_type); $fileSize = JFile::getSize(JPATH_ROOT . $rutaArchivo); $row = $dom->createElement("tr"); $row->setAttribute('id', $itemId); $mime = $dom->createElement("td"); $file = $dom->createElement("td"); $info = $dom->createElement("td"); $info->setAttribute('class', 'center'); $trash = $dom->createElement("td"); $trash->setAttribute('class', 'center'); $mimeImg = $dom->createElement("img"); $mimeImg->setAttribute('src', $iconSrc); $mime->appendChild($mimeImg); $name = $dom->createElement("span"); $nameAnchor = $dom->createElement("a"); $nameAnchor->setAttribute('href', $rutaArchivo); $nameAnchor->setAttribute('target', '_blank'); $nameAnchor->nodeValue = $item->nombre_archivo; $name->appendChild($nameAnchor); $file->appendChild($name); $infoBtn = $dom->createElement("a"); $infoBtn->setAttribute('onclick', 'mostrarInfo(this, event)'); $infoBtn->setAttribute('title', 'Información'); $infoBtn->setAttribute('class', 'modal'); $infoBtn->setAttribute('href', 'javascript:void(0)'); $infoBtn->setAttribute('data-file', $item->nombre_archivo); $infoBtn->setAttribute('data-mimeIcon', $iconSrc); $infoBtn->setAttribute('data-hash', $item->hash); $infoBtn->setAttribute('data-size', $fileSize); $infoBtn->setAttribute('data-mime', $item->mime_type); $infoImg = $dom->createElement("img"); $infoImg->setAttribute('src', JURI::root() . '/media/adjuntos/file-info-icon.png'); $infoBtn->appendChild($infoImg); $info->appendChild($infoBtn); $trashBtn = $dom->createElement("button"); $trashBtn->setAttribute('onclick', 'eliminarAdjunto(this, event)'); $trashBtn->setAttribute('title', 'Eliminar archivo'); $trashBtn->setAttribute('data-hash', $item->hash); $trashBtn->setAttribute('data-id', $itemId); $trashImg = $dom->createElement("img"); $trashImg->setAttribute('src', JURI::root() . '/media/adjuntos/caneca.png'); $trashBtn->appendChild($trashImg); $trash->appendChild($trashBtn); $row->appendChild($mime); $row->appendChild($file); $row->appendChild($info); $row->appendChild($trash); $tbody->appendChild($row); $c++; } $wrap->appendChild($tabla); $tabla->appendChild($tbody); $contenedor->appendChild($wrap); // aplica los cambios realizados al DOM en un nuevo buffer para actualizar la presentación // del la vista del componente en el contexto indicado $newBuffer = $dom->saveHTML(); $doc->setBuffer($newBuffer, 'component'); }