Guest User

Untitled

a guest
May 3rd, 2019
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 128.12 KB | None | 0 0
  1. <?php
  2. /**
  3. Plugin Name: WP Robot 4
  4. Plugin URI: http://www.wprobot.net/
  5. Version: 4.10
  6. Description: Automatically post content related to any topic of your choice to your weblog.
  7. Author: WP Robot
  8. Author URI: http://www.wprobot.net/
  9. License: Commercial. For personal use only. Not to give away or resell
  10. */
  11. /* Copyright 2009 - 2014 Thomas Hoefter
  12. */
  13. error_reporting(E_ERROR | E_PARSE);
  14.  
  15. if (version_compare(PHP_VERSION, '5.0.0.', '<'))
  16. {
  17. die(__("WP Robot requires php 5 or a greater version to work.", "wprobot"));
  18. }
  19.  
  20. if (!defined('WP_CONTENT_URL')) {
  21. define('WP_CONTENT_URL', get_option('siteurl') . '/wp-content');
  22. }
  23.  
  24. define('WPR_URLPATH', WP_PLUGIN_URL.'/'.plugin_basename( dirname(__FILE__) ).'/' );
  25. $wpr_cache = ABSPATH . "wp-content/plugins/". plugin_basename( dirname(__FILE__) )."/plr";
  26.  
  27. function wpr_plugin_init () {
  28. $plugin_dir = basename(dirname(__FILE__));
  29. load_plugin_textdomain( 'wprobot', 'wp-content/plugins/' . $plugin_dir, $plugin_dir );
  30. }
  31. add_action('init', 'wpr_plugin_init');
  32.  
  33. // Global Variables
  34. $wpr_version = "4.10";
  35. $wpr_table_campaigns = $wpdb->prefix . "wpr_campaigns";
  36. $wpr_table_templates = $wpdb->prefix . "wpr_templates";
  37. $wpr_table_posts = $wpdb->prefix . "wpr_posts";
  38. $wpr_table_errors = $wpdb->prefix . "wpr_errors";
  39. $wpr_modules = array("amazon","article","articlebuilder","clickbank","ebay","flickr","yahoonews","youtube","rss","translation","commissionjunction","oodle","pressrelease","shopzilla","itunes","linkshare","eventful","yelp","shareasale","avantlink","plr","bigcontentsearch","kontentmachine");
  40.  
  41. $wpr_file = basename( __FILE__ );
  42. $wpr_folder = basename( dirname( __FILE__ ) );
  43.  
  44. @include_once("func.php");
  45. foreach ($wpr_modules as $module) {$inc = @include_once("modules/$module.php");if($inc == 1) {$wpr_loadedmodules[] = $module;}} // Modules
  46.  
  47. //@include_once("wprupgrader.php");
  48. @include_once("display-cl.php");
  49. @include_once("AllRewriters/allrewriters.php");
  50.  
  51. function wpr_default_options($update=0) {
  52. global $wpr_modules;
  53.  
  54. @include_once("default-options.php");
  55.  
  56. $options = unserialize(get_option("wpr_options"));
  57.  
  58. $options['wpr_poststatus'] = 'published';
  59. $options['wpr_autotag'] = 'Yes';
  60. $options['wpr_resetcount'] = 'no';
  61. $options['wpr_badwords'] = 'what;which;where;when;does;that;with;while;then;your;other;have;make;will';
  62. $options['wpr_randomize'] = 'yes';
  63. $options['wpr_randomize_comments'] = 'no';
  64. $options['wpr_help'] = 'Yes';
  65. $options['wpr_openlinks'] = 'no';
  66. $options['wpr_authorid'] = 1;
  67. $options['wpr_err_retries'] = 4;
  68. $options['wpr_err_maxerr'] = 2;
  69. $options['wpr_err_minmod'] = 1;
  70. $options['wpr_err_disable'] = 30;
  71. $options["wpr_global_exclude"] = "";
  72. $options['wpr_check_unique_old'] = "No";
  73. $options['wpr_replace_keyword'] = "0";
  74. $options['wpr_save_images'] = "Yes";
  75. //$options['wpr_rewrite_active'] = "No";
  76. //$options['wpr_rewrite_level'] = "r";
  77. /*$options['wpr_rewrite_active_tbs'] = 0;
  78. $options['wpr_rewrite_active_sc'] = 0;
  79. $options['wpr_rewrite_active_schimp'] = 0;
  80. $options['wpr_rewrite_active_ucg'] = 0;
  81. $options['wpr_rewrite_active_sr'] = 0;
  82. $options['wpr_rewrite_active_wai'] = 0;
  83. $options['wpr_rewrite_email'] = "";
  84. $options['wpr_rewrite_key'] = "";
  85. $options['wpr_tbs_rewrite_email'] = "";
  86. $options['wpr_tbs_rewrite_pw'] = "";
  87. $options['wpr_tbs_spintxt'] = "No";
  88. $options['wpr_tbs_quality'] = 1;
  89. $options['wpr_rewrite_protected'] = "";
  90. $options['wpr_sc_rewrite_email'] = "";
  91. $options['wpr_sc_rewrite_pw'] = "";
  92. $options['wpr_sc_quality'] = 0;
  93. $options['wpr_sc_port'] = 9001;
  94. $options['wpr_sc_thesaurus'] = "English";
  95. $options['wpr_schimp_rewrite_email'] = "";
  96. $options['wpr_schimp_rewrite_pw'] = "";
  97. $options['wpr_schimp_quality'] = 3;
  98. $options['wpr_sr_rewrite_email'] = "";
  99. $options['wpr_sr_rewrite_pw'] = "";
  100. $options['wpr_sr_quality'] = "medium";
  101. $options['wpr_wai_rewrite_email'] = "";
  102. $options['wpr_wai_rewrite_pw'] = "";
  103. $options['wpr_wai_sentence'] = "on";
  104. $options['wpr_wai_paragraph'] = "";
  105. $options['wpr_wai_nooriginal'] = "";
  106. $options['wpr_wai_quality'] = "Regular"; */
  107. $options['wpr_tbs_rewrite_title'] = "No";
  108. $options['wpr_rewrite_use'] = "rand";
  109. $options['wpr_trans_use_proxies'] = "no";
  110. $options['wpr_trans_proxies'] = "";
  111. foreach($wpr_modules as $module) {
  112. $function = "wpr_".$module."_options_default";
  113. if(function_exists($function)) {
  114. $moptions = $function();
  115. foreach($moptions as $moption => $default) {
  116. if(!empty($defaults[$moption])) {
  117. $options[$moption] = $defaults[$moption];
  118. } else {
  119. $options[$moption] = "$default";
  120. }
  121. }
  122. }
  123. }
  124.  
  125. if(!empty($defaults['wpr_poststatus'])) {$options['wpr_poststatus'] = $defaults['wpr_poststatus'];}
  126. if(!empty($defaults['wpr_autotag'])) {$options['wpr_autotag'] = $defaults['wpr_autotag'];}
  127. if(!empty($defaults['wpr_resetcount'])) {$options['wpr_resetcount'] = $defaults['wpr_resetcount'];}
  128. if(!empty($defaults['wpr_badwords'])) {$options['wpr_badwords'] = $defaults['wpr_badwords'];}
  129. if(!empty($defaults['wpr_randomize'])) {$options['wpr_randomize'] = $defaults['wpr_randomize'];}
  130. if(!empty($defaults['wpr_randomize_comments'])) {$options['wpr_randomize_comments'] = $defaults['wpr_randomize_comments'];}
  131. if(!empty($defaults['wpr_openlinks'])) {$options['wpr_openlinks'] = $defaults['wpr_openlinks'];}
  132. if(!empty($defaults['wpr_authorid'])) {$options['wpr_authorid'] = $defaults['wpr_authorid'];}
  133.  
  134. if(WPLANG == "de_DE") {
  135. $options["wpr_aa_site"] = "de";
  136. $options["wpr_eb_country"] = "77";
  137. $options["wpr_eb_lang"] = "de";
  138. $options["wpr_yt_lang"] = "de";
  139. $options["wpr_yan_lang"] = "de";
  140. $options["wpr_yap_lang"] = "de";
  141. $options["wpr_twitter_lang"] = "de";
  142. $options['wpr_badwords'] = 'weil;doch;als;bei;nun;jetzt;nur;der;die;das;wir;ihr;sie;sobald;darauf';
  143. $options["wpr_aa_revtemplate"] = "<i>Rezession von {author} &uuml;ber {link}</i>&#13;<b>Bewertung: {rating}</b>&#13;{content}&#13;&#13;";
  144. }
  145.  
  146. $croncode = substr(md5(time()), 0, 9);
  147. add_option('wpr_cron',$croncode);
  148. add_option('wpr_cloak',"No");
  149.  
  150. if($update == 1) {
  151. update_option("wpr_options", serialize($options));
  152. return $options;
  153. } else {
  154. add_option("wpr_options", serialize($options));
  155. }
  156. }
  157.  
  158. function wpr_default_options_single($module,$options) {
  159. //$options = unserialize(get_option("wpr_options"));
  160. $function = "wpr_".$module."_options_default";
  161. if(function_exists($function)) {
  162. $moptions = $function();
  163. foreach($moptions as $moption => $default) {
  164. if(!empty($defaults[$moption])) {
  165. $options[$moption] = $defaults[$moption];
  166. } else {
  167. $options[$moption] = "$default";
  168. }
  169. }
  170. }
  171. //update_option("wpr_options", serialize($options));
  172. return $options;
  173. }
  174.  
  175. function wpr_activate() {
  176. global $wpdb;
  177.  
  178. $wpr_db_ver = 96;
  179. $wpr_table_campaigns = $wpdb->prefix . "wpr_campaigns";
  180. $wpr_table_templates = $wpdb->prefix . "wpr_templates";
  181. $wpr_table_posts = $wpdb->prefix . "wpr_posts";
  182. $wpr_table_errors = $wpdb->prefix . "wpr_errors";
  183.  
  184. if(get_option('wpr_db_ver') != $wpr_db_ver) {
  185.  
  186. if ( !empty($wpdb->charset) )
  187. $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
  188.  
  189. $sql[] = "CREATE TABLE ".$wpr_table_campaigns." (
  190. id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  191. name VARCHAR(255) NOT NULL,
  192. ctype VARCHAR(255) NOT NULL,
  193. keywords longtext NOT NULL,
  194. categories longtext NOT NULL,
  195. templates longtext NOT NULL,
  196. cinterval BIGINT(20) NOT NULL,
  197. period VARCHAR(255) NOT NULL,
  198. postspan VARCHAR(255) NOT NULL,
  199. replacekws longtext NOT NULL,
  200. excludekws longtext NOT NULL,
  201. amazon_department VARCHAR(255) NOT NULL,
  202. ebay_cat VARCHAR(255) NOT NULL,
  203. yahoo_cat VARCHAR(255) NOT NULL,
  204. translation VARCHAR(255) NOT NULL,
  205. customfield longtext NOT NULL,
  206. posts_created BIGINT(20) NOT NULL DEFAULT 0,
  207. pause INT(1) NOT NULL DEFAULT 0
  208. ) {$charset_collate};";
  209.  
  210. $sql[] = "CREATE TABLE ".$wpr_table_templates." (
  211. id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  212. type VARCHAR(255) NOT NULL,
  213. typenum INT(4) NOT NULL DEFAULT 1,
  214. content longtext NOT NULL,
  215. title longtext NOT NULL,
  216. comments_amazon INT(1) NOT NULL DEFAULT 0,
  217. comments_flickr INT(1) NOT NULL DEFAULT 0,
  218. comments_yahoo INT(1) NOT NULL DEFAULT 0,
  219. comments_youtube INT(1) NOT NULL DEFAULT 0,
  220. name VARCHAR(255) NOT NULL
  221. ) {$charset_collate};";
  222.  
  223. $sql[] = "CREATE TABLE ".$wpr_table_posts." (
  224. id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  225. campaign BIGINT(20) NOT NULL,
  226. keyword VARCHAR(255) NOT NULL,
  227. module VARCHAR(255) NOT NULL,
  228. unique_id longtext NOT NULL,
  229. time VARCHAR(255) NOT NULL
  230. ) {$charset_collate};";
  231.  
  232. $sql[] = "CREATE TABLE ".$wpr_table_errors." (
  233. id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  234. campaign BIGINT(20) NOT NULL,
  235. keyword VARCHAR(255) NOT NULL,
  236. module VARCHAR(255) NOT NULL,
  237. reason VARCHAR(255) NOT NULL,
  238. message longtext NOT NULL,
  239. time VARCHAR(255) NOT NULL
  240. ) {$charset_collate};";
  241.  
  242. require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
  243. dbDelta($sql);
  244.  
  245. update_option('wpr_db_ver',$wpr_db_ver);
  246.  
  247. }
  248. }
  249. register_activation_hook(__FILE__, 'wpr_activate');
  250.  
  251. function wpr_import_options() {
  252. global $wpr_modules;
  253. $options = unserialize(get_option("wpr_options"));
  254. $options['wpr_poststatus'] = get_option('ma_poststatus');
  255. $options['wpr_autotag'] = get_option('ma_autotag');
  256. $options['wpr_resetcount'] = get_option('ma_resetcount');
  257. $options['wpr_badwords'] = get_option('ma_badwords');
  258. $options['wpr_randomize'] = get_option('ma_randomize');
  259. $options['wpr_authorid'] = get_option('ma_authorid');
  260. $options['wpr_check_unique_old'] = "Yes";
  261. foreach($wpr_modules as $module) {
  262. $function = "wpr_".$module."_options_default";
  263. if(function_exists($function)) {
  264. $moptions = $function();
  265. foreach($moptions as $moption => $default) {
  266. $oldoption = str_replace("wpr_","ma_",$moption);
  267. if( $oldoption != "ma_aa_revtemplate" ) {
  268. $geto = get_option($oldoption);
  269. if($geto != " " && !empty($geto)) {
  270. $options[$moption] = $geto;
  271. }
  272. }
  273. }
  274. }
  275. }
  276. update_option("wpr_options", serialize($options));
  277. return $options;
  278. }
  279.  
  280. function wpr_add_pages() {
  281.  
  282. add_menu_page('WP Robot 4', 'WP Robot 4', 8, 'wpr-campaigns', 'wpr_toplevel', 'none');
  283. add_submenu_page('wpr-campaigns', __('Campaigns', 'wprobot'), __('Campaigns', 'wprobot'), 8, 'wpr-campaigns', 'wpr_toplevel');
  284. add_submenu_page('wpr-campaigns', __('Create Campaign', 'wprobot'), __('Create Campaign', 'wprobot'), 8, 'wpr-add', 'wpr_add');
  285. add_submenu_page('wpr-campaigns', __('Options', 'wprobot'), __('Options', 'wprobot'), 8, 'wpr-options', 'wpr_sub_options');
  286. add_submenu_page('wpr-campaigns', __('Templates', 'wprobot'), __('Templates', 'wprobot'), 8, 'wpr-templates', 'wpr_sub_templates');
  287. add_submenu_page('wpr-campaigns', __('Log', 'wprobot'), __('Log', 'wprobot'), 8, 'wpr-log', 'wpr_errors');
  288. $aropt = add_submenu_page('wpr-campaigns', 'All Rewriters', 'All Rewriters', 'manage_options', 'ar-settings', 'ar_settings_page');
  289. add_action( "admin_print_scripts-$aropt", 'ar_settings_page_scripts' );
  290. add_submenu_page('wpr-campaigns', '', '', 8, 'wpr-single', 'wpr_single');
  291.  
  292. }
  293. add_action('admin_menu', 'wpr_add_pages');
  294.  
  295. function wpr_transform_cats($categories) {
  296. for ($i = 0; $i < count($categories); $i++) {
  297. $categories[$i][0]["id"] = $categories[$i]["id"];
  298. $categories[$i][0]["name"] = $categories[$i]["name"];
  299. unset($categories[$i]["id"]);
  300. unset($categories[$i]["name"]);
  301. }
  302. return $categories;
  303. }
  304.  
  305. function wpr_create_campaign() {
  306. global $wpdb, $wpr_table_campaigns, $wpr_table_templates,$wpr_loadedmodules;
  307.  
  308. $options = unserialize(get_option("wpr_options"));
  309.  
  310. if($options['wpr_simple']=='Yes') {
  311. $totalchance = 0;
  312. foreach($wpr_loadedmodules as $lmodule) {
  313. if($_POST[$lmodule."chance"] > 0) {
  314. $totalchance = $totalchance + $_POST[$lmodule."chance"];
  315. }
  316. }
  317. if($_POST["mixchance"] > 0) {
  318. $totalchance = $totalchance + $_POST["mixchance"];
  319. }
  320. } else {
  321. for ($i = 1; $i <= $_POST['tnum']; $i++) {
  322. if($_POST["chance$i"] > 0) {
  323. $totalchance = $totalchance + $_POST["chance$i"];
  324. }
  325. }
  326. }
  327.  
  328. if($_POST['keywords'] == "" && $_POST['type'] == "keyword") {
  329. echo '<div class="updated"><p>'.__("Please enter at least one keyword!", "wprobot").'</p></div>';
  330. } elseif($_POST['feeds'] == "" && $_POST['type'] == "rss") {
  331. echo '<div class="updated"><p>'.__("Please enter at least one RSS feed!", "wprobot").'</p></div>';
  332. } elseif($_POST['nodes'] == "" && $_POST['type'] == "nodes") {
  333. echo '<div class="updated"><p>'.__("Please enter at least one Amazon BrowseNode!", "wprobot").'</p></div>';
  334. } elseif($_POST['categories'] == "") {
  335. echo '<div class="updated"><p>'.__("Please enter at least one category!", "wprobot").'</p></div>';
  336. } elseif($_POST['interval'] == "") {
  337. echo '<div class="updated"><p>'.__("Please enter a post interval!", "wprobot").'</p></div>';
  338. } elseif($_POST['name'] == "") {
  339. echo '<div class="updated"><p>'.__("Please enter a name for your campaign!", "wprobot").'</p></div>';
  340. } elseif($_POST['title1'] == "" && $options['wpr_simple']!='Yes' || $_POST['content1'] == "" && $options['wpr_simple']!='Yes' || $_POST['chance1'] == "" && $options['wpr_simple']!='Yes') {
  341. echo '<div class="updated"><p>'.__('Please create at least one template for your campaign! Use the "Add Post Template" or "Quick Template Setup" buttons to add a template.', "wprobot").'</p></div>';
  342. } elseif($_POST['amazon_department'] == "All" && $_POST['type'] == "nodes") {
  343. echo '<div class="updated"><p>'.__("Amazon Department can not be 'All' in a BrowseNodes campaign! You have to select the correct Department your Nodes belong to (Amazon API requirement).", "wprobot").'</p></div>';
  344. } elseif($totalchance != 100 && $options['wpr_simple']=='Yes' && $_POST['type'] == "keyword") {
  345. echo '<div class="updated"><p>'.__("Error: The sum of percentages for all Modules together has to be 100!", "wprobot").'</p></div>';
  346. } elseif($totalchance != 100 && $options['wpr_simple']!='Yes') {
  347. echo '<div class="updated"><p>'.__("Error: The sum of the 'Chance of being used' fields for all post templates has to be 100! (Currently: ", "wprobot").$totalchance.')</p></div>';
  348. } elseif($_POST["mixchance"] > 0 && $options['wpr_simple']=='Yes' && empty($_POST["mixcontent"]) && $_POST['type'] == "keyword") {
  349. echo '<div class="updated"><p>'.__("Error: Template for Mixed Posts can not be empty if percentage for it is positive!", "wprobot").'</p></div>';
  350. } else {
  351.  
  352. $type = $_POST['type'];
  353.  
  354. // Keywords
  355. $_POST['keywords'] = stripslashes($_POST['keywords']);
  356. $keywordsinput = str_replace("\r", "", $_POST['keywords']);
  357. $keywordsinput = explode("\n", $keywordsinput);
  358.  
  359. $i=0;
  360. $keywords = array();
  361.  
  362. if($_POST["edit"]) {// GET OLD KEYWORDS FOR NUMs $oldcamp->postspan
  363. $edit = 1;
  364. $oldcamp = $wpdb->get_row( "SELECT keywords,postspan FROM $wpr_table_campaigns WHERE id = '" . $_POST["edit"] . "'" );
  365. $oldkeywords = unserialize($oldcamp->keywords);
  366. }
  367.  
  368. if($type == "keyword") {
  369. foreach( $keywordsinput as $keyword) {
  370. if($keyword != "") {
  371.  
  372. $keyword = explode("|", $keyword);
  373.  
  374. $keywords[$i] = array($keyword[0]);
  375. if($edit == 1) {
  376. $kwnums = false;
  377. foreach($oldkeywords as $key => $oldkeyword) {
  378. if($oldkeyword[0] == $keyword[0]) {$kwnums = $oldkeyword[1];}
  379. }
  380. }
  381. if($kwnums != false) {
  382. $keywords[$i][] = $kwnums;
  383. } else {
  384. $keywords[$i][] = array("total" => 0);
  385. }
  386. $keywords[$i]["skipped"] = 0;
  387.  
  388. // Add alternative keywords
  389. for ($y = 1; $y <= 5; $y++) {
  390. if(!empty($keyword[$y])) {
  391. $keywords[$i]["alternative"][$y] = $keyword[$y];
  392. }
  393. }
  394. }
  395. $i++;
  396. }
  397. } elseif($type == "rss") {
  398. $rssinput = str_replace("\r", "", $_POST['feeds']);
  399. $rssinput = explode("\n", $rssinput);
  400. foreach( $rssinput as $rss) {
  401. if($rss != "") {
  402. $keywords[$i] = array($keywordsinput[$i]);
  403. if($edit == 1) {
  404. $kwnums = false;
  405. foreach($oldkeywords as $key => $oldkeyword) {
  406. if($oldkeyword[0] == $keywordsinput[$i]) {$kwnums = $oldkeyword[1];}
  407. }
  408. }
  409. if($kwnums != false) {
  410. $keywords[$i][] = $kwnums;
  411. } else {
  412. $keywords[$i][] = array("total" => 0);
  413. }
  414. $keywords[$i]["skipped"] = 0;
  415. $keywords[$i]["feed"] = $rss;
  416. }
  417. $i++;
  418. }
  419. } elseif($type == "nodes") {
  420. $nodesinput = str_replace("\r", "", $_POST['nodes']);
  421. $nodesinput = explode("\n", $nodesinput);
  422. $failcount = 0;
  423. foreach( $nodesinput as $node) {
  424. $nodename = wpr_aws_getnodename($node);
  425. if($node != "" && $nodename != false && !is_array($nodename)) {
  426. $keywords[$i] = array($keywordsinput[$i]);
  427. if($edit == 1) {
  428. $kwnums = false;
  429. foreach($oldkeywords as $key => $oldkeyword) {
  430. if($oldkeyword[0] == $keywordsinput[$i]) {$kwnums = $oldkeyword[1];}
  431. }
  432. }
  433. if($kwnums != false) {
  434. $keywords[$i][] = $kwnums;
  435. } else {
  436. $keywords[$i][] = array("total" => 0);
  437. }
  438. $keywords[$i]["skipped"] = 0;
  439. $keywords[$i]["bnn"] = "$nodename";
  440. $keywords[$i]["node"] = $node;
  441. } else {
  442. $failcount++;
  443. }
  444. $i++;
  445. }
  446. if($failcount > 0) {
  447. echo '<div class="updated"><p>'.__("<b>Error</b>: ","wprobot").$failcount.__(" Browsenodes could not be added to your campaign! Make sure to select the correct Amazon Department and the Amazon Site matching your Node ID. This is a requirement of the Amazon API.", "wprobot");
  448. //if(is_array($nodename)) {
  449. // echo __("<br/><br/>The last error Amazon returned was:<br/><i>","wprobot").$nodename["message"]."</i>";
  450. //}
  451. echo '</p></div>';
  452. }
  453. }
  454. $keywords = $wpdb->escape(serialize($keywords));
  455.  
  456. // Categories
  457. if($_POST['multisingle'] == "single") {
  458. $categorysave = array();
  459. $categorysave[0][0]["id"] = $_POST['categories'];
  460. $categorysave[0][0]["name"] = get_cat_name( $_POST['categories'] );
  461. } else {
  462. $categorysave = array();
  463. $_POST['categories'] = stripslashes($_POST['categories']);
  464. $categoriesinput = str_replace("\r", "", $_POST['categories']);
  465. $categoriesinput = explode("\n", $categoriesinput);
  466. $i = 0;
  467. foreach($categoriesinput as $categories) {
  468. $categories = explode(",",$categories);
  469. $k = 0;
  470. foreach($categories as $category) {
  471. if($category != "") {
  472.  
  473. // if category starts with "-" get previous parent ID and set variable
  474. if($category[0] == '-') {
  475. $category = substr($category, 1);
  476. $parent = $parentid;
  477. $saveparent = 0;
  478. } else {
  479. $parent = "";
  480. $saveparent = 1;
  481. }
  482.  
  483. $category = str_replace("&", "&amp;", $category);
  484.  
  485. $catname = ucwords($category);
  486. $category_ID = get_cat_ID( $category );
  487.  
  488. if(!$category_ID && $_POST['createcats'] == "yes") {
  489. if(is_numeric($parent)) {$parent = (int)$parent;} else {$parent = 0;}
  490.  
  491. if(function_exists("wp_create_category")) {
  492. $category_ID = wp_create_category( $catname, $parent );
  493. } elseif(function_exists("wp_insert_category")) {
  494. $category_ID = wp_insert_category( array(
  495. 'cat_ID' => 0,
  496. 'cat_name' => $catname,
  497. 'category_description' => "",
  498. 'category_nicename' => "",
  499. 'category_parent' => $parent,
  500. 'taxonomy' => 'category' ) );
  501. }
  502.  
  503. } elseif(!$category_ID && $_POST['createcats'] != "yes") {
  504. $category_ID = 1;
  505. $catname = get_cat_name( $category_ID );
  506. } elseif(isset($category_ID) && $_POST['createcats'] != "yes") {
  507. $catname = get_cat_name( $category_ID );
  508. }
  509.  
  510. $categorysave[$i][$k]["name"] = $catname;
  511. $categorysave[$i][$k]["id"] = $category_ID;
  512.  
  513. if($saveparent == 1) {$parentid = $category_ID;}
  514. }
  515. $k++;
  516. }
  517. $i++;
  518. }
  519. /*if(count($categories) == 1) {
  520. $categories["type"] = "single";
  521. } else {
  522. $categories["type"] = "multi";
  523. } */
  524. }//print_r($categorysave);
  525. $categorysave = $wpdb->escape(serialize($categorysave));
  526.  
  527. // Templates
  528. $templates = array();
  529. if($options['wpr_simple']=='Yes' && $type == "keyword") {
  530. $i = 1;
  531. foreach($wpr_loadedmodules as $lmodule) {
  532. if($_POST[$lmodule."chance"] > 0) {
  533. $templates[$i]["title"] = "{".$lmodule."title}";
  534. $templates[$i]["content"] = "{".$lmodule."}";
  535. if($lmodule == "ebay" || $lmodule == "yahoonews") {$templates[$i]["content"] .= "\n{".$lmodule."}\n{".$lmodule."}";}
  536. $templates[$i]["chance"] = $_POST[$lmodule."chance"];
  537. if($lmodule == "amazon") {$templates[$i]["comments"]["amazon"] = 1;} else {$templates[$i]["comments"]["amazon"] = 0;}
  538. if($lmodule == "flickr") {$templates[$i]["comments"]["flickr"] = 1;} else {$templates[$i]["comments"]["flickr"] = 0;}
  539. if($lmodule == "yahooanswers") {$templates[$i]["comments"]["yahooanswers"] = 1;} else {$templates[$i]["comments"]["yahooanswers"] = 0;}
  540. if($lmodule == "youtube") {$templates[$i]["comments"]["youtube"] = 1;} else {$templates[$i]["comments"]["youtube"] = 0;}
  541. $i++;
  542. }
  543. }
  544. if($_POST["mixchance"] > 0) {
  545. $templates[$i]["title"] = "{title}";
  546. $templates[$i]["content"] = stripslashes($_POST["mixcontent"]);
  547. $templates[$i]["chance"] = $_POST["mixchance"];
  548. $templates[$i]["comments"]["amazon"] = 1;
  549. $templates[$i]["comments"]["flickr"] = 1;
  550. $templates[$i]["comments"]["yahooanswers"] = 1;
  551. $templates[$i]["comments"]["youtube"] = 1;
  552. }
  553. } else {
  554. for ($i = 1; $i <= $_POST['tnum']; $i++) {
  555. if($_POST["chance$i"] > 0) {
  556. $templates[$i]["title"] = stripslashes($_POST["title$i"]);
  557. $templates[$i]["content"] = stripslashes($_POST["content$i"]);
  558. $templates[$i]["chance"] = $_POST["chance$i"];
  559. $templates[$i]["comments"]["amazon"] = $_POST["comments_amazon$i"];
  560. $templates[$i]["comments"]["flickr"] = $_POST["comments_flickr$i"];
  561. $templates[$i]["comments"]["yahooanswers"] = $_POST["comments_yahoo$i"];
  562. $templates[$i]["comments"]["youtube"] = $_POST["comments_youtube$i"];
  563. }
  564. }
  565. }
  566. //$templates = array_values($templates); -- MAKES FIRST TEMPLATE "0"
  567. $templates = $wpdb->escape(serialize($templates));
  568.  
  569. // Optional settings
  570. $amadept = $_POST['amazon_department'];
  571.  
  572. $yahoocat = array();
  573. $yahoocat["ps"] = $_POST['wpr_poststatus'];
  574. $yahoocat["rw"] = $_POST['wpr_rewriter'];
  575. $yahoocat["a"] = $_POST['wpr_author'];
  576. $yahoocat["t"] = $_POST['wpr_postthumbs'];
  577. $yahoocat["pt"] = $_POST['wpr_posttype'];
  578. $yahoocat = $wpdb->escape(serialize($yahoocat));
  579. $ebaycat = $_POST['ebay_category'];
  580.  
  581. $_POST['replace'] = stripslashes($_POST['replace']);
  582. $replaceinput = str_replace("\r", "", $_POST['replace']);
  583. $replaceinput = explode("\n", $replaceinput);
  584.  
  585. $i=0;
  586. $replaces = array();
  587. foreach( $replaceinput as $replace) {
  588. if($replace != "") {
  589. $replace = explode("|", $replace);
  590. $replaces[$i]["from"] = $replace[0];
  591. $replaces[$i]["to"] = str_replace('\"', "", $replace[1]);
  592. $replaces[$i]["chance"] = $replace[2];
  593. $replaces[$i]["code"] = $replace[3];
  594. }
  595. $i++;
  596. }
  597. $replaces = $wpdb->escape(serialize($replaces));
  598.  
  599. $_POST['exclude'] = stripslashes($_POST['exclude']);
  600. $exclude = str_replace("\r", "", $_POST['exclude']);
  601. $exclude = explode("\n", $exclude);
  602. foreach($exclude as $key => $value) {
  603. if($value == "") {
  604. unset($array[$key]);
  605. }
  606. }
  607. $exclude = array_values($exclude);
  608. $exclude = $wpdb->escape(serialize($exclude));
  609.  
  610. $name = $_POST['name'];
  611. $postevery = $_POST['interval'];
  612. $cr_period = $_POST['period'];
  613. $postspan = "WPR_" . $postevery . "_" . $cr_period;
  614.  
  615. $customfield = array();
  616. for ($i = 1; $i <= $_POST['cfnum']; $i++) {
  617. if(!empty($_POST["cf_value$i"]) && !empty($_POST["cf_name$i"])) {
  618. $customfield[$i]["name"] = $_POST["cf_name$i"];
  619. $customfield[$i]["value"] = $_POST["cf_value$i"];
  620. }
  621. }
  622. $customfield = $wpdb->escape(serialize($customfield));
  623.  
  624. $translation = array();
  625. $translation["chance"] = $_POST['transchance'];
  626. $translation["from"] = $_POST['trans1'];
  627. $translation["to1"] = $_POST['trans2'];
  628. $translation["to2"] = $_POST['trans3'];
  629. $translation["to3"] = $_POST['trans4'];
  630. $translation["comments"] = $_POST['trans_comments'];
  631. $translation = $wpdb->escape(serialize($translation));
  632.  
  633. if($_POST['autopost'] == "yes") {
  634. $pause = 0;
  635. } else {
  636. $pause = 1;
  637. }
  638.  
  639. if($_POST["edit"]) {
  640. $uid = $_POST["edit"];
  641. $update = "UPDATE " . $wpr_table_campaigns . " SET name = '$name', ctype = '$type', keywords = '$keywords'
  642. , categories = '$categorysave', templates = '$templates', cinterval = '$postevery', period = '$cr_period', postspan = '$postspan'
  643. , replacekws = '$replaces', excludekws = '$exclude', amazon_department = '$amadept', ebay_cat = '$ebaycat', yahoo_cat = '$yahoocat'
  644. , translation = '$translation', customfield = '$customfield', pause = '$pause' WHERE id = $uid";
  645. //echo $update . "<br>";
  646. $results = $wpdb->query($update);
  647. if ($results) {
  648. if($postspan != $oldcamp->postspan) {
  649.  
  650. $timestamp = wp_next_scheduled( 'wprobothook', array($uid) );
  651. wp_unschedule_event($timestamp, 'wprobothook', array($uid) );
  652.  
  653. $lag = $_POST['delaystart'] * 3600;
  654. wpr_set_schedule($postevery, $cr_period);
  655. wp_schedule_event( time()+rand(1,500)+$lag, $postspan, "wprobothook" , array($uid) );
  656. //wp_reschedule_event( $oldcamp->postspan, $postspan, "wprobothook", array($uid) ); // wp_reschedule_event( time(), $postspan, "wprobothook", array($uid) );
  657. wpr_delete_schedule($oldcamp->cinterval, $oldcamp->period);
  658. }
  659. echo '<div class="updated"><p>'.__('Campaign has been updated! Go to the <a href="?page=wpr-single&id='.$uid.'">control panel</a> to view details.', "wprobot").'</p></div>';
  660. } else {
  661. echo '<div class="updated"><p>'.__("Campaign could not be updated!", "wprobot").'</p></div>';
  662. }
  663. } else {
  664. $insert = "INSERT INTO " . $wpr_table_campaigns . " SET name = '$name', ctype = '$type', keywords = '$keywords'
  665. , categories = '$categorysave', templates = '$templates', cinterval = '$postevery', period = '$cr_period', postspan = '$postspan'
  666. , replacekws = '$replaces', excludekws = '$exclude', amazon_department = '$amadept', ebay_cat = '$ebaycat', yahoo_cat = '$yahoocat'
  667. , translation = '$translation', customfield = '$customfield', pause = '$pause'";
  668. $result = $wpdb->query($insert);
  669. $insid = mysql_insert_id();
  670.  
  671. if ($result) {
  672.  
  673. $sql = "SELECT LAST_INSERT_ID() FROM " . $wpr_table_campaigns;
  674. $id = $wpdb->get_var($sql); $linkid = $id;
  675. if($linkid != $insid) {$linkid = $insid;}
  676.  
  677. wpr_set_schedule($postevery, $cr_period);
  678. $lag = $_POST['delaystart'] * 3600;
  679. if($lag == "" || !is_numeric($lag) || $lag < 0) {$lag = 200;}
  680.  
  681. wp_schedule_event( time()+$lag, $postspan, "wprobothook" , array($id) );
  682.  
  683. $next = wp_next_scheduled( "wprobothook", array($id) );
  684. if($next == 0 || $next == "0" || $next == null || $next == "") {
  685. wp_schedule_event( time()+$lag, $postspan, "wprobothook" , array($id) );
  686. }
  687.  
  688. echo '<div class="updated"><p>';
  689. printf(__('Campaign "%1$s" has been added! Go to the <a href="?page=wpr-single&id=%2$s">control panel</a> to view details.', 'wprobot'), $name, $linkid);
  690. echo '</p></div>';
  691. }
  692. }
  693. }
  694. }
  695.  
  696. function wpr_errors() {
  697. global $wpdb, $wpr_table_campaigns, $wpr_table_templates, $wpr_table_errors, $_wp_using_ext_object_cache;
  698. $_wp_using_ext_object_cache = false;
  699.  
  700. $options = unserialize(get_option("wpr_options"));
  701. if ($options['wpr_installed'] != "yes") {
  702. echo '<div class="wrap"><h2>WP Robot</h2><div class="updated"><h3>Installation</h3><p>'.__('Please go <a href="?page=wpr-campaigns">here</a> to finish the installation of WP Robot first.', 'wprobot').'</p></div></div>';
  703. return false;
  704. }
  705.  
  706. if(!$_GET['id']) {
  707. $where = "";
  708. } else {
  709. $id = $_GET['id'];
  710. $where = " WHERE campaign = '$id'";
  711. }
  712.  
  713. if(!$_GET['keyword']) {
  714. $where2 = "";
  715. } else {
  716. $keyword = $_GET['keyword'];
  717. $where2 = " AND keyword = '$keyword'";
  718. }
  719.  
  720. if($_POST['wpr_clear_log']) {
  721. $results = $wpdb->query("DELETE FROM $wpr_table_errors$where$where2;");
  722. if($results) {
  723. echo '<div class="updated"><p>'.__('Log has been cleared.', 'wprobot').'</p></div>';
  724. } else {
  725. echo '<div class="updated"><p>'.__('Log could not be cleared.', 'wprobot').'</p></div>';
  726. }
  727. }
  728.  
  729. $errors = $wpdb->get_results("SELECT * FROM " . $wpr_table_errors . "$where$where2 ORDER BY id DESC LIMIT 100");
  730.  
  731. include("display-errors.php");
  732.  
  733. }
  734.  
  735. function wpr_campaign_controls() {
  736. global $wpdb, $wpr_table_campaigns, $wpr_table_templates;
  737.  
  738. if($_POST['pause']) {
  739. if($_POST["delete"] == "" || $_POST["delete"] == 0 || $_POST["delete"] == null) {
  740. echo '<div class="updated"><p>'.__('Please select at least one campaign!', 'wprobot').'</p></div>';
  741. } else {
  742. foreach ($_POST['delete'] as $key => $value) {
  743. $result = $wpdb->update( $wpr_table_campaigns, array( 'pause' => 1 ), array( 'ID' => $value ), array( '%d' ), array( '%d' ) );
  744. }
  745. }
  746. echo '<div class="updated"><p>'.__('Campaigns have been paused.', 'wprobot').'</p></div>';
  747. }
  748.  
  749. if($_POST['continue']) {
  750. if($_POST["delete"] == "" || $_POST["delete"] == 0 || $_POST["delete"] == null) {
  751. echo '<div class="updated"><p>'.__('Please select at least one campaign!', 'wprobot').'</p></div>';
  752. } else {
  753. foreach ($_POST['delete'] as $key => $value) {
  754. $result = $wpdb->update( $wpr_table_campaigns, array( 'pause' => 0 ), array( 'ID' => $value ), array( '%d' ), array( '%d' ) );
  755. }
  756. }
  757. echo '<div class="updated"><p>'.__('Campaigns have been continued.', 'wprobot').'</p></div>';
  758. }
  759.  
  760. if($_GET['pause']) {
  761. $pause = $_GET['pause'];
  762. $wpdb->update( $wpr_table_campaigns, array( 'pause' => 1 ), array( 'ID' => $pause ), array( '%d' ), array( '%d' ) );
  763. echo '<div class="updated"><p>'.__('Campaign has been paused.', 'wprobot').'</p></div>';
  764. }
  765.  
  766. if($_GET['unpause']) {
  767. $pause = $_GET['unpause'];
  768. $wpdb->update( $wpr_table_campaigns, array( 'pause' => 0 ), array( 'ID' => $pause ), array( '%d' ), array( '%d' ) );
  769. echo '<div class="updated"><p>'.__('Campaign has been continued.', 'wprobot').'</p></div>';
  770. }
  771.  
  772. if($_GET['delete'] && !$_POST['deleteall']) {
  773. $_POST["delete"] = array($_GET["delete"]);
  774. wpr_delete_campaign();
  775. }
  776.  
  777. if($_POST['deleteall']) {
  778. if($_POST["delete"] == "" || $_POST["delete"] == 0 || $_POST["delete"] == null) {
  779. echo '<div class="updated"><p>Please select at least one campaign!</p></div>';
  780. } else {
  781. wpr_delete_campaign();
  782. }
  783. }
  784.  
  785. if($_POST['wpr_runnow'] || $_GET['wpr_runnow']) {
  786. if($_POST['wpr_runnow']) {
  787. $_GET['wpr_runnow'] = false;
  788. if($_POST["delete"] == "" || $_POST["delete"] == 0 || $_POST["delete"] == null) {
  789. echo '<div class="updated"><p>'.__('Please select at least one campaign!', 'wprobot').'</p></div>';
  790. } else {
  791. $posted = 0;
  792. $skipped = 0;
  793. $bulk = $_POST["wpr_bulk"];
  794. $delete = $_POST["delete"];
  795. $array = implode(",", $delete);
  796.  
  797. if($bulk == "" || $bulk == 0 || $bulk == null) {$bulk = 1;}
  798.  
  799. if($_POST['time'] && $_POST['backdate'] == "yes") {
  800. $sp1 = $_POST['timespace'];
  801. $sp2 = $_POST['timespace2'];
  802. $time = explode("-", $_POST['time']);
  803. }
  804.  
  805. for($i=0; $i < $bulk; $i++) {
  806. foreach ($_POST['delete'] as $key => $value) {
  807.  
  808. if($_POST['kws']) {
  809. $keywords = $_POST['kws'];
  810. $keyword = $keywords[array_rand($keywords)];
  811. } else {
  812. $keyword = "";
  813. }
  814.  
  815. if($_POST['time'] && $_POST['backdate'] == "yes") {
  816. $comment_date = mktime(rand(0,23), rand(0, 59), rand(0, 59), $time[1], $time[2] + $i* rand($sp1,$sp2), $time[0]);
  817. $_POST['postdate']=date("Y-m-d H:i:s", $comment_date);
  818. }
  819. $result = wpr_poster($value,$keyword,1);
  820. if($result == true) {$posted++;} else {$skipped++;}
  821. }
  822. }
  823. if($posted > 0) {
  824.  
  825. echo '<div class="updated"><p>';
  826. printf(__('%1$s posts have been created successfully %2$s', 'wprobot'), $posted, $sktxt);
  827. if($skipped > 0) {printf(__(' and %1$s posts have been skipped. Please see the <a href="?page=wpr-log">error log</a> for details.', 'wprobot'), $skipped);} else {$sktxt = '';}
  828. echo '</p></div>';
  829. } else {
  830. echo '<div class="updated"><p>';
  831. printf(__('Error: %1$s posts could not be created. Please see the <a href="?page=wpr-log">error log</a> for details.', 'wprobot'), $skipped);
  832. echo '</p></div>';
  833. }
  834. }
  835. } elseif($_GET['wpr_runnow'] && !$_POST['wpr_post'] && !$_POST['wpr_deleteit']) {
  836. $result = wpr_poster($_GET['wpr_runnow'],$_GET['keyword'],1);
  837. if($result == true) {
  838. echo '<div class="updated"><p>'.__('Post has been created successfully!', 'wprobot').'</p></div>';
  839. } else {
  840. echo '<div class="updated"><p>';
  841. printf(__('Error: Post could not be created. Please see the <a href="?page=wpr-log&id=%1$s">error log</a> for details.', 'wprobot'), $_GET['wpr_runnow']);
  842. echo '</p></div>';
  843. }
  844. }
  845. }
  846. }
  847.  
  848. function wpr_single() {
  849. global $wpdb, $wpr_table_campaigns, $wpr_table_templates, $wpr_table_errors, $_wp_using_ext_object_cache;
  850. $_wp_using_ext_object_cache = false;
  851.  
  852. wpr_campaign_controls();
  853. $options = unserialize(get_option("wpr_options"));
  854.  
  855. if(!$_GET['id']) {
  856. _e("Error: No Campaign ID specified", 'wprobot');
  857. } else {
  858. $id = $_GET['id'];
  859. $result = $wpdb->get_row("SELECT * FROM " . $wpr_table_campaigns . " WHERE id = '$id'");
  860. $keywords = unserialize($result->keywords);
  861. $categories = unserialize($result->categories);
  862. if(!empty($categories[0]["id"])) {$categories = wpr_transform_cats($categories);}
  863. $templates = unserialize($result->templates);
  864.  
  865. if($_POST['resetkws']){
  866. $i = 0;
  867. foreach($keywords as $keyword) {
  868. if($keywords[$i]["skipped"] > 2) {
  869. $keywords[$i]["skipped"] = 0;
  870. }
  871. $i++;
  872. }
  873. $keywords2 = $wpdb->escape(serialize($keywords));
  874. $sql = "UPDATE " . $wpr_table_campaigns . " SET `keywords` = '".$keywords2."' WHERE `id` = '".$id."'";
  875.  
  876. $results = $wpdb->query($sql);
  877. if ($results) {
  878. echo '<div class="updated"><p>'.__('All disabled keywords have been reset.', 'wprobot').'</p></div>';
  879. $result = $wpdb->get_row("SELECT * FROM " . $wpr_table_campaigns . " WHERE id = '$id';");
  880. $keywords = unserialize($result->keywords);
  881. } else {
  882. echo '<div class="updated"><p>'.__('Error: Keywords could not be reset!', 'wprobot').'</p></div>';
  883. }
  884. }
  885.  
  886. if($_POST['deletekws']){
  887. $dkws = $_POST['kws'];
  888. if(!empty($dkws)) {
  889. foreach($keywords as $key => $keyword) {
  890. if($result->ctype == "keyword") {$ksearch = $keyword[0];} elseif($result->ctype == "rss") {$ksearch = $keyword["feed"];} elseif($result->ctype == "nodes") {$ksearch = $keyword["node"];}
  891. if(in_array($ksearch, $dkws)) {
  892. unset($keywords[$key]);
  893. unset($categories[$key]);
  894. }
  895. }
  896. $keywords = array_values($keywords);
  897. $categories = array_values($categories); // PROBLEM: MAKES [type] value to [1] !!!
  898. $keywords2 = serialize($keywords);
  899. $categories2 = serialize($categories);
  900. $sql = "UPDATE " . $wpr_table_campaigns . " SET `keywords` = '".$keywords2."', `categories` = '".$categories2."' WHERE `id` = '".$id."'";
  901. $results = $wpdb->query($sql);
  902. if ($results) {
  903. echo '<div class="updated"><p>'.__('Keywords have been deleted.', 'wprobot').'</p></div>';
  904. } else {
  905. echo '<div class="updated"><p>'.__('Error: Keywords could not be deleted!', 'wprobot').'</p></div>';
  906. }
  907. } else {
  908. echo '<div class="updated"><p>'.__('Error: Please select at least one keyword!', 'wprobot').'</p></div>';
  909. }
  910. }
  911.  
  912. if($_GET['kwdelete']){
  913. foreach($keywords as $key => $keyword) {
  914. if($keyword[0] == $_GET['keyword']) {
  915. unset($keywords[$key]);
  916. unset($categories[$key]);
  917. }
  918. }
  919. $keywords = array_values($keywords);
  920. $categories = array_values($categories);
  921. $keywords2 = serialize($keywords);
  922. $categories2 = serialize($categories);
  923. $sql = "UPDATE " . $wpr_table_campaigns . " SET `keywords` = '".$keywords2."', `categories` = '".$categories2."' WHERE `id` = '".$id."'";
  924. $results = $wpdb->query($sql);
  925. if ($results) {
  926. echo '<div class="updated"><p>'.__('Keyword has been deleted.', 'wprobot').'</p></div>';
  927. } else {
  928. echo '<div class="updated"><p>'.__('Error: Keyword could not be deleted!', 'wprobot').'</p></div>';
  929. }
  930. }
  931.  
  932. $errors = $wpdb->get_results("SELECT * FROM " . $wpr_table_errors . " WHERE campaign = '$id' ORDER BY id DESC LIMIT 10");
  933.  
  934. include("display-single.php");
  935. }
  936. }
  937.  
  938. function wpr_install_new_modules($newmodules,$options) {
  939. global $wpr_loadedmodules,$wpdb,$wpr_table_templates;
  940.  
  941. $email = $options["wpr_email"];
  942. if ( function_exists('curl_init') ) {
  943. $request = "http://wprobot.net/robotpal/wprinstall.php";
  944. $newmodules2 = serialize($newmodules);
  945. if(WPLANG == "de_DE") {$ger = 1;} elseif(WPLANG == "zh_CN") {$ger = 2;} else {$ger = 0;}
  946. $post="email=".base64_encode($email)."&modules=".$newmodules2."&ger=".$ger;
  947. $ch = curl_init();
  948. curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Konqueror/4.0; Microsoft Windows) KHTML/4.0.80 (like Gecko)");
  949. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  950. curl_setopt($ch, CURLOPT_URL, $request);
  951. curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  952. curl_setopt($ch, CURLOPT_TIMEOUT, 60);
  953. $response = curl_exec($ch);
  954. curl_close($ch);
  955. } else {
  956. $response = @file_get_contents($request);
  957. }
  958.  
  959. if( $response == "false" || !$response) {
  960. } else {
  961. $responses = explode("###",$response);
  962. $sql = $responses[1];
  963. $options = unserialize(get_option("wpr_options"));
  964.  
  965. if(isset($sql)) {
  966. $sql = str_replace("{wpr_template}",$wpr_table_templates,$sql);
  967. $result = $wpdb->query($sql);
  968. }
  969. if($result) {
  970. foreach($newmodules as $module) {
  971. $options = wpr_default_options_single($module,$options);
  972. }
  973. $options["wpr_installed_modules"] = $wpr_loadedmodules;
  974. update_option("wpr_options", serialize($options));
  975. echo '<div class="updated"><p>'.__('New module files have been found and installed successfully.', 'wprobot').'</p></div>';
  976. } else {
  977. echo '<div class="updated"><p>'.__('Error: New module files have been found but installation failed. Is the Paypal Email you have entered in the Options still correct?', 'wprobot').'</p></div>';
  978. }
  979. }
  980. }
  981.  
  982. function wpr_install_check_modules($options) {
  983. global $wpr_loadedmodules;
  984.  
  985. $installed_modules = $options["wpr_installed_modules"];
  986.  
  987. $newmodules = array();
  988. if(is_array($installed_modules)) {
  989. foreach($wpr_loadedmodules as $module) {
  990. if(!in_array($module, $installed_modules)) {
  991. if($module != "translation" && $module != "articlebuilder" && $module != "bigcontentsearch" && $module != "kontentmachine") {
  992. $newmodules[] = $module;
  993. }
  994. }
  995. }
  996. }
  997.  
  998. if(!empty($newmodules)) {wpr_install_new_modules($newmodules,$options);}
  999. }
  1000.  
  1001. function wpr_update_email($currentemail,$newemail,$updatecore=0) {
  1002.  
  1003. if($currentemail == $newemail && $updatecore == 0) {
  1004. echo '<div class="updated"><p>'.__('Error: Email has not been changed.', 'wprobot').'</p></div>';
  1005. return false;
  1006. } elseif(empty($newemail)) {
  1007. echo '<div class="updated"><p>'.__('Error: Email can not be empty.', 'wprobot').'</p></div>';
  1008. return false;
  1009. }
  1010.  
  1011. // Send email AND modules to Server
  1012. if ( function_exists('curl_init') ) {
  1013. $request = "http://wprobot.net/robotpal/wprinstall.php";
  1014. $post="email=".base64_encode($newemail)."&modules=&site=".get_bloginfo('url');
  1015. $ch = curl_init();
  1016. curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Konqueror/4.0; Microsoft Windows) KHTML/4.0.80 (like Gecko)");
  1017. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1018. curl_setopt($ch, CURLOPT_URL, $request);
  1019. curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  1020. curl_setopt($ch, CURLOPT_TIMEOUT, 60);
  1021. $response = curl_exec($ch);
  1022. if (!$response) {
  1023. echo '<div class="updated"><p>'.__('cURL Error: ', 'wprobot').' '.curl_error($ch).'</p></div>';
  1024. return false;
  1025. }
  1026. curl_close($ch);
  1027. } else {
  1028. $response = @file_get_contents($request);
  1029. if (!$response) {
  1030. echo '<div class="updated"><p>'.__('Error: cURL is not installed on this server.', 'wprobot').'</p></div>';
  1031. return false;
  1032. }
  1033. }
  1034.  
  1035. if( $response == "false" || !$response) {
  1036. echo '<div class="updated"><p>'.__('Error: No record was found for the email you entered.', 'wprobot').'</p></div>';
  1037. } else {
  1038. $responses = explode("###",$response);
  1039. $sql = $responses[1];
  1040. $core = $responses[0];
  1041. $options = unserialize(get_option("wpr_options"));
  1042. $options["wpr_email"] = $newemail;
  1043. $options["wpr_core"] = $core;
  1044. // - Setup Core Option
  1045. if($core == "elite" || $core == "advanced" || $core == "developer" || $core == "devclient") {$options["createposts"] = "no";} else {$options["createposts"] = "yes";}
  1046.  
  1047. update_option("wpr_options", serialize($options));
  1048. echo '<div class="updated"><p>'.__('Paypal Email has been updated successfully.', 'wprobot').'</p></div>';
  1049. return $options["wpr_email"];
  1050. }
  1051.  
  1052. }
  1053.  
  1054. function wpr_install_function($email) {
  1055. global $wpr_loadedmodules,$wpdb,$wpr_table_templates;
  1056.  
  1057. $options = wpr_default_options(1);
  1058.  
  1059. if($email == "demo" || $email == "Demo" || $email == "DEMO") {
  1060.  
  1061. // Insert Templates
  1062. $sql = "INSERT INTO $wpr_table_templates ( type, typenum, content, title, comments_amazon, comments_flickr, comments_yahoo, comments_youtube, name ) VALUES ";
  1063. $sql .= " ( 'clickbank', '0', '<strong>{title}</strong>\r\n{description}\r\n{link}', '', '0', '0', '0', '0', '' ),";
  1064. $sql .= " ( 'twitter', '0', '{tweet} - <i>by {author}</i>\r\n', '', '0', '0', '0', '0', '' ),";
  1065. $sql .= " ( 'pressrelease', '0', '{pressrelease}\r\n', '', '0', '0', '0', '0', '' ),";
  1066. $sql .= " ( 'shopzilla', '0', '<strong><a href=\"{url}\" rel=\"nofollow\">{title} [select:Price Comparison|Best Prices|Top Offers|Top Deals]</a></strong>\r\n{description}\r\n{offers}', '', '0', '0', '0', '0', '' ),";
  1067. $sql .= " ( 'post', '5', '{shopzilla}', '{shopzillatitle}', '0', '0', '0', '0', 'Shopzilla Default' ),";
  1068. $sql .= " ( 'post', '5', '{pressrelease}\r\n[random:50][select:More <a href=\"{catlink}\">{Keyword} Press Releases</a>|Related <a href=\"{catlink}\">{Keyword} Press Releases</a>|Find More <a href=\"{catlink}\">{Keyword} Press Releases</a>][/random]', '{pressreleasetitle}', '0', '0', '0', '0', 'Press Release Default' ),";
  1069. $sql .= " ( 'post', '4', '[random:25]<p>[select:Check out these {keyword} products:|A few {keyword} products I can recommend:]</p>[/random]\r\n{clickbank}\r\n\r\n{clickbank}\r\n\r\n[random:25]{clickbank}[/random]', '{clickbanktitle}', '0', '0', '0', '0', 'Clickbank Default' );";
  1070. $result = $wpdb->query($sql);
  1071.  
  1072. // - Setup Installed Option
  1073. if($result) {
  1074. $options["wpr_installed"] = "yes";
  1075. $options["wpr_installed_modules"] = $wpr_loadedmodules;
  1076. $options["wpr_email"] = "demo";
  1077. $options["wpr_core"] = "basic";
  1078. $options["createposts"] = "yes";
  1079. update_option("wpr_options", serialize($options));
  1080. $optionsurl = get_option('siteurl') . '/wp-admin/options-general.php';
  1081. $cronurl = WPR_URLPATH . 'cron.php?code='.get_option("wpr_cron");
  1082. echo '<div class="wrap"><h2>WP Robot</h2><div class="updated" style="line-height:18px;">'.__('<h3 style="margin: 5px 0 0 0;">Success!</h3><br/><b>Thanks for installing the WP Robot 4 Demo Version!</b> This demo can be used for an unlimited amount of time but and includes several free modules. You can <a href="http://wprobot.net/order/">upgrade to the full version here</a> in order to get more features and use all 20+ content sources.
  1083. <br/><br/>For instructions take a look at this <a href="http://wprobot.net/documentation/quickstart.php" target="_blank">quick start guide</a> or the <a href="http://wprobot.net/documentation/" target="_blank">online documentation</a>!', 'wprobot');
  1084. } else {
  1085. if (is_multisite()) {
  1086. echo '<div class="updated"><p>'.__('Error: WP Robot could not be installed. Please note "Network Activate" will not work for WP Robot. You need to activate it on each subblog individually to complete the installation.', 'wprobot').'</p></div>';
  1087. } else {
  1088. echo '<div class="updated"><p>'.__('Error: WP Robot could not be installed.', 'wprobot').'</p></div>';
  1089. }
  1090. }
  1091.  
  1092. } else {
  1093.  
  1094. // Send email AND modules to Server
  1095. if ( function_exists('curl_init') ) {
  1096. $request = "http://wprobot.net/robotpal/wprinstall.php";
  1097. $wpr_loadedmodules2 = serialize($wpr_loadedmodules);
  1098. if(WPLANG == "de_DE") {$ger = 1;} else {$ger = 0;}
  1099. $post="email=".base64_encode($email)."&modules=".$wpr_loadedmodules2."&site=".get_bloginfo('url')."&ger=".$ger;
  1100. $ch = curl_init();
  1101. curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Konqueror/4.0; Microsoft Windows) KHTML/4.0.80 (like Gecko)");
  1102. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1103. curl_setopt($ch, CURLOPT_URL, $request);
  1104. curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  1105. curl_setopt($ch, CURLOPT_TIMEOUT, 60);
  1106. $response = curl_exec($ch);
  1107. if (!$response) {
  1108. $response = @file_get_contents($request);
  1109. if (!$response) {
  1110. echo '<div class="updated"><p>'.__('cURL Error: ', 'wprobot').' '.curl_error($ch).'</p></div>';
  1111. return false;
  1112. }
  1113. }
  1114. curl_close($ch);
  1115. } else {
  1116. $response = @file_get_contents($request."?".$post);
  1117. if (!$response) {
  1118. echo '<div class="updated"><p>'.__('Error: cURL is not installed on this server.', 'wprobot').'</p></div>';
  1119. return false;
  1120. }
  1121. }
  1122. //echo $response;
  1123. // If FALSE -> Error
  1124. if($email !== "nulledbyimsoldiers@imsoldiers.com") {
  1125. echo '<div class="updated"><p>'.__('Error: Wrong Email.', 'wprobot').'</p></div>';
  1126. return false;
  1127.  
  1128. } else {
  1129. //$responses = explode("###",$response);
  1130. //$sql = $responses[1];
  1131. $core = $responses[0];
  1132.  
  1133. if($core == "elite" || $core == "advanced" || $core == "developer" || $core == "devclient") {$options["createposts"] = "no";} else {$options["createposts"] = "yes";}
  1134.  
  1135. if(isset($sql)) {
  1136. $sql = str_replace("{wpr_template}",$wpr_table_templates,$sql);
  1137. $result = $wpdb->query($sql);
  1138. }
  1139.  
  1140. if( 1===1 ) {
  1141. $options["wpr_installed"] = "yes";
  1142. $options["wpr_installed_modules"] = $wpr_loadedmodules;
  1143. $options["wpr_email"] = $email;
  1144. $options["wpr_core"] = $core;
  1145. $options["wpr_sql"] = "";
  1146. update_option("wpr_options", serialize($options));
  1147. update_option("wpr_sql", serialize($sql));
  1148. $optionsurl = get_option('siteurl') . '/wp-admin/options-general.php';
  1149. $cronurl = WPR_URLPATH . 'cron.php?code='.get_option("wpr_cron");
  1150. echo '<div class="wrap"><h2>WP Robot</h2><div class="updated" style="line-height:18px;">'.__('<h3 style="margin: 5px 0 0 0;">Success!</h3><b>WP Robot has been installed successfully!</b> You can now navigate to the WP Robot admin area with the links on the bottom of the sidebar and might want to start by <a href="?page=wpr-options">setting up your options</a> and then <a href="?page=wpr-add">creating your first campaign</a>. Before that please read on.
  1151. <br/><br/>
  1152. <h3 style="margin: 5px 0 0 0;">Autoposting in WP Robot</h3>
  1153. Please read the following to understand how autoposting works in WP Robot and how to make sure that the plugin functions correctly for you.<br/><br/>
  1154.  
  1155. <b>Wordpress Cron Functions</b><br/>
  1156. By default WP Robot uses Wordpress\' built in cron functions to schedule posts. While no additional setup is necessary for those they have a few disadvantages, namely they are only run when a visitor visits your site, consume more server ressources and are not 100% reliable.<br/><br/>', 'wprobot');
  1157.  
  1158. printf(__('To use the Wordpress cron functions make sure your server time setting and <a href="%1$s">Wordpress time settings</a> (i.e. timezone) are correct. The following should show the right time for where you are:', 'wprobot'), $optionsurl);
  1159. echo '<br />'.
  1160. __('<strong>UTC time: </strong>', 'wprobot').gmdate('d F, Y H:i:s', current_time('timestamp', true)).'<br />'.
  1161. __('<strong>Your time: </strong>', 'wprobot').gmdate('d F, Y H:i:s', current_time('timestamp')).'<br /><br />'.
  1162.  
  1163. __('Please also note that certain other 3rd party Wordpress plugins can interfere with WP Robots autoposting. If you ever see the year for next post dates as "1970" or "1969" this is most likely such a conflict and you should try disabling all your other plugins temporarily first of all before contacting support.<br/><br/>
  1164.  
  1165. <b>Unix Cron Job</b><br/>
  1166. As an alternative you can set up an Unix Cron Job in your webhosts control panel (often cPanel) to create automatic posts. This will use less ressources on your server and be more reliable than the Wordpress solution. To set up a cron job you need to use the following URL:', 'wprobot').'<br /><strong>'.
  1167. $cronurl.
  1168. '</strong><br /><br /></div></div>';
  1169. } else {
  1170. echo '<div class="updated"><p>'.__('Error: WP Robot could not be installed.', 'wprobot').'</p></div>';
  1171. }
  1172. }
  1173. }
  1174. }
  1175.  
  1176. function wpr_install_message() {
  1177.  
  1178. if(isset($_POST['wpr_install_message'])) {
  1179. if(empty($_POST['wpr_install_email']) || !strpos($_POST['wpr_install_email'], "@") && $_POST['wpr_install_email'] != "demo") {
  1180. echo '<div class="updated"><p>'.__('Error: Please enter a valid email address or "demo".', 'wprobot').'</p></div>';
  1181. } else {
  1182. wpr_install_function($_POST['wpr_install_email']);
  1183. }
  1184. } else {
  1185. echo '<div class="wrap"><h2>WP Robot</h2><div class="updated"><h3>Installation</h3><p>'.__('Please enter your Paypal email you bought WP Robot with below and click "install" to finish the installation of WP Robot.', 'wprobot').'</p>
  1186. <form method="post" id="wpr_install">
  1187. <strong>Paypal Email:</strong> <input id="wpr_install_email" class="regular-text" type="text" value="" name="wpr_install_email"/>
  1188. <input class="button-primary" type="submit" name="wpr_install_message" value="'.__('Install', 'wprobot').'" />
  1189. </form>
  1190. <br/><br/>
  1191. '.__('- If you want to use the WP Robot Demo enter "<b>demo</b>"!', 'wprobot').'<br/>
  1192. '.__('- Otherwise enter the exact Paypal email you have used to purchase your copy of WP Robot.', 'wprobot').'<br/>
  1193. '.__('- Please note some Paypal accounts have several emails associated with them. If this is the case for you try all emails!', 'wprobot').'<br/>
  1194. '.__('- Do not tell other people your Paypal email in order to use it with WP Robot. Doing this purposefully can get your license suspended!', 'wprobot').'<br/>
  1195. <br/>
  1196. </div>
  1197. </div>';
  1198. }
  1199. }
  1200.  
  1201. function wpr_cc($core) {
  1202. global $wpr_loadedmodules,$wpr_modules;
  1203. if($core == "basic") {_e('Your WP Robot includes the <b>Basic Core</b>. You can use the plugin on up to 20 of your own websites. <a href="http://wprobot.net/order/ordercustom.php">Go here to upgrade!</a>', 'wprobot');}
  1204. elseif($core == "advanced") {_e('Your WP Robot includes the <b>Advanced Core</b>. You can use the plugin on up to 40 of your own websites. <a href="http://wprobot.net/order/ordercustom.php">Go here to upgrade!</a>', 'wprobot');}
  1205. elseif($core == "elite") {_e('Your WP Robot includes the <b>Elite Core</b>. You can use the plugin on an unlimited number of your own websites. To sell websites that include WP Robot you have to upgrade to the <a href="http://wprobot.net/order/dev.php">developer license</a>, otherwise you risk that your license gets banned!', 'wprobot');}
  1206. elseif($core == "developer") {_e('You are using a <b>Developer Version</b> of WP Robot. This means you can sell this website and include WP Robot with the sale. If you do so please <a href="http://wprobot.net/robotpal/devregister.php">register a sublicense for your client</a> here and make sure to insert the clients email in the WP Robot Options BEFORE transfering the website to him!', 'wprobot');}
  1207. elseif($core == "devclient") {_e('You are using a <b>Developer (client) Version</b> of WP Robot you received with a website you purchased. You may use WP Robot on two additional websites besides the one you received the plugin with. <b>If you want to use WP Robot on an unlimited number of your own websites you can <a href="/order/devupgrade.php">upgrade here</a>!</b>', 'wprobot');}
  1208.  
  1209. echo "<br/><br/>";
  1210. $lcount = count($wpr_loadedmodules);
  1211. $mcount = count($wpr_modules);
  1212. printf(__('You have %1$s modules of %2$s available modules installed. You can <a href="http://wprobot.net/order/ordercustom.php">get new modules</a> here.', 'wprobot'), $lcount, $mcount);
  1213. }
  1214.  
  1215. function wpr_toplevel() {
  1216. global $wpdb, $wpr_table_campaigns, $wpr_table_templates, $_wp_using_ext_object_cache;
  1217.  
  1218. $_wp_using_ext_object_cache = false;
  1219.  
  1220. $options = get_option("wpr_options");
  1221. if(is_array($options) || empty($options)) {} else {$options = unserialize($options);}
  1222.  
  1223. if ($options['wpr_installed'] != "yes") {wpr_install_message();} else {
  1224.  
  1225. $rw_options = get_option("allrewriters_settings");
  1226. if(empty($rw_options)) {$rw_options = ar_activate($options);}
  1227.  
  1228. wpr_install_check_modules($options);
  1229.  
  1230. wpr_campaign_controls();
  1231.  
  1232. include("display-campaigns.php");
  1233.  
  1234. }
  1235. }
  1236.  
  1237. function wpr_add() {
  1238. global $wpdb, $wpr_table_campaigns, $wpr_table_templates,$wpr_loadedmodules, $_wp_using_ext_object_cache;
  1239. $_wp_using_ext_object_cache = false;
  1240.  
  1241. $options = unserialize(get_option("wpr_options"));
  1242. $wpr_disabledmodules = $options["disabled_modules"];
  1243. if(!is_array($wpr_disabledmodules)) {$wpr_disabledmodules = array();}
  1244.  
  1245. if ($options['wpr_installed'] != "yes") {
  1246. echo '<div class="wrap"><h2>WP Robot</h2><div class="updated"><h3>Installation</h3><p>'.__('Please go <a href="?page=wpr-campaigns">here</a> to finish the installation of WP Robot first.', 'wprobot').'</p></div></div>';
  1247. return false;
  1248. }
  1249.  
  1250. if($options["wpr_core"] == "advanced" || $options["wpr_core"] == "basic") {
  1251. if(!$_GET['edit']) {
  1252. if($options["wpr_core"] == "basic") {$lmt = 3;}
  1253. if($options["wpr_core"] == "advanced") {$lmt = 6;}
  1254. $count = $wpdb->get_var("SELECT COUNT(*) FROM ".$wpr_table_campaigns);
  1255. if($count >= $lmt) {
  1256. echo '<div class="wrap"><h2>WP Robot</h2><div class="updated"><h3>Limit Reached</h3><p>'.__('Only '.$lmt.' Campaigns per site can be used with the '.$options["wpr_core"].' Core. You can upgrade <a href="http://wprobot.net/order/ordercustom.php">here</a>.', 'wprobot').'</p></div></div>';
  1257. return false;
  1258. }
  1259. }
  1260. }
  1261.  
  1262. $skippedx = 0;
  1263. $templates = $wpdb->get_results("SELECT * FROM " . $wpr_table_templates . " WHERE `type` = 'post'");
  1264. foreach($templates as $template) {
  1265. $skipmod = 0;
  1266. $modulen = strtolower(str_replace(" ", "", str_replace(" Default", "", $template->name)));
  1267. if(!in_array($modulen, $wpr_disabledmodules)) {
  1268.  
  1269. // amazon, articlebuilder, flickr, yahooanswers, commissionjunction, oodle, shopzilla, linkshare, eventful, yelp, avantlink
  1270. if($modulen == "amazon" && empty($options['wpr_aa_apikey'])) {$skipmod = 1;}
  1271. if($modulen == "articlebuilder" && empty($options['wpr_ab_email'])) {$skipmod = 1;}
  1272. if($modulen == "flickr" && empty($options['wpr_fl_apikey'])) {$skipmod = 1;}
  1273. if($modulen == "yahooanswers" && empty($options['wpr_yap_appkey'])) {$skipmod = 1;}
  1274. if($modulen == "commissionjunction" && empty($options['wpr_commissionjunction_appkey'])) {$skipmod = 1;}
  1275. if($modulen == "oodle" && empty($options['wpr_oodle_appkey'])) {$skipmod = 1;}
  1276. if($modulen == "shopzilla" && empty($options['wpr_shopzilla_appkey'])) {$skipmod = 1;}
  1277. if($modulen == "linkshare" && empty($options['wpr_linkshare_appkey'])) {$skipmod = 1;}
  1278. if($modulen == "eventful" && empty($options['wpr_eventful_appkey'])) {$skipmod = 1;}
  1279. if($modulen == "yelp" && empty($options['wpr_yelp_appkey'])) {$skipmod = 1;}
  1280. if($modulen == "avantlink" && empty($options['wpr_avantlink_appkey'])) {$skipmod = 1;}
  1281.  
  1282. if($skipmod == 0) {
  1283. $presets[$template->name]["content"] = $template->content;
  1284. $presets[$template->name]["title"] = $template->title;
  1285. $presets[$template->name]["comments_amazon"] = $template->comments_amazon;
  1286. $presets[$template->name]["comments_flickr"] = $template->comments_flickr;
  1287. $presets[$template->name]["comments_yahoo"] = $template->comments_yahoo;
  1288. $presets[$template->name]["comments_youtube"] = $template->comments_youtube;
  1289. } else {
  1290. $skippedx++;
  1291. }
  1292. }
  1293. }
  1294.  
  1295.  
  1296. if($_POST['catbut']){
  1297. if($_POST['multisingle'] == "multi") {$_POST['multisingle'] = "single";} else {$_POST['multisingle'] = "multi";$_POST['categories'] = "";}
  1298. }
  1299.  
  1300. if($_POST['importwpr2']) {
  1301. $ma_dbtable = $wpdb->prefix . "wprobot";
  1302. $records = $wpdb->get_results("SELECT * FROM " . $ma_dbtable . " ORDER BY id ASC");
  1303. if ($records) {
  1304. $_POST["keywords"] = "";
  1305. foreach ($records as $record) {
  1306. if(!empty($record->keyword)) {
  1307. $_POST["keywords"] .= '"'.$record->keyword .'"'. "\n";
  1308. }
  1309. }
  1310. }
  1311. }
  1312.  
  1313. if($_POST['exact']) {
  1314. $keywordsinput = str_replace("\r", "", $_POST['keywords']);
  1315. $keywordsinput = explode("\n", $keywordsinput);
  1316. $_POST["keywords"] = "";
  1317. for ($i = 0; $i < count($keywordsinput); $i++) {
  1318. if($keywordsinput[$i] != "") {
  1319. $_POST["keywords"] .= '"'.$keywordsinput[$i] .'"'. "\n";
  1320. }
  1321. }
  1322. }
  1323.  
  1324. if($_POST['evenchance']) {
  1325. $chance = floor(100 / $_POST['tnum']);
  1326. $tchance = 0;
  1327. for ($i = 1; $i <= $_POST['tnum']; $i++) {
  1328. $_POST["chance$i"] = $chance;
  1329. $tchance = $tchance + $chance;
  1330. }
  1331. if($tchance != 100) {$_POST["chance1"] = $_POST["chance1"] + (100 - $tchance); }
  1332. }
  1333.  
  1334. if($_POST['quickrand']) {
  1335. $count = count($presets);
  1336. $_POST['tnum'] = rand(2,$count);
  1337. $rand_keys = array_rand($presets, $_POST['tnum']);
  1338. $chance = floor(100 / $_POST['tnum']);
  1339. $i = 1;
  1340. $tchance = 0;
  1341. foreach($rand_keys as $rand_key) {
  1342. $_POST["chance$i"] = $chance;
  1343. $tchance = $tchance + $chance;
  1344. $_POST["title$i"] = $presets[$rand_key]["title"];
  1345. $_POST["content$i"] = $presets[$rand_key]["content"];
  1346. $_POST["comments_amazon$i"] = $presets[$rand_key]["comments_amazon"];
  1347. $_POST["comments_flickr$i"] = $presets[$rand_key]["comments_flickr"];
  1348. $_POST["comments_yahoo$i"] = $presets[$rand_key]["comments_yahoo"];
  1349. $_POST["comments_youtube$i"] = $presets[$rand_key]["comments_youtube"];
  1350. $i++;
  1351. }
  1352. if($tchance != 100) {$_POST["chance1"] = $_POST["chance1"] + (100 - $tchance); }
  1353. }
  1354.  
  1355. if($_POST['quick']) {
  1356. $count = count($presets);
  1357. $_POST['tnum'] = $count;
  1358. $chance = floor(100 / $count);
  1359. $i = 1;
  1360. $tchance = 0;
  1361. foreach($presets as $prx => $preset) {
  1362. $_POST["chance$i"] = $chance;
  1363. $tchance = $tchance + $chance;
  1364. $_POST["title$i"] = $preset["title"];
  1365. $_POST["content$i"] = $preset["content"];
  1366. $_POST["name$i"] = $prx;
  1367. $_POST["comments_amazon$i"] = $preset["comments_amazon"];
  1368. $_POST["comments_flickr$i"] = $preset["comments_flickr"];
  1369. $_POST["comments_yahoo$i"] = $preset["comments_yahoo"];
  1370. $_POST["comments_youtube$i"] = $preset["comments_youtube"];
  1371. $i++;
  1372. }
  1373. if($tchance != 100) {$_POST["chance1"] = $_POST["chance1"] + (100 - $tchance); }
  1374. }
  1375.  
  1376. if($_POST['type1']) {
  1377. $_POST['type'] = "keyword";
  1378. if($options['wpr_simple']=='Yes') {
  1379. $lmcount = 0;$tchance = 0;
  1380. foreach($wpr_loadedmodules as $lmodule) { if($lmodule != "translation" && $lmodule != "rss") {$lmcount++;} }
  1381. $lchance = floor(100 / $lmcount);
  1382. foreach($wpr_loadedmodules as $lmodule) { if($lmodule != "translation" && $lmodule != "rss") {
  1383. if(empty($firstmodule)) {$firstmodule = $lmodule;}
  1384. $_POST[$lmodule."chance"] = $lchance;
  1385. $tchance = $tchance + $lchance;
  1386. } }
  1387. if($tchance != 100) {$_POST[$firstmodule."chance"] = $_POST[$firstmodule."chance"] + (100 - $tchance); }
  1388. $_POST["mixchance"] = 0;
  1389. }
  1390. }
  1391. if($_POST['type2']) {
  1392. $_POST["tnum"] = 1;
  1393. $_POST["chance1"] = 100;
  1394. $_POST['type'] = "rss";
  1395. $_POST["content1"] = "{rss}";
  1396. $_POST["title1"] = "{rsstitle}";
  1397. $_POST["name1"] = "RSS Default";
  1398. $_POST["comments_amazon1"] = 0;
  1399. $_POST["comments_flickr1"] = 0;
  1400. $_POST["comments_yahoo1"] = 0;
  1401. $_POST["comments_youtube1"] = 0;
  1402. }
  1403. if($_POST['type3']) {
  1404. if(empty($_POST["tnum"])) {$_POST["tnum"] = 1;}
  1405. $_POST['type'] = "nodes";
  1406. if(isset($presets["Amazon Default"])) {
  1407. $_POST["chance1"] = 100;
  1408. $_POST["content1"] = $presets["Amazon Default"]["content"];
  1409. $_POST["title1"] = $presets["Amazon Default"]["title"];
  1410. $_POST["name1"] = "Amazon Default";
  1411. $_POST["comments_amazon1"] = $presets["Amazon Default"]["comments_amazon"];
  1412. $_POST["comments_flickr1"] = $presets["Amazon Default"]["comments_flickr"];
  1413. $_POST["comments_yahoo1"] = $presets["Amazon Default"]["comments_yahoo"];
  1414. $_POST["comments_youtube1"] = $presets["Amazon Default"]["comments_youtube"];
  1415. }
  1416. }
  1417.  
  1418. if(!$_POST['evenchance'] && !$_POST['wpr_cf_remove'] && !$_POST['wpr_cf_add'] && !$_POST['wpr_add_template'] && !$_POST['wpr_add'] && !$_POST['multisingle'] && !$_POST['exact'] && !$_POST['importwpr2'] && !$_POST['quick'] && !$_POST['quickrand'] && !$_POST['type1'] && !$_POST['type2'] && !$_POST['type3']) {
  1419. if($_GET['edit'] || $_GET['ccopy']){
  1420. // EDIT or COPY CAMPAIGN
  1421. $id = $_GET['edit']; if(!$id) {$id = $_GET['ccopy'];}
  1422. $campaign = $wpdb->get_row("SELECT * FROM " . $wpr_table_campaigns . " WHERE `id` = '$id'");
  1423. $_POST["name"] = $campaign->name;
  1424.  
  1425. $yahoocat = unserialize($campaign->yahoo_cat);
  1426. if(!is_array($yahoocat)) {
  1427. $yahoocat = array();
  1428. $yahoocat["a"] = "";
  1429. $yahoocat["rw"] = 0;
  1430. $yahoocat["ps"] = $campaign->yahoo_cat;
  1431. $yahoocat["pt"] = "";
  1432. }
  1433.  
  1434. $_POST["wpr_poststatus"] = $yahoocat["ps"];
  1435. $_POST["wpr_rewriter"] = $yahoocat["rw"];
  1436. $_POST["wpr_author"] = $yahoocat["a"];
  1437. $_POST['wpr_postthumbs'] = $yahoocat["t"];
  1438. $_POST['wpr_posttype'] = $yahoocat["pt"];
  1439.  
  1440. $_POST["type"] = $campaign->ctype;
  1441. if($_GET['ccopy']) {$_POST["name"] .= " Copy";}
  1442. $_POST["interval"] = $campaign->cinterval;
  1443. $_POST["period"] = $campaign->period;
  1444. if($campaign->pause == 0) {$_POST["autopost"] = "yes";}
  1445. $_POST['multisingle'] = "multi";
  1446. $_POST["amazon_department"] = $campaign->amazon_department;
  1447. $_POST["ebay_category"] = $campaign->ebay_cat;
  1448.  
  1449. $exclude = unserialize($campaign->excludekws);
  1450. for ($i = 0; $i < count($exclude); $i++) {
  1451. $_POST["exclude"] .= $exclude[$i] . "\n";
  1452. }
  1453. $replace = unserialize($campaign->replacekws);
  1454. for ($i = 0; $i < count($replace); $i++) {
  1455. $_POST["replace"] .= $replace[$i]["from"] ."|".$replace[$i]["to"]."|".$replace[$i]["chance"]."|".$replace[$i]["code"]."\n";
  1456. }
  1457. $keywords = unserialize($campaign->keywords);
  1458. $_POST["keywords"] = "";$_POST["feeds"] = "";$_POST["nodes"] = "";
  1459. for ($i = 0; $i < count($keywords); $i++) {
  1460. $_POST["keywords"] .= $keywords[$i][0] . "\n";
  1461. if($campaign->ctype == "rss") {
  1462. $_POST["feeds"] .= $keywords[$i]["feed"] . "\n";
  1463. } elseif($campaign->ctype == "nodes") {
  1464. $_POST["nodes"] .= $keywords[$i]["node"] . "\n";
  1465. }
  1466. }
  1467. $categories = unserialize($campaign->categories);
  1468.  
  1469. if(!empty($categories[0]["id"])) {$categories = wpr_transform_cats($categories);}
  1470.  
  1471. if(count($categories) == 1) {
  1472. $_POST['multisingle'] = "single";
  1473. $_POST['categories'] = $categories[0][0]["id"];
  1474. } else {
  1475. for ($i = 0; $i < count($categories); $i++) {
  1476. for ($o = 0; $o < count($categories[$i]); $o++) {
  1477. $_POST["categories"] .= $categories[$i][$o]["name"];
  1478. if($o != count($categories[$i])-1) {$_POST["categories"] .= ","; }
  1479. }
  1480. $_POST["categories"] .= "\n";
  1481. }
  1482. }
  1483.  
  1484. $templates = unserialize($campaign->templates);
  1485. if($options['wpr_simple']=='Yes' && $campaign->ctype == "keyword") {
  1486. foreach($wpr_loadedmodules as $lmodule) { if($lmodule != "translation" && $lmodule != "rss") {$_POST[$lmodule."chance"] = 0;} }
  1487. $_POST["mixchance"] = 0;
  1488. for ($i = 1; $i <= count($templates); $i++) {
  1489. $lmodule = str_replace('{', '', $templates[$i]["title"]);
  1490. $lmodule = str_replace('title}', '', $lmodule);
  1491. $_POST[$lmodule."chance"] = $templates[$i]["chance"];
  1492. if($lmodule == "") {$_POST["mixcontent"] = $templates[$i]["content"];}
  1493. }
  1494. if($_POST["chance"] > 0) {
  1495. $_POST["mixchance"] = $_POST["chance"];
  1496. }
  1497. } else {
  1498. $_POST['tnum'] = count($templates);
  1499. for ($i = 1; $i <= count($templates); $i++) {
  1500. $_POST["chance$i"] = $templates[$i]["chance"];
  1501. $_POST["title$i"] = $templates[$i]["title"];
  1502. $_POST["content$i"] = $templates[$i]["content"];
  1503. $_POST["comments_amazon$i"] = $templates[$i]["comments"]["amazon"];
  1504. $_POST["comments_flickr$i"] = $templates[$i]["comments"]["flickr"];
  1505. $_POST["comments_yahoo$i"] = $templates[$i]["comments"]["yahooanswers"];
  1506. $_POST["comments_youtube$i"] = $templates[$i]["comments"]["youtube"];
  1507. }
  1508. }
  1509. $customfields = unserialize($campaign->customfield);
  1510. if(isset($customfields["name"])) {
  1511. $_POST["cf_name1"] = $customfields["name"];
  1512. $_POST["cf_value1"] = $customfields["value"];
  1513. } else {
  1514. $_POST['cfnum'] = count($customfields);
  1515. for ($i = 1; $i <= count($customfields); $i++) {
  1516. $_POST["cf_name$i"] = $customfields[$i]["name"];
  1517. $_POST["cf_value$i"] = $customfields[$i]["value"];
  1518. }
  1519. }
  1520. $translation = unserialize($campaign->translation);
  1521. $_POST["transchance"] = $translation["chance"];
  1522. $_POST["trans1"] = $translation["from"];
  1523. $_POST["trans2"] = $translation["to1"];
  1524. $_POST["trans3"] = $translation["to2"];
  1525. $_POST["trans4"] = $translation["to3"];
  1526. $_POST['trans_comments'] = $translation["comments"];
  1527. } else {
  1528. $lid = $wpdb->get_var("SELECT id FROM $wpr_table_campaigns ORDER BY id DESC;");if($lid =="") {$lid=0;}
  1529. $lid++;
  1530. if(WPLANG == "de_DE") {$cnm = "Kampagne";} else {$cnm = "Campaign";}
  1531. $_POST["name"] = "$cnm $lid";
  1532. $_POST["interval"] = rand(12,96);
  1533. $_POST["chance1"] = 100;
  1534. if($options['wpr_simple']=='Yes') {
  1535. $lmcount = 0;$tchance = 0;
  1536. foreach($wpr_loadedmodules as $lmodule) { if($lmodule != "translation" && $lmodule != "rss") {$lmcount++;} }
  1537. $lchance = floor(100 / $lmcount);
  1538. foreach($wpr_loadedmodules as $lmodule) { if($lmodule != "translation" && $lmodule != "rss") {
  1539. if(empty($firstmodule)) {$firstmodule = $lmodule;}
  1540. $_POST[$lmodule."chance"] = $lchance;
  1541. $tchance = $tchance + $lchance;
  1542. } }
  1543. if($tchance != 100) {$_POST[$firstmodule."chance"] = $_POST[$firstmodule."chance"] + (100 - $tchance); }
  1544. $_POST["mixchance"] = 0;
  1545. } else {
  1546. /*$rand = array_rand($presets); NO RAND TEMPLATE
  1547. $_POST["content1"] = $presets[$rand]["content"];
  1548. $_POST["title1"] = $presets[$rand]["title"];
  1549. $_POST["comments_amazon1"] = $presets[$rand]["comments_amazon"];
  1550. $_POST["comments_flickr1"] = $presets[$rand]["comments_flickr"];
  1551. $_POST["comments_yahoo1"] = $presets[$rand]["comments_yahoo"];
  1552. $_POST["comments_youtube1"] = $presets[$rand]["comments_youtube"];*/
  1553. }
  1554. $_POST['multisingle'] = "multi";
  1555. $_POST['autopost'] = "yes";
  1556. $_POST['createcats'] = "yes";
  1557. $_POST['transchance'] = "0";
  1558. $_POST['delaystart'] = "0";
  1559. $_POST['type'] = "keyword";
  1560. }
  1561. }
  1562.  
  1563. if($_POST['wpr_cf_add']){
  1564. $_POST['cfnum'] = $_POST['cfnum'] + 1;
  1565. }
  1566. if($_POST['wpr_cf_remove']){
  1567. $_POST['cfnum'] = $_POST['cfnum'] - 1;
  1568. }
  1569.  
  1570. if($_POST['wpr_add_template']){
  1571. $_POST['tnum'] = $_POST['tnum'] + 1;
  1572. $xi = $_POST['tnum'];
  1573. if($_POST['wpr_add_template_preset'] == "Random") {
  1574. $rand = array_rand($presets);
  1575. $_POST["content$xi"] = $presets[$rand]["content"];
  1576. $_POST["title$xi"] = $presets[$rand]["title"];
  1577. $_POST["name$xi"] = $rand;
  1578. $_POST["comments_amazon$xi"] = $presets[$rand]["comments_amazon"];
  1579. $_POST["comments_flickr$xi"] = $presets[$rand]["comments_flickr"];
  1580. $_POST["comments_yahoo$xi"] = $presets[$rand]["comments_yahoo"];
  1581. $_POST["comments_youtube$xi"] = $presets[$rand]["comments_youtube"];
  1582. } else {
  1583. $_POST["content$xi"] = $presets[$_POST['wpr_add_template_preset']]["content"];
  1584. $_POST["title$xi"] = $presets[$_POST['wpr_add_template_preset']]["title"];
  1585. $_POST["name$xi"] = $_POST['wpr_add_template_preset'];
  1586. $_POST["comments_amazon$xi"] = $presets[$_POST['wpr_add_template_preset']]["comments_amazon"];
  1587. $_POST["comments_flickr$xi"] = $presets[$_POST['wpr_add_template_preset']]["comments_flickr"];
  1588. $_POST["comments_yahoo$xi"] = $presets[$_POST['wpr_add_template_preset']]["comments_yahoo"];
  1589. $_POST["comments_youtube$xi"] = $presets[$_POST['wpr_add_template_preset']]["comments_youtube"];
  1590. }
  1591.  
  1592. $chance = floor(100 / $_POST['tnum']);
  1593. $tchance = 0;
  1594. for ($i = 1; $i <= $_POST['tnum']; $i++) {
  1595. $_POST["chance$i"] = $chance;
  1596. $tchance = $tchance + $chance;
  1597. }
  1598. if($tchance != 100) {$_POST["chance1"] = $_POST["chance1"] + (100 - $tchance); }
  1599. }
  1600.  
  1601. for ($i = 1; $i <= $_POST["tnum"]; $i++) {
  1602. if($_POST["load$i"]){ // LOAD PRESET
  1603. $_POST["content$i"] = $presets[$_POST["p$i"]]["content"];
  1604. $_POST["title$i"] = $presets[$_POST["p$i"]]["title"];
  1605. $_POST["name$i"] = $_POST["p$i"]["name"];
  1606. $_POST["comments_amazon$i"] = $presets[$_POST["p$i"]]["comments_amazon"];
  1607. $_POST["comments_flickr$i"] = $presets[$_POST["p$i"]]["comments_flickr"];
  1608. $_POST["comments_yahoo$i"] = $presets[$_POST["p$i"]]["comments_yahoo"];
  1609. $_POST["comments_youtube$i"] = $presets[$_POST["p$i"]]["comments_youtube"];
  1610. } elseif($_POST["delete$i"]) { // DELETE TEMPLATE
  1611. $starter = $i;
  1612. for ($x = $starter; $x <= $_POST["tnum"]; $x++) {
  1613. $y = $x+1;
  1614. if($y <= $_POST["tnum"]) {
  1615. $_POST["content$x"] = $_POST["content$y"];
  1616. $_POST["title$x"] = $_POST["title$y"];
  1617. $_POST["name$x"] = $_POST["name$y"];
  1618. $_POST["comments_amazon$x"] = $_POST["comments_amazon$y"];
  1619. $_POST["comments_flickr$x"] = $_POST["comments_flickr$y"];
  1620. $_POST["comments_yahoo$x"] = $_POST["comments_yahoo$y"];
  1621. $_POST["comments_youtube$x"] = $_POST["comments_youtube$y"];
  1622. } else {
  1623. $_POST["content$x"] = "";
  1624. $_POST["title$x"] = "";
  1625. $_POST["name$x"] = "";
  1626. $_POST["comments_amazon$x"] = "";
  1627. $_POST["comments_flickr$x"] = "";
  1628. $_POST["comments_yahoo$x"] = "";
  1629. $_POST["comments_youtube$x"] = "";
  1630. }
  1631. }
  1632. $_POST["tnum"] = $_POST["tnum"] - 1;
  1633.  
  1634. $chance = floor(100 / $_POST['tnum']);
  1635. $tchance = 0;
  1636. for ($i = 1; $i <= $_POST['tnum']; $i++) {
  1637. $_POST["chance$i"] = $chance;
  1638. $tchance = $tchance + $chance;
  1639. }
  1640. if($tchance != 100) {$_POST["chance1"] = $_POST["chance1"] + (100 - $tchance); }
  1641. }
  1642. }
  1643.  
  1644. if($_POST['wpr_add']) {
  1645. wpr_create_campaign();
  1646. }
  1647.  
  1648. include("add-campaigns.php");
  1649. }
  1650. /*
  1651. function wpr_add_page_head() {
  1652. ?>
  1653. <script type="text/javascript">
  1654. jQuery(document).ready(function($) {
  1655.  
  1656. jQuery('a.deletetemplate').click(function(e) {
  1657. var id = jQuery(this).attr('id').replace('del-','pt-');
  1658. jQuery( "#" + id ).remove();
  1659. return false;
  1660. });
  1661. });
  1662. </script>
  1663. <?php
  1664. }
  1665.  
  1666. if(isset($_GET['page']) && $_GET['page'] == 'wpr-add' ) {
  1667. add_action('admin_head', 'wpr_add_page_head');
  1668. } */
  1669.  
  1670. // Header
  1671. function wpr_sub_templates_head() {
  1672. ?>
  1673. <script type="text/javascript">
  1674. function addtxt(input,txt) {
  1675. var obj = document.getElementById(input);
  1676. obj.value += txt;
  1677. }
  1678. </script>
  1679.  
  1680. <?php
  1681. }
  1682. if(isset($_GET['page']) && $_GET['page'] == 'wpr-templates' ) {
  1683. add_action('admin_head', 'wpr_sub_templates_head');
  1684. }
  1685.  
  1686. function wpr_sub_templates() {
  1687. global $wpdb, $wpr_table_campaigns, $wpr_table_templates,$wpr_loadedmodules, $_wp_using_ext_object_cache;
  1688. $_wp_using_ext_object_cache = false;
  1689.  
  1690. $options = unserialize(get_option("wpr_options"));
  1691. $wpr_disabledmodules = $options["disabled_modules"];
  1692.  
  1693. if ($options['wpr_installed'] != "yes") {
  1694. echo '<div class="wrap"><h2>WP Robot</h2><div class="updated"><h3>Installation</h3><p>'.__('Please go <a href="?page=wpr-campaigns">here</a> to finish the installation of WP Robot first.', 'wprobot').'</p></div></div>';
  1695. return false;
  1696. }
  1697.  
  1698. if($_GET['add'] && !$_POST['tdelete'] && !$_POST['tcopy'] && !$_POST['tsave']){
  1699. $type = $_GET['add'];
  1700. $sql = "INSERT INTO " . $wpr_table_templates . " SET type = '$type'";
  1701. $results = $wpdb->query($sql);
  1702.  
  1703. if ($results) {
  1704. echo '<div class="updated"><p>'.__('Empty '.$type.' template has been added!', 'wprobot').'</p></div>';
  1705. } else {
  1706. echo '<div class="updated"><p>'.__('Error: Template could not be added!', 'wprobot').'</p></div>';
  1707. }
  1708. }
  1709.  
  1710. if($_POST['tmodsave']){
  1711. for ($i = 0; $i <= $_POST['modnum']; $i++) {
  1712. $content = $_POST[$i."c"];
  1713. $id = $_POST[$i."id"];
  1714. $sql = "UPDATE " . $wpr_table_templates . " SET `content` = '".$content."' WHERE `id` = '".$id."'";
  1715. $results = $wpdb->query($sql);
  1716. }
  1717. echo '<div class="updated"><p>'.__('Module Templates have been updated!', 'wprobot').'</p></div>';
  1718. }
  1719.  
  1720. $tids = explode(",",$_POST["tids"]);
  1721. foreach ($tids as $tid) {
  1722. $i = $tid;
  1723. if($_POST["tsave$i"]) {$id = $i;} else {$tsave = false;}
  1724. if($_POST["tdelete$i"]) {$id = $i;} else {$tdelete = false;}
  1725. if($_POST["tcopy$i"]) {$id = $i;} else {$tcopy = false;}
  1726. }
  1727.  
  1728. if($_POST['tsaveall']){
  1729. foreach ($tids as $tid) {
  1730. $id = $tid;
  1731. $content = $_POST["tcontent$id"];
  1732. $title = $_POST["ttitle$id"];
  1733. $name = $_POST["tname$id"];
  1734. $comments_amazon = $_POST["comments_amazon$id"];
  1735. $comments_yahoo = $_POST["comments_yahoo$id"];
  1736. $comments_flickr = $_POST["comments_flickr$id"];
  1737. $comments_youtube = $_POST["comments_youtube$id"];
  1738. $sql = "UPDATE " . $wpr_table_templates . " SET `content` = '".$content."',`title` = '".$title."',`name` = '".$name."',`comments_amazon` = '".$comments_amazon."',`comments_flickr` = '".$comments_flickr."',`comments_yahoo` = '".$comments_yahoo."',`comments_youtube` = '".$comments_youtube."' WHERE `id` = '".$id."'";
  1739.  
  1740. $results = $wpdb->query($sql);
  1741. }
  1742. echo '<div class="updated"><p>'.__('All Templates have been updated!', 'wprobot').'</p></div>';
  1743. }
  1744.  
  1745. if($_POST["tsave$id"]){
  1746. $content = $_POST["tcontent$id"];
  1747. $title = $_POST["ttitle$id"];
  1748. $name = $_POST["tname$id"];
  1749. $comments_amazon = $_POST["comments_amazon$id"];
  1750. $comments_yahoo = $_POST["comments_yahoo$id"];
  1751. $comments_flickr = $_POST["comments_flickr$id"];
  1752. $comments_youtube = $_POST["comments_youtube$id"];
  1753. $sql = "UPDATE " . $wpr_table_templates . " SET `content` = '".$content."',`title` = '".$title."',`name` = '".$name."',`comments_amazon` = '".$comments_amazon."',`comments_flickr` = '".$comments_flickr."',`comments_yahoo` = '".$comments_yahoo."',`comments_youtube` = '".$comments_youtube."' WHERE `id` = '".$id."'";
  1754.  
  1755. $results = $wpdb->query($sql);
  1756.  
  1757. if ($results) {
  1758. echo '<div class="updated"><p>'.__('Template has been updated!', 'wprobot').'</p></div>';
  1759. } else {
  1760. echo '<div class="updated"><p>'.__('Error: Template could not be updated!', 'wprobot').'</p></div>';
  1761. }
  1762. }
  1763.  
  1764. if($_POST["tdelete$id"]){
  1765. $sql = "DELETE FROM " . $wpr_table_templates . " WHERE `id` = '".$id."'";
  1766. $results = $wpdb->query($sql);
  1767.  
  1768. if ($results) {
  1769. echo '<div class="updated"><p>'.__('Template has been deleted!', 'wprobot').'</p></div>';
  1770. } else {
  1771. echo '<div class="updated"><p>'.__('Error: Template could not be deleted!', 'wprobot').'</p></div>';
  1772. }
  1773. }
  1774.  
  1775. if($_POST["tcopy$id"]){
  1776. $templ = $wpdb->get_row("SELECT * FROM " . $wpr_table_templates . " WHERE `id` = '".$id."'");
  1777. $content = $templ->content;
  1778. $type = $templ->type;
  1779. $title = $templ->title;
  1780. $name = $templ->name;
  1781. $comments_amazon = $templ->comments_amazon;
  1782. $comments_yahoo = $templ->comments_yahoo;
  1783. $comments_flickr = $templ->comments_flickr;
  1784. $comments_youtube = $templ->comments_youtube;
  1785. $sql = "INSERT INTO " . $wpr_table_templates . " SET type = '$type', content = '$content',`title` = '".$title."',`name` = '".$name."',`comments_amazon` = '".$comments_amazon."',`comments_flickr` = '".$comments_flickr."',`comments_yahoo` = '".$comments_yahoo."',`comments_youtube` = '".$comments_youtube."'";
  1786. $results = $wpdb->query($sql);
  1787.  
  1788. if ($results) {
  1789. echo '<div class="updated"><p>'.__('Template has been copied!', 'wprobot').'</p></div>';
  1790. } else {
  1791. echo '<div class="updated"><p>'.__('Error: Template could not be copied!', 'wprobot').'</p></div>';
  1792. }
  1793. }
  1794.  
  1795. if($_GET["which"] == "post") {$where = "WHERE type = 'post'";$order = "id DESC";} else {$where = "WHERE type != 'post'";$order = "type ASC";}
  1796. $records = $wpdb->get_results("SELECT * FROM " . $wpr_table_templates . " $where ORDER BY $order");
  1797.  
  1798. $tids = array();
  1799. foreach ($records as $record) {$tids[] = $record->id;}
  1800.  
  1801. include("display-templates.php");
  1802. }
  1803.  
  1804. function wpr_sub_options() {
  1805. global $wpdb, $wpr_table_campaigns, $wpr_table_templates, $wpr_table_errors, $wpr_table_posts, $wpr_modules, $_wp_using_ext_object_cache, $wpr_loadedmodules;
  1806. $_wp_using_ext_object_cache = false;
  1807.  
  1808. $options = unserialize(get_option("wpr_options"));
  1809. $wpr_disabledmodules = $options["disabled_modules"];
  1810. if(!is_array($wpr_disabledmodules)) {$wpr_disabledmodules = array();}
  1811.  
  1812. $rw_options = get_option("allrewriters_settings");
  1813. if(empty($rw_options)) {$rw_options = ar_activate($options);}
  1814.  
  1815. if($_POST['wpr_disable_save']) {
  1816. $wpr_disabledmodules = array();
  1817. foreach($wpr_loadedmodules as $lmodule) {
  1818. if($_POST['disable_'.$lmodule] == 1) {
  1819. } else {
  1820. $wpr_disabledmodules[] = $lmodule;
  1821. }
  1822. }
  1823. $options["disabled_modules"] = $wpr_disabledmodules;
  1824. update_option("wpr_options", serialize($options));
  1825. echo '<div class="updated"><p>'.__('Your module selection has been saved.', 'wprobot').'</p></div>';
  1826. }
  1827.  
  1828. if($_POST['wpr_uninstall']) {
  1829. $results = $wpdb->query("DROP TABLE $wpr_table_posts,$wpr_table_templates,$wpr_table_campaigns,$wpr_table_errors;");
  1830. delete_option("wpr_options");
  1831. delete_option("wpr_cron");
  1832. delete_option("wpr_cloak");
  1833. delete_option('wpr_db_ver');
  1834. ar_deactivate();
  1835. $options = "";
  1836. echo '<div class="updated"><p>'.__('WP Robot has been uninstalled. You can now disable and delete the plugin.<br/><br/><strong>If you intend to reinstall WP Robot please first disable and reenable the plugin on your blogs "Plugins" page - otherwise the installation will not work!</strong>', 'wprobot').'</p></div>';
  1837. }
  1838.  
  1839. if ($options['wpr_installed'] != "yes") {
  1840. echo '<div class="wrap"><h2>WP Robot</h2><div class="updated"><h3>Installation</h3><p>'.__('Please go <a href="?page=wpr-campaigns">here</a> to finish the installation of WP Robot first.', 'wprobot').'</p></div></div>';
  1841. return false;
  1842. }
  1843.  
  1844. if($_POST['wpr_options_default']) {
  1845. $options = wpr_default_options(1);
  1846. echo '<div class="updated"><p>'.__('Options have been reset.', 'wprobot').'</p></div>';
  1847. }
  1848.  
  1849. if($_POST['wpr_templates_default']) {
  1850. $results = $wpdb->query("TRUNCATE TABLE $wpr_table_templates;");
  1851. $sql = unserialize(get_option("wpr_sql"));
  1852. if(empty($sql)) {$sql = $options["wpr_sql"];}
  1853. $results2 = $wpdb->query($sql);
  1854. if($results2) {echo '<div class="updated"><p>'.__('Templates have been reset.', 'wprobot').'</p></div>';}
  1855. else {echo '<div class="updated"><p>'.__('Templates could not be reset.', 'wprobot').'</p></div>';}
  1856. }
  1857.  
  1858. if($_POST['wpr_import']) {
  1859. $options = wpr_import_options();
  1860. echo '<div class="updated"><p>'.__('Settings have been imported.', 'wprobot').'</p></div>';
  1861. }
  1862.  
  1863. if($_POST['wpr_clear_log']) {
  1864. $results = $wpdb->query("TRUNCATE TABLE $wpr_table_errors;");
  1865. echo '<div class="updated"><p>'.__('Log has been cleared.', 'wprobot').'</p></div>';
  1866. }
  1867.  
  1868. if($_POST['wpr_clear_posts']) {
  1869. $results = $wpdb->query("TRUNCATE TABLE $wpr_table_posts;");
  1870. echo '<div class="updated"><p>'.__('History has been cleared.', 'wprobot').'</p></div>';
  1871. }
  1872.  
  1873. if($_POST['wpr_update_email']) {
  1874. $options['wpr_email'] = wpr_update_email($options['wpr_email'],$_POST['wpr_email']);
  1875. }
  1876.  
  1877. if($_POST['wpr_update_core']) {
  1878. wpr_update_email($options['wpr_email'],$options['wpr_email'],1);
  1879. }
  1880.  
  1881. if($_POST['wpr_options_save']) {
  1882.  
  1883. if($_POST['wpr_cloak'] == "Yes" && get_option('wpr_cloak') != "Yes") {
  1884. echo '<div class="updated"><p>'.__('<b>Warning:</b> Link cloaking has been enabled but <a href="http://wprobot.net/blog/how-to-set-up-wp-robot-link-cloaking/">additional steps</a> are required to finish the setup. If you do not follow these steps affiliate links on your blog will not work!', 'wprobot').'</p></div>';
  1885. }
  1886.  
  1887. $options['wpr_resetcount'] = $_POST['wpr_resetcount'];
  1888. $options['wpr_autotag'] = $_POST['wpr_autotag'];
  1889. $options['wpr_badwords'] = $_POST['wpr_badwords'];
  1890. $options['wpr_randomize'] = $_POST['wpr_randomize'];
  1891. $options['wpr_randomize_comments'] = $_POST['wpr_randomize_comments'];
  1892. $options['wpr_help'] = $_POST['wpr_help'];
  1893. $options['wpr_poststatus'] = $_POST['wpr_poststatus'];
  1894. $options['wpr_cb_affkey'] = $_POST['wpr_cb_affkey'];
  1895. $options['wpr_cb_filter'] = $_POST['wpr_cb_filter'];
  1896. $options['wpr_openlinks'] = $_POST['wpr_openlinks'];
  1897. $options['wpr_authorid'] = $_POST['wpr_authorid'];
  1898. $options['wpr_err_retries'] = $_POST['wpr_err_retries'];
  1899. $options['wpr_err_maxerr'] = $_POST['wpr_err_maxerr'];
  1900. $options['wpr_err_minmod'] = $_POST['wpr_err_minmod'];
  1901. $options['wpr_err_disable'] = $_POST['wpr_err_disable'];
  1902. $options["wpr_global_exclude"] = $_POST['wpr_global_exclude'];
  1903. $options['wpr_check_unique_old'] = $_POST['wpr_check_unique_old'];
  1904. $options['wpr_simple'] = $_POST['wpr_simple'];
  1905. $options['wpr_save_images'] = $_POST['wpr_save_images'];
  1906. $options['wpr_replace_keyword'] = $_POST['wpr_replace_keyword'];
  1907. //$options['wpr_rewrite_active'] = $_POST['wpr_rewrite_active'];
  1908. /*$options['wpr_rewrite_active_tbs'] = $_POST['wpr_rewrite_active_tbs'];
  1909. $options['wpr_rewrite_active_sc'] = $_POST['wpr_rewrite_active_sc'];
  1910. $options['wpr_rewrite_active_schimp'] = $_POST['wpr_rewrite_active_schimp'];
  1911. $options['wpr_rewrite_active_ucg'] = $_POST['wpr_rewrite_active_ucg'];
  1912. $options['wpr_rewrite_active_sr'] = $_POST['wpr_rewrite_active_sr'];
  1913. $options['wpr_rewrite_active_wai'] = $_POST['wpr_rewrite_active_wai'];
  1914. $options['wpr_rewrite_email'] = $_POST['wpr_rewrite_email'];
  1915. $options['wpr_rewrite_key'] = $_POST['wpr_rewrite_key'];
  1916. $options['wpr_rewrite_level'] = $_POST['wpr_rewrite_level'];
  1917. $options['wpr_tbs_rewrite_email'] = $_POST['wpr_tbs_rewrite_email'];
  1918. $options['wpr_tbs_rewrite_pw'] = $_POST['wpr_tbs_rewrite_pw'];
  1919. $options['wpr_tbs_spintxt'] = $_POST['wpr_tbs_spintxt'];
  1920. $options['wpr_tbs_quality'] = $_POST['wpr_tbs_quality'];
  1921. $options['wpr_rewrite_protected'] = $_POST['wpr_rewrite_protected'];
  1922. $options['wpr_sc_rewrite_email'] = $_POST['wpr_sc_rewrite_email'];
  1923. $options['wpr_sc_rewrite_pw'] = $_POST['wpr_sc_rewrite_pw'];
  1924. $options['wpr_sc_quality'] = $_POST['wpr_sc_quality'];
  1925. $options['wpr_sc_port'] = $_POST['wpr_sc_port'];
  1926. $options['wpr_sc_thesaurus'] = $_POST['wpr_sc_thesaurus'];
  1927. $options['wpr_schimp_rewrite_email'] = $_POST['wpr_schimp_rewrite_email'];
  1928. $options['wpr_schimp_rewrite_pw'] = $_POST['wpr_schimp_rewrite_pw'];
  1929. $options['wpr_schimp_quality'] = $_POST['wpr_schimp_quality'];
  1930. $options['wpr_sr_rewrite_email'] = $_POST['wpr_sr_rewrite_email'];
  1931. $options['wpr_sr_rewrite_pw'] = $_POST['wpr_sr_rewrite_pw'];
  1932. $options['wpr_sr_quality'] = $_POST['wpr_sr_quality'];
  1933. $options['wpr_wai_rewrite_email'] = $_POST['wpr_wai_rewrite_email'];
  1934. $options['wpr_wai_rewrite_pw'] = $_POST['wpr_wai_rewrite_pw'];
  1935. $options['wpr_wai_quality'] = $_POST['wpr_wai_quality'];
  1936. $options['wpr_wai_sentence'] = $_POST['wpr_wai_sentence'];
  1937. $options['wpr_wai_paragraph'] = $_POST['wpr_wai_paragraph'];
  1938. $options['wpr_wai_nooriginal'] = $_POST['wpr_wai_nooriginal'];*/
  1939. $options['wpr_tbs_rewrite_title'] = $_POST['wpr_tbs_rewrite_title'];
  1940. $options['wpr_rewrite_use'] = $_POST['wpr_rewrite_use'];
  1941. $options['wpr_trans_use_proxies'] = $_POST['wpr_trans_use_proxies'];
  1942. $options['wpr_trans_proxies'] = $_POST['wpr_trans_proxies'];
  1943. foreach($wpr_modules as $module) {
  1944. $function = "wpr_".$module."_options_default";
  1945. if(function_exists($function)) {
  1946. if(is_array($wpr_disabledmodules) && in_array($module, $wpr_disabledmodules)) {
  1947. } else {
  1948. $moptions = $function();
  1949. foreach($moptions as $moption => $default) {
  1950. $options[$moption] = $_POST[$moption];
  1951. }
  1952. }
  1953. }
  1954. }
  1955. update_option("wpr_options", serialize($options));
  1956. update_option('wpr_cloak',$_POST['wpr_cloak']);
  1957. echo '<div class="updated"><p>'.__('Options have updated.', 'wprobot').'</p></div>';
  1958. }
  1959.  
  1960. include("display-options.php");
  1961. }
  1962.  
  1963. function wpr_insertpost($content,$title,$cat=array(),$status,$author="",$thumbnail="",$parent="",$posttype="") {
  1964. remove_filter('the_content', 'make_clickable');
  1965. remove_filter('content_save_pre', 'wp_filter_post_kses');
  1966.  
  1967. if($content == "" || $title == "") {return false;}
  1968.  
  1969. $options = unserialize(get_option("wpr_options"));
  1970. $content = str_replace("$", "$ ", $content);
  1971.  
  1972. if($_POST['postdate']) {
  1973. $post_date= $_POST['postdate'];
  1974. $post_date_gmt= $post_date;
  1975. } else {
  1976. $post_date= current_time('mysql');
  1977. $post_date_gmt= current_time('mysql', 1);
  1978. }
  1979.  
  1980. if(!empty($author)) {
  1981. if(is_numeric($author)) {
  1982. $post_author = $author;
  1983. } else {
  1984. $user = get_user_by('login',$author);
  1985. if($user) {
  1986. $post_author = $user->ID;
  1987. } else {
  1988. $random_password = wp_generate_password( $length=12, $include_standard_special_chars=false );
  1989. $post_author = wp_create_user( $author, $random_password, $author . "@asdf.com" );
  1990. }
  1991. }
  1992. } else {
  1993. if ($options['wpr_authorid']!='') {
  1994. $authors = explode(";",$options['wpr_authorid']);
  1995. if(count($authors) == 0) {$post_author=1;} elseif(count($authors) > 0) {
  1996.  
  1997. $rnd = array_rand($authors);
  1998. if(is_numeric($authors[$rnd])) {
  1999. $post_author = $authors[$rnd];
  2000. } else {
  2001. $user = get_user_by('login',$authors[$rnd]);
  2002. if($user) {
  2003. $post_author = $user->ID;
  2004. } else {
  2005. $random_password = wp_generate_password( $length=12, $include_standard_special_chars=false );
  2006. $post_author = wp_create_user( $authors[$rnd], $random_password, $authors[$rnd] . "@asdf.com" );
  2007. }
  2008. }
  2009. }
  2010. }
  2011. }
  2012. if(empty($post_author)) {
  2013. $post_author = 1;
  2014. }
  2015.  
  2016. if($status=='published') {
  2017. $post_status = 'publish';
  2018. } elseif ($status=='draft') {
  2019. $post_status = 'draft';
  2020. } else {
  2021. if ($options['wpr_poststatus']=='published') {
  2022. $post_status = 'publish';
  2023. } elseif ($options['wpr_poststatus']=='draft') {
  2024. $post_status = 'draft';
  2025. }
  2026. }
  2027.  
  2028. if(empty($cat)) {$post_category = array(1);} else {$post_category = $cat;}
  2029.  
  2030. if ($options['wpr_openlinks']=='yes') {$content = str_replace("<a ", '<a target="_blank" ', $content);}
  2031. $post_content=$content;
  2032.  
  2033. $badwords = explode(";",$options['wpr_badwords']);
  2034. $badchars = array(",", ":", "(", ")", "]", "[", "?", "!", ";", "-", '"');
  2035.  
  2036. $title2 = str_replace($badchars, "", $title);
  2037.  
  2038. $items = explode(' ', $title2);
  2039. $tags_input = array();
  2040. for($k = 0, $l = count($items); $k < $l; ++$k){
  2041. $long = strlen($items[$k]);
  2042. if ($long > 3) {
  2043. if (!in_array(strtolower($items[$k]), $badwords)) {
  2044. if(!empty($items[$k])) {
  2045. $tags_input[] = $items[$k];
  2046. }
  2047. }
  2048. }
  2049. }
  2050. if($options['wpr_autotag'] != 'Yes') {$tags_input = "";}
  2051.  
  2052. $post_title = trim($title);
  2053.  
  2054. $tax_input = "";//array( 'ad_cat' => array( 6764 ) );
  2055.  
  2056. if(!empty($posttype)){
  2057. $post_type = $posttype;
  2058. } else {
  2059. $post_type = "post";
  2060. }
  2061.  
  2062. if(!empty($thumbnail)) {
  2063. $post_status = 'inherit';
  2064. $post_parent = $parent;
  2065. $post_type = 'attachment';
  2066. $post_mime_type = 'image/jpeg';
  2067. $uploads = wp_upload_dir();
  2068. $guid = $upload_dir['url']."/".$thumbnail;
  2069. $thumbnail = str_replace(".jpg", "", $thumbnail);
  2070. $post_title = trim($thumbnail);
  2071.  
  2072. $post_data = compact('post_content','post_title','post_date','post_date_gmt','post_author','post_category', 'post_status', 'tags_input','post_parent','post_type','post_mime_type','guid','tax_input');
  2073. } else {
  2074. $post_data = compact('post_content','post_title','post_date','post_date_gmt','post_author','post_category', 'post_status', 'tags_input','post_type','tax_input');
  2075. }
  2076.  
  2077. $post_data = add_magic_quotes($post_data);
  2078. $post_ID = wp_insert_post($post_data);
  2079. return $post_ID;
  2080. }
  2081.  
  2082. function wpr_insertcomments($postid,$commentsarray,$time="",$transcomments=0,$translation="") {
  2083. remove_filter('comment_text', 'make_clickable', 9);
  2084. $options = unserialize(get_option("wpr_options"));
  2085.  
  2086. if($_POST['postdate']) {
  2087. $comment_date = $_POST['postdate'];
  2088. } else {
  2089. $comment_date = current_time('mysql');
  2090. }
  2091.  
  2092. foreach ($commentsarray as $comments) {
  2093.  
  2094. if($options['wpr_randomize_comments'] == 'Yes') {
  2095. $ccount = count($comments);
  2096. $chalf = ceil($ccount / 2);
  2097. $cnum = rand($chalf,$ccount);
  2098. } else {
  2099. $cnum = count($comments);
  2100. }
  2101.  
  2102. $i = 0;
  2103. foreach ($comments as $comment) {
  2104. if($i < $cnum) {
  2105. $comment_post_ID=$postid;
  2106.  
  2107. if(function_exists("preg_split")) {
  2108. list( $today_year, $today_month, $today_day, $hour, $minute, $second ) = preg_split( '([^0-9])', $comment_date );
  2109. } else {
  2110. //list( $today_year, $today_month, $today_day, $hour, $minute, $second ) = split( '([^0-9])', $comment_date );
  2111. list( $today_year, $today_month, $today_day, $hour, $minute, $second ) = explode( '([^0-9])', $comment_date );
  2112. }
  2113. $comment_date = mktime($hour, $minute + rand(0, 59), $second + rand(0, 59), $today_month, $today_day, $today_year);
  2114. $comment_date=date("Y-m-d H:i:s", $comment_date);
  2115. $comment_date_gmt = $comment_date;
  2116.  
  2117. $rnd= rand(1,9999);
  2118. $comment_author_email="someone$rnd@domain.com";
  2119. $comment_author=$comment["author"];
  2120. $comment_author_url='';
  2121. $comment_content="";
  2122. $comment_content.=$comment["content"];
  2123. if($transcomments==1) {$comment_content = wpr_translate($comment_content,$translation["from"],$translation["to1"],$translation["to2"],$translation["to3"]);}
  2124. $comment_type='';
  2125. $user_ID='';
  2126. $comment_approved = 1;
  2127. $commentdata = compact('comment_post_ID', 'comment_date', 'comment_date_gmt', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'user_ID', 'comment_approved');
  2128. $comment_id = wp_insert_comment( $commentdata );
  2129. }
  2130. $i++;
  2131. }
  2132. }
  2133. }
  2134.  
  2135. function wpr_random_tags($content) {
  2136.  
  2137. preg_match_all('#\[select(.*)\]#smiU', $content, $matches, PREG_SET_ORDER);
  2138. if ($matches) {
  2139. foreach($matches as $match) {
  2140. $match[1] = substr($match[1], 1);
  2141. $paras = explode("|",$match[1]);
  2142. $randp = array_rand($paras);
  2143.  
  2144. $content = str_replace($match[0], $paras[$randp], $content);
  2145. }
  2146. }
  2147. //preg_match_all('#\[random(.*)](.*)[\/random]\]#smiU', $content, $matches, PREG_SET_ORDER);
  2148. preg_match_all('#\[random(.*)\](.*)\[/random\]#smiU', $content, $matches, PREG_SET_ORDER);
  2149. if ($matches) {
  2150. foreach($matches as $match) {
  2151. $match[1] = substr($match[1], 1);
  2152. if($match[1] >= rand(1,100)) {
  2153. //$match[2] = str_replace("[/rando", "", $match[2]);
  2154. $content = str_replace($match[0], $match[2], $content);
  2155. } else {
  2156. $content = str_replace($match[0], "", $content);
  2157. }
  2158. }
  2159. }
  2160.  
  2161. return $content;
  2162. }
  2163.  
  2164. function wpr_run_cron($camp_id="",$mincamp="",$maxcamp="",$minpost="",$maxpost="",$randtime=10,$chance=100) {
  2165. global $wpdb, $wpr_table_campaigns;
  2166.  
  2167. if(empty($chance) || $chance == "" || $chance == " ") {$chance = 100;}
  2168. if($chance >= rand(1,100)) {
  2169.  
  2170. $rtime = rand(0,$randtime);
  2171. $comment_date = time() - $rtime * 60;
  2172. $_POST['postdate']=date("Y-m-d H:i:s", $comment_date);
  2173. $csql = "";
  2174.  
  2175. if(isset($camp_id)) {
  2176. if(empty($minpost) || empty($maxpost)) {$randpost = 1;} else {$randpost = rand($minpost,$maxpost);}
  2177. for ($i = 1; $i <= $randpost; $i++) {
  2178. wpr_poster($camp_id, "", 1);
  2179. }
  2180. } else {
  2181. if(!empty($mincamp) && !empty($maxcamp)) {$campnumber = rand($mincamp,$maxcamp);$csql = " ORDER BY RAND() LIMIT $campnumber";}
  2182.  
  2183. $results = $wpdb->get_results("SELECT id FROM " . $wpr_table_campaigns . "$csql");
  2184. foreach($results as $result) {
  2185. if(empty($minpost) || empty($maxpost)) {$minpost = 1;$randpost = 1;} else {$randpost = rand($minpost,$maxpost);}
  2186. for ($i = $minpost; $i <= $randpost; $i++) {
  2187. $rtime = rand(0,$randtime);
  2188. $comment_date = time() - $rtime * 60;
  2189. $_POST['postdate']=date("Y-m-d H:i:s", $comment_date);
  2190. wpr_poster($result->id, "", 1);
  2191. }
  2192. }
  2193. }
  2194. }
  2195. }
  2196.  
  2197. function wpr_poster($camp_id, $keyword="", $manual=0) {
  2198.  
  2199. $options = unserialize(get_option("wpr_options"));
  2200. $maxretry = $options['wpr_err_retries'];
  2201. $retry = 0;
  2202. while($posted != true) {
  2203. $posted = wpr_post($camp_id, $keyword, $retry, $manual);
  2204. $retry++;
  2205.  
  2206. if($retry > $maxretry) {return false;}
  2207. }
  2208. if($posted) {
  2209. return true;
  2210. }
  2211. }
  2212.  
  2213. function wpr_post($camp_id, $keyword="", $retry=1, $manual=0) {
  2214. global $wpdb, $wpr_table_campaigns, $wpr_table_posts, $wpr_table_errors;
  2215.  
  2216. if($retry > 0) {$retrymsg = " <b>(".__("Retry","wprobot")." $retry)</b>";} else {$retrymsg = "";}
  2217. $time = current_time('mysql');
  2218. $errors = array();
  2219.  
  2220. $options = unserialize(get_option("wpr_options"));
  2221. $result = $wpdb->get_row("SELECT * FROM " . $wpr_table_campaigns . " WHERE id = '$camp_id'");
  2222. if($result->pause == 1 && $manual == 0) {return false;}
  2223.  
  2224. // select KEYWORD
  2225. $keywords = unserialize($result->keywords);
  2226. if(!$keyword) {
  2227. if(empty($keywords)) {
  2228. // SAVE and DISPLAY error
  2229. $esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
  2230. $esql .= " ( '$camp_id', '$keyword', '', 'Inactive', ".__("'Post skipped because no keywords were found in the campaign.$retrymsg'", 'wprobot').", '$time' );";
  2231. $results = $wpdb->query($esql);
  2232. return false;
  2233. }
  2234. // REMOVE KEYWORDS WHERE SKIPPED = 5 (better way without loop?)
  2235. $keywords2 = $keywords;
  2236. foreach($keywords as $key => $keyword) {
  2237. if($keyword["skipped"] >= $options['wpr_err_disable'] && !$keyword["feed"]) {
  2238. unset($keywords2[$key]);
  2239. }
  2240. }
  2241. //echo "<pre>";print_r($keywords2);echo "</pre>";
  2242. //$keywords = array_values($keywords);
  2243. $rnd = array_rand($keywords2);
  2244. $keyword = $keywords[$rnd][0];
  2245. if($rnd === "" || $keyword === "" && !empty($keyword["feed"]) || !is_numeric($rnd)) {
  2246. // SAVE and DISPLAY error
  2247. $esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
  2248. $esql .= " ( '$camp_id', '$keyword', '', 'Inactive', ".__("'No active keywords or feeds for this campaign, possibly because they were disabled due to repeated errors. Check the status and reenable them on the campaign detail page.$retrymsg'", 'wprobot').", '$time' );";
  2249. $results = $wpdb->query($esql);
  2250. return false;
  2251. }
  2252. } else {
  2253. foreach($keywords as $key => $kw) {
  2254. if($kw[0] == $keyword) {
  2255. $rnd = $key;
  2256. }
  2257. }
  2258. }
  2259. $keywordsbackup = $keywords[$rnd];
  2260.  
  2261. // select CATEGORY
  2262. $categories = unserialize($result->categories);
  2263. if(!empty($categories[0]["id"])) {$categories = wpr_transform_cats($categories);}
  2264. $catarray = array();
  2265. if(count($categories) == 1) {
  2266. foreach($categories[0] as $cats) {$catarray[] = $cats["id"];}
  2267. //$category = $categories[0]["id"];
  2268. } else {
  2269. foreach($categories[$rnd] as $cats) {$catarray[] = $cats["id"];}
  2270. //$category = $categories[$rnd]["id"];
  2271. }
  2272.  
  2273. // select TEMPLATE
  2274. $templates = unserialize($result->templates);
  2275. $i = 1;
  2276. foreach($templates as $tchance) {
  2277. $tch[$i] = $templates[$i]["chance"];
  2278. $i++;
  2279. }
  2280.  
  2281. $random = rand(1,100);
  2282. foreach($tch as $name => $chance){
  2283. $luck += $chance;
  2284. if($random <= $luck && empty($templatenum)){
  2285. $templatenum = $name;
  2286. }
  2287. }
  2288. $template = $templates[$templatenum]["content"];
  2289.  
  2290. $templateexcerpt = substr(strip_tags($template), 0, 130);
  2291. $templateusedmsg = '<a target="_blank" class="tooltip" href="#">?<span>'.__('The template used for this post was: <strong>Post Template ',"wprobot").$templatenum.__('</strong>, starting with:<br/>',"wprobot").$templateexcerpt.__('<br/><br/><strong>If there was an error please check the associated module messages directly below this one!</strong>',"wprobot") .'</span></a>';
  2292.  
  2293. // Wordpress action hook
  2294. do_action('wpr_before_post', $insert);
  2295.  
  2296. $content = $template;//echo $template."<br>";
  2297. $noqkeyword = str_replace('"', '', $keyword);
  2298. $content = str_replace("{keyword}", $noqkeyword, $content);
  2299. $content = str_replace("{Keyword}", ucwords($noqkeyword), $content);
  2300. $content = str_replace("{title}", $title, $content);
  2301. $catreplace = get_category_link( $catarray[0] );
  2302. if (!is_wp_error($catreplace)) {
  2303. $content = str_replace("{catlink}", $catreplace, $content);
  2304. } else {$content = str_replace("{catlink}", "", $content); }
  2305.  
  2306. // AMAZON
  2307. preg_match_all('#\{amazonlist(.*)\}#iU', $content, $matches, PREG_SET_ORDER);
  2308. if ($matches) {
  2309. foreach($matches as $match) {
  2310. $match[1] = substr($match[1], 1);
  2311. if($match[1]) {$amanum = $match[1];} else {$amanum = 1;}
  2312. $amalist = wpr_amazon_getlist($keywords[$rnd][0],$amanum);
  2313. if(isset($amalist["error"]) && is_array($amalist)) {$errors[] = $amalist["error"];$content = str_replace($match[0], "", $content);}
  2314. $content = str_replace($match[0], $amalist, $content);
  2315. }
  2316. }
  2317. // THUMBNAIL
  2318. preg_match_all('#\{thumbnail(.*)\}#iU', $content, $matches, PREG_SET_ORDER);
  2319. if ($matches) {
  2320. foreach($matches as $match) {
  2321. $match[1] = substr($match[1], 1);
  2322. if($match[1]) {$tkw = $match[1];} else {$tkw = $keywords[$rnd][0];}
  2323. $thumbnail = wpr_flickr_getthumbnail($tkw);
  2324. if(!empty($thumbnail["error"])) {$errors[] = $thumbnail["error"];}
  2325. $content = str_replace($match[0], $thumbnail[0]["content"], $content);
  2326. }
  2327. }
  2328. // RANDOM Tags
  2329. $content = wpr_random_tags($content);
  2330.  
  2331. $title = $templates[$templatenum]["title"];
  2332. $noqkeyword = str_replace('"', '', $keyword);
  2333. $title = str_replace("{keyword}", $noqkeyword, $title);
  2334. $title = str_replace("{Keyword}", ucwords($noqkeyword), $title);
  2335. if(!empty($keywords[$rnd]["alternative"])) {
  2336. $ll = 1;
  2337. foreach($keywords[$rnd]["alternative"] as $alternative) {
  2338. $content = str_replace("{keyword$ll}", $alternative, $content);
  2339. $title = str_replace("{keyword$ll}", $alternative, $title);
  2340. $ll++;
  2341. }
  2342. }
  2343.  
  2344. // RANDOM Tags
  2345. $title = wpr_random_tags($title);
  2346.  
  2347. $raz[0] = "{";$raz[1] = "}";
  2348. preg_match_all("/\\".$raz[0]."[^\\".$raz[1]."]+\\".$raz[1]."/s", $content, $matches);
  2349. $counts = array_count_values ( $matches[0] ); //echo $counts["{amazon}"];
  2350.  
  2351. $wpr_modulesnum = count($matches[0]);
  2352. if($wpr_modulesnum <= 0) {
  2353. // SAVE and DISPLAY error
  2354. $esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
  2355. $esql .= " ( '$camp_id', '$keyword', '', 'Inactive', ".__("'Post skipped because no modules were found in the template.$retrymsg'", 'wprobot').", '$time' );";
  2356. $results = $wpdb->query($esql);
  2357. return false;
  2358. }
  2359.  
  2360. $usql = "INSERT INTO ".$wpr_table_posts." ( campaign, keyword, module, unique_id, time ) VALUES";
  2361. // Get Content for each Module
  2362. // ["content"] = Content of the item (replaced module template code)
  2363. // ["title"] = Title of the item (i.e. Product title)
  2364. // ["unique"] = Unique ID (i.e. ASIN)
  2365. // ["comments"] = Possible comment content of the item (i.e. reviews)
  2366. $contents = array();
  2367. $commentsarray = array();
  2368. $titleerror = 0;
  2369. $duplicatecount = 0;
  2370. $errorcount = 0;
  2371. $replacecount = 0;
  2372.  
  2373. foreach($counts as $module => $count) {
  2374.  
  2375. $modulname = str_replace(array("{","}"), "", $module);
  2376. $function = "wpr_".$modulname."post";
  2377.  
  2378. $optional = "";$comments = "";
  2379. switch ($modulname) {
  2380. case "amazon":
  2381. $optional = array($result->amazon_department,$keywords[$rnd]["node"]);
  2382. break;
  2383. case "ebay":
  2384. $optional = $result->ebay_cat;
  2385. break;
  2386. case "flickr":
  2387. $comments = $templates[$templatenum]["comments"]["$modulname"];
  2388. break;
  2389. case "youtube":
  2390. $comments = $templates[$templatenum]["comments"]["$modulname"];
  2391. break;
  2392. case "yahooanswers":
  2393. $optional = $result->yahoo_cat;
  2394. $comments = $templates[$templatenum]["comments"]["$modulname"];
  2395. break;
  2396. case "rss":
  2397. $optional = $keywords[$rnd]["feed"];
  2398. break;
  2399. }
  2400.  
  2401. // GET CONTENT
  2402. if(function_exists($function)) {
  2403. $contents["$modulname"] = $function($keyword, $count, $keywords[$rnd][1]["$modulname"], $optional, $comments);
  2404. if(!empty($contents["$modulname"]["error"])) {
  2405. $errors[] = $contents["$modulname"]["error"];
  2406. $errorcount = $errorcount + 1 * $counts["{".$modulname."}"];
  2407. }
  2408. } else {
  2409. $title = str_replace("{".$modulname."title}", "", $title);
  2410. $errors[] = array("module" => ucwords($modulname), "reason" => "Not Installed", "message" => __("$modulname is not installed on this weblog and has been skipped.", 'wprobot'));
  2411. $errorcount = $errorcount + 1;
  2412. }
  2413.  
  2414. //print_r($contents);
  2415.  
  2416. // KEYWORD REPLACE
  2417. if($replacecount == 0 && !empty($contents["$modulname"][0]["title"]) && $options['wpr_replace_keyword'] == 1) {
  2418. $keyword = preg_replace("/[^A-Za-z0-9 ]/", '', $contents["$modulname"][0]["title"]);
  2419. $replacecount = 1;
  2420. }
  2421.  
  2422. // CONTENT REPLACE
  2423. $$modulname = 0;
  2424. $dupl = 0;
  2425.  
  2426. foreach ($matches[0] as $element) {
  2427. if($element=="{".$modulname."}") {
  2428. $unique = $contents["$modulname"][$$modulname]["unique"];
  2429. if($unique != "" || $modulname == "ebay" ) {
  2430. $dcheck = wpr_check_unique($unique);
  2431. //echo "CHECK".$dcheck;
  2432. if($options['wpr_check_unique_old'] == "Yes") {$dcheck2 = wpr_check_unique_old($contents["$modulname"][$$modulname]["title"]);} else {$dcheck2 = false;}
  2433. if($dcheck == false && $dcheck2 == false) {
  2434. $content = preg_replace('/\{'.$modulname.'\}/', $contents["$modulname"][$$modulname]["content"], $content, 1);
  2435. if(!isset($contents["$modulname"]["error"]) ) {
  2436. $unique = $wpdb->escape($unique);
  2437. $ekeyword = $wpdb->escape($keyword);
  2438. $usql .= " ( '$camp_id', '$ekeyword', '$modulname', '$unique', '$time' ),";
  2439. }
  2440.  
  2441.  
  2442. if($templates[$templatenum]["comments"]["$modulname"] == 1) {$commentsarray[] = $contents["$modulname"][$$modulname]["comments"];}
  2443.  
  2444. if(!empty($contents["$modulname"][$$modulname]["comments"]) && $modulname == "articlebuilder") {$commentsarray[] = $contents["$modulname"][$$modulname]["comments"];}
  2445.  
  2446. } else {
  2447. // DUPLICATE POST
  2448. $dupl = 1;
  2449. $duplicatecount++;
  2450. $content = preg_replace('/\{'.$modulname.'\}/', "", $content, 1);
  2451. $errors[] = array("module" => ucwords($modulname), "reason" => "Duplicate", "message" => __("Skipping ", 'wprobot').ucwords($modulname).__(" module because the content has already been posted.", 'wprobot'));
  2452. $errorcount = $errorcount + 1;
  2453. }
  2454. }
  2455.  
  2456. //echo "------------DEBUG START------------<br/>";
  2457. //echo $dupl." DUPLICATE<br/>";
  2458. //echo $contents["$modulname"]["error"]." ERROR<br/>";
  2459. //echo $counts["{".$modulname."}"]." FIRST COUNT<br/>";
  2460. //echo $$modulname." SECOND COUNT<br/>";
  2461. // TITLE REPLACE
  2462. $titlecheck = strpos($title, "{".$modulname."title}");
  2463. $titlecheck2 = strpos($title, "{title}");
  2464. $modulecheckvar = $$modulname + 1;
  2465. if ($titlecheck !== false || $titlecheck2 !== false) {
  2466. if ($counts["{".$modulname."}"] > $modulecheckvar && $dupl == 1 || $counts["{".$modulname."}"] > $modulecheckvar && !empty($contents["$modulname"]["error"])) {
  2467. // Dont Replace Title because there is another title module item
  2468. } elseif($counts["{".$modulname."}"] <= $modulecheckvar && $dupl == 1) {
  2469. // Title Duplicate
  2470. $titleduplicate = 1;
  2471. } elseif($counts["{".$modulname."}"] <= $modulecheckvar && !empty($contents["$modulname"]["error"]) || $counts["{".$modulname."}"] <= $modulecheckvar && empty($contents["$modulname"][0]["title"])) {
  2472. // Title Error
  2473. $titleerror = 1;
  2474. } else {
  2475. // Replace Title
  2476. $title = str_replace("{".$modulname."title}", $contents["$modulname"][$$modulname]["title"], $title);
  2477. $title = str_replace("{title}", $contents["$modulname"][$$modulname]["title"], $title);
  2478. }
  2479. }
  2480. $$modulname++;
  2481. }
  2482. }
  2483.  
  2484. if($contents["$modulname"]["error"]["reason"] == "IncNum") {$incnum = 1;} else {$incnum = 0;}
  2485. // INCREASE NUMS
  2486. if(empty($contents["$modulname"]["error"]) || $contents["$modulname"]["error"]["reason"] == "IncNum") { // don't increase NUMs if ERROR for module
  2487. $keywords[$rnd][1]["$modulname"] = $keywords[$rnd][1]["$modulname"] + $$modulname;
  2488.  
  2489. // RESET POST COUNT
  2490. if($keywords[$rnd][1]["$modulname"] > $options['wpr_resetcount'] && $options['wpr_resetcount'] != "no") {$keywords[$rnd][1]["$modulname"] = 0;}
  2491. if($modulename == "ebay" && $keywords[$rnd][1]["$modulname"] > 50) {$keywords[$rnd][1]["$modulname"] = 0;}
  2492. }
  2493. $content = str_replace("{".$modulname."}","",$content);
  2494. }
  2495.  
  2496. // check ERRORS
  2497. //$errorsnum = count($errors);
  2498. $errorsnum = $errorcount;
  2499. $skip = 0;
  2500. if(!empty($keywords[$rnd]["feed"])) {$errkeyword = "Feed";} elseif(!empty($keywords[$rnd]["node"])) {$errkeyword = "Node:".$keywords[$rnd]["node"];} else {$errkeyword = $wpdb->escape($keyword);}
  2501.  
  2502. // EXCLUDE KEYWORDS Check $options["wpr_global_exclude"]
  2503. $excludeskip = 0;
  2504. $excludes = unserialize($result->excludekws);
  2505.  
  2506. $globals = str_replace("\r", "", $options["wpr_global_exclude"]);
  2507. $globals = explode("\n", $globals);
  2508. $excludes = array_merge($excludes, $globals);
  2509.  
  2510. if(!empty($excludes)) {
  2511. foreach($excludes as $exclude) {
  2512. if($exclude != "" && $exclude != " " ) {
  2513. $excheck = stripos($content, $exclude);
  2514. $texcheck = stripos($title, $exclude);
  2515. if($excheck === false && $texcheck === false) {
  2516. } else {
  2517. $excludeskip = 1; $errors = array();
  2518. $errors[] = array("module" => "", "reason" => "Exclude", "message" => __("Skipping post because exclude keyword $exclude was found.$retrymsg $templateusedmsg", 'wprobot'), "time" => "$time");
  2519. break;
  2520. }
  2521. }
  2522. }
  2523. }
  2524.  
  2525. if($excludeskip == 0) {
  2526. // MARK KEYWORD AS yellow, orange, etc
  2527. $wpr_modulessuccess = $wpr_modulesnum - $errorsnum;
  2528. $duplsuccess = $wpr_modulesnum - $duplicatecount;
  2529. if($duplicatecount > $options["wpr_err_maxerr"] || $duplsuccess < $options["wpr_err_minmod"] || $titleduplicate == 1) { // DUPLICATE ERROR - WiTHOUT skipped INCREASE
  2530. $errors[] = array("module" => "", "reason" => "Duplicate Content", "message" => __("Skipping post to prevent duplicate content.", 'wprobot')."$retrymsg $templateusedmsg", "time" => "$time");
  2531. $skip = 1;
  2532. } elseif($titleerror == 1) {
  2533. if($incnum != 1) {$keywords[$rnd] = $keywordsbackup;}
  2534. $keywords[$rnd]["skipped"] = $keywords[$rnd]["skipped"] + 1;
  2535. $errors[] = array("module" => "", "reason" => "Post skipped", "message" => __("Skipping post because the main module (title module) returned an error.", 'wprobot')."$retrymsg $templateusedmsg", "time" => "$time");
  2536. $skip = 1;
  2537. } elseif($errorsnum > $options["wpr_err_maxerr"] || $wpr_modulessuccess < $options["wpr_err_minmod"]) {
  2538. if($incnum != 1) {$keywords[$rnd] = $keywordsbackup;}
  2539. $keywords[$rnd]["skipped"] = $keywords[$rnd]["skipped"] + 1;
  2540. $errors[] = array("module" => "", "reason" => "Post skipped", "message" => __("Skipping post because too many module errors were encountered.", 'wprobot')."$retrymsg $templateusedmsg", "time" => "$time");
  2541. $skip = 1;
  2542. } else {
  2543. $keywords[$rnd]["skipped"] = 0;
  2544. }
  2545. }
  2546.  
  2547. // SAVE ERRORS
  2548. if($errorsnum > 0 || $excludeskip == 1 || $titleerror == 1) {
  2549. $esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
  2550. foreach($errors as $error) {
  2551. $error["message"] = $wpdb->escape($error["message"]);
  2552. $esql .= " ( '$camp_id', '$errkeyword', '".$error["module"]."', '".$error["reason"]."', '".$error["message"]."', '$time' ),";
  2553. }
  2554. $esql = substr_replace($esql ,";",-1);
  2555. $results = $wpdb->query($esql);
  2556. }
  2557.  
  2558. // SKIP if EXCLUDE found, errors > MAXERRORS or modules < MINMODULES
  2559. if($excludeskip == 1 || $skip == 1) {
  2560. // - update campaign entry with new NUMS
  2561.  
  2562. $keywords = serialize($keywords);
  2563. $keywords = $wpdb->escape($keywords);
  2564. $sql = "UPDATE " . $wpr_table_campaigns . " SET `keywords` = '".$keywords."' WHERE `id` = '".$camp_id."'";
  2565. $results = $wpdb->query($sql);
  2566. return false;
  2567. }
  2568.  
  2569. // SAVE IMAGES
  2570. /*if($options['wpr_save_images'] == "Yes") {
  2571.  
  2572. $allimages = wpr_findimages($content);
  2573. $imageurls = $allimages[2];
  2574.  
  2575. if(sizeof($imageurls)) {
  2576. foreach($imageurls as $oldurl) {
  2577. if(strpos($oldurl, plugin_basename( dirname(__FILE__) )) === false) {
  2578. $newurl = wpr_saveimage($oldurl,$keyword);
  2579. if($newurl) {$content = str_replace($oldurl, $newurl, $content);}
  2580. }
  2581. }
  2582. }
  2583. } */
  2584.  
  2585. // TRANSLATION
  2586. if(function_exists("wpr_translate_partial")) {
  2587. $title = wpr_translate_partial($title);
  2588. }
  2589. $translation = unserialize($result->translation);
  2590. if($translation["chance"] >= rand(1,100)) {
  2591. if($translation["from"] != "no" && $translation["to1"] != "no") {
  2592. $translationcontent = wpr_translate($content,$translation["from"],$translation["to1"],$translation["to2"],$translation["to3"]);
  2593. //print_r($translationcontent);
  2594. if($options["wpr_trans_titles"] == "yes") {
  2595. $translationtitle = wpr_translate($title,$translation["from"],$translation["to1"],$translation["to2"],$translation["to3"]);
  2596.  
  2597. }
  2598. if(!empty($translationcontent["error"]["reason"])) {
  2599. $esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
  2600. $esql .= " ( '$camp_id', '$errkeyword', 'Translation', '".$translationcontent["error"]["reason"]."', '".$translationcontent["error"]["message"]."', '$time' );";
  2601. $results = $wpdb->query($esql);
  2602. if($options['wpr_trans_fail'] == "skip") {
  2603. $esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
  2604. $esql .= " ( '$camp_id', '$errkeyword', '', 'Post skipped', '".__("Skipping post because translation failed ","wprobot")."$retrymsg $templateusedmsg', '$time' );";
  2605. $results = $wpdb->query($esql);
  2606. return false;
  2607. }
  2608. } elseif(empty($translationcontent)) {
  2609. $esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
  2610. $esql .= " ( '$camp_id', '$errkeyword', 'Translation', 'Translation Failed', '".__("The post could not be translated.","wprobot")."', '$time' );";
  2611. $results = $wpdb->query($esql);
  2612. if($options['wpr_trans_fail'] == "skip") {
  2613. $esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
  2614. $esql .= " ( '$camp_id', '$errkeyword', '', 'Post skipped', '".__("Skipping post because translation failed ","wprobot")."$retrymsg $templateusedmsg', '$time' );";
  2615. $results = $wpdb->query($esql);
  2616. return false;
  2617. }
  2618. } else {
  2619. $content = $translationcontent;
  2620. if($options["wpr_trans_titles"] == "yes" && empty($translationtitle["error"]["reason"])) {$title = $translationtitle;}
  2621. if($translation["comments"] == 1) {$transcomments = 1;} else {$transcomments = 0;}
  2622. }
  2623. }
  2624. }
  2625.  
  2626. $yahoocat = unserialize($result->yahoo_cat);
  2627. if(!is_array($yahoocat)) {
  2628. $yahoocat = array();
  2629. $yahoocat["rw"] = 0;
  2630. $yahoocat["ps"] = $result->yahoo_cat;
  2631. $yahoocat["a"] = "";
  2632. }
  2633.  
  2634. // REWRITE
  2635. if($yahoocat["rw"] == 1) {
  2636.  
  2637. $rewrite_use = $options['wpr_rewrite_use'];
  2638. $rewrite_titles = $options['wpr_tbs_rewrite_title'];
  2639.  
  2640. $rw_options = get_option('allrewriters_settings');
  2641.  
  2642. if(empty($rw_options)) {
  2643. $esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
  2644. $esql .= " ( '$camp_id', '$errkeyword', 'Rewriter', 'Rewriter', 'Rewriter settings are empty! Please go to the All Rewriters page to set them up.', '$time' );";
  2645. $results = $wpdb->query($esql);
  2646. } else {
  2647.  
  2648. if($rewrite_use == "chain") {
  2649.  
  2650. if(!empty($rw_options["general"]["options"]["chain"][1]) && !empty($rw_options["general"]["options"]["chain"][2])) {
  2651. foreach($rw_options["general"]["options"]["chain"] as $ch => $chfunc) {
  2652. if(!empty($chfunc)) {
  2653. $result = $chfunc($content);
  2654. if(is_array($result) && !empty($result["error"])) {
  2655. $esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
  2656. $esql .= " ( '$camp_id', '$errkeyword', 'Chain Rewrite', 'Chain Rewrite', '".$result["error"]."', '$time' );";
  2657. $results = $wpdb->query($esql);
  2658. } else {
  2659. $content = $result;
  2660. }
  2661. }
  2662. }
  2663. } else {
  2664. $esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
  2665. $esql .= " ( '$camp_id', '$errkeyword', 'Chain Rewrite', 'Chain Rewrite', 'Please set up your rewriting chain on the All Rewriters settings page under <i>Settings > All Rewriters</i> first', '$time' );";
  2666. $results = $wpdb->query($esql);
  2667. }
  2668.  
  2669. } elseif($rewrite_use == "rand" || empty($rewrite_use)) { // get random active rewriter
  2670. $active_rw = array();
  2671. foreach($rw_options as $module => $moduledata) {if(1 == $moduledata["enabled"]) {$active_rw[] = $module;}}
  2672. $rand_key = array_rand($active_rw);
  2673. $sel_rw = $active_rw[$rand_key];
  2674. } else {
  2675. $sel_rw = $rewrite_use;
  2676. }
  2677.  
  2678. $rw_func = $rw_options[$sel_rw]["function"];
  2679.  
  2680. if(!empty($rw_func) && function_exists($rw_func)) {
  2681.  
  2682. $result = $rw_func($content);
  2683. if(is_array($result) && !empty($result["error"])) {
  2684. $esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
  2685. $esql .= " ( '$camp_id', '$errkeyword', '".$rw_options[$sel_rw]["name"]."', '".$rw_options[$sel_rw]["name"]."', '".$result["error"]."', '$time' );";
  2686. $results = $wpdb->query($esql);
  2687. } else {
  2688. $content = $result;
  2689. }
  2690.  
  2691. //echo "RW: $sel_rw <br><br>RW FUNC: $rw_func <br><br> RESULT: $result";
  2692.  
  2693. if($rewrite_titles == "Yes") {
  2694.  
  2695. $rewritetitle = $rw_func($title);
  2696. if(is_array($rewritetitle) && !empty($rewritetitle["error"])) {
  2697. } else {
  2698. $title = $rewritetitle;
  2699. }
  2700. }
  2701.  
  2702. } elseif($rewrite_use != "chain") {
  2703. $esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
  2704. $esql .= " ( '$camp_id', '$errkeyword', 'Rewriter', 'Rewriter', 'Rewriter Function not found! Please install our free All Rewriter plugin to use rewriting with WP Robot!', '$time' );";
  2705. $results = $wpdb->query($esql);
  2706. }
  2707. }
  2708. }
  2709.  
  2710. if(function_exists("wpr_rewrite_partial")) {
  2711. $content = wpr_rewrite_partial($content,$options);
  2712. }
  2713.  
  2714. // REPLACES
  2715. $replaces = unserialize($result->replacekws);
  2716. if(!empty($replaces)) {
  2717. foreach($replaces as $replace) {
  2718. if($replace["chance"] >= rand(1,100)) {
  2719. $replace["from"] = trim($replace["from"]);
  2720. $replace["to"] = trim($replace["to"]);
  2721. if($replace["code"] == "1") {
  2722. $content = str_replace($replace["from"], $replace["to"], $content);
  2723. $title = str_replace($replace["from"], $replace["to"], $title);
  2724. } else {
  2725. $content = str_replace(" ".$replace["from"], " ".$replace["to"], $content);
  2726. $title = str_replace(" ".$replace["from"], " ".$replace["to"], $title);
  2727. }
  2728. }
  2729. }
  2730. }
  2731.  
  2732. // Wordpress action hook
  2733. do_action('wpr_before_post_save', $content,$title,$catarray);
  2734.  
  2735. // INSERT POST into db
  2736. $insert = wpr_insertpost($content,$title,$catarray,$yahoocat["ps"],$yahoocat["a"],"","",$yahoocat["pt"]);
  2737. if (is_wp_error($insert)) {
  2738. $errormessage = $insert->get_error_message();
  2739. // SAVE and DISPLAY error
  2740. $esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
  2741. $esql .= " ( '$camp_id', '$errkeyword', '', 'Insert failed', ".__("'Wordpress Error: ", 'wprobot')."$errormessage $retrymsg $templateusedmsg', '$time' );";
  2742. $results = $wpdb->query($esql);
  2743. return false;
  2744. } elseif(isset($insert)) {
  2745.  
  2746. // - update campaign entry with new NUMS
  2747. $posts_created = $result->posts_created + 1;
  2748. $keywords[$rnd][1]["total"] = $keywords[$rnd][1]["total"] + 1;
  2749. $keywords = serialize($keywords);
  2750. $keywords = $wpdb->escape($keywords);
  2751. $sql = "UPDATE " . $wpr_table_campaigns . " SET `keywords` = '".$keywords."', `posts_created` = '".$posts_created."' WHERE `id` = '".$camp_id."'";
  2752. $results = $wpdb->query($sql);
  2753.  
  2754. // - SAVE IMAGES
  2755. if($options['wpr_save_images'] == "Yes") {
  2756. $resultimgs = wpr_save_all_images($content,$keyword,$insert);
  2757.  
  2758. $attachments = get_posts(array('numberposts' => '1', 'post_parent' => $insert, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC'));
  2759.  
  2760. if(sizeof($attachments) > 0){
  2761. set_post_thumbnail($insert, $attachments[0]->ID);
  2762. }
  2763. }
  2764.  
  2765. // - save UNIQUE IDS to post table
  2766. $usql = substr_replace($usql ,";",-1);
  2767. $results = $wpdb->query($usql);
  2768.  
  2769. // - insert COMMENTS
  2770. wpr_insertcomments($insert,$commentsarray,"",$transcomments,$translation);
  2771.  
  2772. // - insert CUSTOM FIELDS
  2773. //if($counts["{amazon}"] > 0) {
  2774. // add_post_meta($insert, 'ma_amazonpost', $contents["amazon"][0]["unique"]);
  2775. //}
  2776. //add_post_meta($insert, 'wpr_keyword', $keyword);
  2777.  
  2778. $customfield = unserialize($result->customfield);
  2779.  
  2780. if(isset($customfield["name"])) {
  2781. $customfields = array();
  2782. $customfields[1]["name"] = $customfield["name"];
  2783. $customfields[1]["value"] = $customfield["value"];
  2784. $customfield = $customfields;
  2785. }
  2786.  
  2787. if($yahoocat["t"] == 1 || !empty($customfield)) {
  2788. if(!empty($contents["amazon"][0]["customfield"]["amazonthumbnail"]))
  2789. {$ximage = $contents["amazon"][0]["customfield"]["amazonthumbnail"];
  2790. } elseif(!empty($contents["commissionjunction"][0]["customfield"]["cjthumbnail"]))
  2791. {$ximage = $contents["commissionjunction"][0]["customfield"]["cjthumbnail"];
  2792. } elseif(!empty($contents["rss"][0]["customfield"]["rssimage"]))
  2793. {$ximage = $contents["rss"][0]["customfield"]["rssimage"];
  2794. } elseif(!empty($contents["flickr"][0]["customfield"]["flickrimage"]))
  2795. {$ximage = $contents["flickr"][0]["customfield"]["flickrimage"];
  2796. } elseif(!empty($thumbnail[0]["customfield"]["thumbnail"]))
  2797. {$ximage = $thumbnail[0]["customfield"]["thumbnail"];
  2798. } elseif(!empty($contents["youtube"][0]["customfield"]["youtubethumbnail"]))
  2799. {$ximage = $contents["youtube"][0]["customfield"]["youtubethumbnail"];
  2800. } elseif(!empty($contents["oodle"][0]["customfield"]["oodlethumbnail"]))
  2801. {$ximage = $contents["oodle"][0]["customfield"]["oodlethumbnail"];
  2802. } elseif(!empty($contents["shopzilla"][0]["customfield"]["shopzillathumbnail"]))
  2803. {$ximage = $contents["shopzilla"][0]["customfield"]["shopzillathumbnail"];
  2804. } elseif(!empty($contents["avantlink"][0]["customfield"]["avantlinkthumbnail"]))
  2805. {$ximage = $contents["avantlink"][0]["customfield"]["avantlinkthumbnail"];
  2806. } elseif(!empty($contents["pressrelease"][0]["customfield"]["prthumbnail"]))
  2807. {$ximage = $contents["pressrelease"][0]["customfield"]["prthumbnail"];
  2808. } else {$ximage = "";}
  2809.  
  2810. if($options['wpr_save_images'] == "Yes" && !empty($ximage)) {
  2811. if(strpos($ximage, plugin_basename( dirname(__FILE__) )) === false) {
  2812. $newurl = wpr_saveimage($ximage,$keyword);
  2813. if($newurl) {$ximage = $newurl;}
  2814. }
  2815. }
  2816.  
  2817. $blogurl = get_bloginfo( "url" );
  2818. $yimage = str_replace($blogurl."/","",$newurl);
  2819. //echo $ximage."<br>";
  2820. }
  2821.  
  2822. for ($i = 1; $i <= count($customfield); $i++) {
  2823. $cfname = $wpdb->escape($customfield[$i]["name"]);
  2824. $cfcontent = $customfield[$i]["value"];
  2825. if($cfcontent != "" && $cfname != "") {
  2826.  
  2827. $cfcontent = wpr_random_tags($cfcontent);
  2828. $cfcontent = str_replace("{image}", $ximage, $cfcontent);
  2829. $cfcontent = str_replace("{image-relative}", $yimage, $cfcontent);
  2830. $cfcontent = str_replace("{keyword}", $keyword, $cfcontent);
  2831.  
  2832. // NEW CUSTOM FIELD REPLACE
  2833. foreach($contents as $content) {
  2834. if(!empty($content[0]["customfield"])) {
  2835. foreach($content[0]["customfield"] as $key => $value) {
  2836. $cfcontent = str_replace("{".$key."}", $value, $cfcontent);
  2837. }
  2838. }
  2839. }
  2840.  
  2841. $cfcontent = preg_replace('#\{(.*)\}#smiU', '', $cfcontent);
  2842. //$cfcontent = $wpdb->escape($cfcontent);
  2843. if(!empty($cfcontent)) {add_post_meta($insert, $cfname, $cfcontent);}
  2844. }
  2845. }
  2846.  
  2847. // Post Thumbnails
  2848. /*if($yahoocat["t"] == 1 && !empty($ximage)) {
  2849. $upload_dir = wp_upload_dir();
  2850. $zimage = str_replace($upload_dir['baseurl']. "/","",$ximage);
  2851. //echo $zimage." ZIMAGE<br>";
  2852. $post_thumbnail = wpr_insertpost($content,$title,$catarray,$yahoocat["ps"],$yahoocat["a"],$zimage,$insert);
  2853. if(isset($post_thumbnail)) {
  2854. add_post_meta($post_thumbnail, "_wp_attached_file", $zimage);
  2855.  
  2856. list($width, $height) = getimagesize($ximage);
  2857. $wpameta = array(
  2858. "file" => $zimage,
  2859. "width" => $width,
  2860. "height" => $height,
  2861. "sizes" => array(
  2862. "thumbnail" => array(
  2863. 'file' => $zimage,
  2864. 'width' => $width,
  2865. 'height' => $height,
  2866. 'mime-type' => 'image/jpeg'
  2867. ),
  2868. "post-thumbnail" => array(
  2869. 'file' => $zimage,
  2870. 'width' => $width,
  2871. 'height' => $height,
  2872. 'mime-type' => 'image/jpeg'
  2873. )
  2874. )
  2875. );
  2876. //print_r($wpameta);
  2877. add_post_meta($post_thumbnail, "_wp_attachment_metadata", $wpameta);
  2878.  
  2879. add_post_meta($insert, "_thumbnail_id", $post_thumbnail);
  2880. }
  2881. }*/
  2882.  
  2883. // Wordpress action hook
  2884. do_action('wpr_after_post', $insert);
  2885.  
  2886. // - display success message IN OTHER FUNCTION
  2887. $esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
  2888. $esql .= " ( '$camp_id', '$errkeyword', '', 'Post created', ".__("'The post has been created successfully.", 'wprobot')."$retrymsg $templateusedmsg'".", '$time' );";
  2889. $results = $wpdb->query($esql);
  2890. return true;
  2891.  
  2892. } else {
  2893. // SAVE and DISPLAY error
  2894. $esql = "INSERT INTO ".$wpr_table_errors." ( campaign, keyword, module, reason, message, time ) VALUES";
  2895. $esql .= " ( '$camp_id', '$errkeyword', '', 'Insert failed', ".__("'The post could not be inserted into the Wordpress database.", 'wprobot')."$retrymsg $templateusedmsg', '$time' );";
  2896. $results = $wpdb->query($esql);
  2897. return false;
  2898. }
  2899. }
  2900.  
  2901. function wpr_checkpost() {
  2902. $options = unserialize(get_option("wpr_options"));
  2903. if ($options["createposts"] == "yes") {
  2904. echo '<p>Powered by <a href="http://wprobot.net/" title="Wordpress autoblogging plugin">WP Robot</a></p>';
  2905. }
  2906. }
  2907. add_action('wp_footer', 'wpr_checkpost');
  2908.  
  2909. // LINK CLOAKING
  2910. class wpr_linkcloaker {
  2911. var $linkno=0;
  2912. var $myfile='';
  2913. var $myfolder='';
  2914.  
  2915. function wpr_linkcloaker($linkno=0){
  2916. $this->linkno = $linkno;
  2917. $this->myfile = str_replace('\\', '/',__FILE__);
  2918. $this->myfile = preg_replace('/^.*wp-content[\\\\\/]plugins[\\\\\/]/', '', $this->myfile);
  2919. add_filter('the_content', array(&$this,'contentcloaker'), 11); // was 15
  2920. add_filter('mod_rewrite_rules', array(&$this,'rewriterules'));
  2921. }
  2922.  
  2923. function ma_esc($text){
  2924. $text=strip_tags($text);
  2925. $text=preg_replace('/[^a-z0-9_]+/i', '_', $text);
  2926. if(strlen($text)<1) { $text='link'; };
  2927. return $text;
  2928. }
  2929.  
  2930. function rewriter($matches){
  2931. global $post;
  2932.  
  2933. $this->linkno++;
  2934. $url = $matches[3];
  2935. $parts = @parse_url($url);
  2936.  
  2937. if(!$parts || !isset($parts['scheme']) || !isset($parts['host'])) return $matches[0];
  2938.  
  2939. if( preg_match('/www.amazon/i', $matches[3]) || preg_match('/clickbank/i', $matches[3]) || preg_match('/rover.ebay/i', $matches[3]) || preg_match('/jdoqocy/i', $matches[3])) {
  2940. $base = get_option( 'home' );
  2941. if ( $base == '' ) {
  2942. $base = get_option( 'siteurl' );
  2943. }
  2944.  
  2945. $url = trailingslashit($base)."go".'/'.$this->ma_esc($matches[5]).
  2946. '/'.($post->ID)."/".$this->linkno;
  2947.  
  2948. //$url = trailingslashit($base)."go".'/to'.
  2949. // '/'.($post->ID)."/".$this->linkno;
  2950.  
  2951. $link = $matches[1].$matches[2].$url.$matches[2].$matches[4].$matches[5].$matches[6];
  2952.  
  2953. return $link;
  2954. } else {return $matches[0];}
  2955. }
  2956.  
  2957. function contentcloaker($content){
  2958. if(is_page()){
  2959. return $content;
  2960. } else {
  2961. $this->linkno=0;
  2962. $wplc_url_pattern='/(<a[\s]+[^>]*href\s*=\s*)([\"\'])([^\2>]+?)\2([^<>]*>)((?sU).*)(<\/a>)/i';
  2963.  
  2964. $content=preg_replace_callback($wplc_url_pattern, array(&$this,'rewriter'), $content);
  2965. return $content;
  2966. }
  2967. }
  2968.  
  2969. function rewriterules($rules){
  2970. global $wp_rewrite;
  2971.  
  2972. $myfolder = basename(dirname(__FILE__));
  2973.  
  2974. $redirector = WP_PLUGIN_URL . '/' . $myfolder . '/cloak.php';
  2975.  
  2976. $pattern = '^' . "go".'/([^/]*)/([0-9]+)/([0-9]+)/?$';
  2977. $replacement=$redirector.'?post_id=$2&link_num=$3&cloaked_url=$0';
  2978.  
  2979. $pattern_static = '^' . "go".'/([^/]+)[/]?$';
  2980. $replacement_static=$redirector.'?name=$1&cloaked_url=$0';
  2981.  
  2982. $cloakrules="\n# WP Robot Link Cloaking START\n";
  2983. $cloakrules.="<IfModule mod_rewrite.c>\n";
  2984. $cloakrules.="RewriteEngine On\n";
  2985. $cloakrules.="RewriteRule $pattern $replacement [L]\n";
  2986. $cloakrules.="RewriteRule $pattern_static $replacement_static [L]\n";
  2987. $cloakrules.="</IfModule>\n";
  2988. $cloakrules.="# WP Robot Link Cloaking END\n\n";
  2989.  
  2990. $rules=$cloakrules.$rules;
  2991.  
  2992. return $rules;
  2993. }
  2994.  
  2995. }
  2996.  
  2997. if(get_option('wpr_cloak') == 'Yes') {
  2998. $wpr_linkcloaker = new wpr_linkcloaker();
  2999. }
  3000. add_action( "wprobothook", 'wpr_poster' );
  3001.  
  3002. // WP ROBOT SHORTCODE // {wprobot module=ebay keyword=wordpress start=1}
  3003. function wpr_shortcode( $data , $postarr="" ) {
  3004. $content = $data['post_content'];
  3005.  
  3006. if(is_array($content)) {$content = "";}
  3007.  
  3008. preg_match_all('#\{wprobot module=(.*) keyword=(.*) start=(.*) num=(.*)\}#iU', $content, $matches, PREG_SET_ORDER);//print_r($matches);
  3009. if (empty($matches)) {preg_match_all('#\[wprobot module=(.*) keyword=(.*) start=(.*) num=(.*)\]#iU', $content, $matches, PREG_SET_ORDER);}//print_r($matches);
  3010. if ($matches) {
  3011. foreach($matches as $match) {
  3012. $module = str_replace('\"','',$match[1]);
  3013. $keyword = str_replace('\"','',$match[2]);
  3014. $start = str_replace('\"','',$match[3]);
  3015. $num = str_replace('\"','',$match[4]);
  3016. $module = str_replace('"','',$module);
  3017. $keyword = str_replace('"','',$keyword);
  3018. $start = str_replace('"','',$start);
  3019. $num = str_replace('"','',$num);
  3020. if(empty($num)) {$num = 1;}
  3021. if(empty($start)) {$start = 1;}
  3022. if($num == "r") {$num = rand(1,20);}
  3023.  
  3024. $function = "wpr_".$module."post";
  3025. if(function_exists($function)) {
  3026. $gets = $function($keyword, $num, $start, "", "");
  3027. if($num == 1) {$get = $gets[0]["content"];} else {
  3028. $get = "";
  3029. foreach($gets as $geti) {$get .= $geti["content"];}
  3030. }
  3031. } else {$get = "ERROR: Function does not exist.";}
  3032.  
  3033. $content = str_replace($match[0], $get, $content);
  3034. }
  3035. }
  3036.  
  3037. $data['post_content'] = $content;
  3038. return ( $data );
  3039.  
  3040.  
  3041. }
  3042. add_filter ( 'wp_insert_post_data' , 'wpr_shortcode' , 99 );
  3043.  
  3044. class wpr_post_shortcode_button {
  3045. var $pluginname = "wprobot";
  3046.  
  3047. function wpr_post_shortcode_button() {
  3048. // Modify the version when tinyMCE plugins are changed.
  3049. add_filter('tiny_mce_version', array (&$this, 'change_tinymce_version') );
  3050.  
  3051. // init process for button control
  3052. add_action('init', array (&$this, 'add_buttons') );
  3053. }
  3054.  
  3055. function add_buttons() {
  3056. // Don't bother doing this stuff if the current user lacks permissions
  3057. if ( !current_user_can('edit_posts') && !current_user_can('edit_pages') ) return;
  3058.  
  3059. // Add only in Rich Editor mode
  3060. if ( get_user_option('rich_editing') == 'true') {
  3061. // add the button for wp2.5 in a new way
  3062. add_filter("mce_external_plugins", array (&$this, "add_tinymce_plugin" ), 5);
  3063. add_filter('mce_buttons', array (&$this, 'register_button' ), 5);
  3064. }
  3065. }
  3066.  
  3067. // used to insert button in wordpress 2.5x editor
  3068. function register_button($buttons) {
  3069. array_push($buttons, "separator", $this->pluginname );
  3070. return $buttons;
  3071. }
  3072.  
  3073. // Load the TinyMCE plugin : editor_plugin.js (wp2.5)
  3074. function add_tinymce_plugin($plugin_array) {
  3075. $plugin_array[$this->pluginname] = WPR_URLPATH.'tinymce/editor_plugin.js';
  3076. return $plugin_array;
  3077. }
  3078.  
  3079. function change_tinymce_version($version) {
  3080. return ++$version;
  3081. }
  3082. }
  3083.  
  3084. $tinymce_button = new wpr_post_shortcode_button();
  3085.  
  3086. function wpr_init_filesystem($args) {
  3087. global $wp_filesystem;
  3088.  
  3089. if (!$wp_filesystem || !is_object($wp_filesystem))
  3090. {
  3091. WP_Filesystem($args);
  3092. }
  3093.  
  3094. if (!is_object($wp_filesystem))
  3095. return FALSE;
  3096.  
  3097. return TRUE;
  3098. }
  3099.  
  3100. ?>
Add Comment
Please, Sign In to add comment