api_client->session_key != '') { $result = $fb->api_client->users_getLoggedInUser(); } else { $result = null; } } catch (Exception $e) { $result = null; salsa_debug_log('Exception in FacebookConnect::getFacebookUID: ' . $e->getMessage()); } return $result; } function salsa_fb_pages(&$fb, $fb_uid) { $fql = 'SELECT page_id FROM page_admin WHERE uid = ' . $fb_uid; try { salsa_debug_log($fql); $fql_results = $fb->api_client->fql_query($fql); salsa_debug_log($page_ids); $page_ids = array(); foreach($fql_results as $fql_result) { $page_ids[] = $fql_result['page_id']; } salsa_debug_log('calling baton rouge'); $pages = implode(',', $page_ids); salsa_debug_log($pages); $result = $fb->api_client->pages_getInfo($pages, 'name, page_url, website', '', ''); salsa_debug_log($result); } catch (Exception $e) { salsa_debug_log('Exception in FacebookConnect::getPagesForUID: ' . $e->getMessage()); $result = array(); } return $result; } function salsa_connect_options_form() { $submitted = false; if (isset($_REQUEST['nonce']) && ($nonce = $_REQUEST['nonce'])) { if (wp_verify_nonce($nonce, 'salsa')) { $submitted = true; update_option('salsa.twitter_notify', $_REQUEST['twitter_notify']); update_option('salsa.twitter_username', $_REQUEST['twitter_username']); update_option('salsa.twitter_password', trim($_REQUEST['twitter_password'])); update_option('salsa.bitly_api_key', trim($_REQUEST['bitly_api_key'])); update_option('salsa.bitly_api_login', trim($_REQUEST['bitly_api_login'])); update_option('salsa.url_shortener_svc', trim($_REQUEST['url_shortener_svc'])); update_option('salsa.facebook_notify', trim($_REQUEST['facebook_notify'])); update_option('salsa.facebook_api_key', trim($_REQUEST['facebook_api_key'])); update_option('salsa.facebook_app_secret', trim($_REQUEST['facebook_app_secret'])); update_option('salsa.facebook_page', trim($_REQUEST['facebook_page'])); } } switch (get_option("salsa.url_shortener_svc", 'tinyurl')) { case 'tinyurl': $cur_url_shortener_svc_id = 0; break; case 'bitly': $cur_url_shortener_svc_id = 1; break; } ?>
 

Salsa Options

Settings saved.

Twitter Settings

/>

" />

" />

Facebook Settings

>

To get started with Facebook, you must first create an application on Facebook. Blah, blah, blah...

" />

" />

>

/>

Grant publish permissions

Short URL Settings

Please select a service below and enter the appropriate information.

Nothing to set up here.

" />

" />

Salsa

/>
/>
$value) { curl_setopt($curl_handle, $name, $value); } $buffer = curl_exec($curl_handle); $curlinfo = curl_getinfo($curl_handle); salsa_debug_log($buffer); salsa_debug_log($curlinfo); curl_close($curl_handle); if (($curlinfo['http_code'] < 400) && ($curlinfo['http_code'] != 0)) { return $buffer; } else { return false; } } function salsa_shorten_url($post_url) { $svc = get_option('salsa.url_shortener_svc', 'tinyurl'); if ($svc == 'bitly') { $bitly_key = get_option('salsa.bitly_api_key', ''); $bitly_login = get_option('salsa.bitly_api_login', ''); if (($bitly_key != '') && ($bitly_login != '')) { $uri = 'http://api.bit.ly/shorten?version=2.0.1&longUrl=' . urlencode($post_url) . '&login=' . urlencode($bitly_login) . '&apiKey=' . urlencode($bitly_key); $res = salsa_curl($uri, $post_url); $res_obj = json_decode($res); salsa_debug_log($res_obj); if ($res_obj->errorCode == 0) { $real_res = (array) $res_obj->results; $short_api_obj = $real_res[$post_url]; return $short_api_obj->shortUrl; } } } $uri = 'http://tinyurl.com/api-create.php?url=' . urlencode($post_url); return salsa_curl($uri, $post_url); } function salsa_do_notify_twitter(&$post) { salsa_debug_log('do_notify_twitter'); $url = get_permalink($post->ID); $short_url = salsa_shorten_url($url); salsa_debug_log('url: ' . $url); salsa_debug_log('short_url: ' . $short_url); $twitter_username = get_option('salsa.twitter_username', ''); $twitter_password = get_option('salsa.twitter_password', ''); salsa_debug_log($twitter_username . ':' . $twitter_password); if (($twitter_username != '') && ($twitter_password != '')) { $status = $post->post_title . ' ' . $short_url; $post_fields = array('status' => $status); $curl_options = array(CURLOPT_POST => 1, CURLOPT_HTTPHEADER => array('Expect:'), CURLOPT_POSTFIELDS => $post_fields, CURLOPT_USERPWD => $twitter_username . ':' . $twitter_password); salsa_curl('https://twitter.com/statuses/update.json', $url, $curl_options); } add_post_meta($post->ID, '_salsa_twitter_notified', date('Ymd')); } function salsa_find_imgs($post_body) { if (preg_match_all('|ID); $fb_api_key = get_option("salsa.facebook_api_key", ""); $fb_app_secret = get_option("salsa.facebook_app_secret", ""); $fb = salsa_fb_obj($fb_api_key, $fb_app_secret); $fb_uid = salsa_fb_connected($fb); $fb_page_id = get_option('salsa.facebook_page', $fb_uid); $media = null; $imgs = salsa_find_imgs($post->post_content); if (count($imgs) > 0) { $media = array(array('type' => 'image', 'src' => $imgs[0], 'href' => $url)); } $message = $post->post_title . ' - ' . $url; $attachment = array('name' => $post->post_title, 'href' => $url, 'caption' => 'www.xxxxxxx.com', 'description' => 'xxxxxxx', 'media' => $media, ); $action_links = array( array('text' => 'Share', 'href' => 'http://www.facebook.com/share.php?u=' . urlencode($url) )); $attachment = json_encode($attachment); $action_links = json_encode($action_links); //$action_links = null; if ($fb_uid == $fb_page_id) { $result = $fb->api_client->stream_publish($message, $attachment, $action_links); } else { $result = $fb->api_client->stream_publish($message, $attachment, $action_links, null, $fb_page_id); } salsa_debug_log('result: ' . $result); add_post_meta($post->ID, '_salsa_facebook_notified', date('Ymd')); } function salsa_publish_post($post_id) { salsa_debug_log('salsa_publish_post'); $post = get_post($post_id); $notify_twitter = get_post_meta($post_id, '_salsa_notify_twitter', true); $notify_facebook = get_post_meta($post_id, '_salsa_notify_facebook', true); $url = get_permalink($post_id); salsa_debug_log($post); salsa_debug_log($notify_twitter); salsa_debug_log($notify_facebook); salsa_debug_log('perm: ' . $url); $twitter_notified = get_post_meta($post_id, '_salsa_twitter_notified', true); $facebook_notified = get_post_meta($post_id, '_salsa_facebook_notified', true); salsa_debug_log('salsa_twitter_notified: ' . $twitter_notified); salsa_debug_log('salsa_facebook_notified: ' . $facebook_notified); $installed_date = get_option('salsa.installed_date', date('Y-m-d')); $post_date = date('Ymd', strtotime($post->post_date)); salsa_debug_log('post_date: ' . $post_date); if (($notify_twitter == 'yes') && ($twitter_notified == '')) { if ($post_date >= $installed_date) { salsa_do_notify_twitter($post); } } if (($notify_facebook == 'yes') && ($facebook_notified == '')) { if ($post_date >= $installed_date) { salsa_do_notify_facebook($post); } } } function salsa_store_post_options($post_id, $post = false) { salsa_debug_log("salsa_store_post_options"); salsa_debug_log($post_id); salsa_debug_log($_POST); if (count($_POST) == 0) { return; } $notify_twitter = isset($_POST['salsa_notify_twitter']) ? 'yes' : 'no'; $notify_facebook = isset($_POST['salsa_notify_facebook']) ? 'yes' : 'no'; if (!update_post_meta($post_id, '_salsa_notify_twitter', $notify_twitter)) { add_post_meta($post_id, '_salsa_notify_twitter', $notify_twitter); } if (!update_post_meta($post_id, '_salsa_notify_facebook', $notify_facebook)) { add_post_meta($post_id, '_salsa_notify_facebook', $notify_facebook); } }