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

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

Implement basic/advanced modes, release 0.5.1
bug:1857

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()."&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.Sublocation',
233      'iptc.Supplemental Category',
234      'iptc.Time Created',
235      'iptc.Time Sent',
236      'iptc.Urgency',
237      'iptc.Writer/Editor',
238      'xmp.Iptc4xmpCore:CiAdrCity',
239      'xmp.Iptc4xmpCore:CiAdrCtry',
240      'xmp.Iptc4xmpCore:CiAdrExtadr',
241      'xmp.Iptc4xmpCore:CiAdrPcode',
242      'xmp.Iptc4xmpCore:CiEmailWork',
243      'xmp.Iptc4xmpCore:CiTelWork',
244      'xmp.Iptc4xmpCore:CiUrlWork',
245      'xmp.Iptc4xmpCore:CountryCode',
246      'xmp.Iptc4xmpCore:IntellectualGenre',
247      'xmp.Iptc4xmpCore:Location',
248      'xmp.Iptc4xmpCore:Scene',
249      'xmp.aux:Firmware',
250      'xmp.aux:Lens',
251      'xmp.crs:Balance',
252      'xmp.crs:CameraProfile',
253      'xmp.crs:ColorNoiseReduction',
254      'xmp.crs:Exposure',
255      'xmp.crs:HasCrop',
256      'xmp.crs:HasSettings',
257      'xmp.crs:RawFileName',
258      'xmp.crs:WhiteBalance',
259      'xmp.dc:CreatorTool',
260      'xmp.dc:Type',
261      'xmp.dc:contributor',
262      'xmp.dc:coverage',
263      'xmp.dc:creator',
264      'xmp.dc:description',
265      'xmp.dc:format',
266      'xmp.dc:identifier',
267      'xmp.dc:language',
268      'xmp.dc:publisher',
269      'xmp.dc:relation',
270      'xmp.dc:rights',
271      'xmp.dc:source',
272      'xmp.dc:subject',
273      'xmp.dc:title',
274      'xmp.photoshop:AuthorsPosition',
275      'xmp.photoshop:CaptionWriter',
276      'xmp.photoshop:Category',
277      'xmp.photoshop:City',
278      'xmp.photoshop:Country',
279      'xmp.photoshop:Credit',
280      'xmp.photoshop:DateCreated',
281      'xmp.photoshop:Headline',
282      'xmp.photoshop:ICCProfile',
283      'xmp.photoshop:Instructions',
284      'xmp.photoshop:Source',
285      'xmp.photoshop:State',
286      'xmp.photoshop:SupplementalCategories',
287      'xmp.photoshop:TransmissionReference',
288      'xmp.photoshop:Urgency',
289      'xmp.tiff:Artist',
290      'xmp.tiff:Copyright',
291      'xmp.tiff:DateTime',
292      'xmp.tiff:ImageDescription',
293      'xmp.tiff:Software',
294      'xmp.xmp:Advisory',
295      'xmp.xmp:BaseURL',
296      'xmp.xmp:CreateDate',
297      'xmp.xmp:CreatorTool',
298      'xmp.xmp:Identifier',
299      'xmp.xmp:Label',
300      'xmp.xmp:MetadataDate',
301      'xmp.xmp:ModifyDate',
302      'xmp.xmp:Nickname',
303      'xmp.xmp:Rating',
304      'xmp.xmpRights:Certificate',
305      'xmp.xmpRights:Marked',
306      'xmp.xmpRights:Owner',
307      'xmp.xmpRights:UsageTerms',
308      'xmp.xmpRights:WebStatement'
309    );
310
311    $sql="";
312    foreach($basicMeta as $key=>$val)
313    {
314      $basicMeta[$key]="('$val', 0, -1)";
315    }
316    $sql="INSERT INTO `".$this->tables['selected_tags']."` VALUES ".implode(',', $basicMeta);
317    pwg_query($sql);
318  }
319
320  /**
321   * prepare the tables for the advanced interface mode
322   */
323  protected function initializeDatabaseForAdvancedInterface()
324  {
325    global $user;
326
327    $listToAnalyze=Array(Array(), Array());
328    /*
329     * select 25 pictures into the caddie
330     */
331    $sql="SELECT ti.id, ti.path, ti.has_high
332          FROM ".CADDIE_TABLE." tc
333            LEFT JOIN ".IMAGES_TABLE." ti ON ti.id = tc.element_id
334          WHERE tc.user_id = ".$user['id']."
335            AND ti.id IS NOT NULL
336          ORDER BY RAND() LIMIT 25;";
337    $result=pwg_query($sql);
338    if($result)
339    {
340      while($row=pwg_db_fetch_assoc($result))
341      {
342        $listToAnalyze[0][]=$row;
343        $listToAnalyze[1][]=$row['id'];
344      }
345    }
346    /*
347     * if caddie is empty, of is have less than 25 pictures, select other
348     * pictures from the gallery
349     */
350    if(count($listToAnalyze[0])<25)
351    {
352      if(count($listToAnalyze[0])>0)
353      {
354        $excludeList="WHERE ti.id NOT IN(".implode(",", $listToAnalyze[1]).") ";
355      }
356      else
357      {
358        $excludeList="";
359      }
360      $sql="SELECT ti.id, ti.path, ti.has_high
361            FROM ".IMAGES_TABLE." ti ".$excludeList."
362            ORDER BY RAND() LIMIT ".(25-count($listToAnalyze[0])).";";
363      $result=pwg_query($sql);
364      if($result)
365      {
366        while($row=pwg_db_fetch_assoc($result))
367        {
368          $listToAnalyze[0][]=$row;
369        }
370      }
371    }
372
373    /*
374     * analyze the 25 selected pictures
375     */
376    if(count($listToAnalyze[0])>0)
377    {
378      // $path = path of piwigo's on the server filesystem
379      $path=dirname(dirname(dirname(__FILE__)));
380
381      foreach($listToAnalyze[0] as $val)
382      {
383        if($val['has_high']===true and $this->config['amd_UseMetaFromHD']=='y')
384        {
385          $this->analyzeImageFile($path."/".dirname($val['path'])."/pwg_high/".basename($val['path']), $val['id']);
386        }
387        else
388        {
389          $this->analyzeImageFile($path."/".$val['path'], $val['id']);
390        }
391      }
392      $this->makeStatsConsolidation();
393    }
394  }
395
396
397
398  /*
399   *  ---------------------------------------------------------------------------
400   * AJAX FUNCTIONS
401   * ---------------------------------------------------------------------------
402   */
403
404  /**
405   * set choice for plugin interface mode (basic/advanced)
406   * @param String $interfaceMode : mode for the interface 'basic' or 'advanced'
407   * @return String : ok or ko
408   */
409  protected function ajax_amd_admin_installChooseInterface($interfaceMode)
410  {
411    switch($interfaceMode)
412    {
413      case 'basic':
414        $this->config['amd_FillDataBaseContinuously']='n';
415        $this->initializeDatabaseForBasicInterface();
416        break;
417      case 'advanced':
418        $this->initializeDatabaseForAdvancedInterface();
419        break;
420    }
421
422    $this->config['newInstall']='n';
423    $this->config['amd_interfaceMode']=$interfaceMode;
424    $this->saveConfig();
425
426    return('ok');
427  }
428
429} //class
430
431
432?>
Note: See TracBrowser for help on using the repository browser.