function fs_load_config() { $db_config_type = fs_get_db_config_type(); if ($db_config_type == FS_DB_CONFIG_FILE) { // note: // this is not require_once on purpose! // we need this to be included even if it was included before. require dirname(__FILE__) . '/fs-config.php'; } else { if ($db_config_type == FS_DB_CONFIG_WORDPRESS) { require_once fs_get_wp_config_path(); $fs_config['DB_NAME'] = DB_NAME; if (!fs_is_wpmu()) { global $table_prefix; $db_prefix = isset($table_prefix) ? $table_prefix : ''; } else { global $wpmuBaseTablePrefix; $db_prefix = isset($wpmuBaseTablePrefix) ? $wpmuBaseTablePrefix : ''; } $fs_config['DB_PREFIX'] = $db_prefix; $fs_config['DB_USER'] = DB_USER; $fs_config['DB_PASS'] = DB_PASSWORD; $fs_config['DB_HOST'] = DB_HOST; $GLOBALS['fs_config'] = $fs_config; } else { // load default values $fs_config['DB_NAME'] = 'firestats'; $fs_config['DB_PREFIX'] = ''; $fs_config['DB_USER'] = ''; $fs_config['DB_PASS'] = ''; $fs_config['DB_HOST'] = 'localhost'; $GLOBALS['fs_config'] = $fs_config; } } }
function fs_options_page() { if (fs_is_wpmu()) { if (isset($_POST['action']) && $_POST['action'] == 'update') { update_site_option('firestats_path', $_POST['firestats_path']); update_site_option('firestats_url', $_POST['firestats_url']); } $path = get_site_option('firestats_path'); $url = get_site_option('firestats_url'); } else { if (isset($_POST['action']) && $_POST['action'] == 'update') { update_option('firestats_path', $_POST['firestats_path']); update_option('firestats_url', $_POST['firestats_url']); } $path = get_option('firestats_path'); $url = get_option('firestats_url'); } ?> <div class="fwrap"> <h2><?php _e('FireStats configuration'); ?> </h2> <?php if (fs_is_wpmu()) { _e("This page is only available to WPMU Administrators"); } ?> <form method="post"> <input type="hidden" name="action" value="update" /> <?php $path_good = false; $url_good = false; $path_version = ''; $url_version = ''; if (ini_get('safe_mode') == 1) { ?> <div class="error"><?php _e("Your PHP is configured in safe mode, FireStats may be impossible to configure in satellite mode."); ?> </div> <?php } if (!empty($path)) { $len = strlen($path); if ($path[$len - 1] != '/' && $path[$len - 1] != '\\') { $path .= '/'; } if (file_exists($path . 'firestats.info')) { ?> <div class="updated fade"> <?php echo sprintf(__("FireStats detected at %s"), "<b>{$path}</b>") . '<br/>'; $path_good = true; $info = file($path . 'firestats.info'); $path_version = $info[0]; ?> </div> <?php } else { ?> <div class="error"><?php echo sprintf(__("FireStats was not found at %s"), "<b>{$path}</b>"); ?> </div> <?php } } else { echo '<div class="error">' . __("Enter the directory that contains FireStats") . '</div>'; } if (!empty($url)) { ob_start(); $file = file($url . '/firestats.info'); $output = ob_clean(); if ($file !== false) { ?> <div class="updated fade"> <?php echo sprintf(__("FireStats detected at %s"), "<b>{$url}</b>") . '<br/>'; $url_good = true; $url_version = $file[0]; ?> </div> <?php } else { ?> <div class="error"><?php echo sprintf(__("FireStats was not found at %s"), "<b>{$url}</b>"); ?> </div> <?php } } else { echo '<div class="error">' . __("Enter FireStats url") . '</div>'; } if ($path_good && $url_good) { $plugin_ver = "FireStats/" . FS_WORDPRESS_PLUGIN_VER; if (trim($plugin_ver) != trim($path_version)) { ?> <div class="error"><?php echo sprintf(__("Version mismatch between firestats-wordpress.php (%s) and FireStats at path (%s)"), $plugin_ver, $path_version); ?> </div> <?php } else { if (trim($url_version) == trim($path_version)) { fs_register_wordpress(); fs_update_post_titles(); echo '<div class="updated fade">' . sprintf(__('Everything is okay, click %s to open %s'), '<b>' . fs_get_firestats_url('here') . '</b>', "{$path_version}") . '</div>'; } else { ?> <div class="error"><?php echo sprintf(__("Version mismatch between FireStats at url (%s) and FireStats at path (%s)"), $url_version, $path_version); ?> </div> <?php } } } ?> <table> <tr> <td><?php _e('FireStats path : '); ?> </td> <td><input type="text" class="code" id="firestats_path" name="firestats_path" size="60" value="<?php echo $path; ?> "/> <?php echo __('Example:') . "<b>" . $_SERVER["DOCUMENT_ROOT"] . "firestats/</b>"; ?> </td> </tr> <td><?php _e('FireStats URL : '); ?> </td> <td><input type="text" class="code" id="firestats_url" name="firestats_url" size="60" value="<?php echo $url; ?> "/> <?php _e('Example: <b>http://your_site.com/firestats</b>'); ?> </td> </tr> </table> <p class="submit"> <input type="submit" name="Submit" value="<?php _e('Update options'); ?> »" /> </p> </form> </div> <?php }
function fs_update_local_option($key, $value) { // only administrators may change local options. // local options are site wide, but on the level of the site that implements // the fs_update_local_option_impl function. if (fs_in_wordpress() && fs_is_wpmu()) { // even non admin user is allowed to save those options in a wpmu blog. $allowed = array('firestats_show_footer', 'firestats_show_footer_stats', 'firestats_add_comment_flag', 'firestats_add_comment_browser_os'); } else { $allowed = array(); } if (!fs_is_admin() && !in_array($key, $allowed)) { echo "Access denied : fs_update_local_option, not admin"; return; } $fs_local_options_list = fs_get_local_options_list(); if (!in_array($key, $fs_local_options_list)) { echo "fs_update_local_option: {$key} is not an authorized local option<br/>"; return; } if (function_exists('fs_update_local_option_impl')) { fs_update_local_option_impl($key, $value); } else { fs_update_option($key, $value); } }