prefix . "awpcp_adfees"); define('AWPCP_TABLE_ADS', $wpdb->prefix . "awpcp_ads"); define('AWPCP_TABLE_AD_REGIONS', $wpdb->prefix . "awpcp_ad_regions"); define('AWPCP_TABLE_AD_META', $wpdb->prefix . 'awpcp_admeta'); define('AWPCP_TABLE_MEDIA', $wpdb->prefix . "awpcp_media"); define('AWPCP_TABLE_CATEGORIES', $wpdb->prefix . "awpcp_categories"); define('AWPCP_TABLE_PAYMENTS', $wpdb->prefix . 'awpcp_payments'); define('AWPCP_TABLE_CREDIT_PLANS', $wpdb->prefix . 'awpcp_credit_plans'); define('AWPCP_TABLE_PAGES', $wpdb->prefix . "awpcp_pages"); define('AWPCP_TABLE_PAGENAME', $wpdb->prefix . "awpcp_pagename"); define('AWPCP_TABLE_ADSETTINGS', $wpdb->prefix . "awpcp_adsettings"); define('AWPCP_TABLE_ADPHOTOS', $wpdb->prefix . "awpcp_adphotos"); class AWPCP_Installer { private static $instance = null; private function AWPCP_Installer() { $this->columns = awpcp_database_column_creator(); $this->create_ads_table = "CREATE TABLE IF NOT EXISTS " . AWPCP_TABLE_ADS . " ( `ad_id` INT(10) NOT NULL AUTO_INCREMENT, `adterm_id` INT(10) NOT NULL DEFAULT 0, `payment_term_type` VARCHAR(64) NOT NULL DEFAULT 'fee', `ad_fee_paid` FLOAT(7,2) NOT NULL, `ad_category_id` INT(10) NOT NULL, `ad_category_parent_id` INT(10) NOT NULL, `ad_title` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', `ad_details` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, `ad_contact_name` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', `ad_contact_phone` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', `ad_contact_email` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', `websiteurl` VARCHAR( 375 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, `ad_city` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', `ad_state` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', `ad_country` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', `ad_county_village` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', `ad_item_price` INT(25) NOT NULL, `ad_views` INT(10) NOT NULL DEFAULT 0, `ad_postdate` DATE NOT NULL, `ad_last_updated` DATE NOT NULL, `ad_startdate` DATETIME NOT NULL, `ad_enddate` DATETIME NOT NULL, `disabled` TINYINT(1) NOT NULL DEFAULT 0, `disabled_date` DATETIME, `flagged` TINYINT(1) NOT NULL DEFAULT 0, `verified` TINYINT(1) NOT NULL DEFAULT 1, `verified_at` DATETIME, `ad_key` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', `ad_transaction_id` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', `payment_gateway` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', `payment_status` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', `payer_email` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', `is_featured_ad` TINYINT(1) DEFAULT NULL, `posterip` VARCHAR(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', `user_id` INT(10) DEFAULT NULL, `renew_email_sent` TINYINT(1) NOT NULL DEFAULT 0, `renewed_date` DATETIME, FULLTEXT KEY `titdes` (`ad_title`,`ad_details`), PRIMARY KEY (`ad_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;"; $this->create_ad_regions_table = "CREATE TABLE IF NOT EXISTS " . AWPCP_TABLE_AD_REGIONS . " ( `id` INT(10) NOT NULL AUTO_INCREMENT, `ad_id` INT(10) NOT NULL, `country` VARCHAR(64) COLLATE utf8_general_ci DEFAULT '', `county` VARCHAR(64) COLLATE utf8_general_ci DEFAULT '', `state` VARCHAR(64) COLLATE utf8_general_ci DEFAULT '', `city` VARCHAR(64) COLLATE utf8_general_ci DEFAULT '', `region_id` INT(10) DEFAULT NULL, INDEX `country_index` (`country`), INDEX `county_index` (`county`), INDEX `state_index` (`state`), INDEX `city_index` (`city`), INDEX `region_id_index` (`region_id`), PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;"; $this->create_fees_table = "CREATE TABLE IF NOT EXISTS " . AWPCP_TABLE_ADFEES . " ( `adterm_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `adterm_name` VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', `credits` INT(10) NOT NULL DEFAULT 0, `amount` FLOAT(6,2) UNSIGNED NOT NULL DEFAULT '0.00', `recurring` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, `rec_period` INT(5) UNSIGNED NOT NULL DEFAULT 0, `rec_increment` VARCHAR(5) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', `buys` INT(10) UNSIGNED NOT NULL DEFAULT 0, `imagesallowed` INT(5) UNSIGNED NOT NULL DEFAULT 0, `is_featured_ad_pricing` TINYINT(1) DEFAULT NULL, `categories` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci, `characters_allowed` INT(1) NOT NULL DEFAULT 0, `title_characters` INT(1) NOT NULL DEFAULT 0, `private` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (`adterm_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;"; $this->create_payments_table = 'CREATE TABLE IF NOT EXISTS ' . AWPCP_TABLE_PAYMENTS . " ( `id` VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, `items` TEXT, `data` TEXT, `errors` TEXT, `user_id` INT(10) NOT NULL, `status` VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'open', `payment_status` VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_general_ci, `payment_gateway` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', `payer_email` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', `version` TINYINT(1), `created` DATETIME NOT NULL, `updated` DATETIME NOT NULL, `completed` DATETIME, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;"; $this->create_credit_plans_table = "CREATE TABLE IF NOT EXISTS " . AWPCP_TABLE_CREDIT_PLANS . " ( `id` INT(10) NOT NULL AUTO_INCREMENT, `name` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', `description` VARCHAR(500) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', `credits` INT(10) NOT NULL, `price` FLOAT, `created` DATETIME NOT NULL, `updated` DATETIME NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;"; $this->create_media_table = "CREATE TABLE IF NOT EXISTS " . AWPCP_TABLE_MEDIA . " ( `id` INT(10) NOT NULL AUTO_INCREMENT, `ad_id` INT(10) UNSIGNED NOT NULL DEFAULT 0, `name` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', `path` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', `mime_type` VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', `enabled` TINYINT(1) NOT NULL DEFAULT 0, `status` VARCHAR(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '" . AWPCP_Media::STATUS_APPROVED . "', `is_primary` TINYINT(1) NOT NULL DEFAULT 0, `created` DATETIME NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;"; $this->create_ad_meta_table = "CREATE TABLE IF NOT EXISTS " . AWPCP_TABLE_AD_META . " ( `meta_id` BIGINT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `awpcp_ad_id` BIGINT(10) UNSIGNED NOT NULL, `meta_key` VARCHAR(255), `meta_value` LONGTEXT, PRIMARY KEY (`meta_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;"; } public static function instance() { if (is_null(AWPCP_Installer::$instance)) { AWPCP_Installer::$instance = new AWPCP_Installer(); } return AWPCP_Installer::$instance; } public function activate() { $this->install(); flush_rewrite_rules(); } /** * Creates AWPCP tables. * * If is not a fresh install it calls $this->upgrade(). */ public function install() { global $awpcp, $wpdb, $awpcp_db_version; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); $installed_version = get_option( 'awpcp_db_version' ); // if table exists, this is an upgrade if ( $installed_version !== false && awpcp_table_exists( AWPCP_TABLE_CATEGORIES ) ) { return $this->upgrade( $installed_version, $awpcp_db_version ); } // create Categories table $sql = "CREATE TABLE IF NOT EXISTS " . AWPCP_TABLE_CATEGORIES . " ( `category_id` INT(10) NOT NULL AUTO_INCREMENT, `category_parent_id` INT(10) NOT NULL, `category_name` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', `category_order` INT(10) NULL DEFAULT 0, PRIMARY KEY (`category_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;"; dbDelta($sql); // create Ad Fees table dbDelta($this->create_fees_table); // create Ads table dbDelta($this->create_ads_table); // Create ad metadata table. dbDelta( $this->create_ad_meta_table ); // create awpcp_ad_regions table dbDelta( $this->create_ad_regions_table ); // create awpcp_media table dbDelta( $this->create_media_table ); // create Ad Photos table $sql = "CREATE TABLE IF NOT EXISTS " . AWPCP_TABLE_ADPHOTOS . " ( `key_id` INT(10) NOT NULL AUTO_INCREMENT, `ad_id` INT(10) UNSIGNED NOT NULL DEFAULT 0, `image_name` VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', `disabled` TINYINT(1) NOT NULL DEFAULT 0, `is_primary` TINYINT(1) NOT NULL DEFAULT 0, PRIMARY KEY (`key_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;"; dbDelta($sql); // create Pagename table // TODO: not sure if this table is needed at all, we could use an option... $sql = "CREATE TABLE IF NOT EXISTS " . AWPCP_TABLE_PAGENAME . " ( `key_id` INT(10) NOT NULL AUTO_INCREMENT, `userpagename` VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '', PRIMARY KEY (`key_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;"; dbDelta($sql); // create Pages table $sql = 'CREATE TABLE IF NOT EXISTS ' . AWPCP_TABLE_PAGES . " ( `page` VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, `id` INT(10) NOT NULL, PRIMARY KEY (`page`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;"; dbDelta($sql); // create Payments table dbDelta($this->create_payments_table); // create Credit Plans table dbDelta($this->create_credit_plans_table); // insert deafult category $category = $wpdb->get_results( 'SELECT * FROM ' . AWPCP_TABLE_CATEGORIES . ' WHERE category_id = 1' ); if ( empty( $category ) ) { $data = array( 'category_id' => 1, 'category_parent_id' => 0, 'category_name' => __( 'General', 'AWPCP' ), 'category_order' => 0 ); $wpdb->insert( AWPCP_TABLE_CATEGORIES, $data ); } // insert default Fee $fee = $wpdb->get_results( 'SELECT * FROM ' . AWPCP_TABLE_ADFEES . ' WHERE adterm_id = 1' ); if ( empty( $fee ) ) { $data = array( 'adterm_id' => 1, 'adterm_name' => __( '30 Day Listing', 'AWPCP' ), 'amount' => 9.99, 'recurring' => 1, 'rec_period' => 31, 'rec_increment' => 'D', 'buys' => 0, 'imagesallowed' => 6 ); $wpdb->insert(AWPCP_TABLE_ADFEES, $data); } $result = update_option('awpcp_db_version', $awpcp_db_version); $awpcp->settings->update_option('show-quick-start-guide-notice', true, true); do_action('awpcp_install'); return $result; } public function uninstall() { global $wpdb, $awpcp_plugin_path, $table_prefix, $awpcp; // Remove the upload folders with uploaded images $dirname = AWPCPUPLOADDIR; if (file_exists($dirname)) { require_once $awpcp_plugin_path.'/fileop.class.php'; $fileop = new fileop(); $fileop->delete($dirname); } // Delete the classifieds page(s) $pages = awpcp_pages(); foreach ($pages as $page => $data) { wp_delete_post(awpcp_get_page_id_by_ref($page), true); } // Drop the tables $wpdb->query( "DROP TABLE IF EXISTS " . AWPCP_TABLE_ADFEES ); $wpdb->query( "DROP TABLE IF EXISTS " . AWPCP_TABLE_ADPHOTOS ); $wpdb->query( "DROP TABLE IF EXISTS " . AWPCP_TABLE_ADS ); $wpdb->query( "DROP TABLE IF EXISTS " . AWPCP_TABLE_ADSETTINGS ); $wpdb->query( "DROP TABLE IF EXISTS " . AWPCP_TABLE_AD_META ); $wpdb->query( "DROP TABLE IF EXISTS " . AWPCP_TABLE_AD_REGIONS ); $wpdb->query( "DROP TABLE IF EXISTS " . AWPCP_TABLE_CATEGORIES ); $wpdb->query( "DROP TABLE IF EXISTS " . AWPCP_TABLE_CREDIT_PLANS ); $wpdb->query( "DROP TABLE IF EXISTS " . AWPCP_TABLE_MEDIA ); $wpdb->query( "DROP TABLE IF EXISTS " . AWPCP_TABLE_PAGES ); $wpdb->query( "DROP TABLE IF EXISTS " . AWPCP_TABLE_PAGENAME ); $wpdb->query( "DROP TABLE IF EXISTS " . AWPCP_TABLE_PAYMENTS ); // TODO: implement uninstall methods in other modules $tables = array($wpdb->prefix . 'awpcp_comments'); foreach ($tables as $table) { $wpdb->query("DROP TABLE IF EXISTS " . $table); } // remove AWPCP options from options table array_map('delete_option', array( 'awpcp-pending-manual-upgrade', 'awpcp_installationcomplete', 'awpcp_pagename_warning', 'widget_awpcplatestads', 'awpcp_db_version', $awpcp->settings->setting_name, )); // delete payment transactions $sql = 'SELECT option_name FROM ' . $wpdb->options . ' '; $sql.= "WHERE option_name LIKE 'awpcp-payment-transaction-%%'"; array_map('delete_option', $wpdb->get_col($sql)); // remove widgets unregister_widget("AWPCP_LatestAdsWidget"); unregister_widget('AWPCP_RandomAdWidget'); unregister_widget('AWPCP_Search_Widget'); // Clear the ad expiration schedule wp_clear_scheduled_hook('doadexpirations_hook'); wp_clear_scheduled_hook('doadcleanup_hook'); wp_clear_scheduled_hook('awpcp_ad_renewal_email_hook'); wp_clear_scheduled_hook('awpcp-clean-up-payment-transactions'); // TODO: use deactivate_plugins function // http://core.trac.wordpress.org/browser/branches/3.2/wp-admin/includes/plugin.php#L548 $current = get_option('active_plugins'); $thepluginfile = sprintf("%s/awpcp.php", trim(AWPCP_BASENAME, '/')); array_splice($current, array_search( $thepluginfile, $current), 1 ); update_option('active_plugins', $current); do_action('deactivate_' . $thepluginfile ); } // TODO: remove settings table after another major release // TODO: remove pagename table after another major release public function upgrade($oldversion, $newversion) { global $wpdb; if (version_compare($oldversion, '1.8.9.4') < 0) { $this->upgrade_to_1_8_9_4($oldversion); } if (version_compare($oldversion, '1.9.9') < 0) { $this->upgrade_to_1_9_9($oldversion); } if (version_compare($oldversion, '2.0.0') < 0) { $this->upgrade_to_2_0_0($oldversion); } if (version_compare($oldversion, '2.0.1') < 0) { $this->upgrade_to_2_0_1($oldversion); } if (version_compare($oldversion, '2.0.5') < 0) { $this->upgrade_to_2_0_5($oldversion); } if (version_compare($oldversion, '2.0.6') < 0) { $this->upgrade_to_2_0_6($oldversion); } if (version_compare($oldversion, '2.0.7') < 0) { $this->upgrade_to_2_0_7($oldversion); } if (version_compare($oldversion, '2.1.3') < 0) { $this->upgrade_to_2_1_3($oldversion); } if (version_compare($oldversion, '2.2.1') < 0) { $this->upgrade_to_2_2_1($oldversion); } if (version_compare($oldversion, '3.0-beta23') < 0) { $this->upgrade_to_3_0_0($oldversion); } if ( version_compare( $oldversion, '3.0.2' ) < 0 ) { $this->upgrade_to_3_0_2( $oldversion ); } if ( version_compare( $oldversion, '3.2.2' ) < 0 ) { $this->upgrade_to_3_2_2( $oldversion ); } do_action('awpcp_upgrade', $oldversion, $newversion); return update_option("awpcp_db_version", $newversion); } private function upgrade_to_1_8_9_4($version) { global $wpdb; // Try to enable the expired ads, bug in 1.0.6.17: if ($version == '1.0.6.17') { $query = "UPDATE ". AWPCP_TABLE_ADS ." SET DISABLED=0 WHERE ad_enddate >= NOW()"; $wpdb->query($query); } if ( version_compare( $version, '1.8.7.1', "<" ) ) { // Fix the problem with disabled_date not being nullable from 1.8.7 $query = "ALTER TABLE ". AWPCP_TABLE_ADS ." MODIFY disabled_date DATETIME"; $wpdb->query($query); } // Upgrade featured ad columns for module if ( ! awpcp_column_exists( AWPCP_TABLE_ADS, 'is_featured_ad' ) ) { $wpdb->query("ALTER TABLE " . AWPCP_TABLE_ADS . " ADD `is_featured_ad` TINYINT(1) DEFAULT NULL"); } // Upgrade for tracking poster's IP address if ( ! awpcp_column_exists( AWPCP_TABLE_ADS, 'posterip' ) ) { $wpdb->query("ALTER TABLE " . AWPCP_TABLE_ADS . " ADD `posterip` VARCHAR(15) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL"); } if ( ! awpcp_column_exists( AWPCP_TABLE_ADS, 'flagged' ) ) { $wpdb->query("ALTER TABLE " . AWPCP_TABLE_ADS . " ADD `flagged` TINYINT(1) DEFAULT NULL"); } // Upgrade for deleting ads that are marked as disabled or deleted if ( ! awpcp_column_exists( AWPCP_TABLE_ADS, 'disabled_date' ) ) { $wpdb->query("ALTER TABLE " . AWPCP_TABLE_ADS . " ADD `disabled_date` DATETIME DEFAULT NULL"); } if ( ! awpcp_column_exists( AWPCP_TABLE_ADFEES, 'is_featured_ad_pricing' ) ) { $wpdb->query("ALTER TABLE " . AWPCP_TABLE_ADFEES . " ADD `is_featured_ad_pricing` TINYINT(1) DEFAULT NULL"); } if ( ! awpcp_column_exists( AWPCP_TABLE_ADFEES, 'categories' ) ) { $wpdb->query("ALTER TABLE " . AWPCP_TABLE_ADFEES . " ADD `categories` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci"); } if ( ! awpcp_column_exists( AWPCP_TABLE_CATEGORIES, 'category_order' ) ) { $wpdb->query("ALTER TABLE " . AWPCP_TABLE_CATEGORIES . " ADD `category_order` INT(10) NULL DEFAULT 0 AFTER category_name"); $wpdb->query("UPDATE " . AWPCP_TABLE_CATEGORIES . " SET category_order=0"); } // Fix the shortcode issue if present in installed version $sql = "UPDATE " . $wpdb->posts . " SET post_content='[AWPCPCLASSIFIEDSUI]' "; $sql.= "WHERE post_content='[[AWPCPCLASSIFIEDSUI]]'"; $wpdb->query($sql); $settings_table_exists = checkfortable( AWPCP_TABLE_ADSETTINGS ); if ($settings_table_exists && !field_exists('tos')) { // add terms of service field $sql = 'INSERT INTO '. AWPCP_TABLE_ADSETTINGS .'(`config_option`,`config_value`,`config_diz`,`config_group_id`,`option_type`) VALUES ("tos","Terms of service go here...","Terms of Service for posting an ad - modify this to fit your needs:","1","0")'; $wpdb->query($sql); $sql = 'INSERT INTO '. AWPCP_TABLE_ADSETTINGS .'(`config_option`,`config_value`,`config_diz`,`config_group_id`,`option_type`) VALUES ("requiredtos", "Display and require Terms of Service","Display and require Terms of Service","1","0")'; $wpdb->query($sql); } if ($settings_table_exists && !field_exists('notifyofadexpired')) { //add notify of an expired ad field $sql = 'insert into '.AWPCP_TABLE_ADSETTINGS.'(`config_option`,`config_value`,`config_diz`,`config_group_id`,`option_type`) values ("notifyofadexpired","Notify admin of expired ads.","Notify admin of expired ads.","1","0")'; $wpdb->query($sql); } if ($settings_table_exists && field_exists('notifyofadexpired')) { //Fix bug from 1.8.6.4: $wpdb->query("UPDATE " . AWPCP_TABLE_ADSETTINGS . " SET option_type =0 where config_option='notifyofadexpired'"); } // Update ad_settings table to ad field config groud ID if field does not exist in installed version $cgid_column_name_exists = $wpdb->get_var( "SELECT config_group_id FROM " . AWPCP_TABLE_ADSETTINGS ); if ( $settings_table_exists && ( $cgid_column_name_exists === false || is_null( $cgid_column_name_exists ) ) ) { $query=("ALTER TABLE " . AWPCP_TABLE_ADSETTINGS . " ADD `config_group_id` TINYINT(1) UNSIGNED NOT NULL DEFAULT 1 AFTER config_diz"); $wpdb->query( $query ); $myconfig_group_ops_1=array('showlatestawpcpnews','uiwelcome','main_page_display','useakismet','contactformcheckhuman', 'contactformcheckhumanhighnumval','awpcptitleseparator','showcityinpagetitle','showstateinpagetitle','showcountryinpagetitle','showcategoryinpagetitle','showcountyvillageinpagetitle','awpcppagefilterswitch','activatelanguages','sidebarwidgetbeforecontent','sidebarwidgetaftercontent','sidebarwidgetbeforetitle','sidebarwidgetaftertitle','usesenderemailinsteadofadmin','awpcpadminaccesslevel','awpcpadminemail','useakismet'); $myconfig_group_ops_2=array('addurationfreemode','autoexpiredisabledelete','maxcharactersallowed','notifyofadexpiring', 'notifyofadposted', 'adapprove', 'disablependingads', 'showadcount', 'displayadviews','onlyadmincanplaceads','allowhtmlinadtext', 'hyperlinkurlsinadtext', 'notice_awaiting_approval_ad', 'buildsearchdropdownlists','visitwebsitelinknofollow','groupbrowseadsby','groupsearchresultsby','displayadthumbwidth','adresultsperpage','displayadlayoutcode','awpcpshowtheadlayout'); $myconfig_group_ops_3=array('freepay','paylivetestmode','paypalemail', 'paypalcurrencycode', 'displaycurrencycode', '2checkout', 'activatepaypal', 'activate2checkout','twocheckoutpaymentsrecurring','paypalpaymentsrecurring'); $myconfig_group_ops_4=array('imagesallowdisallow', 'awpcp_thickbox_disabled','imagesapprove', 'imagesallowedfree', 'uploadfoldername', 'maximagesize','minimagesize', 'imgthumbwidth', 'imgmaxheight', 'imgmaxwidth'); $myconfig_group_ops_5=array('useadsense', 'adsense', 'adsenseposition'); $myconfig_group_ops_6=array('displayphonefield', 'displayphonefieldreqop', 'displaycityfield', 'displaycityfieldreqop', 'displaystatefield','displaystatefieldreqop', 'displaycountryfield', 'displaycountryfieldreqop', 'displaycountyvillagefield', 'displaycountyvillagefieldreqop', 'displaypricefield', 'displaypricefieldreqop', 'displaywebsitefield', 'displaywebsitefieldreqop', 'displaypostedbyfield'); $myconfig_group_ops_7=array('requireuserregistration', 'postloginformto', 'registrationurl'); $myconfig_group_ops_8=array('contactformsubjectline','contactformbodymessage','listingaddedsubject','listingaddedbody','resendakeyformsubjectline','resendakeyformbodymessage','paymentabortedsubjectline','paymentabortedbodymessage','adexpiredsubjectline','adexpiredbodymessage'); $myconfig_group_ops_9=array('usesmtp','smtphost','smtpport','smtpusername','smtppassword'); $myconfig_group_ops_10=array('userpagename','showadspagename','placeadpagename','page-name-renew-ad','browseadspagename','browsecatspagename','editadpagename','paymentthankyoupagename','paymentcancelpagename','replytoadpagename','searchadspagename','categoriesviewpagename'); $myconfig_group_ops_11=array('seofriendlyurls','pathvaluecontact','pathvalueshowad','pathvaluebrowsecategory','pathvalueviewcategories','pathvaluecancelpayment','pathvaluepaymentthankyou'); // assign a group value to each setting foreach($myconfig_group_ops_1 as $myconfig_group_op_1){add_config_group_id($cvalue=1,$myconfig_group_op_1);} foreach($myconfig_group_ops_2 as $myconfig_group_op_2){add_config_group_id($cvalue='2',$myconfig_group_op_2);} foreach($myconfig_group_ops_3 as $myconfig_group_op_3){add_config_group_id($cvalue='3',$myconfig_group_op_3);} foreach($myconfig_group_ops_4 as $myconfig_group_op_4){add_config_group_id($cvalue='4',$myconfig_group_op_4);} foreach($myconfig_group_ops_5 as $myconfig_group_op_5){add_config_group_id($cvalue='5',$myconfig_group_op_5);} foreach($myconfig_group_ops_6 as $myconfig_group_op_6){add_config_group_id($cvalue='6',$myconfig_group_op_6);} foreach($myconfig_group_ops_7 as $myconfig_group_op_7){add_config_group_id($cvalue='7',$myconfig_group_op_7);} foreach($myconfig_group_ops_8 as $myconfig_group_op_8){add_config_group_id($cvalue='8',$myconfig_group_op_8);} foreach($myconfig_group_ops_9 as $myconfig_group_op_9){add_config_group_id($cvalue='9',$myconfig_group_op_9);} foreach($myconfig_group_ops_10 as $myconfig_group_op_10){add_config_group_id($cvalue='10',$myconfig_group_op_10);} foreach($myconfig_group_ops_11 as $myconfig_group_op_11){add_config_group_id($cvalue='11',$myconfig_group_op_11);} } if ($settings_table_exists && get_awpcp_option_group_id('seofriendlyurls') == 1){ $wpdb->query("UPDATE " . AWPCP_TABLE_ADSETTINGS . " SET `config_group_id` = '11' WHERE `config_option` = 'seofriendlyurls'"); } if ($settings_table_exists && get_awpcp_option_type('main_page_display') == 1){ $wpdb->query("UPDATE " . AWPCP_TABLE_ADSETTINGS . " SET `config_value` = 0, `option_type` = 0, `config_diz` = 'Main page layout [ check for ad listings ] [ Uncheck for categories ]',config_group_id=1 WHERE `config_option` = 'main_page_display'"); } if ($settings_table_exists && get_awpcp_option_config_diz('paylivetestmode') != "Put payment gateways in test mode"){ $wpdb->query("UPDATE " . AWPCP_TABLE_ADSETTINGS . " SET `config_value` = 0, `option_type` = 0, `config_diz` = 'Put payment gateways in test mode' WHERE `config_option` = 'paylivetestmode'");} if ($settings_table_exists && get_awpcp_option_config_diz('adresultsperpage') != "Default number of ads per page"){ $wpdb->query("UPDATE " . AWPCP_TABLE_ADSETTINGS . " SET `config_value` = '10', `option_type` = 1, `config_diz` = 'Default number of ads per page' WHERE `config_option` = 'adresultsperpage'");} if ($settings_table_exists && get_awpcp_option_config_diz('awpcpshowtheadlayout') != "