Version Description
- New Feature: Included option to link to the attachment page as well as to the actual document.
- Enhancement: Added documentation for customizing the appearance of the plugin.
- Enhancement: Many improvements to the backend, including pretty HTML output and best practice implementation in calls to WordPress core functions.
Download this release
Release Info
Developer | dan.rossiter |
Plugin | Document Gallery |
Version | 1.1 |
Comparing to | |
See all releases |
Code changes from version 1.0.4 to 1.1
- document-gallery.php +57 -37
- readme.txt +68 -10
- style.css +33 -22
document-gallery.php
CHANGED
@@ -2,7 +2,7 @@
|
|
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
|
@@ -14,11 +14,30 @@ define( 'DG_URL', plugin_dir_url( __FILE__ ) );
|
|
14 |
function dg_get_attachment_icons($atts) {
|
15 |
extract( shortcode_atts( array(
|
16 |
'descriptions' => FALSE,
|
17 |
-
'echo' => FALSE,
|
18 |
'orderby' => 'menu_order',
|
19 |
-
'order' => 'ASC'
|
|
|
|
|
20 |
), $atts) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
|
|
22 |
$args = array(
|
23 |
'numberposts' => -1,
|
24 |
'orderby' => $orderby,
|
@@ -28,56 +47,58 @@ function dg_get_attachment_icons($atts) {
|
|
28 |
'post_parent' => get_the_ID() );
|
29 |
|
30 |
if ( $attachments = get_posts($args) ) {
|
31 |
-
$attachment_str = array( '<!--
|
32 |
-
|
33 |
-
|
34 |
-
if($descriptions) {
|
35 |
-
$attachment_str[] = '<table id="document-icon-wrapper">';
|
36 |
-
}
|
37 |
|
38 |
$count = 0;
|
39 |
foreach( $attachments as $attachment ) { //setup array for more than one file attachment
|
40 |
-
$url =
|
|
|
|
|
|
|
|
|
|
|
41 |
$title = get_the_title( $attachment->ID );
|
42 |
-
$icon =
|
43 |
|
44 |
-
if($descriptions) {
|
45 |
-
$attachment_str[] = '<
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
49 |
}
|
50 |
-
$attachment_str[] = '<div class="document-icon">';
|
51 |
}
|
52 |
|
53 |
-
$attachment_str[] = "<a href=\"$url\">$icon<br>$title</a>";
|
54 |
|
55 |
-
if($descriptions) {
|
56 |
-
$attachment_str[] =
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
|
|
61 |
}
|
62 |
}
|
63 |
} // end looping attachments
|
64 |
|
65 |
-
//
|
66 |
-
if($descriptions)
|
67 |
-
$attachment_str[] = '</
|
68 |
-
} elseif($count % 4 != 0) {
|
69 |
-
$attachment_str[] = '</div>';
|
70 |
}
|
71 |
|
72 |
// join array & return
|
73 |
-
|
74 |
-
return $attachment_str;
|
75 |
} // end if attachments
|
76 |
|
77 |
return PHP_EOL.'<!-- Document Gallery: No attachments to display. -->'.PHP_EOL;
|
78 |
}
|
79 |
-
add_shortcode('document gallery', 'dg_get_attachment_icons');
|
80 |
add_shortcode('dg', 'dg_get_attachment_icons');
|
|
|
|
|
81 |
|
82 |
|
83 |
// ADD SOME STYLING //
|
@@ -90,8 +111,7 @@ add_action( 'wp_print_styles', 'dg_add_header_css');
|
|
90 |
// HELPERS //
|
91 |
|
92 |
// pass in $title & $url to avoid mult function calls
|
93 |
-
function
|
94 |
-
$filename = basename( $url );
|
95 |
$filetype = wp_check_filetype( $filename );
|
96 |
|
97 |
// identify extension
|
@@ -249,11 +269,11 @@ function dg_get_attachment_icon( $id, $title, $url ) {
|
|
249 |
break;
|
250 |
// fallback to default icons if not recognized
|
251 |
default:
|
252 |
-
|
|
|
253 |
}
|
254 |
|
255 |
-
|
256 |
-
return $icon;
|
257 |
}
|
258 |
// Filtering attachment_icon was considered, then dismissed in v1.0.3 because it would mean almost
|
259 |
// doubling the amount of processing for each icon. The native WP function would create the icon,
|
2 |
/*
|
3 |
Plugin Name: Document Gallery
|
4 |
Description: Display non-images in gallery format on page.
|
5 |
+
Version: 1.1
|
6 |
Author: Dan Rossiter
|
7 |
Author URI: http://danrossiter.org/
|
8 |
License: GPL2
|
14 |
function dg_get_attachment_icons($atts) {
|
15 |
extract( shortcode_atts( array(
|
16 |
'descriptions' => FALSE,
|
|
|
17 |
'orderby' => 'menu_order',
|
18 |
+
'order' => 'ASC',
|
19 |
+
'attachment_pg' => FALSE, // default: link directly to file (true to link to attachment pg)
|
20 |
+
'ids' => FALSE // not yet supported
|
21 |
), $atts) );
|
22 |
+
|
23 |
+
|
24 |
+
// Some validation of user values
|
25 |
+
$errs = array();
|
26 |
+
|
27 |
+
if($descriptions != FALSE){ $descriptions = TRUE; }
|
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 != FALSE){ $attachment_pg = TRUE; }
|
34 |
+
if($ids != FALSE){ $ids = FALSE; } // not yet supported
|
35 |
+
|
36 |
+
// http://www.youtube.com/watch?v=ClnSMCdw6E8
|
37 |
+
if( $errs ) return implode(' ', $errs);
|
38 |
+
// All's well. Carry on, my wayward son.
|
39 |
|
40 |
+
|
41 |
$args = array(
|
42 |
'numberposts' => -1,
|
43 |
'orderby' => $orderby,
|
47 |
'post_parent' => get_the_ID() );
|
48 |
|
49 |
if ( $attachments = get_posts($args) ) {
|
50 |
+
$attachment_str = array( PHP_EOL.'<!-- Generated using Document Gallery. Get yours here: '.
|
51 |
+
'http://wordpress.org/extend/plugins/document-gallery -->'.PHP_EOL );
|
|
|
|
|
|
|
|
|
52 |
|
53 |
$count = 0;
|
54 |
foreach( $attachments as $attachment ) { //setup array for more than one file attachment
|
55 |
+
$url = $attachment->guid;
|
56 |
+
$filename = basename( $url );
|
57 |
+
|
58 |
+
if( $attachment_pg ) // link to attachment page
|
59 |
+
$url = get_attachment_link( $attachment->ID );
|
60 |
+
|
61 |
$title = get_the_title( $attachment->ID );
|
62 |
+
$icon = dg_get_attachment_image( $attachment->ID, $title, $filename );
|
63 |
|
64 |
+
if($descriptions) { // start wrapper
|
65 |
+
$attachment_str[] = '<div class="document-icon-wrapper descriptions">'.PHP_EOL.
|
66 |
+
' <div class="document-icon">'.PHP_EOL;
|
67 |
+
} else { // no description
|
68 |
+
if( $count % 4 == 0 ) { // start wrapper
|
69 |
+
$attachment_str[] = '<div id="document-icon-wrapper">'.PHP_EOL;
|
70 |
}
|
71 |
+
$attachment_str[] = ' <div class="document-icon">'.PHP_EOL;
|
72 |
}
|
73 |
|
74 |
+
$attachment_str[] = " <a href=\"$url\">$icon<br>$title</a>".PHP_EOL;
|
75 |
|
76 |
+
if($descriptions) { // end icon & add description
|
77 |
+
$attachment_str[] = ' </div>'.PHP_EOL.
|
78 |
+
" <p>$attachment->post_content</p>".
|
79 |
+
PHP_EOL.'</div>'.PHP_EOL;
|
80 |
+
} else { // end icon
|
81 |
+
$attachment_str[] = ' </div>'.PHP_EOL;
|
82 |
+
if( ++$count % 4 == 0 ) { // end wrapper
|
83 |
+
$attachment_str[] = '</div>'.PHP_EOL;
|
84 |
}
|
85 |
}
|
86 |
} // end looping attachments
|
87 |
|
88 |
+
// for galleries w/ number of docs != mult of 4
|
89 |
+
if( $count % 4 != 0 && !$descriptions ){ // end wrapper
|
90 |
+
$attachment_str[] = '</div>'.PHP_EOL;
|
|
|
|
|
91 |
}
|
92 |
|
93 |
// join array & return
|
94 |
+
return implode( '', $attachment_str );
|
|
|
95 |
} // end if attachments
|
96 |
|
97 |
return PHP_EOL.'<!-- Document Gallery: No attachments to display. -->'.PHP_EOL;
|
98 |
}
|
|
|
99 |
add_shortcode('dg', 'dg_get_attachment_icons');
|
100 |
+
// Depreciated as of v1.0. left for backward compatibility
|
101 |
+
add_shortcode('document gallery', 'dg_get_attachment_icons');
|
102 |
|
103 |
|
104 |
// ADD SOME STYLING //
|
111 |
// HELPERS //
|
112 |
|
113 |
// pass in $title & $url to avoid mult function calls
|
114 |
+
function dg_get_attachment_image( $id, $title, $filename ) {
|
|
|
115 |
$filetype = wp_check_filetype( $filename );
|
116 |
|
117 |
// identify extension
|
269 |
break;
|
270 |
// fallback to default icons if not recognized
|
271 |
default:
|
272 |
+
// get_attachment_icon is DEPRECIATED! (replaced in v1.1)
|
273 |
+
return wp_get_attachment_image( $id, null, true );
|
274 |
}
|
275 |
|
276 |
+
return '<img src="'.DG_URL.'icons/'.$icon."\" title=\"$title\" alt=\"$title\"/>";
|
|
|
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,
|
readme.txt
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
=== Document Gallery ===
|
2 |
Contributors: dan.rossiter
|
3 |
-
Tags: attachments, icons, documents, gallery
|
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 |
|
@@ -13,8 +13,12 @@ making them easy to share.
|
|
13 |
== Description ==
|
14 |
|
15 |
This plugin allows the user to effortlessly include a gallery, much like a photo gallery,
|
16 |
-
of all your non-image attachments anywhere within your post.
|
17 |
-
|
|
|
|
|
|
|
|
|
18 |
|
19 |
*If this plugin has helped you, please take a moment to
|
20 |
[rate it](http://wordpress.org/support/view/plugin-reviews/document-gallery#postform)!*
|
@@ -30,9 +34,21 @@ of all your non-image attachments anywhere within your post. Read more in the
|
|
30 |
In order to include all compatible docuements from a given page or post, you must include
|
31 |
the following shortcode in the post:
|
32 |
|
33 |
-
`[dg
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
* `menu_order` - This is probably the one you want to use. Order by the integer fields in the Insert /
|
38 |
Upload Media Gallery dialog. Note that these fields may be blank by default. If this is the case,
|
@@ -42,8 +58,42 @@ you must populate the fields before this option will work.
|
|
42 |
* `author` - Order by the owner of the upload (username).
|
43 |
* `rand` - Pseudo-random order.
|
44 |
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
= Theme Developers =
|
49 |
|
@@ -58,13 +108,21 @@ code wherever you would like it to appear: `<?php echo do_shortcode('[dg]'); ?>`
|
|
58 |
|
59 |
== Changelog ==
|
60 |
|
61 |
-
= Coming Soon
|
62 |
|
63 |
-
*
|
|
|
64 |
* Option to open documents directly within your browser (à la [Google Drive Viewer](https://drive.google.com/viewer)).
|
65 |
* Support for adding your own filetypes/icons.
|
66 |
* Whatever else **you** would like (post on the [support forum](http://wordpress.org/support/plugin/document-gallery) if you have ideas)!
|
67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
= 1.0.4 =
|
69 |
|
70 |
* **Bug Fix:** Removed extra `div` at bottom when number of documents is evenly divisible by 4. (Thanks, joero4ri!)
|
1 |
=== Document Gallery ===
|
2 |
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.1
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
13 |
== Description ==
|
14 |
|
15 |
This plugin allows the user to effortlessly include a gallery, much like a photo gallery,
|
16 |
+
of all your non-image attachments anywhere within your post.
|
17 |
+
|
18 |
+
The plugin will, by default, inherit the styling within your active theme, but with a
|
19 |
+
little CSS knowledge it is easily modified to meet your specific needs.
|
20 |
+
|
21 |
+
Read more in the **Installation** tab!
|
22 |
|
23 |
*If this plugin has helped you, please take a moment to
|
24 |
[rate it](http://wordpress.org/support/view/plugin-reviews/document-gallery#postform)!*
|
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 or false] orderby=[menu_order, title, date, author, rand] order=[ASC or DEC] attachment_pg=[true or false]]`
|
38 |
+
|
39 |
+
**Default Values**
|
40 |
+
|
41 |
+
By default, document gallery will use `descriptions=false`, `orderby=menu_order`, `order=ASC`,
|
42 |
+
and `attachment_pg=false` if you do not specify otherwise.
|
43 |
+
|
44 |
+
**Descriptions Option**
|
45 |
|
46 |
+
If `true`, each document will take its own line with the description displayed alongside it.
|
47 |
+
|
48 |
+
*Note: this will use the `description` field, **not** the `caption`. Be careful when entering
|
49 |
+
your document data.*
|
50 |
+
|
51 |
+
**Orderby Option**
|
52 |
|
53 |
* `menu_order` - This is probably the one you want to use. Order by the integer fields in the Insert /
|
54 |
Upload Media Gallery dialog. Note that these fields may be blank by default. If this is the case,
|
58 |
* `author` - Order by the owner of the upload (username).
|
59 |
* `rand` - Pseudo-random order.
|
60 |
|
61 |
+
**Order Option**
|
62 |
+
|
63 |
+
This option works alongsied the `orderby` option to determine whether the documents are displayed in
|
64 |
+
ascending or decending order.
|
65 |
+
|
66 |
+
**Attachment Page Option** *(New in Version 1.1)*
|
67 |
+
|
68 |
+
This option determines whether each document icon will link to the actual file or to its attachment page.
|
69 |
+
If you want the user to be able to click on the icon and directly rective the option to download then
|
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,
|
76 |
+
but, with a little CSS knowledge, you can customize pretty much anything about how it looks. See
|
77 |
+
[`style.css`](http://plugins.svn.wordpress.org/document-gallery/trunk/style.css) for an idea of what will
|
78 |
+
select different elements within the gallery display.
|
79 |
+
|
80 |
+
**Example**
|
81 |
+
|
82 |
+
Say I would like to include a border for the right and bottom of thedocument icon, but only when descriptions
|
83 |
+
are shown (to deliniate the icon from the description text). To do this, I would need to add the following
|
84 |
+
CSS to my theme stylesheet:
|
85 |
+
|
86 |
+
`.document-icon-wrapper.descriptions .document-icon{
|
87 |
+
border-right: 1px solid #37824A;
|
88 |
+
border-bottom: 1px solid #37824A;
|
89 |
+
}`
|
90 |
+
|
91 |
+
Now, if I wanted to modify that code to instead add the same border to all of the document-icons, regardless of
|
92 |
+
whether they have a description or not, I would just change the first line, removing the descriptions class like so:
|
93 |
+
|
94 |
+
`.document-icon-wrapper .document-icon`
|
95 |
+
|
96 |
+
*NOTE: Please don't modify the plugin stylesheet directly or your changes will be lost when a new version is released.*
|
97 |
|
98 |
= Theme Developers =
|
99 |
|
108 |
|
109 |
== Changelog ==
|
110 |
|
111 |
+
= Coming (Relatively) Soon =
|
112 |
|
113 |
+
* Full integration with the new [Wordpress 3.5 Media Manager](http://codex.wordpress.org/Version_3.5#Highlights).
|
114 |
+
* Option to include player for any music or video attachments uploaded to page.
|
115 |
* Option to open documents directly within your browser (à la [Google Drive Viewer](https://drive.google.com/viewer)).
|
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.
|
122 |
+
* **Enhancement:** Added documentation for customizing the appearance of the plugin.
|
123 |
+
* **Enhancement:** Many improvements to the backend, including pretty HTML output and best practice implementation in
|
124 |
+
calls to WordPress core functions.
|
125 |
+
|
126 |
= 1.0.4 =
|
127 |
|
128 |
* **Bug Fix:** Removed extra `div` at bottom when number of documents is evenly divisible by 4. (Thanks, joero4ri!)
|
style.css
CHANGED
@@ -1,52 +1,63 @@
|
|
1 |
-
.document-icon{ text-align: center; }
|
2 |
|
3 |
-
.document-icon img{
|
4 |
border: none;
|
5 |
}
|
6 |
|
7 |
-
.document-icon a{
|
8 |
font-size: 10px;
|
9 |
line-height: 12px;
|
10 |
}
|
11 |
|
|
|
|
|
12 |
/* WITHOUT DESCRIPTION */
|
13 |
div.document-icon{
|
14 |
display: inline-block;
|
15 |
vertical-align: top;
|
16 |
-
min-height: 125px;
|
17 |
-
/*max-height: 145px;*/
|
18 |
overflow: hidden;
|
19 |
-
|
20 |
-
|
|
|
21 |
}
|
22 |
-
div
|
23 |
width: 100%;
|
24 |
padding: 0;
|
25 |
-
|
26 |
}
|
27 |
/* END WITHOUT DESCRIPTION */
|
28 |
|
29 |
/* WITH DESCRIPTION */
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
table#document-icon-wrapper,
|
34 |
-
table#document-icon-wrapper tbody,
|
35 |
-
table#document-icon-wrapper tr,
|
36 |
-
table#document-icon-wrapper p{
|
37 |
-
width: 100%;
|
38 |
padding: 0;
|
39 |
-
|
40 |
-
|
41 |
}
|
42 |
|
43 |
-
|
44 |
-
padding: 5px 4px 3px;
|
45 |
vertical-align: middle;
|
|
|
46 |
}
|
47 |
|
48 |
-
|
49 |
width: 65px;
|
50 |
height: 65px;
|
51 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
/* END WITH DESCRIPTION */
|
1 |
+
div.document-icon{ text-align: center; }
|
2 |
|
3 |
+
div.document-icon img{
|
4 |
border: none;
|
5 |
}
|
6 |
|
7 |
+
div.document-icon a{
|
8 |
font-size: 10px;
|
9 |
line-height: 12px;
|
10 |
}
|
11 |
|
12 |
+
div.document-icon{ margin: 5px 0 0; }
|
13 |
+
|
14 |
/* WITHOUT DESCRIPTION */
|
15 |
div.document-icon{
|
16 |
display: inline-block;
|
17 |
vertical-align: top;
|
|
|
|
|
18 |
overflow: hidden;
|
19 |
+
/* percents round up in some browsers, making
|
20 |
+
only 3 icons fit per line so can't use 25% */
|
21 |
+
width: 24.5%;
|
22 |
}
|
23 |
+
div.document-icon-wrapper{
|
24 |
width: 100%;
|
25 |
padding: 0;
|
26 |
+
text-align: center;
|
27 |
}
|
28 |
/* END WITHOUT DESCRIPTION */
|
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;
|
36 |
}
|
37 |
|
38 |
+
div.descriptions.document-icon-wrapper{
|
|
|
39 |
vertical-align: middle;
|
40 |
+
text-align: inherit;
|
41 |
}
|
42 |
|
43 |
+
div.descriptions.document-icon-wrapper img{
|
44 |
width: 65px;
|
45 |
height: 65px;
|
46 |
}
|
47 |
+
|
48 |
+
/* clearfix */
|
49 |
+
/* can't depend on theme having a clearfix class,
|
50 |
+
so build it into dg css */
|
51 |
+
div.descriptions.document-icon-wrapper:before,
|
52 |
+
div.descriptions.document-icon-wrapper:after{
|
53 |
+
content: "";
|
54 |
+
display: table;
|
55 |
+
}
|
56 |
+
|
57 |
+
div.descriptions.document-icon-wrapper:after{
|
58 |
+
clear: both;
|
59 |
+
}
|
60 |
+
div.descriptions.document-icon-wrapper{
|
61 |
+
zoom: 1; /* For IE 6/7 (trigger hasLayout) */
|
62 |
+
}
|
63 |
/* END WITH DESCRIPTION */
|