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

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

Fix many bugs
bug:1894, bug:1898, bug:1911, bug:1863, bug:1955, bug:1956, bug:1925

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