Ignore:
Timestamp:
May 7, 2010, 10:23:47 PM (14 years ago)
Author:
grum
Message:

Plugin is now in a usable state (color analysis is not yet tuned)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/ColorStat/cstat_aip.class.inc.php

    r5961 r6107  
    11<?php
    22/* -----------------------------------------------------------------------------
    3   Plugin     : LMT
     3  Plugin     : ColorStat
    44  Author     : Grum
    55    email    : grum@piwigo.org
     
    1010  See main.inc.php for release information
    1111
    12   LMT_AIP : classe to manage plugin admin pages
     12  CStat_AIP : classe to manage plugin admin pages
    1313
    1414  --------------------------------------------------------------------------- */
     15
     16if(!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    1517
    1618include_once('cstat_root.class.inc.php');
    1719include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCTables.class.inc.php');
     20include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCTabSheet.class.inc.php');
     21include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCRequestBuilder.class.inc.php');
    1822include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
    1923
     
    2529  {
    2630    parent::__construct($prefixeTable, $filelocation);
     31    $this->checkRequest();
     32
    2733    $this->loadConfig();
    2834    $this->initEvents();
     
    5561  {
    5662    parent::initEvents();
     63    if($_REQUEST['f_tabsheet']=='search')
     64    {
     65      // load request builder JS only on the search page
     66      GPCRequestBuilder::loadJSandCSS();
     67    }
    5768    add_event_handler('loc_end_page_header', array(&$this->css, 'applyCSS'));
    5869    GPCCss::applyGpcCss();
     
    6576  {
    6677    global $template;
    67 
    68     $this->checkRequest();
    6978
    7079    $this->returnAjaxContent();
     
    154163      {
    155164        if(!isset($_REQUEST['selectMode'])) $_REQUEST['selectMode']='caddieAdd';
    156         if(!isset($_REQUEST['numOfItems'])) $_REQUEST['numOfItems']=$this->config['analyze.itemPerRequest'];
     165        if(!isset($_REQUEST['numOfItems'])) $_REQUEST['numOfItems']=$this->config['analyze_itemPerRequest'];
    157166
    158167        if(!($_REQUEST['selectMode']=='notAnalyzed' or
     
    181190    }
    182191
     192
    183193  }
    184194
     
    195205    $datas=Array(
    196206      'urlRequest' => $this->getAdminLink(),
    197       'numberOfItemsPerRequest' => $this->config['analyze.itemPerRequest']
     207      'numberOfItemsPerRequest' => $this->config['analyze_itemPerRequest']
    198208    );
    199209    $template->assign('datas', $datas);
     
    211221                dirname($this->getFileLocation()).'/admin/cstat_stat.tpl');
    212222
    213     $generalStats=$this->getGeneralStats();
    214 
    215     $colors=Array();
    216     $sql="SELECT color_id, num_images, num_pixels
    217           FROM ".$this->tables['color_table']."
    218           WHERE num_images > 0
    219           ORDER BY color_id ";
    220     $result=pwg_query($sql);
    221     if($result)
    222     {
    223       while($row=pwg_db_fetch_assoc($result))
    224       {
    225         $colors[$row['color_id']]=Array('num_images' => $row['num_images'], 'num_pixels' => $row['num_pixels']);
    226       }
    227     }
    228 
    229     $colorTable=ColorStat::getColorTable(
    230       $this->colorTableSize[$this->config['analyze.colorTable']][0],
    231       $this->colorTableSize[$this->config['analyze.colorTable']][1]
    232     );
    233     foreach($colorTable as $key=>$val)
    234     {
    235       foreach($val as $key2=>$val2)
    236       {
    237         $rgb=$val2->getRGB()->getHexString();
    238         $colorTable[$key][$key2]=Array(
    239           'color' => $rgb,
    240           'pct'   => (array_key_exists($rgb, $colors))?sprintf("%.2f", round(100*$colors[$rgb]['num_pixels']/$generalStats['pixelsAnalyzedSum'],2)):"",
    241           'num'   => (array_key_exists($rgb, $colors))?$colors[$rgb]['num_images']:"",
    242         );
    243       }
    244     }
     223    $colorTable=$this->getColorTableWithStat();
     224
    245225
    246226    $datas=Array(
     227      //'themeconf' => Array('name' => $template->get_themeconf('name')),
    247228      'colorTable' => $this->htmlColorTable(
    248229                        $colorTable,
    249                         ($this->config['analyze.colorTable']=='small')?19:10
     230                        ($this->config['analyze_colorTable']=='small')?19:10,
     231                        "",
     232                        "color0px"
    250233                      ),
    251234      'urlRequest' => $this->getAdminLink(),
    252       'config_GetListColors_OrderType' => $this->config['display.stat.orderType'],
     235      'config_GetListColors_OrderType' => $this->config['display_stat_orderType'],
    253236    );
    254237    $template->assign('datas', $datas);
     
    267250                dirname($this->getFileLocation()).'/admin/cstat_search.tpl');
    268251
     252    $datas=Array(
     253      'dialogBox' => $this->dialogBoxColor(),
     254      'themeName' => $template->get_themeconf('name'),
     255    );
     256
     257    $template->assign('datas', $datas);
     258
    269259    $template->assign_var_from_handle('CSTAT_BODY_PAGE', 'body_page');
    270260  } //displaySearchPage
     
    276266  protected function displayConfigPage()
    277267  {
    278     /*
     268    $tmpPct=$this->config['stat_minPct'];
     269
    279270    if(!$this->adviser_abort())
    280271    {
     
    283274        foreach($this->config as $key => $val)
    284275        {
    285           if(is_array($val))
     276          if(isset($_REQUEST['f_'.$key]))
    286277          {
    287             foreach($languages as $key2 => $val2)
    288             {
    289               if(isset($_REQUEST[str2url('f_'.$key.'_'.$key2)]))
    290               {
    291                 $this->config[$key][$key2] = htmlspecialchars(stripslashes($_REQUEST[str2url('f_'.$key.'_'.$key2)]), ENT_QUOTES);
    292               }
    293             }
     278            $this->config[$key] = $_REQUEST['f_'.$key];
    294279          }
    295           else
    296           {
    297             if(isset($_REQUEST['f_'.$key]))
    298             {
    299               $this->config[$key] = $_REQUEST['f_'.$key];
    300             }
    301           }
    302 
    303280        }
    304         $this->displayResult(l10n('lmt_save_config'), $this->saveConfig());
    305       }
    306     }*/
     281        $this->displayResult(l10n('cstat_save_config'), $this->saveConfig());
     282      }
     283    }
     284
     285    if($tmpPct!=$this->config['stat_minPct'])
     286    {
     287      $this->updateDatabaseConsolidation();
     288    }
     289
    307290    $this->displayConfig();
    308291  }
     
    317300    $template->set_filename('body_page',
    318301                dirname($this->getFileLocation()).'/admin/cstat_config.tpl');
     302
     303    $datas=Array(
     304      'minPct' => $this->config['stat_minPct'],
     305      'showColors' => $this->config['display_gallery_showColors']
     306    );
     307
     308    $template->assign('datas', $datas);
    319309
    320310    $template->assign_var_from_handle('CSTAT_BODY_PAGE', 'body_page');
     
    353343        'quality' => 8,
    354344        'numColors' => 16,
    355         'maxTime' => $this->config['analyze.maxTime'],
    356         'pps' => $this->config['analyze.pps'],
     345        'maxTime' => $this->config['analyze_maxTime'],
     346        'pps' => $this->config['analyze_pps'],
    357347      )
    358348    );
     
    443433  }
    444434
     435
     436  /**
     437   * make consolidation for the color_table :
     438   *  - count number of images using a color
     439   *  - count number of pixels of a color
     440   */
     441  protected function updateDatabaseConsolidation()
     442  {
     443    $sql="UPDATE ".$this->tables['color_table']." cct
     444          SET cct.num_images=0,
     445              cct.num_pixels=0;";
     446    pwg_query($sql);
     447
     448    $sql="UPDATE ".$this->tables['color_table']." cct,
     449                 (SELECT color_id,
     450                         count(image_id) AS num_images,
     451                         sum(num_pixels) AS num_pixels
     452                  FROM ".$this->tables['images_colors']."
     453                  WHERE pct >= ".$this->config['stat_minPct']."
     454                  GROUP BY color_id) cic
     455          SET cct.num_images=cic.num_images,
     456              cct.num_pixels=cic.num_pixels
     457          WHERE cct.color_id=cic.color_id;";
     458    pwg_query($sql);
     459
     460    $sql="UPDATE ".$this->tables['images']." pci
     461          SET pci.colors = '',
     462              pci.colors_pct = ''";
     463    pwg_query($sql);
     464
     465    $sql="UPDATE ".$this->tables['images']." pci,
     466          (SELECT image_id,
     467                  GROUP_CONCAT(color_id ORDER BY pct DESC SEPARATOR ',') AS colors,
     468                  GROUP_CONCAT(pct ORDER BY pct DESC SEPARATOR ',') AS colors_pct
     469           FROM ".$this->tables['images_colors']."
     470           WHERE pct >= ".$this->config['stat_minPct']."
     471           GROUP BY image_id) pcic
     472          SET pci.colors = pcic.colors,
     473              pci.colors_pct = pcic.colors_pct
     474          WHERE pci.image_id = pcic.image_id;";
     475    pwg_query($sql);
     476  }
     477
    445478  /* ---------------------------------------------------------------------------
    446479    ajax functions
     
    593626      {
    594627        $colorTable=ColorStat::getColorTable(
    595           $this->colorTableSize[$this->config['analyze.colorTable']][0],
    596           $this->colorTableSize[$this->config['analyze.colorTable']][1]
     628          $this->colorTableSize[$this->config['analyze_colorTable']][0],
     629          $this->colorTableSize[$this->config['analyze_colorTable']][1]
    597630        );
    598631
     
    629662  private function ajax_cstat_updateDatabaseConsolidation()
    630663  {
    631     $sql="UPDATE ".$this->tables['color_table']." cct,
    632                  (SELECT color_id,
    633                          count(image_id) AS num_images,
    634                          sum(num_pixels) AS num_pixels
    635                   FROM ".$this->tables['images_colors']."
    636                   GROUP BY color_id) cic
    637           SET cct.num_images=cic.num_images,
    638               cct.num_pixels=cic.num_pixels
    639           WHERE cct.color_id=cic.color_id;";
    640     pwg_query($sql);
     664    $this->updateDatabaseConsolidation();
    641665    return("ok");
    642666  }
     
    657681    global $template;
    658682
    659     $this->config['display.stat.orderType'] = $orderType;
     683    $this->config['display_stat_orderType'] = $orderType;
    660684    $this->saveConfig();
    661685
Note: See TracChangeset for help on using the changeset viewer.