FALSE,
'echo' => FALSE,
'orderby' => 'menu_order',
'order' => 'ASC'
), $atts) );
$args = array(
'numberposts' => -1,
'orderby' => $orderby,
'order' => $order,
'post_type' => 'attachment',
'post_mime_type' => 'application,video,text,audio',
'post_parent' => get_the_ID() );
if ( $attachments = get_posts($args) ) {
$attachment_str = array( ''.PHP_EOL );
if($descriptions) {
$attachment_str[] = '
';
}
$count = 0;
foreach( $attachments as $attachment ) { //setup array for more than one file attachment
$url = wp_get_attachment_url( $attachment->ID );
$title = wp_get_attachment_link( $attachment->ID );
$icon = dg_get_attachment_icon( $attachment->ID, $tile, $url );
if($descriptions) {
$attachment_str[] = '';
} else {
if( $count % 4 == 0 ) {
$attachment_str[] = '';
}
$attachment_str[] = ' ';
}
$attachment_str[] = " $icon$title";
if($descriptions) {
$attachment_str[] = " | $attachment->post_content |
";
} else {
$attachment_str[] = '';
if( ++$count % 4 == 0 ) {
$attachment_str[] = '';
}
}
} // end looping attachments
// close #document-icon-wrapper
if($descriptions) {
$attachment_str[] = '
';
} else {
$attachment_str[] = '';
}
// join array & return
$attachment_str = implode( '', $attachment_str );
return $attachment_str;
} // end if attachments
return ''.PHP_EOL;
}
add_shortcode('document gallery', 'dg_get_attachment_icons');
add_shortcode('dg', 'dg_get_attachment_icons');
// ADD SOME STYLING //
function dg_add_header_css() {
wp_enqueue_style( 'document-gallery-css', plugins_url('style.css', __FILE__) );
}
add_action( 'wp_print_styles', 'dg_add_header_css');
// HELPERS //
// pass in $title & $url to avoid mult function calls
function dg_get_attachment_icon( $id, $title, $url ) {
$filename = basename( $url );
$filetype = wp_check_filetype( $filename );
// identify extension
switch( $filetype['ext'] ) {
// Most Common First
case 'pdf':
$icon = 'pdf.png';
break;
// MS Office
case 'doc':
case 'docx':
case 'docm':
case 'dotx':
case 'dotm':
$icon = 'msdoc.png';
break;
case 'ppt':
case 'pot':
case 'pps':
case 'pptx':
case 'pptm':
case 'ppsx':
case 'ppsm':
case 'potx':
case 'potm':
case 'ppam':
case 'sldx':
case 'sldm':
$icon = 'msppt.png';
break;
case 'xla':
case 'xls':
case 'xlt':
case 'xlw':
case 'xlsx':
case 'xlsm':
case 'xlsb':
case 'xltx':
case 'xltm':
case 'xlam':
$icon = 'msxls.png';
break;
case 'mdb':
$icon = 'msaccess.png';
break;
// Video formats
case 'avi':
$icon = 'avi.png';
break;
case 'divx':
$icon = 'divx.png';
break;
case 'flv':
$icon = 'flv.png';
break;
case 'qt':
case 'mov':
$icon = 'mov.png';
break;
case 'asf':
case 'asx':
case 'wax':
case 'wmv':
case 'wmx':
$icon = 'wmv.png';
break;
case 'mkv':
$icon = 'mkv.png';
break;
// Audio formats
case 'mp3':
$icon = 'mp3.png';
break;
case 'wav':
$icon = 'wav.png';
break;
case 'ogg':
case 'oga':
$icon = 'ogg.png';
break;
case 'midi':
case 'mid':
$icon = 'midi.png';
break;
case 'wma':
$icon = 'wma.png';
break;
// Text formats
case 'rtx':
$icon = 'rtx.png';
break;
case 'ics':
$icon = 'ics.png';
break;
case 'csv':
$icon = 'csv.png';
break;
// Msc application formats
case 'html':
case 'htm': // death to all who use this!
$icon = 'html.png';
break;
case 'css':
$icon = 'css.png';
break;
case 'js':
$icon = 'javascript.png';
break;
case 'class':
$icon = 'java.png';
break;
case 'zip':
$icon = 'zip.png';
break;
case 'tar':
case 'gzip':
case 'gz':
case 'bz2': // not yet WP-supported
case 'tgz': // not yet WP-supported
$icon = 'compressed.png';
break;
case 'rar': // RAWR!!!
$icon = 'rar.png';
break;
case '7z':
$icon = '7zip.png';
break;
case 'exec':
$icon = 'exec.png';
break;
case 'rtf':
$icon = 'rtf.png';
break;
case 'swf':
$icon = 'shockwave.png';
break;
// OpenOffice formats
case 'odt':
$icon = 'opendocument-text.png';
break;
case 'odp':
$icon = 'opendocument-presentation.png';
break;
case 'ods':
$icon = 'opendocument-spreadsheet.png';
break;
case 'odg':
$icon = 'opendocument-graphics.png';
break;
case 'odb':
$icon = 'opendocument-database.png';
break;
case 'odf':
$icon = 'opendocument-formula.png';
break;
// fallback to default icons if not recognized
default:
return get_attachment_icon( $id );
}
$icon = '
";
return $icon;
}
?>