+interface ProfileSetting
+{
+ /** Get a field and a value, check that the given value is
+ * valid, if not, return a corrected value. If no valid value can be
+ * computed from the input data, the success flag is set to false.
+ *
+ * If value is null, the default value should be returned.
+ * TODO: check this does not conflict with some possible values.
+ *
+ * Whatever happen, this function must always returns the function to
+ * show on the page to the user.
+ */
+ public function value(ProfilePage &$page, $field, $value, &$success);
+
+ /** Save the new value for the given field.
+ */
+ public function save(ProfilePage &$page, $field, $new_value);
+}
+
+abstract class ProfileNoSave implements ProfileSetting
+{
+ public function save(ProfilePage &$page, $field, $new_value) { }
+}
+
+class ProfileWeb extends ProfileNoSave
+{
+ public function value(ProfilePage &$page, $field, $value, &$success)
+ {
+ if (is_null($value)) {
+ return isset($page->values[$field]) ? $page->values[$field] : S::v($field);
+ }
+ $success = !trim($value) || preg_match("{^(https?|ftp)://[a-zA-Z0-9._%#+/?=&~-]+$}i", $value);
+ if (!$success) {
+ global $page;
+ $page->trig('URL Incorrecte : une url doit commencer par http:// ou https:// ou ftp://'
+ . ' et ne pas contenir de caractères interdits');
+ }
+ return $value;
+ }
+}
+
+class ProfileTel extends ProfileNoSave
+{
+ public function value(ProfilePage &$page, $field, $value, &$success)
+ {
+ if (is_null($value)) {
+ return isset($page->values[$field]) ? $page->values[$field] : S::v($field);
+ }
+ $success = !preg_match('/[<>{}@&#~\/:;?,!§*_`\[\]|%$^=]/', $value, $matches);
+ if (!$success) {
+ global $page;
+ $page->trig('Le numéro de téléphone contient un caractère interdit : ' . pl_entities($matches[0][0]));
+ }
+ return $value;
+ }
+}
+
+class ProfilePub extends ProfileNoSave
+{
+ public function value(ProfilePage &$page, $field, $value, &$success)
+ {
+ $success = true;
+ if (is_null($value)) {
+ return isset($page->values[$field]) ? $page->values[$field] : S::v($field);
+ }
+ if (is_null($value) || !$value) {
+ $value = 'private';
+ } else if ($value == 'on') { // Checkbox
+ $value = 'public';
+ }
+ return $value;
+ }
+}
+
+class ProfileBool extends ProfileNoSave
+{
+ public function value(ProfilePage &$page, $field, $value, &$success)
+ {
+ $success = true;
+ if (is_null($value)) {
+ $value = @$page->values[$field];
+ }
+ return $value ? 1 : 0;
+ }
+}
+
+abstract class ProfilePage implements PlWizardPage