指定某个分组才可以访问文章-可以做VIP文章等相关
=================================================== 找到/app/publish/main.php 在约 18行 加入<!-- 指定分组 -By Jerry 2016.11.1--> <h3><?php _e('文章标题'); ?>:</h3> <?php if ($this->groups) { ?> <div class="aw-publish-title"> <select name="power_group" id="" class="form-control"> <option value="0">不指定用户组</option> <?php foreach ($this->groups as $key => $v): ?> <option value="<?php _e($v['group_id']) ?>"><?php _e($v['group_name']) ?></option> <?php endforeach ?> </select> </div> <?php } ?> <!-- end 指定分组 -By Jerry 2016.11.1-->
找到/app/publish/ajax.php 把publish_article_action方法改为改为//用户组查询 S -By Jerry 2016.11.1 $groups = $this->model('usergroup')->get_groups(); TPL::assign('groups', $groups); // var_dump($groups); //用户组查询 E -By Jerry 2016.11.1
在models下面新建个模型,名字为usergroup.phppublic function publish_article_action() { if (!$this->user_info['permission']['publish_article']) { H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('你没有权限发布文章'))); } if (!$_POST['title']) { H::ajax_json_output(AWS_APP::RSM(null, - 1, AWS_APP::lang()->_t('请输入文章标题'))); } if (get_setting('category_enable') == 'N') { $_POST['category_id'] = 1; } if (!$_POST['category_id']) { H::ajax_json_output(AWS_APP::RSM(null, -1, AWS_APP::lang()->_t('请选择文章分类'))); } if (get_setting('question_title_limit') > 0 AND cjk_strlen($_POST['title']) > get_setting('question_title_limit')) { H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('文章标题字数不得大于 %s 字节', get_setting('question_title_limit')))); } if (!$this->user_info['permission']['publish_url'] AND FORMAT::outside_url_exists($_POST['message'])) { H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('你所在的用户组不允许发布站外链接'))); } if (!$this->model('publish')->insert_attach_is_self_upload($_POST['message'], $_POST['attach_ids'])) { H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('只允许插入当前页面上传的附件'))); } if (human_valid('question_valid_hour') AND !AWS_APP::captcha()->is_validate($_POST['seccode_verify'])) { H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('请填写正确的验证码'))); } if ($_POST['topics']) { foreach ($_POST['topics'] AS $key => $topic_title) { $topic_title = trim($topic_title); if (!$topic_title) { unset($_POST['topics'][$key]); } else { $_POST['topics'][$key] = $topic_title; } } if (get_setting('question_topics_limit') AND sizeof($_POST['topics']) > get_setting('question_topics_limit')) { H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('单个文章话题数量最多为 %s 个, 请调整话题数量', get_setting('question_topics_limit')))); } } if (get_setting('new_question_force_add_topic') == 'Y' AND !$_POST['topics']) { H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('请为文章添加话题'))); } // !注: 来路检测后面不能再放报错提示 if (!valid_post_hash($_POST['post_hash'])) { H::ajax_json_output(AWS_APP::RSM(null, '-1', AWS_APP::lang()->_t('页面停留时间过长,或内容已提交,请刷新页面'))); } $this->model('draft')->delete_draft(1, 'article', $this->user_id); if ($this->publish_approval_valid(array( $_POST['title'], $_POST['message'] ))) { $this->model('publish')->publish_approval('article', array( 'title' => $_POST['title'], 'message' => $_POST['message'], 'category_id' => $_POST['category_id'], 'topics' => $_POST['topics'], 'permission_create_topic' => $this->user_info['permission']['create_topic'], ), $this->user_id, $_POST['attach_access_key']); H::ajax_json_output(AWS_APP::RSM(array( 'url' => get_js_url('/publish/wait_approval/') ), 1, null)); } else { //changed ==by Jerry 2016.11.1 $article_id = $this->model('publish')->publish_article($_POST['title'],$_POST['power_group'], $_POST['message'], $this->user_id, $_POST['topics'], $_POST['category_id'], $_POST['attach_access_key'], $this->user_info['permission']['create_topic']); //changed ==by Jerry 2016.11.1 if ($_POST['_is_mobile']) { $url = get_js_url('/m/article/' . $article_id); } else { $url = get_js_url('/article/' . $article_id); } H::ajax_json_output(AWS_APP::RSM(array( 'url' => $url ), 1, null)); } }
加入以下代码 sql升级<?php if (!defined('IN_ANWSION')) { die; } class usergroup_class extends AWS_MODEL { public function get_groups() { return $this->fetch_all('users_group'); } } //找到models/publish.php 更改publish_article方法为 public function publish_article($title, $power_group,$message, $uid, $topics = null, $category_id = null, $attach_access_key = null, $create_topic = true) { if ($article_id = $this->insert('article', array( 'uid' => intval($uid), 'title' => htmlspecialchars($title), 'message' => htmlspecialchars($message), 'category_id' => intval($category_id), //changed ==by Jerry 2016.11.1 'power_group'=>intval($power_group), //changed ==by Jerry 2016.11.1 'add_time' => time() ))) { set_human_valid('question_valid_hour'); if (is_array($topics)) { foreach ($topics as $key => $topic_title) { $topic_id = $this->model('topic')->save_topic($topic_title, $uid, $create_topic); $this->model('topic')->save_topic_relation($uid, $topic_id, $article_id, 'article'); } } if ($attach_access_key) { $this->model('publish')->update_attach('article', $article_id, $attach_access_key); } $this->model('search_fulltext')->push_index('article', $title, $article_id); // 记录日志 ACTION_LOG::save_action($uid, $article_id, ACTION_LOG::CATEGORY_QUESTION, ACTION_LOG::ADD_ARTICLE, $title, $message, 0); $this->model('posts')->set_posts_index($article_id, 'article'); $this->shutdown_update('users', array( 'article_count' => $this->count('article', 'uid = ' . intval($uid)) ), 'uid = ' . intval($uid)); } return $article_id; }
到此处,发布文章权限就搞定了,下面就是验证组了。 ===================================================== 找到app/article/main.php 把ALTER TABLE `aws_article` ADD COLUMN `power_group` int(11) NULL AFTER `sort`;
<?php //echo $this->article_info['message']; ?> 改成 <?php if($this->article_info['user_info']['group_id']!=$article_info['power_group']){ echo "没有查看权限";}else{echo $this->article_info['message'];} ?>
====相关图片================================= 如果想超级管理员和前台管理员不在些限制,就改成 <?php if($this->article_info['user_info']['group_id']!=$article_info['power_group']&&$this->article_info['user_info']['group_id']!=1&&$this->article_info['user_info']['group_id']!=2){ echo "没有查看权限";}else{echo $this->article_info['message'];} ?>
2016-11-03 17:29
2016-11-02 10:58