function baw_check_config() { global $BAW_CONF, $BAW_MES; // lets check a non-std file, config.php might exist elsewhere $path = $BAW_CONF['site_path'] . "/modules/render_table.inc.php"; if (!file_exists($path)) { // lets get an error-free error message $BAW_MES[58] = ''; $BAW_MES['e'] = 'UTF-8'; include_once './language/lang_en.inc.php'; $check = substr($_SERVER["SCRIPT_FILENAME"], 0, -10); echo baw_raise_error('site_path', array($BAW_CONF['site_path'], $check)); exit; } /* this does not work if the folder is protected with htaccess since the fopen is not authenticated. $url = $BAW_CONF['site_url']. '/modules/render_table.inc.php'; if (!@fopen($url, "r")) { include_once('./language/lang_en.inc.php'); $check = 'http://' . $_SERVER["SERVER_NAME"] . substr($_SERVER["PHP_SELF"], 0, -10); echo baw_raise_error('site_url', array($BAW_CONF['site_url'], $check)); exit; } $url = $BAW_CONF['icons_url']. '/os/linux.png'; if (!@fopen($url, "r")) { echo baw_raise_error('iconpath', array($BAW_CONF['icons_url'])); exit; } */ }
function baw_render_jpgraph($name, $chart, $format, $type = 'pie', $get_avg = false, $top_x = false, $sort = 0) { global $BAW_CONF, $BAW_MES; $dir = $BAW_CONF['jpgraph_path'] . '/jpgraph.php'; if (!file_exists($dir)) { return baw_raise_error('jpgraph_path', array($dir)); } $jp_data = array(); // $jp_legend = array(); $entries = 0; if (count($chart) == 0) { return ""; } // calc others $f = ''; $d = ''; $others = 0; $other_arr = array(); foreach ($chart as $id => $data) { $count = count($data); if ($entries < $top_x) { foreach ($format as $fid => $fdata) { $d .= "&d[{$fid}][]={$data[$fid]}"; } } else { // 'others' foreach ($format as $fid => $fdata) { if ($fdata['format'] !== 'layout_text' && $fdata['format'] !== 'layout_date') { @($other_arr[$fid] += $data[$fid]); } else { if ($fid == 0) { $other_arr[$fid] = $BAW_MES[2]; } else { $other_arr[$fid] = ''; } } } } $entries++; } foreach ($other_arr as $oid => $odata) { $d .= "&d[{$oid}][{$top_x}]={$odata}"; } foreach ($format as $fid => $fdata) { $f .= "&f[]= {$fdata['title']}"; } // $count = count($jp_data); $img_url = $BAW_CONF['site_url'] . "/modules/render_jpgraph.inc.php?getgraph=true&type={$type}{$d}{$f}"; $out = "<div class=\"aligncenter\"><img width=\"575\" height=\"286\" alt=\"chart: {$name}\" src=\"{$img_url}\"></div>"; return $out; }
/** * * @param $data * Page and hit data for each country * @param $top_x * The number of domains to display. If false, display all. * * @return * A string containing the HTML to include an image of the map. */ function baw_render_map($data, $top_x = false) { global $BAW_CONF; // if we don't have GD2 functions, we can't generate the image baw_debug("rendering map"); if (!function_exists('imagecreatetruecolor')) { echo baw_raise_error('gd2notavailable', array()); return; } $im = $BAW_CONF['site_path'] . '/icons/wmap.png'; if (!file_exists($im)) { echo baw_raise_error('mapnotavailable', array($im)); } // fix data for geography $us_domains = array('us', 'mil', 'edu', 'gov', 'arpa'); foreach ($us_domains as $us_domain) { if (isset($data[$us_domain][3])) { if (!isset($data['us'])) { $data['us'] = array(0, 0, 0, 0, 0); } $data['us'][3] += $data[$us_domain][3]; } if (isset($data[$us_domain][4])) { if (!isset($data['us'])) { $data['us'] = array(0, 0, 0, 0, 0); } $data['us'][4] += $data[$us_domain][4]; } } $new_data = ''; $doms = 0; foreach ($data as $country => $vars) { if ($doms >= $top_x && $top_x !== false) { break; } $new_data .= "&c[{$country}][0]={$vars[3]}&c[{$country}][1]={$vars[4]}"; $doms++; } $img_url = url("admin/reports/bawstats/modules/render_map") . $new_data; $out = "<div class=\"aligncenter\"><img width=\"574\" height=\"286\" alt=\"map of domains\" src=\"{$img_url}\"" . XHTML . "></div>"; baw_debug("rendering map finished"); return $out; }
function baw_get_tooltips() { global $BAW_CONF, $BAW_MES; $path = $BAW_CONF['path_lang'] . "/tooltips_w/awstats-tt-{$BAW_CONF['lang']}.txt"; if (!file_exists($path)) { echo baw_raise_error('languagefile', array($path)); $file_text = array(); } else { $file_text = file_get_contents($path); } $search = array("\n", "\r", "</div>", "<br />"); $replace = array("", "", "", ""); $file_text = str_replace($search, $replace, $file_text); $file_text = explode('<div class="CTooltip" ', $file_text); array_shift($file_text); $pattern = '/id=\\"tt(\\d{1,3})\\">(.*)/'; foreach ($file_text as $line) { preg_match($pattern, $line, $match); $BAW_MES['tooltip'][$match[1]] = "<span>{$match[2]}</span>"; } }
function baw_read_filemap(&$f, $site, $date) { global $BAW_DFILES; // $f = fopen($file, 'r'); $str = ''; $check = 1; // read this file until we hit the offsets while ($check !== 0) { $str = fgets($f, 20000); // check for XML Data if (strstr($str, '<xml') !== false) { // we have XML echo baw_raise_error('xmldata'); exit; } $check = strpos($str, 'BEGIN_MAP'); } $check = explode(' ', $str); $lines_count = $check[1]; // line length of the map baw_debug("found data map for file, has {$lines_count} lines"); // now read x more lines for ($i = 0; $i < $lines_count; $i++) { // read the complete offset map $str = fgets($f, 512); // split the info in string - byte offset $check = explode(' ', $str); $type = substr($check[0], 4); $offset = $check[1]; if ($offset > 1) { baw_debug("data type {$type}, starts at offset {$offset}"); $BAW_DFILES[$site][$date]['map'][$type] = $offset; } else { echo baw_raise_error('datafileindex', $err_data); exit; } } baw_debug("map read"); }