-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Création du projet
- Loading branch information
Showing
109 changed files
with
9,377 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
cd php-gtk2 | ||
php.exe ../ScriptDeConversionGTK.php | ||
rem pause |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
|
||
class GetChoix{ | ||
|
||
/** | ||
* @def UTF8_ISO Conversion UTF8 en ISO-8859-1 | ||
* | ||
* @var const | ||
*/ | ||
const UTF8_ISO = 10; | ||
/** | ||
* @def ISO_UTF8 Conversion ISO-8859-1 en UTF8 | ||
* | ||
* @var const | ||
*/ | ||
const ISO_UTF8 = 11; | ||
|
||
/** | ||
* @def LIB_UTF8_ISO Libellé du bouton "Conversion UTF8 en ISO-8859-1" | ||
* | ||
* @var const | ||
*/ | ||
const LIB_UTF8_ISO = "Conversion UTF8 en ISO-8859-1"; | ||
/** | ||
* @def LIB_ISO_UTF8 Libellé du bouton "Conversion ISO-8859-1 en UTF8" | ||
* | ||
* @var const | ||
*/ | ||
const LIB_ISO_UTF8 = "Conversion ISO-8859-1 en UTF8"; | ||
|
||
/** | ||
* Récupération du du sens de la conversion | ||
*/ | ||
public function getSens(){ | ||
|
||
// http://gtk.php.net/manual/en/gtk.gtkmessagedialog.constructor.php | ||
$dialog = new GtkMessageDialog( null,//parent | ||
0, | ||
Gtk::MESSAGE_QUESTION, | ||
Gtk::BUTTONS_NONE, | ||
'Sens de la Conversion?' | ||
); | ||
$dialog->add_button(self::LIB_UTF8_ISO, self::UTF8_ISO); | ||
$dialog->add_button(self::LIB_ISO_UTF8, self::ISO_UTF8); | ||
$dialog->add_button(Gtk::STOCK_CANCEL, Gtk::BUTTONS_CANCEL); | ||
$dialog->set_markup('Sens de la conversion?'); | ||
|
||
$answerClient = $dialog->run(); | ||
$dialog->destroy(); | ||
return $answerClient; | ||
} | ||
|
||
|
||
/** | ||
* Récupération du chemin où se situe le dossier à convertir | ||
*/ | ||
public function getRepInitial(){ | ||
$reponse = null; | ||
// Récupération du chemin du répertoire | ||
$dialog = new GtkFileChooserDialog("Où se trouve le répertoire à convertir?", | ||
null, | ||
Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER, | ||
array(Gtk::STOCK_OK, Gtk::RESPONSE_OK, Gtk::STOCK_CANCEL, Gtk::RESPONSE_CANCEL), | ||
null); | ||
//$dialog->set_filename("c:/tmp"); | ||
|
||
if ($dialog->run() == Gtk::RESPONSE_OK) { | ||
//var_dump($dialog); | ||
$reponse = $dialog->get_filename(); | ||
chdir($reponse); | ||
} | ||
else exit; | ||
$dialog->destroy(); | ||
return $reponse; | ||
} | ||
|
||
/** | ||
* Indique où se va se trouver le réprtoire cible (converti) | ||
*/ | ||
public function getRepCible(){ | ||
$reponse = null; | ||
$dialog = new GtkFileChooserDialog("Où se trouve le répertoire cible?", | ||
null, | ||
Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER, | ||
array(Gtk::STOCK_OK, Gtk::RESPONSE_OK, Gtk::STOCK_CANCEL, Gtk::RESPONSE_CANCEL), | ||
null); | ||
|
||
if ($dialog->run() == Gtk::RESPONSE_OK) { | ||
//var_dump($dialog); | ||
$reponse = $dialog->get_filename(); | ||
chdir($reponse); | ||
} | ||
else exit; | ||
$dialog->destroy(); | ||
return $reponse; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
|
||
require_once 'SetMessages.php'; | ||
|
||
class OutilConvert{ | ||
|
||
protected $set_messages = null; | ||
|
||
public function __construct(){ | ||
$this->set_messages = new SetMessages(); | ||
} | ||
|
||
/************************************************** | ||
** | ||
** [ FONCTION convert_dir ] | ||
** | ||
** Par Jérémy Dombier - Utilisation libre | ||
** | ||
** Copie un dossier vers un autre | ||
** | ||
** http://www.comscripts.com/sources/php.copier-un-dossier-recursif.294.html | ||
** | ||
** DoyDoy : Rajout d'un paramètre d'exception ($sauf) | ||
**************************************************/ | ||
/** | ||
* Conversion d'un répertoire | ||
* @param string $methode 'utf8_encode' ou 'utf8_decode' | ||
* @param string $dir_init | ||
* @param string $dir_cible | ||
* @param array|null $sauf | ||
*/ | ||
public function convert_dir($methode, $dir_init, $dir_cible, array $sauf = null) { | ||
/* | ||
echo '-----------------------------' . "\n"; | ||
echo '$methode : ' . $methode . "\n"; | ||
echo '$dir_init : ' . $dir_init . "\n"; | ||
echo '$dir_cible : ' . $dir_cible . "\n"; | ||
*/ | ||
$dir_init = $dir_init . '/'; | ||
$dir_cible = $dir_cible . '/'; | ||
$dir_init = str_replace('//', '/', $dir_init); | ||
$dir_cible = str_replace('//', '/', $dir_cible); | ||
|
||
// On vérifie si $dir_init est un dossier | ||
if (is_dir($dir_init)) { | ||
|
||
// Si oui, on l'ouvre | ||
if ($dh = opendir($dir_init)) { | ||
|
||
// On liste les dossiers et fichiers de $dir_init | ||
while (($file = readdir($dh)) !== false) { | ||
|
||
// Si le dossier dans lequel on veut coller n'existe pas, on le crée | ||
if (!is_dir($dir_cible)) mkdir ($dir_cible, 0777); | ||
|
||
if (!is_null($sauf)){ | ||
if (in_array($file, $sauf)) { | ||
continue; | ||
} | ||
} | ||
|
||
// S'il s'agit d'un dossier, on relance la fonction récursive | ||
if(is_dir($dir_init.$file) && $file != '..' && $file != '.') | ||
$this->convert_dir($methode, $dir_init.$file.'/', $dir_cible.$file.'/', $sauf); | ||
// S'il sagit d'un fichier, on le copie simplement | ||
elseif($file != '..' && $file != '.'){ | ||
|
||
$contenu = file_get_contents($dir_init.$file); | ||
if ($contenu) | ||
{ $contenu_new = $contenu; | ||
$contenu_new = $methode($contenu); | ||
$conversion = file_put_contents($dir_cible.$file, $contenu_new); | ||
if (!$conversion){ | ||
$this->set_messages->messageError('La conversion du fichier ' . $dir_init . $file . ' a échoué...'); | ||
exit; | ||
} | ||
//else echo 'Conversion effectuée pour le fichier ' . $dir_init . $file ."\n"; | ||
} | ||
else { | ||
echo 'Conversion non effectuée pour le fichier ' . $dir_init . $file . "\n"; | ||
|
||
if (!copy($dir_init.$file, $dir_cible.$file )){ | ||
$this->set_messages->messageError("La copie du fichier " . $dir2copy . $fil . " a échoué..."); | ||
exit; | ||
} | ||
} | ||
} | ||
} | ||
|
||
// On ferme $dir_init | ||
closedir($dh); | ||
} | ||
} | ||
//echo '-----------------------------' . "\n"; | ||
return; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
/* | ||
* | ||
utf8_encode — Convertit une chaîne ISO-8859-1 en UTF-8 : http://fr2.php.net/manual/fr/function.utf8-encode.php | ||
utf8_decode — Convertit une chaîne UTF-8 en ISO-8859-1 : http://fr2.php.net/manual/fr/function.utf8-decode.php | ||
http://forum.phpfrance.com/vos-contributions/utf8izer-pour-convertir-utf-tous-les-fichiers-iso-dossier-t244096.html | ||
*/ | ||
|
||
/** | ||
* Conversion UTF8 <-> ISO-8859-1 | ||
* | ||
* @brief Outil de conversion d'un répertoire ISO-8859-1 en UTF8 et inbversement | ||
* | ||
* @author DoyDoy | ||
* @version 1.0 | ||
* | ||
*/ | ||
// http://www.devshed.com/c/a/PHP/Building-Your-Own-Desktop-Notepad-Application-Using-PHPGTK/2/ | ||
// cd C:\tmp\php-gtk2 | ||
// php c:\tmp\test-phpGTK.php | ||
|
||
require_once 'GetChoix.php'; | ||
require_once 'SetMessages.php'; | ||
require_once 'OutilConvert.php'; | ||
|
||
|
||
//phpinfo(); | ||
|
||
$GetChoix = new GetChoix(); | ||
$SetMessages = new SetMessages(); | ||
$OutilConvert = new OutilConvert(); | ||
|
||
$sens = $GetChoix->getSens(); | ||
echo $sens . "\n"; | ||
if (10 == $sens) // Conversion UTF8 en ISO-8859-1 | ||
$convert = 'utf8_decode'; // utf8_decode — Convertit une chaîne UTF-8 en ISO-8859-1 : http://fr2.php.net/manual/fr/function.utf8-decode.php | ||
elseif (11 == $sens) // Conversion ISO-8859-1 en UTF8 | ||
$convert = 'utf8_encode'; // utf8_encode — Convertit une chaîne ISO-8859-1 en UTF-8 : http://fr2.php.net/manual/fr/function.utf8-encode.php | ||
else | ||
die(); | ||
|
||
echo $convert . "\n"; | ||
|
||
$rep_init = $GetChoix->getRepInitial(); | ||
if (is_null($rep_init)){ | ||
$SetMessages->messageError('Vous n\'avez pas indiqué de répertoire à convertir'); | ||
die(); | ||
} | ||
$rep_init = str_replace("\\", "/", $rep_init); | ||
echo $rep_init . "\n"; | ||
$rep_cible = $GetChoix->getRepCible(); | ||
if (is_null($rep_cible)){ | ||
$SetMessages->messageError('Vous n\'avez pas indiqué de répertoire cible'); | ||
die(); | ||
} | ||
$rep_cible = str_replace("\\", "/", $rep_cible); | ||
echo $rep_cible . "\n"; | ||
|
||
$OutilConvert->convert_dir($convert, $rep_init, $rep_cible); | ||
|
||
$SetMessages->messageInfo('Fin de la convertion'); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
class SetMessages{ | ||
|
||
public function messageInfo($text){ | ||
$this->_message(Gtk::MESSAGE_INFO,$text); | ||
} | ||
|
||
public function messageAlert($text){ | ||
$this->_message(Gtk::MESSAGE_WARNING,$text); | ||
} | ||
public function messageError($text){ | ||
$this->_message(Gtk::MESSAGE_ERROR,$text); | ||
} | ||
|
||
private function _message($typeMessage, $text){ | ||
$dialog = new GtkMessageDialog( null,//parent | ||
0, | ||
$typeMessage, | ||
Gtk::BUTTONS_OK, | ||
$text | ||
); | ||
$dialog->run(); | ||
$dialog->destroy(); | ||
return; | ||
} | ||
} |
Oops, something went wrong.