Ignore:
Timestamp:
Apr 12, 2011, 7:45:22 PM (13 years ago)
Author:
mistic100
Message:

new version 1.4, new plugin for Charlies Content, NConvert updated

File:
1 edited

Legend:

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

    r9265 r10337  
    11<?php
     2
    23// Affiche les textes localisés
    34function l10n($code) {
     
    2223        while ($file = readdir($dh)) {
    2324                if ($file !== '.' && $file !== '..' && is_dir('language/'.$file)) {
    24                         $name = (file_exists('language/'.$file.'/'.$file.'.txt')) ? file_get_contents('language/'.$file.'/'.$file.'.txt') : $file;
     25                        $name = (file_exists('language/'.$file.'/iso.txt')) ? file_get_contents('language/'.$file.'/iso.txt') : $file;
    2526                        $languages[$file] = $name;
    2627                }
     
    6667                return preg_replace($search, $replace, $string);
    6768        } else {
    68                 return str_replace(array('%','$'), '_', $string);
     69                return str_replace(array('%','$',' '), '_', $string);
    6970        }
    7071}
     
    121122        $content = array();
    122123        foreach ($xml as $nom => $elem) {
    123                 if (trim($elem) == '') {
     124                if (trim($elem) == '' AND $elem != '') {
    124125                        $content[$nom] = XMLParse($elem->children());
    125126                } else {
     
    165166                                $array[$key] = true;           
    166167                        } else if ($value === 'false') {
    167                                 $array[$key] = false;           
     168                                $array[$key] = false;   
     169                        } else if ($value == null) {
     170                                // rien à faire ^^
    168171                        } else if (preg_match('#^([0-9]*)$#', $value)) {
    169172                                settype($array[$key], 'int');           
     
    247250// Verifie si une chaine est un nombre décimal (plus strict que is_numeric qui fonctionne avec les hexadecimaux)
    248251function is_decimal($num) {
    249         if(is_numeric($num) === true AND (float)$num == $num) {
     252        if((is_numeric($num) === true AND (float)$num == $num) OR $num === '0') {
    250253                return true;
    251254        } else {
     
    257260function load_plugin_lang($plugin_id) {
    258261        global $CONF, $Lang;
    259         if (file_exists('plugins/'.$plugin_id.'/lang/'.$CONF['user_lang'].'.php')) {
    260                 include('plugins/'.$plugin_id.'/lang/'.$CONF['user_lang'].'.php');
    261         } else {
    262                 include('plugins/'.$plugin_id.'/lang/en_UK.php');
    263         }
    264 }
     262        if (file_exists('plugins/'.$plugin_id.'/language/'.$CONF['user_lang'].'.php')) {
     263                include('plugins/'.$plugin_id.'/language/'.$CONF['user_lang'].'.php');
     264        } else {
     265                include('plugins/'.$plugin_id.'/language/en_UK.php');
     266        }
     267}
     268
     269// fonction nconvert avec gestion du log
     270function nconvert($param, $log=true) {
     271        global $LOG;
     272
     273        exec('include\nconvert.exe '. $param .' 2>&1', $out);
     274       
     275        if ($log) {
     276                for ($i=0; $i<=3; $i++)
     277                        unset($out[$i]);
     278                if (count($out)) $LOG[] = array_values($out);
     279                //$LOG[] = "\t" . $param;
     280        } else {
     281                return $out;
     282        }
     283}
     284
     285// fonction mkdir avec gestion du log
     286function mkdir_log($dir) {
     287        global $LOG;
     288        mkdir($dir, 0777, true);
     289        $LOG[] = 'Dir '.$dir.' created';
     290}
     291
     292// fonction copy avec gestion du log
     293function copy_log($src, $dest) {
     294        global $LOG;
     295        copy($src, $dest);
     296        $LOG[] = 'Copy '.$src.' to '.$dest;
     297}
     298
     299// fonction rename avec gestion du log
     300function rename_log($path, $new_path, $move=false) {
     301        global $LOG;
     302        rename($path, $new_path);
     303        if ($move)
     304                $LOG[] = 'Move '.$path.' to '.$new_path;
     305        else
     306                $LOG[] = 'Rename '.$path.' into '.$new_path;
     307}
     308
     309// enregistre le log dans un fichier
     310function print_log($nb, $s) {
     311        global $APPversion, $LOG;
     312       
     313        $config = file_get_contents('config.xml');
     314       
     315        $string =
     316                "PHP Optimisateur " . $APPversion . "\r\n".
     317                date('r') . "\r\n".
     318                $nb . " files in " . $s . " seconds" . "\r\n\r\n".
     319               
     320                $config . "\r\n\r\n";
     321       
     322        foreach ($LOG as $event) {
     323                if (is_array($event)) {
     324                        $string .= implode("\r\n", $event) . "\r\n";
     325                } else {
     326                        $string .= $event . "\r\n";
     327                }
     328        }
     329       
     330        if (!file_exists('logs')) {
     331                mkdir('logs', 0777, true);
     332        }
     333       
     334        $filename = 'log_' . date('Y-m-d_H-i-s') . '.txt';
     335        file_put_contents('logs/'.$filename, $string);
     336        return $filename;
     337}
     338
     339// case insentive version of in_array
     340function in_arrayi($needle, $haystack) {
     341        $needle = strtolower($needle);
     342        $haystack = array_map('strtolower', $haystack);
     343        return in_array($needle, $haystack);
     344}
     345
    265346?>
Note: See TracChangeset for help on using the changeset viewer.