免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4543 | 回复: 3
打印 上一主题 下一主题

求教:PHPBB如何实现让其友情链接按热门排序 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-08-13 09:41 |只看该作者 |倒序浏览
点击友情链接时,默认是按照网站分类来显示,很不合理,效果如下:
http://www.ioxm.com/links.php


我想让点击友情链接时,默认按照点击数排序来显示,效果如下:
http://www.ioxm.com/links.php?t=pop


不知应如何修改代码?
links.php文件的代码文件如下:

<?php
/***************************************************************************
*                            links.php
*                            -------------------
*  MOD add-on page. Contains GPL code copyright of phpBB group.
*  Author: OOHOO < webdev@phpbb-tw.net >;
*  Author: Stefan2k1 and ddonker from www.portedmods.com
*  Demo: http://phpbb-tw.net/
*  Version: 1.0.X - 2002/03/22 - for phpBB RC serial, and was named Related_Links_MOD
*  Version: 1.1.0 - 2002/04/25 - Re-packed for phpBB 2.0.0, and renamed to Links_MOD
*  Version: 1.2.0 - 2003/06/15 - Enhanced and Re-packed for phpBB 2.0.4
*
*  Modified by CRLin < gzqbyr@mail.dhjh.tcc.edu.tw >;
*  2003/07/30
*  Demo: http://mail.dhjh.tcc.edu.tw/~gzqbyr/phpBB/links.php
***************************************************************************/

/***************************************************************************
*
*   This program is free software; you can redistribute it and/or modify
*   it under the terms of the GNU General Public License as published by
*   the Free Software Foundation; either version 2 of the License, or
*   (at your option) any later version.
***************************************************************************/

define('IN_PHPBB', true);

$phpbb_root_path = "./";
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . "common.$phpEx";
require($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_main_link.' . $phpEx);

// Start session management
$userdata = session_pagestart($user_ip, PAGE_LINKS);
init_userprefs($userdata);

//
// Count and forwrad
//
if($HTTP_GET_VARS['action'] == "go" && $HTTP_GET_VARS['link_id'])
{
        $link_id = $HTTP_GET_VARS['link_id'];
        // Secure check
        if(is_numeric($link_id))
        {
                $sql = "SELECT link_id, link_url, last_user_ip
                        FROM " . LINKS_TABLE . "
                        WHERE link_id = '$link_id'
                        AND link_active = 1";

                if($result = $db->;sql_query($sql))
                {
                        $row = $db->;sql_fetchrow($result);
                        if($link_url = $row['link_url'])
                        {
                                if($user_ip != $row['last_user_ip'])
                                {
                                        // Update
                                        $sql = "UPDATE " . LINKS_TABLE . "
                                                SET link_hits = link_hits + 1, last_user_ip = '$user_ip'
                                                WHERE link_id = '$link_id'";
                                        $result = $db->;sql_query($sql);
                                }

                                // Forward to website
                                header("Location: $link_url";
                                exit;
                        }
                }
        }
}

// Output the basic page
$page_title = $lang['Site_links'];
include('includes/page_header.'.$phpEx);

//
// Define initial vars
//
$start = ( isset($HTTP_GET_VARS['start']) ) ? $HTTP_GET_VARS['start'] : 0;

if ( isset($HTTP_POST_VARS['t']) || isset($HTTP_GET_VARS['t']) )
{
        $t = ( isset($HTTP_POST_VARS['t']) ) ? $HTTP_POST_VARS['t'] : $HTTP_GET_VARS['t'];
} else {
        $t = 'index';
}
if ( isset($HTTP_POST_VARS['cat']) || isset($HTTP_GET_VARS['cat']) )
{
        $cat = ( isset($HTTP_POST_VARS['cat']) ) ? $HTTP_POST_VARS['cat'] : $HTTP_GET_VARS['cat'];
} else {
        $cat = 1;
}
if ( isset($HTTP_POST_VARS['search_keywords']) || isset($HTTP_GET_VARS['search_keywords']) )
{
        $search_keywords = ( isset($HTTP_POST_VARS['search_keywords']) ) ? $HTTP_POST_VARS['search_keywords'] : $HTTP_GET_VARS['search_keywords'];
} else {
        $search_keywords = '';
}

switch($t)
{
        case 'pop':
        case 'new':
                $tmp = "links_popnew.tpl";
                break;
        case 'search':
                $tmp = "links_search.tpl";
                break;
        case 'sub_pages':
                $tmp = "links_body.tpl";
                break;
        default:
                $tmp = "links_index.tpl";
}
$template->;set_filenames(array(
        'body' =>; $tmp
));

//
// Get Link Config
//
$sql = "SELECT *
                FROM ". LINK_CONFIG_TABLE;
if(!$result = $db->;sql_query($sql))
{
        message_die(GENERAL_ERROR, "Could not query Link config information", "", __LINE__, __FILE__, $sql);
}
while( $row = $db->;sql_fetchrow($result) )
{
        $link_config_name = $row['config_name'];
        $link_config_value = $row['config_value'];
        $link_config[$link_config_name] = $link_config_value;
        $linkspp=$link_config['linkspp'];
}

$template->;assign_vars(array(
        'L_SITE_LINKS' =>; $lang['Site_links'],
        'L_LINK_US' =>; $lang['Link_us'] . $board_config['sitename'],
        'L_LINK_US_EXPLAIN' =>; sprintf($lang['Link_us_explain'], $board_config['sitename']),
        'L_LINK_REGISTER' =>; $lang['Link_register'],
        'L_LINK_REGISTER_RULE' =>; $lang['Link_register_rule'],
        'L_LINK_TITLE' =>; $lang['Link_title'],
        'L_LINK_DESC' =>; $lang['Link_desc'],
        'L_LINK_URL' =>; $lang['Link_url'],
        'L_LINK_LOGO_SRC' =>; $lang['Link_logo_src'],
        'L_LINK_JOINED' =>; $lang['Joined'],
        'L_LINK_CATEGORY' =>; $lang['Link_category'],
        'L_LINK_HITS' =>; $lang['link_hits'],
        'L_PLEASE_ENTER_YOUR' =>; $lang['Please_enter_your'],
        'L_SUBMIT' =>; $lang['Submit'],
        'U_SITE_LINKS' =>; append_sid("links.$phpEx",
        'U_SITE_LOGO' =>; $link_config['site_logo'],
        'LINK_US_SYNTAX' =>; str_replace(" ", "&", sprintf(htmlentities($lang['Link_us_syntax'], ENT_QUOTES), $link_config['site_url'], $link_config['site_logo'], $link_config['width'],$link_config['height'], $board_config['sitename'])),
        'U_LINK_REG' =>; append_sid("link_register.$phpEx",
        'LINKS_HOME' =>; $lang['Links_home'],
        'L_SEARCH_SITE' =>; $lang['Search_site'],
        'L_DESCEND_BY_HITS' =>; $lang['Descend_by_hits'],
        'L_DESCEND_BY_JOINDATE' =>; $lang['Descend_by_joindate']
));

if ($t=='pop' || $t=='new')
{
        if ($t=='pop')
        {
                $template->;assign_vars(array(
                        'L_LINK_TITLE1' =>; $lang['Descend_by_hits']
                ));
        }
        else
        {
                $template->;assign_vars(array(
                        'L_LINK_TITLE1' =>; $lang['Descend_by_joindate']
                ));
        }

        //
        // Grab link categories
        //
        $sql = "SELECT cat_id, cat_title FROM " . LINK_CATEGORIES_TABLE . " ORDER BY cat_order";

        if(!$result = $db->;sql_query($sql))
        {
                message_die(GENERAL_ERROR, 'Could not query link categories list', '', __LINE__, __FILE__, $sql);
        }

        while($row = $db->;sql_fetchrow($result))
        {
                $link_categories[$row['cat_id']] = $row['cat_title'];
        }

        //
        // Grab links
        //
        $sql = "SELECT * FROM " . LINKS_TABLE . "
                WHERE link_active = 1
                ORDER BY link_hits DESC, link_id DESC
                LIMIT $start, $linkspp";
        if ($t == 'new')
        {
                $sql = "SELECT * FROM " . LINKS_TABLE . "
                        WHERE link_active = 1
                        ORDER BY link_joined DESC, link_id DESC
                        LIMIT $start, $linkspp";
        }

        if(!$result = $db->;sql_query($sql))
        {
                message_die(GENERAL_ERROR, 'Could not query links list', '', __LINE__, __FILE__, $sql);
        }

        if ( $row = $db->;sql_fetchrow($result) )
        {
                do
                {
                        $template->;assign_block_vars("linkrow", array(
                                'LINK_URL' =>; append_sid("links.$phpEx?action=go&link_id=" . $row['link_id']),
                                'LINK_TITLE' =>; $row['link_title'],
                                'LINK_DESC' =>; $row['link_desc'],
                                'LINK_LOGO_SRC' =>; $row['link_logo_src'],
                                'LINK_CATEGORY' =>; $link_categories[$row['link_category']],
                                'LINK_JOINED' =>; create_date($lang['DATE_FORMAT'], $row['link_joined'], $board_config['board_timezone']),
                                'LINK_HITS' =>; $row['link_hits']
                        ));
                }
                while ( $row = $db->;sql_fetchrow($result) );
        }

        //
        // Pagination
        //
        $sql = "SELECT count(*) AS total
                FROM " . LINKS_TABLE . "
                WHERE link_active = 1";

        if ( !($result = $db->;sql_query($sql)) )
        {
                message_die(GENERAL_ERROR, 'Could not query links number', '', __LINE__, __FILE__, $sql);
        }

        if ( $row = $db->;sql_fetchrow($result) )
        {
                $total_links = $row['total'];
                $pagination = generate_pagination("links.$phpEx?t=$t", $total_links, $linkspp, $start). '&';
        }
        else
        {
                $pagination = '&';
                $total_links = 10;
        }

        //
        // Link categories dropdown list
        //
        foreach($link_categories as $cat_id =>; $cat_title)
        {
                $link_cat_option .= "<option value=\"$cat_id\">;$cat_title</option>;";
        }

       
        $template->;assign_vars(array(
                'PAGINATION' =>; $pagination,
                'PAGE_NUMBER' =>; sprintf($lang['Page_of'], ( floor( $start / $linkspp ) + 1 ), ceil( $total_links / $linkspp )),
                'L_GOTO_PAGE' =>; $lang['Goto_page'],

                'LINK_CAT_OPTION' =>; $link_cat_option
        ));

        $template->;pparse("body";

        include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
        exit;
}

if ($t=='sub_pages')
{
        if ( isset($HTTP_GET_VARS['mode']) || isset($HTTP_POST_VARS['mode']) )
        {
                $mode = ( isset($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];
        }
        else
        {
                $mode = 'link_joined';
        }

        if(isset($HTTP_POST_VARS['order']))
        {
                $sort_order = ($HTTP_POST_VARS['order'] == 'ASC') ? 'ASC' : 'DESC';
        }
        else if(isset($HTTP_GET_VARS['order']))
        {
                $sort_order = ($HTTP_GET_VARS['order'] == 'ASC') ? 'ASC' : 'DESC';
        }
        else
        {
                $sort_order = 'DESC';
        }

        //
        // Links sites sorting
        //
        $mode_types_text = array($lang['link_hits'], $lang['Joined'], $lang['Link_title'], $lang['Link_desc']);
        $mode_types = array('link_hits', 'link_joined', 'link_title', 'link_desc');

        $select_sort_mode = '<select name="mode">;';
        for($i = 0; $i < count($mode_types_text); $i++)
        {
                $selected = ( $mode == $mode_types[$i] ) ? ' selected="selected"' : '';
                $select_sort_mode .= '<option value="' . $mode_types[$i] . '"' . $selected . '>;' . $mode_types_text[$i] . '</option>;';
        }
        $select_sort_mode .= '</select>;';

        $select_sort_order = '<select name="order">;';
        if($sort_order == 'ASC')
        {
                $select_sort_order .= '<option value="ASC" selected="selected">;' . $lang['Sort_Ascending'] . '</option>;<option value="DESC">;' . $lang['Sort_Descending'] . '</option>;';
        }
        else
        {
                $select_sort_order .= '<option value="ASC">;' . $lang['Sort_Ascending'] . '</option>;<option value="DESC" selected="selected">;' . $lang['Sort_Descending'] . '</option>;';
        }
        $select_sort_order .= '</select>;';

        $select_sort_order = $select_sort_order . '<input type="hidden" name="t" value="' . $t .'">;';
        $select_sort_order = $select_sort_order . '<input type="hidden" name="cat" value="' . $cat .'">;';

        $template->;assign_vars(array(
                'L_SEARCH_SITE' =>; $lang['Search_site'],
                'L_SELECT_SORT_METHOD' =>; $lang['Select_sort_method'],
                'L_ORDER' =>; $lang['Order'],
                'L_SUBMITS' =>; $lang['Sort'],
                'S_MODE_SELECT' =>; $select_sort_mode,
                'S_ORDER_SELECT' =>; $select_sort_order
        ));

        //
        // Grab link categories
        //
        $sql = "SELECT cat_id, cat_title FROM " . LINK_CATEGORIES_TABLE . " WHERE cat_id = $cat";

        if(!$result = $db->;sql_query($sql))
        {
                message_die(GENERAL_ERROR, 'Could not query link categories list', '', __LINE__, __FILE__, $sql);
        }

        $row = $db->;sql_fetchrow($result);
        $link_categories[$row['cat_id']] = $row['cat_title'];
        $template->;assign_vars(array(
                'LINK_CATEGORY' =>; $row['cat_title']
        ));

        //
        // Grab links
        //
        $sql = "SELECT * FROM " . LINKS_TABLE . "
                        WHERE link_active = 1 AND link_category = $cat
                        ORDER BY $mode $sort_order, link_id DESC
                        LIMIT $start, $linkspp";

        if(!$result = $db->;sql_query($sql))
        {
                message_die(GENERAL_ERROR, 'Could not query links list', '', __LINE__, __FILE__, $sql);
        }


        if ( $row = $db->;sql_fetchrow($result) )
        {
                do
                {
                        $template->;assign_block_vars("linkrow", array(
                                'LINK_URL' =>; append_sid("links.$phpEx?action=go&link_id=" . $row['link_id']),
                                'LINK_TITLE' =>; $row['link_title'],
                                'LINK_DESC' =>; $row['link_desc'],
                                'LINK_LOGO_SRC' =>; $row['link_logo_src'],
                                'LINK_CATEGORY' =>; $link_categories[$row['link_category']],
                                'LINK_JOINED' =>; create_date($lang['DATE_FORMAT'], $row['link_joined'], $board_config['board_timezone']),
                                'LINK_HITS' =>; $row['link_hits']
                        ));
                }
                while ( $row = $db->;sql_fetchrow($result) );
        }

        //
        // Pagination
        //
        $sql = "SELECT count(*) AS total
                FROM " . LINKS_TABLE . "
                WHERE link_active = 1 AND link_category = $cat";

        if ( !($result = $db->;sql_query($sql)) )
        {
                message_die(GENERAL_ERROR, 'Could not query links number', '', __LINE__, __FILE__, $sql);
        }

        if ( $row = $db->;sql_fetchrow($result) )
        {
                $total_links = $row['total'];
                $pagination = generate_pagination("links.$phpEx?t=$t&cat=$cat&mode=$mode&order=$sort_order", $total_links, $linkspp, $start). '&';
        }
        else
        {
                $pagination = '&';
                $total_links = 10;
        }

        //
        // Link categories dropdown list
        //
        foreach($link_categories as $cat_id =>; $cat_title)
        {
                $link_cat_option .= "<option value=\"$cat_id\">;$cat_title</option>;";
        }

        $template->;assign_vars(array(
                'PAGINATION' =>; $pagination,
                'PAGE_NUMBER' =>; sprintf($lang['Page_of'], ( floor( $start / $linkspp ) + 1 ), ceil( $total_links / $linkspp )),
                'L_GOTO_PAGE' =>; $lang['Goto_page'],

                'LINK_CAT_OPTION' =>; $link_cat_option
        ));

        $template->;pparse("body";

        include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
        exit;
}

if ($t=='search')
{
        if ( $search_keywords )
        {
                $search_keywords = trim(stripslashes($search_keywords));
                $link_title =  $lang['Search_site'] . " & " . $search_keywords;
                $template->;assign_vars(array(
                        'L_LINK_TITLE1' =>; $link_title,
                        'L_SEARCH_SITE_TITLE' =>; $lang['Search_site_title']
                ));
        }
        else
        {
                $template->;assign_vars(array(
                        'L_LINK_TITLE1' =>; $lang['Search_site'],
                        'L_SEARCH_SITE_TITLE' =>; $lang['Search_site_title']
                ));
                $start = 0;
        }
        //
        // Grab link categories
        //
        $sql = "SELECT cat_id, cat_title FROM " . LINK_CATEGORIES_TABLE . " ORDER BY cat_order";

        if(!$result = $db->;sql_query($sql))
        {
                message_die(GENERAL_ERROR, 'Could not query link categories list', '', __LINE__, __FILE__, $sql);
        }

        while($row = $db->;sql_fetchrow($result))
        {
                $link_categories[$row['cat_id']] = $row['cat_title'];
        }

        //
        // Grab links
        //
        if ( $search_keywords )
        {
                $sql = "SELECT * FROM " . LINKS_TABLE . "
                        WHERE link_active = 1";
                $sql = $sql . " AND (link_title LIKE '%$search_keywords%' OR link_desc LIKE '% $search_keywords%') LIMIT $start, $linkspp";
               
                if(!$result = $db->;sql_query($sql))
                {
                        message_die(GENERAL_ERROR, 'Could not query links list', '', __LINE__, __FILE__, $sql);
                }

                if ( $row = $db->;sql_fetchrow($result) )
                {
                        do
                        {
                                $template->;assign_block_vars("linkrow", array(
                                        'LINK_URL' =>; append_sid("links.$phpEx?action=go&link_id=" . $row['link_id']),
                                        'LINK_TITLE' =>; $row['link_title'],
                                        'LINK_DESC' =>; $row['link_desc'],
                                        'LINK_LOGO_SRC' =>; $row['link_logo_src'],
                                        'LINK_CATEGORY' =>; $link_categories[$row['link_category']],
                                        'LINK_JOINED' =>; create_date($lang['DATE_FORMAT'], $row['link_joined'], $board_config['board_timezone']),
                                        'LINK_HITS' =>; $row['link_hits']
                                ));
                        }
                        while ( $row = $db->;sql_fetchrow($result) );
                }

                //
                // Pagination
                //
                $sql = "SELECT count(*) AS total
                        FROM " . LINKS_TABLE . "
                        WHERE link_active = 1";
                $sql .= " AND (link_title LIKE '%$search_keywords%' OR link_desc LIKE '%$search_keywords %')";

                if ( !($result = $db->;sql_query($sql)) )
                {
                        message_die(GENERAL_ERROR, 'Could not query links number', '', __LINE__, __FILE__, $sql);
                }

                if ( $row = $db->;sql_fetchrow($result) )
                {
                        $total_links = $row['total'];
                        $pagination = generate_pagination("links.$phpEx?t=$t&search_keywords=$search_keywords", $total_links, $linkspp, $start). '&';
                }
                else
                {
                        $pagination = '&';
                        $total_links = 10;
                }
        }

        //
        // Link categories dropdown list
        //
        foreach($link_categories as $cat_id =>; $cat_title)
        {
                $link_cat_option .= "<option value=\"$cat_id\">;$cat_title</option>;";
        }

        $template->;assign_vars(array(
                'PAGINATION' =>; $pagination,
                'PAGE_NUMBER' =>; sprintf($lang['Page_of'], ( floor( $start / $linkspp ) + 1 ), ceil( $total_links / $linkspp )),
                'L_GOTO_PAGE' =>; $lang['Goto_page'],

                'LINK_CAT_OPTION' =>; $link_cat_option
        ));

        $template->;pparse("body";

        include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
        exit;
}

$template->;assign_vars(array(
        'FOLDER_IMG' =>; $images['folder']
));

//
// Grab link categories
//
$sql = "SELECT cat_id, cat_title FROM " . LINK_CATEGORIES_TABLE . " ORDER BY cat_order";

if(!$result = $db->;sql_query($sql))
{
        message_die(GENERAL_ERROR, 'Could not query link categories list', '', __LINE__, __FILE__, $sql);
}

// Separate link categories into 2 columns
$I = 0;
if ( $row = $db->;sql_fetchrow($result) )
{
        do
        {
                $I = ($I+1) % 2;
                $link_categories[$row['cat_id']] = $row['cat_title'];
                $sql = "SELECT link_category FROM " . LINKS_TABLE . "
                        WHERE link_active = 1 AND link_category = ";
                $sql .= $row['cat_id'];
                if(!$linknum = $db->;sql_query($sql))
                {
                        message_die(GENERAL_ERROR, 'Could not query links list', '', __LINE__, __FILE__, $sql);
                }
                $template->;assign_block_vars("linkrow" . $I, array(
                        'LINK_URL' =>; append_sid("links.$phpEx?t=sub_pages&cat=" . $row['cat_id']),
                        'LINK_TITLE' =>; $row['cat_title'],
                        'LINK_NUMBER' =>; $db->;sql_numrows($linknum)
                ));
        }
        while ( $row = $db->;sql_fetchrow($result) );
}
       
//
// Link categories dropdown list
//
foreach($link_categories as $cat_id =>; $cat_title)
{
        $link_cat_option .= "<option value=\"$cat_id\">;$cat_title</option>;";
}
       
$template->;assign_vars(array(
        'LINK_CAT_OPTION' =>; $link_cat_option
));

$template->;pparse("body";

include($phpbb_root_path . 'includes/page_tail.'.$phpEx);

?>;

论坛徽章:
0
2 [报告]
发表于 2004-08-13 14:53 |只看该作者

求教:PHPBB如何实现让其友情链接按热门排序

  1. $sql = "SELECT * FROM " . LINKS_TABLE . "
  2. WHERE link_active = 1
  3. ORDER BY link_hits DESC
复制代码


这句不就是按点击数来排的么?你把它放到合适的位置就行了

论坛徽章:
0
3 [报告]
发表于 2004-08-13 14:59 |只看该作者

求教:PHPBB如何实现让其友情链接按热门排序

先谢了!
但我是想让点击友情链接时,直接按热门排序显示,而不是按分类显示。

论坛徽章:
0
4 [报告]
发表于 2004-08-14 17:28 |只看该作者

求教:PHPBB如何实现让其友情链接按热门排序

不然帮我把按分类显示的代码找出来也行,我是想只要把其代码换成按热门排序的代码就行了,不知可否?请各位帮忙呀,谢谢了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP