option = array('SyncPost_Plugin', 'render');
Typecho_Plugin::factory('admin/write-page.php')->option = array('SyncPost_Plugin', 'render');
Typecho_Plugin::factory('Widget_Contents_Post_Edit')->write = array('SyncPost_Plugin', 'postRender');
Typecho_Plugin::factory('Widget_Contents_Page_Edit')->write = array('SyncPost_Plugin', 'postRender');
Helper::addAction('SyncPost', 'SyncPost_Action');
}
public static function deactivate(){
Helper::removeAction('SyncPost');
}
public static function config(Typecho_Widget_Helper_Form $form){
$options = '';
$siteUrl = Helper::options()->siteUrl;
try {
$options = Helper::options()->plugin('SyncPost');
} catch (Exception $e) {
}
echo '';
echo '
';
echo '
';
echo '
';
echo '
';
echo '
';
$postContent = new Typecho_Widget_Helper_Form_Element_Textarea('postContent', NULL, '我发表了一篇新的日志《%title%》,地址是:%permalink%,快来坐沙发吧!', _t('发送内容'), _t('标题:%title%
地址:%permalink%'));
$form->addInput($postContent);
$form->addInput(new Typecho_Widget_Helper_Form_Element_Hidden('tqq_access_token'));
$form->addInput(new Typecho_Widget_Helper_Form_Element_Hidden('tqq_expires_in'));
$form->addInput(new Typecho_Widget_Helper_Form_Element_Hidden('tqq_openid'));
$form->addInput(new Typecho_Widget_Helper_Form_Element_Hidden('tqq_openkey'));
$form->addInput(new Typecho_Widget_Helper_Form_Element_Hidden('tqq_last_time'));
$form->addInput(new Typecho_Widget_Helper_Form_Element_Hidden('sina_access_token'));
$form->addInput(new Typecho_Widget_Helper_Form_Element_Hidden('sina_expires_in'));
$form->addInput(new Typecho_Widget_Helper_Form_Element_Hidden('sina_last_time'));
$form->addInput(new Typecho_Widget_Helper_Form_Element_Hidden('douban_access_token'));
$form->addInput(new Typecho_Widget_Helper_Form_Element_Hidden('douban_refresh_token'));
$form->addInput(new Typecho_Widget_Helper_Form_Element_Hidden('douban_expires_in'));
$form->addInput(new Typecho_Widget_Helper_Form_Element_Hidden('douban_last_time'));
}
public static function personalConfig(Typecho_Widget_Helper_Form $form){}
public static function render()
{
echo '';
}
public static function postRender($contents, $class){
//echo '';
//var_dump($contents);
//exit();
if($class->request->is('do=publish')/* && !$class->request->get('cid')*/){
$opstions = Helper::options()->plugin('SyncPost');
$syncpost = $class->request->get('syncpost');
foreach ((array)$syncpost as $key => $val) {
if($val == 'syncpost-tqq'){
$params = array(
'oauth_consumer_key' => TQQ_CLIENT_ID,
'access_token' => $opstions->tqq_access_token,
'openid' => $opstions->tqq_openid,
'oauth_version' => '2.a',
'format' => 'json',
'content' => str_replace(array('%title%', '%permalink%'), array($contents['title'], $class->permalink), $opstions->postContent)
);
$result = HTTP::request(TQQ_API_URL, $params, 'POST');
}else if($val == 'syncpost-sina'){
$params = array(
'access_token' => $opstions->sina_access_token,
'status' => str_replace(array('%title%', '%permalink%'), array($contents['title'], $class->permalink), $opstions->postContent)
);
$result = HTTP::request(SINA_API_URL, $params, 'POST');
}else if($val == 'syncpost-douban'){
$params = array(
'source' => $opstions->douban_access_token,
'text' => str_replace(array('%title%', '%permalink%'), array($contents['title'], $class->permalink), $opstions->postContent)
);
$result = HTTP::request(DOUBAN_API_URL, $params, 'POST', false, array('Authorization: Bearer ' .$opstions->douban_access_token));
}
}
}
return $contents;
}
}