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

Last change on this file since 5232 was 5226, checked in by grum, 15 years ago

Fix some bug, enhance some functionnalities, and make plugin ready to be translated

  • 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' => JpegMetaData::TAGFILTER_IMPLEMENTED,
86        'optimizeIptcDateTime' => true,
87        'exif' => true,
88        'iptc' => true,
89        'xmp' => true
90      )
91    );
92
93    $conf['show_exif']=false;
94    $conf['show_iptc']=false;
95
96    $tagsList=Array();
97    $sql="SELECT st.tagId, gn.name as gName
98          FROM (".$this->tables['selected_tags']." st
99            LEFT JOIN ".$this->tables['groups']." gr
100              ON gr.groupId = st.groupId)
101            LEFT JOIN ".$this->tables['groups_names']." gn
102              ON st.groupId = gn.groupId
103          WHERE gn.lang='".$user['language']."'
104            AND st.groupId <> -1
105          ORDER BY gr.order, st.order;";
106    $result=pwg_query($sql);
107    if($result)
108    {
109      while($row=mysql_fetch_assoc($result))
110      {
111        $tagsList[$row['tagId']]=$row['gName'];
112      }
113    }
114
115    $metadata=Array();
116    $md=null;
117    $group=null;
118
119    $picturesTags=$this->jpegMD->getTags();
120
121    foreach($tagsList as $key => $val)
122    {
123      if(array_key_exists($key, $picturesTags))
124      {
125        $value=$picturesTags[$key]->getLabel();
126
127        if($value instanceof DateTime)
128        {
129          $value=$value->format("Y-m-d H:i:s");
130        }
131        elseif(is_array($value))
132        {
133          /*
134           * array values are stored in a serialized string
135           */
136          $value=serialize($value);
137        }
138
139        if($group!=$val)
140        {
141          $group=$val;
142          if(!is_null($md))
143          {
144            $metadata[]=$md;
145            unset($md);
146          }
147          $md=Array(
148            'TITLE' => $val,
149            'lines' => Array()
150          );
151        }
152        $md['lines'][L10n::get($picturesTags[$key]->getName())]=$this->prepareValueForDisplay($value, $picturesTags[$key]->isTranslatable());
153      }
154    }
155
156    if(!is_null($md))
157    {
158      $metadata[]=$md;
159    }
160
161
162    if($analyzed=='n' and
163       $this->my_config['amd_FillDataBaseContinuously']=='y' and
164       $this->my_config['amd_AllPicturesAreAnalyzed']=='n')
165    {
166      /* if picture is not analyzed, do analyze
167       *
168       * note : the $loaded parameter is set to true, in this case the function
169       *        analyzeImageFile uses data from the $this->jpegMD object which
170       *        have data already loaded => the picture is not analyzed twice,
171       *        the function only do the database update
172       */
173      $this->analyzeImageFile($filename, $page['image_id'], true);
174      $this->makeStatsConsolidation();
175    }
176
177    $template->assign('metadata', $metadata);
178  }
179
180} // AMD_PIP class
181
182
183?>
Note: See TracBrowser for help on using the repository browser.