<?php
/*
Plugin Name: List View Date Format
Description: Formats the date in cmsb list view
Author: Robin
Version: 0.01
Requires at least: 2.06
*/



// register hooks
addFilter('listRow_displayValue', '_lvdf_changeDateFormat', null, 4);

function _lvdf_changeDateFormat($displayValue, $tableName, $fieldname, $record) {

  $returnValue = $displayValue;

  //Should we even consider this field?
  if(!($displayValueTimeStamp = strtotime($displayValue))) {
    return $returnValue; 
  }


  $dateFormat = "d-m-Y";

  $year = substr($displayValue, 0, 4);
  $firstHyphen = substr($displayValue, 4, 1);

  $month = substr($displayValue, 5, 2);
  $secondHyphen = substr($displayValue, 7, 1);

  $day = substr($displayValue, 8, 2);

  //echo $year . " " . $firstHyphen . " " . $month . " " . $secondHyphen . " " . $day;

  if(is_numeric($year) && is_numeric($month) && is_numeric($day) && ($firstHyphen == "-") && ($secondHyphen == "-")) {
    $displayValueTimeStamp = strtotime($displayValue);
    if($displayValueTimeStamp > 1) {
      $returnValue = date($dateFormat, $displayValueTimeStamp);
    }
  }
  return $returnValue;
}

?>
