bug #459, optin pour NL/ML promo a l'inscription
[platal.git] / modules / profile.php
index 6e8479f..795c99d 100644 (file)
@@ -190,6 +190,8 @@ class ProfileModule extends PLModule
 
         $new   = Env::v('modif') == 'new';
         $user  = get_user_details($login, S::v('uid'), $view);
+        $user['freetext'] = preg_replace('/((?:https?|ftp):\/\/(?:&|\.*,*[a-z@0-9~%$£µ&i#\-+=_\/\?])*)/i',
+                                         '<a href="\\0">\\0</a>', $user['freetext']);
         $title = $user['prenom'] . ' ' . empty($user['nom_usage']) ? $user['nom'] : $user['nom_usage'];
         $page->assign('xorg_title', $title);
 
@@ -251,12 +253,27 @@ class ProfileModule extends PLModule
         require_once 'profil.func.inc.php';
         require_once 'synchro_ax.inc.php';
 
-        if (Post::has('register_from_ax_question')) {
-            XDB::query('UPDATE auth_user_quick
+        if (Post::v('register_from_ax_question')) {
+            XDB::execute('UPDATE auth_user_quick
                                      SET profile_from_ax = 1
                                    WHERE user_id = {?}',
                                  S::v('uid'));
         }
+        if (Post::v('add_to_nl')) {
+            require_once 'newsletter.inc.php';
+            subscribe_nl();
+        }
+        if (Post::v('add_to_promo')) {
+            $r = XDB::query('SELECT id FROM groupex.asso WHERE diminutif = {?}',
+                S::v('promo'));
+            $asso_id = $r->fetchOneCell();
+            XDB::execute('REPLACE INTO groupex.membres (uid,asso_id)
+                                     VALUES ({?}, {?})',
+                                 S::v('uid'), $asso_id);
+            require_once 'lists.inc.php';
+            $client =& lists_xmlrpc(S::v('uid'), S::v('password'));
+            $client->subscribe("promo".S::v('promo'));
+        }
 
         if (is_ax_key_missing()) {
             $page->assign('no_private_key', true);
@@ -649,8 +666,15 @@ class ProfileModule extends PLModule
         $adr = trim($adr1);
         $adr = trim("$adr\n$adr2");
         $adr = trim("$adr\n$adr3");
-        $adr = explode("\n", quoted_printable_encode(";;$adr;$city;$region;$postcode;$country"));
-        return implode("\n", array_map('trim', $adr));
+        return $this->quoted_printable_encode(";;$adr;$city;$region;$postcode;$country");
+    }
+
+    function quoted_printable_encode($text)
+    {
+        return implode("\n", 
+                       array_map('trim',
+                                 explode("\n", 
+                                         quoted_printable_encode($text))));
     }
 
     function handler_vcard(&$page, $x = null)
@@ -669,11 +693,15 @@ class ProfileModule extends PLModule
         require_once 'xorg.misc.inc.php';
         require_once 'user.func.inc.php';
 
-        $page->register_modifier('qp_enc', 'quoted_printable_encode');
+        $page->register_modifier('qp_enc', array($this, 'quoted_printable_encode'));
         $page->register_function('format_adr', array($this, 'format_adr'));
 
         $login = get_user_forlife($x);
         $user  = get_user_details($login);
+        
+        if (strlen(trim($user['freetext']))) {
+            $user['freetext'] = html_entity_decode($user['freetext']);
+        }
 
         // alias virtual
         $res = XDB::query(
@@ -688,7 +716,16 @@ class ProfileModule extends PLModule
                 $user['forlife'].'@'.$globals->mail->domain2);
 
         $user['virtualalias'] = $res->fetchOneCell();
-
+        
+        // get photo
+        $res = XDB::query(
+                "SELECT attach
+                   FROM photo   AS p
+             INNER JOIN aliases AS a ON (a.id = p.uid AND a.type = 'a_vie')
+                  WHERE a.alias = {?}", $login);
+        if ($res->numRows()) {
+            $user['photo'] = $res->fetchOneCell();
+        }
         $page->assign_by_ref('vcard', $user);
 
         header("Pragma: ");