function key($key, $group) { if (empty($group)) { $group = 'default'; } if (false !== array_search($group, $this->global_groups)) { $prefix = ''; } else { $prefix = backpress_get_option('application_id') . ':'; } return preg_replace('/\\s+/', '', $prefix . $group . ':' . $key); }
/** * Checks for invalid UTF8 in a string. * * @since 2.8 * * @param string $string The text which is to be checked. * @param boolean $strip Optional. Whether to attempt to strip out invalid UTF8. Default is false. * @return string The checked text. */ function wp_check_invalid_utf8($string, $strip = false) { $string = (string) $string; if (0 === strlen($string)) { return ''; } // Store the site charset as a static to avoid multiple calls to backpress_get_option() static $is_utf8; if (!isset($is_utf8)) { $is_utf8 = in_array(backpress_get_option('charset'), array('utf8', 'utf-8', 'UTF8', 'UTF-8')); } if (!$is_utf8) { return $string; } // Check for support for utf8 in the installed PCRE library once and store the result in a static static $utf8_pcre; if (!isset($utf8_pcre)) { $utf8_pcre = @preg_match('/^./u', 'a'); } // We can't demand utf8 in the PCRE installation, so just return the string in those cases if (!$utf8_pcre) { return $string; } // preg_match fails when it encounters invalid UTF8 in $string if (1 === @preg_match('/^./us', $string)) { return $string; } // Attempt to strip the bad chars if requested (not recommended) if ($strip && function_exists('iconv')) { return iconv('utf-8', 'utf-8', $string); } return ''; }
/** * Generate authentication cookie contents * * @since 2.5 * @uses apply_filters() Calls 'auth_cookie' hook on $cookie contents, User ID * and expiration of cookie. * * @param int $user_id User ID * @param int $expiration Cookie expiration in seconds * @return string Authentication cookie contents */ function generate_auth_cookie($user_id, $expiration, $scheme = 'auth') { $user = $this->users->get_user($user_id); if (!$user || is_wp_error($user)) { return $user; } $pass_frag = ''; if (1 < WP_AUTH_COOKIE_VERSION) { $pass_frag = substr($user->user_pass, 8, 4); } $key = call_user_func(backpress_get_option('hash_function_name'), $user->user_login . $pass_frag . '|' . $expiration, $scheme); $hash = hash_hmac('md5', $user->user_login . '|' . $expiration, $key); $cookie = $user->user_login . '|' . $expiration . '|' . $hash; return apply_filters('auth_cookie', $cookie, $user_id, $expiration, $scheme); }
/** * Retrieve cron info array option. * * @since 2.1.0 * @access private * * @return array CRON info array. */ function _get_cron_array() { $cron = backpress_get_option('cron'); if (!is_array($cron)) { return false; } if (!isset($cron['version'])) { $cron = _upgrade_cron_array($cron); } unset($cron['version']); return $cron; }
/** * Set the uninstallation hook for a plugin. * * Registers the uninstall hook that will be called when the user clicks on the * uninstall link that calls for the plugin to uninstall itself. The link won't * be active unless the plugin hooks into the action. * * The plugin should not run arbitrary code outside of functions, when * registering the uninstall hook. In order to run using the hook, the plugin * will have to be included, which means that any code laying outside of a * function will be run during the uninstall process. The plugin should not * hinder the uninstall process. * * If the plugin can not be written without running code within the plugin, then * the plugin should create a file named 'uninstall.php' in the base plugin * folder. This file will be called, if it exists, during the uninstall process * bypassing the uninstall hook. The plugin, when using the 'uninstall.php' * should always check for the 'WP_UNINSTALL_PLUGIN' constant, before * executing. * * @since 2.7 * * @param string $file * @param callback $callback The callback to run when the hook is called. */ function register_uninstall_hook($file, $callback) { // The option should not be autoloaded, because it is not needed in most // cases. Emphasis should be put on using the 'uninstall.php' way of // uninstalling the plugin. $uninstallable_plugins = (array) backpress_get_option('uninstall_plugins'); $uninstallable_plugins[plugin_basename($file)] = $callback; backpress_update_option('uninstall_plugins', $uninstallable_plugins); }
/** * Gives a nicely formatted list of timezone strings // temporary! Not in final * * @param $selected_zone string Selected Zone * */ function wp_timezone_choice($selected_zone) { static $mo_loaded = false; $continents = array('Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific', 'Etc'); // Load translations for continents and cities if (!$mo_loaded) { $locale = backpress_get_option('language_locale'); $mofile = backpress_get_option('language_directory') . 'continents-cities-' . $locale . '.mo'; load_textdomain('continents-cities', $mofile); $mo_loaded = true; } $zonen = array(); foreach (timezone_identifiers_list() as $zone) { $zone = explode('/', $zone); if (!in_array($zone[0], $continents)) { continue; } if ('Etc' === $zone[0] && in_array($zone[1], array('UCT', 'GMT', 'GMT0', 'GMT+0', 'GMT-0', 'Greenwich', 'Universal', 'Zulu'))) { continue; } // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later $exists = array(0 => isset($zone[0]) && $zone[0] ? true : false, 1 => isset($zone[1]) && $zone[1] ? true : false, 2 => isset($zone[2]) && $zone[2] ? true : false); $exists[3] = $exists[0] && 'Etc' !== $zone[0] ? true : false; $exists[4] = $exists[1] && $exists[3] ? true : false; $exists[5] = $exists[2] && $exists[3] ? true : false; $zonen[] = array('continent' => $exists[0] ? $zone[0] : '', 'city' => $exists[1] ? $zone[1] : '', 'subcity' => $exists[2] ? $zone[2] : '', 't_continent' => $exists[3] ? translate(str_replace('_', ' ', $zone[0]), 'continents-cities') : '', 't_city' => $exists[4] ? translate(str_replace('_', ' ', $zone[1]), 'continents-cities') : '', 't_subcity' => $exists[5] ? translate(str_replace('_', ' ', $zone[2]), 'continents-cities') : ''); } usort($zonen, '_wp_timezone_choice_usort_callback'); $structure = array(); if (empty($selected_zone)) { $structure[] = '<option selected="selected" value="">' . __('Select a city') . '</option>'; } foreach ($zonen as $key => $zone) { // Build value in an array to join later $value = array($zone['continent']); if (empty($zone['city'])) { // It's at the continent level (generally won't happen) $display = $zone['t_continent']; } else { // It's inside a continent group // Continent optgroup if (!isset($zonen[$key - 1]) || $zonen[$key - 1]['continent'] !== $zone['continent']) { $label = 'Etc' === $zone['continent'] ? __('Manual offsets') : $zone['t_continent']; $structure[] = '<optgroup label="' . esc_attr($label) . '">'; } // Add the city to the value $value[] = $zone['city']; if ('Etc' === $zone['continent']) { if ('UTC' === $zone['city']) { $display = ''; } else { $display = str_replace('GMT', '', $zone['city']); $display = strtr($display, '+-', '-+') . ':00'; } $display = sprintf(__('UTC %s'), $display); } else { $display = $zone['t_city']; if (!empty($zone['subcity'])) { // Add the subcity to the value $value[] = $zone['subcity']; $display .= ' - ' . $zone['t_subcity']; } } } // Build the value $value = join('/', $value); $selected = ''; if ($value === $selected_zone) { $selected = 'selected="selected" '; } $structure[] = '<option ' . $selected . 'value="' . esc_attr($value) . '">' . esc_html($display) . "</option>"; // Close continent optgroup if (!empty($zone['city']) && (!isset($zonen[$key + 1]) || isset($zonen[$key + 1]) && $zonen[$key + 1]['continent'] !== $zone['continent'])) { $structure[] = '</optgroup>'; } } return join("\n", $structure); }
function _mb_substr($str, $start, $length = null, $encoding = null) { // the solution below, works only for utf-8, so in case of a different // charset, just use built-in substr $charset = backpress_get_option('charset'); if (!in_array($charset, array('utf8', 'utf-8', 'UTF8', 'UTF-8'))) { return is_null($length) ? substr($str, $start) : substr($str, $start, $length); } // use the regex unicode support to separate the UTF-8 characters into an array preg_match_all('/./us', $str, $match); $chars = is_null($length) ? array_slice($match[0], $start) : array_slice($match[0], $start, $length); return implode('', $chars); }
/** * Whether URL should be sent through the proxy server. * * We want to keep localhost and the blog URL from being sent through the proxy server, because * some proxies can not handle this. We also have the constant available for defining other * hosts that won't be sent through the proxy. * * @uses WP_PROXY_BYPASS_HOSTS * @since unknown * * @param string $uri URI to check. * @return bool True, to send through the proxy and false if, the proxy should not be used. */ function send_through_proxy($uri) { // parse_url() only handles http, https type URLs, and will emit E_WARNING on failure. // This will be displayed on blogs, which is not reasonable. $check = @parse_url($uri); // Malformed URL, can not process, but this could mean ssl, so let through anyway. if ($check === false) { return true; } $home = parse_url(backpress_get_option('application_uri')); if ($check['host'] == 'localhost' || $check['host'] == $home['host']) { return false; } if (!defined('WP_PROXY_BYPASS_HOSTS')) { return true; } static $bypass_hosts; if (null == $bypass_hosts) { $bypass_hosts = preg_split('|,\\s*|', WP_PROXY_BYPASS_HOSTS); } return !in_array($check['host'], $bypass_hosts); }
* * The HTTP request to this file will not slow down the visitor who happens to * visit when the cron job is needed to run. * * @package bbPress */ ignore_user_abort(true); /** * Tell bbPress we are doing the CRON task. * * @var bool */ define('DOING_CRON', true); /** Setup bbPress environment */ require_once './bb-load.php'; if ($_GET['check'] != backpress_get_option('cron_check')) { exit; } if (bb_get_option('doing_cron') > time()) { exit; } bb_update_option('doing_cron', time() + 30); $crons = _get_cron_array(); $keys = array_keys($crons); if (!is_array($crons) || $keys[0] > time()) { return; } foreach ($crons as $timestamp => $cronhooks) { if ($timestamp > time()) { break; }
function nospamuser_check_bozo($user_id) { // Most of this function is taken from Akismet $settings = bb_get_option('nospamuser-settings'); if (empty($settings['api_key'])) { return; } global $bb_current_user, $user_obj; $bb_current_id = bb_get_current_user_info('id'); bb_set_current_user($user_id); if ($bb_current_id && $bb_current_id != $user_id) { if ($user_obj->data->is_bozo || !$bb_current_user->data->is_bozo) { return; } } bb_set_current_user((int) $bb_current_id); $wp_http = new WP_Http(); $wp_http->post('http://www.stopforumspam.com/post.php', array('body' => array('username' => $user_obj->user_login, 'ip_addr' => $user_obj->data->nospamuser_ip, 'email' => $user_obj->user_email, 'api_key' => $settings['api_key']), 'user-agent' => apply_filters('http_headers_useragent', backpress_get_option('wp_http_version')) . NOSPAMUSER_AGENT)); }