public function GET($verb, $args) { // return random question if ($verb == 'random') { $artwork = new Artwork(); $rand = rand(0, 1); switch ($rand) { case 0: return $this->xmlToJson($artwork->GET("year", $args)); case 1: return $this->xmlToJson($artwork->GET("name", $args)); } } return; }
function create($desc) { extract($desc); // crazy non-generic hack if ($table == 'savedartwork') { Artwork::store_artwork_by_id($values['artworkid']); } if (!ctype_alpha2($table)) { throw new Error("Possible hack attempt 9"); } $sql = "INSERT INTO {$table} "; $valuesSql = array(); $values['created'] = time(); $values['modified'] = time(); $columns = implode(', ', array_keys($values)); foreach ($values as $key => $value) { if (!ctype_alpha2(str_replace(array('_', '.'), '', $key))) { throw new Error("Possible hack attempt 10"); } if (is_string($value)) { $value = "'" . mysql_escape_string($value) . "'"; } $value = str_replace("\\'", "''", $value); if ($key == 'setnote' || $key == 'title') { $value = strip_tags($value); } $valuesSql[] = $value; } $valuesClause = implode(', ', $valuesSql); $sql .= "({$columns}) VALUES ({$valuesClause})"; $query = $this->server->moma->query($sql); return $query->insertId; }
public function receive() { extract($_REQUEST); $f = fopen(dirname(__FILE__) . "/sms.log", "a"); fwrite($f, "[RECEIVE]\n"); fwrite($f, "Phone: {$phone}\n"); fwrite($f, "Message: {$msg}\n"); fwrite($f, "Action: {$action}\n"); fwrite($f, "=====\n\n"); fflush($f); fclose($f); $artworkid = trim($msg); Artwork::store_artwork_by_id($artworkid); $artwork = $this->server->moma->load("artwork({$artworkid})"); if ($artwork) { list($user, $new) = $this->userByPhone($phone); extract($user); $userid = $id; $args = compact('userid', 'artworkid'); $count = $this->server->moma->value("SELECT COUNT(*) FROM savedartwork WHERE userid=:userid AND artworkid=:artworkid", $args); if ($count == 0) { $savedartwork = new SavedArtWork_Object(); $savedartwork->set(compact('userid', 'artworkid')); $this->server->moma->save($savedartwork); } $artwork = $artwork->get(); $title = $artwork['title']; if (!$dontremind) { $updateuser = new User_Object(); $updateuser->set($user); $updateuser->set('dontremind', 1); $this->server->moma->save($updateuser); if ($username == '') { sendsms($normalized_phone, "Hey there. '{$title}' was just saved for you. Go to moma.org/txt to retrieve it and any other works you collect. See you there!"); } else { sendsms($normalized_phone, "Hey {$username}. '{$title}' was added to your collection. You will find it and any other work you collect on moma.org. See you there!"); } } } else { sendsms($phone, "{$artworkid} does not refer to any item in our database. Please verify the number and try again."); } }
public function store_artwork_by_id($artworkid) { Artwork::store_artwork(file_get_contents("http://moma.org/explore/collection/objects/{$artworkid}.json")); }