/** * Produce a basic FormStorage implementation from a classic storage string * @param string $value A classic storage string, such as "option:someoption" or "user:age" * @return ControlStorage An instance of an object that will save and load to the indicated location */ public static function from_storage_string($value) { $storage = explode(':', $value, 2); switch (count($storage)) { case 2: list($type, $location) = $storage; break; case 1: list($location) = $storage; $type = 'option'; break; default: // @todo Figure this case out $location = '__'; $type = '__'; break; } switch ($type) { case 'user': $loader = function ($name) { return User::identify()->info->{$name}; }; $saver = function ($name, $value) { User::identify()->info->{$name} = $value; Session::queue(User::identify()); }; break; case 'option': $loader = function ($name) use($location) { return Options::get($location); }; $saver = function ($name, $value) use($location) { Options::set($location, $value); }; break; case 'action': $loader = function ($name) use($location) { return Plugins::filter($location, '', $name, false); }; $saver = function ($name, $value) use($location) { Plugins::act($location, $value, $name, true); }; break; case 'session': $loader = function ($name) use($location) { $session_set = Session::get_set($location, false); if (isset($session_set[$name])) { return $session_set[$name]; } return null; }; $saver = function ($name, $value) use($location) { Session::add_to_set($location, $value, $name); }; break; default: $loader = function () { }; $saver = function () { }; break; } return new ControlStorage($loader, $saver); }
/** * Saves form fields that are tied to this block. Implements FormStorage. * * @param string $key The name of the form field to store. * @param mixed $value The value of the form field */ public function field_save($key, $value) { $this->{$key} = $value; Session::queue($this); }
/** * Stores a form value into the object * * @param string $key The name of a form component that will be stored * @param mixed $value The value of the form component to store */ function field_save($key, $value) { $default_fields = self::default_fields(); if (isset($default_fields[$key])) { $this->{$key} = $value; } else { $this->info->{$key} = $value; } $self = $this; Session::queue(function () use($self) { if ($self->id == 0) { $self->insert(); } else { $self->update(); } }, $this); }
/** * Stores a form value into this post's info records * * @param string $key The name of a form component that will be stored * @param mixed $value The value of the form component to store */ public function field_save($key, $value) { $field_value = Plugins::filter('post_field_save', $value, $key); $default_fields = self::default_fields(); if (isset($default_fields[$key])) { $this->{$key} = $field_value; } else { $this->info->{$key} = $field_value; } $self = $this; Session::queue(function () use($self) { if ($self->id == 0) { $self->insert(); } else { $self->update(); } }, $this); }