source: extensions/AMetaData/amd_aip_install.class.inc.php @ 27153

Last change on this file since 27153 was 16465, checked in by grum, 12 years ago

feature:2637 - compatibility with Piwigo 2.4
Fix bug blocking install process

File size: 11.5 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 * AIPInstall class => install process page when the plugin is used for the
18 *                     first time
19 *
20 * -----------------------------------------------------------------------------
21 */
22
23
24if(!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
25
26include_once('amd_root.class.inc.php');
27include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCTables.class.inc.php');
28include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
29
30class AMD_AIPInstall extends AMD_root
31{
32  protected $tabsheet;
33
34  public function __construct($prefixeTable, $filelocation)
35  {
36    parent::__construct($prefixeTable, $filelocation);
37    $this->loadConfig();
38    $this->initEvents();
39
40    $this->tabsheet = new tabsheet();
41    $this->tabsheet->add('install',
42                          l10n('g003_install'),
43                          $this->getAdminLink()."-install");
44  }
45
46  public function __destruct()
47  {
48    unset($this->tabsheet);
49    parent::__destruct();
50  }
51
52
53  public function loadCSS()
54  {
55    parent::loadCSS();
56    GPCCore::addUI('gpcCSS');
57    GPCCore::addHeaderCSS('amd.css', 'plugins/'.$this->getDirectory().'/'.$this->getPluginNameFiles().".css");
58  }
59
60
61  /*
62    display administration page
63  */
64  public function manage()
65  {
66    global $template;
67
68    $this->checkRequest();
69    $this->returnAjaxContent();
70
71    GPCCore::setTemplateToken();
72
73    $template->set_filename('plugin_admin_content', dirname($this->getFileLocation())."/admin/amd_admin.tpl");
74
75    $this->tabsheet->select($_GET['tab']);
76    $this->tabsheet->assign();
77    $selected_tab=$this->tabsheet->get_selected();
78    $template->assign($this->tabsheet->get_titlename(), "[".$selected_tab['caption']."]");
79
80    $this->displayInstallPage();
81
82    $pluginInfo=array(
83      'AMD_VERSION' => "<i>".$this->getPluginName()."</i> ".l10n('g003_version').AMD_VERSION,
84      'AMD_PAGE' => $_GET['tab'],
85      'PATH' => AMD_PATH
86    );
87
88    $template->assign('plugin', $pluginInfo);
89
90    $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
91  }
92
93
94
95  /**
96   * check the $_REQUEST values and set default values
97   *
98   */
99  protected function checkRequest()
100  {
101    $_GET['tab']='install';
102
103    if(!isset($_REQUEST['ajaxfct'])) return(false);
104
105    /*
106     * check admin.install.chooseInterface values
107     */
108    if($_REQUEST['ajaxfct']=="admin.install.chooseInterface")
109    {
110       if(!isset($_REQUEST['interfaceMode'])) $_REQUEST['interfaceMode']='';
111
112       if(!($_REQUEST['interfaceMode']=="basic" or
113            $_REQUEST['interfaceMode']=="advanced")) $_REQUEST['ajaxfct']='';
114    }
115  }
116
117
118
119  /**
120   * return ajax content
121   */
122  protected function returnAjaxContent()
123  {
124    global $ajax, $template;
125
126    if(isset($_REQUEST['ajaxfct']))
127    {
128      //$this->debug("AJAXFCT:".$_REQUEST['ajaxfct']);
129      $result="<p class='errors'>An error has occured</p>";
130      switch($_REQUEST['ajaxfct'])
131      {
132        case 'admin.install.chooseInterface':
133          $result=$this->ajax_amd_admin_installChooseInterface($_REQUEST['interfaceMode']);
134          break;
135      }
136      GPCAjax::returnResult($result);
137    }
138  }
139
140
141
142  /**
143   * display config page
144   */
145  protected function displayInstallPage()
146  {
147    global $template, $lang;
148
149
150    $template->set_filename('body_page',
151                dirname($this->getFileLocation()).'/admin/amd_install_page.tpl');
152
153
154    $help=Array(
155      'g003_basic_mode_help' => GPCCore::BBtoHTML($lang['g003_basic_mode_help']),
156      'g003_advanced_mode_help' => GPCCore::BBtoHTML($lang['g003_advanced_mode_help'])
157    );
158
159
160    $template->assign('help', $help);
161    $template->assign('urlRequest', $this->getAdminLink());
162
163    $template->assign_var_from_handle('AMD_BODY_PAGE', 'body_page');
164  } //displayInstallPage
165
166
167
168  /**
169   * prepare the tables for the basic interface mode
170   */
171  protected function initializeDatabaseForBasicInterface()
172  {
173    $basicMeta=array(
174      'magic.Author.Artist',
175      'magic.Author.Comment',
176      'magic.Author.Copyright',
177      'magic.Author.ImageTitle',
178      'magic.Author.Keywords',
179      'magic.GPS.Altitude',
180      'magic.GPS.Latitude',
181      'magic.GPS.LatitudeNum',
182      'magic.GPS.Localization',
183      'magic.GPS.Longitude',
184      'magic.GPS.LongitudeNum',
185      'magic.Image.Dimension',
186      'magic.Image.Height',
187      'magic.Image.Width',
188      'magic.Processing.OriginalFileName',
189      'magic.Processing.PostProcessingDateTime',
190      'magic.Processing.PostProcessingSoftware',
191      'magic.Processing.Software',
192      'magic.ShotInfo.DateTime',
193      'magic.ShotInfo.Flash.RedEyeMode',
194      'iptc.By-line',
195      'iptc.By-line Title',
196      'iptc.Caption/Abstract',
197      'iptc.Category',
198      'iptc.City',
199      'iptc.Contact',
200      'iptc.Content Location Code',
201      'iptc.Content Location Name',
202      'iptc.Copyright Notice',
203      'iptc.Country/Primary Location Code',
204      'iptc.Country/Primary Location Name',
205      'iptc.Credit',
206      'iptc.Date Created',
207      'iptc.Date Sent',
208      'iptc.Destination',
209      'iptc.Digital Creation Date',
210      'iptc.Digital Creation Time',
211      'iptc.Edit Status',
212      'iptc.Envelope Number',
213      'iptc.Envelope Priority',
214      'iptc.Expiration Date',
215      'iptc.Expiration Time',
216      'iptc.Fixture Identifier',
217      'iptc.Headline',
218      'iptc.Image Orientation',
219      'iptc.Keywords',
220      'iptc.Language Identifier',
221      'iptc.Object Attribute Reference',
222      'iptc.Object Cycle',
223      'iptc.Object Name',
224      'iptc.Object Type Reference',
225      'iptc.Original Transmission Reference',
226      'iptc.Originating Program',
227      'iptc.Product I.D.',
228      'iptc.Program Version',
229      'iptc.Province/State',
230      'iptc.Release Date',
231      'iptc.Release Time',
232      'iptc.Service Identifier',
233      'iptc.Source',
234      'iptc.Special Instructions',
235      'iptc.Subject Reference',
236      'iptc.Subject Reference[Detail Name]',
237      'iptc.Subject Reference[IPR]',
238      'iptc.Subject Reference[Matter Name]',
239      'iptc.Subject Reference[Name]',
240      'iptc.Subject Reference[Number]',
241      'iptc.Sublocation',
242      'iptc.Supplemental Category',
243      'iptc.Time Created',
244      'iptc.Time Sent',
245      'iptc.Urgency',
246      'iptc.Writer/Editor',
247      'xmp.Iptc4xmpCore:CiAdrCity',
248      'xmp.Iptc4xmpCore:CiAdrCtry',
249      'xmp.Iptc4xmpCore:CiAdrExtadr',
250      'xmp.Iptc4xmpCore:CiAdrPcode',
251      'xmp.Iptc4xmpCore:CiEmailWork',
252      'xmp.Iptc4xmpCore:CiTelWork',
253      'xmp.Iptc4xmpCore:CiUrlWork',
254      'xmp.Iptc4xmpCore:CountryCode',
255      'xmp.Iptc4xmpCore:IntellectualGenre',
256      'xmp.Iptc4xmpCore:Location',
257      'xmp.Iptc4xmpCore:Scene',
258      'xmp.aux:Firmware',
259      'xmp.aux:Lens',
260      'xmp.crs:Balance',
261      'xmp.crs:CameraProfile',
262      'xmp.crs:ColorNoiseReduction',
263      'xmp.crs:Exposure',
264      'xmp.crs:HasCrop',
265      'xmp.crs:HasSettings',
266      'xmp.crs:RawFileName',
267      'xmp.crs:WhiteBalance',
268      'xmp.dc:CreatorTool',
269      'xmp.dc:Type',
270      'xmp.dc:contributor',
271      'xmp.dc:coverage',
272      'xmp.dc:creator',
273      'xmp.dc:description',
274      'xmp.dc:format',
275      'xmp.dc:identifier',
276      'xmp.dc:language',
277      'xmp.dc:publisher',
278      'xmp.dc:relation',
279      'xmp.dc:rights',
280      'xmp.dc:source',
281      'xmp.dc:subject',
282      'xmp.dc:title',
283      'xmp.photoshop:AuthorsPosition',
284      'xmp.photoshop:CaptionWriter',
285      'xmp.photoshop:Category',
286      'xmp.photoshop:City',
287      'xmp.photoshop:Country',
288      'xmp.photoshop:Credit',
289      'xmp.photoshop:DateCreated',
290      'xmp.photoshop:Headline',
291      'xmp.photoshop:ICCProfile',
292      'xmp.photoshop:Instructions',
293      'xmp.photoshop:Source',
294      'xmp.photoshop:State',
295      'xmp.photoshop:SupplementalCategories',
296      'xmp.photoshop:TransmissionReference',
297      'xmp.photoshop:Urgency',
298      'xmp.tiff:Artist',
299      'xmp.tiff:Copyright',
300      'xmp.tiff:DateTime',
301      'xmp.tiff:ImageDescription',
302      'xmp.tiff:Software',
303      'xmp.xmp:Advisory',
304      'xmp.xmp:BaseURL',
305      'xmp.xmp:CreateDate',
306      'xmp.xmp:CreatorTool',
307      'xmp.xmp:Identifier',
308      'xmp.xmp:Label',
309      'xmp.xmp:MetadataDate',
310      'xmp.xmp:ModifyDate',
311      'xmp.xmp:Nickname',
312      'xmp.xmp:Rating',
313      'xmp.xmpRights:Certificate',
314      'xmp.xmpRights:Marked',
315      'xmp.xmpRights:Owner',
316      'xmp.xmpRights:UsageTerms',
317      'xmp.xmpRights:WebStatement'
318    );
319
320    $sql="";
321    foreach($basicMeta as $key=>$val)
322    {
323      $basicMeta[$key]="('$val', 0, -1)";
324    }
325    $sql="INSERT INTO `".$this->tables['selected_tags']."` VALUES ".implode(',', $basicMeta);
326    pwg_query($sql);
327  }
328
329  /**
330   * prepare the tables for the advanced interface mode
331   */
332  protected function initializeDatabaseForAdvancedInterface()
333  {
334    global $user;
335
336    $listToAnalyze=Array(Array(), Array());
337    /*
338     * select 25 pictures into the caddie
339     */
340    $sql="SELECT ti.id, ti.path
341          FROM ".CADDIE_TABLE." tc
342            LEFT JOIN ".IMAGES_TABLE." ti ON ti.id = tc.element_id
343          WHERE tc.user_id = ".$user['id']."
344            AND ti.id IS NOT NULL
345          ORDER BY RAND() LIMIT 25;";
346    $result=pwg_query($sql);
347    if($result)
348    {
349      while($row=pwg_db_fetch_assoc($result))
350      {
351        $listToAnalyze[0][]=$row;
352        $listToAnalyze[1][]=$row['id'];
353      }
354    }
355    /*
356     * if caddie is empty, of is have less than 25 pictures, select other
357     * pictures from the gallery
358     */
359    if(count($listToAnalyze[0])<25)
360    {
361      if(count($listToAnalyze[0])>0)
362      {
363        $excludeList="WHERE ti.id NOT IN(".implode(",", $listToAnalyze[1]).") ";
364      }
365      else
366      {
367        $excludeList="";
368      }
369      $sql="SELECT ti.id, ti.path
370            FROM ".IMAGES_TABLE." ti ".$excludeList."
371            ORDER BY RAND() LIMIT ".(25-count($listToAnalyze[0])).";";
372      $result=pwg_query($sql);
373      if($result)
374      {
375        while($row=pwg_db_fetch_assoc($result))
376        {
377          $listToAnalyze[0][]=$row;
378        }
379      }
380    }
381
382    /*
383     * analyze the 25 selected pictures
384     */
385    if(count($listToAnalyze[0])>0)
386    {
387      // $path = path of piwigo's on the server filesystem
388      $path=dirname(dirname(dirname(__FILE__)));
389
390      foreach($listToAnalyze[0] as $val)
391      {
392        $this->analyzeImageFile($path."/".$val['path'], $val['id']);
393      }
394      $this->makeStatsConsolidation();
395    }
396  }
397
398
399
400  /*
401   *  ---------------------------------------------------------------------------
402   * AJAX FUNCTIONS
403   * ---------------------------------------------------------------------------
404   */
405
406  /**
407   * set choice for plugin interface mode (basic/advanced)
408   * @param String $interfaceMode : mode for the interface 'basic' or 'advanced'
409   * @return String : ok or ko
410   */
411  protected function ajax_amd_admin_installChooseInterface($interfaceMode)
412  {
413    switch($interfaceMode)
414    {
415      case 'basic':
416        $this->config['amd_FillDataBaseContinuously']='n';
417        $this->initializeDatabaseForBasicInterface();
418        break;
419      case 'advanced':
420        $this->initializeDatabaseForAdvancedInterface();
421        break;
422    }
423
424    $this->config['newInstall']='n';
425    $this->config['amd_InterfaceMode']=$interfaceMode;
426    $this->saveConfig();
427
428    return('ok');
429  }
430
431} //class
432
433
434?>
Note: See TracBrowser for help on using the repository browser.