function fs_lazy_get_latest_version_info($url, $type, $default_check_interval, &$error, $force_check = false) { $fsdb = fs_get_db_conn(); if (!$fsdb->is_connected()) { return null; } $version_check_enabled = fs_get_system_option($type . "_version_check_enabled", 'true'); if ($version_check_enabled != 'false' || $force_check) { $last_version_check_time = (int) fs_get_system_option($type . '_last_version_check_time'); $version_check_interval = (int) fs_get_system_option($type . '_version_check_interval', $default_check_interval); $now = time(); $d = $last_version_check_time + $version_check_interval; if ($now > $d || $force_check) { // in case of an a freeze due to server networking problem, we don't want subsequent calls to check again. // for this reason, I deactivate the version check for the specifed type before testing, and reactivate it after // if the script hangs, the user will probably reload and this time it will work because the check // will never be re-activated. fs_update_system_option($type . "_version_check_enabled", 'false'); // time to check $err = ''; $info = fs_get_latest_version_info($url, $err); if ($err != '') { $error = sprintf(fs_r('Error getting version information from %s : %s'), $url, $err); return null; } fs_update_system_option($type . '_last_version_check_time', $now); // the fetch was successful, we can re-activate the version check fs_update_system_option($type . "_version_check_enabled", 'true'); // if data is null we have a networking problem. just pretend everything is fine // so the server will not continue trying till enough time passed if ($info != null) { fs_update_system_option($type . '_last_version_info_on_server', serialize($info)); } return $info; } else { // use cached result from last check $info = fs_get_system_option($type . '_last_version_info_on_server'); if ($info) { return unserialize($info); } else { // if for some reason we have n data in the cache, try again, this time with force_check = true. return fs_lazy_get_latest_version_info($url, $type, $error, $default_check_interval, true); } } } else { return null; // user does not want version check. assume we are good. } }
/** * store some usage FireStats usage information */ function fs_maintain_usage_stats() { if (fs_is_admin()) { $first_run_time = fs_get_system_option('first_run_time'); if (!$first_run_time) { fs_update_system_option('first_run_time', time()); } $firestats_id = fs_get_system_option('firestats_id'); if (!$firestats_id) { fs_update_system_option('firestats_id', mt_rand()); } } $first_login = fs_get_option('first_login'); if (!$first_login) { fs_update_option('first_login', time()); } }
function fs_add_pending_maintanence_job($id) { $jobs = fs_get_system_option('pending_maintanence', ''); if ($jobs == '') { $jobs = $id; } else { $jobs .= ",{$id}"; } // remove duplicate jobs $jobs = implode(',', array_unique(explode(',', $jobs))); fs_update_system_option('pending_maintanence', $jobs); }
function fs_ajax_handle_pending_maintanence(&$response) { $str = fs_get_system_option('pending_maintanence', ''); if ($str != '') { $jobs = explode(',', $str); if (count($jobs) > 0) { $job = array_pop($jobs); $response['execute'] = "FS.executeProcess('{$job}')"; fs_update_system_option('pending_maintanence', implode(',', $jobs)); } } }