Plugin Directory

Changeset 385428


Ignore:
Timestamp:
05/16/2011 01:28:32 PM (15 years ago)
Author:
cooiky
Message:

在日志中提到微博用户,则发通知

File:
1 edited

Legend:

Unmodified
Added
Removed
  • qqpress/trunk/qqpress.php

    r382174 r385428  
    55Author URI: http://www.hencuo.com/
    66Plugin URI: http://app.hencuo.com/qqpress
    7 Description: 新文章发布时,将文章标题和URL发布到你的腾讯微博。
    8 Version: 1.2
     7Description: 新文章发布时,将文章标题和URL发布到你的腾讯微博。插件设置页面直接发微博。在日志中提到微博用户时,则通知这些用户。
     8Version: 1.3
    99*/
    1010
     
    157157//将日志同步到腾讯微博
    158158function qqpress_publish($postID) {
    159     $post = get_post( $postID );
     159    $post = get_post($postID);
    160160   
    161161    //再次确认该日志状态为publish
     
    163163        $message = qqpress_get_message($postID); //格式化同步内容
    164164        qqpress_publish_2_qq($message);
     165       
     166        //如果日志中有提到微博中用户,则发通知
     167        preg_match_all("/@([A-Za-z]{1}[\w|-]*)[\s|,|。|?|,|.|?]/", $post->post_content, $matches);
     168        if (2 == count($matches) && 0 < count($matches[1])) {
     169            $oauth_token = get_option("qq_oauth_token");
     170            $oauth_token_secret = get_option("qq_oauth_token_secret");
     171           
     172            if(!$oauth_token || !$oauth_token_secret)
     173                return;
     174
     175            if(!class_exists('MBOpenTOAuth'))
     176                include dirname(__FILE__).'/opent.php';
     177
     178            global $qq_consumer_key, $qq_consumer_secret;
     179            $to = new MBOpenTOAuth($qq_consumer_key, $qq_consumer_secret, $oauth_token, $oauth_token_secret);
     180
     181            $params = array('format' => 'json', 'name' => "");
     182            $url = "http://open.t.qq.com/api/user/other_info?f=1";
     183            $users = array();
     184            foreach ($matches[1] as $username) {
     185                $params["name"] = $username;
     186                try {
     187                    $result = $to->get($url, $params);
     188                    if (false === array_search($username, $users))
     189                        array_push($users, $result["data"]["name"]);
     190                } catch (Exception $d) {}
     191            }
     192            if (0 < count($users)) {
     193                $message = "我在新日志《" . $post->post_title . "》中提到了@" . implode(" @", $users) ." ". get_permalink($postID);
     194                qqpress_publish_2_qq($message);
     195            }
     196        }
    165197    }
    166198}
    167199
    168200//将日志转换为自定义的同步格式
    169 function qqpress_get_message($postID) {
     201function qqpress_get_message($post, $postID) {
    170202    $proto = get_option('qqpress_message');
    171     $post = get_post($postID);
    172203
    173204    $proto = str_replace("[title]", $post->post_title, $proto);
Note: See TracChangeset for help on using the changeset viewer.