Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video functions
Resource functions

log_diff()

Description

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

Parameters

ColumnTypeDefaultDescription
$fromvalue string
$tovalue string

Return

string

Location

include/resource_functions.php lines 5226 to 5287

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($fromvalue)>10000)
        {
        
$fromvalue mb_substr($fromvalue,10000);
        }    
    if(
strlen($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(',' == substr($fromvalue01) || ',' == substr($tovalue01))
        {
        
$fromvalue array_filter(explode(','$fromvalue));
        
$tovalue   array_filter(explode(','$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 dirname(__FILE__) . '/../lib/Diff/class.Diff.php';
    
$return Diff::toString(Diff::compare($fromvalue$tovalue));

    return 
$return;
    }

This article was last updated 23rd November 2020 16:05 Europe/London time based on the source file dated 13th November 2020 16:50 Europe/London time.