にへるつおるぐ | src | ブログ | コンタクト | 統計 | | Login |
|
|
ソースコード・スクリプト・パッチ置き場 |
GeneralItems that do not fit in other categories NP_AutoTwitter.php.patchNP_AutoTwitter.php.patch --- NP_AutoTwitter.php 2011-01-29 08:27:02.000000000 +0900 +++ NP_AutoTwitter.php 2013-08-18 21:54:14.000000000 +0900 @@ -17,20 +17,20 @@ // author of plugin function getAuthor(){ global $TWITTER; - return $TWITTER['AUTHOR']; + 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 $TWITTER['URL']; + return 'http://nyan.co.uk/akebia/item/695'; //$TWITTER['URL']; } // version of the plugin function getVersion(){ global $TWITTER; - return $TWITTER['VERSION']; + return $TWITTER['VERSION'].'-4'; } // a description to be shown on the installed plugins listing @@ -38,7 +38,7 @@ return 'Allows blog posts to be automatically announced via Twitter.'; } - function getEventList() { return array('PostAddItem','PreUpdateItem','PostUpdateItem','PostAddComment','QuickMenu'); } + function getEventList() { return array('PostAddItem','PreUpdateItem','PostUpdateItem','PostAddComment','QuickMenu','EditItemFormExtras'); } function init() { if (($this->getOption(UpdatePlugin)=="yes") || ($this->getOption(UpdatePlugin)=="")) { @@ -50,7 +50,7 @@ function event_PostAddComment(&$data) { global $manager,$blog; if($data['comment']['memberid'] > 0){ - if($this->getMemberOption($data['comment']['memberid'],'twitterComments')){ + 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,8 +70,9 @@ $b =& $manager->getBlog($CONF['DefaultBlog']); } $BlogURL = $b->getURL(); - $URLComponents=explode('?',createItemLink($data['comment']['itemid'])); - $LinkURL=$BlogURL.'?'.$URLComponents[1].'#c'; +// $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,7 +101,7 @@ $items = sql_query($query); $item = mysql_fetch_object($items); - if($this->getBlogOption($item->blogid,'twitterNewItems')){ + if($this->getBlogOption($item->blogid,'twitterNewItems') === 'yes'){ if($item->draft==0){ $this->sendItemTweet($item); } @@ -121,14 +122,15 @@ $query = 'SELECT i.idraft as draft, i.inumber as itemid,' . ' i.ititle as title,' . ' i.iauthor as authorid,' - . ' i.iblog as blogid ' - . ' FROM '.sql_table('item').' as i' - . ' WHERE i.inumber=' . $data['itemid']; + . ' c.cblog as blogid ' + . ' FROM '.sql_table('item').' as i,'.sql_table('category').' as c' + . ' WHERE i.icat=c.catid && i.inumber=' . $data['itemid']; $items = sql_query($query); $item = mysql_fetch_object($items); - if($this->getBlogOption($item->blogid,'twitterNewItems')){ - if(($this->itemIsDraft==1)&&($item->draft==0)){ + if($this->getBlogOption($item->blogid,'twitterNewItems') === 'yes'){ + if((($this->itemIsDraft==1)||requestvar('plug_autotwitter_tweet'))&& + ($item->draft==0)){ $this->sendItemTweet($item); } } @@ -158,6 +160,14 @@ $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) @@ -251,18 +261,57 @@ * @return unknown_type */ function sendItemTweet(&$item){ - global $manager,$blog; + 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]; - $twitterNewItemsTempl=$this->getBlogOption($item->authorid,'twitterNewItemsTempl'); +// $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; + } + + function event_EditItemFormExtras(&$data) { + if($data['variables']['draft']) return; + global $TWITTER; + echo '<h3>',$TWITTER['TITLE'],'</h3>', + '<p><label>', + '<input name="plug_autotwitter_tweet" type="checkbox">Tweet', + '</label></p>'; + } } ?> \ ファイル末尾に改行がありません CommentsNo comments yet
Add CommentTrackbackこのトラックバックURL(右クリックして、リンクのURLをコピー)を使ってこの記事にトラックバックを送ることができます。もしあなたのブログがトラックバック送信に対応していない場合にはこちらのフォームからトラックバックを送信することができます。トラックバックの手動送信に失敗したり、拒否された場合には、あけび猫が入力しますので、こちらまでご連絡下さい。重複したトラックバックは、自動的に1つにまとめられるようなので、気軽に色々試してみて下さい。 |