get_rows("SELECT * FROM ".$icdb->prefix."options"); foreach ($rows as $row) { if (array_key_exists($row['options_key'], $options)) $options[$row['options_key']] = $row['options_value']; } } function update_options() { global $icdb, $options; foreach ($options as $key => $value) { $option = $icdb->get_row("SELECT * FROM ".$icdb->prefix."options WHERE options_key = '".$icdb->escape_string($key)."'"); if ($option) { $icdb->query("UPDATE ".$icdb->prefix."options SET options_value = '".$icdb->escape_string($value)."' WHERE options_key = '".$icdb->escape_string($key)."'"); } else { $icdb->query("INSERT INTO ".$icdb->prefix."options (options_key, options_value) VALUES ('".$icdb->escape_string($key)."', '".$icdb->escape_string($value)."')"); } } } function populate_options() { global $icdb, $options; foreach ($options as $key => $value) { if ($key != 'password') { if (isset($_POST[$key])) { if (get_magic_quotes_gpc()) { $options[$key] = stripslashes($_POST[$key]); } else $options[$key] = $_POST[$key]; } } } } function check_options() { global $icdb, $options; $errors = array(); //if ($options['enable_payza'] != "on" && $options['enable_paypal'] != "on" && $options['enable_interkassa'] != "on" && $options['enable_authnet'] != "on" && $options['enable_egopay'] != "on" && $options['enable_perfect'] != "on" && $options['enable_skrill'] != "on" && $options['enable_bitpay'] != "on") $errors[] = 'Select at least one payment method'; if ($options['enable_paypal'] == "on") { if ((!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/i", $options['paypal_id']) && !preg_match("/^([A-Z0-9]+)$/i", $options['paypal_id'])) || strlen($options['paypal_id']) == 0) $errors[] = 'PayPal ID must be valid e-mail address or Merchant ID'; } if ($options['enable_payza'] == "on") { if (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/i", $options['payza_id']) || strlen($options['payza_id']) == 0) $errors[] = 'Payza ID must be valid e-mail address'; } if ($options['enable_interkassa'] == "on") { if (strlen($options['interkassa_checkout_id']) < 3) $errors[] = 'InterKassa Checkout ID is required'; if (strlen($options['interkassa_secret_key']) < 3) $errors[] = 'InterKassa Secret Key is required'; } if ($options['enable_authnet'] == "on") { if (strlen($options['authnet_login']) < 3) $errors[] = 'Authorize.Net API Login ID is required'; if (strlen($options['authnet_key']) < 1) $errors[] = 'Authorize.Net Transaction Key is required'; if (strlen($options['authnet_md5hash']) < 1) $errors[] = 'Authorize.Net MD5 Hash is required'; } if ($options['enable_egopay'] == "on") { if (strlen($options['egopay_store_id']) < 1) $errors[] = 'EgoPay Store ID is required'; if (strlen($options['egopay_store_pass']) < 1) $errors[] = 'EgoPay Store Pass is required'; } if ($options['enable_perfect'] == "on") { if (strlen($options['perfect_account_id']) < 1) $errors[] = 'Perfect Money Payee Account is required'; if (strlen($options['perfect_payee_name']) < 1) $errors[] = 'Perfect Money Payee Name is required'; if (strlen($options['perfect_passphrase']) < 1) $errors[] = 'Perfect Money Alternate Passphrase is required'; } if ($options['enable_skrill'] == "on") { if (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/i", $options['skrill_id']) || strlen($options['skrill_id']) == 0) $errors[] = 'Skrill ID must be valid e-mail address'; if (strlen($options['skrill_secret_word']) < 1) $errors[] = 'Skrill Secret Word is required'; } if ($options['enable_bitpay'] == "on") { if (strlen($options['bitpay_key']) < 1) $errors[] = 'BitPay API Key is required'; } if ($options['enable_stripe'] == "on") { if (strlen($options['stripe_secret']) < 1) $errors[] = 'Stripe Secret Key is required'; if (strlen($options['stripe_publishable']) < 1) $errors[] = 'Stripe Publishable Key is required'; } if (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/i", $options['owner_email']) || strlen($options['owner_email']) == 0) $errors[] = 'E-mail for notifications must be valid e-mail address'; if (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/i", $options['from_email']) || strlen($options['from_email']) == 0) $errors[] = 'Sender e-mail must be valid e-mail address'; if (strlen($options['from_name']) < 3) $errors[] = 'Sender name is too short'; if (strlen($options['success_email_subject']) < 3) $errors[] = 'Successful donation e-mail subject must contain at least 3 characters'; else if (strlen($options['success_email_subject']) > 64) $errors[] = 'Successful donation e-mail subject must contain maximum 64 characters'; if (strlen($options['success_email_body']) < 3) $errors[] = 'Successful donation e-mail body must contain at least 3 characters'; if (strlen($options['failed_email_subject']) < 3) $errors[] = 'Failed donation e-mail subject must contain at least 3 characters'; else if (strlen($options['failed_email_subject']) > 64) $errors[] = 'Failed donation e-mail subject must contain maximum 64 characters'; if (strlen($options['failed_email_body']) < 3) $errors[] = 'Failed donation e-mail body must contain at least 3 characters'; if (strlen($options['stats_email_subject']) < 3) $errors[] = 'Statistics e-mail subject must contain at least 3 characters'; else if (strlen($options['stats_email_subject']) > 64) $errors[] = 'Statistics e-mail subject must contain maximum 64 characters'; if (strlen($options['stats_email_body']) < 3) $errors[] = 'Statistics e-mail body must contain at least 3 characters'; //if (empty($options['signup_page'])) $errors[] = 'Sign up page must be defined.'; if (!is_numeric($options['minimum_days']) || intval($options['minimum_days']) < 5) $errors[] = 'Minimum days number must be 5 or higher'; if (empty($errors)) return true; return $errors; } function get_fingerprint($api_login_id, $transaction_key, $amount, $fp_sequence, $fp_timestamp) { if (function_exists('hash_hmac')) { return hash_hmac("md5", $api_login_id . "^" . $fp_sequence . "^" . $fp_timestamp . "^" . $amount . "^", $transaction_key); } return bin2hex(mhash(MHASH_MD5, $api_login_id . "^" . $fp_sequence . "^" . $fp_timestamp . "^" . $amount . "^", $transaction_key)); } function page_switcher ($_urlbase, $_currentpage, $_totalpages) { $pageswitcher = ""; if ($_totalpages > 1) { $pageswitcher = '
Pages: '; if (strpos($_urlbase,"?") !== false) $_urlbase .= "&"; else $_urlbase .= "?"; if ($_currentpage == 1) $pageswitcher .= "1 "; else $pageswitcher .= " 1 "; $start = max($_currentpage-3, 2); $end = min(max($_currentpage+3,$start+6), $_totalpages-1); $start = max(min($start,$end-6), 2); if ($start > 2) $pageswitcher .= " ... "; for ($i=$start; $i<=$end; $i++) { if ($_currentpage == $i) $pageswitcher .= " ".$i." "; else $pageswitcher .= " ".$i." "; } if ($end < $_totalpages-1) $pageswitcher .= " ... "; if ($_currentpage == $_totalpages) $pageswitcher .= " ".$_totalpages." "; else $pageswitcher .= " ".$_totalpages." "; $pageswitcher .= "
"; } return $pageswitcher; } function random_string($_length = 16) { $symbols = '123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $string = ""; for ($i=0; $i<$_length; $i++) { $string .= $symbols[rand(0, strlen($symbols)-1)]; } return $string; } function period_to_string($period) { $period_str = ""; $days = floor($period/(24*3600)); $period -= $days*24*3600; $hours = floor($period/3600); $period -= $hours*3600; $minutes = floor($period/60); if ($days > 1) $period_str = $days.' days, '; else if ($days == 1) $period_str = $days.' day, '; if ($hours > 1) $period_str .= $hours.' hours, '; else if ($hours == 1) $period_str .= $hours.' hour, '; else if (!empty($period_str)) $period_str .= '0 hours, '; if ($minutes > 1) $period_str .= $minutes.' minutes'; else if ($minutes == 1) $period_str .= $minutes.' minute'; else $period_str .= '0 minutes'; return $period_str; } function cut_string($_string, $_limit=40) { if (strlen($_string) > $_limit) return substr($_string, 0, $_limit-3)."..."; return $_string; } function add_url_parameters($_base, $_params) { if (strpos($_base, "?")) $glue = "&"; else $glue = "?"; $result = $_base; if (is_array($_params)) { foreach ($_params as $key => $value) { $result .= $glue.rawurlencode($key)."=".rawurlencode($value); $glue = "&"; } } return $result; } function send_thanksgiving_email($tags, $vals, $payer_email) { global $options; $body = str_replace($tags, $vals, $options['success_email_body']); if (!empty($payer_email)) { $mail_headers = "Content-Type: text/plain; charset=utf-8\r\n"; $mail_headers .= "From: ".$options['from_name']." <".$options['from_email'].">\r\n"; $mail_headers .= "X-Mailer: PHP/".phpversion()."\r\n"; mail($payer_email, $options['success_email_subject'], $body, $mail_headers); } $body = str_replace($tags, $vals, 'Dear Administrator!'.PHP_EOL.PHP_EOL.'We would like to inform you that {payer_name} ({payer_email}) paid {amount} {currency} for banner "{banner_title}" via {gateway} on {transaction_date}.'.($options['enable_approval'] == 'on' ? PHP_EOL.'Please review banner and approve/reject it.' : '').PHP_EOL.PHP_EOL.'Thanks,'.PHP_EOL.'Ads Manager'); $mail_headers = "Content-Type: text/plain; charset=utf-8\r\n"; $mail_headers .= "From: ".$options['from_name']." <".$options['from_email'].">\r\n"; $mail_headers .= "X-Mailer: PHP/".phpversion()."\r\n"; mail($options['owner_email'], 'Completed payment received', $body, $mail_headers); } function send_failed_email($tags, $vals, $payer_email) { global $options; $body = str_replace($tags, $vals, $options['failed_email_body']); if (!empty($payer_email)) { $mail_headers = "Content-Type: text/plain; charset=utf-8\r\n"; $mail_headers .= "From: ".$options['from_name']." <".$options['from_email'].">\r\n"; $mail_headers .= "X-Mailer: PHP/".phpversion()."\r\n"; mail($payer_email, $options['failed_email_subject'], $body, $mail_headers); } $body = str_replace($tags, $vals, 'Dear Administrator!'.PHP_EOL.PHP_EOL.'We would like to inform you that {payer_name} ({payer_email}) paid {amount} {currency} for banner "{banner_title}" via {gateway} on {transaction_date}. This is non-completed payment.'.PHP_EOL.'Payment status: {payment_status}'.PHP_EOL.PHP_EOL.'Thanks,'.PHP_EOL.'Ads Manager'); $mail_headers = "Content-Type: text/plain; charset=utf-8\r\n"; $mail_headers .= "From: ".$options['from_name']." <".$options['from_email'].">\r\n"; $mail_headers .= "X-Mailer: PHP/".phpversion()."\r\n"; mail($options['owner_email'], 'Non-completed payment received', $body, $mail_headers); } function get_auth_style() { $style = ' '; return str_replace(array("\n", "\r", "\t"), array("", "", ""), $style); } function install() { global $icdb; $table_name = $icdb->prefix."types"; if($icdb->get_var("SHOW TABLES LIKE '".$table_name."'") != $table_name) { $sql = "CREATE TABLE IF NOT EXISTS ".$table_name." ( id int(11) NULL AUTO_INCREMENT, title varchar(255) COLLATE utf8_unicode_ci NULL, width int(11) NULL, height int(11) NULL, slots int(11) NULL, price float NULL, preview_url varchar(255) COLLATE utf8_unicode_ci NULL, status int(11) NULL DEFAULT '".STATUS_ACTIVE."', details text COLLATE utf8_unicode_ci NULL, placeholder_type int(11) NULL DEFAULT '0', placeholder_content longtext COLLATE utf8_unicode_ci NULL, registered int(11) NULL, deleted int(11) NULL DEFAULT '0', UNIQUE KEY id (id) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $icdb->query($sql); } $table_name = $icdb->prefix."banners"; if($icdb->get_var("SHOW TABLES LIKE '".$table_name."'") != $table_name) { $sql = "CREATE TABLE IF NOT EXISTS ".$table_name." ( id int(11) NULL AUTO_INCREMENT, type_id int(11) NULL, title varchar(255) COLLATE utf8_unicode_ci NULL, email varchar(255) COLLATE utf8_unicode_ci NULL, url varchar(255) COLLATE utf8_unicode_ci NULL, file varchar(255) COLLATE utf8_unicode_ci NULL, days_purchased int(11) NULL, amount float NULL, currency varchar(15) COLLATE utf8_unicode_ci NULL, shows_displayed int(11) NULL, clicks int(11) NULL, id_str varchar(63) COLLATE utf8_unicode_ci NULL, status int(11) NULL DEFAULT '".STATUS_DRAFT."', details text COLLATE utf8_unicode_ci NULL, echo text COLLATE utf8_unicode_ci NULL, source int(11) NULL DEFAULT '0', content longtext COLLATE utf8_unicode_ci NULL, registered int(11) NULL, blocked int(11) NULL DEFAULT '0', deleted int(11) NULL DEFAULT '0', UNIQUE KEY id (id) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $icdb->query($sql); } $table_name = $icdb->prefix."transactions"; if($icdb->get_var("SHOW TABLES LIKE '".$table_name."'") != $table_name) { $sql = "CREATE TABLE IF NOT EXISTS ".$table_name." ( id int(11) NULL AUTO_INCREMENT, banner_id int(11) NULL, payer_name varchar(255) COLLATE utf8_unicode_ci NULL, payer_email varchar(255) COLLATE utf8_unicode_ci NULL, gross float NULL, currency varchar(15) COLLATE utf8_unicode_ci NULL, payment_status varchar(63) COLLATE utf8_unicode_ci NULL, transaction_type varchar(63) COLLATE utf8_unicode_ci NULL, txn_id varchar(255) COLLATE utf8_unicode_ci NULL, details text COLLATE utf8_unicode_ci NULL, created int(11) NULL, deleted int(11) NULL DEFAULT '0', UNIQUE KEY id (id) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $icdb->query($sql); } $table_name = $icdb->prefix."log"; if($icdb->get_var("SHOW TABLES LIKE '".$table_name."'") != $table_name) { $sql = "CREATE TABLE IF NOT EXISTS ".$table_name." ( id int(11) NULL auto_increment, banner_id int(11) NULL, type_id int(11) NULL, session_id varchar(255) COLLATE utf8_unicode_ci NULL, created int(11) NULL, UNIQUE KEY id (id) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $icdb->query($sql); } $table_name = $icdb->prefix."options"; if($icdb->get_var("SHOW TABLES LIKE '".$table_name."'") != $table_name) { $sql = "CREATE TABLE IF NOT EXISTS ".$table_name." ( id int(11) NULL AUTO_INCREMENT, options_key varchar(255) COLLATE utf8_unicode_ci NULL, options_value text COLLATE utf8_unicode_ci NULL, UNIQUE KEY id (id) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $icdb->query($sql); } $table_name = $icdb->prefix."sessions"; if($icdb->get_var("SHOW TABLES LIKE '".$table_name."'") != $table_name) { $sql = "CREATE TABLE IF NOT EXISTS ".$table_name." ( id int(11) NULL AUTO_INCREMENT, ip varchar(31) COLLATE utf8_unicode_ci NULL, session_id varchar(255) COLLATE utf8_unicode_ci NULL, registered int(11) NULL, valid_period int(11) NULL, UNIQUE KEY id (id) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; $icdb->query($sql); } if (!file_exists(ABSPATH.'/files')) { mkdir(ABSPATH.'/files'); } if (!file_exists(ABSPATH.'/files/index.html')) { file_put_contents(ABSPATH.'/files/index.html', 'Silence is the gold!'); } if (!file_exists(ABSPATH.'/files/index.html')) { $_SESSION['error'] = 'Important! Please create folder '.ABSPATH.'/files/ and set 0777 permissions.'; } } function handle_version() { global $options, $icdb; if ($options['version'] < 2.60) { $sql = "ALTER TABLE ".$icdb->prefix."banners ADD source INT(11) NULL DEFAULT '0', ADD content LONGTEXT COLLATE utf8_unicode_ci NULL"; $icdb->query($sql); $sql = "ALTER TABLE ".$icdb->prefix."types ADD placeholder_type INT(11) NULL DEFAULT '0', ADD placeholder_content LONGTEXT COLLATE utf8_unicode_ci NULL"; $icdb->query($sql); $options['version'] = 1.0; update_options(); } } ?>