function nxs_doPublishToTW($postID, $options) { $ntCd = 'TW'; $ntCdL = 'tw'; $ntNm = 'Twitter'; $img = ''; $imgURL = ''; global $nxs_urlLen; $nxs_urlLen = 0; //$backtrace = debug_backtrace(); nxs_addToLogN('W', 'Error', $logNT, 'I am here - '.$ntCd."|".print_r($backtrace, true), ''); //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToTW', array($postID, $options)); $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#00FFFF">Twitter</span> - ' . $options['nName']; $snap_ap = get_post_meta($postID, 'snap' . $ntCd, true); $snap_ap = maybe_unserialize($snap_ap); if ($options['pType'] != 'aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) { $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted != '2') { nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:' . $postID, 'Already posted. No reason for posting duplicate' . ' |' . $options['pType']); return; } } $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle == '') { $blogTitle = home_url(); } $uln = 0; if ($options['attchImg'] == '1') { $imgURL = nxs_getPostImage($postID); if (trim($imgURL) == '') { $options['attchImg'] = 0; } else { if (ini_get('allow_url_fopen')) { if (@getimagesize($imgURL) !== false) { $img = wp_remote_get($imgURL); if ($img['headers']['content-length'] < 200) { $options['attchImg'] = 0; } else { if (is_wp_error($img)) { $options['attchImg'] = 0; } else { $img = $img['body']; } } } else { $options['attchImg'] = 0; } } else { $img = wp_remote_get($imgURL); if (is_wp_error($img)) { $options['attchImg'] = 0; } elseif (isset($img['body']) && trim($img['body']) != '') { $img = $img['body']; } else { $options['attchImg'] = 0; } } } if ($options['attchImg'] == 0) { nxs_addToLogN('E', 'Error', $logNT, 'Could not get image, will post without it', $extInfo); } } if ($options['attchImg'] == '1' && $img != '') { $twLim = 118; } else { $twLim = 140; } if ($postID == '0') { echo "Testing ... <br/><br/>"; $msg = 'Test Post from ' . nsTrnc($blogTitle, $twLim - 24) . " - " . rand(1, 155); $uln = nxs_strLen($msg); } else { $post = get_post($postID); if (!$post) { return; } $twMsgFormat = $options['twMsgFormat']; nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); if (stripos($twMsgFormat, '%URL%') !== false || stripos($twMsgFormat, '%SURL%') !== false) { $twLim = $twLim - 22; } if (stripos($twMsgFormat, '%AUTHORNAME%') !== false) { $aun = $post->post_author; $aun = get_the_author_meta('display_name', $aun); $twLim = $twLim - nxs_strLen($aun); } $noRepl = str_ireplace("%TITLE%", "", $twMsgFormat); $noRepl = str_ireplace("%SITENAME%", "", $noRepl); $noRepl = str_ireplace("%URL%", "", $noRepl); $noRepl = str_ireplace("%RAWEXCERPT%", "", $noRepl); $noRepl = str_ireplace("%SURL%", "", $noRepl); $noRepl = str_ireplace("%TEXT%", "", $noRepl); $noRepl = str_ireplace("%FULLTEXT%", "", $noRepl); $noRepl = str_ireplace("%EXCERPT%", "", $noRepl); $noRepl = str_ireplace("%ANNOUNCE%", "", $noRepl); $noRepl = str_ireplace("%AUTHORNAME%", "", $noRepl); $twLim = $twLim - nxs_strLen($noRepl); $pTitle = $title = $post->post_title; if ($post->post_excerpt != "") { $exrText = $post->post_excerpt; } else { $exrText = $post->post_content; } $pText = apply_filters('the_content', $exrText); $pRawText = $post->post_content; $pFullText = apply_filters('the_content', $pRawText); if (stripos($twMsgFormat, '%TAGS%') !== false || stripos($twMsgFormat, '%HTAGS%') !== false) { $t = wp_get_object_terms($postID, 'product_tag'); if (empty($t) || is_wp_error($pt) || !is_array($t)) { $t = wp_get_post_tags($postID); } $tggs = array(); foreach ($t as $tagA) { $frmTag = trim(str_replace(' ', '', preg_replace('/[^a-zA-Z0-9\\p{L}\\p{N}\\s]/u', '', trim(ucwords(str_ireplace('&', '', str_ireplace('&', '', $tagA->name))))))); if (preg_match('/\\b' . $frmTag . '\\b/iu', $pTitle)) { $pTitle = trim(preg_replace('/\\b' . $frmTag . '\\b/iu', '#' . $frmTag, $pTitle)); } if (preg_match('/\\b' . $frmTag . '\\b/iu', $pFullText)) { $pFullText = trim(preg_replace('/\\b' . $frmTag . '\\b/iu', '#' . $frmTag, $pFullText)); } if (preg_match('/\\b' . $frmTag . '\\b/iu', $pText)) { $pText = trim(preg_replace('/\\b' . $frmTag . '\\b/iu', '#' . $frmTag, $pText)); } if (preg_match('/\\b' . $frmTag . '\\b/iu', $pRawText)) { $pRawText = trim(preg_replace('/\\b' . $frmTag . '\\b/iu', '#' . $frmTag, $pRawText)); } if (stripos($twMsgFormat, '%TITLE%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pTitle) || stripos($twMsgFormat, '%TEXT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pText) || stripos($twMsgFormat, '%EXCERPT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pText) || stripos($twMsgFormat, '%RAWEXCERPT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pText) || stripos($twMsgFormat, '%ANNOUNCE%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pText) || stripos($twMsgFormat, '%FULLTEXT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pFullText) || stripos($twMsgFormat, '%RAWTEXT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pRawText)) { } else { $tggs[] = '#' . $frmTag; } } $tags = implode(' ', $tggs); while (count($tags) > $twLim - 10) { array_pop($tggs); $tags = implode(' ', $tggs); } $twMsgFormat = str_ireplace("%TAGS%", $tags, $twMsgFormat); $twMsgFormat = str_ireplace("%HTAGS%", $tags, $twMsgFormat); $twLim = $twLim - nxs_strLen($tags); } if (stripos($twMsgFormat, '%CATS%') !== false || stripos($twMsgFormat, '%HCATS%') !== false) { $t = wp_get_post_categories($postID); $ctts = array(); foreach ($t as $c) { $cat = get_category($c); $frmTag = trim(str_replace(' ', '', str_replace(' ', ' ', str_ireplace('&', '&', trim(ucwords($cat->name)))))); if (stripos($pTitle, $cat->name) !== false) { $pTitle = str_ireplace($cat->name, '#' . $frmTag, $pTitle); } elseif (stripos($pTitle, $frmTag) !== false) { $pTitle = str_ireplace($frmTag, '#' . $frmTag, $pTitle); } if (stripos($pText, $cat->name) !== false) { $pText = str_ireplace($cat->name, '#' . $frmTag, $pText); } elseif (stripos($pText, $frmTag) !== false) { $pText = str_ireplace($frmTag, '#' . $frmTag, $pText); } if (stripos($pFullText, $cat->name) !== false) { $pFullText = str_ireplace($cat->name, '#' . $frmTag, $pFullText); } elseif (stripos($pFullText, $frmTag) !== false) { $pFullText = str_ireplace($frmTag, '#' . $frmTag, $pFullText); } if (stripos($pRawText, $cat->name) !== false) { $pRawText = str_ireplace($cat->name, '#' . $frmTag, $pRawText); } elseif (stripos($pRawText, $frmTag) !== false) { $pRawText = str_ireplace($frmTag, '#' . $frmTag, $pRawText); } if (stripos($twMsgFormat, '%TITLE%') !== false && (stripos($pTitle, $cat->name) !== false || stripos($pTitle, $frmTag) !== false) || stripos($twMsgFormat, '%TEXT%') !== false && (stripos($pText, $cat->name) !== false || stripos($pText, $frmTag) !== false) || stripos($twMsgFormat, '%EXCERPT%') !== false && (stripos($pText, $cat->name) !== false || stripos($pText, $frmTag) !== false) || stripos($twMsgFormat, '%RAWEXCERPT%') !== false && (stripos($exrText, $cat->name) !== false || stripos($exrText, $frmTag) !== false) || stripos($twMsgFormat, '%ANNOUNCE%') !== false && (stripos($pText, $cat->name) !== false || stripos($pText, $frmTag) !== false) || stripos($twMsgFormat, '%FULLTEXT%') !== false && (stripos($pFullText, $cat->name) !== false || stripos($pFullText, $frmTag) !== false) || stripos($twMsgFormat, '%RAWTEXT%') !== false && (stripos($pRawText, $cat->name) !== false || stripos($pRawText, $frmTag) !== false)) { } else { $ctts[] = '#' . $frmTag; } } $cats = implode(' ', $ctts); while (count($cats) > $twLim - 10) { array_pop($ctts); $cats = implode(' ', $ctts); } $twMsgFormat = str_ireplace("%CATS%", $cats, $twMsgFormat); $twMsgFormat = str_ireplace("%HCATS%", $cats, $twMsgFormat); $twLim = $twLim - nxs_strLen($cats); } if (stripos($twMsgFormat, '%TITLE%') !== false) { if (stripos($pTitle, '.co.uk') !== false) { $twLim = $twLim - 14; } if (stripos($pTitle, '.com') !== false) { $twLim = $twLim - 16; } if (stripos($pTitle, '.net') !== false) { $twLim = $twLim - 16; } if (stripos($pTitle, '.org') !== false) { $twLim = $twLim - 16; } $pTitle = html_entity_decode(strip_tags($pTitle), ENT_NOQUOTES, 'UTF-8'); $pTitle = nsTrnc($pTitle, $twLim); $twMsgFormat = str_ireplace("%TITLE%", $pTitle, $twMsgFormat); $twLim = $twLim - nxs_strLen($pTitle); } if (stripos($twMsgFormat, '%SITENAME%') !== false) { $siteTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); $siteTitle = nsTrnc($siteTitle, $twLim); $twMsgFormat = str_ireplace("%SITENAME%", $siteTitle, $twMsgFormat); $twLim = $twLim - nxs_strLen($siteTitle); } if (stripos($twMsgFormat, '%TEXT%') !== false) { $pText = nsTrnc(strip_tags(strip_shortcodes($pText)), 300, " ", "..."); $pText = nsTrnc($pText, $twLim); $twMsgFormat = str_ireplace("%TEXT%", $pText, $twMsgFormat); $twLim = $twLim - nxs_strLen($pText); } if (stripos($twMsgFormat, '%EXCERPT%') !== false) { $pText = nsTrnc(strip_tags(strip_shortcodes($pText)), 300, " ", "..."); $pText = nsTrnc($pText, $twLim); $twMsgFormat = str_ireplace("%EXCERPT%", $pText, $twMsgFormat); $twLim = $twLim - nxs_strLen($pText); } if (stripos($twMsgFormat, '%RAWEXCERPT%') !== false) { $exrText = nsTrnc(strip_tags(strip_shortcodes($exrText)), 300, " ", "..."); $exrText = nsTrnc($exrText, $twLim); $twMsgFormat = str_ireplace("%RAWEXCERPT%", $exrText, $twMsgFormat); $twLim = $twLim - nxs_strLen($exrText); } if (stripos($twMsgFormat, '%FULLTEXT%') !== false) { $pFullText = nsTrnc(strip_tags($pFullText), $twLim); $twMsgFormat = str_ireplace("%FULLTEXT%", $pFullText, $twMsgFormat); $twLim = $twLim - nxs_strLen($pFullText); } if (stripos($twMsgFormat, '%RAWTEXT%') !== false) { $pRawText = nsTrnc(strip_tags($pRawText), $twLim); $twMsgFormat = str_ireplace("%RAWTEXT%", $pRawText, $twMsgFormat); $twLim = $twLim - nxs_strLen($pRawText); } $msg = nsFormatMessage($twMsgFormat, $postID); } $message = array('message' => $msg, 'img' => $img, 'urlLength' => $nxs_urlLen); //## Actual Post $ntToPost = new nxs_class_SNAP_TW(); $ret = $ntToPost->doPostToNT($options, $message); //## Process Results if (!is_array($ret) || $ret['isPosted'] != '1') { //## Error if ($postID == '0') { prr($ret); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo); } else { // ## All Good - log it. if ($postID == '0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo _e('OK - Message Posted, please see your ' . $logNT . ' Page. ', 'nxs_snap'); } 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); } } //## Return Result if ($ret['isPosted'] == '1') { return 200; } else { return print_r($ret, true); } }
function nxs_doPublishToTW($postID, $options) { $ntCd = 'TW'; $ntCdL = 'tw'; $ntNm = 'Twitter'; $imgData = ''; $imgURL = ''; global $plgn_NS_SNAutoPoster, $nxs_urlLen; $nxs_urlLen = 0; if (!is_array($options)) { $options = maybe_unserialize(get_post_meta($postID, $options, true)); } //$backtrace = debug_backtrace(); nxs_addToLogN('W', 'Error', $logNT, 'I am here - '.$ntCd."|".print_r($backtrace, true), ''); //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToTW', array($postID, $options)); $gOptions = $plgn_NS_SNAutoPoster->nxs_options; if (!empty($gOptions['nxsHTSpace'])) { $htS = $gOptions['nxsHTSpace']; } else { $htS = ''; } $addParams = nxs_makeURLParams(array('NTNAME' => $ntNm, 'NTCODE' => $ntCd, 'POSTID' => $postID, 'ACCNAME' => $options['nName'])); $ii = $options['ii']; if (!isset($options['pType'])) { $options['pType'] = 'im'; } if ($options['pType'] == 'sh') { sleep(rand(1, 10)); } $logNT = '<span style="color:#00FFFF">Twitter</span> - ' . $options['nName']; $snap_ap = get_post_meta($postID, 'snap' . $ntCd, true); $snap_ap = maybe_unserialize($snap_ap); if ($options['pType'] != 'aj' && is_array($snap_ap) && (nxs_chArrVar($snap_ap[$ii], 'isPosted', '1') || nxs_chArrVar($snap_ap[$ii], 'isPrePosted', '1'))) { $snap_isAutoPosted = get_post_meta($postID, 'snap_isAutoPosted', true); if ($snap_isAutoPosted != '2') { nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:' . $postID, 'Already posted. No reason for posting duplicate' . ' |' . $options['pType']); return; } } $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); if ($blogTitle == '') { $blogTitle = home_url(); } $uln = 0; $extInfo = ' | PostID: ' . $postID; if ($options['attchImg'] == '1') { if (!empty($options['imgToUse'])) { $imgURL = $options['imgToUse']; } else { $imgURL = nxs_getPostImage($postID); } if (preg_match("/noImg.\\.png/i", $imgURL)) { $imgURL = ''; } if (trim($imgURL) == '') { $options['attchImg'] = 0; } else { $imgURL = str_replace(' ', '%20', $imgURL); $hdrsArr['User-Agent'] = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0'; $advSet = array('headers' => $hdrsArr, 'httpversion' => '1.1', 'timeout' => 45, 'sslverify' => false); $imgData = wp_remote_get($imgURL, $advSet); if (is_wp_error($imgData) || empty($imgData['body']) || !empty($imgData['headers']['content-length']) && (int) $imgData['headers']['content-length'] < 200) { $options['attchImg'] = 0; nxs_addToLogN('E', 'Error', $logNT, 'Could not get image (' . $imgURL . '), will post without it - Error:' . print_r($imgData, true), $extInfo); } else { $imgData = $imgData['body']; } } } if ($options['attchImg'] == '1' && $imgData != '') { $twLim = 117; } else { $twLim = 140; } if ($postID == '0') { echo "Testing ... <br/><br/>"; $msg = 'Test Post from ' . nsTrnc($blogTitle, $twLim - 24) . " - " . rand(1, 155); $uln = nxs_strLen($msg); } else { $post = get_post($postID); if (!$post) { return; } $twMsgFormat = $options['twMsgFormat']; nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1')); $extInfo = ' | PostID: ' . $postID . " - " . $post->post_title . ' |' . $options['pType']; if (stripos($twMsgFormat, '%URL%') !== false || stripos($twMsgFormat, '%SURL%') !== false) { $twLim = $twLim - 22; } if (stripos($twMsgFormat, '%AUTHORNAME%') !== false) { $aun = $post->post_author; $aun = get_the_author_meta('display_name', $aun); $twLim = $twLim - nxs_strLen($aun); } $noRepl = str_ireplace("%TITLE%", "", $twMsgFormat); $noRepl = str_ireplace("%SITENAME%", "", $noRepl); $noRepl = str_ireplace("%URL%", "", $noRepl); $noRepl = str_ireplace("%RAWEXCERPT%", "", $noRepl); $noRepl = str_ireplace("%SURL%", "", $noRepl); $noRepl = str_ireplace("%TEXT%", "", $noRepl); $noRepl = str_ireplace("%FULLTEXT%", "", $noRepl); $noRepl = str_ireplace("%EXCERPT%", "", $noRepl); $noRepl = str_ireplace("%ANNOUNCE%", "", $noRepl); $noRepl = str_ireplace("%AUTHORNAME%", "", $noRepl); $noRepl = str_ireplace("%TAGS%", "", $noRepl); $noRepl = str_ireplace("%CATS%", "", $noRepl); $noRepl = preg_replace('/%H?C(F|T)-[a-zA-Z0-9_]+%/', '', $noRepl); $twLim = $twLim - nxs_strLen($noRepl); // prr($noRepl); $pTitle = nxs_doQTrans($post->post_title); if ($post->post_excerpt != "") { $exrText = nxs_doQTrans($post->post_excerpt); } else { $exrText = nxs_doQTrans($post->post_content); } $pText = empty($gOptions['brokenCntFilters']) ? apply_filters('the_content', $exrText) : $exrText; $pRawText = nxs_doQTrans($post->post_content); $pFullText = empty($gOptions['brokenCntFilters']) ? apply_filters('the_content', $pRawText) : $pRawText; if (stripos($twMsgFormat, '%TAGS%') !== false || stripos($twMsgFormat, '%HTAGS%') !== false) { $t = wp_get_object_terms($postID, 'product_tag'); if (empty($t) || is_wp_error($pt) || !is_array($t)) { $t = wp_get_post_tags($postID); } $tggs = array(); foreach ($t as $tagA) { $frmTag = trim(str_replace(' ', $htS, preg_replace('/[^a-zA-Z0-9\\p{L}\\p{N}\\s]/u', '', trim(ucwords(str_ireplace('&', '', str_ireplace('&', '', $tagA->name))))))); if (preg_match('/\\b' . $frmTag . '\\b/iu', $pTitle)) { $pTitle = trim(preg_replace('/\\b' . $frmTag . '\\b/iu', '#' . $frmTag, $pTitle)); } if (preg_match('/\\b' . $frmTag . '\\b/iu', $pFullText)) { $pFullText = trim(preg_replace('/\\b' . $frmTag . '\\b/iu', '#' . $frmTag, $pFullText)); } if (preg_match('/\\b' . $frmTag . '\\b/iu', $pText)) { $pText = trim(preg_replace('/\\b' . $frmTag . '\\b/iu', '#' . $frmTag, $pText)); } if (preg_match('/\\b' . $frmTag . '\\b/iu', $pRawText)) { $pRawText = trim(preg_replace('/\\b' . $frmTag . '\\b/iu', '#' . $frmTag, $pRawText)); } if (stripos($twMsgFormat, '%TITLE%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pTitle) || stripos($twMsgFormat, '%TEXT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pText) || stripos($twMsgFormat, '%EXCERPT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pText) || stripos($twMsgFormat, '%RAWEXCERPT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pText) || stripos($twMsgFormat, '%ANNOUNCE%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pText) || stripos($twMsgFormat, '%FULLTEXT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pFullText) || stripos($twMsgFormat, '%RAWTEXT%') !== false && preg_match('/\\b' . $frmTag . '\\b/i', $pRawText)) { } else { $tggs[] = '#' . $frmTag; } } $tags = implode(' ', $tggs); $tgsTwLim = $twLim - 20; $tags = nsTrnc($tags, $tgsTwLim, " ", ""); $twMsgFormat = str_ireplace("%TAGS%", $tags, $twMsgFormat); $twMsgFormat = str_ireplace("%HTAGS%", $tags, $twMsgFormat); $twLim = $twLim - nxs_strLen($tags); } if (stripos($twMsgFormat, '%CATS%') !== false || stripos($twMsgFormat, '%HCATS%') !== false) { $t = wp_get_post_categories($postID); $ctts = array(); foreach ($t as $c) { $cat = get_category($c); //$frmTag = trim(str_replace(' ','', str_replace(' ',' ',str_ireplace('&','&',trim(ucwords($cat->name)))))); prr($frmTag); $frmTag = trim(str_replace(' ', $htS, preg_replace('/[^a-zA-Z0-9\\p{L}\\p{N}\\s]/u', '', trim(ucwords(str_ireplace('&', '', str_ireplace('&', '', $cat->name))))))); if (stripos($pTitle, $cat->name) !== false) { $pTitle = str_ireplace($cat->name, '#' . $frmTag, $pTitle); } elseif (stripos($pTitle, $frmTag) !== false) { $pTitle = str_ireplace($frmTag, '#' . $frmTag, $pTitle); } if (stripos($pText, $cat->name) !== false) { $pText = str_ireplace($cat->name, '#' . $frmTag, $pText); } elseif (stripos($pText, $frmTag) !== false) { $pText = str_ireplace($frmTag, '#' . $frmTag, $pText); } if (stripos($pFullText, $cat->name) !== false) { $pFullText = str_ireplace($cat->name, '#' . $frmTag, $pFullText); } elseif (stripos($pFullText, $frmTag) !== false) { $pFullText = str_ireplace($frmTag, '#' . $frmTag, $pFullText); } if (stripos($pRawText, $cat->name) !== false) { $pRawText = str_ireplace($cat->name, '#' . $frmTag, $pRawText); } elseif (stripos($pRawText, $frmTag) !== false) { $pRawText = str_ireplace($frmTag, '#' . $frmTag, $pRawText); } if (stripos($twMsgFormat, '%TITLE%') !== false && (stripos($pTitle, $cat->name) !== false || stripos($pTitle, $frmTag) !== false) || stripos($twMsgFormat, '%TEXT%') !== false && (stripos($pText, $cat->name) !== false || stripos($pText, $frmTag) !== false) || stripos($twMsgFormat, '%EXCERPT%') !== false && (stripos($pText, $cat->name) !== false || stripos($pText, $frmTag) !== false) || stripos($twMsgFormat, '%RAWEXCERPT%') !== false && (stripos($exrText, $cat->name) !== false || stripos($exrText, $frmTag) !== false) || stripos($twMsgFormat, '%ANNOUNCE%') !== false && (stripos($pText, $cat->name) !== false || stripos($pText, $frmTag) !== false) || stripos($twMsgFormat, '%FULLTEXT%') !== false && (stripos($pFullText, $cat->name) !== false || stripos($pFullText, $frmTag) !== false) || stripos($twMsgFormat, '%RAWTEXT%') !== false && (stripos($pRawText, $cat->name) !== false || stripos($pRawText, $frmTag) !== false)) { } else { $ctts[] = '#' . $frmTag; } } $cats = implode(' ', $ctts); $tgsTwLim = $twLim - 20; $cats = nsTrnc($cats, $tgsTwLim, " ", ""); $twMsgFormat = str_ireplace("%CATS%", $cats, $twMsgFormat); $twMsgFormat = str_ireplace("%HCATS%", $cats, $twMsgFormat); $twLim = $twLim - nxs_strLen($cats); } if (preg_match('/%H?CT-[a-zA-Z0-9_]+%/', $twMsgFormat)) { $msgA = explode('%CT', str_ireplace("%HCT", "%CT", $twMsgFormat)); $mout = ''; foreach ($msgA as $mms) { if (substr($mms, 0, 1) == '-' && stripos($mms, '%') !== false) { $mGr = CutFromTo($mms, '-', '%'); $cfItem = wp_get_post_terms($postID, $mGr, array("fields" => "names")); if (is_nxs_error($cfItem)) { nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . $mGr . '|' . print_r($cfItem, true), $extInfo); } else { $tggs = array(); foreach ($cfItem as $frmTag) { $frmTag = trim(str_replace(' ', $htS, preg_replace('/[^a-zA-Z0-9\\p{L}\\p{N}\\s]/u', '', trim(ucwords(str_ireplace('&', '', str_ireplace('&', '', $frmTag))))))); $tggs[] = '#' . $frmTag; } $cfItem = implode(' ', $tggs); $twLim = $twLim - nxs_strLen($cfItem); $mms = str_ireplace("-" . $mGr . "%", $cfItem, $mms); } } $mout .= $mms; } $twMsgFormat = $mout; } $twMsgFormat = str_ireplace(" ", " ", $twMsgFormat); if (stripos($twMsgFormat, '%TITLE%') !== false) { if (stripos($pTitle, '.co.uk') !== false) { $twLim = $twLim - 14; } if (stripos($pTitle, '.com') !== false) { $twLim = $twLim - 16; } if (stripos($pTitle, '.net') !== false) { $twLim = $twLim - 16; } if (stripos($pTitle, '.org') !== false) { $twLim = $twLim - 16; } $pTitle = html_entity_decode(strip_tags($pTitle), ENT_NOQUOTES, 'UTF-8'); //$ttlTwLim = $twLim-20; $ttlTwLim = $twLim; $pTitle = nsTrnc($pTitle, $ttlTwLim); $twMsgFormat = str_ireplace("%TITLE%", $pTitle, $twMsgFormat); $twLim = $twLim - nxs_strLen($pTitle); } if (stripos($twMsgFormat, '%SITENAME%') !== false) { $siteTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES); $siteTitle = nsTrnc($siteTitle, $twLim); $twMsgFormat = str_ireplace("%SITENAME%", $siteTitle, $twMsgFormat); $twLim = $twLim - nxs_strLen($siteTitle); } if (stripos($twMsgFormat, '%TEXT%') !== false) { $pText = nsTrnc(strip_tags(strip_shortcodes($pText)), 140, " ", "..."); $pText = nsTrnc($pText, $twLim); $twMsgFormat = str_ireplace("%TEXT%", $pText, $twMsgFormat); $twLim = $twLim - nxs_strLen($pText); } if (stripos($twMsgFormat, '%EXCERPT%') !== false) { $pText = nsTrnc(strip_tags(strip_shortcodes($pText)), 140, " ", "..."); $pText = nsTrnc($pText, $twLim); $twMsgFormat = str_ireplace("%EXCERPT%", $pText, $twMsgFormat); $twLim = $twLim - nxs_strLen($pText); } if (stripos($twMsgFormat, '%ANNOUNCE%') !== false) { $pText = nsTrnc(strip_tags(strip_shortcodes($pText)), 140, " ", "..."); $pText = nsTrnc($pText, $twLim); $twMsgFormat = str_ireplace("%ANNOUNCE%", $pText, $twMsgFormat); $twLim = $twLim - nxs_strLen($pText); } if (stripos($twMsgFormat, '%RAWEXCERPT%') !== false) { $exrText = nsTrnc(strip_tags(strip_shortcodes($exrText)), 140, " ", "..."); $exrText = nsTrnc($exrText, $twLim); $twMsgFormat = str_ireplace("%RAWEXCERPT%", $exrText, $twMsgFormat); $twLim = $twLim - nxs_strLen($exrText); } if (stripos($twMsgFormat, '%FULLTEXT%') !== false) { $pFullText = nsTrnc(strip_tags($pFullText), $twLim); $twMsgFormat = str_ireplace("%FULLTEXT%", $pFullText, $twMsgFormat); $twLim = $twLim - nxs_strLen($pFullText); } if (stripos($twMsgFormat, '%RAWTEXT%') !== false) { $pRawText = nsTrnc(strip_tags($pRawText), $twLim); $twMsgFormat = str_ireplace("%RAWTEXT%", $pRawText, $twMsgFormat); $twLim = $twLim - nxs_strLen($pRawText); } $msg = nsFormatMessage($twMsgFormat, $postID, $addParams); } $msg = str_replace('&#039;', "'", $msg); $msg = str_replace(''', "'", $msg); $msg = str_replace('#039;', "'", $msg); $msg = str_replace('#039', "'", $msg); $msg = str_replace('&#8217;', "'", $msg); $msg = str_replace('’', "'", $msg); $msg = str_replace('#8217;', "'", $msg); $msg = str_replace('#8217', "'", $msg); $msg = str_replace('&#8220;', '"', $msg); $msg = str_replace('“', '"', $msg); $msg = str_replace('#8220;', '"', $msg); $msg = str_replace('#8220', "'", $msg); $msg = str_replace('&#8221;', '"', $msg); $msg = str_replace('”', '"', $msg); $msg = str_replace('#8221;', '"', $msg); $msg = str_replace('#8221', "'", $msg); $msg = str_replace('&#8212;', '-', $msg); $msg = str_replace('—', '-', $msg); $msg = str_replace('#8212;', '-', $msg); $msg = str_replace('#8212', "-", $msg); $msg = nxs_decodeEntitiesFull($msg); $message = array('message' => $msg, 'img' => $imgData, 'urlLength' => $nxs_urlLen); $options['twMsgFormat'] = $msg; //## This meta field is created by the indieweb taxonomy plugin - by David Peach $response = get_post_meta($postID, 'response', true); if (!empty($response)) { $reply_url = $response['url']; if (!empty($reply_url) && strpos($reply_url, 'twitter.com')) { $explode_at_domain = explode('twitter.com/', $reply_url); $twitter_path = end($explode_at_domain); $exploded_path = explode('/', $twitter_path); $options['in_reply_to_id'] = end($exploded_path); } } //prr($options); //## Actual Post $ntToPost = new nxs_class_SNAP_TW(); $ret = $ntToPost->doPostToNT($options, $message); //## Process Results if (!is_array($ret) || $ret['isPosted'] != '1') { //## Error if ($postID == '0') { prr($ret); } nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo); } else { // ## All Good - log it. if ($postID == '0') { nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted '); echo _e('OK - Message Posted, please see your ' . $logNT . ' Page. ', 'nxs_snap'); } else { nxs_addToRI($postID); nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPosted' => '1', 'pgID' => $ret['postID'], 'pDate' => date('Y-m-d H:i:s'))); $extInfo .= ' | <a href="' . $ret['postURL'] . '" target="_blank">Post Link</a>'; nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo); } } //## Return Result if ($ret['isPosted'] == '1') { return 200; } else { return print_r($ret, true); } }