function phpAds_LoadDbConfig($agencyid = 0) { global $phpAds_config, $phpAds_settings_information; if ((!empty($GLOBALS['phpAds_db_link']) || phpAds_dbConnect()) && isset($phpAds_config['tbl_config'])) { $query = "SELECT *" . " FROM " . $phpAds_config['tbl_config'] . " WHERE agencyid=" . $agencyid; if ($res = phpAds_dbQuery($query)) { if ($row = phpAds_dbFetchArray($res, 0)) { while (list($k, $v) = each($phpAds_settings_information)) { if (!$v['sql'] || !isset($row[$k])) { continue; } switch ($v['type']) { case 'boolean': $row[$k] = $row[$k] == 't'; break; case 'integer': $row[$k] = (int) $row[$k]; break; case 'array': $row[$k] = unserialize($row[$k]); break; case 'float': $row[$k] = (double) $row[$k]; break; } $phpAds_config[$k] = $row[$k]; } reset($phpAds_settings_information); return true; } } } return false; }
$phpAds_config['tbl_adclicks'] = $installvars['tbl_adclicks'] = $table_prefix . 'adclicks'; $phpAds_config['tbl_acls'] = $installvars['tbl_acls'] = $table_prefix . 'acls'; $phpAds_config['tbl_session'] = $installvars['tbl_session'] = $table_prefix . 'session'; $phpAds_config['tbl_zones'] = $installvars['tbl_zones'] = $table_prefix . 'zones'; $phpAds_config['tbl_config'] = $installvars['tbl_config'] = $table_prefix . 'config'; $phpAds_config['tbl_affiliates'] = $installvars['tbl_affiliates'] = $table_prefix . 'affiliates'; $phpAds_config['tbl_images'] = $installvars['tbl_images'] = $table_prefix . 'images'; $phpAds_config['tbl_userlog'] = $installvars['tbl_userlog'] = $table_prefix . 'userlog'; $phpAds_config['tbl_cache'] = $installvars['tbl_cache'] = $table_prefix . 'cache'; $phpAds_config['tbl_targetstats'] = $installvars['tbl_targetstats'] = $table_prefix . 'targetstats'; if (phpAds_checkDatabaseExists()) { $errormessage[1][] = $strTableInUse; } else { if (phpAds_isConfigWritable()) { // Connect if (phpAds_dbConnect()) { if (phpAds_createDatabase($phpAds_config['table_type'])) { // Insert basic settings into database and config file phpAds_SettingsWriteAdd('config_version', $phpAds_version); phpAds_SettingsWriteAdd('instance_id', phpAds_ConfigGenerateId()); phpAds_SettingsWriteAdd('dblocal', $installvars['dblocal']); phpAds_SettingsWriteAdd('dbhost', $installvars['dbhost']); phpAds_SettingsWriteAdd('dbport', $installvars['dbport']); phpAds_SettingsWriteAdd('dbuser', $installvars['dbuser']); phpAds_SettingsWriteAdd('dbpassword', $installvars['dbpassword']); phpAds_SettingsWriteAdd('dbname', $installvars['dbname']); phpAds_SettingsWriteAdd('table_prefix', $installvars['table_prefix']); phpAds_SettingsWriteAdd('table_type', $installvars['table_type']); phpAds_SettingsWriteAdd('mysql4_compatibility', $installvars['mysql4_compatibility']); phpAds_SettingsWriteAdd('tbl_clients', $installvars['tbl_clients']); phpAds_SettingsWriteAdd('tbl_banners', $installvars['tbl_banners']);
require phpAds_path . "/libraries/lib-view-tracker.inc.php"; /*********************************************************/ /* Register input variables */ /*********************************************************/ phpAds_registerGlobal('block', 'capping', 'session_capping', 'trackerid'); /*********************************************************/ /* Main code */ /*********************************************************/ // Determine the user ID $userid = phpAds_getUniqueUserID(false); $conversionsid = NULL; // Send the user ID // phpAds_setCookie("phpAds_id", $userid, time()+365*24*60*60); if (!phpAds_isConversionBlocked($trackerid)) { if ($phpAds_config['log_adconversions']) { phpAds_dbConnect(); $conversionid = phpAds_logConversion($userid, $trackerid); } // Handles variable retrieval from the page echo phpAds_buildJavascriptVariablesScript($trackerid, $conversionid); // Send block cookies phpAds_updateConversionBlockTime($trackerid); } phpAds_updateGeotracking($phpAds_geo); phpAds_flushCookie(); /* header ("Content-Type: image/gif"); header ("Content-Length: 43"); // 1 x 1 gif echo chr(0x47).chr(0x49).chr(0x46).chr(0x38).chr(0x39).chr(0x61).chr(0x01).chr(0x00).
header('Location: upgrade.php'); exit; } elseif (!phpAds_installed) { // Post configmanager, but not installed -> install header('Location: install.php'); exit; } // Include required files include "../libraries/lib-io.inc.php"; include "../libraries/lib-db.inc.php"; include "../libraries/lib-dbconfig.inc.php"; include "lib-gui.inc.php"; include "lib-permissions.inc.php"; include "../libraries/lib-userlog.inc.php"; // Open the database connection $link = phpAds_dbConnect(); if (!$link) { // This text isn't translated, because if it is shown the language files are not yet loaded phpAds_Die("A fatal error occurred", $phpAds_productname . " can't connect to the database.\n\t\t\t\tBecause of this it isn't possible to use the administrator interface. The delivery\n\t\t\t\tof banners might also be affected. Possible reasons for the problem are:\n\t\t\t\t<ul><li>The database server isn't functioning at the moment</li>\n\t\t\t\t<li>The location of the database server has changed</li>\n\t\t\t\t<li>The username or password used to contact the database server are not correct</li>\n\t\t\t\t</ul>"); } // Load settings from the database phpAds_LoadDbConfig(); if (!isset($phpAds_config['config_version']) || $phpAds_version > $phpAds_config['config_version']) { // Post configmanager, but not up to date -> update header("Location: upgrade.php"); exit; } // Check for SLL requirements if ($phpAds_config['ui_forcessl'] && $_SERVER['SERVER_PORT'] != 443) { header('Location: https://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF']); exit;
} // Add starting ":" to host if not present if (isset($dblocal) && !ereg('^:', $dbhost)) { $dbhost = ':' . $dbhost; } if (isset($dbhost) && isset($dbuser) && isset($dbpassword) && isset($dbname)) { phpAds_dbClose(); unset($phpAds_db_link); $phpAds_config['dblocal'] = isset($dblocal); $phpAds_config['dbhost'] = $dbhost; $phpAds_config['dbport'] = isset($dbport) && $dbport ? $dbport : 3306; $phpAds_config['dbuser'] = $dbuser; $phpAds_config['dbpassword'] = isset($dbpassword) ? $dbpassword : ''; $phpAds_config['dbname'] = $dbname; $phpAds_config['persistent_connections'] = isset($persistent_connections) ? true : false; if (!phpAds_dbConnect(true)) { $errormessage[0][] = $strCantConnectToDb; } else { phpAds_SettingsWriteAdd('dblocal', $phpAds_config['dblocal']); phpAds_SettingsWriteAdd('dbhost', $phpAds_config['dbhost']); phpAds_SettingsWriteAdd('dbport', $phpAds_config['dbport']); phpAds_SettingsWriteAdd('dbuser', $phpAds_config['dbuser']); phpAds_SettingsWriteAdd('dbname', $phpAds_config['dbname']); phpAds_SettingsWriteAdd('dbpassword', $phpAds_config['dbpassword']); phpAds_SettingsWriteAdd('persistent_connections', isset($persistent_connections)); } } phpAds_SettingsWriteAdd('insert_delayed', isset($insert_delayed)); phpAds_SettingsWriteAdd('compatibility_mode', isset($compatibility_mode)); phpAds_SettingsWriteAdd('mysql4_compatibility', isset($mysql4_compatibility)); if (!count($errormessage)) {
function phpAds_dbQuery($query) { global $phpAds_last_query; global $phpAds_db_link; // Connect to the database, if needed if (!$phpAds_db_link && !phpAds_dbConnect()) { return false; } $phpAds_last_query = $query; return @mysql_query($query, $phpAds_db_link); }
/* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; either version 2 of the License. */ /************************************************************************/ // Figure out our location define('phpAds_path', '.'); /*********************************************************/ /* Include required files */ /*********************************************************/ require phpAds_path . "/config.inc.php"; require_once phpAds_path . "/libraries/lib-io.inc.php"; require phpAds_path . "/libraries/lib-db.inc.php"; global $phpAds_config; /*********************************************************/ /* Register input variables */ /*********************************************************/ $variables = array(); foreach ($HTTP_GET_VARS as $key => $value) { $variables[$key] = $value; } if (sizeof($variables) > 2 && isset($variables['trackerid']) && isset($variables['conversionid'])) { $conversionid = $variables['conversionid']; $trackerid = $variables['trackerid']; unset($variables['conversionid']); unset($variables['trackerid']); phpAds_dbConnect() or die("didnt connect"); foreach ($variables as $variableid => $value) { $value = $value != 'undefined' ? "'" . $value . "'" : 'NULL'; $query = "INSERT " . ($phpAds_config['insert_delayed'] ? 'DELAYED' : '') . " INTO " . $phpAds_config['tbl_variablevalues'] . "\n\t\t\t\t(variableid,\n\t\t\t\t value,\n\t\t\t\t conversionsid)\n\t\t\tVALUES\n\t\t\t\t(" . $variableid . ",\n\t\t\t\t" . $value . ",\n\t\t\t\t'" . $conversionid . "')"; phpAds_dbQuery($query); } }
function view_raw($what, $clientid = 0, $campaignid = 0, $target = '', $source = '', $withtext = 0, $context = 0, $richmedia = true) { global $phpAds_config, $HTTP_SERVER_VARS; global $phpAds_followedChain; $userid = phpAds_getUniqueUserID(); phpAds_setCookie("phpAds_id", $userid, time() + 365 * 24 * 60 * 60); $outputbuffer = ''; // If $clientid consists of alpha-numeric chars it is // not the clientid, but the target parameter. if (!preg_match('#^[0-9]+$#', $clientid)) { $target = $clientid; $clientid = 0; } // Not sure what this does, but replicated to campaignid... // If $campaignid consists of alpha-numeric chars it is // not the campaignid, but the target parameter. if (!preg_match('#^[0-9]+$#', $campaignid)) { $target = $campaignid; $campaignid = 0; } $found = false; // Open database connection and get a banner if (phpAds_dbConnect()) { // Reset followed zone chain $phpAds_followedChain = array(); $first = true; while (($first || $what != '') && $found == false) { $first = false; if (substr($what, 0, 5) == 'zone:') { if (!defined('LIBVIEWZONE_INCLUDED')) { require phpAds_path . '/libraries/lib-view-zone.inc.php'; } $row = phpAds_fetchBannerZone($what, $clientid, $campaignid, $context, $source, $richmedia); } else { if (!defined('LIBVIEWQUERY_INCLUDED')) { require phpAds_path . '/libraries/lib-view-query.inc.php'; } if (!defined('LIBVIEWDIRECT_INCLUDED')) { require phpAds_path . '/libraries/lib-view-direct.inc.php'; } $row = phpAds_fetchBannerDirect($what, $clientid, $campaignid, $context, $source, $richmedia); } if (is_array($row)) { $found = true; } else { $what = $row; } } } if ($found) { $outputbuffer = ''; // Prepend if (isset($row['prepend'])) { $outputbuffer .= $row['prepend']; } // Get HTML cache $outputbuffer .= $row['htmlcache']; // Append if (isset($row['append'])) { $outputbuffer .= $row['append']; } // Determine target if ($row['target'] == '') { if ($target == '') { $target = '_blank'; } // default } else { $target = $row['target']; } // Determine source $source = urlencode($source); // Set basic variables $outputbuffer = str_replace('{bannerid}', $row['bannerid'], $outputbuffer); $outputbuffer = str_replace('{zoneid}', $row['zoneid'], $outputbuffer); $outputbuffer = str_replace('{target}', $target, $outputbuffer); $outputbuffer = str_replace('{source}', $source, $outputbuffer); // Set path of phpAdsNew if ($HTTP_SERVER_VARS['SERVER_PORT'] == 443) { $phpAds_config['url_prefix'] = $phpAds_config['ssl_url_prefix']; } if (isset($HTTP_SERVER_VARS['HTTP_HOST'])) { $phpAds_config['url_prefix'] = preg_replace('#//[^/]+/#', '//' . $HTTP_SERVER_VARS['HTTP_HOST'] . '/', $phpAds_config['url_prefix']); } $outputbuffer = str_replace('{url_prefix}', $phpAds_config['url_prefix'], $outputbuffer); // Add text below banner if ($withtext) { $outputbuffer = str_replace('[bannertext]', '', $outputbuffer); $outputbuffer = str_replace('[/bannertext]', '', $outputbuffer); } else { $outputbuffer = preg_replace("#\\[bannertext\\](.*)\\[\\/bannertext\\]#", '', $outputbuffer); } // Web banner.. if ($row['storagetype'] == 'web') { if ($HTTP_SERVER_VARS['SERVER_PORT'] == 443) { $phpAds_config['type_web_url'] = $phpAds_config['type_web_ssl_url']; } $outputbuffer = str_replace('{image_url_prefix}', $phpAds_config['type_web_url'], $outputbuffer); } // HTML/URL banner options if ($row['storagetype'] == 'html' || $row['storagetype'] == 'url' || $row['storagetype'] == 'network') { // Replace timestamp $outputbuffer = str_replace('{timestamp}', time(), $outputbuffer); $outputbuffer = str_replace('%7Btimestamp%7D', time(), $outputbuffer); // Replace random while (preg_match('#(%7B|\\{)random((%3A|:)([0-9]+)){0,1}(%7D|})#i', $outputbuffer, $matches)) { if ($matches[4]) { $randomdigits = $matches[4]; } else { $randomdigits = 8; } if (isset($lastdigits) && $lastdigits == $randomdigits) { $randomnumber = $lastrandom; } else { $randomnumber = ''; for ($r = 0; $r < $randomdigits; $r = $r + 9) { $randomnumber .= (string) mt_rand(111111111, 999999999); } $randomnumber = substr($randomnumber, 0 - $randomdigits); } $outputbuffer = str_replace($matches[0], $randomnumber, $outputbuffer); $lastdigits = $randomdigits; $lastrandom = $randomnumber; } } // Parse PHP code inside HTML banners if ($row['storagetype'] == 'html') { if ($phpAds_config['type_html_php']) { if (preg_match("#(\\<\\?php(.*)\\?\\>)#i", $outputbuffer, $parser_regs)) { // Extract PHP script $parser_php = $parser_regs[2]; $parser_result = ''; // Replace output function $parser_php = preg_replace("#echo([^;]*);#i", '$parser_result .=\\1;', $parser_php); $parser_php = preg_replace("#print([^;]*);#i", '$parser_result .=\\1;', $parser_php); $parser_php = preg_replace("#printf([^;]*);#i", '$parser_result .= sprintf\\1;', $parser_php); // Split the PHP script into lines $parser_lines = explode(";", $parser_php); for ($parser_i = 0; $parser_i < sizeof($parser_lines); $parser_i++) { if (trim($parser_lines[$parser_i]) != '') { eval(trim($parser_lines[$parser_i]) . ';'); } } // Replace the script with the result $outputbuffer = str_replace($parser_regs[1], $parser_result, $outputbuffer); } } } // Add beacon image for logging if (isset($HTTP_SERVER_VARS['HTTP_USER_AGENT']) && preg_match("#Mozilla/(1|2|3|4)#", $HTTP_SERVER_VARS['HTTP_USER_AGENT']) && !preg_match("#compatible#", $HTTP_SERVER_VARS['HTTP_USER_AGENT'])) { $outputbuffer .= '<layer id="beacon_' . $row['bannerid'] . '" width="0" height="0" border="0" visibility="hide">'; $outputbuffer .= '<img src=\'' . $phpAds_config['url_prefix'] . '/adlog.php?bannerid=' . $row['bannerid'] . '&clientid=' . $row['clientid'] . '&campaignid=' . $row['campaignid'] . '&zoneid=' . $row['zoneid'] . '&source=' . $source . '&block=' . $row['block'] . '&capping=' . $row['capping'] . '&session_capping=' . $row['session_capping'] . '&cb=' . md5(uniqid('', 1)) . '\' width=\'0\' height=\'0\' alt=\'\'>'; $outputbuffer .= '</layer>'; } else { //$outputbuffer .= '<div id="beacon_'.$row['bannerid'].'" style="width: 0px; height: 0px; overflow: hidden;">'; $outputbuffer .= '<img src=\'' . $phpAds_config['url_prefix'] . '/adlog.php?bannerid=' . $row['bannerid'] . '&clientid=' . $row['clientid'] . '&campaignid=' . $row['campaignid'] . '&zoneid=' . $row['zoneid'] . '&source=' . $source . '&block=' . $row['block'] . '&capping=' . $row['capping'] . '&session_capping=' . $row['session_capping'] . '&cb=' . md5(uniqid('', 1)) . '\' width=\'0\' height=\'0\' alt=\'\' style=\'width: 0px; height: 0px;\'>'; //$outputbuffer .= '</div>'; } // Prepare impression logging if ($phpAds_config['log_adviews'] && !$phpAds_config['log_beacon']) { phpAds_logImpression($userid, $row['bannerid'], $row['zoneid'], $source); } // Return banner return array('html' => $outputbuffer, 'bannerid' => $row['bannerid'], 'alt' => $row['alt'], 'width' => $row['width'], 'height' => $row['height'], 'url' => $row['url'], 'clientid' => $row['clientid'], 'campaignid' => $row['campaignid']); } else { // An error occured, or there are no banners to display at all // Use the default banner if defined if ($phpAds_config['default_banner_target'] != '' && $phpAds_config['default_banner_url'] != '') { // Determine target if ($target == '') { $target = '_blank'; } // default // Show default banner $outputbuffer = '<a href=\'' . $phpAds_config['default_banner_target'] . '\' target=\'' . $target . '\'><img src=\'' . $phpAds_config['default_banner_url'] . '\' border=\'0\' alt=\'\'></a>'; // Return banner return array('html' => $outputbuffer, 'bannerid' => ''); } } }