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 GPCTables($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 | $this->initConfig(); |
---|
50 | $this->loadConfig(); |
---|
51 | $this->config['installed']=AMD_VERSION2; |
---|
52 | $this->saveConfig(); |
---|
53 | |
---|
54 | $tables_def=array( |
---|
55 | "CREATE TABLE `".$this->tables['used_tags']."` ( |
---|
56 | `numId` int(10) unsigned NOT NULL auto_increment, |
---|
57 | `tagId` varchar(80) NOT NULL default '', |
---|
58 | `translatable` char(1) NOT NULL default 'n', |
---|
59 | `name` varchar(200) NOT NULL default '', |
---|
60 | `numOfImg` int(10) unsigned NOT NULL default '0', |
---|
61 | `translatedName` varchar(200) NOT NULL default '', |
---|
62 | PRIMARY KEY (`numId`), |
---|
63 | KEY `by_tag` (`tagId`) |
---|
64 | );", |
---|
65 | "CREATE TABLE `".$this->tables['images_tags']."` ( |
---|
66 | `imageId` mediumint(8) unsigned NOT NULL default '0', |
---|
67 | `numId` int(10) unsigned NOT NULL default '0', |
---|
68 | `value` text default NULL, |
---|
69 | PRIMARY KEY USING BTREE (`imageId`,`numId`) |
---|
70 | );", |
---|
71 | "CREATE TABLE `".$this->tables['images']."` ( |
---|
72 | `imageId` MEDIUMINT(8) UNSIGNED NOT NULL, |
---|
73 | `analyzed` CHAR(1) NOT NULL DEFAULT 'n', |
---|
74 | `nbTags` int(10) unsigned NOT NULL default '0', |
---|
75 | PRIMARY KEY (`imageId`) |
---|
76 | );", |
---|
77 | "CREATE TABLE `".$this->tables['selected_tags']."` ( |
---|
78 | `tagId` VARCHAR(80) NOT NULL, |
---|
79 | `order` INTEGER UNSIGNED NOT NULL DEFAULT 0, |
---|
80 | `groupId` INTEGER NOT NULL DEFAULT -1, |
---|
81 | PRIMARY KEY (`tagId`) |
---|
82 | );", |
---|
83 | "CREATE TABLE `".$this->tables['groups_names']."` ( |
---|
84 | `groupId` INTEGER NOT NULL, |
---|
85 | `lang` CHAR(5) NOT NULL, |
---|
86 | `name` VARCHAR(80) NOT NULL, |
---|
87 | PRIMARY KEY (`groupId`, `lang`) |
---|
88 | );", |
---|
89 | "CREATE TABLE `".$this->tables['groups']."` ( |
---|
90 | `groupId` INTEGER NOT NULL AUTO_INCREMENT, |
---|
91 | `order` INTEGER UNSIGNED NOT NULL DEFAULT 0, |
---|
92 | PRIMARY KEY (`groupId`) |
---|
93 | );" |
---|
94 | ); |
---|
95 | //$table_def array |
---|
96 | $tables_def = create_table_add_character_set($tables_def); |
---|
97 | $result=$this->tablef->create($tables_def); |
---|
98 | unset($tables_def); |
---|
99 | |
---|
100 | $tables_insert=array( |
---|
101 | "INSERT INTO `".$this->tables['groups']."` VALUES(1, 0)", |
---|
102 | "INSERT INTO `".$this->tables['groups_names']."` VALUES(1, '".$user['language']."', '".$lang['g003_default_group_name']."')", |
---|
103 | "INSERT INTO `".$this->tables['selected_tags']."` VALUES |
---|
104 | ('magic.Camera.Make', 0, 1), |
---|
105 | ('magic.Camera.Model', 1, 1), |
---|
106 | ('magic.ShotInfo.Lens', 2, 1), |
---|
107 | ('magic.ShotInfo.Aperture', 3, 1), |
---|
108 | ('magic.ShotInfo.Exposure', 4, 1), |
---|
109 | ('magic.ShotInfo.ISO', 5, 1), |
---|
110 | ('magic.ShotInfo.FocalLength', 6, 1), |
---|
111 | ('magic.ShotInfo.FocalLengthIn35mm', 7, 1), |
---|
112 | ('magic.ShotInfo.Flash.Fired', 8, 1)" |
---|
113 | ); |
---|
114 | foreach($tables_insert as $sql) |
---|
115 | { |
---|
116 | pwg_query($sql); |
---|
117 | } |
---|
118 | |
---|
119 | return($result); |
---|
120 | } |
---|
121 | |
---|
122 | |
---|
123 | /* |
---|
124 | function for uninstall process |
---|
125 | */ |
---|
126 | public function uninstall() |
---|
127 | { |
---|
128 | $this->deleteConfig(); |
---|
129 | $this->tablef->drop(); |
---|
130 | } |
---|
131 | |
---|
132 | public function activate() |
---|
133 | { |
---|
134 | global $template, $user; |
---|
135 | L10n::setLanguage('en_UK'); |
---|
136 | |
---|
137 | pwg_query("DELETE FROM ".$this->tables['used_tags']); |
---|
138 | pwg_query("DELETE FROM ".$this->tables['images_tags']); |
---|
139 | pwg_query("UPDATE ".$this->tables['images']." SET analyzed='n', nbTags=0;"); |
---|
140 | pwg_query("INSERT INTO ".$this->tables['images']." |
---|
141 | SELECT id, 'n', 0 |
---|
142 | FROM ".IMAGES_TABLE." |
---|
143 | WHERE id NOT IN (SELECT imageId FROM ".$this->tables['images'].")"); |
---|
144 | /* |
---|
145 | * fill the 'used_tags' table with default values |
---|
146 | */ |
---|
147 | foreach(AMD_JpegMetaData::getTagList(Array('filter' => AMD_JpegMetaData::TAGFILTER_IMPLEMENTED, 'xmp' => true, 'maker' => true, 'iptc' => true)) as $key => $val) |
---|
148 | { |
---|
149 | $sql="INSERT INTO ".$this->tables['used_tags']." VALUES('', '".$key."', '".(($val['translatable'])?'y':'n')."', '".$val['name']."', 0, '".addslashes(L10n::get($val['name']))."');"; |
---|
150 | pwg_query($sql); |
---|
151 | } |
---|
152 | |
---|
153 | $listToAnalyze=Array(Array(), Array()); |
---|
154 | /* |
---|
155 | * select 25 pictures into the caddie |
---|
156 | */ |
---|
157 | $sql="SELECT ti.id, ti.path |
---|
158 | FROM ".CADDIE_TABLE." tc |
---|
159 | LEFT JOIN ".IMAGES_TABLE." ti ON ti.id = tc.element_id |
---|
160 | WHERE tc.user_id = ".$user['id']." |
---|
161 | AND ti.id IS NOT NULL |
---|
162 | ORDER BY RAND() LIMIT 25;"; |
---|
163 | $result=pwg_query($sql); |
---|
164 | if($result) |
---|
165 | { |
---|
166 | while($row=pwg_db_fetch_assoc($result)) |
---|
167 | { |
---|
168 | $listToAnalyze[0][]=$row; |
---|
169 | $listToAnalyze[1][]=$row['id']; |
---|
170 | } |
---|
171 | } |
---|
172 | /* |
---|
173 | * if caddie is empty, of is have less than 25 pictures, select other |
---|
174 | * pictures from the gallery |
---|
175 | */ |
---|
176 | if(count($listToAnalyze[0])<25) |
---|
177 | { |
---|
178 | if(count($listToAnalyze[0])>0) |
---|
179 | { |
---|
180 | $excludeList="WHERE ti.id NOT IN(".implode(",", $listToAnalyze[1]).") "; |
---|
181 | } |
---|
182 | else |
---|
183 | { |
---|
184 | $excludeList=""; |
---|
185 | } |
---|
186 | $sql="SELECT ti.id, ti.path |
---|
187 | FROM ".IMAGES_TABLE." ti ".$excludeList." |
---|
188 | ORDER BY RAND() LIMIT ".(25-count($listToAnalyze[0])).";"; |
---|
189 | $result=pwg_query($sql); |
---|
190 | if($result) |
---|
191 | { |
---|
192 | while($row=pwg_db_fetch_assoc($result)) |
---|
193 | { |
---|
194 | $listToAnalyze[0][]=$row; |
---|
195 | } |
---|
196 | } |
---|
197 | } |
---|
198 | |
---|
199 | /* |
---|
200 | * analyze the 25 selected pictures |
---|
201 | */ |
---|
202 | if(count($listToAnalyze[0])>0) |
---|
203 | { |
---|
204 | // $path = path of piwigo's on the server filesystem |
---|
205 | $path=dirname(dirname(dirname(__FILE__))); |
---|
206 | |
---|
207 | foreach($listToAnalyze[0] as $val) |
---|
208 | { |
---|
209 | $this->analyzeImageFile($path."/".$val['path'], $val['id']); |
---|
210 | } |
---|
211 | |
---|
212 | $this->makeStatsConsolidation(); |
---|
213 | } |
---|
214 | |
---|
215 | $this->initConfig(); |
---|
216 | $this->loadConfig(); |
---|
217 | $this->config['installed']=AMD_VERSION2; //update the installed release number |
---|
218 | $this->saveConfig(); |
---|
219 | } |
---|
220 | |
---|
221 | |
---|
222 | public function deactivate() |
---|
223 | { |
---|
224 | } |
---|
225 | |
---|
226 | } //class |
---|
227 | |
---|
228 | ?> |
---|