+class ProfileEmailDirectory implements ProfileSetting
+{
+ private $email;
+
+ public function __construct()
+ {
+ }
+
+ public function value(ProfilePage &$page, $field, $value, &$success)
+ {
+ $p = $page;
+ global $page;
+
+ $success = true;
+ if (!is_null($value)) {
+ $email_stripped = strtolower(trim($value));
+ if ((!isvalid_email($email_stripped)) && ($email_stripped) && ($p->values['email_directory'] == "new@new.new")) {
+ $page->assign('email_error', '1');
+ $page->assign('email_directory_error', $email_stripped);
+ $page->trigError('Adresse Email invalide');
+ $success = false;
+ } else {
+ $page->assign('email_error', '0');
+ }
+ }
+ return $value;
+ }
+
+ public function save(ProfilePage &$page, $field, $value)
+ {
+ }
+}
+
+class ProfileNetworking implements ProfileSetting
+{
+ private $email;
+ private $pub;
+ private $web;
+ private $number;
+
+ public function __construct()
+ {
+ $this->email = new ProfileEmail();
+ $this->pub = new ProfilePub();
+ $this->web = new ProfileWeb();
+ $this->number = new ProfileNumber();
+ }
+
+ public function value(ProfilePage &$page, $field, $value, &$success)
+ {
+ if (is_null($value)) {
+ $value = array();
+ $res = XDB::iterator("SELECT n.address, n.network_type AS type, n.pub, m.name
+ FROM profile_networking AS n
+ INNER JOIN profile_networking_enum AS m ON (n.network_type = m.network_type)
+ WHERE n.uid = {?}",
+ S::i('uid'));
+ while($network = $res->next()) {
+ $value[] = $network;
+ }
+ }
+ if (!is_array($value)) {
+ $value = array();
+ }
+ $res = XDB::iterator("SELECT filter, network_type AS type
+ FROM profile_networking_enum;");
+ $filters = array();
+ while($filter = $res->next()) {
+ $filters[$filter['type']] = $filter['filter'];
+ }
+ $success = true;
+ foreach($value as $i=>&$network) {
+ if (!trim($network['address'])) {
+ unset($value[$i]);
+ } else {
+ if (!isset($network['pub'])) {
+ $network['pub'] = 'private';
+ }
+ $network['error'] = false;
+ $network['pub'] = $this->pub->value($page, 'pub', $network['pub'], $s);
+ $s = true;
+ if ($filters[$network['type']] == 'web') {
+ $network['address'] = $this->web->value($page, 'address', $network['address'], $s);
+ } elseif ($filters[$network['type']] == 'email') {
+ $network['address'] = $this->email->value($page, 'address', $network['address'], $s);
+ } elseif ($filters[$network['type']] == 'number') {
+ $network['address'] = $this->number->value($page, 'address', $network['address'], $s);
+ }
+ if (!$s) {
+ $success = false;
+ $network['error'] = true;
+ }
+ }
+ }
+ return $value;
+ }
+
+ public function save(ProfilePage &$page, $field, $value)
+ {
+ XDB::execute("DELETE FROM profile_networking
+ WHERE uid = {?}",
+ S::i('uid'));
+ if (!count($value)) {
+ return;
+ }
+ $insert = array();
+ foreach ($value as $id=>$network) {
+ XDB::execute("INSERT INTO profile_networking (uid, nwid, network_type, address, pub)
+ VALUES ({?}, {?}, {?}, {?}, {?})",
+ S::i('uid'), $id, $network['type'], $network['address'], $network['pub']);
+ }
+ }
+}
+