timezone) ? new \DateTimeImmutable($field->date, new \DateTimeZone($field->timezone)) : (new \DateTimeImmutable($field->date)); } else { // If $field is not an object, assume it's a plain, valid, string $field = new \DateTime($field); } if($field === false || $field->getTimestamp() <= 0) { // If field had data but is invalid DateTime or is 0000-00-00 00:00, set it to null. $field = null; } else { // If valid, return local timezone $field->setTimezone(new \DateTimeZone("Europe/Amsterdam")); } } } public function __construct($data) { $class = get_class($this); foreach($data as $key => $val) { if(property_exists($class, $key)) { $this->$key = is_string($val) ? stripslashes($val) : $val; } } } public function url_slug($text) { // Alles naar kleine letter $text = strtolower($text); // Vervang accent-tekens door niet-geaccentueerde versies // $text = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $text); $search = explode(",","ç,æ,œ,á,é,í,ó,ú,à,è,ì,ò,ù,ä,ë,ï,ö,ü,ÿ,â,ê,î,ô,û,å,e,i,ø,u"); $replace = explode(",","c,ae,oe,a,e,i,o,u,a,e,i,o,u,a,e,i,o,u,y,a,e,i,o,u,a,e,i,o,u"); $text = str_replace($search, $replace, $text); // Verwijder alle woorden van 3 letters, behalve BEL (BEL-combinatie etc) if(strlen($text) > 3) { $text = preg_replace('/\b(?!bel|fm|nh)([a-z]{1,3})\b/u', '', $text); } // Vervang alles dat niet een woord-karakter is (letter, cijfer), een streepje of spatie if(strlen($text) > 3) { $text = preg_replace('/[^\w_\-\s]/', '', $text); } // Reeksen van één of meer spaties / streepjes vervangen door een enkel streepje $text = preg_replace('/[\-\s]+/', '-', $text); // Verwijder alle witruimte / streepjes aan begin en eind return trim(strtolower($text), '-'); } }