Modificacion en el Info center (Recent posts)

Started by therodolphos, August 24, 2007, 06:22:51 PM

Previous topic - Next topic

therodolphos

Buenas. Mi consulta es la siguiente, quiero generar un nuevo info center que muestre los recent topics (los posts nuevos, en vez de los comentarios nuevos).
Si alguien sabe en que parte del codigo del foro hay que hacer modificaciones o si alguien tiene el codigo ya modificado, se lo voy a agradecer de ante mano :D

camaleon


therodolphos

Finalmente despues de muchas pruebas y error con el codigo fuente del foro, logré lo que queria. Les dejo el codigo por si alguien quiere intentarlo, mejorarlo y armar un mod o lo que sea. Recuerden que es codigo modificado por mi que no tengo ni la mas palida idea de PHP, se programar en otros lenguajes pero PHP no, asi que hagan backup y las criticas del codigo que sean solo constructivas XD.

En el archivo BoardIndex.php (se encuentra en la carpeta Sources del ftp)
Buscan el siguiente codigo:
// Load the most recent post?
if ((!empty($settings['number_recent_posts']) && $settings['number_recent_posts'] == 1) || $settings['show_sp1_info'])
$context['latest_post'] = $most_recent_topic['ref'];

if (!empty($settings['number_recent_posts']) && $settings['number_recent_posts'] > 1)
{
require_once($sourcedir . '/Recent.php');

if (($context['latest_posts'] = cache_get_data('boardindex-latest_posts:' . md5($user_info['query_see_board'] . $user_info['language']), 180)) == null)
{
$context['latest_posts'] = getLastPosts($settings['number_recent_posts']);
cache_put_data('boardindex-latest_posts:' . md5($user_info['query_see_board'] . $user_info['language']), $context['latest_posts'], 180);
}


Y lo reemplazan por:
// Load the most recent post?
if ((!empty($settings['number_recent_posts']) && $settings['number_recent_posts'] == 1) || $settings['show_sp1_info'])
   {$context['latest_post'] = $most_recent_topic['ref'];
   $context['latest_post2'] = $most_recent_topic['ref'];}

if (!empty($settings['number_recent_posts']) && $settings['number_recent_posts'] > 1)
{
require_once($sourcedir . '/Recent.php');

if (($context['latest_posts'] = cache_get_data('boardindex-latest_posts:' . md5($user_info['query_see_board'] . $user_info['language']), 180)) == null)
{
$context['latest_posts'] = getLastTopic($settings['number_recent_posts']);
cache_put_data('boardindex-latest_posts:' . md5($user_info['query_see_board'] . $user_info['language']), $context['latest_posts'], 180);
  $context['latest_posts2'] = getLastPosts($settings['number_recent_posts']);
  cache_put_data('boardindex-latest_posts:' . md5($user_info['query_see_board'] . $user_info['language']), $context['latest_posts'], 180);
    }

// We have to clean up the cached data a bit.
foreach ($context['latest_posts'] as $k => $topics)
{
$context['latest_posts'][$k]['time'] = timeformat($topics['raw_timestamp']);
$context['latest_posts'][$k]['timestamp'] = forum_time(true, $topics['raw_timestamp']);
}
// We have to clean up the cached data a bit.
foreach ($context['latest_posts2'] as $k => $post)
{
$context['latest_posts2'][$k]['time'] = timeformat($post['raw_timestamp']);
$context['latest_posts2'][$k]['timestamp'] = forum_time(true, $post['raw_timestamp']);
}
}


En el archivo Recent.php (tambien en la carpeta Sources)
Despues de la funcion getLastPost (linea 82 aprox) agregan la siguiente funcion:
function getLastTopic($showlatestcount)
{
global $scripturl, $txt, $db_prefix, $user_info, $modSettings, $func;

// Find all the posts.  Newer ones will have higher IDs.  (assuming the last 20 * number are accessable...)
// !!!SLOW This query is now slow, NEEDS to be fixed.  Maybe break into two?
$request = db_query("
SELECT
m.posterTime, m.subject, m.ID_TOPIC, m.ID_MEMBER, m.ID_MSG,
IFNULL(mem.realName, m.posterName) AS posterName, t.numReplies,
t.ID_BOARD, t.ID_FIRST_MSG, b.name AS bName
FROM {$db_prefix}messages AS m, {$db_prefix}topics AS t, {$db_prefix}boards AS b, {$db_prefix}categories AS c
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)
WHERE m.ID_MSG >= " . ($modSettings['maxMsgID'] - 4 * $showlatestcount) . "
AND m.ID_MSG = t.ID_LAST_MSG
AND b.ID_BOARD=t.ID_BOARD
AND c.ID_CAT=b.ID_CAT
AND $user_info[query_see_board]
ORDER BY m.ID_MSG DESC
LIMIT $showlatestcount", __FILE__, __LINE__);
$topics = array();
while ($row = mysql_fetch_assoc($request))
{
// Censor the subject and post for the preview ;).
censorText($row['subject']);
censorText($row['body']);

$row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileysEnabled'], $row['ID_MSG']), array('<br />' => '&#10;')));
if ($func['strlen']($row['body']) > 128)
$row['body'] = $func['substr']($row['body'], 0, 128) . '...';

// Build the array.
$topics[] = array(
'board' => array(
'id' => $row['ID_BOARD'],
'name' => $row['bName'],
'href' => $scripturl . '?board=' . $row['ID_BOARD'] . '.0',
'link' => '<a href="' . $scripturl . '?board=' . $row['ID_BOARD'] . '.0">' . $row['bName'] . '</a>'
),
'topic' => $row['ID_TOPIC'],
'poster' => array(
'id' => $row['ID_MEMBER'],
'name' => $row['posterName'],
'href' => empty($row['ID_MEMBER']) ? '' : $scripturl . '?action=profile;u=' . $row['ID_MEMBER'],
'link' => empty($row['ID_MEMBER']) ? $row['posterName'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['posterName'] . '</a>'
),
'subject' => $row['subject'],
'short_subject' => shorten_subject($row['subject'], 24),
'preview' => $row['body'],
'time' => timeformat($row['posterTime']),
'timestamp' => forum_time(true, $row['posterTime']),
'raw_timestamp' => $row['posterTime'],
'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . ';topicseen#msg' . $row['ID_MSG'],
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . ';topicseen#msg' . $row['ID_MSG'] . '">' . $row['subject'] . '</a>'
);

//The Last Posters id for the MemberColor.
if (!empty($modSettings['MemberColorRecentLastPost']) && !empty($row['ID_MEMBER']))
$MemberColor_ID_MEMBER[$row['ID_MEMBER']] = $row['ID_MEMBER'];
}
mysql_free_result($request);


// Know set the colors for the Recent posts...
if (!empty($MemberColor_ID_MEMBER)) {
//Now i can Load the Missing globals :)
global $user_profile;

loadMemberData($MemberColor_ID_MEMBER);
$cmemcolid = NULL;

//So Let's Color The Recent Posts ;)
if (!empty($modSettings['MemberColorRecentLastPost']))
if (is_array($posts))
foreach($posts as $postkey => $postid_memcolor) {
$cmemcolid = $postid_memcolor['poster']['id'];
$profile = &$user_profile[$cmemcolid];
if(!empty($profile['member_group_color']) || !empty($profile['post_group_color']))
$topics[$postkey]['poster']['link'] = '<a href="' . $scripturl . '?action=profile;u=' . $profile['ID_MEMBER'] . '" title="' . $txt[92] . ' ' . $profile['realName'] . '"><span style="color:'.(!empty($profile['member_group_color']) ? $profile['member_group_color'] : $profile['post_group_color']).';">' . $profile['realName'] . '</span></a>';
}
}

return $topics;
}


En el archivo BoardIndex.template.php (dentro de la carpeta del theme que esten usando)
Buscan el siguiente codigo:
// This is the "Recent Posts" bar.
if (!empty($settings['number_recent_posts']))
{
echo '
<tr>
<td class="titlebg" colspan="2">', $txt[214], '</td>
</tr>
<tr>
<td class="windowbg" width="20" valign="middle" align="center">
<a href="', $scripturl, '?action=recent"><img src="', $settings['images_url'], '/post/xx.gif" alt="', $txt[214], '" /></a>
</td>
<td class="windowbg2">';

// Only show one post.
if ($settings['number_recent_posts'] == 1)
{
// latest_post has link, href, time, subject, short_subject (shortened with...), and topic. (its id.)
echo '
<b><a href="', $scripturl, '?action=recent">', $txt[214], '</a></b>
<div class="smalltext">
', $txt[234], ' &quot;', $context['latest_post']['link'], '&quot; ', $txt[235], ' (', $context['latest_post']['time'], ')<br />
</div>';
}
// Show lots of posts.
elseif (!empty($context['latest_posts']))
{
echo '
<table cellpadding="0" cellspacing="0" width="100%" border="0">';

/* Each post in latest_posts has:
board (with an id, name, and link.), topic (the topic's id.), poster (with id, name, and link.),
subject, short_subject (shortened with...), time, link, and href. */
foreach ($context['latest_posts'] as $post)
echo '
<tr>
<td class="middletext" valign="top"><b>', $post['link'], '</b> ', $txt[525], ' ', $post['poster']['link'], ' (', $post['board']['link'], ')</td>
<td class="middletext" align="right" valign="top" nowrap="nowrap">', $post['time'], '</td>
</tr>';
echo '
</table>';
}
echo '
</td>
</tr>';
}

Y lo reemplazan por:
// Here's where the "Info Center" starts...
echo '<br />
<div class="tborder" ', $context['browser']['needs_size_fix'] && !$context['browser']['is_ie6'] ? 'style="width: 100%;"' : '', '>
<div class="catbg" style="padding: 6px; vertical-align: middle; text-align: center; ">
<a href="#" onclick="shrinkHeaderIC(!current_header_ic); return false;"><img id="upshrink_ic" src="', $settings['images_url'], '/', empty($options['collapse_header_ic']) ? 'collapse.gif' : 'expand.gif', '" alt="*" title="', $txt['upshrink_description'], '" style="margin-right: 2ex;" align="right" /></a>
', $txt[685], '
</div>
<div id="upshrinkHeaderIC"', empty($options['collapse_header_ic']) ? '' : ' style="display: none;"', '>
<table border="0" width="100%" cellspacing="1" cellpadding="4" class="bordercolor">';

// This is the "Recent Posts" bar.
if (!empty($settings['number_recent_posts']))
{
echo '
<tr>
<td class="titlebg" colspan="2">', $txt[214], '</td>
</tr>
<tr>
<td class="windowbg" width="20" valign="middle" align="center">
<a href="', $scripturl, '?action=recent"><img src="', $settings['images_url'], '/post/xx.gif" alt="', $txt[214], '" /></a>
</td>
<td class="windowbg2">';

// Only show one post.
if ($settings['number_recent_posts'] == 1)
{
// latest_post has link, href, time, subject, short_subject (shortened with...), and topic. (its id.)
echo '
<b><a href="', $scripturl, '?action=recent">', $txt[214], '</a></b>
<div class="smalltext">
', $txt[234], ' &quot;', $context['latest_post']['link'], '&quot; ', $txt[235], ' (', $context['latest_post']['time'], ')<br />
</div>';
}
// Show lots of posts.
elseif (!empty($context['latest_posts2']))
{
echo '
<table cellpadding="0" cellspacing="0" width="100%" border="0">';

// Each post in latest_posts has:
// board (with an id, name, and link.), topic (the topic's id.), poster (with id, name, and link.),
// subject, short_subject (shortened with...), time, link, and href.
foreach ($context['latest_posts2'] as $topics)
echo '
<tr>
<td class="middletext" valign="top"><b>', $topics['link'], '</b> ', $txt[525], ' ', $topics['poster']['link'], ' (', $topics['board']['link'], ')</td>
<td class="middletext" align="right" valign="top" nowrap="nowrap">', $topics['time'], '</td>
</tr>';
echo '
</table>';
}
echo '
</td>
</tr>';
}
 
  if (!empty($settings['number_recent_posts']))
{

echo '
<tr>
<td class="titlebg" colspan="2">', $txt[215], '</td>
</tr>
<tr>
<td class="windowbg" width="20" valign="middle" align="center">
</td>
<td class="windowbg2">';

// Only show one post.
if ($settings['number_recent_posts'] == 1)
{
// latest_post has link, href, time, subject, short_subject (shortened with...), and topic. (its id.)
echo '
<b><a href="', $scripturl, '?action=recent">', $txt[214], '</a></b>
<div class="smalltext">
', $txt[234], ' &quot;', $context['latest_post']['link'], '&quot; ', $txt[235], ' (', $context['latest_post']['time'], ')<br />
</div>';
}
// Show lots of posts.
elseif (!empty($context['latest_posts']))
{
echo '
<table cellpadding="0" cellspacing="0" width="100%" border="0">';

/* Each post in latest_posts has:
board (with an id, name, and link.), topic (the topic's id.), poster (with id, name, and link.),
subject, short_subject (shortened with...), time, link, and href. */
foreach ($context['latest_posts'] as $post)
echo '
<tr>
<td class="middletext" valign="top"><b>', $post['link'], '</b> ', $txt[525], ' ', $post['poster']['link'], ' (', $post['board']['link'], ')</td>
<td class="middletext" align="right" valign="top" nowrap="nowrap">', $post['time'], '</td>
</tr>';
echo '
</table>';
}
echo '
</td>
</tr>';
}

Finalmente en el archivo index.english.php (se encuentra en la carpeta languages en la carpeta del theme default)
Buscan la siguiente linea:
$txt[214] = 'Recent Posts';
Y abajo le agregan:
$txt[215] = 'Recent Topics';

Con eso ya les queda un info center como este:


Codigo modificado por FalsoProfeta para The Adolphos Foro :D

Obviamente alguien que sepa PHP puede mejorar mucho el codigo, pero por lo menos anda y hace lo que pretendiamos que hiciera.


Advertisement: