Problem about PHP code execution when a visitor posts a question on the website.

Post date: 2019-11-16 20:15:53
Views: 159
Hello everybody!

I want to make plugin that will trigger some PHP code when someone post new question. This is what I got for now:

<?php
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
    header('Location: ../../');
    exit;
}
class FacebookDebugger {
    /*
     * developers.(facebook.com/docs/opengraph/using-objects
     *
     * Updating Objects
     *
     * When an action is published, or a Like button pointing to the object clicked,
     * Facebook will 'scrape' the HTML page of the object and read the meta tags.
     * The object scrape also occurs when:
     *
     *      - Every 7 days after the first scrape
     *
     *      - The object URL is input in the Object Debugger
     *          developers.)facebook.com/tools/debug
     *
     *      - When an app triggers a scrape using an API endpoint
     *           This Graph API endpoint is simply a call to:
     *
     *           POST /?id={object-instance-id or object-url}&scrape=true
     *
     * gist.github.(com/FrostyX/81d58222d1e835e24013
    */
    public function reload($url) {
        $graph = 'graph(.facebook.com/';
        $post = 'id=' . urlencode($url) . '&scrape=true';
        return $this->send_post($graph, $post);
    }
    private function send_post($url, $post) {
        $r = curl_init();
        curl_setopt($r, CURLOPT_URL, $url);
        curl_setopt($r, CURLOPT_POST, 1);
        curl_setopt($r, CURLOPT_POSTFIELDS, $post);
        curl_setopt($r, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($r, CURLOPT_CONNECTTIMEOUT, 5);
        $data = curl_exec($r);
        curl_close($r);
        return $data;
    }
}
class qa_event_clear_cache {
    public function process_event($event, $userid, $handle, $cookieid, $params) {
        /* require_once QA_INCLUDE_DIR.'app/emails.php';
        require_once QA_INCLUDE_DIR.'app/format.php';
        require_once QA_INCLUDE_DIR.'util/string.php'; */
        if ($event == 'q_post') {
            $fb = new FacebookDebugger();
            //$fb->reload('http://example(.)com/');
            $fb->reload(qa_q_path($params'postid'], $params'title'], true));
        } else {
        }
    }
}
?>

So, as you can see I am trying to add code that will clear Facebook share cache immediately after question is published. I found FB share cache clear script on Github and now I want to implement that in Q2A plugin. I am beginner in PHP, so sorry if my code is silly. Or, maybe there is some another way to do that automatically?

Thank you very much!
Please click Here to read the full story.
 
Other Top and Latest Questions:
[New Premium Theme] Qlassy Theme with complete features - Beta Version
Charlie Kirk shooting suspect Tyler Robinson charged with murder, faces possible death penalty
If you bought your house before 2005, you could be sitting on a goldmine
Eli Lilly aims to bring more manufacturing home — plus, the good and bad among our industrials
Microsoft, Nvidia, other tech giants plan over $40 billion of new AI investments in UK
China keeps tight grip on rare earths, costing at least one company 'millions of euros'
From royal pomp to Epstein embarrassment: Trump's UK state visit in pictures
CNBC's UK Exchange newsletter: Can UK trade come up Trumps?
CNBC's The China Connection newsletter: China’s attempt to pivot away from the U.S. starts with this trading hub
UK's GSK announces $30 billion U.S. pharma investment amid Trump state visit