Permalink
Browse files

Starting git repo

  • Loading branch information...
Dougal Campbell
Dougal Campbell committed Sep 9, 2012
0 parents commit dce4fdb1139f463f14b20a8d435550bff07d1eea
@@ -0,0 +1,63 @@
+/* Document styles for the documents-shortcode plugin: */
+ul.dc_documents li {
+ line-height: 32px;
+ list-style: none;
+ display: block;
+}
+
+ul.dc_documents li a {
+ background-position: top left;
+ line-height: 32px;
+ background-repeat: no-repeat;
+ display: inline-block;
+ padding-left: 36px;
+ text-decoration: none;
+}
+
+ul.dc_documents li a:hover {
+ text-decoration: underline;
+}
+
+ul.dc_documents {
+ list-style: none;
+ list-style-type: none;
+}
+
+ul.dc_documents li a {
+ background-image: url(images/page_white_text.png);
+}
+
+ul.dc_documents li.pdf a {
+ background-image: url(images/page_white_acrobat.png);
+}
+
+ul.dc_documents li.doc a,
+ul.dc_documents li.docx a {
+ background-image: url(images/page_white_word.png);
+}
+
+ul.dc_documents li.xls a,
+ul.dc_documents li.xlsx a {
+ background-image: url(images/page_white_excel.png);
+}
+
+ul.dc_documents li.ppt a,
+ul.dc_documents li.pptx a {
+ background-image: url(images/page_white_powerpoint.png);
+}
+
+ul.dc_documents li.vsd a,
+ul.dc_documents li.vsdx a {
+ background-image: url(images/page_white_vector.png);
+}
+
+ul.dc_documents li.mdb a,
+ul.dc_documents li.mdbx a {
+ background-image: url(images/page_white_database.png);
+}
+
+ul.dc_documents li.zip a {
+ background-image: url(images/page_white_zip.png);
+}
+
+
@@ -0,0 +1,96 @@
+<?php
+/*
+Plugin Name: Document Shortcode
+Plugin URI: http://dougal.gunters.org/
+Description: Shortcode to display a list of attached documents, optionally filtered by mime-type and/or file extension.
+Author: Dougal Campbell
+Version: 1.0
+Min WP Version: 2.5
+Author URI: http://dougal.gunters.org/
+*/
+
+/**
+ * The default mimetype match is for "application/*". For other types, you
+ * will need to specifically override that attribute.
+ * Examples:
+ *
+ * Just .XLS files:
+ * [documents ext="xls"]
+ *
+ * All .DOC, .DOCX, or .PDF files:
+ * [documents ext="doc,docx,pdf"]
+ *
+ * Only 'video' types with a .MOV extension:
+ * [documents mimetype="video" ext="mov"]
+ *
+ * Just application/pdf mimetypes:
+ * [documents mimetype="application/pdf"]
+ */
+function dc_document_shortcode($atts) {
+ extract(shortcode_atts(array(
+ 'mimetype' => 'application',
+ 'ext' => null,
+ ), $atts));
+
+ $mime = "&post_mime_type=$mimetype";
+
+ $kids =& get_children( 'post_type=attachment&post_parent=' . get_the_id() . $mime );
+
+ if ( empty( $kids ) ) {
+ return '';
+ }
+
+ $exts = array();
+
+ if ( $ext ) {
+ $exts = explode(',', $ext);
+ $exts = array_map('trim', $exts);
+ $exts = array_map('strtolower', $exts);
+ }
+
+ $documents = '';
+
+ foreach ( $kids as $id => $doc ) {
+ $url = wp_get_attachment_url( $id );
+
+ $file = get_attached_file( $id );
+ $filetype = wp_check_filetype( $file );
+ $file_ext = strtolower($filetype['ext']);
+
+ if ( count($exts) && ! in_array($file_ext, $exts) ) {
+ // Not in list of requested extensions. Skip it!
+ continue;
+ }
+
+ $name = $doc->post_title;
+ $mime = sanitize_title_with_dashes( $file_ext );
+ $documents .= "<li class='$mime'><a href='$url'>$name</a></li>\n";
+ }
+
+ if (! empty( $documents ) ) {
+ // Wrap it up:
+ $documents = "<ul class='dc_documents'>\n" . $documents;
+ $documents .= "</ul>\n";
+ }
+
+ return $documents;
+}
+
+function dc_document_shortcode_init() {
+ add_shortcode( 'documents', 'dc_document_shortcode' );
+}
+
+add_action( 'init', 'dc_document_shortcode_init' );
+
+/**
+ * Register and enqueue the default styles
+ */
+function dc_document_shortcode_add_style() {
+ // Don't need plugin styles in dashboard
+ if ( is_admin() ) return;
+
+ wp_register_style( 'dc_document_shortcode' , plugins_url( 'dc_documents.css', __FILE__ ) );
+ wp_enqueue_style( 'dc_document_shortcode' );
+}
+
+add_action('wp_enqueue_scripts', 'dc_document_shortcode_add_style');
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,52 @@
+=== Documents Shortcode ===
+
+Contributors: dougal
+Donate link: http://dougal.gunters.org/donate
+Tags:
+License: GPL2
+Requires at least: 2.5
+Tested up to: 3.0
+Stable tag: 1.0
+
+
+== Description ==
+
+By adding a simple [documents] shortcode in your post or page, you get a
+list of all documents (non-image/audio/video) attached. Each item in the
+document list can be styled with CSS to indicate different document types
+(e.g., .doc, .pdf, etc).
+
+== Installation ==
+
+Copy the documents-shortcode folder and its contents to your wp-content/plugins
+directory, then activate the plugin.
+
+== Frequently Asked Questions ==
+
+= How can I limit which attachments are listed? =
+
+There are two attributes you can use with the shortcode to control which
+attached documents are listed: `mimetype` and `ext`.
+
+The default mimetype match is for mimetype "application/*". For other types,
+you will need to specifically override that attribute.
+
+Examples:
+
+ Just .XLS files:
+ [documents ext="xls"]
+
+ All .DOC, .DOCX, or .PDF files:
+ [documents ext="doc,docx,pdf"]
+
+ Only 'video' types with a .MOV extension:
+ [documents mimetype="video" ext="mov"]
+
+ Just application/pdf mimetypes:
+ [documents mimetype="application/pdf"]
+
+
+== Changelog ==
+= 1.0 =
+* Initial release. 2012-09-10
+

0 comments on commit dce4fdb

Please sign in to comment.