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

Revision 5191, 6.4 KB checked in by grum, 10 years ago (diff)

add metadata help

  • Property svn:executable set to *
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, $user;
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            WHERE tc.user_id = ".$user['id']."
155            ORDER BY RAND() LIMIT 25;";
156      $result=pwg_query($sql);
157      if($result)
158      {
159        while($row=mysql_fetch_assoc($result))
160        {
161          $listToAnalyze[0][]=$row;
162          $listToAnalyze[1][]=$row['id'];
163        }
164      }
165      /*
166       * if caddie is empty, of is have less than 25 pictures, select other
167       * pictures from the gallery
168       */
169      if(count($listToAnalyze[0])<25)
170      {
171        if(count($listToAnalyze[0])>0)
172        {
173          $excludeList="WHERE ti.id NOT IN(".implode(",", $listToAnalyze[1]).") ";
174        }
175        else
176        {
177          $excludeList="";
178        }
179        $sql="SELECT ti.id, ti.path
180              FROM ".IMAGES_TABLE." ti ".$excludeList."
181              ORDER BY RAND() LIMIT ".(25-count($listToAnalyze[0])).";";
182        $result=pwg_query($sql);
183        if($result)
184        {
185          while($row=mysql_fetch_assoc($result))
186          {
187            $listToAnalyze[0][]=$row;
188          }
189        }
190      }
191
192      /*
193       * analyze the 25 selected pictures
194       */
195      if(count($listToAnalyze[0])>0)
196      {
197        // $path = path of piwigo's on the server filesystem
198        $path=dirname(dirname(dirname(__FILE__)));
199
200        foreach($listToAnalyze[0] as $val)
201        {
202          $this->analyzeImageFile($path."/".$val['path'], $val['id']);
203        }
204
205        $this->makeStatsConsolidation();
206      }
207
208      $this->init_config();
209      $this->load_config();
210      $this->save_config();
211    }
212
213
214    public function deactivate()
215    {
216    }
217
218  } //class
219
220?>
Note: See TracBrowser for help on using the repository browser.