discuz门户文章允许游客评论及添加类似wordpress评论功能

  • 2016-3-28 13:32
  • PHP二次开发
  • 阅读(21210)
  • 评论(854
  • 摘要: 现版本discuz的门户功能虽然相比起专业的CMS系统还有一定的差距,但也已具备了比较完善的文章管理系统。那么,在discuz中如何开启例如wordpress中的游客评论功能呢? 其实也很简单,discuz本身就已经配有游客用户组, ...
    现版本discuz的门户功能虽然相比起专业的CMS系统还有一定的差距,但也已具备了比较完善的文章管理系统。那么,在discuz中如何开启例如wordpress中的游客评论功能呢? 其实也很简单,discuz本身就已经配有游客用户组,只需要我们到 管理后台设置一下相应的权限即可,但要让游客在评论的时候能输入昵称就需要我们稍微修改一下源代码了。

    discuz开启游客评论
    1、进入后台,用户--用户组--系统用户组--游客--编辑

    2、门户相关--文章评论字数(设置此用户组发表文章评论字数限制,设置为0将禁止此用户组发表评论)

    通过以上两步,已开启了discuz文章游客评论的功能,下面我们为游客评论添加昵称输入的功能。

    disucz游客评论输入昵称

    1、模板文件修改(以下修改皆以默认模板文件作为参照,如你使用自己的模板,请对应修改相应的内容即可)

    在template/default/portal/comment.htm文件中找到

    <form id="cform" name="cform" action="portal.php?mod=portalcp&ac=comment" method="post" autocomplete="off">

    在该行下面加入

    <div class="mytxt">
                                        用户名:<input class="txt px vm" type="text" name="guestname" value="$_G['cookie']['php2_username']" />&nbsp;&nbsp;<span style="color:red;">*</span><br /><br />
    									邮 箱:<input class="txt px vm" type="text" name="email" value="$_G['cookie']['php2_email']" />&nbsp;&nbsp;<span style="color:red;">*</span><br /><br />
                                        网 址:<input class="txt px vm" type="text" name="url" value="$_G['cookie']['php2_url']" /> 注意加上“http://”哦!<br /><br />
                                </div>


    再在template/default/portal/portal_comment.htm文件中找到

    <form id="cform" name="cform" action="$form_url" method="post" autocomplete="off">

    在该行下同样加入上面的代码。

    以下设置评论显示里显示游客输入的昵称

    在文件template/default/portal/comment_li.htm中找到以下代码

    $message = censor($message);
    if(censormod($message)) {
    	$comment_status = 1;
    } else {
    	$comment_status = 0;
    }


    把这几行代码修改成:

    <!--{if !empty($comment['username'])}-->
    <a href="$comment['url']" target="_blank" name="robots" content="nofollow" class="xi2 xw1">$comment['username']</a>&nbsp;&nbsp;
    <!--{else}-->
    {lang guest}
    <!--{/if}-->


    2、修改PHP保存评论功能

    在文件source/function/function_portalcp.php中找到

    $message = censor($message);
    if(censormod($message)) {
        $comment_status = 1;
    } else {
        $comment_status = 0;
    }


    在这几行代码下面加入以下代码即可
            //为游客评论增加昵称输入
            $username = $_G['username'];
            if(isset($_POST['guestname'])){
                    $username = addslashes(trim($_POST['guestname']));
            }  
            if(!$_POST['guestname']){
                showmessage('请填写您的昵称');
            }
            if(isset($_POST['url'])){
                    $url = addslashes(trim($_POST['url']));
            }
            if(isset($_POST['email'])){
                    $email = addslashes(trim($_POST['email']));
            }
            if(!$_POST['email']){
                showmessage('请填写您的邮箱');
            }
    
    		//记录cookie
    		dsetcookie('php2_username', $username, 86400*30);
    		dsetcookie('php2_url', $url, 86400*30);
    		dsetcookie('php2_email', $email, 86400*30);

    找到代码:
    $setarr = array(
    		'uid' => $_G['uid'],
    		'username' => $username,
    		'id' => $id,
    		'idtype' => $idtype,
    		'postip' => $_G['clientip'],
    		'port' => $_G['remoteport'],
    		'dateline' => $_G['timestamp'],
    		'status' => $comment_status,
    		'message' => $message
    	);

    修改成:
    $setarr = array(
    		'uid' => $_G['uid'],
    		'username' => $username,
                    'url' => $url,
                    'email' => $email,
    		'id' => $id,
    		'idtype' => $idtype,
    		'postip' => $_G['clientip'],
    		'port' => $_G['remoteport'],
    		'dateline' => $_G['timestamp'],
    		'status' => $comment_status,
    		'message' => $message
    	);


    然后打开数据库,找到表:pre_portal_comment

    增加两个字段:url、email,字段类型为:varchar,长度设置成100即可。

    到此为止,已经全部完成了,具体效果请参考PHP二次开发(www.php2.cc)的文章评论功能,当然你可以为游客的评论设置各种的权限,防止乱发广告的现象,这些都可以在后台的用户组中进行设置。


    PHP技术交流QQ群:422137578

    除非注明,文章均为 PHP二次开发 原创,转载请注明本文地址:http://www.php2.cc/article-2172-1.html

    相关阅读

    发表评论

    最新评论

    引用 Jessesorce   2017-12-15 05:08
    In heart, the huge leap reckless of Kolkata has astounded the bedsitting scope and assorted it as the perpetual Kolkata. Author Resource:McAfee promo code lets you conserve many dollars on McAfee. Also, it is wise to wear gloves or perhaps some type of safety yourself because any deposits from possibly medications or even treatments can impact you too. A lot more than a few solicited and public banks remain generally there to help the deal pursuer by only if individuals each and every day presen ...
    引用 StevenvurcE   2017-10-29 17:53
    Hello everyone, I am new to, please look at a lot, thank you!
    引用 Michaelgox   2017-7-27 07:07
    При упоминании о натуральном камне у каждого пред глазами возникают определения роскоши и красоты. Особенно это относится к мрамору. Сочетание свойств этого камня и его качеств, делают его незаменинмым в области экстерьера.
    Но, как в прочем и все остальное, мрамор также тр ...
    引用 RandallSaf   2017-7-27 02:22
    what is the best cryptocurrency to invest in water
    This would appear to be out of the proverbial Ripley's Believe It Or even otherwise. But as mind-boggling simply may seem, word has it that in the not so far future, World Paper Money could very likely be replaced by electronic-digital currency.

    No you'll sell you this type of software because is "such a nice guy" however the reason why i am giving this out is the fact , for every time i need $100 i have to create a new liberty reserve accou ...
    引用 Howardbluse   2017-7-26 23:54
    Каждый день и в дождь, и в зной ходите на работу, как по часам? С каждым утром все тяжелее просыпаться? А вам еще предстоит толкаться в забитой маршрутке? А на работе еще начальник-хам, который постоянно чем-то недоволен? Устали от такого способа заработка денег? Мы научим вас, ...
    引用 Flossieapons   2017-7-26 17:41
    Revolutional update of SEO/SMM software "XRumer 16.0 + XEvil 3.0":
    captchas solution of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex,
    and more than 8400 another subtypes of captchas,
    with highest precision (80..100%) and highest speed (100 img per second).
    You can connect XEvil 3.0 to all most popular SEO/SMM software: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other software.

    Interested? There are a lot of introducing videos about XEvil in YouTube.
    Good  ...
    引用 EssayPaper   2017-7-26 17:30
    EssayErudite.com is the web's leading provider of quality and professional academic writing.
    When it comes to essay writing, an in-depth research is a big deal. Our experienced writers are professional in many fields of knowledge so that they can assist you with virtually any academic task. We deliver papers of different types: essays, theses, book reviews, case studies, etc.
    We have thousands of satisfied customers who have already recommended us to their friends. Why not follow their example ...
    引用 赚客啦社区   2017-2-23 19:31
    前来学习一下。
    引用 跨境电商运营   2016-3-31 22:30
    说得不错~~~~~

    查看全部评论(854)

    用户名:  *

    邮 箱:  *

    网 址: 注意加上“http://”哦!