[4905] | 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 | |
---|
[5183] | 29 | public function __construct($prefixeTable, $filelocation) |
---|
[4905] | 30 | { |
---|
| 31 | parent::__construct($prefixeTable, $filelocation); |
---|
[5935] | 32 | $this->tablef= new GPCTables($this->tables); |
---|
[4905] | 33 | } |
---|
| 34 | |
---|
[5183] | 35 | public function __destruct() |
---|
| 36 | { |
---|
| 37 | unset($this->tablef); |
---|
| 38 | parent::__destruct(); |
---|
| 39 | } |
---|
| 40 | |
---|
[4905] | 41 | /* |
---|
| 42 | * function for installation process |
---|
| 43 | * return true if install process is ok, otherwise false |
---|
| 44 | */ |
---|
| 45 | public function install() |
---|
| 46 | { |
---|
[5040] | 47 | global $user, $lang; |
---|
| 48 | |
---|
[5935] | 49 | $this->initConfig(); |
---|
| 50 | $this->loadConfig(); |
---|
| 51 | $this->config['installed']=AMD_VERSION2; |
---|
| 52 | $this->saveConfig(); |
---|
| 53 | |
---|
[4905] | 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', |
---|
[5226] | 61 | `translatedName` varchar(200) NOT NULL default '', |
---|
[4905] | 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', |
---|
[5226] | 68 | `value` text default NULL, |
---|
[4905] | 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 | );", |
---|
[4906] | 77 | "CREATE TABLE `".$this->tables['selected_tags']."` ( |
---|
[4905] | 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`) |
---|
[6722] | 93 | );", |
---|
| 94 | "CREATE TABLE `".$this->tables['user_tags_label']."` ( |
---|
| 95 | `numId` INTEGER UNSIGNED NOT NULL, |
---|
| 96 | `lang` CHAR(5) NOT NULL, |
---|
| 97 | `label` VARCHAR(200) NOT NULL, |
---|
| 98 | PRIMARY KEY (`numId`, `lang`) |
---|
| 99 | );", |
---|
| 100 | "CREATE TABLE `".$this->tables['user_tags_def']."` ( |
---|
[6730] | 101 | `numId` int(10) unsigned NOT NULL COMMENT 'Id of the tag', |
---|
| 102 | `defId` int(10) unsigned NOT NULL default '0' COMMENT 'also used for ordering', |
---|
[6722] | 103 | `parentId` int(10) unsigned NOT NULL default '0' COMMENT 'Id of the parent', |
---|
[6730] | 104 | `order` int(10) unsigned NOT NULL, |
---|
[6722] | 105 | `type` char(1) NOT NULL default 'T' COMMENT 'T = static text ; M = metadata value ; C = condition', |
---|
| 106 | `value` varchar(200) NOT NULL, |
---|
| 107 | `conditionType` char(2) NOT NULL default 'E', |
---|
| 108 | `conditionValue` varchar(200) NOT NULL, |
---|
[6730] | 109 | PRIMARY KEY (`numId`,`defId`), |
---|
| 110 | KEY `byTagParentId` USING BTREE (`numId`,`parentId`,`order`), |
---|
| 111 | KEY `byTagOrder` (`numId`,`order`) |
---|
[6722] | 112 | );", |
---|
| 113 | ); |
---|
| 114 | |
---|
| 115 | |
---|
[4905] | 116 | $tables_def = create_table_add_character_set($tables_def); |
---|
[5935] | 117 | $result=$this->tablef->create($tables_def); |
---|
[5040] | 118 | unset($tables_def); |
---|
[4905] | 119 | |
---|
[5040] | 120 | $tables_insert=array( |
---|
| 121 | "INSERT INTO `".$this->tables['groups']."` VALUES(1, 0)", |
---|
| 122 | "INSERT INTO `".$this->tables['groups_names']."` VALUES(1, '".$user['language']."', '".$lang['g003_default_group_name']."')", |
---|
| 123 | "INSERT INTO `".$this->tables['selected_tags']."` VALUES |
---|
| 124 | ('magic.Camera.Make', 0, 1), |
---|
| 125 | ('magic.Camera.Model', 1, 1), |
---|
| 126 | ('magic.ShotInfo.Lens', 2, 1), |
---|
| 127 | ('magic.ShotInfo.Aperture', 3, 1), |
---|
| 128 | ('magic.ShotInfo.Exposure', 4, 1), |
---|
| 129 | ('magic.ShotInfo.ISO', 5, 1), |
---|
| 130 | ('magic.ShotInfo.FocalLength', 6, 1), |
---|
| 131 | ('magic.ShotInfo.FocalLengthIn35mm', 7, 1), |
---|
| 132 | ('magic.ShotInfo.Flash.Fired', 8, 1)" |
---|
| 133 | ); |
---|
| 134 | foreach($tables_insert as $sql) |
---|
| 135 | { |
---|
| 136 | pwg_query($sql); |
---|
| 137 | } |
---|
| 138 | |
---|
[4905] | 139 | return($result); |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | |
---|
| 143 | /* |
---|
| 144 | function for uninstall process |
---|
| 145 | */ |
---|
| 146 | public function uninstall() |
---|
| 147 | { |
---|
[5935] | 148 | $this->deleteConfig(); |
---|
| 149 | $this->tablef->drop(); |
---|
[4905] | 150 | } |
---|
| 151 | |
---|
| 152 | public function activate() |
---|
| 153 | { |
---|
[5191] | 154 | global $template, $user; |
---|
[6722] | 155 | |
---|
| 156 | $this->initConfig(); |
---|
| 157 | $this->loadConfig(); |
---|
[6729] | 158 | $this->loadConfigFromFile(dirname($this->getFileLocation()).'/activatePlugin.conf.php'); |
---|
[6722] | 159 | |
---|
| 160 | /* |
---|
| 161 | * if there is no version information available, assume the previous |
---|
| 162 | * installed release of the plugin is 0.4.0 |
---|
| 163 | */ |
---|
| 164 | if(!isset($this->config['installed'])) $this->config['installed']='00.04.00'; |
---|
| 165 | |
---|
| 166 | switch($this->config['installed']) |
---|
| 167 | { |
---|
| 168 | case '00.04.00': |
---|
| 169 | $this->updateFrom_000400(); |
---|
| 170 | break; |
---|
| 171 | default: |
---|
| 172 | /* |
---|
| 173 | * default is applied for fresh install, and consist to fill the |
---|
| 174 | * database with default values |
---|
| 175 | */ |
---|
| 176 | $this->initializeDatabase(); |
---|
| 177 | break; |
---|
| 178 | } |
---|
| 179 | |
---|
[6729] | 180 | $this->config['amd_FillDataBaseExcludeTags']=array(); |
---|
[6722] | 181 | $this->config['installed']=AMD_VERSION2; //update the installed release number |
---|
| 182 | $this->saveConfig(); |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | |
---|
| 186 | public function deactivate() |
---|
| 187 | { |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | /** |
---|
| 191 | * update the database from the release 0.4.0 |
---|
| 192 | */ |
---|
| 193 | private function updateFrom_000400() |
---|
| 194 | { |
---|
| 195 | /* |
---|
| 196 | * create new tables |
---|
| 197 | */ |
---|
| 198 | $tableDef=array( |
---|
| 199 | "CREATE TABLE `".$this->tables['user_tags_label']."` ( |
---|
| 200 | `numId` INTEGER UNSIGNED NOT NULL, |
---|
| 201 | `lang` CHAR(5) NOT NULL, |
---|
| 202 | `label` VARCHAR(200) NOT NULL, |
---|
| 203 | PRIMARY KEY (`numId`, `lang`) |
---|
| 204 | );", |
---|
| 205 | "CREATE TABLE `".$this->tables['user_tags_def']."` ( |
---|
[6730] | 206 | `numId` int(10) unsigned NOT NULL COMMENT 'Id of the tag', |
---|
| 207 | `defId` int(10) unsigned NOT NULL default '0' COMMENT 'also used for ordering', |
---|
[6722] | 208 | `parentId` int(10) unsigned NOT NULL default '0' COMMENT 'Id of the parent', |
---|
[6730] | 209 | `order` int(10) unsigned NOT NULL, |
---|
[6722] | 210 | `type` char(1) NOT NULL default 'T' COMMENT 'T = static text ; M = metadata value ; C = condition', |
---|
| 211 | `value` varchar(200) NOT NULL, |
---|
| 212 | `conditionType` char(2) NOT NULL default 'E', |
---|
| 213 | `conditionValue` varchar(200) NOT NULL, |
---|
[6730] | 214 | PRIMARY KEY (`numId`,`defId`), |
---|
| 215 | KEY `byTagParentId` USING BTREE (`numId`,`parentId`,`order`), |
---|
| 216 | KEY `byTagOrder` (`numId`,`order`) |
---|
[6722] | 217 | );" |
---|
| 218 | ); |
---|
| 219 | $tablesDef = create_table_add_character_set($tablesDef); |
---|
| 220 | $result=$this->tablef->create($tablesDef); |
---|
| 221 | unset($tablesDef); |
---|
| 222 | |
---|
| 223 | /* |
---|
| 224 | * update old tables |
---|
| 225 | */ |
---|
| 226 | |
---|
| 227 | // no tables to update |
---|
| 228 | } |
---|
| 229 | |
---|
| 230 | |
---|
| 231 | |
---|
| 232 | |
---|
| 233 | /** |
---|
| 234 | * fill the database with some default value |
---|
| 235 | */ |
---|
| 236 | private function initializeDatabase() |
---|
| 237 | { |
---|
[6729] | 238 | global $user; |
---|
| 239 | |
---|
[5226] | 240 | L10n::setLanguage('en_UK'); |
---|
[4905] | 241 | |
---|
[4931] | 242 | pwg_query("DELETE FROM ".$this->tables['used_tags']); |
---|
| 243 | pwg_query("DELETE FROM ".$this->tables['images_tags']); |
---|
| 244 | pwg_query("UPDATE ".$this->tables['images']." SET analyzed='n', nbTags=0;"); |
---|
[5183] | 245 | pwg_query("INSERT INTO ".$this->tables['images']." |
---|
| 246 | SELECT id, 'n', 0 |
---|
| 247 | FROM ".IMAGES_TABLE." |
---|
| 248 | WHERE id NOT IN (SELECT imageId FROM ".$this->tables['images'].")"); |
---|
[4931] | 249 | /* |
---|
| 250 | * fill the 'used_tags' table with default values |
---|
| 251 | */ |
---|
[5790] | 252 | foreach(AMD_JpegMetaData::getTagList(Array('filter' => AMD_JpegMetaData::TAGFILTER_IMPLEMENTED, 'xmp' => true, 'maker' => true, 'iptc' => true)) as $key => $val) |
---|
[4931] | 253 | { |
---|
[5935] | 254 | $sql="INSERT INTO ".$this->tables['used_tags']." VALUES('', '".$key."', '".(($val['translatable'])?'y':'n')."', '".$val['name']."', 0, '".addslashes(L10n::get($val['name']))."');"; |
---|
[4931] | 255 | pwg_query($sql); |
---|
| 256 | } |
---|
| 257 | |
---|
[6729] | 258 | /* |
---|
| 259 | * exclude unauthorized tag with the 'amd_FillDataBaseExcludeTags' option |
---|
| 260 | */ |
---|
| 261 | if(count($this->config['amd_FillDataBaseExcludeTags'])) |
---|
| 262 | { |
---|
| 263 | $sql=""; |
---|
| 264 | foreach($this->config['amd_FillDataBaseExcludeTags'] as $key => $tag) |
---|
| 265 | { |
---|
| 266 | if($sql!="") $sql.=" OR "; |
---|
| 267 | $sql.=" tagId LIKE '$tag' "; |
---|
| 268 | } |
---|
| 269 | $sql="DELETE FROM ".$this->tables['used_tags']." |
---|
| 270 | WHERE ".$sql; |
---|
| 271 | pwg_query($sql); |
---|
| 272 | } |
---|
| 273 | |
---|
[5183] | 274 | $listToAnalyze=Array(Array(), Array()); |
---|
| 275 | /* |
---|
| 276 | * select 25 pictures into the caddie |
---|
| 277 | */ |
---|
| 278 | $sql="SELECT ti.id, ti.path |
---|
| 279 | FROM ".CADDIE_TABLE." tc |
---|
| 280 | LEFT JOIN ".IMAGES_TABLE." ti ON ti.id = tc.element_id |
---|
[5191] | 281 | WHERE tc.user_id = ".$user['id']." |
---|
[5935] | 282 | AND ti.id IS NOT NULL |
---|
[5183] | 283 | ORDER BY RAND() LIMIT 25;"; |
---|
| 284 | $result=pwg_query($sql); |
---|
| 285 | if($result) |
---|
| 286 | { |
---|
[5959] | 287 | while($row=pwg_db_fetch_assoc($result)) |
---|
[5183] | 288 | { |
---|
| 289 | $listToAnalyze[0][]=$row; |
---|
| 290 | $listToAnalyze[1][]=$row['id']; |
---|
| 291 | } |
---|
| 292 | } |
---|
| 293 | /* |
---|
| 294 | * if caddie is empty, of is have less than 25 pictures, select other |
---|
| 295 | * pictures from the gallery |
---|
| 296 | */ |
---|
| 297 | if(count($listToAnalyze[0])<25) |
---|
| 298 | { |
---|
| 299 | if(count($listToAnalyze[0])>0) |
---|
| 300 | { |
---|
| 301 | $excludeList="WHERE ti.id NOT IN(".implode(",", $listToAnalyze[1]).") "; |
---|
| 302 | } |
---|
| 303 | else |
---|
| 304 | { |
---|
| 305 | $excludeList=""; |
---|
| 306 | } |
---|
| 307 | $sql="SELECT ti.id, ti.path |
---|
| 308 | FROM ".IMAGES_TABLE." ti ".$excludeList." |
---|
| 309 | ORDER BY RAND() LIMIT ".(25-count($listToAnalyze[0])).";"; |
---|
| 310 | $result=pwg_query($sql); |
---|
| 311 | if($result) |
---|
| 312 | { |
---|
[5959] | 313 | while($row=pwg_db_fetch_assoc($result)) |
---|
[5183] | 314 | { |
---|
| 315 | $listToAnalyze[0][]=$row; |
---|
| 316 | } |
---|
| 317 | } |
---|
| 318 | } |
---|
| 319 | |
---|
| 320 | /* |
---|
| 321 | * analyze the 25 selected pictures |
---|
| 322 | */ |
---|
| 323 | if(count($listToAnalyze[0])>0) |
---|
| 324 | { |
---|
| 325 | // $path = path of piwigo's on the server filesystem |
---|
| 326 | $path=dirname(dirname(dirname(__FILE__))); |
---|
| 327 | |
---|
| 328 | foreach($listToAnalyze[0] as $val) |
---|
| 329 | { |
---|
| 330 | $this->analyzeImageFile($path."/".$val['path'], $val['id']); |
---|
| 331 | } |
---|
| 332 | |
---|
| 333 | $this->makeStatsConsolidation(); |
---|
| 334 | } |
---|
[4905] | 335 | } |
---|
| 336 | |
---|
| 337 | } //class |
---|
| 338 | |
---|
| 339 | ?> |
---|