/** * 判断用户的管理组权限 * @param int $uid */ public function getPermissionsForUserGroup($uid) { Wind::import('SRV:user.bo.PwUserBo'); $userBo = new PwUserBo($uid); $designPermission = $userBo->getPermission('design_allow_manage.push'); return $designPermission ? $designPermission : -1; }
/** * 判断是否有权限 * 删除全站或是本版帖子 * * @return int */ public function getRight() { if ($this->right) { return $this->right; } $this->right = array('delCurrentThread' => 0, 'delForumThread' => 0, 'delSiteThread' => 0); $permission = $this->loginUser->getPermission('operate_thread', false, array()); //如果是论坛斑竹,并且是操作的是自己的版块的帖子,则有删除选择,否则没有删除本版权限 if (isset($permission['delete']) && 1 == $permission['delete']) { $this->right['delCurrentThread'] = 1; $this->right['delSiteThread'] = 1; } elseif (5 == $this->loginUser->gid && $this->srv->isBM($this->srv->getFids())) { $permission = $this->loginUser->getPermission('operate_thread', true, array()); if (isset($permission['delete']) && $permission['delete'] == 1) { $this->right['delCurrentThread'] = 1; $this->right['delForumThread'] = 1; } } //如果所选用户不是全都是帖子发帖者,则删除当前帖子不可选 if (1 == $this->right['delCurrentThread']) { $threadUids = array(); foreach ($this->srv->getData() as $_item) { $threadUids[] = $_item['created_userid']; } if (array_diff(array_keys($this->getBanUsers()), $threadUids)) { $this->right['delCurrentThread'] = 0; } } return $this->right; }
public function __construct($tid, $pids, PwUserBo $user, $isLazy = false) { $this->user = $user; $this->attachs = $this->_getData($tid, $pids); $this->isAdmin = $user->getPermission('operate_thread.deleteatt'); $this->imgWidth = Wekit::C('bbs', 'ubb.img.width'); $this->imgHeight = Wekit::C('bbs', 'ubb.img.height'); $this->imgLazy = $isLazy; $this->_init(); }
public function beforeAction($handlerAdapter) { $this->_m = $handlerAdapter->getModule(); $this->_c = $handlerAdapter->getController(); $this->_a = $handlerAdapter->getAction(); $this->_mc = $this->_m . '/' . $this->_c; $this->_mca = $this->_mc . '/' . $this->_a; $this->_setPreCache($this->_m, $this->_mc, $this->_mca); $this->loginUser = Wekit::getLoginUser(); $this->_setPreHook($this->_m, $this->_mc, $this->_mca); $config = Wekit::C('site'); if ($config['visit.state'] > 0) { $service = Wekit::load('site.srv.PwSiteStatusService'); $resource = $service->siteStatus($this->loginUser, $config); if ($resource instanceof PwError) { if (!($config['visit.state'] == 1 && $this->_mc == 'u/login')) { $this->showError($resource->getError()); } } } if (!in_array($this->_mc, array('u/login', 'u/register', 'u/findPwd')) && !$this->loginUser->getPermission('allow_visit')) { if ($this->loginUser->isExists()) { if ($this->_mca != 'u/login/logout') { $this->showError(array('permission.visit.allow', array('{grouptitle}' => $this->loginUser->getGroupInfo('name')))); } } else { $this->forwardAction('u/login/run'); } } if ($config['refreshtime'] > 0 && Wind::getApp()->getRequest()->isGet() && !Wind::getApp()->getRequest()->getIsAjaxRequest()) { if (Wekit::app()->lastRequestUri == Wekit::app()->requestUri && Wekit::app()->lastvisit + $config['refreshtime'] > Pw::getTime()) { $this->showError('SITE:refresh.fast'); } } $debug = $config['debug'] || !$config['css.compress']; Wekit::setGlobal(array('debug' => $debug ? '/dev' : '/build'), 'theme'); $this->setTheme('site', null); }
public function doeditAction() { $designId = (int) $this->getInput('design_id', 'post'); $designType = (int) $this->getInput('design_type', 'post'); $new_permissions = $this->getInput('new_permissions', 'post'); $new_username = $this->getInput('new_username', 'post'); $ids = $this->getInput('ids', 'post'); $permissions = $this->getInput('permissions', 'post'); $fail = 0; $ds = $this->_getPermissionsDs(); //添加新用户 前端已修改为单用户提交 if ($new_username) { Wind::import('SRV:design.srv.vo.PwDesignPermissionsSo'); Wind::import('SRV:user.bo.PwUserBo'); $service = $this->_getPermissionsService(); foreach ($new_username as $k => $name) { if (!$name) { continue; } $user = Wekit::load('user.PwUser')->getUserByName($name); $new_uid = isset($user['uid']) ? $user['uid'] : 0; if ($new_uid < 1) { $this->showError("DESIGN:user.name.error"); } $vo = new PwDesignPermissionsSo(); $vo->setDesignId($designId)->setDesignType($designType)->setUid($new_uid); $list = $ds->searchPermissions($vo); if ($list) { $this->showError("DESIGN:user.already.permissions"); } if ($service->getPermissionsForUserGroup($new_uid) < 0) { $this->showError("DESIGN:user.group.error"); } $userBo = new PwUserBo($new_uid); $designPermission = $userBo->getPermission('design_allow_manage.push'); if ($designPermission < 1) { $this->showError("DESIGN:user.group.error"); } $resource = $ds->addInfo($designType, $designId, $new_uid, $new_permissions[$k]); if (!$resource) { $fail++; } } } foreach ($ids as $k => $id) { $resource = $ds->updatePermissions($id, $permissions[$k]); if (!$resource) { $fail++; } } $this->showMessage("operate.success"); }
/** * 检测今日发消息数量 * * @param PwUserBo $user * @param int $countUser * @return PwError | bool */ private function _checkTodayNum(PwUserBo $user, $touids) { !is_array($touids) && ($touids = array($touids)); $behavior = $this->_getUserBehaviorDs()->getBehavior($user->uid, 'message_today'); $dayMax = $user->getPermission('message_max_send'); $countUser = count($touids); if ($behavior['number'] + $countUser > $dayMax) { $touids = array_slice($touids, 0, $dayMax - $behavior['number']); } return array($touids, $behavior['number'], $dayMax); }
public function buyAction() { list($tid, $pid) = $this->getInput(array('tid', 'pid')); $submit = (int) $this->getInput('submit', 'get'); if (!$this->loginUser->isExists()) { $this->showError('login.not'); } if (!$tid) { $this->showError('data.error'); } if ($pid) { $result = Wekit::load('forum.PwThread')->getPost($pid); } else { $pid = 0; $result = Wekit::load('forum.PwThread')->getThread($tid, PwThread::FETCH_ALL); } if (empty($result) || $result['tid'] != $tid) { $this->showError('data.error'); } $start = strpos($result['content'], '[sell='); if ($start === false) { $this->showError('BBS:thread.buy.error.sell.not'); } $start += 6; $end = strpos($result['content'], ']', $start); $cost = substr($result['content'], $start, $end - $start); list($creditvalue, $credittype) = explode(',', $cost); Wind::import('SRV:credit.bo.PwCreditBo'); $creditBo = PwCreditBo::getInstance(); isset($creditBo->cType[$credittype]) || ($credittype = key($creditBo->cType)); $creditType = $creditBo->cType[$credittype]; if ($result['created_userid'] == $this->loginUser->uid) { $this->showError('BBS:thread.buy.error.self'); } if (Wekit::load('forum.PwThreadBuy')->get($tid, $pid, $this->loginUser->uid)) { $this->showError('BBS:thread.buy.error.already'); } if (($myCredit = $this->loginUser->getCredit($credittype)) < $creditvalue) { $this->showError(array('BBS:thread.buy.error.credit.notenough', array('{myCredit}' => $myCredit . $creditType, '{count}' => $creditvalue . $creditType))); } !$submit && $this->showMessage(array('BBS:thread.buy.message.buy', array('{count}' => $myCredit . $creditType, '{buyCount}' => -$creditvalue . $creditType))); Wind::import('SRV:forum.dm.PwThreadBuyDm'); $dm = new PwThreadBuyDm(); $dm->setTid($tid)->setPid($pid)->setCreatedUserid($this->loginUser->uid)->setCreatedTime(Pw::getTime())->setCtype($credittype)->setCost($creditvalue); Wekit::load('forum.PwThreadBuy')->add($dm); $creditBo->addLog('buythread', array($credittype => -$creditvalue), $this->loginUser, array('title' => $result['subject'] ? $result['subject'] : Pw::substrs($result['content'], 20))); $creditBo->set($this->loginUser->uid, $credittype, -$creditvalue, true); $user = new PwUserBo($result['created_userid']); if (($max = $user->getPermission('sell_credit_range.maxincome')) && Wekit::load('forum.PwThreadBuy')->sumCost($tid, $pid) > $max) { } else { $creditBo->addLog('sellthread', array($credittype => $creditvalue), $user, array('title' => $result['subject'] ? $result['subject'] : Pw::substrs($result['content'], 20))); $creditBo->set($user->uid, $credittype, $creditvalue, true); } $creditBo->execute(); if ($pid) { Wind::import('SRV:forum.dm.PwReplyDm'); $dm = new PwReplyDm($pid); $dm->addSellCount(1); Wekit::load('forum.PwThread')->updatePost($dm); } else { Wind::import('SRV:forum.dm.PwTopicDm'); $dm = new PwTopicDm($tid); $dm->addSellCount(1); Wekit::load('forum.PwThread')->updateThread($dm, PwThread::FETCH_CONTENT); } $this->showMessage('success', 'bbs/read/run/?tid=' . $tid . '&fid=' . $result['fid'], true); }
/** * 获得用户拥有的权限 //这个权限在读贴子详细内容时获取,此接口暂时不用 * * @access public * @return void * @example * <pre> * post: tid * </pre> */ private function permissionAction() { $tid = $this->getInput('tid'); $userBo = new PwUserBo($this->uid); Wind::import('SRV:forum.srv.PwThreadDisplay'); $threadDisplay = new PwThreadDisplay($tid, $userBo); $this->runHook('c_read_run', $threadDisplay); if (($result = $threadDisplay->check()) !== true) { $this->showError($result->getError()); } $_cache = Wekit::cache()->fetch(array('level', 'group_right')); $pwforum = $threadDisplay->getForum(); $isBM = $pwforum->isBM($userBo->username); if ($threadPermission = $userBo->getPermission('operate_thread', $isBM, array())) { $operateThread = Pw::subArray($threadPermission, array('delete', 'ban')); $operateReply = Pw::subArray($threadPermission, array('delete', 'ban')); } /** * if ($hasFirstPart || $hasSecondPart || $hasThirdPart) //只要是版主都可以推荐 * $operateThread['delete'] * $operateReply['ban'] */ // print_r($operateThread); // print_r($operateReply); }
/** * 获取帖子类型 * * @param PwUserBo $user * @return array */ public function getThreadType(PwUserBo $user) { if (!is_array($this->forumset['typeorder'])) { return array(); } asort($this->forumset['typeorder']); $array = array(); $tType = Wekit::load('forum.srv.PwThreadType')->getTtype(); foreach ($this->forumset['typeorder'] as $key => $value) { if (isset($tType[$key]) && in_array($key, $this->forumset['allowtype']) && ($tType[$key][2] === true || $user->getPermission($tType[$key][2]))) { $array[$key] = $tType[$key]; } } return $array; }
protected function _operateBuyCredit($attach) { $user = Wekit::getLoginUser(); if (!$attach['cost'] || $attach['created_userid'] == $user->uid) { return false; } Wind::import('SRV:credit.bo.PwCreditBo'); $creditBo = PwCreditBo::getInstance(); Wind::import('SRV:attach.dm.PwThreadAttachBuyDm'); $dm = new PwThreadAttachBuyDm(); $dm->setAid($attach['aid'])->setCreatedUserid($user->uid)->setCreatedTime(Pw::getTime())->setCtype($attach['ctype'])->setCost($attach['cost']); Wekit::load('attach.PwThreadAttachBuy')->add($dm); $creditBo->addLog('attach_buy', array($attach['ctype'] => -$attach['cost']), $user, array('name' => $attach['name'])); $creditBo->set($user->uid, $attach['ctype'], -$attach['cost'], true); $user = new PwUserBo($attach['created_userid']); if (($max = $user->getPermission('sell_credit_range.maxincome')) && Wekit::load('attach.PwThreadAttachBuy')->sumCost($attach['aid']) > $max) { } else { $creditBo->addLog('attach_sell', array($attach['ctype'] => $attach['cost']), $user, array('name' => $attach['name'])); $creditBo->set($user->uid, $attach['ctype'], $attach['cost'], true); } $creditBo->execute(); }
/** * 判断用户是否可以购买邀请码 * * @param PwUserBo $user 购买的用户 * @param int $num 购买的数量 * @param int $creditType 用于购买的积分类型 * @return boolean|PwError */ public function allowBuyInviteCode(PwUserBo $user, $num, $creditType) { if (!WindValidator::isPositive($num)) { return new PwError('USER:invite.buy.num.error'); } $num = intval($num); //用户组能购买的邀请码数量限制 $startTime = Pw::str2time(Pw::time2str(Pw::getTime(), 'Y-m-d')); $readyBuy = $this->_getDs()->countByUidAndTime($user->uid, $startTime); $gidLimit = abs(ceil($user->getPermission('invite_limit_24h'))); if ($readyBuy + $num > $gidLimit) { return new PwError('USER:invite.buy.num.24h.limit', array('{num}' => $gidLimit, '{readynum}' => $readyBuy)); } $price = abs(ceil($user->getPermission('invite_buy_credit_num'))); if ($price * $num > $user->getCredit($creditType)) { return new PwError('USER:invite.buy.credit.no.enough', array('{num}' => $user->getCredit($creditType), '{buynum}' => $num)); } return true; }