'API Key:', 'type'=>'text', 'default'=>''); $networkpub_settings['id'] = array('label'=>'id', 'type'=>'text', 'default'=>''); $options = get_option(WIDGET_NAME_INTERNAL); function networkpub_init() { wp_enqueue_script('jquery'); wp_register_script('networkpubjs', WP_PLUGIN_URL .'/network-publisher/networkpub.js'); wp_enqueue_script('networkpubjs'); wp_register_style('networkpubcss', WP_PLUGIN_URL . '/network-publisher/networkpub.css'); wp_enqueue_style('networkpubcss'); add_action('admin_menu', 'networkpub_pages'); add_action('{$new_status}_{$post->post_type}', 'networkping'); add_action('publish_post', 'networkping'); } add_action('init', 'networkpub_init'); add_action('init', 'networkpub_remove'); function networkping($id) { if(!$id) { return FALSE; } $options = get_option(WIDGET_NAME_INTERNAL); $link = 'http://www.linksalpha.com/a/ping?id='.$options['id']; $response_full = networkpub_http($link); $response_code = $response_full[0]; if ($response_code === 200) { return TRUE; } return FALSE; } function networkpub_pages() { if ( function_exists('add_submenu_page') ) { $page = add_submenu_page('plugins.php', WIDGET_NAME, WIDGET_NAME, 'manage_options', 'networkpub', 'networkpub_conf'); } } function networkpub_conf() { global $networkpub_settings; if ( isset($_POST['submit']) ) { if ( function_exists('current_user_can') && !current_user_can('manage_options') ) { die(__('Cheatin’ uh?')); } $field_name = sprintf('%s_%s', WIDGET_PREFIX, 'api_key'); $value = strip_tags(stripslashes($_POST[$field_name])); if($value) { $networkadd = networkpub_add($value); } } $options = get_option(WIDGET_NAME_INTERNAL); $html = '
'; $html .= '

 '.WIDGET_NAME.'

'; $html .= '
'; $html .= '
Network Publisher makes it easy and painless to Publish your Blog Posts to Social Networks. All you need to do is connect to your Social Networks at LinksAlpha.com, grab API Key for each enabled Network and enter it below. Once setup, your Blog posts content appears on the social networks as soon as you hit the Publish button.
'; $html .= '
Click Here to get API Keys for your Social Networks. You can read more about this process at LinksAlpha.com.
'; $html .= '
Setup
'; $html .= '
'; $html .= '
'; $html .= '
'; $html .= 'Additional API Key'; $curr_field = 'api_key'; $field_name = sprintf('%s_%s', WIDGET_PREFIX, $curr_field); $html .= '
'; $html .= '
'; $html .= '
'; $html .= '
'; $html .= '
'; $html .= '
Currently Publishing
'; $html .= '
'.networkpub_load().'
'; $html .= '
More Plugins
'; echo $html; } function more_plugins() { $html = '
Setup
'; echo $html; } function networkpub_add($api_key) { if (!$api_key) { echo '
Error occured while processing your request. Error Code 100
'; return FALSE; } $url = get_option('siteurl'); $desc = get_bloginfo('description'); if (!$url) { echo '
Error occured while processing your request. Error Code 200
'; return FALSE; } $link = 'http://www.linksalpha.com/a/networkpubadd?url='.urlencode($url).'&key='.$api_key; $response_full = networkpub_http($link); $response_code = $response_full[0]; if ($response_code != 200) { echo '
Error occured while adding the API Key. As a workaround, you can configure the publishing at the following link: LinksAlpha Publisher
'; return FALSE; } $response = networkpub_json_decode($response_full[1]); if ($response->errorCode > 0) { if ($response->errorMessage == ERROR_INVALID_KEY) { echo '
Error occured while processing your request. Please input valid API Key. Error Code 400
'; } else { echo '
Error occured while processing your request. Error Code 500
'; } return FALSE; } $options = get_option(WIDGET_NAME_INTERNAL); if(empty($options['api_key'])) { $options['api_key'] = $api_key; } else { $options_array = explode(',', $options['api_key']); if(!in_array($api_key, $options_array)) { $options['api_key'] = $options['api_key'].','.$api_key; } } $options['id'] = $response->results->id; update_option(WIDGET_NAME_INTERNAL, $options); echo '
API Key has been added successfully
'; return TRUE; } function networkpub_load() { $options = get_option(WIDGET_NAME_INTERNAL); if (empty($options['api_key'])) { $html = '
You have not added any API Key
'; return $html; } $link = 'http://www.linksalpha.com/a/networkpubget'; $body = array('key'=>$options['api_key']); $response_full = networkpub_http_post($link, $body); $response_code = $response_full[0]; if ($response_code != 200) { $html = '
Error occured while trying to load the API Keys. Please try again later.
'; return $html; } $response = networkpub_json_decode($response_full[1]); if($response->errorCode > 0) { $html = '
Error occured while trying to load the API Keys. Please try again later.
'; return $html; } $html = '
You are currently Publishing your Blog to '.count($response->results).' Social Networks
'; $html .= ''; if (count($response->results)) { foreach($response->results as $row) { $html .= ''; switch($row->type) { case 'twitter': $html .= ''; break; case 'fb_page': $html .= ''; break; case 'fb_wall': $html .= ''; break; case 'myspace': $html .= ''; break; case 'linkedin': $html .= ''; break; case 'yammer': $html .= ''; break; case 'yahoo': $html .= ''; break; case 'identica': $html .= ''; break; } $html .= ''; } } else { $html .= ''; } $html .= '
API KeyNetworkOption
'.$row->api_key.'Twitter Account - '.$row->name.''.$row->api_key.'Facebook Page - '.$row->name.''.$row->api_key.''.$row->name.''.$row->api_key.'MySpace Account - '.$row->name.''.$row->api_key.'LinkedIn Account - '.$row->name.''.$row->api_key.'Yammer Account - '.$row->name.''.$row->api_key.'Yahoo Account - '.$row->name.''.$row->api_key.'Identi.ca Account - '.$row->short_name.'Remove
No API Keys have been added
'; return $html; } function networkpub_remove() { $options = get_option(WIDGET_NAME_INTERNAL); if (!empty($_POST['key'])) { $key_full = $_POST['key']; $key_only = substr($key_full, 4); $link = 'http://www.linksalpha.com/a/networkpubremove?id='.$options['id'].'&key='.$key_only; $response_full = networkpub_http($link); $response_code = $response_full[0]; if ($response_code != 200) { echo 500; return; } $api_key = $options['api_key']; $api_key_array = explode(',', $api_key); $loc = array_search($key_only, $api_key_array); if($loc !== FALSE) { unset($api_key_array[$loc]); } $api_key = implode(",", $api_key_array); $options['api_key'] = $api_key; update_option(WIDGET_NAME_INTERNAL, $options); echo $key_full; return; } } function networkpub_json_decode($str) { if (function_exists("json_decode")) { return json_decode($str); } else { if (!class_exists('Services_JSON')) { require_once("JSON.php"); } $json = new Services_JSON(); return $json->decode($str); } } function networkpub_http($link) { if (!$link) { return array(500, 'Invalid Link'); } require_once(ABSPATH.WPINC.'/class-snoopy.php'); $snoop = new Snoopy; $snoop->agent = WIDGET_NAME.' - '.get_option('siteurl'); if($snoop->fetchtext($link)){ if (strpos($snoop->response_code, '200')) { $response = $snoop->results; return array(200, $response); } } if( !class_exists( 'WP_Http' ) ) { include_once( ABSPATH . WPINC. '/class-http.php' ); } if (!class_exists('WP_Http')) { return array(500, $snoop->response_code); } $request = new WP_Http; $headers = array( 'Agent' => WIDGET_NAME.' - '.get_option('siteurl') ); $response_full = $request->request( $link ); $response_code = $response_full['response']['code']; if ($response_code === 200) { $response = $response_full['body']; return array($response_code, $response); } $response_msg = $response_full['response']['message']; return array($response_code, $response_msg); } function networkpub_http_post($link, $body) { if (!$link) { return array(500, 'Invalid Link'); } require_once(ABSPATH.WPINC.'/class-snoopy.php'); $snoop = new Snoopy; $snoop->agent = WIDGET_NAME.' - '.get_option('siteurl'); if($snoop->submit($link, $body)){ if (strpos($snoop->response_code, '200')) { $response = $snoop->results; return array(200, $response); } } if( !class_exists( 'WP_Http' ) ) { include_once( ABSPATH . WPINC. '/class-http.php' ); } if (!class_exists('WP_Http')) { return array(500, $snoop->response_code); } $request = new WP_Http; $headers = array( 'Agent' => WIDGET_NAME.' - '.get_option('siteurl') ); $response_full = $request->request( $link, array( 'method' => 'POST', 'body' => $body, 'headers'=>$headers) ); $response_code = $response_full['response']['code']; if ($response_code === 200) { $response = $response_full['body']; return array($response_code, $response); } $response_msg = $response_full['response']['message']; return array($response_code, $response_msg); } ?>