MetaBBS 플러그인Dec 18, 2006
만고의 법칙 : 시험기간엔 꼭 다른게 하고 싶어진다. 그리고 집중도 더 잘된다.
조만간(2006년 이내에) 동아리 홈페이지를 개편할 예정이다. 게시판은 역시 MetaBBS 를 사용할 생각이다. 그래서 일단 내장되어 있는 간단한 Wiki 플러그인을 뜯어고치기 시작했다. 그러다가..
Dec 17 19:33:42 <디토군> 그리고 위키 엔진 따로 하나 개발중이에요. ~~;
...
그래서 위키는 때려치우고(오늘 하루종일 하라는 공부는 안하고 이거 붙들고 있었는데..-_-), 플러그인을 간략화시켜서 정적HTML 페이지를 생성/관리하는 - WP의 Page 기능처럼 - 플러그인으로 선회했다. 역시 시험기간엔 꼭 평소에 안하던 짓이 하고 싶어지는 법이다.
그리고 Zeroboard 멤버 테이블을 이용해서 인증을 하는 플러그인도 필요한데, 이쪽은 가만히 보니 account 컨트롤러의 액션 쪽에 필터가 없어서 게시판 소스에다 약간 추가해야 할 듯 싶다. 일단 이건 참았다가 시험끝나면 해 볼 생각이다.
PHP:
-
<?php
-
class Page extends Model {
-
var $model = 'page';
-
-
function _init() {
-
$this->table = get_table_name('page');
-
}
-
function find_by_id($id) {
-
$db = get_conn();
-
$table = get_table_name('page');
-
}
-
function find_by_slug($id) {
-
$db = get_conn();
-
$table = get_table_name('page');
-
}
-
function find_all() {
-
$db = get_conn();
-
$table = get_table_name('page');
-
return $this->db->fetchall("SELECT * FROM $table", 'Page');
-
}
-
}
-
-
class StaticPage extends Plugin {
-
var $description = 'Static page plugin for MetaBBS.';
-
-
function on_init() {
-
foreach (Page::find_all() as $page) {
-
}
-
}
-
function on_settings() {
-
if (is_post()) {
-
}
-
}
-
}
-
-
echo "<h2>Plugin : StaticPage</h2>\n";
-
-
$page = Page::find_by_id($_GET['edit']);
-
}
-
-
echo "<dl>\n";
-
echo "</dl>\n";
-
echo "</form>\n";
-
}
-
else {
-
$page = Page::find_by_id($_GET['delete']);
-
if ($page->exists())
-
$page->delete();
-
echo "<div class=\"flash pass\"><p>Page deleted. ".link_to('Click here',$this,'settings')." to continue.</p></div>\n";
-
}
-
else {
-
$pages = Page::find_all();
-
echo "<h3>Pages</h3>\n";
-
echo "<table id=\"pages\">\n";
-
echo "\t<tr>\n";
-
echo "\t<th class=\"slug\">Page slug</th>\n";
-
echo "\t<th class=\"title\">Title</th>\n";
-
echo "\t<th class=\"actions\">Actions</th>\n";
-
echo "\t</tr>\n";
-
foreach ($pages as $page) {
-
echo "\t<tr>\n";
-
echo "\t<td class=\"slug\">{$page->slug}</td>\n";
-
echo "\t<td class=\"title\">{$page->title}</td>\n";
-
echo "\t<td class=\"actions\">";
-
echo "</td>\n";
-
echo "\t</tr>\n";
-
}
-
echo "\t<tr>\n";
-
echo "\t</tr>\n";
-
echo "</table>\n";
-
}
-
}
-
}
-
function on_install() {
-
$t = new Table('page');
-
$t->column('slug', 'string', 45);
-
$t->column('title', 'string', 45);
-
$t->column('body', 'text');
-
$t->column('user_id', 'integer');
-
$t->column('created_at', 'timestamp');
-
$t->add_index('slug');
-
$t->add_index('user_id');
-
$this->db->add_table($t);
-
}
-
function on_uninstall() {
-
$this->db->drop_table('page');
-
}
-
function is_valid($values) {
-
return ($values['slug'] && $values['title'] && $values['body']);
-
}
-
function process_page($do, $values, $what = null) {
-
global $account;
-
-
-
if (!$this->is_valid($values)) {
-
echo "<div class=\"flash pass\"><p>Please fill all fields.</p></div>\n";
-
}
-
-
switch ($do) {
-
case 'new':
-
$page = Page::find_by_slug($values['slug']);
-
$page = ($page->exists()) ? $page : new Page();
-
break;
-
case 'edit':
-
$page = Page::find_by_id($what);
-
break;
-
}
-
-
$page->slug = $values['slug'];
-
$page->title = $values['title'];
-
$page->body = $values['body'];
-
$page->user_id = $account->id;
-
-
switch ($do) {
-
case 'new':
-
if ($page->exists()) {
-
echo "<div class=\"flash pass\"><p>Same slug exists. Change slug name.</p></div>\n";
-
}
-
else {
-
$page->create();
-
echo "<div class=\"flash pass\"><p>Page saved. ".link_to('Click here',$this,'settings')." to continue.</p></div>\n";
-
return null;
-
}
-
break;
-
case 'edit':
-
$page->update();
-
echo "<div class=\"flash pass\"><p>Page saved. ".link_to('Click here',$this,'settings')." to continue.</p></div>\n";
-
break;
-
}
-
}
-
function view_page() {
-
-
$page = Page::find_by_slug($action);
-
$title = $page->title;
-
-
if ($header_path = $config->get('global_header'))
-
include($header_path);
-
-
if ($account->is_admin()) {
-
}
-
-
if ($footer_path = $config->get('global_footer'))
-
include($footer_path);
-
}
-
function wpautop($pee, $br = 1) { //from WordPress
-
$pee = $pee . "\n"; // just to make things a little easier, pad the end
-
// Space things out a little
-
$pee = preg_replace('!(<(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|p|h[1-6])[^>]*>)!', "\n$1", $pee);
-
$pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "<p>$1</p>\n", $pee); // make paragraphs, including one at the end
-
$pee = preg_replace('|<p>\s*?</p>|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace
-
if ($br) $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); // optionally make line breaks
-
$pee = preg_replace('!(<pre .*?>)(.*?)</pre>!ise', " stripslashes('$1') . stripslashes(clean_pre('$2')) . '' ", $pee);
-
-
return $pee;
-
}
-
}
-
-
register_plugin('StaticPage');
-
?>
역시 시험기간의 힘이군요. -_-;;
참고로 만들고 있는 위키엔진 소스는 http://svn.daybreaker.info/ngwiki/trunk에서 보실 수 있습니다. SVN 체크아웃도 가능하구요
데모는? http://dittos.dnip.net/ngwiki/ngwiki.php
시험기간에 힘입어 리비전이 왕창 올라간 건가요?
rc1 기대하겠습니다. 릴리즈되면 이제 슬슬 ZB로 된 동아리 홈페이지도 엎어야겠군요.