plugin_admin.class.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. defined('IN_PHPCMS') or exit('No permission resources.');
  3. class plugin_admin {
  4. function __construct($pluginid) {
  5. $this->pluginid = $pluginid;
  6. $this->op = pc_base::load_app_class('plugin_op');
  7. $this->auth_db = pc_base::load_plugin_model('weibo_auth_info_model');
  8. }
  9. public function oauth() {
  10. pc_base::load_plugin_class('weibooauth','',0);
  11. $setting = getcache('weibo_var','plugins');
  12. if(!isset($_REQUEST['oauth_verifier']) || $_REQUEST['oauth_verifier'] == '') {
  13. if($this->auth_db->get_one(array('source'=>'sina'))) {
  14. $txt = '授权成功,<a href="?m=admin&c=plugin&a=config&pluginid='.$this->pluginid.'&module=removeauth&pc_hash='.$_SESSION['pc_hash'].'">解除绑定</a>';
  15. } else {
  16. $o = new WeiboOAuth( $setting['wb_akey'] , $setting['wb_skey']);
  17. $keys = $o->getRequestToken();
  18. print_r($keys);
  19. $aurl = $o->getAuthorizeURL( $keys['oauth_token'] ,false , get_url());
  20. $_SESSION['keys'] = $keys;
  21. $txt = '<a href="'.$aurl.'">点击进行授权</a>';
  22. }
  23. } else {
  24. $o = new WeiboOAuth( $setting['wb_akey'] , $setting['wb_skey'] , $_SESSION['keys']['oauth_token'] , $_SESSION['keys']['oauth_token_secret'] );
  25. $last_key = $o->getAccessToken( $_REQUEST['oauth_verifier'] ) ;
  26. $c = new WeiboClient( $setting['wb_akey'] , $setting['wb_skey'] , $last_key['oauth_token'] , $last_key['oauth_token_secret'] );
  27. $ms = $c->home_timeline(); // done
  28. $me = $c->verify_credentials();
  29. $this->auth_db->insert(array('uid'=>$me['id'],'token'=>$last_key['oauth_token'],'tsecret'=>$last_key['oauth_token_secret'],'source'=>'sina'));
  30. $txt = '授权成功,'.$me['name'].'<a href="?m=admin&c=plugin&a=config&pluginid='.$this->pluginid.'&module=removeauth&pc_hash='.$_SESSION['pc_hash'].'">解除绑定</a>';
  31. }
  32. include $this->op->plugin_tpl('oauth',PLUGIN_ID);
  33. }
  34. public function removeauth() {
  35. if($this->auth_db->delete(array('source'=>'sina'))) {
  36. showmessage('ok');
  37. } else {
  38. showmessage('fail');
  39. }
  40. }
  41. public function pushtoweibo() {
  42. prnt_r($_GET);
  43. }
  44. }
  45. ?>