Changeset 6722 for extensions/AMetaData/amd_pip.class.inc.php
- Timestamp:
- Jul 28, 2010, 10:48:17 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/AMetaData/amd_pip.class.inc.php
r5959 r6722 22 22 23 23 include_once('amd_root.class.inc.php'); 24 include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCAjax.class.inc.php');25 24 26 25 class AMD_PIP extends AMD_root 27 26 { 27 private $pictureProperties=array( 28 'id' => 0, 29 'analyzed' => 'n' 30 ); 28 31 function AMD_PIP($prefixeTable, $filelocation) 29 32 { … … 47 50 parent::initEvents(); 48 51 add_event_handler('loc_begin_picture', array(&$this, 'loadMetadata')); 52 add_event_handler('loc_end_page_tail', array(&$this, 'applyJS')); 49 53 } 50 54 … … 61 65 $path=dirname(dirname(dirname(__FILE__))); 62 66 $filename=""; 63 $ analyzed='n';67 $this->pictureProperties['id']=$page['image_id']; 64 68 65 69 $sql="SELECT ti.path, tai.analyzed FROM ".IMAGES_TABLE." ti … … 72 76 { 73 77 $filename=$row['path']; 74 $ analyzed=$row['analyzed'];78 $this->pictureProperties['analyzed']=$row['analyzed']; 75 79 } 76 80 $filename=$path."/".$filename; … … 92 96 $conf['show_iptc']=false; 93 97 98 $picturesTags=$this->jpegMD->getTags(); 94 99 $tagsList=Array(); 95 $sql="SELECT st.tagId, gn.name as gName 96 FROM (".$this->tables['selected_tags']." st 100 $userDefinedList=array( 101 'list' => array(), 102 'values' => array(), 103 ); 104 $sql="SELECT st.tagId, gn.name as gName, ut.numId, ut.name 105 FROM ((".$this->tables['selected_tags']." st 97 106 LEFT JOIN ".$this->tables['groups']." gr 98 107 ON gr.groupId = st.groupId) 99 108 LEFT JOIN ".$this->tables['groups_names']." gn 100 ON st.groupId = gn.groupId 109 ON st.groupId = gn.groupId) 110 LEFT JOIN ".$this->tables['used_tags']." ut 111 ON ut.tagId = st.tagId 101 112 WHERE gn.lang='".$user['language']."' 102 113 AND st.groupId <> -1 … … 107 118 while($row=pwg_db_fetch_assoc($result)) 108 119 { 109 $tagsList[$row['tagId']]=$row['gName']; 120 $tagsList[$row['tagId']]=$row; 121 if(preg_match('/^userDefined\./i', $row['tagId'])) 122 { 123 $userDefinedList['list'][]=$row['numId']; 124 } 125 else 126 { 127 if(array_key_exists($row['tagId'], $picturesTags)) 128 { 129 $value=$picturesTags[$row['tagId']]->getLabel(); 130 131 if($value instanceof DateTime) 132 { 133 $value=$value->format("Y-m-d H:i:s"); 134 } 135 elseif(is_array($value)) 136 { 137 /* 138 * array values are stored in a serialized string 139 */ 140 $value=serialize($value); 141 } 142 $userDefinedList['values'][$row['numId']]=$this->prepareValueForDisplay($value, $picturesTags[$row['tagId']]->isTranslatable());; 143 } 144 } 110 145 } 111 146 } … … 115 150 $group=null; 116 151 117 $picturesTags=$this->jpegMD->getTags(); 118 119 foreach($tagsList as $key => $val) 120 { 121 if(array_key_exists($key, $picturesTags)) 152 $userDefinedValues=$this->pictureGetUserDefinedTags($userDefinedList['list'], $userDefinedList['values']); 153 154 foreach($tagsList as $key => $tagProperties) 155 { 156 $keyExist=array_key_exists($key, $picturesTags); 157 $userDefined=preg_match('/^userDefined\./i', $key); 158 159 if(($group!=$tagProperties['gName']) and 160 ( $keyExist or $userDefined) ) 161 { 162 $group=$tagProperties['gName']; 163 if(!is_null($md)) 164 { 165 $metadata[]=$md; 166 unset($md); 167 } 168 $md=Array( 169 'TITLE' => $tagProperties['gName'], 170 'lines' => Array() 171 ); 172 } 173 174 if($keyExist) 122 175 { 123 176 $value=$picturesTags[$key]->getLabel(); … … 134 187 $value=serialize($value); 135 188 } 136 137 if($group!=$val)138 {139 $group=$val;140 if(!is_null($md))141 {142 $metadata[]=$md;143 unset($md);144 }145 $md=Array(146 'TITLE' => $val,147 'lines' => Array()148 );149 }150 189 $md['lines'][L10n::get($picturesTags[$key]->getName())]=$this->prepareValueForDisplay($value, $picturesTags[$key]->isTranslatable()); 151 190 } 191 elseif($userDefined) 192 { 193 $md['lines'][$tagProperties['name']]=$userDefinedValues[$tagProperties['numId']]; 194 } 152 195 } 153 196 … … 157 200 } 158 201 159 160 if($analyzed=='n' and 161 $this->config['amd_FillDataBaseContinuously']=='y' and 202 $template->assign('metadata', $metadata); 203 } 204 205 /** 206 * used by the 'loc_end_page_tail' event 207 * 208 * on each public page viewed, add a script to do an ajax call to the "public.makeStats.doPictureAnalyze" function 209 */ 210 public function applyJS() 211 { 212 global $template; 213 214 if($this->config['amd_FillDataBaseContinuously']=='y' and 162 215 $this->config['amd_AllPicturesAreAnalyzed']=='n') 163 216 { 164 /* if picture is not analyzed, do analyze 165 * 166 * note : the $loaded parameter is set to true, in this case the function 167 * analyzeImageFile uses data from the $this->jpegMD object which 168 * have data already loaded => the picture is not analyzed twice, 169 * the function only do the database update 170 */ 171 $this->analyzeImageFile($filename, $page['image_id'], true); 172 $this->makeStatsConsolidation(); 173 } 174 175 $template->assign('metadata', $metadata); 217 $template->set_filename('applyJS', 218 dirname($this->getFileLocation()).'/templates/doAnalyze.tpl'); 219 220 $datas=array( 221 'urlRequest' => $this->getAdminLink('ajax'), 222 'id' => ($this->pictureProperties['analyzed']=='n')?$this->pictureProperties['id']:'0' 223 ); 224 225 $template->assign('datas', $datas); 226 $template->append('footer_elements', $template->parse('applyJS', true)); 227 } 176 228 } 177 229
Note: See TracChangeset
for help on using the changeset viewer.