- parent::__construct($out);
-
- $this->action = $action;
- $this->content = $content;
- $this->inreplyto = $inreplyto;
- $this->lat = $lat;
- $this->lon = $lon;
- $this->location_id = $location_id;
- $this->location_ns = $location_ns;
-
- if ($user) {
- $this->user = $user;
+ parent::__construct($action);
+
+ // When creating a notice form we don't want to collide with
+ // possibly existing HTML elements, as naming conventions are similar.
+ $this->id_suffix = rand();
+
+ if (is_null($options)) {
+ $options = array();
+ }
+
+ $this->actionName = $action->trimmed('action');
+
+ $prefill = array('content', 'inreplyto', 'lat',
+ 'lon', 'location_id', 'location_ns',
+ 'to_group', 'to_profile', 'private');
+
+ foreach ($prefill as $fieldName) {
+ if (array_key_exists($fieldName, $options)) {
+ $this->$fieldName = $options[$fieldName];
+ }
+ }
+
+ // Prefill the profile if we're replying
+
+ if (empty($this->to_profile) &&
+ !empty($this->inreplyto)) {
+ $notice = Notice::getKV('id', $this->inreplyto);
+ if (!empty($notice)) {
+ $this->to_profile = $notice->getProfile();
+ }
+ }
+
+ if (array_key_exists('user', $options)) {
+ $this->user = $options['user'];