Ignore:
Timestamp:
Sep 5, 2012, 4:15:54 PM (12 years ago)
Author:
grum
Message:

version 0.1.0b

. Fix install bugs
. Manage anonymous directories
. Manage CSV export options settings
. Fix IPadress<=>country association bug & improve join performances
. Fix bug on IP filter
. Improve performances for history consult

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/EStat/estat_root.class.inc.php

    r17737 r17758  
    5757
    5858    protected $fileStatDir='';
     59    protected $fileExportDir='';
    5960
    6061    public function __construct($prefixeTable, $filelocation)
     
    6364      $this->setPluginNameFiles("estat");
    6465      parent::__construct($prefixeTable, $filelocation);
     66      $this->loadConfig();
    6567      $this->section_name=$this->getPluginNameFiles();
    66       $this->fileStatDir=GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.self::DATA_DIRECTORY;
     68      $this->setFileStatDir();
    6769    }
    6870
     
    7274    public function initConfig()
    7375    {
    74       //global $user;
     76      global $user;
     77
     78      $lang='';
     79      if(isset($user['language'])) $lang=$user['language'];
     80
     81      switch($lang)
     82      {
     83        case 'fr_FR':
     84          $csvExport=array(
     85            'export.csv.separator' => ';',
     86            'export.csv.decimalDot' => ','
     87          );
     88          break;
     89        default:
     90          $csvExport=array(
     91            'export.csv.separator' => ',',
     92            'export.csv.decimalDot' => '.'
     93          );
     94          break;
     95      }
     96
    7597      $this->config=array(
     98        'installed' => '00.00.00',
    7699        'plugin.newInstall' => 'y',
    77100        'plugin.active' => 'n',
    78101        'plugin.historyImported' => 'n',
    79102        'plugin.ipCountryBuild' => 'n',
     103        'plugin.pathKey' => '',          // key to be used to know path where are stored the SQLite files
    80104
    81105        'build.delay' => '+24hours',     // delay between 2 consolidation
     
    86110
    87111        'global.itemPerPage' => 250,
     112
     113        'export.csv.separator' => $csvExport['export.csv.separator'],
     114        'export.csv.decimalDot' => $csvExport['export.csv.decimalDot'],
     115        'export.csv.useQuotes' => 'y',
     116        'export.csv.lineFeed' => 'unix',
     117        'export.ods.fileTitle' => '',
     118        'export.ods.keywords' => '',
    88119
    89120        'logs.reverseDNS' => 'n',
     
    233264
    234265
     266
     267
     268
     269    /**
     270     * set the value for $fileStatDir & $fileExportDir
     271     * $rootPath is the root path where are stored the SQLite data files
     272     *  example: (...)/local/plugins/EStat/Data/
     273     *
     274     * This path is known is public and can be found by everyone. To forbid the
     275     * download of files stored in this directory, a random key is added in the
     276     * path
     277     *  example: (...)/local/plugins/EStat/Data-ABCDEF0123456789/
     278     *
     279     * The random key is stored in config file:
     280     *  . if key is not set, try to find the directory
     281     *  . if key is set but directory doesn't exist, try to find the directory
     282     *  . if there's no key and no directory found, the key is created and saved
     283     *
     284     * the $fileStatDir provide the complete path with the key
     285     * the $fileExportDir path gets the same key than $fileStatDir
     286     *
     287     * @return String: $fileStatDir value
     288     */
     289    protected function setFileStatDir()
     290    {
     291      $rootPath=GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.self::DATA_DIRECTORY;
     292
     293      $path=substr($rootPath,0,-1).'-'.$this->config['plugin.pathKey'];
     294      if(file_exists($path) and $this->config['plugin.pathKey']!='')
     295      {
     296        $this->fileStatDir=$path;
     297        $this->fileExportDir=GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.substr(self::EXPORT_DIRECTORY,0,-1).'-'.$this->config['plugin.pathKey'].'/';
     298        return($this->fileStatDir);
     299      }
     300
     301      // key is empty or directory doesn't exist, try to find the diretory
     302      $path=$this->findDirectory(substr($rootPath,0,-1).'-');
     303      if(file_exists($path))
     304      {
     305        $this->fileStatDir=$path;
     306        $path=explode('-', basename($path)); // /xxx/xxx/xxx/data-abcdef012 => array('data', 'abcdef012')
     307        $this->config['plugin.pathKey']=$path[1];
     308        $this->saveConfig();
     309        $this->fileExportDir=GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.substr(self::EXPORT_DIRECTORY,0,-1).'-'.$this->config['plugin.pathKey'].'/';
     310        return($this->fileStatDir);
     311      }
     312
     313      // no directory found, create the key
     314      $this->config['plugin.pathKey']=strtoupper(md5(date('Ymd-His').rand(0,65536)));
     315      $this->saveConfig();
     316      $this->fileStatDir=substr($rootPath,0,-1).'-'.$this->config['plugin.pathKey'];
     317      $this->fileExportDir=GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.substr(self::EXPORT_DIRECTORY,0,-1).'-'.$this->config['plugin.pathKey'].'/';
     318      return($this->fileStatDir);
     319    }
     320
     321    /**
     322     * try to find a directory in the $path
     323     *  exemple:
     324     *     $path = /local/plugins/EStat/Data-
     325     *     => try to find all directory macthing with /local/plugins/EStat/Data-*
     326     *
     327     * @param String $path:
     328     * @return String: found path or empty string if nothing is found
     329     */
     330    private function findDirectory($path)
     331    {
     332      $dirname=dirname($path);
     333      if(!file_exists($dirname)) return('');
     334      $baseName=baseName($path);
     335      $dirContent=scandir($dirname);
     336      foreach($dirContent as $file)
     337      {
     338        if($file!='.' and $file!='..' and is_dir($dirname.'/'.$file) and strpos($file, $baseName)!==false)
     339        {
     340          return($dirname.'/'.$file);
     341        }
     342      }
     343      return('');
     344    }
     345
     346
     347
     348
    235349    /*
    236350     * -------------------------------------------------------------------------
     
    357471    }
    358472
    359 
    360 
    361 
    362473  } //class
     474
    363475
    364476
Note: See TracChangeset for help on using the changeset viewer.