让你的discuz论坛支持用户自定义广告与会员自定义的google adsense

6/22/2009来源:Discuz!专栏人气:8138

功能:允许会员自定义自己的广告,每次发贴或回复时,自定义的广告将自动添加到话题的右侧(支持google adsense)。

1.修改数据表(表前缀_memberfields):
添加adcontent,adurl,adtitle,googlePub三个字段

可以直接在数据库中执行:ALTER TABLE 表前缀_memberfields ADD `adcontent` VARCHAR( 100 ) NOT NULL AFTER `msn` ;

ALTER TABLE 表前缀_memberfields ADD `adurl` VARCHAR( 100 ) NOT NULL AFTER `msn` ;

ALTER TABLE 表前缀_memberfields ADD `adtitle` VARCHAR( 100 ) NOT NULL AFTER `msn` ;

ALTER TABLE 表前缀_memberfields ADD `googlePub` VARCHAR( 20 ) NOT NULL AFTER `msn` ;
复制代码2.修改文件:
打开文件/memcp.php,找到如下一行:} elseif($typeid == 2) {
复制代码一共能搜索到两行,在第二行之前添加代码:                } elseif($typeid == 3) {

 

                        $censorexp = '/^('.str_replace(array('\\*', "\r\n", ' '), array

 

('.*', '|', ''), PReg_quote(($censoruser = trim($censoruser)), '/')).')$/i';

 

                        $googlenew = preg_match ("/^([0-9]+)$/", $googlenew) && strlen

 

($googlenew) == 16 ? $googlenew : '';

                        $adtitlenew = DHTMLspecialchars($adtitlenew);

                        $adurlnew = !preg_match("/^http:\/\/$/i", $adurlnew) ?

 

(dhtmlspecialchars(trim(preg_match("/^https?:\/\/.+/i", $adurlnew) ? $adurlnew : ($adurlnew

 

? 'http://'.$adurlnew : '')))) : '';

                        $adcontentnew = dhtmlspecialchars($adcontentnew);

 

                        if($maxsigsize) {

                                if(strlen($signaturenew) > $maxsigsize) {

                                        showmessage('profile_sig_toolong');

                                }

                        } else {

                                $signaturenew = '';

                        }

 

                        $signaturenew = censor($signaturenew);

                        $sigstatusnew = $signaturenew ? 1 : 0;

                        $bionew = censor(dhtmlspecialchars($bionew));

 

                        $sightmlnew = discuzcode(stripslashes($signaturenew), 1, 0, 0, 0,

 

$allowsigbbcode, $allowsigimgcode, 0, 0, 1);

                        $biohtmlnew = discuzcode(stripslashes($bionew), 1, 0, 0, 0,

 

$allowbiobbcode, $allowbioimgcode, 0, 0, 1);

                        $sightmlnew = addslashes($sightmlnew);

                        $biohtmlnew = addslashes($biohtmlnew);

 

                        $membersql = "gender='$gendernew', bday='$bdaynew',

 

sigstatus='$sigstatusnew'";

                        $memberfieldsql = "adtitle='$adtitlenew', adurl='$adurlnew',

 

adcontent='$adcontentnew', googlePub='$googlenew'";

 

                        if($_DCACHE['fields_required'] || $_DCACHE['fields_optional']) {

                                $fieldadd = array();

                                foreach(array_merge($_DCACHE['fields_required'], $_DCACHE

 

['fields_optional']) as $field) {

                                        $field_key = 'field_'.$field['fieldid'];

                                        $field_val = trim(${'field_'.$field

 

['fieldid'].'new'});

                                        if($field['required'] && $field_val == '' && !

 

($field['unchangeable'] && $member[$field_key])) {

                                                showmessage

 

('profile_required_info_invalid');

                                        } elseif($field['selective'] && $field_val != '' &&

 

!isset($field['choices'][$field_val])) {

                                                showmessage('undefined_action', NULL,

 

'HALTED');

                                        } elseif(!$field['unchangeable'] || !$member

 

[$field_key]) {

                                                $fieldadd[] =

 

"$field_key='".dhtmlspecialchars($field_val)."'";

                                        }

                                }

 

                                if(!empty($fieldadd)) {

                                        $memberfieldsql .= ', '.implode(', ', $fieldadd);

                                }

                        }
复制代码打开文件/templates/default/memcp_profile.htm,找到如下一行代码:        <!--{elseif $typeid == 5}-->
复制代码在上面添加:                        <!--{elseif $typeid == 3}-->

                                <link href="forumdata/cache/style_{STYLEID}_seditor.CSS?

 

{VERHASH}" rel="stylesheet" type="text/css" />

                                <h1>自定义广告设置</h1>

                                <table summary="{lang memcp_profile}" cellspacing="0"

 

cellpadding="0" class="formtable">

                                        <tr>

                                                <th><label for="imme"><b>GGAD广告联盟

 

</b></label></th>

                                                <td>

                                                        <!--{if $member['googlePub']}-->

                                                        您已经设置了google adsense编

 

号,宣传您的贴子会使您赚到更多的美元!

                                                        <!--{else}-->

                                                                设置您的google adsense的pub

 

编号,让娱乐赚钱同时进行!<a href="http://www.google.com/adsense" target="_blank">您没有帐号

 

吗?<b>点此申请</b></a>

                                                        <!--{/if}-->

                                                </td>

                                        </tr>

                                        <tr class="sep_space"><th colspan="2"></th></tr>

                                        <tr>

                                                <th><label for="googlenew">GGAD编号 pub-

 

</label></th>

                                                <td>

                                                        <input type="text" name="googlenew"

 

id="googlenew" size="25" value="$member[googlePub]" class="txt" />Pub编号后16位数字,不包括

 

“pub-”(没有请留空):

                                                </td>

                                        </tr>

 

                                        <tr class="sep_space"><th colspan="2"></th></tr>

                                        <tr>

                                                <th><label for="imme"><b>自定义广告

 

</b></label></th>

                                                <td>

                                                        如果您不希望在此展示google adsense,

 

您也可以使用自定义的广告来增加盈利。

                                                </td>

                                        </tr>

                                        <tr>

                                                <th><label for="adtitlenew">自定义广告标题

 

</label></th>

                                                <td>

                                                        <input type="text" name="adtitlenew"

 

id="adtitlenew" size="25" value="$member[adtitle]" class="txt" />广告标题长度不超过20个汉字

                                                </td>

                                        </tr>

                                        <tr>

                                                <th><label for="adurlnew">广告链接地址:

 

</label></th>

                                                <td>

                                                        <input type="text" name="adurlnew"

 

id="adurlnew" size="25" value="$member[adurl]" class="txt" />*输入广告链接地址,

 

如:http://www.Flashmayi.com

                                                </td>

                                        </tr>

                                        <tr>

                                                <th><label for="adcontentnew">自定义广告内容

 

</label></th>

                                                <td>

                                                        <input type="text"

 

name="adcontentnew" id="adcontentnew" size="25" value="$member[adcontent]" class="txt" />广

 

告内容不超过100个字节

                                                </td>

                                        </tr>
复制代码打开文件/viewthread.php,找到如下代码:“mf.msn,”,在后面添加:
mf.googlePub, mf.adtitle, mf.adurl, mf.adcontent,

打开文件/templates/default/viewthread_node.htm找到:$post[message] ,应该可以找到两个,在第二个上方添加如下代码:<!--贴内右侧广告开始-->

<!--{if $post['count'] < 4 }-->

    <!--{if !$discuz_uid && $post[fid]!='12' && $post['count'] < 2 }-->

            <!--{if $post['googlePub']}-->

            <div align="right" style="float: right;text-align: left;height: 250px;width: 300px;margin: 4px;padding: 0px;">

<script type="text/javascript"><!--

google_ad_client = "pub-$post['googlePub']";

google_ad_width = 300;

google_ad_height = 250;

google_ad_format = "300x250_as";

google_ad_type = "text_image";

//2007-10-26: 文章显示页(图)

google_ad_channel = "0262717294";

google_color_border = "FFFFFF";

google_color_bg = "FFFFFF";

google_color_link = "0000FF";

google_color_text = "000000";

google_color_url = "008000";

google_ui_features = "rc:6";

//-->

</script>

<script type="text/Javascript"

  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">

</script>

                </div>

            <!--{elseif $post['adtitle']}-->

                    <div align="right" style="background-image: url(/images/adbg.jpg);       

 

background-repeat: no-repeat;background-position: center center;padding: 4px;float:

 

right;text-align: left;height: 200px;width: 160px;margin: 4px;border: 1px solid

 

#666;background-color: #FFF;">

                <a href="$post['adurl']"  target="_blank"><font color="blue"><b>$post

 

['adtitle']</b></font></a><br>

        <p style="font-size:10pt;line-height:18px; margin-top:6px;"><a href="$post['adurl']"

 

target="_blank"><font color="#333333">$post['adcontent']</font></a></p>

        <p style="text-align: right;margin-top:8px; color:green;font-size:10pt;"> - <a

 

href="$post['adurl']" target="_blank"><font color=green>查看详情</font></a></p>

        </div>

            <!--{else}-->

                    <div align="right" style="float: right;text-align: left;height:

 

200px;width: 200px;margin: 4px;padding: 0px;">

                <script type="text/javascript"><!--

                google_ad_client = "pub-0504005872777313";

                /* 200x200, 创建于 09-5-19 */

                google_ad_slot = "6751742968";

                google_ad_width = 200;

                google_ad_height = 200;

                //-->

                </script>

                <script type="text/javascript"

                src="http://pagead2.googlesyndication.com/pagead/show_ads.js">

                </script>

        </div>

            <!--{/if}-->

    <!--{else}-->

        <!--{if $post['adtitle']}-->

                    <div align="right" style="background-image: url(/images/adbg.jpg);       

 

background-repeat: no-repeat;background-position: center center;padding: 4px;float:

 

right;text-align: left;height: 200px;width: 160px;margin: 4px;border: 1px solid

 

#666;background-color: #FFF;">

                <a href="$post['adurl']" target="_blank"><font color="blue"><b>$post

 

['adtitle']</b></font></a><br>

        <p style="font-size:10pt;line-height:18px; margin-top:6px;"><a href="$post

 

['adurl']"><font color="#333333">$post['adcontent']</font></a></p>

        <p style="text-align: right;margin-top:8px; color:green;font-size:10pt;"> - <a

 

href="$post['adurl']" target="_blank"><font color=green>查看详情</font></a></p>

        </div>

        <!--{else}-->

                    <div align="right" style="background-image: url(/images/adbg.jpg);       

 

background-repeat: no-repeat;background-position: center center;padding: 4px;float:

 

right;text-align: left;height: 200px;width: 160px;margin: 4px;border: 1px solid

 

#666;background-color: #FFF;">

                <a href="http://www.flashmayi.com/" target="_blank"><font color="blue"><b>免

 

费在此投放广告(支持GGAD)</b></font></a><br>

        <p style="line-height:18px; margin-top:6px;font-size:10pt;color:#333;"><a

 

href="http://www.flashmayi.com/" target="_blank"><font color="#333333">只要在个人中心的“我

 

的广告”中设置自己的广告就可以显示在这里,完全免费,现在就开始吧!</font></a>

    </p>

        <p style="text-align: right;margin-top:8px; color:green;font-size:10pt;"> - <a

 

href="http://www.flashmayi.com/" target="_blank"><font color=green>查看详情</font></a></p>

        </div>

        <!--{/if}-->

    <!--{/if}-->

<!--{/if}-->

<!--贴内右侧广告结束 -->
复制代码打开文件:/templates/default/personal_navbar.htm,找到:<li><a href="memcp.php?action=profile&typeid=2">{lang memcp_profile}</a></li>
复制代码应该也可以找到两行,
在每行的下方添加代码:<li><a href="memcp.php?action=profile&typeid=3">我的广告</a></li>
复制代码上传背景图片:adbg.jpg到/images/下

最后到后台更新缓存就可以啦!
如果您的discuz论坛没有作过大的改动,可以直接下载附件,上传到相应的目录就行了,上传前记着添加数据库字段!
[/code]打开文件:/templates/default/personal_navbar.htm,找到:<li><a href="memcp.php?action=profile&typeid=2">{lang memcp_profile}</a></li>
复制代码应该也可以找到两行,
在每行的下方添加代码:<li><a href="memcp.php?action=profile&typeid=3">我的广告</a></li>
复制代码上传背景图片:adbg.jpg到/images/下

最后到后台更新缓存就可以啦!
如果您的discuz论坛没有作过大的改动,可以直接下载附件,上传到相应的目录就行了,上传前记着添加数据库字段!