Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Allows users to to rate posts
- *
- * @copyright Copyright (C) 2009 crurf.info
- * @license http://creativecommons.org/licenses/by-sa/3.0/ Creative Commons License version 3.0 or higher
- * @package ajax_rating
- */
- define('FORUM_SKIP_CSRF_CONFIRM', 1);
- if (!defined('FORUM_ROOT'))
- define('FORUM_ROOT', './');
- require FORUM_ROOT.'include/common.php';
- include_once FORUM_ROOT . '/extensions/ajax_rating/fns.php';
- if (!$lang_ajax_rating) {
- if (file_exists(FORUM_ROOT . '/extensions/ajax_rating/lang/' . $forum_user['language'] . '/ajax_rating2.php'))
- include_once FORUM_ROOT . '/extensions/ajax_rating/lang/' . $forum_user['language'] . '/ajax_rating2.php';
- else
- include_once FORUM_ROOT . '/extensions/ajax_rating/lang/English/ajax_rating2.php';
- }
- // Load the viewtopic.php language file
- require FORUM_ROOT.'lang/'.$forum_user['language'].'/topic.php';
- $type = isset($_GET['type']) ? intval($_GET['type']) : 0;
- $tab = isset($_GET['tab']) ? intval($_GET['tab']) : 0;
- if (!in_array($type, array(0,1))) $type = 0;
- if (!in_array($tab, array(0,1,2))) $tab = 0;
- $curtime = mktime();
- $period = 24 * 60 * 60;
- switch ($tab) {
- case 1:
- $period = 7 * 24 * 60 * 60;
- break;
- case 2:
- $period = 30 * 24 * 60 * 60;
- break;
- }
- $forum_page['item_count'] = 0; // Keep track of post numbers
- // Retrieve the posts (and their respective poster/online status)
- $query = array(
- 'SELECT' => 'a.rate, t.subject as topicsubj, p.topic_id, u.email, u.title, u.url, u.location, u.signature, u.email_setting, u.num_posts, u.registered, u.admin_note, p.id, p.poster AS username, p.poster_id, p.poster_ip, p.poster_email, p.message, p.hide_smilies, p.posted, p.edited, p.edited_by, g.g_id, g.g_user_title, o.user_id AS is_online',
- 'FROM' => '(
- SELECT ((sum(pd.rating) * 100) / count(*)) as rate, pd.postid
- FROM ' . $forum_db->prefix . 'postrating_det AS pd
- WHERE pd.tstamp <= ' . $curtime . ' AND pd.tstamp >= ' . ($curtime - $period) . '
- GROUP BY pd.postid
- ) AS a',
- 'JOINS' => array(
- array(
- 'INNER JOIN' => $forum_db->prefix . 'posts AS p',
- 'ON' => 'p.id=a.postid'
- ),
- array(
- 'INNER JOIN' => $forum_db->prefix . 'topics AS t',
- 'ON' => 'p.topic_id=t.id'
- ),
- array(
- 'INNER JOIN' => $forum_db->prefix . 'users AS u',
- 'ON' => 'u.id=p.poster_id'
- ),
- array(
- 'INNER JOIN' => $forum_db->prefix . 'groups AS g',
- 'ON' => 'g.g_id=u.group_id'
- ),
- array(
- 'LEFT JOIN' => $forum_db->prefix . 'online AS o',
- 'ON' => '(o.user_id=u.id AND o.user_id!=1 AND o.idle=0)'
- ),
- ),
- 'ORDER BY' => 'a.rate ' . ($type == 1 ? 'ASC' : 'DESC'),
- 'LIMIT' => 5,
- 'PARAMS' => array('NO_PREFIX' => 1)
- );
- $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
- if (!$forum_db->num_rows($result)) {
- message($lang_common['Bad request']);
- } else {
- define('FORUM_PAGE', 'toprated');
- require FORUM_ROOT.'header.php';
- // START SUBST - <!-- forum_main -->
- ob_start();
- ?>
- <div class="admin-menu gen-content">
- <ul>
- <li class="<?php echo ($type == 0 ? 'active ' : ''); ?>first-item"><a href="?type=0&tab=<? echo $tab; ?>"><span><?php echo $lang_ajax_rating['Best']; ?></span></a></li>
- <li class="<?php echo ($type == 1 ? 'active ' : ''); ?>normal"><a href="?type=1&tab=<? echo $tab; ?>"><span><?php echo $lang_ajax_rating['Worst']; ?></span></a></li>
- </ul>
- </div>
- <div class="admin-submenu gen-content">
- <ul>
- <li class="<?php echo ($tab == 0 ? 'active ' : ''); ?>first-item"><a href="?type=<? echo $type; ?>&tab=0"><span><?php echo $lang_ajax_rating['Last day']; ?></span></a></li>
- <li class="<?php echo ($tab == 1 ? 'active ' : ''); ?>normal"><a href="?type=<? echo $type; ?>&tab=1"><span><?php echo $lang_ajax_rating['Last week']; ?></span></a></li>
- <li class="<?php echo ($tab == 2 ? 'active ' : ''); ?>normal"><a href="?type=<? echo $type; ?>&tab=2"><span><?php echo $lang_ajax_rating['Last month']; ?></span></a></li>
- </ul>
- </div>
- <div class="main-content main-topic" id="forum1">
- <?php
- while ($cur_post = $forum_db->fetch_assoc($result)) {
- ++$forum_page['item_count'];
- $forum_page['post_ident'] = array();
- $forum_page['author_ident'] = array();
- $forum_page['author_info'] = array();
- $forum_page['post_options'] = array();
- $forum_page['post_contacts'] = array();
- $forum_page['post_actions'] = array();
- $forum_page['message'] = array();
- // Generate the post heading
- $forum_page['post_ident']['num'] = '<span class="post-num">'.forum_number_format($forum_page['start_from'] + $forum_page['item_count']).'</span>';
- if ($cur_post['poster_id'] > 1)
- $forum_page['post_ident']['byline'] = '<span class="post-byline">'.sprintf((($cur_post['id'] == $cur_topic['first_post_id']) ? $lang_topic['Topic byline'] : $lang_topic['Reply byline']), (($forum_user['g_view_users'] == '1') ? '<a title="'.sprintf($lang_topic['Go to profile'], forum_htmlencode($cur_post['username'])).'" href="'.forum_link($forum_url['user'], $cur_post['poster_id']).'">'.forum_htmlencode($cur_post['username']).'</a>' : '<strong>'.forum_htmlencode($cur_post['username']).'</strong>')).'</span>';
- else
- $forum_page['post_ident']['byline'] = '<span class="post-byline">'.sprintf((($cur_post['id'] == $cur_topic['first_post_id']) ? $lang_topic['Topic byline'] : $lang_topic['Reply byline']), '<strong>'.forum_htmlencode($cur_post['username']).'</strong>').'</span>';
- $forum_page['post_ident']['link'] = '<span class="post-link"><a class="permalink" href="'.forum_link($forum_url['topic'], $cur_post['topic_id']).'"><b>'. $cur_post['topicsubj'] .'</b></a> - <a class="permalink" rel="bookmark" title="'.$lang_topic['Permalink post'].'" href="'.forum_link($forum_url['post'], $cur_post['id']).'">'.format_time($cur_post['posted']).'</a></span>';
- ($hook = get_hook('vt_row_pre_post_ident_merge')) ? eval($hook) : null;
- if (isset($user_data_cache[$cur_post['poster_id']]['author_ident']))
- $forum_page['author_ident'] = $user_data_cache[$cur_post['poster_id']]['author_ident'];
- else
- {
- // Generate author identification
- if ($cur_post['poster_id'] > 1)
- {
- if ($forum_config['o_avatars'] == '1' && $forum_user['show_avatars'] != '0')
- {
- $forum_page['avatar_markup'] = generate_avatar_markup($cur_post['poster_id']);
- if (!empty($forum_page['avatar_markup']))
- $forum_page['author_ident']['avatar'] = '<li class="useravatar">'.$forum_page['avatar_markup'].'</li>';
- }
- $forum_page['author_ident']['username'] = '<li class="username">'.(($forum_user['g_view_users'] == '1') ? '<a title="'.sprintf($lang_topic['Go to profile'], forum_htmlencode($cur_post['username'])).'" href="'.forum_link($forum_url['user'], $cur_post['poster_id']).'">'.forum_htmlencode($cur_post['username']).'</a>' : '<strong>'.forum_htmlencode($cur_post['username']).'</strong>').'</li>';
- $forum_page['author_ident']['usertitle'] = '<li class="usertitle"><span>'.get_title($cur_post).'</span></li>';
- if ($cur_post['is_online'] == $cur_post['poster_id'])
- $forum_page['author_ident']['status'] = '<li class="userstatus"><span>'.$lang_topic['Online'].'</span></li>';
- else
- $forum_page['author_ident']['status'] = '<li class="userstatus"><span>'.$lang_topic['Offline'].'</span></li>';
- }
- else
- {
- $forum_page['author_ident']['username'] = '<li class="username"><strong>'.forum_htmlencode($cur_post['username']).'</strong></li>';
- $forum_page['author_ident']['usertitle'] = '<li class="usertitle"><span>'.get_title($cur_post).'</span></li>';
- }
- }
- if (isset($user_data_cache[$cur_post['poster_id']]['author_info']))
- $forum_page['author_info'] = $user_data_cache[$cur_post['poster_id']]['author_info'];
- else
- {
- // Generate author information
- if ($cur_post['poster_id'] > 1)
- {
- if ($forum_config['o_show_user_info'] == '1')
- {
- if ($cur_post['location'] != '')
- {
- if ($forum_config['o_censoring'] == '1')
- $cur_post['location'] = censor_words($cur_post['location']);
- $forum_page['author_info']['from'] = '<li><span>'.$lang_topic['From'].' <strong>'.forum_htmlencode($cur_post['location']).'</strong></span></li>';
- }
- $forum_page['author_info']['registered'] = '<li><span>'.$lang_topic['Registered'].' <strong>'.format_time($cur_post['registered'], 1).'</strong></span></li>';
- if ($forum_config['o_show_post_count'] == '1' || $forum_user['is_admmod'])
- $forum_page['author_info']['posts'] = '<li><span>'.$lang_topic['Posts info'].' <strong>'.forum_number_format($cur_post['num_posts']).'</strong></span></li>';
- }
- if ($forum_user['is_admmod'])
- {
- if ($cur_post['admin_note'] != '')
- $forum_page['author_info']['note'] = '<li><span>'.$lang_topic['Note'].' <strong>'.forum_htmlencode($cur_post['admin_note']).'</strong></span></li>';
- }
- }
- }
- // Generate IP information for moderators/administrators
- if ($forum_user['is_admmod'])
- $forum_page['author_info']['ip'] = '<li><span>'.$lang_topic['IP'].' <a href="'.forum_link($forum_url['get_host'], $cur_post['id']).'">'.$cur_post['poster_ip'].'</a></span></li>';
- // Generate author contact details
- if ($forum_config['o_show_user_info'] == '1')
- {
- if (isset($user_data_cache[$cur_post['poster_id']]['post_contacts']))
- $forum_page['post_contacts'] = $user_data_cache[$cur_post['poster_id']]['post_contacts'];
- else
- {
- if ($cur_post['poster_id'] > 1)
- {
- if ($cur_post['url'] != '')
- $forum_page['post_contacts']['url'] = '<span class="user-url'.(empty($forum_page['post_contacts']) ? ' first-item' : '').'"><a class="external" href="'.forum_htmlencode(($forum_config['o_censoring'] == '1') ? censor_words($cur_post['url']) : $cur_post['url']).'">'.sprintf($lang_topic['Visit website'], '<span>'.sprintf($lang_topic['User possessive'], forum_htmlencode($cur_post['username'])).'</span>').'</a></span>';
- if ((($cur_post['email_setting'] == '0' && !$forum_user['is_guest']) || $forum_user['is_admmod']) && $forum_user['g_send_email'] == '1')
- $forum_page['post_contacts']['email'] = '<span class="user-email'.(empty($forum_page['post_contacts']) ? ' first-item' : '').'"><a href="mailto:'.forum_htmlencode($cur_post['email']).'">'.$lang_topic['E-mail'].'<span> '.forum_htmlencode($cur_post['username']).'</span></a></span>';
- else if ($cur_post['email_setting'] == '1' && !$forum_user['is_guest'] && $forum_user['g_send_email'] == '1')
- $forum_page['post_contacts']['email'] = '<span class="user-email'.(empty($forum_page['post_contacts']) ? ' first-item' : '').'"><a href="'.forum_link($forum_url['email'], $cur_post['poster_id']).'">'.$lang_topic['E-mail'].'<span> '.forum_htmlencode($cur_post['username']).'</span></a></span>';
- }
- else
- {
- if ($cur_post['poster_email'] != '' && !$forum_user['is_guest'] && $forum_user['g_send_email'] == '1')
- $forum_page['post_contacts']['email'] = '<span class="user-email'.(empty($forum_page['post_contacts']) ? ' first-item' : '').'"><a href="mailto:'.forum_htmlencode($cur_post['poster_email']).'">'.$lang_topic['E-mail'].'<span> '.forum_htmlencode($cur_post['username']).'</span></a></span>';
- }
- }
- ($hook = get_hook('vt_row_pre_post_contacts_merge')) ? eval($hook) : null;
- if (!empty($forum_page['post_contacts']))
- $forum_page['post_options']['contacts'] = '<p class="post-contacts">'.implode(' ', $forum_page['post_contacts']).'</p>';
- }
- // Generate the post options links
- if (!$forum_user['is_guest'])
- {
- $forum_page['post_actions']['report'] = '<span class="report-post'.(empty($forum_page['post_actions']) ? ' first-item' : '').'"><a href="'.forum_link($forum_url['report'], $cur_post['id']).'">'.$lang_topic['Report'].'<span> '.$lang_topic['Post'].' '.forum_number_format($forum_page['start_from'] + $forum_page['item_count']).'</span></a></span>';
- if (!$forum_page['is_admmod'])
- {
- if ($cur_topic['closed'] == '0')
- {
- if ($cur_post['poster_id'] == $forum_user['id'])
- {
- if (($forum_page['start_from'] + $forum_page['item_count']) == 1 && $forum_user['g_delete_topics'] == '1')
- $forum_page['post_actions']['delete'] = '<span class="delete-topic'.(empty($forum_page['post_actions']) ? ' first-item' : '').'"><a href="'.forum_link($forum_url['delete'], $cur_topic['first_post_id']).'">'.$lang_topic['Delete topic'].'</a></span>';
- if (($forum_page['start_from'] + $forum_page['item_count']) > 1 && $forum_user['g_delete_posts'] == '1')
- $forum_page['post_actions']['delete'] = '<span class="delete-post'.(empty($forum_page['post_actions']) ? ' first-item' : '').'"><a href="'.forum_link($forum_url['delete'], $cur_post['id']).'">'.$lang_topic['Delete'].'<span> '.$lang_topic['Post'].' '.forum_number_format($forum_page['start_from'] + $forum_page['item_count']).'</span></a></span>';
- if ($forum_user['g_edit_posts'] == '1')
- $forum_page['post_actions']['edit'] = '<span class="edit-post'.(empty($forum_page['post_actions']) ? ' first-item' : '').'"><a href="'.forum_link($forum_url['edit'], $cur_post['id']).'">'.$lang_topic['Edit'].'<span> '.$lang_topic['Post'].' '.forum_number_format($forum_page['start_from'] + $forum_page['item_count']).'</span></a></span>';
- }
- if (($cur_topic['post_replies'] == '' && $forum_user['g_post_replies'] == '1') || $cur_topic['post_replies'] == '1')
- $forum_page['post_actions']['quote'] = '<span class="quote-post'.(empty($forum_page['post_actions']) ? ' first-item' : '').'"><a href="'.forum_link($forum_url['quote'], array($id, $cur_post['id'])).'">'.$lang_topic['Quote'].'<span> '.$lang_topic['Post'].' '.forum_number_format($forum_page['start_from'] + $forum_page['item_count']).'</span></a></span>';
- }
- }
- else
- {
- if (($forum_page['start_from'] + $forum_page['item_count']) == 1)
- $forum_page['post_actions']['delete'] = '<span class="delete-topic'.(empty($forum_page['post_actions']) ? ' first-item' : '').'"><a href="'.forum_link($forum_url['delete'], $cur_topic['first_post_id']).'">'.$lang_topic['Delete topic'].'</a></span>';
- else
- $forum_page['post_actions']['delete'] = '<span class="delete-post'.(empty($forum_page['post_actions']) ? ' first-item' : '').'"><a href="'.forum_link($forum_url['delete'], $cur_post['id']).'">'.$lang_topic['Delete'].'<span> '.$lang_topic['Post'].' '.forum_number_format($forum_page['start_from'] + $forum_page['item_count']).'</span></a></span>';
- $forum_page['post_actions']['edit'] = '<span class="edit-post'.(empty($forum_page['post_actions']) ? ' first-item' : '').'"><a href="'.forum_link($forum_url['edit'], $cur_post['id']).'">'.$lang_topic['Edit'].'<span> '.$lang_topic['Post'].' '.forum_number_format($forum_page['start_from'] + $forum_page['item_count']).'</span></a></span>';
- $forum_page['post_actions']['quote'] = '<span class="quote-post'.(empty($forum_page['post_actions']) ? ' first-item' : '').'"><a href="'.forum_link($forum_url['quote'], array($id, $cur_post['id'])).'">'.$lang_topic['Quote'].'<span> '.$lang_topic['Post'].' '.forum_number_format($forum_page['start_from'] + $forum_page['item_count']).'</span></a></span>';
- }
- }
- else
- {
- if ($cur_topic['closed'] == '0')
- {
- if (($cur_topic['post_replies'] == '' && $forum_user['g_post_replies'] == '1') || $cur_topic['post_replies'] == '1')
- $forum_page['post_actions']['quote'] = '<span class="report-post'.(empty($forum_page['post_actions']) ? ' first-item' : '').'"><a href="'.forum_link($forum_url['quote'], array($id, $cur_post['id'])).'">'.$lang_topic['Quote'].'<span> '.$lang_topic['Post'].' '.forum_number_format($forum_page['start_from'] + $forum_page['item_count']).'</span></a></span>';
- }
- }
- ($hook = get_hook('vt_row_pre_post_actions_merge')) ? eval($hook) : null;
- if (!empty($forum_page['post_actions']))
- $forum_page['post_options']['actions'] = '<p class="post-actions">'.implode(' ', $forum_page['post_actions']).'</p>';
- // Give the post some class
- $forum_page['item_status'] = array(
- 'post',
- ($forum_page['item_count'] % 2 != 0) ? 'odd' : 'even'
- );
- if ($forum_page['item_count'] == 1)
- $forum_page['item_status']['firstpost'] = 'firstpost';
- if (($forum_page['start_from'] + $forum_page['item_count']) == $forum_page['finish_at'])
- $forum_page['item_status']['lastpost'] = 'lastpost';
- if ($cur_post['id'] == $cur_topic['first_post_id'])
- $forum_page['item_status']['topicpost'] = 'topicpost';
- else
- $forum_page['item_status']['replypost'] = 'replypost';
- // Generate the post title
- if ($cur_post['id'] == $cur_topic['first_post_id'])
- $forum_page['item_subject'] = sprintf($lang_topic['Topic title'], $cur_topic['subject']);
- else
- $forum_page['item_subject'] = sprintf($lang_topic['Reply title'], $cur_topic['subject']);
- $forum_page['item_subject'] = forum_htmlencode($forum_page['item_subject']);
- // Perform the main parsing of the message (BBCode, smilies, censor words etc)
- $forum_page['message']['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);
- if ($cur_post['edited'] != '')
- $forum_page['message']['edited'] = '<p class="lastedit"><em>'.sprintf($lang_topic['Last edited'], forum_htmlencode($cur_post['edited_by']), format_time($cur_post['edited'])).'</em></p>';
- // Do signature parsing/caching
- if ($cur_post['signature'] != '' && $forum_user['show_sig'] != '0' && $forum_config['o_signatures'] == '1')
- {
- if (!isset($signature_cache[$cur_post['poster_id']]))
- $signature_cache[$cur_post['poster_id']] = parse_signature($cur_post['signature']);
- $forum_page['message']['signature'] = '<div class="sig-content"><span class="sig-line"><!-- --></span>'.$signature_cache[$cur_post['poster_id']].'</div>';
- }
- ?>
- <div class="<?php echo implode(' ', $forum_page['item_status']) ?>">
- <div id="p<?php echo $cur_post['id'] ?>" class="posthead">
- <h3 class="hn post-ident"><?php echo implode(' ', $forum_page['post_ident']) ?></h3>
- </div>
- <div class="postbody<?php echo ($cur_post['is_online'] == $cur_post['poster_id']) ? ' online' : '' ?>">
- <div class="post-author">
- <ul class="author-ident">
- <?php echo implode("\n\t\t\t\t\t\t", $forum_page['author_ident'])."\n" ?>
- </ul>
- <ul class="author-info">
- <?php echo implode("\n\t\t\t\t\t\t", $forum_page['author_info'])."\n" ?>
- </ul>
- </div>
- <div class="post-entry">
- <h4 id="pc<?php echo $cur_post['id'] ?>" class="entry-title hn"><?php echo $forum_page['item_subject'] ?></h4>
- <div class="entry-content">
- <?php echo implode("\n\t\t\t\t\t\t", $forum_page['message'])."\n" ?>
- </div>
- </div>
- </div>
- <div class="postfoot">
- <div class="post-options">
- <?php
- AR_getRating($cur_post['id'], $forum_page['post_options'], $forum_user['is_guest']);
- echo implode("\n\t\t\t\t\t", $forum_page['post_options'])."\n";
- ?>
- </div>
- </div>
- </div>
- <?php
- }
- ?>
- </div>
- <?php
- $tpl_temp = forum_trim(ob_get_contents());
- $tpl_main = str_replace('<!-- forum_main -->', $tpl_temp, $tpl_main);
- ob_end_clean();
- // END SUBST - <!-- forum_main -->
- require FORUM_ROOT.'footer.php';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement