$site_ID, 'fcauth' => $fcauth, 'displayName' => $name, 'viewer' => $viewer ); } /** * Post an activity * * Post an activity to Google Friend Connect. The activity is a * message that can include only text and a few HTML elements, namely * b, i, a, and span. * * While the Friend Connect authentication cookie could be obtained * manually, it can also be obtained using {@link gfca_setup()}. * * @param string $fcauth Friend Connect authentication cookie * @param string $activity message representing activity */ function gfca_post_activity($fcauth, $activity) { $url = GFCA_ACTIVITIES . '@me/@self?fcauth=' . $fcauth; $body = json_encode(array( 'title' => $activity )); wp_remote_post($url, array( 'body' => $body, 'headers' => array( 'Content-Type' => 'application/json' ) ) ); } /** * Post the publishing of a post as an activity * * @param int post ID */ function gfca_post_publish_activity($id) { $data = gfca_setup(); if ($data == NULL) return; $title = get_the_title($id); $link = get_permalink($id); $name = $data['displayName']; if ($name != NULL) $format = __('%1$s posted %3$s.', 'gfca'); else $format = __('Posted %3$s.', 'gfca'); $msg = sprintf($format, $name, $link, $title); gfca_post_activity($data['fcauth'], $msg); } /** * Post commenting activity * * @param int comment ID */ function gfca_post_comment_activity($id) { $data = gfca_setup(); if ($data == NULL) return; $title = get_the_title(get_comment($id)->comment_post_ID); $link = get_comment_link($id); $name = $data['displayName']; if ($name != NULL) $format = __('%1$s commented on %3$s.', 'gfca'); else $format = __('Commented on %3$s.', 'gfca'); $msg = sprintf($format, $name, $link, $title); gfca_post_activity($data['fcauth'], $msg); } /** * Post link addition activity * * @param int link ID */ function gfca_post_link_activity($id) { $data = gfca_setup(); if ($data == NULL) return; $bookmark = get_bookmark($id); $title = $bookmark->link_name; $link = $bookmark->link_url; $name = $data['displayName']; if ($name != NULL) $format = __('%1$s added link to %3$s.', 'gfca'); else $format = __('Added link to %3$s.', 'gfca'); $msg = sprintf($format, $name, $link, $title); gfca_post_activity($data['fcauth'], $msg); } /** * Load localization strings */ function gfca_textdomain() { $lang_dir = basename(dirname(__FILE__)) . '/lang'; load_plugin_textdomain('gfca', NULL, $lang_dir); } add_action('publish_post', 'gfca_post_publish_activity'); add_action('comment_post', 'gfca_post_comment_activity'); add_action('add_link', 'gfca_post_link_activity'); add_action('init', 'gfca_textdomain'); ?>