Id());
if ($Mapping == "Title" && strlen($Resource->GetMapped("Url")))
{
DisplayUrlField($Resource, $Field, $Data);
}
else
{
DisplayResourceField($Resource, $Field, $Data);
}
}
/**
* Display a Paragraph field.
* @param $Resource Resource object
* @param $Field MetadataField object
*/
function DisplayParagraphField(Resource $Resource, MetadataField $Field)
{
$Data = GetResourceFieldValue($Resource, $Field);
$Data = nl2br(StripXSSThreats($Data));
DisplayResourceField($Resource, $Field, $Data, array("IsTall" => TRUE));
}
/**
* Display a Number field.
* @param $Resource Resource object
* @param $Field MetadataField object
*/
function DisplayNumberField(Resource $Resource, MetadataField $Field)
{
# don't display the rating field
if ($Field->Name() == "Cumulative Rating")
{
return;
}
$Data = GetResourceFieldValue($Resource, $Field);
$Data = StripXSSThreats($Data);
DisplayResourceField($Resource, $Field, $Data);
}
/**
* Display a Date field.
* @param $Resource Resource object
* @param $Field MetadataField object
*/
function DisplayDateField(Resource $Resource, MetadataField $Field)
{
$Data = GetResourceFieldValue($Resource, $Field);
# convert to text if given a Date object
if ($Data instanceof Date)
{
$Data = $Data->Formatted();
$Data = defaulthtmlentities($Data);
}
$Data = StripXSSThreats($Data);
DisplayResourceField($Resource, $Field, $Data);
}
/**
* Display a Timestamp field.
* @param $Resource Resource object
* @param $Field MetadataField object
*/
function DisplayTimestampField(Resource $Resource, MetadataField $Field)
{
$Data = GetResourceFieldValue($Resource, $Field);
$Data = StripXSSThreats($Data);
DisplayResourceField($Resource, $Field, $Data);
}
/**
* Display a Flag field.
* @param $Resource Resource object
* @param $Field MetadataField object
*/
function DisplayFlagField(Resource $Resource, MetadataField $Field)
{
$Data = GetResourceFieldValue($Resource, $Field);
# convert the value to its corresponding label if the value appears
# unmodified
if (is_numeric($Data))
{
$Data = ($Data > 0) ? $Field->FlagOnLabel() : $Field->FlagOffLabel();
$Data = defaulthtmlentities($Data);
}
$Data = StripXSSThreats($Data);
DisplayResourceField($Resource, $Field, $Data);
}
/**
* Display a Tree field.
* @param $Resource Resource object
* @param $Field MetadataField object
*/
function DisplayTreeField(Resource $Resource, MetadataField $Field)
{
global $AF;
$Names = GetResourceFieldValue($Resource, $Field);
# convert the value to a list if the value appears unmodified
if (is_array($Names))
{
# get additional HTML to display, if any. do this here because the field
# shouldn't be displayed if there no values or additional HTML and the
# DisplayResourceField doesn't have access to that information
$SignalResult = $AF->SignalEvent(
"EVENT_APPEND_HTML_TO_FIELD_DISPLAY",
array(
"Field" => $Field, "Resource" => $Resource,
"Context" => "DISPLAY", "Html" => NULL));
$Html = $SignalResult["Html"];
# only output tree fields with values and no additional HTML
if (count($Names) < 1 && is_null($Html))
{
return;
}
$Data = NULL;
foreach ($Names as $Id => $Name)
{
$LinkAttributes = array(
"href" =>
"index.php?P=AdvancedSearch&Q=Y&G"
.EscapeParam($Field->Id())."=".EscapeParam($Id),
"title" =>
"Search for all resources also classified as \""
.defaulthtmlentities($Name->Name())."\"");
$Data .= PrepareNameValue($Resource, $Field, $Name, $LinkAttributes);
}
$ListAttributes = array(
"class" => "cw-list cw-list-dematte cw-list-unmarked");
$Data = CreateHtmlElement("ul", $ListAttributes, $Data);
# add additional HTML, if any
$Data .= $Html;
}
# value was likely modified and is a string
else
{
$Data = StripXSSThreats($Names);
}
DisplayResourceField(
$Resource,
$Field,
$Data,
array("IsTall" => TRUE, "NoHtml" => TRUE));
}
/**
* Display a Controlled Name field.
* @param $Resource Resource object
* @param $Field MetadataField object
*/
function DisplayControlledNameField(Resource $Resource, MetadataField $Field)
{
global $AF;
$Names = GetResourceFieldValue($Resource, $Field);
# convert the value to a list if the value appears unmodified
if (is_array($Names))
{
# get additional HTML to display, if any. do this here because the field
# shouldn't be displayed if there no values or additional HTML and the
# DisplayResourceField doesn't have access to that information
$SignalResult = $AF->SignalEvent(
"EVENT_APPEND_HTML_TO_FIELD_DISPLAY",
array(
"Field" => $Field, "Resource" => $Resource,
"Context" => "DISPLAY", "Html" => NULL));
$Html = $SignalResult["Html"];
# only output controlled name fields with values and no additional HTML
if (count($Names) < 1 && is_null($Html))
{
return;
}
$Data = NULL;
foreach ($Names as $Id => $Name)
{
$LinkAttributes = array(
"href" =>
"index.php?P=AdvancedSearch&Q=Y&F"
.EscapeParam($Field->Id())."="
.EscapeParam("=".$Name->Name()),
"title" =>
"Search for all resources also classified as \""
.defaulthtmlentities($Name->Name())."\"");
$Data .= PrepareNameValue($Resource, $Field, $Name, $LinkAttributes);
}
$ListAttributes = array(
"class" => "cw-list cw-list-dematte cw-list-unmarked");
$Data = CreateHtmlElement("ul", $ListAttributes, $Data);
# add additional HTML, if any
$Data .= $Html;
}
# value was likely modified and is a string
else
{
$Data = StripXSSThreats($Names);
}
DisplayResourceField(
$Resource, $Field, $Data, array("IsTall" => TRUE, "NoHtml" => TRUE));
}
/**
* Display an Option field.
* @param $Resource Resource object
* @param $Field MetadataField object
*/
function DisplayOptionField(Resource $Resource, MetadataField $Field)
{
global $AF;
$Names = GetResourceFieldValue($Resource, $Field);
# convert the value to a list if the value appears unmodified
if (is_array($Names))
{
# get additional HTML to display, if any. do this here because the field
# shouldn't be displayed if there no values or additional HTML and the
# DisplayResourceField doesn't have access to that information
$SignalResult = $AF->SignalEvent(
"EVENT_APPEND_HTML_TO_FIELD_DISPLAY",
array(
"Field" => $Field, "Resource" => $Resource,
"Context" => "DISPLAY", "Html" => NULL));
$Html = $SignalResult["Html"];
# only output options fields with values and no additional HTML
if (count($Names) < 1 && is_null($Html))
{
return;
}
$Data = NULL;
foreach ($Names as $Id => $Name)
{
$LinkAttributes = array(
"href" =>
"index.php?P=AdvancedSearch&Q=Y&G"
.EscapeParam($Field->Id())."=".EscapeParam($Id),
"title" =>
"Search for all resources also classified as \""
.defaulthtmlentities($Name->Name())."\"");
$Data .= PrepareNameValue($Resource, $Field, $Name, $LinkAttributes);
}
$ListAttributes = array(
"class" => "cw-list cw-list-dematte cw-list-unmarked");
$Data = CreateHtmlElement("ul", $ListAttributes, $Data);
# add additional HTML, if any
$Data .= $Html;
}
# value was likely modified and is a string
else
{
$Data = StripXSSThreats($Names);
}
DisplayResourceField(
$Resource,
$Field,
$Data,
array("IsTall" => TRUE, "NoHtml" => TRUE));
}
/**
* Display an User field.
* @param $Resource Resource object
* @param $Field MetadataField object
*/
function DisplayUserField(Resource $Resource, MetadataField $Field)
{
global $User;
$Data = GetResourceFieldValue($Resource, $Field);
# convert to a user name if given an User object
if ($Data instanceof User)
{
$Data = (is_null($Data->Get("UserId")))
? "Unknown" : $Data->Get("UserName");
$Data = defaulthtmlentities($Data);
}
$Data = StripXSSThreats($Data);
DisplayResourceField($Resource, $Field, $Data);
}
/**
* Display an Image field.
* @param $Resource Resource object
* @param $Field MetadataField object
*/
function DisplayStillImageField(Resource $Resource, MetadataField $Field)
{
$Image = GetResourceFieldValue($Resource, $Field);
# don't display an image that is unavailable
if (is_null($Image))
{
return;
}
# handle an Image object
if ($Image instanceof SPTImage)
{
# only display image fields with an image available
if (!is_readable($Image->PreviewUrl()))
{
return;
}
$ImageAttributes = array(
"src" => $Image->PreviewUrl(),
"alt" => $Image->AltText(),
"title" => $Image->AltText());
if ($Image->PreviewWidth() > 0)
{
$ImageAttributes["width"] = $Image->PreviewWidth();
}
if ($Image->PreviewHeight() > 0)
{
$ImageAttributes["height"] = $Image->PreviewHeight();
}
$Image = CreateHtmlElement("img", $ImageAttributes);
$LinkAttributes = array(
"href" =>
"index.php?P=FullImage&ResourceId=".$Resource->Id()
."&FieldName=".$Field->Name()."&edit=0");
$Data = CreateHtmlElement("a", $LinkAttributes, $Image);
}
# value was likely modified and is a string
else
{
$Data = StripXSSThreats($Image);
}
DisplayResourceField($Resource, $Field, $Data, array("IsTall" => TRUE));
}
/**
* Display a File field.
* @param $Resource Resource object
* @param $Field MetadataField object
*/
function DisplayFileField(Resource $Resource, MetadataField $Field)
{
$Files = GetResourceFieldValue($Resource, $Field);
# given an array of files
if (is_array($Files))
{
# only display file fields with at least one file
if (count($Files) < 1)
{
return;
}
$Data = NULL;
foreach ($Files as $Id => $File)
{
$Item = defaulthtmlentities($File->Name());
$Attributes = array(
"href" => $File->GetLink(),
"title" => "Download \"".$File->Name()."\"");
$Item = CreateHtmlElement("a", $Attributes, $Item);
$Data .= CreateHtmlElement("li", array(), $Item);
}
$ListAttributes = array(
"class" => "cw-list cw-list-dematte cw-list-unmarked");
$Data = CreateHtmlElement("ul", $ListAttributes, $Data);
}
# value was likely modified and is a string
else
{
$Data = StripXSSThreats($Files);
}
DisplayResourceField($Resource, $Field, $Data, array("IsTall" => TRUE));
}
/**
* Display an Url field.
* @param $Resource Resource object
* @param $Field MetadataField object
* @param $Value optional value for the URL
*/
function DisplayUrlField(Resource $Resource, MetadataField $Field, $Value=NULL)
{
global $SysConfig;
$Data = GetResourceFieldValue($Resource, $Field);
# only display URLs with a set value
if (strlen($Data) < 1)
{
return;
}
# if the data looks like an URL
if (IsSensibleUrl($Data))
{
$TruncData = (!is_null($Value))
? $Value : defaulthtmlentities(NeatlyTruncateString($Data, 70, TRUE));
$LinkAttributes = array(
"href" => "index.php?P=GoTo&ID=".$Resource->Id()."&MF=".$Field->Id(),
"title" => $Data);
if ($SysConfig->ResourceLaunchesNewWindowEnabled())
{
$LinkAttributes["target"] = "_blank";
}
$Link = CreateHtmlElement("a", $LinkAttributes, $TruncData);
}
# value was likely modified and is a string
else
{
$Link = StripXSSThreats($Data);
}
DisplayResourceField($Resource, $Field, $Link);
}
/**
* Display a Point field.
* @param $Resource Resource object
* @param $Field MetadataField object
*/
function DisplayPointField(Resource $Resource, MetadataField $Field)
{
$Data = GetResourceFieldValue($Resource, $Field);
# reduce to a single value if given an array that contains the point values
if (is_array($Data))
{
$X = $Data["X"];
$Y = $Data["Y"];
$Data = !is_null($X) ? $X . ", " . $Y : NULL;
}
$Data = StripXSSThreats($Data);
DisplayResourceField($Resource, $Field, $Data, array("IsTall" => TRUE));
}
# star rating functions
function PrintRatingGraphic0() { ?> " alt="This resource has a 1 star rating" />
" alt="This resource has a 1 star rating" />
" alt="This resource has a 1 star rating" />
" alt="This resource has a 1.5 star rating" />
" alt="This resource has a 2 star rating" />
" alt="This resource has a 2.5 star rating" />
" alt="This resource has a 3 star rating" />
" alt="This resource has a 3.5 star rating" />
" alt="This resource has a 4 star rating" />
" alt="This resource has a 4.5 star rating" />
" alt="This resource has a 5 star rating" /> (not yet rated)"; }
# ----- LOCAL FUNCTIONS ------------------------------------------------------
/**
* Determine if a MetadataField value can be displayed, depending on whether
* it's enabled and the user has the necessary privileges.
* @param $Field MetadataField object
* return TRUE if the field can be displayed, FALSE otherwise
*/
function CanDisplayField(MetadataField $Field=NULL)
{
global $User;
# field not set or not enabled
if (is_null($Field) || !$Field->Enabled())
{
return FALSE;
}
$ViewingPrivilege = $Field->ViewingPrivilege();
# insufficient privileges
if ($ViewingPrivilege != 0 && !$User->HasPriv($ViewingPrivilege))
{
return FALSE;
}
return TRUE;
}
/**
* Generate an HTML element.
* @param $Name a valid HTML element name (is not escaped)
* @param $Attributes array of attributes and values (only values are escaped)
* @param $Inner inner HTML elements or text (is not escaped)
* return HTML element string
*/
function CreateHtmlElement($Name, $Attributes=array(), $Inner=NULL)
{
$Element = "<" . $Name;
foreach ($Attributes as $Attribute => $Value)
{
$Value = defaulthtmlentities($Value);
$Element .= " " . $Attribute . '="' . $Value . '"';
}
$Element .= (is_null($Inner)) ? " />" : ">".$Inner."".$Name.">";
return $Element;
}
/**
* Display a resource field value.
* @param $Resource Resource object
* @param $Field MetadataField object
* @param $Data the field value with any alterations made
* @param $Options array of options
*/
function DisplayResourceField(
Resource $Resource, MetadataField $Field, $Data, array $Options=array())
{
global $AF;
# only display fields with a value
if (is_null($Data) || (is_string($Data) && strlen($Data) < 1))
{
return;
}
$Header = defaulthtmlentities($Field->GetDisplayName());
$Description = defaulthtmlentities($Field->Description());
$IsTall = GetArrayValue($Options, "IsTall", FALSE);
# vertically align to the top if more than 100 characters
$RowClass = ($IsTall) ? ' class="cw-content-tallrow"' : "";
$Html = NULL;
if (!isset($Options["NoHtml"]) || !$Options["NoHtml"])
{
# get additional HTML to display, if any
$SignalResult = $AF->SignalEvent(
"EVENT_APPEND_HTML_TO_FIELD_DISPLAY",
array(
"Field" => $Field, "Resource" => $Resource,
"Context" => "DISPLAY", "Html" => NULL));
$Html = $SignalResult["Html"];
}
?>
No resource was found with the specified ID.
(no comments available yet for this resource)
HasPriv(PRIV_SYSADMIN, PRIV_POSTCOMMENTS)) { ?>
Resource Comments