Ejemplo n.º 1
0
 function nxs_doPublishToPN($postID, $options)
 {
     global $nxs_gCookiesArr;
     $ntCd = 'PN';
     $ntCdL = 'pn';
     $ntNm = 'Pinterest';
     // $backtrace = debug_backtrace(); nxs_addToLogN('W', 'Enter', $ntCd, 'I am here - '.$ntCd."|".print_r($backtrace, true), '');
     //if (isset($options['timeToRun'])) wp_unschedule_event( $options['timeToRun'], 'nxs_doPublishToPN',  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:#FA5069">Pinterest</span> - ' . $options['nName'];
     $snap_ap = get_post_meta($postID, 'snap' . $ntCd, true);
     $snap_ap = maybe_unserialize($snap_ap);
     $isAttachVid = $options['isAttachVid'];
     $isAttachVid = '1';
     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') {
             sleep(5);
             nxs_addToLogN('W', 'Notice', $logNT, '-=Duplicate=- Post ID:' . $postID, 'Already posted. No reason for posting duplicate' . ' |' . $uqID);
             return;
         }
     }
     $blogTitle = htmlspecialchars_decode(get_bloginfo('name'), ENT_QUOTES);
     if ($blogTitle == '') {
         $blogTitle = home_url();
     }
     if ($postID == '0') {
         echo "Testing ... <br/><br/>";
         $msg = 'Test Post from ' . $blogTitle;
         $link = home_url();
         if ($options['pnDefImg'] != '') {
             $imgURL = $options['pnDefImg'];
         } else {
             $imgURL = "http://direct.gtln.us/img/nxs/NextScriptsLogoT.png";
         }
     } else {
         $post = get_post($postID);
         if (!$post) {
             return;
         }
         $pnMsgFormat = $options['pnMsgFormat'];
         $msg = nsFormatMessage($pnMsgFormat, $postID);
         $link = get_permalink($postID);
         nxs_metaMarkAsPosted($postID, $ntCd, $options['ii'], array('isPrePosted' => '1'));
         $imgURL = nxs_getPostImage($postID, 'large', $options['pnDefImg']);
         //prr($options); echo $imgURL."######"; // echo "WW".$postID."|";
         if ($isAttachVid == '1') {
             $vids = nsFindVidsInPost($post);
             if (count($vids) > 0) {
                 $vidURL = 'http://www.youtube.com/v/' . $vids[0];
                 $imgURL = 'http://img.youtube.com/vi/' . $vids[0] . '/0.jpg';
             }
         }
     }
     $email = $options['pnUName'];
     $boardID = $options['pnBoard'];
     $pass = substr($options['pnPass'], 0, 5) == 'g9c1a' ? nsx_doDecode(substr($options['pnPass'], 5)) : $options['pnPass'];
     // prr($boardID); prr($_POST); die();
     if (isset($options['pnSvC'])) {
         $nxs_gCookiesArr = maybe_unserialize($options['pnSvC']);
     }
     $loginError = true;
     if (is_array($nxs_gCookiesArr)) {
         $loginError = doCheckPinterest();
     }
     $extInfo = ' | PostID: ' . $postID . " - " . $post->post_title;
     if ($loginError !== false) {
         $loginError = doConnectToPinterest($email, $pass);
     }
     if ($loginError !== false) {
         echo $loginError;
         nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($loginError, true), $extInfo);
         return "BAD USER/PASS";
     }
     if (serialize($nxs_gCookiesArr) != $options['pnSvC']) {
         global $plgn_NS_SNAutoPoster;
         $gOptions = $plgn_NS_SNAutoPoster->nxs_options;
         // prr($gOptions['pn']);
         if (isset($options['ii']) && $options['ii'] !== '') {
             $gOptions['pn'][$options['ii']]['pnSvC'] = serialize($nxs_gCookiesArr);
             update_option('NS_SNAutoPoster', $gOptions);
         } else {
             foreach ($gOptions['pn'] as $ii => $gpn) {
                 $result = array_diff($options, $gpn);
                 if (!is_array($result) || count($result) < 1) {
                     $gOptions['pn'][$ii]['pnSvC'] = serialize($nxs_gCookiesArr);
                     update_option('NS_SNAutoPoster', $gOptions);
                     break;
                 }
             }
         }
     }
     // echo "PN SET:".$msg."|".$imgURL."|".$link."|".$boardID;
     if (preg_match('/\\$(\\d+\\.\\d+)/', $msg, $matches)) {
         $price = $matches[0];
     }
     $ret = doPostToPinterest($msg, $imgURL, $link, $boardID, 'TITLE WHERE IS IT?', $price, $link . "/GTH/");
     if ($ret == 'OK') {
         $ret = array("code" => "OK", "post_id" => '');
     }
     if (!is_array($ret) && $ret != 'OK') {
         if ($postID == '0') {
             echo $ret;
         }
         nxs_addToLogN('E', 'Error', $logNT, '-=ERROR=- ' . print_r($ret, true), $extInfo);
     } else {
         if ($postID == '0') {
             nxs_addToLogN('S', 'Test', $logNT, 'OK - TEST Message Posted ');
             echo 'OK - Message Posted, please see your Pinterest Page';
         } else {
             nxs_metaMarkAsPosted($postID, 'PN', $options['ii'], array('isPosted' => '1', 'pgID' => $ret['post_id'], 'pDate' => date('Y-m-d H:i:s')));
             nxs_addToLogN('S', 'Posted', $logNT, 'OK - Message Posted ', $extInfo);
         }
     }
     if ($ret['code'] == 'OK') {
         return 200;
     } else {
         return $ret;
     }
 }
Ejemplo n.º 2
0
 public function postToPinterest($message, $image, $link)
 {
     $email = Mage::getStoreConfig('besociable/pinterest/email');
     $pass = Mage::getStoreConfig('besociable/pinterest/password');
     $boardId = trim(Mage::getStoreConfig('besociable/pinterest/boardid'));
     $login = doConnectToPinterest($email, $pass);
     if (!$login) {
         $result = doPostToPinterest($message, $image, $link, $boardId);
         if ($result == 'OK') {
             return true;
         } else {
             Mage::log('pinterest response begin');
             Mage::log('result: ' . $result);
             Mage::log('message: ' . $message);
             Mage::log('image: ' . $image);
             Mage::log('link: ' . $link);
             Mage::log('boardId: ' . $boardId);
             Mage::log('pinterest response end');
         }
         return false;
     }
     return false;
 }
Ejemplo n.º 3
0
 function doPostToNT($options, $message)
 {
     global $nxs_gCookiesArr;
     $badOut = array('pgID' => '', 'isPosted' => 0, 'pDate' => date('Y-m-d H:i:s'), 'Error' => '');
     //## Check settings
     if (!is_array($options)) {
         $badOut['Error'] = 'No Options';
         return $badOut;
     }
     if (!isset($options['pnUName']) || trim($options['pnPass']) == '') {
         $badOut['Error'] = 'Not Configured';
         return $badOut;
     }
     $pass = substr($options['pnPass'], 0, 5) == 'g9c1a' ? nsx_doDecode(substr($options['pnPass'], 5)) : $options['pnPass'];
     if (empty($options['imgSize'])) {
         $options['imgSize'] = '';
     }
     //## Format
     if (!empty($message['pText'])) {
         $msg = $message['pText'];
     } else {
         $msg = nxs_doFormatMsg($options['pnMsgFormat'], $message);
     }
     $boardID = $options['pnBoard'];
     // prr($boardID); prr($_POST); die();
     if (isset($message['imageURL'])) {
         $imgURL = trim(nxs_getImgfrOpt($message['imageURL'], $options['imgSize']));
     } else {
         $imgURL = '';
     }
     if ($imgURL == '') {
         $badOut['Error'] .= 'NO Image.';
     }
     $urlToGo = !empty($message['url']) ? $message['url'] : '';
     //## Check for existing session
     if (isset($options['ck'])) {
         $nxs_gCookiesArr = maybe_unserialize($options['ck']);
     }
     $loginError = true;
     if (is_array($nxs_gCookiesArr)) {
         $loginError = doCheckPinterest();
     }
     if ($loginError !== false) {
         $loginError = doConnectToPinterest($options['pnUName'], $pass);
     }
     if ($loginError !== false) {
         $badOut['Error'] = print_r($loginError, true) . " - BAD USER/PASS";
         return $badOut;
     }
     if (preg_match('/\\$(\\d+\\.\\d+)/', $msg, $matches)) {
         $price = $matches[0];
     } else {
         $price = '';
     }
     if (isset($options['cImgURL']) && $options['cImgURL'] == 'S') {
         $urlToGo = nxs_mkShortURL($urlToGo);
     } elseif (isset($options['cImgURL']) && $options['cImgURL'] == 'N') {
         $urlToGo = '';
     }
     $ret = doPostToPinterest($msg, $imgURL, $urlToGo, $boardID, 'TITLE WHERE IS IT?', $price, $urlToGo . "/GTH/");
     if ($ret == 'OK') {
         $ret = array("code" => "OK", "post_id" => '');
     }
     //prr($ret);
     if (is_array($ret) && !empty($ret['post_id'])) {
         return array('postID' => str_ireplace('/pin/', '', $ret['post_id']), 'isPosted' => 1, 'postURL' => $ret['post_url'], 'pDate' => date('Y-m-d H:i:s'));
     } else {
         $badOut['Error'] .= 'Something went wrong - ' . print_r($ret, true);
     }
     return $badOut;
 }
Ejemplo n.º 4
0
 public function testpinterestAction()
 {
     $email = trim(Mage::getStoreConfig('besociable/pinterest/email'));
     $pass = Mage::getStoreConfig('besociable/pinterest/password');
     $boardId = trim(Mage::getStoreConfig('besociable/pinterest/boardid'));
     $message = 'Pinned from ' . Mage::app()->getStore()->getFrontendName() . ' ' . Mage::getModel('core/date')->timestamp(time());
     try {
         $login = doConnectToPinterest($email, $pass);
         if (!$login) {
             $result = doPostToPinterest($message, Mage::getDesign()->getSkinUrl(Mage::getStoreConfig('design/header/logo_src'), array('_area' => 'frontend')), $this->getFrontendUrl(''), $boardId);
             if ($result == 'OK') {
                 Mage::getSingleton("adminhtml/session")->addSuccess(Mage::helper("sociable")->__('Test pin has been posted. Please check your pinterest board.'));
             }
         } else {
             Mage::getSingleton("adminhtml/session")->addError(Mage::helper("sociable")->__('Could not login! Please check your Pinterest Email and Password!'));
         }
     } catch (Exception $e) {
         Mage::getSingleton("adminhtml/session")->addError($e->getMessage());
     }
     $this->_redirect("*/system_config/edit/section/besociable/");
 }