아래 제안한 기능(제한된 아이디만 게시판 접근) 만들어버렸습니다.
|
2008-07-10 18:06:59
|
훌쩍 만들어 버렸네요. ^^a ㅎㅎㅎ
Code:
Index: app/models/user.php
===================================================================
--- app/models/user.php (revision 1212)
+++ app/models/user.php (working copy)
@@ -117,6 +117,10 @@
break;
}
}
+ function is_member($object) {
+ if ($this->is_admin()) return true;
+ return $object->is_member($this);
+ }
}
class Guest extends Model
@@ -178,5 +182,9 @@
break;
}
}
+ function is_member($object) {
+ if ($this->is_admin()) return true;
+ return $object->is_member($this);
+ }
}
?>
Index: app/models/board.php
===================================================================
--- app/models/board.php (revision 1212)
+++ app/models/board.php (working copy)
@@ -17,6 +17,7 @@
function _init() {
$this->admin_table = get_table_name('board_admin');
+ $this->member_table = get_table_name('board_member');
$this->post_table = get_table_name('post');
$this->comment_table = get_table_name('comment');
$this->category_table = get_table_name('category');
@@ -110,9 +111,34 @@
}
$this->db->execute("INSERT INTO $this->admin_table (board_id, user_id) VALUES($this->id, $user->id)");
}
- function drop_admin($admin) {
- $this->db->execute("DELETE FROM $this->admin_table WHERE board_id=$this->id AND user_id=$admin->id");
+ function drop_admin($user) {
+ $this->db->execute("DELETE FROM $this->admin_table WHERE board_id=$this->id AND user_id=$user->id");
}
+ function get_members() {
+ if (!isset($this->_members)) {
+ $table = get_table_name('user');
+ $this->_members = $this->db->fetchall("SELECT u.* FROM $this->member_table a, $table u WHERE u.level=255 OR (a.board_id=$this->id AND a.user_id=u.id) GROUP BY u.id", "User");
+ }
+ return $this->_members;
+ }
+ function is_member($user) {
+ foreach ($this->get_members() as $member) {
+ if ($member->id == $user->id) return true;
+ }
+ return false;
+ }
+ function add_member($user) {
+ foreach ($this->get_members() as $member) {
+ if ($member->id == $user->id) return;
+ }
+ $this->db->execute("INSERT INTO $this->member_table (board_id, user_id) VALUES($this->id, $user->id)");
+ }
+ function drop_member($user) {
+ $this->db->execute("DELETE FROM $this->member_table WHERE board_id=$this->id AND user_id=$user->id");
+ }
+ function is_member_mode() {
+ return $this->db->fetchone("SELECT COUNT(*) FROM $this->member_table WHERE board_id=$this->id") > 0;
+ }
function reset_sort_keys() {
if (!$this->order_by) $this->order_by = 'id DESC';
$this->db->execute("UPDATE $this->post_table SET sort_key=-id WHERE notice=1");
Index: app/views/board/edit_permission.php
===================================================================
--- app/views/board/edit_permission.php (revision 1212)
+++ app/views/board/edit_permission.php (working copy)
@@ -18,6 +18,37 @@
<p><input type="submit" value="OK" /></p>
</form>
+<h3><?=i('Members')?></h3>
+<p><?=i('Set members are able to access this board.')?></p>
+<table id="users">
+<tr>
+ <th class="name"><?=i('Name')?></th>
+ <th class="level"><?=i('Level')?></th>
+ <th class="actions"><?=i('Actions')?></th>
+</tr>
+<? $_ = $board->get_members(); if ($_) { foreach ($_ as $member) { ?>
+<tr>
+ <td><?=$member->name?> <small>(<?=$member->user?>)</small></td>
+ <td><?=$member->level?></td>
+ <td>
+ <? if (!$member->is_admin()) { ?>
+ <a href="<?=url_for($board, 'members')?>?action=drop&id=<?=$member->id?>">멤버 제거</a>
+ <? } else { ?>
+ -
+ <? } ?>
+ </td>
+</tr>
+<? } } else { ?>
+<tr>
+ <td colspan="3" style="text-align: center; height: 4em">멤버가 없습니다.</td>
+</tr>
+<? } ?>
+</table>
+<form method="post" action="<?=url_for($board, 'members')?>?action=add">
+<p>멤버로 추가할 사용자의 아이디를 입력하세요.</p>
+<p><input type="text" name="member_id" /> <input type="submit" value="<?=i('Add')?>" /></p>
+</form>
+
<h3><?=i('Administrators')?></h3>
<table id="users">
<tr>
Index: lib/permission.php
===================================================================
--- lib/permission.php (revision 1212)
+++ lib/permission.php (working copy)
@@ -3,8 +3,10 @@
function permission_required($action, $object) {
global $account;
- $result = $account->has_perm($action, $object);
- if (!$result)
+ $result_permission = $account->has_perm($action, $object);
+ $result_member = $account->is_member($object);
+ $flag = $object->is_member_mode();
+ if (($flag && (!$result_permission || !$result_member)) || !$flag && !$result_permission )
access_denied();
else if ($result === ASK_PASSWORD)
ask_password_of($object);
Index: lang/ko.php
===================================================================
--- lang/ko.php (revision 1212)
+++ lang/ko.php (working copy)
@@ -143,3 +143,8 @@
$lang['Maintenance'] = '유지 보수';
$lang['Site theme'] = '사이트 테마';
$lang['Information'] = '정보';
+$lang['Inputs is Empty.'] = '입력란이 비었습니다.';
+$lang['Fill out The Title and Body.'] = '제목과 내용을 채워주세요.';
+$lang['Back to Write Page'] = '쓰기 페이지로 이동';
+$lang['Members'] = '접근 가능한 멤버';
+$lang['Set members are able to access this board.'] = '게시판에 접근할수 있는 멤버를 설정합니다.';
Index: app/controllers/board/members.php
===================================================================
--- app/controllers/board/members.php (revision 0)
+++ app/controllers/board/members.php (revision 0)
@@ -0,0 +1,20 @@
+<?php
+if (!$account->is_admin()) {
+ access_denied();
+}
+var_dump($_POST);
+
+switch ($_GET['action']) {
+ case 'add':
+ $user = User::find_by_user($_POST['member_id']);
+ if ($user->exists() && !$user->is_admin())
+ $board->add_member($user);
+ break;
+ case 'drop':
+ $admin = User::find($_GET['id']);
+ if ($admin->exists())
+ $board->drop_member($admin);
+ break;
+}
+redirect_to(url_for($board, 'edit', array('tab' => 'permission')));
+?>
DB 추가(update에 포함될 것)
Code:<?php
$t = new Table('board_member');
$t->column('board_id', 'integer');
$t->column('user_id', 'integer');
$t->add_index('board_id');
$conn->add_table($t);
$conn->query("INSERT INTO ".get_table_name('board_member')." (board_id, user_id) VALUES(0, 0)"); // insert dummy data
?>엽기민원 님이 2008-07-10 18:22:05에 고쳤습니다. |
커미터로 임명(?)합니다. 메일 주소를 알려주시면, 계정을 생성할 수 있는 URL을 보내드리겠습니다. (놀랍게도 초대 시스템;;이 있습니다.)
공개 장소에 메일 주소를 쓰는 게 곤란하시다면 제 메일 dittos@gmail.com으로 보내셔도 되고요.
ㅎㅎ 메일 보냈슴다.
^^
초대 메일 보냈어요.
바하흐로 MetaBBS의 팀블로그, 그들만의 게시판 시대가 열렸군요. ^^
revision 1226입니다. ^^