PostNuke

Flexible Content Management System

News

Some suggestions...

Contributed by Thanks Phil, but you on Jul 17, 2001 - 12:02 AM





  • With CSS disable and images loading OFF, Post-Nuke is a bit less readable. I mean, it's not easy to see where the previous story end and where the new one start.



    Maybe a few extra blank lines or a <hr> separator would help ?




  • With images loading OFF, the layout is different (and sometimes look like a big mess). This is because there are missing WIDTH, HEIGHT and ALT attributes for the IMG element. Beside the aspect, rendering a page is slower too because the page has to be re-rendered each time a new image is loaded.



    IMHO, the WIDTH, HEIGHT and ALT attributes should ALWAYS be present.



    There are some case where the WIDTH and HEIGHT size cannot be determined at coding time. But here is a suggestion I made several time on PHP-Nuke.org to bypass this problem (I discussed this with hombergs on phpnuke.org's Bug Fix forum when it was alive).



    In mainfile.php, add this function:







    function GetImgTag($dir, $image, $alttext=" ", $border=0) {



      global $language;







      $path = "$dir/$language/$image";



      if (!file_exists($path)) {



        $path = "$dir/$image";



      }



      $size = GetImageSize ($path);







      $ImgTag = "<img src="$path"";



      if ($size[0]) {



        $ImgTag .= " width="$size[0]"";



      }



      if ($size[1]) {



        $ImgTag .= " height="$size[1]"";



      }



      $imgTag .= " alt="$alttext"";



      $ImgTag .= " border="$border"";



      $ImgTag .= ">";







      return($ImgTag);



    }







    Now, if you want to build a IMG tag but you don't know what the size of the image will be, you can just call the function like this:



    echo "...something..." . GetImgTag("PicDir", "Image.png", "Alternative text") . "...something...";




  • To make sure the user name stored in the cookie is EXACTLY the same as stored in the users table (and thus, have a workaround for the savetheme problem); change in the user.php file, login() function, the lines:







      $result = mysql_query("select pass, uid, storynum, umode, uorder, thold, noscore, ublockon, theme, commentmax from users where uname='$uname'");







    by:







      $result = mysql_query("select pass, uid, uname, storynum, umode, uorder, thold, noscore, ublockon, theme, commentmax from users where uname='$uname'");







    and:







      docookie($setinfo[uid], $uname, $pass, $setinfo[storynum], $setinfo[umode], $setinfo[uorder], $setinfo[thold], $setinfo[noscore], $setinfo[ublockon], $setinfo[theme], $setinfo[commentmax]);







    by:







      docookie($setinfo[uid], $setinfo[uname], $pass, $setinfo[storynum], $setinfo[umode], $setinfo[uorder], $setinfo[thold], $setinfo[noscore], $setinfo[ublockon], $setinfo[theme], $setinfo[commentmax]);







  • In admin/modules/settings.php, the themes list is built using the following code:







      $handle=opendir('themes');



      while ($file = readdir($handle)) {



        if ( (!ereg("[.]",$file)) ) {



          $themelist .= "$file ";



        }



      }



      closedir($handle);







    assuming that anything in the themes/ directory that don't have a "." (dot) in its name IS a theme directory; which is bad, bad, bad !!!



    (Directories CAN have dots in their names, and files names CAN have no dots at all !)







    Someone told me that the is_file() and is_dir() PHP functions were not supported on Windows platforms.



    (Why aren't people definitively dropping Windoz ? ;-) )







    So, here is another solution:







      $handle=opendir('themes');



      while ($file = readdir($handle)) {



        if (!ereg("^[.]{1,2}$",$file)) {



          if ($test = @opendir("themes/$file")) {



            closedir($test);



            $themelist .= "$file ";



          }



        }



      }



      closedir($handle);







  • Since PHP-Nuke 5.0, a sumitted story is formatted with the nl2br() function. I don't think it's a good idea, especially when the story already contains HTML tags.



    I guess you've done that to find a solution for people who don't know about HTML and wish to have their stories published as they have submitted them ? Well, why not offer the choice then: submit as TEXT or HTML (with TEXT being default).



    For text stories, use the PRE element to keep them as is.



    As for comments, IMHO:



     - exttrans should keep HREF links as is, convert any conformant URL (starting with the protocol !!!) to link too, ignore (STRIP) any other HTML tags, THEN apply the nl2br() function.



     - plaintext should be just that, no HTML interpretation (so apply the htmlspecialchars() function here, not in exttrans); use the PRE element.



     - html: well, allowed HTML.




  • The 'lang' cookie (Haa, that awful annoying cookie...) ;-)



    Please drop that lang cookie; there's already too much cookies floating around, and this one is not always very usefull (Try to login WITHOUT the lang cookie...).



    I personnally find it very annoying to have to tell my browser: "No, I don't want this cookie" for each page I load, whereas the default language of a site suit my needs.



    IMHO, the language selection should be a feature offered to registered users only. The prefered language of a user should be a field in the user cookie (yet another good reason to register!), and this will be set only ONCE at loggin time, or when the user decide to change his preferences. No needs for another cookie.



    Now, here is how PHP-Nuke should check for the user's prefered language: for each HTTP request,



     - check from the user cookie if a lang is set and use it



     - IF NOT, check if the browser has sent a lang preference in the HTTP header, and use that



     - IF NOT, use the default language for the site.







    Ok, I guess it's easier to say it than to do it; so I'll try to provide an alternative for a better language auto-selection. Here is the idea (not tested, I'm writing this as I think about it).



    In mainfile.php, replace:







      if (isset($newlang)) {



        if (file_exists("language/lang-$newlang.php")) {



        setcookie("lang",$newlang,time()+31536000);



        include("language/lang-$newlang.php");



        } else {



        setcookie("lang",$language,time()+31536000);



        include("language/lang-$language.php");



        }



      } elseif (isset($lang)) {



        include("language/lang-$lang.php");



      } else {



        setcookie("lang",$language,time()+31536000);



        include("language/lang-$language.php");



      }







    by:







      if (!SetUserLang()) {



        if (!SetNavLang()) {



          include("language/lang-$language.php");



        }



      }







    (and bye bye the 'lang' cookie... hurray !!!) ;-)







    Now, add these functions to mainfile.php (or functions.php ?):







      function SetUserLang() {



        $usercookie = $HTTP_COOKIE_VARS["user"];



        if ($usercookie != "") {



          $usercookie = base64_decode($usercookie);



          $usercookie = explode(":", $usercookie);



          $userlang = $usercookie[10];



          if ($userlang != "") {



            if (file_exists("language/lang-$userlang.php")) {



              include("language/lang-$userlang.php");



              return TRUE;



            }



          }



        }



        return FALSE;



      }



     



      function SetNavLang() {



        $navlang = getenv("HTTP_ACCEPT_LANGUAGE");



        if ($navlang != "") {



          $navlang = explode(",", $navlang);



          for ($i=0; $i < sizeof($navlang); $i++) {



            $tmplang = ltrim($navlang[$i]);



            if ((eregi("^en", $tmplang)) AND (file_exists("language/lang-english.php"))) {



              include("language/lang-english.php");



              return TRUE;



            }



            elseif ((eregi("^fr", $tmplang)) AND (file_exists("language/lang-french.php"))) {



              include("language/lang-french.php");



              return TRUE;



            }



            elseif ((eregi("^de", $tmplang)) AND (file_exists("language/lang-german.php"))) {



              include("language/lang-german.php");



              return TRUE;



            }



            elseif ((eregi("^es", $tmplang)) AND (file_exists("language/lang-spanish.php"))) {



              include("language/lang-spanish.php");



              return TRUE;



            }



            elseif ((eregi("^nl", $tmplang)) AND (file_exists("language/lang-dutch.php"))) {



              include("language/lang-dutch.php");



              return TRUE;



            }



            elseif ((eregi("^it", $tmplang)) AND (file_exists("language/lang-italian.php"))) {



              include("language/lang-italian.php");



              return TRUE;



            }



            elseif ((eregi("^pt-br", $tmplang)) AND (file_exists("language/lang-brasilian.php"))) {



              include("language/lang-brasilian.php");



              return TRUE;



            }



            elseif ((eregi("^pt", $tmplang)) AND (file_exists("language/lang-portuguese.php"))) {



              include("language/lang-portuguese.php");



              return TRUE;



            }



            elseif ((eregi("^no", $tmplang)) AND (file_exists("language/lang-norwegian.php"))) {



              include("language/lang-norwegian.php");



              return TRUE;



            }



            elseif ((eregi("^da", $tmplang)) AND (file_exists("language/lang-danish.php"))) {



              include("language/lang-danish.php");



              return TRUE;



            }



            elseif ((eregi("^sv", $tmplang)) AND (file_exists("language/lang-swedish.php"))) {



              include("language/lang-swedish.php");



              return TRUE;



            }



            /* And so on for other languages available... */



          }



        }



        return FALSE;



      }







    Last, you can now drop the old interface language selection, and offer something else to registered users (Eg.: in the user's preference page). This time not creating a 'lang' cookie, but setting a new 'prefered language' field in the 'user' cookie (from this example code, it could be the 10th field in the 'user' cookie).







Off-topic note: Has anyone tried MakeLang on Post-Nuke yet ? How does it work ?











AmigaPhil at ping.be







1190