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

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

Install process make a default config (select metadata, add a predefined group, set default values for filters)

  • Property svn:executable set to *
File size: 4.4 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 AMD_install($prefixeTable, $filelocation)
30    {
31      parent::__construct($prefixeTable, $filelocation);
32      $this->tablef= new manage_tables($this->tables);
33    }
34
35    /*
36     * function for installation process
37     * return true if install process is ok, otherwise false
38     */
39    public function install()
40    {
41      global $user, $lang;
42
43      $tables_def=array(
44"CREATE TABLE `".$this->tables['used_tags']."` (
45  `numId` int(10) unsigned NOT NULL auto_increment,
46  `tagId` varchar(80) NOT NULL default '',
47  `translatable` char(1) NOT NULL default 'n',
48  `name` varchar(200) NOT NULL default '',
49  `numOfImg` int(10) unsigned NOT NULL default '0',
50  PRIMARY KEY  (`numId`),
51  KEY `by_tag` (`tagId`)
52);",
53"CREATE TABLE `".$this->tables['images_tags']."` (
54  `imageId` mediumint(8) unsigned NOT NULL default '0',
55  `numId` int(10) unsigned NOT NULL default '0',
56  `value` varchar(255) default NULL,
57  PRIMARY KEY  USING BTREE (`imageId`,`numId`)
58);",
59"CREATE TABLE `".$this->tables['images']."` (
60  `imageId` MEDIUMINT(8) UNSIGNED NOT NULL,
61  `analyzed` CHAR(1)  NOT NULL DEFAULT 'n',
62  `nbTags` int(10) unsigned NOT NULL default '0',
63  PRIMARY KEY (`imageId`)
64);",
65"CREATE TABLE `".$this->tables['selected_tags']."` (
66  `tagId` VARCHAR(80)  NOT NULL,
67  `order` INTEGER UNSIGNED NOT NULL DEFAULT 0,
68  `groupId` INTEGER  NOT NULL DEFAULT -1,
69  PRIMARY KEY (`tagId`)
70);",
71"CREATE TABLE `".$this->tables['groups_names']."` (
72  `groupId` INTEGER  NOT NULL,
73  `lang` CHAR(5)  NOT NULL,
74  `name` VARCHAR(80)  NOT NULL,
75  PRIMARY KEY (`groupId`, `lang`)
76);",
77"CREATE TABLE `".$this->tables['groups']."` (
78  `groupId` INTEGER  NOT NULL AUTO_INCREMENT,
79  `order` INTEGER UNSIGNED NOT NULL DEFAULT 0,
80  PRIMARY KEY (`groupId`)
81);"
82);
83      //$table_def array
84      $tables_def = create_table_add_character_set($tables_def);
85      $result=$this->tablef->create_tables($tables_def);
86      unset($tables_def);
87
88      $tables_insert=array(
89"INSERT INTO `".$this->tables['groups']."` VALUES(1, 0)",
90"INSERT INTO `".$this->tables['groups_names']."` VALUES(1, '".$user['language']."', '".$lang['g003_default_group_name']."')",
91"INSERT INTO `".$this->tables['selected_tags']."` VALUES
92    ('magic.Camera.Make', 0, 1),
93    ('magic.Camera.Model', 1, 1),
94    ('magic.ShotInfo.Lens', 2, 1),
95    ('magic.ShotInfo.Aperture', 3, 1),
96    ('magic.ShotInfo.Exposure', 4, 1),
97    ('magic.ShotInfo.ISO', 5, 1),
98    ('magic.ShotInfo.FocalLength', 6, 1),
99    ('magic.ShotInfo.FocalLengthIn35mm', 7, 1),
100    ('magic.ShotInfo.Flash.Fired', 8, 1)"
101      );
102      foreach($tables_insert as $sql)
103      {
104        pwg_query($sql);
105      }
106
107      return($result);
108    }
109
110
111    /*
112        function for uninstall process
113    */
114    public function uninstall()
115    {
116      $this->delete_config();
117      $this->tablef->drop_tables();
118    }
119
120    public function activate()
121    {
122      global $template;
123
124
125      pwg_query("DELETE FROM ".$this->tables['used_tags']);
126      pwg_query("DELETE FROM ".$this->tables['images_tags']);
127      pwg_query("UPDATE ".$this->tables['images']." SET analyzed='n', nbTags=0;");
128      /*
129       * fill the 'used_tags' table with default values
130       */
131      foreach(JpegMetaData::getTagList(Array('filter' => JpegMetaData::TAGFILTER_IMPLEMENTED, 'xmp' => true, 'maker' => true, 'iptc' => true)) as $key => $val)
132      {
133        $sql="INSERT INTO ".$this->tables['used_tags']." VALUES('', '".$key."', '".(($val['translatable'])?'y':'n')."', '".$val['name']."', 0);";
134        pwg_query($sql);
135      }
136
137      $this->init_config();
138      $this->load_config();
139      $this->save_config();
140    }
141
142
143    public function deactivate()
144    {
145    }
146
147  } //class
148
149?>
Note: See TracBrowser for help on using the repository browser.