我是关于php的新手,我想在mybb论坛上删除之前备份帖子。
我修改了inc/class_moderation.php
添加了以下函数backup_post
,但是在调用函数backup_post
时
抛出
调用未定义的函数backup_post() 第485行/membri/myforum/inc/class_moderation.php
function delete_post($pid)
{
global $mybb, $db, $cache, $plugins;
$pid = $plugins->run_hooks("class_moderation_delete_post_start", $pid);
// Get pid, uid, fid, tid, visibility, forum post count status of post
$pid = intval($pid);
$query = $db->query("
SELECT p.pid, p.uid, p.fid, p.tid, p.visible, f.usepostcounts, t.visible as threadvisible, message, p.username as p_username, p.subject, p.dateline
FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=p.fid)
WHERE p.pid='$pid'
");
$post = $db->fetch_array($query);
// If post counts enabled in this forum and it hasn't already been unapproved, remove 1
if($post['usepostcounts'] != 0 && $post['visible'] != 0 && $post['threadvisible'] != 0)
{
$db->update_query("users", array("postnum" => "postnum-1"), "uid='{$post['uid']}'", 1, true);
}
if(!function_exists("remove_attachments"))
{
require MYBB_ROOT."inc/functions_upload.php";
}
// Remove attachments
remove_attachments($pid);
//Backup the post
backup_post($pid);
// Delete the post
$db->delete_query("posts", "pid='$pid'");
// Remove any reports attached to this post
$db->delete_query("reportedposts", "pid='$pid'");
$num_unapproved_posts = $num_approved_posts = 0;
// Update unapproved post count
if($post['visible'] == 0 || $post['threadvisible'] == 0)
{
++$num_unapproved_posts;
}
else
{
++$num_approved_posts;
}
$plugins->run_hooks("class_moderation_delete_post", $post['pid']);
// Update stats
$update_array = array(
"replies" => "-{$num_approved_posts}",
"unapprovedposts" => "-{$num_unapproved_posts}"
);
update_thread_counters($post['tid'], $update_array);
// Update stats
$update_array = array(
"posts" => "-{$num_approved_posts}",
"unapprovedposts" => "-{$num_unapproved_posts}"
);
update_forum_counters($post['fid'], $update_array);
return true;
}
function backup_post($pid)
{
global $mybb, $db, $cache, $plugins;
// Get pid, uid, fid, tid, visibility, forum post count status of post
$pid = intval($pid);
$query = $db->query("
SELECT p.pid, p.uid, p.fid, p.tid, p.visible, f.usepostcounts, t.visible as threadvisible, message, p.username as p_username, p.subject, p.dateline
FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=p.fid)
WHERE p.pid='$pid'
");
$post = $db->fetch_array($query);
$deletedpost = array(
"username_delete" => $mybb->user['username'],
"username" => $post['p_username'],
"subject" => $post['subject'],
"message" => $post['message'],
"dateline" => TIME_NOW,
"post_dateline" => $post['dateline'],
);
$db->insert_query("posts_deleted", $deletedpost);
//14-06-20016
//ob_start();
//var_dump($mybb);
//$data = ob_get_clean();
//$fp = fopen(MYBB_ROOT."myText.txt","wb");
//fwrite($fp,$data);
//fwrite($fp, "cancellato da ".$mybb->user['username']);
//fwrite($fp, "autore ".$post['p_username']);
//fwrite($fp, "messaggio ".$post['message']);
/*
foreach ($post as $key => $value) {
fwrite($fp, $key );
}
*/
//fclose($fp);
return true;
}
答案 0 :(得分:0)
您正在向一个类添加函数(然后我们倾向于将它们称为“方法”而不是“函数”,但这并不重要)。
如果要调用类方法,则需要将其称为$class_instance->method_name()
,而不是通常用于“普通”函数的method_name()
。
当您从同一个类中的另一个方法调用方法时,使用$this
来获取相同的类实例。
所以如果你改变这一行:
backup_post($pid);
为:
$this->backup_post($pid);
它应该有用。