function wp_connect_comment($id) { global $siteurl, $post, $wptm_options, $wptm_connect, $wptm_advanced; $post_id = $_POST['comment_post_ID'] ? $_POST['comment_post_ID'] : $post->ID; if (!$post_id) { return; } @ini_set("max_execution_time", 60); $comments = get_comment($id); $user_id = $comments->user_id; $comment_content = wp_replace($comments->comment_content); $parent_id = $comments->comment_parent; if ($user_id) { if ($parent_id) { $comment_parent = get_comment($parent_id); $parent_uid = $comment_parent->user_id; $name = get_user_meta($parent_uid, 'login_name', true); } $tid = $_POST['sync_comment']; if ($tid) { if (!is_object($post)) { $post = get_post($post_id); } $url = get_permalink($post_id) . '#comment-' . $id; if ($wptm_options['t_cn']) { $url = get_t_cn(urlencode($url)); } $title = wp_replace($post->post_title); $username = get_user_meta($user_id, 'login_name', true); require_once dirname(__FILE__) . '/OAuth/OAuth.php'; if ($tid == 'stid') { $login = get_user_meta($user_id, 'login_sina', true); if ($login[0] && $login[1]) { if (!class_exists('sinaOAuth')) { include dirname(__FILE__) . '/OAuth/sina_OAuth.php'; } $to = new sinaClient(SINA_APP_KEY, SINA_APP_SECRET, $login[0], $login[1]); $content = at_username($name['sina'], $username['sina'], $wptm_connect['sina_username'], $comment_content); //return var_dump($content); $status = wp_status('评论《' . $title . '》: ' . $content, urlencode($url), 140, 1); $result = $to->update($status); } } elseif ($tid == 'qtid') { $login = get_user_meta($user_id, 'login_qq', true); if ($login[0] && $login[1]) { if (!class_exists('qqOAuth')) { include dirname(__FILE__) . '/OAuth/qq_OAuth.php'; } $to = new qqClient(QQ_APP_KEY, QQ_APP_SECRET, $login[0], $login[1]); $content = at_username($name['qq'], $username['qq'], $wptm_connect['qq_username'], $comment_content); $status = wp_status('评论《' . $title . '》: ' . $content, $url, 140, 1); $result = $to->update($status); } } elseif ($tid == 'ntid') { $login = get_user_meta($user_id, 'login_netease', true); if ($login[0] && $login[1]) { if (!class_exists('neteaseOAuth')) { include dirname(__FILE__) . '/OAuth/netease_OAuth.php'; } $to = new neteaseClient(APP_KEY, APP_SECRET, $login[0], $login[1]); $content = at_username($name['netease'], $username['netease'], $wptm_connect['netease_username'], $comment_content); $status = wp_status('评论《' . $title . '》: ' . $content, $url, 163); $result = $to->update($status); } } elseif ($tid == 'shtid') { $login = get_user_meta($user_id, 'login_sohu', true); if ($login[0] && $login[1]) { if (!class_exists('sohuOAuth')) { include dirname(__FILE__) . '/OAuth/sohu_OAuth.php'; } $to = new sohuClient(SOHU_APP_KEY, SOHU_APP_SECRET, $login[0], $login[1]); $content = at_username($name['sohu'], $username['sohu'], $wptm_connect['sohu_username'], $comment_content); $status = wp_status('评论《' . $title . '》: ' . $content, urlencode($url), 140, 1); $result = $to->update($status); } } elseif ($tid == 'dtid') { if ($login = get_user_meta($user_id, 'login_douban', true)) { if ($login[0] && $login[1]) { if (!class_exists('doubanOAuth')) { include dirname(__FILE__) . '/OAuth/douban_OAuth.php'; } $to = new doubanClient(DOUBAN_APP_KEY, DOUBAN_APP_SECRET, $login[0], $login[1]); $status = wp_status('评论《' . $title . '》: ' . $comment_content, $url, 128); $result = $to->update($status); } } } } } }
function wp_connect_comment($id) { global $post, $wptm_options, $wptm_connect; $post_id = isset($_POST['comment_post_ID']) ? $_POST['comment_post_ID'] : $post->ID; if (!$post_id) { return; } @ini_set("max_execution_time", 60); $comments = get_comment($id); $user_id = $comments->user_id; $comment_content = wp_replace($comments->comment_content); $parent_id = $comments->comment_parent; if ($user_id) { if ($parent_id) { $comment_parent = get_comment($parent_id); $parent_uid = $comment_parent->user_id; $name = get_user_meta($parent_uid, 'login_name', true); } $tid = $_POST['sync_comment']; if ($tid) { if (!is_object($post)) { $post = get_post($post_id); } $url = get_permalink($post_id) . '#comment-' . $id; if ($wptm_options['t_cn']) { $url = get_url_short($url); } $title = wp_replace($post->post_title); $username = get_user_meta($user_id, 'login_name', true); require_once dirname(__FILE__) . '/OAuth/OAuth.php'; if ($tid == 'stid') { $login = get_user_meta($user_id, 'login_sina', true); if ($login[0] && $login[1]) { $token = array('access_token' => $login[0], 'expires_in' => $login[1]); // V2.0 $content = at_username($name['sina'], $username['sina'], $wptm_connect['sina_username'], $comment_content); // return var_dump($content); $status = wp_status($content, urlencode($url), 140, 1); $result = wp_update_t_sina($token, $status, ''); } } elseif ($tid == 'qtid') { $login = get_user_meta($user_id, 'login_qq', true); if ($login[0] && $login[1]) { $token = array('oauth_token' => $login[0], 'oauth_token_secret' => $login[1]); $content = at_username($name['qq'], $username['qq'], $wptm_connect['qq_username'], $comment_content); $status = wp_status($content, $url, 140, 1); $result = wp_update_t_qq($token, $status, ''); } } elseif ($tid == 'ntid') { $login = get_user_meta($user_id, 'login_netease', true); if ($login[0] && $login[1]) { $token = array('oauth_token' => $login[0], 'oauth_token_secret' => $login[1]); $content = at_username($name['netease'], $username['netease'], $wptm_connect['netease_username'], $comment_content); $status = wp_status($content, $url, 163); $result = wp_update_t_163($token, $status, ''); } } elseif ($tid == 'shtid') { $login = get_user_meta($user_id, 'login_sohu', true); if ($login[0] && $login[1]) { $token = array('oauth_token' => $login[0], 'oauth_token_secret' => $login[1]); $content = at_username($name['sohu'], $username['sohu'], $wptm_connect['sohu_username'], $comment_content); $status = wp_status($content, $url, 200, 1); $result = wp_update_t_sohu($token, $status, ''); } } elseif ($tid == 'dtid') { if ($login = get_user_meta($user_id, 'login_douban', true)) { if ($login[0] && $login[1]) { $token = array('oauth_token' => $login[0], 'oauth_token_secret' => $login[1]); $status = wp_status($comment_content, $url, 128); $result = wp_update_douban($token, $status); } } } } } }
function wp_connect_publish($post_ID) { global $sync_loaded, $wptm_options; $sync_loaded += 1; if (isset($_POST['publish_no_sync']) || $sync_loaded > 1 || $_POST['post_password']) { return; } @ini_set("max_execution_time", 120); $time = time(); $post = get_post($post_ID); if ($wptm_options['post_types']) { if (in_array($post->post_type, explode(',', $wptm_options['post_types']))) { return; } } $title = wp_replace($post->post_title); $content = $post->post_content; $excerpt = $post->post_excerpt; $post_author_ID = $post->post_author; $post_date = strtotime($post->post_date); $post_modified = strtotime($post->post_modified); $post_content = wp_replace($content); if ($wptm_options['multiple_authors']) { $wptm_profile = get_user_meta($post_author_ID, 'wptm_profile', true); if ($wptm_profile['sync_option']) { $account = wp_usermeta_account($post_author_ID); } } // 是否开启了多作者博客 if ($account) { $sync_option = $wptm_profile['sync_option']; $new_prefix = $wptm_profile['new_prefix']; $update_prefix = $wptm_profile['update_prefix']; $update_days = $wptm_profile['update_days'] * 60 * 60 * 24; $is_author = true; } else { if (!$wptm_options['sync_option']) { return; } $account = wp_option_account(); $sync_option = $wptm_options['sync_option']; $new_prefix = $wptm_options['new_prefix']; $update_prefix = $wptm_options['update_prefix']; $update_days = $wptm_options['update_days'] * 60 * 60 * 24; } // 是否绑定了帐号 if (!$account) { return; } // 新浪微博授权码过期检查 V1.9.22 if (!empty($account['sina']['expires_in'])) { $expires = $account['sina']['expires_in'] - BJTIMESTAMP; if ($expires < 20 * 3600) { if ($is_author) { if (get_current_user_id() == $post_author_ID) { $into = "<a href=" . admin_url('profile.php') . " target=\"_blank\">我的个人资料</a>"; } else { $into = "<a href=" . admin_url("user-edit.php?user_id={$post_author_ID}") . " target=\"_blank\">用户资料</a>"; } } else { $into = "<a href=" . admin_url('options-general.php?page=wp-connect') . " target=\"_blank\">WordPress连接微博插件</a>"; } if ($expires < 60) { return setcookie('sina_access_token_expires', "您的 新浪微博授权码已经过期了,刚刚发布的文章已经取消了所有微博同步,请先到 " . $into . " 重新绑定下新浪微博帐号之后再同步吧,本条提示5分钟后自动消失。", BJTIMESTAMP + 600); } elseif ($expires < 3600) { $expires_in = (int) ($expires / 60) . '分钟'; } else { $expires_in = (int) ($expires / 3600) . '小时'; } setcookie('sina_access_token_expires', "您的 新浪微博授权码再过 " . $expires_in . " 就过期了,咱们先到 " . $into . " 重新绑定下吧,否则不能同步到新浪微博噢,本条提示5分钟后自动消失。", BJTIMESTAMP + 600); } elseif ($_COOKIE['sina_access_token_expires']) { setcookie('sina_access_token_expires', "", BJTIMESTAMP - (BJTIMESTAMP + 600)); } } // 是否为新发布 if (($post->post_status == 'publish' || $_POST['publish'] == 'Publish') && ($_POST['prev_status'] == 'draft' || $_POST['original_post_status'] == 'draft' || $_POST['original_post_status'] == 'auto-draft' || $_POST['prev_status'] == 'pending' || $_POST['original_post_status'] == 'pending')) { $prefix = $new_prefix; } elseif ($_POST['originalaction'] == "editpost" && ($_POST['prev_status'] == 'publish' || $_POST['original_post_status'] == 'publish') && $post->post_status == 'publish') { // 是否已发布 if (isset($_POST['publish_new_sync'])) { $prefix = $new_prefix; } elseif (!isset($_POST['publish_update_sync'])) { if ($update_days == 0 || $time - $post_date < $update_days) { // 判断当前时间与文章发布时间差 return; } } else { $prefix = $update_prefix; } } elseif (isset($_POST['_inline_edit'])) { // 是否是快速编辑 $quicktime = $_POST['aa'] . '-' . $_POST['mm'] . '-' . $_POST['jj'] . ' ' . $_POST['hh'] . ':' . $_POST['mn'] . ':00'; $post_date = strtotime($quicktime); if ($update_days == 0 || $time - $post_date < $update_days) { // 判断当前时间与文章发布时间差 return; } $prefix = $update_prefix; } elseif (defined('DOING_CRON')) { // 定时发布 $prefix = $new_prefix; } else { // 后台快速发布,xmlrpc等发布 if ($post->post_status == 'publish') { if ($post_modified == $post_date || $time - $post_date <= 30) { // 新文章(包括延迟<=30秒) $prefix = $new_prefix; } } } // 微博话题 $cat_ids = $wptm_options['cat_ids']; $enable_cats = $wptm_options['enable_cats']; $enable_tags = $wptm_options['enable_tags']; if ($enable_cats || $cat_ids) { if ($postcats = get_the_category($post_ID)) { foreach ($postcats as $cat) { $cat_id .= $cat->cat_ID . ','; $cat_name .= $cat->cat_name . ','; } // 不想同步的文章分类ID if ($cat_ids && wp_in_array($cat_ids, $cat_id)) { return; } // 是否将文章分类当成话题 if ($enable_cats) { $cats = $cat_name; } } } // 是否将文章标签当成话题 if (substr_count($cats, ',') < 2 && $enable_tags) { if ($posttags = get_the_tags($post_ID)) { foreach ($posttags as $tag) { $tags .= $tag->name . ','; } } } $tags = $cats . $tags; if ($tags) { $tags = explode(',', rtrim($tags, ',')); if (count($tags) == 1) { $tags = '#' . $tags[0] . '# '; } elseif (count($tags) >= 2) { $tags = '#' . $tags[0] . '# #' . $tags[1] . '# '; } } // 文章URL if ($wptm_options['enable_shorten']) { // 是否使用博客默认短网址 $siteurl = get_bloginfo('url'); if ($post->post_type == 'post') { $postlink = $siteurl . "/?p=" . $post_ID; } elseif ($post->post_type == 'page') { $postlink = $siteurl . "/?page_id=" . $post_ID; } else { $postlink = get_permalink($post_ID); } } else { $postlink = get_permalink($post_ID); } $url = $postlink; if ($excerpt) { // 是否有摘要 $post_content = wp_replace($excerpt); } $format = $wptm_options['format']; if ($format && strpos($format, '%title%') !== false) { $format_title = true; $title2 = str_replace('%title%', $title, $format); } else { $title2 = $title . ' | '; } if ($sync_option == '2') { // 同步 前缀+标题+摘要/内容+链接 $text = $tags . $prefix . $title2 . $post_content; } elseif ($sync_option == '3') { // 同步 文章摘要/内容 $text = $tags . $prefix . $post_content; $url = ""; } elseif ($sync_option == '4') { // 同步 文章摘要/内容+链接 $text = $tags . $prefix . $post_content; } elseif ($sync_option == '5') { // 同步 标题 + 内容 $text = $tags . $prefix . $title2 . $post_content; $url = ""; } elseif ($sync_option == '6') { // 同步 标题 $text = $tags . $prefix . $title2; $url = ""; } else { // 同步 标题 + 链接 $title2 = $format_title ? $title2 : $title; $text = $tags . $prefix . $title2; } $richMedia = wp_multi_media_url($content, $post_ID); $list = array('title' => $title, 'content' => $content, 'excerpt' => $excerpt, 'postlink' => $postlink, 'tags' => $tags, 'text' => str_replace(array("[embed]", "[/embed]", $richMedia[1]), "", $text), 'url' => $url, 'richMedia' => $richMedia, 'is_author' => $is_author); $list = apply_filters('post_sync_weibo', $list, $post_ID, $post_author_ID); // return var_dump($list); // $other = array('is_author'=>$is_author, 'uid'=>$post_author_ID); // $account = array_merge($account, $other); if (is_array($list)) { wp_update_list($list['text'], $list['url'], $list['richMedia'], $account, $post_ID); } }
/** * 发布 * @since 1.9.10 */ function wp_connect_publish($post_ID) { global $wptm_options, $siteurl; @ini_set("max_execution_time", 60); $time = time(); $post = get_post($post_ID); $title = wp_replace($post->post_title); $content = $post->post_content; $excerpt = $post->post_excerpt; $postlink = get_permalink($post_ID); $post_author_ID = $post->post_author; $post_date = strtotime($post->post_date); $post_modified = strtotime($post->post_modified); $post_content = wp_replace($content); // 匹配视频、图片 $pic = wp_multi_media_url($content); // 是否有摘要 if ($excerpt) { $post_content = wp_replace($excerpt); } if ($wptm_options['multiple_authors']) { $wptm_profile = get_user_meta($post_author_ID, 'wptm_profile', true); $account = wp_usermeta_account($post_author_ID); } // 是否开启了多作者博客 if ($account && $wptm_profile['sync_option']) { $sync_option = $wptm_profile['sync_option']; $new_prefix = $wptm_profile['new_prefix']; $update_prefix = $wptm_profile['update_prefix']; $update_days = $wptm_profile['update_days'] * 60 * 60 * 24; } else { if (!$wptm_options['sync_option']) { return; } $account = wp_option_account(); $sync_option = $wptm_options['sync_option']; $new_prefix = $wptm_options['new_prefix']; $update_prefix = $wptm_options['update_prefix']; $update_days = $wptm_options['update_days'] * 60 * 60 * 24; } // 是否绑定了帐号 if (!$account) { return; } $cat_ids = $wptm_options['cat_ids']; $enable_cats = $wptm_options['enable_cats']; $enable_tags = $wptm_options['enable_tags']; if ($enable_cats || $cat_ids) { if ($postcats = get_the_category($post_ID)) { foreach ($postcats as $cat) { $cat_id .= $cat->cat_ID . ','; $cat_name .= $cat->cat_name . ','; } // 不想同步的文章分类ID if ($cat_ids && wp_in_array($cat_ids, $cat_id)) { return; } // 是否将文章分类当成话题 if ($enable_cats) { $cats = $cat_name; } } } // 是否将文章标签当成话题 if (substr_count($cats, ',') < 2 && $enable_tags) { if ($posttags = get_the_tags($post_ID)) { foreach ($posttags as $tag) { $tags .= $tag->name . ','; } } } $tags = $cats . $tags; if ($tags) { $tags = explode(',', rtrim($tags, ',')); if (count($tags) == 1) { $tags = '#' . $tags[0] . '# '; } elseif (count($tags) >= 2) { $tags = '#' . $tags[0] . '# #' . $tags[1] . '# '; } } // 是否为新发布 if (($post->post_status == 'publish' || $_POST['publish'] == 'Publish') && ($_POST['prev_status'] == 'draft' || $_POST['original_post_status'] == 'draft' || $_POST['original_post_status'] == 'auto-draft' || $_POST['prev_status'] == 'pending' || $_POST['original_post_status'] == 'pending')) { if ($_POST['publish_no_sync']) { return; } $title = $new_prefix . $title; } elseif ($_POST['originalaction'] == "editpost" && ($_POST['prev_status'] == 'publish' || $_POST['original_post_status'] == 'publish') && $post->post_status == 'publish') { // 是否已发布 if (!$_POST['publish_update_sync']) { if ($time - $post_date < $update_days || $update_days == 0) { // 判断当前时间与文章发布时间差 return; } } if ($_POST['publish_new_sync']) { $update_prefix = $new_prefix; } $title = $update_prefix . $title; } elseif ($_POST['_inline_edit']) { // 是否是快速编辑 $quicktime = $_POST['aa'] . '-' . $_POST['mm'] . '-' . $_POST['jj'] . ' ' . $_POST['hh'] . ':' . $_POST['mn'] . ':00'; $post_date = strtotime($quicktime); if ($time - $post_date < $update_days || $update_days == 0) { // 判断当前时间与文章发布时间差 return; } $title = $update_prefix . $title; } elseif (defined('DOING_CRON')) { // 定时发布 $title = $new_prefix . $title; } else { // 后台快速发布,xmlrpc等发布 if ($post->post_status == 'publish') { if ($post_modified == $post_date || $time - $post_date <= 30) { // 新文章(包括延迟<=30秒) $title = $new_prefix . $title; } else { $title = $title; } } else { $title = $title; } } if ($wptm_options['enable_shorten']) { // 是否使用博客默认短网址 if ($post->post_type == 'page') { $postlink = $siteurl . "/?page_id=" . $post_ID; } else { $postlink = $siteurl . "/?p=" . $post_ID; } } if ($sync_option == '2') { // 同步 前缀+标题+摘要/内容+链接 $title = $tags . $title . " - " . $post_content; } elseif ($sync_option == '3') { // 同步 文章摘要/内容 $title = $tags . $post_content; $postlink = ""; } elseif ($sync_option == '4') { // 同步 文章摘要/内容+链接 $title = $tags . $post_content; } elseif ($sync_option == '5') { // 同步 标题 + 内容 $title = $tags . $title . $post_content; $postlink = ""; } else { $title = $tags . $title; } if ($pic[0] == "image" && $wptm_options['disable_pic']) { $pic = ''; } wp_update_list($title, $postlink, $pic, $account); }
function wp_connect_comment($id) { global $post, $wptm_options, $wptm_connect; $post_id = isset($_POST['comment_post_ID']) ? $_POST['comment_post_ID'] : $post->ID; if (!$post_id) { return; } @ini_set("max_execution_time", 60); $comments = get_comment($id); $user_id = $comments->user_id; $comment_content = wp_replace($comments->comment_content); $parent_id = $comments->comment_parent; if ($user_id) { if ($parent_id) { $comment_parent = get_comment($parent_id); $parent_uid = $comment_parent->user_id; $name = get_user_meta($parent_uid, 'login_name', true); } $tid = $_POST['sync_comment']; if ($tid) { // if (!is_object($post)) { // $post = get_post($post_id); // } $url = get_permalink($post_id) . '#comment-' . $id; if ($wptm_options['t_cn']) { $url = get_url_short($url); } // $title = wp_replace($post -> post_title); $username = get_user_meta($user_id, 'login_name', true); if ($tid == 'stid') { if ($mediaUserID = get_user_meta($user_id, 'smid', true)) { $content = at_username($name['sina'], $username['sina'], $wptm_connect['sina_username'], $comment_content); wp_update_share($mediaUserID, $content, $url); } } elseif ($tid == 'qtid') { if ($mediaUserID = get_user_meta($user_id, 'qmid', true)) { $content = at_username($name['qq'], $username['qq'], $wptm_connect['qq_username'], $comment_content); wp_update_share($mediaUserID, $content, $url); } } elseif ($tid == 'ntid') { if ($mediaUserID = get_user_meta($user_id, 'nmid', true)) { $content = at_username($name['netease'], $username['netease'], $wptm_connect['netease_username'], $comment_content); wp_update_share($mediaUserID, $content, $url); } } elseif ($tid == 'shtid') { if ($mediaUserID = get_user_meta($user_id, 'shmid', true)) { $content = at_username($name['sohu'], $username['sohu'], $wptm_connect['sohu_username'], $comment_content); wp_update_share($mediaUserID, $content, $url); } } elseif ($tid == 'tytid') { if ($mediaUserID = get_user_meta($user_id, 'tymid', true)) { $content = $comment_content; wp_update_share($mediaUserID, $content, $url); } } } } }