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

log_diff()

Description

Check changes made to a metadata field and create a nice user friendly summary

Parameters

ColumnTypeDefaultDescription
$fromvalue string - if nodes then values will be separated by NODE_NAME_STRING_SEPARATOR
$tovalue string - if nodes then values will be separated by NODE_NAME_STRING_SEPARATOR

Return

string

Location

include/resource_functions.php lines 5902 to 5961

Definition

 
function log_diff($fromvalue$tovalue)
    {
    
$return '';
    
debug_function_call("log_diff",func_get_args());

    
// Trim values as it can cause out of memory errors with class.Diff.php e.g. when saving extracted text or creating previews for large PDF files
    
if(strlen((string) $fromvalue)>10000)
        {
        
$fromvalue mb_substr($fromvalue,10000);
        }
    if(
strlen((string) $tovalue)>10000)
        {
        
$tovalue mb_substr($tovalue,10000);
        }

    
// Remove any database escaping
    
$fromvalue str_replace("\\"''$fromvalue);
    
$tovalue   str_replace("\\"''$tovalue);

    
// Work a different way for fixed lists
    
if(strpos($fromvalueNODE_NAME_STRING_SEPARATOR) !== false || strpos($tovalueNODE_NAME_STRING_SEPARATOR) !== false)
        {
        
$fromvalue array_filter(explode(NODE_NAME_STRING_SEPARATOR$fromvalue));
        
$tovalue   array_filter(explode(NODE_NAME_STRING_SEPARATOR$tovalue));

        
// Empty arrays if either side is blank.
        
if (count($fromvalue)==0) {$fromvalue=array();}
        if (
count($tovalue)==0)   {$tovalue=array();}

        
// Get diffs
        
$inserts array_diff($tovalue$fromvalue);
        
$deletes array_diff($fromvalue$tovalue);

        
// Process array diffs into meaningful strings
        
if(count($deletes))
            {
            
$return .= '- ' join("\n- " $deletes);
            }

        if(
count($inserts))
            {
            if(
'' != $return)
                {
                
$return .= "\n";
                }

            
$return .= '+ ' join("\n+ "$inserts);
            }

        return 
$return;
        }

    
// Simple return when either side is blank (the user is adding or removing all the text)
    
if ($fromvalue=="") {return "+ " $tovalue;}
    if (
$tovalue=="") {return "- " $fromvalue;}

    
// For standard strings, use Diff library
    
require_once __DIR__ '/../lib/Diff/class.Diff.php';
    return 
Diff::toString(Diff::compare($fromvalue$tovalue));
    }

This article was last updated 11th December 2024 11:35 Europe/London time based on the source file dated 11th December 2024 10:05 Europe/London time.