cellphoneworld

Untitled

Jan 23rd, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 190.24 KB | None | 0 0
  1. <?php
  2.  
  3. // spintax
  4. require_once ('inc/class.spintax.php');
  5.  
  6.  
  7. // youtube
  8. require_once ('inc/youtube_class.php');
  9.  
  10. /*
  11. * ---* Auto Link Builder Class ---
  12. */
  13. class wp_automatic {
  14. public $ch = '';
  15. public $db = '';
  16. public $spintax = '';
  17. public $plugin_url = '';
  18. public $wp_prefix = '';
  19. public $used_keyword = '';
  20. public $used_link ='';
  21. public $used_tags = '' ;
  22. public $duplicate_id = '';
  23. public $cached_file_path = '';
  24. public $minimum_post_timestamp = '';
  25. public $minimum_post_timestamp_camp = '';
  26. public $debug = false;
  27. public $translationSuccess ;
  28. public $currentCampID ;
  29.  
  30. // Excluded links cache
  31. public $campExcludedLinks; // excluded links of the currecnt campaign comma separated
  32. public $campExcludedLinksFetched; // true if the excluded links fetched from the database
  33.  
  34. // Duplicated links cache
  35. public $campOldDuplicateLinks; // duplicate links found from last run
  36. public $campOldDuplicateLinksFetched; // loaded or not?
  37. public $campNewDuplicateLinks; // new checked and found duplicate links
  38. public $campDuplicateLinksUpdate; // update them or not flag
  39.  
  40. // Call limit
  41. public $sourceCallLimit; // number of times allowed to call the source if reached exists
  42. public $sourceCallTimes; // number of times the source was called
  43.  
  44. // Link sufix
  45. public $isLinkSuffixed;
  46.  
  47. //proxy connected or not
  48. public $isProxified;
  49.  
  50. //general banned words
  51. public $generalBannedWords;
  52.  
  53. /*
  54. * ---* Class Constructor ---
  55. */
  56. function __construct() {
  57. // plugin url
  58. $siteurl = get_bloginfo ( 'url' );
  59. $this->plugin_url = $siteurl . '/wp-content/plugins/alb/';
  60.  
  61. echo '<br><small><i>Memory used before running the script: '. number_format(memory_get_peak_usage()/(1024*1024),2) .'MB and DB queries count:'.get_num_queries() .'</i> </small>';
  62.  
  63. // db
  64. global $wpdb;
  65. $this->db = $wpdb;
  66. $this->wp_prefix = $wpdb->prefix;
  67. // $this->db->show_errors();
  68. @$this->db->query ( "set session wait_timeout=28800" );
  69.  
  70. // curl
  71. $this->ch = curl_init ();
  72. curl_setopt ( $this->ch, CURLOPT_HEADER, 0 );
  73. curl_setopt ( $this->ch, CURLOPT_RETURNTRANSFER, 1 );
  74. curl_setopt ( $this->ch, CURLOPT_CONNECTTIMEOUT, 10 );
  75. curl_setopt ( $this->ch, CURLOPT_TIMEOUT, 200 );
  76. curl_setopt ( $this->ch, CURLOPT_REFERER, 'http://www.bing.com/' );
  77. curl_setopt ( $this->ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36' );
  78. //curl_setopt($this->ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8');
  79.  
  80. curl_setopt ( $this->ch, CURLOPT_MAXREDIRS, 20 ); // Good leeway for redirections.
  81. @curl_setopt ( $this->ch, CURLOPT_FOLLOWLOCATION, 1 ); // Many login forms redirect at least once.
  82.  
  83. @curl_setopt ( $this->ch, CURLOPT_COOKIEJAR, str_replace('core.php', 'cookie.txt', __FILE__) );
  84. @curl_setopt ( $this->ch, CURLOPT_COOKIEJAR, 'cookie.txt' );
  85. curl_setopt ( $this->ch, CURLOPT_SSL_VERIFYPEER, false );
  86.  
  87. /*
  88. //verbose
  89. $verbose=fopen( str_replace('core.php', 'verbose.txt', __FILE__) , 'w');
  90. curl_setopt($this->ch, CURLOPT_VERBOSE , 1);
  91. curl_setopt($this->ch, CURLOPT_STDERR,$verbose);
  92. */
  93.  
  94.  
  95. // spintax
  96. $this->spintax = new Spintax ();
  97.  
  98. // Ini excluded links
  99. $this->campExcludedLinksFetched = false;
  100. $this->campOldDuplicateLinksFetched = false;
  101. $this->campDuplicateLinksUpdate = false;
  102. $this->campNewDuplicateLinks = array();
  103.  
  104. // Link suffix
  105. $this->isLinkSuffixed = false;
  106.  
  107. // Call Limit
  108. $this->sourceCallLimit = 2 ;
  109. $this->sourceCallTimes = 0 ;
  110.  
  111. // proxified
  112. $this->isProxified = false;
  113.  
  114. //wp_automatic_ccc_stop
  115. $this->generalBannedWords = get_option('wp_automatic_ccc_stop','');
  116.  
  117. }
  118.  
  119. /*
  120. * ---* Function Process Campaigns ---
  121. */
  122. function process_campaigns($cid = false) {
  123.  
  124. // DB prefix
  125. $prefix = $this->db->prefix;
  126.  
  127. // Single or all check
  128. if (trim ( $cid ) == '') {
  129.  
  130. // All campaings
  131. $last = get_option ( 'gm_last_processed', 0 );
  132.  
  133. // get all the campaigns from the db lower than the last processed
  134. $query = "SELECT * FROM {$this->wp_prefix}automatic_camps where camp_id < $last ORDER BY camp_id DESC";
  135. $camps = $this->db->get_results ( $query );
  136.  
  137. // check if results returned with id less than the last processed or not if not using regular method
  138. $query = "SELECT * FROM {$this->wp_prefix}automatic_camps WHERE camp_id >= $last ORDER BY camp_id DESC";
  139. $camps2 = $this->db->get_results ( $query );
  140.  
  141. // merging 2 arrays
  142. $camps = array_merge ( $camps, $camps2 );
  143. } else {
  144.  
  145. // Single campaign process
  146. $query = "SELECT * FROM {$this->wp_prefix}automatic_camps where camp_id = $cid ORDER BY camp_id DESC";
  147. $camps = $this->db->get_results ( $query );
  148. }
  149.  
  150. // check if need to process camaigns or skip
  151. if (count ( $camps ) == 0) {
  152. echo '<br>No valid campaigns to process ';
  153. return;
  154. }else{
  155. if(trim($cid) == '')
  156. echo '<br>DB contains '.count($camps).' campaigns<br>';
  157. }
  158.  
  159. // now processing each fetched campaign
  160. $i = 0;
  161. foreach ( $camps as $campaign ) {
  162.  
  163. // reading post status
  164. $status = get_post_status ( $campaign->camp_id );
  165.  
  166. // if published process
  167. if ($status == 'publish') {
  168. if ($i != 0)
  169. echo '<br>';
  170. echo "<b>Processing Campaign</b> $campaign->camp_name { $campaign->camp_id }";
  171.  
  172. // updating the last id processed
  173. update_option ( 'gm_last_processed', $campaign->camp_id );
  174.  
  175. //check if deserve spinning now or not
  176. if(trim($cid) == false){
  177.  
  178. //read post every x minutes
  179. if( stristr($campaign->camp_general, 'a:') ) $campaign->camp_general=base64_encode($campaign->camp_general);
  180. $camp_general = unserialize (base64_decode( $campaign->camp_general) );
  181. $camp_general=array_map('wp_automatic_stripslashes', $camp_general);
  182.  
  183. if(! is_array($camp_general) || ! isset($camp_general['cg_update_every']) ){
  184. $camp_general = array('cg_update_every'=>60 ,'cg_update_unit'=> 1);
  185. }
  186.  
  187. $post_every = $camp_general['cg_update_every'] * $camp_general['cg_update_unit'];
  188.  
  189. echo '<br>Campaign scheduled to process every '.$post_every . ' minutes ';
  190.  
  191. //get last check time
  192. $last_update=get_post_meta($campaign->camp_id,'last_update',1);
  193. if(trim($last_update) == '') $last_update =1388692276 ;
  194. // echo '<br>Last updated stamp '.$last_update;
  195.  
  196. $difference = $this->get_time_difference($last_update, time());
  197.  
  198. echo '<br> last processing was <strong>'.$difference. '</strong> minutes ago ';
  199.  
  200. if($difference > $post_every ){
  201. echo '<br>Campaign passed the time and eligible to be processed';
  202. update_post_meta($campaign->camp_id,'last_update',time());
  203.  
  204. $this->log ( '<strong>Cron</strong> >> eligible waiting campaign' , $campaign->camp_name .'{'.$campaign->camp_id .'} last processing was <strong>'.$difference. '</strong> minutes ago ');
  205.  
  206. //process
  207. $this->log ( '<strong>Cron</strong> >> Processing Campaign:' . $campaign->camp_id, $campaign->camp_name .'{'.$campaign->camp_id .'}');
  208. $this->process_campaign ( $campaign );
  209. }else{
  210. echo '<br>Campaign still not passed '.$post_every . ' minutes';
  211. }
  212.  
  213.  
  214. }else{
  215.  
  216. // No cron just regular call
  217.  
  218. // update last run
  219. update_post_meta($campaign->camp_id,'last_update',time());
  220.  
  221. // process
  222. $this->log ( '<strong>User</strong> >> Processing Campaign:' . $campaign->camp_id, $campaign->camp_name .'{'.$campaign->camp_id .'}' );
  223. $this->process_campaign ( $campaign );
  224.  
  225. }
  226.  
  227.  
  228.  
  229. $i ++;
  230. } elseif (! $status) {
  231. // deleting Camp record
  232. $query = "delete from {$this->wp_prefix}automatic_camps where camp_id= '$campaign->camp_id'";
  233. $this->db->query ( $query );
  234. // deleting matching records for keywords
  235. $query = "delete from {$this->wp_prefix}automatic_keywords where keyword_camp ='$campaign->camp_id'";
  236. $this->db->query ( $query );
  237. }else{
  238. echo 'Campaign should be published firstly to run..';
  239. }
  240. }
  241. }
  242.  
  243. /*
  244. * ---* Processing Single Campaign Function ---
  245. */
  246. function process_campaign($camp) {
  247.  
  248. // Ini get options
  249. $this->currentCampID = $camp->camp_id;
  250.  
  251.  
  252. $camp_post_every = $camp->camp_post_every;
  253. $wp_automatic_tw = get_option ( 'wp_automatic_tw', 400 );
  254. $wp_automatic_options = get_option('wp_automatic_options',array() );
  255. $camp_type = $camp->camp_type;
  256. $camp_post_custom_k = unserialize ( $camp->camp_post_custom_k );
  257. $camp_post_custom_v = unserialize ( $camp->camp_post_custom_v );
  258.  
  259.  
  260. //camp general options
  261. if( stristr($camp->camp_general, 'a:') ) $camp->camp_general=base64_encode($camp->camp_general);
  262. $camp_general = unserialize ( base64_decode( $camp->camp_general) );
  263. @$camp_general=array_map('wp_automatic_stripslashes', $camp_general);
  264.  
  265. // get the count of posted posts so far
  266. $key = 'Posted:' . $camp->camp_id;
  267. $query = "select count(id) as count from {$this->wp_prefix}automatic_log where action='$key'";
  268. $temp = $this->db->get_results ( $query );
  269. $temps = $temp [0];
  270. $posted = $temps->count;
  271.  
  272.  
  273. // if maximum reached skip
  274. if ($camp_post_every <= $posted) {
  275. echo '<br>Maximum Number of posts are Posted we will stop now. You have set this campaign to post a maximum of '.$camp_post_every. ' posts.';
  276. $this->log('Cancel Campaign', 'campaign reached maximum number of posts');
  277. return false;
  278. }
  279.  
  280. // campaign options
  281. $camp_opt = unserialize ( $camp->camp_options );
  282.  
  283. if (! is_array ( $camp_opt ))
  284. $camp_opt = array ();
  285.  
  286. //link suffix
  287. if(in_array('OPT_LINK_PREFIX', $camp_opt)){
  288. $this->isLinkSuffixed = true;
  289. }
  290.  
  291. // reading keywords that need to be processed
  292. $rawKeywords = trim($camp->camp_keywords);
  293. if(! stristr($rawKeywords, ',')){
  294.  
  295. $newLinesCount = substr_count($rawKeywords, "\n");
  296.  
  297. if($newLinesCount > 0 ){
  298. $keywords = explode("\n", $rawKeywords);
  299.  
  300. $rawKeywords = implode(',', $keywords);
  301. echo '<br>keywords suspected to be one per line adapting...';
  302. }
  303.  
  304. }
  305.  
  306. $keywords = explode ( ',', $rawKeywords );
  307. $keywords=array_filter($keywords);
  308. $keywords=array_map('trim', $keywords);
  309.  
  310.  
  311. // set minimum item date if exists
  312. if(in_array('OPT_YT_DATE', $camp_opt)){
  313.  
  314. // check if dynamic date
  315. if(in_array('OPT_YT_DATE_T', $camp_opt) && is_numeric(trim($camp_general['cg_yt_dte_minutes'])) ){
  316.  
  317. $cg_yt_dte_minutes = trim($camp_general['cg_yt_dte_minutes']);
  318. $current_time = time('now');
  319. $minimum_time = $current_time - $cg_yt_dte_minutes * 60;
  320. // echo '<br>Minimum timestamp:'.$minimum_time;
  321. $this->minimum_post_timestamp = $minimum_time;
  322. }else{
  323. $this->minimum_post_timestamp = strtotime($camp_general['cg_yt_dte_year'].'-'.$camp_general['cg_yt_dte_month'].'-'.$camp_general['cg_yt_dte_day'].'T00:00:00.000Z');
  324. }
  325.  
  326.  
  327. $this->minimum_post_timestamp_camp = $camp->camp_id;
  328.  
  329. }
  330.  
  331. //Rotate Keywords
  332. if(in_array('OPT_ROTATE', $camp_opt)){
  333. echo '<br>Rotating Keywords Enabled';
  334.  
  335. //last used keyword
  336. $last_keyword = get_post_meta($camp->camp_id ,'last_keyword',1);
  337.  
  338. if( ! trim($last_keyword) == ''){
  339. //found last keyword usage let's split
  340. echo '<br>Last Keyword: '.$last_keyword;
  341.  
  342. //add all keywords after the last keyword
  343. $add = false;
  344. foreach ($keywords as $current_keword){
  345. if($add){
  346. //set add flag to add all coming keywords
  347. $rotatedKeywords[]=$current_keword;
  348.  
  349. }elseif (trim($current_keword) == trim($last_keyword)) {
  350. $add = true;
  351. }
  352. }
  353.  
  354. //add all keywords before the last keyword
  355. foreach ($keywords as $current_keword){
  356. $rotatedKeywords[]=$current_keword;
  357. if(trim($current_keword) == trim ($last_keyword)) break ;
  358.  
  359. }
  360.  
  361. //set keywords to rotated keywords
  362. if( count($rotatedKeywords) != 0 ) $keywords = $rotatedKeywords;
  363. $keywordsString = implode(',', $rotatedKeywords);
  364. $camp->camp_keywords=$keywordsString;
  365. }
  366. }else{
  367. $camp->camp_keywords=implode(',', $keywords);
  368. }
  369.  
  370. //Rotate feeds
  371. if(in_array('OPT_ROTATE_FEEDS', $camp_opt)){
  372. echo '<br>Rotating feeds Enabled';
  373.  
  374. //last used feed
  375. $last_feed = get_post_meta($camp->camp_id ,'last_feed',1);
  376.  
  377. if( ! trim($last_feed) == ''){
  378. //found last feed usage let's split
  379. echo '<br>Last feed: '.$last_feed;
  380.  
  381. //add all feeds after the last feed
  382. $add = false;
  383. $feeds = explode("\n", $camp->feeds);
  384. $feeds = array_filter($feeds);
  385.  
  386. foreach ($feeds as $current_feed){
  387.  
  388. if($add){
  389. //set add flag to add all coming feeds
  390. $rotatedfeeds[]=$current_feed;
  391.  
  392. }elseif (trim($current_feed) == trim($last_feed)) {
  393. $add = true;
  394. }
  395. }
  396.  
  397.  
  398. //add all feeds before the last feed
  399. foreach ($feeds as $current_feed){
  400. $rotatedfeeds[]=$current_feed;
  401. if(trim($current_feed) == trim ($last_feed)) break ;
  402.  
  403. }
  404.  
  405. //set feeds to rotated feeds
  406. if( count($rotatedfeeds) != 0 ) $feeds = $rotatedfeeds;
  407. $feedsString = implode("\n", $rotatedfeeds);
  408. $camp->feeds=$feedsString;
  409. }
  410. }
  411.  
  412.  
  413. $post_content = stripslashes($camp->camp_post_content );
  414. $post_title = stripslashes( $camp->camp_post_title );
  415.  
  416. if(in_array('OPT_USE_PROXY', $camp_opt) && $camp_type != 'Articles' && $camp_type != 'ArticlesBase'){
  417. $this->fire_proxy ();
  418. }
  419.  
  420.  
  421. // ini content
  422. $abcont = '';
  423. if ($camp_type == 'Articles') {
  424.  
  425. // proxyfy
  426. $this->fire_proxy ();
  427.  
  428. $article = $this->articlebase_get_post ( $camp );
  429. $abcont = $article ['cont'];
  430. $title = $article ['title'];
  431. $source_link = $article ['source_link'];
  432. $img = $article;
  433.  
  434. }elseif ($camp_type == 'ArticlesBase') {
  435.  
  436. // proxyfy
  437. $this->fire_proxy ();
  438.  
  439. $article = $this->articlebase_get_post ( $camp );
  440. $abcont = $article ['cont'];
  441. $title = $article ['title'];
  442. $source_link = $article ['source_link'];
  443. $img = $article;
  444.  
  445. } elseif ($camp_type == 'Feeds') {
  446. // feeds posting
  447. echo '<br>Should get content from feeds';
  448. $article = $this->feeds_get_post ( $camp );
  449. $abcont = $article ['cont'];
  450. $title = $article ['title'];
  451. $source_link = $article ['source_link'];
  452. $img = $article;
  453. } elseif ($camp_type == 'Amazon') {
  454. echo '<br>Trying to post a new Amazon product...';
  455. $product = $this->amazon_get_post ( $camp );
  456.  
  457. //update offer url to add to chart
  458.  
  459. if ( in_array('OPT_LINK_CHART', $camp_opt) ) {
  460.  
  461. $product['product_link'] = $product['chart_url'];
  462.  
  463. }
  464.  
  465. $img =$product;
  466.  
  467. $abcont = @$product ['offer_desc'];
  468. $title = @$product ['offer_title'];
  469. $source_link = @$product ['offer_url'];
  470. $product_img = @$product ['offer_img'];
  471. $product_price = @$product ['offer_price'];
  472. } elseif ($camp_type == 'Clickbank') {
  473.  
  474. echo '<br>Clickbank product is required';
  475. $img = $product = $this->clickbank_get_post ( $camp );
  476. $abcont = $product ['offer_desc'];
  477. $title = $product ['title'];
  478. $source_link = $product ['offer_link'];
  479. $product_img = $product ['img'];
  480. $product_original_link = $product ['original_link'];
  481.  
  482. // print_r($product);
  483. } elseif ($camp_type == 'Youtube') {
  484.  
  485. echo '<br>Youtube Vid is required';
  486. $img = $vid = $this->youtube_get_post ( $camp );
  487. $abcont = $vid ['vid_desc'];
  488. $original_title = $vid ['vid_title'];
  489. $title = $vid ['vid_title'];
  490. $source_link = $vid ['vid_url'];
  491.  
  492. } elseif($camp_type == 'Vimeo'){
  493.  
  494. echo '<br>Vimeo campaign let\'s get vimeo vid';
  495.  
  496. $img = $vid = $this->vimeo_get_post ( $camp );
  497.  
  498. //set player width and hieght
  499.  
  500. $abcont = $vid ['vid_description'];
  501. $original_title = $vid ['vid_title'];
  502. $title = $vid ['vid_title'];
  503. $source_link = $vid ['vid_url'];
  504.  
  505. } elseif ($camp_type == 'Flicker') {
  506. echo '<br>Flicker image is required';
  507. $img = $this->flicker_get_post ( $camp );
  508.  
  509. $abcont = $img ['img_description'];
  510. $original_title = $img ['img_title'];
  511. $title = $img ['img_title'];
  512. $source_link = $img ['img_link'];
  513. } elseif ($camp_type == 'eBay') {
  514. echo '<br>eBay item is required';
  515. $img = $this->ebay_get_post ( $camp );
  516.  
  517. $abcont = $img ['item_desc'];
  518. $original_title = $img ['item_title'];
  519. $title = $img ['item_title'];
  520. $source_link = $img ['item_link'];
  521. }elseif($camp_type == 'Spintax'){
  522.  
  523. echo '<p>Processing spintax campaign';
  524.  
  525. $abconts =$post_title . '(99999)' . $post_content;
  526.  
  527. if( in_array('OPT_TBS', $camp_opt) ){
  528. $abconts = $this->spin ( $abconts );
  529. }
  530.  
  531.  
  532. $abconts = $this->spintax->spin ( $abconts );
  533. $tempz = explode ( '(99999)', $abconts );
  534.  
  535. // Rewrite the title
  536. if(! in_array('OPT_TBS_TTL', $camp_opt)){
  537. echo '<br>Spinning the title';
  538. $post_title = $tempz [0];
  539. }
  540.  
  541.  
  542. $post_content = $tempz [1];
  543. $title =trim($post_title);
  544. $img=array();
  545. }elseif( $camp_type == 'Facebook' ){
  546.  
  547. $img = $this->fb_get_post($camp);
  548.  
  549. $abcont = $img['matched_content'];
  550. $original_title = $img ['original_title'];
  551. $title = $img ['original_title'];
  552. $source_link = $img ['original_link'];
  553.  
  554. }elseif ($camp_type == 'Pinterest' ){
  555.  
  556. $img = $this->pinterest_get_post($camp);
  557.  
  558. $abcont = $img ['pin_description'];
  559. $original_title = $img ['pin_title'];
  560. $title = $img ['pin_title'];
  561. $source_link = $img ['pin_url'];
  562.  
  563. }elseif ($camp_type == 'Instagram' ){
  564.  
  565. $img = $this->instagram_get_post($camp);
  566.  
  567. $abcont = $img ['item_description'];
  568. $original_title = $img ['item_title'];
  569. $title = $img ['item_title'];
  570. $source_link = $img ['item_url'];
  571.  
  572. }elseif($camp_type == 'Twitter' ){
  573.  
  574. $img = $this->twitter_get_post($camp);
  575.  
  576. $abcont = $img ['item_description'];
  577. $original_title = $img ['item_title'];
  578. $title = $img ['item_title'];
  579. $source_link = $img ['item_url'];
  580.  
  581.  
  582. }elseif($camp_type == 'SoundCloud' ){
  583.  
  584. $img = $this->sound_get_post($camp);
  585.  
  586. $abcont = $img ['item_description'];
  587. $original_title = $img ['item_title'];
  588. $title = $img ['item_title'];
  589. $source_link = $img ['item_url'];
  590.  
  591.  
  592. }elseif($camp_type == 'Craigslist' ){
  593.  
  594. $img = $this->craigslist_get_post($camp);
  595.  
  596. $abcont = $img ['item_description'];
  597. $original_title = $img ['item_title'];
  598. $title = $img ['item_title'];
  599. $source_link = $img ['item_link'];
  600.  
  601. }elseif($camp_type == 'Reddit' ){
  602.  
  603. $img = $this->reddit_get_post($camp);
  604.  
  605. $abcont = $img ['item_description'];
  606. $original_title = $img ['item_title'];
  607. $title = $img ['item_title'];
  608. $source_link = $img ['item_url'];
  609.  
  610.  
  611. }elseif($camp_type == 'Itunes' ){
  612. $img = $this->itunes_get_post($camp);
  613. $abcont = $img ['item_description'];
  614. $original_title = $img ['item_title'];
  615. $title = $img ['item_title'];
  616. $source_link = $img ['item_link'];
  617.  
  618. }elseif($camp_type == 'Envato' ){
  619.  
  620. $img = $this->envato_get_post($camp);
  621. $abcont = $img ['item_description'];
  622. $original_title = $img ['item_title'];
  623. $title = $img ['item_title'];
  624. $source_link = $img ['item_link'];
  625.  
  626. }elseif($camp_type == 'DailyMotion' ){
  627.  
  628. $img = $this->DailyMotion_get_post($camp);
  629.  
  630. $abcont = $img ['item_description'];
  631. $original_title = $img ['item_title'];
  632. $title = $img ['item_title'];
  633. $source_link = $img ['item_link'];
  634.  
  635. }elseif($camp_type == 'Walmart' ){
  636.  
  637. $img = $this->walmart_get_post($camp);
  638.  
  639. $abcont = $img ['item_description'];
  640. $original_title = $img ['item_title'];
  641. $title = $img ['item_title'];
  642. $source_link = $img ['item_link'];
  643.  
  644. }elseif($camp_type == 'Single' ){
  645.  
  646. $img = $this->single_get_post($camp);
  647.  
  648. $abcont = $img ['matched_content'];
  649. $original_title = $img ['original_title'];
  650. $title = $img ['original_title'];
  651. $source_link = $img ['source_link'];
  652. }
  653.  
  654. // link suffix
  655. if($this->isLinkSuffixed == true){
  656. if(stristr($source_link, '?')){
  657. $source_link = $source_link.'&rand='.$this->currentCampID ;
  658. }else{
  659. $source_link = $source_link.'?rand='.$this->currentCampID ;
  660. }
  661. }
  662.  
  663. //limit the content returned
  664. if(in_array('OPT_LIMIT', $camp_opt)){
  665. echo '<br>Triming post content to '.$camp_general['cg_content_limit'] . ' chars';
  666. $abcont = $this->truncateHtml($abcont,$camp_general['cg_content_limit']);
  667. }
  668.  
  669. if(in_array('OPT_LIMIT_TITLE', $camp_opt) && trim($title) != ''){
  670. echo '<br>Triming post title to '.$camp_general['cg_title_limit'] . ' chars';
  671.  
  672. $titleCharsCount = $this->chars_count($title);
  673.  
  674. if( $camp_general['cg_title_limit'] < $titleCharsCount ){
  675.  
  676. if(function_exists('mb_substr')){
  677. $title = mb_substr($title, 0,$camp_general['cg_title_limit']);
  678. }else{
  679. $title = substr($title, 0,$camp_general['cg_title_limit']);
  680.  
  681. }
  682.  
  683. $title = $this->removeEmoji($title);
  684. $title = $title . '...';
  685.  
  686. }
  687.  
  688. }
  689.  
  690.  
  691. // check if valid content fetched
  692. if (trim ( $title ) != '') {
  693.  
  694. // validate if the content contains wanted or execluded texts
  695.  
  696. $valid = true;
  697.  
  698. $exact = $camp->camp_post_exact;
  699. $execl = $camp->camp_post_execlude;
  700. $execr = '';
  701. $execr = @$camp_general['cg_camp_post_regex_exact'];
  702. $excludeRegex = @$camp_general['cg_camp_post_regex_exclude'];
  703.  
  704. // validating exact
  705. if (trim ( $exact ) != '' & in_array('OPT_EXACT', $camp_opt) && ! in_array('OPT_EXACT_AFTER', $camp_opt)) {
  706. $valid = false;
  707. $exactArr = explode ( "\n", trim ( $exact ) );
  708.  
  709. foreach ( $exactArr as $wordexact ) {
  710. if (trim ( $wordexact != '' )) {
  711.  
  712. if(in_array('OPT_EXACT_STR', $camp_opt)){
  713.  
  714. if( in_array('OPT_EXACT_TITLE_ONLY', $camp_opt) && stristr( html_entity_decode($title) , trim ( $wordexact ) ) ){
  715. echo '<br>Title contains the word : ' . $wordexact ;
  716. $valid = true;
  717. break;
  718. }elseif ( ! in_array('OPT_EXACT_TITLE_ONLY', $camp_opt) && ( stristr ( html_entity_decode($abcont) , trim ( $wordexact ) ) || stristr ( trim ( $wordexact ) , html_entity_decode($title) ) ) ) {
  719. echo '<br>Content contains the word : ' . $wordexact ;
  720. $valid = true;
  721. break;
  722. }else{
  723. echo '<br>Content does not contain the word : ' . $wordexact . ' try another ';
  724. } // match
  725.  
  726. }else{
  727.  
  728. if( in_array('OPT_EXACT_TITLE_ONLY', $camp_opt) && preg_match ( '/\b' . trim ( $wordexact ) . '\b/iu', html_entity_decode($title) ) ){
  729. echo '<br>Title contains the word : ' . $wordexact ;
  730. $valid = true;
  731. break;
  732. }elseif ( ! in_array('OPT_EXACT_TITLE_ONLY', $camp_opt) && ( preg_match ( '/\b' . trim ( $wordexact ) . '\b/iu', html_entity_decode($abcont) ) || preg_match ( '/\b' . trim ( $wordexact ) . '\b/iu', html_entity_decode($title) ) ) ) {
  733. echo '<br>Content contains the word : ' . $wordexact ;
  734. $valid = true;
  735. break;
  736. }else{
  737. echo '<br>Content does not contain the word : ' . $wordexact . ' try another ';
  738. } // match
  739.  
  740.  
  741. }
  742.  
  743.  
  744. } // trim wordexact
  745. } // foreach exactword
  746. } // trim exact
  747.  
  748. // validating execlude
  749. if ($valid == true) {
  750.  
  751. echo ' <br>Valid post';
  752.  
  753. $execl.= "\n".$this->generalBannedWords;
  754.  
  755. if (trim ( $execl ) != '' && in_array('OPT_EXECLUDE', $camp_opt) && ! in_array('OPT_EXECLUDE_AFTER', $camp_opt) ) {
  756.  
  757. $execlArr = explode ( "\n", trim ( $execl ) );
  758.  
  759. foreach ( $execlArr as $wordex ) {
  760.  
  761.  
  762. if (trim ( $wordex != '' )) {
  763. if ( preg_match ( '/\b' . trim ( $wordex ) . '\b/iu', html_entity_decode($abcont) ) || preg_match ( '/\b' . trim ( $wordex ) . '\b/iu', (html_entity_decode($title)) ) ) {
  764. echo '<br>Content contains the banned word :' . $wordex . ' getting another ';
  765. $valid = false;
  766. break;
  767. }
  768. } // trim wordexec
  769. } // foreach wordex
  770. } // trim execl
  771. } // valid
  772.  
  773.  
  774. // validate REGEX
  775. if($valid == true){
  776.  
  777. if(trim ( $execr ) != '' & in_array('OPT_EXACT_REGEX', $camp_opt) && ! in_array('OPT_EXACT_REGEX_AFTER', $camp_opt)){
  778.  
  779. $valid = false;
  780.  
  781. $exactArr = explode ( "\n", trim ( $execr ) );
  782.  
  783. foreach ( $exactArr as $wordexact ) {
  784. if (trim ( $wordexact != '' )) {
  785. if ( preg_match ( '{'.$wordexact.'}ius', html_entity_decode($abcont) ) || preg_match ( '{' . trim ( $wordexact ) . '}ius', html_entity_decode($title) ) ) {
  786.  
  787. echo '<br>REGEX Matched : ' . $wordexact ;
  788. $valid = true;
  789. break;
  790. }else{
  791. echo '<br>REGEX did not match : ' . $wordexact . ' try another ';
  792. } // match
  793. } // trim wordexact
  794. } // foreach exactword
  795.  
  796. }
  797. }
  798.  
  799.  
  800. // exclude if match a specific REGEX
  801. if( $valid == true ){
  802.  
  803. if(trim ( $excludeRegex ) != '' & in_array('OPT_EXCLUDE_REGEX', $camp_opt) ){
  804.  
  805. $excludeArr = explode ( "\n", trim ( $excludeRegex ) );
  806.  
  807. foreach ( $excludeArr as $wordexact ) {
  808. $wordexact = trim($wordexact);
  809. if (trim ( $wordexact != '' )) {
  810. if ( preg_match ( '{'.$wordexact.'}ius', html_entity_decode($abcont) ) || preg_match ( '{' . trim ( $wordexact ) . '}ius', html_entity_decode($title) ) ) {
  811.  
  812. echo '<br>Exclude REGEX matched : ' . $wordexact ;
  813. $valid = false;
  814. break;
  815. }else{
  816. echo '<br>Exclude REGEX did not match : ' . $wordexact . ' try another ';
  817. } // match
  818. } // trim wordexact
  819. } // foreach exactword
  820.  
  821. }
  822.  
  823. }
  824.  
  825. // duplicate title check
  826. if($valid == true){
  827. //check if there is a post published with the same title
  828. if(in_array('OPT_FEED_TITLE_SKIP',$camp_opt) ) {
  829. if($this->is_title_duplicate($title,$camp->camp_post_type)){
  830. echo '<-- duplicate title skipping..';
  831. $valid = false;
  832. }
  833. }
  834.  
  835. }
  836.  
  837.  
  838. // if not valid process the campaign again and exit
  839. if ($valid == false) {
  840.  
  841. //blacklisting the link so we don'g teg it again and cause a loop
  842. $this->link_execlude($camp->camp_id, $source_link);
  843. $this->process_campaign ( $camp );
  844. exit ();
  845. }
  846.  
  847. // strip links
  848. if (in_array ( 'OPT_STRIP', $camp_opt )) {
  849. echo '<br>Striping links ';
  850. //$abcont = strip_tags ( $abcont, '<p><img><b><strong><br><iframe><embed><table><del><i><div>' );
  851.  
  852.  
  853. preg_match_all('{<a.*?>(.*?)</a>}' , $abcont , $allLinksMatchs);
  854.  
  855. $allLinksTexts = $allLinksMatchs[1];
  856. $allLinksMatchs=$allLinksMatchs[0];
  857.  
  858. $j = 0;
  859. foreach ($allLinksMatchs as $singleLink){
  860.  
  861. if(! stristr($singleLink, 'twitter.com'))
  862. $abcont = str_replace($singleLink, $allLinksTexts[$j], $abcont);
  863.  
  864. $j++;
  865. }
  866.  
  867.  
  868. if( $camp_type == 'Youtube' ){
  869. echo '...striping inline links';
  870. $abcont = preg_replace('/https?:\/\/[^<\s]+/', '', $abcont);
  871. }
  872.  
  873. }
  874.  
  875. // translate the cotent
  876. if (in_array ( 'OPT_TRANSLATE', $camp_opt ) && trim ( $abcont ) != '') {
  877. echo '<br>Translating the post...' . $title;
  878.  
  879. //to translate tags
  880. $tagsToTranslate= '';
  881. if(isset($img['tags']) && trim($img['tags']) != '' ){
  882. $tagsToTranslate = trim($img['tags']);
  883. }
  884.  
  885. if(isset($img['custom_fields'])){
  886. foreach ($img['custom_fields'] as $customFieldArr ){
  887. if($customFieldArr[0] == 'tags'){
  888. $tagsToTranslate = $customFieldArr[1];
  889. break;
  890. }
  891. }
  892. }
  893.  
  894.  
  895. if( trim($tagsToTranslate) != ''){
  896.  
  897. $tagsToTranslate = explode(',', $tagsToTranslate) ;
  898. $tagsToTranslate = array_filter($tagsToTranslate);
  899. $tagsToTranslate=array_map('trim', $tagsToTranslate);
  900. $tagsToTranslate=implode('[t]', $tagsToTranslate);
  901.  
  902. $abcont = $abcont . ' .[tagsToTranslate]'. $tagsToTranslate ;
  903.  
  904. }
  905.  
  906. // Translation Method
  907. $translationMethod = $camp_general['cg_translate_method'];
  908.  
  909. if($translationMethod != 'googleTranslator'){
  910. $translationMethod = 'microsoftTranslator';
  911. }
  912.  
  913. // Translation success flag ini
  914. $this->translationSuccess = false ;
  915.  
  916. $translation = $this->gtranslate ( $title, $abcont, $camp->camp_translate_from, $camp->camp_translate_to ,$translationMethod);
  917.  
  918. if (in_array ( 'OPT_TRANSLATE_TITLE', $camp_opt )) {
  919. $title = $translation [0];
  920. }
  921.  
  922. $abcont = $translation [1];
  923.  
  924. // check if another translation needed
  925. if (trim ( $camp->camp_translate_to_2 ) != 'no' && trim($camp->camp_translate_to_2) !='' ) {
  926. // another translate
  927.  
  928. echo '<br>translating the post another time ';
  929. $translation = $this->gtranslate ( $title, $abcont, $camp->camp_translate_to, $camp->camp_translate_to_2 ,$translationMethod);
  930.  
  931. if (in_array ( 'OPT_TRANSLATE_TITLE', $camp_opt )) {
  932. $title = $translation [0];
  933. }
  934.  
  935. $abcont = $translation [1];
  936. }
  937.  
  938. //strip tagstotransate
  939. if(stristr($abcont, 'tagsToTranslate') || stristr($abcont, '[t]')){
  940. preg_match('{\[tagsToTranslate\](.*)}', $abcont , $tagMatchs);
  941. $tagsTranslated = $tagMatchs[1];
  942. $tagsTranslated = str_replace('[t]', ',' , $tagsTranslated);
  943.  
  944. //strip the tags
  945. $abcont = preg_replace('{\[tagsToTranslate.*}', '', $abcont);
  946.  
  947. if(stristr($abcont, '[t]')){
  948.  
  949. preg_match('{\[t\].*}', $abcont , $tagMatchs);
  950. $tagsTranslated = $tagMatchs[0];
  951. $tagsTranslated = explode('[t]', $tagsTranslated);
  952. $tagsToTranslate= implode(',', array_filter($tagsTranslated));
  953.  
  954. $abcont = preg_replace('{\[t\].*}', '', $abcont);
  955.  
  956. }
  957.  
  958. //restore tags
  959. if(isset($img['tags']) && trim($img['tags']) != '' ){
  960. $img['tags'] = $tagsTranslated;
  961. }
  962.  
  963. $newFields = array();
  964. if(isset($img['custom_fields'])){
  965. foreach ($img['custom_fields'] as $customFieldArr ){
  966. if($customFieldArr[0] == 'tags'){
  967. $newFields[] = array('tags' , $tagsTranslated) ;
  968. }else{
  969. $newFields[] = $customFieldArr;
  970. }
  971. }
  972. $img['custom_fields'] = $newFields;
  973. }
  974.  
  975.  
  976.  
  977. }
  978.  
  979. }
  980.  
  981. // replacing general terms title and source link
  982. if(isset($source_link)) $post_content = str_replace ( '[source_link]', $source_link, $post_content );
  983. $post_title = @str_replace ( '[original_title]', $title, $post_title );
  984. $post_content = str_replace ( '[original_title]', $title, $post_content );
  985.  
  986. if ($camp_type == 'Feeds' ) {
  987.  
  988. $post_content = str_replace ( '[matched_content]', $abcont, $post_content );
  989.  
  990. }elseif( $camp_type == 'Articles' || $camp_type == 'ArticlesBase'){
  991.  
  992. $post_content = str_replace ( '[matched_content]', $abcont, $post_content );
  993.  
  994. } elseif ($camp_type == 'Amazon') {
  995.  
  996. $post_content = str_replace ( '[product_desc]', $abcont, $post_content );
  997. $post_content = str_replace ( '[product_img]', $product_img, $post_content );
  998. //$post_content = str_replace ( '[product_link]', $source_link, $post_content );
  999. $post_content = str_replace ( '[product_price]', $product_price, $post_content );
  1000.  
  1001. //remove built-in gallery for amazon products when a woo gallery is used
  1002. if( $camp->camp_post_type == 'product' && in_array('OPT_AM_GALLERY', $camp_opt)){
  1003. $post_content = str_replace('[product_imgs_html]', '', $post_content);
  1004. }
  1005.  
  1006.  
  1007. } elseif ($camp_type == 'Clickbank') {
  1008. $post_content = str_replace ( '[product_desc]', $abcont, $post_content );
  1009. $post_content = str_replace ( '[product_img]', $product_img, $post_content );
  1010. $post_content = str_replace ( '[product_link]', $source_link, $post_content );
  1011. $post_content = str_replace ( '[product_original_link]', $product_original_link, $post_content );
  1012. } elseif ($camp_type == 'Youtube') {
  1013.  
  1014. $post_content = str_replace ( '[vid_player]', addslashes ( $vid ['vid_player'] ), $post_content );
  1015. $post_content = str_replace ( '[vid_desc]', $abcont, $post_content );
  1016. $post_content = str_replace ( '[vid_views]', $vid ['vid_views'], $post_content );
  1017. $post_content = str_replace ( '[vid_rating]', $vid ['vid_rating'], $post_content );
  1018. $post_content = str_replace ( '[vid_img]', $vid ['vid_img'], $post_content );
  1019. }elseif($camp_type == 'eBay'){
  1020.  
  1021. $post_content = str_replace('[item_desc]', $abcont, $post_content);
  1022.  
  1023. if(stristr($post_content, '[item_images]') && is_array($img['item_images']) ){
  1024.  
  1025. $cg_eb_full_img_t = html_entity_decode( $camp_general['cg_eb_full_img_t']);
  1026.  
  1027. $imgs = $img['item_images'];
  1028.  
  1029. if(! stristr($cg_eb_full_img_t, '[img_src]') ) {
  1030. $cg_eb_full_img_t = '<img src="[img_src]" class="wp_automatic_gallery" />';
  1031. }
  1032.  
  1033. $contimgs='';
  1034. foreach ($imgs as $newimg){
  1035. $tempimg =$cg_eb_full_img_t;
  1036. $contimgs.= str_replace('[img_src]', $newimg, $tempimg);
  1037. }
  1038.  
  1039. $post_content = str_replace('[item_images]', $contimgs, $post_content);
  1040.  
  1041. }
  1042.  
  1043. }elseif ($camp_type == 'Flicker' ) {
  1044.  
  1045. $post_content = str_replace ( '[img_description]', $abcont, $post_content );
  1046.  
  1047. } elseif( $camp_type == 'Vimeo' ) {
  1048.  
  1049. $post_content = str_replace('[vid_description]', $abcont, $post_content);
  1050.  
  1051. //set player width and height
  1052. $vm_width = $camp_general['cg_vm_width'];
  1053. $vm_height = $camp_general['cg_vm_height'];
  1054.  
  1055. if(trim($vm_width)!= ''){
  1056. $img['vid_embed'] = $vid['vid_embed'] = str_replace('width="560"', 'width="'.$vm_width.'"', $vid['vid_embed']);
  1057. }
  1058.  
  1059. if(trim($vm_height)!= ''){
  1060. $img['vid_embed'] = $vid['vid_embed'] = str_replace('height="315"', 'height="'.$vm_height.'"', $vid['vid_embed']);
  1061. }
  1062.  
  1063. }elseif( $camp_type == 'Pinterest' ){
  1064.  
  1065. $post_content = str_replace ( '[pin_description]', $abcont, $post_content );
  1066.  
  1067. }elseif( $camp_type == 'Instagram' ){
  1068.  
  1069. $post_content = str_replace('[item_description]', $abcont, $post_content);
  1070.  
  1071. // if video hide it's image
  1072. if(stristr($abcont, '[embed') && ! in_array('OPT_IT_NO_VID_IMG_HIDE', $camp_opt) ){
  1073. echo '<br>Hiding vid image';
  1074. $post_content = str_replace('[item_img]"', '[item_img]" style="display:none;" ', $post_content);
  1075. $post_content = str_replace('[item_img]\"', '[item_img]\" style="display:none;" ', $post_content);
  1076. }
  1077.  
  1078. }elseif( $camp_type == 'Twitter' ){
  1079.  
  1080. $post_content = str_replace('[item_description]', $abcont, $post_content);
  1081.  
  1082. }elseif( $camp_type == 'Facebook' || $camp_type == 'Single'){
  1083. $post_content = str_replace('[matched_content]', $abcont, $post_content);
  1084. }elseif($camp_type == 'SoundCloud' || $camp_type == 'Craigslist' || $camp_type == 'Itunes' || $camp_type == 'Envato' || $camp_type == 'DailyMotion' || $camp_type == 'Reddit' || $camp_type == 'Walmart' ){
  1085. $post_content = str_replace('[item_description]', $abcont, $post_content);
  1086.  
  1087. } else {
  1088. $post_content .= "<br>$abcont";
  1089. }
  1090.  
  1091. // Replacing generic tags
  1092. if(stristr($this->used_keyword, '_')) {
  1093. $pan=explode('_', $this->used_keyword);
  1094. $this->used_keyword = $pan[1];
  1095. }
  1096.  
  1097. $post_content = str_replace('[keyword]', $this->used_keyword, $post_content);
  1098. $post_title = str_replace('[keyword]', $this->used_keyword, $post_title);
  1099.  
  1100. //replacing attributes
  1101. foreach ( $img as $key => $val ) {
  1102.  
  1103. if( ! is_array($val)){
  1104. $post_content = str_replace ( '[' . $key . ']', $val, $post_content );
  1105. $post_title = str_replace ( '[' . $key . ']', $val, $post_title );
  1106. }
  1107.  
  1108. }
  1109.  
  1110. // replacing custom attributes for feeds
  1111. if($camp_type == 'Feeds'){
  1112.  
  1113. $attributes = $img['attributes'];
  1114.  
  1115. foreach ($attributes as $attributeKey => $attributeValue){
  1116.  
  1117. $post_content = str_replace('['.$attributeKey.']', $attributeValue[0]['data'] , $post_content);
  1118.  
  1119. }
  1120. }
  1121.  
  1122. // formated date
  1123. if(stristr($post_content ,'formated_date') || stristr($post_title, 'formated_date') ){
  1124.  
  1125. $post_title = do_shortcode($post_title);
  1126. $post_content = do_shortcode($post_content);
  1127.  
  1128. }
  1129.  
  1130.  
  1131. // replacing the keywords with affiliate links
  1132. if (in_array ( 'OPT_REPLACE', $camp_opt )) {
  1133. foreach ( $keywords as $keyword ) {
  1134.  
  1135. $keyword = trim($keyword);
  1136.  
  1137. if (trim ( $keyword != '' )) {
  1138. //$post_content = str_replace ( $keyword, '<a href="' . $camp->camp_replace_link . '">' . $keyword . '</a>', $post_content );
  1139.  
  1140. $post_content = preg_replace ( '/\b'.preg_quote($keyword,'/').'\b/', '<a href="' . $camp->camp_replace_link . '">' . $keyword . '</a>', $post_content );
  1141. }
  1142. }
  1143. }
  1144.  
  1145.  
  1146.  
  1147. //replacing patterns
  1148. if(in_array('OPT_RGX_REPLACE', $camp_opt)){
  1149.  
  1150. $regex_patterns = trim($camp_general['cg_regex_replace']);
  1151. echo '<br>Replacing using REGEX';
  1152.  
  1153. //title only flag
  1154. $isTitleOnly = false;
  1155.  
  1156. if(stristr($regex_patterns, '|titleonly')){
  1157. $isTitleOnly=true;
  1158. $regex_patterns=str_replace('|titleonly', '', $regex_patterns) ;
  1159. }
  1160.  
  1161.  
  1162. //protecting tags
  1163. if(in_array('OPT_RGX_REPLACE_PROTECT', $camp_opt)){
  1164. echo '..protecting tags.';
  1165.  
  1166. preg_match_all("/<[^<>]+>/is",$post_content,$matches,PREG_PATTERN_ORDER);
  1167. $htmlfounds=$matches[0];
  1168.  
  1169. //extract all fucken shortcodes
  1170. $pattern="\[.*?\]";
  1171. preg_match_all("/".$pattern."/s",$post_content,$matches2,PREG_PATTERN_ORDER);
  1172. $shortcodes=$matches2[0];
  1173.  
  1174. $htmlfounds = array_merge($htmlfounds,$shortcodes);
  1175.  
  1176. $htmlfounds = array_filter( array_unique($htmlfounds) );
  1177.  
  1178.  
  1179. $i=1;
  1180. foreach ($htmlfounds as $htmlfound){
  1181.  
  1182. $post_content = str_replace($htmlfound, "[" . str_repeat('*', $i) . "]", $post_content);
  1183. $i++;
  1184.  
  1185. }
  1186.  
  1187.  
  1188. }
  1189.  
  1190. if(stristr($regex_patterns, '|')){
  1191. $regex_patterns_arr = explode("\n",$regex_patterns);
  1192.  
  1193. foreach ($regex_patterns_arr as $regex_pattern){
  1194.  
  1195. $regex_pattern = trim($regex_pattern);
  1196.  
  1197. if(stristr($regex_pattern, '|')){
  1198.  
  1199. $regex_pattern_parts = explode('|', $regex_pattern);
  1200.  
  1201. $regex_pattern_search = $regex_pattern_parts[0];
  1202.  
  1203. if(count($regex_pattern_parts) > 2 ){
  1204.  
  1205. $regex_pattern_replace = $regex_pattern_parts[rand(1,count($regex_pattern_parts) - 1)];
  1206. }else{
  1207. $regex_pattern_replace = $regex_pattern_parts[1];
  1208. }
  1209.  
  1210. echo '<br>Replacing '.htmlentities($regex_pattern_search) .' with '.htmlentities($regex_pattern_replace);
  1211.  
  1212. // echo $post_content;
  1213. //exit;
  1214.  
  1215. if(! $isTitleOnly){
  1216. if( ! in_array('OPT_RGX_REPLACE_WORD', $camp_opt)){
  1217. $post_content = preg_replace('{'.$regex_pattern_search.'}su', $regex_pattern_replace, $post_content);
  1218. }else{
  1219. $post_content = preg_replace('{\b'.preg_quote( $regex_pattern_search ).'\b}su', $regex_pattern_replace, $post_content);
  1220. }
  1221. }else{
  1222. echo ' on titles only';
  1223. }
  1224.  
  1225. if(in_array('OPT_RGX_REPLACE_TTL', $camp_opt) || $isTitleOnly){
  1226.  
  1227. if( ! in_array('OPT_RGX_REPLACE_WORD', $camp_opt)){
  1228. $post_title = preg_replace('{'.$regex_pattern_search.'}su', $regex_pattern_replace, $post_title);
  1229. }else{
  1230. $post_title = preg_replace('{\b'.preg_quote( $regex_pattern_search ).'\b}su', $regex_pattern_replace, $post_title);
  1231. }
  1232.  
  1233. }
  1234.  
  1235. }
  1236.  
  1237. }
  1238.  
  1239. }
  1240.  
  1241. //restore protected tags
  1242. if( isset($htmlfounds) and count($htmlfounds) >0 ){
  1243.  
  1244. //restoring
  1245. $i = 1;
  1246. foreach ($htmlfounds as $htmlfound){
  1247. $post_content = str_replace('['.str_repeat('*', $i).']', $htmlfound, $post_content);
  1248. $i++;
  1249. }
  1250.  
  1251.  
  1252. }
  1253.  
  1254. }
  1255.  
  1256.  
  1257. // cache images locally ?
  1258. if (in_array ( 'OPT_CACHE', $camp_opt )) {
  1259.  
  1260. preg_match_all ( '/<img [^>]*src=["|\']([^"|\']+)/i', stripslashes ( $post_content ), $matches );
  1261.  
  1262. $srcs = $matches [1];
  1263. $srcs = array_unique ( $srcs );
  1264. $current_host = parse_url ( home_url (), PHP_URL_HOST );
  1265. foreach ( $srcs as $image_url ) {
  1266.  
  1267. //check inline images
  1268. if(stristr($image_url, 'data:image')){
  1269. continue;
  1270. }
  1271.  
  1272. //instantiate so we replace . note we modify image_url
  1273. $image_url_original = $image_url;
  1274.  
  1275. //decode html entitiies
  1276. $image_url = html_entity_decode($image_url);
  1277.  
  1278. if(stristr($image_url, '%') ) {
  1279. $image_url = urldecode($image_url);
  1280. }
  1281.  
  1282. //file name to store
  1283. $filename = basename ( $image_url );
  1284.  
  1285. //clean names
  1286. if(in_array('OPT_CACHE_CLEAN' , $camp_opt )){
  1287.  
  1288. $clean_name = '';
  1289. $clean_name = sanitize_title($post_title);
  1290.  
  1291.  
  1292.  
  1293. if(trim($clean_name) != ""){
  1294.  
  1295. //get the image extension \.\w{3}
  1296. $ext = pathinfo($filename, PATHINFO_EXTENSION);
  1297.  
  1298. if(stristr($ext, '?')){
  1299. $ext_parts = explode('?',$ext);
  1300. $ext = $ext_parts[0];
  1301. }
  1302.  
  1303. //clean parameters after filename
  1304. $filename = trim($clean_name);
  1305.  
  1306.  
  1307. if( trim($ext) !='' ){
  1308. $filename = $filename .'.'. $ext;
  1309. }
  1310.  
  1311. }
  1312.  
  1313. }
  1314.  
  1315.  
  1316.  
  1317. if(stristr($image_url, '%') || stristr($filename, '%') ){
  1318. $filename = urldecode($filename);
  1319. }
  1320.  
  1321.  
  1322. if(stristr($image_url ,' ')){
  1323. $image_url = str_replace(' ', '%20', $image_url);
  1324. }
  1325.  
  1326. $imghost = parse_url ( $image_url, PHP_URL_HOST );
  1327.  
  1328. if(stristr($imghost, 'http://')){
  1329. $imgrefer=$imghost;
  1330. }else{
  1331. $imgrefer = 'http://'.$imghost;
  1332. }
  1333.  
  1334.  
  1335. if ($imghost != $current_host ) {
  1336. echo '<br>Caching image: ' . $image_url;
  1337.  
  1338.  
  1339. // let's cache this image
  1340. // set thumbnail
  1341. $upload_dir = wp_upload_dir ();
  1342.  
  1343.  
  1344. //curl get
  1345. $x='error';
  1346. curl_setopt($this->ch, CURLOPT_HTTPGET, 1);
  1347. curl_setopt($this->ch, CURLOPT_URL, trim($image_url));
  1348.  
  1349. //empty referal
  1350. if(! in_array('OPT_CACHE_REFER_NULL', $camp_opt) ){
  1351. curl_setopt ( $this->ch, CURLOPT_REFERER, $imgrefer );
  1352. }else{
  1353. curl_setopt ( $this->ch, CURLOPT_REFERER, '' );
  1354. }
  1355.  
  1356.  
  1357. curl_setopt ( $this->ch, CURLOPT_HEADER, 0 );
  1358.  
  1359. $image_data=$this->curl_exec_follow($this->ch);
  1360. $image_data_md5 = md5($image_data);
  1361.  
  1362. //check if already cached before
  1363. $is_cached = $this->is_cached($image_url , $image_data_md5);
  1364. if( $is_cached != false ){
  1365. echo '<--already cached';
  1366. $post_content = str_replace ( $image_url_original, $is_cached , $post_content );
  1367. continue;
  1368. }
  1369.  
  1370.  
  1371. $x=curl_error($this->ch);
  1372.  
  1373.  
  1374. if(trim($image_data) != ''){
  1375.  
  1376. $x=curl_error($this->ch);
  1377.  
  1378. if (stristr ( $filename, '?' )) {
  1379. $farr = explode ( '?', $filename );
  1380. $filename = $farr [0];
  1381. }
  1382.  
  1383. if (wp_mkdir_p ( $upload_dir ['path'] ))
  1384. $file = $upload_dir ['path'] . '/' . $filename;
  1385. else
  1386. $file = $upload_dir ['basedir'] . '/' . $filename;
  1387.  
  1388. // check if same image name already exists
  1389.  
  1390. if (file_exists ( $file )) {
  1391. $filename = time ( 'now' ) .'_'. rand(0,999) . '_' . $filename;
  1392.  
  1393. if (wp_mkdir_p ( $upload_dir ['path'] ))
  1394. $file = $upload_dir ['path'] . '/' . $filename;
  1395. else
  1396. $file = $upload_dir ['basedir'] . '/' . $filename;
  1397. } else {
  1398. }
  1399.  
  1400.  
  1401. file_put_contents ( $file, $image_data );
  1402. $file_link = $upload_dir ['url'] . '/' . $filename;
  1403.  
  1404. // replace original src with new file link
  1405. $post_content = str_replace ( $image_url_original, $file_link, $post_content );
  1406. $this->img_cached($image_url_original, $file_link,$image_data_md5,$file);
  1407.  
  1408. echo '<-- cached';
  1409. }else{
  1410. echo '<-- can not get image content '.$x;
  1411. }
  1412.  
  1413.  
  1414. }
  1415. } // end foreach image
  1416. }
  1417.  
  1418. // replacing words that should be replaced
  1419. $sets = stripslashes(get_option ( 'wp_automatic_replace', '' ) );
  1420.  
  1421.  
  1422. //exit;
  1423. $sets_arr = explode ( "\n", $sets );
  1424.  
  1425. foreach ( $sets_arr as $set ) {
  1426. if (trim ( $set ) != '' && stristr ( $set, '|' )) {
  1427.  
  1428. // valid set let's replace
  1429. $set_words = explode ( '|', $set );
  1430.  
  1431.  
  1432. // cleaning empty words
  1433. $i = 0;
  1434. foreach ( $set_words as $setword ) {
  1435. if (trim ( $setword ) == '') {
  1436. unset ( $set_words [$i] );
  1437. }
  1438. $i ++;
  1439. }
  1440.  
  1441. if (count ( $set_words ) > 1) {
  1442. // word 1
  1443.  
  1444. $word1 = trim($set_words [0]);
  1445.  
  1446. // randomize replacing word
  1447. $rand = rand ( 1, count ( $set_words ) - 1 );
  1448. $replaceword = trim($set_words [$rand]);
  1449.  
  1450. echo '<br>replacing "'.$word1.'" by "'.$replaceword.'"' ;
  1451.  
  1452. if( in_array('OPT_REPLACE_NO_REGEX', $wp_automatic_options) ){
  1453.  
  1454. $post_title = str_replace ( $word1 , $replaceword, $post_title );
  1455. $post_content = str_replace ( $word1 , $replaceword, $post_content );
  1456.  
  1457. }else{
  1458.  
  1459. $post_title = preg_replace ( '/\b' . trim ( preg_quote( $word1,'/') ) . '\b/iu', $replaceword, $post_title );
  1460. $post_content = preg_replace ( '/\b' . trim ( preg_quote( $word1,'/') ) . '\b/iu', $replaceword, $post_content );
  1461. }
  1462.  
  1463.  
  1464. }
  1465. }
  1466. }
  1467.  
  1468.  
  1469. $abcontTxt = $camp->camp_post_content;
  1470. $abtitleTxt = $camp->camp_post_title;
  1471.  
  1472. // spin the content
  1473. if (in_array ( 'OPT_TBS', $camp_opt ) && trim ( $abcontTxt ) != '' || stristr($abcontTxt, '{') && stristr($abcontTxt, '}') && stristr($abcontTxt, '|') || stristr($abtitleTxt, '{') && stristr($abtitleTxt, '}') && stristr($abtitleTxt, '|') ) {
  1474.  
  1475. if($camp_type != 'Spintax'){
  1476.  
  1477. echo '<br>Spin the content enabled';
  1478.  
  1479. $abconts = $post_title . '(99999)' . $post_content;
  1480.  
  1481. if (in_array ( 'OPT_TBS', $camp_opt )){
  1482. $abconts =$this->spin ( $abconts );
  1483. }
  1484.  
  1485. $abconts = $this->spintax->spin ( $abconts );
  1486. $tempz = explode ( '(99999)', $abconts );
  1487.  
  1488. // Rewrite the title
  1489. if(! in_array('OPT_TBS_TTL', $camp_opt)){
  1490. echo '<br>Spinning the title';
  1491. $post_title = $tempz [0];
  1492. }
  1493.  
  1494. $post_content = $tempz [1];
  1495.  
  1496.  
  1497. //remove nospin tags
  1498. $post_title = str_replace('[nospin]', '', $post_title);
  1499. $post_title = str_replace('[/nospin]', '', $post_title);
  1500. $post_content = str_replace('[nospin]', '', $post_content);
  1501. $post_content = str_replace('[/nospin]', '', $post_content);
  1502.  
  1503. }//not spintax
  1504. }
  1505.  
  1506.  
  1507.  
  1508. //categories for post
  1509. if( stristr($camp->camp_post_category, ',') ) {
  1510. $categories = array_filter(explode(',',$camp->camp_post_category ));
  1511. }else{
  1512. $categories = array ($camp->camp_post_category);
  1513. }
  1514.  
  1515.  
  1516. //check if dummy title (notitle)
  1517. if($post_title == '(notitle)') $post_title = '';
  1518.  
  1519. // Keyword to category
  1520. if(in_array('OPT_KEYWORD_CAT', $camp_opt) && trim($camp_general['cg_keyword_cat']) != '' ){
  1521. echo '<br>Keyword to category check started...';
  1522.  
  1523. $cg_keyword_cat = $camp_general['cg_keyword_cat'];
  1524. $cg_keyword_cat_rules = array_filter( explode("\n", $cg_keyword_cat) );
  1525.  
  1526. foreach ($cg_keyword_cat_rules as $cg_keyword_cat_rule) {
  1527. if(stristr( $cg_keyword_cat_rule , '|')){
  1528.  
  1529. $cg_keyword_cat_rule = trim($cg_keyword_cat_rule);
  1530.  
  1531. $cg_keyword_cat_rule_parts = explode ('|', $cg_keyword_cat_rule) ;
  1532.  
  1533. $cg_keyword_cat_rule_keyword = $cg_keyword_cat_rule_parts[0];
  1534. $cg_keyword_cat_rule_category = $cg_keyword_cat_rule_parts[1];
  1535.  
  1536. if( preg_match('{\b' . preg_quote( $cg_keyword_cat_rule_keyword ). '\b}siu', $abcont) || (stristr($cg_keyword_cat_rule_keyword, '#') && stristr($abcont, trim($cg_keyword_cat_rule_keyword)) )){
  1537.  
  1538. echo '<br><- Key '.$cg_keyword_cat_rule_keyword . ' exists adding category:'.$cg_keyword_cat_rule_category;
  1539.  
  1540. if(is_numeric($cg_keyword_cat_rule_category)){
  1541. $categories[]=$cg_keyword_cat_rule_category;
  1542.  
  1543. }elseif( stristr($cg_keyword_cat_rule_category, ',') ){
  1544. $categories = array_merge($categories,explode(',', $cg_keyword_cat_rule_category));
  1545. }
  1546.  
  1547. }
  1548.  
  1549. }
  1550. }
  1551.  
  1552. }
  1553.  
  1554. // post status
  1555. if(in_array('OPT_DRAFT_PUBLISH', $camp_opt) && $camp->camp_post_status == 'publish'){
  1556. echo '<br>Setting post status to draft temporarily';
  1557. $postStatus = 'draft' ;
  1558.  
  1559. }else{
  1560.  
  1561. $postStatus = $camp->camp_post_status;
  1562.  
  1563. }
  1564.  
  1565. // building post
  1566. $my_post = array (
  1567. 'post_title' => strip_tags( $post_title),
  1568. 'post_content' => $post_content,
  1569. 'post_status' => $postStatus,
  1570. 'post_author' => $camp->camp_post_author,
  1571. 'post_type' => $camp->camp_post_type,
  1572. 'post_category' => $categories,
  1573.  
  1574. );
  1575.  
  1576.  
  1577. //Pending for non english
  1578.  
  1579. if(in_array('OPT_MUST_ENGLISH', $camp_opt)){
  1580. echo '<br>Checking If English or not';
  1581.  
  1582. if($this->is_english($post_title)){
  1583. echo '<-- English ';
  1584. }else{
  1585. echo '<--Guessed as Not English setting as pending';
  1586. $my_post['post_status'] = 'pending';
  1587.  
  1588. }
  1589.  
  1590. }
  1591.  
  1592. //Pending for transation fail
  1593. // skip if translation failed
  1594.  
  1595. if( in_array('OPT_TRANSLATE', $camp_opt) && in_array('OPT_TRANSLATE_FTP', $camp_opt)){
  1596.  
  1597. echo '<br>Checking if translation faild..';
  1598.  
  1599. if($this->translationSuccess == false){
  1600. echo ' Found Failed... set to pending..';
  1601. $my_post['post_status'] = 'pending';
  1602. }else{
  1603. echo ' Found succeeded ';
  1604. }
  1605.  
  1606. }
  1607.  
  1608.  
  1609. //prepare author
  1610. if($camp_type == 'Feeds' && isset($img['author']) && trim($img['author']) != '' && in_array('OPT_ORIGINAL_AUTHOR', $camp_opt) ){
  1611. echo '<br>Trying to set the post author to '.$img['author'];
  1612. $author_id = $this->get_user_id_by_display_name($img['author']);
  1613. if($author_id != false){
  1614. $my_post['post_author'] = $author_id;
  1615. }
  1616. }
  1617.  
  1618.  
  1619. kses_remove_filters ();
  1620.  
  1621. if ( $camp_type == 'Feeds' && in_array ( 'OPT_ORIGINAL_TIME', $camp_opt ) ){
  1622.  
  1623. $wpdate = get_date_from_gmt( $article['wpdate'] );
  1624. echo '<br>Setting date for the post to '.$wpdate;
  1625. $my_post['post_date'] = $wpdate ;
  1626.  
  1627. }
  1628.  
  1629. if ( $camp_type == 'Craigslist' && in_array ( 'OPT_CL_TIME', $camp_opt ) ){
  1630.  
  1631. $wpdate = get_date_from_gmt( gmdate ( 'Y-m-d H:i:s' , strtotime($img['item_date']) ) );
  1632. echo '<br>Setting date for the post to '.$wpdate ;
  1633. $my_post['post_date'] = $wpdate ;
  1634.  
  1635. }
  1636.  
  1637. if ( $camp_type == 'Reddit' && in_array ( 'OPT_RD_TIME', $camp_opt ) ){
  1638.  
  1639. $wpdate = get_date_from_gmt( gmdate ( 'Y-m-d H:i:s' , ($img['item_date']) ) );
  1640. echo '<br>Setting date for the post to '.$wpdate ;
  1641. $my_post['post_date'] = $wpdate ;
  1642.  
  1643. }
  1644.  
  1645. if ( $camp_type == 'Instagram' && in_array ( 'OPT_IT_DATE', $camp_opt ) ){
  1646. echo '<br>Setting date for the post to '. $img['item_created_date'];
  1647. $my_post['post_date']=$img['item_created_date'];
  1648. }
  1649.  
  1650. if ( ($camp_type == 'Twitter' && in_array ( 'OPT_IT_DATE', $camp_opt )) || ($camp_type == 'SoundCloud' && in_array('OPT_SC_DATE', $camp_opt)) ){
  1651.  
  1652. $item_created_at = date ( 'Y-m-d H:i:s' , strtotime( $img['item_created_at']) );
  1653. //$item_created_at = get_date_from_gmt($item_created_at);
  1654.  
  1655. echo '<br>Setting date for the post to '.$item_created_at;
  1656. $my_post['post_date']=$item_created_at;
  1657.  
  1658. }
  1659.  
  1660.  
  1661. if ( $camp_type == 'Youtube' && in_array ( 'OPT_YT_ORIGINAL_TIME', $camp_opt ) ){
  1662.  
  1663. $realDate = get_date_from_gmt( gmdate('Y-m-d H:i:s' ,$vid['vid_time'] ) );
  1664.  
  1665. echo '<br>Setting date for the post to '. $realDate;
  1666. $my_post['post_date']= $realDate ;
  1667.  
  1668. }
  1669.  
  1670. if ( $camp_type == 'DailyMotion' && in_array ( 'OPT_DM_ORIGINAL_TIME', $camp_opt ) ){
  1671.  
  1672.  
  1673. $realDate = get_date_from_gmt( gmdate('Y-m-d H:i:s' ,$img['item_published_at'] ) );
  1674.  
  1675. echo '<br>Setting date for the post to '. $realDate;
  1676. $my_post['post_date']= $realDate ;
  1677.  
  1678. }
  1679.  
  1680. if ( $camp_type == 'Vimeo' && in_array ( 'OPT_VM_ORIGINAL_TIME', $camp_opt ) ){
  1681. $realDate = $vid['vid_created_time'] ;
  1682. echo '<br>Setting date for the post to '. $realDate;
  1683. $my_post['post_date']= $realDate ;
  1684.  
  1685. }
  1686.  
  1687. if ( $camp_type == 'Facebook' && in_array ( 'OPT_ORIGINAL_FB_TIME', $camp_opt ) ){
  1688. $realDate = $img['original_date'];
  1689. echo '<br>Setting date for the post to '. $realDate;
  1690. $my_post['post_date']= $realDate ;
  1691.  
  1692. }
  1693.  
  1694. //set excerpt of amazon product post type
  1695. if($camp_type == 'Amazon' && $camp->camp_post_type == 'product' && in_array('OPT_AMAZON_EXCERPT', $camp_opt)){
  1696. echo '<br>Setting product short description';
  1697. $my_post['post_excerpt'] = $img['product_desc'];
  1698. }
  1699.  
  1700. //set excerpt of ebay product post type
  1701. if($camp_type == 'eBay' && $camp->camp_post_type == 'product' && in_array('OPT_EBAY_EXCERPT', $camp_opt)){
  1702. echo '<br>Setting product short description';
  1703. $my_post['post_excerpt'] = $img['item_desc'];
  1704. }
  1705.  
  1706.  
  1707. //remove filter kses for security
  1708. remove_filter('content_save_pre', 'wp_filter_post_kses');
  1709.  
  1710. //fixing utf8
  1711.  
  1712. // echo ' Fixing ... '.$my_post['post_content'];
  1713.  
  1714. $my_post['post_content'] = $this->fix_utf8($my_post['post_content']);
  1715. $my_post['post_title'] = $this->fix_utf8($my_post['post_title']);
  1716.  
  1717.  
  1718. //truemag instagram remove embed
  1719. if( ($camp_type == 'Instagram' ) && stristr($abcont, '[embed]') ){
  1720.  
  1721. if( (defined('PARENT_THEME') && (PARENT_THEME =='truemag' || PARENT_THEME =='newstube')) || class_exists('Cactus_video') ){
  1722.  
  1723. //extract video url
  1724. $my_post['post_content'] = preg_replace('{\[embed\](.*?)\[/embed\]}','', $my_post['post_content']);
  1725. }
  1726. }
  1727.  
  1728. // Exact match check
  1729. // validating exact
  1730. $valid = true;
  1731. if (trim ( $exact ) != '' & in_array('OPT_EXACT', $camp_opt) && in_array('OPT_EXACT_AFTER', $camp_opt)) {
  1732. $valid = false;
  1733. $exactArr = explode ( "\n", trim ( $exact ) );
  1734.  
  1735. foreach ( $exactArr as $wordexact ) {
  1736. if (trim ( $wordexact != '' )) {
  1737.  
  1738. if(in_array('OPT_EXACT_STR', $camp_opt)){
  1739.  
  1740. if( in_array('OPT_EXACT_TITLE_ONLY', $camp_opt) && stristr( ($title) , $wordexact ) ){
  1741. echo '<br> Title contains the word : ' . $wordexact ;
  1742. $valid = true;
  1743. break;
  1744.  
  1745. }elseif ( !in_array('OPT_EXACT_TITLE_ONLY', $camp_opt) && ( stristr( ($post_content) , trim ( $wordexact ) ) || stristr ( ($title) , $wordexact ) ) ) {
  1746.  
  1747. echo '<br>Content contains the word : ' . $wordexact ;
  1748. $valid = true;
  1749. break;
  1750.  
  1751. }else{
  1752. echo '<br>Exact Content does not contain the word : ' . $wordexact . ' try another ';
  1753. } // match
  1754.  
  1755. }else{
  1756.  
  1757. if( in_array('OPT_EXACT_TITLE_ONLY', $camp_opt) && preg_match ( '/\b' . $wordexact . '\b/iu', html_entity_decode($title) ) ){
  1758. echo '<br>Title contains the word : ' . $wordexact ;
  1759. $valid = true;
  1760. break;
  1761.  
  1762. }elseif ( !in_array('OPT_EXACT_TITLE_ONLY', $camp_opt) && ( preg_match ( '/\b' . trim ( $wordexact ) . '\b/iu', html_entity_decode($post_content) ) || preg_match ( '/\b' . $wordexact . '\b/iu', html_entity_decode($title) ) ) ) {
  1763.  
  1764. echo '<br>Content contains the word : ' . $wordexact ;
  1765. $valid = true;
  1766. break;
  1767.  
  1768. }else{
  1769. echo '<br>Content does not contain the word : ' . $wordexact . ' try another ';
  1770. } // match
  1771.  
  1772. }
  1773.  
  1774.  
  1775. } // trim wordexact
  1776. } // foreach exactword
  1777. } // trim exact
  1778.  
  1779. // validating execlude
  1780. if ($valid == true) {
  1781. if (trim ( $execl ) != '' && in_array('OPT_EXECLUDE', $camp_opt) && in_array('OPT_EXECLUDE_AFTER', $camp_opt) ) {
  1782.  
  1783. $execl .= $this->generalBannedWords;
  1784.  
  1785. $execlArr = explode ( "\n", trim ( $execl ) );
  1786.  
  1787. foreach ( $execlArr as $wordex ) {
  1788.  
  1789.  
  1790. if (trim ( $wordex != '' )) {
  1791. if ( preg_match ( '/\b' . trim ( $wordex ) . '\b/iu', html_entity_decode($my_post['post_content']) ) || preg_match ( '/\b' . trim ( $wordex ) . '\b/iu', (html_entity_decode($title)) ) ) {
  1792. echo '<br>Content contains the banned word :' . $wordex . ' getting another ';
  1793. $valid = false;
  1794. break;
  1795. }
  1796. } // trim wordexec
  1797. } // foreach wordex
  1798. } // trim execl
  1799. } // valid
  1800.  
  1801. // if not valid process the campaign again and exit
  1802. if ($valid == false) {
  1803.  
  1804. //blacklisting the link so we don'g teg it again and cause a loop
  1805. $this->link_execlude($camp->camp_id, $source_link);
  1806. $this->process_campaign ( $camp );
  1807. exit ();
  1808. }
  1809.  
  1810.  
  1811.  
  1812. // fix html entities
  1813.  
  1814.  
  1815. // Emoji fix
  1816.  
  1817. if(! isset( $wpdb)) global $wpdb;
  1818.  
  1819. $emoji_fields = array( 'post_title', 'post_content', 'post_excerpt' );
  1820.  
  1821. foreach ( $emoji_fields as $emoji_field ) {
  1822. if ( isset( $my_post[ $emoji_field ] ) ) {
  1823. $charset = $wpdb->get_col_charset( $wpdb->posts, $emoji_field );
  1824. if ( 'utf8' === $charset ) {
  1825. $my_post[ $emoji_field ] = wp_encode_emoji( $my_post[ $emoji_field ] );
  1826. $my_post[ $emoji_field ] = preg_replace('/[\x{10000}-\x{10FFFF}]/u', "", $my_post[ $emoji_field]);
  1827.  
  1828. }
  1829. }
  1830. }
  1831.  
  1832. // single campaign decide the decision
  1833. if($camp_type == 'Single'){
  1834.  
  1835. $previousPostID = get_post_meta( $camp->camp_id, 'wp_automatic_previous_id' ,1);
  1836. $previousHash = get_post_meta( $camp->camp_id, 'wp_automatic_previous_hash' ,1);
  1837. $currentHash = md5( $my_post['post_title'] . $my_post['post_content'] );
  1838. $cg_sn_after = $camp_general['cg_sn_after'] ;
  1839.  
  1840. if( $cg_sn_after == 'justnew' ){
  1841. // ignore all of that, a new post should be created ignoring last post
  1842.  
  1843. }else{
  1844.  
  1845. if(trim($previousPostID) == ''){
  1846. //inogre that, it is the first post ever
  1847. echo '<br>First time posting...';
  1848.  
  1849. }else{
  1850. //previous post exists
  1851.  
  1852. if($cg_sn_after == 'delete'){
  1853. //always delete old post, lets delete it
  1854. echo '<br>Deleting previous post with ID:'.$previousPostID;
  1855. wp_delete_post($previousPostID,true);
  1856.  
  1857. }else{
  1858. // we have a previous post, let's see if new post is a differnet or the same
  1859.  
  1860. if($previousHash == $currentHash){
  1861. // nothing changed, it is the same post
  1862. echo '<br>Previous post contains the latest content as nothing changed...';
  1863. exit;
  1864. }else{
  1865. // post changed
  1866. if($cg_sn_after == 'deletechange'){
  1867.  
  1868. //delete and create new one
  1869. echo '<br>Content changed, Deleting previous post with ID:'.$previousPostID;
  1870. wp_delete_post($previousPostID,true);
  1871.  
  1872. }elseif( $cg_sn_after == 'new' ){
  1873.  
  1874. // don't delete anything, just create a new post
  1875. echo '<br>Content changed, keeping old post and create a new one';
  1876.  
  1877. }elseif($cg_sn_after == 'update' ){
  1878.  
  1879. // update an existing post
  1880. echo '<br>Content changed, updating post with ID:'.$previousPostID;
  1881. $my_post['ID'] = $previousPostID;
  1882.  
  1883. }
  1884.  
  1885. }
  1886.  
  1887. }
  1888.  
  1889.  
  1890.  
  1891. }
  1892.  
  1893. }
  1894.  
  1895. }
  1896.  
  1897. // Insert the post into the database
  1898. if($my_post['post_type'] == 'topic' && function_exists('bbp_insert_topic')){
  1899.  
  1900. $cg_bb_fid = $camp_general['cg_bb_fid'];
  1901.  
  1902. if(is_numeric($cg_bb_fid)) {
  1903. $my_post['post_parent'] = $cg_bb_fid;
  1904. }
  1905.  
  1906. $topicMeta= array();
  1907. $topicMeta['forum_id'] = $cg_bb_fid;
  1908.  
  1909. $id = bbp_insert_topic( $my_post ,$topicMeta );
  1910.  
  1911. }else{
  1912.  
  1913. $id = wp_insert_post( $my_post );
  1914.  
  1915. }
  1916.  
  1917.  
  1918. if($id == 0){
  1919. echo '<br>Error:Post Insertion failure';
  1920. //print_r($my_post);
  1921. }
  1922.  
  1923. //wpml integration
  1924. if(in_array('OPT_WPML', $camp_opt) && function_exists('icl_object_id') ){
  1925. include_once( WP_PLUGIN_DIR . '/sitepress-multilingual-cms/inc/wpml-api.php' );
  1926. $language_code = $camp_general['cg_wpml_lang']; // change the language code
  1927. echo '<br>Setting WPML language to: '.$language_code;
  1928. wpml_update_translatable_content('post_'.$camp->camp_post_type, $id, trim($language_code) );
  1929. }
  1930.  
  1931.  
  1932.  
  1933. //setting categories for custom post types
  1934. if( true | $camp->camp_post_type != 'post'){
  1935.  
  1936. $customPostTaxonomies = get_object_taxonomies($camp->camp_post_type);
  1937.  
  1938. if(count($customPostTaxonomies) > 0)
  1939. {
  1940.  
  1941. foreach($customPostTaxonomies as $tax)
  1942. {
  1943.  
  1944. if(is_taxonomy_hierarchical($tax)){
  1945. echo '<br>Setting taxonomy '.$tax.' to '.$camp->camp_post_category;
  1946. @wp_set_post_terms($id, $categories , $tax,true);
  1947. }
  1948. }
  1949. }
  1950.  
  1951.  
  1952.  
  1953. }else{
  1954.  
  1955. }
  1956.  
  1957. //feeds category
  1958. if($camp_type == 'Feeds' && trim($img['cats'] != '')){
  1959.  
  1960. //Removed @v3.24.0
  1961. //add_post_meta ( $id, 'original_cats', $img['cats'] );
  1962.  
  1963. if(in_array('OPT_ORIGINAL_CATS', $camp_opt)){
  1964.  
  1965. echo '<br>Setting Categories to :'.$img['cats'];
  1966.  
  1967. $cats= array_filter(explode(',', $img['cats']));
  1968.  
  1969. if( $camp->camp_post_type == 'post' ){
  1970. $taxonomy = 'category';
  1971. }else{
  1972. $taxonomy = $camp_general['cg_camp_tax'] ;
  1973. }
  1974.  
  1975. $new_cats = array();
  1976.  
  1977. //convert cats to ids
  1978. foreach($cats as $cat_name){
  1979.  
  1980. $cat = get_term_by('name', $cat_name , $taxonomy);
  1981.  
  1982. //check existence
  1983. if($cat == false){
  1984.  
  1985.  
  1986. //cateogry not exist create it
  1987. $cat = wp_insert_term($cat_name, $taxonomy);
  1988.  
  1989. if( ! is_wp_error($cat) ){
  1990. //category id of inserted cat
  1991. $cat_id = $cat['term_id'] ;
  1992. $new_cats[] = $cat_id;
  1993. }
  1994.  
  1995.  
  1996. }else{
  1997.  
  1998. //category already exists let's get it's id
  1999. $cat_id = $cat->term_id ;
  2000. $new_cats[] = $cat_id;
  2001. }
  2002. }
  2003.  
  2004. //insert cats
  2005. if(count($new_cats) > 0)
  2006. wp_set_post_terms($id,$new_cats,$taxonomy ,true);
  2007.  
  2008. //delete uncategorized
  2009. if($taxonomy == 'category'){
  2010. //get uncategorized slug by term id
  2011. $uncatObject = get_term(1);
  2012. wp_remove_object_terms( $id, $uncatObject->slug, $taxonomy );
  2013. }
  2014.  
  2015.  
  2016. }
  2017.  
  2018. }
  2019.  
  2020. // Feeds part to field extraction set
  2021. if($camp_type == 'Feeds'){
  2022.  
  2023. $customFieldsArr = $img['custom_fields'];
  2024.  
  2025. if( is_array($customFieldsArr) && count($customFieldsArr) != 0 ){
  2026.  
  2027. foreach ($customFieldsArr as $customFieldSet){
  2028.  
  2029. if($customFieldSet[0] == 'excerpt'){
  2030. $my_post = array(
  2031. 'ID' => $id,
  2032. 'post_excerpt' => $customFieldSet[1]
  2033. );
  2034.  
  2035. wp_update_post( $my_post );
  2036.  
  2037. }elseif( $customFieldSet[0] == 'tags'){
  2038.  
  2039. if(in_array('OPT_TAXONOMY_TAG', $camp_opt)){
  2040. wp_set_post_terms( $id, $customFieldSet[1], trim($camp_general['cg_tag_tax']), true );
  2041. }else{
  2042. wp_set_post_tags ( $id, $customFieldSet[1], true );
  2043. }
  2044.  
  2045. }else{
  2046. add_post_meta ( $id, $customFieldSet[0], $customFieldSet[1] );
  2047. }
  2048. }//foreach field
  2049.  
  2050. }//if array
  2051.  
  2052. }//if feed
  2053.  
  2054. $post_id = $id;
  2055.  
  2056.  
  2057. add_post_meta ( $id, 'original_title', $title );
  2058. if(isset($source_link) ) add_post_meta ( $id, 'original_link', $source_link );
  2059. add_post_meta($id , 'wp_automatic_camp',$camp->camp_id);
  2060.  
  2061. // Record link if posted before
  2062. if (in_array('OPT_LINK_ONCE', $camp_opt)){
  2063.  
  2064. $query="insert into {$this->wp_prefix}automatic_links( link_url ,link_keyword ) values ('".md5($source_link)."','".$camp->camp_id."')";
  2065. $this->db->query($query);
  2066.  
  2067. }
  2068.  
  2069. //if link to source set flag
  2070. if(in_array('OPT_LINK_SOURSE', $camp_opt)){
  2071. add_post_meta ( $id, '_link_to_source', 'yes' );
  2072. }
  2073.  
  2074. //if link canonical
  2075. if(in_array('OPT_LINK_CANONICAL', $camp_opt)){
  2076. add_post_meta ( $id, 'canonical_url', $source_link );
  2077. }
  2078.  
  2079. // add featured image
  2080. if (in_array ( 'OPT_REPLACE', $camp_opt )) {
  2081. foreach ( $keywords as $keyword ) {
  2082.  
  2083. $keyword = trim($keyword);
  2084.  
  2085. if (trim ( $keyword != '' )) {
  2086. $post_content = str_replace ( $keyword, '<a href="' . $camp->camp_replace_link . '">' . $keyword . '</a>', $post_content );
  2087. }
  2088. }
  2089. }
  2090.  
  2091. // Featured image
  2092. if (in_array ( 'OPT_THUMB', $camp_opt )) {
  2093.  
  2094. $srcs = array(); //ini
  2095. $srcs_alts = array();
  2096.  
  2097. //if force og_img
  2098. if(in_array('OPT_FEEDS_OG_IMG', $camp_opt) && isset($img['og_img']) && trim($img['og_img']) != '' ){
  2099.  
  2100. if(in_array('OPT_FEEDS_OG_IMG_REVERSE', $camp_opt) && stristr($post_content, '<img')){
  2101. echo '<br>og:image found but will be skipped';
  2102. //here the image contains a first image and og:image should skipped
  2103.  
  2104. //set an og:image variable so it get appended to the end of found images. If width check is active and all images on post are not wide enough
  2105. $og_image = $img['og_img'];
  2106.  
  2107. }else{
  2108. $srcs = array($img['og_img']) ;
  2109. $srcs_alts[] = $img['og_alt'];
  2110.  
  2111. }
  2112. }
  2113.  
  2114. //if youtube set thumbnail to video thum
  2115. if($camp_type == 'Youtube' || $camp_type == 'Vimeo' ){
  2116. //set youtube/vimeo image as featured image
  2117.  
  2118. //check if maxres exists
  2119. if( stristr( $vid['vid_img'] , 'hqdefault' ) ){
  2120. $maxres = str_replace('hqdefault', 'maxresdefault', $vid['vid_img']) ;
  2121.  
  2122. $maxhead = wp_remote_head($maxres);
  2123.  
  2124. if(! is_wp_error($maxhead) && $maxhead['response']['code'] == 200 ){
  2125. $vid['vid_img'] = $maxres;
  2126. }
  2127.  
  2128. }
  2129.  
  2130.  
  2131. $srcs=array($vid['vid_img']);
  2132.  
  2133. echo '<br>Vid Thumb:'.$vid['vid_img'];
  2134.  
  2135. }elseif( $camp_type == 'DailyMotion' ){
  2136. $srcs=array($img['item_image']);
  2137.  
  2138. }elseif($camp_type == 'SoundCloud'){
  2139.  
  2140. if(trim($img['item_thumbnail']) != ''){
  2141. $srcs = array($img['item_thumbnail']);
  2142. }elseif(trim($img['item_user_thumbnail']) != ''){
  2143. //$srcs = array($img['item_user_thumbnail']);
  2144. }
  2145.  
  2146. }elseif($camp_type == 'Twitter' && in_array('OPT_TW_CARDS', $camp_opt) && isset($img['item_image']) ){
  2147.  
  2148. $srcs = array($img['item_image']);
  2149.  
  2150. }elseif($camp_type == 'Amazon'){
  2151.  
  2152. $srcs = array($img['product_img']);
  2153.  
  2154. }elseif(isset($srcs) && count($srcs) > 0 ){
  2155.  
  2156.  
  2157. }else{
  2158.  
  2159. // extract first image
  2160. preg_match_all ( '/<img [^>]*src[\s]*=[\s]*["|\']([^"|\']+).*?>/i', stripslashes ( $post_content ), $matches );
  2161. $srcs = $matches [1];
  2162. $srcs_html = $matches[0];
  2163.  
  2164.  
  2165. foreach ($srcs_html as $src_html){
  2166.  
  2167. preg_match('/alt[\s]*=[\s]*["|\'](.*?)["|\']/i', $src_html,$alt_matches) ;
  2168. $srcs_alts[] = $alt_matches[1];
  2169.  
  2170. }
  2171.  
  2172.  
  2173.  
  2174. if(isset($og_image)){
  2175. $og_arr = array();
  2176. $og_arr[] = $og_image;
  2177. $srcs = array_merge($srcs,$og_arr);
  2178.  
  2179. }
  2180.  
  2181. }
  2182.  
  2183.  
  2184. //may be a wp_automatic_Readability missed the image on the content get it from summary ?
  2185. if( count($srcs) == 0 && $camp_type == 'Feeds' && in_array('OPT_FULL_FEED', $camp_opt) ){
  2186. echo '<br>Featured image is missing at full content searching for it in feed instead';
  2187. preg_match_all ( '/<img [^>]*src=["|\']([^"|\']+).*?/i', stripslashes ( $article['original_content'] ), $matches );
  2188. $srcs = $matches [1];
  2189. $srcs_html = $matches[0];
  2190.  
  2191. foreach ($srcs_html as $src_html){
  2192.  
  2193. preg_match('/alt[\s]*=[\s]*["|\'](.*?)["|\']/i', $src_html,$alt_matches) ;
  2194. $srcs_alts[] = $alt_matches[1];
  2195.  
  2196. }
  2197.  
  2198. if(count($srcs) == 0){
  2199. echo '<br>No image found at the feed summary';
  2200.  
  2201. if( trim($img['og_img']) != '' ){
  2202. echo '<br>Graph image thumb found';
  2203. $srcs = array($img['og_img']);
  2204. }
  2205.  
  2206. }
  2207.  
  2208. }
  2209.  
  2210.  
  2211. //No featured image found let's check if random image list found
  2212. if ( count($srcs) == 0 && in_array ( 'OPT_THUMB_LIST', $camp_opt )) {
  2213. echo '<br>Trying to set random image as featured image';
  2214.  
  2215. $cg_thmb_list=$camp_general['cg_thmb_list'];
  2216.  
  2217. $cg_imgs = explode("\n", $cg_thmb_list);
  2218. $cg_imgs = array_filter($cg_imgs);
  2219. $cg_rand_img = trim( $cg_imgs [rand(0,count($cg_imgs)-1)]);
  2220.  
  2221. //validate image
  2222. if(trim( $cg_rand_img)!='' ){
  2223. $srcs=array($cg_rand_img);
  2224. }
  2225.  
  2226. }elseif(in_array ( 'OPT_THUMB_LIST', $camp_opt )){
  2227.  
  2228. $cg_thmb_list=$camp_general['cg_thmb_list'];
  2229.  
  2230. $cg_imgs = explode("\n", $cg_thmb_list);
  2231. $cg_imgs = array_filter($cg_imgs);
  2232. $cg_rand_img = trim( $cg_imgs [rand(0,count($cg_imgs)-1)]);
  2233.  
  2234. //validate image
  2235. if( trim($cg_rand_img)!= '' ){
  2236. $srcs= array_merge($srcs, array($cg_rand_img) ) ;
  2237. }
  2238.  
  2239. }
  2240.  
  2241. //if foce using thumb list
  2242. if( in_array('OPT_THUMB_LIST_FORCE', $camp_opt) && in_array ( 'OPT_THUMB_LIST', $camp_opt ) ){
  2243.  
  2244. echo '<br>Force using image from set list';
  2245.  
  2246. $cg_thmb_list=$camp_general['cg_thmb_list'];
  2247.  
  2248. $cg_imgs = explode("\n", $cg_thmb_list);
  2249. $cg_imgs = array_filter($cg_imgs);
  2250.  
  2251.  
  2252.  
  2253. $cg_rand_img = trim( $cg_imgs [rand(0,count($cg_imgs)-1)]);
  2254.  
  2255.  
  2256. //validate image
  2257. if(trim( $cg_rand_img)!='' ){
  2258. $srcs=array($cg_rand_img);
  2259. }
  2260.  
  2261. }
  2262.  
  2263. //check srcs size to skip small images
  2264. if(count($srcs) >0 && in_array('OPT_THUMB_WIDTH_CHECK', $camp_opt)){
  2265.  
  2266. $cg_minimum_width = 0;
  2267. $cg_minimum_width = $camp_general['cg_minimum_width'];
  2268.  
  2269. if(! (is_numeric( $cg_minimum_width ) && $cg_minimum_width > 0 ) ){
  2270. $cg_minimum_width = 100;
  2271. }
  2272.  
  2273. $n=0;
  2274. $upload_dir = wp_upload_dir ();
  2275.  
  2276. foreach($srcs as $current_img){
  2277.  
  2278. echo '<br>Candidate featured image: '.$current_img ;
  2279.  
  2280. if(stristr($current_img, 'data:image') && stristr($current_img, 'base64,')){
  2281.  
  2282. $ex = explode('base64,', $current_img);
  2283.  
  2284. $image_data = base64_decode($ex[1]);
  2285.  
  2286.  
  2287. }else{
  2288.  
  2289. //curl get
  2290. $x='error';
  2291. curl_setopt($this->ch, CURLOPT_HTTPGET, 1);
  2292. curl_setopt($this->ch, CURLOPT_URL, trim($current_img));
  2293. $image_data=curl_exec($this->ch);
  2294. $x=curl_error($this->ch);
  2295.  
  2296. }
  2297.  
  2298.  
  2299.  
  2300. if(trim($image_data) != '' ){
  2301.  
  2302. //let's save the file
  2303. if (wp_mkdir_p ( $upload_dir ['path'] ))
  2304. $file = $upload_dir ['path'] . '/' . 'temp_wp_automatic';
  2305. else
  2306. $file = $upload_dir ['basedir'] . '/' . 'temp_wp_automatic';
  2307.  
  2308. file_put_contents ( $file, $image_data );
  2309.  
  2310. $size = getimagesize($file);
  2311.  
  2312. if($size != false){
  2313.  
  2314. if($size[0] >$cg_minimum_width ){
  2315. echo '<-- Valid width is '.$size[0] . ' larger than '.$cg_minimum_width ;
  2316. break;
  2317. }else{
  2318. echo '<-- width is too low '.$size[0];
  2319. unset($srcs[$n]);
  2320. if(isset($srcs_alts[$n])) unset($srcs_alts[$n]) ;
  2321. }
  2322.  
  2323. }else{
  2324. echo '<--size verification failed';
  2325. unset($srcs[$n]);
  2326. if(isset($srcs_alts[$n])) unset($srcs_alts[$n]) ;
  2327. }
  2328.  
  2329.  
  2330. }else{
  2331. echo '<--no content ';
  2332. unset($srcs[$n]);
  2333. if(isset($srcs_alts[$n])) unset($srcs_alts[$n]) ;
  2334. }
  2335.  
  2336. $n++;
  2337. }
  2338.  
  2339. }
  2340.  
  2341.  
  2342. // Setting the thumb
  2343. if (count ( $srcs ) > 0) {
  2344.  
  2345. $src = reset($srcs);
  2346.  
  2347. $image_url = $src;
  2348.  
  2349. $this->log ( 'Featured image', '<a href="' . $image_url . '">' . $image_url . '</a>' );
  2350. echo '<br>Featured image src: '.$image_url;
  2351.  
  2352. // set thumbnail
  2353. $upload_dir = wp_upload_dir ();
  2354.  
  2355. //img host
  2356. $imghost = parse_url ( $image_url, PHP_URL_HOST );
  2357.  
  2358. if(stristr($imghost, 'http://')){
  2359. $imgrefer=$imghost;
  2360. }else{
  2361. $imgrefer = 'http://'.$imghost;
  2362. }
  2363.  
  2364. //empty referal
  2365. if( ! in_array('OPT_CACHE_REFER_NULL', $camp_opt) ){
  2366. curl_setopt ( $this->ch, CURLOPT_REFERER, $imgrefer );
  2367. }else{
  2368. curl_setopt ( $this->ch, CURLOPT_REFERER, '' );
  2369. }
  2370.  
  2371.  
  2372. if( stristr($image_url, 'base64,') ){
  2373.  
  2374. $filename = time('now');
  2375.  
  2376.  
  2377. }else{
  2378.  
  2379. //decode html entitiies
  2380. $image_url = html_entity_decode($image_url);
  2381.  
  2382. if(stristr($image_url, '%') ) {
  2383. $image_url = urldecode($image_url);
  2384. }
  2385.  
  2386. //file name to store
  2387. $filename = basename ( $image_url );
  2388.  
  2389. //youtube hqdefault.jpg may exists with different data, change the name
  2390. if(stristr($filename, 'default.jpg') ) {
  2391. $filename = time('now') . '_' .$filename;
  2392. }
  2393.  
  2394. if(stristr($image_url ,' ')){
  2395. $image_url = str_replace(' ', '%20', $image_url);
  2396. }
  2397.  
  2398. }
  2399.  
  2400. // Clean thumb
  2401. if(in_array('OPT_THUMB_CLEAN' , $camp_opt )){
  2402.  
  2403. $clean_name = '';
  2404. $clean_name = sanitize_title($post_title);
  2405.  
  2406. if(trim($clean_name) != ""){
  2407.  
  2408. //get the image extension \.\w{3}
  2409. $ext = pathinfo($filename, PATHINFO_EXTENSION);
  2410.  
  2411. if(stristr($ext, '?')){
  2412. $ext_parts = explode('?',$ext);
  2413. $ext = $ext_parts[0];
  2414. }
  2415.  
  2416. //clean parameters after filename
  2417. $filename = trim($clean_name);
  2418.  
  2419. if( trim($ext) !='' ){
  2420. $filename = $filename .'.'. $ext;
  2421. }
  2422.  
  2423. }
  2424.  
  2425. }
  2426.  
  2427.  
  2428.  
  2429. if(!in_array('OPT_THUM_NELO', $camp_opt) || stristr($image_url, 'base64,')){
  2430.  
  2431. if( stristr($image_url, 'base64,') ){
  2432. $ex = explode('base64,', $current_img);
  2433. $image_data = base64_decode($ex[1]);
  2434.  
  2435. //set fileName extention .png, .jpg etc
  2436. preg_match('{data:image/(.*?);}', $image_url ,$ex_matches);
  2437. $image_ext = $ex_matches[1];
  2438.  
  2439. if(trim($image_ext) != ''){
  2440. $filename = $filename .'.'.$image_ext;
  2441.  
  2442. echo '<br>Fname:'.$filename;
  2443.  
  2444.  
  2445. }
  2446.  
  2447. }else{
  2448.  
  2449.  
  2450. //get image content
  2451. $x='error';
  2452. curl_setopt($this->ch, CURLOPT_HTTPGET, 1);
  2453. curl_setopt($this->ch, CURLOPT_URL, trim( html_entity_decode($image_url) ) );
  2454. $image_data=$this->curl_exec_follow($this->ch);
  2455. $contentType = curl_getinfo($this->ch, CURLINFO_CONTENT_TYPE);
  2456. echo '<br>Content type:'.$contentType;
  2457. $x=curl_error($this->ch);
  2458.  
  2459.  
  2460. }
  2461.  
  2462.  
  2463.  
  2464. if(trim($image_data) != '' && stristr($contentType , 'image')){
  2465.  
  2466. //check if already saved
  2467.  
  2468. $image_data_md5 = md5($image_data);
  2469.  
  2470. $is_cached = $this->is_cached($image_url , $image_data_md5);
  2471. if( $is_cached != false ){
  2472. echo '<--already cached' ;
  2473. $file = $this->cached_file_path;
  2474. $guid = $is_cached;
  2475. }else{
  2476.  
  2477.  
  2478. if (stristr ( $filename, '?' )) {
  2479. $farr = explode ( '?', $filename );
  2480. $filename = $farr [0];
  2481. }
  2482.  
  2483. //pagepeeker fix
  2484. if(stristr($image_url, 'pagepeeker') && ! in_array('OPT_THUMB_CLEAN' , $camp_opt )){
  2485. $filename = md5($filename).'.jpg';
  2486. }
  2487.  
  2488. if (wp_mkdir_p ( $upload_dir ['path'] ))
  2489. $file = $upload_dir ['path'] . '/' . $filename;
  2490. else
  2491. $file = $upload_dir ['basedir'] . '/' . $filename;
  2492.  
  2493. // check if same image name already exists
  2494. if (file_exists ( $file )) {
  2495.  
  2496. //get the current saved one to check if identical
  2497. $already_saved_image_link=$upload_dir ['url'] . '/' . $filename;
  2498.  
  2499. //curl get
  2500. $x='error';
  2501. $url=$already_saved_image_link;
  2502. curl_setopt($this->ch, CURLOPT_HTTPGET, 1);
  2503. curl_setopt($this->ch, CURLOPT_URL, trim($url));
  2504.  
  2505. $exec=curl_exec($this->ch);
  2506.  
  2507. if(trim($exec) == trim($image_data)){
  2508. $idential = true;
  2509. echo '<br>Featured image already exists with same path.. using it';
  2510. }else{
  2511. echo '<br>Featured image exists with same path but not identical.. saving ';
  2512.  
  2513. $filename = time ( 'now' ) . '_' . $filename;
  2514.  
  2515. }
  2516.  
  2517. }
  2518.  
  2519.  
  2520. //saving image
  2521. if(! isset($idential )){
  2522. if (wp_mkdir_p ( $upload_dir ['path'] ))
  2523. $file = $upload_dir ['path'] . '/' . $filename;
  2524. else
  2525. $file = $upload_dir ['basedir'] . '/' . $filename;
  2526.  
  2527. $f=file_put_contents ( $file, $image_data );
  2528.  
  2529.  
  2530.  
  2531. }
  2532.  
  2533. $guid = $upload_dir['url'] . '/' . basename( $filename );
  2534.  
  2535. $this->img_cached($image_url, $guid,$image_data_md5,$file);
  2536.  
  2537. }//not cached
  2538.  
  2539. //atttatchment check if exists or not
  2540. global $wpdb;
  2541.  
  2542.  
  2543. $query = "select * from $wpdb->posts where guid = '$guid'";
  2544. $already_saved_attachment = $wpdb->get_row($query);
  2545.  
  2546. if(isset($already_saved_attachment->ID)){
  2547.  
  2548. $attach_id = $already_saved_attachment->ID;
  2549.  
  2550. }else{
  2551.  
  2552. $wp_filetype = wp_check_filetype ( $filename, null );
  2553.  
  2554. if($wp_filetype['type'] == false){
  2555. $wp_filetype['type'] = 'image/jpeg';
  2556. }
  2557.  
  2558. //Title handling
  2559. $imgTitle = sanitize_file_name ( $filename );
  2560. if(in_array('OPT_THUMB_ALT',$camp_opt)){
  2561. $imgTitle = $title;
  2562. }
  2563.  
  2564. $attachment = array (
  2565. 'guid' => $guid,
  2566. 'post_mime_type' => $wp_filetype ['type'],
  2567. 'post_title' => $imgTitle,
  2568. 'post_content' => '',
  2569. 'post_status' => 'inherit'
  2570. );
  2571.  
  2572. $attach_id = wp_insert_attachment ( $attachment, $file, $post_id );
  2573.  
  2574. require_once (ABSPATH . 'wp-admin/includes/image.php');
  2575. $attach_data = wp_generate_attachment_metadata ( $attach_id, $file );
  2576. wp_update_attachment_metadata ( $attach_id, $attach_data );
  2577.  
  2578. //alt text
  2579. if(in_array('OPT_THUMB_ALT2', $camp_opt)){
  2580. $img_alt= reset($srcs_alts);
  2581.  
  2582. if(trim($img_alt) != ''){
  2583. update_post_meta($attach_id, '_wp_attachment_image_alt', $img_alt);
  2584. }
  2585.  
  2586. if(in_array('OPT_THUMB_ALT3', $camp_opt)){
  2587.  
  2588. if(trim($img_alt) == ''){
  2589. update_post_meta($attach_id, '_wp_attachment_image_alt', $title);
  2590. }
  2591.  
  2592. }
  2593.  
  2594.  
  2595. }
  2596.  
  2597. }
  2598.  
  2599. set_post_thumbnail ( $post_id, $attach_id );
  2600. echo ' <-- thumbnail set successfully';
  2601.  
  2602. //if hide first image set the custom field
  2603. if(in_array('OPT_THUMB_STRIP', $camp_opt)){
  2604.  
  2605. if(in_array('OPT_THUMB_STRIP_FULL', $camp_opt)){
  2606. echo '<br>Deleting first image from the content...';
  2607.  
  2608. $new_post = get_post($id);
  2609. $new_content = preg_replace ( '/<img [^>]*src=["|\'][^"|\']+.*?>/i', '' ,$new_post->post_content ,1 );
  2610.  
  2611. $my_post = array(
  2612. 'ID' => $id,
  2613. 'post_content' => $new_content,
  2614. );
  2615.  
  2616. // Update the post into the database
  2617. wp_update_post( $my_post );
  2618.  
  2619. }else{
  2620. update_post_meta ( $post_id, 'wp_automatic_remove_first_image', 'yes' );
  2621. }
  2622. }
  2623.  
  2624. }else{
  2625. echo ' <-- can not get image content '.$x;
  2626. }
  2627.  
  2628. }else{//nelo
  2629. //setting custom field for nelo image
  2630. echo '<br>Setting the featured image custom field for nelio plugin';
  2631. update_post_meta($id, '_nelioefi_url', $image_url);
  2632.  
  2633. //if hide first image set the custom field
  2634. if(in_array('OPT_THUMB_STRIP', $camp_opt)){
  2635.  
  2636. if(in_array('OPT_THUMB_STRIP_FULL', $camp_opt)){
  2637. echo '<br>Deleting first image from the content...';
  2638.  
  2639. $new_post = get_post($id);
  2640. $new_content = preg_replace ( '/<img [^>]*src=["|\'][^"|\']+.*?>/i', '' ,$new_post->post_content ,1 );
  2641.  
  2642.  
  2643. $my_post = array(
  2644. 'ID' => $id,
  2645. 'post_content' => $new_content,
  2646. );
  2647.  
  2648. // Update the post into the database
  2649.  
  2650.  
  2651. wp_update_post( $my_post );
  2652.  
  2653. }else{
  2654. update_post_meta ( $post_id, 'wp_automatic_remove_first_image', 'yes' );
  2655. }
  2656. }
  2657.  
  2658. }
  2659.  
  2660.  
  2661. } else {
  2662.  
  2663. //currently no images in the content
  2664. $this->log ( 'Featured image', 'No images found to set as featured' );
  2665.  
  2666. }
  2667. } // thumbnails
  2668.  
  2669. // tags
  2670. if (in_array ( 'OPT_TAG', $camp_opt )) {
  2671. if(in_array('OPT_TAXONOMY_TAG', $camp_opt)){
  2672. wp_set_post_terms( $id, $keywords , trim($camp_general['cg_tag_tax']), true );
  2673. }else{
  2674. wp_set_post_tags ( $id, $keywords, true );
  2675. }
  2676. }
  2677.  
  2678. //youtube tags and comments
  2679. if($camp_type == 'Youtube' ){
  2680.  
  2681. //tags
  2682. if(in_array('OPT_YT_TAG', $camp_opt)){
  2683. if(trim($this->used_tags) != ''){
  2684.  
  2685. if(in_array('OPT_TAXONOMY_TAG', $camp_opt)){
  2686. wp_set_post_terms( $id, $this->used_tags , trim($camp_general['cg_tag_tax']), true );
  2687. }else{
  2688. wp_set_post_tags ( $id, $this->used_tags, true );
  2689. }
  2690.  
  2691. }
  2692. }
  2693.  
  2694. //comments
  2695. if(in_array('OPT_YT_COMMENT', $camp_opt) ){
  2696. echo '<br>Trying to post comments';
  2697.  
  2698. //get id
  2699. $temp=explode('v=', $this->used_link);
  2700. $vid_id=$temp[1] ;
  2701.  
  2702. $wp_automatic_yt_tocken=trim(get_option('wp_automatic_yt_tocken',''));
  2703.  
  2704. $maxResults = rand(20,50);
  2705.  
  2706. $comments_link="https://www.googleapis.com/youtube/v3/commentThreads?maxResults=$maxResults&part=snippet&videoId=".$vid_id."&key=$wp_automatic_yt_tocken";
  2707.  
  2708. echo '<br>Comments yt url:'.$comments_link;
  2709.  
  2710. //curl get
  2711. $x='error';
  2712. $url=$comments_link;
  2713. curl_setopt($this->ch, CURLOPT_HTTPGET, 1);
  2714. curl_setopt($this->ch, CURLOPT_URL, trim($url));
  2715. $exec=curl_exec($this->ch);
  2716.  
  2717.  
  2718. $x=curl_error($this->ch);
  2719.  
  2720. if(trim($x) != '') echo '<br>'.$x;
  2721.  
  2722. if(trim($exec) !=''){
  2723.  
  2724. if( stristr($exec, 'items')){
  2725. $comments_array=json_decode($exec);
  2726.  
  2727. $entry=$comments_array->items ;
  2728.  
  2729. if(count($entry) == 0){
  2730. echo '<br>No comments found';
  2731. }else{
  2732. echo '<br>Found '.count($entry). ' comment to post';
  2733.  
  2734. foreach($entry as $comment ){
  2735.  
  2736. $comment = $comment->snippet->topLevelComment->snippet;
  2737.  
  2738. $commentText= $comment->textDisplay;
  2739. $commentAuthor= $comment->authorDisplayName;
  2740.  
  2741.  
  2742. $commentUri='';
  2743. if(! in_array('OPT_NO_COMMENT_LINK', $camp_opt))
  2744. $commentUri= $comment->authorChannelUrl;
  2745.  
  2746. if(in_array('OPT_YT_ORIGINAL_TIME', $camp_opt)){
  2747.  
  2748. $time = $comment->publishedAt;
  2749. $time = get_date_from_gmt( gmdate('Y-m-d H:i:s' , strtotime( $time ) ) );
  2750.  
  2751.  
  2752. }else{
  2753.  
  2754. $time = current_time('mysql');
  2755.  
  2756. }
  2757.  
  2758.  
  2759.  
  2760. if(trim($commentText) != '' ){
  2761. $data = array(
  2762. 'comment_post_ID' => $id,
  2763. 'comment_author' => $commentAuthor,
  2764. 'comment_author_email' => '',
  2765. 'comment_author_url' => $commentUri,
  2766. 'comment_content' => $commentText,
  2767. 'comment_type' => '',
  2768. 'comment_parent' => 0,
  2769.  
  2770. 'comment_author_IP' => '127.0.0.1',
  2771. 'comment_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 (.NET CLR 3.5.30729)',
  2772. 'comment_date' => $time,
  2773. 'comment_approved' => 1,
  2774. );
  2775.  
  2776. wp_insert_comment($data);
  2777. }
  2778.  
  2779. }
  2780.  
  2781. }
  2782.  
  2783. }else{
  2784. echo '<br>could not find comments';
  2785. }
  2786.  
  2787. }else{
  2788. echo '<br>No valid comments feed';
  2789. }
  2790.  
  2791. }
  2792.  
  2793. }
  2794.  
  2795. // After single scraper
  2796. if($camp_type == 'Single'){
  2797.  
  2798. //update last post
  2799. update_post_meta( $camp->camp_id, 'wp_automatic_previous_id' ,$id);
  2800. update_post_meta( $camp->camp_id, 'wp_automatic_previous_hash' ,$currentHash);
  2801.  
  2802.  
  2803. }
  2804.  
  2805. // AFTER POST SPECIFIC DAILYMOTION
  2806. if( $camp_type == 'DailyMotion'){
  2807. //tags
  2808. if(in_array('OPT_DM_TAG', $camp_opt)){
  2809. if(trim($this->used_tags) != ''){
  2810.  
  2811. if(in_array('OPT_TAXONOMY_TAG', $camp_opt)){
  2812. wp_set_post_terms( $id, $this->used_tags , trim($camp_general['cg_tag_tax']), true );
  2813. }else{
  2814. wp_set_post_tags ( $id, $this->used_tags, true );
  2815. }
  2816.  
  2817. }
  2818. }
  2819. }
  2820.  
  2821. // AFTER POST SPECIFIC
  2822. if ($camp_type == 'Flicker') {
  2823. if (in_array ( 'OPT_FL_TAG', $camp_opt )) {
  2824.  
  2825. if(in_array('OPT_TAXONOMY_TAG', $camp_opt)){
  2826.  
  2827. wp_set_post_terms( $id, $img ['img_tags'] , trim($camp_general['cg_tag_tax']), true );
  2828.  
  2829. }else{
  2830. wp_set_post_tags ( $id, $img ['img_tags'], true );
  2831. }
  2832.  
  2833.  
  2834. }
  2835. }
  2836.  
  2837. // AFTER POST SPECIFIC SoundCloud
  2838. if ($camp_type == 'SoundCloud') {
  2839.  
  2840. //tags
  2841. if (in_array ( 'OPT_SC_TAG', $camp_opt )) {
  2842.  
  2843. $item_tags = $img['item_tags'];
  2844.  
  2845. //extract tags with multiple words
  2846. preg_match_all('{".*?"}', $item_tags, $multiple_tags_matches);
  2847.  
  2848. $multiple_tags_matches = $multiple_tags_matches[0];
  2849.  
  2850. $single_item_tags = $item_tags;
  2851.  
  2852.  
  2853. foreach ($multiple_tags_matches as $multiple_tag){
  2854. $single_item_tags = str_replace($multiple_tag, '', $single_item_tags);
  2855. $single_item_tags = str_replace(' ', ' ', $single_item_tags);
  2856. }
  2857.  
  2858. //remove "
  2859. $multiple_tags_matches = str_replace('"', '', $multiple_tags_matches);
  2860.  
  2861. //explode single tags
  2862. $single_item_tags = explode(' ', $single_item_tags);
  2863.  
  2864. $all_tags = array_merge($multiple_tags_matches,$single_item_tags);
  2865. $all_tags = array_filter($all_tags);
  2866. $all_tags_comma = implode(',', $all_tags);
  2867.  
  2868. if(trim($all_tags_comma) != ''){
  2869. echo '<br>Tags:'.$all_tags_comma;
  2870.  
  2871. if(in_array('OPT_TAXONOMY_TAG', $camp_opt)){
  2872.  
  2873. wp_set_post_terms( $id, $all_tags_comma , trim($camp_general['cg_tag_tax']), true );
  2874.  
  2875. }else{
  2876. wp_set_post_tags ( $id, $all_tags_comma, true );
  2877. }
  2878.  
  2879.  
  2880.  
  2881. }
  2882.  
  2883. }
  2884.  
  2885. //comments
  2886. if(in_array('OPT_SC_COMMENT', $camp_opt)){
  2887.  
  2888. $wp_automatic_sc_client= get_option('wp_automatic_sc_client');
  2889.  
  2890. if(trim($wp_automatic_sc_client) != ''){
  2891.  
  2892. //getting the comment
  2893.  
  2894. $item_id = $img['item_id'];
  2895.  
  2896. echo '<br>Fetching comments for tack:'.$item_id;
  2897.  
  2898. $commentsCount = rand(20,30);
  2899.  
  2900. $api_url = "http://api.soundcloud.com/tracks/$item_id/comments?client_id=$wp_automatic_sc_client&limit=$commentsCount";
  2901.  
  2902. //curl get
  2903. $x='error';
  2904.  
  2905. curl_setopt($this->ch, CURLOPT_HTTPGET, 1);
  2906. curl_setopt($this->ch, CURLOPT_URL, trim($api_url));
  2907. $exec=curl_exec($this->ch);
  2908. $x=curl_error($this->ch);
  2909.  
  2910. if( stristr($exec, '"comment"')){
  2911.  
  2912. $comments_json = json_decode($exec);
  2913.  
  2914. echo '<br>Found '.count($comments_json) . ' comments to post.';
  2915.  
  2916. $time = current_time('mysql');
  2917.  
  2918. foreach ($comments_json as $new_comment){
  2919.  
  2920. if($new_comment->kind == 'comment'){
  2921.  
  2922. $commentUri='';
  2923. if(! in_array('OPT_NO_COMMENT_LINK', $camp_opt))
  2924. $commentUri=$new_comment->user->permalink_url;
  2925.  
  2926. $data = array(
  2927. 'comment_post_ID' => $id,
  2928. 'comment_author' => $new_comment->user->username,
  2929. 'comment_author_email' => '',
  2930. 'comment_author_url' => $commentUri,
  2931. 'comment_content' => $new_comment->body,
  2932. 'comment_type' => '',
  2933. 'comment_parent' => 0,
  2934.  
  2935. 'comment_author_IP' => '127.0.0.1',
  2936. 'comment_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 (.NET CLR 3.5.30729)',
  2937. 'comment_date' => $time,
  2938. 'comment_approved' => 1,
  2939. );
  2940.  
  2941. wp_insert_comment($data);
  2942.  
  2943.  
  2944. }
  2945.  
  2946. }
  2947.  
  2948.  
  2949.  
  2950.  
  2951. }else{
  2952. echo '<br>No comments found';
  2953. }
  2954.  
  2955. }
  2956.  
  2957. }
  2958.  
  2959. }
  2960.  
  2961. //After post facebook
  2962. if($camp_type == 'Facebook'){
  2963. //tags
  2964. if(in_array('OPT_FB_TAGS', $camp_opt)){
  2965. if(trim($img['item_tags']) != ''){
  2966. echo '<br>Setting tags:'.$img['item_tags'];
  2967. if(in_array('OPT_TAXONOMY_TAG', $camp_opt)){
  2968. wp_set_post_terms( $id, $keywords , $img['item_tags'] , true );
  2969. }else{
  2970. wp_set_post_tags ( $id, $img['item_tags'], true );
  2971. }
  2972. }
  2973. }
  2974.  
  2975.  
  2976. // comments
  2977. if(in_array('OPT_FB_COMMENT', $camp_opt)){
  2978.  
  2979. //trying to post FB comments
  2980. echo '<br>Posting FB comments as comments :'.$img['post_id'];
  2981.  
  2982. $cg_fb_access = get_option('wp_automatic_fb_token','');
  2983.  
  2984. //curl get
  2985. $x='error';
  2986. $url='https://graph.facebook.com/v2.5/'.$img['post_id'].'/comments?access_token='.$cg_fb_access.'&summary=1&filter=toplevel&fields=message,id,from,message_tags,created_time,attachment';
  2987.  
  2988.  
  2989. curl_setopt($this->ch, CURLOPT_HTTPGET, 1);
  2990. curl_setopt($this->ch, CURLOPT_URL, trim($url));
  2991. $exec=curl_exec($this->ch);
  2992. $x=curl_error($this->ch);
  2993.  
  2994. if(stristr($exec, 'data')){
  2995.  
  2996. $comments_json = json_decode($exec);
  2997. $comments = $comments_json->data;
  2998.  
  2999. $added = 0 ;
  3000. $time = current_time('mysql');
  3001.  
  3002. foreach($comments as $comment){
  3003.  
  3004. if(! is_array($comment->message_tags)){
  3005.  
  3006.  
  3007. $commentText= $comment->message;
  3008.  
  3009. $commentImg = '';
  3010. $commentImg = @$comment->attachment->media->image->src;
  3011.  
  3012.  
  3013. if(trim($commentImg) != '') $commentText.='<img src="'.$commentImg.'"/>';
  3014.  
  3015. $commentAuthor= $comment->from->name;
  3016.  
  3017. $commentAuthorID= $comment->from->id;
  3018.  
  3019. $commentUri='';
  3020. if(! in_array('OPT_NO_COMMENT_LINK', $camp_opt))
  3021. $commentUri= "https://facebook.com/". $commentAuthorID;
  3022.  
  3023.  
  3024. if(in_array('OPT_ORIGINAL_FB_TIME', $camp_opt) ){
  3025.  
  3026. $time = date('Y-m-d H:i:s', strtotime($comment->created_time) );
  3027. }
  3028.  
  3029.  
  3030. if(trim($commentText) != '' ){
  3031. $data = array(
  3032. 'comment_post_ID' => $id,
  3033. 'comment_author' => $commentAuthor,
  3034. 'comment_author_email' => '',
  3035. 'comment_author_url' => $commentUri,
  3036. 'comment_content' => $commentText,
  3037. 'comment_type' => '',
  3038. 'comment_parent' => 0,
  3039.  
  3040. 'comment_author_IP' => '127.0.0.1',
  3041. 'comment_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 (.NET CLR 3.5.30729)',
  3042. 'comment_date' => $time,
  3043. 'comment_approved' => 1,
  3044. );
  3045.  
  3046. wp_insert_comment($data);
  3047. }
  3048.  
  3049.  
  3050.  
  3051. $added++;
  3052. }
  3053.  
  3054. }
  3055.  
  3056.  
  3057. echo '<br>'.$added . ' comments to post';
  3058.  
  3059.  
  3060.  
  3061.  
  3062. }else{
  3063. echo '<br>No valid reply for the comments request';
  3064. }
  3065.  
  3066.  
  3067. }
  3068. }
  3069.  
  3070. //After post vimeo
  3071. if($camp_type == 'Vimeo'){
  3072.  
  3073. if(in_array('OPT_VM_TAG', $camp_opt)){
  3074.  
  3075. if(trim($vid['vid_tags']) != ''){
  3076.  
  3077. if(in_array('OPT_TAXONOMY_TAG', $camp_opt)){
  3078.  
  3079. wp_set_post_terms( $id, $keywords , $vid['vid_tags'], true );
  3080.  
  3081. }else{
  3082. wp_set_post_tags ( $id, $vid['vid_tags'], true );
  3083. }
  3084.  
  3085. }
  3086. }
  3087.  
  3088. }
  3089.  
  3090. if($camp_type == 'Envato'){
  3091.  
  3092. if(in_array('OPT_EV_AUTO_TAGS', $camp_opt)){
  3093.  
  3094. if(trim($img['item_tags']) != ''){
  3095.  
  3096. if(in_array('OPT_TAXONOMY_TAG', $camp_opt)){
  3097.  
  3098. wp_set_post_terms( $id, $keywords , $img['item_tags'], true );
  3099.  
  3100. }else{
  3101. wp_set_post_tags ( $id, $img['item_tags'], true );
  3102. }
  3103.  
  3104. }
  3105.  
  3106. }
  3107.  
  3108. }
  3109.  
  3110. if($camp_type == 'Instagram'){
  3111.  
  3112. if(in_array('OPT_IT_TAGS', $camp_opt)){
  3113. if(trim($img['item_tags']) != ''){
  3114. echo '<br>Setting tags:'.$img['item_tags'];
  3115. if(in_array('OPT_TAXONOMY_TAG', $camp_opt)){
  3116. wp_set_post_terms( $id, $keywords , $img['item_tags'] , true );
  3117. }else{
  3118. wp_set_post_tags ( $id, $img['item_tags'], true );
  3119. }
  3120. }
  3121. }
  3122.  
  3123. //comments
  3124. if(in_array('OPT_IT_COMMENT', $camp_opt) ){
  3125.  
  3126. echo '<br>Trying to post comments';
  3127.  
  3128. $time = current_time('mysql');
  3129.  
  3130. $comments = $img['item_comments'];
  3131.  
  3132.  
  3133. if(count($comments) > 0){
  3134.  
  3135. echo '<br>Found '.count($comments). ' comment to post from';
  3136.  
  3137. // random count
  3138. $commentsCount = count($comments);
  3139. if($commentsCount == 40 ) {
  3140. $commentsCount = rand(20,40);
  3141. echo '...Posting '.$commentsCount;
  3142. }
  3143.  
  3144.  
  3145. $i=0;
  3146. foreach($comments as $comment ){
  3147.  
  3148. $i++;
  3149.  
  3150. if( $i > $commentsCount ) break;
  3151.  
  3152. $comment = $comment->node;
  3153.  
  3154. $commentText= $comment->text;
  3155.  
  3156. if(isset($comment->created_at) && trim($comment->created_at) != ''){
  3157.  
  3158. //new comments format
  3159. $commentAuthor= $comment->owner->username;
  3160. $commentAuthorID= $comment->owner->id;
  3161.  
  3162.  
  3163. $commentUri='';
  3164. if(! in_array('OPT_NO_COMMENT_LINK', $camp_opt))
  3165. $commentUri= "https://instagram.com/". $comment->owner->username;
  3166.  
  3167. if(in_array('OPT_IT_DATE', $camp_opt) ){
  3168. $time = date('Y-m-d H:i:s',$comment->created_at);
  3169. }
  3170.  
  3171. }else{
  3172.  
  3173. //old comments format
  3174. $commentAuthor= $comment->from->full_name;
  3175. if(trim($commentAuthor) == '') $commentAuthor= $comment->from->username;
  3176. $commentAuthorID= $comment->author[0]->uri->x;
  3177.  
  3178.  
  3179. $commentUri='';
  3180. if(! in_array('OPT_NO_COMMENT_LINK', $camp_opt))
  3181. $commentUri= "https://instagram.com/". $comment->from->username;
  3182. if(in_array('OPT_IT_DATE', $camp_opt) ){
  3183. $time = date('Y-m-d H:i:s',$comment->created_time);
  3184. }
  3185.  
  3186.  
  3187. }
  3188.  
  3189.  
  3190. if(trim($commentText) != '' ){
  3191. $data = array(
  3192. 'comment_post_ID' => $id,
  3193. 'comment_author' => $commentAuthor,
  3194. 'comment_author_email' => '',
  3195. 'comment_author_url' => $commentUri,
  3196. 'comment_content' => $commentText,
  3197. 'comment_type' => '',
  3198. 'comment_parent' => 0,
  3199.  
  3200. 'comment_author_IP' => '127.0.0.1',
  3201. 'comment_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 (.NET CLR 3.5.30729)',
  3202. 'comment_date' => $time,
  3203. 'comment_approved' => 1,
  3204. );
  3205.  
  3206. wp_insert_comment($data);
  3207. }
  3208.  
  3209. }
  3210.  
  3211.  
  3212.  
  3213.  
  3214.  
  3215. }else{
  3216. echo '<br>No comments found';
  3217. }
  3218.  
  3219. }
  3220.  
  3221.  
  3222.  
  3223. }
  3224.  
  3225. //After Twitter
  3226. if($camp_type == 'Twitter'){
  3227. if(in_array('OPT_TW_TAG', $camp_opt)){
  3228.  
  3229. if(isset($img['item_hashtags'])){
  3230. echo '<br>Tags:'.$img['item_hashtags'];
  3231. wp_set_post_tags ( $id, $img['item_hashtags'], true );
  3232.  
  3233. }
  3234. }
  3235. }
  3236.  
  3237. //After Reddit
  3238. if($camp_type == 'Reddit'){
  3239.  
  3240. if(in_array('OPT_RD_COMMENT', $camp_opt)){
  3241.  
  3242. //comments
  3243. echo '<br>Getting comments';
  3244. $comments_link = ($img['item_link'].'.json');
  3245.  
  3246. //curl get
  3247. $x='error';
  3248.  
  3249. curl_setopt($this->ch, CURLOPT_HTTPGET, 1);
  3250. curl_setopt($this->ch, CURLOPT_URL, trim($comments_link));
  3251. $exec=curl_exec($this->ch);
  3252. $x=curl_error($this->ch);
  3253.  
  3254. if(stristr($exec, '[{')){
  3255.  
  3256. $commentsJson = json_decode($exec);
  3257. $commentsJson = $commentsJson[1]->data->children;
  3258.  
  3259. echo '<br>Found '.count($commentsJson) . ' comments ';
  3260. $time = current_time('mysql');
  3261.  
  3262. foreach ($commentsJson as $newComment){
  3263.  
  3264. if(in_array('OPT_RD_TIME', $camp_opt)){
  3265. $time = get_date_from_gmt( gmdate ( 'Y-m-d H:i:s' , ($newComment->data->created_utc) ) ) ;
  3266. }
  3267.  
  3268. $commentUri='';
  3269. if(! in_array('OPT_NO_COMMENT_LINK', $camp_opt))
  3270.  
  3271. $commentUri='https://www.reddit.com/'.$newComment->data->author;
  3272.  
  3273. $data = array(
  3274. 'comment_post_ID' => $id,
  3275. 'comment_author' => $newComment->data->author,
  3276. 'comment_author_email' => '',
  3277. 'comment_author_url' => $commentUri,
  3278. 'comment_content' => $newComment->data->body,
  3279. 'comment_type' => '',
  3280. 'comment_parent' => 0,
  3281.  
  3282. 'comment_author_IP' => '127.0.0.1',
  3283. 'comment_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 (.NET CLR 3.5.30729)',
  3284. 'comment_date' => $time,
  3285. 'comment_approved' => 1,
  3286. );
  3287.  
  3288. wp_insert_comment($data);
  3289.  
  3290.  
  3291. }
  3292.  
  3293.  
  3294. }else{
  3295. echo '<br>Not valid reply from Reddit';
  3296. }
  3297.  
  3298.  
  3299.  
  3300.  
  3301. }
  3302.  
  3303. }
  3304.  
  3305. //After ebay
  3306. if(in_array('OPT_EB_REDIRECT_END', $camp_opt)){
  3307. echo '<br>Setting expiry date: '.$img['item_end_date'];
  3308.  
  3309. $expiry_date = strtotime( $img['item_end_date'] );
  3310.  
  3311. add_post_meta($id, 'wp_automatic_redirect_date', $expiry_date);
  3312. add_post_meta($id, 'wp_automatic_redirect_link', $camp_general['cg_eb_redirect_end']);
  3313.  
  3314. }
  3315.  
  3316. if(in_array('OPT_EB_TRASH', $camp_opt)){
  3317. echo '<br>Setting trash date: '.$img['item_end_date'];
  3318.  
  3319. $expiry_date = strtotime( $img['item_end_date'] );
  3320.  
  3321. add_post_meta($id, 'wp_automatic_trash_date', $expiry_date);
  3322.  
  3323. }
  3324.  
  3325. //setting post tags
  3326. $post_tags=array();
  3327.  
  3328. if(in_array('OPT_ADD_TAGS',$camp_opt ) ){
  3329.  
  3330. $post_tags = array_filter( explode("\n", $camp_general['cg_post_tags']));
  3331.  
  3332. $max = $camp_general['cg_tags_limit'];
  3333. if(! is_numeric($max)) $max= 100;
  3334.  
  3335. if(in_array('OPT_RANDOM_TAGS', $camp_opt) && count($post_tags) > $max ){
  3336.  
  3337.  
  3338. $rand_keys = array_rand($post_tags,$max);
  3339.  
  3340. if(is_array($rand_keys)) {
  3341.  
  3342.  
  3343. $temp_tags = array();
  3344. foreach ($rand_keys as $key){
  3345. $temp_tags[] = $post_tags[$key];
  3346. }
  3347.  
  3348. }else{
  3349.  
  3350. //single value selected like 0
  3351.  
  3352. $temp_tags[] = $post_tags[$rand_keys] ;
  3353. }
  3354.  
  3355. $post_tags = $temp_tags;
  3356.  
  3357. }
  3358.  
  3359. }
  3360.  
  3361.  
  3362.  
  3363. if(in_array('OPT_ORIGINAL_TAGS', $camp_opt)){
  3364. $new_tags = explode(',', $img['tags']);
  3365.  
  3366. if(count($new_tags) > 0 ){
  3367. $post_tags = array_merge($post_tags,$new_tags);
  3368. }
  3369.  
  3370. }
  3371.  
  3372. //title tags
  3373. if(in_array('OPT_TITLE_TAG', $camp_opt)){
  3374.  
  3375. $titleWords = explode(' ', $my_post['post_title'] );
  3376. $validTitleWords = array();
  3377.  
  3378. //get stop words
  3379. $stopWordsRaw = file_get_contents( dirname(__FILE__) . '/stopwords.txt');
  3380.  
  3381. $stopWords = array();
  3382. $stopWords = explode(',', $stopWordsRaw);
  3383.  
  3384. //additional stop words
  3385. $additionalStopWordsRaw = get_option('wp_automatic_ttt_stop','');
  3386.  
  3387. if(trim($additionalStopWordsRaw) != ''){
  3388. $additionalStopWordsArr = explode("\n", $additionalStopWordsRaw);
  3389. $additionalStopWordsArr = array_filter($additionalStopWordsArr);
  3390.  
  3391. $stopWords = array_merge($stopWords,$additionalStopWordsArr);
  3392.  
  3393. }
  3394.  
  3395. $stopWords = array_map('trim', $stopWords);
  3396.  
  3397. foreach ($titleWords as $titleWord){
  3398.  
  3399. $titleWord = preg_replace('#[^\p{L}\p{N}]+#u', '', $titleWord);
  3400.  
  3401. if( ! in_array( strtolower($titleWord) , $stopWords)){
  3402.  
  3403. if(in_array('OPT_TITLE_NUM', $camp_opt) && is_numeric(trim($titleWord))){
  3404. //numbers
  3405. }else{
  3406. $validTitleWords[]=$titleWord;
  3407. }
  3408.  
  3409.  
  3410. }
  3411.  
  3412.  
  3413. }
  3414.  
  3415. $post_tags = array_merge($post_tags,$validTitleWords);
  3416.  
  3417.  
  3418. }
  3419.  
  3420. // Keyword to tag
  3421. if(in_array('OPT_KEYWORD_TAG', $camp_opt) && trim($camp_general['cg_keyword_tag']) != '' ){
  3422. echo '<br>Keyword to tag check started...';
  3423.  
  3424. $cg_keyword_tag = $camp_general['cg_keyword_tag'];
  3425. $cg_keyword_tag_rules = array_filter( explode("\n", $cg_keyword_tag) );
  3426.  
  3427. foreach ($cg_keyword_tag_rules as $cg_keyword_tag_rule) {
  3428. if(stristr( $cg_keyword_tag_rule , '|')){
  3429.  
  3430. $cg_keyword_tag_rule = trim($cg_keyword_tag_rule);
  3431.  
  3432. $cg_keyword_tag_rule_parts = explode ('|', $cg_keyword_tag_rule) ;
  3433.  
  3434. $cg_keyword_tag_rule_keyword = $cg_keyword_tag_rule_parts[0];
  3435. $cg_keyword_tag_rule_tag = $cg_keyword_tag_rule_parts[1];
  3436.  
  3437. if( preg_match('{\b' . preg_quote( $cg_keyword_tag_rule_keyword ). '\b}siu', $abcont)){
  3438.  
  3439. echo '<br><- Key '.$cg_keyword_tag_rule_keyword . ' exists adding tag:'.$cg_keyword_tag_rule_tag;
  3440.  
  3441. if( stristr($cg_keyword_tag_rule_tag, ',') ){
  3442.  
  3443. $post_tags = array_merge($post_tags,explode(',', $cg_keyword_tag_rule_tag));
  3444.  
  3445. }elseif(trim($cg_keyword_tag_rule_tag)){
  3446.  
  3447. $post_tags[]=$cg_keyword_tag_rule_tag;
  3448.  
  3449. }
  3450.  
  3451. }
  3452.  
  3453. }
  3454. }
  3455.  
  3456. }
  3457.  
  3458.  
  3459. if(count( array_filter( $post_tags ) ) > 0){
  3460.  
  3461. $post_tags = array_filter($post_tags);
  3462.  
  3463. echo '<br>Setting ' . count($post_tags) .' post tags as tags';
  3464.  
  3465. if(in_array('OPT_TAXONOMY_TAG', $camp_opt)){
  3466.  
  3467. wp_set_post_terms( $id, implode(',', $post_tags), trim($camp_general['cg_tag_tax']), true );
  3468.  
  3469. }else{
  3470. wp_set_post_tags ( $id, implode(',', $post_tags) , true );
  3471. }
  3472.  
  3473. }
  3474.  
  3475. //now timestamp
  3476. $now = time('now');
  3477.  
  3478. //amazon woocommerce integration
  3479. if($camp_type == 'Amazon' && $camp->camp_post_type == 'product'){
  3480.  
  3481. $camp_post_custom_k = array_merge ( array('product_price_updated','product_asin','product_price','product_list_price','_regular_price','_price','_sale_price','_visibility', '_product_url','_button_text','_product_type'),$camp_post_custom_k);
  3482.  
  3483. $wp_automatic_woo_buy = get_option('wp_automatic_woo_buy','Buy Now');
  3484. if(trim($wp_automatic_woo_buy) == '') $wp_automatic_woo_buy = 'Buy Now' ;
  3485.  
  3486. $camp_post_custom_v = array_merge ( array( $now , '[product_asin]','[product_price]','[product_list_price]','[list_price_numeric]','[price_numeric]','[price_numeric]','visible','[product_link]',$wp_automatic_woo_buy,'external'),$camp_post_custom_v);
  3487.  
  3488. //product gallery
  3489. if( isset($img['product_imgs']) && stristr($img['product_imgs'], ',') && in_array('OPT_AM_GALLERY', $camp_opt)){
  3490.  
  3491. echo '<br>Multiple images found setting a gallery';
  3492. $attachmentsIDs=array();
  3493.  
  3494. $product_imgs_txt = $img['product_imgs'];
  3495. $product_imgs = explode(',', $product_imgs_txt);
  3496.  
  3497. //first image already attached
  3498. if(isset($attach_id)){
  3499.  
  3500. //$attachmentsIDs[] = $attach_id;
  3501. unset($product_imgs[0]);
  3502. }
  3503.  
  3504. // set rest images as attachments
  3505. foreach ($product_imgs as $product_img){
  3506. echo '<br>Attaching:'. $product_img ;
  3507. $newAttach = $this->attach_image($product_img, $camp_opt, $post_id);
  3508.  
  3509. if(is_numeric($newAttach) && $newAttach > 0 ){
  3510. $attachmentsIDs[]=$newAttach;
  3511. }
  3512.  
  3513.  
  3514. }
  3515.  
  3516. if(count($attachmentsIDs) > 0){
  3517.  
  3518. $attachmentsIDsStr = implode(',', $attachmentsIDs);
  3519. add_post_meta($id,'_product_image_gallery',$attachmentsIDsStr);
  3520.  
  3521. }
  3522.  
  3523. }
  3524.  
  3525. wp_set_object_terms ($id, 'external', 'product_type');
  3526.  
  3527.  
  3528.  
  3529. }elseif($camp_type == 'eBay' && $camp->camp_post_type == 'product'){
  3530.  
  3531. $camp_post_custom_k = array_merge ( $camp_post_custom_k , array('_regular_price','_price','_visibility', '_product_url','_button_text','_product_type'));
  3532. $wp_automatic_woo_buy = get_option('wp_automatic_woo_buy2','Buy Now');
  3533. if(trim($wp_automatic_woo_buy) == '') $wp_automatic_woo_buy = 'Buy Now' ;
  3534.  
  3535. $camp_post_custom_v = array_merge ( $camp_post_custom_v , array('[item_price_numeric]','[item_price_numeric] ','visible','[item_link]',$wp_automatic_woo_buy,'external'));
  3536.  
  3537. wp_set_object_terms ($id, 'external', 'product_type');
  3538.  
  3539. }elseif($camp_type == 'Amazon' && $camp->camp_post_type != 'product'){
  3540.  
  3541. $camp_post_custom_k = array_merge ( array('product_price_updated','product_asin','product_price','product_list_price'),$camp_post_custom_k);
  3542. $camp_post_custom_v = array_merge ( array( $now , '[product_asin]','[product_price]','[product_list_price]'),$camp_post_custom_v);
  3543.  
  3544. }elseif($camp_type == 'Walmart' && $camp->camp_post_type != 'product'){
  3545.  
  3546. $camp_post_custom_k = array_merge ( array('product_price_updated','product_upc','product_price','product_list_price'),$camp_post_custom_k);
  3547. $camp_post_custom_v = array_merge ( array( $now , '[item_upc]','$[item_price]','$[item_list_price]'),$camp_post_custom_v);
  3548.  
  3549. }elseif($camp_type == 'Walmart' && $camp->camp_post_type == 'product'){
  3550.  
  3551. //affiliate item_link
  3552. if(stristr( $post_content , 'linksynergy')){
  3553. $buyShortCode = '[product_affiliate_url]';
  3554. }else{
  3555. $buyShortCode = '[item_link]';
  3556. }
  3557.  
  3558. $camp_post_custom_k = array_merge ( array('product_price_updated','product_upc','product_price','product_list_price','_regular_price','_price','_sale_price','_visibility', '_product_url','_button_text','_product_type'),$camp_post_custom_k);
  3559.  
  3560. $wp_automatic_woo_buy = get_option('wp_automatic_woo_buy','Buy Now');
  3561. if(trim($wp_automatic_woo_buy) == '') $wp_automatic_woo_buy = 'Buy Now' ;
  3562.  
  3563. $camp_post_custom_v = array_merge ( array( $now , '[item_upc]','$[item_price]','$[item_list_price]','[item_list_price]','[item_price]','[item_price]','visible',$buyShortCode,$wp_automatic_woo_buy,'external'),$camp_post_custom_v);
  3564.  
  3565. //product gallery
  3566. if( isset($img['item_imgs']) && stristr($img['item_imgs'], ',') && in_array('OPT_WM_GALLERY', $camp_opt)){
  3567.  
  3568. echo '<br>Multiple images found setting a gallery';
  3569. $attachmentsIDs=array();
  3570.  
  3571. $product_imgs_txt = $img['item_imgs'];
  3572. $product_imgs = explode(',', $product_imgs_txt);
  3573.  
  3574. //first image already attached
  3575. if(isset($attach_id)){
  3576.  
  3577. //$attachmentsIDs[] = $attach_id;
  3578. unset($product_imgs[0]);
  3579. }
  3580.  
  3581. // set rest images as attachments
  3582. foreach ($product_imgs as $product_img){
  3583. echo '<br>Attaching:'. $product_img ;
  3584. $newAttach = $this->attach_image($product_img, $camp_opt, $post_id);
  3585.  
  3586. if(is_numeric($newAttach) && $newAttach > 0 ){
  3587. $attachmentsIDs[]=$newAttach;
  3588. }
  3589.  
  3590.  
  3591. }
  3592.  
  3593. if(count($attachmentsIDs) > 0){
  3594.  
  3595. $attachmentsIDsStr = implode(',', $attachmentsIDs);
  3596. add_post_meta($id,'_product_image_gallery',$attachmentsIDsStr);
  3597.  
  3598. }
  3599.  
  3600. }
  3601.  
  3602. wp_set_object_terms ($id, 'external', 'product_type');
  3603.  
  3604. }elseif( $camp->camp_post_type == 'product' ){
  3605.  
  3606. $camp_post_custom_k = array_merge ( $camp_post_custom_k , array('_visibility'));
  3607. $camp_post_custom_v = array_merge ( $camp_post_custom_v , array('visible'));
  3608.  
  3609. wp_set_object_terms ($id, 'external', 'product_type');
  3610.  
  3611.  
  3612. }
  3613.  
  3614. //TrueMag integration
  3615. if( ($camp_type == 'Youtube' || $camp_type == 'Vimeo') ){
  3616.  
  3617. if( (defined('PARENT_THEME') && (PARENT_THEME =='truemag' || PARENT_THEME =='newstube')) || class_exists('Cactus_video') ){
  3618.  
  3619. echo '<br>TrueMag/NewsTube theme exists adabting config..';
  3620. $camp_post_custom_k = array_merge ( $camp_post_custom_k , array('tm_video_url','_count-views_all'));
  3621. $camp_post_custom_v = array_merge ( $camp_post_custom_v , array('[source_link]','[vid_views]'));
  3622.  
  3623. //adding likes n dislikes
  3624. $vid_likes = $img['vid_likes'];
  3625. $vid_dislikes = $img['vid_dislikes'];
  3626.  
  3627. //adding likes
  3628. if($vid_likes > 0 ){
  3629.  
  3630. try {
  3631.  
  3632. $query = "INSERT INTO {$this->db->prefix}wti_like_post SET ";
  3633. $query .= "post_id = '" . $id . "', ";
  3634. $query .= "value = '$vid_likes', ";
  3635. $query .= "date_time = '" . date( 'Y-m-d H:i:s' ) . "', ";
  3636. $query .= "ip = ''";
  3637. @$this->db->query($query);
  3638.  
  3639. } catch (Exception $e) {
  3640.  
  3641. }
  3642.  
  3643. }
  3644.  
  3645. if($vid_dislikes > 0 && $camp_type == 'Youtube' ){
  3646.  
  3647. $query = "INSERT INTO {$this->db->prefix}wti_like_post SET ";
  3648. $query .= "post_id = '" . $id . "', ";
  3649. $query .= "value = '-$vid_dislikes', ";
  3650. $query .= "date_time = '" . date( 'Y-m-d H:i:s' ) . "', ";
  3651. $query .= "ip = ''";
  3652. @$this->db->query($query);
  3653. }
  3654.  
  3655.  
  3656.  
  3657. }
  3658. }
  3659.  
  3660. // truemag dailymotion integration
  3661. if($camp_type == 'DailyMotion'){
  3662.  
  3663. if( (defined('PARENT_THEME') && (PARENT_THEME =='truemag' || PARENT_THEME =='newstube')) || class_exists('Cactus_video') ){
  3664.  
  3665. echo '<br>TrueMag/NewsTube theme exists adabting config..';
  3666. $camp_post_custom_k = array_merge ( $camp_post_custom_k , array('tm_video_url','_count-views_all'));
  3667. $camp_post_custom_v = array_merge ( $camp_post_custom_v , array('[source_link]','[item_views]'));
  3668.  
  3669.  
  3670. }
  3671.  
  3672. }
  3673.  
  3674. // trumag instagram integration
  3675. if( ($camp_type == 'Instagram' ) && stristr($abcont, '[embed]') ){
  3676.  
  3677. if( (defined('PARENT_THEME') && (PARENT_THEME =='truemag' || PARENT_THEME =='newstube')) || class_exists('Cactus_video') ){
  3678.  
  3679. echo '<br>TrueMag/NewsTube theme exists adabting config..';
  3680.  
  3681. //extract video url
  3682. preg_match('{\[embed\](.*?)\[/embed\]}', $abcont,$embedMatchs);
  3683.  
  3684. $embedUrl = $embedMatchs[1];
  3685.  
  3686.  
  3687. $camp_post_custom_k = array_merge ( $camp_post_custom_k , array('tm_video_file'));
  3688. $camp_post_custom_v = array_merge ( $camp_post_custom_v , array($embedUrl));
  3689.  
  3690. //adding likes n dislikes
  3691. $vid_likes = $img['item_likes_count'];
  3692.  
  3693. //adding likes
  3694. if($vid_likes > 0 ){
  3695.  
  3696. try {
  3697.  
  3698.  
  3699. $query = "INSERT INTO {$this->db->prefix}wti_like_post SET ";
  3700. $query .= "post_id = '" . $id . "', ";
  3701. $query .= "value = '$vid_likes', ";
  3702. $query .= "date_time = '" . date( 'Y-m-d H:i:s' ) . "', ";
  3703. $query .= "ip = ''";
  3704. @$this->db->query($query);
  3705.  
  3706. } catch (Exception $e) {
  3707. }
  3708.  
  3709. }
  3710.  
  3711. }
  3712. }
  3713.  
  3714.  
  3715. //truemag facebook integration
  3716. if($camp_type =='Facebook'){
  3717.  
  3718. if(isset($img['vid_url'])){
  3719.  
  3720. if( (defined('PARENT_THEME') && (PARENT_THEME =='truemag' || PARENT_THEME =='newstube')) || class_exists('Cactus_video') ){
  3721.  
  3722. echo '<br>TrueMag setup and video exists...';
  3723.  
  3724. $camp_post_custom_k = array_merge ( $camp_post_custom_k , array('tm_video_url'));
  3725. $camp_post_custom_v = array_merge ( $camp_post_custom_v , array($img['vid_url']));
  3726.  
  3727.  
  3728. }
  3729. }
  3730.  
  3731. }
  3732.  
  3733.  
  3734. //replacing tags
  3735. $camp_post_custom_v = implode ( '****', $camp_post_custom_v );
  3736. foreach ( $img as $key => $val ) {
  3737. if(! is_array($val)){
  3738. $camp_post_custom_v = str_replace ( '[' . $key . ']', $val, $camp_post_custom_v );
  3739. }
  3740.  
  3741. //feed custom attributes
  3742. if($camp_type == 'Feeds'){
  3743.  
  3744. $attributes = $img['attributes'];
  3745.  
  3746. foreach ($attributes as $attributeKey => $attributeValue){
  3747.  
  3748. $camp_post_custom_v = str_replace('['.$attributeKey.']', $attributeValue[0]['data'] , $camp_post_custom_v);
  3749.  
  3750. }
  3751. }
  3752.  
  3753. }
  3754. $camp_post_custom_v = explode ( '****', $camp_post_custom_v );
  3755.  
  3756.  
  3757. //NewsPaper theme integration
  3758. if( ($camp_type == 'Youtube' || $camp_type == 'Vimeo') && function_exists('td_bbp_change_avatar_size')){
  3759. echo '<br>NewsPaper theme found integrating..';
  3760.  
  3761.  
  3762.  
  3763. $td_video = array();
  3764. $td_video['td_video'] = $img['vid_url'];
  3765. $td_video['td_last_video'] = $img['vid_url'];
  3766.  
  3767.  
  3768.  
  3769. $camp_post_custom_k[] = 'td_post_video';
  3770. $camp_post_custom_v[] = $td_video;
  3771.  
  3772. //format
  3773. echo '<br>setting post format to Video';
  3774. set_post_format($id, 'video' );
  3775.  
  3776. //custom field
  3777.  
  3778. }
  3779.  
  3780.  
  3781. // adding custom filds
  3782. $in = 0;
  3783. if (count ( $camp_post_custom_k ) > 0) {
  3784.  
  3785.  
  3786. foreach ( $camp_post_custom_k as $key ) {
  3787. if (trim ( $key ) != '' & trim ( $camp_post_custom_v [$in] != '' )) {
  3788. echo '<br>Setting custom field ' . $key ;
  3789.  
  3790. //serialized arrays
  3791. if(is_serialized($camp_post_custom_v [$in])) $camp_post_custom_v [$in] = unserialize($camp_post_custom_v [$in]);
  3792.  
  3793. if($key == 'excerpt'){
  3794.  
  3795. $my_post = array(
  3796. 'ID' => $id,
  3797. 'post_excerpt' => $camp_post_custom_v [$in] ,
  3798. );
  3799.  
  3800. wp_update_post( $my_post );
  3801.  
  3802. }else{
  3803. update_post_meta ( $id, $key, $camp_post_custom_v [$in] );
  3804.  
  3805. }
  3806.  
  3807. }
  3808.  
  3809. $in ++;
  3810. }
  3811. }
  3812.  
  3813. //setting post format OPT_FORMAT
  3814. if (in_array ( 'OPT_FORMAT', $camp_opt )) {
  3815. echo '<br>setting post format to '.$camp_general['cg_post_format'];
  3816. set_post_format($id, stripslashes($camp_general['cg_post_format']) );
  3817. }elseif ( ($camp_type == 'Youtube' || $camp_type == 'Vimeo' || $camp_type == 'DailyMotion') ){
  3818.  
  3819. if( (defined('PARENT_THEME') && (PARENT_THEME =='truemag' || PARENT_THEME =='newstube')) || class_exists('Cactus_video') ){
  3820. echo '<br>setting post format to Video';
  3821. set_post_format($id, 'video' );
  3822. }
  3823. }elseif ( ($camp_type == 'Instagram' ) && stristr($abcont, '[embed]') ){
  3824.  
  3825. if( (defined('PARENT_THEME') && (PARENT_THEME =='truemag' || PARENT_THEME =='newstube')) || class_exists('Cactus_video') ){
  3826. echo '<br>setting post format to Video';
  3827. set_post_format($id, 'video' );
  3828. }
  3829. }elseif($camp_type == 'Facebook' && isset($img['vid_url'])){
  3830.  
  3831. if( (defined('PARENT_THEME') && (PARENT_THEME =='truemag' || PARENT_THEME =='newstube')) || class_exists('Cactus_video') ){
  3832. echo '<br>setting post format to Video';
  3833. set_post_format($id, 'video' );
  3834. }
  3835.  
  3836. }
  3837.  
  3838.  
  3839. //publishing the post
  3840. if(in_array('OPT_DRAFT_PUBLISH', $camp_opt) && $camp->camp_post_status == 'publish'){
  3841.  
  3842. echo '<br>Publishing the post now...';
  3843. $newUpdatedPostArr['ID'] = $id;
  3844. $newUpdatedPostArr['post_status'] = 'publish';
  3845.  
  3846. wp_update_post($newUpdatedPostArr);
  3847.  
  3848. }
  3849.  
  3850. if(in_array('OPT_PREVIEW_EDIT',$wp_automatic_options)){
  3851. $plink = admin_url('post.php?post='.$id.'&action=edit');
  3852. if(trim($plink) == '') $plink = get_permalink ( $id ) ;
  3853. }else{
  3854. $plink = get_permalink ( $id ) ;
  3855. }
  3856.  
  3857. $plink = str_replace('&amp;', '&', $plink) ;
  3858.  
  3859.  
  3860. $display_title = get_the_title ( $id );
  3861.  
  3862. if(trim($display_title) == '') $display_title = '(no title)';
  3863.  
  3864. $now = date ( 'Y-m-d H:i:s' );
  3865. $now = get_date_from_gmt($now);
  3866.  
  3867. echo '<br>New Post posted: <a target="_blank" class="new_post_link" time="' . $now . '" href="' . $plink . '"> ' . $display_title . '</a>';
  3868. $this->log ( 'Posted:' . $camp->camp_id, 'New post posted:<a href="' . $plink . '">' . get_the_title ( $id ) . '</a>' );
  3869.  
  3870. //returning the security filter
  3871. add_filter('content_save_pre', 'wp_filter_post_kses');
  3872.  
  3873. //duplicate cache update
  3874. if( $this->campDuplicateLinksUpdate == true ){
  3875.  
  3876. $this->campNewDuplicateLinks[$id] = $source_link;
  3877. update_post_meta($camp->camp_id, 'wp_automatic_duplicate_cache', $this->campNewDuplicateLinks);
  3878.  
  3879. }
  3880.  
  3881. exit ();
  3882.  
  3883. print_r ( $ret );
  3884. } // if title
  3885. } // end function
  3886.  
  3887.  
  3888. /**
  3889. * Checks if allowed to call the source or not: compares the call limit with actual previous calls
  3890. */
  3891. function is_allowed_to_call(){
  3892.  
  3893. if($this->sourceCallLimit == $this->sourceCallTimes){
  3894. echo '<br> We have called the source '.$this->sourceCallLimit.' times already will die now and complete next time...';
  3895. exit;
  3896. }
  3897.  
  3898. $this->sourceCallTimes++ ;
  3899.  
  3900. }
  3901.  
  3902.  
  3903. /**
  3904. * Validate if the post contains the exact match keywords and does not contain the banned words
  3905. * @param String $cnt the content
  3906. * @param String $ttl the title
  3907. * @param String $opt campaign options
  3908. * @param String $camp whole camp record
  3909. */
  3910. function validate_exacts(&$abcont,&$title,&$camp_opt,&$camp){
  3911.  
  3912. // Valid
  3913. $valid = true;
  3914.  
  3915. // Validate exacts
  3916. if(in_array('OPT_EXACT' , $camp_opt )){
  3917.  
  3918. // Exact keys
  3919. $exact = $camp->camp_post_exact;
  3920.  
  3921. // Validating Exact
  3922. if (trim ( $exact ) != '' & in_array('OPT_EXACT', $camp_opt) && ! in_array('OPT_EXACT_AFTER', $camp_opt)) {
  3923.  
  3924. $valid = false;
  3925.  
  3926. $exactArr = explode ( "\n", trim ( $exact ) );
  3927.  
  3928. foreach ( $exactArr as $wordexact ) {
  3929. if (trim ( $wordexact != '' )) {
  3930.  
  3931. if(in_array('OPT_EXACT_STR', $camp_opt)){
  3932.  
  3933. if( in_array('OPT_EXACT_TITLE_ONLY', $camp_opt) && stristr( html_entity_decode($title) , trim ( $wordexact ) ) ){
  3934.  
  3935. echo '<br>Title contains the word : ' . $wordexact ;
  3936. $valid = true;
  3937. break;
  3938.  
  3939. }elseif ( ! in_array('OPT_EXACT_TITLE_ONLY', $camp_opt) && ( stristr ( html_entity_decode($abcont) , trim ( $wordexact ) ) || stristr ( trim ( $wordexact ) , html_entity_decode($title) ) ) ) {
  3940. echo '<br>Content contains the word : ' . $wordexact ;
  3941. $valid = true;
  3942. break;
  3943. }else{
  3944. echo '<br>Content does not contain the word : ' . $wordexact . ' try another ';
  3945. } // match
  3946.  
  3947. }else{
  3948.  
  3949. if( in_array('OPT_EXACT_TITLE_ONLY', $camp_opt) && preg_match ( '/\b' . trim ( $wordexact ) . '\b/iu', html_entity_decode($title) ) ){
  3950. echo '<br>Title contains the word : ' . $wordexact ;
  3951. $valid = true;
  3952. break;
  3953. }elseif ( ! in_array('OPT_EXACT_TITLE_ONLY', $camp_opt) && ( preg_match ( '/\b' . trim ( $wordexact ) . '\b/iu', html_entity_decode($abcont) ) || preg_match ( '/\b' . trim ( $wordexact ) . '\b/iu', html_entity_decode($title) ) ) ) {
  3954. echo '<br>Content contains the word : ' . $wordexact ;
  3955. $valid = true;
  3956. break;
  3957. }else{
  3958. echo '<br>Content does not contain the word : ' . $wordexact . ' try another ';
  3959. } // match
  3960.  
  3961.  
  3962. }
  3963.  
  3964.  
  3965. } // trim wordexact
  3966. } // foreach exactword
  3967. } // trim exact
  3968. }
  3969.  
  3970. // validating execlude
  3971. if ($valid == true) {
  3972.  
  3973. $execl = $camp->camp_post_execlude;
  3974.  
  3975.  
  3976. if (trim ( $execl ) != '' && in_array('OPT_EXECLUDE', $camp_opt) && ! in_array('OPT_EXECLUDE_AFTER', $camp_opt) ) {
  3977.  
  3978. //additional excl
  3979. $execl.= "\n".$this->generalBannedWords ;
  3980.  
  3981. $execlArr = explode ( "\n", trim ( $execl ) );
  3982.  
  3983. foreach ( $execlArr as $wordex ) {
  3984. if (trim ( $wordex != '' )) {
  3985. if ( preg_match ( '/\b' . trim ( $wordex ) . '\b/iu', html_entity_decode($abcont) ) || preg_match ( '/\b' . trim ( $wordex ) . '\b/iu', (html_entity_decode($title)) ) ) {
  3986. echo '<br>Content contains the banned word :' . $wordex . ' getting another ';
  3987. $valid = false;
  3988. break;
  3989. }
  3990. } // trim wordexec
  3991. } // foreach wordex
  3992. } // trim execl
  3993. } // valid
  3994.  
  3995.  
  3996. return $valid;
  3997.  
  3998.  
  3999. }
  4000.  
  4001. function fire_proxy() {
  4002. echo '<br>Proxy Check Fired';
  4003. $proxies = get_option ( 'wp_automatic_proxy' );
  4004. if (stristr ( $proxies, ':' )) {
  4005. echo '<br>Proxy Found lets try';
  4006. // listing all proxies
  4007.  
  4008. $proxyarr = explode ( "\n", $proxies );
  4009.  
  4010. foreach ( $proxyarr as $proxy ) {
  4011. if (trim ( $proxy ) != '') {
  4012.  
  4013. $auth = '';
  4014. if (substr_count ( $proxy, ':' ) == 3) {
  4015. echo '<br>Private proxy found .. using authentication';
  4016. $proxy_parts = explode ( ':', $proxy );
  4017.  
  4018. $proxy = $proxy_parts [0] . ':' . $proxy_parts [1];
  4019. $auth = $proxy_parts [2] . ':' . $proxy_parts [3];
  4020.  
  4021. curl_setopt ( $this->ch, CURLOPT_PROXY, trim ( $proxy ) );
  4022. curl_setopt ( $this->ch, CURLOPT_PROXYUSERPWD, trim($auth) );
  4023. } else {
  4024. curl_setopt ( $this->ch, CURLOPT_PROXY, trim ( $proxy ) );
  4025. }
  4026.  
  4027. echo "<br>Trying using proxy :$proxy";
  4028.  
  4029. curl_setopt ( $this->ch, CURLOPT_HTTPPROXYTUNNEL, 1 );
  4030.  
  4031. curl_setopt ( $this->ch, CURLOPT_URL, 'www.bing.com/search?count=50&intlF=1&mkt=En-us&first=0&q=test' );
  4032. // curl_setopt($this->ch, CURLOPT_URL, 'http://whatismyipaddress.com/');
  4033. $exec = curl_exec ( $this->ch );
  4034. $x = curl_error ( $this->ch );
  4035.  
  4036. if ( trim($x) != '' ) {
  4037. echo '<br>Curl Proxy Error:' . curl_error ( $this->ch );
  4038. } else {
  4039.  
  4040. if (stristr ( $exec, 'It appears that you are using a Proxy' ) || stristr ( $exec, 'excessive amount of traffic' )) {
  4041. echo '<br>Proxy working but captcha met let s skip it';
  4042. } elseif (stristr ( $exec, 'microsoft.com' )) {
  4043.  
  4044. // succsfull connection here
  4045. // echo curl_exec($this->ch);
  4046. // reordering the proxy
  4047. $proxies = str_replace ( ' ', '', $proxies );
  4048.  
  4049. if(trim($auth) != '')
  4050. $proxy = $proxy.':'.$auth;
  4051.  
  4052. $proxies = str_replace($proxy, '', $proxies);
  4053.  
  4054. $proxies = str_replace ( "\n\n", "\n", $proxies );
  4055. $proxies = "$proxy\n$proxies";
  4056. // echo $proxies;
  4057. update_option ( 'wp_automatic_proxy', $proxies );
  4058.  
  4059. echo '<br>Connected successfully using this proxy ';
  4060.  
  4061. $this->isProxified = true;
  4062.  
  4063. return true;
  4064. } else {
  4065.  
  4066. echo '<br>Proxy Reply:'.$exec;
  4067.  
  4068. }
  4069. }
  4070. }
  4071. }
  4072.  
  4073. // all proxies not working let's call proxyfrog for new list
  4074.  
  4075. // no proxyfrog list
  4076. $this->unproxyify ();
  4077.  
  4078. // proxifing the connection
  4079. }else{
  4080. echo '..No proxies';
  4081. }
  4082. }
  4083.  
  4084. /*
  4085. * ---* Clear proxy function ---
  4086. */
  4087. function unproxyify() {
  4088. // clean the connection
  4089. unset ( $this->ch );
  4090.  
  4091. // curl ini
  4092. $this->ch = curl_init ();
  4093. curl_setopt ( $this->ch, CURLOPT_HEADER, 0 );
  4094. curl_setopt ( $this->ch, CURLOPT_RETURNTRANSFER, 1 );
  4095. curl_setopt ( $this->ch, CURLOPT_CONNECTTIMEOUT, 20 );
  4096. curl_setopt ( $this->ch, CURLOPT_TIMEOUT, 30 );
  4097. curl_setopt ( $this->ch, CURLOPT_REFERER, 'http://www.google.com' );
  4098. curl_setopt ( $this->ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8' );
  4099. curl_setopt ( $this->ch, CURLOPT_MAXREDIRS, 5 ); // Good leeway for redirections.
  4100. curl_setopt ( $this->ch, CURLOPT_FOLLOWLOCATION, 1 ); // Many login forms redirect at least once.
  4101. curl_setopt ( $this->ch, CURLOPT_COOKIEJAR, "cookie.txt" );
  4102. }
  4103.  
  4104. /*
  4105. * ---* Spin function that calls TBS ---
  4106. */
  4107. function spin($html) {
  4108.  
  4109. $url = 'http://thebestspinner.com/api.php';
  4110.  
  4111. // $testmethod = 'identifySynonyms';
  4112. $testmethod = 'replaceEveryonesFavorites';
  4113.  
  4114. // Build the data array for authenticating.
  4115.  
  4116. $data = array ();
  4117. $data ['action'] = 'authenticate';
  4118. $data ['format'] = 'php'; // You can also specify 'xml' as the format.
  4119.  
  4120. // The user credentials should change for each UAW user with a TBS account.
  4121. $tbs_username = get_option ( 'wp_automatic_tbs', '' ); // "gigoftheday@gmail.com"; // Enter your The Best Spinner's Email ID
  4122. $tbs_password = get_option ( 'wp_automatic_tbs_p', '' ); // "nd8da759a40a551b9aafdc87a1d902f3d"; // Enter your The Best Spinner's Password
  4123. $tbs_protected = get_option ('wp_automatic_tbs_protected','');
  4124.  
  4125. if(trim($tbs_protected) != ''){
  4126. $tbs_protected = explode("\n", $tbs_protected);
  4127. $tbs_protected = array_filter($tbs_protected);
  4128. $tbs_protected = array_map('trim', $tbs_protected);
  4129.  
  4130. $tbs_protected = array_filter($tbs_protected);
  4131.  
  4132. $tbs_protected = implode(',', $tbs_protected);
  4133. }
  4134.  
  4135. //add , if not exists
  4136. if(! stristr($tbs_protected, ',') ){
  4137. $tbs_protected = $tbs_protected .',';
  4138. }
  4139.  
  4140. //add ad_1, ad_2 , numbers
  4141. $tbs_protected = $tbs_protected . 'ad_1,ad_2,0,1,2,3,4,5,6,7,8,9,';
  4142. $data ['protectedterms'] = $tbs_protected;
  4143.  
  4144. if (trim ( $tbs_username ) == '' || trim ( $tbs_password ) == '') {
  4145. //$this->log ( 'Info', 'No BTS account found , it is highly recommended ' );
  4146. return $html;
  4147. }
  4148.  
  4149. $data ['username'] = $tbs_username;
  4150. $data ['password'] = $tbs_password;
  4151.  
  4152. // Authenticate and get back the session id.
  4153. // You only need to authenticate once per session.
  4154. // A session is good for 24 hours.
  4155. $output = unserialize ( $this->curl_post ( $url, $data, $info ) );
  4156.  
  4157. if ($output ['success'] == 'true') {
  4158.  
  4159. $this->log ( 'TBS', "TBS Login success" );
  4160. echo '<br>TBS Login success';
  4161. // Success.
  4162. $session = $output ['session'];
  4163.  
  4164. // Build the data array for the example.
  4165. $data = array ();
  4166. $data ['session'] = $session;
  4167. $data ['format'] = 'php'; // You can also specify 'xml' as the format.
  4168.  
  4169. //instantiate original html
  4170. $newhtml = $html;
  4171.  
  4172. //replace nospins with astrics
  4173. preg_match_all('{\[nospin.*?\/nospin\]}s', $html ,$nospins);
  4174. $nospins = $nospins[0];
  4175.  
  4176. //shortcodes
  4177. preg_match_all('{\[.*?]}s', $html ,$shortcodes);
  4178. $shortcodes = $shortcodes[0];
  4179.  
  4180. //html
  4181. preg_match_all("/<[^<>]+>/is",$html,$matches,PREG_PATTERN_ORDER);
  4182. $htmlfounds=$matches[0];
  4183.  
  4184. //js
  4185. preg_match_all("/<script.*?<\/script>/is",$html,$matches3,PREG_PATTERN_ORDER);
  4186. $js=$matches3[0];
  4187.  
  4188. //numbers
  4189. preg_match_all("{\d\d+}is", $html,$numMatches);
  4190. $numFounds = ($numMatches[0]);
  4191. $numFounds = array_filter(array_unique($numFounds));
  4192.  
  4193. usort($numFounds,'wp_automatic_sort');
  4194.  
  4195. $nospins = array_merge($nospins,$shortcodes,$htmlfounds,$js,$numFounds,array(9,8,7,6,5,4,3,2,1));
  4196.  
  4197. //remove empty and duplicate
  4198. $nospins = array_filter(array_unique($nospins));
  4199.  
  4200. //replace nospin parts with astrics
  4201. $i=1;
  4202. foreach ($nospins as $nospin){
  4203. $newhtml = str_replace($nospin, '['.str_repeat('*', $i).']', $newhtml);
  4204. $i++;
  4205. }
  4206.  
  4207. $data ['text'] = ( html_entity_decode($newhtml) );
  4208.  
  4209.  
  4210. //$data ['text'] = 'test <br> word <a href="http://onetow.com">http://onetow.com</a> ';
  4211.  
  4212. $data ['action'] = $testmethod;
  4213. $data ['maxsyns'] = '100'; // The number of synonyms per term.
  4214.  
  4215. if ($testmethod == 'replaceEveryonesFavorites') {
  4216. // Add a quality score for this method.
  4217. $data ['quality'] = '1';
  4218. }
  4219.  
  4220. // Post to API and get back results.
  4221. $output = $this->curl_post ( $url, $data, $info );
  4222. $output = unserialize ( $output );
  4223.  
  4224. // Show results.
  4225. // echo "<p><b>Method:</b><br>$testmethod</p>";
  4226. // echo "<p><b>Text:</b><br>$data[text]</p>";
  4227.  
  4228. if ($output ['success'] == 'true') {
  4229. $this->log ( 'TBS', "TBS Successfully spinned the content" );
  4230.  
  4231.  
  4232. //replace the astrics with nospin tags
  4233. if( count($nospins) > 0 ){
  4234.  
  4235. $i = 1 ;
  4236.  
  4237. foreach($nospins as $nospin){
  4238.  
  4239. $output ['output'] = str_replace('['.str_repeat('*', $i).']', $nospin, $output ['output']);
  4240.  
  4241. $i++;
  4242. }
  4243.  
  4244.  
  4245. }
  4246.  
  4247.  
  4248. echo '<br>TBS Successfully spinned the content';
  4249. return $output ['output'];
  4250. } else {
  4251.  
  4252.  
  4253. $this->log ( 'error', "TBS Returned an error:$output[error]" );
  4254. echo "TBS Returned an error:$output[error]";
  4255. return $html;
  4256. }
  4257. } else {
  4258. // There were errors.
  4259. echo "<br>TBS returned an error : $output[error]";
  4260. $this->log ( 'error', "TBS returned an error : $output[error]" );
  4261. return $html;
  4262. }
  4263. } // end function
  4264.  
  4265. /*
  4266. * gtranslte function
  4267. */
  4268. function gtranslate($title, $content, $from, $to , $translationMethod = 'microsoftTranslator') {
  4269.  
  4270.  
  4271. // Verify API data
  4272. if($translationMethod == 'microsoftTranslator'){
  4273.  
  4274. //$wp_automatic_mt_secret = trim(get_option('wp_automatic_mt_secret',''));
  4275. $wp_automatic_mt_id = trim(get_option('wp_automatic_mt_key',''));
  4276.  
  4277. if(trim($wp_automatic_mt_id) == ''){
  4278. echo '<br><span style="color:red">Microsoft translator settings required. Visit the plugin settings and set it.</span>';
  4279. return array($title,$content);
  4280. }
  4281.  
  4282. $titleSeparator = '[19459000]';
  4283.  
  4284. }else{
  4285.  
  4286. $titleSeparator = '##########';
  4287. $titleSeparator = "\n[19459000]";
  4288.  
  4289. }
  4290.  
  4291. // Fix Norwegian language Translation
  4292. if($from == 'nor') $from = 'no';
  4293. if($to == 'nor') $to = 'no';
  4294.  
  4295. // Report Translate
  4296. echo '<br>Translating from '.$from . ' to '.$to . ' using '.$translationMethod;
  4297.  
  4298. // Concat title and content in one text
  4299. $text = $title . $titleSeparator . $content;
  4300.  
  4301. if($this->debug == true) echo "\n\n--- Translation text-------\n".$text;
  4302.  
  4303. //decode html for chars like &euro;
  4304. $text = html_entity_decode($text);
  4305.  
  4306. // STRIP html and links
  4307. preg_match_all ( "/<[^<>]+>/is", $text, $matches, PREG_PATTERN_ORDER );
  4308. $htmlfounds = array_filter( array_unique($matches [0]));
  4309. $htmlfounds[] = '&quot;';
  4310.  
  4311. // Fix alt tags
  4312. $imgFoundsSeparated = array();
  4313. foreach($htmlfounds as $key => $currentFound){
  4314.  
  4315. if(stristr($currentFound, '<img') && stristr($currentFound, 'alt')){
  4316.  
  4317. $altSeparator = '';
  4318. $colonSeparator = '';
  4319. if(stristr($currentFound, 'alt="')){
  4320. $altSeparator = 'alt="';
  4321. $colonSeparator = '"';
  4322. }elseif(stristr($currentFound, 'alt = "')){
  4323. $altSeparator = 'alt = "';
  4324. $colonSeparator = '"';
  4325. }elseif(stristr($currentFound, 'alt ="')){
  4326. $altSeparator = 'alt ="';
  4327. $colonSeparator = '"';
  4328. }elseif(stristr($currentFound, 'alt= "')){
  4329. $altSeparator = 'alt= "';
  4330. $colonSeparator = '"';
  4331. }elseif(stristr($currentFound, 'alt=\'')){
  4332. $altSeparator = 'alt=\'';
  4333. $colonSeparator = '\'';
  4334. }elseif(stristr($currentFound, 'alt = \'')){
  4335. $altSeparator = 'alt = \'';
  4336. $colonSeparator = '\'';
  4337. }elseif(stristr($currentFound, 'alt= \'')){
  4338. $altSeparator = 'alt= \'';
  4339. $colonSeparator = '\'';
  4340. }elseif(stristr($currentFound, 'alt =\'')){
  4341. $altSeparator = 'alt =\'';
  4342. $colonSeparator = '\'';
  4343. }
  4344.  
  4345. if(trim($altSeparator) != ''){
  4346.  
  4347. $currentFoundParts = explode($altSeparator, $currentFound);
  4348.  
  4349. $preAlt = $currentFoundParts[1];
  4350. $preAltParts = explode($colonSeparator, $preAlt);
  4351. $altText = $preAltParts[0];
  4352.  
  4353. if(trim($altText) != ''){
  4354.  
  4355. unset($preAltParts[0]);
  4356. $imgFoundsSeparated[] = $currentFoundParts[0].$altSeparator;
  4357. $imgFoundsSeparated[] = str_replace($altText, '', $currentFoundParts[1]);
  4358.  
  4359. /*
  4360. echo ' ImageFound:'.$in.' '.$currentFound;
  4361. print_r($currentFoundParts);
  4362. print_r($imgFoundsSeparated); */
  4363.  
  4364. $htmlfounds[$key] = '';
  4365.  
  4366. }
  4367. }
  4368. }
  4369. }
  4370.  
  4371. if(count($imgFoundsSeparated) != 0){
  4372. $htmlfounds = array_merge($htmlfounds,$imgFoundsSeparated);
  4373. }
  4374.  
  4375. //<!-- <br> -->
  4376. preg_match_all ( "/<\!--.*?-->/is", $text, $matches2, PREG_PATTERN_ORDER );
  4377. $newhtmlfounds = $matches2[0];
  4378.  
  4379. //strip shortcodes
  4380. preg_match_all ( "/\[.*?\]/is", $text, $matches3, PREG_PATTERN_ORDER );
  4381. $shortcodesfounds = $matches3[0];
  4382.  
  4383. $htmlfounds=array_merge($htmlfounds,$newhtmlfounds,$shortcodesfounds);
  4384.  
  4385. //clean title separator & empties
  4386. $in=0;
  4387. $cleanHtmlFounds = array();
  4388. foreach ($htmlfounds as $htmlfound){
  4389.  
  4390. if($htmlfound == '[19459000]') {
  4391.  
  4392. }elseif(trim($htmlfound) == ''){
  4393.  
  4394. }else{
  4395. $cleanHtmlFounds[] = $htmlfound;
  4396. }
  4397.  
  4398. }
  4399.  
  4400. $htmlfounds = $cleanHtmlFounds;
  4401.  
  4402.  
  4403.  
  4404. // Replace founds by numbers
  4405. $start = 19459001;
  4406. foreach ( $htmlfounds as $htmlfound ) {
  4407. $text = str_replace ( $htmlfound, '[' . $start . ']', $text );
  4408. $start++;
  4409. }
  4410.  
  4411. // .{ replace with . {
  4412. $text = str_replace('.{', '. {', $text);
  4413.  
  4414. //group consequent matchs [19459003][19459003][19459004][19459003]
  4415. preg_match_all('!(?:\[1945\d*\][\s]*){2,}!s', $text,$conseqMatchs);
  4416.  
  4417. if($this->debug == true) {
  4418. echo "\n\n--- Html finds-------\n";
  4419. print_r($htmlfounds);
  4420. echo "\n\n----- Html before consequent replacements-----\n".$text;
  4421.  
  4422. echo "\n\n--- Consequent masks finds-------\n";
  4423. print_r($conseqMatchs);
  4424.  
  4425. }
  4426.  
  4427. //replacing consequents
  4428. $startConseq = 19659001 ;
  4429. foreach ($conseqMatchs[0] as $conseqMatch){
  4430. $text = str_replace($conseqMatch, '['.$startConseq.']', $text);
  4431. $startConseq++;
  4432. }
  4433.  
  4434. if($this->debug == true) {
  4435.  
  4436. echo "\n\n----- Content to translate-----\n".$text;
  4437.  
  4438. }
  4439.  
  4440.  
  4441.  
  4442.  
  4443. // Check Translation Method and use it
  4444.  
  4445. if( $translationMethod == 'googleTranslator' ){
  4446.  
  4447. try {
  4448.  
  4449. // Google Translator Class
  4450. require_once 'inc/translator.Google.php';
  4451.  
  4452. // Google Translator Object
  4453. $GoogleTranslator = new GoogleTranslator($this->ch);
  4454.  
  4455. // Translate Method
  4456. $translated = $GoogleTranslator->translateText($text, $from, $to);
  4457.  
  4458. // same language error The page you have attempted to translate is already
  4459. if(stristr($translated, 'The page you have attempted to translate is already')){
  4460. echo '<br>Google refused to translate and tells that the article is in the same laguage';
  4461. $translated=$text;
  4462. }
  4463.  
  4464. if($this->debug == true) { echo "\n\n\n\n--- Returned translation-------\n".$translated."\n\n\n" ;}
  4465.  
  4466. } catch (Exception $e) {
  4467.  
  4468. echo 'Exception:'.$e->getMessage();
  4469.  
  4470. $this->translationSuccess = false ;
  4471.  
  4472. return array($title,$content);
  4473. }
  4474.  
  4475.  
  4476. }else{
  4477.  
  4478. // Translating using Microsoft translator
  4479. require_once 'inc/translator.Microsoft.php';
  4480.  
  4481. $MicrosoftTranslator = new MicrosoftTranslator($this->ch);
  4482.  
  4483. try {
  4484.  
  4485. // Generate access token
  4486. $accessToken = $MicrosoftTranslator->getToken($wp_automatic_mt_id);
  4487.  
  4488. echo '<br>Translated text chars: '. $this->chars_count($text);
  4489.  
  4490. $translated = $MicrosoftTranslator->translateWrap($text, $from, $to);
  4491.  
  4492.  
  4493. } catch (Exception $e) {
  4494.  
  4495. echo '<br>Translation error:'.$e->getMessage();
  4496.  
  4497. $this->translationSuccess = false ;
  4498.  
  4499. return array($title,$content);
  4500.  
  4501. }
  4502.  
  4503. }
  4504.  
  4505.  
  4506.  
  4507. // Fix broken ] 19459
  4508. $translated = preg_replace('{]\s*?1945}' , '][1945', $translated);
  4509.  
  4510. // Fix broken Add Comment 19459012]
  4511. $translated = preg_replace('{ 19459(\d*?)]}' , ' [19459$1]', $translated);
  4512.  
  4513. // Fix [[1945
  4514. $translated = str_replace('[ [1945', '[1945', $translated);
  4515.  
  4516. // Fix ], [
  4517. $translated = str_replace('], ', ']', $translated);
  4518.  
  4519. //file_put_contents( dirname(__FILE__) .'/test.txt' , $translated);
  4520.  
  4521. if($this->debug == true) { echo '<br>--- Fixed translation-------'; print_r($translated);}
  4522.  
  4523. // restore consquent masks
  4524. $startConseq = 19659001 ;
  4525. foreach ($conseqMatchs[0] as $conseqMatch){
  4526. $translated = str_replace( '['.$startConseq.']', $conseqMatch,$translated);
  4527. $startConseq++;
  4528. }
  4529.  
  4530.  
  4531. // Grab all replacements with **
  4532. preg_match_all('!\[.*?\]!', $translated,$brackets);
  4533.  
  4534. $brackets = $brackets[0];
  4535. $brackets = array_unique($brackets);
  4536.  
  4537.  
  4538. foreach ($brackets as $bracket){
  4539. if(stristr($bracket, '19')){
  4540.  
  4541. $corrrect_bracket = str_replace(' ', '', $bracket);
  4542. $corrrect_bracket = str_replace('.', '', $corrrect_bracket);
  4543. $corrrect_bracket = str_replace(',', '', $corrrect_bracket);
  4544.  
  4545. $translated = str_replace($bracket, $corrrect_bracket, $translated);
  4546.  
  4547. }
  4548. }
  4549.  
  4550.  
  4551. // check if successful translation contains ***
  4552. if (stristr ( $translated, trim($titleSeparator) )) {
  4553.  
  4554. $this->translationSuccess = true ;
  4555.  
  4556. // restore html tags
  4557. $start = 19459001;
  4558. foreach ( $htmlfounds as $htmlfound ) {
  4559. $translated = str_replace ( '[' . $start . ']', $htmlfound, $translated );
  4560. $start ++;
  4561. }
  4562.  
  4563.  
  4564. $contents = explode ( trim($titleSeparator), $translated );
  4565. $title = $contents [0];
  4566. $content = $contents [1];
  4567. } else {
  4568.  
  4569. $this->translationSuccess = false ;
  4570.  
  4571. echo '<br>Translation failed ';
  4572.  
  4573. }
  4574.  
  4575. return array (
  4576. $title,
  4577. $content
  4578. );
  4579. }
  4580. function curl_post($url, $data, &$info) {
  4581. $ch = curl_init ();
  4582.  
  4583.  
  4584. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
  4585. curl_setopt($ch, CURLOPT_TIMEOUT,20);
  4586. curl_setopt ( $ch, CURLOPT_URL, $url );
  4587. curl_setopt ( $ch, CURLOPT_POST, true );
  4588. curl_setopt ( $ch, CURLOPT_POSTFIELDS, $this->curl_postData ( $data ) );
  4589. curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, true );
  4590. curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
  4591. curl_setopt ( $ch, CURLOPT_REFERER, $url );
  4592. $html = trim ( curl_exec ( $ch ) );
  4593.  
  4594. print_r(curl_error($ch));
  4595.  
  4596. return $html;
  4597. }
  4598. function curl_postData($data) {
  4599. $fdata = "";
  4600. foreach ( $data as $key => $val ) {
  4601. $fdata .= "$key=" . urlencode ( $val ) . "&";
  4602. }
  4603.  
  4604. return $fdata;
  4605. }
  4606.  
  4607. /*
  4608. * ---* update cb categories ---
  4609. */
  4610. function update_categories() {
  4611. // Get
  4612. $x = 'error';
  4613. while ( trim ( $x ) != '' ) {
  4614. $url = 'http://www.clickbank.com/advancedMarketplaceSearch.htm';
  4615. curl_setopt ( $this->ch, CURLOPT_HTTPGET, 1 );
  4616. curl_setopt ( $this->ch, CURLOPT_URL, trim ( $url ) );
  4617. $exec = curl_exec ( $this->ch );
  4618. echo $x = curl_error ( $this->ch );
  4619. }
  4620.  
  4621. if (stristr ( $exec, '<option value="">- All categories -</option>' )) {
  4622. echo '<br>categories found';
  4623. preg_match_all ( "{>- All categories -</option>((.|\s)*?)</select>}", $exec, $matches, PREG_PATTERN_ORDER );
  4624.  
  4625. $res = $matches [0];
  4626. $cats = $res [0];
  4627.  
  4628. // extracting single parent categories [<option value="1510">Betting Systems</option>]
  4629. preg_match_all ( "{<option value=\"(.*?)\">(.*?)</option>}", $cats, $matches, PREG_PATTERN_ORDER );
  4630. $paretcats_ids = $matches [1];
  4631. $paretcats_names = $matches [2];
  4632.  
  4633. // delete current records
  4634. if (count ( $paretcats_names ) > 0) {
  4635. $query = "delete from {$this->wp_prefix}automatic_categories ";
  4636. $this->db->query ( $query );
  4637. }
  4638.  
  4639. // adding parent categories
  4640. $i = 0;
  4641. foreach ( $paretcats_ids as $parentcat_id ) {
  4642.  
  4643. $parentcat_name = $paretcats_names [$i];
  4644.  
  4645. // inserting cats
  4646. $query = "insert into {$this->wp_prefix}automatic_categories (cat_id , cat_name) values ('$parentcat_id','$parentcat_name')";
  4647. $this->db->query ( $query );
  4648. $i ++;
  4649. }
  4650.  
  4651. echo '<br>Parent Categories added:' . $i;
  4652.  
  4653. // extracting subcategories
  4654. /*
  4655. * <option value="1265" parent="1253" path="Arts & Entertainment &raquo; Architecture"> Architecture </option>
  4656. */
  4657.  
  4658. // echo $exec;
  4659. // exit;
  4660. preg_match_all ( "{<option value=\"(.*?)\" parent=\"(.*?)\"(.|\s)*?>((.|\s)*?)</option>}", $exec, $matches, PREG_PATTERN_ORDER );
  4661. $subcats_ids = $matches [1];
  4662. $subcats_parents = $matches [2];
  4663. $subcats_names = $matches [4];
  4664.  
  4665. $i = 0;
  4666. foreach ( $subcats_ids as $subcats_id ) {
  4667. $subcats_names [$i] = trim ( $subcats_names [$i] );
  4668. $subcats_parents [$i] = trim ( $subcats_parents [$i] );
  4669. $query = "insert into {$this->wp_prefix}automatic_categories(cat_id,cat_parent,cat_name) values('$subcats_id','$subcats_parents[$i]','$subcats_names[$i]')";
  4670. $this->db->query ( $query );
  4671. $i ++;
  4672. }
  4673.  
  4674. echo '<br>Sub Categories added ' . $i;
  4675.  
  4676. // print_r($matches);
  4677. exit ();
  4678.  
  4679. $res = $matches [2];
  4680. $form = $res [0];
  4681.  
  4682. preg_match_all ( "{<option value=\"(.*?)\" parent=\"(.*?)\"}", $exec, $matches, PREG_PATTERN_ORDER );
  4683.  
  4684. print_r ( $matches );
  4685.  
  4686. // print_r($matches);
  4687. exit ();
  4688. $res = $matches [0];
  4689. $cats = $res [0];
  4690. }
  4691. }
  4692.  
  4693. /*
  4694. * ---* Proxy Frog Integration ---
  4695. */
  4696. function alb_proxyfrog() {
  4697.  
  4698. // get the current list
  4699. $proxies = get_option ( 'alb_proxy_list' );
  4700.  
  4701. // no proxies
  4702. echo '<br>Need new valid proxies';
  4703.  
  4704. if (function_exists ( 'proxyfrogfunc' )) {
  4705. echo '<br>Getting New Proxy List from ProxyFrog.me';
  4706. // Get
  4707. $x = 'error';
  4708.  
  4709. $ch = curl_init ();
  4710. curl_setopt ( $ch, CURLOPT_HEADER, 0 );
  4711. curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
  4712. curl_setopt ( $ch, CURLOPT_CONNECTTIMEOUT, 10 );
  4713. curl_setopt ( $ch, CURLOPT_TIMEOUT, 20 );
  4714. curl_setopt ( $ch, CURLOPT_REFERER, 'http://www.bing.com/' );
  4715. curl_setopt ( $ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8' );
  4716. curl_setopt ( $ch, CURLOPT_MAXREDIRS, 5 ); // Good leeway for redirections.
  4717. curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, 0 ); // Many login forms redirect at least once.
  4718. curl_setopt ( $ch, CURLOPT_COOKIEJAR, "cookie.txt" );
  4719.  
  4720. // Get
  4721. // license
  4722. $paypal = get_option ( 'pf_license' );
  4723. $paypal = urlencode ( $paypal );
  4724. $url = "http://proxyfrog.me/proxyfrog/api.php?email=$paypal";
  4725. curl_setopt ( $ch, CURLOPT_HTTPGET, 1 );
  4726. curl_setopt ( $ch, CURLOPT_URL, trim ( $url ) );
  4727. $exec = curl_exec ( $ch );
  4728.  
  4729. // echo $exec;
  4730.  
  4731. if (stristr ( $exec, ':' )) {
  4732. update_option ( 'be_proxy_list', $exec );
  4733. update_option ( 'alb_proxy_list', $exec );
  4734. echo '<br>New Proxy List <b>Added successfully</b> ';
  4735. $this->log ( 'ProxyFrog', "New Proxy list added from ProxyFrog" );
  4736. return true;
  4737. } else {
  4738. $this->log ( 'ProxyFrog', $exec );
  4739. }
  4740. } else {
  4741.  
  4742. return false;
  4743. }
  4744. } // end fun
  4745.  
  4746. /*
  4747. * ---* Logging Function ---
  4748. */
  4749. function log($type, $data) {
  4750. // $now= date("F j, Y, g:i a");
  4751. $now = date ( 'Y-m-d H:i:s' );
  4752. $data = @addslashes ( $data );
  4753.  
  4754.  
  4755. $query = "INSERT INTO {$this->wp_prefix}automatic_log (action,date,data) values('$type','$now','$data')";
  4756.  
  4757.  
  4758.  
  4759. // echome$query;
  4760. $this->db->query ( $query );
  4761.  
  4762. $insert = $this->db->insert_id;
  4763.  
  4764. $insert_below_100 = $insert -100 ;
  4765.  
  4766. if($insert_below_100 > 0){
  4767. //delete
  4768. $query="delete from {$this->wp_prefix}automatic_log where id < $insert_below_100 and action not like '%Posted%'" ;
  4769. $this->db->query($query);
  4770. }
  4771.  
  4772. }
  4773.  
  4774. /**
  4775. * Function that checks if the current link is already posted
  4776. * @param unknown $link
  4777. */
  4778. function is_duplicate($link_url){
  4779.  
  4780. $duplicate=false;
  4781.  
  4782. // link suffix
  4783. if($this->isLinkSuffixed == true){
  4784. if(stristr($link_url, '?')){
  4785. $link_url = $link_url.'&rand='.$this->currentCampID ;
  4786. }else{
  4787. $link_url = $link_url.'?rand='.$this->currentCampID ;
  4788. }
  4789. }
  4790.  
  4791. // Find items from the duplicate cache
  4792. if( ! $this->campOldDuplicateLinksFetched){
  4793. $this->campOldDuplicateLinks = get_post_meta($this->currentCampID,'wp_automatic_duplicate_cache',1);
  4794.  
  4795. //array it
  4796. if(! is_array($this->campOldDuplicateLinks)) $this->campOldDuplicateLinks = array();
  4797.  
  4798. $this->campOldDuplicateLinksFetched = true;
  4799. }
  4800.  
  4801. $possibleID = array_search($link_url, $this->campOldDuplicateLinks ) ;
  4802.  
  4803. if( $possibleID != false ){
  4804.  
  4805. $duplicate = true;
  4806. $this->duplicate_id = $possibleID;
  4807. }
  4808.  
  4809. // Find items with meta = this url
  4810. if( ! $duplicate ){
  4811.  
  4812. $query = "SELECT post_id from {$this->wp_prefix}postmeta where meta_value='$link_url' ";
  4813. $pres = $this->db->get_results ( $query );
  4814.  
  4815. //double check again
  4816. if(count ( $pres ) == 0 ){
  4817. $pres = $this->db->get_results ( $query );
  4818. }
  4819.  
  4820.  
  4821. if(count ( $pres ) == 0 ){
  4822. $duplicate = false;
  4823. }else{
  4824.  
  4825. $duplicate = true;
  4826.  
  4827. foreach($pres as $prow){
  4828.  
  4829. $ppid=$prow->post_id;
  4830. $this->duplicate_id = $ppid;
  4831.  
  4832. $pstatus = get_post_status($ppid);
  4833.  
  4834. if($pstatus != 'trash') {
  4835. break;
  4836. }
  4837. }
  4838.  
  4839. }
  4840.  
  4841. }
  4842.  
  4843. // Check if completely deleted
  4844. if( ! $duplicate ){
  4845.  
  4846. $md5 = md5($link_url);
  4847. $query = "SELECT link_url from {$this->wp_prefix}automatic_links where link_url='$md5' ";
  4848. $pres = $this->db->get_results ( $query );
  4849.  
  4850. if ( count($pres) != 0){
  4851. $duplicate = true;
  4852. $this->duplicate_id = 'Deleted' ;
  4853. }
  4854.  
  4855. }
  4856.  
  4857. // Update Duplicate cache
  4858. if($duplicate == true){
  4859.  
  4860. // duplicated url, add it to the duplicate cache array
  4861. if(is_numeric($this->duplicate_id)){
  4862. $this->campNewDuplicateLinks[$this->duplicate_id] = $link_url;
  4863. $this->campDuplicateLinksUpdate = true;
  4864. }
  4865.  
  4866. }
  4867.  
  4868. return $duplicate;
  4869. }
  4870.  
  4871. /**
  4872. * Function link exclude to execlude links
  4873. * @param unknown $camp_id
  4874. * @param unknown $source_link
  4875. */
  4876. function link_execlude($camp_id,$source_link){
  4877.  
  4878. if($this->campExcludedLinksFetched == true){
  4879. $execluded_links = $this->campExcludedLinks;
  4880. }else{
  4881.  
  4882. $execluded_links = get_post_meta($camp_id,'_execluded_links',1);
  4883. $this->campExcludedLinks = $execluded_links;
  4884. $this->campExcludedLinksFetched = true;
  4885. }
  4886.  
  4887. $newExecluded_links = $execluded_links.','.$source_link;
  4888. update_post_meta($camp_id,'_execluded_links', $newExecluded_links );
  4889. $this->campExcludedLinks = $newExecluded_links;
  4890.  
  4891.  
  4892. }
  4893.  
  4894. /**
  4895. * Check if link is execluded or not i.e it didn't contain exact match keys or contins blocked keys
  4896. * @param unknown $camp_id
  4897. * @param unknown $link
  4898. */
  4899. function is_execluded($camp_id,$link){
  4900.  
  4901. if($this->campExcludedLinksFetched == true){
  4902. $execluded_links = $this->campExcludedLinks;
  4903. }else{
  4904. $execluded_links = get_post_meta($camp_id,'_execluded_links',1);
  4905. $this->campExcludedLinks = $execluded_links;
  4906. $this->campExcludedLinksFetched = true;
  4907. }
  4908.  
  4909. if(stristr(','.$execluded_links, $link )){
  4910. return true;
  4911. }else{
  4912. return false;
  4913. }
  4914.  
  4915. }
  4916.  
  4917. /**
  4918. * function cache_image
  4919. * return local image src if found
  4920. * return false if not cached
  4921. */
  4922. function is_cached($remote_img,$data_md5){
  4923.  
  4924. //md5
  4925. $md5=md5($remote_img);
  4926.  
  4927. //query database for this image
  4928.  
  4929. $query="SELECT * FROM {$this->db->prefix}automatic_cached where img_hash='$md5' and img_data_hash='$data_md5' limit 1";
  4930.  
  4931.  
  4932. $rows=$this->db->get_results($query);
  4933.  
  4934. if(count($rows) == 0 ) return false;
  4935. $row=$rows[0];
  4936.  
  4937. //hm we have cached image with previous same source let's compare
  4938. $local_src = $row->img_internal;
  4939.  
  4940. //make sure current image have same data md5 right now otherwise delete
  4941. //curl get
  4942. curl_setopt($this->ch, CURLOPT_HTTPGET, 1);
  4943. curl_setopt($this->ch, CURLOPT_URL, trim($local_src));
  4944. $exec=curl_exec($this->ch);
  4945.  
  4946. if(md5($exec) == $data_md5) {
  4947.  
  4948. $this->cached_file_path = $row->img_path;
  4949.  
  4950. return $local_src;
  4951. }else{
  4952.  
  4953. //now the local image no more giving the same md5 may be deleted or changed delete the record
  4954. $query="delete from {$this->db->prefix}automatic_cached where img_hash = '$md5' ";
  4955. $this->db->query($query);
  4956.  
  4957. return false;
  4958. }
  4959.  
  4960.  
  4961.  
  4962. }
  4963.  
  4964. /**
  4965. *
  4966. * @param unknown $remote_img
  4967. * @param unknown $local_img
  4968. * @param number $thumb_id
  4969. */
  4970.  
  4971. function img_cached($remote_img,$local_img,$image_data_md5,$file_path ){
  4972.  
  4973. $md5= md5($remote_img);
  4974. $query="insert into {$this->db->prefix}automatic_cached(img_external,img_internal,img_hash,img_data_hash,img_path) values ('$remote_img','$local_img','$md5','$image_data_md5','$file_path')";
  4975. $this->db->query($query);
  4976.  
  4977.  
  4978. }
  4979.  
  4980. /**
  4981. * deactivate keyword : set the reactivation time to one comig hour
  4982. * @param integer $camp_id
  4983. * @param string $keyword
  4984. */
  4985. function deactivate_key($camp_id,$keyword,$seconds= 3600){
  4986.  
  4987. $deactivatedUntill = time('now') + $seconds ;
  4988.  
  4989. if($seconds == 0) $deactivatedUntill = 0 ;
  4990.  
  4991. update_post_meta($camp_id, '_'.md5($keyword), $deactivatedUntill );
  4992.  
  4993. }
  4994.  
  4995. /**
  4996. * is_deactivated: check if the current deactivated keyword is still deactivated or not
  4997. * if yes it return false
  4998. * if not deactivated return true
  4999. * @param integer $camp_id
  5000. * @param string $key
  5001. */
  5002. function is_deactivated($camp_id,$keyword){
  5003.  
  5004. //let's see if this keyword deactivated till date or not
  5005. $keyword_key = '_'.md5($keyword) ;
  5006. $deactivated_till = get_post_meta($camp_id,$keyword_key,1);
  5007. if(trim($deactivated_till) == '') $deactivated_till = 1410020931;
  5008.  
  5009. if($deactivated_till == 0){
  5010.  
  5011. //still deactivated
  5012. echo '<br>Calling source for this keyword is <strong>deactivated</strong> permanently because last time we called the source for new items, There were no more results to get. You can still <a class="wp_automatic_key_reactivate" data-id="'.$camp_id.'" data-key="'. $keyword_key . '" href="#"><u>Reactivate Now.</u></a><span class="spinner_'.$keyword_key.' spinner"></span>' ;
  5013. return false;
  5014.  
  5015. }if(time('now') > $deactivated_till ){
  5016. //time passed let's reactivate
  5017. echo '<br>Keyword search reached end page lets sart from first page again ';
  5018. return true;
  5019. }else{
  5020.  
  5021. //still deactivated
  5022. echo '<br>Calling source for this keyword is <strong>deactivated</strong> temporarily because last time we called the source for new items, There were no more results to get. We will reactivate it after '. number_format(( $deactivated_till - time('now') ) /60 , 2 ) . ' minutes. You can still <a class="wp_automatic_key_reactivate" data-id="'.$camp_id.'" data-key="'. $keyword_key . '" href="#"><u>Reactivate Now.</u></a><span class="spinner_'.$keyword_key.' spinner"></span>' ;
  5023. return false;
  5024. }
  5025.  
  5026. }
  5027.  
  5028. /**
  5029. * Function is_link_old check if the timestamp for the link is older than minimum
  5030. * @param unknown $camp_id
  5031. * @param unknown $link_timestamp
  5032. */
  5033. function is_link_old($camp_id , $link_timestamp){
  5034.  
  5035. if($this->debug == true) echo '<br>is_link_old Minimum:'.$this->minimum_post_timestamp . ' Current:'.$link_timestamp;
  5036.  
  5037. if($this->minimum_post_timestamp_camp == $camp_id ){
  5038. if($link_timestamp < $this->minimum_post_timestamp){
  5039. return true;
  5040. }else{
  5041. return false;
  5042. }
  5043. }
  5044. }
  5045.  
  5046. /**
  5047. * function is_title_duplicate
  5048. * @param unknown $title
  5049. */
  5050. function is_title_duplicate($title,$post_type){
  5051.  
  5052. /*
  5053. echo ' title is:'.$title;
  5054.  
  5055. var_dump(get_page_by_title( $title, 'OBJECT', $post_type ));
  5056.  
  5057. exit;*/
  5058.  
  5059. if( get_page_by_title( $title, 'OBJECT', $post_type ) ){
  5060.  
  5061. return true;
  5062.  
  5063. }else{
  5064. return false;
  5065. }
  5066. }
  5067.  
  5068. /*
  5069. * ---* validating ---
  5070. */
  5071. function validate() {
  5072. $paypal = get_option ( 'alb_license', '' );
  5073. $active = get_option ( 'alb_license_active', '' );
  5074. $link = 'http://wpplusone.com/trafficautomator/activate.php';
  5075.  
  5076. // no license
  5077. if (trim ( $paypal ) == '') {
  5078. $this->log ( 'Error', 'License Required please visit settings and add the paypal email you used to purchase the product' );
  5079. exit ();
  5080. }
  5081.  
  5082. // cehck validety
  5083. if (trim ( $active ) != '1') {
  5084. // first time activation
  5085. // opening the page using curl
  5086. $this->c->set ( CURLOPT_URL, trim ( "$link?email=$paypal" ) );
  5087. $this->c->set ( CURLOPT_CONNECTTIMEOUT, 20 );
  5088. $this->c->set ( CURLOPT_TIMEOUT, 50 );
  5089. $this->c->set ( CURLOPT_HTTPGET, 1 );
  5090. $ret = $this->c->execute ();
  5091. $ret = trim ( $ret );
  5092. // when no response
  5093. if ($ret == '') {
  5094. // service not available
  5095. $this->log ( 'Error', 'Could not activate licence at this time may be our server is under maintenance now I will keep try and if the problem exists contact support' );
  5096. exit ();
  5097. } elseif ($ret == '0') {
  5098. // not valid license
  5099. $this->log ( 'Error', 'License is not valid please visit settings and use a valid license please, if you do\'t have a license consider to purchase <a href="http://wpsbox.com/buy">Here</a> and if you have just purchased just hold on our records will update after 10 minutes please be patient' );
  5100. exit ();
  5101. } elseif ($ret == '-1') {
  5102. // Refunded
  5103. $this->log ( 'Error', 'License is not valid a Refund may have been already issued for this license' );
  5104. exit ();
  5105. } elseif ($ret == '1') {
  5106. // valid license
  5107. update_option ( 'alb_license_active', '1' );
  5108. // register last chek
  5109. $date = date ( "m\-d\-y" );
  5110. update_option ( 'alb_license_last', $date );
  5111. } else {
  5112. $this->log ( 'Error', 'License could not be validated at this time, our server may be under maintenance now will try the next cron' );
  5113. exit ();
  5114. }
  5115. } else {
  5116. // license is working without problem we should check again
  5117. $date = date ( "m\-d\-y" );
  5118. $last_check = get_option ( 'alb_license_last', $date );
  5119. $offset = $this->dateDiff ( "-", $date, $last_check );
  5120. if ($offset >= 1) {
  5121. // echo 'checking license again';
  5122. // check again
  5123. // opening the page using curl
  5124. $this->c->set ( CURLOPT_URL, trim ( "$link?email=$paypal" ) );
  5125. $this->c->set ( CURLOPT_CONNECTTIMEOUT, 20 );
  5126. $this->c->set ( CURLOPT_TIMEOUT, 50 );
  5127. $this->c->set ( CURLOPT_HTTPGET, 1 );
  5128. $ret = $this->c->execute ();
  5129. $ret = trim ( $ret );
  5130. // when no response
  5131. if ($ret == '0') {
  5132. // not valid license
  5133. $this->log ( 'Error', 'License is not valid please visit settings and use a valid license please, if you do\'t have a license consider to purchase <a href="http://wpsbox.com/buy">Here</a>' );
  5134. update_option ( 'alb_license_active', '' );
  5135. exit ();
  5136. } elseif ($ret == '-1') {
  5137. // Refunded
  5138. $this->log ( 'Error', 'License is not valid a Refund may have been already issued for this license' );
  5139. update_option ( 'alb_license_active', '' );
  5140. exit ();
  5141. } elseif ($ret == '1') {
  5142. // valid license
  5143. update_option ( 'alb_license_active', '1' );
  5144. // register last chek
  5145. $date = date ( "m\-d\-y" );
  5146. update_option ( 'alb_license_last', $date );
  5147. }
  5148. }
  5149. }
  5150.  
  5151. return true;
  5152. }
  5153.  
  5154. /*
  5155. * ---* Date Difference return days between two dates ---
  5156. */
  5157. function dateDiff($dformat, $endDate, $beginDate) {
  5158. $date_parts1 = explode ( $dformat, $beginDate );
  5159. $date_parts2 = explode ( $dformat, $endDate );
  5160. $start_date = gregoriantojd ( $date_parts1 [0], $date_parts1 [1], $date_parts1 [2] );
  5161. $end_date = gregoriantojd ( $date_parts2 [0], $date_parts2 [1], $date_parts2 [2] );
  5162. return $end_date - $start_date;
  5163. }
  5164.  
  5165. /*
  5166. * ---* Download File ---
  5167. */
  5168. function downloadfile($link) {
  5169. $downloader = $this->plugin_url . 'downloader.php';
  5170. // $downloader='http://localhost/php/wpsbox_aals/downloader.php';
  5171. $link = str_replace ( 'http', 'httpz', $link );
  5172.  
  5173. $enc = urlencode ( $link );
  5174. // $return=file_get_contents($downloader.'?link='.$enc);
  5175. // echo $return ;
  5176.  
  5177. if (stristr ( $return, 'error' )) {
  5178. echo '<br>An Error downloading the <b>damn file</b> :';
  5179. echo ' <i><small>' . $return . '</small></i>';
  5180.  
  5181. return false;
  5182. }
  5183. return true;
  5184. }
  5185.  
  5186. /*
  5187. * ---* Solve captcha function ---
  5188. */
  5189. function solvecap($url) {
  5190. $decap_user = get_option ( 'alb_de_u' );
  5191. $decap_pass = get_option ( 'alb_de_p' );
  5192.  
  5193. // if decap not registered return false
  5194. if (trim ( $decap_user ) == '' || trim ( $decap_pass ) == '') {
  5195. echo '<br>decaptcher.com <b>account needed</b>';
  5196. $this->log ( 'Error', 'Capatcha Met at ' . $proxy . ' , Decapatcher Account needed please register one at decapatcher.com , add balance to it then enter login details at settings tab ' );
  5197. return false;
  5198. }
  5199.  
  5200. // curl ini
  5201. $ch = curl_init ();
  5202. curl_setopt ( $ch, CURLOPT_HEADER, 0 );
  5203. curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
  5204. curl_setopt ( $ch, CURLOPT_CONNECTTIMEOUT, 10 );
  5205. curl_setopt ( $ch, CURLOPT_TIMEOUT, 20 );
  5206. curl_setopt ( $ch, CURLOPT_REFERER, 'http://www.bing.com/' );
  5207. curl_setopt ( $ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8' );
  5208. curl_setopt ( $ch, CURLOPT_MAXREDIRS, 5 ); // Good leeway for redirections.
  5209. curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, 1 ); // Many login forms redirect at least once.
  5210. curl_setopt ( $ch, CURLOPT_COOKIEJAR, "cookie.txt" );
  5211. curl_setopt ( $ch, CURLOPT_URL, trim ( $url ) );
  5212. curl_setopt ( $ch, CURLOPT_HEADER, 0 );
  5213. $img = curl_exec ( $ch );
  5214. if (trim ( $img ) == '')
  5215. return false;
  5216. if (curl_error ( $ch ) != '') {
  5217. echo '<br>Image fetched with error:' . curl_error ( $ch ) . '<br>';
  5218. return false;
  5219. }
  5220.  
  5221. // file_put_contents('files/cap.jpg',$img);
  5222.  
  5223. // positng image to capatcher to get the decapatched version
  5224. curl_setopt ( $ch, CURLOPT_VERBOSE, 0 );
  5225. curl_setopt ( $ch, CURLOPT_URL, 'http://poster.decaptcher.com' );
  5226. curl_setopt ( $ch, CURLOPT_POST, true );
  5227.  
  5228. $decap_acc = '1169';
  5229.  
  5230. $post = array (
  5231. "pict" => "@files/cap.jpg",
  5232. "function" => "picture2",
  5233. "username" => $decap_user,
  5234. "password" => $decap_pass,
  5235. "pict_to" => "0",
  5236. "pict_type" => $decap_acc
  5237. );
  5238. curl_setopt ( $ch, CURLOPT_POSTFIELDS, $post );
  5239. if (curl_error ( $ch ) != '') {
  5240. echo '<br>Captacha Posted with error:' . curl_error ( $ch ) . '<br>';
  5241. return false;
  5242. }
  5243.  
  5244. $decap = curl_exec ( $ch );
  5245. echo '<br>Decap returned:' . $decap;
  5246. // check if decapatcher returned an error -
  5247. if (stristr ( $decap, '-' ) || trim ( $decap ) == '') {
  5248. echo '<br>Decapatcher returned an <b>error</b> ' . $decap;
  5249. $this->log ( 'Error', 'Decapatcher Account Error Please check login details and suffecient balance' );
  5250. return false;
  5251. }
  5252.  
  5253. if (trim ( $decap ) == '')
  5254. return false;
  5255. $decaps = explode ( '|', $decap );
  5256. $decap = $decaps [5];
  5257. if (trim ( $decap ) == '')
  5258. return false;
  5259. echo '<br>Decap Solution:' . $decap;
  5260. return $decap;
  5261. }
  5262.  
  5263. /*
  5264. * ---* Trackback function using wp modification ---
  5265. */
  5266. function trackback($trackback_url, $author, $ttl, $excerpt, $link) {
  5267. $options = array ();
  5268. $options ['timeout'] = 4;
  5269. $options ['body'] = array (
  5270. 'title' => $ttl,
  5271. 'url' => $link,
  5272. 'blog_name' => $author,
  5273. 'excerpt' => $excerpt
  5274. );
  5275.  
  5276. $response = wp_remote_post ( $trackback_url, $options );
  5277.  
  5278. if (is_wp_error ( $response )) {
  5279. echo '<br>Trackback Error';
  5280. return;
  5281. } else {
  5282. echo '<br>No Track back error';
  5283. }
  5284. }
  5285.  
  5286.  
  5287. /*
  5288. * function get_time_difference: get the time difference in minutes.
  5289. * @start: time stamp
  5290. * @end: time stamp
  5291. */
  5292.  
  5293. function get_time_difference( $start, $end )
  5294. {
  5295.  
  5296. $uts['start'] = $start ;
  5297. $uts['end'] = $end ;
  5298.  
  5299.  
  5300.  
  5301. if( $uts['start']!==-1 && $uts['end']!==-1 )
  5302. {
  5303. if( $uts['end'] >= $uts['start'] )
  5304. {
  5305. $diff = $uts['end'] - $uts['start'];
  5306.  
  5307. return round($diff/60,0);
  5308.  
  5309. }
  5310.  
  5311. }
  5312. }
  5313.  
  5314. function truncateHtml($text, $length = 100, $ending = '...', $exact = false, $considerHtml = true) {
  5315. if ($considerHtml) {
  5316. // if the plain text is shorter than the maximum length, return the whole text
  5317. if (strlen(preg_replace('/<.*?>/', '', $text)) <= $length) {
  5318. return $text;
  5319. }
  5320. // splits all html-tags to scanable lines
  5321. preg_match_all('/(<.+?>)?([^<>]*)/s', $text, $lines, PREG_SET_ORDER);
  5322. $total_length = strlen($ending);
  5323. $open_tags = array();
  5324. $truncate = '';
  5325. foreach ($lines as $line_matchings) {
  5326. // if there is any html-tag in this line, handle it and add it (uncounted) to the output
  5327. if (!empty($line_matchings[1])) {
  5328. // if it's an "empty element" with or without xhtml-conform closing slash
  5329. if (preg_match('/^<(\s*.+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s.+?)?)>$/is', $line_matchings[1])) {
  5330. // do nothing
  5331. // if tag is a closing tag
  5332. } else if (preg_match('/^<\s*\/([^\s]+?)\s*>$/s', $line_matchings[1], $tag_matchings)) {
  5333. // delete tag from $open_tags list
  5334. $pos = array_search($tag_matchings[1], $open_tags);
  5335. if ($pos !== false) {
  5336. unset($open_tags[$pos]);
  5337. }
  5338. // if tag is an opening tag
  5339. } else if (preg_match('/^<\s*([^\s>!]+).*?>$/s', $line_matchings[1], $tag_matchings)) {
  5340. // add tag to the beginning of $open_tags list
  5341. array_unshift($open_tags, strtolower($tag_matchings[1]));
  5342. }
  5343. // add html-tag to $truncate'd text
  5344. $truncate .= $line_matchings[1];
  5345. }
  5346. // calculate the length of the plain text part of the line; handle entities as one character
  5347. $content_length = strlen(preg_replace('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|[0-9a-f]{1,6};/i', ' ', $line_matchings[2]));
  5348. if ($total_length+$content_length> $length) {
  5349. // the number of characters which are left
  5350. $left = $length - $total_length;
  5351. $entities_length = 0;
  5352. // search for html entities
  5353. if (preg_match_all('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|[0-9a-f]{1,6};/i', $line_matchings[2], $entities, PREG_OFFSET_CAPTURE)) {
  5354. // calculate the real length of all entities in the legal range
  5355. foreach ($entities[0] as $entity) {
  5356. if ($entity[1]+1-$entities_length <= $left) {
  5357. $left--;
  5358. $entities_length += strlen($entity[0]);
  5359. } else {
  5360. // no more characters left
  5361. break;
  5362. }
  5363. }
  5364. }
  5365. $truncate .= substr($line_matchings[2], 0, $left+$entities_length);
  5366. // maximum lenght is reached, so get off the loop
  5367. break;
  5368. } else {
  5369. $truncate .= $line_matchings[2];
  5370. $total_length += $content_length;
  5371. }
  5372. // if the maximum length is reached, get off the loop
  5373. if($total_length>= $length) {
  5374. break;
  5375. }
  5376. }
  5377. } else {
  5378. if (strlen($text) <= $length) {
  5379. return $text;
  5380. } else {
  5381. $truncate = substr($text, 0, $length - strlen($ending));
  5382. }
  5383. }
  5384. // if the words shouldn't be cut in the middle...
  5385. if (!$exact) {
  5386. // ...search the last occurance of a space...
  5387. $spacepos = strrpos($truncate, ' ');
  5388. if (isset($spacepos)) {
  5389. // ...and cut the text in this position
  5390. $truncate = substr($truncate, 0, $spacepos);
  5391. }
  5392. }
  5393. // add the defined ending to the text
  5394. $truncate .= $ending;
  5395. if($considerHtml) {
  5396. // close all unclosed html-tags
  5397. foreach ($open_tags as $tag) {
  5398. $truncate .= '</' . $tag . '>';
  5399. }
  5400. }
  5401. return $truncate;
  5402. }//end function
  5403.  
  5404.  
  5405. /**
  5406. * function: curl with follocation that will get url if openbasedir is set or safe mode enabled
  5407. * @param unknown $ch
  5408. * @return mixed
  5409. */
  5410.  
  5411. function curl_exec_follow( &$ch){
  5412.  
  5413. $max_redir = 3;
  5414.  
  5415. for ($i=0;$i<$max_redir;$i++){
  5416.  
  5417. $exec=curl_exec($ch);
  5418. $x=curl_error($ch);
  5419. $info = curl_getinfo($ch);
  5420.  
  5421. //meta refresh
  5422. if(stristr($exec, 'http-equiv="refresh"') && $info['http_code'] == 200){
  5423.  
  5424. //get the Redirect URL
  5425. preg_match('{<meta.*?http-equiv="refresh".*?>}', $exec,$redirectMatch);
  5426. if(isset($redirectMatch[0]) && trim($redirectMatch[0]) != '' ){
  5427.  
  5428. preg_match('#\bhttps?://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))#', $redirectMatch[0],$urlMatchs);
  5429.  
  5430. if( isset($urlMatchs[0]) && stristr($urlMatchs[0], 'http') ){
  5431. $info['http_code'] = 302;
  5432. $info['redirect_url'] = $urlMatchs[0];
  5433. }
  5434.  
  5435. }
  5436.  
  5437.  
  5438.  
  5439. }
  5440.  
  5441. if($info['http_code'] == 301 || $info['http_code'] == 302){
  5442.  
  5443. //if there is no reddirect_url
  5444. if(trim($info['redirect_url']) == ''){
  5445. $info['redirect_url']= curl_getinfo($ch, CURLINFO_REDIRECT_URL);
  5446.  
  5447. //if php is below 5.3.7 and there is no redirect_url option
  5448. if(trim($info['redirect_url']) == '' ){
  5449.  
  5450. if(stristr($exec, 'Location:')){
  5451. preg_match( '{Location:(.*)}' , $exec, $loc_matches);
  5452. $redirect_url = trim($loc_matches[1]);
  5453.  
  5454. if(trim($redirect_url) != ''){
  5455. $info['redirect_url'] = $redirect_url;
  5456. }
  5457. }else{
  5458.  
  5459. //$info['redirect_url'] = $info['url'];
  5460.  
  5461. }
  5462.  
  5463.  
  5464. }
  5465.  
  5466. }
  5467.  
  5468. curl_setopt($ch, CURLOPT_HTTPGET, 1);
  5469. curl_setopt($ch, CURLOPT_URL, trim($info['redirect_url']));
  5470.  
  5471. $exec=curl_exec($ch);
  5472.  
  5473. }else{
  5474.  
  5475. //no redirect just return
  5476. break;
  5477.  
  5478. }
  5479.  
  5480.  
  5481. }
  5482.  
  5483. return $exec;
  5484.  
  5485. }
  5486.  
  5487. /**
  5488. * function curl_file_exists: check existence of a file
  5489. * @param unknown $url
  5490. * @return boolean
  5491. */
  5492. function curl_file_exists($url){
  5493.  
  5494. //curl get
  5495.  
  5496. $x='error';
  5497. curl_setopt($this->ch, CURLOPT_HTTPGET, 1);
  5498. curl_setopt($this->ch, CURLOPT_URL, trim($url));
  5499. curl_setopt($this->ch, CURLOPT_REFERER, $url);
  5500. //curl_setopt($this->ch, CURLOPT_NOBODY, true);
  5501.  
  5502. $exec=curl_exec($this->ch);
  5503. $x=curl_error($this->ch);
  5504.  
  5505. $httpCode = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);
  5506.  
  5507. //curl_setopt($this->ch, CURLOPT_NOBODY, false);
  5508.  
  5509.  
  5510. if($httpCode == '200' || $httpCode == '302') return true;
  5511.  
  5512. return false;
  5513. }
  5514.  
  5515. //function to get user id and create it if not exists
  5516. function get_user_id_by_display_name( $display_name ) {
  5517.  
  5518. //trim
  5519. $display_name = trim($display_name);
  5520.  
  5521.  
  5522. //check user existence
  5523. if ( ! $user = $this->db->get_row( $this->db->prepare(
  5524. "SELECT `ID` FROM {$this->db->users} WHERE `display_name` = %s", $display_name
  5525. ) ) ){
  5526.  
  5527. //replace spaces
  5528. $login_name = str_replace(' ', '_', $display_name);
  5529.  
  5530.  
  5531. //no user with this name let's create it and return the id
  5532. $userdata['display_name'] = $display_name;
  5533. $userdata['user_login'] = $display_name;
  5534.  
  5535. $user_id = wp_insert_user( $userdata );
  5536.  
  5537.  
  5538. if( !is_wp_error($user_id) ) {
  5539. echo '<br>New user created:'.$login_name;
  5540. return $user_id;
  5541. }else {
  5542. return false;
  5543. }
  5544.  
  5545. return false;
  5546.  
  5547. }
  5548.  
  5549.  
  5550. return $user->ID;
  5551. }
  5552.  
  5553. //remove emoji from instagram
  5554. function removeEmoji($text) {
  5555.  
  5556. $clean_text = "";
  5557.  
  5558. // Match Emoticons
  5559. $regexEmoticons = '/[\x{1F600}-\x{1F64F}]/u';
  5560. $clean_text = preg_replace($regexEmoticons, '', $text);
  5561.  
  5562. // Match Miscellaneous Symbols and Pictographs
  5563. $regexSymbols = '/[\x{1F300}-\x{1F5FF}]/u';
  5564. $clean_text = preg_replace($regexSymbols, '', $clean_text);
  5565.  
  5566. // Match Transport And Map Symbols
  5567. $regexTransport = '/[\x{1F680}-\x{1F6FF}]/u';
  5568. $clean_text = preg_replace($regexTransport, '', $clean_text);
  5569.  
  5570. // Match Miscellaneous Symbols
  5571. $regexMisc = '/[\x{2600}-\x{26FF}]/u';
  5572. $clean_text = preg_replace($regexMisc, '', $clean_text);
  5573.  
  5574. // Match Dingbats
  5575. $regexDingbats = '/[\x{2700}-\x{27BF}]/u';
  5576. $clean_text = preg_replace($regexDingbats, '', $clean_text);
  5577.  
  5578. return $clean_text;
  5579. }
  5580.  
  5581. //function for hyperlinking
  5582. function hyperlink_this($text){
  5583.  
  5584. return preg_replace('@(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)@', '<a href="$1" target="_blank">$0</a>', $text);
  5585.  
  5586. }
  5587.  
  5588. //function for stripping inline urls
  5589. function strip_urls($content){
  5590.  
  5591. return preg_replace('{http[s]?://[^\s]*}', '', $content);
  5592.  
  5593. }
  5594.  
  5595. //fix invalid uلtf chars
  5596. function fix_utf8($string){
  5597.  
  5598.  
  5599. //check if wrong utf8
  5600. if ( 1 === @preg_match( '/^./us', $string ) ) {
  5601.  
  5602. return $string;
  5603. }else{
  5604. echo '<br>Fixing invalid utf8 text...' ;
  5605.  
  5606. if(function_exists('iconv')){
  5607. return iconv( 'utf-8', 'utf-8//IGNORE', $string );
  5608. }else{
  5609. echo '<br>Iconv module is not installed, please install PHP iconv module';
  5610. return $string;
  5611. }
  5612.  
  5613. }
  5614.  
  5615. }
  5616.  
  5617. function cleanthetitle($title) {
  5618. $title = str_replace('nospin', '', $title);
  5619. $title = str_replace(' ', '-', $title); // Replaces all spaces with hyphens.
  5620. $title = preg_replace('/[^A-Za-z0-9\-]/', '', $title); // Removes special chars.
  5621.  
  5622. return preg_replace('/-+/', '-', $title); // Replaces multiple hyphens with single one.
  5623. }
  5624.  
  5625. //is_enlish: checks if the text is english requires mb_string module
  5626. function is_english ($string){
  5627.  
  5628. if( ! function_exists('mb_strlen') ){
  5629.  
  5630. echo '<br>Will skip checking if english as mbstring module must be installed ';
  5631.  
  5632. return true;
  5633. }
  5634.  
  5635. $string = str_replace(array('”','“','’','‘','’'),'',$string) ;
  5636.  
  5637.  
  5638. if(strlen($string) != mb_strlen($string, 'utf-8'))
  5639. {
  5640. return false;
  5641. }
  5642. else {
  5643. return true;
  5644. }
  5645.  
  5646.  
  5647. }
  5648.  
  5649. function attach_image($image_url,$camp_opt,$post_id){
  5650.  
  5651. // Upload dir
  5652. $upload_dir = wp_upload_dir ();
  5653.  
  5654. //img host
  5655. $imghost = parse_url ( $image_url, PHP_URL_HOST );
  5656.  
  5657. if(stristr($imghost, 'http://')){
  5658. $imgrefer=$imghost;
  5659. }else{
  5660. $imgrefer = 'http://'.$imghost;
  5661. }
  5662.  
  5663. //empty referal
  5664. if( ! in_array('OPT_CACHE_REFER_NULL', $camp_opt) ){
  5665. curl_setopt ( $this->ch, CURLOPT_REFERER, $imgrefer );
  5666. }else{
  5667. curl_setopt ( $this->ch, CURLOPT_REFERER, '' );
  5668. }
  5669.  
  5670. if( stristr($image_url, 'base64,') ){
  5671.  
  5672. $filename = time('now');
  5673.  
  5674. }else{
  5675.  
  5676. //decode html entitiies
  5677. $image_url = html_entity_decode($image_url);
  5678.  
  5679. if(stristr($image_url, '%') ) {
  5680. $image_url = urldecode($image_url);
  5681. }
  5682.  
  5683. //file name to store
  5684. $filename = basename ( $image_url );
  5685.  
  5686.  
  5687. if(stristr($image_url ,' ')){
  5688. $image_url = str_replace(' ', '%20', $image_url);
  5689. }
  5690.  
  5691. }
  5692.  
  5693. // Clean thumb
  5694. if(in_array('OPT_THUMB_CLEAN' , $camp_opt )){
  5695.  
  5696. $clean_name = '';
  5697. $clean_name = sanitize_title($post_title);
  5698.  
  5699. if(trim($clean_name) != ""){
  5700.  
  5701. //get the image extension \.\w{3}
  5702. $ext = pathinfo($filename, PATHINFO_EXTENSION);
  5703.  
  5704. if(stristr($ext, '?')){
  5705. $ext_parts = explode('?',$ext);
  5706. $ext = $ext_parts[0];
  5707. }
  5708.  
  5709. //clean parameters after filename
  5710. $filename = trim($clean_name);
  5711.  
  5712. if( trim($ext) !='' ){
  5713. $filename = $filename .'.'. $ext;
  5714. }
  5715.  
  5716. }
  5717.  
  5718. }
  5719.  
  5720.  
  5721.  
  5722. if( stristr($image_url, 'base64,') ){
  5723. $ex = explode('base64,', $current_img);
  5724. $image_data = base64_decode($ex[1]);
  5725.  
  5726. //set fileName extention .png, .jpg etc
  5727. preg_match('{data:image/(.*?);}', $image_url ,$ex_matches);
  5728. $image_ext = $ex_matches[1];
  5729.  
  5730. if(trim($image_ext) != ''){
  5731. $filename = $filename .'.'.$image_ext;
  5732. }
  5733.  
  5734. }else{
  5735.  
  5736.  
  5737. //get image content
  5738. $x='error';
  5739. curl_setopt($this->ch, CURLOPT_HTTPGET, 1);
  5740. curl_setopt($this->ch, CURLOPT_URL, trim( html_entity_decode($image_url) ) );
  5741. $image_data=$this->curl_exec_follow($this->ch);
  5742.  
  5743. $x=curl_error($this->ch);
  5744.  
  5745.  
  5746. }
  5747.  
  5748.  
  5749. if(trim($image_data) != ''){
  5750.  
  5751. //check if already saved
  5752.  
  5753. $image_data_md5 = md5($image_data);
  5754.  
  5755. $is_cached = $this->is_cached($image_url , $image_data_md5);
  5756.  
  5757. if( $is_cached != false ){
  5758. echo '<--already cached' ;
  5759. $file = $this->cached_file_path;
  5760. $guid = $is_cached;
  5761. }else{
  5762.  
  5763.  
  5764. if (stristr ( $filename, '?' )) {
  5765. $farr = explode ( '?', $filename );
  5766. $filename = $farr [0];
  5767. }
  5768.  
  5769. //pagepeeker fix
  5770. if(stristr($image_url, 'pagepeeker') && ! in_array('OPT_THUMB_CLEAN' , $camp_opt )){
  5771. $filename = md5($filename).'.jpg';
  5772. }
  5773.  
  5774. if (wp_mkdir_p ( $upload_dir ['path'] ))
  5775. $file = $upload_dir ['path'] . '/' . $filename;
  5776. else
  5777. $file = $upload_dir ['basedir'] . '/' . $filename;
  5778.  
  5779. // check if same image name already exists
  5780. if (file_exists ( $file )) {
  5781.  
  5782. //get the current saved one to check if identical
  5783. $already_saved_image_link=$upload_dir ['url'] . '/' . $filename;
  5784.  
  5785. //curl get
  5786. $x='error';
  5787. $url=$already_saved_image_link;
  5788. curl_setopt($this->ch, CURLOPT_HTTPGET, 1);
  5789. curl_setopt($this->ch, CURLOPT_URL, trim($url));
  5790.  
  5791. $exec=curl_exec($this->ch);
  5792.  
  5793. if(trim($exec) == trim($image_data)){
  5794. $idential = true;
  5795. echo '<br>Featured image already exists with same path.. using it';
  5796. }else{
  5797. echo '<br>Featured image exists with same path but not identical.. saving ';
  5798.  
  5799. $filename = time ( 'now' ) . '_' . $filename;
  5800.  
  5801. }
  5802.  
  5803. }
  5804.  
  5805.  
  5806. //saving image
  5807. if(! isset($idential )){
  5808. if (wp_mkdir_p ( $upload_dir ['path'] ))
  5809. $file = $upload_dir ['path'] . '/' . $filename;
  5810. else
  5811. $file = $upload_dir ['basedir'] . '/' . $filename;
  5812.  
  5813. $f=file_put_contents ( $file, $image_data );
  5814.  
  5815.  
  5816.  
  5817. }
  5818.  
  5819. $guid = $upload_dir['url'] . '/' . basename( $filename );
  5820.  
  5821. $this->img_cached($image_url, $guid,$image_data_md5,$file);
  5822.  
  5823. }//not cached
  5824.  
  5825. //atttatchment check if exists or not
  5826. global $wpdb;
  5827.  
  5828.  
  5829. $query = "select * from $wpdb->posts where guid = '$guid'";
  5830. $already_saved_attachment = $wpdb->get_row($query);
  5831.  
  5832. if(isset($already_saved_attachment->ID)){
  5833.  
  5834. $attach_id = $already_saved_attachment->ID;
  5835.  
  5836. }else{
  5837.  
  5838. $wp_filetype = wp_check_filetype ( $filename, null );
  5839.  
  5840. if($wp_filetype['type'] == false){
  5841. $wp_filetype['type'] = 'image/jpeg';
  5842. }
  5843.  
  5844. //Alt handling
  5845. $imgTitle = sanitize_file_name ( $filename );
  5846. if(in_array('OPT_THUMB_ALT',$camp_opt)){
  5847. //$imgTitle = $title;
  5848. }
  5849.  
  5850. $attachment = array (
  5851. 'guid' => $guid,
  5852. 'post_mime_type' => $wp_filetype ['type'],
  5853. 'post_title' => $imgTitle,
  5854. 'post_content' => '',
  5855. 'post_status' => 'inherit'
  5856. );
  5857.  
  5858. $attach_id = wp_insert_attachment ( $attachment, $file, $post_id );
  5859. require_once (ABSPATH . 'wp-admin/includes/image.php');
  5860. $attach_data = wp_generate_attachment_metadata ( $attach_id, $file );
  5861. wp_update_attachment_metadata ( $attach_id, $attach_data );
  5862.  
  5863. }
  5864.  
  5865.  
  5866. if(is_numeric($attach_id) && $attach_id > 0 ){
  5867. return $attach_id;
  5868. }
  5869.  
  5870.  
  5871. }else{
  5872. echo ' <-- can not get image content '.$x;
  5873. return false;
  5874. }
  5875.  
  5876.  
  5877.  
  5878. }
  5879.  
  5880. /**
  5881. * Count chars on text using mb_ module and if not exists it count it using strlen
  5882. * @param unknown $text
  5883. */
  5884. function chars_count(&$text){
  5885.  
  5886. if(function_exists('mb_strlen')){
  5887. return mb_strlen($text);
  5888. }else{
  5889. return strlen($text);
  5890. }
  5891.  
  5892. }
  5893.  
  5894.  
  5895. function randomUserAgent(){
  5896.  
  5897. $agents = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36
  5898. Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36
  5899. Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36
  5900. Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36
  5901. Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.1.2 Safari/603.3.8
  5902. Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36
  5903. Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36
  5904. Mozilla/5.0 (Windows NT 10.0; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0
  5905. Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0
  5906. Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36
  5907. Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko
  5908. Mozilla/5.0 (Windows NT 6.1; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0
  5909. Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:55.0) Gecko/20100101 Firefox/55.0
  5910. Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36
  5911. Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Edge/15.15063
  5912. Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:55.0) Gecko/20100101 Firefox/55.0
  5913. Mozilla/5.0 (Windows NT 10.0; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0
  5914. Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36
  5915. Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36
  5916. Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36";
  5917.  
  5918. $arrAgents = explode("\n", $agents);
  5919.  
  5920. $rand = rand(0,count($arrAgents) -1);
  5921.  
  5922. return $arrAgents[$rand];
  5923.  
  5924. }
  5925. /**
  5926. * Function to download file and return the url of it at the server
  5927. * @param String $url
  5928. * @parm String optional $ext ex .xml
  5929. * return path of the file or false
  5930. */
  5931. function download_file($url,$ext=''){
  5932.  
  5933. //curl get
  5934. $x='error';
  5935.  
  5936. curl_setopt($this->ch, CURLOPT_HTTPGET, 1);
  5937. curl_setopt($this->ch, CURLOPT_URL, trim($url));
  5938. $exec=curl_exec($this->ch);
  5939. $x=curl_error($this->ch);
  5940.  
  5941. if(trim($x) == '' && trim($exec) != ''){
  5942.  
  5943. $upload_dir = wp_upload_dir ();
  5944. $filePath = $upload_dir['basedir'] .'/wp_automatic_temp'.$ext;
  5945. $fileUrl = $upload_dir['baseurl'] .'/wp_automatic_temp'.$ext;
  5946. file_put_contents($filePath, $exec);
  5947. return $fileUrl;
  5948.  
  5949. }
  5950.  
  5951. return false;
  5952. }
  5953.  
  5954.  
  5955. } // End
  5956.  
  5957. ?>
Add Comment
Please, Sign In to add comment