Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test functions

display_field_data()

Parameters

ColumnTypeDefaultDescription
$field array
$valueonly false
$fixedwidth 452

Location

include/render_functions.php lines 4214 to 4468

Definition

 
function display_field_data(array $field,$valueonly=false,$fixedwidth=452)
    {
    
debug_function_call(__FUNCTION__, [$field['ref'], $valueonly$fixedwidth]);
    global 
$ref$show_expiry_warning$access$search$extra$lang$FIXED_LIST_FIELD_TYPES$force_display_template_orderby;

    
$value = (string) $field["value"];
    
$title=escape($field["title"]);
    
$modified_field=hook("beforeviewdisplayfielddata_processing","",array($field));
    if(
$modified_field)
        {
        
$field=$modified_field;
        
debug(sprintf('$field #%s was modified by beforeviewdisplayfielddata_processing hook'$field['ref']));
        }

    
$warningtext="";
    
$dismisstext="";
    
$dismisslink="";
    
# Handle expiry date warning messages
    
if (!$valueonly && $field["type"] == FIELD_TYPE_EXPIRY_DATE && $value != "" && $value <= date("Y-m-d H:i") && $show_expiry_warning
        {
        
debug('Handle expiry date warning messages');
        
$title escape($lang["warningexpired"]);
        
$warningtext escape($lang["warningexpiredtext"]);
        
$dismisstext LINK_CARET escape($lang["warningexpiredok"]);
        
$dismisslink "<p id=\"WarningOK\">
        <a href=\"#\" onClick=\"document.getElementById('RecordDownloadTabContainer').style.display='block';document.getElementById('WarningOK').style.display='none';\">
{$dismisstext}</a></p>";
        
$extra.="<style>#RecordDownloadTabContainer {display:none;}</style>";

        
# If there is no display template then prepare the full markup here
        
if (trim((string) $field["display_template"]) == ""
            {
            
$extra.="<div class=\"clearerleft\"></div><div class=\"RecordStory\"><h1>{$title}</h1>
            <p>
{$value}</p><p>{$warningtext}</p>{$dismisslink}</div>";
            }
        }
    
    
# Handle general warning messages
    
if (!$valueonly && $field["type"] == FIELD_TYPE_WARNING_MESSAGE && trim($value) != ""
        {
        
debug('Handle general warning messages');
        
$warningtext $value;
        
$dismisstext LINK_CARET escape($lang["warningexpiredok"]);
        
$dismisslink "<p id=\"WarningOK_{$field['ref']}\">
        <a href=\"#\" onClick=\"document.getElementById('RecordDownloadTabContainer').style.display='block';document.getElementById('WarningOK_
{$field['ref']}').style.display='none';\">{$dismisstext}</a></p>";
        
$extra.="<style>#RecordDownloadTabContainer {display:none;}</style>";

        
# If there is no display template then prepare the full markup here
        
if (trim((string) $field["display_template"]) == ""
            {
            
$extra.="<div class=\"clearerleft\"></div><div class=\"RecordStory\"><h1>{$title}</h1>
            <p>"
.nl2br(escape(i18n_get_translated($warningtext)))."</p>{$dismisslink}</div>";
            }
        }

    if (
$field['value_filter']!="")
        {
        
debug('Calling value_filter...');
        eval(
eval_check_signed($field['value_filter']));
        }
    elseif (
$field["type"]==FIELD_TYPE_DATE_AND_OPTIONAL_TIME && strpos($value,":")!=false)
        {
        
// Show the time as well as date if entered
        
$value=nicedate($value,true,true);
        }
    elseif (
$field["type"]==FIELD_TYPE_DATE_AND_OPTIONAL_TIME || $field["type"]==FIELD_TYPE_EXPIRY_DATE || $field["type"]==FIELD_TYPE_DATE)
        {
        
$value=nicedate($value,false,true);
        }
    elseif (
$field["type"]==FIELD_TYPE_DATE_RANGE)
        {
        
$rangedates explode(",",$value);
        
natsort($rangedates);
        
$value=implode(DATE_RANGE_SEPARATOR,$rangedates);
        }
    
        if(
$field['type'] == FIELD_TYPE_CATEGORY_TREE)
            {
            
$parentnode null;
            
$recursive true;
            
$treenodes get_nodes($field["ref"], $parentnode$recursive);
            
$detailed=false# Just get the nodes
            
$node_sort=false# Do not sort the nodes
            
$resource_nodes=get_resource_nodes($ref$field["ref"], $detailed$node_sort);
            
$treenodenames = array();
            foreach (
$treenodes as $treenode)
                {
                if(
in_array($treenode["ref"],$resource_nodes)) 
                    {
                    
$treenodenames[] = ["ref" => $treenode["ref"], "name" => $treenode["translated_path"]];
                    }
                }
            
$value render_fixed_list_as_pills($treenodenames);
            }
    
    if ((
$value!="") && ($value!=",") && ($field["display_field"]==1) && ($access==|| ($access==&& !$field["hide_when_restricted"])))
        {
        
debug('Field can display...');
        if (!
$valueonly)
            {
            
debug('Showing title');
            
$title=escape(str_replace("Keywords - ","",$field["title"]));
            }
        else
            {
            
debug('Blanking title');
            
$title="";
            }

        
# Value formatting
        # Optimised to use the value as is if there are no "~" characters present in the value
        
if (is_i18n_language_string($value) && $field['type'] != FIELD_TYPE_CATEGORY_TREE) {
            
$field_value $value;
            
debug('value formatting due to ~ character...');
            
# The field value may be a list of comma separated language encoded values, so process the nodes
            
$field_nodes_in_value explode(","$field["nodes"]);
            if (
count($field_nodes_in_value) > 1) {
                
# Multiple nodes in value; Get all nodes for the field and translate each one which is in the metadata
                
$field_nodes_all get_nodes($field['ref']);
                
$names_i18n_in_value extract_node_options($field_nodes_alltruetrue);
                
# Convert the field nodes in value as an array keyed by the names to allow an intersect by key operation 
                
$node_names_in_value array_intersect_key($names_i18n_in_valuearray_flip($field_nodes_in_value));
                
$value implode(', '$node_names_in_value);
                
$field_nodes_translated array_map(function($node_value$node_id
                        {
                        return [
'name' => $node_value'ref' => $node_id];
                        }
                        , 
$node_names_in_valuearray_keys($node_names_in_value));
            }

            
# Not a node list so translate the raw value or something went wrong trying to resolve the node values 
            # so attempt to translate the raw value to display instead
            
if (count($field_nodes_in_value) == || trim($value) == "") {
                
# Translate the single value
                
$value=i18n_get_translated($field_value);
                
$field_nodes_translated = [['name' => $value'ref' => $field['nodes']]];
            }
        }

        
// Handle the rest of the fixed list fields, category trees have their own section
        
if (in_array($field['type'], $FIXED_LIST_FIELD_TYPES) && $field['type'] != FIELD_TYPE_CATEGORY_TREE) {
            
$value render_fixed_list_as_pills($field_nodes_translated ?? get_resource_nodes($ref$field["ref"], truefalse));
        }

        
# Do not convert HTML formatted fields (that are already HTML) to HTML. Added check for extracted fields set to 
        # ckeditor that have not yet been edited.
        
if(
            (
$field["type"] != FIELD_TYPE_TEXT_BOX_FORMATTED_AND_CKEDITOR && !in_array($field['type'], $FIXED_LIST_FIELD_TYPES))
            || (
$field["type"] == FIELD_TYPE_TEXT_BOX_FORMATTED_AND_CKEDITOR && $value == strip_tags($value))
            )
            {
            
$value nl2br(escape($value));
            }
        elseif(
$field["type"] == FIELD_TYPE_TEXT_BOX_FORMATTED_AND_CKEDITOR && $value != strip_tags($value))
            {
            
$value strip_tags_and_attributes($value, ['a'], ['href''target']);
            }

        
$modified_value hook('display_field_modified_value''', array($field));
        if(
$modified_value)
            {       
            
$value $modified_value['value'];
            
debug('field value modified by display_field_modified_value hook');
            }
        
# Final stages of rendering

        # Include display template when necessary
        
if (!$valueonly && trim($field["display_template"] ?? "")!="")
            {
            
debug('Include display_template');
            
$value_for_url=$value;
            
# Highlight keywords
            
$value=highlightkeywords($value,$search,$field["partial_index"],$field["name"],$field["keywords_index"]);
            
            
$value_mod_after_highlight=hook('value_mod_after_highlight''', array($field,$value));
            if(
$value_mod_after_highlight)
                {
                
$value=$value_mod_after_highlight;
                }

            
# Use a display template to render this field
            
$template strip_tags_and_attributes($field['display_template'], array("a"), array("href""target"));
            
$template str_replace('[title]'$title$template);
            
$template str_replace('[value]'$value$template);
            
$template str_replace(['[url]''%5Burl%5D'], escape($value_for_url), $template);
            
$template str_replace('[warning]'escape($warningtext), $template);
            
$template str_replace('[ref]', (int) $ref$template);
            
$template str_replace('[link]'strip_tags_and_attributes($dismisslink, array("a"), array("href""onclick")), $template);

            
/*Language strings
            Format: [lang-language-name_here]
            Example: [lang-resourcetype-photo]
            */
            
preg_match_all('/\[lang-(.+?)\]/'$template$template_language_matches);
            
$i 0;
            foreach(
$template_language_matches[0] as $template_language_match_placeholder)
                {
                
$placeholder_value $template_language_match_placeholder;

                if(isset(
$lang[$template_language_matches[1][$i]]))
                    {
                    
$placeholder_value $lang[$template_language_matches[1][$i]];
                    }

                
$template str_replace($template_language_match_placeholder$placeholder_value$template);

                
$i++;
                }

            
$extra   .= $template;
            }
        else
            {
            
debug('No display template');
            
# There is a value in this field, but we also need to check again for a current-language value after the i18n_get_translated() function was called, to avoid drawing empty fields
            
if ($value!="")
                {
                
debug('Draw this field normally...');
                
# Draw this field normally. - value has already been sanitized by htmlspecialchars
                # Highlight keywords
                
$value=highlightkeywords($value,$search,$field["partial_index"],$field["name"],$field["keywords_index"]);
                
                
$value_mod_after_highlight=hook('value_mod_after_highlight''', array($field,$value));
                if(
$value_mod_after_highlight)
                    {
                    
$value=$value_mod_after_highlight;
                    }
                
                
?><div 
                
                
if (!$valueonly)
                    {
                    if (
$field["full_width"])
                        {
                        echo 
"class=\"clearerleft item itemType".$field['type']."\"";
                        }
                    else
                        {
                        echo 
"class=\"itemNarrow itemType".$field['type']."\"";
                        }
                    }
                elseif (isset(
$fixedwidth))
                    {
                    echo 
"style=\"width:" $fixedwidth "px\"";
                    } 
?>>
                <h3> echo $title?></h3><p> echo $value?></p></div>
                
}
            }
            
        if(
$force_display_template_orderby)
            {
            echo 
$extra;
            
$extra='';
            }
        }
    }

This article was last updated 4th December 2024 08:35 Europe/London time based on the source file dated 3rd December 2024 11:55 Europe/London time.