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

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

database is partially filled during the install process, and fill database picture per picture each time a page is displayed (and until all the database is filled)

  • Property svn:executable set to *
File size: 4.8 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($picturesTags[$key]->isTranslatable())
128          $translatable="y";
129        else
130          $translatable="n";
131
132        if($value instanceof DateTime)
133        {
134          $value=$value->format("Y-m-d H:i:s");
135        }
136        elseif(is_array($value))
137        {
138          /*
139           * array values are stored in a serialized string
140           */
141          $value=serialize($value);
142        }
143
144        if($group!=$val)
145        {
146          $group=$val;
147          if(!is_null($md))
148          {
149            $metadata[]=$md;
150            unset($md);
151          }
152          $md=Array(
153            'TITLE' => $val,
154            'lines' => Array()
155          );
156        }
157        $md['lines'][L10n::get($picturesTags[$key]->getName())]=$value;
158      }
159    }
160
161    if(!is_null($md))
162    {
163      $metadata[]=$md;
164    }
165
166
167    if($analyzed=='n' and
168       $this->my_config['amd_FillDataBaseContinuously']=='y' and
169       $this->my_config['amd_AllPicturesAreAnalyzed']=='n')
170    {
171      /* if picture is not analyzed, do analyze
172       *
173       * note : the $loaded parameter is set to true, in this case the function
174       *        analyzeImageFile uses data from the $this->jpegMD object which
175       *        have data already loaded => the picture is not analyzed twice,
176       *        the function only do the database update
177       */
178      $this->analyzeImageFile($filename, $page['image_id'], true);
179      $this->makeStatsConsolidation();
180    }
181
182    $template->assign('metadata', $metadata);
183  }
184
185} // AMD_PIP class
186
187
188?>
Note: See TracBrowser for help on using the repository browser.