[4905] | 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 | |
---|
| 21 | if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); } |
---|
| 22 | |
---|
| 23 | include_once('amd_root.class.inc.php'); |
---|
| 24 | |
---|
| 25 | class AMD_PIP extends AMD_root |
---|
| 26 | { |
---|
[6722] | 27 | private $pictureProperties=array( |
---|
| 28 | 'id' => 0, |
---|
| 29 | 'analyzed' => 'n' |
---|
| 30 | ); |
---|
[4905] | 31 | function AMD_PIP($prefixeTable, $filelocation) |
---|
| 32 | { |
---|
| 33 | parent::__construct($prefixeTable, $filelocation); |
---|
| 34 | |
---|
[5935] | 35 | $this->loadConfig(); |
---|
| 36 | $this->initEvents(); |
---|
[4905] | 37 | } |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | /* --------------------------------------------------------------------------- |
---|
| 41 | Public classe functions |
---|
| 42 | --------------------------------------------------------------------------- */ |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | /* |
---|
| 46 | initialize events call for the plugin |
---|
| 47 | */ |
---|
[5935] | 48 | public function initEvents() |
---|
[4905] | 49 | { |
---|
[5935] | 50 | parent::initEvents(); |
---|
[4905] | 51 | add_event_handler('loc_begin_picture', array(&$this, 'loadMetadata')); |
---|
[6722] | 52 | add_event_handler('loc_end_page_tail', array(&$this, 'applyJS')); |
---|
[4905] | 53 | } |
---|
| 54 | |
---|
| 55 | /** |
---|
| 56 | * override piwigo's metadata with picture metadata |
---|
| 57 | * |
---|
| 58 | */ |
---|
| 59 | public function loadMetadata() |
---|
| 60 | { |
---|
| 61 | global $conf, $template, $page, $user; |
---|
| 62 | |
---|
| 63 | L10n::setLanguage($user['language']); |
---|
| 64 | |
---|
| 65 | $path=dirname(dirname(dirname(__FILE__))); |
---|
| 66 | $filename=""; |
---|
[6722] | 67 | $this->pictureProperties['id']=$page['image_id']; |
---|
[4905] | 68 | |
---|
[6920] | 69 | $sql="SELECT ti.path, tai.analyzed, ti.has_high FROM ".IMAGES_TABLE." ti |
---|
[5183] | 70 | LEFT JOIN ".$this->tables['images']." tai ON tai.imageId = ti.id |
---|
| 71 | WHERE ti.id=".$page['image_id'].";"; |
---|
[4905] | 72 | $result=pwg_query($sql); |
---|
| 73 | if($result) |
---|
| 74 | { |
---|
[6920] | 75 | $hasHigh=''; |
---|
[5959] | 76 | while($row=pwg_db_fetch_assoc($result)) |
---|
[4905] | 77 | { |
---|
| 78 | $filename=$row['path']; |
---|
[6920] | 79 | $hasHigh=$row['has_high']; |
---|
[6722] | 80 | $this->pictureProperties['analyzed']=$row['analyzed']; |
---|
[4905] | 81 | } |
---|
| 82 | $filename=$path."/".$filename; |
---|
[6920] | 83 | |
---|
| 84 | if($hasHigh==='true' and $this->config['amd_UseMetaFromHD']=='y') |
---|
| 85 | { |
---|
| 86 | $filename=dirname($filename)."/pwg_high/".basename($filename); |
---|
| 87 | } |
---|
[4905] | 88 | } |
---|
| 89 | |
---|
[6920] | 90 | |
---|
| 91 | |
---|
[5183] | 92 | $this->jpegMD->load( |
---|
[4905] | 93 | $filename, |
---|
| 94 | Array( |
---|
[5790] | 95 | 'filter' => AMD_JpegMetaData::TAGFILTER_IMPLEMENTED, |
---|
[4905] | 96 | 'optimizeIptcDateTime' => true, |
---|
| 97 | 'exif' => true, |
---|
| 98 | 'iptc' => true, |
---|
[5790] | 99 | 'xmp' => true, |
---|
| 100 | 'magic' => true, |
---|
[4905] | 101 | ) |
---|
| 102 | ); |
---|
| 103 | |
---|
[6891] | 104 | trigger_action('amd_jpegMD_loaded', $this->jpegMD); |
---|
| 105 | |
---|
[4905] | 106 | $conf['show_exif']=false; |
---|
| 107 | $conf['show_iptc']=false; |
---|
| 108 | |
---|
[6722] | 109 | $picturesTags=$this->jpegMD->getTags(); |
---|
[4905] | 110 | $tagsList=Array(); |
---|
[6722] | 111 | $userDefinedList=array( |
---|
| 112 | 'list' => array(), |
---|
| 113 | 'values' => array(), |
---|
| 114 | ); |
---|
[12226] | 115 | $sql="(SELECT st.tagId, gn.name as gName, ut.numId, ut.name, 'y' AS displayStatus, st.order AS tOrder, gr.order as gOrder, gr.groupId |
---|
[6722] | 116 | FROM ((".$this->tables['selected_tags']." st |
---|
[4909] | 117 | LEFT JOIN ".$this->tables['groups']." gr |
---|
[4905] | 118 | ON gr.groupId = st.groupId) |
---|
[4909] | 119 | LEFT JOIN ".$this->tables['groups_names']." gn |
---|
[6722] | 120 | ON st.groupId = gn.groupId) |
---|
| 121 | LEFT JOIN ".$this->tables['used_tags']." ut |
---|
| 122 | ON ut.tagId = st.tagId |
---|
[4905] | 123 | WHERE gn.lang='".$user['language']."' |
---|
[12224] | 124 | AND st.groupId <> -1) |
---|
[7700] | 125 | |
---|
| 126 | UNION |
---|
| 127 | |
---|
[12226] | 128 | (SELECT DISTINCT ut3.tagId, '', pautd.value, '', 'n', -1, -1, -1 |
---|
[7700] | 129 | FROM ((".$this->tables['selected_tags']." st2 |
---|
| 130 | LEFT JOIN ".$this->tables['used_tags']." ut2 ON ut2.tagId = st2.tagId) |
---|
| 131 | LEFT JOIN ".$this->tables['user_tags_def']." pautd ON pautd.numId=ut2.numId) |
---|
| 132 | LEFT JOIN ".$this->tables['used_tags']." ut3 ON ut3.numId = pautd.value |
---|
| 133 | WHERE st2.tagId LIKE 'userDefined.%' |
---|
[12224] | 134 | AND pautd.type = 'M') |
---|
[7700] | 135 | |
---|
[12224] | 136 | ORDER BY gOrder, tOrder;"; |
---|
| 137 | |
---|
[4905] | 138 | $result=pwg_query($sql); |
---|
| 139 | if($result) |
---|
| 140 | { |
---|
[12226] | 141 | $numMD=0; |
---|
| 142 | |
---|
[5959] | 143 | while($row=pwg_db_fetch_assoc($result)) |
---|
[4905] | 144 | { |
---|
[12226] | 145 | if(trim($row['gName'])=='') |
---|
| 146 | { |
---|
| 147 | $sql2="SELECT gn0.name |
---|
| 148 | FROM ".$this->tables['groups_names']." gn0 |
---|
| 149 | WHERE gn0.lang='en_UK' AND gn0.name <> '' AND groupId=".$row['groupId']." |
---|
| 150 | |
---|
| 151 | UNION |
---|
| 152 | |
---|
| 153 | SELECT gn0.name |
---|
| 154 | FROM ".$this->tables['groups_names']." gn0 |
---|
| 155 | WHERE gn0.lang<>'".$user['language']."' AND gn0.name <> '' AND groupId=".$row['groupId']." |
---|
| 156 | |
---|
| 157 | LIMIT 0,1;"; |
---|
| 158 | $result2=pwg_query($sql2); |
---|
| 159 | if($result2) |
---|
| 160 | { |
---|
| 161 | $row2=pwg_db_fetch_assoc($result2); |
---|
| 162 | if($row2['name']!='') $row['gName']=$row2['name']; |
---|
| 163 | } |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | if($row['gName']=='') |
---|
| 167 | { |
---|
| 168 | $row['gName']='Metadatas #'.$numMD; |
---|
| 169 | $numMD++; |
---|
| 170 | } |
---|
| 171 | |
---|
[6722] | 172 | $tagsList[$row['tagId']]=$row; |
---|
| 173 | if(preg_match('/^userDefined\./i', $row['tagId'])) |
---|
| 174 | { |
---|
| 175 | $userDefinedList['list'][]=$row['numId']; |
---|
| 176 | } |
---|
| 177 | else |
---|
| 178 | { |
---|
| 179 | if(array_key_exists($row['tagId'], $picturesTags)) |
---|
| 180 | { |
---|
| 181 | $value=$picturesTags[$row['tagId']]->getLabel(); |
---|
| 182 | |
---|
| 183 | if($value instanceof DateTime) |
---|
| 184 | { |
---|
| 185 | $value=$value->format("Y-m-d H:i:s"); |
---|
| 186 | } |
---|
| 187 | elseif(is_array($value)) |
---|
| 188 | { |
---|
| 189 | /* |
---|
| 190 | * array values are stored in a serialized string |
---|
| 191 | */ |
---|
| 192 | $value=serialize($value); |
---|
| 193 | } |
---|
[6891] | 194 | $userDefinedList['values'][$row['numId']]=AMD_root::prepareValueForDisplay($value, $picturesTags[$row['tagId']]->isTranslatable());; |
---|
[6722] | 195 | } |
---|
| 196 | } |
---|
[4905] | 197 | } |
---|
| 198 | } |
---|
| 199 | |
---|
[6891] | 200 | $metadata=$template->get_template_vars('metadata'); |
---|
[4905] | 201 | $md=null; |
---|
| 202 | $group=null; |
---|
| 203 | |
---|
[6722] | 204 | $userDefinedValues=$this->pictureGetUserDefinedTags($userDefinedList['list'], $userDefinedList['values']); |
---|
[4905] | 205 | |
---|
[6891] | 206 | trigger_action('amd_jpegMD_userDefinedValues_built', |
---|
| 207 | array( |
---|
| 208 | 'picture' => $userDefinedList['values'], |
---|
| 209 | 'user' => $userDefinedValues, |
---|
| 210 | ) |
---|
| 211 | ); |
---|
| 212 | |
---|
[6722] | 213 | foreach($tagsList as $key => $tagProperties) |
---|
[4905] | 214 | { |
---|
[7700] | 215 | $keyExist=array_key_exists($key, $picturesTags) & ($tagProperties['displayStatus']=='y'); |
---|
[6722] | 216 | $userDefined=preg_match('/^userDefined\./i', $key); |
---|
| 217 | |
---|
| 218 | if(($group!=$tagProperties['gName']) and |
---|
| 219 | ( $keyExist or $userDefined) ) |
---|
[4905] | 220 | { |
---|
[6722] | 221 | $group=$tagProperties['gName']; |
---|
| 222 | if(!is_null($md)) |
---|
| 223 | { |
---|
| 224 | $metadata[]=$md; |
---|
| 225 | unset($md); |
---|
| 226 | } |
---|
| 227 | $md=Array( |
---|
| 228 | 'TITLE' => $tagProperties['gName'], |
---|
| 229 | 'lines' => Array() |
---|
| 230 | ); |
---|
| 231 | } |
---|
| 232 | |
---|
| 233 | if($keyExist) |
---|
| 234 | { |
---|
[4905] | 235 | $value=$picturesTags[$key]->getLabel(); |
---|
| 236 | |
---|
| 237 | if($value instanceof DateTime) |
---|
| 238 | { |
---|
| 239 | $value=$value->format("Y-m-d H:i:s"); |
---|
| 240 | } |
---|
| 241 | elseif(is_array($value)) |
---|
| 242 | { |
---|
| 243 | /* |
---|
| 244 | * array values are stored in a serialized string |
---|
| 245 | */ |
---|
| 246 | $value=serialize($value); |
---|
| 247 | } |
---|
[6891] | 248 | |
---|
| 249 | if($value!="") |
---|
| 250 | { |
---|
| 251 | $md['lines'][L10n::get($picturesTags[$key]->getName())]=AMD_root::prepareValueForDisplay($value, $picturesTags[$key]->isTranslatable()); |
---|
| 252 | } |
---|
[4905] | 253 | } |
---|
[6891] | 254 | elseif($userDefined and isset($userDefinedValues[$tagProperties['numId']]) and $userDefinedValues[$tagProperties['numId']]!='') |
---|
[6722] | 255 | { |
---|
| 256 | $md['lines'][$tagProperties['name']]=$userDefinedValues[$tagProperties['numId']]; |
---|
| 257 | } |
---|
[4905] | 258 | } |
---|
| 259 | |
---|
[6891] | 260 | if(!is_null($md) and count($md['lines'])>0) |
---|
[4905] | 261 | { |
---|
| 262 | $metadata[]=$md; |
---|
| 263 | } |
---|
| 264 | |
---|
[6722] | 265 | $template->assign('metadata', $metadata); |
---|
| 266 | } |
---|
[4905] | 267 | |
---|
[6722] | 268 | /** |
---|
| 269 | * used by the 'loc_end_page_tail' event |
---|
| 270 | * |
---|
| 271 | * on each public page viewed, add a script to do an ajax call to the "public.makeStats.doPictureAnalyze" function |
---|
| 272 | */ |
---|
| 273 | public function applyJS() |
---|
| 274 | { |
---|
| 275 | global $template; |
---|
| 276 | |
---|
| 277 | if($this->config['amd_FillDataBaseContinuously']=='y' and |
---|
[5935] | 278 | $this->config['amd_AllPicturesAreAnalyzed']=='n') |
---|
[5183] | 279 | { |
---|
[6722] | 280 | $template->set_filename('applyJS', |
---|
| 281 | dirname($this->getFileLocation()).'/templates/doAnalyze.tpl'); |
---|
| 282 | |
---|
| 283 | $datas=array( |
---|
| 284 | 'urlRequest' => $this->getAdminLink('ajax'), |
---|
| 285 | 'id' => ($this->pictureProperties['analyzed']=='n')?$this->pictureProperties['id']:'0' |
---|
| 286 | ); |
---|
| 287 | |
---|
| 288 | $template->assign('datas', $datas); |
---|
| 289 | $template->append('footer_elements', $template->parse('applyJS', true)); |
---|
[5183] | 290 | } |
---|
[4905] | 291 | } |
---|
| 292 | |
---|
| 293 | } // AMD_PIP class |
---|
| 294 | |
---|
| 295 | |
---|
| 296 | ?> |
---|