} } if (!empty($_G['gp_newuser'])) { $value = DB::fetch_first("SELECT uid FROM " . DB::table('common_member') . " WHERE username='******'gp_newuser']}'"); if ($value) { $user['uid'] = $value['uid']; $user['allowmanage'] = $_G['gp_newallowmanage'] ? 1 : 0; $user['allowrecommend'] = $_G['gp_newallowrecommend'] ? 1 : 0; $user['needverify'] = $_G['gp_newneedverify'] ? 1 : 0; $users[$user['uid']] = $user; } else { cpmsg_error($_G['gp_newuser'] . cplang('block_has_no_allowauthorizedblock')); } } require_once libfile('class/blockpermission'); $blockpermsission =& block_permission::instance(); if (!empty($users)) { $blockpermsission->add_users_perm($bid, $users); } if (!empty($_G['gp_delete'])) { $blockpermsission->delete_users_perm($bid, $_G['gp_delete']); } $notinherited = !$_POST['inheritance'] ? '1' : '0'; if ($notinherited != $block['notinherited']) { if ($notinherited) { $blockpermsission->delete_inherited_perm_by_bid($bid); } else { $blockpermsission->remake_inherited_perm($bid); } DB::update('common_block', array('notinherited' => $notinherited), array('bid' => $bid)); }
function getblockperm($bid) { global $_G; $perm = array('allowmanage' => '0', 'allowrecommend' => '0', 'needverify' => '1'); $bid = max(0, intval($bid)); if (!$bid) { return $perm; } $allperm = array('allowmanage' => '1', 'allowrecommend' => '1', 'needverify' => '0'); if (checkperm('allowdiy')) { return $allperm; } elseif (!getstatus($_G['member']['allowadmincp'], 4) && !getstatus($_G['member']['allowadmincp'], 5) && !getstatus($_G['member']['allowadmincp'], 6) && !checkperm('allowmanagetopic') && !checkperm('allowaddtopic')) { return $perm; } require_once libfile('class/blockpermission'); $blockpermsission =& block_permission::instance(); $perm = $blockpermsission->get_perms_by_bid($bid, $_G['uid']); $perm = $perm ? current($perm) : ''; if (empty($perm)) { if ($block = C::t('common_block')->fetch($bid)) { $block = array_merge($block, C::t('common_template_block')->fetch_by_bid($bid)); } if (empty($block['targettplname']) && empty($block['blocktype'])) { if ($_G['group']['allowmanagetopic'] || $_G['group']['allowaddtopic'] && $block['uid'] == $_G['uid']) { $perm = $allperm; } } elseif (substr($block['targettplname'], 0, 28) == 'portal/portal_topic_content_') { if (!empty($_G['group']['allowmanagetopic'])) { $perm = $allperm; } elseif ($_G['group']['allowaddtopic']) { $id = str_replace('portal/portal_topic_content_', '', $block['targettplname']); $topic = C::t('portal_topic')->fetch(intval($id)); if ($topic['uid'] == $_G['uid']) { $perm = $allperm; } } } } return $perm; }
function remake_inherited_perm($tplname, $parenttplname) { if ($tplname && $parenttplname) { $users = $this->get_users_perm_by_template($parenttplname); $templates = $this->_get_templates_subs($tplname); $this->_add_users_templates($users, $templates, $parenttplname); $blockpermission =& block_permission::instance(); $bids = $blockpermission->get_bids_by_template($templates); $blockpermission->add_users_blocks($users, $bids, $parenttplname); } }
function getblockperm($bid) { global $_G; $perm = array('allowmanage' => '0', 'allowrecommend' => '0', 'needverify' => '1'); $bid = max(0, intval($bid)); if (!$bid) { return $perm; } $allperm = array('allowmanage' => '1', 'allowrecommend' => '1', 'needverify' => '0'); if (checkperm('allowdiy')) { return $allperm; } elseif (!getstatus($_G['member']['allowadmincp'], 4) && !getstatus($_G['member']['allowadmincp'], 5) && !getstatus($_G['member']['allowadmincp'], 6) && !checkperm('allowmanagetopic') && !checkperm('allowaddtopic')) { return $perm; } require_once libfile('class/blockpermission'); $blockpermsission =& block_permission::instance(); $perm = $blockpermsission->get_perms_by_bid($bid, $_G['uid']); $perm = $perm ? $perm[0] : ''; if (empty($perm)) { $block = DB::fetch_first('SELECT tb.*,b.blocktype,b.uid FROM ' . DB::table('common_block') . " b LEFT JOIN " . DB::table('common_template_block') . " tb ON b.bid=tb.bid WHERE b.bid = '{$bid}'"); if (empty($block['targettplname']) && empty($block['blocktype'])) { if ($_G['group']['allowmanagetopic'] || $_G['group']['allowaddtopic'] && $block['uid'] == $_G['uid']) { $perm = $allperm; } } elseif (substr($block['targettplname'], 0, 28) == 'portal/portal_topic_content_') { if (!empty($_G['group']['allowmanagetopic'])) { $perm = $allperm; } elseif ($_G['group']['allowaddtopic']) { $id = str_replace('portal/portal_topic_content_', '', $block['targettplname']); $topic = DB::fetch_first('SELECT uid FROM ' . DB::table('portal_topic') . " WHERE topicid='" . intval($id) . "'"); if ($topic['uid'] == $_G['uid']) { $perm = $allperm; } } } } return $perm; }
/** * 重新生成指定页面的所有继承权限 * @param string $tplname 页面名称 * @param string $parenttplname 继承权限页面名称 */ function remake_inherited_perm($tplname, $parenttplname) { if ($tplname && $parenttplname) { //上级页面的所有权限 $users = $this->get_users_perm_by_template($parenttplname); //所有页面,包括子页面 $templates = $this->_get_templates_subs($tplname); //批量添加页面继承上级的用户权限 $this->_add_users_templates($users, $templates, $parenttplname); $blockpermission =& block_permission::instance(); $bids = $blockpermission->get_bids_by_template($templates); //所有模块的ID $blockpermission->add_users_blocks($users, $bids, $parenttplname); //添加用户和模块的关联 } }