Source of file SyncFilterHelper.php
Size: 2,271 Bytes - Last Modified: 2021-12-23T10:03:30+00:00
/var/www/docs.ssmods.com/process/src/code/SyncFilterHelper.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 | <?php /** * Processes where filters and makes a few things easier * such as date ranges. Currently processes: * * 'Date' => ':future' * 'Date' => ':last X days' * * @author Mark Guinn <mark@adaircreative.com> * @date 3.13.13 * @package silverstripe-sync */ class SyncFilterHelper { /** * @static * @param array $filters * @return array */ public static function process_filters(array $filters) { $out = array(); foreach ($filters as $field => $filter) { if (is_string($filter) && $filter == ':future') { $out[$field . ':GreaterThan'] = date('Y-m-d H:i:s'); } elseif (is_string($filter) && preg_match('/^:last (\d+) days?$/', $filter, $matches)) { $out[$field . ':GreaterThan'] = date('Y-m-d H:i:s', time() - ($matches[1] * 24 * 60 * 60)); } else { // pass everything else through $out[$field] = $filter; } } return $out; } /** * @param array $field_names * @return array - key=real field name, value=false|callable */ public static function process_fields(array $field_names) { $out = array(); foreach ($field_names as $name) { if (strpos($name, ':') !== false) { $parts = explode(':', $name); $out[$parts[0]] = array('SyncFilterHelper', $parts[1]); } else { $out[$name] = false; } } return $out; } // Filter functions ///////////////////////////////////////////////////////// /** * @param $s * @return string */ public static function strip_html($s) { return Convert::html2raw($s); } /** * @param $s * @return string */ public static function strip_html_and_whitespace($s) { return self::fix_whitespace(self::strip_html($s)); } /** * @param $s * @return string */ public static function quote_html($s) { return htmlentities($s); } /** * @param $s * @return string */ public static function fix_whitespace($s) { return trim(preg_replace('/\s+/', ' ', $s)); } } |