+ /**
+ * Prepare page to run
+ *
+ *
+ * @param $args
+ * @return string title
+ */
+
+ function prepare($args)
+ {
+ parent::prepare($args);
+ $this->code = $this->trimmed('code');
+
+ if (empty($this->code)) {
+ common_ensure_session();
+ if (array_key_exists('invitecode', $_SESSION)) {
+ $this->code = $_SESSION['invitecode'];
+ }
+ }
+
+ if (common_config('site', 'inviteonly') && empty($this->code)) {
+ $this->clientError(_('Sorry, only invited people can register.'));
+ return false;
+ }
+
+ if (!empty($this->code)) {
+ $this->invite = Invitation::staticGet('code', $this->code);
+ if (empty($this->invite)) {
+ $this->clientError(_('Sorry, invalid invitation code.'));
+ return false;
+ }
+ // Store this in case we need it
+ common_ensure_session();
+ $_SESSION['invitecode'] = $this->code;
+ }
+
+ return true;
+ }
+