Recordad que para pedir soporte alguno, debéis facilitar los datos de soporte oportunos por favor, mirad aquí y leer las Normas generales del foro, esto nos servirá de ayuda para dar el mejor soporte..

Gracias.

La Administración de phpBB España.

Tabla de ultimos post en los foros o en cualquier foro

Guías, manuales, tutoriales, etc. sobre phpBB2 y otros sistemas.
Foro de lectura, las dudas en el Foro oportuno por favor.
Cerrado
Avatar de Usuario
ThE KuKa
Administrador
Mensajes: 10374
Registrado: 04 Ene 2004, 19:27
Género:
Edad: 49

Tabla de ultimos post en los foros o en cualquier foro

#1

Mensaje por ThE KuKa »

Esta modicación incluye en el índice del foro una tablita con información de los últimos posts enviados a los foros.

Está hecha de tal forma que si no se pasa por query string al index la variable f que contiene el identificador del foro a mostrar, mostrará los últimos mensajes de TODOS los foros, y si se pasa un identificador de foro, bien manualmente, bien usando el select que he incorporado abajo de la tabla, mostrará los últimos mensajes del foro apropiado.

Cuando se pase un identificador de foro que no existe o bien el de un foro al cual el usuario no tiene acceso, mostrará por defecto la información de los últimos posts de TODOS LOS FOROS.

El select no muestra claro está los foros a los que el usuario no tiene acceso (he usado simplemente la función make_jumpbox que lo hace automáticamente). Puesto que la función make_jumpbox devuelve únicamente el select de los foros, para permitir la navegación a MOSTRAR TODOS LOS FOROS ha sido necesario usar un link(un simple link al index mismo sin pasar variable por query string).

Además he usado una plantilla para que quién quiera instalarselo no se tenga que liar a toquetear el php.

Instalación:
Crear un archivo llamado ultimos.php con el siguiente contenido:

Código: Seleccionar todo

<?
//iniciamos template
$template->set_filenames(array(
		'ultimos' => 'ultimos.tpl')
	);

// AVERIGUAMOS LOS FOROS A LOS QUE EL USUARIO NO TIENE ACCESO y A LOS QUE TIENE ACCESO. Tb adaptamos salida para concatenar a query
$auth_ary = auth(AUTH_READ, AUTH_LIST_ALL, $userdata); 
foreach ( $auth_ary as $auth_forum_id=>$auth_level ) 
{
	if (!$auth_level['auth_read'] ) 
	{ 
		$auth_view_forums = ($auth_view_forums . " p.forum_id<>" . $auth_forum_id . " AND "); 
		$auth_view_forums1 = ($auth_view_forums1 . " forum_id<>" . $auth_forum_id . " AND "); 
		$no_accesibles[]=$auth_forum_id;
	}
	else 
	{
		$accesibles[]=$auth_forum_id;
	}
	
} 
$auth_view_forums="WHERE " . $auth_view_forums; 


// si no se pasa f por query string	 ->		TODOS LOS FOROS
// si se pasa f por query string	:
//									si no existe ese foro -> TODOS LOS FOROS
//									si existe pero no tiene permisos el usuario -> TODOS LOS FOROS

$foro = ( ( is_array( $no_accesibles ) && in_array( $HTTP_GET_VARS['f'] , $no_accesibles ) ) || !in_array( $HTTP_GET_VARS['f'] , $accesibles ) ) ? "" : $HTTP_GET_VARS['f'];

// Pasamos a primera query el identificador de foro si procede y sino nada
$foro_query = ( $foro == "" ) ? "" : ( " p.forum_id=" . $HTTP_GET_VARS['f'] . " AND " );

// primera query que recoge distintos topic_id dados los últimos mensajes
$sql_ini=("SELECT distinct p.topic_id FROM ".POSTS_TABLE."  p, ".TOPICS_TABLE." t $auth_view_forums $foro_query p.topic_id=t.topic_id ORDER BY t.topic_last_post_id DESC LIMIT 0,5");
if ( !($result_ini = $db->sql_query($sql_ini)) )
		{
			message_die(GENERAL_ERROR, 'No se pudo obtener últimos temas', '', __LINE__, __FILE__, $sql_ini);
		}


while ( $assoc_ini=$db->sql_fetchrow($result_ini) )
	// Para cada topic_id obtenido extraeremos datos necesarios en dos querys
	{
		// Segunda query todos los datos menos el ultimo usuario
		$sql=("SELECT t.topic_last_post_id, t.topic_title, t.topic_id, t.topic_time, t.topic_replies, u.username,u.user_id, f.forum_name, f.forum_id, p.post_id, p.post_time FROM ".POSTS_TABLE." p, ".TOPICS_TABLE." t, ".USERS_TABLE." u, ".FORUMS_TABLE." f WHERE t.topic_poster=u.user_id AND t.topic_id=".$assoc_ini['topic_id']." AND p.post_id=t.topic_last_post_id AND t.forum_id=f.forum_id");
		if ( !($result = $db->sql_query($sql)) )
		{
			message_die(GENERAL_ERROR, 'No se pudo obtener últimos temas', '', __LINE__, __FILE__, $sql);
		}
		while ( $assoc=$db->sql_fetchrow($result) )
		{
			// tercera query ultimo posteador
			$sql_last=("SELECT u.username FROM ".POSTS_TABLE." p, ".USERS_TABLE." u WHERE p.post_id=".$assoc['topic_last_post_id']." AND  p.poster_id=u.user_id");
			if ( !($result_last = $db->sql_query($sql_last)) )
			{
				message_die(GENERAL_ERROR, 'No se pudo obtener últimos temas', '', __LINE__, __FILE__, $sql_last);
			}
			$ultimo_usuario=$db->sql_fetchrow($result_last);
			$ultimo_usuario=$ultimo_usuario['username'];
			$db->sql_freeresult($result_last);
			$fecha_ultimo=getdate($assoc['post_time']);
			$fecha_ultimo=$fecha_ultimo["mday"]."-".$fecha_ultimo["mon"]."-".$fecha_ultimo["year"]; 
			$fecha_abierto=getdate($assoc['topic_time']);
			$fecha_abierto=$fecha_abierto["mday"]."-".$fecha_abierto["mon"]."-".$fecha_abierto["year"]; 
			$foro_nombre = $assoc['forum_name'];
			$template->assign_block_vars('ultimos', array(
				'LINK_TITULO'		=>	append_sid( "viewtopic.$phpEx?p=".$assoc['post_id']."&highlight=#".$assoc['post_id'] ),
				'TITULO'			=>	( ( strlen ( $assoc["topic_title"] ) > 19 ) ? ( substr ( $assoc["topic_title"] , 0 , 19 ) . "..." ) : $assoc["topic_title"] ),
				'LINK_FORO'			=>	append_sid( "viewforum.$phpEx?f=".$assoc["forum_id"] ),
				'FORO'				=>  ( ( strlen ( $assoc["forum_name"] ) > 19 ) ? ( substr ( $assoc["forum_name"] , 0 , 19 ) . 	"..." ) : $assoc["forum_name"] ),
				'LINK_CREADOR_TEMA'	=>	append_sid( "profile.$phpEx?mode=viewprofile&u=".$assoc["username"] ),
				'CREADOR_TEMA'		=>	$assoc["username"],
				'CREADOR_FECHA'		=>  $fecha_abierto,
				'LINK_AUTOR_ULTIMO'	=>	append_sid( "profile.$phpEx?mode=viewprofile&u=".$ultimo_usuario ),
				'AUTOR_ULTIMO'		=>	$ultimo_usuario,
				'FECHA_ULTIMO'		=>	$fecha_ultimo,
				'RESPUESTAS'		=>	$assoc["topic_replies"]));
		}
		$db->sql_freeresult($result);
		
	}
$db->sql_freeresult($result_ini);
$template->assign_vars(array(
				'FORO_NOMBRE'		=>	( ( $foro == "" ) ? "TODOS LOS FOROS" : $foro_nombre ),
				'INDICE'			=> append_sid("index.$phpEx" ) ) );
make_jumpbox('index.'.$phpEx);
$template->pparse('ultimos');
?>
Y subirlo al directorio raiz del foro

Crear un archivo llamado ultimos.tpl con el siguiente contenido:

Código: Seleccionar todo

<table align="center" class="forumline" width="100%">
<tr align="right">
		<td class="catHead" colspan="5" height="28"><span class="cattitle"><a href="#" class="cattitle">Últimos mensajes en los foros&nbsp;&nbsp;::&nbsp;&nbsp;{FORO_NOMBRE}</a></span></td>
	</tr>
<tr>
	<th colspan="2">
	Título - Foro
	</th>
	<th>
	Abierto por
	</th>
	<th>
	Último mensaje
	</th>
	<th>
	Respuestas
	</th>
</tr>
<!-- BEGIN ultimos -->
<tr>
	<td class="row1" align="center" height="28">
		<span class="gensmall">
		<a href="{ultimos.LINK_TITULO}">
		{ultimos.TITULO}
		</a>
		</span>
	</td>
	<td class="row1" align="center" height="28">
<span class="gensmall">
		<a href="{ultimos.LINK_FORO}"> 
			{ultimos.FORO}
		</a></span>

	</td>
	<td class="row1" align="center" height="28">
		<span class="gensmall">
		<a href="{ultimos.LINK_CREADOR_TEMA}"> 
			{ultimos.CREADOR_TEMA}
		</a> </span>
		&nbsp;<span class="gensmall" height="28">
		el {ultimos.CREADOR_FECHA}</span>

	</td>
	<td class="row1" align="center" height="28">
		<span class="gensmall">
		<a href="{ultimos.LINK_AUTOR_ULTIMO}"> 
			{ultimos.AUTOR_ULTIMO}
		</a> </span>
		&nbsp;<span class="gensmall">
		el {ultimos.FECHA_ULTIMO}</span>

	<td class="row1" align="center" height="28">
	<span class="gensmall">
	{ultimos.RESPUESTAS}</span>

	</td>
</tr>
  <!-- END ultimos -->
<tr>
<td class="row3" colspan="2" align="center">
<span class="gensmall"><a href="{INDICE}">Todos los foros</a></span></td>
<td class="row3" colspan="3" align="center">
{JUMPBOX}</td>
</tr>
</table>
Y subirlo al directorio raiz de las plantillas que tengamos instaladas...

Abrir el archivo index.php y localizar la linea +/- 290

Código: Seleccionar todo

	include($phpbb_root_path . 'includes/page_header.'.$phpEx);
y despues hacer un include a nuestro ultimos.php (o como quieras haberle llamado)

Código: Seleccionar todo

	include($phpbb_root_path . 'ultimos.'.$phpEx);
Espero que sea útil...

📌 Raul [ThE KuKa] en phpBB 📌
✅ Jr. Extension Validator - Jr. Styles Validator - Style Customisations - Translator - International Support Team
✅

Si te gustan mis estilos, traducciones, etc. y quieres mostrar algo de aprecio, no dudes en hacer una donación Imagen
:flag_es: phpBB España - En línea desde 2003 :heart:



Cerrado

Volver a “Guías, manuales, tutoriales, ayuda, sobre phpBB 2 y otros”