/** * Creates a new site with the specified id. * if new_sid is 'auto', the site id is chosen automatically, otherwise the new_sid is used as the site id. * * @param $new_sid the site id to use, 'auto' to choose automatically. * @param $name site name * @param $type site type as defined in constants.php * @param $baseline_views the initial value for views for this site. (default 0) * @param $baseline_visitors the initial value for visitor for this site. (default 0) * * * @return true on success, or error message on failure. */ function fs_create_new_site($new_sid, $name, $type, $baseline_views = 0, $baseline_visitors = 0) { if (empty($name)) { return fs_r('Site name not specified'); } $fsdb =& fs_get_db_conn(); $sites = fs_sites_table(); if ($new_sid == 'auto') { $newSite = true; $new_sid = fs_register_site(); if ($new_sid === false) { return fs_db_error(); } } else { if (!is_numeric($new_sid) || (int) $new_sid <= 0) { return fs_r('Site ID must be a positive number'); } $exists = fs_site_exists($new_sid); if ($exists === null) { return fs_db_error(); } if ($exists === true) { return sprintf(fs_r("A site with the ID %s already exists"), $new_sid); } } $new_sid = $fsdb->escape($new_sid); $type = $fsdb->escape($type); $name = $fsdb->escape($name); $sql = "REPLACE INTO `{$sites}` (`id`,`type`,`name`) VALUES ({$new_sid},{$type},{$name})"; $r = $fsdb->query($sql); if ($r === false) { return fs_db_error(); } if (!is_numeric($baseline_views)) { $baseline_views = 0; } if (!is_numeric($baseline_visitors)) { $baseline_visitors = 0; } $baseline_views = $fsdb->escape($baseline_views); $baseline_visitors = $fsdb->escape($baseline_visitors); $archive_sites = fs_archive_sites(); $sql = "REPLACE INTO `{$archive_sites}` (`range_id`,`site_id`,`views`,`visits`) VALUES(1,{$new_sid},{$baseline_views},{$baseline_visitors})"; $r = $fsdb->query($sql); if ($r === false) { return fs_db_error(); } 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); }