nxs_doFormatMsg

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

Description

nxs_doFormatMsg( (string) $format, $message, (string) $addURLParams = '' ); 

Parameters (3)

0. $format (string)
The format.
1. $message
The message.
2. $addurlparams (string)
The addurlparams.

Usage

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

Defined (1)

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

/nxs_functions.php  
  1. if (!function_exists('nxs_doFormatMsg')) { function nxs_doFormatMsg($format, $message, $addURLParams='') { global $nxs_urlLen; $msg = nxs_doSpin($format);// prr($msg); prr($message);// Make "message default" 
  2. $msgDef = array('title'=>'', 'announce'=>'', 'text'=>'', 'url'=>'', 'surl'=>'', 'urlDescr'=>'', 'urlTitle'=>'', 'imageURL' => array(), 'videoCode'=>'', 'videoURL'=>'', 'siteName'=>'', 'tags'=>'', 'cats'=>'', 'authorName'=>'', 'orID'=>''); $message = array_merge($msgDef, $message); 
  3. if (preg_match('/%URL%/', $msg)) { $url = $message['url']; if($addURLParams!='') $url .= (strpos($url, '?')!==false?'&':'?').$addURLParams; $nxs_urlLen = nxs_strLen($url); $msg = str_ireplace("%URL%", $url, $msg);} 
  4. if (preg_match('/%SURL%/', $msg)) {  
  5. if (isset($message['surl']) && $message['surl']!='') $url = $message['surl']; else { $url = $message['url']; if($addURLParams!='') $url .= (strpos($url, '?')!==false?'&':'?').$addURLParams; $url = nxs_mkShortURL($url); }  
  6. $nxs_urlLen = nxs_strLen($url); $msg = str_ireplace("%SURL%", $url, $msg); 
  7. if (preg_match('/%IMG%/', $msg)) { if (isset($message['imgURL']) && is_array($message['imgURL'])) { $imgURL = trim($message['imgURL']['large']); if ($imgURL=='') $imgURL = trim($message['imgURL']['medium']);  
  8. if ($imgURL=='') $imgURL = trim($message['imgURL']['original']); if ($imgURL=='') $imgURL = trim($message['imgURL']['thumb']); 
  9. } elseif (!empty($message['imgURL'])) $imgURL = $message['imgURL']; else $imgURL = ''; $msg = str_ireplace("%IMG%", $imgURL, $msg);  
  10. if (preg_match('/%IMGLARGE%/', $msg)) $msg = str_ireplace("%IMG%", trim($message['imgURL']['large'], $msg));  
  11. if (preg_match('/%IMGMEDIUM%/', $msg)) $msg = str_ireplace("%IMGMEDIUM%", trim($message['imgURL']['medium'], $msg));  
  12. if (preg_match('/%IMGTHUMB%/', $msg)) $msg = str_ireplace("%IMGTHUMB%", trim($message['imgURL']['thumb'], $msg));  
  13. if (preg_match('/%IMGORIGINAL%/', $msg)) $msg = str_ireplace("%IMGORIGINAL%", trim($message['imgURL']['original'], $msg));  
  14.  
  15. if (preg_match('/%ORID%/', $msg)) $msg = str_ireplace("%ORID%", $message['orID'], $msg);  
  16. if (preg_match('/%TITLE%/', $msg)) $msg = str_ireplace("%TITLE%", $message['title'], $msg);  
  17. if (preg_match('/%STITLE%/', $msg)) { $title = substr($message['title'], 0, 115); $msg = str_ireplace("%STITLE%", $title, $msg); }  
  18. if (preg_match('/%AUTHORNAME%/', $msg)) $msg = str_ireplace("%AUTHORNAME%", $message['authorName'], $msg); 
  19. if (preg_match('/%SITENAME%/', $msg)) $msg = str_ireplace("%SITENAME%", $message['siteName'], $msg);  
  20.  
  21. if (preg_match('/%ANNOUNCE%/', $msg)) { $sText = trim($message['announce'])!=''?$message['announce']:nsTrnc($message['description'], 300, " ", "..."); $msg = str_ireplace("%ANNOUNCE%", $sText, $msg); } 
  22. if (preg_match('/%EXCERPT%/', $msg)) { $sText = trim($message['announce'])!=''?$message['announce']:nsTrnc($message['description'], 300, " ", "..."); $msg = str_ireplace("%EXCERPT%", $sText, $msg); } 
  23. if (preg_match('/%RAWEXCERPT%/', $msg)) { $sText = trim($message['announce'])!=''?$message['announce']:nsTrnc($message['description'], 300, " ", "..."); $msg = str_ireplace("%RAWEXCERPT%", $sText, $msg); } 
  24.  
  25. if (preg_match('/%TEXT%/', $msg)) $msg = str_ireplace("%TEXT%", $message['description'], $msg);  
  26. if (preg_match('/%FULLTEXT%/', $msg)) $msg = str_ireplace("%FULLTEXT%", $message['description'], $msg);  
  27. if (preg_match('/%RAWTEXT%/', $msg)) $msg = str_ireplace("%RAWTEXT%", $message['description'], $msg);  
  28.  
  29.  
  30. if (preg_match('/%TAGS%/', $msg)) { $tags = nxs_doProcessTags($message['tags']); $msg = str_ireplace("%TAGS%", $tags['tags'], $msg); } 
  31. if (preg_match('/%HTAGS%/', $msg)) { $tags = nxs_doProcessTags($message['tags']); $msg = str_ireplace("%HTAGS%", $tags['htags'], $msg); } 
  32. if (preg_match('/%CATS%/', $msg)) { $tags = nxs_doProcessTags($message['cats']); $msg = str_ireplace("%CATS%", $tags['cats'], $msg); } 
  33. if (preg_match('/%HCATS%/', $msg)) { $tags = nxs_doProcessTags($message['hcats']); $msg = str_ireplace("%HCATS%", $tags['hcats'], $msg); } 
  34.  
  35. if (preg_match('/%+CF-[a-zA-Z0-9-_]+%/', $msg)) { $msgA = explode('%CF', $msg); $mout = ''; 
  36. foreach ($msgA as $mms) {  
  37. if (substr($mms, 0, 1)=='-' && stripos($mms, '%')!==false) { $mGr = CutFromTo($mms, '-', '%'); $cfItem = $message[$mGr]; $mms = str_ireplace("-".$mGr."%", $cfItem, $mms); } $mout .= $mms;  
  38. } $msg = $mout;  
  39. }  
  40.  
  41.  
  42.  
  43. return trim($msg); 
  44. }}