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

Last change on this file since 4909 was 4909, checked in by plg, 14 years ago

bug fixed: use variables for table names

  • Property svn:executable set to *
File size: 4.0 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
67    $sql="SELECT path FROM ".IMAGES_TABLE." WHERE id=".$page['image_id'].";";
68    $result=pwg_query($sql);
69    if($result)
70    {
71      while($row=mysql_fetch_assoc($result))
72      {
73        $filename=$row['path'];
74      }
75      $filename=$path."/".$filename;
76    }
77
78    $JpegMD = new JpegMetaData(
79      $filename,
80      Array(
81        'filter' => JpegMetaData::TAGFILTER_IMPLEMENTED,
82        'optimizeIptcDateTime' => true,
83        'exif' => true,
84        'iptc' => true,
85        'xmp' => true
86      )
87    );
88
89    $conf['show_exif']=false;
90    $conf['show_iptc']=false;
91
92    $tagsList=Array();
93    $sql="SELECT st.tagId, gn.name as gName
94          FROM (".$this->tables['selected_tags']." st
95            LEFT JOIN ".$this->tables['groups']." gr
96              ON gr.groupId = st.groupId)
97            LEFT JOIN ".$this->tables['groups_names']." gn
98              ON st.groupId = gn.groupId
99          WHERE gn.lang='".$user['language']."'
100            AND st.groupId <> -1
101          ORDER BY gr.order, st.order;";
102    $result=pwg_query($sql);
103    if($result)
104    {
105      while($row=mysql_fetch_assoc($result))
106      {
107        $tagsList[$row['tagId']]=$row['gName'];
108      }
109    }
110
111    $metadata=Array();
112    $md=null;
113    $group=null;
114
115    $picturesTags=$JpegMD->getTags();
116
117    foreach($tagsList as $key => $val)
118    {
119      if(array_key_exists($key, $picturesTags))
120      {
121        $value=$picturesTags[$key]->getLabel();
122
123        if($picturesTags[$key]->isTranslatable())
124          $translatable="y";
125        else
126          $translatable="n";
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())]=$value;
154      }
155    }
156
157    if(!is_null($md))
158    {
159      $metadata[]=$md;
160    }
161
162    unset($JpegMD);
163
164    $template->assign('metadata', $metadata);
165  }
166
167} // AMD_PIP class
168
169
170?>
Note: See TracBrowser for help on using the repository browser.