function fs_delete_site($site_id, $action, $new_sid) { if (empty($site_id)) { return "Uspecified site id"; } $fsdb =& fs_get_db_conn(); $sites = fs_sites_table(); $hits = fs_hits_table(); if ($fsdb->query("START TRANSACTION") === false) { return fs_db_error(); } $exists = fs_site_exists($site_id); if ($exists === null) { return fs_db_error(true); } if ($exists === false) { $fsdb->query("ROLLBACK"); return sprintf(fs_r("No site with the id %s exists"), $site_id); } if ($action == "delete") { $id = $fsdb->escape($site_id); $sql = "DELETE FROM `{$hits}` WHERE site_id = {$id}"; $r = $fsdb->query($sql); if ($r === false) { return fs_db_error(true); } $archives = array(fs_archive_sites(), fs_archive_pages(), fs_archive_referrers(), fs_archive_useragents(), fs_archive_countries()); foreach ($archives as $archive) { $sql = "DELETE FROM `{$archive}` WHERE site_id = {$id}"; $r = $fsdb->query($sql); if ($r === false) { return fs_db_error(true); } } } else { if ($action == "change") { if (empty($new_sid)) { $fsdb->query("ROLLBACK"); return fs_r("New site_id must not be empty"); } if ($site_id == $new_sid) { $fsdb->query("ROLLBACK"); return fs_r("Can't move the hits to the same site"); } $exists = fs_site_exists($new_sid); if ($exists === null) { return fs_db_error(true); } if ($exists === false) { $fsdb->query("ROLLBACK"); return sprintf(fs_r("No site with the id %s exists"), $new_sid); } $r = fs_transfer_site_hits($site_id, $new_sid); if ($r === false) { return fs_db_error(true); } } else { $fsdb->query("ROLLBACK"); return "Unknown action {$action}"; } } $id = $fsdb->escape($site_id); $sql = "DELETE FROM `{$sites}` WHERE `id` = {$id}"; $r = $fsdb->query($sql); if ($r === false) { return fs_db_error(true); } if ($fsdb->query("COMMIT") === false) { return fs_db_error(true); } return true; }
/** * Registers this instance of wordpress with FireStats. * This is requires so that if there is more than one blog/system that works with * the same FireStats instance it will be possible to filter the stats per site. */ function fs_register_wordpress() { $FS_PATH = fs_get_firestats_path(); if (!$FS_PATH) { return; } require_once $FS_PATH . '/php/db-sql.php'; $firestats_site_id = get_option('firestats_site_id'); if ($firestats_site_id == null && !fs_site_exists($firestats_site_id)) { $site_id = null; if (fs_is_wpmu()) { // for wpmu sites, use the blog id as the firestats site id. global $blog_id; $site_id = $blog_id; } $firestats_site_id = fs_register_site($site_id); if (firestats_site_id === false) { echo "FireStats: error registering blog with id = {$site_id}"; return; } update_option('firestats_site_id', $firestats_site_id); } $name = get_option('blogname'); $type = FS_SITE_TYPE_WORDPRESS; $res = fs_update_site_params($firestats_site_id, $firestats_site_id, $name, $type); if ($res !== true) { echo $res; } // update the filter to show us this blog by default after the installation update_option('firestats_sites_filter', $firestats_site_id); }