You are here

public static function EasyRdf_Utils::dumpResourceValue in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/easyrdf/easyrdf/lib/EasyRdf/Utils.php \EasyRdf_Utils::dumpResourceValue()

Return pretty-print view of a resource URI

This method is mainly intended for internal use and is used by EasyRdf_Graph and EasyRdf_Sparql_Result to format a resource for display.

Parameters

mixed $resource An EasyRdf_Resource object or an associative array:

string $format Either 'html' or 'text':

string $color The colour of the text:

Return value

string

2 calls to EasyRdf_Utils::dumpResourceValue()
EasyRdf_Graph::dumpResource in vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php
Return a human readable view of a resource and its properties
EasyRdf_Resource::dumpValue in vendor/easyrdf/easyrdf/lib/EasyRdf/Resource.php
Return pretty-print view of the resource

File

vendor/easyrdf/easyrdf/lib/EasyRdf/Utils.php, line 119

Class

EasyRdf_Utils
Class containing static utility functions

Code

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)) {
    $resource = $resource['value'];
  }
  $short = EasyRdf_Namespace::shorten($resource);
  if ($format == 'html') {
    $escaped = htmlentities($resource, ENT_QUOTES);
    if (substr($resource, 0, 2) == '_:') {
      $href = '#' . $escaped;
    }
    else {
      $href = $escaped;
    }
    if ($short) {
      return "<a href='{$href}' style='text-decoration:none;color:{$color}'>{$short}</a>";
    }
    else {
      return "<a href='{$href}' style='text-decoration:none;color:{$color}'>{$escaped}</a>";
    }
  }
  else {
    if ($short) {
      return $short;
    }
    else {
      return $resource;
    }
  }
}