summaryrefslogtreecommitdiffstats
path: root/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Utils.php
diff options
context:
space:
mode:
Diffstat (limited to 'core/vendor/easyrdf/easyrdf/lib/EasyRdf/Utils.php')
-rw-r--r--core/vendor/easyrdf/easyrdf/lib/EasyRdf/Utils.php51
1 files changed, 33 insertions, 18 deletions
diff --git a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Utils.php b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Utils.php
index a48686b..1c2d7dd 100644
--- a/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Utils.php
+++ b/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Utils.php
@@ -5,7 +5,7 @@
*
* LICENSE
*
- * Copyright (c) 2009-2012 Nicholas J Humfrey. All rights reserved.
+ * Copyright (c) 2009-2013 Nicholas J Humfrey. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -31,9 +31,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*
* @package EasyRdf
- * @copyright Copyright (c) 2009-2012 Nicholas J Humfrey
+ * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey
* @license http://www.opensource.org/licenses/bsd-license.php
- * @version $Id$
*/
@@ -41,7 +40,7 @@
* Class containing static utility functions
*
* @package EasyRdf
- * @copyright Copyright (c) 2009-2010 Nicholas J Humfrey
+ * @copyright Copyright (c) 2009-2013 Nicholas J Humfrey
* @license http://www.opensource.org/licenses/bsd-license.php
*/
class EasyRdf_Utils
@@ -112,13 +111,19 @@ class EasyRdf_Utils
* EasyRdf_Graph and EasyRdf_Sparql_Result to format a resource
* for display.
*
- * @param mixed $resource An EasyRdf_Resource object or an associative array
- * @param bool $html Set to true to format the dump using HTML
- * @param string $color The colour of the text
+ * @param mixed $resource An EasyRdf_Resource object or an associative array
+ * @param string $format Either 'html' or 'text'
+ * @param string $color The colour of the text
* @return string
*/
- public static function dumpResourceValue($resource, $html = true, $color = 'blue')
+ public static function dumpResourceValue($resource, $format = 'html', $color = 'blue')
{
+ if (!preg_match('/^#?[-\w]+$/', $color)) {
+ throw new InvalidArgumentException(
+ "\$color must be a legal color code or name"
+ );
+ }
+
if (is_object($resource)) {
$resource = strval($resource);
} elseif (is_array($resource)) {
@@ -126,8 +131,8 @@ class EasyRdf_Utils
}
$short = EasyRdf_Namespace::shorten($resource);
- if ($html) {
- $escaped = htmlentities($resource);
+ if ($format == 'html') {
+ $escaped = htmlentities($resource, ENT_QUOTES);
if (substr($resource, 0, 2) == '_:') {
$href = '#' . $escaped;
} else {
@@ -153,15 +158,21 @@ class EasyRdf_Utils
* EasyRdf_Graph and EasyRdf_Sparql_Result to format a literal
* for display.
*
- * @param mixed $literal An EasyRdf_Literal object or an associative array
- * @param bool $html Set to true to format the dump using HTML
- * @param string $color The colour of the text
+ * @param mixed $literal An EasyRdf_Literal object or an associative array
+ * @param string $format Either 'html' or 'text'
+ * @param string $color The colour of the text
* @return string
*/
- public static function dumpLiteralValue($literal, $html = true, $color = 'black')
+ public static function dumpLiteralValue($literal, $format = 'html', $color = 'black')
{
+ if (!preg_match('/^#?[-\w]+$/', $color)) {
+ throw new InvalidArgumentException(
+ "\$color must be a legal color code or name"
+ );
+ }
+
if (is_object($literal)) {
- $literal = $literal->toArray();
+ $literal = $literal->toRdfPhp();
} elseif (!is_array($literal)) {
$literal = array('value' => $literal);
}
@@ -171,11 +182,15 @@ class EasyRdf_Utils
$text .= '@' . $literal['lang'];
}
if (isset($literal['datatype'])) {
- $datatype = EasyRdf_Namespace::shorten($literal['datatype']);
- $text .= "^^$datatype";
+ $short = EasyRdf_Namespace::shorten($literal['datatype']);
+ if ($short) {
+ $text .= "^^$short";
+ } else {
+ $text .= "^^<".$literal['datatype'].">";
+ }
}
- if ($html) {
+ if ($format == 'html') {
return "<span style='color:$color'>".
htmlentities($text, ENT_COMPAT, "UTF-8").
"</span>";