我想制作一个可以在有人发布新问题时触发一些PHP代码的插件。这就是我现在得到的:
<?php
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../');
exit;
}
class FacebookDebugger {
/*
* https://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
* http://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
*
* https://gist.github.com/FrostyX/81d58222d1e835e24013
*/
public function reload($url) {
$graph = 'https://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 {
}
}
}
?>
因此,如您所见,我正在尝试添加代码,以在问题发布后立即清除Facebook共享缓存。我在Github上找到了FB共享缓存清除脚本,现在我想在Q2A插件中实现该脚本。我是PHP的初学者,如果我的代码很傻,请对不起。 或者,也许还有另一种自动执行此操作的方法?