Discuz!NT 2.5 正式版 下载
beta、RC版升级补丁
中秋模板发布
首届Discuz!NT 模板大赛圆满结束
著名音乐网站SoGua网、分贝网
采用Discuz!NT搭建社区
FIFA Online2官网论坛使用Discuz!NT
游戏城寨论坛使用Discuz!NT搭建
Discuz!NT 2.5正式开源 Discuz!NT文档中心
用户整合说明文档
Discuz!NT亮相微软Tech-Ed 2007
Discuz!NT情景搞笑短片抢先看
武林三国《赤壁》下(双线二区)开服好礼大放送
1/4页1234 跳转到查看:11031
发新话题 回复该主题

闲来没事,做了个以论坛为核心的门户插件

闲来没事,做了个以论坛为核心的门户插件

看了http://BBS.WAFGAME.COM的门户X件,闲来无事,又要帮学校做网站,顺手做了一个,代号XShell(顺便赞个IEDevTool,看代码清晰的说)
图就不放了,我采用的和它的一样模板。
先感谢提供DNT SQL 2.0反编译代码的那个兄弟,我就是用的你的代码。
由于我只有VS2005 SP1的环境,所以只放出X件的2.0版。哦还有我的测试环境SQL数据库有点问题,我把X件改成支持ACCESS的了。SQL的只要把源代码中的OleDbDataReader改成SqlDataReader应该就可以了。
我加入了独立的标签系统。方便对门户修改。
标签介绍如下:
{$FourmName}:论坛名字
{$Keywords} :论坛关键字
{$Description} :论坛介绍
以上3个和你的论坛配置有关,配置文件是config/general.config
{$LastTopic_Title}:最新发表主题标题
{$LastTopic_Time} :最新发表主题时间
{$LastTopic_Content}:最新发表主题内容
理论上讲,这些标签处理是支持HTML代码的。但UBB的没有考虑。以后可能会加(主要是不知道DISCUZ!NT UBB处理代码在哪)
{$LastNotice_Title_*}:最新公告的标题
{$LastNotice_Time_*}:最新公告的时间
{$LastNotice_Content_*}:最新公告的内容
这里和TOPIC一样的处理方式,而且*代表数字,表示是调用第几条最新公告,如果是1就是最后发布的那条,如果是2就是倒数第二次发布的那条,以此类推。
{$NewTopic} :最新主题列表
{$NoticeList} :公告列表
{$FourmClass} :论坛大分类列表
这里的列表除了最后一个我都限制显示10个。后续开发的时候我可能添加一个配置文件,专门负责这个插件的一些配置数据。

另外详细论坛分类我没有做标签,目前我都是自己手工改,链接我也没做成自动的。因为要考虑到通用性,现在的这个模板太局限了。以后做了配置文件再闹。目前也还能凑合着用。

如果不想看代码只要用的。就看下面这个部分
DISCUZ!NT的目录
---------BIN
--------------Discuz.Plugin.XShell.dll
---------aspx生成模板以后的目录,由于我没有闹清DNT的模板生成机制,导致生成出来的XShell.aspx死活不能用,只好自己修改好放在这里了,还要请雪人教教。
              -----1
                      -XShell.aspx
---------images
            -------Xshell这里就是图片目录了,CSS定义文件也请放在这里
---------Xshell这里是XShell的模板文件目录,文件名XShell.Html,后续版本会把这个东西也做成配置信息,使其更加灵活
XShell.AspX前台调用文件。如果要改名,请配合ASPX/1/XSHELL.aspx一起改,不然找不到文件哦。
(PS:采用了HTML模板直接生成模式后,AJAX技术就不能用了。。。。哎。。。)
晕。帖子超过长度限度了,我在一楼发源代码!

附件

Xshell_Access_2.0_File.rar ()

2007-5-16 15:23:04


本帖被评分 1 次

TOP

 

回复: 闲来没事,做了个以论坛为核心的门户插件



using System;
using System.IO;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Xml;
using Discuz.Common;
using Discuz.Forum;
namespace Discuz.Plugin
{
    ///<summary>
    ///Discuz!NT XShell插件
    ///<summary>
    public class XShell
    {
        //定义输出的HTML代码保存变量
        static string showFile = string.Empty;
        /// <summary>
        /// 显示页面
        /// </summary>
        /// <returns>页面HTML代码</returns>
        public static string HtmlShow()
        {
            //定义XShell模板文件夹
            string strFilePatch = Utils.GetMapPath(BaseConfigFactory.GetForumPath + "Xshell/");
            //定义XShell文件位置
            string filePatch = strFilePatch + "XShell.html";
            if (File.Exists(filePatch))
            {
                using (StreamReader strReader = new StreamReader(filePatch, Encoding.UTF8))
                {
                    System.Text.StringBuilder strOutput = new System.Text.StringBuilder();
                    strOutput.Append(strReader.ReadToEnd());
                    strReader.Close();
                    showFile = strOutput.ToString();
                    HtmlReplace(filePatch);
                    return showFile;
                }
            }
            else return "Error!!";
        }
        #region 私有方法
        /// <summary>
        /// 标签处理
        /// </summary>
        /// <param name="filePatch">模板地址</param>
        /// <returns>处理标签后的HTML代码</returns>
        private static string HtmlReplace(string filePatch)
        {
            //定义论坛关键字
            string fourmKeywords = string.Empty;
            //定义论坛附加字
            string fourmTitle2 = string.Empty;
            //定义论坛标题
            string fourmTitle = string.Empty;
            //定义论坛描述
            string fourmDescription = string.Empty;
            //定义论坛新帖
            string fourmNewTopic = string.Empty;
            //定义论坛公告
            string fourmNotice = string.Empty;
            //定义论坛大分类
            string fourmClass = string.Empty;
            //定义最新论坛主题
            string fourmTopic = string.Empty;
            //定义论坛访问路径
            string fourmUrl = string.Empty;
            //配置文件路径
            string configFilePatch = Utils.GetMapPath(BaseConfigFactory.GetForumPath + "config/");
            XmlDocument XmlDoc = new XmlDocument();
            XmlDoc.Load(configFilePatch + "general.config");
            XmlNodeList NodeList = XmlDoc.SelectSingleNode("ConfigInfo").ChildNodes;
            //处理参数
            foreach (XmlNode Xn in NodeList)
            {
                XmlElement Xe = (XmlElement)Xn;
                if (Xe.Name == "Forumurl") fourmUrl = Xe.InnerText;
                if (Xe.Name == "Forumtitle") fourmTitle = Xe.InnerText;
                if (Xe.Name == "Seotitle") fourmTitle2 = Xe.InnerText;
                if (Xe.Name == "Seokeywords") fourmKeywords = Xe.InnerText;
                if (Xe.Name == "Seodescription") fourmDescription = Xe.InnerText;
            }
            //定义数据库连接,处理最新帖子列表
            OleDbDataReader reader = Database.ExecuteReader(CommandType.Text, "SELECT [tid], [fid], [title], [lastpost] FROM [" + BaseConfigFactory.GetTablePrefix + "topics] Order By [lastpost] DESC");
            if (reader != null)
            {
                int i = 0;
                StringBuilder newTopic = new StringBuilder();
                while (reader.Read())
                {
                    OleDbDataReader readerFourm = Database.ExecuteReader(CommandType.Text, "SELECT [name] FROM [" + BaseConfigFactory.GetTablePrefix + "forums] WHERE fid =" + reader[1].ToString().Trim());
                    readerFourm.Read();
                    newTopic.Append("<a href=\"" + fourmUrl + "/showtopic-" + reader[0].ToString().Trim() + ".aspx\"" + " title=\"" + reader[2].ToString().Trim() + "\">");
                    newTopic.Append("[" + readerFourm[0].ToString().Trim() + "]" + reader[2].ToString().Trim() + "</A><Br />");
                    readerFourm.Close();
                    i++;
                    if (i == 10) break;
                }
                reader.Close();
                fourmTopic = newTopic.ToString();
              }
            else fourmTopic = "暂无帖子!";
            //论坛大分类
            OleDbDataReader readerFourmClass = Database.ExecuteReader(CommandType.Text, "SELECT [fid], [name] FROM [" + BaseConfigFactory.GetTablePrefix + "forums] Where parentid = 0");
            if (readerFourmClass != null)
            {
                StringBuilder fourmClasslist = new StringBuilder();
                while (readerFourmClass.Read())
                {
                    fourmClasslist.Append("<a href=\"showforum-" + readerFourmClass[0].ToString().Trim() + ".aspx\" target=\"_blank\">");
                    fourmClasslist.Append(readerFourmClass[1].ToString() + "</a><br />");
                }
                fourmClass = fourmClasslist.ToString();
            }
            else fourmClass = "尚无分类";
            //处理最新发布帖子
            OleDbDataReader readerNewTopic = Database.ExecuteReader(CommandType.Text, "SELECT [tid], [fid], [title], [lastpost], [posterid], [poster] FROM [" + BaseConfigFactory.GetTablePrefix + "topics] Order By lastpost DESC");
            if (readerNewTopic != null)
            {
                readerNewTopic.Read();
                string poster = readerNewTopic[5].ToString().Trim();
                string posterid = readerNewTopic[4].ToString().Trim();
                fourmNewTopic = readerNewTopic[2].ToString().Trim();
                showFile = showFile.Replace("{$LastTopic_Title}", fourmNewTopic);
                fourmNewTopic = readerNewTopic[3].ToString().Trim();
                showFile = showFile.Replace("{$LastTopic_Time}", fourmNewTopic);
                OleDbDataReader readerNewTopicContent = Database.ExecuteReader(CommandType.Text, "SELECT [message] FROM [" + BaseConfigFactory.GetTablePrefix + "posts1] where title = '" + readerNewTopic[2].ToString().Trim() + "' and poster = '" + poster + "' and posterid = " + posterid);
                readerNewTopicContent.Read();
                fourmNewTopic = readerNewTopicContent[0].ToString().Trim();
                showFile = showFile.Replace("{$LastTopic_Content}", fourmNewTopic);
                readerNewTopicContent.Close();
                readerNewTopic.Close();
            }
            else
            {
                showFile = showFile.Replace("{$LastTopic_Title}", "No Topic");
                showFile = showFile.Replace("{$LastTopic_Time}", "No Topic");
                showFile = showFile.Replace("{$LastTopic_Content}", "No Topic");
            }
           
            //公告标签处理
            OleDbDataReader readerNotice = Database.ExecuteReader(CommandType.Text, "SELECT [id], [title], [message], [starttime] FROM [" + BaseConfigFactory.GetTablePrefix + "announcements] Order By id DESC");
            if (readerNotice != null)
            {
                int i = 0;
                StringBuilder NoticeList = new StringBuilder();
                while (readerNotice.Read())
                {
                    i++;
                    NoticeList.Append("<a href=\"announcement.aspx#" + readerNotice[0].ToString().Trim() + "\" target=\"_blank\">");
                    NoticeList.Append(readerNotice[1] + "</a><br />");
                    if (i == 10) break;
                    showFile = showFile.Replace("{$LastNotice_Title_" + i.ToString() + "}", readerNotice[1].ToString());
                    showFile = showFile.Replace("{$LastNotice_Time_" + i.ToString() + "}", readerNotice[3].ToString());
                    showFile = showFile.Replace("{$LastNotice_Content_" + i.ToString() + "}", readerNotice[2].ToString());
                }
                fourmNotice = NoticeList.ToString();
                showFile = showFile.Replace("{$NoticeList}", fourmNotice);
                readerNotice.Close();
            }
            //标签处理
            showFile = showFile.Replace("{$FourmName}", fourmTitle + " - " + fourmTitle2);
            showFile = showFile.Replace("{$Keywords}", fourmKeywords);
            showFile = showFile.Replace("{$Description}", fourmDescription);
            showFile = showFile.Replace("{$NewTopic}", fourmTopic);
            showFile = showFile.Replace("{$FourmClass}", fourmClass);
            return showFile;
        }
        #endregion
       
    }
}


基本都有注释。应该能看懂吧。

DNT的代码太多了,看得我那是个累啊。。。

TOP

 

回复:闲来没事,做了个以论坛为核心的门户插件

沙发,稍后更新测试,谢谢楼主
我们永远追逐青春、自由、梦想,欢迎光临AYA168社区http://bbs.aya168.com

TOP

 

回复:闲来没事,做了个以论坛为核心的门户插件

不错满喜欢的

TOP

 

回复:闲来没事,做了个以论坛为核心的门户插件

感谢LZ的无私奉献,奖励一下!!
致力于解决Discuz!NT&Discuz!5.0的普遍性问题!
大多数人的问题就是我的问题,解决才是硬道理!
筹建DISCUZ!NT插件策划及开发小组!

TOP

 

回复:闲来没事,做了个以论坛为核心的门户插件

....不怎么会弄,总不显示

TOP

 

回复:闲来没事,做了个以论坛为核心的门户插件

楼主能再说清楚点吗?

TOP

 

回复: 闲来没事,做了个以论坛为核心的门户插件

出现问题了,不能调用
最后编辑wenzillc 最后编辑于 2007-05-16 21:41:47

TOP

 

回复:闲来没事,做了个以论坛为核心的门户插件

8楼的请加我QQ 373323940..我告诉你咋闹。。。。。

PS:目前测试还有点BUG。。。我会不断修正然后发布上来的

TOP

 

回复: 闲来没事,做了个以论坛为核心的门户插件



引用:
原帖由 cmgs 于 2007-5-16 21:450 发表
8楼的请加我QQ 373323940..我告诉你咋闹。。。。。

PS:目前测试还有点BUG。。。我会不断修正然后发布上来的


已经加了QQ了,貌似没反应!~

TOP

 
1/4页1234 跳转到
发表新主题 回复该主题