web/wp-content/plugins/network-publisher/networkpub.php
changeset 194 32102edaa81b
parent 170 8e3a5a6fc63e
child 204 09a1c134465b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
     1 <?php
     1 <?php
     2 /*
     2 /*
     3 Plugin Name: Network Publisher
     3  Plugin Name: Network Publisher
     4 Plugin URI: http://www.linksalpha.com/
     4  Plugin URI: http://wordpress.org/extend/plugins/network-publisher/
     5 Description: Automatically posts your Articles to Social Networks - Facebook, Twitter, and LinkedIn
     5  Description: Automatically publish your blog posts to multiple Social Networks including Twitter, Facebook Profile, Facebook Pages, LinkedIn, MySpace, Yammer, Yahoo, Identi.ca, and <a href="http://www.linksalpha.com/networks" target="_blank">more</a>. Click <a href="http://help.linksalpha.com/networks/getting-started">here</a> for instructions. Email us at post@linksalpha.com if you have any queries.
     6 Version: 1.0.4
     6  Version: 5.6
     7 Author: Vivek Puri
     7  Author: linksalpha
     8 Author URI: http://vivekpuri.com
     8  Author URI: http://www.linksalpha.com
     9 */
     9  */
    10 
    10 
    11 define('WIDGET_NAME', 'Network Publisher');
    11 /*
    12 define('WIDGET_NAME_INTERNAL', 'networkpub');
    12  Copyright (C) 2012 LinksAlpha.
    13 define('WIDGET_PREFIX', 'networkpub');
    13 
    14 define('NETWORKPUB', 'Automatically post your Articles to Social Networks - Facebook and Twitter');
    14  This program is free software; you can redistribute it and/or modify
    15 define('ERROR_INTERNAL', 'internal error');
    15  it under the terms of the GNU General Public License as published by
    16 define('ERROR_INVALID_URL', 'invalid url');
    16  the Free Software Foundation; either version 2 of the License, or
    17 define('ERROR_INVALID_KEY', 'invalid key');
    17  (at your option) any later version.
    18 if ( ! defined( 'WP_CONTENT_URL' ) )
    18 
    19       define( 'WP_CONTENT_URL', get_option( 'siteurl' ) . '/wp-content' );
    19  This program is distributed in the hope that it will be useful,
    20 if ( ! defined( 'WP_CONTENT_DIR' ) )
    20  but WITHOUT ANY WARRANTY; without even the implied warranty of
    21       define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
    21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    22 define('WP_PLUGIN_URL', WP_CONTENT_URL. '/plugins' );
    22  GNU General Public License for more details.
    23 
    23 
    24 $networkpub_settings['api_key'] = array('label'=>'API Key:', 'type'=>'text', 'default'=>'');
    24  You should have received a copy of the GNU General Public License
    25 $networkpub_settings['id'] = array('label'=>'id', 'type'=>'text', 'default'=>'');
    25  along with this program; if not, write to the Free Software
    26 $options = get_option(WIDGET_NAME_INTERNAL);
    26  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    27 
    27  */
       
    28 
       
    29 define('NETWORKPUB_WP_PLUGIN_URL',					networkpub_get_plugin_dir());
       
    30 define('NETWORKPUB_WIDGET_NAME', 					__("Network Publisher"));
       
    31 define('NETWORKPUB_WIDGET_NAME_INTERNAL', 			'networkpub');
       
    32 define('NETWORKPUB_WIDGET_NAME_INTERNAL_NW', 		'nw');
       
    33 define('NETWORKPUB_PLUGIN_ADMIN_URL', 				admin_url() . 'plugins.php?page=' . NETWORKPUB_WIDGET_NAME_INTERNAL);
       
    34 define('NETWORKPUB_WIDGET_NAME_POSTBOX', 			__("Postbox"));
       
    35 define('NETWORKPUB_WIDGET_NAME_POSTBOX_INTERNAL', 	'networkpubpostbox');
       
    36 define('NETWORKPUB_WIDGET_PREFIX', 					'networkpub');
       
    37 define('NETWORKPUB', 								__('Automatically publish your blog posts to 20+ Social Networks including Facebook, Twitter, LinkedIn, Yahoo, Yammer, MySpace, Identi.ca'));
       
    38 define('NETWORKPUB_ERROR_INTERNAL', 				'internal error');
       
    39 define('NETWORKPUB_ERROR_INVALID_URL', 				'invalid url');
       
    40 define('NETWORKPUB_ERROR_INVALID_KEY', 				'invalid key');
       
    41 define('NETWORKPUB_CURRENTLY_PUBLISHING', 			__('You are currently Publishing your Blog to'));
       
    42 define('NETWORKPUB_SOCIAL_NETWORKS', 				__('Social Networks'));
       
    43 define('NETWORKPUB_SOCIAL_NETWORK', 				__('Social Network'));
       
    44 define('NETWORKPUB_PLUGIN_VERSION', 				'5.6');
       
    45 
       
    46 $networkpub_settings['api_key'] = array('label' => 'API Key:', 'type' => 'text', 'default' => '');
       
    47 $networkpub_settings['id'] = array('label' => 'id', 'type' => 'text', 'default' => '');
       
    48 $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
       
    49 
       
    50 /**
       
    51  * This is the intialization function
       
    52  */
       
    53   
    28 function networkpub_init() {
    54 function networkpub_init() {
    29 	wp_enqueue_script('jquery');
    55 	networkpub_options();
    30 	wp_register_script('networkpubjs', WP_PLUGIN_URL .'/network-publisher/networkpub.js');
    56 	//Following will run only if the user is admin of wordpress
    31 	wp_enqueue_script('networkpubjs');
    57 	if (is_admin()) {
    32 	wp_register_style('networkpubcss', WP_PLUGIN_URL . '/network-publisher/networkpub.css');
    58 		//Enqueue css and js bundled with wordpress
    33 	wp_enqueue_style('networkpubcss');
    59 		wp_enqueue_style('thickbox');
    34 	add_action('admin_menu', 'networkpub_pages');	
    60 		wp_enqueue_script('jquery');
    35 	add_action('{$new_status}_{$post->post_type}', 'networkping');
    61 		wp_enqueue_script('thickbox');
    36 	add_action('publish_post', 'networkping');
    62 		//Register and enqueue css and js bundled with the plugin
       
    63 		wp_register_script('networkpublisherjs', NETWORKPUB_WP_PLUGIN_URL . 'networkpub.js');
       
    64 		wp_enqueue_script('networkpublisherjs');
       
    65 		wp_register_script('postmessagejs', NETWORKPUB_WP_PLUGIN_URL . 'jquery.ba-postmessage.min.js');
       
    66 		wp_enqueue_script('postmessagejs');
       
    67 		wp_register_style('networkpublishercss', NETWORKPUB_WP_PLUGIN_URL . 'networkpub.css');
       
    68 		wp_enqueue_style('networkpublishercss');
       
    69 		//Hook into admin menu and activation loop
       
    70 		add_action('admin_menu', 'networkpub_pages');
       
    71 		add_action('activate_{$plugin}', 'networkpub_pushpresscheck');
       
    72 		add_action("activated_plugin", "networkpub_pushpresscheck");
       
    73 		//Deactivate loop
       
    74 		register_deactivation_hook(__FILE__, 'networkpub_deactivate');
       
    75 	}
    37 }
    76 }
    38 
    77 
    39 add_action('init', 'networkpub_init');
    78 add_action('init', 'networkpub_init');
       
    79 register_activation_hook(__FILE__, 'networkpub_activate');
       
    80 add_action('admin_notices', 'networkpub_warning');
       
    81 add_action('admin_notices', 'networkpub_auth_errors');
    40 add_action('init', 'networkpub_remove');
    82 add_action('init', 'networkpub_remove');
    41 
    83 add_action('init', 'networkpub_get_posts');
    42 function networkping($id) {
    84 add_action('xmlrpc_publish_post', 'networkpub_ping');
    43 	if(!$id) {
    85 add_action('{$new_status}_{$post->post_type}', 'networkpub_ping');
    44 		return FALSE;
    86 add_action('publish_post', 'networkpub_ping');
    45 	}
    87 add_action('future_to_publish', 'networkpub_ping');
    46 	$options = get_option(WIDGET_NAME_INTERNAL);
    88 add_action('transition_post_status', 'networkpub_ping_custom', 12, 3);
    47 	$link = 'http://www.linksalpha.com/a/ping?id='.$options['id'];
    89 add_action('xmlrpc_publish_post', 'networkpub_post_xmlrpc', 12);
    48 	require_once(ABSPATH.WPINC.'/class-snoopy.php');
    90 add_action('{$new_status}_{$post->post_type}', 'networkpub_post', 12);
    49 	$snoop = new Snoopy;
    91 add_action('publish_post', 'networkpub_post', 12);
    50 	$snoop->agent = WIDGET_NAME.' - '.get_option('siteurl');
    92 add_action('future_to_publish', 'networkpub_post', 12);
    51 	$response = '';
    93 add_action('transition_post_status', 'networkpub_post_custom', 12, 3);
    52 	if($snoop->fetchtext($link)){
    94 add_action('{$new_status}_{$post->post_type}', 'networkpub_convert');
    53 		if (strpos($snoop->response_code, '200')) {
    95 add_action('publish_post', 'networkpub_convert');
    54 			return TRUE;
    96 add_action('future_to_publish', 'networkpub_convert');
    55 		} 
    97 add_action('admin_menu', 'networkpub_create_post_meta_box');
    56 	}
    98 add_action('save_post', 'networkpub_post_publish_status', 4, 2);
    57 	return FALSE;
    99 add_action('save_post', 'networkpub_save_post_meta_box', 5, 2);
    58 }
   100 add_action('wp_head', 'networkpub_add_metatags');
    59 
   101 add_filter('language_attributes', 'networkpub_html_schema');
    60 function networkpub_pages() {
   102 
    61 	if ( function_exists('add_submenu_page') ) {
   103 function networkpub_options() {
    62 		$page = add_submenu_page('plugins.php', WIDGET_NAME, WIDGET_NAME, 'manage_options', 'networkpub', 'networkpub_conf');
   104 	$options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
    63 	}
   105 	if (!array_key_exists('networkpub_auth_error_show', $options)) {
       
   106 		$options['networkpub_auth_error_show'] = 1;
       
   107 	}
       
   108 	if (!array_key_exists('networkpub_mixed_mode_alert_show', $options)) {
       
   109 		$options['networkpub_mixed_mode_alert_show'] = 1;
       
   110 	}
       
   111 	if (!array_key_exists('networkpub_metatags_facebook', $options)) {
       
   112 		$options['networkpub_metatags_facebook'] = 1;
       
   113 	}
       
   114 	if (!array_key_exists('networkpub_lang_facebook', $options)) {
       
   115 		$options['networkpub_lang_facebook'] = 'en_US';
       
   116 	}
       
   117 	if (!array_key_exists('networkpub_facebook_page_type', $options)) {
       
   118 		$options['networkpub_facebook_page_type'] = 'article';
       
   119 	}
       
   120 	if (!array_key_exists('networkpub_ogtype_facebook', $options)) {
       
   121 		$options['networkpub_ogtype_facebook'] = 'article';
       
   122 	}
       
   123 	if (!array_key_exists('networkpub_facebook_app_id', $options)) {
       
   124 		$options['networkpub_facebook_app_id'] = '';
       
   125 	}
       
   126 	if (!array_key_exists('networkpub_metatags_googleplus', $options)) {
       
   127 		$options['networkpub_metatags_googleplus'] = 'checked';
       
   128 	}
       
   129 	if (!array_key_exists('networkpub_googleplus_page_type', $options)) {
       
   130 		$options['networkpub_googleplus_page_type'] = 'Article';
       
   131 	}
       
   132 	if (!array_key_exists('networkpub_custom_field_image', $options)) {
       
   133 		$options['networkpub_custom_field_image'] = '';
       
   134 	}
       
   135 	if (!array_key_exists('networkpub_post_types', $options)) {
       
   136 		$options['networkpub_post_types'] = 'post';
       
   137 	}
       
   138 	if (!array_key_exists('networkpub_thumbnail_size', $options)) {
       
   139 		$options['networkpub_thumbnail_size'] = 'medium';
       
   140 	}
       
   141 	if (!array_key_exists('networkpub_post_image_video', $options)) {
       
   142 		$options['networkpub_post_image_video'] = 'image';
       
   143 	}
       
   144 	update_option(NETWORKPUB_WIDGET_NAME_INTERNAL, $options);
       
   145 }
       
   146 
       
   147 function networkpub_actlinks($links) {
       
   148 	$settings_link = '<a href="' . NETWORKPUB_PLUGIN_ADMIN_URL . '">' . __('Settings') . '</a>';
       
   149 	array_unshift($links, $settings_link);
       
   150 	return $links;
       
   151 }
       
   152 $plugin = plugin_basename(__FILE__);
       
   153 add_filter("plugin_action_links_$plugin", 'networkpub_actlinks');
       
   154 
       
   155 function networkpub_create_post_meta_box() {
       
   156 	add_meta_box( 'networkpub_meta_box', NETWORKPUB_WIDGET_NAME, 'networkpub_post_meta_box', 'post', 'side', 'core' );
       
   157     add_meta_box( 'networkpub_meta_box', NETWORKPUB_WIDGET_NAME, 'networkpub_post_meta_box', 'page', 'side', 'core' );
       
   158     add_meta_box( 'networkpub_meta_box', NETWORKPUB_WIDGET_NAME, 'networkpub_post_meta_box', 'link', 'side', 'core' );
       
   159     if(function_exists('get_post_types')) {
       
   160         $args=array('public'   => true,
       
   161                     '_builtin' => false);
       
   162         $post_types=get_post_types($args, '');
       
   163     foreach($post_types as $key=>$val) {
       
   164 	    add_meta_box( 'networkpub_meta_box', NETWORKPUB_WIDGET_NAME, 'networkpub_post_meta_box', $val->name, 'side', 'core', array($key) );
       
   165 	    }
       
   166 	 }
       
   167 }
       
   168 
       
   169 function networkpub_post_meta_box($object, $box) {
       
   170 	$options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
       
   171 	//WordPress Post Type of post
       
   172 	$this_post_type = $object->post_type;
       
   173 	if(!$this_post_type) {
       
   174 	     $this_post_type = $box['args'][0];
       
   175 	}
       
   176 	//Published State
       
   177 	$networkpub_meta_published = get_post_meta($object->ID, '_networkpub_meta_published', true);
       
   178 	if (in_array($networkpub_meta_published, array('done', 'failed'))) {
       
   179 		$inputs_disabled = 'disabled="disabled"';
       
   180 	} else {
       
   181 		$inputs_disabled = '';
       
   182 	}
       
   183 	//HTML
       
   184 	$html = '';
       
   185 	//Publish
       
   186 	$curr_val_publish = get_post_meta($object->ID, '_networkpub_meta_publish', true);
       
   187 	if ($curr_val_publish == '') {
       
   188 		$curr_val_publish = 1;
       
   189 	}
       
   190 	$html .= '<div class="misc-pub-section">';
       
   191 	$html_label = '&nbsp;<label for="networkpub_meta_cb_publish">' . __('Publish this') . ' <i>' . $this_post_type .'</i>'. __(' to') . ' <a href="' . NETWORKPUB_PLUGIN_ADMIN_URL . '">' . __('configured Networks') . '</a></label>';
       
   192 	$html_label_type_disabled = '&nbsp;<label for="networkpub_meta_cb_publish" style="background-color:yellow;">' . __('Publishing of') . ' <i>' . $this_post_type .'</i>'. ' <a href="http://codex.wordpress.org/Post_Types" target="_blank">' . __('Post Type') . '</a>' . __(' to') . ' <a href="' . NETWORKPUB_PLUGIN_ADMIN_URL . '">' . __('configured Networks') . '</a>' . ' ' . __('has been disabled. ') . '<a href="' . NETWORKPUB_PLUGIN_ADMIN_URL . '#setting_networkpub_post_types">' . __('Click Here') . '</a>' . __(' to enable again.') . '</label>';
       
   193 	if ($curr_val_publish) {
       
   194 		if (array_key_exists('networkpub_post_types', $options)) {
       
   195 			if (in_array($this_post_type, explode(',', $options['networkpub_post_types']))) {
       
   196 				$html .= '<input type="checkbox" name="networkpub_meta_cb_publish" id="networkpub_meta_cb_publish" checked ' . $inputs_disabled . ' />';
       
   197 			} else {
       
   198 				$inputs_disabled = 'disabled="disabled"';
       
   199 				$html .= '<input type="checkbox" name="networkpub_meta_cb_publish" id="networkpub_meta_cb_publish" ' . $inputs_disabled . ' />';
       
   200 				$html_label = $html_label_type_disabled;
       
   201 			}
       
   202 		} else {
       
   203 			$html .= '<input type="checkbox" name="networkpub_meta_cb_publish" id="networkpub_meta_cb_publish" checked ' . $inputs_disabled . ' />';
       
   204 		}
       
   205 	} else {
       
   206 		if (in_array($this_post_type, explode(',', $options['networkpub_post_types']))) {
       
   207 			$html .= '<input type="checkbox" name="networkpub_meta_cb_publish" id="networkpub_meta_cb_publish" ' . $inputs_disabled . ' />';
       
   208 		} else {
       
   209 			$inputs_disabled = 'disabled="disabled"';
       
   210 			$html .= '<input type="checkbox" name="networkpub_meta_cb_publish" id="networkpub_meta_cb_publish" ' . $inputs_disabled . ' />';
       
   211 			$html_label = $html_label_type_disabled;
       
   212 		}
       
   213 	}
       
   214 	$html .= $html_label;
       
   215 	$html .= '</div>';
       
   216 	//Message
       
   217 	$curr_val_message = get_post_meta($object->ID, 'networkpub_postmessage', true);
       
   218 	$html .= '<div class="misc-pub-section">';
       
   219 	$html .= '<div class="networkpublisher_post_meta_box_label_box"><label class="networkpublisher_post_meta_box_label" for="networkpub_postmessage"><a target="_blank" href="http://help.linksalpha.com/wordpress-plugin-network-publisher/message">'. __('Message').'</a>'.(' to be included in the post:') . '</label></div>';
       
   220 	$html .= '<textarea ' . $inputs_disabled . ' name="networkpub_postmessage" id="networkpub_postmessage">' . $curr_val_message . '</textarea>';
       
   221 	$html .= '</div>';
       
   222 	//Twitter handle
       
   223 	$curr_val_twitterhandle = get_post_meta($object->ID, 'networkpub_twitterhandle', true);
       
   224 	$html .= '<div class="misc-pub-section">';
       
   225 	$html .= '<div class="networkpublisher_post_meta_box_label_box"><label class="networkpublisher_post_meta_box_label" for="networkpub_twitterhandle">@<a target="_blank" href="http://help.linksalpha.com/wordpress-plugin-network-publisher/twitter-handle">' .__('Twitter handles').'</a>'.__(' to mention in the post:') . '</label></div>';
       
   226 	$html .= '<input ' . $inputs_disabled . ' type="text" name="networkpub_twitterhandle" id="networkpub_twitterhandle" value="'. $curr_val_twitterhandle .'" />';
       
   227 	$html .= '<div class="networkpublisher_post_meta_box_helper">2 max, comma separated</div>';
       
   228 	$html .= '</div>';
       
   229 	//Twitter hash
       
   230 	$curr_val_twitterhash = get_post_meta($object->ID, 'networkpub_twitterhash', true);
       
   231 	$html .= '<div class="misc-pub-section">';
       
   232 	$html .= '<div class="networkpublisher_post_meta_box_label_box"><label class="networkpublisher_post_meta_box_label" for="networkpub_twitterhash"><a target="_blank" href="http://help.linksalpha.com/wordpress-plugin-network-publisher/twitter-hashtag">' . __('Twitter hashtags').'</a>'.__(' to be included in the post:') . '</label></div>';
       
   233 	$html .= '<input ' . $inputs_disabled . ' type="text" name="networkpub_twitterhash" id="networkpub_twitterhash" value="'.$curr_val_twitterhash.'" />';
       
   234 	$html .= '<div class="networkpublisher_post_meta_box_helper">2 max, comma separated</div>';
       
   235 	$html .= '</div>';
       
   236 	//Facebook Page Type
       
   237 	$curr_val_ogtype_facebook = get_post_meta($object->ID, 'networkpub_ogtype_facebook', true);
       
   238 	$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'));
       
   239 	$facebook_page_type_options = '';
       
   240 	foreach ($facebook_page_type as $key => $val) {
       
   241 		if ($curr_val_ogtype_facebook == $key) {
       
   242 			$facebook_page_type_options = $facebook_page_type_options . '<option value="' . htmlentities($key) . '" selected>' . htmlentities($val) . '</option>';
       
   243 		} else {
       
   244 			$facebook_page_type_options = $facebook_page_type_options . '<option value="' . htmlentities($key) . '">' . htmlentities($val) . '</option>';
       
   245 		}
       
   246 	}
       
   247 	$html .= '<div class="misc-pub-section">';
       
   248 	$html .= '<div class="networkpublisher_post_meta_box_label_box"><label for="networkpub_ogtype_facebook">' . __('Page Type for Facebook metatags:') . '</label></div>';
       
   249 	$html .= '<div><select ' . $inputs_disabled . ' name="networkpub_ogtype_facebook" id="networkpub_ogtype_facebook">' . $facebook_page_type_options . '</select></div>';
       
   250 	$html .= '</div>';
       
   251 	//Image/Video
       
   252 	$curr_val_post_image_video = get_post_meta($object->ID, 'networkpub_post_image_video', true);
       
   253 	if(!$curr_val_post_image_video) {
       
   254 		if (array_key_exists('networkpub_post_image_video', $options)) {
       
   255 			$curr_val_post_image_video = $options['networkpub_post_image_video'];
       
   256 		}	
       
   257 	}
       
   258 	$post_image_video_type = array('image' => __('Image'), 'video' => __('Video'));
       
   259 	$post_image_video_options = '';
       
   260 	foreach ($post_image_video_type as $key => $val) {
       
   261 		if ($curr_val_post_image_video == $key) {
       
   262 			$post_image_video_options = $post_image_video_options . '<option value="' . htmlentities($key) . '" selected>' . htmlentities($val) . '</option>';
       
   263 		} else {
       
   264 			$post_image_video_options = $post_image_video_options . '<option value="' . htmlentities($key) . '">' . htmlentities($val) . '</option>';
       
   265 		}
       
   266 	}
       
   267 	$html .= '<div class="misc-pub-section">';
       
   268 	$html .= '<div class="networkpublisher_post_meta_box_label_box"><label for="networkpub_post_image_video">' . __('Attach Image or Video') . '</label>&nbsp;(<a target="_blank" href="http://help.linksalpha.com/networks/publish-option-image-or-video">' .__('help') .'</a>):</div>';
       
   269 	$html .= '<div><select ' . $inputs_disabled . ' name="networkpub_post_image_video" id="networkpub_post_image_video">' . $post_image_video_options . '</select></div>';
       
   270 	$html .= '</div>';
       
   271 	//Content from Excerpt
       
   272 	$curr_val_content = get_post_meta($object->ID, '_networkpub_meta_content', true);
       
   273 	if ($curr_val_content == '') {
       
   274 		$curr_val_content = 0;
       
   275 	}
       
   276 	if (in_array($networkpub_meta_published, array('failed', 'done'))) {
       
   277 		$html .= '<div class="misc-pub-section">';	
       
   278 	} else {
       
   279 		$html .= '<div class="misc-pub-section" style="border-bottom:0px;padding-bottom:0px;">';
       
   280 	}
       
   281 	$html .= '<div class="networkpublisher_post_meta_box">';
       
   282 	if ($curr_val_content) {
       
   283 		$html .= '<input type="checkbox" name="networkpub_meta_cb_content" id="networkpub_meta_cb_content" checked ' . $inputs_disabled . ' />';
       
   284 	} else {
       
   285 		$html .= '<input type="checkbox" name="networkpub_meta_cb_content" id="networkpub_meta_cb_content" ' . $inputs_disabled . ' />';
       
   286 	}
       
   287 	$html .= '&nbsp;<label for="networkpub_meta_cb_content">' . __('Use Excerpt for publishing to Networks') . '</label>';
       
   288 	$html .= '</div>';
       
   289 	$html .= '</div>';
       
   290 	//Content Sent successfully
       
   291     if ($networkpub_meta_published == 'failed') {
       
   292     	$html .= '<div class="misc-pub-section" style="border-bottom:0px;padding-bottom:0px;">';
       
   293 		$html .= '<div class="networkpublisher_post_meta_box" style="color:red;"><img src="' . NETWORKPUB_WP_PLUGIN_URL . 'alert.png" />&nbsp;' . __('Post to social networks failed.') . '</div>';
       
   294 		$html .= '</div>';
       
   295 	} elseif ($networkpub_meta_published == 'done') {
       
   296 		$html .= '<div class="misc-pub-section" style="border-bottom:0px;padding-bottom:0px;">';
       
   297 		$html .= '<div class="networkpublisher_post_meta_box" style="color:green;"><input type="checkbox" checked disabled="disabled" />&nbsp;<label for="networkpub_meta_cb_content">' . __('Data sent successfully.') . '</label></div>';
       
   298 		$html .= '</div>';
       
   299 	}
       
   300 	//nonce
       
   301 	$html .= '<input type="hidden" name="networkpub_meta_nonce" value="' . wp_create_nonce(plugin_basename(__FILE__)) . '" />';
       
   302 	//Return
       
   303 	echo $html;
       
   304 }
       
   305 
       
   306 function networkpub_save_post_meta_box($post_id, $post) {
       
   307 	#Options
       
   308 	$options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
       
   309 	if (empty($_POST['networkpub_meta_nonce'])) {
       
   310 		return $post_id;
       
   311 	}
       
   312 	#Nonce
       
   313 	if (!wp_verify_nonce($_POST['networkpub_meta_nonce'], plugin_basename(__FILE__))) {
       
   314 		return $post_id;
       
   315 	}
       
   316 	#User auth
       
   317 	if (!current_user_can('edit_post', $post_id)) {
       
   318 		return $post_id;
       
   319 	}
       
   320 	#Message
       
   321 	$new_meta_value_postmessage = '';
       
   322 	if (!empty($_POST['networkpub_postmessage'])) {
       
   323 		if ($_POST['networkpub_postmessage']) {
       
   324 			$new_meta_value_postmessage = strip_tags($_POST['networkpub_postmessage']);
       
   325 		}
       
   326 	}
       
   327 	update_post_meta($post_id, 'networkpub_postmessage', $new_meta_value_postmessage);
       
   328 	#Twitter Handle
       
   329 	$new_meta_value_twitterhandle = '';
       
   330 	if (!empty($_POST['networkpub_twitterhandle'])) {
       
   331 		if ($_POST['networkpub_twitterhandle']) {
       
   332 			$new_meta_value_twitterhandle = strip_tags($_POST['networkpub_twitterhandle']);
       
   333 			$new_meta_value_twitterhandle = str_replace("@", "", $new_meta_value_twitterhandle);
       
   334 		}
       
   335 	}
       
   336 	update_post_meta($post_id, 'networkpub_twitterhandle', $new_meta_value_twitterhandle);
       
   337 	#Twitter Hash
       
   338 	$new_meta_value_twitterhash = '';
       
   339 	if (!empty($_POST['networkpub_twitterhash'])) {
       
   340 		if ($_POST['networkpub_twitterhash']) {
       
   341 			$new_meta_value_twitterhash = strip_tags($_POST['networkpub_twitterhash']);
       
   342 			$new_meta_value_twitterhash = str_replace("#", "", $new_meta_value_twitterhash);
       
   343 		}
       
   344 	}
       
   345 	update_post_meta($post_id, 'networkpub_twitterhash', $new_meta_value_twitterhash);
       
   346 	#Facebook Page Type
       
   347 	$new_meta_value_ogtypefacebook = '';
       
   348 	if (!empty($_POST['networkpub_ogtype_facebook'])) {
       
   349 		if ($_POST['networkpub_ogtype_facebook']) {
       
   350 			$new_meta_value_ogtypefacebook = strip_tags($_POST['networkpub_ogtype_facebook']);
       
   351 		}
       
   352 	}
       
   353 	update_post_meta($post_id, 'networkpub_ogtype_facebook', $new_meta_value_ogtypefacebook);
       
   354 	#Image/Video
       
   355 	$new_meta_value_post_image_video = '';
       
   356 	if (!empty($_POST['networkpub_post_image_video'])) {
       
   357 		if ($_POST['networkpub_post_image_video']) {
       
   358 			$new_meta_value_post_image_video = strip_tags($_POST['networkpub_post_image_video']);
       
   359 		}
       
   360 	}
       
   361 	update_post_meta($post_id, 'networkpub_post_image_video', $new_meta_value_post_image_video);
       
   362 	$options['networkpub_post_image_video'] = $new_meta_value_post_image_video;
       
   363 	#Content
       
   364 	$new_meta_value_content = 0;
       
   365 	if (!empty($_POST['networkpub_meta_cb_content'])) {
       
   366 		if ($_POST['networkpub_meta_cb_content']) {
       
   367 			$new_meta_value_content = 1;
       
   368 		}
       
   369 	}
       
   370 	update_post_meta($post_id, '_networkpub_meta_content', $new_meta_value_content);
       
   371 	#Update Options
       
   372 	update_option(NETWORKPUB_WIDGET_NAME_INTERNAL, $options);
       
   373 }
       
   374 
       
   375 function networkpub_post_publish_status($post_id, $post) {
       
   376 	add_post_meta($post_id, '_networkpub_meta_published', 'new', true);
       
   377 }
       
   378 
       
   379 function networkpub_warning() {
       
   380 	$options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
       
   381 	if (empty($options['api_key'])) {
       
   382 		if (!isset($_POST['submit'])) {
       
   383 			echo '
       
   384 				<div class="updated fade" style="padding:10px;text-align:left">
       
   385 					<div style="font-weight:bold;"><a href="http://wordpress.org/extend/plugins/network-publisher/" target="_blank">' . NETWORKPUB_WIDGET_NAME . '</a> ' . __('plugin is almost ready.') . '</div>
       
   386 					<div>' . __('You must') . ' <a href="' . NETWORKPUB_PLUGIN_ADMIN_URL . '">' . __('enter API key') . '</a> ' . __(' 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') . '</div>
       
   387 				</div>';
       
   388 		}
       
   389 	}
       
   390 }
       
   391 
       
   392 function networkpub_auth_errors() {
       
   393 	//Get options
       
   394 	$options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
       
   395 	if (!is_array($options)) {
       
   396 		return;
       
   397 	}
       
   398 	if (empty($options['networkpub_auth_error_show'])) {
       
   399 		return;
       
   400 	}
       
   401 	$networkpub_auth_error_show = $options['networkpub_auth_error_show'];
       
   402 	if (!$networkpub_auth_error_show) {
       
   403 		return;
       
   404 	}
       
   405 	if (empty($options['api_key'])) {
       
   406 		return;
       
   407 	}
       
   408 	$api_key = $options['api_key'];
       
   409 	$link = 'http://www.linksalpha.com/a/networkpubautherrors';
       
   410 	$params = array('api_key' => $api_key, 'plugin' => NETWORKPUB_WIDGET_NAME_INTERNAL_NW, 'plugin_version' => networkpub_version(), );
       
   411 	$response_full = networkpub_http_post($link, $params);
       
   412 	$response_code = $response_full[0];
       
   413 	if ($response_code == 200) {
       
   414 		return;
       
   415 	}
       
   416 	if ($response_code == 401) {
       
   417 		echo "
       
   418 		<div class='updated fade' style='padding:10px;'>
       
   419 			<div style='color:red;font-weight:bold;'>
       
   420 				<img src='" . NETWORKPUB_WP_PLUGIN_URL . "alert.png' style='vertical-align:text-bottom;' />&nbsp;" . __("Network Publisher Authorization Error") . "
       
   421 			</div>
       
   422 			<div style='padding-top:0px;'>
       
   423 				" . __("Authorization provided on one or more of your Network accounts has expired. Please") . " <a target='_blank' href='http://www.linksalpha.com/networks'>" . __("add the related Account") . "</a> " . __("again to be able to publish content. To learn more, ") . "<a target='_blank' href='http://help.linksalpha.com/networks/authorization-error'>" . __("Click Here") . "</a>. " . __("To access Settings page of the plugin, ") . "<a href='plugins.php?page=networkpub'>" . __("Click Here.") . "</a>
       
   424 			</div>
       
   425 		</div>
       
   426 		";
       
   427 		return;
       
   428 	}
       
   429 	return;
       
   430 }
       
   431 
       
   432 function networkpub_mixed_mode() {
       
   433 	$options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
       
   434 	if (!is_array($options)) {
       
   435 		return;
       
   436 	}
       
   437 	if (empty($options['networkpub_mixed_mode_alert_show'])) {
       
   438 		return;
       
   439 	}
       
   440 	$networkpub_mixed_mode_alert_show = $options['networkpub_mixed_mode_alert_show'];
       
   441 	if (!$networkpub_mixed_mode_alert_show) {
       
   442 		return;
       
   443 	}
       
   444 	if (empty($options['id_2'])) {
       
   445 		return;
       
   446 	}
       
   447 	$id = $options['id_2'];
       
   448 	$link = 'http://www.linksalpha.com/a/networkpubmixedmode';
       
   449 	$params = array('id' => $id, 'plugin' => NETWORKPUB_WIDGET_NAME_INTERNAL_NW, 'plugin_version' => networkpub_version(), );
       
   450 	$response_full = networkpub_http_post($link, $params);
       
   451 	$response_code = $response_full[0];
       
   452 	if ($response_code == 200) {
       
   453 		$response = networkpub_json_decode($response_full[1]);
       
   454 		if ($response -> errorCode > 0) {
       
   455 			if ($response -> errorMessage == 'mixed mode') {
       
   456 				echo "
       
   457 				<div class='updated fade' style='padding:10px;'>
       
   458 					<div style='color:red;font-weight:bold;'>
       
   459 						<img src='" . NETWORKPUB_WP_PLUGIN_URL . "alert.png' style='vertical-align:text-bottom;' />&nbsp;" . __("Network Publisher - Mixed Mode Alert") . "
       
   460 					</div>
       
   461 					<div style='padding-top:0px;'>
       
   462 						" . __("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. ") . "<a target='_blank' href='http://help.linksalpha.com/wordpress-plugin-network-publisher/mixed-mode-alert'>" . __("Click here") . "</a> " . __("to read the help document that will help resolve this Mixed Mode configuration issue.") . "
       
   463 					</div>
       
   464 				</div>
       
   465 				";
       
   466 			}
       
   467 		}
       
   468 	}
       
   469 }
       
   470 
       
   471 function networkpub_disabled_check($networkpub_enable) {
       
   472 	$html = '<div class="networkpublisher_alert_disable_pub">
       
   473              	<div class="networkpublisher_alert_disable_pub_header"><b><img src="' . NETWORKPUB_WP_PLUGIN_URL . 'alert.png" style="vertical-align:text-bottom;" />&nbsp;' . __('Alert - Publishing has been Disabled!') . '</b></div>
       
   474                 <div>' . __('You have disabled publishing of posts using Network Publisher. To Enable it again please check the ').'<a href="' . NETWORKPUB_PLUGIN_ADMIN_URL . '#setting_networkpub_enable">'.__('Enable Publishing Checkbox.').'</a></div>
       
   475 				<div>' . __('If you still face issues, please open a ticket at: ') . '<a target="_blank" href="http://support.linksalpha.com/">' . __('LinksAlpha.com Help Desk.') . '</a></div>
       
   476 			</div>';
       
   477 	if ($networkpub_enable != 'checked') {
       
   478 		echo $html;
       
   479 	}
       
   480 }
       
   481 
       
   482 function networkpub_ping($id) {
       
   483 	if (!$id) {
       
   484 		return;
       
   485 	}
       
   486 	$options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
       
   487 	if (empty($options['id']) or empty($options['api_key'])) {
       
   488 		return;
       
   489 	}
       
   490 	$link = 'http://www.linksalpha.com/a/ping?id=' . $options['id'];
       
   491 	$response_full = networkpub_http($link);
       
   492 	return;
       
   493 }
       
   494 
       
   495 function networkpub_ping_custom($new, $old, $post) {
       
   496 	if ($new == 'publish' && $old != 'publish') {
       
   497 		$post_types = get_post_types(array('public' => true), 'objects');
       
   498 		foreach ($post_types as $post_type) {
       
   499 			if ($post -> post_type == $post_type -> name) {
       
   500 				networkpub_ping($post->ID, $post);
       
   501 				break;
       
   502 			}
       
   503 		}
       
   504 	}
       
   505 	return;
       
   506 }
       
   507 
       
   508 function networkpub_convert($id) {
       
   509 	if (!$id) {
       
   510 		return;
       
   511 	}
       
   512 	$options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
       
   513 	if (!empty($options['id_2'])) {
       
   514 		return;
       
   515 	}
       
   516 	if (empty($options['id']) or empty($options['api_key'])) {
       
   517 		return;
       
   518 	}
       
   519 	$link = 'http://www.linksalpha.com/a/networkpubconvert';
       
   520 	$params = array('id' => $options['id'], 'api_key' => $options['api_key'], 'plugin' => NETWORKPUB_WIDGET_NAME_INTERNAL_NW, );
       
   521 	//HTTP Call
       
   522 	$response_full = networkpub_http_post($link, $params);
       
   523 	$response_code = $response_full[0];
       
   524 	if ($response_code != 200) {
       
   525 		return;
       
   526 	}$response = networkpub_json_decode($response_full[1]);
       
   527 	if ($response -> errorCode > 0) {
       
   528 		return;
       
   529 	}
       
   530 	$options['id_2'] = $response -> results;
       
   531 	//Save
       
   532 	update_option(NETWORKPUB_WIDGET_NAME_INTERNAL, $options);
       
   533 	return;
       
   534 }
       
   535 
       
   536 function networkpub_post($post_id) {
       
   537 	$options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
       
   538 	if (!is_array($options)) {
       
   539 		return;
       
   540 	}
       
   541 	if (array_key_exists('networkpub_enable', $options)) {
       
   542 		$networkpub_enable_value = $options['networkpub_enable'];
       
   543 	} else {
       
   544 		$networkpub_enable_value = 1;
       
   545 	}
       
   546 	if (!$networkpub_enable_value) {
       
   547 		return;
       
   548 	}
       
   549 	if (!$options['networkpub_post_types']) {
       
   550 		return;
       
   551 	}
       
   552 	$post_types_enabled = explode(',', $options['networkpub_post_types']);
       
   553 	$post_type = get_post_type($post_id);
       
   554 	if (!in_array($post_type, $post_types_enabled)) {
       
   555 		return;
       
   556 	}
       
   557 	//Network keys
       
   558 	if (empty($options['api_key']) or empty($options['id_2'])) {
       
   559 		return;
       
   560 	}
       
   561 	$id = $options['id_2'];
       
   562 	$api_key = $options['api_key'];
       
   563 	//Post data
       
   564 	$post_data = get_post($post_id, ARRAY_A);
       
   565 	//Post Published?
       
   566 	if (!in_array($post_data['post_status'], array('future', 'publish'))) {
       
   567 		return;
       
   568 	}
       
   569 	//post too old?
       
   570 	$post_date = strtotime($post_data['post_date_gmt']);
       
   571 	$current_date = time();
       
   572 	$diff = $current_date - $post_date;
       
   573 	$days = floor($diff / (60 * 60 * 24));
       
   574 	if ($days > 3) {
       
   575 		return;
       
   576 	}
       
   577 	$post_message = get_post_meta($post_id, 'networkpub_postmessage', true);
       
   578 	$post_twitterhandle = get_post_meta($post_id, 'networkpub_twitterhandle', true);
       
   579 	$post_twitterhash = get_post_meta($post_id, 'networkpub_twitterhash', true);
       
   580 	$post_ogtypefacebook = get_post_meta($post_id, 'networkpub_ogtype_facebook', true);
       
   581 	$networkpub_meta_publish = get_post_meta($post_id, '_networkpub_meta_publish', true);
       
   582 	$networkpub_post_image_video = get_post_meta($post_id, 'networkpub_post_image_video', true);
       
   583 	if ($networkpub_meta_publish == "") {
       
   584 	} elseif ($networkpub_meta_publish == 0) {
       
   585 		return;
       
   586 	}
       
   587 	$networkpub_meta_published = get_post_meta($post_id, '_networkpub_meta_published', true);
       
   588 	if ($networkpub_meta_published == 'done') {
       
   589 		return;
       
   590 	}
       
   591 	//Post meta - networkpub_meta_content
       
   592 	$networkpub_meta_content = get_post_meta($post_id, '_networkpub_meta_content', true);
       
   593 	//Post data: id, content and title
       
   594 	$post_title = $post_data['post_title'];
       
   595 	if ($networkpub_meta_content) {
       
   596 		$post_content = $post_data['post_excerpt'];
       
   597 	} else {
       
   598 		$post_content = $post_data['post_content'];
       
   599 	}
       
   600 	//Post data: Permalink
       
   601 	$post_link = get_permalink($post_id);
       
   602 	//Post data: Categories
       
   603 	$post_categories_array = array();
       
   604 	$post_categories_data = get_the_category($post_id);
       
   605 	foreach ($post_categories_data as $category) {
       
   606 		$post_categories_array[] = $category -> cat_name;
       
   607 	}
       
   608 	$post_categories = implode(",", $post_categories_array);
       
   609 	$post_tags_array = array();
       
   610 	$post_tags_data = wp_get_post_tags($post_id);
       
   611 	foreach ($post_tags_data as $tag) {
       
   612 		$post_tags_array[] = $tag -> name;
       
   613 	}
       
   614 	$post_tags = implode(",", $post_tags_array);
       
   615 	if (function_exists('get_wpgeo_latitude')) {
       
   616 		if (get_wpgeo_latitude($post_id) and get_wpgeo_longitude($post_id)) {
       
   617 			$post_geotag = get_wpgeo_latitude($post_id) . ' ' . get_wpgeo_longitude($post_id);
       
   618 		}
       
   619 	}
       
   620 	if (!isset($post_geotag)) {
       
   621 		$post_geotag = '';
       
   622 	}
       
   623 	$link = 'http://www.linksalpha.com/a/networkpubpost';
       
   624 	$params = array('id' => $id,
       
   625 					'api_key' => $api_key,
       
   626 					'post_id' => $post_id,
       
   627 					'post_link' => $post_link,
       
   628 					'post_title' => $post_title,
       
   629 					'post_content' => $post_content,
       
   630 					'plugin' => NETWORKPUB_WIDGET_NAME_INTERNAL_NW,
       
   631 					'plugin_version' => networkpub_version(),
       
   632 					'post_categories' => $post_categories,
       
   633 					'post_tags' => $post_tags,
       
   634 					'post_geotag' => $post_geotag,
       
   635 					'twitterhandle' => $post_twitterhandle,
       
   636 					'hashtag' => $post_twitterhash,
       
   637 					'content_message' => $post_message,
       
   638 					'post_image_video' => $networkpub_post_image_video,
       
   639 				);
       
   640 	$post_image = networkpub_thumbnail_link($post_id, $post_data['post_content']);
       
   641 	if ($post_image) {
       
   642 		$params['post_image'] = $post_image;
       
   643 	}
       
   644 	$response_full = networkpub_http_post($link, $params);
       
   645 	$response_code = $response_full[0];
       
   646 	if ($response_code == 200) {
       
   647 		update_post_meta($post_id, '_networkpub_meta_published', 'done');
       
   648 	} else {
       
   649 		update_post_meta($post_id, '_networkpub_meta_published', 'failed');	
       
   650 	}
       
   651 	networkpub_video($post_id, $post_content);
       
   652 	return;
       
   653 }
       
   654 
       
   655 function networkpub_post_xmlrpc($post_id) {
       
   656 	networkpub_post($post_id);
       
   657 	return;
       
   658 }
       
   659 
       
   660 function networkpub_post_custom($new, $old, $post) {
       
   661 	if ($new == 'publish' && $old != 'publish') {
       
   662 		$post_types = get_post_types(array('public' => true), 'objects');
       
   663 		foreach ($post_types as $post_type) {
       
   664 			if ($post -> post_type == $post_type -> name) {
       
   665 				networkpub_post($post->ID);
       
   666 				break;
       
   667 			}
       
   668 		}
       
   669 	}
       
   670 	return;
    64 }
   671 }
    65 
   672 
    66 function networkpub_conf() {
   673 function networkpub_conf() {
       
   674 	$options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
    67 	global $networkpub_settings;
   675 	global $networkpub_settings;
    68 	
   676 	if (isset($_POST['submit'])) {
    69 	if ( isset($_POST['submit']) ) {
   677 		if (function_exists('current_user_can') && !current_user_can('manage_options')) {
    70 		if ( function_exists('current_user_can') && !current_user_can('manage_options') ) {
       
    71 			die(__('Cheatin&#8217; uh?'));
   678 			die(__('Cheatin&#8217; uh?'));
    72 		}
   679 		}
    73 		$field_name = sprintf('%s_%s', WIDGET_PREFIX, 'api_key');
   680 		$field_name = sprintf('%s_%s', NETWORKPUB_WIDGET_PREFIX, 'api_key');
    74 		$value = strip_tags(stripslashes($_POST[$field_name]));
   681 		if (array_key_exists($field_name, $_POST)) {
    75 		if($value) {
   682 			$value = strip_tags(stripslashes($_POST[$field_name]));
    76 			$networkadd = networkpub_add($value);	
   683 			if ($value) {
    77 		}
   684 				$networkadd = networkpub_add($value);
    78 	}
   685 			}
    79 	$options = get_option(WIDGET_NAME_INTERNAL);
   686 		} else {
    80 	$html  = '<div class="rts_header"><big><strong>'.WIDGET_NAME.'</strong></big></div>';
   687 			if ($_POST['networkpub_form_type'] == 'networkpub_enable') {
    81 	$html .= '<table style="width:800px;"><tr><td style="padding-bottom:40px;">';
   688 				if (array_key_exists('networkpub_enable', $_POST)) {
    82 	$html .= '<div style="padding:0px 0px 10px 0px;">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 <a target="_blank" href="http://www.linksalpha.com/user/networks">LinksAlpha.com</a>, 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.</div>';
   689 					$networkpub_enable = 1;
    83 	$html .= '<div style="padding:0px 0px 20px 0px;"><a href="http://www.linksalpha.com/user/networks" style="font-weight:bold;" target="_blank">Click Here</a> to get API Keys for your Social Networks. You can <a href="http://help.linksalpha.com/wordpress-plugin-network-publisher" target="_blank">read more about this process at LinksAlpha.com.</a></div>';
   690 				} else {
    84 	$html .= '<div class="rts_header2"><big><strong>Setup</strong></big></div><div style="padding-left:10px;">';
   691 					$networkpub_enable = 0;
    85 	$html .= '<div style="text-align:left;">';
   692 				}
    86 	$html .= '<form action="" method="post" id="networkpubadd" name="networkpubadd" style="width:90%;">';
   693 				networkpub_update_option('networkpub_enable', $networkpub_enable);
    87 	$html .= '<fieldset class="rts_fieldset">';
   694 			} elseif ($_POST['networkpub_form_type'] == 'networkpub_auth_error_show') {
    88 	$html .= '<legend>Additional API Key</legend>';
   695 				if (array_key_exists('networkpub_auth_error_show', $_POST)) {
    89 	
   696 					$networkpub_auth_error_show = 1;
       
   697 				} else {
       
   698 					$networkpub_auth_error_show = 0;
       
   699 				}
       
   700 				networkpub_update_option('networkpub_auth_error_show', $networkpub_auth_error_show);
       
   701 			} elseif ($_POST['networkpub_form_type'] == 'networkpub_mixed_mode_alert_show') {
       
   702 				if (array_key_exists('networkpub_mixed_mode_alert_show', $_POST)) {
       
   703 					$networkpub_mixed_mode_alert_show = 1;
       
   704 				} else {
       
   705 					$networkpub_mixed_mode_alert_show = 0;
       
   706 				}
       
   707 				networkpub_update_option('networkpub_mixed_mode_alert_show', $networkpub_mixed_mode_alert_show);
       
   708 			} elseif ($_POST['networkpub_form_type'] == 'networkpub_metatags_facebook') {
       
   709 				if (array_key_exists('networkpub_metatags_facebook', $_POST)) {
       
   710 					$networkpub_metatags_facebook = 1;
       
   711 				} else {
       
   712 					$networkpub_metatags_facebook = 0;
       
   713 				}
       
   714 				if (array_key_exists('networkpub_lang_facebook', $_POST)) {
       
   715 					$networkpub_lang_facebook = strip_tags($_POST['networkpub_lang_facebook']);
       
   716 				} else {
       
   717 					$networkpub_lang_facebook = 'en_US';
       
   718 				}
       
   719 				if (array_key_exists('networkpub_facebook_page_type', $_POST)) {
       
   720 					$networkpub_facebook_page_type = strip_tags($_POST['networkpub_facebook_page_type']);
       
   721 				} else {
       
   722 					$networkpub_facebook_page_type = 'article';
       
   723 				}
       
   724 				if (array_key_exists('networkpub_facebook_app_id', $_POST)) {
       
   725 					$networkpub_facebook_app_id = strip_tags($_POST['networkpub_facebook_app_id']);
       
   726 				} else {
       
   727 					$networkpub_facebook_app_id = '';
       
   728 				}
       
   729 				networkpub_update_option('networkpub_metatags_facebook', $networkpub_metatags_facebook);
       
   730 				networkpub_update_option('networkpub_lang_facebook', $networkpub_lang_facebook);
       
   731 				networkpub_update_option('networkpub_facebook_page_type', $networkpub_facebook_page_type);
       
   732 				networkpub_update_option('networkpub_facebook_app_id', $networkpub_facebook_app_id);
       
   733 			} elseif ($_POST['networkpub_form_type'] == 'networkpub_metatags_googleplus') {
       
   734 				if (array_key_exists('networkpub_metatags_googleplus', $_POST)) {
       
   735 					$networkpub_metatags_googleplus = 'checked';
       
   736 				} else {
       
   737 					$networkpub_metatags_googleplus = '';
       
   738 				}
       
   739 				if (array_key_exists('networkpub_googleplus_page_type', $_POST)) {
       
   740 					$networkpub_googleplus_page_type = strip_tags($_POST['networkpub_googleplus_page_type']);
       
   741 				} else {
       
   742 					$networkpub_googleplus_page_type = 'Article';
       
   743 				}
       
   744 				networkpub_update_option('networkpub_metatags_googleplus', $networkpub_metatags_googleplus);
       
   745 				networkpub_update_option('networkpub_googleplus_page_type', $networkpub_googleplus_page_type);
       
   746 			} elseif ($_POST['networkpub_form_type'] == 'networkpub_custom_field_image') {
       
   747 				if (array_key_exists('networkpub_custom_field_image', $_POST)) {
       
   748 					$networkpub_custom_field_image = strip_tags($_POST['networkpub_custom_field_image']);
       
   749 				} else {
       
   750 					$networkpub_custom_field_image = '';
       
   751 				}
       
   752 				networkpub_update_option('networkpub_custom_field_image', $networkpub_custom_field_image);
       
   753 				if (array_key_exists('networkpub_custom_field_image', $_POST)) {
       
   754 					$networkpub_custom_field_image_url = strip_tags($_POST['networkpub_custom_field_image_url']);
       
   755 				} else {
       
   756 					$networkpub_custom_field_image_url = '';
       
   757 				}
       
   758 				networkpub_update_option('networkpub_custom_field_image_url', $networkpub_custom_field_image_url);
       
   759 			} elseif ($_POST['networkpub_form_type'] == 'networkpub_post_types') {
       
   760 				if (array_key_exists('networkpub_post_types', $_POST)) {
       
   761 					$networkpub_post_types = array();
       
   762 					foreach($_POST['networkpub_post_types'] as $value) {
       
   763 						$networkpub_post_types[] = strip_tags($value);
       
   764 					}
       
   765 					$networkpub_post_types = implode(',', $_POST['networkpub_post_types']);
       
   766 				} else {
       
   767 					$networkpub_post_types = '';
       
   768 				}
       
   769 				networkpub_update_option('networkpub_post_types', $networkpub_post_types);
       
   770 			} elseif ($_POST['networkpub_form_type'] == 'networkpub_thumbnail_size') {
       
   771 				if (array_key_exists('networkpub_thumbnail_size', $_POST)) {
       
   772 					$networkpub_thumbnail_size = strip_tags($_POST['networkpub_thumbnail_size']);
       
   773 				} else {
       
   774 					$networkpub_thumbnail_size = 'medium';
       
   775 				}
       
   776 				networkpub_update_option('networkpub_thumbnail_size', $networkpub_thumbnail_size);
       
   777 			}
       
   778 		}
       
   779 	}
       
   780 	if (!empty($_GET['linksalpha_request_type'])) {
       
   781 		if ($_GET['linksalpha_request_type'] == 'get_posts') {
       
   782 			networkpub_get_posts();
       
   783 		}
       
   784 		return;
       
   785 	}
       
   786 	$options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
       
   787 	if (is_array($options)) {
       
   788 		//Publishing Enable/Disable
       
   789 		if (array_key_exists('networkpub_enable', $options)) {
       
   790 			$networkpub_enable = $options['networkpub_enable'];
       
   791 			if ($networkpub_enable) {
       
   792 				$networkpub_enable = 'checked';
       
   793 			} else {
       
   794 				$networkpub_enable = '';
       
   795 			}
       
   796 		} else {
       
   797 			$networkpub_enable = 'checked';
       
   798 		}
       
   799 		if (array_key_exists('networkpub_auth_error_show', $options)) {
       
   800 			$networkpub_auth_error_show = $options['networkpub_auth_error_show'];
       
   801 			if ($networkpub_auth_error_show) {
       
   802 				$networkpub_auth_error_show = 'checked';
       
   803 			} else {
       
   804 				$networkpub_auth_error_show = '';
       
   805 			}
       
   806 		} else {
       
   807 			$networkpub_auth_error_show = 'checked';
       
   808 		}
       
   809 		if (array_key_exists('networkpub_mixed_mode_alert_show', $options)) {
       
   810 			$networkpub_mixed_mode_alert_show = $options['networkpub_mixed_mode_alert_show'];
       
   811 			if ($networkpub_mixed_mode_alert_show) {
       
   812 				$networkpub_mixed_mode_alert_show = 'checked';
       
   813 			} else {
       
   814 				$networkpub_mixed_mode_alert_show = '';
       
   815 			}
       
   816 		} else {
       
   817 			$networkpub_mixed_mode_alert_show = 'checked';
       
   818 		}
       
   819 		if (array_key_exists('networkpub_metatags_facebook', $options)) {
       
   820 			$networkpub_metatags_facebook = $options['networkpub_metatags_facebook'];
       
   821 			if ($networkpub_metatags_facebook) {
       
   822 				$networkpub_metatags_facebook = 'checked';
       
   823 			} else {
       
   824 				$networkpub_metatags_facebook = '';
       
   825 			}
       
   826 		} else {
       
   827 			$networkpub_metatags_facebook = 'checked';
       
   828 		}
       
   829 		if (array_key_exists('networkpub_lang_facebook', $options)) {
       
   830 			$networkpub_lang_facebook = $options['networkpub_lang_facebook'];
       
   831 		} else {
       
   832 			$networkpub_metatags_facebook = 'en_US';
       
   833 		}
       
   834 		if (array_key_exists('networkpub_facebook_page_type', $options)) {
       
   835 			$networkpub_facebook_page_type = $options['networkpub_facebook_page_type'];
       
   836 		} else {
       
   837 			$networkpub_facebook_page_type = 'article';
       
   838 		}
       
   839 		if (array_key_exists('networkpub_facebook_app_id', $options)) {
       
   840 			$networkpub_facebook_app_id = $options['networkpub_facebook_app_id'];
       
   841 		} else {
       
   842 			$networkpub_facebook_app_id = '';
       
   843 		}
       
   844 		if (array_key_exists('networkpub_metatags_googleplus', $options)) {
       
   845 			$networkpub_metatags_googleplus = $options['networkpub_metatags_googleplus'];
       
   846 			if ($networkpub_metatags_googleplus) {
       
   847 				$networkpub_metatags_googleplus = 'checked';
       
   848 			} else {
       
   849 				$networkpub_metatags_googleplus = '';
       
   850 			}
       
   851 		} else {
       
   852 			$networkpub_metatags_googleplus = 'checked';
       
   853 		}
       
   854 		if (array_key_exists('networkpub_googleplus_page_type', $options)) {
       
   855 			$networkpub_googleplus_page_type = $options['networkpub_googleplus_page_type'];
       
   856 		} else {
       
   857 			$networkpub_googleplus_page_type = 'Article';
       
   858 		}
       
   859 		if (array_key_exists('networkpub_custom_field_image', $options)) {
       
   860 			$networkpub_custom_field_image = $options['networkpub_custom_field_image'];
       
   861 		} else {
       
   862 			$networkpub_custom_field_image = '';
       
   863 		}
       
   864 		if (array_key_exists('networkpub_custom_field_image_url', $options)) {
       
   865 			$networkpub_custom_field_image_url = $options['networkpub_custom_field_image_url'];
       
   866 		} else {
       
   867 			$networkpub_custom_field_image_url = '';
       
   868 		}
       
   869 		if (array_key_exists('networkpub_thumbnail_size', $options)) {
       
   870 			$networkpub_thumbnail_size = $options['networkpub_thumbnail_size'];
       
   871 		} else {
       
   872 			$networkpub_thumbnail_size = 'medium';
       
   873 		}
       
   874 	} else {
       
   875 		$networkpub_enable = 'checked';
       
   876 		$networkpub_auth_error_show = 'checked';
       
   877 		$networkpub_mixed_mode_alert_show = 'checked';
       
   878 		$networkpub_metatags_facebook = 'checked';
       
   879 		$networkpub_lang_facebook = 'en_US';
       
   880 		$networkpub_facebook_page_type = 'article';
       
   881 		$networkpub_facebook_app_id = '';
       
   882 		$networkpub_metatags_googleplus = 'checked';
       
   883 		$networkpub_googleplus_page_type = 'Article';
       
   884 		$networkpub_custom_field_image = '';
       
   885 		$networkpub_custom_field_image_url = '';
       
   886 		$networkpub_thumbnail_size = 'medium';
       
   887 	}
       
   888 	$fb_langs = networkpub_fb_langs();
       
   889 	$fb_langs_options = '';
       
   890 	asort($fb_langs);
       
   891 	foreach ($fb_langs as $key => $val) {
       
   892 		if ($networkpub_lang_facebook == $key) {
       
   893 			$fb_langs_options = $fb_langs_options . '<option value="' . htmlentities($key) . '" selected>' . htmlentities($val) . '</option>';
       
   894 		} else {
       
   895 			$fb_langs_options = $fb_langs_options . '<option value="' . htmlentities($key) . '">' . htmlentities($val) . '</option>';
       
   896 		}
       
   897 	}
       
   898 	$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'));
       
   899 	$facebook_page_type_options = '';
       
   900 	foreach ($facebook_page_type as $key => $val) {
       
   901 		if ($networkpub_facebook_page_type == $key) {
       
   902 			$facebook_page_type_options = $facebook_page_type_options . '<option value="' . htmlentities($key) . '" selected>' . htmlentities($val) . '</option>';
       
   903 		} else {
       
   904 			$facebook_page_type_options = $facebook_page_type_options . '<option value="' . htmlentities($key) . '">' . htmlentities($val) . '</option>';
       
   905 		}
       
   906 	}
       
   907 	$googleplus_page_type = array('Article' => __('Article'), 'Blog' => __('Blog'), 'Book' => __('Book'), 'Event' => __('Event'), 'LocalBusiness' => __('Local Business'), 'Organization' => __('Organization'), 'Person' => __('Person'), 'Product' => __('Product'), 'Review' => __('Review'));
       
   908 	$googleplus_page_type_options = '';
       
   909 	foreach ($googleplus_page_type as $key => $val) {
       
   910 		if ($networkpub_googleplus_page_type == $key) {
       
   911 			$googleplus_page_type_options = $googleplus_page_type_options . '<option value="' . htmlentities($key) . '" selected>' . htmlentities($val) . '</option>';
       
   912 		} else {
       
   913 			$googleplus_page_type_options = $googleplus_page_type_options . '<option value="' . htmlentities($key) . '">' . htmlentities($val) . '</option>';
       
   914 		}
       
   915 	}
       
   916 	$thumbnail_size_types = array('medium'=>'Medium', 'large'=>'Large');
       
   917 	$thumbnail_size_options = '';
       
   918 	foreach ($thumbnail_size_types as $key => $val) {
       
   919 		if ($networkpub_thumbnail_size == $key) {
       
   920 			$thumbnail_size_options = $thumbnail_size_options . '<option value="' . htmlentities($key) . '" selected>' . htmlentities($val) . '</option>';
       
   921 		} else {
       
   922 			$thumbnail_size_options = $thumbnail_size_options . '<option value="' . htmlentities($key) . '">' . htmlentities($val) . '</option>';
       
   923 		}
       
   924 	}
       
   925 	networkpub_mixed_mode();
       
   926 	networkpub_disabled_check($networkpub_enable);
       
   927 	$html = '
       
   928 	<div id="networkpub_msg"></div>
       
   929 			<div class="wrap">
       
   930 				<span><div class="icon32" id="networkpubisher_laicon"><br /></div><h2>' . NETWORKPUB_WIDGET_NAME . '</h2></span>
       
   931 			</div>
       
   932 			<div class="wrap">
       
   933 			<div style="width:76%;float:left;">
       
   934 				<div class="networkpublisher_share_box">
       
   935 					<table>
       
   936 						<tr>
       
   937 							<td>
       
   938 								<a href="' . networkpub_postbox_url() . '">' . __('Postbox') . '</a>&nbsp;&nbsp;|&nbsp;&nbsp;' . __('Share') . '
       
   939 							</td>
       
   940 							<td>
       
   941 								<div class="linksalpha-email-button" id="linksalpha_tag_208867858" data-url="http://www.linksalpha.com" data-text="LinksAlpha - Making Social Media Easy!" data-desc="LinksAlpha provides quick and easy way for companies and users to connect and share on social web. Using LinksAlpha tools, you can integrate Social Media Buttons into your website, Publish your Website Content Automatically to Social Media Sites, and Track Social Media Profiles, all from one place." data-image="http://www.linksalpha.com/images/LALOGO_s175.png"></div>
       
   942 								<script type="text/javascript" src="http://www.linksalpha.com/social/loader?tag_id=linksalpha_tag_208867858&fblikefont=arial&vkontakte=1&livejournal=1&twitter=1&xinglang=de&linkedin=1&tumblr=1&hyves=1&fblikelang=en_US&delicious=1&twitterw=110&gpluslang=en-US&gmail=1&weibo=1&posterous=1&xing=1&sonico=1&twitterlang=en&pinterest=1&myspace=1&msn=1&print=1&mailru=1&email=1&counters=googleplus%2Cfacebook%2Clinkedin%2Ctwitter&reddit=1&hotmail=1&netlog=1&twitterrelated=linksalpha&aolmail=1&link=http%3A%2F%2Fwww.linksalpha.com&diigo=1&evernote=1&digg=1&yahoomail=1&yammer=1&stumbleupon=1&instapaper=1&facebookw=90&googleplus=1&fblikeverb=like&fblikeref=linksalpha&halign=left&readitlater=1&v=2&facebook=1&button=googleplus%2Cfacebook%2Clinkedin%2Ctwitter&identica=1"></script>
       
   943 							</td>
       
   944 						</tr>
       
   945 					</table>
       
   946 				</div>
       
   947 				<div>
       
   948 					<div class="networkpublisher_started">
       
   949 						<div style="padding:0px 0px 5px 0px;"><strong>' . __('Network Publisher') . '</strong> ' . __('makes it easy to Publish your Blog Posts to Social Networks. To configure:') . '</div>
       
   950 						<div><b>1.</b>&nbsp;' . __('Connect to your Social Networks at') . ' <a target="_blank" href="http://www.linksalpha.com/networks">' . __('LinksAlpha.com') . '</a></div>
       
   951 						<div><b>2.</b>&nbsp;' . __('Get your') . ' <a target="_blank" href="http://www.linksalpha.com/account/your_api_key">' . __('User API Key') . '</a> ' . __('or') . ' <a target="_blank" href="http://www.linksalpha.com/networks">' . __('Network API Key') . '</a> ' . __('and enter it below.') . '</div>
       
   952 						<div style="padding:5px 0px 0px 0px;">' . __('Once setup, your Blog posts content appears on the social networks as soon as you hit the Publish button.') . '</div>
       
   953 						<div>' . __('You can') . ' <a href="http://help.linksalpha.com/networks/getting-started" target="_blank">' . __('read more about this process at LinksAlpha.com.') . '</a></div>
       
   954 					</div>
       
   955 					<div class="networkpublisher_header">
       
   956 						<strong>' . __('Setup') . '</strong>
       
   957 					</div>
       
   958 					<div style="padding-left:0px;margin-bottom:40px;">
       
   959 						<div class="networkpublisher_content_box">
       
   960 							<form action="" method="post">
       
   961 							<fieldset class="networkpublisher_fieldset">
       
   962 								<legend>' . __('API Key') . '</legend>';
    90 	$curr_field = 'api_key';
   963 	$curr_field = 'api_key';
    91 	$field_name = sprintf('%s_%s', WIDGET_PREFIX, $curr_field);
   964 	$field_name = sprintf('%s_%s', NETWORKPUB_WIDGET_PREFIX, $curr_field);
    92 	$html .= '<div><label for="'.$field_name.'">'.$networkpub_settings[$curr_field]['label'].'&nbsp;</label></div>';
   965 	$html .= '<table style="width:100%;">
    93 	$html .= '<div style="padding-bottom:10px"><input style="width:400px;" class="widefat" id="'.$field_name.'" name="'.$field_name.'" type="text" /></div>';
   966                                     <tr>
    94 	
   967                                         <td>
    95 	$html .= '</fieldset>';
   968                                             <label for="' . $field_name . '">
    96 	$html .= '<div style="padding-top:20px;"><input type="submit" name="submit" value="Add API Key" /></div>';
   969                                                 ' . __('Get your') . ' <a href="http://www.linksalpha.com/account/your_api_key" target="_blank">' . __('User API Key') . '</a> ' . __('or') . ' <a target="_blank" href="http://www.linksalpha.com/networks">' . __('Network API Key') . '</a> ' . __('and enter it below.') . '
    97 	$html .= '<input type="hidden" value="'.WP_PLUGIN_URL.'" id="networkpub_plugin_url" /></form></div></td></tr><tr><td style="padding:0px 0px 0px 0px;vertical-align:top;">';
   970                                             </label>
    98 	$html .= '<div class="rts_header2"><big><strong>Currently Publishing</strong></big></div>';
   971                                         </td>
    99 	$html .= '<div style="padding-left:10px;">'.networkpub_load().'</div>';
   972                                     </tr>
   100 	$html .= '</div></td></tr></table>';
   973                                     <tr>
       
   974                                         <td>
       
   975                                             <div style="padding-bottom:10px;padding-top:3px;">
       
   976                                                 <input style="width:400px;  border-width:1px;border-color:gray;border-style:solid" class="widefat" id="' . $field_name . '" name="' . $field_name . '" type="text" TABINDEX=1000 />
       
   977                                             </div>
       
   978                                         </td>
       
   979                                     </tr>
       
   980                                 </table>
       
   981 							</fieldset>
       
   982 							<div style="padding-top:0px;">
       
   983                                 <table class="networkpublisher_add_key_submit">
       
   984                                     <tr>
       
   985                                         <td class="networkpublisher_add_key_submit_button">
       
   986                                             <input type="submit" name="submit" class="button-primary" value="' . __('Add API Key') . '" TABINDEX=1001 />
       
   987                                         </td>
       
   988                                         <td class="networkpublisher_add_key_submit_social">
       
   989                                             <div class="linksalpha-email-button" id="linksalpha_tag_20886785812" data-url="http://www.linksalpha.com" data-text="LinksAlpha - Making Social Media Easy!" data-desc="LinksAlpha provides quick and easy way for companies and users to connect and share on social web. Using LinksAlpha tools, you can integrate Social Media Buttons into your website, Publish your Website Content Automatically to Social Media Sites, and Track Social Media Profiles, all from one place." data-image="http://www.linksalpha.com/images/LALOGO_s175.png"></div>
       
   990 											<script type="text/javascript" src="http://www.linksalpha.com/social/loader?tag_id=linksalpha_tag_20886785812&fblikefont=arial&vkontakte=1&livejournal=1&twitter=1&xinglang=de&linkedin=1&tumblr=1&hyves=1&fblikelang=en_US&delicious=1&twitterw=110&gpluslang=en-US&gmail=1&weibo=1&posterous=1&xing=1&sonico=1&twitterlang=en&pinterest=1&myspace=1&msn=1&print=1&mailru=1&email=1&counters=googleplus%2Cfacebook%2Clinkedin%2Ctwitter&reddit=1&hotmail=1&netlog=1&twitterrelated=linksalpha&aolmail=1&link=http%3A%2F%2Fwww.linksalpha.com&diigo=1&evernote=1&digg=1&yahoomail=1&yammer=1&stumbleupon=1&instapaper=1&facebookw=90&googleplus=1&fblikeverb=like&fblikeref=linksalpha&halign=left&readitlater=1&v=2&facebook=1&button=googleplus%2Cfacebook%2Clinkedin%2Ctwitter&identica=1"></script>
       
   991                                         </td>
       
   992                                     </tr>
       
   993                                 </table>
       
   994 							</div>
       
   995 							<input type="hidden" value="' . NETWORKPUB_WP_PLUGIN_URL . '" id="networkpub_plugin_url" />
       
   996 							<input type="hidden" value="' . __('Removing...') . '" id="networkpub_text_removing" />
       
   997 							<input type="hidden" value="' . __('An error occured while removing the Publication. As a workaround, you can remove this Publication from') . '" id="networkpub_text_an_error_occured" />
       
   998 							<input type="hidden" value="' . __('LinksAlpha Publisher') . '" id="networkpub_text_linksalpha_publisher" />
       
   999 							<input type="hidden" value="' . __('Publication has been removed successfully') . '" id="networkpub_text_publication_has_been_removed" />
       
  1000 							</form>
       
  1001 						</div>
       
  1002 						<div style="font-size:14px;margin:10px 0px 0px 0px;padding:5px;" id="networkpub_remove">&nbsp;</div>
       
  1003 						<div style="padding:5px 0px 0px 0px;">
       
  1004 							<div class="networkpublisher_header">
       
  1005 								<strong>' . __('Currently Publishing') . '</strong>
       
  1006 							</div>
       
  1007 							<div class="networkpublisher_content_box">' . networkpub_load() . '</div>
       
  1008 						</div>
       
  1009 
       
  1010 						<a href="#setting_networkpub_enable" style="text-decoration:none;color:#333;">
       
  1011 							<div style="padding:40px 0px 0px 0px;">
       
  1012 								<div class="networkpublisher_header">
       
  1013 									<strong>' . __('Enable/Disable Publishing') . '</strong>
       
  1014 								</div>
       
  1015 								<div class="networkpublisher_content_box networkpublisher_highlight"  name="setting_networkpub_enable" id="setting_networkpub_enable">
       
  1016 									<div style="padding-bottom:10px;">
       
  1017 										<form action="" method="post">
       
  1018 											<div>
       
  1019 												<input type="checkbox" id="networkpub_enable" name="networkpub_enable" ' . $networkpub_enable . ' /><label for="networkpub_enable">&nbsp;&nbsp;' . __('Check this box to Enable publishing') . '</label>
       
  1020 											</div>
       
  1021 											<div style="padding-top:5px;">
       
  1022 												<input type="hidden" name="networkpub_form_type" value="networkpub_enable" />
       
  1023 												<input type="submit" name="submit" class="button-primary" value="' . __('Update') . '" />
       
  1024 											</div>
       
  1025 										</form>
       
  1026 									</div>
       
  1027 									<div>
       
  1028 										<div style="padding-bottom:5px;">' . __('Notes:') . '</div>
       
  1029 										<ol>
       
  1030 											<li>' . __('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') . '</li>
       
  1031 											<li>' . __('Deactivating the plugin will not disable publishing. You need to use this checkbox to disable publishing') . '</li>
       
  1032 										</ol>
       
  1033 									</div>
       
  1034 								</div>
       
  1035 							</div>
       
  1036 						</a>
       
  1037  						<div style="padding:40px 0px 0px 0px;">
       
  1038  							<div class="networkpublisher_header">
       
  1039  								<strong>' . __('Show/Hide Authorization Errors') . '</strong>
       
  1040  							</div>
       
  1041  							<div class="networkpublisher_content_box">
       
  1042  								<div style="padding-bottom:10px;">
       
  1043  									<form action="" method="post">
       
  1044  										<div>
       
  1045  											<input type="checkbox" id="networkpub_auth_error_show" name="networkpub_auth_error_show" ' . $networkpub_auth_error_show . ' /><label for="networkpub_auth_error_show">&nbsp;&nbsp;' . __('Check this box to show error message in WordPress Admin Console in case there are Authorization Errors with any of your social network profiles.') . ' <a target="_blank" href="http://help.linksalpha.com/networks/authorization-error">' . __('Click Here') . '</a> ' . __('to learn more.') . '</label>
       
  1046  										</div>
       
  1047  										<div style="padding-top:5px;">
       
  1048  											<input type="hidden" name="networkpub_form_type" value="networkpub_auth_error_show" />
       
  1049  											<input type="submit" name="submit" class="button-primary" value="' . __('Update') . '" />
       
  1050  										</div>
       
  1051  									</form>
       
  1052  								</div>
       
  1053  							</div>
       
  1054  						</div>
       
  1055 						<div style="padding:40px 0px 0px 0px;">
       
  1056 							<div class="networkpublisher_header">
       
  1057 								<strong>' . __('Show/Hide Mixed Mode Configuration Alert') . '</strong>
       
  1058 							</div>
       
  1059 							<div class="networkpublisher_content_box">
       
  1060 								<div style="padding-bottom:10px;">
       
  1061 									<form action="" method="post">
       
  1062 										<div>
       
  1063 											<input type="checkbox" id="networkpub_mixed_mode_alert_show" name="networkpub_mixed_mode_alert_show" ' . $networkpub_mixed_mode_alert_show . ' /><label for="networkpub_mixed_mode_alert_show">&nbsp;&nbsp;' . __('Check this box to show alert if Mixed Mode configuration is detected.') . ' <a target="_blank" href="http://help.linksalpha.com/wordpress-plugin-network-publisher/mixed-mode-alert">' . __('Click Here') . '</a> ' . __('to learn more.') . '</label>
       
  1064 										</div>
       
  1065 										<div style="padding-top:5px;">
       
  1066 											<input type="hidden" name="networkpub_form_type" value="networkpub_mixed_mode_alert_show" />
       
  1067 											<input type="submit" name="submit" class="button-primary" value="' . __('Update') . '" />
       
  1068 										</div>
       
  1069 									</form>
       
  1070 								</div>
       
  1071 							</div>
       
  1072 						</div>
       
  1073 						<div style="padding:40px 0px 0px 0px;">
       
  1074 							<div class="networkpublisher_header">
       
  1075 								<strong>' . __('Facebook Open Graph Metatags and Locale') . '</strong>
       
  1076 							</div>
       
  1077 							<div class="networkpublisher_content_box">
       
  1078 								<div style="padding-bottom:10px;">
       
  1079 									<form action="" method="post">
       
  1080 										<div>
       
  1081 											<input type="checkbox" id="networkpub_metatags_facebook" name="networkpub_metatags_facebook" ' . $networkpub_metatags_facebook . ' /><label for="networkpub_metatags_facebook">&nbsp;&nbsp;' . __('Check this box if you want Facebook Open Graph Metatags added to your pages. ') . ' <a target="_blank" href="http://help.linksalpha.com/wordpress-plugin-network-publisher/metatags">' . __('Click Here') . '</a> ' . __('to learn more.') . '</label>
       
  1082 										</div>
       
  1083 										<div style="padding:10px 0px;">
       
  1084 											<div style="width:220px;float:left;">
       
  1085 				                            	<select name="networkpub_lang_facebook" id="networkpub_lang_facebook">
       
  1086 				                                	' . $fb_langs_options . '
       
  1087 				                            	</select>
       
  1088 				                            </div>
       
  1089 				                            <div style="float:left;width:400px;">
       
  1090 												<label for="networkpub_lang_facebook">' . __('Facebook Locale') . '</label>
       
  1091 											</div>
       
  1092 				                            <br style="clear:both;"/>
       
  1093 			                            </div>
       
  1094 			                            <div style="padding:10px 0px;">
       
  1095 											<div style="width:120px;float:left;">
       
  1096 				                            	<select name="networkpub_facebook_page_type" id="networkpub_facebook_page_type">
       
  1097 				                                	' . $facebook_page_type_options . '
       
  1098 				                            	</select>
       
  1099 				                            </div>
       
  1100 				                            <div style="float:left;width:400px;">
       
  1101 												<label for="networkpub_facebook_page_type">' . __('Page Type') . '</label>
       
  1102 											</div>
       
  1103 				                            <br style="clear:both;"/>
       
  1104 			                            </div>
       
  1105 										<div style="padding:10px 0px;">
       
  1106 											<div style="width:120px;float:left;">
       
  1107 				                            	<input style="width:110px" type="text" name="networkpub_facebook_app_id" id="networkpub_facebook_app_id" value="' . $networkpub_facebook_app_id . '" />
       
  1108 				                            </div>
       
  1109 				                            <div style="float:left;width:400px;">
       
  1110 												<label for="networkpub_facebook_app_id">' . __('Facebook App ID') . '</label>
       
  1111 											</div>
       
  1112 				                            <br style="clear:both;"/>
       
  1113 			                            </div>
       
  1114 										<div>
       
  1115 											<input type="hidden" name="networkpub_form_type" value="networkpub_metatags_facebook" />
       
  1116 											<input type="submit" name="submit" class="button-primary" value="' . __('Update') . '" />
       
  1117 										</div>
       
  1118 									</form>
       
  1119 								</div>
       
  1120 							</div>
       
  1121 						</div>
       
  1122 						<div style="padding:40px 0px 0px 0px;">
       
  1123 							<div class="networkpublisher_header">
       
  1124 								<strong>' . __('Google Plus Metatags and Page Type') . '</strong>
       
  1125 							</div>
       
  1126 							<div class="networkpublisher_content_box">
       
  1127 								<div style="padding-bottom:10px;">
       
  1128 									<form action="" method="post">
       
  1129 										<div>
       
  1130 											<input type="checkbox" id="networkpub_metatags_googleplus" name="networkpub_metatags_googleplus" ' . $networkpub_metatags_googleplus . ' /><label for="networkpub_metatags_googleplus">&nbsp;&nbsp;' . __('Check this box if you want Google Plus Metatags added to your pages. ') . ' <a target="_blank" href="http://help.linksalpha.com/wordpress-plugin-network-publisher/metatags">' . __('Click Here') . '</a> ' . __('to learn more.') . '</label>
       
  1131 										</div>
       
  1132 										<div style="padding:10px 0px;">
       
  1133 											<div style="width:120px;float:left;">
       
  1134 				                            	<select name="networkpub_googleplus_page_type" id="networkpub_googleplus_page_type">
       
  1135 				                                	' . $googleplus_page_type_options . '
       
  1136 				                            	</select>
       
  1137 				                            </div>
       
  1138 				                            <div style="float:left;width:400px;">
       
  1139 												<label for="networkpub_googleplus_page_type">' . __('Page Type') . '</label>
       
  1140 											</div>
       
  1141 				                            <br style="clear:both;"/>
       
  1142 			                            </div>
       
  1143 										<div>
       
  1144 											<input type="hidden" name="networkpub_form_type" value="networkpub_metatags_googleplus" />
       
  1145 											<input type="submit" name="submit" class="button-primary" value="' . __('Update') . '" />
       
  1146 										</div>
       
  1147 									</form>
       
  1148 								</div>
       
  1149 							</div>
       
  1150 						</div>
       
  1151 						<div style="padding:40px 0px 0px 0px;">
       
  1152 							<div class="networkpublisher_header">
       
  1153 								<strong>' . __('Image Size') . '</strong>
       
  1154 							</div>
       
  1155 							<div class="networkpublisher_content_box">
       
  1156 								<div style="padding-bottom:10px;">
       
  1157 									<form action="" method="post">
       
  1158 										<div style="padding-bottom:3px;">
       
  1159 											<label for="networkpub_thumbnail_size">' . __('Select the Image Size to be used while posting.') . '</label>
       
  1160 										</div>
       
  1161 										<div>
       
  1162 			                            	<select name="networkpub_thumbnail_size"' . $networkpub_thumbnail_size . ' id="networkpub_thumbnail_size">
       
  1163 			                                	'. $thumbnail_size_options .'
       
  1164 			                            	</select>
       
  1165 			                           	</div>
       
  1166 										<div style="padding:3px 0px 20px 0px;color:gray;">
       
  1167 			                            ' . __('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.') . '
       
  1168 			                            </div>
       
  1169 										<div>
       
  1170 											<input type="hidden" name="networkpub_form_type" value="networkpub_thumbnail_size" />
       
  1171 											<input type="submit" name="submit" class="button-primary" value="' . __('Update') . '" />
       
  1172 						 				</div>
       
  1173 									</form>
       
  1174 								</div>
       
  1175 							</div>
       
  1176 						</div>
       
  1177 						<div style="padding:40px 0px 0px 0px;">
       
  1178 							<div class="networkpublisher_header">
       
  1179 								<strong>' . __('Image URL from Custom Field') . '</strong>
       
  1180 							</div>
       
  1181 						   	<div class="networkpublisher_content_box">
       
  1182 								<form action="" method="post">
       
  1183 									<div style="padding:0px 0px 0px 0px;">
       
  1184 										<div style="padding:3px 0px 0px 0px;">
       
  1185 											<label for="networkpub_custom_field_image">' . __('	Custom Field Name') . '</label>
       
  1186 										</div>
       
  1187 										<div>
       
  1188 			                            	<input style="width:210px;" type="text" name="networkpub_custom_field_image" id="networkpub_custom_field_image" value="' . $networkpub_custom_field_image . '" />
       
  1189 			                            </div>
       
  1190 		                            </div>
       
  1191 		                            <div style="padding:0px 0px 0px 0px;color:gray;">
       
  1192 		                            ' . __('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') . ' <a href="http://support.linksalpha.com">' . __('LinksAlpha Support.') . '</a>
       
  1193 		                            </div>
       
  1194 									<div style="padding:10px 0px 0px 0px;">
       
  1195 										<div style="padding:3px 0px 0px 0px;">
       
  1196 											<label for="networkpub_custom_field_image_url">' . __('URL to prepend the image') . '</label>
       
  1197 										</div>
       
  1198 		                            	<div>
       
  1199 			                            	<input style="width:210px;" type="text" name="networkpub_custom_field_image_url" id="networkpub_custom_field_image_url" value="'. $networkpub_custom_field_image_url.'" />
       
  1200 			                            </div>
       
  1201 		                            </div>
       
  1202 		                            <div style="padding:0px 0px 20px 0px;color:gray;">
       
  1203 		                            ' . __('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.') . '
       
  1204 		                            </div>
       
  1205 									<div>
       
  1206 										<input type="hidden" name="networkpub_form_type" value="networkpub_custom_field_image" />
       
  1207 										<input type="submit" name="submit" class="button-primary" value="' . __('Update') . '" />
       
  1208 									</div>
       
  1209 								</form>
       
  1210 							</div>
       
  1211 						</div>
       
  1212 						<a href="#setting_networkpub_post_types" style="text-decoration:none;color:#333;">
       
  1213 							<div style="padding:40px 0px 0px 0px;">
       
  1214 								<div class="networkpublisher_header">
       
  1215 									<strong>' . __('Post Types to Publish') . '</strong>
       
  1216 								</div>
       
  1217 								<div class="networkpublisher_content_box networkpublisher_highlight"  name="setting_networkpub_post_types" id="setting_networkpub_post_types">
       
  1218 									<div style="padding-bottom:10px;">
       
  1219 										<form action="" method="post">
       
  1220 											<div style="padding:0px 0px 10px 0px;">
       
  1221 				                            ' . __('Select the WordPress ') . '<a href="http://codex.wordpress.org/Post_Types" target="_blank">' . __('Post Types') . '</a>' . __(' that you want to Publish to your Social Network profiles.') . '</a>
       
  1222 
       
  1223 				                            </div>
       
  1224 				                            <div style="padding:0px 0px 10px 0px;">' . networkpub_post_types() . '</div>
       
  1225 											<div>
       
  1226 												<input type="hidden" name="networkpub_form_type" value="networkpub_post_types" />
       
  1227 												<input type="submit" name="submit" class="button-primary" value="' . __('Update') . '" />
       
  1228 											</div>
       
  1229 										</form>
       
  1230 									</div>
       
  1231 								</div>
       
  1232 							</div>
       
  1233 						</a>
       
  1234 						<div style="font-size:13px;margin:40px 0px 0px 0px;">
       
  1235                             <div class="networkpublisher_header">
       
  1236 								<strong>' . __('Note') . '</strong>
       
  1237 							</div>
       
  1238 							<div class="networkpublisher_content_box">
       
  1239                                 ' . __('If you decide to stop using this plugin permanently, please remove your blog URL from') . ' <a href="http://www.linksalpha.com/websites" target="_blank">' . __('LinksAlpha Website Manager') . '</a>. ' . __('Otherwise, your blog posts may continue to get posted even after you remove this plugin.') . '
       
  1240                             </div>
       
  1241 						</div>
       
  1242 					</div>
       
  1243 				</div>
       
  1244 			</div>
       
  1245 			<div style="vertical-align:top;padding-left:2%;text-align:right;width:20%;float:left;">
       
  1246 				<div style="margin-bottom:20px;width:150px;margin-top:10px;float:right;">
       
  1247 					<a href="' . networkpub_postbox_url() . '" style="text-decoration:none;">
       
  1248 						<div class="networkpublisher_button_yellow">' . __('View Postbox') . '</div>
       
  1249 					</a>
       
  1250 				</div>
       
  1251 				<div class="networkpub_clear_both"></div>
       
  1252 				<div class="networkpublisher_header_3" style="float:right;margin-right:-20px;">' . __('Supported Networks') . '</div>
       
  1253 				<div class="networkpub_clear_both"></div>
       
  1254 				<div class="networkpublisher_content_box_3" style="float:right;margin-right:-20px;">
       
  1255 					' . networkpub_supported_networks() . '
       
  1256 				</div>
       
  1257 				<div class="networkpub_clear_both"></div>
       
  1258 			</div>
       
  1259 			</div>';
   101 	echo $html;
  1260 	echo $html;
   102 }
  1261 }
   103 
  1262 
   104 function networkpub_add($api_key) {
  1263 function networkpub_add($api_key) {
   105 	if (!$api_key) {
  1264 	if (!$api_key) {
       
  1265 		$errdesc = networkpub_error_msgs('invalid key');
       
  1266 		echo $errdesc;
       
  1267 		return;
       
  1268 	}
       
  1269 	$url = get_bloginfo('url');
       
  1270 	if (!$url) {
       
  1271 		$errdesc = networkpub_error_msgs('invalid url');
       
  1272 		echo $errdesc;
       
  1273 		return;
       
  1274 	}
       
  1275 	$desc = get_bloginfo('description');
       
  1276 	$options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
       
  1277 	if (!empty($options['id'])) {
       
  1278 		$id = $options['id'];
       
  1279 	} elseif (!empty($options['id_2'])) {
       
  1280 		$id = $options['id_2'];
       
  1281 	} else {
       
  1282 		$id = '';
       
  1283 	}
       
  1284 	$url_parsed = parse_url($url);
       
  1285 	$url_host = $url_parsed['host'];
       
  1286 	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) {
       
  1287 		$errdesc = networkpub_error_msgs('localhost url');
       
  1288 		echo $errdesc;
   106 		return FALSE;
  1289 		return FALSE;
   107 	}
  1290 	}
   108 	$url = get_option('siteurl');
  1291 	$link = 'http://www.linksalpha.com/a/networkpubaddone';
   109 	$desc = get_bloginfo('description');
  1292 	// Build Params
   110 	if (!$url) {
  1293 	$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);
       
  1294 	$response_full = networkpub_http_post($link, $params);
       
  1295 	$response_code = $response_full[0];
       
  1296 	if ($response_code != 200) {
       
  1297 		$errdesc = networkpub_error_msgs($response_full[1]);
       
  1298 		echo $errdesc;
   111 		return FALSE;
  1299 		return FALSE;
   112 	}
  1300 	}
   113 	$link = 'http://www.linksalpha.com/a/networkpubadd?url='.urlencode($url).'&key='.$api_key.'&desc='.urlencode($desc);
  1301 	$response = networkpub_json_decode($response_full[1]);
   114 	require_once(ABSPATH.WPINC.'/class-snoopy.php');
  1302 	if ($response->errorCode > 0) {
   115 	$snoop = new Snoopy;
  1303 		if(isset($response->errorDetail)) {
   116 	$snoop->agent = WIDGET_NAME.' - '.get_option('siteurl');
  1304 			$errdesc = networkpub_error_msgs($response->errorMessage, $response->errorDetail);	
   117 	$response = '';
  1305 		} else {
   118 	if($snoop->fetchtext($link)){
  1306 			$errdesc = networkpub_error_msgs($response->errorMessage);	
   119 		if (strpos($snoop->response_code, '200')) {
  1307 		}
   120 			$response_json = $snoop->results;
  1308 		echo $errdesc;
   121 			$response = networkpub_json_decode($response_json);
       
   122 		}
       
   123 	}
       
   124 	if (!$response) {
       
   125 		return FALSE;
  1309 		return FALSE;
   126 	}
  1310 	}
       
  1311 	$options['id_2'] = $response->results->id;
       
  1312 	if (empty($options['api_key'])) {
       
  1313 		$options['api_key'] = $response -> results -> api_key;
       
  1314 	} else {
       
  1315 		$option_api_key_array = explode(',', $options['api_key']);
       
  1316 		$option_api_key_new = $response -> results -> api_key;
       
  1317 		$option_api_key_new_array = explode(',', $option_api_key_new);
       
  1318 		foreach ($option_api_key_new_array as $key => $val) {
       
  1319 			if (!in_array($val, $option_api_key_array)) {
       
  1320 				$options['api_key'] = $options['api_key'] . ',' . $val;
       
  1321 			}
       
  1322 		}
       
  1323 	}
       
  1324 	update_option(NETWORKPUB_WIDGET_NAME_INTERNAL, $options);
       
  1325 	//Return
       
  1326 	echo '<div class="updated fade wrap networkpub_msg" style="text-align:center">' . __('API Key has been added successfully.') . '</div>';
       
  1327 	return;
       
  1328 }
       
  1329 function networkpub_load() {
       
  1330 	$options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
       
  1331 	if (empty($options['api_key'])) {
       
  1332 		$html = '<div>' . __('You have not added an API Key') . '</div>';
       
  1333 		return $html;
       
  1334 	}
       
  1335 	$link = 'http://www.linksalpha.com/a/networkpubget';
       
  1336 	$body = array('key' => $options['api_key'], 'version' => 2);
       
  1337 	$response_full = networkpub_http_post($link, $body);
       
  1338 	$response_code = $response_full[0];
       
  1339 	if ($response_code != 200) {
       
  1340 		$errdeschtml = networkpub_error_msgs('misc');
       
  1341 		return $errdeschtml;
       
  1342 	}	$response = networkpub_json_decode($response_full[1]);
   127 	if ($response->errorCode > 0) {
  1343 	if ($response->errorCode > 0) {
   128 		return FALSE;
  1344 		$html = '<div>' . __('Error occured while trying to load the API Keys. Please try again later.') . '</div>';
   129 	}
  1345 		return $html;
   130 	$options = get_option(WIDGET_NAME_INTERNAL);
  1346 	}
   131 	if(empty($options['api_key'])) {
  1347 	if (count($response->results_deleted)) {
   132 		$options['api_key'] = $api_key;	
  1348 		$option_api_key_array = explode(',', $options['api_key']);
       
  1349 		foreach($response->results_deleted as $row) {
       
  1350 			if(in_array($row, $option_api_key_array)) {
       
  1351 				$option_api_key_array = array_diff($option_api_key_array, array($row));
       
  1352 			}
       
  1353 		}
       
  1354 		$api_key = implode(",", $option_api_key_array);
       
  1355 		$options['api_key'] = $api_key;
       
  1356 		update_option(NETWORKPUB_WIDGET_NAME_INTERNAL, $options);
       
  1357 	}
       
  1358 	if (!count($response -> results)) {
       
  1359 		return '<div>' . __('You have not added an API Key') . '</div>';
       
  1360 	}
       
  1361 	if (count($response -> results) == 1) {
       
  1362 		$html = '<div style="padding:0px 10px 5px 0px;">' . NETWORKPUB_CURRENTLY_PUBLISHING . '&nbsp;' . count($response -> results) . '&nbsp;' . NETWORKPUB_SOCIAL_NETWORK . '</div>';
   133 	} else {
  1363 	} else {
   134 		$options_array = explode(',', $options['api_key']);
  1364 		$html = '<div style="padding:0px 10px 5px 0px;">' . NETWORKPUB_CURRENTLY_PUBLISHING . '&nbsp;' . count($response -> results) . '&nbsp;' . NETWORKPUB_SOCIAL_NETWORKS . '</div>';
   135 		if(!in_array($api_key, $options_array)) {
  1365 	}
   136 			$options['api_key'] = $options['api_key'].','.$api_key;	
  1366 	$html .= '<table class="networkpublisher_added"><tr><th>' . __('Network Account') . '</th><th>' . __('Options') . '</th><th>' . __('Publish Results') . '</th><th>' . __('Remove') . '</th></tr>';
   137 		}
  1367 	$i = 1;
   138 	}
  1368 	foreach ($response->results as $row) {
   139 	$options['id'] = $response->results->id; 
  1369 		if ($row -> auth_expired) {
   140 	update_option(WIDGET_NAME_INTERNAL, $options);
  1370 			$auth_error_class = 'class="networkpublisher_auth_error"';
   141 	return TRUE;	
  1371 			$auth_error_image = '<img alt="' . __('Authorization provided to LinksAlpha.com on this account has expired. Please Add the Account again to be able to publish content') . '" title="' . __('Authorization provided to LinksAlpha.com on this account has expired. Please Add the Account again to be able to publish content') . '" src="' . NETWORKPUB_WP_PLUGIN_URL . 'alert.png" style="vertical-align:text-bottom;" />&nbsp;';
   142 }
  1372 		} else {
   143 
  1373 			$auth_error_class = '';
   144 function networkpub_load() {
  1374 			$auth_error_image = '';
   145 	$options = get_option(WIDGET_NAME_INTERNAL);
  1375 		}
   146 	if (empty($options['api_key'])) {
  1376 		$html .= '<tr id="r_key_' . $row -> api_key . '">';
   147 		$html = '<div>You have not added any API Key</div>';
  1377 		if ($i % 2) {
   148 		return $html;
  1378 			$html .= '<td ' . $auth_error_class . '>';
   149 	}
  1379 		} else {
   150 	$link = 'http://www.linksalpha.com/a/networkpubget?key='.$options['api_key'];
  1380 			$html .= '<td ' . $auth_error_class . ' style="background-color:#F7F7F7;">';
   151 	require_once(ABSPATH.WPINC.'/class-snoopy.php');
  1381 		}
   152 	$snoop = new Snoopy;
  1382 		$html .= $auth_error_image . '<a target="_blank" href="' . $row -> profile_url . '">' . $row -> name . '</a></td>';
   153 	$snoop->agent = WIDGET_NAME.' - '.get_option('siteurl');
  1383 		if ($i % 2) {
   154 	$response = '';
  1384 			$html .= '<td ' . $auth_error_class . ' style="text-align:center;">';
   155 	if($snoop->fetchtext($link)){
  1385 		} else {
   156 		if (strpos($snoop->response_code, '200')) {
  1386 			$html .= '<td ' . $auth_error_class . ' style="text-align:center;background-color:#F7F7F7;">';
   157 			$response_json = $snoop->results;
  1387 		}
   158 			$response = networkpub_json_decode($response_json);
  1388 		$html .= '<a href="http://www.linksalpha.com/a/networkpuboptions?api_key=' . $row -> api_key . '&id=' . $options['id_2'] . '&version=' . networkpub_version() . '&KeepThis=true&TB_iframe=true&height=465&width=650" title="Publish Options" class="thickbox" type="button" />' . __('Options') . '</a></td>';
   159 		}
  1389 		if ($i % 2) {
   160 	}
  1390 			$html .= '<td ' . $auth_error_class . ' style="text-align:center;">';
   161 	if (!$response) {
  1391 		} else {
   162 		$html = '<div>Error occured while trying to load the API Keys. Please try again later.</div>';
  1392 			$html .= '<td ' . $auth_error_class . ' style="text-align:center;background-color:#F7F7F7;">';
   163 		return $html;
  1393 		}
   164 	}
  1394 		$html .= '<a href="https://www.linksalpha.com/a/networkpublogs?api_key=' . $row -> api_key . '&id=' . $options['id_2'] . '&version=' . networkpub_version() . '&KeepThis=true&TB_iframe=true&height=400&width=920" title="Publish Result" class="thickbox" type="button" />' . __('Publish Results') . '</a></td>';
   165 	if($response->errorCode > 0) {
  1395 		if ($i % 2) {
   166 		$html = '<div>Error occured while trying to load the API Keys. Please try again later.</div>';
  1396 			$html .= '<td ' . $auth_error_class . ' style="text-align:center;">';
   167 		return $html;
  1397 		} else {
   168 	}
  1398 			$html .= '<td ' . $auth_error_class . ' style="text-align:center;background-color:#F7F7F7;">';
   169 	$html = '<div style="padding-bottom:10px;">You are currently Publishing your Blog to '.count($response->results).' Social Networks</div>';
  1399 		}
   170 	$html .= '<table class="networkpub_added"><tr><th>API Key</th><th>Network</th><th>Option</th></tr>';
  1400 		$html .= '<a href="#" id="key_' . $row -> api_key . '" class="networkpublisherremove">' . __('Remove') . '</a></td>';
   171 	foreach($response->results as $row) {
  1401 		$html .= '</tr>';
   172 		$html .= '<tr id="r_key_'.$row->api_key.'">';
  1402 		$i++;
   173 		switch($row->type) {
       
   174 			case 'twitter':
       
   175 				$html  .= '<td>'.$row->api_key.'</td><td>Twitter Account - <a target="_blank" href="http://twitter.com/'.$row->short_name.'">'.$row->name.'</a></td>';
       
   176 				break;
       
   177 			case 'fb_page':
       
   178 				$html  .= '<td>'.$row->api_key.'</td><td>Facebook Page - <a target="_blank" href="'.$row->page_url.'">'.$row->name.'</a></td>';
       
   179 				break;
       
   180 			case 'fb_wall':
       
   181 				$html  .= '<td>'.$row->api_key.'</td><td><a target="_blank" href="http://www.facebook.com/profile.php?id='.$row->id.'">'.$row->name.'</a></td>';
       
   182 				break;	
       
   183 			case 'myspace':
       
   184 				$html  .= '<td>'.$row->api_key.'</td><td>MySpace Account - <a target="_blank" href="'.$row->page_url.'">'.$row->name.'</a></td>';
       
   185 				break;	
       
   186 			case 'linkedin':
       
   187 				$html  .= '<td>'.$row->api_key.'</td><td>LinkedIn Account - <a target="_blank" href="'.$row->page_url.'">'.$row->name.'</a></td>';
       
   188 				break;
       
   189 			case 'yammer':
       
   190 				$html  .= '<td>'.$row->api_key.'</td><td>Yammer Account - <a target="_blank" href="'.$row->page_url.'">'.$row->name.'</a></td>';
       
   191 				break;	
       
   192 		}
       
   193 		$html .= '<td><a href="#" id="key_'.$row->api_key.'" class="networkpubre">Remove</a></td></tr>';
       
   194 	}
  1403 	}
   195 	$html .= '</table>';
  1404 	$html .= '</table>';
   196 	return $html;
  1405 	return $html;
   197 }
  1406 }
   198 
  1407 
       
  1408 function networkpub_post_types() {
       
  1409 	$options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
       
  1410 	if (empty($options['networkpub_post_types'])) {
       
  1411 		$post_types_in_options = array();
       
  1412 	} else {
       
  1413 		$post_types_in_options = explode(',', $options['networkpub_post_types']);
       
  1414 	}
       
  1415 	if (!function_exists('get_post_types')) {
       
  1416 		return;
       
  1417 	}
       
  1418 	$html = '';
       
  1419 	$args = array('public' => true, '_builtin' => false);
       
  1420 	$output = 'names';
       
  1421 	$operator = 'and';
       
  1422 	$post_types = get_post_types($args, $output, $operator);
       
  1423 	array_unshift($post_types, 'post', 'page');
       
  1424 	foreach ($post_types as $post_type) {
       
  1425 		$checked = '';
       
  1426 		if (in_array($post_type, $post_types_in_options)) {
       
  1427 			$checked = 'checked';
       
  1428 		}
       
  1429 		$html .= '<div style="padding-bottom:2px;"><input id="networkpub_post_type_' . $post_type . '" type="checkbox" value="' . $post_type . '" name="networkpub_post_types[]" ' . $checked . ' />&nbsp;<label for="networkpub_post_type_' . $post_type . '" >' . $post_type . '</label></div>';
       
  1430 	}
       
  1431 	return $html;
       
  1432 }
       
  1433 
   199 function networkpub_remove() {
  1434 function networkpub_remove() {
   200 	$options = get_option(WIDGET_NAME_INTERNAL);
  1435 	$options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
   201 	if (!empty($_POST['key'])) {
  1436 	if (!empty($_POST['networkpub_key'])) {
   202 		$key_full = $_POST['key'];
  1437 		$key_full = strip_tags($_POST['networkpub_key']);
   203 		$key_only = substr($key_full, 4);
  1438 		$key_only = substr($key_full, 4);
       
  1439 		$link = 'http://www.linksalpha.com/a/networkpubremove';
       
  1440 		$body = array('id' => $options['id_2'], 'key' => $key_only);
       
  1441 		$response_full = networkpub_http_post($link, $body);
       
  1442 		$response_code = $response_full[0];
       
  1443 		if ($response_code != 200) {
       
  1444 			$errdesc = networkpubnw_error_msgs($response_full[1]);
       
  1445 			echo $errdesc;
       
  1446 			return;
       
  1447 		}
   204 		$api_key = $options['api_key'];
  1448 		$api_key = $options['api_key'];
   205 		$api_key_array = explode(',', $api_key);
  1449 		$api_key_array = explode(',', $api_key);
   206 		$loc = array_search($key_only, $api_key_array);
  1450 		$loc = array_search($key_only, $api_key_array);
   207 		if($loc !== FALSE) {
  1451 		if ($loc !== FALSE) {
   208 			unset($api_key_array[$loc]);
  1452 			unset($api_key_array[$loc]);
   209 		}
  1453 		}
   210 		$api_key = implode(",", $api_key_array);
  1454 		$api_key = implode(",", $api_key_array);
   211 		$options['api_key'] = $api_key;
  1455 		$options['api_key'] = $api_key;
   212 		update_option(WIDGET_NAME_INTERNAL, $options);
  1456 		update_option(NETWORKPUB_WIDGET_NAME_INTERNAL, $options);
   213 		$link = 'http://www.linksalpha.com/a/networkpubremove?id='.$options['id'].'&key='.$key_only;
       
   214 		require_once(ABSPATH.WPINC.'/class-snoopy.php');
       
   215 		$snoop = new Snoopy;
       
   216 		$snoop->agent = WIDGET_NAME.' - '.get_option('siteurl');
       
   217 		$response = '';
       
   218 		$snoop->fetchtext($link);	
       
   219 		echo $key_full;
  1457 		echo $key_full;
   220 		return;
  1458 		return;
   221 	}
  1459 	}
       
  1460 }
       
  1461 
       
  1462 function networkpub_update_option($option, $value) {
       
  1463 	$options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
       
  1464 	$options[$option] = $value;
       
  1465 	update_option(NETWORKPUB_WIDGET_NAME_INTERNAL, $options);
       
  1466 	return;
       
  1467 }
       
  1468 
       
  1469 function networkpub_pages() {
       
  1470 	if (function_exists('add_submenu_page')) {
       
  1471 		$page = add_submenu_page('plugins.php', NETWORKPUB_WIDGET_NAME, NETWORKPUB_WIDGET_NAME, 'manage_options', NETWORKPUB_WIDGET_NAME_INTERNAL, 'networkpub_conf');
       
  1472 		if (is_admin()) {
       
  1473 			$page = add_submenu_page('edit.php', NETWORKPUB_WIDGET_NAME_POSTBOX, NETWORKPUB_WIDGET_NAME_POSTBOX, 'manage_options', NETWORKPUB_WIDGET_NAME_POSTBOX_INTERNAL, 'networkpub_postbox');
       
  1474 		}
       
  1475 	}
       
  1476 }
       
  1477 
       
  1478 function networkpub_postbox() {
       
  1479 	$html = '<div class="wrap"><div class="icon32" id="networkpubisher_laicon"><br /></div><h2>' . NETWORKPUB_WIDGET_NAME . ' - ' . NETWORKPUB_WIDGET_NAME_POSTBOX . '</h2></div>';
       
  1480 	$html .= '<iframe id="networkpub_postbox" src="http://www.linksalpha.com/post?source=wordpress&netpublink=' . urlencode(NETWORKPUB_WP_PLUGIN_URL) . '&sourcelink=' . urlencode(networkpub_postbox_url()) . '#' . urlencode(networkpub_postbox_url()) . '" width="1050px;" height="650px;" scrolling="no" style="background-color: transparent; border:none !important;" allowTransparency="allowTransparency" frameBorder="0"></iframe>';
       
  1481 	$html .= '<div style="padding:10px 10px 6px 10px;background-color:#FFFFFF;margin-bottom:15px;margin-top:0px;border:1px solid #F0F0F0;width:1005px;">
       
  1482 				<div style="width:130px;float:left;font-weight:bold;">
       
  1483 					' . __('Share this Plugin') . '
       
  1484 				</div>
       
  1485 				<div style="width:700px">
       
  1486 					<div class="linksalpha-email-button" id="linksalpha_tag_20886785813" data-url="http://www.linksalpha.com" data-text="LinksAlpha - Making Social Media Easy!" data-desc="LinksAlpha provides quick and easy way for companies and users to connect and share on social web. Using LinksAlpha tools, you can integrate Social Media Buttons into your website, Publish your Website Content Automatically to Social Media Sites, and Track Social Media Profiles, all from one place." data-image="http://www.linksalpha.com/images/LALOGO_s175.png"></div>
       
  1487 					<script type="text/javascript" src="http://www.linksalpha.com/social/loader?tag_id=linksalpha_tag_20886785813&fblikefont=arial&vkontakte=1&livejournal=1&twitter=1&xinglang=de&linkedin=1&tumblr=1&hyves=1&fblikelang=en_US&delicious=1&twitterw=110&gpluslang=en-US&gmail=1&weibo=1&posterous=1&xing=1&sonico=1&twitterlang=en&pinterest=1&myspace=1&msn=1&print=1&mailru=1&email=1&counters=googleplus%2Cfacebook%2Clinkedin%2Ctwitter&reddit=1&hotmail=1&netlog=1&twitterrelated=linksalpha&aolmail=1&link=http%3A%2F%2Fwww.linksalpha.com&diigo=1&evernote=1&digg=1&yahoomail=1&yammer=1&stumbleupon=1&instapaper=1&facebookw=90&googleplus=1&fblikeverb=like&fblikeref=linksalpha&halign=left&readitlater=1&v=2&facebook=1&button=googleplus%2Cfacebook%2Clinkedin%2Ctwitter&identica=1"></script>
       
  1488 				</div>
       
  1489 			  </div>';
       
  1490 	echo $html;
       
  1491 	return;
       
  1492 }
       
  1493 
       
  1494 function networkpub_supported_networks() {
       
  1495 	$html = '';
       
  1496 	$response_full = networkpub_http('http://www.linksalpha.com/a/networkpubsupported');
       
  1497 	$response_code = $response_full[0];
       
  1498 	if ($response_code != 200) {
       
  1499 		return $html;
       
  1500 	}
       
  1501 	$response = $response_full[1];
       
  1502 	$content = networkpub_json_decode($response);
       
  1503 	if (!$content) {
       
  1504 		return $html;
       
  1505 	}
       
  1506 	$html .= '<ul style="bullet-style:none ! important;">';
       
  1507 	$i = 0;
       
  1508 	foreach ($content as $key => $val) {
       
  1509 		if ($i % 2) {
       
  1510 			$bg_color = "#FFFFFF";
       
  1511 		} else {
       
  1512 			$bg_color = "#F7F7F7";
       
  1513 		}
       
  1514 		$html .= '<li style="padding:5px 10px;background-color:' . $bg_color . ';margin:0px;"><a href="https://www.linksalpha.com/networks?tab=' . $val -> type . '" target="_blank" style="text-decoration:none ! important;"><img src="http://www.linksalpha.com/images/' . $val -> type . '_icon.png" style="vertical-align:bottom;border:0px;" />&nbsp;' . $val -> name . '</a></li>';
       
  1515 		$i++;
       
  1516 	}
       
  1517 	$html .= '</ul>';
       
  1518 	return $html;
   222 }
  1519 }
   223 
  1520 
   224 function networkpub_json_decode($str) {
  1521 function networkpub_json_decode($str) {
   225 	if (function_exists("json_decode")) {
  1522 	if (function_exists("json_decode")) {
   226 	    return json_decode($str);
  1523 		return json_decode($str);
   227 	} else {
  1524 	} else {
   228 		if (!class_exists('Services_JSON')) {
  1525 		if (!class_exists('Services_JSON')) {
   229 			require_once("JSON.php");
  1526 			require_once ("JSON.php");
   230 		}
  1527 		}
   231 	    $json = new Services_JSON();
  1528 		$json = new Services_JSON();
   232 	    return $json->decode($str);
  1529 		return $json -> decode($str);
   233 	}
  1530 	}
   234 }
  1531 }
   235 
  1532 
       
  1533 function networkpub_http($link) {
       
  1534 	if (!$link) {
       
  1535 		return array(500, 'invalid url');
       
  1536 	}
       
  1537 	if (!class_exists('WP_Http')) {
       
  1538 		include_once (ABSPATH . WPINC . '/class-http.php');
       
  1539 	}
       
  1540 	if (class_exists('WP_Http')) {
       
  1541 		$request = new WP_Http;
       
  1542 		$headers = array('Agent' => NETWORKPUB_WIDGET_NAME . ' - ' . get_bloginfo('url'));
       
  1543 		$response_full = $request -> request($link, array('method' => 'GET', 'headers' => $headers, 'timeout' => 60));
       
  1544 		if (isset($response_full -> errors)) {
       
  1545 			return array(500, 'internal error');
       
  1546 		}
       
  1547 		if (!is_array($response_full['response'])) {
       
  1548 			return array(500, 'internal error');
       
  1549 		}
       
  1550 		$response_code = $response_full['response']['code'];
       
  1551 		if ($response_code == 200) {
       
  1552 			$response = $response_full['body'];
       
  1553 			return array($response_code, $response);
       
  1554 		}
       
  1555 		$response_msg = $response_full['response']['message'];
       
  1556 		return array($response_code, $response_msg);
       
  1557 	}
       
  1558 	require_once (ABSPATH . WPINC . '/class-snoopy.php');
       
  1559 	$snoop = new Snoopy;
       
  1560 	$snoop -> agent = NETWORKPUB_WIDGET_NAME . ' - ' . get_bloginfo('url');
       
  1561 	if ($snoop -> fetchtext($link)) {
       
  1562 		if (strpos($snoop -> response_code, '200')) {
       
  1563 			$response = $snoop -> results;
       
  1564 			return array(200, $response);
       
  1565 		}
       
  1566 	}
       
  1567 	return array(500, 'internal error');
       
  1568 }
       
  1569 
       
  1570 function networkpub_http_post($link, $body) {
       
  1571 	if (!$link) {
       
  1572 		return array(500, 'invalid url');
       
  1573 	}
       
  1574 	if (!class_exists('WP_Http')) {
       
  1575 		include_once (ABSPATH . WPINC . '/class-http.php');
       
  1576 	}
       
  1577 	if (class_exists('WP_Http')) {
       
  1578 		$request = new WP_Http;
       
  1579 		$headers = array('Agent' => NETWORKPUB_WIDGET_NAME . ' - ' . get_bloginfo('url'));
       
  1580 		$response_full = $request -> request($link, array('method' => 'POST', 'body' => $body, 'headers' => $headers, 'timeout' => 60));
       
  1581 		if (isset($response_full -> errors)) {
       
  1582 			return array(500, 'internal error');
       
  1583 		}
       
  1584 		if (!is_array($response_full['response'])) {
       
  1585 			return array(500, 'internal error');
       
  1586 		}
       
  1587 		$response_code = $response_full['response']['code'];
       
  1588 		if ($response_code == 200) {
       
  1589 			$response = $response_full['body'];
       
  1590 			return array($response_code, $response);
       
  1591 		}
       
  1592 		$response_msg = $response_full['response']['message'];
       
  1593 		return array($response_code, $response_msg);
       
  1594 	}
       
  1595 
       
  1596 	// If no WP_HTTP found, fall back on snoopy.php for making HTTP request
       
  1597 	require_once (ABSPATH . WPINC . '/class-snoopy.php');
       
  1598 	$snoop = new Snoopy;
       
  1599 	$snoop -> agent = NETWORKPUB_WIDGET_NAME . ' - ' . get_bloginfo('url');
       
  1600 	if ($snoop -> submit($link, $body)) {
       
  1601 		if (strpos($snoop -> response_code, '200')) {
       
  1602 			$response = $snoop -> results;
       
  1603 			return array(200, $response);
       
  1604 		}
       
  1605 	}
       
  1606 	return array(500, 'internal error');
       
  1607 }
       
  1608 
       
  1609 function networkpub_error_msgs($errMsg, $errorDetail='') {
       
  1610 	$arr_errCodes = explode(";", $errMsg);
       
  1611 	$errCodesCount = count($arr_errCodes);
       
  1612 	switch (trim($arr_errCodes[0])) {
       
  1613 		case 'internal error' :
       
  1614 			$html = '<div class="updated fade wrap networkpub_msg">
       
  1615                         <div class="networkpublisher_msg_error_header"><b><img src="' . NETWORKPUB_WP_PLUGIN_URL . 'alert.png" style="vertical-align:text-bottom;" />&nbsp;' . __('Unknown Error') . '</b></div>
       
  1616                         <div>' . __('There was an unknown error. Please try again') . '.</div>
       
  1617 					    <div>' . __('If you still face issues, please open a ticket at: ') . '<a target="_blank" href="http://support.linksalpha.com/">' . __('LinksAlpha.com Help Desk') . '</a></div>
       
  1618                     </div>';
       
  1619 			return $html;
       
  1620 			break;
       
  1621 		case 'invalid url' :
       
  1622 			$html = '<div class="updated fade wrap networkpub_msg"><b>' . __('Your blog URL is invalid') . ':</b>' . $arr_errCodes[$errCodesCount - 1];
       
  1623 			if ($errCodesCount == 3) {
       
  1624 				$html .= '.&nbsp;' . __('Error Code') . '&nbsp;=' . $arr_errCodes[$errCodesCount - 2];
       
  1625 			}
       
  1626 			$html .= '<div>
       
  1627 					' . __('You can also') . '&nbsp;<a href="http://www.linksalpha.com/websites?show_add=1" target="_blank">' . __('Click here') . '</a>' . __(' to enter blog URL on LinksAlpha manually.
       
  1628 					  Also ensure that in ') . '<b>' . __('Settings') . '->' . __('General') . '->"' . __('Blog address (URL)') . '"</b> ' . __('the URL is filled-in correctly') . '.</div>
       
  1629 					  <div>' . __('If you still face issues then email us at') . '&nbsp;<a href="mailto:post@linksalpha.com">post@linksalpha.com</a>&nbsp;' . __('with error description') . '.</div>';
       
  1630 			return $html;
       
  1631 			break;
       
  1632 		case 'localhost url' :
       
  1633 			$html = '
       
  1634 			<div class="updated fade wrap networkpub_msg" style="padding:10px;"">
       
  1635 			<div style="color:red;font-weight:bold;">
       
  1636 				<img src="" . NETWORKPUB_WP_PLUGIN_URL . "alert.png" style="vertical-align:text-bottom;" />&nbsp;" . __("Network Publisher Authorization Error") . "
       
  1637 			</div>
       
  1638 			<div style="padding-top:0px;">
       
  1639 				        <div>' . __('If you still face issues, please open a ticket at: ') . '<a target="_blank" href="http://support.linksalpha.com/">LinksAlpha.com ' . __('Help Desk') . '</a></div>
       
  1640 			</div>
       
  1641 		</div>
       
  1642 
       
  1643 			<div class="updated fade wrap networkpub_msg"><div><b>' . __('Website/Blog inaccessible') . '</b></div>';
       
  1644 			$html .= '<div>' . __('You are trying to use the plugin on ') . '<b>localhost</b> ' . __('or behind a') . ' <b>' . __('firewall') . '</b>, ' . __('which is not supported. Please install the plugin on a Wordpress blog on a live server') . '.</div>
       
  1645 				  </div>';
       
  1646 			return $html;
       
  1647 			break;
       
  1648 		case 'remote url error' :
       
  1649 			$html = '<div class="updated fade wrap networkpub_msg"><div><b>' . __('Remote URL error') . ': </b>' . $arr_errCodes[$errCodesCount - 1];
       
  1650 			if ($errCodesCount == 3) {
       
  1651 				$html .= '. ' . __('Error Code') . '&nbsp;=' . $arr_errCodes[$errCodesCount - 2];
       
  1652 			}
       
  1653 			$html .= '</div>
       
  1654 					<div>
       
  1655 						<b>' . __('Description:') . '</b>
       
  1656 						<b>' . __('Please try again') . '. </b> ' . __('Your site either did not respond (it is extremely slow) or it is not operational') . '.
       
  1657 					</div>
       
  1658 					<div>
       
  1659 						' . __('You can also') . ' <a href="http://www.linksalpha.com/websites?show_add=1" target="_blank">' . __('Click here') . '</a> ' . __('to enter blog URL on LinksAlpha manually') . '.
       
  1660 						' . __('Also ensure that in') . ' <b>' . __('Settings') . '->' . __('General') . '->"' . __('Blog address (URL)') . '"</b> ' . __('the URL is filled-in correctly') . '.
       
  1661 					</div>
       
  1662 					<div>' . __('If you still face issues, please open a ticket at: ') . '<a target="_blank" href="http://support.linksalpha.com/">LinksAlpha.com ' . __('Help Desk') . '</a></div>
       
  1663 				</div>';
       
  1664 			return $html;
       
  1665 			break;
       
  1666 		case 'feed parsing error' :
       
  1667 			$html = '<div class="updated fade wrap networkpub_msg"><div><b>' . __('Feed parsing error') . ': </b>' . $arr_errCodes[$errCodesCount - 1];
       
  1668 			if ($errCodesCount == 3) {
       
  1669 				$html .= '. ' . __('Error Code') . '=&nbsp;' . $arr_errCodes[$errCodesCount - 2];
       
  1670 			}
       
  1671 			$html .= '	</div>
       
  1672 					<div>
       
  1673 						<b>' . __('Description') . ': </b>
       
  1674 						' . __('Your RSS feed has errors. Pls go to') . ' <a href=http://beta.feedvalidator.org/ target="_blank">href=http://beta.feedvalidator.org/</a> ' . __('to validate your RSS feed') . '.
       
  1675 					</div>
       
  1676                     <div>' . __('If you still face issues, please open a ticket at: ') . '<a target="_blank" href="http://support.linksalpha.com/">LinksAlpha.com ' . __('Help Desk') . '</a></div>
       
  1677 				</div>';
       
  1678 			return $html;
       
  1679 			break;
       
  1680 		case 'feed not found' :
       
  1681 			$html = '<div class="updated fade wrap networkpub_msg">
       
  1682 					<div>
       
  1683 						<b>' . __('We could not find feed URL for your blog') . '.</b>
       
  1684 					</div>
       
  1685 					<div>
       
  1686 						<a href="http://www.linksalpha.com/websites?show_add=1" target="_blank">' . __('Click here') . '</a> ' . __('to enter feed URL on LinksAlpha manually') . '.
       
  1687 						' . __('Also ensure that in ') . '<b>' . __('Settings') . '->' . __('General') . '->"' . __('Blog address (URL)') . '"</b> ' . __('the URL is filled-in correctly') . '.
       
  1688 					</div>
       
  1689 					<div>' . __('If you still face issues, please open a ticket at: ') . '<a target="_blank" href="http://support.linksalpha.com/">LinksAlpha.com ' . __('Help Desk') . '</a></div>
       
  1690 				</div>';
       
  1691 			return $html;
       
  1692 			break;
       
  1693 		case 'invalid key' :
       
  1694 			$html = '<div class="updated fade wrap networkpub_msg">
       
  1695                         <div class="networkpublisher_msg_error_header"><b><img src="' . NETWORKPUB_WP_PLUGIN_URL . 'alert.png" style="vertical-align:text-bottom;" />&nbsp;Invalid Key</b></div>
       
  1696                         <div>' . __('The key that you entered is incorrect. Please input a valid <a target="_blank" href="http://www.linksalpha.com/account/your_api_key">User</a> or <a target="_blank" href="http://www.linksalpha.com/networks">Network</a> API key and try again') . '.</div>
       
  1697                         <div>' . __('If you still face issues, please open a ticket at: ') . '<a target="_blank" href="http://support.linksalpha.com/">LinksAlpha.com ' . __('Help Desk') . '</a></div>
       
  1698                     </div>';
       
  1699 			return $html;
       
  1700 			break;
       
  1701 		case 'network key' :
       
  1702 			$html = '<div class="updated fade wrap networkpub_msg_center">
       
  1703 					<div>
       
  1704 						<img src="' . NETWORKPUB_WP_PLUGIN_URL . 'alert.png" style="vertical-align:text-bottom;" />&nbsp;' . __('Invalid Key') . ':&nbsp;' . __('Please make sure you enter the ') . '<a target="_blank" href="http://www.linksalpha.com/account/your_api_key">' . __('User API key') . '</a>' . __(', and not the key of a Network') . '.
       
  1705 					</div>
       
  1706 				</div>';
       
  1707 			return $html;
       
  1708 			break;
       
  1709 		case 'subscription upgrade required':
       
  1710 			if($errorDetail) {
       
  1711 				$html = '<div class="updated fade wrap networkpub_msg_center">
       
  1712 							<img src="' . NETWORKPUB_WP_PLUGIN_URL . 'alert.png" style="vertical-align:text-bottom;" />&nbsp;<b>' . __('Upgrade account') . '.</b> ' . $errorDetail . '
       
  1713 						</div>';
       
  1714 				return $html;	
       
  1715 			} else {
       
  1716 				$html = '<div class="updated fade wrap networkpub_msg_center">
       
  1717 							<img src="' . NETWORKPUB_WP_PLUGIN_URL . 'alert.png" style="vertical-align:text-bottom;" />&nbsp;<b>' . __('Upgrade account') . '.</b> ' . __('Please') . ' <a href="http://www.linksalpha.com/account" target="_blank">' . __('upgrade your subscription') . '</a> ' . __('to continue using current number of networks and websites') . '.
       
  1718 						</div>';
       
  1719 				return $html;	
       
  1720 			}
       
  1721 			break;
       
  1722 		case 'multiple accounts' :
       
  1723 			$html = '
       
  1724 			<div class="updated fade wrap networkpub_msg">
       
  1725                         <div class="networkpublisher_msg_error_header"><b><img src="' . NETWORKPUB_WP_PLUGIN_URL . 'alert.png" style="vertical-align:text-bottom;" />&nbsp;' . __('Account Error') . '</b></div>
       
  1726                         <div>' . __('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 <a target="_blank" href="http://www.linksalpha.com/account/your_api_key">User</a> or <a target="_blank" href="http://www.linksalpha.com/networks">Network</a> API key and try again') . '.</div>
       
  1727                         <div>' . __('If you still face issues, please open a ticket at: ') . '<a target="_blank" href="http://support.linksalpha.com/">LinksAlpha.com ' . __('Help Desk') . '</a></div>
       
  1728                     </div>
       
  1729 			';
       
  1730 			return $html;
       
  1731 			break;
       
  1732 		case 'no networks' :
       
  1733 			$html = '<div class="updated fade wrap networkpub_msg">
       
  1734                         <div class="networkpublisher_msg_error_header"><b><img src="' . NETWORKPUB_WP_PLUGIN_URL . 'alert.png" style="vertical-align:text-bottom;" />&nbsp;' . __('No Network Accounts Found') . '</b></div>
       
  1735                         <div>' . __('You should first authorize LinksAlpha to publish to your social network profiles') . ' <a target="_blank" href="http://www.linksalpha.com/networks">' . __('Click Here') . '</a> ' . __('to get started.') . '</div>
       
  1736                         <div>' . __('If you still face issues, please open a ticket at: ') . '<a target="_blank" href="http://support.linksalpha.com/">LinksAlpha.com ' . __('Help Desk') . '</a></div>
       
  1737                     </div>';
       
  1738 			return $html;
       
  1739 			break;
       
  1740 		default :
       
  1741 			$html = '<div class="updated fade wrap networkpub_msg">
       
  1742 						<div class="networkpublisher_msg_error_header"><b><img src="' . NETWORKPUB_WP_PLUGIN_URL . 'alert.png" style="vertical-align:text-bottom;" />&nbsp;' . __('Not able to connect to') . ' <a href="http://www.linksalpha.com" target="_blank">' . __('LinksAlpha.com') . '</a></b></div>
       
  1743 						<div style="text-align:left;">
       
  1744 							<div class="networkpublisher_msg_error_item">' . __('Your website is not able to connect to LinksAlpha.com. This might be due to:') . '</div>
       
  1745 							<div>
       
  1746 								<ul class="networkpublisher_msg_error_list">
       
  1747 									<li class="networkpublisher_msg_error_item">' . __('An issue with your hosting company where they might be preventing HTTP calls to external sites.') . '</li>
       
  1748 									<li class="networkpublisher_msg_error_item">' . __('A plugin you are using has overwritten the .htaccess preventing access to external websites') . '</li>
       
  1749 								</ul>
       
  1750 							</div>
       
  1751 							<div class="networkpublisher_msg_error_item">' . __('As an alternative you can configure publishing as described in Method-2 of the -') . ' <a href="http://help.linksalpha.com/networks/getting-started" target="_blank">' . __('Getting Started help document.') . '</a></div>
       
  1752 						</div>
       
  1753 					</div>';
       
  1754 			return $html;
       
  1755 			break;
       
  1756 	}
       
  1757 }
       
  1758 
       
  1759 function networkpub_get_plugin_dir() {
       
  1760 
       
  1761 	global $wp_version;
       
  1762 	if (version_compare($wp_version, '2.8', '<')) {
       
  1763 		$path = dirname(plugin_basename(__FILE__));
       
  1764 		if ($path == '.')
       
  1765 			$path = '';
       
  1766 		$plugin_path = trailingslashit(plugins_url($path));
       
  1767 	} else {
       
  1768 		$plugin_path = trailingslashit(plugins_url('', __FILE__));
       
  1769 	}
       
  1770 	return $plugin_path;
       
  1771 }
       
  1772 
       
  1773 function networkpub_activate() {
       
  1774 	$networkpub_eget = get_bloginfo('admin_email');
       
  1775 	$networkpub_uget = get_bloginfo('url');
       
  1776 	$networkpub_nget = get_bloginfo('name');
       
  1777 	$networkpub_dget = get_bloginfo('description');
       
  1778 	$networkpub_cget = get_bloginfo('charset');
       
  1779 	$networkpub_vget = get_bloginfo('version');
       
  1780 	$networkpub_lget = get_bloginfo('language');
       
  1781 	$link = 'http://www.linksalpha.com/a/bloginfo';
       
  1782 	$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);
       
  1783 	networkpub_http_post($link, $networkpub_bloginfo);
       
  1784 	$options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
       
  1785 	if (empty($options['id_2']) or empty($options['api_key'])) {
       
  1786 		return;
       
  1787 	}
       
  1788 	$link = 'http://www.linksalpha.com/a/networkpubconvertdirect';
       
  1789 	$params = array('id' => $options['id_2'], 'key' => $options['api_key'], 'plugin' => NETWORKPUB_WIDGET_NAME_INTERNAL_NW, );
       
  1790 	$response_full = networkpub_http_post($link, $params);
       
  1791 	$response_code = $response_full[0];
       
  1792 	return;
       
  1793 }
       
  1794 
       
  1795 function networkpub_deactivate() {
       
  1796 	$options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
       
  1797 	if (empty($options['id_2']) or empty($options['api_key'])) {
       
  1798 		return;
       
  1799 	}
       
  1800 	// Build Params
       
  1801 	$link = 'http://www.linksalpha.com/a/networkpubconvertfeed';
       
  1802 	$params = array('id' => $options['id_2'], 'key' => $options['api_key'], );
       
  1803 	//HTTP Call
       
  1804 	$response_full = networkpub_http_post($link, $params);
       
  1805 	$response_code = $response_full[0];
       
  1806 	return;
       
  1807 }
       
  1808 
       
  1809 function networkpub_pushpresscheck() {
       
  1810 	$active_plugins = get_option('active_plugins');
       
  1811 	$pushpress_plugin = 'pushpress/pushpress.php';
       
  1812 	$this_plugin_key = array_search($pushpress_plugin, $active_plugins);
       
  1813 	if ($this_plugin_key) {
       
  1814 		$options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
       
  1815 		if (array_key_exists('id', $options)) {
       
  1816 			if (!empty($options['id_2'])) {
       
  1817 				$link = 'http://www.linksalpha.com/a/pushpress';
       
  1818 				$body = array('id' => $options['id_2']);
       
  1819 				$response_full = networkpub_http_post($link, $body);
       
  1820 				$response_code = $response_full[0];
       
  1821 			}
       
  1822 		}
       
  1823 	}
       
  1824 }
       
  1825 
       
  1826 function networkpub_postbox_url() {
       
  1827 	global $wp_version;
       
  1828 	if (version_compare($wp_version, '3.0.0', '<')) {
       
  1829 		$admin_url = site_url() . '/wp-admin/edit.php?page=' . NETWORKPUB_WIDGET_NAME_POSTBOX_INTERNAL;
       
  1830 	} else {
       
  1831 		$admin_url = site_url() . '/wp-admin/edit.php?page=' . NETWORKPUB_WIDGET_NAME_POSTBOX_INTERNAL;
       
  1832 	}
       
  1833 	return $admin_url;
       
  1834 }
       
  1835 
       
  1836 function networkpub_version() {
       
  1837 	return NETWORKPUB_PLUGIN_VERSION;
       
  1838 }
       
  1839 
       
  1840 function networkpub_get_posts() {
       
  1841 	if (!empty($_GET['linksalpha_request_type'])) {
       
  1842 		$args = array('numberposts' => 20, 'offset' => 0, 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => 'post', 'post_status' => 'publish');
       
  1843 		$posts_array = get_posts($args);
       
  1844 		$html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>';
       
  1845 		$html .= '<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>';
       
  1846 		$html .= '<script type="text/javascript" src="' . NETWORKPUB_WP_PLUGIN_URL . 'jquery.ba-postmessage.min.js"></script>';
       
  1847 		$html .= '<script type="text/javascript" src="' . NETWORKPUB_WP_PLUGIN_URL . 'networkpub.js"></script>';
       
  1848 		$html .= '</head><body style="margin:0 !important;padding:0 !important;">';
       
  1849 		$html .= '<select style="margin:0 !important;padding:0 !important;width:300px !important;" id="site_links" name="site_links" class="post_network" >';
       
  1850 		$html .= '<option class="post_network" value="" selected >---</option>';
       
  1851 		foreach ($posts_array as $post) {
       
  1852 			$params = array();
       
  1853 			$post_link = get_permalink($post->ID);
       
  1854 			$params['content_link'] = $post_link;
       
  1855 			$params['title'] = trim(strip_tags($post -> post_title));
       
  1856 			$params['content_text'] = trim(strip_tags($post -> post_title));
       
  1857 			$params['content_body'] = trim(strip_tags($post -> post_content));
       
  1858 			$post_image = networkpub_thumbnail_link($post_id, $post -> post_content);
       
  1859 			if ($post_image) {
       
  1860 				$params['content_image'] = $post_image;
       
  1861 			}
       
  1862 			$form_data = http_build_query($params);
       
  1863 			$html .= '<option class="post_network" value="' . $form_data . '">' . $post -> post_title . '</option>';
       
  1864 		}
       
  1865 		$html .= '</select></body></html>';
       
  1866 		echo $html;
       
  1867 	}
       
  1868 	return;
       
  1869 }
       
  1870 
       
  1871 function networkpub_fb_langs() {
       
  1872 	$langs = array();
       
  1873 	$response_full = networkpub_http_post("http://www.facebook.com/translations/FacebookLocales.xml", array());
       
  1874 	$response_code = $response_full[0];
       
  1875 	if ($response_code == 200) {
       
  1876 		preg_match_all('/<locale>\s*<englishName>([^<]+)<\/englishName>\s*<codes>\s*<code>\s*<standard>.+?<representation>([^<]+)<\/representation>/s', utf8_decode($response_full[1]), $langslist, PREG_PATTERN_ORDER);
       
  1877 		foreach ($langslist[1] as $key => $val) {
       
  1878 			$langs[$langslist[2][$key]] = $val;
       
  1879 		}
       
  1880 	} else {
       
  1881 		$langs['default'] = "Default";
       
  1882 	}
       
  1883 	return $langs;
       
  1884 }
       
  1885 
       
  1886 function networkpub_add_metatags() {
       
  1887 	$options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
       
  1888 	if (!is_array($options)) {
       
  1889 		return;
       
  1890 	}
       
  1891 	if (!array_key_exists('networkpub_metatags_facebook', $options)) {
       
  1892 		return;
       
  1893 	}
       
  1894 	$networkpub_metatags_facebook = $options['networkpub_metatags_facebook'];
       
  1895 	$networkpub_metatags_googleplus = $options['networkpub_metatags_googleplus'];
       
  1896 	if (!$networkpub_metatags_facebook and !$networkpub_metatags_googleplus) {
       
  1897 		return;
       
  1898 	}
       
  1899 	global $posts;
       
  1900 	//Site name
       
  1901 	$og_site_name = get_bloginfo('name');
       
  1902 	//Set defaults for video types
       
  1903 	$og_video = '';
       
  1904 	$og_video_type = '';
       
  1905 	//Post or Page
       
  1906 	if (is_single() || is_page()) {
       
  1907 		//Post data
       
  1908 		$post_data = get_post($posts[0]->ID, ARRAY_A);
       
  1909 		//Title
       
  1910 		$og_title = networkpub_prepare_text($post_data['post_title']);
       
  1911 		//Link
       
  1912 		$og_link = get_permalink($posts[0]->ID);
       
  1913 		//Image or Video
       
  1914 		$networkpub_post_image_video = get_post_meta($posts[0]->ID, 'networkpub_post_image_video', true);
       
  1915 		if($networkpub_post_image_video == 'image') {
       
  1916 			$og_link_image = networkpub_thumbnail_link($posts[0]->ID, $post_data['post_content']);
       
  1917 		} else {
       
  1918 			$og_link_image = get_post_meta($posts[0]->ID, 'networkpub_video_picture', true);
       
  1919 			$og_video = get_post_meta($posts[0]->ID, 'networkpub_video_source', true);
       
  1920 			$og_video_type = "application/x-shockwave-flash";
       
  1921 		}
       
  1922 		//Content
       
  1923 		if (!empty($post_data['post_excerpt'])) {
       
  1924 			$og_desc = $post_data['post_excerpt'];
       
  1925 		} else {
       
  1926 			$og_desc = $post_data['post_content'];
       
  1927 		}
       
  1928 		$og_desc = networkpub_prepare_text($og_desc);
       
  1929 		//Facebook Page Type
       
  1930 		$post_ogtypefacebook = get_post_meta($posts[0]->ID, 'networkpub_ogtype_facebook', true);
       
  1931 		if ($post_ogtypefacebook) {
       
  1932 			$og_type = $post_ogtypefacebook;
       
  1933 		} else {
       
  1934 			if (!empty($options['networkpub_facebook_page_type']))	{
       
  1935 			 	$og_type = $options['networkpub_facebook_page_type'];
       
  1936 			} else {
       
  1937 			 	$og_type = 'article';
       
  1938 			}
       
  1939 		}
       
  1940 	} else {
       
  1941 		//Title
       
  1942 		$og_title = networkpub_prepare_text($og_site_name);
       
  1943 		//Link
       
  1944 		$og_link = get_bloginfo('url');
       
  1945 		//Image Link
       
  1946 		$og_link_image = '';
       
  1947 		//Desc
       
  1948 		$og_desc = get_bloginfo('description');
       
  1949 		$og_desc = networkpub_prepare_text($og_desc);
       
  1950 		//Type
       
  1951 		$og_type = 'website';
       
  1952 	}
       
  1953 	if (!empty($options['networkpub_lang_facebook'])) {
       
  1954 		$og_locale = $options['networkpub_lang_facebook'];
       
  1955 	} else {
       
  1956 		$og_locale = 'en_US';
       
  1957 	}
       
  1958 	if (!empty($options['networkpub_facebook_app_id'])) {
       
  1959 		$og_fb_app_id = $options['networkpub_facebook_app_id'];
       
  1960 	} else {
       
  1961 		$og_fb_app_id = '';
       
  1962 	}
       
  1963 	//Google Plus Page Type
       
  1964 	if (!empty($options['networkpub_googleplus_page_type'])) {
       
  1965 		$og_type_google = $options['networkpub_googleplus_page_type'];
       
  1966 	} else {
       
  1967 		$og_type_google = 'Article';
       
  1968 	}
       
  1969 	if ($networkpub_metatags_facebook) {
       
  1970 		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);
       
  1971 	}
       
  1972 	if ($networkpub_metatags_googleplus) {
       
  1973 		networkpub_build_meta_googleplus($og_title, $og_link_image, $og_desc, $og_type_google);
       
  1974 	}
       
  1975 	return;
       
  1976 }
       
  1977 
       
  1978 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) {
       
  1979 	$opengraph_meta = '';
       
  1980 	if ($og_site_name) {
       
  1981 		$opengraph_meta .= "\n<meta property=\"og:site_name\" content=\"" . $og_site_name . "\" />";
       
  1982 	}
       
  1983 	if ($og_title) {
       
  1984 		$opengraph_meta .= "\n<meta property=\"og:title\" content=\"" . $og_title . "\" />";
       
  1985 	}
       
  1986 	if ($og_link) {
       
  1987 		$opengraph_meta .= "\n<meta property=\"og:url\" content=\"" . $og_link . "\" />";
       
  1988 	}
       
  1989 	if ($og_link_image) {
       
  1990 		$opengraph_meta .= "\n<meta property=\"og:image\" content=\"" . $og_link_image . "\" />";
       
  1991 	}
       
  1992 	if ($og_video) {
       
  1993 		$opengraph_meta .= "\n<meta property=\"og:video\" content=\"" . $og_video . "\" />";
       
  1994 	}
       
  1995 	if ($og_video_type) {
       
  1996 		$opengraph_meta .= "\n<meta property=\"og:video:type\" content=\"" . $og_video_type . "\" />";
       
  1997 	}
       
  1998 	if ($og_desc) {
       
  1999 		$opengraph_meta .= "\n<meta property=\"og:description\" content=\"" . $og_desc . "\" />";
       
  2000 	}
       
  2001 	if ($og_type) {
       
  2002 		$opengraph_meta .= "\n<meta property=\"og:type\" content=\"" . $og_type . "\" />";
       
  2003 	}
       
  2004 	if ($og_locale) {
       
  2005 		$opengraph_meta .= "\n<meta property=\"og:locale\" content=\"" . strtolower($og_locale) . "\" />";
       
  2006 	}
       
  2007 	if ($og_fb_app_id) {
       
  2008 		$opengraph_meta .= "\n<meta property=\"fb:app_id\" content=\"" . trim($og_fb_app_id) . "\" />";
       
  2009 	}
       
  2010 	echo "\n<!-- Facebook Open Graph metatags added by WordPress plugin - Network Publisher. Get it at: http://wordpress.org/extend/plugins/network-publisher/ -->" . $opengraph_meta . "\n<!-- End Facebook Open Graph metatags-->\n";
       
  2011 }
       
  2012 
       
  2013 function networkpub_build_meta_googleplus($og_title, $og_link_image, $og_desc, $og_type) {
       
  2014 	$opengraph_meta = '';
       
  2015 	if ($og_title) {
       
  2016 		$opengraph_meta = "\n<meta itemprop=\"name\"  content=\"" . $og_title . "\" />";
       
  2017 	}
       
  2018 	if ($og_link_image) {
       
  2019 		$opengraph_meta .= "\n<meta itemprop=\"image\" content=\"" . $og_link_image . "\" />";
       
  2020 	}
       
  2021 	if ($og_desc) {
       
  2022 		$opengraph_meta .= "\n<meta itemprop=\"description\" content=\"" . $og_desc . "\" />";
       
  2023 	}
       
  2024 	if ($og_type) {
       
  2025 		$opengraph_meta .= "\n<meta itemprop=\"type\" content=\"" . $og_type . "\" />";
       
  2026 	}
       
  2027 	echo "\n<!-- Google Plus metatags added by WordPress plugin - Network Publisher. Get it at: http://wordpress.org/extend/plugins/network-publisher/ -->" . $opengraph_meta . "\n<!-- End Google Plus metatags-->\n";
       
  2028 }
       
  2029 
       
  2030 function networkpub_html_schema($attr) {
       
  2031 	$options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
       
  2032 	if (!is_array($options)) {
       
  2033 		return;
       
  2034 	}
       
  2035 	if (!array_key_exists('networkpub_metatags_facebook', $options)) {
       
  2036 		return;
       
  2037 	}
       
  2038 	$networkpub_metatags_facebook = $options['networkpub_metatags_facebook'];
       
  2039 	$networkpub_metatags_googleplus = $options['networkpub_metatags_googleplus'];
       
  2040 	if (!$networkpub_metatags_facebook and !$networkpub_metatags_googleplus) {
       
  2041 		return;
       
  2042 	}
       
  2043 	if ($networkpub_metatags_facebook) {
       
  2044 		$attr .= " xmlns:og=\"http://opengraphprotocol.org/schema/\"";
       
  2045 		$attr .= " xmlns:fb=\"http://www.facebook.com/2008/fbml\"";
       
  2046 	}
       
  2047 	if ($networkpub_metatags_googleplus) {
       
  2048 		$networkpub_googleplus_page_type = $options['networkpub_googleplus_page_type'];
       
  2049 		$attr .= " itemscope itemtype=\"http://schema.org/" . $networkpub_googleplus_page_type . "\"";
       
  2050 	}
       
  2051 	return $attr;
       
  2052 }
       
  2053 
       
  2054 function networkpub_prepare_text($text) {
       
  2055 	$text = stripslashes($text);
       
  2056 	$text = strip_tags($text);
       
  2057 	$text = preg_replace("/\[.*?\]/", '', $text);
       
  2058 	$text = preg_replace('/([\n \t\r]+)/', ' ', $text);
       
  2059 	$text = preg_replace('/( +)/', ' ', $text);
       
  2060 	$text = preg_replace('/\s\s+/', ' ', $text);
       
  2061 	$text = networkpub_prepare_string($text, 310);
       
  2062 	$text = networkpub_smart_truncate($text, 300);
       
  2063 	$text = trim($text);
       
  2064 	$text = htmlspecialchars($text);
       
  2065 	return $text;
       
  2066 }
       
  2067 
       
  2068 function networkpub_smart_truncate($string, $required_length) {
       
  2069 	$parts = preg_split('/([\s\n\r]+)/', $string, null, PREG_SPLIT_DELIM_CAPTURE);
       
  2070 	$parts_count = count($parts);
       
  2071 	$length = 0;
       
  2072 	$last_part = 0;
       
  2073 	for (; $last_part < $parts_count; ++$last_part) {
       
  2074 		$length += strlen($parts[$last_part]);
       
  2075 		if ($length > $required_length) {
       
  2076 			break;
       
  2077 		}
       
  2078 	}
       
  2079 	return implode(array_slice($parts, 0, $last_part));
       
  2080 }
       
  2081 
       
  2082 function networkpub_prepare_string($string, $string_length) {
       
  2083 	$final_string = '';
       
  2084 	$utf8marker = chr(128);
       
  2085 	$count = 0;
       
  2086 	while (isset($string{$count})) {
       
  2087 		if ($string{$count} >= $utf8marker) {
       
  2088 			$parsechar = substr($string, $count, 2);
       
  2089 			$count += 2;
       
  2090 		} else {
       
  2091 			$parsechar = $string{$count};
       
  2092 			$count++;
       
  2093 		}
       
  2094 		if ($count > $string_length) {
       
  2095 			return $final_string;
       
  2096 		}
       
  2097 		$final_string = $final_string . $parsechar;
       
  2098 	}
       
  2099 	return $final_string;
       
  2100 }
       
  2101 
       
  2102 function networkpub_startswith($haystack, $needle) {
       
  2103     $length = strlen($needle);
       
  2104     return (substr($haystack, 0, $length) === $needle);
       
  2105 }
       
  2106 
       
  2107 function networkpub_endswith($haystack, $needle) {
       
  2108     $length = strlen($needle);
       
  2109     if ($length == 0) {
       
  2110         return true;
       
  2111     }
       
  2112 	return (substr($haystack, -$length) === $needle);
       
  2113 }
       
  2114 
       
  2115 function networkpub_thumbnail_link($post_id, $post_content) {
       
  2116 	$options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
       
  2117 	if (is_array($options)) {
       
  2118 		if ((!empty($options['networkpub_custom_field_image'])) && (!empty($options['networkpub_custom_field_image_url']))) {
       
  2119 			$networkpub_custom_field_image = $options['networkpub_custom_field_image'];
       
  2120 			$networkpub_custom_field_image_url = $options['networkpub_custom_field_image_url'];
       
  2121 			$post_data_custom = get_post_custom($post_id, ARRAY_A);
       
  2122 			if ((!empty($post_data_custom[$networkpub_custom_field_image]) ) ) {
       
  2123 				$post_data_custom_image = $post_data_custom[$networkpub_custom_field_image][0];
       
  2124 				if ( ( !networkpub_endswith($networkpub_custom_field_image_url, "/") && !networkpub_startswith($post_data_custom_image, "/") )  )  {
       
  2125 					return $networkpub_custom_field_image_url . '/' . $post_data_custom_image;
       
  2126 				} elseif ( !networkpub_endswith($networkpub_custom_field_image_url, "/") && networkpub_startswith($post_data_custom_image, "/") ) {
       
  2127 					return $networkpub_custom_field_image_url . $post_data_custom_image;
       
  2128 				} elseif ( networkpub_endswith($networkpub_custom_field_image_url, "/") && !networkpub_startswith($post_data_custom_image, "/") ) {
       
  2129 					return $networkpub_custom_field_image_url . $post_data_custom_image;
       
  2130 				} elseif ( networkpub_endswith($networkpub_custom_field_image_url, "/") && networkpub_startswith($post_data_custom_image, "/") ){
       
  2131 					$networkpub_custom_field_image_url = rtrim($networkpub_custom_field_image_url, "/");
       
  2132 					return $networkpub_custom_field_image_url . $post_data_custom_image;
       
  2133 				}
       
  2134 			}
       
  2135 		}  elseif ((!empty($options['networkpub_custom_field_image'])) && (empty($options['networkpub_custom_field_image_url']))) {
       
  2136 			$networkpub_custom_field_image = $options['networkpub_custom_field_image'];
       
  2137 			$post_data_custom = get_post_custom($post_id, ARRAY_A);
       
  2138 			if ((!empty($post_data_custom[$networkpub_custom_field_image]))) {
       
  2139 				return $post_data_custom[$networkpub_custom_field_image][0];
       
  2140 			}
       
  2141 		}
       
  2142 	}
       
  2143 	if (is_array($options)) {
       
  2144 		if (!empty($options['networkpub_thumbnail_size'])) {
       
  2145 			$networkpub_thumbnail_size = $options['networkpub_thumbnail_size'];
       
  2146 		}
       
  2147 	}
       
  2148 	if (function_exists('get_post_thumbnail_id') and function_exists('wp_get_attachment_image_src')) {
       
  2149 		$src = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), $networkpub_thumbnail_size);
       
  2150 		if ($src) {
       
  2151 			$src = $src[0];
       
  2152 			return $src;
       
  2153 		}
       
  2154 	}
       
  2155 	if (!$post_content) {
       
  2156 		return False;
       
  2157 	}
       
  2158 	if (class_exists("DOMDocument") and function_exists('simplexml_import_dom')) {
       
  2159 		libxml_use_internal_errors(true);
       
  2160 		$doc = new DOMDocument();
       
  2161 		if (!($doc->loadHTML($post_content))) {
       
  2162 			return False;
       
  2163 		}
       
  2164 		try {
       
  2165 			$xml = @simplexml_import_dom($doc);
       
  2166 			if ($xml) {
       
  2167 				$images = $xml -> xpath('//img');
       
  2168 				if (!empty($images)) {
       
  2169 					return $images[0]['src'];
       
  2170 				}
       
  2171 			} else {
       
  2172 				return False;
       
  2173 			}
       
  2174 		} catch (Exception $e) {
       
  2175 			return False;
       
  2176 		}
       
  2177 	}
       
  2178 	return False;
       
  2179 }
       
  2180 
       
  2181 function networkpub_video($post_id, $post_content) {
       
  2182 	if (!$post_content) {
       
  2183 		return;
       
  2184 	}
       
  2185 	$link = 'http://www.linksalpha.com/a/networkpubvideoinfo';
       
  2186 	$params = array('post_content' => $post_content,
       
  2187 					'plugin' => NETWORKPUB_WIDGET_NAME_INTERNAL_NW,
       
  2188 					'plugin_version' => networkpub_version(),
       
  2189 				);
       
  2190 	$response_full = networkpub_http_post($link, $params);
       
  2191 	$response_code = $response_full[0];
       
  2192 	if ($response_code != 200) {
       
  2193 		return;
       
  2194 	}
       
  2195 	$response = networkpub_json_decode($response_full[1]);
       
  2196 	if ($response->errorCode > 0) {
       
  2197 		return;
       
  2198 	}
       
  2199 	update_post_meta($post_id, 'networkpub_video_source', $response->results->source);
       
  2200 	update_post_meta($post_id, 'networkpub_video_picture', $response->results->picture);
       
  2201 	return;
       
  2202 }
       
  2203 
       
  2204 register_deactivation_hook(__FILE__, 'networkpub_deactivate');
   236 ?>
  2205 ?>