去评论
dz插件网

discuzx 3.5 x3.4开发手册-常用函数和模板调用方法[长期更新]

admin
2021/09/08 17:27:25
登录
  1. <a href="member.php?mod=logging&action=login" title="登录">登录</a>

注册
  1. <a href="member.php?mod=register" title="立即注册">立即注册</a>

忘记密码
  1. <a href="javascript:;" title="找回密码">找回密码</a>

购买邀请码
  1. misc.php?mod=buyinvitecode

JS跳转
  1. onclick="window.location.href='home.php?mod=mobile&do=friend';"

JS更换class的名称
  1. document.getElementById('idname').className='a';
  2. document.getElementById('idname').style.display='block';
  3. document.getElementById("idname").style.marginTop="30px";

批量替换超链接:
  1. href="[^"]*"

过滤DZ代码:
  1. preg_replace ("/\[[a-z][^\]]*\]|\[\/[a-z]+\]/i",'',preg_replace("/\[attach\]\d+\[\/attach\]/i",'',$message));

调用单个数据
  1. $a = DB::result(DB::query("SELECT qi FROM ".DB::table('abc')." WHERE id = '1'"));

调用统计数据
  1. $a = DB::result(DB::query("SELECT count(*) FROM ".DB::table('abc')." WHERE id = '1'"));

单数据表调用
  1. $perpage = 20;
  2. $curpage = empty ( $_GET['page'] ) ? 1 : intval ( $_GET['page'] );
  3. $start = ($curpage-1)*$perpage;
  4. $askcount = DB::result(DB::query("SELECT COUNT(*) FROM ".DB::table('forum_thread')." WHERE fid = '2' AND authorid > 1"));
  5. //$asklist
  6. $asklist = array();
  7. if ($askcount) {
  8.         $query = DB::query("SELECT * FROM ".DB::table('forum_thread')." WHERE fid = '2' AND displayorder > -1 ORDER BY tid ASC LIMIT $start,$perpage");
  9.         while ($value = DB::fetch($query)) {
  10.                 $asklist[] = $value;
  11.         }
  12. }
  13. $multi = multi($askcount, $perpage, $curpage, "这里填写跳转地址");



多数据表调用
  1. $perpage = 40;
  2. $curpage = empty ( $_GET['page'] ) ? 1 : intval ( $_GET['page'] );
  3. $start = ($curpage-1)*$perpage;
  4. $acount = DB::result(DB::query("SELECT count(*) FROM ".DB::table('forum_forum')." b LEFT JOIN ".DB::table('forum_forumfield')." bf ON bf.fid=b.fid WHERE b.type='sub' AND b.status = 3 AND bf.icon != ''"));
  5. //$alist
  6. $alist = array();
  7. if ($acount) {
  8.         $query = DB::query("SELECT bf.*, b.* FROM ".DB::table('forum_forum')." b LEFT JOIN ".DB::table('forum_forumfield')." bf ON bf.fid=b.fid WHERE b.type='sub' AND b.status = 3 AND bf.icon != '' ORDER BY bf.shoplevel DESC, b.commoncredits DESC, bf.fid DESC LIMIT $start,$perpage");
  9.         while ($value = DB::fetch($query)) {
  10.                 $alist[] = $value;
  11.         }
  12. }
  13. $multi = multi($acount, $perpage, $curpage, "这里填写跳转地址");



前台数据显示
  1. <!--{loop $alist $key $value}-->
  2. <!--{eval $tupianfm = DB::result(DB::query("SELECT attachment FROM ".DB::table('forum_threadimage')." WHERE tid = '$value[tid]'"));}-->
  3. <img src="$tupianfm"><br>$value[authorid]
  4. <!--{/loop}-->


取数据表中符合条件的第一条数据
  1. $app=array();
  2. $app=DB::fetch_first("select * from ".DB::table('abc')." where id='{$id}'");



人性化时间戳
  1. <!--{echo dgmdate(这里填写时间参数, 'u', '9999', getglobal('setting/dateformat'))}-->
  2. <!--{echo date("Y-m/d H:i:s",这里填写时间参数)}-->


截取字符字数
  1. <!--{echo cutstr(这里填写参数,40)}-->


过滤DISCUZ代码
  1. preg_replace ("/\[[a-z][^\]]*\]|\[\/[a-z]+\]/i",'',preg_replace("/\[attach\]\d+\[\/attach\]/i",'',$message));


写入数据库
  1. if(submitcheck('tijiao')) {
  2.         $setarr = array(
  3.                 'tid' => $_GET['topicid'],
  4.                 'name' => $_POST['name'],
  5.                 'position' => $_GET['position'],
  6.                 'dateline' => $_G['timestamp'],
  7.         );
  8.         DB::insert('abc', $setarr, 1);
  9.         $query = DB::query("UPDATE ".DB::table('abc')." SET stickreply='1' WHERE tid='$tid'");
  10.         $query = DB::query("DELETE FROM ".DB::table('abc')." WHERE pid='$pid'");
  11.         showmessage('成功的提示信息', "跳转地址");
  12. }



表单提交:
  1. <form action="do.php" method="post" autocomplete="off">
  2.         <input type="hidden" value="{FORMHASH}" name="formhash" />
  3.         最低奖金:<input name="qi" type="text" value="" /> 
  4.         最高奖金:<input name="end" type="text" value="" />  
  5.         <button value="true" name="tijiao" type="submit">提交设置</button>
  6.         <input type="hidden" name="tijiao" value="true" />
  7. </form>



以下两个时间格式是对等关系
  1. date("Ymd",time());  20150212
  2. FROM_UNIXTIME(dateline, '%Y%m%d')

前者用于PHP,后者用于数据库调用的字段的格式化

调用图片附件
  1. <!--{eval $biaoid = substr($value[tid], -1); $cover = DB::result(DB::query("SELECT attachment FROM ".DB::table('forum_attachment_'.$biaoid.'')." WHERE tid = '$value[tid]'"));}-->


数据库循环嵌套调用
  1. <!--{eval $slides = DB::fetch_all("SELECT * FROM ".DB::table('a')." WHERE `uid`= $_G[uid] ORDER BY `id` DESC");}-->
  2. <!--{loop $slides $slide}-->
  3. $slide[name]
  4. <!--{/loop}-->


ucenter无法登录:
  1. 打开uc_server/model/admin.php
  2. 找到第22行的
  3. $this->cookie_status = 0;


改成
  1. $this->cookie_status = isset($_COOKIE['sid']) ? 1 : 0;



无刷新切换li标签并且同时加载框架页面:
  1. <script type="text/javascript">
  2. var jq = jQuery.noConflict();
  3. jq(function(){
  4. jq("#changemenu>li").mouseover(function(){
  5. jq("#changemenu>li").each(function(i){
  6. jq(this).removeClass("current");
  7. });
  8. jq(this).addClass("current");
  9. document.getElementById("changenr").innerHTML='<iframe src="do.php?id='+jq(this).attr('dataid')+'" height="350" width="1070" frameborder="0" scrolling="no"></iframe>';
  10. }).mouseout(function(){
  11. jq(this).addClass("current");
  12. });
  13. });
  14. </script>
  15. <ul id="changemenu">
  16.    <li class="current" dataid="1"></li>
  17.    <li dataid="2"></li>
  18. </ul>
  19. <div id="changenr"></div>



快速发帖
  1. <a href="forum.php?mod=misc&action=nav">发布新话题</a>



DISCUZ JSON数据解析获取
  1. $str = 'a:2:{s:8:"sitename";s:8:"dz插件网";s:3:"pic";s:12:"ymg6.jpg";}';
  2. $newstr = str_replace("","",$str);
  3. $data = unserialize($newstr);
  4. echo $data[sitename];//输出结果为dz插件网



DISCUZ云平台站点同步提示DNS错误解决方法:打开source\plugin\manyou\Service\Client\Restful.php,找到代码:
  1. $result = $this->_fsockopen($url, 0, $data, '', false, $ip, 5);


修改为:
  1. $result = $this->_fsockopen($url, 0, $data, '', false, $ip, 30);



LI标签列表自适应宽度JS实现代码(去除每行最后一个li标签的右边距):
  1. <script type="text/javascript" src="http://www.banban.so/new/bang/uploads/146383669567393.js"></script>
  2. <style>ul,li{margin:0; padding:0; list-style:none;}.list{width:100%; margin:0 auto;}.list li{width:32%; float:left; margin-right:2%; background:#0092B9; text-align:center; color:#fff; height:300px; line-height:300px; margin-bottom:10px;}</style>
  3. <div class="list">
  4.         <ul>
  5.         <li>dz插件网</li>
  6.         <li>dz插件网</li>
  7.         <li>dz插件网</li>
  8.         <li>dz插件网</li>
  9.         <li>dz插件网</li>
  10.         <li>dz插件网</li>
  11.     </ul>
  12. </div>
  13. <script type="text/javascript">
  14.     $('.list li:nth-child(3n)').css('marginRight', '0');
  15. </script>



常用词汇
  1. select 选择
  2. count 总数
  3. table 表
  4. where 条件
  5. result 结果
  6. perpage 每页
  7. curpage 当前页
  8. update 更新
  9. delete 删除
  10. insert 写入
  11. dateline 日期
  12. time 时间
  13. echo 输出   <?php   echo '123';   ?>
  14. multi 分页函数
  15. if 如果
  16. else 否则
  17. elseif
  18. start 起始
  19. limit 限制  limit 10
  20. DESC 倒序
  21. ASC 正序



活动帖发布页面核心处理文件:
  1. source\class\extend\extend_thread_activity.php

分类信息解析文件
  1. source\function\function_threadsort.php
Discuz模版运行php代码
  1. <!--{eval echo'dz插件网';}-->
  1. <!--{eval}-->
  2. echo'dz插件网';
  3. <!--{/eval}-->
标签获得焦点后触发js
  1. onfocus="ymgcom()"


标签失去焦点后触发js
  1. onblur="ymgcom();"


密码输出1*****6
  1. //原密码为$_GET['password']
  2. $password = preg_replace("/^(.{".round(strlen($_GET['password']) / 4)."})(.+?)(.{".round(strlen($_GET['password']) / 6)."})$/s", "\\1***\\3", $_GET['password']);
  3. echo $password;
常用:
获取数组
  1. $a = DB::fetch_all("SELECT title FROM ".DB::table('abc')." WHERE uid = '".$uid."'");




获取对应数据表中一条数据的值返回为数组
  1. $a = DB::fetch(DB::query("SELECT * FROM ".DB::table('abc')." WHERE id = '".$id."'"));
仅有数据的调用返回为字符串
  1. $a = DB::result(DB::query("SELECT qi FROM ".DB::table('abc')." WHERE id = '1'"));
统计数据返回为int
  1. $a = DB::result(DB::query("SELECT count(*) FROM ".DB::table('abc')." WHERE id = '1'"));
写入数据(表名,键值数组,条件)
  1. DB::insert('abc', $setarr, 1);
更新数据(表名,键值数组,条件)
  1. DB::update('abc', $setarr, 1);
删除数据(表名,键值数组,条件)
  1. DB::delete('abc', $setarr, 1);
其他不怎么用的手册
  1. DB::table($table) //获取带前缀的表名  
  2. DB::delete($table, $condition, $limit = 0, $unbuffered = true) //删除数据  
  3. DB::insert($table, $data, $return_insert_id = false, $replace = false, $silent = false) //插入数据  
  4. DB::update($table, $data, $condition, $unbuffered = false, $low_priority = false)//更新  
  5. DB::insert_id()//返回插件的自增长id  
  6. DB::fetch_first($sql, $arg = array(), $silent = false) //取查询的第一条数据fetch  
  7. DB::fetch_all($sql, $arg = array(), $keyfield = '', $silent=false) //查询并fetch  
  8. DB::result_first($sql, $arg = array(), $silent = false)//查询结果集的第一个字段值  
  9. DB::query($sql, $arg = array(), $silent = false, $unbuffered = false) //普通查询 一条sql语句
  10. DB::limit($start, $limit = 0) //limit条件  
  11. DB::order($field, $order = 'ASC')//返回排序  
  12. DB::field($field, $val, $glue = '=')//返回字段条件 $val可以为数组  
数据库类定义\source\class\table\
  1. C::t('tablename')->method();
插件新增的目录使用方法mytablename
在目录:source/plugin/mypluginid/table/table_mytablename.php
使用类名称:table_mytablename
使用最佳时间:
  1. C::t('#mypluginid#mytablename')->method();

数据库常用方法
常用词
选择选择;总数;表格表;条件在哪里;结果结果;每页每页;当前页;更新更新;删除删除;插入写入;日期时间页;时间时间;多分函数;如果;否则;开始视线;限制限制;DESC倒序;ASC正序;

调用单条数据
  1. $qishi = DB::result(DB::query("SELECT qi FROM " .DB::table('jiangchi')."WHERE id = '1'));
  2. $qishi ;qi: 字段;jiangchi :表;id = 1 :条件;
调用统计数据
  1. $qishi = DB::result(DB::query("SELECT count(*) FROM " .DB::table('jiangchi')."WHERE id = '1'));
单数据表调用
  1. $perpage = 20;//页数
  2. $curpage = empty ( $_GET['page'] ) ? 1 : intval ( $_GET['page'] );//获取当前页代码
  3. $start = ($curpage-1)*$perpage;//获取起始数据
  4. $askcount = DB::result(DB::query("SELECT COUNT(*) FROM ".DB::table('forum_thread')." WHERE fid = '2' AND authorid > 1 AND FROM_UNIXTIME(dateline, '%Y%m%d') = '$jintian'"));
  5. //$asklist
  6. $asklist = array();
  7. if ($askcount) {//如果有数据
  8.     $query = DB::query("SELECT * FROM ".DB::table('forum_thread')." WHERE fid = '2' AND displayorder > -1 ORDER BY tid ASC LIMIT $start,$perpage");//根据tid正序排序,limit起始到显示
  9.     while ($value = DB::fetch($query)) {
  10.         $asklist[] = $value;
  11.     }
  12. }
  13. $multi = multi($askcount, $perpage, $curpage, "portal.php?mod=topic&topic=ask");
获取数组
  1. $add = DB::fetch_first("SELECT * FROM ".DB::table('peach_webmaster')." WHERE uid=".$uid);
多数据表调用
  1. $perpage = 40;
  2. $curpage = empty ( $_GET['page'] ) ? 1 : intval ( $_GET['page'] );
  3. $start = ($curpage-1)*$perpage;
  4. $acount = DB::result(DB::query("SELECT count(*) FROM ".DB::table('forum_forum')." b LEFT JOIN ".DB::table('forum_forumfield')." bf ON bf.fid=b.fid WHERE b.type='sub' AND b.status = 3 AND bf.icon != ''"));
  5. //$alist
  6. $alist = array();
  7. if ($acount) {
  8.     $query = DB::query("SELECT bf.*, b.* FROM ".DB::table('forum_forum')." b LEFT JOIN ".DB::table('forum_forumfield')." bf ON bf.fid=b.fid WHERE b.type='sub' AND b.status = 3 AND bf.icon != '' ORDER BY bf.shoplevel DESC, b.commoncredits DESC, bf.fid DESC LIMIT $start,$perpage");
  9.     while ($value = DB::fetch($query)) {
  10.         $alist[] = $value;
  11.     }
  12. }
  13. $multi = multi($acount, $perpage, $curpage, "这里填写跳转地址");
前台数据显示
  1. <!--{loop $alist $key $value}-->
  2. <!--{eval $tupianfm = DB::result(DB::query("SELECT attachment FROM ".DB::table('forum_threadimage')." WHERE tid = '$value[tid]'"));}-->
  3. $value[authorid]
  4. <!--{/loop}-->
人性化时间
  1. <!--{echo dgmdate(这里填写时间参数, 'u', '9999', getglobal('setting/dateformat'))}-->
  2. <!--{echo date("Y-m/d H:i:s",这里填写时间参数)}-->
截取字符数
  1. <!--{echo cutstr(这里填写参数,40)}-->
写入数据库
  1. if(submitcheck('tijiao')) {
  2.     $setarr = array(
  3.         'tid' => $_GET['topicid'],
  4.         'name' => $_POST['name'],
  5.         'position' => $_GET['position'],
  6.         'dateline' => $_G['timestamp'],
  7.     );
  8.     DB::insert('forum_poststick', $setarr, 1);
  9.     $query = DB::query("UPDATE ".DB::table('forum_thread')." SET stickreply='1'
  10.         WHERE tid='$tid'");
  11.     $query = DB::query("DELETE FROM ".DB::table('forum_post')."
  12.         WHERE pid='$pid'");
  13.     showmessage('成功的提示信息', "forum.php?mod=viewthread&tid=$tid");
  14. }
更新数据库
  1.         $setarr = array(
  2.             'uid' => $uid,
  3.             'name' => $name,
  4.             'url' => $url,
  5.             'datatime' => $datatime,
  6.         );
  7.         DB::update('peach_webmaster',$setarr,1);
表单提交:
  1. <form action="do.php?op=jiangchi&con=yes" method="post" autocomplete="off">
  2.     <input type="hidden" value="{FORMHASH}" name="formhash" />
  3.     最低奖金:<input name="qi" type="text" value="$qishi" /> 
  4.     最高奖金:<input name="end" type="text" value="$zhzh" />  
  5.     <button value="true" name="tijiao" type="submit">提交设置</button>
  6.     <input type="hidden" name="tijiao" value="true" />
  7. </form>
以下两个时间格式是对等关系
  1. date("Ymd",time()); 20150212
  2. FROM_UNIXTIME(dateline, '%Y%m%d')
用于PHP,用于后期数据库调用的事件的发生

调用图片附件
  1. <!--{eval $biaoid = substr($value[tid], -1); $cover = DB::result(DB::query("SELECT attachment FROM ".DB::table('forum_attachment_'.$biaoid.'')." WHERE tid = '$value[tid]'"));}-->