群组

群组这块在整个phpwind体系中算是一块比较独立的功能,主要的代码都是放在apps/groups 目录下面的,再通过其他页面包含相关的功能代码进行执行。

其中action目录里面存放的是前台页面的代码,不同的action在不同的文件里面,看文件名就能知道了。

admin目录放的就是后台管理页面的代码了,这里也是按不同的请求分开不同的文件的。

Lib目录存放的是群组功能所需要用的到各种方法的类库,包括一些验证还有对数据库的增删改查等等的功能。

Template目录下存放的就是群组功能所有页面的模板了,也包括后台管理页面的模板,其中admin.htmadmin_ajax.htm是供后台使用的,其他模板在前台根据不同的action调用不同的模板,按文件名就能区分。

 

下面来说一说Lib目录下面这些类库的作用,其实对群组的大部分操作都是通过调用Lib目录下面的类来执行的,只要了解了这些类的作用和就能自己针对群组的功能做修改了。

 

Active.class.php                                 群组活动服务类

Activepost.class.php                           群组活动发布修改操作类

Colony.class.php                                群组类(主要与群组信息相关)

Colonypost.class.php                          组发布回复主题等操作类

Colonys.class.php                               群组公共服务

Colonyseo.class.php                            群组SEO

Group.class.php                                 群组首页相关操作

Groupstyle.class.php                           群组自有分类处理

Imgupload.class.php                           组图片上传相关处理

 

下面来介绍一下对群组的一些操作

增加一个群组(编辑跟增加的差不多)

 

//包含跟新用户信息的公用方法库

       require_once(R_P.'require/postfunc.php');

       //POST请求检查

       PostCheck(1,$o_groups_gdcheck,$o_groups_qcheck);

       //接收参数

       S::gp(array('cname','descrip'),'P');

       S::gp(array('cid','firstgradestyle','secondgradestyle'), 'P', 2);

       //验证群组名称是否合法

       (!$cname || strlen(stripslashes(html_entity_decode($cname,ENT_QUOTES))) > 20) && Showmsg('colony_emptyname');

       $descrip = str_replace('=' , '=', $descrip);

       //验证群组简介是否合法

       strlen(stripslashes(html_entity_decode($descrip,ENT_QUOTES))) > 255 && Showmsg('colony_descrip');

       //!$cid && Showmsg('colony_class');

       //下面是对填写内容的过滤

       require_once(R_P . 'require/bbscode.php');

       //敏感词过滤

       $wordsfb = L::loadClass('FilterUtil', 'filter');

       if (($banword = $wordsfb->comprise($cname)) !== false) {

           Showmsg('title_wordsfb');

       }

       if (($banword = $wordsfb->comprise($descrip)) !== false) {

           Showmsg('title_wordsfb');

       }

       //群组分类认证,判断是否选择了群组分类和分类是否存在

       $styleid = 0;

       $styles = array();

       if ($o_styledb) {

           if (!isset($o_style_relation[$firstgradestyle])) {

              Showmsg('请选择分类!');

           }

           if (empty($o_style_relation[$firstgradestyle])) {

              $styleid = $firstgradestyle;

              array_push($styles,$firstgradestyle);

           } else {

              !in_array($secondgradestyle, $o_style_relation[$firstgradestyle]) && Showmsg('请选择二级分类!');

              $styleid = $secondgradestyle;

              array_push($styles,$firstgradestyle,$secondgradestyle);

           }

       }

       /*

       if (empty($cid) || !isset($o_classdb[$cid])) {

           $cid = 0;

       }

       */

       //判断群组名称是否重复了

       $rt = $db->get_one("SELECT id FROM pw_colonys WHERE cname=".S::sqlEscape($cname));

       $rt['id'] > 0 && Showmsg('colony_samename');

       //积分变动

       if (!empty($o_groups_creditset['Creategroup'])) {

           $creditset = getCreditset($o_groups_creditset['Creategroup'],false);

           $credit->sets($winduid,$creditset,true);

           updateMemberid($winduid);

       }

       if ($creditlog = $o_groups_creditlog) {

           //记录积分日志

           addLog($creditlog['Creategroup'],$windid,$winduid,'groups_Creategroup');

       }

       //判断用户是否有权创建群组

       @asort($o_groups_levelneed);

       $commonLevel = key($o_groups_levelneed);

       empty($commonLevel) && Showmsg("系统未创建群组等级,无法创建群组!");

       S::gp(array('title1','title2','title3','title4'));

       $titlefont = S::escapeChar("$title1~$title2~$title3~$title4~$title5~$title6~");

       /**

       $db->update("INSERT INTO pw_colonys SET " . S::sqlSingle(array(

              'cname'       => $cname,

              //'classid'   => $cid,

              'styleid'  => $styleid,

              'commonlevel' => $commonLevel,

              'admin'       => $windid,

              'members'  => 1,

              'ifcheck'  => 2,

              'createtime'=> $timestamp,

              'descrip'  => $descrip,

              'titlefont' => $titlefont

       )));

       $cyid = $db->insert_id();

       **/

       //群组图标上次 这里调用群组的图片上传类

       require_once(A_P . 'groups/lib/imgupload.class.php');

       $img = new CnimgUpload($cyid);

       PwUpload::upload($img);

       pwFtpClose($ftp);

       //组装sql语句插入数据库 并更新相关信息

       $cyid = pwQuery::insert('pw_colonys', array(

              'cname'       => $cname,

              //'classid'   => $cid,

              'styleid'  => $styleid,

              'commonlevel' => $commonLevel,

              'admin'       => $windid,

              'members'  => 1,

              'ifcheck'  => 2,

              'createtime'=> $timestamp,

              'descrip'  => $descrip,

              'titlefont' => $titlefont

       ));

      

       $db->update("UPDATE pw_cnstyles SET csum=csum+1 WHERE id IN (" . S::sqlImplode($styles) . ')');

       if ($cnimg = $img->getImgUrl()) {

           $cnimg = substr(strrchr($cnimg,'/'),1);

           //* $db->update("UPDATE pw_colonys SET cnimg=".S::sqlEscape($cnimg)." WHERE id=".S::sqlEscape($cyid));

           $db->update(pwQuery::buildClause("UPDATE :pw_table SET cnimg=:cnimg WHERE id=:id", array('pw_colonys',$cnimg,$cyid)));

       }

       /**

       $db->update("INSERT INTO pw_cmembers SET " . S::sqlSingle(array(

              'uid'      => $winduid,

              'username' => $windid,

              'ifadmin'  => 1,

              'colonyid' => $cyid,

              'addtime'  => $timestamp

       )));

       **/

       pwQuery::insert('pw_cmembers', array(

              'uid'      => $winduid,

              'username' => $windid,

              'ifadmin'  => 1,

              'colonyid' => $cyid,

              'addtime'  => $timestamp

       ));

      

       updateUserAppNum($winduid,'group');

       $url = "apps.php?q=group&cyid=$cyid&a=set";

       $msg = defined('AJAX') ?  "success\t".$url : 'colony_regsuccess';

       refreshto("apps.php?q=group&cyid=$cyid&a=set",$msg);

 

解散群组

//验证用户信息

           S::gp(array('password'));

           $userService = L::loadClass('UserService', 'user'); /* @var $userService PW_UserService */

           $userinfo = $userService->get($winduid);

          

           if (md5($password) != $userinfo['password']) {

              Showmsg('您输入的密码不正确!');

           }

           //判断群组下面的照片是否已经删除

           if ($db->get_value("SELECT COUNT(*) as sum FROM pw_cnalbum WHERE atype=1 AND ownerid=" . S::sqlEscape($cyid)) > 0) {

              Showmsg('colony_del_photo');

           }

           //删除群组图片

           if ($colony['cnimg']) {

              pwDelatt("cn_img/$colony[cnimg]",$db_ifftp);

              pwFtpClose($ftp);

           }

           //删除群组信息  并且删除与这个群组相关的其他信息  有活动、话题等等

           $query = $db->query("SELECT uid FROM pw_cmembers WHERE colonyid=".S::sqlEscape($cyid)." AND ifadmin != '-1'");

           while ($rt = $db->fetch_array($query)) {

              $cMembers[] = $rt['uid'];

           }

           updateUserAppNum($cMembers,'group','minus');

           $db->update("DELETE FROM pw_cmembers WHERE colonyid=" . S::sqlEscape($cyid));

           //* $db->update("DELETE FROM pw_colonys WHERE id=" . S::sqlEscape($cyid));

           pwQuery::delete('pw_colonys', 'id=:id', array($cyid));

           $db->update("UPDATE pw_cnclass SET cnsum=cnsum-1 WHERE fid=" . S::sqlEscape($colony['classid']) . " AND cnsum>0");

           $db->update("DELETE FROM pw_argument WHERE cyid=" . S::sqlEscape($cyid));

           $db->update("DELETE FROM pw_active WHERE cid=" . S::sqlEscape($cyid));

 

           refreshto("apps.php?q=groups", '解散群组成功!');