NextScripts: Social Networks Auto-Poster - Version 2.7.22

Version Description

[10/26/2013] =

  • Critical Bug Fix - Showing post contents instead of saving it..
Download this release

Release Info

Developer NextScripts
Plugin Icon 128x128 NextScripts: Social Networks Auto-Poster
Version 2.7.22
Comparing to
See all releases

Code changes from version 2.7.14 to 2.7.22

NextScripts_SNAP.php CHANGED
@@ -4,11 +4,11 @@ Plugin Name: NextScripts: Social Networks Auto-Poster
4
  Plugin URI: http://www.nextscripts.com/social-networks-auto-poster-for-wordpress
5
  Description: This plugin automatically publishes posts from your blog to multiple accounts on Facebook, Twitter, and Google+ profiles and/or pages.
6
  Author: Next Scripts
7
- Version: 2.7.14
8
  Author URI: http://www.nextscripts.com
9
  Copyright 2012 Next Scripts, Inc
10
  */
11
- define( 'NextScripts_SNAP_Version' , '2.7.14' ); require_once "nxs_functions.php";
12
  //## Include All Available Networks
13
  global $nxs_snapAvNts, $nxs_snapThisPageUrl, $nxs_plurl, $nxs_isWPMU, $nxs_tpWMPU;
14
  if (!isset($nxs_snapAvNts) || !is_array($nxs_snapAvNts)) $nxs_snapAvNts = array(); $nxs_snapAPINts = array(); foreach (glob(plugin_dir_path( __FILE__ ).'inc-cl/*.php') as $filename){ require_once $filename; }
@@ -35,7 +35,8 @@ if (!class_exists("NS_SNAutoPoster")) {
35
  //## Some Default Values
36
  //$options = array('nsOpenGraph'=>1);
37
  $dbOptions = get_option($this->dbOptionsName);
38
- $this->nxs_ntoptions = get_site_option($this->dbOptionsName);
 
39
  if ($nxs_isWPMU && $blog_id>1) { switch_to_blog(1); $dbMUOptions = get_option($this->dbOptionsName);
40
  if (function_exists('nxs_getInitAdd')) nxs_getInitAdd($dbMUOptions); restore_current_blog();
41
  $dbOptions['lk'] = $dbMUOptions['lk']; $dbOptions['ukver'] = $dbMUOptions['ukver']; $dbOptions['uklch'] = $dbMUOptions['uklch']; $dbOptions['uk'] = $dbMUOptions['uk'];
@@ -176,7 +177,7 @@ define('WP_ALLOW_MULTISITE', true);<br/>to<br/>define('WP_ALLOW_MULTISITE', fals
176
  if ($nxs_isWPMU && (!isset($options['suaMode'])||$options['suaMode'] == '')) $options['suaMode'] = $nxs_tpWMPU;
177
  $editable_roles = get_editable_roles(); foreach ( $editable_roles as $roleX => $details ) {$role = get_role($roleX); $role->remove_cap('see_snap_box'); $role->remove_cap('make_snap_posts'); }
178
 
179
- foreach ($options['whoCanSeeSNAPBox'] as $uRole) { $role = get_role($uRole); $role->add_cap('see_snap_box'); }
180
  foreach ($options['whoCanMakePosts'] as $uRole) { $role = get_role($uRole); $role->add_cap('make_snap_posts'); }
181
 
182
  update_option($this->dbOptionsName, $options); // prr($options);
@@ -226,11 +227,12 @@ if ( is_array($category_ids) && is_array($pk) && count($category_ids) == count($
226
  <div id="fbSelCats<?php echo $ii; ?>" class="categorydivInd" style="padding-left: 15px; background-color: #fff;">
227
  <a href="#" onclick="nxs_chAllCatsL(1, 'fbSelCats<?php echo $ii; ?>'); return false;">Check all</a> &nbsp;|&nbsp; <a href="#" onclick="nxs_chAllCatsL(0, 'fbSelCats<?php echo $ii; ?>'); return false;">UnCheck all</a>
228
  <div id="category-all" class="tabs-panel"> <input type="hidden" id="tmpCatSelNT" name="tmpCatSelNT" value="" />
229
- <ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
230
- <?php if (function_exists('wp_terms_checklist')) wp_terms_checklist(0, $args ); ?>
 
231
  </ul>
232
  </div>
233
- </div> <div class="submit"><input type="button" id="" class="button-primary" name="btnSelCats" onclick="nxs_doSetSelCats( jQuery('#tmpCatSelNT').val() ); $('#showCatSel').bPopup().close();" value="Select Categories" /></div>
234
  </div>
235
 
236
  <?php wp_nonce_field( 'nsDN', 'nsDN_wpnonce' );
@@ -621,8 +623,8 @@ Please see #4 and #5 for Twitter:<br/>
621
  <br/><br/><br/>This version of the plugin is not compatible with <b>Wordpress Multisite Edition</b>. Please contact your Network Admin for the upgrade. <?php }
622
 
623
  function NS_SNAP_ShowPageTop(){ global $nxs_snapAvNts, $nxs_snapThisPageUrl, $nxsOne, $nxs_plurl, $nxs_isWPMU; $nxsOne = ''; $options = $this->nxs_options;
624
- $nxsOne = NextScripts_SNAP_Version; if (defined('NXSAPIVER')) $nxsOne .= " (<span id='nxsAPIUpd'>API</span> Version: ".NXSAPIVER.")"; ?>
625
-
626
 
627
  <div style="float:right; padding-top: 10px; padding-right: 10px;">
628
  <div style="float:right; text-align: center;"><a target="_blank" href="http://www.nextscripts.com"><img src="<?php echo $nxs_plurl; ?>img/Next_Scripts_Logo2.1-HOR-100px.png"></a><br/>
@@ -667,24 +669,25 @@ Please see #4 and #5 for Twitter:<br/>
667
  <?php }
668
  }
669
 
670
- function NS_SNAP_SavePostMetaTags($id) { global $nxs_snapAvNts, $plgn_NS_SNAutoPoster; if (!isset($plgn_NS_SNAutoPoster)) return; $options = $plgn_NS_SNAutoPoster->nxs_options; // echo "| NS_SNAP_SavePostMetaTags - ".$id." |";
671
- $post = get_post($id); if ($post->post_type=='revision' && $post->post_status=='inherit' && $post->post_parent!='0') return;
672
- if (isset($_POST["snapEdIT"])) $nspost_edit = $_POST["snapEdIT"]; //echo "| snapEdIT |"; // prr($nspost_edit);
673
- if (get_magic_quotes_gpc() || $_POST['nxs_mqTest']=="\'"){ array_walk_recursive($_POST, 'nsx_stripSlashes'); }
674
- $snap_isAutoPosted = get_post_meta($id, 'snap_isAutoPosted', true); if ($snap_isAutoPosted=='1' && $post->post_status=='future') { delete_post_meta($id, 'snap_isAutoPosted'); add_post_meta($id, 'snap_isAutoPosted', '2'); }
675
- if (isset($nspost_edit) && !empty($nspost_edit)) { delete_post_meta($id, 'snapEdIT'); add_post_meta($id, 'snapEdIT', '1' );
676
- foreach ($nxs_snapAvNts as $avNt) {
 
677
  if (count($options[$avNt['lcode']])>0 && isset($_POST[$avNt['lcode']]) && count($_POST[$avNt['lcode']])>0) { $savedMeta = maybe_unserialize(get_post_meta($id, 'snap'.$avNt['code'], true));
678
  if(is_array($_POST[$avNt['lcode']])) { $ii=0;
679
- foreach ($_POST[$avNt['lcode']] as $pst ) { // echo "#############################################################################"; prr($pst);
680
- if (is_array($pst) && $pst['do'.$avNt['code']]=='' && $_POST[$avNt['lcode']][$ii]['do'.$avNt['code']]=='') $_POST[$avNt['lcode']][$ii]['do'.$avNt['code']]= 0; $ii++;
681
  }
682
  } $newMeta = $_POST[$avNt['lcode']];
683
  if (is_array($savedMeta) && is_array($newMeta)) $newMeta = nxsMergeArraysOV($savedMeta, $newMeta); // echo "##### ".$id."| snap".$avNt['code']; prr($savedMeta); echo "||"; prr($newMeta);// $newMeta = 'AAA';
684
  delete_post_meta($id, 'snap'.$avNt['code']); add_post_meta($id, 'snap'.$avNt['code'], serialize($newMeta));
685
  }
686
  }
687
- } // prr($_POST);
688
  }
689
 
690
  function NS_SNAP_AddPostMetaTags() { global $post, $nxs_snapAvNts, $plgn_NS_SNAutoPoster; $post_id = $post; if (is_object($post_id)) $post_id = $post_id->ID; if (!is_object($post)) $post = get_post($post_id);
@@ -705,7 +708,7 @@ Please see #4 and #5 for Twitter:<br/>
705
  <?php } ?>
706
  <table style="margin-bottom:40px; clear:both;" width="100%" border="0"><?php
707
  foreach ($nxs_snapAvNts as $avNt) { $clName = 'nxs_snapClass'.$avNt['code'];
708
- if (count($options[$avNt['lcode']])>0) { $ntClInst = new $clName(); $ntClInst->showEdPostNTSettings($options[$avNt['lcode']], $post); }
709
  }
710
  ?></table></div></div></div> <?php
711
  }
@@ -716,7 +719,7 @@ Please see #4 and #5 for Twitter:<br/>
716
  if ($options['useForPages']=='1') add_meta_box( 'NS_SNAP_AddPostMetaTags', __( 'NextScripts: Social Networks Auto Poster - Post Options', 'nxs_snap' ), array($this, 'NS_SNAP_AddPostMetaTags'), 'page' );
717
 
718
  $args=array('public'=>true, '_builtin'=>false); $output = 'names'; $operator = 'and'; $post_types = array(); if (function_exists('get_post_types')) $post_types=get_post_types($args, $output, $operator);
719
- if ((isset($options['nxsCPTSeld'])) && $options['nxsCPTSeld']!='') $nxsCPTSeld = unserialize($options['nxsCPTSeld']); else $nxsCPTSeld = array_keys($post_types); //prr($nxsCPTSeld);
720
  foreach ($post_types as $cptID=>$cptName) if (in_array($cptID, $nxsCPTSeld)){
721
  add_meta_box( 'NS_SNAP_AddPostMetaTags', __('NextScripts: Social Networks Auto Poster - Post Options', 'nxs_snap'), array($this, 'NS_SNAP_AddPostMetaTags'), $cptID );
722
  }
@@ -724,6 +727,18 @@ Please see #4 and #5 for Twitter:<br/>
724
  }
725
  }
726
 
 
 
 
 
 
 
 
 
 
 
 
 
727
  if (class_exists("NS_SNAutoPoster")) { nxs_checkAddLogTable(); $plgn_NS_SNAutoPoster = new NS_SNAutoPoster(); }
728
  //## Delete Account
729
  if (!function_exists("ns_delNT_ajax")) { function ns_delNT_ajax(){ check_ajax_referer('nsDN'); $indx = (int)$_POST['id'];
@@ -792,50 +807,57 @@ if (!function_exists("NS_SNAutoPoster_apx")) { function NS_SNAutoPoster_apx() {
792
  }}}
793
 
794
  //## Main Function to Post
 
 
 
795
  if (!function_exists("nxs_snapPublishTo")) { function nxs_snapPublishTo($postArr, $type='', $aj=false) { global $plgn_NS_SNAutoPoster, $nxs_snapAvNts, $blog_id, $nxs_tpWMPU; // echo " | nxs_doSMAS2 | "; prr($postArr);
796
- if (!isset($plgn_NS_SNAutoPoster)) return; $options = $plgn_NS_SNAutoPoster->nxs_options;
797
- if(is_object($postArr)) $postID = $postArr->ID; else { $postID = $postArr; $postArr = get_post($postID); } $isPost = isset($_POST["snapEdIT"]);
798
- if ($isPost && $options['skipSecurity']!='1' && !current_user_can("make_snap_posts") && !current_user_can("manage_options")) { nxs_addToLogN('I', 'Skipped', '', 'Current user can\'t autopost - Post ID:('.$postID.')' ); return; }
799
- $postUser = $postArr->post_author;
800
- if ($options['skipSecurity']!='1' && !user_can( $postUser, "make_snap_posts" ) && !user_can( $postUser, "manage_options")){ nxs_addToLogN('I', 'Skipped', '', 'User ID '.$postUser.' can\'t autopost - Post ID:('.$postID.')' ); return; }
801
- if ($isPost) $plgn_NS_SNAutoPoster->NS_SNAP_SavePostMetaTags($postID);
802
- if (function_exists('nxs_doSMAS2')) { nxs_doSMAS2($postArr, $type, $aj); return; } else {
803
- $options = $plgn_NS_SNAutoPoster->nxs_options; $ltype=strtolower($type);
804
- if ($nxs_tpWMPU=='S') { switch_to_blog(1); $plgn_NS_SNAutoPoster = new NS_SNAutoPoster(); $options = $plgn_NS_SNAutoPoster->nxs_options; restore_current_blog(); }
805
- if (!isset($options['nxsHTDP']) || $options['nxsHTDP']=='S') { if(isset($_POST["snapEdIT"]) && $_POST["snapEdIT"]=='1') { $publtype='S'; $delay = rand(2,10); } else $publtype='A'; } else $publtype = 'I';
806
- nxs_addToLogN('BG', 'Start =- ', '', '------=========#### NEW AUTO-POST REQUEST '.($blog_id>1?'BlogID:'.$blog_id:'').' PostID:('.$postID.') '.($publtype=='S'?'Scheduled +'.$delay:($publtype=='A'?'Non Human':'Immediate')).' ####=========------');
807
- $post = get_post($postID); $args=array( 'public' => true, '_builtin' => false); $output = 'names'; $operator = 'and'; $post_types = array(); if (function_exists('get_post_types')) $post_types=get_post_types($args, $output, $operator);
808
- $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted=='1') { nxs_addToLogN('W', 'Skipped', '', 'Already Autoposted - Post ID:('.$postID.')' ); return; }
809
- $snap_isEdIT = get_post_meta($postID, 'snapEdIT', true); if ($snap_isEdIT!='1') { $doPost = true; $exclCats = maybe_unserialize($options['exclCats']); $postCats = wp_get_post_categories($postID);
810
- foreach ($postCats as $pCat) { if ( (is_array($exclCats)) && in_array($pCat, $exclCats)) $doPost = false; else {$doPost = true; break;}}
811
- if (!$doPost) { nxs_addToLogN('I', 'Skipped', '', 'Non-Human Post - Category Excluded - Post ID:('.$postID.')' ); return; }
812
- }
813
- if ($options['nxsCPTSeld']!='') $nxsCPTSeld = unserialize($options['nxsCPTSeld']); else $nxsCPTSeld = array_keys($post_types); //prr($nxsCPTSeld);
814
 
815
- if ($post->post_type == 'post'|| ($options['useForPages']=='1' && $post->post_type == 'page') || in_array($post->post_type, $post_types) && in_array($post->post_type, $nxsCPTSeld)) foreach ($nxs_snapAvNts as $avNt) {
816
- if (count($options[$avNt['lcode']])>0) { $clName = 'nxs_snapClass'.$avNt['code'];
817
- if ($isPost && isset($_POST[$avNt['lcode']])) $po = $_POST[$avNt['lcode']]; else { $po = get_post_meta($postID, 'snap'.$avNt['code'], true); $po = maybe_unserialize($po);}
 
 
818
 
819
- if (isset($po) && is_array($po)) $isPostMeta = true; else { $isPostMeta = false; $po = $options[$avNt['lcode']]; }
820
- delete_post_meta($postID, 'snap_isAutoPosted'); add_post_meta($postID, 'snap_isAutoPosted', '1');
 
821
 
822
- $optMt = $options[$avNt['lcode']][0]; if ($isPostMeta) { $ntClInst = new $clName(); $optMt = $ntClInst->adjMetaOpt($optMt, $po[0]); }
823
- if ($snap_isEdIT!='1') { $doPost = true;
824
- if ( $optMt['catSel']=='1' && trim($optMt['catSelEd'])!='' ) { $inclCats = explode(',',$optMt['catSelEd']); foreach ($postCats as $pCat) { if (!in_array($pCat, $inclCats)) $doPost = false; else {$doPost = true; break;}}
825
- if (!$doPost) { nxs_addToLogN('I', 'Skipped', $avNt['name'].' ('.$optMt['nName'].')', '[Non-Human Post] - Individual Category Excluded - Post ID:('.$postID.')' ); return; }
826
- }
827
- }
828
- if ($optMt['do'.$avNt['code']]=='1') { $optMt['ii'] = 0;
829
- if ($publtype=='A' && ($optMt['nMin']>0 || $optMt['nHrs']>0 || $optMt['nTime']!='')) $publtype='S';
830
- if ($publtype=='S') { if (isset($optMt['nHrs']) && isset($optMt['nMin']) && ($optMt['nHrs']>0 || $optMt['nMin']>0) ) { $delay = $optMt['nMin']*60+$optMt['nHrs']*3600;
831
- nxs_addToLogN('I', 'Delayed', $avNt['name'].' ('.$optMt['nName'].')', 'Post has been delayed for '.$delay.' Seconds ('.($optMt['nHrs']>0?$optMt['nHrs'].' Hours':'')." ".($optMt['nMin']>0?$optMt['nMin'].' Minutes':'').')' );
832
- } else $delay = rand(2,10); $optMt['timeToRun'] = time()+$delay; $args = array($postID, $optMt); wp_schedule_single_event($optMt['timeToRun'],'ns_doPublishTo'.$avNt['code'], $args);
833
- nxs_addToLogN('BI', 'Scheduled', $avNt['name'].' ('.$optMt['nName'].')', ' PostID:('.$postID.')' );
834
- } else { $fname = 'nxs_doPublishTo'.$avNt['code']; $fname($postID, $optMt); }
835
- } else { nxs_addToLogN('GR', 'Skipped', $avNt['name'].' ('.$optMt['nName'].')', '-=[Unchecked Account]=- - PostID:'.$postID.'' ); }
836
- }
837
- }
838
- } if ($isS) restore_current_blog();
 
 
 
839
  }}
840
 
841
  //## AJAX to Post to Google+
@@ -851,19 +873,6 @@ if (!function_exists("ns_add_settings_link")) { function ns_add_settings_link($l
851
  return $links;
852
  }}
853
  //## Actions and filters
854
- if (!function_exists("ns_custom_types_setup")) { function ns_custom_types_setup(){ global $plgn_NS_SNAutoPoster; if (!isset($plgn_NS_SNAutoPoster)) return; $options = $plgn_NS_SNAutoPoster->nxs_options;
855
- $args=array('public'=>true, '_builtin'=>false); $output = 'names'; $operator = 'and'; $post_types = array(); if (function_exists('get_post_types')) $post_types=get_post_types($args, $output, $operator);
856
- if ( isset($options['nxsCPTSeld']) && $options['nxsCPTSeld']!='') $nxsCPTSeld = unserialize($options['nxsCPTSeld']); else $nxsCPTSeld = array_keys($post_types); //prr($nxsCPTSeld);
857
-
858
- foreach ($post_types as $cptID=>$cptName) if (in_array($cptID, $nxsCPTSeld)){ // echo "|".$cptID."|";
859
- add_action('future_to_publish_'.$cptID, 'nxs_snapPublishTo');
860
- add_action('new_to_publish_'.$cptID, 'nxs_snapPublishTo');
861
- add_action('draft_to_publish_'.$cptID, 'nxs_snapPublishTo');
862
- add_action('pending_to_publish_'.$cptID, 'nxs_snapPublishTo');
863
- add_action('private_to_publish_'.$cptID, 'nxs_snapPublishTo');
864
- add_action('auto-draft_to_publish_'.$cptID, 'nxs_snapPublishTo');
865
- }
866
- }}
867
 
868
  //## Process Spin
869
  if (!function_exists("nxs_spinRecursion")) { function nxs_spinRecursion(&$txt, $startCh) { global $nxs_spin_lCh, $nxs_spin_rCh, $nxs_spin_splCh; $startPos = $startCh;
@@ -882,7 +891,7 @@ if (!function_exists("nxs_doSpin")) { function nxs_doSpin($msg){ global $nxs_sp
882
 
883
  //## Format Message
884
  if (!function_exists("nsFormatMessage")) { function nsFormatMessage($msg, $postID, $addURLParams=''){ global $ShownAds, $plgn_NS_SNAutoPoster, $nxs_urlLen; $post = get_post($postID); $options = $plgn_NS_SNAutoPoster->nxs_options;
885
- // if ($addURLParams=='' && $options['addURLParams']!='') $addURLParams = $options['addURLParams'];
886
  $msg = stripcslashes($msg); if (isset($ShownAds)) $ShownAdsL = $ShownAds; // $msg = htmlspecialchars(stripcslashes($msg));
887
  $msg = nxs_doSpin($msg);
888
  if (preg_match('%URL%', $msg)) { $url = get_permalink($postID); if($addURLParams!='') $url .= (strpos($url,'?')!==false?'&':'?').$addURLParams; $nxs_urlLen = nxs_strLen($url); $msg = str_ireplace("%URL%", $url, $msg);}
@@ -894,9 +903,9 @@ if (!function_exists("nsFormatMessage")) { function nsFormatMessage($msg, $postI
894
  if (preg_match('%STITLE%', $msg)) { $title = nxs_doQTrans($post->post_title, $lng); $title = substr($title, 0, 115); $msg = str_ireplace("%STITLE%", $title, $msg); }
895
  if (preg_match('%AUTHORNAME%', $msg)) { $aun = $post->post_author; $aun = get_the_author_meta('display_name', $aun ); $msg = str_ireplace("%AUTHORNAME%", $aun, $msg);}
896
  if (preg_match('%ANNOUNCE%', $msg)) { $postContent = nxs_doQTrans($post->post_content, $lng);
897
- if (stripos($postContent, '<!--more-->')!==false) { $postContentEx = explode('<!--more-->',$postContent); $postContent = $postContentEx[0]; }
898
- elseif (stripos($postContent, '&lt;!--more--&gt;')!==false) { $postContentEx = explode('&lt;!--more--&gt;',$postContent); $postContent = $postContentEx[0]; }
899
- else $postContent = nsTrnc($postContent, $options['anounTagLimit']); $msg = str_ireplace("%ANNOUNCE%", $postContent, $msg);
900
  }
901
  if (preg_match('%TEXT%', $msg)) {
902
  if ($post->post_excerpt!="") $excerpt = apply_filters('the_content', nxs_doQTrans($post->post_excerpt, $lng)); else $excerpt= apply_filters('the_content', nxs_doQTrans($post->post_content, $lng));
@@ -966,14 +975,15 @@ function nxs_start_ob(){ob_start( 'nxs_ogtgCallback' );}
966
  function nxs_end_flush_ob(){ob_end_flush();}
967
 
968
  function nxs_ogtgCallback($content){ global $post, $plgn_NS_SNAutoPoster; if (!isset($plgn_NS_SNAutoPoster)) return; $options = $plgn_NS_SNAutoPoster->nxs_options; $ogimgs = array();
 
969
  if (stripos($content, 'og:title')!==false) $ogOut = "\r\n"; else {
970
  $title = preg_match( '/<title>(.*)<\/title>/', $content, $title_matches );
971
  if ($title !== false && count( $title_matches) == 2 ) $ogT ='<meta property="og:title" content="' . $title_matches[1] . '" />'."\r\n"; else {
972
  if (is_home() || is_front_page() ) $ogT = get_bloginfo( 'name' ); else $ogT = get_the_title();
973
  $ogT = '<meta property="og:title" content="' . esc_attr( apply_filters( 'nxsog_title', $ogT ) ) . '" />'."\r\n";
974
  }
975
- $decsription = preg_match( '/<meta name="description" content="(.*)"/', $content, $description_matches );
976
- if ( $description !== false && count( $description_matches ) == 2 ) $ogD = '<meta property="og:description" content="' . $description_matches[1] . '" />'."\r\n"; {
977
  if (is_singular()) {
978
  if(has_excerpt($post->ID))$ogD=strip_tags(nxs_snapCleanHTML(get_the_excerpt($post->ID)));else $ogD= str_replace(" ", ' ', str_replace("\r\n", ' ', trim(substr(strip_tags(nxs_snapCleanHTML(strip_shortcodes($post->post_content))), 0, 200))));
979
  } else $ogD = get_bloginfo('description'); $ogD = preg_replace('/\r\n|\r|\n/m','',$ogD);
@@ -982,7 +992,9 @@ function nxs_ogtgCallback($content){ global $post, $plgn_NS_SNAutoPoster; if (!
982
  $ogSN = '<meta property="og:site_name" content="'.get_bloginfo('name').'" />'."\r\n";
983
  $ogLoc = strtolower(esc_attr(get_locale())); if (strlen($ogLoc)==2) $ogLoc .= "_".strtoupper($ogLoc);
984
  $ogLoc = '<meta property="og:locale" content="'.$ogLoc.'" />'."\r\n"; $iss = is_home();
985
- $ogType = is_singular()?'article':'website'; if($vidsFromPost == false) $ogType = '<meta property="og:type" content="'.esc_attr(apply_filters('nxsog_type', $ogType)).'" />'."\r\n";
 
 
986
 
987
  if (is_home() || is_front_page()) $ogUrl = get_bloginfo( 'url' ); else $ogUrl = 'http' . (is_ssl() ? 's' : '') . "://".$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
988
  $ogUrl = '<meta property="og:url" content="'.esc_url( apply_filters( 'nxsog_url', $ogUrl ) ) . '" />' . "\r\n";
@@ -995,7 +1007,7 @@ function nxs_ogtgCallback($content){ global $post, $plgn_NS_SNAutoPoster; if (!
995
  echo '<meta property="og:image" content="http://i2.ytimg.com/vi/'.$vidsFromPost[0].'/mqdefault.jpg" />'."\n";
996
  echo '<meta property="og:type" content="video" />'."\n";
997
  } */
998
- if (function_exists('has_post_thumbnail') && has_post_thumbnail($post->ID)) {
999
  $thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'thumbnail' ); $ogimgs[] = $thumbnail_src[0];
1000
  } $imgsFromPost = nsFindImgsInPost($post, (int)$options['advFindOGImg']==1);
1001
  if ($imgsFromPost !== false && is_singular() && is_array($ogimgs) && is_array($imgsFromPost)) $ogimgs = array_merge($ogimgs, $imgsFromPost);
@@ -1051,8 +1063,9 @@ if (isset($plgn_NS_SNAutoPoster)) { //## Actions
1051
  add_action('wp', 'nxs_activation');
1052
  add_action('shutdown', 'nxs_psCron');
1053
 
1054
-
1055
  if ($isO || $isS) {
 
1056
  //## Whenever you publish a post, post to Social Networks
1057
  add_action('future_to_publish', 'nxs_snapPublishTo');
1058
  add_action('new_to_publish', 'nxs_snapPublishTo');
@@ -1061,7 +1074,7 @@ if (isset($plgn_NS_SNAutoPoster)) { //## Actions
1061
  add_action('private_to_publish', 'nxs_snapPublishTo');
1062
  add_action('auto-draft_to_publish', 'nxs_snapPublishTo');
1063
  //## Add nxs_snapPublishTo to custom post types
1064
- add_action('wp_loaded', 'ns_custom_types_setup' );
1065
  foreach ($nxs_snapAvNts as $avNt) { add_action('ns_doPublishTo'.$avNt['code'], 'nxs_doPublishTo'.$avNt['code'], 1, 2); }
1066
  foreach ($nxs_snapAvNts as $avNt) { add_action('wp_ajax_rePostTo'.$avNt['code'], 'nxs_rePostTo'.$avNt['code'].'_ajax'); }
1067
 
@@ -1083,9 +1096,7 @@ if (isset($plgn_NS_SNAutoPoster)) { //## Actions
1083
  add_action('edit_post', array($plgn_NS_SNAutoPoster, 'NS_SNAP_SavePostMetaTags'));
1084
  add_action('publish_post', array($plgn_NS_SNAutoPoster, 'NS_SNAP_SavePostMetaTags'));
1085
  add_action('save_post', array($plgn_NS_SNAutoPoster, 'NS_SNAP_SavePostMetaTags'));
1086
- add_action('edit_page_form', array($plgn_NS_SNAutoPoster, 'NS_SNAP_SavePostMetaTags'));
1087
-
1088
-
1089
 
1090
  add_action('wp_ajax_nsAuthFBSv', 'nsAuthFBSv_ajax');
1091
  //## Custom Post Types and OG tags
4
  Plugin URI: http://www.nextscripts.com/social-networks-auto-poster-for-wordpress
5
  Description: This plugin automatically publishes posts from your blog to multiple accounts on Facebook, Twitter, and Google+ profiles and/or pages.
6
  Author: Next Scripts
7
+ Version: 2.7.22
8
  Author URI: http://www.nextscripts.com
9
  Copyright 2012 Next Scripts, Inc
10
  */
11
+ define( 'NextScripts_SNAP_Version' , '2.7.22' ); require_once "nxs_functions.php";
12
  //## Include All Available Networks
13
  global $nxs_snapAvNts, $nxs_snapThisPageUrl, $nxs_plurl, $nxs_isWPMU, $nxs_tpWMPU;
14
  if (!isset($nxs_snapAvNts) || !is_array($nxs_snapAvNts)) $nxs_snapAvNts = array(); $nxs_snapAPINts = array(); foreach (glob(plugin_dir_path( __FILE__ ).'inc-cl/*.php') as $filename){ require_once $filename; }
35
  //## Some Default Values
36
  //$options = array('nsOpenGraph'=>1);
37
  $dbOptions = get_option($this->dbOptionsName);
38
+ $this->nxs_ntoptions = get_site_option($this->dbOptionsName); $nxs_UPPath = 'nxs-snap-pro-upgrade';
39
+ $pf = ABSPATH . 'wp-content/plugins/'.$nxs_UPPath.'/'.$nxs_UPPath.'.php'; if (file_exists($pf) && !function_exists('nxs_getInitAdd') ) require_once $pf;
40
  if ($nxs_isWPMU && $blog_id>1) { switch_to_blog(1); $dbMUOptions = get_option($this->dbOptionsName);
41
  if (function_exists('nxs_getInitAdd')) nxs_getInitAdd($dbMUOptions); restore_current_blog();
42
  $dbOptions['lk'] = $dbMUOptions['lk']; $dbOptions['ukver'] = $dbMUOptions['ukver']; $dbOptions['uklch'] = $dbMUOptions['uklch']; $dbOptions['uk'] = $dbMUOptions['uk'];
177
  if ($nxs_isWPMU && (!isset($options['suaMode'])||$options['suaMode'] == '')) $options['suaMode'] = $nxs_tpWMPU;
178
  $editable_roles = get_editable_roles(); foreach ( $editable_roles as $roleX => $details ) {$role = get_role($roleX); $role->remove_cap('see_snap_box'); $role->remove_cap('make_snap_posts'); }
179
 
180
+ foreach ($options['whoCanSeeSNAPBox'] as $uRole) { $role = get_role($uRole); $role->add_cap('see_snap_box'); $role->add_cap('make_snap_posts'); }
181
  foreach ($options['whoCanMakePosts'] as $uRole) { $role = get_role($uRole); $role->add_cap('make_snap_posts'); }
182
 
183
  update_option($this->dbOptionsName, $options); // prr($options);
227
  <div id="fbSelCats<?php echo $ii; ?>" class="categorydivInd" style="padding-left: 15px; background-color: #fff;">
228
  <a href="#" onclick="nxs_chAllCatsL(1, 'fbSelCats<?php echo $ii; ?>'); return false;">Check all</a> &nbsp;|&nbsp; <a href="#" onclick="nxs_chAllCatsL(0, 'fbSelCats<?php echo $ii; ?>'); return false;">UnCheck all</a>
229
  <div id="category-all" class="tabs-panel"> <input type="hidden" id="tmpCatSelNT" name="tmpCatSelNT" value="" />
230
+ <ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
231
+ <?php $args = array( 'descendants_and_self' => 0, 'selected_cats' => '', 'taxonomy' => 'category', 'checked_ontop' => false);
232
+ if (function_exists('wp_terms_checklist')) wp_terms_checklist(0, $args ); ?>
233
  </ul>
234
  </div>
235
+ </div> <div class="submit"><input type="button" id="" class="button-primary" name="btnSelCats" onclick="nxs_doSetSelCats( jQuery('#tmpCatSelNT').val() ); jQuery('#showCatSel').bPopup().close();" value="Select Categories" /></div>
236
  </div>
237
 
238
  <?php wp_nonce_field( 'nsDN', 'nsDN_wpnonce' );
623
  <br/><br/><br/>This version of the plugin is not compatible with <b>Wordpress Multisite Edition</b>. Please contact your Network Admin for the upgrade. <?php }
624
 
625
  function NS_SNAP_ShowPageTop(){ global $nxs_snapAvNts, $nxs_snapThisPageUrl, $nxsOne, $nxs_plurl, $nxs_isWPMU; $nxsOne = ''; $options = $this->nxs_options;
626
+ if ($_GET['page']=='NextScripts_SNAP.php' && isset($_GET['do']) && $_GET['do']=='h'){ nxs_do_this_hourly(); die(); }
627
+ $nxsOne = NextScripts_SNAP_Version; if (defined('NXSAPIVER')) $nxsOne .= " (<span id='nxsAPIUpd'>API</span> Version: ".NXSAPIVER.")"; ?>
628
 
629
  <div style="float:right; padding-top: 10px; padding-right: 10px;">
630
  <div style="float:right; text-align: center;"><a target="_blank" href="http://www.nextscripts.com"><img src="<?php echo $nxs_plurl; ?>img/Next_Scripts_Logo2.1-HOR-100px.png"></a><br/>
669
  <?php }
670
  }
671
 
672
+ function NS_SNAP_SavePostMetaTags($id) { global $nxs_snapAvNts, $plgn_NS_SNAutoPoster; if (count($_POST)<1 || !isset($_POST["snapEdIT"]) || empty($_POST["snapEdIT"])) return;
673
+ if (!isset($plgn_NS_SNAutoPoster)) return; $options = $plgn_NS_SNAutoPoster->nxs_options; // echo "| NS_SNAP_SavePostMetaTags - ".$id." |";
674
+ $post = get_post($id); //prr($post); die();
675
+ if ($post->post_type=='revision' && $post->post_status=='inherit' && $post->post_parent!='0') return;
676
+ if (get_magic_quotes_gpc() || ( isset($_POST['nxs_mqTest']) && $_POST['nxs_mqTest']=="\'")){ array_walk_recursive($_POST, 'nsx_stripSlashes'); }
677
+ $snap_isAutoPosted = get_post_meta($id, 'snap_isAutoPosted', true); if ($snap_isAutoPosted=='1' && $post->post_status=='future') { delete_post_meta($id, 'snap_isAutoPosted'); add_post_meta($id, 'snap_isAutoPosted', '2'); }
678
+ delete_post_meta($id, 'snapEdIT'); add_post_meta($id, 'snapEdIT', '1' );
679
+ foreach ($nxs_snapAvNts as $avNt) {
680
  if (count($options[$avNt['lcode']])>0 && isset($_POST[$avNt['lcode']]) && count($_POST[$avNt['lcode']])>0) { $savedMeta = maybe_unserialize(get_post_meta($id, 'snap'.$avNt['code'], true));
681
  if(is_array($_POST[$avNt['lcode']])) { $ii=0;
682
+ foreach ($_POST[$avNt['lcode']] as $pst ) { //echo "#############################################################################"; prr($pst);
683
+ if (is_array($pst) && empty( $pst['do'.$avNt['code']]) && empty($_POST[$avNt['lcode']][$ii]['do'.$avNt['code']])) $_POST[$avNt['lcode']][$ii]['do'.$avNt['code']]= 0; $ii++;
684
  }
685
  } $newMeta = $_POST[$avNt['lcode']];
686
  if (is_array($savedMeta) && is_array($newMeta)) $newMeta = nxsMergeArraysOV($savedMeta, $newMeta); // echo "##### ".$id."| snap".$avNt['code']; prr($savedMeta); echo "||"; prr($newMeta);// $newMeta = 'AAA';
687
  delete_post_meta($id, 'snap'.$avNt['code']); add_post_meta($id, 'snap'.$avNt['code'], serialize($newMeta));
688
  }
689
  }
690
+ //prr($_POST);
691
  }
692
 
693
  function NS_SNAP_AddPostMetaTags() { global $post, $nxs_snapAvNts, $plgn_NS_SNAutoPoster; $post_id = $post; if (is_object($post_id)) $post_id = $post_id->ID; if (!is_object($post)) $post = get_post($post_id);
708
  <?php } ?>
709
  <table style="margin-bottom:40px; clear:both;" width="100%" border="0"><?php
710
  foreach ($nxs_snapAvNts as $avNt) { $clName = 'nxs_snapClass'.$avNt['code'];
711
+ if ( isset($avNt['lcode']) && isset($options[$avNt['lcode']]) && count($options[$avNt['lcode']])>0) { $ntClInst = new $clName(); $ntClInst->showEdPostNTSettings($options[$avNt['lcode']], $post); }
712
  }
713
  ?></table></div></div></div> <?php
714
  }
719
  if ($options['useForPages']=='1') add_meta_box( 'NS_SNAP_AddPostMetaTags', __( 'NextScripts: Social Networks Auto Poster - Post Options', 'nxs_snap' ), array($this, 'NS_SNAP_AddPostMetaTags'), 'page' );
720
 
721
  $args=array('public'=>true, '_builtin'=>false); $output = 'names'; $operator = 'and'; $post_types = array(); if (function_exists('get_post_types')) $post_types=get_post_types($args, $output, $operator);
722
+ if ((isset($options['nxsCPTSeld'])) && $options['nxsCPTSeld']!='') $nxsCPTSeld = unserialize($options['nxsCPTSeld']); else $nxsCPTSeld = array_keys($post_types); //prr($nxsCPTSeld); prr($post_types);
723
  foreach ($post_types as $cptID=>$cptName) if (in_array($cptID, $nxsCPTSeld)){
724
  add_meta_box( 'NS_SNAP_AddPostMetaTags', __('NextScripts: Social Networks Auto Poster - Post Options', 'nxs_snap'), array($this, 'NS_SNAP_AddPostMetaTags'), $cptID );
725
  }
727
  }
728
  }
729
 
730
+ if (isset($_GET['page']) && $_GET['page']=='NextScripts_SNAP.php' && isset($_GET['do']) && $_GET['do']=='test'){ echo "Testting... cURL<br/>";
731
+ nxs_cURLTest("http://www.google.com/intl/en/contact/", "HTTP to Google", "Mountain View, CA");
732
+ nxs_cURLTest("https://www.google.com/intl/en/contact/", "HTTPS to Google", "Mountain View, CA");
733
+ nxs_cURLTest("https://www.facebook.com/", "HTTPS to Facebook", 'id="facebook"');
734
+ nxs_cURLTest("https://graph.facebook.com/nextscripts", "HTTPS to API (Graph) Facebook", '270851199672443');
735
+ nxs_cURLTest("https://www.linkedin.com/", "HTTPS to LinkedIn", 'rel="canonical" href="https://www.linkedin.com/"');
736
+ nxs_cURLTest("https://twitter.com/", "HTTPS to Twitter", '<link rel="canonical" href="https://twitter.com/">');
737
+ nxs_cURLTest("http://pinterest.com/", "HTTPS to Pinterest", 'content="Pinterest"');
738
+ nxs_cURLTest("http://www.livejournal.com/", "HTTP to LiveJournal", '1999 LiveJournal');
739
+ die('Done');
740
+ }
741
+
742
  if (class_exists("NS_SNAutoPoster")) { nxs_checkAddLogTable(); $plgn_NS_SNAutoPoster = new NS_SNAutoPoster(); }
743
  //## Delete Account
744
  if (!function_exists("ns_delNT_ajax")) { function ns_delNT_ajax(){ check_ajax_referer('nsDN'); $indx = (int)$_POST['id'];
807
  }}}
808
 
809
  //## Main Function to Post
810
+ if (!function_exists("nxs_snapLogPublishTo")) { function nxs_snapLogPublishTo( $new_status, $old_status, $post ) {
811
+ if ( $old_status!='publish' && $new_status == 'publish' ) nxs_addToLogN('BG', "*** ID: {$post->ID}, Type: {$post->post_type}", '', ' Status Changed: '."{$old_status}_to_{$new_status}".'. Autopost requested.');
812
+ }}
813
  if (!function_exists("nxs_snapPublishTo")) { function nxs_snapPublishTo($postArr, $type='', $aj=false) { global $plgn_NS_SNAutoPoster, $nxs_snapAvNts, $blog_id, $nxs_tpWMPU; // echo " | nxs_doSMAS2 | "; prr($postArr);
814
+ if (!isset($plgn_NS_SNAutoPoster)) return; $options = $plgn_NS_SNAutoPoster->nxs_options;
815
+ if(is_object($postArr)) $postID = $postArr->ID; else { $postID = $postArr; $postArr = get_post($postID); } $isPost = isset($_POST["snapEdIT"]); $post = get_post($postID);
816
+ //nxs_addToLogN('BG', 'Post Status Changed', '', '-=## Autopost requested.'.($blog_id>1?'BlogID:'.$blog_id:'').' PostID:('.$postID.') Post Type: '.$post->post_type.' ##=-');
817
+ $args=array('public'=>true, '_builtin'=>false); $output = 'names'; $operator = 'and'; $post_types = array(); if (function_exists('get_post_types')) $post_types=get_post_types($args, $output, $operator);
818
+ if ( isset($options['nxsCPTSeld']) && $options['nxsCPTSeld']!='') $nxsCPTSeld = unserialize($options['nxsCPTSeld']); else $nxsCPTSeld = array(); // $nxsCPTSeld = array_keys($post_types); - why we needed it?
819
+
820
+ if ($post->post_type == 'post' || ($options['useForPages']=='1' && $post->post_type == 'page') || (in_array($post->post_type, $post_types) && in_array($post->post_type, $nxsCPTSeld))) {
821
+ if ($isPost && $options['skipSecurity']!='1' && !current_user_can("make_snap_posts") && !current_user_can("manage_options")) { nxs_addToLogN('I', 'Skipped', '', 'Current user can\'t autopost - Post ID:('.$postID.')' ); return; }
822
+ $postUser = $postArr->post_author;
823
+ if ($options['skipSecurity']!='1' && !user_can( $postUser, "make_snap_posts" ) && !user_can( $postUser, "manage_options")){ nxs_addToLogN('I', 'Skipped', '', 'User ID '.$postUser.' can\'t autopost - Post ID:('.$postID.')' ); return; }
824
+ if ($isPost) $plgn_NS_SNAutoPoster->NS_SNAP_SavePostMetaTags($postID);
825
+ if (function_exists('nxs_doSMAS2')) { nxs_doSMAS2($postArr, $type, $aj); return; } else {
826
+ $options = $plgn_NS_SNAutoPoster->nxs_options; $ltype=strtolower($type);
827
+ if ($nxs_tpWMPU=='S') { switch_to_blog(1); $plgn_NS_SNAutoPoster = new NS_SNAutoPoster(); $options = $plgn_NS_SNAutoPoster->nxs_options; restore_current_blog(); }
828
+ if (!isset($options['nxsHTDP']) || $options['nxsHTDP']=='S') { if(isset($_POST["snapEdIT"]) && $_POST["snapEdIT"]=='1') { $publtype='S'; $delay = rand(2,10); } else $publtype='A'; } else $publtype = 'I';
829
+ nxs_addToLogN('BG', 'Start =- ', '', '------=========#### NEW AUTO-POST REQUEST '.($blog_id>1?'BlogID:'.$blog_id:'').' PostID:('.$postID.') '.($publtype=='S'?'Scheduled +'.$delay:($publtype=='A'?'Non Human':'Immediate')).' ####=========------');
 
 
830
 
831
+ $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted=='1') { nxs_addToLogN('W', 'Skipped', '', 'Already Autoposted - Post ID:('.$postID.')' ); return; }
832
+ $snap_isEdIT = get_post_meta($postID, 'snapEdIT', true); if ($snap_isEdIT!='1') { $doPost = true; $exclCats = maybe_unserialize($options['exclCats']); $postCats = wp_get_post_categories($postID);
833
+ foreach ($postCats as $pCat) { if ( (is_array($exclCats)) && in_array($pCat, $exclCats)) $doPost = false; else {$doPost = true; break;}}
834
+ if (!$doPost) { nxs_addToLogN('I', 'Skipped', '', 'Non-Human Post - Category Excluded - Post ID:('.$postID.')' ); return; }
835
+ }
836
 
837
+ foreach ($nxs_snapAvNts as $avNt) {
838
+ if (count($options[$avNt['lcode']])>0) { $clName = 'nxs_snapClass'.$avNt['code'];
839
+ if ($isPost && isset($_POST[$avNt['lcode']])) $po = $_POST[$avNt['lcode']]; else { $po = get_post_meta($postID, 'snap'.$avNt['code'], true); $po = maybe_unserialize($po);}
840
 
841
+ if (isset($po) && is_array($po)) $isPostMeta = true; else { $isPostMeta = false; $po = $options[$avNt['lcode']]; }
842
+ delete_post_meta($postID, 'snap_isAutoPosted'); add_post_meta($postID, 'snap_isAutoPosted', '1');
843
+
844
+ $optMt = $options[$avNt['lcode']][0]; if ($isPostMeta) { $ntClInst = new $clName(); $optMt = $ntClInst->adjMetaOpt($optMt, $po[0]); }
845
+ if ($snap_isEdIT!='1') { $doPost = true;
846
+ if ( $optMt['catSel']=='1' && trim($optMt['catSelEd'])!='' ) { $inclCats = explode(',',$optMt['catSelEd']); foreach ($postCats as $pCat) { if (!in_array($pCat, $inclCats)) $doPost = false; else {$doPost = true; break;}}
847
+ if (!$doPost) { nxs_addToLogN('I', 'Skipped', $avNt['name'].' ('.$optMt['nName'].')', '[Non-Human Post] - Individual Category Excluded - Post ID:('.$postID.')' ); return; }
848
+ }
849
+ }
850
+ if ($optMt['do'.$avNt['code']]=='1') { $optMt['ii'] = 0;
851
+ if ($publtype=='A' && ($optMt['nMin']>0 || $optMt['nHrs']>0 || $optMt['nTime']!='')) $publtype='S';
852
+ if ($publtype=='S') { if (isset($optMt['nHrs']) && isset($optMt['nMin']) && ($optMt['nHrs']>0 || $optMt['nMin']>0) ) { $delay = $optMt['nMin']*60+$optMt['nHrs']*3600;
853
+ nxs_addToLogN('I', 'Delayed', $avNt['name'].' ('.$optMt['nName'].')', 'Post has been delayed for '.$delay.' Seconds ('.($optMt['nHrs']>0?$optMt['nHrs'].' Hours':'')." ".($optMt['nMin']>0?$optMt['nMin'].' Minutes':'').')' );
854
+ } else $delay = rand(2,10); $optMt['timeToRun'] = time()+$delay; $args = array($postID, $optMt); wp_schedule_single_event($optMt['timeToRun'],'ns_doPublishTo'.$avNt['code'], $args);
855
+ nxs_addToLogN('BI', 'Scheduled', $avNt['name'].' ('.$optMt['nName'].')', ' PostID:('.$postID.')' );
856
+ } else { $fname = 'nxs_doPublishTo'.$avNt['code']; $fname($postID, $optMt); }
857
+ } else { nxs_addToLogN('GR', 'Skipped', $avNt['name'].' ('.$optMt['nName'].')', '-=[Unchecked Account]=- - PostID:'.$postID.'' ); }
858
+ }
859
+ } } } else { nxs_addToLogN('I', 'Skipped', '', 'Excluded Post Type:(Post ID: '.$postID.')' ); return; }
860
+ if ($isS) restore_current_blog();
861
  }}
862
 
863
  //## AJAX to Post to Google+
873
  return $links;
874
  }}
875
  //## Actions and filters
 
 
 
 
 
 
 
 
 
 
 
 
 
876
 
877
  //## Process Spin
878
  if (!function_exists("nxs_spinRecursion")) { function nxs_spinRecursion(&$txt, $startCh) { global $nxs_spin_lCh, $nxs_spin_rCh, $nxs_spin_splCh; $startPos = $startCh;
891
 
892
  //## Format Message
893
  if (!function_exists("nsFormatMessage")) { function nsFormatMessage($msg, $postID, $addURLParams=''){ global $ShownAds, $plgn_NS_SNAutoPoster, $nxs_urlLen; $post = get_post($postID); $options = $plgn_NS_SNAutoPoster->nxs_options;
894
+ if ($addURLParams=='' && $options['addURLParams']!='') $addURLParams = $options['addURLParams'];
895
  $msg = stripcslashes($msg); if (isset($ShownAds)) $ShownAdsL = $ShownAds; // $msg = htmlspecialchars(stripcslashes($msg));
896
  $msg = nxs_doSpin($msg);
897
  if (preg_match('%URL%', $msg)) { $url = get_permalink($postID); if($addURLParams!='') $url .= (strpos($url,'?')!==false?'&':'?').$addURLParams; $nxs_urlLen = nxs_strLen($url); $msg = str_ireplace("%URL%", $url, $msg);}
903
  if (preg_match('%STITLE%', $msg)) { $title = nxs_doQTrans($post->post_title, $lng); $title = substr($title, 0, 115); $msg = str_ireplace("%STITLE%", $title, $msg); }
904
  if (preg_match('%AUTHORNAME%', $msg)) { $aun = $post->post_author; $aun = get_the_author_meta('display_name', $aun ); $msg = str_ireplace("%AUTHORNAME%", $aun, $msg);}
905
  if (preg_match('%ANNOUNCE%', $msg)) { $postContent = nxs_doQTrans($post->post_content, $lng);
906
+ $postContent = strip_tags(strip_shortcodes(str_ireplace('<!--more-->', '#####!--more--!#####', str_ireplace("&lt;!--more--&gt;", '<!--more-->', $postContent))));
907
+ if (stripos($postContent, '#####!--more--!#####')!==false) { $postContentEx = explode('#####!--more--!#####',$postContent); $postContent = $postContentEx[0]; }
908
+ else $postContent = nsTrnc($postContent, $options['anounTagLimit']); $msg = str_ireplace("%ANNOUNCE%", $postContent, $msg);
909
  }
910
  if (preg_match('%TEXT%', $msg)) {
911
  if ($post->post_excerpt!="") $excerpt = apply_filters('the_content', nxs_doQTrans($post->post_excerpt, $lng)); else $excerpt= apply_filters('the_content', nxs_doQTrans($post->post_content, $lng));
975
  function nxs_end_flush_ob(){ob_end_flush();}
976
 
977
  function nxs_ogtgCallback($content){ global $post, $plgn_NS_SNAutoPoster; if (!isset($plgn_NS_SNAutoPoster)) return; $options = $plgn_NS_SNAutoPoster->nxs_options; $ogimgs = array();
978
+ if (!is_object($post) && (int)$post > 0) $post = get_post($post); if (empty($options['advFindOGImg'])) $options['advFindOGImg'] = 0;
979
  if (stripos($content, 'og:title')!==false) $ogOut = "\r\n"; else {
980
  $title = preg_match( '/<title>(.*)<\/title>/', $content, $title_matches );
981
  if ($title !== false && count( $title_matches) == 2 ) $ogT ='<meta property="og:title" content="' . $title_matches[1] . '" />'."\r\n"; else {
982
  if (is_home() || is_front_page() ) $ogT = get_bloginfo( 'name' ); else $ogT = get_the_title();
983
  $ogT = '<meta property="og:title" content="' . esc_attr( apply_filters( 'nxsog_title', $ogT ) ) . '" />'."\r\n";
984
  }
985
+ $prcRes = preg_match( '/<meta name="description" content="(.*)"/', $content, $description_matches );
986
+ if ( $prcRes !== false && count( $description_matches ) == 2 ) $ogD = '<meta property="og:description" content="' . $description_matches[1] . '" />'."\r\n"; {
987
  if (is_singular()) {
988
  if(has_excerpt($post->ID))$ogD=strip_tags(nxs_snapCleanHTML(get_the_excerpt($post->ID)));else $ogD= str_replace(" ", ' ', str_replace("\r\n", ' ', trim(substr(strip_tags(nxs_snapCleanHTML(strip_shortcodes($post->post_content))), 0, 200))));
989
  } else $ogD = get_bloginfo('description'); $ogD = preg_replace('/\r\n|\r|\n/m','',$ogD);
992
  $ogSN = '<meta property="og:site_name" content="'.get_bloginfo('name').'" />'."\r\n";
993
  $ogLoc = strtolower(esc_attr(get_locale())); if (strlen($ogLoc)==2) $ogLoc .= "_".strtoupper($ogLoc);
994
  $ogLoc = '<meta property="og:locale" content="'.$ogLoc.'" />'."\r\n"; $iss = is_home();
995
+ $ogType = is_singular()?'article':'website';
996
+ //if($vidsFromPost == false)
997
+ $ogType = '<meta property="og:type" content="'.esc_attr(apply_filters('nxsog_type', $ogType)).'" />'."\r\n";
998
 
999
  if (is_home() || is_front_page()) $ogUrl = get_bloginfo( 'url' ); else $ogUrl = 'http' . (is_ssl() ? 's' : '') . "://".$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
1000
  $ogUrl = '<meta property="og:url" content="'.esc_url( apply_filters( 'nxsog_url', $ogUrl ) ) . '" />' . "\r\n";
1007
  echo '<meta property="og:image" content="http://i2.ytimg.com/vi/'.$vidsFromPost[0].'/mqdefault.jpg" />'."\n";
1008
  echo '<meta property="og:type" content="video" />'."\n";
1009
  } */
1010
+ if (function_exists('has_post_thumbnail') && is_object($post) && has_post_thumbnail($post->ID)) {
1011
  $thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'thumbnail' ); $ogimgs[] = $thumbnail_src[0];
1012
  } $imgsFromPost = nsFindImgsInPost($post, (int)$options['advFindOGImg']==1);
1013
  if ($imgsFromPost !== false && is_singular() && is_array($ogimgs) && is_array($imgsFromPost)) $ogimgs = array_merge($ogimgs, $imgsFromPost);
1063
  add_action('wp', 'nxs_activation');
1064
  add_action('shutdown', 'nxs_psCron');
1065
 
1066
+
1067
  if ($isO || $isS) {
1068
+ add_action( 'transition_post_status', 'nxs_snapLogPublishTo', 10, 3 );
1069
  //## Whenever you publish a post, post to Social Networks
1070
  add_action('future_to_publish', 'nxs_snapPublishTo');
1071
  add_action('new_to_publish', 'nxs_snapPublishTo');
1074
  add_action('private_to_publish', 'nxs_snapPublishTo');
1075
  add_action('auto-draft_to_publish', 'nxs_snapPublishTo');
1076
  //## Add nxs_snapPublishTo to custom post types
1077
+
1078
  foreach ($nxs_snapAvNts as $avNt) { add_action('ns_doPublishTo'.$avNt['code'], 'nxs_doPublishTo'.$avNt['code'], 1, 2); }
1079
  foreach ($nxs_snapAvNts as $avNt) { add_action('wp_ajax_rePostTo'.$avNt['code'], 'nxs_rePostTo'.$avNt['code'].'_ajax'); }
1080
 
1096
  add_action('edit_post', array($plgn_NS_SNAutoPoster, 'NS_SNAP_SavePostMetaTags'));
1097
  add_action('publish_post', array($plgn_NS_SNAutoPoster, 'NS_SNAP_SavePostMetaTags'));
1098
  add_action('save_post', array($plgn_NS_SNAutoPoster, 'NS_SNAP_SavePostMetaTags'));
1099
+ // add_action('edit_page_form', array($plgn_NS_SNAutoPoster, 'NS_SNAP_SavePostMetaTags'));
 
 
1100
 
1101
  add_action('wp_ajax_nsAuthFBSv', 'nsAuthFBSv_ajax');
1102
  //## Custom Post Types and OG tags
img/ap-bg.png ADDED
Binary file
img/ap16.png ADDED
Binary file
img/fb2wops.png ADDED
Binary file
inc-cl/apis/base_facebook.php CHANGED
@@ -1,1431 +1,1431 @@
1
- <?php
2
- /**
3
- * Copyright 2011 Facebook, Inc.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
6
- * not use this file except in compliance with the License. You may obtain
7
- * a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
- * License for the specific language governing permissions and limitations
15
- * under the License.
16
- */
17
-
18
- if (!function_exists('curl_init')) {
19
- throw new Exception('Facebook needs the CURL PHP extension.');
20
- }
21
- if (!function_exists('json_decode')) {
22
- throw new Exception('Facebook needs the JSON PHP extension.');
23
- }
24
-
25
- /**
26
- * Thrown when an API call returns an exception.
27
- *
28
- * @author Naitik Shah <naitik@facebook.com>
29
- */
30
- class NXS_FacebookApiException extends Exception
31
- {
32
- /**
33
- * The result from the API server that represents the exception information.
34
- */
35
- protected $result;
36
-
37
- /**
38
- * Make a new API Exception with the given result.
39
- *
40
- * @param array $result The result from the API server
41
- */
42
- public function __construct($result) {
43
- $this->result = $result;
44
-
45
- $code = isset($result['error_code']) ? $result['error_code'] : 0;
46
-
47
- if (isset($result['error_description'])) {
48
- // OAuth 2.0 Draft 10 style
49
- $msg = $result['error_description'];
50
- } else if (isset($result['error']) && is_array($result['error'])) {
51
- // OAuth 2.0 Draft 00 style
52
- $msg = $result['error']['message'];
53
- if ($code==0 && isset($result['error']['code'])) $code = $result['error']['code'];
54
- } else if (isset($result['error_msg'])) {
55
- // Rest server style
56
- $msg = $result['error_msg'];
57
- } else {
58
- $msg = 'Unknown Error. Check getResult()';
59
- }
60
-
61
- parent::__construct($msg, $code);
62
- }
63
-
64
- /**
65
- * Return the associated result object returned by the API server.
66
- *
67
- * @return array The result from the API server
68
- */
69
- public function getResult() {
70
- return $this->result;
71
- }
72
-
73
- /**
74
- * Returns the associated type for the error. This will default to
75
- * 'Exception' when a type is not available.
76
- *
77
- * @return string
78
- */
79
- public function getType() {
80
- if (isset($this->result['error'])) {
81
- $error = $this->result['error'];
82
- if (is_string($error)) {
83
- // OAuth 2.0 Draft 10 style
84
- return $error;
85
- } else if (is_array($error)) {
86
- // OAuth 2.0 Draft 00 style
87
- if (isset($error['type'])) {
88
- return $error['type'];
89
- }
90
- }
91
- }
92
-
93
- return 'Exception';
94
- }
95
-
96
- /**
97
- * To make debugging easier.
98
- *
99
- * @return string The string representation of the error
100
- */
101
- public function __toString() {
102
- $str = $this->getType() . ': ';
103
- if ($this->code != 0) {
104
- $str .= $this->code . ': ';
105
- }
106
- return $str . $this->message;
107
- }
108
- }
109
-
110
- /**
111
- * Provides access to the Facebook Platform. This class provides
112
- * a majority of the functionality needed, but the class is abstract
113
- * because it is designed to be sub-classed. The subclass must
114
- * implement the four abstract methods listed at the bottom of
115
- * the file.
116
- *
117
- * @author Naitik Shah <naitik@facebook.com>
118
- */
119
- abstract class NXS_BaseFacebook
120
- {
121
- /**
122
- * Version.
123
- */
124
- const VERSION = '3.2.0';
125
-
126
- /**
127
- * Signed Request Algorithm.
128
- */
129
- const SIGNED_REQUEST_ALGORITHM = 'HMAC-SHA256';
130
-
131
- /**
132
- * Default options for curl.
133
- */
134
- public static $CURL_OPTS = array(
135
- CURLOPT_CONNECTTIMEOUT => 10,
136
- CURLOPT_RETURNTRANSFER => true,
137
- CURLOPT_TIMEOUT => 60,
138
- CURLOPT_USERAGENT => 'facebook-php-3.2',
139
- );
140
-
141
- /**
142
- * List of query parameters that get automatically dropped when rebuilding
143
- * the current URL.
144
- */
145
- protected static $DROP_QUERY_PARAMS = array(
146
- 'code',
147
- 'state',
148
- 'signed_request',
149
- );
150
-
151
- /**
152
- * Maps aliases to Facebook domains.
153
- */
154
- public static $DOMAIN_MAP = array(
155
- 'api' => 'https://api.facebook.com/',
156
- 'api_video' => 'https://api-video.facebook.com/',
157
- 'api_read' => 'https://api-read.facebook.com/',
158
- 'graph' => 'https://graph.facebook.com/',
159
- 'graph_video' => 'https://graph-video.facebook.com/',
160
- 'www' => 'https://www.facebook.com/',
161
- );
162
-
163
- /**
164
- * The Application ID.
165
- *
166
- * @var string
167
- */
168
- protected $appId;
169
-
170
- /**
171
- * The Application App Secret.
172
- *
173
- * @var string
174
- */
175
- protected $appSecret;
176
-
177
- /**
178
- * The ID of the Facebook user, or 0 if the user is logged out.
179
- *
180
- * @var integer
181
- */
182
- protected $user;
183
-
184
- /**
185
- * The data from the signed_request token.
186
- */
187
- protected $signedRequest;
188
-
189
- /**
190
- * A CSRF state variable to assist in the defense against CSRF attacks.
191
- */
192
- protected $state;
193
-
194
- /**
195
- * The OAuth access token received in exchange for a valid authorization
196
- * code. null means the access token has yet to be determined.
197
- *
198
- * @var string
199
- */
200
- protected $accessToken = null;
201
-
202
- /**
203
- * Indicates if the CURL based @ syntax for file uploads is enabled.
204
- *
205
- * @var boolean
206
- */
207
- protected $fileUploadSupport = false;
208
-
209
- /**
210
- * Indicates if we trust HTTP_X_FORWARDED_* headers.
211
- *
212
- * @var boolean
213
- */
214
- protected $trustForwarded = false;
215
-
216
- /**
217
- * Initialize a Facebook Application.
218
- *
219
- * The configuration:
220
- * - appId: the application ID
221
- * - secret: the application secret
222
- * - fileUpload: (optional) boolean indicating if file uploads are enabled
223
- *
224
- * @param array $config The application configuration
225
- */
226
- public function __construct($config) {
227
- $this->setAppId($config['appId']);
228
- $this->setAppSecret($config['secret']);
229
- if (isset($config['fileUpload'])) {
230
- $this->setFileUploadSupport($config['fileUpload']);
231
- }
232
- if (isset($config['trustForwarded']) && $config['trustForwarded']) {
233
- $this->trustForwarded = true;
234
- }
235
- $state = $this->getPersistentData('state');
236
- if (!empty($state)) {
237
- $this->state = $state;
238
- }
239
- }
240
-
241
- /**
242
- * Set the Application ID.
243
- *
244
- * @param string $appId The Application ID
245
- * @return BaseFacebook
246
- */
247
- public function setAppId($appId) {
248
- $this->appId = $appId;
249
- return $this;
250
- }
251
-
252
- /**
253
- * Get the Application ID.
254
- *
255
- * @return string the Application ID
256
- */
257
- public function getAppId() {
258
- return $this->appId;
259
- }
260
-
261
- /**
262
- * Set the App Secret.
263
- *
264
- * @param string $apiSecret The App Secret
265
- * @return BaseFacebook
266
- * @deprecated
267
- */
268
- public function setApiSecret($apiSecret) {
269
- $this->setAppSecret($apiSecret);
270
- return $this;
271
- }
272
-
273
- /**
274
- * Set the App Secret.
275
- *
276
- * @param string $appSecret The App Secret
277
- * @return BaseFacebook
278
- */
279
- public function setAppSecret($appSecret) {
280
- $this->appSecret = $appSecret;
281
- return $this;
282
- }
283
-
284
- /**
285
- * Get the App Secret.
286
- *
287
- * @return string the App Secret
288
- * @deprecated
289
- */
290
- public function getApiSecret() {
291
- return $this->getAppSecret();
292
- }
293
-
294
- /**
295
- * Get the App Secret.
296
- *
297
- * @return string the App Secret
298
- */
299
- public function getAppSecret() {
300
- return $this->appSecret;
301
- }
302
-
303
- /**
304
- * Set the file upload support status.
305
- *
306
- * @param boolean $fileUploadSupport The file upload support status.
307
- * @return BaseFacebook
308
- */
309
- public function setFileUploadSupport($fileUploadSupport) {
310
- $this->fileUploadSupport = $fileUploadSupport;
311
- return $this;
312
- }
313
-
314
- /**
315
- * Get the file upload support status.
316
- *
317
- * @return boolean true if and only if the server supports file upload.
318
- */
319
- public function getFileUploadSupport() {
320
- return $this->fileUploadSupport;
321
- }
322
-
323
- /**
324
- * DEPRECATED! Please use getFileUploadSupport instead.
325
- *
326
- * Get the file upload support status.
327
- *
328
- * @return boolean true if and only if the server supports file upload.
329
- */
330
- public function useFileUploadSupport() {
331
- return $this->getFileUploadSupport();
332
- }
333
-
334
- /**
335
- * Sets the access token for api calls. Use this if you get
336
- * your access token by other means and just want the SDK
337
- * to use it.
338
- *
339
- * @param string $access_token an access token.
340
- * @return BaseFacebook
341
- */
342
- public function setAccessToken($access_token) {
343
- $this->accessToken = $access_token;
344
- return $this;
345
- }
346
-
347
- /**
348
- * Extend an access token, while removing the short-lived token that might
349
- * have been generated via client-side flow. Thanks to http://bit.ly/b0Pt0H
350
- * for the workaround.
351
- */
352
- public function setExtendedAccessToken() {
353
- try {
354
- // need to circumvent json_decode by calling _oauthRequest
355
- // directly, since response isn't JSON format.
356
- $access_token_response = $this->_oauthRequest(
357
- $this->getUrl('graph', '/oauth/access_token'),
358
- $params = array(
359
- 'client_id' => $this->getAppId(),
360
- 'client_secret' => $this->getAppSecret(),
361
- 'grant_type' => 'fb_exchange_token',
362
- 'fb_exchange_token' => $this->getAccessToken(),
363
- )
364
- );
365
- }
366
- catch (NXS_FacebookApiException $e) {
367
- // most likely that user very recently revoked authorization.
368
- // In any event, we don't have an access token, so say so.
369
- return false;
370
- }
371
-
372
- if (empty($access_token_response)) {
373
- return false;
374
- }
375
-
376
- $response_params = array();
377
- parse_str($access_token_response, $response_params);
378
-
379
- if (!isset($response_params['access_token'])) {
380
- return false;
381
- }
382
-
383
- $this->destroySession();
384
-
385
- $this->setPersistentData(
386
- 'access_token', $response_params['access_token']
387
- );
388
- }
389
-
390
- /**
391
- * Determines the access token that should be used for API calls.
392
- * The first time this is called, $this->accessToken is set equal
393
- * to either a valid user access token, or it's set to the application
394
- * access token if a valid user access token wasn't available. Subsequent
395
- * calls return whatever the first call returned.
396
- *
397
- * @return string The access token
398
- */
399
- public function getAccessToken() {
400
- if ($this->accessToken !== null) {
401
- // we've done this already and cached it. Just return.
402
- return $this->accessToken;
403
- }
404
-
405
- // first establish access token to be the application
406
- // access token, in case we navigate to the /oauth/access_token
407
- // endpoint, where SOME access token is required.
408
- $this->setAccessToken($this->getApplicationAccessToken());
409
- $user_access_token = $this->getUserAccessToken();
410
- if ($user_access_token) {
411
- $this->setAccessToken($user_access_token);
412
- }
413
-
414
- return $this->accessToken;
415
- }
416
-
417
- /**
418
- * Determines and returns the user access token, first using
419
- * the signed request if present, and then falling back on
420
- * the authorization code if present. The intent is to
421
- * return a valid user access token, or false if one is determined
422
- * to not be available.
423
- *
424
- * @return string A valid user access token, or false if one
425
- * could not be determined.
426
- */
427
- protected function getUserAccessToken() {
428
- // first, consider a signed request if it's supplied.
429
- // if there is a signed request, then it alone determines
430
- // the access token.
431
- $signed_request = $this->getSignedRequest();
432
- if ($signed_request) {
433
- // apps.facebook.com hands the access_token in the signed_request
434
- if (array_key_exists('oauth_token', $signed_request)) {
435
- $access_token = $signed_request['oauth_token'];
436
- $this->setPersistentData('access_token', $access_token);
437
- return $access_token;
438
- }
439
-
440
- // the JS SDK puts a code in with the redirect_uri of ''
441
- if (array_key_exists('code', $signed_request)) {
442
- $code = $signed_request['code'];
443
- $access_token = $this->getAccessTokenFromCode($code, '');
444
- if ($access_token) {
445
- $this->setPersistentData('code', $code);
446
- $this->setPersistentData('access_token', $access_token);
447
- return $access_token;
448
- }
449
- }
450
-
451
- // signed request states there's no access token, so anything
452
- // stored should be cleared.
453
- $this->clearAllPersistentData();
454
- return false; // respect the signed request's data, even
455
- // if there's an authorization code or something else
456
- }
457
-
458
- $code = $this->getCode();
459
- if ($code && $code != $this->getPersistentData('code')) {
460
- $access_token = $this->getAccessTokenFromCode($code);
461
- if ($access_token) {
462
- $this->setPersistentData('code', $code);
463
- $this->setPersistentData('access_token', $access_token);
464
- return $access_token;
465
- }
466
-
467
- // code was bogus, so everything based on it should be invalidated.
468
- $this->clearAllPersistentData();
469
- return false;
470
- }
471
-
472
- // as a fallback, just return whatever is in the persistent
473
- // store, knowing nothing explicit (signed request, authorization
474
- // code, etc.) was present to shadow it (or we saw a code in $_REQUEST,
475
- // but it's the same as what's in the persistent store)
476
- return $this->getPersistentData('access_token');
477
- }
478
-
479
- /**
480
- * Retrieve the signed request, either from a request parameter or,
481
- * if not present, from a cookie.
482
- *
483
- * @return string the signed request, if available, or null otherwise.
484
- */
485
- public function getSignedRequest() {
486
- if (!$this->signedRequest) {
487
- if (isset($_REQUEST['signed_request'])) {
488
- $this->signedRequest = $this->parseSignedRequest(
489
- $_REQUEST['signed_request']);
490
- } else if (isset($_COOKIE[$this->getSignedRequestCookieName()])) {
491
- $this->signedRequest = $this->parseSignedRequest(
492
- $_COOKIE[$this->getSignedRequestCookieName()]);
493
- }
494
- }
495
- return $this->signedRequest;
496
- }
497
-
498
- /**
499
- * Get the UID of the connected user, or 0
500
- * if the Facebook user is not connected.
501
- *
502
- * @return string the UID if available.
503
- */
504
- public function getUser() {
505
- if ($this->user !== null) {
506
- // we've already determined this and cached the value.
507
- return $this->user;
508
- }
509
-
510
- return $this->user = $this->getUserFromAvailableData();
511
- }
512
-
513
- /**
514
- * Determines the connected user by first examining any signed
515
- * requests, then considering an authorization code, and then
516
- * falling back to any persistent store storing the user.
517
- *
518
- * @return integer The id of the connected Facebook user,
519
- * or 0 if no such user exists.
520
- */
521
- protected function getUserFromAvailableData() {
522
- // if a signed request is supplied, then it solely determines
523
- // who the user is.
524
- $signed_request = $this->getSignedRequest();
525
- if ($signed_request) {
526
- if (array_key_exists('user_id', $signed_request)) {
527
- $user = $signed_request['user_id'];
528
- $this->setPersistentData('user_id', $signed_request['user_id']);
529
- return $user;
530
- }
531
-
532
- // if the signed request didn't present a user id, then invalidate
533
- // all entries in any persistent store.
534
- $this->clearAllPersistentData();
535
- return 0;
536
- }
537
-
538
- $user = $this->getPersistentData('user_id', $default = 0);
539
- $persisted_access_token = $this->getPersistentData('access_token');
540
-
541
- // use access_token to fetch user id if we have a user access_token, or if
542
- // the cached access token has changed.
543
- $access_token = $this->getAccessToken();
544
- if ($access_token &&
545
- $access_token != $this->getApplicationAccessToken() &&
546
- !($user && $persisted_access_token == $access_token)) {
547
- $user = $this->getUserFromAccessToken();
548
- if ($user) {
549
- $this->setPersistentData('user_id', $user);
550
- } else {
551
- $this->clearAllPersistentData();
552
- }
553
- }
554
-
555
- return $user;
556
- }
557
-
558
- /**
559
- * Get a Login URL for use with redirects. By default, full page redirect is
560
- * assumed. If you are using the generated URL with a window.open() call in
561
- * JavaScript, you can pass in display=popup as part of the $params.
562
- *
563
- * The parameters:
564
- * - redirect_uri: the url to go to after a successful login
565
- * - scope: comma separated list of requested extended perms
566
- *
567
- * @param array $params Provide custom parameters
568
- * @return string The URL for the login flow
569
- */
570
- public function getLoginUrl($params=array()) {
571
- $this->establishCSRFTokenState();
572
- $currentUrl = $this->getCurrentUrl();
573
-
574
- // if 'scope' is passed as an array, convert to comma separated list
575
- $scopeParams = isset($params['scope']) ? $params['scope'] : null;
576
- if ($scopeParams && is_array($scopeParams)) {
577
- $params['scope'] = implode(',', $scopeParams);
578
- }
579
-
580
- return $this->getUrl(
581
- 'www',
582
- 'dialog/oauth',
583
- array_merge(array(
584
- 'client_id' => $this->getAppId(),
585
- 'redirect_uri' => $currentUrl, // possibly overwritten
586
- 'state' => $this->state),
587
- $params));
588
- }
589
-
590
- /**
591
- * Get a Logout URL suitable for use with redirects.
592
- *
593
- * The parameters:
594
- * - next: the url to go to after a successful logout
595
- *
596
- * @param array $params Provide custom parameters
597
- * @return string The URL for the logout flow
598
- */
599
- public function getLogoutUrl($params=array()) {
600
- return $this->getUrl(
601
- 'www',
602
- 'logout.php',
603
- array_merge(array(
604
- 'next' => $this->getCurrentUrl(),
605
- 'access_token' => $this->getUserAccessToken(),
606
- ), $params)
607
- );
608
- }
609
-
610
- /**
611
- * Get a login status URL to fetch the status from Facebook.
612
- *
613
- * The parameters:
614
- * - ok_session: the URL to go to if a session is found
615
- * - no_session: the URL to go to if the user is not connected
616
- * - no_user: the URL to go to if the user is not signed into facebook
617
- *
618
- * @param array $params Provide custom parameters
619
- * @return string The URL for the logout flow
620
- */
621
- public function getLoginStatusUrl($params=array()) {
622
- return $this->getUrl(
623
- 'www',
624
- 'extern/login_status.php',
625
- array_merge(array(
626
- 'api_key' => $this->getAppId(),
627
- 'no_session' => $this->getCurrentUrl(),
628
- 'no_user' => $this->getCurrentUrl(),
629
- 'ok_session' => $this->getCurrentUrl(),
630
- 'session_version' => 3,
631
- ), $params)
632
- );
633
- }
634
-
635
- /**
636
- * Make an API call.
637
- *
638
- * @return mixed The decoded response
639
- */
640
- public function api(/* polymorphic */) {
641
- $args = func_get_args();
642
- if (is_array($args[0])) {
643
- return $this->_restserver($args[0]);
644
- } else {
645
- return call_user_func_array(array($this, '_graph'), $args);
646
- }
647
- }
648
-
649
- /**
650
- * Constructs and returns the name of the cookie that
651
- * potentially houses the signed request for the app user.
652
- * The cookie is not set by the BaseFacebook class, but
653
- * it may be set by the JavaScript SDK.
654
- *
655
- * @return string the name of the cookie that would house
656
- * the signed request value.
657
- */
658
- protected function getSignedRequestCookieName() {
659
- return 'fbsr_'.$this->getAppId();
660
- }
661
-
662
- /**
663
- * Constructs and returns the name of the coookie that potentially contain
664
- * metadata. The cookie is not set by the BaseFacebook class, but it may be
665
- * set by the JavaScript SDK.
666
- *
667
- * @return string the name of the cookie that would house metadata.
668
- */
669
- protected function getMetadataCookieName() {
670
- return 'fbm_'.$this->getAppId();
671
- }
672
-
673
- /**
674
- * Get the authorization code from the query parameters, if it exists,
675
- * and otherwise return false to signal no authorization code was
676
- * discoverable.
677
- *
678
- * @return mixed The authorization code, or false if the authorization
679
- * code could not be determined.
680
- */
681
- protected function getCode() {
682
- if (isset($_REQUEST['code'])) {
683
- if ($this->state !== null &&
684
- isset($_REQUEST['state']) &&
685
- $this->state === $_REQUEST['state']) {
686
-
687
- // CSRF state has done its job, so clear it
688
- $this->state = null;
689
- $this->clearPersistentData('state');
690
- return $_REQUEST['code'];
691
- } else {
692
- self::errorLog('CSRF state token does not match one provided.');
693
- return false;
694
- }
695
- }
696
-
697
- return false;
698
- }
699
-
700
- /**
701
- * Retrieves the UID with the understanding that
702
- * $this->accessToken has already been set and is
703
- * seemingly legitimate. It relies on Facebook's Graph API
704
- * to retrieve user information and then extract
705
- * the user ID.
706
- *
707
- * @return integer Returns the UID of the Facebook user, or 0
708
- * if the Facebook user could not be determined.
709
- */
710
- protected function getUserFromAccessToken() {
711
- try {
712
- $user_info = $this->api('/me');
713
- return $user_info['id'];
714
- } catch (NXS_FacebookApiException $e) {
715
- return 0;
716
- }
717
- }
718
-
719
- /**
720
- * Returns the access token that should be used for logged out
721
- * users when no authorization code is available.
722
- *
723
- * @return string The application access token, useful for gathering
724
- * public information about users and applications.
725
- */
726
- protected function getApplicationAccessToken() {
727
- return $this->appId.'|'.$this->appSecret;
728
- }
729
-
730
- /**
731
- * Lays down a CSRF state token for this process.
732
- *
733
- * @return void
734
- */
735
- protected function establishCSRFTokenState() {
736
- if ($this->state === null) {
737
- $this->state = md5(uniqid(mt_rand(), true));
738
- $this->setPersistentData('state', $this->state);
739
- }
740
- }
741
-
742
- /**
743
- * Retrieves an access token for the given authorization code
744
- * (previously generated from www.facebook.com on behalf of
745
- * a specific user). The authorization code is sent to graph.facebook.com
746
- * and a legitimate access token is generated provided the access token
747
- * and the user for which it was generated all match, and the user is
748
- * either logged in to Facebook or has granted an offline access permission.
749
- *
750
- * @param string $code An authorization code.
751
- * @return mixed An access token exchanged for the authorization code, or
752
- * false if an access token could not be generated.
753
- */
754
- protected function getAccessTokenFromCode($code, $redirect_uri = null) {
755
- if (empty($code)) {
756
- return false;
757
- }
758
-
759
- if ($redirect_uri === null) {
760
- $redirect_uri = $this->getCurrentUrl();
761
- }
762
-
763
- try {
764
- // need to circumvent json_decode by calling _oauthRequest
765
- // directly, since response isn't JSON format.
766
- $access_token_response =
767
- $this->_oauthRequest(
768
- $this->getUrl('graph', '/oauth/access_token'),
769
- $params = array('client_id' => $this->getAppId(),
770
- 'client_secret' => $this->getAppSecret(),
771
- 'redirect_uri' => $redirect_uri,
772
- 'code' => $code));
773
- } catch (NXS_FacebookApiException $e) {
774
- // most likely that user very recently revoked authorization.
775
- // In any event, we don't have an access token, so say so.
776
- return false;
777
- }
778
-
779
- if (empty($access_token_response)) {
780
- return false;
781
- }
782
-
783
- $response_params = array();
784
- parse_str($access_token_response, $response_params);
785
- if (!isset($response_params['access_token'])) {
786
- return false;
787
- }
788
-
789
- return $response_params['access_token'];
790
- }
791
-
792
- /**
793
- * Invoke the old restserver.php endpoint.
794
- *
795
- * @param array $params Method call object
796
- *
797
- * @return mixed The decoded response object
798
- * @throws NXS_FacebookApiException
799
- */
800
- protected function _restserver($params) {
801
- // generic application level parameters
802
- $params['api_key'] = $this->getAppId();
803
- $params['format'] = 'json-strings';
804
-
805
- $result = json_decode($this->_oauthRequest(
806
- $this->getApiUrl($params['method']),
807
- $params
808
- ), true);
809
-
810
- // results are returned, errors are thrown
811
- if (is_array($result) && isset($result['error_code'])) {
812
- $this->throwAPIException($result);
813
- // @codeCoverageIgnoreStart
814
- }
815
- // @codeCoverageIgnoreEnd
816
-
817
- $method = strtolower($params['method']);
818
- if ($method === 'auth.expiresession' ||
819
- $method === 'auth.revokeauthorization') {
820
- $this->destroySession();
821
- }
822
-
823
- return $result;
824
- }
825
-
826
- /**
827
- * Return true if this is video post.
828
- *
829
- * @param string $path The path
830
- * @param string $method The http method (default 'GET')
831
- *
832
- * @return boolean true if this is video post
833
- */
834
- protected function isVideoPost($path, $method = 'GET') {
835
- if ($method == 'POST' && preg_match("/^(\/)(.+)(\/)(videos)$/", $path)) {
836
- return true;
837
- }
838
- return false;
839
- }
840
-
841
- /**
842
- * Invoke the Graph API.
843
- *
844
- * @param string $path The path (required)
845
- * @param string $method The http method (default 'GET')
846
- * @param array $params The query/post data
847
- *
848
- * @return mixed The decoded response object
849
- * @throws NXS_FacebookApiException
850
- */
851
- protected function _graph($path, $method = 'GET', $params = array()) {
852
- if (is_array($method) && empty($params)) {
853
- $params = $method;
854
- $method = 'GET';
855
- }
856
- $params['method'] = $method; // method override as we always do a POST
857
-
858
- if ($this->isVideoPost($path, $method)) {
859
- $domainKey = 'graph_video';
860
- } else {
861
- $domainKey = 'graph';
862
- }
863
-
864
- $result = json_decode($this->_oauthRequest(
865
- $this->getUrl($domainKey, $path),
866
- $params
867
- ), true);
868
-
869
- // prr($domainKey); prr($path); prr($params);
870
- // results are returned, errors are thrown
871
- if (is_array($result) && isset($result['error'])) {
872
- $this->throwAPIException($result);
873
- // @codeCoverageIgnoreStart
874
- }
875
- // @codeCoverageIgnoreEnd
876
-
877
- return $result;
878
- }
879
-
880
- /**
881
- * Make a OAuth Request.
882
- *
883
- * @param string $url The path (required)
884
- * @param array $params The query/post data
885
- *
886
- * @return string The decoded response object
887
- * @throws NXS_FacebookApiException
888
- */
889
- protected function _oauthRequest($url, $params) {
890
- if (!isset($params['access_token'])) {
891
- $params['access_token'] = $this->getAccessToken();
892
- }
893
-
894
- // json_encode all params values that are not strings
895
- foreach ($params as $key => $value) {
896
- if (!is_string($value)) {
897
- $params[$key] = json_encode($value);
898
- }
899
- }
900
-
901
- return $this->makeRequest($url, $params);
902
- }
903
-
904
- /**
905
- * Makes an HTTP request. This method can be overridden by subclasses if
906
- * developers want to do fancier things or use something other than curl to
907
- * make the request.
908
- *
909
- * @param string $url The URL to make the request to
910
- * @param array $params The parameters to use for the POST body
911
- * @param CurlHandler $ch Initialized curl handle
912
- *
913
- * @return string The response text
914
- */
915
- protected function makeRequest($url, $params, $ch=null) {
916
- if (!$ch) {
917
- $ch = curl_init();
918
- }
919
- // echo $url;
920
- $opts = self::$CURL_OPTS;
921
- if ($this->getFileUploadSupport()) {
922
- $opts[CURLOPT_POSTFIELDS] = $params;
923
- } else {
924
- $opts[CURLOPT_POSTFIELDS] = http_build_query($params, null, '&');
925
- }
926
- $opts[CURLOPT_URL] = $url;
927
-
928
- // disable the 'Expect: 100-continue' behaviour. This causes CURL to wait
929
- // for 2 seconds if the server does not support this header.
930
- if (isset($opts[CURLOPT_HTTPHEADER])) {
931
- $existing_headers = $opts[CURLOPT_HTTPHEADER];
932
- $existing_headers[] = 'Expect:';
933
- $opts[CURLOPT_HTTPHEADER] = $existing_headers;
934
- } else {
935
- $opts[CURLOPT_HTTPHEADER] = array('Expect:');
936
- }
937
-
938
- curl_setopt_array($ch, $opts);
939
-
940
- $result = curl_exec($ch);
941
-
942
- if (curl_errno($ch) == 60) { // CURLE_SSL_CACERT
943
- self::errorLog('Invalid or no certificate authority found, using bundled information');
944
- curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/fb_ca_chain_bundle.crt');
945
- $result = curl_exec($ch);
946
- }
947
-
948
- if (curl_errno($ch) == 60) { // CURLE_SSL_CACERT
949
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
950
- $result = curl_exec($ch);
951
- }
952
-
953
- // With dual stacked DNS responses, it's possible for a server to
954
- // have IPv6 enabled but not have IPv6 connectivity. If this is
955
- // the case, curl will try IPv4 first and if that fails, then it will
956
- // fall back to IPv6 and the error EHOSTUNREACH is returned by the
957
- // operating system.
958
- if ($result === false && empty($opts[CURLOPT_IPRESOLVE])) {
959
- $matches = array();
960
- $regex = '/Failed to connect to ([^:].*): Network is unreachable/';
961
- if (preg_match($regex, curl_error($ch), $matches)) {
962
- if (strlen(@inet_pton($matches[1])) === 16) {
963
- self::errorLog('Invalid IPv6 configuration on server, '.
964
- 'Please disable or get native IPv6 on your server.');
965
- self::$CURL_OPTS[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4;
966
- curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
967
- $result = curl_exec($ch);
968
- }
969
- }
970
- }
971
-
972
- if ($result === false) {
973
- $e = new NXS_FacebookApiException(array(
974
- 'error_code' => curl_errno($ch),
975
- 'error' => array(
976
- 'message' => curl_error($ch),
977
- 'type' => 'CurlException',
978
- ),
979
- ));
980
- curl_close($ch);
981
- throw $e;
982
- }
983
- curl_close($ch);
984
- return $result;
985
- }
986
-
987
- /**
988
- * Parses a signed_request and validates the signature.
989
- *
990
- * @param string $signed_request A signed token
991
- * @return array The payload inside it or null if the sig is wrong
992
- */
993
- protected function parseSignedRequest($signed_request) {
994
- list($encoded_sig, $payload) = explode('.', $signed_request, 2);
995
-
996
- // decode the data
997
- $sig = self::base64UrlDecode($encoded_sig);
998
- $data = json_decode(self::base64UrlDecode($payload), true);
999
-
1000
- if (strtoupper($data['algorithm']) !== self::SIGNED_REQUEST_ALGORITHM) {
1001
- self::errorLog(
1002
- 'Unknown algorithm. Expected ' . self::SIGNED_REQUEST_ALGORITHM);
1003
- return null;
1004
- }
1005
-
1006
- // check sig
1007
- $expected_sig = hash_hmac('sha256', $payload,
1008
- $this->getAppSecret(), $raw = true);
1009
- if ($sig !== $expected_sig) {
1010
- self::errorLog('Bad Signed JSON signature!');
1011
- return null;
1012
- }
1013
-
1014
- return $data;
1015
- }
1016
-
1017
- /**
1018
- * Makes a signed_request blob using the given data.
1019
- *
1020
- * @param array The data array.
1021
- * @return string The signed request.
1022
- */
1023
- protected function makeSignedRequest($data) {
1024
- if (!is_array($data)) {
1025
- throw new InvalidArgumentException(
1026
- 'makeSignedRequest expects an array. Got: ' . print_r($data, true));
1027
- }
1028
- $data['algorithm'] = self::SIGNED_REQUEST_ALGORITHM;
1029
- $data['issued_at'] = time();
1030
- $json = json_encode($data);
1031
- $b64 = self::base64UrlEncode($json);
1032
- $raw_sig = hash_hmac('sha256', $b64, $this->getAppSecret(), $raw = true);
1033
- $sig = self::base64UrlEncode($raw_sig);
1034
- return $sig.'.'.$b64;
1035
- }
1036
-
1037
- /**
1038
- * Build the URL for api given parameters.
1039
- *
1040
- * @param $method String the method name.
1041
- * @return string The URL for the given parameters
1042
- */
1043
- protected function getApiUrl($method) {
1044
- static $READ_ONLY_CALLS =
1045
- array('admin.getallocation' => 1,
1046
- 'admin.getappproperties' => 1,
1047
- 'admin.getbannedusers' => 1,
1048
- 'admin.getlivestreamvialink' => 1,
1049
- 'admin.getmetrics' => 1,
1050
- 'admin.getrestrictioninfo' => 1,
1051
- 'application.getpublicinfo' => 1,
1052
- 'auth.getapppublickey' => 1,
1053
- 'auth.getsession' => 1,
1054
- 'auth.getsignedpublicsessiondata' => 1,
1055
- 'comments.get' => 1,
1056
- 'connect.getunconnectedfriendscount' => 1,
1057
- 'dashboard.getactivity' => 1,
1058
- 'dashboard.getcount' => 1,
1059
- 'dashboard.getglobalnews' => 1,
1060
- 'dashboard.getnews' => 1,
1061
- 'dashboard.multigetcount' => 1,
1062
- 'dashboard.multigetnews' => 1,
1063
- 'data.getcookies' => 1,
1064
- 'events.get' => 1,
1065
- 'events.getmembers' => 1,
1066
- 'fbml.getcustomtags' => 1,
1067
- 'feed.getappfriendstories' => 1,
1068
- 'feed.getregisteredtemplatebundlebyid' => 1,
1069
- 'feed.getregisteredtemplatebundles' => 1,
1070
- 'fql.multiquery' => 1,
1071
- 'fql.query' => 1,
1072
- 'friends.arefriends' => 1,
1073
- 'friends.get' => 1,
1074
- 'friends.getappusers' => 1,
1075
- 'friends.getlists' => 1,
1076
- 'friends.getmutualfriends' => 1,
1077
- 'gifts.get' => 1,
1078
- 'groups.get' => 1,
1079
- 'groups.getmembers' => 1,
1080
- 'intl.gettranslations' => 1,
1081
- 'links.get' => 1,
1082
- 'notes.get' => 1,
1083
- 'notifications.get' => 1,
1084
- 'pages.getinfo' => 1,
1085
- 'pages.isadmin' => 1,
1086
- 'pages.isappadded' => 1,
1087
- 'pages.isfan' => 1,
1088
- 'permissions.checkavailableapiaccess' => 1,
1089
- 'permissions.checkgrantedapiaccess' => 1,
1090
- 'photos.get' => 1,
1091
- 'photos.getalbums' => 1,
1092
- 'photos.gettags' => 1,
1093
- 'profile.getinfo' => 1,
1094
- 'profile.getinfooptions' => 1,
1095
- 'stream.get' => 1,
1096
- 'stream.getcomments' => 1,
1097
- 'stream.getfilters' => 1,
1098
- 'users.getinfo' => 1,
1099
- 'users.getloggedinuser' => 1,
1100
- 'users.getstandardinfo' => 1,
1101
- 'users.hasapppermission' => 1,
1102
- 'users.isappuser' => 1,
1103
- 'users.isverified' => 1,
1104
- 'video.getuploadlimits' => 1);
1105
- $name = 'api';
1106
- if (isset($READ_ONLY_CALLS[strtolower($method)])) {
1107
- $name = 'api_read';
1108
- } else if (strtolower($method) == 'video.upload') {
1109
- $name = 'api_video';
1110
- }
1111
- return self::getUrl($name, 'restserver.php');
1112
- }
1113
-
1114
- /**
1115
- * Build the URL for given domain alias, path and parameters.
1116
- *
1117
- * @param $name string The name of the domain
1118
- * @param $path string Optional path (without a leading slash)
1119
- * @param $params array Optional query parameters
1120
- *
1121
- * @return string The URL for the given parameters
1122
- */
1123
- protected function getUrl($name, $path='', $params=array()) {
1124
- $url = self::$DOMAIN_MAP[$name];
1125
- if ($path) {
1126
- if ($path[0] === '/') {
1127
- $path = substr($path, 1);
1128
- }
1129
- $url .= $path;
1130
- }
1131
- if ($params) {
1132
- $url .= '?' . http_build_query($params, null, '&');
1133
- }
1134
-
1135
- return $url;
1136
- }
1137
-
1138
- protected function getHttpHost() {
1139
- if ($this->trustForwarded && isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
1140
- return $_SERVER['HTTP_X_FORWARDED_HOST'];
1141
- }
1142
- return $_SERVER['HTTP_HOST'];
1143
- }
1144
-
1145
- protected function getHttpProtocol() {
1146
- if ($this->trustForwarded && isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
1147
- if ($_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
1148
- return 'https';
1149
- }
1150
- return 'http';
1151
- }
1152
- if (isset($_SERVER['HTTPS']) &&
1153
- ($_SERVER['HTTPS'] === 'on' || $_SERVER['HTTPS'] == 1)) {
1154
- return 'https';
1155
- }
1156
- return 'http';
1157
- }
1158
-
1159
- /**
1160
- * Get the base domain used for the cookie.
1161
- */
1162
- protected function getBaseDomain() {
1163
- // The base domain is stored in the metadata cookie if not we fallback
1164
- // to the current hostname
1165
- $metadata = $this->getMetadataCookie();
1166
- if (array_key_exists('base_domain', $metadata) &&
1167
- !empty($metadata['base_domain'])) {
1168
- return trim($metadata['base_domain'], '.');
1169
- }
1170
- return $this->getHttpHost();
1171
- }
1172
-
1173
- /**
1174
-
1175
- /**
1176
- * Returns the Current URL, stripping it of known FB parameters that should
1177
- * not persist.
1178
- *
1179
- * @return string The current URL
1180
- */
1181
- protected function getCurrentUrl() {
1182
- $protocol = $this->getHttpProtocol() . '://';
1183
- $host = $this->getHttpHost();
1184
- $currentUrl = $protocol.$host.$_SERVER['REQUEST_URI'];
1185
- $parts = parse_url($currentUrl);
1186
-
1187
- $query = '';
1188
- if (!empty($parts['query'])) {
1189
- // drop known fb params
1190
- $params = explode('&', $parts['query']);
1191
- $retained_params = array();
1192
- foreach ($params as $param) {
1193
- if ($this->shouldRetainParam($param)) {
1194
- $retained_params[] = $param;
1195
- }
1196
- }
1197
-
1198
- if (!empty($retained_params)) {
1199
- $query = '?'.implode($retained_params, '&');
1200
- }
1201
- }
1202
-
1203
- // use port if non default
1204
- $port =
1205
- isset($parts['port']) &&
1206
- (($protocol === 'http://' && $parts['port'] !== 80) ||
1207
- ($protocol === 'https://' && $parts['port'] !== 443))
1208
- ? ':' . $parts['port'] : '';
1209
-
1210
- // rebuild
1211
- return $protocol . $parts['host'] . $port . $parts['path'] . $query;
1212
- }
1213
-
1214
- /**
1215
- * Returns true if and only if the key or key/value pair should
1216
- * be retained as part of the query string. This amounts to
1217
- * a brute-force search of the very small list of Facebook-specific
1218
- * params that should be stripped out.
1219
- *
1220
- * @param string $param A key or key/value pair within a URL's query (e.g.
1221
- * 'foo=a', 'foo=', or 'foo'.
1222
- *
1223
- * @return boolean
1224
- */
1225
- protected function shouldRetainParam($param) {
1226
- foreach (self::$DROP_QUERY_PARAMS as $drop_query_param) {
1227
- if (strpos($param, $drop_query_param.'=') === 0) {
1228
- return false;
1229
- }
1230
- }
1231
-
1232
- return true;
1233
- }
1234
-
1235
- /**
1236
- * Analyzes the supplied result to see if it was thrown
1237
- * because the access token is no longer valid. If that is
1238
- * the case, then we destroy the session.
1239
- *
1240
- * @param $result array A record storing the error message returned
1241
- * by a failed API call.
1242
- */
1243
- protected function throwAPIException($result) { //prr($result);
1244
- $e = new NXS_FacebookApiException($result);
1245
- switch ($e->getType()) {
1246
- // OAuth 2.0 Draft 00 style
1247
- case 'OAuthException':
1248
- // OAuth 2.0 Draft 10 style
1249
- case 'invalid_token':
1250
- // REST server errors are just Exceptions
1251
- case 'Exception':
1252
- $message = $e->getMessage();
1253
- if ((strpos($message, 'Error validating access token') !== false) ||
1254
- (strpos($message, 'Invalid OAuth access token') !== false) ||
1255
- (strpos($message, 'An active access token must be used') !== false)
1256
- ) {
1257
- $this->destroySession();
1258
- }
1259
- break;
1260
- }
1261
-
1262
- throw $e;
1263
- }
1264
-
1265
-
1266
- /**
1267
- * Prints to the error log if you aren't in command line mode.
1268
- *
1269
- * @param string $msg Log message
1270
- */
1271
- protected static function errorLog($msg) {
1272
- // disable error log if we are running in a CLI environment
1273
- // @codeCoverageIgnoreStart
1274
- if (php_sapi_name() != 'cli') {
1275
- error_log($msg);
1276
- }
1277
- // uncomment this if you want to see the errors on the page
1278
- // print 'error_log: '.$msg."\n";
1279
- // @codeCoverageIgnoreEnd
1280
- }
1281
-
1282
- /**
1283
- * Base64 encoding that doesn't need to be urlencode()ed.
1284
- * Exactly the same as base64_encode except it uses
1285
- * - instead of +
1286
- * _ instead of /
1287
- * No padded =
1288
- *
1289
- * @param string $input base64UrlEncoded string
1290
- * @return string
1291
- */
1292
- protected static function base64UrlDecode($input) {
1293
- return base64_decode(strtr($input, '-_', '+/'));
1294
- }
1295
-
1296
- /**
1297
- * Base64 encoding that doesn't need to be urlencode()ed.
1298
- * Exactly the same as base64_encode except it uses
1299
- * - instead of +
1300
- * _ instead of /
1301
- *
1302
- * @param string $input string
1303
- * @return string base64Url encoded string
1304
- */
1305
- protected static function base64UrlEncode($input) {
1306
- $str = strtr(base64_encode($input), '+/', '-_');
1307
- $str = str_replace('=', '', $str);
1308
- return $str;
1309
- }
1310
-
1311
- /**
1312
- * Destroy the current session
1313
- */
1314
- public function destroySession() {
1315
- $this->accessToken = null;
1316
- $this->signedRequest = null;
1317
- $this->user = null;
1318
- $this->clearAllPersistentData();
1319
-
1320
- // Javascript sets a cookie that will be used in getSignedRequest that we
1321
- // need to clear if we can
1322
- $cookie_name = $this->getSignedRequestCookieName();
1323
- if (array_key_exists($cookie_name, $_COOKIE)) {
1324
- unset($_COOKIE[$cookie_name]);
1325
- if (!headers_sent()) {
1326
- $base_domain = $this->getBaseDomain();
1327
- setcookie($cookie_name, '', 1, '/', '.'.$base_domain);
1328
- } else {
1329
- // @codeCoverageIgnoreStart
1330
- self::errorLog(
1331
- 'There exists a cookie that we wanted to clear that we couldn\'t '.
1332
- 'clear because headers was already sent. Make sure to do the first '.
1333
- 'API call before outputing anything.'
1334
- );
1335
- // @codeCoverageIgnoreEnd
1336
- }
1337
- }
1338
- }
1339
-
1340
- /**
1341
- * Parses the metadata cookie that our Javascript API set
1342
- *
1343
- * @return an array mapping key to value
1344
- */
1345
- protected function getMetadataCookie() {
1346
- $cookie_name = $this->getMetadataCookieName();
1347
- if (!array_key_exists($cookie_name, $_COOKIE)) {
1348
- return array();
1349
- }
1350
-
1351
- // The cookie value can be wrapped in "-characters so remove them
1352
- $cookie_value = trim($_COOKIE[$cookie_name], '"');
1353
-
1354
- if (empty($cookie_value)) {
1355
- return array();
1356
- }
1357
-
1358
- $parts = explode('&', $cookie_value);
1359
- $metadata = array();
1360
- foreach ($parts as $part) {
1361
- $pair = explode('=', $part, 2);
1362
- if (!empty($pair[0])) {
1363
- $metadata[urldecode($pair[0])] =
1364
- (count($pair) > 1) ? urldecode($pair[1]) : '';
1365
- }
1366
- }
1367
-
1368
- return $metadata;
1369
- }
1370
-
1371
- protected static function isAllowedDomain($big, $small) {
1372
- if ($big === $small) {
1373
- return true;
1374
- }
1375
- return self::endsWith($big, '.'.$small);
1376
- }
1377
-
1378
- protected static function endsWith($big, $small) {
1379
- $len = strlen($small);
1380
- if ($len === 0) {
1381
- return true;
1382
- }
1383
- return substr($big, -$len) === $small;
1384
- }
1385
-
1386
- /**
1387
- * Each of the following four methods should be overridden in
1388
- * a concrete subclass, as they are in the provided Facebook class.
1389
- * The Facebook class uses PHP sessions to provide a primitive
1390
- * persistent store, but another subclass--one that you implement--
1391
- * might use a database, memcache, or an in-memory cache.
1392
- *
1393
- * @see Facebook
1394
- */
1395
-
1396
- /**
1397
- * Stores the given ($key, $value) pair, so that future calls to
1398
- * getPersistentData($key) return $value. This call may be in another request.
1399
- *
1400
- * @param string $key
1401
- * @param array $value
1402
- *
1403
- * @return void
1404
- */
1405
- abstract protected function setPersistentData($key, $value);
1406
-
1407
- /**
1408
- * Get the data for $key, persisted by BaseFacebook::setPersistentData()
1409
- *
1410
- * @param string $key The key of the data to retrieve
1411
- * @param boolean $default The default value to return if $key is not found
1412
- *
1413
- * @return mixed
1414
- */
1415
- abstract protected function getPersistentData($key, $default = false);
1416
-
1417
- /**
1418
- * Clear the data with $key from the persistent storage
1419
- *
1420
- * @param string $key
1421
- * @return void
1422
- */
1423
- abstract protected function clearPersistentData($key);
1424
-
1425
- /**
1426
- * Clear all data from the persistent storage
1427
- *
1428
- * @return void
1429
- */
1430
- abstract protected function clearAllPersistentData();
1431
- }
1
+ <?php
2
+ /**
3
+ * Copyright 2011 Facebook, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
6
+ * not use this file except in compliance with the License. You may obtain
7
+ * a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ * License for the specific language governing permissions and limitations
15
+ * under the License.
16
+ */
17
+
18
+ if (!function_exists('curl_init')) {
19
+ throw new Exception('Facebook needs the CURL PHP extension.');
20
+ }
21
+ if (!function_exists('json_decode')) {
22
+ throw new Exception('Facebook needs the JSON PHP extension.');
23
+ }
24
+
25
+ /**
26
+ * Thrown when an API call returns an exception.
27
+ *
28
+ * @author Naitik Shah <naitik@facebook.com>
29
+ */
30
+ class NXS_FacebookApiException extends Exception
31
+ {
32
+ /**
33
+ * The result from the API server that represents the exception information.
34
+ */
35
+ protected $result;
36
+
37
+ /**
38
+ * Make a new API Exception with the given result.
39
+ *
40
+ * @param array $result The result from the API server
41
+ */
42
+ public function __construct($result) {
43
+ $this->result = $result;
44
+
45
+ $code = isset($result['error_code']) ? $result['error_code'] : 0;
46
+
47
+ if (isset($result['error_description'])) {
48
+ // OAuth 2.0 Draft 10 style
49
+ $msg = $result['error_description'];
50
+ } else if (isset($result['error']) && is_array($result['error'])) {
51
+ // OAuth 2.0 Draft 00 style
52
+ $msg = $result['error']['message'];
53
+ if ($code==0 && isset($result['error']['code'])) $code = $result['error']['code'];
54
+ } else if (isset($result['error_msg'])) {
55
+ // Rest server style
56
+ $msg = $result['error_msg'];
57
+ } else {
58
+ $msg = 'Unknown Error. Check getResult()';
59
+ }
60
+
61
+ parent::__construct($msg, $code);
62
+ }
63
+
64
+ /**
65
+ * Return the associated result object returned by the API server.
66
+ *
67
+ * @return array The result from the API server
68
+ */
69
+ public function getResult() {
70
+ return $this->result;
71
+ }
72
+
73
+ /**
74
+ * Returns the associated type for the error. This will default to
75
+ * 'Exception' when a type is not available.
76
+ *
77
+ * @return string
78
+ */
79
+ public function getType() {
80
+ if (isset($this->result['error'])) {
81
+ $error = $this->result['error'];
82
+ if (is_string($error)) {
83
+ // OAuth 2.0 Draft 10 style
84
+ return $error;
85
+ } else if (is_array($error)) {
86
+ // OAuth 2.0 Draft 00 style
87
+ if (isset($error['type'])) {
88
+ return $error['type'];
89
+ }
90
+ }
91
+ }
92
+
93
+ return 'Exception';
94
+ }
95
+
96
+ /**
97
+ * To make debugging easier.
98
+ *
99
+ * @return string The string representation of the error
100
+ */
101
+ public function __toString() {
102
+ $str = $this->getType() . ': ';
103
+ if ($this->code != 0) {
104
+ $str .= $this->code . ': ';
105
+ }
106
+ return $str . $this->message;
107
+ }
108
+ }
109
+
110
+ /**
111
+ * Provides access to the Facebook Platform. This class provides
112
+ * a majority of the functionality needed, but the class is abstract
113
+ * because it is designed to be sub-classed. The subclass must
114
+ * implement the four abstract methods listed at the bottom of
115
+ * the file.
116
+ *
117
+ * @author Naitik Shah <naitik@facebook.com>
118
+ */
119
+ abstract class NXS_BaseFacebook
120
+ {
121
+ /**
122
+ * Version.
123
+ */
124
+ const VERSION = '3.2.0';
125
+
126
+ /**
127
+ * Signed Request Algorithm.
128
+ */
129
+ const SIGNED_REQUEST_ALGORITHM = 'HMAC-SHA256';
130
+
131
+ /**
132
+ * Default options for curl.
133
+ */
134
+ public static $CURL_OPTS = array(
135
+ CURLOPT_CONNECTTIMEOUT => 10,
136
+ CURLOPT_RETURNTRANSFER => true,
137
+ CURLOPT_TIMEOUT => 60,
138
+ CURLOPT_USERAGENT => 'facebook-php-3.2',
139
+ );
140
+
141
+ /**
142
+ * List of query parameters that get automatically dropped when rebuilding
143
+ * the current URL.
144
+ */
145
+ protected static $DROP_QUERY_PARAMS = array(
146
+ 'code',
147
+ 'state',
148
+ 'signed_request',
149
+ );
150
+
151
+ /**
152
+ * Maps aliases to Facebook domains.
153
+ */
154
+ public static $DOMAIN_MAP = array(
155
+ 'api' => 'https://api.facebook.com/',
156
+ 'api_video' => 'https://api-video.facebook.com/',
157
+ 'api_read' => 'https://api-read.facebook.com/',
158
+ 'graph' => 'https://graph.facebook.com/',
159
+ 'graph_video' => 'https://graph-video.facebook.com/',
160
+ 'www' => 'https://www.facebook.com/',
161
+ );
162
+
163
+ /**
164
+ * The Application ID.
165
+ *
166
+ * @var string
167
+ */
168
+ protected $appId;
169
+
170
+ /**
171
+ * The Application App Secret.
172
+ *
173
+ * @var string
174
+ */
175
+ protected $appSecret;
176
+
177
+ /**
178
+ * The ID of the Facebook user, or 0 if the user is logged out.
179
+ *
180
+ * @var integer
181
+ */
182
+ protected $user;
183
+
184
+ /**
185
+ * The data from the signed_request token.
186
+ */
187
+ protected $signedRequest;
188
+
189
+ /**
190
+ * A CSRF state variable to assist in the defense against CSRF attacks.
191
+ */
192
+ protected $state;
193
+
194
+ /**
195
+ * The OAuth access token received in exchange for a valid authorization
196
+ * code. null means the access token has yet to be determined.
197
+ *
198
+ * @var string
199
+ */
200
+ protected $accessToken = null;
201
+
202
+ /**
203
+ * Indicates if the CURL based @ syntax for file uploads is enabled.
204
+ *
205
+ * @var boolean
206
+ */
207
+ protected $fileUploadSupport = false;
208
+
209
+ /**
210
+ * Indicates if we trust HTTP_X_FORWARDED_* headers.
211
+ *
212
+ * @var boolean
213
+ */
214
+ protected $trustForwarded = false;
215
+
216
+ /**
217
+ * Initialize a Facebook Application.
218
+ *
219
+ * The configuration:
220
+ * - appId: the application ID
221
+ * - secret: the application secret
222
+ * - fileUpload: (optional) boolean indicating if file uploads are enabled
223
+ *
224
+ * @param array $config The application configuration
225
+ */
226
+ public function __construct($config) {
227
+ $this->setAppId($config['appId']);
228
+ $this->setAppSecret($config['secret']);
229
+ if (isset($config['fileUpload'])) {
230
+ $this->setFileUploadSupport($config['fileUpload']);
231
+ }
232
+ if (isset($config['trustForwarded']) && $config['trustForwarded']) {
233
+ $this->trustForwarded = true;
234
+ }
235
+ $state = $this->getPersistentData('state');
236
+ if (!empty($state)) {
237
+ $this->state = $state;
238
+ }
239
+ }
240
+
241
+ /**
242
+ * Set the Application ID.
243
+ *
244
+ * @param string $appId The Application ID
245
+ * @return BaseFacebook
246
+ */
247
+ public function setAppId($appId) {
248
+ $this->appId = $appId;
249
+ return $this;
250
+ }
251
+
252
+ /**
253
+ * Get the Application ID.
254
+ *
255
+ * @return string the Application ID
256
+ */
257
+ public function getAppId() {
258
+ return $this->appId;
259
+ }
260
+
261
+ /**
262
+ * Set the App Secret.
263
+ *
264
+ * @param string $apiSecret The App Secret
265
+ * @return BaseFacebook
266
+ * @deprecated
267
+ */
268
+ public function setApiSecret($apiSecret) {
269
+ $this->setAppSecret($apiSecret);
270
+ return $this;
271
+ }
272
+
273
+ /**
274
+ * Set the App Secret.
275
+ *
276
+ * @param string $appSecret The App Secret
277
+ * @return BaseFacebook
278
+ */
279
+ public function setAppSecret($appSecret) {
280
+ $this->appSecret = $appSecret;
281
+ return $this;
282
+ }
283
+
284
+ /**
285
+ * Get the App Secret.
286
+ *
287
+ * @return string the App Secret
288
+ * @deprecated
289
+ */
290
+ public function getApiSecret() {
291
+ return $this->getAppSecret();
292
+ }
293
+
294
+ /**
295
+ * Get the App Secret.
296
+ *
297
+ * @return string the App Secret
298
+ */
299
+ public function getAppSecret() {
300
+ return $this->appSecret;
301
+ }
302
+
303
+ /**
304
+ * Set the file upload support status.
305
+ *
306
+ * @param boolean $fileUploadSupport The file upload support status.
307
+ * @return BaseFacebook
308
+ */
309
+ public function setFileUploadSupport($fileUploadSupport) {
310
+ $this->fileUploadSupport = $fileUploadSupport;
311
+ return $this;
312
+ }
313
+
314
+ /**
315
+ * Get the file upload support status.
316
+ *
317
+ * @return boolean true if and only if the server supports file upload.
318
+ */
319
+ public function getFileUploadSupport() {
320
+ return $this->fileUploadSupport;
321
+ }
322
+
323
+ /**
324
+ * DEPRECATED! Please use getFileUploadSupport instead.
325
+ *
326
+ * Get the file upload support status.
327
+ *
328
+ * @return boolean true if and only if the server supports file upload.
329
+ */
330
+ public function useFileUploadSupport() {
331
+ return $this->getFileUploadSupport();
332
+ }
333
+
334
+ /**
335
+ * Sets the access token for api calls. Use this if you get
336
+ * your access token by other means and just want the SDK
337
+ * to use it.
338
+ *
339
+ * @param string $access_token an access token.
340
+ * @return BaseFacebook
341
+ */
342
+ public function setAccessToken($access_token) {
343
+ $this->accessToken = $access_token;
344
+ return $this;
345
+ }
346
+
347
+ /**
348
+ * Extend an access token, while removing the short-lived token that might
349
+ * have been generated via client-side flow. Thanks to http://bit.ly/b0Pt0H
350
+ * for the workaround.
351
+ */
352
+ public function setExtendedAccessToken() {
353
+ try {
354
+ // need to circumvent json_decode by calling _oauthRequest
355
+ // directly, since response isn't JSON format.
356
+ $access_token_response = $this->_oauthRequest(
357
+ $this->getUrl('graph', '/oauth/access_token'),
358
+ $params = array(
359
+ 'client_id' => $this->getAppId(),
360
+ 'client_secret' => $this->getAppSecret(),
361
+ 'grant_type' => 'fb_exchange_token',
362
+ 'fb_exchange_token' => $this->getAccessToken(),
363
+ )
364
+ );
365
+ }
366
+ catch (NXS_FacebookApiException $e) {
367
+ // most likely that user very recently revoked authorization.
368
+ // In any event, we don't have an access token, so say so.
369
+ return false;
370
+ }
371
+
372
+ if (empty($access_token_response)) {
373
+ return false;
374
+ }
375
+
376
+ $response_params = array();
377
+ parse_str($access_token_response, $response_params);
378
+
379
+ if (!isset($response_params['access_token'])) {
380
+ return false;
381
+ }
382
+
383
+ $this->destroySession();
384
+
385
+ $this->setPersistentData(
386
+ 'access_token', $response_params['access_token']
387
+ );
388
+ }
389
+
390
+ /**
391
+ * Determines the access token that should be used for API calls.
392
+ * The first time this is called, $this->accessToken is set equal
393
+ * to either a valid user access token, or it's set to the application
394
+ * access token if a valid user access token wasn't available. Subsequent
395
+ * calls return whatever the first call returned.
396
+ *
397
+ * @return string The access token
398
+ */
399
+ public function getAccessToken() {
400
+ if ($this->accessToken !== null) {
401
+ // we've done this already and cached it. Just return.
402
+ return $this->accessToken;
403
+ }
404
+
405
+ // first establish access token to be the application
406
+ // access token, in case we navigate to the /oauth/access_token
407
+ // endpoint, where SOME access token is required.
408
+ $this->setAccessToken($this->getApplicationAccessToken());
409
+ $user_access_token = $this->getUserAccessToken();
410
+ if ($user_access_token) {
411
+ $this->setAccessToken($user_access_token);
412
+ }
413
+
414
+ return $this->accessToken;
415
+ }
416
+
417
+ /**
418
+ * Determines and returns the user access token, first using
419
+ * the signed request if present, and then falling back on
420
+ * the authorization code if present. The intent is to
421
+ * return a valid user access token, or false if one is determined
422
+ * to not be available.
423
+ *
424
+ * @return string A valid user access token, or false if one
425
+ * could not be determined.
426
+ */
427
+ protected function getUserAccessToken() {
428
+ // first, consider a signed request if it's supplied.
429
+ // if there is a signed request, then it alone determines
430
+ // the access token.
431
+ $signed_request = $this->getSignedRequest();
432
+ if ($signed_request) {
433
+ // apps.facebook.com hands the access_token in the signed_request
434
+ if (array_key_exists('oauth_token', $signed_request)) {
435
+ $access_token = $signed_request['oauth_token'];
436
+ $this->setPersistentData('access_token', $access_token);
437
+ return $access_token;
438
+ }
439
+
440
+ // the JS SDK puts a code in with the redirect_uri of ''
441
+ if (array_key_exists('code', $signed_request)) {
442
+ $code = $signed_request['code'];
443
+ $access_token = $this->getAccessTokenFromCode($code, '');
444
+ if ($access_token) {
445
+ $this->setPersistentData('code', $code);
446
+ $this->setPersistentData('access_token', $access_token);
447
+ return $access_token;
448
+ }
449
+ }
450
+
451
+ // signed request states there's no access token, so anything
452
+ // stored should be cleared.
453
+ $this->clearAllPersistentData();
454
+ return false; // respect the signed request's data, even
455
+ // if there's an authorization code or something else
456
+ }
457
+
458
+ $code = $this->getCode();
459
+ if ($code && $code != $this->getPersistentData('code')) {
460
+ $access_token = $this->getAccessTokenFromCode($code);
461
+ if ($access_token) {
462
+ $this->setPersistentData('code', $code);
463
+ $this->setPersistentData('access_token', $access_token);
464
+ return $access_token;
465
+ }
466
+
467
+ // code was bogus, so everything based on it should be invalidated.
468
+ $this->clearAllPersistentData();
469
+ return false;
470
+ }
471
+
472
+ // as a fallback, just return whatever is in the persistent
473
+ // store, knowing nothing explicit (signed request, authorization
474
+ // code, etc.) was present to shadow it (or we saw a code in $_REQUEST,
475
+ // but it's the same as what's in the persistent store)
476
+ return $this->getPersistentData('access_token');
477
+ }
478
+
479
+ /**
480
+ * Retrieve the signed request, either from a request parameter or,
481
+ * if not present, from a cookie.
482
+ *
483
+ * @return string the signed request, if available, or null otherwise.
484
+ */
485
+ public function getSignedRequest() {
486
+ if (!$this->signedRequest) {
487
+ if (isset($_REQUEST['signed_request'])) {
488
+ $this->signedRequest = $this->parseSignedRequest(
489
+ $_REQUEST['signed_request']);
490
+ } else if (isset($_COOKIE[$this->getSignedRequestCookieName()])) {
491
+ $this->signedRequest = $this->parseSignedRequest(
492
+ $_COOKIE[$this->getSignedRequestCookieName()]);
493
+ }
494
+ }
495
+ return $this->signedRequest;
496
+ }
497
+
498
+ /**
499
+ * Get the UID of the connected user, or 0
500
+ * if the Facebook user is not connected.
501
+ *
502
+ * @return string the UID if available.
503
+ */
504
+ public function getUser() {
505
+ if ($this->user !== null) {
506
+ // we've already determined this and cached the value.
507
+ return $this->user;
508
+ }
509
+
510
+ return $this->user = $this->getUserFromAvailableData();
511
+ }
512
+
513
+ /**
514
+ * Determines the connected user by first examining any signed
515
+ * requests, then considering an authorization code, and then
516
+ * falling back to any persistent store storing the user.
517
+ *
518
+ * @return integer The id of the connected Facebook user,
519
+ * or 0 if no such user exists.
520
+ */
521
+ protected function getUserFromAvailableData() {
522
+ // if a signed request is supplied, then it solely determines
523
+ // who the user is.
524
+ $signed_request = $this->getSignedRequest();
525
+ if ($signed_request) {
526
+ if (array_key_exists('user_id', $signed_request)) {
527
+ $user = $signed_request['user_id'];
528
+ $this->setPersistentData('user_id', $signed_request['user_id']);
529
+ return $user;
530
+ }
531
+
532
+ // if the signed request didn't present a user id, then invalidate
533
+ // all entries in any persistent store.
534
+ $this->clearAllPersistentData();
535
+ return 0;
536
+ }
537
+
538
+ $user = $this->getPersistentData('user_id', $default = 0);
539
+ $persisted_access_token = $this->getPersistentData('access_token');
540
+
541
+ // use access_token to fetch user id if we have a user access_token, or if
542
+ // the cached access token has changed.
543
+ $access_token = $this->getAccessToken();
544
+ if ($access_token &&
545
+ $access_token != $this->getApplicationAccessToken() &&
546
+ !($user && $persisted_access_token == $access_token)) {
547
+ $user = $this->getUserFromAccessToken();
548
+ if ($user) {
549
+ $this->setPersistentData('user_id', $user);
550
+ } else {
551
+ $this->clearAllPersistentData();
552
+ }
553
+ }
554
+
555
+ return $user;
556
+ }
557
+
558
+ /**
559
+ * Get a Login URL for use with redirects. By default, full page redirect is
560
+ * assumed. If you are using the generated URL with a window.open() call in
561
+ * JavaScript, you can pass in display=popup as part of the $params.
562
+ *
563
+ * The parameters:
564
+ * - redirect_uri: the url to go to after a successful login
565
+ * - scope: comma separated list of requested extended perms
566
+ *
567
+ * @param array $params Provide custom parameters
568
+ * @return string The URL for the login flow
569
+ */
570
+ public function getLoginUrl($params=array()) {
571
+ $this->establishCSRFTokenState();
572
+ $currentUrl = $this->getCurrentUrl();
573
+
574
+ // if 'scope' is passed as an array, convert to comma separated list
575
+ $scopeParams = isset($params['scope']) ? $params['scope'] : null;
576
+ if ($scopeParams && is_array($scopeParams)) {
577
+ $params['scope'] = implode(',', $scopeParams);
578
+ }
579
+
580
+ return $this->getUrl(
581
+ 'www',
582
+ 'dialog/oauth',
583
+ array_merge(array(
584
+ 'client_id' => $this->getAppId(),
585
+ 'redirect_uri' => $currentUrl, // possibly overwritten
586
+ 'state' => $this->state),
587
+ $params));
588
+ }
589
+
590
+ /**
591
+ * Get a Logout URL suitable for use with redirects.
592
+ *
593
+ * The parameters:
594
+ * - next: the url to go to after a successful logout
595
+ *
596
+ * @param array $params Provide custom parameters
597
+ * @return string The URL for the logout flow
598
+ */
599
+ public function getLogoutUrl($params=array()) {
600
+ return $this->getUrl(
601
+ 'www',
602
+ 'logout.php',
603
+ array_merge(array(
604
+ 'next' => $this->getCurrentUrl(),
605
+ 'access_token' => $this->getUserAccessToken(),
606
+ ), $params)
607
+ );
608
+ }
609
+
610
+ /**
611
+ * Get a login status URL to fetch the status from Facebook.
612
+ *
613
+ * The parameters:
614
+ * - ok_session: the URL to go to if a session is found
615
+ * - no_session: the URL to go to if the user is not connected
616
+ * - no_user: the URL to go to if the user is not signed into facebook
617
+ *
618
+ * @param array $params Provide custom parameters
619
+ * @return string The URL for the logout flow
620
+ */
621
+ public function getLoginStatusUrl($params=array()) {
622
+ return $this->getUrl(
623
+ 'www',
624
+ 'extern/login_status.php',
625
+ array_merge(array(
626
+ 'api_key' => $this->getAppId(),
627
+ 'no_session' => $this->getCurrentUrl(),
628
+ 'no_user' => $this->getCurrentUrl(),
629
+ 'ok_session' => $this->getCurrentUrl(),
630
+ 'session_version' => 3,
631
+ ), $params)
632
+ );
633
+ }
634
+
635
+ /**
636
+ * Make an API call.
637
+ *
638
+ * @return mixed The decoded response
639
+ */
640
+ public function api(/* polymorphic */) {
641
+ $args = func_get_args();
642
+ if (is_array($args[0])) {
643
+ return $this->_restserver($args[0]);
644
+ } else {
645
+ return call_user_func_array(array($this, '_graph'), $args);
646
+ }
647
+ }
648
+
649
+ /**
650
+ * Constructs and returns the name of the cookie that
651
+ * potentially houses the signed request for the app user.
652
+ * The cookie is not set by the BaseFacebook class, but
653
+ * it may be set by the JavaScript SDK.
654
+ *
655
+ * @return string the name of the cookie that would house
656
+ * the signed request value.
657
+ */
658
+ protected function getSignedRequestCookieName() {
659
+ return 'fbsr_'.$this->getAppId();
660
+ }
661
+
662
+ /**
663
+ * Constructs and returns the name of the coookie that potentially contain
664
+ * metadata. The cookie is not set by the BaseFacebook class, but it may be
665
+ * set by the JavaScript SDK.
666
+ *
667
+ * @return string the name of the cookie that would house metadata.
668
+ */
669
+ protected function getMetadataCookieName() {
670
+ return 'fbm_'.$this->getAppId();
671
+ }
672
+
673
+ /**
674
+ * Get the authorization code from the query parameters, if it exists,
675
+ * and otherwise return false to signal no authorization code was
676
+ * discoverable.
677
+ *
678
+ * @return mixed The authorization code, or false if the authorization
679
+ * code could not be determined.
680
+ */
681
+ protected function getCode() {
682
+ if (isset($_REQUEST['code'])) {
683
+ if ($this->state !== null &&
684
+ isset($_REQUEST['state']) &&
685
+ $this->state === $_REQUEST['state']) {
686
+
687
+ // CSRF state has done its job, so clear it
688
+ $this->state = null;
689
+ $this->clearPersistentData('state');
690
+ return $_REQUEST['code'];
691
+ } else {
692
+ self::errorLog('CSRF state token does not match one provided.');
693
+ return false;
694
+ }
695
+ }
696
+
697
+ return false;
698
+ }
699
+
700
+ /**
701
+ * Retrieves the UID with the understanding that
702
+ * $this->accessToken has already been set and is
703
+ * seemingly legitimate. It relies on Facebook's Graph API
704
+ * to retrieve user information and then extract
705
+ * the user ID.
706
+ *
707
+ * @return integer Returns the UID of the Facebook user, or 0
708
+ * if the Facebook user could not be determined.
709
+ */
710
+ protected function getUserFromAccessToken() {
711
+ try {
712
+ $user_info = $this->api('/me');
713
+ return $user_info['id'];
714
+ } catch (NXS_FacebookApiException $e) {
715
+ return 0;
716
+ }
717
+ }
718
+
719
+ /**
720
+ * Returns the access token that should be used for logged out
721
+ * users when no authorization code is available.
722
+ *
723
+ * @return string The application access token, useful for gathering
724
+ * public information about users and applications.
725
+ */
726
+ protected function getApplicationAccessToken() {
727
+ return $this->appId.'|'.$this->appSecret;
728
+ }
729
+
730
+ /**
731
+ * Lays down a CSRF state token for this process.
732
+ *
733
+ * @return void
734
+ */
735
+ protected function establishCSRFTokenState() {
736
+ if ($this->state === null) {
737
+ $this->state = md5(uniqid(mt_rand(), true));
738
+ $this->setPersistentData('state', $this->state);
739
+ }
740
+ }
741
+
742
+ /**
743
+ * Retrieves an access token for the given authorization code
744
+ * (previously generated from www.facebook.com on behalf of
745
+ * a specific user). The authorization code is sent to graph.facebook.com
746
+ * and a legitimate access token is generated provided the access token
747
+ * and the user for which it was generated all match, and the user is
748
+ * either logged in to Facebook or has granted an offline access permission.
749
+ *
750
+ * @param string $code An authorization code.
751
+ * @return mixed An access token exchanged for the authorization code, or
752
+ * false if an access token could not be generated.
753
+ */
754
+ protected function getAccessTokenFromCode($code, $redirect_uri = null) {
755
+ if (empty($code)) {
756
+ return false;
757
+ }
758
+
759
+ if ($redirect_uri === null) {
760
+ $redirect_uri = $this->getCurrentUrl();
761
+ }
762
+
763
+ try {
764
+ // need to circumvent json_decode by calling _oauthRequest
765
+ // directly, since response isn't JSON format.
766
+ $access_token_response =
767
+ $this->_oauthRequest(
768
+ $this->getUrl('graph', '/oauth/access_token'),
769
+ $params = array('client_id' => $this->getAppId(),
770
+ 'client_secret' => $this->getAppSecret(),
771
+ 'redirect_uri' => $redirect_uri,
772
+ 'code' => $code));
773
+ } catch (NXS_FacebookApiException $e) {
774
+ // most likely that user very recently revoked authorization.
775
+ // In any event, we don't have an access token, so say so.
776
+ return false;
777
+ }
778
+
779
+ if (empty($access_token_response)) {
780
+ return false;
781
+ }
782
+
783
+ $response_params = array();
784
+ parse_str($access_token_response, $response_params);
785
+ if (!isset($response_params['access_token'])) {
786
+ return false;
787
+ }
788
+
789
+ return $response_params['access_token'];
790
+ }
791
+
792
+ /**
793
+ * Invoke the old restserver.php endpoint.
794
+ *
795
+ * @param array $params Method call object
796
+ *
797
+ * @return mixed The decoded response object
798
+ * @throws NXS_FacebookApiException
799
+ */
800
+ protected function _restserver($params) {
801
+ // generic application level parameters
802
+ $params['api_key'] = $this->getAppId();
803
+ $params['format'] = 'json-strings';
804
+
805
+ $result = json_decode($this->_oauthRequest(
806
+ $this->getApiUrl($params['method']),
807
+ $params
808
+ ), true);
809
+
810
+ // results are returned, errors are thrown
811
+ if (is_array($result) && isset($result['error_code'])) {
812
+ $this->throwAPIException($result);
813
+ // @codeCoverageIgnoreStart
814
+ }
815
+ // @codeCoverageIgnoreEnd
816
+
817
+ $method = strtolower($params['method']);
818
+ if ($method === 'auth.expiresession' ||
819
+ $method === 'auth.revokeauthorization') {
820
+ $this->destroySession();
821
+ }
822
+
823
+ return $result;
824
+ }
825
+
826
+ /**
827
+ * Return true if this is video post.
828
+ *
829
+ * @param string $path The path
830
+ * @param string $method The http method (default 'GET')
831
+ *
832
+ * @return boolean true if this is video post
833
+ */
834
+ protected function isVideoPost($path, $method = 'GET') {
835
+ if ($method == 'POST' && preg_match("/^(\/)(.+)(\/)(videos)$/", $path)) {
836
+ return true;
837
+ }
838
+ return false;
839
+ }
840
+
841
+ /**
842
+ * Invoke the Graph API.
843
+ *
844
+ * @param string $path The path (required)
845
+ * @param string $method The http method (default 'GET')
846
+ * @param array $params The query/post data
847
+ *
848
+ * @return mixed The decoded response object
849
+ * @throws NXS_FacebookApiException
850
+ */
851
+ protected function _graph($path, $method = 'GET', $params = array()) {
852
+ if (is_array($method) && empty($params)) {
853
+ $params = $method;
854
+ $method = 'GET';
855
+ }
856
+ $params['method'] = $method; // method override as we always do a POST
857
+
858
+ if ($this->isVideoPost($path, $method)) {
859
+ $domainKey = 'graph_video';
860
+ } else {
861
+ $domainKey = 'graph';
862
+ }
863
+
864
+ $result = json_decode($this->_oauthRequest(
865
+ $this->getUrl($domainKey, $path),
866
+ $params
867
+ ), true);
868
+
869
+ // prr($domainKey); prr($path); prr($params);
870
+ // results are returned, errors are thrown
871
+ if (is_array($result) && isset($result['error'])) {
872
+ $this->throwAPIException($result);
873
+ // @codeCoverageIgnoreStart
874
+ }
875
+ // @codeCoverageIgnoreEnd
876
+
877
+ return $result;
878
+ }
879
+
880
+ /**
881
+ * Make a OAuth Request.
882
+ *
883
+ * @param string $url The path (required)
884
+ * @param array $params The query/post data
885
+ *
886
+ * @return string The decoded response object
887
+ * @throws NXS_FacebookApiException
888
+ */
889
+ protected function _oauthRequest($url, $params) {
890
+ if (!isset($params['access_token'])) {
891
+ $params['access_token'] = $this->getAccessToken();
892
+ }
893
+
894
+ // json_encode all params values that are not strings
895
+ foreach ($params as $key => $value) {
896
+ if (!is_string($value)) {
897
+ $params[$key] = json_encode($value);
898
+ }
899
+ }
900
+
901
+ return $this->makeRequest($url, $params);
902
+ }
903
+
904
+ /**
905
+ * Makes an HTTP request. This method can be overridden by subclasses if
906
+ * developers want to do fancier things or use something other than curl to
907
+ * make the request.
908
+ *
909
+ * @param string $url The URL to make the request to
910
+ * @param array $params The parameters to use for the POST body
911
+ * @param CurlHandler $ch Initialized curl handle
912
+ *
913
+ * @return string The response text
914
+ */
915
+ protected function makeRequest($url, $params, $ch=null) {
916
+ if (!$ch) {
917
+ $ch = curl_init();
918
+ }
919
+ // echo $url;
920
+ $opts = self::$CURL_OPTS;
921
+ if ($this->getFileUploadSupport()) {
922
+ $opts[CURLOPT_POSTFIELDS] = $params;
923
+ } else {
924
+ $opts[CURLOPT_POSTFIELDS] = http_build_query($params, null, '&');
925
+ }
926
+ $opts[CURLOPT_URL] = $url;
927
+
928
+ // disable the 'Expect: 100-continue' behaviour. This causes CURL to wait
929
+ // for 2 seconds if the server does not support this header.
930
+ if (isset($opts[CURLOPT_HTTPHEADER])) {
931
+ $existing_headers = $opts[CURLOPT_HTTPHEADER];
932
+ $existing_headers[] = 'Expect:';
933
+ $opts[CURLOPT_HTTPHEADER] = $existing_headers;
934
+ } else {
935
+ $opts[CURLOPT_HTTPHEADER] = array('Expect:');
936
+ }
937
+
938
+ curl_setopt_array($ch, $opts);
939
+
940
+ $result = curl_exec($ch);
941
+
942
+ if (curl_errno($ch) == 60) { // CURLE_SSL_CACERT
943
+ self::errorLog('Invalid or no certificate authority found, using bundled information');
944
+ curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/fb_ca_chain_bundle.crt');
945
+ $result = curl_exec($ch);
946
+ }
947
+
948
+ if (curl_errno($ch) == 60) { // CURLE_SSL_CACERT
949
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
950
+ $result = curl_exec($ch);
951
+ }
952
+
953
+ // With dual stacked DNS responses, it's possible for a server to
954
+ // have IPv6 enabled but not have IPv6 connectivity. If this is
955
+ // the case, curl will try IPv4 first and if that fails, then it will
956
+ // fall back to IPv6 and the error EHOSTUNREACH is returned by the
957
+ // operating system.
958
+ if ($result === false && empty($opts[CURLOPT_IPRESOLVE])) {
959
+ $matches = array();
960
+ $regex = '/Failed to connect to ([^:].*): Network is unreachable/';
961
+ if (preg_match($regex, curl_error($ch), $matches)) {
962
+ if (strlen(@inet_pton($matches[1])) === 16) {
963
+ self::errorLog('Invalid IPv6 configuration on server, '.
964
+ 'Please disable or get native IPv6 on your server.');
965
+ self::$CURL_OPTS[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4;
966
+ curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
967
+ $result = curl_exec($ch);
968
+ }
969
+ }
970
+ }
971
+
972
+ if ($result === false) {
973
+ $e = new NXS_FacebookApiException(array(
974
+ 'error_code' => curl_errno($ch),
975
+ 'error' => array(
976
+ 'message' => curl_error($ch),
977
+ 'type' => 'CurlException',
978
+ ),
979
+ ));
980
+ curl_close($ch);
981
+ throw $e;
982
+ }
983
+ curl_close($ch);
984
+ return $result;
985
+ }
986
+
987
+ /**
988
+ * Parses a signed_request and validates the signature.
989
+ *
990
+ * @param string $signed_request A signed token
991
+ * @return array The payload inside it or null if the sig is wrong
992
+ */
993
+ protected function parseSignedRequest($signed_request) {
994
+ list($encoded_sig, $payload) = explode('.', $signed_request, 2);
995
+
996
+ // decode the data
997
+ $sig = self::base64UrlDecode($encoded_sig);
998
+ $data = json_decode(self::base64UrlDecode($payload), true);
999
+
1000
+ if (strtoupper($data['algorithm']) !== self::SIGNED_REQUEST_ALGORITHM) {
1001
+ self::errorLog(
1002
+ 'Unknown algorithm. Expected ' . self::SIGNED_REQUEST_ALGORITHM);
1003
+ return null;
1004
+ }
1005
+
1006
+ // check sig
1007
+ $expected_sig = hash_hmac('sha256', $payload,
1008
+ $this->getAppSecret(), $raw = true);
1009
+ if ($sig !== $expected_sig) {
1010
+ self::errorLog('Bad Signed JSON signature!');
1011
+ return null;
1012
+ }
1013
+
1014
+ return $data;
1015
+ }
1016
+
1017
+ /**
1018
+ * Makes a signed_request blob using the given data.
1019
+ *
1020
+ * @param array The data array.
1021
+ * @return string The signed request.
1022
+ */
1023
+ protected function makeSignedRequest($data) {
1024
+ if (!is_array($data)) {
1025
+ throw new InvalidArgumentException(
1026
+ 'makeSignedRequest expects an array. Got: ' . print_r($data, true));
1027
+ }
1028
+ $data['algorithm'] = self::SIGNED_REQUEST_ALGORITHM;
1029
+ $data['issued_at'] = time();
1030
+ $json = json_encode($data);
1031
+ $b64 = self::base64UrlEncode($json);
1032
+ $raw_sig = hash_hmac('sha256', $b64, $this->getAppSecret(), $raw = true);
1033
+ $sig = self::base64UrlEncode($raw_sig);
1034
+ return $sig.'.'.$b64;
1035
+ }
1036
+
1037
+ /**
1038
+ * Build the URL for api given parameters.
1039
+ *
1040
+ * @param $method String the method name.
1041
+ * @return string The URL for the given parameters
1042
+ */
1043
+ protected function getApiUrl($method) {
1044
+ static $READ_ONLY_CALLS =
1045
+ array('admin.getallocation' => 1,
1046
+ 'admin.getappproperties' => 1,
1047
+ 'admin.getbannedusers' => 1,
1048
+ 'admin.getlivestreamvialink' => 1,
1049
+ 'admin.getmetrics' => 1,
1050
+ 'admin.getrestrictioninfo' => 1,
1051
+ 'application.getpublicinfo' => 1,
1052
+ 'auth.getapppublickey' => 1,
1053
+ 'auth.getsession' => 1,
1054
+ 'auth.getsignedpublicsessiondata' => 1,
1055
+ 'comments.get' => 1,
1056
+ 'connect.getunconnectedfriendscount' => 1,
1057
+ 'dashboard.getactivity' => 1,
1058
+ 'dashboard.getcount' => 1,
1059
+ 'dashboard.getglobalnews' => 1,
1060
+ 'dashboard.getnews' => 1,
1061
+ 'dashboard.multigetcount' => 1,
1062
+ 'dashboard.multigetnews' => 1,
1063
+ 'data.getcookies' => 1,
1064
+ 'events.get' => 1,
1065
+ 'events.getmembers' => 1,
1066
+ 'fbml.getcustomtags' => 1,
1067
+ 'feed.getappfriendstories' => 1,
1068
+ 'feed.getregisteredtemplatebundlebyid' => 1,
1069
+ 'feed.getregisteredtemplatebundles' => 1,
1070
+ 'fql.multiquery' => 1,
1071
+ 'fql.query' => 1,
1072
+ 'friends.arefriends' => 1,
1073
+ 'friends.get' => 1,
1074
+ 'friends.getappusers' => 1,
1075
+ 'friends.getlists' => 1,
1076
+ 'friends.getmutualfriends' => 1,
1077
+ 'gifts.get' => 1,
1078
+ 'groups.get' => 1,
1079
+ 'groups.getmembers' => 1,
1080
+ 'intl.gettranslations' => 1,
1081
+ 'links.get' => 1,
1082
+ 'notes.get' => 1,
1083
+ 'notifications.get' => 1,
1084
+ 'pages.getinfo' => 1,
1085
+ 'pages.isadmin' => 1,
1086
+ 'pages.isappadded' => 1,
1087
+ 'pages.isfan' => 1,
1088
+ 'permissions.checkavailableapiaccess' => 1,
1089
+ 'permissions.checkgrantedapiaccess' => 1,
1090
+ 'photos.get' => 1,
1091
+ 'photos.getalbums' => 1,
1092
+ 'photos.gettags' => 1,
1093
+ 'profile.getinfo' => 1,
1094
+ 'profile.getinfooptions' => 1,
1095
+ 'stream.get' => 1,
1096
+ 'stream.getcomments' => 1,
1097
+ 'stream.getfilters' => 1,
1098
+ 'users.getinfo' => 1,
1099
+ 'users.getloggedinuser' => 1,
1100
+ 'users.getstandardinfo' => 1,
1101
+ 'users.hasapppermission' => 1,
1102
+ 'users.isappuser' => 1,
1103
+ 'users.isverified' => 1,
1104
+ 'video.getuploadlimits' => 1);
1105
+ $name = 'api';
1106
+ if (isset($READ_ONLY_CALLS[strtolower($method)])) {
1107
+ $name = 'api_read';
1108
+ } else if (strtolower($method) == 'video.upload') {
1109
+ $name = 'api_video';
1110
+ }
1111
+ return self::getUrl($name, 'restserver.php');
1112
+ }
1113
+
1114
+ /**
1115
+ * Build the URL for given domain alias, path and parameters.
1116
+ *
1117
+ * @param $name string The name of the domain
1118
+ * @param $path string Optional path (without a leading slash)
1119
+ * @param $params array Optional query parameters
1120
+ *
1121
+ * @return string The URL for the given parameters
1122
+ */
1123
+ protected function getUrl($name, $path='', $params=array()) {
1124
+ $url = self::$DOMAIN_MAP[$name];
1125
+ if ($path) {
1126
+ if ($path[0] === '/') {
1127
+ $path = substr($path, 1);
1128
+ }
1129
+ $url .= $path;
1130
+ }
1131
+ if ($params) {
1132
+ $url .= '?' . http_build_query($params, null, '&');
1133
+ }
1134
+
1135
+ return $url;
1136
+ }
1137
+
1138
+ protected function getHttpHost() {
1139
+ if ($this->trustForwarded && isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
1140
+ return $_SERVER['HTTP_X_FORWARDED_HOST'];
1141
+ }
1142
+ return $_SERVER['HTTP_HOST'];
1143
+ }
1144
+
1145
+ protected function getHttpProtocol() {
1146
+ if ($this->trustForwarded && isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
1147
+ if ($_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
1148
+ return 'https';
1149
+ }
1150
+ return 'http';
1151
+ }
1152
+ if (isset($_SERVER['HTTPS']) &&
1153
+ ($_SERVER['HTTPS'] === 'on' || $_SERVER['HTTPS'] == 1)) {
1154
+ return 'https';
1155
+ }
1156
+ return 'http';
1157
+ }
1158
+
1159
+ /**
1160
+ * Get the base domain used for the cookie.
1161
+ */
1162
+ protected function getBaseDomain() {
1163
+ // The base domain is stored in the metadata cookie if not we fallback
1164
+ // to the current hostname
1165
+ $metadata = $this->getMetadataCookie();
1166
+ if (array_key_exists('base_domain', $metadata) &&
1167
+ !empty($metadata['base_domain'])) {
1168
+ return trim($metadata['base_domain'], '.');
1169
+ }
1170
+ return $this->getHttpHost();
1171
+ }
1172
+
1173
+ /**
1174
+
1175
+ /**
1176
+ * Returns the Current URL, stripping it of known FB parameters that should
1177
+ * not persist.
1178
+ *
1179
+ * @return string The current URL
1180
+ */
1181
+ protected function getCurrentUrl() {
1182
+ $protocol = $this->getHttpProtocol() . '://';
1183
+ $host = $this->getHttpHost();
1184
+ $currentUrl = $protocol.$host.$_SERVER['REQUEST_URI'];
1185
+ $parts = parse_url($currentUrl);
1186
+
1187
+ $query = '';
1188
+ if (!empty($parts['query'])) {
1189
+ // drop known fb params
1190
+ $params = explode('&', $parts['query']);
1191
+ $retained_params = array();
1192
+ foreach ($params as $param) {
1193
+ if ($this->shouldRetainParam($param)) {
1194
+ $retained_params[] = $param;
1195
+ }
1196
+ }
1197
+
1198
+ if (!empty($retained_params)) {
1199
+ $query = '?'.implode($retained_params, '&');
1200
+ }
1201
+ }
1202
+
1203
+ // use port if non default
1204
+ $port =
1205
+ isset($parts['port']) &&
1206
+ (($protocol === 'http://' && $parts['port'] !== 80) ||
1207
+ ($protocol === 'https://' && $parts['port'] !== 443))
1208
+ ? ':' . $parts['port'] : '';
1209
+
1210
+ // rebuild
1211
+ return $protocol . $parts['host'] . $port . $parts['path'] . $query;
1212
+ }
1213
+
1214
+ /**
1215
+ * Returns true if and only if the key or key/value pair should
1216
+ * be retained as part of the query string. This amounts to
1217
+ * a brute-force search of the very small list of Facebook-specific
1218
+ * params that should be stripped out.
1219
+ *
1220
+ * @param string $param A key or key/value pair within a URL's query (e.g.
1221
+ * 'foo=a', 'foo=', or 'foo'.
1222
+ *
1223
+ * @return boolean
1224
+ */
1225
+ protected function shouldRetainParam($param) {
1226
+ foreach (self::$DROP_QUERY_PARAMS as $drop_query_param) {
1227
+ if (strpos($param, $drop_query_param.'=') === 0) {
1228
+ return false;
1229
+ }
1230
+ }
1231
+
1232
+ return true;
1233
+ }
1234
+
1235
+ /**
1236
+ * Analyzes the supplied result to see if it was thrown
1237
+ * because the access token is no longer valid. If that is
1238
+ * the case, then we destroy the session.
1239
+ *
1240
+ * @param $result array A record storing the error message returned
1241
+ * by a failed API call.
1242
+ */
1243
+ protected function throwAPIException($result) { //prr($result);
1244
+ $e = new NXS_FacebookApiException($result);
1245
+ switch ($e->getType()) {
1246
+ // OAuth 2.0 Draft 00 style
1247
+ case 'OAuthException':
1248
+ // OAuth 2.0 Draft 10 style
1249
+ case 'invalid_token':
1250
+ // REST server errors are just Exceptions
1251
+ case 'Exception':
1252
+ $message = $e->getMessage();
1253
+ if ((strpos($message, 'Error validating access token') !== false) ||
1254
+ (strpos($message, 'Invalid OAuth access token') !== false) ||
1255
+ (strpos($message, 'An active access token must be used') !== false)
1256
+ ) {
1257
+ $this->destroySession();
1258
+ }
1259
+ break;
1260
+ }
1261
+
1262
+ throw $e;
1263
+ }
1264
+
1265
+
1266
+ /**
1267
+ * Prints to the error log if you aren't in command line mode.
1268
+ *
1269
+ * @param string $msg Log message
1270
+ */
1271
+ protected static function errorLog($msg) {
1272
+ // disable error log if we are running in a CLI environment
1273
+ // @codeCoverageIgnoreStart
1274
+ if (php_sapi_name() != 'cli') {
1275
+ error_log($msg);
1276
+ }
1277
+ // uncomment this if you want to see the errors on the page
1278
+ // print 'error_log: '.$msg."\n";
1279
+ // @codeCoverageIgnoreEnd
1280
+ }
1281
+
1282
+ /**
1283
+ * Base64 encoding that doesn't need to be urlencode()ed.
1284
+ * Exactly the same as base64_encode except it uses
1285
+ * - instead of +
1286
+ * _ instead of /
1287
+ * No padded =
1288
+ *
1289
+ * @param string $input base64UrlEncoded string
1290
+ * @return string
1291
+ */
1292
+ protected static function base64UrlDecode($input) {
1293
+ return base64_decode(strtr($input, '-_', '+/'));
1294
+ }
1295
+
1296
+ /**
1297
+ * Base64 encoding that doesn't need to be urlencode()ed.
1298
+ * Exactly the same as base64_encode except it uses
1299
+ * - instead of +
1300
+ * _ instead of /
1301
+ *
1302
+ * @param string $input string
1303
+ * @return string base64Url encoded string
1304
+ */
1305
+ protected static function base64UrlEncode($input) {
1306
+ $str = strtr(base64_encode($input), '+/', '-_');
1307
+ $str = str_replace('=', '', $str);
1308
+ return $str;
1309
+ }
1310
+
1311
+ /**
1312
+ * Destroy the current session
1313
+ */
1314
+ public function destroySession() {
1315
+ $this->accessToken = null;
1316
+ $this->signedRequest = null;
1317
+ $this->user = null;
1318
+ $this->clearAllPersistentData();
1319
+
1320
+ // Javascript sets a cookie that will be used in getSignedRequest that we
1321
+ // need to clear if we can
1322
+ $cookie_name = $this->getSignedRequestCookieName();
1323
+ if (array_key_exists($cookie_name, $_COOKIE)) {
1324
+ unset($_COOKIE[$cookie_name]);
1325
+ if (!headers_sent()) {
1326
+ $base_domain = $this->getBaseDomain();
1327
+ setcookie($cookie_name, '', 1, '/', '.'.$base_domain);
1328
+ } else {
1329
+ // @codeCoverageIgnoreStart
1330
+ self::errorLog(
1331
+ 'There exists a cookie that we wanted to clear that we couldn\'t '.
1332
+ 'clear because headers was already sent. Make sure to do the first '.
1333
+ 'API call before outputing anything.'
1334
+ );
1335
+ // @codeCoverageIgnoreEnd
1336
+ }
1337
+ }
1338
+ }
1339
+
1340
+ /**
1341
+ * Parses the metadata cookie that our Javascript API set
1342
+ *
1343
+ * @return an array mapping key to value
1344
+ */
1345
+ protected function getMetadataCookie() {
1346
+ $cookie_name = $this->getMetadataCookieName();
1347
+ if (!array_key_exists($cookie_name, $_COOKIE)) {
1348
+ return array();
1349
+ }
1350
+
1351
+ // The cookie value can be wrapped in "-characters so remove them
1352
+ $cookie_value = trim($_COOKIE[$cookie_name], '"');
1353
+
1354
+ if (empty($cookie_value)) {
1355
+ return array();
1356
+ }
1357
+
1358
+ $parts = explode('&', $cookie_value);
1359
+ $metadata = array();
1360
+ foreach ($parts as $part) {
1361
+ $pair = explode('=', $part, 2);
1362
+ if (!empty($pair[0])) {
1363
+ $metadata[urldecode($pair[0])] =
1364
+ (count($pair) > 1) ? urldecode($pair[1]) : '';
1365
+ }
1366
+ }
1367
+
1368
+ return $metadata;
1369
+ }
1370
+
1371
+ protected static function isAllowedDomain($big, $small) {
1372
+ if ($big === $small) {
1373
+ return true;
1374
+ }
1375
+ return self::endsWith($big, '.'.$small);
1376
+ }
1377
+
1378
+ protected static function endsWith($big, $small) {
1379
+ $len = strlen($small);
1380
+ if ($len === 0) {
1381
+ return true;
1382
+ }
1383
+ return substr($big, -$len) === $small;
1384
+ }
1385
+
1386
+ /**
1387
+ * Each of the following four methods should be overridden in
1388
+ * a concrete subclass, as they are in the provided Facebook class.
1389
+ * The Facebook class uses PHP sessions to provide a primitive
1390
+ * persistent store, but another subclass--one that you implement--
1391
+ * might use a database, memcache, or an in-memory cache.
1392
+ *
1393
+ * @see Facebook
1394
+ */
1395
+
1396
+ /**
1397
+ * Stores the given ($key, $value) pair, so that future calls to
1398
+ * getPersistentData($key) return $value. This call may be in another request.
1399
+ *
1400
+ * @param string $key
1401
+ * @param array $value
1402
+ *
1403
+ * @return void
1404
+ */
1405
+ abstract protected function setPersistentData($key, $value);
1406
+
1407
+ /**
1408
+ * Get the data for $key, persisted by BaseFacebook::setPersistentData()
1409
+ *
1410
+ * @param string $key The key of the data to retrieve
1411
+ * @param boolean $default The default value to return if $key is not found
1412
+ *
1413
+ * @return mixed
1414
+ */
1415
+ abstract protected function getPersistentData($key, $default = false);
1416
+
1417
+ /**
1418
+ * Clear the data with $key from the persistent storage
1419
+ *
1420
+ * @param string $key
1421
+ * @return void
1422
+ */
1423
+ abstract protected function clearPersistentData($key);
1424
+
1425
+ /**
1426
+ * Clear all data from the persistent storage
1427
+ *
1428
+ * @return void
1429
+ */
1430
+ abstract protected function clearAllPersistentData();
1431
+ }
inc-cl/apis/facebook.php CHANGED
@@ -1,160 +1,160 @@
1
- <?php
2
- /**
3
- * Copyright 2011 Facebook, Inc.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
6
- * not use this file except in compliance with the License. You may obtain
7
- * a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
- * License for the specific language governing permissions and limitations
15
- * under the License.
16
- */
17
-
18
- require_once "base_facebook.php";
19
-
20
- /**
21
- * Extends the BaseFacebook class with the intent of using
22
- * PHP sessions to store user ids and access tokens.
23
- */
24
- class NXS_Facebook extends NXS_BaseFacebook
25
- {
26
- const FBSS_COOKIE_NAME = 'fbss';
27
-
28
- // We can set this to a high number because the main session
29
- // expiration will trump this.
30
- const FBSS_COOKIE_EXPIRE = 31556926; // 1 year
31
-
32
- // Stores the shared session ID if one is set.
33
- protected $sharedSessionID;
34
-
35
- /**
36
- * Identical to the parent constructor, except that
37
- * we start a PHP session to store the user ID and
38
- * access token if during the course of execution
39
- * we discover them.
40
- *
41
- * @param Array $config the application configuration. Additionally
42
- * accepts "sharedSession" as a boolean to turn on a secondary
43
- * cookie for environments with a shared session (that is, your app
44
- * shares the domain with other apps).
45
- * @see BaseFacebook::__construct in facebook.php
46
- */
47
- public function __construct($config) {
48
- if (!session_id() && !headers_sent() ) {
49
- session_start();
50
- }
51
- parent::__construct($config);
52
- if (!empty($config['sharedSession'])) {
53
- $this->initSharedSession();
54
- }
55
- }
56
-
57
- protected static $kSupportedKeys =
58
- array('state', 'code', 'access_token', 'user_id');
59
-
60
- protected function initSharedSession() {
61
- $cookie_name = $this->getSharedSessionCookieName();
62
- if (isset($_COOKIE[$cookie_name])) {
63
- $data = $this->parseSignedRequest($_COOKIE[$cookie_name]);
64
- if ($data && !empty($data['domain']) &&
65
- self::isAllowedDomain($this->getHttpHost(), $data['domain'])) {
66
- // good case
67
- $this->sharedSessionID = $data['id'];
68
- return;
69
- }
70
- // ignoring potentially unreachable data
71
- }
72
- // evil/corrupt/missing case
73
- $base_domain = $this->getBaseDomain();
74
- $this->sharedSessionID = md5(uniqid(mt_rand(), true));
75
- $cookie_value = $this->makeSignedRequest(
76
- array(
77
- 'domain' => $base_domain,
78
- 'id' => $this->sharedSessionID,
79
- )
80
- );
81
- $_COOKIE[$cookie_name] = $cookie_value;
82
- if (!headers_sent()) {
83
- $expire = time() + self::FBSS_COOKIE_EXPIRE;
84
- setcookie($cookie_name, $cookie_value, $expire, '/', '.'.$base_domain);
85
- } else {
86
- // @codeCoverageIgnoreStart
87
- self::errorLog(
88
- 'Shared session ID cookie could not be set! You must ensure you '.
89
- 'create the Facebook instance before headers have been sent. This '.
90
- 'will cause authentication issues after the first request.'
91
- );
92
- // @codeCoverageIgnoreEnd
93
- }
94
- }
95
-
96
- /**
97
- * Provides the implementations of the inherited abstract
98
- * methods. The implementation uses PHP sessions to maintain
99
- * a store for authorization codes, user ids, CSRF states, and
100
- * access tokens.
101
- */
102
- protected function setPersistentData($key, $value) {
103
- if (!in_array($key, self::$kSupportedKeys)) {
104
- self::errorLog('Unsupported key passed to setPersistentData.');
105
- return;
106
- }
107
-
108
- $session_var_name = $this->constructSessionVariableName($key);
109
- $_SESSION[$session_var_name] = $value;
110
- }
111
-
112
- protected function getPersistentData($key, $default = false) {
113
- if (!in_array($key, self::$kSupportedKeys)) {
114
- self::errorLog('Unsupported key passed to getPersistentData.');
115
- return $default;
116
- }
117
-
118
- $session_var_name = $this->constructSessionVariableName($key);
119
- return isset($_SESSION[$session_var_name]) ?
120
- $_SESSION[$session_var_name] : $default;
121
- }
122
-
123
- protected function clearPersistentData($key) {
124
- if (!in_array($key, self::$kSupportedKeys)) {
125
- self::errorLog('Unsupported key passed to clearPersistentData.');
126
- return;
127
- }
128
-
129
- $session_var_name = $this->constructSessionVariableName($key);
130
- unset($_SESSION[$session_var_name]);
131
- }
132
-
133
- protected function clearAllPersistentData() {
134
- foreach (self::$kSupportedKeys as $key) {
135
- $this->clearPersistentData($key);
136
- }
137
- if ($this->sharedSessionID) {
138
- $this->deleteSharedSessionCookie();
139
- }
140
- }
141
-
142
- protected function deleteSharedSessionCookie() {
143
- $cookie_name = $this->getSharedSessionCookieName();
144
- unset($_COOKIE[$cookie_name]);
145
- $base_domain = $this->getBaseDomain();
146
- setcookie($cookie_name, '', 1, '/', '.'.$base_domain);
147
- }
148
-
149
- protected function getSharedSessionCookieName() {
150
- return self::FBSS_COOKIE_NAME . '_' . $this->getAppId();
151
- }
152
-
153
- protected function constructSessionVariableName($key) {
154
- $parts = array('fb', $this->getAppId(), $key);
155
- if ($this->sharedSessionID) {
156
- array_unshift($parts, $this->sharedSessionID);
157
- }
158
- return implode('_', $parts);
159
- }
160
- }
1
+ <?php
2
+ /**
3
+ * Copyright 2011 Facebook, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
6
+ * not use this file except in compliance with the License. You may obtain
7
+ * a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ * License for the specific language governing permissions and limitations
15
+ * under the License.
16
+ */
17
+
18
+ require_once "base_facebook.php";
19
+
20
+ /**
21
+ * Extends the BaseFacebook class with the intent of using
22
+ * PHP sessions to store user ids and access tokens.
23
+ */
24
+ class NXS_Facebook extends NXS_BaseFacebook
25
+ {
26
+ const FBSS_COOKIE_NAME = 'fbss';
27
+
28
+ // We can set this to a high number because the main session
29
+ // expiration will trump this.
30
+ const FBSS_COOKIE_EXPIRE = 31556926; // 1 year
31
+
32
+ // Stores the shared session ID if one is set.
33
+ protected $sharedSessionID;
34
+
35
+ /**
36
+ * Identical to the parent constructor, except that
37
+ * we start a PHP session to store the user ID and
38
+ * access token if during the course of execution
39
+ * we discover them.
40
+ *
41
+ * @param Array $config the application configuration. Additionally
42
+ * accepts "sharedSession" as a boolean to turn on a secondary
43
+ * cookie for environments with a shared session (that is, your app
44
+ * shares the domain with other apps).
45
+ * @see BaseFacebook::__construct in facebook.php
46
+ */
47
+ public function __construct($config) {
48
+ if (!session_id() && !headers_sent() ) {
49
+ session_start();
50
+ }
51
+ parent::__construct($config);
52
+ if (!empty($config['sharedSession'])) {
53
+ $this->initSharedSession();
54
+ }
55
+ }
56
+
57
+ protected static $kSupportedKeys =
58
+ array('state', 'code', 'access_token', 'user_id');
59
+
60
+ protected function initSharedSession() {
61
+ $cookie_name = $this->getSharedSessionCookieName();
62
+ if (isset($_COOKIE[$cookie_name])) {
63
+ $data = $this->parseSignedRequest($_COOKIE[$cookie_name]);
64
+ if ($data && !empty($data['domain']) &&
65
+ self::isAllowedDomain($this->getHttpHost(), $data['domain'])) {
66
+ // good case
67
+ $this->sharedSessionID = $data['id'];
68
+ return;
69
+ }
70
+ // ignoring potentially unreachable data
71
+ }
72
+ // evil/corrupt/missing case
73
+ $base_domain = $this->getBaseDomain();
74
+ $this->sharedSessionID = md5(uniqid(mt_rand(), true));
75
+ $cookie_value = $this->makeSignedRequest(
76
+ array(
77
+ 'domain' => $base_domain,
78
+ 'id' => $this->sharedSessionID,
79
+ )
80
+ );
81
+ $_COOKIE[$cookie_name] = $cookie_value;
82
+ if (!headers_sent()) {
83
+ $expire = time() + self::FBSS_COOKIE_EXPIRE;
84
+ setcookie($cookie_name, $cookie_value, $expire, '/', '.'.$base_domain);
85
+ } else {
86
+ // @codeCoverageIgnoreStart
87
+ self::errorLog(
88
+ 'Shared session ID cookie could not be set! You must ensure you '.
89
+ 'create the Facebook instance before headers have been sent. This '.
90
+ 'will cause authentication issues after the first request.'
91
+ );
92
+ // @codeCoverageIgnoreEnd
93
+ }
94
+ }
95
+
96
+ /**
97
+ * Provides the implementations of the inherited abstract
98
+ * methods. The implementation uses PHP sessions to maintain
99
+ * a store for authorization codes, user ids, CSRF states, and
100
+ * access tokens.
101
+ */
102
+ protected function setPersistentData($key, $value) {
103
+ if (!in_array($key, self::$kSupportedKeys)) {
104
+ self::errorLog('Unsupported key passed to setPersistentData.');
105
+ return;
106
+ }
107
+
108
+ $session_var_name = $this->constructSessionVariableName($key);
109
+ $_SESSION[$session_var_name] = $value;
110
+ }
111
+
112
+ protected function getPersistentData($key, $default = false) {
113
+ if (!in_array($key, self::$kSupportedKeys)) {
114
+ self::errorLog('Unsupported key passed to getPersistentData.');
115
+ return $default;
116
+ }
117
+
118
+ $session_var_name = $this->constructSessionVariableName($key);
119
+ return isset($_SESSION[$session_var_name]) ?
120
+ $_SESSION[$session_var_name] : $default;
121
+ }
122
+
123
+ protected function clearPersistentData($key) {
124
+ if (!in_array($key, self::$kSupportedKeys)) {
125
+ self::errorLog('Unsupported key passed to clearPersistentData.');
126
+ return;
127
+ }
128
+
129
+ $session_var_name = $this->constructSessionVariableName($key);
130
+ unset($_SESSION[$session_var_name]);
131
+ }
132
+
133
+ protected function clearAllPersistentData() {
134
+ foreach (self::$kSupportedKeys as $key) {
135
+ $this->clearPersistentData($key);
136
+ }
137
+ if ($this->sharedSessionID) {
138
+ $this->deleteSharedSessionCookie();
139
+ }
140
+ }
141
+
142
+ protected function deleteSharedSessionCookie() {
143
+ $cookie_name = $this->getSharedSessionCookieName();
144
+ unset($_COOKIE[$cookie_name]);
145
+ $base_domain = $this->getBaseDomain();
146
+ setcookie($cookie_name, '', 1, '/', '.'.$base_domain);
147
+ }
148
+
149
+ protected function getSharedSessionCookieName() {
150
+ return self::FBSS_COOKIE_NAME . '_' . $this->getAppId();
151
+ }
152
+
153
+ protected function constructSessionVariableName($key) {
154
+ $parts = array('fb', $this->getAppId(), $key);
155
+ if ($this->sharedSessionID) {
156
+ array_unshift($parts, $this->sharedSessionID);
157
+ }
158
+ return implode('_', $parts);
159
+ }
160
+ }
inc-cl/apis/htmlNumTable.php CHANGED
@@ -1,260 +1,260 @@
1
- <?php
2
-
3
- $HTML401NamedToNumeric = array(
4
- '&apos;' => '&#39;',
5
- '&nbsp;' => '&#160;', # no-break space = non-breaking space, U+00A0 ISOnum
6
- '&iexcl;' => '&#161;', # inverted exclamation mark, U+00A1 ISOnum
7
- '&cent;' => '&#162;', # cent sign, U+00A2 ISOnum
8
- '&pound;' => '&#163;', # pound sign, U+00A3 ISOnum
9
- '&curren;' => '&#164;', # currency sign, U+00A4 ISOnum
10
- '&yen;' => '&#165;', # yen sign = yuan sign, U+00A5 ISOnum
11
- '&brvbar;' => '&#166;', # broken bar = broken vertical bar, U+00A6 ISOnum
12
- '&sect;' => '&#167;', # section sign, U+00A7 ISOnum
13
- '&uml;' => '&#168;', # diaeresis = spacing diaeresis, U+00A8 ISOdia
14
- '&copy;' => '&#169;', # copyright sign, U+00A9 ISOnum
15
- '&ordf;' => '&#170;', # feminine ordinal indicator, U+00AA ISOnum
16
- '&laquo;' => '&#171;', # left-pointing double angle quotation mark = left pointing guillemet, U+00AB ISOnum
17
- '&not;' => '&#172;', # not sign, U+00AC ISOnum
18
- '&shy;' => '&#173;', # soft hyphen = discretionary hyphen, U+00AD ISOnum
19
- '&reg;' => '&#174;', # registered sign = registered trade mark sign, U+00AE ISOnum
20
- '&macr;' => '&#175;', # macron = spacing macron = overline = APL overbar, U+00AF ISOdia
21
- '&deg;' => '&#176;', # degree sign, U+00B0 ISOnum
22
- '&plusmn;' => '&#177;', # plus-minus sign = plus-or-minus sign, U+00B1 ISOnum
23
- '&sup2;' => '&#178;', # superscript two = superscript digit two = squared, U+00B2 ISOnum
24
- '&sup3;' => '&#179;', # superscript three = superscript digit three = cubed, U+00B3 ISOnum
25
- '&acute;' => '&#180;', # acute accent = spacing acute, U+00B4 ISOdia
26
- '&micro;' => '&#181;', # micro sign, U+00B5 ISOnum
27
- '&para;' => '&#182;', # pilcrow sign = paragraph sign, U+00B6 ISOnum
28
- '&middot;' => '&#183;', # middle dot = Georgian comma = Greek middle dot, U+00B7 ISOnum
29
- '&cedil;' => '&#184;', # cedilla = spacing cedilla, U+00B8 ISOdia
30
- '&sup1;' => '&#185;', # superscript one = superscript digit one, U+00B9 ISOnum
31
- '&ordm;' => '&#186;', # masculine ordinal indicator, U+00BA ISOnum
32
- '&raquo;' => '&#187;', # right-pointing double angle quotation mark = right pointing guillemet, U+00BB ISOnum
33
- '&frac14;' => '&#188;', # vulgar fraction one quarter = fraction one quarter, U+00BC ISOnum
34
- '&frac12;' => '&#189;', # vulgar fraction one half = fraction one half, U+00BD ISOnum
35
- '&frac34;' => '&#190;', # vulgar fraction three quarters = fraction three quarters, U+00BE ISOnum
36
- '&iquest;' => '&#191;', # inverted question mark = turned question mark, U+00BF ISOnum
37
- '&Agrave;' => '&#192;', # latin capital letter A with grave = latin capital letter A grave, U+00C0 ISOlat1
38
- '&Aacute;' => '&#193;', # latin capital letter A with acute, U+00C1 ISOlat1
39
- '&Acirc;' => '&#194;', # latin capital letter A with circumflex, U+00C2 ISOlat1
40
- '&Atilde;' => '&#195;', # latin capital letter A with tilde, U+00C3 ISOlat1
41
- '&Auml;' => '&#196;', # latin capital letter A with diaeresis, U+00C4 ISOlat1
42
- '&Aring;' => '&#197;', # latin capital letter A with ring above = latin capital letter A ring, U+00C5 ISOlat1
43
- '&AElig;' => '&#198;', # latin capital letter AE = latin capital ligature AE, U+00C6 ISOlat1
44
- '&Ccedil;' => '&#199;', # latin capital letter C with cedilla, U+00C7 ISOlat1
45
- '&Egrave;' => '&#200;', # latin capital letter E with grave, U+00C8 ISOlat1
46
- '&Eacute;' => '&#201;', # latin capital letter E with acute, U+00C9 ISOlat1
47
- '&Ecirc;' => '&#202;', # latin capital letter E with circumflex, U+00CA ISOlat1
48
- '&Euml;' => '&#203;', # latin capital letter E with diaeresis, U+00CB ISOlat1
49
- '&Igrave;' => '&#204;', # latin capital letter I with grave, U+00CC ISOlat1
50
- '&Iacute;' => '&#205;', # latin capital letter I with acute, U+00CD ISOlat1
51
- '&Icirc;' => '&#206;', # latin capital letter I with circumflex, U+00CE ISOlat1
52
- '&Iuml;' => '&#207;', # latin capital letter I with diaeresis, U+00CF ISOlat1
53
- '&ETH;' => '&#208;', # latin capital letter ETH, U+00D0 ISOlat1
54
- '&Ntilde;' => '&#209;', # latin capital letter N with tilde, U+00D1 ISOlat1
55
- '&Ograve;' => '&#210;', # latin capital letter O with grave, U+00D2 ISOlat1
56
- '&Oacute;' => '&#211;', # latin capital letter O with acute, U+00D3 ISOlat1
57
- '&Ocirc;' => '&#212;', # latin capital letter O with circumflex, U+00D4 ISOlat1
58
- '&Otilde;' => '&#213;', # latin capital letter O with tilde, U+00D5 ISOlat1
59
- '&Ouml;' => '&#214;', # latin capital letter O with diaeresis, U+00D6 ISOlat1
60
- '&times;' => '&#215;', # multiplication sign, U+00D7 ISOnum
61
- '&Oslash;' => '&#216;', # latin capital letter O with stroke = latin capital letter O slash, U+00D8 ISOlat1
62
- '&Ugrave;' => '&#217;', # latin capital letter U with grave, U+00D9 ISOlat1
63
- '&Uacute;' => '&#218;', # latin capital letter U with acute, U+00DA ISOlat1
64
- '&Ucirc;' => '&#219;', # latin capital letter U with circumflex, U+00DB ISOlat1
65
- '&Uuml;' => '&#220;', # latin capital letter U with diaeresis, U+00DC ISOlat1
66
- '&Yacute;' => '&#221;', # latin capital letter Y with acute, U+00DD ISOlat1
67
- '&THORN;' => '&#222;', # latin capital letter THORN, U+00DE ISOlat1
68
- '&szlig;' => '&#223;', # latin small letter sharp s = ess-zed, U+00DF ISOlat1
69
- '&agrave;' => '&#224;', # latin small letter a with grave = latin small letter a grave, U+00E0 ISOlat1
70
- '&aacute;' => '&#225;', # latin small letter a with acute, U+00E1 ISOlat1
71
- '&acirc;' => '&#226;', # latin small letter a with circumflex, U+00E2 ISOlat1
72
- '&atilde;' => '&#227;', # latin small letter a with tilde, U+00E3 ISOlat1
73
- '&auml;' => '&#228;', # latin small letter a with diaeresis, U+00E4 ISOlat1
74
- '&aring;' => '&#229;', # latin small letter a with ring above = latin small letter a ring, U+00E5 ISOlat1
75
- '&aelig;' => '&#230;', # latin small letter ae = latin small ligature ae, U+00E6 ISOlat1
76
- '&ccedil;' => '&#231;', # latin small letter c with cedilla, U+00E7 ISOlat1
77
- '&egrave;' => '&#232;', # latin small letter e with grave, U+00E8 ISOlat1
78
- '&eacute;' => '&#233;', # latin small letter e with acute, U+00E9 ISOlat1
79
- '&ecirc;' => '&#234;', # latin small letter e with circumflex, U+00EA ISOlat1
80
- '&euml;' => '&#235;', # latin small letter e with diaeresis, U+00EB ISOlat1
81
- '&igrave;' => '&#236;', # latin small letter i with grave, U+00EC ISOlat1
82
- '&iacute;' => '&#237;', # latin small letter i with acute, U+00ED ISOlat1
83
- '&icirc;' => '&#238;', # latin small letter i with circumflex, U+00EE ISOlat1
84
- '&iuml;' => '&#239;', # latin small letter i with diaeresis, U+00EF ISOlat1
85
- '&eth;' => '&#240;', # latin small letter eth, U+00F0 ISOlat1
86
- '&ntilde;' => '&#241;', # latin small letter n with tilde, U+00F1 ISOlat1
87
- '&ograve;' => '&#242;', # latin small letter o with grave, U+00F2 ISOlat1
88
- '&oacute;' => '&#243;', # latin small letter o with acute, U+00F3 ISOlat1
89
- '&ocirc;' => '&#244;', # latin small letter o with circumflex, U+00F4 ISOlat1
90
- '&otilde;' => '&#245;', # latin small letter o with tilde, U+00F5 ISOlat1
91
- '&ouml;' => '&#246;', # latin small letter o with diaeresis, U+00F6 ISOlat1
92
- '&divide;' => '&#247;', # division sign, U+00F7 ISOnum
93
- '&oslash;' => '&#248;', # latin small letter o with stroke, = latin small letter o slash, U+00F8 ISOlat1
94
- '&ugrave;' => '&#249;', # latin small letter u with grave, U+00F9 ISOlat1
95
- '&uacute;' => '&#250;', # latin small letter u with acute, U+00FA ISOlat1
96
- '&ucirc;' => '&#251;', # latin small letter u with circumflex, U+00FB ISOlat1
97
- '&uuml;' => '&#252;', # latin small letter u with diaeresis, U+00FC ISOlat1
98
- '&yacute;' => '&#253;', # latin small letter y with acute, U+00FD ISOlat1
99
- '&thorn;' => '&#254;', # latin small letter thorn, U+00FE ISOlat1
100
- '&yuml;' => '&#255;', # latin small letter y with diaeresis, U+00FF ISOlat1
101
- '&fnof;' => '&#402;', # latin small f with hook = function = florin, U+0192 ISOtech
102
- '&Alpha;' => '&#913;', # greek capital letter alpha, U+0391
103
- '&Beta;' => '&#914;', # greek capital letter beta, U+0392
104
- '&Gamma;' => '&#915;', # greek capital letter gamma, U+0393 ISOgrk3
105
- '&Delta;' => '&#916;', # greek capital letter delta, U+0394 ISOgrk3
106
- '&Epsilon;' => '&#917;', # greek capital letter epsilon, U+0395
107
- '&Zeta;' => '&#918;', # greek capital letter zeta, U+0396
108
- '&Eta;' => '&#919;', # greek capital letter eta, U+0397
109
- '&Theta;' => '&#920;', # greek capital letter theta, U+0398 ISOgrk3
110
- '&Iota;' => '&#921;', # greek capital letter iota, U+0399
111
- '&Kappa;' => '&#922;', # greek capital letter kappa, U+039A
112
- '&Lambda;' => '&#923;', # greek capital letter lambda, U+039B ISOgrk3
113
- '&Mu;' => '&#924;', # greek capital letter mu, U+039C
114
- '&Nu;' => '&#925;', # greek capital letter nu, U+039D
115
- '&Xi;' => '&#926;', # greek capital letter xi, U+039E ISOgrk3
116
- '&Omicron;' => '&#927;', # greek capital letter omicron, U+039F
117
- '&Pi;' => '&#928;', # greek capital letter pi, U+03A0 ISOgrk3
118
- '&Rho;' => '&#929;', # greek capital letter rho, U+03A1
119
- '&Sigma;' => '&#931;', # greek capital letter sigma, U+03A3 ISOgrk3
120
- '&Tau;' => '&#932;', # greek capital letter tau, U+03A4
121
- '&Upsilon;' => '&#933;', # greek capital letter upsilon, U+03A5 ISOgrk3
122
- '&Phi;' => '&#934;', # greek capital letter phi, U+03A6 ISOgrk3
123
- '&Chi;' => '&#935;', # greek capital letter chi, U+03A7
124
- '&Psi;' => '&#936;', # greek capital letter psi, U+03A8 ISOgrk3
125
- '&Omega;' => '&#937;', # greek capital letter omega, U+03A9 ISOgrk3
126
- '&alpha;' => '&#945;', # greek small letter alpha, U+03B1 ISOgrk3
127
- '&beta;' => '&#946;', # greek small letter beta, U+03B2 ISOgrk3
128
- '&gamma;' => '&#947;', # greek small letter gamma, U+03B3 ISOgrk3
129
- '&delta;' => '&#948;', # greek small letter delta, U+03B4 ISOgrk3
130
- '&epsilon;' => '&#949;', # greek small letter epsilon, U+03B5 ISOgrk3
131
- '&zeta;' => '&#950;', # greek small letter zeta, U+03B6 ISOgrk3
132
- '&eta;' => '&#951;', # greek small letter eta, U+03B7 ISOgrk3
133
- '&theta;' => '&#952;', # greek small letter theta, U+03B8 ISOgrk3
134
- '&iota;' => '&#953;', # greek small letter iota, U+03B9 ISOgrk3
135
- '&kappa;' => '&#954;', # greek small letter kappa, U+03BA ISOgrk3
136
- '&lambda;' => '&#955;', # greek small letter lambda, U+03BB ISOgrk3
137
- '&mu;' => '&#956;', # greek small letter mu, U+03BC ISOgrk3
138
- '&nu;' => '&#957;', # greek small letter nu, U+03BD ISOgrk3
139
- '&xi;' => '&#958;', # greek small letter xi, U+03BE ISOgrk3
140
- '&omicron;' => '&#959;', # greek small letter omicron, U+03BF NEW
141
- '&pi;' => '&#960;', # greek small letter pi, U+03C0 ISOgrk3
142
- '&rho;' => '&#961;', # greek small letter rho, U+03C1 ISOgrk3
143
- '&sigmaf;' => '&#962;', # greek small letter final sigma, U+03C2 ISOgrk3
144
- '&sigma;' => '&#963;', # greek small letter sigma, U+03C3 ISOgrk3
145
- '&tau;' => '&#964;', # greek small letter tau, U+03C4 ISOgrk3
146
- '&upsilon;' => '&#965;', # greek small letter upsilon, U+03C5 ISOgrk3
147
- '&phi;' => '&#966;', # greek small letter phi, U+03C6 ISOgrk3
148
- '&chi;' => '&#967;', # greek small letter chi, U+03C7 ISOgrk3
149
- '&psi;' => '&#968;', # greek small letter psi, U+03C8 ISOgrk3
150
- '&omega;' => '&#969;', # greek small letter omega, U+03C9 ISOgrk3
151
- '&thetasym;' => '&#977;', # greek small letter theta symbol, U+03D1 NEW
152
- '&upsih;' => '&#978;', # greek upsilon with hook symbol, U+03D2 NEW
153
- '&piv;' => '&#982;', # greek pi symbol, U+03D6 ISOgrk3
154
- '&bull;' => '&#8226;', # bullet = black small circle, U+2022 ISOpub
155
- '&hellip;' => '&#8230;', # horizontal ellipsis = three dot leader, U+2026 ISOpub
156
- '&prime;' => '&#8242;', # prime = minutes = feet, U+2032 ISOtech
157
- '&Prime;' => '&#8243;', # double prime = seconds = inches, U+2033 ISOtech
158
- '&oline;' => '&#8254;', # overline = spacing overscore, U+203E NEW
159
- '&frasl;' => '&#8260;', # fraction slash, U+2044 NEW
160
- '&weierp;' => '&#8472;', # script capital P = power set = Weierstrass p, U+2118 ISOamso
161
- '&image;' => '&#8465;', # blackletter capital I = imaginary part, U+2111 ISOamso
162
- '&real;' => '&#8476;', # blackletter capital R = real part symbol, U+211C ISOamso
163
- '&trade;' => '&#8482;', # trade mark sign, U+2122 ISOnum
164
- '&alefsym;' => '&#8501;', # alef symbol = first transfinite cardinal, U+2135 NEW
165
- '&larr;' => '&#8592;', # leftwards arrow, U+2190 ISOnum
166
- '&uarr;' => '&#8593;', # upwards arrow, U+2191 ISOnum
167
- '&rarr;' => '&#8594;', # rightwards arrow, U+2192 ISOnum
168
- '&darr;' => '&#8595;', # downwards arrow, U+2193 ISOnum
169
- '&harr;' => '&#8596;', # left right arrow, U+2194 ISOamsa
170
- '&crarr;' => '&#8629;', # downwards arrow with corner leftwards = carriage return, U+21B5 NEW
171
- '&lArr;' => '&#8656;', # leftwards double arrow, U+21D0 ISOtech
172
- '&uArr;' => '&#8657;', # upwards double arrow, U+21D1 ISOamsa
173
- '&rArr;' => '&#8658;', # rightwards double arrow, U+21D2 ISOtech
174
- '&dArr;' => '&#8659;', # downwards double arrow, U+21D3 ISOamsa
175
- '&hArr;' => '&#8660;', # left right double arrow, U+21D4 ISOamsa
176
- '&forall;' => '&#8704;', # for all, U+2200 ISOtech
177
- '&part;' => '&#8706;', # partial differential, U+2202 ISOtech
178
- '&exist;' => '&#8707;', # there exists, U+2203 ISOtech
179
- '&empty;' => '&#8709;', # empty set = null set = diameter, U+2205 ISOamso
180
- '&nabla;' => '&#8711;', # nabla = backward difference, U+2207 ISOtech
181
- '&isin;' => '&#8712;', # element of, U+2208 ISOtech
182
- '&notin;' => '&#8713;', # not an element of, U+2209 ISOtech
183
- '&ni;' => '&#8715;', # contains as member, U+220B ISOtech
184
- '&prod;' => '&#8719;', # n-ary product = product sign, U+220F ISOamsb
185
- '&sum;' => '&#8721;', # n-ary sumation, U+2211 ISOamsb
186
- '&minus;' => '&#8722;', # minus sign, U+2212 ISOtech
187
- '&lowast;' => '&#8727;', # asterisk operator, U+2217 ISOtech
188
- '&radic;' => '&#8730;', # square root = radical sign, U+221A ISOtech
189
- '&prop;' => '&#8733;', # proportional to, U+221D ISOtech
190
- '&infin;' => '&#8734;', # infinity, U+221E ISOtech
191
- '&ang;' => '&#8736;', # angle, U+2220 ISOamso
192
- '&and;' => '&#8743;', # logical and = wedge, U+2227 ISOtech
193
- '&or;' => '&#8744;', # logical or = vee, U+2228 ISOtech
194
- '&cap;' => '&#8745;', # intersection = cap, U+2229 ISOtech
195
- '&cup;' => '&#8746;', # union = cup, U+222A ISOtech
196
- '&int;' => '&#8747;', # integral, U+222B ISOtech
197
- '&there4;' => '&#8756;', # therefore, U+2234 ISOtech
198
- '&sim;' => '&#8764;', # tilde operator = varies with = similar to, U+223C ISOtech
199
- '&cong;' => '&#8773;', # approximately equal to, U+2245 ISOtech
200
- '&asymp;' => '&#8776;', # almost equal to = asymptotic to, U+2248 ISOamsr
201
- '&ne;' => '&#8800;', # not equal to, U+2260 ISOtech
202
- '&equiv;' => '&#8801;', # identical to, U+2261 ISOtech
203
- '&le;' => '&#8804;', # less-than or equal to, U+2264 ISOtech
204
- '&ge;' => '&#8805;', # greater-than or equal to, U+2265 ISOtech
205
- '&sub;' => '&#8834;', # subset of, U+2282 ISOtech
206
- '&sup;' => '&#8835;', # superset of, U+2283 ISOtech
207
- '&nsub;' => '&#8836;', # not a subset of, U+2284 ISOamsn
208
- '&sube;' => '&#8838;', # subset of or equal to, U+2286 ISOtech
209
- '&supe;' => '&#8839;', # superset of or equal to, U+2287 ISOtech
210
- '&oplus;' => '&#8853;', # circled plus = direct sum, U+2295 ISOamsb
211
- '&otimes;' => '&#8855;', # circled times = vector product, U+2297 ISOamsb
212
- '&perp;' => '&#8869;', # up tack = orthogonal to = perpendicular, U+22A5 ISOtech
213
- '&sdot;' => '&#8901;', # dot operator, U+22C5 ISOamsb
214
- '&lceil;' => '&#8968;', # left ceiling = apl upstile, U+2308 ISOamsc
215
- '&rceil;' => '&#8969;', # right ceiling, U+2309 ISOamsc
216
- '&lfloor;' => '&#8970;', # left floor = apl downstile, U+230A ISOamsc
217
- '&rfloor;' => '&#8971;', # right floor, U+230B ISOamsc
218
- '&lang;' => '&#9001;', # left-pointing angle bracket = bra, U+2329 ISOtech
219
- '&rang;' => '&#9002;', # right-pointing angle bracket = ket, U+232A ISOtech
220
- '&loz;' => '&#9674;', # lozenge, U+25CA ISOpub
221
- '&spades;' => '&#9824;', # black spade suit, U+2660 ISOpub
222
- '&clubs;' => '&#9827;', # black club suit = shamrock, U+2663 ISOpub
223
- '&hearts;' => '&#9829;', # black heart suit = valentine, U+2665 ISOpub
224
- '&diams;' => '&#9830;', # black diamond suit, U+2666 ISOpub
225
- '&quot;' => '&#34;', # quotation mark = APL quote, U+0022 ISOnum
226
- '&amp;' => '&#38;', # ampersand, U+0026 ISOnum
227
- '&lt;' => '&#60;', # less-than sign, U+003C ISOnum
228
- '&gt;' => '&#62;', # greater-than sign, U+003E ISOnum
229
- '&OElig;' => '&#338;', # latin capital ligature OE, U+0152 ISOlat2
230
- '&oelig;' => '&#339;', # latin small ligature oe, U+0153 ISOlat2
231
- '&Scaron;' => '&#352;', # latin capital letter S with caron, U+0160 ISOlat2
232
- '&scaron;' => '&#353;', # latin small letter s with caron, U+0161 ISOlat2
233
- '&Yuml;' => '&#376;', # latin capital letter Y with diaeresis, U+0178 ISOlat2
234
- '&circ;' => '&#710;', # modifier letter circumflex accent, U+02C6 ISOpub
235
- '&tilde;' => '&#732;', # small tilde, U+02DC ISOdia
236
- '&ensp;' => '&#8194;', # en space, U+2002 ISOpub
237
- '&emsp;' => '&#8195;', # em space, U+2003 ISOpub
238
- '&thinsp;' => '&#8201;', # thin space, U+2009 ISOpub
239
- '&zwnj;' => '&#8204;', # zero width non-joiner, U+200C NEW RFC 2070
240
- '&zwj;' => '&#8205;', # zero width joiner, U+200D NEW RFC 2070
241
- '&lrm;' => '&#8206;', # left-to-right mark, U+200E NEW RFC 2070
242
- '&rlm;' => '&#8207;', # right-to-left mark, U+200F NEW RFC 2070
243
- '&ndash;' => '&#8211;', # en dash, U+2013 ISOpub
244
- '&mdash;' => '&#8212;', # em dash, U+2014 ISOpub
245
- '&lsquo;' => '&#8216;', # left single quotation mark, U+2018 ISOnum
246
- '&rsquo;' => '&#8217;', # right single quotation mark, U+2019 ISOnum
247
- '&sbquo;' => '&#8218;', # single low-9 quotation mark, U+201A NEW
248
- '&ldquo;' => '&#8220;', # left double quotation mark, U+201C ISOnum
249
- '&rdquo;' => '&#8221;', # right double quotation mark, U+201D ISOnum
250
- '&bdquo;' => '&#8222;', # double low-9 quotation mark, U+201E NEW
251
- '&dagger;' => '&#8224;', # dagger, U+2020 ISOpub
252
- '&Dagger;' => '&#8225;', # double dagger, U+2021 ISOpub
253
- '&permil;' => '&#8240;', # per mille sign, U+2030 ISOtech
254
- '&lsaquo;' => '&#8249;', # single left-pointing angle quotation mark, U+2039 ISO proposed
255
- '&rsaquo;' => '&#8250;', # single right-pointing angle quotation mark, U+203A ISO proposed
256
- '&euro;' => '&#8364;', # euro sign, U+20AC NEW
257
- );
258
-
259
-
260
  ?>
1
+ <?php
2
+
3
+ $HTML401NamedToNumeric = array(
4
+ '&apos;' => '&#39;',
5
+ '&nbsp;' => '&#160;', # no-break space = non-breaking space, U+00A0 ISOnum
6
+ '&iexcl;' => '&#161;', # inverted exclamation mark, U+00A1 ISOnum
7
+ '&cent;' => '&#162;', # cent sign, U+00A2 ISOnum
8
+ '&pound;' => '&#163;', # pound sign, U+00A3 ISOnum
9
+ '&curren;' => '&#164;', # currency sign, U+00A4 ISOnum
10
+ '&yen;' => '&#165;', # yen sign = yuan sign, U+00A5 ISOnum
11
+ '&brvbar;' => '&#166;', # broken bar = broken vertical bar, U+00A6 ISOnum
12
+ '&sect;' => '&#167;', # section sign, U+00A7 ISOnum
13
+ '&uml;' => '&#168;', # diaeresis = spacing diaeresis, U+00A8 ISOdia
14
+ '&copy;' => '&#169;', # copyright sign, U+00A9 ISOnum
15
+ '&ordf;' => '&#170;', # feminine ordinal indicator, U+00AA ISOnum
16
+ '&laquo;' => '&#171;', # left-pointing double angle quotation mark = left pointing guillemet, U+00AB ISOnum
17
+ '&not;' => '&#172;', # not sign, U+00AC ISOnum
18
+ '&shy;' => '&#173;', # soft hyphen = discretionary hyphen, U+00AD ISOnum
19
+ '&reg;' => '&#174;', # registered sign = registered trade mark sign, U+00AE ISOnum
20
+ '&macr;' => '&#175;', # macron = spacing macron = overline = APL overbar, U+00AF ISOdia
21
+ '&deg;' => '&#176;', # degree sign, U+00B0 ISOnum
22
+ '&plusmn;' => '&#177;', # plus-minus sign = plus-or-minus sign, U+00B1 ISOnum
23
+ '&sup2;' => '&#178;', # superscript two = superscript digit two = squared, U+00B2 ISOnum
24
+ '&sup3;' => '&#179;', # superscript three = superscript digit three = cubed, U+00B3 ISOnum
25
+ '&acute;' => '&#180;', # acute accent = spacing acute, U+00B4 ISOdia
26
+ '&micro;' => '&#181;', # micro sign, U+00B5 ISOnum
27
+ '&para;' => '&#182;', # pilcrow sign = paragraph sign, U+00B6 ISOnum
28
+ '&middot;' => '&#183;', # middle dot = Georgian comma = Greek middle dot, U+00B7 ISOnum
29
+ '&cedil;' => '&#184;', # cedilla = spacing cedilla, U+00B8 ISOdia
30
+ '&sup1;' => '&#185;', # superscript one = superscript digit one, U+00B9 ISOnum
31
+ '&ordm;' => '&#186;', # masculine ordinal indicator, U+00BA ISOnum
32
+ '&raquo;' => '&#187;', # right-pointing double angle quotation mark = right pointing guillemet, U+00BB ISOnum
33
+ '&frac14;' => '&#188;', # vulgar fraction one quarter = fraction one quarter, U+00BC ISOnum
34
+ '&frac12;' => '&#189;', # vulgar fraction one half = fraction one half, U+00BD ISOnum
35
+ '&frac34;' => '&#190;', # vulgar fraction three quarters = fraction three quarters, U+00BE ISOnum
36
+ '&iquest;' => '&#191;', # inverted question mark = turned question mark, U+00BF ISOnum
37
+ '&Agrave;' => '&#192;', # latin capital letter A with grave = latin capital letter A grave, U+00C0 ISOlat1
38
+ '&Aacute;' => '&#193;', # latin capital letter A with acute, U+00C1 ISOlat1
39
+ '&Acirc;' => '&#194;', # latin capital letter A with circumflex, U+00C2 ISOlat1
40
+ '&Atilde;' => '&#195;', # latin capital letter A with tilde, U+00C3 ISOlat1
41
+ '&Auml;' => '&#196;', # latin capital letter A with diaeresis, U+00C4 ISOlat1
42
+ '&Aring;' => '&#197;', # latin capital letter A with ring above = latin capital letter A ring, U+00C5 ISOlat1
43
+ '&AElig;' => '&#198;', # latin capital letter AE = latin capital ligature AE, U+00C6 ISOlat1
44
+ '&Ccedil;' => '&#199;', # latin capital letter C with cedilla, U+00C7 ISOlat1
45
+ '&Egrave;' => '&#200;', # latin capital letter E with grave, U+00C8 ISOlat1
46
+ '&Eacute;' => '&#201;', # latin capital letter E with acute, U+00C9 ISOlat1
47
+ '&Ecirc;' => '&#202;', # latin capital letter E with circumflex, U+00CA ISOlat1
48
+ '&Euml;' => '&#203;', # latin capital letter E with diaeresis, U+00CB ISOlat1
49
+ '&Igrave;' => '&#204;', # latin capital letter I with grave, U+00CC ISOlat1
50
+ '&Iacute;' => '&#205;', # latin capital letter I with acute, U+00CD ISOlat1
51
+ '&Icirc;' => '&#206;', # latin capital letter I with circumflex, U+00CE ISOlat1
52
+ '&Iuml;' => '&#207;', # latin capital letter I with diaeresis, U+00CF ISOlat1
53
+ '&ETH;' => '&#208;', # latin capital letter ETH, U+00D0 ISOlat1
54
+ '&Ntilde;' => '&#209;', # latin capital letter N with tilde, U+00D1 ISOlat1
55
+ '&Ograve;' => '&#210;', # latin capital letter O with grave, U+00D2 ISOlat1
56
+ '&Oacute;' => '&#211;', # latin capital letter O with acute, U+00D3 ISOlat1
57
+ '&Ocirc;' => '&#212;', # latin capital letter O with circumflex, U+00D4 ISOlat1
58
+ '&Otilde;' => '&#213;', # latin capital letter O with tilde, U+00D5 ISOlat1
59
+ '&Ouml;' => '&#214;', # latin capital letter O with diaeresis, U+00D6 ISOlat1
60
+ '&times;' => '&#215;', # multiplication sign, U+00D7 ISOnum
61
+ '&Oslash;' => '&#216;', # latin capital letter O with stroke = latin capital letter O slash, U+00D8 ISOlat1
62
+ '&Ugrave;' => '&#217;', # latin capital letter U with grave, U+00D9 ISOlat1
63
+ '&Uacute;' => '&#218;', # latin capital letter U with acute, U+00DA ISOlat1
64
+ '&Ucirc;' => '&#219;', # latin capital letter U with circumflex, U+00DB ISOlat1
65
+ '&Uuml;' => '&#220;', # latin capital letter U with diaeresis, U+00DC ISOlat1
66
+ '&Yacute;' => '&#221;', # latin capital letter Y with acute, U+00DD ISOlat1
67
+ '&THORN;' => '&#222;', # latin capital letter THORN, U+00DE ISOlat1
68
+ '&szlig;' => '&#223;', # latin small letter sharp s = ess-zed, U+00DF ISOlat1
69
+ '&agrave;' => '&#224;', # latin small letter a with grave = latin small letter a grave, U+00E0 ISOlat1
70
+ '&aacute;' => '&#225;', # latin small letter a with acute, U+00E1 ISOlat1
71
+ '&acirc;' => '&#226;', # latin small letter a with circumflex, U+00E2 ISOlat1
72
+ '&atilde;' => '&#227;', # latin small letter a with tilde, U+00E3 ISOlat1
73
+ '&auml;' => '&#228;', # latin small letter a with diaeresis, U+00E4 ISOlat1
74
+ '&aring;' => '&#229;', # latin small letter a with ring above = latin small letter a ring, U+00E5 ISOlat1
75
+ '&aelig;' => '&#230;', # latin small letter ae = latin small ligature ae, U+00E6 ISOlat1
76
+ '&ccedil;' => '&#231;', # latin small letter c with cedilla, U+00E7 ISOlat1
77
+ '&egrave;' => '&#232;', # latin small letter e with grave, U+00E8 ISOlat1
78
+ '&eacute;' => '&#233;', # latin small letter e with acute, U+00E9 ISOlat1
79
+ '&ecirc;' => '&#234;', # latin small letter e with circumflex, U+00EA ISOlat1
80
+ '&euml;' => '&#235;', # latin small letter e with diaeresis, U+00EB ISOlat1
81
+ '&igrave;' => '&#236;', # latin small letter i with grave, U+00EC ISOlat1
82
+ '&iacute;' => '&#237;', # latin small letter i with acute, U+00ED ISOlat1
83
+ '&icirc;' => '&#238;', # latin small letter i with circumflex, U+00EE ISOlat1
84
+ '&iuml;' => '&#239;', # latin small letter i with diaeresis, U+00EF ISOlat1
85
+ '&eth;' => '&#240;', # latin small letter eth, U+00F0 ISOlat1
86
+ '&ntilde;' => '&#241;', # latin small letter n with tilde, U+00F1 ISOlat1
87
+ '&ograve;' => '&#242;', # latin small letter o with grave, U+00F2 ISOlat1
88
+ '&oacute;' => '&#243;', # latin small letter o with acute, U+00F3 ISOlat1
89
+ '&ocirc;' => '&#244;', # latin small letter o with circumflex, U+00F4 ISOlat1
90
+ '&otilde;' => '&#245;', # latin small letter o with tilde, U+00F5 ISOlat1
91
+ '&ouml;' => '&#246;', # latin small letter o with diaeresis, U+00F6 ISOlat1
92
+ '&divide;' => '&#247;', # division sign, U+00F7 ISOnum
93
+ '&oslash;' => '&#248;', # latin small letter o with stroke, = latin small letter o slash, U+00F8 ISOlat1
94
+ '&ugrave;' => '&#249;', # latin small letter u with grave, U+00F9 ISOlat1
95
+ '&uacute;' => '&#250;', # latin small letter u with acute, U+00FA ISOlat1
96
+ '&ucirc;' => '&#251;', # latin small letter u with circumflex, U+00FB ISOlat1
97
+ '&uuml;' => '&#252;', # latin small letter u with diaeresis, U+00FC ISOlat1
98
+ '&yacute;' => '&#253;', # latin small letter y with acute, U+00FD ISOlat1
99
+ '&thorn;' => '&#254;', # latin small letter thorn, U+00FE ISOlat1
100
+ '&yuml;' => '&#255;', # latin small letter y with diaeresis, U+00FF ISOlat1
101
+ '&fnof;' => '&#402;', # latin small f with hook = function = florin, U+0192 ISOtech
102
+ '&Alpha;' => '&#913;', # greek capital letter alpha, U+0391
103
+ '&Beta;' => '&#914;', # greek capital letter beta, U+0392
104
+ '&Gamma;' => '&#915;', # greek capital letter gamma, U+0393 ISOgrk3
105
+ '&Delta;' => '&#916;', # greek capital letter delta, U+0394 ISOgrk3
106
+ '&Epsilon;' => '&#917;', # greek capital letter epsilon, U+0395
107
+ '&Zeta;' => '&#918;', # greek capital letter zeta, U+0396
108
+ '&Eta;' => '&#919;', # greek capital letter eta, U+0397
109
+ '&Theta;' => '&#920;', # greek capital letter theta, U+0398 ISOgrk3
110
+ '&Iota;' => '&#921;', # greek capital letter iota, U+0399
111
+ '&Kappa;' => '&#922;', # greek capital letter kappa, U+039A
112
+ '&Lambda;' => '&#923;', # greek capital letter lambda, U+039B ISOgrk3
113
+ '&Mu;' => '&#924;', # greek capital letter mu, U+039C
114
+ '&Nu;' => '&#925;', # greek capital letter nu, U+039D
115
+ '&Xi;' => '&#926;', # greek capital letter xi, U+039E ISOgrk3
116
+ '&Omicron;' => '&#927;', # greek capital letter omicron, U+039F
117
+ '&Pi;' => '&#928;', # greek capital letter pi, U+03A0 ISOgrk3
118
+ '&Rho;' => '&#929;', # greek capital letter rho, U+03A1
119
+ '&Sigma;' => '&#931;', # greek capital letter sigma, U+03A3 ISOgrk3
120
+ '&Tau;' => '&#932;', # greek capital letter tau, U+03A4
121
+ '&Upsilon;' => '&#933;', # greek capital letter upsilon, U+03A5 ISOgrk3
122
+ '&Phi;' => '&#934;', # greek capital letter phi, U+03A6 ISOgrk3
123
+ '&Chi;' => '&#935;', # greek capital letter chi, U+03A7
124
+ '&Psi;' => '&#936;', # greek capital letter psi, U+03A8 ISOgrk3
125
+ '&Omega;' => '&#937;', # greek capital letter omega, U+03A9 ISOgrk3
126
+ '&alpha;' => '&#945;', # greek small letter alpha, U+03B1 ISOgrk3
127
+ '&beta;' => '&#946;', # greek small letter beta, U+03B2 ISOgrk3
128
+ '&gamma;' => '&#947;', # greek small letter gamma, U+03B3 ISOgrk3
129
+ '&delta;' => '&#948;', # greek small letter delta, U+03B4 ISOgrk3
130
+ '&epsilon;' => '&#949;', # greek small letter epsilon, U+03B5 ISOgrk3
131
+ '&zeta;' => '&#950;', # greek small letter zeta, U+03B6 ISOgrk3
132
+ '&eta;' => '&#951;', # greek small letter eta, U+03B7 ISOgrk3
133
+ '&theta;' => '&#952;', # greek small letter theta, U+03B8 ISOgrk3
134
+ '&iota;' => '&#953;', # greek small letter iota, U+03B9 ISOgrk3
135
+ '&kappa;' => '&#954;', # greek small letter kappa, U+03BA ISOgrk3
136
+ '&lambda;' => '&#955;', # greek small letter lambda, U+03BB ISOgrk3
137
+ '&mu;' => '&#956;', # greek small letter mu, U+03BC ISOgrk3
138
+ '&nu;' => '&#957;', # greek small letter nu, U+03BD ISOgrk3
139
+ '&xi;' => '&#958;', # greek small letter xi, U+03BE ISOgrk3
140
+ '&omicron;' => '&#959;', # greek small letter omicron, U+03BF NEW
141
+ '&pi;' => '&#960;', # greek small letter pi, U+03C0 ISOgrk3
142
+ '&rho;' => '&#961;', # greek small letter rho, U+03C1 ISOgrk3
143
+ '&sigmaf;' => '&#962;', # greek small letter final sigma, U+03C2 ISOgrk3
144
+ '&sigma;' => '&#963;', # greek small letter sigma, U+03C3 ISOgrk3
145
+ '&tau;' => '&#964;', # greek small letter tau, U+03C4 ISOgrk3
146
+ '&upsilon;' => '&#965;', # greek small letter upsilon, U+03C5 ISOgrk3
147
+ '&phi;' => '&#966;', # greek small letter phi, U+03C6 ISOgrk3
148
+ '&chi;' => '&#967;', # greek small letter chi, U+03C7 ISOgrk3
149
+ '&psi;' => '&#968;', # greek small letter psi, U+03C8 ISOgrk3
150
+ '&omega;' => '&#969;', # greek small letter omega, U+03C9 ISOgrk3
151
+ '&thetasym;' => '&#977;', # greek small letter theta symbol, U+03D1 NEW
152
+ '&upsih;' => '&#978;', # greek upsilon with hook symbol, U+03D2 NEW
153
+ '&piv;' => '&#982;', # greek pi symbol, U+03D6 ISOgrk3
154
+ '&bull;' => '&#8226;', # bullet = black small circle, U+2022 ISOpub
155
+ '&hellip;' => '&#8230;', # horizontal ellipsis = three dot leader, U+2026 ISOpub
156
+ '&prime;' => '&#8242;', # prime = minutes = feet, U+2032 ISOtech
157
+ '&Prime;' => '&#8243;', # double prime = seconds = inches, U+2033 ISOtech
158
+ '&oline;' => '&#8254;', # overline = spacing overscore, U+203E NEW
159
+ '&frasl;' => '&#8260;', # fraction slash, U+2044 NEW
160
+ '&weierp;' => '&#8472;', # script capital P = power set = Weierstrass p, U+2118 ISOamso
161
+ '&image;' => '&#8465;', # blackletter capital I = imaginary part, U+2111 ISOamso
162
+ '&real;' => '&#8476;', # blackletter capital R = real part symbol, U+211C ISOamso
163
+ '&trade;' => '&#8482;', # trade mark sign, U+2122 ISOnum
164
+ '&alefsym;' => '&#8501;', # alef symbol = first transfinite cardinal, U+2135 NEW
165
+ '&larr;' => '&#8592;', # leftwards arrow, U+2190 ISOnum
166
+ '&uarr;' => '&#8593;', # upwards arrow, U+2191 ISOnum
167
+ '&rarr;' => '&#8594;', # rightwards arrow, U+2192 ISOnum
168
+ '&darr;' => '&#8595;', # downwards arrow, U+2193 ISOnum
169
+ '&harr;' => '&#8596;', # left right arrow, U+2194 ISOamsa
170
+ '&crarr;' => '&#8629;', # downwards arrow with corner leftwards = carriage return, U+21B5 NEW
171
+ '&lArr;' => '&#8656;', # leftwards double arrow, U+21D0 ISOtech
172
+ '&uArr;' => '&#8657;', # upwards double arrow, U+21D1 ISOamsa
173
+ '&rArr;' => '&#8658;', # rightwards double arrow, U+21D2 ISOtech
174
+ '&dArr;' => '&#8659;', # downwards double arrow, U+21D3 ISOamsa
175
+ '&hArr;' => '&#8660;', # left right double arrow, U+21D4 ISOamsa
176
+ '&forall;' => '&#8704;', # for all, U+2200 ISOtech
177
+ '&part;' => '&#8706;', # partial differential, U+2202 ISOtech
178
+ '&exist;' => '&#8707;', # there exists, U+2203 ISOtech
179
+ '&empty;' => '&#8709;', # empty set = null set = diameter, U+2205 ISOamso
180
+ '&nabla;' => '&#8711;', # nabla = backward difference, U+2207 ISOtech
181
+ '&isin;' => '&#8712;', # element of, U+2208 ISOtech
182
+ '&notin;' => '&#8713;', # not an element of, U+2209 ISOtech
183
+ '&ni;' => '&#8715;', # contains as member, U+220B ISOtech
184
+ '&prod;' => '&#8719;', # n-ary product = product sign, U+220F ISOamsb
185
+ '&sum;' => '&#8721;', # n-ary sumation, U+2211 ISOamsb
186
+ '&minus;' => '&#8722;', # minus sign, U+2212 ISOtech
187
+ '&lowast;' => '&#8727;', # asterisk operator, U+2217 ISOtech
188
+ '&radic;' => '&#8730;', # square root = radical sign, U+221A ISOtech
189
+ '&prop;' => '&#8733;', # proportional to, U+221D ISOtech
190
+ '&infin;' => '&#8734;', # infinity, U+221E ISOtech
191
+ '&ang;' => '&#8736;', # angle, U+2220 ISOamso
192
+ '&and;' => '&#8743;', # logical and = wedge, U+2227 ISOtech
193
+ '&or;' => '&#8744;', # logical or = vee, U+2228 ISOtech
194
+ '&cap;' => '&#8745;', # intersection = cap, U+2229 ISOtech
195
+ '&cup;' => '&#8746;', # union = cup, U+222A ISOtech
196
+ '&int;' => '&#8747;', # integral, U+222B ISOtech
197
+ '&there4;' => '&#8756;', # therefore, U+2234 ISOtech
198
+ '&sim;' => '&#8764;', # tilde operator = varies with = similar to, U+223C ISOtech
199
+ '&cong;' => '&#8773;', # approximately equal to, U+2245 ISOtech
200
+ '&asymp;' => '&#8776;', # almost equal to = asymptotic to, U+2248 ISOamsr
201
+ '&ne;' => '&#8800;', # not equal to, U+2260 ISOtech
202
+ '&equiv;' => '&#8801;', # identical to, U+2261 ISOtech
203
+ '&le;' => '&#8804;', # less-than or equal to, U+2264 ISOtech
204
+ '&ge;' => '&#8805;', # greater-than or equal to, U+2265 ISOtech
205
+ '&sub;' => '&#8834;', # subset of, U+2282 ISOtech
206
+ '&sup;' => '&#8835;', # superset of, U+2283 ISOtech
207
+ '&nsub;' => '&#8836;', # not a subset of, U+2284 ISOamsn
208
+ '&sube;' => '&#8838;', # subset of or equal to, U+2286 ISOtech
209
+ '&supe;' => '&#8839;', # superset of or equal to, U+2287 ISOtech
210
+ '&oplus;' => '&#8853;', # circled plus = direct sum, U+2295 ISOamsb
211
+ '&otimes;' => '&#8855;', # circled times = vector product, U+2297 ISOamsb
212
+ '&perp;' => '&#8869;', # up tack = orthogonal to = perpendicular, U+22A5 ISOtech
213
+ '&sdot;' => '&#8901;', # dot operator, U+22C5 ISOamsb
214
+ '&lceil;' => '&#8968;', # left ceiling = apl upstile, U+2308 ISOamsc
215
+ '&rceil;' => '&#8969;', # right ceiling, U+2309 ISOamsc
216
+ '&lfloor;' => '&#8970;', # left floor = apl downstile, U+230A ISOamsc
217
+ '&rfloor;' => '&#8971;', # right floor, U+230B ISOamsc
218
+ '&lang;' => '&#9001;', # left-pointing angle bracket = bra, U+2329 ISOtech
219
+ '&rang;' => '&#9002;', # right-pointing angle bracket = ket, U+232A ISOtech
220
+ '&loz;' => '&#9674;', # lozenge, U+25CA ISOpub
221
+ '&spades;' => '&#9824;', # black spade suit, U+2660 ISOpub
222
+ '&clubs;' => '&#9827;', # black club suit = shamrock, U+2663 ISOpub
223
+ '&hearts;' => '&#9829;', # black heart suit = valentine, U+2665 ISOpub
224
+ '&diams;' => '&#9830;', # black diamond suit, U+2666 ISOpub
225
+ '&quot;' => '&#34;', # quotation mark = APL quote, U+0022 ISOnum
226
+ '&amp;' => '&#38;', # ampersand, U+0026 ISOnum
227
+ '&lt;' => '&#60;', # less-than sign, U+003C ISOnum
228
+ '&gt;' => '&#62;', # greater-than sign, U+003E ISOnum
229
+ '&OElig;' => '&#338;', # latin capital ligature OE, U+0152 ISOlat2
230
+ '&oelig;' => '&#339;', # latin small ligature oe, U+0153 ISOlat2
231
+ '&Scaron;' => '&#352;', # latin capital letter S with caron, U+0160 ISOlat2
232
+ '&scaron;' => '&#353;', # latin small letter s with caron, U+0161 ISOlat2
233
+ '&Yuml;' => '&#376;', # latin capital letter Y with diaeresis, U+0178 ISOlat2
234
+ '&circ;' => '&#710;', # modifier letter circumflex accent, U+02C6 ISOpub
235
+ '&tilde;' => '&#732;', # small tilde, U+02DC ISOdia
236
+ '&ensp;' => '&#8194;', # en space, U+2002 ISOpub
237
+ '&emsp;' => '&#8195;', # em space, U+2003 ISOpub
238
+ '&thinsp;' => '&#8201;', # thin space, U+2009 ISOpub
239
+ '&zwnj;' => '&#8204;', # zero width non-joiner, U+200C NEW RFC 2070
240
+ '&zwj;' => '&#8205;', # zero width joiner, U+200D NEW RFC 2070
241
+ '&lrm;' => '&#8206;', # left-to-right mark, U+200E NEW RFC 2070
242
+ '&rlm;' => '&#8207;', # right-to-left mark, U+200F NEW RFC 2070
243
+ '&ndash;' => '&#8211;', # en dash, U+2013 ISOpub
244
+ '&mdash;' => '&#8212;', # em dash, U+2014 ISOpub
245
+ '&lsquo;' => '&#8216;', # left single quotation mark, U+2018 ISOnum
246
+ '&rsquo;' => '&#8217;', # right single quotation mark, U+2019 ISOnum
247
+ '&sbquo;' => '&#8218;', # single low-9 quotation mark, U+201A NEW
248
+ '&ldquo;' => '&#8220;', # left double quotation mark, U+201C ISOnum
249
+ '&rdquo;' => '&#8221;', # right double quotation mark, U+201D ISOnum
250
+ '&bdquo;' => '&#8222;', # double low-9 quotation mark, U+201E NEW
251
+ '&dagger;' => '&#8224;', # dagger, U+2020 ISOpub
252
+ '&Dagger;' => '&#8225;', # double dagger, U+2021 ISOpub
253
+ '&permil;' => '&#8240;', # per mille sign, U+2030 ISOtech
254
+ '&lsaquo;' => '&#8249;', # single left-pointing angle quotation mark, U+2039 ISO proposed
255
+ '&rsaquo;' => '&#8250;', # single right-pointing angle quotation mark, U+203A ISO proposed
256
+ '&euro;' => '&#8364;', # euro sign, U+20AC NEW
257
+ );
258
+
259
+
260
  ?>
inc-cl/apis/liOAuth.php CHANGED
@@ -1,185 +1,185 @@
1
- <?php
2
- require_once("OAuth.php");
3
-
4
- class nsx_LinkedIn {
5
- public $base_url = "http://api.linkedin.com";
6
- public $secure_base_url = "https://api.linkedin.com";
7
- public $oauth_callback = "oob";
8
- public $consumer;
9
- public $request_token;
10
- public $access_token;
11
- public $oauth_verifier;
12
- public $signature_method;
13
- public $request_token_path;
14
- public $access_token_path;
15
- public $authorize_path;
16
- public $debug = false;
17
- public $http_code;
18
-
19
- function __construct($consumer_key, $consumer_secret, $oauth_callback = NULL) {
20
-
21
- if($oauth_callback) {
22
- $this->oauth_callback = $oauth_callback;
23
- }
24
-
25
- $this->consumer = new nsx_trOAuthConsumer($consumer_key, $consumer_secret, $this->oauth_callback);
26
- $this->signature_method = new nsx_trOAuthSignatureMethod_HMAC_SHA1();
27
- $this->request_token_path = $this->secure_base_url . "/uas/oauth/requestToken?scope=r_basicprofile+r_emailaddress+rw_nus+rw_groups";
28
- $this->access_token_path = $this->secure_base_url . "/uas/oauth/accessToken";
29
- $this->authorize_path = $this->secure_base_url . "/uas/oauth/authorize";
30
-
31
- }
32
-
33
- function getRequestToken() {
34
- $consumer = $this->consumer;
35
- $request = nsx_trOAuthRequest::from_consumer_and_token($consumer, NULL, "GET", $this->request_token_path);
36
- $request->set_parameter("oauth_callback", $this->oauth_callback);
37
- $request->sign_request($this->signature_method, $consumer, NULL); // prr($request);
38
- $headers = Array();
39
- $url = $request->to_url(); // echo "^^^^^"; prr($url);
40
- $response = $this->httpRequest($url, $headers, "GET"); //prr($response);
41
- if ($response!='') $this->http_code = 200;
42
- parse_str($response, $response_params); //prr($response_params); echo "!!!!";
43
- $this->request_token = new nsx_trOAuthConsumer($response_params['oauth_token'], $response_params['oauth_token_secret'], 1); return $this->request_token;
44
- }
45
-
46
- function generateAuthorizeUrl() {
47
- $consumer = $this->consumer;
48
- $request_token = $this->request_token;
49
- return $this->authorize_path . "?oauth_token=" . $request_token->key;
50
- }
51
-
52
- function getAccessToken($oauth_verifier) {
53
- $request = nsx_trOAuthRequest::from_consumer_and_token($this->consumer, $this->request_token, "GET", $this->access_token_path);
54
- $request->set_parameter("oauth_verifier", $oauth_verifier);
55
- $request->sign_request($this->signature_method, $this->consumer, $this->request_token);
56
- $headers = Array();
57
- $url = $request->to_url(); // echo "==========";
58
- $response = $this->httpRequest($url, $headers, "GET"); //prr($request);
59
- parse_str($response, $response_params); // prr($response_params);
60
- if($debug) {
61
- echo $response . "\n";
62
- }
63
- $this->access_token = new nsx_trOAuthConsumer($response_params['oauth_token'], $response_params['oauth_token_secret'], 1);
64
- }
65
-
66
- function getProfile($resource = "~") {
67
- $profile_url = $this->base_url . "/v1/people/" . $resource;
68
- $request = nsx_trOAuthRequest::from_consumer_and_token($this->consumer, $this->access_token, "GET", $profile_url);
69
- $request->sign_request($this->signature_method, $this->consumer, $this->access_token);
70
- $auth_header = $request->to_header("https://api.linkedin.com"); # this is the realm
71
- # This PHP library doesn't generate the header correctly when a realm is not specified.
72
- # Make sure there is a space and not a comma after OAuth
73
- // $auth_header = preg_replace("/Authorization\: OAuth\,/", "Authorization: OAuth ", $auth_header);
74
- // # Make sure there is a space between OAuth attribute
75
- // $auth_header = preg_replace('/\"\,/', '", ', $auth_header);
76
- if ($debug) {
77
- echo $auth_header;
78
- }
79
- // $response will now hold the XML document
80
- $response = $this->httpRequest($profile_url, $auth_header, "GET");
81
- return $response;
82
- }
83
-
84
-
85
-
86
-
87
- function postShare($msg, $title='', $url='', $imgURL='', $dsc='') { $status_url = $this->base_url . "/v1/people/~/shares";
88
- $dsc = nxs_decodeEntitiesFull(strip_tags($dsc)); $msg = strip_tags(nxs_decodeEntitiesFull($msg)); $title = nxs_decodeEntitiesFull(strip_tags($title));
89
- $xml = '<?xml version="1.0" encoding="UTF-8"?><share><comment>'.htmlspecialchars($msg, ENT_NOQUOTES, "UTF-8").'</comment>'.
90
- ($url!=''?'<content><title>'.htmlspecialchars($title, ENT_NOQUOTES, "UTF-8").'</title><submitted-url>'.$url.'</submitted-url><submitted-image-url>'.$imgURL.'</submitted-image-url><description>'.htmlspecialchars($dsc, ENT_NOQUOTES, "UTF-8").'</description></content>':'').
91
- '<visibility><code>anyone</code></visibility></share>';
92
- $request = nsx_trOAuthRequest::from_consumer_and_token($this->consumer, $this->access_token, "POST", $status_url);
93
- $request->sign_request($this->signature_method, $this->consumer, $this->access_token);
94
- $auth_header = $request->to_header("https://api.linkedin.com");
95
- if ($debug) echo $auth_header . "\n";
96
- $response = $this->httpRequest($status_url, $auth_header, "POST", $xml);
97
- return $response;
98
- }
99
-
100
- function postToGroup($msg, $title, $groupID, $url='', $imgURL='', $dsc='') { $status_url = $this->base_url . "/v1/groups/".$groupID."/posts"; //$debug = true;
101
- $dsc = nxs_decodeEntitiesFull(strip_tags($dsc)); $msg = strip_tags(nxs_decodeEntitiesFull($msg)); $title = nxs_decodeEntitiesFull(strip_tags($title));
102
- $xml = '<?xml version="1.0" encoding="UTF-8"?><post><title>'.htmlspecialchars($title, ENT_NOQUOTES, "UTF-8").'</title><summary>'.htmlspecialchars($msg, ENT_NOQUOTES, "UTF-8").'</summary>
103
- '.($url!=''?'<content><title>'.htmlspecialchars($title, ENT_NOQUOTES, "UTF-8").'</title><submitted-url>'.$url.'</submitted-url><submitted-image-url>'.$imgURL.'</submitted-image-url><description>'.htmlspecialchars($dsc, ENT_NOQUOTES, "UTF-8").'</description></content>':'').'</post>';
104
-
105
- $request = nsx_trOAuthRequest::from_consumer_and_token($this->consumer, $this->access_token, "POST", $status_url);
106
- $request->sign_request($this->signature_method, $this->consumer, $this->access_token);
107
- $auth_header = $request->to_header("https://api.linkedin.com");
108
- if ($debug) echo $auth_header . "\n";
109
- $response = $this->httpRequest($status_url, $auth_header, "POST", $xml);//prr($response);
110
- return $response;
111
- }
112
-
113
- function setStatus($status) {
114
- $status_url = $this->base_url . "/v1/people/~/current-status";
115
- //echo "Setting status...\n";
116
- $xml = "<current-status>" . htmlspecialchars($status, ENT_NOQUOTES, "UTF-8") . "</current-status>";
117
- //echo $xml . "\n";
118
- $request = nsx_trOAuthRequest::from_consumer_and_token($this->consumer, $this->access_token, "PUT", $status_url);
119
- $request->sign_request($this->signature_method, $this->consumer, $this->access_token);
120
- $auth_header = $request->to_header("https://api.linkedin.com");
121
- if ($debug) {
122
- echo $auth_header . "\n";
123
- }
124
- $response = $this->httpRequest($status_url, $auth_header, "PUT", $xml); // prr($response);
125
- return $response;
126
- }
127
-
128
- # Parameters should be a query string starting with "?"
129
- # Example search("?count=10&start=10&company=LinkedIn");
130
- function search($parameters) {
131
- $search_url = $this->base_url . "/v1/people/" . $parameters;
132
- echo "Performing search for: " . $parameters . "\n";
133
- $request = nsx_trOAuthRequest::from_consumer_and_token($this->consumer, $this->access_token, "GET", $search_url);
134
- $request->sign_request($this->signature_method, $this->consumer, $this->access_token);
135
- $auth_header = $request->to_header("https://api.linkedin.com");
136
- if ($debug) {
137
- echo $request->get_signature_base_string() . "\n";
138
- echo $auth_header . "\n";
139
- }
140
- $response = $this->httpRequest($search_url, $auth_header, "GET");
141
- return $response;
142
- }
143
-
144
- function getCurrentShare($parameters='') {
145
- $search_url = $this->base_url . "/v1/people/~/current-share";
146
- $request = nsx_trOAuthRequest::from_consumer_and_token($this->consumer, $this->access_token, "GET", $search_url);
147
- $request->sign_request($this->signature_method, $this->consumer, $this->access_token);
148
- $auth_header = $request->to_header("https://api.linkedin.com");
149
- if ($debug) {
150
- echo $request->get_signature_base_string() . "\n";
151
- echo $auth_header . "\n";
152
- }
153
- $response = $this->httpRequest($search_url, $auth_header, "GET");
154
- return $response;
155
- }
156
-
157
- function httpRequest($url, $auth_header, $method, $body = NULL) { // $this->debug = true; //if (!is_array($auth_header)) $auth_header = array($auth_header);
158
- if (!is_array($auth_header)) $auth_header = array($auth_header);
159
- if (!$method) $method = "GET"; $curl = curl_init();
160
- curl_setopt($curl, CURLOPT_URL, $url);
161
- curl_setopt($curl, CURLOPT_HEADER, 0);
162
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
163
- curl_setopt($curl, CURLOPT_HTTPHEADER, $auth_header); // Set the headers.
164
-
165
- if ($body) { $auth_header[] = "Content-Type: text/xml;charset=utf-8";
166
- curl_setopt($curl, CURLOPT_POST, 1);
167
- curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
168
- curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
169
- curl_setopt($curl, CURLOPT_HTTPHEADER, $auth_header);
170
- }
171
-
172
- $data = curl_exec($curl); $errmsg = curl_error($curl); //prr($data);// die();
173
-
174
- //## NextScripts Fix
175
- if (curl_errno($curl) == 60 || stripos($errmsg, 'SSL')!==false) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $data = curl_exec($curl);}
176
- if (curl_errno($curl) > 0) { $err = curl_errno($curl); $errmsg = curl_error($curl); prr($errmsg); prr($err);}
177
- //## /NextScripts Fix
178
- $header = curl_getinfo($curl); curl_close($curl);// prr($header);
179
-
180
- if ($this->debug) echo $data . "\n";
181
- if (trim($data)=='' && ($header['http_code']=='201' || $header['http_code']=='200' || $header['http_code']=='202')) $data = '201';
182
- return $data;
183
- }
184
-
185
  }
1
+ <?php
2
+ require_once("OAuth.php");
3
+
4
+ class nsx_LinkedIn {
5
+ public $base_url = "http://api.linkedin.com";
6
+ public $secure_base_url = "https://api.linkedin.com";
7
+ public $oauth_callback = "oob";
8
+ public $consumer;
9
+ public $request_token;
10
+ public $access_token;
11
+ public $oauth_verifier;
12
+ public $signature_method;
13
+ public $request_token_path;
14
+ public $access_token_path;
15
+ public $authorize_path;
16
+ public $debug = false;
17
+ public $http_code;
18
+
19
+ function __construct($consumer_key, $consumer_secret, $oauth_callback = NULL) {
20
+
21
+ if($oauth_callback) {
22
+ $this->oauth_callback = $oauth_callback;
23
+ }
24
+
25
+ $this->consumer = new nsx_trOAuthConsumer($consumer_key, $consumer_secret, $this->oauth_callback);
26
+ $this->signature_method = new nsx_trOAuthSignatureMethod_HMAC_SHA1();
27
+ $this->request_token_path = $this->secure_base_url . "/uas/oauth/requestToken?scope=r_basicprofile+r_emailaddress+rw_nus+rw_groups";
28
+ $this->access_token_path = $this->secure_base_url . "/uas/oauth/accessToken";
29
+ $this->authorize_path = $this->secure_base_url . "/uas/oauth/authorize";
30
+
31
+ }
32
+
33
+ function getRequestToken() {
34
+ $consumer = $this->consumer;
35
+ $request = nsx_trOAuthRequest::from_consumer_and_token($consumer, NULL, "GET", $this->request_token_path);
36
+ $request->set_parameter("oauth_callback", $this->oauth_callback);
37
+ $request->sign_request($this->signature_method, $consumer, NULL); // prr($request);
38
+ $headers = Array();
39
+ $url = $request->to_url(); // echo "^^^^^"; prr($url);
40
+ $response = $this->httpRequest($url, $headers, "GET"); //prr($response);
41
+ if ($response!='') $this->http_code = 200;
42
+ parse_str($response, $response_params); //prr($response_params); echo "!!!!";
43
+ $this->request_token = new nsx_trOAuthConsumer($response_params['oauth_token'], $response_params['oauth_token_secret'], 1); return $this->request_token;
44
+ }
45
+
46
+ function generateAuthorizeUrl() {
47
+ $consumer = $this->consumer;
48
+ $request_token = $this->request_token;
49
+ return $this->authorize_path . "?oauth_token=" . $request_token->key;
50
+ }
51
+
52
+ function getAccessToken($oauth_verifier) {
53
+ $request = nsx_trOAuthRequest::from_consumer_and_token($this->consumer, $this->request_token, "GET", $this->access_token_path);
54
+ $request->set_parameter("oauth_verifier", $oauth_verifier);
55
+ $request->sign_request($this->signature_method, $this->consumer, $this->request_token);
56
+ $headers = Array();
57
+ $url = $request->to_url(); // echo "==========";
58
+ $response = $this->httpRequest($url, $headers, "GET"); //prr($request);
59
+ parse_str($response, $response_params); // prr($response_params);
60
+ if($debug) {
61
+ echo $response . "\n";
62
+ }
63
+ $this->access_token = new nsx_trOAuthConsumer($response_params['oauth_token'], $response_params['oauth_token_secret'], 1);
64
+ }
65
+
66
+ function getProfile($resource = "~") {
67
+ $profile_url = $this->base_url . "/v1/people/" . $resource;
68
+ $request = nsx_trOAuthRequest::from_consumer_and_token($this->consumer, $this->access_token, "GET", $profile_url);
69
+ $request->sign_request($this->signature_method, $this->consumer, $this->access_token);
70
+ $auth_header = $request->to_header("https://api.linkedin.com"); # this is the realm
71
+ # This PHP library doesn't generate the header correctly when a realm is not specified.
72
+ # Make sure there is a space and not a comma after OAuth
73
+ // $auth_header = preg_replace("/Authorization\: OAuth\,/", "Authorization: OAuth ", $auth_header);
74
+ // # Make sure there is a space between OAuth attribute
75
+ // $auth_header = preg_replace('/\"\,/', '", ', $auth_header);
76
+ if ($debug) {
77
+ echo $auth_header;
78
+ }
79
+ // $response will now hold the XML document
80
+ $response = $this->httpRequest($profile_url, $auth_header, "GET");
81
+ return $response;
82
+ }
83
+
84
+
85
+
86
+
87
+ function postShare($msg, $title='', $url='', $imgURL='', $dsc='') { $status_url = $this->base_url . "/v1/people/~/shares";
88
+ $dsc = nxs_decodeEntitiesFull(strip_tags($dsc)); $msg = strip_tags(nxs_decodeEntitiesFull($msg)); $title = nxs_decodeEntitiesFull(strip_tags($title));
89
+ $xml = '<?xml version="1.0" encoding="UTF-8"?><share><comment>'.htmlspecialchars($msg, ENT_NOQUOTES, "UTF-8").'</comment>'.
90
+ ($url!=''?'<content><title>'.htmlspecialchars($title, ENT_NOQUOTES, "UTF-8").'</title><submitted-url>'.$url.'</submitted-url><submitted-image-url>'.$imgURL.'</submitted-image-url><description>'.htmlspecialchars($dsc, ENT_NOQUOTES, "UTF-8").'</description></content>':'').
91
+ '<visibility><code>anyone</code></visibility></share>';
92
+ $request = nsx_trOAuthRequest::from_consumer_and_token($this->consumer, $this->access_token, "POST", $status_url);
93
+ $request->sign_request($this->signature_method, $this->consumer, $this->access_token);
94
+ $auth_header = $request->to_header("https://api.linkedin.com");
95
+ if ($debug) echo $auth_header . "\n";
96
+ $response = $this->httpRequest($status_url, $auth_header, "POST", $xml);
97
+ return $response;
98
+ }
99
+
100
+ function postToGroup($msg, $title, $groupID, $url='', $imgURL='', $dsc='') { $status_url = $this->base_url . "/v1/groups/".$groupID."/posts"; //$debug = true;
101
+ $dsc = nxs_decodeEntitiesFull(strip_tags($dsc)); $msg = strip_tags(nxs_decodeEntitiesFull($msg)); $title = nxs_decodeEntitiesFull(strip_tags($title));
102
+ $xml = '<?xml version="1.0" encoding="UTF-8"?><post><title>'.htmlspecialchars($title, ENT_NOQUOTES, "UTF-8").'</title><summary>'.htmlspecialchars($msg, ENT_NOQUOTES, "UTF-8").'</summary>
103
+ '.($url!=''?'<content><title>'.htmlspecialchars($title, ENT_NOQUOTES, "UTF-8").'</title><submitted-url>'.$url.'</submitted-url><submitted-image-url>'.$imgURL.'</submitted-image-url><description>'.htmlspecialchars($dsc, ENT_NOQUOTES, "UTF-8").'</description></content>':'').'</post>';
104
+
105
+ $request = nsx_trOAuthRequest::from_consumer_and_token($this->consumer, $this->access_token, "POST", $status_url);
106
+ $request->sign_request($this->signature_method, $this->consumer, $this->access_token);
107
+ $auth_header = $request->to_header("https://api.linkedin.com");
108
+ if ($debug) echo $auth_header . "\n";
109
+ $response = $this->httpRequest($status_url, $auth_header, "POST", $xml);//prr($response);
110
+ return $response;
111
+ }
112
+
113
+ function setStatus($status) {
114
+ $status_url = $this->base_url . "/v1/people/~/current-status";
115
+ //echo "Setting status...\n";
116
+ $xml = "<current-status>" . htmlspecialchars($status, ENT_NOQUOTES, "UTF-8") . "</current-status>";
117
+ //echo $xml . "\n";
118
+ $request = nsx_trOAuthRequest::from_consumer_and_token($this->consumer, $this->access_token, "PUT", $status_url);
119
+ $request->sign_request($this->signature_method, $this->consumer, $this->access_token);
120
+ $auth_header = $request->to_header("https://api.linkedin.com");
121
+ if ($debug) {
122
+ echo $auth_header . "\n";
123
+ }
124
+ $response = $this->httpRequest($status_url, $auth_header, "PUT", $xml); // prr($response);
125
+ return $response;
126
+ }
127
+
128
+ # Parameters should be a query string starting with "?"
129
+ # Example search("?count=10&start=10&company=LinkedIn");
130
+ function search($parameters) {
131
+ $search_url = $this->base_url . "/v1/people/" . $parameters;
132
+ echo "Performing search for: " . $parameters . "\n";
133
+ $request = nsx_trOAuthRequest::from_consumer_and_token($this->consumer, $this->access_token, "GET", $search_url);
134
+ $request->sign_request($this->signature_method, $this->consumer, $this->access_token);
135
+ $auth_header = $request->to_header("https://api.linkedin.com");
136
+ if ($debug) {
137
+ echo $request->get_signature_base_string() . "\n";
138
+ echo $auth_header . "\n";
139
+ }
140
+ $response = $this->httpRequest($search_url, $auth_header, "GET");
141
+ return $response;
142
+ }
143
+
144
+ function getCurrentShare($parameters='') {
145
+ $search_url = $this->base_url . "/v1/people/~/current-share";
146
+ $request = nsx_trOAuthRequest::from_consumer_and_token($this->consumer, $this->access_token, "GET", $search_url);
147
+ $request->sign_request($this->signature_method, $this->consumer, $this->access_token);
148
+ $auth_header = $request->to_header("https://api.linkedin.com");
149
+ if ($debug) {
150
+ echo $request->get_signature_base_string() . "\n";
151
+ echo $auth_header . "\n";
152
+ }
153
+ $response = $this->httpRequest($search_url, $auth_header, "GET");
154
+ return $response;
155
+ }
156
+
157
+ function httpRequest($url, $auth_header, $method, $body = NULL) { // $this->debug = true; //if (!is_array($auth_header)) $auth_header = array($auth_header);
158
+ if (!is_array($auth_header)) $auth_header = array($auth_header);
159
+ if (!$method) $method = "GET"; $curl = curl_init();
160
+ curl_setopt($curl, CURLOPT_URL, $url);
161
+ curl_setopt($curl, CURLOPT_HEADER, 0);
162
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
163
+ curl_setopt($curl, CURLOPT_HTTPHEADER, $auth_header); // Set the headers.
164
+
165
+ if ($body) { $auth_header[] = "Content-Type: text/xml;charset=utf-8";
166
+ curl_setopt($curl, CURLOPT_POST, 1);
167
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
168
+ curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
169
+ curl_setopt($curl, CURLOPT_HTTPHEADER, $auth_header);
170
+ }
171
+
172
+ $data = curl_exec($curl); $errmsg = curl_error($curl); //prr($data);// die();
173
+
174
+ //## NextScripts Fix
175
+ if (curl_errno($curl) == 60 || stripos($errmsg, 'SSL')!==false) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $data = curl_exec($curl);}
176
+ if (curl_errno($curl) > 0) { $err = curl_errno($curl); $errmsg = curl_error($curl); prr($errmsg); prr($err);}
177
+ //## /NextScripts Fix
178
+ $header = curl_getinfo($curl); curl_close($curl);// prr($header);
179
+
180
+ if ($this->debug) echo $data . "\n";
181
+ if (trim($data)=='' && ($header['http_code']=='201' || $header['http_code']=='200' || $header['http_code']=='202')) $data = '201';
182
+ return $data;
183
+ }
184
+
185
  }
inc-cl/apis/plurkOAuth.php CHANGED
@@ -1,203 +1,203 @@
1
- <?php
2
-
3
- define('PLURK_ACCESS_TOKEN_PATH', "/OAuth/access_token");
4
- define('PLURK_AUTHORIZE_PATH', "/OAuth/authorize");
5
- define('PLURK_REQUEST_TOKEN_PATH', "/OAuth/request_token");
6
-
7
- abstract class nxspk_SignatureMethod
8
- {
9
- abstract public function signing_base($request, $consumer, $token);
10
- abstract public function sign($request, $consumer, $token);
11
- public function check($request, $consumer, $token, $signature) {
12
- $built = $this->sign($request, $consumer, $token);
13
- return $built == $signature;
14
- }
15
- }
16
-
17
- class nxspk_SigMethod_HMAC_SHA1 extends nxspk_SignatureMethod {
18
- public $name = 'HMAC-SHA1';
19
- public function signing_base($request, $consumer_secret, $token) {
20
- $sig = array(rawurlencode($request['method']), rawurlencode($request['normalized_url']), rawurlencode($request['normalized_parameters']));
21
- $key = sprintf("%s&", rawurlencode($consumer_secret));
22
- if (isset($token)) $key .= rawurlencode($token->secret);
23
- $raw = implode('&', $sig);
24
- return array ($key, $raw);
25
- }
26
- public function sign($request, $consumer_secret, $token) {
27
- $key_raw = $this->signing_base($request, $consumer_secret, $token);// prr($key_raw);
28
- $basestring = base64_encode (hash_hmac('sha1', $key_raw[1], $key_raw[0], true)); //echo $basestring;
29
- return rawurlencode($basestring);
30
- }
31
-
32
- public static function urlencode_rfc3986($input) {
33
- if (is_array($input)) {
34
- return array_map(array('nxspk_SigMethod_HMAC_SHA1', 'urlencode_rfc3986'), $input);
35
- } else if (is_scalar($input)) {
36
- return str_replace(
37
- '+',
38
- ' ',
39
- str_replace('%7E', '~', rawurlencode($input))
40
- );
41
- } else {
42
- return '';
43
- }
44
- }
45
- public function get_normalized_http_url($url) {
46
- $parts = parse_url($url);
47
-
48
- $port = @$parts['port'];
49
- $scheme = $parts['scheme'];
50
- $host = $parts['host'];
51
- $path = @$parts['path'];
52
-
53
- $port or $port = ($scheme == 'https') ? '443' : '80';
54
-
55
- if (($scheme == 'https' && $port != '443')|| ($scheme == 'http' && $port != '80')) {
56
- $host = "$host:$port";
57
- }
58
- return "$scheme://$host$path";
59
- }
60
- public function get_signature_base_string($url, $params) {
61
- $parts = array( 'GET', $this->get_normalized_http_url($url), $params); //prr($parts);
62
- $parts = $this->urlencode_rfc3986($parts);
63
- return implode('&', $parts);
64
- }
65
-
66
- public function sign2($request, $consumer_secret, $token){
67
-
68
- $base_string = $this->get_signature_base_string($request['normalized_url'], $request['normalized_parameters']);
69
- //$request->base_string = $base_string;
70
-
71
- //$key_parts = array( $consumer_secret); if ($token) $key_parts[] = $token->secret;
72
- $key_parts = array( $consumer_secret, ($token) ? $token : "");
73
-
74
- //$key_parts = array( $consumer_secret, "");
75
-
76
- $key_parts = $this->urlencode_rfc3986($key_parts);
77
- $key = implode('&', $key_parts); //prr($key); prr($base_string);
78
- return rawurlencode(base64_encode(hash_hmac('sha1', $base_string, $key, true)));
79
- }
80
-
81
-
82
- public function check($request, $consumer_secret, $token, $signature) {
83
- $built = $this->sign($request, $consumer_secret, $token);
84
- return $built == $signature;
85
- }
86
- }
87
-
88
- class wpPlurkOAuth{
89
- public $baseURL = 'http://www.plurk.com';
90
- public $http_code;
91
- protected $version = '1.0';
92
- protected $sign_method;
93
- protected $request_token;
94
- protected $access_token;
95
- protected $access_secret;
96
- protected $consumer_key;
97
- protected $consumer_secret;
98
-
99
- function __construct($consumer_key, $consumer_secret, $access_token = NULL, $access_secret = NULL) {
100
- $this->sign_method = new nxspk_SigMethod_HMAC_SHA1();
101
- $this->consumer_key = $consumer_key; $this->consumer_secret = $consumer_secret;
102
- $this->access_token = $access_token; $this->access_secret = $access_secret;
103
- // if (!empty($access_token) && !empty($access_secret)) $this->authorize($access_token, $access_secret);
104
- }
105
-
106
- function get_normalized_parameters($params) { $items = array();
107
- foreach ($params as $key => $value) {
108
- if ($key == 'oauth_signature') continue;
109
- if (is_array($value)) $mtems = array_merge($value, $items); else $items[$key] = $value;
110
- }
111
- ksort($items);
112
- $item_parts = array();
113
- foreach ($items as $key => $value) {
114
- $item_parts[] =
115
- sprintf("%s=%s",rawurlencode($key),rawurlencode($value));
116
- }
117
- return implode('&', $item_parts);
118
- }
119
- function genRndString($length = 8) { $chars = '0123456789abcdefghijklmnopqrstuvwxyz'; $string = '';
120
- for ($p = 0; $p < $length; $p++) $string .= $chars[mt_rand(0, strlen($chars))];
121
- return $string;
122
- }
123
- function makeHTTPHeaders($ref, $post=false){ $hdrsArr = array();
124
- $hdrsArr['X-Requested-With']='XMLHttpRequest'; $hdrsArr['Connection']='keep-alive'; $hdrsArr['Referer']=$ref;
125
- $hdrsArr['User-Agent']='Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.22 Safari/537.11';
126
- if($post) $hdrsArr['Content-Type']='application/x-www-form-urlencoded';
127
- $hdrsArr['Accept']='application/json, text/javascript, */*; q=0.01';
128
- $hdrsArr['Accept-Encoding']='gzip,deflate,sdch'; $hdrsArr['Accept-Language']='en-US,en;q=0.8'; $hdrsArr['Accept-Charset']='ISO-8859-1,utf-8;q=0.7,*;q=0.3'; return $hdrsArr;
129
- }
130
-
131
- function oAuthRespToArr($str){ $arr = explode('&', $str); $out = array();
132
- foreach ($arr as $ar) { $strr = explode('=', $ar); $out[$strr[0]] = $strr[1];} return $out;
133
- }
134
-
135
- function getReqToken($cbu){
136
- $args = array (
137
- 'oauth_consumer_key' => $this->consumer_key,
138
- 'oauth_timestamp' => time(),
139
- 'oauth_nonce' => $this->genRndString(),
140
- 'oauth_version' => $this->version,
141
- 'oauth_callback' => $cbu,
142
- 'oauth_signature_method' => 'HMAC-SHA1'
143
-
144
- );
145
- $req = array(); $req['method'] = 'GET';
146
- $req['normalized_url'] = $this->baseURL.PLURK_REQUEST_TOKEN_PATH;
147
- $req['normalized_parameters'] = $this->get_normalized_parameters($args);
148
- $args['oauth_signature'] = $this->sign_method->sign2($req, $this->consumer_secret, $token);
149
- $cbu = nxspk_SigMethod_HMAC_SHA1::urlencode_rfc3986($cbu);
150
- $url = $this->baseURL.PLURK_REQUEST_TOKEN_PATH.'?oauth_nonce='.$args['oauth_nonce'].'&oauth_timestamp='.$args['oauth_timestamp'].'&oauth_consumer_key='.$this->consumer_key.'&oauth_signature_method='.$args['oauth_signature_method'].'&oauth_version='.$args['oauth_version'].'&oauth_callback='.$cbu.'&oauth_signature='.$args['oauth_signature'];
151
- echo "<br/>REQ Token URL: ".$url."<br/>";
152
- $hdrsArr = $this->makeHTTPHeaders($url); $ckArr = $nxs_vbCkArray;
153
- $response = wp_remote_get($url, array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'cookies' => $ckArr));
154
- $this->http_code = $response['response']['code']; // prr($response);
155
- if (stripos($response['body'],'oauth_token_secret=')===false) echo 'Bad oAuth Login:'.$response['body']; else return $this->oAuthRespToArr($response['body']);
156
- }
157
- function getAccToken($verifier){
158
- $args = array (
159
- 'oauth_token' => $this->access_token,
160
- 'oauth_token_secret' => $this->access_secret,
161
- 'oauth_timestamp' => time(),
162
- 'oauth_nonce' => $this->genRndString(),
163
- 'oauth_version' => $this->version,
164
- 'oauth_consumer_key' => $this->consumer_key,
165
- 'oauth_verifier' => $verifier,
166
- 'oauth_signature_method' => 'HMAC-SHA1'
167
- );
168
- $req = array(); $req['method'] = 'GET'; $req['normalized_url'] = $this->baseURL.PLURK_ACCESS_TOKEN_PATH; // echo "ARGS:"; prr($args);
169
- $req['normalized_parameters'] = $this->get_normalized_parameters($args);
170
- $args['oauth_signature'] = $this->sign_method->sign2($req, $this->consumer_secret, $this->access_secret);
171
- $url = $this->baseURL.PLURK_ACCESS_TOKEN_PATH.'?oauth_nonce='.$args['oauth_nonce'].'&oauth_timestamp='.$args['oauth_timestamp'].'&oauth_token_secret='.$this->access_secret.'&oauth_signature_method='.$args['oauth_signature_method'].'&oauth_consumer_key='.$this->consumer_key.'&oauth_verifier='.$verifier.'&oauth_version='.$args['oauth_version'].'&oauth_token='.$this->access_token.'&oauth_signature='.$args['oauth_signature'];
172
- echo "<br/>REQ Token URL: ".$url."<br/>";
173
- $hdrsArr = $this->makeHTTPHeaders($url); $ckArr = $nxs_vbCkArray;
174
- $response = wp_remote_get($url, array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'cookies' => $ckArr));
175
- if ( is_wp_error($response) ) return $response;
176
- $this->http_code = $response['response']['code'];
177
- if (stripos($response['body'],'oauth_token_secret=')===false) echo 'Bad oAuth Login:'.$response['body']; else return $this->oAuthRespToArr($response['body']);
178
- }
179
- function makeReq($url, $params){
180
- $args = array (
181
- 'oauth_token' => $this->access_token,
182
- 'oauth_token_secret' => $this->access_secret,
183
- 'oauth_consumer_key' => $this->consumer_key,
184
- 'oauth_timestamp' => time(),
185
- 'oauth_nonce' => $this->genRndString(),
186
- 'oauth_version' => $this->version,
187
- 'oauth_signature_method' => 'HMAC-SHA1'
188
- );
189
- if (is_array($params)) { $argsTS = array_merge($args, $params);} else $argsTS = $args;
190
- $req = array(); $req['method'] = 'GET'; $req['normalized_url'] = $url;
191
- $req['normalized_parameters'] = $this->get_normalized_parameters($argsTS);
192
- $args['oauth_signature'] = $this->sign_method->sign2($req, $this->consumer_secret, $this->access_secret);
193
- if (is_array($params)) { $params = nxspk_SigMethod_HMAC_SHA1::urlencode_rfc3986($params); $args = array_merge($args, $params);} //prr($args);
194
- $argsStr = ''; $argsT = array(); foreach ($args as $arN=>$arV){$argsT[] = $arN.'='.$arV;} $argsStr = implode('&', $argsT); $url .= '?'.$argsStr;
195
- $hdrsArr = $this->makeHTTPHeaders($url); $ckArr = $nxs_vbCkArray;
196
- $response = wp_remote_get($url, array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'cookies' => $ckArr)); // prr($response);
197
- if ( is_wp_error($response) ) return $response;
198
- $this->http_code = $response['response']['code'];
199
- return json_decode($response['body'], true);
200
- }
201
-
202
- }
203
- ?>
1
+ <?php
2
+
3
+ define('PLURK_ACCESS_TOKEN_PATH', "/OAuth/access_token");
4
+ define('PLURK_AUTHORIZE_PATH', "/OAuth/authorize");
5
+ define('PLURK_REQUEST_TOKEN_PATH', "/OAuth/request_token");
6
+
7
+ abstract class nxspk_SignatureMethod
8
+ {
9
+ abstract public function signing_base($request, $consumer, $token);
10
+ abstract public function sign($request, $consumer, $token);
11
+ public function check($request, $consumer, $token, $signature) {
12
+ $built = $this->sign($request, $consumer, $token);
13
+ return $built == $signature;
14
+ }
15
+ }
16
+
17
+ class nxspk_SigMethod_HMAC_SHA1 extends nxspk_SignatureMethod {
18
+ public $name = 'HMAC-SHA1';
19
+ public function signing_base($request, $consumer_secret, $token) {
20
+ $sig = array(rawurlencode($request['method']), rawurlencode($request['normalized_url']), rawurlencode($request['normalized_parameters']));
21
+ $key = sprintf("%s&", rawurlencode($consumer_secret));
22
+ if (isset($token)) $key .= rawurlencode($token->secret);
23
+ $raw = implode('&', $sig);
24
+ return array ($key, $raw);
25
+ }
26
+ public function sign($request, $consumer_secret, $token) {
27
+ $key_raw = $this->signing_base($request, $consumer_secret, $token);// prr($key_raw);
28
+ $basestring = base64_encode (hash_hmac('sha1', $key_raw[1], $key_raw[0], true)); //echo $basestring;
29
+ return rawurlencode($basestring);
30
+ }
31
+
32
+ public static function urlencode_rfc3986($input) {
33
+ if (is_array($input)) {
34
+ return array_map(array('nxspk_SigMethod_HMAC_SHA1', 'urlencode_rfc3986'), $input);
35
+ } else if (is_scalar($input)) {
36
+ return str_replace(
37
+ '+',
38
+ ' ',
39
+ str_replace('%7E', '~', rawurlencode($input))
40
+ );
41
+ } else {
42
+ return '';
43
+ }
44
+ }
45
+ public function get_normalized_http_url($url) {
46
+ $parts = parse_url($url);
47
+
48
+ $port = @$parts['port'];
49
+ $scheme = $parts['scheme'];
50
+ $host = $parts['host'];
51
+ $path = @$parts['path'];
52
+
53
+ $port or $port = ($scheme == 'https') ? '443' : '80';
54
+
55
+ if (($scheme == 'https' && $port != '443')|| ($scheme == 'http' && $port != '80')) {
56
+ $host = "$host:$port";
57
+ }
58
+ return "$scheme://$host$path";
59
+ }
60
+ public function get_signature_base_string($url, $params) {
61
+ $parts = array( 'GET', $this->get_normalized_http_url($url), $params); //prr($parts);
62
+ $parts = $this->urlencode_rfc3986($parts);
63
+ return implode('&', $parts);
64
+ }
65
+
66
+ public function sign2($request, $consumer_secret, $token){
67
+
68
+ $base_string = $this->get_signature_base_string($request['normalized_url'], $request['normalized_parameters']);
69
+ //$request->base_string = $base_string;
70
+
71
+ //$key_parts = array( $consumer_secret); if ($token) $key_parts[] = $token->secret;
72
+ $key_parts = array( $consumer_secret, ($token) ? $token : "");
73
+
74
+ //$key_parts = array( $consumer_secret, "");
75
+
76
+ $key_parts = $this->urlencode_rfc3986($key_parts);
77
+ $key = implode('&', $key_parts); //prr($key); prr($base_string);
78
+ return rawurlencode(base64_encode(hash_hmac('sha1', $base_string, $key, true)));
79
+ }
80
+
81
+
82
+ public function check($request, $consumer_secret, $token, $signature) {
83
+ $built = $this->sign($request, $consumer_secret, $token);
84
+ return $built == $signature;
85
+ }
86
+ }
87
+
88
+ class wpPlurkOAuth{
89
+ public $baseURL = 'http://www.plurk.com';
90
+ public $http_code;
91
+ protected $version = '1.0';
92
+ protected $sign_method;
93
+ protected $request_token;
94
+ protected $access_token;
95
+ protected $access_secret;
96
+ protected $consumer_key;
97
+ protected $consumer_secret;
98
+
99
+ function __construct($consumer_key, $consumer_secret, $access_token = NULL, $access_secret = NULL) {
100
+ $this->sign_method = new nxspk_SigMethod_HMAC_SHA1();
101
+ $this->consumer_key = $consumer_key; $this->consumer_secret = $consumer_secret;
102
+ $this->access_token = $access_token; $this->access_secret = $access_secret;
103
+ // if (!empty($access_token) && !empty($access_secret)) $this->authorize($access_token, $access_secret);
104
+ }
105
+
106
+ function get_normalized_parameters($params) { $items = array();
107
+ foreach ($params as $key => $value) {
108
+ if ($key == 'oauth_signature') continue;
109
+ if (is_array($value)) $mtems = array_merge($value, $items); else $items[$key] = $value;
110
+ }
111
+ ksort($items);
112
+ $item_parts = array();
113
+ foreach ($items as $key => $value) {
114
+ $item_parts[] =
115
+ sprintf("%s=%s",rawurlencode($key),rawurlencode($value));
116
+ }
117
+ return implode('&', $item_parts);
118
+ }
119
+ function genRndString($length = 8) { $chars = '0123456789abcdefghijklmnopqrstuvwxyz'; $string = '';
120
+ for ($p = 0; $p < $length; $p++) $string .= $chars[mt_rand(0, strlen($chars))];
121
+ return $string;
122
+ }
123
+ function makeHTTPHeaders($ref, $post=false){ $hdrsArr = array();
124
+ $hdrsArr['X-Requested-With']='XMLHttpRequest'; $hdrsArr['Connection']='keep-alive'; $hdrsArr['Referer']=$ref;
125
+ $hdrsArr['User-Agent']='Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.22 Safari/537.11';
126
+ if($post) $hdrsArr['Content-Type']='application/x-www-form-urlencoded';
127
+ $hdrsArr['Accept']='application/json, text/javascript, */*; q=0.01';
128
+ $hdrsArr['Accept-Encoding']='gzip,deflate,sdch'; $hdrsArr['Accept-Language']='en-US,en;q=0.8'; $hdrsArr['Accept-Charset']='ISO-8859-1,utf-8;q=0.7,*;q=0.3'; return $hdrsArr;
129
+ }
130
+
131
+ function oAuthRespToArr($str){ $arr = explode('&', $str); $out = array();
132
+ foreach ($arr as $ar) { $strr = explode('=', $ar); $out[$strr[0]] = $strr[1];} return $out;
133
+ }
134
+
135
+ function getReqToken($cbu){
136
+ $args = array (
137
+ 'oauth_consumer_key' => $this->consumer_key,
138
+ 'oauth_timestamp' => time(),
139
+ 'oauth_nonce' => $this->genRndString(),
140
+ 'oauth_version' => $this->version,
141
+ 'oauth_callback' => $cbu,
142
+ 'oauth_signature_method' => 'HMAC-SHA1'
143
+
144
+ );
145
+ $req = array(); $req['method'] = 'GET';
146
+ $req['normalized_url'] = $this->baseURL.PLURK_REQUEST_TOKEN_PATH;
147
+ $req['normalized_parameters'] = $this->get_normalized_parameters($args);
148
+ $args['oauth_signature'] = $this->sign_method->sign2($req, $this->consumer_secret, $token);
149
+ $cbu = nxspk_SigMethod_HMAC_SHA1::urlencode_rfc3986($cbu);
150
+ $url = $this->baseURL.PLURK_REQUEST_TOKEN_PATH.'?oauth_nonce='.$args['oauth_nonce'].'&oauth_timestamp='.$args['oauth_timestamp'].'&oauth_consumer_key='.$this->consumer_key.'&oauth_signature_method='.$args['oauth_signature_method'].'&oauth_version='.$args['oauth_version'].'&oauth_callback='.$cbu.'&oauth_signature='.$args['oauth_signature'];
151
+ echo "<br/>REQ Token URL: ".$url."<br/>";
152
+ $hdrsArr = $this->makeHTTPHeaders($url); $ckArr = $nxs_vbCkArray;
153
+ $response = wp_remote_get($url, array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'cookies' => $ckArr));
154
+ $this->http_code = $response['response']['code']; // prr($response);
155
+ if (stripos($response['body'],'oauth_token_secret=')===false) echo 'Bad oAuth Login:'.$response['body']; else return $this->oAuthRespToArr($response['body']);
156
+ }
157
+ function getAccToken($verifier){
158
+ $args = array (
159
+ 'oauth_token' => $this->access_token,
160
+ 'oauth_token_secret' => $this->access_secret,
161
+ 'oauth_timestamp' => time(),
162
+ 'oauth_nonce' => $this->genRndString(),
163
+ 'oauth_version' => $this->version,
164
+ 'oauth_consumer_key' => $this->consumer_key,
165
+ 'oauth_verifier' => $verifier,
166
+ 'oauth_signature_method' => 'HMAC-SHA1'
167
+ );
168
+ $req = array(); $req['method'] = 'GET'; $req['normalized_url'] = $this->baseURL.PLURK_ACCESS_TOKEN_PATH; // echo "ARGS:"; prr($args);
169
+ $req['normalized_parameters'] = $this->get_normalized_parameters($args);
170
+ $args['oauth_signature'] = $this->sign_method->sign2($req, $this->consumer_secret, $this->access_secret);
171
+ $url = $this->baseURL.PLURK_ACCESS_TOKEN_PATH.'?oauth_nonce='.$args['oauth_nonce'].'&oauth_timestamp='.$args['oauth_timestamp'].'&oauth_token_secret='.$this->access_secret.'&oauth_signature_method='.$args['oauth_signature_method'].'&oauth_consumer_key='.$this->consumer_key.'&oauth_verifier='.$verifier.'&oauth_version='.$args['oauth_version'].'&oauth_token='.$this->access_token.'&oauth_signature='.$args['oauth_signature'];
172
+ echo "<br/>REQ Token URL: ".$url."<br/>";
173
+ $hdrsArr = $this->makeHTTPHeaders($url); $ckArr = $nxs_vbCkArray;
174
+ $response = wp_remote_get($url, array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'cookies' => $ckArr));
175
+ if ( is_wp_error($response) ) return $response;
176
+ $this->http_code = $response['response']['code'];
177
+ if (stripos($response['body'],'oauth_token_secret=')===false) echo 'Bad oAuth Login:'.$response['body']; else return $this->oAuthRespToArr($response['body']);
178
+ }
179
+ function makeReq($url, $params){
180
+ $args = array (
181
+ 'oauth_token' => $this->access_token,
182
+ 'oauth_token_secret' => $this->access_secret,
183
+ 'oauth_consumer_key' => $this->consumer_key,
184
+ 'oauth_timestamp' => time(),
185
+ 'oauth_nonce' => $this->genRndString(),
186
+ 'oauth_version' => $this->version,
187
+ 'oauth_signature_method' => 'HMAC-SHA1'
188
+ );
189
+ if (is_array($params)) { $argsTS = array_merge($args, $params);} else $argsTS = $args;
190
+ $req = array(); $req['method'] = 'GET'; $req['normalized_url'] = $url;
191
+ $req['normalized_parameters'] = $this->get_normalized_parameters($argsTS);
192
+ $args['oauth_signature'] = $this->sign_method->sign2($req, $this->consumer_secret, $this->access_secret);
193
+ if (is_array($params)) { $params = nxspk_SigMethod_HMAC_SHA1::urlencode_rfc3986($params); $args = array_merge($args, $params);} //prr($args);
194
+ $argsStr = ''; $argsT = array(); foreach ($args as $arN=>$arV){$argsT[] = $arN.'='.$arV;} $argsStr = implode('&', $argsT); $url .= '?'.$argsStr;
195
+ $hdrsArr = $this->makeHTTPHeaders($url); $ckArr = $nxs_vbCkArray;
196
+ $response = wp_remote_get($url, array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'cookies' => $ckArr)); // prr($response);
197
+ if ( is_wp_error($response) ) return $response;
198
+ $this->http_code = $response['response']['code'];
199
+ return json_decode($response['body'], true);
200
+ }
201
+
202
+ }
203
+ ?>
inc-cl/apis/tmhOAuth.php CHANGED
@@ -1,656 +1,656 @@
1
- <?php
2
- /**
3
- * tmhOAuth
4
- *
5
- * An OAuth 1.0A library written in PHP.
6
- * The library supports file uploading using multipart/form as well as general
7
- * REST requests. OAuth authentication is sent using the an Authorization Header.
8
- *
9
- * @author themattharris
10
- * @version 0.61
11
- *
12
- * 16 January 2012
13
- */
14
- class NXS_tmhOAuth {
15
- const VERSION = 0.61;
16
-
17
- /**
18
- * Creates a new tmhOAuth object
19
- *
20
- * @param string $config, the configuration to use for this request
21
- */
22
- function __construct($config) {
23
- $this->params = array();
24
- $this->headers = array();
25
- $this->auto_fixed_time = false;
26
- $this->buffer = null;
27
-
28
- // default configuration options
29
- $this->config = array_merge(
30
- array(
31
- // leave 'user_agent' blank for default, otherwise set this to
32
- // something that clearly identifies your app
33
- 'user_agent' => '',
34
-
35
- 'use_ssl' => false,
36
- 'host' => 'api.twitter.com',
37
-
38
- 'consumer_key' => '',
39
- 'consumer_secret' => '',
40
- 'user_token' => '',
41
- 'user_secret' => '',
42
- 'force_nonce' => false,
43
- 'nonce' => false, // used for checking signatures. leave as false for auto
44
- 'force_timestamp' => false,
45
- 'timestamp' => false, // used for checking signatures. leave as false for auto
46
-
47
- // oauth signing variables that are not dynamic
48
- 'oauth_version' => '1.0',
49
- 'oauth_signature_method' => 'HMAC-SHA1',
50
-
51
- // you probably don't want to change any of these curl values
52
- 'curl_connecttimeout' => 30,
53
- 'curl_timeout' => 10,
54
-
55
- // for security this should always be set to 2.
56
- 'curl_ssl_verifyhost' => 2,
57
- // for security this should always be set to true.
58
- 'curl_ssl_verifypeer' => true,
59
-
60
- // you can get the latest cacert.pem from here http://curl.haxx.se/ca/cacert.pem
61
- 'curl_cainfo' => dirname(__FILE__) . '/cacert.pem',
62
- 'curl_capath' => dirname(__FILE__),
63
-
64
- 'curl_followlocation' => false, // whether to follow redirects or not
65
-
66
- // support for proxy servers
67
- 'curl_proxy' => false, // really you don't want to use this if you are using streaming
68
- 'curl_proxyuserpwd' => false, // format username:password for proxy, if required
69
- 'curl_encoding' => '', // leave blank for all supported formats, else use gzip, deflate, identity
70
-
71
- // streaming API
72
- 'is_streaming' => false,
73
- 'streaming_eol' => "\r\n",
74
- 'streaming_metrics_interval' => 60,
75
-
76
- // header or querystring. You should always use header!
77
- // this is just to help me debug other developers implementations
78
- 'as_header' => true,
79
- 'debug' => false,
80
- ),
81
- $config
82
- );
83
- $this->set_user_agent();
84
- }
85
-
86
- function set_user_agent() {
87
- if (!empty($this->config['user_agent']))
88
- return;
89
-
90
- if ($this->config['curl_ssl_verifyhost'] && $this->config['curl_ssl_verifypeer']) {
91
- $ssl = '+SSL';
92
- } else {
93
- $ssl = '-SSL';
94
- }
95
-
96
- $ua = 'tmhOAuth ' . self::VERSION . $ssl . ' - //github.com/themattharris/tmhOAuth';
97
- $this->config['user_agent'] = $ua;
98
- }
99
-
100
- /**
101
- * Generates a random OAuth nonce.
102
- * If 'force_nonce' is true a nonce is not generated and the value in the configuration will be retained.
103
- *
104
- * @param string $length how many characters the nonce should be before MD5 hashing. default 12
105
- * @param string $include_time whether to include time at the beginning of the nonce. default true
106
- * @return void
107
- */
108
- private function create_nonce($length=12, $include_time=true) {
109
- if ($this->config['force_nonce'] == false) {
110
- $sequence = array_merge(range(0,9), range('A','Z'), range('a','z'));
111
- $length = $length > count($sequence) ? count($sequence) : $length;
112
- shuffle($sequence);
113
-
114
- $prefix = $include_time ? microtime() : '';
115
- $this->config['nonce'] = md5(substr($prefix . implode('', $sequence), 0, $length));
116
- }
117
- }
118
-
119
- /**
120
- * Generates a timestamp.
121
- * If 'force_timestamp' is true a nonce is not generated and the value in the configuration will be retained.
122
- *
123
- * @return void
124
- */
125
- private function create_timestamp() {
126
- $this->config['timestamp'] = ($this->config['force_timestamp'] == false ? time() : $this->config['timestamp']); //echo "#### ".$this->config['timestamp'];// prr($this->config);
127
- }
128
-
129
- /**
130
- * Encodes the string or array passed in a way compatible with OAuth.
131
- * If an array is passed each array value will will be encoded.
132
- *
133
- * @param mixed $data the scalar or array to encode
134
- * @return $data encoded in a way compatible with OAuth
135
- */
136
- private function safe_encode($data) {
137
- if (is_array($data)) {
138
- return array_map(array($this, 'safe_encode'), $data);
139
- } else if (is_scalar($data)) {
140
- return str_ireplace(
141
- array('+', '%7E'),
142
- array(' ', '~'),
143
- rawurlencode($data)
144
- );
145
- } else {
146
- return '';
147
- }
148
- }
149
-
150
- /**
151
- * Decodes the string or array from it's URL encoded form
152
- * If an array is passed each array value will will be decoded.
153
- *
154
- * @param mixed $data the scalar or array to decode
155
- * @return $data decoded from the URL encoded form
156
- */
157
- private function safe_decode($data) {
158
- if (is_array($data)) {
159
- return array_map(array($this, 'safe_decode'), $data);
160
- } else if (is_scalar($data)) {
161
- return rawurldecode($data);
162
- } else {
163
- return '';
164
- }
165
- }
166
-
167
- /**
168
- * Returns an array of the standard OAuth parameters.
169
- *
170
- * @return array all required OAuth parameters, safely encoded
171
- */
172
- private function get_defaults() {
173
- $defaults = array(
174
- 'oauth_version' => $this->config['oauth_version'],
175
- 'oauth_nonce' => $this->config['nonce'],
176
- 'oauth_timestamp' => $this->config['timestamp'],
177
- 'oauth_consumer_key' => $this->config['consumer_key'],
178
- 'oauth_signature_method' => $this->config['oauth_signature_method'],
179
- );
180
-
181
- // include the user token if it exists
182
- if ( $this->config['user_token'] )
183
- $defaults['oauth_token'] = $this->config['user_token'];
184
-
185
- // safely encode
186
- foreach ($defaults as $k => $v) {
187
- $_defaults[$this->safe_encode($k)] = $this->safe_encode($v);
188
- }
189
-
190
- return $_defaults;
191
- }
192
-
193
- /**
194
- * Extracts and decodes OAuth parameters from the passed string
195
- *
196
- * @param string $body the response body from an OAuth flow method
197
- * @return array the response body safely decoded to an array of key => values
198
- */
199
- function extract_params($body) {
200
- $kvs = explode('&', $body);
201
- $decoded = array();
202
- foreach ($kvs as $kv) {
203
- $kv = explode('=', $kv, 2);
204
- $kv[0] = $this->safe_decode($kv[0]);
205
- $kv[1] = $this->safe_decode($kv[1]);
206
- $decoded[$kv[0]] = $kv[1];
207
- }
208
- return $decoded;
209
- }
210
-
211
- /**
212
- * Prepares the HTTP method for use in the base string by converting it to
213
- * uppercase.
214
- *
215
- * @param string $method an HTTP method such as GET or POST
216
- * @return void value is stored to a class variable
217
- * @author themattharris
218
- */
219
- private function prepare_method($method) {
220
- $this->method = strtoupper($method);
221
- }
222
-
223
- /**
224
- * Prepares the URL for use in the base string by ripping it apart and
225
- * reconstructing it.
226
- *
227
- * Ref: 3.4.1.2
228
- *
229
- * @param string $url the request URL
230
- * @return void value is stored to a class variable
231
- * @author themattharris
232
- */
233
- private function prepare_url($url) {
234
- $parts = parse_url($url);
235
-
236
- $port = isset($parts['port']) ? $parts['port'] : false;
237
- $scheme = $parts['scheme'];
238
- $host = $parts['host'];
239
- $path = isset($parts['path']) ? $parts['path'] : false;
240
-
241
- $port or $port = ($scheme == 'https') ? '443' : '80';
242
-
243
- if (($scheme == 'https' && $port != '443')
244
- || ($scheme == 'http' && $port != '80')) {
245
- $host = "$host:$port";
246
- }
247
- $this->url = strtolower("$scheme://$host$path");
248
- }
249
-
250
- /**
251
- * Prepares all parameters for the base string and request.
252
- * Multipart parameters are ignored as they are not defined in the specification,
253
- * all other types of parameter are encoded for compatibility with OAuth.
254
- *
255
- * @param array $params the parameters for the request
256
- * @return void prepared values are stored in class variables
257
- */
258
- private function prepare_params($params) {
259
- // do not encode multipart parameters, leave them alone
260
- if ($this->config['multipart']) {
261
- $this->request_params = $params;
262
- $params = array();
263
- }
264
-
265
- // signing parameters are request parameters + OAuth default parameters
266
- $this->signing_params = array_merge($this->get_defaults(), (array)$params);
267
-
268
- // Remove oauth_signature if present
269
- // Ref: Spec: 9.1.1 ("The oauth_signature parameter MUST be excluded.")
270
- if (isset($this->signing_params['oauth_signature'])) {
271
- unset($this->signing_params['oauth_signature']);
272
- }
273
-
274
- // Parameters are sorted by name, using lexicographical byte value ordering.
275
- // Ref: Spec: 9.1.1 (1)
276
- uksort($this->signing_params, 'strcmp');
277
-
278
- // encode. Also sort the signed parameters from the POST parameters
279
- foreach ($this->signing_params as $k => $v) {
280
- $k = $this->safe_encode($k);
281
- $v = $this->safe_encode($v);
282
- $_signing_params[$k] = $v;
283
- $kv[] = "{$k}={$v}";
284
- }
285
-
286
- // auth params = the default oauth params which are present in our collection of signing params
287
- $this->auth_params = array_intersect_key($this->get_defaults(), $_signing_params);
288
- if (isset($_signing_params['oauth_callback'])) {
289
- $this->auth_params['oauth_callback'] = $_signing_params['oauth_callback'];
290
- unset($_signing_params['oauth_callback']);
291
- }
292
-
293
- if (isset($_signing_params['oauth_verifier'])) {
294
- $this->auth_params['oauth_verifier'] = $_signing_params['oauth_verifier'];
295
- unset($_signing_params['oauth_verifier']);
296
- }
297
-
298
- // request_params is already set if we're doing multipart, if not we need to set them now
299
- if ( ! $this->config['multipart'])
300
- $this->request_params = array_diff_key($_signing_params, $this->get_defaults());
301
-
302
- // create the parameter part of the base string
303
- $this->signing_params = implode('&', $kv);
304
- }
305
-
306
- /**
307
- * Prepares the OAuth signing key
308
- *
309
- * @return void prepared signing key is stored in a class variables
310
- */
311
- private function prepare_signing_key() {
312
- $this->signing_key = $this->safe_encode($this->config['consumer_secret']) . '&' . $this->safe_encode($this->config['user_secret']);
313
- }
314
-
315
- /**
316
- * Prepare the base string.
317
- * Ref: Spec: 9.1.3 ("Concatenate Request Elements")
318
- *
319
- * @return void prepared base string is stored in a class variables
320
- */
321
- private function prepare_base_string() {
322
- $base = array(
323
- $this->method,
324
- $this->url,
325
- $this->signing_params
326
- );
327
- $this->base_string = implode('&', $this->safe_encode($base));
328
- }
329
-
330
- /**
331
- * Prepares the Authorization header
332
- *
333
- * @return void prepared authorization header is stored in a class variables
334
- */
335
- private function prepare_auth_header() {
336
- $this->headers = array();
337
- uksort($this->auth_params, 'strcmp');
338
- if (!$this->config['as_header']) :
339
- $this->request_params = array_merge($this->request_params, $this->auth_params);
340
- return;
341
- endif;
342
-
343
- foreach ($this->auth_params as $k => $v) {
344
- $kv[] = "{$k}=\"{$v}\"";
345
- }
346
- $this->auth_header = 'OAuth ' . implode(', ', $kv);
347
- $this->headers['Authorization'] = $this->auth_header;
348
- }
349
-
350
- /**
351
- * Signs the request and adds the OAuth signature. This runs all the request
352
- * parameter preparation methods.
353
- *
354
- * @param string $method the HTTP method being used. e.g. POST, GET, HEAD etc
355
- * @param string $url the request URL without query string parameters
356
- * @param array $params the request parameters as an array of key=value pairs
357
- * @param string $useauth whether to use authentication when making the request.
358
- */
359
- private function sign($method, $url, $params, $useauth) {
360
- $this->prepare_method($method);
361
- $this->prepare_url($url);
362
- $this->prepare_params($params);
363
-
364
- // we don't sign anything is we're not using auth
365
- if ($useauth) {
366
- $this->prepare_base_string();
367
- $this->prepare_signing_key();
368
-
369
- $this->auth_params['oauth_signature'] = $this->safe_encode(
370
- base64_encode(
371
- hash_hmac(
372
- 'sha1', $this->base_string, $this->signing_key, true
373
- )));
374
-
375
- $this->prepare_auth_header();
376
- }
377
- }
378
-
379
- /**
380
- * Make an HTTP request using this library. This method doesn't return anything.
381
- * Instead the response should be inspected directly.
382
- *
383
- * @param string $method the HTTP method being used. e.g. POST, GET, HEAD etc
384
- * @param string $url the request URL without query string parameters
385
- * @param array $params the request parameters as an array of key=value pairs
386
- * @param string $useauth whether to use authentication when making the request. Default true.
387
- * @param string $multipart whether this request contains multipart data. Default false
388
- */
389
- function request($method, $url, $params=array(), $useauth=true, $multipart=false) {
390
- $this->config['multipart'] = $multipart;
391
-
392
- $this->create_nonce();
393
- $this->create_timestamp();
394
-
395
- $this->sign($method, $url, $params, $useauth);
396
- return $this->curlit();
397
- }
398
-
399
- /**
400
- * Make a long poll HTTP request using this library. This method is
401
- * different to the other request methods as it isn't supposed to disconnect
402
- *
403
- * Using this method expects a callback which will receive the streaming
404
- * responses.
405
- *
406
- * @param string $method the HTTP method being used. e.g. POST, GET, HEAD etc
407
- * @param string $url the request URL without query string parameters
408
- * @param array $params the request parameters as an array of key=value pairs
409
- * @param string $callback the callback function to stream the buffer to.
410
- */
411
- function streaming_request($method, $url, $params=array(), $callback='') {
412
- if ( ! empty($callback) ) {
413
- if ( ! function_exists($callback) ) {
414
- return false;
415
- }
416
- $this->config['streaming_callback'] = $callback;
417
- }
418
- $this->metrics['start'] = time();
419
- $this->metrics['interval_start'] = $this->metrics['start'];
420
- $this->metrics['tweets'] = 0;
421
- $this->metrics['last_tweets'] = 0;
422
- $this->metrics['bytes'] = 0;
423
- $this->metrics['last_bytes'] = 0;
424
- $this->config['is_streaming'] = true;
425
- $this->request($method, $url, $params);
426
- }
427
-
428
- /**
429
- * Handles the updating of the current Streaming API metrics.
430
- */
431
- function update_metrics() {
432
- $now = time();
433
- if (($this->metrics['interval_start'] + $this->config['streaming_metrics_interval']) > $now)
434
- return false;
435
-
436
- $this->metrics['tps'] = round( ($this->metrics['tweets'] - $this->metrics['last_tweets']) / $this->config['streaming_metrics_interval'], 2);
437
- $this->metrics['bps'] = round( ($this->metrics['bytes'] - $this->metrics['last_bytes']) / $this->config['streaming_metrics_interval'], 2);
438
-
439
- $this->metrics['last_bytes'] = $this->metrics['bytes'];
440
- $this->metrics['last_tweets'] = $this->metrics['tweets'];
441
- $this->metrics['interval_start'] = $now;
442
- return $this->metrics;
443
- }
444
-
445
- /**
446
- * Utility function to create the request URL in the requested format
447
- *
448
- * @param string $request the API method without extension
449
- * @param string $format the format of the response. Default json. Set to an empty string to exclude the format
450
- * @return string the concatenation of the host, API version, API method and format
451
- */
452
- function url($request, $format='json') {
453
- $format = strlen($format) > 0 ? ".$format" : '';
454
- $proto = $this->config['use_ssl'] ? 'https:/' : 'http:/';
455
-
456
- // backwards compatibility with v0.1
457
- if (isset($this->config['v']))
458
- $this->config['host'] = $this->config['host'] . '/' . $this->config['v'];
459
-
460
- return implode('/', array(
461
- $proto,
462
- $this->config['host'],
463
- $request . $format
464
- ));
465
- }
466
-
467
- /**
468
- * Public access to the private safe decode/encode methods
469
- *
470
- * @param string $text the text to transform
471
- * @param string $mode the transformation mode. either encode or decode
472
- * @return the string as transformed by the given mode
473
- */
474
- function transformText($text, $mode='encode') {
475
- return $this->{"safe_$mode"}($text);
476
- }
477
-
478
- /**
479
- * Utility function to parse the returned curl headers and store them in the
480
- * class array variable.
481
- *
482
- * @param object $ch curl handle
483
- * @param string $header the response headers
484
- * @return the string length of the header
485
- */
486
- private function curlHeader($ch, $header) {
487
- $i = strpos($header, ':');
488
- if ( ! empty($i) ) {
489
- $key = str_replace('-', '_', strtolower(substr($header, 0, $i)));
490
- $value = trim(substr($header, $i + 2));
491
- $this->response['headers'][$key] = $value;
492
- }
493
- return strlen($header);
494
- }
495
-
496
- /**
497
- * Utility function to parse the returned curl buffer and store them until
498
- * an EOL is found. The buffer for curl is an undefined size so we need
499
- * to collect the content until an EOL is found.
500
- *
501
- * This function calls the previously defined streaming callback method.
502
- *
503
- * @param object $ch curl handle
504
- * @param string $data the current curl buffer
505
- */
506
- private function curlWrite($ch, $data) {
507
- $l = strlen($data);
508
- if (strpos($data, $this->config['streaming_eol']) === false) {
509
- $this->buffer .= $data;
510
- return $l;
511
- }
512
-
513
- $buffered = explode($this->config['streaming_eol'], $data);
514
- $content = $this->buffer . $buffered[0];
515
-
516
- $this->metrics['tweets']++;
517
- $this->metrics['bytes'] += strlen($content);
518
-
519
- if ( ! function_exists($this->config['streaming_callback']))
520
- return 0;
521
-
522
- $metrics = $this->update_metrics();
523
- $stop = call_user_func(
524
- $this->config['streaming_callback'],
525
- $content,
526
- strlen($content),
527
- $metrics
528
- );
529
- $this->buffer = $buffered[1];
530
- if ($stop)
531
- return 0;
532
-
533
- return $l;
534
- }
535
-
536
- /**
537
- * Makes a curl request. Takes no parameters as all should have been prepared
538
- * by the request method
539
- *
540
- * @return void response data is stored in the class variable 'response'
541
- */
542
- private function curlit() {
543
- // method handling
544
- switch ($this->method) {
545
- case 'POST':
546
- break;
547
- default:
548
- // GET, DELETE request so convert the parameters to a querystring
549
- if ( ! empty($this->request_params)) {
550
- foreach ($this->request_params as $k => $v) {
551
- // Multipart params haven't been encoded yet.
552
- // Not sure why you would do a multipart GET but anyway, here's the support for it
553
- if ($this->config['multipart']) {
554
- $params[] = $this->safe_encode($k) . '=' . $this->safe_encode($v);
555
- } else {
556
- $params[] = $k . '=' . $v;
557
- }
558
- }
559
- $qs = implode('&', $params);
560
- $this->url = strlen($qs) > 0 ? $this->url . '?' . $qs : $this->url;
561
- $this->request_params = array();
562
- }
563
- break;
564
- }
565
-
566
- // configure curl
567
- $c = curl_init();
568
- curl_setopt_array($c, array(
569
- CURLOPT_USERAGENT => $this->config['user_agent'],
570
- CURLOPT_CONNECTTIMEOUT => $this->config['curl_connecttimeout'],
571
- CURLOPT_TIMEOUT => $this->config['curl_timeout'],
572
- CURLOPT_RETURNTRANSFER => true,
573
- CURLOPT_SSL_VERIFYPEER => $this->config['curl_ssl_verifypeer'],
574
- CURLOPT_SSL_VERIFYHOST => $this->config['curl_ssl_verifyhost'],
575
-
576
- CURLOPT_FOLLOWLOCATION => $this->config['curl_followlocation'],
577
- CURLOPT_PROXY => $this->config['curl_proxy'],
578
- CURLOPT_ENCODING => $this->config['curl_encoding'],
579
- CURLOPT_URL => $this->url,
580
- // process the headers
581
- CURLOPT_HEADERFUNCTION => array($this, 'curlHeader'),
582
- CURLOPT_HEADER => false,
583
- CURLINFO_HEADER_OUT => true,
584
- ));
585
-
586
- if ($this->config['curl_cainfo'] !== false)
587
- curl_setopt($c, CURLOPT_CAINFO, $this->config['curl_cainfo']);
588
-
589
- if ($this->config['curl_capath'] !== false)
590
- curl_setopt($c, CURLOPT_CAPATH, $this->config['curl_capath']);
591
-
592
- if ($this->config['curl_proxyuserpwd'] !== false)
593
- curl_setopt($c, CURLOPT_PROXYUSERPWD, $this->config['curl_proxyuserpwd']);
594
-
595
- if ($this->config['is_streaming']) {
596
- // process the body
597
- $this->response['content-length'] = 0;
598
- curl_setopt($c, CURLOPT_TIMEOUT, 0);
599
- curl_setopt($c, CURLOPT_WRITEFUNCTION, array($this, 'curlWrite'));
600
- }
601
-
602
- switch ($this->method) {
603
- case 'GET':
604
- break;
605
- case 'POST':
606
- curl_setopt($c, CURLOPT_POST, true);
607
- break;
608
- default:
609
- curl_setopt($c, CURLOPT_CUSTOMREQUEST, $this->method);
610
- }
611
-
612
- if ( ! empty($this->request_params) ) {
613
- // if not doing multipart we need to implode the parameters
614
- if ( ! $this->config['multipart'] ) {
615
- foreach ($this->request_params as $k => $v) {
616
- $ps[] = "{$k}={$v}";
617
- }
618
- $this->request_params = implode('&', $ps);
619
- }
620
- curl_setopt($c, CURLOPT_POSTFIELDS, $this->request_params);
621
- } else {
622
- // CURL will set length to -1 when there is no data, which breaks Twitter
623
- $this->headers['Content-Type'] = '';
624
- $this->headers['Content-Length'] = '';
625
- }
626
-
627
- // CURL defaults to setting this to Expect: 100-Continue which Twitter rejects
628
- $this->headers['Expect'] = '';
629
-
630
- if ( ! empty($this->headers)) {
631
- foreach ($this->headers as $k => $v) {
632
- $headers[] = trim($k . ': ' . $v);
633
- }
634
- curl_setopt($c, CURLOPT_HTTPHEADER, $headers);
635
- }
636
-
637
- if (isset($this->config['prevent_request']) && true == $this->config['prevent_request'])
638
- return;
639
-
640
- // do it!
641
- $response = curl_exec($c);
642
- $code = curl_getinfo($c, CURLINFO_HTTP_CODE);
643
- $info = curl_getinfo($c);
644
- $error = curl_error($c);
645
- $errno = curl_errno($c);
646
- curl_close($c);
647
-
648
- // store the response
649
- $this->response['code'] = $code;
650
- $this->response['response'] = $response;
651
- $this->response['info'] = $info;
652
- $this->response['error'] = $error;
653
- $this->response['errno'] = $errno;
654
- return $code;
655
- }
656
  }
1
+ <?php
2
+ /**
3
+ * tmhOAuth
4
+ *
5
+ * An OAuth 1.0A library written in PHP.
6
+ * The library supports file uploading using multipart/form as well as general
7
+ * REST requests. OAuth authentication is sent using the an Authorization Header.
8
+ *
9
+ * @author themattharris
10
+ * @version 0.61
11
+ *
12
+ * 16 January 2012
13
+ */
14
+ class NXS_tmhOAuth {
15
+ const VERSION = 0.61;
16
+
17
+ /**
18
+ * Creates a new tmhOAuth object
19
+ *
20
+ * @param string $config, the configuration to use for this request
21
+ */
22
+ function __construct($config) {
23
+ $this->params = array();
24
+ $this->headers = array();
25
+ $this->auto_fixed_time = false;
26
+ $this->buffer = null;
27
+
28
+ // default configuration options
29
+ $this->config = array_merge(
30
+ array(
31
+ // leave 'user_agent' blank for default, otherwise set this to
32
+ // something that clearly identifies your app
33
+ 'user_agent' => '',
34
+
35
+ 'use_ssl' => false,
36
+ 'host' => 'api.twitter.com',
37
+
38
+ 'consumer_key' => '',
39
+ 'consumer_secret' => '',
40
+ 'user_token' => '',
41
+ 'user_secret' => '',
42
+ 'force_nonce' => false,
43
+ 'nonce' => false, // used for checking signatures. leave as false for auto
44
+ 'force_timestamp' => false,
45
+ 'timestamp' => false, // used for checking signatures. leave as false for auto
46
+
47
+ // oauth signing variables that are not dynamic
48
+ 'oauth_version' => '1.0',
49
+ 'oauth_signature_method' => 'HMAC-SHA1',
50
+
51
+ // you probably don't want to change any of these curl values
52
+ 'curl_connecttimeout' => 30,
53
+ 'curl_timeout' => 10,
54
+
55
+ // for security this should always be set to 2.
56
+ 'curl_ssl_verifyhost' => 2,
57
+ // for security this should always be set to true.
58
+ 'curl_ssl_verifypeer' => true,
59
+
60
+ // you can get the latest cacert.pem from here http://curl.haxx.se/ca/cacert.pem
61
+ 'curl_cainfo' => dirname(__FILE__) . '/cacert.pem',
62
+ 'curl_capath' => dirname(__FILE__),
63
+
64
+ 'curl_followlocation' => false, // whether to follow redirects or not
65
+
66
+ // support for proxy servers
67
+ 'curl_proxy' => false, // really you don't want to use this if you are using streaming
68
+ 'curl_proxyuserpwd' => false, // format username:password for proxy, if required
69
+ 'curl_encoding' => '', // leave blank for all supported formats, else use gzip, deflate, identity
70
+
71
+ // streaming API
72
+ 'is_streaming' => false,
73
+ 'streaming_eol' => "\r\n",
74
+ 'streaming_metrics_interval' => 60,
75
+
76
+ // header or querystring. You should always use header!
77
+ // this is just to help me debug other developers implementations
78
+ 'as_header' => true,
79
+ 'debug' => false,
80
+ ),
81
+ $config
82
+ );
83
+ $this->set_user_agent();
84
+ }
85
+
86
+ function set_user_agent() {
87
+ if (!empty($this->config['user_agent']))
88
+ return;
89
+
90
+ if ($this->config['curl_ssl_verifyhost'] && $this->config['curl_ssl_verifypeer']) {
91
+ $ssl = '+SSL';
92
+ } else {
93
+ $ssl = '-SSL';
94
+ }
95
+
96
+ $ua = 'tmhOAuth ' . self::VERSION . $ssl . ' - //github.com/themattharris/tmhOAuth';
97
+ $this->config['user_agent'] = $ua;
98
+ }
99
+
100
+ /**
101
+ * Generates a random OAuth nonce.
102
+ * If 'force_nonce' is true a nonce is not generated and the value in the configuration will be retained.
103
+ *
104
+ * @param string $length how many characters the nonce should be before MD5 hashing. default 12
105
+ * @param string $include_time whether to include time at the beginning of the nonce. default true
106
+ * @return void
107
+ */
108
+ private function create_nonce($length=12, $include_time=true) {
109
+ if ($this->config['force_nonce'] == false) {
110
+ $sequence = array_merge(range(0,9), range('A','Z'), range('a','z'));
111
+ $length = $length > count($sequence) ? count($sequence) : $length;
112
+ shuffle($sequence);
113
+
114
+ $prefix = $include_time ? microtime() : '';
115
+ $this->config['nonce'] = md5(substr($prefix . implode('', $sequence), 0, $length));
116
+ }
117
+ }
118
+
119
+ /**
120
+ * Generates a timestamp.
121
+ * If 'force_timestamp' is true a nonce is not generated and the value in the configuration will be retained.
122
+ *
123
+ * @return void
124
+ */
125
+ private function create_timestamp() {
126
+ $this->config['timestamp'] = ($this->config['force_timestamp'] == false ? time() : $this->config['timestamp']); //echo "#### ".$this->config['timestamp'];// prr($this->config);
127
+ }
128
+
129
+ /**
130
+ * Encodes the string or array passed in a way compatible with OAuth.
131
+ * If an array is passed each array value will will be encoded.
132
+ *
133
+ * @param mixed $data the scalar or array to encode
134
+ * @return $data encoded in a way compatible with OAuth
135
+ */
136
+ private function safe_encode($data) {
137
+ if (is_array($data)) {
138
+ return array_map(array($this, 'safe_encode'), $data);
139
+ } else if (is_scalar($data)) {
140
+ return str_ireplace(
141
+ array('+', '%7E'),
142
+ array(' ', '~'),
143
+ rawurlencode($data)
144
+ );
145
+ } else {
146
+ return '';
147
+ }
148
+ }
149
+
150
+ /**
151
+ * Decodes the string or array from it's URL encoded form
152
+ * If an array is passed each array value will will be decoded.
153
+ *
154
+ * @param mixed $data the scalar or array to decode
155
+ * @return $data decoded from the URL encoded form
156
+ */
157
+ private function safe_decode($data) {
158
+ if (is_array($data)) {
159
+ return array_map(array($this, 'safe_decode'), $data);
160
+ } else if (is_scalar($data)) {
161
+ return rawurldecode($data);
162
+ } else {
163
+ return '';
164
+ }
165
+ }
166
+
167
+ /**
168
+ * Returns an array of the standard OAuth parameters.
169
+ *
170
+ * @return array all required OAuth parameters, safely encoded
171
+ */
172
+ private function get_defaults() {
173
+ $defaults = array(
174
+ 'oauth_version' => $this->config['oauth_version'],
175
+ 'oauth_nonce' => $this->config['nonce'],
176
+ 'oauth_timestamp' => $this->config['timestamp'],
177
+ 'oauth_consumer_key' => $this->config['consumer_key'],
178
+ 'oauth_signature_method' => $this->config['oauth_signature_method'],
179
+ );
180
+
181
+ // include the user token if it exists
182
+ if ( $this->config['user_token'] )
183
+ $defaults['oauth_token'] = $this->config['user_token'];
184
+
185
+ // safely encode
186
+ foreach ($defaults as $k => $v) {
187
+ $_defaults[$this->safe_encode($k)] = $this->safe_encode($v);
188
+ }
189
+
190
+ return $_defaults;
191
+ }
192
+
193
+ /**
194
+ * Extracts and decodes OAuth parameters from the passed string
195
+ *
196
+ * @param string $body the response body from an OAuth flow method
197
+ * @return array the response body safely decoded to an array of key => values
198
+ */
199
+ function extract_params($body) {
200
+ $kvs = explode('&', $body);
201
+ $decoded = array();
202
+ foreach ($kvs as $kv) {
203
+ $kv = explode('=', $kv, 2);
204
+ $kv[0] = $this->safe_decode($kv[0]);
205
+ $kv[1] = $this->safe_decode($kv[1]);
206
+ $decoded[$kv[0]] = $kv[1];
207
+ }
208
+ return $decoded;
209
+ }
210
+
211
+ /**
212
+ * Prepares the HTTP method for use in the base string by converting it to
213
+ * uppercase.
214
+ *
215
+ * @param string $method an HTTP method such as GET or POST
216
+ * @return void value is stored to a class variable
217
+ * @author themattharris
218
+ */
219
+ private function prepare_method($method) {
220
+ $this->method = strtoupper($method);
221
+ }
222
+
223
+ /**
224
+ * Prepares the URL for use in the base string by ripping it apart and
225
+ * reconstructing it.
226
+ *
227
+ * Ref: 3.4.1.2
228
+ *
229
+ * @param string $url the request URL
230
+ * @return void value is stored to a class variable
231
+ * @author themattharris
232
+ */
233
+ private function prepare_url($url) {
234
+ $parts = parse_url($url);
235
+
236
+ $port = isset($parts['port']) ? $parts['port'] : false;
237
+ $scheme = $parts['scheme'];
238
+ $host = $parts['host'];
239
+ $path = isset($parts['path']) ? $parts['path'] : false;
240
+
241
+ $port or $port = ($scheme == 'https') ? '443' : '80';
242
+
243
+ if (($scheme == 'https' && $port != '443')
244
+ || ($scheme == 'http' && $port != '80')) {
245
+ $host = "$host:$port";
246
+ }
247
+ $this->url = strtolower("$scheme://$host$path");
248
+ }
249
+
250
+ /**
251
+ * Prepares all parameters for the base string and request.
252
+ * Multipart parameters are ignored as they are not defined in the specification,
253
+ * all other types of parameter are encoded for compatibility with OAuth.
254
+ *
255
+ * @param array $params the parameters for the request
256
+ * @return void prepared values are stored in class variables
257
+ */
258
+ private function prepare_params($params) {
259
+ // do not encode multipart parameters, leave them alone
260
+ if ($this->config['multipart']) {
261
+ $this->request_params = $params;
262
+ $params = array();
263
+ }
264
+
265
+ // signing parameters are request parameters + OAuth default parameters
266
+ $this->signing_params = array_merge($this->get_defaults(), (array)$params);
267
+
268
+ // Remove oauth_signature if present
269
+ // Ref: Spec: 9.1.1 ("The oauth_signature parameter MUST be excluded.")
270
+ if (isset($this->signing_params['oauth_signature'])) {
271
+ unset($this->signing_params['oauth_signature']);
272
+ }
273
+
274
+ // Parameters are sorted by name, using lexicographical byte value ordering.
275
+ // Ref: Spec: 9.1.1 (1)
276
+ uksort($this->signing_params, 'strcmp');
277
+
278
+ // encode. Also sort the signed parameters from the POST parameters
279
+ foreach ($this->signing_params as $k => $v) {
280
+ $k = $this->safe_encode($k);
281
+ $v = $this->safe_encode($v);
282
+ $_signing_params[$k] = $v;
283
+ $kv[] = "{$k}={$v}";
284
+ }
285
+
286
+ // auth params = the default oauth params which are present in our collection of signing params
287
+ $this->auth_params = array_intersect_key($this->get_defaults(), $_signing_params);
288
+ if (isset($_signing_params['oauth_callback'])) {
289
+ $this->auth_params['oauth_callback'] = $_signing_params['oauth_callback'];
290
+ unset($_signing_params['oauth_callback']);
291
+ }
292
+
293
+ if (isset($_signing_params['oauth_verifier'])) {
294
+ $this->auth_params['oauth_verifier'] = $_signing_params['oauth_verifier'];
295
+ unset($_signing_params['oauth_verifier']);
296
+ }
297
+
298
+ // request_params is already set if we're doing multipart, if not we need to set them now
299
+ if ( ! $this->config['multipart'])
300
+ $this->request_params = array_diff_key($_signing_params, $this->get_defaults());
301
+
302
+ // create the parameter part of the base string
303
+ $this->signing_params = implode('&', $kv);
304
+ }
305
+
306
+ /**
307
+ * Prepares the OAuth signing key
308
+ *
309
+ * @return void prepared signing key is stored in a class variables
310
+ */
311
+ private function prepare_signing_key() {
312
+ $this->signing_key = $this->safe_encode($this->config['consumer_secret']) . '&' . $this->safe_encode($this->config['user_secret']);
313
+ }
314
+
315
+ /**
316
+ * Prepare the base string.
317
+ * Ref: Spec: 9.1.3 ("Concatenate Request Elements")
318
+ *
319
+ * @return void prepared base string is stored in a class variables
320
+ */
321
+ private function prepare_base_string() {
322
+ $base = array(
323
+ $this->method,
324
+ $this->url,
325
+ $this->signing_params
326
+ );
327
+ $this->base_string = implode('&', $this->safe_encode($base));
328
+ }
329
+
330
+ /**
331
+ * Prepares the Authorization header
332
+ *
333
+ * @return void prepared authorization header is stored in a class variables
334
+ */
335
+ private function prepare_auth_header() {
336
+ $this->headers = array();
337
+ uksort($this->auth_params, 'strcmp');
338
+ if (!$this->config['as_header']) :
339
+ $this->request_params = array_merge($this->request_params, $this->auth_params);
340
+ return;
341
+ endif;
342
+
343
+ foreach ($this->auth_params as $k => $v) {
344
+ $kv[] = "{$k}=\"{$v}\"";
345
+ }
346
+ $this->auth_header = 'OAuth ' . implode(', ', $kv);
347
+ $this->headers['Authorization'] = $this->auth_header;
348
+ }
349
+
350
+ /**
351
+ * Signs the request and adds the OAuth signature. This runs all the request
352
+ * parameter preparation methods.
353
+ *
354
+ * @param string $method the HTTP method being used. e.g. POST, GET, HEAD etc
355
+ * @param string $url the request URL without query string parameters
356
+ * @param array $params the request parameters as an array of key=value pairs
357
+ * @param string $useauth whether to use authentication when making the request.
358
+ */
359
+ private function sign($method, $url, $params, $useauth) {
360
+ $this->prepare_method($method);
361
+ $this->prepare_url($url);
362
+ $this->prepare_params($params);
363
+
364
+ // we don't sign anything is we're not using auth
365
+ if ($useauth) {
366
+ $this->prepare_base_string();
367
+ $this->prepare_signing_key();
368
+
369
+ $this->auth_params['oauth_signature'] = $this->safe_encode(
370
+ base64_encode(
371
+ hash_hmac(
372
+ 'sha1', $this->base_string, $this->signing_key, true
373
+ )));
374
+
375
+ $this->prepare_auth_header();
376
+ }
377
+ }
378
+
379
+ /**
380
+ * Make an HTTP request using this library. This method doesn't return anything.
381
+ * Instead the response should be inspected directly.
382
+ *
383
+ * @param string $method the HTTP method being used. e.g. POST, GET, HEAD etc
384
+ * @param string $url the request URL without query string parameters
385
+ * @param array $params the request parameters as an array of key=value pairs
386
+ * @param string $useauth whether to use authentication when making the request. Default true.
387
+ * @param string $multipart whether this request contains multipart data. Default false
388
+ */
389
+ function request($method, $url, $params=array(), $useauth=true, $multipart=false) {
390
+ $this->config['multipart'] = $multipart;
391
+
392
+ $this->create_nonce();
393
+ $this->create_timestamp();
394
+
395
+ $this->sign($method, $url, $params, $useauth);
396
+ return $this->curlit();
397
+ }
398
+
399
+ /**
400
+ * Make a long poll HTTP request using this library. This method is
401
+ * different to the other request methods as it isn't supposed to disconnect
402
+ *
403
+ * Using this method expects a callback which will receive the streaming
404
+ * responses.
405
+ *
406
+ * @param string $method the HTTP method being used. e.g. POST, GET, HEAD etc
407
+ * @param string $url the request URL without query string parameters
408
+ * @param array $params the request parameters as an array of key=value pairs
409
+ * @param string $callback the callback function to stream the buffer to.
410
+ */
411
+ function streaming_request($method, $url, $params=array(), $callback='') {
412
+ if ( ! empty($callback) ) {
413
+ if ( ! function_exists($callback) ) {
414
+ return false;
415
+ }
416
+ $this->config['streaming_callback'] = $callback;
417
+ }
418
+ $this->metrics['start'] = time();
419
+ $this->metrics['interval_start'] = $this->metrics['start'];
420
+ $this->metrics['tweets'] = 0;
421
+ $this->metrics['last_tweets'] = 0;
422
+ $this->metrics['bytes'] = 0;
423
+ $this->metrics['last_bytes'] = 0;
424
+ $this->config['is_streaming'] = true;
425
+ $this->request($method, $url, $params);
426
+ }
427
+
428
+ /**
429
+ * Handles the updating of the current Streaming API metrics.
430
+ */
431
+ function update_metrics() {
432
+ $now = time();
433
+ if (($this->metrics['interval_start'] + $this->config['streaming_metrics_interval']) > $now)
434
+ return false;
435
+
436
+ $this->metrics['tps'] = round( ($this->metrics['tweets'] - $this->metrics['last_tweets']) / $this->config['streaming_metrics_interval'], 2);
437
+ $this->metrics['bps'] = round( ($this->metrics['bytes'] - $this->metrics['last_bytes']) / $this->config['streaming_metrics_interval'], 2);
438
+
439
+ $this->metrics['last_bytes'] = $this->metrics['bytes'];
440
+ $this->metrics['last_tweets'] = $this->metrics['tweets'];
441
+ $this->metrics['interval_start'] = $now;
442
+ return $this->metrics;
443
+ }
444
+
445
+ /**
446
+ * Utility function to create the request URL in the requested format
447
+ *
448
+ * @param string $request the API method without extension
449
+ * @param string $format the format of the response. Default json. Set to an empty string to exclude the format
450
+ * @return string the concatenation of the host, API version, API method and format
451
+ */
452
+ function url($request, $format='json') {
453
+ $format = strlen($format) > 0 ? ".$format" : '';
454
+ $proto = $this->config['use_ssl'] ? 'https:/' : 'http:/';
455
+
456
+ // backwards compatibility with v0.1
457
+ if (isset($this->config['v']))
458
+ $this->config['host'] = $this->config['host'] . '/' . $this->config['v'];
459
+
460
+ return implode('/', array(
461
+ $proto,
462
+ $this->config['host'],
463
+ $request . $format
464
+ ));
465
+ }
466
+
467
+ /**
468
+ * Public access to the private safe decode/encode methods
469
+ *
470
+ * @param string $text the text to transform
471
+ * @param string $mode the transformation mode. either encode or decode
472
+ * @return the string as transformed by the given mode
473
+ */
474
+ function transformText($text, $mode='encode') {
475
+ return $this->{"safe_$mode"}($text);
476
+ }
477
+
478
+ /**
479
+ * Utility function to parse the returned curl headers and store them in the
480
+ * class array variable.
481
+ *
482
+ * @param object $ch curl handle
483
+ * @param string $header the response headers
484
+ * @return the string length of the header
485
+ */
486
+ private function curlHeader($ch, $header) {
487
+ $i = strpos($header, ':');
488
+ if ( ! empty($i) ) {
489
+ $key = str_replace('-', '_', strtolower(substr($header, 0, $i)));
490
+ $value = trim(substr($header, $i + 2));
491
+ $this->response['headers'][$key] = $value;
492
+ }
493
+ return strlen($header);
494
+ }
495
+
496
+ /**
497
+ * Utility function to parse the returned curl buffer and store them until
498
+ * an EOL is found. The buffer for curl is an undefined size so we need
499
+ * to collect the content until an EOL is found.
500
+ *
501
+ * This function calls the previously defined streaming callback method.
502
+ *
503
+ * @param object $ch curl handle
504
+ * @param string $data the current curl buffer
505
+ */
506
+ private function curlWrite($ch, $data) {
507
+ $l = strlen($data);
508
+ if (strpos($data, $this->config['streaming_eol']) === false) {
509
+ $this->buffer .= $data;
510
+ return $l;
511
+ }
512
+
513
+ $buffered = explode($this->config['streaming_eol'], $data);
514
+ $content = $this->buffer . $buffered[0];
515
+
516
+ $this->metrics['tweets']++;
517
+ $this->metrics['bytes'] += strlen($content);
518
+
519
+ if ( ! function_exists($this->config['streaming_callback']))
520
+ return 0;
521
+
522
+ $metrics = $this->update_metrics();
523
+ $stop = call_user_func(
524
+ $this->config['streaming_callback'],
525
+ $content,
526
+ strlen($content),
527
+ $metrics
528
+ );
529
+ $this->buffer = $buffered[1];
530
+ if ($stop)
531
+ return 0;
532
+
533
+ return $l;
534
+ }
535
+
536
+ /**
537
+ * Makes a curl request. Takes no parameters as all should have been prepared
538
+ * by the request method
539
+ *
540
+ * @return void response data is stored in the class variable 'response'
541
+ */
542
+ private function curlit() {
543
+ // method handling
544
+ switch ($this->method) {
545
+ case 'POST':
546
+ break;
547
+ default:
548
+ // GET, DELETE request so convert the parameters to a querystring
549
+ if ( ! empty($this->request_params)) {
550
+ foreach ($this->request_params as $k => $v) {
551
+ // Multipart params haven't been encoded yet.
552
+ // Not sure why you would do a multipart GET but anyway, here's the support for it
553
+ if ($this->config['multipart']) {
554
+ $params[] = $this->safe_encode($k) . '=' . $this->safe_encode($v);
555
+ } else {
556
+ $params[] = $k . '=' . $v;
557
+ }
558
+ }
559
+ $qs = implode('&', $params);
560
+ $this->url = strlen($qs) > 0 ? $this->url . '?' . $qs : $this->url;
561
+ $this->request_params = array();
562
+ }
563
+ break;
564
+ }
565
+
566
+ // configure curl
567
+ $c = curl_init();
568
+ curl_setopt_array($c, array(
569
+ CURLOPT_USERAGENT => $this->config['user_agent'],
570
+ CURLOPT_CONNECTTIMEOUT => $this->config['curl_connecttimeout'],
571
+ CURLOPT_TIMEOUT => $this->config['curl_timeout'],
572
+ CURLOPT_RETURNTRANSFER => true,
573
+ CURLOPT_SSL_VERIFYPEER => $this->config['curl_ssl_verifypeer'],
574
+ CURLOPT_SSL_VERIFYHOST => $this->config['curl_ssl_verifyhost'],
575
+
576
+ CURLOPT_FOLLOWLOCATION => $this->config['curl_followlocation'],
577
+ CURLOPT_PROXY => $this->config['curl_proxy'],
578
+ CURLOPT_ENCODING => $this->config['curl_encoding'],
579
+ CURLOPT_URL => $this->url,
580
+ // process the headers
581
+ CURLOPT_HEADERFUNCTION => array($this, 'curlHeader'),
582
+ CURLOPT_HEADER => false,
583
+ CURLINFO_HEADER_OUT => true,
584
+ ));
585
+
586
+ if ($this->config['curl_cainfo'] !== false)
587
+ curl_setopt($c, CURLOPT_CAINFO, $this->config['curl_cainfo']);
588
+
589
+ if ($this->config['curl_capath'] !== false)
590
+ curl_setopt($c, CURLOPT_CAPATH, $this->config['curl_capath']);
591
+
592
+ if ($this->config['curl_proxyuserpwd'] !== false)
593
+ curl_setopt($c, CURLOPT_PROXYUSERPWD, $this->config['curl_proxyuserpwd']);
594
+
595
+ if ($this->config['is_streaming']) {
596
+ // process the body
597
+ $this->response['content-length'] = 0;
598
+ curl_setopt($c, CURLOPT_TIMEOUT, 0);
599
+ curl_setopt($c, CURLOPT_WRITEFUNCTION, array($this, 'curlWrite'));
600
+ }
601
+
602
+ switch ($this->method) {
603
+ case 'GET':
604
+ break;
605
+ case 'POST':
606
+ curl_setopt($c, CURLOPT_POST, true);
607
+ break;
608
+ default:
609
+ curl_setopt($c, CURLOPT_CUSTOMREQUEST, $this->method);
610
+ }
611
+
612
+ if ( ! empty($this->request_params) ) {
613
+ // if not doing multipart we need to implode the parameters
614
+ if ( ! $this->config['multipart'] ) {
615
+ foreach ($this->request_params as $k => $v) {
616
+ $ps[] = "{$k}={$v}";
617
+ }
618
+ $this->request_params = implode('&', $ps);
619
+ }
620
+ curl_setopt($c, CURLOPT_POSTFIELDS, $this->request_params);
621
+ } else {
622
+ // CURL will set length to -1 when there is no data, which breaks Twitter
623
+ $this->headers['Content-Type'] = '';
624
+ $this->headers['Content-Length'] = '';
625
+ }
626
+
627
+ // CURL defaults to setting this to Expect: 100-Continue which Twitter rejects
628
+ $this->headers['Expect'] = '';
629
+
630
+ if ( ! empty($this->headers)) {
631
+ foreach ($this->headers as $k => $v) {
632
+ $headers[] = trim($k . ': ' . $v);
633
+ }
634
+ curl_setopt($c, CURLOPT_HTTPHEADER, $headers);
635
+ }
636
+
637
+ if (isset($this->config['prevent_request']) && true == $this->config['prevent_request'])
638
+ return;
639
+
640
+ // do it!
641
+ $response = curl_exec($c);
642
+ $code = curl_getinfo($c, CURLINFO_HTTP_CODE);
643
+ $info = curl_getinfo($c);
644
+ $error = curl_error($c);
645
+ $errno = curl_errno($c);
646
+ curl_close($c);
647
+
648
+ // store the response
649
+ $this->response['code'] = $code;
650
+ $this->response['response'] = $response;
651
+ $this->response['info'] = $info;
652
+ $this->response['error'] = $error;
653
+ $this->response['errno'] = $errno;
654
+ return $code;
655
+ }
656
  }
inc-cl/apis/tmhUtilities.php CHANGED
@@ -1,249 +1,249 @@
1
- <?php
2
- /**
3
- * tmhUtilities
4
- *
5
- * Helpful utility and Twitter formatting functions
6
- *
7
- * @author themattharris
8
- * @version 0.2
9
- *
10
- * 29 September 2011
11
- */
12
- class NXS_tmhUtilities {
13
- /**
14
- * Entifies the tweet using the given entities element
15
- *
16
- * @param array $tweet the json converted to normalised array
17
- * @return the tweet text with entities replaced with hyperlinks
18
- */
19
- function entify($tweet, &$replacements=array()) {
20
- $encoding = mb_internal_encoding();
21
- mb_internal_encoding("UTF-8");
22
-
23
- $keys = array();
24
- // $replacements = array();
25
- $is_retweet = false;
26
-
27
- if (isset($tweet['retweeted_status'])) {
28
- $tweet = $tweet['retweeted_status'];
29
- $is_retweet = true;
30
- }
31
-
32
- if (!isset($tweet['entities'])) {
33
- return $tweet['text'];
34
- }
35
-
36
- // prepare the entities
37
- foreach ($tweet['entities'] as $type => $things) {
38
- foreach ($things as $entity => $value) {
39
- $tweet_link = "<a href=\"http://twitter.com/{$tweet['user']['screen_name']}/statuses/{$tweet['id']}\">{$tweet['created_at']}</a>";
40
-
41
- switch ($type) {
42
- case 'hashtags':
43
- $href = "<a href=\"http://twitter.com/search?q=%23{$value['text']}\">#{$value['text']}</a>";
44
- break;
45
- case 'user_mentions':
46
- $href = "@<a href=\"http://twitter.com/{$value['screen_name']}\" title=\"{$value['name']}\">{$value['screen_name']}</a>";
47
- break;
48
- case 'urls':
49
- case 'media':
50
- $url = empty($value['expanded_url']) ? $value['url'] : $value['expanded_url'];
51
- $display = isset($value['display_url']) ? $value['display_url'] : str_replace('http://', '', $url);
52
- // Not all pages are served in UTF-8 so you may need to do this ...
53
- $display = urldecode(str_replace('%E2%80%A6', '&hellip;', urlencode($display)));
54
- $href = "<a href=\"{$value['url']}\">{$display}</a>";
55
- break;
56
- }
57
- $keys[$value['indices']['0']] = mb_substr(
58
- $tweet['text'],
59
- $value['indices']['0'],
60
- $value['indices']['1'] - $value['indices']['0']
61
- );
62
- $replacements[$value['indices']['0']] = $href;
63
- }
64
- }
65
-
66
- ksort($replacements);
67
- $replacements = array_reverse($replacements, true);
68
- $entified_tweet = $tweet['text'];
69
- foreach ($replacements as $k => $v) {
70
- // $entified_tweet = substr_replace($entified_tweet, $v, $k, strlen($keys[$k]));
71
- $entified_tweet = mb_substr($entified_tweet, 0, $k).$v.mb_substr($entified_tweet, $k + strlen($keys[$k]));
72
- }
73
- $replacements = array(
74
- 'replacements' => $replacements,
75
- 'keys' => $keys
76
- );
77
-
78
- mb_internal_encoding($encoding);
79
- return $entified_tweet;
80
- }
81
-
82
- /**
83
- * Returns the current URL. This is instead of PHP_SELF which is unsafe
84
- *
85
- * @param bool $dropqs whether to drop the querystring or not. Default true
86
- * @return string the current URL
87
- */
88
- function php_self($dropqs=true) {
89
- $url = sprintf('%s://%s%s',
90
- empty($_SERVER['HTTPS']) ? (@$_SERVER['SERVER_PORT'] == '443' ? 'https' : 'http') : 'http',
91
- $_SERVER['SERVER_NAME'],
92
- $_SERVER['REQUEST_URI']
93
- );
94
-
95
- $parts = parse_url($url);
96
-
97
- $port = $_SERVER['SERVER_PORT'];
98
- $scheme = $parts['scheme'];
99
- $host = $parts['host'];
100
- $path = @$parts['path'];
101
- $qs = @$parts['query'];
102
-
103
- $port or $port = ($scheme == 'https') ? '443' : '80';
104
-
105
- if (($scheme == 'https' && $port != '443')
106
- || ($scheme == 'http' && $port != '80')) {
107
- $host = "$host:$port";
108
- }
109
- $url = "$scheme://$host$path";
110
- if ( ! $dropqs)
111
- return "{$url}?{$qs}";
112
- else
113
- return $url;
114
- }
115
-
116
- function is_cli() {
117
- return (PHP_SAPI == 'cli' && empty($_SERVER['REMOTE_ADDR']));
118
- }
119
-
120
- /**
121
- * Debug function for printing the content of an object
122
- *
123
- * @param mixes $obj
124
- */
125
- function pr($obj) {
126
-
127
- if (!self::is_cli())
128
- echo '<pre style="word-wrap: break-word">';
129
- if ( is_object($obj) )
130
- print_r($obj);
131
- elseif ( is_array($obj) )
132
- print_r($obj);
133
- else
134
- echo $obj;
135
- if (!self::is_cli())
136
- echo '</pre>';
137
- }
138
-
139
- /**
140
- * Make an HTTP request using this library. This method is different to 'request'
141
- * because on a 401 error it will retry the request.
142
- *
143
- * When a 401 error is returned it is possible the timestamp of the client is
144
- * too different to that of the API server. In this situation it is recommended
145
- * the request is retried with the OAuth timestamp set to the same as the API
146
- * server. This method will automatically try that technique.
147
- *
148
- * This method doesn't return anything. Instead the response should be
149
- * inspected directly.
150
- *
151
- * @param string $method the HTTP method being used. e.g. POST, GET, HEAD etc
152
- * @param string $url the request URL without query string parameters
153
- * @param array $params the request parameters as an array of key=value pairs
154
- * @param string $useauth whether to use authentication when making the request. Default true.
155
- * @param string $multipart whether this request contains multipart data. Default false
156
- */
157
- function auto_fix_time_request($tmhOAuth, $method, $url, $params=array(), $useauth=true, $multipart=false) {
158
- $tmhOAuth->request($method, $url, $params, $useauth, $multipart);
159
-
160
- // if we're not doing auth the timestamp isn't important
161
- if ( ! $useauth)
162
- return;
163
-
164
- // some error that isn't a 401
165
- if ($tmhOAuth->response['code'] != 401)
166
- return;
167
-
168
- // some error that is a 401 but isn't because the OAuth token and signature are incorrect
169
- // TODO: this check is horrid but helps avoid requesting twice when the username and password are wrong
170
- if (stripos($tmhOAuth->response['response'], 'password') !== false)
171
- return;
172
-
173
- // force the timestamp to be the same as the Twitter servers, and re-request
174
- $tmhOAuth->auto_fixed_time = true;
175
- $tmhOAuth->config['force_timestamp'] = true;
176
- $tmhOAuth->config['timestamp'] = strtotime($tmhOAuth->response['headers']['date']);
177
- return $tmhOAuth->request($method, $url, $params, $useauth, $multipart);
178
- }
179
-
180
- /**
181
- * Asks the user for input and returns the line they enter
182
- *
183
- * @param string $prompt the text to display to the user
184
- * @return the text entered by the user
185
- */
186
- function read_input($prompt) {
187
- echo $prompt;
188
- $handle = fopen("php://stdin","r");
189
- $data = fgets($handle);
190
- return trim($data);
191
- }
192
-
193
- /**
194
- * Get a password from the shell.
195
- *
196
- * This function works on *nix systems only and requires shell_exec and stty.
197
- *
198
- * @param boolean $stars Wether or not to output stars for given characters
199
- * @return string
200
- * @url http://www.dasprids.de/blog/2008/08/22/getting-a-password-hidden-from-stdin-with-php-cli
201
- */
202
- function read_password($prompt, $stars=false) {
203
- echo $prompt;
204
- $style = shell_exec('stty -g');
205
-
206
- if ($stars === false) {
207
- shell_exec('stty -echo');
208
- $password = rtrim(fgets(STDIN), "\n");
209
- } else {
210
- shell_exec('stty -icanon -echo min 1 time 0');
211
- $password = '';
212
- while (true) :
213
- $char = fgetc(STDIN);
214
- if ($char === "\n") :
215
- break;
216
- elseif (ord($char) === 127) :
217
- if (strlen($password) > 0) {
218
- fwrite(STDOUT, "\x08 \x08");
219
- $password = substr($password, 0, -1);
220
- }
221
- else
222
- fwrite(STDOUT, "*");
223
- $password .= $char;
224
- endif;
225
- endwhile;
226
- }
227
-
228
- // Reset
229
- shell_exec('stty ' . $style);
230
- echo PHP_EOL;
231
- return $password;
232
- }
233
-
234
- /**
235
- * Check if one string ends with another
236
- *
237
- * @param string $haystack the string to check inside of
238
- * @param string $needle the string to check $haystack ends with
239
- * @return true if $haystack ends with $needle, false otherwise
240
- */
241
- function endswith($haystack, $needle) {
242
- $haylen = strlen($haystack);
243
- $needlelen = strlen($needle);
244
- if ($needlelen > $haylen)
245
- return false;
246
-
247
- return substr_compare($haystack, $needle, -$needlelen) === 0;
248
- }
249
  }
1
+ <?php
2
+ /**
3
+ * tmhUtilities
4
+ *
5
+ * Helpful utility and Twitter formatting functions
6
+ *
7
+ * @author themattharris
8
+ * @version 0.2
9
+ *
10
+ * 29 September 2011
11
+ */
12
+ class NXS_tmhUtilities {
13
+ /**
14
+ * Entifies the tweet using the given entities element
15
+ *
16
+ * @param array $tweet the json converted to normalised array
17
+ * @return the tweet text with entities replaced with hyperlinks
18
+ */
19
+ function entify($tweet, &$replacements=array()) {
20
+ $encoding = mb_internal_encoding();
21
+ mb_internal_encoding("UTF-8");
22
+
23
+ $keys = array();
24
+ // $replacements = array();
25
+ $is_retweet = false;
26
+
27
+ if (isset($tweet['retweeted_status'])) {
28
+ $tweet = $tweet['retweeted_status'];
29
+ $is_retweet = true;
30
+ }
31
+
32
+ if (!isset($tweet['entities'])) {
33
+ return $tweet['text'];
34
+ }
35
+
36
+ // prepare the entities
37
+ foreach ($tweet['entities'] as $type => $things) {
38
+ foreach ($things as $entity => $value) {
39
+ $tweet_link = "<a href=\"http://twitter.com/{$tweet['user']['screen_name']}/statuses/{$tweet['id']}\">{$tweet['created_at']}</a>";
40
+
41
+ switch ($type) {
42
+ case 'hashtags':
43
+ $href = "<a href=\"http://twitter.com/search?q=%23{$value['text']}\">#{$value['text']}</a>";
44
+ break;
45
+ case 'user_mentions':
46
+ $href = "@<a href=\"http://twitter.com/{$value['screen_name']}\" title=\"{$value['name']}\">{$value['screen_name']}</a>";
47
+ break;
48
+ case 'urls':
49
+ case 'media':
50
+ $url = empty($value['expanded_url']) ? $value['url'] : $value['expanded_url'];
51
+ $display = isset($value['display_url']) ? $value['display_url'] : str_replace('http://', '', $url);
52
+ // Not all pages are served in UTF-8 so you may need to do this ...
53
+ $display = urldecode(str_replace('%E2%80%A6', '&hellip;', urlencode($display)));
54
+ $href = "<a href=\"{$value['url']}\">{$display}</a>";
55
+ break;
56
+ }
57
+ $keys[$value['indices']['0']] = mb_substr(
58
+ $tweet['text'],
59
+ $value['indices']['0'],
60
+ $value['indices']['1'] - $value['indices']['0']
61
+ );
62
+ $replacements[$value['indices']['0']] = $href;
63
+ }
64
+ }
65
+
66
+ ksort($replacements);
67
+ $replacements = array_reverse($replacements, true);
68
+ $entified_tweet = $tweet['text'];
69
+ foreach ($replacements as $k => $v) {
70
+ // $entified_tweet = substr_replace($entified_tweet, $v, $k, strlen($keys[$k]));
71
+ $entified_tweet = mb_substr($entified_tweet, 0, $k).$v.mb_substr($entified_tweet, $k + strlen($keys[$k]));
72
+ }
73
+ $replacements = array(
74
+ 'replacements' => $replacements,
75
+ 'keys' => $keys
76
+ );
77
+
78
+ mb_internal_encoding($encoding);
79
+ return $entified_tweet;
80
+ }
81
+
82
+ /**
83
+ * Returns the current URL. This is instead of PHP_SELF which is unsafe
84
+ *
85
+ * @param bool $dropqs whether to drop the querystring or not. Default true
86
+ * @return string the current URL
87
+ */
88
+ function php_self($dropqs=true) {
89
+ $url = sprintf('%s://%s%s',
90
+ empty($_SERVER['HTTPS']) ? (@$_SERVER['SERVER_PORT'] == '443' ? 'https' : 'http') : 'http',
91
+ $_SERVER['SERVER_NAME'],
92
+ $_SERVER['REQUEST_URI']
93
+ );
94
+
95
+ $parts = parse_url($url);
96
+
97
+ $port = $_SERVER['SERVER_PORT'];
98
+ $scheme = $parts['scheme'];
99
+ $host = $parts['host'];
100
+ $path = @$parts['path'];
101
+ $qs = @$parts['query'];
102
+
103
+ $port or $port = ($scheme == 'https') ? '443' : '80';
104
+
105
+ if (($scheme == 'https' && $port != '443')
106
+ || ($scheme == 'http' && $port != '80')) {
107
+ $host = "$host:$port";
108
+ }
109
+ $url = "$scheme://$host$path";
110
+ if ( ! $dropqs)
111
+ return "{$url}?{$qs}";
112
+ else
113
+ return $url;
114
+ }
115
+
116
+ function is_cli() {
117
+ return (PHP_SAPI == 'cli' && empty($_SERVER['REMOTE_ADDR']));
118
+ }
119
+
120
+ /**
121
+ * Debug function for printing the content of an object
122
+ *
123
+ * @param mixes $obj
124
+ */
125
+ function pr($obj) {
126
+
127
+ if (!self::is_cli())
128
+ echo '<pre style="word-wrap: break-word">';
129
+ if ( is_object($obj) )
130
+ print_r($obj);
131
+ elseif ( is_array($obj) )
132
+ print_r($obj);
133
+ else
134
+ echo $obj;
135
+ if (!self::is_cli())
136
+ echo '</pre>';
137
+ }
138
+
139
+ /**
140
+ * Make an HTTP request using this library. This method is different to 'request'
141
+ * because on a 401 error it will retry the request.
142
+ *
143
+ * When a 401 error is returned it is possible the timestamp of the client is
144
+ * too different to that of the API server. In this situation it is recommended
145
+ * the request is retried with the OAuth timestamp set to the same as the API
146
+ * server. This method will automatically try that technique.
147
+ *
148
+ * This method doesn't return anything. Instead the response should be
149
+ * inspected directly.
150
+ *
151
+ * @param string $method the HTTP method being used. e.g. POST, GET, HEAD etc
152
+ * @param string $url the request URL without query string parameters
153
+ * @param array $params the request parameters as an array of key=value pairs
154
+ * @param string $useauth whether to use authentication when making the request. Default true.
155
+ * @param string $multipart whether this request contains multipart data. Default false
156
+ */
157
+ function auto_fix_time_request($tmhOAuth, $method, $url, $params=array(), $useauth=true, $multipart=false) {
158
+ $tmhOAuth->request($method, $url, $params, $useauth, $multipart);
159
+
160
+ // if we're not doing auth the timestamp isn't important
161
+ if ( ! $useauth)
162
+ return;
163
+
164
+ // some error that isn't a 401
165
+ if ($tmhOAuth->response['code'] != 401)
166
+ return;
167
+
168
+ // some error that is a 401 but isn't because the OAuth token and signature are incorrect
169
+ // TODO: this check is horrid but helps avoid requesting twice when the username and password are wrong
170
+ if (stripos($tmhOAuth->response['response'], 'password') !== false)
171
+ return;
172
+
173
+ // force the timestamp to be the same as the Twitter servers, and re-request
174
+ $tmhOAuth->auto_fixed_time = true;
175
+ $tmhOAuth->config['force_timestamp'] = true;
176
+ $tmhOAuth->config['timestamp'] = strtotime($tmhOAuth->response['headers']['date']);
177
+ return $tmhOAuth->request($method, $url, $params, $useauth, $multipart);
178
+ }
179
+
180
+ /**
181
+ * Asks the user for input and returns the line they enter
182
+ *
183
+ * @param string $prompt the text to display to the user
184
+ * @return the text entered by the user
185
+ */
186
+ function read_input($prompt) {
187
+ echo $prompt;
188
+ $handle = fopen("php://stdin","r");
189
+ $data = fgets($handle);
190
+ return trim($data);
191
+ }
192
+
193
+ /**
194
+ * Get a password from the shell.
195
+ *
196
+ * This function works on *nix systems only and requires shell_exec and stty.
197
+ *
198
+ * @param boolean $stars Wether or not to output stars for given characters
199
+ * @return string
200
+ * @url http://www.dasprids.de/blog/2008/08/22/getting-a-password-hidden-from-stdin-with-php-cli
201
+ */
202
+ function read_password($prompt, $stars=false) {
203
+ echo $prompt;
204
+ $style = shell_exec('stty -g');
205
+
206
+ if ($stars === false) {
207
+ shell_exec('stty -echo');
208
+ $password = rtrim(fgets(STDIN), "\n");
209
+ } else {
210
+ shell_exec('stty -icanon -echo min 1 time 0');
211
+ $password = '';
212
+ while (true) :
213
+ $char = fgetc(STDIN);
214
+ if ($char === "\n") :
215
+ break;
216
+ elseif (ord($char) === 127) :
217
+ if (strlen($password) > 0) {
218
+ fwrite(STDOUT, "\x08 \x08");
219
+ $password = substr($password, 0, -1);
220
+ }
221
+ else
222
+ fwrite(STDOUT, "*");
223
+ $password .= $char;
224
+ endif;
225
+ endwhile;
226
+ }
227
+
228
+ // Reset
229
+ shell_exec('stty ' . $style);
230
+ echo PHP_EOL;
231
+ return $password;
232
+ }
233
+
234
+ /**
235
+ * Check if one string ends with another
236
+ *
237
+ * @param string $haystack the string to check inside of
238
+ * @param string $needle the string to check $haystack ends with
239
+ * @return true if $haystack ends with $needle, false otherwise
240
+ */
241
+ function endswith($haystack, $needle) {
242
+ $haylen = strlen($haystack);
243
+ $needlelen = strlen($needle);
244
+ if ($needlelen > $haylen)
245
+ return false;
246
+
247
+ return substr_compare($haystack, $needle, -$needlelen) === 0;
248
+ }
249
  }
inc-cl/apis/xmlrpc-client.php CHANGED
@@ -1,1451 +1,1451 @@
1
- <?php
2
- /**
3
- * IXR - The Incutio XML-RPC Library
4
- *
5
- * Copyright (c) 2010, Incutio Ltd.
6
- * All rights reserved.
7
- *
8
- * Redistribution and use in source and binary forms, with or without
9
- * modification, are permitted provided that the following conditions are met:
10
- *
11
- * - Redistributions of source code must retain the above copyright notice,
12
- * this list of conditions and the following disclaimer.
13
- * - Redistributions in binary form must reproduce the above copyright
14
- * notice, this list of conditions and the following disclaimer in the
15
- * documentation and/or other materials provided with the distribution.
16
- * - Neither the name of Incutio Ltd. nor the names of its contributors
17
- * may be used to endorse or promote products derived from this software
18
- * without specific prior written permission.
19
- *
20
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21
- * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
24
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
28
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30
- * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
- *
32
- * @package IXR
33
- * @since 1.5
34
- *
35
- * @copyright Incutio Ltd 2010 (http://www.incutio.com)
36
- * @version 1.7.4 7th September 2010
37
- * @author Simon Willison
38
- * @link http://scripts.incutio.com/xmlrpc/ Site/manual
39
- */
40
-
41
-
42
- class NXS_XMLRPC_Value
43
- {
44
- var $data;
45
- var $type;
46
-
47
- function NXS_XMLRPC_Value($data, $type = false)
48
- {
49
- $this->data = $data;
50
- if (!$type) {
51
- $type = $this->calculateType();
52
- }
53
- $this->type = $type;
54
- if ($type == 'struct') {
55
- // Turn all the values in the array in to new NXS_XMLRPC_Value objects
56
- foreach ($this->data as $key => $value) {
57
- $this->data[$key] = new NXS_XMLRPC_Value($value);
58
- }
59
- }
60
- if ($type == 'array') {
61
- for ($i = 0, $j = count($this->data); $i < $j; $i++) {
62
- $this->data[$i] = new NXS_XMLRPC_Value($this->data[$i]);
63
- }
64
- }
65
- }
66
-
67
- function calculateType()
68
- {
69
- if ($this->data === true || $this->data === false) {
70
- return 'boolean';
71
- }
72
- if (is_integer($this->data)) {
73
- return 'int';
74
- }
75
- if (is_double($this->data)) {
76
- return 'double';
77
- }
78
-
79
- // Deal with IXR object types base64 and date
80
- if (is_object($this->data) && is_a($this->data, 'NXS_XMLRPC_Date')) {
81
- return 'date';
82
- }
83
- if (is_object($this->data) && is_a($this->data, 'NXS_XMLRPC_Base64')) {
84
- return 'base64';
85
- }
86
-
87
- // If it is a normal PHP object convert it in to a struct
88
- if (is_object($this->data)) {
89
- $this->data = get_object_vars($this->data);
90
- return 'struct';
91
- }
92
- if (!is_array($this->data)) {
93
- return 'string';
94
- }
95
-
96
- // We have an array - is it an array or a struct?
97
- if ($this->isStruct($this->data)) {
98
- return 'struct';
99
- } else {
100
- return 'array';
101
- }
102
- }
103
-
104
- function getXml()
105
- {
106
- // Return XML for this value
107
- switch ($this->type) {
108
- case 'boolean':
109
- return '<boolean>'.(($this->data) ? '1' : '0').'</boolean>';
110
- break;
111
- case 'int':
112
- return '<int>'.$this->data.'</int>';
113
- break;
114
- case 'double':
115
- return '<double>'.$this->data.'</double>';
116
- break;
117
- case 'string':
118
- return '<string>'.htmlspecialchars($this->data).'</string>';
119
- break;
120
- case 'array':
121
- $return = '<array><data>'."\n";
122
- foreach ($this->data as $item) {
123
- $return .= ' <value>'.$item->getXml()."</value>\n";
124
- }
125
- $return .= '</data></array>';
126
- return $return;
127
- break;
128
- case 'struct':
129
- $return = '<struct>'."\n";
130
- foreach ($this->data as $name => $value) {
131
- $return .= " <member><name>$name</name><value>";
132
- $return .= $value->getXml()."</value></member>\n";
133
- }
134
- $return .= '</struct>';
135
- return $return;
136
- break;
137
- case 'date':
138
- case 'base64':
139
- return $this->data->getXml();
140
- break;
141
- }
142
- return false;
143
- }
144
-
145
- /**
146
- * Checks whether or not the supplied array is a struct or not
147
- *
148
- * @param unknown_type $array
149
- * @return boolean
150
- */
151
- function isStruct($array)
152
- {
153
- $expected = 0;
154
- foreach ($array as $key => $value) {
155
- if ((string)$key != (string)$expected) {
156
- return true;
157
- }
158
- $expected++;
159
- }
160
- return false;
161
- }
162
- }
163
-
164
- /**
165
- * NXS_XMLRPC_MESSAGE
166
- *
167
- * @package IXR
168
- * @since 1.5
169
- *
170
- */
171
- class NXS_XMLRPC_Message
172
- {
173
- var $message;
174
- var $messageType; // methodCall / methodResponse / fault
175
- var $faultCode;
176
- var $faultString;
177
- var $methodName;
178
- var $params;
179
-
180
- // Current variable stacks
181
- var $_arraystructs = array(); // The stack used to keep track of the current array/struct
182
- var $_arraystructstypes = array(); // Stack keeping track of if things are structs or array
183
- var $_currentStructName = array(); // A stack as well
184
- var $_param;
185
- var $_value;
186
- var $_currentTag;
187
- var $_currentTagContents;
188
- // The XML parser
189
- var $_parser;
190
-
191
- function NXS_XMLRPC_Message($message)
192
- {
193
- $this->message =& $message;
194
- }
195
-
196
- function parse()
197
- {
198
- // first remove the XML declaration
199
- // merged from WP #10698 - this method avoids the RAM usage of preg_replace on very large messages
200
- $header = preg_replace( '/<\?xml.*?\?'.'>/', '', substr($this->message, 0, 100), 1);
201
- $this->message = substr_replace($this->message, $header, 0, 100);
202
- if (trim($this->message) == '') {
203
- return false;
204
- }
205
- $this->_parser = xml_parser_create();
206
- // Set XML parser to take the case of tags in to account
207
- xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false);
208
- // Set XML parser callback functions
209
- xml_set_object($this->_parser, $this);
210
- xml_set_element_handler($this->_parser, 'tag_open', 'tag_close');
211
- xml_set_character_data_handler($this->_parser, 'cdata');
212
- $chunk_size = 262144; // 256Kb, parse in chunks to avoid the RAM usage on very large messages
213
- do {
214
- if (strlen($this->message) <= $chunk_size) {
215
- $final = true;
216
- }
217
- $part = substr($this->message, 0, $chunk_size);
218
- $this->message = substr($this->message, $chunk_size);
219
- if (!xml_parse($this->_parser, $part, $final)) {
220
- return false;
221
- }
222
- if ($final) {
223
- break;
224
- }
225
- } while (true);
226
- xml_parser_free($this->_parser);
227
-
228
- // Grab the error messages, if any
229
- if ($this->messageType == 'fault') {
230
- $this->faultCode = $this->params[0]['faultCode'];
231
- $this->faultString = $this->params[0]['faultString'];
232
- }
233
- return true;
234
- }
235
-
236
- function tag_open($parser, $tag, $attr)
237
- {
238
- $this->_currentTagContents = '';
239
- $this->currentTag = $tag;
240
- switch($tag) {
241
- case 'methodCall':
242
- case 'methodResponse':
243
- case 'fault':
244
- $this->messageType = $tag;
245
- break;
246
- /* Deal with stacks of arrays and structs */
247
- case 'data': // data is to all intents and puposes more interesting than array
248
- $this->_arraystructstypes[] = 'array';
249
- $this->_arraystructs[] = array();
250
- break;
251
- case 'struct':
252
- $this->_arraystructstypes[] = 'struct';
253
- $this->_arraystructs[] = array();
254
- break;
255
- }
256
- }
257
-
258
- function cdata($parser, $cdata)
259
- {
260
- $this->_currentTagContents .= $cdata;
261
- }
262
-
263
- function tag_close($parser, $tag)
264
- {
265
- $valueFlag = false;
266
- switch($tag) {
267
- case 'int':
268
- case 'i4':
269
- $value = (int)trim($this->_currentTagContents);
270
- $valueFlag = true;
271
- break;
272
- case 'double':
273
- $value = (double)trim($this->_currentTagContents);
274
- $valueFlag = true;
275
- break;
276
- case 'string':
277
- $value = (string)trim($this->_currentTagContents);
278
- $valueFlag = true;
279
- break;
280
- case 'dateTime.iso8601':
281
- $value = new NXS_XMLRPC_Date(trim($this->_currentTagContents));
282
- $valueFlag = true;
283
- break;
284
- case 'value':
285
- // "If no type is indicated, the type is string."
286
- if (trim($this->_currentTagContents) != '') {
287
- $value = (string)$this->_currentTagContents;
288
- $valueFlag = true;
289
- }
290
- break;
291
- case 'boolean':
292
- $value = (boolean)trim($this->_currentTagContents);
293
- $valueFlag = true;
294
- break;
295
- case 'base64':
296
- $value = base64_decode($this->_currentTagContents);
297
- $valueFlag = true;
298
- break;
299
- /* Deal with stacks of arrays and structs */
300
- case 'data':
301
- case 'struct':
302
- $value = array_pop($this->_arraystructs);
303
- array_pop($this->_arraystructstypes);
304
- $valueFlag = true;
305
- break;
306
- case 'member':
307
- array_pop($this->_currentStructName);
308
- break;
309
- case 'name':
310
- $this->_currentStructName[] = trim($this->_currentTagContents);
311
- break;
312
- case 'methodName':
313
- $this->methodName = trim($this->_currentTagContents);
314
- break;
315
- }
316
-
317
- if ($valueFlag) {
318
- if (count($this->_arraystructs) > 0) {
319
- // Add value to struct or array
320
- if ($this->_arraystructstypes[count($this->_arraystructstypes)-1] == 'struct') {
321
- // Add to struct
322
- $this->_arraystructs[count($this->_arraystructs)-1][$this->_currentStructName[count($this->_currentStructName)-1]] = $value;
323
- } else {
324
- // Add to array
325
- $this->_arraystructs[count($this->_arraystructs)-1][] = $value;
326
- }
327
- } else {
328
- // Just add as a paramater
329
- $this->params[] = $value;
330
- }
331
- }
332
- $this->_currentTagContents = '';
333
- }
334
- }
335
-
336
- /**
337
- * NXS_XMLRPC_Server
338
- *
339
- * @package IXR
340
- * @since 1.5
341
- */
342
- class NXS_XMLRPC_Server
343
- {
344
- var $data;
345
- var $callbacks = array();
346
- var $message;
347
- var $capabilities;
348
-
349
- function NXS_XMLRPC_Server($callbacks = false, $data = false, $wait = false)
350
- {
351
- $this->setCapabilities();
352
- if ($callbacks) {
353
- $this->callbacks = $callbacks;
354
- }
355
- $this->setCallbacks();
356
- if (!$wait) {
357
- $this->serve($data);
358
- }
359
- }
360
-
361
- function serve($data = false)
362
- {
363
- if (!$data) {
364
- if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] !== 'POST') {
365
- header('Content-Type: text/plain'); // merged from WP #9093
366
- die('XML-RPC server accepts POST requests only.');
367
- }
368
-
369
- global $HTTP_RAW_POST_DATA;
370
- if (empty($HTTP_RAW_POST_DATA)) {
371
- // workaround for a bug in PHP 5.2.2 - http://bugs.php.net/bug.php?id=41293
372
- $data = file_get_contents('php://input');
373
- } else {
374
- $data =& $HTTP_RAW_POST_DATA;
375
- }
376
- }
377
- $this->message = new NXS_XMLRPC_Message($data);
378
- if (!$this->message->parse()) {
379
- $this->error(-32700, 'parse error. not well formed');
380
- }
381
- if ($this->message->messageType != 'methodCall') {
382
- $this->error(-32600, 'server error. invalid xml-rpc. not conforming to spec. Request must be a methodCall');
383
- }
384
- $result = $this->call($this->message->methodName, $this->message->params);
385
-
386
- // Is the result an error?
387
- if (is_a($result, 'NXS_XMLRPC_Error')) {
388
- $this->error($result);
389
- }
390
-
391
- // Encode the result
392
- $r = new NXS_XMLRPC_Value($result);
393
- $resultxml = $r->getXml();
394
-
395
- // Create the XML
396
- $xml = <<<EOD
397
- <methodResponse>
398
- <params>
399
- <param>
400
- <value>
401
- $resultxml
402
- </value>
403
- </param>
404
- </params>
405
- </methodResponse>
406
-
407
- EOD;
408
- // Send it
409
- $this->output($xml);
410
- }
411
-
412
- function call($methodname, $args)
413
- {
414
- if (!$this->hasMethod($methodname)) {
415
- return new NXS_XMLRPC_Error(-32601, 'server error. requested method '.$methodname.' does not exist.');
416
- }
417
- $method = $this->callbacks[$methodname];
418
-
419
- // Perform the callback and send the response
420
- if (count($args) == 1) {
421
- // If only one paramater just send that instead of the whole array
422
- $args = $args[0];
423
- }
424
-
425
- // Are we dealing with a function or a method?
426
- if (is_string($method) && substr($method, 0, 5) == 'this:') {
427
- // It's a class method - check it exists
428
- $method = substr($method, 5);
429
- if (!method_exists($this, $method)) {
430
- return new NXS_XMLRPC_Error(-32601, 'server error. requested class method "'.$method.'" does not exist.');
431
- }
432
-
433
- //Call the method
434
- $result = $this->$method($args);
435
- } else {
436
- // It's a function - does it exist?
437
- if (is_array($method)) {
438
- if (!method_exists($method[0], $method[1])) {
439
- return new NXS_XMLRPC_Error(-32601, 'server error. requested object method "'.$method[1].'" does not exist.');
440
- }
441
- } else if (!function_exists($method)) {
442
- return new NXS_XMLRPC_Error(-32601, 'server error. requested function "'.$method.'" does not exist.');
443
- }
444
-
445
- // Call the function
446
- $result = call_user_func($method, $args);
447
- }
448
- return $result;
449
- }
450
-
451
- function error($error, $message = false)
452
- {
453
- // Accepts either an error object or an error code and message
454
- if ($message && !is_object($error)) {
455
- $error = new NXS_XMLRPC_Error($error, $message);
456
- }
457
- $this->output($error->getXml());
458
- }
459
-
460
- function output($xml)
461
- {
462
- $xml = '<?xml version="1.0"?>'."\n".$xml;
463
- $length = strlen($xml);
464
- header('Connection: close');
465
- header('Content-Length: '.$length);
466
- header('Content-Type: text/xml');
467
- header('Date: '.date('r'));
468
- echo $xml;
469
- exit;
470
- }
471
-
472
- function hasMethod($method)
473
- {
474
- return in_array($method, array_keys($this->callbacks));
475
- }
476
-
477
- function setCapabilities()
478
- {
479
- // Initialises capabilities array
480
- $this->capabilities = array(
481
- 'xmlrpc' => array(
482
- 'specUrl' => 'http://www.xmlrpc.com/spec',
483
- 'specVersion' => 1
484
- ),
485
- 'faults_interop' => array(
486
- 'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php',
487
- 'specVersion' => 20010516
488
- ),
489
- 'system.multicall' => array(
490
- 'specUrl' => 'http://www.xmlrpc.com/discuss/msgReader$1208',
491
- 'specVersion' => 1
492
- ),
493
- );
494
- }
495
-
496
- function getCapabilities($args)
497
- {
498
- return $this->capabilities;
499
- }
500
-
501
- function setCallbacks()
502
- {
503
- $this->callbacks['system.getCapabilities'] = 'this:getCapabilities';
504
- $this->callbacks['system.listMethods'] = 'this:listMethods';
505
- $this->callbacks['system.multicall'] = 'this:multiCall';
506
- }
507
-
508
- function listMethods($args)
509
- {
510
- // Returns a list of methods - uses array_reverse to ensure user defined
511
- // methods are listed before server defined methods
512
- return array_reverse(array_keys($this->callbacks));
513
- }
514
-
515
- function multiCall($methodcalls)
516
- {
517
- // See http://www.xmlrpc.com/discuss/msgReader$1208
518
- $return = array();
519
- foreach ($methodcalls as $call) {
520
- $method = $call['methodName'];
521
- $params = $call['params'];
522
- if ($method == 'system.multicall') {
523
- $result = new NXS_XMLRPC_Error(-32600, 'Recursive calls to system.multicall are forbidden');
524
- } else {
525
- $result = $this->call($method, $params);
526
- }
527
- if (is_a($result, 'NXS_XMLRPC_Error')) {
528
- $return[] = array(
529
- 'faultCode' => $result->code,
530
- 'faultString' => $result->message
531
- );
532
- } else {
533
- $return[] = array($result);
534
- }
535
- }
536
- return $return;
537
- }
538
- }
539
-
540
- /**
541
- * NXS_XMLRPC_Request
542
- *
543
- * @package IXR
544
- * @since 1.5
545
- */
546
- class NXS_XMLRPC_Request
547
- {
548
- var $method;
549
- var $args;
550
- var $xml;
551
-
552
- function NXS_XMLRPC_Request($method, $args)
553
- {
554
- $this->method = $method;
555
- $this->args = $args;
556
- $this->xml = <<<EOD
557
- <?xml version="1.0"?>
558
- <methodCall>
559
- <methodName>{$this->method}</methodName>
560
- <params>
561
-
562
- EOD;
563
- foreach ($this->args as $arg) {
564
- $this->xml .= '<param><value>';
565
- $v = new NXS_XMLRPC_Value($arg);
566
- $this->xml .= $v->getXml();
567
- $this->xml .= "</value></param>\n";
568
- }
569
- $this->xml .= '</params></methodCall>';
570
- }
571
-
572
- function getLength()
573
- {
574
- return strlen($this->xml);
575
- }
576
-
577
- function getXml()
578
- {
579
- return $this->xml;
580
- }
581
- }
582
-
583
- /**
584
- * NXS_XMLRPC_Client
585
- *
586
- * @package IXR
587
- * @since 1.5
588
- *
589
- */
590
- class NXS_XMLRPC_Client
591
- {
592
- var $server;
593
- var $port;
594
- var $path;
595
- var $useragent;
596
- var $response;
597
- var $message = false;
598
- var $debug = false;
599
- var $timeout;
600
-
601
- // Storage place for an error message
602
- var $error = false;
603
-
604
- function NXS_XMLRPC_Client($server, $path = false, $port = 80, $timeout = 15)
605
- {
606
- if (!$path) {
607
- // Assume we have been given a URL instead
608
- $bits = parse_url($server);
609
- $this->server = $bits['host'];
610
- $this->port = isset($bits['port']) ? $bits['port'] : 80;
611
- $this->path = isset($bits['path']) ? $bits['path'] : '/';
612
-
613
- // Make absolutely sure we have a path
614
- if (!$this->path) {
615
- $this->path = '/';
616
- }
617
- } else {
618
- $this->server = $server;
619
- $this->path = $path;
620
- $this->port = $port;
621
- }
622
- $this->useragent = 'The Incutio XML-RPC PHP Library';
623
- $this->timeout = $timeout;
624
- }
625
-
626
- function queryFS()
627
- {
628
- $args = func_get_args();
629
- $method = array_shift($args);
630
- $request = new NXS_XMLRPC_Request($method, $args);
631
- $length = $request->getLength();
632
- $xml = $request->getXml();
633
- $r = "\r\n";
634
- $request = "POST {$this->path} HTTP/1.0$r";
635
-
636
- // Merged from WP #8145 - allow custom headers
637
- $this->headers['Host'] = $this->server;
638
- $this->headers['Content-Type'] = 'text/xml';
639
- $this->headers['User-Agent'] = $this->useragent;
640
- $this->headers['Content-Length']= $length;
641
-
642
- foreach( $this->headers as $header => $value ) {
643
- $request .= "{$header}: {$value}{$r}";
644
- }
645
- $request .= $r;
646
-
647
- $request .= $xml;
648
-
649
- // Now send the request
650
- if ($this->debug) {
651
- echo '<pre class="NXS_XMLRPC_request">'.htmlspecialchars($request)."\n</pre>\n\n";
652
- }
653
-
654
- if ($this->timeout) {
655
- $fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout);
656
- } else {
657
- $fp = @fsockopen($this->server, $this->port, $errno, $errstr);
658
- }
659
- if (!$fp) {
660
- $this->error = new NXS_XMLRPC_Error(-32300, 'transport error - could not open socket');
661
- return false;
662
- }
663
- fputs($fp, $request);
664
- $contents = '';
665
- $debugContents = '';
666
- $gotFirstLine = false;
667
- $gettingHeaders = true;
668
- while (!feof($fp)) {
669
- $line = fgets($fp, 4096);
670
- if (!$gotFirstLine) {
671
- // Check line for '200'
672
- if (strstr($line, '200') === false) {
673
- $this->error = new NXS_XMLRPC_Error(-32300, 'transport error - HTTP status code was not 200');
674
- return false;
675
- }
676
- $gotFirstLine = true;
677
- }
678
- if (trim($line) == '') {
679
- $gettingHeaders = false;
680
- }
681
- if (!$gettingHeaders) {
682
- // merged from WP #12559 - remove trim
683
- $contents .= $line;
684
- }
685
- if ($this->debug) {
686
- $debugContents .= $line;
687
- }
688
- }
689
- if ($this->debug) {
690
- echo '<pre class="NXS_XMLRPC_response">'.htmlspecialchars($debugContents)."\n</pre>\n\n";
691
- }
692
-
693
- // Now parse what we've got back
694
- $this->message = new NXS_XMLRPC_Message($contents);
695
- if (!$this->message->parse()) {
696
- // XML error
697
- $this->error = new NXS_XMLRPC_Error(-32700, 'parse error. not well formed');
698
- return false;
699
- }
700
-
701
- // Is the message a fault?
702
- if ($this->message->messageType == 'fault') {
703
- $this->error = new NXS_XMLRPC_Error($this->message->faultCode, $this->message->faultString);
704
- return false;
705
- }
706
-
707
- // Message must be OK
708
- return true;
709
- }
710
-
711
- /**
712
- * Set the query to send to the XML-RPC Server
713
- * @since 0.1.0
714
- */
715
- function query()
716
- {
717
- $args = func_get_args();
718
- $method = array_shift($args);
719
- $request = new NXS_XMLRPC_Request($method, $args);
720
- $length = $request->getLength();
721
- $xml = $request->getXml();
722
-
723
- if ($this->debug) {
724
- echo '<pre>'.htmlspecialchars($xml)."\n</pre>\n\n";
725
- }
726
-
727
- //This is where we deviate from the normal query()
728
- //Rather than open a normal sock, we will actually use the cURL
729
- //extensions to make the calls, and handle the SSL stuff.
730
-
731
- //Since 04Aug2004 (0.1.3) - Need to include the port (duh...)
732
- //Since 06Oct2004 (0.1.4) - Need to include the colon!!!
733
- // (I swear I've fixed this before... ESP in live... But anyhu...)
734
- $curl=curl_init('http://' . $this->server . ':' . $this->port . $this->path);
735
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
736
-
737
- //Since 23Jun2004 (0.1.2) - Made timeout a class field
738
- curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout);
739
-
740
- if ($this->debug) {
741
- curl_setopt($curl, CURLOPT_VERBOSE, 1);
742
- }
743
-
744
- curl_setopt($curl, CURLOPT_HEADER, 1);
745
- curl_setopt($curl, CURLOPT_POST, 1);
746
- curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
747
- curl_setopt($curl, CURLOPT_PORT, $this->port);
748
- curl_setopt($curl, CURLOPT_HTTPHEADER, array(
749
- "Content-Type: text/xml",
750
- "Content-length: {$length}"));
751
-
752
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
753
-
754
- // Call cURL to do it's stuff and return us the content
755
- $contents = curl_exec($curl);
756
- curl_close($curl);
757
-
758
- // Check for 200 Code in $contents
759
- if (!strstr($contents, '200 OK')) {
760
- //There was no "200 OK" returned - we failed
761
- $this->error = new NXS_XMLRPC_Error(-32300, 'transport error - HTTP status code was not 200');
762
- return false;
763
- }
764
-
765
- if ($this->debug) {
766
- echo '<pre>'.htmlspecialchars($contents)."\n</pre>\n\n";
767
- }
768
- // Now parse what we've got back
769
- // Since 20Jun2004 (0.1.1) - We need to remove the headers first
770
- // Why I have only just found this, I will never know...
771
- // So, remove everything before the first <
772
- $contents = substr($contents,strpos($contents, '<'));
773
-
774
- $this->message = new NXS_XMLRPC_Message($contents);
775
- if (!$this->message->parse()) {
776
- // XML error
777
- $this->error = new NXS_XMLRPC_Error(-32700, 'parse error. not well formed');
778
- return false;
779
- }
780
- // Is the message a fault?
781
- if ($this->message->messageType == 'fault') {
782
- $this->error = new NXS_XMLRPC_Error($this->message->faultCode, $this->message->faultString);
783
- return false;
784
- }
785
-
786
- // Message must be OK
787
- return true;
788
- }
789
-
790
- function getResponse()
791
- {
792
- // methodResponses can only have one param - return that
793
- return $this->message->params[0];
794
- }
795
-
796
- function isError()
797
- {
798
- return (is_object($this->error));
799
- }
800
-
801
- function getErrorCode()
802
- {
803
- return $this->error->code;
804
- }
805
-
806
- function getErrorMessage()
807
- {
808
- return $this->error->message;
809
- }
810
- }
811
-
812
-
813
- /**
814
- * NXS_XMLRPC_Error
815
- *
816
- * @package IXR
817
- * @since 1.5
818
- */
819
- class NXS_XMLRPC_Error
820
- {
821
- var $code;
822
- var $message;
823
-
824
- function NXS_XMLRPC_Error($code, $message)
825
- {
826
- $this->code = $code;
827
- $this->message = htmlspecialchars($message);
828
- }
829
-
830
- function getXml()
831
- {
832
- $xml = <<<EOD
833
- <methodResponse>
834
- <fault>
835
- <value>
836
- <struct>
837
- <member>
838
- <name>faultCode</name>
839
- <value><int>{$this->code}</int></value>
840
- </member>
841
- <member>
842
- <name>faultString</name>
843
- <value><string>{$this->message}</string></value>
844
- </member>
845
- </struct>
846
- </value>
847
- </fault>
848
- </methodResponse>
849
-
850
- EOD;
851
- return $xml;
852
- }
853
- }
854
-
855
- /**
856
- * NXS_XMLRPC_Date
857
- *
858
- * @package IXR
859
- * @since 1.5
860
- */
861
- class NXS_XMLRPC_Date {
862
- var $year;
863
- var $month;
864
- var $day;
865
- var $hour;
866
- var $minute;
867
- var $second;
868
- var $timezone;
869
-
870
- function NXS_XMLRPC_Date($time)
871
- {
872
- // $time can be a PHP timestamp or an ISO one
873
- if (is_numeric($time)) {
874
- $this->parseTimestamp($time);
875
- } else {
876
- $this->parseIso($time);
877
- }
878
- }
879
-
880
- function parseTimestamp($timestamp)
881
- {
882
- $this->year = date('Y', $timestamp);
883
- $this->month = date('m', $timestamp);
884
- $this->day = date('d', $timestamp);
885
- $this->hour = date('H', $timestamp);
886
- $this->minute = date('i', $timestamp);
887
- $this->second = date('s', $timestamp);
888
- $this->timezone = '';
889
- }
890
-
891
- function parseIso($iso)
892
- {
893
- $this->year = substr($iso, 0, 4);
894
- $this->month = substr($iso, 4, 2);
895
- $this->day = substr($iso, 6, 2);
896
- $this->hour = substr($iso, 9, 2);
897
- $this->minute = substr($iso, 12, 2);
898
- $this->second = substr($iso, 15, 2);
899
- $this->timezone = substr($iso, 17);
900
- }
901
-
902
- function getIso()
903
- {
904
- return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second.$this->timezone;
905
- }
906
-
907
- function getXml()
908
- {
909
- return '<dateTime.iso8601>'.$this->getIso().'</dateTime.iso8601>';
910
- }
911
-
912
- function getTimestamp()
913
- {
914
- return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year);
915
- }
916
- }
917
-
918
- /**
919
- * NXS_XMLRPC_Base64
920
- *
921
- * @package IXR
922
- * @since 1.5
923
- */
924
- class NXS_XMLRPC_Base64
925
- {
926
- var $data;
927
-
928
- function NXS_XMLRPC_Base64($data)
929
- {
930
- $this->data = $data;
931
- }
932
-
933
- function getXml()
934
- {
935
- return '<base64>'.base64_encode($this->data).'</base64>';
936
- }
937
- }
938
-
939
- /**
940
- * NXS_XMLRPC_IntrospectionServer
941
- *
942
- * @package IXR
943
- * @since 1.5
944
- */
945
- class NXS_XMLRPC_IntrospectionServer extends NXS_XMLRPC_Server
946
- {
947
- var $signatures;
948
- var $help;
949
-
950
- function NXS_XMLRPC_IntrospectionServer()
951
- {
952
- $this->setCallbacks();
953
- $this->setCapabilities();
954
- $this->capabilities['introspection'] = array(
955
- 'specUrl' => 'http://xmlrpc.usefulinc.com/doc/reserved.html',
956
- 'specVersion' => 1
957
- );
958
- $this->addCallback(
959
- 'system.methodSignature',
960
- 'this:methodSignature',
961
- array('array', 'string'),
962
- 'Returns an array describing the return type and required parameters of a method'
963
- );
964
- $this->addCallback(
965
- 'system.getCapabilities',
966
- 'this:getCapabilities',
967
- array('struct'),
968
- 'Returns a struct describing the XML-RPC specifications supported by this server'
969
- );
970
- $this->addCallback(
971
- 'system.listMethods',
972
- 'this:listMethods',
973
- array('array'),
974
- 'Returns an array of available methods on this server'
975
- );
976
- $this->addCallback(
977
- 'system.methodHelp',
978
- 'this:methodHelp',
979
- array('string', 'string'),
980
- 'Returns a documentation string for the specified method'
981
- );
982
- }
983
-
984
- function addCallback($method, $callback, $args, $help)
985
- {
986
- $this->callbacks[$method] = $callback;
987
- $this->signatures[$method] = $args;
988
- $this->help[$method] = $help;
989
- }
990
-
991
- function call($methodname, $args)
992
- {
993
- // Make sure it's in an array
994
- if ($args && !is_array($args)) {
995
- $args = array($args);
996
- }
997
-
998
- // Over-rides default call method, adds signature check
999
- if (!$this->hasMethod($methodname)) {
1000
- return new NXS_XMLRPC_Error(-32601, 'server error. requested method "'.$this->message->methodName.'" not specified.');
1001
- }
1002
- $method = $this->callbacks[$methodname];
1003
- $signature = $this->signatures[$methodname];
1004
- $returnType = array_shift($signature);
1005
-
1006
- // Check the number of arguments
1007
- if (count($args) != count($signature)) {
1008
- return new NXS_XMLRPC_Error(-32602, 'server error. wrong number of method parameters');
1009
- }
1010
-
1011
- // Check the argument types
1012
- $ok = true;
1013
- $argsbackup = $args;
1014
- for ($i = 0, $j = count($args); $i < $j; $i++) {
1015
- $arg = array_shift($args);
1016
- $type = array_shift($signature);
1017
- switch ($type) {
1018
- case 'int':
1019
- case 'i4':
1020
- if (is_array($arg) || !is_int($arg)) {
1021
- $ok = false;
1022
- }
1023
- break;
1024
- case 'base64':
1025
- case 'string':
1026
- if (!is_string($arg)) {
1027
- $ok = false;
1028
- }
1029
- break;
1030
- case 'boolean':
1031
- if ($arg !== false && $arg !== true) {
1032
- $ok = false;
1033
- }
1034
- break;
1035
- case 'float':
1036
- case 'double':
1037
- if (!is_float($arg)) {
1038
- $ok = false;
1039
- }
1040
- break;
1041
- case 'date':
1042
- case 'dateTime.iso8601':
1043
- if (!is_a($arg, 'NXS_XMLRPC_Date')) {
1044
- $ok = false;
1045
- }
1046
- break;
1047
- }
1048
- if (!$ok) {
1049
- return new NXS_XMLRPC_Error(-32602, 'server error. invalid method parameters');
1050
- }
1051
- }
1052
- // It passed the test - run the "real" method call
1053
- return parent::call($methodname, $argsbackup);
1054
- }
1055
-
1056
- function methodSignature($method)
1057
- {
1058
- if (!$this->hasMethod($method)) {
1059
- return new NXS_XMLRPC_Error(-32601, 'server error. requested method "'.$method.'" not specified.');
1060
- }
1061
- // We should be returning an array of types
1062
- $types = $this->signatures[$method];
1063
- $return = array();
1064
- foreach ($types as $type) {
1065
- switch ($type) {
1066
- case 'string':
1067
- $return[] = 'string';
1068
- break;
1069
- case 'int':
1070
- case 'i4':
1071
- $return[] = 42;
1072
- break;
1073
- case 'double':
1074
- $return[] = 3.1415;
1075
- break;
1076
- case 'dateTime.iso8601':
1077
- $return[] = new NXS_XMLRPC_Date(time());
1078
- break;
1079
- case 'boolean':
1080
- $return[] = true;
1081
- break;
1082
- case 'base64':
1083
- $return[] = new NXS_XMLRPC_Base64('base64');
1084
- break;
1085
- case 'array':
1086
- $return[] = array('array');
1087
- break;
1088
- case 'struct':
1089
- $return[] = array('struct' => 'struct');
1090
- break;
1091
- }
1092
- }
1093
- return $return;
1094
- }
1095
-
1096
- function methodHelp($method)
1097
- {
1098
- return $this->help[$method];
1099
- }
1100
- }
1101
-
1102
- /**
1103
- * NXS_XMLRPC_ClientMulticall
1104
- *
1105
- * @package IXR
1106
- * @since 1.5
1107
- */
1108
- class NXS_XMLRPC_ClientMulticall extends NXS_XMLRPC_Client
1109
- {
1110
- var $calls = array();
1111
-
1112
- function NXS_XMLRPC_ClientMulticall($server, $path = false, $port = 80)
1113
- {
1114
- parent::NXS_XMLRPC_Client($server, $path, $port);
1115
- $this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)';
1116
- }
1117
-
1118
- function addCall()
1119
- {
1120
- $args = func_get_args();
1121
- $methodName = array_shift($args);
1122
- $struct = array(
1123
- 'methodName' => $methodName,
1124
- 'params' => $args
1125
- );
1126
- $this->calls[] = $struct;
1127
- }
1128
-
1129
- function query()
1130
- {
1131
- // Prepare multicall, then call the parent::query() method
1132
- return parent::query('system.multicall', $this->calls);
1133
- }
1134
- }
1135
-
1136
- /**
1137
- * Client for communicating with a XML-RPC Server over HTTPS.
1138
- *
1139
- * @author Jason Stirk <jstirk@gmm.com.au> (@link http://blog.griffin.homelinux.org/projects/xmlrpc/)
1140
- * @version 0.2.0 26May2005 08:34 +0800
1141
- * @copyright (c) 2004-2005 Jason Stirk
1142
- * @package IXR
1143
- */
1144
- class NXS_XMLRPC_ClientSSL extends NXS_XMLRPC_Client
1145
- {
1146
- /**
1147
- * Filename of the SSL Client Certificate
1148
- * @access private
1149
- * @since 0.1.0
1150
- * @var string
1151
- */
1152
- var $_certFile;
1153
-
1154
- /**
1155
- * Filename of the SSL CA Certificate
1156
- * @access private
1157
- * @since 0.1.0
1158
- * @var string
1159
- */
1160
- var $_caFile;
1161
-
1162
- /**
1163
- * Filename of the SSL Client Private Key
1164
- * @access private
1165
- * @since 0.1.0
1166
- * @var string
1167
- */
1168
- var $_keyFile;
1169
-
1170
- /**
1171
- * Passphrase to unlock the private key
1172
- * @access private
1173
- * @since 0.1.0
1174
- * @var string
1175
- */
1176
- var $_passphrase;
1177
-
1178
- /**
1179
- * Constructor
1180
- * @param string $server URL of the Server to connect to
1181
- * @since 0.1.0
1182
- */
1183
- function NXS_XMLRPC_ClientSSL($server, $path = false, $port = 443, $timeout = false)
1184
- {
1185
- parent::NXS_XMLRPC_Client($server, $path, $port, $timeout);
1186
- $this->useragent = 'The Incutio XML-RPC PHP Library for SSL';
1187
-
1188
- // Set class fields
1189
- $this->_certFile=false;
1190
- $this->_caFile=false;
1191
- $this->_keyFile=false;
1192
- $this->_passphrase='';
1193
- }
1194
-
1195
- /**
1196
- * Set the client side certificates to communicate with the server.
1197
- *
1198
- * @since 0.1.0
1199
- * @param string $certificateFile Filename of the client side certificate to use
1200
- * @param string $keyFile Filename of the client side certificate's private key
1201
- * @param string $keyPhrase Passphrase to unlock the private key
1202
- */
1203
- function setCertificate($certificateFile, $keyFile, $keyPhrase='')
1204
- {
1205
- // Check the files all exist
1206
- if (is_file($certificateFile)) {
1207
- $this->_certFile = $certificateFile;
1208
- } else {
1209
- die('Could not open certificate: ' . $certificateFile);
1210
- }
1211
-
1212
- if (is_file($keyFile)) {
1213
- $this->_keyFile = $keyFile;
1214
- } else {
1215
- die('Could not open private key: ' . $keyFile);
1216
- }
1217
-
1218
- $this->_passphrase=(string)$keyPhrase;
1219
- }
1220
-
1221
- function setCACertificate($caFile)
1222
- {
1223
- if (is_file($caFile)) {
1224
- $this->_caFile = $caFile;
1225
- } else {
1226
- die('Could not open CA certificate: ' . $caFile);
1227
- }
1228
- }
1229
-
1230
- /**
1231
- * Sets the connection timeout (in seconds)
1232
- * @param int $newTimeOut Timeout in seconds
1233
- * @returns void
1234
- * @since 0.1.2
1235
- */
1236
- function setTimeOut($newTimeOut)
1237
- {
1238
- $this->timeout = (int)$newTimeOut;
1239
- }
1240
-
1241
- /**
1242
- * Returns the connection timeout (in seconds)
1243
- * @returns int
1244
- * @since 0.1.2
1245
- */
1246
- function getTimeOut()
1247
- {
1248
- return $this->timeout;
1249
- }
1250
-
1251
- /**
1252
- * Set the query to send to the XML-RPC Server
1253
- * @since 0.1.0
1254
- */
1255
- function query()
1256
- {
1257
- $args = func_get_args();
1258
- $method = array_shift($args);
1259
- $request = new NXS_XMLRPC_Request($method, $args);
1260
- $length = $request->getLength();
1261
- $xml = $request->getXml();
1262
-
1263
- if ($this->debug) {
1264
- echo '<pre>'.htmlspecialchars($xml)."\n</pre>\n\n";
1265
- }
1266
-
1267
- //This is where we deviate from the normal query()
1268
- //Rather than open a normal sock, we will actually use the cURL
1269
- //extensions to make the calls, and handle the SSL stuff.
1270
-
1271
- //Since 04Aug2004 (0.1.3) - Need to include the port (duh...)
1272
- //Since 06Oct2004 (0.1.4) - Need to include the colon!!!
1273
- // (I swear I've fixed this before... ESP in live... But anyhu...)
1274
- $curl=curl_init('https://' . $this->server . ':' . $this->port . $this->path);
1275
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
1276
-
1277
- //Since 23Jun2004 (0.1.2) - Made timeout a class field
1278
- curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout);
1279
-
1280
- if ($this->debug) {
1281
- curl_setopt($curl, CURLOPT_VERBOSE, 1);
1282
- }
1283
-
1284
- curl_setopt($curl, CURLOPT_HEADER, 1);
1285
- curl_setopt($curl, CURLOPT_POST, 1);
1286
- curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
1287
- curl_setopt($curl, CURLOPT_PORT, $this->port);
1288
- curl_setopt($curl, CURLOPT_HTTPHEADER, array(
1289
- "Content-Type: text/xml",
1290
- "Content-length: {$length}"));
1291
-
1292
- // Process the SSL certificates, etc. to use
1293
- if (!($this->_certFile === false)) {
1294
- // We have a certificate file set, so add these to the cURL handler
1295
- curl_setopt($curl, CURLOPT_SSLCERT, $this->_certFile);
1296
- curl_setopt($curl, CURLOPT_SSLKEY, $this->_keyFile);
1297
-
1298
- if ($this->debug) {
1299
- echo "SSL Cert at : " . $this->_certFile . "\n";
1300
- echo "SSL Key at : " . $this->_keyFile . "\n";
1301
- }
1302
-
1303
- // See if we need to give a passphrase
1304
- if (!($this->_passphrase === '')) {
1305
- curl_setopt($curl, CURLOPT_SSLCERTPASSWD, $this->_passphrase);
1306
- }
1307
-
1308
- if ($this->_caFile === false) {
1309
- // Don't verify their certificate, as we don't have a CA to verify against
1310
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
1311
- } else {
1312
- // Verify against a CA
1313
- curl_setopt($curl, CURLOPT_CAINFO, $this->_caFile);
1314
- }
1315
- }
1316
-
1317
- // Call cURL to do it's stuff and return us the content
1318
- $contents = curl_exec($curl);
1319
- curl_close($curl);
1320
-
1321
- // Check for 200 Code in $contents
1322
- if (!strstr($contents, '200 OK')) {
1323
- //There was no "200 OK" returned - we failed
1324
- $this->error = new NXS_XMLRPC_Error(-32300, 'transport error - HTTP status code was not 200');
1325
- return false;
1326
- }
1327
-
1328
- if ($this->debug) {
1329
- echo '<pre>'.htmlspecialchars($contents)."\n</pre>\n\n";
1330
- }
1331
- // Now parse what we've got back
1332
- // Since 20Jun2004 (0.1.1) - We need to remove the headers first
1333
- // Why I have only just found this, I will never know...
1334
- // So, remove everything before the first <
1335
- $contents = substr($contents,strpos($contents, '<'));
1336
-
1337
- $this->message = new NXS_XMLRPC_Message($contents);
1338
- if (!$this->message->parse()) {
1339
- // XML error
1340
- $this->error = new NXS_XMLRPC_Error(-32700, 'parse error. not well formed');
1341
- return false;
1342
- }
1343
- // Is the message a fault?
1344
- if ($this->message->messageType == 'fault') {
1345
- $this->error = new NXS_XMLRPC_Error($this->message->faultCode, $this->message->faultString);
1346
- return false;
1347
- }
1348
-
1349
- // Message must be OK
1350
- return true;
1351
- }
1352
- }
1353
-
1354
- /**
1355
- * Extension of the {@link NXS_XMLRPC_Server} class to easily wrap objects.
1356
- *
1357
- * Class is designed to extend the existing XML-RPC server to allow the
1358
- * presentation of methods from a variety of different objects via an
1359
- * XML-RPC server.
1360
- * It is intended to assist in organization of your XML-RPC methods by allowing
1361
- * you to "write once" in your existing model classes and present them.
1362
- *
1363
- * @author Jason Stirk <jstirk@gmm.com.au>
1364
- * @version 1.0.1 19Apr2005 17:40 +0800
1365
- * @copyright Copyright (c) 2005 Jason Stirk
1366
- * @package IXR
1367
- */
1368
- class NXS_XMLRPC_ClassServer extends NXS_XMLRPC_Server
1369
- {
1370
- var $_objects;
1371
- var $_delim;
1372
-
1373
- function NXS_XMLRPC_ClassServer($delim = '.', $wait = false)
1374
- {
1375
- $this->NXS_XMLRPC_Server(array(), false, $wait);
1376
- $this->_delimiter = $delim;
1377
- $this->_objects = array();
1378
- }
1379
-
1380
- function addMethod($rpcName, $functionName)
1381
- {
1382
- $this->callbacks[$rpcName] = $functionName;
1383
- }
1384
-
1385
- function registerObject($object, $methods, $prefix=null)
1386
- {
1387
- if (is_null($prefix))
1388
- {
1389
- $prefix = get_class($object);
1390
- }
1391
- $this->_objects[$prefix] = $object;
1392
-
1393
- // Add to our callbacks array
1394
- foreach($methods as $method)
1395
- {
1396
- if (is_array($method))
1397
- {
1398
- $targetMethod = $method[0];
1399
- $method = $method[1];
1400
- }
1401
- else
1402
- {
1403
- $targetMethod = $method;
1404
- }
1405
- $this->callbacks[$prefix . $this->_delimiter . $method]=array($prefix, $targetMethod);
1406
- }
1407
- }
1408
-
1409
- function call($methodname, $args)
1410
- {
1411
- if (!$this->hasMethod($methodname)) {
1412
- return new NXS_XMLRPC_Error(-32601, 'server error. requested method '.$methodname.' does not exist.');
1413
- }
1414
- $method = $this->callbacks[$methodname];
1415
-
1416
- // Perform the callback and send the response
1417
- if (count($args) == 1) {
1418
- // If only one paramater just send that instead of the whole array
1419
- $args = $args[0];
1420
- }
1421
-
1422
- // See if this method comes from one of our objects or maybe self
1423
- if (is_array($method) || (substr($method, 0, 5) == 'this:')) {
1424
- if (is_array($method)) {
1425
- $object=$this->_objects[$method[0]];
1426
- $method=$method[1];
1427
- } else {
1428
- $object=$this;
1429
- $method = substr($method, 5);
1430
- }
1431
-
1432
- // It's a class method - check it exists
1433
- if (!method_exists($object, $method)) {
1434
- return new NXS_XMLRPC_Error(-32601, 'server error. requested class method "'.$method.'" does not exist.');
1435
- }
1436
-
1437
- // Call the method
1438
- $result = $object->$method($args);
1439
- } else {
1440
- // It's a function - does it exist?
1441
- if (!function_exists($method)) {
1442
- return new NXS_XMLRPC_Error(-32601, 'server error. requested function "'.$method.'" does not exist.');
1443
- }
1444
-
1445
- // Call the function
1446
- $result = $method($args);
1447
- }
1448
- return $result;
1449
- }
1450
- }
1451
  ?>
1
+ <?php
2
+ /**
3
+ * IXR - The Incutio XML-RPC Library
4
+ *
5
+ * Copyright (c) 2010, Incutio Ltd.
6
+ * All rights reserved.
7
+ *
8
+ * Redistribution and use in source and binary forms, with or without
9
+ * modification, are permitted provided that the following conditions are met:
10
+ *
11
+ * - Redistributions of source code must retain the above copyright notice,
12
+ * this list of conditions and the following disclaimer.
13
+ * - Redistributions in binary form must reproduce the above copyright
14
+ * notice, this list of conditions and the following disclaimer in the
15
+ * documentation and/or other materials provided with the distribution.
16
+ * - Neither the name of Incutio Ltd. nor the names of its contributors
17
+ * may be used to endorse or promote products derived from this software
18
+ * without specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
24
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
28
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ *
32
+ * @package IXR
33
+ * @since 1.5
34
+ *
35
+ * @copyright Incutio Ltd 2010 (http://www.incutio.com)
36
+ * @version 1.7.4 7th September 2010
37
+ * @author Simon Willison
38
+ * @link http://scripts.incutio.com/xmlrpc/ Site/manual
39
+ */
40
+
41
+
42
+ class NXS_XMLRPC_Value
43
+ {
44
+ var $data;
45
+ var $type;
46
+
47
+ function NXS_XMLRPC_Value($data, $type = false)
48
+ {
49
+ $this->data = $data;
50
+ if (!$type) {
51
+ $type = $this->calculateType();
52
+ }
53
+ $this->type = $type;
54
+ if ($type == 'struct') {
55
+ // Turn all the values in the array in to new NXS_XMLRPC_Value objects
56
+ foreach ($this->data as $key => $value) {
57
+ $this->data[$key] = new NXS_XMLRPC_Value($value);
58
+ }
59
+ }
60
+ if ($type == 'array') {
61
+ for ($i = 0, $j = count($this->data); $i < $j; $i++) {
62
+ $this->data[$i] = new NXS_XMLRPC_Value($this->data[$i]);
63
+ }
64
+ }
65
+ }
66
+
67
+ function calculateType()
68
+ {
69
+ if ($this->data === true || $this->data === false) {
70
+ return 'boolean';
71
+ }
72
+ if (is_integer($this->data)) {
73
+ return 'int';
74
+ }
75
+ if (is_double($this->data)) {
76
+ return 'double';
77
+ }
78
+
79
+ // Deal with IXR object types base64 and date
80
+ if (is_object($this->data) && is_a($this->data, 'NXS_XMLRPC_Date')) {
81
+ return 'date';
82
+ }
83
+ if (is_object($this->data) && is_a($this->data, 'NXS_XMLRPC_Base64')) {
84
+ return 'base64';
85
+ }
86
+
87
+ // If it is a normal PHP object convert it in to a struct
88
+ if (is_object($this->data)) {
89
+ $this->data = get_object_vars($this->data);
90
+ return 'struct';
91
+ }
92
+ if (!is_array($this->data)) {
93
+ return 'string';
94
+ }
95
+
96
+ // We have an array - is it an array or a struct?
97
+ if ($this->isStruct($this->data)) {
98
+ return 'struct';
99
+ } else {
100
+ return 'array';
101
+ }
102
+ }
103
+
104
+ function getXml()
105
+ {
106
+ // Return XML for this value
107
+ switch ($this->type) {
108
+ case 'boolean':
109
+ return '<boolean>'.(($this->data) ? '1' : '0').'</boolean>';
110
+ break;
111
+ case 'int':
112
+ return '<int>'.$this->data.'</int>';
113
+ break;
114
+ case 'double':
115
+ return '<double>'.$this->data.'</double>';
116
+ break;
117
+ case 'string':
118
+ return '<string>'.htmlspecialchars($this->data).'</string>';
119
+ break;
120
+ case 'array':
121
+ $return = '<array><data>'."\n";
122
+ foreach ($this->data as $item) {
123
+ $return .= ' <value>'.$item->getXml()."</value>\n";
124
+ }
125
+ $return .= '</data></array>';
126
+ return $return;
127
+ break;
128
+ case 'struct':
129
+ $return = '<struct>'."\n";
130
+ foreach ($this->data as $name => $value) {
131
+ $return .= " <member><name>$name</name><value>";
132
+ $return .= $value->getXml()."</value></member>\n";
133
+ }
134
+ $return .= '</struct>';
135
+ return $return;
136
+ break;
137
+ case 'date':
138
+ case 'base64':
139
+ return $this->data->getXml();
140
+ break;
141
+ }
142
+ return false;
143
+ }
144
+
145
+ /**
146
+ * Checks whether or not the supplied array is a struct or not
147
+ *
148
+ * @param unknown_type $array
149
+ * @return boolean
150
+ */
151
+ function isStruct($array)
152
+ {
153
+ $expected = 0;
154
+ foreach ($array as $key => $value) {
155
+ if ((string)$key != (string)$expected) {
156
+ return true;
157
+ }
158
+ $expected++;
159
+ }
160
+ return false;
161
+ }
162
+ }
163
+
164
+ /**
165
+ * NXS_XMLRPC_MESSAGE
166
+ *
167
+ * @package IXR
168
+ * @since 1.5
169
+ *
170
+ */
171
+ class NXS_XMLRPC_Message
172
+ {
173
+ var $message;
174
+ var $messageType; // methodCall / methodResponse / fault
175
+ var $faultCode;
176
+ var $faultString;
177
+ var $methodName;
178
+ var $params;
179
+
180
+ // Current variable stacks
181
+ var $_arraystructs = array(); // The stack used to keep track of the current array/struct
182
+ var $_arraystructstypes = array(); // Stack keeping track of if things are structs or array
183
+ var $_currentStructName = array(); // A stack as well
184
+ var $_param;
185
+ var $_value;
186
+ var $_currentTag;
187
+ var $_currentTagContents;
188
+ // The XML parser
189
+ var $_parser;
190
+
191
+ function NXS_XMLRPC_Message($message)
192
+ {
193
+ $this->message =& $message;
194
+ }
195
+
196
+ function parse()
197
+ {
198
+ // first remove the XML declaration
199
+ // merged from WP #10698 - this method avoids the RAM usage of preg_replace on very large messages
200
+ $header = preg_replace( '/<\?xml.*?\?'.'>/', '', substr($this->message, 0, 100), 1);
201
+ $this->message = substr_replace($this->message, $header, 0, 100);
202
+ if (trim($this->message) == '') {
203
+ return false;
204
+ }
205
+ $this->_parser = xml_parser_create();
206
+ // Set XML parser to take the case of tags in to account
207
+ xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false);
208
+ // Set XML parser callback functions
209
+ xml_set_object($this->_parser, $this);
210
+ xml_set_element_handler($this->_parser, 'tag_open', 'tag_close');
211
+ xml_set_character_data_handler($this->_parser, 'cdata');
212
+ $chunk_size = 262144; // 256Kb, parse in chunks to avoid the RAM usage on very large messages
213
+ do {
214
+ if (strlen($this->message) <= $chunk_size) {
215
+ $final = true;
216
+ }
217
+ $part = substr($this->message, 0, $chunk_size);
218
+ $this->message = substr($this->message, $chunk_size);
219
+ if (!xml_parse($this->_parser, $part, $final)) {
220
+ return false;
221
+ }
222
+ if ($final) {
223
+ break;
224
+ }
225
+ } while (true);
226
+ xml_parser_free($this->_parser);
227
+
228
+ // Grab the error messages, if any
229
+ if ($this->messageType == 'fault') {
230
+ $this->faultCode = $this->params[0]['faultCode'];
231
+ $this->faultString = $this->params[0]['faultString'];
232
+ }
233
+ return true;
234
+ }
235
+
236
+ function tag_open($parser, $tag, $attr)
237
+ {
238
+ $this->_currentTagContents = '';
239
+ $this->currentTag = $tag;
240
+ switch($tag) {
241
+ case 'methodCall':
242
+ case 'methodResponse':
243
+ case 'fault':
244
+ $this->messageType = $tag;
245
+ break;
246
+ /* Deal with stacks of arrays and structs */
247
+ case 'data': // data is to all intents and puposes more interesting than array
248
+ $this->_arraystructstypes[] = 'array';
249
+ $this->_arraystructs[] = array();
250
+ break;
251
+ case 'struct':
252
+ $this->_arraystructstypes[] = 'struct';
253
+ $this->_arraystructs[] = array();
254
+ break;
255
+ }
256
+ }
257
+
258
+ function cdata($parser, $cdata)
259
+ {
260
+ $this->_currentTagContents .= $cdata;
261
+ }
262
+
263
+ function tag_close($parser, $tag)
264
+ {
265
+ $valueFlag = false;
266
+ switch($tag) {
267
+ case 'int':
268
+ case 'i4':
269
+ $value = (int)trim($this->_currentTagContents);
270
+ $valueFlag = true;
271
+ break;
272
+ case 'double':
273
+ $value = (double)trim($this->_currentTagContents);
274
+ $valueFlag = true;
275
+ break;
276
+ case 'string':
277
+ $value = (string)trim($this->_currentTagContents);
278
+ $valueFlag = true;
279
+ break;
280
+ case 'dateTime.iso8601':
281
+ $value = new NXS_XMLRPC_Date(trim($this->_currentTagContents));
282
+ $valueFlag = true;
283
+ break;
284
+ case 'value':
285
+ // "If no type is indicated, the type is string."
286
+ if (trim($this->_currentTagContents) != '') {
287
+ $value = (string)$this->_currentTagContents;
288
+ $valueFlag = true;
289
+ }
290
+ break;
291
+ case 'boolean':
292
+ $value = (boolean)trim($this->_currentTagContents);
293
+ $valueFlag = true;
294
+ break;
295
+ case 'base64':
296
+ $value = base64_decode($this->_currentTagContents);
297
+ $valueFlag = true;
298
+ break;
299
+ /* Deal with stacks of arrays and structs */
300
+ case 'data':
301
+ case 'struct':
302
+ $value = array_pop($this->_arraystructs);
303
+ array_pop($this->_arraystructstypes);
304
+ $valueFlag = true;
305
+ break;
306
+ case 'member':
307
+ array_pop($this->_currentStructName);
308
+ break;
309
+ case 'name':
310
+ $this->_currentStructName[] = trim($this->_currentTagContents);
311
+ break;
312
+ case 'methodName':
313
+ $this->methodName = trim($this->_currentTagContents);
314
+ break;
315
+ }
316
+
317
+ if ($valueFlag) {
318
+ if (count($this->_arraystructs) > 0) {
319
+ // Add value to struct or array
320
+ if ($this->_arraystructstypes[count($this->_arraystructstypes)-1] == 'struct') {
321
+ // Add to struct
322
+ $this->_arraystructs[count($this->_arraystructs)-1][$this->_currentStructName[count($this->_currentStructName)-1]] = $value;
323
+ } else {
324
+ // Add to array
325
+ $this->_arraystructs[count($this->_arraystructs)-1][] = $value;
326
+ }
327
+ } else {
328
+ // Just add as a paramater
329
+ $this->params[] = $value;
330
+ }
331
+ }
332
+ $this->_currentTagContents = '';
333
+ }
334
+ }
335
+
336
+ /**
337
+ * NXS_XMLRPC_Server
338
+ *
339
+ * @package IXR
340
+ * @since 1.5
341
+ */
342
+ class NXS_XMLRPC_Server
343
+ {
344
+ var $data;
345
+ var $callbacks = array();
346
+ var $message;
347
+ var $capabilities;
348
+
349
+ function NXS_XMLRPC_Server($callbacks = false, $data = false, $wait = false)
350
+ {
351
+ $this->setCapabilities();
352
+ if ($callbacks) {
353
+ $this->callbacks = $callbacks;
354
+ }
355
+ $this->setCallbacks();
356
+ if (!$wait) {
357
+ $this->serve($data);
358
+ }
359
+ }
360
+
361
+ function serve($data = false)
362
+ {
363
+ if (!$data) {
364
+ if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] !== 'POST') {
365
+ header('Content-Type: text/plain'); // merged from WP #9093
366
+ die('XML-RPC server accepts POST requests only.');
367
+ }
368
+
369
+ global $HTTP_RAW_POST_DATA;
370
+ if (empty($HTTP_RAW_POST_DATA)) {
371
+ // workaround for a bug in PHP 5.2.2 - http://bugs.php.net/bug.php?id=41293
372
+ $data = file_get_contents('php://input');
373
+ } else {
374
+ $data =& $HTTP_RAW_POST_DATA;
375
+ }
376
+ }
377
+ $this->message = new NXS_XMLRPC_Message($data);
378
+ if (!$this->message->parse()) {
379
+ $this->error(-32700, 'parse error. not well formed');
380
+ }
381
+ if ($this->message->messageType != 'methodCall') {
382
+ $this->error(-32600, 'server error. invalid xml-rpc. not conforming to spec. Request must be a methodCall');
383
+ }
384
+ $result = $this->call($this->message->methodName, $this->message->params);
385
+
386
+ // Is the result an error?
387
+ if (is_a($result, 'NXS_XMLRPC_Error')) {
388
+ $this->error($result);
389
+ }
390
+
391
+ // Encode the result
392
+ $r = new NXS_XMLRPC_Value($result);
393
+ $resultxml = $r->getXml();
394
+
395
+ // Create the XML
396
+ $xml = <<<EOD
397
+ <methodResponse>
398
+ <params>
399
+ <param>
400
+ <value>
401
+ $resultxml
402
+ </value>
403
+ </param>
404
+ </params>
405
+ </methodResponse>
406
+
407
+ EOD;
408
+ // Send it
409
+ $this->output($xml);
410
+ }
411
+
412
+ function call($methodname, $args)
413
+ {
414
+ if (!$this->hasMethod($methodname)) {
415
+ return new NXS_XMLRPC_Error(-32601, 'server error. requested method '.$methodname.' does not exist.');
416
+ }
417
+ $method = $this->callbacks[$methodname];
418
+
419
+ // Perform the callback and send the response
420
+ if (count($args) == 1) {
421
+ // If only one paramater just send that instead of the whole array
422
+ $args = $args[0];
423
+ }
424
+
425
+ // Are we dealing with a function or a method?
426
+ if (is_string($method) && substr($method, 0, 5) == 'this:') {
427
+ // It's a class method - check it exists
428
+ $method = substr($method, 5);
429
+ if (!method_exists($this, $method)) {
430
+ return new NXS_XMLRPC_Error(-32601, 'server error. requested class method "'.$method.'" does not exist.');
431
+ }
432
+
433
+ //Call the method
434
+ $result = $this->$method($args);
435
+ } else {
436
+ // It's a function - does it exist?
437
+ if (is_array($method)) {
438
+ if (!method_exists($method[0], $method[1])) {
439
+ return new NXS_XMLRPC_Error(-32601, 'server error. requested object method "'.$method[1].'" does not exist.');
440
+ }
441
+ } else if (!function_exists($method)) {
442
+ return new NXS_XMLRPC_Error(-32601, 'server error. requested function "'.$method.'" does not exist.');
443
+ }
444
+
445
+ // Call the function
446
+ $result = call_user_func($method, $args);
447
+ }
448
+ return $result;
449
+ }
450
+
451
+ function error($error, $message = false)
452
+ {
453
+ // Accepts either an error object or an error code and message
454
+ if ($message && !is_object($error)) {
455
+ $error = new NXS_XMLRPC_Error($error, $message);
456
+ }
457
+ $this->output($error->getXml());
458
+ }
459
+
460
+ function output($xml)
461
+ {
462
+ $xml = '<?xml version="1.0"?>'."\n".$xml;
463
+ $length = strlen($xml);
464
+ header('Connection: close');
465
+ header('Content-Length: '.$length);
466
+ header('Content-Type: text/xml');
467
+ header('Date: '.date('r'));
468
+ echo $xml;
469
+ exit;
470
+ }
471
+
472
+ function hasMethod($method)
473
+ {
474
+ return in_array($method, array_keys($this->callbacks));
475
+ }
476
+
477
+ function setCapabilities()
478
+ {
479
+ // Initialises capabilities array
480
+ $this->capabilities = array(
481
+ 'xmlrpc' => array(
482
+ 'specUrl' => 'http://www.xmlrpc.com/spec',
483
+ 'specVersion' => 1
484
+ ),
485
+ 'faults_interop' => array(
486
+ 'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php',
487
+ 'specVersion' => 20010516
488
+ ),
489
+ 'system.multicall' => array(
490
+ 'specUrl' => 'http://www.xmlrpc.com/discuss/msgReader$1208',
491
+ 'specVersion' => 1
492
+ ),
493
+ );
494
+ }
495
+
496
+ function getCapabilities($args)
497
+ {
498
+ return $this->capabilities;
499
+ }
500
+
501
+ function setCallbacks()
502
+ {
503
+ $this->callbacks['system.getCapabilities'] = 'this:getCapabilities';
504
+ $this->callbacks['system.listMethods'] = 'this:listMethods';
505
+ $this->callbacks['system.multicall'] = 'this:multiCall';
506
+ }
507
+
508
+ function listMethods($args)
509
+ {
510
+ // Returns a list of methods - uses array_reverse to ensure user defined
511
+ // methods are listed before server defined methods
512
+ return array_reverse(array_keys($this->callbacks));
513
+ }
514
+
515
+ function multiCall($methodcalls)
516
+ {
517
+ // See http://www.xmlrpc.com/discuss/msgReader$1208
518
+ $return = array();
519
+ foreach ($methodcalls as $call) {
520
+ $method = $call['methodName'];
521
+ $params = $call['params'];
522
+ if ($method == 'system.multicall') {
523
+ $result = new NXS_XMLRPC_Error(-32600, 'Recursive calls to system.multicall are forbidden');
524
+ } else {
525
+ $result = $this->call($method, $params);
526
+ }
527
+ if (is_a($result, 'NXS_XMLRPC_Error')) {
528
+ $return[] = array(
529
+ 'faultCode' => $result->code,
530
+ 'faultString' => $result->message
531
+ );
532
+ } else {
533
+ $return[] = array($result);
534
+ }
535
+ }
536
+ return $return;
537
+ }
538
+ }
539
+
540
+ /**
541
+ * NXS_XMLRPC_Request
542
+ *
543
+ * @package IXR
544
+ * @since 1.5
545
+ */
546
+ class NXS_XMLRPC_Request
547
+ {
548
+ var $method;
549
+ var $args;
550
+ var $xml;
551
+
552
+ function NXS_XMLRPC_Request($method, $args)
553
+ {
554
+ $this->method = $method;
555
+ $this->args = $args;
556
+ $this->xml = <<<EOD
557
+ <?xml version="1.0"?>
558
+ <methodCall>
559
+ <methodName>{$this->method}</methodName>
560
+ <params>
561
+
562
+ EOD;
563
+ foreach ($this->args as $arg) {
564
+ $this->xml .= '<param><value>';
565
+ $v = new NXS_XMLRPC_Value($arg);
566
+ $this->xml .= $v->getXml();
567
+ $this->xml .= "</value></param>\n";
568
+ }
569
+ $this->xml .= '</params></methodCall>';
570
+ }
571
+
572
+ function getLength()
573
+ {
574
+ return strlen($this->xml);
575
+ }
576
+
577
+ function getXml()
578
+ {
579
+ return $this->xml;
580
+ }
581
+ }
582
+
583
+ /**
584
+ * NXS_XMLRPC_Client
585
+ *
586
+ * @package IXR
587
+ * @since 1.5
588
+ *
589
+ */
590
+ class NXS_XMLRPC_Client
591
+ {
592
+ var $server;
593
+ var $port;
594
+ var $path;
595
+ var $useragent;
596
+ var $response;
597
+ var $message = false;
598
+ var $debug = false;
599
+ var $timeout;
600
+
601
+ // Storage place for an error message
602
+ var $error = false;
603
+
604
+ function NXS_XMLRPC_Client($server, $path = false, $port = 80, $timeout = 15)
605
+ {
606
+ if (!$path) {
607
+ // Assume we have been given a URL instead
608
+ $bits = parse_url($server);
609
+ $this->server = $bits['host'];
610
+ $this->port = isset($bits['port']) ? $bits['port'] : 80;
611
+ $this->path = isset($bits['path']) ? $bits['path'] : '/';
612
+
613
+ // Make absolutely sure we have a path
614
+ if (!$this->path) {
615
+ $this->path = '/';
616
+ }
617
+ } else {
618
+ $this->server = $server;
619
+ $this->path = $path;
620
+ $this->port = $port;
621
+ }
622
+ $this->useragent = 'The Incutio XML-RPC PHP Library';
623
+ $this->timeout = $timeout;
624
+ }
625
+
626
+ function queryFS()
627
+ {
628
+ $args = func_get_args();
629
+ $method = array_shift($args);
630
+ $request = new NXS_XMLRPC_Request($method, $args);
631
+ $length = $request->getLength();
632
+ $xml = $request->getXml();
633
+ $r = "\r\n";
634
+ $request = "POST {$this->path} HTTP/1.0$r";
635
+
636
+ // Merged from WP #8145 - allow custom headers
637
+ $this->headers['Host'] = $this->server;
638
+ $this->headers['Content-Type'] = 'text/xml';
639
+ $this->headers['User-Agent'] = $this->useragent;
640
+ $this->headers['Content-Length']= $length;
641
+
642
+ foreach( $this->headers as $header => $value ) {
643
+ $request .= "{$header}: {$value}{$r}";
644
+ }
645
+ $request .= $r;
646
+
647
+ $request .= $xml;
648
+
649
+ // Now send the request
650
+ if ($this->debug) {
651
+ echo '<pre class="NXS_XMLRPC_request">'.htmlspecialchars($request)."\n</pre>\n\n";
652
+ }
653
+
654
+ if ($this->timeout) {
655
+ $fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout);
656
+ } else {
657
+ $fp = @fsockopen($this->server, $this->port, $errno, $errstr);
658
+ }
659
+ if (!$fp) {
660
+ $this->error = new NXS_XMLRPC_Error(-32300, 'transport error - could not open socket');
661
+ return false;
662
+ }
663
+ fputs($fp, $request);
664
+ $contents = '';
665
+ $debugContents = '';
666
+ $gotFirstLine = false;
667
+ $gettingHeaders = true;
668
+ while (!feof($fp)) {
669
+ $line = fgets($fp, 4096);
670
+ if (!$gotFirstLine) {
671
+ // Check line for '200'
672
+ if (strstr($line, '200') === false) {
673
+ $this->error = new NXS_XMLRPC_Error(-32300, 'transport error - HTTP status code was not 200');
674
+ return false;
675
+ }
676
+ $gotFirstLine = true;
677
+ }
678
+ if (trim($line) == '') {
679
+ $gettingHeaders = false;
680
+ }
681
+ if (!$gettingHeaders) {
682
+ // merged from WP #12559 - remove trim
683
+ $contents .= $line;
684
+ }
685
+ if ($this->debug) {
686
+ $debugContents .= $line;
687
+ }
688
+ }
689
+ if ($this->debug) {
690
+ echo '<pre class="NXS_XMLRPC_response">'.htmlspecialchars($debugContents)."\n</pre>\n\n";
691
+ }
692
+
693
+ // Now parse what we've got back
694
+ $this->message = new NXS_XMLRPC_Message($contents);
695
+ if (!$this->message->parse()) {
696
+ // XML error
697
+ $this->error = new NXS_XMLRPC_Error(-32700, 'parse error. not well formed');
698
+ return false;
699
+ }
700
+
701
+ // Is the message a fault?
702
+ if ($this->message->messageType == 'fault') {
703
+ $this->error = new NXS_XMLRPC_Error($this->message->faultCode, $this->message->faultString);
704
+ return false;
705
+ }
706
+
707
+ // Message must be OK
708
+ return true;
709
+ }
710
+
711
+ /**
712
+ * Set the query to send to the XML-RPC Server
713
+ * @since 0.1.0
714
+ */
715
+ function query()
716
+ {
717
+ $args = func_get_args();
718
+ $method = array_shift($args);
719
+ $request = new NXS_XMLRPC_Request($method, $args);
720
+ $length = $request->getLength();
721
+ $xml = $request->getXml();
722
+
723
+ if ($this->debug) {
724
+ echo '<pre>'.htmlspecialchars($xml)."\n</pre>\n\n";
725
+ }
726
+
727
+ //This is where we deviate from the normal query()
728
+ //Rather than open a normal sock, we will actually use the cURL
729
+ //extensions to make the calls, and handle the SSL stuff.
730
+
731
+ //Since 04Aug2004 (0.1.3) - Need to include the port (duh...)
732
+ //Since 06Oct2004 (0.1.4) - Need to include the colon!!!
733
+ // (I swear I've fixed this before... ESP in live... But anyhu...)
734
+ $curl=curl_init('http://' . $this->server . ':' . $this->port . $this->path);
735
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
736
+
737
+ //Since 23Jun2004 (0.1.2) - Made timeout a class field
738
+ curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout);
739
+
740
+ if ($this->debug) {
741
+ curl_setopt($curl, CURLOPT_VERBOSE, 1);
742
+ }
743
+
744
+ curl_setopt($curl, CURLOPT_HEADER, 1);
745
+ curl_setopt($curl, CURLOPT_POST, 1);
746
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
747
+ curl_setopt($curl, CURLOPT_PORT, $this->port);
748
+ curl_setopt($curl, CURLOPT_HTTPHEADER, array(
749
+ "Content-Type: text/xml",
750
+ "Content-length: {$length}"));
751
+
752
+ curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
753
+
754
+ // Call cURL to do it's stuff and return us the content
755
+ $contents = curl_exec($curl);
756
+ curl_close($curl);
757
+
758
+ // Check for 200 Code in $contents
759
+ if (!strstr($contents, '200 OK')) {
760
+ //There was no "200 OK" returned - we failed
761
+ $this->error = new NXS_XMLRPC_Error(-32300, 'transport error - HTTP status code was not 200');
762
+ return false;
763
+ }
764
+
765
+ if ($this->debug) {
766
+ echo '<pre>'.htmlspecialchars($contents)."\n</pre>\n\n";
767
+ }
768
+ // Now parse what we've got back
769
+ // Since 20Jun2004 (0.1.1) - We need to remove the headers first
770
+ // Why I have only just found this, I will never know...
771
+ // So, remove everything before the first <
772
+ $contents = substr($contents,strpos($contents, '<'));
773
+
774
+ $this->message = new NXS_XMLRPC_Message($contents);
775
+ if (!$this->message->parse()) {
776
+ // XML error
777
+ $this->error = new NXS_XMLRPC_Error(-32700, 'parse error. not well formed');
778
+ return false;
779
+ }
780
+ // Is the message a fault?
781
+ if ($this->message->messageType == 'fault') {
782
+ $this->error = new NXS_XMLRPC_Error($this->message->faultCode, $this->message->faultString);
783
+ return false;
784
+ }
785
+
786
+ // Message must be OK
787
+ return true;
788
+ }
789
+
790
+ function getResponse()
791
+ {
792
+ // methodResponses can only have one param - return that
793
+ return $this->message->params[0];
794
+ }
795
+
796
+ function isError()
797
+ {
798
+ return (is_object($this->error));
799
+ }
800
+
801
+ function getErrorCode()
802
+ {
803
+ return $this->error->code;
804
+ }
805
+
806
+ function getErrorMessage()
807
+ {
808
+ return $this->error->message;
809
+ }
810
+ }
811
+
812
+
813
+ /**
814
+ * NXS_XMLRPC_Error
815
+ *
816
+ * @package IXR
817
+ * @since 1.5
818
+ */
819
+ class NXS_XMLRPC_Error
820
+ {
821
+ var $code;
822
+ var $message;
823
+
824
+ function NXS_XMLRPC_Error($code, $message)
825
+ {
826
+ $this->code = $code;
827
+ $this->message = htmlspecialchars($message);
828
+ }
829
+
830
+ function getXml()
831
+ {
832
+ $xml = <<<EOD
833
+ <methodResponse>
834
+ <fault>
835
+ <value>
836
+ <struct>
837
+ <member>
838
+ <name>faultCode</name>
839
+ <value><int>{$this->code}</int></value>
840
+ </member>
841
+ <member>
842
+ <name>faultString</name>
843
+ <value><string>{$this->message}</string></value>
844
+ </member>
845
+ </struct>
846
+ </value>
847
+ </fault>
848
+ </methodResponse>
849
+
850
+ EOD;
851
+ return $xml;
852
+ }
853
+ }
854
+
855
+ /**
856
+ * NXS_XMLRPC_Date
857
+ *
858
+ * @package IXR
859
+ * @since 1.5
860
+ */
861
+ class NXS_XMLRPC_Date {
862
+ var $year;
863
+ var $month;
864
+ var $day;
865
+ var $hour;
866
+ var $minute;
867
+ var $second;
868
+ var $timezone;
869
+
870
+ function NXS_XMLRPC_Date($time)
871
+ {
872
+ // $time can be a PHP timestamp or an ISO one
873
+ if (is_numeric($time)) {
874
+ $this->parseTimestamp($time);
875
+ } else {
876
+ $this->parseIso($time);
877
+ }
878
+ }
879
+
880
+ function parseTimestamp($timestamp)
881
+ {
882
+ $this->year = date('Y', $timestamp);
883
+ $this->month = date('m', $timestamp);
884
+ $this->day = date('d', $timestamp);
885
+ $this->hour = date('H', $timestamp);
886
+ $this->minute = date('i', $timestamp);
887
+ $this->second = date('s', $timestamp);
888
+ $this->timezone = '';
889
+ }
890
+
891
+ function parseIso($iso)
892
+ {
893
+ $this->year = substr($iso, 0, 4);
894
+ $this->month = substr($iso, 4, 2);
895
+ $this->day = substr($iso, 6, 2);
896
+ $this->hour = substr($iso, 9, 2);
897
+ $this->minute = substr($iso, 12, 2);
898
+ $this->second = substr($iso, 15, 2);
899
+ $this->timezone = substr($iso, 17);
900
+ }
901
+
902
+ function getIso()
903
+ {
904
+ return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second.$this->timezone;
905
+ }
906
+
907
+ function getXml()
908
+ {
909
+ return '<dateTime.iso8601>'.$this->getIso().'</dateTime.iso8601>';
910
+ }
911
+
912
+ function getTimestamp()
913
+ {
914
+ return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year);
915
+ }
916
+ }
917
+
918
+ /**
919
+ * NXS_XMLRPC_Base64
920
+ *
921
+ * @package IXR
922
+ * @since 1.5
923
+ */
924
+ class NXS_XMLRPC_Base64
925
+ {
926
+ var $data;
927
+
928
+ function NXS_XMLRPC_Base64($data)
929
+ {
930
+ $this->data = $data;
931
+ }
932
+
933
+ function getXml()
934
+ {
935
+ return '<base64>'.base64_encode($this->data).'</base64>';
936
+ }
937
+ }
938
+
939
+ /**
940
+ * NXS_XMLRPC_IntrospectionServer
941
+ *
942
+ * @package IXR
943
+ * @since 1.5
944
+ */
945
+ class NXS_XMLRPC_IntrospectionServer extends NXS_XMLRPC_Server
946
+ {
947
+ var $signatures;
948
+ var $help;
949
+
950
+ function NXS_XMLRPC_IntrospectionServer()
951
+ {
952
+ $this->setCallbacks();
953
+ $this->setCapabilities();
954
+ $this->capabilities['introspection'] = array(
955
+ 'specUrl' => 'http://xmlrpc.usefulinc.com/doc/reserved.html',
956
+ 'specVersion' => 1
957
+ );
958
+ $this->addCallback(
959
+ 'system.methodSignature',
960
+ 'this:methodSignature',
961
+ array('array', 'string'),
962
+ 'Returns an array describing the return type and required parameters of a method'
963
+ );
964
+ $this->addCallback(
965
+ 'system.getCapabilities',
966
+ 'this:getCapabilities',
967
+ array('struct'),
968
+ 'Returns a struct describing the XML-RPC specifications supported by this server'
969
+ );
970
+ $this->addCallback(
971
+ 'system.listMethods',
972
+ 'this:listMethods',
973
+ array('array'),
974
+ 'Returns an array of available methods on this server'
975
+ );
976
+ $this->addCallback(
977
+ 'system.methodHelp',
978
+ 'this:methodHelp',
979
+ array('string', 'string'),
980
+ 'Returns a documentation string for the specified method'
981
+ );
982
+ }
983
+
984
+ function addCallback($method, $callback, $args, $help)
985
+ {
986
+ $this->callbacks[$method] = $callback;
987
+ $this->signatures[$method] = $args;
988
+ $this->help[$method] = $help;
989
+ }
990
+
991
+ function call($methodname, $args)
992
+ {
993
+ // Make sure it's in an array
994
+ if ($args && !is_array($args)) {
995
+ $args = array($args);
996
+ }
997
+
998
+ // Over-rides default call method, adds signature check
999
+ if (!$this->hasMethod($methodname)) {
1000
+ return new NXS_XMLRPC_Error(-32601, 'server error. requested method "'.$this->message->methodName.'" not specified.');
1001
+ }
1002
+ $method = $this->callbacks[$methodname];
1003
+ $signature = $this->signatures[$methodname];
1004
+ $returnType = array_shift($signature);
1005
+
1006
+ // Check the number of arguments
1007
+ if (count($args) != count($signature)) {
1008
+ return new NXS_XMLRPC_Error(-32602, 'server error. wrong number of method parameters');
1009
+ }
1010
+
1011
+ // Check the argument types
1012
+ $ok = true;
1013
+ $argsbackup = $args;
1014
+ for ($i = 0, $j = count($args); $i < $j; $i++) {
1015
+ $arg = array_shift($args);
1016
+ $type = array_shift($signature);
1017
+ switch ($type) {
1018
+ case 'int':
1019
+ case 'i4':
1020
+ if (is_array($arg) || !is_int($arg)) {
1021
+ $ok = false;
1022
+ }
1023
+ break;
1024
+ case 'base64':
1025
+ case 'string':
1026
+ if (!is_string($arg)) {
1027
+ $ok = false;
1028
+ }
1029
+ break;
1030
+ case 'boolean':
1031
+ if ($arg !== false && $arg !== true) {
1032
+ $ok = false;
1033
+ }
1034
+ break;
1035
+ case 'float':
1036
+ case 'double':
1037
+ if (!is_float($arg)) {
1038
+ $ok = false;
1039
+ }
1040
+ break;
1041
+ case 'date':
1042
+ case 'dateTime.iso8601':
1043
+ if (!is_a($arg, 'NXS_XMLRPC_Date')) {
1044
+ $ok = false;
1045
+ }
1046
+ break;
1047
+ }
1048
+ if (!$ok) {
1049
+ return new NXS_XMLRPC_Error(-32602, 'server error. invalid method parameters');
1050
+ }
1051
+ }
1052
+ // It passed the test - run the "real" method call
1053
+ return parent::call($methodname, $argsbackup);
1054
+ }
1055
+
1056
+ function methodSignature($method)
1057
+ {
1058
+ if (!$this->hasMethod($method)) {
1059
+ return new NXS_XMLRPC_Error(-32601, 'server error. requested method "'.$method.'" not specified.');
1060
+ }
1061
+ // We should be returning an array of types
1062
+ $types = $this->signatures[$method];
1063
+ $return = array();
1064
+ foreach ($types as $type) {
1065
+ switch ($type) {
1066
+ case 'string':
1067
+ $return[] = 'string';
1068
+ break;
1069
+ case 'int':
1070
+ case 'i4':
1071
+ $return[] = 42;
1072
+ break;
1073
+ case 'double':
1074
+ $return[] = 3.1415;
1075
+ break;
1076
+ case 'dateTime.iso8601':
1077
+ $return[] = new NXS_XMLRPC_Date(time());
1078
+ break;
1079
+ case 'boolean':
1080
+ $return[] = true;
1081
+ break;
1082
+ case 'base64':
1083
+ $return[] = new NXS_XMLRPC_Base64('base64');
1084
+ break;
1085
+ case 'array':
1086
+ $return[] = array('array');
1087
+ break;
1088
+ case 'struct':
1089
+ $return[] = array('struct' => 'struct');
1090
+ break;
1091
+ }
1092
+ }
1093
+ return $return;
1094
+ }
1095
+
1096
+ function methodHelp($method)
1097
+ {
1098
+ return $this->help[$method];
1099
+ }
1100
+ }
1101
+
1102
+ /**
1103
+ * NXS_XMLRPC_ClientMulticall
1104
+ *
1105
+ * @package IXR
1106
+ * @since 1.5
1107
+ */
1108
+ class NXS_XMLRPC_ClientMulticall extends NXS_XMLRPC_Client
1109
+ {
1110
+ var $calls = array();
1111
+
1112
+ function NXS_XMLRPC_ClientMulticall($server, $path = false, $port = 80)
1113
+ {
1114
+ parent::NXS_XMLRPC_Client($server, $path, $port);
1115
+ $this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)';
1116
+ }
1117
+
1118
+ function addCall()
1119
+ {
1120
+ $args = func_get_args();
1121
+ $methodName = array_shift($args);
1122
+ $struct = array(
1123
+ 'methodName' => $methodName,
1124
+ 'params' => $args
1125
+ );
1126
+ $this->calls[] = $struct;
1127
+ }
1128
+
1129
+ function query()
1130
+ {
1131
+ // Prepare multicall, then call the parent::query() method
1132
+ return parent::query('system.multicall', $this->calls);
1133
+ }
1134
+ }
1135
+
1136
+ /**
1137
+ * Client for communicating with a XML-RPC Server over HTTPS.
1138
+ *
1139
+ * @author Jason Stirk <jstirk@gmm.com.au> (@link http://blog.griffin.homelinux.org/projects/xmlrpc/)
1140
+ * @version 0.2.0 26May2005 08:34 +0800
1141
+ * @copyright (c) 2004-2005 Jason Stirk
1142
+ * @package IXR
1143
+ */
1144
+ class NXS_XMLRPC_ClientSSL extends NXS_XMLRPC_Client
1145
+ {
1146
+ /**
1147
+ * Filename of the SSL Client Certificate
1148
+ * @access private
1149
+ * @since 0.1.0
1150
+ * @var string
1151
+ */
1152
+ var $_certFile;
1153
+
1154
+ /**
1155
+ * Filename of the SSL CA Certificate
1156
+ * @access private
1157
+ * @since 0.1.0
1158
+ * @var string
1159
+ */
1160
+ var $_caFile;
1161
+
1162
+ /**
1163
+ * Filename of the SSL Client Private Key
1164
+ * @access private
1165
+ * @since 0.1.0
1166
+ * @var string
1167
+ */
1168
+ var $_keyFile;
1169
+
1170
+ /**
1171
+ * Passphrase to unlock the private key
1172
+ * @access private
1173
+ * @since 0.1.0
1174
+ * @var string
1175
+ */
1176
+ var $_passphrase;
1177
+
1178
+ /**
1179
+ * Constructor
1180
+ * @param string $server URL of the Server to connect to
1181
+ * @since 0.1.0
1182
+ */
1183
+ function NXS_XMLRPC_ClientSSL($server, $path = false, $port = 443, $timeout = false)
1184
+ {
1185
+ parent::NXS_XMLRPC_Client($server, $path, $port, $timeout);
1186
+ $this->useragent = 'The Incutio XML-RPC PHP Library for SSL';
1187
+
1188
+ // Set class fields
1189
+ $this->_certFile=false;
1190
+ $this->_caFile=false;
1191
+ $this->_keyFile=false;
1192
+ $this->_passphrase='';
1193
+ }
1194
+
1195
+ /**
1196
+ * Set the client side certificates to communicate with the server.
1197
+ *
1198
+ * @since 0.1.0
1199
+ * @param string $certificateFile Filename of the client side certificate to use
1200
+ * @param string $keyFile Filename of the client side certificate's private key
1201
+ * @param string $keyPhrase Passphrase to unlock the private key
1202
+ */
1203
+ function setCertificate($certificateFile, $keyFile, $keyPhrase='')
1204
+ {
1205
+ // Check the files all exist
1206
+ if (is_file($certificateFile)) {
1207
+ $this->_certFile = $certificateFile;
1208
+ } else {
1209
+ die('Could not open certificate: ' . $certificateFile);
1210
+ }
1211
+
1212
+ if (is_file($keyFile)) {
1213
+ $this->_keyFile = $keyFile;
1214
+ } else {
1215
+ die('Could not open private key: ' . $keyFile);
1216
+ }
1217
+
1218
+ $this->_passphrase=(string)$keyPhrase;
1219
+ }
1220
+
1221
+ function setCACertificate($caFile)
1222
+ {
1223
+ if (is_file($caFile)) {
1224
+ $this->_caFile = $caFile;
1225
+ } else {
1226
+ die('Could not open CA certificate: ' . $caFile);
1227
+ }
1228
+ }
1229
+
1230
+ /**
1231
+ * Sets the connection timeout (in seconds)
1232
+ * @param int $newTimeOut Timeout in seconds
1233
+ * @returns void
1234
+ * @since 0.1.2
1235
+ */
1236
+ function setTimeOut($newTimeOut)
1237
+ {
1238
+ $this->timeout = (int)$newTimeOut;
1239
+ }
1240
+
1241
+ /**
1242
+ * Returns the connection timeout (in seconds)
1243
+ * @returns int
1244
+ * @since 0.1.2
1245
+ */
1246
+ function getTimeOut()
1247
+ {
1248
+ return $this->timeout;
1249
+ }
1250
+
1251
+ /**
1252
+ * Set the query to send to the XML-RPC Server
1253
+ * @since 0.1.0
1254
+ */
1255
+ function query()
1256
+ {
1257
+ $args = func_get_args();
1258
+ $method = array_shift($args);
1259
+ $request = new NXS_XMLRPC_Request($method, $args);
1260
+ $length = $request->getLength();
1261
+ $xml = $request->getXml();
1262
+
1263
+ if ($this->debug) {
1264
+ echo '<pre>'.htmlspecialchars($xml)."\n</pre>\n\n";
1265
+ }
1266
+
1267
+ //This is where we deviate from the normal query()
1268
+ //Rather than open a normal sock, we will actually use the cURL
1269
+ //extensions to make the calls, and handle the SSL stuff.
1270
+
1271
+ //Since 04Aug2004 (0.1.3) - Need to include the port (duh...)
1272
+ //Since 06Oct2004 (0.1.4) - Need to include the colon!!!
1273
+ // (I swear I've fixed this before... ESP in live... But anyhu...)
1274
+ $curl=curl_init('https://' . $this->server . ':' . $this->port . $this->path);
1275
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
1276
+
1277
+ //Since 23Jun2004 (0.1.2) - Made timeout a class field
1278
+ curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout);
1279
+
1280
+ if ($this->debug) {
1281
+ curl_setopt($curl, CURLOPT_VERBOSE, 1);
1282
+ }
1283
+
1284
+ curl_setopt($curl, CURLOPT_HEADER, 1);
1285
+ curl_setopt($curl, CURLOPT_POST, 1);
1286
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
1287
+ curl_setopt($curl, CURLOPT_PORT, $this->port);
1288
+ curl_setopt($curl, CURLOPT_HTTPHEADER, array(
1289
+ "Content-Type: text/xml",
1290
+ "Content-length: {$length}"));
1291
+
1292
+ // Process the SSL certificates, etc. to use
1293
+ if (!($this->_certFile === false)) {
1294
+ // We have a certificate file set, so add these to the cURL handler
1295
+ curl_setopt($curl, CURLOPT_SSLCERT, $this->_certFile);
1296
+ curl_setopt($curl, CURLOPT_SSLKEY, $this->_keyFile);
1297
+
1298
+ if ($this->debug) {
1299
+ echo "SSL Cert at : " . $this->_certFile . "\n";
1300
+ echo "SSL Key at : " . $this->_keyFile . "\n";
1301
+ }
1302
+
1303
+ // See if we need to give a passphrase
1304
+ if (!($this->_passphrase === '')) {
1305
+ curl_setopt($curl, CURLOPT_SSLCERTPASSWD, $this->_passphrase);
1306
+ }
1307
+
1308
+ if ($this->_caFile === false) {
1309
+ // Don't verify their certificate, as we don't have a CA to verify against
1310
+ curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
1311
+ } else {
1312
+ // Verify against a CA
1313
+ curl_setopt($curl, CURLOPT_CAINFO, $this->_caFile);
1314
+ }
1315
+ }
1316
+
1317
+ // Call cURL to do it's stuff and return us the content
1318
+ $contents = curl_exec($curl);
1319
+ curl_close($curl);
1320
+
1321
+ // Check for 200 Code in $contents
1322
+ if (!strstr($contents, '200 OK')) {
1323
+ //There was no "200 OK" returned - we failed
1324
+ $this->error = new NXS_XMLRPC_Error(-32300, 'transport error - HTTP status code was not 200');
1325
+ return false;
1326
+ }
1327
+
1328
+ if ($this->debug) {
1329
+ echo '<pre>'.htmlspecialchars($contents)."\n</pre>\n\n";
1330
+ }
1331
+ // Now parse what we've got back
1332
+ // Since 20Jun2004 (0.1.1) - We need to remove the headers first
1333
+ // Why I have only just found this, I will never know...
1334
+ // So, remove everything before the first <
1335
+ $contents = substr($contents,strpos($contents, '<'));
1336
+
1337
+ $this->message = new NXS_XMLRPC_Message($contents);
1338
+ if (!$this->message->parse()) {
1339
+ // XML error
1340
+ $this->error = new NXS_XMLRPC_Error(-32700, 'parse error. not well formed');
1341
+ return false;
1342
+ }
1343
+ // Is the message a fault?
1344
+ if ($this->message->messageType == 'fault') {
1345
+ $this->error = new NXS_XMLRPC_Error($this->message->faultCode, $this->message->faultString);
1346
+ return false;
1347
+ }
1348
+
1349
+ // Message must be OK
1350
+ return true;
1351
+ }
1352
+ }
1353
+
1354
+ /**
1355
+ * Extension of the {@link NXS_XMLRPC_Server} class to easily wrap objects.
1356
+ *
1357
+ * Class is designed to extend the existing XML-RPC server to allow the
1358
+ * presentation of methods from a variety of different objects via an
1359
+ * XML-RPC server.
1360
+ * It is intended to assist in organization of your XML-RPC methods by allowing
1361
+ * you to "write once" in your existing model classes and present them.
1362
+ *
1363
+ * @author Jason Stirk <jstirk@gmm.com.au>
1364
+ * @version 1.0.1 19Apr2005 17:40 +0800
1365
+ * @copyright Copyright (c) 2005 Jason Stirk
1366
+ * @package IXR
1367
+ */
1368
+ class NXS_XMLRPC_ClassServer extends NXS_XMLRPC_Server
1369
+ {
1370
+ var $_objects;
1371
+ var $_delim;
1372
+
1373
+ function NXS_XMLRPC_ClassServer($delim = '.', $wait = false)
1374
+ {
1375
+ $this->NXS_XMLRPC_Server(array(), false, $wait);
1376
+ $this->_delimiter = $delim;
1377
+ $this->_objects = array();
1378
+ }
1379
+
1380
+ function addMethod($rpcName, $functionName)
1381
+ {
1382
+ $this->callbacks[$rpcName] = $functionName;
1383
+ }
1384
+
1385
+ function registerObject($object, $methods, $prefix=null)
1386
+ {
1387
+ if (is_null($prefix))
1388
+ {
1389
+ $prefix = get_class($object);
1390
+ }
1391
+ $this->_objects[$prefix] = $object;
1392
+
1393
+ // Add to our callbacks array
1394
+ foreach($methods as $method)
1395
+ {
1396
+ if (is_array($method))
1397
+ {
1398
+ $targetMethod = $method[0];
1399
+ $method = $method[1];
1400
+ }
1401
+ else
1402
+ {
1403
+ $targetMethod = $method;
1404
+ }
1405
+ $this->callbacks[$prefix . $this->_delimiter . $method]=array($prefix, $targetMethod);
1406
+ }
1407
+ }
1408
+
1409
+ function call($methodname, $args)
1410
+ {
1411
+ if (!$this->hasMethod($methodname)) {
1412
+ return new NXS_XMLRPC_Error(-32601, 'server error. requested method '.$methodname.' does not exist.');
1413
+ }
1414
+ $method = $this->callbacks[$methodname];
1415
+
1416
+ // Perform the callback and send the response
1417
+ if (count($args) == 1) {
1418
+ // If only one paramater just send that instead of the whole array
1419
+ $args = $args[0];
1420
+ }
1421
+
1422
+ // See if this method comes from one of our objects or maybe self
1423
+ if (is_array($method) || (substr($method, 0, 5) == 'this:')) {
1424
+ if (is_array($method)) {
1425
+ $object=$this->_objects[$method[0]];
1426
+ $method=$method[1];
1427
+ } else {
1428
+ $object=$this;
1429
+ $method = substr($method, 5);
1430
+ }
1431
+
1432
+ // It's a class method - check it exists
1433
+ if (!method_exists($object, $method)) {
1434
+ return new NXS_XMLRPC_Error(-32601, 'server error. requested class method "'.$method.'" does not exist.');
1435
+ }
1436
+
1437
+ // Call the method
1438
+ $result = $object->$method($args);
1439
+ } else {
1440
+ // It's a function - does it exist?
1441
+ if (!function_exists($method)) {
1442
+ return new NXS_XMLRPC_Error(-32601, 'server error. requested function "'.$method.'" does not exist.');
1443
+ }
1444
+
1445
+ // Call the function
1446
+ $result = $method($args);
1447
+ }
1448
+ return $result;
1449
+ }
1450
+ }
1451
  ?>
inc-cl/bg.php CHANGED
@@ -1,237 +1,240 @@
1
- <?php
2
- //## NextScripts Facebook Connection Class
3
- $nxs_snapAvNts[] = array('code'=>'BG', 'lcode'=>'bg', 'name'=>'Blogger');
4
-
5
- if (!class_exists("nxs_snapClassBG")) { class nxs_snapClassBG {
6
- //#### Show Common Settings
7
- function showGenNTSettings($ntOpts){ global $nxs_plurl; $ntInfo = array('code'=>'BG', 'lcode'=>'bg', 'name'=>'Blogger', 'defNName'=>'diUName', 'tstReq' => true); ?>
8
- <div class="nxs_box">
9
- <div class="nxs_box_header">
10
- <div class="nsx_iconedTitle" style="margin-bottom:1px;background-image:url(<?php echo $nxs_plurl;?>img/<?php echo $ntInfo['lcode']; ?>16.png);"><?php echo $ntInfo['name']; ?>
11
- <?php $cbo = count($ntOpts); ?> <?php wp_nonce_field( 'ns'.$ntInfo['code'], 'ns'.$ntInfo['code'].'_wpnonce' ); ?>
12
- <?php if ($cbo>1){ ?><div class="nsBigText"><?php echo "(".($cbo=='0'?'No':$cbo)." "; _e('accounts', 'nxs_snap'); echo ")"; ?></div><?php } ?>
13
- </div>
14
- </div>
15
- <div class="nxs_box_inside">
16
- <?php foreach ($ntOpts as $indx=>$pbo){ if (trim($pbo['nName']=='')) $pbo['nName'] = $pbo[$ntInfo['defNName']]; ?>
17
- <p style="margin:0px;margin-left:5px;">
18
- <input value="1" name="<?php echo $ntInfo['lcode']; ?>[<?php echo $indx; ?>][apDo<?php echo $ntInfo['code']; ?>]" onchange="doShowHideBlocks('<?php echo $ntInfo['code']; ?>');" type="checkbox" <?php if ((int)$pbo['do'.$ntInfo['code']] == 1) echo "checked"; ?> /> <?php if ((int)$pbo['catSel'] == 1) { ?> <span onmouseout="nxs_hidePopUpInfo('popOnlyCat');" onmouseover="nxs_showPopUpInfo('popOnlyCat', event);"><?php echo "*[".(substr_count($pbo['catSelEd'], ",")+1)."]*" ?></span><?php } ?>
19
- <strong><?php _e('Auto-publish to', 'nxs_snap'); ?> <?php echo $ntInfo['name']; ?> <i style="color: #005800;"><?php if($pbo['nName']!='') echo "(".$pbo['nName'].")"; ?></i></strong>
20
- &nbsp;&nbsp;<?php if ($ntInfo['tstReq'] && (!isset($pbo[$ntInfo['lcode'].'OK']) || $pbo[$ntInfo['lcode'].'OK']=='')){ ?><b style="color: #800000"><?php _e('Attention requred. Unfinished setup', 'nxs_snap'); ?> ==&gt;</b><?php } ?><a id="do<?php echo $ntInfo['code'].$indx; ?>A" href="#" onclick="doShowHideBlocks2('<?php echo $ntInfo['code'].$indx; ?>');return false;">[<?php _e('Show Settings', 'nxs_snap'); ?>]</a>&nbsp;&nbsp;
21
- <a href="#" onclick="doDelAcct('<?php echo $ntInfo['lcode']; ?>', '<?php echo $indx; ?>', '<?php if (isset($pbo['bgBlogID'])) echo $pbo['nName']; ?>');return false;">[<?php _e('Remove Account', 'nxs_snap'); ?>]</a>
22
- </p><?php $this->showNTSettings($indx, $pbo);
23
- }?>
24
- </div>
25
- </div> <?php //## END Settings
26
- }
27
- //#### Show NEW Settings Page
28
- function showNewNTSettings($bo){ $po = array('nName'=>'', 'doBG'=>'1', 'bgUName'=>'', 'bgPass'=>'', 'bgBlogID'=>'', 'bgInclTags'=>'1', 'bgMsgFormat'=>'%FULLTEXT% <br/><a href=\'%URL%\'>%TITLE%</a>', 'bgMsgTFormat'=>'%TITLE%' ); $this->showNTSettings($bo, $po, true);}
29
- //#### Show Unit Settings
30
- function showNTSettings($ii, $options, $isNew=false){ global $nxs_plurl; ?>
31
- <div id="doBG<?php echo $ii; ?>Div" class="insOneDiv<?php if ($isNew){ ?> clNewNTSets<?php } ?>" style="background-image: url(<?php echo $nxs_plurl; ?>img/bg-bg.png);background-position:90% 10%;"> <input type="hidden" name="apDoSBG<?php echo $ii; ?>" value="0" id="apDoSBG<?php echo $ii; ?>" />
32
- <?php if ($isNew) { ?> <input type="hidden" name="bg[<?php echo $ii; ?>][apDoBG]" value="1" id="apDoNewBG<?php echo $ii; ?>" /> <?php } ?>
33
-
34
- <div style="display: none;"><input name="bg[<?php echo $ii; ?>][apBGPassChr]" id="apBGPassChr" type="password" value="" /></div>
35
-
36
- <div id="doBG<?php echo $ii; ?>Div" style="margin-left: 10px;"> <div class="nsx_iconedTitle" style="float: right; background-image: url(<?php echo $nxs_plurl; ?>img/bg16.png);"><a style="font-size: 12px;" target="_blank" href="http://www.nextscripts.com/setup-installation-blogger-social-networks-auto-poster-wordpress/"><?php $nType="Blogger"; printf( __( 'Detailed %s Installation/Configuration Instructions', 'nxs_snap' ), $nType); ?></a></div>
37
-
38
- <div style="width:100%;"><strong><?php _e('Account Nickname', 'nxs_snap'); ?>:</strong> <i><?php _e('Just so you can easely identify it', 'nxs_snap'); ?></i> </div><input name="bg[<?php echo $ii; ?>][nName]" id="bgnName<?php echo $ii; ?>" style="font-weight: bold; color: #005800; border: 1px solid #ACACAC; width: 40%;" value="<?php _e(apply_filters('format_to_edit',htmlentities($options['nName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /><br/>
39
- <?php echo nxs_addQTranslSel('bg', $ii, $options['qTLng']); ?>
40
- <?php echo nxs_addPostingDelaySel('bg', $ii, $options['nHrs'], $options['nMin']); ?>
41
-
42
- <?php if (!$isNew) { ?>
43
- <div style="width:100%;"><strong><?php _e('Categories', 'nxs_snap'); ?>:</strong>
44
- <input value="0" id="catSelA<?php echo $ii; ?>" type="radio" name="bg[<?php echo $ii; ?>][catSel]" <?php if ((int)$options['catSel'] != 1) echo "checked"; ?> /> All
45
- <input value="1" id="catSelSBG<?php echo $ii; ?>" type="radio" name="bg[<?php echo $ii; ?>][catSel]" <?php if ((int)$options['catSel'] == 1) echo "checked"; ?> /> <a href="#" style="text-decoration: none;" class="showCats" id="nxs_SCA_BG<?php echo $ii; ?>" onclick="jQuery('#catSelSBG<?php echo $ii; ?>').attr('checked', true); jQuery('#tmpCatSelNT').val('BG<?php echo $ii; ?>'); nxs_markCats( jQuery('#nxs_SC_BG<?php echo $ii; ?>').val() ); jQuery('#showCatSel').bPopup({ modalClose: false, appendTo: '#nsStForm', opacity: 0.6, follow: [false, false], position: [75, 'auto']}); return false;">Selected<?php if ($options['catSelEd']!='') echo "[".(substr_count($options['catSelEd'], ",")+1)."]"; ?></a>
46
- <input type="hidden" name="bg[<?php echo $ii; ?>][catSelEd]" id="nxs_SC_BG<?php echo $ii; ?>" value="<?php echo $options['catSelEd']; ?>" />
47
- <br/><i><?php _e('Only selected categories will be autoposted to this account', 'nxs_snap'); ?></i>
48
- </div>
49
- <br/>
50
- <?php } ?>
51
-
52
- <div style="width:100%;"><strong>Blogger Username/Email:</strong> </div><input name="bg[<?php echo $ii; ?>][apBGUName]" id="apBGUName" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit',htmlentities($options['bgUName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
53
- <div style="width:100%;"><strong>Blogger Password:</strong> </div><input name="bg[<?php echo $ii; ?>][apBGPass]" id="apBGPass" autocomplete="off" type="password" style="width: 30%;" value="<?php if (trim($options['bgPass'])!='') _e(apply_filters('format_to_edit', htmlentities(substr($options['bgPass'], 0, 5)=='b4d7s'?nsx_doDecode(substr($options['bgPass'], 5)):$options['bgPass'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /> <br/>
54
- <div style="width:100%;"><strong>Blogger Blog ID:</strong>
55
- <p style="font-size: 11px; margin: 0px;"><?php _e('Log to your Blogger management panel and look at the URL of your blog: http://www.blogger.com/blogger.g?blogID=8959085979163812093#allposts. Your Blog ID will be: 8959085979163812093', 'nxs_snap'); ?></p>
56
- </div><input name="bg[<?php echo $ii; ?>][apBGBlogID]" id="apBGBlogID" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['bgBlogID'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
57
- <br/><br/>
58
-
59
- <div style="width:100%;"><strong id="altFormatText"><?php _e('Post Title Format', 'nxs_snap'); ?>:</strong> (<a href="#" id="apBGTMsgFrmt<?php echo $ii; ?>HintInfo" onclick="mxs_showHideFrmtInfo('apBGTMsgFrmt<?php echo $ii; ?>'); return false;"><?php _e('Show format info', 'nxs_snap'); ?></a>)</div>
60
-
61
- <input name="bg[<?php echo $ii; ?>][apBGMsgTFrmt]" id="apBGMsgTFrmt" style="width: 50%;" value="<?php if ($options['bgMsgTFormat']!='') _e(apply_filters('format_to_edit', htmlentities($options['bgMsgTFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap'); else echo "%TITLE%"; ?>" onfocus="mxs_showFrmtInfo('apBGTMsgFrmt<?php echo $ii; ?>');" /><?php nxs_doShowHint("apBGTMsgFrmt".$ii); ?><br/>
62
-
63
- <div id="altFormat" style="">
64
- <div style="width:100%;"><strong id="altFormatText"><?php _e('Post Text Format', 'nxs_snap'); ?>:</strong> (<a href="#" id="apBGMsgFrmt<?php echo $ii; ?>HintInfo" onclick="mxs_showHideFrmtInfo('apBGMsgFrmt<?php echo $ii; ?>'); return false;"><?php _e('Show format info', 'nxs_snap'); ?></a>)
65
-
66
- <!--
67
- HTML is <?php if(!function_exists('doPostToGooglePlus')) {?> <b>NOT</b> <?php } ?> allowed. <?php if(!function_exists('doPostToGooglePlus')) {?> <i>- Blogger "Free API" limitation. Please get <a href="http://www.nextscripts.com/google-plus-automated-posting/#blogger">NextScripts API</a> to allow HTML</i> <?php } ?> -->
68
- </div>
69
-
70
- <textarea cols="150" rows="3" id="bg<?php echo $ii; ?>SNAPformat" name="bg[<?php echo $ii; ?>][apBGMsgFrmt]" style="width:51%;max-width: 650px;" onfocus="jQuery('#bg<?php echo $ii; ?>SNAPformat').attr('rows', 6); mxs_showFrmtInfo('apBGMsgFrmt<?php echo $ii; ?>');"><?php if ($options['bgMsgFormat']!='') _e(apply_filters('format_to_edit',htmlentities($options['bgMsgFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap'); else echo "%FULLTEXT% <br/><a href='%URL%'>%TITLE%</a>"; ?></textarea>
71
-
72
- <?php nxs_doShowHint("apBGMsgFrmt".$ii, __('HTML is allowed', 'nxs_snap')); ?>
73
- </div>
74
-
75
- <p style="margin-bottom: 20px;margin-top: 5px;"><input value="1" id="bgInclTags" type="checkbox" name="bg[<?php echo $ii; ?>][bgInclTags]" <?php if ((int)$options['bgInclTags'] == 1) echo "checked"; ?> />
76
- <strong><?php _e('Post with tags', 'nxs_snap'); ?></strong> <?php _e('Tags from the blogpost will be auto-posted to Blogger/Blogspot', 'nxs_snap'); ?>
77
- </p>
78
-
79
- <?php if ($options['bgPass']!='') { ?>
80
- <?php wp_nonce_field( 'rePostToBG', 'rePostToBG_wpnonce' ); ?>
81
- <b><?php _e('Test your settings', 'nxs_snap'); ?>:</b>&nbsp;&nbsp;&nbsp; <?php if (!isset($options['bgOK']) || $options['bgOK']!='1') { ?> <div class="blnkg">=== <?php _e('Submit Test Post to Finish Configuration', 'nxs_snap'); ?> ===&gt;</div> <?php } ?> <a href="#" class="NXSButton" onclick="testPost('BG', '<?php echo $ii; ?>'); return false;"><?php printf( __( 'Submit Test Post to %s', 'nxs_snap' ), $nType); ?></a>
82
- <?php } ?>
83
-
84
- <div class="submit"><input type="submit" class="button-primary" name="update_NS_SNAutoPoster_settings" value="<?php _e('Update Settings', 'nxs_snap') ?>" /></div>
85
- </div>
86
- </div>
87
- <?php
88
-
89
-
90
- }
91
- //#### Set Unit Settings from POST
92
- function setNTSettings($post, $options){ global $nxs_snapThisPageUrl; //prr($post); die();
93
- foreach ($post as $ii => $pval){// prr($pval);
94
- if (isset($pval['apBGUName']) && trim($pval['apBGUName'])!='' && isset($pval['apBGPass']) && trim($pval['apBGPass'])!='') { if (!isset($options[$ii])) $options[$ii] = array();
95
-
96
- if (isset($pval['apDoBG'])) $options[$ii]['doBG'] = $pval['apDoBG']; else $options[$ii]['doBG'] = 0;
97
-
98
- if (isset($pval['catSel'])) $options[$ii]['catSel'] = trim($pval['catSel']);
99
- if ($options[$ii]['catSel']=='1' && trim($pval['catSelEd'])!='') $options[$ii]['catSelEd'] = trim($pval['catSelEd']); else $options[$ii]['catSelEd'] = '';
100
-
101
- if (isset($pval['nName'])) $options[$ii]['nName'] = trim($pval['nName']);
102
- if (isset($pval['apBGUName'])) $options[$ii]['bgUName'] = trim($pval['apBGUName']);
103
- if (isset($pval['apBGPass'])) $options[$ii]['bgPass'] = 'b4d7s'.nsx_doEncode($pval['apBGPass']); else $options[$ii]['bgPass'] = '';
104
- if (isset($pval['apBGBlogID'])) $options[$ii]['bgBlogID'] = trim($pval['apBGBlogID']);
105
- if (isset($pval['apBGMsgFrmt'])) $options[$ii]['bgMsgFormat'] = trim($pval['apBGMsgFrmt']);
106
- if (isset($pval['apBGMsgTFrmt'])) $options[$ii]['bgMsgTFormat'] = trim($pval['apBGMsgTFrmt']);
107
- if (isset($pval['bgInclTags'])) $options[$ii]['bgInclTags'] = $pval['bgInclTags']; else $options[$ii]['bgInclTags'] = 0;
108
-
109
- if (isset($pval['delayHrs'])) $options[$ii]['nHrs'] = trim($pval['delayHrs']); if (isset($pval['delayMin'])) $options[$ii]['nMin'] = trim($pval['delayMin']);
110
- if (isset($pval['qTLng'])) $options[$ii]['qTLng'] = trim($pval['qTLng']);
111
-
112
- } //prr($options);
113
- } return $options;
114
- }
115
- //#### Show Post->Edit Meta Box Settings
116
- function showEdPostNTSettings($ntOpts, $post){ global $nxs_plurl; $post_id = $post->ID;
117
- foreach($ntOpts as $ii=>$options){ $pMeta = maybe_unserialize(get_post_meta($post_id, 'snapBG', true)); if (is_array($pMeta)) $options = $this->adjMetaOpt($options, $pMeta[$ii]);
118
- $doBG = $options['doBG'] && (is_array($pMeta) || $options['catSel']!='1');
119
- $isAvailBG = $options['bgUName']!='' && $options['bgPass']!=''; $bgMsgFormat = htmlentities($options['bgMsgFormat'], ENT_COMPAT, "UTF-8"); $bgMsgTFormat = htmlentities($options['bgMsgTFormat'], ENT_COMPAT, "UTF-8");
120
- ?>
121
-
122
- <tr><th style="text-align:left;" colspan="2"><?php if ( $options['catSel']=='1' && trim($options['catSelEd'])!='' ) { ?> <input type="hidden" class="nxs_SC" id="nxs_SC_BG<?php echo $ii; ?>" value="<?php echo $options['catSelEd']; ?>" /> <?php } ?>
123
- <?php if ($isAvailBG) { ?><input class="nxsGrpDoChb" value="1" id="doBG<?php echo $ii; ?>" <?php if ($post->post_status == "publish") echo 'disabled="disabled"';?> type="checkbox" name="bg[<?php echo $ii; ?>][doBG]" <?php if ((int)$doBG == 1) echo 'checked="checked" title="def"'; ?> /> <?php if ($post->post_status == "publish") { ?> <input type="hidden" name="bg[<?php echo $ii; ?>][doBG]" value="<?php echo $doBG;?>"> <?php } ?> <?php } ?>
124
- <div class="nsx_iconedTitle" style="display: inline; font-size: 13px; background-image: url(<?php echo $nxs_plurl; ?>img/bg16.png);">Blogger - <?php _e('publish to', 'nxs_snap') ?> (<i style="color: #005800;"><?php echo $options['nName']; ?></i>)</div></th> <td style="min-width: 180px; width: 350px;" ><?php //## Only show RePost button if the post is "published"
125
- if ($post->post_status == "publish" && $isAvailBG) { ?>
126
- <input alt="<?php echo $ii; ?>" style="float: right;" onmouseout="hidePopShAtt('SV');" onmouseover="showPopShAtt('SV', event);" onclick="return false;" type="button" class="button" name="rePostToBG_repostButton" id="rePostToBG_button" value="<?php _e('Repost to Blogger', 'nxs_snap') ?>" />
127
- <?php wp_nonce_field( 'rePostToBG', 'rePostToBG_wpnonce' ); } ?>
128
-
129
- <?php if (is_array($pMeta) && is_array($pMeta[$ii]) && isset($pMeta[$ii]['pgID']) ) {
130
- ?> <span id="pstdBG<?php echo $ii; ?>" style="float: right; padding-top: 4px; padding-right: 10px;">
131
- <a style="font-size: 10px;" href="<?php echo $pMeta[$ii]['pgID']; ?>" target="_blank"><?php $nType="Blogger"; printf( __( 'Posted on', 'nxs_snap' ), $nType); ?><?php echo (isset($pMeta[$ii]['pDate']) && $pMeta[$ii]['pDate']!='')?(" (".$pMeta[$ii]['pDate'].")"):""; ?></a>
132
- </span><?php } ?>
133
-
134
- </td></tr>
135
- <?php if (!$isAvailBG) { ?><tr><th scope="row" style="text-align:right; width:150px; padding-top: 5px; padding-right:10px;"></th> <td><b><?php _e('Setup your Blogger Account to AutoPost to Blogger', 'nxs_snap') ?></b>
136
- <?php } elseif ($post->post_status != "puZblish") { ?>
137
- <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top: 6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Title Format:', 'NS_SPAP') ?></th>
138
- <td><input value="<?php echo $bgMsgTFormat ?>" type="text" name="bg[<?php echo $ii; ?>][SNAPTformat]" style="width:60%;max-width: 610px;" onfocus="jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apBGTMsgFrmt<?php echo $ii; ?>');"/><?php nxs_doShowHint("apBGTMsgFrmt".$ii, '', '58'); ?></td></tr>
139
- <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top: 6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Message Format:', 'NS_SPAP') ?></th>
140
- <td>
141
- <textarea cols="150" rows="1" id="bg<?php echo $ii; ?>SNAPformat" name="bg[<?php echo $ii; ?>][SNAPformat]" style="width:60%;max-width: 610px;" onfocus="jQuery('#bg<?php echo $ii; ?>SNAPformat').attr('rows', 4); jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apBGMsgFrmt<?php echo $ii; ?>');"><?php echo $bgMsgFormat; ?></textarea>
142
- <?php nxs_doShowHint("apBGMsgFrmt".$ii, '', '58'); ?></td></tr>
143
- <?php }
144
- }
145
- }
146
-
147
- function adjMetaOpt($optMt, $pMeta){ if (isset($pMeta['isPosted'])) $optMt['isPosted'] = $pMeta['isPosted']; else $optMt['isPosted'] = '';
148
- if (isset($pMeta['SNAPformat'])) $optMt['bgMsgFormat'] = $pMeta['SNAPformat'];
149
- if (isset($pMeta['SNAPTformat'])) $optMt['bgMsgTFormat'] = $pMeta['SNAPTformat'];
150
- if (isset($pMeta['doBG'])) $optMt['doBG'] = $pMeta['doBG'] == 1?1:0; else { if (isset($pMeta['SNAPformat'])) $optMt['doBG'] = 0; }
151
- if (isset($pMeta['SNAPincludeBG']) && $pMeta['SNAPincludeBG'] == '1' ) $optMt['doBG'] = 1;
152
- return $optMt;
153
- }
154
- }}
155
-
156
- if (!function_exists("nxs_rePostToBG_ajax")) { function nxs_rePostToBG_ajax() { check_ajax_referer('rePostToBG'); $postID = $_POST['id']; // $result = nsPublishTo($id, 'FB', true);
157
- global $plgn_NS_SNAutoPoster; if (!isset($plgn_NS_SNAutoPoster)) return; $options = $plgn_NS_SNAutoPoster->nxs_options;
158
- foreach ($options['bg'] as $ii=>$po) if ($ii==$_POST['nid']) { $po['ii'] = $ii; $po['pType'] = 'aj';
159
- $mpo = get_post_meta($postID, 'snapBG', true); $mpo = maybe_unserialize($mpo);
160
- if (is_array($mpo) && isset($mpo[$ii]) && is_array($mpo[$ii]) ){ $ntClInst = new nxs_snapClassBG(); $po = $ntClInst->adjMetaOpt($po, $mpo[$ii]); }
161
- $result = nxs_doPublishToBG($postID, $po); if ($result == 201) { $options['bg'][$ii]['bgOK']=1; update_option('NS_SNAutoPoster', $options); }
162
-
163
- if ($result == 200) die("Successfully sent your post to Blooger."); else die($result);
164
- }
165
- }
166
- }
167
- if (!function_exists('nsBloggerGetAuth')){ function nsBloggerGetAuth($email, $pass) { $pass = urlencode($pass);
168
- $ch = curl_init("https://www.google.com/accounts/ClientLogin?Email=$email&Passwd=$pass&service=blogger&accountType=GOOGLE");
169
- $headers = array(); $headers[] = 'Accept: text/html, application/xhtml+xml, */*';
170
- $headers[] = 'Connection: Keep-Alive'; $headers[] = 'Accept-Language: en-us';
171
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
172
- curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0)");
173
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,10); curl_setopt($ch, CURLOPT_TIMEOUT, 10);
174
- curl_setopt($ch, CURLOPT_HEADER,0); curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1);
175
- $result = curl_exec($ch); $resultArray = curl_getinfo($ch);
176
- curl_close($ch); $arr = explode("=",$result); $token = $arr[3]; if (trim($token)=='') return false; else return $token;
177
- }}
178
- if (!function_exists('nsBloggerNewPost')){ function nsBloggerNewPost($auth, $blogID, $title, $text) {$text = str_ireplace('allowfullscreen','', $text); $title = utf8_decode(strip_tags($title));
179
- $text = preg_replace('/<object\b[^>]*>(.*?)<\/object>/is', "", $text); $text = preg_replace('/<iframe\b[^>]*>(.*?)<\/iframe>/is', "", $text); $text = utf8_decode($text);
180
-
181
- $postText = '<entry xmlns="http://www.w3.org/2005/Atom"><title type="text">'.$title.'</title><content type="xhtml">'.$text.'</content></entry>'; //prr($postText);
182
- $len = strlen($entry); $ch = curl_init("https://www.blogger.com/feeds/$blogID/posts/default");
183
- $headers = array("Content-type: application/atom+xml", "Content-Length: ".strlen($postText), "Authorization: GoogleLogin auth=".$auth, $postText);
184
- curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, 1); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
185
- curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0)");
186
- curl_setopt($ch, CURLOPT_HEADER,0); curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1); curl_setopt($ch, CURLINFO_HEADER_OUT, true);
187
- $result = curl_exec($ch); curl_close($ch);
188
- if (stripos($result,'tag:blogger.com')!==false) { $postID = CutFromTo($result, " rel='alternate' type='text/html' href='", "'"); return array("code"=>"OK", "post_id"=>$postID); } else { prr($result); return false;}
189
- }}
190
- if (!function_exists("nxs_doPublishToBG")) { //## Second Function to Post to BG
191
- function nxs_doPublishToBG($postID, $options){ $ntCd = 'BG'; $ntCdL = 'bg'; $ntNm = 'Blogger'; // $uqID = uniqid('BG_');
192
- //$backtrace = debug_backtrace(); nxs_addToLogN('W', 'Enter', $ntCd, 'I am here - '.$ntCd."|".print_r($backtrace, true), '');
193
- // if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToBG', array($postID, $options));
194
- $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle=='') $blogTitle = home_url();
195
- $addParams = nxs_makeURLParams(array('NTNAME'=>$ntNm, 'NTCODE'=>$ntCd, 'ACCNAME'=>$options['nName'], 'POSTID'=>$postID));
196
- $ii = $options['ii']; if (!isset($options['pType'])) $options['pType'] = 'im'; if ($options['pType']=='sh') sleep(rand(1, 10));
197
- $logNT = '<span style="color:#F87907">'.$ntNm.'</span> - '.$options['nName'];
198
- $snap_ap = get_post_meta($postID, 'snap'.$ntCd, true); $snap_ap = maybe_unserialize($snap_ap);
199
- if ($options['pType']!='aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
200
- $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted!='2') {
201
- nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:'.$postID, 'Already posted. No reason for posting duplicate'); return;
202
- }
203
- }
204
-
205
- if ($postID=='0') { echo "Testing ... <br/><br/>"; $msgT = 'Test Post from '.htmlentities($blogTitle); $link = home_url(); $msg = 'Test Post from '.$blogTitle. " ".$link; }
206
- else { $post = get_post($postID); if(!$post) return; $msgFormat = $options['bgMsgFormat']; $msg = nsFormatMessage($msgFormat, $postID, $addParams);
207
- $link = get_permalink($postID); $msgTFormat = $options['bgMsgTFormat']; $msgT = nsFormatMessage($msgTFormat, $postID, $addParams); nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted'=>'1'));
208
- }
209
- $extInfo = ' | PostID: '.$postID." - ".nxs_doQTrans($post->post_title, $lng);
210
- //## Actual POST Code
211
- $email = $options['bgUName']; $pass = substr($options['bgPass'], 0, 5)=='b4d7s'?nsx_doDecode(substr($options['bgPass'], 5)):$options['bgPass']; $blogID = $options['bgBlogID'];
212
- //echo "###".$auth."|".$blogID."|".$msgT."|".$msg;
213
- if ($options['bgInclTags']=='1'){$t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) {$tggs[] = $tagA->name;} $tags = implode('","',$tggs); $tags = nsTrnc($tags, 195, ',', ''); }
214
- if (substr($tags, -1)=='"') $tags = substr($tags, 0, -1);
215
-
216
- if (class_exists('DOMDocument')) {$doc = new DOMDocument(); @$doc->loadHTML('<?xml encoding="UTF-8">' .$msg); $doc->encoding = 'UTF-8'; $msg = $doc->saveHTML(); $msg = CutFromTo($msg, '<body>', '</body>');
217
- $msg = preg_replace('/<br(.*?)\/?>/','<br$1/>',$msg); $msg = preg_replace('/<img(.*?)\/?>/','<img$1/>',$msg);
218
- require_once ('apis/htmlNumTable.php'); if (is_array($HTML401NamedToNumeric)) { $msg = strtr($msg, $HTML401NamedToNumeric); $msgT = strtr($msgT, $HTML401NamedToNumeric); }
219
- } // prr($text);
220
- // prr($msg); echo " =HT= ";
221
- $msg = preg_replace('/<script\b[^>]*>(.*?)<\/script>/is', "", $msg); $msg = preg_replace('/<!--(.*)-->/Uis', "", $msg); $nxshf = new NXS_HtmlFixer(); $nxshf->debug = false; $msg = $nxshf->getFixedHtml($msg);
222
- $msg = str_replace("\r\n","\n", $msg); $msg = str_replace("\n\r","\n", $msg); $msg = str_replace("\r","\n", $msg); $msg = str_replace("\n","<br/>", $msg); // prr($msg); die();
223
- if (function_exists("doConnectToBlogger")) {$auth = doConnectToBlogger($email, $pass); if ($auth!==false) $ret = $auth; else $ret = doPostToBlogger($blogID, $msgT, $msg, $tags);}
224
- else {$auth = nsBloggerGetAuth($email, $pass); if ($auth===false) $ret = 'Incorrect Username/Password'; else { $msgT = str_ireplace('&amp;', '&', $msgT);
225
- $msgT = utf8_encode(str_ireplace('&', '&amp;', $msgT)); $msg = utf8_encode($msg); $ret = nsBloggerNewPost($auth, $blogID, $msgT, $msg);
226
- }}
227
- //## /Actual POST Code
228
- if ( (!is_array($ret)) && $ret!='OK') { if ($postID=='0') prr($ret); nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '. strip_tags(print_r($ret, true)), $extInfo); return $ret; }
229
- else { if ($postID=='0') { echo 'OK - Message Posted, please see your '.$ntNm.' Page '; nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); return 201;}
230
- else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted'=>'1', 'pgID'=>$ret['post_id'], 'pDate'=>date('Y-m-d H:i:s')));
231
- do_action('nxs_actOnBG', array('postID'=>$postID, 'pgID'=>$ret['post_id'], 'ii'=>$ii)); nxs_addToLogN( 'S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo);
232
- } return 200;
233
- }
234
- }
235
- }
236
-
 
 
 
237
  ?>
1
+ <?php
2
+ //## NextScripts Facebook Connection Class
3
+ $nxs_snapAvNts[] = array('code'=>'BG', 'lcode'=>'bg', 'name'=>'Blogger');
4
+
5
+ if (!class_exists("nxs_snapClassBG")) { class nxs_snapClassBG {
6
+ //#### Show Common Settings
7
+ function showGenNTSettings($ntOpts){ global $nxs_plurl; $ntInfo = array('code'=>'BG', 'lcode'=>'bg', 'name'=>'Blogger', 'defNName'=>'diUName', 'tstReq' => true); ?>
8
+ <div class="nxs_box">
9
+ <div class="nxs_box_header">
10
+ <div class="nsx_iconedTitle" style="margin-bottom:1px;background-image:url(<?php echo $nxs_plurl;?>img/<?php echo $ntInfo['lcode']; ?>16.png);"><?php echo $ntInfo['name']; ?>
11
+ <?php $cbo = count($ntOpts); ?> <?php wp_nonce_field( 'ns'.$ntInfo['code'], 'ns'.$ntInfo['code'].'_wpnonce' ); ?>
12
+ <?php if ($cbo>1){ ?><div class="nsBigText"><?php echo "(".($cbo=='0'?'No':$cbo)." "; _e('accounts', 'nxs_snap'); echo ")"; ?></div><?php } ?>
13
+ </div>
14
+ </div>
15
+ <div class="nxs_box_inside">
16
+ <?php foreach ($ntOpts as $indx=>$pbo){ if (trim($pbo['nName']=='')) $pbo['nName'] = $pbo[$ntInfo['defNName']]; ?>
17
+ <p style="margin:0px;margin-left:5px;">
18
+ <input value="1" name="<?php echo $ntInfo['lcode']; ?>[<?php echo $indx; ?>][apDo<?php echo $ntInfo['code']; ?>]" onchange="doShowHideBlocks('<?php echo $ntInfo['code']; ?>');" type="checkbox" <?php if ((int)$pbo['do'.$ntInfo['code']] == 1) echo "checked"; ?> /> <?php if ((int)$pbo['catSel'] == 1) { ?> <span onmouseout="nxs_hidePopUpInfo('popOnlyCat');" onmouseover="nxs_showPopUpInfo('popOnlyCat', event);"><?php echo "*[".(substr_count($pbo['catSelEd'], ",")+1)."]*" ?></span><?php } ?>
19
+ <strong><?php _e('Auto-publish to', 'nxs_snap'); ?> <?php echo $ntInfo['name']; ?> <i style="color: #005800;"><?php if($pbo['nName']!='') echo "(".$pbo['nName'].")"; ?></i></strong>
20
+ &nbsp;&nbsp;<?php if ($ntInfo['tstReq'] && (!isset($pbo[$ntInfo['lcode'].'OK']) || $pbo[$ntInfo['lcode'].'OK']=='')){ ?><b style="color: #800000"><?php _e('Attention requred. Unfinished setup', 'nxs_snap'); ?> ==&gt;</b><?php } ?><a id="do<?php echo $ntInfo['code'].$indx; ?>A" href="#" onclick="doShowHideBlocks2('<?php echo $ntInfo['code'].$indx; ?>');return false;">[<?php _e('Show Settings', 'nxs_snap'); ?>]</a>&nbsp;&nbsp;
21
+ <a href="#" onclick="doDelAcct('<?php echo $ntInfo['lcode']; ?>', '<?php echo $indx; ?>', '<?php if (isset($pbo['bgBlogID'])) echo $pbo['nName']; ?>');return false;">[<?php _e('Remove Account', 'nxs_snap'); ?>]</a>
22
+ </p><?php $this->showNTSettings($indx, $pbo);
23
+ }?>
24
+ </div>
25
+ </div> <?php //## END Settings
26
+ }
27
+ //#### Show NEW Settings Page
28
+ function showNewNTSettings($bo){ $po = array('nName'=>'', 'doBG'=>'1', 'bgUName'=>'', 'bgPass'=>'', 'bgBlogID'=>'', 'bgInclTags'=>'1', 'bgMsgFormat'=>'%FULLTEXT% <br/><a href=\'%URL%\'>%TITLE%</a>', 'bgMsgTFormat'=>'%TITLE%' ); $this->showNTSettings($bo, $po, true);}
29
+ //#### Show Unit Settings
30
+ function showNTSettings($ii, $options, $isNew=false){ global $nxs_plurl;
31
+ if (!isset($options['nHrs'])) $options['nHrs'] = 0; if (!isset($options['nMin'])) $options['nMin'] = 0; if (!isset($options['catSel'])) $options['catSel'] = 0; if (!isset($options['catSelEd'])) $options['catSelEd'] = '';
32
+ if (!isset($options['nDays'])) $options['nDays'] = 0; if (!isset($options['qTLng'])) $options['qTLng'] = ''; ?>
33
+ <div id="doBG<?php echo $ii; ?>Div" class="insOneDiv<?php if ($isNew){ ?> clNewNTSets<?php } ?>" style="background-image: url(<?php echo $nxs_plurl; ?>img/bg-bg.png);background-position:90% 10%;"> <input type="hidden" name="apDoSBG<?php echo $ii; ?>" value="0" id="apDoSBG<?php echo $ii; ?>" />
34
+ <?php if ($isNew) { ?> <input type="hidden" name="bg[<?php echo $ii; ?>][apDoBG]" value="1" id="apDoNewBG<?php echo $ii; ?>" /> <?php } ?>
35
+
36
+ <div style="display: none;"><input name="bg[<?php echo $ii; ?>][apBGPassChr]" id="apBGPassChr" type="password" value="" /></div>
37
+
38
+ <div id="doBG<?php echo $ii; ?>Div" style="margin-left: 10px;"> <div class="nsx_iconedTitle" style="float: right; background-image: url(<?php echo $nxs_plurl; ?>img/bg16.png);"><a style="font-size: 12px;" target="_blank" href="http://www.nextscripts.com/setup-installation-blogger-social-networks-auto-poster-wordpress/"><?php $nType="Blogger"; printf( __( 'Detailed %s Installation/Configuration Instructions', 'nxs_snap' ), $nType); ?></a></div>
39
+
40
+ <div style="width:100%;"><strong><?php _e('Account Nickname', 'nxs_snap'); ?>:</strong> <i><?php _e('Just so you can easely identify it', 'nxs_snap'); ?></i> </div><input name="bg[<?php echo $ii; ?>][nName]" id="bgnName<?php echo $ii; ?>" style="font-weight: bold; color: #005800; border: 1px solid #ACACAC; width: 40%;" value="<?php _e(apply_filters('format_to_edit',htmlentities($options['nName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /><br/>
41
+ <?php echo nxs_addQTranslSel('bg', $ii, $options['qTLng']); ?>
42
+ <?php echo nxs_addPostingDelaySel('bg', $ii, $options['nHrs'], $options['nMin'], $options['nDays']); ?>
43
+
44
+ <?php if (!$isNew) { ?>
45
+ <div style="width:100%;"><strong><?php _e('Categories', 'nxs_snap'); ?>:</strong>
46
+ <input value="0" id="catSelA<?php echo $ii; ?>" type="radio" name="bg[<?php echo $ii; ?>][catSel]" <?php if ((int)$options['catSel'] != 1) echo "checked"; ?> /> All
47
+ <input value="1" id="catSelSBG<?php echo $ii; ?>" type="radio" name="bg[<?php echo $ii; ?>][catSel]" <?php if ((int)$options['catSel'] == 1) echo "checked"; ?> /> <a href="#" style="text-decoration: none;" class="showCats" id="nxs_SCA_BG<?php echo $ii; ?>" onclick="jQuery('#catSelSBG<?php echo $ii; ?>').attr('checked', true); jQuery('#tmpCatSelNT').val('BG<?php echo $ii; ?>'); nxs_markCats( jQuery('#nxs_SC_BG<?php echo $ii; ?>').val() ); jQuery('#showCatSel').bPopup({ modalClose: false, appendTo: '#nsStForm', opacity: 0.6, follow: [false, false], position: [75, 'auto']}); return false;">Selected<?php if ($options['catSelEd']!='') echo "[".(substr_count($options['catSelEd'], ",")+1)."]"; ?></a>
48
+ <input type="hidden" name="bg[<?php echo $ii; ?>][catSelEd]" id="nxs_SC_BG<?php echo $ii; ?>" value="<?php echo $options['catSelEd']; ?>" />
49
+ <br/><i><?php _e('Only selected categories will be autoposted to this account', 'nxs_snap'); ?></i>
50
+ </div>
51
+ <br/>
52
+ <?php } ?>
53
+
54
+ <div style="width:100%;"><strong>Blogger Username/Email:</strong> </div><input name="bg[<?php echo $ii; ?>][apBGUName]" id="apBGUName" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit',htmlentities($options['bgUName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
55
+ <div style="width:100%;"><strong>Blogger Password:</strong> </div><input name="bg[<?php echo $ii; ?>][apBGPass]" id="apBGPass" autocomplete="off" type="password" style="width: 30%;" value="<?php if (trim($options['bgPass'])!='') _e(apply_filters('format_to_edit', htmlentities(substr($options['bgPass'], 0, 5)=='b4d7s'?nsx_doDecode(substr($options['bgPass'], 5)):$options['bgPass'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /> <br/>
56
+ <div style="width:100%;"><strong>Blogger Blog ID:</strong>
57
+ <p style="font-size: 11px; margin: 0px;"><?php _e('Log to your Blogger management panel and look at the URL of your blog: http://www.blogger.com/blogger.g?blogID=8959085979163812093#allposts. Your Blog ID will be: 8959085979163812093', 'nxs_snap'); ?></p>
58
+ </div><input name="bg[<?php echo $ii; ?>][apBGBlogID]" id="apBGBlogID" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['bgBlogID'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
59
+ <br/><br/>
60
+
61
+ <div style="width:100%;"><strong id="altFormatText"><?php _e('Post Title Format', 'nxs_snap'); ?>:</strong> (<a href="#" id="apBGTMsgFrmt<?php echo $ii; ?>HintInfo" onclick="mxs_showHideFrmtInfo('apBGTMsgFrmt<?php echo $ii; ?>'); return false;"><?php _e('Show format info', 'nxs_snap'); ?></a>)</div>
62
+
63
+ <input name="bg[<?php echo $ii; ?>][apBGMsgTFrmt]" id="apBGMsgTFrmt" style="width: 50%;" value="<?php if ($options['bgMsgTFormat']!='') _e(apply_filters('format_to_edit', htmlentities($options['bgMsgTFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap'); else echo "%TITLE%"; ?>" onfocus="mxs_showFrmtInfo('apBGTMsgFrmt<?php echo $ii; ?>');" /><?php nxs_doShowHint("apBGTMsgFrmt".$ii); ?><br/>
64
+
65
+ <div id="altFormat" style="">
66
+ <div style="width:100%;"><strong id="altFormatText"><?php _e('Post Text Format', 'nxs_snap'); ?>:</strong> (<a href="#" id="apBGMsgFrmt<?php echo $ii; ?>HintInfo" onclick="mxs_showHideFrmtInfo('apBGMsgFrmt<?php echo $ii; ?>'); return false;"><?php _e('Show format info', 'nxs_snap'); ?></a>)
67
+
68
+ <!--
69
+ HTML is <?php if(!function_exists('doPostToGooglePlus')) {?> <b>NOT</b> <?php } ?> allowed. <?php if(!function_exists('doPostToGooglePlus')) {?> <i>- Blogger "Free API" limitation. Please get <a href="http://www.nextscripts.com/google-plus-automated-posting/#blogger">NextScripts API</a> to allow HTML</i> <?php } ?> -->
70
+ </div>
71
+
72
+ <textarea cols="150" rows="3" id="bg<?php echo $ii; ?>SNAPformat" name="bg[<?php echo $ii; ?>][apBGMsgFrmt]" style="width:51%;max-width: 650px;" onfocus="jQuery('#bg<?php echo $ii; ?>SNAPformat').attr('rows', 6); mxs_showFrmtInfo('apBGMsgFrmt<?php echo $ii; ?>');"><?php if ($options['bgMsgFormat']!='') _e(apply_filters('format_to_edit',htmlentities($options['bgMsgFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap'); else echo "%FULLTEXT% <br/><a href='%URL%'>%TITLE%</a>"; ?></textarea>
73
+
74
+ <?php nxs_doShowHint("apBGMsgFrmt".$ii, __('HTML is allowed', 'nxs_snap')); ?>
75
+ </div>
76
+
77
+ <p style="margin-bottom: 20px;margin-top: 5px;"><input value="1" id="bgInclTags" type="checkbox" name="bg[<?php echo $ii; ?>][bgInclTags]" <?php if ((int)$options['bgInclTags'] == 1) echo "checked"; ?> />
78
+ <strong><?php _e('Post with tags', 'nxs_snap'); ?></strong> <?php _e('Tags from the blogpost will be auto-posted to Blogger/Blogspot', 'nxs_snap'); ?>
79
+ </p>
80
+
81
+ <?php if ($options['bgPass']!='') { ?>
82
+ <?php wp_nonce_field( 'rePostToBG', 'rePostToBG_wpnonce' ); ?>
83
+ <b><?php _e('Test your settings', 'nxs_snap'); ?>:</b>&nbsp;&nbsp;&nbsp; <?php if (!isset($options['bgOK']) || $options['bgOK']!='1') { ?> <div class="blnkg">=== <?php _e('Submit Test Post to Finish Configuration', 'nxs_snap'); ?> ===&gt;</div> <?php } ?> <a href="#" class="NXSButton" onclick="testPost('BG', '<?php echo $ii; ?>'); return false;"><?php printf( __( 'Submit Test Post to %s', 'nxs_snap' ), $nType); ?></a>
84
+ <?php } ?>
85
+
86
+ <div class="submit"><input type="submit" class="button-primary" name="update_NS_SNAutoPoster_settings" value="<?php _e('Update Settings', 'nxs_snap') ?>" /></div>
87
+ </div>
88
+ </div>
89
+ <?php
90
+
91
+
92
+ }
93
+ //#### Set Unit Settings from POST
94
+ function setNTSettings($post, $options){ global $nxs_snapThisPageUrl; //prr($post); die();
95
+ foreach ($post as $ii => $pval){// prr($pval);
96
+ if (isset($pval['apBGUName']) && trim($pval['apBGUName'])!='' && isset($pval['apBGPass']) && trim($pval['apBGPass'])!='') { if (!isset($options[$ii])) $options[$ii] = array();
97
+
98
+ if (isset($pval['apDoBG'])) $options[$ii]['doBG'] = $pval['apDoBG']; else $options[$ii]['doBG'] = 0;
99
+
100
+ if (isset($pval['catSel'])) $options[$ii]['catSel'] = trim($pval['catSel']);
101
+ if ($options[$ii]['catSel']=='1' && trim($pval['catSelEd'])!='') $options[$ii]['catSelEd'] = trim($pval['catSelEd']); else $options[$ii]['catSelEd'] = '';
102
+
103
+ if (isset($pval['nName'])) $options[$ii]['nName'] = trim($pval['nName']);
104
+ if (isset($pval['apBGUName'])) $options[$ii]['bgUName'] = trim($pval['apBGUName']);
105
+ if (isset($pval['apBGPass'])) $options[$ii]['bgPass'] = 'b4d7s'.nsx_doEncode($pval['apBGPass']); else $options[$ii]['bgPass'] = '';
106
+ if (isset($pval['apBGBlogID'])) $options[$ii]['bgBlogID'] = trim($pval['apBGBlogID']);
107
+ if (isset($pval['apBGMsgFrmt'])) $options[$ii]['bgMsgFormat'] = trim($pval['apBGMsgFrmt']);
108
+ if (isset($pval['apBGMsgTFrmt'])) $options[$ii]['bgMsgTFormat'] = trim($pval['apBGMsgTFrmt']);
109
+ if (isset($pval['bgInclTags'])) $options[$ii]['bgInclTags'] = $pval['bgInclTags']; else $options[$ii]['bgInclTags'] = 0;
110
+
111
+ if (isset($pval['delayDays'])) $options[$ii]['nDays'] = trim($pval['delayDays']);
112
+ if (isset($pval['delayHrs'])) $options[$ii]['nHrs'] = trim($pval['delayHrs']); if (isset($pval['delayMin'])) $options[$ii]['nMin'] = trim($pval['delayMin']);
113
+ if (isset($pval['qTLng'])) $options[$ii]['qTLng'] = trim($pval['qTLng']);
114
+
115
+ } //prr($options);
116
+ } return $options;
117
+ }
118
+ //#### Show Post->Edit Meta Box Settings
119
+ function showEdPostNTSettings($ntOpts, $post){ global $nxs_plurl; $post_id = $post->ID;
120
+ foreach($ntOpts as $ii=>$options){ $pMeta = maybe_unserialize(get_post_meta($post_id, 'snapBG', true)); if (is_array($pMeta)) $options = $this->adjMetaOpt($options, $pMeta[$ii]);
121
+ $doBG = $options['doBG'] && (is_array($pMeta) || $options['catSel']!='1');
122
+ $isAvailBG = $options['bgUName']!='' && $options['bgPass']!=''; $bgMsgFormat = htmlentities($options['bgMsgFormat'], ENT_COMPAT, "UTF-8"); $bgMsgTFormat = htmlentities($options['bgMsgTFormat'], ENT_COMPAT, "UTF-8");
123
+ ?>
124
+
125
+ <tr><th style="text-align:left;" colspan="2"><?php if ( $options['catSel']=='1' && trim($options['catSelEd'])!='' ) { ?> <input type="hidden" class="nxs_SC" id="nxs_SC_BG<?php echo $ii; ?>" value="<?php echo $options['catSelEd']; ?>" /> <?php } ?>
126
+ <?php if ($isAvailBG) { ?><input class="nxsGrpDoChb" value="1" id="doBG<?php echo $ii; ?>" <?php if ($post->post_status == "publish") echo 'disabled="disabled"';?> type="checkbox" name="bg[<?php echo $ii; ?>][doBG]" <?php if ((int)$doBG == 1) echo 'checked="checked" title="def"'; ?> /> <?php if ($post->post_status == "publish") { ?> <input type="hidden" name="bg[<?php echo $ii; ?>][doBG]" value="<?php echo $doBG;?>"> <?php } ?> <?php } ?>
127
+ <div class="nsx_iconedTitle" style="display: inline; font-size: 13px; background-image: url(<?php echo $nxs_plurl; ?>img/bg16.png);">Blogger - <?php _e('publish to', 'nxs_snap') ?> (<i style="color: #005800;"><?php echo $options['nName']; ?></i>)</div></th> <td style="min-width: 180px; width: 350px;" ><?php //## Only show RePost button if the post is "published"
128
+ if ($post->post_status == "publish" && $isAvailBG) { ?>
129
+ <input alt="<?php echo $ii; ?>" style="float: right;" onmouseout="hidePopShAtt('SV');" onmouseover="showPopShAtt('SV', event);" onclick="return false;" type="button" class="button" name="rePostToBG_repostButton" id="rePostToBG_button" value="<?php _e('Repost to Blogger', 'nxs_snap') ?>" />
130
+ <?php wp_nonce_field( 'rePostToBG', 'rePostToBG_wpnonce' ); } ?>
131
+
132
+ <?php if (is_array($pMeta) && is_array($pMeta[$ii]) && isset($pMeta[$ii]['pgID']) ) {
133
+ ?> <span id="pstdBG<?php echo $ii; ?>" style="float: right; padding-top: 4px; padding-right: 10px;">
134
+ <a style="font-size: 10px;" href="<?php echo $pMeta[$ii]['pgID']; ?>" target="_blank"><?php $nType="Blogger"; printf( __( 'Posted on', 'nxs_snap' ), $nType); ?><?php echo (isset($pMeta[$ii]['pDate']) && $pMeta[$ii]['pDate']!='')?(" (".$pMeta[$ii]['pDate'].")"):""; ?></a>
135
+ </span><?php } ?>
136
+
137
+ </td></tr>
138
+ <?php if (!$isAvailBG) { ?><tr><th scope="row" style="text-align:right; width:150px; padding-top: 5px; padding-right:10px;"></th> <td><b><?php _e('Setup your Blogger Account to AutoPost to Blogger', 'nxs_snap') ?></b>
139
+ <?php } elseif ($post->post_status != "puZblish") { ?>
140
+ <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top: 6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Title Format:', 'NS_SPAP') ?></th>
141
+ <td><input value="<?php echo $bgMsgTFormat ?>" type="text" name="bg[<?php echo $ii; ?>][SNAPTformat]" style="width:60%;max-width: 610px;" onfocus="jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apBGTMsgFrmt<?php echo $ii; ?>');"/><?php nxs_doShowHint("apBGTMsgFrmt".$ii, '', '58'); ?></td></tr>
142
+ <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top: 6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Message Format:', 'NS_SPAP') ?></th>
143
+ <td>
144
+ <textarea cols="150" rows="1" id="bg<?php echo $ii; ?>SNAPformat" name="bg[<?php echo $ii; ?>][SNAPformat]" style="width:60%;max-width: 610px;" onfocus="jQuery('#bg<?php echo $ii; ?>SNAPformat').attr('rows', 4); jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apBGMsgFrmt<?php echo $ii; ?>');"><?php echo $bgMsgFormat; ?></textarea>
145
+ <?php nxs_doShowHint("apBGMsgFrmt".$ii, '', '58'); ?></td></tr>
146
+ <?php }
147
+ }
148
+ }
149
+
150
+ function adjMetaOpt($optMt, $pMeta){ if (isset($pMeta['isPosted'])) $optMt['isPosted'] = $pMeta['isPosted']; else $optMt['isPosted'] = '';
151
+ if (isset($pMeta['SNAPformat'])) $optMt['bgMsgFormat'] = $pMeta['SNAPformat'];
152
+ if (isset($pMeta['SNAPTformat'])) $optMt['bgMsgTFormat'] = $pMeta['SNAPTformat'];
153
+ if (isset($pMeta['doBG'])) $optMt['doBG'] = $pMeta['doBG'] == 1?1:0; else { if (isset($pMeta['SNAPformat'])) $optMt['doBG'] = 0; }
154
+ if (isset($pMeta['SNAPincludeBG']) && $pMeta['SNAPincludeBG'] == '1' ) $optMt['doBG'] = 1;
155
+ return $optMt;
156
+ }
157
+ }}
158
+
159
+ if (!function_exists("nxs_rePostToBG_ajax")) { function nxs_rePostToBG_ajax() { check_ajax_referer('rePostToBG'); $postID = $_POST['id']; // $result = nsPublishTo($id, 'FB', true);
160
+ global $plgn_NS_SNAutoPoster; if (!isset($plgn_NS_SNAutoPoster)) return; $options = $plgn_NS_SNAutoPoster->nxs_options;
161
+ foreach ($options['bg'] as $ii=>$po) if ($ii==$_POST['nid']) { $po['ii'] = $ii; $po['pType'] = 'aj';
162
+ $mpo = get_post_meta($postID, 'snapBG', true); $mpo = maybe_unserialize($mpo);
163
+ if (is_array($mpo) && isset($mpo[$ii]) && is_array($mpo[$ii]) ){ $ntClInst = new nxs_snapClassBG(); $po = $ntClInst->adjMetaOpt($po, $mpo[$ii]); }
164
+ $result = nxs_doPublishToBG($postID, $po); if ($result == 201) { $options['bg'][$ii]['bgOK']=1; update_option('NS_SNAutoPoster', $options); }
165
+
166
+ if ($result == 200) die("Successfully sent your post to Blooger."); else die($result);
167
+ }
168
+ }
169
+ }
170
+ if (!function_exists('nsBloggerGetAuth')){ function nsBloggerGetAuth($email, $pass) { $pass = urlencode($pass);
171
+ $ch = curl_init("https://www.google.com/accounts/ClientLogin?Email=$email&Passwd=$pass&service=blogger&accountType=GOOGLE");
172
+ $headers = array(); $headers[] = 'Accept: text/html, application/xhtml+xml, */*';
173
+ $headers[] = 'Connection: Keep-Alive'; $headers[] = 'Accept-Language: en-us';
174
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
175
+ curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0)");
176
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,10); curl_setopt($ch, CURLOPT_TIMEOUT, 10);
177
+ curl_setopt($ch, CURLOPT_HEADER,0); curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1);
178
+ $result = curl_exec($ch); $resultArray = curl_getinfo($ch);
179
+ curl_close($ch); $arr = explode("=",$result); $token = $arr[3]; if (trim($token)=='') return false; else return $token;
180
+ }}
181
+ if (!function_exists('nsBloggerNewPost')){ function nsBloggerNewPost($auth, $blogID, $title, $text) {$text = str_ireplace('allowfullscreen','', $text); $title = utf8_decode(strip_tags($title));
182
+ $text = preg_replace('/<object\b[^>]*>(.*?)<\/object>/is', "", $text); $text = preg_replace('/<iframe\b[^>]*>(.*?)<\/iframe>/is', "", $text); $text = utf8_decode($text);
183
+
184
+ $postText = '<entry xmlns="http://www.w3.org/2005/Atom"><title type="text">'.$title.'</title><content type="xhtml">'.$text.'</content></entry>'; //prr($postText);
185
+ $len = strlen($entry); $ch = curl_init("https://www.blogger.com/feeds/$blogID/posts/default");
186
+ $headers = array("Content-type: application/atom+xml", "Content-Length: ".strlen($postText), "Authorization: GoogleLogin auth=".$auth, $postText);
187
+ curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, 1); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
188
+ curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0)");
189
+ curl_setopt($ch, CURLOPT_HEADER,0); curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1); curl_setopt($ch, CURLINFO_HEADER_OUT, true);
190
+ $result = curl_exec($ch); curl_close($ch);
191
+ if (stripos($result,'tag:blogger.com')!==false) { $postID = CutFromTo($result, " rel='alternate' type='text/html' href='", "'"); return array("code"=>"OK", "post_id"=>$postID); } else { prr($result); return false;}
192
+ }}
193
+ if (!function_exists("nxs_doPublishToBG")) { //## Second Function to Post to BG
194
+ function nxs_doPublishToBG($postID, $options){ $ntCd = 'BG'; $ntCdL = 'bg'; $ntNm = 'Blogger'; // $uqID = uniqid('BG_');
195
+ //$backtrace = debug_backtrace(); nxs_addToLogN('W', 'Enter', $ntCd, 'I am here - '.$ntCd."|".print_r($backtrace, true), '');
196
+ // if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToBG', array($postID, $options));
197
+ $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle=='') $blogTitle = home_url();
198
+ $addParams = nxs_makeURLParams(array('NTNAME'=>$ntNm, 'NTCODE'=>$ntCd, 'ACCNAME'=>$options['nName'], 'POSTID'=>$postID));
199
+ $ii = $options['ii']; if (!isset($options['pType'])) $options['pType'] = 'im'; if ($options['pType']=='sh') sleep(rand(1, 10));
200
+ $logNT = '<span style="color:#F87907">'.$ntNm.'</span> - '.$options['nName'];
201
+ $snap_ap = get_post_meta($postID, 'snap'.$ntCd, true); $snap_ap = maybe_unserialize($snap_ap);
202
+ if ($options['pType']!='aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
203
+ $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted!='2') {
204
+ nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:'.$postID, 'Already posted. No reason for posting duplicate'); return;
205
+ }
206
+ }
207
+
208
+ if ($postID=='0') { echo "Testing ... <br/><br/>"; $msgT = 'Test Post from '.htmlentities($blogTitle); $link = home_url(); $msg = 'Test Post from '.$blogTitle. " ".$link; }
209
+ else { $post = get_post($postID); if(!$post) return; $msgFormat = $options['bgMsgFormat']; $msg = nsFormatMessage($msgFormat, $postID, $addParams);
210
+ $link = get_permalink($postID); $msgTFormat = $options['bgMsgTFormat']; $msgT = nsFormatMessage($msgTFormat, $postID, $addParams); nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted'=>'1'));
211
+ }
212
+ $extInfo = ' | PostID: '.$postID." - ".nxs_doQTrans($post->post_title, $lng);
213
+ //## Actual POST Code
214
+ $email = $options['bgUName']; $pass = substr($options['bgPass'], 0, 5)=='b4d7s'?nsx_doDecode(substr($options['bgPass'], 5)):$options['bgPass']; $blogID = $options['bgBlogID'];
215
+ //echo "###".$auth."|".$blogID."|".$msgT."|".$msg;
216
+ if ($options['bgInclTags']=='1'){$t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) {$tggs[] = $tagA->name;} $tags = implode('","',$tggs); $tags = nsTrnc($tags, 195, ',', ''); }
217
+ if (substr($tags, -1)=='"') $tags = substr($tags, 0, -1);
218
+
219
+ if (class_exists('DOMDocument')) {$doc = new DOMDocument(); @$doc->loadHTML('<?xml encoding="UTF-8">' .$msg); $doc->encoding = 'UTF-8'; $msg = $doc->saveHTML(); $msg = CutFromTo($msg, '<body>', '</body>');
220
+ $msg = preg_replace('/<br(.*?)\/?>/','<br$1/>',$msg); $msg = preg_replace('/<img(.*?)\/?>/','<img$1/>',$msg);
221
+ require_once ('apis/htmlNumTable.php'); if (is_array($HTML401NamedToNumeric)) { $msg = strtr($msg, $HTML401NamedToNumeric); $msgT = strtr($msgT, $HTML401NamedToNumeric); }
222
+ } // prr($text);
223
+ // prr($msg); echo " =HT= ";
224
+ $msg = preg_replace('/<script\b[^>]*>(.*?)<\/script>/is', "", $msg); $msg = preg_replace('/<!--(.*)-->/Uis', "", $msg); $nxshf = new NXS_HtmlFixer(); $nxshf->debug = false; $msg = $nxshf->getFixedHtml($msg);
225
+ $msg = str_replace("\r\n","\n", $msg); $msg = str_replace("\n\r","\n", $msg); $msg = str_replace("\r","\n", $msg); $msg = str_replace("\n","<br/>", $msg); // prr($msg); die();
226
+ if (function_exists("doConnectToBlogger")) {$auth = doConnectToBlogger($email, $pass); if ($auth!==false) $ret = $auth; else $ret = doPostToBlogger($blogID, $msgT, $msg, $tags);}
227
+ else {$auth = nsBloggerGetAuth($email, $pass); if ($auth===false) $ret = 'Incorrect Username/Password'; else { $msgT = str_ireplace('&amp;', '&', $msgT);
228
+ $msgT = utf8_encode(str_ireplace('&', '&amp;', $msgT)); $msg = utf8_encode($msg); $ret = nsBloggerNewPost($auth, $blogID, $msgT, $msg);
229
+ }}
230
+ //## /Actual POST Code
231
+ if ( (!is_array($ret)) && $ret!='OK') { if ($postID=='0') prr($ret); nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '. strip_tags(print_r($ret, true)), $extInfo); return $ret; }
232
+ else { if ($postID=='0') { echo 'OK - Message Posted, please see your '.$ntNm.' Page '; nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); return 201;}
233
+ else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted'=>'1', 'pgID'=>$ret['post_id'], 'pDate'=>date('Y-m-d H:i:s')));
234
+ do_action('nxs_actOnBG', array('postID'=>$postID, 'pgID'=>$ret['post_id'], 'ii'=>$ii)); nxs_addToLogN( 'S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo);
235
+ } return 200;
236
+ }
237
+ }
238
+ }
239
+
240
  ?>
inc-cl/di.php CHANGED
@@ -1,268 +1,270 @@
1
- <?php
2
- //## NextScripts Facebook Connection Class
3
- $nxs_snapAvNts[] = array('code'=>'DI', 'lcode'=>'di', 'name'=>'Diigo');
4
-
5
- if (!class_exists("nxs_snapClassDI")) { class nxs_snapClassDI {
6
- //#### Show Common Settings
7
-
8
- function showGenNTSettings($ntOpts){ global $nxs_plurl; $ntInfo = array('code'=>'DI', 'lcode'=>'di', 'name'=>'Diigo', 'defNName'=>'diUName', 'tstReq' => false); ?>
9
- <div class="nxs_box">
10
- <div class="nxs_box_header">
11
- <div class="nsx_iconedTitle" style="margin-bottom:1px;background-image:url(<?php echo $nxs_plurl;?>img/<?php echo $ntInfo['lcode']; ?>16.png);"><?php echo $ntInfo['name']; ?>
12
- <?php $cbo = count($ntOpts); ?> <?php wp_nonce_field( 'ns'.$ntInfo['code'], 'ns'.$ntInfo['code'].'_wpnonce' ); ?>
13
- <?php if ($cbo>1){ ?><div class="nsBigText"><?php echo "(".($cbo=='0'?'No':$cbo)." "; _e('accounts', 'nxs_snap'); echo ")"; ?></div><?php } ?>
14
- </div>
15
- </div>
16
- <div class="nxs_box_inside">
17
- <?php foreach ($ntOpts as $indx=>$pbo){ if (trim($pbo['nName']=='')) $pbo['nName'] = $pbo[$ntInfo['defNName']]; ?>
18
- <p style="margin:0px;margin-left:5px;">
19
- <input value="1" name="<?php echo $ntInfo['lcode']; ?>[<?php echo $indx; ?>][apDo<?php echo $ntInfo['code']; ?>]" onchange="doShowHideBlocks('<?php echo $ntInfo['code']; ?>');" type="checkbox" <?php if ((int)$pbo['do'.$ntInfo['code']] == 1) echo "checked"; ?> /> <?php if ((int)$pbo['catSel'] == 1) { ?> <span onmouseout="nxs_hidePopUpInfo('popOnlyCat');" onmouseover="nxs_showPopUpInfo('popOnlyCat', event);"><?php echo "*[".(substr_count($pbo['catSelEd'], ",")+1)."]*" ?></span><?php } ?>
20
- <strong><?php _e('Auto-publish to', 'nxs_snap'); ?> <?php echo $ntInfo['name']; ?> <i style="color: #005800;"><?php if($pbo['nName']!='') echo "(".$pbo['nName'].")"; ?></i></strong>
21
- &nbsp;&nbsp;<?php if ($ntInfo['tstReq'] && (!isset($pbo[$ntInfo['lcode'].'OK']) || $pbo[$ntInfo['lcode'].'OK']=='')){ ?><b style="color: #800000"><?php _e('Attention requred. Unfinished setup', 'nxs_snap'); ?> ==&gt;</b><?php } ?><a id="do<?php echo $ntInfo['code'].$indx; ?>A" href="#" onclick="doShowHideBlocks2('<?php echo $ntInfo['code'].$indx; ?>');return false;">[<?php _e('Show Settings', 'nxs_snap'); ?>]</a>&nbsp;&nbsp;
22
- <a href="#" onclick="doDelAcct('<?php echo $ntInfo['lcode']; ?>', '<?php echo $indx; ?>', '<?php if (isset($pbo['bgBlogID'])) echo $pbo['nName']; ?>');return false;">[<?php _e('Remove Account', 'nxs_snap'); ?>]</a>
23
- </p><?php $this->showNTSettings($indx, $pbo);
24
- }?>
25
- </div>
26
- </div> <?php
27
- }
28
-
29
- //#### Show NEW Settings Page
30
- function showNewNTSettings($mgpo){ $options = array('nName'=>'', 'doDI'=>'1', 'diUName'=>'', 'diInclTags'=>'1', 'diAttch'=>'', 'diAPIKey'=>'', 'diPass'=>''); $this->showNTSettings($mgpo, $options, true);}
31
-
32
- //#### Show Unit Settings
33
- function showNTSettings($ii, $options, $isNew=false){ global $nxs_plurl; ?>
34
- <div id="doDI<?php echo $ii; ?>Div" class="insOneDiv<?php if ($isNew){ ?> clNewNTSets<?php } ?>" style="background-image: url(<?php echo $nxs_plurl; ?>img/di-bg.png);background-position:90% 10%;"> <input type="hidden" name="apDoSDI<?php echo $ii; ?>" value="0" id="apDoSDI<?php echo $ii; ?>" />
35
-
36
- <div class="nsx_iconedTitle" style="float: right; background-image: url(<?php echo $nxs_plurl; ?>img/di16.png);"><a style="font-size: 12px;" target="_blank" href="http://www.nextscripts.com/setup-installation-diigo-social-networks-auto-poster-wordpress/"><?php $nType="Diigo"; printf( __( 'Detailed %s Installation/Configuration Instructions', 'nxs_snap' ), $nType); ?></a></div>
37
-
38
- <div style="width:100%;"><strong><?php _e('Account Nickname', 'nxs_snap'); ?>:</strong> <i><?php _e('Just so you can easely identify it', 'nxs_snap'); ?></i> </div><input name="di[<?php echo $ii; ?>][nName]" id="dinName<?php echo $ii; ?>" style="font-weight: bold; color: #005800; border: 1px solid #ACACAC; width: 40%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['nName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /><br/>
39
- <?php echo nxs_addQTranslSel('di', $ii, $options['qTLng']); ?>
40
- <?php echo nxs_addPostingDelaySel('di', $ii, $options['nHrs'], $options['nMin']); ?>
41
-
42
- <?php if (!$isNew) { ?>
43
- <div style="width:100%;"><strong><?php _e('Categories', 'nxs_snap'); ?>:</strong>
44
- <input value="0" id="catSelA<?php echo $ii; ?>" type="radio" name="di[<?php echo $ii; ?>][catSel]" <?php if ((int)$options['catSel'] != 1) echo "checked"; ?> /> All
45
- <input value="1" id="catSelSDI<?php echo $ii; ?>" type="radio" name="di[<?php echo $ii; ?>][catSel]" <?php if ((int)$options['catSel'] == 1) echo "checked"; ?> /> <a href="#" style="text-decoration: none;" class="showCats" id="nxs_SCA_DI<?php echo $ii; ?>" onclick="jQuery('#catSelSDI<?php echo $ii; ?>').attr('checked', true); jQuery('#tmpCatSelNT').val('DI<?php echo $ii; ?>'); nxs_markCats( jQuery('#nxs_SC_DI<?php echo $ii; ?>').val() ); jQuery('#showCatSel').bPopup({ modalClose: false, appendTo: '#nsStForm', opacity: 0.6, follow: [false, false], position: [75, 'auto']}); return false;">Selected<?php if ($options['catSelEd']!='') echo "[".(substr_count($options['catSelEd'], ",")+1)."]"; ?></a>
46
- <input type="hidden" name="di[<?php echo $ii; ?>][catSelEd]" id="nxs_SC_DI<?php echo $ii; ?>" value="<?php echo $options['catSelEd']; ?>" />
47
- <br/><i><?php _e('Only selected categories will be autoposted to this account', 'nxs_snap'); ?></i></div>
48
- <br/>
49
- <?php } ?>
50
-
51
- <div id="altFormat" style="">
52
- <div style="width:100%;"><strong id="altFormatText">Diigo API Key:</strong> <span style="font-size: 11px; margin: 0px;">Get it from <a target="_blank" href="http://www.diigo.com/api_keys/">http://www.diigo.com/api_keys</a>.</span></div>
53
- <input name="di[<?php echo $ii; ?>][apDIAPIKey]" id="apDIAPIKey" style="width: 60%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['diAPIKey'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /> <br/>
54
- </div>
55
- <div style="width:100%;"><strong>Diigo Username:</strong> </div><input name="di[<?php echo $ii; ?>][apDIUName]" id="apDIUName" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['diUName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
56
- <div style="width:100%;"><strong>Diigo Password:</strong> </div><input name="di[<?php echo $ii; ?>][apDIPass]" id="apDIPass" type="password" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities(substr($options['diPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($options['diPass'], 5)):$options['diPass'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /> <br/>
57
-
58
- <?php if ($isNew) { ?> <input type="hidden" name="di[<?php echo $ii; ?>][apDoDI]" value="1" id="apDoNewDI<?php echo $ii; ?>" /> <?php } ?><br/>
59
- <p style="margin-bottom: 20px;margin-top: 5px;"><input value="1" id="diInclTags" type="checkbox" name="di[<?php echo $ii; ?>][diInclTags]" <?php if ((int)$options['diInclTags'] == 1) echo "checked"; ?> />
60
- <strong><?php _e('Post with tags', 'nxs_snap'); ?></strong> <?php _e('Tags from the blogpost will be auto posted to Diigo', 'nxs_snap'); ?>
61
- </p>
62
-
63
- <div id="altFormat" style="">
64
- <div style="width:100%;"><strong id="altFormatText"><?php _e('Post Title Format', 'nxs_snap'); ?></strong> (<a href="#" id="apDIMsgTFrmt<?php echo $ii; ?>HintInfo" onclick="mxs_showHideFrmtInfo('apDIMsgTFrmt<?php echo $ii; ?>'); return false;"><?php _e('Show format info', 'nxs_snap'); ?></a>)</div>
65
- <input name="di[<?php echo $ii; ?>][apDIMsgTFrmt]" id="apDIMsgTFrmt<?php echo $ii; ?>" style="width: 50%;" value="<?php if ($isNew) echo "%TITLE%"; else _e(apply_filters('format_to_edit', htmlentities($options['diMsgTFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap'); ?>" onfocus="mxs_showFrmtInfo('apDIMsgTFrmt<?php echo $ii; ?>');" /><?php nxs_doShowHint("apDIMsgTFrmt".$ii); ?>
66
- </div><br/>
67
-
68
- <div id="altFormat" style="">
69
- <div style="width:100%;"><strong id="altFormatText"><?php _e('Post Text Format', 'nxs_snap'); ?></strong> (<a href="#" id="apDIMsgFrmt<?php echo $ii; ?>HintInfo" onclick="mxs_showHideFrmtInfo('apDIMsgFrmt<?php echo $ii; ?>'); return false;"><?php _e('Show format info', 'nxs_snap'); ?></a>)</div>
70
-
71
-
72
- <textarea cols="150" rows="3" id="di<?php echo $ii; ?>SNAPformat" name="di[<?php echo $ii; ?>][apDIMsgFrmt]" style="width:51%;max-width: 650px;" onfocus="jQuery('#di<?php echo $ii; ?>SNAPformat').attr('rows', 6); mxs_showFrmtInfo('apDIMsgFrmt<?php echo $ii; ?>');"><?php if ($isNew) echo "%EXCERPT%"; else _e(apply_filters('format_to_edit', htmlentities($options['diMsgFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap'); ?></textarea>
73
-
74
- <?php nxs_doShowHint("apDIMsgFrmt".$ii); ?>
75
- </div><br/>
76
-
77
- <?php if ($options['diPass']!='') { ?>
78
- <?php wp_nonce_field( 'rePostToDI', 'rePostToDI_wpnonce' ); ?>
79
- <b><?php _e('Test your settings', 'nxs_snap'); ?>:</b>&nbsp;&nbsp;&nbsp; <a href="#" class="NXSButton" onclick="testPost('DI', '<?php echo $ii; ?>'); return false;"><?php printf( __( 'Submit Test Post to %s', 'nxs_snap' ), $nType); ?></a> <?php }
80
- ?><div class="submit"><input type="submit" class="button-primary" name="update_NS_SNAutoPoster_settings" value="<?php _e('Update Settings', 'nxs_snap') ?>" /></div></div><?php
81
- }
82
- //#### Set Unit Settings from POST
83
- function setNTSettings($post, $options){ global $nxs_snapThisPageUrl; $code = 'DI'; $lcode = 'di';
84
- foreach ($post as $ii => $pval){
85
- if (isset($pval['apDIUName']) && $pval['apDIUName']!=''){ if (!isset($options[$ii])) $options[$ii] = array();
86
- if (isset($pval['apDIUName'])) $options[$ii]['diUName'] = trim($pval['apDIUName']);
87
- if (isset($pval['nName'])) $options[$ii]['nName'] = trim($pval['nName']);
88
- if (isset($pval['apDIPass'])) $options[$ii]['diPass'] = 'n5g9a'.nsx_doEncode($pval['apDIPass']); else $options[$ii]['diPass'] = '';
89
- if (isset($pval['apDIAPIKey'])) $options[$ii]['diAPIKey'] = trim($pval['apDIAPIKey']);
90
-
91
- if (isset($pval['catSel'])) $options[$ii]['catSel'] = trim($pval['catSel']);
92
- if ($options[$ii]['catSel']=='1' && trim($pval['catSelEd'])!='') $options[$ii]['catSelEd'] = trim($pval['catSelEd']); else $options[$ii]['catSelEd'] = '';
93
-
94
- if (isset($pval['diInclTags'])) $options[$ii]['diInclTags'] = $pval['diInclTags']; else $options[$ii]['diInclTags'] = 0;
95
- if (isset($pval['apDIMsgTFrmt'])) $options[$ii]['diMsgTFormat'] = trim($pval['apDIMsgTFrmt']);
96
- if (isset($pval['apDIMsgFrmt'])) $options[$ii]['diMsgFormat'] = trim($pval['apDIMsgFrmt']);
97
- if (isset($pval['apDoDI'])) $options[$ii]['doDI'] = $pval['apDoDI']; else $options[$ii]['doDI'] = 0;
98
- if (isset($pval['delayHrs'])) $options[$ii]['nHrs'] = trim($pval['delayHrs']); if (isset($pval['delayMin'])) $options[$ii]['nMin'] = trim($pval['delayMin']);
99
- if (isset($pval['qTLng'])) $options[$ii]['qTLng'] = trim($pval['qTLng']);
100
- }
101
- } return $options;
102
- }
103
- //#### Show Post->Edit Meta Box Settings
104
- function showEdPostNTSettings($ntOpts, $post){ global $nxs_plurl; $post_id = $post->ID;
105
- foreach($ntOpts as $ii=>$ntOpt) { $pMeta = maybe_unserialize(get_post_meta($post_id, 'snapDI', true)); if (is_array($pMeta)) $ntOpt = $this->adjMetaOpt($ntOpt, $pMeta[$ii]);
106
- $doDI = $ntOpt['doDI'] && (is_array($pMeta) || $ntOpt['catSel']!='1');
107
- $isAvailDI = $ntOpt['diUName']!='' && $ntOpt['diPass']!=''; $diMsgFormat = htmlentities($ntOpt['diMsgFormat'], ENT_COMPAT, "UTF-8"); $diMsgTFormat = htmlentities($ntOpt['diMsgTFormat'], ENT_COMPAT, "UTF-8");
108
- ?>
109
- <tr><th style="text-align:left;" colspan="2"><?php if ( $ntOpt['catSel']=='1' && trim($ntOpt['catSelEd'])!='' ) { ?> <input type="hidden" class="nxs_SC" id="nxs_SC_DI<?php echo $ii; ?>" value="<?php echo $ntOpt['catSelEd']; ?>" /> <?php } ?>
110
- <?php if ($isAvailDI) { ?><input class="nxsGrpDoChb" value="1" id="doDI<?php echo $ii; ?>" <?php if ($post->post_status == "publish") echo 'disabled="disabled"';?> type="checkbox" name="di[<?php echo $ii; ?>][doDI]" <?php if ((int)$doDI == 1) echo 'checked="checked" title="def"'; ?> />
111
- <?php if ($post->post_status == "publish") { ?> <input type="hidden" name="di[<?php echo $ii; ?>][doDI]" value="<?php echo $doDI;?>"> <?php } ?> <?php } ?>
112
-
113
- <div class="nsx_iconedTitle" style="display: inline; font-size: 13px; background-image: url(<?php echo $nxs_plurl; ?>img/di16.png);">Diigo - <?php _e('publish to', 'nxs_snap') ?> (<i style="color: #005800;"><?php echo $ntOpt['nName']; ?></i>)</div></th> <td><?php //## Only show RePost button if the post is "published"
114
- if ($post->post_status == "publish" && $isAvailDI) { ?><input alt="<?php echo $ii; ?>" style="float: right;" onmouseout="hidePopShAtt('SV');" onmouseover="showPopShAtt('SV', event);" onclick="return false;" type="button" class="button" name="rePostToDI_repostButton" id="rePostToDI_button" value="<?php _e('Repost to Diigo', 'nxs_snap') ?>" />
115
- <?php wp_nonce_field( 'rePostToDI', 'rePostToDI_wpnonce' ); } ?>
116
- <?php if (is_array($pMeta) && is_array($pMeta[$ii]) && isset($pMeta[$ii]['pgID']) ) {
117
- ?> <span id="pstdDI<?php echo $ii; ?>" style="float: right; padding-top: 4px; padding-right: 10px;">
118
- <a style="font-size: 10px;" href="http://www.diigo.com/user/<?php echo $ntOpt['diUName']; ?>" target="_blank"><?php $nType="Diigo"; printf( __( 'Posted on', 'nxs_snap' ), $nType); ?> <?php echo (isset($pMeta[$ii]['pDate']) && $pMeta[$ii]['pDate']!='')?(" (".$pMeta[$ii]['pDate'].")"):""; ?></a>
119
- </span><?php } ?>
120
- </td></tr>
121
- <?php if (!$isAvailDI) { ?><tr><th scope="row" style="text-align:right; width:150px; padding-top: 5px; padding-right:10px;"></th> <td><b>Setup your Diigo Account to AutoPost to Diigo</b>
122
- <?php } elseif ($post->post_status != "pubZlish") { ?>
123
- <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top: 6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Title Format:', 'nxs_snap') ?></th>
124
- <td><input value="<?php echo $diMsgTFormat ?>" type="text" name="di[<?php echo $ii; ?>][SNAPformatT]" style="width:60%;max-width: 610px;" onfocus="jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apDIMsgTFrmt<?php echo $ii; ?>');"/><?php nxs_doShowHint("apDIMsgTFrmt".$ii, '', '58'); ?></td></tr>
125
- <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top: 6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Text Format:', 'nxs_snap') ?></th>
126
- <td>
127
- <textarea cols="150" rows="1" id="di<?php echo $ii; ?>SNAPformat" name="di[<?php echo $ii; ?>][SNAPformat]" style="width:60%;max-width: 610px;" onfocus="jQuery('#di<?php echo $ii; ?>SNAPformat').attr('rows', 4); jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apDIMsgFrmt<?php echo $ii; ?>');"><?php echo $diMsgFormat; ?></textarea>
128
- <?php nxs_doShowHint("apDIMsgFrmt".$ii, '', '58'); ?></td></tr>
129
- <?php }
130
- }
131
- }
132
- //#### Save Meta Tags to the Post
133
- function adjMetaOpt($optMt, $pMeta){ if (isset($pMeta['isPosted'])) $optMt['isPosted'] = $pMeta['isPosted']; else $optMt['isPosted'] = '';
134
- if (isset($pMeta['SNAPformat'])) $optMt['diMsgFormat'] = $pMeta['SNAPformat'];
135
- if (isset($pMeta['SNAPformatT'])) $optMt['diMsgTFormat'] = $pMeta['SNAPformatT'];
136
- if (isset($pMeta['doDI'])) $optMt['doDI'] = $pMeta['doDI'] == 1?1:0; else { if (isset($pMeta['SNAPformat'])) $optMt['doDI'] = 0; }
137
- if (isset($pMeta['SNAPincludeDI']) && $pMeta['SNAPincludeDI'] == '1' ) $optMt['doDI'] = 1;
138
- return $optMt;
139
- }
140
- }}
141
- if (!function_exists("nxs_rePostToDI_ajax")) {
142
- function nxs_rePostToDI_ajax() { check_ajax_referer('rePostToDI'); $postID = $_POST['id']; $options = get_option('NS_SNAutoPoster');
143
- foreach ($options['di'] as $ii=>$two) if ($ii==$_POST['nid']) { $two['ii'] = $ii; $two['pType'] = 'aj'; //if ($two['gpPageID'].$two['gpUName']==$_POST['nid']) {
144
- $gppo = get_post_meta($postID, 'snapDI', true); $gppo = maybe_unserialize($gppo);// prr($gppo);
145
- if (is_array($gppo) && isset($gppo[$ii]) && is_array($gppo[$ii])){ $ntClInst = new nxs_snapClassDI(); $two = $ntClInst->adjMetaOpt($two, $gppo[$ii]); }
146
- $result = nxs_doPublishToDI($postID, $two); if ($result == 200) die("Successfully sent your post to Diigo."); else die($result);
147
- }
148
- }
149
- }
150
-
151
- if (!function_exists("nxs_getDIHeaders")) { function nxs_getDIHeaders($ref, $uname, $pass, $post=false){ $hdrsArr = array();
152
- $hdrsArr['X-Requested-With']='XMLHttpRequest'; $hdrsArr['Connection']='keep-alive'; $hdrsArr['Referer']=$ref;
153
- $hdrsArr['User-Agent']='Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.22 Safari/537.11';
154
- if($post) $hdrsArr['Content-Type']='application/x-www-form-urlencoded';
155
- $hdrsArr['Accept']='application/json, text/javascript, */*; q=0.01';
156
- $hdrsArr['Authorization']= 'Basic '.base64_encode($uname.':'.$pass);
157
- $hdrsArr['Accept-Encoding']='gzip,deflate,sdch'; $hdrsArr['Accept-Language']='en-US,en;q=0.8'; $hdrsArr['Accept-Charset']='ISO-8859-1,utf-8;q=0.7,*;q=0.3'; return $hdrsArr;
158
- }}
159
- if (!function_exists("nxs_doCheckDI")) {function nxs_doCheckDI($url){ global $nxs_diCkArray; $hdrsArr = nxs_getDIHeaders($url); $ckArr = $nxs_diCkArray;
160
- $response = wp_remote_get($url, array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'cookies' => $ckArr));
161
- if (stripos($response['body'],'logouthash=')===false) return 'Bad Saved Login';
162
- if ( stripos($response['body'], 'usercp.php')!==false && stripos($response['body'], 'logouthash')!==false){ /*echo "You are IN"; */ return false;
163
- } else return 'No Saved Login';
164
- return false;
165
- }}
166
- if (!function_exists("nxs_doConnectToDI")) { function nxs_doConnectToDI($u, $p, $url){ global $nxs_diCkArray; $hdrsArr = nxs_getDIHeaders($url, true); echo "LOGGIN";
167
- $response = wp_remote_get($url); $contents = $response['body']; //$response['body'] = htmlentities($response['body']); prr($response); die();
168
- $ckArr = $response['cookies']; $mdhashLoc = stripos($contents, 'md5hash(di_login_password');
169
- if ($mdhashLoc===false) return "No DI found";
170
- $frmTxt = CutFromTo($contents, 'md5hash(di_login_password','</form>'); $md = array(); $flds = array();
171
- while (stripos($frmTxt, '<input')!==false){ $inpField = trim(CutFromTo($frmTxt,'<input', '>')); $name = trim(CutFromTo($inpField,'name="', '"'));
172
- if ( stripos($inpField, '"hidden"')!==false && $name!='' && !in_array($name, $md)) { $md[] = $name; $val = trim(CutFromTo($inpField,'value="', '"')); $flds[$name]= $val; $mids .= "&".$name."=".$val;}
173
- $frmTxt = substr($frmTxt, stripos($frmTxt, '<input')+8);
174
- } $flds['di_login_username'] = $u; $flds['di_login_md5password'] = md5($p); $flds['di_login_md5password_utf'] = md5($p); $flds['cookieuser'] = '1'; $flds['do'] = 'login';
175
-
176
- // $logURL = substr($contents, $mdhashLoc-250, 250); $logURL = CutFromTo($logURL, 'action="', '"');
177
- if (stripos($contents, 'base href="')!==false) $baseURL = trim(CutFromTo($contents,'base href="', '"')); else { $uarr = explode('/',$url); $dd = $uarr[count($uarr)-1]; $baseURL = str_replace($dd, '', $url);}
178
-
179
- //echo $baseURL.'login.php?do=login'; prr($flds);
180
- $r2 = wp_remote_post( $baseURL.'login.php?do=login', array( 'method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'body' => $flds, 'cookies' => $ckArr));
181
-
182
- //$r2['body'] = htmlentities($r2['body']); prr($r2);
183
-
184
- if (stripos($r2['body'],'exec_refresh()')!==false) { $ckArr = nxsMergeArraysOV($ckArr, $r2['cookies']); $nxs_diCkArray = $ckArr; return false; } else return "Bad Username/Password";
185
- }}
186
-
187
- if (!function_exists("nxs_doPostToDI")) { function nxs_doPostToDI($url, $subj, $msg, $lnk, $tags){ global $nxs_diCkArray; $hdrsArr = nxs_getDIHeaders($url); $ckArr = $nxs_diCkArray;
188
- $response = wp_remote_get($url, array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'cookies' => $ckArr));
189
- $contents = $response['body']; //$response['body'] = htmlentities($response['body']); prr($response); die();
190
- if (stripos($contents, 'base href="')!==false) $baseURL = trim(CutFromTo($contents,'base href="', '"')); else { $uarr = explode('/',$url); $dd = $uarr[count($uarr)-1]; $baseURL = str_replace($dd, '', $url);}
191
- if (stripos($contents, 'newthread.php?do=newthread')!==false) $mdd='t'; elseif (stripos($contents, 'newreply.php?')!==false) $mdd='p'; else return "No Thread/Post Controls found";
192
-
193
- if ($mdd=='t'){ $fid = CutFromTo($contents, 'newthread.php?do=newthread','"'); // echo $baseURL.'newthread.php?do=newthread'.str_replace('&amp;','&',$fid);
194
- $response = wp_remote_get( $baseURL.'newthread.php?do=newthread'.str_replace('&amp;','&',$fid), array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'cookies' => $ckArr)); $contents = $response['body'];
195
- $frmTxt = CutFromTo($contents, 'newthread.php?do=postthread','</form>'); $md = array(); $flds = array(); //prr($frmTxt);
196
- while (stripos($frmTxt, '<input')!==false){ $inpField = trim(CutFromTo($frmTxt,'<input', '>')); $name = trim(CutFromTo($inpField,'name="', '"'));
197
- if ( stripos($inpField, '"hidden"')!==false && $name!='' && !in_array($name, $md)) { $md[] = $name; $val = trim(CutFromTo($inpField,'value="', '"')); $flds[$name]= $val; $mids .= "&".$name."=".$val;}
198
- $frmTxt = substr($frmTxt, stripos($frmTxt, '<input')+8);
199
- } $flds['subject'] = $subj; $flds['message'] = $msg; $flds['message_backup'] = $msg; $flds['wysiwyg'] = '1'; $flds['do'] = 'postthread'; $flds['taglist'] = $tags; $flds['parseurl'] = '1'; $flds['sbutton'] = 'Submit+New+Thread';
200
- $smURL = $baseURL.'newthread.php?do=postthread'.str_replace('&amp;','&',$fid);
201
- }
202
-
203
- if ($mdd=='p'){ $fid = CutFromTo($contents, 'newreply.php?do=newreply','"');
204
- $response = wp_remote_get( $baseURL.'newreply.php?do=newreply'.str_replace('&amp;','&',$fid), array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'cookies' => $ckArr)); $contents = $response['body'];
205
-
206
- $frmTxt = CutFromTo($contents, 'newreply.php?do=postreply','</form>'); $md = array(); $flds = array(); //prr($frmTxt);
207
-
208
- while (stripos($frmTxt, '<input')!==false){ $inpField = trim(CutFromTo($frmTxt,'<input', '>')); $name = trim(CutFromTo($inpField,'name="', '"'));
209
- if ( stripos($inpField, '"hidden"')!==false && $name!='' && !in_array($name, $md)) { $md[] = $name; $val = trim(CutFromTo($inpField,'value="', '"')); $flds[$name]= $val; $mids .= "&".$name."=".$val;}
210
- $frmTxt = substr($frmTxt, stripos($frmTxt, '<input')+8);
211
- } $flds['title'] = $subj; $flds['message'] = $msg; $flds['message_backup'] = $msg; $flds['wysiwyg'] = '1'; $flds['do'] = 'postreply'; $flds['parseurl'] = '1'; $flds['sbutton'] = 'Submit+Reply';
212
- $smURL = $baseURL.'newreply.php?do=postreply'.str_replace('&amp;','&',$fid);
213
- }
214
-
215
- //echo $smURL."|"; prr($flds);
216
- $r2 = wp_remote_post( $smURL, array( 'method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'body' => $flds, 'cookies' => $ckArr));
217
- if (stripos($r2['body'], 'errorblock')!==false) return trim(strip_tags( CutFromTo($r2['body'], 'errorblock','</div>')));
218
- if (stripos($r2['body'], 'exec_refresh()')!==false && stripos($r2['body'], 'blockrow restore">')!==false) return trim(strip_tags( CutFromTo($r2['body'], 'blockrow restore">','</p>')));
219
- if (stripos($r2['body'], '<error>')!==false) return trim(strip_tags( CutFromTo($r2['body'], '<error>','</error>')));
220
- if ( $r2['response']['code']=='302' || $r2['response']['code']=='303') return 'OK';
221
- if (stripos($r2['body'], '<newpostid>')!==false || stripos($r2['body'], 'postbit postid="')!==false ) return 'OK';
222
-
223
- // $r2['body'] = htmlentities($r2['body']); prr($r2); die();
224
-
225
- return "Something wrong";
226
- }}
227
-
228
- if (!function_exists("nxs_doPublishToDI")) { //## Second Function to Post to DI
229
- function nxs_doPublishToDI($postID, $options){ global $nxs_diCkArray; $ntCd = 'DI'; $ntCdL = 'di'; $ntNm = 'Diigo';
230
- // if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToDI', array($postID, $options));
231
- $ii = $options['ii']; if (!isset($options['pType'])) $options['pType'] = 'im'; if ($options['pType']=='sh') sleep(rand(1, 10));
232
- $logNT = '<span style="color:#000080">Diigo</span> - '.$options['nName'];
233
- $snap_ap = get_post_meta($postID, 'snap'.$ntCd, true); $snap_ap = maybe_unserialize($snap_ap);
234
- if ($options['pType']!='aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
235
- $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted!='2') { sleep(5);
236
- nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:'.$postID, 'Already posted. No reason for posting duplicate'); return;
237
- }
238
- }
239
- if ($postID=='0') { echo "Testing ... <br/><br/>"; $link = home_url(); $msg = 'Test Message from '.$link; $msgT = 'Test Link from '.$link; } else {
240
- $post = get_post($postID); if(!$post) return; $link = get_permalink($postID);
241
- $msgFormat = $options['diMsgFormat']; $diCat = $options['diCat']; $msg = nsFormatMessage($msgFormat, $postID); $msgFormatT = $options['diMsgTFormat']; $msgT = nsFormatMessage($msgFormatT, $postID);
242
- nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted'=>'1'));
243
- }
244
- $extInfo = ' | PostID: '.$postID." - ".$post->post_title;
245
- //## Actual POST Code
246
- $email = $options['diUName']; $pass = (substr($options['diPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($options['diPass'], 5)):$options['diPass']);
247
- $dusername = $options['diUName']; //$link = urlencode($link); $desc = urlencode(substr($msg, 0, 500));
248
-
249
- $t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) {$tggs[] = $tagA->name;} $tags = (implode(',',$tggs)); $tags = str_replace(' ','+',$tags);
250
-
251
- $flds = array(); $flds['key']=$options['diAPIKey']; $flds['url']=$link; $flds['title']=nsTrnc($msgT, 250); $flds['desc']=nsTrnc($msg, 250); $flds['tags']=$tags; $flds['shared']='yes';
252
- $hdrsArr = nxs_getDIHeaders('https://secure.diigo.com/api/v2/bookmarks', $dusername, $pass, true);
253
- $cnt = wp_remote_post( 'https://secure.diigo.com/api/v2/bookmarks', array( 'method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'body' => $flds));
254
-
255
- if( is_wp_error( $cnt ) ) {
256
- $ret = 'Something went wrong - '; nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.$ret. "ERR: ".print_r($cnt, true), $extInfo);
257
- } else {
258
- if (is_array($cnt) && stripos($cnt['body'],'"code":1')!==false)
259
- { $ret = 'OK'; nxs_metaMarkAsPosted($postID, 'DI', $options['ii'], array('isPosted'=>'1', 'pgID'=>'DI', 'pDate'=>date('Y-m-d H:i:s'))); nxs_addToLogN( 'S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); }
260
- else { if ($cnt['response']['code']=='401') $ret = " Incorrect Username/Password "; else $ret = 'Something went wrong - '; nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.$ret. "ERR: ".print_r($cnt, true), $extInfo);
261
- }
262
- }
263
- if ($ret!='OK') { if ($postID=='0') echo $ret; } else if ($postID=='0') { echo 'OK - Message Posted, please see your Diigo Page'; nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); }
264
- if ($ret == 'OK') return 200; else return $ret;
265
-
266
- }
267
- }
 
 
268
  ?>
1
+ <?php
2
+ //## NextScripts Facebook Connection Class
3
+ $nxs_snapAvNts[] = array('code'=>'DI', 'lcode'=>'di', 'name'=>'Diigo');
4
+
5
+ if (!class_exists("nxs_snapClassDI")) { class nxs_snapClassDI {
6
+ //#### Show Common Settings
7
+
8
+ function showGenNTSettings($ntOpts){ global $nxs_plurl; $ntInfo = array('code'=>'DI', 'lcode'=>'di', 'name'=>'Diigo', 'defNName'=>'diUName', 'tstReq' => false); ?>
9
+ <div class="nxs_box">
10
+ <div class="nxs_box_header">
11
+ <div class="nsx_iconedTitle" style="margin-bottom:1px;background-image:url(<?php echo $nxs_plurl;?>img/<?php echo $ntInfo['lcode']; ?>16.png);"><?php echo $ntInfo['name']; ?>
12
+ <?php $cbo = count($ntOpts); ?> <?php wp_nonce_field( 'ns'.$ntInfo['code'], 'ns'.$ntInfo['code'].'_wpnonce' ); ?>
13
+ <?php if ($cbo>1){ ?><div class="nsBigText"><?php echo "(".($cbo=='0'?'No':$cbo)." "; _e('accounts', 'nxs_snap'); echo ")"; ?></div><?php } ?>
14
+ </div>
15
+ </div>
16
+ <div class="nxs_box_inside">
17
+ <?php foreach ($ntOpts as $indx=>$pbo){ if (trim($pbo['nName']=='')) $pbo['nName'] = $pbo[$ntInfo['defNName']]; ?>
18
+ <p style="margin:0px;margin-left:5px;">
19
+ <input value="1" name="<?php echo $ntInfo['lcode']; ?>[<?php echo $indx; ?>][apDo<?php echo $ntInfo['code']; ?>]" onchange="doShowHideBlocks('<?php echo $ntInfo['code']; ?>');" type="checkbox" <?php if ((int)$pbo['do'.$ntInfo['code']] == 1) echo "checked"; ?> /> <?php if ((int)$pbo['catSel'] == 1) { ?> <span onmouseout="nxs_hidePopUpInfo('popOnlyCat');" onmouseover="nxs_showPopUpInfo('popOnlyCat', event);"><?php echo "*[".(substr_count($pbo['catSelEd'], ",")+1)."]*" ?></span><?php } ?>
20
+ <strong><?php _e('Auto-publish to', 'nxs_snap'); ?> <?php echo $ntInfo['name']; ?> <i style="color: #005800;"><?php if($pbo['nName']!='') echo "(".$pbo['nName'].")"; ?></i></strong>
21
+ &nbsp;&nbsp;<?php if ($ntInfo['tstReq'] && (!isset($pbo[$ntInfo['lcode'].'OK']) || $pbo[$ntInfo['lcode'].'OK']=='')){ ?><b style="color: #800000"><?php _e('Attention requred. Unfinished setup', 'nxs_snap'); ?> ==&gt;</b><?php } ?><a id="do<?php echo $ntInfo['code'].$indx; ?>A" href="#" onclick="doShowHideBlocks2('<?php echo $ntInfo['code'].$indx; ?>');return false;">[<?php _e('Show Settings', 'nxs_snap'); ?>]</a>&nbsp;&nbsp;
22
+ <a href="#" onclick="doDelAcct('<?php echo $ntInfo['lcode']; ?>', '<?php echo $indx; ?>', '<?php if (isset($pbo['bgBlogID'])) echo $pbo['nName']; ?>');return false;">[<?php _e('Remove Account', 'nxs_snap'); ?>]</a>
23
+ </p><?php $this->showNTSettings($indx, $pbo);
24
+ }?>
25
+ </div>
26
+ </div> <?php
27
+ }
28
+
29
+ //#### Show NEW Settings Page
30
+ function showNewNTSettings($mgpo){ $options = array('nName'=>'', 'doDI'=>'1', 'diUName'=>'', 'diInclTags'=>'1', 'diAttch'=>'', 'diAPIKey'=>'', 'diPass'=>''); $this->showNTSettings($mgpo, $options, true);}
31
+
32
+ //#### Show Unit Settings
33
+ function showNTSettings($ii, $options, $isNew=false){ global $nxs_plurl;
34
+ if (!isset($options['nHrs'])) $options['nHrs'] = 0; if (!isset($options['nMin'])) $options['nMin'] = 0; if (!isset($options['catSel'])) $options['catSel'] = 0; if (!isset($options['catSelEd'])) $options['catSelEd'] = '';
35
+ if (!isset($options['nDays'])) $options['nDays'] = 0; if (!isset($options['qTLng'])) $options['qTLng'] = ''; ?>
36
+ <div id="doDI<?php echo $ii; ?>Div" class="insOneDiv<?php if ($isNew){ ?> clNewNTSets<?php } ?>" style="background-image: url(<?php echo $nxs_plurl; ?>img/di-bg.png);background-position:90% 10%;"> <input type="hidden" name="apDoSDI<?php echo $ii; ?>" value="0" id="apDoSDI<?php echo $ii; ?>" />
37
+
38
+ <div class="nsx_iconedTitle" style="float: right; background-image: url(<?php echo $nxs_plurl; ?>img/di16.png);"><a style="font-size: 12px;" target="_blank" href="http://www.nextscripts.com/setup-installation-diigo-social-networks-auto-poster-wordpress/"><?php $nType="Diigo"; printf( __( 'Detailed %s Installation/Configuration Instructions', 'nxs_snap' ), $nType); ?></a></div>
39
+
40
+ <div style="width:100%;"><strong><?php _e('Account Nickname', 'nxs_snap'); ?>:</strong> <i><?php _e('Just so you can easely identify it', 'nxs_snap'); ?></i> </div><input name="di[<?php echo $ii; ?>][nName]" id="dinName<?php echo $ii; ?>" style="font-weight: bold; color: #005800; border: 1px solid #ACACAC; width: 40%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['nName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /><br/>
41
+ <?php echo nxs_addQTranslSel('di', $ii, $options['qTLng']); ?>
42
+ <?php echo nxs_addPostingDelaySel('di', $ii, $options['nHrs'], $options['nMin']); ?>
43
+
44
+ <?php if (!$isNew) { ?>
45
+ <div style="width:100%;"><strong><?php _e('Categories', 'nxs_snap'); ?>:</strong>
46
+ <input value="0" id="catSelA<?php echo $ii; ?>" type="radio" name="di[<?php echo $ii; ?>][catSel]" <?php if ((int)$options['catSel'] != 1) echo "checked"; ?> /> All
47
+ <input value="1" id="catSelSDI<?php echo $ii; ?>" type="radio" name="di[<?php echo $ii; ?>][catSel]" <?php if ((int)$options['catSel'] == 1) echo "checked"; ?> /> <a href="#" style="text-decoration: none;" class="showCats" id="nxs_SCA_DI<?php echo $ii; ?>" onclick="jQuery('#catSelSDI<?php echo $ii; ?>').attr('checked', true); jQuery('#tmpCatSelNT').val('DI<?php echo $ii; ?>'); nxs_markCats( jQuery('#nxs_SC_DI<?php echo $ii; ?>').val() ); jQuery('#showCatSel').bPopup({ modalClose: false, appendTo: '#nsStForm', opacity: 0.6, follow: [false, false], position: [75, 'auto']}); return false;">Selected<?php if ($options['catSelEd']!='') echo "[".(substr_count($options['catSelEd'], ",")+1)."]"; ?></a>
48
+ <input type="hidden" name="di[<?php echo $ii; ?>][catSelEd]" id="nxs_SC_DI<?php echo $ii; ?>" value="<?php echo $options['catSelEd']; ?>" />
49
+ <br/><i><?php _e('Only selected categories will be autoposted to this account', 'nxs_snap'); ?></i></div>
50
+ <br/>
51
+ <?php } ?>
52
+
53
+ <div id="altFormat" style="">
54
+ <div style="width:100%;"><strong id="altFormatText">Diigo API Key:</strong> <span style="font-size: 11px; margin: 0px;">Get it from <a target="_blank" href="http://www.diigo.com/api_keys/">http://www.diigo.com/api_keys</a>.</span></div>
55
+ <input name="di[<?php echo $ii; ?>][apDIAPIKey]" id="apDIAPIKey" style="width: 60%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['diAPIKey'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /> <br/>
56
+ </div>
57
+ <div style="width:100%;"><strong>Diigo Username:</strong> </div><input name="di[<?php echo $ii; ?>][apDIUName]" id="apDIUName" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['diUName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
58
+ <div style="width:100%;"><strong>Diigo Password:</strong> </div><input name="di[<?php echo $ii; ?>][apDIPass]" id="apDIPass" type="password" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities(substr($options['diPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($options['diPass'], 5)):$options['diPass'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /> <br/>
59
+
60
+ <?php if ($isNew) { ?> <input type="hidden" name="di[<?php echo $ii; ?>][apDoDI]" value="1" id="apDoNewDI<?php echo $ii; ?>" /> <?php } ?><br/>
61
+ <p style="margin-bottom: 20px;margin-top: 5px;"><input value="1" id="diInclTags" type="checkbox" name="di[<?php echo $ii; ?>][diInclTags]" <?php if ((int)$options['diInclTags'] == 1) echo "checked"; ?> />
62
+ <strong><?php _e('Post with tags', 'nxs_snap'); ?></strong> <?php _e('Tags from the blogpost will be auto posted to Diigo', 'nxs_snap'); ?>
63
+ </p>
64
+
65
+ <div id="altFormat" style="">
66
+ <div style="width:100%;"><strong id="altFormatText"><?php _e('Post Title Format', 'nxs_snap'); ?></strong> (<a href="#" id="apDIMsgTFrmt<?php echo $ii; ?>HintInfo" onclick="mxs_showHideFrmtInfo('apDIMsgTFrmt<?php echo $ii; ?>'); return false;"><?php _e('Show format info', 'nxs_snap'); ?></a>)</div>
67
+ <input name="di[<?php echo $ii; ?>][apDIMsgTFrmt]" id="apDIMsgTFrmt<?php echo $ii; ?>" style="width: 50%;" value="<?php if ($isNew) echo "%TITLE%"; else _e(apply_filters('format_to_edit', htmlentities($options['diMsgTFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap'); ?>" onfocus="mxs_showFrmtInfo('apDIMsgTFrmt<?php echo $ii; ?>');" /><?php nxs_doShowHint("apDIMsgTFrmt".$ii); ?>
68
+ </div><br/>
69
+
70
+ <div id="altFormat" style="">
71
+ <div style="width:100%;"><strong id="altFormatText"><?php _e('Post Text Format', 'nxs_snap'); ?></strong> (<a href="#" id="apDIMsgFrmt<?php echo $ii; ?>HintInfo" onclick="mxs_showHideFrmtInfo('apDIMsgFrmt<?php echo $ii; ?>'); return false;"><?php _e('Show format info', 'nxs_snap'); ?></a>)</div>
72
+
73
+
74
+ <textarea cols="150" rows="3" id="di<?php echo $ii; ?>SNAPformat" name="di[<?php echo $ii; ?>][apDIMsgFrmt]" style="width:51%;max-width: 650px;" onfocus="jQuery('#di<?php echo $ii; ?>SNAPformat').attr('rows', 6); mxs_showFrmtInfo('apDIMsgFrmt<?php echo $ii; ?>');"><?php if ($isNew) echo "%EXCERPT%"; else _e(apply_filters('format_to_edit', htmlentities($options['diMsgFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap'); ?></textarea>
75
+
76
+ <?php nxs_doShowHint("apDIMsgFrmt".$ii); ?>
77
+ </div><br/>
78
+
79
+ <?php if ($options['diPass']!='') { ?>
80
+ <?php wp_nonce_field( 'rePostToDI', 'rePostToDI_wpnonce' ); ?>
81
+ <b><?php _e('Test your settings', 'nxs_snap'); ?>:</b>&nbsp;&nbsp;&nbsp; <a href="#" class="NXSButton" onclick="testPost('DI', '<?php echo $ii; ?>'); return false;"><?php printf( __( 'Submit Test Post to %s', 'nxs_snap' ), $nType); ?></a> <?php }
82
+ ?><div class="submit"><input type="submit" class="button-primary" name="update_NS_SNAutoPoster_settings" value="<?php _e('Update Settings', 'nxs_snap') ?>" /></div></div><?php
83
+ }
84
+ //#### Set Unit Settings from POST
85
+ function setNTSettings($post, $options){ global $nxs_snapThisPageUrl; $code = 'DI'; $lcode = 'di';
86
+ foreach ($post as $ii => $pval){
87
+ if (isset($pval['apDIUName']) && $pval['apDIUName']!=''){ if (!isset($options[$ii])) $options[$ii] = array();
88
+ if (isset($pval['apDIUName'])) $options[$ii]['diUName'] = trim($pval['apDIUName']);
89
+ if (isset($pval['nName'])) $options[$ii]['nName'] = trim($pval['nName']);
90
+ if (isset($pval['apDIPass'])) $options[$ii]['diPass'] = 'n5g9a'.nsx_doEncode($pval['apDIPass']); else $options[$ii]['diPass'] = '';
91
+ if (isset($pval['apDIAPIKey'])) $options[$ii]['diAPIKey'] = trim($pval['apDIAPIKey']);
92
+
93
+ if (isset($pval['catSel'])) $options[$ii]['catSel'] = trim($pval['catSel']);
94
+ if ($options[$ii]['catSel']=='1' && trim($pval['catSelEd'])!='') $options[$ii]['catSelEd'] = trim($pval['catSelEd']); else $options[$ii]['catSelEd'] = '';
95
+
96
+ if (isset($pval['diInclTags'])) $options[$ii]['diInclTags'] = $pval['diInclTags']; else $options[$ii]['diInclTags'] = 0;
97
+ if (isset($pval['apDIMsgTFrmt'])) $options[$ii]['diMsgTFormat'] = trim($pval['apDIMsgTFrmt']);
98
+ if (isset($pval['apDIMsgFrmt'])) $options[$ii]['diMsgFormat'] = trim($pval['apDIMsgFrmt']);
99
+ if (isset($pval['apDoDI'])) $options[$ii]['doDI'] = $pval['apDoDI']; else $options[$ii]['doDI'] = 0;
100
+ if (isset($pval['delayHrs'])) $options[$ii]['nHrs'] = trim($pval['delayHrs']); if (isset($pval['delayMin'])) $options[$ii]['nMin'] = trim($pval['delayMin']);
101
+ if (isset($pval['qTLng'])) $options[$ii]['qTLng'] = trim($pval['qTLng']);
102
+ }
103
+ } return $options;
104
+ }
105
+ //#### Show Post->Edit Meta Box Settings
106
+ function showEdPostNTSettings($ntOpts, $post){ global $nxs_plurl; $post_id = $post->ID;
107
+ foreach($ntOpts as $ii=>$ntOpt) { $pMeta = maybe_unserialize(get_post_meta($post_id, 'snapDI', true)); if (is_array($pMeta)) $ntOpt = $this->adjMetaOpt($ntOpt, $pMeta[$ii]);
108
+ $doDI = $ntOpt['doDI'] && (is_array($pMeta) || $ntOpt['catSel']!='1');
109
+ $isAvailDI = $ntOpt['diUName']!='' && $ntOpt['diPass']!=''; $diMsgFormat = htmlentities($ntOpt['diMsgFormat'], ENT_COMPAT, "UTF-8"); $diMsgTFormat = htmlentities($ntOpt['diMsgTFormat'], ENT_COMPAT, "UTF-8");
110
+ ?>
111
+ <tr><th style="text-align:left;" colspan="2"><?php if ( $ntOpt['catSel']=='1' && trim($ntOpt['catSelEd'])!='' ) { ?> <input type="hidden" class="nxs_SC" id="nxs_SC_DI<?php echo $ii; ?>" value="<?php echo $ntOpt['catSelEd']; ?>" /> <?php } ?>
112
+ <?php if ($isAvailDI) { ?><input class="nxsGrpDoChb" value="1" id="doDI<?php echo $ii; ?>" <?php if ($post->post_status == "publish") echo 'disabled="disabled"';?> type="checkbox" name="di[<?php echo $ii; ?>][doDI]" <?php if ((int)$doDI == 1) echo 'checked="checked" title="def"'; ?> />
113
+ <?php if ($post->post_status == "publish") { ?> <input type="hidden" name="di[<?php echo $ii; ?>][doDI]" value="<?php echo $doDI;?>"> <?php } ?> <?php } ?>
114
+
115
+ <div class="nsx_iconedTitle" style="display: inline; font-size: 13px; background-image: url(<?php echo $nxs_plurl; ?>img/di16.png);">Diigo - <?php _e('publish to', 'nxs_snap') ?> (<i style="color: #005800;"><?php echo $ntOpt['nName']; ?></i>)</div></th> <td><?php //## Only show RePost button if the post is "published"
116
+ if ($post->post_status == "publish" && $isAvailDI) { ?><input alt="<?php echo $ii; ?>" style="float: right;" onmouseout="hidePopShAtt('SV');" onmouseover="showPopShAtt('SV', event);" onclick="return false;" type="button" class="button" name="rePostToDI_repostButton" id="rePostToDI_button" value="<?php _e('Repost to Diigo', 'nxs_snap') ?>" />
117
+ <?php wp_nonce_field( 'rePostToDI', 'rePostToDI_wpnonce' ); } ?>
118
+ <?php if (is_array($pMeta) && is_array($pMeta[$ii]) && isset($pMeta[$ii]['pgID']) ) {
119
+ ?> <span id="pstdDI<?php echo $ii; ?>" style="float: right; padding-top: 4px; padding-right: 10px;">
120
+ <a style="font-size: 10px;" href="http://www.diigo.com/user/<?php echo $ntOpt['diUName']; ?>" target="_blank"><?php $nType="Diigo"; printf( __( 'Posted on', 'nxs_snap' ), $nType); ?> <?php echo (isset($pMeta[$ii]['pDate']) && $pMeta[$ii]['pDate']!='')?(" (".$pMeta[$ii]['pDate'].")"):""; ?></a>
121
+ </span><?php } ?>
122
+ </td></tr>
123
+ <?php if (!$isAvailDI) { ?><tr><th scope="row" style="text-align:right; width:150px; padding-top: 5px; padding-right:10px;"></th> <td><b>Setup your Diigo Account to AutoPost to Diigo</b>
124
+ <?php } elseif ($post->post_status != "pubZlish") { ?>
125
+ <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top: 6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Title Format:', 'nxs_snap') ?></th>
126
+ <td><input value="<?php echo $diMsgTFormat ?>" type="text" name="di[<?php echo $ii; ?>][SNAPformatT]" style="width:60%;max-width: 610px;" onfocus="jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apDIMsgTFrmt<?php echo $ii; ?>');"/><?php nxs_doShowHint("apDIMsgTFrmt".$ii, '', '58'); ?></td></tr>
127
+ <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top: 6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Text Format:', 'nxs_snap') ?></th>
128
+ <td>
129
+ <textarea cols="150" rows="1" id="di<?php echo $ii; ?>SNAPformat" name="di[<?php echo $ii; ?>][SNAPformat]" style="width:60%;max-width: 610px;" onfocus="jQuery('#di<?php echo $ii; ?>SNAPformat').attr('rows', 4); jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apDIMsgFrmt<?php echo $ii; ?>');"><?php echo $diMsgFormat; ?></textarea>
130
+ <?php nxs_doShowHint("apDIMsgFrmt".$ii, '', '58'); ?></td></tr>
131
+ <?php }
132
+ }
133
+ }
134
+ //#### Save Meta Tags to the Post
135
+ function adjMetaOpt($optMt, $pMeta){ if (isset($pMeta['isPosted'])) $optMt['isPosted'] = $pMeta['isPosted']; else $optMt['isPosted'] = '';
136
+ if (isset($pMeta['SNAPformat'])) $optMt['diMsgFormat'] = $pMeta['SNAPformat'];
137
+ if (isset($pMeta['SNAPformatT'])) $optMt['diMsgTFormat'] = $pMeta['SNAPformatT'];
138
+ if (isset($pMeta['doDI'])) $optMt['doDI'] = $pMeta['doDI'] == 1?1:0; else { if (isset($pMeta['SNAPformat'])) $optMt['doDI'] = 0; }
139
+ if (isset($pMeta['SNAPincludeDI']) && $pMeta['SNAPincludeDI'] == '1' ) $optMt['doDI'] = 1;
140
+ return $optMt;
141
+ }
142
+ }}
143
+ if (!function_exists("nxs_rePostToDI_ajax")) {
144
+ function nxs_rePostToDI_ajax() { check_ajax_referer('rePostToDI'); $postID = $_POST['id']; $options = get_option('NS_SNAutoPoster');
145
+ foreach ($options['di'] as $ii=>$two) if ($ii==$_POST['nid']) { $two['ii'] = $ii; $two['pType'] = 'aj'; //if ($two['gpPageID'].$two['gpUName']==$_POST['nid']) {
146
+ $gppo = get_post_meta($postID, 'snapDI', true); $gppo = maybe_unserialize($gppo);// prr($gppo);
147
+ if (is_array($gppo) && isset($gppo[$ii]) && is_array($gppo[$ii])){ $ntClInst = new nxs_snapClassDI(); $two = $ntClInst->adjMetaOpt($two, $gppo[$ii]); }
148
+ $result = nxs_doPublishToDI($postID, $two); if ($result == 200) die("Successfully sent your post to Diigo."); else die($result);
149
+ }
150
+ }
151
+ }
152
+
153
+ if (!function_exists("nxs_getDIHeaders")) { function nxs_getDIHeaders($ref, $uname, $pass, $post=false){ $hdrsArr = array();
154
+ $hdrsArr['X-Requested-With']='XMLHttpRequest'; $hdrsArr['Connection']='keep-alive'; $hdrsArr['Referer']=$ref;
155
+ $hdrsArr['User-Agent']='Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.22 Safari/537.11';
156
+ if($post) $hdrsArr['Content-Type']='application/x-www-form-urlencoded';
157
+ $hdrsArr['Accept']='application/json, text/javascript, */*; q=0.01';
158
+ $hdrsArr['Authorization']= 'Basic '.base64_encode($uname.':'.$pass);
159
+ $hdrsArr['Accept-Encoding']='gzip,deflate,sdch'; $hdrsArr['Accept-Language']='en-US,en;q=0.8'; $hdrsArr['Accept-Charset']='ISO-8859-1,utf-8;q=0.7,*;q=0.3'; return $hdrsArr;
160
+ }}
161
+ if (!function_exists("nxs_doCheckDI")) {function nxs_doCheckDI($url){ global $nxs_diCkArray; $hdrsArr = nxs_getDIHeaders($url); $ckArr = $nxs_diCkArray;
162
+ $response = wp_remote_get($url, array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'cookies' => $ckArr));
163
+ if (stripos($response['body'],'logouthash=')===false) return 'Bad Saved Login';
164
+ if ( stripos($response['body'], 'usercp.php')!==false && stripos($response['body'], 'logouthash')!==false){ /*echo "You are IN"; */ return false;
165
+ } else return 'No Saved Login';
166
+ return false;
167
+ }}
168
+ if (!function_exists("nxs_doConnectToDI")) { function nxs_doConnectToDI($u, $p, $url){ global $nxs_diCkArray; $hdrsArr = nxs_getDIHeaders($url, true); echo "LOGGIN";
169
+ $response = wp_remote_get($url); $contents = $response['body']; //$response['body'] = htmlentities($response['body']); prr($response); die();
170
+ $ckArr = $response['cookies']; $mdhashLoc = stripos($contents, 'md5hash(di_login_password');
171
+ if ($mdhashLoc===false) return "No DI found";
172
+ $frmTxt = CutFromTo($contents, 'md5hash(di_login_password','</form>'); $md = array(); $flds = array();
173
+ while (stripos($frmTxt, '<input')!==false){ $inpField = trim(CutFromTo($frmTxt,'<input', '>')); $name = trim(CutFromTo($inpField,'name="', '"'));
174
+ if ( stripos($inpField, '"hidden"')!==false && $name!='' && !in_array($name, $md)) { $md[] = $name; $val = trim(CutFromTo($inpField,'value="', '"')); $flds[$name]= $val; $mids .= "&".$name."=".$val;}
175
+ $frmTxt = substr($frmTxt, stripos($frmTxt, '<input')+8);
176
+ } $flds['di_login_username'] = $u; $flds['di_login_md5password'] = md5($p); $flds['di_login_md5password_utf'] = md5($p); $flds['cookieuser'] = '1'; $flds['do'] = 'login';
177
+
178
+ // $logURL = substr($contents, $mdhashLoc-250, 250); $logURL = CutFromTo($logURL, 'action="', '"');
179
+ if (stripos($contents, 'base href="')!==false) $baseURL = trim(CutFromTo($contents,'base href="', '"')); else { $uarr = explode('/',$url); $dd = $uarr[count($uarr)-1]; $baseURL = str_replace($dd, '', $url);}
180
+
181
+ //echo $baseURL.'login.php?do=login'; prr($flds);
182
+ $r2 = wp_remote_post( $baseURL.'login.php?do=login', array( 'method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'body' => $flds, 'cookies' => $ckArr));
183
+
184
+ //$r2['body'] = htmlentities($r2['body']); prr($r2);
185
+
186
+ if (stripos($r2['body'],'exec_refresh()')!==false) { $ckArr = nxsMergeArraysOV($ckArr, $r2['cookies']); $nxs_diCkArray = $ckArr; return false; } else return "Bad Username/Password";
187
+ }}
188
+
189
+ if (!function_exists("nxs_doPostToDI")) { function nxs_doPostToDI($url, $subj, $msg, $lnk, $tags){ global $nxs_diCkArray; $hdrsArr = nxs_getDIHeaders($url); $ckArr = $nxs_diCkArray;
190
+ $response = wp_remote_get($url, array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'cookies' => $ckArr));
191
+ $contents = $response['body']; //$response['body'] = htmlentities($response['body']); prr($response); die();
192
+ if (stripos($contents, 'base href="')!==false) $baseURL = trim(CutFromTo($contents,'base href="', '"')); else { $uarr = explode('/',$url); $dd = $uarr[count($uarr)-1]; $baseURL = str_replace($dd, '', $url);}
193
+ if (stripos($contents, 'newthread.php?do=newthread')!==false) $mdd='t'; elseif (stripos($contents, 'newreply.php?')!==false) $mdd='p'; else return "No Thread/Post Controls found";
194
+
195
+ if ($mdd=='t'){ $fid = CutFromTo($contents, 'newthread.php?do=newthread','"'); // echo $baseURL.'newthread.php?do=newthread'.str_replace('&amp;','&',$fid);
196
+ $response = wp_remote_get( $baseURL.'newthread.php?do=newthread'.str_replace('&amp;','&',$fid), array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'cookies' => $ckArr)); $contents = $response['body'];
197
+ $frmTxt = CutFromTo($contents, 'newthread.php?do=postthread','</form>'); $md = array(); $flds = array(); //prr($frmTxt);
198
+ while (stripos($frmTxt, '<input')!==false){ $inpField = trim(CutFromTo($frmTxt,'<input', '>')); $name = trim(CutFromTo($inpField,'name="', '"'));
199
+ if ( stripos($inpField, '"hidden"')!==false && $name!='' && !in_array($name, $md)) { $md[] = $name; $val = trim(CutFromTo($inpField,'value="', '"')); $flds[$name]= $val; $mids .= "&".$name."=".$val;}
200
+ $frmTxt = substr($frmTxt, stripos($frmTxt, '<input')+8);
201
+ } $flds['subject'] = $subj; $flds['message'] = $msg; $flds['message_backup'] = $msg; $flds['wysiwyg'] = '1'; $flds['do'] = 'postthread'; $flds['taglist'] = $tags; $flds['parseurl'] = '1'; $flds['sbutton'] = 'Submit+New+Thread';
202
+ $smURL = $baseURL.'newthread.php?do=postthread'.str_replace('&amp;','&',$fid);
203
+ }
204
+
205
+ if ($mdd=='p'){ $fid = CutFromTo($contents, 'newreply.php?do=newreply','"');
206
+ $response = wp_remote_get( $baseURL.'newreply.php?do=newreply'.str_replace('&amp;','&',$fid), array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'cookies' => $ckArr)); $contents = $response['body'];
207
+
208
+ $frmTxt = CutFromTo($contents, 'newreply.php?do=postreply','</form>'); $md = array(); $flds = array(); //prr($frmTxt);
209
+
210
+ while (stripos($frmTxt, '<input')!==false){ $inpField = trim(CutFromTo($frmTxt,'<input', '>')); $name = trim(CutFromTo($inpField,'name="', '"'));
211
+ if ( stripos($inpField, '"hidden"')!==false && $name!='' && !in_array($name, $md)) { $md[] = $name; $val = trim(CutFromTo($inpField,'value="', '"')); $flds[$name]= $val; $mids .= "&".$name."=".$val;}
212
+ $frmTxt = substr($frmTxt, stripos($frmTxt, '<input')+8);
213
+ } $flds['title'] = $subj; $flds['message'] = $msg; $flds['message_backup'] = $msg; $flds['wysiwyg'] = '1'; $flds['do'] = 'postreply'; $flds['parseurl'] = '1'; $flds['sbutton'] = 'Submit+Reply';
214
+ $smURL = $baseURL.'newreply.php?do=postreply'.str_replace('&amp;','&',$fid);
215
+ }
216
+
217
+ //echo $smURL."|"; prr($flds);
218
+ $r2 = wp_remote_post( $smURL, array( 'method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'body' => $flds, 'cookies' => $ckArr));
219
+ if (stripos($r2['body'], 'errorblock')!==false) return trim(strip_tags( CutFromTo($r2['body'], 'errorblock','</div>')));
220
+ if (stripos($r2['body'], 'exec_refresh()')!==false && stripos($r2['body'], 'blockrow restore">')!==false) return trim(strip_tags( CutFromTo($r2['body'], 'blockrow restore">','</p>')));
221
+ if (stripos($r2['body'], '<error>')!==false) return trim(strip_tags( CutFromTo($r2['body'], '<error>','</error>')));
222
+ if ( $r2['response']['code']=='302' || $r2['response']['code']=='303') return 'OK';
223
+ if (stripos($r2['body'], '<newpostid>')!==false || stripos($r2['body'], 'postbit postid="')!==false ) return 'OK';
224
+
225
+ // $r2['body'] = htmlentities($r2['body']); prr($r2); die();
226
+
227
+ return "Something wrong";
228
+ }}
229
+
230
+ if (!function_exists("nxs_doPublishToDI")) { //## Second Function to Post to DI
231
+ function nxs_doPublishToDI($postID, $options){ global $nxs_diCkArray; $ntCd = 'DI'; $ntCdL = 'di'; $ntNm = 'Diigo';
232
+ // if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToDI', array($postID, $options));
233
+ $ii = $options['ii']; if (!isset($options['pType'])) $options['pType'] = 'im'; if ($options['pType']=='sh') sleep(rand(1, 10));
234
+ $logNT = '<span style="color:#000080">Diigo</span> - '.$options['nName'];
235
+ $snap_ap = get_post_meta($postID, 'snap'.$ntCd, true); $snap_ap = maybe_unserialize($snap_ap);
236
+ if ($options['pType']!='aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
237
+ $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted!='2') { sleep(5);
238
+ nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:'.$postID, 'Already posted. No reason for posting duplicate'); return;
239
+ }
240
+ }
241
+ if ($postID=='0') { echo "Testing ... <br/><br/>"; $link = home_url(); $msg = 'Test Message from '.$link; $msgT = 'Test Link from '.$link; } else {
242
+ $post = get_post($postID); if(!$post) return; $link = get_permalink($postID);
243
+ $msgFormat = $options['diMsgFormat']; $diCat = $options['diCat']; $msg = nsFormatMessage($msgFormat, $postID); $msgFormatT = $options['diMsgTFormat']; $msgT = nsFormatMessage($msgFormatT, $postID);
244
+ nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted'=>'1'));
245
+ }
246
+ $extInfo = ' | PostID: '.$postID." - ".$post->post_title;
247
+ //## Actual POST Code
248
+ $email = $options['diUName']; $pass = (substr($options['diPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($options['diPass'], 5)):$options['diPass']);
249
+ $dusername = $options['diUName']; //$link = urlencode($link); $desc = urlencode(substr($msg, 0, 500));
250
+
251
+ $t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) {$tggs[] = $tagA->name;} $tags = (implode(',',$tggs)); $tags = str_replace(' ','+',$tags);
252
+
253
+ $flds = array(); $flds['key']=$options['diAPIKey']; $flds['url']=$link; $flds['title']=nsTrnc($msgT, 250); $flds['desc']=nsTrnc($msg, 250); $flds['tags']=$tags; $flds['shared']='yes';
254
+ $hdrsArr = nxs_getDIHeaders('https://secure.diigo.com/api/v2/bookmarks', $dusername, $pass, true);
255
+ $cnt = wp_remote_post( 'https://secure.diigo.com/api/v2/bookmarks', array( 'method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'body' => $flds));
256
+
257
+ if( is_wp_error( $cnt ) ) {
258
+ $ret = 'Something went wrong - '; nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.$ret. "ERR: ".print_r($cnt, true), $extInfo);
259
+ } else {
260
+ if (is_array($cnt) && stripos($cnt['body'],'"code":1')!==false)
261
+ { $ret = 'OK'; nxs_metaMarkAsPosted($postID, 'DI', $options['ii'], array('isPosted'=>'1', 'pgID'=>'DI', 'pDate'=>date('Y-m-d H:i:s'))); nxs_addToLogN( 'S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); }
262
+ else { if ($cnt['response']['code']=='401') $ret = " Incorrect Username/Password "; else $ret = 'Something went wrong - '; nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.$ret. "ERR: ".print_r($cnt, true), $extInfo);
263
+ }
264
+ }
265
+ if ($ret!='OK') { if ($postID=='0') echo $ret; } else if ($postID=='0') { echo 'OK - Message Posted, please see your Diigo Page'; nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); }
266
+ if ($ret == 'OK') return 200; else return $ret;
267
+
268
+ }
269
+ }
270
  ?>
inc-cl/dl.php CHANGED
@@ -1,204 +1,206 @@
1
- <?php
2
- //## NextScripts Facebook Connection Class
3
- $nxs_snapAvNts[] = array('code'=>'DL', 'lcode'=>'dl', 'name'=>'Delicious');
4
-
5
- if (!class_exists("nxs_snapClassDL")) { class nxs_snapClassDL {
6
- //#### Show Common Settings
7
- function showGenNTSettings($ntOpts){ global $nxs_plurl; $ntInfo = array('code'=>'DL', 'lcode'=>'dl', 'name'=>'Delicious', 'defNName'=>'dlUName', 'tstReq' => false); ?>
8
- <div class="nxs_box">
9
- <div class="nxs_box_header">
10
- <div class="nsx_iconedTitle" style="margin-bottom:1px;background-image:url(<?php echo $nxs_plurl;?>img/<?php echo $ntInfo['lcode']; ?>16.png);"><?php echo $ntInfo['name']; ?>
11
- <?php $cbo = count($ntOpts); ?> <?php wp_nonce_field( 'ns'.$ntInfo['code'], 'ns'.$ntInfo['code'].'_wpnonce' ); ?>
12
- <?php if ($cbo>1){ ?><div class="nsBigText"><?php echo "(".($cbo=='0'?'No':$cbo)." "; _e('accounts', 'nxs_snap'); echo ")"; ?></div><?php } ?>
13
- </div>
14
- </div>
15
- <div class="nxs_box_inside">
16
- <?php foreach ($ntOpts as $indx=>$pbo){ if (trim($pbo['nName']=='')) $pbo['nName'] = $pbo[$ntInfo['defNName']]; ?>
17
- <p style="margin:0px;margin-left:5px;">
18
- <input value="1" name="<?php echo $ntInfo['lcode']; ?>[<?php echo $indx; ?>][apDo<?php echo $ntInfo['code']; ?>]" onchange="doShowHideBlocks('<?php echo $ntInfo['code']; ?>');" type="checkbox" <?php if ((int)$pbo['do'.$ntInfo['code']] == 1) echo "checked"; ?> /> <?php if ((int)$pbo['catSel'] == 1) { ?> <span onmouseout="nxs_hidePopUpInfo('popOnlyCat');" onmouseover="nxs_showPopUpInfo('popOnlyCat', event);"><?php echo "*[".(substr_count($pbo['catSelEd'], ",")+1)."]*" ?></span><?php } ?>
19
- <strong><?php _e('Auto-publish to', 'nxs_snap'); ?> <?php echo $ntInfo['name']; ?> <i style="color: #005800;"><?php if($pbo['nName']!='') echo "(".$pbo['nName'].")"; ?></i></strong>
20
- &nbsp;&nbsp;<?php if ($ntInfo['tstReq'] && (!isset($pbo[$ntInfo['lcode'].'OK']) || $pbo[$ntInfo['lcode'].'OK']=='')){ ?><b style="color: #800000"><?php _e('Attention requred. Unfinished setup', 'nxs_snap'); ?> ==&gt;</b><?php } ?><a id="do<?php echo $ntInfo['code'].$indx; ?>A" href="#" onclick="doShowHideBlocks2('<?php echo $ntInfo['code'].$indx; ?>');return false;">[<?php _e('Show Settings', 'nxs_snap'); ?>]</a>&nbsp;&nbsp;
21
- <a href="#" onclick="doDelAcct('<?php echo $ntInfo['lcode']; ?>', '<?php echo $indx; ?>', '<?php if (isset($pbo['bgBlogID'])) echo $pbo['nName']; ?>');return false;">[<?php _e('Remove Account', 'nxs_snap'); ?>]</a>
22
- </p><?php $this->showNTSettings($indx, $pbo);
23
- }?>
24
- </div>
25
- </div> <?php
26
- }
27
- //#### Show NEW Settings Page
28
- function showNewNTSettings($mgpo){ $gpo = array('nName'=>'', 'doDL'=>'1', 'dlUName'=>'', 'dlPageID'=>'', 'dlAttch'=>'', 'dlPass'=>''); $this->showNTSettings($mgpo, $gpo, true);}
29
- //#### Show Unit Settings
30
- function showNTSettings($ii, $gpo, $isNew=false){ global $nxs_plurl; ?>
31
- <div id="doDL<?php echo $ii; ?>Div" class="insOneDiv<?php if ($isNew) echo " clNewNTSets"; ?>" style="max-width: 1000px; background-color: #EBF4FB; background-image: url(<?php echo $nxs_plurl; ?>img/dl-bg.png); background-position:90% 10%; background-repeat: no-repeat; margin: 10px; border: 1px solid #808080; padding: 10px; display:none;"> <input type="hidden" name="apDoSDL<?php echo $ii; ?>" value="0" id="apDoSDL<?php echo $ii; ?>" />
32
-
33
- <div class="nsx_iconedTitle" style="float: right; background-image: url(<?php echo $nxs_plurl; ?>img/dl16.png);"><a style="font-size: 12px;" target="_blank" href="http://www.nextscripts.com/setup-installation-delicious-social-networks-auto-poster-wordpress/"><?php $nType="Delicious"; printf( __( 'Detailed %s Installation/Configuration Instructions', 'nxs_snap' ), $nType); ?></a></div>
34
-
35
- <div style="width:100%;"><strong><?php _e('Account Nickname', 'nxs_snap'); ?>:</strong> <i><?php _e('Just so you can easely identify it', 'nxs_snap'); ?></i> </div><input name="dl[<?php echo $ii; ?>][nName]" id="dlnName<?php echo $ii; ?>" style="font-weight: bold; color: #005800; border: 1px solid #ACACAC; width: 40%;" value="<?php _e(apply_filters('format_to_edit',htmlentities($gpo['nName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /><br/>
36
- <?php echo nxs_addQTranslSel('dl', $ii, $gpo['qTLng']); ?><?php echo nxs_addPostingDelaySel('dl', $ii, $gpo['nHrs'], $gpo['nMin']); ?>
37
-
38
- <?php if (!$isNew) { ?>
39
- <div style="width:100%;"><strong><?php _e('Categories', 'nxs_snap'); ?>:</strong>
40
- <input value="0" id="catSelA<?php echo $ii; ?>" type="radio" name="dl[<?php echo $ii; ?>][catSel]" <?php if ((int)$gpo['catSel'] != 1) echo "checked"; ?> /> All
41
- <input value="1" id="catSelSDL<?php echo $ii; ?>" type="radio" name="dl[<?php echo $ii; ?>][catSel]" <?php if ((int)$gpo['catSel'] == 1) echo "checked"; ?> /> <a href="#" style="text-decoration: none;" class="showCats" id="nxs_SCA_DL<?php echo $ii; ?>" onclick="jQuery('#catSelSDL<?php echo $ii; ?>').attr('checked', true); jQuery('#tmpCatSelNT').val('DL<?php echo $ii; ?>'); nxs_markCats( jQuery('#nxs_SC_DL<?php echo $ii; ?>').val() ); jQuery('#showCatSel').bPopup({ modalClose: false, appendTo: '#nsStForm', opacity: 0.6, follow: [false, false], position: [75, 'auto']}); return false;">Selected<?php if ($gpo['catSelEd']!='') echo "[".(substr_count($gpo['catSelEd'], ",")+1)."]"; ?></a>
42
- <input type="hidden" name="dl[<?php echo $ii; ?>][catSelEd]" id="nxs_SC_DL<?php echo $ii; ?>" value="<?php echo $gpo['catSelEd']; ?>" />
43
- <br/><i><?php _e('Only selected categories will be autoposted to this account', 'nxs_snap'); ?></i></div>
44
- <br/>
45
- <?php } ?>
46
-
47
- <div style="width:100%;"><strong>Delicious Username:</strong> </div><input name="dl[<?php echo $ii; ?>][apDLUName]" id="apDLUName" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit',htmlentities($gpo['dlUName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
48
- <div style="width:100%;"><strong>Delicious Password:</strong> </div><input name="dl[<?php echo $ii; ?>][apDLPass]" id="apDLPass" type="password" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities(substr($gpo['dlPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($gpo['dlPass'], 5)):$gpo['dlPass'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /> <br/>
49
-
50
- <?php if ($isNew) { ?> <input type="hidden" name="dl[<?php echo $ii; ?>][apDoDL]" value="1" id="apDoNewDL<?php echo $ii; ?>" /> <?php } ?>
51
- <br/>
52
-
53
- <div id="altFormat" style="">
54
- <div style="width:100%;"><strong id="altFormatText"><?php _e('Post Title Format', 'nxs_snap'); ?></strong> (<a href="#" id="apDLTMsgFrmt<?php echo $ii; ?>HintInfo" onclick="mxs_showHideFrmtInfo('apDLTMsgFrmt<?php echo $ii; ?>'); return false;"><?php _e('Show format info', 'nxs_snap'); ?></a>)</div>
55
-
56
- <input name="dl[<?php echo $ii; ?>][apDLMsgTFrmt]" id="apDLMsgTFrmt" style="width: 50%;" value="<?php if ($isNew) echo "%TITLE%"; else _e(apply_filters('format_to_edit',htmlentities($gpo['dlMsgTFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap'); ?>" onfocus="mxs_showFrmtInfo('apDLTMsgFrmt<?php echo $ii; ?>');" /><?php nxs_doShowHint("apDLTMsgFrmt".$ii); ?>
57
- </div>
58
-
59
- <div id="altFormat" style="">
60
- <div style="width:100%;"><strong id="altFormatText"><?php _e('Post Text Format', 'nxs_snap'); ?></strong> (<a href="#" id="apDLMsgFrmt<?php echo $ii; ?>HintInfo" onclick="mxs_showHideFrmtInfo('apDLMsgFrmt<?php echo $ii; ?>'); return false;"><?php _e('Show format info', 'nxs_snap'); ?></a>)</div>
61
-
62
- <textarea cols="150" rows="3" id="di<?php echo $ii; ?>SNAPformat" name="dl[<?php echo $ii; ?>][apDLMsgFrmt]" style="width:51%;max-width: 650px;" onfocus="jQuery('#dl<?php echo $ii; ?>SNAPformat').attr('rows', 6); mxs_showFrmtInfo('apDLMsgFrmt<?php echo $ii; ?>');"><?php if ($isNew) echo "%EXCERPT%"; else _e(apply_filters('format_to_edit', htmlentities($gpo['dlMsgFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap'); ?></textarea>
63
-
64
- <?php nxs_doShowHint("apDLMsgFrmt".$ii); ?>
65
- </div><br/>
66
-
67
- <?php if ($gpo['dlPass']!='') { ?>
68
- <?php wp_nonce_field( 'rePostToDL', 'rePostToDL_wpnonce' ); ?>
69
- <b><?php _e('Test your settings', 'nxs_snap'); ?>:</b>&nbsp;&nbsp;&nbsp; <a href="#" class="NXSButton" onclick="testPost('DL', '<?php echo $ii; ?>'); return false;"><?php printf( __( 'Submit Test Post to %s', 'nxs_snap' ), $nType); ?></a>
70
-
71
- <?php }
72
-
73
- ?><div class="submit"><input type="submit" class="button-primary" name="update_NS_SNAutoPoster_settings" value="<?php _e('Update Settings', 'nxs_snap') ?>" /></div></div><?php
74
- }
75
- //#### Set Unit Settings from POST
76
- function setNTSettings($post, $options){ global $nxs_snapThisPageUrl; $code = 'DL'; $lcode = 'dl';
77
- foreach ($post as $ii => $pval){
78
- if (isset($pval['apDLUName']) && $pval['apDLUName']!=''){ if (!isset($options[$ii])) $options[$ii] = array();
79
- if (isset($pval['apDLUName'])) $options[$ii]['dlUName'] = trim($pval['apDLUName']);
80
- if (isset($pval['nName'])) $options[$ii]['nName'] = trim($pval['nName']);
81
- if (isset($pval['apDLPass'])) $options[$ii]['dlPass'] = 'n5g9a'.nsx_doEncode($pval['apDLPass']); else $options[$ii]['dlPass'] = '';
82
-
83
- if (isset($pval['catSel'])) $options[$ii]['catSel'] = trim($pval['catSel']);
84
- if ($options[$ii]['catSel']=='1' && trim($pval['catSelEd'])!='') $options[$ii]['catSelEd'] = trim($pval['catSelEd']); else $options[$ii]['catSelEd'] = '';
85
-
86
- if (isset($pval['apDLMsgFrmt'])) $options[$ii]['dlMsgFormat'] = trim($pval['apDLMsgFrmt']);
87
- if (isset($pval['apDLMsgTFrmt'])) $options[$ii]['dlMsgTFormat'] = trim($pval['apDLMsgTFrmt']);
88
- if (isset($pval['apDoDL'])) $options[$ii]['doDL'] = $pval['apDoDL']; else $options[$ii]['doDL'] = 0;
89
- if (isset($pval['delayHrs'])) $options[$ii]['nHrs'] = trim($pval['delayHrs']); if (isset($pval['delayMin'])) $options[$ii]['nMin'] = trim($pval['delayMin']);
90
- if (isset($pval['qTLng'])) $options[$ii]['qTLng'] = trim($pval['qTLng']);
91
- }
92
- } return $options;
93
- }
94
- //#### Show Post->Edit Meta Box Settings
95
- function showEdPostNTSettings($ntOpts, $post){ global $nxs_plurl; $post_id = $post->ID;
96
- foreach($ntOpts as $ii=>$ntOpt) { $pMeta = maybe_unserialize(get_post_meta($post_id, 'snapDL', true)); if (is_array($pMeta)) $ntOpt = $this->adjMetaOpt($ntOpt, $pMeta[$ii]);
97
- $doDL = $ntOpt['doDL'] && (is_array($pMeta) || $ntOpt['catSel']!='1');
98
- $isAvailDL = $ntOpt['dlUName']!='' && $ntOpt['dlPass']!=''; $dlMsgFormat = htmlentities($ntOpt['dlMsgFormat'], ENT_COMPAT, "UTF-8"); $dlMsgTFormat = htmlentities($ntOpt['dlMsgTFormat'], ENT_COMPAT, "UTF-8");
99
- ?>
100
- <tr><th style="text-align:left;" colspan="2"><?php if ( $ntOpt['catSel']=='1' && trim($ntOpt['catSelEd'])!='' ) { ?> <input type="hidden" class="nxs_SC" id="nxs_SC_DL<?php echo $ii; ?>" value="<?php echo $ntOpt['catSelEd']; ?>" /> <?php } ?>
101
- <?php if ($isAvailDL) { ?><input class="nxsGrpDoChb" value="1" id="doDL<?php echo $ii; ?>" <?php if ($post->post_status == "publish") echo 'disabled="disabled"';?> type="checkbox" name="dl[<?php echo $ii; ?>][doDL]" <?php if ((int)$doDL == 1) echo 'checked="checked" title="def"'; ?> />
102
- <?php if ($post->post_status == "publish") { ?> <input type="hidden" name="dl[<?php echo $ii; ?>][doDL]" value="<?php echo $doDL;?>"> <?php } ?> <?php } ?>
103
-
104
- <div class="nsx_iconedTitle" style="display: inline; font-size: 13px; background-image: url(<?php echo $nxs_plurl; ?>img/dl16.png);">Delicious - <?php _e('publish to', 'nxs_snap') ?> (<i style="color: #005800;"><?php echo $ntOpt['nName']; ?></i>)</div></th> <td><?php //## Only show RePost button if the post is "published"
105
- if ($post->post_status == "publish" && $isAvailDL) { ?><input alt="<?php echo $ii; ?>" style="float: right;" onmouseout="hidePopShAtt('SV');" onmouseover="showPopShAtt('SV', event);" onclick="return false;" type="button" class="button" name="rePostToDL_repostButton" id="rePostToDL_button" value="<?php _e('Repost to Delicious', 'nxs_snap') ?>" />
106
- <?php wp_nonce_field( 'rePostToDL', 'rePostToDL_wpnonce' ); } ?>
107
-
108
- <?php if (is_array($pMeta) && is_array($pMeta[$ii]) && isset($pMeta[$ii]['pgID']) ) {
109
- ?> <span id="pstdDL<?php echo $ii; ?>" style="float: right; padding-top: 4px; padding-right: 10px;">
110
- <a style="font-size: 10px;" href="http://delicious.com/<?php echo $ntOpt['dlUName']; ?>" target="_blank"><?php $nType="Delicious"; printf( __( 'Posted on', 'nxs_snap' ), $nType); ?> <?php echo (isset($pMeta[$ii]['pDate']) && $pMeta[$ii]['pDate']!='')?(" (".$pMeta[$ii]['pDate'].")"):""; ?></a>
111
- </span><?php } ?>
112
-
113
- </td></tr>
114
-
115
- <?php if (!$isAvailDL) { ?><tr><th scope="row" style="text-align:right; width:150px; padding-top: 5px; padding-right:10px;"></th> <td><b>Setup your Delicious Account to AutoPost to Delicious</b>
116
- <?php } elseif ($post->post_status != "pubZlish") { ?>
117
-
118
- <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top: 6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Title Format:', 'nxs_snap') ?></th>
119
- <td><input value="<?php echo $dlMsgTFormat ?>" type="text" name="dl[<?php echo $ii; ?>][SNAPformatT]" style="width:60%;max-width: 610px;" onfocus="jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apDLTMsgFrmt<?php echo $ii; ?>');"/><?php nxs_doShowHint("apDLTMsgFrmt".$ii, '', '58'); ?></td></tr>
120
-
121
- <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top: 6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Text Format:', 'nxs_snap') ?></th>
122
- <td>
123
- <textarea cols="150" rows="1" id="dl<?php echo $ii; ?>SNAPformat" name="dl[<?php echo $ii; ?>][SNAPformat]" style="width:60%;max-width: 610px;" onfocus="jQuery('#dl<?php echo $ii; ?>SNAPformat').attr('rows', 4); jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apDLMsgFrmt<?php echo $ii; ?>');"><?php echo $dlMsgFormat; ?></textarea>
124
- <?php nxs_doShowHint("apDLMsgFrmt".$ii, '', '58'); ?></td></tr>
125
- <?php }
126
- }
127
- }
128
- //#### Save Meta Tags to the Post
129
- function adjMetaOpt($optMt, $pMeta){ if (isset($pMeta['isPosted'])) $optMt['isPosted'] = $pMeta['isPosted']; else $optMt['isPosted'] = '';
130
- if (isset($pMeta['SNAPformat'])) $optMt['dlMsgFormat'] = $pMeta['SNAPformat'];
131
- if (isset($pMeta['SNAPformatT'])) $optMt['dlMsgTFormat'] = $pMeta['SNAPformatT'];
132
- if (isset($pMeta['doDL'])) $optMt['doDL'] = $pMeta['doDL'] == 1?1:0; else { if (isset($pMeta['SNAPformat'])) $optMt['doDL'] = 0; }
133
- if (isset($pMeta['SNAPincludeDL']) && $pMeta['SNAPincludeDL'] == '1' ) $optMt['doDL'] = 1;
134
- return $optMt;
135
- }
136
- }}
137
- if (!function_exists("nxs_rePostToDL_ajax")) {
138
- function nxs_rePostToDL_ajax() { check_ajax_referer('rePostToDL'); $postID = $_POST['id']; $options = get_option('NS_SNAutoPoster');
139
- foreach ($options['dl'] as $ii=>$two) if ($ii==$_POST['nid']) { $two['ii'] = $ii; $two['pType'] = 'aj'; //if ($two['gpPageID'].$two['gpUName']==$_POST['nid']) {
140
- $gppo = get_post_meta($postID, 'snapDL', true); $gppo = maybe_unserialize($gppo);// prr($gppo);
141
- if (is_array($gppo) && isset($gppo[$ii]) && is_array($gppo[$ii])){ $ntClInst = new nxs_snapClassDL(); $two = $ntClInst->adjMetaOpt($two, $gppo[$ii]);}
142
- $result = nxs_doPublishToDL($postID, $two); if ($result == 200) die("Successfully sent your post to Delicious."); else die($result);
143
- }
144
- }
145
- }
146
- if (!function_exists("doConnectToDelicious")) { function doConnectToDelicious($u, $p){ global $nxs_gCookiesArr; $nxs_gCookiesArr = array(); $advSettings = array();
147
- $fldsTxt = 'username='.$u.'&password='.$p;
148
- $contents = getCurlPageX(' http://www.delicious.com/login ','', false, $fldsTxt, false, $advSettings); // prr($nxs_gCookiesArr); prr($contents);
149
- }}
150
- if (!function_exists("doPostToDelicious")) { function doPostToDelicious($postID, $options){ global $nxs_gCookiesArr;
151
-
152
- }}
153
-
154
- if (!function_exists("nxs_getDLHeaders")) { function nxs_getDLHeaders($up){ $hdrsArr = array();
155
- $hdrsArr['Cache-Control']='no-cache'; $hdrsArr['Connection']='keep-alive';
156
- $hdrsArr['User-Agent']='SNAP for Wordpress; Ver '.NextScripts_SNAP_Version;
157
- $hdrsArr['Accept']='text/html, application/xhtml+xml, */*'; $hdrsArr['DNT']='1';
158
- $hdrsArr['Authorization'] = 'Basic ' . base64_encode("$up");
159
- $hdrsArr['Accept-Encoding']='gzip,deflate'; $hdrsArr['Accept-Language']='en-US,en;q=0.8'; $hdrsArr['Accept-Charset']='ISO-8859-1,utf-8;q=0.7,*;q=0.3'; return $hdrsArr;
160
- }}
161
-
162
- if (!function_exists("nxs_doPublishToDL")) { //## Second Function to Post to DL
163
- function nxs_doPublishToDL($postID, $options){ $ntCd = 'DL'; $ntCdL = 'dl'; $ntNm = 'Delicious';
164
- // if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToDL', array($postID, $options));
165
- $ii = $options['ii']; if (!isset($options['pType'])) $options['pType'] = 'im'; if ($options['pType']=='sh') sleep(rand(1, 10));
166
- $logNT = '<span style="color:#000080">Delicious</span> - '.$options['nName'];
167
- $snap_ap = get_post_meta($postID, 'snap'.$ntCd, true); $snap_ap = maybe_unserialize($snap_ap);
168
- if ($options['pType']!='aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
169
- $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted!='2') { sleep(5);
170
- nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:'.$postID, 'Already posted. No reason for posting duplicate'); return;
171
- }
172
- }
173
-
174
- if ($postID=='0') { echo "Testing ... <br/><br/>"; $link = home_url(); $msgT = 'Test Link from '.$link; } else { $post = get_post($postID); if(!$post) return; $link = get_permalink($postID);
175
- $msgFormat = $options['dlMsgFormat']; $msgTFormat = $options['dlMsgTFormat']; $msgT = nsFormatMessage($msgTFormat, $postID); $msg = nsFormatMessage($msgFormat, $postID);
176
- nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted'=>'1'));
177
- }
178
- $extInfo = ' | PostID: '.$postID." - ".$post->post_title;
179
- $dusername = $options['dlUName']; $pass = (substr($options['dlPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($options['dlPass'], 5)):$options['dlPass']);
180
- $api = "api.del.icio.us/v1"; $link = urlencode($link); $desc = urlencode(substr($msgT, 0, 250)); $ext = urlencode(substr($msg, 0, 1000));
181
- $t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) {$tggs[] = $tagA->name;} $tags = urlencode(implode(',',$tggs)); $tags = str_replace(' ','+',$tags);
182
- $apicall = "https://$api/posts/add?red=api&url=$link&description=$desc&extended=$ext&tags=$tags";
183
- $hdrsArr = nxs_getDLHeaders($dusername.':'.$pass); $cnt = wp_remote_get( $apicall, array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr) ); // prr($cnt);
184
-
185
- if(is_wp_error($cnt)) { $error_string = $cnt->get_error_message(); if (stripos($error_string, ' timed out')!==false) { sleep(10);
186
- $cnt = wp_remote_get( $apicall, array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr) );}
187
- }
188
- if(is_wp_error($cnt)) {
189
- $ret = 'Something went wrong - '."http://$dusername:*********@$api/posts/add?&url=$link&description=$desc&extended=$ext&tags=$tags"; nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.$ret. "ERR: ".print_r($cnt, true), $extInfo);
190
- } else {
191
- if (is_array($cnt) && stripos($cnt['body'],'code="done"')!==false)
192
- { $ret = 'OK'; nxs_metaMarkAsPosted($postID, 'DL', $options['ii'], array('isPosted'=>'1', 'pgID'=>'DL', 'pDate'=>date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); }
193
- elseif (is_array($cnt) && $cnt['body']=='<?xml version="1.0" encoding="UTF-8"?>') { $ret = 'It looks like Delicious API is Down'; nxs_addToLogN('E', 'Error', $logNT, 'It looks like Delicious API is Down', $extInfo); }
194
- elseif (is_array($cnt) && stripos($cnt['body'],'item already exists')!==false) { $ret = '..All good, but this link has already been bookmarked..'; nxs_addToLogN('S', 'Skipped', $logNT, 'All good, but this link has already been bookmarked', $extInfo); }
195
- else { if ($cnt['response']['code']=='401') $ret = " Incorrect Username/Password "; else $ret = 'Something went wrong - '."https://$dusername:*********@$api/posts/add?&url=$link&description=$desc&extended=$ext&tags=$tags";
196
- nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.$ret. "ERR: ".print_r($cnt, true), $extInfo);
197
- }
198
- }
199
- if ($ret!='OK') { if ($postID=='0') echo $ret; } else if ($postID=='0') { echo 'OK - Message Posted, please see your Delicious Page'; nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); }
200
- if ($ret == 'OK') return 200; else return $ret;
201
-
202
- }
203
- }
 
 
204
  ?>
1
+ <?php
2
+ //## NextScripts Facebook Connection Class
3
+ $nxs_snapAvNts[] = array('code'=>'DL', 'lcode'=>'dl', 'name'=>'Delicious');
4
+
5
+ if (!class_exists("nxs_snapClassDL")) { class nxs_snapClassDL {
6
+ //#### Show Common Settings
7
+ function showGenNTSettings($ntOpts){ global $nxs_plurl; $ntInfo = array('code'=>'DL', 'lcode'=>'dl', 'name'=>'Delicious', 'defNName'=>'dlUName', 'tstReq' => false); ?>
8
+ <div class="nxs_box">
9
+ <div class="nxs_box_header">
10
+ <div class="nsx_iconedTitle" style="margin-bottom:1px;background-image:url(<?php echo $nxs_plurl;?>img/<?php echo $ntInfo['lcode']; ?>16.png);"><?php echo $ntInfo['name']; ?>
11
+ <?php $cbo = count($ntOpts); ?> <?php wp_nonce_field( 'ns'.$ntInfo['code'], 'ns'.$ntInfo['code'].'_wpnonce' ); ?>
12
+ <?php if ($cbo>1){ ?><div class="nsBigText"><?php echo "(".($cbo=='0'?'No':$cbo)." "; _e('accounts', 'nxs_snap'); echo ")"; ?></div><?php } ?>
13
+ </div>
14
+ </div>
15
+ <div class="nxs_box_inside">
16
+ <?php foreach ($ntOpts as $indx=>$pbo){ if (trim($pbo['nName']=='')) $pbo['nName'] = $pbo[$ntInfo['defNName']]; ?>
17
+ <p style="margin:0px;margin-left:5px;">
18
+ <input value="1" name="<?php echo $ntInfo['lcode']; ?>[<?php echo $indx; ?>][apDo<?php echo $ntInfo['code']; ?>]" onchange="doShowHideBlocks('<?php echo $ntInfo['code']; ?>');" type="checkbox" <?php if ((int)$pbo['do'.$ntInfo['code']] == 1) echo "checked"; ?> /> <?php if ((int)$pbo['catSel'] == 1) { ?> <span onmouseout="nxs_hidePopUpInfo('popOnlyCat');" onmouseover="nxs_showPopUpInfo('popOnlyCat', event);"><?php echo "*[".(substr_count($pbo['catSelEd'], ",")+1)."]*" ?></span><?php } ?>
19
+ <strong><?php _e('Auto-publish to', 'nxs_snap'); ?> <?php echo $ntInfo['name']; ?> <i style="color: #005800;"><?php if($pbo['nName']!='') echo "(".$pbo['nName'].")"; ?></i></strong>
20
+ &nbsp;&nbsp;<?php if ($ntInfo['tstReq'] && (!isset($pbo[$ntInfo['lcode'].'OK']) || $pbo[$ntInfo['lcode'].'OK']=='')){ ?><b style="color: #800000"><?php _e('Attention requred. Unfinished setup', 'nxs_snap'); ?> ==&gt;</b><?php } ?><a id="do<?php echo $ntInfo['code'].$indx; ?>A" href="#" onclick="doShowHideBlocks2('<?php echo $ntInfo['code'].$indx; ?>');return false;">[<?php _e('Show Settings', 'nxs_snap'); ?>]</a>&nbsp;&nbsp;
21
+ <a href="#" onclick="doDelAcct('<?php echo $ntInfo['lcode']; ?>', '<?php echo $indx; ?>', '<?php if (isset($pbo['bgBlogID'])) echo $pbo['nName']; ?>');return false;">[<?php _e('Remove Account', 'nxs_snap'); ?>]</a>
22
+ </p><?php $this->showNTSettings($indx, $pbo);
23
+ }?>
24
+ </div>
25
+ </div> <?php
26
+ }
27
+ //#### Show NEW Settings Page
28
+ function showNewNTSettings($mgpo){ $gpo = array('nName'=>'', 'doDL'=>'1', 'dlUName'=>'', 'dlPageID'=>'', 'dlAttch'=>'', 'dlPass'=>''); $this->showNTSettings($mgpo, $gpo, true);}
29
+ //#### Show Unit Settings
30
+ function showNTSettings($ii, $gpo, $isNew=false){ global $nxs_plurl;
31
+ if (!isset($gpo['nHrs'])) $gpo['nHrs'] = 0; if (!isset($gpo['nMin'])) $gpo['nMin'] = 0; if (!isset($gpo['catSel'])) $gpo['catSel'] = 0; if (!isset($gpo['catSelEd'])) $gpo['catSelEd'] = '';
32
+ if (!isset($gpo['nDays'])) $gpo['nDays'] = 0; if (!isset($gpo['qTLng'])) $gpo['qTLng'] = ''; ?>
33
+ <div id="doDL<?php echo $ii; ?>Div" class="insOneDiv<?php if ($isNew) echo " clNewNTSets"; ?>" style="max-width: 1000px; background-color: #EBF4FB; background-image: url(<?php echo $nxs_plurl; ?>img/dl-bg.png); background-position:90% 10%; background-repeat: no-repeat; margin: 10px; border: 1px solid #808080; padding: 10px; display:none;"> <input type="hidden" name="apDoSDL<?php echo $ii; ?>" value="0" id="apDoSDL<?php echo $ii; ?>" />
34
+
35
+ <div class="nsx_iconedTitle" style="float: right; background-image: url(<?php echo $nxs_plurl; ?>img/dl16.png);"><a style="font-size: 12px;" target="_blank" href="http://www.nextscripts.com/setup-installation-delicious-social-networks-auto-poster-wordpress/"><?php $nType="Delicious"; printf( __( 'Detailed %s Installation/Configuration Instructions', 'nxs_snap' ), $nType); ?></a></div>
36
+
37
+ <div style="width:100%;"><strong><?php _e('Account Nickname', 'nxs_snap'); ?>:</strong> <i><?php _e('Just so you can easely identify it', 'nxs_snap'); ?></i> </div><input name="dl[<?php echo $ii; ?>][nName]" id="dlnName<?php echo $ii; ?>" style="font-weight: bold; color: #005800; border: 1px solid #ACACAC; width: 40%;" value="<?php _e(apply_filters('format_to_edit',htmlentities($gpo['nName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /><br/>
38
+ <?php echo nxs_addQTranslSel('dl', $ii, $gpo['qTLng']); ?><?php echo nxs_addPostingDelaySel('dl', $ii, $gpo['nHrs'], $gpo['nMin']); ?>
39
+
40
+ <?php if (!$isNew) { ?>
41
+ <div style="width:100%;"><strong><?php _e('Categories', 'nxs_snap'); ?>:</strong>
42
+ <input value="0" id="catSelA<?php echo $ii; ?>" type="radio" name="dl[<?php echo $ii; ?>][catSel]" <?php if ((int)$gpo['catSel'] != 1) echo "checked"; ?> /> All
43
+ <input value="1" id="catSelSDL<?php echo $ii; ?>" type="radio" name="dl[<?php echo $ii; ?>][catSel]" <?php if ((int)$gpo['catSel'] == 1) echo "checked"; ?> /> <a href="#" style="text-decoration: none;" class="showCats" id="nxs_SCA_DL<?php echo $ii; ?>" onclick="jQuery('#catSelSDL<?php echo $ii; ?>').attr('checked', true); jQuery('#tmpCatSelNT').val('DL<?php echo $ii; ?>'); nxs_markCats( jQuery('#nxs_SC_DL<?php echo $ii; ?>').val() ); jQuery('#showCatSel').bPopup({ modalClose: false, appendTo: '#nsStForm', opacity: 0.6, follow: [false, false], position: [75, 'auto']}); return false;">Selected<?php if ($gpo['catSelEd']!='') echo "[".(substr_count($gpo['catSelEd'], ",")+1)."]"; ?></a>
44
+ <input type="hidden" name="dl[<?php echo $ii; ?>][catSelEd]" id="nxs_SC_DL<?php echo $ii; ?>" value="<?php echo $gpo['catSelEd']; ?>" />
45
+ <br/><i><?php _e('Only selected categories will be autoposted to this account', 'nxs_snap'); ?></i></div>
46
+ <br/>
47
+ <?php } ?>
48
+
49
+ <div style="width:100%;"><strong>Delicious Username:</strong> </div><input name="dl[<?php echo $ii; ?>][apDLUName]" id="apDLUName" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit',htmlentities($gpo['dlUName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
50
+ <div style="width:100%;"><strong>Delicious Password:</strong> </div><input name="dl[<?php echo $ii; ?>][apDLPass]" id="apDLPass" type="password" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities(substr($gpo['dlPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($gpo['dlPass'], 5)):$gpo['dlPass'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /> <br/>
51
+
52
+ <?php if ($isNew) { ?> <input type="hidden" name="dl[<?php echo $ii; ?>][apDoDL]" value="1" id="apDoNewDL<?php echo $ii; ?>" /> <?php } ?>
53
+ <br/>
54
+
55
+ <div id="altFormat" style="">
56
+ <div style="width:100%;"><strong id="altFormatText"><?php _e('Post Title Format', 'nxs_snap'); ?></strong> (<a href="#" id="apDLTMsgFrmt<?php echo $ii; ?>HintInfo" onclick="mxs_showHideFrmtInfo('apDLTMsgFrmt<?php echo $ii; ?>'); return false;"><?php _e('Show format info', 'nxs_snap'); ?></a>)</div>
57
+
58
+ <input name="dl[<?php echo $ii; ?>][apDLMsgTFrmt]" id="apDLMsgTFrmt" style="width: 50%;" value="<?php if ($isNew) echo "%TITLE%"; else _e(apply_filters('format_to_edit',htmlentities($gpo['dlMsgTFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap'); ?>" onfocus="mxs_showFrmtInfo('apDLTMsgFrmt<?php echo $ii; ?>');" /><?php nxs_doShowHint("apDLTMsgFrmt".$ii); ?>
59
+ </div>
60
+
61
+ <div id="altFormat" style="">
62
+ <div style="width:100%;"><strong id="altFormatText"><?php _e('Post Text Format', 'nxs_snap'); ?></strong> (<a href="#" id="apDLMsgFrmt<?php echo $ii; ?>HintInfo" onclick="mxs_showHideFrmtInfo('apDLMsgFrmt<?php echo $ii; ?>'); return false;"><?php _e('Show format info', 'nxs_snap'); ?></a>)</div>
63
+
64
+ <textarea cols="150" rows="3" id="di<?php echo $ii; ?>SNAPformat" name="dl[<?php echo $ii; ?>][apDLMsgFrmt]" style="width:51%;max-width: 650px;" onfocus="jQuery('#dl<?php echo $ii; ?>SNAPformat').attr('rows', 6); mxs_showFrmtInfo('apDLMsgFrmt<?php echo $ii; ?>');"><?php if ($isNew) echo "%EXCERPT%"; else _e(apply_filters('format_to_edit', htmlentities($gpo['dlMsgFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap'); ?></textarea>
65
+
66
+ <?php nxs_doShowHint("apDLMsgFrmt".$ii); ?>
67
+ </div><br/>
68
+
69
+ <?php if ($gpo['dlPass']!='') { ?>
70
+ <?php wp_nonce_field( 'rePostToDL', 'rePostToDL_wpnonce' ); ?>
71
+ <b><?php _e('Test your settings', 'nxs_snap'); ?>:</b>&nbsp;&nbsp;&nbsp; <a href="#" class="NXSButton" onclick="testPost('DL', '<?php echo $ii; ?>'); return false;"><?php printf( __( 'Submit Test Post to %s', 'nxs_snap' ), $nType); ?></a>
72
+
73
+ <?php }
74
+
75
+ ?><div class="submit"><input type="submit" class="button-primary" name="update_NS_SNAutoPoster_settings" value="<?php _e('Update Settings', 'nxs_snap') ?>" /></div></div><?php
76
+ }
77
+ //#### Set Unit Settings from POST
78
+ function setNTSettings($post, $options){ global $nxs_snapThisPageUrl; $code = 'DL'; $lcode = 'dl';
79
+ foreach ($post as $ii => $pval){
80
+ if (isset($pval['apDLUName']) && $pval['apDLUName']!=''){ if (!isset($options[$ii])) $options[$ii] = array();
81
+ if (isset($pval['apDLUName'])) $options[$ii]['dlUName'] = trim($pval['apDLUName']);
82
+ if (isset($pval['nName'])) $options[$ii]['nName'] = trim($pval['nName']);
83
+ if (isset($pval['apDLPass'])) $options[$ii]['dlPass'] = 'n5g9a'.nsx_doEncode($pval['apDLPass']); else $options[$ii]['dlPass'] = '';
84
+
85
+ if (isset($pval['catSel'])) $options[$ii]['catSel'] = trim($pval['catSel']);
86
+ if ($options[$ii]['catSel']=='1' && trim($pval['catSelEd'])!='') $options[$ii]['catSelEd'] = trim($pval['catSelEd']); else $options[$ii]['catSelEd'] = '';
87
+
88
+ if (isset($pval['apDLMsgFrmt'])) $options[$ii]['dlMsgFormat'] = trim($pval['apDLMsgFrmt']);
89
+ if (isset($pval['apDLMsgTFrmt'])) $options[$ii]['dlMsgTFormat'] = trim($pval['apDLMsgTFrmt']);
90
+ if (isset($pval['apDoDL'])) $options[$ii]['doDL'] = $pval['apDoDL']; else $options[$ii]['doDL'] = 0;
91
+ if (isset($pval['delayHrs'])) $options[$ii]['nHrs'] = trim($pval['delayHrs']); if (isset($pval['delayMin'])) $options[$ii]['nMin'] = trim($pval['delayMin']);
92
+ if (isset($pval['qTLng'])) $options[$ii]['qTLng'] = trim($pval['qTLng']);
93
+ }
94
+ } return $options;
95
+ }
96
+ //#### Show Post->Edit Meta Box Settings
97
+ function showEdPostNTSettings($ntOpts, $post){ global $nxs_plurl; $post_id = $post->ID;
98
+ foreach($ntOpts as $ii=>$ntOpt) { $pMeta = maybe_unserialize(get_post_meta($post_id, 'snapDL', true)); if (is_array($pMeta)) $ntOpt = $this->adjMetaOpt($ntOpt, $pMeta[$ii]);
99
+ $doDL = $ntOpt['doDL'] && (is_array($pMeta) || $ntOpt['catSel']!='1');
100
+ $isAvailDL = $ntOpt['dlUName']!='' && $ntOpt['dlPass']!=''; $dlMsgFormat = htmlentities($ntOpt['dlMsgFormat'], ENT_COMPAT, "UTF-8"); $dlMsgTFormat = htmlentities($ntOpt['dlMsgTFormat'], ENT_COMPAT, "UTF-8");
101
+ ?>
102
+ <tr><th style="text-align:left;" colspan="2"><?php if ( $ntOpt['catSel']=='1' && trim($ntOpt['catSelEd'])!='' ) { ?> <input type="hidden" class="nxs_SC" id="nxs_SC_DL<?php echo $ii; ?>" value="<?php echo $ntOpt['catSelEd']; ?>" /> <?php } ?>
103
+ <?php if ($isAvailDL) { ?><input class="nxsGrpDoChb" value="1" id="doDL<?php echo $ii; ?>" <?php if ($post->post_status == "publish") echo 'disabled="disabled"';?> type="checkbox" name="dl[<?php echo $ii; ?>][doDL]" <?php if ((int)$doDL == 1) echo 'checked="checked" title="def"'; ?> />
104
+ <?php if ($post->post_status == "publish") { ?> <input type="hidden" name="dl[<?php echo $ii; ?>][doDL]" value="<?php echo $doDL;?>"> <?php } ?> <?php } ?>
105
+
106
+ <div class="nsx_iconedTitle" style="display: inline; font-size: 13px; background-image: url(<?php echo $nxs_plurl; ?>img/dl16.png);">Delicious - <?php _e('publish to', 'nxs_snap') ?> (<i style="color: #005800;"><?php echo $ntOpt['nName']; ?></i>)</div></th> <td><?php //## Only show RePost button if the post is "published"
107
+ if ($post->post_status == "publish" && $isAvailDL) { ?><input alt="<?php echo $ii; ?>" style="float: right;" onmouseout="hidePopShAtt('SV');" onmouseover="showPopShAtt('SV', event);" onclick="return false;" type="button" class="button" name="rePostToDL_repostButton" id="rePostToDL_button" value="<?php _e('Repost to Delicious', 'nxs_snap') ?>" />
108
+ <?php wp_nonce_field( 'rePostToDL', 'rePostToDL_wpnonce' ); } ?>
109
+
110
+ <?php if (is_array($pMeta) && is_array($pMeta[$ii]) && isset($pMeta[$ii]['pgID']) ) {
111
+ ?> <span id="pstdDL<?php echo $ii; ?>" style="float: right; padding-top: 4px; padding-right: 10px;">
112
+ <a style="font-size: 10px;" href="http://delicious.com/<?php echo $ntOpt['dlUName']; ?>" target="_blank"><?php $nType="Delicious"; printf( __( 'Posted on', 'nxs_snap' ), $nType); ?> <?php echo (isset($pMeta[$ii]['pDate']) && $pMeta[$ii]['pDate']!='')?(" (".$pMeta[$ii]['pDate'].")"):""; ?></a>
113
+ </span><?php } ?>
114
+
115
+ </td></tr>
116
+
117
+ <?php if (!$isAvailDL) { ?><tr><th scope="row" style="text-align:right; width:150px; padding-top: 5px; padding-right:10px;"></th> <td><b>Setup your Delicious Account to AutoPost to Delicious</b>
118
+ <?php } elseif ($post->post_status != "pubZlish") { ?>
119
+
120
+ <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top: 6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Title Format:', 'nxs_snap') ?></th>
121
+ <td><input value="<?php echo $dlMsgTFormat ?>" type="text" name="dl[<?php echo $ii; ?>][SNAPformatT]" style="width:60%;max-width: 610px;" onfocus="jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apDLTMsgFrmt<?php echo $ii; ?>');"/><?php nxs_doShowHint("apDLTMsgFrmt".$ii, '', '58'); ?></td></tr>
122
+
123
+ <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top: 6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Text Format:', 'nxs_snap') ?></th>
124
+ <td>
125
+ <textarea cols="150" rows="1" id="dl<?php echo $ii; ?>SNAPformat" name="dl[<?php echo $ii; ?>][SNAPformat]" style="width:60%;max-width: 610px;" onfocus="jQuery('#dl<?php echo $ii; ?>SNAPformat').attr('rows', 4); jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apDLMsgFrmt<?php echo $ii; ?>');"><?php echo $dlMsgFormat; ?></textarea>
126
+ <?php nxs_doShowHint("apDLMsgFrmt".$ii, '', '58'); ?></td></tr>
127
+ <?php }
128
+ }
129
+ }
130
+ //#### Save Meta Tags to the Post
131
+ function adjMetaOpt($optMt, $pMeta){ if (isset($pMeta['isPosted'])) $optMt['isPosted'] = $pMeta['isPosted']; else $optMt['isPosted'] = '';
132
+ if (isset($pMeta['SNAPformat'])) $optMt['dlMsgFormat'] = $pMeta['SNAPformat'];
133
+ if (isset($pMeta['SNAPformatT'])) $optMt['dlMsgTFormat'] = $pMeta['SNAPformatT'];
134
+ if (isset($pMeta['doDL'])) $optMt['doDL'] = $pMeta['doDL'] == 1?1:0; else { if (isset($pMeta['SNAPformat'])) $optMt['doDL'] = 0; }
135
+ if (isset($pMeta['SNAPincludeDL']) && $pMeta['SNAPincludeDL'] == '1' ) $optMt['doDL'] = 1;
136
+ return $optMt;
137
+ }
138
+ }}
139
+ if (!function_exists("nxs_rePostToDL_ajax")) {
140
+ function nxs_rePostToDL_ajax() { check_ajax_referer('rePostToDL'); $postID = $_POST['id']; $options = get_option('NS_SNAutoPoster');
141
+ foreach ($options['dl'] as $ii=>$two) if ($ii==$_POST['nid']) { $two['ii'] = $ii; $two['pType'] = 'aj'; //if ($two['gpPageID'].$two['gpUName']==$_POST['nid']) {
142
+ $gppo = get_post_meta($postID, 'snapDL', true); $gppo = maybe_unserialize($gppo);// prr($gppo);
143
+ if (is_array($gppo) && isset($gppo[$ii]) && is_array($gppo[$ii])){ $ntClInst = new nxs_snapClassDL(); $two = $ntClInst->adjMetaOpt($two, $gppo[$ii]);}
144
+ $result = nxs_doPublishToDL($postID, $two); if ($result == 200) die("Successfully sent your post to Delicious."); else die($result);
145
+ }
146
+ }
147
+ }
148
+ if (!function_exists("doConnectToDelicious")) { function doConnectToDelicious($u, $p){ global $nxs_gCookiesArr; $nxs_gCookiesArr = array(); $advSettings = array();
149
+ $fldsTxt = 'username='.$u.'&password='.$p;
150
+ $contents = getCurlPageX(' http://www.delicious.com/login ','', false, $fldsTxt, false, $advSettings); // prr($nxs_gCookiesArr); prr($contents);
151
+ }}
152
+ if (!function_exists("doPostToDelicious")) { function doPostToDelicious($postID, $options){ global $nxs_gCookiesArr;
153
+
154
+ }}
155
+
156
+ if (!function_exists("nxs_getDLHeaders")) { function nxs_getDLHeaders($up){ $hdrsArr = array();
157
+ $hdrsArr['Cache-Control']='no-cache'; $hdrsArr['Connection']='keep-alive';
158
+ $hdrsArr['User-Agent']='SNAP for Wordpress; Ver '.NextScripts_SNAP_Version;
159
+ $hdrsArr['Accept']='text/html, application/xhtml+xml, */*'; $hdrsArr['DNT']='1';
160
+ $hdrsArr['Authorization'] = 'Basic ' . base64_encode("$up");
161
+ $hdrsArr['Accept-Encoding']='gzip,deflate'; $hdrsArr['Accept-Language']='en-US,en;q=0.8'; $hdrsArr['Accept-Charset']='ISO-8859-1,utf-8;q=0.7,*;q=0.3'; return $hdrsArr;
162
+ }}
163
+
164
+ if (!function_exists("nxs_doPublishToDL")) { //## Second Function to Post to DL
165
+ function nxs_doPublishToDL($postID, $options){ $ntCd = 'DL'; $ntCdL = 'dl'; $ntNm = 'Delicious';
166
+ // if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToDL', array($postID, $options));
167
+ $ii = $options['ii']; if (!isset($options['pType'])) $options['pType'] = 'im'; if ($options['pType']=='sh') sleep(rand(1, 10));
168
+ $logNT = '<span style="color:#000080">Delicious</span> - '.$options['nName'];
169
+ $snap_ap = get_post_meta($postID, 'snap'.$ntCd, true); $snap_ap = maybe_unserialize($snap_ap);
170
+ if ($options['pType']!='aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
171
+ $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted!='2') { sleep(5);
172
+ nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:'.$postID, 'Already posted. No reason for posting duplicate'); return;
173
+ }
174
+ }
175
+
176
+ if ($postID=='0') { echo "Testing ... <br/><br/>"; $link = home_url(); $msgT = 'Test Link from '.$link; } else { $post = get_post($postID); if(!$post) return; $link = get_permalink($postID);
177
+ $msgFormat = $options['dlMsgFormat']; $msgTFormat = $options['dlMsgTFormat']; $msgT = nsFormatMessage($msgTFormat, $postID); $msg = nsFormatMessage($msgFormat, $postID);
178
+ nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted'=>'1'));
179
+ }
180
+ $extInfo = ' | PostID: '.$postID." - ".$post->post_title;
181
+ $dusername = $options['dlUName']; $pass = (substr($options['dlPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($options['dlPass'], 5)):$options['dlPass']);
182
+ $api = "api.del.icio.us/v1"; $link = urlencode($link); $desc = urlencode(substr($msgT, 0, 250)); $ext = urlencode(substr($msg, 0, 1000));
183
+ $t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) {$tggs[] = $tagA->name;} $tags = urlencode(implode(',',$tggs)); $tags = str_replace(' ','+',$tags);
184
+ $apicall = "https://$api/posts/add?red=api&url=$link&description=$desc&extended=$ext&tags=$tags";
185
+ $hdrsArr = nxs_getDLHeaders($dusername.':'.$pass); $cnt = wp_remote_get( $apicall, array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr) ); // prr($cnt);
186
+
187
+ if(is_wp_error($cnt)) { $error_string = $cnt->get_error_message(); if (stripos($error_string, ' timed out')!==false) { sleep(10);
188
+ $cnt = wp_remote_get( $apicall, array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr) );}
189
+ }
190
+ if(is_wp_error($cnt)) {
191
+ $ret = 'Something went wrong - '."http://$dusername:*********@$api/posts/add?&url=$link&description=$desc&extended=$ext&tags=$tags"; nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.$ret. "ERR: ".print_r($cnt, true), $extInfo);
192
+ } else {
193
+ if (is_array($cnt) && stripos($cnt['body'],'code="done"')!==false)
194
+ { $ret = 'OK'; nxs_metaMarkAsPosted($postID, 'DL', $options['ii'], array('isPosted'=>'1', 'pgID'=>'DL', 'pDate'=>date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); }
195
+ elseif (is_array($cnt) && $cnt['body']=='<?xml version="1.0" encoding="UTF-8"?>') { $ret = 'It looks like Delicious API is Down'; nxs_addToLogN('E', 'Error', $logNT, 'It looks like Delicious API is Down', $extInfo); }
196
+ elseif (is_array($cnt) && stripos($cnt['body'],'item already exists')!==false) { $ret = '..All good, but this link has already been bookmarked..'; nxs_addToLogN('S', 'Skipped', $logNT, 'All good, but this link has already been bookmarked', $extInfo); }
197
+ else { if ($cnt['response']['code']=='401') $ret = " Incorrect Username/Password "; else $ret = 'Something went wrong - '."https://$dusername:*********@$api/posts/add?&url=$link&description=$desc&extended=$ext&tags=$tags";
198
+ nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.$ret. "ERR: ".print_r($cnt, true), $extInfo);
199
+ }
200
+ }
201
+ if ($ret!='OK') { if ($postID=='0') echo $ret; } else if ($postID=='0') { echo 'OK - Message Posted, please see your Delicious Page'; nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); }
202
+ if ($ret == 'OK') return 200; else return $ret;
203
+
204
+ }
205
+ }
206
  ?>
inc-cl/fb.api.php CHANGED
@@ -1,61 +1,62 @@
1
- <?php
2
- //## NextScripts Facebook Connection Class
3
- $nxs_snapAPINts[] = array('code'=>'FB', 'lcode'=>'fb', 'name'=>'Facebook');
4
-
5
- if (!class_exists("nxs_class_SNAP_FB")) { class nxs_class_SNAP_FB {
6
-
7
- var $ntCode = 'FB';
8
- var $ntLCode = 'fb';
9
-
10
- function doPost($options, $message){ if (!is_array($options)) return false; $out = array(); //return false;
11
- foreach ($options as $ii=>$ntOpts) $out[$ii] = $this->doPostToNT($ntOpts, $message);
12
- return $out;
13
- }
14
- function doPostToNT($options, $message){ require_once ('apis/facebook.php'); $badOut = array('pgID'=>'', 'isPosted'=>0, 'pDate'=>date('Y-m-d H:i:s'), 'Error'=>''); // prr($message); prr($options);
15
- //## Check settings
16
- if (!is_array($options)) { $badOut['Error'] = 'No Options'; return $badOut; }
17
- if (!isset($options['fbAppAuthToken']) || trim($options['fbAppAuthToken'])=='') { $badOut['Error'] = 'No Auth Token Found'; return $badOut; }
18
- //## Make Post
19
- $facebook = new NXS_Facebook(array( 'appId' => $options['fbAppID'], 'secret' => $options['fbAppSec'], 'cookie' => true ));
20
- if (!isset($options['fbAppPageAuthToken']) || trim($options['fbAppPageAuthToken'])=='') $options['fbAppPageAuthToken'] = $options['fbAppAuthToken'];
21
-
22
- //## Some OLD Format Conversion
23
- if (!isset($options['attachType']) && isset($options['fbAttch'])) $options['attachType'] = $options['fbAttch'];
24
- if (!isset($options['postType']) && isset($options['fbPostType'])) $options['postType'] = $options['fbPostType'];
25
- if (!isset($options['pgID']) && isset($options['fbPgID'])) $options['pgID'] = $options['fbPgID'];
26
-
27
- $msg = $message['message']; $imgURL = $message['imageURL']; $fbPostType = $options['postType']; $fbWhere = 'feed';
28
- $attachType = $options['attachType']; if ($attachType=='1') $attachType = 'A'; else $attachType = 'S';
29
- if ($options['imgUpl']!='2') $options['imgUpl'] = 'T'; else $options['imgUpl'] = 'A'; $page_id = $options['pgID'];
30
-
31
- $mssg = array('access_token' => $options['fbAppPageAuthToken'], 'message' => $msg);
32
-
33
- if ($fbPostType=='I' && trim($imgURL)=='') $fbPostType='T';
34
- if ($fbPostType=='A' || $fbPostType=='') {
35
- if (($attachType=='A' || $attachType=='S')) { $attArr = array('name' => $message['title'], 'caption' => $message['siteName'], 'link' =>$message['link'], 'description' => $message['description']); $mssg = array_merge($mssg, $attArr); ; }
36
- if ($attachType=='A') $mssg['actions'] = array(array('name' => $message['siteName'], 'link' =>$message['link']));
37
- if (trim($imgURL)!='') $mssg['picture'] = $imgURL; if (trim($message['videoURL'])!='') $mssg['source'] = $message['videoURL'];
38
- } elseif ($fbPostType=='I') { $facebook->setFileUploadSupport(true); $fbWhere = 'photos'; $mssg['url'] = $imgURL;
39
- if ($options['imgUpl']=='T') { //## Try to Post to TImeline
40
- $aacct = array('access_token' => $options['fbAppPageAuthToken']);
41
- try { $albums = $facebook->api("/$page_id/albums", "get", $aacct); } catch (NXS_FacebookApiException $e) { $badOut['Error'] = ' [ERROR] '.$e->getMessage()."<br/>\n"; }
42
-
43
- if (isset($albums) && isset($albums["data"]) && is_array($albums["data"])) foreach ($albums["data"] as $album) { if ($album["type"] == "wall") { $chosen_album = $album; break;}}
44
- if (isset($chosen_album) && isset($chosen_album["id"])) $page_id = $chosen_album["id"];
45
- }
46
- }
47
- //prr($message); prr($mssg); prr($options); //die();
48
- try { $ret = $facebook->api("/$page_id/".$fbWhere, "post", $mssg);} catch (NXS_FacebookApiException $e) { $badOut['Error'] = ' [ERROR] '.$e->getMessage()."<br/>\n";
49
- if (stripos($e->getMessage(),'This API call requires a valid app_id')!==false) {
50
- if ( !is_numeric($page_id) && stripos($options['fbURL'], '/groups/')!=false) $badOut['Error'] .= ' [ERROR] Unrecognized Facebook Group ID. Please use numeric ID.';
51
- else $badOut['Error'] .= " [ERROR] (invalid app_id) Authorization Error. <br/>\r\n<br/>\r\n Possible Reasons: <br/>\r\n 1. Your app is not authorized. Please go to the Plugin Settings - Facebook and authorize it.<br/>\r\n 2. The current authorized user have no rights to post to the specified page. Please login to Facebook as the correct user and Re-Authorize the Plugin.<br/>\r\n 3. You clicked 'Skip' or unchecked the 'Manage Pages' or 'Post on your behalf' permissions when Authorization wizard asked you. Please Re-Authorize the Plugin<br/>\r\n";
52
- }
53
- }
54
- if (isset($ret['id']) && $ret['id']!='') {
55
- $pgID = (isset($ret['post_id']) && strpos($ret['post_id'],'_')!==false)?$ret['post_id']:$ret['id']; $pgg = explode('_', $pgID); $postID = $pgg[1];
56
- $pgURL = 'http://www.facebook.com/'.$options['pgID'].'/posts/'.$postID;
57
- return array('isPosted'=>'1', 'postID'=>$pgID, 'postURL'=>$pgURL, 'pDate'=>date('Y-m-d H:i:s'));
58
- } else return $badOut;
59
- }
60
- }}
 
61
  ?>
1
+ <?php
2
+ //## NextScripts Facebook Connection Class
3
+ $nxs_snapAPINts[] = array('code'=>'FB', 'lcode'=>'fb', 'name'=>'Facebook');
4
+
5
+ if (!class_exists("nxs_class_SNAP_FB")) { class nxs_class_SNAP_FB {
6
+
7
+ var $ntCode = 'FB';
8
+ var $ntLCode = 'fb';
9
+
10
+ function doPost($options, $message){ if (!is_array($options)) return false; $out = array(); //return false;
11
+ foreach ($options as $ii=>$ntOpts) $out[$ii] = $this->doPostToNT($ntOpts, $message);
12
+ return $out;
13
+ }
14
+ function doPostToNT($options, $message){ require_once ('apis/facebook.php'); $badOut = array('pgID'=>'', 'isPosted'=>0, 'pDate'=>date('Y-m-d H:i:s'), 'Error'=>''); // prr($message); prr($options);
15
+ //## Check settings
16
+ if (!is_array($options)) { $badOut['Error'] = 'No Options'; return $badOut; }
17
+ if (!isset($options['fbAppAuthToken']) || trim($options['fbAppAuthToken'])=='') { $badOut['Error'] = 'No Auth Token Found'; return $badOut; }
18
+ //## Make Post
19
+ $facebook = new NXS_Facebook(array( 'appId' => $options['fbAppID'], 'secret' => $options['fbAppSec'], 'cookie' => true ));
20
+ if (!isset($options['fbAppPageAuthToken']) || trim($options['fbAppPageAuthToken'])=='') $options['fbAppPageAuthToken'] = $options['fbAppAuthToken'];
21
+
22
+ //## Some OLD Format Conversion
23
+ if (!isset($options['attachType']) && isset($options['fbAttch'])) $options['attachType'] = $options['fbAttch'];
24
+ if (!isset($options['postType']) && isset($options['fbPostType'])) $options['postType'] = $options['fbPostType'];
25
+ if (!isset($options['pgID']) && isset($options['fbPgID'])) $options['pgID'] = $options['fbPgID'];
26
+
27
+ $msg = $message['message']; $imgURL = $message['imageURL']; $fbPostType = $options['postType']; $fbWhere = 'feed';
28
+ $attachType = $options['attachType']; if ($attachType=='1') $attachType = 'A'; else $attachType = 'S';
29
+ if ($options['imgUpl']!='2') $options['imgUpl'] = 'T'; else $options['imgUpl'] = 'A'; $page_id = $options['pgID'];
30
+ $msg = strip_tags($msg); $msg = str_ireplace('&lt;(")','<(")', $msg); //## FB Smiles FIX 3
31
+ if (substr($msg, 0, 1)=='@') $msg = ' '.$msg;
32
+ $mssg = array('access_token' => $options['fbAppPageAuthToken'], 'message' => $msg);
33
+
34
+ if ($fbPostType=='I' && trim($imgURL)=='') $fbPostType='T';
35
+ if ($fbPostType=='A' || $fbPostType=='') {
36
+ if (($attachType=='A' || $attachType=='S')) { $attArr = array('name' => $message['title'], 'caption' => $message['siteName'], 'link' =>$message['link'], 'description' => $message['description']); $mssg = array_merge($mssg, $attArr); ; }
37
+ if ($attachType=='A') $mssg['actions'] = array(array('name' => $message['siteName'], 'link' =>$message['link']));
38
+ if (trim($imgURL)!='') $mssg['picture'] = $imgURL; if (trim($message['videoURL'])!='') $mssg['source'] = $message['videoURL'];
39
+ } elseif ($fbPostType=='I') { $facebook->setFileUploadSupport(true); $fbWhere = 'photos'; $mssg['url'] = $imgURL;
40
+ if ($options['imgUpl']=='T') { //## Try to Post to TImeline
41
+ $aacct = array('access_token' => $options['fbAppPageAuthToken']);
42
+ try { $albums = $facebook->api("/$page_id/albums", "get", $aacct); } catch (NXS_FacebookApiException $e) { $badOut['Error'] = ' [ERROR] '.$e->getMessage()."<br/>\n"; }
43
+
44
+ if (isset($albums) && isset($albums["data"]) && is_array($albums["data"])) foreach ($albums["data"] as $album) { if ($album["type"] == "wall") { $chosen_album = $album; break;}}
45
+ if (isset($chosen_album) && isset($chosen_album["id"])) $page_id = $chosen_album["id"];
46
+ }
47
+ }
48
+ //prr($message); prr($mssg); prr($options); //die();
49
+ try { $ret = $facebook->api("/$page_id/".$fbWhere, "post", $mssg);} catch (NXS_FacebookApiException $e) { $badOut['Error'] = ' [ERROR] '.$e->getMessage()."<br/>\n";
50
+ if (stripos($e->getMessage(),'This API call requires a valid app_id')!==false) {
51
+ if ( !is_numeric($page_id) && stripos($options['fbURL'], '/groups/')!=false) $badOut['Error'] .= ' [ERROR] Unrecognized Facebook Group ID. Please use numeric ID.';
52
+ else $badOut['Error'] .= " [ERROR] (invalid app_id) Authorization Error. <br/>\r\n<br/>\r\n Possible Reasons: <br/>\r\n 1. Your app is not authorized. Please go to the Plugin Settings - Facebook and authorize it.<br/>\r\n 2. The current authorized user have no rights to post to the specified page. Please login to Facebook as the correct user and Re-Authorize the Plugin.<br/>\r\n 3. You clicked 'Skip' or unchecked the 'Manage Pages' or 'Post on your behalf' permissions when Authorization wizard asked you. Please Re-Authorize the Plugin<br/>\r\n";
53
+ }
54
+ }
55
+ if (isset($ret['id']) && $ret['id']!='') {
56
+ $pgID = (isset($ret['post_id']) && strpos($ret['post_id'],'_')!==false)?$ret['post_id']:$ret['id']; $pgg = explode('_', $pgID); $postID = $pgg[1];
57
+ $pgURL = 'http://www.facebook.com/'.$options['pgID'].'/posts/'.$postID;
58
+ return array('isPosted'=>'1', 'postID'=>$pgID, 'postURL'=>$pgURL, 'pDate'=>date('Y-m-d H:i:s'));
59
+ } else return $badOut;
60
+ }
61
+ }}
62
  ?>
inc-cl/fb.php CHANGED
@@ -1,387 +1,420 @@
1
- <?php
2
- //## NextScripts Facebook Connection Class
3
- $nxs_snapAvNts[] = array('code'=>'FB', 'lcode'=>'fb', 'name'=>'Facebook');
4
-
5
- if (!class_exists("nxs_snapClassFB")) { class nxs_snapClassFB {
6
- //#### Show Common Settings
7
- function showGenNTSettings($ntOpts){ global $nxs_snapThisPageUrl, $nxs_plurl; $ntInfo = array('code'=>'FB', 'lcode'=>'fb', 'name'=>'Facebook', 'defNName'=>'dlUName', 'tstReq' => true);
8
- if ( isset($_GET['code']) && $_GET['code']!='' && (isset($_GET['auth']) && $_GET['auth']=='fb') && ((!isset($_GET['action'])) || $_GET['action']!='gPlusAuth')){ $at = $_GET['code']; echo "-= This is normal technical authorization info that will dissapear (Unless you get some errors) =- <br/><br/><br/>";
9
- //$fbo = array('wfa'=> 1339160000); //foreach ($ntOpts as $two) { if (isset($two['wfa']) && $two['wfa']>$fbo['wfa']) $fbo = $two; }
10
- $fbo = $ntOpts[$_GET['acc']]; $wprg = array(); $response = wp_remote_get('https://graph.facebook.com/nextscripts', $wprg);
11
- if( is_wp_error( $response) && isset($response->errors['http_request_failed']) && stripos($response->errors['http_request_failed'][0], 'SSL')!==false ) { prr($response->errors); $wprg['sslverify'] = false; }
12
- if (isset($fbo['fbPgID'])){ echo "-="; prr($fbo);// die();
13
- $response = wp_remote_get('https://graph.facebook.com/oauth/access_token?client_id='.$fbo['fbAppID'].'&redirect_uri='.urlencode($nxs_snapThisPageUrl.'&auth=fb&acc='.$_GET['acc']).'&client_secret='.$fbo['fbAppSec'].'&code='.$at, $wprg);
14
- //prr('https://graph.facebook.com/oauth/access_token?client_id='.$fbo['fbAppID'].'&redirect_uri='.urlencode($nxs_snapThisPageUrl).'&client_secret='.$fbo['fbAppSec'].'&code='.$at);
15
- if ( (is_object($response) && (isset($response->errors))) || (is_array($response) && stripos($response['body'],'"error":')!==false )) { prr($response); die(); }
16
- parse_str($response['body'], $params); $at = $params['access_token']; prr($response); prr($params);
17
- $response = wp_remote_get('https://graph.facebook.com/oauth/access_token?client_secret='.$fbo['fbAppSec'].'&client_id='.$fbo['fbAppID'].'&grant_type=fb_exchange_token&fb_exchange_token='.$at, $wprg);
18
- if ((is_object($response) && isset($response->errors))) { prr($response); die();}
19
- parse_str($response['body'], $params); $at = $params['access_token']; $fbo['fbAppAuthToken'] = $at;
20
- require_once ('apis/facebook.php'); echo "-= Using API =-<br/>";
21
- $facebook = new NXS_Facebook(array( 'appId' => $fbo['fbAppID'], 'secret' => $fbo['fbAppSec'], 'cookie' => true));
22
- $facebook -> setAccessToken($fbo['fbAppAuthToken']); $user = $facebook->getUser(); echo "USER:"; prr($user);
23
- if ($user) {
24
- try { $page_id = $fbo['fbPgID']; echo "-= Authorizing Page =-";
25
- if ( !is_numeric($page_id) && stripos($fbo['fbURL'], '/groups/')!=false) { //$fbPgIDR = wp_remote_get('nxs.php?g='.$fbo['fbURL']); // TODO - how to replace
26
- $fbPgIDR = trim($fbPgIDR['body']); $page_id = $fbPgIDR!=''?$fbPgIDR:$page_id;
27
- } $page_info = $facebook->api("/$page_id?fields=access_token");
28
- if( !empty($page_info['access_token']) ) { $fbo['fbAppPageAuthToken'] = $page_info['access_token']; }
29
- } catch (NXS_FacebookApiException $e) { $errMsg = $e->getMessage(); prr($errMsg);
30
- if ( stripos($errMsg, 'Unknown fields: access_token')!==false) { $fbo['fbAppPageAuthToken'] = $fbo['fbAppAuthToken']; } else {
31
- if (stripos($errMsg, 'Unsupported get request')!==false) echo "<b style='color:red;'>Error </b>: Your Facebook URL ( <i>".$fbo['fbURL']."</i> ) is either incorrect or authorzing user don't have rights to post there.<br/>";
32
- echo 'Reported Error: ', $errMsg, "\n"; die();
33
- }
34
- }
35
- } else echo "Can't get Facebook User. Please login to Facebook.";
36
-
37
- if ($user>0) { $fbo['fbAppAuthUser'] = $user;
38
- $optionsG = get_option('NS_SNAutoPoster'); $optionsG['fb'][$_GET['acc']] = $fbo; update_option('NS_SNAutoPoster', $optionsG);
39
- ?><script type="text/javascript">window.location = "<?php echo $nxs_snapThisPageUrl; ?>"</script>
40
- <?php } die(); }
41
- }
42
- ?>
43
- <div class="nxs_box">
44
- <div class="nxs_box_header">
45
- <div class="nsx_iconedTitle" style="margin-bottom:1px;background-image:url(<?php echo $nxs_plurl;?>img/<?php echo $ntInfo['lcode']; ?>16.png);"><?php echo $ntInfo['name']; ?>
46
- <?php $cbo = count($ntOpts); ?> <?php wp_nonce_field( 'ns'.$ntInfo['code'], 'ns'.$ntInfo['code'].'_wpnonce' ); ?>
47
- <?php if ($cbo>1){ ?><div class="nsBigText"><?php echo "(".($cbo=='0'?'No':$cbo)." "; _e('accounts', 'nxs_snap'); echo ")"; ?></div><?php } ?>
48
- </div>
49
- </div>
50
- <div class="nxs_box_inside">
51
- <?php foreach ($ntOpts as $indx=>$pbo){ if (trim($pbo['nName']=='')) $pbo['nName'] = str_ireplace('https://www.facebook.com','', str_ireplace('http://www.facebook.com','', $pbo['fbURL']));
52
- if (!isset($pbo[$ntInfo['lcode'].'OK']) || $pbo[$ntInfo['lcode'].'OK']=='') $pbo[$ntInfo['lcode'].'OK'] = (isset($pbo['fbAppAuthUser']) && $pbo['fbAppAuthUser']>1)?'1':''; ?>
53
- <p style="margin:0px;margin-left:5px;">
54
- <input value="1" name="<?php echo $ntInfo['lcode']; ?>[<?php echo $indx; ?>][apDo<?php echo $ntInfo['code']; ?>]" onchange="doShowHideBlocks('<?php echo $ntInfo['code']; ?>');" type="checkbox" <?php if ((int)$pbo['do'.$ntInfo['code']] == 1) echo "checked"; ?> /> <?php if ((int)$pbo['catSel'] == 1) { ?> <span onmouseout="nxs_hidePopUpInfo('popOnlyCat');" onmouseover="nxs_showPopUpInfo('popOnlyCat', event);"><?php echo "*[".(substr_count($pbo['catSelEd'], ",")+1)."]*" ?></span><?php } ?>
55
- <strong><?php _e('Auto-publish to', 'nxs_snap'); ?> <?php echo $ntInfo['name']; ?> <i style="color: #005800;"><?php if($pbo['nName']!='') echo "(".$pbo['nName'].")"; ?></i></strong>
56
- &nbsp;&nbsp;<?php if ($ntInfo['tstReq'] && (!isset($pbo[$ntInfo['lcode'].'OK']) || $pbo[$ntInfo['lcode'].'OK']=='')){ ?><b style="color: #800000"><?php _e('Attention requred. Unfinished setup', 'nxs_snap'); ?> ==&gt;</b><?php } ?><a id="do<?php echo $ntInfo['code'].$indx; ?>A" href="#" onclick="doShowHideBlocks2('<?php echo $ntInfo['code'].$indx; ?>');return false;">[<?php _e('Show Settings', 'nxs_snap'); ?>]</a>&nbsp;&nbsp;
57
- <a href="#" onclick="doDelAcct('<?php echo $ntInfo['lcode']; ?>', '<?php echo $indx; ?>', '<?php if (isset($pbo['bgBlogID'])) echo $pbo['nName']; ?>');return false;">[<?php _e('Remove Account', 'nxs_snap'); ?>]</a>
58
- </p><?php $this->showNTSettings($indx, $pbo);
59
- }?>
60
- </div>
61
- </div> <?php
62
-
63
-
64
- }
65
- //#### Show NEW Settings Page
66
- function showNewNTSettings($mfbo){ $fbo = array('nName'=>'', 'doFB'=>'1', 'fbURL'=>'', 'fbAppID'=>'', 'imgUpl'=>'1', 'fbPostType'=>'A', 'fbMsgAFormat'=>'', 'fbAppSec'=>'', 'fbAttch'=>'1', 'fbPgID'=>'', 'fbAppAuthUser'=>'', 'fbMsgFormat'=>__('New post (%TITLE%) has been published on %SITENAME%', 'nxs_snap') ); $this->showNTSettings($mfbo, $fbo, true);}
67
- //#### Show Unit Settings
68
- function showNTSettings($ii, $fbo, $isNew=false){ global $nxs_plurl, $nxs_snapThisPageUrl, $plgn_NS_SNAutoPoster; if ((int)$fbo['fbAttch']==0 && (!isset($fbo['trPostType']) || $fbo['trPostType']=='')) $fbo['trPostType'] = 'T';
69
- if (!isset($plgn_NS_SNAutoPoster)) return; $gOptions = $plgn_NS_SNAutoPoster->nxs_options;
70
- if (!isset($fbo['nHrs'])) $fbo['nHrs'] = 0; if (!isset($fbo['nMin'])) $fbo['nMin'] = 0; if (!isset($fbo['catSel'])) $fbo['catSel'] = 0; if (!isset($fbo['catSelEd'])) $fbo['catSelEd'] = ''; ?>
71
- <div id="doFB<?php echo $ii; ?>Div" class="insOneDiv<?php if ($isNew) echo " clNewNTSets"; ?>" style="background-image: url(<?php echo $nxs_plurl; ?>img/fb-bg.png); background-position:90% 10%;"> <input type="hidden" name="apDoSFB<?php echo $ii; ?>" value="0" id="apDoSFB<?php echo $ii; ?>" />
72
- <?php if ($isNew) { ?> <input type="hidden" name="fb[<?php echo $ii; ?>][apDoFB]" value="1" id="apDoNewFB<?php echo $ii; ?>" /> <?php } ?>
73
-
74
- <div class="nsx_iconedTitle" style="float: right; max-width: 322px; text-align: right; background-image: url(<?php echo $nxs_plurl; ?>img/fb16.png);"><a style="font-size: 12px;" target="_blank" href="http://www.nextscripts.com/setup-installation-facebook-social-networks-auto-poster-wordpress/"><?php $nType="Facebook"; printf( __( 'Detailed %s Installation/Configuration Instructions', 'nxs_snap' ), $nType); ?></a><br/>
75
- <span style="font-size: 10px;"><?php _e('Please use in your Facebook App:', 'nxs_snap'); ?> <br/> URL: <em style="font-size: 10px; color:#CB4B16;">http://<?php echo $_SERVER["SERVER_NAME"] ?></em> <br/>Domain: <em style="font-size: 10px; color:#CB4B16;"><?php echo $_SERVER["SERVER_NAME"] ?></em> </span>
76
-
77
- </div>
78
-
79
- <div style="width:100%;"><strong><?php _e('Account Nickname', 'nxs_snap'); ?>:</strong> <i><?php _e('Just so you can easely identify it', 'nxs_snap'); ?></i> </div><input name="fb[<?php echo $ii; ?>][nName]" id="fbnName<?php echo $ii; ?>" style="font-weight: bold; color: #005800; border: 1px solid #ACACAC; width: 40%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($fbo['nName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /><br/>
80
- <?php echo nxs_addQTranslSel('fb', $ii, $fbo['qTLng']); ?>
81
- <?php echo nxs_addPostingDelaySel('fb', $ii, $fbo['nHrs'], $fbo['nMin']); ?>
82
-
83
- <?php if (!$isNew) { ?>
84
- <div style="width:100%;"><strong><?php _e('Categories', 'nxs_snap'); ?>:</strong>
85
- <input value="0" id="catSelA<?php echo $ii; ?>" type="radio" name="fb[<?php echo $ii; ?>][catSel]" <?php if ((int)$fbo['catSel'] != 1) echo "checked"; ?> /> All
86
- <input value="1" id="catSelSFB<?php echo $ii; ?>" type="radio" name="fb[<?php echo $ii; ?>][catSel]" <?php if ((int)$fbo['catSel'] == 1) echo "checked"; ?> /> <a href="#" style="text-decoration: none;" class="showCats" id="nxs_SCA_FB<?php echo $ii; ?>" onclick="jQuery('#catSelSFB<?php echo $ii; ?>').attr('checked', true); jQuery('#tmpCatSelNT').val('FB<?php echo $ii; ?>'); nxs_markCats( jQuery('#nxs_SC_FB<?php echo $ii; ?>').val() ); jQuery('#showCatSel').bPopup({ modalClose: false, appendTo: '#nsStForm', opacity: 0.6, follow: [false, false], position: [75, 'auto']}); return false;">Selected<?php if ($fbo['catSelEd']!='') echo "[".(substr_count($fbo['catSelEd'], ",")+1)."]"; ?></a>
87
- <input type="hidden" name="fb[<?php echo $ii; ?>][catSelEd]" id="nxs_SC_FB<?php echo $ii; ?>" value="<?php echo $fbo['catSelEd']; ?>" />
88
- <br/><i><?php _e('Only selected categories will be autoposted to this account', 'nxs_snap'); ?></i></div>
89
- <br/>
90
- <?php } ?>
91
- <div style="width:100%;"><strong style="font-size: 16px;">Facebook Settings:</strong> </div>
92
-
93
- <div style="width:100%;"><strong>Facebook URL:</strong> </div>
94
- <p style="font-size: 11px; margin: 0px;"><?php _e('Could be your Facebook Profile, Facebook Page, Facebook Group', 'nxs_snap'); ?></p>
95
- <input name="fb[<?php echo $ii; ?>][apFBURL]" id="apFBURL" style="width: 50%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($fbo['fbURL'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
96
- <div style="width:100%;"><strong>Facebook App ID:</strong> </div><input name="fb[<?php echo $ii; ?>][apFBAppID]" id="apFBAppID" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($fbo['fbAppID'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
97
- <div style="width:100%;"><strong>Facebook App Secret:</strong> </div><input name="fb[<?php echo $ii; ?>][apFBAppSec]" id="apFBAppSec" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($fbo['fbAppSec'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /><br/><br/>
98
- <div id="altFormat">
99
- <div style="width:100%;"><strong id="altFormatText"><?php _e('Message text Format', 'nxs_snap'); ?>:</strong> (<a href="#" id="apFBMsgFrmt<?php echo $ii; ?>HintInfo" onclick="mxs_showHideFrmtInfo('apFBMsgFrmt<?php echo $ii; ?>'); return false;"><?php _e('Show format info', 'nxs_snap'); ?></a>)</div>
100
-
101
- <textarea cols="150" rows="3" id="fb<?php echo $ii; ?>SNAPformat" name="fb[<?php echo $ii; ?>][apFBMsgFrmt]" style="width:51%;max-width: 610px;" onfocus="jQuery('#fb<?php echo $ii; ?>SNAPformat').attr('rows', 6); mxs_showFrmtInfo('apFBMsgFrmt<?php echo $ii; ?>');"><?php _e(apply_filters('format_to_edit', htmlentities($fbo['fbMsgFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?></textarea> <?php nxs_doShowHint("apFBMsgFrmt".$ii); ?>
102
- <br/>
103
- </div><br/>
104
- <div style="width:100%;"><strong style="font-size: 16px;" id="altFormatText">Post Type:</strong>&lt;-- (<a id="showShAtt" onmouseout="hidePopShAtt('<?php echo $ii; ?>X');" onmouseover="showPopShAtt('<?php echo $ii; ?>X', event);" onclick="return false;" class="underdash" href="http://www.nextscripts.com/blog/"><?php _e('What\'s the difference?', 'nxs_snap'); ?></a>) </div>
105
- <div style="margin-left: 10px;">
106
-
107
- <input type="radio" name="fb[<?php echo $ii; ?>][fbPostType]" value="T" <?php if ($fbo['fbPostType'] == 'T') echo 'checked="checked"'; ?> /> <?php _e('Text Post', 'nxs_snap'); ?> - <i><?php _e('just text message', 'nxs_snap'); ?></i><br/>
108
-
109
- <input type="radio" name="fb[<?php echo $ii; ?>][fbPostType]" value="I" <?php if ($fbo['fbPostType'] == 'I') echo 'checked="checked"'; ?> /> <?php _e('Image Post', 'nxs_snap'); ?> - <i><?php _e('big image with text message', 'nxs_snap'); ?></i><br/>
110
- <div style="width:100%; margin-left: 15px;"><strong><?php _e('Upload Images to', 'nxs_snap'); ?>:&nbsp;</strong>
111
- <input value="2" id="apFBImgUplAPP<?php echo $ii; ?>" type="radio" name="fb[<?php echo $ii; ?>][apFBImgUpl]" <?php if ((int)$fbo['imgUpl'] == 2) echo "checked"; ?> /> <?php _e('App Album', 'nxs_snap'); ?> .. <?php _e('or', 'nxs_snap'); ?> ..
112
- <input value="1" id="apFBImgUplTML<?php echo $ii; ?>" type="radio" name="fb[<?php echo $ii; ?>][apFBImgUpl]" <?php if ((int)$fbo['imgUpl'] != 2) echo "checked"; ?> />
113
- <?php _e('Timeline', 'nxs_snap'); ?> &lt;-- (<a id="showShAtt" onmouseout="hidePopShAtt('<?php echo $ii; ?>I');" onmouseover="showPopShAtt('<?php echo $ii; ?>I', event);" onclick="return false;" class="underdash" href="http://www.nextscripts.com/blog/"><?php _e('What\'s the difference?', 'nxs_snap'); ?></a>)
114
- </div>
115
-
116
- <input type="radio" name="fb[<?php echo $ii; ?>][fbPostType]" value="A" <?php if ( !isset($fbo['fbPostType']) || $fbo['fbPostType'] == '' || $fbo['fbPostType'] == 'A') echo 'checked="checked"'; ?> /> <?php _e('Text Post with "attached" link', 'nxs_snap'); ?><br/>
117
-
118
- <div style="width:100%; margin-left: 15px;"><strong><?php _e('Link attachment type', 'nxs_snap'); ?>:&nbsp;</strong> <input value="2" id="apFBAttchShare<?php echo $ii; ?>" type="radio" name="fb[<?php echo $ii; ?>][apFBAttch]" <?php if ((int)$fbo['fbAttch'] == 2) echo "checked"; ?> />
119
- <?php _e('Share a link to your blogpost', 'nxs_snap'); ?> .. <?php _e('or', 'nxs_snap'); ?> ..
120
- <input value="1" id="apFBAttch<?php echo $ii; ?>" type="radio" name="fb[<?php echo $ii; ?>][apFBAttch]" <?php if ((int)$fbo['fbAttch'] == 1) echo "checked"; ?> />
121
- <?php _e('Attach your blogpost', 'nxs_snap'); ?> &lt;-- (<a id="showShAtt" onmouseout="hidePopShAtt('<?php echo $ii; ?>');" onmouseover="showPopShAtt('<?php echo $ii; ?>', event);" onclick="return false;" class="underdash" href="http://www.nextscripts.com/blog/"><?php _e('What\'s the difference?', 'nxs_snap'); ?></a>)
122
- <div style="margin-bottom: 5px; margin-left: 10px; "><input value="1" id="apFBAttchAsVid" type="checkbox" name="fb[<?php echo $ii; ?>][apFBAttchAsVid]" <?php if (isset($fbo['fbAttchAsVid']) && (int)$fbo['fbAttchAsVid'] == 1) echo "checked"; ?> /> <strong><?php _e('If post has video use it as an attachment thumbnail.', 'nxs_snap'); ?></strong> <i><?php _e('Video will be used for an attachment thumbnail instead of featured image. Only Youtube is supported at this time.', 'nxs_snap'); ?></i>
123
- <br/></div>
124
- <strong><?php _e('Attachment Text Format', 'nxs_snap'); ?>:</strong><br/>
125
- <input value="1" id="apFBMsgAFrmtA<?php echo $ii; ?>" <?php if (trim($fbo['fbMsgAFrmt'])=='') echo "checked"; ?> onchange="if (jQuery(this).is(':checked')) { jQuery('#apFBMsgAFrmtDiv<?php echo $ii; ?>').hide(); jQuery('#apFBMsgAFrmt<?php echo $ii; ?>').val(''); }else jQuery('#apFBMsgAFrmtDiv<?php echo $ii; ?>').show();" type="checkbox" name="fb[<?php echo $ii; ?>][apFBMsgAFrmtA]"/> <strong><?php _e('Auto', 'nxs_snap'); ?></strong>
126
- <i> - <?php _e('Recommended. Info from SEO Plugins will be used, then post excerpt, then post text', 'nxs_snap'); ?> </i><br/>
127
- <div id="apFBMsgAFrmtDiv<?php echo $ii; ?>" style="<?php if ($fbo['fbMsgAFrmt']=='') echo "display:none;"; ?>" >&nbsp;&nbsp;&nbsp; <?php _e('Set your own format', 'nxs_snap'); ?>:<input name="fb[<?php echo $ii; ?>][apFBMsgAFrmt]" id="apFBMsgAFrmt<?php echo $ii; ?>" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($fbo['fbMsgAFrmt'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /><br/></div>
128
- </div><br/>
129
- </div>
130
- <div style="width:100%;"><strong style="font-size: 16px;"><?php _e('Facebook Comments:', 'nxs_snap'); ?></strong> </div>
131
- <div style="margin-bottom: 5px; margin-left: 10px; ">
132
- <p style="font-size: 11px; margin: 0px;"><?php _e('Plugin could grab comments from Facebook and import them as Wordpress Comments', 'nxs_snap'); ?></p>
133
-
134
- <?php if ( $gOptions['riActive'] == '1' ) { ?>
135
- <input value="1" id="apFBMsgAFrmtA<?php echo $ii; ?>" <?php if (trim($fbo['riComments'])=='1') echo "checked"; ?> type="checkbox" name="fb[<?php echo $ii; ?>][riComments]"/> <strong><?php _e('Import Facebook Comments', 'nxs_snap'); ?></strong>
136
- <br/>
137
- <div style="margin-bottom: 5px; margin-left: 10px; ">
138
- <input value="1" id="apFBMsgAFrmtA<?php echo $ii; ?>" <?php if (trim($fbo['riCommentsAA'])=='1') echo "checked"; ?> type="checkbox" name="fb[<?php echo $ii; ?>][riCommentsAA]"/> <strong><?php _e('Auto-approve imported comments', 'nxs_snap'); ?></strong></div>
139
-
140
- <?php } else { echo "<br/>"; _e('Please activate the "Comments Import" from SNAP Settings - Other Settings', 'nxs_snap'); } ?>
141
-
142
- </div>
143
-
144
- <br/><br/>
145
-
146
- <div class="popShAtt" style="z-index: 9999; width: 350px;" id="popShAtt<?php echo $ii; ?>I"><h3><?php _e('Where to upload Images', 'nxs_snap'); ?></h3> <b><?php _e('(App Album)', 'nxs_snap'); ?></b> <?php _e('Facebook automatically creates an album for your app. Images will be grouped there as in any regular album.', 'nxs_snap'); ?> <br/><br/><b><?php _e('(Timeline)', 'nxs_snap'); ?></b> <?php _e('Images will be posted to the special "Wall/Timeline" album and won\'t be grouped. "Wall/Timeline" album must exist. It\'s created when first image posted to timeline manually.', 'nxs_snap'); ?></div>
147
- <div class="popShAtt" style="z-index: 9999" id="popShAtt<?php echo $ii; ?>"><h3><?php _e('Two ways of attaching post on Facebook', 'nxs_snap'); ?></h3><img src="<?php echo $nxs_plurl; ?>img/fb2wops.jpg" width="600" height="271" alt="<?php _e('Two ways of attaching post on Facebook', 'nxs_snap'); ?>"/></div>
148
- <div class="popShAtt" style="z-index: 9999" id="popShAtt<?php echo $ii; ?>X"><h3><?php _e('Facebook Post Types', 'nxs_snap'); ?></h3><img src="<?php echo $nxs_plurl; ?>img/fbPostTypesDiff6.png" width="600" height="398" alt="<?php _e('Facebook Post Types', 'nxs_snap'); ?>"/></div>
149
-
150
-
151
-
152
-
153
- <?php if ($fbo['fbPgID']!='') {?><div style="width:100%;"><strong>Facebook Page ID:</strong> <?php _e(apply_filters('format_to_edit', htmlentities($fbo['fbPgID'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?> </div><?php } ?>
154
- <?php
155
- if($fbo['fbAppSec']=='') { ?>
156
- <b><?php _e('Authorize Your Facebook Account', 'nxs_snap'); ?></b> <?php _e('Please click "Update Settings" to be able to Authorize your account.', 'nxs_snap'); ?>
157
- <?php } else { if(isset($fbo['fbAppAuthUser']) && $fbo['fbAppAuthUser']>0) { ?>
158
- <?php _e('Your Facebook Account has been authorized.', 'nxs_snap'); ?> User ID: <?php _e(apply_filters('format_to_edit', htmlentities($fbo['fbAppAuthUser'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>.
159
- <?php _e('You can', 'nxs_snap'); ?> Re- <?php } ?>
160
- <a href="https://www.facebook.com/dialog/oauth?client_id=<?php echo trim($fbo['fbAppID']);?>&client_secret=<?php echo trim($fbo['fbAppSec']);?>&scope=publish_stream,user_photos,photo_upload,friends_photos,offline_access,read_stream,manage_pages,user_groups,friends_groups&redirect_uri=<?php echo trim(urlencode($nxs_snapThisPageUrl.'&auth=fb&acc='.$ii));?>">Authorize Your Facebook Account</a>
161
- <?php if (!isset($fbo['fbAppAuthUser']) || $fbo['fbAppAuthUser']<1) { ?> <div class="blnkg">&lt;=== <?php _e('Authorize your account', 'nxs_snap'); ?> ===</div>
162
- <br/><br/><i> <?php _e('If you get Facebook message:', 'nxs_snap'); ?> <b>"Error. An error occurred. Please try again later."</b> or <b>"Error 191"</b> <?php _e('please make sure that domain name in your Facebook App matches your website domain exactly. Please note that www. and non www. versions are different domains.', 'nxs_snap'); ?></i> <?php }?>
163
- <?php } ?>
164
-
165
- <?php if(isset($fbo['fbAppAuthUser']) && $fbo['fbAppAuthUser']>0) { ?>
166
- <?php wp_nonce_field( 'rePostToFB', 'rePostToFB_wpnonce' ); ?>
167
- <br/><br/><b><?php _e('Test your settings', 'nxs_snap'); ?>:</b>&nbsp;&nbsp;&nbsp; <a href="#" class="NXSButton" onclick="testPost('FB','<?php echo $ii; ?>'); return false;"><?php printf( __( 'Submit Test Post to %s', 'nxs_snap' ), $nType); ?></a>
168
- <?php }?>
169
- <div class="submit"><input type="submit" class="button-primary" name="update_NS_SNAutoPoster_settings" value="<?php _e('Update Settings', 'nxs_snap') ?>" /></div>
170
-
171
- </div>
172
- <?php
173
-
174
- }
175
- //#### Set Unit Settings from POST
176
- function setNTSettings($post, $options){ global $nxs_snapThisPageUrl; $code = 'FB'; $lcode = 'fb';
177
- foreach ($post as $ii => $pval){
178
- if (isset($pval['apFBAppID']) && $pval['apFBAppID']!='') { if (!isset($options[$ii])) $options[$ii] = array();
179
- if (isset($pval['apDoFB'])) $options[$ii]['doFB'] = $pval['apDoFB']; else $options[$ii]['doFB'] = 0;
180
- if (isset($pval['nName'])) $options[$ii]['nName'] = trim($pval['nName']);
181
- if (isset($pval['apFBAppID'])) $options[$ii]['fbAppID'] = trim($pval['apFBAppID']);
182
- if (isset($pval['apFBAppSec'])) $options[$ii]['fbAppSec'] = trim($pval['apFBAppSec']);
183
-
184
- if (isset($pval['catSel'])) $options[$ii]['catSel'] = trim($pval['catSel']);
185
- if ($options[$ii]['catSel']=='1' && trim($pval['catSelEd'])!='') $options[$ii]['catSelEd'] = trim($pval['catSelEd']); else $options[$ii]['catSelEd'] = '';
186
-
187
- if (isset($pval['fbPostType'])) $options[$ii]['fbPostType'] = trim($pval['fbPostType']);
188
- if (isset($pval['apFBAttch'])) $options[$ii]['fbAttch'] = $pval['apFBAttch']; else $options[$ii]['fbAttch'] = 0;
189
- if (isset($pval['apFBAttchAsVid'])) $options[$ii]['fbAttchAsVid'] = $pval['apFBAttchAsVid']; else $options[$ii]['fbAttchAsVid'] = 0;
190
-
191
- if (isset($pval['apFBImgUpl'])) $options[$ii]['imgUpl'] = $pval['apFBImgUpl']; else $options[$ii]['imgUpl'] = 0;
192
-
193
- if (isset($pval['apFBMsgFrmt'])) $options[$ii]['fbMsgFormat'] = trim($pval['apFBMsgFrmt']);
194
- if (isset($pval['apFBMsgAFrmt'])) $options[$ii]['fbMsgAFrmt'] = trim($pval['apFBMsgAFrmt']);
195
-
196
- if (isset($pval['riComments'])) $options[$ii]['riComments'] = $pval['riComments']; else $options[$ii]['riComments'] = 0;
197
- if (isset($pval['riCommentsAA'])) $options[$ii]['riCommentsAA'] = $pval['riCommentsAA']; else $options[$ii]['riCommentsAA'] = 0;
198
-
199
-
200
- if (isset($pval['delayHrs'])) $options[$ii]['nHrs'] = trim($pval['delayHrs']); if (isset($pval['delayMin'])) $options[$ii]['nMin'] = trim($pval['delayMin']);
201
- if (isset($pval['qTLng'])) $options[$ii]['qTLng'] = trim($pval['qTLng']);
202
-
203
- if (isset($pval['apFBURL'])) { $options[$ii]['fbURL'] = trim($pval['apFBURL']); if ( substr($options[$ii]['fbURL'], 0, 4)!='http' ) $options[$ii]['fbURL'] = 'http://'.$options[$ii]['fbURL'];
204
- $fbPgID = $options[$ii]['fbURL']; if (substr($fbPgID, -1)=='/') $fbPgID = substr($fbPgID, 0, -1); $fbPgID = substr(strrchr($fbPgID, "/"), 1);
205
- if (strpos($fbPgID, '?')!==false) $fbPgID = substr($fbPgID, 0, strpos($fbPgID, '?'));
206
- $options[$ii]['fbPgID'] = $fbPgID; //echo $fbPgID;
207
- if (strpos($options[$ii]['fbURL'], '?')!==false) $options[$ii]['fbURL'] = substr($options[$ii]['fbURL'], 0, strpos($options[$ii]['fbURL'], '?'));// prr($pval); prr($options[$ii]); // die();
208
- }
209
- }
210
- } return $options;
211
- }
212
- //#### Show Post->Edit Meta Box Settings
213
- function showEdPostNTSettings($ntOpts, $post){ global $nxs_plurl; $post_id = $post->ID;
214
- foreach($ntOpts as $ii=>$ntOpt) { $pMeta = maybe_unserialize(get_post_meta($post_id, 'snapFB', true)); if (is_array($pMeta)) $ntOpt = $this->adjMetaOpt($ntOpt, $pMeta[$ii]);
215
- $doFB = $ntOpt['doFB'] && (is_array($pMeta) || $ntOpt['catSel']!='1');
216
- $isAvailFB = $ntOpt['fbURL']!='' && $ntOpt['fbAppID']!='' && $ntOpt['fbAppSec']!=''; $isAttachFB = $ntOpt['fbAttch']; $fbMsgFormat = htmlentities($ntOpt['fbMsgFormat'], ENT_COMPAT, "UTF-8"); $fbPostType = $ntOpt['fbPostType'];
217
- ?>
218
-
219
- <tr><th style="text-align:left;" colspan="2"> <?php if ( $ntOpt['catSel']=='1' && trim($ntOpt['catSelEd'])!='' ) { ?> <input type="hidden" class="nxs_SC" id="nxs_SC_FB<?php echo $ii; ?>" value="<?php echo $ntOpt['catSelEd']; ?>" /> <?php } ?>
220
-
221
- <?php if ($isAvailFB) { ?><input class="nxsGrpDoChb" value="1" id="doFB<?php echo $ii; ?>" <?php if ($post->post_status == "publish") echo 'disabled="disabled"';?> type="checkbox" name="fb[<?php echo $ii; ?>][doFB]" <?php if ((int)$doFB == 1) echo 'checked="checked" title="def"'; ?> />
222
- <?php if ($post->post_status == "publish") { ?> <input type="hidden" name="fb[<?php echo $ii; ?>][doFB]" value="<?php echo $doFB;?>"> <?php } ?> <?php } ?>
223
-
224
- <div class="nsx_iconedTitle" style="display: inline; font-size: 13px; background-image: url(<?php echo $nxs_plurl; ?>img/fb16.png);">Facebook - <?php _e('publish to', 'nxs_snap') ?> (<i style="color: #005800;"><?php echo $ntOpt['nName']; ?></i>)</div></th><td><?php //## Only show RePost button if the post is "published"
225
- if ($post->post_status == "publish" && $isAvailFB) { ?>
226
-
227
- <input alt="<?php echo $ii; ?>" style="float: right;margin-left: 10px" onmouseout="hidePopShAtt('SV');" onmouseover="showPopShAtt('SV', event);" onclick="return false;" type="button" class="button" name="rePostToFB_repostButton" id="rePostToFB_button" value="<?php _e('Repost to Facebook', 'nxs_snap') ?>" />
228
- <?php if ($ntOpt['riComments']=='1' && (is_array($pMeta) && is_array($pMeta[$ii]) && isset($pMeta[$ii]['pgID']) && strpos($pMeta[$ii]['pgID'],'_')!==false ) ) { ?>
229
- <input alt="<?php echo $ii; ?>" style="float: right; " onclick="return false;" type="button" class="button" name="riToFB_repostButton" id="riToFB_button" value="<?php _e('Import Comments from Facebook', 'nxs_snap') ?>" />
230
- <?php } ?>
231
-
232
- <?php wp_nonce_field( 'rePostToFB', 'rePostToFB_wpnonce' ); } ?>
233
-
234
- <?php if (is_array($pMeta) && is_array($pMeta[$ii]) && isset($pMeta[$ii]['pgID']) && strpos($pMeta[$ii]['pgID'],'_')!==false ) { $pid = explode('_', $pMeta[$ii]['pgID']);
235
-
236
- ?> <span id="pstdFB<?php echo $ii; ?>" style="float: right;padding-top: 4px; padding-right: 10px;">
237
- <a style="font-size: 10px;" href="http://www.facebook.com/permalink.php?story_fbid=<?php echo $pid[1].'&id='.$pid[0]; ?>" target="_blank"><?php $nType="Facebook"; printf( __( 'Posted on', 'nxs_snap' ), $nType); ?> <?php echo (isset($pMeta[$ii]['pDate']) && $pMeta[$ii]['pDate']!='')?(" (".$pMeta[$ii]['pDate'].")"):""; ?></a>
238
- </span><?php } ?>
239
-
240
- </td></tr>
241
- <?php if (!$isAvailFB) { ?><tr><th scope="row" style="text-align:right; width:150px; padding-top: 5px; padding-right:10px;"></th> <td><b>Setup and Authorize your Facebook Account to AutoPost to Facebook</b>
242
- <?php } elseif ($post->post_status != "puZblish") {?>
243
-
244
- <tr><th scope="row" style="text-align:right; width:150px; padding-top: 5px; padding-right:10px;">
245
-
246
- <b></b>
247
- </th>
248
- <td></td>
249
- </tr>
250
-
251
- <tr><th scope="row" style="text-align:right; width:150px; vertical-align:top; padding-top: 0px; padding-right:10px;"> <?php _e('Post Type:', 'nxs_snap'); ?> <br/>
252
- (<a id="showShAtt" style="font-weight: normal" onmouseout="hidePopShAtt('<?php echo $ii; ?>X');" onmouseover="showPopShAtt('<?php echo $ii; ?>X', event);" onclick="return false;" class="underdash" href="http://www.nextscripts.com/blog/"><?php _e('What\'s the difference?', 'nxs_snap'); ?></a>)</th><td>
253
-
254
- <input type="radio" name="fb[<?php echo $ii; ?>][PostType]" value="T" <?php if ($fbPostType == 'T') echo 'checked="checked"'; ?> /> <?php _e('Text Post', 'nxs_snap'); ?> - <i><?php _e('just text message', 'nxs_snap'); ?></i><br/>
255
- <input type="radio" name="fb[<?php echo $ii; ?>][PostType]" value="I" <?php if ($fbPostType == 'I') echo 'checked="checked"'; ?> /> <?php _e('Image Post', 'nxs_snap'); ?> - <i><?php _e('big image with text message', 'nxs_snap'); ?></i><br/>
256
- <input type="radio" name="fb[<?php echo $ii; ?>][PostType]" value="A" <?php if ( !isset($fbPostType) || $fbPostType == '' || $fbPostType == 'A') echo 'checked="checked"'; ?> /> <?php _e('Text Post with "attached" blogpost', 'nxs_snap'); ?> &lt;-- (<a id="showShAtt" onmouseout="hidePopShAtt('<?php echo $ii; ?>');" onmouseover="showPopShAtt('<?php echo $ii; ?>', event);" onclick="return false;" class="underdash" href="http://www.nextscripts.com/blog/"><?php _e('What\'s the difference?', 'nxs_snap'); ?></a>) <br/>
257
-
258
- <div style="width:100%; margin-left: 25px;"><strong><?php _e('Link attachment type:', 'nxs_snap'); ?>&nbsp;</strong> <input value="2" id="apFBAttchShare<?php echo $ii; ?>" onchange="doSwitchShAtt(0,<?php echo $ii; ?>);" type="radio" name="fb[<?php echo $ii; ?>][AttachPost]" <?php if ((int)$isAttachFB == 2) echo "checked"; ?> />
259
- <?php _e('Share a link to your blogpost', 'nxs_snap'); ?> .. <?php _e('or', 'nxs_snap'); ?> ..
260
- <input value="1" id="apFBAttch<?php echo $ii; ?>" onchange="doSwitchShAtt(1,<?php echo $ii; ?>);" type="radio" name="fb[<?php echo $ii; ?>][AttachPost]" <?php if ((int)$isAttachFB == 1) echo "checked"; ?> />
261
- <?php _e('Attach your blogpost', 'nxs_snap'); ?>
262
- </div>
263
- <div class="popShAtt" id="popShAtt<?php echo $ii; ?>"><h3><?php _e('Two ways of attaching post on Facebook', 'nxs_snap'); ?></h3> <img src="<?php echo $nxs_plurl; ?>img/fb2wops.jpg" width="600" height="271" alt="<?php _e('Two ways of attaching post on Facebook', 'nxs_snap'); ?>"/></div>
264
- <div class="popShAtt" id="popShAtt<?php echo $ii; ?>X"><h3><?php _e('Facebook Post Types', 'nxs_snap'); ?></h3><img src="<?php echo $nxs_plurl; ?>img/fbPostTypesDiff6.png" width="600" height="398" alt="<?php _e('Facebook Post Types', 'nxs_snap'); ?>"/></div>
265
- </td></tr>
266
- <!--
267
- <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top: 6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Image(s) to use:', 'nxs_snap') ?></th>
268
- <td><input type="checkbox" class="isAutoImg" checked="checked" id="isAutoImg-fb<?php echo $ii; ?>" name="fb[<?php echo $ii; ?>][isAutoImg]" value="A"/> <?php _e('Auto', 'nxs_snap'); ?><br/>
269
- <div id="imgPrevList-fb<?php echo $ii; ?>" class="nxs_imgPrevList"></div></td></tr>
270
- -->
271
- <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top: 6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Message Format:', 'nxs_snap') ?></th>
272
- <td>
273
- <?php if (1==1) { ?>
274
- <textarea cols="150" rows="2" id="fb<?php echo $ii; ?>SNAPformat" name="fb[<?php echo $ii; ?>][SNAPformat]" style="width:60%;max-width: 610px;" onfocus="jQuery('#fb<?php echo $ii; ?>SNAPformat').attr('rows', 4); jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apFBTMsgFrmt<?php echo $ii; ?>');"><?php echo $fbMsgFormat ?></textarea>
275
- <?php } else { ?>
276
- <input value="<?php echo $fbMsgFormat ?>" type="text" name="fb[<?php echo $ii; ?>][SNAPformat]" style="width:60%;max-width: 610px;" onfocus="jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apFBTMsgFrmt<?php echo $ii; ?>');"/><?php nxs_doShowHint("apFBTMsgFrmt".$ii, '', '58'); ?>
277
- <?php } ?>
278
- </td></tr>
279
-
280
- <?php }
281
- }
282
-
283
- }
284
-
285
- function adjMetaOpt($optMt, $pMeta){ if (isset($pMeta['isPosted'])) $optMt['isPosted'] = $pMeta['isPosted']; else $optMt['isPosted'] = '';
286
- if (isset($pMeta['SNAPformat'])) $optMt['fbMsgFormat'] = $pMeta['SNAPformat'];
287
- if (isset($pMeta['AttachPost'])) $optMt['fbAttch'] = ($pMeta['AttachPost'] != '')?$pMeta['AttachPost']:0; else { if (isset($pMeta['SNAPformat'])) $optMt['fbAttch'] = 0; }
288
- if (isset($pMeta['PostType'])) $optMt['fbPostType'] = ($pMeta['PostType'] != '')?$pMeta['PostType']:0; else { if (isset($pMeta['SNAPformat'])) $optMt['fbPostType'] = 'T'; }
289
- if (isset($pMeta['doFB'])) $optMt['doFB'] = $pMeta['doFB'] == 1?1:0; else { if (isset($pMeta['SNAPformat'])) $optMt['doFB'] = 0; }
290
- if (isset($pMeta['SNAPincludeFB']) && $pMeta['SNAPincludeFB'] == '1' ) $optMt['doFB'] = 1; // <2.6 Compatibility fix
291
- return $optMt;
292
- }
293
- }}
294
-
295
- if (!function_exists("nxs_getBackFBComments")) { function nxs_getBackFBComments($postID, $options, $po) { require_once ('apis/facebook.php'); $opts = array('access_token' => $options['fbAppPageAuthToken']);
296
- $facebook = new NXS_Facebook(array( 'appId' => $options['fbAppID'], 'secret' => $options['fbAppSec'], 'cookie' => true )); $ci = 0;
297
- $ret = $facebook->api($po['pgID']."/comments", "GET", $opts); $impCmnts = get_post_meta($postID, 'snapImportedComments', true); if (!is_array($impCmnts)) $impCmnts = array();
298
- if (is_array($ret) && is_array($ret['data'])) foreach ($ret['data'] as $comment){ $cid = $comment['id']; if (trim($cid)=='' || in_array('fbxcw'.$cid, $impCmnts)) continue; else $impCmnts[] = 'fbxcw'.$cid; // prr($impCmnts);
299
- $authData = $facebook->api($comment['from']['id'], "GET", $opts);
300
- $commentdata = array( 'comment_post_ID' => $postID, 'comment_author' => $comment['from']['name'], 'comment_author_email' => $comment['from']['id'].'@facebook.com',
301
- 'comment_author_url' => $authData['link'], 'comment_content' => $comment['message'], 'comment_date_gmt' => date('Y-m-d H:i:s', strtotime( $comment['created_time'] ) ), 'comment_type' => '');
302
- // prr($commentdata);
303
- nxs_postNewComment($commentdata, $options['riCommentsAA']=='1'); $ci++;
304
- }
305
- delete_post_meta($postID, 'snapImportedComments'); add_post_meta($postID, 'snapImportedComments', $impCmnts );
306
- if ($_POST['id']!='') printf( _n( '%d comment has been imported.', '%d comments has been imported.', $ci, 'nxs_snap'), $ci );
307
- }}
308
-
309
- if (!function_exists("nxs_rePostToFB_ajax")) { function nxs_rePostToFB_ajax() { check_ajax_referer('rePostToFB'); $postID = $_POST['id']; // $result = nsPublishTo($id, 'FB', true);
310
- $options = get_option('NS_SNAutoPoster'); foreach ($options['fb'] as $ii=>$fbo) if ($ii==$_POST['nid']) { $fbo['ii'] = $ii; $fbo['pType'] = 'aj';
311
- $fbpo = get_post_meta($postID, 'snapFB', true); /* echo $postID."|"; echo $fbpo; */ $fbpo = maybe_unserialize($fbpo); // prr($fbpo);
312
- if (is_array($fbpo) && isset($fbpo[$ii]) && is_array($fbpo[$ii]) ){ $ntClInst = new nxs_snapClassFB(); $fbo = $ntClInst->adjMetaOpt($fbo, $fbpo[$ii]); } //prr($fbo);
313
- if ($_POST['ri']=='1') { nxs_getBackFBComments($postID, $fbo, $fbpo[$ii]); die(); } else {
314
- $result = nxs_doPublishToFB($postID, $fbo); if ($result == '200') die("Your post has been successfully sent to FaceBook."); else die($result);
315
- }
316
- }
317
- }
318
- }
319
-
320
- if (!function_exists("nxs_doPublishToFB")) { //## Second Function to Post to FB
321
- function nxs_doPublishToFB($postID, $options){ global $ShownAds; $ntCd = 'FB'; $ntCdL = 'fb'; $ntNm = 'Facebook'; $dsc = '';
322
- if (!class_exists('nxs_class_SNAP_FB')) { nxs_addToLogN('E', 'Error', $ntCd, '-=ERROR=- No Facebook API Lib Detected', ''); return "No Facebook API Lib Detected";}
323
-
324
- $fbWhere = 'feed'; $page_id = $options['fbPgID']; if (isset($ShownAds)) $ShownAdsL = $ShownAds; $addParams = nxs_makeURLParams(array('NTNAME'=>$ntNm, 'NTCODE'=>$ntCd, 'POSTID'=>$postID, 'ACCNAME'=>$options['nName']));
325
- //## Some Common stuff
326
- $ii = $options['ii']; if (!isset($options['pType'])) $options['pType'] = 'im'; if ($options['pType']=='sh') sleep(rand(1, 10));
327
- $logNT = '<span style="color:#0000FF">Facebook</span> - '.$options['nName'];
328
- $snap_ap = get_post_meta($postID, 'snap'.$ntCd, true); $snap_ap = maybe_unserialize($snap_ap);
329
- if ($options['pType']!='aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
330
- $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted!='2') {
331
- nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:'.$postID, 'Already posted. No reason for posting duplicate'.' |'.$options['pType']); return;
332
- }
333
- }
334
- //## Make the post
335
- if (isset($options['qTLng'])) $lng = $options['qTLng']; else $lng = ''; if (!isset($options['fbAppPageAuthToken'])) $options['fbAppPageAuthToken'] = '';
336
- $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle=='') $blogTitle = home_url();
337
- //## Initiate Posting Array
338
- $message = array('message'=>'', 'link'=>'', 'title'=>'', 'description'=>'', 'imageURL'=>'', 'videoURL'=>'', 'siteName'=>$blogTitle);
339
-
340
- if ($postID=='0') { $message['message'] = 'Test Post, Please Ignore';
341
- $message['description'] = 'Test Post, Description'; $message['title'] = 'Test Post - Title'; $message['link'] = home_url();
342
- } else { $post = get_post($postID); if(!$post) return; $msg = nsFormatMessage($options['fbMsgFormat'], $postID, $addParams);
343
- $isAttachFB = $options['fbAttch']; $fbPostType = $options['fbPostType']; $isAttachVidFB = $options['fbAttchAsVid'];
344
- nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted'=>'1')); $extInfo = ' | PostID: '.$postID." - ".nxs_doQTrans($post->post_title, $lng).' |'.$options['pType'];
345
- if (($isAttachFB=='1' || $isAttachFB=='2' || $fbPostType=='A')) $imgURL = nxs_getPostImage($postID, 'medium'); // prr($options); echo "PP - ".$postID; prr($src);
346
- if ($fbPostType=='I') $imgURL = nxs_getPostImage($postID, 'full'); // prr($options); echo "PP - ".$postID; prr($src);
347
- if (($isAttachFB=='1' || $fbPostType=='A' || $fbPostType=='S')){
348
- //## AUTO - Get Post Descr from SEO Plugins or make it.
349
- if (trim($options['fbMsgAFrmt'])!='') {$dsc = nsFormatMessage($options['fbMsgAFrmt'], $postID, $addParams);} else { if (function_exists('aioseop_mrt_fix_meta') && $dsc=='') $dsc = trim(get_post_meta($postID, '_aioseop_description', true));
350
- if (function_exists('wpseo_admin_init') && $dsc=='') $dsc = trim(get_post_meta($postID, '_yoast_wpseo_opengraph-description', true));
351
- if (function_exists('wpseo_admin_init') && $dsc=='') $dsc = trim(get_post_meta($postID, '_yoast_wpseo_metadesc', true));
352
- if ($dsc=='') $dsc = trim(apply_filters('the_content', nxs_doQTrans($post->post_excerpt, $lng))); if ($dsc=='') $dsc = trim(nxs_doQTrans($post->post_excerpt, $lng));
353
- if ($dsc=='') $dsc = trim(apply_filters('the_content', nxs_doQTrans($post->post_content, $lng))); if ($dsc=='') $dsc = trim(nxs_doQTrans($post->post_content, $lng));
354
- if ($dsc=='') $dsc = get_bloginfo('description');
355
- }
356
- $dsc = strip_tags($dsc); $dsc = nxs_decodeEntitiesFull($dsc); $dsc = nsTrnc($dsc, 900, ' ');
357
- }
358
-
359
- $postSubtitle = home_url(); $msg = str_replace('<br>', "\n", $msg); $msg = str_replace('<br/>', "\n", $msg); $msg = str_replace('<br />', "\n", $msg);
360
- $msg = strip_tags($msg); $msg = nxs_decodeEntitiesFull($msg);
361
-
362
- if ($isAttachVidFB=='1') {$vids = nsFindVidsInPost($post, false); if (count($vids)>0) {
363
- if (strlen($vids[0])==11) { $vidURL = 'http://www.youtube.com/v/'.$vids[0]; $imgURL = nsGetYTThumb($vids[0]); }
364
- if (strlen($vids[0])==8) { $vidURL = 'https://secure.vimeo.com/moogaloop.swf?clip_id='.$vids[0].'&autoplay=1';
365
- $apiURL = "http://vimeo.com/api/v2/video/".$vids[0].".json?callback=showThumb"; $json = wp_remote_get($apiURL);
366
- if (!is_wp_error($json)) { $json = $json['body']; $json = str_replace('showThumb(','',$json); $json = str_replace('])',']',$json); $json = json_decode($json, true); $imgURL = $json[0]['thumbnail_large']; }
367
- }
368
- }}
369
- $message = array('message'=>$msg, 'link'=>get_permalink($postID), 'title'=>nxs_doQTrans($post->post_title, $lng), 'description'=>$dsc, 'imageURL'=>$imgURL, 'videoURL'=>$vidURL, 'siteName'=>$blogTitle);
370
- } // prr($mssg); // prr($options); // prr($facebook); echo "/$page_id/feed";
371
- if (isset($ShownAds)) $ShownAds = $ShownAdsL; // FIX for the quick-adsense plugin
372
-
373
- //## Actual Post
374
- $ntToPost = new nxs_class_SNAP_FB(); $ret = $ntToPost->doPostToNT($options, $message);
375
- //## Process Results
376
- if (!is_array($ret) || $ret['isPosted']!='1') { //## Error
377
- if ($postID=='0') prr($ret); nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.print_r($ret, true), $extInfo);
378
- } else { // ## All Good - log it.
379
- if ($postID=='0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo _e('OK - Message Posted, please see your '.$logNT.' Page. ', 'nxs_snap'); }
380
- else { nxs_addToRI($postID); nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted'=>'1', 'pgID'=>$ret['postID'], 'pDate'=>date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); }
381
- }
382
- //## Return Result
383
- if ($ret['isPosted']=='1') return 200; else return print_r($ret, true);
384
- }
385
- }
386
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
387
  ?>
1
+ <?php
2
+ //## NextScripts Facebook Connection Class
3
+ $nxs_snapAvNts[] = array('code'=>'FB', 'lcode'=>'fb', 'name'=>'Facebook');
4
+
5
+ if (!class_exists("nxs_snapClassFB")) { class nxs_snapClassFB {
6
+ //#### Show Common Settings
7
+ function showGenNTSettings($ntOpts){ global $nxs_snapThisPageUrl, $nxs_plurl; $ntInfo = array('code'=>'FB', 'lcode'=>'fb', 'name'=>'Facebook', 'defNName'=>'dlUName', 'tstReq' => true);
8
+ if ( isset($_GET['code']) && $_GET['code']!='' && (isset($_GET['auth']) && $_GET['auth']=='fb') && ((!isset($_GET['action'])) || $_GET['action']!='gPlusAuth')){ $at = $_GET['code']; echo "-= This is normal technical authorization info that will dissapear (Unless you get some errors) =- <br/><br/><br/>";
9
+ //$fbo = array('wfa'=> 1339160000); //foreach ($ntOpts as $two) { if (isset($two['wfa']) && $two['wfa']>$fbo['wfa']) $fbo = $two; }
10
+ $fbo = $ntOpts[$_GET['acc']]; $wprg = array(); $response = wp_remote_get('https://graph.facebook.com/nextscripts', $wprg);
11
+ if( is_wp_error( $response) && isset($response->errors['http_request_failed']) && stripos($response->errors['http_request_failed'][0], 'SSL')!==false ) { prr($response->errors); $wprg['sslverify'] = false; }
12
+ if (isset($fbo['fbPgID'])){ echo "-="; prr($fbo);// die();
13
+ $response = wp_remote_get('https://graph.facebook.com/oauth/access_token?client_id='.$fbo['fbAppID'].'&redirect_uri='.urlencode($nxs_snapThisPageUrl.'&auth=fb&acc='.$_GET['acc']).'&client_secret='.$fbo['fbAppSec'].'&code='.$at, $wprg);
14
+ //prr('https://graph.facebook.com/oauth/access_token?client_id='.$fbo['fbAppID'].'&redirect_uri='.urlencode($nxs_snapThisPageUrl).'&client_secret='.$fbo['fbAppSec'].'&code='.$at);
15
+ if ( (is_object($response) && (isset($response->errors))) || (is_array($response) && stripos($response['body'],'"error":')!==false )) { prr($response); die(); }
16
+ parse_str($response['body'], $params); $at = $params['access_token']; prr($response); prr($params);
17
+ $response = wp_remote_get('https://graph.facebook.com/oauth/access_token?client_secret='.$fbo['fbAppSec'].'&client_id='.$fbo['fbAppID'].'&grant_type=fb_exchange_token&fb_exchange_token='.$at, $wprg);
18
+ if ((is_object($response) && isset($response->errors))) { prr($response); die();}
19
+ parse_str($response['body'], $params); $at = $params['access_token']; $fbo['fbAppAuthToken'] = $at;
20
+ require_once ('apis/facebook.php'); echo "-= Using API =-<br/>";
21
+ $facebook = new NXS_Facebook(array( 'appId' => $fbo['fbAppID'], 'secret' => $fbo['fbAppSec'], 'cookie' => true));
22
+ $facebook -> setAccessToken($fbo['fbAppAuthToken']); $user = $facebook->getUser(); echo "USER:"; prr($user);
23
+ if ($user) {
24
+ try { $page_id = $fbo['fbPgID']; echo "-= Authorizing Page =-";
25
+ if ( !is_numeric($page_id) && stripos($fbo['fbURL'], '/groups/')!=false) { //$fbPgIDR = wp_remote_get('nxs.php?g='.$fbo['fbURL']); // TODO - how to replace
26
+ $fbPgIDR = trim($fbPgIDR['body']); $page_id = $fbPgIDR!=''?$fbPgIDR:$page_id;
27
+ } $page_info = $facebook->api("/$page_id?fields=access_token");
28
+ if( !empty($page_info['access_token']) ) { $fbo['fbAppPageAuthToken'] = $page_info['access_token']; }
29
+ } catch (NXS_FacebookApiException $e) { $errMsg = $e->getMessage(); prr($errMsg);
30
+ if ( stripos($errMsg, 'Unknown fields: access_token')!==false) { $fbo['fbAppPageAuthToken'] = $fbo['fbAppAuthToken']; } else {
31
+ if (stripos($errMsg, 'Unsupported get request')!==false) echo "<b style='color:red;'>Error </b>: Your Facebook URL ( <i>".$fbo['fbURL']."</i> ) is either incorrect or authorzing user don't have rights to post there.<br/>";
32
+ echo 'Reported Error: ', $errMsg, "\n"; die();
33
+ }
34
+ }
35
+ } else echo "Can't get Facebook User. Please login to Facebook.";
36
+
37
+ if ($user>0) { $fbo['fbAppAuthUser'] = $user;
38
+ $optionsG = get_option('NS_SNAutoPoster'); $optionsG['fb'][$_GET['acc']] = $fbo; update_option('NS_SNAutoPoster', $optionsG);
39
+ ?><script type="text/javascript">window.location = "<?php echo $nxs_snapThisPageUrl; ?>"</script>
40
+ <?php } die(); }
41
+ }
42
+ ?>
43
+ <div class="nxs_box">
44
+ <div class="nxs_box_header">
45
+ <div class="nsx_iconedTitle" style="margin-bottom:1px;background-image:url(<?php echo $nxs_plurl;?>img/<?php echo $ntInfo['lcode']; ?>16.png);"><?php echo $ntInfo['name']; ?>
46
+ <?php $cbo = count($ntOpts); ?> <?php wp_nonce_field( 'ns'.$ntInfo['code'], 'ns'.$ntInfo['code'].'_wpnonce' ); ?>
47
+ <?php if ($cbo>1){ ?><div class="nsBigText"><?php echo "(".($cbo=='0'?'No':$cbo)." "; _e('accounts', 'nxs_snap'); echo ")"; ?></div><?php } ?>
48
+ </div>
49
+ </div>
50
+ <div class="nxs_box_inside">
51
+ <?php foreach ($ntOpts as $indx=>$pbo){ if (trim($pbo['nName']=='')) $pbo['nName'] = str_ireplace('https://www.facebook.com','', str_ireplace('http://www.facebook.com','', $pbo['fbURL']));
52
+ if (!isset($pbo[$ntInfo['lcode'].'OK']) || $pbo[$ntInfo['lcode'].'OK']=='') $pbo[$ntInfo['lcode'].'OK'] = (isset($pbo['fbAppAuthUser']) && $pbo['fbAppAuthUser']>1)?'1':''; ?>
53
+ <p style="margin:0px;margin-left:5px;">
54
+ <input value="1" name="<?php echo $ntInfo['lcode']; ?>[<?php echo $indx; ?>][apDo<?php echo $ntInfo['code']; ?>]" onchange="doShowHideBlocks('<?php echo $ntInfo['code']; ?>');" type="checkbox" <?php if ((int)$pbo['do'.$ntInfo['code']] == 1) echo "checked"; ?> /> <?php if ((int)$pbo['catSel'] == 1) { ?> <span onmouseout="nxs_hidePopUpInfo('popOnlyCat');" onmouseover="nxs_showPopUpInfo('popOnlyCat', event);"><?php echo "*[".(substr_count($pbo['catSelEd'], ",")+1)."]*" ?></span><?php } ?>
55
+ <strong><?php _e('Auto-publish to', 'nxs_snap'); ?> <?php echo $ntInfo['name']; ?> <i style="color: #005800;"><?php if($pbo['nName']!='') echo "(".$pbo['nName'].")"; ?></i></strong>
56
+ &nbsp;&nbsp;<?php if ($ntInfo['tstReq'] && (!isset($pbo[$ntInfo['lcode'].'OK']) || $pbo[$ntInfo['lcode'].'OK']=='')){ ?><b style="color: #800000"><?php _e('Attention required. Unfinished setup', 'nxs_snap'); ?> ==&gt;</b><?php } ?><a id="do<?php echo $ntInfo['code'].$indx; ?>A" href="#" onclick="doShowHideBlocks2('<?php echo $ntInfo['code'].$indx; ?>');return false;">[<?php _e('Show Settings', 'nxs_snap'); ?>]</a>&nbsp;&nbsp;
57
+ <a href="#" onclick="doDelAcct('<?php echo $ntInfo['lcode']; ?>', '<?php echo $indx; ?>', '<?php if (isset($pbo['bgBlogID'])) echo $pbo['nName']; ?>');return false;">[<?php _e('Remove Account', 'nxs_snap'); ?>]</a>
58
+ </p><?php $this->showNTSettings($indx, $pbo);
59
+ }?>
60
+ </div>
61
+ </div> <?php
62
+
63
+
64
+ }
65
+ //#### Show NEW Settings Page
66
+ function showNewNTSettings($mfbo){ $fbo = array('nName'=>'', 'doFB'=>'1', 'fbURL'=>'', 'fbAppID'=>'', 'imgUpl'=>'1', 'fbPostType'=>'A', 'fbMsgAFormat'=>'', 'fbAppSec'=>'', 'fbAttch'=>'1', 'fbPgID'=>'', 'fbAppAuthUser'=>'', 'fbMsgFormat'=>__('New post (%TITLE%) has been published on %SITENAME%', 'nxs_snap') ); $this->showNTSettings($mfbo, $fbo, true);}
67
+ //#### Show Unit Settings
68
+ function showNTSettings($ii, $fbo, $isNew=false){ global $nxs_plurl, $nxs_snapThisPageUrl, $plgn_NS_SNAutoPoster; if ((int)$fbo['fbAttch']==0 && (!isset($fbo['trPostType']) || $fbo['trPostType']=='')) $fbo['trPostType'] = 'T';
69
+ if (!isset($plgn_NS_SNAutoPoster)) return; $gOptions = $plgn_NS_SNAutoPoster->nxs_options;
70
+ if (!isset($fbo['nHrs'])) $fbo['nHrs'] = 0; if (!isset($fbo['nMin'])) $fbo['nMin'] = 0; if (!isset($fbo['catSel'])) $fbo['catSel'] = 0; if (!isset($fbo['catSelEd'])) $fbo['catSelEd'] = '';
71
+ if (!isset($fbo['nDays'])) $fbo['nDays'] = 0; if (!isset($fbo['qTLng'])) $fbo['qTLng'] = ''; if (!isset($fbo['fbMsgAFrmt'])) $fbo['fbMsgAFrmt'] = '';
72
+ if (!isset($fbo['riComments'])) $fbo['riComments'] = ''; if (!isset($fbo['riCommentsAA'])) $fbo['riCommentsAA'] = '';
73
+ ?>
74
+ <div id="doFB<?php echo $ii; ?>Div" class="insOneDiv<?php if ($isNew) echo " clNewNTSets"; ?>" style="background-image: url(<?php echo $nxs_plurl; ?>img/fb-bg.png); background-position:90% 10%;"> <input type="hidden" name="apDoSFB<?php echo $ii; ?>" value="0" id="apDoSFB<?php echo $ii; ?>" />
75
+ <?php if ($isNew) { ?> <input type="hidden" name="fb[<?php echo $ii; ?>][apDoFB]" value="1" id="apDoNewFB<?php echo $ii; ?>" /> <?php } ?>
76
+
77
+ <div class="nsx_iconedTitle" style="float: right; max-width: 322px; text-align: right; background-image: url(<?php echo $nxs_plurl; ?>img/fb16.png);"><a style="font-size: 12px;" target="_blank" href="http://www.nextscripts.com/setup-installation-facebook-social-networks-auto-poster-wordpress/"><?php $nType="Facebook"; printf( __( 'Detailed %s Installation/Configuration Instructions', 'nxs_snap' ), $nType); ?></a><br/>
78
+ <span style="font-size: 10px;"><?php _e('Please use in your Facebook App:', 'nxs_snap'); ?> <br/> URL: <em style="font-size: 10px; color:#CB4B16;">http://<?php echo $_SERVER["SERVER_NAME"] ?></em> <br/>Domain: <em style="font-size: 10px; color:#CB4B16;"><?php echo $_SERVER["SERVER_NAME"] ?></em> </span>
79
+
80
+ </div>
81
+
82
+ <div style="width:100%;"><strong><?php _e('Account Nickname', 'nxs_snap'); ?>:</strong> <i><?php _e('Just so you can easely identify it', 'nxs_snap'); ?></i> </div><input name="fb[<?php echo $ii; ?>][nName]" id="fbnName<?php echo $ii; ?>" style="font-weight: bold; color: #005800; border: 1px solid #ACACAC; width: 40%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($fbo['nName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /><br/>
83
+ <?php echo nxs_addQTranslSel('fb', $ii, $fbo['qTLng']); ?>
84
+ <?php echo nxs_addPostingDelaySel('fb', $ii, $fbo['nHrs'], $fbo['nMin'], $fbo['nDays']); ?>
85
+
86
+ <?php if (!$isNew) { ?>
87
+ <div style="width:100%;"><strong><?php _e('Categories', 'nxs_snap'); ?>:</strong>
88
+ <input value="0" id="catSelA<?php echo $ii; ?>" type="radio" name="fb[<?php echo $ii; ?>][catSel]" <?php if ((int)$fbo['catSel'] != 1) echo "checked"; ?> /> All
89
+ <input value="1" id="catSelSFB<?php echo $ii; ?>" type="radio" name="fb[<?php echo $ii; ?>][catSel]" <?php if ((int)$fbo['catSel'] == 1) echo "checked"; ?> /> <a href="#" style="text-decoration: none;" class="showCats" id="nxs_SCA_FB<?php echo $ii; ?>" onclick="jQuery('#catSelSFB<?php echo $ii; ?>').attr('checked', true); jQuery('#tmpCatSelNT').val('FB<?php echo $ii; ?>'); nxs_markCats( jQuery('#nxs_SC_FB<?php echo $ii; ?>').val() ); jQuery('#showCatSel').bPopup({ modalClose: false, appendTo: '#nsStForm', opacity: 0.6, follow: [false, false], position: [75, 'auto']}); return false;">Selected<?php if ($fbo['catSelEd']!='') echo "[".(substr_count($fbo['catSelEd'], ",")+1)."]"; ?></a>
90
+ <input type="hidden" name="fb[<?php echo $ii; ?>][catSelEd]" id="nxs_SC_FB<?php echo $ii; ?>" value="<?php echo $fbo['catSelEd']; ?>" />
91
+ <br/><i><?php _e('Only selected categories will be autoposted to this account', 'nxs_snap'); ?></i></div>
92
+ <br/>
93
+ <?php } ?>
94
+ <div style="width:100%;"><strong style="font-size: 16px;">Facebook Settings:</strong> </div>
95
+
96
+ <div style="width:100%;"><strong>Facebook URL:</strong> </div>
97
+ <p style="font-size: 11px; margin: 0px;"><?php _e('Could be your Facebook Profile, Facebook Page, Facebook Group', 'nxs_snap'); ?></p>
98
+ <input name="fb[<?php echo $ii; ?>][apFBURL]" id="apFBURL" style="width: 50%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($fbo['fbURL'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
99
+ <div style="width:100%;"><strong>Facebook App ID:</strong> </div><input name="fb[<?php echo $ii; ?>][apFBAppID]" id="apFBAppID" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($fbo['fbAppID'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
100
+ <div style="width:100%;"><strong>Facebook App Secret:</strong> </div><input name="fb[<?php echo $ii; ?>][apFBAppSec]" id="apFBAppSec" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($fbo['fbAppSec'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /><br/><br/>
101
+ <div id="altFormat">
102
+ <div style="width:100%;"><strong id="altFormatText"><?php _e('Message text Format', 'nxs_snap'); ?>:</strong> (<a href="#" id="apFBMsgFrmt<?php echo $ii; ?>HintInfo" onclick="mxs_showHideFrmtInfo('apFBMsgFrmt<?php echo $ii; ?>'); return false;"><?php _e('Show format info', 'nxs_snap'); ?></a>)</div>
103
+
104
+ <textarea cols="150" rows="3" id="fb<?php echo $ii; ?>SNAPformat" name="fb[<?php echo $ii; ?>][apFBMsgFrmt]" style="width:51%;max-width: 610px;" onfocus="jQuery('#fb<?php echo $ii; ?>SNAPformat').attr('rows', 6); mxs_showFrmtInfo('apFBMsgFrmt<?php echo $ii; ?>');"><?php _e(apply_filters('format_to_edit', htmlentities($fbo['fbMsgFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?></textarea> <?php nxs_doShowHint("apFBMsgFrmt".$ii); ?>
105
+ <br/>
106
+ </div><br/>
107
+ <div style="width:100%;"><strong style="font-size: 16px;" id="altFormatText">Post Type:</strong>&lt;-- (<a id="showShAtt" onmouseout="hidePopShAtt('<?php echo $ii; ?>X');" onmouseover="showPopShAtt('<?php echo $ii; ?>X', event);" onclick="return false;" class="underdash" href="http://www.nextscripts.com/blog/"><?php _e('What\'s the difference?', 'nxs_snap'); ?></a>) </div>
108
+ <div style="margin-left: 10px;">
109
+
110
+ <input type="radio" name="fb[<?php echo $ii; ?>][fbPostType]" value="T" <?php if ($fbo['fbPostType'] == 'T') echo 'checked="checked"'; ?> /> <?php _e('Text Post', 'nxs_snap'); ?> - <i><?php _e('just text message', 'nxs_snap'); ?></i><br/>
111
+
112
+ <input type="radio" name="fb[<?php echo $ii; ?>][fbPostType]" value="I" <?php if ($fbo['fbPostType'] == 'I') echo 'checked="checked"'; ?> /> <?php _e('Image Post', 'nxs_snap'); ?> - <i><?php _e('big image with text message', 'nxs_snap'); ?></i><br/>
113
+ <div style="width:100%; margin-left: 15px;"><strong><?php _e('Upload Images to', 'nxs_snap'); ?>:&nbsp;</strong>
114
+ <input value="2" id="apFBImgUplAPP<?php echo $ii; ?>" type="radio" name="fb[<?php echo $ii; ?>][apFBImgUpl]" <?php if ((int)$fbo['imgUpl'] == 2) echo "checked"; ?> /> <?php _e('App Album', 'nxs_snap'); ?> .. <?php _e('or', 'nxs_snap'); ?> ..
115
+ <input value="1" id="apFBImgUplTML<?php echo $ii; ?>" type="radio" name="fb[<?php echo $ii; ?>][apFBImgUpl]" <?php if ((int)$fbo['imgUpl'] != 2) echo "checked"; ?> />
116
+ <?php _e('Timeline', 'nxs_snap'); ?> &lt;-- (<a id="showShAtt" onmouseout="hidePopShAtt('<?php echo $ii; ?>I');" onmouseover="showPopShAtt('<?php echo $ii; ?>I', event);" onclick="return false;" class="underdash" href="http://www.nextscripts.com/blog/"><?php _e('What\'s the difference?', 'nxs_snap'); ?></a>)
117
+ </div>
118
+
119
+ <input type="radio" name="fb[<?php echo $ii; ?>][fbPostType]" value="A" <?php if ( !isset($fbo['fbPostType']) || $fbo['fbPostType'] == '' || $fbo['fbPostType'] == 'A') echo 'checked="checked"'; ?> /> <?php _e('Text Post with "attached" link', 'nxs_snap'); ?><br/>
120
+
121
+ <div style="width:100%; margin-left: 15px;"><strong><?php _e('Link attachment type', 'nxs_snap'); ?>:&nbsp;</strong> <input value="2" id="apFBAttchShare<?php echo $ii; ?>" type="radio" name="fb[<?php echo $ii; ?>][apFBAttch]" <?php if ((int)$fbo['fbAttch'] == 2) echo "checked"; ?> />
122
+ <?php _e('Share a link to your blogpost', 'nxs_snap'); ?> .. <?php _e('or', 'nxs_snap'); ?> ..
123
+ <input value="1" id="apFBAttch<?php echo $ii; ?>" type="radio" name="fb[<?php echo $ii; ?>][apFBAttch]" <?php if ((int)$fbo['fbAttch'] == 1) echo "checked"; ?> />
124
+ <?php _e('Attach your blogpost', 'nxs_snap'); ?> &lt;-- (<a id="showShAtt" onmouseout="hidePopShAtt('<?php echo $ii; ?>');" onmouseover="showPopShAtt('<?php echo $ii; ?>', event);" onclick="return false;" class="underdash" href="http://www.nextscripts.com/blog/"><?php _e('What\'s the difference?', 'nxs_snap'); ?></a>)
125
+ <div style="margin-bottom: 5px; margin-left: 10px; "><input value="1" id="apFBAttchAsVid" type="checkbox" name="fb[<?php echo $ii; ?>][apFBAttchAsVid]" <?php if (isset($fbo['fbAttchAsVid']) && (int)$fbo['fbAttchAsVid'] == 1) echo "checked"; ?> /> <strong><?php _e('If post has video use it as an attachment thumbnail.', 'nxs_snap'); ?></strong> <i><?php _e('Video will be used for an attachment thumbnail instead of featured image. Only Youtube is supported at this time.', 'nxs_snap'); ?></i>
126
+ <br/></div>
127
+ <strong><?php _e('Attachment Text Format', 'nxs_snap'); ?>:</strong><br/>
128
+ <input value="1" id="apFBMsgAFrmtA<?php echo $ii; ?>" <?php if (trim($fbo['fbMsgAFrmt'])=='') echo "checked"; ?> onchange="if (jQuery(this).is(':checked')) { jQuery('#apFBMsgAFrmtDiv<?php echo $ii; ?>').hide(); jQuery('#apFBMsgAFrmt<?php echo $ii; ?>').val(''); }else jQuery('#apFBMsgAFrmtDiv<?php echo $ii; ?>').show();" type="checkbox" name="fb[<?php echo $ii; ?>][apFBMsgAFrmtA]"/> <strong><?php _e('Auto', 'nxs_snap'); ?></strong>
129
+ <i> - <?php _e('Recommended. Info from SEO Plugins will be used, then post excerpt, then post text', 'nxs_snap'); ?> </i><br/>
130
+ <div id="apFBMsgAFrmtDiv<?php echo $ii; ?>" style="<?php if ($fbo['fbMsgAFrmt']=='') echo "display:none;"; ?>" >&nbsp;&nbsp;&nbsp; <?php _e('Set your own format', 'nxs_snap'); ?>:<input name="fb[<?php echo $ii; ?>][apFBMsgAFrmt]" id="apFBMsgAFrmt<?php echo $ii; ?>" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($fbo['fbMsgAFrmt'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /><br/></div>
131
+ </div><br/>
132
+ </div>
133
+ <div style="width:100%;"><strong style="font-size: 16px;"><?php _e('Facebook Comments:', 'nxs_snap'); ?></strong> </div>
134
+ <div style="margin-bottom: 5px; margin-left: 10px; ">
135
+ <p style="font-size: 11px; margin: 0px;"><?php _e('Plugin could grab comments from Facebook and import them as Wordpress Comments', 'nxs_snap'); ?></p>
136
+
137
+ <?php if ( $gOptions['riActive'] == '1' ) { ?>
138
+ <input value="1" id="apFBMsgAFrmtA<?php echo $ii; ?>" <?php if (trim($fbo['riComments'])=='1') echo "checked"; ?> type="checkbox" name="fb[<?php echo $ii; ?>][riComments]"/> <strong><?php _e('Import Facebook Comments', 'nxs_snap'); ?></strong>
139
+ <br/>
140
+ <div style="margin-bottom: 5px; margin-left: 10px; ">
141
+ <input value="1" id="apFBMsgAFrmtA<?php echo $ii; ?>" <?php if (trim($fbo['riCommentsAA'])=='1') echo "checked"; ?> type="checkbox" name="fb[<?php echo $ii; ?>][riCommentsAA]"/> <strong><?php _e('Auto-approve imported comments', 'nxs_snap'); ?></strong></div>
142
+
143
+ <?php } else { echo "<br/>"; _e('Please activate the "Comments Import" from SNAP Settings - Other Settings', 'nxs_snap'); } ?>
144
+
145
+ </div>
146
+
147
+ <br/><br/>
148
+
149
+ <div class="popShAtt" style="z-index: 9999; width: 350px;" id="popShAtt<?php echo $ii; ?>I"><h3><?php _e('Where to upload Images', 'nxs_snap'); ?></h3> <b><?php _e('(App Album)', 'nxs_snap'); ?></b> <?php _e('Facebook automatically creates an album for your app. Images will be grouped there as in any regular album.', 'nxs_snap'); ?> <br/><br/><b><?php _e('(Timeline)', 'nxs_snap'); ?></b> <?php _e('Images will be posted to the special "Wall/Timeline" album and won\'t be grouped. "Wall/Timeline" album must exist. It\'s created when first image posted to timeline manually.', 'nxs_snap'); ?></div>
150
+ <div class="popShAtt" style="z-index: 9999" id="popShAtt<?php echo $ii; ?>"><h3><?php _e('Two ways of attaching post on Facebook', 'nxs_snap'); ?></h3><img src="<?php echo $nxs_plurl; ?>img/fb2wops.png" width="600" height="257" alt="<?php _e('Two ways of attaching post on Facebook', 'nxs_snap'); ?>"/></div>
151
+ <div class="popShAtt" style="z-index: 9999" id="popShAtt<?php echo $ii; ?>X"><h3><?php _e('Facebook Post Types', 'nxs_snap'); ?></h3><img src="<?php echo $nxs_plurl; ?>img/fbPostTypesDiff6.png" width="600" height="398" alt="<?php _e('Facebook Post Types', 'nxs_snap'); ?>"/></div>
152
+
153
+
154
+
155
+
156
+ <?php if ($fbo['fbPgID']!='') {?><div style="width:100%;"><strong>Facebook Page ID:</strong> <?php _e(apply_filters('format_to_edit', htmlentities($fbo['fbPgID'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?> </div><?php } ?>
157
+ <?php
158
+ if($fbo['fbAppSec']=='') { ?>
159
+ <b><?php _e('Authorize Your Facebook Account', 'nxs_snap'); ?></b> <?php _e('Please click "Update Settings" to be able to Authorize your account.', 'nxs_snap'); ?>
160
+ <?php } else { if(isset($fbo['fbAppAuthUser']) && $fbo['fbAppAuthUser']>0) { ?>
161
+ <?php _e('Your Facebook Account has been authorized.', 'nxs_snap'); ?> User ID: <?php _e(apply_filters('format_to_edit', htmlentities($fbo['fbAppAuthUser'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>.
162
+ <?php _e('You can', 'nxs_snap'); ?> Re- <?php } ?>
163
+ <a href="https://www.facebook.com/dialog/oauth?client_id=<?php echo trim($fbo['fbAppID']);?>&client_secret=<?php echo trim($fbo['fbAppSec']);?>&scope=publish_stream,user_photos,photo_upload,friends_photos,offline_access,read_stream,manage_pages,user_groups,friends_groups&redirect_uri=<?php echo trim(urlencode($nxs_snapThisPageUrl.'&auth=fb&acc='.$ii));?>">Authorize Your Facebook Account</a>
164
+ <?php if (!isset($fbo['fbAppAuthUser']) || $fbo['fbAppAuthUser']<1) { ?> <div class="blnkg">&lt;=== <?php _e('Authorize your account', 'nxs_snap'); ?> ===</div>
165
+ <br/><br/><i> <?php _e('If you get Facebook message:', 'nxs_snap'); ?> <b>"Error. An error occurred. Please try again later."</b> or <b>"Error 191"</b> <?php _e('please make sure that domain name in your Facebook App matches your website domain exactly. Please note that www. and non www. versions are different domains.', 'nxs_snap'); ?></i> <?php }?>
166
+ <?php } ?>
167
+
168
+ <?php if(isset($fbo['fbAppAuthUser']) && $fbo['fbAppAuthUser']>0) { ?>
169
+ <?php wp_nonce_field( 'rePostToFB', 'rePostToFB_wpnonce' ); ?>
170
+ <br/><br/><b><?php _e('Test your settings', 'nxs_snap'); ?>:</b>&nbsp;&nbsp;&nbsp; <a href="#" class="NXSButton" onclick="testPost('FB','<?php echo $ii; ?>'); return false;"><?php printf( __( 'Submit Test Post to %s', 'nxs_snap' ), $nType); ?></a>
171
+ <?php }?>
172
+ <div class="submit"><input type="submit" class="button-primary" name="update_NS_SNAutoPoster_settings" value="<?php _e('Update Settings', 'nxs_snap') ?>" /></div>
173
+
174
+ </div>
175
+ <?php
176
+
177
+ }
178
+ //#### Set Unit Settings from POST
179
+ function setNTSettings($post, $options){ global $nxs_snapThisPageUrl; $code = 'FB'; $lcode = 'fb';
180
+ foreach ($post as $ii => $pval){
181
+ if (isset($pval['apFBAppID']) && $pval['apFBAppID']!='') { if (!isset($options[$ii])) $options[$ii] = array();
182
+ if (isset($pval['apDoFB'])) $options[$ii]['doFB'] = $pval['apDoFB']; else $options[$ii]['doFB'] = 0;
183
+ if (isset($pval['nName'])) $options[$ii]['nName'] = trim($pval['nName']);
184
+ if (isset($pval['apFBAppID'])) $options[$ii]['fbAppID'] = trim($pval['apFBAppID']);
185
+ if (isset($pval['apFBAppSec'])) $options[$ii]['fbAppSec'] = trim($pval['apFBAppSec']);
186
+
187
+ if (isset($pval['catSel'])) $options[$ii]['catSel'] = trim($pval['catSel']);
188
+ if ($options[$ii]['catSel']=='1' && trim($pval['catSelEd'])!='') $options[$ii]['catSelEd'] = trim($pval['catSelEd']); else $options[$ii]['catSelEd'] = '';
189
+
190
+ if (isset($pval['fbPostType'])) $options[$ii]['fbPostType'] = trim($pval['fbPostType']);
191
+ if (isset($pval['apFBAttch'])) $options[$ii]['fbAttch'] = $pval['apFBAttch']; else $options[$ii]['fbAttch'] = 0;
192
+ if (isset($pval['apFBAttchAsVid'])) $options[$ii]['fbAttchAsVid'] = $pval['apFBAttchAsVid']; else $options[$ii]['fbAttchAsVid'] = 0;
193
+
194
+ if (isset($pval['apFBImgUpl'])) $options[$ii]['imgUpl'] = $pval['apFBImgUpl']; else $options[$ii]['imgUpl'] = 0;
195
+
196
+ if (isset($pval['apFBMsgFrmt'])) $options[$ii]['fbMsgFormat'] = trim($pval['apFBMsgFrmt']);
197
+ if (isset($pval['apFBMsgAFrmt'])) $options[$ii]['fbMsgAFrmt'] = trim($pval['apFBMsgAFrmt']);
198
+
199
+ if (isset($pval['riComments'])) $options[$ii]['riComments'] = $pval['riComments']; else $options[$ii]['riComments'] = 0;
200
+ if (isset($pval['riCommentsAA'])) $options[$ii]['riCommentsAA'] = $pval['riCommentsAA']; else $options[$ii]['riCommentsAA'] = 0;
201
+
202
+ if (isset($pval['delayDays'])) $options[$ii]['nDays'] = trim($pval['delayDays']);
203
+ if (isset($pval['delayHrs'])) $options[$ii]['nHrs'] = trim($pval['delayHrs']); if (isset($pval['delayMin'])) $options[$ii]['nMin'] = trim($pval['delayMin']);
204
+ if (isset($pval['qTLng'])) $options[$ii]['qTLng'] = trim($pval['qTLng']);
205
+
206
+ if (isset($pval['apFBURL'])) { $options[$ii]['fbURL'] = trim($pval['apFBURL']); if ( substr($options[$ii]['fbURL'], 0, 4)!='http' ) $options[$ii]['fbURL'] = 'http://'.$options[$ii]['fbURL'];
207
+ $fbPgID = $options[$ii]['fbURL']; if (substr($fbPgID, -1)=='/') $fbPgID = substr($fbPgID, 0, -1); $fbPgID = substr(strrchr($fbPgID, "/"), 1);
208
+ if (strpos($fbPgID, '?')!==false) $fbPgID = substr($fbPgID, 0, strpos($fbPgID, '?'));
209
+ $options[$ii]['fbPgID'] = $fbPgID; //echo $fbPgID;
210
+ if (strpos($options[$ii]['fbURL'], '?')!==false) $options[$ii]['fbURL'] = substr($options[$ii]['fbURL'], 0, strpos($options[$ii]['fbURL'], '?'));// prr($pval); prr($options[$ii]); // die();
211
+ }
212
+ }
213
+ } return $options;
214
+ }
215
+ //#### Show Post->Edit Meta Box Settings
216
+ function showEdPostNTSettings($ntOpts, $post){ global $nxs_plurl; $post_id = $post->ID;
217
+ foreach($ntOpts as $ii=>$ntOpt) { $pMeta = maybe_unserialize(get_post_meta($post_id, 'snapFB', true)); if (is_array($pMeta)) $ntOpt = $this->adjMetaOpt($ntOpt, $pMeta[$ii]);
218
+ $doFB = $ntOpt['doFB'] && (is_array($pMeta) || $ntOpt['catSel']!='1');
219
+ $isAvailFB = $ntOpt['fbURL']!='' && $ntOpt['fbAppID']!='' && $ntOpt['fbAppSec']!=''; $isAttachFB = $ntOpt['fbAttch']; $fbMsgFormat = htmlentities($ntOpt['fbMsgFormat'], ENT_COMPAT, "UTF-8"); $fbPostType = $ntOpt['fbPostType'];
220
+ ?>
221
+
222
+ <tr><th style="text-align:left;" colspan="2"> <?php if ( $ntOpt['catSel']=='1' && trim($ntOpt['catSelEd'])!='' ) { ?> <input type="hidden" class="nxs_SC" id="nxs_SC_FB<?php echo $ii; ?>" value="<?php echo $ntOpt['catSelEd']; ?>" /> <?php } ?>
223
+
224
+ <?php if ($isAvailFB) { ?><input class="nxsGrpDoChb" value="1" id="doFB<?php echo $ii; ?>" <?php if ($post->post_status == "publish") echo 'disabled="disabled"';?> type="checkbox" name="fb[<?php echo $ii; ?>][doFB]" <?php if ((int)$doFB == 1) echo 'checked="checked" title="def"'; ?> />
225
+ <?php if ($post->post_status == "publish") { ?> <input type="hidden" name="fb[<?php echo $ii; ?>][doFB]" value="<?php echo $doFB;?>"> <?php } ?> <?php } ?>
226
+
227
+ <div class="nsx_iconedTitle" style="display: inline; font-size: 13px; background-image: url(<?php echo $nxs_plurl; ?>img/fb16.png);">Facebook - <?php _e('publish to', 'nxs_snap') ?> (<i style="color: #005800;"><?php echo $ntOpt['nName']; ?></i>)</div></th><td><?php //## Only show RePost button if the post is "published"
228
+ if ($post->post_status == "publish" && $isAvailFB) { ?>
229
+
230
+ <input alt="<?php echo $ii; ?>" style="float: right;margin-left: 10px" onmouseout="hidePopShAtt('SV');" onmouseover="showPopShAtt('SV', event);" onclick="return false;" type="button" class="button" name="rePostToFB_repostButton" id="rePostToFB_button" value="<?php _e('Repost to Facebook', 'nxs_snap') ?>" />
231
+ <?php if ($ntOpt['riComments']=='1' && (is_array($pMeta) && is_array($pMeta[$ii]) && isset($pMeta[$ii]['pgID']) && strpos($pMeta[$ii]['pgID'],'_')!==false ) ) { ?>
232
+ <input alt="<?php echo $ii; ?>" style="float: right; " onclick="return false;" type="button" class="button" name="riToFB_repostButton" id="riToFB_button" value="<?php _e('Import Comments from Facebook', 'nxs_snap') ?>" />
233
+ <?php } ?>
234
+
235
+ <?php wp_nonce_field( 'rePostToFB', 'rePostToFB_wpnonce' ); } ?>
236
+
237
+ <?php if (is_array($pMeta) && is_array($pMeta[$ii]) && isset($pMeta[$ii]['pgID']) && strpos($pMeta[$ii]['pgID'],'_')!==false ) { $pid = explode('_', $pMeta[$ii]['pgID']);
238
+
239
+ ?> <span id="pstdFB<?php echo $ii; ?>" style="float: right;padding-top: 4px; padding-right: 10px;">
240
+ <a style="font-size: 10px;" href="http://www.facebook.com/permalink.php?story_fbid=<?php echo $pid[1].'&id='.$pid[0]; ?>" target="_blank"><?php $nType="Facebook"; printf( __( 'Posted on', 'nxs_snap' ), $nType); ?> <?php echo (isset($pMeta[$ii]['pDate']) && $pMeta[$ii]['pDate']!='')?(" (".$pMeta[$ii]['pDate'].")"):""; ?></a>
241
+ </span><?php } ?>
242
+
243
+ </td></tr>
244
+ <?php if (!$isAvailFB) { ?><tr><th scope="row" style="text-align:right; width:150px; padding-top: 5px; padding-right:10px;"></th> <td><b>Setup and Authorize your Facebook Account to AutoPost to Facebook</b>
245
+ <?php } elseif ($post->post_status != "puZblish") {?>
246
+
247
+ <tr><th scope="row" style="text-align:right; width:150px; padding-top: 5px; padding-right:10px;">
248
+
249
+ <b></b>
250
+ </th>
251
+ <td></td>
252
+ </tr>
253
+
254
+ <tr><th scope="row" style="text-align:right; width:150px; vertical-align:top; padding-top: 0px; padding-right:10px;"> <?php _e('Post Type:', 'nxs_snap'); ?> <br/>
255
+ (<a id="showShAtt" style="font-weight: normal" onmouseout="hidePopShAtt('<?php echo $ii; ?>X');" onmouseover="showPopShAtt('<?php echo $ii; ?>X', event);" onclick="return false;" class="underdash" href="http://www.nextscripts.com/blog/"><?php _e('What\'s the difference?', 'nxs_snap'); ?></a>)</th><td>
256
+
257
+ <input type="radio" name="fb[<?php echo $ii; ?>][PostType]" value="T" <?php if ($fbPostType == 'T') echo 'checked="checked"'; ?> /> <?php _e('Text Post', 'nxs_snap'); ?> - <i><?php _e('just text message', 'nxs_snap'); ?></i><br/>
258
+ <input type="radio" name="fb[<?php echo $ii; ?>][PostType]" value="I" <?php if ($fbPostType == 'I') echo 'checked="checked"'; ?> /> <?php _e('Image Post', 'nxs_snap'); ?> - <i><?php _e('big image with text message', 'nxs_snap'); ?></i><br/>
259
+ <input type="radio" name="fb[<?php echo $ii; ?>][PostType]" value="A" <?php if ( !isset($fbPostType) || $fbPostType == '' || $fbPostType == 'A') echo 'checked="checked"'; ?> /> <?php _e('Text Post with "attached" blogpost', 'nxs_snap'); ?> &lt;-- (<a id="showShAtt" onmouseout="hidePopShAtt('<?php echo $ii; ?>');" onmouseover="showPopShAtt('<?php echo $ii; ?>', event);" onclick="return false;" class="underdash" href="http://www.nextscripts.com/blog/"><?php _e('What\'s the difference?', 'nxs_snap'); ?></a>) <br/>
260
+
261
+ <div style="width:100%; margin-left: 25px;"><strong><?php _e('Link attachment type:', 'nxs_snap'); ?>&nbsp;</strong> <input value="2" id="apFBAttchShare<?php echo $ii; ?>" onchange="doSwitchShAtt(0,<?php echo $ii; ?>);" type="radio" name="fb[<?php echo $ii; ?>][AttachPost]" <?php if ((int)$isAttachFB == 2) echo "checked"; ?> />
262
+ <?php _e('Share a link to your blogpost', 'nxs_snap'); ?> .. <?php _e('or', 'nxs_snap'); ?> ..
263
+ <input value="1" id="apFBAttch<?php echo $ii; ?>" onchange="doSwitchShAtt(1,<?php echo $ii; ?>);" type="radio" name="fb[<?php echo $ii; ?>][AttachPost]" <?php if ((int)$isAttachFB == 1) echo "checked"; ?> />
264
+ <?php _e('Attach your blogpost', 'nxs_snap'); ?>
265
+ </div>
266
+ <div class="popShAtt" id="popShAtt<?php echo $ii; ?>"><h3><?php _e('Two ways of attaching post on Facebook', 'nxs_snap'); ?></h3> <img src="<?php echo $nxs_plurl; ?>img/fb2wops.png" width="600" height="257" alt="<?php _e('Two ways of attaching post on Facebook', 'nxs_snap'); ?>"/></div>
267
+ <div class="popShAtt" id="popShAtt<?php echo $ii; ?>X"><h3><?php _e('Facebook Post Types', 'nxs_snap'); ?></h3><img src="<?php echo $nxs_plurl; ?>img/fbPostTypesDiff6.png" width="600" height="398" alt="<?php _e('Facebook Post Types', 'nxs_snap'); ?>"/></div>
268
+ </td></tr>
269
+ <!--
270
+ <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top: 6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Image(s) to use:', 'nxs_snap') ?></th>
271
+ <td><input type="checkbox" class="isAutoImg" checked="checked" id="isAutoImg-fb<?php echo $ii; ?>" name="fb[<?php echo $ii; ?>][isAutoImg]" value="A"/> <?php _e('Auto', 'nxs_snap'); ?><br/>
272
+ <div id="imgPrevList-fb<?php echo $ii; ?>" class="nxs_imgPrevList"></div></td></tr>
273
+ -->
274
+ <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top: 6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Message Format:', 'nxs_snap') ?></th>
275
+ <td>
276
+ <?php if (1==1) { ?>
277
+ <textarea cols="150" rows="2" id="fb<?php echo $ii; ?>SNAPformat" name="fb[<?php echo $ii; ?>][SNAPformat]" style="width:60%;max-width: 610px;" onfocus="jQuery('#fb<?php echo $ii; ?>SNAPformat').attr('rows', 4); jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apFBTMsgFrmt<?php echo $ii; ?>');"><?php echo $fbMsgFormat ?></textarea>
278
+ <?php } else { ?>
279
+ <input value="<?php echo $fbMsgFormat ?>" type="text" name="fb[<?php echo $ii; ?>][SNAPformat]" style="width:60%;max-width: 610px;" onfocus="jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apFBTMsgFrmt<?php echo $ii; ?>');"/><?php nxs_doShowHint("apFBTMsgFrmt".$ii, '', '58'); ?>
280
+ <?php } ?>
281
+ </td></tr>
282
+
283
+ <?php }
284
+ }
285
+
286
+ }
287
+
288
+ function adjMetaOpt($optMt, $pMeta){ if (isset($pMeta['isPosted'])) $optMt['isPosted'] = $pMeta['isPosted']; else $optMt['isPosted'] = '';
289
+ if (isset($pMeta['SNAPformat'])) $optMt['fbMsgFormat'] = $pMeta['SNAPformat'];
290
+ if (isset($pMeta['AttachPost'])) $optMt['fbAttch'] = ($pMeta['AttachPost'] != '')?$pMeta['AttachPost']:0; else { if (isset($pMeta['SNAPformat'])) $optMt['fbAttch'] = 0; }
291
+ if (isset($pMeta['PostType'])) $optMt['fbPostType'] = ($pMeta['PostType'] != '')?$pMeta['PostType']:0; else { if (isset($pMeta['SNAPformat'])) $optMt['fbPostType'] = 'T'; }
292
+ if (isset($pMeta['doFB'])) $optMt['doFB'] = $pMeta['doFB'] == 1?1:0; else { if (isset($pMeta['SNAPformat'])) $optMt['doFB'] = 0; }
293
+ if (isset($pMeta['SNAPincludeFB']) && $pMeta['SNAPincludeFB'] == '1' ) $optMt['doFB'] = 1; // <2.6 Compatibility fix
294
+ return $optMt;
295
+ }
296
+ }}
297
+
298
+ // ShortCode [nxs_fbembed accnum=0]
299
+ function nxs_fbembed_func( $atts ) { extract( shortcode_atts( array('accnum' => '0'), $atts ) ); $pid = get_the_ID(); $fbpo = get_post_meta($pid, 'snapFB', true); $fbpo = maybe_unserialize($fbpo);
300
+ if (!is_array($fbpo) || !is_array($fbpo[$accnum]) || !isset($fbpo[$accnum]['pgID']) || strpos($fbpo[$accnum]['pgID'], '_')===false ) return; $fbpo = $fbpo[$accnum]['pgID'];
301
+ $fbpoA = explode('_',$fbpo); $fpg = $fbpoA[0]; $fpid = $fbpoA[1];
302
+ $txtOut = '<div id="fb-root"></div> <script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/all.js#xfbml=1"; fjs.parentNode.insertBefore(js, fjs); }(document, \'script\', \'facebook-jssdk\'));</script>
303
+ <div class="fb-post" data-href="https://www.facebook.com/permalink.php?story_fbid='.$fpid.'&amp;id='.$fpg.'"><div class="fb-xfbml-parse-ignore"><a href="https://www.facebook.com/permalink.php?story_fbid='.$fpid.'&amp;id='.$fpg.'">Post</a></div></div>';
304
+ return $txtOut;
305
+ }
306
+ add_shortcode( 'nxs_fbembed', 'nxs_fbembed_func' );
307
+
308
+ if (!function_exists("nxs_getBackFBComments")) { function nxs_getBackFBComments($postID, $options, $po) { require_once ('apis/facebook.php'); $opts = array('access_token' => $options['fbAppPageAuthToken']);
309
+ $facebook = new NXS_Facebook(array( 'appId' => $options['fbAppID'], 'secret' => $options['fbAppSec'], 'cookie' => true )); $ci = 0;
310
+ $ret = $facebook->api($po['pgID']."/comments?filter=toplevel", "GET", $opts);
311
+ $impCmnts = get_post_meta($postID, 'snapImportedFBComments', true); if (!is_array($impCmnts)) $impCmnts = array(); //prr($impCmnts);
312
+ if (is_array($ret) && is_array($ret['data'])) foreach ($ret['data'] as $comment){ $cid = $comment['id']; if (trim($cid)=='') continue;
313
+ if (!in_array('fbxcw'.$cid, $impCmnts)) { $authData = $facebook->api($comment['from']['id'], "GET", $opts);
314
+ $commentdata = array( 'comment_post_ID' => $postID, 'comment_author' => $comment['from']['name'], 'comment_author_email' => $comment['from']['id'].'@facebook.com',
315
+ 'comment_author_url' => $authData['link'], 'comment_content' => $comment['message'], 'comment_date_gmt' => date('Y-m-d H:i:s', strtotime( $comment['created_time'] ) ), 'comment_type' => '');
316
+ //prr($commentdata);
317
+ $wpCid = nxs_postNewComment($commentdata, $options['riCommentsAA']=='1'); $ci++; $impCmnts[$wpCid] = 'fbxcw'.$cid;
318
+ } else $wpCid = array_search('fbxcw'.$cid, $impCmnts);
319
+ $replRet = $facebook->api($cid."/comments", "GET", $opts);
320
+ if (is_array($replRet) && is_array($replRet['data'])) foreach ($replRet['data'] as $rComment){ $rCid = $rComment['id'];
321
+ if (trim($rCid)!='' && !in_array('fbxcw'.$rCid, $impCmnts)) { // prr($impCmnts);
322
+ $authData = $facebook->api($rComment['from']['id'], "GET", $opts);
323
+ $commentdata = array( 'comment_parent' => $wpCid, 'comment_post_ID' => $postID, 'comment_author' => $rComment['from']['name'], 'comment_author_email' => $rComment['from']['id'].'@facebook.com',
324
+ 'comment_author_url' => $authData['link'], 'comment_content' => $rComment['message'], 'comment_date_gmt' => date('Y-m-d H:i:s', strtotime( $rComment['created_time'] ) ), 'comment_type' => '');
325
+ // prr($commentdata);
326
+ nxs_postNewComment($commentdata, $options['riCommentsAA']=='1'); $ci++; $impCmnts[] = 'fbxcw'.$rCid;
327
+ }
328
+ }
329
+ }
330
+ delete_post_meta($postID, 'snapImportedFBComments'); add_post_meta($postID, 'snapImportedFBComments', $impCmnts );
331
+ //## if Importing manually from Button echo result.
332
+ if ($_POST['id']!='') printf( _n( '%d comment has been imported.', '%d comments has been imported.', $ci, 'nxs_snap'), $ci );
333
+ }}
334
+
335
+ if (!function_exists("nxs_rePostToFB_ajax")) { function nxs_rePostToFB_ajax() { check_ajax_referer('rePostToFB'); $postID = $_POST['id']; // $result = nsPublishTo($id, 'FB', true);
336
+ $options = get_option('NS_SNAutoPoster'); foreach ($options['fb'] as $ii=>$fbo) if ($ii==$_POST['nid']) { $fbo['ii'] = $ii; $fbo['pType'] = 'aj';
337
+ $fbpo = get_post_meta($postID, 'snapFB', true); /* echo $postID."|"; echo $fbpo; */ $fbpo = maybe_unserialize($fbpo); // prr($fbpo);
338
+ if (is_array($fbpo) && isset($fbpo[$ii]) && is_array($fbpo[$ii]) ){ $ntClInst = new nxs_snapClassFB(); $fbo = $ntClInst->adjMetaOpt($fbo, $fbpo[$ii]); } //prr($fbo);
339
+ if ($_POST['ri']=='1') { nxs_getBackFBComments($postID, $fbo, $fbpo[$ii]); die(); } else {
340
+ $result = nxs_doPublishToFB($postID, $fbo); if ($result == '200') die("Your post has been successfully sent to FaceBook."); else die($result);
341
+ }
342
+ }
343
+ }
344
+ }
345
+
346
+ if (!function_exists("nxs_doPublishToFB")) { //## Second Function to Post to FB
347
+ function nxs_doPublishToFB($postID, $options){ global $ShownAds; $ntCd = 'FB'; $ntCdL = 'fb'; $ntNm = 'Facebook'; $dsc = '';
348
+ if (!class_exists('nxs_class_SNAP_FB')) { nxs_addToLogN('E', 'Error', $ntCd, '-=ERROR=- No Facebook API Lib Detected', ''); return "No Facebook API Lib Detected";}
349
+
350
+ $fbWhere = 'feed'; $page_id = $options['fbPgID']; if (isset($ShownAds)) $ShownAdsL = $ShownAds; $addParams = nxs_makeURLParams(array('NTNAME'=>$ntNm, 'NTCODE'=>$ntCd, 'POSTID'=>$postID, 'ACCNAME'=>$options['nName']));
351
+ //## Some Common stuff
352
+ $ii = $options['ii']; if (!isset($options['pType'])) $options['pType'] = 'im'; if ($options['pType']=='sh') sleep(rand(1, 10));
353
+ $logNT = '<span style="color:#0000FF">Facebook</span> - '.$options['nName'];
354
+ $snap_ap = get_post_meta($postID, 'snap'.$ntCd, true); $snap_ap = maybe_unserialize($snap_ap);
355
+ if ($options['pType']!='aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
356
+ $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted!='2') {
357
+ nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:'.$postID, 'Already posted. No reason for posting duplicate'.' |'.$options['pType']); return;
358
+ }
359
+ }
360
+ //## Make the post
361
+ if (isset($options['qTLng'])) $lng = $options['qTLng']; else $lng = ''; if (!isset($options['fbAppPageAuthToken'])) $options['fbAppPageAuthToken'] = '';
362
+ $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle=='') $blogTitle = home_url();
363
+ //## Initiate Posting Array
364
+ $message = array('message'=>'', 'link'=>'', 'title'=>'', 'description'=>'', 'imageURL'=>'', 'videoURL'=>'', 'siteName'=>$blogTitle);
365
+
366
+ if ($postID=='0') { $message['message'] = 'Test Post, Please Ignore';
367
+ $message['description'] = 'Test Post, Description'; $message['title'] = 'Test Post - Title'; $message['link'] = home_url();
368
+ } else { $post = get_post($postID); if(!$post) return; $msg = nsFormatMessage($options['fbMsgFormat'], $postID, $addParams);
369
+ $isAttachFB = $options['fbAttch']; $fbPostType = $options['fbPostType']; $isAttachVidFB = $options['fbAttchAsVid'];
370
+ nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted'=>'1')); $extInfo = ' | PostID: '.$postID." - ".nxs_doQTrans($post->post_title, $lng).' |'.$options['pType'];
371
+ if (($isAttachFB=='1' || $isAttachFB=='2' || $fbPostType=='A')) $imgURL = nxs_getPostImage($postID, 'medium'); // prr($options); echo "PP - ".$postID; prr($src);
372
+ if ($fbPostType=='I') $imgURL = nxs_getPostImage($postID, 'full'); // prr($options); echo "PP - ".$postID; prr($src);
373
+ if (($isAttachFB=='1' || $fbPostType=='A' || $fbPostType=='S')){
374
+ //## AUTO - Get Post Descr from SEO Plugins or make it.
375
+ if (trim($options['fbMsgAFrmt'])!='') {$dsc = nsFormatMessage($options['fbMsgAFrmt'], $postID, $addParams);} else { if (function_exists('aioseop_mrt_fix_meta') && $dsc=='') $dsc = trim(get_post_meta($postID, '_aioseop_description', true));
376
+ if (function_exists('wpseo_admin_init') && $dsc=='') $dsc = trim(get_post_meta($postID, '_yoast_wpseo_opengraph-description', true));
377
+ if (function_exists('wpseo_admin_init') && $dsc=='') $dsc = trim(get_post_meta($postID, '_yoast_wpseo_metadesc', true));
378
+ if ($dsc=='') $dsc = trim(apply_filters('the_content', nxs_doQTrans($post->post_excerpt, $lng))); if ($dsc=='') $dsc = trim(nxs_doQTrans($post->post_excerpt, $lng));
379
+ if ($dsc=='') $dsc = trim(apply_filters('the_content', nxs_doQTrans($post->post_content, $lng))); if ($dsc=='') $dsc = trim(nxs_doQTrans($post->post_content, $lng));
380
+ if ($dsc=='') $dsc = get_bloginfo('description');
381
+ }
382
+ $dsc = strip_tags($dsc); $dsc = nxs_decodeEntitiesFull($dsc); $dsc = nsTrnc($dsc, 900, ' ');
383
+ }
384
+
385
+ $msg = str_replace('<br>', "\n", $msg); $msg = str_replace('<br/>', "\n", $msg); $msg = str_replace('<br />', "\n", $msg);
386
+ $msg = str_ireplace('<3','&lt;3', $msg); $msg = str_ireplace('<(','&lt;(', $msg); //## FB Smiles FIX.
387
+ $msg = strip_tags($msg); $msg = nxs_decodeEntitiesFull($msg);
388
+ $msg = str_ireplace('&#39;',"'", $msg); $msg = str_ireplace('<3','&lt;3', $msg); $msg = str_ireplace('<(','&lt;(', $msg); //## FB Smiles FIX 2.
389
+
390
+ if ($isAttachVidFB=='1') {$vids = nsFindVidsInPost($post, false); if (count($vids)>0) {
391
+ if (strlen($vids[0])==11) { $vidURL = 'http://www.youtube.com/v/'.$vids[0]; $imgURL = nsGetYTThumb($vids[0]); }
392
+ if (strlen($vids[0])==8) { $vidURL = 'https://secure.vimeo.com/moogaloop.swf?clip_id='.$vids[0].'&autoplay=1';
393
+ $apiURL = "http://vimeo.com/api/v2/video/".$vids[0].".json?callback=showThumb"; $json = wp_remote_get($apiURL);
394
+ if (!is_wp_error($json)) { $json = $json['body']; $json = str_replace('showThumb(','',$json); $json = str_replace('])',']',$json); $json = json_decode($json, true); $imgURL = $json[0]['thumbnail_large']; }
395
+ }
396
+ }}
397
+ //## MyURL - URLToGo code
398
+ if (!isset($options['urlToUse']) || trim($options['urlToUse'])=='') $myurl = trim(get_post_meta($postID, 'snap_MYURL', true)); if ($myurl!='') $options['urlToUse'] = $myurl;
399
+ if (isset($options['urlToUse']) && trim($options['urlToUse'])!='') { $urlToGo = $options['urlToUse']; $options['useFBGURLInfo'] = true; } else $urlToGo = get_permalink($postID);
400
+ if($addParams!='') $urlToGo .= (strpos($urlToGo,'?')!==false?'&':'?').$addParams;
401
+
402
+ $message = array('message'=>$msg, 'link'=>$urlToGo, 'title'=>nxs_doQTrans($post->post_title, $lng), 'description'=>$dsc, 'imageURL'=>$imgURL, 'videoURL'=>$vidURL, 'siteName'=>$blogTitle);
403
+ } // prr($mssg); // prr($options); // prr($facebook); echo "/$page_id/feed";
404
+ if (isset($ShownAds)) $ShownAds = $ShownAdsL; // FIX for the quick-adsense plugin
405
+
406
+ //## Actual Post
407
+ $ntToPost = new nxs_class_SNAP_FB(); $ret = $ntToPost->doPostToNT($options, $message);
408
+ //## Process Results
409
+ if (!is_array($ret) || $ret['isPosted']!='1') { //## Error
410
+ if ($postID=='0') prr($ret); nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.print_r($ret, true), $extInfo);
411
+ } else { // ## All Good - log it.
412
+ if ($postID=='0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo _e('OK - Message Posted, please see your '.$logNT.' Page. ', 'nxs_snap'); }
413
+ else { nxs_addToRI($postID); nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted'=>'1', 'pgID'=>$ret['postID'], 'pDate'=>date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); }
414
+ }
415
+ //## Return Result
416
+ if ($ret['isPosted']=='1') return 200; else return print_r($ret, true);
417
+ }
418
+ }
419
+
420
  ?>
inc-cl/ff.php CHANGED
@@ -1,202 +1,205 @@
1
- <?php
2
- //## NextScripts Facebook Connection Class
3
- $nxs_snapAvNts[] = array('code'=>'FF', 'lcode'=>'ff', 'name'=>'FriendFeed');
4
-
5
- if (!class_exists("nxs_snapClassFF")) { class nxs_snapClassFF {
6
- //#### Show Common Settings
7
- function showGenNTSettings($ntOpts){ global $nxs_plurl; $ntInfo = array('code'=>'FF', 'lcode'=>'ff', 'name'=>'FriendFeed', 'defNName'=>'ffUName', 'tstReq' => false); ?>
8
- <div class="nxs_box">
9
- <div class="nxs_box_header">
10
- <div class="nsx_iconedTitle" style="margin-bottom:1px;background-image:url(<?php echo $nxs_plurl;?>img/<?php echo $ntInfo['lcode']; ?>16.png);"><?php echo $ntInfo['name']; ?>
11
- <?php $cbo = count($ntOpts); ?> <?php wp_nonce_field( 'ns'.$ntInfo['code'], 'ns'.$ntInfo['code'].'_wpnonce' ); ?>
12
- <?php if ($cbo>1){ ?><div class="nsBigText"><?php echo "(".($cbo=='0'?'No':$cbo)." "; _e('accounts', 'nxs_snap'); echo ")"; ?></div><?php } ?>
13
- </div>
14
- </div>
15
- <div class="nxs_box_inside">
16
- <?php foreach ($ntOpts as $indx=>$pbo){ if (trim($pbo['nName']=='')) $pbo['nName'] = $pbo[$ntInfo['defNName']]; ?>
17
- <p style="margin:0px;margin-left:5px;">
18
- <input value="1" name="<?php echo $ntInfo['lcode']; ?>[<?php echo $indx; ?>][apDo<?php echo $ntInfo['code']; ?>]" onchange="doShowHideBlocks('<?php echo $ntInfo['code']; ?>');" type="checkbox" <?php if ((int)$pbo['do'.$ntInfo['code']] == 1) echo "checked"; ?> /> <?php if ((int)$pbo['catSel'] == 1) { ?> <span onmouseout="nxs_hidePopUpInfo('popOnlyCat');" onmouseover="nxs_showPopUpInfo('popOnlyCat', event);"><?php echo "*[".(substr_count($pbo['catSelEd'], ",")+1)."]*" ?></span><?php } ?>
19
- <strong><?php _e('Auto-publish to', 'nxs_snap'); ?> <?php echo $ntInfo['name']; ?> <i style="color: #005800;"><?php if($pbo['nName']!='') echo "(".$pbo['nName'].")"; ?></i></strong>
20
- &nbsp;&nbsp;<?php if ($ntInfo['tstReq'] && (!isset($pbo[$ntInfo['lcode'].'OK']) || $pbo[$ntInfo['lcode'].'OK']=='')){ ?><b style="color: #800000"><?php _e('Attention requred. Unfinished setup', 'nxs_snap'); ?> ==&gt;</b><?php } ?><a id="do<?php echo $ntInfo['code'].$indx; ?>A" href="#" onclick="doShowHideBlocks2('<?php echo $ntInfo['code'].$indx; ?>');return false;">[<?php _e('Show Settings', 'nxs_snap'); ?>]</a>&nbsp;&nbsp;
21
- <a href="#" onclick="doDelAcct('<?php echo $ntInfo['lcode']; ?>', '<?php echo $indx; ?>', '<?php if (isset($pbo['bgBlogID'])) echo $pbo['nName']; ?>');return false;">[<?php _e('Remove Account', 'nxs_snap'); ?>]</a>
22
- </p><?php $this->showNTSettings($indx, $pbo);
23
- }?>
24
- </div>
25
- </div> <?php
26
- }
27
- //#### Show NEW Settings Page
28
- function showNewNTSettings($mgpo){ $gpo = array('nName'=>'', 'doFF'=>'1', 'ffUName'=>'', 'ffPageID'=>'', 'ffAttch'=>'', 'ffPass'=>''); $this->showNTSettings($mgpo, $gpo, true);}
29
- //#### Show Unit Settings
30
- function showNTSettings($ii, $gpo, $isNew=false){ global $nxs_plurl; ?>
31
- <div id="doFF<?php echo $ii; ?>Div" class="insOneDiv<?php if ($isNew) echo " clNewNTSets"; ?>" style="max-width: 1000px; background-color: #EBF4FB; background-image: url(<?php echo $nxs_plurl; ?>img/ff-bg.png); background-position:90% 10%; background-repeat: no-repeat; margin: 10px; border: 1px solid #808080; padding: 10px; display:none;"> <input type="hidden" name="apDoSFF<?php echo $ii; ?>" value="0" id="apDoSFF<?php echo $ii; ?>" />
32
-
33
- <div class="nsx_iconedTitle" style="float: right; background-image: url(<?php echo $nxs_plurl; ?>img/ff16.png);"><a style="font-size: 12px;" target="_blank" href="http://www.nextscripts.com/setup-installation-FriendFeed-social-networks-auto-poster-wordpress/"><?php $nType="FriendFeed"; printf( __( 'Detailed %s Installation/Configuration Instructions', 'nxs_snap' ), $nType); ?></a></div>
34
-
35
- <div style="width:100%;"><strong><?php _e('Account Nickname', 'nxs_snap'); ?>:</strong> <i><?php _e('Just so you can easely identify it', 'nxs_snap'); ?></i> </div><input name="ff[<?php echo $ii; ?>][nName]" id="ffnName<?php echo $ii; ?>" style="font-weight: bold; color: #005800; border: 1px solid #ACACAC; width: 40%;" value="<?php _e(apply_filters('format_to_edit',htmlentities($gpo['nName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /><br/>
36
- <?php echo nxs_addQTranslSel('ff', $ii, $gpo['qTLng']); ?><?php echo nxs_addPostingDelaySel('ff', $ii, $gpo['nHrs'], $gpo['nMin']); ?>
37
-
38
- <?php if (!$isNew) { ?>
39
- <div style="width:100%;"><strong><?php _e('Categories', 'nxs_snap'); ?>:</strong>
40
- <input value="0" id="catSelA<?php echo $ii; ?>" type="radio" name="ff[<?php echo $ii; ?>][catSel]" <?php if ((int)$gpo['catSel'] != 1) echo "checked"; ?> /> All
41
- <input value="1" id="catSelSFF<?php echo $ii; ?>" type="radio" name="ff[<?php echo $ii; ?>][catSel]" <?php if ((int)$gpo['catSel'] == 1) echo "checked"; ?> /> <a href="#" style="text-decoration: none;" class="showCats" id="nxs_SCA_FF<?php echo $ii; ?>" onclick="jQuery('#catSelSFF<?php echo $ii; ?>').attr('checked', true); jQuery('#tmpCatSelNT').val('FF<?php echo $ii; ?>'); nxs_markCats( jQuery('#nxs_SC_FF<?php echo $ii; ?>').val() ); jQuery('#showCatSel').bPopup({ modalClose: false, appendTo: '#nsStForm', opacity: 0.6, follow: [false, false], position: [75, 'auto']}); return false;">Selected<?php if ($gpo['catSelEd']!='') echo "[".(substr_count($gpo['catSelEd'], ",")+1)."]"; ?></a>
42
- <input type="hidden" name="ff[<?php echo $ii; ?>][catSelEd]" id="nxs_SC_FF<?php echo $ii; ?>" value="<?php echo $gpo['catSelEd']; ?>" />
43
- <br/><i><?php _e('Only selected categories will be autoposted to this account', 'nxs_snap'); ?></i></div>
44
- <br/>
45
- <?php } ?>
46
-
47
- <div style="width:100%;"><strong>FriendFeed nickname:</strong> <span style="font-size: 11px; margin: 0px;">Get it from <a target="_blank" href="https://friendfeed.com/account/api">https://friendfeed.com/account/api</a>.</span></div><input name="ff[<?php echo $ii; ?>][apFFUName]" id="apFFUName" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit',htmlentities($gpo['ffUName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
48
- <div style="width:100%;"><strong>FriendFeed remote key:</strong> <span style="font-size: 11px; margin: 0px;">Get it from <a target="_blank" href="https://friendfeed.com/account/api">https://friendfeed.com/account/api</a>.</span>
49
-
50
- </div><input name="ff[<?php echo $ii; ?>][apFFPass]" id="apFFPass" type="password" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities(substr($gpo['ffPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($gpo['ffPass'], 5)):$gpo['ffPass'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /> <br/>
51
-
52
- <div style="width:100%;"><br/><strong>Group ID:</strong> [Optional] Please specify Group ID. <i>Use this <b>only</b> if you are posting NOT to your own feed. </i></div>
53
- <input name="ff[<?php echo $ii; ?>][grpID]" id="grpID" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($gpo['grpID'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
54
-
55
- <?php if ($isNew) { ?> <input type="hidden" name="ff[<?php echo $ii; ?>][apDoFF]" value="1" id="apDoNewFF<?php echo $ii; ?>" /> <?php } ?>
56
- <br/> <br/>
57
-
58
- <div id="altFormat" style="">
59
- <div style="width:100%;"><strong id="altFormatText"><?php _e('Post Text Format', 'nxs_snap'); ?></strong> (<a href="#" id="apFFMsgFrmt<?php echo $ii; ?>HintInfo" onclick="mxs_showHideFrmtInfo('apFFMsgFrmt<?php echo $ii; ?>'); return false;"><?php _e('Show format info', 'nxs_snap'); ?></a>)</div>
60
- <input name="ff[<?php echo $ii; ?>][apFFMsgFrmt]" id="apFFMsgFrmt" style="width: 50%;" value="<?php if ($isNew) echo "%TITLE% - %URL% %EXCERPT%"; else _e(apply_filters('format_to_edit',htmlentities($gpo['ffMsgFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap'); ?>" onfocus="mxs_showFrmtInfo('apFFMsgFrmt<?php echo $ii; ?>');" /><?php nxs_doShowHint("apFFMsgFrmt".$ii); ?>
61
- </div>
62
- <p style="margin: 0px;"><input value="1" id="apLIAttch" type="checkbox" name="ff[<?php echo $ii; ?>][attchImg]" <?php if ((int)$gpo['attchImg'] == 1) echo "checked"; ?> /> <strong><?php _e('Attach Image to FriendFeed Post', 'nxs_snap'); ?></strong></p>
63
- <br/>
64
-
65
- <?php if ($gpo['ffPass']!='') { ?>
66
- <?php wp_nonce_field( 'rePostToFF', 'rePostToFF_wpnonce' ); ?>
67
- <b><?php _e('Test your settings', 'nxs_snap'); ?>:</b>&nbsp;&nbsp;&nbsp; <a href="#" class="NXSButton" onclick="testPost('FF', '<?php echo $ii; ?>'); return false;"><?php printf( __( 'Submit Test Post to %s', 'nxs_snap' ), $nType); ?></a>
68
-
69
- <?php }
70
-
71
- ?><div class="submit"><input type="submit" class="button-primary" name="update_NS_SNAutoPoster_settings" value="<?php _e('Update Settings', 'nxs_snap') ?>" /></div></div><?php
72
- }
73
- //#### Set Unit Settings from POST
74
- function setNTSettings($post, $options){ global $nxs_snapThisPageUrl; $code = 'FF'; $lcode = 'ff';
75
- foreach ($post as $ii => $pval){
76
- if (isset($pval['apFFUName']) && $pval['apFFUName']!=''){ if (!isset($options[$ii])) $options[$ii] = array();
77
- if (isset($pval['apFFUName'])) $options[$ii]['ffUName'] = trim($pval['apFFUName']);
78
- if (isset($pval['nName'])) $options[$ii]['nName'] = trim($pval['nName']);
79
- if (isset($pval['apFFPass'])) $options[$ii]['ffPass'] = 'n5g9a'.nsx_doEncode($pval['apFFPass']); else $options[$ii]['ffPass'] = '';
80
-
81
- if (isset($pval['catSel'])) $options[$ii]['catSel'] = trim($pval['catSel']);
82
- if ($options[$ii]['catSel']=='1' && trim($pval['catSelEd'])!='') $options[$ii]['catSelEd'] = trim($pval['catSelEd']); else $options[$ii]['catSelEd'] = '';
83
-
84
- if (isset($pval['apFFMsgFrmt'])) $options[$ii]['ffMsgFormat'] = trim($pval['apFFMsgFrmt']);
85
- if (isset($pval['grpID'])) $options[$ii]['grpID'] = trim($pval['grpID']);
86
- if (isset($pval['attchImg'])) $options[$ii]['attchImg'] = $pval['attchImg']; else $options[$ii]['attchImg'] = 0;
87
- if (isset($pval['apDoFF'])) $options[$ii]['doFF'] = $pval['apDoFF']; else $options[$ii]['doFF'] = 0;
88
- if (isset($pval['delayHrs'])) $options[$ii]['nHrs'] = trim($pval['delayHrs']); if (isset($pval['delayMin'])) $options[$ii]['nMin'] = trim($pval['delayMin']);
89
- if (isset($pval['qTLng'])) $options[$ii]['qTLng'] = trim($pval['qTLng']);
90
- }
91
- } return $options;
92
- }
93
- //#### Show Post->Edit Meta Box Settings
94
- function showEdPostNTSettings($ntOpts, $post){ global $nxs_plurl; $post_id = $post->ID;
95
- foreach($ntOpts as $ii=>$ntOpt) { $pMeta = maybe_unserialize(get_post_meta($post_id, 'snapFF', true)); if (is_array($pMeta)) $ntOpt = $this->adjMetaOpt($ntOpt, $pMeta[$ii]);
96
- $doFF = $ntOpt['doFF'] && (is_array($pMeta) || $ntOpt['catSel']!='1');
97
- $isAvailFF = $ntOpt['ffUName']!='' && $ntOpt['ffPass']!=''; $ffMsgFormat = htmlentities($ntOpt['ffMsgFormat'], ENT_COMPAT, "UTF-8"); $ffMsgTFormat = htmlentities($ntOpt['ffMsgTFormat'], ENT_COMPAT, "UTF-8");
98
- $isAttchImg = $ntOpt['attchImg'];
99
- ?>
100
- <tr><th style="text-align:left;" colspan="2"><?php if ( $ntOpt['catSel']=='1' && trim($ntOpt['catSelEd'])!='' ) { ?> <input type="hidden" class="nxs_SC" id="nxs_SC_FF<?php echo $ii; ?>" value="<?php echo $ntOpt['catSelEd']; ?>" /> <?php } ?>
101
- <?php if ($isAvailFF) { ?><input class="nxsGrpDoChb" value="1" id="doFF<?php echo $ii; ?>" <?php if ($post->post_status == "publish") echo 'disabled="disabled"';?> type="checkbox" name="ff[<?php echo $ii; ?>][doFF]" <?php if ((int)$doFF == 1) echo 'checked="checked" title="def"'; ?> />
102
- <?php if ($post->post_status == "publish") { ?> <input type="hidden" name="ff[<?php echo $ii; ?>][doFF]" value="<?php echo $doFF;?>"> <?php } ?> <?php } ?>
103
-
104
- <div class="nsx_iconedTitle" style="display: inline; font-size: 13px; background-image: url(<?php echo $nxs_plurl; ?>img/ff16.png);">FriendFeed - <?php _e('publish to', 'nxs_snap') ?> (<i style="color: #005800;"><?php echo $ntOpt['nName']; ?></i>)</div></th> <td><?php //## Only show RePost button if the post is "published"
105
- if ($post->post_status == "publish" && $isAvailFF) { ?><input alt="<?php echo $ii; ?>" style="float: right;" onmouseout="hidePopShAtt('SV');" onmouseover="showPopShAtt('SV', event);" onclick="return false;" type="button" class="button" name="rePostToFF_repostButton" id="rePostToFF_button" value="<?php _e('Repost to FriendFeed', 'nxs_snap') ?>" />
106
- <?php wp_nonce_field( 'rePostToFF', 'rePostToFF_wpnonce' ); } ?>
107
-
108
- <?php if (is_array($pMeta) && is_array($pMeta[$ii]) && isset($pMeta[$ii]['pgID']) ) {
109
- ?> <span id="pstdFF<?php echo $ii; ?>" style="float: right; padding-top: 4px; padding-right: 10px;">
110
- <a style="font-size: 10px;" href="http://www.FriendFeed.com/e/<?php echo $pMeta[$ii]['pgID']; ?>" target="_blank"><?php $nType="FriendFeed"; printf( __( 'Posted on', 'nxs_snap' ), $nType); ?> <?php echo (isset($pMeta[$ii]['pDate']) && $pMeta[$ii]['pDate']!='')?(" (".$pMeta[$ii]['pDate'].")"):""; ?></a>
111
- </span><?php } ?>
112
-
113
- </td></tr>
114
-
115
- <tr><th scope="row" style="text-align:right; width:150px; vertical-align:top; padding-top: 5px; padding-right:10px;">
116
- <input value="0" type="hidden" name="ff[<?php echo $ii; ?>][attchImg]"/>
117
- <input value="1" type="checkbox" name="ff[<?php echo $ii; ?>][attchImg]" <?php if ((int)$isAttchImg == 1) echo "checked"; ?> /> </th><td><strong>Attach Image to FriendFeed Post</strong></td> </tr>
118
-
119
- <?php if (!$isAvailFF) { ?><tr><th scope="row" style="text-align:right; width:150px; padding-top: 5px; padding-right:10px;"></th> <td><b>Setup your FriendFeed Account to AutoPost to FriendFeed</b>
120
- <?php } elseif ($post->post_status != "pubZlish") { ?>
121
-
122
- <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top: 6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Title Format:', 'nxs_snap') ?></th>
123
- <td><input value="<?php echo $ffMsgFormat ?>" type="text" name="ff[<?php echo $ii; ?>][SNAPformatT]" style="width:60%;max-width: 610px;" onfocus="jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apFFMsgFrmt<?php echo $ii; ?>');"/><?php nxs_doShowHint("apFFMsgFrmt".$ii, '', '58'); ?></td></tr>
124
-
125
- <?php }
126
- }
127
- }
128
- //#### Save Meta Tags to the Post
129
- function adjMetaOpt($optMt, $pMeta){ if (isset($pMeta['isPosted'])) $optMt['isPosted'] = $pMeta['isPosted']; else $optMt['isPosted'] = '';
130
- if (isset($pMeta['SNAPformat'])) $optMt['ffMsgFormat'] = $pMeta['SNAPformat'];
131
- if (isset($pMeta['attchImg'])) $optMt['attchImg'] = $pMeta['attchImg'] == 1?1:0; else { if (isset($pMeta['attchImg'])) $optMt['attchImg'] = 0; }
132
-
133
- if (isset($pMeta['doFF'])) $optMt['doFF'] = $pMeta['doFF'] == 1?1:0; else { if (isset($pMeta['SNAPformat'])) $optMt['doFF'] = 0; }
134
- if (isset($pMeta['SNAPincludeFF']) && $pMeta['SNAPincludeFF'] == '1' ) $optMt['doFF'] = 1;
135
- return $optMt;
136
- }
137
- }}
138
- if (!function_exists("nxs_rePostToFF_ajax")) {
139
- function nxs_rePostToFF_ajax() { check_ajax_referer('rePostToFF'); $postID = $_POST['id']; $options = get_option('NS_SNAutoPoster');
140
- foreach ($options['ff'] as $ii=>$two) if ($ii==$_POST['nid']) { $two['ii'] = $ii; $two['pType'] = 'aj'; //if ($two['gpPageID'].$two['gpUName']==$_POST['nid']) {
141
- $gppo = get_post_meta($postID, 'snapFF', true); $gppo = maybe_unserialize($gppo);// prr($gppo);
142
- if (is_array($gppo) && isset($gppo[$ii]) && is_array($gppo[$ii])){ $ntClInst = new nxs_snapClassFF(); $two = $ntClInst->adjMetaOpt($two, $gppo[$ii]);}
143
- $result = nxs_doPublishToFF($postID, $two); if ($result == 200) die("Successfully sent your post to FriendFeed."); else die($result);
144
- }
145
- }
146
- }
147
-
148
- if (!function_exists("nxs_getFFHeaders")) { function nxs_getFFHeaders($up){ $hdrsArr = array();
149
- $hdrsArr['Cache-Control']='no-cache'; $hdrsArr['Connection']='keep-alive';
150
- $hdrsArr['User-Agent']='SNAP for Wordpress; Ver '.NextScripts_SNAP_Version;
151
- $hdrsArr['Accept']='text/html, application/xhtml+xml, */*'; $hdrsArr['DNT']='1';
152
- $hdrsArr['Content-Type']='application/x-www-form-urlencoded';
153
- $hdrsArr['Authorization'] = 'Basic ' . base64_encode("$up");
154
- //$hdrsArr['Authorization'] = $up;
155
- $hdrsArr['Accept-Encoding']='gzip,deflate'; $hdrsArr['Accept-Language']='en-US,en;q=0.8'; $hdrsArr['Accept-Charset']='ISO-8859-1,utf-8;q=0.7,*;q=0.3'; return $hdrsArr;
156
- }}
157
-
158
- if (!function_exists("nxs_doPublishToFF")) { //## Second Function to Post to FF
159
- function nxs_doPublishToFF($postID, $options){ $ntCd = 'FF'; $ntCdL = 'ff'; $ntNm = 'FriendFeed';
160
- //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToFF', array($postID, $options));
161
-
162
- $ii = $options['ii']; if (!isset($options['pType'])) $options['pType'] = 'im'; if ($options['pType']=='sh') sleep(rand(1, 10));
163
- $logNT = '<span style="color:#000080">FriendFeed</span> - '.$options['nName'];
164
- $snap_ap = get_post_meta($postID, 'snap'.$ntCd, true); $snap_ap = maybe_unserialize($snap_ap);
165
- if ($options['pType']!='aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
166
- $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted!='2') { sleep(5);
167
- nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:'.$postID, 'Already posted. No reason for posting duplicate'.' |'.$uqID); return;
168
- }
169
- }
170
-
171
- if ($postID=='0') { echo "Testing ... <br/><br/>"; $link = home_url(); $msg = 'Test Link from '.$link; } else { $post = get_post($postID); if(!$post) return; $link = get_permalink($postID);
172
- $msgFormat = $options['ffMsgFormat']; $msgTFormat = $options['ffMsgTFormat']; $msgT = nsFormatMessage($msgTFormat, $postID); $msg = nsFormatMessage($msgFormat, $postID);
173
- nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted'=>'1'));
174
- }
175
- $extInfo = ' | PostID: '.$postID." - ".$post->post_title;
176
- $dusername = $options['ffUName']; $pass = (substr($options['ffPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($options['ffPass'], 5)):$options['ffPass']);
177
- $link = urlencode($link); $ext = urlencode(substr($msg, 0, 1000));
178
- // API/V2 if we ever switch - $postArr = array('body'=>$msg, 'link'=>'', 'to'=>($options['grpID']!=''?$options['grpID']:'me'), 'image_url'=>($imgURL!=''?$imgURL:'me'), 'short'=>0); prr($postArr);
179
-
180
- if ($options['attchImg']=='1') $imgURL = nxs_getPostImage($postID, 'full'); else $imgURL = '';
181
- $postArr = array('title'=>$msg, 'image0_link'=>'', 'room'=>($options['grpID']!=''?$options['grpID']:''), 'image0_url'=>($imgURL!=''?$imgURL:''));
182
- $apicall = "http://friendfeed.com/api/share"; $hdrsArr = nxs_getFFHeaders($dusername.':'.$pass);
183
- $paramcall = array( 'method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'body'=> $postArr, 'headers' => $hdrsArr);
184
-
185
- $cnt = wp_remote_post( $apicall, $paramcall ); // prr(json_decode($cnt['body'], true));
186
-
187
- if(is_wp_error($cnt)) {
188
- $ret = 'Something went wrong - '.""; nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.$ret. "ERR: ".print_r($cnt, true), $extInfo);
189
- } else {
190
- if (is_array($cnt) && $cnt['response']['code']=='200' && is_array(json_decode($cnt['body'], true)))
191
- { $ret = 'OK'; $retInfo = json_decode($cnt['body'], true);
192
- nxs_metaMarkAsPosted($postID, 'FF', $options['ii'], array('isPosted'=>'1', 'pgID'=>$retInfo['entries'][0]['id'], 'pDate'=>date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); }
193
- else { $ret = "Error: ";
194
- if ($cnt['response']['code']=='401') $ret .= " Incorrect Username/Password ";
195
- $ret .= $cnt['response']['message']; nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.$ret. " | ERR: ".print_r($cnt, true), $extInfo);
196
- }
197
- }
198
- if ($ret!='OK') { if ($postID=='0') echo $ret; } else if ($postID=='0') { echo 'OK - Message Posted, please see your FriendFeed Page. '; nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); }
199
- if ($ret == 'OK') return 200; else return $ret;
200
- }
201
- }
 
 
 
202
  ?>
1
+ <?php
2
+ //## NextScripts Facebook Connection Class
3
+ $nxs_snapAvNts[] = array('code'=>'FF', 'lcode'=>'ff', 'name'=>'FriendFeed');
4
+
5
+ if (!class_exists("nxs_snapClassFF")) { class nxs_snapClassFF {
6
+ //#### Show Common Settings
7
+ function showGenNTSettings($ntOpts){ global $nxs_plurl; $ntInfo = array('code'=>'FF', 'lcode'=>'ff', 'name'=>'FriendFeed', 'defNName'=>'ffUName', 'tstReq' => false); ?>
8
+ <div class="nxs_box">
9
+ <div class="nxs_box_header">
10
+ <div class="nsx_iconedTitle" style="margin-bottom:1px;background-image:url(<?php echo $nxs_plurl;?>img/<?php echo $ntInfo['lcode']; ?>16.png);"><?php echo $ntInfo['name']; ?>
11
+ <?php $cbo = count($ntOpts); ?> <?php wp_nonce_field( 'ns'.$ntInfo['code'], 'ns'.$ntInfo['code'].'_wpnonce' ); ?>
12
+ <?php if ($cbo>1){ ?><div class="nsBigText"><?php echo "(".($cbo=='0'?'No':$cbo)." "; _e('accounts', 'nxs_snap'); echo ")"; ?></div><?php } ?>
13
+ </div>
14
+ </div>
15
+ <div class="nxs_box_inside">
16
+ <?php foreach ($ntOpts as $indx=>$pbo){ if (trim($pbo['nName']=='')) $pbo['nName'] = $pbo[$ntInfo['defNName']]; ?>
17
+ <p style="margin:0px;margin-left:5px;">
18
+ <input value="1" name="<?php echo $ntInfo['lcode']; ?>[<?php echo $indx; ?>][apDo<?php echo $ntInfo['code']; ?>]" onchange="doShowHideBlocks('<?php echo $ntInfo['code']; ?>');" type="checkbox" <?php if ((int)$pbo['do'.$ntInfo['code']] == 1) echo "checked"; ?> /> <?php if ((int)$pbo['catSel'] == 1) { ?> <span onmouseout="nxs_hidePopUpInfo('popOnlyCat');" onmouseover="nxs_showPopUpInfo('popOnlyCat', event);"><?php echo "*[".(substr_count($pbo['catSelEd'], ",")+1)."]*" ?></span><?php } ?>
19
+ <strong><?php _e('Auto-publish to', 'nxs_snap'); ?> <?php echo $ntInfo['name']; ?> <i style="color: #005800;"><?php if($pbo['nName']!='') echo "(".$pbo['nName'].")"; ?></i></strong>
20
+ &nbsp;&nbsp;<?php if ($ntInfo['tstReq'] && (!isset($pbo[$ntInfo['lcode'].'OK']) || $pbo[$ntInfo['lcode'].'OK']=='')){ ?><b style="color: #800000"><?php _e('Attention requred. Unfinished setup', 'nxs_snap'); ?> ==&gt;</b><?php } ?><a id="do<?php echo $ntInfo['code'].$indx; ?>A" href="#" onclick="doShowHideBlocks2('<?php echo $ntInfo['code'].$indx; ?>');return false;">[<?php _e('Show Settings', 'nxs_snap'); ?>]</a>&nbsp;&nbsp;
21
+ <a href="#" onclick="doDelAcct('<?php echo $ntInfo['lcode']; ?>', '<?php echo $indx; ?>', '<?php if (isset($pbo['bgBlogID'])) echo $pbo['nName']; ?>');return false;">[<?php _e('Remove Account', 'nxs_snap'); ?>]</a>
22
+ </p><?php $this->showNTSettings($indx, $pbo);
23
+ }?>
24
+ </div>
25
+ </div> <?php
26
+ }
27
+ //#### Show NEW Settings Page
28
+ function showNewNTSettings($mgpo){ $gpo = array('nName'=>'', 'doFF'=>'1', 'ffUName'=>'', 'ffPageID'=>'', 'ffAttch'=>'', 'ffPass'=>''); $this->showNTSettings($mgpo, $gpo, true);}
29
+ //#### Show Unit Settings
30
+ function showNTSettings($ii, $gpo, $isNew=false){ global $nxs_plurl;
31
+ if (!isset($gpo['nHrs'])) $gpo['nHrs'] = 0; if (!isset($gpo['nMin'])) $gpo['nMin'] = 0; if (!isset($gpo['catSel'])) $gpo['catSel'] = 0; if (!isset($gpo['catSelEd'])) $gpo['catSelEd'] = '';
32
+ if (!isset($gpo['nDays'])) $gpo['nDays'] = 0; if (!isset($gpo['qTLng'])) $gpo['qTLng'] = ''; ?>
33
+
34
+ <div id="doFF<?php echo $ii; ?>Div" class="insOneDiv<?php if ($isNew) echo " clNewNTSets"; ?>" style="max-width: 1000px; background-color: #EBF4FB; background-image: url(<?php echo $nxs_plurl; ?>img/ff-bg.png); background-position:90% 10%; background-repeat: no-repeat; margin: 10px; border: 1px solid #808080; padding: 10px; display:none;"> <input type="hidden" name="apDoSFF<?php echo $ii; ?>" value="0" id="apDoSFF<?php echo $ii; ?>" />
35
+
36
+ <div class="nsx_iconedTitle" style="float: right; background-image: url(<?php echo $nxs_plurl; ?>img/ff16.png);"><a style="font-size: 12px;" target="_blank" href="http://www.nextscripts.com/setup-installation-FriendFeed-social-networks-auto-poster-wordpress/"><?php $nType="FriendFeed"; printf( __( 'Detailed %s Installation/Configuration Instructions', 'nxs_snap' ), $nType); ?></a></div>
37
+
38
+ <div style="width:100%;"><strong><?php _e('Account Nickname', 'nxs_snap'); ?>:</strong> <i><?php _e('Just so you can easely identify it', 'nxs_snap'); ?></i> </div><input name="ff[<?php echo $ii; ?>][nName]" id="ffnName<?php echo $ii; ?>" style="font-weight: bold; color: #005800; border: 1px solid #ACACAC; width: 40%;" value="<?php _e(apply_filters('format_to_edit',htmlentities($gpo['nName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /><br/>
39
+ <?php echo nxs_addQTranslSel('ff', $ii, $gpo['qTLng']); ?><?php echo nxs_addPostingDelaySel('ff', $ii, $gpo['nHrs'], $gpo['nMin']); ?>
40
+
41
+ <?php if (!$isNew) { ?>
42
+ <div style="width:100%;"><strong><?php _e('Categories', 'nxs_snap'); ?>:</strong>
43
+ <input value="0" id="catSelA<?php echo $ii; ?>" type="radio" name="ff[<?php echo $ii; ?>][catSel]" <?php if ((int)$gpo['catSel'] != 1) echo "checked"; ?> /> All
44
+ <input value="1" id="catSelSFF<?php echo $ii; ?>" type="radio" name="ff[<?php echo $ii; ?>][catSel]" <?php if ((int)$gpo['catSel'] == 1) echo "checked"; ?> /> <a href="#" style="text-decoration: none;" class="showCats" id="nxs_SCA_FF<?php echo $ii; ?>" onclick="jQuery('#catSelSFF<?php echo $ii; ?>').attr('checked', true); jQuery('#tmpCatSelNT').val('FF<?php echo $ii; ?>'); nxs_markCats( jQuery('#nxs_SC_FF<?php echo $ii; ?>').val() ); jQuery('#showCatSel').bPopup({ modalClose: false, appendTo: '#nsStForm', opacity: 0.6, follow: [false, false], position: [75, 'auto']}); return false;">Selected<?php if ($gpo['catSelEd']!='') echo "[".(substr_count($gpo['catSelEd'], ",")+1)."]"; ?></a>
45
+ <input type="hidden" name="ff[<?php echo $ii; ?>][catSelEd]" id="nxs_SC_FF<?php echo $ii; ?>" value="<?php echo $gpo['catSelEd']; ?>" />
46
+ <br/><i><?php _e('Only selected categories will be autoposted to this account', 'nxs_snap'); ?></i></div>
47
+ <br/>
48
+ <?php } ?>
49
+
50
+ <div style="width:100%;"><strong>FriendFeed nickname:</strong> <span style="font-size: 11px; margin: 0px;">Get it from <a target="_blank" href="https://friendfeed.com/account/api">https://friendfeed.com/account/api</a>.</span></div><input name="ff[<?php echo $ii; ?>][apFFUName]" id="apFFUName" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit',htmlentities($gpo['ffUName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
51
+ <div style="width:100%;"><strong>FriendFeed remote key:</strong> <span style="font-size: 11px; margin: 0px;">Get it from <a target="_blank" href="https://friendfeed.com/account/api">https://friendfeed.com/account/api</a>.</span>
52
+
53
+ </div><input name="ff[<?php echo $ii; ?>][apFFPass]" id="apFFPass" type="password" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities(substr($gpo['ffPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($gpo['ffPass'], 5)):$gpo['ffPass'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /> <br/>
54
+
55
+ <div style="width:100%;"><br/><strong>Group ID:</strong> [Optional] Please specify Group ID. <i>Use this <b>only</b> if you are posting NOT to your own feed. </i></div>
56
+ <input name="ff[<?php echo $ii; ?>][grpID]" id="grpID" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($gpo['grpID'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
57
+
58
+ <?php if ($isNew) { ?> <input type="hidden" name="ff[<?php echo $ii; ?>][apDoFF]" value="1" id="apDoNewFF<?php echo $ii; ?>" /> <?php } ?>
59
+ <br/> <br/>
60
+
61
+ <div id="altFormat" style="">
62
+ <div style="width:100%;"><strong id="altFormatText"><?php _e('Post Text Format', 'nxs_snap'); ?></strong> (<a href="#" id="apFFMsgFrmt<?php echo $ii; ?>HintInfo" onclick="mxs_showHideFrmtInfo('apFFMsgFrmt<?php echo $ii; ?>'); return false;"><?php _e('Show format info', 'nxs_snap'); ?></a>)</div>
63
+ <input name="ff[<?php echo $ii; ?>][apFFMsgFrmt]" id="apFFMsgFrmt" style="width: 50%;" value="<?php if ($isNew) echo "%TITLE% - %URL% %EXCERPT%"; else _e(apply_filters('format_to_edit',htmlentities($gpo['ffMsgFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap'); ?>" onfocus="mxs_showFrmtInfo('apFFMsgFrmt<?php echo $ii; ?>');" /><?php nxs_doShowHint("apFFMsgFrmt".$ii); ?>
64
+ </div>
65
+ <p style="margin: 0px;"><input value="1" id="apLIAttch" type="checkbox" name="ff[<?php echo $ii; ?>][attchImg]" <?php if ((int)$gpo['attchImg'] == 1) echo "checked"; ?> /> <strong><?php _e('Attach Image to FriendFeed Post', 'nxs_snap'); ?></strong></p>
66
+ <br/>
67
+
68
+ <?php if ($gpo['ffPass']!='') { ?>
69
+ <?php wp_nonce_field( 'rePostToFF', 'rePostToFF_wpnonce' ); ?>
70
+ <b><?php _e('Test your settings', 'nxs_snap'); ?>:</b>&nbsp;&nbsp;&nbsp; <a href="#" class="NXSButton" onclick="testPost('FF', '<?php echo $ii; ?>'); return false;"><?php printf( __( 'Submit Test Post to %s', 'nxs_snap' ), $nType); ?></a>
71
+
72
+ <?php }
73
+
74
+ ?><div class="submit"><input type="submit" class="button-primary" name="update_NS_SNAutoPoster_settings" value="<?php _e('Update Settings', 'nxs_snap') ?>" /></div></div><?php
75
+ }
76
+ //#### Set Unit Settings from POST
77
+ function setNTSettings($post, $options){ global $nxs_snapThisPageUrl; $code = 'FF'; $lcode = 'ff';
78
+ foreach ($post as $ii => $pval){
79
+ if (isset($pval['apFFUName']) && $pval['apFFUName']!=''){ if (!isset($options[$ii])) $options[$ii] = array();
80
+ if (isset($pval['apFFUName'])) $options[$ii]['ffUName'] = trim($pval['apFFUName']);
81
+ if (isset($pval['nName'])) $options[$ii]['nName'] = trim($pval['nName']);
82
+ if (isset($pval['apFFPass'])) $options[$ii]['ffPass'] = 'n5g9a'.nsx_doEncode($pval['apFFPass']); else $options[$ii]['ffPass'] = '';
83
+
84
+ if (isset($pval['catSel'])) $options[$ii]['catSel'] = trim($pval['catSel']);
85
+ if ($options[$ii]['catSel']=='1' && trim($pval['catSelEd'])!='') $options[$ii]['catSelEd'] = trim($pval['catSelEd']); else $options[$ii]['catSelEd'] = '';
86
+
87
+ if (isset($pval['apFFMsgFrmt'])) $options[$ii]['ffMsgFormat'] = trim($pval['apFFMsgFrmt']);
88
+ if (isset($pval['grpID'])) $options[$ii]['grpID'] = trim($pval['grpID']);
89
+ if (isset($pval['attchImg'])) $options[$ii]['attchImg'] = $pval['attchImg']; else $options[$ii]['attchImg'] = 0;
90
+ if (isset($pval['apDoFF'])) $options[$ii]['doFF'] = $pval['apDoFF']; else $options[$ii]['doFF'] = 0;
91
+ if (isset($pval['delayHrs'])) $options[$ii]['nHrs'] = trim($pval['delayHrs']); if (isset($pval['delayMin'])) $options[$ii]['nMin'] = trim($pval['delayMin']);
92
+ if (isset($pval['qTLng'])) $options[$ii]['qTLng'] = trim($pval['qTLng']);
93
+ }
94
+ } return $options;
95
+ }
96
+ //#### Show Post->Edit Meta Box Settings
97
+ function showEdPostNTSettings($ntOpts, $post){ global $nxs_plurl; $post_id = $post->ID;
98
+ foreach($ntOpts as $ii=>$ntOpt) { $pMeta = maybe_unserialize(get_post_meta($post_id, 'snapFF', true)); if (is_array($pMeta)) $ntOpt = $this->adjMetaOpt($ntOpt, $pMeta[$ii]);
99
+ $doFF = $ntOpt['doFF'] && (is_array($pMeta) || $ntOpt['catSel']!='1');
100
+ $isAvailFF = $ntOpt['ffUName']!='' && $ntOpt['ffPass']!=''; $ffMsgFormat = htmlentities($ntOpt['ffMsgFormat'], ENT_COMPAT, "UTF-8"); $ffMsgTFormat = htmlentities($ntOpt['ffMsgTFormat'], ENT_COMPAT, "UTF-8");
101
+ $isAttchImg = $ntOpt['attchImg'];
102
+ ?>
103
+ <tr><th style="text-align:left;" colspan="2"><?php if ( $ntOpt['catSel']=='1' && trim($ntOpt['catSelEd'])!='' ) { ?> <input type="hidden" class="nxs_SC" id="nxs_SC_FF<?php echo $ii; ?>" value="<?php echo $ntOpt['catSelEd']; ?>" /> <?php } ?>
104
+ <?php if ($isAvailFF) { ?><input class="nxsGrpDoChb" value="1" id="doFF<?php echo $ii; ?>" <?php if ($post->post_status == "publish") echo 'disabled="disabled"';?> type="checkbox" name="ff[<?php echo $ii; ?>][doFF]" <?php if ((int)$doFF == 1) echo 'checked="checked" title="def"'; ?> />
105
+ <?php if ($post->post_status == "publish") { ?> <input type="hidden" name="ff[<?php echo $ii; ?>][doFF]" value="<?php echo $doFF;?>"> <?php } ?> <?php } ?>
106
+
107
+ <div class="nsx_iconedTitle" style="display: inline; font-size: 13px; background-image: url(<?php echo $nxs_plurl; ?>img/ff16.png);">FriendFeed - <?php _e('publish to', 'nxs_snap') ?> (<i style="color: #005800;"><?php echo $ntOpt['nName']; ?></i>)</div></th> <td><?php //## Only show RePost button if the post is "published"
108
+ if ($post->post_status == "publish" && $isAvailFF) { ?><input alt="<?php echo $ii; ?>" style="float: right;" onmouseout="hidePopShAtt('SV');" onmouseover="showPopShAtt('SV', event);" onclick="return false;" type="button" class="button" name="rePostToFF_repostButton" id="rePostToFF_button" value="<?php _e('Repost to FriendFeed', 'nxs_snap') ?>" />
109
+ <?php wp_nonce_field( 'rePostToFF', 'rePostToFF_wpnonce' ); } ?>
110
+
111
+ <?php if (is_array($pMeta) && is_array($pMeta[$ii]) && isset($pMeta[$ii]['pgID']) ) {
112
+ ?> <span id="pstdFF<?php echo $ii; ?>" style="float: right; padding-top: 4px; padding-right: 10px;">
113
+ <a style="font-size: 10px;" href="http://www.FriendFeed.com/e/<?php echo $pMeta[$ii]['pgID']; ?>" target="_blank"><?php $nType="FriendFeed"; printf( __( 'Posted on', 'nxs_snap' ), $nType); ?> <?php echo (isset($pMeta[$ii]['pDate']) && $pMeta[$ii]['pDate']!='')?(" (".$pMeta[$ii]['pDate'].")"):""; ?></a>
114
+ </span><?php } ?>
115
+
116
+ </td></tr>
117
+
118
+ <tr><th scope="row" style="text-align:right; width:150px; vertical-align:top; padding-top: 5px; padding-right:10px;">
119
+ <input value="0" type="hidden" name="ff[<?php echo $ii; ?>][attchImg]"/>
120
+ <input value="1" type="checkbox" name="ff[<?php echo $ii; ?>][attchImg]" <?php if ((int)$isAttchImg == 1) echo "checked"; ?> /> </th><td><strong>Attach Image to FriendFeed Post</strong></td> </tr>
121
+
122
+ <?php if (!$isAvailFF) { ?><tr><th scope="row" style="text-align:right; width:150px; padding-top: 5px; padding-right:10px;"></th> <td><b>Setup your FriendFeed Account to AutoPost to FriendFeed</b>
123
+ <?php } elseif ($post->post_status != "pubZlish") { ?>
124
+
125
+ <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top: 6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Title Format:', 'nxs_snap') ?></th>
126
+ <td><input value="<?php echo $ffMsgFormat ?>" type="text" name="ff[<?php echo $ii; ?>][SNAPformatT]" style="width:60%;max-width: 610px;" onfocus="jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apFFMsgFrmt<?php echo $ii; ?>');"/><?php nxs_doShowHint("apFFMsgFrmt".$ii, '', '58'); ?></td></tr>
127
+
128
+ <?php }
129
+ }
130
+ }
131
+ //#### Save Meta Tags to the Post
132
+ function adjMetaOpt($optMt, $pMeta){ if (isset($pMeta['isPosted'])) $optMt['isPosted'] = $pMeta['isPosted']; else $optMt['isPosted'] = '';
133
+ if (isset($pMeta['SNAPformat'])) $optMt['ffMsgFormat'] = $pMeta['SNAPformat'];
134
+ if (isset($pMeta['attchImg'])) $optMt['attchImg'] = $pMeta['attchImg'] == 1?1:0; else { if (isset($pMeta['attchImg'])) $optMt['attchImg'] = 0; }
135
+
136
+ if (isset($pMeta['doFF'])) $optMt['doFF'] = $pMeta['doFF'] == 1?1:0; else { if (isset($pMeta['SNAPformat'])) $optMt['doFF'] = 0; }
137
+ if (isset($pMeta['SNAPincludeFF']) && $pMeta['SNAPincludeFF'] == '1' ) $optMt['doFF'] = 1;
138
+ return $optMt;
139
+ }
140
+ }}
141
+ if (!function_exists("nxs_rePostToFF_ajax")) {
142
+ function nxs_rePostToFF_ajax() { check_ajax_referer('rePostToFF'); $postID = $_POST['id']; $options = get_option('NS_SNAutoPoster');
143
+ foreach ($options['ff'] as $ii=>$two) if ($ii==$_POST['nid']) { $two['ii'] = $ii; $two['pType'] = 'aj'; //if ($two['gpPageID'].$two['gpUName']==$_POST['nid']) {
144
+ $gppo = get_post_meta($postID, 'snapFF', true); $gppo = maybe_unserialize($gppo);// prr($gppo);
145
+ if (is_array($gppo) && isset($gppo[$ii]) && is_array($gppo[$ii])){ $ntClInst = new nxs_snapClassFF(); $two = $ntClInst->adjMetaOpt($two, $gppo[$ii]);}
146
+ $result = nxs_doPublishToFF($postID, $two); if ($result == 200) die("Successfully sent your post to FriendFeed."); else die($result);
147
+ }
148
+ }
149
+ }
150
+
151
+ if (!function_exists("nxs_getFFHeaders")) { function nxs_getFFHeaders($up){ $hdrsArr = array();
152
+ $hdrsArr['Cache-Control']='no-cache'; $hdrsArr['Connection']='keep-alive';
153
+ $hdrsArr['User-Agent']='SNAP for Wordpress; Ver '.NextScripts_SNAP_Version;
154
+ $hdrsArr['Accept']='text/html, application/xhtml+xml, */*'; $hdrsArr['DNT']='1';
155
+ $hdrsArr['Content-Type']='application/x-www-form-urlencoded';
156
+ $hdrsArr['Authorization'] = 'Basic ' . base64_encode("$up");
157
+ //$hdrsArr['Authorization'] = $up;
158
+ $hdrsArr['Accept-Encoding']='gzip,deflate'; $hdrsArr['Accept-Language']='en-US,en;q=0.8'; $hdrsArr['Accept-Charset']='ISO-8859-1,utf-8;q=0.7,*;q=0.3'; return $hdrsArr;
159
+ }}
160
+
161
+ if (!function_exists("nxs_doPublishToFF")) { //## Second Function to Post to FF
162
+ function nxs_doPublishToFF($postID, $options){ $ntCd = 'FF'; $ntCdL = 'ff'; $ntNm = 'FriendFeed';
163
+ //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToFF', array($postID, $options));
164
+
165
+ $ii = $options['ii']; if (!isset($options['pType'])) $options['pType'] = 'im'; if ($options['pType']=='sh') sleep(rand(1, 10));
166
+ $logNT = '<span style="color:#000080">FriendFeed</span> - '.$options['nName'];
167
+ $snap_ap = get_post_meta($postID, 'snap'.$ntCd, true); $snap_ap = maybe_unserialize($snap_ap);
168
+ if ($options['pType']!='aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
169
+ $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted!='2') { sleep(5);
170
+ nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:'.$postID, 'Already posted. No reason for posting duplicate'.' |'.$uqID); return;
171
+ }
172
+ }
173
+
174
+ if ($postID=='0') { echo "Testing ... <br/><br/>"; $link = home_url(); $msg = 'Test Link from '.$link; } else { $post = get_post($postID); if(!$post) return; $link = get_permalink($postID);
175
+ $msgFormat = $options['ffMsgFormat']; $msgTFormat = $options['ffMsgTFormat']; $msgT = nsFormatMessage($msgTFormat, $postID); $msg = nsFormatMessage($msgFormat, $postID);
176
+ nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted'=>'1'));
177
+ }
178
+ $extInfo = ' | PostID: '.$postID." - ".$post->post_title;
179
+ $dusername = $options['ffUName']; $pass = (substr($options['ffPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($options['ffPass'], 5)):$options['ffPass']);
180
+ $link = urlencode($link); $ext = urlencode(substr($msg, 0, 1000));
181
+ // API/V2 if we ever switch - $postArr = array('body'=>$msg, 'link'=>'', 'to'=>($options['grpID']!=''?$options['grpID']:'me'), 'image_url'=>($imgURL!=''?$imgURL:'me'), 'short'=>0); prr($postArr);
182
+
183
+ if ($options['attchImg']=='1') $imgURL = nxs_getPostImage($postID, 'full'); else $imgURL = '';
184
+ $postArr = array('title'=>$msg, 'image0_link'=>'', 'room'=>($options['grpID']!=''?$options['grpID']:''), 'image0_url'=>($imgURL!=''?$imgURL:''));
185
+ $apicall = "http://friendfeed.com/api/share"; $hdrsArr = nxs_getFFHeaders($dusername.':'.$pass);
186
+ $paramcall = array( 'method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'body'=> $postArr, 'headers' => $hdrsArr);
187
+
188
+ $cnt = wp_remote_post( $apicall, $paramcall ); // prr(json_decode($cnt['body'], true));
189
+
190
+ if(is_wp_error($cnt)) {
191
+ $ret = 'Something went wrong - '.""; nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.$ret. "ERR: ".print_r($cnt, true), $extInfo);
192
+ } else {
193
+ if (is_array($cnt) && $cnt['response']['code']=='200' && is_array(json_decode($cnt['body'], true)))
194
+ { $ret = 'OK'; $retInfo = json_decode($cnt['body'], true);
195
+ nxs_metaMarkAsPosted($postID, 'FF', $options['ii'], array('isPosted'=>'1', 'pgID'=>$retInfo['entries'][0]['id'], 'pDate'=>date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); }
196
+ else { $ret = "Error: ";
197
+ if ($cnt['response']['code']=='401') $ret .= " Incorrect Username/Password ";
198
+ $ret .= $cnt['response']['message']; nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.$ret. " | ERR: ".print_r($cnt, true), $extInfo);
199
+ }
200
+ }
201
+ if ($ret!='OK') { if ($postID=='0') echo $ret; } else if ($postID=='0') { echo 'OK - Message Posted, please see your FriendFeed Page. '; nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); }
202
+ if ($ret == 'OK') return 200; else return $ret;
203
+ }
204
+ }
205
  ?>
inc-cl/gp.api.php CHANGED
@@ -1,43 +1,43 @@
1
- <?php
2
- //## NextScripts Facebook Connection Class
3
- $nxs_snapAPINts[] = array('code'=>'GP', 'lcode'=>'gp', 'name'=>'Google+');
4
-
5
- if (!class_exists("nxs_class_SNAP_GP")) { class nxs_class_SNAP_GP {
6
-
7
- var $ntCode = 'GP';
8
- var $ntLCode = 'gp';
9
-
10
- function doPost($options, $message){ if (!is_array($options)) return false;
11
- foreach ($options as $ntOpts) $out[] = $this->doPostToNT($ntOpts, $message);
12
- return $out;
13
- }
14
- function doPostToNT($options, $message){ $badOut = array('pgID'=>'', 'isPosted'=>0, 'pDate'=>date('Y-m-d H:i:s'), 'Error'=>'');
15
- //## Check API Lib
16
- if (!function_exists('doPostToGooglePlus')) if (file_exists('apis/postToGooglePlus.php')) require_once ('apis/postToGooglePlus.php'); elseif (file_exists('/home/_shared/deSrc.php')) require_once ('/home/_shared/deSrc.php');
17
- if (!function_exists('doPostToGooglePlus')) { $badOut['Error'] = 'Google+ API Library not found'; return $badOut; }
18
- //## Check settings
19
- if (!is_array($options)) { $badOut['Error'] = 'No Options'; return $badOut; }
20
- if (!isset($options['gpUName']) || trim($options['gpPass'])=='') { $badOut['Error'] = 'Not Configured'; return $badOut; }
21
- //## Make Post
22
- $gpPostType = $options['postType'];
23
-
24
- $msg = nxs_doFormatMsg($options['gpMsgFormat'], $message); // Make "message default"
25
- if ($gpPostType=='I' || $gpPostType=='A') {
26
- if (is_array($message['imageURL'])) { $imgURL = trim($message['imageURL'][$options['attchImg']]);
27
- if ($imgURL=='') $imgURL = trim($message['imageURL']['large']); if ($imgURL=='') $imgURL = trim($message['imageURL']['medium']);
28
- if ($imgURL=='') $imgURL = trim($message['imageURL']['original']); if ($imgURL=='') $imgURL = trim($message['imageURL']['thumb']);
29
- } else $imgURL = $message['imageURL'];
30
- }
31
-
32
- $email = $options['gpUName']; $pass = substr($options['gpPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($options['gpPass'], 5)):$options['gpPass'];
33
- $loginError = doConnectToGooglePlus2($email, $pass); if ($loginError!==false) { $badOut['Error'] = print_r($loginError, true)." - BAD USER/PASS"; return $badOut; }
34
- if ($gpPostType=='I') $lnk = array(); if ($gpPostType=='A') $lnk = doGetGoogleUrlInfo2($message['url']); if (is_array($lnk) && $imgURL!='') $lnk['img'] = $imgURL;
35
- if ($gpPostType=='I' && trim($message['videoURL'])!='') { $lnk['video'] = $message['videoURL']; }
36
- if (!empty($options['gpPageID'])) { $to = $options['gpPageID']; $ret = doPostToGooglePlus2($msg, $lnk, $to);}
37
- elseif (!empty($options['gpCommID'])) $ret = doPostToGooglePlus2($msg, $lnk, '', $options['gpCommID'], $options['gpCCat']); else $ret = doPostToGooglePlus2($msg, $lnk);
38
- if ( (!is_array($ret)) && $ret!='OK') { $badOut['Error'] = print_r($ret, true); } else { return array('isPosted'=>'1', 'postID'=>$ret['post_id'], 'postURL'=>'https://plus.google.com/'.$ret['post_id'], 'pDate'=>date('Y-m-d H:i:s')); }
39
- return $badOut;
40
- }
41
-
42
- }}
43
  ?>
1
+ <?php
2
+ //## NextScripts Facebook Connection Class
3
+ $nxs_snapAPINts[] = array('code'=>'GP', 'lcode'=>'gp', 'name'=>'Google+');
4
+
5
+ if (!class_exists("nxs_class_SNAP_GP")) { class nxs_class_SNAP_GP {
6
+
7
+ var $ntCode = 'GP';
8
+ var $ntLCode = 'gp';
9
+
10
+ function doPost($options, $message){ if (!is_array($options)) return false;
11
+ foreach ($options as $ntOpts) $out[] = $this->doPostToNT($ntOpts, $message);
12
+ return $out;
13
+ }
14
+ function doPostToNT($options, $message){ $badOut = array('pgID'=>'', 'isPosted'=>0, 'pDate'=>date('Y-m-d H:i:s'), 'Error'=>'');
15
+ //## Check API Lib
16
+ if (!function_exists('doPostToGooglePlus')) if (file_exists('apis/postToGooglePlus.php')) require_once ('apis/postToGooglePlus.php'); elseif (file_exists('/home/_shared/deSrc.php')) require_once ('/home/_shared/deSrc.php');
17
+ if (!function_exists('doPostToGooglePlus')) { $badOut['Error'] = 'Google+ API Library not found'; return $badOut; }
18
+ //## Check settings
19
+ if (!is_array($options)) { $badOut['Error'] = 'No Options'; return $badOut; }
20
+ if (!isset($options['gpUName']) || trim($options['gpPass'])=='') { $badOut['Error'] = 'Not Configured'; return $badOut; }
21
+ //## Make Post
22
+ $gpPostType = $options['postType'];
23
+
24
+ $msg = nxs_doFormatMsg($options['gpMsgFormat'], $message); // Make "message default"
25
+ if ($gpPostType=='I' || $gpPostType=='A') {
26
+ if (is_array($message['imageURL'])) { $imgURL = trim($message['imageURL'][$options['attchImg']]);
27
+ if ($imgURL=='') $imgURL = trim($message['imageURL']['large']); if ($imgURL=='') $imgURL = trim($message['imageURL']['medium']);
28
+ if ($imgURL=='') $imgURL = trim($message['imageURL']['original']); if ($imgURL=='') $imgURL = trim($message['imageURL']['thumb']);
29
+ } else $imgURL = $message['imageURL'];
30
+ }
31
+
32
+ $email = $options['gpUName']; $pass = substr($options['gpPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($options['gpPass'], 5)):$options['gpPass'];
33
+ $loginError = doConnectToGooglePlus2($email, $pass); if ($loginError!==false) { $badOut['Error'] = print_r($loginError, true)." - BAD USER/PASS"; return $badOut; }
34
+ if ($gpPostType=='I') $lnk = array(); if ($gpPostType=='A') $lnk = doGetGoogleUrlInfo2($message['url']); if (is_array($lnk) && $imgURL!='') $lnk['img'] = $imgURL;
35
+ if ($gpPostType=='I' && trim($message['videoURL'])!='') { $lnk['video'] = $message['videoURL']; }
36
+ if (!empty($options['gpPageID'])) { $to = $options['gpPageID']; $ret = doPostToGooglePlus2($msg, $lnk, $to);}
37
+ elseif (!empty($options['gpCommID'])) $ret = doPostToGooglePlus2($msg, $lnk, '', $options['gpCommID'], $options['gpCCat']); else $ret = doPostToGooglePlus2($msg, $lnk);
38
+ if ( (!is_array($ret)) && $ret!='OK') { $badOut['Error'] = print_r($ret, true); } else { return array('isPosted'=>'1', 'postID'=>$ret['post_id'], 'postURL'=>'https://plus.google.com/'.$ret['post_id'], 'pDate'=>date('Y-m-d H:i:s')); }
39
+ return $badOut;
40
+ }
41
+
42
+ }}
43
  ?>
inc-cl/gp.php CHANGED
@@ -1,239 +1,246 @@
1
- <?php
2
- //## NextScripts Facebook Connection Class
3
- $nxs_snapAvNts[] = array('code'=>'GP', 'lcode'=>'gp', 'name'=>'Google+');
4
-
5
- if (!class_exists("nxs_snapClassGP")) { class nxs_snapClassGP {
6
- //#### Show Common Settings
7
- function showGenNTSettings($ntOpts){ global $nxs_plurl; $ntInfo = array('code'=>'GP', 'lcode'=>'gp', 'name'=>'Google+', 'defNName'=>'gpUName', 'tstReq' => false); ?>
8
- <div class="nxs_box">
9
- <div class="nxs_box_header">
10
- <div class="nsx_iconedTitle" style="margin-bottom:1px;background-image:url(<?php echo $nxs_plurl;?>img/<?php echo $ntInfo['lcode']; ?>16.png);"><?php echo $ntInfo['name']; ?>
11
- <?php $cbo = count($ntOpts); ?> <?php wp_nonce_field( 'ns'.$ntInfo['code'], 'ns'.$ntInfo['code'].'_wpnonce' ); ?>
12
- <?php if ($cbo>1){ ?><div class="nsBigText"><?php echo "(".($cbo=='0'?'No':$cbo)." "; _e('accounts', 'nxs_snap'); echo ")"; ?></div><?php } ?>
13
- </div>
14
- </div>
15
- <div class="nxs_box_inside">
16
- <?php if(!function_exists('doPostToGooglePlus')) {?> Google+ doesn't have a built-in API for automated posts yet. The current <a href="http://developers.google.com/+/api/">Google+ API</a> is "Read Only" and can't be used for posting. <br/>You need to get a special <a target="_blank" href="http://www.nextscripts.com/google-plus-automated-posting">library module</a> to be able to publish your content to Google+.
17
- <?php } else foreach ($ntOpts as $indx=>$pbo){ if (trim($pbo['nName']=='')) $pbo['nName'] = $pbo[$ntInfo['defNName']]; ?>
18
- <p style="margin:0px;margin-left:5px;">
19
- <input value="1" name="<?php echo $ntInfo['lcode']; ?>[<?php echo $indx; ?>][apDo<?php echo $ntInfo['code']; ?>]" onchange="doShowHideBlocks('<?php echo $ntInfo['code']; ?>');" type="checkbox" <?php if ((int)$pbo['do'.$ntInfo['code']] == 1) echo "checked"; ?> /> <?php if ((int)$pbo['catSel'] == 1) { ?> <span onmouseout="nxs_hidePopUpInfo('popOnlyCat');" onmouseover="nxs_showPopUpInfo('popOnlyCat', event);"><?php echo "*[".(substr_count($pbo['catSelEd'], ",")+1)."]*" ?></span><?php } ?>
20
- <strong><?php _e('Auto-publish to', 'nxs_snap'); ?> <?php echo $ntInfo['name']; ?> <i style="color: #005800;"><?php if($pbo['nName']!='') echo "(".$pbo['nName'].")"; ?></i></strong>
21
- &nbsp;&nbsp;<?php if ($ntInfo['tstReq'] && (!isset($pbo[$ntInfo['lcode'].'OK']) || $pbo[$ntInfo['lcode'].'OK']=='')){ ?><b style="color: #800000"><?php _e('Attention requred. Unfinished setup', 'nxs_snap'); ?> ==&gt;</b><?php } ?><a id="do<?php echo $ntInfo['code'].$indx; ?>A" href="#" onclick="doShowHideBlocks2('<?php echo $ntInfo['code'].$indx; ?>');return false;">[<?php _e('Show Settings', 'nxs_snap'); ?>]</a>&nbsp;&nbsp;
22
- <a href="#" onclick="doDelAcct('<?php echo $ntInfo['lcode']; ?>', '<?php echo $indx; ?>', '<?php if (isset($pbo['bgBlogID'])) echo $pbo['nName']; ?>');return false;">[<?php _e('Remove Account', 'nxs_snap'); ?>]</a>
23
- </p><?php $this->showNTSettings($indx, $pbo);
24
- }?>
25
- </div>
26
- </div> <?php
27
- }
28
- //#### Show NEW Settings Page
29
- function showNewNTSettings($mgpo){ $options = array('nName'=>'', 'doGP'=>'1', 'gpUName'=>'', 'gpPageID'=>'', 'gpCommID'=>'', 'postType'=>'A', 'gpPass'=>''); $this->showNTSettings($mgpo, $options, true);}
30
- //#### Show Unit Settings
31
- function showNTSettings($ii, $options, $isNew=false){ global $nxs_plurl; ?>
32
- <div id="doGP<?php echo $ii; ?>Div" class="insOneDiv<?php if ($isNew) echo " clNewNTSets"; ?>" style="background-image: url(<?php echo $nxs_plurl; ?>img/gp-bg.png); background-position:90% 10%;"> <input type="hidden" name="apDoSGP<?php echo $ii; ?>" value="0" id="apDoSGP<?php echo $ii; ?>" />
33
- <?php if(!function_exists('doPostToGooglePlus')) {?><span style="color:#580000; font-size: 16px;"><br/><br/>
34
- <b><?php _e('Google+ API Library not found', 'nxs_snap'); ?></b>
35
- <br/><br/> <?php _e('Google+ doesn\'t have a built-in API for automated posts yet.', 'nxs_snap'); ?> <br/><?php _e('The current <a target="_blank" href="http://developers.google.com/+/api/">Google+ API</a> is "Read Only" and can\'t be used for posting. <br/><br/>You need to get a special <a target="_blank" href="http://www.nextscripts.com/google-plus-automated-posting"><b>API Library Module</b></a> to be able to publish your content to Google+.', 'nxs_snap'); ?></span></div>
36
- <?php return; }; ?>
37
- <div class="nsx_iconedTitle" style="float: right; background-image: url(<?php echo $nxs_plurl; ?>img/gp16.png);"><a style="font-size: 12px;" target="_blank" href="http://www.nextscripts.com/setup-installation-google-plus-social-networks-auto-poster-wordpress/"><?php $nType="Google+"; printf( __( 'Detailed %s Installation/Configuration Instructions', 'nxs_snap' ), $nType); ?></a></div>
38
-
39
- <div style="width:100%;"><strong><?php _e('Account Nickname', 'nxs_snap'); ?>:</strong> <i><?php _e('Just so you can easely identify it', 'nxs_snap'); ?></i> </div><input name="gp[<?php echo $ii; ?>][nName]" id="gpnName<?php echo $ii; ?>" style="font-weight: bold; color: #005800; border: 1px solid #ACACAC; width: 40%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['nName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /><br/>
40
- <?php echo nxs_addQTranslSel('gp', $ii, $options['qTLng']); ?><?php echo nxs_addPostingDelaySel('gp', $ii, $options['nHrs'], $options['nMin']); ?>
41
-
42
- <?php if (!$isNew) { ?>
43
- <div style="width:100%;"><strong><?php _e('Categories', 'nxs_snap'); ?>:</strong>
44
- <input value="0" id="catSelA<?php echo $ii; ?>" type="radio" name="gp[<?php echo $ii; ?>][catSel]" <?php if ((int)$options['catSel'] != 1) echo "checked"; ?> /> All
45
- <input value="1" id="catSelSGP<?php echo $ii; ?>" type="radio" name="gp[<?php echo $ii; ?>][catSel]" <?php if ((int)$options['catSel'] == 1) echo "checked"; ?> /> <a href="#" style="text-decoration: none;" class="showCats" id="nxs_SCA_GP<?php echo $ii; ?>" onclick="jQuery('#catSelSGP<?php echo $ii; ?>').attr('checked', true); jQuery('#tmpCatSelNT').val('GP<?php echo $ii; ?>'); nxs_markCats( jQuery('#nxs_SC_GP<?php echo $ii; ?>').val() ); jQuery('#showCatSel').bPopup({ modalClose: false, appendTo: '#nsStForm', opacity: 0.6, follow: [false, false], position: [75, 'auto']}); return false;">Selected<?php if ($options['catSelEd']!='') echo "[".(substr_count($options['catSelEd'], ",")+1)."]"; ?></a>
46
- <input type="hidden" name="gp[<?php echo $ii; ?>][catSelEd]" id="nxs_SC_GP<?php echo $ii; ?>" value="<?php echo $options['catSelEd']; ?>" />
47
- <br/><i><?php _e('Only selected categories will be autoposted to this account', 'nxs_snap'); ?></i></div>
48
- <br/>
49
- <?php } ?>
50
-
51
- <div style="width:100%;"><strong>Google+ Username:</strong> </div><input name="gp[<?php echo $ii; ?>][apGPUName]" id="apGPUName<?php echo $ii; ?>" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['gpUName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
52
- <div style="width:100%;"><strong>Google+ Password:</strong> </div><input name="gp[<?php echo $ii; ?>][apGPPass]" id="apGPPass<?php echo $ii; ?>" type="password" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities(substr($options['gpPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($options['gpPass'], 5)):$options['gpPass'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /> <br/>
53
- <p><div style="width:100%;"><strong>Google+ Page ID (Optional - for Google+ Pages Only. <b style="color: #580000;"> <?php _e('Leave Empty to publish to your profile or community', 'nxs_snap'); ?></b>):</strong>
54
- <p style="font-size: 11px; margin: 0px;">For example if URL of your page is https://plus.google.com/u/0/b/117008619877691455570/ your Page ID is: 117008619877691455570. <b><?php _e('Leave Empty to publish to your profile or community.', 'nxs_snap'); ?></b></p>
55
- </div><input name="gp[<?php echo $ii; ?>][apGPPage]" id="apGPPage" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['gpPageID'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
56
- <br/>
57
- <p><div style="width:100%;"><strong>Google+ Community ID (Optional - for Google+ Communities Only. <b style="color: #580000;"> <?php _e('Leave Empty to publish to your profile or page', 'nxs_snap'); ?></b>):</strong>
58
- <p style="font-size: 11px; margin: 0px;">For example if URL of your Community is https://plus.google.com/communities/100396001601096060160 your Page ID is: 100396001601096060160. <b><?php _e('Leave Empty to publish to your profile or page', 'nxs_snap'); ?>.</b></p>
59
- </div><input name="gp[<?php echo $ii; ?>][gpCommID]" id="gpCommID<?php echo $ii; ?>" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['gpCommID'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />&nbsp;&nbsp;
60
- <a href="#" onclick="getGPCats(jQuery('<?php if ($isNew) echo "#nsx_addNT "; ?>#apGPUName<?php echo $ii; ?>').val(), jQuery('<?php if ($isNew) echo "#nsx_addNT "; ?>#apGPPass<?php echo $ii; ?>').val(), '<?php echo $ii; ?>', jQuery('<?php if ($isNew) echo "#nsx_addNT "; ?>#gpCommID<?php echo $ii; ?>').val()); return false;">
61
- <?php _e('Retreive Categories', 'nxs_snap'); ?>
62
- </a>
63
- <div style="padding-left: 15px; width:100%;"><strong>Community Category:</strong>
64
- <?php wp_nonce_field( 'getGPCats', 'getGPCats_wpnonce' ); ?><img id="gpLoadingImg<?php echo $ii; ?>" style="display: none;" src='<?php echo $nxs_plurl; ?>img/ajax-loader-sm.gif' />
65
- <select name="gp[<?php echo $ii; ?>][apGPCCats]" id="apGPCCats<?php echo $ii; ?>">
66
- <?php if ($options['gpCCatsList']!=''){ $gGPCats = $options['gpCCatsList']; if ( base64_encode(base64_decode($gGPCats)) === $gGPCats) $gGPCats = base64_decode($gGPCats);
67
- if ($options['gpCCat']!='') $gGPCats = str_replace($options['gpCCat'].'"', $options['gpCCat'].'" selected="selected"', $gGPCats); echo $gGPCats;} else { ?>
68
- <option value="0">None(Click above to retrieve your categories)</option>
69
- <?php } ?>
70
- </select> </div>
71
-
72
- <br/><br/>
73
-
74
- <div id="altFormat" style="">
75
- <div style="width:100%;"><strong id="altFormatText"><?php _e('Message text Format', 'nxs_snap'); ?>:</strong> (<a href="#" id="apGPMsgFrmt<?php echo $ii; ?>HintInfo" onclick="mxs_showHideFrmtInfo('apGPMsgFrmt<?php echo $ii; ?>'); return false;"><?php _e('Show format info', 'nxs_snap'); ?></a>)
76
- </div>
77
-
78
- <textarea cols="150" rows="3" id="gp<?php echo $ii; ?>SNAPformat" name="gp[<?php echo $ii; ?>][apGPMsgFrmt]" style="width:51%;max-width: 650px;" onfocus="jQuery('#gp<?php echo $ii; ?>SNAPformat').attr('rows', 6); mxs_showFrmtInfo('apGPMsgFrmt<?php echo $ii; ?>');"><?php if ($isNew) _e("New post (%TITLE%) has been published on %SITENAME%", 'nxs_snap'); else _e(apply_filters('format_to_edit', htmlentities($options['gpMsgFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap'); ?></textarea>
79
-
80
- <?php nxs_doShowHint("apGPMsgFrmt".$ii); ?>
81
- </div><br/>
82
-
83
- <div style="width:100%;"><strong id="altFormatText">Post Type:</strong>&lt;-- (<a id="showShAtt" onmouseout="hidePopShAtt('<?php echo $ii; ?>XG');" onmouseover="showPopShAtt('<?php echo $ii; ?>XG', event);" onclick="return false;" class="underdash" href="http://www.nextscripts.com/blog/"><?php _e('What\'s the difference?', 'nxs_snap'); ?></a>) </div>
84
- <div style="margin-left: 10px;">
85
- <?php if(!isset($options['postType']) || $options['postType']=='') {
86
- if ((int)$options['imgPost'] == 1) $options['postType'] = 'I';
87
- if ((int)$options['gpAttch'] == 1 || $isNew) $options['postType'] = 'A';
88
- } ?>
89
- <input type="radio" name="gp[<?php echo $ii; ?>][postType]" value="T" <?php if ($options['postType'] == 'T') echo 'checked="checked"'; ?> /> <?php _e('Text Post', 'nxs_snap'); ?> - <i><?php _e('just text message', 'nxs_snap'); ?></i><br/>
90
- <input type="radio" name="gp[<?php echo $ii; ?>][postType]" value="I" <?php if ($options['postType'] == 'I') echo 'checked="checked"'; ?> /> <?php _e('Google+ Image Post', 'nxs_snap'); ?> - <i><?php _e('big image with text message', 'nxs_snap'); ?></i><br/>
91
- <input type="radio" name="gp[<?php echo $ii; ?>][postType]" value="A" <?php if ( !isset($options['postType']) || $options['postType'] == '' || $options['postType'] == 'A') echo 'checked="checked"'; ?> /> <?php _e('Add blogpost to Google+ message as an attachment', 'nxs_snap'); ?><br/>
92
- <div class="popShAtt" id="popShAtt<?php echo $ii; ?>XG"><h3><?php _e('Google+ Post Types', 'nxs_snap'); ?></h3><img src="<?php echo $nxs_plurl; ?>img/gpPostTypesDiff6.png" width="600" height="285" alt="<?php _e('Google+ Post Types', 'nxs_snap'); ?>"/></div>
93
- </div><br/>
94
- <?php if ($isNew) { ?> <input type="hidden" name="gp[<?php echo $ii; ?>][apDoGP]" value="1" id="apDoNewGP<?php echo $ii; ?>" /> <?php } ?>
95
- <?php if ($options['gpPass']!='') { ?>
96
- <?php wp_nonce_field( 'rePostToGP', 'rePostToGP_wpnonce' ); ?>
97
- <b><?php _e('Test your settings', 'nxs_snap'); ?>:</b>&nbsp;&nbsp;&nbsp; <a href="#" class="NXSButton" onclick="testPost('GP', '<?php echo $ii; ?>'); return false;"><?php printf( __( 'Submit Test Post to %s', 'nxs_snap' ), $nType); ?></a> <?php }
98
- ?><div class="submit"><input type="submit" class="button-primary" name="update_NS_SNAutoPoster_settings" value="<?php _e('Update Settings', 'nxs_snap') ?>" /></div></div><?php
99
- }
100
- //#### Set Unit Settings from POST
101
- function setNTSettings($post, $options){ global $nxs_snapThisPageUrl; $code = 'GP'; $lcode = 'gp';
102
- foreach ($post as $ii => $pval){
103
- if (isset($pval['apGPUName']) && $pval['apGPUName']!=''){ if (!isset($options[$ii])) $options[$ii] = array();
104
- if (isset($pval['apGPUName'])) $options[$ii]['gpUName'] = trim($pval['apGPUName']);
105
- if (isset($pval['nName'])) $options[$ii]['nName'] = trim($pval['nName']);
106
- if (isset($pval['apGPPass'])) $options[$ii]['gpPass'] = 'n5g9a'.nsx_doEncode($pval['apGPPass']); else $options[$ii]['gpPass'] = '';
107
- if (isset($pval['apGPPage'])) $options[$ii]['gpPageID'] = trim($pval['apGPPage']);
108
- if (isset($pval['gpCommID'])) $options[$ii]['gpCommID'] = trim($pval['gpCommID']);
109
-
110
- if (isset($pval['catSel'])) $options[$ii]['catSel'] = trim($pval['catSel']);
111
- if ($options[$ii]['catSel']=='1' && trim($pval['catSelEd'])!='') $options[$ii]['catSelEd'] = trim($pval['catSelEd']); else $options[$ii]['catSelEd'] = '';
112
- if (isset($pval['apGPCCats'])) $options[$ii]['gpCCat'] = trim($pval['apGPCCats']);
113
-
114
- if (isset($pval['postType'])) $options[$ii]['postType'] = $pval['postType'];
115
- if (isset($pval['apGPMsgFrmt'])) $options[$ii]['gpMsgFormat'] = trim($pval['apGPMsgFrmt']);
116
- if (isset($pval['apDoGP'])) $options[$ii]['doGP'] = $pval['apDoGP']; else $options[$ii]['doGP'] = 0;
117
- if (isset($pval['delayHrs'])) $options[$ii]['nHrs'] = trim($pval['delayHrs']); if (isset($pval['delayMin'])) $options[$ii]['nMin'] = trim($pval['delayMin']);
118
- if (isset($pval['qTLng'])) $options[$ii]['qTLng'] = trim($pval['qTLng']);
119
- }
120
- } return $options;
121
- }
122
- //#### Show Post->Edit Meta Box Settings
123
- function showEdPostNTSettings($ntOpts, $post){ global $nxs_plurl; $post_id = $post->ID;
124
- foreach($ntOpts as $ii=>$ntOpt) { $pMeta = maybe_unserialize(get_post_meta($post_id, 'snapGP', true)); if (is_array($pMeta)) $ntOpt = $this->adjMetaOpt($ntOpt, $pMeta[$ii]);
125
- $doGP = $ntOpt['doGP'] && (is_array($pMeta) || $ntOpt['catSel']!='1');
126
- $isAvailGP = $ntOpt['gpUName']!='' && $ntOpt['gpPass']!=''; $gpMsgFormat = htmlentities($ntOpt['gpMsgFormat'], ENT_COMPAT, "UTF-8");
127
- if(!isset($ntOpt['postType']) || $ntOpt['postType']=='') {
128
- if ((int)$ntOpt['imgPost'] == 1) $ntOpt['postType'] = 'I';
129
- if ((int)$ntOpt['gpAttch'] == 1 || $isNew) $ntOpt['postType'] = 'A';
130
- } $gpPostType = $ntOpt['postType'];
131
- ?>
132
- <tr><th style="text-align:left;" colspan="2"><?php if ( $ntOpt['catSel']=='1' && trim($ntOpt['catSelEd'])!='' ) { ?> <input type="hidden" class="nxs_SC" id="nxs_SC_GP<?php echo $ii; ?>" value="<?php echo $ntOpt['catSelEd']; ?>" /> <?php } ?>
133
- <?php if ($isAvailGP) { ?><input class="nxsGrpDoChb" value="1" id="doGP<?php echo $ii; ?>" <?php if ($post->post_status == "publish") echo 'disabled="disabled"';?> type="checkbox" name="gp[<?php echo $ii; ?>][doGP]" <?php if ((int)$doGP == 1) echo 'checked="checked" title="def"'; ?> />
134
- <?php if ($post->post_status == "publish") { ?> <input type="hidden" name="gp[<?php echo $ii; ?>][doGP]" value="<?php echo $doGP;?>"> <?php } ?> <?php } ?>
135
-
136
- <div class="nsx_iconedTitle" style="display: inline; font-size: 13px; background-image: url(<?php echo $nxs_plurl; ?>img/gp16.png);">Google+ - <?php _e('publish to', 'nxs_snap') ?> (<i style="color: #005800;"><?php echo $ntOpt['nName']; ?></i>)</div></th> <td><?php //## Only show RePost button if the post is "published"
137
- if ($post->post_status == "publish" && $isAvailGP) { ?><input alt="<?php echo $ii; ?>" style="float: right;" onmouseout="hidePopShAtt('SV');" onmouseover="showPopShAtt('SV', event);" onclick="return false;" type="button" class="button" name="rePostToGP_repostButton" id="rePostToGP_button" value="<?php _e('Repost to Google+', 'nxs_snap') ?>" />
138
- <?php wp_nonce_field( 'rePostToGP', 'rePostToGP_wpnonce' ); } ?>
139
-
140
- <?php if (is_array($pMeta) && is_array($pMeta[$ii]) && isset($pMeta[$ii]['pgID']) ) {
141
-
142
- ?> <span id="pstdGP<?php echo $ii; ?>" style="float: right;padding-top: 4px; padding-right: 10px;">
143
- <a style="font-size: 10px;" href="https://plus.google.com/<?php echo $pMeta[$ii]['pgID']; ?>" target="_blank"><?php $nType="Google+"; printf( __( 'Posted on', 'nxs_snap' ), $nType); ?> <?php echo (isset($pMeta[$ii]['pDate']) && $pMeta[$ii]['pDate']!='')?(" (".$pMeta[$ii]['pDate'].")"):""; ?></a>
144
- </span><?php } ?>
145
-
146
- </td></tr>
147
-
148
- <?php if (!$isAvailGP) { ?><tr><th scope="row" style="text-align:right; width:150px; padding-top: 5px; padding-right:10px;"></th> <td><b>Setup your Google+ Account to AutoPost to Google+</b>
149
- <?php } elseif ($post->post_status != "puZblish") { ?>
150
-
151
- <tr><th scope="row" style="text-align:right; width:150px; vertical-align:top; padding-top: 0px; padding-right:10px;"> <?php _e('Post Type:', 'nxs_snap') ?> <br/>
152
- (<a id="showShAtt" style="font-weight: normal" onmouseout="hidePopShAtt('<?php echo $ii; ?>XG');" onmouseover="showPopShAtt('<?php echo $ii; ?>XG', event);" onclick="return false;" class="underdash" href="http://www.nextscripts.com/blog/"><?php _e('What\'s the difference?', 'nxs_snap'); ?></a>)
153
- </th><td>
154
-
155
- <input type="radio" name="gp[<?php echo $ii; ?>][postType]" value="T" <?php if ($gpPostType == 'T') echo 'checked="checked"'; ?> /> <?php _e('Text Post', 'nxs_snap') ?> - <i><?php _e('just text message', 'nxs_snap') ?></i><br/>
156
- <input type="radio" name="gp[<?php echo $ii; ?>][postType]" value="I" <?php if ($gpPostType == 'I') echo 'checked="checked"'; ?> /> <?php _e('Post to Google+ as "Image post"', 'nxs_snap') ?> - <i><?php _e('big image with text message', 'nxs_snap') ?></i><br/>
157
- <input type="radio" name="gp[<?php echo $ii; ?>][postType]" value="A" <?php if ( !isset($gpPostType) || $gpPostType == '' || $gpPostType == 'A') echo 'checked="checked"'; ?> /><?php _e('Text Post with "attached" blogpost', 'nxs_snap') ?>
158
- <div class="popShAtt" id="popShAtt<?php echo $ii; ?>XG"><h3><?php _e('Google+ Post Types', 'nxs_snap') ?></h3><img src="<?php echo $nxs_plurl; ?>img/gpPostTypesDiff6.png" width="600" height="285" alt="<?php _e('Google+ Post Types', 'nxs_snap') ?>"/></div>
159
- </td></tr>
160
- <?php if ($ntOpt['gpCommID']!='') { ?>
161
- <tr><th scope="row" style="text-align:right; width:150px; padding-top: 5px; padding-right:10px;">Community Category</th>
162
- <td><select name="gp[<?php echo $ii; ?>][apGPCCat]" id="apGPCCat">
163
- <?php if ($ntOpt['gpCCatsList']!=''){ $gCats = $ntOpt['gpCCatsList']; if ( base64_encode(base64_decode($gCats)) === $gCats) $gCats = base64_decode($gCats);
164
- if ($ntOpt['gpCCat']!='') $gCats = str_replace($ntOpt['gpCCat'].'"', $ntOpt['gpCCat'].'" selected="selected"', $gCats); echo $gCats;} else { ?>
165
- <option value="0">None(Please go to settings and retreive)</option>
166
- <?php } ?>
167
- </select></td>
168
- </tr>
169
- <?php } ?>
170
- <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top: 6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Message Format:', 'nxs_snap') ?></th>
171
- <td>
172
-
173
- <?php if (1==1) { ?>
174
- <textarea cols="150" rows="1" id="gp<?php echo $ii; ?>SNAPformat" name="gp[<?php echo $ii; ?>][SNAPformat]" style="width:60%;max-width: 610px;" onfocus="jQuery('#gp<?php echo $ii; ?>SNAPformat').attr('rows', 4); jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apGPMsgFrmt<?php echo $ii; ?>');"><?php echo $gpMsgFormat ?></textarea>
175
- <?php } else { ?>
176
- <input value="<?php echo $gpMsgFormat ?>" type="text" name="gp[<?php echo $ii; ?>][SNAPformat]" style="width:60%;max-width: 610px;" onfocus="jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apGPMsgFrmt<?php echo $ii; ?>');"/><?php nxs_doShowHint("apGPMsgFrmt".$ii); ?>
177
- <?php } ?>
178
-
179
-
180
- </td></tr>
181
- <?php }
182
- }
183
- }
184
- //#### Save Meta Tags to the Post
185
- function adjMetaOpt($optMt, $pMeta){ if (isset($pMeta['isPosted'])) $optMt['isPosted'] = $pMeta['isPosted']; else $optMt['isPosted'] = '';
186
- if (isset($pMeta['SNAPformat'])) $optMt['gpMsgFormat'] = $pMeta['SNAPformat'];
187
- if (isset($pMeta['postType'])) $optMt['postType'] = $pMeta['postType'];
188
- if (isset($pMeta['apGPCCat']) && $pMeta['apGPCCat']!='' && $pMeta['apGPCCat']!='0') $optMt['gpCCat'] = $pMeta['apGPCCat'];
189
- if (isset($pMeta['doGP'])) $optMt['doGP'] = $pMeta['doGP'] == 1?1:0; else { if (isset($pMeta['SNAPformat'])) $optMt['doGP'] = 0; }
190
- if (isset($pMeta['SNAPincludeGP']) && $pMeta['SNAPincludeGP'] == '1' ) $optMt['doGP'] = 1;
191
- return $optMt;
192
- }
193
- }}
194
- if (!function_exists("nxs_rePostToGP_ajax")) {
195
- function nxs_rePostToGP_ajax() { check_ajax_referer('rePostToGP'); $postID = $_POST['id']; global $plgn_NS_SNAutoPoster; if (!isset($plgn_NS_SNAutoPoster)) return; $options = $plgn_NS_SNAutoPoster->nxs_options;
196
- foreach ($options['gp'] as $ii=>$two) if ($ii==$_POST['nid']) { $two['ii'] = $ii; $two['pType'] = 'aj'; //if ($two['gpPageID'].$two['gpUName']==$_POST['nid']) {
197
- $gppo = get_post_meta($postID, 'snapGP', true); $gppo = maybe_unserialize($gppo);// prr($gppo);
198
- if (is_array($gppo) && isset($gppo[$ii]) && is_array($gppo[$ii])){ $ntClInst = new nxs_snapClassGP(); $two = $ntClInst->adjMetaOpt($two, $gppo[$ii]); }
199
- $result = nxs_doPublishToGP($postID, $two); if ($result == 200) die("Successfully sent your post to Google+."); else die($result);
200
- }
201
- }
202
- }
203
- if (!function_exists("nxs_doPublishToGP")) { //## Second Function to Post to G+
204
- function nxs_doPublishToGP($postID, $options){ $ntCd = 'GP'; $ntCdL = 'gp'; $ntNm = 'Google+';
205
- if(!function_exists('doConnectToGooglePlus2') || !function_exists('doPostToGooglePlus2')) { nxs_addToLogN('E', 'Error', $ntCd, '-=ERROR=- No G+ API Lib Detected', ''); return "No G+ API Lib Detected";}
206
- $ii = $options['ii']; if (!isset($options['pType'])) $options['pType'] = 'im'; if ($options['pType']=='sh') sleep(rand(1, 10));
207
- $logNT = '<span style="color:#800000">Google+</span> - '.$options['nName'];
208
- $snap_ap = get_post_meta($postID, 'snap'.$ntCd, true); $snap_ap = maybe_unserialize($snap_ap);
209
- if ($options['pType']!='aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
210
- $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted!='2') {
211
- nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:'.$postID, 'Already posted. No reason for posting duplicate'.' |'.$uqID); return;
212
- }
213
- }
214
-
215
- $message = array('message'=>'', 'link'=>'', 'imageURL'=>'', 'videoURL'=>'');
216
-
217
- if ($postID=='0') { echo "Testing ... <br/><br/>"; $options['gpMsgFormat'] = "Test Post from ". htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES)." - ".home_url(); $message['url'] = home_url();
218
- } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted'=>'1')); $post = get_post($postID); if(!$post) return;
219
- $gpMsgFormat = $options['gpMsgFormat']; $gpPostType = $options['postType']; $msg = nsFormatMessage($gpMsgFormat, $postID); $options['gpMsgFormat'] = $msg;
220
- $extInfo = ' | PostID: '.$postID." - ".$post->post_title;
221
- if($gpPostType=='I') { $vids = nsFindVidsInPost($post, false); if (count($vids)>0) $ytCode = $vids[0]; if (trim($ytCode)=='') $options['trPostType']='T'; }
222
- if ($gpPostType=='A') $imgURL = nxs_getPostImage($postID, 'medium'); if ($gpPostType=='I') $imgURL = nxs_getPostImage($postID, 'full');
223
- $message = array('message'=>$msg, 'url'=>get_permalink($postID), 'imageURL'=>$imgURL, 'videoCode'=>$ytCode);
224
- }
225
- //## Actual Post
226
- $ntToPost = new nxs_class_SNAP_GP(); $ret = $ntToPost->doPostToNT($options, $message);
227
- //## Process Results
228
- if (!is_array($ret) || $ret['isPosted']!='1') { //## Error
229
- if ($postID=='0') prr($ret); nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.print_r($ret, true), $extInfo);
230
- } else { // ## All Good - log it.
231
- if ($postID=='0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo _e('OK - Message Posted, please see your '.$logNT.' Page. ', 'nxs_snap'); }
232
- else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted'=>'1', 'pgID'=>$ret['postID'], 'pDate'=>date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); }
233
- }
234
- //## Return Result
235
- if ($ret['isPosted']=='1') return 200; else return print_r($ret, true);
236
-
237
- }
238
- }
 
 
 
 
 
 
 
239
  ?>
1
+ <?php
2
+ //## NextScripts Facebook Connection Class
3
+ $nxs_snapAvNts[] = array('code'=>'GP', 'lcode'=>'gp', 'name'=>'Google+');
4
+
5
+ if (!class_exists("nxs_snapClassGP")) { class nxs_snapClassGP {
6
+ //#### Show Common Settings
7
+ function showGenNTSettings($ntOpts){ global $nxs_plurl; $ntInfo = array('code'=>'GP', 'lcode'=>'gp', 'name'=>'Google+', 'defNName'=>'gpUName', 'tstReq' => false); ?>
8
+ <div class="nxs_box">
9
+ <div class="nxs_box_header">
10
+ <div class="nsx_iconedTitle" style="margin-bottom:1px;background-image:url(<?php echo $nxs_plurl;?>img/<?php echo $ntInfo['lcode']; ?>16.png);"><?php echo $ntInfo['name']; ?>
11
+ <?php $cbo = count($ntOpts); ?> <?php wp_nonce_field( 'ns'.$ntInfo['code'], 'ns'.$ntInfo['code'].'_wpnonce' ); ?>
12
+ <?php if ($cbo>1){ ?><div class="nsBigText"><?php echo "(".($cbo=='0'?'No':$cbo)." "; _e('accounts', 'nxs_snap'); echo ")"; ?></div><?php } ?>
13
+ </div>
14
+ </div>
15
+ <div class="nxs_box_inside">
16
+ <?php if(!function_exists('doPostToGooglePlus')) {?> Google+ doesn't have a built-in API for automated posts yet. The current <a href="http://developers.google.com/+/api/">Google+ API</a> is "Read Only" and can't be used for posting. <br/>You need to get a special <a target="_blank" href="http://www.nextscripts.com/google-plus-automated-posting">library module</a> to be able to publish your content to Google+.
17
+ <?php } else foreach ($ntOpts as $indx=>$pbo){ if (trim($pbo['nName']=='')) $pbo['nName'] = $pbo[$ntInfo['defNName']]; ?>
18
+ <p style="margin:0px;margin-left:5px;">
19
+ <input value="1" name="<?php echo $ntInfo['lcode']; ?>[<?php echo $indx; ?>][apDo<?php echo $ntInfo['code']; ?>]" onchange="doShowHideBlocks('<?php echo $ntInfo['code']; ?>');" type="checkbox" <?php if ((int)$pbo['do'.$ntInfo['code']] == 1) echo "checked"; ?> /> <?php if ((int)$pbo['catSel'] == 1) { ?> <span onmouseout="nxs_hidePopUpInfo('popOnlyCat');" onmouseover="nxs_showPopUpInfo('popOnlyCat', event);"><?php echo "*[".(substr_count($pbo['catSelEd'], ",")+1)."]*" ?></span><?php } ?>
20
+ <strong><?php _e('Auto-publish to', 'nxs_snap'); ?> <?php echo $ntInfo['name']; ?> <i style="color: #005800;"><?php if($pbo['nName']!='') echo "(".$pbo['nName'].")"; ?></i></strong>
21
+ &nbsp;&nbsp;<?php if ($ntInfo['tstReq'] && (!isset($pbo[$ntInfo['lcode'].'OK']) || $pbo[$ntInfo['lcode'].'OK']=='')){ ?><b style="color: #800000"><?php _e('Attention requred. Unfinished setup', 'nxs_snap'); ?> ==&gt;</b><?php } ?><a id="do<?php echo $ntInfo['code'].$indx; ?>A" href="#" onclick="doShowHideBlocks2('<?php echo $ntInfo['code'].$indx; ?>');return false;">[<?php _e('Show Settings', 'nxs_snap'); ?>]</a>&nbsp;&nbsp;
22
+ <a href="#" onclick="doDelAcct('<?php echo $ntInfo['lcode']; ?>', '<?php echo $indx; ?>', '<?php if (isset($pbo['bgBlogID'])) echo $pbo['nName']; ?>');return false;">[<?php _e('Remove Account', 'nxs_snap'); ?>]</a>
23
+ </p><?php $this->showNTSettings($indx, $pbo);
24
+ }?>
25
+ </div>
26
+ </div> <?php
27
+ }
28
+ //#### Show NEW Settings Page
29
+ function showNewNTSettings($mgpo){ $options = array('nName'=>'', 'doGP'=>'1', 'gpUName'=>'', 'gpPageID'=>'', 'gpCommID'=>'', 'postType'=>'A', 'gpPass'=>''); $this->showNTSettings($mgpo, $options, true);}
30
+ //#### Show Unit Settings
31
+ function showNTSettings($ii, $options, $isNew=false){ global $nxs_plurl;
32
+ if (!isset($options['nHrs'])) $options['nHrs'] = 0; if (!isset($options['nMin'])) $options['nMin'] = 0; if (!isset($options['catSel'])) $options['catSel'] = 0; if (!isset($options['catSelEd'])) $options['catSelEd'] = '';
33
+ if (!isset($options['nDays'])) $options['nDays'] = 0; if (!isset($options['qTLng'])) $options['qTLng'] = ''; ?>
34
+ <div id="doGP<?php echo $ii; ?>Div" class="insOneDiv<?php if ($isNew) echo " clNewNTSets"; ?>" style="background-image: url(<?php echo $nxs_plurl; ?>img/gp-bg.png); background-position:90% 10%;"> <input type="hidden" name="apDoSGP<?php echo $ii; ?>" value="0" id="apDoSGP<?php echo $ii; ?>" />
35
+ <?php if(!function_exists('doPostToGooglePlus')) {?><span style="color:#580000; font-size: 16px;"><br/><br/>
36
+ <b><?php _e('Google+ API Library not found', 'nxs_snap'); ?></b>
37
+ <br/><br/> <?php _e('Google+ doesn\'t have a built-in API for automated posts yet.', 'nxs_snap'); ?> <br/><?php _e('The current <a target="_blank" href="http://developers.google.com/+/api/">Google+ API</a> is "Read Only" and can\'t be used for posting. <br/><br/>You need to get a special <a target="_blank" href="http://www.nextscripts.com/google-plus-automated-posting"><b>API Library Module</b></a> to be able to publish your content to Google+.', 'nxs_snap'); ?></span></div>
38
+ <?php return; }; ?>
39
+ <div class="nsx_iconedTitle" style="float: right; background-image: url(<?php echo $nxs_plurl; ?>img/gp16.png);"><a style="font-size: 12px;" target="_blank" href="http://www.nextscripts.com/setup-installation-google-plus-social-networks-auto-poster-wordpress/"><?php $nType="Google+"; printf( __( 'Detailed %s Installation/Configuration Instructions', 'nxs_snap' ), $nType); ?></a></div>
40
+
41
+ <div style="width:100%;"><strong><?php _e('Account Nickname', 'nxs_snap'); ?>:</strong> <i><?php _e('Just so you can easely identify it', 'nxs_snap'); ?></i> </div><input name="gp[<?php echo $ii; ?>][nName]" id="gpnName<?php echo $ii; ?>" style="font-weight: bold; color: #005800; border: 1px solid #ACACAC; width: 40%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['nName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /><br/>
42
+ <?php echo nxs_addQTranslSel('gp', $ii, $options['qTLng']); ?><?php echo nxs_addPostingDelaySel('gp', $ii, $options['nHrs'], $options['nMin'], $options['nDays']); ?>
43
+
44
+ <?php if (!$isNew) { ?>
45
+ <div style="width:100%;"><strong><?php _e('Categories', 'nxs_snap'); ?>:</strong>
46
+ <input value="0" id="catSelA<?php echo $ii; ?>" type="radio" name="gp[<?php echo $ii; ?>][catSel]" <?php if ((int)$options['catSel'] != 1) echo "checked"; ?> /> All
47
+ <input value="1" id="catSelSGP<?php echo $ii; ?>" type="radio" name="gp[<?php echo $ii; ?>][catSel]" <?php if ((int)$options['catSel'] == 1) echo "checked"; ?> /> <a href="#" style="text-decoration: none;" class="showCats" id="nxs_SCA_GP<?php echo $ii; ?>" onclick="jQuery('#catSelSGP<?php echo $ii; ?>').attr('checked', true); jQuery('#tmpCatSelNT').val('GP<?php echo $ii; ?>'); nxs_markCats( jQuery('#nxs_SC_GP<?php echo $ii; ?>').val() ); jQuery('#showCatSel').bPopup({ modalClose: false, appendTo: '#nsStForm', opacity: 0.6, follow: [false, false], position: [75, 'auto']}); return false;">Selected<?php if ($options['catSelEd']!='') echo "[".(substr_count($options['catSelEd'], ",")+1)."]"; ?></a>
48
+ <input type="hidden" name="gp[<?php echo $ii; ?>][catSelEd]" id="nxs_SC_GP<?php echo $ii; ?>" value="<?php echo $options['catSelEd']; ?>" />
49
+ <br/><i><?php _e('Only selected categories will be autoposted to this account', 'nxs_snap'); ?></i></div>
50
+ <br/>
51
+ <?php } ?>
52
+
53
+ <div style="width:100%;"><strong>Google+ Username:</strong> </div><input name="gp[<?php echo $ii; ?>][apGPUName]" id="apGPUName<?php echo $ii; ?>" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['gpUName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
54
+ <div style="width:100%;"><strong>Google+ Password:</strong> </div><input name="gp[<?php echo $ii; ?>][apGPPass]" id="apGPPass<?php echo $ii; ?>" type="password" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities(substr($options['gpPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($options['gpPass'], 5)):$options['gpPass'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /> <br/>
55
+ <p><div style="width:100%;"><strong>Google+ Page ID (Optional - for Google+ Pages Only. <b style="color: #580000;"> <?php _e('Leave Empty to publish to your profile or community', 'nxs_snap'); ?></b>):</strong>
56
+ <p style="font-size: 11px; margin: 0px;">For example if URL of your page is https://plus.google.com/u/0/b/117008619877691455570/ your Page ID is: 117008619877691455570. <b><?php _e('Leave Empty to publish to your profile or community.', 'nxs_snap'); ?></b></p>
57
+ </div><input name="gp[<?php echo $ii; ?>][apGPPage]" id="apGPPage" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['gpPageID'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
58
+ <br/>
59
+ <p><div style="width:100%;"><strong>Google+ Community ID (Optional - for Google+ Communities Only. <b style="color: #580000;"> <?php _e('Leave Empty to publish to your profile or page', 'nxs_snap'); ?></b>):</strong>
60
+ <p style="font-size: 11px; margin: 0px;">For example if URL of your Community is https://plus.google.com/communities/100396001601096060160 your Page ID is: 100396001601096060160. <b><?php _e('Leave Empty to publish to your profile or page', 'nxs_snap'); ?>.</b></p>
61
+ </div><input name="gp[<?php echo $ii; ?>][gpCommID]" id="gpCommID<?php echo $ii; ?>" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['gpCommID'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />&nbsp;&nbsp;
62
+ <a href="#" onclick="getGPCats(jQuery('<?php if ($isNew) echo "#nsx_addNT "; ?>#apGPUName<?php echo $ii; ?>').val(), jQuery('<?php if ($isNew) echo "#nsx_addNT "; ?>#apGPPass<?php echo $ii; ?>').val(), '<?php echo $ii; ?>', jQuery('<?php if ($isNew) echo "#nsx_addNT "; ?>#gpCommID<?php echo $ii; ?>').val()); return false;">
63
+ <?php _e('Retreive Categories', 'nxs_snap'); ?>
64
+ </a>
65
+ <div style="padding-left: 15px; width:100%;"><strong>Community Category:</strong>
66
+ <?php wp_nonce_field( 'getGPCats', 'getGPCats_wpnonce' ); ?><img id="gpLoadingImg<?php echo $ii; ?>" style="display: none;" src='<?php echo $nxs_plurl; ?>img/ajax-loader-sm.gif' />
67
+ <select name="gp[<?php echo $ii; ?>][apGPCCats]" id="apGPCCats<?php echo $ii; ?>">
68
+ <?php if ($options['gpCCatsList']!=''){ $gGPCats = $options['gpCCatsList']; if ( base64_encode(base64_decode($gGPCats)) === $gGPCats) $gGPCats = base64_decode($gGPCats);
69
+ if ($options['gpCCat']!='') $gGPCats = str_replace($options['gpCCat'].'"', $options['gpCCat'].'" selected="selected"', $gGPCats); echo $gGPCats;} else { ?>
70
+ <option value="0">None(Click above to retrieve your categories)</option>
71
+ <?php } ?>
72
+ </select> </div>
73
+
74
+ <br/><br/>
75
+
76
+ <div id="altFormat" style="">
77
+ <div style="width:100%;"><strong id="altFormatText"><?php _e('Message text Format', 'nxs_snap'); ?>:</strong> (<a href="#" id="apGPMsgFrmt<?php echo $ii; ?>HintInfo" onclick="mxs_showHideFrmtInfo('apGPMsgFrmt<?php echo $ii; ?>'); return false;"><?php _e('Show format info', 'nxs_snap'); ?></a>)
78
+ </div>
79
+
80
+ <textarea cols="150" rows="3" id="gp<?php echo $ii; ?>SNAPformat" name="gp[<?php echo $ii; ?>][apGPMsgFrmt]" style="width:51%;max-width: 650px;" onfocus="jQuery('#gp<?php echo $ii; ?>SNAPformat').attr('rows', 6); mxs_showFrmtInfo('apGPMsgFrmt<?php echo $ii; ?>');"><?php if ($isNew) _e("New post (%TITLE%) has been published on %SITENAME%", 'nxs_snap'); else _e(apply_filters('format_to_edit', htmlentities($options['gpMsgFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap'); ?></textarea>
81
+
82
+ <?php nxs_doShowHint("apGPMsgFrmt".$ii); ?>
83
+ </div><br/>
84
+
85
+ <div style="width:100%;"><strong id="altFormatText">Post Type:</strong>&lt;-- (<a id="showShAtt" onmouseout="hidePopShAtt('<?php echo $ii; ?>XG');" onmouseover="showPopShAtt('<?php echo $ii; ?>XG', event);" onclick="return false;" class="underdash" href="http://www.nextscripts.com/blog/"><?php _e('What\'s the difference?', 'nxs_snap'); ?></a>) </div>
86
+ <div style="margin-left: 10px;">
87
+ <?php if(!isset($options['postType']) || $options['postType']=='') {
88
+ if ((int)$options['imgPost'] == 1) $options['postType'] = 'I';
89
+ if ((int)$options['gpAttch'] == 1 || $isNew) $options['postType'] = 'A';
90
+ } ?>
91
+ <input type="radio" name="gp[<?php echo $ii; ?>][postType]" value="T" <?php if ($options['postType'] == 'T') echo 'checked="checked"'; ?> /> <?php _e('Text Post', 'nxs_snap'); ?> - <i><?php _e('just text message', 'nxs_snap'); ?></i><br/>
92
+ <input type="radio" name="gp[<?php echo $ii; ?>][postType]" value="I" <?php if ($options['postType'] == 'I') echo 'checked="checked"'; ?> /> <?php _e('Google+ Image Post', 'nxs_snap'); ?> - <i><?php _e('big image with text message', 'nxs_snap'); ?></i><br/>
93
+ <input type="radio" name="gp[<?php echo $ii; ?>][postType]" value="A" <?php if ( !isset($options['postType']) || $options['postType'] == '' || $options['postType'] == 'A') echo 'checked="checked"'; ?> /> <?php _e('Add blogpost to Google+ message as an attachment', 'nxs_snap'); ?><br/>
94
+ <div class="popShAtt" id="popShAtt<?php echo $ii; ?>XG"><h3><?php _e('Google+ Post Types', 'nxs_snap'); ?></h3><img src="<?php echo $nxs_plurl; ?>img/gpPostTypesDiff6.png" width="600" height="285" alt="<?php _e('Google+ Post Types', 'nxs_snap'); ?>"/></div>
95
+ </div><br/>
96
+ <?php if ($isNew) { ?> <input type="hidden" name="gp[<?php echo $ii; ?>][apDoGP]" value="1" id="apDoNewGP<?php echo $ii; ?>" /> <?php } ?>
97
+ <?php if ($options['gpPass']!='') { ?>
98
+ <?php wp_nonce_field( 'rePostToGP', 'rePostToGP_wpnonce' ); ?>
99
+ <b><?php _e('Test your settings', 'nxs_snap'); ?>:</b>&nbsp;&nbsp;&nbsp; <a href="#" class="NXSButton" onclick="testPost('GP', '<?php echo $ii; ?>'); return false;"><?php printf( __( 'Submit Test Post to %s', 'nxs_snap' ), $nType); ?></a> <?php }
100
+ ?><div class="submit"><input type="submit" class="button-primary" name="update_NS_SNAutoPoster_settings" value="<?php _e('Update Settings', 'nxs_snap') ?>" /></div></div><?php
101
+ }
102
+ //#### Set Unit Settings from POST
103
+ function setNTSettings($post, $options){ global $nxs_snapThisPageUrl; $code = 'GP'; $lcode = 'gp';
104
+ foreach ($post as $ii => $pval){
105
+ if (isset($pval['apGPUName']) && $pval['apGPUName']!=''){ if (!isset($options[$ii])) $options[$ii] = array();
106
+ if (isset($pval['apGPUName'])) $options[$ii]['gpUName'] = trim($pval['apGPUName']);
107
+ if (isset($pval['nName'])) $options[$ii]['nName'] = trim($pval['nName']);
108
+ if (isset($pval['apGPPass'])) $options[$ii]['gpPass'] = 'n5g9a'.nsx_doEncode($pval['apGPPass']); else $options[$ii]['gpPass'] = '';
109
+ if (isset($pval['apGPPage'])) $options[$ii]['gpPageID'] = trim($pval['apGPPage']);
110
+ if (isset($pval['gpCommID'])) $options[$ii]['gpCommID'] = trim($pval['gpCommID']);
111
+
112
+ if (isset($pval['catSel'])) $options[$ii]['catSel'] = trim($pval['catSel']);
113
+ if ($options[$ii]['catSel']=='1' && trim($pval['catSelEd'])!='') $options[$ii]['catSelEd'] = trim($pval['catSelEd']); else $options[$ii]['catSelEd'] = '';
114
+ if (isset($pval['apGPCCats'])) $options[$ii]['gpCCat'] = trim($pval['apGPCCats']);
115
+
116
+ if (isset($pval['postType'])) $options[$ii]['postType'] = $pval['postType'];
117
+ if (isset($pval['apGPMsgFrmt'])) $options[$ii]['gpMsgFormat'] = trim($pval['apGPMsgFrmt']);
118
+ if (isset($pval['apDoGP'])) $options[$ii]['doGP'] = $pval['apDoGP']; else $options[$ii]['doGP'] = 0;
119
+ if (isset($pval['delayDays'])) $options[$ii]['nDays'] = trim($pval['delayDays']);
120
+ if (isset($pval['delayHrs'])) $options[$ii]['nHrs'] = trim($pval['delayHrs']); if (isset($pval['delayMin'])) $options[$ii]['nMin'] = trim($pval['delayMin']);
121
+ if (isset($pval['qTLng'])) $options[$ii]['qTLng'] = trim($pval['qTLng']);
122
+ }
123
+ } return $options;
124
+ }
125
+ //#### Show Post->Edit Meta Box Settings
126
+ function showEdPostNTSettings($ntOpts, $post){ global $nxs_plurl; $post_id = $post->ID;
127
+ foreach($ntOpts as $ii=>$ntOpt) { $pMeta = maybe_unserialize(get_post_meta($post_id, 'snapGP', true)); if (is_array($pMeta)) $ntOpt = $this->adjMetaOpt($ntOpt, $pMeta[$ii]);
128
+ $doGP = $ntOpt['doGP'] && (is_array($pMeta) || $ntOpt['catSel']!='1');
129
+ $isAvailGP = $ntOpt['gpUName']!='' && $ntOpt['gpPass']!=''; $gpMsgFormat = htmlentities($ntOpt['gpMsgFormat'], ENT_COMPAT, "UTF-8");
130
+ if(!isset($ntOpt['postType']) || $ntOpt['postType']=='') {
131
+ if ((int)$ntOpt['imgPost'] == 1) $ntOpt['postType'] = 'I';
132
+ if ((int)$ntOpt['gpAttch'] == 1 || $isNew) $ntOpt['postType'] = 'A';
133
+ } $gpPostType = $ntOpt['postType'];
134
+ ?>
135
+ <tr><th style="text-align:left;" colspan="2"><?php if ( $ntOpt['catSel']=='1' && trim($ntOpt['catSelEd'])!='' ) { ?> <input type="hidden" class="nxs_SC" id="nxs_SC_GP<?php echo $ii; ?>" value="<?php echo $ntOpt['catSelEd']; ?>" /> <?php } ?>
136
+ <?php if ($isAvailGP) { ?><input class="nxsGrpDoChb" value="1" id="doGP<?php echo $ii; ?>" <?php if ($post->post_status == "publish") echo 'disabled="disabled"';?> type="checkbox" name="gp[<?php echo $ii; ?>][doGP]" <?php if ((int)$doGP == 1) echo 'checked="checked" title="def"'; ?> />
137
+ <?php if ($post->post_status == "publish") { ?> <input type="hidden" name="gp[<?php echo $ii; ?>][doGP]" value="<?php echo $doGP;?>"> <?php } ?> <?php } ?>
138
+
139
+ <div class="nsx_iconedTitle" style="display: inline; font-size: 13px; background-image: url(<?php echo $nxs_plurl; ?>img/gp16.png);">Google+ - <?php _e('publish to', 'nxs_snap') ?> (<i style="color: #005800;"><?php echo $ntOpt['nName']; ?></i>)</div></th> <td><?php //## Only show RePost button if the post is "published"
140
+ if ($post->post_status == "publish" && $isAvailGP) { ?><input alt="<?php echo $ii; ?>" style="float: right;" onmouseout="hidePopShAtt('SV');" onmouseover="showPopShAtt('SV', event);" onclick="return false;" type="button" class="button" name="rePostToGP_repostButton" id="rePostToGP_button" value="<?php _e('Repost to Google+', 'nxs_snap') ?>" />
141
+ <?php wp_nonce_field( 'rePostToGP', 'rePostToGP_wpnonce' ); } ?>
142
+
143
+ <?php if (is_array($pMeta) && is_array($pMeta[$ii]) && isset($pMeta[$ii]['pgID']) ) {
144
+
145
+ ?> <span id="pstdGP<?php echo $ii; ?>" style="float: right;padding-top: 4px; padding-right: 10px;">
146
+ <a style="font-size: 10px;" href="https://plus.google.com/<?php echo $pMeta[$ii]['pgID']; ?>" target="_blank"><?php $nType="Google+"; printf( __( 'Posted on', 'nxs_snap' ), $nType); ?> <?php echo (isset($pMeta[$ii]['pDate']) && $pMeta[$ii]['pDate']!='')?(" (".$pMeta[$ii]['pDate'].")"):""; ?></a>
147
+ </span><?php } ?>
148
+
149
+ </td></tr>
150
+
151
+ <?php if (!$isAvailGP) { ?><tr><th scope="row" style="text-align:right; width:150px; padding-top: 5px; padding-right:10px;"></th> <td><b>Setup your Google+ Account to AutoPost to Google+</b>
152
+ <?php } elseif ($post->post_status != "puZblish") { ?>
153
+
154
+ <tr><th scope="row" style="text-align:right; width:150px; vertical-align:top; padding-top: 0px; padding-right:10px;"> <?php _e('Post Type:', 'nxs_snap') ?> <br/>
155
+ (<a id="showShAtt" style="font-weight: normal" onmouseout="hidePopShAtt('<?php echo $ii; ?>XG');" onmouseover="showPopShAtt('<?php echo $ii; ?>XG', event);" onclick="return false;" class="underdash" href="http://www.nextscripts.com/blog/"><?php _e('What\'s the difference?', 'nxs_snap'); ?></a>)
156
+ </th><td>
157
+
158
+ <input type="radio" name="gp[<?php echo $ii; ?>][postType]" value="T" <?php if ($gpPostType == 'T') echo 'checked="checked"'; ?> /> <?php _e('Text Post', 'nxs_snap') ?> - <i><?php _e('just text message', 'nxs_snap') ?></i><br/>
159
+ <input type="radio" name="gp[<?php echo $ii; ?>][postType]" value="I" <?php if ($gpPostType == 'I') echo 'checked="checked"'; ?> /> <?php _e('Post to Google+ as "Image post"', 'nxs_snap') ?> - <i><?php _e('big image with text message', 'nxs_snap') ?></i><br/>
160
+ <input type="radio" name="gp[<?php echo $ii; ?>][postType]" value="A" <?php if ( !isset($gpPostType) || $gpPostType == '' || $gpPostType == 'A') echo 'checked="checked"'; ?> /><?php _e('Text Post with "attached" blogpost', 'nxs_snap') ?>
161
+ <div class="popShAtt" id="popShAtt<?php echo $ii; ?>XG"><h3><?php _e('Google+ Post Types', 'nxs_snap') ?></h3><img src="<?php echo $nxs_plurl; ?>img/gpPostTypesDiff6.png" width="600" height="285" alt="<?php _e('Google+ Post Types', 'nxs_snap') ?>"/></div>
162
+ </td></tr>
163
+ <?php if ($ntOpt['gpCommID']!='') { ?>
164
+ <tr><th scope="row" style="text-align:right; width:150px; padding-top: 5px; padding-right:10px;">Community Category</th>
165
+ <td><select name="gp[<?php echo $ii; ?>][apGPCCat]" id="apGPCCat">
166
+ <?php if ($ntOpt['gpCCatsList']!=''){ $gCats = $ntOpt['gpCCatsList']; if ( base64_encode(base64_decode($gCats)) === $gCats) $gCats = base64_decode($gCats);
167
+ if ($ntOpt['gpCCat']!='') $gCats = str_replace($ntOpt['gpCCat'].'"', $ntOpt['gpCCat'].'" selected="selected"', $gCats); echo $gCats;} else { ?>
168
+ <option value="0">None(Please go to settings and retreive)</option>
169
+ <?php } ?>
170
+ </select></td>
171
+ </tr>
172
+ <?php } ?>
173
+ <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top: 6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Message Format:', 'nxs_snap') ?></th>
174
+ <td>
175
+
176
+ <?php if (1==1) { ?>
177
+ <textarea cols="150" rows="1" id="gp<?php echo $ii; ?>SNAPformat" name="gp[<?php echo $ii; ?>][SNAPformat]" style="width:60%;max-width: 610px;" onfocus="jQuery('#gp<?php echo $ii; ?>SNAPformat').attr('rows', 4); jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apGPMsgFrmt<?php echo $ii; ?>');"><?php echo $gpMsgFormat ?></textarea>
178
+ <?php } else { ?>
179
+ <input value="<?php echo $gpMsgFormat ?>" type="text" name="gp[<?php echo $ii; ?>][SNAPformat]" style="width:60%;max-width: 610px;" onfocus="jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apGPMsgFrmt<?php echo $ii; ?>');"/><?php nxs_doShowHint("apGPMsgFrmt".$ii); ?>
180
+ <?php } ?>
181
+
182
+
183
+ </td></tr>
184
+ <?php }
185
+ }
186
+ }
187
+ //#### Save Meta Tags to the Post
188
+ function adjMetaOpt($optMt, $pMeta){ if (isset($pMeta['isPosted'])) $optMt['isPosted'] = $pMeta['isPosted']; else $optMt['isPosted'] = '';
189
+ if (isset($pMeta['SNAPformat'])) $optMt['gpMsgFormat'] = $pMeta['SNAPformat'];
190
+ if (isset($pMeta['postType'])) $optMt['postType'] = $pMeta['postType'];
191
+ if (isset($pMeta['apGPCCat']) && $pMeta['apGPCCat']!='' && $pMeta['apGPCCat']!='0') $optMt['gpCCat'] = $pMeta['apGPCCat'];
192
+ if (isset($pMeta['doGP'])) $optMt['doGP'] = $pMeta['doGP'] == 1?1:0; else { if (isset($pMeta['SNAPformat'])) $optMt['doGP'] = 0; }
193
+ if (isset($pMeta['SNAPincludeGP']) && $pMeta['SNAPincludeGP'] == '1' ) $optMt['doGP'] = 1;
194
+ return $optMt;
195
+ }
196
+ }}
197
+ if (!function_exists("nxs_rePostToGP_ajax")) {
198
+ function nxs_rePostToGP_ajax() { check_ajax_referer('rePostToGP'); $postID = $_POST['id']; global $plgn_NS_SNAutoPoster; if (!isset($plgn_NS_SNAutoPoster)) return; $options = $plgn_NS_SNAutoPoster->nxs_options;
199
+ foreach ($options['gp'] as $ii=>$two) if ($ii==$_POST['nid']) { $two['ii'] = $ii; $two['pType'] = 'aj'; //if ($two['gpPageID'].$two['gpUName']==$_POST['nid']) {
200
+ $gppo = get_post_meta($postID, 'snapGP', true); $gppo = maybe_unserialize($gppo);// prr($gppo);
201
+ if (is_array($gppo) && isset($gppo[$ii]) && is_array($gppo[$ii])){ $ntClInst = new nxs_snapClassGP(); $two = $ntClInst->adjMetaOpt($two, $gppo[$ii]); }
202
+ $result = nxs_doPublishToGP($postID, $two); if ($result == 200) die("Successfully sent your post to Google+."); else die($result);
203
+ }
204
+ }
205
+ }
206
+ if (!function_exists("nxs_doPublishToGP")) { //## Second Function to Post to G+
207
+ function nxs_doPublishToGP($postID, $options){ $ntCd = 'GP'; $ntCdL = 'gp'; $ntNm = 'Google+'; global $plgn_NS_SNAutoPoster;
208
+ if(!function_exists('doConnectToGooglePlus2') || !function_exists('doPostToGooglePlus2')) { nxs_addToLogN('E', 'Error', $ntCd, '-=ERROR=- No G+ API Lib Detected', ''); return "No G+ API Lib Detected";}
209
+ $addParams = nxs_makeURLParams(array('NTNAME'=>$ntNm, 'NTCODE'=>$ntCd, 'POSTID'=>$postID, 'ACCNAME'=>$options['nName']));
210
+ $ii = $options['ii']; if (!isset($options['pType'])) $options['pType'] = 'im'; if ($options['pType']=='sh') sleep(rand(1, 10));
211
+ $logNT = '<span style="color:#800000">Google+</span> - '.$options['nName'];
212
+ $snap_ap = get_post_meta($postID, 'snap'.$ntCd, true); $snap_ap = maybe_unserialize($snap_ap);
213
+ if ($options['pType']!='aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
214
+ $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted!='2') {
215
+ nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:'.$postID, 'Already posted. No reason for posting duplicate'.' |'.$uqID); return;
216
+ }
217
+ }
218
+ $message = array('message'=>'', 'link'=>'', 'imageURL'=>'', 'videoURL'=>'');
219
+
220
+ if ($postID=='0') { echo "Testing ... <br/><br/>"; $options['gpMsgFormat'] = "Test Post from ". htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES)." - ".home_url(); $message['url'] = home_url();
221
+ } else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted'=>'1')); $post = get_post($postID); if(!$post) return;
222
+ $gpMsgFormat = $options['gpMsgFormat']; $gpPostType = $options['postType']; $msg = nsFormatMessage($gpMsgFormat, $postID, $addParams); $options['gpMsgFormat'] = $msg;
223
+ $extInfo = ' | PostID: '.$postID." - ".$post->post_title;
224
+ if($gpPostType=='I') { $vids = nsFindVidsInPost($post, false); if (count($vids)>0) $ytCode = $vids[0]; if (trim($ytCode)=='') $options['trPostType']='T'; }
225
+ if ($gpPostType=='A') $imgURL = nxs_getPostImage($postID, 'medium'); if ($gpPostType=='I') $imgURL = nxs_getPostImage($postID, 'full');
226
+ //## MyURL - URLToGo code
227
+ if (!isset($options['urlToUse']) || trim($options['urlToUse'])=='') $myurl = trim(get_post_meta($postID, 'snap_MYURL', true)); if ($myurl!='') $options['urlToUse'] = $myurl;
228
+ if (isset($options['urlToUse']) && trim($options['urlToUse'])!='') { $urlToGo = $options['urlToUse']; $options['useFBGURLInfo'] = true; } else $urlToGo = get_permalink($postID);
229
+ if($addParams!='') $urlToGo .= (strpos($urlToGo,'?')!==false?'&':'?').$addParams;
230
+ $message = array('message'=>$msg, 'url'=>$urlToGo, 'imageURL'=>$imgURL, 'videoCode'=>$ytCode);
231
+ }
232
+ //## Actual Post
233
+ $ntToPost = new nxs_class_SNAP_GP(); $ret = $ntToPost->doPostToNT($options, $message);
234
+ //## Process Results
235
+ if (!is_array($ret) || $ret['isPosted']!='1') { //## Error
236
+ if ($postID=='0') prr($ret); nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.print_r($ret, true), $extInfo);
237
+ } else { // ## All Good - log it.
238
+ if ($postID=='0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo _e('OK - Message Posted, please see your '.$logNT.' Page. ', 'nxs_snap'); }
239
+ else { nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted'=>'1', 'pgID'=>$ret['postID'], 'pDate'=>date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); }
240
+ }
241
+ //## Return Result
242
+ if ($ret['isPosted']=='1') return 200; else return print_r($ret, true);
243
+
244
+ }
245
+ }
246
  ?>
inc-cl/ip.php CHANGED
@@ -1,196 +1,196 @@
1
- <?php
2
- //## NextScripts Facebook Connection Class
3
- $nxs_snapAvNts[] = array('code'=>'IP', 'lcode'=>'ip', 'name'=>'Instapaper');
4
-
5
- if (!class_exists("nxs_snapClassIP")) { class nxs_snapClassIP {
6
- //#### Show Common Settings
7
- function showGenNTSettings($ntOpts){ global $nxs_plurl; $ntInfo = array('code'=>'IP', 'lcode'=>'ip', 'name'=>'Instapaper', 'defNName'=>'ipUName', 'tstReq' => false); ?>
8
- <div class="nxs_box">
9
- <div class="nxs_box_header">
10
- <div class="nsx_iconedTitle" style="margin-bottom:1px;background-image:url(<?php echo $nxs_plurl;?>img/<?php echo $ntInfo['lcode']; ?>16.png);"><?php echo $ntInfo['name']; ?>
11
- <?php $cbo = count($ntOpts); ?> <?php wp_nonce_field( 'ns'.$ntInfo['code'], 'ns'.$ntInfo['code'].'_wpnonce' ); ?>
12
- <?php if ($cbo>1){ ?><div class="nsBigText"><?php echo "(".($cbo=='0'?'No':$cbo)." "; _e('accounts', 'nxs_snap'); echo ")"; ?></div><?php } ?>
13
- </div>
14
- </div>
15
- <div class="nxs_box_inside">
16
- <?php foreach ($ntOpts as $indx=>$pbo){ if (trim($pbo['nName']=='')) $pbo['nName'] = $pbo[$ntInfo['defNName']]; ?>
17
- <p style="margin:0px;margin-left:5px;">
18
- <input value="1" name="<?php echo $ntInfo['lcode']; ?>[<?php echo $indx; ?>][apDo<?php echo $ntInfo['code']; ?>]" onchange="doShowHideBlocks('<?php echo $ntInfo['code']; ?>');" type="checkbox" <?php if ((int)$pbo['do'.$ntInfo['code']] == 1) echo "checked"; ?> /> <?php if ((int)$pbo['catSel'] == 1) { ?> <span onmouseout="nxs_hidePopUpInfo('popOnlyCat');" onmouseover="nxs_showPopUpInfo('popOnlyCat', event);"><?php echo "*[".(substr_count($pbo['catSelEd'], ",")+1)."]*" ?></span><?php } ?>
19
- <strong><?php _e('Auto-publish to', 'nxs_snap'); ?> <?php echo $ntInfo['name']; ?> <i style="color: #005800;"><?php if($pbo['nName']!='') echo "(".$pbo['nName'].")"; ?></i></strong>
20
- &nbsp;&nbsp;<?php if ($ntInfo['tstReq'] && (!isset($pbo[$ntInfo['lcode'].'OK']) || $pbo[$ntInfo['lcode'].'OK']=='')){ ?><b style="color: #800000"><?php _e('Attention requred. Unfinished setup', 'nxs_snap'); ?> ==&gt;</b><?php } ?><a id="do<?php echo $ntInfo['code'].$indx; ?>A" href="#" onclick="doShowHideBlocks2('<?php echo $ntInfo['code'].$indx; ?>');return false;">[<?php _e('Show Settings', 'nxs_snap'); ?>]</a>&nbsp;&nbsp;
21
- <a href="#" onclick="doDelAcct('<?php echo $ntInfo['lcode']; ?>', '<?php echo $indx; ?>', '<?php if (isset($pbo['bgBlogID'])) echo $pbo['nName']; ?>');return false;">[<?php _e('Remove Account', 'nxs_snap'); ?>]</a>
22
- </p><?php $this->showNTSettings($indx, $pbo);
23
- }?>
24
- </div>
25
- </div> <?php
26
- }
27
- //#### Show NEW Settings Page
28
- function showNewNTSettings($mgpo){ $gpo = array('nName'=>'', 'doIP'=>'1', 'ipUName'=>'', 'ipPageID'=>'', 'ipAttch'=>'', 'ipPass'=>''); $this->showNTSettings($mgpo, $gpo, true);}
29
- //#### Show Unit Settings
30
- function showNTSettings($ii, $gpo, $isNew=false){ global $nxs_plurl; ?>
31
- <div id="doIP<?php echo $ii; ?>Div" class="insOneDiv<?php if ($isNew) echo " clNewNTSets"; ?>" style="max-width: 1000px; background-color: #EBF4FB; background-image: url(<?php echo $nxs_plurl; ?>img/ip-bg.png); background-position:90% 10%; background-repeat: no-repeat; margin: 10px; border: 1px solid #808080; padding: 10px; display:none;"> <input type="hidden" name="apDoSIP<?php echo $ii; ?>" value="0" id="apDoSIP<?php echo $ii; ?>" />
32
-
33
- <div class="nsx_iconedTitle" style="float: right; background-image: url(<?php echo $nxs_plurl; ?>img/ip16.png);"><a style="font-size: 12px;" target="_blank" href="http://www.nextscripts.com/setup-installation-instapaper-social-networks-auto-poster-wordpress/"><?php $nType="Instapaper"; printf( __( 'Detailed %s Installation/Configuration Instructions', 'nxs_snap' ), $nType); ?></a></div>
34
-
35
- <div style="width:100%;"><strong><?php _e('Account Nickname', 'nxs_snap'); ?>:</strong> <i><?php _e('Just so you can easely identify it', 'nxs_snap'); ?></i> </div><input name="ip[<?php echo $ii; ?>][nName]" id="ipnName<?php echo $ii; ?>" style="font-weight: bold; color: #005800; border: 1px solid #ACACAC; width: 40%;" value="<?php _e(apply_filters('format_to_edit',htmlentities($gpo['nName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /><br/>
36
- <?php echo nxs_addQTranslSel('ip', $ii, $gpo['qTLng']); ?><?php echo nxs_addPostingDelaySel('ip', $ii, $gpo['nHrs'], $gpo['nMin']); ?>
37
-
38
- <?php if (!$isNew) { ?>
39
- <div style="width:100%;"><strong><?php _e('Categories', 'nxs_snap'); ?>:</strong>
40
- <input value="0" id="catSelA<?php echo $ii; ?>" type="radio" name="ip[<?php echo $ii; ?>][catSel]" <?php if ((int)$gpo['catSel'] != 1) echo "checked"; ?> /> All
41
- <input value="1" id="catSelSIP<?php echo $ii; ?>" type="radio" name="ip[<?php echo $ii; ?>][catSel]" <?php if ((int)$gpo['catSel'] == 1) echo "checked"; ?> /> <a href="#" style="text-decoration: none;" class="showCats" id="nxs_SCA_IP<?php echo $ii; ?>" onclick="jQuery('#catSelSIP<?php echo $ii; ?>').attr('checked', true); jQuery('#tmpCatSelNT').val('IP<?php echo $ii; ?>'); nxs_markCats( jQuery('#nxs_SC_IP<?php echo $ii; ?>').val() ); jQuery('#showCatSel').bPopup({ modalClose: false, appendTo: '#nsStForm', opacity: 0.6, follow: [false, false], position: [75, 'auto']}); return false;">Selected<?php if ($gpo['catSelEd']!='') echo "[".(substr_count($gpo['catSelEd'], ",")+1)."]"; ?></a>
42
- <input type="hidden" name="ip[<?php echo $ii; ?>][catSelEd]" id="nxs_SC_IP<?php echo $ii; ?>" value="<?php echo $gpo['catSelEd']; ?>" />
43
- <br/><i><?php _e('Only selected categories will be autoposted to this account', 'nxs_snap'); ?></i></div>
44
- <br/>
45
- <?php } ?>
46
-
47
- <div style="width:100%;"><strong>Instapaper Username:</strong> </div><input name="ip[<?php echo $ii; ?>][apIPUName]" id="apIPUName" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit',htmlentities($gpo['ipUName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
48
- <div style="width:100%;"><strong>Instapaper Password:</strong> </div><input name="ip[<?php echo $ii; ?>][apIPPass]" id="apIPPass" type="password" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities(substr($gpo['ipPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($gpo['ipPass'], 5)):$gpo['ipPass'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /> <br/>
49
-
50
- <?php if ($isNew) { ?> <input type="hidden" name="ip[<?php echo $ii; ?>][apDoIP]" value="1" id="apDoNewIP<?php echo $ii; ?>" /> <?php } ?>
51
- <br/>
52
-
53
- <div id="altFormat" style="">
54
- <div style="width:100%;"><strong id="altFormatText"><?php _e('Post Title Format', 'nxs_snap'); ?></strong> (<a href="#" id="apIPTMsgFrmt<?php echo $ii; ?>HintInfo" onclick="mxs_showHideFrmtInfo('apIPTMsgFrmt<?php echo $ii; ?>'); return false;"><?php _e('Show format info', 'nxs_snap'); ?></a>)</div>
55
-
56
- <input name="ip[<?php echo $ii; ?>][apIPMsgTFrmt]" id="apIPMsgTFrmt" style="width: 50%;" value="<?php if ($isNew) echo "%TITLE%"; else _e(apply_filters('format_to_edit',htmlentities($gpo['ipMsgTFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap'); ?>" onfocus="mxs_showFrmtInfo('apIPTMsgFrmt<?php echo $ii; ?>');" /><?php nxs_doShowHint("apIPTMsgFrmt".$ii); ?>
57
- </div>
58
-
59
- <div id="altFormat" style="">
60
- <div style="width:100%;"><strong id="altFormatText"><?php _e('Post Text Format', 'nxs_snap'); ?></strong> (<a href="#" id="apIPMsgFrmt<?php echo $ii; ?>HintInfo" onclick="mxs_showHideFrmtInfo('apIPMsgFrmt<?php echo $ii; ?>'); return false;"><?php _e('Show format info', 'nxs_snap'); ?></a>)</div>
61
-
62
- <textarea cols="150" rows="3" id="ip<?php echo $ii; ?>SNAPformat" name="ip[<?php echo $ii; ?>][apIPMsgFrmt]" style="width:51%;max-width: 650px;" onfocus="jQuery('#ip<?php echo $ii; ?>SNAPformat').attr('rows', 6); mxs_showFrmtInfo('apIPMsgFrmt<?php echo $ii; ?>');"><?php if ($isNew) echo "%EXCERPT%"; else _e(apply_filters('format_to_edit', htmlentities($gpo['ipMsgFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap'); ?></textarea>
63
-
64
- <?php nxs_doShowHint("apIPMsgFrmt".$ii); ?>
65
- </div><br/>
66
-
67
- <?php if ($gpo['ipPass']!='') { ?>
68
- <?php wp_nonce_field( 'rePostToIP', 'rePostToIP_wpnonce' ); ?>
69
- <b><?php _e('Test your settings', 'nxs_snap'); ?>:</b>&nbsp;&nbsp;&nbsp; <a href="#" class="NXSButton" onclick="testPost('IP', '<?php echo $ii; ?>'); return false;"><?php printf( __( 'Submit Test Post to %s', 'nxs_snap' ), $nType); ?></a>
70
-
71
- <?php }
72
-
73
- ?><div class="submit"><input type="submit" class="button-primary" name="update_NS_SNAutoPoster_settings" value="<?php _e('Update Settings', 'nxs_snap') ?>" /></div></div><?php
74
- }
75
- //#### Set Unit Settings from POST
76
- function setNTSettings($post, $options){ global $nxs_snapThisPageUrl; $code = 'IP'; $lcode = 'ip';
77
- foreach ($post as $ii => $pval){
78
- if (isset($pval['apIPUName']) && $pval['apIPUName']!=''){ if (!isset($options[$ii])) $options[$ii] = array();
79
- if (isset($pval['apIPUName'])) $options[$ii]['ipUName'] = trim($pval['apIPUName']);
80
- if (isset($pval['nName'])) $options[$ii]['nName'] = trim($pval['nName']);
81
- if (isset($pval['apIPPass'])) $options[$ii]['ipPass'] = 'n5g9a'.nsx_doEncode($pval['apIPPass']); else $options[$ii]['ipPass'] = '';
82
-
83
- if (isset($pval['catSel'])) $options[$ii]['catSel'] = trim($pval['catSel']);
84
- if ($options[$ii]['catSel']=='1' && trim($pval['catSelEd'])!='') $options[$ii]['catSelEd'] = trim($pval['catSelEd']); else $options[$ii]['catSelEd'] = '';
85
-
86
- if (isset($pval['apIPMsgFrmt'])) $options[$ii]['ipMsgFormat'] = trim($pval['apIPMsgFrmt']);
87
- if (isset($pval['apIPMsgTFrmt'])) $options[$ii]['ipMsgTFormat'] = trim($pval['apIPMsgTFrmt']);
88
- if (isset($pval['apDoIP'])) $options[$ii]['doIP'] = $pval['apDoIP']; else $options[$ii]['doIP'] = 0;
89
- if (isset($pval['delayHrs'])) $options[$ii]['nHrs'] = trim($pval['delayHrs']); if (isset($pval['delayMin'])) $options[$ii]['nMin'] = trim($pval['delayMin']);
90
- if (isset($pval['qTLng'])) $options[$ii]['qTLng'] = trim($pval['qTLng']);
91
- }
92
- } return $options;
93
- }
94
- //#### Show Post->Edit Meta Box Settings
95
- function showEdPostNTSettings($ntOpts, $post){ global $nxs_plurl; $post_id = $post->ID;
96
- foreach($ntOpts as $ii=>$ntOpt) { $pMeta = maybe_unserialize(get_post_meta($post_id, 'snapIP', true)); if (is_array($pMeta)) $ntOpt = $this->adjMetaOpt($ntOpt, $pMeta[$ii]);
97
- $doIP = $ntOpt['doIP'] && (is_array($pMeta) || $ntOpt['catSel']!='1');
98
- $isAvailIP = $ntOpt['ipUName']!='' && $ntOpt['ipPass']!=''; $ipMsgFormat = htmlentities($ntOpt['ipMsgFormat'], ENT_COMPAT, "UTF-8"); $ipMsgTFormat = htmlentities($ntOpt['ipMsgTFormat'], ENT_COMPAT, "UTF-8");
99
- ?>
100
- <tr><th style="text-align:left;" colspan="2"><?php if ( $ntOpt['catSel']=='1' && trim($ntOpt['catSelEd'])!='' ) { ?> <input type="hidden" class="nxs_SC" id="nxs_SC_IP<?php echo $ii; ?>" value="<?php echo $ntOpt['catSelEd']; ?>" /> <?php } ?>
101
- <?php if ($isAvailIP) { ?><input class="nxsGrpDoChb" value="1" id="doIP<?php echo $ii; ?>" <?php if ($post->post_status == "publish") echo 'disabled="disabled"';?> type="checkbox" name="ip[<?php echo $ii; ?>][doIP]" <?php if ((int)$doIP == 1) echo 'checked="checked" title="def"'; ?> />
102
- <?php if ($post->post_status == "publish") { ?> <input type="hidden" name="ip[<?php echo $ii; ?>][doIP]" value="<?php echo $doIP;?>"> <?php } ?> <?php } ?>
103
-
104
- <div class="nsx_iconedTitle" style="display: inline; font-size: 13px; background-image: url(<?php echo $nxs_plurl; ?>img/ip16.png);">Instapaper - <?php _e('publish to', 'nxs_snap') ?> (<i style="color: #005800;"><?php echo $ntOpt['nName']; ?></i>)</div></th> <td><?php //## Only show RePost button if the post is "published"
105
- if ($post->post_status == "publish" && $isAvailIP) { ?><input alt="<?php echo $ii; ?>" style="float: right;" onmouseout="hidePopShAtt('SV');" onmouseover="showPopShAtt('SV', event);" onclick="return false;" type="button" class="button" name="rePostToIP_repostButton" id="rePostToIP_button" value="<?php _e('Repost to Instapaper', 'nxs_snap') ?>" />
106
- <?php wp_nonce_field( 'rePostToIP', 'rePostToIP_wpnonce' ); } ?>
107
-
108
- <?php if (is_array($pMeta) && is_array($pMeta[$ii]) && isset($pMeta[$ii]['pgID']) ) {
109
- ?> <span id="pstdIP<?php echo $ii; ?>" style="float: right; padding-top: 4px; padding-right: 10px;">
110
- <a style="font-size: 10px;" href="http://www.instapaper.com/u" target="_blank"><?php $nType="Instapaper"; printf( __( 'Posted on', 'nxs_snap' ), $nType); ?> <?php echo (isset($pMeta[$ii]['pDate']) && $pMeta[$ii]['pDate']!='')?(" (".$pMeta[$ii]['pDate'].")"):""; ?></a>
111
- </span><?php } ?>
112
-
113
- </td></tr>
114
-
115
- <?php if (!$isAvailIP) { ?><tr><th scope="row" style="text-align:right; width:150px; padding-top: 5px; padding-right:10px;"></th> <td><b>Setup your Instapaper Account to AutoPost to Instapaper</b>
116
- <?php } elseif ($post->post_status != "pubZlish") { ?>
117
-
118
- <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top: 6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Title Format:', 'nxs_snap') ?></th>
119
- <td><input value="<?php echo $ipMsgTFormat ?>" type="text" name="ip[<?php echo $ii; ?>][SNAPformatT]" style="width:60%;max-width: 610px;" onfocus="jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apIPTMsgFrmt<?php echo $ii; ?>');"/><?php nxs_doShowHint("apIPTMsgFrmt".$ii); ?></td></tr>
120
-
121
- <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top: 6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Text Format:', 'nxs_snap') ?></th>
122
- <td>
123
- <textarea cols="150" rows="1" id="ip<?php echo $ii; ?>SNAPformat" name="ip[<?php echo $ii; ?>][SNAPformat]" style="width:60%;max-width: 610px;" onfocus="jQuery('#ip<?php echo $ii; ?>SNAPformat').attr('rows', 4); jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apIPMsgFrmt<?php echo $ii; ?>');"><?php echo $ipMsgFormat; ?></textarea>
124
- <?php nxs_doShowHint("apIPMsgFrmt".$ii); ?></td></tr>
125
- <?php }
126
- }
127
- }
128
- //#### Save Meta Tags to the Post
129
- function adjMetaOpt($optMt, $pMeta){ if (isset($pMeta['isPosted'])) $optMt['isPosted'] = $pMeta['isPosted']; else $optMt['isPosted'] = '';
130
- if (isset($pMeta['SNAPformat'])) $optMt['ipMsgFormat'] = $pMeta['SNAPformat'];
131
- if (isset($pMeta['SNAPformatT'])) $optMt['ipMsgTFormat'] = $pMeta['SNAPformatT'];
132
- if (isset($pMeta['doIP'])) $optMt['doIP'] = $pMeta['doIP'] == 1?1:0; else { if (isset($pMeta['SNAPformat'])) $optMt['doIP'] = 0; }
133
- if (isset($pMeta['SNAPincludeIP']) && $pMeta['SNAPincludeIP'] == '1' ) $optMt['doIP'] = 1;
134
- return $optMt;
135
- }
136
- }}
137
- if (!function_exists("nxs_rePostToIP_ajax")) {
138
- function nxs_rePostToIP_ajax() { check_ajax_referer('rePostToIP'); $postID = $_POST['id']; $options = get_option('NS_SNAutoPoster');
139
- foreach ($options['ip'] as $ii=>$two) if ($ii==$_POST['nid']) { $two['ii'] = $ii; $two['pType'] = 'aj'; //if ($two['gpPageID'].$two['gpUName']==$_POST['nid']) {
140
- $gppo = get_post_meta($postID, 'snapIP', true); $gppo = maybe_unserialize($gppo);// prr($gppo);
141
- if (is_array($gppo) && isset($gppo[$ii]) && is_array($gppo[$ii])){ $ntClInst = new nxs_snapClassIP(); $two = $ntClInst->adjMetaOpt($two, $gppo[$ii]);}
142
- $result = nxs_doPublishToIP($postID, $two); if ($result == 200) die("Successfully sent your post to Instapaper."); else die($result);
143
- }
144
- }
145
- }
146
-
147
- if (!function_exists("nxs_getIPHeaders")) { function nxs_getIPHeaders($up){ $hdrsArr = array();
148
- $hdrsArr['Cache-Control']='no-cache'; $hdrsArr['Connection']='keep-alive';
149
- $hdrsArr['User-Agent']='SNAP for Wordpress; Ver '.NextScripts_SNAP_Version;
150
- $hdrsArr['Accept']='text/html, application/xhtml+xml, */*'; $hdrsArr['DNT']='1';
151
- $hdrsArr['Authorization'] = 'Basic ' . base64_encode("$up");
152
- $hdrsArr['Accept-Encoding']='gzip,deflate'; $hdrsArr['Accept-Language']='en-US,en;q=0.8'; $hdrsArr['Accept-Charset']='ISO-8859-1,utf-8;q=0.7,*;q=0.3'; return $hdrsArr;
153
- }}
154
-
155
- if (!function_exists("nxs_doPublishToIP")) { //## Second Function to Post to IP
156
- function nxs_doPublishToIP($postID, $options){ $ntCd = 'IP'; $ntCdL = 'ip'; $ntNm = 'Instapaper';
157
- //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToIP', array($postID, $options));
158
-
159
- $ii = $options['ii']; if (!isset($options['pType'])) $options['pType'] = 'im'; if ($options['pType']=='sh') sleep(rand(1, 10));
160
- $logNT = '<span style="color:#000080">Instapaper</span> - '.$options['nName'];
161
- $snap_ap = get_post_meta($postID, 'snap'.$ntCd, true); $snap_ap = maybe_unserialize($snap_ap);
162
- if ($options['pType']!='aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
163
- $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted!='2') { sleep(5);
164
- nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:'.$postID, 'Already posted. No reason for posting duplicate'.' |'.$uqID); return;
165
- }
166
- }
167
-
168
- if ($postID=='0') { echo "Testing ... <br/><br/>"; $link = home_url(); $msgT = 'Test Link from '.$link; } else { $post = get_post($postID); if(!$post) return; $link = get_permalink($postID);
169
- $msgFormat = $options['ipMsgFormat']; $msgTFormat = $options['ipMsgTFormat']; $msgT = nsFormatMessage($msgTFormat, $postID); $msg = nsFormatMessage($msgFormat, $postID);
170
- nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted'=>'1'));
171
- }
172
- $extInfo = ' | PostID: '.$postID." - ".$post->post_title;
173
- $dusername = $options['ipUName']; $pass = (substr($options['ipPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($options['ipPass'], 5)):$options['ipPass']);
174
- $link = urlencode($link); $desc = urlencode(substr($msgT, 0, 250)); $ext = urlencode(substr($msg, 0, 1000));
175
- $t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) {$tggs[] = $tagA->name;} $tags = urlencode(implode(',',$tggs)); $tags = str_replace(' ','+',$tags);
176
- $apicall = "https://www.instapaper.com/api/add?red=api&url=$link&title=$desc&selection=$ext";
177
- $hdrsArr = nxs_getIPHeaders($dusername.':'.$pass); $cnt = wp_remote_get( $apicall, array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr) );// prr($cnt);
178
-
179
- if(is_wp_error($cnt)) { $error_string = $cnt->get_error_message(); if (stripos($error_string, ' timed out')!==false) { sleep(10);
180
- $cnt = wp_remote_get( $apicall, array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr) );}
181
- }
182
- if(is_wp_error($cnt)) {
183
- $ret = 'Something went wrong - '.""; nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.$ret. "ERR: ".print_r($cnt, true), $extInfo);
184
- } else {
185
- if (is_array($cnt) && stripos($cnt['body'],'201')!==false)
186
- { $ret = 'OK'; nxs_metaMarkAsPosted($postID, 'IP', $options['ii'], array('isPosted'=>'1', 'pgID'=>'IP', 'pDate'=>date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); }
187
- else { if ($cnt['response']['code']=='401') $ret = " Incorrect Username/Password "; else $ret = 'Something went wrong - '."https://$dusername:*********@$api/posts/add?&url=$link&description=$desc&extended=$ext&tags=$tags";
188
- nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.$ret. "ERR: ".print_r($cnt, true), $extInfo);
189
- }
190
- }
191
- if ($ret!='OK') { if ($postID=='0') echo $ret; } else if ($postID=='0') { echo 'OK - Message Posted, please see your Instapaper Page. '; nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); }
192
- if ($ret == 'OK') return 200; else return $ret;
193
-
194
- }
195
- }
196
  ?>
1
+ <?php
2
+ //## NextScripts Facebook Connection Class
3
+ $nxs_snapAvNts[] = array('code'=>'IP', 'lcode'=>'ip', 'name'=>'Instapaper');
4
+
5
+ if (!class_exists("nxs_snapClassIP")) { class nxs_snapClassIP {
6
+ //#### Show Common Settings
7
+ function showGenNTSettings($ntOpts){ global $nxs_plurl; $ntInfo = array('code'=>'IP', 'lcode'=>'ip', 'name'=>'Instapaper', 'defNName'=>'ipUName', 'tstReq' => false); ?>
8
+ <div class="nxs_box">
9
+ <div class="nxs_box_header">
10
+ <div class="nsx_iconedTitle" style="margin-bottom:1px;background-image:url(<?php echo $nxs_plurl;?>img/<?php echo $ntInfo['lcode']; ?>16.png);"><?php echo $ntInfo['name']; ?>
11
+ <?php $cbo = count($ntOpts); ?> <?php wp_nonce_field( 'ns'.$ntInfo['code'], 'ns'.$ntInfo['code'].'_wpnonce' ); ?>
12
+ <?php if ($cbo>1){ ?><div class="nsBigText"><?php echo "(".($cbo=='0'?'No':$cbo)." "; _e('accounts', 'nxs_snap'); echo ")"; ?></div><?php } ?>
13
+ </div>
14
+ </div>
15
+ <div class="nxs_box_inside">
16
+ <?php foreach ($ntOpts as $indx=>$pbo){ if (trim($pbo['nName']=='')) $pbo['nName'] = $pbo[$ntInfo['defNName']]; ?>
17
+ <p style="margin:0px;margin-left:5px;">
18
+ <input value="1" name="<?php echo $ntInfo['lcode']; ?>[<?php echo $indx; ?>][apDo<?php echo $ntInfo['code']; ?>]" onchange="doShowHideBlocks('<?php echo $ntInfo['code']; ?>');" type="checkbox" <?php if ((int)$pbo['do'.$ntInfo['code']] == 1) echo "checked"; ?> /> <?php if ((int)$pbo['catSel'] == 1) { ?> <span onmouseout="nxs_hidePopUpInfo('popOnlyCat');" onmouseover="nxs_showPopUpInfo('popOnlyCat', event);"><?php echo "*[".(substr_count($pbo['catSelEd'], ",")+1)."]*" ?></span><?php } ?>
19
+ <strong><?php _e('Auto-publish to', 'nxs_snap'); ?> <?php echo $ntInfo['name']; ?> <i style="color: #005800;"><?php if($pbo['nName']!='') echo "(".$pbo['nName'].")"; ?></i></strong>
20
+ &nbsp;&nbsp;<?php if ($ntInfo['tstReq'] && (!isset($pbo[$ntInfo['lcode'].'OK']) || $pbo[$ntInfo['lcode'].'OK']=='')){ ?><b style="color: #800000"><?php _e('Attention requred. Unfinished setup', 'nxs_snap'); ?> ==&gt;</b><?php } ?><a id="do<?php echo $ntInfo['code'].$indx; ?>A" href="#" onclick="doShowHideBlocks2('<?php echo $ntInfo['code'].$indx; ?>');return false;">[<?php _e('Show Settings', 'nxs_snap'); ?>]</a>&nbsp;&nbsp;
21
+ <a href="#" onclick="doDelAcct('<?php echo $ntInfo['lcode']; ?>', '<?php echo $indx; ?>', '<?php if (isset($pbo['bgBlogID'])) echo $pbo['nName']; ?>');return false;">[<?php _e('Remove Account', 'nxs_snap'); ?>]</a>
22
+ </p><?php $this->showNTSettings($indx, $pbo);
23
+ }?>
24
+ </div>
25
+ </div> <?php
26
+ }
27
+ //#### Show NEW Settings Page
28
+ function showNewNTSettings($mgpo){ $gpo = array('nName'=>'', 'doIP'=>'1', 'ipUName'=>'', 'ipPageID'=>'', 'ipAttch'=>'', 'ipPass'=>''); $this->showNTSettings($mgpo, $gpo, true);}
29
+ //#### Show Unit Settings
30
+ function showNTSettings($ii, $gpo, $isNew=false){ global $nxs_plurl; ?>
31
+ <div id="doIP<?php echo $ii; ?>Div" class="insOneDiv<?php if ($isNew) echo " clNewNTSets"; ?>" style="max-width: 1000px; background-color: #EBF4FB; background-image: url(<?php echo $nxs_plurl; ?>img/ip-bg.png); background-position:90% 10%; background-repeat: no-repeat; margin: 10px; border: 1px solid #808080; padding: 10px; display:none;"> <input type="hidden" name="apDoSIP<?php echo $ii; ?>" value="0" id="apDoSIP<?php echo $ii; ?>" />
32
+
33
+ <div class="nsx_iconedTitle" style="float: right; background-image: url(<?php echo $nxs_plurl; ?>img/ip16.png);"><a style="font-size: 12px;" target="_blank" href="http://www.nextscripts.com/setup-installation-instapaper-social-networks-auto-poster-wordpress/"><?php $nType="Instapaper"; printf( __( 'Detailed %s Installation/Configuration Instructions', 'nxs_snap' ), $nType); ?></a></div>
34
+
35
+ <div style="width:100%;"><strong><?php _e('Account Nickname', 'nxs_snap'); ?>:</strong> <i><?php _e('Just so you can easely identify it', 'nxs_snap'); ?></i> </div><input name="ip[<?php echo $ii; ?>][nName]" id="ipnName<?php echo $ii; ?>" style="font-weight: bold; color: #005800; border: 1px solid #ACACAC; width: 40%;" value="<?php _e(apply_filters('format_to_edit',htmlentities($gpo['nName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /><br/>
36
+ <?php echo nxs_addQTranslSel('ip', $ii, $gpo['qTLng']); ?><?php echo nxs_addPostingDelaySel('ip', $ii, $gpo['nHrs'], $gpo['nMin']); ?>
37
+
38
+ <?php if (!$isNew) { ?>
39
+ <div style="width:100%;"><strong><?php _e('Categories', 'nxs_snap'); ?>:</strong>
40
+ <input value="0" id="catSelA<?php echo $ii; ?>" type="radio" name="ip[<?php echo $ii; ?>][catSel]" <?php if ((int)$gpo['catSel'] != 1) echo "checked"; ?> /> All
41
+ <input value="1" id="catSelSIP<?php echo $ii; ?>" type="radio" name="ip[<?php echo $ii; ?>][catSel]" <?php if ((int)$gpo['catSel'] == 1) echo "checked"; ?> /> <a href="#" style="text-decoration: none;" class="showCats" id="nxs_SCA_IP<?php echo $ii; ?>" onclick="jQuery('#catSelSIP<?php echo $ii; ?>').attr('checked', true); jQuery('#tmpCatSelNT').val('IP<?php echo $ii; ?>'); nxs_markCats( jQuery('#nxs_SC_IP<?php echo $ii; ?>').val() ); jQuery('#showCatSel').bPopup({ modalClose: false, appendTo: '#nsStForm', opacity: 0.6, follow: [false, false], position: [75, 'auto']}); return false;">Selected<?php if ($gpo['catSelEd']!='') echo "[".(substr_count($gpo['catSelEd'], ",")+1)."]"; ?></a>
42
+ <input type="hidden" name="ip[<?php echo $ii; ?>][catSelEd]" id="nxs_SC_IP<?php echo $ii; ?>" value="<?php echo $gpo['catSelEd']; ?>" />
43
+ <br/><i><?php _e('Only selected categories will be autoposted to this account', 'nxs_snap'); ?></i></div>
44
+ <br/>
45
+ <?php } ?>
46
+
47
+ <div style="width:100%;"><strong>Instapaper Username:</strong> </div><input name="ip[<?php echo $ii; ?>][apIPUName]" id="apIPUName" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit',htmlentities($gpo['ipUName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
48
+ <div style="width:100%;"><strong>Instapaper Password:</strong> </div><input name="ip[<?php echo $ii; ?>][apIPPass]" id="apIPPass" type="password" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities(substr($gpo['ipPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($gpo['ipPass'], 5)):$gpo['ipPass'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /> <br/>
49
+
50
+ <?php if ($isNew) { ?> <input type="hidden" name="ip[<?php echo $ii; ?>][apDoIP]" value="1" id="apDoNewIP<?php echo $ii; ?>" /> <?php } ?>
51
+ <br/>
52
+
53
+ <div id="altFormat" style="">
54
+ <div style="width:100%;"><strong id="altFormatText"><?php _e('Post Title Format', 'nxs_snap'); ?></strong> (<a href="#" id="apIPTMsgFrmt<?php echo $ii; ?>HintInfo" onclick="mxs_showHideFrmtInfo('apIPTMsgFrmt<?php echo $ii; ?>'); return false;"><?php _e('Show format info', 'nxs_snap'); ?></a>)</div>
55
+
56
+ <input name="ip[<?php echo $ii; ?>][apIPMsgTFrmt]" id="apIPMsgTFrmt" style="width: 50%;" value="<?php if ($isNew) echo "%TITLE%"; else _e(apply_filters('format_to_edit',htmlentities($gpo['ipMsgTFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap'); ?>" onfocus="mxs_showFrmtInfo('apIPTMsgFrmt<?php echo $ii; ?>');" /><?php nxs_doShowHint("apIPTMsgFrmt".$ii); ?>
57
+ </div>
58
+
59
+ <div id="altFormat" style="">
60
+ <div style="width:100%;"><strong id="altFormatText"><?php _e('Post Text Format', 'nxs_snap'); ?></strong> (<a href="#" id="apIPMsgFrmt<?php echo $ii; ?>HintInfo" onclick="mxs_showHideFrmtInfo('apIPMsgFrmt<?php echo $ii; ?>'); return false;"><?php _e('Show format info', 'nxs_snap'); ?></a>)</div>
61
+
62
+ <textarea cols="150" rows="3" id="ip<?php echo $ii; ?>SNAPformat" name="ip[<?php echo $ii; ?>][apIPMsgFrmt]" style="width:51%;max-width: 650px;" onfocus="jQuery('#ip<?php echo $ii; ?>SNAPformat').attr('rows', 6); mxs_showFrmtInfo('apIPMsgFrmt<?php echo $ii; ?>');"><?php if ($isNew) echo "%EXCERPT%"; else _e(apply_filters('format_to_edit', htmlentities($gpo['ipMsgFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap'); ?></textarea>
63
+
64
+ <?php nxs_doShowHint("apIPMsgFrmt".$ii); ?>
65
+ </div><br/>
66
+
67
+ <?php if ($gpo['ipPass']!='') { ?>
68
+ <?php wp_nonce_field( 'rePostToIP', 'rePostToIP_wpnonce' ); ?>
69
+ <b><?php _e('Test your settings', 'nxs_snap'); ?>:</b>&nbsp;&nbsp;&nbsp; <a href="#" class="NXSButton" onclick="testPost('IP', '<?php echo $ii; ?>'); return false;"><?php printf( __( 'Submit Test Post to %s', 'nxs_snap' ), $nType); ?></a>
70
+
71
+ <?php }
72
+
73
+ ?><div class="submit"><input type="submit" class="button-primary" name="update_NS_SNAutoPoster_settings" value="<?php _e('Update Settings', 'nxs_snap') ?>" /></div></div><?php
74
+ }
75
+ //#### Set Unit Settings from POST
76
+ function setNTSettings($post, $options){ global $nxs_snapThisPageUrl; $code = 'IP'; $lcode = 'ip';
77
+ foreach ($post as $ii => $pval){
78
+ if (isset($pval['apIPUName']) && $pval['apIPUName']!=''){ if (!isset($options[$ii])) $options[$ii] = array();
79
+ if (isset($pval['apIPUName'])) $options[$ii]['ipUName'] = trim($pval['apIPUName']);
80
+ if (isset($pval['nName'])) $options[$ii]['nName'] = trim($pval['nName']);
81
+ if (isset($pval['apIPPass'])) $options[$ii]['ipPass'] = 'n5g9a'.nsx_doEncode($pval['apIPPass']); else $options[$ii]['ipPass'] = '';
82
+
83
+ if (isset($pval['catSel'])) $options[$ii]['catSel'] = trim($pval['catSel']);
84
+ if ($options[$ii]['catSel']=='1' && trim($pval['catSelEd'])!='') $options[$ii]['catSelEd'] = trim($pval['catSelEd']); else $options[$ii]['catSelEd'] = '';
85
+
86
+ if (isset($pval['apIPMsgFrmt'])) $options[$ii]['ipMsgFormat'] = trim($pval['apIPMsgFrmt']);
87
+ if (isset($pval['apIPMsgTFrmt'])) $options[$ii]['ipMsgTFormat'] = trim($pval['apIPMsgTFrmt']);
88
+ if (isset($pval['apDoIP'])) $options[$ii]['doIP'] = $pval['apDoIP']; else $options[$ii]['doIP'] = 0;
89
+ if (isset($pval['delayHrs'])) $options[$ii]['nHrs'] = trim($pval['delayHrs']); if (isset($pval['delayMin'])) $options[$ii]['nMin'] = trim($pval['delayMin']);
90
+ if (isset($pval['qTLng'])) $options[$ii]['qTLng'] = trim($pval['qTLng']);
91
+ }
92
+ } return $options;
93
+ }
94
+ //#### Show Post->Edit Meta Box Settings
95
+ function showEdPostNTSettings($ntOpts, $post){ global $nxs_plurl; $post_id = $post->ID;
96
+ foreach($ntOpts as $ii=>$ntOpt) { $pMeta = maybe_unserialize(get_post_meta($post_id, 'snapIP', true)); if (is_array($pMeta)) $ntOpt = $this->adjMetaOpt($ntOpt, $pMeta[$ii]);
97
+ $doIP = $ntOpt['doIP'] && (is_array($pMeta) || $ntOpt['catSel']!='1');
98
+ $isAvailIP = $ntOpt['ipUName']!='' && $ntOpt['ipPass']!=''; $ipMsgFormat = htmlentities($ntOpt['ipMsgFormat'], ENT_COMPAT, "UTF-8"); $ipMsgTFormat = htmlentities($ntOpt['ipMsgTFormat'], ENT_COMPAT, "UTF-8");
99
+ ?>
100
+ <tr><th style="text-align:left;" colspan="2"><?php if ( $ntOpt['catSel']=='1' && trim($ntOpt['catSelEd'])!='' ) { ?> <input type="hidden" class="nxs_SC" id="nxs_SC_IP<?php echo $ii; ?>" value="<?php echo $ntOpt['catSelEd']; ?>" /> <?php } ?>
101
+ <?php if ($isAvailIP) { ?><input class="nxsGrpDoChb" value="1" id="doIP<?php echo $ii; ?>" <?php if ($post->post_status == "publish") echo 'disabled="disabled"';?> type="checkbox" name="ip[<?php echo $ii; ?>][doIP]" <?php if ((int)$doIP == 1) echo 'checked="checked" title="def"'; ?> />
102
+ <?php if ($post->post_status == "publish") { ?> <input type="hidden" name="ip[<?php echo $ii; ?>][doIP]" value="<?php echo $doIP;?>"> <?php } ?> <?php } ?>
103
+
104
+ <div class="nsx_iconedTitle" style="display: inline; font-size: 13px; background-image: url(<?php echo $nxs_plurl; ?>img/ip16.png);">Instapaper - <?php _e('publish to', 'nxs_snap') ?> (<i style="color: #005800;"><?php echo $ntOpt['nName']; ?></i>)</div></th> <td><?php //## Only show RePost button if the post is "published"
105
+ if ($post->post_status == "publish" && $isAvailIP) { ?><input alt="<?php echo $ii; ?>" style="float: right;" onmouseout="hidePopShAtt('SV');" onmouseover="showPopShAtt('SV', event);" onclick="return false;" type="button" class="button" name="rePostToIP_repostButton" id="rePostToIP_button" value="<?php _e('Repost to Instapaper', 'nxs_snap') ?>" />
106
+ <?php wp_nonce_field( 'rePostToIP', 'rePostToIP_wpnonce' ); } ?>
107
+
108
+ <?php if (is_array($pMeta) && is_array($pMeta[$ii]) && isset($pMeta[$ii]['pgID']) ) {
109
+ ?> <span id="pstdIP<?php echo $ii; ?>" style="float: right; padding-top: 4px; padding-right: 10px;">
110
+ <a style="font-size: 10px;" href="http://www.instapaper.com/u" target="_blank"><?php $nType="Instapaper"; printf( __( 'Posted on', 'nxs_snap' ), $nType); ?> <?php echo (isset($pMeta[$ii]['pDate']) && $pMeta[$ii]['pDate']!='')?(" (".$pMeta[$ii]['pDate'].")"):""; ?></a>
111
+ </span><?php } ?>
112
+
113
+ </td></tr>
114
+
115
+ <?php if (!$isAvailIP) { ?><tr><th scope="row" style="text-align:right; width:150px; padding-top: 5px; padding-right:10px;"></th> <td><b>Setup your Instapaper Account to AutoPost to Instapaper</b>
116
+ <?php } elseif ($post->post_status != "pubZlish") { ?>
117
+
118
+ <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top: 6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Title Format:', 'nxs_snap') ?></th>
119
+ <td><input value="<?php echo $ipMsgTFormat ?>" type="text" name="ip[<?php echo $ii; ?>][SNAPformatT]" style="width:60%;max-width: 610px;" onfocus="jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apIPTMsgFrmt<?php echo $ii; ?>');"/><?php nxs_doShowHint("apIPTMsgFrmt".$ii); ?></td></tr>
120
+
121
+ <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top: 6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Text Format:', 'nxs_snap') ?></th>
122
+ <td>
123
+ <textarea cols="150" rows="1" id="ip<?php echo $ii; ?>SNAPformat" name="ip[<?php echo $ii; ?>][SNAPformat]" style="width:60%;max-width: 610px;" onfocus="jQuery('#ip<?php echo $ii; ?>SNAPformat').attr('rows', 4); jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apIPMsgFrmt<?php echo $ii; ?>');"><?php echo $ipMsgFormat; ?></textarea>
124
+ <?php nxs_doShowHint("apIPMsgFrmt".$ii); ?></td></tr>
125
+ <?php }
126
+ }
127
+ }
128
+ //#### Save Meta Tags to the Post
129
+ function adjMetaOpt($optMt, $pMeta){ if (isset($pMeta['isPosted'])) $optMt['isPosted'] = $pMeta['isPosted']; else $optMt['isPosted'] = '';
130
+ if (isset($pMeta['SNAPformat'])) $optMt['ipMsgFormat'] = $pMeta['SNAPformat'];
131
+ if (isset($pMeta['SNAPformatT'])) $optMt['ipMsgTFormat'] = $pMeta['SNAPformatT'];
132
+ if (isset($pMeta['doIP'])) $optMt['doIP'] = $pMeta['doIP'] == 1?1:0; else { if (isset($pMeta['SNAPformat'])) $optMt['doIP'] = 0; }
133
+ if (isset($pMeta['SNAPincludeIP']) && $pMeta['SNAPincludeIP'] == '1' ) $optMt['doIP'] = 1;
134
+ return $optMt;
135
+ }
136
+ }}
137
+ if (!function_exists("nxs_rePostToIP_ajax")) {
138
+ function nxs_rePostToIP_ajax() { check_ajax_referer('rePostToIP'); $postID = $_POST['id']; $options = get_option('NS_SNAutoPoster');
139
+ foreach ($options['ip'] as $ii=>$two) if ($ii==$_POST['nid']) { $two['ii'] = $ii; $two['pType'] = 'aj'; //if ($two['gpPageID'].$two['gpUName']==$_POST['nid']) {
140
+ $gppo = get_post_meta($postID, 'snapIP', true); $gppo = maybe_unserialize($gppo);// prr($gppo);
141
+ if (is_array($gppo) && isset($gppo[$ii]) && is_array($gppo[$ii])){ $ntClInst = new nxs_snapClassIP(); $two = $ntClInst->adjMetaOpt($two, $gppo[$ii]);}
142
+ $result = nxs_doPublishToIP($postID, $two); if ($result == 200) die("Successfully sent your post to Instapaper."); else die($result);
143
+ }
144
+ }
145
+ }
146
+
147
+ if (!function_exists("nxs_getIPHeaders")) { function nxs_getIPHeaders($up){ $hdrsArr = array();
148
+ $hdrsArr['Cache-Control']='no-cache'; $hdrsArr['Connection']='keep-alive';
149
+ $hdrsArr['User-Agent']='SNAP for Wordpress; Ver '.NextScripts_SNAP_Version;
150
+ $hdrsArr['Accept']='text/html, application/xhtml+xml, */*'; $hdrsArr['DNT']='1';
151
+ $hdrsArr['Authorization'] = 'Basic ' . base64_encode("$up");
152
+ $hdrsArr['Accept-Encoding']='gzip,deflate'; $hdrsArr['Accept-Language']='en-US,en;q=0.8'; $hdrsArr['Accept-Charset']='ISO-8859-1,utf-8;q=0.7,*;q=0.3'; return $hdrsArr;
153
+ }}
154
+
155
+ if (!function_exists("nxs_doPublishToIP")) { //## Second Function to Post to IP
156
+ function nxs_doPublishToIP($postID, $options){ $ntCd = 'IP'; $ntCdL = 'ip'; $ntNm = 'Instapaper';
157
+ //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToIP', array($postID, $options));
158
+
159
+ $ii = $options['ii']; if (!isset($options['pType'])) $options['pType'] = 'im'; if ($options['pType']=='sh') sleep(rand(1, 10));
160
+ $logNT = '<span style="color:#000080">Instapaper</span> - '.$options['nName'];
161
+ $snap_ap = get_post_meta($postID, 'snap'.$ntCd, true); $snap_ap = maybe_unserialize($snap_ap);
162
+ if ($options['pType']!='aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
163
+ $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted!='2') { sleep(5);
164
+ nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:'.$postID, 'Already posted. No reason for posting duplicate'.' |'.$uqID); return;
165
+ }
166
+ }
167
+
168
+ if ($postID=='0') { echo "Testing ... <br/><br/>"; $link = home_url(); $msgT = 'Test Link from '.$link; } else { $post = get_post($postID); if(!$post) return; $link = get_permalink($postID);
169
+ $msgFormat = $options['ipMsgFormat']; $msgTFormat = $options['ipMsgTFormat']; $msgT = nsFormatMessage($msgTFormat, $postID); $msg = nsFormatMessage($msgFormat, $postID);
170
+ nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted'=>'1'));
171
+ }
172
+ $extInfo = ' | PostID: '.$postID." - ".$post->post_title;
173
+ $dusername = $options['ipUName']; $pass = (substr($options['ipPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($options['ipPass'], 5)):$options['ipPass']);
174
+ $link = urlencode($link); $desc = urlencode(substr($msgT, 0, 250)); $ext = urlencode(substr($msg, 0, 1000));
175
+ $t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) {$tggs[] = $tagA->name;} $tags = urlencode(implode(',',$tggs)); $tags = str_replace(' ','+',$tags);
176
+ $apicall = "https://www.instapaper.com/api/add?red=api&url=$link&title=$desc&selection=$ext";
177
+ $hdrsArr = nxs_getIPHeaders($dusername.':'.$pass); $cnt = wp_remote_get( $apicall, array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr) );// prr($cnt);
178
+
179
+ if(is_wp_error($cnt)) { $error_string = $cnt->get_error_message(); if (stripos($error_string, ' timed out')!==false) { sleep(10);
180
+ $cnt = wp_remote_get( $apicall, array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr) );}
181
+ }
182
+ if(is_wp_error($cnt)) {
183
+ $ret = 'Something went wrong - '.""; nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.$ret. "ERR: ".print_r($cnt, true), $extInfo);
184
+ } else {
185
+ if (is_array($cnt) && stripos($cnt['body'],'201')!==false)
186
+ { $ret = 'OK'; nxs_metaMarkAsPosted($postID, 'IP', $options['ii'], array('isPosted'=>'1', 'pgID'=>'IP', 'pDate'=>date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); }
187
+ else { if ($cnt['response']['code']=='401') $ret = " Incorrect Username/Password "; else $ret = 'Something went wrong - '."https://$dusername:*********@$api/posts/add?&url=$link&description=$desc&extended=$ext&tags=$tags";
188
+ nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.$ret. "ERR: ".print_r($cnt, true), $extInfo);
189
+ }
190
+ }
191
+ if ($ret!='OK') { if ($postID=='0') echo $ret; } else if ($postID=='0') { echo 'OK - Message Posted, please see your Instapaper Page. '; nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); }
192
+ if ($ret == 'OK') return 200; else return $ret;
193
+
194
+ }
195
+ }
196
  ?>
inc-cl/li.php CHANGED
@@ -1,336 +1,342 @@
1
- <?php
2
-
3
- if (isset($_GET['ca']) && $_GET['ca']!='') { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/recaptcha/api/image?c='.$_GET['ca']);
4
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_REFERER, 'https://www.google.com/'); $imageData = curl_exec($ch);
5
- header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
6
- header("Cache-Control: private",false); header("Content-Type: image/jpg"); header("Content-Transfer-Encoding: binary"); echo $imageData; die();
7
- }
8
-
9
- add_action('wp_ajax_nxsCptCheck' , 'nxsCptCheck_ajax');
10
- if (!function_exists("nxsCptCheck_ajax")) { function nxsCptCheck_ajax() { global $nxs_gCookiesArr;
11
- if ($_POST['c']!='') { $seForDB = get_option('nxs_li_ctp_save'); $ser = maybe_unserialize($seForDB); $nxs_gCookiesArr = $ser['c']; $flds = $ser['f'];
12
- $flds['recaptcha_response_field'] = $_POST['c']; $cfldsTxt = build_http_query($flds); // prr($cfldsTxt); prr($nxs_gCookiesArr);
13
- $contents2 = getCurlPageX('https://www.linkedin.com/uas/captcha-submit','https://www.linkedin.com/uas/login-submit', false, $cfldsTxt, false, $advSettings); // prr($contents2);
14
- if (stripos($contents2['content'], 'The email address or password you provided does not match our records')!==false) { echo "Invalid Login/Password"; die(); }
15
- if (stripos($contents2['url'], 'linkedin.com/uas/captcha-submit')!==false) echo "Wrong Captcha. Please try Again";
16
- if (stripos($contents2['url'], 'linkedin.com/home')!==false) { echo "OK. You are In";
17
- $contents3 = getCurlPageX('http://www.linkedin.com/profile/edit?trk=tab_pro', 'http://www.linkedin.com/home', false, '', false, $advSettings); // prr($contents3);
18
- if ($_POST['i']!='') { global $plgn_NS_SNAutoPoster; if (!isset($plgn_NS_SNAutoPoster)) return; $options = $plgn_NS_SNAutoPoster->nxs_options;
19
- $options['li'][$_POST['i']]['uCook'] = $nxs_gCookiesArr; if (is_array($options)) update_option('NS_SNAutoPoster', $options);
20
- }
21
- }
22
- } die();
23
- }}
24
-
25
- //## NextScripts Facebook Connection Class
26
- $nxs_snapAvNts[] = array('code'=>'LI', 'lcode'=>'li', 'name'=>'LinkedIn');
27
-
28
- if (!class_exists("nxs_snapClassLI")) { class nxs_snapClassLI {
29
- //#### Show Common Settings
30
- function showGenNTSettings($ntOpts){ global $nxs_snapThisPageUrl, $nxs_plurl; $ntInfo = array('code'=>'LI', 'lcode'=>'li', 'name'=>'LinkedIn', 'defNName'=>'ulName', 'tstReq' => true);
31
-
32
- if ( isset($_GET['auth']) && $_GET['auth']=='li'){ require_once('apis/liOAuth.php'); $options = $ntOpts[$_GET['acc']];
33
-
34
- $api_key = $options['liAPIKey']; $api_secret = $options['liAPISec'];
35
- $callback_url = $nxs_snapThisPageUrl."&auth=lia&acc=".$_GET['acc'];
36
- $li_oauth = new nsx_LinkedIn($api_key, $api_secret, $callback_url);
37
- $request_token = $li_oauth->getRequestToken(); //echo "####"; prr($request_token); die();
38
- $options['liOAuthToken'] = $request_token->key;
39
- $options['liOAuthTokenSecret'] = $request_token->secret; // prr($li_oauth);
40
- switch ($li_oauth->http_code) { case 200: $url = $li_oauth->generateAuthorizeUrl(); $optionsG = get_option('NS_SNAutoPoster'); $optionsG['li'][$_GET['acc']] = $options; update_option('NS_SNAutoPoster', $optionsG);
41
- echo '<script type="text/javascript">window.location = "'.$url.'"</script>'; break;
42
- default: echo '<br/><b style="color:red">Could not connect to LinkedIn. Refresh the page or try again later.</b>'; die();
43
- }die();
44
- }
45
- if ( isset($_GET['auth']) && $_GET['auth']=='lia'){ require_once('apis/liOAuth.php'); $options = $ntOpts[$_GET['acc']]; $api_key = $options['liAPIKey']; $api_secret = $options['liAPISec'];
46
- $li_oauth = new nsx_LinkedIn($api_key, $api_secret); $li_oauth->request_token = new nsx_trOAuthConsumer($options['liOAuthToken'], $options['liOAuthTokenSecret'], 1);
47
- $li_oauth->oauth_verifier = $_REQUEST['oauth_verifier']; $li_oauth->getAccessToken($_REQUEST['oauth_verifier']); $options['liOAuthVerifier'] = $_REQUEST['oauth_verifier'];
48
- $options['liAccessToken'] = $li_oauth->access_token->key; $options['liAccessTokenSecret'] = $li_oauth->access_token->secret;
49
- try{$xml_response = $li_oauth->getProfile("~:(id,first-name,last-name)");} catch (Exception $o){prr($o); die("<span style='color:red;'>ERROR: Authorization Error</span>");}
50
- if (stripos($xml_response,'<first-name>')!==false) $userinfo = CutFromTo($xml_response, '<id>','</id>')." - ".CutFromTo($xml_response, '<first-name>','</first-name>')." ".CutFromTo($xml_response, '<last-name>','</last-name>'); else $userinfo='';
51
- if ($userinfo!='') { $options['liUserInfo'] = $userinfo; $optionsG = get_option('NS_SNAutoPoster'); $optionsG['li'][$_GET['acc']] = $options; update_option('NS_SNAutoPoster', $optionsG);
52
- echo '<script type="text/javascript">window.location = "'.$nxs_snapThisPageUrl.'"</script>'; die();
53
- } prr($xml_response); die("<span style='color:red;'>ERROR: Something is Wrong with your LinkedIn account</span>");
54
- }
55
-
56
- ?>
57
- <div class="nxs_box">
58
- <div class="nxs_box_header">
59
- <div class="nsx_iconedTitle" style="margin-bottom:1px;background-image:url(<?php echo $nxs_plurl;?>img/<?php echo $ntInfo['lcode']; ?>16.png);"><?php echo $ntInfo['name']; ?>
60
- <?php $cbo = count($ntOpts); ?> <?php wp_nonce_field( 'ns'.$ntInfo['code'], 'ns'.$ntInfo['code'].'_wpnonce' ); ?>
61
- <?php if ($cbo>1){ ?><div class="nsBigText"><?php echo "(".($cbo=='0'?'No':$cbo)." "; _e('accounts', 'nxs_snap'); echo ")"; ?></div><?php } ?>
62
- </div>
63
- </div>
64
- <div class="nxs_box_inside">
65
- <?php foreach ($ntOpts as $indx=>$pbo){ if (trim($pbo['nName']=='')) $pbo['nName'] = $pbo[$ntInfo['defNName']];
66
- if (!isset($pbo[$ntInfo['lcode'].'OK']) || $pbo[$ntInfo['lcode'].'OK']=='') $pbo[$ntInfo['lcode'].'OK'] = (isset($pbo['liAccessToken']) && $pbo['liAccessTokenSecret']!='')?'1':'';
67
- ?>
68
- <p style="margin:0px;margin-left:5px;">
69
- <input value="1" name="<?php echo $ntInfo['lcode']; ?>[<?php echo $indx; ?>][apDo<?php echo $ntInfo['code']; ?>]" onchange="doShowHideBlocks('<?php echo $ntInfo['code']; ?>');" type="checkbox" <?php if ((int)$pbo['do'.$ntInfo['code']] == 1) echo "checked"; ?> /> <?php if ((int)$pbo['catSel'] == 1) { ?> <span onmouseout="nxs_hidePopUpInfo('popOnlyCat');" onmouseover="nxs_showPopUpInfo('popOnlyCat', event);"><?php echo "*[".(substr_count($pbo['catSelEd'], ",")+1)."]*" ?></span><?php } ?>
70
- <strong><?php _e('Auto-publish to', 'nxs_snap'); ?> <?php echo $ntInfo['name']; ?> <i style="color: #005800;"><?php if($pbo['nName']!='') echo "(".$pbo['nName'].")"; ?></i></strong>
71
- &nbsp;&nbsp;<?php if ($ntInfo['tstReq'] && (!isset($pbo[$ntInfo['lcode'].'OK']) || $pbo[$ntInfo['lcode'].'OK']=='')){ ?><b style="color: #800000"><?php _e('Attention requred. Unfinished setup', 'nxs_snap'); ?> ==&gt;</b><?php } ?><a id="do<?php echo $ntInfo['code'].$indx; ?>A" href="#" onclick="doShowHideBlocks2('<?php echo $ntInfo['code'].$indx; ?>');return false;">[<?php _e('Show Settings', 'nxs_snap'); ?>]</a>&nbsp;&nbsp;
72
- <a href="#" onclick="doDelAcct('<?php echo $ntInfo['lcode']; ?>', '<?php echo $indx; ?>', '<?php if (isset($pbo['bgBlogID'])) echo $pbo['nName']; ?>');return false;">[<?php _e('Remove Account', 'nxs_snap'); ?>]</a>
73
- </p><?php $this->showNTSettings($indx, $pbo);
74
- }?>
75
- </div>
76
- </div> <?php
77
- }
78
- //#### Show NEW Settings Page
79
- function showNewNTSettings($bo){ $po = array('nName'=>'', 'ulName'=>'', 'uPass'=>'', 'grpID'=>'', 'uPage'=>'', 'doLI'=>'1', 'liAPIKey'=>'', 'liAPISec'=>'', 'liUserInfo'=>'', 'liAttch'=>'1', 'liOAuthToken'=>'', 'liMsgFormat'=>'New post has been published on %SITENAME%', 'liMsgFormatT'=>'New post - %TITLE%' ); $this->showNTSettings($bo, $po, true);}
80
- //#### Show Unit Settings
81
- function showNTSettings($ii, $options, $isNew=false){ global $nxs_plurl,$nxs_snapThisPageUrl; if (!isset($options['liOK'])) $options['liOK'] = ''; ?>
82
- <div id="doLI<?php echo $ii; ?>Div" class="insOneDiv<?php if ($isNew) echo " clNewNTSets"; ?>" style="background-image: url(<?php echo $nxs_plurl; ?>img/li-bg.png); background-position:90% 10%;"> <input type="hidden" name="apDoSLI<?php echo $ii; ?>" value="0" id="apDoSLI<?php echo $ii; ?>" />
83
- <?php if ($isNew) { ?> <input type="hidden" name="li[<?php echo $ii; ?>][apDoLI]" value="1" id="apDoNewLI<?php echo $ii; ?>" /> <?php } ?>
84
- <div id="doLI<?php echo $ii; ?>Div" style="margin-left: 10px;">
85
-
86
- <div class="nsx_iconedTitle" style="float: right; background-image: url(<?php echo $nxs_plurl; ?>img/li16.png);"><a style="font-size: 12px;" target="_blank" href="http://www.nextscripts.com/setup-installation-linkedin-social-networks-auto-poster-wordpress/"><?php $nType="LinkedIn"; printf( __( 'Detailed %s Installation/Configuration Instructions' , 'nxs_snap'), $nType); ?></a></div>
87
-
88
- <div style="width:100%;"><strong><?php _e('Account Nickname', 'nxs_snap'); ?>:</strong> <i><?php _e('Just so you can easely identify it', 'nxs_snap'); ?></i> </div><input name="li[<?php echo $ii; ?>][nName]" id="linName<?php echo $ii; ?>" style="font-weight: bold; color: #005800; border: 1px solid #ACACAC; width: 40%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['nName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /><br/>
89
- <?php echo nxs_addQTranslSel('li', $ii, $options['qTLng']); ?><?php echo nxs_addPostingDelaySel('li', $ii, $options['nHrs'], $options['nMin']); ?>
90
-
91
- <?php if (!$isNew) { ?>
92
- <div style="width:100%;"><strong><?php _e('Categories', 'nxs_snap'); ?>:</strong>
93
- <input value="0" id="catSelA<?php echo $ii; ?>" type="radio" name="li[<?php echo $ii; ?>][catSel]" <?php if ((int)$options['catSel'] != 1) echo "checked"; ?> /> All
94
- <input value="1" id="catSelSLI<?php echo $ii; ?>" type="radio" name="li[<?php echo $ii; ?>][catSel]" <?php if ((int)$options['catSel'] == 1) echo "checked"; ?> /> <a href="#" style="text-decoration: none;" class="showCats" id="nxs_SCA_LI<?php echo $ii; ?>" onclick="jQuery('#catSelSLI<?php echo $ii; ?>').attr('checked', true); jQuery('#tmpCatSelNT').val('LI<?php echo $ii; ?>'); nxs_markCats( jQuery('#nxs_SC_LI<?php echo $ii; ?>').val() ); jQuery('#showCatSel').bPopup({ modalClose: false, appendTo: '#nsStForm', opacity: 0.6, follow: [false, false], position: [75, 'auto']}); return false;">Selected<?php if ($options['catSelEd']!='') echo "[".(substr_count($options['catSelEd'], ",")+1)."]"; ?></a>
95
- <input type="hidden" name="li[<?php echo $ii; ?>][catSelEd]" id="nxs_SC_LI<?php echo $ii; ?>" value="<?php echo $options['catSelEd']; ?>" />
96
- <br/><i><?php _e('Only selected categories will be autoposted to this account', 'nxs_snap'); ?></i></div>
97
- <br/>
98
- <?php } ?>
99
-
100
- <table width="800" border="0" cellpadding="10">
101
- <tr><td colspan="2">
102
- <div style="width:100%; text-align: center; color:#005800; font-weight: bold; font-size: 14px;">You can choose what API you would like to use. </div>
103
- </td></tr>
104
- <tr><td valign="top" width="50%" style="border-right: 1px solid #999;">
105
- <span style="color:#005800; font-weight: bold; font-size: 14px;">LinkedIn Native API:</span> Free built-in API from LinkedIn. Can be used for posting to your profile only. More secure, more stable. More complicated - requires LinkedIn App and authorization. <a target="_blank" href="http://www.nextscripts.com/setup-installation-linkedin-social-networks-auto-poster-wordpress/">LinkedIn Installation/configuration instructions</a><br/><br/>
106
-
107
- <div class="subDiv" id="sub<?php echo $ii; ?>DivL" style="display: block;">
108
-
109
- <div style="width:100%;"><strong>Your LinkedIn API Key:</strong> </div><input name="li[<?php echo $ii; ?>][apLIAPIKey]" id="apLIAPIKey" style="width: 70%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['liAPIKey'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
110
- <div style="width:100%;"><strong>Your LinkedIn API Secret:</strong> </div><input name="li[<?php echo $ii; ?>][apLIAPISec]" id="apLIAPISec" style="width: 70%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['liAPISec'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
111
-
112
- <br/><br/><div style="width:100%;"><strong>Your LinkedIn Group ID:</strong><br/> Fill only if you are posting to LinkedIn Group. Leave empty to post to your profile. </div><input name="li[<?php echo $ii; ?>][grpID]" id="" style="width: 70%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['grpID'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
113
-
114
- <br/><br/>
115
- <?php
116
- if($options['liAPIKey']=='') { ?>
117
- <b>Authorize Your LinkedIn Account</b>. Please save your settings and come back here to Authorize your account.
118
- <?php } else { if(isset($options['liAccessToken']) && isset($options['liAccessTokenSecret']) && $options['liAccessTokenSecret']!=='') { ?>
119
- Your LinkedIn Account has been authorized. <br/>User ID: <?php _e(apply_filters('format_to_edit', $options['liUserInfo']), 'nxs_snap') ?>.
120
- <br/>You can Re- <?php } ?>
121
- <a href="<?php echo $nxs_snapThisPageUrl; ?>&auth=li&acc=<?php echo $ii; ?>">Authorize Your LinkedIn Account</a>
122
-
123
- <?php if (!isset($options['liAccessTokenSecret']) || $options['liAccessTokenSecret']=='') { ?> <div class="blnkg">&lt;=== Authorize your account ===</div> <?php } ?>
124
-
125
- <?php } ?>
126
- </div>
127
- </td><td valign="top" width="50%">
128
-
129
-
130
-
131
- <span style="color:#005800; font-weight: bold; font-size: 14px;">NextScripts LinkedIn API:</span> Premium API with extended functionality. Can be used for posting to your profile, <b>group page</b> or <b>company page</b>. Less secure - requires your password. Use it only if you need to post to your LinkedIn Company Page.<br/><br/>
132
-
133
- <?php if (function_exists("doConnectToLinkedIn")) { ?>
134
-
135
- <div class="subDiv" id="sub<?php echo $ii; ?>DivN" style="display: block;"> <span style="color:#800000; font-size: 14px;"> <b>Beta</b>, please <a target="_blank" href="http://www.nextscripts.com/support/">report</a> any problems.</span><br/><br/>
136
- <div style="width:100%;"><strong>Your LinkedIn Page URL:</strong> Could be your company page or group page. Leave empty to post to your own profile.</div><input name="li[<?php echo $ii; ?>][uPage]" id="liuPage" style="width: 90%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['uPage'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
137
- <br/>
138
- <div style="width:100%;"><strong>Your LinkedIn Username/Email:</strong> </div><input name="li[<?php echo $ii; ?>][ulName]" id="liulName" style="width: 70%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['ulName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
139
- <div style="width:100%;"><strong>Your LinkedIn Password:</strong> </div><input type="password" name="li[<?php echo $ii; ?>][uPass]" id="liuPass" style="width: 75%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['uPass'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
140
-
141
- </div>
142
-
143
- <?php } else { ?>
144
-
145
- You can get NextScripts LinkedIn API <a target="_blank" href="http://www.nextscripts.com/linkedin-api-automated-posting/"><b>here</b></a>.
146
-
147
- <?php } ?>
148
-
149
- </td></tr></table>
150
-
151
- <br/><br/>
152
-
153
- <div id="altFormat">
154
- <div style="width:100%;"><strong id="altFormatText"><?php _e('Message text Format', 'nxs_snap'); ?>:</strong> </div>
155
- <textarea cols="150" rows="3" id="li<?php echo $ii; ?>SNAPformat" name="li[<?php echo $ii; ?>][apLIMsgFrmt]" style="width:51%;max-width: 650px;" onfocus="jQuery('#li<?php echo $ii; ?>SNAPformat').attr('rows', 6); mxs_showFrmtInfo('apLIMsgFrmt<?php echo $ii; ?>');"><?php _e(apply_filters('format_to_edit',htmlentities($options['liMsgFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?></textarea>
156
- <?php nxs_doShowHint("apIPMsgFrmt".$ii); ?>
157
- </div>
158
-
159
- <p style="margin: 0px;"><input value="1" id="apLIAttch" onchange="doShowHideAltFormat();" type="checkbox" name="li[<?php echo $ii; ?>][apLIAttch]" <?php if ((int)$options['liAttch'] == 1) echo "checked"; ?> />
160
- <strong>Publish Posts to LinkedIn as an Attachment</strong>
161
- </p>
162
-
163
- <div style="margin-left: 10px;">
164
-
165
- <strong><?php _e('Attachment Text Format', 'nxs_snap'); ?>:</strong><br/>
166
- <input value="1" id="apLIMsgAFrmtA<?php echo $ii; ?>" <?php if (trim($options['liMsgAFrmt'])=='') echo "checked"; ?> onchange="if (jQuery(this).is(':checked')) { jQuery('#apLIMsgAFrmtDiv<?php echo $ii; ?>').hide(); jQuery('#apLIMsgAFrmt<?php echo $ii; ?>').val(''); }else jQuery('#apLIMsgAFrmtDiv<?php echo $ii; ?>').show();" type="checkbox" name="li[<?php echo $ii; ?>][apLIMsgAFrmtA]"/> <strong><?php _e('Auto', 'nxs_snap'); ?></strong>
167
- <i> - <?php _e('Recommended. Info from SEO Plugins will be used, then post excerpt, then post text', 'nxs_snap'); ?> </i><br/>
168
- <div id="apLIMsgAFrmtDiv<?php echo $ii; ?>" style="<?php if ($options['liMsgAFrmt']=='') echo "display:none;"; ?>" >&nbsp;&nbsp;&nbsp; <?php _e('Set your own format', 'nxs_snap'); ?>:<input name="li[<?php echo $ii; ?>][apLIMsgAFrmt]" id="apLIMsgAFrmt<?php echo $ii; ?>" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['liMsgAFrmt'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /><br/></div>
169
-
170
- </div>
171
-
172
- <br/>
173
- <div id="altFormat">
174
- <div style="width:100%;"><strong id="altFormatText"><?php _e('Message title Format (Groups Only)', 'nxs_snap'); ?>:</strong> </div>
175
-
176
- <input name="li[<?php echo $ii; ?>][apLIMsgFrmtT]" id="li<?php echo $ii; ?>SNAPformatT" style="width: 50%;" value="<?php if ($isNew) echo "New Post - %TITLE%"; else _e(apply_filters('format_to_edit',htmlentities($options['liMsgFormatT'], ENT_COMPAT, "UTF-8")), 'nxs_snap'); ?>" onfocus="mxs_showFrmtInfo('apLIMsgFrmtT<?php echo $ii; ?>');" /><?php nxs_doShowHint("apIPMsgFrmt".$ii); ?>
177
-
178
- </div>
179
-
180
- <br/>
181
-
182
- <?php if($options['liAPIKey']!='' || (isset($options['uPass']) && $options['uPass']!='')) { ?>
183
- <?php wp_nonce_field( 'rePostToLI', 'rePostToLI_wpnonce' ); ?>
184
- <br/><b><?php _e('Test your settings', 'nxs_snap'); ?>:</b>&nbsp;&nbsp;&nbsp; <a href="#" class="NXSButton" onclick="testPost('LI', '<?php echo $ii; ?>'); return false;"><?php printf( __( 'Submit Test Post to %s', 'nxs_snap' ), $nType); ?></a>
185
-
186
- <?php if (!isset($options['liOK']) || $options['liOK']=='') { ?> <div class="blnkg">&lt;=== Click "Test" to finish setup ===</div> <?php } ?>
187
-
188
- <br/><?php }?>
189
- <div class="submit"><input type="submit" class="button-primary" name="update_NS_SNAutoPoster_settings" value="<?php _e('Update Settings', 'nxs_snap') ?>" /></div>
190
- </div>
191
- </div>
192
- <?php
193
-
194
-
195
- }
196
- //#### Set Unit Settings from POST
197
- function setNTSettings($post, $options){ global $nxs_snapThisPageUrl;
198
- foreach ($post as $ii => $pval){ // prr($pval);
199
- if ( (isset($pval['apLIAPIKey']) && $pval['apLIAPISec']!='') || (isset($pval['uPass']) && $pval['uPass']!='') ) { if (!isset($options[$ii])) $options[$ii] = array(); $options[$ii]['ii'] = $ii;
200
- if (isset($pval['apDoLI'])) $options[$ii]['doLI'] = $pval['apDoLI']; else $options[$ii]['doLI'] = 0;
201
- if (isset($pval['nName'])) $options[$ii]['nName'] = trim($pval['nName']);
202
- if (isset($pval['apLIAPIKey']))$options[$ii]['liAPIKey'] = trim($pval['apLIAPIKey']);
203
- if (isset($pval['apLIAPISec']))$options[$ii]['liAPISec'] = trim($pval['apLIAPISec']);
204
- if (isset($pval['apLIAttch'])) $options[$ii]['liAttch'] = $pval['apLIAttch']; else $options[$ii]['liAttch'] = 0;
205
-
206
- if (isset($pval['catSel'])) $options[$ii]['catSel'] = trim($pval['catSel']);
207
- if ($options[$ii]['catSel']=='1' && trim($pval['catSelEd'])!='') $options[$ii]['catSelEd'] = trim($pval['catSelEd']); else $options[$ii]['catSelEd'] = '';
208
-
209
- if (isset($pval['ulName'])) $options[$ii]['ulName'] = trim($pval['ulName']);
210
- if (isset($pval['uPass'])) $options[$ii]['uPass'] = trim($pval['uPass']);
211
- if (isset($pval['grpID'])) $options[$ii]['grpID'] = trim($pval['grpID']);
212
- if (isset($pval['uPage'])) $options[$ii]['uPage'] = trim($pval['uPage']);
213
- if (isset($pval['apLIMsgFrmt'])) $options[$ii]['liMsgFormat'] = trim($pval['apLIMsgFrmt']);
214
- if (isset($pval['apLIMsgFrmtT'])) $options[$ii]['liMsgFormatT'] = trim($pval['apLIMsgFrmtT']);
215
- if (isset($pval['apLIMsgAFrmt'])) $options[$ii]['liMsgAFrmt'] = trim($pval['apLIMsgAFrmt']);
216
-
217
- if (isset($pval['delayHrs'])) $options[$ii]['nHrs'] = trim($pval['delayHrs']); if (isset($pval['delayMin'])) $options[$ii]['nMin'] = trim($pval['delayMin']);
218
- if (isset($pval['qTLng'])) $options[$ii]['qTLng'] = trim($pval['qTLng']);
219
- } //prr($options);
220
- } return $options;
221
- }
222
- //#### Show Post->Edit Meta Box Settings
223
- function showEdPostNTSettings($ntOpts, $post){ global $nxs_plurl; $post_id = $post->ID; //prr($ntOpts);
224
- foreach($ntOpts as $ii=>$options) { $pMeta = maybe_unserialize(get_post_meta($post_id, 'snapLI', true)); if (is_array($pMeta)) $options = $this->adjMetaOpt($options, $pMeta[$ii]);
225
- $doLI = $options['doLI'] && (is_array($pMeta) || $options['catSel']!='1');
226
- $isAvailLI = (isset($options['liOAuthVerifier']) && $options['liOAuthVerifier']!='' && $options['liAccessTokenSecret']!='' && $options['liAccessToken']!='' && $options['liAPIKey']!='') || ($options['ulName']!=='' && $options['uPass']!=='');
227
- $isAttachLI = $options['liAttch']; $liMsgFormat = htmlentities($options['liMsgFormat'], ENT_COMPAT, "UTF-8"); $liMsgFormatT = htmlentities($options['liMsgFormatT'], ENT_COMPAT, "UTF-8");
228
- ?>
229
-
230
- <tr><th style="text-align:left;" colspan="2"><?php if ( $options['catSel']=='1' && trim($options['catSelEd'])!='' ) { ?> <input type="hidden" class="nxs_SC" id="nxs_SC_LI<?php echo $ii; ?>" value="<?php echo $options['catSelEd']; ?>" /> <?php } ?>
231
- <?php if ($isAvailLI) { ?><input class="nxsGrpDoChb" value="1" id="doLI<?php echo $ii; ?>" <?php if ($post->post_status == "publish") echo 'disabled="disabled"';?> type="checkbox" name="li[<?php echo $ii; ?>][doLI]" <?php if ((int)$doLI == 1) echo 'checked="checked" title="def"'; ?> />
232
- <?php if ($post->post_status == "publish") { ?> <input type="hidden" name="li[<?php echo $ii; ?>][doLI]" value="<?php echo $doLI;?>"> <?php } ?> <?php } ?>
233
- <div class="nsx_iconedTitle" style="display: inline; font-size: 13px; background-image: url(<?php echo $nxs_plurl; ?>img/li16.png);">LinkedIn - <?php _e('publish to', 'nxs_snap') ?> (<i style="color: #005800;"><?php echo $options['nName']; ?></i>)</div></th><td><?php //## Only show RePost button if the post is "published"
234
- if ($post->post_status == "publish" && $isAvailLI) { ?><input alt="<?php echo $ii; ?>" style="float: right;" onmouseout="hidePopShAtt('SV');" onmouseover="showPopShAtt('SV', event);" onclick="return false;" type="button" class="button" name="rePostToLI_repostButton" id="rePostToLI_button" value="<?php _e('Repost to LinkedIn', 'nxs_snap') ?>" />
235
- <?php wp_nonce_field( 'rePostToLI', 'rePostToLI_wpnonce' ); } ?>
236
-
237
- <?php if (is_array($pMeta) && is_array($pMeta[$ii]) && isset($pMeta[$ii]['pgID']) ) {
238
- ?> <span id="pstdLI<?php echo $ii; ?>" style="float: right;padding-top: 4px; padding-right: 10px;">
239
- <a style="font-size: 10px;" href="<?php if ($options['uPage']!='') echo $options['uPage']; else { echo $pMeta[$ii]['pgID']; } ?>" target="_blank"><?php $nType="LinkedIn"; printf( __( 'Posted on', 'nxs_snap' ), $nType); ?> <?php echo (isset($pMeta[$ii]['pDate']) && $pMeta[$ii]['pDate']!='')?(" (".$pMeta[$ii]['pDate'].")"):""; ?></a>
240
- </span><?php } ?>
241
-
242
- </td></tr>
243
- <?php if (!$isAvailLI) { ?><tr><th scope="row" style="text-align:right; width:150px; padding-top: 5px; padding-right:10px;"></th> <td><b>Setup your LinkedIn Account to AutoPost to LinkedIn</b>
244
- <?php } elseif ($post->post_status != "puZblish") { ?>
245
-
246
- <tr><th scope="row" style="text-align:right; width:150px; vertical-align:top; padding-top: 5px; padding-right:10px;">
247
- <input value="0" type="hidden" name="li[<?php echo $ii; ?>][AttachPost]"/>
248
- <input value="1" id="SNAP_AttachLI" onchange="doShowHideAltFormatX();" type="checkbox" name="li[<?php echo $ii; ?>][AttachPost]" <?php if ((int)$isAttachLI == 1) echo "checked"; ?> /> </th><td><strong>Publish Post to LinkedIn as Attachment</strong></td> </tr>
249
-
250
- <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top: 6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Message Format:', 'nxs_snap') ?></th>
251
- <td>
252
- <textarea cols="150" rows="1" id="li<?php echo $ii; ?>SNAPformat" name="li[<?php echo $ii; ?>][SNAPformat]" style="width:60%;max-width: 610px;" onfocus="jQuery('#li<?php echo $ii; ?>SNAPformat').attr('rows', 4); jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apLIMsgFrmt<?php echo $ii; ?>');"><?php echo $liMsgFormat; ?></textarea>
253
- <?php nxs_doShowHint("apLIMsgFrmt".$ii); ?></td></tr>
254
-
255
- <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top: 6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Title Format (Groups Only):', 'nxs_snap') ?></th>
256
- <td><input value="<?php echo $liMsgFormatT ?>" type="text" name="li[<?php echo $ii; ?>][SNAPformatT]" style="width:60%;max-width: 610px;" onfocus="jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apLIMsgFrmtT<?php echo $ii; ?>');"/><?php nxs_doShowHint("apLIMsgFrmtT".$ii, '', '58'); ?></td></tr>
257
-
258
- <?php }
259
- }
260
- }
261
-
262
- function adjMetaOpt($optMt, $pMeta){ if (isset($pMeta['isPosted'])) $optMt['isPosted'] = $pMeta['isPosted']; else $optMt['isPosted'] = '';
263
- if (isset($pMeta['SNAPformat'])) $optMt['liMsgFormat'] = $pMeta['SNAPformat']; if (trim($optMt['liMsgFormat'])=='') $optMt['liMsgFormat'] = '&nbsp;';
264
- if (isset($pMeta['SNAPformatT'])) $optMt['liMsgFormatT'] = $pMeta['SNAPformatT']; if (trim($optMt['liMsgFormatT'])=='') $optMt['liMsgFormatT'] = '&nbsp;';
265
- if (isset($pMeta['AttachPost'])) $optMt['liAttch'] = $pMeta['AttachPost'] == 1?1:0; else { if (isset($pMeta['SNAPformat'])) $optMt['liAttch'] = 0; }
266
- if (isset($pMeta['doLI'])) $optMt['doLI'] = $pMeta['doLI'] == 1?1:0; else { if (isset($pMeta['SNAPformat'])) $optMt['doLI'] = 0; }
267
- if (isset($pMeta['SNAPincludeLI']) && $pMeta['SNAPincludeLI'] == '1' ) $optMt['doLI'] = 1;
268
- return $optMt;
269
- }
270
- }}
271
-
272
- if (!function_exists("nxs_rePostToLI_ajax")) { function nxs_rePostToLI_ajax() { check_ajax_referer('rePostToLI'); $postID = $_POST['id']; // $result = nsPublishTo($id, 'FB', true);
273
- global $plgn_NS_SNAutoPoster; if (!isset($plgn_NS_SNAutoPoster)) return; $options = $plgn_NS_SNAutoPoster->nxs_options;
274
- foreach ($options['li'] as $ii=>$po) if ($ii==$_POST['nid']) { $po['ii'] = $ii; $po['pType'] = 'aj';
275
- $mpo = get_post_meta($postID, 'snapLI', true); $mpo = maybe_unserialize($mpo);
276
- if (is_array($mpo) && isset($mpo[$ii]) && is_array($mpo[$ii]) ){ $ntClInst = new nxs_snapClassLI(); $po = $ntClInst->adjMetaOpt($po, $mpo[$ii]); }
277
- $result = nxs_doPublishToLI($postID, $po); if ($result == 200 && ($postID=='0') && $options['li'][$ii]['liOK']!='1') { $options['li'][$ii]['liOK']=1; update_option('NS_SNAutoPoster', $options); }
278
- if ($result == 200) die("Successfully sent your post to LinkedIn."); else die($result);
279
- }
280
- }
281
- }
282
-
283
- if (!function_exists("nxs_doPublishToLI")) { //## Second Function to Post to LI
284
- function nxs_doPublishToLI($postID, $options){ global $nxs_gCookiesArr; $ntCd = 'LI'; $ntCdL = 'li'; $ntNm = 'LinkedIn';
285
- //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToLI', array($postID, $options));
286
- $ii = $options['ii']; if (!isset($options['pType'])) $options['pType'] = 'im'; if ($options['pType']=='sh') sleep(rand(1, 10));
287
- $logNT = '<span style="color:#000058">LinkedIn</span> - '.$options['nName'];
288
- $snap_ap = get_post_meta($postID, 'snap'.$ntCd, true); $snap_ap = maybe_unserialize($snap_ap);
289
- if ($options['pType']!='aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
290
- $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted!='2') { sleep(5);
291
- nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:'.$postID, 'Already posted. No reason for posting duplicate'.' |'.$uqID); return;
292
- }
293
- }
294
-
295
- $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle=='') $blogTitle = home_url(); // prr($options);
296
- if ($postID=='0') { echo "Testing ... <br/><br/>"; $msgT = 'Test Post from '.$blogTitle; $link = home_url(); $msg = 'Test Post from '.$blogTitle. " ".$link; $isAttachLI = ''; $title = $blogTitle; }
297
- else { $post = get_post($postID); if(!$post) return; $liMsgFormat = $options['liMsgFormat']; $msg = nsFormatMessage($liMsgFormat, $postID); $msgT = nsFormatMessage($options['liMsgFormatT'], $postID);
298
- $link = get_permalink($postID); $isAttachLI = $options['liAttch']; $title = nsTrnc($post->post_title, 200); nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted'=>'1'));
299
- }
300
- $extInfo = ' | PostID: '.$postID." - ".$post->post_title; $msgT = nsTrnc($msgT, 200);
301
- if ($isAttachLI=='1') {
302
- if (trim($options['liMsgAFrmt'])!='') {$dsc = nsFormatMessage($options['liMsgAFrmt'], $postID, $addParams);} else {
303
- $src = nxs_getPostImage($postID); $dsc = trim(apply_filters('the_content', $post->post_excerpt)); if ($dsc=='') $dsc = apply_filters('the_content', $post->post_content);
304
- } $dsc = strip_tags($dsc); $dsc = nxs_decodeEntitiesFull($dsc); $dsc = nxs_html_to_utf8($dsc); $dsc = nsTrnc($dsc, 300);
305
- }
306
- $msg = nxs_html_to_utf8($msg); $msgT = nxs_html_to_utf8($msgT);
307
- if (function_exists("doConnectToLinkedIn") && $options['ulName']!='' && $options['uPass']!='') {
308
- $auth = doConnectToLinkedIn($options['ulName'], $options['uPass'], $options['ii']); if ($auth!==false) die($auth);
309
- $to = $options['uPage']!=''?$options['uPage']:'http://www.linkedin.com/home'; $lnk = array(); $msg = str_ireplace('&nbsp;',' ',$msg); $msg = nsTrnc(strip_tags($msg), 700);
310
- if ($postID=='0') { $lnk['title'] = get_bloginfo('name'); $lnk['desc'] = get_bloginfo('description'); $lnk['url'] = home_url();
311
- } else { if ($isAttachLI=='1') { $lnk['title'] = nsTrnc( strip_tags($post->post_title), 200); $lnk['postTitle'] = $msgT; $lnk['desc'] = $dsc; $lnk['url'] = get_permalink($postID); $lnk['img'] = $src; }} //prr($msg);
312
- $ret = doPostToLinkedIn($msg, $lnk, $to); $liPostID = $options['uPage'];
313
- } else { require_once ('apis/liOAuth.php'); $linkedin = new nsx_LinkedIn($options['liAPIKey'], $options['liAPISec']); $linkedin->oauth_verifier = $options['liOAuthVerifier'];
314
- $linkedin->request_token = new nsx_trOAuthConsumer($options['liOAuthToken'], $options['liOAuthTokenSecret'], 1);
315
- $linkedin->access_token = new nsx_trOAuthConsumer($options['liAccessToken'], $options['liAccessTokenSecret'], 1); $msg = nsTrnc($msg, 700);
316
- if ($options['grpID']!=''){
317
- try{ // prr($msgT); prr($msg); prr($options['grpID']); prr($src); prr($dsc); $purl = get_permalink($postID); prr($purl);
318
- if($isAttachLI=='1') $ret = $linkedin->postToGroup($msg, $msgT, $options['grpID'], get_permalink($postID), $src, $dsc); else $ret = $linkedin->postToGroup($msg, $msgT, $options['grpID']);
319
- $liPostID= 'http://www.linkedin.com/groups?gid='.$options['grpID'];
320
- } catch (Exception $o){ nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '."Linkedin Status couldn't be updated! - ".print_r($o, true)); $ret="ERROR:".print_r($o, true); }
321
- } else {
322
- try{ if($isAttachLI=='1') $ret = $linkedin->postShare($msg, nsTrnc($post->post_title, 200), get_permalink($postID), $src, $dsc); else $ret = $linkedin->postShare($msg); }
323
- catch (Exception $o){ nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '."<br/>Linkedin Status couldn't be updated! - ".print_r($o, true)); $ret="ERROR:".print_r($o, true); }
324
- }
325
- //$liPostID = $linkedin->getCurrentShare(); prr($liPostID);
326
- if ($liPostID=='') $liPostID = $options['liUserInfo'];
327
- }
328
- if (stripos($ret, 'update-url')!==false) { $liPostID = CutFromTo($ret, '<update-url>','</update-url>'); $ret = '201'; }
329
- if ($ret!='201') { if ($postID=='0') prr($ret); nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.print_r($ret, true), $extInfo); }
330
- else if ($postID=='0') { echo 'OK - Linkedin status updated successfully'; nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); } else
331
- { nxs_metaMarkAsPosted($postID, 'LI', $options['ii'], array('isPosted'=>'1', 'pgID'=>$liPostID, 'pDate'=>date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); }
332
- if ($ret=='201') return true; else return 'Something Wrong';
333
- }
334
- }
335
-
 
 
 
 
 
 
336
  ?>
1
+ <?php
2
+
3
+ if (isset($_GET['ca']) && $_GET['ca']!='') { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/recaptcha/api/image?c='.$_GET['ca']);
4
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_REFERER, 'https://www.google.com/'); $imageData = curl_exec($ch);
5
+ header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
6
+ header("Cache-Control: private",false); header("Content-Type: image/jpg"); header("Content-Transfer-Encoding: binary"); echo $imageData; die();
7
+ }
8
+
9
+ add_action('wp_ajax_nxsCptCheck' , 'nxsCptCheck_ajax');
10
+ if (!function_exists("nxsCptCheck_ajax")) { function nxsCptCheck_ajax() { global $nxs_gCookiesArr;
11
+ if ($_POST['c']!='') { $seForDB = get_option('nxs_li_ctp_save'); $ser = maybe_unserialize($seForDB); $nxs_gCookiesArr = $ser['c']; $flds = $ser['f'];
12
+ $flds['recaptcha_response_field'] = $_POST['c']; $cfldsTxt = build_http_query($flds); // prr($cfldsTxt); prr($nxs_gCookiesArr);
13
+ $contents2 = getCurlPageX('https://www.linkedin.com/uas/captcha-submit','https://www.linkedin.com/uas/login-submit', false, $cfldsTxt, false, $advSettings); // prr($contents2);
14
+ if (stripos($contents2['content'], 'The email address or password you provided does not match our records')!==false) { echo "Invalid Login/Password"; die(); }
15
+ if (stripos($contents2['url'], 'linkedin.com/uas/captcha-submit')!==false) echo "Wrong Captcha. Please try Again";
16
+ if (stripos($contents2['url'], 'linkedin.com/home')!==false) { echo "OK. You are In";
17
+ $contents3 = getCurlPageX('http://www.linkedin.com/profile/edit?trk=tab_pro', 'http://www.linkedin.com/home', false, '', false, $advSettings); // prr($contents3);
18
+ if ($_POST['i']!='') { global $plgn_NS_SNAutoPoster; if (!isset($plgn_NS_SNAutoPoster)) return; $options = $plgn_NS_SNAutoPoster->nxs_options;
19
+ $options['li'][$_POST['i']]['uCook'] = $nxs_gCookiesArr; if (is_array($options)) update_option('NS_SNAutoPoster', $options);
20
+ }
21
+ }
22
+ } die();
23
+ }}
24
+
25
+ //## NextScripts Facebook Connection Class
26
+ $nxs_snapAvNts[] = array('code'=>'LI', 'lcode'=>'li', 'name'=>'LinkedIn');
27
+
28
+ if (!class_exists("nxs_snapClassLI")) { class nxs_snapClassLI {
29
+ //#### Show Common Settings
30
+ function showGenNTSettings($ntOpts){ global $nxs_snapThisPageUrl, $nxs_plurl; $ntInfo = array('code'=>'LI', 'lcode'=>'li', 'name'=>'LinkedIn', 'defNName'=>'ulName', 'tstReq' => true);
31
+
32
+ if ( isset($_GET['auth']) && $_GET['auth']=='li'){ require_once('apis/liOAuth.php'); $options = $ntOpts[$_GET['acc']];
33
+
34
+ $api_key = $options['liAPIKey']; $api_secret = $options['liAPISec'];
35
+ $callback_url = $nxs_snapThisPageUrl."&auth=lia&acc=".$_GET['acc'];
36
+ $li_oauth = new nsx_LinkedIn($api_key, $api_secret, $callback_url);
37
+ $request_token = $li_oauth->getRequestToken(); //echo "####"; prr($request_token); die();
38
+ $options['liOAuthToken'] = $request_token->key;
39
+ $options['liOAuthTokenSecret'] = $request_token->secret; // prr($li_oauth);
40
+ switch ($li_oauth->http_code) { case 200: $url = $li_oauth->generateAuthorizeUrl(); $optionsG = get_option('NS_SNAutoPoster'); $optionsG['li'][$_GET['acc']] = $options; update_option('NS_SNAutoPoster', $optionsG);
41
+ echo '<script type="text/javascript">window.location = "'.$url.'"</script>'; break;
42
+ default: echo '<br/><b style="color:red">Could not connect to LinkedIn. Refresh the page or try again later.</b>'; die();
43
+ }die();
44
+ }
45
+ if ( isset($_GET['auth']) && $_GET['auth']=='lia'){ require_once('apis/liOAuth.php'); $options = $ntOpts[$_GET['acc']]; $api_key = $options['liAPIKey']; $api_secret = $options['liAPISec'];
46
+ $li_oauth = new nsx_LinkedIn($api_key, $api_secret); $li_oauth->request_token = new nsx_trOAuthConsumer($options['liOAuthToken'], $options['liOAuthTokenSecret'], 1);
47
+ $li_oauth->oauth_verifier = $_REQUEST['oauth_verifier']; $li_oauth->getAccessToken($_REQUEST['oauth_verifier']); $options['liOAuthVerifier'] = $_REQUEST['oauth_verifier'];
48
+ $options['liAccessToken'] = $li_oauth->access_token->key; $options['liAccessTokenSecret'] = $li_oauth->access_token->secret;
49
+ try{$xml_response = $li_oauth->getProfile("~:(id,first-name,last-name)");} catch (Exception $o){prr($o); die("<span style='color:red;'>ERROR: Authorization Error</span>");}
50
+ if (stripos($xml_response,'<first-name>')!==false) $userinfo = CutFromTo($xml_response, '<id>','</id>')." - ".CutFromTo($xml_response, '<first-name>','</first-name>')." ".CutFromTo($xml_response, '<last-name>','</last-name>'); else $userinfo='';
51
+ if ($userinfo!='') { $options['liUserInfo'] = $userinfo; $optionsG = get_option('NS_SNAutoPoster'); $optionsG['li'][$_GET['acc']] = $options; update_option('NS_SNAutoPoster', $optionsG);
52
+ echo '<script type="text/javascript">window.location = "'.$nxs_snapThisPageUrl.'"</script>'; die();
53
+ } prr($xml_response); die("<span style='color:red;'>ERROR: Something is Wrong with your LinkedIn account</span>");
54
+ }
55
+
56
+ ?>
57
+ <div class="nxs_box">
58
+ <div class="nxs_box_header">
59
+ <div class="nsx_iconedTitle" style="margin-bottom:1px;background-image:url(<?php echo $nxs_plurl;?>img/<?php echo $ntInfo['lcode']; ?>16.png);"><?php echo $ntInfo['name']; ?>
60
+ <?php $cbo = count($ntOpts); ?> <?php wp_nonce_field( 'ns'.$ntInfo['code'], 'ns'.$ntInfo['code'].'_wpnonce' ); ?>
61
+ <?php if ($cbo>1){ ?><div class="nsBigText"><?php echo "(".($cbo=='0'?'No':$cbo)." "; _e('accounts', 'nxs_snap'); echo ")"; ?></div><?php } ?>
62
+ </div>
63
+ </div>
64
+ <div class="nxs_box_inside">
65
+ <?php foreach ($ntOpts as $indx=>$pbo){ if (trim($pbo['nName']=='')) $pbo['nName'] = $pbo[$ntInfo['defNName']];
66
+ if (!isset($pbo[$ntInfo['lcode'].'OK']) || $pbo[$ntInfo['lcode'].'OK']=='') $pbo[$ntInfo['lcode'].'OK'] = (isset($pbo['liAccessToken']) && $pbo['liAccessTokenSecret']!='')?'1':'';
67
+ ?>
68
+ <p style="margin:0px;margin-left:5px;">
69
+ <input value="1" name="<?php echo $ntInfo['lcode']; ?>[<?php echo $indx; ?>][apDo<?php echo $ntInfo['code']; ?>]" onchange="doShowHideBlocks('<?php echo $ntInfo['code']; ?>');" type="checkbox" <?php if ((int)$pbo['do'.$ntInfo['code']] == 1) echo "checked"; ?> /> <?php if ((int)$pbo['catSel'] == 1) { ?> <span onmouseout="nxs_hidePopUpInfo('popOnlyCat');" onmouseover="nxs_showPopUpInfo('popOnlyCat', event);"><?php echo "*[".(substr_count($pbo['catSelEd'], ",")+1)."]*" ?></span><?php } ?>
70
+ <strong><?php _e('Auto-publish to', 'nxs_snap'); ?> <?php echo $ntInfo['name']; ?> <i style="color: #005800;"><?php if($pbo['nName']!='') echo "(".$pbo['nName'].")"; ?></i></strong>
71
+ &nbsp;&nbsp;<?php if ($ntInfo['tstReq'] && (!isset($pbo[$ntInfo['lcode'].'OK']) || $pbo[$ntInfo['lcode'].'OK']=='')){ ?><b style="color: #800000"><?php _e('Attention requred. Unfinished setup', 'nxs_snap'); ?> ==&gt;</b><?php } ?><a id="do<?php echo $ntInfo['code'].$indx; ?>A" href="#" onclick="doShowHideBlocks2('<?php echo $ntInfo['code'].$indx; ?>');return false;">[<?php _e('Show Settings', 'nxs_snap'); ?>]</a>&nbsp;&nbsp;
72
+ <a href="#" onclick="doDelAcct('<?php echo $ntInfo['lcode']; ?>', '<?php echo $indx; ?>', '<?php if (isset($pbo['bgBlogID'])) echo $pbo['nName']; ?>');return false;">[<?php _e('Remove Account', 'nxs_snap'); ?>]</a>
73
+ </p><?php $this->showNTSettings($indx, $pbo);
74
+ }?>
75
+ </div>
76
+ </div> <?php
77
+ }
78
+ //#### Show NEW Settings Page
79
+ function showNewNTSettings($bo){ $po = array('nName'=>'', 'ulName'=>'', 'uPass'=>'', 'grpID'=>'', 'uPage'=>'', 'doLI'=>'1', 'liAPIKey'=>'', 'liAPISec'=>'', 'liUserInfo'=>'', 'liAttch'=>'1', 'liOAuthToken'=>'', 'liMsgFormat'=>'New post has been published on %SITENAME%', 'liMsgFormatT'=>'New post - %TITLE%' ); $this->showNTSettings($bo, $po, true);}
80
+ //#### Show Unit Settings
81
+ function showNTSettings($ii, $options, $isNew=false){ global $nxs_plurl,$nxs_snapThisPageUrl; if (!isset($options['liOK'])) $options['liOK'] = ''; ?>
82
+ <div id="doLI<?php echo $ii; ?>Div" class="insOneDiv<?php if ($isNew) echo " clNewNTSets"; ?>" style="background-image: url(<?php echo $nxs_plurl; ?>img/li-bg.png); background-position:90% 10%;"> <input type="hidden" name="apDoSLI<?php echo $ii; ?>" value="0" id="apDoSLI<?php echo $ii; ?>" />
83
+ <?php if ($isNew) { ?> <input type="hidden" name="li[<?php echo $ii; ?>][apDoLI]" value="1" id="apDoNewLI<?php echo $ii; ?>" /> <?php } ?>
84
+ <div id="doLI<?php echo $ii; ?>Div" style="margin-left: 10px;">
85
+
86
+ <div class="nsx_iconedTitle" style="float: right; background-image: url(<?php echo $nxs_plurl; ?>img/li16.png);"><a style="font-size: 12px;" target="_blank" href="http://www.nextscripts.com/setup-installation-linkedin-social-networks-auto-poster-wordpress/"><?php $nType="LinkedIn"; printf( __( 'Detailed %s Installation/Configuration Instructions' , 'nxs_snap'), $nType); ?></a></div>
87
+
88
+ <div style="width:100%;"><strong><?php _e('Account Nickname', 'nxs_snap'); ?>:</strong> <i><?php _e('Just so you can easely identify it', 'nxs_snap'); ?></i> </div><input name="li[<?php echo $ii; ?>][nName]" id="linName<?php echo $ii; ?>" style="font-weight: bold; color: #005800; border: 1px solid #ACACAC; width: 40%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['nName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /><br/>
89
+ <?php echo nxs_addQTranslSel('li', $ii, $options['qTLng']); ?><?php echo nxs_addPostingDelaySel('li', $ii, $options['nHrs'], $options['nMin'], $options['nDays']); ?>
90
+
91
+ <?php if (!$isNew) { ?>
92
+ <div style="width:100%;"><strong><?php _e('Categories', 'nxs_snap'); ?>:</strong>
93
+ <input value="0" id="catSelA<?php echo $ii; ?>" type="radio" name="li[<?php echo $ii; ?>][catSel]" <?php if ((int)$options['catSel'] != 1) echo "checked"; ?> /> All
94
+ <input value="1" id="catSelSLI<?php echo $ii; ?>" type="radio" name="li[<?php echo $ii; ?>][catSel]" <?php if ((int)$options['catSel'] == 1) echo "checked"; ?> /> <a href="#" style="text-decoration: none;" class="showCats" id="nxs_SCA_LI<?php echo $ii; ?>" onclick="jQuery('#catSelSLI<?php echo $ii; ?>').attr('checked', true); jQuery('#tmpCatSelNT').val('LI<?php echo $ii; ?>'); nxs_markCats( jQuery('#nxs_SC_LI<?php echo $ii; ?>').val() ); jQuery('#showCatSel').bPopup({ modalClose: false, appendTo: '#nsStForm', opacity: 0.6, follow: [false, false], position: [75, 'auto']}); return false;">Selected<?php if ($options['catSelEd']!='') echo "[".(substr_count($options['catSelEd'], ",")+1)."]"; ?></a>
95
+ <input type="hidden" name="li[<?php echo $ii; ?>][catSelEd]" id="nxs_SC_LI<?php echo $ii; ?>" value="<?php echo $options['catSelEd']; ?>" />
96
+ <br/><i><?php _e('Only selected categories will be autoposted to this account', 'nxs_snap'); ?></i></div>
97
+ <br/>
98
+ <?php } ?>
99
+
100
+ <table width="800" border="0" cellpadding="10">
101
+ <tr><td colspan="2">
102
+ <div style="width:100%; text-align: center; color:#005800; font-weight: bold; font-size: 14px;">You can choose what API you would like to use. </div>
103
+ </td></tr>
104
+ <tr><td valign="top" width="50%" style="border-right: 1px solid #999;">
105
+ <span style="color:#005800; font-weight: bold; font-size: 14px;">LinkedIn Native API:</span> Free built-in API from LinkedIn. Can be used for posting to your profile only. More secure, more stable. More complicated - requires LinkedIn App and authorization. <a target="_blank" href="http://www.nextscripts.com/setup-installation-linkedin-social-networks-auto-poster-wordpress/">LinkedIn Installation/configuration instructions</a><br/><br/>
106
+
107
+ <div class="subDiv" id="sub<?php echo $ii; ?>DivL" style="display: block;">
108
+
109
+ <div style="width:100%;"><strong>Your LinkedIn API Key:</strong> </div><input name="li[<?php echo $ii; ?>][apLIAPIKey]" id="apLIAPIKey" style="width: 70%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['liAPIKey'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
110
+ <div style="width:100%;"><strong>Your LinkedIn API Secret:</strong> </div><input name="li[<?php echo $ii; ?>][apLIAPISec]" id="apLIAPISec" style="width: 70%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['liAPISec'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
111
+
112
+ <br/><br/><div style="width:100%;"><strong>Your LinkedIn Group ID:</strong><br/> Fill only if you are posting to LinkedIn Group. Leave empty to post to your profile. </div><input name="li[<?php echo $ii; ?>][grpID]" id="" style="width: 70%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['grpID'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
113
+
114
+ <br/><br/>
115
+ <?php
116
+ if($options['liAPIKey']=='') { ?>
117
+ <b>Authorize Your LinkedIn Account</b>. Please save your settings and come back here to Authorize your account.
118
+ <?php } else { if(isset($options['liAccessToken']) && isset($options['liAccessTokenSecret']) && $options['liAccessTokenSecret']!=='') { ?>
119
+ Your LinkedIn Account has been authorized. <br/>User ID: <?php _e(apply_filters('format_to_edit', $options['liUserInfo']), 'nxs_snap') ?>.
120
+ <br/>You can Re- <?php } ?>
121
+ <a href="<?php echo $nxs_snapThisPageUrl; ?>&auth=li&acc=<?php echo $ii; ?>">Authorize Your LinkedIn Account</a>
122
+
123
+ <?php if (!isset($options['liAccessTokenSecret']) || $options['liAccessTokenSecret']=='') { ?> <div class="blnkg">&lt;=== Authorize your account ===</div> <?php } ?>
124
+
125
+ <?php } ?>
126
+ </div>
127
+ </td><td valign="top" width="50%">
128
+
129
+
130
+
131
+ <span style="color:#005800; font-weight: bold; font-size: 14px;">NextScripts LinkedIn API:</span> Premium API with extended functionality. Can be used for posting to your profile, <b>group page</b> or <b>company page</b>. Less secure - requires your password. Use it only if you need to post to your LinkedIn Company Page.<br/><br/>
132
+
133
+ <?php if (function_exists("doConnectToLinkedIn")) { ?>
134
+
135
+ <div class="subDiv" id="sub<?php echo $ii; ?>DivN" style="display: block;"> <span style="color:#800000; font-size: 14px;"> <b>Beta</b>, please <a target="_blank" href="http://www.nextscripts.com/support/">report</a> any problems.</span><br/><br/>
136
+ <div style="width:100%;"><strong>Your LinkedIn Page URL:</strong> Could be your company page or group page. Leave empty to post to your own profile.</div><input name="li[<?php echo $ii; ?>][uPage]" id="liuPage" style="width: 90%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['uPage'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
137
+ <br/>
138
+ <div style="width:100%;"><strong>Your LinkedIn Username/Email:</strong> </div><input name="li[<?php echo $ii; ?>][ulName]" id="liulName" style="width: 70%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['ulName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
139
+ <div style="width:100%;"><strong>Your LinkedIn Password:</strong> </div><input type="password" name="li[<?php echo $ii; ?>][uPass]" id="liuPass" style="width: 75%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['uPass'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
140
+
141
+ </div>
142
+
143
+ <?php } else { ?>
144
+
145
+ You can get NextScripts LinkedIn API <a target="_blank" href="http://www.nextscripts.com/linkedin-api-automated-posting/"><b>here</b></a>.
146
+
147
+ <?php } ?>
148
+
149
+ </td></tr></table>
150
+
151
+ <br/><br/>
152
+
153
+ <div id="altFormat">
154
+ <div style="width:100%;"><strong id="altFormatText"><?php _e('Message text Format', 'nxs_snap'); ?>:</strong> </div>
155
+ <textarea cols="150" rows="3" id="li<?php echo $ii; ?>SNAPformat" name="li[<?php echo $ii; ?>][apLIMsgFrmt]" style="width:51%;max-width: 650px;" onfocus="jQuery('#li<?php echo $ii; ?>SNAPformat').attr('rows', 6); mxs_showFrmtInfo('apLIMsgFrmt<?php echo $ii; ?>');"><?php _e(apply_filters('format_to_edit',htmlentities($options['liMsgFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?></textarea>
156
+ <?php nxs_doShowHint("apIPMsgFrmt".$ii); ?>
157
+ </div>
158
+
159
+ <p style="margin: 0px;"><input value="1" id="apLIAttch" onchange="doShowHideAltFormat();" type="checkbox" name="li[<?php echo $ii; ?>][apLIAttch]" <?php if ((int)$options['liAttch'] == 1) echo "checked"; ?> />
160
+ <strong>Publish Posts to LinkedIn as an Attachment</strong>
161
+ </p>
162
+
163
+ <div style="margin-left: 10px;">
164
+
165
+ <strong><?php _e('Attachment Text Format', 'nxs_snap'); ?>:</strong><br/>
166
+ <input value="1" id="apLIMsgAFrmtA<?php echo $ii; ?>" <?php if (trim($options['liMsgAFrmt'])=='') echo "checked"; ?> onchange="if (jQuery(this).is(':checked')) { jQuery('#apLIMsgAFrmtDiv<?php echo $ii; ?>').hide(); jQuery('#apLIMsgAFrmt<?php echo $ii; ?>').val(''); }else jQuery('#apLIMsgAFrmtDiv<?php echo $ii; ?>').show();" type="checkbox" name="li[<?php echo $ii; ?>][apLIMsgAFrmtA]"/> <strong><?php _e('Auto', 'nxs_snap'); ?></strong>
167
+ <i> - <?php _e('Recommended. Info from SEO Plugins will be used, then post excerpt, then post text', 'nxs_snap'); ?> </i><br/>
168
+ <div id="apLIMsgAFrmtDiv<?php echo $ii; ?>" style="<?php if ($options['liMsgAFrmt']=='') echo "display:none;"; ?>" >&nbsp;&nbsp;&nbsp; <?php _e('Set your own format', 'nxs_snap'); ?>:<input name="li[<?php echo $ii; ?>][apLIMsgAFrmt]" id="apLIMsgAFrmt<?php echo $ii; ?>" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['liMsgAFrmt'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /><br/></div>
169
+
170
+ </div>
171
+
172
+ <br/>
173
+ <div id="altFormat">
174
+ <div style="width:100%;"><strong id="altFormatText"><?php _e('Message title Format (Groups Only)', 'nxs_snap'); ?>:</strong> </div>
175
+
176
+ <input name="li[<?php echo $ii; ?>][apLIMsgFrmtT]" id="li<?php echo $ii; ?>SNAPformatT" style="width: 50%;" value="<?php if ($isNew) echo "New Post - %TITLE%"; else _e(apply_filters('format_to_edit',htmlentities($options['liMsgFormatT'], ENT_COMPAT, "UTF-8")), 'nxs_snap'); ?>" onfocus="mxs_showFrmtInfo('apLIMsgFrmtT<?php echo $ii; ?>');" /><?php nxs_doShowHint("apIPMsgFrmt".$ii); ?>
177
+
178
+ </div>
179
+
180
+ <br/>
181
+
182
+ <?php if($options['liAPIKey']!='' || (isset($options['uPass']) && $options['uPass']!='')) { ?>
183
+ <?php wp_nonce_field( 'rePostToLI', 'rePostToLI_wpnonce' ); ?>
184
+ <br/><b><?php _e('Test your settings', 'nxs_snap'); ?>:</b>&nbsp;&nbsp;&nbsp; <a href="#" class="NXSButton" onclick="testPost('LI', '<?php echo $ii; ?>'); return false;"><?php printf( __( 'Submit Test Post to %s', 'nxs_snap' ), $nType); ?></a>
185
+
186
+ <?php if (!isset($options['liOK']) || $options['liOK']=='') { ?> <div class="blnkg">&lt;=== Click "Test" to finish setup ===</div> <?php } ?>
187
+
188
+ <br/><?php }?>
189
+ <div class="submit"><input type="submit" class="button-primary" name="update_NS_SNAutoPoster_settings" value="<?php _e('Update Settings', 'nxs_snap') ?>" /></div>
190
+ </div>
191
+ </div>
192
+ <?php
193
+
194
+
195
+ }
196
+ //#### Set Unit Settings from POST
197
+ function setNTSettings($post, $options){ global $nxs_snapThisPageUrl;
198
+ foreach ($post as $ii => $pval){ // prr($pval);
199
+ if ( (isset($pval['apLIAPIKey']) && $pval['apLIAPISec']!='') || (isset($pval['uPass']) && $pval['uPass']!='') ) { if (!isset($options[$ii])) $options[$ii] = array(); $options[$ii]['ii'] = $ii;
200
+ if (isset($pval['apDoLI'])) $options[$ii]['doLI'] = $pval['apDoLI']; else $options[$ii]['doLI'] = 0;
201
+ if (isset($pval['nName'])) $options[$ii]['nName'] = trim($pval['nName']);
202
+ if (isset($pval['apLIAPIKey']))$options[$ii]['liAPIKey'] = trim($pval['apLIAPIKey']);
203
+ if (isset($pval['apLIAPISec']))$options[$ii]['liAPISec'] = trim($pval['apLIAPISec']);
204
+ if (isset($pval['apLIAttch'])) $options[$ii]['liAttch'] = $pval['apLIAttch']; else $options[$ii]['liAttch'] = 0;
205
+
206
+ if (isset($pval['catSel'])) $options[$ii]['catSel'] = trim($pval['catSel']);
207
+ if ($options[$ii]['catSel']=='1' && trim($pval['catSelEd'])!='') $options[$ii]['catSelEd'] = trim($pval['catSelEd']); else $options[$ii]['catSelEd'] = '';
208
+
209
+ if (isset($pval['ulName'])) $options[$ii]['ulName'] = trim($pval['ulName']);
210
+ if (isset($pval['uPass'])) $options[$ii]['uPass'] = trim($pval['uPass']);
211
+ if (isset($pval['grpID'])) $options[$ii]['grpID'] = trim($pval['grpID']);
212
+ if (isset($pval['uPage'])) $options[$ii]['uPage'] = trim($pval['uPage']);
213
+ if (isset($pval['apLIMsgFrmt'])) $options[$ii]['liMsgFormat'] = trim($pval['apLIMsgFrmt']);
214
+ if (isset($pval['apLIMsgFrmtT'])) $options[$ii]['liMsgFormatT'] = trim($pval['apLIMsgFrmtT']);
215
+ if (isset($pval['apLIMsgAFrmt'])) $options[$ii]['liMsgAFrmt'] = trim($pval['apLIMsgAFrmt']);
216
+
217
+ if (isset($pval['delayDays'])) $options[$ii]['nDays'] = trim($pval['delayDays']);
218
+ if (isset($pval['delayHrs'])) $options[$ii]['nHrs'] = trim($pval['delayHrs']); if (isset($pval['delayMin'])) $options[$ii]['nMin'] = trim($pval['delayMin']);
219
+ if (isset($pval['qTLng'])) $options[$ii]['qTLng'] = trim($pval['qTLng']);
220
+ } //prr($options);
221
+ } return $options;
222
+ }
223
+ //#### Show Post->Edit Meta Box Settings
224
+ function showEdPostNTSettings($ntOpts, $post){ global $nxs_plurl; $post_id = $post->ID; //prr($ntOpts);
225
+ foreach($ntOpts as $ii=>$options) { $pMeta = maybe_unserialize(get_post_meta($post_id, 'snapLI', true)); if (is_array($pMeta)) $options = $this->adjMetaOpt($options, $pMeta[$ii]);
226
+ $doLI = $options['doLI'] && (is_array($pMeta) || $options['catSel']!='1');
227
+ $isAvailLI = (isset($options['liOAuthVerifier']) && $options['liOAuthVerifier']!='' && $options['liAccessTokenSecret']!='' && $options['liAccessToken']!='' && $options['liAPIKey']!='') || ($options['ulName']!=='' && $options['uPass']!=='');
228
+ $isAttachLI = $options['liAttch']; $liMsgFormat = htmlentities($options['liMsgFormat'], ENT_COMPAT, "UTF-8"); $liMsgFormatT = htmlentities($options['liMsgFormatT'], ENT_COMPAT, "UTF-8");
229
+ ?>
230
+
231
+ <tr><th style="text-align:left;" colspan="2"><?php if ( $options['catSel']=='1' && trim($options['catSelEd'])!='' ) { ?> <input type="hidden" class="nxs_SC" id="nxs_SC_LI<?php echo $ii; ?>" value="<?php echo $options['catSelEd']; ?>" /> <?php } ?>
232
+ <?php if ($isAvailLI) { ?><input class="nxsGrpDoChb" value="1" id="doLI<?php echo $ii; ?>" <?php if ($post->post_status == "publish") echo 'disabled="disabled"';?> type="checkbox" name="li[<?php echo $ii; ?>][doLI]" <?php if ((int)$doLI == 1) echo 'checked="checked" title="def"'; ?> />
233
+ <?php if ($post->post_status == "publish") { ?> <input type="hidden" name="li[<?php echo $ii; ?>][doLI]" value="<?php echo $doLI;?>"> <?php } ?> <?php } ?>
234
+ <div class="nsx_iconedTitle" style="display: inline; font-size: 13px; background-image: url(<?php echo $nxs_plurl; ?>img/li16.png);">LinkedIn - <?php _e('publish to', 'nxs_snap') ?> (<i style="color: #005800;"><?php echo $options['nName']; ?></i>)</div></th><td><?php //## Only show RePost button if the post is "published"
235
+ if ($post->post_status == "publish" && $isAvailLI) { ?><input alt="<?php echo $ii; ?>" style="float: right;" onmouseout="hidePopShAtt('SV');" onmouseover="showPopShAtt('SV', event);" onclick="return false;" type="button" class="button" name="rePostToLI_repostButton" id="rePostToLI_button" value="<?php _e('Repost to LinkedIn', 'nxs_snap') ?>" />
236
+ <?php wp_nonce_field( 'rePostToLI', 'rePostToLI_wpnonce' ); } ?>
237
+
238
+ <?php if (is_array($pMeta) && is_array($pMeta[$ii]) && isset($pMeta[$ii]['pgID']) ) {
239
+ ?> <span id="pstdLI<?php echo $ii; ?>" style="float: right;padding-top: 4px; padding-right: 10px;">
240
+ <a style="font-size: 10px;" href="<?php if ($options['uPage']!='') echo $options['uPage']; else { echo $pMeta[$ii]['pgID']; } ?>" target="_blank"><?php $nType="LinkedIn"; printf( __( 'Posted on', 'nxs_snap' ), $nType); ?> <?php echo (isset($pMeta[$ii]['pDate']) && $pMeta[$ii]['pDate']!='')?(" (".$pMeta[$ii]['pDate'].")"):""; ?></a>
241
+ </span><?php } ?>
242
+
243
+ </td></tr>
244
+ <?php if (!$isAvailLI) { ?><tr><th scope="row" style="text-align:right; width:150px; padding-top: 5px; padding-right:10px;"></th> <td><b>Setup your LinkedIn Account to AutoPost to LinkedIn</b>
245
+ <?php } elseif ($post->post_status != "puZblish") { ?>
246
+
247
+ <tr><th scope="row" style="text-align:right; width:150px; vertical-align:top; padding-top: 5px; padding-right:10px;">
248
+ <input value="0" type="hidden" name="li[<?php echo $ii; ?>][AttachPost]"/>
249
+ <input value="1" id="SNAP_AttachLI" onchange="doShowHideAltFormatX();" type="checkbox" name="li[<?php echo $ii; ?>][AttachPost]" <?php if ((int)$isAttachLI == 1) echo "checked"; ?> /> </th><td><strong>Publish Post to LinkedIn as Attachment</strong></td> </tr>
250
+
251
+ <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top: 6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Message Format:', 'nxs_snap') ?></th>
252
+ <td>
253
+ <textarea cols="150" rows="1" id="li<?php echo $ii; ?>SNAPformat" name="li[<?php echo $ii; ?>][SNAPformat]" style="width:60%;max-width: 610px;" onfocus="jQuery('#li<?php echo $ii; ?>SNAPformat').attr('rows', 4); jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apLIMsgFrmt<?php echo $ii; ?>');"><?php echo $liMsgFormat; ?></textarea>
254
+ <?php nxs_doShowHint("apLIMsgFrmt".$ii); ?></td></tr>
255
+
256
+ <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top: 6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Title Format (Groups Only):', 'nxs_snap') ?></th>
257
+ <td><input value="<?php echo $liMsgFormatT ?>" type="text" name="li[<?php echo $ii; ?>][SNAPformatT]" style="width:60%;max-width: 610px;" onfocus="jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apLIMsgFrmtT<?php echo $ii; ?>');"/><?php nxs_doShowHint("apLIMsgFrmtT".$ii, '', '58'); ?></td></tr>
258
+
259
+ <?php }
260
+ }
261
+ }
262
+
263
+ function adjMetaOpt($optMt, $pMeta){ if (isset($pMeta['isPosted'])) $optMt['isPosted'] = $pMeta['isPosted']; else $optMt['isPosted'] = '';
264
+ if (isset($pMeta['SNAPformat'])) $optMt['liMsgFormat'] = $pMeta['SNAPformat']; if (trim($optMt['liMsgFormat'])=='') $optMt['liMsgFormat'] = '&nbsp;';
265
+ if (isset($pMeta['SNAPformatT'])) $optMt['liMsgFormatT'] = $pMeta['SNAPformatT']; if (trim($optMt['liMsgFormatT'])=='') $optMt['liMsgFormatT'] = '&nbsp;';
266
+ if (isset($pMeta['AttachPost'])) $optMt['liAttch'] = $pMeta['AttachPost'] == 1?1:0; else { if (isset($pMeta['SNAPformat'])) $optMt['liAttch'] = 0; }
267
+ if (isset($pMeta['doLI'])) $optMt['doLI'] = $pMeta['doLI'] == 1?1:0; else { if (isset($pMeta['SNAPformat'])) $optMt['doLI'] = 0; }
268
+ if (isset($pMeta['SNAPincludeLI']) && $pMeta['SNAPincludeLI'] == '1' ) $optMt['doLI'] = 1;
269
+ return $optMt;
270
+ }
271
+ }}
272
+
273
+ if (!function_exists("nxs_rePostToLI_ajax")) { function nxs_rePostToLI_ajax() { check_ajax_referer('rePostToLI'); $postID = $_POST['id']; // $result = nsPublishTo($id, 'FB', true);
274
+ global $plgn_NS_SNAutoPoster; if (!isset($plgn_NS_SNAutoPoster)) return; $options = $plgn_NS_SNAutoPoster->nxs_options;
275
+ foreach ($options['li'] as $ii=>$po) if ($ii==$_POST['nid']) { $po['ii'] = $ii; $po['pType'] = 'aj';
276
+ $mpo = get_post_meta($postID, 'snapLI', true); $mpo = maybe_unserialize($mpo);
277
+ if (is_array($mpo) && isset($mpo[$ii]) && is_array($mpo[$ii]) ){ $ntClInst = new nxs_snapClassLI(); $po = $ntClInst->adjMetaOpt($po, $mpo[$ii]); }
278
+ $result = nxs_doPublishToLI($postID, $po); if ($result == 200 && ($postID=='0') && $options['li'][$ii]['liOK']!='1') { $options['li'][$ii]['liOK']=1; update_option('NS_SNAutoPoster', $options); }
279
+ if ($result == 200) die("Successfully sent your post to LinkedIn."); else die($result);
280
+ }
281
+ }
282
+ }
283
+
284
+ if (!function_exists("nxs_doPublishToLI")) { //## Second Function to Post to LI
285
+ function nxs_doPublishToLI($postID, $options){ global $nxs_gCookiesArr; $ntCd = 'LI'; $ntCdL = 'li'; $ntNm = 'LinkedIn';
286
+ //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToLI', array($postID, $options));
287
+ $addParams = nxs_makeURLParams(array('NTNAME'=>$ntNm, 'NTCODE'=>$ntCd, 'POSTID'=>$postID, 'ACCNAME'=>$options['nName']));
288
+ $ii = $options['ii']; if (!isset($options['pType'])) $options['pType'] = 'im'; if ($options['pType']=='sh') sleep(rand(1, 10));
289
+ $logNT = '<span style="color:#000058">LinkedIn</span> - '.$options['nName'];
290
+ $snap_ap = get_post_meta($postID, 'snap'.$ntCd, true); $snap_ap = maybe_unserialize($snap_ap);
291
+ if ($options['pType']!='aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
292
+ $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted!='2') { sleep(5);
293
+ nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:'.$postID, 'Already posted. No reason for posting duplicate'.' |'.$uqID); return;
294
+ }
295
+ }
296
+
297
+ $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle=='') $blogTitle = home_url(); // prr($options);
298
+ if ($postID=='0') { echo "Testing ... <br/><br/>"; $msgT = 'Test Post from '.$blogTitle; $urlToGo = home_url(); $msg = 'Test Post from '.$blogTitle. " ".$urlToGo; $isAttachLI = ''; $title = $blogTitle; }
299
+ else { $post = get_post($postID); if(!$post) return; $liMsgFormat = $options['liMsgFormat']; $msg = nsFormatMessage($liMsgFormat, $postID, $addParams); $msgT = nsFormatMessage($options['liMsgFormatT'], $postID, $addParams);
300
+ //## MyURL - URLToGo code
301
+ if (!isset($options['urlToUse']) || trim($options['urlToUse'])=='') $myurl = trim(get_post_meta($postID, 'snap_MYURL', true)); if ($myurl!='') $options['urlToUse'] = $myurl;
302
+ if (isset($options['urlToUse']) && trim($options['urlToUse'])!='') { $urlToGo = $options['urlToUse']; $options['useFBGURLInfo'] = true; } else $urlToGo = get_permalink($postID);
303
+ if($addParams!='') $urlToGo .= (strpos($urlToGo,'?')!==false?'&':'?').$addParams;
304
+ $isAttachLI = $options['liAttch']; $title = nsTrnc($post->post_title, 200); nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted'=>'1'));
305
+ }
306
+ $extInfo = ' | PostID: '.$postID." - ".$post->post_title; $msgT = nsTrnc($msgT, 200);
307
+ if ($isAttachLI=='1') {
308
+ if (trim($options['liMsgAFrmt'])!='') {$dsc = nsFormatMessage($options['liMsgAFrmt'], $postID, $addParams);} else {
309
+ $src = nxs_getPostImage($postID); $dsc = trim(apply_filters('the_content', $post->post_excerpt)); if ($dsc=='') $dsc = apply_filters('the_content', $post->post_content);
310
+ } $dsc = strip_tags($dsc); $dsc = nxs_decodeEntitiesFull($dsc); $dsc = nxs_html_to_utf8($dsc); $dsc = nsTrnc($dsc, 300);
311
+ }
312
+ $msg = nxs_html_to_utf8($msg); $msgT = nxs_html_to_utf8($msgT);
313
+ if (function_exists("doConnectToLinkedIn") && $options['ulName']!='' && $options['uPass']!='') {
314
+ $auth = doConnectToLinkedIn($options['ulName'], $options['uPass'], $options['ii']); if ($auth!==false) die($auth);
315
+ $to = $options['uPage']!=''?$options['uPage']:'http://www.linkedin.com/home'; $lnk = array(); $msg = str_ireplace('&nbsp;',' ',$msg); $msg = nsTrnc(strip_tags($msg), 700);
316
+ if ($postID=='0') { $lnk['title'] = get_bloginfo('name'); $lnk['desc'] = get_bloginfo('description'); $lnk['url'] = home_url();
317
+ } else { if ($isAttachLI=='1') { $lnk['title'] = nsTrnc( strip_tags($post->post_title), 200); $lnk['postTitle'] = $msgT; $lnk['desc'] = $dsc; $lnk['url'] = $urlToGo; $lnk['img'] = $src; }} //prr($msg);
318
+ $ret = doPostToLinkedIn($msg, $lnk, $to); $liPostID = $options['uPage'];
319
+ } else { require_once ('apis/liOAuth.php'); $linkedin = new nsx_LinkedIn($options['liAPIKey'], $options['liAPISec']); $linkedin->oauth_verifier = $options['liOAuthVerifier'];
320
+ $linkedin->request_token = new nsx_trOAuthConsumer($options['liOAuthToken'], $options['liOAuthTokenSecret'], 1);
321
+ $linkedin->access_token = new nsx_trOAuthConsumer($options['liAccessToken'], $options['liAccessTokenSecret'], 1); $msg = nsTrnc($msg, 700);
322
+ if ($options['grpID']!=''){
323
+ try{
324
+ if($isAttachLI=='1') $ret = $linkedin->postToGroup($msg, $msgT, $options['grpID'], $urlToGo, $src, $dsc); else $ret = $linkedin->postToGroup($msg, $msgT, $options['grpID']);
325
+ $liPostID= 'http://www.linkedin.com/groups?gid='.$options['grpID'];
326
+ } catch (Exception $o){ nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '."Linkedin Status couldn't be updated! - ".print_r($o, true)); $ret="ERROR:".print_r($o, true); }
327
+ } else {
328
+ try{ if($isAttachLI=='1') $ret = $linkedin->postShare($msg, nsTrnc($post->post_title, 200), $urlToGo, $src, $dsc); else $ret = $linkedin->postShare($msg); }
329
+ catch (Exception $o){ nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '."<br/>Linkedin Status couldn't be updated! - ".print_r($o, true)); $ret="ERROR:".print_r($o, true); }
330
+ }
331
+ //$liPostID = $linkedin->getCurrentShare(); prr($liPostID);
332
+ if ($liPostID=='') $liPostID = $options['liUserInfo'];
333
+ }
334
+ if (stripos($ret, 'update-url')!==false) { $liPostID = CutFromTo($ret, '<update-url>','</update-url>'); $ret = '201'; }
335
+ if ($ret!='201') { if ($postID=='0') prr($ret); nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.print_r($ret, true), $extInfo); }
336
+ else if ($postID=='0') { echo 'OK - Linkedin status updated successfully'; nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); } else
337
+ { nxs_metaMarkAsPosted($postID, 'LI', $options['ii'], array('isPosted'=>'1', 'pgID'=>$liPostID, 'pDate'=>date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); }
338
+ if ($ret=='201') return true; else return 'Something Wrong';
339
+ }
340
+ }
341
+
342
  ?>
inc-cl/lj.php CHANGED
@@ -1,200 +1,201 @@
1
- <?php
2
- //## NextScripts Facebook Connection Class
3
- $nxs_snapAvNts[] = array('code'=>'LJ', 'lcode'=>'lj', 'name'=>'LiveJournal');
4
-
5
- if (!class_exists("nxs_snapClassLJ")) { class nxs_snapClassLJ {
6
- //#### Show Common Settings
7
- function showGenNTSettings($ntOpts){ global $nxs_plurl; $ntInfo = array('code'=>'LJ', 'lcode'=>'lj', 'name'=>'LiveJournal', 'defNName'=>'', 'tstReq' => false); ?>
8
- <div class="nxs_box">
9
- <div class="nxs_box_header">
10
- <div class="nsx_iconedTitle" style="margin-bottom:1px;background-image:url(<?php echo $nxs_plurl;?>img/<?php echo $ntInfo['lcode']; ?>16.png);"><?php echo $ntInfo['name']; ?>
11
- <?php $cbo = count($ntOpts); ?> <?php wp_nonce_field( 'ns'.$ntInfo['code'], 'ns'.$ntInfo['code'].'_wpnonce' ); ?>
12
- <?php if ($cbo>1){ ?><div class="nsBigText"><?php echo "(".($cbo=='0'?'No':$cbo)." "; _e('accounts', 'nxs_snap'); echo ")"; ?></div><?php } ?>
13
- </div>
14
- </div>
15
- <div class="nxs_box_inside">
16
- <?php foreach ($ntOpts as $indx=>$pbo){ if (trim($pbo['nName']=='')) $pbo['nName'] = str_ireplace('/xmlrpc.php','', str_ireplace('http://','', str_ireplace('https://','', $pbo['ljURL']))); ?>
17
- <p style="margin:0px;margin-left:5px;">
18
- <input value="1" name="<?php echo $ntInfo['lcode']; ?>[<?php echo $indx; ?>][apDo<?php echo $ntInfo['code']; ?>]" onchange="doShowHideBlocks('<?php echo $ntInfo['code']; ?>');" type="checkbox" <?php if ((int)$pbo['do'.$ntInfo['code']] == 1) echo "checked"; ?> /> <?php if ((int)$pbo['catSel'] == 1) { ?> <span onmouseout="nxs_hidePopUpInfo('popOnlyCat');" onmouseover="nxs_showPopUpInfo('popOnlyCat', event);"><?php echo "*[".(substr_count($pbo['catSelEd'], ",")+1)."]*" ?></span><?php } ?>
19
- <strong><?php _e('Auto-publish to', 'nxs_snap'); ?> <?php echo $ntInfo['name']; ?> <i style="color: #005800;"><?php if($pbo['nName']!='') echo "(".$pbo['nName'].")"; ?></i></strong>
20
- &nbsp;&nbsp;<?php if ($ntInfo['tstReq'] && (!isset($pbo[$ntInfo['lcode'].'OK']) || $pbo[$ntInfo['lcode'].'OK']=='')){ ?><b style="color: #800000"><?php _e('Attention requred. Unfinished setup', 'nxs_snap'); ?> ==&gt;</b><?php } ?><a id="do<?php echo $ntInfo['code'].$indx; ?>A" href="#" onclick="doShowHideBlocks2('<?php echo $ntInfo['code'].$indx; ?>');return false;">[<?php _e('Show Settings', 'nxs_snap'); ?>]</a>&nbsp;&nbsp;
21
- <a href="#" onclick="doDelAcct('<?php echo $ntInfo['lcode']; ?>', '<?php echo $indx; ?>', '<?php if (isset($pbo['bgBlogID'])) echo $pbo['nName']; ?>');return false;">[<?php _e('Remove Account', 'nxs_snap'); ?>]</a>
22
- </p><?php $this->showNTSettings($indx, $pbo);
23
- }?>
24
- </div>
25
- </div> <?php
26
- }
27
- //#### Show NEW Settings Page
28
- function showNewNTSettings($mgpo){ $gpo = array('nName'=>'', 'doLJ'=>'1', 'ljUName'=>'', 'ljPageID'=>'', 'inclTags'=>'1', 'ljAttch'=>'', 'ljPass'=>'', 'ljURL'=>''); $this->showNTSettings($mgpo, $gpo, true);}
29
- //#### Show Unit Settings
30
- function showNTSettings($ii, $gpo, $isNew=false){ global $nxs_plurl; ?>
31
- <div id="doLJ<?php echo $ii; ?>Div" class="insOneDiv<?php if ($isNew) echo " clNewNTSets"; ?>" style="background-image: url(<?php echo $nxs_plurl; ?>img/lj-bg.png); background-position:90% 10%;"> <input type="hidden" name="apDoSLJ<?php echo $ii; ?>" value="0" id="apDoSLJ<?php echo $ii; ?>" />
32
-
33
- <div class="nsx_iconedTitle" style="float: right; background-image: url(<?php echo $nxs_plurl; ?>img/lj16.png);"><a style="font-size: 12px;" target="_blank" href="http://www.nextscripts.com/setup-installation-livejournal-social-networks-auto-poster-for-wordpress/"><?php $nType="LiveJournal"; printf( __( 'Detailed %s Installation/Configuration Instructions', 'nxs_snap' ), $nType); ?></a></div>
34
- <?php if ($isNew){ ?> <br/><?php _e('You can setup LiveJournal blog.', 'nxs_snap'); ?><br/><br/> <?php } ?>
35
-
36
- <div style="width:100%;"><strong><?php _e('Account Nickname', 'nxs_snap'); ?>:</strong> <i><?php _e('Just so you can easely identify it', 'nxs_snap'); ?></i> </div><input name="lj[<?php echo $ii; ?>][nName]" id="ljnName<?php echo $ii; ?>" style="font-weight: bold; color: #005800; border: 1px solid #ACACAC; width: 40%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($gpo['nName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /><br/>
37
- <?php echo nxs_addQTranslSel('lj', $ii, $gpo['qTLng']); ?><?php echo nxs_addPostingDelaySel('lj', $ii, $gpo['nHrs'], $gpo['nMin']); ?>
38
-
39
- <?php if (!$isNew) { ?>
40
- <div style="width:100%;"><strong><?php _e('Categories', 'nxs_snap'); ?>:</strong>
41
- <input value="0" id="catSelA<?php echo $ii; ?>" type="radio" name="lj[<?php echo $ii; ?>][catSel]" <?php if ((int)$gpo['catSel'] != 1) echo "checked"; ?> /> All
42
- <input value="1" id="catSelSLJ<?php echo $ii; ?>" type="radio" name="lj[<?php echo $ii; ?>][catSel]" <?php if ((int)$gpo['catSel'] == 1) echo "checked"; ?> /> <a href="#" style="text-decoration: none;" class="showCats" id="nxs_SCA_LJ<?php echo $ii; ?>" onclick="jQuery('#catSelSLJ<?php echo $ii; ?>').attr('checked', true); jQuery('#tmpCatSelNT').val('LJ<?php echo $ii; ?>'); nxs_markCats( jQuery('#nxs_SC_LJ<?php echo $ii; ?>').val() ); jQuery('#showCatSel').bPopup({ modalClose: false, appendTo: '#nsStForm', opacity: 0.6, follow: [false, false], position: [75, 'auto']}); return false;">Selected<?php if ($gpo['catSelEd']!='') echo "[".(substr_count($gpo['catSelEd'], ",")+1)."]"; ?></a>
43
- <input type="hidden" name="lj[<?php echo $ii; ?>][catSelEd]" id="nxs_SC_LJ<?php echo $ii; ?>" value="<?php echo $gpo['catSelEd']; ?>" />
44
- <br/><i><?php _e('Only selected categories will be autoposted to this account', 'nxs_snap'); ?></i></div>
45
- <?php } ?>
46
- <div style="width:100%;"><br/><strong>LiveJournal Username:</strong> </div><input name="lj[<?php echo $ii; ?>][apLJUName]" id="apLJUName" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($gpo['ljUName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
47
- <div style="width:100%;"><strong>LiveJournal Password:</strong> </div><input name="lj[<?php echo $ii; ?>][apLJPass]" id="apLJPass" type="password" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities(substr($gpo['ljPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($gpo['ljPass'], 5)):$gpo['ljPass'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /> <br/>
48
-
49
- <div style="width:100%;"><br/><strong>Blog/Community URL or ID:</strong> Please specify the Blog or Community URL or ID. <i>Use this only if you are posting NOT to your own journal. </i></div>
50
- <input name="lj[<?php echo $ii; ?>][commID]" id="commID" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($gpo['commID'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
51
-
52
- <div style="width:100%;"><br/><strong>Website:</strong> Please select your website. <i>SNAP could also post to other LJ Engine Based sites like DreamWidth.org </i></div>
53
-
54
- <select id="lj1delayHrs" name="lj[<?php echo $ii; ?>][ljSrv]"><option <?php if ( !isset($gpo['ljSrv']) || $gpo['ljSrv']=='' || $gpo['ljSrv']=='LJ') {?> selected="selected" <?php } ?> value="LJ">LiveJournal.com</option>
55
- <option <?php if ( isset($gpo['ljSrv']) && $gpo['ljSrv']=='DW') {?> selected="selected" <?php } ?> value="DW">DreamWidth.org</option>
56
- </select>
57
-
58
- <br/>
59
-
60
- <?php if ($isNew) { ?> <input type="hidden" name="lj[<?php echo $ii; ?>][apDoLJ]" value="1" id="apDoNewLJ<?php echo $ii; ?>" /> <?php } ?>
61
-
62
- <br/><strong id="altFormatText"><?php _e('Post Title and Post Text Formats', 'nxs_snap'); ?></strong>
63
- <div id="altFormat" style="">
64
- <div style="width:100%;"><strong id="altFormatText"><?php _e('Post Title Format', 'nxs_snap'); ?></strong> (<a href="#" id="apLJMsgTFrmt<?php echo $ii; ?>HintInfo" onclick="mxs_showHideFrmtInfo('apLJMsgTFrmt<?php echo $ii; ?>'); return false;"><?php _e('Show format info', 'nxs_snap'); ?></a>)
65
- </div><input name="lj[<?php echo $ii; ?>][apLJMsgTFrmt]" id="apLJMsgTFrmt<?php echo $ii; ?>" style="width: 50%;" value="<?php if ($isNew) echo "%TITLE%"; else _e(apply_filters('format_to_edit', htmlentities($gpo['ljMsgTFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap'); ?>" onfocus="mxs_showFrmtInfo('apLJMsgTFrmt<?php echo $ii; ?>');" /><?php nxs_doShowHint("apLJMsgTFrmt".$ii); ?>
66
- </div>
67
- <div id="altFormat" style="">
68
- <div style="width:100%;"><strong id="altFormatText"><?php _e('Post Text Format', 'nxs_snap'); ?></strong> (<a href="#" id="apLJMsgFrmt<?php echo $ii; ?>HintInfo" onclick="mxs_showHideFrmtInfo('apLJMsgFrmt<?php echo $ii; ?>'); return false;"><?php _e('Show format info', 'nxs_snap'); ?></a>)
69
- </div>
70
-
71
- <textarea cols="150" rows="3" id="lj<?php echo $ii; ?>SNAPformat" name="lj[<?php echo $ii; ?>][apLJMsgFrmt]" style="width:51%;max-width: 650px;" onfocus="jQuery('#lj<?php echo $ii; ?>SNAPformat').attr('rows', 6); mxs_showFrmtInfo('apLJMsgFrmt<?php echo $ii; ?>');"><?php if ($isNew) echo "%FULLTEXT%"; else _e(apply_filters('format_to_edit', htmlentities($gpo['ljMsgFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap'); ?></textarea>
72
-
73
- <?php nxs_doShowHint("apLJMsgFrmt".$ii); ?>
74
- </div>
75
- <p style="margin-bottom: 20px;margin-top: 5px;"><input value="1" id="ljInclTags<?php echo $ii; ?>" type="checkbox" name="lj[<?php echo $ii; ?>][inclTags]" <?php if ((int)$gpo['inclTags'] == 1) echo "checked"; ?> />
76
- <strong><?php _e('Post with tags.', 'nxs_snap') ?></strong> <?php _e('Tags from the blogpost will be auto posted to LiveJournal', 'nxs_snap') ?>
77
- </p><br/>
78
- <?php if ($gpo['ljPass']!='') { ?>
79
- <?php wp_nonce_field( 'rePostToLJ', 'rePostToLJ_wpnonce' ); ?>
80
- <b><?php _e('Test your settings', 'nxs_snap'); ?>:</b>&nbsp;&nbsp;&nbsp; <a href="#" class="NXSButton" onclick="testPost('LJ', '<?php echo $ii; ?>'); return false;"><?php printf( __( 'Submit Test Post to %s', 'nxs_snap' ), $nType); ?></a> <?php } ?>
81
- <div class="submit"><input type="submit" class="button-primary" name="update_NS_SNAutoPoster_settings" value="<?php _e('Update Settings', 'nxs_snap') ?>" /></div></div><?php
82
- }
83
- //#### Set Unit Settings from POST
84
- function setNTSettings($post, $options){ global $nxs_snapThisPageUrl; $code = 'LJ'; $lcode = 'lj';
85
- foreach ($post as $ii => $pval){
86
- if (isset($pval['apLJUName']) && $pval['apLJUName']!=''){ if (!isset($options[$ii])) $options[$ii] = array();
87
- if (isset($pval['nName'])) $options[$ii]['nName'] = trim($pval['nName']);
88
- if (isset($pval['ljSrv'])) $options[$ii]['ljSrv'] = trim($pval['ljSrv']); if ($options[$ii]['ljSrv']=='DW') $server = 'dreamwidth.org'; else $server = 'livejournal.com';
89
- if (isset($pval['apLJUName'])) $options[$ii]['ljUName'] = trim($pval['apLJUName']); $options[$ii]['ljURL'] = 'http://'.$options[$ii]['ljUName'].$server;
90
- if (isset($pval['apLJPass'])) $options[$ii]['ljPass'] = 'n5g9a'.nsx_doEncode($pval['apLJPass']); else $options[$ii]['ljPass'] = '';
91
- if (isset($pval['apLJMsgFrmt'])) $options[$ii]['ljMsgFormat'] = trim($pval['apLJMsgFrmt']);
92
- if (isset($pval['apLJMsgTFrmt'])) $options[$ii]['ljMsgTFormat'] = trim($pval['apLJMsgTFrmt']);
93
- if (isset($pval['catSel'])) $options[$ii]['catSel'] = trim($pval['catSel']);
94
- if (isset($pval['inclTags'])) $options[$ii]['inclTags'] = $pval['inclTags']; else $options[$ii]['inclTags'] = 0;
95
-
96
- if ($options[$ii]['catSel']=='1' && trim($pval['catSelEd'])!='') $options[$ii]['catSelEd'] = trim($pval['catSelEd']); else $options[$ii]['catSelEd'] = '';
97
-
98
- if (isset($pval['commID'])) {
99
- if (stripos($pval['commID'], '.')!==false) $pval['commID'] = CutFromTo($pval['commID'], '://', '.');
100
- $options[$ii]['commID'] = trim($pval['commID']);
101
- }
102
- if (isset($pval['apDoLJ'])) $options[$ii]['doLJ'] = $pval['apDoLJ']; else $options[$ii]['doLJ'] = 0;
103
- if (isset($pval['delayHrs'])) $options[$ii]['nHrs'] = trim($pval['delayHrs']); if (isset($pval['delayMin'])) $options[$ii]['nMin'] = trim($pval['delayMin']);
104
- if (isset($pval['qTLng'])) $options[$ii]['qTLng'] = trim($pval['qTLng']);
105
- }
106
- } return $options;
107
- }
108
- //#### Show Post->Edit Meta Box Settings
109
- function showEdPostNTSettings($ntOpts, $post){ global $nxs_plurl; $post_id = $post->ID;
110
- foreach($ntOpts as $ii=>$ntOpt) { $pMeta = maybe_unserialize(get_post_meta($post_id, 'snapLJ', true)); if (is_array($pMeta)) $ntOpt = $this->adjMetaOpt($ntOpt, $pMeta[$ii]);
111
- $doLJ = $ntOpt['doLJ'] && (is_array($pMeta) || $ntOpt['catSel']!='1');
112
- $isAvailLJ = $ntOpt['ljUName']!='' && $ntOpt['ljPass']!=''; $ljMsgFormat = htmlentities($ntOpt['ljMsgFormat'], ENT_COMPAT, "UTF-8"); $ljMsgTFormat = htmlentities($ntOpt['ljMsgTFormat'], ENT_COMPAT, "UTF-8");
113
- ?>
114
- <tr><th style="text-align:left;" colspan="2"><?php if ( $ntOpt['catSel']=='1' && trim($ntOpt['catSelEd'])!='' ) { ?> <input type="hidden" class="nxs_SC" id="nxs_SC_LJ<?php echo $ii; ?>" value="<?php echo $ntOpt['catSelEd']; ?>" /> <?php } ?>
115
- <?php if ($isAvailLJ) { ?><input class="nxsGrpDoChb" value="1" id="doLJ<?php echo $ii; ?>" <?php if ($post->post_status == "publish") echo 'disabled="disabled"';?> type="checkbox" name="lj[<?php echo $ii; ?>][doLJ]" <?php if ((int)$doLJ == 1) echo 'checked="checked" title="def"'; ?> />
116
- <?php if ($post->post_status == "publish") { ?> <input type="hidden" name="lj[<?php echo $ii; ?>][doLJ]" value="<?php echo $doLJ;?>"> <?php } ?> <?php } ?>
117
- <div class="nsx_iconedTitle" style="display: inline; font-size: 13px; background-image: url(<?php echo $nxs_plurl; ?>img/lj16.png);">LiveJournal - <?php _e('publish to', 'nxs_snap') ?> (<i style="color: #005800;"><?php echo $ntOpt['nName']; ?></i>)</div></th> <td><?php //## Only show RePost button if the post is "published"
118
- if ($post->post_status == "publish" && $isAvailLJ) { ?><input alt="<?php echo $ii; ?>" style="float: right;" onmouseout="hidePopShAtt('SV');" onmouseover="shoLJopShAtt('SV', event);" onclick="return false;" type="button" class="button" name="rePostToLJ_repostButton" id="rePostToLJ_button" value="<?php _e('Repost to LiveJournal', 'nxs_snap') ?>" />
119
- <?php wp_nonce_field( 'rePostToLJ', 'rePostToLJ_wpnonce' ); } ?>
120
-
121
- <?php if (is_array($pMeta) && is_array($pMeta[$ii]) && isset($pMeta[$ii]['pgID']) ) {
122
- ?> <span id="pstdLJ<?php echo $ii; ?>" style="float: right;padding-top: 4px; padding-right: 10px;">
123
- <a style="font-size: 10px;" href="<?php echo $pMeta[$ii]['pgID']; ?>" target="_blank"><?php $nType="LiveJournal"; printf( __( 'Posted on', 'nxs_snap' ), $nType); ?> <?php echo (isset($pMeta[$ii]['pDate']) && $pMeta[$ii]['pDate']!='')?(" (".$pMeta[$ii]['pDate'].")"):""; ?></a>
124
- </span><?php } ?>
125
-
126
- </td></tr>
127
-
128
- <?php if (!$isAvailLJ) { ?><tr><th scope="row" style="text-align:right; width:150px; padding-top: 5px; padding-right:10px;"></th> <td><b>Setup your LiveJournal Account to AutoPost to LiveJournal</b>
129
- <?php } elseif ($post->post_status != "puZblish") { ?>
130
-
131
- <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top: 6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Title Format:', 'nxs_snap') ?></th>
132
- <td><input value="<?php echo $ljMsgTFormat ?>" type="text" name="lj[<?php echo $ii; ?>][SNAPformatT]" style="width:60%;max-width: 610px;" onfocus="jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apLJTMsgFrmt<?php echo $ii; ?>');"/><?php nxs_doShowHint("apLJTMsgFrmt".$ii); ?></td></tr>
133
-
134
- <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top: 6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Text Format:', 'nxs_snap') ?></th>
135
- <td>
136
- <textarea cols="150" rows="1" id="lj<?php echo $ii; ?>SNAPformat" name="lj[<?php echo $ii; ?>][SNAPformat]" style="width:60%;max-width: 610px;" onfocus="jQuery('#lj<?php echo $ii; ?>SNAPformat').attr('rows', 4); jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apLJMsgFrmt<?php echo $ii; ?>');"><?php echo $ljMsgFormat; ?></textarea>
137
- <?php nxs_doShowHint("apLJMsgFrmt".$ii); ?></td></tr>
138
-
139
- <?php }
140
- }
141
- }
142
- //#### Save Meta Tags to the Post
143
- function adjMetaOpt($optMt, $pMeta){ if (isset($pMeta['isPosted'])) $optMt['isPosted'] = $pMeta['isPosted']; else $optMt['isPosted'] = '';
144
- if (isset($pMeta['SNAPformat'])) $optMt['ljMsgFormat'] = $pMeta['SNAPformat'];
145
- if (isset($pMeta['SNAPformatT'])) $optMt['ljMsgTFormat'] = $pMeta['SNAPformatT'];
146
- if (isset($pMeta['doLJ'])) $optMt['doLJ'] = $pMeta['doLJ'] == 1?1:0; else { if (isset($pMeta['SNAPformat'])) $optMt['doLJ'] = 0; }
147
- if (isset($pMeta['SNAPincludeLJ']) && $pMeta['SNAPincludeLJ'] == '1' ) $optMt['doLJ'] = 1;
148
- return $optMt;
149
- }
150
- }}
151
- if (!function_exists("nxs_rePostToLJ_ajax")) {
152
- function nxs_rePostToLJ_ajax() { check_ajax_referer('rePostToLJ'); $postID = $_POST['id']; $options = get_option('NS_SNAutoPoster');
153
- foreach ($options['lj'] as $ii=>$two) if ($ii==$_POST['nid']) { $two['ii'] = $ii; $two['pType'] = 'aj';//if ($two['gpPageID'].$two['gpUName']==$_POST['nid']) {
154
- $gppo = get_post_meta($postID, 'snapLJ', true); $gppo = maybe_unserialize($gppo);// prr($gppo);
155
- if (is_array($gppo) && isset($gppo[$ii]) && is_array($gppo[$ii])){ $ntClInst = new nxs_snapClassLJ(); $two = $ntClInst->adjMetaOpt($two, $gppo[$ii]); }
156
- $result = nxs_doPublishToLJ($postID, $two); if ($result == 200) die("Successfully sent your post to LiveJournal."); else die($result);
157
- }
158
- }
159
- }
160
-
161
- if (!function_exists("nxs_doPublishToLJ")) { //## Second Function to Post to LJ
162
- function nxs_doPublishToLJ($postID, $options){ $ntCd = 'LJ'; $ntCdL = 'lj'; $ntNm = 'LJ Based Blog';
163
- //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToLJ', array($postID, $options));
164
- $ii = $options['ii']; if (!isset($options['pType'])) $options['pType'] = 'im'; if ($options['pType']=='sh') sleep(rand(1, 10));
165
- $logNT = '<span style="color:#2097EE">LJ</span> - '.$options['nName'];
166
- $snap_ap = get_post_meta($postID, 'snap'.$ntCd, true); $snap_ap = maybe_unserialize($snap_ap);
167
- if ($options['pType']!='aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
168
- $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted!='2') {
169
- nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:'.$postID, 'Already posted. No reason for posting duplicate'.' |'.$uqID); return;
170
- }
171
- }
172
- $imgURL = nxs_getPostImage($postID);
173
- $email = $options['ljUName']; $pass = substr($options['ljPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($options['ljPass'], 5)):$options['ljPass'];
174
- if ($postID=='0') { echo "Testing ... <br/><br/>"; $link = home_url(); $msgT = 'Test Link from '.$link; $msg = 'Test post please ignore'; } else { $post = get_post($postID); if(!$post) return; $link = get_permalink($postID);
175
- $msgFormat = $options['ljMsgFormat']; $msg = nsFormatMessage($msgFormat, $postID); $msgTFormat = $options['ljMsgTFormat']; $msgT = nsFormatMessage($msgTFormat, $postID);
176
- nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted'=>'1'));
177
- } //prr($msg); prr($msgFormat);
178
- $extInfo = ' | PostID: '.$postID." - ".$post->post_title;
179
- //## Post
180
- require_once ('apis/xmlrpc-client.php'); if ($options['ljSrv']=='DW') $server = 'dreamwidth.org'; else $server = 'livejournal.com';
181
- $nxsToLJclient = new NXS_XMLRPC_Client('http://www.'.$server.'/interface/xmlrpc'); $nxsToLJclient->debug = false;
182
-
183
- $date = time(); $year = date("Y", $date); $mon = date("m", $date); $day = date("d", $date); $hour = date("G", $date); $min = date("i", $date);
184
- $nxsToLJContent = array( "username" => $options['ljUName'], "password" => $pass, "event" => $msg, "subject" => $msgT, "lineendings" => "unix", "year" => $year, "mon" => $mon, "day" => $day, "hour" => $hour, "min" => $min, "ver" => 2);
185
- if ($options['commID']!='') $nxsToLJContent["usejournal"] = $options['commID'];
186
-
187
- if ($options['inclTags']=='1'){ $t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) {$tggs[] = $tagA->name;} $tags = implode(',', $tggs); $nxsToLJContent['props'] = array('taglist' => $tags); }
188
-
189
-
190
- if (!$nxsToLJclient->query('LJ.XMLRPC.postevent', $nxsToLJContent)) { $ret = 'Something went wrong - '.$nxsToLJclient->getErrorCode().' : '.$nxsToLJclient->getErrorMessage();} else $ret = 'OK';
191
- $pid = $nxsToLJclient->getResponse(); if (is_array($pid)) $pid = $pid['url']; else { $ret = 'Something went wrong - NO PID '.print_r($pid, true);}
192
-
193
- if ($ret!='OK') { if ($postID=='0') echo $ret;
194
- nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.print_r($ret, true), $extInfo);
195
- } else { if ($postID=='0') { echo 'OK - Message Posted, please see your LiveJournal'; nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); } else
196
- { nxs_metaMarkAsPosted($postID, 'LJ', $options['ii'], array('isPosted'=>'1', 'pgID'=>$pid, 'pDate'=>date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo);} }
197
- if ($ret == 'OK') return 200; else return $ret;
198
- }
199
- }
 
200
  ?>
1
+ <?php
2
+ //## NextScripts Facebook Connection Class
3
+ $nxs_snapAvNts[] = array('code'=>'LJ', 'lcode'=>'lj', 'name'=>'LiveJournal');
4
+
5
+ if (!class_exists("nxs_snapClassLJ")) { class nxs_snapClassLJ {
6
+ //#### Show Common Settings
7
+ function showGenNTSettings($ntOpts){ global $nxs_plurl; $ntInfo = array('code'=>'LJ', 'lcode'=>'lj', 'name'=>'LiveJournal', 'defNName'=>'', 'tstReq' => false); ?>
8
+ <div class="nxs_box">
9
+ <div class="nxs_box_header">
10
+ <div class="nsx_iconedTitle" style="margin-bottom:1px;background-image:url(<?php echo $nxs_plurl;?>img/<?php echo $ntInfo['lcode']; ?>16.png);"><?php echo $ntInfo['name']; ?>
11
+ <?php $cbo = count($ntOpts); ?> <?php wp_nonce_field( 'ns'.$ntInfo['code'], 'ns'.$ntInfo['code'].'_wpnonce' ); ?>
12
+ <?php if ($cbo>1){ ?><div class="nsBigText"><?php echo "(".($cbo=='0'?'No':$cbo)." "; _e('accounts', 'nxs_snap'); echo ")"; ?></div><?php } ?>
13
+ </div>
14
+ </div>
15
+ <div class="nxs_box_inside">
16
+ <?php foreach ($ntOpts as $indx=>$pbo){ if (trim($pbo['nName']=='')) $pbo['nName'] = str_ireplace('/xmlrpc.php','', str_ireplace('http://','', str_ireplace('https://','', $pbo['ljURL']))); ?>
17
+ <p style="margin:0px;margin-left:5px;">
18
+ <input value="1" name="<?php echo $ntInfo['lcode']; ?>[<?php echo $indx; ?>][apDo<?php echo $ntInfo['code']; ?>]" onchange="doShowHideBlocks('<?php echo $ntInfo['code']; ?>');" type="checkbox" <?php if ((int)$pbo['do'.$ntInfo['code']] == 1) echo "checked"; ?> /> <?php if ((int)$pbo['catSel'] == 1) { ?> <span onmouseout="nxs_hidePopUpInfo('popOnlyCat');" onmouseover="nxs_showPopUpInfo('popOnlyCat', event);"><?php echo "*[".(substr_count($pbo['catSelEd'], ",")+1)."]*" ?></span><?php } ?>
19
+ <strong><?php _e('Auto-publish to', 'nxs_snap'); ?> <?php echo $ntInfo['name']; ?> <i style="color: #005800;"><?php if($pbo['nName']!='') echo "(".$pbo['nName'].")"; ?></i></strong>
20
+ &nbsp;&nbsp;<?php if ($ntInfo['tstReq'] && (!isset($pbo[$ntInfo['lcode'].'OK']) || $pbo[$ntInfo['lcode'].'OK']=='')){ ?><b style="color: #800000"><?php _e('Attention requred. Unfinished setup', 'nxs_snap'); ?> ==&gt;</b><?php } ?><a id="do<?php echo $ntInfo['code'].$indx; ?>A" href="#" onclick="doShowHideBlocks2('<?php echo $ntInfo['code'].$indx; ?>');return false;">[<?php _e('Show Settings', 'nxs_snap'); ?>]</a>&nbsp;&nbsp;
21
+ <a href="#" onclick="doDelAcct('<?php echo $ntInfo['lcode']; ?>', '<?php echo $indx; ?>', '<?php if (isset($pbo['bgBlogID'])) echo $pbo['nName']; ?>');return false;">[<?php _e('Remove Account', 'nxs_snap'); ?>]</a>
22
+ </p><?php $this->showNTSettings($indx, $pbo);
23
+ }?>
24
+ </div>
25
+ </div> <?php
26
+ }
27
+ //#### Show NEW Settings Page
28
+ function showNewNTSettings($mgpo){ $gpo = array('nName'=>'', 'doLJ'=>'1', 'ljUName'=>'', 'ljPageID'=>'', 'inclTags'=>'1', 'ljAttch'=>'', 'ljPass'=>'', 'ljURL'=>''); $this->showNTSettings($mgpo, $gpo, true);}
29
+ //#### Show Unit Settings
30
+ function showNTSettings($ii, $gpo, $isNew=false){ global $nxs_plurl; ?>
31
+ <div id="doLJ<?php echo $ii; ?>Div" class="insOneDiv<?php if ($isNew) echo " clNewNTSets"; ?>" style="background-image: url(<?php echo $nxs_plurl; ?>img/lj-bg.png); background-position:90% 10%;"> <input type="hidden" name="apDoSLJ<?php echo $ii; ?>" value="0" id="apDoSLJ<?php echo $ii; ?>" />
32
+
33
+ <div class="nsx_iconedTitle" style="float: right; background-image: url(<?php echo $nxs_plurl; ?>img/lj16.png);"><a style="font-size: 12px;" target="_blank" href="http://www.nextscripts.com/setup-installation-livejournal-social-networks-auto-poster-for-wordpress/"><?php $nType="LiveJournal"; printf( __( 'Detailed %s Installation/Configuration Instructions', 'nxs_snap' ), $nType); ?></a></div>
34
+ <?php if ($isNew){ ?> <br/><?php _e('You can setup LiveJournal blog.', 'nxs_snap'); ?><br/><br/> <?php } ?>
35
+
36
+ <div style="width:100%;"><strong><?php _e('Account Nickname', 'nxs_snap'); ?>:</strong> <i><?php _e('Just so you can easely identify it', 'nxs_snap'); ?></i> </div><input name="lj[<?php echo $ii; ?>][nName]" id="ljnName<?php echo $ii; ?>" style="font-weight: bold; color: #005800; border: 1px solid #ACACAC; width: 40%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($gpo['nName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /><br/>
37
+ <?php echo nxs_addQTranslSel('lj', $ii, $gpo['qTLng']); ?><?php echo nxs_addPostingDelaySel('lj', $ii, $gpo['nHrs'], $gpo['nMin']); ?>
38
+
39
+ <?php if (!$isNew) { ?>
40
+ <div style="width:100%;"><strong><?php _e('Categories', 'nxs_snap'); ?>:</strong>
41
+ <input value="0" id="catSelA<?php echo $ii; ?>" type="radio" name="lj[<?php echo $ii; ?>][catSel]" <?php if ((int)$gpo['catSel'] != 1) echo "checked"; ?> /> All
42
+ <input value="1" id="catSelSLJ<?php echo $ii; ?>" type="radio" name="lj[<?php echo $ii; ?>][catSel]" <?php if ((int)$gpo['catSel'] == 1) echo "checked"; ?> /> <a href="#" style="text-decoration: none;" class="showCats" id="nxs_SCA_LJ<?php echo $ii; ?>" onclick="jQuery('#catSelSLJ<?php echo $ii; ?>').attr('checked', true); jQuery('#tmpCatSelNT').val('LJ<?php echo $ii; ?>'); nxs_markCats( jQuery('#nxs_SC_LJ<?php echo $ii; ?>').val() ); jQuery('#showCatSel').bPopup({ modalClose: false, appendTo: '#nsStForm', opacity: 0.6, follow: [false, false], position: [75, 'auto']}); return false;">Selected<?php if ($gpo['catSelEd']!='') echo "[".(substr_count($gpo['catSelEd'], ",")+1)."]"; ?></a>
43
+ <input type="hidden" name="lj[<?php echo $ii; ?>][catSelEd]" id="nxs_SC_LJ<?php echo $ii; ?>" value="<?php echo $gpo['catSelEd']; ?>" />
44
+ <br/><i><?php _e('Only selected categories will be autoposted to this account', 'nxs_snap'); ?></i></div>
45
+ <?php } ?>
46
+ <div style="width:100%;"><br/><strong>LiveJournal Username:</strong> </div><input name="lj[<?php echo $ii; ?>][apLJUName]" id="apLJUName" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($gpo['ljUName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
47
+ <div style="width:100%;"><strong>LiveJournal Password:</strong> </div><input name="lj[<?php echo $ii; ?>][apLJPass]" id="apLJPass" type="password" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities(substr($gpo['ljPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($gpo['ljPass'], 5)):$gpo['ljPass'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /> <br/>
48
+
49
+ <div style="width:100%;"><br/><strong>Blog/Community URL or ID:</strong> Please specify the Blog or Community URL or ID. <i>Use this only if you are posting NOT to your own journal. </i></div>
50
+ <input name="lj[<?php echo $ii; ?>][commID]" id="commID" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($gpo['commID'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
51
+
52
+ <div style="width:100%;"><br/><strong>Website:</strong> Please select your website. <i>SNAP could also post to other LJ Engine Based sites like DreamWidth.org </i></div>
53
+
54
+ <select id="lj1delayHrs" name="lj[<?php echo $ii; ?>][ljSrv]"><option <?php if ( !isset($gpo['ljSrv']) || $gpo['ljSrv']=='' || $gpo['ljSrv']=='LJ') {?> selected="selected" <?php } ?> value="LJ">LiveJournal.com</option>
55
+ <option <?php if ( isset($gpo['ljSrv']) && $gpo['ljSrv']=='DW') {?> selected="selected" <?php } ?> value="DW">DreamWidth.org</option>
56
+ </select>
57
+
58
+ <br/>
59
+
60
+ <?php if ($isNew) { ?> <input type="hidden" name="lj[<?php echo $ii; ?>][apDoLJ]" value="1" id="apDoNewLJ<?php echo $ii; ?>" /> <?php } ?>
61
+
62
+ <br/><strong id="altFormatText"><?php _e('Post Title and Post Text Formats', 'nxs_snap'); ?></strong>
63
+ <div id="altFormat" style="">
64
+ <div style="width:100%;"><strong id="altFormatText"><?php _e('Post Title Format', 'nxs_snap'); ?></strong> (<a href="#" id="apLJMsgTFrmt<?php echo $ii; ?>HintInfo" onclick="mxs_showHideFrmtInfo('apLJMsgTFrmt<?php echo $ii; ?>'); return false;"><?php _e('Show format info', 'nxs_snap'); ?></a>)
65
+ </div><input name="lj[<?php echo $ii; ?>][apLJMsgTFrmt]" id="apLJMsgTFrmt<?php echo $ii; ?>" style="width: 50%;" value="<?php if ($isNew) echo "%TITLE%"; else _e(apply_filters('format_to_edit', htmlentities($gpo['ljMsgTFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap'); ?>" onfocus="mxs_showFrmtInfo('apLJMsgTFrmt<?php echo $ii; ?>');" /><?php nxs_doShowHint("apLJMsgTFrmt".$ii); ?>
66
+ </div>
67
+ <div id="altFormat" style="">
68
+ <div style="width:100%;"><strong id="altFormatText"><?php _e('Post Text Format', 'nxs_snap'); ?></strong> (<a href="#" id="apLJMsgFrmt<?php echo $ii; ?>HintInfo" onclick="mxs_showHideFrmtInfo('apLJMsgFrmt<?php echo $ii; ?>'); return false;"><?php _e('Show format info', 'nxs_snap'); ?></a>)
69
+ </div>
70
+
71
+ <textarea cols="150" rows="3" id="lj<?php echo $ii; ?>SNAPformat" name="lj[<?php echo $ii; ?>][apLJMsgFrmt]" style="width:51%;max-width: 650px;" onfocus="jQuery('#lj<?php echo $ii; ?>SNAPformat').attr('rows', 6); mxs_showFrmtInfo('apLJMsgFrmt<?php echo $ii; ?>');"><?php if ($isNew) echo "%FULLTEXT%"; else _e(apply_filters('format_to_edit', htmlentities($gpo['ljMsgFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap'); ?></textarea>
72
+
73
+ <?php nxs_doShowHint("apLJMsgFrmt".$ii); ?>
74
+ </div>
75
+ <p style="margin-bottom: 20px;margin-top: 5px;"><input value="1" id="ljInclTags<?php echo $ii; ?>" type="checkbox" name="lj[<?php echo $ii; ?>][inclTags]" <?php if ((int)$gpo['inclTags'] == 1) echo "checked"; ?> />
76
+ <strong><?php _e('Post with tags.', 'nxs_snap') ?></strong> <?php _e('Tags from the blogpost will be auto posted to LiveJournal', 'nxs_snap') ?>
77
+ </p><br/>
78
+ <?php if ($gpo['ljPass']!='') { ?>
79
+ <?php wp_nonce_field( 'rePostToLJ', 'rePostToLJ_wpnonce' ); ?>
80
+ <b><?php _e('Test your settings', 'nxs_snap'); ?>:</b>&nbsp;&nbsp;&nbsp; <a href="#" class="NXSButton" onclick="testPost('LJ', '<?php echo $ii; ?>'); return false;"><?php printf( __( 'Submit Test Post to %s', 'nxs_snap' ), $nType); ?></a> <?php } ?>
81
+ <div class="submit"><input type="submit" class="button-primary" name="update_NS_SNAutoPoster_settings" value="<?php _e('Update Settings', 'nxs_snap') ?>" /></div></div><?php
82
+ }
83
+ //#### Set Unit Settings from POST
84
+ function setNTSettings($post, $options){ global $nxs_snapThisPageUrl; $code = 'LJ'; $lcode = 'lj';
85
+ foreach ($post as $ii => $pval){
86
+ if (isset($pval['apLJUName']) && $pval['apLJUName']!=''){ if (!isset($options[$ii])) $options[$ii] = array();
87
+ if (isset($pval['nName'])) $options[$ii]['nName'] = trim($pval['nName']);
88
+ if (isset($pval['ljSrv'])) $options[$ii]['ljSrv'] = trim($pval['ljSrv']); if ($options[$ii]['ljSrv']=='DW') $server = 'dreamwidth.org'; else $server = 'livejournal.com';
89
+ if (isset($pval['apLJUName'])) $options[$ii]['ljUName'] = trim($pval['apLJUName']); $options[$ii]['ljURL'] = 'http://'.$options[$ii]['ljUName'].$server;
90
+ if (isset($pval['apLJPass'])) $options[$ii]['ljPass'] = 'n5g9a'.nsx_doEncode($pval['apLJPass']); else $options[$ii]['ljPass'] = '';
91
+ if (isset($pval['apLJMsgFrmt'])) $options[$ii]['ljMsgFormat'] = trim($pval['apLJMsgFrmt']);
92
+ if (isset($pval['apLJMsgTFrmt'])) $options[$ii]['ljMsgTFormat'] = trim($pval['apLJMsgTFrmt']);
93
+ if (isset($pval['catSel'])) $options[$ii]['catSel'] = trim($pval['catSel']);
94
+ if (isset($pval['inclTags'])) $options[$ii]['inclTags'] = $pval['inclTags']; else $options[$ii]['inclTags'] = 0;
95
+
96
+ if ($options[$ii]['catSel']=='1' && trim($pval['catSelEd'])!='') $options[$ii]['catSelEd'] = trim($pval['catSelEd']); else $options[$ii]['catSelEd'] = '';
97
+
98
+ if (isset($pval['commID'])) {
99
+ if (stripos($pval['commID'], '.')!==false) $pval['commID'] = CutFromTo($pval['commID'], '://', '.');
100
+ $options[$ii]['commID'] = trim($pval['commID']);
101
+ }
102
+ if (isset($pval['apDoLJ'])) $options[$ii]['doLJ'] = $pval['apDoLJ']; else $options[$ii]['doLJ'] = 0;
103
+ if (isset($pval['delayHrs'])) $options[$ii]['nHrs'] = trim($pval['delayHrs']); if (isset($pval['delayMin'])) $options[$ii]['nMin'] = trim($pval['delayMin']);
104
+ if (isset($pval['qTLng'])) $options[$ii]['qTLng'] = trim($pval['qTLng']);
105
+ }
106
+ } return $options;
107
+ }
108
+ //#### Show Post->Edit Meta Box Settings
109
+ function showEdPostNTSettings($ntOpts, $post){ global $nxs_plurl; $post_id = $post->ID;
110
+ foreach($ntOpts as $ii=>$ntOpt) { $pMeta = maybe_unserialize(get_post_meta($post_id, 'snapLJ', true)); if (is_array($pMeta)) $ntOpt = $this->adjMetaOpt($ntOpt, $pMeta[$ii]);
111
+ $doLJ = $ntOpt['doLJ'] && (is_array($pMeta) || $ntOpt['catSel']!='1');
112
+ $isAvailLJ = $ntOpt['ljUName']!='' && $ntOpt['ljPass']!=''; $ljMsgFormat = htmlentities($ntOpt['ljMsgFormat'], ENT_COMPAT, "UTF-8"); $ljMsgTFormat = htmlentities($ntOpt['ljMsgTFormat'], ENT_COMPAT, "UTF-8");
113
+ ?>
114
+ <tr><th style="text-align:left;" colspan="2"><?php if ( $ntOpt['catSel']=='1' && trim($ntOpt['catSelEd'])!='' ) { ?> <input type="hidden" class="nxs_SC" id="nxs_SC_LJ<?php echo $ii; ?>" value="<?php echo $ntOpt['catSelEd']; ?>" /> <?php } ?>
115
+ <?php if ($isAvailLJ) { ?><input class="nxsGrpDoChb" value="1" id="doLJ<?php echo $ii; ?>" <?php if ($post->post_status == "publish") echo 'disabled="disabled"';?> type="checkbox" name="lj[<?php echo $ii; ?>][doLJ]" <?php if ((int)$doLJ == 1) echo 'checked="checked" title="def"'; ?> />
116
+ <?php if ($post->post_status == "publish") { ?> <input type="hidden" name="lj[<?php echo $ii; ?>][doLJ]" value="<?php echo $doLJ;?>"> <?php } ?> <?php } ?>
117
+ <div class="nsx_iconedTitle" style="display: inline; font-size: 13px; background-image: url(<?php echo $nxs_plurl; ?>img/lj16.png);">LiveJournal - <?php _e('publish to', 'nxs_snap') ?> (<i style="color: #005800;"><?php echo $ntOpt['nName']; ?></i>)</div></th> <td><?php //## Only show RePost button if the post is "published"
118
+ if ($post->post_status == "publish" && $isAvailLJ) { ?><input alt="<?php echo $ii; ?>" style="float: right;" onmouseout="hidePopShAtt('SV');" onmouseover="shoLJopShAtt('SV', event);" onclick="return false;" type="button" class="button" name="rePostToLJ_repostButton" id="rePostToLJ_button" value="<?php _e('Repost to LiveJournal', 'nxs_snap') ?>" />
119
+ <?php wp_nonce_field( 'rePostToLJ', 'rePostToLJ_wpnonce' ); } ?>
120
+
121
+ <?php if (is_array($pMeta) && is_array($pMeta[$ii]) && isset($pMeta[$ii]['pgID']) ) {
122
+ ?> <span id="pstdLJ<?php echo $ii; ?>" style="float: right;padding-top: 4px; padding-right: 10px;">
123
+ <a style="font-size: 10px;" href="<?php echo $pMeta[$ii]['pgID']; ?>" target="_blank"><?php $nType="LiveJournal"; printf( __( 'Posted on', 'nxs_snap' ), $nType); ?> <?php echo (isset($pMeta[$ii]['pDate']) && $pMeta[$ii]['pDate']!='')?(" (".$pMeta[$ii]['pDate'].")"):""; ?></a>
124
+ </span><?php } ?>
125
+
126
+ </td></tr>
127
+
128
+ <?php if (!$isAvailLJ) { ?><tr><th scope="row" style="text-align:right; width:150px; padding-top: 5px; padding-right:10px;"></th> <td><b>Setup your LiveJournal Account to AutoPost to LiveJournal</b>
129
+ <?php } elseif ($post->post_status != "puZblish") { ?>
130
+
131
+ <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top: 6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Title Format:', 'nxs_snap') ?></th>
132
+ <td><input value="<?php echo $ljMsgTFormat ?>" type="text" name="lj[<?php echo $ii; ?>][SNAPformatT]" style="width:60%;max-width: 610px;" onfocus="jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apLJTMsgFrmt<?php echo $ii; ?>');"/><?php nxs_doShowHint("apLJTMsgFrmt".$ii); ?></td></tr>
133
+
134
+ <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top: 6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Text Format:', 'nxs_snap') ?></th>
135
+ <td>
136
+ <textarea cols="150" rows="1" id="lj<?php echo $ii; ?>SNAPformat" name="lj[<?php echo $ii; ?>][SNAPformat]" style="width:60%;max-width: 610px;" onfocus="jQuery('#lj<?php echo $ii; ?>SNAPformat').attr('rows', 4); jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apLJMsgFrmt<?php echo $ii; ?>');"><?php echo $ljMsgFormat; ?></textarea>
137
+ <?php nxs_doShowHint("apLJMsgFrmt".$ii); ?></td></tr>
138
+
139
+ <?php }
140
+ }
141
+ }
142
+ //#### Save Meta Tags to the Post
143
+ function adjMetaOpt($optMt, $pMeta){ if (isset($pMeta['isPosted'])) $optMt['isPosted'] = $pMeta['isPosted']; else $optMt['isPosted'] = '';
144
+ if (isset($pMeta['SNAPformat'])) $optMt['ljMsgFormat'] = $pMeta['SNAPformat'];
145
+ if (isset($pMeta['SNAPformatT'])) $optMt['ljMsgTFormat'] = $pMeta['SNAPformatT'];
146
+ if (isset($pMeta['doLJ'])) $optMt['doLJ'] = $pMeta['doLJ'] == 1?1:0; else { if (isset($pMeta['SNAPformat'])) $optMt['doLJ'] = 0; }
147
+ if (isset($pMeta['SNAPincludeLJ']) && $pMeta['SNAPincludeLJ'] == '1' ) $optMt['doLJ'] = 1;
148
+ return $optMt;
149
+ }
150
+ }}
151
+ if (!function_exists("nxs_rePostToLJ_ajax")) {
152
+ function nxs_rePostToLJ_ajax() { check_ajax_referer('rePostToLJ'); $postID = $_POST['id']; $options = get_option('NS_SNAutoPoster');
153
+ foreach ($options['lj'] as $ii=>$two) if ($ii==$_POST['nid']) { $two['ii'] = $ii; $two['pType'] = 'aj';//if ($two['gpPageID'].$two['gpUName']==$_POST['nid']) {
154
+ $gppo = get_post_meta($postID, 'snapLJ', true); $gppo = maybe_unserialize($gppo);// prr($gppo);
155
+ if (is_array($gppo) && isset($gppo[$ii]) && is_array($gppo[$ii])){ $ntClInst = new nxs_snapClassLJ(); $two = $ntClInst->adjMetaOpt($two, $gppo[$ii]); }
156
+ $result = nxs_doPublishToLJ($postID, $two); if ($result == 200) die("Successfully sent your post to LiveJournal."); else die($result);
157
+ }
158
+ }
159
+ }
160
+
161
+ if (!function_exists("nxs_doPublishToLJ")) { //## Second Function to Post to LJ
162
+ function nxs_doPublishToLJ($postID, $options){ $ntCd = 'LJ'; $ntCdL = 'lj'; $ntNm = 'LJ Based Blog';
163
+ //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToLJ', array($postID, $options));
164
+ $ii = $options['ii']; if (!isset($options['pType'])) $options['pType'] = 'im'; if ($options['pType']=='sh') sleep(rand(1, 10));
165
+ $logNT = '<span style="color:#2097EE">LJ</span> - '.$options['nName'];
166
+ $snap_ap = get_post_meta($postID, 'snap'.$ntCd, true); $snap_ap = maybe_unserialize($snap_ap);
167
+ if ($options['pType']!='aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
168
+ $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted!='2') {
169
+ nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:'.$postID, 'Already posted. No reason for posting duplicate'.' |'.$uqID); return;
170
+ }
171
+ }
172
+ $imgURL = nxs_getPostImage($postID);
173
+ $email = $options['ljUName']; $pass = substr($options['ljPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($options['ljPass'], 5)):$options['ljPass'];
174
+ if ($postID=='0') { echo "Testing ... <br/><br/>"; $link = home_url(); $msgT = 'Test Link from '.$link; $msg = 'Test post please ignore'; } else { $post = get_post($postID); if(!$post) return; $link = get_permalink($postID);
175
+ $msgFormat = $options['ljMsgFormat']; $msg = nsFormatMessage($msgFormat, $postID); $msgTFormat = $options['ljMsgTFormat']; $msgT = nsFormatMessage($msgTFormat, $postID);
176
+ nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted'=>'1'));
177
+ } //prr($msg); prr($msgFormat);
178
+ $msg = str_ireplace("&lt;!--more--&gt;", '<!--more-->', $msg); if (stripos($msg, '<!--more-->')!==false) $msg = str_ireplace('<!--more-->', '<lj-cut>', $msg).'</lj-cut>';
179
+ $extInfo = ' | PostID: '.$postID." - ".$post->post_title;
180
+ //## Post
181
+ require_once ('apis/xmlrpc-client.php'); if ($options['ljSrv']=='DW') $server = 'dreamwidth.org'; else $server = 'livejournal.com';
182
+ $nxsToLJclient = new NXS_XMLRPC_Client('http://www.'.$server.'/interface/xmlrpc'); $nxsToLJclient->debug = false;
183
+
184
+ $date = time(); $year = date("Y", $date); $mon = date("m", $date); $day = date("d", $date); $hour = date("G", $date); $min = date("i", $date);
185
+ $nxsToLJContent = array( "username" => $options['ljUName'], "password" => $pass, "event" => $msg, "subject" => $msgT, "lineendings" => "unix", "year" => $year, "mon" => $mon, "day" => $day, "hour" => $hour, "min" => $min, "ver" => 2);
186
+ if ($options['commID']!='') $nxsToLJContent["usejournal"] = $options['commID'];
187
+
188
+ if ($options['inclTags']=='1'){ $t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) {$tggs[] = $tagA->name;} $tags = implode(',', $tggs); $nxsToLJContent['props'] = array('taglist' => $tags); }
189
+
190
+
191
+ if (!$nxsToLJclient->query('LJ.XMLRPC.postevent', $nxsToLJContent)) { $ret = 'Something went wrong - '.$nxsToLJclient->getErrorCode().' : '.$nxsToLJclient->getErrorMessage();} else $ret = 'OK';
192
+ $pid = $nxsToLJclient->getResponse(); if (is_array($pid)) $pid = $pid['url']; else { $ret = 'Something went wrong - NO PID '.print_r($pid, true);}
193
+
194
+ if ($ret!='OK') { if ($postID=='0') echo $ret;
195
+ nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.print_r($ret, true), $extInfo);
196
+ } else { if ($postID=='0') { echo 'OK - Message Posted, please see your LiveJournal'; nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); } else
197
+ { nxs_metaMarkAsPosted($postID, 'LJ', $options['ii'], array('isPosted'=>'1', 'pgID'=>$pid, 'pDate'=>date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo);} }
198
+ if ($ret == 'OK') return 200; else return $ret;
199
+ }
200
+ }
201
  ?>
inc-cl/pk.php CHANGED
@@ -1,295 +1,295 @@
1
- <?php
2
- //## NextScripts Facebook Connection Class
3
- $nxs_snapAvNts[] = array('code'=>'PK', 'lcode'=>'pk', 'name'=>'Plurk');
4
-
5
- if (!class_exists("nxs_snapClassPK")) { class nxs_snapClassPK {
6
-
7
- function pkCats() { return '<option value="">:freestyle(None)</option><option value="loves">loves</option><option value="likes">likes</option><option value="shares">shares</option><option value="gives">gives</option><option value="hates">hates</option><option value="wants">wants</option><option value="wishes">wishes</option><option value="needs">needs</option><option value="will">will</option><option value="hopes">hopes</option><option value="asks">asks</option><option value="has">has</option><option value="was">was</option><option value="wonders">wonders</option><option value="feels on">feels</option><option value="thinks">thinks</option><option value="says">says</option><option value="is">is</option>';}
8
- //#### Show Common Settings
9
- function showGenNTSettings($ntOpts){ global $nxs_snapThisPageUrl, $nxs_plurl; $ntInfo = array('code'=>'PK', 'lcode'=>'pk', 'name'=>'Plurk', 'defNName'=>'', 'tstReq' => true);
10
- if ( isset($_GET['auth']) && $_GET['auth']=='pk'){ require_once('apis/plurkOAuth.php'); $options = $ntOpts[$_GET['acc']];
11
- $consumer_key = $options['pkConsKey']; $consumer_secret = $options['pkConsSec'];
12
- $callback_url = $nxs_snapThisPageUrl."&auth=pka&acc=".$_GET['acc'];
13
-
14
- $tum_oauth = new wpPlurkOAuth($consumer_key, $consumer_secret); //prr($tum_oauth);
15
- $request_token = $tum_oauth->getReqToken($callback_url);
16
- $options['pkOAuthToken'] = $request_token['oauth_token'];
17
- $options['pkOAuthTokenSecret'] = $request_token['oauth_token_secret'];// prr($tum_oauth ); die();
18
-
19
- //prr($tum_oauth); prr($options); die();
20
-
21
- switch ($tum_oauth->http_code) { case 200: $url = 'http://www.plurk.com/OAuth/authorize?oauth_token='.$options['pkOAuthToken'];
22
- $optionsG = get_option('NS_SNAutoPoster'); $optionsG['pk'][$_GET['acc']] = $options; update_option('NS_SNAutoPoster', $optionsG);
23
- echo '<br/><br/>All good?! Redirecting ..... <script type="text/javascript">window.location = "'.$url.'"</script>'; break;
24
- default: echo '<br/><b style="color:red">Could not connect to Plurk. Refresh the page or try again later.</b>'; die();
25
- }
26
- die();
27
- }
28
- if ( isset($_GET['auth']) && $_GET['auth']=='pka'){ require_once('apis/plurkOAuth.php'); $options = $ntOpts[$_GET['acc']];
29
- $consumer_key = $options['pkConsKey']; $consumer_secret = $options['pkConsSec'];
30
-
31
- $tum_oauth = new wpPlurkOAuth($consumer_key, $consumer_secret, $options['pkOAuthToken'], $options['pkOAuthTokenSecret']); //prr($tum_oauth);
32
- $access_token = $tum_oauth->getAccToken($_GET['oauth_verifier']); prr($access_token);
33
- $options['pkAccessTocken'] = $access_token['oauth_token']; $options['pkAccessTockenSec'] = $access_token['oauth_token_secret'];
34
- $optionsG = get_option('NS_SNAutoPoster'); $optionsG['pk'][$_GET['acc']] = $options; update_option('NS_SNAutoPoster', $optionsG);
35
-
36
- $tum_oauth = new wpPlurkOAuth($consumer_key, $consumer_secret, $options['pkAccessTocken'], $options['pkAccessTockenSec']);
37
- $uinfo = $tum_oauth->makeReq('http://www.plurk.com/APP/Profile/getOwnProfile', $params);
38
- if (is_array($uinfo) && isset($uinfo['user_info'])) $userinfo = $uinfo['user_info']['display_name'];
39
-
40
- $options['pkPgID'] = $userinfo; $optionsG = get_option('NS_SNAutoPoster'); $optionsG['pk'][$_GET['acc']] = $options; update_option('NS_SNAutoPoster', $optionsG);
41
-
42
- if ($options['pkPgID']!='') { echo '<br/><br/>All good?! Redirecting ..... <script type="text/javascript">window.location = "'.$nxs_snapThisPageUrl.'"</script>'; break; die();}
43
- else die("<span style='color:red;'>ERROR: Authorization Error: <span style='color:darkred; font-weight: bold;'>".$options['pkPgID']."</span></span>");
44
- }
45
- global $nxs_plurl; ?>
46
- <div class="nxs_box">
47
- <div class="nxs_box_header">
48
- <div class="nsx_iconedTitle" style="margin-bottom:1px;background-image:url(<?php echo $nxs_plurl;?>img/<?php echo $ntInfo['lcode']; ?>16.png);"><?php echo $ntInfo['name']; ?>
49
- <?php $cbo = count($ntOpts); ?> <?php wp_nonce_field( 'ns'.$ntInfo['code'], 'ns'.$ntInfo['code'].'_wpnonce' ); ?>
50
- <?php if ($cbo>1){ ?><div class="nsBigText"><?php echo "(".($cbo=='0'?'No':$cbo)." "; _e('accounts', 'nxs_snap'); echo ")"; ?></div><?php } ?>
51
- </div>
52
- </div>
53
- <div class="nxs_box_inside">
54
- <?php foreach ($ntOpts as $indx=>$pbo){ if (trim($pbo['nName']=='')) $pbo['nName'] = str_ireplace('https://','', str_ireplace('http://','', $pbo['pkURL']));
55
- if (!isset($pbo[$ntInfo['lcode'].'OK']) || $pbo[$ntInfo['lcode'].'OK']=='') $pbo[$ntInfo['lcode'].'OK'] = (isset($pbo['pkOAuthTokenSecret']) && $pbo['pkOAuthTokenSecret']!='')?'1':''; ?>
56
- <p style="margin:0px;margin-left:5px;">
57
- <input value="1" name="<?php echo $ntInfo['lcode']; ?>[<?php echo $indx; ?>][apDo<?php echo $ntInfo['code']; ?>]" onchange="doShowHideBlocks('<?php echo $ntInfo['code']; ?>');" type="checkbox" <?php if ((int)$pbo['do'.$ntInfo['code']] == 1) echo "checked"; ?> /> <?php if ((int)$pbo['catSel'] == 1) { ?> <span onmouseout="nxs_hidePopUpInfo('popOnlyCat');" onmouseover="nxs_showPopUpInfo('popOnlyCat', event);"><?php echo "*[".(substr_count($pbo['catSelEd'], ",")+1)."]*" ?></span><?php } ?>
58
- <strong><?php _e('Auto-publish to', 'nxs_snap'); ?> <?php echo $ntInfo['name']; ?> <i style="color: #005800;"><?php if($pbo['nName']!='') echo "(".$pbo['nName'].")"; ?></i></strong>
59
- &nbsp;&nbsp;<?php if ($ntInfo['tstReq'] && (!isset($pbo[$ntInfo['lcode'].'OK']) || $pbo[$ntInfo['lcode'].'OK']=='')){ ?><b style="color: #800000"><?php _e('Attention requred. Unfinished setup', 'nxs_snap'); ?> ==&gt;</b><?php } ?><a id="do<?php echo $ntInfo['code'].$indx; ?>A" href="#" onclick="doShowHideBlocks2('<?php echo $ntInfo['code'].$indx; ?>');return false;">[<?php _e('Show Settings', 'nxs_snap'); ?>]</a>&nbsp;&nbsp;
60
- <a href="#" onclick="doDelAcct('<?php echo $ntInfo['lcode']; ?>', '<?php echo $indx; ?>', '<?php if (isset($pbo['bgBlogID'])) echo $pbo['nName']; ?>');return false;">[<?php _e('Remove Account', 'nxs_snap'); ?>]</a>
61
- </p><?php $this->showNTSettings($indx, $pbo);
62
- }?>
63
- </div>
64
- </div> <?php
65
- }
66
- //#### Show NEW Settings Page
67
- function showNewNTSettings($bo){ $po = array('nName'=>'', 'doPK'=>'1', 'pkURL'=>'', 'pkPgID'=>'', 'pkConsKey'=>'', 'pkInclTags'=>'1', 'cImgURL'=>'R', 'pkConsSec'=>'', 'pkPostType'=>'T', 'pkDefImg'=>'', 'pkOAuthTokenSecret'=>'', 'pkAccessTocken'=>'', 'pkMsgFormat'=>'%TITLE% - %URL%'); $this->showNTSettings($bo, $po, true);}
68
- //#### Show Unit Settings
69
- function showNTSettings($ii, $options, $isNew=false){ global $nxs_plurl,$nxs_snapThisPageUrl; ?>
70
- <div id="doPK<?php echo $ii; ?>Div" class="insOneDiv<?php if ($isNew) echo " clNewNTSets"; ?>" style="background-image: url(<?php echo $nxs_plurl; ?>img/pk-bg.png); background-position:90% 10%;"> <input type="hidden" name="apDoSPK<?php echo $ii; ?>" value="0" id="apDoSPK<?php echo $ii; ?>" />
71
- <?php if ($isNew) { ?> <input type="hidden" name="pk[<?php echo $ii; ?>][apDoPK]" value="1" id="apDoNewPK<?php echo $ii; ?>" /> <?php } ?>
72
-
73
- <div class="nsx_iconedTitle" style="float: right; background-image: url(<?php echo $nxs_plurl; ?>img/pk16.png);"><a style="font-size: 12px;" target="_blank" href="http://www.nextscripts.com/setup-installation-plurk-social-networks-auto-poster-wordpress/"><?php $nType="Plurk"; printf( __( 'Detailed %s Installation/Configuration Instructions', 'nxs_snap' ), $nType); ?></a></div>
74
-
75
- <div style="width:100%;"><strong><?php _e('Account Nickname', 'nxs_snap'); ?>:</strong> <i><?php _e('Just so you can easely identify it', 'nxs_snap'); ?></i> </div><input name="pk[<?php echo $ii; ?>][nName]" id="pknName<?php echo $ii; ?>" style="font-weight: bold; color: #005800; border: 1px solid #ACACAC; width: 40%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['nName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /><br/>
76
- <?php echo nxs_addQTranslSel('pk', $ii, $options['qTLng']); ?><?php echo nxs_addPostingDelaySel('pk', $ii, $options['nHrs'], $options['nMin']); ?>
77
-
78
- <?php if (!$isNew) { ?>
79
- <div style="width:100%;"><strong><?php _e('Categories', 'nxs_snap'); ?>:</strong>
80
- <input value="0" id="catSelA<?php echo $ii; ?>" type="radio" name="pk[<?php echo $ii; ?>][catSel]" <?php if ((int)$options['catSel'] != 1) echo "checked"; ?> /> All
81
- <input value="1" id="catSelSPK<?php echo $ii; ?>" type="radio" name="pk[<?php echo $ii; ?>][catSel]" <?php if ((int)$options['catSel'] == 1) echo "checked"; ?> /> <a href="#" style="text-decoration: none;" class="showCats" id="nxs_SCA_PK<?php echo $ii; ?>" onclick="jQuery('#catSelSPK<?php echo $ii; ?>').attr('checked', true); jQuery('#tmpCatSelNT').val('PK<?php echo $ii; ?>'); nxs_markCats( jQuery('#nxs_SC_PK<?php echo $ii; ?>').val() ); jQuery('#showCatSel').bPopup({ modalClose: false, appendTo: '#nsStForm', opacity: 0.6, follow: [false, false], position: [75, 'auto']}); return false;">Selected<?php if ($options['catSelEd']!='') echo "[".(substr_count($options['catSelEd'], ",")+1)."]"; ?></a>
82
- <input type="hidden" name="pk[<?php echo $ii; ?>][catSelEd]" id="nxs_SC_PK<?php echo $ii; ?>" value="<?php echo $options['catSelEd']; ?>" />
83
- <br/><i><?php _e('Only selected categories will be autoposted to this account', 'nxs_snap'); ?></i></div>
84
- <br/>
85
- <?php } ?>
86
-
87
- <div style="width:100%;"><strong>Your Plurk URL:</strong> </div><input onchange="nxsPKURLVal(<?php echo $ii; ?>);" name="pk[<?php echo $ii; ?>][apPKURL]" id="apPKURL<?php echo $ii; ?>" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['pkURL'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /><span style="color: #F00000;" id="apPKURLerr<?php echo $ii; ?>"></span>
88
- <div style="width:100%;"><strong>Your Plurk App Key:</strong> </div><input name="pk[<?php echo $ii; ?>][apPKConsKey]" id="apPKConsKey" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['pkConsKey'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
89
- <div style="width:100%;"><strong>Your Plurk App Secret:</strong> </div><input name="pk[<?php echo $ii; ?>][apPKConsSec]" id="apPKConsSec" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['pkConsSec'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
90
- <br/><br/>
91
-
92
- <div id="altFormat" style="">
93
- <div style="width:100%;"><strong id="altFormatText">Plurk prefix:</strong> </div>
94
-
95
- <select name="pk[<?php echo $ii; ?>][Cat]" id="pkCat<?php echo $ii; ?>">
96
- <?php $pkCats = $this->pkCats();
97
- if (isset($options['pkCat']) && $options['pkCat']!='') $pkCats = str_replace($options['pkCat'].'"', $options['pkCat'].'" selected="selected"', $pkCats); echo $pkCats;
98
- ?>
99
- </select>
100
- </div>
101
- <br/>
102
- <p style="margin: 0px;"><input value="1" id="apLIAttch" type="checkbox" name="pk[<?php echo $ii; ?>][attchImg]" <?php if ((int)$options['attchImg'] == 1) echo "checked"; ?> /> <strong>Attach Image to Plurk Post</strong></p>
103
- <br/>
104
-
105
- <div style="width:100%;"><strong id="altFormatText"><?php _e('Post Text Format', 'nxs_snap'); ?>:</strong> (<a href="#" id="apPKMsgFrmt<?php echo $ii; ?>HintInfo" onclick="mxs_showHideFrmtInfo('apPKMsgFrmt<?php echo $ii; ?>'); return false;"><?php _e('Show format info', 'nxs_snap'); ?></a>) </div>
106
-
107
- <textarea cols="150" rows="3" id="pk<?php echo $ii; ?>SNAPformat" name="pk[<?php echo $ii; ?>][apPKMsgFrmt]" style="width:51%;max-width: 650px;" onfocus="jQuery('#pk<?php echo $ii; ?>SNAPformat').attr('rows', 6); mxs_showFrmtInfo('apPKMsgFrmt<?php echo $ii; ?>');"><?php if ($options['pkMsgFormat']!='') _e(apply_filters('format_to_edit', htmlentities($options['pkMsgFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap'); else echo htmlentities("%TITLE% - %URL%"); ?></textarea>
108
-
109
- <br/>
110
- <?php nxs_doShowHint("apPKMsgFrmt".$ii); ?>
111
- <br/>
112
- <?php
113
- if($options['pkConsSec']=='') { ?>
114
- <b>Authorize Your Plurk Account</b>. Please save your settings and come back here to Authorize your account.
115
- <?php } else { if(isset($options['pkAccessTocken']) && isset($options['pkAccessTocken']['oauth_token_secret']) && $options['pkAccessTocken']['oauth_token_secret']!=='') { ?>
116
- Your Plurk Account has been authorized. Your display name: <?php _e(apply_filters('format_to_edit', htmlentities($options['pkPgID'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>.
117
- You can Re- <?php } ?>
118
- <a href="<?php echo $nxs_snapThisPageUrl;?>&auth=pk&acc=<?php echo $ii; ?>">Authorize Your Plurk Account</a>
119
- <?php if (!isset($options['pkOAuthTokenSecret']) || $options['pkOAuthTokenSecret']=='') { ?> <div class="blnkg">&lt;=== Authorize your account ===</div> <?php } ?>
120
- <?php } ?>
121
-
122
-
123
- <?php if( isset($options['pkOAuthTokenSecret']) && $options['pkOAuthTokenSecret']!='') { ?>
124
- <?php wp_nonce_field( 'rePostToPK', 'rePostToPK_wpnonce' ); ?>
125
- <br/><br/><b><?php _e('Test your settings', 'nxs_snap'); ?>:</b>&nbsp;&nbsp;&nbsp; <a href="#" class="NXSButton" onclick="testPost('PK', '<?php echo $ii; ?>'); return false;"><?php printf( __( 'Submit Test Post to %s', 'nxs_snap' ), $nType); ?></a> <br/><br/>
126
- <?php }?>
127
- <div class="submit"><input type="submit" class="button-primary" name="update_NS_SNAutoPoster_settings" value="<?php _e('Update Settings', 'nxs_snap') ?>" /></div>
128
-
129
- </div>
130
- <?php
131
-
132
-
133
- }
134
- //#### Set Unit Settings from POST
135
- function setNTSettings($post, $options){ global $nxs_snapThisPageUrl; //prr($post); die();
136
- foreach ($post as $ii => $pval){ // prr($pval);
137
- if (isset($pval['apPKConsKey']) && $pval['apPKConsSec']!='') { if (!isset($options[$ii])) $options[$ii] = array();
138
-
139
- if (isset($pval['apPKURL'])) { $options[$ii]['pkURL'] = trim($pval['apPKURL']); if ( substr($options[$ii]['pkURL'], 0, 4)!='http' ) $options[$ii]['pkURL'] = 'http://'.$options[$ii]['pkURL'];
140
- $pkPgID = $options[$ii]['pkURL']; if (substr($pkPgID, -1)=='/') $pkPgID = substr($pkPgID, 0, -1); $pkPgID = substr(strrchr($pkPgID, "/"), 1);
141
- $options[$ii]['pkPgID'] = $pkPgID; //echo $fbPgID;
142
- }
143
- if (isset($pval['apDoPK'])) $options[$ii]['doPK'] = $pval['apDoPK']; else $options[$ii]['doPK'] = 0;
144
- if (isset($pval['nName'])) $options[$ii]['nName'] = trim($pval['nName']);
145
- if (isset($pval['apPKConsKey'])) $options[$ii]['pkConsKey'] = trim($pval['apPKConsKey']);
146
- if (isset($pval['apPKConsSec'])) $options[$ii]['pkConsSec'] = trim($pval['apPKConsSec']);
147
-
148
- if (isset($pval['catSel'])) $options[$ii]['catSel'] = trim($pval['catSel']);
149
- if ($options[$ii]['catSel']=='1' && trim($pval['catSelEd'])!='') $options[$ii]['catSelEd'] = trim($pval['catSelEd']); else $options[$ii]['catSelEd'] = '';
150
-
151
- if (isset($pval['apPKMsgFrmt'])) $options[$ii]['pkMsgFormat'] = trim($pval['apPKMsgFrmt']);
152
- if (isset($pval['Cat'])) $options[$ii]['pkCat'] = $pval['Cat']; else $options[$ii]['pkCat'] = "";
153
- if (isset($pval['attchImg'])) $options[$ii]['attchImg'] = $pval['attchImg']; else $options[$ii]['attchImg'] = 0;
154
- if (isset($pval['delayHrs'])) $options[$ii]['nHrs'] = trim($pval['delayHrs']); if (isset($pval['delayMin'])) $options[$ii]['nMin'] = trim($pval['delayMin']);
155
- if (isset($pval['qTLng'])) $options[$ii]['qTLng'] = trim($pval['qTLng']);
156
- } // prr($options);
157
- } return $options;
158
- }
159
- //#### Show Post->Edit Meta Box Settings
160
- function showEdPostNTSettings($ntOpts, $post){ global $nxs_plurl; $post_id = $post->ID;
161
- foreach($ntOpts as $ii=>$options) {$pMeta = maybe_unserialize(get_post_meta($post_id, 'snapPK', true)); if (is_array($pMeta)) $options = $this->adjMetaOpt($options, $pMeta[$ii]);
162
- $doPK = $options['doPK'] && (is_array($pMeta) || $options['catSel']!='1');
163
- $isAvailPK = isset($options['pkAccessTocken']) && isset($options['pkAccessTocken']['oauth_token_secret']) && $options['pkAccessTocken']['oauth_token_secret']!=='';
164
- $pkMsgFormat = htmlentities($options['pkMsgFormat'], ENT_COMPAT, "UTF-8"); $pkMsgTFormat = htmlentities($options['pkMsgTFormat'], ENT_COMPAT, "UTF-8");
165
- ?>
166
-
167
- <tr><th style="text-align:left;" colspan="2"><?php if ( $options['catSel']=='1' && trim($options['catSelEd'])!='' ) { ?> <input type="hidden" class="nxs_SC" id="nxs_SC_PK<?php echo $ii; ?>" value="<?php echo $options['catSelEd']; ?>" /> <?php } ?>
168
- <?php if ($isAvailPK) { ?><input class="nxsGrpDoChb" value="1" id="doPK<?php echo $ii; ?>" <?php if ($post->post_status == "publish") echo 'disabled="disabled"';?> type="checkbox" name="pk[<?php echo $ii; ?>][doPK]" <?php if ((int)$doPK == 1) echo 'checked="checked" title="def"'; ?> />
169
- <?php if ($post->post_status == "publish") { ?> <input type="hidden" name="pk[<?php echo $ii; ?>][doPK]" value="<?php echo $doPK;?>"> <?php } ?> <?php } ?>
170
- <div class="nsx_iconedTitle" style="display: inline; font-size: 13px; background-image: url(<?php echo $nxs_plurl; ?>img/pk16.png);">Plurk - <?php _e('publish to', 'nxs_snap') ?> (<i style="color: #005800;"><?php echo $options['nName']; ?></i>) </div></th><td><?php //## Only show RePost button if the post is "published"
171
- if ($post->post_status == "publish" && $isAvailPK) { ?><input alt="<?php echo $ii; ?>" style="float: right;" onmouseout="hidePopShAtt('SV');" onmouseover="showPopShAtt('SV', event);" onclick="return false;" type="button" class="button" name="rePostToPK_repostButton" id="rePostToPK_button" value="<?php _e('Repost to Plurk', 'nxs_snap') ?>" />
172
- <?php wp_nonce_field( 'rePostToPK', 'rePostToPK_wpnonce' ); } ?>
173
-
174
- <?php if (is_array($pMeta) && is_array($pMeta[$ii]) && isset($pMeta[$ii]['pgID']) ) {
175
- ?> <span id="pstdPK<?php echo $ii; ?>" style="float: right;padding-top: 4px; padding-right: 10px;">
176
- <a style="font-size: 10px;" href="http://www.plurk.com/p/<?php echo base_convert($pMeta[$ii]['pgID'], 10, 36); ?>" target="_blank"><?php $nType="Plurk"; printf( __( 'Posted on', 'nxs_snap' ), $nType); ?> <?php echo (isset($pMeta[$ii]['pDate']) && $pMeta[$ii]['pDate']!='')?(" (".$pMeta[$ii]['pDate'].")"):""; ?></a>
177
- </span><?php } ?>
178
-
179
- </td></tr>
180
- <?php if (!$isAvailPK) { ?><tr><th scope="row" style="text-align:right; width:150px; padding-top: 5px; padding-right:10px;"></th> <td><b>Setup and authorize your Plurk Account to AutoPost to Plurk</b>
181
- <?php }elseif ($post->post_status != "puZblish") { ?>
182
-
183
- <tr id="altFormat1" style=""><th scope="row" style="text-align:right; width:60px; padding-right:10px;">
184
- Prefix:
185
-
186
- </th>
187
- <td><select name="pk[<?php echo $ii; ?>][Cat]" id="apPKCat<?php echo $ii; ?>">
188
- <?php $pkCats = $this->pkCats();
189
- if ($ntOpt['pkCat']!='') $pkCats = str_replace($ntOpt['pkCat'].'"', $ntOpt['pkCat'].'" selected="selected"', $pkCats); echo $pkCats;
190
-
191
- ?>
192
- </select></td></tr>
193
-
194
- <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top:6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Text Format:', 'nxs_snap') ?></th>
195
- <td>
196
- <textarea cols="150" rows="1" id="pk<?php echo $ii; ?>SNAPformat" name="pk[<?php echo $ii; ?>][SNAPformat]" style="width:60%;max-width: 610px;" onfocus="jQuery('#pk<?php echo $ii; ?>SNAPformat').attr('rows', 4); jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apPKMsgFrmt<?php echo $ii; ?>');"><?php echo $pkMsgFormat; ?></textarea>
197
- <?php nxs_doShowHint("apPKMsgFrmt".$ii); ?></td></tr>
198
-
199
- <?php }
200
- }
201
-
202
- }
203
-
204
- function adjMetaOpt($optMt, $pMeta){ if (isset($pMeta['isPosted'])) $optMt['isPosted'] = $pMeta['isPosted']; else $optMt['isPosted'] = '';
205
- if (isset($pMeta['SNAPformat'])) $optMt['pkMsgFormat'] = $pMeta['SNAPformat'];
206
- if (isset($pMeta['Cat'])) $optMt['pkCat'] = $pMeta['Cat'];
207
- if (isset($pMeta['doPK'])) $optMt['doPK'] = $pMeta['doPK'] == 1?1:0; else { if (isset($pMeta['SNAPformat'])) $optMt['doPK'] = 0; }
208
- if (isset($pMeta['SNAPincludePK']) && $pMeta['SNAPincludePK'] == '1' ) $optMt['doPK'] = 1;
209
- return $optMt;
210
- }
211
- }}
212
-
213
- if (!function_exists("nxs_rePostToPK_ajax")) { function nxs_rePostToPK_ajax() { check_ajax_referer('rePostToPK'); $postID = $_POST['id']; // $result = nsPublishTo($id, 'FB', true);
214
- $options = get_option('NS_SNAutoPoster'); foreach ($options['pk'] as $ii=>$po) if ($ii==$_POST['nid']) { $po['ii'] = $ii; $po['pType'] = 'aj';
215
- $mpo = get_post_meta($postID, 'snapPK', true); $mpo = maybe_unserialize($mpo);
216
- if (is_array($mpo) && isset($mpo[$ii]) && is_array($mpo[$ii]) ){ $ntClInst = new nxs_snapClassPK(); $po = $ntClInst->adjMetaOpt($po, $mpo[$ii]); }
217
- $result = nxs_doPublishToPK($postID, $po); if ($result == 200 || $result == 201) die("Your post has been successfully sent to Plurk."); else { echo $result; die(); }
218
- }
219
- }
220
- }
221
-
222
- if (!function_exists("nxs_doPublishToPK")) { //## Second Function to Post to TR
223
- function nxs_doPublishToPK($postID, $options){ $ntCd = 'PK'; $ntCdL = 'pk'; $ntNm = 'Plurk';
224
- //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToPK', array($postID, $options));
225
- $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle=='') $blogTitle = home_url();
226
-
227
- $ii = $options['ii']; if (!isset($options['pType'])) $options['pType'] = 'im'; if ($options['pType']=='sh') sleep(rand(1, 10));
228
- $logNT = '<span style="color:#014A76">Plurk</span> - '.$options['nName'];
229
- $snap_ap = get_post_meta($postID, 'snap'.$ntCd, true); $snap_ap = maybe_unserialize($snap_ap);
230
- if ($options['pType']!='aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
231
- $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted!='2') { sleep(5);
232
- nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:'.$postID, 'Already posted. No reason for posting duplicate'.' |'.$uqID); return;
233
- }
234
- }
235
- //## Format
236
- if ($postID=='0') { echo "Testing ... <br/><br/>"; $msg = 'Test Post from '.$blogTitle; $msgT = 'Test Post from '.$blogTitle;}
237
- else{ $post = get_post($postID); if(!$post) return; $twMsgFormat = $options['pkMsgFormat']; nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted'=>'1')); $twLim = 180;
238
- $extInfo = ' | PostID: '.$postID." - ".$post->post_title;
239
- if (stripos($twMsgFormat, '%URL%')!==false || stripos($twMsgFormat, '%SURL%')!==false) $twLim = $twLim - 5;
240
- if (stripos($twMsgFormat, '%AUTHORNAME%')!==false) { $aun = $post->post_author; $aun = get_the_author_meta('display_name', $aun ); $twLim = $twLim - strlen($aun); }
241
-
242
- $noRepl = str_ireplace("%TITLE%", "", $twMsgFormat); $noRepl = str_ireplace("%SITENAME%", "", $noRepl); $noRepl = str_ireplace("%URL%", "", $noRepl);$noRepl = str_ireplace("%RAWEXCERPT%", "", $noRepl);
243
- $noRepl = str_ireplace("%SURL%", "", $noRepl);$noRepl = str_ireplace("%TEXT%", "", $noRepl);$noRepl = str_ireplace("%FULLTEXT%", "", $noRepl);$noRepl = str_ireplace("%EXCERPT%", "", $noRepl);
244
- $noRepl = str_ireplace("%ANNOUNCE%", "", $noRepl); $noRepl = str_ireplace("%AUTHORNAME%", "", $noRepl); $twLim = $twLim - strlen($noRepl);
245
-
246
- $pTitle = $title = $post->post_title;
247
- if ($post->post_excerpt!="") $pText = apply_filters('the_content', $post->post_excerpt); else $pText= apply_filters('the_content', $post->post_content);
248
- $pFullText = apply_filters('the_content', $post->post_content);
249
- $pRawText = $post->post_content;
250
-
251
-
252
- if (stripos($twMsgFormat, '%TITLE%')!==false) {
253
- $pTitle = nsTrnc($pTitle, $twLim); $twMsgFormat = str_ireplace("%TITLE%", $pTitle, $twMsgFormat); $twLim = $twLim - strlen($pTitle);
254
- }
255
- if (stripos($twMsgFormat, '%SITENAME%')!==false) {
256
- $siteTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); $siteTitle = nsTrnc($siteTitle, $twLim); $twMsgFormat = str_ireplace("%SITENAME%", $siteTitle, $twMsgFormat); $twLim = $twLim - strlen($siteTitle);
257
- }
258
- if (stripos($twMsgFormat, '%EXCERPT%')!==false) {
259
- $pText = nsTrnc(strip_tags(strip_shortcodes($pText)), 300, " ", "...");
260
- $pText = nsTrnc($pText, $twLim); $twMsgFormat = str_ireplace("%EXCERPT%", $pText, $twMsgFormat); $twLim = $twLim - strlen($pText);
261
- }
262
- if (stripos($twMsgFormat, '%FULLTEXT%')!==false) {
263
- $pFullText = nsTrnc(strip_tags($pFullText), $twLim); $twMsgFormat = str_ireplace("%FULLTEXT%", $pFullText, $twMsgFormat); $twLim = $twLim - strlen($pFullText);
264
- }
265
- if (stripos($twMsgFormat, '%RAWTEXT%')!==false) {
266
- $pRawText = nsTrnc(strip_tags($pRawText), $twLim); $twMsgFormat = str_ireplace("%FULLTEXT%", $pRawText, $twMsgFormat); $twLim = $twLim - strlen($pRawText);
267
- }
268
-
269
- $msg = nsFormatMessage($twMsgFormat, $postID);
270
-
271
- }
272
- //## Post
273
- require_once('apis/plurkOAuth.php'); $consumer_key = $options['pkConsKey']; $consumer_secret = $options['pkConsSec'];
274
- $tum_oauth = new wpPlurkOAuth($consumer_key, $consumer_secret, $options['pkAccessTocken'], $options['pkAccessTockenSec']);
275
- $pkURL = trim(str_ireplace('http://', '', $options['pkURL'])); if (substr($pkURL,-1)=='/') $pkURL = substr($pkURL,0,-1);
276
- if ($options['pkCat']=='')$options['pkCat'] = ':';
277
-
278
- if ($options['attchImg']=='1') { $imgURL = nxs_getPostImage($postID); $msg .= " ".$imgURL; }
279
-
280
- $postDate = ($post->post_date_gmt!='0000-00-00 00:00:00'?$post->post_date_gmt:gmdate("Y-m-d H:i:s", strtotime($post->post_date)))." GMT"; //## Adds date to Tumblr post. Thanks to Kenneth Lecky
281
-
282
- $postArr = array('content'=>$msg, 'qualifier'=>$options['pkCat']);
283
- $postinfo = $tum_oauth->makeReq('http://www.plurk.com/APP/Timeline/plurkAdd', $postArr); // prr($postinfo);
284
- if (is_array($postinfo) && isset($postinfo['plurk_id'])) $pkID = $postinfo['plurk_id'];
285
-
286
- $code = $tum_oauth->http_code;// echo "XX".print_r($code); prr($postinfo); // prr($msg); prr($postinfo); echo $code."VVVV"; die("|====");
287
- if ($code == 200) { if ($postID=='0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo 'OK - Message Posted, please see your Plurk Page. <br/> Result:'; }
288
- else { nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); nxs_metaMarkAsPosted($postID, 'PK', $options['ii'], array('isPosted'=>'1', 'pgID'=>$pkID, 'pDate'=>date('Y-m-d H:i:s'))); } }
289
- else { nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.print_r($postinfo, true), $extInfo); if ($postID=='0') prr($postinfo); $code .= " ERROR: - ".$postinfo['error_text']; }
290
-
291
- return $code;
292
- }
293
- }
294
-
295
  ?>
1
+ <?php
2
+ //## NextScripts Facebook Connection Class
3
+ $nxs_snapAvNts[] = array('code'=>'PK', 'lcode'=>'pk', 'name'=>'Plurk');
4
+
5
+ if (!class_exists("nxs_snapClassPK")) { class nxs_snapClassPK {
6
+
7
+ function pkCats() { return '<option value="">:freestyle(None)</option><option value="loves">loves</option><option value="likes">likes</option><option value="shares">shares</option><option value="gives">gives</option><option value="hates">hates</option><option value="wants">wants</option><option value="wishes">wishes</option><option value="needs">needs</option><option value="will">will</option><option value="hopes">hopes</option><option value="asks">asks</option><option value="has">has</option><option value="was">was</option><option value="wonders">wonders</option><option value="feels on">feels</option><option value="thinks">thinks</option><option value="says">says</option><option value="is">is</option>';}
8
+ //#### Show Common Settings
9
+ function showGenNTSettings($ntOpts){ global $nxs_snapThisPageUrl, $nxs_plurl; $ntInfo = array('code'=>'PK', 'lcode'=>'pk', 'name'=>'Plurk', 'defNName'=>'', 'tstReq' => true);
10
+ if ( isset($_GET['auth']) && $_GET['auth']=='pk'){ require_once('apis/plurkOAuth.php'); $options = $ntOpts[$_GET['acc']];
11
+ $consumer_key = $options['pkConsKey']; $consumer_secret = $options['pkConsSec'];
12
+ $callback_url = $nxs_snapThisPageUrl."&auth=pka&acc=".$_GET['acc'];
13
+
14
+ $tum_oauth = new wpPlurkOAuth($consumer_key, $consumer_secret); //prr($tum_oauth);
15
+ $request_token = $tum_oauth->getReqToken($callback_url);
16
+ $options['pkOAuthToken'] = $request_token['oauth_token'];
17
+ $options['pkOAuthTokenSecret'] = $request_token['oauth_token_secret'];// prr($tum_oauth ); die();
18
+
19
+ //prr($tum_oauth); prr($options); die();
20
+
21
+ switch ($tum_oauth->http_code) { case 200: $url = 'http://www.plurk.com/OAuth/authorize?oauth_token='.$options['pkOAuthToken'];
22
+ $optionsG = get_option('NS_SNAutoPoster'); $optionsG['pk'][$_GET['acc']] = $options; update_option('NS_SNAutoPoster', $optionsG);
23
+ echo '<br/><br/>All good?! Redirecting ..... <script type="text/javascript">window.location = "'.$url.'"</script>'; break;
24
+ default: echo '<br/><b style="color:red">Could not connect to Plurk. Refresh the page or try again later.</b>'; die();
25
+ }
26
+ die();
27
+ }
28
+ if ( isset($_GET['auth']) && $_GET['auth']=='pka'){ require_once('apis/plurkOAuth.php'); $options = $ntOpts[$_GET['acc']];
29
+ $consumer_key = $options['pkConsKey']; $consumer_secret = $options['pkConsSec'];
30
+
31
+ $tum_oauth = new wpPlurkOAuth($consumer_key, $consumer_secret, $options['pkOAuthToken'], $options['pkOAuthTokenSecret']); //prr($tum_oauth);
32
+ $access_token = $tum_oauth->getAccToken($_GET['oauth_verifier']); prr($access_token);
33
+ $options['pkAccessTocken'] = $access_token['oauth_token']; $options['pkAccessTockenSec'] = $access_token['oauth_token_secret'];
34
+ $optionsG = get_option('NS_SNAutoPoster'); $optionsG['pk'][$_GET['acc']] = $options; update_option('NS_SNAutoPoster', $optionsG);
35
+
36
+ $tum_oauth = new wpPlurkOAuth($consumer_key, $consumer_secret, $options['pkAccessTocken'], $options['pkAccessTockenSec']);
37
+ $uinfo = $tum_oauth->makeReq('http://www.plurk.com/APP/Profile/getOwnProfile', $params);
38
+ if (is_array($uinfo) && isset($uinfo['user_info'])) $userinfo = $uinfo['user_info']['display_name'];
39
+
40
+ $options['pkPgID'] = $userinfo; $optionsG = get_option('NS_SNAutoPoster'); $optionsG['pk'][$_GET['acc']] = $options; update_option('NS_SNAutoPoster', $optionsG);
41
+
42
+ if ($options['pkPgID']!='') { echo '<br/><br/>All good?! Redirecting ..... <script type="text/javascript">window.location = "'.$nxs_snapThisPageUrl.'"</script>'; break; die();}
43
+ else die("<span style='color:red;'>ERROR: Authorization Error: <span style='color:darkred; font-weight: bold;'>".$options['pkPgID']."</span></span>");
44
+ }
45
+ global $nxs_plurl; ?>
46
+ <div class="nxs_box">
47
+ <div class="nxs_box_header">
48
+ <div class="nsx_iconedTitle" style="margin-bottom:1px;background-image:url(<?php echo $nxs_plurl;?>img/<?php echo $ntInfo['lcode']; ?>16.png);"><?php echo $ntInfo['name']; ?>
49
+ <?php $cbo = count($ntOpts); ?> <?php wp_nonce_field( 'ns'.$ntInfo['code'], 'ns'.$ntInfo['code'].'_wpnonce' ); ?>
50
+ <?php if ($cbo>1){ ?><div class="nsBigText"><?php echo "(".($cbo=='0'?'No':$cbo)." "; _e('accounts', 'nxs_snap'); echo ")"; ?></div><?php } ?>
51
+ </div>
52
+ </div>
53
+ <div class="nxs_box_inside">
54
+ <?php foreach ($ntOpts as $indx=>$pbo){ if (trim($pbo['nName']=='')) $pbo['nName'] = str_ireplace('https://','', str_ireplace('http://','', $pbo['pkURL']));
55
+ if (!isset($pbo[$ntInfo['lcode'].'OK']) || $pbo[$ntInfo['lcode'].'OK']=='') $pbo[$ntInfo['lcode'].'OK'] = (isset($pbo['pkOAuthTokenSecret']) && $pbo['pkOAuthTokenSecret']!='')?'1':''; ?>
56
+ <p style="margin:0px;margin-left:5px;">
57
+ <input value="1" name="<?php echo $ntInfo['lcode']; ?>[<?php echo $indx; ?>][apDo<?php echo $ntInfo['code']; ?>]" onchange="doShowHideBlocks('<?php echo $ntInfo['code']; ?>');" type="checkbox" <?php if ((int)$pbo['do'.$ntInfo['code']] == 1) echo "checked"; ?> /> <?php if ((int)$pbo['catSel'] == 1) { ?> <span onmouseout="nxs_hidePopUpInfo('popOnlyCat');" onmouseover="nxs_showPopUpInfo('popOnlyCat', event);"><?php echo "*[".(substr_count($pbo['catSelEd'], ",")+1)."]*" ?></span><?php } ?>
58
+ <strong><?php _e('Auto-publish to', 'nxs_snap'); ?> <?php echo $ntInfo['name']; ?> <i style="color: #005800;"><?php if($pbo['nName']!='') echo "(".$pbo['nName'].")"; ?></i></strong>
59
+ &nbsp;&nbsp;<?php if ($ntInfo['tstReq'] && (!isset($pbo[$ntInfo['lcode'].'OK']) || $pbo[$ntInfo['lcode'].'OK']=='')){ ?><b style="color: #800000"><?php _e('Attention requred. Unfinished setup', 'nxs_snap'); ?> ==&gt;</b><?php } ?><a id="do<?php echo $ntInfo['code'].$indx; ?>A" href="#" onclick="doShowHideBlocks2('<?php echo $ntInfo['code'].$indx; ?>');return false;">[<?php _e('Show Settings', 'nxs_snap'); ?>]</a>&nbsp;&nbsp;
60
+ <a href="#" onclick="doDelAcct('<?php echo $ntInfo['lcode']; ?>', '<?php echo $indx; ?>', '<?php if (isset($pbo['bgBlogID'])) echo $pbo['nName']; ?>');return false;">[<?php _e('Remove Account', 'nxs_snap'); ?>]</a>
61
+ </p><?php $this->showNTSettings($indx, $pbo);
62
+ }?>
63
+ </div>
64
+ </div> <?php
65
+ }
66
+ //#### Show NEW Settings Page
67
+ function showNewNTSettings($bo){ $po = array('nName'=>'', 'doPK'=>'1', 'pkURL'=>'', 'pkPgID'=>'', 'pkConsKey'=>'', 'pkInclTags'=>'1', 'cImgURL'=>'R', 'pkConsSec'=>'', 'pkPostType'=>'T', 'pkDefImg'=>'', 'pkOAuthTokenSecret'=>'', 'pkAccessTocken'=>'', 'pkMsgFormat'=>'%TITLE% - %URL%'); $this->showNTSettings($bo, $po, true);}
68
+ //#### Show Unit Settings
69
+ function showNTSettings($ii, $options, $isNew=false){ global $nxs_plurl,$nxs_snapThisPageUrl; ?>
70
+ <div id="doPK<?php echo $ii; ?>Div" class="insOneDiv<?php if ($isNew) echo " clNewNTSets"; ?>" style="background-image: url(<?php echo $nxs_plurl; ?>img/pk-bg.png); background-position:90% 10%;"> <input type="hidden" name="apDoSPK<?php echo $ii; ?>" value="0" id="apDoSPK<?php echo $ii; ?>" />
71
+ <?php if ($isNew) { ?> <input type="hidden" name="pk[<?php echo $ii; ?>][apDoPK]" value="1" id="apDoNewPK<?php echo $ii; ?>" /> <?php } ?>
72
+
73
+ <div class="nsx_iconedTitle" style="float: right; background-image: url(<?php echo $nxs_plurl; ?>img/pk16.png);"><a style="font-size: 12px;" target="_blank" href="http://www.nextscripts.com/setup-installation-plurk-social-networks-auto-poster-wordpress/"><?php $nType="Plurk"; printf( __( 'Detailed %s Installation/Configuration Instructions', 'nxs_snap' ), $nType); ?></a></div>
74
+
75
+ <div style="width:100%;"><strong><?php _e('Account Nickname', 'nxs_snap'); ?>:</strong> <i><?php _e('Just so you can easely identify it', 'nxs_snap'); ?></i> </div><input name="pk[<?php echo $ii; ?>][nName]" id="pknName<?php echo $ii; ?>" style="font-weight: bold; color: #005800; border: 1px solid #ACACAC; width: 40%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['nName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /><br/>
76
+ <?php echo nxs_addQTranslSel('pk', $ii, $options['qTLng']); ?><?php echo nxs_addPostingDelaySel('pk', $ii, $options['nHrs'], $options['nMin']); ?>
77
+
78
+ <?php if (!$isNew) { ?>
79
+ <div style="width:100%;"><strong><?php _e('Categories', 'nxs_snap'); ?>:</strong>
80
+ <input value="0" id="catSelA<?php echo $ii; ?>" type="radio" name="pk[<?php echo $ii; ?>][catSel]" <?php if ((int)$options['catSel'] != 1) echo "checked"; ?> /> All
81
+ <input value="1" id="catSelSPK<?php echo $ii; ?>" type="radio" name="pk[<?php echo $ii; ?>][catSel]" <?php if ((int)$options['catSel'] == 1) echo "checked"; ?> /> <a href="#" style="text-decoration: none;" class="showCats" id="nxs_SCA_PK<?php echo $ii; ?>" onclick="jQuery('#catSelSPK<?php echo $ii; ?>').attr('checked', true); jQuery('#tmpCatSelNT').val('PK<?php echo $ii; ?>'); nxs_markCats( jQuery('#nxs_SC_PK<?php echo $ii; ?>').val() ); jQuery('#showCatSel').bPopup({ modalClose: false, appendTo: '#nsStForm', opacity: 0.6, follow: [false, false], position: [75, 'auto']}); return false;">Selected<?php if ($options['catSelEd']!='') echo "[".(substr_count($options['catSelEd'], ",")+1)."]"; ?></a>
82
+ <input type="hidden" name="pk[<?php echo $ii; ?>][catSelEd]" id="nxs_SC_PK<?php echo $ii; ?>" value="<?php echo $options['catSelEd']; ?>" />
83
+ <br/><i><?php _e('Only selected categories will be autoposted to this account', 'nxs_snap'); ?></i></div>
84
+ <br/>
85
+ <?php } ?>
86
+
87
+ <div style="width:100%;"><strong>Your Plurk URL:</strong> </div><input onchange="nxsPKURLVal(<?php echo $ii; ?>);" name="pk[<?php echo $ii; ?>][apPKURL]" id="apPKURL<?php echo $ii; ?>" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['pkURL'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /><span style="color: #F00000;" id="apPKURLerr<?php echo $ii; ?>"></span>
88
+ <div style="width:100%;"><strong>Your Plurk App Key:</strong> </div><input name="pk[<?php echo $ii; ?>][apPKConsKey]" id="apPKConsKey" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['pkConsKey'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
89
+ <div style="width:100%;"><strong>Your Plurk App Secret:</strong> </div><input name="pk[<?php echo $ii; ?>][apPKConsSec]" id="apPKConsSec" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['pkConsSec'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
90
+ <br/><br/>
91
+
92
+ <div id="altFormat" style="">
93
+ <div style="width:100%;"><strong id="altFormatText">Plurk prefix:</strong> </div>
94
+
95
+ <select name="pk[<?php echo $ii; ?>][Cat]" id="pkCat<?php echo $ii; ?>">
96
+ <?php $pkCats = $this->pkCats();
97
+ if (isset($options['pkCat']) && $options['pkCat']!='') $pkCats = str_replace($options['pkCat'].'"', $options['pkCat'].'" selected="selected"', $pkCats); echo $pkCats;
98
+ ?>
99
+ </select>
100
+ </div>
101
+ <br/>
102
+ <p style="margin: 0px;"><input value="1" id="apLIAttch" type="checkbox" name="pk[<?php echo $ii; ?>][attchImg]" <?php if ((int)$options['attchImg'] == 1) echo "checked"; ?> /> <strong>Attach Image to Plurk Post</strong></p>
103
+ <br/>
104
+
105
+ <div style="width:100%;"><strong id="altFormatText"><?php _e('Post Text Format', 'nxs_snap'); ?>:</strong> (<a href="#" id="apPKMsgFrmt<?php echo $ii; ?>HintInfo" onclick="mxs_showHideFrmtInfo('apPKMsgFrmt<?php echo $ii; ?>'); return false;"><?php _e('Show format info', 'nxs_snap'); ?></a>) </div>
106
+
107
+ <textarea cols="150" rows="3" id="pk<?php echo $ii; ?>SNAPformat" name="pk[<?php echo $ii; ?>][apPKMsgFrmt]" style="width:51%;max-width: 650px;" onfocus="jQuery('#pk<?php echo $ii; ?>SNAPformat').attr('rows', 6); mxs_showFrmtInfo('apPKMsgFrmt<?php echo $ii; ?>');"><?php if ($options['pkMsgFormat']!='') _e(apply_filters('format_to_edit', htmlentities($options['pkMsgFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap'); else echo htmlentities("%TITLE% - %URL%"); ?></textarea>
108
+
109
+ <br/>
110
+ <?php nxs_doShowHint("apPKMsgFrmt".$ii); ?>
111
+ <br/>
112
+ <?php
113
+ if($options['pkConsSec']=='') { ?>
114
+ <b>Authorize Your Plurk Account</b>. Please save your settings and come back here to Authorize your account.
115
+ <?php } else { if(isset($options['pkAccessTocken']) && isset($options['pkAccessTocken']['oauth_token_secret']) && $options['pkAccessTocken']['oauth_token_secret']!=='') { ?>
116
+ Your Plurk Account has been authorized. Your display name: <?php _e(apply_filters('format_to_edit', htmlentities($options['pkPgID'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>.
117
+ You can Re- <?php } ?>
118
+ <a href="<?php echo $nxs_snapThisPageUrl;?>&auth=pk&acc=<?php echo $ii; ?>">Authorize Your Plurk Account</a>
119
+ <?php if (!isset($options['pkOAuthTokenSecret']) || $options['pkOAuthTokenSecret']=='') { ?> <div class="blnkg">&lt;=== Authorize your account ===</div> <?php } ?>
120
+ <?php } ?>
121
+
122
+
123
+ <?php if( isset($options['pkOAuthTokenSecret']) && $options['pkOAuthTokenSecret']!='') { ?>
124
+ <?php wp_nonce_field( 'rePostToPK', 'rePostToPK_wpnonce' ); ?>
125
+ <br/><br/><b><?php _e('Test your settings', 'nxs_snap'); ?>:</b>&nbsp;&nbsp;&nbsp; <a href="#" class="NXSButton" onclick="testPost('PK', '<?php echo $ii; ?>'); return false;"><?php printf( __( 'Submit Test Post to %s', 'nxs_snap' ), $nType); ?></a> <br/><br/>
126
+ <?php }?>
127
+ <div class="submit"><input type="submit" class="button-primary" name="update_NS_SNAutoPoster_settings" value="<?php _e('Update Settings', 'nxs_snap') ?>" /></div>
128
+
129
+ </div>
130
+ <?php
131
+
132
+
133
+ }
134
+ //#### Set Unit Settings from POST
135
+ function setNTSettings($post, $options){ global $nxs_snapThisPageUrl; //prr($post); die();
136
+ foreach ($post as $ii => $pval){ // prr($pval);
137
+ if (isset($pval['apPKConsKey']) && $pval['apPKConsSec']!='') { if (!isset($options[$ii])) $options[$ii] = array();
138
+
139
+ if (isset($pval['apPKURL'])) { $options[$ii]['pkURL'] = trim($pval['apPKURL']); if ( substr($options[$ii]['pkURL'], 0, 4)!='http' ) $options[$ii]['pkURL'] = 'http://'.$options[$ii]['pkURL'];
140
+ $pkPgID = $options[$ii]['pkURL']; if (substr($pkPgID, -1)=='/') $pkPgID = substr($pkPgID, 0, -1); $pkPgID = substr(strrchr($pkPgID, "/"), 1);
141
+ $options[$ii]['pkPgID'] = $pkPgID; //echo $fbPgID;
142
+ }
143
+ if (isset($pval['apDoPK'])) $options[$ii]['doPK'] = $pval['apDoPK']; else $options[$ii]['doPK'] = 0;
144
+ if (isset($pval['nName'])) $options[$ii]['nName'] = trim($pval['nName']);
145
+ if (isset($pval['apPKConsKey'])) $options[$ii]['pkConsKey'] = trim($pval['apPKConsKey']);
146
+ if (isset($pval['apPKConsSec'])) $options[$ii]['pkConsSec'] = trim($pval['apPKConsSec']);
147
+
148
+ if (isset($pval['catSel'])) $options[$ii]['catSel'] = trim($pval['catSel']);
149
+ if ($options[$ii]['catSel']=='1' && trim($pval['catSelEd'])!='') $options[$ii]['catSelEd'] = trim($pval['catSelEd']); else $options[$ii]['catSelEd'] = '';
150
+
151
+ if (isset($pval['apPKMsgFrmt'])) $options[$ii]['pkMsgFormat'] = trim($pval['apPKMsgFrmt']);
152
+ if (isset($pval['Cat'])) $options[$ii]['pkCat'] = $pval['Cat']; else $options[$ii]['pkCat'] = "";
153
+ if (isset($pval['attchImg'])) $options[$ii]['attchImg'] = $pval['attchImg']; else $options[$ii]['attchImg'] = 0;
154
+ if (isset($pval['delayHrs'])) $options[$ii]['nHrs'] = trim($pval['delayHrs']); if (isset($pval['delayMin'])) $options[$ii]['nMin'] = trim($pval['delayMin']);
155
+ if (isset($pval['qTLng'])) $options[$ii]['qTLng'] = trim($pval['qTLng']);
156
+ } // prr($options);
157
+ } return $options;
158
+ }
159
+ //#### Show Post->Edit Meta Box Settings
160
+ function showEdPostNTSettings($ntOpts, $post){ global $nxs_plurl; $post_id = $post->ID;
161
+ foreach($ntOpts as $ii=>$options) {$pMeta = maybe_unserialize(get_post_meta($post_id, 'snapPK', true)); if (is_array($pMeta)) $options = $this->adjMetaOpt($options, $pMeta[$ii]);
162
+ $doPK = $options['doPK'] && (is_array($pMeta) || $options['catSel']!='1');
163
+ $isAvailPK = isset($options['pkAccessTocken']) && isset($options['pkAccessTocken']['oauth_token_secret']) && $options['pkAccessTocken']['oauth_token_secret']!=='';
164
+ $pkMsgFormat = htmlentities($options['pkMsgFormat'], ENT_COMPAT, "UTF-8"); $pkMsgTFormat = htmlentities($options['pkMsgTFormat'], ENT_COMPAT, "UTF-8");
165
+ ?>
166
+
167
+ <tr><th style="text-align:left;" colspan="2"><?php if ( $options['catSel']=='1' && trim($options['catSelEd'])!='' ) { ?> <input type="hidden" class="nxs_SC" id="nxs_SC_PK<?php echo $ii; ?>" value="<?php echo $options['catSelEd']; ?>" /> <?php } ?>
168
+ <?php if ($isAvailPK) { ?><input class="nxsGrpDoChb" value="1" id="doPK<?php echo $ii; ?>" <?php if ($post->post_status == "publish") echo 'disabled="disabled"';?> type="checkbox" name="pk[<?php echo $ii; ?>][doPK]" <?php if ((int)$doPK == 1) echo 'checked="checked" title="def"'; ?> />
169
+ <?php if ($post->post_status == "publish") { ?> <input type="hidden" name="pk[<?php echo $ii; ?>][doPK]" value="<?php echo $doPK;?>"> <?php } ?> <?php } ?>
170
+ <div class="nsx_iconedTitle" style="display: inline; font-size: 13px; background-image: url(<?php echo $nxs_plurl; ?>img/pk16.png);">Plurk - <?php _e('publish to', 'nxs_snap') ?> (<i style="color: #005800;"><?php echo $options['nName']; ?></i>) </div></th><td><?php //## Only show RePost button if the post is "published"
171
+ if ($post->post_status == "publish" && $isAvailPK) { ?><input alt="<?php echo $ii; ?>" style="float: right;" onmouseout="hidePopShAtt('SV');" onmouseover="showPopShAtt('SV', event);" onclick="return false;" type="button" class="button" name="rePostToPK_repostButton" id="rePostToPK_button" value="<?php _e('Repost to Plurk', 'nxs_snap') ?>" />
172
+ <?php wp_nonce_field( 'rePostToPK', 'rePostToPK_wpnonce' ); } ?>
173
+
174
+ <?php if (is_array($pMeta) && is_array($pMeta[$ii]) && isset($pMeta[$ii]['pgID']) ) {
175
+ ?> <span id="pstdPK<?php echo $ii; ?>" style="float: right;padding-top: 4px; padding-right: 10px;">
176
+ <a style="font-size: 10px;" href="http://www.plurk.com/p/<?php echo base_convert($pMeta[$ii]['pgID'], 10, 36); ?>" target="_blank"><?php $nType="Plurk"; printf( __( 'Posted on', 'nxs_snap' ), $nType); ?> <?php echo (isset($pMeta[$ii]['pDate']) && $pMeta[$ii]['pDate']!='')?(" (".$pMeta[$ii]['pDate'].")"):""; ?></a>
177
+ </span><?php } ?>
178
+
179
+ </td></tr>
180
+ <?php if (!$isAvailPK) { ?><tr><th scope="row" style="text-align:right; width:150px; padding-top: 5px; padding-right:10px;"></th> <td><b>Setup and authorize your Plurk Account to AutoPost to Plurk</b>
181
+ <?php }elseif ($post->post_status != "puZblish") { ?>
182
+
183
+ <tr id="altFormat1" style=""><th scope="row" style="text-align:right; width:60px; padding-right:10px;">
184
+ Prefix:
185
+
186
+ </th>
187
+ <td><select name="pk[<?php echo $ii; ?>][Cat]" id="apPKCat<?php echo $ii; ?>">
188
+ <?php $pkCats = $this->pkCats();
189
+ if ($ntOpt['pkCat']!='') $pkCats = str_replace($ntOpt['pkCat'].'"', $ntOpt['pkCat'].'" selected="selected"', $pkCats); echo $pkCats;
190
+
191
+ ?>
192
+ </select></td></tr>
193
+
194
+ <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top:6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Text Format:', 'nxs_snap') ?></th>
195
+ <td>
196
+ <textarea cols="150" rows="1" id="pk<?php echo $ii; ?>SNAPformat" name="pk[<?php echo $ii; ?>][SNAPformat]" style="width:60%;max-width: 610px;" onfocus="jQuery('#pk<?php echo $ii; ?>SNAPformat').attr('rows', 4); jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apPKMsgFrmt<?php echo $ii; ?>');"><?php echo $pkMsgFormat; ?></textarea>
197
+ <?php nxs_doShowHint("apPKMsgFrmt".$ii); ?></td></tr>
198
+
199
+ <?php }
200
+ }
201
+
202
+ }
203
+
204
+ function adjMetaOpt($optMt, $pMeta){ if (isset($pMeta['isPosted'])) $optMt['isPosted'] = $pMeta['isPosted']; else $optMt['isPosted'] = '';
205
+ if (isset($pMeta['SNAPformat'])) $optMt['pkMsgFormat'] = $pMeta['SNAPformat'];
206
+ if (isset($pMeta['Cat'])) $optMt['pkCat'] = $pMeta['Cat'];
207
+ if (isset($pMeta['doPK'])) $optMt['doPK'] = $pMeta['doPK'] == 1?1:0; else { if (isset($pMeta['SNAPformat'])) $optMt['doPK'] = 0; }
208
+ if (isset($pMeta['SNAPincludePK']) && $pMeta['SNAPincludePK'] == '1' ) $optMt['doPK'] = 1;
209
+ return $optMt;
210
+ }
211
+ }}
212
+
213
+ if (!function_exists("nxs_rePostToPK_ajax")) { function nxs_rePostToPK_ajax() { check_ajax_referer('rePostToPK'); $postID = $_POST['id']; // $result = nsPublishTo($id, 'FB', true);
214
+ $options = get_option('NS_SNAutoPoster'); foreach ($options['pk'] as $ii=>$po) if ($ii==$_POST['nid']) { $po['ii'] = $ii; $po['pType'] = 'aj';
215
+ $mpo = get_post_meta($postID, 'snapPK', true); $mpo = maybe_unserialize($mpo);
216
+ if (is_array($mpo) && isset($mpo[$ii]) && is_array($mpo[$ii]) ){ $ntClInst = new nxs_snapClassPK(); $po = $ntClInst->adjMetaOpt($po, $mpo[$ii]); }
217
+ $result = nxs_doPublishToPK($postID, $po); if ($result == 200 || $result == 201) die("Your post has been successfully sent to Plurk."); else { echo $result; die(); }
218
+ }
219
+ }
220
+ }
221
+
222
+ if (!function_exists("nxs_doPublishToPK")) { //## Second Function to Post to TR
223
+ function nxs_doPublishToPK($postID, $options){ $ntCd = 'PK'; $ntCdL = 'pk'; $ntNm = 'Plurk';
224
+ //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToPK', array($postID, $options));
225
+ $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle=='') $blogTitle = home_url();
226
+
227
+ $ii = $options['ii']; if (!isset($options['pType'])) $options['pType'] = 'im'; if ($options['pType']=='sh') sleep(rand(1, 10));
228
+ $logNT = '<span style="color:#014A76">Plurk</span> - '.$options['nName'];
229
+ $snap_ap = get_post_meta($postID, 'snap'.$ntCd, true); $snap_ap = maybe_unserialize($snap_ap);
230
+ if ($options['pType']!='aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
231
+ $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted!='2') { sleep(5);
232
+ nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:'.$postID, 'Already posted. No reason for posting duplicate'.' |'.$uqID); return;
233
+ }
234
+ }
235
+ //## Format
236
+ if ($postID=='0') { echo "Testing ... <br/><br/>"; $msg = 'Test Post from '.$blogTitle; $msgT = 'Test Post from '.$blogTitle;}
237
+ else{ $post = get_post($postID); if(!$post) return; $twMsgFormat = $options['pkMsgFormat']; nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted'=>'1')); $twLim = 180;
238
+ $extInfo = ' | PostID: '.$postID." - ".$post->post_title;
239
+ if (stripos($twMsgFormat, '%URL%')!==false || stripos($twMsgFormat, '%SURL%')!==false) $twLim = $twLim - 5;
240
+ if (stripos($twMsgFormat, '%AUTHORNAME%')!==false) { $aun = $post->post_author; $aun = get_the_author_meta('display_name', $aun ); $twLim = $twLim - strlen($aun); }
241
+
242
+ $noRepl = str_ireplace("%TITLE%", "", $twMsgFormat); $noRepl = str_ireplace("%SITENAME%", "", $noRepl); $noRepl = str_ireplace("%URL%", "", $noRepl);$noRepl = str_ireplace("%RAWEXCERPT%", "", $noRepl);
243
+ $noRepl = str_ireplace("%SURL%", "", $noRepl);$noRepl = str_ireplace("%TEXT%", "", $noRepl);$noRepl = str_ireplace("%FULLTEXT%", "", $noRepl);$noRepl = str_ireplace("%EXCERPT%", "", $noRepl);
244
+ $noRepl = str_ireplace("%ANNOUNCE%", "", $noRepl); $noRepl = str_ireplace("%AUTHORNAME%", "", $noRepl); $twLim = $twLim - strlen($noRepl);
245
+
246
+ $pTitle = $title = $post->post_title;
247
+ if ($post->post_excerpt!="") $pText = apply_filters('the_content', $post->post_excerpt); else $pText= apply_filters('the_content', $post->post_content);
248
+ $pFullText = apply_filters('the_content', $post->post_content);
249
+ $pRawText = $post->post_content;
250
+
251
+
252
+ if (stripos($twMsgFormat, '%TITLE%')!==false) {
253
+ $pTitle = nsTrnc($pTitle, $twLim); $twMsgFormat = str_ireplace("%TITLE%", $pTitle, $twMsgFormat); $twLim = $twLim - strlen($pTitle);
254
+ }
255
+ if (stripos($twMsgFormat, '%SITENAME%')!==false) {
256
+ $siteTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); $siteTitle = nsTrnc($siteTitle, $twLim); $twMsgFormat = str_ireplace("%SITENAME%", $siteTitle, $twMsgFormat); $twLim = $twLim - strlen($siteTitle);
257
+ }
258
+ if (stripos($twMsgFormat, '%EXCERPT%')!==false) {
259
+ $pText = nsTrnc(strip_tags(strip_shortcodes($pText)), 300, " ", "...");
260
+ $pText = nsTrnc($pText, $twLim); $twMsgFormat = str_ireplace("%EXCERPT%", $pText, $twMsgFormat); $twLim = $twLim - strlen($pText);
261
+ }
262
+ if (stripos($twMsgFormat, '%FULLTEXT%')!==false) {
263
+ $pFullText = nsTrnc(strip_tags($pFullText), $twLim); $twMsgFormat = str_ireplace("%FULLTEXT%", $pFullText, $twMsgFormat); $twLim = $twLim - strlen($pFullText);
264
+ }
265
+ if (stripos($twMsgFormat, '%RAWTEXT%')!==false) {
266
+ $pRawText = nsTrnc(strip_tags($pRawText), $twLim); $twMsgFormat = str_ireplace("%FULLTEXT%", $pRawText, $twMsgFormat); $twLim = $twLim - strlen($pRawText);
267
+ }
268
+
269
+ $msg = nsFormatMessage($twMsgFormat, $postID);
270
+
271
+ }
272
+ //## Post
273
+ require_once('apis/plurkOAuth.php'); $consumer_key = $options['pkConsKey']; $consumer_secret = $options['pkConsSec'];
274
+ $tum_oauth = new wpPlurkOAuth($consumer_key, $consumer_secret, $options['pkAccessTocken'], $options['pkAccessTockenSec']);
275
+ $pkURL = trim(str_ireplace('http://', '', $options['pkURL'])); if (substr($pkURL,-1)=='/') $pkURL = substr($pkURL,0,-1);
276
+ if ($options['pkCat']=='')$options['pkCat'] = ':';
277
+
278
+ if ($options['attchImg']=='1') { $imgURL = nxs_getPostImage($postID); $msg .= " ".$imgURL; }
279
+
280
+ $postDate = ($post->post_date_gmt!='0000-00-00 00:00:00'?$post->post_date_gmt:gmdate("Y-m-d H:i:s", strtotime($post->post_date)))." GMT"; //## Adds date to Tumblr post. Thanks to Kenneth Lecky
281
+
282
+ $postArr = array('content'=>$msg, 'qualifier'=>$options['pkCat']);
283
+ $postinfo = $tum_oauth->makeReq('http://www.plurk.com/APP/Timeline/plurkAdd', $postArr); // prr($postinfo);
284
+ if (is_array($postinfo) && isset($postinfo['plurk_id'])) $pkID = $postinfo['plurk_id'];
285
+
286
+ $code = $tum_oauth->http_code;// echo "XX".print_r($code); prr($postinfo); // prr($msg); prr($postinfo); echo $code."VVVV"; die("|====");
287
+ if ($code == 200) { if ($postID=='0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo 'OK - Message Posted, please see your Plurk Page. <br/> Result:'; }
288
+ else { nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); nxs_metaMarkAsPosted($postID, 'PK', $options['ii'], array('isPosted'=>'1', 'pgID'=>$pkID, 'pDate'=>date('Y-m-d H:i:s'))); } }
289
+ else { nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.print_r($postinfo, true), $extInfo); if ($postID=='0') prr($postinfo); $code .= " ERROR: - ".$postinfo['error_text']; }
290
+
291
+ return $code;
292
+ }
293
+ }
294
+
295
  ?>
inc-cl/pn.php CHANGED
@@ -1,212 +1,223 @@
1
- <?php
2
- //## NextScripts Facebook Connection Class
3
- $nxs_snapAvNts[] = array('code'=>'PN', 'lcode'=>'pn', 'name'=>'Pinterest');
4
-
5
- if (!class_exists("nxs_snapClassPN")) { class nxs_snapClassPN {
6
- //#### Show Common Settings
7
- function showGenNTSettings($ntOpts){ global $nxs_plurl; $ntInfo = array('code'=>'PN', 'lcode'=>'pn', 'name'=>'Pinterest', 'defNName'=>'pnUName', 'tstReq' => false); ?>
8
- <div class="nxs_box">
9
- <div class="nxs_box_header">
10
- <div class="nsx_iconedTitle" style="margin-bottom:1px;background-image:url(<?php echo $nxs_plurl;?>img/<?php echo $ntInfo['lcode']; ?>16.png);"><?php echo $ntInfo['name']; ?>
11
- <?php $cbo = count($ntOpts); ?> <?php wp_nonce_field( 'ns'.$ntInfo['code'], 'ns'.$ntInfo['code'].'_wpnonce' ); ?>
12
- <?php if ($cbo>1){ ?><div class="nsBigText"><?php echo "(".($cbo=='0'?'No':$cbo)." "; _e('accounts', 'nxs_snap'); echo ")"; ?></div><?php } ?>
13
- </div>
14
- </div>
15
- <div class="nxs_box_inside">
16
- <?php if(!function_exists('doPostToPinterest')) {?> Pinterest doesn't have a built-in API for automated posts yet. <br/>You need to get a special <a target="_blank" href="http://www.nextscripts.com/pinterest-automated-posting">library module</a> to be able to publish your content to Pinterest.
17
- <?php } else foreach ($ntOpts as $indx=>$pbo){ if (trim($pbo['nName']=='')) $pbo['nName'] = $pbo[$ntInfo['defNName']]; ?>
18
- <p style="margin:0px;margin-left:5px;">
19
- <input value="1" name="<?php echo $ntInfo['lcode']; ?>[<?php echo $indx; ?>][apDo<?php echo $ntInfo['code']; ?>]" onchange="doShowHideBlocks('<?php echo $ntInfo['code']; ?>');" type="checkbox" <?php if ((int)$pbo['do'.$ntInfo['code']] == 1) echo "checked"; ?> /> <?php if ((int)$pbo['catSel'] == 1) { ?> <span onmouseout="nxs_hidePopUpInfo('popOnlyCat');" onmouseover="nxs_showPopUpInfo('popOnlyCat', event);"><?php echo "*[".(substr_count($pbo['catSelEd'], ",")+1)."]*" ?></span><?php } ?>
20
- <strong><?php _e('Auto-publish to', 'nxs_snap'); ?> <?php echo $ntInfo['name']; ?> <i style="color: #005800;"><?php if($pbo['nName']!='') echo "(".$pbo['nName'].")"; ?></i></strong>
21
- &nbsp;&nbsp;<?php if ($ntInfo['tstReq'] && (!isset($pbo[$ntInfo['lcode'].'OK']) || $pbo[$ntInfo['lcode'].'OK']=='')){ ?><b style="color: #800000"><?php _e('Attention requred. Unfinished setup', 'nxs_snap'); ?> ==&gt;</b><?php } ?><a id="do<?php echo $ntInfo['code'].$indx; ?>A" href="#" onclick="doShowHideBlocks2('<?php echo $ntInfo['code'].$indx; ?>');return false;">[<?php _e('Show Settings', 'nxs_snap'); ?>]</a>&nbsp;&nbsp;
22
- <a href="#" onclick="doDelAcct('<?php echo $ntInfo['lcode']; ?>', '<?php echo $indx; ?>', '<?php if (isset($pbo['bgBlogID'])) echo $pbo['nName']; ?>');return false;">[<?php _e('Remove Account', 'nxs_snap'); ?>]</a>
23
- </p><?php $this->showNTSettings($indx, $pbo);
24
- } ?>
25
- </div>
26
- </div> <?php
27
- }
28
- //#### Show NEW Settings Page
29
- function showNewNTSettings($mgpo){ $po = array('nName'=>'', 'doPN'=>'1', 'pnUName'=>'', 'pnBoard'=>'', 'gpAttch'=>'', 'pnPass'=>'', 'pnDefImg'=>'', 'pnMsgFormat'=>'', 'pnBoard'=>'', 'pnBoardsList'=>'', 'doPN'=>1); $this->showNTSettings($mgpo, $po, true);}
30
- //#### Show Unit Settings
31
- function showNTSettings($ii, $options, $isNew=false){ global $nxs_plurl; ?>
32
- <div id="doPN<?php echo $ii; ?>Div" class="insOneDiv<?php if ($isNew) echo " clNewNTSets"; ?>" style="background-image: url(<?php echo $nxs_plurl; ?>img/pn-bg.png); background-position:90% 10%;"> <input type="hidden" name="apDoSPN<?php echo $ii; ?>" value="0" id="apDoSPN<?php echo $ii; ?>" />
33
-
34
- <?php if(!function_exists('doPostToPinterest')) {?><span style="color:#580000; font-size: 16px;"><br/><br/>
35
- <b>Pinterest API Library not found</b>
36
- <br/><br/> Pinterest doesn't have a built-in API for automated posts yet. <br/><br/>You need to get a special <a target="_blank" href="http://www.nextscripts.com/pinterest-automated-posting"><b>API Library Module</b></a> to be able to publish your content to Pinterest.</span></div>
37
-
38
- <?php return; }; ?>
39
-
40
-
41
- <div id="doPN<?php echo $ii; ?>Div" style="margin-left: 10px;"> <div class="nsx_iconedTitle" style="float: right; background-image: url(<?php echo $nxs_plurl; ?>img/pn16.png);"><a style="font-size: 12px;" target="_blank" href="http://www.nextscripts.com/setup-installation-pinterest-social-networks-auto-poster-wordpress/"><?php $nType="Pinterest"; printf( __( 'Detailed %s Installation/Configuration Instructions', 'nxs_snap' ), $nType); ?></a></div>
42
- <div style="width:100%;"><strong><?php _e('Account Nickname', 'nxs_snap'); ?>:</strong> <i><?php _e('Just so you can easely identify it', 'nxs_snap'); ?></i> </div><input name="pn[<?php echo $ii; ?>][nName]" id="pnnName<?php echo $ii; ?>" style="font-weight: bold; color: #005800; border: 1px solid #ACACAC; width: 40%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['nName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /><br/>
43
- <?php echo nxs_addQTranslSel('pn', $ii, $options['qTLng']); ?><?php echo nxs_addPostingDelaySel('pn', $ii, $options['nHrs'], $options['nMin']); ?>
44
-
45
- <?php if (!$isNew) { ?>
46
- <div style="width:100%;"><strong><?php _e('Categories', 'nxs_snap'); ?>:</strong>
47
- <input value="0" id="catSelA<?php echo $ii; ?>" type="radio" name="pn[<?php echo $ii; ?>][catSel]" <?php if ((int)$options['catSel'] != 1) echo "checked"; ?> /> All
48
- <input value="1" id="catSelSPN<?php echo $ii; ?>" type="radio" name="pn[<?php echo $ii; ?>][catSel]" <?php if ((int)$options['catSel'] == 1) echo "checked"; ?> /> <a href="#" style="text-decoration: none;" class="showCats" id="nxs_SCA_PN<?php echo $ii; ?>" onclick="jQuery('#catSelSPN<?php echo $ii; ?>').attr('checked', true); jQuery('#tmpCatSelNT').val('PN<?php echo $ii; ?>'); nxs_markCats( jQuery('#nxs_SC_PN<?php echo $ii; ?>').val() ); jQuery('#showCatSel').bPopup({ modalClose: false, appendTo: '#nsStForm', opacity: 0.6, follow: [false, false], position: [75, 'auto']}); return false;">Selected<?php if ($options['catSelEd']!='') echo "[".(substr_count($options['catSelEd'], ",")+1)."]"; ?></a>
49
- <input type="hidden" name="pn[<?php echo $ii; ?>][catSelEd]" id="nxs_SC_PN<?php echo $ii; ?>" value="<?php echo $options['catSelEd']; ?>" />
50
- <br/><i><?php _e('Only selected categories will be autoposted to this account', 'nxs_snap'); ?></i></div>
51
- <br/>
52
- <?php } ?>
53
-
54
- <div style="width:100%;"><strong>Pinterest Email:</strong> </div><input name="pn[<?php echo $ii; ?>][apPNUName]" id="apPNUName<?php echo $ii; ?>" class="apPNUName<?php echo $ii; ?>" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['pnUName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
55
- <div style="width:100%;"><strong>Pinterest Password:</strong> </div><input name="pn[<?php echo $ii; ?>][apPNPass]" id="apPNPass<?php echo $ii; ?>" type="password" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities(substr($options['pnPass'], 0, 5)=='g9c1a'?nsx_doDecode(substr($options['pnPass'], 5)):$options['pnPass'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /> <br/>
56
- <div style="width:100%;"><strong>Default Image to Pin:</strong>
57
- <p style="font-size: 11px; margin: 0px;">If your post missing Featured Image this will be used instead.</p>
58
- </div><input name="pn[<?php echo $ii; ?>][apPNDefImg]" id="apPNDefImg" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['pnDefImg'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
59
- <br/><br/>
60
-
61
- <div style="width:100%;"><strong>Board:</strong>
62
- Please <a href="#" onclick="getBoards(jQuery('<?php if ($isNew) echo "#nsx_addNT "; ?>#apPNUName<?php echo $ii; ?>').val(),jQuery('<?php if ($isNew) echo "#nsx_addNT "; ?>#apPNPass<?php echo $ii; ?>').val(), '<?php echo $ii; ?>'); return false;">click here to retrieve your boards</a>
63
- </div>
64
- <?php wp_nonce_field( 'getBoards', 'getBoards_wpnonce' ); ?><img id="pnLoadingImg<?php echo $ii; ?>" style="display: none;" src='<?php echo $nxs_plurl; ?>img/ajax-loader-sm.gif' />
65
- <select name="pn[<?php echo $ii; ?>][apPNBoard]" id="apPNBoard<?php echo $ii; ?>">
66
- <?php if ($options['pnBoardsList']!=''){ $gPNBoards = $options['pnBoardsList']; if ( base64_encode(base64_decode($gPNBoards)) === $gPNBoards) $gPNBoards = base64_decode($gPNBoards);
67
- if ($options['pnBoard']!='') $gPNBoards = str_replace($options['pnBoard'].'"', $options['pnBoard'].'" selected="selected"', $gPNBoards); echo $gPNBoards;} else { ?>
68
- <option value="0">None(Click above to retrieve your boards)</option>
69
- <?php } ?>
70
- </select>
71
-
72
- <br/><br/>
73
-
74
-
75
- <div id="altFormat" style="">
76
- <div style="width:100%;"><strong id="altFormatText"><?php _e('Message text Format', 'nxs_snap'); ?>:</strong> <a href="#" id="apPNMsgFrmt<?php echo $ii; ?>HintInfo" onclick="mxs_showHideFrmtInfo('apPNMsgFrmt<?php echo $ii; ?>'); return false;"><?php _e('Show format info', 'nxs_snap'); ?></a>
77
- </div>
78
-
79
- <textarea cols="150" rows="3" id="pn<?php echo $ii; ?>SNAPformat" name="pn[<?php echo $ii; ?>][apPNMsgFrmt]" style="width:51%;max-width: 650px;" onfocus="jQuery('#pn<?php echo $ii; ?>SNAPformat').attr('rows', 6); mxs_showFrmtInfo('apPNMsgFrmt<?php echo $ii; ?>');"><?php if ($options['pnMsgFormat']!='') _e(apply_filters('format_to_edit', htmlentities($options['pnMsgFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap'); else echo "%TITLE% - %URL%"; ?></textarea>
80
-
81
- <?php nxs_doShowHint("apPNMsgFrmt".$ii); ?>
82
- </div><br/>
83
- <?php if ($isNew) { ?> <input type="hidden" name="pn[<?php echo $ii; ?>][apDoPN]" value="1" id="apDoNewPN<?php echo $ii; ?>" /> <?php } ?>
84
- <?php if ($options['pnPass']!='') { ?>
85
- <?php wp_nonce_field( 'rePostToPN', 'rePostToPN_wpnonce' ); ?>
86
- <b><?php _e('Test your settings', 'nxs_snap'); ?>:</b>&nbsp;&nbsp;&nbsp; <a href="#" class="NXSButton" onclick="testPost('PN', '<?php echo $ii; ?>'); return false;"><?php printf( __( 'Submit Test Post to %s', 'nxs_snap' ), $nType); ?></a>
87
- <?php } ?>
88
-
89
- <div class="submit"><input type="submit" class="button-primary" name="update_NS_SNAutoPoster_settings" value="<?php _e('Update Settings', 'nxs_snap') ?>" /></div>
90
- </div>
91
- </div>
92
- <?php
93
- }
94
- //#### Set Unit Settings from POST
95
- function setNTSettings($post, $options){ global $nxs_snapThisPageUrl;// $code = 'PN'; $lcode = 'pn';
96
- foreach ($post as $ii => $pval){
97
- if (isset($pval['apPNUName']) && $pval['apPNUName']!=''){ if (!isset($options[$ii])) $options[$ii] = array();
98
- if (isset($pval['apDoPN'])) $options[$ii]['doPN'] = $pval['apDoPN']; else $options[$ii]['doPN'] = 0;
99
- if (isset($pval['nName'])) $options[$ii]['nName'] = trim($pval['nName']);
100
- if (isset($pval['apPNUName'])) $options[$ii]['pnUName'] = trim($pval['apPNUName']);
101
- if (isset($pval['apPNPass'])) $options[$ii]['pnPass'] = 'g9c1a'.nsx_doEncode($pval['apPNPass']); else $options[$ii]['pnPass'] = '';
102
- if (isset($pval['apPNBoard'])) $options[$ii]['pnBoard'] = trim($pval['apPNBoard']);
103
- if (isset($pval['apPNDefImg'])) $options[$ii]['pnDefImg'] = trim($pval['apPNDefImg']);
104
-
105
- if (isset($pval['catSel'])) $options[$ii]['catSel'] = trim($pval['catSel']);
106
- if ($options[$ii]['catSel']=='1' && trim($pval['catSelEd'])!='') $options[$ii]['catSelEd'] = trim($pval['catSelEd']); else $options[$ii]['catSelEd'] = '';
107
-
108
- if (isset($pval['apPNMsgFrmt'])) $options[$ii]['pnMsgFormat'] = trim($pval['apPNMsgFrmt']);
109
- if (isset($pval['delayHrs'])) $options[$ii]['nHrs'] = trim($pval['delayHrs']); if (isset($pval['delayMin'])) $options[$ii]['nMin'] = trim($pval['delayMin']);
110
- if (isset($pval['qTLng'])) $options[$ii]['qTLng'] = trim($pval['qTLng']);
111
- }
112
- } return $options;
113
- }
114
- //#### Show Post->Edit Meta Box Settings
115
- function showEdPostNTSettings($ntOpts, $post){ global $nxs_plurl; $post_id = $post->ID;
116
- foreach($ntOpts as $ii=>$ntOpt) { $pMeta = maybe_unserialize(get_post_meta($post_id, 'snapPN', true)); if (is_array($pMeta)) $ntOpt = $this->adjMetaOpt($ntOpt, $pMeta[$ii]);
117
- $doPN = $ntOpt['doPN'] && (is_array($pMeta) || $ntOpt['catSel']!='1');
118
- $isAvailPN = $ntOpt['pnUName']!='' && $ntOpt['pnPass']!=''; $pnMsgFormat = htmlentities($ntOpt['pnMsgFormat'], ENT_COMPAT, "UTF-8");
119
- ?>
120
- <tr><th style="text-align:left;" colspan="2"><?php if ( $ntOpt['catSel']=='1' && trim($ntOpt['catSelEd'])!='' ) { ?> <input type="hidden" class="nxs_SC" id="nxs_SC_PN<?php echo $ii; ?>" value="<?php echo $ntOpt['catSelEd']; ?>" /> <?php } ?>
121
- <?php if ($isAvailPN) { ?><input class="nxsGrpDoChb" value="1" id="doPN<?php echo $ii; ?>" <?php if ($post->post_status == "publish") echo 'disabled="disabled"';?> type="checkbox" name="pn[<?php echo $ii; ?>][doPN]" <?php if ((int)$doPN == 1) echo 'checked="checked" title="def"'; ?> />
122
- <?php if ($post->post_status == "publish") { ?> <input type="hidden" name="pn[<?php echo $ii; ?>][doPN]" value="<?php echo $doPN;?>"> <?php } ?> <?php } ?>
123
- <div class="nsx_iconedTitle" style="display: inline; font-size: 13px; background-image: url(<?php echo $nxs_plurl; ?>img/pn16.png);">Pinterest - <?php _e('publish to', 'nxs_snap') ?> (<i style="color: #005800;"><?php echo $ntOpt['nName']; ?></i>)</div></th> <td><?php //## Only show RePost button if the post is "published"
124
- if ($post->post_status == "publish" && $isAvailPN) { ?><input alt="<?php echo $ii; ?>" style="float: right;" onmouseout="hidePopShAtt('SV');" onmouseover="showPopShAtt('SV', event);" onclick="return false;" type="button" class="button" name="rePostToPN_repostButton" id="rePostToPN_button" value="<?php _e('Repost to Pinterest', 'nxs_snap') ?>" />
125
- <?php wp_nonce_field( 'rePostToPN', 'rePostToPN_wpnonce' ); } ?>
126
-
127
- <?php if (is_array($pMeta) && is_array($pMeta[$ii]) && isset($pMeta[$ii]['pgID']) ) {
128
- ?> <span id="pstdPN<?php echo $ii; ?>" style="float: right;padding-top: 4px; padding-right: 10px;">
129
- <a style="font-size: 10px;" href="http://pinterest.com<?php echo $pMeta[$ii]['pgID']; ?>" target="_blank"><?php $nType="Pinterest"; printf( __( 'Posted on', 'nxs_snap' ), $nType); ?> <?php echo (isset($pMeta[$ii]['pDate']) && $pMeta[$ii]['pDate']!='')?(" (".$pMeta[$ii]['pDate'].")"):""; ?></a>
130
- </span><?php } ?>
131
-
132
- </td></tr>
133
-
134
- <?php if (!$isAvailPN) { ?><tr><th scope="row" style="text-align:right; width:150px; padding-top: 5px; padding-right:10px;"></th> <td><b>Setup your Pinterest Account to AutoPost to Pinterest</b>
135
- <?php } elseif ($post->post_status != "puZblish") { ?>
136
-
137
- <tr><th scope="row" style="text-align:right; width:150px; padding-top: 5px; padding-right:10px;">Select Board</th>
138
- <td><select name="pn[<?php echo $ii; ?>][apPNBoard]" id="apPNBoard">
139
- <?php if ($ntOpt['pnBoardsList']!=''){ $gPNBoards = $ntOpt['pnBoardsList']; if ( base64_encode(base64_decode($gPNBoards)) === $gPNBoards) $gPNBoards = base64_decode($gPNBoards);
140
- if ($ntOpt['pnBoard']!='') $gPNBoards = str_replace($ntOpt['pnBoard'].'"', $ntOpt['pnBoard'].'" selected="selected"', $gPNBoards); echo $gPNBoards;} else { ?>
141
- <option value="0">None(Click above to retrieve your boards)</option>
142
- <?php } ?>
143
- </select></td>
144
- </tr>
145
-
146
- <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top:6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Text Message Format:', 'nxs_snap') ?></th>
147
- <td>
148
- <textarea cols="150" rows="1" id="pn<?php echo $ii; ?>SNAPformat" name="pn[<?php echo $ii; ?>][SNAPformat]" style="width:60%;max-width: 610px;" onfocus="jQuery('#pn<?php echo $ii; ?>SNAPformat').attr('rows', 4); jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apPNMsgFrmt<?php echo $ii; ?>');"><?php echo $pnMsgFormat; ?></textarea>
149
- <?php nxs_doShowHint("apPNMsgFrmt".$ii); ?></td></tr>
150
-
151
- <?php }
152
- }
153
- }
154
- //#### Save Meta Tags to the Post
155
- function adjMetaOpt($optMt, $pMeta){ if (isset($pMeta['isPosted'])) $optMt['isPosted'] = $pMeta['isPosted']; else $optMt['isPosted'] = '';
156
- if (isset($pMeta['SNAPformat'])) $optMt['pnMsgFormat'] = $pMeta['SNAPformat'];
157
- if (isset($pMeta['doPN'])) $optMt['doPN'] = $pMeta['doPN'] == 1?1:0; else { if (isset($pMeta['SNAPformat'])) $optMt['doPN'] = 0; }
158
- if (isset($pMeta['apPNBoard']) && $pMeta['apPNBoard']!='' && $pMeta['apPNBoard']!='0') $optMt['pnBoard'] = $pMeta['apPNBoard'];
159
- if (isset($pMeta['SNAPincludePN']) && $pMeta['SNAPincludePN'] == '1' ) $optMt['doPN'] = 1;
160
- return $optMt;
161
- }
162
- }}
163
- if (!function_exists("nxs_rePostToPN_ajax")) {
164
- function nxs_rePostToPN_ajax() { check_ajax_referer('rePostToPN'); $postID = $_POST['id']; $options = get_option('NS_SNAutoPoster');
165
- foreach ($options['pn'] as $ii=>$two) if ($ii==$_POST['nid']) { $two['ii'] = $ii; $two['pType'] = 'aj'; //if ($two['gpPageID'].$two['gpUName']==$_POST['nid']) {
166
- $po = get_post_meta($postID, 'snapPN', true); $po = maybe_unserialize($po);// prr($gppo);
167
- if (is_array($po) && isset($po[$ii]) && is_array($po[$ii])){ $ntClInst = new nxs_snapClassPN(); $two = $ntClInst->adjMetaOpt($two, $po[$ii]); }
168
- $result = nxs_doPublishToPN($postID, $two); if ($result == 200) die("Successfully sent your post to Pinterest."); else die($result);
169
- }
170
- }
171
- }
172
-
173
- if (!function_exists("nxs_doPublishToPN")) { //## Second Function to Post to G+
174
- function nxs_doPublishToPN($postID, $options){ global $nxs_gCookiesArr; $ntCd = 'PN'; $ntCdL = 'pn'; $ntNm = 'Pinterest';
175
- // $backtrace = debug_backtrace(); nxs_addToLogN('W', 'Enter', $ntCd, 'I am here - '.$ntCd."|".print_r($backtrace, true), '');
176
- //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToPN', array($postID, $options));
177
- $ii = $options['ii']; if (!isset($options['pType'])) $options['pType'] = 'im'; if ($options['pType']=='sh') sleep(rand(1, 10));
178
- $logNT = '<span style="color:#FA5069">Pinterest</span> - '.$options['nName'];
179
- $snap_ap = get_post_meta($postID, 'snap'.$ntCd, true); $snap_ap = maybe_unserialize($snap_ap);
180
- $isAttachVid = $options['isAttachVid']; $isAttachVid = '1';
181
- if ($options['pType']!='aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
182
- $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted!='2') { sleep(5);
183
- nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:'.$postID, 'Already posted. No reason for posting duplicate'.' |'.$uqID); return;
184
- }
185
- }
186
- $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle=='') $blogTitle = home_url();
187
-
188
- if ($postID=='0') { echo "Testing ... <br/><br/>"; $msg = 'Test Post from '.$blogTitle; $link = home_url();
189
- if ($options['pnDefImg']!='') $imgURL = $options['pnDefImg']; else $imgURL ="http://direct.gtln.us/img/nxs/NextScriptsLogoT.png";
190
- }
191
- else { $post = get_post($postID); if(!$post) return; $pnMsgFormat = $options['pnMsgFormat']; $msg = nsFormatMessage($pnMsgFormat, $postID); $link = get_permalink($postID);
192
- nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted'=>'1')); $imgURL = nxs_getPostImage($postID, 'large', $options['pnDefImg']); //prr($options); echo $imgURL."######"; // echo "WW".$postID."|";
193
- if ($isAttachVid=='1') { $vids = nsFindVidsInPost($post); if (count($vids)>0) { $vidURL = 'http://www.youtube.com/v/'.$vids[0]; $imgURL = 'http://img.youtube.com/vi/'.$vids[0].'/0.jpg'; }}
194
- }
195
- $email = $options['pnUName']; $boardID = $options['pnBoard']; $pass = substr($options['pnPass'], 0, 5)=='g9c1a'?nsx_doDecode(substr($options['pnPass'], 5)):$options['pnPass'];// prr($boardID); prr($_POST); die();
196
- if (isset($options['pnSvC'])) $nxs_gCookiesArr = maybe_unserialize( $options['pnSvC']); $loginError = true;
197
- if (is_array($nxs_gCookiesArr)) $loginError = doCheckPinterest();
198
- $extInfo = ' | PostID: '.$postID." - ".$post->post_title;
199
- if ($loginError!==false) $loginError = doConnectToPinterest($email, $pass); if ($loginError!==false) {echo $loginError; nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.print_r($loginError, true), $extInfo); return "BAD USER/PASS";}
200
- if (serialize($nxs_gCookiesArr)!=$options['pnSvC']) { global $plgn_NS_SNAutoPoster; $gOptions = $plgn_NS_SNAutoPoster->nxs_options; // prr($gOptions['pn']);
201
- if (isset($options['ii']) && $options['ii']!=='') { $gOptions['pn'][$options['ii']]['pnSvC'] = serialize($nxs_gCookiesArr); update_option('NS_SNAutoPoster', $gOptions); }
202
- else foreach ($gOptions['pn'] as $ii=>$gpn) { $result = array_diff($options, $gpn);
203
- if (!is_array($result) || count($result)<1) { $gOptions['pn'][$ii]['pnSvC'] = serialize($nxs_gCookiesArr); update_option('NS_SNAutoPoster', $gOptions); break; }
204
- }
205
- } // echo "PN SET:".$msg."|".$imgURL."|".$link."|".$boardID;
206
- if (preg_match ( '/\$(\d+\.\d+)/', $msg, $matches )) $price = $matches[0];
207
- $ret = doPostToPinterest($msg, $imgURL, $link, $boardID, 'TITLE WHERE IS IT?', $price, $link."/GTH/" ); if ($ret=='OK') $ret = array("code"=>"OK", "post_id"=>'');
208
- if ( (!is_array($ret)) && $ret!='OK') { if ($postID=='0') echo $ret; nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.print_r($ret, true), $extInfo); } else { if ($postID=='0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo 'OK - Message Posted, please see your Pinterest Page'; } else { nxs_metaMarkAsPosted($postID, 'PN', $options['ii'], array('isPosted'=>'1', 'pgID'=>$ret['post_id'], 'pDate'=>date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo);} }
209
- if ($ret['code']=='OK') return 200; else return $ret;
210
- }
211
- }
 
 
 
 
 
 
 
 
 
 
 
212
  ?>
1
+ <?php
2
+ //## NextScripts Facebook Connection Class
3
+ $nxs_snapAvNts[] = array('code'=>'PN', 'lcode'=>'pn', 'name'=>'Pinterest');
4
+
5
+ if (!class_exists("nxs_snapClassPN")) { class nxs_snapClassPN {
6
+ //#### Show Common Settings
7
+ function showGenNTSettings($ntOpts){ global $nxs_plurl; $ntInfo = array('code'=>'PN', 'lcode'=>'pn', 'name'=>'Pinterest', 'defNName'=>'pnUName', 'tstReq' => false); ?>
8
+ <div class="nxs_box">
9
+ <div class="nxs_box_header">
10
+ <div class="nsx_iconedTitle" style="margin-bottom:1px;background-image:url(<?php echo $nxs_plurl;?>img/<?php echo $ntInfo['lcode']; ?>16.png);"><?php echo $ntInfo['name']; ?>
11
+ <?php $cbo = count($ntOpts); ?> <?php wp_nonce_field( 'ns'.$ntInfo['code'], 'ns'.$ntInfo['code'].'_wpnonce' ); ?>
12
+ <?php if ($cbo>1){ ?><div class="nsBigText"><?php echo "(".($cbo=='0'?'No':$cbo)." "; _e('accounts', 'nxs_snap'); echo ")"; ?></div><?php } ?>
13
+ </div>
14
+ </div>
15
+ <div class="nxs_box_inside">
16
+ <?php if(!function_exists('doPostToPinterest')) {?> Pinterest doesn't have a built-in API for automated posts yet. <br/>You need to get a special <a target="_blank" href="http://www.nextscripts.com/pinterest-automated-posting">library module</a> to be able to publish your content to Pinterest.
17
+ <?php } else foreach ($ntOpts as $indx=>$pbo){ if (trim($pbo['nName']=='')) $pbo['nName'] = $pbo[$ntInfo['defNName']]; ?>
18
+ <p style="margin:0px;margin-left:5px;">
19
+ <input value="1" name="<?php echo $ntInfo['lcode']; ?>[<?php echo $indx; ?>][apDo<?php echo $ntInfo['code']; ?>]" onchange="doShowHideBlocks('<?php echo $ntInfo['code']; ?>');" type="checkbox" <?php if ((int)$pbo['do'.$ntInfo['code']] == 1) echo "checked"; ?> /> <?php if ((int)$pbo['catSel'] == 1) { ?> <span onmouseout="nxs_hidePopUpInfo('popOnlyCat');" onmouseover="nxs_showPopUpInfo('popOnlyCat', event);"><?php echo "*[".(substr_count($pbo['catSelEd'], ",")+1)."]*" ?></span><?php } ?>
20
+ <strong><?php _e('Auto-publish to', 'nxs_snap'); ?> <?php echo $ntInfo['name']; ?> <i style="color: #005800;"><?php if($pbo['nName']!='') echo "(".$pbo['nName'].")"; ?></i></strong>
21
+ &nbsp;&nbsp;<?php if ($ntInfo['tstReq'] && (!isset($pbo[$ntInfo['lcode'].'OK']) || $pbo[$ntInfo['lcode'].'OK']=='')){ ?><b style="color: #800000"><?php _e('Attention requred. Unfinished setup', 'nxs_snap'); ?> ==&gt;</b><?php } ?><a id="do<?php echo $ntInfo['code'].$indx; ?>A" href="#" onclick="doShowHideBlocks2('<?php echo $ntInfo['code'].$indx; ?>');return false;">[<?php _e('Show Settings', 'nxs_snap'); ?>]</a>&nbsp;&nbsp;
22
+ <a href="#" onclick="doDelAcct('<?php echo $ntInfo['lcode']; ?>', '<?php echo $indx; ?>', '<?php if (isset($pbo['bgBlogID'])) echo $pbo['nName']; ?>');return false;">[<?php _e('Remove Account', 'nxs_snap'); ?>]</a>
23
+ </p><?php $this->showNTSettings($indx, $pbo);
24
+ } ?>
25
+ </div>
26
+ </div> <?php
27
+ }
28
+ //#### Show NEW Settings Page
29
+ function showNewNTSettings($mgpo){ $po = array('nName'=>'', 'doPN'=>'1', 'pnUName'=>'', 'pnBoard'=>'', 'gpAttch'=>'', 'pnPass'=>'', 'pnDefImg'=>'', 'pnMsgFormat'=>'', 'pnBoard'=>'', 'pnBoardsList'=>'', 'doPN'=>1); $this->showNTSettings($mgpo, $po, true);}
30
+ //#### Show Unit Settings
31
+ function showNTSettings($ii, $options, $isNew=false){ global $nxs_plurl; ?>
32
+ <div id="doPN<?php echo $ii; ?>Div" class="insOneDiv<?php if ($isNew) echo " clNewNTSets"; ?>" style="background-image: url(<?php echo $nxs_plurl; ?>img/pn-bg.png); background-position:90% 10%;"> <input type="hidden" name="apDoSPN<?php echo $ii; ?>" value="0" id="apDoSPN<?php echo $ii; ?>" />
33
+
34
+ <?php if(!function_exists('doPostToPinterest')) {?><span style="color:#580000; font-size: 16px;"><br/><br/>
35
+ <b>Pinterest API Library not found</b>
36
+ <br/><br/> Pinterest doesn't have a built-in API for automated posts yet. <br/><br/>You need to get a special <a target="_blank" href="http://www.nextscripts.com/pinterest-automated-posting"><b>API Library Module</b></a> to be able to publish your content to Pinterest.</span></div>
37
+
38
+ <?php return; }; ?>
39
+
40
+
41
+ <div id="doPN<?php echo $ii; ?>Div" style="margin-left: 10px;"> <div class="nsx_iconedTitle" style="float: right; background-image: url(<?php echo $nxs_plurl; ?>img/pn16.png);"><a style="font-size: 12px;" target="_blank" href="http://www.nextscripts.com/setup-installation-pinterest-social-networks-auto-poster-wordpress/"><?php $nType="Pinterest"; printf( __( 'Detailed %s Installation/Configuration Instructions', 'nxs_snap' ), $nType); ?></a></div>
42
+ <div style="width:100%;"><strong><?php _e('Account Nickname', 'nxs_snap'); ?>:</strong> <i><?php _e('Just so you can easely identify it', 'nxs_snap'); ?></i> </div><input name="pn[<?php echo $ii; ?>][nName]" id="pnnName<?php echo $ii; ?>" style="font-weight: bold; color: #005800; border: 1px solid #ACACAC; width: 40%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['nName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /><br/>
43
+ <?php echo nxs_addQTranslSel('pn', $ii, $options['qTLng']); ?><?php echo nxs_addPostingDelaySel('pn', $ii, $options['nHrs'], $options['nMin'], $options['nDays']); ?>
44
+
45
+ <?php if (!$isNew) { ?>
46
+ <div style="width:100%;"><strong><?php _e('Categories', 'nxs_snap'); ?>:</strong>
47
+ <input value="0" id="catSelA<?php echo $ii; ?>" type="radio" name="pn[<?php echo $ii; ?>][catSel]" <?php if ((int)$options['catSel'] != 1) echo "checked"; ?> /> All
48
+ <input value="1" id="catSelSPN<?php echo $ii; ?>" type="radio" name="pn[<?php echo $ii; ?>][catSel]" <?php if ((int)$options['catSel'] == 1) echo "checked"; ?> /> <a href="#" style="text-decoration: none;" class="showCats" id="nxs_SCA_PN<?php echo $ii; ?>" onclick="jQuery('#catSelSPN<?php echo $ii; ?>').attr('checked', true); jQuery('#tmpCatSelNT').val('PN<?php echo $ii; ?>'); nxs_markCats( jQuery('#nxs_SC_PN<?php echo $ii; ?>').val() ); jQuery('#showCatSel').bPopup({ modalClose: false, appendTo: '#nsStForm', opacity: 0.6, follow: [false, false], position: [75, 'auto']}); return false;">Selected<?php if ($options['catSelEd']!='') echo "[".(substr_count($options['catSelEd'], ",")+1)."]"; ?></a>
49
+ <input type="hidden" name="pn[<?php echo $ii; ?>][catSelEd]" id="nxs_SC_PN<?php echo $ii; ?>" value="<?php echo $options['catSelEd']; ?>" />
50
+ <br/><i><?php _e('Only selected categories will be autoposted to this account', 'nxs_snap'); ?></i></div>
51
+ <br/>
52
+ <?php } ?>
53
+
54
+ <div style="width:100%;"><strong>Pinterest Email:</strong> </div><input name="pn[<?php echo $ii; ?>][apPNUName]" id="apPNUName<?php echo $ii; ?>" class="apPNUName<?php echo $ii; ?>" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['pnUName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
55
+ <div style="width:100%;"><strong>Pinterest Password:</strong> </div><input name="pn[<?php echo $ii; ?>][apPNPass]" id="apPNPass<?php echo $ii; ?>" type="password" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities(substr($options['pnPass'], 0, 5)=='g9c1a'?nsx_doDecode(substr($options['pnPass'], 5)):$options['pnPass'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /> <br/>
56
+ <div style="width:100%;"><strong>Default Image to Pin:</strong>
57
+ <p style="font-size: 11px; margin: 0px;">If your post missing Featured Image this will be used instead.</p>
58
+ </div><input name="pn[<?php echo $ii; ?>][apPNDefImg]" id="apPNDefImg" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['pnDefImg'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
59
+ <br/><br/>
60
+
61
+ <div style="width:100%;"><strong>Board:</strong>
62
+ Please <a href="#" onclick="getBoards(jQuery('<?php if ($isNew) echo "#nsx_addNT "; ?>#apPNUName<?php echo $ii; ?>').val(),jQuery('<?php if ($isNew) echo "#nsx_addNT "; ?>#apPNPass<?php echo $ii; ?>').val(), '<?php echo $ii; ?>'); return false;">click here to retrieve your boards</a>
63
+ </div>
64
+ <?php wp_nonce_field( 'getBoards', 'getBoards_wpnonce' ); ?><img id="pnLoadingImg<?php echo $ii; ?>" style="display: none;" src='<?php echo $nxs_plurl; ?>img/ajax-loader-sm.gif' />
65
+ <select name="pn[<?php echo $ii; ?>][apPNBoard]" id="apPNBoard<?php echo $ii; ?>">
66
+ <?php if ($options['pnBoardsList']!=''){ $gPNBoards = $options['pnBoardsList']; if ( base64_encode(base64_decode($gPNBoards)) === $gPNBoards) $gPNBoards = base64_decode($gPNBoards);
67
+ if ($options['pnBoard']!='') $gPNBoards = str_replace($options['pnBoard'].'"', $options['pnBoard'].'" selected="selected"', $gPNBoards); echo $gPNBoards;} else { ?>
68
+ <option value="0">None(Click above to retrieve your boards)</option>
69
+ <?php } ?>
70
+ </select>
71
+
72
+ <br/><br/>
73
+
74
+ <div style="margin-bottom: 5px; margin-left: 0px; "><input value="1" id="isAttachVid" type="checkbox" name="pn[<?php echo $ii; ?>][isAttachVid]" <?php if (isset($options['isAttachVid']) && (int)$options['isAttachVid'] == 1) echo "checked"; ?> /> <strong><?php _e('If post has a video use it instead of image', 'nxs_snap'); ?></strong> <i><?php _e('Video will be pinned instead of featured image. Only Youtube is supported at this time.', 'nxs_snap'); ?></i>
75
+ <br/></div>
76
+
77
+
78
+ <div id="altFormat" style="">
79
+ <div style="width:100%;"><strong id="altFormatText"><?php _e('Message text Format', 'nxs_snap'); ?>:</strong> <a href="#" id="apPNMsgFrmt<?php echo $ii; ?>HintInfo" onclick="mxs_showHideFrmtInfo('apPNMsgFrmt<?php echo $ii; ?>'); return false;"><?php _e('Show format info', 'nxs_snap'); ?></a>
80
+ </div>
81
+
82
+ <textarea cols="150" rows="3" id="pn<?php echo $ii; ?>SNAPformat" name="pn[<?php echo $ii; ?>][apPNMsgFrmt]" style="width:51%;max-width: 650px;" onfocus="jQuery('#pn<?php echo $ii; ?>SNAPformat').attr('rows', 6); mxs_showFrmtInfo('apPNMsgFrmt<?php echo $ii; ?>');"><?php if ($options['pnMsgFormat']!='') _e(apply_filters('format_to_edit', htmlentities($options['pnMsgFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap'); else echo "%TITLE% - %URL%"; ?></textarea>
83
+
84
+ <?php nxs_doShowHint("apPNMsgFrmt".$ii); ?>
85
+ </div><br/>
86
+ <?php if ($isNew) { ?> <input type="hidden" name="pn[<?php echo $ii; ?>][apDoPN]" value="1" id="apDoNewPN<?php echo $ii; ?>" /> <?php } ?>
87
+ <?php if ($options['pnPass']!='') { ?>
88
+ <?php wp_nonce_field( 'rePostToPN', 'rePostToPN_wpnonce' ); ?>
89
+ <b><?php _e('Test your settings', 'nxs_snap'); ?>:</b>&nbsp;&nbsp;&nbsp; <a href="#" class="NXSButton" onclick="testPost('PN', '<?php echo $ii; ?>'); return false;"><?php printf( __( 'Submit Test Post to %s', 'nxs_snap' ), $nType); ?></a>
90
+ <?php } ?>
91
+
92
+ <div class="submit"><input type="submit" class="button-primary" name="update_NS_SNAutoPoster_settings" value="<?php _e('Update Settings', 'nxs_snap') ?>" /></div>
93
+ </div>
94
+ </div>
95
+ <?php
96
+ }
97
+ //#### Set Unit Settings from POST
98
+ function setNTSettings($post, $options){ global $nxs_snapThisPageUrl;// $code = 'PN'; $lcode = 'pn';
99
+ foreach ($post as $ii => $pval){
100
+ if (isset($pval['apPNUName']) && $pval['apPNUName']!=''){ if (!isset($options[$ii])) $options[$ii] = array();
101
+ if (isset($pval['apDoPN'])) $options[$ii]['doPN'] = $pval['apDoPN']; else $options[$ii]['doPN'] = 0;
102
+ if (isset($pval['nName'])) $options[$ii]['nName'] = trim($pval['nName']);
103
+ if (isset($pval['apPNUName'])) $options[$ii]['pnUName'] = trim($pval['apPNUName']);
104
+ if (isset($pval['apPNPass'])) $options[$ii]['pnPass'] = 'g9c1a'.nsx_doEncode($pval['apPNPass']); else $options[$ii]['pnPass'] = '';
105
+ if (isset($pval['apPNBoard'])) $options[$ii]['pnBoard'] = trim($pval['apPNBoard']);
106
+ if (isset($pval['apPNDefImg'])) $options[$ii]['pnDefImg'] = trim($pval['apPNDefImg']);
107
+ if (isset($pval['isAttachVid'])) $options[$ii]['isAttachVid'] = $pval['isAttachVid']; else $options[$ii]['isAttachVid'] = 0;
108
+
109
+ if (isset($pval['catSel'])) $options[$ii]['catSel'] = trim($pval['catSel']);
110
+ if ($options[$ii]['catSel']=='1' && trim($pval['catSelEd'])!='') $options[$ii]['catSelEd'] = trim($pval['catSelEd']); else $options[$ii]['catSelEd'] = '';
111
+
112
+ if (isset($pval['apPNMsgFrmt'])) $options[$ii]['pnMsgFormat'] = trim($pval['apPNMsgFrmt']);
113
+
114
+ if (isset($pval['delayDays'])) $options[$ii]['nDays'] = trim($pval['delayDays']);
115
+ if (isset($pval['delayHrs'])) $options[$ii]['nHrs'] = trim($pval['delayHrs']); if (isset($pval['delayMin'])) $options[$ii]['nMin'] = trim($pval['delayMin']);
116
+ if (isset($pval['qTLng'])) $options[$ii]['qTLng'] = trim($pval['qTLng']);
117
+ }
118
+ } return $options;
119
+ }
120
+ //#### Show Post->Edit Meta Box Settings
121
+ function showEdPostNTSettings($ntOpts, $post){ global $nxs_plurl; $post_id = $post->ID;
122
+ foreach($ntOpts as $ii=>$ntOpt) { $pMeta = maybe_unserialize(get_post_meta($post_id, 'snapPN', true)); if (is_array($pMeta)) $ntOpt = $this->adjMetaOpt($ntOpt, $pMeta[$ii]);
123
+ $doPN = $ntOpt['doPN'] && (is_array($pMeta) || $ntOpt['catSel']!='1');
124
+ $isAvailPN = $ntOpt['pnUName']!='' && $ntOpt['pnPass']!=''; $pnMsgFormat = htmlentities($ntOpt['pnMsgFormat'], ENT_COMPAT, "UTF-8");
125
+ ?>
126
+ <tr><th style="text-align:left;" colspan="2"><?php if ( $ntOpt['catSel']=='1' && trim($ntOpt['catSelEd'])!='' ) { ?> <input type="hidden" class="nxs_SC" id="nxs_SC_PN<?php echo $ii; ?>" value="<?php echo $ntOpt['catSelEd']; ?>" /> <?php } ?>
127
+ <?php if ($isAvailPN) { ?><input class="nxsGrpDoChb" value="1" id="doPN<?php echo $ii; ?>" <?php if ($post->post_status == "publish") echo 'disabled="disabled"';?> type="checkbox" name="pn[<?php echo $ii; ?>][doPN]" <?php if ((int)$doPN == 1) echo 'checked="checked" title="def"'; ?> />
128
+ <?php if ($post->post_status == "publish") { ?> <input type="hidden" name="pn[<?php echo $ii; ?>][doPN]" value="<?php echo $doPN;?>"> <?php } ?> <?php } ?>
129
+ <div class="nsx_iconedTitle" style="display: inline; font-size: 13px; background-image: url(<?php echo $nxs_plurl; ?>img/pn16.png);">Pinterest - <?php _e('publish to', 'nxs_snap') ?> (<i style="color: #005800;"><?php echo $ntOpt['nName']; ?></i>)</div></th> <td><?php //## Only show RePost button if the post is "published"
130
+ if ($post->post_status == "publish" && $isAvailPN) { ?><input alt="<?php echo $ii; ?>" style="float: right;" onmouseout="hidePopShAtt('SV');" onmouseover="showPopShAtt('SV', event);" onclick="return false;" type="button" class="button" name="rePostToPN_repostButton" id="rePostToPN_button" value="<?php _e('Repost to Pinterest', 'nxs_snap') ?>" />
131
+ <?php wp_nonce_field( 'rePostToPN', 'rePostToPN_wpnonce' ); } ?>
132
+
133
+ <?php if (is_array($pMeta) && is_array($pMeta[$ii]) && isset($pMeta[$ii]['pgID']) ) {
134
+ ?> <span id="pstdPN<?php echo $ii; ?>" style="float: right;padding-top: 4px; padding-right: 10px;">
135
+ <a style="font-size: 10px;" href="http://pinterest.com<?php echo $pMeta[$ii]['pgID']; ?>" target="_blank"><?php $nType="Pinterest"; printf( __( 'Posted on', 'nxs_snap' ), $nType); ?> <?php echo (isset($pMeta[$ii]['pDate']) && $pMeta[$ii]['pDate']!='')?(" (".$pMeta[$ii]['pDate'].")"):""; ?></a>
136
+ </span><?php } ?>
137
+
138
+ </td></tr>
139
+
140
+ <?php if (!$isAvailPN) { ?><tr><th scope="row" style="text-align:right; width:150px; padding-top: 5px; padding-right:10px;"></th> <td><b>Setup your Pinterest Account to AutoPost to Pinterest</b>
141
+ <?php } elseif ($post->post_status != "puZblish") { ?>
142
+
143
+ <tr><th scope="row" style="text-align:right; width:150px; padding-top: 5px; padding-right:10px;">Select Board</th>
144
+ <td><select name="pn[<?php echo $ii; ?>][apPNBoard]" id="apPNBoard">
145
+ <?php if ($ntOpt['pnBoardsList']!=''){ $gPNBoards = $ntOpt['pnBoardsList']; if ( base64_encode(base64_decode($gPNBoards)) === $gPNBoards) $gPNBoards = base64_decode($gPNBoards);
146
+ if ($ntOpt['pnBoard']!='') $gPNBoards = str_replace($ntOpt['pnBoard'].'"', $ntOpt['pnBoard'].'" selected="selected"', $gPNBoards); echo $gPNBoards;} else { ?>
147
+ <option value="0">None(Click above to retrieve your boards)</option>
148
+ <?php } ?>
149
+ </select></td>
150
+ </tr>
151
+
152
+ <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top:6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Text Message Format:', 'nxs_snap') ?></th>
153
+ <td>
154
+ <textarea cols="150" rows="1" id="pn<?php echo $ii; ?>SNAPformat" name="pn[<?php echo $ii; ?>][SNAPformat]" style="width:60%;max-width: 610px;" onfocus="jQuery('#pn<?php echo $ii; ?>SNAPformat').attr('rows', 4); jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apPNMsgFrmt<?php echo $ii; ?>');"><?php echo $pnMsgFormat; ?></textarea>
155
+ <?php nxs_doShowHint("apPNMsgFrmt".$ii); ?></td></tr>
156
+
157
+ <?php }
158
+ }
159
+ }
160
+ //#### Save Meta Tags to the Post
161
+ function adjMetaOpt($optMt, $pMeta){ if (isset($pMeta['isPosted'])) $optMt['isPosted'] = $pMeta['isPosted']; else $optMt['isPosted'] = '';
162
+ if (isset($pMeta['SNAPformat'])) $optMt['pnMsgFormat'] = $pMeta['SNAPformat'];
163
+ if (isset($pMeta['doPN'])) $optMt['doPN'] = $pMeta['doPN'] == 1?1:0; else { if (isset($pMeta['SNAPformat'])) $optMt['doPN'] = 0; }
164
+ if (isset($pMeta['apPNBoard']) && $pMeta['apPNBoard']!='' && $pMeta['apPNBoard']!='0') $optMt['pnBoard'] = $pMeta['apPNBoard'];
165
+ if (isset($pMeta['SNAPincludePN']) && $pMeta['SNAPincludePN'] == '1' ) $optMt['doPN'] = 1;
166
+ return $optMt;
167
+ }
168
+ }}
169
+ if (!function_exists("nxs_rePostToPN_ajax")) {
170
+ function nxs_rePostToPN_ajax() { check_ajax_referer('rePostToPN'); $postID = $_POST['id']; $options = get_option('NS_SNAutoPoster');
171
+ foreach ($options['pn'] as $ii=>$two) if ($ii==$_POST['nid']) { $two['ii'] = $ii; $two['pType'] = 'aj'; //if ($two['gpPageID'].$two['gpUName']==$_POST['nid']) {
172
+ $po = get_post_meta($postID, 'snapPN', true); $po = maybe_unserialize($po);// prr($gppo);
173
+ if (is_array($po) && isset($po[$ii]) && is_array($po[$ii])){ $ntClInst = new nxs_snapClassPN(); $two = $ntClInst->adjMetaOpt($two, $po[$ii]); }
174
+ $result = nxs_doPublishToPN($postID, $two); if ($result == 200) die("Successfully sent your post to Pinterest."); else die($result);
175
+ }
176
+ }
177
+ }
178
+
179
+ if (!function_exists("nxs_doPublishToPN")) { //## Second Function to Post to G+
180
+ function nxs_doPublishToPN($postID, $options){ global $nxs_gCookiesArr, $plgn_NS_SNAutoPoster; $ntCd = 'PN'; $ntCdL = 'pn'; $ntNm = 'Pinterest';
181
+ // $backtrace = debug_backtrace(); nxs_addToLogN('W', 'Enter', $ntCd, 'I am here - '.$ntCd."|".print_r($backtrace, true), '');
182
+ //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToPN', array($postID, $options));
183
+ $addParams = nxs_makeURLParams(array('NTNAME'=>$ntNm, 'NTCODE'=>$ntCd, 'POSTID'=>$postID, 'ACCNAME'=>$options['nName']));
184
+ $ii = $options['ii']; if (!isset($options['pType'])) $options['pType'] = 'im'; if ($options['pType']=='sh') sleep(rand(1, 10));
185
+ $logNT = '<span style="color:#FA5069">Pinterest</span> - '.$options['nName'];
186
+ $snap_ap = get_post_meta($postID, 'snap'.$ntCd, true); $snap_ap = maybe_unserialize($snap_ap);
187
+ $isAttachVid = $options['isAttachVid'];
188
+ if ($options['pType']!='aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
189
+ $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted!='2') { sleep(5);
190
+ nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:'.$postID, 'Already posted. No reason for posting duplicate'.' |'.$uqID); return;
191
+ }
192
+ }
193
+ $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle=='') $blogTitle = home_url();
194
+
195
+ if ($postID=='0') { echo "Testing ... <br/><br/>"; $msg = 'Test Post from '.$blogTitle; $urlToGo = home_url();
196
+ if ($options['pnDefImg']!='') $imgURL = $options['pnDefImg']; else $imgURL ="http://direct.gtln.us/img/nxs/NextScriptsLogoT.png";
197
+ }
198
+ else { $post = get_post($postID); if(!$post) return; $pnMsgFormat = $options['pnMsgFormat']; $msg = nsFormatMessage($pnMsgFormat, $postID, $addParams);
199
+ //## MyURL - URLToGo code
200
+ if (!isset($options['urlToUse']) || trim($options['urlToUse'])=='') $myurl = trim(get_post_meta($postID, 'snap_MYURL', true)); if ($myurl!='') $options['urlToUse'] = $myurl;
201
+ if (isset($options['urlToUse']) && trim($options['urlToUse'])!='') { $urlToGo = $options['urlToUse']; $options['useFBGURLInfo'] = true; } else $urlToGo = get_permalink($postID);
202
+ if($addParams!='') $urlToGo .= (strpos($urlToGo,'?')!==false?'&':'?').$addParams;
203
+ nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted'=>'1')); $imgURL = nxs_getPostImage($postID, 'large', $options['pnDefImg']); //prr($options); echo $imgURL."######"; // echo "WW".$postID."|";
204
+ if ($isAttachVid=='1') { $vids = nsFindVidsInPost($post); if (count($vids)>0) { $vidURL = 'http://www.youtube.com/v/'.$vids[0]; $imgURL = 'http://img.youtube.com/vi/'.$vids[0].'/0.jpg'; }}
205
+ }
206
+ $email = $options['pnUName']; $boardID = $options['pnBoard']; $pass = substr($options['pnPass'], 0, 5)=='g9c1a'?nsx_doDecode(substr($options['pnPass'], 5)):$options['pnPass'];// prr($boardID); prr($_POST); die();
207
+ if (isset($options['pnSvC'])) $nxs_gCookiesArr = maybe_unserialize( $options['pnSvC']); $loginError = true;
208
+ if (is_array($nxs_gCookiesArr)) $loginError = doCheckPinterest();
209
+ $extInfo = ' | PostID: '.$postID." - ".$post->post_title;
210
+ if ($loginError!==false) $loginError = doConnectToPinterest($email, $pass); if ($loginError!==false) {echo $loginError; nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.print_r($loginError, true), $extInfo); return "BAD USER/PASS";}
211
+ if (serialize($nxs_gCookiesArr)!=$options['pnSvC']) { global $plgn_NS_SNAutoPoster; $gOptions = $plgn_NS_SNAutoPoster->nxs_options; // prr($gOptions['pn']);
212
+ if (isset($options['ii']) && $options['ii']!=='') { $gOptions['pn'][$options['ii']]['pnSvC'] = serialize($nxs_gCookiesArr); update_option('NS_SNAutoPoster', $gOptions); }
213
+ else foreach ($gOptions['pn'] as $ii=>$gpn) { $result = array_diff($options, $gpn);
214
+ if (!is_array($result) || count($result)<1) { $gOptions['pn'][$ii]['pnSvC'] = serialize($nxs_gCookiesArr); update_option('NS_SNAutoPoster', $gOptions); break; }
215
+ }
216
+ } // echo "PN SET:".$msg."|".$imgURL."|".$link."|".$boardID;
217
+ if (preg_match ( '/\$(\d+\.\d+)/', $msg, $matches )) $price = $matches[0]; $urlToGo = apply_filters( 'nxs_adjust_ex_url', $urlToGo, $post->post_content );
218
+ $ret = doPostToPinterest($msg, $imgURL, $urlToGo, $boardID, 'TITLE WHERE IS IT?', $price, $urlToGo."/GTH/" ); if ($ret=='OK') $ret = array("code"=>"OK", "post_id"=>'');
219
+ if ( (!is_array($ret)) && $ret!='OK') { if ($postID=='0') echo $ret; nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.print_r($ret, true), $extInfo); } else { if ($postID=='0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo 'OK - Message Posted, please see your Pinterest Page'; } else { nxs_metaMarkAsPosted($postID, 'PN', $options['ii'], array('isPosted'=>'1', 'pgID'=>$ret['post_id'], 'pDate'=>date('Y-m-d H:i:s'))); nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo);} }
220
+ if (is_array($ret) && isset($ret['code']) && $ret['code']=='OK') return 200; else return $ret;
221
+ }
222
+ }
223
  ?>
inc-cl/su.php CHANGED
@@ -1,287 +1,294 @@
1
- <?php
2
- //## NextScripts Facebook Connection Class
3
- $nxs_snapAvNts[] = array('code'=>'SU', 'lcode'=>'su', 'name'=>'StumbleUpon');
4
-
5
- if (!class_exists("nxs_snapClassSU")) { class nxs_snapClassSU {
6
- //#### Show Common Settings
7
- function showGenNTSettings($ntOpts){ global $nxs_plurl; $ntInfo = array('code'=>'SU', 'lcode'=>'su', 'name'=>'StumbleUpon', 'defNName'=>'suUName', 'tstReq' => false); ?>
8
- <div class="nxs_box">
9
- <div class="nxs_box_header">
10
- <div class="nsx_iconedTitle" style="margin-bottom:1px;background-image:url(<?php echo $nxs_plurl;?>img/<?php echo $ntInfo['lcode']; ?>16.png);"><?php echo $ntInfo['name']; ?>
11
- <?php $cbo = count($ntOpts); ?> <?php wp_nonce_field( 'ns'.$ntInfo['code'], 'ns'.$ntInfo['code'].'_wpnonce' ); ?>
12
- <?php if ($cbo>1){ ?><div class="nsBigText"><?php echo "(".($cbo=='0'?'No':$cbo)." "; _e('accounts', 'nxs_snap'); echo ")"; ?></div><?php } ?>
13
- </div>
14
- </div>
15
- <div class="nxs_box_inside">
16
- <?php foreach ($ntOpts as $indx=>$pbo){ if (trim($pbo['nName']=='')) $pbo['nName'] = $pbo[$ntInfo['defNName']]; ?>
17
- <p style="margin:0px;margin-left:5px;">
18
- <input value="1" name="<?php echo $ntInfo['lcode']; ?>[<?php echo $indx; ?>][apDo<?php echo $ntInfo['code']; ?>]" onchange="doShowHideBlocks('<?php echo $ntInfo['code']; ?>');" type="checkbox" <?php if ((int)$pbo['do'.$ntInfo['code']] == 1) echo "checked"; ?> /> <?php if ((int)$pbo['catSel'] == 1) { ?> <span onmouseout="nxs_hidePopUpInfo('popOnlyCat');" onmouseover="nxs_showPopUpInfo('popOnlyCat', event);"><?php echo "*[".(substr_count($pbo['catSelEd'], ",")+1)."]*" ?></span><?php } ?>
19
- <strong><?php _e('Auto-publish to', 'nxs_snap'); ?> <?php echo $ntInfo['name']; ?> <i style="color: #005800;"><?php if($pbo['nName']!='') echo "(".$pbo['nName'].")"; ?></i></strong>
20
- &nbsp;&nbsp;<?php if ($ntInfo['tstReq'] && (!isset($pbo[$ntInfo['lcode'].'OK']) || $pbo[$ntInfo['lcode'].'OK']=='')){ ?><b style="color: #800000"><?php _e('Attention requred. Unfinished setup', 'nxs_snap'); ?> ==&gt;</b><?php } ?><a id="do<?php echo $ntInfo['code'].$indx; ?>A" href="#" onclick="doShowHideBlocks2('<?php echo $ntInfo['code'].$indx; ?>');return false;">[<?php _e('Show Settings', 'nxs_snap'); ?>]</a>&nbsp;&nbsp;
21
- <a href="#" onclick="doDelAcct('<?php echo $ntInfo['lcode']; ?>', '<?php echo $indx; ?>', '<?php if (isset($pbo['bgBlogID'])) echo $pbo['nName']; ?>');return false;">[<?php _e('Remove Account', 'nxs_snap'); ?>]</a>
22
- </p><?php $this->showNTSettings($indx, $pbo);
23
- }?>
24
- </div>
25
- </div> <?php
26
- }
27
- //#### Show NEW Settings Page
28
- function showNewNTSettings($mgpo){ $options = array('nName'=>'', 'doSU'=>'1', 'suUName'=>'', 'suInclTags'=>'1', 'suAttch'=>'', 'suPass'=>''); $this->showNTSettings($mgpo, $options, true);}
29
-
30
- function suCats() { return '<option value="A.I.">A.I.</option><option value="AIDS">AIDS</option><option value="Accounting">Accounting</option><option value="Acting">Acting</option><option value="Action Movies">Action Movies</option><option value="Activism">Activism</option><option value="Adult Humor">Adult Humor</option><option value="Advertising">Advertising</option><option value="Africa">Africa</option><option value="African Americans">African Americans</option><option value="Aging">Aging</option><option value="Agriculture">Agriculture</option><option value="Alcoholic Drinks">Alcoholic Drinks</option><option value="Alternative Energy">Alternative Energy</option><option value="Alternative Health">Alternative Health</option><option value="Alternative News">Alternative News</option><option value="Alternative Rock">Alternative Rock</option><option value="Amateur Radio">Amateur Radio</option><option value="Ambient Music">Ambient Music</option><option value="American Football">American Football</option><option value="American History">American History</option><option value="American Lit.">American Lit.</option><option value="Anarchism">Anarchism</option><option value="Anatomy">Anatomy</option><option value="Ancient History">Ancient History</option><option value="Animals">Animals</option><option value="Animation">Animation</option><option value="Anime">Anime</option><option value="Anthropology">Anthropology</option><option value="Antiaging">Antiaging</option><option value="Antiques">Antiques</option><option value="Archaeology">Archaeology</option><option value="Architecture">Architecture</option><option value="Art History">Art History</option><option value="Arthritis">Arthritis</option><option value="Arts">Arts</option><option value="Asia">Asia</option><option value="Asthma">Asthma</option><option value="Astrology/Psychics">Astrology/Psychics</option><option value="Astronomy">Astronomy</option><option value="Atheist/Agnostic">Atheist/Agnostic</option><option value="Audio Equipment">Audio Equipment</option><option value="Australia">Australia</option><option value="Aviation/Aerospace">Aviation/Aerospace</option><option value="BDSM">BDSM</option><option value="Babes">Babes</option><option value="Babies">Babies</option><option value="Badminton">Badminton</option><option value="Ballet">Ballet</option><option value="Banking">Banking</option><option value="Bargains/Coupons">Bargains/Coupons</option><option value="Baseball">Baseball</option><option value="Basketball">Basketball</option><option value="Beauty">Beauty</option><option value="Beer">Beer</option><option value="Beverages">Beverages</option><option value="Bicycling">Bicycling</option><option value="Billiards">Billiards</option><option value="Biographies">Biographies</option><option value="Biology">Biology</option><option value="Biomechanics">Biomechanics</option><option value="Biotech">Biotech</option><option value="Bird Watching">Bird Watching</option><option value="Birds">Birds</option><option value="Bisexual Culture">Bisexual Culture</option><option value="Bisexual Sex">Bisexual Sex</option><option value="Bizarre/Oddities">Bizarre/Oddities</option><option value="Blues music">Blues music</option><option value="Board Games">Board Games</option><option value="Boating">Boating</option><option value="Bodybuilding">Bodybuilding</option><option value="Books">Books</option><option value="Botany">Botany</option><option value="Bowling">Bowling</option><option value="Boxing">Boxing</option><option value="Brain Disorders">Brain Disorders</option><option value="Brazil">Brazil</option><option value="British Literature">British Literature</option><option value="Britpop">Britpop</option><option value="Buddhism">Buddhism</option><option value="Business">Business</option><option value="C.A.D.">C.A.D.</option><option value="Camping">Camping</option><option value="Canada">Canada</option><option value="Cancer">Cancer</option><option value="Canoeing/Kayaking">Canoeing/Kayaking</option><option value="Capitalism">Capitalism</option><option value="Car Parts">Car Parts</option><option value="Card Games">Card Games</option><option value="Career planning">Career planning</option><option value="Caribbean">Caribbean</option><option value="Cars">Cars</option><option value="Cartoons">Cartoons</option><option value="Catholic">Catholic</option><option value="Cats">Cats</option><option value="Celebrities">Celebrities</option><option value="Cell Phones">Cell Phones</option><option value="Celtic Music">Celtic Music</option><option value="Central America">Central America</option><option value="Chaos/Complexity">Chaos/Complexity</option><option value="Cheerleading">Cheerleading</option><option value="Chemical Eng.">Chemical Eng.</option><option value="Chemistry">Chemistry</option><option value="Chess">Chess</option><option value="Children\'s Books">Children\'s Books</option><option value="China">China</option><option value="Christian Music">Christian Music</option><option value="Christianity">Christianity</option><option value="Christmas">Christmas</option><option value="Cigars">Cigars</option><option value="Civil Engineering">Civil Engineering</option><option value="Classic Films">Classic Films</option><option value="Classic Rock">Classic Rock</option><option value="Classical Music">Classical Music</option><option value="Classical Studies">Classical Studies</option><option value="Climbing">Climbing</option><option value="Clothing">Clothing</option><option value="Coffee">Coffee</option><option value="Cognitive Science">Cognitive Science</option><option value="Cold War">Cold War</option><option value="Collecting">Collecting</option><option value="Comedy Movies">Comedy Movies</option><option value="Comic Books">Comic Books</option><option value="Communism">Communism</option><option value="Computer Graphics">Computer Graphics</option><option value="Computer Hardware">Computer Hardware</option><option value="Computer Science">Computer Science</option><option value="Computer Security">Computer Security</option><option value="Computers">Computers</option><option value="Conservative Politics">Conservative Politics</option><option value="Conspiracies">Conspiracies</option><option value="Construction">Construction</option><option value="Consumer Info">Consumer Info</option><option value="Continuing Education">Continuing Education</option><option value="Counterculture">Counterculture</option><option value="Country music">Country music</option><option value="Crafts">Crafts</option><option value="Cricket">Cricket</option><option value="Crime">Crime</option><option value="Crochet">Crochet</option><option value="Cult Films">Cult Films</option><option value="Culture/Ethnicity">Culture/Ethnicity</option><option value="Cyberculture">Cyberculture</option><option value="DJ\'s/Mixing">DJ\'s/Mixing</option><option value="Dance Music">Dance Music</option><option value="Dancing">Dancing</option><option value="Databases">Databases</option><option value="Dating Tips">Dating Tips</option><option value="Daytrading">Daytrading</option><option value="Dentistry">Dentistry</option><option value="Design">Design</option><option value="Desktop Publishing">Desktop Publishing</option><option value="Diabetes">Diabetes</option><option value="Disabilities">Disabilities</option><option value="Disco">Disco</option><option value="Divorce">Divorce</option><option value="Doctors/Surgeons">Doctors/Surgeons</option><option value="Dogs">Dogs</option><option value="Dolls/Puppets">Dolls/Puppets</option><option value="Drama Movies">Drama Movies</option><option value="Drawing">Drawing</option><option value="Drugs">Drugs</option><option value="Drum\'n\'Bass">Drum\'n\'Bass</option><option value="Eastern Studies">Eastern Studies</option><option value="Eating Disorders">Eating Disorders</option><option value="Ecology">Ecology</option><option value="Ecommerce">Ecommerce</option><option value="Economics">Economics</option><option value="Education">Education</option><option value="Electrical Eng.">Electrical Eng.</option><option value="Electronic Devices">Electronic Devices</option><option value="Electronic Parts">Electronic Parts</option><option value="Electronica/IDM">Electronica/IDM</option><option value="Embedded Systems">Embedded Systems</option><option value="Encryption">Encryption</option><option value="Energy Industry">Energy Industry</option><option value="Entertaining Guests">Entertaining Guests</option><option value="Entrepreneurship">Entrepreneurship</option><option value="Environment">Environment</option><option value="Equestrian/Horses">Equestrian/Horses</option><option value="Ergonomics">Ergonomics</option><option value="Erotic Literature">Erotic Literature</option><option value="Ethics">Ethics</option><option value="Ethnic Music">Ethnic Music</option><option value="Europe">Europe</option><option value="Evolution">Evolution</option><option value="Exotic Pets">Exotic Pets</option><option value="Extreme Sports">Extreme Sports</option><option value="Facebook">Facebook</option><option value="Family">Family</option><option value="Fantasy Books">Fantasy Books</option><option value="Fashion">Fashion</option><option value="Feminism">Feminism</option><option value="Fetish Sexuality">Fetish Sexuality</option><option value="Figure Skating">Figure Skating</option><option value="Film Noir">Film Noir</option><option value="Filmmaking">Filmmaking</option><option value="Financial planning">Financial planning</option><option value="Fine Arts">Fine Arts</option><option value="Firefox">Firefox</option><option value="Fish">Fish</option><option value="Fishing">Fishing</option><option value="Fitness">Fitness</option><option value="Flyfishing">Flyfishing</option><option value="Folk music">Folk music</option><option value="Food/Cooking">Food/Cooking</option><option value="For Kids">For Kids</option><option value="Foreign Films">Foreign Films</option><option value="Forensics">Forensics</option><option value="Forestry">Forestry</option><option value="Forums">Forums</option><option value="France">France</option><option value="Funk">Funk</option><option value="Futurism">Futurism</option><option value="Gadgets">Gadgets</option><option value="Gambling">Gambling</option><option value="Gardening">Gardening</option><option value="Gay Culture">Gay Culture</option><option value="Gay Sex">Gay Sex</option><option value="Genealogy">Genealogy</option><option value="Genetics">Genetics</option><option value="Geography">Geography</option><option value="Geoscience">Geoscience</option><option value="Germany">Germany</option><option value="Glaucoma">Glaucoma</option><option value="Golf">Golf</option><option value="Gospel music">Gospel music</option><option value="Goth Culture">Goth Culture</option><option value="Government">Government</option><option value="Graphic Design">Graphic Design</option><option value="Guitar">Guitar</option><option value="Guns">Guns</option><option value="Gymnastics">Gymnastics</option><option value="Hacking">Hacking</option><option value="Health">Health</option><option value="Heart Conditions">Heart Conditions</option><option value="Heavy metal">Heavy metal</option><option value="Hedonism">Hedonism</option><option value="Hentai Anime">Hentai Anime</option><option value="Hiking">Hiking</option><option value="Hinduism">Hinduism</option><option value="HipHop/Rap">HipHop/Rap</option><option value="History">History</option><option value="Hockey">Hockey</option><option value="Home Business">Home Business</option><option value="Home Improvement">Home Improvement</option><option value="Homebrewing">Homebrewing</option><option value="Homemaking">Homemaking</option><option value="Homeschooling">Homeschooling</option><option value="Horror Movies">Horror Movies</option><option value="Hotels">Hotels</option><option value="House music">House music</option><option value="Humanitarianism">Humanitarianism</option><option value="Humanities">Humanities</option><option value="Humor">Humor</option><option value="Hunting">Hunting</option><option value="IT">IT</option><option value="Independent Film">Independent Film</option><option value="India">India</option><option value="Indie Rock/Pop">Indie Rock/Pop</option><option value="Industrial Design">Industrial Design</option><option value="Industrial Music">Industrial Music</option><option value="Instant Messaging">Instant Messaging</option><option value="Insurance">Insurance</option><option value="Int\'l Development">Int\'l Development</option><option value="Interior Design">Interior Design</option><option value="Internet">Internet</option><option value="Internet Tools">Internet Tools</option><option value="Investing">Investing</option><option value="Ipod">Ipod</option><option value="Iraq">Iraq</option><option value="Ireland">Ireland</option><option value="Islam">Islam</option><option value="Israel">Israel</option><option value="Italy">Italy</option><option value="Japan">Japan</option><option value="Java">Java</option><option value="Jazz">Jazz</option><option value="Jewelry">Jewelry</option><option value="Journalism">Journalism</option><option value="Judaism">Judaism</option><option value="Karaoke">Karaoke</option><option value="Kids">Kids</option><option value="Kinesiology">Kinesiology</option><option value="Knitting">Knitting</option><option value="Korea">Korea</option><option value="Landscaping">Landscaping</option><option value="Latin Music">Latin Music</option><option value="Law">Law</option><option value="Learning Disorders">Learning Disorders</option><option value="Lefthanded">Lefthanded</option><option value="Lesbian Culture">Lesbian Culture</option><option value="Lesbian Sex">Lesbian Sex</option><option value="Liberal Politics">Liberal Politics</option><option value="Liberties/Rights">Liberties/Rights</option><option value="Library Resources">Library Resources</option><option value="Lingerie">Lingerie</option><option value="Linguistics">Linguistics</option><option value="Linux/Unix">Linux/Unix</option><option value="Literature">Literature</option><option value="Live Theatre">Live Theatre</option><option value="Logic">Logic</option><option value="Lounge Music">Lounge Music</option><option value="Luxury">Luxury</option><option value="MacOS">MacOS</option><option value="Machinery">Machinery</option><option value="Magic/Illusions">Magic/Illusions</option><option value="Management/HR">Management/HR</option><option value="Manufacturing">Manufacturing</option><option value="Marine Biology">Marine Biology</option><option value="Marketing">Marketing</option><option value="Married Life">Married Life</option><option value="Martial Arts">Martial Arts</option><option value="Matchmaking">Matchmaking</option><option value="Mathematics">Mathematics</option><option value="Mechanical Eng.">Mechanical Eng.</option><option value="Medical Science">Medical Science</option><option value="Medieval History">Medieval History</option><option value="Memorabilia">Memorabilia</option><option value="Men\'s Issues">Men\'s Issues</option><option value="Mental Health">Mental Health</option><option value="Meteorology">Meteorology</option><option value="Mexico">Mexico</option><option value="Microbiology">Microbiology</option><option value="Middle East">Middle East</option><option value="Military">Military</option><option value="Mining/Metallurgy">Mining/Metallurgy</option><option value="Mobile Computing">Mobile Computing</option><option value="Mormon">Mormon</option><option value="Motor Sports">Motor Sports</option><option value="Motorcycles">Motorcycles</option><option value="Movies">Movies</option><option value="Multimedia">Multimedia</option><option value="Music">Music</option><option value="Music Composition">Music Composition</option><option value="Music Instruments">Music Instruments</option><option value="Music Theory">Music Theory</option><option value="Musicals">Musicals</option><option value="Musician Resources">Musician Resources</option><option value="Mutual Funds">Mutual Funds</option><option value="Mystery Novels">Mystery Novels</option><option value="Mythology">Mythology</option><option value="Nanotech">Nanotech</option><option value="Native Americans">Native Americans</option><option value="Nature">Nature</option><option value="Netherlands">Netherlands</option><option value="Network Security">Network Security</option><option value="Neuroscience">Neuroscience</option><option value="New Age">New Age</option><option value="New York">New York</option><option value="News(General)">News(General)</option><option value="Nightlife">Nightlife</option><option value="Nonprofit/Charity">Nonprofit/Charity</option><option value="Nuclear Science">Nuclear Science</option><option value="Nude Art">Nude Art</option><option value="Nursing">Nursing</option><option value="Nutrition">Nutrition</option><option value="Oceania">Oceania</option><option value="Oldies Music">Oldies Music</option><option value="Online Games">Online Games</option><option value="Open Source">Open Source</option><option value="Opera">Opera</option><option value="Operating Systems">Operating Systems</option><option value="Options/Futures">Options/Futures</option><option value="Orthodox">Orthodox</option><option value="Outdoors">Outdoors</option><option value="P2P">P2P</option><option value="PHP">PHP</option><option value="Paganism">Paganism</option><option value="Painting">Painting</option><option value="Paleontology">Paleontology</option><option value="Paranormal">Paranormal</option><option value="Parenting">Parenting</option><option value="Percussion">Percussion</option><option value="Performing Arts">Performing Arts</option><option value="Peripheral Devices">Peripheral Devices</option><option value="Perl">Perl</option><option value="Personal Sites">Personal Sites</option><option value="Petroleum">Petroleum</option><option value="Pets">Pets</option><option value="Pharmacology">Pharmacology</option><option value="Philosophy">Philosophy</option><option value="Photo Gear">Photo Gear</option><option value="Photography">Photography</option><option value="Photoshop">Photoshop</option><option value="Physical Therapy">Physical Therapy</option><option value="Physics">Physics</option><option value="Physiology">Physiology</option><option value="Poetry">Poetry</option><option value="Poker">Poker</option><option value="Political Science">Political Science</option><option value="Politics">Politics</option><option value="Pop music">Pop music</option><option value="Pornography">Pornography</option><option value="Postmodernism">Postmodernism</option><option value="Pregnancy/Birth">Pregnancy/Birth</option><option value="Programming">Programming</option><option value="Protestant">Protestant</option><option value="Proxy">Proxy</option><option value="Psychiatry">Psychiatry</option><option value="Psychology">Psychology</option><option value="Punk Rock">Punk Rock</option><option value="Puzzles">Puzzles</option><option value="Quilting">Quilting</option><option value="Quizzes">Quizzes</option><option value="Quotes">Quotes</option><option value="Racquetball">Racquetball</option><option value="Radio Broadcasts">Radio Broadcasts</option><option value="Rave Culture">Rave Culture</option><option value="Real Estate">Real Estate</option><option value="Recording Gear">Recording Gear</option><option value="Reggae">Reggae</option><option value="Relationships">Relationships</option><option value="Religion">Religion</option><option value="Research">Research</option><option value="Restaurants">Restaurants</option><option value="Restoration">Restoration</option><option value="Robotics">Robotics</option><option value="Rock music">Rock music</option><option value="Rodeo">Rodeo</option><option value="Roleplaying Games">Roleplaying Games</option><option value="Romance Novels">Romance Novels</option><option value="Rugby">Rugby</option><option value="Running">Running</option><option value="Russia">Russia</option><option value="SEO">SEO</option><option value="Sailing">Sailing</option><option value="Satire">Satire</option><option value="Science">Science</option><option value="Science Fiction">Science Fiction</option><option value="Scientology">Scientology</option><option value="Scouting">Scouting</option><option value="Scrapbooking">Scrapbooking</option><option value="Scuba Diving">Scuba Diving</option><option value="Sculpting">Sculpting</option><option value="Search">Search</option><option value="Self Improvement">Self Improvement</option><option value="Semiconductors">Semiconductors</option><option value="Senior Citizens">Senior Citizens</option><option value="Sewing">Sewing</option><option value="Sex Industry">Sex Industry</option><option value="Sex Toys">Sex Toys</option><option value="Sexual Health">Sexual Health</option><option value="Sexuality">Sexuality</option><option value="Shakespeare">Shakespeare</option><option value="Shareware">Shareware</option><option value="Shopping">Shopping</option><option value="Skateboarding">Skateboarding</option><option value="Skiing">Skiing</option><option value="Skydiving">Skydiving</option><option value="Snowboarding">Snowboarding</option><option value="Soap Operas">Soap Operas</option><option value="Soccer">Soccer</option><option value="Socialism">Socialism</option><option value="Sociology">Sociology</option><option value="Software">Software</option><option value="Songwriting">Songwriting</option><option value="Soul/R&amp;B">Soul/R&amp;B</option><option value="Soundtracks">Soundtracks</option><option value="South America">South America</option><option value="Space Exploration">Space Exploration</option><option value="Spain">Spain</option><option value="Spas">Spas</option><option value="Spirituality">Spirituality</option><option value="Sports(General)">Sports(General)</option><option value="Squash">Squash</option><option value="Statistics">Statistics</option><option value="StumbleUpon">StumbleUpon</option><option value="Subculture">Subculture</option><option value="Substance Abuse">Substance Abuse</option><option value="Sufism">Sufism</option><option value="Sunni">Sunni</option><option value="Supercomputing">Supercomputing</option><option value="Surfing">Surfing</option><option value="Survivalist">Survivalist</option><option value="Swimming">Swimming</option><option value="Swingers">Swingers</option><option value="Tattoos/Piercing">Tattoos/Piercing</option><option value="Taxation">Taxation</option><option value="Tea">Tea</option><option value="Techno">Techno</option><option value="Technology">Technology</option><option value="Teen Life">Teen Life</option><option value="Teen Parenting">Teen Parenting</option><option value="Telecom">Telecom</option><option value="Television">Television</option><option value="Tennis">Tennis</option><option value="Terrorism">Terrorism</option><option value="Toys">Toys</option><option value="Track/Field">Track/Field</option><option value="Trains/Railroads">Trains/Railroads</option><option value="Trance">Trance</option><option value="Transexual Sex">Transexual Sex</option><option value="Transportation">Transportation</option><option value="Travel">Travel</option><option value="TripHop/Downtempo">TripHop/Downtempo</option><option value="UFOs">UFOs</option><option value="UK">UK</option><option value="USA">USA</option><option value="University/College">University/College</option><option value="Vegetarian">Vegetarian</option><option value="Video Equipment">Video Equipment</option><option value="Video Games">Video Games</option><option value="Vintage Cars">Vintage Cars</option><option value="Virtual Reality">Virtual Reality</option><option value="Vocal Music">Vocal Music</option><option value="Volleyball">Volleyball</option><option value="Water Sports">Water Sports</option><option value="Web Development">Web Development</option><option value="Webhosting">Webhosting</option><option value="Weblogs">Weblogs</option><option value="Weddings">Weddings</option><option value="Weight Loss">Weight Loss</option><option value="Wicca">Wicca</option><option value="Windows">Windows</option><option value="Windows Dev">Windows Dev</option><option value="Windsurfing">Windsurfing</option><option value="Wine">Wine</option><option value="Women\'s Issues">Women\'s Issues</option><option value="Woodworking">Woodworking</option><option value="Wrestling">Wrestling</option><option value="Writing">Writing</option><option value="Yoga">Yoga</option><option value="Zoology">Zoology</option>'; }
31
- //#### Show Unit Settings
32
- function showNTSettings($ii, $options, $isNew=false){ global $nxs_plurl; ?>
33
- <div id="doSU<?php echo $ii; ?>Div" class="insOneDiv<?php if ($isNew) echo " clNewNTSets"; ?>" style="background-image: url(<?php echo $nxs_plurl; ?>img/su-bg.png); background-position:90% 10%;"> <input type="hidden" name="apDoSSU<?php echo $ii; ?>" value="0" id="apDoSSU<?php echo $ii; ?>" />
34
-
35
- <div class="nsx_iconedTitle" style="float: right; background-image: url(<?php echo $nxs_plurl; ?>img/su16.png);"><a style="font-size: 12px;" target="_blank" href="http://www.nextscripts.com/setup-installation-stumbleupon-social-networks-auto-poster-wordpress/"><?php $nType="StumbleUpon"; printf( __( 'Detailed %s Installation/Configuration Instructions', 'nxs_snap' ), $nType); ?></a></div>
36
-
37
- <div style="width:100%;"><strong><?php _e('Account Nickname', 'nxs_snap'); ?>:</strong> <i><?php _e('Just so you can easely identify it', 'nxs_snap'); ?></i> </div><input name="su[<?php echo $ii; ?>][nName]" id="sunName<?php echo $ii; ?>" style="font-weight: bold; color: #005800; border: 1px solid #ACACAC; width: 40%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['nName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /><br/>
38
- <?php echo nxs_addQTranslSel('su', $ii, $options['qTLng']); ?><?php echo nxs_addPostingDelaySel('su', $ii, $options['nHrs'], $options['nMin']); ?>
39
-
40
- <?php if (!$isNew) { ?>
41
- <div style="width:100%;"><strong><?php _e('Categories', 'nxs_snap'); ?>:</strong>
42
- <input value="0" id="catSelA<?php echo $ii; ?>" type="radio" name="su[<?php echo $ii; ?>][catSel]" <?php if ((int)$options['catSel'] != 1) echo "checked"; ?> /> All
43
- <input value="1" id="catSelSSU<?php echo $ii; ?>" type="radio" name="su[<?php echo $ii; ?>][catSel]" <?php if ((int)$options['catSel'] == 1) echo "checked"; ?> /> <a href="#" style="text-decoration: none;" class="showCats" id="nxs_SCA_SU<?php echo $ii; ?>" onclick="jQuery('#catSelSSU<?php echo $ii; ?>').attr('checked', true); jQuery('#tmpCatSelNT').val('SU<?php echo $ii; ?>'); nxs_markCats( jQuery('#nxs_SC_SU<?php echo $ii; ?>').val() ); jQuery('#showCatSel').bPopup({ modalClose: false, appendTo: '#nsStForm', opacity: 0.6, follow: [false, false], position: [75, 'auto']}); return false;">Selected<?php if ($options['catSelEd']!='') echo "[".(substr_count($options['catSelEd'], ",")+1)."]"; ?></a>
44
- <input type="hidden" name="su[<?php echo $ii; ?>][catSelEd]" id="nxs_SC_SU<?php echo $ii; ?>" value="<?php echo $options['catSelEd']; ?>" />
45
- <br/><i><?php _e('Only selected categories will be autoposted to this account', 'nxs_snap'); ?></i></div>
46
- <br/>
47
- <?php } ?>
48
-
49
- <div style="width:100%;"><strong>StumbleUpon Username:</strong> </div><input name="su[<?php echo $ii; ?>][apSUUName]" id="apSUUName" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($options['suUName'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" />
50
- <div style="width:100%;"><strong>StumbleUpon Password:</strong> </div><input name="su[<?php echo $ii; ?>][apSUPass]" id="apSUPass" type="password" style="width: 30%;" value="<?php _e(apply_filters('format_to_edit', htmlentities(substr($options['suPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($options['suPass'], 5)):$options['suPass'], ENT_COMPAT, "UTF-8")), 'nxs_snap') ?>" /> <br/>
51
-
52
- <?php if ($isNew) { ?> <input type="hidden" name="su[<?php echo $ii; ?>][apDoSU]" value="1" id="apDoNewSU<?php echo $ii; ?>" /> <?php } ?>
53
- <br/>
54
-
55
- <div id="altFormat" style="">
56
- <div style="width:100%;"><strong id="altFormatText">StumbleUpon Category:</strong> </div>
57
-
58
- <select name="su[<?php echo $ii; ?>][apSUCat]" id="apSUCat<?php echo $ii; ?>"><option value="error" selected="selected" disabled="">Select default StumbleUpon Category</option>
59
- <?php $suCats = $this->suCats();
60
- if (isset($options['suCat']) && $options['suCat']!='') $suCats = str_replace('"'.$options['suCat'].'"', '"'.$options['suCat'].'" selected="selected"', $suCats); echo $suCats;
61
-
62
- ?>
63
- </select>
64
- <input value="1" id="suInclTags" type="checkbox" name="su[<?php echo $ii; ?>][nsfw]" <?php if ((int)$options['nsfw'] == 1) echo "checked"; ?> /> <strong>NSFW</strong>
65
- </div>
66
-
67
- <p style="margin-bottom: 20px;margin-top: 5px;"><input value="1" id="suInclTags" type="checkbox" name="su[<?php echo $ii; ?>][suInclTags]" <?php if ((int)$options['suInclTags'] == 1) echo "checked"; ?> />
68
- <strong>Post with tags</strong> Tags from the blogpost will be auto posted to StumbleUpon
69
- </p>
70
-
71
- <div id="altFormat" style="">
72
- <div style="width:100%;"><strong id="altFormatText"><?php _e('Post Text Format', 'nxs_snap'); ?></strong> (<a href="#" id="apSUMsgFrmt<?php echo $ii; ?>HintInfo" onclick="mxs_showHideFrmtInfo('apSUMsgFrmt<?php echo $ii; ?>'); return false;"><?php _e('Show format info', 'nxs_snap'); ?></a>)</div>
73
-
74
- <textarea cols="150" rows="3" id="su<?php echo $ii; ?>SNAPformat" name="su[<?php echo $ii; ?>][apSUMsgFrmt]" style="width:51%;max-width: 650px;" onfocus="jQuery('#su<?php echo $ii; ?>SNAPformat').attr('rows', 6); mxs_showFrmtInfo('apSUMsgFrmt<?php echo $ii; ?>');"><?php if ($isNew) echo "%TITLE% - %EXCERPT%"; else _e(apply_filters('format_to_edit', htmlentities($options['suMsgFormat'], ENT_COMPAT, "UTF-8")), 'nxs_snap'); ?></textarea>
75
-
76
-
77
- <?php nxs_doShowHint("apSUMsgFrmt".$ii); ?>
78
- </div><br/>
79
-
80
- <?php if ($options['suPass']!='') { ?>
81
- <?php wp_nonce_field( 'rePostToSU', 'rePostToSU_wpnonce' ); ?>
82
- <b><?php _e('Test your settings', 'nxs_snap'); ?>:</b>&nbsp;&nbsp;&nbsp; <a href="#" class="NXSButton" onclick="testPost('SU', '<?php echo $ii; ?>'); return false;"><?php printf( __( 'Submit Test Post to %s' , 'nxs_snap'), $nType); ?></a>
83
-
84
- <?php }
85
-
86
- ?><div class="submit"><input type="submit" class="button-primary" name="update_NS_SNAutoPoster_settings" value="<?php _e('Update Settings', 'nxs_snap') ?>" /></div></div><?php
87
- }
88
- //#### Set Unit Settings from POST
89
- function setNTSettings($post, $options){ global $nxs_snapThisPageUrl; $code = 'SU'; $lcode = 'su';
90
- foreach ($post as $ii => $pval){
91
- if (isset($pval['apSUUName']) && $pval['apSUUName']!=''){ if (!isset($options[$ii])) $options[$ii] = array();
92
- if (isset($pval['apSUUName'])) $options[$ii]['suUName'] = trim($pval['apSUUName']);
93
- if (isset($pval['nName'])) $options[$ii]['nName'] = trim($pval['nName']);
94
- if (isset($pval['apSUPass'])) $options[$ii]['suPass'] = 'n5g9a'.nsx_doEncode($pval['apSUPass']); else $options[$ii]['suPass'] = '';
95
- if (isset($pval['apSUCat'])) $options[$ii]['suCat'] = trim($pval['apSUCat']);
96
- if (isset($pval['suInclTags'])) $options[$ii]['suInclTags'] = $pval['suInclTags']; else $options[$ii]['suInclTags'] = 0;
97
- if (isset($pval['apSUMsgFrmt'])) $options[$ii]['suMsgFormat'] = trim($pval['apSUMsgFrmt']);
98
-
99
- if (isset($pval['catSel'])) $options[$ii]['catSel'] = trim($pval['catSel']);
100
- if ($options[$ii]['catSel']=='1' && trim($pval['catSelEd'])!='') $options[$ii]['catSelEd'] = trim($pval['catSelEd']); else $options[$ii]['catSelEd'] = '';
101
-
102
- if (isset($pval['apDoSU'])) $options[$ii]['doSU'] = $pval['apDoSU']; else $options[$ii]['doSU'] = 0;
103
- if (isset($pval['nsfw'])) $options[$ii]['nsfw'] = $pval['nsfw']; else $options[$ii]['nsfw'] = 0;
104
- if (isset($pval['delayHrs'])) $options[$ii]['nHrs'] = trim($pval['delayHrs']); if (isset($pval['delayMin'])) $options[$ii]['nMin'] = trim($pval['delayMin']);
105
- if (isset($pval['qTLng'])) $options[$ii]['qTLng'] = trim($pval['qTLng']);
106
- }
107
- } return $options;
108
- }
109
- //#### Show Post->Edit Meta Box Settings
110
- function showEdPostNTSettings($ntOpts, $post){ global $nxs_plurl; $post_id = $post->ID;
111
- foreach($ntOpts as $ii=>$ntOpt) { $pMeta = maybe_unserialize(get_post_meta($post_id, 'snapSU', true)); if (is_array($pMeta)) $ntOpt = $this->adjMetaOpt($ntOpt, $pMeta[$ii]);
112
- $doSU = $ntOpt['doSU'] && (is_array($pMeta) || $ntOpt['catSel']!='1');
113
- $isAvailSU = $ntOpt['suUName']!='' && $ntOpt['suPass']!=''; $suMsgFormat = htmlentities($ntOpt['suMsgFormat'], ENT_COMPAT, "UTF-8"); $suMsgTFormat = htmlentities($ntOpt['suMsgTFormat'], ENT_COMPAT, "UTF-8");
114
- ?>
115
- <tr><th style="text-align:left;" colspan="2"><?php if ( $ntOpt['catSel']=='1' && trim($ntOpt['catSelEd'])!='' ) { ?> <input type="hidden" class="nxs_SC" id="nxs_SC_SU<?php echo $ii; ?>" value="<?php echo $ntOpt['catSelEd']; ?>" /> <?php } ?>
116
- <?php if ($isAvailSU) { ?><input class="nxsGrpDoChb" value="1" id="doSU<?php echo $ii; ?>" <?php if ($post->post_status == "publish") echo 'disabled="disabled"';?> type="checkbox" name="su[<?php echo $ii; ?>][doSU]" <?php if ((int)$doSU == 1) echo 'checked="checked" title="def"'; ?> />
117
- <?php if ($post->post_status == "publish") { ?> <input type="hidden" name="su[<?php echo $ii; ?>][doSU]" value="<?php echo $doSU;?>"> <?php } ?> <?php } ?>
118
-
119
- <div class="nsx_iconedTitle" style="display: inline; font-size: 13px; background-image: url(<?php echo $nxs_plurl; ?>img/su16.png);">StumbleUpon - <?php _e('publish to', 'nxs_snap') ?> (<i style="color: #005800;"><?php echo $ntOpt['nName']; ?></i>)</div></th> <td><?php //## Only show RePost button if the post is "published"
120
- if ($post->post_status == "publish" && $isAvailSU) { ?><input alt="<?php echo $ii; ?>" style="float: right;" onmouseout="hidePopShAtt('SV');" onmouseover="showPopShAtt('SV', event);" onclick="return false;" type="button" class="button" name="rePostToSU_repostButton" id="rePostToSU_button" value="<?php _e('Repost to StumbleUpon', 'nxs_snap') ?>" />
121
- <?php wp_nonce_field( 'rePostToSU', 'rePostToSU_wpnonce' ); } ?>
122
-
123
- <?php if (is_array($pMeta) && is_array($pMeta[$ii]) && isset($pMeta[$ii]['pgID']) ) {
124
-
125
- ?> <span id="pstdSU<?php echo $ii; ?>" style="float: right;padding-top: 4px; padding-right: 10px;">
126
- <a style="font-size: 10px;" href="http://www.stumbleupon.com/content/<?php echo $pMeta[$ii]['pgID']; ?>" target="_blank"><?php $nType="Stumbleupon"; printf( __( 'Posted on', 'nxs_snap' ), $nType); ?> <?php echo (isset($pMeta[$ii]['pDate']) && $pMeta[$ii]['pDate']!='')?(" (".$pMeta[$ii]['pDate'].")"):""; ?></a>
127
- </span><?php } ?>
128
- </td></tr>
129
-
130
- <?php if (!$isAvailSU) { ?><tr><th scope="row" style="text-align:right; width:150px; padding-top: 5px; padding-right:10px;"></th> <td><b>Setup your StumbleUpon Account to AutoPost to StumbleUpon</b>
131
- <?php } elseif ($post->post_status != "puZblish") { ?>
132
-
133
- <tr id="altFormat1" style=""><th scope="row" style="text-align:right; width:60px; padding-right:10px;">Category:</th>
134
- <td><div id="altFormat" style="">
135
- <select name="su[<?php echo $ii; ?>][apSUCat]" id="apSUCat<?php echo $ii; ?>"><option value="error" selected="selected" disabled="">Select default StumbleUpon Category</option>
136
- <?php $suCats = $this->suCats();
137
- if (isset($ntOpt['suCat']) && $ntOpt['suCat']!='') $suCats = str_replace('"'.$ntOpt['suCat'].'"', '"'.$ntOpt['suCat'].'" selected="selected"', $suCats); echo $suCats;
138
- ?>
139
- </select> <input value="1" id="sunsfw<?php echo $ii; ?>" type="checkbox" name="su[<?php echo $ii; ?>][nsfw]" <?php if ((int)$options['nsfw'] == 1) echo "checked"; ?> /> <strong>NSFW</strong>
140
-
141
- </div> </td></tr>
142
-
143
- <tr id="altFormat1" style=""><th scope="row" style="vertical-align:top; padding-top:6px; text-align:right; width:60px; padding-right:10px;"><?php _e('Text Format:', 'nxs_snap') ?></th>
144
- <td>
145
- <textarea cols="150" rows="1" id="su<?php echo $ii; ?>SNAPformat" name="su[<?php echo $ii; ?>][SNAPformat]" style="width:60%;max-width: 610px;" onfocus="jQuery('#su<?php echo $ii; ?>SNAPformat').attr('rows', 4); jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apSUMsgFrmt<?php echo $ii; ?>');"><?php echo $suMsgFormat; ?></textarea>
146
- <?php nxs_doShowHint("apSUMsgFrmt".$ii); ?></td></tr>
147
- <?php }
148
- }
149
- }
150
- //#### Save Meta Tags to the Post
151
- function adjMetaOpt($optMt, $pMeta){ if (isset($pMeta['isPosted'])) $optMt['isPosted'] = $pMeta['isPosted']; else $optMt['isPosted'] = '';
152
- if (isset($pMeta['nsfw'])) $optMt['nsfw'] = $pMeta['nsfw'];
153
- if (isset($pMeta['SNAPformat'])) $optMt['suMsgFormat'] = $pMeta['SNAPformat'];
154
- if (isset($pMeta['apSUCat'])) $optMt['suCat'] = $pMeta['apSUCat'];
155
- if (isset($pMeta['doSU'])) $optMt['doSU'] = $pMeta['doSU'] == 1?1:0; else { if (isset($pMeta['SNAPformat'])) $optMt['doSU'] = 0; }
156
- if (isset($pMeta['SNAPincludeSU']) && $pMeta['SNAPincludeSU'] == '1' ) $optMt['doSU'] = 1;
157
- return $optMt;
158
- }
159
- }}
160
- if (!function_exists("nxs_rePostToSU_ajax")) {
161
- function nxs_rePostToSU_ajax() { check_ajax_referer('rePostToSU'); $postID = $_POST['id']; $options = get_option('NS_SNAutoPoster');
162
- foreach ($options['su'] as $ii=>$two) if ($ii==$_POST['nid']) { $two['ii'] = $ii; $two['pType'] = 'aj'; //if ($two['gpPageID'].$two['gpUName']==$_POST['nid']) {
163
- $gppo = get_post_meta($postID, 'snapSU', true); $gppo = maybe_unserialize($gppo);// prr($gppo);
164
- if (is_array($gppo) && isset($gppo[$ii]) && is_array($gppo[$ii])){ $ntClInst = new nxs_snapClassSU(); $two = $ntClInst->adjMetaOpt($two, $gppo[$ii]); }
165
- $result = nxs_doPublishToSU($postID, $two); if ($result == 200) die("Successfully sent your post to StumbleUpon."); else die($result);
166
- }
167
- }
168
- }
169
-
170
- if (!function_exists("nxs_getSUHeaders")) { function nxs_getSUHeaders($ref, $post=false, $xhr=true){ $hdrsArr = array();
171
- if ($xhr) $hdrsArr['X-Requested-With']='XMLHttpRequest';
172
- $hdrsArr['Connection']='keep-alive'; $hdrsArr['Referer']=$ref;
173
- $hdrsArr['User-Agent']='Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)';
174
- if($post) $hdrsArr['Content-Type']='application/x-www-form-urlencoded';
175
- if ($xhr) $hdrsArr['Accept']='application/json, text/javascript, */*; q=0.01'; else $hdrsArr['Accept']='text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
176
- $hdrsArr['Origin']='http://www.stumbleupon.com';
177
- $hdrsArr['Accept-Encoding']='gzip,deflate,sdch'; $hdrsArr['Accept-Language']='en-US,en;q=0.8'; $hdrsArr['Accept-Charset']='ISO-8859-1,utf-8;q=0.7,*;q=0.3'; return $hdrsArr;
178
- }}
179
- if (!function_exists("nxs_doCheckSU")) {function nxs_doCheckSU(){ global $nxs_suCkArray; $hdrsArr = nxs_getSUHeaders('https://www.stumbleupon.com/submit'); $ckArr = $nxs_suCkArray;
180
- $response = wp_remote_get('http://www.stumbleupon.com/submit', array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'cookies' => $ckArr));
181
- $response['body'] = htmlentities($response['body'], ENT_COMPAT, "UTF-8"); // $response['body'] = htmlentities($response['body']); prr($response); die();
182
- if (isset($response['headers']['location']) && $response['headers']['location']=='/submit/visitor') return 'Bad Saved Login';
183
- if ( $response['response']['code']=='200' && stripos($response['body'], 'Add a New Page')!==false){
184
-
185
-
186
- /*echo "You are IN"; */ return false;
187
- } else return 'No Saved Login';
188
- return false;
189
- }}
190
- if (!function_exists("nxs_doConnectToSU")) { function nxs_doConnectToSU($u, $p){ global $nxs_suCkArray; $hdrsArr = nxs_getSUHeaders('https://www.stumbleupon.com/login', true); // echo "LOGGIN";
191
- $response = wp_remote_get('https://www.stumbleupon.com/login'); if (is_wp_error($response)) { nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- '.print_r($response, true), ''); return "Connection ERROR. Please see log";}
192
- $contents = $response['body']; //$response['body'] = htmlentities($response['body']); prr($response); die();
193
- $ckArr = $response['cookies'];
194
- $frmTxt = CutFromTo($contents, '<form id="login-form"','</form>'); $md = array(); $flds = array();// prr($frmTxt);
195
- while (stripos($frmTxt, '<input')!==false){ $inpField = trim(CutFromTo($frmTxt,'<input', '>')); $name = trim(CutFromTo($inpField,'name="', '"'));
196
- if ( stripos($inpField, '"hidden"')!==false && $name!='' && !in_array($name, $md)) { $md[] = $name; $val = trim(CutFromTo($inpField,'value="', '"')); $flds[$name]= $val; $mids .= "&".$name."=".$val;}
197
- $frmTxt = substr($frmTxt, stripos($frmTxt, '<input')+8);
198
- } $flds['user'] = $u; $flds['pass'] = $p; $flds['remember'] = 'true'; $flds['nativeSubmit'] = '0'; $flds['_method'] = 'create';
199
-
200
- $r2 = wp_remote_post( 'https://www.stumbleupon.com/login', array( 'method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'body' => $flds, 'cookies' => $ckArr));
201
- //prr($flds); prr($ckArr); prr($r2);
202
- $resp = json_decode($r2['body'], true);
203
- if ($resp['_success']=='1') { $ckArr = nxsMergeArraysOV($ckArr, $r2['cookies']); $nxs_suCkArray = $ckArr; return false; } elseif (isset($resp['_reason'])) { return $resp['_reason']; } else return "ERROR";
204
- }}
205
- if (!function_exists("nxs_doPostToSU")) { function nxs_doPostToSU($msg, $lnk, $cat, $tags, $nsfw=false){ global $nxs_suCkArray; $r2 = wp_remote_get($lnk);
206
- $hdrsArr = nxs_getSUHeaders('https://www.stumbleupon.com/submit', false, false); $ckArr = $nxs_suCkArray;
207
- $response = wp_remote_get('https://www.stumbleupon.com/submit', array( 'method' => 'GET', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'cookies' => $ckArr));
208
- $ckArr2 = nxsMergeArraysOV($ckArr, $response['cookies']); //$nxs_suCkArray = $ckArr;
209
-
210
- $contents = $response['body']; //$response['body'] = htmlentities($response['body']); prr($response);
211
- //$ckArr = nxsMergeArraysOV($ckArr, $response['cookies']);
212
- $hdrsArr = nxs_getSUHeaders('https://www.stumbleupon.com/submit', true);
213
- $frmTxt = CutFromTo($contents, '<form method="post" id="submit-form"','</form>'); $md = array(); $flds = array(); // prr($contents);
214
- while (stripos($frmTxt, '<input')!==false){ $inpField = trim(CutFromTo($frmTxt,'<input', '>')); $name = trim(CutFromTo($inpField,'name="', '"'));
215
- if ( stripos($inpField, '"hidden"')!==false && $name!='' && !in_array($name, $md)) { $md[] = $name; $val = trim(CutFromTo($inpField,'value="', '"')); $flds[$name]= $val; $mids .= "&".$name."=".$val;}
216
- $frmTxt = substr($frmTxt, stripos($frmTxt, '<input')+8);
217
- } $flds['url'] = $lnk; $flds['review'] = $msg; $flds['tags'] = $cat; $flds['nsfw'] = $nsfw?'true':'false'; $flds['user-tags'] = $tags; $flds['_output'] = 'Json'; $flds['_method'] = 'create'; $flds['language'] = 'EN';
218
-
219
- $r2 = wp_remote_post('https://www.stumbleupon.com/submit', array('method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'body' => $flds, 'cookies' => $ckArr));
220
- $resp = json_decode($r2['body'], true);
221
-
222
- if (stripos($resp['_reason'][0]['message'], 'Failed to add URL')!==false) { sleep(5);
223
- $r2 = wp_remote_post('https://www.stumbleupon.com/submit', array('method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'body' => $flds, 'cookies' => $ckArr));
224
- $resp = json_decode($r2['body'], true);
225
- }
226
-
227
- if (stripos($resp['_error'], 'Invalid token')!==false) { // In case we got the Wrong Cookies
228
- $r2 = wp_remote_post('https://www.stumbleupon.com/submit', array('method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'body' => $flds, 'cookies' => $ckArr2));
229
- $resp = json_decode($r2['body'], true);
230
-
231
- if (stripos($resp['_reason'][0]['message'], 'Failed to add URL')!==false) { sleep(5);
232
- $r2 = wp_remote_post('https://www.stumbleupon.com/submit', array('method' => 'POST', 'timeout' => 45, 'redirection' => 0, 'headers' => $hdrsArr, 'body' => $flds, 'cookies' => $ckArr2));
233
- $resp = json_decode($r2['body'], true); // prr($flds); prr($resp); //nxs_addToLogN('SU', 'E', '-=DBG=- '.print_r($resp, true)." - #####", $extInfo);
234
- }
235
- }
236
-
237
- if (isset($resp['discovery']['publicid'])) $pageID = $resp['discovery']['publicid']; elseif (isset($resp['discovery']['url']['publicid']))$pageID = $resp['discovery']['url']['publicid'];
238
- if ($resp['_success']=='1') { $ckArr = nxsMergeArraysOV($ckArr, $r2['cookies']); $nxs_suCkArray = $ckArr; return array("code"=>"OK", "post_id"=>$pageID); }
239
- elseif (isset($resp['_reason'])) { $resp['_reason']['NXS_FIELDS'] = $flds; $resp['_reason']['NXS_RESP'] = $resp; return $resp['_reason']; } else return "ERROR".print_r($resp, true);
240
- }}
241
-
242
- if (!function_exists("nxs_doPublishToSU")) { //## Second Function to Post to SU
243
- function nxs_doPublishToSU($postID, $options){ global $nxs_suCkArray; $ntCd = 'SU'; $ntCdL = 'su'; $ntNm = 'StumbleUpon';
244
- //$backtrace = debug_backtrace(); nxs_addToLogN('W', 'Enter', $ntCd, 'I am here - '.$ntCd."|".print_r($backtrace, true), '');
245
- //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToSU', array($postID, $options));
246
- $ii = $options['ii']; if (!isset($options['pType'])) $options['pType'] = 'im'; if ($options['pType']=='sh') sleep(rand(1, 10));
247
- $logNT = '<span style="color:#000080">StumbleUpon</span> - '.$options['nName'];
248
- $snap_ap = get_post_meta($postID, 'snap'.$ntCd, true); $snap_ap = maybe_unserialize($snap_ap);
249
- if ($options['reset'] != '1' && $options['pType']!='aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
250
- $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted!='2') { sleep(5);
251
- nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:'.$postID, 'Already posted. No reason for posting duplicate'.' |'.$uqID); return;
252
- }
253
- }
254
- $suCat = $options['suCat'];
255
- // if (function_exists("get_post_thumbnail_id") ){ $src = wp_get_attachment_image_src(get_post_thumbnail_id($postID), 'thumbnail'); $src = $src[0];}
256
- $email = $options['suUName']; $pass = (substr($options['suPass'], 0, 5)=='n5g9a'?nsx_doDecode(substr($options['suPass'], 5)):$options['suPass']);
257
- if ($postID=='0') { echo "Testing ... <br/><br/>"; $link = home_url(); $msg = 'Test Link from '.$link; } else { $post = get_post($postID); if(!$post) return;
258
- $msgFormat = $options['suMsgFormat']; $msg = nsFormatMessage($msgFormat, $postID); $link = get_permalink($postID); nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted'=>'1'));
259
- }
260
- $dusername = $options['suUName']; //$link = urlencode($link); $desc = urlencode(substr($msg, 0, 500));
261
- $extInfo = ' | PostID: '.$postID." - ".$post->post_title;
262
- if ($options['suInclTags']=='1') { $t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) {$tggs[] = $tagA->name;} $tags = urlencode(implode(',',$tggs)); $tags = str_replace(' ','+',$tags); } else $tags = '';
263
- if (isset($options['suSvC'])) $nxs_suCkArray = maybe_unserialize( $options['suSvC']); $loginError = true;
264
- if (is_array($nxs_suCkArray)) $loginError = nxs_doCheckSU(); if ($loginError!=false) $loginErro