nxs_mkShortURL

The NextScripts: Social Networks Auto-Poster nxs mkShortURL function.

Description

nxs_mkShortURL( $url, (string) $postID = '' ); 

Parameters (2)

0. $url
The url.
1. $postid (string)
The postid.

Usage

  1. if ( !function_exists( 'nxs_mkShortURL' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'nextscripts-social-networks-auto-poster/nxs_functions.php'; 
  3.  
  4. // The url. 
  5. $url = null; 
  6.  
  7. // The postid. 
  8. $postid = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = nxs_mkShortURL($url, $postid); 
  12.  

Defined (1)

The function is defined in the following location(s).

/nxs_functions.php  
  1. if (!function_exists("nxs_mkShortURL")) { function nxs_mkShortURL($url, $postID='') { $rurl = ''; global $plgn_NS_SNAutoPoster; if (!isset($plgn_NS_SNAutoPoster)) return; $options = $plgn_NS_SNAutoPoster->nxs_options; 
  2. if ($options['nxsURLShrtnr']=='B' && trim($options['bitlyUname']!='') && trim($options['bitlyAPIKey']!='')) {  
  3. $response = wp_remote_get('http://api-ssl.bitly.com/v3/shorten?login='.$options['bitlyUname'].'&apiKey='.$options['bitlyAPIKey'].'&longUrl='.urlencode($url));  
  4. if (is_wp_error($response)) { nxs_addToLogN('E', 'bit.ly', '', '-=ERROR=- '.print_r($response, true)); return $url; } 
  5. $rtr = json_decode($response['body'], true); 
  6. if ($rtr['status_code']=='200') $rurl = $rtr['data']['url']; 
  7. } //echo "###".$rurl; 
  8. if ($options['nxsURLShrtnr']=='A' && trim($options['adflyUname']!='') && trim($options['adflyAPIKey']!='')) {  
  9. $response = wp_remote_get('http://api.adf.ly/api.php?key='.$options['adflyAPIKey'].'&uid='.$options['adflyUname'].'&advert_type=int&domain='.$options['adflyDomain'].'&url='.urlencode($url));  
  10. if (is_wp_error($response)) { nxs_addToLogN('E', 'adf.ly', '', '-=ERROR=- '.print_r($response, true)); return $url; }  
  11. if ( $response['body']!=error) $rurl = $response['body']; else { nxs_addToLogN('E', 'adf.ly', '', '-=ERROR=- '.print_r($response, true)); return $url; } 
  12. if ($options['nxsURLShrtnr']=='C' && trim($options['clkimAPIKey']!='')) {  
  13. $response = wp_remote_get('http://clk.im/api?api='.$options['clkimAPIKey'].'&url='.urlencode($url)); 
  14. if (is_wp_error($response)) { nxs_addToLogN('E', 'clk.im', '', '-=ERROR (SYS)=- '.print_r($response, true)); return $url; } $r = json_decode($response['body'], true); //prr($r); die(); 
  15. if (!is_array($r) || $r[error]!='0') { nxs_addToLogN('E', 'clk.im', '', '-=ERROR (JSON)=- '.print_r($response['body'], true)); return $url; } else $rurl = urldecode($r['short']); 
  16. if ($options['nxsURLShrtnr']=='X' && trim($options['xcoAPIKey']!='')) {  
  17. $response = wp_remote_get('http://api.x.co/Squeeze.svc/text/'.$options['xcoAPIKey'].'?url='.urlencode($url));  
  18. if (is_wp_error($response)) { nxs_addToLogN('E', 'x.co', '', '-=ERROR (SYS)=- '.print_r($response, true)); return $url; } $r = $response['body']; 
  19. if (empty($r) || stripos($r, 'http://')===false) { nxs_addToLogN('E', 'x.co', '', '-=ERROR (RES)=- '.print_r($r, true)); return $url; } else $rurl = $r; 
  20.  
  21. if ($options['nxsURLShrtnr']=='U') {  
  22. $flds = array('a'=>'add', 'url'=>$url); $response = wp_remote_post('http://u.to/', array('body' => $flds));  
  23. if (is_wp_error($response)) { nxs_addToLogN('E', 'u.to', '', '-=ERROR (SYS)=- '.print_r($response, true)); return $url; } $r = $response['body']; 
  24. if (empty($r) || stripos($r, "#shurlout').val('")===false) { nxs_addToLogN('E', 'x.co', '', '-=ERROR (RES)=- '.print_r($r, true)); return $url; } else $rurl = CutFromTo($r, "#shurlout').val('", "'"); 
  25.  
  26. if ($options['nxsURLShrtnr']=='P' && trim($options['postAPIKey']!='')) {  
  27. $response = wp_remote_get('http://po.st/api/shorten?longUrl='.urlencode($url).'&apiKey='.$options['postAPIKey']);  
  28. if (is_wp_error($response)) { nxs_addToLogN('E', 'po.st', '', '-=ERROR (SYS)=- '.print_r($response, true)); return $url; } $r = json_decode($response['body'], true);  
  29. if (!is_array($r) || $r['status_txt']!='OK') { nxs_addToLogN('E', 'po.st', '', '-=ERROR (JSON)=- '.print_r($response['body'], true)); return $url; } else $rurl = $r['short_url']; 
  30. if ($options['nxsURLShrtnr']=='W' && function_exists('wp_get_shortlink')) { global $post; $post = get_post($postID); $rurl = wp_get_shortlink($postID, 'post'); } 
  31. if ($options['nxsURLShrtnr']=='Y' && trim($options['YOURLSKey']!='') && trim($options['YOURLSURL']!='')) { $timestamp = time(); $signature = md5( $timestamp . $options['YOURLSKey'] );  
  32. $flds = array('signature'=>$signature, 'action' => 'shorturl', 'url'=>$url, 'format'=>'json', 'timestamp'=>$timestamp);  
  33. $response = wp_remote_post(($options['YOURLSURL']), array('body' => $flds));  
  34. if (is_wp_error($response)) { nxs_addToLogN('E', 'YOURLS', '', '-=ERROR=- '.print_r($response, true)); return $url; }  
  35. $rtr = json_decode($response['body'], true); if (!is_array($rtr) || !isset($rtr['shorturl']) ) { nxs_addToLogN('E', 'goo.gl', '', '-=ERROR=- '.print_r($response, true)); return $url; }  
  36. $rurl = $rtr['shorturl']; 
  37.  
  38. }  
  39. if ($options['nxsURLShrtnr']=='O' || $options['nxsURLShrtnr']=='' || $options['nxsURLShrtnr']=='G') {  
  40. $response = wp_remote_post('https://www.googleapis.com/urlshortener/v1/url'.($options['gglAPIKey']!=''?'?key='.$options['gglAPIKey']:''), array('headers' => array('Content-Type'=>'application/json'), 'body' => '{"longUrl": "'.$url.'"}'));  
  41. if (is_wp_error($response)) { nxs_addToLogN('E', 'goo.gl', '', '-=ERROR=- '.print_r($response, true)); return $url; }  
  42. $rtr = json_decode($response['body'], true); if (!is_array($rtr) || isset($rtr[error]) || !isset($rtr['id']) ) { nxs_addToLogN('E', 'goo.gl', '', '-=ERROR=- '.print_r($response, true)); return $url; }  
  43. $rurl = $rtr['id']; 
  44. }  
  45. //if ($rurl=='') { $response = wp_remote_get('http://gd.is/gtq/'.$url); if ((is_array($response) && ($response['response']['code']=='200'))) $rurl = $response['body']; } 
  46. if ($rurl!='') $url = $rurl; return $url; 
  47. }}