nsFormatMessage

The NextScripts: Social Networks Auto-Poster nsFormatMessage function.

Description

nsFormatMessage( $msg, $postID, (string) $addURLParams = '', (string) $lng = '' ); 

Parameters (4)

0. $msg
The msg.
1. $postid
The postid.
2. $addurlparams (string)
The addurlparams.
3. $lng — Optional. (string) => ''
The lng.

Usage

  1. if ( !function_exists( 'nsFormatMessage' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'nextscripts-social-networks-auto-poster/inc/nxs_functions_adv.php'; 
  3.  
  4. // The msg. 
  5. $msg = null; 
  6.  
  7. // The postid. 
  8. $postid = null; 
  9.  
  10. // The addurlparams. 
  11. $addurlparams = ''; 
  12.  
  13. // The lng. 
  14. $lng = ''; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = nsFormatMessage($msg, $postid, $addurlparams, $lng); 
  18.  

Defined (1)

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

/inc/nxs_functions_adv.php  
  1. if (!function_exists("nsFormatMessage")) { function nsFormatMessage($msg, $postID, $addURLParams='', $lng='') { global $ShownAds, $plgn_NS_SNAutoPoster, $nxs_urlLen;  
  2. $post = get_post($postID); $options = $plgn_NS_SNAutoPoster->nxs_options;  
  3. if (!empty($options['brokenCntFilters'])) { $msg = str_replace('%FULLTITLE%', '%TITLE%', $msg); $msg = str_replace('%PANNOUNCE%', '%ANNOUNCE%', $msg); $msg = str_replace('%PANNOUNCER%', '%ANNOUNCER%', $msg);  
  4. $msg = str_replace('%EXCERPT%', '%RAWEXCERPT%', $msg); $msg = str_replace('%FULLTEXT%', '%RAWTEXT%', $msg);  
  5. } if (!empty($options['nxsHTSpace'])) $htS = $options['nxsHTSpace']; else $htS = '';  
  6. if (!empty($options['nxsHTSepar'])) $htSep = $options['nxsHTSepar']; else $htSep = ', '; $htSep = str_replace('_', ' ', $htSep); $htSep = str_replace('c', ', ', $htSep); 
  7. // if ($addURLParams=='' && $options['addURLParams']!='') $addURLParams = $options['addURLParams']; 
  8. $msg = str_replace('%TEXT%', '%EXCERPT%', $msg); $msg = str_replace('%RAWEXTEXT%', '%RAWEXCERPT%', $msg); 
  9. $msg = stripcslashes($msg); if (isset($ShownAds)) $ShownAdsL = $ShownAds; // $msg = htmlspecialchars(stripcslashes($msg));  
  10. $msg = nxs_doSpin($msg); 
  11. if (preg_match('/%URL%/', $msg)) { $oo=array(); $oo = nxs_getURL($oo, $postID, $addURLParams); $url = $oo['urlToUse']; $nxs_urlLen = nxs_strLen($url); $msg = str_ireplace("%URL%", $url, $msg);} 
  12. if (preg_match('/%MYURL%/', $msg)) { $url = get_post_meta($postID, 'snap_MYURL', true); if($addURLParams!='') $url .= (strpos($url, '?')!==false?'&':'?').$addURLParams; $nxs_urlLen = nxs_strLen($url); $msg = str_ireplace("%MYURL%", $url, $msg);}// prr($msg); 
  13. if (preg_match('/%SURL%/', $msg)) { $oo=array(); $oo = nxs_getURL($oo, $postID, $addURLParams); $url = $oo['urlToUse']; $url = nxs_mkShortURL($url, $postID); $nxs_urlLen = nxs_strLen($url); $msg = str_ireplace("%SURL%", $url, $msg);}  
  14. if (preg_match('/%ORID%/', $msg)) { $msg = str_ireplace("%ORID%", $postID, $msg); }  
  15. if (preg_match('/%IMG%/', $msg)) { $imgURL = nxs_getPostImage($postID); $msg = str_ireplace("%IMG%", $imgURL, $msg); }  
  16. if (preg_match('/%TITLE%/', $msg)) { $title = nxs_doQTrans($post->post_title, $lng); $msg = str_ireplace("%TITLE%", $title, $msg); }  
  17. if (preg_match('/%FULLTITLE%/', $msg)) { $title = apply_filters('the_title', nxs_doQTrans($post->post_title, $lng)); $msg = str_ireplace("%FULLTITLE%", $title, $msg); }  
  18. if (preg_match('/%STITLE%/', $msg)) { $title = nxs_doQTrans($post->post_title, $lng); $title = substr($title, 0, 115); $msg = str_ireplace("%STITLE%", $title, $msg); }  
  19. if (preg_match('/%AUTHORNAME%/', $msg)) { $aun = $post->post_author; $aun = get_the_author_meta('display_name', $aun ); $msg = str_ireplace("%AUTHORNAME%", $aun, $msg);}  
  20. if (preg_match('/%AUTHORTWNAME%/', $msg)) { $aun = $post->post_author; $aun = get_the_author_meta('twitter', $aun ); $msg = str_ireplace("%AUTHORTWNAME%", $aun, $msg);}  
  21. if (preg_match('/%ANNOUNCE%/', $msg)) { $postContent = nxs_doQTrans($post->post_content, $lng);  
  22. $postContent = strip_tags(strip_shortcodes(str_ireplace('<!--more-->', '#####!--more--!#####', str_ireplace("<!--more-->", '<!--more-->', $postContent)))); 
  23. if (stripos($postContent, '#####!--more--!#####')!==false) { $postContentEx = explode('#####!--more--!#####', $postContent); $postContent = $postContentEx[0]; }  
  24. else $postContent = nsTrnc($postContent, $options['anounTagLimit'], ' ', ''); $msg = str_ireplace("%ANNOUNCE%", $postContent, $msg); 
  25. }  
  26. if (preg_match('/%PANNOUNCE%/', $msg)) { $postContent = apply_filters('the_content', nxs_doQTrans($post->post_content, $lng)); 
  27. $postContent = strip_tags(strip_shortcodes(str_ireplace('<!--more-->', '#####!--more--!#####', str_ireplace("<!--more-->", '<!--more-->', $postContent)))); 
  28. if (stripos($postContent, '#####!--more--!#####')!==false) { $postContentEx = explode('#####!--more--!#####', $postContent); $postContent = $postContentEx[0]; }  
  29. else $postContent = nsTrnc($postContent, $options['anounTagLimit'], ' ', ''); $msg = str_ireplace("%PANNOUNCE%", $postContent, $msg); 
  30. }  
  31. if (preg_match('/%ANNOUNCER%/', $msg)) { $postContent = nxs_doQTrans($post->post_content, $lng);  
  32. $postContent = strip_tags(strip_shortcodes(str_ireplace('<!--more-->', '#####!--more--!#####', str_ireplace("<!--more-->", '<!--more-->', $postContent)))); 
  33. if (stripos($postContent, '#####!--more--!#####')!==false) { $postContentEx = explode('#####!--more--!#####', $postContent); $postContent = $postContentEx[1]; }  
  34. else $postContent = str_replace(nsTrnc($postContent, $options['anounTagLimit'], ' ', ''), '', $postContent); $msg = str_ireplace("%ANNOUNCER%", $postContent, $msg); 
  35. }  
  36. if (preg_match('/%PANNOUNCER%/', $msg)) { $postContent = apply_filters('the_content', nxs_doQTrans($post->post_content, $lng)); 
  37. $postContent = strip_tags(strip_shortcodes(str_ireplace('<!--more-->', '#####!--more--!#####', str_ireplace("<!--more-->", '<!--more-->', $postContent)))); 
  38. if (stripos($postContent, '#####!--more--!#####')!==false) { $postContentEx = explode('#####!--more--!#####', $postContent); $postContent = $postContentEx[1]; }  
  39. else $postContent = str_replace(nsTrnc($postContent, $options['anounTagLimit'], ' ', ''), '', $postContent); $msg = str_ireplace("%PANNOUNCER%", $postContent, $msg); 
  40. }  
  41. if (preg_match('/%EXCERPT%/', $msg)) {  
  42. if ($post->post_excerpt!="") $excerpt = strip_tags(strip_shortcodes(apply_filters('the_content', nxs_doQTrans($post->post_excerpt, $lng))));  
  43. else $excerpt= nsTrnc(strip_tags(strip_shortcodes(apply_filters('the_content', nxs_doQTrans($post->post_content, $lng)))), 300, " ", "...");  
  44. $msg = str_ireplace("%EXCERPT%", $excerpt, $msg); 
  45. }  
  46. if (preg_match('/%RAWEXCERPT%/', $msg)) {  
  47. if ($post->post_excerpt!="") $excerpt = strip_tags(strip_shortcodes(nxs_doQTrans($post->post_excerpt, $lng))); else $excerpt= nsTrnc(strip_tags(strip_shortcodes(nxs_doQTrans($post->post_content, $lng))), 300, " ", "...");  
  48. $msg = str_ireplace("%RAWEXCERPT%", $excerpt, $msg); 
  49. if (preg_match('/%RAWEXCERPTHTML%/', $msg)) {  
  50. if ($post->post_excerpt!="") $excerpt = strip_shortcodes(nxs_doQTrans($post->post_excerpt, $lng)); else $excerpt= nsTrnc(strip_tags(strip_shortcodes(nxs_doQTrans($post->post_content, $lng))), 300, " ", "...");  
  51. $msg = str_ireplace("%RAWEXCERPTHTML%", $excerpt, $msg); 
  52. if (preg_match('/%TAGS%/', $msg)) { $t = wp_get_object_terms($postID, 'product_tag'); if ( empty($t) || is_wp_error($pt) || !is_array($t) ) $t = wp_get_post_tags($postID); 
  53. $tggs = array(); foreach ($t as $tagA) {$tggs[] = $tagA->name;} $tags = implode(', ', $tggs); $msg = str_ireplace("%TAGS%", $tags, $msg); 
  54. if (preg_match('/%CATS%/', $msg)) { $t = wp_get_post_categories($postID); $cats = array(); foreach($t as $c) { $cat = get_category($c); $cats[] = str_ireplace('&', '&', $cat->name); }  
  55. $ctts = implode(', ', $cats); $msg = str_ireplace("%CATS%", $ctts, $msg); 
  56. if (preg_match('/%HCATS%/', $msg)) { $t = wp_get_post_categories($postID); $cats = array();  
  57. foreach($t as $c) { $cat = get_category($c); $cats[] = "#".trim(str_replace(' ', $htS, str_replace(' ', ' ', trim(str_ireplace('&', '', str_ireplace('&', '', $cat->name)))))); }  
  58. $ctts = implode($htSep, $cats); $msg = str_ireplace("%HCATS%", $ctts, $msg); 
  59. }  
  60. if (preg_match('/%HTAGS%/', $msg)) { $t = wp_get_object_terms($postID, 'product_tag'); if ( empty($t) || is_wp_error($pt) || !is_array($t) ) $t = wp_get_post_tags($postID); 
  61. $tggs = array(); foreach ($t as $tagA) {$tggs[] = "#".trim(str_replace(' ', $htS, preg_replace('/[^a-zA-Z0-9\p{L}\p{N}\s]/u', '', trim(nxs_ucwords(str_ireplace('&', '', str_ireplace('&', '', $tagA->name)))))));}  
  62. $tags = implode($htSep, $tggs); $msg = str_ireplace("%HTAGS%", $tags, $msg); 
  63. }  
  64. if (preg_match('/%+CF-[a-zA-Z0-9-_]+%/', $msg)) { $msgA = explode('%CF', $msg); $mout = ''; 
  65. foreach ($msgA as $mms) {  
  66. if (substr($mms, 0, 1)=='-' && stripos($mms, '%')!==false) { $mGr = CutFromTo($mms, '-', '%'); $cfItem = get_post_meta($postID, $mGr, true); $mms = str_ireplace("-".$mGr."%", $cfItem, $mms); } $mout .= $mms;  
  67. } $msg = $mout;  
  68. }  
  69. $mm = array(); if (preg_match_all('/%H?CT-[a-zA-Z0-9_]+%/', $msg, $mm)) { $msgA = explode('%CT', str_ireplace("%HCT", "%CT", $msg)); $mout = ''; $i = 0; 
  70. foreach ($msgA as $mms) {  
  71. if (substr($mms, 0, 1)=='-' && stripos($mms, '%')!==false) { $h = strpos($mm[0][$i], '%HCT-')!==false; $i++; $mGr=CutFromTo($mms, '-', '%'); $cfItem=wp_get_post_terms($postID, $mGr, array("fields"=>"names")); 
  72. if (is_nxs_error($cfItem)) {nxs_addToLogN('E', 'Error', 'MSG', '-=ERROR=- '.$mGr.'|'.print_r($cfItem, true), ''); $mms=str_ireplace("-".$mGr."%", '', $mms); } else { $tggs = array();  
  73. foreach ($cfItem as $frmTag) { if ($h) $frmTag = trim(str_replace(' ', $htS, preg_replace('/[^a-zA-Z0-9\p{L}\p{N}\s]/u', '', trim(nxs_ucwords(str_ireplace('&', '', str_ireplace('&', '', $frmTag))))))); 
  74. $tggs[] = ($h?'#':'').$frmTag;  
  75. } $cfItem = implode(' ', $tggs); $mms=str_ireplace("-".$mGr."%", $cfItem, $mms);  
  76. } $mout.=$mms;  
  77. } $msg = $mout;  
  78. if (preg_match('/%FULLTEXT%/', $msg)) { $postContent = apply_filters('the_content', nxs_doQTrans($post->post_content, $lng)); $msg = str_ireplace("%FULLTEXT%", $postContent, $msg);}  
  79. if (preg_match('/%RAWTEXT%/', $msg)) { $postContent = nxs_doQTrans($post->post_content, $lng); $msg = str_ireplace("%RAWTEXT%", $postContent, $msg);} 
  80. if (preg_match('/%SITENAME%/', $msg)) { $siteTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); $msg = str_ireplace("%SITENAME%", $siteTitle, $msg);}  
  81. if (isset($ShownAds)) $ShownAds = $ShownAdsL; // FIX for the quick-adsense plugin 
  82. return trim($msg); 
  83. }}