true, '_builtin' => false); $post_types=get_post_types($args, ''); foreach($post_types as $key=>$val) { add_meta_box( 'lacandsnw_meta_box', LAECHONW_WIDGET_NAME, 'lacandsnw_post_meta_box', $val->name, 'side', 'core', array($key) ); } } } function lacandsnw_post_meta_box($object, $box) { $options = get_option(LAECHONW_WIDGET_NAME_INTERNAL); $this_post_type = $object -> post_type; if(!$this_post_type) { $this_post_type = $box['args'][0]; } //HTML $html = ''; //Extension download //1 Click Publish $curr_val = get_post_meta( $object->ID, '_lacands_meta_show', true ); if($curr_val == '') { $curr_val = 1; } $html .= '
'; if($curr_val) { $html .= ''; } else { $html .= ''; } $html .= ' '; //Hidden $html .= ''; $html .= '
'; //Published State $lacandsnw_meta_published = get_post_meta($object->ID, '_lacandsnw_meta_published', true); if (in_array($lacandsnw_meta_published, array('done', 'failed'))) { $inputs_disabled = 'disabled="disabled"'; } else { $inputs_disabled = ''; } //Publish $curr_val_publish = get_post_meta($object->ID, '_lacandsnw_meta_publish', true); $curr_val_publish_out = $curr_val_publish; if ($curr_val_publish == '' or "$curr_val_publish" === '0') { $curr_val_publish_out = 1; } $html .= '
'; $html_label = ' '; $html_label_type_disabled = ' '; if ($curr_val_publish_out) { if (array_key_exists('lacandsnw_post_types', $options)) { if (in_array($this_post_type, explode(',', $options['lacandsnw_post_types']))) { $html .= ''; } else { $inputs_disabled = 'disabled="disabled"'; $html .= ''; $html_label = $html_label_type_disabled; } } else { if ("$curr_val_publish" === '0') { $html .= ''; } else { $html .= ''; } } } else { if (array_key_exists('lacandsnw_post_types', $options)) { if (in_array($this_post_type, explode(',', $options['lacandsnw_post_types']))) { $html .= ''; } else { $inputs_disabled = 'disabled="disabled"'; $html .= ''; $html_label = $html_label_type_disabled; } } else { $html .= ''; } } $html .= $html_label; $html .= '
'; //Message $curr_val_message = get_post_meta($object -> ID, 'lacandsnw_postmessage', true); $html .= '
'; $html .= '
'; $html .= ''; $html .= '
'; //Twitter handle $curr_val_twitterhandle = get_post_meta($object -> ID, 'lacandsnw_twitterhandle', true); $html .= '
'; $html .= '
'; $html .= ''; $html .= '
2 max, comma separated
'; $html .= '
'; //Twitter hash $curr_val_twitterhash = get_post_meta($object -> ID, 'lacandsnw_twitterhash', true); $html .= '
'; $html .= '
'; $html .= ''; $html .= '
2 max, comma separated
'; $html .= '
'; //Content $curr_val_content = get_post_meta($object -> ID, '_lacandsnw_meta_content', true); if ($curr_val_content == '') { $curr_val_content = 0; } if (in_array($lacandsnw_meta_published, array('failed', 'done'))) { $html .= '
'; } else { $html .= '
'; } if ($curr_val_content) { $html .= ''; } else { $html .= ''; } $html .= ' '; $html .= '
'; //Content Sent successfully if ($lacandsnw_meta_published == 'failed') { $html .= '
 ' . __('Post to social networks failed.') . '
'; } elseif ($lacandsnw_meta_published == 'done') { $html .= '
 
'; } //Manually post an update if(in_array($lacandsnw_meta_published, array('failed', 'done'))) { $html .= '
'; $post_data = lacandsnw_get_post_data_republish($object); $post_data_string = http_build_query($post_data); $html .= ''; $html .= ''; $html .= '
'; } //nonce $html .= ''; //Return echo $html; } function lacandsnw_save_post_meta_box($post_id, $post) { if(empty($_POST['lacandsnw_meta_nonce'])) { return $post_id; } if(!wp_verify_nonce($_POST['lacandsnw_meta_nonce'], plugin_basename( __FILE__ ))){ return $post_id; } if(!current_user_can('edit_post', $post_id)) { return $post_id; } //Show if(!empty($_POST['lacands_meta_cb_show'])) { $new_meta_value = 1; } else { $new_meta_value = 0; } update_post_meta( $post_id, '_lacands_meta_show', $new_meta_value ); //Postmessage - Facebook $new_meta_value_postmessage = ''; if (!empty($_POST['lacandsnw_postmessage'])) { if ($_POST['lacandsnw_postmessage']) { $new_meta_value_postmessage = strip_tags($_POST['lacandsnw_postmessage']); } } update_post_meta($post_id, 'lacandsnw_postmessage', $new_meta_value_postmessage); //Twitterhandle $new_meta_value_twitterhandle = ''; if (!empty($_POST['lacandsnw_twitterhandle'])) { if ($_POST['lacandsnw_twitterhandle']) { $new_meta_value_twitterhandle = strip_tags($_POST['lacandsnw_twitterhandle']); $new_meta_value_twitterhandle = str_replace("@", "", $new_meta_value_twitterhandle); } } update_post_meta($post_id, 'lacandsnw_twitterhandle', $new_meta_value_twitterhandle); //Twitterhash $new_meta_value_twitterhash = ''; if (!empty($_POST['lacandsnw_twitterhash'])) { if ($_POST['lacandsnw_twitterhash']) { $new_meta_value_twitterhash = strip_tags($_POST['lacandsnw_twitterhash']); $new_meta_value_twitterhash = str_replace("#", "", $new_meta_value_twitterhash); } } //Publish $new_meta_value_publish = 0; if (!empty($_POST['lacandsnw_meta_cb_publish'])) { if ($_POST['lacandsnw_meta_cb_publish']) { $new_meta_value_publish = 1; } } update_post_meta($post_id, '_lacandsnw_meta_publish', $new_meta_value_publish); //Content $new_meta_value_content = 0; if (!empty($_POST['lacandsnw_meta_cb_content'])) { if ($_POST['lacandsnw_meta_cb_content']) { $new_meta_value_content = 1; } } update_post_meta($post_id, '_lacandsnw_meta_content', $new_meta_value_content); } function lacandsnw_auth_errors() { //Get options $options = get_option(LAECHONW_WIDGET_NAME_INTERNAL); if(!is_array($options)) { return; } if(empty($options['lacandsnw_auth_error_show'])) { return; } $lacandsnw_auth_error_show = $options['lacandsnw_auth_error_show']; if(!$lacandsnw_auth_error_show) { return; } if (empty($options['api_key'])) { return; } $api_key = $options['api_key']; $link = 'http://www.linksalpha.com/a/networkpubautherrors'; $params = array('api_key'=>$api_key, 'plugin'=>LAECHONW_PLUGIN_NAME, 'plugin_version'=>lacandsnw_version(), ); $response_full = lacandsnw_http_post($link, $params); $response_code = $response_full[0]; if($response_code == 200) { return; } if($response_code == 401) { echo "
 ".LACANDSNW_WIDGET_NAME_POST_EDITOR.' - '.__("Authorization Error")."
".__("Authorization provided on one or more of your Network accounts has expired. Please")." ".__("add the related Account")." ".__("again to be able to publish content. To learn more, ")."".__("Click Here").". ".__("To access Settings page of the plugin, ")."".__("Click Here.")."
"; return; } return; } function lacandsnw_auth_error_show($lacandsnw_auth_error_show) { $options = get_option(LAECHONW_WIDGET_NAME_INTERNAL); $options['lacandsnw_auth_error_show'] = $lacandsnw_auth_error_show; update_option(LAECHONW_WIDGET_NAME_INTERNAL, $options); return; } function lacandsnw_mixed_mode() { $options = get_option(LAECHONW_WIDGET_NAME_INTERNAL); if(!is_array($options)) { return; } if(empty($options['lacandsnw_mixed_mode_alert_show'])) { return; } $lacandsnw_mixed_mode_alert_show = $options['lacandsnw_mixed_mode_alert_show']; if(!$lacandsnw_mixed_mode_alert_show) { return; } if (empty($options['id_2'])) { return; } $id = $options['id_2']; $link = 'http://www.linksalpha.com/a/networkpubmixedmode'; $params = array('id'=>$id, 'plugin'=>LAECHONW_PLUGIN_NAME, 'plugin_version'=>lacandsnw_version(), ); $response_full = lacandsnw_http_post($link, $params); $response_code = $response_full[0]; if($response_code == 200) { $response = lacandsnw_json_decode($response_full[1]); if ($response->errorCode > 0) { if($response->errorMessage == 'mixed mode') { echo "
 ".LACANDSNW_WIDGET_NAME_POST_EDITOR.' - '.__("Mixed Mode Alert")."
".__("Publishing of your website content via LinksAlpha Publisher seems to be configured using both the WordPress Plugin and RSS Feed of your website. LinksAlpha recommends use of plugin over RSS Feed. ")."".__("Click here")." ".__("to read the help document that will help resolve this Mixed Mode configuration issue.")."
"; } } } } function lacandsnw_mixed_mode_alert_show($lacandsnw_mixed_mode_alert_show) { $options = get_option(LAECHONW_WIDGET_NAME_INTERNAL); $options['lacandsnw_mixed_mode_alert_show'] = $lacandsnw_mixed_mode_alert_show; update_option(LAECHONW_WIDGET_NAME_INTERNAL, $options); return; } function lacandsnw_install_extension_alert_show($lacandsnw_install_extension_alert_show) { $options = get_option(LAECHONW_WIDGET_NAME_INTERNAL); $options['lacandsnw_install_extension_alert_show'] = $lacandsnw_install_extension_alert_show; update_option(LAECHONW_WIDGET_NAME_INTERNAL, $options); return; } function lacandsnw_networkping($id) { if(!$id) { return FALSE; } $options = get_option(LAECHONW_WIDGET_NAME_INTERNAL); if(empty($options['lacandsnw_id']) or empty($options['api_key'])) { return; } $link = 'http://www.linksalpha.com/a/ping?id='.$options['lacandsnw_id']; $response_full = lacandsnw_http($link); return; } function lacandsnw_networkping_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 ) { lacandsnw_networkping($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_http_post($link, $params); $response_code = $response_full[0]; if ($response_code != 200) { return; } $response = lacandsnw_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'))) { return; } //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_message = get_post_meta($post_id, 'lacandsnw_postmessage', true); $post_twitterhandle = get_post_meta($post_id, 'lacandsnw_twitterhandle', true); $post_twitterhash = get_post_meta($post_id, 'lacandsnw_twitterhash', true); $lacandsnw_meta_publish = get_post_meta($post_id, '_lacandsnw_meta_publish', true); if ($lacandsnw_meta_publish == "") { } elseif ($lacandsnw_meta_publish == 0) { return; } $lacandsnw_meta_published = get_post_meta($post_id, '_lacandsnw_meta_published', true); if ($lacandsnw_meta_published == 'done') { return; } //Post meta - lacandsnw_meta_content $lacandsnw_meta_content = get_post_meta($post_id, '_lacandsnw_meta_content', true); //Post data: id, content and title $post_title = $post_data['post_title']; if ($lacandsnw_meta_content) { $post_content = $post_data['post_excerpt']; } else { $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, 'post_geotag' => $post_geotag, 'content_message' => $post_message, 'twitterhandle' => $post_twitterhandle, 'hashtag' => $post_twitterhash, '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, $post_content); if($post_image) { $params['post_image'] = $post_image; } //HTTP Call $response_full = lacandsnw_http_post($link,$params); $response_code = $response_full[0]; if ($response_code == 200) { update_post_meta($post_id, '_lacandsnw_meta_published', 'done'); return; } update_post_meta($post_id, '_lacandsnw_meta_published', 'failed'); 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 ) { lacandsnw_post($post->ID); 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, 'version'=>LACANDSNW_PLUGIN_VERSION, 'all_keys'=>$options['api_key'], 'id'=>$id); //HTTP Call $response_full = lacandsnw_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_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_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_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 .= ''; if ($i % 2) { $html .= ''; $html .= ''; $i++; } $html .= '
'.__('Network').''.__('Option').''.__('Results').''.__('Remove').'
'; } else { $html .= ''; } $html .= ''.$row->name.''; } else { $html .= ''; } $html .= ''.__('Options').''; } else { $html .= ''; } $html .= '' . __('Results') . ''; } else { $html .= ''; } $html .= ''.__('Remove').'
'; echo $html; return; } add_action('admin_head', 'lacandsnw_networkpub_remove_javascript'); function lacandsnw_networkpub_remove_javascript() { ?> $options['id_2'], 'key'=>$key_only); $response_full = lacandsnw_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_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_http($link) { if (!$link) { return array(500, 'invalid url'); } $headers = array( 'Agent' => LAECHONW_WIDGET_NAME.' - '.get_bloginfo('url') ); $response_full = wp_remote_get( $link, array( 'timeout'=>30, 'headers'=>$headers ) ); if( is_wp_error($response) ) { return array(500, $response->get_error_message()); } $response = $response_full['body']; return array(200, $response); } function lacandsnw_http_post($link, $body) { if (!$link) { return array(500, 'invalid url'); } $headers = array( 'Agent' => LAECHONW_WIDGET_NAME.' - '.get_bloginfo('url') ); $response_full = wp_remote_post($link, array( 'method'=>'POST', 'body'=>$body, 'headers'=>$headers, 'timeout'=>30) ); if( is_wp_error($response) ) { return array(500, $response->get_error_message()); } $response = $response_full['body']; return array(200, $response); } function lacandsnw_error_msgs($errMsg) { $arr_errCodes = explode(";", $errMsg); $errCodesCount = count($arr_errCodes); switch (trim($arr_errCodes[0])) { case 'internal error': $html = '
'.__('An unknown error occured. Please try again later. Else, open a ticket with').' '.__('LinksAlpha Help Desk').'
'; return $html; break; case 'invalid url': $html = '
 '.__('Your website URL is invalid').'
'.__('URL of your website is not valid and as a result LinksAlpha.com is not able to connect to it. You can try adding the website URL directly in the').' '.''.__('LinksAlpha Website Manager.').' '.__('If that also does not work, please open a ticket at').' '.''.__('LinksAlpha Help Desk.').'
'; return $html; break; case 'remote url error': $html = '
 '.__('Remote URL error').'
'.__('Your website is either loading extremely slowly or it is in maintenance mode. As a result LinksAlpha.com is not able to connect to it. You can try adding the website URL directly in the').' '.''.__('LinksAlpha Website Manager.').' '.__('If that also does not work, please open a ticket at').' '.''.__('LinksAlpha Help Desk.').'
'; return $html; break; case 'feed parsing error': $html = '
 '.__('RSS Feed parsing error').'
'.__('Your RSS feed has errors and as a result LinksAlpha.com is not able to connect to it. You can try validating your RSS feed using').' '.''.__('Feed Validator.').' '.__('If the RSS feed is indeed valid and you continue to face isses, please open a ticket at').' '.''.__('LinksAlpha Help Desk.').'
'; return $html; break; case 'feed not found': $html = '
 '.__('RSS Feed URL not found').'
'.__('Plugin was not able to find RSS feed URL for your website. Please ensure that under Settings').'->'.__('General').'->'.__('Blog address (URL)').' '.__('the URL is filled-in correctly').'
'.__('If you still face issues, please open a ticket at: ').'LinksAlpha.com '.__('Help Desk').'
'; return $html; break; case 'invalid key': $html = '
 '.__('Invalid Key').'
'.__('The').' '.''.__('User').' '.__('or').' '.__('Network').' '.__('API key that you entered is not valid. Please input a valid key and try again.').'
'.__('If you still face issues, please open a ticket at: ').'LinksAlpha.com '.__('Help Desk').'
'; return $html; break; case 'subscription upgrade required': $html = '
 '.__('Account Error').'
'.__('Please ').' '.''.__('Upgrade your Account').' '.__('to be able to Publish to more Networks. You can learn more about LinksAlpha Networks by').' '.__('clicking here').'
'.__('If you still face issues, please open a ticket at: ').'LinksAlpha.com '.__('Help Desk').'
'; return $html; break; case 'localhost url': $html = '
 '.__('Website/Blog inaccessible').'
'.__('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.').'
'.__('If you still face issues, please open a ticket at: ').'LinksAlpha.com '.__('Help Desk').'
'; return $html; break; case 'multiple accounts': $html = '
 Account Error
'.__('The key that you entered is for a LinksAlpha account that is different from the currently used account for this website. You can use API key from only one account on this website. Please input a valid User or Network API key and try again').'.
'.__('If you still face issues, please open a ticket at: ').'LinksAlpha.com '.__('Help Desk').'
'; return $html; break; case 'no networks': $html = '
 '.__('No Network Accounts Found').'
'.__('You should first authorize LinksAlpha to publish to your social network profiles').' '.__('Click Here').' '.__('to get started.').'
'.__('If you still face issues, please open a ticket at: ').'LinksAlpha.com '.__('Help Desk').'
'; return $html; break; default: $html = '
'.__('An unknown error occured. Please try again later. Else, open a ticket with').' '.__('LinksAlpha Help Desk').'
'; return $html; break; } } function lacandsnw_get_plugin_dir() { global $wp_version; if ( version_compare($wp_version, '2.8', '<') ) { $path = dirname(plugin_basename(__FILE__)); if ( $path == '.' ) $path = ''; $plugin_path = trailingslashit( plugins_url( $path ) ); } else { $plugin_path = trailingslashit( plugins_url( '', __FILE__) ); } return $plugin_path; } 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_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() { return; global $wp_version; 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(){ return; $html = '
 '.LACANDSNW_WIDGET_NAME_POSTBOX.'
'; $html .= '
'; $html .= '
'.__('Share this Plugin').'
'; echo $html; return; } function lacandsnw_thumbnail_link($post_id, $post_content) { $lacandsnw_thumbnail_size = 'full'; if (function_exists('get_post_thumbnail_id') and function_exists('wp_get_attachment_image_src')) { $src = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), $lacandsnw_thumbnail_size); if ($src) { $src = $src[0]; return $src; } } if (!$post_content) { return False; } if (class_exists("DOMDocument") and function_exists('simplexml_import_dom')) { libxml_use_internal_errors(true); $doc = new DOMDocument(); if (!($doc -> loadHTML($post_content))) { return False; } try { $xml = @simplexml_import_dom($doc); if ($xml) { $images = $xml -> xpath('//img'); if (!empty($images)) { return (string)$images[0]['src']; } } else { return False; } } catch (Exception $e) { return False; } } } function lacandsnw_get_posts() { if(!empty($_GET['linksalpha_request_type'])) { $args = array( 'numberposts' => 20, 'offset' => 0, 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => 'post', 'post_status' => 'publish' ); $posts_array = get_posts( $args ); $html = ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; echo $html; } return; } function lacandsnw_smart_truncate($string, $required_length) { $parts = preg_split('/([\s\n\r]+)/', $string, null, PREG_SPLIT_DELIM_CAPTURE); $parts_count = count($parts); $length = 0; $last_part = 0; for (; $last_part < $parts_count; ++$last_part) { $length += strlen($parts[$last_part]); if ($length > $required_length) { break; } } return implode(array_slice($parts, 0, $last_part)); } function lacandsnw_prepare_string($string, $string_length) { $final_string = ''; $utf8marker = chr(128); $count = 0; while (isset($string{$count})) { if ($string{$count} >= $utf8marker) { $parsechar = substr($string, $count, 2); $count += 2; } else { $parsechar = $string{$count}; $count++; } if ($count > $string_length) { return $final_string; } $final_string = $final_string . $parsechar; } return $final_string; } function lacandsnw_prepare_text($text) { $text = stripslashes($text); $text = strip_tags($text); $text = preg_replace("/\[.*?\]/", '', $text); $text = preg_replace('/([\n \t\r]+)/', ' ', $text); $text = preg_replace('/( +)/', ' ', $text); $text = preg_replace('/\s\s+/', ' ', $text); $text = lacandsnw_prepare_string($text, 310); $text = lacandsnw_smart_truncate($text, 300); $text = trim($text); $text = htmlspecialchars($text); return $text; } function lacandsnw_get_post_data_republish($p) { $post_data = array(); $post_data['page_url'] = get_permalink($p); if($p->post_title) { $post_data['page_title'] = lacandsnw_prepare_text($p->post_title); } if($p->post_content) { $post_data['page_text'] = lacandsnw_prepare_text($p->post_content); } $page_url_image = lacandsnw_thumbnail_link($p->ID, $p->post_content); if($page_url_image) { $post_data['page_url_image'] = $page_url_image; } return $post_data; } function lacandsnw_version() { return LACANDSNW_PLUGIN_VERSION; } ?>