Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource functions

display_field_data()

Parameters

ColumnTypeDefaultDescription
$field array
$valueonly false
$fixedwidth 452

Location

include/render_functions.php lines 4149 to 4398

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=$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((string)$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((string)$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(",",(string)$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[]=$treenode["path"];
                    }
                }
            
$value implode(", ",$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(strpos($value,"~") !== false
        {
        
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(",",$value);
        if(
count($field_nodes_in_value) == 1)  
            {
            
# Translate the single value
            
$value=i18n_get_translated($value);
            }
        elseif(
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(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 19th March 2024 04:05 Europe/London time based on the source file dated 15th March 2024 17:00 Europe/London time.