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

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

feature:2637- compatibility with Piwigo 2.4

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