[mod] Redirect to Custom User Pages & Bilingual Mailing List

3rd party code for phpList

[mod] Redirect to Custom User Pages & Bilingual Mailing List

Postby gibble » 12:40pm, Mon 29 Jun, 2009

I needed to custom pretty much all of the user pages, so that they would work with a site that I have, I also needed to add bilingual support so that we could manage both our english and french users - to do this I wrote a little frontend of sorts, I figured I'd share it in case some people had similar requirements, or wanted to see how I set up the custom pages - we also changed some functionality - particularly with the user preference page - and for our set up we did not want the 'blacklisting' so I didn't really implement that - although I'm sure anyone who uses this won't have a problem adding it :P

Misc Changes

FILE: ../index.php and ../admin/subscribelib2.php

LINES: 14 to 28 (index.php) and 6 to 18 (subscribelin2.php)
CHANGES:
Add these lines after '$_SERVER = removeXss($_SERVER);'
Code: Select all
      //FRONTEND START
      if (!$_SERVER['REDIRECT_URL'])
      {
         if ($_REQUEST['lang'] == 'fra')
         {
            $_SERVER['REDIRECT_URL'] = '/fra';
         }
         else
         {
            $_SERVER['REDIRECT_URL'] = '/eng';
         }
      }

      $URL_TO_FRONTEND = $_SERVER['SERVER_NAME'].$_SERVER['REDIRECT_URL']; //Custom URL to redirect to for the FRONTEND
      //FRONTEND STOP

NOTES: this provides basic language awareness, and makes the header redirects easier to change if needed

LINES: *At the beginning of each function in both files*
CHANGES:
Add $URL_TO_FRONTEND to each functions global variables (7 times total)
ex:
Code: Select all
global $tables;
            global $URL_TO_FRONTEND;


FILE: phplist_fe.inc

LINES: 357 and 449
CHANGES:
Just make sure that the form action is pointing to the correct location (should be pointing to index.php) in both functions


Custom "Request Preferences" Page

FILE: ../index.php

LINES: 345 to 364
CHANGES:
Above "return $html" set $html equal to a header redirect and add
Code: Select all
         // Custom FRONTEND code starts
         $get='';

         if ($_REQUEST['message'])
         {
            $get.= '&message='.$_REQUEST['message'];
         }

         if ($_REQUEST['uid'])
         {
            $get.= '&uid='.$_REQUEST['uid'];
         }

         if ($_REQUEST['lang'])
         {
            $get.= '&lang='.$_REQUEST['lang'];
         }

         $html = header("Location: http://".$URL_TO_FRONTEND."?p=preferences".$get);
         // FRONTEND code ends


Custom "Preferences" Page

FILE: ../index.php

LINES: 439 to 453
CHANGES:
Above "return $html" set $html equal to a header redirect and add
Code: Select all
         //Custom FRONTEND code starts
         $get='';

         if ($_REQUEST['uid'])
         {
            $get.= '&uid='.$_REQUEST['uid'];
         }

         if ($_REQUEST['lang'])
         {
            $get.= '&lang='.$_REQUEST['lang'];
         }

         $html = header("Location: http://".$URL_TO_FRONTEND."?p=preferences".$get);
         //FRONTEND code ends


Create a Custom Subscribe Page

FILE: ../index.php

LINES: 581 to 603
CHANGES:
Add a header redirect and a few extra lines to preserve some data
Code: Select all
            //FRONTEND START
            if ($_REQUEST['p'] || $_REQUEST['list_id'] || $_REQUEST['id'])
            {
               $get = '?';
               $and = '';
               if ($_REQUEST['p'])
               {
                  $get.= 'p='.$_REQUEST['p'];
                  $and = '&';
               }
               if ($_REQUEST['list_id'])
               {
                  $get.= 'list_id='.$_REQUEST['list_id'];
                  $and = '&';
               }
               if ($_REQUEST['id'])
               {
                  $get.= $and.'id='.$_REQUEST['id'];
               }
            }

            $html = header("Location: http://".$URL_TO_FRONTEND.$get);
            //FRONTEND STOP


Custom "Confirmed" Page

FILE: ../index.php

LINES: 662-670
CHANGES:
right before the "return $res" set $res equal to a header redirect and add
Code: Select all
         //Custom FRONTEND code starts
         $get ='';
         if ($_REQUEST['lang'])
         {
            $get.= '&lang='.$_REQUEST['lang'];
         }

         $res = header("Location: http://".$URL_TO_FRONTEND."?p=confirmed".$get);
         //FRONTEND code ends


Custom "User Not Found" Page

FILE: ../index.php

LINES: 742 TO 751
CHANGES:
Above "logEvent(..." and inside the 'else {' set $res equal to a header redirect and add
Code: Select all
         //Custom FRONTEND code starts

         $get ='';
           if ($_REQUEST['lang'])
           {
            $get.= '&lang='.$_REQUEST['lang'];
           }

         $res = header("Location: http://".$URL_TO_FRONTEND."?p=no_user".$get);
         //FRONTEND code ends


Custom "Unsubscribe Successful" Page

FILE: ../index.php

LINES: 770 to 777
CHANGES:
right before the "return $res" inside the if ($userid) add
Code: Select all
         $get ='';
         if ($_REQUEST['lang'])
         {
            $get.= '&lang='.$_REQUEST['lang'];
         }

         $res = header("Location: http://".$$URL_TO_FRONTEND."?p=bl_success".$get); //Custome FRONTEND

NOTES: Make sure to change $res to the header redirect


Custom "Unsubscribe" Page

FILE: ../index.php

LINES: 866 to 874
CHANGES:
right before the "return $res" at the end of the 'unsubscribePage' function add
Code: Select all
         //Custom FRONTEND code starts
         $get ='';
         if ($_REQUEST['lang'])
         {
            get.= '&lang='.$_REQUEST['lang'];
         }

         $res = header("Location: http://".$URL_TO_FRONTEND."?p=blacklist".$get);
         //FRONTEND code ends


LINES: 812 to 821
CHANGES:
right before the "return $res" inside the if (!$email) add
Code: Select all
         //Custom FRONTEND code starts

         $get ='';
           if ($_REQUEST['lang'])
           {
            $get.= '&lang='.$_REQUEST['lang'];
           }

         $res = header("Location: http://".$URL_TO_FRONTEND."?p=blacklist".$get);
         //FRONTEND code ends


NOTES: Make sure to change $res to the header redirect


Custom "Thank You Page"

FILE: ../admin/subscribelib2.php

LINES: 352 and 355
CHANGES:
Set $thankyoupage equal to a header redirect

ex:
Code: Select all
$thankyoupage = header("Location: http://".$URL_TO_FRONTEND."?p=thankyou&lang=".$_REQUEST['lang']);


Do this for both instances


Modifie the admin tools to support the bilingual mailing lists and improve usability

FILE: ../admin/editlist.php

LINES: 54 to 76
CHANGES:
Replace the inside of the 'else {...}' with
Code: Select all
         //mod begins
         // gets the max id for the lists
         $id_offset_sql = 'SELECT MAX(id) as maxid FROM '.$tables["list"];
         $id_offset_results = Sql_Query($id_offset_sql);
         $id_offset_data = Sql_fetch_array($id_offset_results);
         $id_offset = $id_offset_data['maxid'];

         // gets the max id for the subscription pages
         $sid_offset_sql = 'SELECT MAX(id) as maxid FROM '.$tables["subscribepage_data"];
         $sid_offset_results = Sql_Query($sid_offset_sql);
         $sid_offset_data = Sql_fetch_array($sid_offset_results);
         $sid_offset = $sid_offset_data['maxid'];

         //inserts the new list (enlgish)
         $query = sprintf('insert into %s
           (name,description,language,alt_list,entered,listorder,owner,prefix,rssfeed,active)
           values("%s","%s","eng",%d,now(),%d,%d,"%s","%s",%d)',
           $tables["list"],addslashes($_POST["listname"]),addslashes($_POST["description"]),$id_offset+2,
           $_POST["listorder"],$_POST["owner"],$_POST["prefix"],$_POST["rssfeed"],$_POST["active"]);
           //this adds the english subscription page
         Sql_Query(sprintf('insert into %s (title,owner) values("%s",%d)',
           $tables["subscribepage"],$_POST["listname"],1));
           //this sets the english subscription page title
         Sql_Query(sprintf('insert into %s (id,name,data) values(%d,"title","%s")',
           $tables["subscribepage_data"],$sid_offset+1,$_POST["listname"]));
           //this sets the list the subscription page is linked to
         Sql_Query(sprintf('insert into %s (id,name,data) values(%d,"lists",%d)',
           $tables["subscribepage_data"],$sid_offset+1,$id_offset+1));

         // inserts the new list (french)
         $query_f = sprintf('insert into %s
           (name,description,language,alt_list,entered,listorder,owner,prefix,rssfeed,active)
           values("%s","%s","fra",%d,now(),%d,%d,"%s","%s",%d)',
           $tables["list"],addslashes($_POST["flistname"]),addslashes($_POST["fdescription"]),$id_offset+1,
           $_POST["listorder"],$_POST["owner"],$_POST["prefix"],$_POST["rssfeed"],$_POST["active"]);
           // adds the french subscription page
           Sql_Query(sprintf('insert into %s (title,owner) values("%s",%d)',
           $tables["subscribepage"],$_POST["flistname"],1));
           // adds the title to the french subscription page
           Sql_Query(sprintf('insert into %s (id,name,data) values(%d,"title","%s")',
           $tables["subscribepage_data"],$sid_offset+2,$_POST["flistname"]));
           // links the subscription page to the appropriate list
           Sql_Query(sprintf('insert into %s (id,name,data) values(%d,"lists",%d)',
           $tables["subscribepage_data"],$sid_offset+2,$id_offset+2));
         //mod ends


LINES: 79
CHANGES:
Add this line after '$result = Sql_Query($query);'
Code: Select all
         $result_f = Sql_Query($query_f);


NOTES: For these mods to work (specifically the bilingual aspects) I added two fields to the table phplist_list, language - which takes enum values 'eng' or 'fra', and alt_list - which takes the id of the alternate language list ex: if list 1 is english, and list 2 is french then list 2's alt_list would be 1, and list 1's alt_list would be 2


note's about the frontend

the text() function is a function that decides which language to print - you'll probably need to replace all instances of these, LG is a variable for language (eng or fra) - you'll probably need to change that too, $_REQUEST['language'] is the same - also I didn't do this with OO in mind since most of our setup isn't written with OO in mind, (actually phplist is problably the most OO program we've got :P) and I'm sure there are better ways to do some of the things I've done - I appreciate all C&C so let me know :D

Once all the changes that you need to make this work on your setup you should only need to require_once('phplist.php') and that should take care of almost anything
Attachments
PHPList User Frontend.zip
a zip file containing the frontend and a copy of the notes I posted
(6.54 KiB) Downloaded 305 times
gibble
phpList newbie
 
Posts: 4
Joined: 1:40pm, Tue 09 Jun, 2009

Re: Redirect to Custom User Pages and Bilingual Mailing List

Postby carol » 2:41pm, Mon 29 Jun, 2009

Thanks for sharing! :D
carol
PL Geek
 
Posts: 138
Joined: 12:57pm, Wed 28 Jan, 2009
Location: São Paulo, Brasil

Re: [mod] Redirect to Custom User Pages & Bilingual Mailing List

Postby sol001 » 12:13pm, Tue 08 Sep, 2009

Hi

Thanks for posting your hard work on here. I have a question I hope you can help me with - I posted it on the other topic (don't want to post it twice....):

http://forums.phplist.com/viewtopic.php?f=6&t=8940&p=67896#p67896

your help would be GREATLY appreciated.

Thanks
Sol
sol001
PL Nut
 
Posts: 18
Joined: 9:20am, Fri 22 Feb, 2008

Re: [mod] Redirect to Custom User Pages & Bilingual Mailing List

Postby stacef » 9:41pm, Sun 22 Nov, 2009

I've posted a fairly detailed explanation of how I customized my PHPList installation over here:

http://forums.phplist.com/viewtopic.php?f=6&t=29269

Please check it out; I'd love the feedback.

Thanks,
Stace
stacef
phpLister
 
Posts: 9
Joined: 10:02pm, Wed 16 Sep, 2009


Return to Contributions: Plug-ins, Add-ons, Mods

Who is online

Users browsing this forum: No registered users and 2 guests