Collections functions
General functions
Render functions
Theme permission functions
Resource functions

display_field_data()

Parameters

ColumnTypeDefaultDescription
$field
$valueonly false
$fixedwidth 452

Location

include/render_functions.php lines 4098 to 4318

Definition

 
function display_field_data($field,$valueonly=false,$fixedwidth=452)
    {        
    global 
$ref$show_expiry_warning$access$search$extra$lang$FIXED_LIST_FIELD_TYPES$range_separator$force_display_template_orderby;

    
$value=$field["value"];
    
$title=htmlspecialchars($field["title"]);
    
$modified_field=hook("beforeviewdisplayfielddata_processing","",array($field));
    if(
$modified_field)
        {
        
$field=$modified_field;
        }

    
$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
        {
        
$title htmlspecialchars($lang["warningexpired"]);
        
$warningtext htmlspecialchars($lang["warningexpiredtext"]);
        
$dismisstext LINK_CARET htmlspecialchars($lang["warningexpiredok"]);
        
$dismisslink "<p id=\"WarningOK\">
        <a href=\"#\" onClick=\"document.getElementById('RecordDownload').style.display='block';document.getElementById('WarningOK').style.display='none';\">
{$dismisstext}</a></p>";
        
$extra.="<style>#RecordDownload {display:none;}</style>";

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

        
# If there is no display template then prepare the full markup here
        
if (trim((string) $field["display_template"]) == ""
            {
            
$extra.="<div class=\"RecordStory\"><h1>{$title}</h1>
            <p>"
.nl2br(htmlspecialchars(i18n_get_translated($warningtext)))."</p>{$dismisslink}</div>";
            }
        }
    
    if (
$field['value_filter']!="")
        {
        eval(
eval_check_signed($field['value_filter']));
        }
    else if (
$field["type"]==FIELD_TYPE_DATE_AND_OPTIONAL_TIME && strpos((string)$value,":")!=false)
        {
        
// Show the time as well as date if entered
        
$value=nicedate($value,true,true);
        }
    else if (
$field["type"]==FIELD_TYPE_DATE_AND_OPTIONAL_TIME || $field["type"]==FIELD_TYPE_EXPIRY_DATE || $field["type"]==FIELD_TYPE_DATE)
        {
        
$value=nicedate($value,false,true);
        }
    else if (
$field["type"]==FIELD_TYPE_DATE_RANGE
        {
        
$rangedates explode(",",(string)$value);        
        
natsort($rangedates);
        
$value=implode($range_separator,$rangedates);
        }
    
        if(
$field['type'] == FIELD_TYPE_CATEGORY_TREE)
            {
            
$treenodes get_cattree_nodes_ordered($field["ref"], $reffalse); # True means get all nodes; False means get selected nodes
            
$treenodenames get_cattree_node_strings($treenodestrue); # True means names are paths to nodes; False means names are node names
            
$value implode(", ",$treenodenames);        
            }
    
    if ((
$value!="") && ($value!=",") && ($field["display_field"]==1) && ($access==|| ($access==&& !$field["hide_when_restricted"])))
        {            
        if (!
$valueonly)
            {
            
$title=htmlspecialchars(str_replace("Keywords - ","",$field["title"]));
            }
        else
            {
            
$title="";
            }

    
# Value formatting
    # Optimised to use the value as is if there are no "~" characters present in the value
    
if(strpos($value,"~") !== false
        {
        
# 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)  
            {
            
# Translate the single value
            
$value=i18n_get_translated($value);
            }
        else 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);
            }
        } 
        
        
// Don't display the comma for radio buttons:
        
if($field['type'] == FIELD_TYPE_RADIO_BUTTONS)
            {
            
$value str_replace(','''$value);
            }

        
# 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
            
|| ($field["type"] == FIELD_TYPE_TEXT_BOX_FORMATTED_AND_CKEDITOR && $value == strip_tags($value))
            )
            {
            
$value nl2br(htmlspecialchars($value));
            }

        
$modified_value hook('display_field_modified_value''', array($field));
        if(
$modified_value)
            {        
            
$value $modified_value['value'];
            }

        
# Final stages of rendering

        # Include display template when necessary
        
if (!$valueonly && trim($field["display_template"] ?? "")!="")
            {
            
# 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 $field['display_template'];
            
$template str_replace('[title]'$title$template);
            
$template str_replace('[value]'strip_tags_and_attributes($value,array("a"),array("href","target")), $template);
            
$template str_replace('[warning]'$warningtext$template);
            
$template str_replace('[ref]', (int) $ref$template);
            
$template str_replace('[link]'$dismisslink$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 
# 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!="")
                {
                
# 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 October 2022 12:05 Europe/London time based on the source file dated 22nd September 2022 16:20 Europe/London time.