null,
'ngg_id' => null,
'include' => 'all',
'exclude' => null,
'not_keyword' => null,
'show_title' => true,
'show_empty' => false,
), $atts ) );
global $adobeXMP;
$pids = array();
$html = '';
if ( ! empty( $id ) ) {
$pids = array_map( 'trim', explode( ',', $id ) );
}
if ( ! empty( $ngg_id ) ) {
foreach ( explode( ',', $ngg_id ) as $pid ) {
$pids[] = 'ngg-' . trim( $pid );
}
}
$include_dt = $this->explode_csv( $include ); // Lowercase associative array.
$exclude_dt = $this->explode_csv( $exclude ); // Lowercase associative array.
$exclude_kw = $this->explode_csv( $not_keyword ); // Lowercase associative array.
$show_title = $this->get_bool( $show_title ); // Sanitize true/false.
$show_empty = $this->get_bool( $show_empty ); // Sanitize true/false.
foreach ( $pids as $pid ) {
if ( empty( $pid ) ) { // Just in case.
continue;
}
$image_xmp = $adobeXMP->get_xmp( $pid );
if ( empty( $image_xmp ) ) {
$html .= '
' . sprintf( __( 'No XMP found for image ID %s.',
'adobe-xmp-for-wp' ), $pid ) . '
';
continue;
}
if ( $include === 'all' ) {
foreach( array_keys( $image_xmp ) as $val ) {
$val = trim( strtolower( $val ), '\'" ' );
$include_dt[ $val ] = true;
}
}
$html .= "\n" . '' . "\n";
foreach ( array_keys( $image_xmp ) as $dt ) {
$dt_lower = strtolower( $dt );
if ( empty( $include_dt[ $dt_lower ] ) || ! empty( $exclude_dt[ $dt_lower ] ) ) {
continue;
}
$css_class = 'xmp_' . sanitize_key( str_replace( ' ', '_', $dt_lower ) );
if ( ! $show_empty && empty( $image_xmp[ $dt ] ) ) {
continue;
}
if ( $show_title ) {
$html .= '- ' . $dt . '
' . "\n";
}
/**
* First dimension.
*/
if ( is_array( $image_xmp[ $dt ] ) ) {
/**
* Check for second dimension.
*/
foreach ( $image_xmp[ $dt ] as $dd ) {
/**
* Second dimension arrays are printed with multiple - tags.
*/
if ( is_array( $dd ) ) {
switch ( $dt ) {
/**
* Check for hierarchical strings to ignore.
*/
case 'Hierarchical Keywords' :
if ( ! empty( $exclude_kw ) ) {
$kws = strtolower( implode( '-', array_values( $dd ) ) );
if ( ! empty( $exclude_kw[ $kws ] ) ) {
continue 2;
}
}
break;
}
$html .= '
- ' .
implode( ' > ', array_values( $dd ) ) . '
' . "\n";
/**
* Print simple arrays as a comma delimited list, and break the foreach loop.
*/
} else {
switch ( $dt ) {
case 'Keywords' :
if ( ! empty( $exclude_kw ) ) {
foreach ( $image_xmp[ $dt ] as $el => $val ) {
if ( ! empty( $exclude_kw[ strtolower( $val ) ] ) ) {
unset ( $image_xmp[ $dt ][ $el ] );
}
}
}
break;
}
$html .= '- ' .
implode( ', ', array_values( $image_xmp[ $dt ] ) ) . '
' . "\n";
/**
* Get another element from the $include array.
*/
break;
}
}
/**
* Value is a simple string.
*/
} else {
$html .= '- ' . $image_xmp[ $dt ] . '
' . "\n";
}
}
$html .= '
' . "\n";
}
return $html;
}
private function explode_csv( $str ) {
$ret = array();
foreach ( explode( ',', $str ) as $val ) {
$val = trim( strtolower( $val ), '\'" ' );
$ret[ $val ] = true;
}
return $ret;
}
/**
* Converts string to boolean.
*/
private function get_bool( $mixed ) {
return is_string( $mixed ) ? filter_var( $mixed, FILTER_VALIDATE_BOOLEAN ) : (bool) $mixed;
}
}
adobeXMPforWPShortcode::get_instance();
}