public static function initComment($api) { session_start(); $options = Typecho_Widget::widget('Widget_Options'); $config = $options->plugin('ConnectToTwitter'); //发送请求到twitter if (isset($api->request->connect_to_twitter)) { $to = new TwitterOAuth($config->consumerKey, $config->consumerSecret); $tok = $to->getRequestToken(); Typecho_Cookie::set('oauth_request_token', $tok['oauth_token']); Typecho_Cookie::set('oauth_request_token_secret', $tok['oauth_token_secret']); /* Build the authorization URL */ $request_link = $to->getAuthorizeURL($tok['oauth_token']); header('Location:' . $request_link); } //从twitter返回 if (isset($api->request->oauth_token)) { if (Typecho_Cookie::get('oauth_request_token') && Typecho_Cookie::get('oauth_request_token_secret')) { $to = new TwitterOAuth($config->consumerKey, $config->consumerSecret, Typecho_Cookie::get('oauth_request_token'), Typecho_Cookie::get('oauth_request_token_secret')); $tok = $to->getAccessToken(); Typecho_Cookie::set('oauth_access_token', $tok['oauth_token'], time() + 60 * 60 * 24 * 30); Typecho_Cookie::set('oauth_access_token_secret', $tok['oauth_token_secret'], time() + 60 * 60 * 24 * 30); $info_json = $to->OAuthRequest('https://twitter.com/account/verify_credentials.json', array(), 'GET'); $info = Typecho_Json::decode($info_json, true); self::twitterLogin($info, $api); } } }
public function action() { /** 验证合法性 */ if (!isset($_SERVER['HTTP_GOOGLE_CODE_PROJECT_HOSTING_HOOK_HMAC'])) { return; } $googleSecretInfo = $_SERVER['HTTP_GOOGLE_CODE_PROJECT_HOSTING_HOOK_HMAC']; $revisionData = file_get_contents('php://input'); if (empty($revisionData)) { return; } $secretVerify = hash_hmac("md5", $revisionData, Helper::options()->plugin('GoogleCodeSVN')->secretKey); if ($googleSecretInfo != $secretVerify) { return; } $data = Typecho_Json::decode($revisionData); if (!$data) { return; } /** 登录用户 */ $master = $this->db->fetchRow($this->db->select()->from('table.users')->where('group = ?', 'administrator')->order('uid', Typecho_Db::SORT_ASC)->limit(1)); if (empty($master)) { return false; } else { if (!$this->user->simpleLogin($master['uid'])) { return false; } } if (isset($data->revisions) && is_array($data->revisions)) { foreach ($data->revisions as $revision) { if (!empty($revision->added)) { foreach ($revision->added as $file) { $input = $this->parseFileName($file, $data->repository_path); if ($input) { $this->widget('Widget_Contents_Post_Edit', NULL, $input, false)->action(); } } } if (!empty($revision->modified)) { foreach ($revision->modified as $file) { $input = $this->parseFileName($file, $data->repository_path); if ($input) { $this->widget('Widget_Contents_Post_Edit', NULL, $input, false)->action(); } } } if (!empty($revision->removed)) { foreach ($revision->removed as $file) { $input = $this->parseFileName($file, $data->repository_path); if ($input && isset($input['cid'])) { $postId = $input['cid']; $this->widget('Widget_Contents_Post_Edit', NULL, "cid={$postId}", false)->deletePost(); } } } } } }
$feed = Typecho_Cookie::get('__typecho_feed'); ?> <div id="typecho-message" class="intro-link"> <ul> <?php if (empty($feed)) { ?> <li><?php _e('读取中...'); ?> </li> <?php } else { ?> <?php $feed = Typecho_Json::decode($feed); foreach ($feed as $item) { ?> <?php $item = (array) $item; ?> <li><a href="<?php echo $item['link']; ?> "><?php echo $item['title']; ?> </a> - <span class="date"><?php echo $item['date']; ?> </span></li>