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

Revision 5959, 4.7 KB checked in by grum, 10 years ago (diff)

Some changes on release 0.4b

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