[6891] | 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 | * RBCallBackAMetadata classe => used for the request builder |
---|
| 18 | * |
---|
| 19 | * ----------------------------------------------------------------------------- |
---|
| 20 | */ |
---|
| 21 | global $user; |
---|
| 22 | |
---|
| 23 | if(!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
[16007] | 24 | if(!defined('JPEG_METADATA_DIR')) define('JPEG_METADATA_DIR', dirname(__FILE__)."/JpegMetaData/"); |
---|
[6891] | 25 | |
---|
| 26 | //include_once('') |
---|
| 27 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCRequestBuilder.class.inc.php'); |
---|
[16007] | 28 | include_once(PHPWG_PLUGINS_PATH.'AMetaData/JpegMetaData/Common/Const.class.php'); |
---|
| 29 | include_once(PHPWG_PLUGINS_PATH.'AMetaData/JpegMetaData/Common/L10n.class.php'); |
---|
[6891] | 30 | |
---|
| 31 | load_language('plugin.lang', AMD_PATH); |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | if(isset($user['language'])) |
---|
| 35 | { |
---|
| 36 | L10n::setLanguage($user['language']); |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | class RBCallBackAMetaData extends GPCSearchCallback { |
---|
| 40 | |
---|
| 41 | /** |
---|
| 42 | * the getImageId returns the name of the image id attribute |
---|
| 43 | * return String |
---|
| 44 | */ |
---|
| 45 | static public function getImageId() |
---|
| 46 | { |
---|
| 47 | return("pait.imageId"); |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | /** |
---|
| 51 | * the getSelect function must return an attribute list separated with a comma |
---|
| 52 | * |
---|
| 53 | * "att1, att2, att3, att4" |
---|
| 54 | */ |
---|
| 55 | static public function getSelect($param="") |
---|
| 56 | { |
---|
[7399] | 57 | return(" pait.value AS amdValue, paut.name AS amdName "); |
---|
[6891] | 58 | } |
---|
| 59 | |
---|
| 60 | /** |
---|
| 61 | * the getFrom function must return a tables list separated with a comma |
---|
| 62 | * |
---|
| 63 | * "table1, (table2 left join table3 on table2.key = table3.key), table4" |
---|
| 64 | */ |
---|
| 65 | static public function getFrom($param="") |
---|
| 66 | { |
---|
| 67 | global $prefixeTable; |
---|
| 68 | |
---|
| 69 | return($prefixeTable."amd_images_tags pait |
---|
| 70 | LEFT JOIN ".$prefixeTable."amd_used_tags paut |
---|
| 71 | ON pait.numId = paut.numId "); |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | /** |
---|
| 75 | * the getWhere function must return a ready to use where clause |
---|
| 76 | * |
---|
| 77 | * "(att1 = value0 OR att2 = value1) AND att4 LIKE value2 " |
---|
| 78 | */ |
---|
| 79 | static public function getWhere($param="") |
---|
| 80 | { |
---|
| 81 | switch($param['conditionIf']) |
---|
| 82 | { |
---|
| 83 | case 'E': |
---|
| 84 | $returned="pait.numId = ".$param['metaNumId']; |
---|
| 85 | break; |
---|
| 86 | case '!E': |
---|
| 87 | $returned="pait.numId = ".$param['metaNumId']; |
---|
| 88 | break; |
---|
| 89 | case '=': |
---|
| 90 | $returned="pait.numId = ".$param['metaNumId']." AND "; |
---|
| 91 | |
---|
| 92 | $tmp=array(); |
---|
| 93 | foreach($param['listValues'] as $key=>$val) |
---|
| 94 | { |
---|
| 95 | $tmp[]="pait.value = '".$val."'"; |
---|
| 96 | } |
---|
| 97 | $returned.="(".implode(' OR ', $tmp).")"; |
---|
| 98 | break; |
---|
| 99 | case '!=': |
---|
| 100 | $returned="pait.numId = ".$param['metaNumId']." AND NOT "; |
---|
| 101 | |
---|
| 102 | $tmp=array(); |
---|
| 103 | foreach($param['listValues'] as $key=>$val) |
---|
| 104 | { |
---|
| 105 | $tmp[]="pait.value = '".$val."'"; |
---|
| 106 | } |
---|
| 107 | $returned.="(".implode(' OR ', $tmp).")"; |
---|
| 108 | break; |
---|
| 109 | case '%': |
---|
| 110 | $returned="pait.numId = ".$param['metaNumId']." AND "; |
---|
| 111 | |
---|
| 112 | $tmp=array(); |
---|
| 113 | foreach($param['listValues'] as $key=>$val) |
---|
| 114 | { |
---|
| 115 | $tmp[]="pait.value LIKE '%".$val."%'"; |
---|
| 116 | } |
---|
| 117 | $returned.="(".implode(' OR ', $tmp).")"; |
---|
| 118 | break; |
---|
| 119 | case '!%': |
---|
| 120 | $returned="pait.numId = ".$param['metaNumId']." AND NOT "; |
---|
| 121 | |
---|
| 122 | $tmp=array(); |
---|
| 123 | foreach($param['listValues'] as $key=>$val) |
---|
| 124 | { |
---|
| 125 | $tmp[]="pait.value LIKE '%".$val."%'"; |
---|
| 126 | } |
---|
| 127 | $returned.="(".implode(' OR ', $tmp).")"; |
---|
| 128 | break; |
---|
| 129 | case '^%': |
---|
| 130 | $returned="pait.numId = ".$param['metaNumId']." AND "; |
---|
| 131 | |
---|
| 132 | $tmp=array(); |
---|
| 133 | foreach($param['listValues'] as $key=>$val) |
---|
| 134 | { |
---|
| 135 | $tmp[]="pait.value LIKE '".$val."%'"; |
---|
| 136 | } |
---|
| 137 | $returned.="(".implode(' OR ', $tmp).")"; |
---|
| 138 | break; |
---|
| 139 | case '!^%': |
---|
| 140 | $returned="pait.numId = ".$param['metaNumId']." AND NOT "; |
---|
| 141 | |
---|
| 142 | $tmp=array(); |
---|
| 143 | foreach($param['listValues'] as $key=>$val) |
---|
| 144 | { |
---|
| 145 | $tmp[]="pait.value LIKE '".$val."%'"; |
---|
| 146 | } |
---|
| 147 | $returned.="(".implode(' OR ', $tmp).")"; |
---|
| 148 | break; |
---|
| 149 | case '$%': |
---|
| 150 | $returned="pait.numId = ".$param['metaNumId']." AND "; |
---|
| 151 | |
---|
| 152 | $tmp=array(); |
---|
| 153 | foreach($param['listValues'] as $key=>$val) |
---|
| 154 | { |
---|
| 155 | $tmp[]="pait.value LIKE '%".$val."'"; |
---|
| 156 | } |
---|
| 157 | $returned.="(".implode(' OR ', $tmp).")"; |
---|
| 158 | break; |
---|
| 159 | case '!$%': |
---|
| 160 | $returned="pait.numId = ".$param['metaNumId']." AND NOT "; |
---|
| 161 | |
---|
| 162 | $tmp=array(); |
---|
| 163 | foreach($param['listValues'] as $key=>$val) |
---|
| 164 | { |
---|
| 165 | $tmp[]="pait.value LIKE '%".$val."'"; |
---|
| 166 | } |
---|
| 167 | $returned.="(".implode(' OR ', $tmp).")"; |
---|
| 168 | break; |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | return($returned); |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | /** |
---|
| 175 | * the getJoin function must return a ready to use where allowing to join the |
---|
| 176 | * IMAGES table (key : id) with given conditions |
---|
| 177 | * |
---|
| 178 | * "att3 = pit.id " |
---|
| 179 | */ |
---|
| 180 | static public function getJoin($param="") |
---|
| 181 | { |
---|
| 182 | return("pit.id = pait.imageId"); |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | |
---|
| 186 | /** |
---|
| 187 | * the getFilter function must return a ready to use where clause |
---|
| 188 | * this where clause is used to filter the cache when the used tables can |
---|
| 189 | * return more than one result |
---|
| 190 | * |
---|
| 191 | * the filter is equal to the where clause, or is equal to a part of the where |
---|
| 192 | * clause |
---|
| 193 | * |
---|
| 194 | */ |
---|
| 195 | static public function getFilter($param="") |
---|
| 196 | { |
---|
| 197 | return("pait.numId = ".$param['metaNumId']); |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | |
---|
| 201 | /** |
---|
| 202 | * this function is called by the request builder, allowing to display plugin |
---|
| 203 | * data with a specific format |
---|
| 204 | * |
---|
| 205 | * @param Array $attributes : array of ('attribute_name' => 'attribute_value') |
---|
| 206 | * @return String : HTML formatted value |
---|
| 207 | */ |
---|
| 208 | static public function formatData($attributes) |
---|
| 209 | { |
---|
| 210 | /* attributes is an array : |
---|
| 211 | * Array( |
---|
| 212 | * 'amdValue' => 'value1#sep#value2#...#sep#valueN' |
---|
| 213 | * 'amdTagId' => 'tagId1#sep#tagId2#...#sep#tagIdN' |
---|
| 214 | * ); |
---|
| 215 | */ |
---|
| 216 | $returned=''; |
---|
| 217 | |
---|
| 218 | $values=explode('#sep#', $attributes['amdValue']); |
---|
| 219 | $tagIds=explode('#sep#', $attributes['amdName']); |
---|
| 220 | |
---|
| 221 | foreach($tagIds as $key => $val) |
---|
| 222 | { |
---|
| 223 | if($returned!='') $returned.='<br>'; |
---|
| 224 | |
---|
| 225 | $returned.="<span style='font-weight:bold;'>".L10n::get($val)."</span> : ".L10n::get($values[$key]); |
---|
| 226 | } |
---|
| 227 | |
---|
| 228 | return($returned); |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | |
---|
| 232 | /** |
---|
| 233 | * this function is called by the request builder to make the search page, and |
---|
| 234 | * must return the HTML & JS code of the dialogbox used to select criterion |
---|
| 235 | * |
---|
| 236 | * Notes : |
---|
| 237 | * - the dialogbox is a JS object with a public method 'show' |
---|
| 238 | * - when the method show is called, one parameter is given by the request |
---|
| 239 | * builder ; the parameter is an object defined as this : |
---|
| 240 | * { |
---|
| 241 | * cBuilder: an instance of the criteriaBuilder object used in the page, |
---|
| 242 | * eventOK : a callback function, called when the OK button is pushed |
---|
| 243 | * id: |
---|
| 244 | * } |
---|
| 245 | * |
---|
| 246 | * |
---|
| 247 | * |
---|
| 248 | * |
---|
| 249 | * @param String $mode : can take 'admin' or 'public' values, allowing to |
---|
| 250 | * return different interface if needed |
---|
| 251 | * @return String : HTML formatted value |
---|
| 252 | */ |
---|
| 253 | static public function getInterfaceContent($mode='admin') |
---|
| 254 | { |
---|
| 255 | return(AMD_functions::dialogBoxMetadata()); |
---|
| 256 | } |
---|
| 257 | |
---|
| 258 | /** |
---|
| 259 | * this function returns the label displayed in the criterion menu |
---|
| 260 | * |
---|
| 261 | * @return String : label displayed in the criterions menu |
---|
| 262 | */ |
---|
| 263 | static public function getInterfaceLabel() |
---|
| 264 | { |
---|
| 265 | return(l10n('g003_add_metadata')); |
---|
| 266 | } |
---|
| 267 | |
---|
| 268 | /** |
---|
| 269 | * this function returns the name of the dialog box class |
---|
| 270 | * |
---|
| 271 | * @return String : name of the dialogbox class |
---|
| 272 | */ |
---|
| 273 | static public function getInterfaceDBClass() |
---|
| 274 | { |
---|
| 275 | return('dialogChooseMetadataBox'); |
---|
| 276 | } |
---|
| 277 | |
---|
| 278 | } |
---|
| 279 | |
---|
| 280 | ?> |
---|