ho incrociato 2 Mod per tirare fuori una tabella a 3 settori da inserire nella home del mio forum che fa vedere:
nella 1: gli ultimi 10 argomenti scritti,
nella 2: 10 utenti più attivi ( questi due presi dalla mod TOP_FIVE, modificata un pochino per portarla a 10)
nella 3: 10 argomenti più visti (questa è una MOD sviluppata da Carlino e modificata da Bingo)... tutto funziona e si vede, e ciò mi fa molto contento perchè finalmente inizio a capire come è strutturato phpbb e come si muove.
Ho però un arcano da proporre:
Le cose non combaciano proprio, in quanto la MOD TOP FIVE lavora tenendo conto dei permessi dell'utente in quanto ogni utente vede gli ultimi 10 messaggi scritti in base ai suoi permessi ( e ne vede sempre e comunque 10); con la MOD di Carlino l'utente vede i 10 messaggi più visti in assoluto MENO i messaggi che non può vedere...in pratica un utente con meno privilegi dell'amministratore ne vede ad esempio soltanto 6 di messaggi, vede i 6 messaggi più visti in assoluto in base ai suoi permessi e non i primi 10 messaggi in base ai suoi peressi (l'amministratore cioè io ne vedo invece 10)....non so se mi sono spiegato, spero di si!
Provo a postare i due diversi codici php:
Questo è il codice php dela MOd TOP FIVE (da me mdificata in TOP TEN) con query ULTIMI 10 TOPIC, gli ultimi 10 utenti registrati (anche se è ancora scritta io non l'ho ustata) e i PRIMI 10 UTENTI ATTIVI :
Codice: Seleziona tutto
/**
*
* @package phpBB3
* @version $Id: top_five.php,v 1.0.5 2009/08/17 06:20:00 EST rmcgirr83 Exp $
* @copyright (c) 2009 Rich McGirr
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Include only once.
*/
if (!defined('INCLUDES_TOP_FIVE_PHP'))
{
define('INCLUDES_TOP_FIVE_PHP', true);
global $auth, $cache, $config, $user, $db, $phpbb_root_path, $phpEx, $template;
$user->add_lang('mods/top_five');
// grab auths that allow a user to read a forum
$forum_array = array_unique(array_keys($auth->acl_getf('!f_read', true)));
// we have auths, change the sql query below
$sql_and = '';
if (sizeof($forum_array))
{
$sql_and = ' AND ' . $db->sql_in_set('p.forum_id', $forum_array, true);
}
// grab all posts that meet criteria and auths
$sql_ary = array(
'SELECT' => 'MAX(p.post_time) as post_time, u.user_id, u.username, u.user_colour, t.topic_title, t.forum_id, t.topic_last_post_id',
'FROM' => array(TOPICS_TABLE => 't', POSTS_TABLE => 'p'),
'LEFT_JOIN' => array(
array(
'FROM' => array(USERS_TABLE => 'u'),
'ON' => 'p.poster_id = u.user_id',
),
),
'WHERE' => 'p.topic_id = t.topic_id
AND p.post_approved = 1
AND t.topic_moved_id = 0' . $sql_and,
'GROUP_BY' => 't.topic_id',
'ORDER_BY' => 'post_time DESC',
);
$result = $db->sql_query_limit($db->sql_build_query('SELECT', $sql_ary), 5);
while( $row = $db->sql_fetchrow($result) )
{
$view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&p=' . $row['topic_last_post_id'] . '#p' . $row['topic_last_post_id']);
$topic_title = censor_text($row['topic_title']);
$template->assign_block_vars('top_five_topic',array(
'U_TOPIC' => $view_topic_url,
'USERNAME_FULL' => $user->lang['BY'] . ' ' . get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
'TOPIC_TITLE' => $user->lang['IN'] . ' ' . $topic_title));
}
$db->sql_freeresult($result);
// an array of user types we dont' bother with
// could add board founder (USER_FOUNDER) if wanted
$ignore_users = array(USER_IGNORE, USER_INACTIVE);
// top five posters
if (($user_posts = $cache->get('_top_five_posters')) === false)
{
$user_posts = array();
// grab users with most posts
$sql = 'SELECT user_id, username, user_colour, user_posts
FROM ' . USERS_TABLE . '
WHERE ' . $db->sql_in_set('user_type', $ignore_users, true) . '
AND user_posts <> 0
ORDER BY user_posts DESC';
$result = $db->sql_query_limit($sql, 5);
while ($row = $db->sql_fetchrow($result))
{
$user_posts[$row['user_id']] = array(
'user_id' => $row['user_id'],
'username' => $row['username'],
'user_colour' => $row['user_colour'],
'user_posts' => $row['user_posts'],
);
}
$db->sql_freeresult($result);
// cache this data for 5 minutes, this improves performance
$cache->put('_top_five_posters', $user_posts, 300);
}
foreach ($user_posts as $row)
{
$username_string = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
$template->assign_block_vars('top_five_active',array(
'S_SEARCH_ACTION' => append_sid("{$phpbb_root_path}search.$phpEx", 'author_id=' . $row['user_id'] . '&sr=posts'),
'POSTS' => $row['user_posts'],
'USERNAME_FULL' => $username_string)
);
}
// newest registered users
if (($newest_users = $cache->get('_top_five_newest_users')) === false)
{
$newest_users = array();
// grab most recent registered users
$sql = 'SELECT user_id, username, user_colour, user_regdate
FROM ' . USERS_TABLE . '
WHERE ' . $db->sql_in_set('user_type', $ignore_users, true) . '
AND user_inactive_reason = 0
ORDER BY user_regdate DESC';
$result = $db->sql_query_limit($sql, 5);
while ($row = $db->sql_fetchrow($result))
{
$newest_users[$row['user_id']] = array(
'user_id' => $row['user_id'],
'username' => $row['username'],
'user_colour' => $row['user_colour'],
'user_regdate' => $row['user_regdate'],
);
}
$db->sql_freeresult($result);
// cache this data for 5 minutes, this improves performance
$cache->put('_top_five_newest_users', $newest_users, 300);
}
foreach ($newest_users as $row)
{
$username_string = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
$template->assign_block_vars('top_five_newest',array(
'REG_DATE' => $user->format_date($row['user_regdate']),
'USERNAME_FULL' => $username_string)
);
}
}
?>Questo invece è il codice della Mod di Carlino (c'è solo il codice php di riferimento alla query dei 10 topics più visti inseriti in index.php in quanto mi seriva soltanto questo) :
Codice: Seleziona tutto
// ----- inizio MOD Ultimi 10 Topics e i 10 topics più visti - Carlino1994 modificata da Bingo 24.01.2010
$sql = "SELECT topic_id, forum_id, topic_title, topic_first_poster_name, topic_views FROM " . TOPICS_TABLE . " ORDER BY topic_views DESC LIMIT 0,10";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
if ($auth->acl_get('f_read', $row['forum_id']) == 1) {
$template->assign_block_vars('topics_view', array(
'VIEW_LINK' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=" . $row['forum_id'] . "&t=" . $row['topic_id']),
'VIEW_TITOLO' => $row['topic_title'],
'VIEW_AUTHOR' => $row['topic_first_poster_name'],
'VIEW_VIEWS' => $row['topic_views']
));
}
}
$db->sql_freeresult($result);
// FINE QUERY 10 TOPICS PIU' VISTI
// ----------------------------------------------Qualcuno è in grado di modificare la query di Carlino (il secondo code) in modo che ogni utente del forum, in base ai suoi permessi, veda comunque i suoi 10 messaggi più visti, proprio come TOP FIVE?
Grazie ciao


