strip_tags($el2)';
break;
case SORT_STRING :
$compare_function = 'strnatcmp(TableSort::orderingstring(strip_tags($el1)),TableSort::orderingstring(strip_tags($el2))) > 0';
break;
case SORT_IMAGE :
$compare_function = 'strnatcmp(TableSort::orderingstring(strip_tags($el1,"
")),TableSort::orderingstring(strip_tags($el2,"
"))) > 0';
break;
case SORT_DATE :
$compare_function = 'strtotime(strip_tags($el1)) > strtotime(strip_tags($el2))';
}
$function_body = '$el1 = $a['.$column.']; $el2 = $b['.$column.']; return ('.$direction.' == SORT_ASC ? ('.$compare_function.') : !('.$compare_function.'));';
// Sort the content
usort($data, create_function('$a,$b', $function_body));
return $data;
}
/**
* Checks if a column of a 2D-array contains only numeric values
* @param array $data The data-array
* @param int $column The index of the column to check
* @return bool true if column contains only dates, false otherwise
* @todo Take locale into account (eg decimal point or comma ?)
* @author bart.mollet@hogent.be
*/
function is_numeric_column($data, $column)
{
$is_numeric = true;
foreach ($data as $index => $row)
{
$is_numeric &= is_numeric(strip_tags($row[$column]));
}
return $is_numeric;
}
/**
* Checks if a column of a 2D-array contains only dates (GNU date syntax)
* @param array $data The data-array
* @param int $column The index of the column to check
* @return bool true if column contains only dates, false otherwise
* @author bart.mollet@hogent.be
*/
function is_date_column($data, $column)
{
$is_date = true;
foreach ($data as $index => $row)
{
if(strlen(strip_tags($row[$column])) != 0 )
{
$check_date = strtotime(strip_tags($row[$column]));
// strtotime Returns a timestamp on success, FALSE otherwise.
// Previous to PHP 5.1.0, this function would return -1 on failure.
$is_date &= ($check_date != -1 && $check_date != false);
}
else
{
$is_date &= false;
}
}
return $is_date;
}
/**
* Checks if a column of a 2D-array contains only images (
)
* @param array $data The data-array
* @param int $column The index of the column to check
* @return bool true if column contains only images, false otherwise
* @author bart.mollet@hogent.be
*/
function is_image_column($data, $column)
{
$is_image = true;
foreach ($data as $index => $row)
{
$is_image &= strlen(trim(strip_tags($row[$column],'
'))) > 0; // at least one img-tag
$is_image &= strlen(trim(strip_tags($row[$column]))) == 0; // and no text outside attribute-values
}
return $is_image;
}
}
?>