diff --git a/inc/class.page.php b/inc/class.page.php --- a/inc/class.page.php +++ b/inc/class.page.php @@ -823,6 +823,25 @@ class page /** * \brief + * Return an array of name=value pairs that are urlencoded. + * + * Supports query_string() and query_formbutton(). + */ + private static function _uriencode_query_array(array $query) + { + $query_string_parts = array(); + foreach ($query as $param => $values) + { + if (!is_array($values)) + $values = array($values); + foreach ($values as $value) + $query_string_parts[] = rawurlencode($param) . '=' . rawurlencode($value); + } + return $query_string_parts; + } + + /** + * \brief * Form a query string from a map. * * \param $query @@ -836,17 +855,136 @@ class page */ public static function query_string(array $query, $question = TRUE) { - $query_string_parts = array(); - foreach ($query as $param => $values) + $query_string_parts = self::_uriencode_query_array($query); + if (count($query_string_parts)) + return ($question ? '?' : '') . implode('&', $query_string_parts); + return ''; + } + + /** + * \brief + * Return an HTML form button which submits all keys, as many of + * them with GET as possible. + * + * Allows one to automatically delegate fatter values to be POSTed + * to prevent the querystring from getting too long and making the + * URI itself become too long. Always returns a
with a + * ' . $button_post_html . PHP_EOL + . '
'; } /** @@ -958,4 +1096,16 @@ class page return ' /'; return ''; } + + /** + * \brief + * Encode things using htmlentities() with proper precautions. + */ + public static function entities($text) + { + $opts = ENT_QUOTES; + if (defined('ENT_XML1')) + $opts |= ENT_XML1; + return htmlentities($text, $opts, 'utf-8'); + } }