Changeset 5183


Ignore:
Timestamp:
Mar 18, 2010, 11:47:11 PM (14 years ago)
Author:
grum
Message:

database is partially filled during the install process, and fill database picture per picture each time a page is displayed (and until all the database is filled)

Location:
extensions/AMetaData
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • extensions/AMetaData/admin/amd_metadata_database.tpl

    r5080 r5183  
    233233      <form class="formtable">
    234234        <div class="warning">
    235           <p style="font-weight:bold; font-size:+1;">{'g003_warning_on_analyze_0'|@translate}</p>
     235          <p style="font-weight:bold; font-size:+2;">{'g003_warning_on_analyze_0'|@translate}</p>
    236236          <p>{'g003_warning_on_analyze_1'|@translate}</p>
    237237          <p  style="font-weight:bold;">{'g003_warning_on_analyze_2'|@translate}</p>
     
    271271      </form>
    272272  </fieldset>
     273
    273274</div>
    274275
  • extensions/AMetaData/amd_aip.class.inc.php

    r5097 r5183  
    3333  protected $tabsheet;
    3434  protected $ajax;
    35   protected $jpegMD;
    3635
    3736  /**
     
    4241   * @param String $filelocation
    4342   */
    44   function __construct($prefixeTable, $filelocation)
     43  public function __construct($prefixeTable, $filelocation)
    4544  {
    4645    parent::__construct($prefixeTable, $filelocation);
     
    5756                          $this->page_link.'&amp;fAMD_tabsheet=help');
    5857    $this->ajax = new Ajax();
    59     $this->jpegMD=new JpegMetaData();
    60   }
    61 
    62   function __destruct()
     58  }
     59
     60  public function __destruct()
    6361  {
    6462    unset($this->tabsheet);
    6563    unset($this->ajax);
    66     unset($this->jpegMD);
     64    parent::__destruct();
    6765  }
    6866
     
    681679
    682680
    683   /**
    684    * this function analyze tags from a picture, and insert the result into the
    685    * database
    686    *
    687    * NOTE : only implemented tags are analyzed and stored
    688    *
    689    * @param String $fileName : filename of picture to analyze
    690    * @param Integer $imageId : id of image in piwigo's database
    691    */
    692   protected function analyzeImageFile($fileName, $imageId)
    693   {
    694     /*
    695      * the JpegMetaData object is instancied in the constructor
    696      */
    697     $this->jpegMD->load($fileName, Array(
    698       'filter' => JpegMetaData::TAGFILTER_IMPLEMENTED,
    699       'optimizeIptcDateTime' => true)
    700     );
    701 
    702     $sqlInsert="";
    703     $massInsert=array();
    704     $nbTags=0;
    705     foreach($this->jpegMD->getTags() as $key => $val)
    706     {
    707       $value=$val->getLabel();
    708 
    709       if($val->isTranslatable())
    710         $translatable="y";
    711       else
    712         $translatable="n";
    713 
    714       if($value instanceof DateTime)
    715       {
    716         $value=$value->format("Y-m-d H:i:s");
    717       }
    718       elseif(is_array($value))
    719       {
    720         /*
    721          * array values are stored in a serialized string
    722          */
    723         $value=serialize($value);
    724       }
    725 
    726       $sql="SELECT numId FROM ".$this->tables['used_tags']." WHERE tagId = '$key'";
    727       $result=pwg_query($sql);
    728       if($result)
    729       {
    730         $numId=-1;
    731         while($row=mysql_fetch_assoc($result))
    732         {
    733           $numId=$row['numId'];
    734         }
    735 
    736         if($numId>0)
    737         {
    738           $nbTags++;
    739           if($sqlInsert!="") $sqlInsert.=", ";
    740           $sqlInsert.="($imageId, '$numId', '".addslashes($value)."')";
    741           $massInsert[]="('$imageId', '$numId', '".addslashes($value)."') ";
    742         }
    743       }
    744     }
    745 
    746     $sql="REPLACE INTO ".$this->tables['images_tags']." (imageId, numId, value)
    747           VALUES ".implode(", ", $massInsert);
    748     pwg_query($sql);
    749     //mass_inserts($this->tables['images_tags'], array('imageId', 'numId', 'value'), $massInsert);
    750 
    751     $sql="UPDATE ".$this->tables['images']."
    752             SET analyzed = 'y', nbTags=".$nbTags."
    753             WHERE imageId=$imageId;";
    754     pwg_query($sql);
    755 
    756 
    757     return("$imageId=$nbTags;");
    758   }
    759 
    760 
    761   /**
    762    * returns the number of pictures analyzed
    763    *
    764    * @return Integer
    765    */
    766   protected function getNumOfPictures()
    767   {
    768     $numOfPictures=0;
    769     $sql="SELECT COUNT(imageId) FROM ".$this->tables['images']."
    770             WHERE analyzed='y';";
    771     $result=pwg_query($sql);
    772     if($result)
    773     {
    774       while($row=mysql_fetch_row($result))
    775       {
    776         $numOfPictures=$row[0];
    777       }
    778     }
    779     return($numOfPictures);
    780   }
    781681
    782682
     
    910810  private function ajax_amd_makeStatsConsolidation()
    911811  {
    912     $sql="UPDATE ".$this->tables['used_tags']." ut,
    913             (SELECT COUNT(imageId) AS nb, numId
    914               FROM ".$this->tables['images_tags']."
    915               GROUP BY numId) nb
    916           SET ut.numOfImg = nb.nb
    917           WHERE ut.numId = nb.numId;";
    918     pwg_query($sql);
     812    $this->makeStatsConsolidation();
    919813  }
    920814
  • extensions/AMetaData/amd_install.class.inc.php

    r5040 r5183  
    2727    private $tablef;
    2828
    29     public function AMD_install($prefixeTable, $filelocation)
     29    public function __construct($prefixeTable, $filelocation)
    3030    {
    3131      parent::__construct($prefixeTable, $filelocation);
    3232      $this->tablef= new manage_tables($this->tables);
     33    }
     34
     35    public function __destruct()
     36    {
     37      unset($this->tablef);
     38      parent::__destruct();
    3339    }
    3440
     
    126132      pwg_query("DELETE FROM ".$this->tables['images_tags']);
    127133      pwg_query("UPDATE ".$this->tables['images']." SET analyzed='n', nbTags=0;");
     134      pwg_query("INSERT INTO ".$this->tables['images']."
     135                  SELECT id, 'n', 0
     136                    FROM ".IMAGES_TABLE."
     137                    WHERE id NOT IN (SELECT imageId FROM ".$this->tables['images'].")");
    128138      /*
    129139       * fill the 'used_tags' table with default values
     
    133143        $sql="INSERT INTO ".$this->tables['used_tags']." VALUES('', '".$key."', '".(($val['translatable'])?'y':'n')."', '".$val['name']."', 0);";
    134144        pwg_query($sql);
     145      }
     146
     147      $listToAnalyze=Array(Array(), Array());
     148      /*
     149       * select 25 pictures into the caddie
     150       */
     151      $sql="SELECT ti.id, ti.path
     152            FROM ".CADDIE_TABLE." tc
     153              LEFT JOIN ".IMAGES_TABLE." ti ON ti.id = tc.element_id
     154            ORDER BY RAND() LIMIT 25;";
     155      $result=pwg_query($sql);
     156      if($result)
     157      {
     158        while($row=mysql_fetch_assoc($result))
     159        {
     160          $listToAnalyze[0][]=$row;
     161          $listToAnalyze[1][]=$row['id'];
     162        }
     163      }
     164      /*
     165       * if caddie is empty, of is have less than 25 pictures, select other
     166       * pictures from the gallery
     167       */
     168      if(count($listToAnalyze[0])<25)
     169      {
     170        if(count($listToAnalyze[0])>0)
     171        {
     172          $excludeList="WHERE ti.id NOT IN(".implode(",", $listToAnalyze[1]).") ";
     173        }
     174        else
     175        {
     176          $excludeList="";
     177        }
     178        $sql="SELECT ti.id, ti.path
     179              FROM ".IMAGES_TABLE." ti ".$excludeList."
     180              ORDER BY RAND() LIMIT ".(25-count($listToAnalyze[0])).";";
     181        $result=pwg_query($sql);
     182        if($result)
     183        {
     184          while($row=mysql_fetch_assoc($result))
     185          {
     186            $listToAnalyze[0][]=$row;
     187          }
     188        }
     189      }
     190
     191      /*
     192       * analyze the 25 selected pictures
     193       */
     194      if(count($listToAnalyze[0])>0)
     195      {
     196        // $path = path of piwigo's on the server filesystem
     197        $path=dirname(dirname(dirname(__FILE__)));
     198
     199        foreach($listToAnalyze[0] as $val)
     200        {
     201          $this->analyzeImageFile($path."/".$val['path'], $val['id']);
     202        }
     203
     204        $this->makeStatsConsolidation();
    135205      }
    136206
  • extensions/AMetaData/amd_pip.class.inc.php

    r4909 r5183  
    6464    $path=dirname(dirname(dirname(__FILE__)));
    6565    $filename="";
     66    $analyzed='n';
    6667
    67     $sql="SELECT path FROM ".IMAGES_TABLE." WHERE id=".$page['image_id'].";";
     68    $sql="SELECT ti.path, tai.analyzed FROM ".IMAGES_TABLE." ti
     69            LEFT JOIN ".$this->tables['images']." tai ON tai.imageId = ti.id
     70          WHERE ti.id=".$page['image_id'].";";
    6871    $result=pwg_query($sql);
    6972    if($result)
     
    7275      {
    7376        $filename=$row['path'];
     77        $analyzed=$row['analyzed'];
    7478      }
    7579      $filename=$path."/".$filename;
    7680    }
    7781
    78     $JpegMD = new JpegMetaData(
     82    $this->jpegMD->load(
    7983      $filename,
    8084      Array(
     
    113117    $group=null;
    114118
    115     $picturesTags=$JpegMD->getTags();
     119    $picturesTags=$this->jpegMD->getTags();
    116120
    117121    foreach($tagsList as $key => $val)
     
    160164    }
    161165
    162     unset($JpegMD);
     166
     167    if($analyzed=='n' and
     168       $this->my_config['amd_FillDataBaseContinuously']=='y' and
     169       $this->my_config['amd_AllPicturesAreAnalyzed']=='n')
     170    {
     171      /* if picture is not analyzed, do analyze
     172       *
     173       * note : the $loaded parameter is set to true, in this case the function
     174       *        analyzeImageFile uses data from the $this->jpegMD object which
     175       *        have data already loaded => the picture is not analyzed twice,
     176       *        the function only do the database update
     177       */
     178      $this->analyzeImageFile($filename, $page['image_id'], true);
     179      $this->makeStatsConsolidation();
     180    }
    163181
    164182    $template->assign('metadata', $metadata);
  • extensions/AMetaData/amd_root.class.inc.php

    r5088 r5183  
    3030{
    3131  protected $css;   //the css object
    32 
    33   function AMD_root($prefixeTable, $filelocation)
     32  protected $jpegMD;
     33
     34  public function __construct($prefixeTable, $filelocation)
    3435  {
    3536    $this->plugin_name="AMetaData";
     
    4142
    4243    $this->css = new css(dirname($this->filelocation).'/'.$this->plugin_name_files.".css");
    43   }
     44    $this->jpegMD=new JpegMetaData();
     45  }
     46
     47  public function __destruct()
     48  {
     49    unset($this->jpegMD);
     50    unset($this->css);
     51    //parent::__destruct();
     52  }
     53
    4454
    4555  /* ---------------------------------------------------------------------------
     
    5666      'amd_GetListTags_ExcludeUnusedTag' => "y",
    5767      'amd_GetListTags_SelectedTagOnly' => "n",
    58       'amd_GetListImages_OrderType' => "value"
     68      'amd_GetListImages_OrderType' => "value",
     69      'amd_FillDataBaseContinuously' => "y",
     70      'amd_AllPicturesAreAnalyzed' => "n",
    5971    );
    6072  }
     
    6375  {
    6476    parent::load_config();
    65     if(!$this->css->css_file_exists())
    66     {
    67       $this->css->make_CSS($this->generate_CSS());
    68     }
    6977  }
    7078
     
    7280  {
    7381    parent::init_events();
    74   }
    75 
    76   /*
    77    * generate the css code
    78    */
    79   function generate_CSS()
    80   {
    81     $text = "
    82       .formtable, .formtable P { text-align:left; display:block; }
    83       .formtable tr { vertical-align:top; }
    84       .littlefont { font-size:90%; }
    85       .littlefont td { padding:1px; }
    86       table.littlefont th { padding:3px; text-align:left;}
    87       table.littlefont td { padding:1px 3px; }
    88       #iprogressbar_contener { border:1px solid #606060; margin:0px; padding:0px; display:block; height:20px; }
    89       #iprogressbar_bg { background:#606060; display:block; z-index:100; position:relative; height:20px; }
    90       #iprogressbar_fg { color:#FF3363; width:100%; text-align:center; display: block; z-index:200; position:relative; top:-18px;  }
    91       #iHeaderListTags { width:100%; border:1px solid; border-collapse: collapse; margin-top:3px; }
    92       #iListTags { width:100%; border:1px solid; height:280px; border-top:0px; overflow:auto;}
    93       #iListImages { width:100%; border-bottom:1px solid; overflow:auto;}
    94       #iListTagsNb, #iListImagesNb { width:99%; text-align:right; margin-bottom:8px; padding:2px; font-size:80%; }
    95       #iListTags table, #iListImages table, table.listTags { width:100%; text-align:left; border-collapse: collapse; }
    96       #iListTags table tr:hover { cursor:pointer; background:#303030; }
    97       #iListImages table tr:hover, table.listTags tr:hover { background:#303030; cursor:default; }
    98       #iHeaderListImages { width:100%; border-bottom:1px solid; }
    99       .warning { color:#dd0000; border:1px solid #dd0000; margin-bottom:8px; margin-top:8px; padding:8px; }
    100       .warning p { margin-top:0.5em; margin-bottom:0em; }
    101       .warning ul { margin-top:0em; margin-bottom:0.5em; }
    102       .pctBar { height:6px; background:#FF7700; }
    103       li.groupItems { border:1px solid #666666; margin-bottom:5px; padding:0 5px; width:90%; cursor:move; padding:4px; }
    104       div.addGroup { padding-left:40px; text-align:left; }
    105       #iGroups { list-style: none; }
    106       .ui-dialog { background: #222222; border:2px solid #FF3363; }
    107       .ui-dialog-buttonpane { padding:4px; }
    108       .ui-dialog-buttonpane button { margin-right:8px; }
    109       .ui-dialog-titlebar { background:#111111; font-weight:bold; }
    110       .ui-dialog-title-dialog { text-align: left; }
    111       .ui-dialog-titlebar-close { float: right; }
    112       .ui-dialog-content { overflow:auto; }
    113       .ui-dialog-container { }
    114       .ui-dialog-titlebar-close { display:none; }
    115       .tagListOrder { list-style: none; padding:0px; margin-right:8px; margin-left:35px; }
    116       .tagListOrder li { border:none; background:#333333; padding:1px; margin-bottom:2px; width:100%; }
    117       .groupTags { padding-top:8px; }
    118       .editGroupListButton { margin-left:8px; position:absolute; z-index:1000; }
    119       table.tagListOrderItem { width:100%; border-collapse:collapse; }
    120       .dialogForm { text-align:left; margin:8px; }
    121       #ianalyzestatus { background: #333333; margin:8px; padding:8px; }
    122       #ianalyzestatus ul { margin:0px; padding:0 0 0 20px; }
    123       #iamd_nb_item_per_request_display { display:inline-block; width:70px; }
    124       #iamd_nb_item_per_request_slider { display:inline-block; width:350px; }
    125       #iDialogProgress { margin:16px 8px 8px; }
    126     ";
    127 
    128     return($text);
    129   }
     82
     83
     84    if(!isset($_REQUEST['ajaxfct']) and
     85       $this->my_config['amd_FillDataBaseContinuously']=='y' and
     86       $this->my_config['amd_AllPicturesAreAnalyzed']=='n')
     87    {
     88      /* do analyze for a random picture only if :
     89       *  - config is set to fill database continuously
     90       *  - we are not in an ajax call
     91       */
     92      add_event_handler('init', array(&$this, 'doRandomAnalyze'));
     93    }
     94  }
     95
     96
     97  /**
     98   * returns the number of pictures analyzed
     99   *
     100   * @return Integer
     101   */
     102  protected function getNumOfPictures()
     103  {
     104    $numOfPictures=0;
     105    $sql="SELECT COUNT(imageId) FROM ".$this->tables['images']."
     106            WHERE analyzed='y';";
     107    $result=pwg_query($sql);
     108    if($result)
     109    {
     110      while($row=mysql_fetch_row($result))
     111      {
     112        $numOfPictures=$row[0];
     113      }
     114    }
     115    return($numOfPictures);
     116  }
     117
     118
     119  /**
     120   * this function randomly choose a picture in the list of pictures not
     121   * analyzed, and analyze it
     122   *
     123   */
     124  public function doRandomAnalyze()
     125  {
     126    $sql="SELECT tai.imageId, ti.path FROM ".$this->tables['images']." tai
     127            LEFT JOIN ".IMAGES_TABLE." ti ON tai.imageId = ti.id
     128          WHERE tai.analyzed = 'n'
     129          ORDER BY RAND() LIMIT 1;";
     130    $result=pwg_query($sql);
     131    if($result)
     132    {
     133      // $path = path of piwigo's on the server filesystem
     134      $path=dirname(dirname(dirname(__FILE__)));
     135
     136      while($row=mysql_fetch_assoc($result))
     137      {
     138        $this->analyzeImageFile($path."/".$row['path'], $row['imageId']);
     139      }
     140
     141      $this->makeStatsConsolidation();
     142    }
     143  }
     144
     145
     146  /**
     147   * this function analyze tags from a picture, and insert the result into the
     148   * database
     149   *
     150   * NOTE : only implemented tags are analyzed and stored
     151   *
     152   * @param String $fileName : filename of picture to analyze
     153   * @param Integer $imageId : id of image in piwigo's database
     154   * @param Boolean $loaded  : default = false
     155   *                            WARNING
     156   *                            if $loaded is set to TRUE, the function assume
     157   *                            that the metadata have been alreay loaded
     158   *                            do not use the TRUE value if you are not sure
     159   *                            of the consequences
     160   */
     161  protected function analyzeImageFile($fileName, $imageId, $loaded=false)
     162  {
     163    /*
     164     * the JpegMetaData object is instancied in the constructor
     165     */
     166    if(!$loaded)
     167    {
     168      $this->jpegMD->load(
     169        $fileName,
     170        Array(
     171          'filter' => JpegMetaData::TAGFILTER_IMPLEMENTED,
     172          'optimizeIptcDateTime' => true,
     173          'exif' => true,
     174          'iptc' => true,
     175          'xmp' => true
     176        )
     177      );
     178    }
     179
     180    $sqlInsert="";
     181    $massInsert=array();
     182    $nbTags=0;
     183    foreach($this->jpegMD->getTags() as $key => $val)
     184    {
     185      $value=$val->getLabel();
     186
     187      if($val->isTranslatable())
     188        $translatable="y";
     189      else
     190        $translatable="n";
     191
     192      if($value instanceof DateTime)
     193      {
     194        $value=$value->format("Y-m-d H:i:s");
     195      }
     196      elseif(is_array($value))
     197      {
     198        /*
     199         * array values are stored in a serialized string
     200         */
     201        $value=serialize($value);
     202      }
     203
     204      $sql="SELECT numId FROM ".$this->tables['used_tags']." WHERE tagId = '$key'";
     205
     206      $result=pwg_query($sql);
     207      if($result)
     208      {
     209        $numId=-1;
     210        while($row=mysql_fetch_assoc($result))
     211        {
     212          $numId=$row['numId'];
     213        }
     214
     215        if($numId>0)
     216        {
     217          $nbTags++;
     218          if($sqlInsert!="") $sqlInsert.=", ";
     219          $sqlInsert.="($imageId, '$numId', '".addslashes($value)."')";
     220          $massInsert[]="('$imageId', '$numId', '".addslashes($value)."') ";
     221        }
     222      }
     223    }
     224
     225    if(count($massInsert)>0)
     226    {
     227      $sql="REPLACE INTO ".$this->tables['images_tags']." (imageId, numId, value) VALUES ".implode(", ", $massInsert).";";
     228      pwg_query($sql);
     229    }
     230    //mass_inserts($this->tables['images_tags'], array('imageId', 'numId', 'value'), $massInsert);
     231
     232    $sql="UPDATE ".$this->tables['images']."
     233            SET analyzed = 'y', nbTags=".$nbTags."
     234            WHERE imageId=$imageId;";
     235    pwg_query($sql);
     236
     237
     238    return("$imageId=$nbTags;");
     239  }
     240
     241
     242  /**
     243   * do some consolidations on database to optimize other requests
     244   *
     245   */
     246  protected function makeStatsConsolidation()
     247  {
     248    $sql="UPDATE ".$this->tables['used_tags']." ut,
     249            (SELECT COUNT(imageId) AS nb, numId
     250              FROM ".$this->tables['images_tags']."
     251              GROUP BY numId) nb
     252          SET ut.numOfImg = nb.nb
     253          WHERE ut.numId = nb.numId;";
     254    pwg_query($sql);
     255
     256
     257    $sql="SELECT COUNT(imageId) AS nb
     258          FROM ".$this->tables['images']."
     259          WHERE analyzed = 'n';";
     260    $result=pwg_query($sql);
     261    if($result)
     262    {
     263      while($row=mysql_fetch_assoc($result))
     264      {
     265        $this->my_config['amd_AllPicturesAreAnalyzed']=($row['nb']==0)?'y':'n';
     266      }
     267
     268    }
     269    $this->save_config();
     270  }
     271
    130272
    131273} // amd_root  class
  • extensions/AMetaData/language/fr_FR/plugin.lang.php

    r5080 r5183  
    8484$lang['g003_warning_on_analyze_3'] = "Il est fortement recommandé de remplir le panier avec une cinquantaine de photos représentatives de la galerie pour procéder au traitement.";
    8585
     86$lang['g003_metadata_detail'] = "Domaine de valeurs pour la métadonnée";
     87
     88$lang['g003_help'] = "Aide sur les métadonnées";
    8689
    8790?>
Note: See TracChangeset for help on using the changeset viewer.