true), 'objects' ); foreach ( $post_types as $post_type ) { if ( $post->post_type == $post_type->name ) { networkpub_ping($post->ID, $post); break; } } } return; } function lacandsnw_convert($id) { if(!$id) { return; } $options = get_option(LAECHONW_WIDGET_NAME_INTERNAL); if(!empty($options['id_2'])) { return; } if(empty($options['lacandsnw_id']) or empty($options['api_key'])) { return; } // Build Params $link = 'http://www.linksalpha.com/a/networkpubconvert'; $params = array('id'=>$options['lacandsnw_id'], 'api_key'=>$options['api_key'], 'plugin'=>LACANDSNW_PLUGIN_NAME, ); //HTTP Call $response_full = lacandsnw_networkpub_http_post($link, $params); $response_code = $response_full[0]; if ($response_code != 200) { return; } $response = lacandsnw_networkpub_json_decode($response_full[1]); if ($response->errorCode > 0) { return; } //Update options $options['id_2'] = $response->results; //Save update_option(LAECHONW_WIDGET_NAME_INTERNAL, $options); return; } function lacandsnw_post($post_id) { //Network keys $options = get_option(LAECHONW_WIDGET_NAME_INTERNAL); if (empty($options['api_key']) or empty($options['id_2'])) { return; } $id = $options['id_2']; $api_key = $options['api_key']; //Post data $post_data = get_post( $post_id, ARRAY_A ); //Post Published? if(in_array($post_data['post_status'], array('future', 'publish'))) { //Post too old $post_date = strtotime($post_data['post_date_gmt']); $current_date = time(); $diff = $current_date - $post_date; $days = floor( $diff / (60*60*24) ); if($days > 3) { return; } //Post data: id, content and title $post_title = $post_data['post_title']; $post_content = $post_data['post_content']; //Post data: Permalink $post_link = get_permalink($post_id); //Post data: Categories $post_categories_array = array(); $post_categories_data = get_the_category( $post_id ); foreach($post_categories_data as $category) { $post_categories_array[] = $category->cat_name; } $post_categories = implode(",", $post_categories_array); //Post tags $post_tags_array = array(); $post_tags_data = wp_get_post_tags( $post_id ); foreach($post_tags_data as $tag) { $post_tags_array[] = $tag->name; } $post_tags = implode(",", $post_tags_array); //Post Geo if(function_exists('get_wpgeo_latitude')) { if(get_wpgeo_latitude( $post_id ) and get_wpgeo_longitude( $post_id )) { $post_geotag = get_wpgeo_latitude( $post_id ).' '.get_wpgeo_longitude( $post_id ); } } if(!isset($post_geotag)) { $post_geotag = ''; } // Build Params $link = 'http://www.linksalpha.com/a/networkpubpost'; $params = array('id'=>$id, 'api_key'=>$api_key, 'post_id'=>$post_id, 'post_link'=>$post_link, 'post_title'=>$post_title, 'post_content'=>$post_content, 'plugin'=>LACANDSNW_PLUGIN_NAME, 'plugin_version'=>lacandsnw_version(), 'post_categories'=>$post_categories, 'post_tags'=>$post_tags, 'post_geotag'=>$post_geotag ); //Featured Image $post_image = lacandsnw_thumbnail_link( $post_id ); if($post_image) { $params['post_image'] = $post_image; } //HTTP Call $response_full = lacandsnw_networkpub_http_post($link,$params); } return; } function lacandsnw_post_xmlrpc($post_id) { lacandsnw_post($post_id); } function lacandsnw_post_custom($new, $old, $post) { if ($new == 'publish' && $old != 'publish') { $post_types = get_post_types( array('public' => true), 'objects' ); foreach ( $post_types as $post_type ) { if ( $post->post_type == $post_type->name ) { networkpub_post($post->ID, $post); break; } } } return; } function lacandsnw_networkpub_add($api_key) { if (!$api_key) { $errdesc = lacandsnw_error_msgs('invalid key'); echo $errdesc; return; } $url = get_bloginfo('url'); if (!$url) { $errdesc = lacandsnw_error_msgs('invalid url'); echo $errdesc; return; } $desc = get_bloginfo('description'); $options = get_option(LAECHONW_WIDGET_NAME_INTERNAL); if(!empty($options['lacandsnw_id'])) { $id = $options['lacandsnw_id']; } elseif (!empty($options['id_2'])) { $id = $options['id_2']; } else { $id = ''; } $url_parsed = parse_url($url); $url_host = $url_parsed['host']; if( substr_count($url, 'localhost') or strpos($url_host, '192.168.') === 0 or strpos($url_host, '127.0.0') === 0 or (strpos($url_host, '172.') === 0 and (int)substr($url_host, 4, 2) > 15 and (int)substr($url_host, 4, 2) < 32 ) or strpos($url_host, '10.') === 0 ) { $errdesc = lacandsnw_error_msgs('localhost url'); echo $errdesc; return FALSE; } $link = 'http://www.linksalpha.com/a/networkpubaddone'; // Build Params $params = array('url'=>urlencode($url), 'key'=>$api_key, 'plugin'=>LACANDSNW_PLUGIN_NAME, 'id'=>$id); //HTTP Call $response_full = lacandsnw_networkpub_http_post($link,$params); $response_code = $response_full[0]; if ($response_code != 200) { $errdesc = lacandsnw_error_msgs($response_full[1]); echo $errdesc; return FALSE; } $response = lacandsnw_networkpub_json_decode($response_full[1]); if ($response->errorCode > 0) { $errdesc = lacandsnw_error_msgs($response->errorMessage); echo $errdesc; return FALSE; } //Update options - Site id $options['id_2'] = $response->results->id; //Update options - Network Keys if(empty($options['api_key'])) { $options['api_key'] = $response->results->api_key; } else { $option_api_key_array = explode(',', $options['api_key']); $option_api_key_new = $response->results->api_key; $option_api_key_new_array = explode(',', $option_api_key_new); foreach($option_api_key_new_array as $key=>$val) { if(!in_array($val, $option_api_key_array)) { $options['api_key'] = $options['api_key'].','.$val; } } } //Save update_option(LAECHONW_WIDGET_NAME_INTERNAL, $options); //Return echo '
API Key has been added successfully
'; return; } function lacandsnw_networkpub_load() { $options = get_option(LAECHONW_WIDGET_NAME_INTERNAL); if (empty($options['api_key'])) { $html = '
'.LACANDSNW_YOU_HAVE_NOT_ADDED_ANY_API_KEY.'
'; echo $html; return; } $link = 'http://www.linksalpha.com/a/networkpubget'; $body = array('key'=>$options['api_key'], 'version'=>2); $response_full = lacandsnw_networkpub_http_post($link, $body); $response_code = $response_full[0]; if ($response_code != 200) { $errdeschtml = lacandsnw_error_msgs($response_full[1]); echo $errdeschtml; return; } $response = lacandsnw_networkpub_json_decode($response_full[1]); if($response->errorCode > 0) { $html = '
'.LACANDSNW_ERROR_LOADING_API_KEYS.'.
'; echo $html; return; } if(count($response->results_deleted)) { $option_api_key_array = explode(',', $options['api_key']); foreach($response->results_deleted as $row) { if(in_array($row, $option_api_key_array)) { $pos = $option_api_key_array[$row]; unset($option_api_key_array[$pos]); } } $api_key = implode(",", $option_api_key_array); $options['api_key'] = $api_key; update_option(LAECHONW_WIDGET_NAME_INTERNAL, $options); } if(!count($response->results)) { return '
You have not added an API Key
'; } if(count($response->results) == 1) { $html = '
'.LACANDSNW_CURRENTLY_PUBLISHING.' '.count($response->results).' '.LACANDSNW_SOCIAL_NETWORK.'
'; } else { $html = '
'.LACANDSNW_CURRENTLY_PUBLISHING.' '.count($response->results).' '.LACANDSNW_SOCIAL_NETWORKS.'
'; } $html .= ''; $i = 1; foreach($response->results as $row) { $html .= ''; if($i&1) { $html .= ''; if($i&1) { $html .= ''; if($i&1) { $html .= ''; $html .= ''; $i++; } $html .= '
'.__('Network').''.__('Option').''.__('Remove').'
'; } else { $html .= ''; } $html .= ''.$row->name.''; } else { $html .= ''; } $html .= ''.__('Options').''; } else { $html .= ''; } $html .= ''.__('Remove').'
'; echo $html; return; } function lacandsnw_networkpub_ajax() { if(!empty($_POST['type'])) { if(in_array($_POST['type'],array('remove','load'))) { if($_POST['type']=='remove') { lacandsnw_networkpub_remove($_POST['key']); } if($_POST['type']=='load') { lacandsnw_networkpub_load(); } } } } function lacandsnw_networkpub_remove() { $options = get_option(LAECHONW_WIDGET_NAME_INTERNAL); if (!empty($_POST['lacandsnw_networkpub_key'])) { $key_full = $_POST['lacandsnw_networkpub_key']; $key_only = trim(substr($key_full, 4)); $link = 'http://www.linksalpha.com/a/networkpubremove'; $body = array('id'=>$options['id_2'], 'key'=>$key_only); $response_full = lacandsnw_networkpub_http_post($link, $body); $response_code = $response_full[0]; if ($response_code != 200) { $errdesc = lacandsnw_error_msgs($response_full[1]); echo $errdesc; return; } $api_key = $options['api_key']; $api_key_array = explode(',', $api_key); $loc = array_search($key_only, $api_key_array, True); if($loc !== FALSE) { unset($api_key_array[$loc]); } $api_key = implode(",", $api_key_array); $options['api_key'] = $api_key; update_option(LAECHONW_WIDGET_NAME_INTERNAL, $options); echo $key_full; return; } } function lacandsnw_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 lacandsnw_networkpub_http($link) { if (!$link) { return array(500, 'invalid url'); } if( !class_exists( 'WP_Http' ) ) { include_once( ABSPATH . WPINC. '/class-http.php' ); } if (class_exists('WP_Http')) { $request = new WP_Http; $headers = array( 'Agent' => LAECHONW_WIDGET_NAME.' - '.get_bloginfo('url') ); $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); } require_once(ABSPATH.WPINC.'/class-snoopy.php'); $snoop = new Snoopy; $snoop->agent = LAECHONW_WIDGET_NAME.' - '.get_bloginfo('url'); if($snoop->fetchtext($link)){ if (strpos($snoop->response_code, '200')) { $response = $snoop->results; return array(200, $response); } } return array(500, 'internal error'); } function lacandsnw_networkpub_http_post($link, $body) { if (!$link) { return array(500, 'invalid url'); } if( !class_exists( 'WP_Http' ) ) { include_once( ABSPATH . WPINC. '/class-http.php' ); } if (class_exists('WP_Http')) { $request = new WP_Http; $headers = array( 'Agent' => LAECHONW_WIDGET_NAME.' - '.get_bloginfo('url') ); $response_full = $request->request( $link, array( 'method' => 'POST', 'body' => $body, 'headers'=>$headers) ); if(isset($response_full->errors)) { return array(500, 'internal error'); } $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); } require_once(ABSPATH.WPINC.'/class-snoopy.php'); $snoop = new Snoopy; $snoop->agent = LAECHONW_WIDGET_NAME.' - '.get_bloginfo('url'); if($snoop->submit($link, $body)){ if (strpos($snoop->response_code, '200')) { $response = $snoop->results; return array(200, $response); } } return array(500, 'internal error'); } function lacandsnw_error_msgs($errMsg) { $arr_errCodes = explode(";", $errMsg); $errCodesCount = count($arr_errCodes); switch (trim($arr_errCodes[0])) { case 'internal error': $html = '
'.__('Please try again. Wait for sometime and try again').' '.__('There was an unknown error. Please try again. You can also email us at').' post@linksalpha.com '.__('with error description (your blog URL and the error)').'.
'; return $html; break; case 'invalid url': $html = '
'.__('Your blog URL is invalid').':'.$arr_errCodes[$errCodesCount-1]; if($errCodesCount == 3) { $html .= '. '.__('Error Code').' ='.$arr_errCodes[$errCodesCount-2]; } $html .= '
'.__('You can also').' '.__('Click here').''.__(' to enter blog URL on LinksAlpha manually. Also ensure that in ').''.__('Settings').'->'.__('General').'->"'.__('Blog address (URL)').'" '.__('the URL is filled-in correctly').'.
'.__('If you still face issues then email us at').' post@linksalpha.com '.__('with error description').'.
'; return $html; break; case 'localhost url': $html = '
'.__('Website/Blog inaccessible').'
'; $html .= '
'.__('You are trying to use the plugin on ').'localhost '.__('or behind a').' '.__('firewall').', '.__('which is not supported. Please install the plugin on a Wordpress blog on a live server').'.
'; return $html; break; case 'remote url error': $html = '
'.__('Remote URL error').': '.$arr_errCodes[$errCodesCount-1]; if($errCodesCount == 3) { $html .= '. '.__('Error Code').' ='.$arr_errCodes[$errCodesCount-2]; } $html .= '
'.__('Description:').' '.__('Please try again').'. '.__('Your site either did not respond (it is extremely slow) or it is not operational').'.
'.__('You can also').' '.__('Click here').' '.__('to enter blog URL on LinksAlpha manually').'. '.__('Also ensure that in').' '.__('Settings').'->'.__('General').'->"'.__('Blog address (URL)').'" '.__('the URL is filled-in correctly').'.
'.__('If you still face issues then email us at').' post@linksalpha.com '.__('with error description').'.
'; return $html; break; case 'feed parsing error': $html = '
'.__('Feed parsing error').': '.$arr_errCodes[$errCodesCount-1]; if($errCodesCount == 3) { $html .= '. '.__('Error Code').'= '.$arr_errCodes[$errCodesCount-2]; } $html .= '
'.__('Description').': '.__('Your RSS feed has errors. Pls go to').' href=http://beta.feedvalidator.org/ '.__('to validate your RSS feed').'.
'.__('If it comes out to be correct, try again and email as at ').'post@linksalpha.com '.__('with your blog URL and error description').'.
'; return $html; break; case 'feed not found': $html ='
'.__('We could not find feed URL for your blog').'.
'.__('Click here').' '.__('to enter feed URL on LinksAlpha manually').'. '.__('Also ensure that in ').''.__('Settings').'->'.__('General').'->"'.__('Blog address (URL)').'" '.__('the URL is filled-in correctly').'.
'.__('If you still face issues then email us at ').'post@linksalpha.com '.__('with error description').'
'; return $html; break; case 'invalid key': $html = '
'.__('Invalid Key').': '.__('the key that you entered is incorrect. Please try again').'.
'.__('Getting Errors').'? '.__('See help page').' '.__('here').'
'.__('Or').', '.__('Click here').' '.__('to enter your blog URL on LinksAlpha manually').'. '.__('If you still face issues then email us at ').'post@linksalpha.com '.__('with error description').'
'; return $html; break; case 'subscription upgrade required': $html = '
'.__('Upgrade account').'. '.__('Please').' '.__('upgrade your subscription').' '.__('to add more networks').'.
'; return $html; break; default: $html = '
'.__('Sorry we are undergoing maintenance at this time - this happens very rarely but is critical to ensure continued availability. We apologize for the inconvenience.').' '.__('This can take upto 2 hours maximum. Please try again after sometime and it is guaranteed to work').'. '.__('You can also email us at').' post@linksalpha.com '.__('if issue persists. Thanks for your understanding').'
'; return $html; break; } } function lacandsnw_pushpresscheck() { $active_plugins = get_option('active_plugins'); $pushpress_plugin = 'pushpress/pushpress.php'; $this_plugin_key = array_search($pushpress_plugin, $active_plugins); if ($this_plugin_key) { $options = get_option(LAECHONW_WIDGET_NAME_INTERNAL); if(array_key_exists('lacandsnw_id', $options)) { if($options['lacandsnw_id']) { $link = 'http://www.linksalpha.com/a/pushpress'; $body = array('id'=>$options['lacandsnw_id']); $response_full = lacandsnw_networkpub_http_post($link, $body); $response_code = $response_full[0]; } } } } function lacandsnw_networkpubcheck() { $active_plugins = get_option('active_plugins'); $pushpress_plugin = 'network-publisher/networkpub.php'; $this_plugin_key = array_search($pushpress_plugin, $active_plugins); if ($this_plugin_key) { return True; } return False; } function lacandsnw_postbox_url() { if ( version_compare($wp_version, '3.0.0', '<') ) { $admin_url = get_bloginfo('url').'/wp-admin/edit.php?page='.LACANDSNW_WIDGET_NAME_POSTBOX_INTERNAL; } else { $admin_url = get_admin_url().'/edit.php?page='.LACANDSNW_WIDGET_NAME_POSTBOX_INTERNAL; } return $admin_url; } function lacandsnw_postbox(){ $html = '

'.LAECHONW_WIDGET_NAME.' - '.LACANDSNW_WIDGET_NAME_POSTBOX.'

'; $html .= ''; $html .= '
'.__('Share this Plugin').'
'; echo $html; return; } function lacandsnw_thumbnail_link( $post_id ) { if(!function_exists('get_post_thumbnail_id')) { return False; } $src = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), 'full'); if($src) { $src = $src[0]; return $src; } else { return False; } } function lacandsnw_version() { return LACANDSNW_PLUGIN_VERSION; } ?>