[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 | { |
---|
[16007] | 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 | |
---|
[15343] | 69 | $sql="SELECT ti.path, tai.analyzed 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 | { |
---|
[5959] | 75 | while($row=pwg_db_fetch_assoc($result)) |
---|
[4905] | 76 | { |
---|
| 77 | $filename=$row['path']; |
---|
[6722] | 78 | $this->pictureProperties['analyzed']=$row['analyzed']; |
---|
[4905] | 79 | } |
---|
| 80 | $filename=$path."/".$filename; |
---|
| 81 | } |
---|
| 82 | |
---|
[6920] | 83 | |
---|
| 84 | |
---|
[5183] | 85 | $this->jpegMD->load( |
---|
[4905] | 86 | $filename, |
---|
| 87 | Array( |
---|
[5790] | 88 | 'filter' => AMD_JpegMetaData::TAGFILTER_IMPLEMENTED, |
---|
[4905] | 89 | 'optimizeIptcDateTime' => true, |
---|
| 90 | 'exif' => true, |
---|
| 91 | 'iptc' => true, |
---|
[5790] | 92 | 'xmp' => true, |
---|
| 93 | 'magic' => true, |
---|
[4905] | 94 | ) |
---|
| 95 | ); |
---|
| 96 | |
---|
[6891] | 97 | trigger_action('amd_jpegMD_loaded', $this->jpegMD); |
---|
| 98 | |
---|
[4905] | 99 | $conf['show_exif']=false; |
---|
| 100 | $conf['show_iptc']=false; |
---|
| 101 | |
---|
[6722] | 102 | $picturesTags=$this->jpegMD->getTags(); |
---|
[4905] | 103 | $tagsList=Array(); |
---|
[6722] | 104 | $userDefinedList=array( |
---|
| 105 | 'list' => array(), |
---|
| 106 | 'values' => array(), |
---|
| 107 | ); |
---|
[12226] | 108 | $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] | 109 | FROM ((".$this->tables['selected_tags']." st |
---|
[4909] | 110 | LEFT JOIN ".$this->tables['groups']." gr |
---|
[4905] | 111 | ON gr.groupId = st.groupId) |
---|
[4909] | 112 | LEFT JOIN ".$this->tables['groups_names']." gn |
---|
[6722] | 113 | ON st.groupId = gn.groupId) |
---|
| 114 | LEFT JOIN ".$this->tables['used_tags']." ut |
---|
| 115 | ON ut.tagId = st.tagId |
---|
[4905] | 116 | WHERE gn.lang='".$user['language']."' |
---|
[12224] | 117 | AND st.groupId <> -1) |
---|
[7700] | 118 | |
---|
| 119 | UNION |
---|
| 120 | |
---|
[12226] | 121 | (SELECT DISTINCT ut3.tagId, '', pautd.value, '', 'n', -1, -1, -1 |
---|
[7700] | 122 | FROM ((".$this->tables['selected_tags']." st2 |
---|
| 123 | LEFT JOIN ".$this->tables['used_tags']." ut2 ON ut2.tagId = st2.tagId) |
---|
| 124 | LEFT JOIN ".$this->tables['user_tags_def']." pautd ON pautd.numId=ut2.numId) |
---|
| 125 | LEFT JOIN ".$this->tables['used_tags']." ut3 ON ut3.numId = pautd.value |
---|
| 126 | WHERE st2.tagId LIKE 'userDefined.%' |
---|
[12224] | 127 | AND pautd.type = 'M') |
---|
[7700] | 128 | |
---|
[12224] | 129 | ORDER BY gOrder, tOrder;"; |
---|
| 130 | |
---|
[4905] | 131 | $result=pwg_query($sql); |
---|
| 132 | if($result) |
---|
| 133 | { |
---|
[12226] | 134 | $numMD=0; |
---|
| 135 | |
---|
[5959] | 136 | while($row=pwg_db_fetch_assoc($result)) |
---|
[4905] | 137 | { |
---|
[12226] | 138 | if(trim($row['gName'])=='') |
---|
| 139 | { |
---|
| 140 | $sql2="SELECT gn0.name |
---|
| 141 | FROM ".$this->tables['groups_names']." gn0 |
---|
| 142 | WHERE gn0.lang='en_UK' AND gn0.name <> '' AND groupId=".$row['groupId']." |
---|
| 143 | |
---|
| 144 | UNION |
---|
| 145 | |
---|
| 146 | SELECT gn0.name |
---|
| 147 | FROM ".$this->tables['groups_names']." gn0 |
---|
| 148 | WHERE gn0.lang<>'".$user['language']."' AND gn0.name <> '' AND groupId=".$row['groupId']." |
---|
| 149 | |
---|
| 150 | LIMIT 0,1;"; |
---|
| 151 | $result2=pwg_query($sql2); |
---|
| 152 | if($result2) |
---|
| 153 | { |
---|
| 154 | $row2=pwg_db_fetch_assoc($result2); |
---|
| 155 | if($row2['name']!='') $row['gName']=$row2['name']; |
---|
| 156 | } |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | if($row['gName']=='') |
---|
| 160 | { |
---|
| 161 | $row['gName']='Metadatas #'.$numMD; |
---|
| 162 | $numMD++; |
---|
| 163 | } |
---|
| 164 | |
---|
[6722] | 165 | $tagsList[$row['tagId']]=$row; |
---|
| 166 | if(preg_match('/^userDefined\./i', $row['tagId'])) |
---|
| 167 | { |
---|
| 168 | $userDefinedList['list'][]=$row['numId']; |
---|
| 169 | } |
---|
| 170 | else |
---|
| 171 | { |
---|
| 172 | if(array_key_exists($row['tagId'], $picturesTags)) |
---|
| 173 | { |
---|
| 174 | $value=$picturesTags[$row['tagId']]->getLabel(); |
---|
| 175 | |
---|
| 176 | if($value instanceof DateTime) |
---|
| 177 | { |
---|
| 178 | $value=$value->format("Y-m-d H:i:s"); |
---|
| 179 | } |
---|
| 180 | elseif(is_array($value)) |
---|
| 181 | { |
---|
| 182 | /* |
---|
| 183 | * array values are stored in a serialized string |
---|
| 184 | */ |
---|
| 185 | $value=serialize($value); |
---|
| 186 | } |
---|
[6891] | 187 | $userDefinedList['values'][$row['numId']]=AMD_root::prepareValueForDisplay($value, $picturesTags[$row['tagId']]->isTranslatable());; |
---|
[6722] | 188 | } |
---|
| 189 | } |
---|
[4905] | 190 | } |
---|
| 191 | } |
---|
| 192 | |
---|
[6891] | 193 | $metadata=$template->get_template_vars('metadata'); |
---|
[4905] | 194 | $md=null; |
---|
| 195 | $group=null; |
---|
| 196 | |
---|
[6722] | 197 | $userDefinedValues=$this->pictureGetUserDefinedTags($userDefinedList['list'], $userDefinedList['values']); |
---|
[4905] | 198 | |
---|
[6891] | 199 | trigger_action('amd_jpegMD_userDefinedValues_built', |
---|
| 200 | array( |
---|
| 201 | 'picture' => $userDefinedList['values'], |
---|
| 202 | 'user' => $userDefinedValues, |
---|
| 203 | ) |
---|
| 204 | ); |
---|
| 205 | |
---|
[6722] | 206 | foreach($tagsList as $key => $tagProperties) |
---|
[4905] | 207 | { |
---|
[7700] | 208 | $keyExist=array_key_exists($key, $picturesTags) & ($tagProperties['displayStatus']=='y'); |
---|
[6722] | 209 | $userDefined=preg_match('/^userDefined\./i', $key); |
---|
| 210 | |
---|
[16007] | 211 | if(($group!='AMD'.$tagProperties['groupId']) and |
---|
[6722] | 212 | ( $keyExist or $userDefined) ) |
---|
[4905] | 213 | { |
---|
[16007] | 214 | $group='AMD'.$tagProperties['groupId']; |
---|
[15343] | 215 | if(!isset($metadata[$group])) |
---|
[6722] | 216 | { |
---|
[15343] | 217 | $metadata[$group]=Array( |
---|
| 218 | 'TITLE' => $tagProperties['gName'], |
---|
| 219 | 'lines' => Array() |
---|
| 220 | ); |
---|
[6722] | 221 | } |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | if($keyExist) |
---|
| 225 | { |
---|
[4905] | 226 | $value=$picturesTags[$key]->getLabel(); |
---|
| 227 | |
---|
| 228 | if($value instanceof DateTime) |
---|
| 229 | { |
---|
| 230 | $value=$value->format("Y-m-d H:i:s"); |
---|
| 231 | } |
---|
| 232 | elseif(is_array($value)) |
---|
| 233 | { |
---|
| 234 | /* |
---|
| 235 | * array values are stored in a serialized string |
---|
| 236 | */ |
---|
| 237 | $value=serialize($value); |
---|
| 238 | } |
---|
[6891] | 239 | |
---|
| 240 | if($value!="") |
---|
| 241 | { |
---|
[15343] | 242 | $metadata[$group]['lines'][L10n::get($picturesTags[$key]->getName())]=AMD_root::prepareValueForDisplay($value, $picturesTags[$key]->isTranslatable()); |
---|
[6891] | 243 | } |
---|
[4905] | 244 | } |
---|
[6891] | 245 | elseif($userDefined and isset($userDefinedValues[$tagProperties['numId']]) and $userDefinedValues[$tagProperties['numId']]!='') |
---|
[6722] | 246 | { |
---|
[15343] | 247 | $metadata[$group]['lines'][$tagProperties['name']]=$userDefinedValues[$tagProperties['numId']]; |
---|
[6722] | 248 | } |
---|
[4905] | 249 | } |
---|
| 250 | |
---|
[6722] | 251 | $template->assign('metadata', $metadata); |
---|
| 252 | } |
---|
[4905] | 253 | |
---|
[6722] | 254 | /** |
---|
| 255 | * used by the 'loc_end_page_tail' event |
---|
| 256 | * |
---|
| 257 | * on each public page viewed, add a script to do an ajax call to the "public.makeStats.doPictureAnalyze" function |
---|
| 258 | */ |
---|
| 259 | public function applyJS() |
---|
| 260 | { |
---|
| 261 | global $template; |
---|
| 262 | |
---|
| 263 | if($this->config['amd_FillDataBaseContinuously']=='y' and |
---|
[5935] | 264 | $this->config['amd_AllPicturesAreAnalyzed']=='n') |
---|
[5183] | 265 | { |
---|
[6722] | 266 | $template->set_filename('applyJS', |
---|
| 267 | dirname($this->getFileLocation()).'/templates/doAnalyze.tpl'); |
---|
| 268 | |
---|
| 269 | $datas=array( |
---|
| 270 | 'urlRequest' => $this->getAdminLink('ajax'), |
---|
| 271 | 'id' => ($this->pictureProperties['analyzed']=='n')?$this->pictureProperties['id']:'0' |
---|
| 272 | ); |
---|
| 273 | |
---|
[16007] | 274 | GPCCore::setTemplateToken(); |
---|
[6722] | 275 | $template->assign('datas', $datas); |
---|
| 276 | $template->append('footer_elements', $template->parse('applyJS', true)); |
---|
[5183] | 277 | } |
---|
[4905] | 278 | } |
---|
| 279 | |
---|
| 280 | } // AMD_PIP class |
---|
| 281 | |
---|
| 282 | |
---|
| 283 | ?> |
---|