/** * Converts a number of special characters into their HTML entities. * * Specifically deals with: &, <, >, ", and '. * * $quote_style can be set to ENT_COMPAT to encode " to * ", or ENT_QUOTES to do both. Default is ENT_NOQUOTES where no quotes are encoded. * * @since 0.0.1 * @access private * * @staticvar string $_charset * * @param string $string The text which is to be encoded. * @param int $quote_style Optional. Converts double quotes if set to ENT_COMPAT, both single and double if set to ENT_QUOTES or none if set to ENT_NOQUOTES. Also compatible with old values; converting single quotes if set to 'single', double if set to 'double' or both if otherwise set. Default is ENT_NOQUOTES. * @param string $charset Optional. The character encoding of the string. Default is false. * @param bool $double_encode Optional. Whether to encode existing html entities. Default is false. * @return string The encoded text with HTML entities. */ function _hq_specialchars($string, $quote_style = ENT_NOQUOTES, $charset = false, $double_encode = false) { $string = (string) $string; if (0 === strlen($string)) { return ''; } // Don't bother if there are no specialchars - saves some processing if (!preg_match('/[&<>"\']/', $string)) { return $string; } // Account for the previous behaviour of the function when the $quote_style is not an accepted value if (empty($quote_style)) { $quote_style = ENT_NOQUOTES; } elseif (!in_array($quote_style, array(0, 2, 3, 'single', 'double'), true)) { $quote_style = ENT_QUOTES; } // Store the site charset as a static to avoid multiple calls to hq_load_alloptions() if (!$charset) { static $_charset = null; if (!isset($_charset)) { $alloptions = hq_load_alloptions(); $_charset = isset($alloptions['blog_charset']) ? $alloptions['blog_charset'] : ''; } $charset = $_charset; } if (in_array($charset, array('utf8', 'utf-8', 'UTF8'))) { $charset = 'UTF-8'; } $_quote_style = $quote_style; if ($quote_style === 'double') { $quote_style = ENT_COMPAT; $_quote_style = ENT_COMPAT; } elseif ($quote_style === 'single') { $quote_style = ENT_NOQUOTES; } if (!$double_encode) { // Guarantee every &entity; is valid, convert &garbage; into &garbage; // This is required for PHP < 5.4.0 because ENT_HTML401 flag is unavailable. $string = hq_kses_normalize_entities($string); } $string = @htmlspecialchars($string, $quote_style, $charset, $double_encode); // Backwards compatibility if ('single' === $_quote_style) { $string = str_replace("'", ''', $string); } return $string; }
/** * Test whether HiveQueen is already installed. * * The cache will be checked first. If you have a cache plugin, which saves * the cache values, then this will work. If you use the default HiveQueen * cache, and the database goes away, then you might have problems. * * Checks for the 'siteurl' option for whether HiveQueen is installed. * * @since 0.0.1 * * @global hqdb $hqdb HiveQueen database abstraction object. * * @return bool Whether the blog is already installed. */ function is_hq_installed() { global $hqdb; /* * Check cache first. If options table goes away and we have true * cached, oh well. */ //TODO: no cache // if ( hq_cache_get( 'is_hq_installed' ) ) // return true; $suppress = $hqdb->suppress_errors(); if (!defined('HQ_INSTALLING')) { $alloptions = hq_load_alloptions(); } // If siteurl is not set to autoload, check it specifically if (!isset($alloptions['siteurl'])) { $installed = $hqdb->get_var("SELECT option_value FROM {$hqdb->options} WHERE option_name = 'siteurl'"); } else { $installed = $alloptions['siteurl']; } $hqdb->suppress_errors($suppress); $installed = !empty($installed); //TODO: no cache //hq_cache_set( 'is_hq_installed', $installed ); if ($installed) { return true; } // If visiting repair.php, return true and let it take over. if (defined('HQ_REPAIRING')) { return true; } $suppress = $hqdb->suppress_errors(); /* * Loop over the HQ tables. If none exist, then scratch install is allowed. * If one or more exist, suggest table repair since we got here because the * options table could not be accessed. */ $hq_tables = $hqdb->tables(); foreach ($hq_tables as $table) { // The existence of custom user tables shouldn't suggest an insane state or prevent a clean install. if (defined('CUSTOM_USER_TABLE') && CUSTOM_USER_TABLE == $table) { continue; } if (defined('CUSTOM_USER_META_TABLE') && CUSTOM_USER_META_TABLE == $table) { continue; } if (!$hqdb->get_results("DESCRIBE {$table};")) { continue; } // One or more tables exist. We are insane. hq_load_translations_early(); // Die with a DB error. $hqdb->error = sprintf(__('One or more database tables are unavailable. The database may need to be <a href="%s">repaired</a>.'), 'maint/repair.php?referrer=is_hq_installed'); dead_db(); } $hqdb->suppress_errors($suppress); // TODO: no chache //hq_cache_set( 'is_hq_installed', false ); return false; }
/** * Get the value of a transient. * * If the transient does not exist, does not have a value, or has expired, * then the return value will be false. * * @since 0.0.1 * * @param string $transient Transient name. Expected to not be SQL-escaped. * @return mixed Value of transient. */ function get_transient($transient) { /** * Filter the value of an existing transient. * * The dynamic portion of the hook name, `$transient`, refers to the transient name. * * Passing a truthy value to the filter will effectively short-circuit retrieval * of the transient, returning the passed value instead. * * @since 0.0.1 * * @param mixed $pre_transient The default value to return if the transient does not exist. * Any value other than false will short-circuit the retrieval * of the transient, and return the returned value. */ $pre = apply_filters('pre_transient_' . $transient, false); if (false !== $pre) { return $pre; } if (hq_using_ext_object_cache()) { $value = hq_cache_get($transient, 'transient'); } else { $transient_option = '_transient_' . $transient; if (!defined('HQ_INSTALLING')) { // If option is not in alloptions, it is not autoloaded and thus has a timeout $alloptions = hq_load_alloptions(); if (!isset($alloptions[$transient_option])) { $transient_timeout = '_transient_timeout_' . $transient; $timeout = get_option($transient_timeout); if (false !== $timeout && $timeout < time()) { delete_option($transient_option); delete_option($transient_timeout); $value = false; } } } if (!isset($value)) { $value = get_option($transient_option); } } /** * Filter an existing transient's value. * * The dynamic portion of the hook name, `$transient`, refers to the transient name. * * @since 0.0.1 * * @param mixed $value Value of transient. */ return apply_filters('transient_' . $transient, $value); }