Advertisement
Guest User

NextScripts WordPress Social Networks Auto Poster Twitter

a guest
Dec 16th, 2012
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 22.85 KB | None | 0 0
  1. <?php    
  2. //## NextScripts Twitter Connection Class
  3. $nxs_snapAvNts[] = array('code'=>'TW', 'lcode'=>'tw', 'name'=>'Twitter');
  4.  
  5. if (!class_exists("nxs_snapClassTW")) { class nxs_snapClassTW {
  6.   //#### Show Common Settings  
  7.   function showGenNTSettings($ntOpts){ global $nxs_snapThisPageUrl, $nxs_plurl; $code = 'TW'; $lcode = 'tw'; wp_nonce_field( 'ns'.$code, 'ns'.$code.'_wpnonce' ); ?>
  8.     <hr/><div class="nsx_iconedTitle" style="background-image: url(<?php echo $nxs_plurl; ?>img/<?php echo $lcode; ?>16.png);">Twitter Settings:     <?php $ctwo = count($ntOpts); $mtwo = 1+max(array_keys($ntOpts)); ?>        
  9.     <div class="nsBigText">You have <?php echo $ctwo=='0'?'No':$ctwo; ?> Twitter account<?php if ($ctwo!=1){ ?>s<?php } ?> <!-- set - <a href="#" class="NXSButton" onclick="doShowHideBlocks2('TW<?php echo $mtwo; ?>');return false;">Add new Twitter Account</a> --></div><br/></div>
  10.     <?php // if (function_exists('nxs_doSMAS1')) nxs_doSMAS1($this, $mtwo); else nxs_doSMAS('Twitter', 'TW'.$mtwo);  ?>            
  11.     <?php foreach ($ntOpts as $indx=>$two){ if (trim($two['nName']=='')) $two['nName'] = str_ireplace('https://','', str_ireplace('http://','', $two['twURL'])); ?>            
  12.       <p style="margin: 0px;margin-left: 5px;"><input value="1" id="apDoTW" name="tw[<?php echo $indx; ?>][apDoTW]" type="checkbox" <?php if ((int)$two['doTW'] == 1) echo "checked"; ?> />
  13.         <strong>Auto-publish your Posts to your Twitter <i style="color: #005800;"><?php if($two['nName']!='') echo "(".$two['nName'].")"; ?></i></strong>                                
  14.         &nbsp;&nbsp;<a id="doTW<?php echo $indx; ?>A" href="#" onclick="doShowHideBlocks2('TW<?php echo $indx; ?>');return false;">[Show Settings]</a>&nbsp;&nbsp;
  15.         <a href="#" onclick="doDelAcct('tw','<?php echo $indx; ?>', '<?php echo $two['twURL']; ?>');return false;">[Remove Account]</a>
  16.       </p><?php $this->showNTSettings($indx, $two);            
  17.     } //## END TW Settings
  18.   }  
  19.   //#### Show NEW Settings Page
  20.   function showNewNTSettings($mtwo){ $two = array('nName'=>'', 'doTW'=>'1', 'twURL'=>'', 'twConsKey'=>'',  'twConsSec'=>'', 'twAccToken'=>'', 'twAccTokenSec'=>'', 'attchImg'=>0, 'twAttch'=>'', 'twAccTokenSec'=>''); $this->showNTSettings($mtwo, $two, true);}
  21.   //#### Show Unit  Settings
  22.   function showNTSettings($ii, $two, $isNew=false){ global $nxs_plurl; ?>
  23.     <div id="doTW<?php echo $ii; ?>Div" <?php if ($isNew){ ?>class="clNewNTSets"<?php } ?> style="max-width: 1000px; background-color: #EBF4FB; background-image: url(<?php echo $nxs_plurl; ?>img/tw-bg.png);  background-position:90% 10%; background-repeat: no-repeat; margin: 10px; border: 1px solid #808080; padding: 10px; <?php if ((isset($two['twOK']) && $two['twOK']=='1')||$isNew) { ?>display:none;<?php } ?>">   <input type="hidden" name="apDoSTW<?php echo $ii; ?>" value="0" id="apDoSTW<?php echo $ii; ?>" />      
  24.    
  25.      <div class="nsx_iconedTitle" style="float: right; background-image: url(<?php echo $nxs_plurl; ?>img/tw16.png);"><a style="font-size: 12px;" target="_blank"  href="http://www.nextscripts.com/setup-installation-twitter-social-networks-auto-poster-wordpress/">Detailed Twitter Installation/Configuration Instructions</a></div>
  26.    
  27.     <div style="width:100%;"><strong>Account Nickname:</strong> <i>Just so you can easely identify it</i> </div><input name="tw[<?php echo $ii; ?>][nName]" id="twnName<?php echo $ii; ?>" style="font-weight: bold; color: #005800; border: 1px solid #ACACAC; width: 40%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($two['nName'], ENT_COMPAT, "UTF-8")), 'NS_SNAutoPoster') ?>" /><br/>
  28.     <?php echo nxs_addQTranslSel('tw', $ii, $two['qTLng']); ?><?php echo nxs_addPostingDelaySel('tw', $ii, $two['nHrs'], $two['nMin']); ?>
  29.     <div style="width:100%;"><strong>Your Twitter URL:</strong> </div><input name="tw[<?php echo $ii; ?>][apTWURL]" id="apTWURL" style="width: 40%;border: 1px solid #ACACAC;" value="<?php _e(apply_filters('format_to_edit', htmlentities($two['twURL'], ENT_COMPAT, "UTF-8")), 'NS_SNAutoPoster') ?>" />
  30.     <div style="width:100%;"><strong>Your Twitter Consumer Key:</strong> </div><input name="tw[<?php echo $ii; ?>][apTWConsKey]" id="apTWConsKey" style="width: 40%; border: 1px solid #ACACAC;" value="<?php _e(apply_filters('format_to_edit', htmlentities($two['twConsKey'], ENT_COMPAT, "UTF-8")), 'NS_SNAutoPoster') ?>" />  
  31.     <div style="width:100%;"><strong>Your Twitter Consumer Secret:</strong> </div><input name="tw[<?php echo $ii; ?>][apTWConsSec]" id="apTWConsSec" style="width: 40%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($two['twConsSec'], ENT_COMPAT, "UTF-8")), 'NS_SNAutoPoster') ?>" />
  32.     <div style="width:100%;"><strong>Your Access Token:</strong> </div><input name="tw[<?php echo $ii; ?>][apTWAccToken]" id="apTWAccToken" style="width: 40%;" value="<?php _e(apply_filters('format_to_edit', htmlentities($two['twAccToken'], ENT_COMPAT, "UTF-8")), 'NS_SNAutoPoster') ?>" />
  33.     <div style="width:100%;"><strong>Your Access Token Secret:</strong> </div><input name="tw[<?php echo $ii; ?>][apTWAccTokenSec]" id="apTWAccTokenSec" style="width: 40%;" value="<?php  _e(apply_filters('format_to_edit', htmlentities($two['twAccTokenSec'], ENT_COMPAT, "UTF-8")), 'NS_SNAutoPoster') ?>" />
  34.     <?php if ($isNew) { ?> <input type="hidden" name="tw[<?php echo $ii; ?>][apDoTW]" value="1" id="apDoNewTW<?php echo $ii; ?>" /> <?php } ?>
  35.     <br/><br/>
  36.     <p style="margin: 0px;"><input value="1"  id="apLIAttch" type="checkbox" name="tw[<?php echo $ii; ?>][attchImg]"  <?php if ((int)$two['attchImg'] == 1) echo "checked"; ?> /> <strong>Attach Image to Twitter Post</strong></p>
  37.     <br/>
  38.     <strong id="altFormatText">Message Text Format:</strong>
  39.     <div style="width:100%;">
  40.       <p style="font-size: 11px; margin: 0px;">%SITENAME% - Inserts the Your Blog/Site Name. &nbsp; %TITLE% - Inserts the Title of your post. &nbsp; %URL% - Inserts the URL of your post. &nbsp; %SURL% - Inserts the <b>Shortened URL</b> of your post. &nbsp;  %TEXT% - Inserts the excerpt of your post. &nbsp;  %FULLTEXT% - Inserts the body(text) of your post, %AUTHORNAME% - Inserts the author's name. <i>Twitter takes only 140 characters.</i></p>
  41.     </div>
  42.     <input name="tw[<?php echo $ii; ?>][apTWMsgFrmt]" id="apTWMsgFrmt" style="width: 50%;" value="<?php if (!$isNew) _e(apply_filters('format_to_edit', htmlentities($two['twMsgFormat'], ENT_COMPAT, "UTF-8")), 'NS_SNAutoPoster'); else echo "%TITLE% - %URL%"; ?>" />
  43.                
  44.     <?php if($two['twAccTokenSec']!='') { ?> <?php wp_nonce_field( 'rePostToTW', 'rePostToTW_wpnonce' ); ?>
  45.       <br/><br/><b>Test your settings:</b>&nbsp;&nbsp;&nbsp; <?php if (!isset($two['twOK']) || $two['twOK']!='1') { ?> <div class="blnkg">=== Submit Test Post to Complete ===&gt;</div> <?php } ?> <a href="#" class="NXSButton" onclick="testPost('TW', '<?php echo $ii; ?>'); return false;">Submit Test Post to Twitter</a> <br/>
  46.       <?php }?>
  47.       <div class="submit"><input type="submit" class="button-primary" name="update_NS_SNAutoPoster_settings" value="<?php _e('Update Settings', 'NS_SNAutoPoster') ?>" /></div>
  48.     </div>
  49.     <?php
  50.   }
  51.   //#### Set Unit Settings from POST
  52.   function setNTSettings($post, $options){ global $nxs_snapThisPageUrl; $code = 'TW'; $lcode = 'tw';
  53.     foreach ($post as $ii => $pval){
  54.       if (isset($pval['apTWURL']) && $pval['apTWURL']!='') { if (!isset($options[$ii])) $options[$ii] = array();
  55.         if (isset($pval['apDoTW']))         $options[$ii]['doTW'] = $pval['apDoTW']; else $options[$ii]['doTW'] = 0;
  56.         if (isset($pval['nName']))          $options[$ii]['nName'] = trim($pval['nName']);
  57.         if (isset($pval['apTWURL']))        $options[$ii]['twURL'] = trim($pval['apTWURL']);  if ( substr($options[$ii]['twURL'], 0, 4)!='http' )  $options[$ii]['twURL'] = 'http://'.$options[$ii]['twURL'];
  58.         if (isset($pval['apTWConsKey']))    $options[$ii]['twConsKey'] = trim($pval['apTWConsKey']);
  59.         if (isset($pval['apTWConsSec']))    $options[$ii]['twConsSec'] = trim($pval['apTWConsSec']);                                
  60.         if (isset($pval['apTWAccToken']))   $options[$ii]['twAccToken'] = trim($pval['apTWAccToken']);                
  61.         if (isset($pval['apTWAccTokenSec']))$options[$ii]['twAccTokenSec'] = trim($pval['apTWAccTokenSec']);                                
  62.         if (isset($pval['apTWMsgFrmt']))    $options[$ii]['twMsgFormat'] = trim($pval['apTWMsgFrmt']);
  63.         if (isset($pval['attchImg'])) $options[$ii]['attchImg'] = $pval['attchImg']; else $options[$ii]['attchImg'] = 0;                
  64.         if (isset($pval['delayHrs'])) $options[$ii]['nHrs'] = trim($pval['delayHrs']); if (isset($pval['delayMin'])) $options[$ii]['nMin'] = trim($pval['delayMin']);
  65.         if (isset($pval['qTLng'])) $options[$ii]['qTLng'] = trim($pval['qTLng']);
  66.       }
  67.     } return $options;
  68.   }    
  69.   //#### Show Post->Edit Meta Box Settings
  70.   function showEdPostNTSettings($ntOpts, $post){ global $nxs_plurl; $post_id = $post->ID;
  71.     foreach($ntOpts as $ii=>$ntOpt)  { $pMeta = maybe_unserialize(get_post_meta($post_id, 'snapTW', true));  if (is_array($pMeta)) $ntOpt = $this->adjMetaOpt($ntOpt, $pMeta[$ii]); $doTW = $ntOpt['doTW'];  
  72.          $isAvailTW =  $ntOpt['twURL']!='' && $ntOpt['twConsKey']!='' && $ntOpt['twConsSec']!='' && $ntOpt['twAccToken']!=''; $twMsgFormat = htmlentities($ntOpt['twMsgFormat'], ENT_COMPAT, "UTF-8");   $isAttchImg = $ntOpt['attchImg'];    
  73.       ?>  
  74.       <tr><th style="text-align:left;" colspan="2">
  75.       <?php if ($isAvailTW) { ?><input class="nxsGrpDoChb" value="1" <?php if ($post->post_status == "publish") echo 'disabled="disabled"';?> type="checkbox" name="tw[<?php echo $ii; ?>][SNAPincludeTW]" <?php if (($post->post_status == "publish" && $ntOpt['isPosted'] == '1') || ($post->post_status != "publish" && ((int)$doTW == 1)) ) echo 'checked="checked" title="def"';  ?> /> <?php } ?>
  76.       <div class="nsx_iconedTitle" style="display: inline; font-size: 13px; background-image: url(<?php echo $nxs_plurl; ?>img/tw16.png);">Twitter - publish to (<i style="color: #005800;"><?php echo $ntOpt['nName']; ?></i>)</div></th><td><?php //## Only show RePost button if the post is "published"
  77.                     if ($post->post_status == "publish" && $isAvailTW) { ?><input alt="<?php echo $ii; ?>" style="float: right;" onmouseout="hidePopShAtt('SV');" onmouseover="showPopShAtt('SV', event);" onclick="return false;" type="button" class="button" name="rePostToTW_repostButton" id="rePostToTW_button" value="<?php _e('Repost to Twitter', 're-post') ?>" />
  78.                     <?php wp_nonce_field( 'rePostToTW', 'rePostToTW_wpnonce' ); } ?>
  79.                 </td></tr>
  80.                 <?php if (!$isAvailTW) { ?><tr><th scope="row" style="text-align:right; width:150px; padding-top: 5px; padding-right:10px;"></th> <td><b>Setup your Twitter Account to AutoPost to Twitter</b>
  81.                 <?php }elseif ($post->post_status != "puZblish") { ?>
  82.                
  83.                 <tr id="altFormat1" style=""><th scope="row" style="text-align:right; width:60px; padding-right:10px;"><?php _e('Message Format:', 'NS_SPAP') ?></th>
  84.                 <td><input value="<?php echo $twMsgFormat ?>" type="text" name="tw[<?php echo $ii; ?>][SNAPformat]"  style="width:60%;max-width: 610px;" onfocus="jQuery('.nxs_FRMTHint').hide();mxs_showFrmtInfo('apTWMsgFrmt<?php echo $ii; ?>');"/><?php nxs_doShowHint("apTWMsgFrmt".$ii); ?></td></tr>
  85.                
  86. <tr><th scope="row" style="text-align:right; width:150px; vertical-align:top; padding-top: 5px; padding-right:10px;">
  87.                  <input value="1" type="checkbox" name="tw[<?php echo $ii; ?>][attchImg]"  <?php if ((int)$isAttchImg == 1) echo "checked"; ?> /> </th><td><strong>Attach Image to Twitter Post</strong></td> </tr>                  
  88.        <?php }
  89.     }
  90.   }
  91.   //####
  92.   function adjMetaOpt($optMt, $pMeta){  if (isset($pMeta['isPosted'])) $optMt['isPosted'] = $pMeta['isPosted']; else $optMt['isPosted'] = '';
  93.      if (isset($pMeta['SNAPformat'])) $optMt['twMsgFormat'] = $pMeta['SNAPformat'];
  94.      if (isset($pMeta['attchImg'])) $optMt['attchImg'] = $pMeta['attchImg'] == 1?1:0; else { if (isset($pMeta['attchImg'])) $optMt['attchImg'] = 0; }
  95.      if (isset($pMeta['SNAPincludeTW'])) $optMt['doTW'] = $pMeta['SNAPincludeTW'] == 1?1:0; else { if (isset($pMeta['SNAPformat'])) $optMt['doTW'] = 0; } return $optMt;
  96.   }
  97. }}
  98.  
  99. if (!function_exists("nxs_rePostToTW_ajax")) {
  100.   function nxs_rePostToTW_ajax() { check_ajax_referer('rePostToTW');  $postID = $_POST['id']; $options = get_option('NS_SNAutoPoster');  
  101.     foreach ($options['tw'] as $ii=>$two) if ($ii==$_POST['nid']) {   $two['ii'] = $ii;  $two['pType'] = 'aj';
  102.       $twpo =  get_post_meta($postID, 'snapTW', true); $twpo =  maybe_unserialize($twpo);
  103.       if (is_array($twpo) && isset($twpo[$ii]) && is_array($twpo[$ii]) && isset($twpo[$ii]['SNAPformat']) ) { $ntClInst = new nxs_snapClassTW(); $two = $ntClInst->adjMetaOpt($two, $twpo[$ii]);}
  104.       $result = nxs_doPublishToTW($postID, $two); if ($result == 201) {$options['tw'][$ii]['twOK']=1;  update_option('NS_SNAutoPoster', $options); } if ($result == 200) die("Successfully sent your post to Twitter."); else die($result);
  105.     }
  106.   }
  107. }
  108.  
  109. if (!function_exists("nxs_doPublishToTW")) { //## Second Function to Post to TW
  110.   function nxs_doPublishToTW($postID, $options){ $ntCd = 'TW'; $ntCdL = 'tw'; $ntNm = 'Twitter'; $img = ''; $imgURL = '';
  111.    
  112.     $ii = $options['ii']; if (!isset($options['pType'])) $options['pType'] = 'im'; if ($options['pType']=='sh') sleep(rand(1, 10)); $snap_ap = get_post_meta($postID, 'snap'.$ntCd, true); $snap_ap = maybe_unserialize($snap_ap);    
  113.     if ($options['pType']!='aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) {
  114.         nxs_addToLog($ntCd.' - '.$options['nName'], 'E', '-=Duplicate=- Post ID:'.$postID, 'Not posted. No reason for posting duplicate'); return;
  115.     }
  116.    
  117.     if (isset($options['qTLng'])) $lng = $options['qTLng']; else $lng = '';
  118.     $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle=='') $blogTitle = home_url(); $uln = 0;
  119.    
  120.     if ($options['attchImg']=='1') { $imgURL = nxs_getPostImage($postID); if(trim($imgURL)=='') $options['attchImg'] = 0; else {  
  121.       if (@getimagesize($imgURL)!==false) { $img = wp_remote_get($imgURL); if(is_wp_error($img)) $options['attchImg'] = 0; else $img = $img['body']; } else $options['attchImg'] = 0;
  122.     }}
  123.     if ($options['attchImg']=='1' && $img!='') $twLim = 119; else $twLim = 140;
  124.    
  125.     if ($postID=='0') { echo "Testing ... <br/><br/>"; $msg = 'Test Post from '.$blogTitle." - ".rand(1, 155); $uln = strlen($msg);}  
  126.     else{ $post = get_post($postID); if(!$post) return; $twMsgFormat = $options['twMsgFormat'];  nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted'=>'1'));        
  127.         if (stripos($twMsgFormat, '%URL%')!==false || stripos($twMsgFormat, '%SURL%')!==false) $twLim = $twLim - 20;
  128.         if (stripos($twMsgFormat, '%AUTHORNAME%')!==false) { $aun = $post->post_author;  $aun = get_the_author_meta('display_name', $aun ); $twLim = $twLim - strlen($aun); }
  129.        
  130.         $noRepl = str_ireplace("%TITLE%", "", $twMsgFormat); $noRepl = str_ireplace("%SITENAME%", "", $noRepl); $noRepl = str_ireplace("%URL%", "", $noRepl);
  131.         $noRepl = str_ireplace("%SURL%", "", $noRepl);$noRepl = str_ireplace("%TEXT%", "", $noRepl);$noRepl = str_ireplace("%FULLTEXT%", "", $noRepl);
  132.         $noRepl = str_ireplace("%AUTHORNAME%", "", $noRepl); $twLim = $twLim - strlen($noRepl);
  133.        
  134.         $pTitle = $title = nxs_doQTrans($post->post_title, $lng);
  135.         if ($post->post_excerpt!="") $pText = apply_filters('the_content', $post->post_excerpt); else $pText= apply_filters('the_content', nxs_doQTrans($post->post_content, $lng));
  136.         $pFullText = apply_filters('the_content', nxs_doQTrans($post->post_content, $lng));
  137.         $pRawText = nxs_doQTrans($post->post_content, $lng);
  138.        
  139.         if (stripos($twMsgFormat, '%TAGS%')!==false) {
  140.           $t = wp_get_post_tags($postID); $tggs = array(); foreach ($t as $tagA) { $frmTag =  str_replace(' ','_', str_replace('  ',' ',preg_replace("/[^A-Za-z0-9\s\s+\_]/","",$tagA->name)));
  141.               if (stripos($pTitle, $tagA->name)!=false) $pTitle = str_ireplace($tagA->name, '#'.$frmTag, $pTitle); elseif (stripos($pTitle, $frmTag)!=false) $pTitle = str_ireplace($frmTag, '#'.$frmTag, $pTitle);
  142.               if (stripos($pText, $tagA->name)!=false) $pText = str_ireplace($tagA->name, '#'.$frmTag, $pText); elseif (stripos($pText, $frmTag)!=false) $pText = str_ireplace($frmTag, '#'.$frmTag, $pText);
  143.               if (stripos($pFullText, $tagA->name)!=false) $pFullText = str_ireplace($tagA->name, '#'.$frmTag, $pFullText); elseif (stripos($pFullText, $frmTag)!=false) $pFullText = str_ireplace($frmTag, '#'.$frmTag, $pFullText);
  144.               if (stripos($pRawText, $tagA->name)!=false) $pRawText = str_ireplace($tagA->name, '#'.$frmTag, $pRawText); elseif (stripos($pRawText, $frmTag)!=false) $pRawText = str_ireplace($frmTag, '#'.$frmTag, $pRawText);
  145.               if ( ((stripos($twMsgFormat, '%TITLE%')!==false) && (stripos($pTitle, $tagA->name)!=false || stripos($pTitle, $frmTag)!=false)) ||
  146.                    ((stripos($twMsgFormat, '%TEXT%')!==false) && (stripos($pText, $tagA->name)!=false || stripos($pText, $frmTag)!=false)) ||
  147.                    ((stripos($twMsgFormat, '%FULLTEXT%')!==false) && (stripos($pFullText, $tagA->name)!=false || stripos($pFullText, $frmTag)!=false)) ||
  148.                    ((stripos($twMsgFormat, '%RAWTEXT%')!==false) && (stripos($pRawText, $tagA->name)!=false || stripos($pRawText, $frmTag)!=false)) ) {} else $tggs[] = '#'.$frmTag;
  149.           } $tags = implode(' ',$tggs); $twMsgFormat = str_ireplace("%TAGS%", $tags, $twMsgFormat); $twLim = $twLim - strlen($tags);
  150.         }
  151.         if (stripos($twMsgFormat, '%CATS%')!==false) {
  152.           $t = wp_get_post_categories($postID); $cats = array();  foreach($t as $c){ $cat = get_category($c); $frmTag =  str_replace(' ','_', str_replace('  ',' ',str_ireplace('&','&amp;',preg_replace("/[^A-Za-z0-9\s\s+\_]/","",$cat->name))));
  153.           if (stripos($pTitle, $cat->name)!=false) $pTitle = str_ireplace($cat->name, '#'.$frmTag, $pTitle); elseif (stripos($pTitle, $frmTag)!=false) $pTitle = str_ireplace($frmTag, '#'.$frmTag, $pTitle);
  154.               if (stripos($pText, $cat->name)!=false) $pText = str_ireplace($cat->name, '#'.$frmTag, $pText); elseif (stripos($pText, $frmTag)!=false) $pText = str_ireplace($frmTag, '#'.$frmTag, $pText);
  155.               if (stripos($pFullText, $cat->name)!=false) $pFullText = str_ireplace($cat->name, '#'.$frmTag, $pFullText); elseif (stripos($pFullText, $frmTag)!=false) $pFullText = str_ireplace($frmTag, '#'.$frmTag, $pFullText);
  156.               if (stripos($pRawText, $cat->name)!=false) $pRawText = str_ireplace($cat->name, '#'.$frmTag, $pRawText); elseif (stripos($pRawText, $frmTag)!=false) $pRawText = str_ireplace($frmTag, '#'.$frmTag, $pRawText);
  157.               if ( ((stripos($twMsgFormat, '%TITLE%')!==false) && (stripos($pTitle, $cat->name)!=false || stripos($pTitle, $frmTag)!=false)) ||
  158.                    ((stripos($twMsgFormat, '%TEXT%')!==false) && (stripos($pText, $cat->name)!=false || stripos($pText, $frmTag)!=false)) ||
  159.                    ((stripos($twMsgFormat, '%FULLTEXT%')!==false) && (stripos($pFullText, $cat->name)!=false || stripos($pFullText, $frmTag)!=false)) ||
  160.                    ((stripos($twMsgFormat, '%RAWTEXT%')!==false) && (stripos($pRawText, $cat->name)!=false || stripos($pRawText, $frmTag)!=false)) ) {} else $cats[] = '#'.$frmTag;
  161.           } $ctts = implode(' ',$cats); $twMsgFormat = str_ireplace("%CATS%", $ctts, $twMsgFormat); $twLim = $twLim - strlen($ctts);
  162.         }
  163.         if (stripos($twMsgFormat, '%TITLE%')!==false) { if (stripos($pTitle, '.co.uk')!==false) $twLim = $twLim - 14;
  164.            if (stripos($pTitle, '.com')!==false) $twLim = $twLim - 16; if (stripos($pTitle, '.net')!==false) $twLim = $twLim - 16; if (stripos($pTitle, '.org')!==false) $twLim = $twLim - 16;
  165.            $pTitle = nsTrnc($pTitle, $twLim); $twMsgFormat = str_ireplace("%TITLE%", $pTitle, $twMsgFormat); $twLim = $twLim - strlen($pTitle);
  166.         }
  167.         if (stripos($twMsgFormat, '%SITENAME%')!==false) {
  168.           $siteTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); $siteTitle = nsTrnc($siteTitle, $twLim); $twMsgFormat = str_ireplace("%SITENAME%", $siteTitle, $twMsgFormat); $twLim = $twLim - strlen($siteTitle);
  169.         }        
  170.         if (stripos($twMsgFormat, '%TEXT%')!==false) {          
  171.           $pText = nsTrnc(strip_tags(strip_shortcodes($pText)), 300, " ", "...");
  172.           $pText = nsTrnc($pText, $twLim); $twMsgFormat = str_ireplace("%TEXT%", $pText, $twMsgFormat); $twLim = $twLim - strlen($pText);
  173.         }
  174.         if (stripos($twMsgFormat, '%FULLTEXT%')!==false) {
  175.            $pFullText = nsTrnc(strip_tags($pFullText), $twLim); $twMsgFormat = str_ireplace("%FULLTEXT%", $pFullText, $twMsgFormat); $twLim = $twLim - strlen($pFullText);
  176.         }          
  177.         if (stripos($twMsgFormat, '%RAWTEXT%')!==false) {
  178.            $pRawText = nsTrnc(strip_tags($pRawText), $twLim); $twMsgFormat = str_ireplace("%FULLTEXT%", $pRawText, $twMsgFormat); $twLim = $twLim - strlen($pRawText);
  179.         }          
  180.                
  181.         $msg = nsFormatMessage($twMsgFormat, $postID);      
  182.        
  183.          
  184.     } //prr($msg);
  185.    
  186.     $extInfo = ' | PostID: '.$postID." - ".nxs_doQTrans($post->post_title, $lng); $logNT = '<span style="color:#00FFFF">Twitter</span> - '.$options['nName'];
  187.     require_once ('apis/tmhOAuth.php'); require_once ('apis/tmhUtilities.php'); if ($uln>0) $msg = nsTrnc($msg, 140+$uln); else { $url = get_permalink($postID); $msg = nsTrnc($msg, 120+strlen($url)); }
  188.     $tmhOAuth = new NXS_tmhOAuth(array( 'consumer_key' => $options['twConsKey'], 'consumer_secret' => $options['twConsSec'], 'user_token' => $options['twAccToken'], 'user_secret' => $options['twAccTokenSec']));
  189.      
  190.     if ($options['attchImg']=='1' && $img!='') $code = $tmhOAuth -> request('POST', 'http://upload.twitter.com/1/statuses/update_with_media.json', array( 'media[]' => $img, 'status' => $msg), true, true);    
  191.       else $code = $tmhOAuth->request('POST', $tmhOAuth->url('1.1/statuses/update'), array('status' =>$msg)); //prr($code); echo "YYY";
  192.     if ($code == 200){if ($postID=='0'){ nxs_addToLog($logNT, 'M', 'OK - TEST Message Posted '); echo 'OK - Message Posted, please see your Twitter Page'; /*NXS_tmhUtilities::pr(json_decode($tmhOAuth->response['response'])); */ return 201;}
  193.       else { nxs_metaMarkAsPosted($postID, 'TW', $options['ii']); nxs_addToLog($logNT, 'M', 'OK - Message Posted ', $extInfo);}
  194.     } else{ if ($postID=='0') {NXS_tmhUtilities::pr($tmhOAuth->response['response']); prr($msg); } nxs_addToLog($logNT, 'E', '-=ERROR=- '.print_r($tmhOAuth->response['response'], true)." MSG:".print_r($msg, true), $extInfo);
  195.       $code .= " | ".$tmhOAuth->response['response']." | ".print_r($msg, true);
  196.     }
  197.     return $code;
  198.   }
  199. }
  200.  
  201. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement