Changeset 17758


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

Location:
extensions/EStat
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • extensions/EStat/admin.php

    r17737 r17758  
    2727  $config=Array();
    2828  GPCCore::loadConfig('estat', $config);
    29 
    3029
    3130  if($config['installed']!=ESTAT_VERSION2)
  • extensions/EStat/admin/estat_admin.tpl

    r17737 r17758  
    55  var translateString={
    66      {/literal}
    7         dateTime:'{"estat_datetime"|@translate}',
    8         ip_user:'{"estat_ip_user"|@translate}',
    9         ipAdress:'{"estat_ipAdress"|@translate}',
    10         country:'{"estat_country"|@translate}',
    11         album:'{"estat_category"|@translate}',
    12         image:'{"estat_image"|@translate}',
    13         tags:'{"estat_tags"|@translate}',
    14         section:'{"estat_section"|@translate}',
    15         browser:'{"estat_browser"|@translate}',
    16         os:'{"estat_os"|@translate}',
    17         type:'{"estat_type"|@translate}',
    18         engine:'{"estat_engine"|@translate}',
    19         item_nb:'{"estat_item_nb"|@translate}',
    20         items_nb:'{"estat_items_nb"|@translate}',
    21         events:'{"estat_events"|@translate}',
    22         ok:'{"estat_ok"|@translate}',
    23         cancel:'{"estat_cancel"|@translate}',
    24         eraseFilter:'{"estat_eraseFilter"|@translate}',
    25         sortBy:'{"estat_sortBy"|@translate}',
    26         ip_nb:'{"estat_ip_nb"|@translate}',
    27         ips_nb:'{"estat_ips_nb"|@translate}',
    28         category_nb:'{"estat_category_nb"|@translate}',
    29         categories_nb:'{"estat_categories_nb"|@translate}',
    30         image_nb:'{"estat_image_nb"|@translate}',
    31         images_nb:'{"estat_images_nb"|@translate}',
    32         dataExport:'{"estat_dataExport"|@translate}',
     7        dateTime:"{'estat_datetime'|@translate}",
     8        ip_user:"{'estat_ip_user'|@translate}",
     9        ipAdress:"{'estat_ipAdress'|@translate}",
     10        country:"{'estat_country'|@translate}",
     11        album:"{'estat_category'|@translate}",
     12        image:"{'estat_image'|@translate}",
     13        tags:"{'estat_tags'|@translate}",
     14        section:"{'estat_section'|@translate}",
     15        browser:"{'estat_browser'|@translate}",
     16        os:"{'estat_os'|@translate}",
     17        type:"{'estat_type'|@translate}",
     18        engine:"{'estat_engine'|@translate}",
     19        item_nb:"{'estat_item_nb'|@translate}",
     20        items_nb:"{'estat_items_nb'|@translate}",
     21        events:"{'estat_events'|@translate}",
     22        ok:"{'estat_ok'|@translate}",
     23        cancel:"{'estat_cancel'|@translate}",
     24        eraseFilter:"{'estat_eraseFilter'|@translate}",
     25        sortBy:"{'estat_sortBy'|@translate}",
     26        dataExport:"{'estat_dataExport'|@translate}",
    3327
    34         allYear:'{"estat_allYear"|@translate}',
    35         year:'{"estat_year"|@translate}',
    36         viewedPages:'{"estat_viewedPages"|@translate}',
    37         viewedAlbums:'{"estat_viewedAlbums"|@translate}',
    38         viewedImages:'{"estat_viewedImages"|@translate}',
    39         uniqueIP:'{"estat_uniqueIP"|@translate}',
    40         visits:'{"estat_visits"|@translate}',
    41         period:'{"estat_period"|@translate}',
     28        allYear:"{'estat_allYear'|@translate}",
     29        year:"{'estat_year'|@translate}",
     30        viewedPages:"{'estat_viewedPages'|@translate}",
     31        viewedAlbums:"{'estat_viewedAlbums'|@translate}",
     32        viewedImages:"{'estat_viewedImages'|@translate}",
     33        uniqueIP:"{'estat_uniqueIP'|@translate}",
     34        visits:"{'estat_visits'|@translate}",
     35        period:"{'estat_period'|@translate}",
    4236
    43         fileFormatCSV:'{"estat_fileFormatCSV"|@translate}',
    44         fileFormatODS:'{"estat_fileFormatODS"|@translate}',
    45         fileFormatSQLite:'{"estat_fileFormatSQLite"|@translate}',
     37        fileFormatCSV:"{'estat_fileFormatCSV'|@translate}",
     38        fileFormatODS:"{'estat_fileFormatODS'|@translate}",
     39        fileFormatSQLite:"{'estat_fileFormatSQLite'|@translate}",
    4640
    47         fileCompressionNone:'{"estat_fileCompressionNone"|@translate}',
    48         fileCompressionZIP:'{"estat_fileCompressionZIP"|@translate}',
    49         fileCompressionGZ:'{"estat_fileCompressionGZ"|@translate}',
    50         fileCompressionBZ2:'{"estat_fileCompressionBZ2"|@translate}',
     41        fileCompressionNone:"{'estat_fileCompressionNone'|@translate}",
     42        fileCompressionZIP:"{'estat_fileCompressionZIP'|@translate}",
     43        fileCompressionGZ:"{'estat_fileCompressionGZ'|@translate}",
     44        fileCompressionBZ2:"{'estat_fileCompressionBZ2'|@translate}",
    5145
    52         downloadError:'{"estat_downloadError"|@translate}',
    53         waitForDownload:'{"estat_waitForDownload"|@translate}',
     46        downloadError:"{'estat_downloadError'|@translate}",
     47        waitForDownload:"{'estat_waitForDownload'|@translate}",
    5448
    55         total:'{"estat_total"|@translate}',
    56         ua_Mobile:'{"ua_Mobile"|@translate}',
    57         ua_Computer:'{"ua_Computer"|@translate}',
    58         ua_Console:'{"ua_Console"|@translate}',
    59         ua_Unknown:'{"ua_Unknown"|@translate}',
    60         ua_Crawler:'{"ua_Crawler"|@translate}',
    61         ua_Other:'{"ua_Other"|@translate}',
     49        total:"{'estat_total'|@translate}",
     50        ua_Mobile:"{'ua_Mobile'|@translate}",
     51        ua_Computer:"{'ua_Computer'|@translate}",
     52        ua_Console:"{'ua_Console'|@translate}",
     53        ua_Unknown:"{'ua_Unknown'|@translate}",
     54        ua_Crawler:"{'ua_Crawler'|@translate}",
     55        ua_Other:"{'ua_Other'|@translate}",
    6256      {literal}
    6357
    6458        filter:{
    6559      {/literal}
    66           dateTime:'{"estat_datetime"|@translate}',
    67           ipAdress:'{"estat_ipAdress"|@translate}',
    68           country:'{"estat_country"|@translate}',
    69           section:'{"estat_section"|@translate}',
    70           browser:'{"estat_browser"|@translate}',
    71           os:'{"estat_os"|@translate}',
    72           type:'{"estat_type"|@translate}',
    73           engine:'{"estat_engine"|@translate}'
     60          dateTime:"{'estat_datetime'|@translate}",
     61          ipAdress:"{'estat_ipAdress'|@translate}",
     62          country:"{'estat_country'|@translate}",
     63          section:"{'estat_section'|@translate}",
     64          browser:"{'estat_browser'|@translate}",
     65          os:"{'estat_os'|@translate}",
     66          type:"{'estat_type'|@translate}",
     67          engine:"{'estat_engine'|@translate}"
    7468      {literal}
    7569        }
     
    7872    inputFilterBoxLang={
    7973    {/literal}
    80       'Operator':'{"filter_operator"|@translate}',
    81       'Value':'{"filter_value"|@translate}',
    82       'MinValue':'{"filter_minValue"|@translate}',
    83       'MaxValue':'{"filter_maxValue"|@translate}',
    84       '>':'{"filter_gt"|@translate}',
    85       '<':'{"filter_lt"|@translate}',
    86       '>=':'{"filter_ge"|@translate}',
    87       '<=':'{"filter_le"|@translate}',
    88       '=':'{"filter_equal"|@translate}',
    89       '!=':'{"filter_notEqual"|@translate}',
    90       'between':'{"filter_between"|@translate}',
    91       'and':'{"filter_and"|@translate}',
    92       'like':'{"filter_like"|@translate}',
    93       'not like':'{"filter_notLike"|@translate}',
     74      'Operator':"{'filter_operator'|@translate}",
     75      'Value':"{'filter_value'|@translate}",
     76      'MinValue':"{'filter_minValue'|@translate}",
     77      'MaxValue':"{'filter_maxValue'|@translate}",
     78      '>':"{'filter_gt'|@translate}",
     79      '<':"{'filter_lt'|@translate}",
     80      '>=':"{'filter_ge'|@translate}",
     81      '<=':"{'filter_le'|@translate}",
     82      '=':"{'filter_equal'|@translate}",
     83      '!=':"{'filter_notEqual'|@translate}",
     84      'between':"{'filter_between'|@translate}",
     85      'not between':"{'filter_notbetween'|@translate}",
     86      'and':"{'filter_and'|@translate}",
     87      'like':"{'filter_like'|@translate}",
     88      'not like':"{'filter_notLike'|@translate}",
    9489      'invalidParam':"{'filter_invalid'|@translate}"
    9590    {literal}
     
    9792    inputExportBoxLang={
    9893    {/literal}
    99       'export':'{"export_dialogTitle"|@translate}',
    100       'name':'{"export_Name"|@translate}',
    101       'format':'{"export_Format"|@translate}',
    102       'compression':'{"export_Compression"|@translate}'
     94      'export':"{'export_dialogTitle'|@translate}",
     95      'name':"{'export_Name'|@translate}",
     96      'format':"{'export_Format'|@translate}",
     97      'compression':"{'export_Compression'|@translate}"
    10398    {literal}
    10499    };
  • extensions/EStat/estat_ajax.php

    r17737 r17758  
    475475
    476476      $gStatFile=new StatDBGlobal($this->fileStatDir, self::FILE_GLOBAL);
    477       $gStatFile->setIpCountryFile(ESTAT_PATH.'data/ipCountry.db');
     477      $gStatFile->setIpCountryFile($this->fileStatDir.'/'.self::FILE_COUNTRY.'.db', true);
    478478      $gStatFile->open(ASDF_OPEN_WRITE);
    479479      if($gStatFile->getInfoProperty('log', 'startImport')==null)
     
    575575
    576576      // prepare an EStat_IdList to buid a list of unique Id
    577       $idList=new EStat_IdList(array('catId', 'imageId', 'tagsId', 'userId', 'IPadress'));
     577      $idList=new EStat_IdList(array('catId', 'imageId', 'tagsId', 'userId'));
    578578      // $idAssoc will get the label associated to the id
    579579      $idAssoc=array(
     
    581581        'imageId'=>array(),
    582582        'tagsId'=>array(),
    583         'userId'=>array(),
    584         'IPadress'=>array()
     583        'userId'=>array()
    585584      );
    586585
     
    612611        $this->prepareIdList($idAssoc, 'userId', "SELECT id, username AS name FROM ".USERS_TABLE." WHERE id IN (".implode(',', $idList->getItems('userId')).") ORDER BY id;");
    613612
    614       // for reverse DNS
    615       if($this->config['logs.ipCountry']=='y')
    616         $this->getIpInfos($idAssoc, $idList->getItems('IPadress'));
    617 
    618613      // complete the data
    619614      foreach($returned['rows'] as $key=>$row)
     
    636631          'date' => date('Y-m-d H:i:s', $row['date']),
    637632          'IpUserId' => ($row['userId']==2)?$row['IPadress']:$this->getId($idAssoc, 'userId', $row['userId'], $row['IPadress'], 'name'),
    638           //'country' => $row['country'],
     633          'country' => $row['country'],
    639634          'catId' => GPCCore::getUserLanguageDesc($this->getId($idAssoc, 'catId', $row['catId'], ($row['catId']==0)?'-':'?')),
    640635          'imageId' => $this->getId($idAssoc, 'imageId', $row['imageId'], ($row['imageId']==0)?'-':'?', 'name'),
     
    702697        if($row['userId']==2)
    703698        {
    704           $ipInfo=$this->getId($idAssoc, 'IPadress', $tmp['IpUserId'], '?');
    705699          if($this->config['logs.reverseDNS']=='y')
    706700          {/*
     
    716710          }
    717711
    718           if($ipInfo['country']!='--' and $ipInfo['country']!='XA')
     712          if($row['country']!='--' and $row['country']!='XA')
    719713          {
    720             $tmp['IpUserId'].='<span class="geoip">[<a href="http://www.geoiptool.com/fr/?IP='.$tmp['IpUserId'].'">'.$ipInfo['country'].'</a>]</span>';
     714            $tmp['IpUserId'].='<span class="geoip">[<a href="http://www.geoiptool.com/fr/?IP='.$tmp['IpUserId'].'">'.$row['country'].'</a>]</span>';
    721715          }
    722716          else
  • extensions/EStat/estat_ajax_export.php

    r17737 r17758  
    238238
    239239      // prepare an EStat_IdList to buid a list of unique Id
    240       $idList=new EStat_IdList(array('catId', 'imageId', 'tagsId', 'userId', 'IPadress'));
     240      $idList=new EStat_IdList(array('catId', 'imageId', 'tagsId', 'userId'));
    241241      // $idAssoc will get the label associated to the id
    242242      $idAssoc=array(
     
    244244        'imageId'=>array(),
    245245        'tagsId'=>array(),
    246         'userId'=>array(),
    247         'IPadress'=>array()
     246        'userId'=>array()
    248247      );
    249248
     
    256255            'imageId' => $row['imageId'],
    257256            'tagsId' => $row['tagsId'],
    258             'userId' => $row['userId'],
    259             'IPadress' => $row['IPadress']
     257            'userId' => $row['userId']
    260258          )
    261259        );
     
    274272      if(count($idList->getItems('userId')) > 0)
    275273        $this->prepareIdList($idAssoc, 'userId', "SELECT id, username AS name FROM ".USERS_TABLE." WHERE id IN (".implode(',', $idList->getItems('userId')).") ORDER BY id;");
    276 
    277       // for reverse DNS
    278       if($this->config['logs.ipCountry']=='y')
    279         $this->getIpInfos($idAssoc, $idList->getItems('IPadress'));
    280274
    281275      $data=array();
     
    283277      foreach($result as $row)
    284278      {
    285         $ipInfo=$this->getId($idAssoc, 'IPadress', $row['IPadress'], '?');
    286 
    287279        $userAgentNfo=GPCUserAgent::getProperties(
    288280            array(
     
    298290        if($userAgentNfo[UA_DATA_OS_NAME]=='Unknown') $userAgentNfo[UA_DATA_OS_NAME]='ua_Unknown';
    299291
    300         $country=l10n('estat_country_'.strtoupper($ipInfo['country']));
     292        $country=l10n('estat_country_'.strtoupper($row['country']));
    301293        if(isset($lang[$country]))
    302294        {
     
    314306          'UserId' => $row['userId'],
    315307          'UserName' => $this->getId($idAssoc, 'userId', $row['userId'], '?', 'name'),
    316           'countryId' => $ipInfo['country'],
     308          'countryId' => $row['country'],
    317309          'country' => $country,
    318310          'catId' => $row['catId'],
     
    345337          $export->setOptions(
    346338              array(
    347                 'separator' => ';',
    348                 'decimalDot' => ',',
    349                 'useQuotes' => true,
    350                 'lineFeed' => 'unix'
     339                'separator' => $this->config['export.csv.separator'],
     340                'decimalDot' => $this->config['export.csv.decimalDot'],
     341                'useQuotes' => ($this->config['export.csv.useQuotes']=='y')?true:false,
     342                'lineFeed' => $this->config['export.csv.lineFeed'],
    351343              )
    352344            );
     
    386378              array(
    387379                'sheetName' => l10n('estat_history'),
    388                 'fileTitle' => '',
     380                'fileTitle' => $this->config['export.ods.fileTitle'],
    389381                'fileSubject' => sprintf(l10n('estat_fileODSSubject'), l10n('estat_history')),
    390                 'keywords' => '',
     382                'keywords' => $this->config['export.ods.keywords'],
    391383                'comments' => sprintf(l10n('estat_fileODSComments_1'), date('Y-m-d@H:i:s'), ESTAT_VERSION, PHPWG_VERSION)
    392384              )
     
    460452      }
    461453      $export->setFileName($name.$extension);
    462       $export->setFileDir(GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.self::EXPORT_DIRECTORY);
     454      $export->setFileDir($this->fileExportDir);
    463455
    464456      if($export->write($data))
    465457      {
    466         $file=GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.self::EXPORT_DIRECTORY.$export->getFileName();
     458        $file=$this->fileExportDir.$export->getFileName();
    467459
    468460        if($compression!='none')
     
    623615          $export->setOptions(
    624616              array(
    625                 'separator' => ';',
    626                 'decimalDot' => ',',
    627                 'useQuotes' => true,
    628                 'lineFeed' => 'unix'
     617                'separator' => $this->config['export.csv.separator'],
     618                'decimalDot' => $this->config['export.csv.decimalDot'],
     619                'useQuotes' => ($this->config['export.csv.useQuotes']=='y')?true:false,
     620                'lineFeed' => $this->config['export.csv.lineFeed'],
    629621              )
    630622            );
     
    646638              array(
    647639                'sheetName' => l10n('estat_ipAdress'),
    648                 'fileTitle' => '',
     640                'fileTitle' => $this->config['export.ods.fileTitle'],
    649641                'fileSubject' => sprintf(l10n('estat_fileODSSubject'), l10n('estat_by_ip')),
    650                 'keywords' => '',
     642                'keywords' => $this->config['export.ods.keywords'],
    651643                'comments' => sprintf(l10n('estat_fileODSComments_1'), date('Y-m-d@H:i:s'), ESTAT_VERSION, PHPWG_VERSION)
    652644              )
     
    668660          $export->setOptions(
    669661              array(
    670                 'tableName' => 'history'
     662                'tableName' => 'ipAdress'
    671663              )
    672664            );
     
    684676      }
    685677      $export->setFileName($name.$extension);
    686       $export->setFileDir(GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.self::EXPORT_DIRECTORY);
     678      $export->setFileDir($this->fileExportDir);
    687679
    688680      if($export->write($data))
    689681      {
    690         $file=GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.self::EXPORT_DIRECTORY.$export->getFileName();
     682        $file=$this->fileExportDir.$export->getFileName();
    691683
    692684        if($compression!='none')
     
    852844          $export->setOptions(
    853845              array(
    854                 'separator' => ';',
    855                 'decimalDot' => ',',
    856                 'useQuotes' => true,
    857                 'lineFeed' => 'unix'
     846                'separator' => $this->config['export.csv.separator'],
     847                'decimalDot' => $this->config['export.csv.decimalDot'],
     848                'useQuotes' => ($this->config['export.csv.useQuotes']=='y')?true:false,
     849                'lineFeed' => $this->config['export.csv.lineFeed'],
    858850              )
    859851            );
     
    873865          $export->setOptions(
    874866              array(
    875                 'sheetName' => l10n('estat_ipAdress'),
    876                 'fileTitle' => '',
    877                 'fileSubject' => sprintf(l10n('estat_fileODSSubject'), l10n('estat_by_ip')),
    878                 'keywords' => '',
     867                'sheetName' => l10n('estat_category'),
     868                'fileTitle' => $this->config['export.ods.fileTitle'],
     869                'fileSubject' => sprintf(l10n('estat_fileODSSubject'), l10n('estat_by_category')),
     870                'keywords' => $this->config['export.ods.keywords'],
    879871                'comments' => sprintf(l10n('estat_fileODSComments_1'), date('Y-m-d@H:i:s'), ESTAT_VERSION, PHPWG_VERSION)
    880872              )
     
    895887          $export->setOptions(
    896888              array(
    897                 'tableName' => 'history'
     889                'tableName' => 'album'
    898890              )
    899891            );
     
    910902      }
    911903      $export->setFileName($name.$extension);
    912       $export->setFileDir(GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.self::EXPORT_DIRECTORY);
     904      $export->setFileDir($this->fileExportDir);
    913905
    914906      if($export->write($data))
    915907      {
    916         $file=GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.self::EXPORT_DIRECTORY.$export->getFileName();
     908        $file=$this->fileExportDir.$export->getFileName();
    917909
    918910        if($compression!='none')
     
    10901082          $export->setOptions(
    10911083              array(
    1092                 'separator' => ';',
    1093                 'decimalDot' => ',',
    1094                 'useQuotes' => true,
    1095                 'lineFeed' => 'unix'
     1084                'separator' => $this->config['export.csv.separator'],
     1085                'decimalDot' => $this->config['export.csv.decimalDot'],
     1086                'useQuotes' => ($this->config['export.csv.useQuotes']=='y')?true:false,
     1087                'lineFeed' => $this->config['export.csv.lineFeed'],
    10961088              )
    10971089            );
     
    11131105          $export->setOptions(
    11141106              array(
    1115                 'sheetName' => l10n('estat_ipAdress'),
    1116                 'fileTitle' => '',
    1117                 'fileSubject' => sprintf(l10n('estat_fileODSSubject'), l10n('estat_by_ip')),
    1118                 'keywords' => '',
     1107                'sheetName' => l10n('estat_image'),
     1108                'fileTitle' => $this->config['export.ods.fileTitle'],
     1109                'fileSubject' => sprintf(l10n('estat_fileODSSubject'), l10n('estat_by_image')),
     1110                'keywords' => $this->config['export.ods.keywords'],
    11191111                'comments' => sprintf(l10n('estat_fileODSComments_1'), date('Y-m-d@H:i:s'), ESTAT_VERSION, PHPWG_VERSION)
    11201112              )
     
    11371129          $export->setOptions(
    11381130              array(
    1139                 'tableName' => 'history'
     1131                'tableName' => 'image'
    11401132              )
    11411133            );
     
    11541146      }
    11551147      $export->setFileName($name.$extension);
    1156       $export->setFileDir(GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.self::EXPORT_DIRECTORY);
     1148      $export->setFileDir($this->fileExportDir);
    11571149
    11581150      if($export->write($data))
    11591151      {
    1160         $file=GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.self::EXPORT_DIRECTORY.$export->getFileName();
     1152        $file=$this->fileExportDir.$export->getFileName();
    11611153
    11621154        if($compression!='none')
     
    11851177    private function ajax_estat_export_admin_loadFile($name, $deleteFile=true)
    11861178    {
    1187       $file=GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.self::EXPORT_DIRECTORY.$name;
     1179      $file=$this->fileExportDir.$name;
    11881180      if(!file_exists($file))
    11891181        do_error(404, "Requested file not readable - $name");
  • extensions/EStat/estat_install.class.inc.php

    r17737 r17758  
    2626    public function install()
    2727    {
    28       if(!file_exists($this->fileStatDir))
    29           mkdir($this->fileStatDir, 0755, true);
    30 
     28      $this->checkDirectories();
    3129      $this->initConfig();
    3230      $this->loadConfig();
     
    5149    public function uninstall()
    5250    {
    53       //GPCCore::rmDir(dirname(GPCCore::getPiwigoSystemPath().'/'.PWG_LOCAL_DIR.self::DATA_DIRECTORY));
     51      //GPCCore::rmDir(dirname($this->fileStatDir));
    5452      $this->deleteConfig();
    5553      GPCCore::unregister($this->getPluginName());
     
    5957    public function activate()
    6058    {
     59      $this->checkDirectories();
    6160      $this->initConfig();
    6261      $this->loadConfig();
     
    7069      switch($this->config['installed'])
    7170      {
    72         case '01.00.00':
    73           //$this->updateFrom_010000();
     71        case '00.01.00b':
     72          //$this->updateFrom_000100b();
    7473        default:
    7574          // nothing to do...
     
    9089
    9190    /**
    92      * update from release 1.0.0
     91     * update from release 0.1.0b
    9392     *
    9493     *  -- dummy --
    9594     *
    9695     */
    97     private function updateFrom_010000()
     96    private function updateFrom_000100b()
    9897    {
    9998      return(false);
     
    123122    }
    124123
     124    /**
     125     * create the local directories & copy index.php files
     126     *
     127     */
     128    private function checkDirectories()
     129    {
     130      if(!file_exists($this->fileStatDir))
     131          mkdir($this->fileStatDir, 0755, true);
     132
     133      if(!file_exists($this->fileExportDir))
     134          mkdir($this->fileExportDir, 0755, true);
     135
     136
     137      if(!file_exists($this->fileStatDir.'/index.php'))
     138        copy(ESTAT_PATH.'index.php', $this->fileStatDir.'/index.php');
     139
     140      if(!file_exists(dirname($this->fileStatDir).'/index.php'))
     141        copy(ESTAT_PATH.'index.php', dirname($this->fileStatDir).'/index.php');
     142
     143      if(!file_exists($this->fileExportDir.'/index.php'))
     144        copy(ESTAT_PATH.'index.php', $this->fileExportDir.'/index.php');
     145
     146      if(!file_exists(dirname($this->fileExportDir).'/index.php'))
     147        copy(ESTAT_PATH.'index.php', dirname($this->fileExportDir).'/index.php');
     148    }
     149
    125150  } //class
    126151
  • 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
  • extensions/EStat/js/estatPM.js

    r17737 r17758  
    600600                          regexp:'\d{1,3}(?:\.\d{1,3}){0,3}'
    601601                        },
    602                       defaultOperator:'=',
    603                       filterOperators:['=', '!=', 'between']
     602                      defaultOperator:'like',
     603                      filterOperators:['like', 'not like', 'between', 'not between']
    604604                    },
    605605                  group:true,
     
    665665            footerString:
    666666              {
    667                 singular:translateString.ip_nb,
    668                 plural:translateString.ips_nb,
     667                singular:translateString.item_nb,
     668                plural:translateString.items_nb,
    669669                waitForDownload:translateString.waitForDownload
    670670              },
     
    939939            footerString:
    940940              {
    941                 singular:translateString.category_nb,
    942                 plural:translateString.categories_nb,
     941                singular:translateString.item_nb,
     942                plural:translateString.items_nb,
    943943                waitForDownload:translateString.waitForDownload
    944944              },
     
    11101110            footerString:
    11111111              {
    1112                 singular:translateString.image_nb,
    1113                 plural:translateString.images_nb,
     1112                singular:translateString.item_nb,
     1113                plural:translateString.items_nb,
    11141114                waitForDownload:translateString.waitForDownload
    11151115              },
     
    12521252                        },
    12531253                      defaultOperator:'between',
    1254                       filterOperators:['>', '<', '>=', '<=', '=', '!=', 'between']
     1254                      filterOperators:['>', '<', '>=', '<=', '=', '!=', 'between', 'not between']
    12551255                    },
    12561256                  sortable:'asc',
     
    12671267                          regexp:'\d{1,3}(?:\.\d{1,3}){0,3}'
    12681268                        },
    1269                       defaultOperator:'=',
    1270                       filterOperators:['=', '!=', 'between']
     1269                      defaultOperator:'like',
     1270                      filterOperators:['like', 'not like', 'between', 'not between']
    12711271                    },
    12721272                  sortable:'asc',
     
    14121412            saveButtonClick: function (event, data)
    14131413              {
    1414                 $('#iHistoryTable').dynamicTable('waitForDownload', true);
    14151414                $.dialogExport(
    14161415                  {
  • extensions/EStat/language/en_UK/plugin.lang.php

    r17737 r17758  
    8989$lang['estat_allPeriods']='All periods';
    9090
    91 
    92 $lang['estat_item_nb']='% event';
    93 $lang['estat_items_nb']='% events';
    94 $lang['estat_ip_nb']='% IP adress';
    95 $lang['estat_ips_nb']='% IP adresses';
    96 $lang['estat_category_nb']='% album';
    97 $lang['estat_categories_nb']='% albums';
    98 $lang['estat_image_nb']='% photo';
    99 $lang['estat_images_nb']='% photos';
     91$lang['estat_item_nb']='% item';
     92$lang['estat_items_nb']='% items';
     93
    10094$lang['estat_country_nb']='%s country';
    10195$lang['estat_countries_nb']='%s countries';
    102 $lang['estat_items']='Events';
     96
    10397$lang['estat_ok']='Ok';
    10498$lang['estat_cancel']='Cancel';
  • extensions/EStat/language/fr_FR/plugin.lang.php

    r17737 r17758  
    8989$lang['estat_allPeriods']='Toutes périodes';
    9090
    91 
    92 $lang['estat_item_nb']='% événement';
    93 $lang['estat_items_nb']='% événements';
    94 $lang['estat_ip_nb']='% adresse IP';
    95 $lang['estat_ips_nb']='% adresses IP';
    96 $lang['estat_category_nb']='% album';
    97 $lang['estat_categories_nb']='% albums';
    98 $lang['estat_image_nb']='% photo';
    99 $lang['estat_images_nb']='% photos';
     91$lang['estat_item_nb']='% élément';
     92$lang['estat_items_nb']='% éléments';
     93
    10094$lang['estat_country_nb']='%s pays';
    10195$lang['estat_countries_nb']='%s pays';
    102 $lang['estat_items']='Evénements';
     96
     97
    10398$lang['estat_ok']='Ok';
    10499$lang['estat_cancel']='Annuler';
  • extensions/EStat/lib/statDB.class.inc.php

    r17737 r17758  
    193193   *
    194194   * @param String $file
     195   * @param Boolean $force: if true, $force the filename affectation even if file doesn't exist
    195196   * @return String: file name set
    196197   */
    197   public function setIpCountryFile($file)
    198   {
    199     if(file_exists($file))
     198  public function setIpCountryFile($file, $force=false)
     199  {
     200    if($force or file_exists($file))
    200201      $this->ipCountryFile=$file;
    201202    return($this->ipCountryFile);
     
    728729            break;
    729730          case 'between':
     731          case 'not between':
    730732            if($field=='IPadress')
    731733            {
     
    737739              $num++;
    738740            }
    739             $where[]=' '.$field." BETWEEN ".$param['minValue']." AND ".$param['maxValue']." ";
     741            $where[]=' '.$field.' '.strtoupper($param['operator']).' '.$param['minValue']." AND ".$param['maxValue']." ";
    740742            break;
    741743        }
     
    824826  }
    825827
     828
     829  /**
     830   * to be used with IP filter: replace the given operator with 'between' or 'not between'
     831   *
     832   * @param Array $value
     833   * @return Array
     834   */
     835  protected function checkIPFilter($value)
     836  {
     837    if(is_array($value))
     838    {
     839      if(isset($value['operator']))
     840      {
     841        if($value['operator']=='=' or
     842           $value['operator']=='>' or
     843           $value['operator']=='>=' or
     844           $value['operator']=='<' or
     845           $value['operator']=='<=' or
     846           $value['operator']=='like')
     847        {
     848          $value['operator']='between';
     849          $value['minValue']=$value['value'];
     850          $value['maxValue']=$value['value'];
     851          $value['value']=null;
     852        }
     853        elseif($value['operator']=='!=' or
     854               $value['operator']=='not like')
     855        {
     856          $value['operator']='not between';
     857          $value['minValue']=$value['value'];
     858          $value['maxValue']=$value['value'];
     859          $value['value']=null;
     860        }
     861      }
     862    }
     863    return($value);
     864  } // checkIPFilter
    826865
    827866
     
    856895          case '<=':
    857896          case '!=':
     897          case 'like':
     898          case 'not like':
    858899            if(isset($value['value']))
    859900            {
     
    866907                  break;
    867908                case 'IP':
    868                   $value['value']=$this->checkValueIP($value['value']);
     909                  // for IP, replace internaly the operator with a 'between'
     910                  $value['value']=$this->checkValueIP($value['value'], 0);
    869911                  if($value['value']==null) return(null);
    870912                  break;
     
    893935                    break;
    894936                  case 'IP':
    895                     $val=$this->checkValueIP($val);
     937                    $val=$this->checkValueIP($val, 0);
    896938                    if($val!=null) $returned[]=$val;
    897939                    break;
     
    910952            break;
    911953          case 'between':
     954          case 'not between':
    912955            if(isset($value['minValue']) and  isset($value['maxValue']))
    913956            {
     
    921964                  break;
    922965                case 'IP':
    923                   $value['minValue']=$this->checkValueIP($value['minValue']);
     966                  $value['minValue']=$this->checkValueIP($value['minValue'], 0);
    924967                  if($value['minValue']==null) return(null);
    925                   $value['maxValue']=$this->checkValueIP($value['maxValue']);
     968                  $value['maxValue']=$this->checkValueIP($value['maxValue'], 255);
    926969                  if($value['maxValue']==null) return(null);
    927970                  break;
     
    9811024   *
    9821025   * @param String $value
     1026   * @param Integer $completeCode
    9831027   * @return String
    9841028   */
    985   protected function checkValueIP($value)
    986   {
    987     $returned=self::IPBinaryEncode($value);
     1029  protected function checkValueIP($value, $completeCode=0)
     1030  {
     1031    $returned=self::IPBinaryEncode($value, $completeCode);
    9881032    if($returned=="\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00") return(null);
    9891033    return($returned);
     
    10001044   *
    10011045   * @param String $IP: text IP string
     1046   * @param Integer $completeCode
    10021047   * @return String: a binary string
    10031048   */
    1004   static public function IPBinaryEncode($IP)
     1049  static public function IPBinaryEncode($IP, $completeCode=0)
    10051050  {
    10061051    $value=trim($IP);
    1007     if(preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/i',$value)>0)
     1052    if(preg_match('/\d{1,3}(\.\d{1,3}(\.\d{1,3}(\.\d{1,3})?)?)?/i',$value)>0)
    10081053    {
    10091054      //IPv4
    10101055      $tmp=explode('.',$value);
     1056      while(count($tmp)<4) $tmp[]=$completeCode;
     1057
    10111058      return("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".chr($tmp[0]+0).chr($tmp[1]+0).chr($tmp[2]+0).chr($tmp[3]+0));
    10121059    }
     
    10881135
    10891136
    1090 
    1091 
    1092 
     1137/*
     1138 used to display binary values when debug is necessary...
     1139
     1140function toHexDump($data)
     1141  {
     1142    $returned="";
     1143    $maxItems=strlen($data);
     1144
     1145    $tmp=array();
     1146    for($i=0;$i<$maxItems;$i++)
     1147    {
     1148      $tmp[]=sprintf("%02x", ord($data{$i}));
     1149    }
     1150    $returned.=implode(" ", $tmp);
     1151    return($returned);
     1152  }
     1153*/
    10931154
    10941155
  • extensions/EStat/lib/statDBGlobal.class.inc.php

    r17737 r17758  
    223223            SELECT uaType, IPadress, catId, $year, $month, SUM(visits), country
    224224            FROM period.statIP
    225             GROUP BY uaType, IPadress, catId;
     225            GROUP BY uaType, IPadress, catId, country;
    226226
    227227        REPLACE INTO main.statUA (uaData, uaValue, uaVersion, year, month, visits)
     
    486486    if(!isset($filter['country'])) $filter['country']=null;
    487487
     488    $filter['IPadress']=$this->checkIPFilter($filter['IPadress']);
    488489    // check filter values - getOperator check and 'clean' the filter
    489490    $filter['IPadress']=$this->getOperator($filter['IPadress'], 'IP');
     
    543544      case ASDF_GET_ROWS:
    544545          $sql=$select." FROM statip ".$where.$groupBy.$orderBy.$limit;
    545 
    546546          $sqlStm=$this->dbHandle->prepare($sql);
    547547          foreach($IPList as $num=>$IP)
     
    12451245            );
    12461246          $this->dbHandle->exec("CREATE UNIQUE INDEX iIP ON statIP ('uaType', 'IPadress', 'catId', 'year', 'month');");
    1247           $this->dbHandle->exec("CREATE UNIQUE INDEX iIPPeriod ON statIP ('year', 'month', 'IPadress', 'uaType');");
     1247          $this->dbHandle->exec("CREATE INDEX iIPPeriod ON statIP ('year', 'month', 'IPadress', 'uaType');");
    12481248        }
    12491249
  • extensions/EStat/lib/statDBMonth.class.inc.php

    r17737 r17758  
    7878   *
    7979   * missing values are set to default value
     80   * country is defined automatically after buildIPCountry call; set to '' while
     81   * call is not made
    8082   *
    8183   * @param Array $log : a record
     
    109111      // insert log
    110112      $sql="INSERT INTO logs
    111             (date, IPadress, userId, catId, imageId, tagsId, section,
     113            (date, IPadress, country, userId, catId, imageId, tagsId, section,
    112114             userAgent, uaBrowser, uaBrowserVersion, uaEngine, uaEngineVersion,
    113115             uaOS, uaOSVersion, uaType, screenSizeW, screenSizeH)
     
    115117                      //"'".$this->dbHandle->escapeString($value['IPadress'])."', ".
    116118                      ":IP, ".
     119                      "'', ".
    117120                      $value['userId'].", ".
    118121                      $value['catId'].", ".
     
    254257    if(!isset($filter['uaType'])) $filter['uaType']=null;
    255258
     259    $filter['IPadress']=$this->checkIPFilter($filter['IPadress']);
    256260    // check filter values - getOperator check and 'clean' the filter
    257261    $filter['date']=$this->getOperator($filter['date'], 'date');
     
    296300        array('id'=>'id', 'direction'=>'A')
    297301      );
     302    // to optimize query, if date is the first field selected for order by,
     303    // all other fields are removed; exception: if IPadress is the second one this
     304    // field is kept
     305    $tmp=$orderBy;
     306    if($tmp[0]['id']=='date')
     307    {
     308      $orderBy=array($tmp[0]);
     309      if($tmp[1]['id']=='IPadress')
     310      {
     311        $orderBy[]=$tmp[1];
     312      }
     313    }
     314
    298315    //build ORDER BY clause
    299316    $orderBy=$this->buildOrderByClause($orderBy);
     
    310327    {
    311328      case ASDF_GET_ROWS:
    312           $sql="SELECT id, date, IPadress, userId, catId, imageId, tagsId, section,
     329          $sql="SELECT id, date, IPadress, country, userId, catId, imageId, tagsId, section,
    313330                       userAgent, uaBrowser, uaBrowserVersion, uaEngine, uaEngineVersion,
    314331                       uaOS, uaOSVersion, uaType, screenSizeW, screenSizeH
    315332                FROM logs $where $orderBy $limit;";
     333
    316334          $sqlStm=$this->dbHandle->prepare($sql);
    317335          foreach($IPList as $num=>$IP)
     
    576594    if(!isset($filter['country'])) $filter['country']=null;
    577595
     596    $filter['IPadress']=$this->checkIPFilter($filter['IPadress']);
    578597    // check filter values - getOperator check and 'clean' the filter
    579598    $filter['IPadress']=$this->getOperator($filter['IPadress'], 'IP');
     
    12481267        DROP TABLE IF EXISTS tmpIp;
    12491268
     1269        -- update the logs table for rows with unset country
     1270        -- use a simple sub select here, assuming that it's quick enough for the update
     1271        UPDATE logs
     1272        SET country=(SELECT sip.country FROM statip sip WHERE logs.IPadress = sip.IPadress)
     1273        WHERE country='';
     1274
    12501275        -- commit changes
    12511276        COMMIT TRANSACTION;
     
    12851310                  'date' INTEGER,
    12861311                  'IPadress' BLOB,
     1312                  'country' TEXT,
    12871313                  'userId' INTEGER,
    12881314                  'catId' INTEGER,
     
    13021328              );"
    13031329            );
    1304           $this->dbHandle->exec("CREATE INDEX iDate ON logs ('date');");
    1305           $this->dbHandle->exec("CREATE INDEX iByIP ON logs ('IPadress');");
     1330          $this->dbHandle->exec("CREATE INDEX iDateIP ON logs ('date', 'IPadress');");
     1331          $this->dbHandle->exec("CREATE INDEX iIPCountry ON logs ('IPadress', 'country');");
     1332          $this->dbHandle->exec("CREATE INDEX iUAB ON logs ('uaType', 'uaBrowser', 'uaEngine');");
     1333          $this->dbHandle->exec("CREATE INDEX iUAO ON logs ('uaOS');");
    13061334        }
    13071335
Note: See TracChangeset for help on using the changeset viewer.