/** * Called when plugin is activated * * */ function activate($force_install = false) { global $wpdb; if (file_exists(ABSPATH . '/wp-admin/upgrade-functions.php')) { require_once ABSPATH . '/wp-admin/upgrade-functions.php'; } else { require_once ABSPATH . '/wp-admin/includes/upgrade.php'; } # Options WPOTools::addMissingOptions(array('wpo_log' => array(1, 'Log WP-o-Matic actions'), 'wpo_log_stdout' => array(0, 'Output logs to browser while a campaign is being processed'), 'wpo_unixcron' => array(WPOTools::isUnix(), 'Use unix-style cron'), 'wpo_croncode' => array(substr(md5(time()), 0, 8), 'Cron job password.'), 'wpo_cacheimages' => array(0, 'Cache all images. Overrides campaign options'), 'wpo_cachepath' => array('cache', 'Cache path relative to wpomatic directory'), 'wpo_duplicates' => array(0, 'Allows duplicate posts'))); // only re-install if new version or uninstalled if ($force_install || !$this->installed || $this->installed != $this->version) { # wpo_campaign dbDelta("CREATE TABLE {$this->db['campaign']} (\n\t\t\t\t\t\t\t id int(11) unsigned NOT NULL auto_increment,\n\t\t\t\t\t\t\t title varchar(255) NOT NULL default '',\n\t\t\t\t\t\t\t active tinyint(1) default '1',\n\t\t\t\t\t\t\t slug varchar(250) default '',\n\t\t\t\t\t\t\t template MEDIUMTEXT default '',\n \t\t\t\t\t\t\t frequency int(5) default '180',\n\t\t\t\t\t\t\t feeddate tinyint(1) default '0',\n\t\t\t\t\t\t\t cacheimages tinyint(1) default '1',\n\t\t\t\t\t\t\t posttype enum('publish','draft','private') NOT NULL default 'publish',\n\t\t\t\t\t\t\t authorid int(11) default NULL,\n\t\t\t\t\t\t\t comment_status enum('open','closed','registered_only') NOT NULL default 'open',\n\t\t\t\t\t\t\t allowpings tinyint(1) default '1',\n\t\t\t\t\t\t\t dopingbacks tinyint(1) default '1',\n\t\t\t\t\t\t\t max smallint(3) default '10',\n\t\t\t\t\t\t\t linktosource tinyint(1) default '0',\n\t\t\t\t\t\t\t count int(11) default '0',\n\t\t\t\t\t\t\t lastactive datetime NOT NULL default '0000-00-00 00:00:00',\n\t\t\t\t\t\t\t created_on datetime NOT NULL default '0000-00-00 00:00:00',\n\t\t\t\t\t\t\t PRIMARY KEY (id)\n\t\t\t\t\t\t );"); # wpo_campaign_category dbDelta("CREATE TABLE {$this->db['campaign_category']} (\n \t\t\t\t\t\t id int(11) unsigned NOT NULL auto_increment,\n \t\t\t\t\t\t\t category_id int(11) NOT NULL,\n \t\t\t\t\t\t\t campaign_id int(11) NOT NULL,\n \t\t\t\t\t\t\t PRIMARY KEY (id)\n \t\t\t\t\t\t );"); # wpo_campaign_feed dbDelta("CREATE TABLE {$this->db['campaign_feed']} (\n \t\t\t\t\t\t id int(11) unsigned NOT NULL auto_increment,\n \t\t\t\t\t\t\t campaign_id int(11) NOT NULL default '0',\n \t\t\t\t\t\t\t url varchar(255) NOT NULL default '',\n \t\t\t\t\t\t\t type varchar(255) NOT NULL default '',\n \t\t\t\t\t\t\t title varchar(255) NOT NULL default '',\n \t\t\t\t\t\t\t description varchar(255) NOT NULL default '',\n \t\t\t\t\t\t\t logo varchar(255) default '',\n \t\t\t\t\t\t\t count int(11) default '0',\n \t\t\t\t\t\t\t hash varchar(255) default '',\n \t\t\t\t\t\t\t lastactive datetime NOT NULL default '0000-00-00 00:00:00',\n \t\t\t\t\t\t\t PRIMARY KEY (id)\n \t\t\t\t\t\t );"); # wpo_campaign_post dbDelta("CREATE TABLE {$this->db['campaign_post']} (\n \t\t\t\t id int(11) unsigned NOT NULL auto_increment,\n \t\t\t\t\t campaign_id int(11) NOT NULL,\n \t\t\t\t\t feed_id int(11) NOT NULL,\n \t\t\t\t\t post_id int(11) NOT NULL,\n\t\t\t\t\t\t hash varchar(255) default '',\n \t\t\t\t\t PRIMARY KEY (id)\n \t\t\t\t );"); # wpo_campaign_word dbDelta("CREATE TABLE {$this->db['campaign_word']} (\n \t\t\t\t\t\t id int(11) unsigned NOT NULL auto_increment,\n \t\t\t\t\t\t\t campaign_id int(11) NOT NULL,\n \t\t\t\t\t\t\t word varchar(255) NOT NULL default '',\n\t\t\t\t\t\t\t regex tinyint(1) default '0',\n \t\t\t\t\t\t\t rewrite tinyint(1) default '1',\n \t\t\t\t\t\t\t rewrite_to varchar(255) default '',\n \t\t\t\t\t\t\t relink varchar(255) default '',\n \t\t\t\t\t\t\t PRIMARY KEY (id)\n \t\t\t\t\t\t );"); # wpo_log dbDelta("CREATE TABLE {$this->db['log']} (\n \t\t\t\t\t\t id int(11) unsigned NOT NULL auto_increment,\n \t\t\t\t\t\t\t message mediumtext NOT NULL default '',\n \t\t\t\t\t\t\t created_on datetime NOT NULL default '0000-00-00 00:00:00',\n \t\t\t\t\t\t\t PRIMARY KEY (id)\n \t\t\t\t\t\t );"); add_option('wpo_version', $this->version, 'Installed version log'); $this->installed = true; } }
/** * Called when plugin is activated * * */ function activate($force_install = false) { global $wpdb, $blog_id; //error_log("OMFG!"); if (file_exists(ABSPATH . '/wp-admin/upgrade-functions.php')) { require_once ABSPATH . '/wp-admin/upgrade-functions.php'; } else { require_once ABSPATH . '/wp-admin/includes/upgrade.php'; } $croncode = array(substr(md5(time()), 0, 8), 'Cron job password.'); # Options WPOTools::addMissingOptions(array('wpo_log' => array(1, 'Log WP-o-Matic actions'), 'wpo_log_stdout' => array(0, 'Output logs to browser while a campaign is being processed'), 'wpo_unixcron' => array(WPOTools::isUnix(), 'Use unix-style cron'), 'wpo_croncode' => $croncode, 'wpo_cacheimages' => array(0, 'Cache all images. Overrides campaign options'), 'wpo_cachepath' => array('cache', 'Cache path relative to wpomatic directory'))); //$force_install = true; // only re-install if new version or uninstalled if ($force_install || !$this->installed || $this->installed != $this->version) { # wpo_campaign dbDelta("CREATE TABLE {$this->db['campaign']} (\n\t\t\t\t\t\t\t id int(11) unsigned NOT NULL auto_increment,\n\t\t\t\t\t\t\t title varchar(255) NOT NULL default '', \n\t\t\t\t\t\t\t active tinyint(1) default '1', \n\t\t\t\t\t\t\t slug varchar(250) default '', \n\t\t\t\t\t\t\t template MEDIUMTEXT default '', \n \t\t\t\t\t\t\t frequency int(5) default '180',\n\t\t\t\t\t\t\t feeddate tinyint(1) default '1', \n\t\t\t\t\t\t\t cacheimages tinyint(1) default '1',\n\t\t\t\t\t\t\t posttype enum('publish','draft','private') NOT NULL default 'publish',\n\t\t\t\t\t\t\t authorid int(11) default NULL, \n\t\t\t\t\t\t\t comment_status enum('open','closed','registered_only') NOT NULL default 'open',\n\t\t\t\t\t\t\t allowpings tinyint(1) default '1',\n\t\t\t\t\t\t\t dopingbacks tinyint(1) default '1',\n\t\t\t\t\t\t\t max smallint(3) default '20',\n\t\t\t\t\t\t\t linktosource tinyint(1) default '0',\n\t\t\t\t\t\t\t count int(11) default '0',\n\t\t\t\t\t\t\t lastactive datetime NOT NULL default '0000-00-00 00:00:00',\t\n\t\t\t\t\t\t\t created_on datetime NOT NULL default '0000-00-00 00:00:00', \t\t\t\t\t\t\t \n\t\t\t\t\t\t\t PRIMARY KEY (id)\n\t\t\t\t\t\t );"); dbDelta("CREATE TABLE {$this->db['authors']} (\n\t\t\t\t\t\tid mediumint(9) NOT NULL auto_increment,\n\t\t\t\t\t\tname varchar(255) NOT NULL,\n\t\t\t\t\t\temail varchar(255),\n\t\t\t\t\t\turl varchar(255),\n\t\t\t\t\t\tPRIMARY KEY (id)\n\t\t\t\t\t);"); # wpo_campaign_category dbDelta("CREATE TABLE {$this->db['campaign_category']} (\n \t\t\t\t\t\t\t category_id int(11) NOT NULL,\n \t\t\t\t\t\t\t campaign_id int(11) NOT NULL,\n \t\t\t\t\t\t\t PRIMARY KEY (category_id, campaign_id)\n \t\t\t\t\t\t );"); # wpo_campaign_feed dbDelta("CREATE TABLE {$this->db['campaign_feed']} (\n \t\t\t\t\t\t id int(11) unsigned NOT NULL auto_increment,\n \t\t\t\t\t\t\t campaign_id int(11) NOT NULL default '0', \n \t\t\t\t\t\t\t url varchar(255) NOT NULL default '', \n \t\t\t\t\t\t\t type varchar(255) NOT NULL default '', \n \t\t\t\t\t\t\t title varchar(255) NOT NULL default '', \n \t\t\t\t\t\t\t description varchar(255) NOT NULL default '',\n \t\t\t\t\t\t\t logo varchar(255) default '', \n \t\t\t\t\t\t\t count int(11) default '0',\n \t\t\t\t\t\t\t hash varchar(255) default '',\n \t\t\t\t\t\t\t lastactive datetime NOT NULL default '0000-00-00 00:00:00',\t\t\t\t\t\t\t \n \t\t\t\t\t\t\t PRIMARY KEY (id)\n \t\t\t\t\t\t );"); # wpo_campaign_post dbDelta("CREATE TABLE {$this->db['campaign_post']} (\n \t\t\t\t id int(11) unsigned NOT NULL auto_increment,\n \t\t\t\t\t campaign_id int(11) NOT NULL,\n \t\t\t\t\t feed_id int(11) NOT NULL,\n \t\t\t\t\t post_id int(11) NOT NULL,\t\t\t\t\t\n\t\t\t\t\t\t hash varchar(255) default '' UNIQUE,\t \n \t\t\t\t\t PRIMARY KEY (id)\n \t\t\t\t );"); # wpo_campaign_word dbDelta("CREATE TABLE {$this->db['campaign_word']} (\n \t\t\t\t\t\t id int(11) unsigned NOT NULL auto_increment,\n \t\t\t\t\t\t\t campaign_id int(11) NOT NULL,\n \t\t\t\t\t\t\t word varchar(255) NOT NULL default '',\n\t\t\t\t\t\t\t regex tinyint(1) default '0',\n \t\t\t\t\t\t\t rewrite tinyint(1) default '1',\n \t\t\t\t\t\t\t rewrite_to varchar(255) default '',\n \t\t\t\t\t\t\t relink varchar(255) default '',\n \t\t\t\t\t\t\t PRIMARY KEY (id)\n \t\t\t\t\t\t );"); # wpo_log dbDelta("CREATE TABLE {$this->db['log']} (\n \t\t\t\t\t\t id int(11) unsigned NOT NULL auto_increment,\n \t\t\t\t\t\t\t message mediumtext NOT NULL default '',\n \t\t\t\t\t\t\t created_on datetime NOT NULL default '0000-00-00 00:00:00',\n \t\t\t\t\t\t\t PRIMARY KEY (id)\n \t\t\t\t\t\t );"); add_option('wpo_version', $this->version, 'Installed version log'); $main = array('title' => 'Feeds to Approve', 'posttype' => 'draft', 'active' => 0, 'comment_status' => 'closed', 'lastactive' => time(), 'created_on' => time()); $this->installed = true; } if (!get_option('wpo-fu-campaign-id')) { $wpdb->insert($this->db['campaign'], $main, array('%s', '%s', '%d', '%s', '%s', '%s')); update_option('wpo-fu-campaign-id', $wpdb->insert_id); } global $current_site; $id = 'campdx.com' == $current_site->domain ? 61 : 35; update_usermeta(1, 'feeduserid', $id); $wpdb->insert('wp_croncodes', array('blog_id' => $blog_id, 'cron_code' => $croncode), array('%d', '%s')); }
/** * Called when autoreader plugin is first activated * * */ public function activate($h, $force_install = false) { // only re-install if there is new version or plugin has been uninstalled if ($force_install || !$h->getPluginVersion() || $h->getPluginVersion() != $this->version) { # autoreader_campaign $exists = $h->db->table_exists(str_replace(DB_PREFIX, "", $this->db['campaign'])); if (!$exists) { $h->db->query("CREATE TABLE " . $this->db['campaign'] . " (\n id int(11) unsigned NOT NULL auto_increment,\n title varchar(255) NOT NULL default '',\n active tinyint(1) default '1',\n slug varchar(250) default '',\n template MEDIUMTEXT default '',\n frequency int(5) default '180',\n feeddate tinyint(1) default '0',\n cacheimages tinyint(1) default '1',\n posttype enum('new','pending','top') NOT NULL default 'pending',\n authorid int(11) default NULL,\n comment_status enum('open','closed','registered_only') NOT NULL default 'open',\n allowpings tinyint(1) default '1',\n dopingbacks tinyint(1) default '1',\n max smallint(3) default '10',\n linktosource tinyint(1) default '0',\n count int(11) default '0',\n lastactive datetime NOT NULL default '0000-00-00 00:00:00',\n created_on datetime NOT NULL default '0000-00-00 00:00:00',\n PRIMARY KEY (id)\n ) ENGINE=" . DB_ENGINE . " DEFAULT CHARSET=" . DB_CHARSET . " COLLATE=" . DB_COLLATE . " COMMENT='autoreader campaign'; "); } else { //update for 0.1 versions $sql = "ALTER TABLE " . $this->db['campaign'] . " MODIFY COLUMN posttype enum('new','pending','top') NOT NULL default 'pending'"; $h->db->query($h->db->prepare($sql)); } # autoreader_campaign_category $exists = $h->db->table_exists(str_replace(DB_PREFIX, "", $this->db['campaign_category'])); if (!$exists) { $h->db->query("CREATE TABLE " . $this->db['campaign_category'] . " (\n \t\t\t\t\t\t id int(11) unsigned NOT NULL auto_increment,\n \t\t\t\t\t\t\t category_id int(11) NOT NULL,\n \t\t\t\t\t\t\t campaign_id int(11) NOT NULL,\n \t\t\t\t\t\t\t PRIMARY KEY (id)\n \t\t\t\t\t\t ) ENGINE=" . DB_ENGINE . " DEFAULT CHARSET=" . DB_CHARSET . " COLLATE=" . DB_COLLATE . " COMMENT='autoreader campaign category'; "); } # autoreader_campaign_feed $exists = $h->db->table_exists(str_replace(DB_PREFIX, "", $this->db['campaign_feed'])); if (!$exists) { $h->db->query("CREATE TABLE " . $this->db['campaign_feed'] . " (\n id int(11) unsigned NOT NULL auto_increment,\n campaign_id int(11) NOT NULL default '0',\n url varchar(255) NOT NULL default '',\n type varchar(255) NOT NULL default '',\n title varchar(255) NOT NULL default '',\n description varchar(255) NOT NULL default '',\n logo varchar(255) default '',\n count int(11) default '0',\n hash varchar(255) default '',\n lastactive datetime NOT NULL default '0000-00-00 00:00:00',\n PRIMARY KEY (id)\n ) ENGINE=" . DB_ENGINE . " DEFAULT CHARSET=" . DB_CHARSET . " COLLATE=" . DB_COLLATE . " COMMENT='autoreader campaign feed'; "); } # autoreader_campaign_post $exists = $h->db->table_exists(str_replace(DB_PREFIX, "", $this->db['campaign_post'])); if (!$exists) { $h->db->query("CREATE TABLE " . $this->db['campaign_post'] . " (\n id int(11) unsigned NOT NULL auto_increment,\n campaign_id int(11) NOT NULL,\n feed_id int(11) NOT NULL,\n post_id int(11) NOT NULL,\n hash varchar(255) default '',\n PRIMARY KEY (id)\n ) ENGINE=" . DB_ENGINE . " DEFAULT CHARSET=" . DB_CHARSET . " COLLATE=" . DB_COLLATE . " COMMENT='autoreader campaign post'; "); } # autoreader_campaign_word $exists = $h->db->table_exists(str_replace(DB_PREFIX, "", $this->db['campaign_word'])); if (!$exists) { $h->db->query("CREATE TABLE " . $this->db['campaign_word'] . " (\n id int(11) unsigned NOT NULL auto_increment,\n campaign_id int(11) NOT NULL,\n word varchar(255) NOT NULL default '',\n regex tinyint(1) default '0',\n rewrite tinyint(1) default '1',\n rewrite_to varchar(255) default '',\n relink varchar(255) default '',\n PRIMARY KEY (id)\n ) ENGINE=" . DB_ENGINE . " DEFAULT CHARSET=" . DB_CHARSET . " COLLATE=" . DB_COLLATE . " COMMENT='autoreader campaign word'; "); } # autoreader_log $exists = $h->db->table_exists(str_replace(DB_PREFIX, "", $this->db['log'])); if (!$exists) { $h->db->query("CREATE TABLE " . $this->db['log'] . " (\n id int(11) unsigned NOT NULL auto_increment,\n message mediumtext NOT NULL default '',\n created_on datetime NOT NULL default '0000-00-00 00:00:00',\n PRIMARY KEY (id)\n ) ENGINE=" . DB_ENGINE . " DEFAULT CHARSET=" . DB_CHARSET . " COLLATE=" . DB_COLLATE . " COMMENT='autoreader log'; "); } # Options WPOTools::addMissingOptions(array('wpo_log' => array(1, 'Log WP-o-Matic actions'), 'wpo_log_stdout' => array(0, 'Output logs to browser while a campaign is being processed'), 'wpo_unixcron' => array(WPOTools::isUnix(), 'Use unix-style cron'), 'wpo_croncode' => array(substr(md5(time()), 0, 8), 'Cron job password.'), 'wpo_cacheimages' => array(0, 'Cache all images. Overrides campaign options'), 'wpo_cachepath' => array('cache', 'Cache path relative to wpomatic directory'))); $this->installed = true; } }