2016-06-15 1 views
1

저는 PHP에 익숙하지 않습니다. mybb 포럼에서 삭제하기 전에 게시물을 백업하기 위해 triyng입니다.php 파일에 함수 추가 get 정의되지 않은 함수 예외에 대한 호출

나는 다음과 같은 기능 backup_post를 추가 inc/class_moderation.php을 편집 할 수 있지만 함수의 호출은 backup_post 라인에 /membri/myforum/inc/class_moderation.php에 정의되지 않은 함수 backup_post()에

통화가 발생하는 경우 485

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

당신은 클래스에 기능을 추가하는 (우리는 "방법"대신 "기능을 호출하는 경향이 그러나 그것은 정말로 중요하지 않다).

클래스 메서드를 호출하려면 "plain"함수로 작동하는 method_name() 대신 $class_instance->method_name()과 같이 호출해야합니다.

동일한 클래스의 다른 메서드에서 메서드를 호출 할 때는 $this을 사용하여 동일한 클래스 인스턴스를 가져옵니다.

그래서 당신이 줄을 변경할 경우 :

backup_post($pid); 

에를 :

$this->backup_post($pid); 

그것을 작동합니다.

관련 문제