function fs_get_excluded_users_list() { $users = fs_wp_get_users(); if ($users === false) { return fs_db_error(); } $excluded_users = explode(",", fs_get_local_option('firestats_excluded_users', '')); $c = count($users); $res = ''; if ($c == 0) { $res .= fs_r('Empty'); } else { foreach ($users as $u) { $user_id = $u['id']; $user_name = $u['name']; $in = in_array($u['id'], $excluded_users); $checked = $in ? "checked='checked'" : ""; $res .= "<input type='checkbox' onclick='updateExcludedUsers(this,{$user_id})' id='wordpress_user_{$user_id}' {$checked}/><label for='wordpress_user_{$user_id}'>{$user_name}</label><br/>"; } } return $res; }
function fs_get_site_id_query($site_id, $site_table_name = null) { $sql = ""; if (is_numeric($site_id)) { $sql = "`site_id` = '{$site_id}'"; } else { if ($site_id) { $site = fs_get_local_option('firestats_sites_filter', 'all'); if ($site != 'all') { if ($site_table_name == null) { $sql = "`site_id` = '{$site}'"; } else { $sql = "{$site_table_name}.`site_id` = '{$site}'"; } } } } return $sql != "" ? $sql : "'1'"; }
fs_e('Advanced'); ?> </h3> <?php fs_e('WordPress site ID, every hit From this blog is recorded with this as the source Site ID'); ?> <br /> <?php fs_e("This should be the same ID as the Site ID in the sites table. you don't normally need to change this."); ?> <br /> <input type="text" onkeypress="return trapEnter(event,'saveWpSiteID();');" id="wp_site_id" style="width:120px" value="<?php echo fs_get_local_option('firestats_site_id', ''); ?> " /> <button class="button" onclick="saveWpSiteID()"><?php fs_e('Save'); ?> </button> </td> </tr> <tr> <td class="config_cell" colspan="2"> <?php fs_e("This will update the titles of the blog posts inside FireStats, you don't normally need to use it"); ?> <button class="button" onclick="sendRequest('action=update_wordpress_titles')"><?php fs_e('Update');
function fs_authenticate_wp_user() { // use wordpress users only when installed in hosted mode if (fs_full_installation()) { global $current_user; $path = fs_get_firestats_path(); require_once $path . '/php/auth.php'; $user = new stdClass(); $user->name = $current_user->user_login; $user->id = $current_user->id; if (fs_is_wpmu()) { if (is_site_admin()) { $user->security_level = SEC_ADMIN; } else { $user->security_level = current_user_can('publish_posts') ? SEC_USER : SEC_NONE; } } else { if (current_user_can('manage_options')) { $user->security_level = SEC_ADMIN; } else { if (current_user_can('moderate_comments')) { $user_level = 4; } else { if (current_user_can('publish_posts')) { $user_level = 3; } else { if (current_user_can('edit_posts')) { $user_level = 2; } else { if (current_user_can('read')) { $user_level = 1; } else { $user_level = 0; // a bumhug } } } } $required = (int) fs_get_local_option('firestats_min_view_security_level', 3); echo "required : {$required}, actual {$user_level}"; $user->security_level = $required <= $user_level ? SEC_USER : SEC_NONE; } } fs_start_user_session($user); } else { fs_resume_user_session(); if (!fs_authenticated()) { fs_start_user_session(null); // dummy session that can only be used to login. } } }
function fs_ajax_delete_site(&$response) { if (!fs_ajax_assert_admin($response)) { return; } $sid = $_POST['site_id']; $action = $_POST['action_code']; $new_sid = isset($_POST['new_sid']) ? $_POST['new_sid'] : null; $res = fs_delete_site($sid, $action, $new_sid); if ($res === true) { // if the deleted site was selected in the filter, update the filter $current_selected = fs_get_local_option('firestats_sites_filter'); if ($current_selected == $sid) { // reset filter to 'all'. fs_update_local_option('firestats_sites_filter', 'all'); fs_ajax_get_all_stats($response); } // and also send whatever the client requested. fs_ajax_send_update($response); } else { ajax_error($response, $res); } }
function fs_add_hit_immediate__($user_id, $site_id, $time = null) { if (!fs_db_valid()) { return fs_get_database_status_message(); } $fsdb =& fs_get_db_conn(); $d = fs_get_hit_data($fsdb, $user_id, $site_id); $user_id = $d->user_id; $site_id = $d->site_id; $remoteaddr = $d->remoteaddr; $useragent = $d->useragent; $url = $d->url; $referer = $d->referer; if ($time === null) { $time = "NOW()"; } else { $time = $fsdb->escape($time); } $useragents = fs_useragents_table(); $urls = fs_urls_table(); $excluded_ips = fs_excluded_ips_table(); if ($fsdb->query("START TRANSACTION") === false) { return fs_debug_rollback(); } // insert to user agent table (no duplicates) $ret = $fsdb->query("INSERT IGNORE INTO `{$useragents}` (`useragent`,`md5`) VALUES ({$useragent} ,MD5(`useragent`))"); if ($ret === false) { return fs_debug_rollback(); } // if we actually inserted a new useragent, we need to match it against existing filters. if ($ret > 0) { $bots = fs_bots_table(); $ret = $fsdb->get_row("SELECT ua.id id,count(wildcard) c\n\t\t\t\tFROM {$bots} RIGHT JOIN {$useragents} ua \n\t\t\t\tON useragent REGEXP wildcard \n\t\t\t\tWHERE useragent = {$useragent}\n\t\t\t\tGROUP BY useragent"); if ($ret === false) { return fs_debug_rollback(); } $ret = $fsdb->query("UPDATE {$useragents} SET match_bots='{$ret->c}' WHERE id='{$ret->id}'"); if ($ret === false) { return fs_debug_rollback(); } } $save_excluded = fs_get_save_excluded_records() === 'true'; $c = $fsdb->get_var("SELECT COUNT(ip) FROM `{$excluded_ips}` WHERE `ip` = " . $remoteaddr); if ($c === false) { return fs_debug_rollback(); } $c = (int) $c; $excluded_ip = $c > 0 ? 1 : 0; $excluded_users = fs_get_local_option('firestats_excluded_users'); if ($excluded_users === false) { return fs_debug_rollback(); } $excluded_user = $user_id && $excluded_users && in_array($user_id, explode(",", $excluded_users)) ? 1 : 0; // get index of useragent in table, can't use LAST_INSERT_ID() here because of the no-dups policy $ua_info = $fsdb->get_row("SELECT id,match_bots from `{$useragents}` WHERE `useragent` = {$useragent}"); $excluded_useragent = $ua_info->match_bots > 0; // check if we want to save this if (!$save_excluded && ($excluded_useragent || $excluded_user || $excluded_ip)) { return true; } $useragent_id = $ua_info->id; if ($useragent_id === false) { return fs_debug_rollback(); } // insert to urls table (no duplicates) $url = $url ? "{$url}" : "''"; if ($fsdb->query("INSERT IGNORE INTO `{$urls}` (`url`,`md5`,`add_time`,`host`) \n\t\t\t\t\t VALUES ({$url},MD5(url),{$time},substring_index(substring_index(`url`,'/',3),'/',-1))") === false) { return fs_debug_rollback(); } // get index of url in table, can't use LAST_INSERT_ID() here because of the no-dups policy $url_id = $fsdb->get_var("SELECT id from " . fs_urls_table() . " WHERE `url` = {$url}"); if ($url_id === false) { return fs_debug_rollback(); } if ($url_id == null) { return fs_debug_rollback(); } // update site id of url to current site id. // this is only done for the url and not for the referrer: // we don't know the site id of the referrer. if it will appear as a url it will be assigned the site_id. if (false === $fsdb->get_var("UPDATE `{$urls}` SET `site_id` = {$site_id} WHERE `id` = {$url_id}")) { return fs_debug_rollback(); } // insert referers into urls table (no duplicates) $referer = $referer ? "{$referer}" : "''"; require_once FS_ABS_PATH . '/php/searchengines.php'; $search_engine_id = "NULL"; $search_terms = "NULL"; $referrer_breakdown = null; if (isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER'])) { $search_params = fs_get_search_terms_and_engine($_SERVER['HTTP_REFERER'], $referrer_breakdown); if ($search_params) { $id = $search_params->engine_id; $terms = $search_params->search_terms; if (!empty($id)) { $search_engine_id = $fsdb->escape($id); } if (!empty($terms)) { $search_terms = $fsdb->escape($terms); } } } $has_scheme = isset($referrer_breakdown['scheme']); $optional_host = $has_scheme ? ",`host`" : ""; $optional_host_query = $has_scheme ? ",substring_index(substring_index(`url`,'/',3),'/',-1)" : ""; if ($fsdb->query("INSERT IGNORE INTO `{$urls}`(`url`,`md5`,`add_time`,`search_engine_id`,`search_terms` {$optional_host}) VALUES ({$referer},MD5(url),{$time},{$search_engine_id} ,{$search_terms} {$optional_host_query})") === false) { return fs_debug_rollback(); } // get index of url in table, can't use LAST_INSERT_ID() here because of the no-dups policy $referer_id = $fsdb->get_var("SELECT id from {$urls} WHERE `url` = {$referer}"); if ($referer_id === false) { return fs_debug_rollback(); } if ($referer_id == null) { echo "FireStats : Error getting referrer id "; return fs_debug_rollback(); } require_once dirname(__FILE__) . '/ip2country.php'; $ip2c_res = fs_ip2c($d->ip_address, true); $ccode = $ip2c_res ? $fsdb->escape($ip2c_res) : "NULL"; // insert to database. $sql = "INSERT IGNORE INTO " . fs_hits_table() . "\n\t\t\t(site_id,ip,timestamp,url_id,referer_id,useragent_id,session_id,excluded_ip,excluded_user,user_id,country_code) \n\t\t\t\t\tVALUES ({$site_id},\n\t\t\t\t\t\t\t{$remoteaddr},\n\t\t\t\t\t\t\t{$time},\n\t\t\t\t\t\t\t{$url_id},\n\t\t\t\t\t\t\t{$referer_id},\n\t\t\t\t\t\t\t{$useragent_id},\n\t\t\t\t\t\t\t" . (isset($session_id) ? "{$session_id}" : "NULL") . ",\n\t\t\t\t\t\t\t{$excluded_ip},\n\t\t\t\t\t\t\t{$excluded_user},\n\t\t\t\t\t\t\t" . ($user_id ? "{$user_id}" : "NULL") . ",\n\t\t\t\t\t\t\t{$ccode}\n\t\t\t\t\t\t\t)"; if ($fsdb->query($sql) === false) { return fs_debug_rollback(); } if ($fsdb->query("COMMIT") === false) { return fs_debug_rollback(); } return true; }