source: extensions/AMetaData/amd_install.class.inc.php @ 5183

Last change on this file since 5183 was 5183, checked in by grum, 14 years ago

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)

  • Property svn:executable set to *
File size: 6.3 KB
Line 
1<?php
2/*
3 * -----------------------------------------------------------------------------
4 * Plugin Name: Advanced MetaData
5 * -----------------------------------------------------------------------------
6 * Author     : Grum
7 *   email    : grum@piwigo.org
8 *   website  : http://photos.grum.fr
9 *   PWG user : http://forum.piwigo.org/profile.php?id=3706
10 *
11 *   << May the Little SpaceFrog be with you ! >>
12 *
13 * -----------------------------------------------------------------------------
14 *
15 * See main.inc.php for release information
16 *
17 * AMD_install : classe to manage plugin install
18 * ---------------------------------------------------------------------------
19 */
20
21  @include_once('amd_root.class.inc.php');
22  include_once(PHPWG_PLUGINS_PATH.'grum_plugins_classes-2/tables.class.inc.php');
23
24
25  class AMD_install extends AMD_root
26  {
27    private $tablef;
28
29    public function __construct($prefixeTable, $filelocation)
30    {
31      parent::__construct($prefixeTable, $filelocation);
32      $this->tablef= new manage_tables($this->tables);
33    }
34
35    public function __destruct()
36    {
37      unset($this->tablef);
38      parent::__destruct();
39    }
40
41    /*
42     * function for installation process
43     * return true if install process is ok, otherwise false
44     */
45    public function install()
46    {
47      global $user, $lang;
48
49      $tables_def=array(
50"CREATE TABLE `".$this->tables['used_tags']."` (
51  `numId` int(10) unsigned NOT NULL auto_increment,
52  `tagId` varchar(80) NOT NULL default '',
53  `translatable` char(1) NOT NULL default 'n',
54  `name` varchar(200) NOT NULL default '',
55  `numOfImg` int(10) unsigned NOT NULL default '0',
56  PRIMARY KEY  (`numId`),
57  KEY `by_tag` (`tagId`)
58);",
59"CREATE TABLE `".$this->tables['images_tags']."` (
60  `imageId` mediumint(8) unsigned NOT NULL default '0',
61  `numId` int(10) unsigned NOT NULL default '0',
62  `value` varchar(255) default NULL,
63  PRIMARY KEY  USING BTREE (`imageId`,`numId`)
64);",
65"CREATE TABLE `".$this->tables['images']."` (
66  `imageId` MEDIUMINT(8) UNSIGNED NOT NULL,
67  `analyzed` CHAR(1)  NOT NULL DEFAULT 'n',
68  `nbTags` int(10) unsigned NOT NULL default '0',
69  PRIMARY KEY (`imageId`)
70);",
71"CREATE TABLE `".$this->tables['selected_tags']."` (
72  `tagId` VARCHAR(80)  NOT NULL,
73  `order` INTEGER UNSIGNED NOT NULL DEFAULT 0,
74  `groupId` INTEGER  NOT NULL DEFAULT -1,
75  PRIMARY KEY (`tagId`)
76);",
77"CREATE TABLE `".$this->tables['groups_names']."` (
78  `groupId` INTEGER  NOT NULL,
79  `lang` CHAR(5)  NOT NULL,
80  `name` VARCHAR(80)  NOT NULL,
81  PRIMARY KEY (`groupId`, `lang`)
82);",
83"CREATE TABLE `".$this->tables['groups']."` (
84  `groupId` INTEGER  NOT NULL AUTO_INCREMENT,
85  `order` INTEGER UNSIGNED NOT NULL DEFAULT 0,
86  PRIMARY KEY (`groupId`)
87);"
88);
89      //$table_def array
90      $tables_def = create_table_add_character_set($tables_def);
91      $result=$this->tablef->create_tables($tables_def);
92      unset($tables_def);
93
94      $tables_insert=array(
95"INSERT INTO `".$this->tables['groups']."` VALUES(1, 0)",
96"INSERT INTO `".$this->tables['groups_names']."` VALUES(1, '".$user['language']."', '".$lang['g003_default_group_name']."')",
97"INSERT INTO `".$this->tables['selected_tags']."` VALUES
98    ('magic.Camera.Make', 0, 1),
99    ('magic.Camera.Model', 1, 1),
100    ('magic.ShotInfo.Lens', 2, 1),
101    ('magic.ShotInfo.Aperture', 3, 1),
102    ('magic.ShotInfo.Exposure', 4, 1),
103    ('magic.ShotInfo.ISO', 5, 1),
104    ('magic.ShotInfo.FocalLength', 6, 1),
105    ('magic.ShotInfo.FocalLengthIn35mm', 7, 1),
106    ('magic.ShotInfo.Flash.Fired', 8, 1)"
107      );
108      foreach($tables_insert as $sql)
109      {
110        pwg_query($sql);
111      }
112
113      return($result);
114    }
115
116
117    /*
118        function for uninstall process
119    */
120    public function uninstall()
121    {
122      $this->delete_config();
123      $this->tablef->drop_tables();
124    }
125
126    public function activate()
127    {
128      global $template;
129
130
131      pwg_query("DELETE FROM ".$this->tables['used_tags']);
132      pwg_query("DELETE FROM ".$this->tables['images_tags']);
133      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'].")");
138      /*
139       * fill the 'used_tags' table with default values
140       */
141      foreach(JpegMetaData::getTagList(Array('filter' => JpegMetaData::TAGFILTER_IMPLEMENTED, 'xmp' => true, 'maker' => true, 'iptc' => true)) as $key => $val)
142      {
143        $sql="INSERT INTO ".$this->tables['used_tags']." VALUES('', '".$key."', '".(($val['translatable'])?'y':'n')."', '".$val['name']."', 0);";
144        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();
205      }
206
207      $this->init_config();
208      $this->load_config();
209      $this->save_config();
210    }
211
212
213    public function deactivate()
214    {
215    }
216
217  } //class
218
219?>
Note: See TracBrowser for help on using the repository browser.