diff -r 2f6f6f7551ca -r 32102edaa81b web/wp-content/plugins/network-publisher/networkpub.php
--- a/web/wp-content/plugins/network-publisher/networkpub.php Thu Sep 16 15:45:36 2010 +0000
+++ b/web/wp-content/plugins/network-publisher/networkpub.php Mon Nov 19 18:26:13 2012 +0100
@@ -1,236 +1,2205 @@
-'API Key:', 'type'=>'text', 'default'=>'');
-$networkpub_settings['id'] = array('label'=>'id', 'type'=>'text', 'default'=>'');
-$options = get_option(WIDGET_NAME_INTERNAL);
-
-function networkpub_init() {
- wp_enqueue_script('jquery');
- wp_register_script('networkpubjs', WP_PLUGIN_URL .'/network-publisher/networkpub.js');
- wp_enqueue_script('networkpubjs');
- wp_register_style('networkpubcss', WP_PLUGIN_URL . '/network-publisher/networkpub.css');
- wp_enqueue_style('networkpubcss');
- add_action('admin_menu', 'networkpub_pages');
- add_action('{$new_status}_{$post->post_type}', 'networkping');
- add_action('publish_post', 'networkping');
-}
-
-add_action('init', 'networkpub_init');
-add_action('init', 'networkpub_remove');
-
-function networkping($id) {
- if(!$id) {
- return FALSE;
- }
- $options = get_option(WIDGET_NAME_INTERNAL);
- $link = 'http://www.linksalpha.com/a/ping?id='.$options['id'];
- require_once(ABSPATH.WPINC.'/class-snoopy.php');
- $snoop = new Snoopy;
- $snoop->agent = WIDGET_NAME.' - '.get_option('siteurl');
- $response = '';
- if($snoop->fetchtext($link)){
- if (strpos($snoop->response_code, '200')) {
- return TRUE;
- }
- }
- return FALSE;
-}
-
-function networkpub_pages() {
- if ( function_exists('add_submenu_page') ) {
- $page = add_submenu_page('plugins.php', WIDGET_NAME, WIDGET_NAME, 'manage_options', 'networkpub', 'networkpub_conf');
- }
-}
-
-function networkpub_conf() {
- global $networkpub_settings;
-
- if ( isset($_POST['submit']) ) {
- if ( function_exists('current_user_can') && !current_user_can('manage_options') ) {
- die(__('Cheatin’ uh?'));
- }
- $field_name = sprintf('%s_%s', WIDGET_PREFIX, 'api_key');
- $value = strip_tags(stripslashes($_POST[$field_name]));
- if($value) {
- $networkadd = networkpub_add($value);
- }
- }
- $options = get_option(WIDGET_NAME_INTERNAL);
- $html = '
';
- $html .= 'Error occured while trying to load the API Keys. Please try again later.
';
- return $html;
- }
- if($response->errorCode > 0) {
- $html = 'Error occured while trying to load the API Keys. Please try again later.
';
- return $html;
- }
- $html = 'You are currently Publishing your Blog to '.count($response->results).' Social Networks
';
- $html .= '';
+ } else {
+ $html .= '
';
+ //Content Sent successfully
+ if ($networkpub_meta_published == 'failed') {
+ $html .= '
';
+ $html .= '
' . __('Post to social networks failed.') . '
';
+ $html .= '
';
+ } elseif ($networkpub_meta_published == 'done') {
+ $html .= '
';
+ $html .= '
' . __('Data sent successfully.') . '
';
+ $html .= '
';
+ }
+ //nonce
+ $html .= '
';
+ //Return
+ echo $html;
+}
+
+function networkpub_save_post_meta_box($post_id, $post) {
+ #Options
+ $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
+ if (empty($_POST['networkpub_meta_nonce'])) {
+ return $post_id;
+ }
+ #Nonce
+ if (!wp_verify_nonce($_POST['networkpub_meta_nonce'], plugin_basename(__FILE__))) {
+ return $post_id;
+ }
+ #User auth
+ if (!current_user_can('edit_post', $post_id)) {
+ return $post_id;
+ }
+ #Message
+ $new_meta_value_postmessage = '';
+ if (!empty($_POST['networkpub_postmessage'])) {
+ if ($_POST['networkpub_postmessage']) {
+ $new_meta_value_postmessage = strip_tags($_POST['networkpub_postmessage']);
+ }
+ }
+ update_post_meta($post_id, 'networkpub_postmessage', $new_meta_value_postmessage);
+ #Twitter Handle
+ $new_meta_value_twitterhandle = '';
+ if (!empty($_POST['networkpub_twitterhandle'])) {
+ if ($_POST['networkpub_twitterhandle']) {
+ $new_meta_value_twitterhandle = strip_tags($_POST['networkpub_twitterhandle']);
+ $new_meta_value_twitterhandle = str_replace("@", "", $new_meta_value_twitterhandle);
+ }
+ }
+ update_post_meta($post_id, 'networkpub_twitterhandle', $new_meta_value_twitterhandle);
+ #Twitter Hash
+ $new_meta_value_twitterhash = '';
+ if (!empty($_POST['networkpub_twitterhash'])) {
+ if ($_POST['networkpub_twitterhash']) {
+ $new_meta_value_twitterhash = strip_tags($_POST['networkpub_twitterhash']);
+ $new_meta_value_twitterhash = str_replace("#", "", $new_meta_value_twitterhash);
+ }
+ }
+ update_post_meta($post_id, 'networkpub_twitterhash', $new_meta_value_twitterhash);
+ #Facebook Page Type
+ $new_meta_value_ogtypefacebook = '';
+ if (!empty($_POST['networkpub_ogtype_facebook'])) {
+ if ($_POST['networkpub_ogtype_facebook']) {
+ $new_meta_value_ogtypefacebook = strip_tags($_POST['networkpub_ogtype_facebook']);
+ }
+ }
+ update_post_meta($post_id, 'networkpub_ogtype_facebook', $new_meta_value_ogtypefacebook);
+ #Image/Video
+ $new_meta_value_post_image_video = '';
+ if (!empty($_POST['networkpub_post_image_video'])) {
+ if ($_POST['networkpub_post_image_video']) {
+ $new_meta_value_post_image_video = strip_tags($_POST['networkpub_post_image_video']);
+ }
+ }
+ update_post_meta($post_id, 'networkpub_post_image_video', $new_meta_value_post_image_video);
+ $options['networkpub_post_image_video'] = $new_meta_value_post_image_video;
+ #Content
+ $new_meta_value_content = 0;
+ if (!empty($_POST['networkpub_meta_cb_content'])) {
+ if ($_POST['networkpub_meta_cb_content']) {
+ $new_meta_value_content = 1;
+ }
+ }
+ update_post_meta($post_id, '_networkpub_meta_content', $new_meta_value_content);
+ #Update Options
+ update_option(NETWORKPUB_WIDGET_NAME_INTERNAL, $options);
+}
+
+function networkpub_post_publish_status($post_id, $post) {
+ add_post_meta($post_id, '_networkpub_meta_published', 'new', true);
+}
+
+function networkpub_warning() {
+ $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
+ if (empty($options['api_key'])) {
+ if (!isset($_POST['submit'])) {
+ echo '
+
+
+
' . __('You must') . '
' . __('enter API key') . ' ' . __(' on the settings page for plugin') . ' ' . NETWORKPUB_WIDGET_NAME . ' ' . __('for automatic posting of your blog articles to 20+ Social Networks including Twitter, Facebook Profile, Facebook Pages, LinkedIn, MySpace, Yammer, Yahoo, Identi.ca, and more to work') . '
+
';
+ }
+ }
+}
+
+function networkpub_auth_errors() {
+ //Get options
+ $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
+ if (!is_array($options)) {
+ return;
+ }
+ if (empty($options['networkpub_auth_error_show'])) {
+ return;
+ }
+ $networkpub_auth_error_show = $options['networkpub_auth_error_show'];
+ if (!$networkpub_auth_error_show) {
+ return;
+ }
+ if (empty($options['api_key'])) {
+ return;
+ }
+ $api_key = $options['api_key'];
+ $link = 'http://www.linksalpha.com/a/networkpubautherrors';
+ $params = array('api_key' => $api_key, 'plugin' => NETWORKPUB_WIDGET_NAME_INTERNAL_NW, 'plugin_version' => networkpub_version(), );
+ $response_full = networkpub_http_post($link, $params);
+ $response_code = $response_full[0];
+ if ($response_code == 200) {
+ return;
+ }
+ if ($response_code == 401) {
+ echo "
+
+
+
" . __("Network Publisher Authorization Error") . "
+
+
+
+ ";
+ return;
+ }
+ return;
+}
+
+function networkpub_mixed_mode() {
+ $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
+ if (!is_array($options)) {
+ return;
+ }
+ if (empty($options['networkpub_mixed_mode_alert_show'])) {
+ return;
+ }
+ $networkpub_mixed_mode_alert_show = $options['networkpub_mixed_mode_alert_show'];
+ if (!$networkpub_mixed_mode_alert_show) {
+ return;
+ }
+ if (empty($options['id_2'])) {
+ return;
+ }
+ $id = $options['id_2'];
+ $link = 'http://www.linksalpha.com/a/networkpubmixedmode';
+ $params = array('id' => $id, 'plugin' => NETWORKPUB_WIDGET_NAME_INTERNAL_NW, 'plugin_version' => networkpub_version(), );
+ $response_full = networkpub_http_post($link, $params);
+ $response_code = $response_full[0];
+ if ($response_code == 200) {
+ $response = networkpub_json_decode($response_full[1]);
+ if ($response -> errorCode > 0) {
+ if ($response -> errorMessage == 'mixed mode') {
+ echo "
+
+
+
" . __("Network Publisher - Mixed Mode Alert") . "
+
+
+ " . __("Publishing of your website content via LinksAlpha Network Publisher seems to be configured using both the Network Publisher Plugin and RSS Feed of your website. LinksAlpha recommends use of Network Publisher plugin over RSS Feed. ") . "
" . __("Click here") . " " . __("to read the help document that will help resolve this Mixed Mode configuration issue.") . "
+
+
+ ";
+ }
+ }
+ }
+}
+
+function networkpub_disabled_check($networkpub_enable) {
+ $html = '
';
+ if ($networkpub_enable != 'checked') {
+ echo $html;
+ }
+}
+
+function networkpub_ping($id) {
+ if (!$id) {
+ return;
+ }
+ $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
+ if (empty($options['id']) or empty($options['api_key'])) {
+ return;
+ }
+ $link = 'http://www.linksalpha.com/a/ping?id=' . $options['id'];
+ $response_full = networkpub_http($link);
+ return;
+}
+
+function networkpub_ping_custom($new, $old, $post) {
+ if ($new == 'publish' && $old != 'publish') {
+ $post_types = get_post_types(array('public' => true), 'objects');
+ foreach ($post_types as $post_type) {
+ if ($post -> post_type == $post_type -> name) {
+ networkpub_ping($post->ID, $post);
+ break;
+ }
+ }
+ }
+ return;
+}
+
+function networkpub_convert($id) {
+ if (!$id) {
+ return;
+ }
+ $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
+ if (!empty($options['id_2'])) {
+ return;
+ }
+ if (empty($options['id']) or empty($options['api_key'])) {
+ return;
+ }
+ $link = 'http://www.linksalpha.com/a/networkpubconvert';
+ $params = array('id' => $options['id'], 'api_key' => $options['api_key'], 'plugin' => NETWORKPUB_WIDGET_NAME_INTERNAL_NW, );
+ //HTTP Call
+ $response_full = networkpub_http_post($link, $params);
+ $response_code = $response_full[0];
+ if ($response_code != 200) {
+ return;
+ }$response = networkpub_json_decode($response_full[1]);
+ if ($response -> errorCode > 0) {
+ return;
+ }
+ $options['id_2'] = $response -> results;
+ //Save
+ update_option(NETWORKPUB_WIDGET_NAME_INTERNAL, $options);
+ return;
+}
+
+function networkpub_post($post_id) {
+ $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
+ if (!is_array($options)) {
+ return;
+ }
+ if (array_key_exists('networkpub_enable', $options)) {
+ $networkpub_enable_value = $options['networkpub_enable'];
+ } else {
+ $networkpub_enable_value = 1;
+ }
+ if (!$networkpub_enable_value) {
+ return;
+ }
+ if (!$options['networkpub_post_types']) {
+ return;
+ }
+ $post_types_enabled = explode(',', $options['networkpub_post_types']);
+ $post_type = get_post_type($post_id);
+ if (!in_array($post_type, $post_types_enabled)) {
+ return;
+ }
+ //Network keys
+ if (empty($options['api_key']) or empty($options['id_2'])) {
+ return;
+ }
+ $id = $options['id_2'];
+ $api_key = $options['api_key'];
+ //Post data
+ $post_data = get_post($post_id, ARRAY_A);
+ //Post Published?
+ if (!in_array($post_data['post_status'], array('future', 'publish'))) {
+ return;
+ }
+ //post too old?
+ $post_date = strtotime($post_data['post_date_gmt']);
+ $current_date = time();
+ $diff = $current_date - $post_date;
+ $days = floor($diff / (60 * 60 * 24));
+ if ($days > 3) {
+ return;
+ }
+ $post_message = get_post_meta($post_id, 'networkpub_postmessage', true);
+ $post_twitterhandle = get_post_meta($post_id, 'networkpub_twitterhandle', true);
+ $post_twitterhash = get_post_meta($post_id, 'networkpub_twitterhash', true);
+ $post_ogtypefacebook = get_post_meta($post_id, 'networkpub_ogtype_facebook', true);
+ $networkpub_meta_publish = get_post_meta($post_id, '_networkpub_meta_publish', true);
+ $networkpub_post_image_video = get_post_meta($post_id, 'networkpub_post_image_video', true);
+ if ($networkpub_meta_publish == "") {
+ } elseif ($networkpub_meta_publish == 0) {
+ return;
+ }
+ $networkpub_meta_published = get_post_meta($post_id, '_networkpub_meta_published', true);
+ if ($networkpub_meta_published == 'done') {
+ return;
+ }
+ //Post meta - networkpub_meta_content
+ $networkpub_meta_content = get_post_meta($post_id, '_networkpub_meta_content', true);
+ //Post data: id, content and title
+ $post_title = $post_data['post_title'];
+ if ($networkpub_meta_content) {
+ $post_content = $post_data['post_excerpt'];
+ } else {
+ $post_content = $post_data['post_content'];
+ }
+ //Post data: Permalink
+ $post_link = get_permalink($post_id);
+ //Post data: Categories
+ $post_categories_array = array();
+ $post_categories_data = get_the_category($post_id);
+ foreach ($post_categories_data as $category) {
+ $post_categories_array[] = $category -> cat_name;
+ }
+ $post_categories = implode(",", $post_categories_array);
+ $post_tags_array = array();
+ $post_tags_data = wp_get_post_tags($post_id);
+ foreach ($post_tags_data as $tag) {
+ $post_tags_array[] = $tag -> name;
+ }
+ $post_tags = implode(",", $post_tags_array);
+ if (function_exists('get_wpgeo_latitude')) {
+ if (get_wpgeo_latitude($post_id) and get_wpgeo_longitude($post_id)) {
+ $post_geotag = get_wpgeo_latitude($post_id) . ' ' . get_wpgeo_longitude($post_id);
+ }
+ }
+ if (!isset($post_geotag)) {
+ $post_geotag = '';
+ }
+ $link = 'http://www.linksalpha.com/a/networkpubpost';
+ $params = array('id' => $id,
+ 'api_key' => $api_key,
+ 'post_id' => $post_id,
+ 'post_link' => $post_link,
+ 'post_title' => $post_title,
+ 'post_content' => $post_content,
+ 'plugin' => NETWORKPUB_WIDGET_NAME_INTERNAL_NW,
+ 'plugin_version' => networkpub_version(),
+ 'post_categories' => $post_categories,
+ 'post_tags' => $post_tags,
+ 'post_geotag' => $post_geotag,
+ 'twitterhandle' => $post_twitterhandle,
+ 'hashtag' => $post_twitterhash,
+ 'content_message' => $post_message,
+ 'post_image_video' => $networkpub_post_image_video,
+ );
+ $post_image = networkpub_thumbnail_link($post_id, $post_data['post_content']);
+ if ($post_image) {
+ $params['post_image'] = $post_image;
+ }
+ $response_full = networkpub_http_post($link, $params);
+ $response_code = $response_full[0];
+ if ($response_code == 200) {
+ update_post_meta($post_id, '_networkpub_meta_published', 'done');
+ } else {
+ update_post_meta($post_id, '_networkpub_meta_published', 'failed');
+ }
+ networkpub_video($post_id, $post_content);
+ return;
+}
+
+function networkpub_post_xmlrpc($post_id) {
+ networkpub_post($post_id);
+ return;
+}
+
+function networkpub_post_custom($new, $old, $post) {
+ if ($new == 'publish' && $old != 'publish') {
+ $post_types = get_post_types(array('public' => true), 'objects');
+ foreach ($post_types as $post_type) {
+ if ($post -> post_type == $post_type -> name) {
+ networkpub_post($post->ID);
+ break;
+ }
+ }
+ }
+ return;
+}
+
+function networkpub_conf() {
+ $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
+ global $networkpub_settings;
+ if (isset($_POST['submit'])) {
+ if (function_exists('current_user_can') && !current_user_can('manage_options')) {
+ die(__('Cheatin’ uh?'));
+ }
+ $field_name = sprintf('%s_%s', NETWORKPUB_WIDGET_PREFIX, 'api_key');
+ if (array_key_exists($field_name, $_POST)) {
+ $value = strip_tags(stripslashes($_POST[$field_name]));
+ if ($value) {
+ $networkadd = networkpub_add($value);
+ }
+ } else {
+ if ($_POST['networkpub_form_type'] == 'networkpub_enable') {
+ if (array_key_exists('networkpub_enable', $_POST)) {
+ $networkpub_enable = 1;
+ } else {
+ $networkpub_enable = 0;
+ }
+ networkpub_update_option('networkpub_enable', $networkpub_enable);
+ } elseif ($_POST['networkpub_form_type'] == 'networkpub_auth_error_show') {
+ if (array_key_exists('networkpub_auth_error_show', $_POST)) {
+ $networkpub_auth_error_show = 1;
+ } else {
+ $networkpub_auth_error_show = 0;
+ }
+ networkpub_update_option('networkpub_auth_error_show', $networkpub_auth_error_show);
+ } elseif ($_POST['networkpub_form_type'] == 'networkpub_mixed_mode_alert_show') {
+ if (array_key_exists('networkpub_mixed_mode_alert_show', $_POST)) {
+ $networkpub_mixed_mode_alert_show = 1;
+ } else {
+ $networkpub_mixed_mode_alert_show = 0;
+ }
+ networkpub_update_option('networkpub_mixed_mode_alert_show', $networkpub_mixed_mode_alert_show);
+ } elseif ($_POST['networkpub_form_type'] == 'networkpub_metatags_facebook') {
+ if (array_key_exists('networkpub_metatags_facebook', $_POST)) {
+ $networkpub_metatags_facebook = 1;
+ } else {
+ $networkpub_metatags_facebook = 0;
+ }
+ if (array_key_exists('networkpub_lang_facebook', $_POST)) {
+ $networkpub_lang_facebook = strip_tags($_POST['networkpub_lang_facebook']);
+ } else {
+ $networkpub_lang_facebook = 'en_US';
+ }
+ if (array_key_exists('networkpub_facebook_page_type', $_POST)) {
+ $networkpub_facebook_page_type = strip_tags($_POST['networkpub_facebook_page_type']);
+ } else {
+ $networkpub_facebook_page_type = 'article';
+ }
+ if (array_key_exists('networkpub_facebook_app_id', $_POST)) {
+ $networkpub_facebook_app_id = strip_tags($_POST['networkpub_facebook_app_id']);
+ } else {
+ $networkpub_facebook_app_id = '';
+ }
+ networkpub_update_option('networkpub_metatags_facebook', $networkpub_metatags_facebook);
+ networkpub_update_option('networkpub_lang_facebook', $networkpub_lang_facebook);
+ networkpub_update_option('networkpub_facebook_page_type', $networkpub_facebook_page_type);
+ networkpub_update_option('networkpub_facebook_app_id', $networkpub_facebook_app_id);
+ } elseif ($_POST['networkpub_form_type'] == 'networkpub_metatags_googleplus') {
+ if (array_key_exists('networkpub_metatags_googleplus', $_POST)) {
+ $networkpub_metatags_googleplus = 'checked';
+ } else {
+ $networkpub_metatags_googleplus = '';
+ }
+ if (array_key_exists('networkpub_googleplus_page_type', $_POST)) {
+ $networkpub_googleplus_page_type = strip_tags($_POST['networkpub_googleplus_page_type']);
+ } else {
+ $networkpub_googleplus_page_type = 'Article';
+ }
+ networkpub_update_option('networkpub_metatags_googleplus', $networkpub_metatags_googleplus);
+ networkpub_update_option('networkpub_googleplus_page_type', $networkpub_googleplus_page_type);
+ } elseif ($_POST['networkpub_form_type'] == 'networkpub_custom_field_image') {
+ if (array_key_exists('networkpub_custom_field_image', $_POST)) {
+ $networkpub_custom_field_image = strip_tags($_POST['networkpub_custom_field_image']);
+ } else {
+ $networkpub_custom_field_image = '';
+ }
+ networkpub_update_option('networkpub_custom_field_image', $networkpub_custom_field_image);
+ if (array_key_exists('networkpub_custom_field_image', $_POST)) {
+ $networkpub_custom_field_image_url = strip_tags($_POST['networkpub_custom_field_image_url']);
+ } else {
+ $networkpub_custom_field_image_url = '';
+ }
+ networkpub_update_option('networkpub_custom_field_image_url', $networkpub_custom_field_image_url);
+ } elseif ($_POST['networkpub_form_type'] == 'networkpub_post_types') {
+ if (array_key_exists('networkpub_post_types', $_POST)) {
+ $networkpub_post_types = array();
+ foreach($_POST['networkpub_post_types'] as $value) {
+ $networkpub_post_types[] = strip_tags($value);
+ }
+ $networkpub_post_types = implode(',', $_POST['networkpub_post_types']);
+ } else {
+ $networkpub_post_types = '';
+ }
+ networkpub_update_option('networkpub_post_types', $networkpub_post_types);
+ } elseif ($_POST['networkpub_form_type'] == 'networkpub_thumbnail_size') {
+ if (array_key_exists('networkpub_thumbnail_size', $_POST)) {
+ $networkpub_thumbnail_size = strip_tags($_POST['networkpub_thumbnail_size']);
+ } else {
+ $networkpub_thumbnail_size = 'medium';
+ }
+ networkpub_update_option('networkpub_thumbnail_size', $networkpub_thumbnail_size);
+ }
+ }
+ }
+ if (!empty($_GET['linksalpha_request_type'])) {
+ if ($_GET['linksalpha_request_type'] == 'get_posts') {
+ networkpub_get_posts();
+ }
+ return;
+ }
+ $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
+ if (is_array($options)) {
+ //Publishing Enable/Disable
+ if (array_key_exists('networkpub_enable', $options)) {
+ $networkpub_enable = $options['networkpub_enable'];
+ if ($networkpub_enable) {
+ $networkpub_enable = 'checked';
+ } else {
+ $networkpub_enable = '';
+ }
+ } else {
+ $networkpub_enable = 'checked';
+ }
+ if (array_key_exists('networkpub_auth_error_show', $options)) {
+ $networkpub_auth_error_show = $options['networkpub_auth_error_show'];
+ if ($networkpub_auth_error_show) {
+ $networkpub_auth_error_show = 'checked';
+ } else {
+ $networkpub_auth_error_show = '';
+ }
+ } else {
+ $networkpub_auth_error_show = 'checked';
+ }
+ if (array_key_exists('networkpub_mixed_mode_alert_show', $options)) {
+ $networkpub_mixed_mode_alert_show = $options['networkpub_mixed_mode_alert_show'];
+ if ($networkpub_mixed_mode_alert_show) {
+ $networkpub_mixed_mode_alert_show = 'checked';
+ } else {
+ $networkpub_mixed_mode_alert_show = '';
+ }
+ } else {
+ $networkpub_mixed_mode_alert_show = 'checked';
+ }
+ if (array_key_exists('networkpub_metatags_facebook', $options)) {
+ $networkpub_metatags_facebook = $options['networkpub_metatags_facebook'];
+ if ($networkpub_metatags_facebook) {
+ $networkpub_metatags_facebook = 'checked';
+ } else {
+ $networkpub_metatags_facebook = '';
+ }
+ } else {
+ $networkpub_metatags_facebook = 'checked';
+ }
+ if (array_key_exists('networkpub_lang_facebook', $options)) {
+ $networkpub_lang_facebook = $options['networkpub_lang_facebook'];
+ } else {
+ $networkpub_metatags_facebook = 'en_US';
+ }
+ if (array_key_exists('networkpub_facebook_page_type', $options)) {
+ $networkpub_facebook_page_type = $options['networkpub_facebook_page_type'];
+ } else {
+ $networkpub_facebook_page_type = 'article';
+ }
+ if (array_key_exists('networkpub_facebook_app_id', $options)) {
+ $networkpub_facebook_app_id = $options['networkpub_facebook_app_id'];
+ } else {
+ $networkpub_facebook_app_id = '';
+ }
+ if (array_key_exists('networkpub_metatags_googleplus', $options)) {
+ $networkpub_metatags_googleplus = $options['networkpub_metatags_googleplus'];
+ if ($networkpub_metatags_googleplus) {
+ $networkpub_metatags_googleplus = 'checked';
+ } else {
+ $networkpub_metatags_googleplus = '';
+ }
+ } else {
+ $networkpub_metatags_googleplus = 'checked';
+ }
+ if (array_key_exists('networkpub_googleplus_page_type', $options)) {
+ $networkpub_googleplus_page_type = $options['networkpub_googleplus_page_type'];
+ } else {
+ $networkpub_googleplus_page_type = 'Article';
+ }
+ if (array_key_exists('networkpub_custom_field_image', $options)) {
+ $networkpub_custom_field_image = $options['networkpub_custom_field_image'];
+ } else {
+ $networkpub_custom_field_image = '';
+ }
+ if (array_key_exists('networkpub_custom_field_image_url', $options)) {
+ $networkpub_custom_field_image_url = $options['networkpub_custom_field_image_url'];
+ } else {
+ $networkpub_custom_field_image_url = '';
+ }
+ if (array_key_exists('networkpub_thumbnail_size', $options)) {
+ $networkpub_thumbnail_size = $options['networkpub_thumbnail_size'];
+ } else {
+ $networkpub_thumbnail_size = 'medium';
+ }
+ } else {
+ $networkpub_enable = 'checked';
+ $networkpub_auth_error_show = 'checked';
+ $networkpub_mixed_mode_alert_show = 'checked';
+ $networkpub_metatags_facebook = 'checked';
+ $networkpub_lang_facebook = 'en_US';
+ $networkpub_facebook_page_type = 'article';
+ $networkpub_facebook_app_id = '';
+ $networkpub_metatags_googleplus = 'checked';
+ $networkpub_googleplus_page_type = 'Article';
+ $networkpub_custom_field_image = '';
+ $networkpub_custom_field_image_url = '';
+ $networkpub_thumbnail_size = 'medium';
+ }
+ $fb_langs = networkpub_fb_langs();
+ $fb_langs_options = '';
+ asort($fb_langs);
+ foreach ($fb_langs as $key => $val) {
+ if ($networkpub_lang_facebook == $key) {
+ $fb_langs_options = $fb_langs_options . '
' . htmlentities($val) . ' ';
+ } else {
+ $fb_langs_options = $fb_langs_options . '
' . htmlentities($val) . ' ';
+ }
+ }
+ $facebook_page_type = array('article' => __('Article'), 'blog' => __('Blog'), 'book' => __('Book'), 'profile' => __('External Profile'), 'video.movie' => __('Movie'), 'video.episode' => __('TV Episode'), 'video.tv_show' => __('TV Show'), 'video.other' => __('Video'), 'website' => __('Website'));
+ $facebook_page_type_options = '';
+ foreach ($facebook_page_type as $key => $val) {
+ if ($networkpub_facebook_page_type == $key) {
+ $facebook_page_type_options = $facebook_page_type_options . '
' . htmlentities($val) . ' ';
+ } else {
+ $facebook_page_type_options = $facebook_page_type_options . '
' . htmlentities($val) . ' ';
+ }
+ }
+ $googleplus_page_type = array('Article' => __('Article'), 'Blog' => __('Blog'), 'Book' => __('Book'), 'Event' => __('Event'), 'LocalBusiness' => __('Local Business'), 'Organization' => __('Organization'), 'Person' => __('Person'), 'Product' => __('Product'), 'Review' => __('Review'));
+ $googleplus_page_type_options = '';
+ foreach ($googleplus_page_type as $key => $val) {
+ if ($networkpub_googleplus_page_type == $key) {
+ $googleplus_page_type_options = $googleplus_page_type_options . '
' . htmlentities($val) . ' ';
+ } else {
+ $googleplus_page_type_options = $googleplus_page_type_options . '
' . htmlentities($val) . ' ';
+ }
+ }
+ $thumbnail_size_types = array('medium'=>'Medium', 'large'=>'Large');
+ $thumbnail_size_options = '';
+ foreach ($thumbnail_size_types as $key => $val) {
+ if ($networkpub_thumbnail_size == $key) {
+ $thumbnail_size_options = $thumbnail_size_options . '
' . htmlentities($val) . ' ';
+ } else {
+ $thumbnail_size_options = $thumbnail_size_options . '
' . htmlentities($val) . ' ';
+ }
+ }
+ networkpub_mixed_mode();
+ networkpub_disabled_check($networkpub_enable);
+ $html = '
+
+
+
' . NETWORKPUB_WIDGET_NAME . '
+
+
+
+
+
+
+
' . __('Network Publisher') . ' ' . __('makes it easy to Publish your Blog Posts to Social Networks. To configure:') . '
+
+
+
' . __('Once setup, your Blog posts content appears on the social networks as soon as you hit the Publish button.') . '
+
+
+
+
+
+
+
+
+
+
+
+
+ ' . networkpub_supported_networks() . '
+
+
+
+
';
+ echo $html;
+}
+
+function networkpub_add($api_key) {
+ if (!$api_key) {
+ $errdesc = networkpub_error_msgs('invalid key');
+ echo $errdesc;
+ return;
+ }
+ $url = get_bloginfo('url');
+ if (!$url) {
+ $errdesc = networkpub_error_msgs('invalid url');
+ echo $errdesc;
+ return;
+ }
+ $desc = get_bloginfo('description');
+ $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
+ if (!empty($options['id'])) {
+ $id = $options['id'];
+ } elseif (!empty($options['id_2'])) {
+ $id = $options['id_2'];
+ } else {
+ $id = '';
+ }
+ $url_parsed = parse_url($url);
+ $url_host = $url_parsed['host'];
+ if (substr_count($url, 'localhost') or strpos($url_host, '192.168.') === 0 or strpos($url_host, '127.0.0') === 0 or (strpos($url_host, '172.') === 0 and (int)substr($url_host, 4, 2) > 15 and (int)substr($url_host, 4, 2) < 32) or strpos($url_host, '10.') === 0) {
+ $errdesc = networkpub_error_msgs('localhost url');
+ echo $errdesc;
+ return FALSE;
+ }
+ $link = 'http://www.linksalpha.com/a/networkpubaddone';
+ // Build Params
+ $params = array('url' => urlencode($url), 'key' => $api_key, 'plugin' => NETWORKPUB_WIDGET_NAME_INTERNAL_NW, 'version' => NETWORKPUB_PLUGIN_VERSION, 'all_keys' => $options['api_key'], 'id' => $id);
+ $response_full = networkpub_http_post($link, $params);
+ $response_code = $response_full[0];
+ if ($response_code != 200) {
+ $errdesc = networkpub_error_msgs($response_full[1]);
+ echo $errdesc;
+ return FALSE;
+ }
+ $response = networkpub_json_decode($response_full[1]);
+ if ($response->errorCode > 0) {
+ if(isset($response->errorDetail)) {
+ $errdesc = networkpub_error_msgs($response->errorMessage, $response->errorDetail);
+ } else {
+ $errdesc = networkpub_error_msgs($response->errorMessage);
+ }
+ echo $errdesc;
+ return FALSE;
+ }
+ $options['id_2'] = $response->results->id;
+ if (empty($options['api_key'])) {
+ $options['api_key'] = $response -> results -> api_key;
+ } else {
+ $option_api_key_array = explode(',', $options['api_key']);
+ $option_api_key_new = $response -> results -> api_key;
+ $option_api_key_new_array = explode(',', $option_api_key_new);
+ foreach ($option_api_key_new_array as $key => $val) {
+ if (!in_array($val, $option_api_key_array)) {
+ $options['api_key'] = $options['api_key'] . ',' . $val;
+ }
+ }
+ }
+ update_option(NETWORKPUB_WIDGET_NAME_INTERNAL, $options);
+ //Return
+ echo '
' . __('API Key has been added successfully.') . '
';
+ return;
+}
+function networkpub_load() {
+ $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
+ if (empty($options['api_key'])) {
+ $html = '
' . __('You have not added an API Key') . '
';
+ return $html;
+ }
+ $link = 'http://www.linksalpha.com/a/networkpubget';
+ $body = array('key' => $options['api_key'], 'version' => 2);
+ $response_full = networkpub_http_post($link, $body);
+ $response_code = $response_full[0];
+ if ($response_code != 200) {
+ $errdeschtml = networkpub_error_msgs('misc');
+ return $errdeschtml;
+ } $response = networkpub_json_decode($response_full[1]);
+ if ($response->errorCode > 0) {
+ $html = '
' . __('Error occured while trying to load the API Keys. Please try again later.') . '
';
+ return $html;
+ }
+ if (count($response->results_deleted)) {
+ $option_api_key_array = explode(',', $options['api_key']);
+ foreach($response->results_deleted as $row) {
+ if(in_array($row, $option_api_key_array)) {
+ $option_api_key_array = array_diff($option_api_key_array, array($row));
+ }
+ }
+ $api_key = implode(",", $option_api_key_array);
+ $options['api_key'] = $api_key;
+ update_option(NETWORKPUB_WIDGET_NAME_INTERNAL, $options);
+ }
+ if (!count($response -> results)) {
+ return '
' . __('You have not added an API Key') . '
';
+ }
+ if (count($response -> results) == 1) {
+ $html = '
' . NETWORKPUB_CURRENTLY_PUBLISHING . ' ' . count($response -> results) . ' ' . NETWORKPUB_SOCIAL_NETWORK . '
';
+ } else {
+ $html = '
' . NETWORKPUB_CURRENTLY_PUBLISHING . ' ' . count($response -> results) . ' ' . NETWORKPUB_SOCIAL_NETWORKS . '
';
+ }
+ $html .= '
' . __('Network Account') . ' ' . __('Options') . ' ' . __('Publish Results') . ' ' . __('Remove') . ' ';
+ $i = 1;
+ foreach ($response->results as $row) {
+ if ($row -> auth_expired) {
+ $auth_error_class = 'class="networkpublisher_auth_error"';
+ $auth_error_image = ' ';
+ } else {
+ $auth_error_class = '';
+ $auth_error_image = '';
+ }
+ $html .= '';
+ if ($i % 2) {
+ $html .= '';
+ } else {
+ $html .= ' ';
+ }
+ $html .= $auth_error_image . '' . $row -> name . ' ';
+ if ($i % 2) {
+ $html .= '';
+ } else {
+ $html .= ' ';
+ }
+ $html .= ' ' . __('Options') . ' ';
+ if ($i % 2) {
+ $html .= '';
+ } else {
+ $html .= ' ';
+ }
+ $html .= ' ' . __('Publish Results') . ' ';
+ if ($i % 2) {
+ $html .= '';
+ } else {
+ $html .= ' ';
+ }
+ $html .= '' . __('Remove') . ' ';
+ $html .= ' ';
+ $i++;
+ }
+ $html .= '
';
+ return $html;
+}
+
+function networkpub_post_types() {
+ $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
+ if (empty($options['networkpub_post_types'])) {
+ $post_types_in_options = array();
+ } else {
+ $post_types_in_options = explode(',', $options['networkpub_post_types']);
+ }
+ if (!function_exists('get_post_types')) {
+ return;
+ }
+ $html = '';
+ $args = array('public' => true, '_builtin' => false);
+ $output = 'names';
+ $operator = 'and';
+ $post_types = get_post_types($args, $output, $operator);
+ array_unshift($post_types, 'post', 'page');
+ foreach ($post_types as $post_type) {
+ $checked = '';
+ if (in_array($post_type, $post_types_in_options)) {
+ $checked = 'checked';
+ }
+ $html .= '
' . $post_type . '
';
+ }
+ return $html;
+}
+
+function networkpub_remove() {
+ $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
+ if (!empty($_POST['networkpub_key'])) {
+ $key_full = strip_tags($_POST['networkpub_key']);
+ $key_only = substr($key_full, 4);
+ $link = 'http://www.linksalpha.com/a/networkpubremove';
+ $body = array('id' => $options['id_2'], 'key' => $key_only);
+ $response_full = networkpub_http_post($link, $body);
+ $response_code = $response_full[0];
+ if ($response_code != 200) {
+ $errdesc = networkpubnw_error_msgs($response_full[1]);
+ echo $errdesc;
+ return;
+ }
+ $api_key = $options['api_key'];
+ $api_key_array = explode(',', $api_key);
+ $loc = array_search($key_only, $api_key_array);
+ if ($loc !== FALSE) {
+ unset($api_key_array[$loc]);
+ }
+ $api_key = implode(",", $api_key_array);
+ $options['api_key'] = $api_key;
+ update_option(NETWORKPUB_WIDGET_NAME_INTERNAL, $options);
+ echo $key_full;
+ return;
+ }
+}
+
+function networkpub_update_option($option, $value) {
+ $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
+ $options[$option] = $value;
+ update_option(NETWORKPUB_WIDGET_NAME_INTERNAL, $options);
+ return;
+}
+
+function networkpub_pages() {
+ if (function_exists('add_submenu_page')) {
+ $page = add_submenu_page('plugins.php', NETWORKPUB_WIDGET_NAME, NETWORKPUB_WIDGET_NAME, 'manage_options', NETWORKPUB_WIDGET_NAME_INTERNAL, 'networkpub_conf');
+ if (is_admin()) {
+ $page = add_submenu_page('edit.php', NETWORKPUB_WIDGET_NAME_POSTBOX, NETWORKPUB_WIDGET_NAME_POSTBOX, 'manage_options', NETWORKPUB_WIDGET_NAME_POSTBOX_INTERNAL, 'networkpub_postbox');
+ }
+ }
+}
+
+function networkpub_postbox() {
+ $html = '
' . NETWORKPUB_WIDGET_NAME . ' - ' . NETWORKPUB_WIDGET_NAME_POSTBOX . ' ';
+ $html .= '
';
+ $html .= '
+
+ ' . __('Share this Plugin') . '
+
+
+
';
+ echo $html;
+ return;
+}
+
+function networkpub_supported_networks() {
+ $html = '';
+ $response_full = networkpub_http('http://www.linksalpha.com/a/networkpubsupported');
+ $response_code = $response_full[0];
+ if ($response_code != 200) {
+ return $html;
+ }
+ $response = $response_full[1];
+ $content = networkpub_json_decode($response);
+ if (!$content) {
+ return $html;
+ }
+ $html .= '
';
+ $i = 0;
+ foreach ($content as $key => $val) {
+ if ($i % 2) {
+ $bg_color = "#FFFFFF";
+ } else {
+ $bg_color = "#F7F7F7";
+ }
+ $html .= ' ' . $val -> name . ' ';
+ $i++;
+ }
+ $html .= ' ';
+ return $html;
+}
+
+function networkpub_json_decode($str) {
+ if (function_exists("json_decode")) {
+ return json_decode($str);
+ } else {
+ if (!class_exists('Services_JSON')) {
+ require_once ("JSON.php");
+ }
+ $json = new Services_JSON();
+ return $json -> decode($str);
+ }
+}
+
+function networkpub_http($link) {
+ if (!$link) {
+ return array(500, 'invalid url');
+ }
+ if (!class_exists('WP_Http')) {
+ include_once (ABSPATH . WPINC . '/class-http.php');
+ }
+ if (class_exists('WP_Http')) {
+ $request = new WP_Http;
+ $headers = array('Agent' => NETWORKPUB_WIDGET_NAME . ' - ' . get_bloginfo('url'));
+ $response_full = $request -> request($link, array('method' => 'GET', 'headers' => $headers, 'timeout' => 60));
+ if (isset($response_full -> errors)) {
+ return array(500, 'internal error');
+ }
+ if (!is_array($response_full['response'])) {
+ return array(500, 'internal error');
+ }
+ $response_code = $response_full['response']['code'];
+ if ($response_code == 200) {
+ $response = $response_full['body'];
+ return array($response_code, $response);
+ }
+ $response_msg = $response_full['response']['message'];
+ return array($response_code, $response_msg);
+ }
+ require_once (ABSPATH . WPINC . '/class-snoopy.php');
+ $snoop = new Snoopy;
+ $snoop -> agent = NETWORKPUB_WIDGET_NAME . ' - ' . get_bloginfo('url');
+ if ($snoop -> fetchtext($link)) {
+ if (strpos($snoop -> response_code, '200')) {
+ $response = $snoop -> results;
+ return array(200, $response);
+ }
+ }
+ return array(500, 'internal error');
+}
+
+function networkpub_http_post($link, $body) {
+ if (!$link) {
+ return array(500, 'invalid url');
+ }
+ if (!class_exists('WP_Http')) {
+ include_once (ABSPATH . WPINC . '/class-http.php');
+ }
+ if (class_exists('WP_Http')) {
+ $request = new WP_Http;
+ $headers = array('Agent' => NETWORKPUB_WIDGET_NAME . ' - ' . get_bloginfo('url'));
+ $response_full = $request -> request($link, array('method' => 'POST', 'body' => $body, 'headers' => $headers, 'timeout' => 60));
+ if (isset($response_full -> errors)) {
+ return array(500, 'internal error');
+ }
+ if (!is_array($response_full['response'])) {
+ return array(500, 'internal error');
+ }
+ $response_code = $response_full['response']['code'];
+ if ($response_code == 200) {
+ $response = $response_full['body'];
+ return array($response_code, $response);
+ }
+ $response_msg = $response_full['response']['message'];
+ return array($response_code, $response_msg);
+ }
+
+ // If no WP_HTTP found, fall back on snoopy.php for making HTTP request
+ require_once (ABSPATH . WPINC . '/class-snoopy.php');
+ $snoop = new Snoopy;
+ $snoop -> agent = NETWORKPUB_WIDGET_NAME . ' - ' . get_bloginfo('url');
+ if ($snoop -> submit($link, $body)) {
+ if (strpos($snoop -> response_code, '200')) {
+ $response = $snoop -> results;
+ return array(200, $response);
+ }
+ }
+ return array(500, 'internal error');
+}
+
+function networkpub_error_msgs($errMsg, $errorDetail='') {
+ $arr_errCodes = explode(";", $errMsg);
+ $errCodesCount = count($arr_errCodes);
+ switch (trim($arr_errCodes[0])) {
+ case 'internal error' :
+ $html = '
+
+
' . __('There was an unknown error. Please try again') . '.
+
+
';
+ return $html;
+ break;
+ case 'invalid url' :
+ $html = '
' . __('Your blog URL is invalid') . ': ' . $arr_errCodes[$errCodesCount - 1];
+ if ($errCodesCount == 3) {
+ $html .= '. ' . __('Error Code') . ' =' . $arr_errCodes[$errCodesCount - 2];
+ }
+ $html .= '
+ ' . __('You can also') . '
' . __('Click here') . ' ' . __(' to enter blog URL on LinksAlpha manually.
+ Also ensure that in ') . '
' . __('Settings') . '->' . __('General') . '->"' . __('Blog address (URL)') . '" ' . __('the URL is filled-in correctly') . '.
+
' . __('If you still face issues then email us at') . '
post@linksalpha.com ' . __('with error description') . '.
';
+ return $html;
+ break;
+ case 'localhost url' :
+ $html = '
+
+
+
" . __("Network Publisher Authorization Error") . "
+
+
+
+
+
' . __('Website/Blog inaccessible') . '
';
+ $html .= '
' . __('You are trying to use the plugin on ') . 'localhost ' . __('or behind a') . ' ' . __('firewall') . ' , ' . __('which is not supported. Please install the plugin on a Wordpress blog on a live server') . '.
+
';
+ return $html;
+ break;
+ case 'remote url error' :
+ $html = '
' . __('Remote URL error') . ': ' . $arr_errCodes[$errCodesCount - 1];
+ if ($errCodesCount == 3) {
+ $html .= '. ' . __('Error Code') . ' =' . $arr_errCodes[$errCodesCount - 2];
+ }
+ $html .= '
+
+ ' . __('Description:') . '
+ ' . __('Please try again') . '. ' . __('Your site either did not respond (it is extremely slow) or it is not operational') . '.
+
+
+ ' . __('You can also') . '
' . __('Click here') . ' ' . __('to enter blog URL on LinksAlpha manually') . '.
+ ' . __('Also ensure that in') . '
' . __('Settings') . '->' . __('General') . '->"' . __('Blog address (URL)') . '" ' . __('the URL is filled-in correctly') . '.
+
+
+
';
+ return $html;
+ break;
+ case 'feed parsing error' :
+ $html = '
' . __('Feed parsing error') . ': ' . $arr_errCodes[$errCodesCount - 1];
+ if ($errCodesCount == 3) {
+ $html .= '. ' . __('Error Code') . '= ' . $arr_errCodes[$errCodesCount - 2];
+ }
+ $html .= '
+
+
+
';
+ return $html;
+ break;
+ case 'feed not found' :
+ $html = '
+
+ ' . __('We could not find feed URL for your blog') . '.
+
+
+
' . __('Click here') . ' ' . __('to enter feed URL on LinksAlpha manually') . '.
+ ' . __('Also ensure that in ') . '
' . __('Settings') . '->' . __('General') . '->"' . __('Blog address (URL)') . '" ' . __('the URL is filled-in correctly') . '.
+
+
+
';
+ return $html;
+ break;
+ case 'invalid key' :
+ $html = '
+
+
' . __('The key that you entered is incorrect. Please input a valid
User or
Network API key and try again') . '.
+
+
';
+ return $html;
+ break;
+ case 'network key' :
+ $html = '
+
+
' . __('Invalid Key') . ': ' . __('Please make sure you enter the ') . '
' . __('User API key') . ' ' . __(', and not the key of a Network') . '.
+
+
';
+ return $html;
+ break;
+ case 'subscription upgrade required':
+ if($errorDetail) {
+ $html = '
+
' . __('Upgrade account') . '. ' . $errorDetail . '
+
';
+ return $html;
+ } else {
+ $html = '
';
+ return $html;
+ }
+ break;
+ case 'multiple accounts' :
+ $html = '
+
+
+
' . __('The key that you entered is for a LinksAlpha account that is different from the currently used account for this website. You can use API key from only one account on this website. Please input a valid
User or
Network API key and try again') . '.
+
+
+ ';
+ return $html;
+ break;
+ case 'no networks' :
+ $html = '
+
+
' . __('You should first authorize LinksAlpha to publish to your social network profiles') . '
' . __('Click Here') . ' ' . __('to get started.') . '
+
+
';
+ return $html;
+ break;
+ default :
+ $html = '
+
+
+
' . __('Your website is not able to connect to LinksAlpha.com. This might be due to:') . '
+
+
+ ' . __('An issue with your hosting company where they might be preventing HTTP calls to external sites.') . '
+ ' . __('A plugin you are using has overwritten the .htaccess preventing access to external websites') . '
+
+
+
+
+
';
+ return $html;
+ break;
+ }
+}
+
+function networkpub_get_plugin_dir() {
+
+ global $wp_version;
+ if (version_compare($wp_version, '2.8', '<')) {
+ $path = dirname(plugin_basename(__FILE__));
+ if ($path == '.')
+ $path = '';
+ $plugin_path = trailingslashit(plugins_url($path));
+ } else {
+ $plugin_path = trailingslashit(plugins_url('', __FILE__));
+ }
+ return $plugin_path;
+}
+
+function networkpub_activate() {
+ $networkpub_eget = get_bloginfo('admin_email');
+ $networkpub_uget = get_bloginfo('url');
+ $networkpub_nget = get_bloginfo('name');
+ $networkpub_dget = get_bloginfo('description');
+ $networkpub_cget = get_bloginfo('charset');
+ $networkpub_vget = get_bloginfo('version');
+ $networkpub_lget = get_bloginfo('language');
+ $link = 'http://www.linksalpha.com/a/bloginfo';
+ $networkpub_bloginfo = array('email' => $networkpub_eget, 'url' => $networkpub_uget, 'name' => $networkpub_nget, 'desc' => $networkpub_dget, 'charset' => $networkpub_cget, 'version' => $networkpub_vget, 'lang' => $networkpub_lget, 'plugin' => NETWORKPUB_WIDGET_NAME_INTERNAL_NW);
+ networkpub_http_post($link, $networkpub_bloginfo);
+ $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
+ if (empty($options['id_2']) or empty($options['api_key'])) {
+ return;
+ }
+ $link = 'http://www.linksalpha.com/a/networkpubconvertdirect';
+ $params = array('id' => $options['id_2'], 'key' => $options['api_key'], 'plugin' => NETWORKPUB_WIDGET_NAME_INTERNAL_NW, );
+ $response_full = networkpub_http_post($link, $params);
+ $response_code = $response_full[0];
+ return;
+}
+
+function networkpub_deactivate() {
+ $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
+ if (empty($options['id_2']) or empty($options['api_key'])) {
+ return;
+ }
+ // Build Params
+ $link = 'http://www.linksalpha.com/a/networkpubconvertfeed';
+ $params = array('id' => $options['id_2'], 'key' => $options['api_key'], );
+ //HTTP Call
+ $response_full = networkpub_http_post($link, $params);
+ $response_code = $response_full[0];
+ return;
+}
+
+function networkpub_pushpresscheck() {
+ $active_plugins = get_option('active_plugins');
+ $pushpress_plugin = 'pushpress/pushpress.php';
+ $this_plugin_key = array_search($pushpress_plugin, $active_plugins);
+ if ($this_plugin_key) {
+ $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
+ if (array_key_exists('id', $options)) {
+ if (!empty($options['id_2'])) {
+ $link = 'http://www.linksalpha.com/a/pushpress';
+ $body = array('id' => $options['id_2']);
+ $response_full = networkpub_http_post($link, $body);
+ $response_code = $response_full[0];
+ }
+ }
+ }
+}
+
+function networkpub_postbox_url() {
+ global $wp_version;
+ if (version_compare($wp_version, '3.0.0', '<')) {
+ $admin_url = site_url() . '/wp-admin/edit.php?page=' . NETWORKPUB_WIDGET_NAME_POSTBOX_INTERNAL;
+ } else {
+ $admin_url = site_url() . '/wp-admin/edit.php?page=' . NETWORKPUB_WIDGET_NAME_POSTBOX_INTERNAL;
+ }
+ return $admin_url;
+}
+
+function networkpub_version() {
+ return NETWORKPUB_PLUGIN_VERSION;
+}
+
+function networkpub_get_posts() {
+ if (!empty($_GET['linksalpha_request_type'])) {
+ $args = array('numberposts' => 20, 'offset' => 0, 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => 'post', 'post_status' => 'publish');
+ $posts_array = get_posts($args);
+ $html = '';
+ $html .= '';
+ $html .= '';
+ $html .= '';
+ $html .= '';
+ $html .= '
';
+ $html .= '--- ';
+ foreach ($posts_array as $post) {
+ $params = array();
+ $post_link = get_permalink($post->ID);
+ $params['content_link'] = $post_link;
+ $params['title'] = trim(strip_tags($post -> post_title));
+ $params['content_text'] = trim(strip_tags($post -> post_title));
+ $params['content_body'] = trim(strip_tags($post -> post_content));
+ $post_image = networkpub_thumbnail_link($post_id, $post -> post_content);
+ if ($post_image) {
+ $params['content_image'] = $post_image;
+ }
+ $form_data = http_build_query($params);
+ $html .= '' . $post -> post_title . ' ';
+ }
+ $html .= ' ';
+ echo $html;
+ }
+ return;
+}
+
+function networkpub_fb_langs() {
+ $langs = array();
+ $response_full = networkpub_http_post("http://www.facebook.com/translations/FacebookLocales.xml", array());
+ $response_code = $response_full[0];
+ if ($response_code == 200) {
+ preg_match_all('/
\s*([^<]+)<\/englishName>\s*\s*\s*.+?([^<]+)<\/representation>/s', utf8_decode($response_full[1]), $langslist, PREG_PATTERN_ORDER);
+ foreach ($langslist[1] as $key => $val) {
+ $langs[$langslist[2][$key]] = $val;
+ }
+ } else {
+ $langs['default'] = "Default";
+ }
+ return $langs;
+}
+
+function networkpub_add_metatags() {
+ $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
+ if (!is_array($options)) {
+ return;
+ }
+ if (!array_key_exists('networkpub_metatags_facebook', $options)) {
+ return;
+ }
+ $networkpub_metatags_facebook = $options['networkpub_metatags_facebook'];
+ $networkpub_metatags_googleplus = $options['networkpub_metatags_googleplus'];
+ if (!$networkpub_metatags_facebook and !$networkpub_metatags_googleplus) {
+ return;
+ }
+ global $posts;
+ //Site name
+ $og_site_name = get_bloginfo('name');
+ //Set defaults for video types
+ $og_video = '';
+ $og_video_type = '';
+ //Post or Page
+ if (is_single() || is_page()) {
+ //Post data
+ $post_data = get_post($posts[0]->ID, ARRAY_A);
+ //Title
+ $og_title = networkpub_prepare_text($post_data['post_title']);
+ //Link
+ $og_link = get_permalink($posts[0]->ID);
+ //Image or Video
+ $networkpub_post_image_video = get_post_meta($posts[0]->ID, 'networkpub_post_image_video', true);
+ if($networkpub_post_image_video == 'image') {
+ $og_link_image = networkpub_thumbnail_link($posts[0]->ID, $post_data['post_content']);
+ } else {
+ $og_link_image = get_post_meta($posts[0]->ID, 'networkpub_video_picture', true);
+ $og_video = get_post_meta($posts[0]->ID, 'networkpub_video_source', true);
+ $og_video_type = "application/x-shockwave-flash";
+ }
+ //Content
+ if (!empty($post_data['post_excerpt'])) {
+ $og_desc = $post_data['post_excerpt'];
+ } else {
+ $og_desc = $post_data['post_content'];
+ }
+ $og_desc = networkpub_prepare_text($og_desc);
+ //Facebook Page Type
+ $post_ogtypefacebook = get_post_meta($posts[0]->ID, 'networkpub_ogtype_facebook', true);
+ if ($post_ogtypefacebook) {
+ $og_type = $post_ogtypefacebook;
+ } else {
+ if (!empty($options['networkpub_facebook_page_type'])) {
+ $og_type = $options['networkpub_facebook_page_type'];
+ } else {
+ $og_type = 'article';
+ }
+ }
+ } else {
+ //Title
+ $og_title = networkpub_prepare_text($og_site_name);
+ //Link
+ $og_link = get_bloginfo('url');
+ //Image Link
+ $og_link_image = '';
+ //Desc
+ $og_desc = get_bloginfo('description');
+ $og_desc = networkpub_prepare_text($og_desc);
+ //Type
+ $og_type = 'website';
+ }
+ if (!empty($options['networkpub_lang_facebook'])) {
+ $og_locale = $options['networkpub_lang_facebook'];
+ } else {
+ $og_locale = 'en_US';
+ }
+ if (!empty($options['networkpub_facebook_app_id'])) {
+ $og_fb_app_id = $options['networkpub_facebook_app_id'];
+ } else {
+ $og_fb_app_id = '';
+ }
+ //Google Plus Page Type
+ if (!empty($options['networkpub_googleplus_page_type'])) {
+ $og_type_google = $options['networkpub_googleplus_page_type'];
+ } else {
+ $og_type_google = 'Article';
+ }
+ if ($networkpub_metatags_facebook) {
+ networkpub_build_meta_facebook($og_site_name, $og_title, $og_link, $og_link_image, $og_desc, $og_type, $og_locale, $og_fb_app_id, $og_video, $og_video_type);
+ }
+ if ($networkpub_metatags_googleplus) {
+ networkpub_build_meta_googleplus($og_title, $og_link_image, $og_desc, $og_type_google);
+ }
+ return;
+}
+
+function networkpub_build_meta_facebook($og_site_name, $og_title, $og_link, $og_link_image, $og_desc, $og_type, $og_locale, $og_fb_app_id, $og_video, $og_video_type) {
+ $opengraph_meta = '';
+ if ($og_site_name) {
+ $opengraph_meta .= "\n ";
+ }
+ if ($og_title) {
+ $opengraph_meta .= "\n ";
+ }
+ if ($og_link) {
+ $opengraph_meta .= "\n ";
+ }
+ if ($og_link_image) {
+ $opengraph_meta .= "\n ";
+ }
+ if ($og_video) {
+ $opengraph_meta .= "\n ";
+ }
+ if ($og_video_type) {
+ $opengraph_meta .= "\n ";
+ }
+ if ($og_desc) {
+ $opengraph_meta .= "\n ";
+ }
+ if ($og_type) {
+ $opengraph_meta .= "\n ";
+ }
+ if ($og_locale) {
+ $opengraph_meta .= "\n ";
+ }
+ if ($og_fb_app_id) {
+ $opengraph_meta .= "\n ";
+ }
+ echo "\n" . $opengraph_meta . "\n\n";
+}
+
+function networkpub_build_meta_googleplus($og_title, $og_link_image, $og_desc, $og_type) {
+ $opengraph_meta = '';
+ if ($og_title) {
+ $opengraph_meta = "\n ";
+ }
+ if ($og_link_image) {
+ $opengraph_meta .= "\n ";
+ }
+ if ($og_desc) {
+ $opengraph_meta .= "\n ";
+ }
+ if ($og_type) {
+ $opengraph_meta .= "\n ";
+ }
+ echo "\n" . $opengraph_meta . "\n\n";
+}
+
+function networkpub_html_schema($attr) {
+ $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
+ if (!is_array($options)) {
+ return;
+ }
+ if (!array_key_exists('networkpub_metatags_facebook', $options)) {
+ return;
+ }
+ $networkpub_metatags_facebook = $options['networkpub_metatags_facebook'];
+ $networkpub_metatags_googleplus = $options['networkpub_metatags_googleplus'];
+ if (!$networkpub_metatags_facebook and !$networkpub_metatags_googleplus) {
+ return;
+ }
+ if ($networkpub_metatags_facebook) {
+ $attr .= " xmlns:og=\"http://opengraphprotocol.org/schema/\"";
+ $attr .= " xmlns:fb=\"http://www.facebook.com/2008/fbml\"";
+ }
+ if ($networkpub_metatags_googleplus) {
+ $networkpub_googleplus_page_type = $options['networkpub_googleplus_page_type'];
+ $attr .= " itemscope itemtype=\"http://schema.org/" . $networkpub_googleplus_page_type . "\"";
+ }
+ return $attr;
+}
+
+function networkpub_prepare_text($text) {
+ $text = stripslashes($text);
+ $text = strip_tags($text);
+ $text = preg_replace("/\[.*?\]/", '', $text);
+ $text = preg_replace('/([\n \t\r]+)/', ' ', $text);
+ $text = preg_replace('/( +)/', ' ', $text);
+ $text = preg_replace('/\s\s+/', ' ', $text);
+ $text = networkpub_prepare_string($text, 310);
+ $text = networkpub_smart_truncate($text, 300);
+ $text = trim($text);
+ $text = htmlspecialchars($text);
+ return $text;
+}
+
+function networkpub_smart_truncate($string, $required_length) {
+ $parts = preg_split('/([\s\n\r]+)/', $string, null, PREG_SPLIT_DELIM_CAPTURE);
+ $parts_count = count($parts);
+ $length = 0;
+ $last_part = 0;
+ for (; $last_part < $parts_count; ++$last_part) {
+ $length += strlen($parts[$last_part]);
+ if ($length > $required_length) {
+ break;
+ }
+ }
+ return implode(array_slice($parts, 0, $last_part));
+}
+
+function networkpub_prepare_string($string, $string_length) {
+ $final_string = '';
+ $utf8marker = chr(128);
+ $count = 0;
+ while (isset($string{$count})) {
+ if ($string{$count} >= $utf8marker) {
+ $parsechar = substr($string, $count, 2);
+ $count += 2;
+ } else {
+ $parsechar = $string{$count};
+ $count++;
+ }
+ if ($count > $string_length) {
+ return $final_string;
+ }
+ $final_string = $final_string . $parsechar;
+ }
+ return $final_string;
+}
+
+function networkpub_startswith($haystack, $needle) {
+ $length = strlen($needle);
+ return (substr($haystack, 0, $length) === $needle);
+}
+
+function networkpub_endswith($haystack, $needle) {
+ $length = strlen($needle);
+ if ($length == 0) {
+ return true;
+ }
+ return (substr($haystack, -$length) === $needle);
+}
+
+function networkpub_thumbnail_link($post_id, $post_content) {
+ $options = get_option(NETWORKPUB_WIDGET_NAME_INTERNAL);
+ if (is_array($options)) {
+ if ((!empty($options['networkpub_custom_field_image'])) && (!empty($options['networkpub_custom_field_image_url']))) {
+ $networkpub_custom_field_image = $options['networkpub_custom_field_image'];
+ $networkpub_custom_field_image_url = $options['networkpub_custom_field_image_url'];
+ $post_data_custom = get_post_custom($post_id, ARRAY_A);
+ if ((!empty($post_data_custom[$networkpub_custom_field_image]) ) ) {
+ $post_data_custom_image = $post_data_custom[$networkpub_custom_field_image][0];
+ if ( ( !networkpub_endswith($networkpub_custom_field_image_url, "/") && !networkpub_startswith($post_data_custom_image, "/") ) ) {
+ return $networkpub_custom_field_image_url . '/' . $post_data_custom_image;
+ } elseif ( !networkpub_endswith($networkpub_custom_field_image_url, "/") && networkpub_startswith($post_data_custom_image, "/") ) {
+ return $networkpub_custom_field_image_url . $post_data_custom_image;
+ } elseif ( networkpub_endswith($networkpub_custom_field_image_url, "/") && !networkpub_startswith($post_data_custom_image, "/") ) {
+ return $networkpub_custom_field_image_url . $post_data_custom_image;
+ } elseif ( networkpub_endswith($networkpub_custom_field_image_url, "/") && networkpub_startswith($post_data_custom_image, "/") ){
+ $networkpub_custom_field_image_url = rtrim($networkpub_custom_field_image_url, "/");
+ return $networkpub_custom_field_image_url . $post_data_custom_image;
+ }
+ }
+ } elseif ((!empty($options['networkpub_custom_field_image'])) && (empty($options['networkpub_custom_field_image_url']))) {
+ $networkpub_custom_field_image = $options['networkpub_custom_field_image'];
+ $post_data_custom = get_post_custom($post_id, ARRAY_A);
+ if ((!empty($post_data_custom[$networkpub_custom_field_image]))) {
+ return $post_data_custom[$networkpub_custom_field_image][0];
+ }
+ }
+ }
+ if (is_array($options)) {
+ if (!empty($options['networkpub_thumbnail_size'])) {
+ $networkpub_thumbnail_size = $options['networkpub_thumbnail_size'];
+ }
+ }
+ if (function_exists('get_post_thumbnail_id') and function_exists('wp_get_attachment_image_src')) {
+ $src = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), $networkpub_thumbnail_size);
+ if ($src) {
+ $src = $src[0];
+ return $src;
+ }
+ }
+ if (!$post_content) {
+ return False;
+ }
+ if (class_exists("DOMDocument") and function_exists('simplexml_import_dom')) {
+ libxml_use_internal_errors(true);
+ $doc = new DOMDocument();
+ if (!($doc->loadHTML($post_content))) {
+ return False;
+ }
+ try {
+ $xml = @simplexml_import_dom($doc);
+ if ($xml) {
+ $images = $xml -> xpath('//img');
+ if (!empty($images)) {
+ return $images[0]['src'];
+ }
+ } else {
+ return False;
+ }
+ } catch (Exception $e) {
+ return False;
+ }
+ }
+ return False;
+}
+
+function networkpub_video($post_id, $post_content) {
+ if (!$post_content) {
+ return;
+ }
+ $link = 'http://www.linksalpha.com/a/networkpubvideoinfo';
+ $params = array('post_content' => $post_content,
+ 'plugin' => NETWORKPUB_WIDGET_NAME_INTERNAL_NW,
+ 'plugin_version' => networkpub_version(),
+ );
+ $response_full = networkpub_http_post($link, $params);
+ $response_code = $response_full[0];
+ if ($response_code != 200) {
+ return;
+ }
+ $response = networkpub_json_decode($response_full[1]);
+ if ($response->errorCode > 0) {
+ return;
+ }
+ update_post_meta($post_id, 'networkpub_video_source', $response->results->source);
+ update_post_meta($post_id, 'networkpub_video_picture', $response->results->picture);
+ return;
+}
+
+register_deactivation_hook(__FILE__, 'networkpub_deactivate');
?>
\ No newline at end of file