source: extensions/AMetaData/amd_pip.class.inc.php @ 5790

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

Add some GPS functionnalities

  • Property svn:executable set to *
File size: 4.7 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 * PIP classe => manage integration in public interface
18 * -----------------------------------------------------------------------------
19*/
20
21if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); }
22
23include_once('amd_root.class.inc.php');
24include_once(PHPWG_PLUGINS_PATH.'grum_plugins_classes-2/ajax.class.inc.php');
25
26class AMD_PIP extends AMD_root
27{
28  protected $ajax;
29
30  function AMD_PIP($prefixeTable, $filelocation)
31  {
32    parent::__construct($prefixeTable, $filelocation);
33    $this->ajax = new Ajax();
34
35    $this->load_config();
36    $this->init_events();
37  }
38
39
40  /* ---------------------------------------------------------------------------
41  Public classe functions
42  --------------------------------------------------------------------------- */
43
44
45  /*
46    initialize events call for the plugin
47  */
48  public function init_events()
49  {
50    parent::init_events();
51    add_event_handler('loc_begin_picture', array(&$this, 'loadMetadata'));
52  }
53
54  /**
55   * override piwigo's metadata with picture metadata
56   *
57   */
58  public function loadMetadata()
59  {
60    global $conf, $template, $page, $user;
61
62    L10n::setLanguage($user['language']);
63
64    $path=dirname(dirname(dirname(__FILE__)));
65    $filename="";
66    $analyzed='n';
67
68    $sql="SELECT ti.path, tai.analyzed FROM ".IMAGES_TABLE." ti
69            LEFT JOIN ".$this->tables['images']." tai ON tai.imageId = ti.id
70          WHERE ti.id=".$page['image_id'].";";
71    $result=pwg_query($sql);
72    if($result)
73    {
74      while($row=mysql_fetch_assoc($result))
75      {
76        $filename=$row['path'];
77        $analyzed=$row['analyzed'];
78      }
79      $filename=$path."/".$filename;
80    }
81
82    $this->jpegMD->load(
83      $filename,
84      Array(
85        'filter' => AMD_JpegMetaData::TAGFILTER_IMPLEMENTED,
86        'optimizeIptcDateTime' => true,
87        'exif' => true,
88        'iptc' => true,
89        'xmp' => true,
90        'magic' => true,
91      )
92    );
93
94    $conf['show_exif']=false;
95    $conf['show_iptc']=false;
96
97    $tagsList=Array();
98    $sql="SELECT st.tagId, gn.name as gName
99          FROM (".$this->tables['selected_tags']." st
100            LEFT JOIN ".$this->tables['groups']." gr
101              ON gr.groupId = st.groupId)
102            LEFT JOIN ".$this->tables['groups_names']." gn
103              ON st.groupId = gn.groupId
104          WHERE gn.lang='".$user['language']."'
105            AND st.groupId <> -1
106          ORDER BY gr.order, st.order;";
107    $result=pwg_query($sql);
108    if($result)
109    {
110      while($row=mysql_fetch_assoc($result))
111      {
112        $tagsList[$row['tagId']]=$row['gName'];
113      }
114    }
115
116    $metadata=Array();
117    $md=null;
118    $group=null;
119
120    $picturesTags=$this->jpegMD->getTags();
121
122    foreach($tagsList as $key => $val)
123    {
124      if(array_key_exists($key, $picturesTags))
125      {
126        $value=$picturesTags[$key]->getLabel();
127
128        if($value instanceof DateTime)
129        {
130          $value=$value->format("Y-m-d H:i:s");
131        }
132        elseif(is_array($value))
133        {
134          /*
135           * array values are stored in a serialized string
136           */
137          $value=serialize($value);
138        }
139
140        if($group!=$val)
141        {
142          $group=$val;
143          if(!is_null($md))
144          {
145            $metadata[]=$md;
146            unset($md);
147          }
148          $md=Array(
149            'TITLE' => $val,
150            'lines' => Array()
151          );
152        }
153        $md['lines'][L10n::get($picturesTags[$key]->getName())]=$this->prepareValueForDisplay($value, $picturesTags[$key]->isTranslatable());
154      }
155    }
156
157    if(!is_null($md))
158    {
159      $metadata[]=$md;
160    }
161
162
163    if($analyzed=='n' and
164       $this->my_config['amd_FillDataBaseContinuously']=='y' and
165       $this->my_config['amd_AllPicturesAreAnalyzed']=='n')
166    {
167      /* if picture is not analyzed, do analyze
168       *
169       * note : the $loaded parameter is set to true, in this case the function
170       *        analyzeImageFile uses data from the $this->jpegMD object which
171       *        have data already loaded => the picture is not analyzed twice,
172       *        the function only do the database update
173       */
174      $this->analyzeImageFile($filename, $page['image_id'], true);
175      $this->makeStatsConsolidation();
176    }
177
178    $template->assign('metadata', $metadata);
179  }
180
181} // AMD_PIP class
182
183
184?>
Note: See TracBrowser for help on using the repository browser.