User Tools

Site Tools


programming:web:developer_tools

My SKELETON

Before reinventing the wheel

Content Management System (CMS)

Joomla! …because open source matters

Wiki

DokuWiki is a standards compliant, simple to use Wiki which does not need databases.

Development tools

Code Editor

Vim This is the Vi IMproved version of the well known VI programmer's editor distributed with most UNIX systems. (Debian: apt-get install vim)

Language Editor

For information on how to use the php gettext function, please go to melaxis.com website.

Below are the steps followed in order to make everything working:

apt-get upgrade
apt-get install aspell aspell-fr aspell-...
apt-get install locales
dpkg-reconfigure locales #And select what you need
locale -a # To see installed locales
apt-get install poedit #gettext catalog editor which scans PHP files and build translation files
apt-get install potool #A program to aid manipulation of gettext po files

You can use poedit through an SSH connection using the X redirection.

Country Flag

To use with the locales, people like flags. On Debian, it exist a package that provides all this flags:

apt-get install link-monitor-applet

which will provide in the /usr/share/link-monitor-applet/flags directory all flags in svg format.

Personally I prefer to have png files which are better supported by all navigators and for that you can use the svg2png.sh script below:

apt-get install librsvg2-bin

which provides the rsvg program.

To convert all this flags at once, you can use the small script below:

#!/bin/bash
 
resol=32
 
for svg in `ls ./svg`
do
     rsvg-convert -h "$resol" -w "$resol"  "svg/${svg}" -o "png/${svg}.$resol.png"
done

the tree structure in my case was:

sylvain:/usr/share/link-monitor-applet# tree -L 2
.
|-- flags
|   |-- png
|   |-- svg
|   `-- svg2png.sh

Firefox/Iceweasel

Internet Explorer (IE)

  • Debug Bar The DebugBar is FREE for personal use.

IE6 and IE7 Running on a Single Machine

Requirements

  • Base your web site with the IRO's skeleton which is available on SIRO2. (cp -pPr)
  • BE W3C COMPLIENT. Check with the W3C Validator! More validator are available in the W3C Tools section.
  • Try a validation on watchfire webXACT. (non-free since february 1st, 2008)
  • Complete at least CSS for screen and print. If you have enough time, please go ahead with others!
  • Use HTML entities for non-ascii chars!
  • Test your web site with:
    • Firefox
    • Safari
    • IE6
    • IE7
    • lynx

Skeleton File Structure

root@siro2:/# tree -L 3 /www/skeleton.irovision.ch/
/www/skeleton.irovision.ch/
|-- index.php -> skeleton/index.php
`-- skeleton
    |-- index.php
    |-- awstats -> /www/awstats/awstats/wwwroot/
    |-- img -> /www/img/
    |-- lib -> /www/lib/
    |-- locales -> /www/lib/locales/
    |-- metas
    |   |-- lib_metas.php -> /www/lib/lib_metas.php
    |   |-- metas.anotherSkeleton.php
    |   |-- metas.common.php
    |   |-- metas.main.php
    |   |-- metas.skeleton.php
    |-- page
    |   |-- anotherSkeleton.php
    |   |-- config.php
    |   |-- info.php
    |   |-- language.bck.php
    |   |-- language.php
    |   |-- lib_dbconnection.php -> /www/lib/lib_dbconnection.php
    |   |-- lib_functions.php -> /www/lib/lib_functions.php
    |   |-- lib_language.php -> /www/lib/lib_language.php
    |   |-- lib_validators.php -> /www/lib/lib_validators.php
    |   |-- main.php
    |   |-- menu.php
    |   |-- skeleton.php
    |-- profiles
    |   |-- core
    |   `-- profile
    |-- script
    |   |-- lib_menu.js -> /www/lib/lib_menu.js
    |   |-- script.anotherSkeleton.js
    |   |-- script.main.js
    |   |-- script.skeleton.js
    `-- style
        |-- screen-sw.css
        |-- screen-ws.css
        |-- style.all.css
        |-- style.aural.css
        |-- style.braille.css
        |-- style.handheld.css
        |-- style.print.css
        `-- style.screen.css

Some of this links (ln -s) are hard coded into the apache2 configuration files (e.g /etc/apache2/conf.d). Example:

root@proxy:/etc/apache2/conf.d# cat awstats
Alias /awstatsicons/ "/www/awstats/awstats/wwwroot/icon/"
Alias /awstats/js/ "/www/awstats/awstats/wwwroot/js/"
 
ScriptAlias /awstats/ "/www/awstats/awstats/wwwroot/cgi-bin/"
<Directory "/www/awstats/awstats/wwwroot/cgi-bin">
        AllowOverride None
        Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
</Directory>

Skeleton Files

Location: /www/skeleton.irovision.ch/skeleton

Index.php

Location: /www/skeleton.irovision.ch/skeleton

<?php
ob_start(); //Start stream buffering
 
require_once("page/config.php"); //include configuration file
require_once("page/lib_language.php"); //include languages functions
require_once("page/lib_validators.php"); //includs validators and more...
require_once("page/menu.php"); //inclusion du menu
 
$lInit=initializeLocales(DEFAULT_LANGUAGE);
 
$page="main";
$metas="metas.$page";
$func=NULL;
if(isset($_GET['page'])){
        //echo "Getting page ($_GET[page])...<br>";
        if(file_exists("page/$_GET[page].php")){
                //echo "existing page(page/$_GET[page].php)...<br>";
                $page=$_GET['page']; //What is the request?
        }
}
 
if(file_exists("metas/metas.$page.php")){
                $metas="metas.$page";
}
/*echo '<?xml version="1.0" encoding="ISO-8859-1"?>'; //Encoding*/
?>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
     "http://www.w3.org/TR/html4/strict.dtd">
<html lang="<?php echo getLanguage('en');?>">
<head profile="<?php echo HOST.'/profiles/core';?>">
        <?php require_once("metas/$metas.php");?>
</head>
 
<body>
        <noscript>
                <p>
                        <?php
                                echo _("WARNING: Your browser seems not able to hande javascript");
                        ?>
                        .
                </p>
        </noscript>
        <div id="topBar">
                <div id="title">
                </div>
        </div>
        <div id="leftSideBar">
                <div id="lang">
                        <?php
                                $flagSize=32;
                                $locales=array('en_US','fr_FR','de_DE');
                                echo localesForm("/index.php?page=language&amp;function=changeLanguage",$locales,$flagSize);
                        ?>
                </div>
                <div id="menu">
                        <?php
                                echo menuForm();
                        ?>
                </div>
                <div id="webmaster">
                <?
                        echo validators();
                ?>
                </div>
        </div>
        <div id="main">
                <?php
                        include("page/$page.php");
                ?>
        </div>
 
        <div id="rightSideBar">
                <div id="addons">
                <?php
                        if (isset($_SESSION['rightSideBarAddon'])){
                                include_once($_SESSION['rightSideBarAddon']);
                        }
 
                ?>
                </div>
                <div id="bottomBar">
                </div>
        </div>
        <!--<script type="text/javascript" src="/awstats/js/awstats_misc_tracker.js"></script>
        <noscript>
        <p>
        <img src="/awstats/js/awstats_misc_tracker.js?nojs=y" height="0" width="0" style="display: none" alt="Awstat Image">
        </p>
        </noscript>
        -->
</body>
</html>
<?php
        ob_end_flush(); //Send the stream at once to the browser client
?>

page

Location: /www/skeleton.irovision.ch/skeleton/page

config.php

Location: /www/skeleton.irovision.ch/skeleton/page

<?php
session_start();
//clear everythings that are in the rightSideBar addon div
unset($_SESSION['rightSideBarAddon']);
 
$lInit=false;
 
$protocol="http";
//$sprotocol="https";
$sprotocol="https";
//print_r($_SERVER);
if(isset($_SESSION["id_author"])) $protocol=$sprotocol;
 
if (isset($_SERVER['HTTP_HOST'])){
        define("FQDN","skeleton.irovision.ch");
        //define("FQDN",$_SERVER['HTTP_HOST']);
        define("HOST",$protocol."://".FQDN);
        define("SHOST",$sprotocol."://".FQDN);
}else{
        define("FQDN","skeleton.irovision.ch");
        define("HOST",$protocol."://".FQDN);
        define("SHOST",$sprotocol."://".FQDN);
}
 
define("DB_HOST","localhost");
define("DB_USER" ,"dbskeleton");
define("DB_PWD","dbskeletonpw");
 
define("DB_COMMON","skeleton_common");
 
define("EMAIL_ADDRESS","it@irovision.ch");
 
define("DEFAULT_LANGUAGE","en_US");
 
//AFTER THE PHP END TAG THEY SHOULD NOT BE ANY MORE CARRIEGE RETURN
//otherwise they would be supplementary CR in the javascript response.text
?>

Location: /www/skeleton.irovision.ch/skeleton/page

<?php
require_once("config.php");
require_once("lib_language.php");
 
function getMenuForm(){
        echo menuForm();
}
 
function menuForm(){
//print_r($_SERVER);
                $tabindex=0;
                $language=getLanguage(DEFAULT_LANGUAGE);
 
                $str="";
                $str.='<div class="unorderedList">';
                $str.='<a ';
                $str.='name="Home" ';
                $str.='href="'.HOST.'/index.php" ';
                $str.='hreflang="'.$language.'" ';
                $tabindex++;
                $str.='tabindex="'.$tabindex.'"';
                $str.='>';
                $str.=_('Home');
                $str.='</a>';
                $str.='</div>';
        /*
                if($_SESSION["id_author"]) {
                        $str.='<div ';
                        $str.='class="unorderedList" ';
                        $str.='onclick="selectMenu(\'register\',\'getGetMyCard\'); return false;" ';
                        $str.='onkeypress="selectMenu(\'register\',\'getGetMyCard\'); return false;" ';
                        $str.='>';
                        $str.='<a ';
                        $str.='name="Card" ';
                        $str.='href="'.SHOST.'/index.php?page=register&amp;function=getGetMyCard" ';
                        $str.='hreflang="'.$language.'" ';
                        $tabindex++;
                        $str.='tabindex="'.$tabindex.'"';
                        $str.='>';
                        $str.=_('My Account');
                        $str.='</a>';
                        $str.='</div>';
                }else{
                        $str.='<div ';
                        $str.='class="unorderedList" ';
                        $str.='>';
                        $str.='<a ';
                        $str.='name="Registration" ';
                        $str.='href="'.SHOST.'/index.php?page=register&amp;function=getRegistrationForm" ';
                        $str.='hreflang="'.$language.'" ';
                        $tabindex++;
                        $str.='tabindex="'.$tabindex.'"';
                        $str.='>';
                        $str.=_('Register');
                        $str.='</a>';
                        $str.='</div>';
                }
        */
                $str.='<div ';
                $str.='class="unorderedList" style="color: red" ';
                $str.='onclick="selectMenu(\'skeleton\',\'getSkeletonFunction\'); return false;" ';
                $str.='onkeypress="selectMenu(\'skeleton\',\'getSkeletonFunction\'); return false;" ';
                $str.='>';
                $str.='<a ';
                $str.='name="Skeleton" ';
                $str.='href="'.HOST.'/index.php?page=skeleton&amp;function=getSkeletonFunction" ';
                $str.='hreflang="'.$language.'" ';
                $tabindex++;
                $str.='tabindex="'.$tabindex.'"';
                $str.='>';
                $str.=_('Skeleton');
                $str.='</a>';
                $str.='</div>';
 
                $str.='<div ';
                $str.='class="unorderedList" style="color: red" ';
                $str.='onclick="selectMenu(\'anotherSkeleton\',\'getSkeletonFunction\'); return false;" ';
                $str.='onkeypress="selectMenu(\'anotherSkeleton\',\'getSkeletonFunction\'); return false;" ';
                $str.='>';
                $str.='<a ';
                $str.='name="AnotherSkeleton" ';
                $str.='href="'.HOST.'/index.php?page=anotherSkeleton&amp;function=getSkeletonFunction" ';
                $str.='hreflang="'.$language.'" ';
                $tabindex++;
                $str.='tabindex="'.$tabindex.'"';
                $str.='>';
                $str.=_('Another Skeleton');
                $str.='</a>';
                $str.='</div>';
 
                $str.='<div ';
                $str.='class="unorderedList" style="color: red" ';
                $str.='onclick="selectMenu(\'language\',\'getGetLocale\'); return false;" ';
                $str.='onkeypress="selectMenu(\'language\',\'getGetLocale\'); return false;" ';
                $str.='>';
                $str.='<a ';
                $str.='name="language" ';
                $str.='href="'.HOST.'/index.php?page=language&amp;function=getGetLocale" ';
                $str.='hreflang="'.$language.'" ';
                $tabindex++;
                $str.='tabindex="'.$tabindex.'"';
                $str.='>';
                $str.=_('Language');
                $str.='</a>';
                $str.='</div>';
 
                $str.='<div ';
                $str.='class="unorderedList" style="color: red" ';
                $str.='onclick="selectMenu(\'info\',\'getInfo\'); return false;" ';
                $str.='onkeypress="selectMenu(\'info\',\'getInfo\'); return false;" ';
                $str.='>';
                $str.='<a ';
                $str.='name="info" ';
                $str.='href="'.HOST.'/index.php?page=info&amp;function=getInfo" ';
                $str.='hreflang="'.$language.'" ';
                $tabindex++;
                $str.='tabindex="'.$tabindex.'"';
                $str.='>';
                $str.=_('Info');
                $str.='</a>';
                $str.='</div>';
 
                /*For registered user only*/
                if($_SESSION["id_author"]) {
                        /***ABSTRACT***/
        /*              $str.='<div ';
                        $str.='class="unorderedList" ';
                        $str.='onclick="selectMenu(\'registerAbstract\',\'getPreviewAbstract\'); return false;" ';
                        $str.='onkeypress="selectMenu(\'registerAbstract\',\'getPreviewAbstract\'); return false;" ';
                        $str.='>';
                        $str.='<a ';
                        $str.='name="PreviewAbstract" ';
                        $str.='href="'.SHOST.'/index.php?page=registerAbstract&amp;function=getPreviewAbstract" ';
                        $str.='hreflang="'.$language.'" ';
                        $tabindex++;
                        $str.='tabindex="'.$tabindex.'"';
                        $str.='>';
                        $str.=_('Abstract');
                        $str.='</a>';
                        $str.="</div>";
 
                        $str.='<div ';
                        $str.='class="menuListItemBlock" ';
                        $str.='>';
                        $str.='<div ';
                        $str.='class="menuListItem" ';
                        $str.='onclick="selectMenu(\'registerAbstract\',\'abstractForm\',\'page/entities.html\'); return false;" ';
                        $str.='onkeypress="selectMenu(\'registerAbstract\',\'abstractForm\',\'page/entities.html\'); return false;" ';
                        $str.='>';
                        $str.='<a ';
                        $str.='name="RegisterAbstract" ';
                        $str.='href="'.SHOST.'/index.php?page=registerAbstract&amp;function=abstractForm" ';
                        $str.='hreflang="'.$language.'" ';
                        $tabindex++;
                        $str.='tabindex="'.$tabindex.'"';
                        $str.='>';
                        $str.=_('edit abstract');
                        $str.='</a>';
                        $str.='</div>';
                        $str.='</div>';
        */
                }
 
                if($_SESSION["id_author"]) {
        /*              $str.='<div ';
                        $str.='class="unorderedList" ';
                        $str.='>';
                        $str.='<a ';
                        $str.='name="Logout" ';
                        $str.='href="'.SHOST.'/index.php?page=login&amp;function=logout" ';
                        $str.='hreflang="'.$language.'" ';
                        $tabindex++;
                        $str.='tabindex="'.$tabindex.'"';
                        $str.='>';
                        $str.=_('Logout');
                        $str.='</a>';
                        $str.='</div>';
                } else {
                        $str.='<div ';
                        $str.='class="unorderedList" ';
                        $str.='>';
                        $str.='<a ';
                        $str.='name="Login" ';
                        $str.='href="'.SHOST.'/index.php?page=login&amp;function=loginForm" ';
                        $str.='hreflang="'.$language.'" ';
                        $tabindex++;
                        $str.='tabindex="'.$tabindex.'"';
                        $str.='>';
                        $str.=_('Login');
                        $str.='</a>';
                                $str.='</a>';
                        $str.='</div>';
        */
                }
 
        return $str;
}
 
//AFTER THE PHP END TAG THEY SHOULD NOT BE ANY MORE CARRIEGE RETURN
//otherwise they would be supplementary CR in the javascript response.text
?>

main.php

Location: /www/skeleton.irovision.ch/skeleton/page

<?php
        $str ="";
        $str.='<div class="centre">';
        $str.='<div class="milieu">';
        $str.='<h3>';
        $str.=_('News');
        $str.='&nbsp;!';
        $str.='</h3>';
 
        $str.='<h3>';
        $str.=_('IRO\'s SKELETON');
        $str.='&nbsp;!';
        $str.='</h3>';
        $str.='</div>';
        $str.='</div>';
 
        echo $str;
 
//AFTER THE PHP END TAG THEY SHOULD NOT BE ANY MORE CARRIEGE RETURN
//otherwise they would be supplementary CR in the javascript response.text
?>

skeleton.php

Location: /www/skeleton.irovision.ch/skeleton/page

<?php
require_once("config.php");
require_once("lib_dbconnection.php");
require_once("lib_functions.php");
 
function getSkeletonFunction(){
        $fields=array("in1","in2","in3");
 
        $ajax=false;
        $ajax=getOptions("ajax",false);
 
        foreach($fields as $key){
                ${$key}=NULL;
                ${$key}=getOptions($key,$ajax);
                //echo $key." ".${$key}." <br>";
        }
 
        echo skeletonFunction($in1,$in2,$in3);
}
 
function skeletonFunction($in1,$in2,$in3){
        $str="";
        $str.=_("This is the skeleton function");
        return $str;
}
 
callFunction(__FILE__);
cleanUpDB();
 
//AFTER THE PHP END TAG THEY SHOULD NOT BE ANY MORE CARRIEGE RETURN
//otherwise they would be supplementary CR in the javascript response.text
?>

profiles

Location: /www/skeleton.irovision.ch/skeleton/profiles FIXME

core

Location: /www/skeleton.irovision.ch/skeleton/profiles FIXME

profile

Location: /www/skeleton.irovision.ch/skeleton/profiles FIXME

script

Location: /www/skeleton.irovision.ch/skeleton/script

script.main.js

Location: /www/skeleton.irovision.ch/skeleton/script

function aMain(){
}
script.skeleton.js

Location: /www/skeleton.irovision.ch/skeleton/script

function aSkeleton(){
}

style

Location: /www/skeleton.irovision.ch/skeleton/style

Creates:

  `-- style
      |-- screen-sw.css
      |-- screen-ws.css
      |-- style.all.css
      |-- style.aural.css
      |-- style.braille.css
      |-- style.handheld.css
      |-- style.print.css
      `-- style.screen.css

metas

skeleton: /www/skeleton.irovision.ch/skeleton/metas

metas.common.php

Location: /www/skeleton.irovision.ch/skeleton/metas

<?php
 
require_once('lib_metas.php');
 
function commonMetas($filename){
 
        $str="";
 
        //echo "Entering filename: $filename<br>";
 
        $path_part=pathinfo($filename);
        $rootDirectory=$_SERVER['DOCUMENT_ROOT'];
        $dirname=$path_part['dirname'];
        $filename=$path_part['filename'];
        $extension=$path_part['extension'];
 
        $filename_array= explode('.', $filename);
        $explosionCounter=count($filename_array);
        //echo "explosion: $explosionCounter<br>";
        if( $explosionCounter > 1 ){
                //print_r($filename_array);
                $filename=$filename_array[$explosionCounter-1];
        }
        /*
        echo "Document Root: $rootDirectory<br>";
        echo "dirname $dirname<br>";
        echo "filename $filename<br>";
        echo "extension $extension<br>";
        */
 
        $PageRootDir="$rootDirectory/page";
        $MetasRootDir="$rootDirectory/metas";
        $ScriptRootDir="$rootDirectory/script";
        $StyleRootDir="$rootDirectory/style";
        //$targetFile=str_replace("metas","page",$targetFile);
 
        $str.='<base href="'.HOST.'">';
 
        /*META*/
        $str.='<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">';
        $str.=lastRevisionDate("$PageRootDir/$filename.php",$filename);
        /*LINK*/
 
        /*STYLESHEET*/
        $cssType=array('all','aural','braille','embossed','handheld','print','projection','screen');
 
        //Include CSS specific to the whole web site
        foreach ($cssType as $key){
                $str.=linkStyleSheet("$StyleRootDir/style.$key.css","style/style.$key.css",$key);
        }
       //Include CSS specific to the requested page
        foreach ($cssType as $key){
                $str.=linkStyleSheet("$StyleRootDir/style.$filename.$key.css","style/style.$filename.$key.css",$key);
        }
 
        /*ALTERNATE STYLESHEET*/
        //$str.='<link rel="alternate stylesheet" type="text/css" href="styles/screen-print.css" title="Print">';
        //$str.='<link rel="alternate stylesheet" type="text/css" href="styles/screen-ws.css" title="White + Black">';
        //$str.='<link rel="alternate stylesheet" type="text/css" href="styles/screen-sw.css" title="Black + White">';
 
 
        /*SCRIPT*/
        //Include common scripts
        // Call Prototype javascript framwork (Simplify AJAX and DOM)-->
        $str.=includeScript("$rootDirectory/lib/prototype.js","lib/prototype.js");
 
        // Call Scriptaculous javascript framwork (visual effects) -->
        $str.=includeScript("$rootDirectory/lib/scriptaculous/scriptaculous.js","lib/scriptaculous/scriptaculous.js?load=effects");
 
        //Call Proprietary (s.bolay) frameworks
        $str.=includeScript("$rootDirectory/lib/lib_variables.js","lib/lib_variables.js");
        $str.=includeScript("$rootDirectory/lib/lib_menu.js","lib/lib_menu.js");
 
        //Include script file linked to the actual page
        $str.=includeScript("$ScriptRootDir/$filename.js","script/script.$filename.js");
 
        return $str;
}
//AFTER THE PHP END TAG THEY SHOULD NOT BE ANY MORE CARRIEGE RETURN
//otherwise they would be supplementary CR in the javascript response.text
?>
metas.main.php

Location: /www/skeleton.irovision.ch/skeleton/metas

<?
include("metas.common.php");
$str="";
$str=commonMetas(__FILE__);
 
//For details see http://eis.bris.ac.uk/~cckhrb/webdev/code/html/meta_w3c.htm
$str.="<title>Main - This is an IRO's website example!</title>";
 
$str.='<meta name="author" content="Sylvain Bolay">';
$str.='<meta name="generator" content="VIM - Vi IMproved, version 7.0.235">';
$str.='<meta name="description" content="This is the main page">';
$str.='<meta name="keywords" content="IRO Main page, an Example, something else">';
$str.='<meta name="robots" content="aRobots">';
 
$str.='<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">';
$str.='<meta http-equiv="reply-to" content="it@irovision.ch (Sylvain Bolay)">';
//$str.="<meta http-equiv=\"expires\" content=\"aDate\">";
//$str.="<meta http-equiv=\"refresh\" content=\"aRefresh\">";
 
echo $str;
 
//AFTER THE PHP END TAG THEY SHOULD NOT BE ANY MORE CARRIEGE RETURN
//otherwise they would be supplementary CR in the javascript response.text
?>
metas.skeleton.php

Location: /www/skeleton.irovision.ch/skeleton/metas

<?
include("metas.common.php");
$str="";
$str=commonMetas(__FILE__);
 
//For details see http://eis.bris.ac.uk/~cckhrb/webdev/code/html/meta_w3c.htm
$str.="<title>SKELETON - This is an IRO's website example!</title>";
 
$str.="<meta name=\"author\" content=\"Sylvain Bolay\">";
$str.="<meta name=\"generator\" content=\"VIM - Vi IMproved, version 7.0.235\">";
$str.="<meta name=\"description\" content=\"This is the skeleton page\">";
$str.="<meta name=\"keywords\" content=\"IRO the Skeleton page, an Example, something else\">";
$str.="<meta name=\"robots\" content=\"aRobots\">";
 
$str.="<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">";
$str.="<meta http-equiv=\"reply-to\" content=\"it@irovision.ch (Sylvain Bolay)\">";
//$str.="<meta http-equiv=\"expires\" content=\"aDate\">";
//$str.="<meta http-equiv=\"refresh\" content=\"aRefresh\">";
 
echo $str;
 
//AFTER THE PHP END TAG THEY SHOULD NOT BE ANY MORE CARRIEGE RETURN
//otherwise they would be supplementary CR in the javascript response.text
?>

Libraries

Location: /www/lib

lib_metas.php

Location: /www/lib

<?php
 
function lastRevisionDate($file,$filename){
        $str="";
        if (file_exists($file)) {
                // outputs e.g.  somefile.txt was last modified: December 29 2002 22:16:23.
                //echo "$filename was last modified: " . date ("F d Y H:i:s.", filemtime($filename));
                $modificationDate=date("d/m/Y", filemtime($file));
                $str.='<meta name="revised" content="'.$filename.', '.$modificationDate.'">';
        }
        return $str;
}
 
function linkStyleSheet($file,$link,$type){
        $str="";
        if (file_exists($file)) {
                $str.='<link rel="stylesheet" type="text/css" href="'.$link.'" media="'.$type.'">';
                //echo "$str<br>";
        }
        return $str;
}
 
 
function includeScript($file,$link){
        $str="";
        if (file_exists($file)) {
                $str.='<script type="text/javascript" src="'.$link.'"></script>';
        }
        return $str;
}
 
//AFTER THE PHP END TAG THEY SHOULD NOT BE ANY MORE CARRIEGE RETURN
//otherwise they would be supplementary CR in the javascript response.text
?>

lib_dbconnection.php

Location: /www/lib

<?php
 
$db_connection = false;
 
function getMyConnection() { // 2.1
        global $db_connection;
        if( $db_connection ) return $db_connection;
        $db_connection = mysql_connect(DB_HOST, DB_USER, DB_PWD) or die('Could not connect to server.' );
        mysql_select_db(DATABASE, $db_connection) or die('Could not select database.');
        return $db_connection;
}
 
function cleanUpDB() { // 2.2
        global $db_connection;
        if( $db_connection != false ) mysql_close($db_connection);
        $db_connection = false;
}
 
//AFTER THE PHP END TAG THEY SHOULD NOT BE ANY MORE CARRIEGE RETURN
//otherwise they would be supplementary CR in the javascript response.text
?>

lib_functions.php

Location: /www/lib

<?php
 
require_once('lib_language.php');
 
/* This has to be added in the form
$str.='<form>';
        $str.='<input type="hidden" name="ajax" id="ajax" value="0">';
$str.='</form>';
*/
 
/* This is to modify the ajax field with the javascript before posting the form
// Remember, this instruction does DOM with the help of the prototype.js library
function aFunction(){
        $('ajax').value = "1";
}
*/
 
function getOptions($key,$ajax){
        $field=NULL;
        if (isset($_GET[$key])){
                if($ajax) $field=utf8_decode($_GET[$key]);
                else $field=$_GET[$key];
        }elseif (isset($_POST[$key])){
                if($ajax) $field=utf8_decode($_POST[$key]);
                else $field=$_POST[$key];
        }else{
                //echo("You ask for the $key option which actually does not exist!<br>");
        }
        return $field;
}
 
function getAFunction(){
        $ajax=false;
        $ajax=getOptions("ajax",false);
 
        $fields=array("field1","field2","field3");
        foreach($fields as $key){
                ${$key}=NULL;
                ${$key}=getOptions($key,$ajax);
                //echo $key." ".${$key}." <br>";
        }
        $id_gen=aFunction($field1, $field2, $field3);
        if ($ajax) echo "A Result When Ajax is Used<br>";
        else echo "Another Result When Ajax is Not Used<br>";
}
 
function noFunction(){
        $str ="";
        $str.=_("Error 404. Requested Page/Function not found!");
        return $str;
}
 
function callFunction($file){
        $fileName = pathinfo($file,PATHINFO_FILENAME);
        $incommingURL=pathinfo($_SERVER["PHP_SELF"],PATHINFO_FILENAME);
        //echo "** $_POST[page] | $_GET[page] | $incommingURL || $fileName **";
        if($_POST["page"]==$fileName || $_GET["page"]==$fileName || $incommingURL==$fileName ){
                //envoi des donnees par post ou get en passant en parametre tout ce qu'il y a apres le f
                $aFunction=null;
 
                if(isset($_POST['function']))           $aFunction=$_POST['function'];
                elseif (isset($_GET['function']))       $aFunction=$_GET['function'];
                elseif(isset($_POST['fonction']))       $aFunction=$_POST['fonction'];//kept for compatibilities reasons
                elseif (isset($_GET['fonction']))       $aFunction=$_GET['fonction'];//kept for compatibilities reasons
                else {
                        echo noFunction();
                        return;
                }
                if (function_exists($aFunction)) {
                        if (!isset($_GET['locale'])){
                                $_SESSION['lastPage']=$fileName;
                                $_SESSION['lastFunction']=$aFunction;
                        }
                        if(!$lInit) $lInit=initializeLocales(DEFAULT_LANGUAGE);
                        $aFunction();
                }else{
                        echo noFunction();
                }
 
        }
}
 
/*Use the callFunction as:
        require_once("common.php");
        callFunction(__FILE__);
*/
 
//AFTER THE PHP END TAG THEY SHOULD NOT BE ANY MORE CARRIEGE RETURN
//otherwise they would be supplementary CR in the javascript response.text
?>

lib_language.php

Location: /www/lib

<?php
function getLanguage($default){
        $str=$default;
        if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
                $str=substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
        }
        return $str;
}
 
function changeLanguage(){
//      initializeLocales(DEFAULT_LANGUAGE);
        if (isset($_SESSION['lastPage'])&&isset($_SESSION['lastFunction'])){
                header('Location: '.HOST.'/index.php?page='.$_SESSION['lastPage'].'&function='.$_SESSION['lastFunction']);
        }else{
                header('Location: '.HOST.'/index.php');
        }
}
 
function initializeLocales($default){
                        //echo date(DATE_RFC822);
/*
        function list_system_locales(){
                ob_start();
                system('locale -a');
                $str = ob_get_contents();
                ob_end_clean();
                return split("\\n", trim($str));
        }
*/
        //print_r($_GET);
        if (isset($_GET["locale"])){
                $_SESSION['locale']=$_GET["locale"];
                setcookie("locale", $_SESSION['locale'], time()+60*60*24*30, "/");// save a cookie
        }elseif (isset($_SESSION['locale'])){
                //nothing to do
        }elseif (!isset($_SESSION['locale']) && isset($_COOKIE["locale"])){
                $_SESSION['locale']=$_COOKIE["locale"];
        }elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
                $_SESSION['locale']=substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
        }else{
                $_SESSION['locale']=$default;
        }
/*
        //$locale.=".iso88591";
        //$locale="french";
        //echo "Locale: $locale<br>";
 
        //$locale = "fr_FR.UTF8";
        //$locale = "fr_FR.UTF8";
        $locales = list_system_locales();
 
       if(in_array($locale, $locales)){
                        echo "yes yes yes....<br>";
        }else{
                        echo "no no no.......<br>";
        }
*/
        //echo $_SESSION['locale'];
        $gettext_domain = FQDN; // set following the FQDN
        putenv("LC_ALL=$_SESSION[locale]");//needed on some systems
        putenv("LANGUAGE=$_SESSION[locale]");//needed on some systems
        //echo "setlocale: ".setlocale(LC_ALL,0)."<br>";//print actual locale
        setlocale(LC_ALL, $_SESSION['locale']);
        //echo "setlocale: ".setlocale(LC_ALL,0)."<br>";//print actual locale
        //bindtextdomain("messages", "./locale");
        //echo "bindtextdomain: ".bindtextdomain("fr", "./locales")."<br>";
        //echo "bindtextdomain($gettext_domain, /www/lib/locales)<br>";
        bindtextdomain($gettext_domain, "/www/lib/locales");
        //bind_textdomain_codeset("messages", "UTF-8");
        //echo "bind_textdomain_codeset: ".bind_textdomain_codeset("fr", "ISO-8859-1")."<br>";
        bind_textdomain_codeset($gettext_domain, "ISO-8859-1");
        //echo "textdomain: ".textdomain("skeleton")."<br>";
        textdomain($gettext_domain);
/*
        $locale = "fr_CH.iso-8859-1";
        $gettext_domain = 'fr'; // change by language
        putenv("LC_ALL=$locale");//needed on some systems
        putenv("LANG=$locale");//needed on some systems
        putenv("LANGUAGE=$locale");//needed on some systems
        setlocale(LC_ALL, $locale); // change by language, directory name fr_CH, not fr_CH.ISO-8859-1
        bindtextdomain($gettext_domain, "./locales");
        bind_textdomain_codeset($gettext_domain, 'iso-8859-1');
        textdomain($gettext_domain);
*/
        return true;
}
 
function localesForm($href,$locales,$flagSize){
 
        $str="";
        //$str.=date('l dS \of F Y h:i:s A');
        //$str.=date(DATE_RFC822);
 
        foreach ($locales as $key){
                //$shortLocale=substr($key, 0, 2);
 
                $str.='<a ';
                $str.="href=\"$href&amp;locale=$key\">";
                $str.="<img src=\"/img/flags/png/$key.svg.$flagSize.png\" alt=\"$key "._('Flag')."\" height=\"$flagSize\" width=\"$flagSize\">";
                $str.='</a>';
                $str.='&nbsp;|&nbsp;';
        }
 
        return $str;
}
 
//AFTER THE PHP END TAG THEY SHOULD NOT BE ANY MORE CARRIEGE RETURN
//otherwise they would be supplementary CR in the javascript response.text
?>

lib_validators.php

Location: /www/lib

<?php
function validators(){
 
        $str="";
        $str.='<p>';
        $str.='Webmaster';
        $str.='&nbsp;';
        $str.='<a ';
        $str.='href="http://www.bolay.net" ';
        $str.='>';
        $str.='Sylvain Bolay';
        $str.='</a>';
        $str.='@';
        $str.='<a ';
        $str.='href="http://www.irovision.ch" ';
        $str.='>';
        $str.='Irovision.ch';
        $str.='</a>';
        $str.='</p>';
 
        $str.='Spread Firefox/Iceweasel';
        $str.='<p>';
        $str.='<!-- http://www.spreadfirefox.com/?q=affiliates/homepage -->';
        $str.='<!--[if IE]>';
        $str.='<div ';
        $str.='id="getfirefox" ';
        $str.='style="text-align:center" ';
        $str.='>';
        $str.='<a ';
        $str.='href="http://www.spreadfirefox.com/?q=affiliates&amp;id=0&amp;t=210" ';
        $str.='>';
        $str.='<img ';
        $str.='border="0" ';
        $str.='alt="Firefox 2" ';
        $str.='title="Firefox 2" ';
        $str.='src="http://sfx-images.mozilla.org/affiliates/Buttons/firefox2/firefox-spread-btn-1b.png" ';
        $str.='>';
        $str.='</a>';
        $str.='</div>';
        $str.='<![endif]-->';
        $str.='</p>';
 
        $str.='Valid HTML 4.01 Strict!';
        $str.='<p>';
        $str.='<a ';
        $str.='href="http://validator.w3.org/check?uri=referer" ';
        $str.='>';
        $str.='<img ';
        $str.='src="img/valid-html401-blue" ';
        $str.='alt="Valid HTML 4.01 Strict" ';
        $str.='height="31" ';
        $str.='width="88" ';
        $str.='>';
        $str.='</a>';
        $str.='</p>';
 
        $str.='Valid CSS!';
        $str.='<p>';
        $str.='<a ';
        //$str.='href="http://jigsaw.w3.org/css-validator/" ';
        $str.='href="http://jigsaw.w3.org/css-validator/validator?uri='.urlencode(HOST.$_SERVER['REQUEST_URI']).'" ';
        $str.='>';
        $str.='<img ';
        $str.='style="border:0px" ';
        $str.='src="img/vcss" ';
        $str.='alt="Valid CSS!" ';
        $str.='height="31" ';
        $str.='width="88" ';
        $str.='>';
        $str.='</a>';
        $str.='</p>';
 
        $str.='Valid Cynthia!';
        $str.='<p>';
        $str.='<a ';
        $str.='href="http://www.CynthiaSays.com/org/cynthiatested.htm" ';
        $str.='>';
        $str.='<img ';
        $str.='style="border:0px" ';
        $str.='src="http://www.CynthiaSays.com/images/Ctested.gif" ';
        $str.='alt="Cynthia Tested!" ';
        $str.='height="31" ';
        $str.='width="88" ';
        $str.='>';
        $str.='</a>';
        $str.='</p>';
 
        return $str;
}
 
//AFTER THE PHP END TAG THEY SHOULD NOT BE ANY MORE CARRIEGE RETURN
//otherwise they would be supplementary CR in the javascript response.text
?>

lib_.php

Location: /www/lib

<?php
 
//AFTER THE PHP END TAG THEY SHOULD NOT BE ANY MORE CARRIEGE RETURN
//otherwise they would be supplementary CR in the javascript response.text
?>

Language Translation (Locale)

In general our web site will be written in english (en/en_US) and the translation (called “Locale”) into other languages will be performed through gettext (either in bash or php). In this section I describe the file structure and the way I create a locale.

PHP can automatically translate files if when the text is surrounded by _():

echo _('Hello World!');

based on gettext

aptitude install php-gettext

Locale File Structure

root@siro2:/# tree /www/lib/locales/
/www/lib/locales/
|-- fr_CH
|   `-- LC_MESSAGES
|       |-- skeleton.irovision.ch.mo
|       `-- skeleton.irovision.ch.po
`-- fr_FR
    `-- LC_MESSAGES
        |-- skeleton.irovision.ch.mo
        `-- skeleton.irovision.ch.po

Locale Creation

ssh -X username@siro2.iro
poedit

Normally at this stage poedit should be opened! Next:

  1. File → New catalog…
  2. Complete Fields under the Project info tab
    • e.g Project name and version is set to the FQDN of the targeted website
    • e.g Team is set to IRO's IT TEAM
    • e.g Team's email address is set to it@irovision.ch
    • Language and Country is set following the translation you have to do.
    • e.g Charset and Source code charset are set to ISO-8859-1
  3. Complete Fields under the Paths tab
    • e.g Base path is set to /www/skeleton.irovision.ch/skeleton/ (this is where your web page are stored!)
    • e.g. Under the Paths text area, add
      • .
      • page
      • metas
  4. Confirm by clicking the OK button
  5. Then you can Update the catalog and start the translation
  6. And finally save it as e.g /www/lib/locales/fr_FR/LC_MESSAGES/skeleton.irovision.ch.po

Replace the fr_FR by the right directory following your choice that you did on point 4 above. Furthermore, the .po file has to be saved with the name of the FQDN of your web site.

It may take some time since apache is aware of the modification. You can overcome this problem by reloading the apache web server (/etc/init.d/apache2 reload).

programming/web/developer_tools.txt · Last modified: 2011/08/15 20:31 by sbolay