- <?php
- /**
- * @file iconize.php
- * @brief le fichier qui permet d'afficher dans un dossier, une icone par sous dossier, en prennant la premiere image vennue :)
- * @test php iconize.php
- */
- include('top.php');
-
- function first_icon($path){
- $a=opendir($path);
- while ($b=readdir($a)){
- if ($b{0}!='.'){
- if (is_dir($path.$b)){
- if ($c=first_icon($path.$b.'/')) return $c;
- }else if (substr($b, strlen($b)-3)=='jpg'){
- return $path.$b;
- }
- }
- }
- return false;
- }
-
- function encode($str, $a=true){
- $b=array(' ', 'é', ']', '[', ',', 'î');
- $c=array('%20', '%C3%A9', '%5D', '%5B', '%2C', '%C3%A');
- if ($a) {$b[]='/'; $c[]='%2F';}
- return str_replace( $b, $c, $str );
- }
-
- $dir='/media/Yakumo/Musique/musique libre';
- $dest='/home/max/.nautilus/metafiles/file:%2F%2F%2Fmedia%2FYakumo%2FMusique%2Fmusique%2520libre.xml';
- $a=new GnomeDirXml();
- $b=opendir($dir);
- while ($c=readdir($b)){
- if ($c{0}!=='.'){
- $a->appendChild($d=new TemplateXML('file'));
- $d->setAttribute('name', encode($c));
- $d->setAttribute('timestamp', time()+10000);
- $d->setAttribute('custom_icon', encode(substr(first_icon($dir.'/'.$c.'/'), strlen($dir)+2+strlen($c)), false));
- }
- }
- $fd=fopen($dest, 'w');
- fputs($fd, $a->show());
- fclose($fd);
-
- ?>
<?php
/**
* @file iconize.php
* @brief le fichier qui permet d'afficher dans un dossier, une icone par sous dossier, en prennant la premiere image vennue :)
* @test php iconize.php
*/
include('top.php');
function first_icon($path){
$a=opendir($path);
while ($b=readdir($a)){
if ($b{0}!='.'){
if (is_dir($path.$b)){
if ($c=first_icon($path.$b.'/')) return $c;
}else if (substr($b, strlen($b)-3)=='jpg'){
return $path.$b;
}
}
}
return false;
}
function encode($str, $a=true){
$b=array(' ', 'é', ']', '[', ',', 'î');
$c=array('%20', '%C3%A9', '%5D', '%5B', '%2C', '%C3%A');
if ($a) {$b[]='/'; $c[]='%2F';}
return str_replace( $b, $c, $str );
}
$dir='/media/Yakumo/Musique/musique libre';
$dest='/home/max/.nautilus/metafiles/file:%2F%2F%2Fmedia%2FYakumo%2FMusique%2Fmusique%2520libre.xml';
$a=new GnomeDirXml();
$b=opendir($dir);
while ($c=readdir($b)){
if ($c{0}!=='.'){
$a->appendChild($d=new TemplateXML('file'));
$d->setAttribute('name', encode($c));
$d->setAttribute('timestamp', time()+10000);
$d->setAttribute('custom_icon', encode(substr(first_icon($dir.'/'.$c.'/'), strlen($dir)+2+strlen($c)), false));
}
}
$fd=fopen($dest, 'w');
fputs($fd, $a->show());
fclose($fd);
?>