public function setDate($val) { if ($val == "0000-00-00 in press") { //handle non dates $val = ""; } $this["published"] = trim($val) == "" ? "in press" : $val; //we can't really reliably determine this, we should also store it as text if (empty($val)) { return $this->published_at = null; } if (preg_match("/^\\d{4}\$/", $val)) { //strtotime can't handle YYYY $val = "Jan 1, " . $val; } $range = DateRange::parseString($val); if (isset($range)) { //try date range return $this->published_at = DTStore::date($range->getStartDate()); } else { if (strtotime($val) !== false) { //try regular parse return $this->published_at = DTStore::date(strtotime($val)); } else { if (preg_match("/(\\d{4})/", $val, $matches)) { //try just a year return $this->published_at = DTSTore::date(strtotime("Jan 1, " . $matches[1])); } else { return $this->published_at = null; } } } //give up }
/** @param twid the twitter id that should be assigned to the user @param tw_acc the access token. This must be stored in the appropriate session variable ([api_name]_oauth_access_token) to make TW requests on the provider side */ public function matchTWUser($twid, $tw_acc, $tw_sec) { $session = DTSession::sharedSession(); $session["twitter_oauth_access_token"] = $tw_acc; //this needs to happen before matchTWUser tries to make any calls $session["twitter_oauth_access_secret"] = $tw_sec; return $user = DTSSOUser::upsert($this->db->where("twitter_id='{$twid}'"), array("twitter_id" => $twid), array("created_at" => DTStore::now())); }