message = trim($this->message); $timeSeparators = array(' in ',' at ',' on ',' tomorrow'); $seppos = -1; $sepposend = 0; $tomorrow = false; // find which separator is used foreach ($timeSeparators as $sep) { $offset = 0; // find the last use of this separator while (($thisseppos = strpos($this->message,$sep,$offset)) !== false) { $offset = $thisseppos+1; } $thisseppos = $offset-1; // is this the separator? if ($thisseppos > $seppos) { $seppos = $thisseppos; $sepposend = $seppos + strlen($sep); if ($sep == ' tomorrow') { $tomorrow = true; } } } $message = substr($this->message,0,$seppos); $timestring = substr($this->message,$sepposend); // expand 'a' and 'p' to 'am' and 'pm', respectively $timestring = str_replace(array('a ','p '),array('am ','pm '),$timestring); $timestring = preg_replace('/a$/','am',$timestring); $timestring = preg_replace('/p$/','pm',$timestring); if ($tomorrow && $timestring == '') { // if time is "tomorrow", add what time $utctime = strtotime('tomorrow '.date('H:i:s')); } elseif (in_array(strtolower($timestring),array('sun','mon','tues','wed','thurs','thu','fri','sat','sunday','monday','tuesday','wednesday','thursday','friday','saturday'))) { // if the time is just a day of the week, add the time $utctime = strtotime(date('Y-m-d',strtotime($timestring)).' '.date('H:i:s')); } else { // fall back on php $utctime = strtotime($timestring); } if ($utctime < time()) { // obviously the user didn't mean sometime before now $utctime += 24*60*60; } $db = Database::singleton(); $query = "insert into ".Database::DBPREFIX."reminders set reminderdate='".addslashes(date('Y-m-d H:i:s',$utctime))."', message='".addslashes($message)."', fromaddress='".addslashes($this->from)."' "; $db->query($query); } } ?>