| にゃんこうけ | src | ブログ | コンタクト | 統計 | | Login |
|
|
|
|
ソースコード・スクリプト・パッチ置き場 |
GeneralItems that do not fit in other categories
NP_AutoTwitter.php.patchNP_AutoTwitter.php.patch *** NP_AutoTwitter.php 2010-10-19 22:11:42.000000000 +0900 --- NP_AutoTwitter.php 2010-11-30 20:16:55.000000000 +0900 *************** *** 17,36 **** // author of plugin function getAuthor(){ global $TWITTER; ! return $TWITTER['AUTHOR']; } // an URL to the plugin website // can also be of the form mailto:foo@bar.com function getURL(){ global $TWITTER; ! return $TWITTER['URL']; } // version of the plugin function getVersion(){ global $TWITTER; ! return $TWITTER['VERSION']; } // a description to be shown on the installed plugins listing --- 17,36 ---- // author of plugin function getAuthor(){ global $TWITTER; ! return $TWITTER['AUTHOR'].' + akebia'; } // an URL to the plugin website // can also be of the form mailto:foo@bar.com function getURL(){ global $TWITTER; ! return 'http://nyan.co.uk/akebia/item/695'; //$TWITTER['URL']; } // version of the plugin function getVersion(){ global $TWITTER; ! return $TWITTER['VERSION'].'-2'; } // a description to be shown on the installed plugins listing *************** *** 50,56 **** function event_PostAddComment(&$data) { global $manager,$blog; if($data['comment']['memberid'] > 0){ ! if($this->getMemberOption($data['comment']['memberid'],'twitterComments')){ // The following line is causing failure, as blogid is not present in the array. if($data['comment']['blogid']){ $blogid=$data['comment']['blogid']; --- 50,56 ---- function event_PostAddComment(&$data) { global $manager,$blog; if($data['comment']['memberid'] > 0){ ! if($this->getMemberOption($data['comment']['memberid'],'twitterComments') === 'yes'){ // The following line is causing failure, as blogid is not present in the array. if($data['comment']['blogid']){ $blogid=$data['comment']['blogid']; *************** *** 70,77 **** $b =& $manager->getBlog($CONF['DefaultBlog']); } $BlogURL = $b->getURL(); ! $URLComponents=explode('?',createItemLink($data['comment']['itemid'])); ! $LinkURL=$BlogURL.'?'.$URLComponents[1].'#c'; $query = 'SELECT i.idraft as draft, i.inumber as itemid, i.iclosed as closed, ' . ' i.ititle as title, i.ibody as body, m.mname as author, ' --- 70,78 ---- $b =& $manager->getBlog($CONF['DefaultBlog']); } $BlogURL = $b->getURL(); ! // $URLComponents=explode('?',createItemLink($data['comment']['itemid'])); ! // $LinkURL=$BlogURL.'?'.$URLComponents[1].'#c'; ! $LinkURL=$this->shortenURL($this->itemURL($BlogURL, $data['comment']['itemid']).'#c'.$data['commentid'], $data['comment']['memberid']); $query = 'SELECT i.idraft as draft, i.inumber as itemid, i.iclosed as closed, ' . ' i.ititle as title, i.ibody as body, m.mname as author, ' *************** *** 100,106 **** $items = sql_query($query); $item = mysql_fetch_object($items); ! if($this->getBlogOption($item->blogid,'twitterNewItems')){ if($item->draft==0){ $this->sendItemTweet($item); } --- 101,107 ---- $items = sql_query($query); $item = mysql_fetch_object($items); ! if($this->getBlogOption($item->blogid,'twitterNewItems') === 'yes'){ if($item->draft==0){ $this->sendItemTweet($item); } *************** *** 127,133 **** $items = sql_query($query); $item = mysql_fetch_object($items); ! if($this->getBlogOption($item->blogid,'twitterNewItems')){ if(($this->itemIsDraft==1)&&($item->draft==0)){ $this->sendItemTweet($item); } --- 128,134 ---- $items = sql_query($query); $item = mysql_fetch_object($items); ! if($this->getBlogOption($item->blogid,'twitterNewItems') === 'yes'){ if(($this->itemIsDraft==1)&&($item->draft==0)){ $this->sendItemTweet($item); } *************** *** 158,163 **** --- 159,172 ---- $this->createMemberOption('twitterComments','Tweet Comments','yesno'); if (count($this->getAllMemberOptions('twitterCommentsTempl'))==0) $this->createMemberOption('twitterCommentsTempl','Tweet Template','text','Commented on %##BLOGNAME##% - %##URL##%'); + if (count($this->getAllMemberOptions('twitterBitly'))==0) + $this->createMemberOption('twitterBitly','Shorten URL with bit.ly','yesno'); + if (count($this->getAllMemberOptions('twitterBitlyDomain'))==0) + $this->createMemberOption('twitterBitlyDomain','bit.ly Domain','text','bit.ly'); + if (count($this->getAllMemberOptions('twitterBitlyUsername'))==0) + $this->createMemberOption('twitterBitlyUsername','bit.ly Username','text',''); + if (count($this->getAllMemberOptions('twitterBitlyAPIKey'))==0) + $this->createMemberOption('twitterBitlyAPIKey','bit.ly API Key','text',''); if (count($this->getAllBlogOptions('twitterNewItems'))==0) $this->createBlogOption('twitterNewItems','Tweet New Posts','yesno'); if (count($this->getAllBlogOptions('twitterNewItemsTempl'))==0) *************** *** 250,267 **** * @return unknown_type */ function sendItemTweet(&$item){ ! global $manager,$blog; // Post tweet for item, but only if the user has a username and password specified. $access_token = TwitterDriver::getAccessTokenForUser($item->authorid); if(TwitterDriver::isValidAccessToken($access_token)){ $b =& $manager->getBlog($item->blogid); $BlogURL = $b->getURL(); ! $URLComponents=explode('?',createItemLink($item->itemid)); ! $LinkURL=$BlogURL.'?'.$URLComponents[1]; ! $twitterNewItemsTempl=$this->getBlogOption($item->authorid,'twitterNewItemsTempl'); $tweet=$this->getReplacedText($twitterNewItemsTempl,$LinkURL,$item->title,$b->getName()); TwitterDriver::sendRawTweet($tweet,$access_token); } } } ?> \ ファイル末尾に改行がありません --- 259,306 ---- * @return unknown_type */ function sendItemTweet(&$item){ ! global $manager,$blog,$CONF; // Post tweet for item, but only if the user has a username and password specified. $access_token = TwitterDriver::getAccessTokenForUser($item->authorid); if(TwitterDriver::isValidAccessToken($access_token)){ $b =& $manager->getBlog($item->blogid); $BlogURL = $b->getURL(); ! // $URLComponents=explode('?',createItemLink($item->itemid)); ! // $LinkURL=$BlogURL.'?'.$URLComponents[1]; ! $LinkURL=$this->shortenURL($this->itemURL($BlogURL, $item->itemid), $item->authorid); ! $twitterNewItemsTempl=$this->getBlogOption($item->blogid,'twitterNewItemsTempl'); $tweet=$this->getReplacedText($twitterNewItemsTempl,$LinkURL,$item->title,$b->getName()); TwitterDriver::sendRawTweet($tweet,$access_token); } } + + function itemURL($blogurl, $itemid){ + global $CONF; + if ($CONF['URLMode'] == 'pathinfo') { + $LinkURL = $blogurl . $CONF['ItemKey'] . '/' . $itemid; + } else { + $LinkURL = $blogurl . '?itemid=' . $itemid; + } + return $LinkURL; + } + + function shortenURL($url, $authorid){ + if($this->getMemberOption($authorid,'twitterBitly') === 'yes'){ + $ch = curl_init(); + $w = array( + CURLOPT_URL => + 'http://api.'.$this->getMemberOption($authorid,'twitterBitlyDomain'). + '/v3/shorten?login='.$this->getMemberOption($authorid,'twitterBitlyUsername'). + '&apiKey='.$this->getMemberOption($authorid,'twitterBitlyAPIKey'). + '&format=txt&longUrl='.$url, + CURLOPT_RETURNTRANSFER => 1 + ); + curl_setopt_array($ch, $w); + $w = curl_exec($ch); + curl_close($ch); + if (substr($w, 0, 7) === 'http://') return $w; + } + return $url; + } } ?> \ ファイル末尾に改行がありません CommentsNo comments yet
Add CommentTrackbackこのトラックバックURL(右クリックして、リンクのURLをコピー)を使ってこの記事にトラックバックを送ることができます。もしあなたのブログがトラックバック送信に対応していない場合にはこちらのフォームからトラックバックを送信することができます。トラックバックの手動送信に失敗したり、拒否された場合には、あけび猫が入力しますので、こちらまでご連絡下さい。重複したトラックバックは、自動的に1つにまとめられるようなので、気軽に色々試してみて下さい。
|