📄 c_core.php
字号:
<?php
/**
* CuteBook 多用户留言本
* 程式版權 (c) 2001 by midiguy www.jaxp.net
* 作者Email: midiguy@263.net 欢迎批评指正
* 请不要修改版权信息,谢谢
*/
class c_core extends c_base {
// post reply form
function reply()
{
global $lang, $info;
$err = false;
$err_msg = '';
if (!isset($_GET['userid']) || !is_numeric($_GET['userid'])) {
$err_msg .= '<br>' . $lang['userid_missing'];
$err = true;
}
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
$err_msg .= '<br>' . $lang['topic_id_missing'];
$err = true;
}
if ($err) {
$this->c_error->freeback2($err_msg);
return;
}
$userid = $_GET['userid'];
$id = $_GET['id'];
$t = &$this->c_smarty_tpl;
$t->caching = false;
$t->assign(array('userid' => $userid, 'id' => $id, 'reply_authorize' => $info['reply_authorize']));
$t->display('post/reply_form.tpl', '', "post");
}
// post
function post()
{
global $lang;
$err = false;
$err_msg = '';
if (!isset($_GET['userid']) || !is_numeric($_GET['userid'])) {
$err_msg .= '<br>' . $lang['userid_missing'];
$err = true;
}
if ($err) {
$this->c_error->freeback2($err_msg);
return;
}
$userid = $_GET['userid'];
$t = &$this->c_smarty_tpl;
$t->caching = false;
$t->assign('userid', $userid);
$t->display('post/post_form.tpl', '', 'post');
}
// post save
function post_save()
{
global $db_table, $lang, $c_user;
$err = false;
$err_msg = '';
if (!isset($_POST['userid']) || trim($_POST['userid']) == '') {
$err = true;
$err_msg .= '<br>' . $lang['userid_missing'];
}
$userid = $_POST['userid'];
if ($err) {
$this->c_error->freeback("./?act=post_list&userid=$userid", $err_msg);
return;
}
if (isset($_POST['email']) && trim($_POST['email']) != '' && !$this->c_function->is_email_valid($_POST['email'])) {
$err = true;
$err_msg .= '<br>' . $lang['email_invalid'];
}
if (!isset($_POST['name']) || trim($_POST['name']) == '') {
$err = true;
$err_msg .= '<br>' . $lang['name_empty'];
}
if (!isset($_POST['post_body']) || trim($_POST['post_body']) == '') {
$err = true;
$err_msg .= '<br>' . $lang['post_body_empty'];
}
if (!$c_user->userid_exist($_POST['userid'])) {
$err = true;
$err_msg .= '<br>' . $lang['userid_not_exist'];
}
if ($err) {
$this->c_error->freeback("./?act=post_list&userid=$userid", $err_msg);
return;
}
$SQL = " INSERT INTO " . $db_table['topic'] . "(
userid,name,sex,address,email,homepage,emotion,post_body,post_time,post_color,ip) VALUES (
" . $userid . ",
'" . trim($_POST['name']) . "',
'" . $_POST['sex'] . "',
'" . trim($_POST['address']) . "',
'" . trim($_POST['email']) . "',
'" . trim($_POST['homepage']) . "',
'" . $_POST['emotion'] . "',
'" . trim($_POST['post_body']) . "',
'" . date("Y-m-d H:i:s") . "',
'" . $_POST['post_color'] . "',
'" . $this->c_function->get_client_ip() . "'
)";
$result = $this->c_db->query($SQL);
if ($result) {
if ($c_user->need_auth($userid)) {
$this->c_error->freeback1($lang['thank_for_post']);
} else {
$this->c_error->freeback("./?act=post_list&userid=$userid", $lang['thank_for_post']);
}
}
}
// post list
function post_list($page = 1, $items_size = 10, $pagesize = 20)
{
global $db_table, $c_user, $lang, $c_util;
$err = false;
$err_msg = '';
if (!isset($_GET['userid']) || !is_numeric($_GET['userid'])) {
$err_msg .= '<br>' . $lang['userid_missing'];
$err = true;
}
if (isset($_GET['userid']) && !$c_user->userid_exist($_GET['userid'])) {
$err_msg .= '<br>' . $lang['userid_not_exist'];
$err = true;
}
if ($err) {
$this->c_error->freeback1($err_msg);
return;
}
$userid = $_GET['userid'];
$t = &$this->c_smarty_tpl;
$t->caching = false;
if (isset($_GET['page'])) $page = $_GET['page'];
$SQL = "SELECT id from " . $db_table['topic'] . " where userid=" . $userid;
$result = $this->c_db->query($SQL);
$total = $this->c_db->num_rows($result);
$pagecount = ceil($total / $pagesize);
$page = ($page > $pagecount)?$pagecount:$page;
$offset = ($page-1) * $pagesize;
$SQL = " SELECT * FROM " . $db_table['topic'] . " WHERE userid=$userid ORDER BY id DESC LIMIT $offset,$pagesize";
$post_list_info = array();
$result = $this->c_db->query($SQL);
while ($row = $this->c_db->fetch_array($result)) {
$post_list_info[] = array('id' => $row['id'],
'name' => $this->c_function->text_filter_html($row['name']),
'sex' => $row['sex'],
'address' => $this->c_function->text_filter_html($row['address']),
'email' => $this->c_function->text_filter_html($row['email']),
'homepage' => $this->c_function->text_filter_html($row['homepage']),
'emotion' => $row['emotion'],
'body' => $this->c_function->text_filter_html($row['post_body']),
'time' => $row['post_time'],
'color' => $row['post_color'],
'replies' => $c_util->get_replies_count_by_topic($row['id'])
);
}
// pages
$c_url = "<a href=./?act=post_list&userid=$userid";
$_pages_info = $this->c_function->_pages($page, $items_size, $pagecount, $c_url);
$t->assign(array('post_list_info' => $post_list_info,
'l_arrow' => $_pages_info['l_arrow'],
'r_arrow' => $_pages_info['r_arrow'],
'item_list_info' => $_pages_info['item_list_info'],
'total' => $total,
'page' => $page,
'pagecount' => $pagecount,
'userid' => $userid
));
$t->display('post/post_list.tpl', '', 'post');
}
// view (no pages)
function view($items_size = 10, $pagesize = 20)
{
global $db_table;
$t = &$this->c_smarty_tpl;
$t->caching = false;
$id = isset($_GET['id'])?$_GET['id']:-1;
$page = isset($_GET['page'])?$_GET['page']:1;
$userid = isset($_GET['userid'])?$_GET['userid']:-1;
$SQL = "select * from " . $db_table['reply'] . " where father_id=" . $id . " order by id desc";
$reply_list_info = array();
$result = $this->c_db->query($SQL);
while ($row = $this->c_db->fetch_array($result)) {
$reply_list_info[] = array('name' => $this->c_function->text_filter_html($row['name']),
'sex' => $row['sex'],
'address' => $this->c_function->text_filter_html($row['address']),
'email' => $this->c_function->text_filter_html($row['email']),
'homepage' => $this->c_function->text_filter_html($row['homepage']),
'emotion' => $row['emotion'],
'body' => $this->c_function->text_filter_html($row['post_body']),
'time' => $row['post_time'],
'color' => $row['post_color'],
'ip' => $row['ip']
);
}
$SQL = "select * from " . $db_table['topic'] . " where id=" . $id;
$topic_list_info = array();
$result = $this->c_db->query($SQL);
while ($row = $this->c_db->fetch_array($result)) {
$topic_list_info[] = array('name' => $this->c_function->text_filter_html($row['name']),
'sex' => $row['sex'],
'address' => $this->c_function->text_filter_html($row['address']),
'email' => $this->c_function->text_filter_html($row['email']),
'homepage' => $this->c_function->text_filter_html($row['homepage']),
'emotion' => $row['emotion'],
'body' => $this->c_function->text_filter_html($row['post_body']),
'time' => $row['post_time'],
'color' => $row['post_color'],
'ip' => $row['ip']
);
}
$t->assign(array('reply_list_info' => $reply_list_info,
'topic_list_info' => $topic_list_info,
'userid' => $userid,
'topic_id' => $id,
'page' => $page
));
$t->display('post/all_list.tpl', '', 'post');
}
// reply save
function reply_save()
{
global $db_table, $lang, $c_user, $info;
$err = false;
$err_msg = '';
if (!isset($_POST['userid']) || trim($_POST['userid']) == '') {
$err_msg .= '<br>' . $lang['userid_missing'];
$err = true;
}
if (!isset($_POST['id']) || trim($_POST['id']) == '') {
$err_msg .= '<br>' . $lang['topic_id_missing'];
$err = true;
}
if (isset($_POST['email']) && trim($_POST['email']) != '' && !$this->c_function->is_email_valid($_POST['email'])) {
$err_msg .= '<br>' . $lang['email_invalid'];
$err = true;
}
if (!isset($_POST['name']) || trim($_POST['name']) == '') {
$err = true;
$err_msg .= '<br>' . $lang['name_empty'];
}
if (!isset($_POST['post_body']) || trim($_POST['post_body']) == '') {
$err_msg .= '<br>' . $lang['post_body_empty'];
$err = true;
}
if (!$c_user->userid_exist($_POST['userid'])) {
$err = true;
$err_msg .= '<br>' . $lang['userid_not_exist'];
}
if ($info['reply_authorize'] && !$c_user->is_manager_by_userid($_POST['userid'], trim($_POST['password']))) {
$err = true;
$err_msg .= '<br>' . $lang['password_error'];
}
if ($err) {
$this->c_error->freeback2($err_msg);
return;
}
$userid = $_POST['userid'];
$SQL = " INSERT INTO " . $db_table['reply'] . "(
father_id,name,sex,address,email,homepage,emotion,post_body,post_time,post_color,ip) VALUES (
" . $_POST['id'] . ",
'" . trim($_POST['name']) . "',
'" . $_POST['sex'] . "',
'" . trim($_POST['address']) . "',
'" . trim($_POST['email']) . "',
'" . trim($_POST['homepage']) . "',
'" . $_POST['emotion'] . "',
'" . trim($_POST['post_body']) . "',
'" . date('Y-m-d H:i:s') . "',
'" . $_POST['post_color'] . "',
'" . $this->c_function->get_client_ip() . "'
)";
$result = $this->c_db->query($SQL);
if ($result) {
$this->c_error->freeback("./?act=post_list&userid=$userid", $lang['reply_success']);
}
}
// post delete
function post_delete()
{
global $lang;
$err = false;
$err_msg = '';
if (!isset($_GET['userid']) || !is_numeric($_GET['userid'])) {
$err_msg .= '<br>' . $lang['userid_missing'];
$err = true;
}
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
$err_msg .= '<br>' . $lang['topic_id_missing'];
$err = true;
}
if ($err) {
$this->c_error->freeback2($err_msg);
return;
}
$userid = $_GET['userid'];
$id = $_GET['id'];
$t = &$this->c_smarty_tpl;
$t->caching = false;
$t->assign(array('userid' => $userid, 'id' => $id));
$t->display('post/post_delete.tpl', '', 'post');
}
// delete save
function delete_save()
{
global $db_table, $lang, $c_user;
$err = false;
$err_msg = '';
if (!isset($_POST['userid']) || trim($_POST['userid']) == '') {
$err_msg .= '<br>' . $lang['userid_missing'];
$err = true;
}
if (!isset($_POST['id']) || trim($_POST['id']) == '') {
$err_msg .= '<br>' . $lang['topic_id_missing'];
$err = true;
}
if (!isset($_POST['password']) || trim($_POST['password']) == '') {
$err_msg .= '<br>' . $lang['password_empty'];
$err = true;
}
if (!$c_user->is_manager_by_userid($_POST['userid'], trim($_POST['password']))) {
$err = true;
$err_msg .= '<br>' . $lang['password_error'];
}
if ($err) {
$this->c_error->freeback2($err_msg);
return;
}
$userid = $_POST['userid'];
$id = $_POST['id'];
// topic delete
$SQL = "DELETE FROM " . $db_table['topic'] . " WHERE id=" . $id;
$result1 = $this->c_db->query($SQL);
// reply delete
$SQL = "DELETE FROM " . $db_table['reply'] . " WHERE father_id=" . $id;
$result2 = $this->c_db->query($SQL);
if ($result1 && $result2) {
$this->c_error->freeback("./?act=post_list&userid=$userid", $lang['delete_success']);
}
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -