diff -r 2f6f6f7551ca -r 32102edaa81b web/wp-content/plugins/network-publisher/networkpub.php --- a/web/wp-content/plugins/network-publisher/networkpub.php Thu Sep 16 15:45:36 2010 +0000 +++ b/web/wp-content/plugins/network-publisher/networkpub.php Mon Nov 19 18:26:13 2012 +0100 @@ -1,236 +1,2205 @@ -'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']; - require_once(ABSPATH.WPINC.'/class-snoopy.php'); - $snoop = new Snoopy; - $snoop->agent = WIDGET_NAME.' - '.get_option('siteurl'); - $response = ''; - if($snoop->fetchtext($link)){ - if (strpos($snoop->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 = '
'.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 .= '
'; - echo $html; -} - -function networkpub_add($api_key) { - if (!$api_key) { - return FALSE; - } - $url = get_option('siteurl'); - $desc = get_bloginfo('description'); - if (!$url) { - return FALSE; - } - $link = 'http://www.linksalpha.com/a/networkpubadd?url='.urlencode($url).'&key='.$api_key.'&desc='.urlencode($desc); - require_once(ABSPATH.WPINC.'/class-snoopy.php'); - $snoop = new Snoopy; - $snoop->agent = WIDGET_NAME.' - '.get_option('siteurl'); - $response = ''; - if($snoop->fetchtext($link)){ - if (strpos($snoop->response_code, '200')) { - $response_json = $snoop->results; - $response = networkpub_json_decode($response_json); - } - } - if (!$response) { - return FALSE; - } - if ($response->errorCode > 0) { - 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); - 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?key='.$options['api_key']; - require_once(ABSPATH.WPINC.'/class-snoopy.php'); - $snoop = new Snoopy; - $snoop->agent = WIDGET_NAME.' - '.get_option('siteurl'); - $response = ''; - if($snoop->fetchtext($link)){ - if (strpos($snoop->response_code, '200')) { - $response_json = $snoop->results; - $response = networkpub_json_decode($response_json); - } - } - if (!$response) { - $html = '
Error occured while trying to load the API Keys. Please try again later.
'; - return $html; - } - 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 .= ''; - 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; - } - $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.'Remove
'; - 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); - $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); - $link = 'http://www.linksalpha.com/a/networkpubremove?id='.$options['id'].'&key='.$key_only; - require_once(ABSPATH.WPINC.'/class-snoopy.php'); - $snoop = new Snoopy; - $snoop->agent = WIDGET_NAME.' - '.get_option('siteurl'); - $response = ''; - $snoop->fetchtext($link); - 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); - } -} - +more. Click here for instructions. Email us at post@linksalpha.com if you have any queries. + Version: 5.6 + Author: linksalpha + Author URI: http://www.linksalpha.com + */ + +/* + Copyright (C) 2012 LinksAlpha. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +define('NETWORKPUB_WP_PLUGIN_URL', networkpub_get_plugin_dir()); +define('NETWORKPUB_WIDGET_NAME', __("Network Publisher")); +define('NETWORKPUB_WIDGET_NAME_INTERNAL', 'networkpub'); +define('NETWORKPUB_WIDGET_NAME_INTERNAL_NW', 'nw'); +define('NETWORKPUB_PLUGIN_ADMIN_URL', admin_url() . 'plugins.php?page=' . NETWORKPUB_WIDGET_NAME_INTERNAL); +define('NETWORKPUB_WIDGET_NAME_POSTBOX', __("Postbox")); +define('NETWORKPUB_WIDGET_NAME_POSTBOX_INTERNAL', 'networkpubpostbox'); +define('NETWORKPUB_WIDGET_PREFIX', 'networkpub'); +define('NETWORKPUB', __('Automatically publish your blog posts to 20+ Social Networks including Facebook, Twitter, LinkedIn, Yahoo, Yammer, MySpace, Identi.ca')); +define('NETWORKPUB_ERROR_INTERNAL', 'internal error'); +define('NETWORKPUB_ERROR_INVALID_URL', 'invalid url'); +define('NETWORKPUB_ERROR_INVALID_KEY', 'invalid key'); +define('NETWORKPUB_CURRENTLY_PUBLISHING', __('You are currently Publishing your Blog to')); +define('NETWORKPUB_SOCIAL_NETWORKS', __('Social Networks')); +define('NETWORKPUB_SOCIAL_NETWORK', __('Social Network')); +define('NETWORKPUB_PLUGIN_VERSION', '5.6'); + +$networkpub_settings['api_key'] = array('label' => 'API Key:', 'type' => 'text', 'default' => ''); +$networkpub_settings['id'] = array('label' => 'id', 'type' => 'text', 'default' => ''); +$options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL); + +/** + * This is the intialization function + */ + +function networkpub_init() { + networkpub_options(); + //Following will run only if the user is admin of wordpress + if (is_admin()) { + //Enqueue css and js bundled with wordpress + wp_enqueue_style('thickbox'); + wp_enqueue_script('jquery'); + wp_enqueue_script('thickbox'); + //Register and enqueue css and js bundled with the plugin + wp_register_script('networkpublisherjs', NETWORKPUB_WP_PLUGIN_URL . 'networkpub.js'); + wp_enqueue_script('networkpublisherjs'); + wp_register_script('postmessagejs', NETWORKPUB_WP_PLUGIN_URL . 'jquery.ba-postmessage.min.js'); + wp_enqueue_script('postmessagejs'); + wp_register_style('networkpublishercss', NETWORKPUB_WP_PLUGIN_URL . 'networkpub.css'); + wp_enqueue_style('networkpublishercss'); + //Hook into admin menu and activation loop + add_action('admin_menu', 'networkpub_pages'); + add_action('activate_{$plugin}', 'networkpub_pushpresscheck'); + add_action("activated_plugin", "networkpub_pushpresscheck"); + //Deactivate loop + register_deactivation_hook(__FILE__, 'networkpub_deactivate'); + } +} + +add_action('init', 'networkpub_init'); +register_activation_hook(__FILE__, 'networkpub_activate'); +add_action('admin_notices', 'networkpub_warning'); +add_action('admin_notices', 'networkpub_auth_errors'); +add_action('init', 'networkpub_remove'); +add_action('init', 'networkpub_get_posts'); +add_action('xmlrpc_publish_post', 'networkpub_ping'); +add_action('{$new_status}_{$post->post_type}', 'networkpub_ping'); +add_action('publish_post', 'networkpub_ping'); +add_action('future_to_publish', 'networkpub_ping'); +add_action('transition_post_status', 'networkpub_ping_custom', 12, 3); +add_action('xmlrpc_publish_post', 'networkpub_post_xmlrpc', 12); +add_action('{$new_status}_{$post->post_type}', 'networkpub_post', 12); +add_action('publish_post', 'networkpub_post', 12); +add_action('future_to_publish', 'networkpub_post', 12); +add_action('transition_post_status', 'networkpub_post_custom', 12, 3); +add_action('{$new_status}_{$post->post_type}', 'networkpub_convert'); +add_action('publish_post', 'networkpub_convert'); +add_action('future_to_publish', 'networkpub_convert'); +add_action('admin_menu', 'networkpub_create_post_meta_box'); +add_action('save_post', 'networkpub_post_publish_status', 4, 2); +add_action('save_post', 'networkpub_save_post_meta_box', 5, 2); +add_action('wp_head', 'networkpub_add_metatags'); +add_filter('language_attributes', 'networkpub_html_schema'); + +function networkpub_options() { + $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL); + if (!array_key_exists('networkpub_auth_error_show', $options)) { + $options['networkpub_auth_error_show'] = 1; + } + if (!array_key_exists('networkpub_mixed_mode_alert_show', $options)) { + $options['networkpub_mixed_mode_alert_show'] = 1; + } + if (!array_key_exists('networkpub_metatags_facebook', $options)) { + $options['networkpub_metatags_facebook'] = 1; + } + if (!array_key_exists('networkpub_lang_facebook', $options)) { + $options['networkpub_lang_facebook'] = 'en_US'; + } + if (!array_key_exists('networkpub_facebook_page_type', $options)) { + $options['networkpub_facebook_page_type'] = 'article'; + } + if (!array_key_exists('networkpub_ogtype_facebook', $options)) { + $options['networkpub_ogtype_facebook'] = 'article'; + } + if (!array_key_exists('networkpub_facebook_app_id', $options)) { + $options['networkpub_facebook_app_id'] = ''; + } + if (!array_key_exists('networkpub_metatags_googleplus', $options)) { + $options['networkpub_metatags_googleplus'] = 'checked'; + } + if (!array_key_exists('networkpub_googleplus_page_type', $options)) { + $options['networkpub_googleplus_page_type'] = 'Article'; + } + if (!array_key_exists('networkpub_custom_field_image', $options)) { + $options['networkpub_custom_field_image'] = ''; + } + if (!array_key_exists('networkpub_post_types', $options)) { + $options['networkpub_post_types'] = 'post'; + } + if (!array_key_exists('networkpub_thumbnail_size', $options)) { + $options['networkpub_thumbnail_size'] = 'medium'; + } + if (!array_key_exists('networkpub_post_image_video', $options)) { + $options['networkpub_post_image_video'] = 'image'; + } + update_option(NETWORKPUB_WIDGET_NAME_INTERNAL, $options); +} + +function networkpub_actlinks($links) { + $settings_link = '' . __('Settings') . ''; + array_unshift($links, $settings_link); + return $links; +} +$plugin = plugin_basename(__FILE__); +add_filter("plugin_action_links_$plugin", 'networkpub_actlinks'); + +function networkpub_create_post_meta_box() { + add_meta_box( 'networkpub_meta_box', NETWORKPUB_WIDGET_NAME, 'networkpub_post_meta_box', 'post', 'side', 'core' ); + add_meta_box( 'networkpub_meta_box', NETWORKPUB_WIDGET_NAME, 'networkpub_post_meta_box', 'page', 'side', 'core' ); + add_meta_box( 'networkpub_meta_box', NETWORKPUB_WIDGET_NAME, 'networkpub_post_meta_box', 'link', 'side', 'core' ); + if(function_exists('get_post_types')) { + $args=array('public' => true, + '_builtin' => false); + $post_types=get_post_types($args, ''); + foreach($post_types as $key=>$val) { + add_meta_box( 'networkpub_meta_box', NETWORKPUB_WIDGET_NAME, 'networkpub_post_meta_box', $val->name, 'side', 'core', array($key) ); + } + } +} + +function networkpub_post_meta_box($object, $box) { + $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL); + //WordPress Post Type of post + $this_post_type = $object->post_type; + if(!$this_post_type) { + $this_post_type = $box['args'][0]; + } + //Published State + $networkpub_meta_published = get_post_meta($object->ID, '_networkpub_meta_published', true); + if (in_array($networkpub_meta_published, array('done', 'failed'))) { + $inputs_disabled = 'disabled="disabled"'; + } else { + $inputs_disabled = ''; + } + //HTML + $html = ''; + //Publish + $curr_val_publish = get_post_meta($object->ID, '_networkpub_meta_publish', true); + if ($curr_val_publish == '') { + $curr_val_publish = 1; + } + $html .= '
'; + $html_label = ' '; + $html_label_type_disabled = ' '; + if ($curr_val_publish) { + if (array_key_exists('networkpub_post_types', $options)) { + if (in_array($this_post_type, explode(',', $options['networkpub_post_types']))) { + $html .= ''; + } else { + $inputs_disabled = 'disabled="disabled"'; + $html .= ''; + $html_label = $html_label_type_disabled; + } + } else { + $html .= ''; + } + } else { + if (in_array($this_post_type, explode(',', $options['networkpub_post_types']))) { + $html .= ''; + } else { + $inputs_disabled = 'disabled="disabled"'; + $html .= ''; + $html_label = $html_label_type_disabled; + } + } + $html .= $html_label; + $html .= '
'; + //Message + $curr_val_message = get_post_meta($object->ID, 'networkpub_postmessage', true); + $html .= '
'; + $html .= '
'; + $html .= ''; + $html .= '
'; + //Twitter handle + $curr_val_twitterhandle = get_post_meta($object->ID, 'networkpub_twitterhandle', true); + $html .= '
'; + $html .= '
'; + $html .= ''; + $html .= '
2 max, comma separated
'; + $html .= '
'; + //Twitter hash + $curr_val_twitterhash = get_post_meta($object->ID, 'networkpub_twitterhash', true); + $html .= '
'; + $html .= '
'; + $html .= ''; + $html .= '
2 max, comma separated
'; + $html .= '
'; + //Facebook Page Type + $curr_val_ogtype_facebook = get_post_meta($object->ID, 'networkpub_ogtype_facebook', true); + $facebook_page_type = array('article' => __('Article'), 'blog' => __('Blog'), 'book' => __('Book'), 'profile' => __('External Profile'), 'video.movie' => __('Movie'), 'video.episode' => __('TV Episode'), 'video.tv_show' => __('TV Show'), 'video.other' => __('Video'), 'website' => __('Website')); + $facebook_page_type_options = ''; + foreach ($facebook_page_type as $key => $val) { + if ($curr_val_ogtype_facebook == $key) { + $facebook_page_type_options = $facebook_page_type_options . ''; + } else { + $facebook_page_type_options = $facebook_page_type_options . ''; + } + } + $html .= '
'; + $html .= '
'; + $html .= '
'; + $html .= '
'; + //Image/Video + $curr_val_post_image_video = get_post_meta($object->ID, 'networkpub_post_image_video', true); + if(!$curr_val_post_image_video) { + if (array_key_exists('networkpub_post_image_video', $options)) { + $curr_val_post_image_video = $options['networkpub_post_image_video']; + } + } + $post_image_video_type = array('image' => __('Image'), 'video' => __('Video')); + $post_image_video_options = ''; + foreach ($post_image_video_type as $key => $val) { + if ($curr_val_post_image_video == $key) { + $post_image_video_options = $post_image_video_options . ''; + } else { + $post_image_video_options = $post_image_video_options . ''; + } + } + $html .= '
'; + $html .= '
 (' .__('help') .'):
'; + $html .= '
'; + $html .= '
'; + //Content from Excerpt + $curr_val_content = get_post_meta($object->ID, '_networkpub_meta_content', true); + if ($curr_val_content == '') { + $curr_val_content = 0; + } + if (in_array($networkpub_meta_published, array('failed', 'done'))) { + $html .= '
'; + } else { + $html .= '
'; + } + $html .= ''; + $html .= '
'; + //Content Sent successfully + if ($networkpub_meta_published == 'failed') { + $html .= '
'; + $html .= ''; + $html .= '
'; + } elseif ($networkpub_meta_published == 'done') { + $html .= '
'; + $html .= ''; + $html .= '
'; + } + //nonce + $html .= ''; + //Return + echo $html; +} + +function networkpub_save_post_meta_box($post_id, $post) { + #Options + $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL); + if (empty($_POST['networkpub_meta_nonce'])) { + return $post_id; + } + #Nonce + if (!wp_verify_nonce($_POST['networkpub_meta_nonce'], plugin_basename(__FILE__))) { + return $post_id; + } + #User auth + if (!current_user_can('edit_post', $post_id)) { + return $post_id; + } + #Message + $new_meta_value_postmessage = ''; + if (!empty($_POST['networkpub_postmessage'])) { + if ($_POST['networkpub_postmessage']) { + $new_meta_value_postmessage = strip_tags($_POST['networkpub_postmessage']); + } + } + update_post_meta($post_id, 'networkpub_postmessage', $new_meta_value_postmessage); + #Twitter Handle + $new_meta_value_twitterhandle = ''; + if (!empty($_POST['networkpub_twitterhandle'])) { + if ($_POST['networkpub_twitterhandle']) { + $new_meta_value_twitterhandle = strip_tags($_POST['networkpub_twitterhandle']); + $new_meta_value_twitterhandle = str_replace("@", "", $new_meta_value_twitterhandle); + } + } + update_post_meta($post_id, 'networkpub_twitterhandle', $new_meta_value_twitterhandle); + #Twitter Hash + $new_meta_value_twitterhash = ''; + if (!empty($_POST['networkpub_twitterhash'])) { + if ($_POST['networkpub_twitterhash']) { + $new_meta_value_twitterhash = strip_tags($_POST['networkpub_twitterhash']); + $new_meta_value_twitterhash = str_replace("#", "", $new_meta_value_twitterhash); + } + } + update_post_meta($post_id, 'networkpub_twitterhash', $new_meta_value_twitterhash); + #Facebook Page Type + $new_meta_value_ogtypefacebook = ''; + if (!empty($_POST['networkpub_ogtype_facebook'])) { + if ($_POST['networkpub_ogtype_facebook']) { + $new_meta_value_ogtypefacebook = strip_tags($_POST['networkpub_ogtype_facebook']); + } + } + update_post_meta($post_id, 'networkpub_ogtype_facebook', $new_meta_value_ogtypefacebook); + #Image/Video + $new_meta_value_post_image_video = ''; + if (!empty($_POST['networkpub_post_image_video'])) { + if ($_POST['networkpub_post_image_video']) { + $new_meta_value_post_image_video = strip_tags($_POST['networkpub_post_image_video']); + } + } + update_post_meta($post_id, 'networkpub_post_image_video', $new_meta_value_post_image_video); + $options['networkpub_post_image_video'] = $new_meta_value_post_image_video; + #Content + $new_meta_value_content = 0; + if (!empty($_POST['networkpub_meta_cb_content'])) { + if ($_POST['networkpub_meta_cb_content']) { + $new_meta_value_content = 1; + } + } + update_post_meta($post_id, '_networkpub_meta_content', $new_meta_value_content); + #Update Options + update_option(NETWORKPUB_WIDGET_NAME_INTERNAL, $options); +} + +function networkpub_post_publish_status($post_id, $post) { + add_post_meta($post_id, '_networkpub_meta_published', 'new', true); +} + +function networkpub_warning() { + $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL); + if (empty($options['api_key'])) { + if (!isset($_POST['submit'])) { + echo ' +
+
' . NETWORKPUB_WIDGET_NAME . ' ' . __('plugin is almost ready.') . '
+
' . __('You must') . ' ' . __('enter API key') . ' ' . __(' on the settings page for plugin') . ' ' . NETWORKPUB_WIDGET_NAME . ' ' . __('for automatic posting of your blog articles to 20+ Social Networks including Twitter, Facebook Profile, Facebook Pages, LinkedIn, MySpace, Yammer, Yahoo, Identi.ca, and more to work') . '
+
'; + } + } +} + +function networkpub_auth_errors() { + //Get options + $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL); + if (!is_array($options)) { + return; + } + if (empty($options['networkpub_auth_error_show'])) { + return; + } + $networkpub_auth_error_show = $options['networkpub_auth_error_show']; + if (!$networkpub_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' => NETWORKPUB_WIDGET_NAME_INTERNAL_NW, 'plugin_version' => networkpub_version(), ); + $response_full = networkpub_http_post($link, $params); + $response_code = $response_full[0]; + if ($response_code == 200) { + return; + } + if ($response_code == 401) { + echo " +
+
+  " . __("Network Publisher 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 networkpub_mixed_mode() { + $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL); + if (!is_array($options)) { + return; + } + if (empty($options['networkpub_mixed_mode_alert_show'])) { + return; + } + $networkpub_mixed_mode_alert_show = $options['networkpub_mixed_mode_alert_show']; + if (!$networkpub_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' => NETWORKPUB_WIDGET_NAME_INTERNAL_NW, 'plugin_version' => networkpub_version(), ); + $response_full = networkpub_http_post($link, $params); + $response_code = $response_full[0]; + if ($response_code == 200) { + $response = networkpub_json_decode($response_full[1]); + if ($response -> errorCode > 0) { + if ($response -> errorMessage == 'mixed mode') { + echo " +
+
+  " . __("Network Publisher - Mixed Mode Alert") . " +
+
+ " . __("Publishing of your website content via LinksAlpha Network Publisher seems to be configured using both the Network Publisher Plugin and RSS Feed of your website. LinksAlpha recommends use of Network Publisher plugin over RSS Feed. ") . "" . __("Click here") . " " . __("to read the help document that will help resolve this Mixed Mode configuration issue.") . " +
+
+ "; + } + } + } +} + +function networkpub_disabled_check($networkpub_enable) { + $html = '
+
 ' . __('Alert - Publishing has been Disabled!') . '
+
' . __('You have disabled publishing of posts using Network Publisher. To Enable it again please check the ').''.__('Enable Publishing Checkbox.').'
+
' . __('If you still face issues, please open a ticket at: ') . '' . __('LinksAlpha.com Help Desk.') . '
+
'; + if ($networkpub_enable != 'checked') { + echo $html; + } +} + +function networkpub_ping($id) { + if (!$id) { + return; + } + $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL); + if (empty($options['id']) or empty($options['api_key'])) { + return; + } + $link = 'http://www.linksalpha.com/a/ping?id=' . $options['id']; + $response_full = networkpub_http($link); + return; +} + +function networkpub_ping_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_ping($post->ID, $post); + break; + } + } + } + return; +} + +function networkpub_convert($id) { + if (!$id) { + return; + } + $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL); + if (!empty($options['id_2'])) { + return; + } + if (empty($options['id']) or empty($options['api_key'])) { + return; + } + $link = 'http://www.linksalpha.com/a/networkpubconvert'; + $params = array('id' => $options['id'], 'api_key' => $options['api_key'], 'plugin' => NETWORKPUB_WIDGET_NAME_INTERNAL_NW, ); + //HTTP Call + $response_full = networkpub_http_post($link, $params); + $response_code = $response_full[0]; + if ($response_code != 200) { + return; + }$response = networkpub_json_decode($response_full[1]); + if ($response -> errorCode > 0) { + return; + } + $options['id_2'] = $response -> results; + //Save + update_option(NETWORKPUB_WIDGET_NAME_INTERNAL, $options); + return; +} + +function networkpub_post($post_id) { + $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL); + if (!is_array($options)) { + return; + } + if (array_key_exists('networkpub_enable', $options)) { + $networkpub_enable_value = $options['networkpub_enable']; + } else { + $networkpub_enable_value = 1; + } + if (!$networkpub_enable_value) { + return; + } + if (!$options['networkpub_post_types']) { + return; + } + $post_types_enabled = explode(',', $options['networkpub_post_types']); + $post_type = get_post_type($post_id); + if (!in_array($post_type, $post_types_enabled)) { + return; + } + //Network keys + 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, 'networkpub_postmessage', true); + $post_twitterhandle = get_post_meta($post_id, 'networkpub_twitterhandle', true); + $post_twitterhash = get_post_meta($post_id, 'networkpub_twitterhash', true); + $post_ogtypefacebook = get_post_meta($post_id, 'networkpub_ogtype_facebook', true); + $networkpub_meta_publish = get_post_meta($post_id, '_networkpub_meta_publish', true); + $networkpub_post_image_video = get_post_meta($post_id, 'networkpub_post_image_video', true); + if ($networkpub_meta_publish == "") { + } elseif ($networkpub_meta_publish == 0) { + return; + } + $networkpub_meta_published = get_post_meta($post_id, '_networkpub_meta_published', true); + if ($networkpub_meta_published == 'done') { + return; + } + //Post meta - networkpub_meta_content + $networkpub_meta_content = get_post_meta($post_id, '_networkpub_meta_content', true); + //Post data: id, content and title + $post_title = $post_data['post_title']; + if ($networkpub_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_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); + 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 = ''; + } + $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' => NETWORKPUB_WIDGET_NAME_INTERNAL_NW, + 'plugin_version' => networkpub_version(), + 'post_categories' => $post_categories, + 'post_tags' => $post_tags, + 'post_geotag' => $post_geotag, + 'twitterhandle' => $post_twitterhandle, + 'hashtag' => $post_twitterhash, + 'content_message' => $post_message, + 'post_image_video' => $networkpub_post_image_video, + ); + $post_image = networkpub_thumbnail_link($post_id, $post_data['post_content']); + if ($post_image) { + $params['post_image'] = $post_image; + } + $response_full = networkpub_http_post($link, $params); + $response_code = $response_full[0]; + if ($response_code == 200) { + update_post_meta($post_id, '_networkpub_meta_published', 'done'); + } else { + update_post_meta($post_id, '_networkpub_meta_published', 'failed'); + } + networkpub_video($post_id, $post_content); + return; +} + +function networkpub_post_xmlrpc($post_id) { + networkpub_post($post_id); + return; +} + +function networkpub_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); + break; + } + } + } + return; +} + +function networkpub_conf() { + $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL); + 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', NETWORKPUB_WIDGET_PREFIX, 'api_key'); + if (array_key_exists($field_name, $_POST)) { + $value = strip_tags(stripslashes($_POST[$field_name])); + if ($value) { + $networkadd = networkpub_add($value); + } + } else { + if ($_POST['networkpub_form_type'] == 'networkpub_enable') { + if (array_key_exists('networkpub_enable', $_POST)) { + $networkpub_enable = 1; + } else { + $networkpub_enable = 0; + } + networkpub_update_option('networkpub_enable', $networkpub_enable); + } elseif ($_POST['networkpub_form_type'] == 'networkpub_auth_error_show') { + if (array_key_exists('networkpub_auth_error_show', $_POST)) { + $networkpub_auth_error_show = 1; + } else { + $networkpub_auth_error_show = 0; + } + networkpub_update_option('networkpub_auth_error_show', $networkpub_auth_error_show); + } elseif ($_POST['networkpub_form_type'] == 'networkpub_mixed_mode_alert_show') { + if (array_key_exists('networkpub_mixed_mode_alert_show', $_POST)) { + $networkpub_mixed_mode_alert_show = 1; + } else { + $networkpub_mixed_mode_alert_show = 0; + } + networkpub_update_option('networkpub_mixed_mode_alert_show', $networkpub_mixed_mode_alert_show); + } elseif ($_POST['networkpub_form_type'] == 'networkpub_metatags_facebook') { + if (array_key_exists('networkpub_metatags_facebook', $_POST)) { + $networkpub_metatags_facebook = 1; + } else { + $networkpub_metatags_facebook = 0; + } + if (array_key_exists('networkpub_lang_facebook', $_POST)) { + $networkpub_lang_facebook = strip_tags($_POST['networkpub_lang_facebook']); + } else { + $networkpub_lang_facebook = 'en_US'; + } + if (array_key_exists('networkpub_facebook_page_type', $_POST)) { + $networkpub_facebook_page_type = strip_tags($_POST['networkpub_facebook_page_type']); + } else { + $networkpub_facebook_page_type = 'article'; + } + if (array_key_exists('networkpub_facebook_app_id', $_POST)) { + $networkpub_facebook_app_id = strip_tags($_POST['networkpub_facebook_app_id']); + } else { + $networkpub_facebook_app_id = ''; + } + networkpub_update_option('networkpub_metatags_facebook', $networkpub_metatags_facebook); + networkpub_update_option('networkpub_lang_facebook', $networkpub_lang_facebook); + networkpub_update_option('networkpub_facebook_page_type', $networkpub_facebook_page_type); + networkpub_update_option('networkpub_facebook_app_id', $networkpub_facebook_app_id); + } elseif ($_POST['networkpub_form_type'] == 'networkpub_metatags_googleplus') { + if (array_key_exists('networkpub_metatags_googleplus', $_POST)) { + $networkpub_metatags_googleplus = 'checked'; + } else { + $networkpub_metatags_googleplus = ''; + } + if (array_key_exists('networkpub_googleplus_page_type', $_POST)) { + $networkpub_googleplus_page_type = strip_tags($_POST['networkpub_googleplus_page_type']); + } else { + $networkpub_googleplus_page_type = 'Article'; + } + networkpub_update_option('networkpub_metatags_googleplus', $networkpub_metatags_googleplus); + networkpub_update_option('networkpub_googleplus_page_type', $networkpub_googleplus_page_type); + } elseif ($_POST['networkpub_form_type'] == 'networkpub_custom_field_image') { + if (array_key_exists('networkpub_custom_field_image', $_POST)) { + $networkpub_custom_field_image = strip_tags($_POST['networkpub_custom_field_image']); + } else { + $networkpub_custom_field_image = ''; + } + networkpub_update_option('networkpub_custom_field_image', $networkpub_custom_field_image); + if (array_key_exists('networkpub_custom_field_image', $_POST)) { + $networkpub_custom_field_image_url = strip_tags($_POST['networkpub_custom_field_image_url']); + } else { + $networkpub_custom_field_image_url = ''; + } + networkpub_update_option('networkpub_custom_field_image_url', $networkpub_custom_field_image_url); + } elseif ($_POST['networkpub_form_type'] == 'networkpub_post_types') { + if (array_key_exists('networkpub_post_types', $_POST)) { + $networkpub_post_types = array(); + foreach($_POST['networkpub_post_types'] as $value) { + $networkpub_post_types[] = strip_tags($value); + } + $networkpub_post_types = implode(',', $_POST['networkpub_post_types']); + } else { + $networkpub_post_types = ''; + } + networkpub_update_option('networkpub_post_types', $networkpub_post_types); + } elseif ($_POST['networkpub_form_type'] == 'networkpub_thumbnail_size') { + if (array_key_exists('networkpub_thumbnail_size', $_POST)) { + $networkpub_thumbnail_size = strip_tags($_POST['networkpub_thumbnail_size']); + } else { + $networkpub_thumbnail_size = 'medium'; + } + networkpub_update_option('networkpub_thumbnail_size', $networkpub_thumbnail_size); + } + } + } + if (!empty($_GET['linksalpha_request_type'])) { + if ($_GET['linksalpha_request_type'] == 'get_posts') { + networkpub_get_posts(); + } + return; + } + $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL); + if (is_array($options)) { + //Publishing Enable/Disable + if (array_key_exists('networkpub_enable', $options)) { + $networkpub_enable = $options['networkpub_enable']; + if ($networkpub_enable) { + $networkpub_enable = 'checked'; + } else { + $networkpub_enable = ''; + } + } else { + $networkpub_enable = 'checked'; + } + if (array_key_exists('networkpub_auth_error_show', $options)) { + $networkpub_auth_error_show = $options['networkpub_auth_error_show']; + if ($networkpub_auth_error_show) { + $networkpub_auth_error_show = 'checked'; + } else { + $networkpub_auth_error_show = ''; + } + } else { + $networkpub_auth_error_show = 'checked'; + } + if (array_key_exists('networkpub_mixed_mode_alert_show', $options)) { + $networkpub_mixed_mode_alert_show = $options['networkpub_mixed_mode_alert_show']; + if ($networkpub_mixed_mode_alert_show) { + $networkpub_mixed_mode_alert_show = 'checked'; + } else { + $networkpub_mixed_mode_alert_show = ''; + } + } else { + $networkpub_mixed_mode_alert_show = 'checked'; + } + if (array_key_exists('networkpub_metatags_facebook', $options)) { + $networkpub_metatags_facebook = $options['networkpub_metatags_facebook']; + if ($networkpub_metatags_facebook) { + $networkpub_metatags_facebook = 'checked'; + } else { + $networkpub_metatags_facebook = ''; + } + } else { + $networkpub_metatags_facebook = 'checked'; + } + if (array_key_exists('networkpub_lang_facebook', $options)) { + $networkpub_lang_facebook = $options['networkpub_lang_facebook']; + } else { + $networkpub_metatags_facebook = 'en_US'; + } + if (array_key_exists('networkpub_facebook_page_type', $options)) { + $networkpub_facebook_page_type = $options['networkpub_facebook_page_type']; + } else { + $networkpub_facebook_page_type = 'article'; + } + if (array_key_exists('networkpub_facebook_app_id', $options)) { + $networkpub_facebook_app_id = $options['networkpub_facebook_app_id']; + } else { + $networkpub_facebook_app_id = ''; + } + if (array_key_exists('networkpub_metatags_googleplus', $options)) { + $networkpub_metatags_googleplus = $options['networkpub_metatags_googleplus']; + if ($networkpub_metatags_googleplus) { + $networkpub_metatags_googleplus = 'checked'; + } else { + $networkpub_metatags_googleplus = ''; + } + } else { + $networkpub_metatags_googleplus = 'checked'; + } + if (array_key_exists('networkpub_googleplus_page_type', $options)) { + $networkpub_googleplus_page_type = $options['networkpub_googleplus_page_type']; + } else { + $networkpub_googleplus_page_type = 'Article'; + } + if (array_key_exists('networkpub_custom_field_image', $options)) { + $networkpub_custom_field_image = $options['networkpub_custom_field_image']; + } else { + $networkpub_custom_field_image = ''; + } + if (array_key_exists('networkpub_custom_field_image_url', $options)) { + $networkpub_custom_field_image_url = $options['networkpub_custom_field_image_url']; + } else { + $networkpub_custom_field_image_url = ''; + } + if (array_key_exists('networkpub_thumbnail_size', $options)) { + $networkpub_thumbnail_size = $options['networkpub_thumbnail_size']; + } else { + $networkpub_thumbnail_size = 'medium'; + } + } else { + $networkpub_enable = 'checked'; + $networkpub_auth_error_show = 'checked'; + $networkpub_mixed_mode_alert_show = 'checked'; + $networkpub_metatags_facebook = 'checked'; + $networkpub_lang_facebook = 'en_US'; + $networkpub_facebook_page_type = 'article'; + $networkpub_facebook_app_id = ''; + $networkpub_metatags_googleplus = 'checked'; + $networkpub_googleplus_page_type = 'Article'; + $networkpub_custom_field_image = ''; + $networkpub_custom_field_image_url = ''; + $networkpub_thumbnail_size = 'medium'; + } + $fb_langs = networkpub_fb_langs(); + $fb_langs_options = ''; + asort($fb_langs); + foreach ($fb_langs as $key => $val) { + if ($networkpub_lang_facebook == $key) { + $fb_langs_options = $fb_langs_options . ''; + } else { + $fb_langs_options = $fb_langs_options . ''; + } + } + $facebook_page_type = array('article' => __('Article'), 'blog' => __('Blog'), 'book' => __('Book'), 'profile' => __('External Profile'), 'video.movie' => __('Movie'), 'video.episode' => __('TV Episode'), 'video.tv_show' => __('TV Show'), 'video.other' => __('Video'), 'website' => __('Website')); + $facebook_page_type_options = ''; + foreach ($facebook_page_type as $key => $val) { + if ($networkpub_facebook_page_type == $key) { + $facebook_page_type_options = $facebook_page_type_options . ''; + } else { + $facebook_page_type_options = $facebook_page_type_options . ''; + } + } + $googleplus_page_type = array('Article' => __('Article'), 'Blog' => __('Blog'), 'Book' => __('Book'), 'Event' => __('Event'), 'LocalBusiness' => __('Local Business'), 'Organization' => __('Organization'), 'Person' => __('Person'), 'Product' => __('Product'), 'Review' => __('Review')); + $googleplus_page_type_options = ''; + foreach ($googleplus_page_type as $key => $val) { + if ($networkpub_googleplus_page_type == $key) { + $googleplus_page_type_options = $googleplus_page_type_options . ''; + } else { + $googleplus_page_type_options = $googleplus_page_type_options . ''; + } + } + $thumbnail_size_types = array('medium'=>'Medium', 'large'=>'Large'); + $thumbnail_size_options = ''; + foreach ($thumbnail_size_types as $key => $val) { + if ($networkpub_thumbnail_size == $key) { + $thumbnail_size_options = $thumbnail_size_options . ''; + } else { + $thumbnail_size_options = $thumbnail_size_options . ''; + } + } + networkpub_mixed_mode(); + networkpub_disabled_check($networkpub_enable); + $html = ' +
+
+

' . NETWORKPUB_WIDGET_NAME . '

+
+
+
+
+ + + + + +
+ ' . __('Postbox') . '  |  ' . __('Share') . ' + +
+ +
+
+
+
+
' . __('Network Publisher') . ' ' . __('makes it easy to Publish your Blog Posts to Social Networks. To configure:') . '
+
1. ' . __('Connect to your Social Networks at') . ' ' . __('LinksAlpha.com') . '
+
2. ' . __('Get your') . ' ' . __('User API Key') . ' ' . __('or') . ' ' . __('Network API Key') . ' ' . __('and enter it below.') . '
+
' . __('Once setup, your Blog posts content appears on the social networks as soon as you hit the Publish button.') . '
+ +
+
+ ' . __('Setup') . ' +
+
+
+
+
+ ' . __('API Key') . ''; + $curr_field = 'api_key'; + $field_name = sprintf('%s_%s', NETWORKPUB_WIDGET_PREFIX, $curr_field); + $html .= ' + + + + + + +
+ +
+
+ +
+
+
+
+ + + + + +
+ + +
+ +
+
+ + + + + +
+
+
 
+
+
+ ' . __('Currently Publishing') . ' +
+
' . networkpub_load() . '
+
+ + +
+
+ ' . __('Enable/Disable Publishing') . ' +
+
+
+
+
+ +
+
+ + +
+
+
+
+
' . __('Notes:') . '
+
    +
  1. ' . __('You should typically use this option when you are making mass updates to your posts to prevent them from getting published to the configured networks') . '
  2. +
  3. ' . __('Deactivating the plugin will not disable publishing. You need to use this checkbox to disable publishing') . '
  4. +
+
+
+
+
+
+
+ ' . __('Show/Hide Authorization Errors') . ' +
+
+
+
+
+ +
+
+ + +
+
+
+
+
+
+
+ ' . __('Show/Hide Mixed Mode Configuration Alert') . ' +
+
+
+
+
+ +
+
+ + +
+
+
+
+
+
+
+ ' . __('Facebook Open Graph Metatags and Locale') . ' +
+
+
+
+
+ +
+
+
+ +
+
+ +
+
+
+
+
+ +
+
+ +
+
+
+
+
+ +
+
+ +
+
+
+
+ + +
+
+
+
+
+
+
+ ' . __('Google Plus Metatags and Page Type') . ' +
+
+
+
+
+ +
+
+
+ +
+
+ +
+
+
+
+ + +
+
+
+
+
+
+
+ ' . __('Image Size') . ' +
+
+
+
+
+ +
+
+ +
+
+ ' . __('Above selected image size would be included as part of the posts published to Facebook, LinkedIn... The social networks would then use this image to generate a thumbnail.') . ' +
+
+ + +
+
+
+
+
+
+
+ ' . __('Image URL from Custom Field') . ' +
+
+
+
+
+ +
+
+ +
+
+
+ ' . __('If your posts store images in a custom field, input the name of the custom field here. Please note that the URL to prepend the image can be inserted in the textbox below. If this solution does not work for you, please contact') . ' ' . __('LinksAlpha Support.') . ' +
+
+
+ +
+
+ +
+
+
+ ' . __('If the image URL in your custom field does not have the domain URL prepended to it, please provide the domain URL here and the plugin will prepare the complete URL before sending the content to the respective Network.') . ' +
+
+ + +
+
+
+
+ +
+
+ ' . __('Post Types to Publish') . ' +
+
+
+
+
+ ' . __('Select the WordPress ') . '' . __('Post Types') . '' . __(' that you want to Publish to your Social Network profiles.') . ' + +
+
' . networkpub_post_types() . '
+
+ + +
+
+
+
+
+ +
+
+ ' . __('Note') . ' +
+
+ ' . __('If you decide to stop using this plugin permanently, please remove your blog URL from') . ' ' . __('LinksAlpha Website Manager') . '. ' . __('Otherwise, your blog posts may continue to get posted even after you remove this plugin.') . ' +
+
+
+
+
+
+
+ +
' . __('View Postbox') . '
+
+
+
+
' . __('Supported Networks') . '
+
+
+ ' . networkpub_supported_networks() . ' +
+
+
+
'; + echo $html; +} + +function networkpub_add($api_key) { + if (!$api_key) { + $errdesc = networkpub_error_msgs('invalid key'); + echo $errdesc; + return; + } + $url = get_bloginfo('url'); + if (!$url) { + $errdesc = networkpub_error_msgs('invalid url'); + echo $errdesc; + return; + } + $desc = get_bloginfo('description'); + $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL); + if (!empty($options['id'])) { + $id = $options['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 = networkpub_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' => NETWORKPUB_WIDGET_NAME_INTERNAL_NW, 'version' => NETWORKPUB_PLUGIN_VERSION, 'all_keys' => $options['api_key'], 'id' => $id); + $response_full = networkpub_http_post($link, $params); + $response_code = $response_full[0]; + if ($response_code != 200) { + $errdesc = networkpub_error_msgs($response_full[1]); + echo $errdesc; + return FALSE; + } + $response = networkpub_json_decode($response_full[1]); + if ($response->errorCode > 0) { + if(isset($response->errorDetail)) { + $errdesc = networkpub_error_msgs($response->errorMessage, $response->errorDetail); + } else { + $errdesc = networkpub_error_msgs($response->errorMessage); + } + echo $errdesc; + return FALSE; + } + $options['id_2'] = $response->results->id; + 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; + } + } + } + update_option(NETWORKPUB_WIDGET_NAME_INTERNAL, $options); + //Return + echo '
' . __('API Key has been added successfully.') . '
'; + return; +} +function networkpub_load() { + $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL); + if (empty($options['api_key'])) { + $html = '
' . __('You have not added an API Key') . '
'; + return $html; + } + $link = 'http://www.linksalpha.com/a/networkpubget'; + $body = array('key' => $options['api_key'], 'version' => 2); + $response_full = networkpub_http_post($link, $body); + $response_code = $response_full[0]; + if ($response_code != 200) { + $errdeschtml = networkpub_error_msgs('misc'); + return $errdeschtml; + } $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; + } + 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)) { + $option_api_key_array = array_diff($option_api_key_array, array($row)); + } + } + $api_key = implode(",", $option_api_key_array); + $options['api_key'] = $api_key; + update_option(NETWORKPUB_WIDGET_NAME_INTERNAL, $options); + } + if (!count($response -> results)) { + return '
' . __('You have not added an API Key') . '
'; + } + if (count($response -> results) == 1) { + $html = '
' . NETWORKPUB_CURRENTLY_PUBLISHING . ' ' . count($response -> results) . ' ' . NETWORKPUB_SOCIAL_NETWORK . '
'; + } else { + $html = '
' . NETWORKPUB_CURRENTLY_PUBLISHING . ' ' . count($response -> results) . ' ' . NETWORKPUB_SOCIAL_NETWORKS . '
'; + } + $html .= ''; + $i = 1; + foreach ($response->results as $row) { + if ($row -> auth_expired) { + $auth_error_class = 'class="networkpublisher_auth_error"'; + $auth_error_image = '' . __('Authorization provided to LinksAlpha.com on this account has expired. Please Add the Account again to be able to publish content') . ' '; + } else { + $auth_error_class = ''; + $auth_error_image = ''; + } + $html .= ''; + if ($i % 2) { + $html .= ''; + if ($i % 2) { + $html .= ''; + if ($i % 2) { + $html .= ''; + if ($i % 2) { + $html .= ''; + $html .= ''; + $i++; + } + $html .= '
' . __('Network Account') . '' . __('Options') . '' . __('Publish Results') . '' . __('Remove') . '
'; + } else { + $html .= ''; + } + $html .= $auth_error_image . '' . $row -> name . ''; + } else { + $html .= ''; + } + $html .= '' . __('Options') . ''; + } else { + $html .= ''; + } + $html .= '' . __('Publish Results') . ''; + } else { + $html .= ''; + } + $html .= '' . __('Remove') . '
'; + return $html; +} + +function networkpub_post_types() { + $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL); + if (empty($options['networkpub_post_types'])) { + $post_types_in_options = array(); + } else { + $post_types_in_options = explode(',', $options['networkpub_post_types']); + } + if (!function_exists('get_post_types')) { + return; + } + $html = ''; + $args = array('public' => true, '_builtin' => false); + $output = 'names'; + $operator = 'and'; + $post_types = get_post_types($args, $output, $operator); + array_unshift($post_types, 'post', 'page'); + foreach ($post_types as $post_type) { + $checked = ''; + if (in_array($post_type, $post_types_in_options)) { + $checked = 'checked'; + } + $html .= '
 
'; + } + return $html; +} + +function networkpub_remove() { + $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL); + if (!empty($_POST['networkpub_key'])) { + $key_full = strip_tags($_POST['networkpub_key']); + $key_only = substr($key_full, 4); + $link = 'http://www.linksalpha.com/a/networkpubremove'; + $body = array('id' => $options['id_2'], 'key' => $key_only); + $response_full = networkpub_http_post($link, $body); + $response_code = $response_full[0]; + if ($response_code != 200) { + $errdesc = networkpubnw_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); + if ($loc !== FALSE) { + unset($api_key_array[$loc]); + } + $api_key = implode(",", $api_key_array); + $options['api_key'] = $api_key; + update_option(NETWORKPUB_WIDGET_NAME_INTERNAL, $options); + echo $key_full; + return; + } +} + +function networkpub_update_option($option, $value) { + $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL); + $options[$option] = $value; + update_option(NETWORKPUB_WIDGET_NAME_INTERNAL, $options); + return; +} + +function networkpub_pages() { + if (function_exists('add_submenu_page')) { + $page = add_submenu_page('plugins.php', NETWORKPUB_WIDGET_NAME, NETWORKPUB_WIDGET_NAME, 'manage_options', NETWORKPUB_WIDGET_NAME_INTERNAL, 'networkpub_conf'); + if (is_admin()) { + $page = add_submenu_page('edit.php', NETWORKPUB_WIDGET_NAME_POSTBOX, NETWORKPUB_WIDGET_NAME_POSTBOX, 'manage_options', NETWORKPUB_WIDGET_NAME_POSTBOX_INTERNAL, 'networkpub_postbox'); + } + } +} + +function networkpub_postbox() { + $html = '

' . NETWORKPUB_WIDGET_NAME . ' - ' . NETWORKPUB_WIDGET_NAME_POSTBOX . '

'; + $html .= ''; + $html .= '
+
+ ' . __('Share this Plugin') . ' +
+
+
+ +
+
'; + echo $html; + return; +} + +function networkpub_supported_networks() { + $html = ''; + $response_full = networkpub_http('http://www.linksalpha.com/a/networkpubsupported'); + $response_code = $response_full[0]; + if ($response_code != 200) { + return $html; + } + $response = $response_full[1]; + $content = networkpub_json_decode($response); + if (!$content) { + return $html; + } + $html .= ''; + return $html; +} + +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 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' => NETWORKPUB_WIDGET_NAME . ' - ' . get_bloginfo('url')); + $response_full = $request -> request($link, array('method' => 'GET', 'headers' => $headers, 'timeout' => 60)); + if (isset($response_full -> errors)) { + return array(500, 'internal error'); + } + if (!is_array($response_full['response'])) { + 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 = NETWORKPUB_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 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' => NETWORKPUB_WIDGET_NAME . ' - ' . get_bloginfo('url')); + $response_full = $request -> request($link, array('method' => 'POST', 'body' => $body, 'headers' => $headers, 'timeout' => 60)); + if (isset($response_full -> errors)) { + return array(500, 'internal error'); + } + if (!is_array($response_full['response'])) { + 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); + } + + // If no WP_HTTP found, fall back on snoopy.php for making HTTP request + require_once (ABSPATH . WPINC . '/class-snoopy.php'); + $snoop = new Snoopy; + $snoop -> agent = NETWORKPUB_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 networkpub_error_msgs($errMsg, $errorDetail='') { + $arr_errCodes = explode(";", $errMsg); + $errCodesCount = count($arr_errCodes); + switch (trim($arr_errCodes[0])) { + case 'internal error' : + $html = '
+
 ' . __('Unknown Error') . '
+
' . __('There was an unknown error. Please try again') . '.
+
' . __('If you still face issues, please open a ticket at: ') . '' . __('LinksAlpha.com Help Desk') . '
+
'; + 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 = ' +
+
+  " . __("Network Publisher Authorization Error") . " +
+
+
' . __('If you still face issues, please open a ticket at: ') . 'LinksAlpha.com ' . __('Help Desk') . '
+
+
+ +
' . __('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, please open a ticket at: ') . 'LinksAlpha.com ' . __('Help Desk') . '
+
'; + 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 you still face issues, please open a ticket at: ') . 'LinksAlpha.com ' . __('Help Desk') . '
+
'; + 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, please open a ticket at: ') . 'LinksAlpha.com ' . __('Help Desk') . '
+
'; + return $html; + break; + case 'invalid key' : + $html = '
+
 Invalid Key
+
' . __('The key that you entered is incorrect. 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 'network key' : + $html = '
+
+  ' . __('Invalid Key') . ': ' . __('Please make sure you enter the ') . '' . __('User API key') . '' . __(', and not the key of a Network') . '. +
+
'; + return $html; + break; + case 'subscription upgrade required': + if($errorDetail) { + $html = '
+  ' . __('Upgrade account') . '. ' . $errorDetail . ' +
'; + return $html; + } else { + $html = '
+  ' . __('Upgrade account') . '. ' . __('Please') . ' ' . __('upgrade your subscription') . ' ' . __('to continue using current number of networks and websites') . '. +
'; + 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 = '
+
 ' . __('Not able to connect to') . ' ' . __('LinksAlpha.com') . '
+
+
' . __('Your website is not able to connect to LinksAlpha.com. This might be due to:') . '
+
+
    +
  • ' . __('An issue with your hosting company where they might be preventing HTTP calls to external sites.') . '
  • +
  • ' . __('A plugin you are using has overwritten the .htaccess preventing access to external websites') . '
  • +
+
+
' . __('As an alternative you can configure publishing as described in Method-2 of the -') . ' ' . __('Getting Started help document.') . '
+
+
'; + return $html; + break; + } +} + +function networkpub_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 networkpub_activate() { + $networkpub_eget = get_bloginfo('admin_email'); + $networkpub_uget = get_bloginfo('url'); + $networkpub_nget = get_bloginfo('name'); + $networkpub_dget = get_bloginfo('description'); + $networkpub_cget = get_bloginfo('charset'); + $networkpub_vget = get_bloginfo('version'); + $networkpub_lget = get_bloginfo('language'); + $link = 'http://www.linksalpha.com/a/bloginfo'; + $networkpub_bloginfo = array('email' => $networkpub_eget, 'url' => $networkpub_uget, 'name' => $networkpub_nget, 'desc' => $networkpub_dget, 'charset' => $networkpub_cget, 'version' => $networkpub_vget, 'lang' => $networkpub_lget, 'plugin' => NETWORKPUB_WIDGET_NAME_INTERNAL_NW); + networkpub_http_post($link, $networkpub_bloginfo); + $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL); + if (empty($options['id_2']) or empty($options['api_key'])) { + return; + } + $link = 'http://www.linksalpha.com/a/networkpubconvertdirect'; + $params = array('id' => $options['id_2'], 'key' => $options['api_key'], 'plugin' => NETWORKPUB_WIDGET_NAME_INTERNAL_NW, ); + $response_full = networkpub_http_post($link, $params); + $response_code = $response_full[0]; + return; +} + +function networkpub_deactivate() { + $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL); + if (empty($options['id_2']) or empty($options['api_key'])) { + return; + } + // Build Params + $link = 'http://www.linksalpha.com/a/networkpubconvertfeed'; + $params = array('id' => $options['id_2'], 'key' => $options['api_key'], ); + //HTTP Call + $response_full = networkpub_http_post($link, $params); + $response_code = $response_full[0]; + return; +} + +function networkpub_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(NETWORKPUB_WIDGET_NAME_INTERNAL); + if (array_key_exists('id', $options)) { + if (!empty($options['id_2'])) { + $link = 'http://www.linksalpha.com/a/pushpress'; + $body = array('id' => $options['id_2']); + $response_full = networkpub_http_post($link, $body); + $response_code = $response_full[0]; + } + } + } +} + +function networkpub_postbox_url() { + global $wp_version; + if (version_compare($wp_version, '3.0.0', '<')) { + $admin_url = site_url() . '/wp-admin/edit.php?page=' . NETWORKPUB_WIDGET_NAME_POSTBOX_INTERNAL; + } else { + $admin_url = site_url() . '/wp-admin/edit.php?page=' . NETWORKPUB_WIDGET_NAME_POSTBOX_INTERNAL; + } + return $admin_url; +} + +function networkpub_version() { + return NETWORKPUB_PLUGIN_VERSION; +} + +function networkpub_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 networkpub_fb_langs() { + $langs = array(); + $response_full = networkpub_http_post("http://www.facebook.com/translations/FacebookLocales.xml", array()); + $response_code = $response_full[0]; + if ($response_code == 200) { + preg_match_all('/\s*([^<]+)<\/englishName>\s*\s*\s*.+?([^<]+)<\/representation>/s', utf8_decode($response_full[1]), $langslist, PREG_PATTERN_ORDER); + foreach ($langslist[1] as $key => $val) { + $langs[$langslist[2][$key]] = $val; + } + } else { + $langs['default'] = "Default"; + } + return $langs; +} + +function networkpub_add_metatags() { + $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL); + if (!is_array($options)) { + return; + } + if (!array_key_exists('networkpub_metatags_facebook', $options)) { + return; + } + $networkpub_metatags_facebook = $options['networkpub_metatags_facebook']; + $networkpub_metatags_googleplus = $options['networkpub_metatags_googleplus']; + if (!$networkpub_metatags_facebook and !$networkpub_metatags_googleplus) { + return; + } + global $posts; + //Site name + $og_site_name = get_bloginfo('name'); + //Set defaults for video types + $og_video = ''; + $og_video_type = ''; + //Post or Page + if (is_single() || is_page()) { + //Post data + $post_data = get_post($posts[0]->ID, ARRAY_A); + //Title + $og_title = networkpub_prepare_text($post_data['post_title']); + //Link + $og_link = get_permalink($posts[0]->ID); + //Image or Video + $networkpub_post_image_video = get_post_meta($posts[0]->ID, 'networkpub_post_image_video', true); + if($networkpub_post_image_video == 'image') { + $og_link_image = networkpub_thumbnail_link($posts[0]->ID, $post_data['post_content']); + } else { + $og_link_image = get_post_meta($posts[0]->ID, 'networkpub_video_picture', true); + $og_video = get_post_meta($posts[0]->ID, 'networkpub_video_source', true); + $og_video_type = "application/x-shockwave-flash"; + } + //Content + if (!empty($post_data['post_excerpt'])) { + $og_desc = $post_data['post_excerpt']; + } else { + $og_desc = $post_data['post_content']; + } + $og_desc = networkpub_prepare_text($og_desc); + //Facebook Page Type + $post_ogtypefacebook = get_post_meta($posts[0]->ID, 'networkpub_ogtype_facebook', true); + if ($post_ogtypefacebook) { + $og_type = $post_ogtypefacebook; + } else { + if (!empty($options['networkpub_facebook_page_type'])) { + $og_type = $options['networkpub_facebook_page_type']; + } else { + $og_type = 'article'; + } + } + } else { + //Title + $og_title = networkpub_prepare_text($og_site_name); + //Link + $og_link = get_bloginfo('url'); + //Image Link + $og_link_image = ''; + //Desc + $og_desc = get_bloginfo('description'); + $og_desc = networkpub_prepare_text($og_desc); + //Type + $og_type = 'website'; + } + if (!empty($options['networkpub_lang_facebook'])) { + $og_locale = $options['networkpub_lang_facebook']; + } else { + $og_locale = 'en_US'; + } + if (!empty($options['networkpub_facebook_app_id'])) { + $og_fb_app_id = $options['networkpub_facebook_app_id']; + } else { + $og_fb_app_id = ''; + } + //Google Plus Page Type + if (!empty($options['networkpub_googleplus_page_type'])) { + $og_type_google = $options['networkpub_googleplus_page_type']; + } else { + $og_type_google = 'Article'; + } + if ($networkpub_metatags_facebook) { + networkpub_build_meta_facebook($og_site_name, $og_title, $og_link, $og_link_image, $og_desc, $og_type, $og_locale, $og_fb_app_id, $og_video, $og_video_type); + } + if ($networkpub_metatags_googleplus) { + networkpub_build_meta_googleplus($og_title, $og_link_image, $og_desc, $og_type_google); + } + return; +} + +function networkpub_build_meta_facebook($og_site_name, $og_title, $og_link, $og_link_image, $og_desc, $og_type, $og_locale, $og_fb_app_id, $og_video, $og_video_type) { + $opengraph_meta = ''; + if ($og_site_name) { + $opengraph_meta .= "\n"; + } + if ($og_title) { + $opengraph_meta .= "\n"; + } + if ($og_link) { + $opengraph_meta .= "\n"; + } + if ($og_link_image) { + $opengraph_meta .= "\n"; + } + if ($og_video) { + $opengraph_meta .= "\n"; + } + if ($og_video_type) { + $opengraph_meta .= "\n"; + } + if ($og_desc) { + $opengraph_meta .= "\n"; + } + if ($og_type) { + $opengraph_meta .= "\n"; + } + if ($og_locale) { + $opengraph_meta .= "\n"; + } + if ($og_fb_app_id) { + $opengraph_meta .= "\n"; + } + echo "\n" . $opengraph_meta . "\n\n"; +} + +function networkpub_build_meta_googleplus($og_title, $og_link_image, $og_desc, $og_type) { + $opengraph_meta = ''; + if ($og_title) { + $opengraph_meta = "\n"; + } + if ($og_link_image) { + $opengraph_meta .= "\n"; + } + if ($og_desc) { + $opengraph_meta .= "\n"; + } + if ($og_type) { + $opengraph_meta .= "\n"; + } + echo "\n" . $opengraph_meta . "\n\n"; +} + +function networkpub_html_schema($attr) { + $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL); + if (!is_array($options)) { + return; + } + if (!array_key_exists('networkpub_metatags_facebook', $options)) { + return; + } + $networkpub_metatags_facebook = $options['networkpub_metatags_facebook']; + $networkpub_metatags_googleplus = $options['networkpub_metatags_googleplus']; + if (!$networkpub_metatags_facebook and !$networkpub_metatags_googleplus) { + return; + } + if ($networkpub_metatags_facebook) { + $attr .= " xmlns:og=\"http://opengraphprotocol.org/schema/\""; + $attr .= " xmlns:fb=\"http://www.facebook.com/2008/fbml\""; + } + if ($networkpub_metatags_googleplus) { + $networkpub_googleplus_page_type = $options['networkpub_googleplus_page_type']; + $attr .= " itemscope itemtype=\"http://schema.org/" . $networkpub_googleplus_page_type . "\""; + } + return $attr; +} + +function networkpub_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 = networkpub_prepare_string($text, 310); + $text = networkpub_smart_truncate($text, 300); + $text = trim($text); + $text = htmlspecialchars($text); + return $text; +} + +function networkpub_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 networkpub_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 networkpub_startswith($haystack, $needle) { + $length = strlen($needle); + return (substr($haystack, 0, $length) === $needle); +} + +function networkpub_endswith($haystack, $needle) { + $length = strlen($needle); + if ($length == 0) { + return true; + } + return (substr($haystack, -$length) === $needle); +} + +function networkpub_thumbnail_link($post_id, $post_content) { + $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL); + if (is_array($options)) { + if ((!empty($options['networkpub_custom_field_image'])) && (!empty($options['networkpub_custom_field_image_url']))) { + $networkpub_custom_field_image = $options['networkpub_custom_field_image']; + $networkpub_custom_field_image_url = $options['networkpub_custom_field_image_url']; + $post_data_custom = get_post_custom($post_id, ARRAY_A); + if ((!empty($post_data_custom[$networkpub_custom_field_image]) ) ) { + $post_data_custom_image = $post_data_custom[$networkpub_custom_field_image][0]; + if ( ( !networkpub_endswith($networkpub_custom_field_image_url, "/") && !networkpub_startswith($post_data_custom_image, "/") ) ) { + return $networkpub_custom_field_image_url . '/' . $post_data_custom_image; + } elseif ( !networkpub_endswith($networkpub_custom_field_image_url, "/") && networkpub_startswith($post_data_custom_image, "/") ) { + return $networkpub_custom_field_image_url . $post_data_custom_image; + } elseif ( networkpub_endswith($networkpub_custom_field_image_url, "/") && !networkpub_startswith($post_data_custom_image, "/") ) { + return $networkpub_custom_field_image_url . $post_data_custom_image; + } elseif ( networkpub_endswith($networkpub_custom_field_image_url, "/") && networkpub_startswith($post_data_custom_image, "/") ){ + $networkpub_custom_field_image_url = rtrim($networkpub_custom_field_image_url, "/"); + return $networkpub_custom_field_image_url . $post_data_custom_image; + } + } + } elseif ((!empty($options['networkpub_custom_field_image'])) && (empty($options['networkpub_custom_field_image_url']))) { + $networkpub_custom_field_image = $options['networkpub_custom_field_image']; + $post_data_custom = get_post_custom($post_id, ARRAY_A); + if ((!empty($post_data_custom[$networkpub_custom_field_image]))) { + return $post_data_custom[$networkpub_custom_field_image][0]; + } + } + } + if (is_array($options)) { + if (!empty($options['networkpub_thumbnail_size'])) { + $networkpub_thumbnail_size = $options['networkpub_thumbnail_size']; + } + } + 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), $networkpub_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 $images[0]['src']; + } + } else { + return False; + } + } catch (Exception $e) { + return False; + } + } + return False; +} + +function networkpub_video($post_id, $post_content) { + if (!$post_content) { + return; + } + $link = 'http://www.linksalpha.com/a/networkpubvideoinfo'; + $params = array('post_content' => $post_content, + 'plugin' => NETWORKPUB_WIDGET_NAME_INTERNAL_NW, + 'plugin_version' => networkpub_version(), + ); + $response_full = networkpub_http_post($link, $params); + $response_code = $response_full[0]; + if ($response_code != 200) { + return; + } + $response = networkpub_json_decode($response_full[1]); + if ($response->errorCode > 0) { + return; + } + update_post_meta($post_id, 'networkpub_video_source', $response->results->source); + update_post_meta($post_id, 'networkpub_video_picture', $response->results->picture); + return; +} + +register_deactivation_hook(__FILE__, 'networkpub_deactivate'); ?> \ No newline at end of file