function search($needle, $haystack, $sort_flag = null, $compare_function = null) { $len = strlen($needle); if (!$len) { return false; } if (!is_array($haystack)) { return false; } if (is_null($compare_function)) { $compare_function = 'strncmp'; } if ($sort_flag) { sort($haystack); } fbDebug::dump($haystack, '$haystack'); $high = count($haystack) - 1; if ($high < 0) { return false; } $mid = 0; $low = 0; fbDebug::log(sprintf("%3d: low=%5s high=%5s mid=%5s arr[mid]=%5s\n", __LINE__, $low, $high, $mid, $haystack[$mid])); while ($high >= $low) { $mid = $high + $low >> 1; $t = @$compare_function($needle, $haystack[$mid], $len); if ($t < 0) { $high = $mid - 1; } elseif ($t > 0) { $low = $mid + 1; } else { fbDebug::log(sprintf("%3d: low=%5s high=%5s mid=%5s arr[mid]=%5s\n", __LINE__, $low, $high, $mid, $haystack[$mid])); return $mid; } fbDebug::log(sprintf("%3d: low=%5s high=%5s mid=%5s arr[mid]=%5s\n", __LINE__, $low, $high, $mid, $haystack[$mid])); } fbDebug::log(sprintf("%3d: low=%5s high=%5s mid=%5s arr[mid]=%5s\n", __LINE__, $low, $high, $mid, $haystack[$mid])); return $mid; }
function getCountryIdByIP($ip) { static $cache = array(); $ipf = fbGeoIP_Free_Ascii::_formatIP4address($ip); if (!$ipf) { return false; } /* if (isset($cache[$ipf])) { return $cache[$ipf]; } */ // \todo make a parameter $file = FREEBEER_BASE . '/etc/geo/geo-ips.txt'; if (!is_file($file)) { trigger_error(sprintf("File not found: '%s'", $file)); return false; } $bsf =& new fbBinarySearch_File($file); $bsf->setReadLength(64); // 36 for unix, 37 for ms-dos/windows $found = $bsf->search($ipf); $midval = $bsf->getRecordNumber(); $rec_len = $bsf->getRecordLength(); if ($found === false) { return false; } fbDebug::log(sprintf("ip=%s found=%s midval=%s rec_len=%s\n\n", $ip, $found, $midval, $rec_len)); $matches = preg_split('/\\s+/', $found); if (count($matches) < 3) { trigger_error(sprintf('Read error reading \'%s\': File does not contain whitespace', $file)); return false; } if ($ipf < $matches[0] || $ipf > $matches[1]) { trigger_error(sprintf('Unexpected result: \'%s\' (\'%s\') is not between \'%s\' and \'%s\'', $ip, $ipf, $matches[0], $matches[1]), E_USER_NOTICE); return false; } // $cache[$ipf] = trim($matches[2]); return trim($matches[2]); }
function getCountryIdByIP($ip) { static $cache = array(); $ipf = fbGeoIP_Free_Binary::_formatIP4address($ip); if (!$ipf) { return false; } /* if (isset($cache[$ipf])) { return $cache[$ipf]; } */ // \todo make a parameter $file = FREEBEER_BASE . '/etc/geo/geo-ips-binary.txt'; if (!is_file($file)) { trigger_error(sprintf("File not found: '%s'", $file)); return false; } $bsf =& new fbBinarySearch_File($file); $bsf->setRecordLength(10); $found = $bsf->search($ipf); $midval = $bsf->getRecordNumber(); $rec_len = $bsf->getRecordLength(); if ($found === false) { return false; } fbDebug::log(sprintf("ip=%s found=%s midval=%s rec_len=%s\n\n", $ip, $found, $midval, $rec_len)); $a = unpack('C*', $found); $cc = sprintf('%c%c', $a[9], $a[10]); $ips = sprintf('%d.%d.%d.%d', $a[1], $a[2], $a[3], $a[4]); $ipe = sprintf('%d.%d.%d.%d', $a[5], $a[6], $a[7], $a[8]); if ($ipf < substr($found, 0, 4) || $ipf > substr($found, 4, 4)) { trigger_error(sprintf('Unexpected result: \'%s\' is not between \'%s\' and \'%s\'', $ip, $ips, $ipe), E_USER_NOTICE); return false; } // $cache[$ipf] = $cc; return $cc; }
function sqldump($sql, $fields = false) { if (!fbDebug::debugging()) { return ''; } $s = ADODB_debug::_sqldump($sql, $fields); fbDebug::_log($s); return $s; }
function assertHandler($file, $line, $code) { if ((fbDebug::getLevel() & FB_DEBUG_NO_ASSERTS) == FB_DEBUG_NO_ASSERTS) { return; } fbDebug::log(fbDebug::pre(sprintf("%-30s: Assertion Failed: '%s'\t(%s)\n", basename($file) . '(' . $line . ')', $code, $file))); fbDebug::stackdump(2); }
function fb_adodb_outp($msg, $newline) { if (!(fbDebug::getLevel() & FB_DEBUG_ADODB)) { global $_SERVER; // < 4.1.0 if ($newline) { $msg .= "<br>\n"; } if (isset($_SERVER['HTTP_USER_AGENT'])) { echo $msg; } else { echo strip_tags($msg); } flush(); return; } // \todo make fbDebug browser aware if (isset($_SERVER['HTTP_USER_AGENT'])) { // if (function_exists('html_entity_decode')) { // } $msg = wordwrap($msg, 132); fbDebug::log("\n<pre>\n" . $msg . "\n</pre>\n"); } else { if ($newline) { $msg .= "\n"; } fbDebug::log(strip_tags($msg)); } }
<?php // $CVSHeader: _freebeer/www/demo/Debug.php,v 1.2 2004/03/07 17:51:33 ross Exp $ // Copyright (c) 2002-2004, Ross Smith. All rights reserved. // Licensed under the BSD or LGPL License. See license.txt for details. require_once './_demo.php'; require_once FREEBEER_BASE . '/lib/Debug.php'; fbDebug::setLevel(FB_DEBUG_ALL); echo html_header_demo('fbDebug demo'); echo "<pre>\n"; echo 'fbDebug::getLevel()=', fbDebug::getLevel(), "\n"; fbDebug::log('log'); assert('1 == 2'); print_r(debug_backtrace()); fbDebug::stackdump(); fbDebug::trace("Hey you!"); ?> </pre> <address> $CVSHeader: _freebeer/www/demo/Debug.php,v 1.2 2004/03/07 17:51:33 ross Exp $ </address> </body> </html>
function numberFormat($number, $digits = null, $locale = null) { fbDebug::enter(); static $localeconv_cache = array(); $get_locale = is_null($locale); fbDebug::dump($get_locale, '$get_locale'); if ($get_locale) { $locale = fbLocale::getLocale(LC_MONETARY); fbDebug::dump($locale, '$locale'); } fbDebug::dump($localeconv_cache, '$localeconv_cache'); if (!isset($localeconv_cache[$locale])) { fbDebug::dump($locale, '$locale'); if (!$get_locale) { $rv = fbLocale::pushLocale(LC_MONETARY, $locale); fbDebug::dump($rv, '$rv'); } $_locale = fbLocale::getLocale(LC_MONETARY); fbDebug::dump($_locale, '$_locale'); $localeconv_cache[$locale] = localeconv(); fbDebug::dump($localeconv_cache[$locale], '$localeconv_cache[$locale]'); if (!$get_locale) { fbLocale::popLocale(LC_MONETARY); } } $lc = $localeconv_cache[$locale]; fbDebug::dump($lc, '$lc'); if (is_null($digits)) { $digits = $lc['int_frac_digits']; } $rv = number_format($number, $digits, $lc['mon_decimal_point'], $lc['mon_thousands_sep']); $n = strpos($rv, '-'); if ($n !== false) { $rv = str_replace('-', $lc['negative_sign'], $rv); } fbDebug::leave($rv); return $rv; }
function gettext($message) { fbDebug::enter(); static $current_locale = null; $locale = fbLocale::getLocale(); if ($locale != $current_locale) { fbGettext::_loadData(); $current_locale = $locale; } $translation_map =& fbGettext::_translation_map(); fbDebug::dump($translation_map, 'translation_map'); if (isset($translation_map[$message])) { return $translation_map[$message]; } return $message; }
function &Execute($sql, $inputarr = false, $arg3 = false) { $this->_start(); $rs =& parent::Execute($sql, $inputarr, $arg3); if (!$rs) { // \todo use adodb-error.inc.php values instead // key violations should not be fatal errors if ($this->ErrorNo() == 1062) { return $rs; } $this->_error("Execute", $sql, $inputarr); } $affected_rows = $this->Affected_Rows(); $this->_end(); $this->_dumpSql("Execute", $sql, $inputarr); $this->_explain($sql, $inputarr, $arg3); $this->_elapsed(); ADODB_debug::rsdumpNoSql($rs); if ($rs && fbDebug::_level() & FB_DEBUG_SQL) { if (preg_match('/^\\s*insert\\s+|^\\s*delete\\s+|^\\s*update\\s+/i', $sql)) { fbDebug::dump($affected_rows, 'Affected_Rows'); } } // fbDebug::log(fbDebug::hr()); return $rs; }
<?php // $CVSHeader: _freebeer/www/demo/Payment_PayflowPro.php,v 1.2 2004/03/07 17:51:33 ross Exp $ // Copyright (c) 2002-2004, Ross Smith. All rights reserved. // Licensed under the BSD or LGPL License. See license.txt for details. require_once './_demo.php'; require_once FREEBEER_BASE . '/lib/Debug.php'; //require_once FREEBEER_BASE . '/lib/Random.php'; require_once FREEBEER_BASE . '/lib/Payment/PayflowPro.php'; fbDebug::setLevel(FB_DEBUG_TEXT); echo html_header_demo('fbPayment_PayflowPro Class'); echo "<pre>"; $fields = array('login' => 'rosssmith2', 'partner' => 'VeriSign', 'password' => 'rosssmith22', 'CVV2' => '223', 'city' => 'SANTA MONICA', 'description' => 'Product Description', 'invoice_number' => '12345', 'company' => 'N/A', 'country' => 'US', 'email' => '*****@*****.**', 'expiration' => '1205', 'first_name' => 'Ross', 'last_name' => 'Smith', 'state' => 'CA', 'address' => '832 EUCLID ST 107', 'zip' => '90403-1735'); $p =& new fbPayment_PayflowPro(); $p->setTestMode(true); $p->setFields($fields); $p->setTestCardType(FB_PAYMENT_CREDIT_CARD_TYPE_VISA); $p->setTestResponseType(FB_PAYMENT_RESPONSE_TYPE_APPROVED); $p->setTestTransactionType(FB_PAYMENT_TRANSACTION_TYPE_SALE); $p->submit(); $p->printResults();