clean code (identation, if with {)

This commit is contained in:
Simon Leblanc 2011-05-15 03:56:54 +02:00
parent 13f5608a3e
commit 4f380d8f8d
229 changed files with 69871 additions and 2690 deletions

View file

@ -40,51 +40,37 @@
//ouverture de la connection avec la base SQL
$connect = pg_connect("host= dbname= user=");
$sondage=pg_exec($connect, "select * from sondage where format='D' or format='D+'");
for ($i=0;$i<pg_numrows($sondage);$i++){
$dsondage=pg_fetch_object($sondage,$i);
// print "Pour le sondage ".$dsondage->id_sondage." ";
$sujets=pg_exec($connect, "select sujet from sujet_studs where id_sondage='$dsondage->id_sondage'");
$dsujets=pg_fetch_object($sujets,0);
$nouvelledateaffiche="";
$anciensujethoraires=explode(",",$dsujets->sujet);
for ($j=0;$j<count($anciensujethoraires);$j++){
if (strpos('@',$anciensujethoraires[$j]) !== false){
$ancientsujet=explode("@",$anciensujethoraires[$j]);
//;([0-2]\d)/([0-2]\d)/(\d{4});
if (preg_match(";(\d{1,2})/(\d{1,2})/(\d{4});",$ancientsujet[0],$registredate)){
$nouvelledate=mktime(0,0,0,$registredate[2],$registredate[1],$registredate[3]);
// echo $ancientsujet[0].'@'.$ancientsujet[1].' ---> '.$nouvelledate.'@'.$ancientsujet[1].'<br> ';
$nouvelledateaffiche.=$nouvelledate.'@'.$ancientsujet[1].',';
}
}
else{
if (preg_match(";(\d{1,2})/(\d{1,2})/(\d{4});",$anciensujethoraires[$j],$registredate)){
$nouvelledate=mktime(0,0,0,$registredate[2],$registredate[1],$registredate[3]);
// echo $anciensujethoraires[$j].' ---- > '.$nouvelledate.'<br>';
$nouvelledateaffiche.=$nouvelledate.',';
}
}
}
$nouvelledateaffiche=substr($nouvelledateaffiche,0,-1);
print $dsujets->sujet.' donne '.$nouvelledateaffiche.'\n\n';
// pg_exec($connect,"update sujet_studs set sujet='$nouvelledateaffiche' where id_sondage='$dsondage->id_sondage'");
}
?>
for ($i=0;$i<pg_numrows($sondage);$i++) {
$dsondage=pg_fetch_object($sondage,$i);
// print "Pour le sondage ".$dsondage->id_sondage." ";
$sujets=pg_exec($connect, "select sujet from sujet_studs where id_sondage='$dsondage->id_sondage'");
$dsujets=pg_fetch_object($sujets,0);
$nouvelledateaffiche="";
$anciensujethoraires=explode(",",$dsujets->sujet);
for ($j=0;$j<count($anciensujethoraires);$j++) {
if (strpos('@',$anciensujethoraires[$j]) !== false) {
$ancientsujet=explode("@",$anciensujethoraires[$j]);
//;([0-2]\d)/([0-2]\d)/(\d{4});
if (preg_match(";(\d{1,2})/(\d{1,2})/(\d{4});",$ancientsujet[0],$registredate)) {
$nouvelledate=mktime(0,0,0,$registredate[2],$registredate[1],$registredate[3]);
// echo $ancientsujet[0].'@'.$ancientsujet[1].' ---> '.$nouvelledate.'@'.$ancientsujet[1].'<br> ';
$nouvelledateaffiche.=$nouvelledate.'@'.$ancientsujet[1].',';
}
} else {
if (preg_match(";(\d{1,2})/(\d{1,2})/(\d{4});",$anciensujethoraires[$j],$registredate)) {
$nouvelledate=mktime(0,0,0,$registredate[2],$registredate[1],$registredate[3]);
// echo $anciensujethoraires[$j].' ---- > '.$nouvelledate.'<br>';
$nouvelledateaffiche.=$nouvelledate.',';
}
}
}
$nouvelledateaffiche=substr($nouvelledateaffiche,0,-1);
print $dsujets->sujet.' donne '.$nouvelledateaffiche.'\n\n';
// pg_exec($connect,"update sujet_studs set sujet='$nouvelledateaffiche' where id_sondage='$dsondage->id_sondage'");
}

View file

@ -43,22 +43,17 @@ include_once('../fonctions.php');
$date_courante=date("U");
$date=date('H:i:s d/m/Y:');
//ouverture de la connection avec la base SQL
$sondage=$connect->Execute("select * from sondage");
while ( $dsondage=$sondage->FetchNextObject(false)) {
if ($date_courante > strtotime($dsondage->date_fin)){
//destruction des données dans la base
$connect->Execute('DELETE FROM sondage LEFT INNER JOIN sujet_studs ON sujet_studs.id_sondage = sondage.id_sondage '.
'LEFT INNER JOIN user_studs ON user_studs.id_sondage = sondage.id_sondage ' .
'LEFT INNER JOIN comments ON comments.id_sondage = sondage.id_sondage ' .
"WHERE id_sondage = '$dsondage->id_sondage' ");
// ecriture des traces dans le fichier de logs
error_log($date . " SUPPRESSION: $dsondage->id_sondage\t$dsondage->format\t$dsondage->nom_admin\t$dsondage->mail_admin\n", '../admin/logs_studs.txt');
}
}
?>
while ($dsondage=$sondage->FetchNextObject(false)) {
if ($date_courante > strtotime($dsondage->date_fin)) {
//destruction des données dans la base
$connect->Execute('DELETE FROM sondage LEFT INNER JOIN sujet_studs ON sujet_studs.id_sondage = sondage.id_sondage '.
'LEFT INNER JOIN user_studs ON user_studs.id_sondage = sondage.id_sondage ' .
'LEFT INNER JOIN comments ON comments.id_sondage = sondage.id_sondage ' .
"WHERE id_sondage = '$dsondage->id_sondage' ");
// ecriture des traces dans le fichier de logs
error_log($date . " SUPPRESSION: $dsondage->id_sondage\t$dsondage->format\t$dsondage->nom_admin\t$dsondage->mail_admin\n", '../admin/logs_studs.txt');
}
}

View file

@ -1,24 +1,25 @@
<?php
/*
raphael.droz@gmail.com, dwtfywwi licence , 2010 :
/*
raphael.droz@gmail.com, dwtfywwi licence , 2010 :
choppe un fichier $vara="traduction"; dans <lang>.inc
build un assoc array
preg_replace les appels wrappés dans gettext() dans le php principal
generate un .po
(
echo -e "<?php\n\$l = array (";
sed -n '/^$.*$/s/^$\([^=]\+\)=.\(.*\).;/"\1"=>\x27\2\x27,/p' lang/en.inc;
echo '); ?>'
) > /tmp/lang.mod
(manually tweak 2 double quotes)
*/
choppe un fichier $vara="traduction"; dans <lang>.inc
build un assoc array
preg_replace les appels wrappés dans gettext() dans le php principal
generate un .po
(
echo -e "<?php\n\$l = array (";
sed -n '/^$.*$/s/^$\([^=]\+\)=.\(.*\).;/"\1"=>\x27\2\x27,/p' lang/en.inc;
echo '); ?>'
) > /tmp/lang.mod
(manually tweak 2 double quotes)
*/
// drop a $l which contain the array
if(isset($_SERVER['PHP_SELF']))
// drop a $l which contain the array
if(isset($_SERVER['PHP_SELF'])) {
die(); // die if not run with php-cli
}
require_once('/tmp/lang.mod');
$mypath = '/var/www/studs';
@ -43,19 +44,23 @@ msgstr ""
';
/* helpers */
function stripN($a) {
function stripN($a)
{
return preg_replace("/\n/","\\n", $a);
}
function addDQ($a) {
function addDQ($a)
{
return addcslashes($a,'"');
}
/* low priority for weak regexps (small variable length) at the end, please */
function cmp($a, $b) {
function cmp($a, $b)
{
return (mb_strlen($a) < mb_strlen($b));
}
uksort($l, 'cmp');
/*
@ -79,12 +84,15 @@ foreach($l as $k => $v) {
}
foreach (new DirectoryIterator('.') as $fileInfo) {
if($fileInfo->isDot()) continue;
if($fileInfo->isDot()) {
continue;
}
$name = $fileInfo->getFilename();
// process php files
if(!preg_match('/\.php$/' , $name) ||
preg_match('/phpVar2getText/', $name))
if(!preg_match('/\.php$/' , $name) || preg_match('/phpVar2getText/', $name)) {
continue;
}
$orig = file_get_contents($name);
$a = preg_replace($match0, $repl0, $orig, -1, $b);
@ -114,16 +122,14 @@ foreach(array('fr_FR','es_ES','de_DE', 'en_GB') as $i) {
foreach(array_unique($l) as $k => $v) {
/* poedit is strict with its syntax */
$po_ready_v = stripN(addDQ($v));
if($f == 'en')
$a .= 'msgid "' . $po_ready_v . '"' . "\n" .
'msgstr "' . $po_ready_v . '"' . "\n\n";
else
if($f == 'en') {
$a .= 'msgid "' . $po_ready_v . '"' . "\n" . 'msgstr "' . $po_ready_v . '"' . "\n\n";
} else {
$a .= 'msgid "' . $po_ready_v . '"' . "\n" .
/* ${$k} the key (var name) in the orig (EN) array
to look for as a raw $var while the <lang>.inc is included in the context */
'msgstr "' . stripN(addDQ(${$k})) . '"' . "\n\n";
}
}
file_put_contents('locale/' . $f . '_' . $g . '/LC_MESSAGES/Studs.po', $header . $a);
}
?>
}

View file

@ -38,16 +38,9 @@
#!/usr/bin/perl
open (FILE,"../admin/logs_studs.txt");
while (<FILE>){
/.*\t(.*u-strasbg.fr)\t.*/;
print $1."\n";
while (<FILE>) {
/.*\t(.*u-strasbg.fr)\t.*/;
print $1."\n";
}

View file

@ -40,18 +40,10 @@
//ouverture de la connection avec la base SQL
$connect = pg_connect("host= dbname= user=");
$sondage=pg_exec($connect, "select distinct mail_admin from sondage ");
for ($i=0;$i<pg_numrows($sondage);$i++){
$dsondage=pg_fetch_object($sondage,$i);
print "$dsondage->mail_admin, ";
// print "$dsondage->mail_admin\n";
}
?>
$dsondage=pg_fetch_object($sondage,$i);
print "$dsondage->mail_admin, ";
// print "$dsondage->mail_admin\n";
}