if (!function_exists("doConnectToGooglePlus2")) {function doConnectToGooglePlus2($email, $pass, $srv='GP', $iidb=0){ global $nxs_plurl, $nxs_gCookiesArr, $plgn_NS_SNAutoPoster; if (isset($plgn_NS_SNAutoPoster)) { $options = $plgn_NS_SNAutoPoster->nxs_options; if (isset($options['gp'][$iidb]['ck'])) $ck = maybe_unserialize($options['gp'][$iidb]['ck']); } else $ck = array(); $nt = new nxsAPI_GP(); $nt->debug = false; if (!empty($ck)) $nt->ck = $ck; $loginErr = $nt->connect($email, $pass, $srv); $nxs_gCookiesArr = $nt->ck; if (isset($plgn_NS_SNAutoPoster) && !empty($options)) { if (!$loginErr){ $options['gp'][$iidb]['ck'] = $nt->ck; if(is_array($options)) { update_option('NS_SNAutoPoster', $options); $plgn_NS_SNAutoPoster->nxs_options = $options; }} } return $loginErr; }}
function doPostToNT($options, $message) { $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['ytUName']) || trim($options['ytPass']) == '') { $badOut['Error'] = 'Not Configured'; return $badOut; } $email = $options['ytUName']; $pass = substr($options['ytPass'], 0, 5) == 'n5g9a' ? nsx_doDecode(substr($options['ytPass'], 5)) : $options['ytPass']; //## Format if (!empty($message['pText'])) { $msg = $message['pText']; } else { $msg = nxs_doFormatMsg($options['ytMsgFormat'], $message); } $nt = new nxsAPI_GP(); if (!empty($options['ck'])) { $nt->ck = $options['ck']; } $nt->debug = false; $loginError = $nt->connect($email, $pass, 'YT'); if (!$loginError) { $result = $nt->postYT($msg, $options['ytPageID'], $message['videoURL'], $options['ytGPPageID']); } else { $badOut['Error'] = "Login/Connection Error: " . print_r($loginError, true); return $badOut; } if (is_array($result) && $result['isPosted'] == '1') { nxs_save_glbNtwrks('yt', $options['ii'], $nt->ck, 'ck'); } return $result; }
public function afterImport() { if (!function_exists('PHPMailerAutoload')) require __DIR__ . DIRECTORY_SEPARATOR . 'phpmailer' . DIRECTORY_SEPARATOR . 'PHPMailerAutoload.php'; $config = array(); foreach ($this->selectAll( 'SELECT `path`,`value` FROM `core_config_data` WHERE `scope` = "default" AND ( `path` LIKE "%/lesti_smtp/%" OR `path` LIKE "%/ident_general/%" OR `path` = "web/unsecure/base_url")') as $value) { $config [$value['path']] = $value['value']; } $secondPath = $this->selectone('SELECT `value` FROM `core_config_data` WHERE `scope_id` = 2 AND `path` = "web/unsecure/base_url"',null,'value'); $imageDir = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . 'catalog' . DIRECTORY_SEPARATOR . 'product' . DIRECTORY_SEPARATOR; $imageDir = realpath($imageDir); $name_id = $this->selectone(' SELECT `attribute_id` FROM `eav_attribute` WHERE `attribute_code`="name" AND `entity_type_id`= (SELECT `entity_type_id` FROM `eav_entity_type` WHERE `entity_type_code`="catalog_product" ) ',null,'attribute_id'); //$name = 71; $description_id = $this->selectone(' SELECT `attribute_id` FROM `eav_attribute` WHERE `attribute_code`="description" AND `entity_type_id`= (SELECT `entity_type_id` FROM `eav_entity_type` WHERE `entity_type_code`="catalog_product" ) ',null,'attribute_id'); //$description = 72; $url_key_id = $this->selectone(' SELECT `attribute_id` FROM `eav_attribute` WHERE `attribute_code`="url_key" AND `entity_type_id`= (SELECT `entity_type_id` FROM `eav_entity_type` WHERE `entity_type_code`="catalog_product" ) ',null,'attribute_id'); //$url_key = 97; $image_id = $this->selectone(' SELECT `attribute_id` FROM `eav_attribute` WHERE `attribute_code`="image" AND `entity_type_id`= (SELECT `entity_type_id` FROM `eav_entity_type` WHERE `entity_type_code`="catalog_product" ) ',null,'attribute_id'); //$image = 85; $catalog_category_id = $this->selectone(' SELECT `attribute_id` FROM `eav_attribute` WHERE `attribute_code`="name" AND `entity_type_id`= (SELECT `entity_type_id` FROM `eav_entity_type` WHERE `entity_type_code`="catalog_category" ) ',null,'attribute_id'); //$catalog_category = 41; $shared_on_social_networks_id = $this->selectone(' SELECT `attribute_id` FROM `eav_attribute` WHERE `attribute_code`="shared_on_social_networks" ',null,'attribute_id'); //$shared_on_social_networks = 143; $news_from_date = $this->selectone(' SELECT `attribute_id` FROM `eav_attribute` WHERE `attribute_code`="news_from_date" ',null,'attribute_id'); //$shared_on_social_networks = 93; $product_stmt = $this->exec_stmt(' SELECT `catalog_product_entity`.`entity_id` , `catalog_product_entity`.`sku` FROM `catalog_product_entity` LEFT JOIN `catalog_product_entity_int` ON `catalog_product_entity_int`.`entity_id`=`catalog_product_entity`.`entity_id` AND `catalog_product_entity_int`.`attribute_id`= '.$shared_on_social_networks_id.' LEFT JOIN `catalog_product_entity_datetime` ON `catalog_product_entity_datetime`.`entity_id`=`catalog_product_entity`.`entity_id` AND `catalog_product_entity_datetime`.`attribute_id`= '.$news_from_date.' WHERE ( `catalog_product_entity_int`.`value` IS NULL OR `catalog_product_entity_int`.`value` != 1 ) AND ( `catalog_product_entity_datetime`.`value` IS NOT NULL OR `catalog_product_entity_datetime`.`value` != "" ) GROUP BY `catalog_product_entity`.`entity_id` ORDER BY `catalog_product_entity_datetime`.`value` DESC ',null,false); // Full path to twitterOAuth.php (change OAuth to your own path) // create new instance $tweet = new TwitterOAuth( $this->getParam("SOCIAL:twitterkey", ""), $this->getParam("SOCIAL:twittersecret", ""), $this->getParam("SOCIAL:twitterotoken", ""), $this->getParam("SOCIAL:twitterosecret", "") ); $productCount = 0; $facebookPages = explode(':',$this->getParam("SOCIAL:facebook", "")); $gogglePages = explode(':',$this->getParam("SOCIAL:gpage", "")); while ($productCount < $this->getParam("SOCIAL:topost", "10") && $product = $product_stmt->fetch(PDO::FETCH_ASSOC) ) { $product['image']= $this->selectone(' SELECT `value` FROM `catalog_product_entity_varchar` WHERE `catalog_product_entity_varchar`.`entity_id`='.$product['entity_id'].' AND `catalog_product_entity_varchar`.`attribute_id`= '.$image_id.' LIMIT 1 ',null,'value'); $product['url_path'] = $this->selectone(' SELECT `request_path` FROM `core_url_rewrite` WHERE `id_path` LIKE "product/%" AND `product_id` ='.$product['entity_id'].' ORDER BY `category_id` ASC LIMIT 1 ',null,'request_path'); if ( $product['url_path'] == '' || !is_file($imageDir . $product['image']) ) { continue; } $product['name']= $this->selectone(' SELECT `value` FROM `catalog_product_entity_varchar` WHERE `catalog_product_entity_varchar`.`entity_id`='.$product['entity_id'].' AND `catalog_product_entity_varchar`.`attribute_id`= '.$name_id.' LIMIT 1 ',null,'value'); $product['description']= $this->selectone(' SELECT `value` FROM `catalog_product_entity_text` WHERE `catalog_product_entity_text`.`entity_id`='.$product['entity_id'].' AND `catalog_product_entity_text`.`attribute_id`= '.$description_id.' LIMIT 1 ',null,'value'); $product['url_key']= $this->selectone(' SELECT `value` FROM `catalog_product_entity_varchar` WHERE `catalog_product_entity_varchar`.`entity_id`='.$product['entity_id'].' AND `catalog_product_entity_varchar`.`attribute_id`= '.$url_key_id.' LIMIT 1 ',null,'value'); $product['category_names'] = $this->selectone(' SELECT GROUP_CONCAT( DISTINCT `value` SEPARATOR ", ") as value FROM `catalog_category_entity_varchar` WHERE `entity_id` IN (SELECT `category_id` FROM `catalog_category_product` WHERE `product_id` = '.$product['entity_id'].') AND `catalog_category_entity_varchar`.`attribute_id`= '.$catalog_category_id.' ',null,'value'); $productCount ++; $tags = preg_replace('/^[^,]*, /', '', $product['category_names']); $tags = strtolower(', '.$tags); $tags = str_replace(' ','_',$tags); $tags = trim(str_replace(',_',' #',$tags)); if ( $this->getParam("SOCIAL:gemail", "") != '' && $this->getParam("SOCIAL:gpassword", "") != '' && $this->getParam("SOCIAL:gpage", "") != '' ) { foreach($gogglePages as $key=>$gogglePage) { $baseUrl = $config['web/unsecure/base_url']; if ($key>0 && $secondPath != '') $baseUrl = $secondPath; $nt = new nxsAPI_GP(); $loginError = $nt->connect($this->getParam("SOCIAL:gemail", ""), $this->getParam("SOCIAL:gpassword", "")); // Image URL $lnk = array('img'=>$baseUrl. '/media/catalog/product/' . $product['image']); $nt->postGP($product['name'] .' '. $tags . ' ' . $baseUrl . 'index.php/' . $product['url_path'], $lnk, $gogglePage); if ($loginError === false) $this->log($baseUrl . 'index.php/' . $product['url_path'] . " not sent succesfully " . $loginError, "info"); } } // Your Message $message = substr($product['name'], 0, 100) . ' ' . $config['web/unsecure/base_url'] . 'index.php/' . $product['url_path']. ' ' . $tags; if ( $this->getParam("SOCIAL:twitterkey", "") != '' && $this->getParam("SOCIAL:twittersecret", "") != '' && $this->getParam("SOCIAL:twitterotoken", "") != '' && $this->getParam("SOCIAL:twitterosecret", "") != '' ) { // Send tweet $tweet->post('statuses/update', array('status' => $message)); } if ( $this->getParam("SOCIAL:wpurl", "") != '' && $this->getParam("SOCIAL:wpusername") != '' && $this->getParam("SOCIAL:wppassword", "") != '' ) { $client = new IXR_Client($this->getParam("SOCIAL:wpurl", "")); $description = substr($product['description'],0,100); $description .= '<!--more-->'; $description .= substr($product['description'],100); $description .= '<br/><a href="' . $config['web/unsecure/base_url'] . 'index.php/' . $product['url_path'] . '">' . $product['name'] . '</a>'; $content = array( 'post_status' => 'draft', 'post_type' => 'post', 'post_title' => $product['name'], 'post_content' => $description, 'terms' => array('category' => array($this->getParam("SOCIAL:wpcategory_id", ""))) ); $params = array(0, $this->getParam("SOCIAL:wpusername", ""), $this->getParam("SOCIAL:wppassword", ""), $content); $client->query('wp.newPost', $params); $post_id = $client->getResponse(); $command = 'convert "' .$imageDir . $product['image']. '" -resize 604x270\\> -resample 72 /tmp/storebaby.jpg 2>&1 '; exec($command); $content = array( 'name' => basename($product['image']), 'type' => mime_content_type(basename($product['image'])), 'bits' => new IXR_Base64(file_get_contents('/tmp/storebaby.jpg')), true ); $client->query('metaWeblog.newMediaObject', 1, $this->getParam("SOCIAL:wpusername"), $this->getParam("SOCIAL:wppassword"), $content); $media = $client->getResponse(); $content = array( 'post_status' => 'publish', 'mt_keywords' => preg_replace('/^[^,]*, /', '', $product['category_names']), 'wp_post_thumbnail' => $media['id'] ); $client->query('metaWeblog.editPost', $post_id, $this->getParam("SOCIAL:wpusername"), $this->getParam("SOCIAL:wppassword"), $content, true); } $fbConfigFile = __DIR__.'/fbConf.php'; if (is_file($fbConfigFile)) { require $fbConfigFile; $baseUrl = $config['web/unsecure/base_url']; $fb = new Facebook\Facebook(array( 'app_id' => $fbConfig['appId'], 'app_secret' => $fbConfig['appSecret'], 'default_graph_version' => 'v2.3' )); foreach($fbConfig['pages'] as $pageId=>$pageToken) { $fb->setDefaultAccessToken($pageToken); $linkData = [ 'link' => $baseUrl . 'index.php/' . $product['url_path'], 'name' => $product['name'] .' ' . $tags, 'message' => $product['name'] .' ' . $tags, 'picture' => $baseUrl. '/media/catalog/product/' . $product['image'] ]; try { // Returns a `Facebook\FacebookResponse` object $fb->post('/'. substr($pageId,1,99) .'/feed', $linkData,$pageToken); } catch(Facebook\Exceptions\FacebookResponseException $e) { echo 'Graph returned an error: ' . $e->getMessage(); } catch(Facebook\Exceptions\FacebookSDKException $e) { echo 'Facebook SDK returned an error: ' . $e->getMessage(); } } $this->exec_stmt('REPLACE INTO `catalog_product_entity_int` SET `value`=1 , `catalog_product_entity_int`.`attribute_id`= '.$shared_on_social_networks_id.', `catalog_product_entity_int`.`entity_id` = ' . $product['entity_id'] . ' '); } unlink('/tmp/storebaby.jpg'); } $product_stmt->closeCursor(); }
function doPostToNT($options, $message) { $badOut = array('pgID' => '', 'isPosted' => 0, 'pDate' => date('Y-m-d H:i:s'), 'Error' => ''); $lnk = ''; //## Check API Lib // if (!function_exists('doPostToGooglePlus')) if (file_exists('apis/postToGooglePlus.php')) require_once ('apis/postToGooglePlus.php'); elseif (file_exists('/home/_shared/deSrc.php')) require_once ('/home/_shared/deSrc.php'); if (!function_exists('doPostToGooglePlus')) { $badOut['Error'] = 'Google+ API Library not found'; return $badOut; } //## Check settings if (!is_array($options)) { $badOut['Error'] = 'No Options'; return $badOut; } if (!isset($options['gpUName']) || trim($options['gpPass']) == '') { $badOut['Error'] = 'Not Configured'; return $badOut; } if (empty($options['imgSize'])) { $options['imgSize'] = ''; } //## Make Post $gpPostType = $options['postType']; if (!empty($message['pText'])) { $msg = $message['pText']; } else { $msg = nxs_doFormatMsg($options['gpMsgFormat'], $message); } // Make "message default" if ($gpPostType == 'I' || $gpPostType == 'A') { if (isset($message['imageURL'])) { $imgURL = trim(nxs_getImgfrOpt($message['imageURL'], $options['imgSize'])); } else { $imgURL = ''; } } $email = $options['gpUName']; $pass = substr($options['gpPass'], 0, 5) == 'n5g9a' ? nsx_doDecode(substr($options['gpPass'], 5)) : $options['gpPass']; $nt = new nxsAPI_GP(); if (!empty($options['ck'])) { $nt->ck = $options['ck']; } $nt->debug = false; $loginError = $nt->connect($email, $pass); if (!$loginError) { if ($gpPostType == 'A') { $lnk = $message['url']; } elseif ($gpPostType == 'I') { $lnk = array(); if ($imgURL != '') { $lnk['img'] = $imgURL; } if ($imgURL == '' && $message['noImg'] === true) { $lnk['img'] = ''; } if (!empty($message['videoURL'])) { $lnk['video'] = $message['videoURL']; } } $pageID = ''; $comPgID = ''; $comPGCatID = ''; //if (!empty($options['gpPageID']) && empty($options['gpCommID'])) $pageID = $options['gpPageID']; if (!empty($options['gpPageID'])) { $pageID = $options['gpPageID']; } if (!empty($options['gpCommID'])) { $comPgID = $options['gpCommID']; $comPGCatID = $options['gpCCat']; } $result = $nt->postGP($msg, $lnk, $pageID, $comPgID, $comPGCatID); } else { $badOut['Error'] = "Login/Connection Error: " . print_r($loginError, true); return $badOut; } if (is_array($result) && $result['isPosted'] == '1') { nxs_save_glbNtwrks('gp', $options['ii'], $nt->ck, 'ck'); } return $result; }
function doPostToNT($options, $message) { $badOut = array('pgID' => '', 'isPosted' => 0, 'pDate' => date('Y-m-d H:i:s'), 'Error' => ''); // prr($message); prr($options); //## Check API Lib //if (!function_exists('doConnectToBlogger')) if (file_exists('apis/postToGooglePlus.php')) require_once ('apis/postToGooglePlus.php'); elseif (file_exists('/home/_shared/deSrc.php')) require_once ('/home/_shared/deSrc.php'); //## Check settings if (!is_array($options)) { $badOut['Error'] = 'No Options'; return $badOut; } if ((!isset($options['bgUName']) || empty($options['bgPass'])) && empty($options['AccessToken'])) { $badOut['Error'] = 'Not Configured'; return $badOut; } //## Format if (!empty($message['pText'])) { $msg = $message['pText']; } else { $msg = nxs_doFormatMsg($options['bgMsgFormat'], $message); } if (!empty($message['pTitle'])) { $msgT = $message['pTitle']; } else { $msgT = nxs_doFormatMsg($options['bgMsgTFormat'], $message); } if ($options['bgInclTags'] == '1') { $tags = nsTrnc($message['tags'], 195, ',', ''); } else { $tags = ''; } //## Check/Fix HTML if (class_exists('DOMDocument')) { $doc = new DOMDocument(); @$doc->loadHTML('<?xml encoding="UTF-8">' . $msg); $doc->encoding = 'UTF-8'; $msg = $doc->saveHTML(); $msg = CutFromTo($msg, '<body>', '</body>'); $msg = preg_replace('/<br(.*?)\\/?>/', '<br$1/>', $msg); $msg = preg_replace('/<img(.*?)\\/?>/', '<img$1/>', $msg); require 'apis/htmlNumTable.php'; if (is_array($HTML401NamedToNumeric)) { $msg = strtr($msg, $HTML401NamedToNumeric); $msgT = strtr($msgT, $HTML401NamedToNumeric); } } $msg = preg_replace('/<script\\b[^>]*>(.*?)<\\/script>/is', "", $msg); $msg = preg_replace('/<!--(.*)-->/Uis', "", $msg); $nxshf = new NXS_HtmlFixer(); $nxshf->debug = false; $msg = $nxshf->getFixedHtml($msg); $msg = str_replace("\r\n", "\n", $msg); $msg = str_replace("\n\r", "\n", $msg); $msg = str_replace("\r", "\n", $msg); $msg = str_replace("\n", "<br/>", $msg); //## Make Post $email = $options['bgUName']; $pass = substr($options['bgPass'], 0, 5) == 'b4d7s' ? nsx_doDecode(substr($options['bgPass'], 5)) : $options['bgPass']; $blogID = $options['bgBlogID']; // prr($msgT); prr($msg); die(); if (class_exists('nxsAPI_GP') && !empty($options['bgUName']) && empty($options['APIKey'])) { $nt = new nxsAPI_GP(); if (!empty($options['ck'])) { $nt->ck = $options['ck']; } $nt->debug = false; $loginError = $nt->connect($email, $pass, 'BG'); if (!$loginError) { $result = $nt->postBG($blogID, $msgT, $msg, $tags); // prr($result); } else { $badOut['Error'] = "Login/Connection Error: " . print_r($loginError, true); return $badOut; } if (is_array($result) && $result['isPosted'] == '1') { nxs_save_glbNtwrks('bg', $options['ii'], $nt->ck, 'ck'); } return $result; } else { //## Refresh token if (function_exists('get_option')) { $currTime = time() + get_option('gmt_offset') * HOUR_IN_SECONDS; } else { $currTime = time(); } if ($options['AccessTokenExp'] < $currTime) { $tknURL = 'https://www.googleapis.com/oauth2/v3/token?refresh_token=' . $options['RefreshToken'] . '&client_id=' . $options['APIKey'] . '&client_secret=' . $options['APISec'] . '&grant_type=refresh_token'; $response = wp_remote_post($tknURL); $resp = json_decode($response['body'], true); $options['AccessToken'] = $resp['access_token']; $options['AccessTokenExp'] = $currTime + $resp['expires_in']; nxs_save_glbNtwrks('bg', $options['ii'], $resp['access_token'], 'AccessTokenExp'); nxs_save_glbNtwrks('bg', $options['ii'], $options['AccessTokenExp'], 'AccessTokenExp'); //nxs_addToLogN('S', 'Test', $logNT, 'Token Refreshed '.date('Y-m-d H:i:s',$options['AccessTokenExp'])."|".$tknURL.$options['AccessToken'].print_r($response, true)); } //## Post $post = array("kind" => "blogger#post", "blog" => array("id" => $blogID), "title" => $msgT, "content" => $msg); $post = json_encode($post); // prr($post); $hdrsArr = array('Content-Type' => 'application/json'); $advSet = array('headers' => $hdrsArr, 'httpversion' => '1.1', 'timeout' => 45, 'redirection' => 0, 'body' => $post); $tknURL = 'https://www.googleapis.com/blogger/v3/blogs/' . $blogID . '/posts?access_token=' . $options['AccessToken'] . ''; $ret = ''; $response = wp_remote_post($tknURL, $advSet); //prr($tknURL); prr($response); if (is_object($response) && isset($response->errors)) { $badOut['Error'] = print_r($response, true); } else { $ret = json_decode($response['body'], true); } //prr($ret); if (is_array($ret) && !empty($ret['id'])) { return array('postID' => $ret['id'], 'isPosted' => 1, 'postURL' => $ret['url'], 'pDate' => date('Y-m-d H:i:s')); } else { $badOut['Error'] .= "Error: " . print_r($ret, true); return $badOut; } } //## Return if (is_array($ret) && $ret['post_id'] != '') { return array('postID' => $ret['post_id'], 'isPosted' => 1, 'postURL' => $ret['post_id'], 'pDate' => date('Y-m-d H:i:s')); } else { $badOut['Error'] .= print_r($ret, true); return $badOut; } }
<?php require "wp/formatting.php"; require "wp/functions.php"; require "wp/plugin.php"; require "NextScripts_APIs/postToGooglePlus.php"; $nt = new nxsAPI_GP(); $loginError = $nt->connect('*****@*****.**', 'stbaby2014'); $lnk=array('img'=>'http://www.storebaby.it/media/catalog/product/0/0/00007331070000.jpeg'); //$lnk = array('img'=>'http://www.nextscripts.com/imgs/nextscripts.png'); var_dump($nt->postGP('Chicco Fiat 500 macchina elettronica - red 00007331070000 http://www.storebaby.it', $lnk, '113160380943238250605')); var_dump($loginError); //var_dump(doConnectToGooglePlus2('*****@*****.**', 'stbaby2014')); //var_dump( doPostToGooglePlus2('Test', 'http://digilander.libero.it/caiofior/','113160380943238250605'));