Pagina 1 di 3

Aiuto sulla mod topics list

Inviato: 17/04/2011, 16:55
da sport
Ciao a tutti,
Ho installato la mod "topics list" che ho scaricato da questo post:
http://www.phpbbitalia.net/forum/richie ... html#p7693

Tutto è perfettamente funzionante.
Adesso, però, vorrei far in modo che la mod mi visualizzasse anche le prime parole del primo post di ogni topic o meglio, le parole contenute nel tag "[quote]".

Come posso fare? :roll:

Re: Aiuto sulla mod topics list

Inviato: 17/04/2011, 23:19
da Carlo
Puoi riportarmi la parte di codice da te utilizzata per mostrare quei dati?

Re: Aiuto sulla mod topics list

Inviato: 18/04/2011, 18:01
da sport
Questo è il file php che ho utilizzato

Codice: Seleziona tutto

<?php
/*
*
* @package Topic più visti & Ultimi Topic [MOD]
* @author Carlo
* @website http://www.phpbbitalia.net/
*
*/
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

// Configuration
$max_topic = 6;
$forums_id = array(228,229,230,231,232,233,234,236,237,238,239,240,241,242,243,244,245,246,132,133,291,287,288,289,286,147,145);
$default_image = './images/Not_Available.jpg';

$sql = "SELECT p.post_text, p.bbcode_uid, t.* FROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t WHERE t.forum_id IN (" . implode(', ', $forums_id) . ") AND p.post_id = t.topic_first_post_id ORDER BY topic_views DESC LIMIT 0," . $max_topic;
$result = $db->sql_query($sql);

$a = $b = 0;

while ($row = $db->sql_fetchrow($result)) {
	if ($auth->acl_get('f_read', $row['forum_id'])) {
		$a++;
		$bbcode_img_to_array = bbcode_img_to_array($row['post_text'], $row['bbcode_uid']);
		$thumb = (isset($bbcode_img_to_array['img'][0]) ? $bbcode_img_to_array['img'][0] : (isset($bbcode_img_to_array['img'][0]) ? $bbcode_img_to_array['img'][0] : $default_image));
		
		$template->assign_block_vars('topics_views', array(
			'EVEN'   => (($a % 2 == 0) ? true : false),
			'THUMB'	=> $thumb,
			'LINK'	=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=" . $row['forum_id'] . "&t=" . $row['topic_id']),
			'TITLE'	=> $row['topic_title'],
			'VIEWS'	=> $row['topic_views']
		));
	}
}

$db->sql_freeresult($result);


$sql = "SELECT p.post_text, p.bbcode_uid, t.* FROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t WHERE t.forum_id IN (" . implode(', ', $forums_id) . ") AND p.post_id = t.topic_first_post_id ORDER BY topic_time DESC LIMIT 0," . $max_topic;
$result = $db->sql_query($sql);

while ($row = $db->sql_fetchrow($result)) {
	if ($auth->acl_get('f_read', $row['forum_id'])) {
		$b++;
		$bbcode_img_to_array = bbcode_img_to_array($row['post_text'], $row['bbcode_uid']);
		$thumb = (isset($bbcode_img_to_array['img'][0]) ? $bbcode_img_to_array['img'][0] : (isset($bbcode_img_to_array['img'][0]) ? $bbcode_img_to_array['img'][0] : $default_image));
		
		$template->assign_block_vars('topics_time', array(
			'EVEN'   => (($b % 2 == 0) ? true : false),
			'THUMB'	=> $thumb,
			'LINK'	=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=" . $row['forum_id'] . "&t=" . $row['topic_id']),
			'TIME'	=> $user->format_date($row['topic_time'], false, false),
			'TITLE'	=> $row['topic_title']
		));
	}
}

$db->sql_freeresult($result);

/*
* Parse [img] and [thumbnail] BBCode for messages and insert in an array BBCode params
*
* @param $msg string message to parse
* @param $uid string bbcode uid for message
*
*/
function bbcode_img_to_array($msg, $uid) {
	$array_parsed_item = array();
	
	$msg = str_replace("\n", '', $msg);
	$msg = str_replace(array('[', ']'), array('<', '>'), $msg);
	$msg = str_replace(':' . $uid, '', $msg);
	$msg = preg_replace("|<url=(.*)>(.*)</url>|U", "<url>$1</url>", $msg);
	
	preg_match_all("|<img>(.*)</img>|U", $msg, $array['img']);
	preg_match_all("|<thumbnail>(.*)</thumbnail>|U", $msg, $array['thumbnail']);

	$bbcode = array(
		'img'		=> $array['img'][1],
		'thumbnail'	=> $array['thumbnail'][1]

	);
	
	return $bbcode;
}

page_header('Topic pi&ugrave; visti & Ultimi topic');

$template->set_filenames(array(
	'body' => 'topics_list.html',
));

page_footer();
?>
E qui quello html:

Codice: Seleziona tutto

<!-- INCLUDE overall_header.html -->

		<h2>Topic pi&ugrave; visti</h2>
		<table border="0">
		<!-- BEGIN topics_views -->
			<!-- IF not topics_views.EVEN -->
			<tr>
			<!-- ENDIF -->
				<td>
					
					<div class="panel">
						<div class="inner"><span class="corners-top"><span></span></span>
						
						<div class="content">
							<h2><a href="{topics_views.LINK}">{topics_views.TITLE}</a></h2>
							<div style="font-size: 1.2em;">
								<table border="0">
									<tr>
										<td><img src="{topics_views.THUMB}" width="134" height="166" alt="{topics_views.TITLE}" title="{topics_views.TITLE}" /></td>
										<td valign="center">
											<a href="{topics_views.LINK}">{topics_views.TITLE}</a><br />
											<em>Visite: <b>{topics_views.VIEWS}</b></em><br />
										</td>
									</tr>
								</table>
							</div>
						</div>
						
						<span class="corners-bottom"><span></span></span></div>
					</div>
					
				</td>
			<!-- IF topics_views.EVEN -->
			</tr>
			<!-- ENDIF -->
		<!-- END topics_views -->
		</table>
		
		<h2>Ultimi topic</h2>
		<table border="0">
		<!-- BEGIN topics_time -->
			<!-- IF not topics_time.EVEN -->
			<tr>
			<!-- ENDIF -->
				<td>
					
					<div class="panel">
						<div class="inner"><span class="corners-top"><span></span></span>
						
						<div class="content">
							<h2><a href="{topics_time.LINK}">{topics_time.TITLE}</a></h2>
							<div style="font-size: 1.2em;">
								<table border="0">
									<tr>
										<td><img src="{topics_time.THUMB}" width="134" height="166" alt="{topics_time.TITLE}" title="{topics_time.TITLE}" /></td>
										<td valign="center">
											<a href="{topics_time.LINK}">{topics_time.TITLE}</a><br />
											<em>Data: <b>{topics_time.TIME}</b></em><br />
										</td>
									</tr>
								</table>
							</div>
						</div>
						
						<span class="corners-bottom"><span></span></span></div>
					</div>
					
				</td>
			<!-- IF topics_time.EVEN -->
			</tr>
			<!-- ENDIF -->
		<!-- END topics_time -->
		</table>

<!-- INCLUDE overall_footer.html -->

Re: Aiuto sulla mod topics list

Inviato: 18/04/2011, 18:47
da Micogian
Bisognerebbe capire se effettivamente i Topics hanno sempre un testo racchiuso tra i tag [quote].
La Mod estrae gli ultimi Topics, in particolare il primo post degli ultimi topics, tra una trentina di Forums.
Siamo sicuri che il primo post di un Topic contenga un [quote] ?

Re: Aiuto sulla mod topics list

Inviato: 18/04/2011, 20:08
da sport
In realtà le parole che vorrei estrarre dai primi post degli ultimi topic del mio forum, sono contenute nel bbcode [trama]. E' un bbcode molto simile al quote. Nei primi post ho scritto riguardo il bbcode quote per intenderci...

Comunque, circa il 65% dei primi post contiene il bbcode "trama" e presto lo farò aggiungere anche ai restanti.

Allora è fattibile ?

Re: Aiuto sulla mod topics list

Inviato: 18/04/2011, 21:06
da Micogian
Si può fare con preg_match()

Codice: Seleziona tutto

$sql = "SELECT p.post_text, p.bbcode_uid, t.* FROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t WHERE t.forum_id IN (" . implode(', ', $forums_id) . ") AND p.post_id = t.topic_first_post_id ORDER BY topic_views DESC LIMIT 0," . $max_topic;
$result = $db->sql_query($sql);

$a = $b = 0;

while ($row = $db->sql_fetchrow($result)) {
   if ($auth->acl_get('f_read', $row['forum_id'])) {
      $a++;
      $bbcode_img_to_array = bbcode_img_to_array($row['post_text'], $row['bbcode_uid']);
      $thumb = (isset($bbcode_img_to_array['img'][0]) ? $bbcode_img_to_array['img'][0] : (isset($bbcode_img_to_array['img'][0]) ? $bbcode_img_to_array['img'][0] : $default_image));
      
	  $pattern = "#\[trama](.*?)\[/trama\]#i" ;
	  preg_match($pattern, $row['post_text'], $matches) ;
	  $text_trama = isset($matches[1]) ? $matches[1] : '';
	  
      $template->assign_block_vars('topics_views', array(
         'EVEN'   => (($a % 2 == 0) ? true : false),
         'THUMB'   => $thumb,
         'LINK'   => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=" . $row['forum_id'] . "&t=" . $row['topic_id']),
         'TITLE'   => $row['topic_title'],
         'VIEWS'   => $row['topic_views'],
	 'TRAMA'   => $text_trama
      ));
   }
Lo devi fare su entrambe le query e poi inserire la variabile {TRAMA} nel template.

Re: Aiuto sulla mod topics list

Inviato: 18/04/2011, 21:29
da sport
Non funziona, adesso apre la pagina e non estrarre nessun topic .. in poche parole ho una pagina vuota :(

Come mai?

Re: Aiuto sulla mod topics list

Inviato: 18/04/2011, 22:10
da Micogian
Potrebbe darsi che hai sbagliato qualcosa. Il preg_match() dovrebbe funzionare, se vuoi fai questa prova:
crea un file prova_trama.php con il seguente contenuto

Codice: Seleziona tutto

<?php
$row['post_text'] = "Prova di testo che contiene una trama [trama]contenuto della trama[/trama] nel testo del post.";
     $pattern = "#\[trama](.*?)\[/trama\]#i" ;
     preg_match($pattern, $row['post_text'], $matches) ;
     $text_trama = isset($matches[1]) ? $matches[1] : '';
	 
	 echo "Post_text: " . $row['post_text'] . "<br />";
	 echo "risultato: " . $text_trama . "<br />";
?>
Mettilo nel server, provalo e vedi il risultato.
Il resto dipende da come è stata fatta la modifica. Ci può essere un errore nel php ma anche nel template.
Al limite la variabile {TRAMA} potrebbere essere vuota ma questo non influisce sul resto della pagina.

Re: Aiuto sulla mod topics list

Inviato: 18/04/2011, 22:41
da sport
Infatti, avevi ragione. Adesso mi visualizza solo la scritta "Trama:" e non il contenuto scritto nel bbcode; nonostante ci siano topic con il bbcode trama nei primi post. Credo di aver sbgliato nel template..

Dove modifico?

... il template lo postato nel secondo post

Re: Aiuto sulla mod topics list

Inviato: 18/04/2011, 22:52
da Micogian
Questo dipende da come e dove vuoi visualizzare il testo.
Le variabili da inserire nel template sono {topics_views.TRAMA} e {topics_time.TRAMA}