dz插件开发(一) 从常用的常量 变量 函数开始
从常用的常量 变量 函数开始
函数和变量我尽量都打印出来看看是些什么东西
一:常量 变量
1 $_G 里面什么都有 自己打印出来看看就知道
2 $_G['uid'] 当前用户的uid,可以用于判断用户是否登录
3 $_G['groupid'] 判断用户的会员组,用于权限管理,打印出来是数字,比如1 2 3
4 FORMHASH 随机字串 一般用于表单提交 打印:8fcdd1b9
5 待续
二:函数
1 showmessage($message,$urlforward) 前台的提示信息,像美化过的alert 默认一个参数就行
2 cpmsg() 后台的提示信息
3 获取当前用户的信息
(1)基本信息 可以直接
$result=DB::fetch_all("select * from ".DB::table('common_member')." where uid ={$_G['uid']}")
这样可以得到一些基本信息
pre_common_member_count可以得到其具体积分信息
(2)通过函数getuserprofile
这个函数只能获得某一个filed的信息,比如extcredits2
$profile=getuserprofile('extcredits2'); //得到97,97刚好为我当前用户extcredits2积分的数量,用函数比查表来的方便点 //此函数还可以查很多东西,具体可以参见其函数的代码 static $tablefields = array( 'count' => array('extcredits1','extcredits2','extcredits3','extcredits4','extcredits5','extcredits6','extcredits7','extcredits8','friends','posts','threads','digestposts','doings','blogs','albums','sharings','attachsize','views','oltime','todayattachs','todayattachsize', 'follower', 'following', 'newfollower', 'blacklist'), 'status' => array('regip','lastip','lastvisit','lastactivity','lastpost','lastsendmail','invisible','buyercredit','sellercredit','favtimes','sharetimes','profileprogress'), 'field_forum' => array('publishfeed','customshow','customstatus','medals','sightml','groupterms','authstr','groups','attentiongroup'), 'field_home' => array('videophoto','spacename','spacedescription','domain','addsize','addfriend','menunum','theme','spacecss','blockposition','recentnote','spacenote','privacy','feedfriend','acceptemail','magicgift','stickblogs'), 'profile' => array('realname','gender','birthyear','birthmonth','birthday','constellation','zodiac','telephone','mobile','idcardtype','idcard','address','zipcode','nationality','birthprovince','birthcity','resideprovince','residecity','residedist','residecommunity','residesuite','graduateschool','company','education','occupation','position','revenue','affectivestatus','lookingfor','bloodtype','height','weight','alipay','icq','qq','yahoo','msn','taobao','site','bio','interest','field1','field2','field3','field4','field5','field6','field7','field8'), 'verify' => array('verify1', 'verify2', 'verify3', 'verify4', 'verify5', 'verify6', 'verify7'), ); //数组中的都可以做参数来查询
4 积分操作 目前用到两个
(1)updatecreditbyaction
/** * 执行积分规则 * @param String $action: 规则action名称 * @param Integer $uid: 操作用户 * @param array $extrasql: common_member_count的额外操作字段数组格式为 array('extcredits1' => '1') * @param String $needle: 防重字符串 * @param Integer $coef: 积分放大倍数 * @param Integer $update: 是否执行更新操作 * @param Integer $fid: 版块ID * @return 返回积分策略 */ function updatecreditbyaction($action, $uid = 0, $extrasql = array(), $needle = '', $coef = 1, $update = 1, $fid = 0) { ...... }
使用如下:
updatecreditbyaction('扣积分extcredits2',$uid,array('extcredits2'=>-1)); //会将extcredits2积分扣除1
(2)updatemembercount
/** * 添加积分 * @param Integer $uids: 用户uid或者uid数组 * @param String $dataarr: member count相关操作数组,例: array('threads' => 1, 'doings' => -1) * @param Boolean $checkgroup: 是否检查用户组 true or false * @param String $operation: 操作类型 * @param Integer $relatedid: * @param String $ruletxt: 积分规则文本 */ function updatemembercount($uids, $dataarr = array(), $checkgroup = true, $operation = '', $relatedid = 0, $ruletxt = '') { if(!emptyempty($uids) && (is_array($dataarr) && $dataarr)) { require_once libfile('function/credit'); return _updatemembercount($uids, $dataarr, $checkgroup, $operation, $relatedid, $ruletxt); } return true; }
主要还是_updatemembercount这个函数 ,看了下这个函数对参数$dataarr的处理
//有这么一段 foreach($dataarr as $key => $val) { if(empty($val)) continue; $val = intval($val); $id = intval($key); $id = !$id && substr($key, 0, -1) == 'extcredits' ? intval(substr($key, -1, 1)) : $id; if(0 < $id && $id < 9) { $data['extcredits'.$id] = $val; if($writelog) { $log['extcredits'.$id] = $val; } } else { $data[$key] = $val; } } /* substr($key, 0, -1) 截取掉最后一个字符的意思,一般用于比如extcredits2去掉2,得到extcredits 当满足这个条件的时候 $id得到extcredits2后的这个2 即$id=2 然后$data['extcredits'.$id] = $val; 修改对应的积分为$val值 所以 这么执行 */
updatemembercount($uid,array('extcredits2'=>-1)); //同样使extcredits2积分减1
5 未完待续