Skip to content

Instantly share code, notes, and snippets.

@Mark-Shine
Created May 22, 2014 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mark-Shine/f1d2ee907098be86e112 to your computer and use it in GitHub Desktop.
Save Mark-Shine/f1d2ee907098be86e112 to your computer and use it in GitHub Desktop.
php 插件
<?php
if (! defined ( 'IN_DISCUZ' )) {
exit ( 'Access Denied' );
}
class plugin_monitor {
}
class plugin_monitor_forum extends plugin_monitor {
function do_post_request($url, $data, $optional_headers = null)
{
$params = array('http' => array(
'method' => 'POST',
'content' => $data
));
if ($optional_headers !== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
}
function post_checkreply_message($param) {
global $_G;
if ($param ['param'] [0] == "post_reply_succeed" or $param ['param'] [0] == "post_newthread_succeed") {
$web_root=$_G['siteurl'];
$MAX_POSTS = 3;
loadcache("posts_queue");
$posts_queue_cache = $_G['cache']['posts_queue'];
if (empty($posts_queue_cache)){
$posts_queue_cache = array();
}
if(substr($web_root,-1)!='/'){
$web_root=$web_root.'/';
}
$sitename=$_G['setting']['bbname'];
$pid=$param ['param'] [2]['pid'];
$tid=$param ['param'] [2]['tid'];
$thread=C::t("forum_thread")->fetch($tid);
$post=C::t("forum_post")->fetch('',$pid);
$url=$web_root."forum.php?mod=viewthread&tid=$tid";
//无法获取中文
$message = $post['message'];
$data = array(
"author"=>$post['author'],
"message"=>$message,
"title"=>$thread['subject'],
"sitename"=>$sitename,
"clientip"=>$post['useip'],
"time"=>(String)time(),
"url"=>$url,
"authorid"=>$post['authorid'],
);
$posts_queue_cache[] = json_encode($data);
if (count($posts_queue_cache) >= $MAX_POSTS){
// send data
$postdata = http_build_query($posts_queue_cache);
//±ØÐëÆðÒ»¸öÒì²½Ị̈߳¬·ñÔòÔ¶³Ì³ö´íʱ£¬ÕâÀïÓÐÇ£Á¬
$this->do_post_request("http://127.0.0.1:9090/api/test", $postdata);
//clear cache
$posts_queue_cache = array();
}
save_syscache("posts_queue", $posts_queue_cache);
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment