Version Description
-
New Feature: Images can now be included alongside documents in a document gallery (using
images=true
attribute). -
New Feature: Attachment ids can now be explicitly listed, allowing for documents not attached to a post or page
to be included in a document gallery (e.g.:
ids=2,42,57,1
). Note that no spaces should be included. - Enhancement: The CSS stylesheet has been enhanced for more flexibility in sizing icons.
Download this release
Release Info
Developer | dan.rossiter |
Plugin | Document Gallery |
Version | 1.2 |
Comparing to | |
See all releases |
Code changes from version 1.1 to 1.2
- document-gallery.php +59 -22
- readme.txt +24 -4
- style.css +5 -3
document-gallery.php
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: Document Gallery
|
4 |
-
Description: Display non-images in gallery format on page.
|
5 |
-
Version: 1.
|
6 |
Author: Dan Rossiter
|
7 |
Author URI: http://danrossiter.org/
|
8 |
License: GPL2
|
@@ -17,36 +17,53 @@ function dg_get_attachment_icons($atts) {
|
|
17 |
'orderby' => 'menu_order',
|
18 |
'order' => 'ASC',
|
19 |
'attachment_pg' => FALSE, // default: link directly to file (true to link to attachment pg)
|
20 |
-
'
|
|
|
21 |
), $atts) );
|
22 |
|
23 |
-
|
24 |
-
|
25 |
$errs = array();
|
26 |
|
27 |
-
|
|
|
|
|
28 |
|
29 |
$order = strtoupper( $order );
|
30 |
if($order != 'ASC' && $order != 'DEC')
|
31 |
$errs[] = "The order attribute must be either ASC or DEC. You entered $order.";
|
32 |
|
33 |
-
if($attachment_pg
|
34 |
-
|
|
|
|
|
|
|
35 |
|
36 |
// http://www.youtube.com/watch?v=ClnSMCdw6E8
|
37 |
if( $errs ) return implode(' ', $errs);
|
38 |
-
//
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
-
|
|
|
|
|
42 |
'numberposts' => -1,
|
43 |
'orderby' => $orderby,
|
44 |
'order' => $order,
|
45 |
'post_type' => 'attachment',
|
46 |
'post_mime_type' => 'application,video,text,audio',
|
47 |
'post_parent' => get_the_ID() );
|
|
|
|
|
|
|
|
|
48 |
|
49 |
-
if ( $attachments
|
50 |
$attachment_str = array( PHP_EOL.'<!-- Generated using Document Gallery. Get yours here: '.
|
51 |
'http://wordpress.org/extend/plugins/document-gallery -->'.PHP_EOL );
|
52 |
|
@@ -92,7 +109,7 @@ function dg_get_attachment_icons($atts) {
|
|
92 |
|
93 |
// join array & return
|
94 |
return implode( '', $attachment_str );
|
95 |
-
} //
|
96 |
|
97 |
return PHP_EOL.'<!-- Document Gallery: No attachments to display. -->'.PHP_EOL;
|
98 |
}
|
@@ -101,14 +118,18 @@ add_shortcode('dg', 'dg_get_attachment_icons');
|
|
101 |
add_shortcode('document gallery', 'dg_get_attachment_icons');
|
102 |
|
103 |
|
104 |
-
// ADD SOME STYLING //
|
105 |
-
function dg_add_header_css() {
|
106 |
-
wp_enqueue_style( 'document-gallery-css', plugins_url('style.css', __FILE__) );
|
107 |
-
}
|
108 |
-
add_action( 'wp_print_styles', 'dg_add_header_css');
|
109 |
-
|
110 |
|
111 |
// HELPERS //
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
|
113 |
// pass in $title & $url to avoid mult function calls
|
114 |
function dg_get_attachment_image( $id, $title, $filename ) {
|
@@ -269,15 +290,31 @@ function dg_get_attachment_image( $id, $title, $filename ) {
|
|
269 |
break;
|
270 |
// fallback to default icons if not recognized
|
271 |
default:
|
272 |
-
//
|
273 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
274 |
}
|
275 |
|
276 |
-
return '<img src="'.DG_URL.
|
277 |
}
|
|
|
278 |
// Filtering attachment_icon was considered, then dismissed in v1.0.3 because it would mean almost
|
279 |
// doubling the amount of processing for each icon. The native WP function would create the icon,
|
280 |
// then 99% of the time this function would replace it. Better to just call the native WP function
|
281 |
// at the end when needed. Filter would look like this:
|
282 |
// add_filter( 'attachment_icon', 'dg_get_attachment_icon', 10, 2 );v
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
283 |
?>
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: Document Gallery
|
4 |
+
Description: Display non-images (and images) in gallery format on a page or post with the [dg] shortcode.
|
5 |
+
Version: 1.2
|
6 |
Author: Dan Rossiter
|
7 |
Author URI: http://danrossiter.org/
|
8 |
License: GPL2
|
17 |
'orderby' => 'menu_order',
|
18 |
'order' => 'ASC',
|
19 |
'attachment_pg' => FALSE, // default: link directly to file (true to link to attachment pg)
|
20 |
+
'images' => FALSE, // if enabled, all images attached to current page will be included also
|
21 |
+
'ids' => FALSE // comma-separated list of attachment ids
|
22 |
), $atts) );
|
23 |
|
24 |
+
// INIT
|
25 |
+
$attachments = array();
|
26 |
$errs = array();
|
27 |
|
28 |
+
|
29 |
+
// ATTRIBUTE VALIDATION
|
30 |
+
if( strtolower($descriptions) == "false" ){ $descriptions = FALSE; }
|
31 |
|
32 |
$order = strtoupper( $order );
|
33 |
if($order != 'ASC' && $order != 'DEC')
|
34 |
$errs[] = "The order attribute must be either ASC or DEC. You entered $order.";
|
35 |
|
36 |
+
if( strtolower($attachment_pg) == "false" ){ $attachment_pg = FALSE; }
|
37 |
+
|
38 |
+
if( strtolower($images) == "false" ){ $images = FALSE; }
|
39 |
+
|
40 |
+
if( strtolower($ids) ){ $ids = FALSE; }
|
41 |
|
42 |
// http://www.youtube.com/watch?v=ClnSMCdw6E8
|
43 |
if( $errs ) return implode(' ', $errs);
|
44 |
+
// END VALIDATION (WE MADE IT!)
|
45 |
+
|
46 |
+
|
47 |
+
// LET'S GET SOME DOCUMENTS!
|
48 |
+
if( $ids && ( $ids = explode( ',', $ids ) ) ){
|
49 |
+
$attachments = dg_get_attachments_by_ids( $ids );
|
50 |
+
}
|
51 |
|
52 |
+
// if 'ids' was used, skip
|
53 |
+
if( !$attachments ){
|
54 |
+
$args = array(
|
55 |
'numberposts' => -1,
|
56 |
'orderby' => $orderby,
|
57 |
'order' => $order,
|
58 |
'post_type' => 'attachment',
|
59 |
'post_mime_type' => 'application,video,text,audio',
|
60 |
'post_parent' => get_the_ID() );
|
61 |
+
if( $images ) $args['post_mime_type'] .= ',image';
|
62 |
+
|
63 |
+
$attachments = get_posts($args);
|
64 |
+
}
|
65 |
|
66 |
+
if ( $attachments ) { // DOCUMENT LOOP
|
67 |
$attachment_str = array( PHP_EOL.'<!-- Generated using Document Gallery. Get yours here: '.
|
68 |
'http://wordpress.org/extend/plugins/document-gallery -->'.PHP_EOL );
|
69 |
|
109 |
|
110 |
// join array & return
|
111 |
return implode( '', $attachment_str );
|
112 |
+
} // END DOCUMENT LOOP
|
113 |
|
114 |
return PHP_EOL.'<!-- Document Gallery: No attachments to display. -->'.PHP_EOL;
|
115 |
}
|
118 |
add_shortcode('document gallery', 'dg_get_attachment_icons');
|
119 |
|
120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
|
122 |
// HELPERS //
|
123 |
+
function dg_get_attachments_by_ids( $ids ){
|
124 |
+
$attachments = array();
|
125 |
+
foreach( $ids as $id ){
|
126 |
+
$attachment = get_post( $id );
|
127 |
+
if( $attachment->post_type == 'attachment' )
|
128 |
+
$attachments[] = $attachment;
|
129 |
+
// else: not an attachment so skip
|
130 |
+
}
|
131 |
+
return $attachments;
|
132 |
+
}
|
133 |
|
134 |
// pass in $title & $url to avoid mult function calls
|
135 |
function dg_get_attachment_image( $id, $title, $filename ) {
|
290 |
break;
|
291 |
// fallback to default icons if not recognized
|
292 |
default:
|
293 |
+
// handle images
|
294 |
+
if( preg_match( '/^image/', $filetype['type'] ) &&
|
295 |
+
( $icon = wp_get_attachment_image( $id, 'thumbnail', false ) ) )
|
296 |
+
return $icon;
|
297 |
+
|
298 |
+
// fallback to wp defaults - get_attachment_icon is DEPRECIATED! (replaced in dg v1.1)
|
299 |
+
if( $icon = wp_get_attachment_image( $id, null, true ) )
|
300 |
+
return $icon;
|
301 |
+
|
302 |
+
return "<!-- Failed to retrive icon for attachment #$id -->"; // everything failed. This is bad...
|
303 |
}
|
304 |
|
305 |
+
return '<img src="'.DG_URL."icons/$icon\" title=\"$title\" alt=\"$title\" />";
|
306 |
}
|
307 |
+
|
308 |
// Filtering attachment_icon was considered, then dismissed in v1.0.3 because it would mean almost
|
309 |
// doubling the amount of processing for each icon. The native WP function would create the icon,
|
310 |
// then 99% of the time this function would replace it. Better to just call the native WP function
|
311 |
// at the end when needed. Filter would look like this:
|
312 |
// add_filter( 'attachment_icon', 'dg_get_attachment_icon', 10, 2 );v
|
313 |
+
|
314 |
+
// ADD SOME STYLING //
|
315 |
+
function dg_add_header_css() {
|
316 |
+
wp_enqueue_style( 'document-gallery-css', plugins_url('style.css', __FILE__) );
|
317 |
+
}
|
318 |
+
add_action( 'wp_print_styles', 'dg_add_header_css');
|
319 |
+
|
320 |
?>
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: dan.rossiter
|
|
3 |
Tags: attachments, icons, documents, gallery, ms office, doc, ppt, xls, docx, pptx, xlsx, pdf, openoffice
|
4 |
Requires at least: 2.6
|
5 |
Tested up to: 3.5
|
6 |
-
Stable tag: 1.
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
@@ -34,12 +34,13 @@ Read more in the **Installation** tab!
|
|
34 |
In order to include all compatible docuements from a given page or post, you must include
|
35 |
the following shortcode in the post:
|
36 |
|
37 |
-
`[dg descriptions=[true
|
|
|
38 |
|
39 |
**Default Values**
|
40 |
|
41 |
-
By default, document gallery will use `descriptions=false`, `orderby=menu_order`, `order=ASC
|
42 |
-
|
43 |
|
44 |
**Descriptions Option**
|
45 |
|
@@ -70,6 +71,18 @@ If you want the user to be able to click on the icon and directly rective the op
|
|
70 |
use `attachment_pg=false` (the default). If you have information on the attachment page that you want the
|
71 |
link to go to, use `attachment_pg=true`.
|
72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
= Customize Appearance =
|
74 |
|
75 |
By default, the document gallery will use the styles within your active theme to handle most of the appearance,
|
@@ -116,6 +129,13 @@ code wherever you would like it to appear: `<?php echo do_shortcode('[dg]'); ?>`
|
|
116 |
* Support for adding your own filetypes/icons.
|
117 |
* Whatever else **you** would like (post on the [support forum](http://wordpress.org/support/plugin/document-gallery) if you have ideas)!
|
118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
= 1.1 =
|
120 |
|
121 |
* **New Feature:** Included option to link to the attachment page as well as to the actual document.
|
3 |
Tags: attachments, icons, documents, gallery, ms office, doc, ppt, xls, docx, pptx, xlsx, pdf, openoffice
|
4 |
Requires at least: 2.6
|
5 |
Tested up to: 3.5
|
6 |
+
Stable tag: 1.2
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
34 |
In order to include all compatible docuements from a given page or post, you must include
|
35 |
the following shortcode in the post:
|
36 |
|
37 |
+
`[dg descriptions=[true/false] orderby=[menu_order, title, date, author, rand] order=[ASC/DEC]
|
38 |
+
attachment_pg=[true/false] images=[true/false] ids=[false/comma-separated list of id #s]]`
|
39 |
|
40 |
**Default Values**
|
41 |
|
42 |
+
By default, document gallery will use `descriptions=false`, `orderby=menu_order`, `order=ASC`
|
43 |
+
, `attachment_pg=false`, `images=false`, and `ids=false` if you do not specify otherwise.
|
44 |
|
45 |
**Descriptions Option**
|
46 |
|
71 |
use `attachment_pg=false` (the default). If you have information on the attachment page that you want the
|
72 |
link to go to, use `attachment_pg=true`.
|
73 |
|
74 |
+
**Images** *(New in Version 1.2)*
|
75 |
+
|
76 |
+
This option will tell the plugin to pull all images attached to to a page or post in addition to all documents.
|
77 |
+
|
78 |
+
**Ids** *(New in Version 1.2)*
|
79 |
+
|
80 |
+
This is an advanced option intended for experienced WordPress users. If this option is used, the plugin will
|
81 |
+
ignore attached documents, instead including all attachments defined by the ids attribute (e.g.: `ids=10,2,4,42`).
|
82 |
+
|
83 |
+
*Note: If this attribute is used, the `order`, `orderby`, and `images` attributes will be ignored. Order is defined
|
84 |
+
by the order the ids are provided.*
|
85 |
+
|
86 |
= Customize Appearance =
|
87 |
|
88 |
By default, the document gallery will use the styles within your active theme to handle most of the appearance,
|
129 |
* Support for adding your own filetypes/icons.
|
130 |
* Whatever else **you** would like (post on the [support forum](http://wordpress.org/support/plugin/document-gallery) if you have ideas)!
|
131 |
|
132 |
+
= 1.2 =
|
133 |
+
|
134 |
+
* **New Feature:** Images can now be included alongside documents in a document gallery (using `images=true` attribute).
|
135 |
+
* **New Feature:** Attachment ids can now be explicitly listed, allowing for documents not attached to a post or page
|
136 |
+
to be included in a document gallery (e.g.: `ids=2,42,57,1`). Note that no spaces should be included.
|
137 |
+
* **Enhancement:** The CSS stylesheet has been enhanced for more flexibility in sizing icons.
|
138 |
+
|
139 |
= 1.1 =
|
140 |
|
141 |
* **New Feature:** Included option to link to the attachment page as well as to the actual document.
|
style.css
CHANGED
@@ -1,6 +1,8 @@
|
|
1 |
div.document-icon{ text-align: center; }
|
2 |
|
3 |
div.document-icon img{
|
|
|
|
|
4 |
border: none;
|
5 |
}
|
6 |
|
@@ -29,7 +31,7 @@ div.document-icon-wrapper{
|
|
29 |
|
30 |
/* WITH DESCRIPTION */
|
31 |
div.descriptions.document-icon-wrapper div.document-icon{
|
32 |
-
width: 115px;
|
33 |
padding: 0;
|
34 |
padding-right: 3px;
|
35 |
float: left;
|
@@ -41,8 +43,8 @@ div.descriptions.document-icon-wrapper{
|
|
41 |
}
|
42 |
|
43 |
div.descriptions.document-icon-wrapper img{
|
44 |
-
width: 65px;
|
45 |
-
height: 65px;
|
46 |
}
|
47 |
|
48 |
/* clearfix */
|
1 |
div.document-icon{ text-align: center; }
|
2 |
|
3 |
div.document-icon img{
|
4 |
+
max-width: 89px;
|
5 |
+
max-height: 89px;
|
6 |
border: none;
|
7 |
}
|
8 |
|
31 |
|
32 |
/* WITH DESCRIPTION */
|
33 |
div.descriptions.document-icon-wrapper div.document-icon{
|
34 |
+
max-width: 115px;
|
35 |
padding: 0;
|
36 |
padding-right: 3px;
|
37 |
float: left;
|
43 |
}
|
44 |
|
45 |
div.descriptions.document-icon-wrapper img{
|
46 |
+
max-width: 65px;
|
47 |
+
max-height: 65px;
|
48 |
}
|
49 |
|
50 |
/* clearfix */
|