Autor Tópico: Estatísticas Top 10 para Smf 2.0rc1 ate 2.x  (Lida 9435 vezes)

0 Membros e 1 Visitante estão a ver este tópico.

Offline candidosa2

  • Suporte Tecnico
  • Fundador
  • *
  • Mensagens: 5073
  • Rank: 1658
  • Sexo: Masculino
  • Suporte
    • Hosting Moçambique
Estatísticas Top 10 para Smf 2.0rc1 ate 2.x
« em: 08 de Março de 2009, 09:56 »
Mod Name:  Top Stats
Created By:  Fovist
Type:  New Feature
Latest Version:    1.0
Compatible With:   2.0 RC1
Mod Link:http://custom.simplemachines.org/mods/index.php?mod=1687






Sources/BoardIndex.php

Pesquisar
Código: [Seleccione]
loadTemplate('BoardIndex', 'forum');
Substituir por
Código: [Seleccione]
loadTemplate('BoardIndex', 'forum');
      TopStats();


Pesquisar
Código: [Seleccione]
?>
Colocar este codigo antes

Código: [Seleccione]
// TopStats by gorselsanatlar.org
function TopStats()
{
   global $context, $smcFunc, $txt, $db_prefix, $scripturl, $modSettings;
         // Newest members top 10
   $members_result =  $smcFunc['db_query']('', '
      SELECT id_member, real_name, posts
      FROM {db_prefix}members
      ORDER BY id_member DESC
      LIMIT 10',
      array(
      )
   );
   $context['new_members'] = array();
   while ($row_members = $smcFunc['db_fetch_assoc']($members_result))
   {
      $context['new_members'][] = array(
         'name' => $row_members['real_name'],
         'id' => $row_members['id_member'],
         'href' => $scripturl . '?action=profile;u=' . $row_members['id_member'],
         'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_members['id_member'] . '">' . $row_members['real_name'] . '</a>'
      );
   }
   $smcFunc['db_free_result']($members_result);
   //// Newest members top 10 Finish
    // Poster top 10.
   $members_result = $smcFunc['db_query']('', '
      SELECT id_member, real_name, posts
      FROM {db_prefix}members
      WHERE posts > {int:no_posts}
      ORDER BY posts DESC
      LIMIT 10',
      array(
         'no_posts' => 0,
      )
   );
   $context['top_posters'] = array();
   $max_num_posts = 1;
   $context['MemberColor_ID_MEMBER'] = array();
   while ($row_members = $smcFunc['db_fetch_assoc']($members_result))
   {
      $context['top_posters'][] = array(
         'name' => $row_members['real_name'],
         'id' => $row_members['id_member'],
         'num_posts' => $row_members['posts'],
         'href' => $scripturl . '?action=profile;u=' . $row_members['id_member'],
         'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_members['id_member'] . '">' . $row_members['real_name'] . '</a>'
      );

      if ($max_num_posts < $row_members['posts'])
         $max_num_posts = $row_members['posts'];
      if (!empty($modSettings['MemberColorStats']) && !empty($row_members['id_member']))
         $context['MemberColor_ID_MEMBER'][$row_members['id_member']] = $row_members['id_member'];
   }
   $smcFunc['db_free_result']($members_result);

   foreach ($context['top_posters'] as $i => $poster)
   {
      $context['top_posters'][$i]['post_percent'] = round(($poster['num_posts'] * 100) / $max_num_posts);
      $context['top_posters'][$i]['num_posts'] = comma_format($context['top_posters'][$i]['num_posts']);
   }

   // Board top 10.
   $boards_result = $smcFunc['db_query']('', '
      SELECT id_board, name, num_posts
      FROM {db_prefix}boards AS b
      WHERE {query_see_board}' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
         AND b.id_board != {int:recycle_board}' : '') . '
         AND b.redirect = {string:blank_redirect}
      ORDER BY num_posts DESC
      LIMIT 10',
      array(
         'recycle_board' => $modSettings['recycle_board'],
         'blank_redirect' => '',
      )
   );
   $context['top_boards'] = array();
   $max_num_posts = 1;
   while ($row_board = $smcFunc['db_fetch_assoc']($boards_result))
   {
      $context['top_boards'][] = array(
         'id' => $row_board['id_board'],
         'name' => $row_board['name'],
         'num_posts' => $row_board['num_posts'],
         'href' => $scripturl . '?board=' . $row_board['id_board'] . '.0',
         'link' => '<a href="' . $scripturl . '?board=' . $row_board['id_board'] . '.0">' . $row_board['name'] . '</a>'
      );

      if ($max_num_posts < $row_board['num_posts'])
         $max_num_posts = $row_board['num_posts'];
   }
   $smcFunc['db_free_result']($boards_result);

   foreach ($context['top_boards'] as $i => $board)
   {
      $context['top_boards'][$i]['post_percent'] = round(($board['num_posts'] * 100) / $max_num_posts);
      $context['top_boards'][$i]['num_posts'] = comma_format($context['top_boards'][$i]['num_posts']);
   }
      // Are you on a larger forum?  If so, let's try to limit the number of topics we search through.
   if ($modSettings['totalMessages'] > 100000)
   {
      $request = $smcFunc['db_query']('', '
         SELECT id_topic
         FROM {db_prefix}topics
         WHERE num_replies != {int:no_replies}' . ($modSettings['postmod_active'] ? '
            AND approved = {int:is_approved}' : '') . '
         ORDER BY num_replies DESC
         LIMIT 100',
         array(
            'no_replies' => 0,
            'is_approved' => 1,
         )
      );
      $topic_ids = array();
      while ($row = $smcFunc['db_fetch_assoc']($request))
         $topic_ids[] = $row['id_topic'];
      $smcFunc['db_free_result']($request);
   }
   else
      $topic_ids = array();
   // Topic views top 10.
   $topic_view_result = $smcFunc['db_query']('', '
      SELECT m.subject, t.num_views, t.id_board, t.id_topic, b.name
      FROM {db_prefix}topics AS t
         INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
         INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
         AND b.id_board != {int:recycle_board}' : '') . ')
      WHERE {query_see_board}' . (!empty($topic_ids) ? '
         AND t.id_topic IN ({array_int:topic_list})' : ($modSettings['postmod_active'] ? '
         AND t.approved = {int:is_approved}' : '')) . '
      ORDER BY t.num_views DESC
      LIMIT 10',
      array(
         'topic_list' => $topic_ids,
         'recycle_board' => $modSettings['recycle_board'],
         'is_approved' => 1,
      )
   );
   $context['top_topics_views'] = array();
   $max_num_views = 1;
   while ($row_topic_views = $smcFunc['db_fetch_assoc']($topic_view_result))
   {
      censorText($row_topic_views['subject']);
$row_topic_views['subject'] = shorten_subject($row_topic_views['subject'], 20);
      $context['top_topics_views'][] = array(
         'id' => $row_topic_views['id_topic'],
         'board' => array(
            'id' => $row_topic_views['id_board'],
            'name' => $row_topic_views['name'],
            'href' => $scripturl . '?board=' . $row_topic_views['id_board'] . '.0',
            'link' => '<a href="' . $scripturl . '?board=' . $row_topic_views['id_board'] . '.0">' . $row_topic_views['name'] . '</a>'
         ),
         'subject' => $row_topic_views['subject'],
         'num_views' => $row_topic_views['num_views'],
         'href' => $scripturl . '?topic=' . $row_topic_views['id_topic'] . '.0',
         'link' => '<a href="' . $scripturl . '?topic=' . $row_topic_views['id_topic'] . '.0">' . $row_topic_views['subject'] . '</a>'
      );

      if ($max_num_views < $row_topic_views['num_views'])
         $max_num_views = $row_topic_views['num_views'];
   }
   $smcFunc['db_free_result']($topic_view_result);

   foreach ($context['top_topics_views'] as $i => $topic)
   {
      $context['top_topics_views'][$i]['post_percent'] = round(($topic['num_views'] * 100) / $max_num_views);
      $context['top_topics_views'][$i]['num_views'] = comma_format($context['top_topics_views'][$i]['num_views']);
   }

   // Try to cache this when possible, because it's a little unavoidably slow.
   if (($members = cache_get_data('stats_top_starters', 360)) == null)
   {
      $request = $smcFunc['db_query']('', '
         SELECT id_member_started, COUNT(*) AS hits
         FROM {db_prefix}topics' . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
         WHERE id_board != {int:recycle_board}' : '') . '
         GROUP BY id_member_started
         ORDER BY hits DESC
         LIMIT 10',
         array(
            'recycle_board' => $modSettings['recycle_board'],
         )
      );
      $members = array();
      while ($row = $smcFunc['db_fetch_assoc']($request))
         $members[$row['id_member_started']] = $row['hits'];
      $smcFunc['db_free_result']($request);

      cache_put_data('stats_top_starters', $members, 360);
   }

   if (empty($members))
      $members = array(0 => 0);

   // Topic poster top 10.
   $members_result = $smcFunc['db_query']('', '
      SELECT id_member, real_name
      FROM {db_prefix}members
      WHERE id_member IN ({array_int:member_list})
      ORDER BY FIND_IN_SET(id_member, {string:top_topic_posters})
      LIMIT 10',
      array(
         'member_list' => array_keys($members),
         'top_topic_posters' => implode(',', array_keys($members)),
      )
   );
   $context['top_starters'] = array();
   $max_num_topics = 1;
   while ($row_members = $smcFunc['db_fetch_assoc']($members_result))
   {
      $context['top_starters'][] = array(
         'name' => $row_members['real_name'],
         'id' => $row_members['id_member'],
         'num_topics' => $members[$row_members['id_member']],
         'href' => $scripturl . '?action=profile;u=' . $row_members['id_member'],
         'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_members['id_member'] . '">' . $row_members['real_name'] . '</a>'
      );

      if ($max_num_topics < $members[$row_members['id_member']])
         $max_num_topics = $members[$row_members['id_member']];
      if (!empty($modSettings['MemberColorStats']))
         $context['MemberColor_ID_MEMBER'][$row_members['id_member']] = $row_members['id_member'];
   }
   $smcFunc['db_free_result']($members_result);

   foreach ($context['top_starters'] as $i => $topic)
   {
      $context['top_starters'][$i]['post_percent'] = round(($topic['num_topics'] * 100) / $max_num_topics);
      $context['top_starters'][$i]['num_topics'] = comma_format($context['top_starters'][$i]['num_topics']);
   }
   
   //Yeah baby give me some colors =).
   if (!empty($modSettings['MemberColorLinkInstalled']) && !empty($context['MemberColor_ID_MEMBER'])) {
      $colorDatas = load_onlineColors($context['MemberColor_ID_MEMBER']);
      $cmemcolid = null;
      if (!empty($modSettings['MemberColorStats'])) {
         // First the Top Posters =)
         foreach($context['top_posters'] as $key => $value) {
            $cmemcolid = $context['top_posters'][$key]['id'];
            if(!empty($colorDatas[$cmemcolid]['colored_link']))
               $context['top_posters'][$key]['link'] = $colorDatas[$cmemcolid]['colored_link'];
         }
         // First the Top Starter =)     
         foreach($context['top_starters'] as $key => $value) {
            $cmemcolid = $context['top_starters'][$key]['id'];
            if(!empty($colorDatas[$cmemcolid]['colored_link']))
               $context['top_starters'][$key]['link'] = $colorDatas[$cmemcolid]['colored_link'];
         }
      }
      if (!empty($modSettings['latestMember']) && !empty($modSettings['MemberColorLatestMember'])) {
         if(!empty($colorDatas[$modSettings['latestMember']]['colored_link']))
            $context['latest_member']['link'] = $colorDatas[$modSettings['latestMember']]['colored_link'];
      }
   }
}


./Themes/default/BoardIndex.template.php

Pesquisar remover


Código: [Seleccione]
// This is the "Recent Posts" bar.
   if (!empty($settings['number_recent_posts']))
   {
      echo '
         <div class="infocenter_section">
            <h4 class="headerpadding titlebg">', $txt['recent_posts'], '</h4>
            <div class="windowbg">
               <p class="section">
                  <a href="', $scripturl, '?action=recent"><img src="', $settings['images_url'], '/post/xx.gif" alt="', $txt['recent_posts'], '" /></a>
               </p>
               <div class="windowbg2 sectionbody hslice clearfix" id="recent_posts_content"><div class="entry-title" style="display: none;">', $context['forum_name_html_safe'], ' - ', $txt['recent_posts'], '<><div class="entry-content" style="display: none;"><a rel="feedurl" href="', $scripturl, '?action=.xml;type=webslice">', $txt['subscribe_webslice'], '</a><>';

      // 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 '
                  <strong><a href="', $scripturl, '?action=recent">', $txt['recent_posts'], '</a></strong>
                  <p id="infocenter_onepost" class="smalltext">
                        ', $txt['recent_view'], ' &quot;', $context['latest_post']['link'], '&quot; ', $txt['recent_updated'], ' (', $context['latest_post']['time'], ')<br />
                  </p>';
      }
      // Show lots of posts.
      elseif (!empty($context['latest_posts']))
      {
         echo '
                  <dl id="infocenter_recentposts" class="middletext">';

         /* 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 '
                     <dt><strong>', $post['link'], '</strong> ', $txt['by'], ' ', $post['poster']['link'], ' (', $post['board']['link'], ')</dt>
                     <dd>', $post['time'], '</dd>';
         echo '
                  </dl>';
      }
      echo '
               <>
            <>
         <>';
   }

Pesquisar
Código: [Seleccione]
template_info_center();

trocar por este
Código: [Seleccione]
//top stats start. by gorselsanatlar.org
   loadLanguage('Stats');
  echo '
  <table border="0" width="100%" cellspacing="1" cellpadding="2" class="categoryframe tborder">
    <tr>
        <td class="catbg" height="25" width="100%" colspan="8" align="center">', $txt['forum_stats'], '</td>
    </tr>
    <tr>
        <td class="titlebg" width="20%" colspan="2" align="center">', $txt['new'] ,' ', $txt['members_title'], '</td>
        <td class="titlebg" width="24%" colspan="2" align="center">', $txt['top_topics_views'], '</td>
        <td class="titlebg" width="56%" colspan="3" align="center">', $txt['recent_posts'], '</td>
    </tr>
    <tr>
        <td class="windowbg2" width="20%" colspan="2" valign="top"><span class="smalltext"><b>', $txt['user'], '</b></span><br />';
                  foreach ($context['new_members'] as $poster)
        {
         echo '
         <img alt="" src="', $settings['images_url'], '/icons/online.gif', '" width="12" height="12" />
        <span class="smalltext">',$poster['link'], '</span><br />';
        }
        echo '
        </td>
        <td class="windowbg2" width="18%" valign="top"><span class="smalltext"><b>', $txt['board_topics'], '</b></span><br />';
            foreach ($context['top_topics_views'] as $topic)
        echo '
        <img alt="" src="', $settings['images_url'], '/email_sm.gif', '" width="12" />
        <span class="smalltext">', $topic['link'], '</span><br />';   
        echo '</td>
        <td class="windowbg2" width="6%" align="right" valign="top"><span class="smalltext"><b>', $txt['views'] ,'</b></span><br />';
            foreach ($context['top_topics_views'] as $topic)
        echo '
        <img alt="" src="', $settings['images_url'], '/icons/field_valid.gif" height="12" />       
        <span class="smalltext">', $topic['num_views'], '</span><br />';
        echo '</td>
        <td class="windowbg2" width="20%" rowspan="3" valign="top"><span class="smalltext"><b>', $txt['board_topics'], '</b></span><br />';
            if (!empty($context['latest_posts']))
            foreach ($context['latest_posts'] as $post)
        echo '
        <img src="', $settings['images_url'], '/email_sm.gif', '" width="12" alt="" />
        <span class="smalltext"><a href="',$post['href'],'">', $post['short_subject'], '</a></span><br />';
        echo '</td>
        <td class="windowbg2" width="17%" rowspan="3" valign="top"><span class="smalltext"><b>', $txt['author'] ,'</b></span><br />';
            if (!empty($context['latest_posts']))
            foreach ($context['latest_posts'] as $post)
        echo '
        <img alt="" src="', $settings['images_url'], '/icons/online.gif', '" width="12" height="12" />
        <span class="smalltext">', $post['poster']['link'], '</span><br />';
        echo'
        </td>
        <td class="windowbg2" width="19%" rowspan="3" valign="top"><span class="smalltext"><b>', $txt['date'] ,'</b></span><br />';
            if (!empty($context['latest_posts']))
            foreach ($context['latest_posts'] as $post)
            echo '
            <img alt="" src="', $settings['images_url'], '/icons/calendar.gif', '" width="12" />
            <span class="smalltext">', $post['time'], '</span><br />';
        echo '</td>
    </tr>
    <tr>
        <td class="titlebg" width="20%" colspan="2" align="center">', $txt['top_posters'], '</td>
        <td class="titlebg" width="24%" colspan="2" align="center">', $txt['top_starters'], '</td>
    </tr>
    <tr>
        <td class="windowbg2" width="14%" valign="top"><span class="smalltext"><b>', $txt['user'], '</b></span><br />';
            foreach ($context['top_posters'] as $poster)
        echo '
      <img alt="" src="', $settings['images_url'], '/icons/online.gif', '" width="12" height="12" />
        <span class="smalltext">', $poster['link'], '</span><br />';
        echo '</td>
        <td class="windowbg2" valign="top" align="right" width="6%"><span class="smalltext"><b>', $txt['posts'], '</b></span><br />';
            foreach ($context['top_posters'] as $poster)   
        echo '
        <img alt="" src="', $settings['images_url'], '/icons/field_valid.gif" height="12" /> 
        <span class="smalltext">', $poster['num_posts'], '</span><br />';
        echo '</td>
        <td class="windowbg2" valign="top" width="18%"><span class="smalltext"><b>', $txt['user'], '</b></span><br />';
            foreach ($context['top_starters'] as $poster)
        echo '
        <img alt="" src="', $settings['images_url'], '/icons/online.gif', '" width="12" height="12" />
        <span class="smalltext">', $poster['link'], '</span><br />';
        echo '</td>
        <td class="windowbg2" valign="top" align="right" width="6%"><span class="smalltext"><b>', $txt['board_topics'], '</b></span><br />';
           foreach ($context['top_starters'] as $poster)
        echo '
        <img alt="" src="', $settings['images_url'], '/icons/field_valid.gif" height="12" />   
        <span class="smalltext">', $poster['num_topics'], '</span><br />';
        echo '</td>
    </tr>
</table><br />';
   
    //top stats finish. by gorselsanatlar.org
 
   template_info_center();
« Última modificação: 25 de Agosto de 2013, 18:26 por candidosa2 »