Ignore:
Timestamp:
Jan 1, 2012, 10:09:17 PM (12 years ago)
Author:
mistic100
Message:

fix detection regex and watermark position

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/PHP_Optimisateur/include/main.php

    r10337 r12819  
    22// Si mode silencieux vidage automatique du dossier de sortie
    33if ($CONF['silentORNOT'] == 'erase') {
    4         @rrmdir($CONF['DIRsortie']);
    5         @mkdir($CONF['DIRsortie']);
     4  @rrmdir($CONF['DIRsortie']);
     5  @mkdir($CONF['DIRsortie']);
    66}
    77
     
    1010// Les caractères '%' et '$' sont systématiquement échappés, ca génère des bugs dans les noms de fichiers
    1111function recursive_delete_special_car($dir) {
    12         $dir = rtrim($dir, '/');
    13         $dh = opendir($dir);
    14        
    15         while (($file = readdir($dh)) !== false ) {
    16                 if ($file !== '.' && $file !== '..') {
    17                         $path = $dir.'/'.$file;
    18                         $new_path = $dir.'/'.delete_special_car($file);
    19                        
    20                         if ($path != $new_path) {
    21                                 rename_log($path, $new_path);
    22                         }
    23                        
    24                         if (is_dir($new_path)) {
    25                                 recursive_delete_special_car($new_path);
    26                         }
    27                 }
    28         }
    29         closedir($dh);
     12  $dir = rtrim($dir, '/');
     13  $dh = opendir($dir);
     14 
     15  while (($file = readdir($dh)) !== false ) {
     16    if ($file !== '.' && $file !== '..') {
     17      $path = $dir.'/'.$file;
     18      $new_path = $dir.'/'.delete_special_car($file);
     19     
     20      if ($path != $new_path) {
     21        rename_log($path, $new_path);
     22      }
     23     
     24      if (is_dir($new_path)) {
     25        recursive_delete_special_car($new_path);
     26      }
     27    }
     28  }
     29  closedir($dh);
    3030}
    3131
     
    3838
    3939if ($CONF['copyONhd']) {
    40         $CONF['copyHD'] = '-text_font "'.$CONF['copyFONT'].'" '.$CONF['DIMnormal']*$CONF['copySIZE'].' -text_color '.$CONF['copyCOLOR'].' -text_flag '.$CONF['copyPOS'].' -text_pos 0 0 -text "'.$CONF['copyright'].'"';
     40  $CONF['copyHD'] = '-text_font "'.$CONF['copyFONT'].'" '.$CONF['DIMnormal']*$CONF['copySIZE'].' -text_color '.$CONF['copyCOLOR'].' -text_flag '.$CONF['copyPOS'].' -text_pos 0 0 -text "'.$CONF['copyright'].'"';
    4141} else {
    42         $CONF['copyHD'] = null;
     42  $CONF['copyHD'] = null;
    4343}
    4444
    4545if ($CONF['copyONnormal']) {
    46         $CONF['copyNormal'] = '-text_font "'.$CONF['copyFONT'].'" '.$CONF['DIMnormal']*$CONF['copySIZE'].' -text_color '.$CONF['copyCOLOR'].' -text_flag '.$CONF['copyPOS'].' -text_pos 0 0 -text "'.$CONF['copyright'].'"';
     46  $CONF['copyNormal'] = '-text_font "'.$CONF['copyFONT'].'" '.$CONF['DIMnormal']*$CONF['copySIZE'].' -text_color '.$CONF['copyCOLOR'].' -text_flag '.$CONF['copyPOS'].' -text_pos 0 0 -text "'.$CONF['copyright'].'"';
    4747} else {
    48         $CONF['copyNormal'] = null;
     48  $CONF['copyNormal'] = null;
    4949}
    5050
     
    5555### Plugins avant execution ###
    5656foreach ($CONF['Plugins'] as $plugin_id => $plugin_config) {
    57         if ($plugin_config['mode'] == 'Before' AND $plugin_config['active']) {
    58                 include('plugins/'.$plugin_id.'/main.php');
    59         }
     57  if ($plugin_config['mode'] == 'Before' AND $plugin_config['active']) {
     58    include('plugins/'.$plugin_id.'/main.php');
     59  }
    6060}
    6161
     
    7171// Boucle sur tous les fichiers
    7272for ($i=0; $i<count($FilesSource); $i++) {
    73         // Découpe le nom de fichier : dossier/fichier/extension
    74         preg_match('#^(.*)/(.*)\.([a-z0-9]{2,4})$#', $FilesSource[$i], $matches);
    75         $file['folder_src'] = $matches[1].'/'; // dossier d'entrée
    76         $file['folder_out'] = str_replace($CONF['DIRsource'], $CONF['DIRsortie'], $file['folder_src']); // dossier de sortie
    77         $file['name'] = $matches[2]; // nom final
    78         $file['ext'] = $matches[3]; // extension orginale
    79                        
    80         // Crée les sous-dossiers de sortie & 'pwg_high' & 'thumbnail'
    81         if (!file_exists($file['folder_out'].'pwg_high') AND $CONF['DIRhighORNOT']) {
    82                 mkdir_log($file['folder_out'].'pwg_high');
    83         }
    84         if (!file_exists($file['folder_out'].'thumbnail')) {
    85                 mkdir_log($file['folder_out'].'thumbnail');
    86         }
    87        
    88         if (!in_arrayi($file['ext'], $CONF['allowedExt'])) {
    89                 $BlockAll['main'] = true;
    90                 $LOG[] = 'Not image file : '.$FilesSource[$i];
    91         }
    92        
    93         if (!isset($BlockAll)) {
    94                 // Informations sur le fichier
    95                 exec('include\nconvert.exe -info "'.$FilesSource[$i].'"', $FileInfos);
    96                
    97                 for ($m=0; $m<=5; $m++) {
    98                         unset($FileInfos[$m]);
    99                 }
    100                 foreach ($FileInfos as $key) {
    101                         if ($key != '') {
    102                                 $a = explode(':', $key);
    103                                 $FileInfos[trim($a[0])] = trim($a[1]);
    104                         }
    105                 }
    106         }
    107                
    108         // Plugins pendant l'execution, haute priorité
    109         foreach ($CONF['Plugins'] as $plugin_id => $plugin_config) {
    110                 if ($plugin_config['mode'] == 'ProcessHigh' AND $plugin_config['active']) {
    111                         include('plugins/'.$plugin_id.'/main.php');
    112                 }
    113         }
    114        
    115         // Plugins pendant l'execution
    116         foreach ($CONF['Plugins'] as $plugin_id => $plugin_config) {
    117                 if ($plugin_config['mode'] == 'Process' AND $plugin_config['active']) {
    118                         include('plugins/'.$plugin_id.'/main.php');
    119                 }
    120         }
    121        
    122         // Compresse les fichiers dans le dossier de sortie
    123         if (!isset($BlockNormal) AND !isset($BlockAll)) {
    124                 nconvert('-q '.$CONF['Qnormal'].' -out jpeg -o "'.$file['folder_out'].$file['name'].'.jpg" -dpi 72 '.$CONF['convOptions'].' -resize '.$CONF['DIMnormal'].' '.$CONF['DIMnormal'].' '.$CONF['copyNormal'].' "'.$FilesSource[$i].'"');
    125         }
    126         if (!isset($BlockThumbnail) AND !isset($BlockAll)) {
    127                 nconvert('-q '.$CONF['Qthumbnail'].' -out jpeg -o "'.$file['folder_out'].'thumbnail/'.$CONF['prefixe_mini'].$file['name'].'.jpg" -dpi 72 '.$CONF['convOptions'].' -resize '.$CONF['DIMthumbnail'].' '.$CONF['DIMthumbnail'].' -rmeta -rexifthumb "'.$FilesSource[$i].'"');
    128         }
    129         if (!isset($BlockHigh) AND $CONF['DIRhighORNOT'] AND !isset($BlockAll)) {
    130                 if ($CONF['DIMhdORNOT']) {
    131                         nconvert('-q '.$CONF['Qhd'].' -out jpeg -o "'.$file['folder_out'].'pwg_high/'.$file['name'].'.jpg" -dpi '.$CONF['DPI'].' '.$CONF['convOptions'].' -resize '.$CONF['DIMhd'].' '.$CONF['DIMhd'].' '.$CONF['copyHD'].' "'.$FilesSource[$i].'"');
    132                 } else if (strtolower($file['ext']) != 'jpg') {
    133                         nconvert('-q '.$CONF['Qhd'].' -out jpeg -o "'.$file['folder_out'].'pwg_high/'.$file['name'].'.jpg" "'.$FilesSource[$i].'"');
    134                 } else {
    135                         copy_log($FilesSource[$i], $file['folder_out'].'pwg_high/'.$file['name'].'.jpg');
    136                 }
    137         }
    138        
    139         // Réinitialise les variables
    140         unset($file, $FileInfos, $BlockNormal, $BlockThumbnail, $BlockHigh, $BlockAll);
    141         $LOG[] = "\r\n";
     73  // Découpe le nom de fichier : dossier/fichier/extension
     74  preg_match('#^(.*)/(.*)\.([a-z0-9]{2,4})$#i', $FilesSource[$i], $matches);
     75  $file['folder_src'] = $matches[1].'/'; // dossier d'entrée
     76  $file['folder_out'] = str_replace($CONF['DIRsource'], $CONF['DIRsortie'], $file['folder_src']); // dossier de sortie
     77  $file['name'] = $matches[2]; // nom final
     78  $file['ext'] = $matches[3]; // extension orginale
     79     
     80  // Crée les sous-dossiers de sortie & 'pwg_high' & 'thumbnail'
     81  if (!file_exists($file['folder_out'].'pwg_high') AND $CONF['DIRhighORNOT']) {
     82    mkdir_log($file['folder_out'].'pwg_high');
     83  }
     84  if (!file_exists($file['folder_out'].'thumbnail')) {
     85    mkdir_log($file['folder_out'].'thumbnail');
     86  }
     87 
     88  if (!in_arrayi($file['ext'], $CONF['allowedExt'])) {
     89    $BlockAll['main'] = true;
     90    $LOG[] = 'Not image file : '.$FilesSource[$i];
     91  }
     92 
     93  if (!isset($BlockAll)) {
     94    // Informations sur le fichier
     95    exec('include\nconvert.exe -info "'.$FilesSource[$i].'"', $FileInfos);
     96   
     97    for ($m=0; $m<=5; $m++) {
     98      unset($FileInfos[$m]);
     99    }
     100    foreach ($FileInfos as $key) {
     101      if ($key != '') {
     102        $a = explode(':', $key);
     103        $FileInfos[trim($a[0])] = trim($a[1]);
     104      }
     105    }
     106  }
     107   
     108  // Plugins pendant l'execution, haute priorité
     109  foreach ($CONF['Plugins'] as $plugin_id => $plugin_config) {
     110    if ($plugin_config['mode'] == 'ProcessHigh' AND $plugin_config['active']) {
     111      include('plugins/'.$plugin_id.'/main.php');
     112    }
     113  }
     114 
     115  // Plugins pendant l'execution
     116  foreach ($CONF['Plugins'] as $plugin_id => $plugin_config) {
     117    if ($plugin_config['mode'] == 'Process' AND $plugin_config['active']) {
     118      include('plugins/'.$plugin_id.'/main.php');
     119    }
     120  }
     121 
     122  // Compresse les fichiers dans le dossier de sortie
     123  if (!isset($BlockNormal) AND !isset($BlockAll)) {
     124    nconvert('-q '.$CONF['Qnormal'].' -out jpeg -o "'.$file['folder_out'].$file['name'].'.jpg" -dpi 72 '.$CONF['convOptions'].' -resize '.$CONF['DIMnormal'].' '.$CONF['DIMnormal'].' '.$CONF['copyNormal'].' "'.$FilesSource[$i].'"');
     125  }
     126  if (!isset($BlockThumbnail) AND !isset($BlockAll)) {
     127    nconvert('-q '.$CONF['Qthumbnail'].' -out jpeg -o "'.$file['folder_out'].'thumbnail/'.$CONF['prefixe_mini'].$file['name'].'.jpg" -dpi 72 '.$CONF['convOptions'].' -resize '.$CONF['DIMthumbnail'].' '.$CONF['DIMthumbnail'].' -rmeta -rexifthumb "'.$FilesSource[$i].'"');
     128  }
     129  if (!isset($BlockHigh) AND $CONF['DIRhighORNOT'] AND !isset($BlockAll)) {
     130    if ($CONF['DIMhdORNOT']) {
     131      nconvert('-q '.$CONF['Qhd'].' -out jpeg -o "'.$file['folder_out'].'pwg_high/'.$file['name'].'.jpg" -dpi '.$CONF['DPI'].' '.$CONF['convOptions'].' -resize '.$CONF['DIMhd'].' '.$CONF['DIMhd'].' '.$CONF['copyHD'].' "'.$FilesSource[$i].'"');
     132    } else if (strtolower($file['ext']) != 'jpg') {
     133      nconvert('-q '.$CONF['Qhd'].' -out jpeg -o "'.$file['folder_out'].'pwg_high/'.$file['name'].'.jpg" "'.$FilesSource[$i].'"');
     134    } else {
     135      copy_log($FilesSource[$i], $file['folder_out'].'pwg_high/'.$file['name'].'.jpg');
     136    }
     137  }
     138 
     139  // Réinitialise les variables
     140  unset($file, $FileInfos, $BlockNormal, $BlockThumbnail, $BlockHigh, $BlockAll);
     141  $LOG[] = "\r\n";
    142142}
    143143
     
    148148
    149149foreach($DirsSortie as $dir) {
    150         if (is_dir_empty($dir)) {
    151                 rmdir($dir);
    152         } else if ($CONF['indexORNOT']) {
    153                 copy_log('include/index.php', $dir.'/index.php');
    154         }
     150  if (is_dir_empty($dir)) {
     151    rmdir($dir);
     152  } else if ($CONF['indexORNOT']) {
     153    copy_log('include/index.php', $dir.'/index.php');
     154  }
    155155}
    156156
     
    160160### Plugins après execution ###
    161161foreach ($CONF['Plugins'] as $plugin_id => $plugin_config) {
    162         if ($plugin_config['mode'] == 'After' AND $plugin_config['active']) {
    163                 include('plugins/'.$plugin_id.'/main.php');
    164         }
     162  if ($plugin_config['mode'] == 'After' AND $plugin_config['active']) {
     163    include('plugins/'.$plugin_id.'/main.php');
     164  }
    165165}
    166166?>
Note: See TracChangeset for help on using the changeset viewer.