Embed PDF - Version 1.02

Version Description

  • Added support for gdoc shortcode for compatibility with older plugins
Download this release

Release Info

Developer pathawks
Plugin Icon wp plugin Embed PDF
Version 1.02
Comparing to
See all releases

Code changes from version 1.00 to 1.02

Files changed (2) hide show
  1. embed.php +47 -29
  2. readme.txt +15 -7
embed.php CHANGED
@@ -4,11 +4,13 @@ Plugin Name: DirtySuds - Embed PDF
4
  Plugin URI: http://dirtysuds.com
5
  Description: Embed a PDF using Google Docs Viewer
6
  Author: Pat Hawks
7
- Version: 1.00.20110224
8
  Author URI: http://www.pathawks.com
9
 
10
  Updates:
11
- 1.00.20110224 - First Version
 
 
12
 
13
  Copyright 2011 Pat Hawks (email : pat@pathawks.com)
14
 
@@ -27,41 +29,57 @@ Updates:
27
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28
  */
29
 
30
- wp_embed_register_handler( 'pdf', '#(^http.+\.pdf$)#i', 'wp_embed_handler_pdf' );
 
 
31
 
32
- function wp_embed_handler_pdf( $matches, $attr, $url, $rawattr ) {
 
 
 
 
 
 
 
 
 
33
 
34
- $width = get_option('embed_size_w');
35
- $height = round($width * 1.32);
36
- if ($height > get_option('embed_size_h')) {
37
- $height = get_option('embed_size_h');
38
- }
39
-
40
- if ($attr['height']) {
41
- $height = $attr['height'];
42
- }
43
 
44
- if ($attr['width']) {
45
- $width = $attr['width'];
 
 
 
 
 
 
 
 
 
46
  }
47
-
48
- if ($attr['height'] && !$attr['width']) {
49
- $width = round($height / 1.32);
 
50
  }
51
-
52
- if ($attr['width'] && !$attr['height']) {
53
- $height = round($width * 1.32);
54
  }
55
-
56
- if ($height > get_option('embed_size_h') && !$attr['height']) {
57
- $height = get_option('embed_size_h');
58
  }
59
-
60
- if ($width > get_option('embed_size_w') && !$attr['width']) {
61
- $width = get_option('embed_size_w');
62
  }
63
-
64
- $embed = '<iframe src="http://docs.google.com/viewer?url='.urlencode($url).'&amp;embedded=true" style="height:'.$height.'px;width:'.$width.'px;margin:0;border:0;"></iframe>';
65
 
66
  return apply_filters( 'embed_pdf', $embed, $matches, $attr, $url, $rawattr );
 
 
 
 
 
 
 
67
  }
4
  Plugin URI: http://dirtysuds.com
5
  Description: Embed a PDF using Google Docs Viewer
6
  Author: Pat Hawks
7
+ Version: 1.02
8
  Author URI: http://www.pathawks.com
9
 
10
  Updates:
11
+ 1.02 20110315 - Added support for `gdoc` shortcode
12
+ 1.01 20110303 - Added support for class and ID attributes
13
+ 1.00 20110224 - First Version
14
 
15
  Copyright 2011 Pat Hawks (email : pat@pathawks.com)
16
 
29
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30
  */
31
 
32
+ wp_embed_register_handler( 'pdf', '#(^(http|wpurl)\:\/\/.+\.pdf$)#i', 'dirtysuds_embed_pdf' );
33
+ add_shortcode( 'gdoc', 'dirtysuds_embed_pdf' );
34
+ add_filter('plugin_row_meta', 'dirtysuds_embed_pdf_rate',10,2);
35
 
36
+ function dirtysuds_embed_pdf( $matches, $atts, $url, $rawattr=null ) {
37
+ extract( shortcode_atts( array(
38
+ 'height' => get_option('embed_size_h'),
39
+ 'width' => get_option('embed_size_w'),
40
+ 'border' => '',
41
+ 'style' => '',
42
+ 'title' => '',
43
+ 'class' => 'pdf',
44
+ 'id' => '',
45
+ ), $atts ) );
46
 
47
+ $url = str_replace('wpurl://',get_bloginfo('wpurl').'/',$url);
 
 
 
 
 
 
 
 
48
 
49
+ if (!strstr($url,'http://') && strstr($atts,'http://')) {
50
+ $url = $atts;
51
+ extract( shortcode_atts( array(
52
+ 'height' => get_option('embed_size_h'),
53
+ 'width' => get_option('embed_size_w'),
54
+ 'border' => '',
55
+ 'style' => '',
56
+ 'title' => '',
57
+ 'class' => 'pdf',
58
+ 'id' => '',
59
+ ), $matches ) );
60
  }
61
+
62
+ $embed = '<iframe src="http://docs.google.com/viewer?url='.urlencode($url).'&amp;embedded=true" style="height:'.$height.'px;width:'.$width.'px;" class="'.$class.'"';
63
+ if ($id) {
64
+ $embed .= ' id="'.$id.'"';
65
  }
66
+ if ($border) {
67
+ $embed .= ' frameborder="'.$border.'"';
 
68
  }
69
+ if ($style) {
70
+ $embed .= ' style="'.$style.'"';
 
71
  }
72
+ if ($title) {
73
+ $embed .= ' title="'.$title.'"';
 
74
  }
75
+ $embed .= '></iframe>';
 
76
 
77
  return apply_filters( 'embed_pdf', $embed, $matches, $attr, $url, $rawattr );
78
+ }
79
+
80
+ function dirtysuds_embed_pdf_rate($links,$file) {
81
+ if (plugin_basename(__FILE__) == $file) {
82
+ $links[] = '<a href="http://wordpress.org/extend/plugins/dirtysuds-embed-pdf/">Rate this plugin</a>';
83
+ }
84
+ return $links;
85
  }
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
- === DirtySuds - Embed PDF ===
2
- Contributors: pathawks
3
  Donate link: http://www.pathawks.com/p/wordpress-plugins.html
4
- Tags: plugins, wordpress, embed, eombed, pdf, google, Google Docs
5
- Requires at least: 3.0
6
  Tested up to: 3.1
7
- Stable tag: trunk
8
 
9
  Adds pseudo oembed support for PDF documents
10
 
@@ -14,9 +14,11 @@ Will embed a PDF file using Google Docs Viewer
14
  Simply include the URL for a PDF document on it's own line, or wrapped in the embed tag like `[embed]http://example.com/file.pdf[/embed]` and the plugin will embed the PDF into the page using the Google Docs Viewer embed code.
15
  The url must end with `.pdf`
16
 
 
 
17
  == Installation ==
18
 
19
- 1. Upload 'dirtysuds-embed--pdf' to the '/wp-content/plugins/' directory
20
  2. Activate **DirtySuds - Embed PDF** through the 'Plugins' menu in WordPress
21
  3. That's it. Now when you embed a PDF using the Wordpress `[embed]` shortcode, the plugin will embed the document using the Google Docs viewer
22
 
@@ -26,11 +28,17 @@ The url must end with `.pdf`
26
  = I have an idea for a great way to improve this plugin =
27
 
28
  Great! I'd love to hear from you.
29
- postlist@pathawks.com
30
 
31
 
32
  == Changelog ==
33
 
 
 
 
 
 
 
34
  = 1.00 =
35
  * First version
36
  * Works
1
+ === Embed PDF ===
2
+ Contributors: dirtysuds, pathawks
3
  Donate link: http://www.pathawks.com/p/wordpress-plugins.html
4
+ Tags: plugins, wordpress, embed, eombed, pdf, google, Google Docs, shortcode
5
+ Requires at least: 2.9
6
  Tested up to: 3.1
7
+ Stable tag: 1.02
8
 
9
  Adds pseudo oembed support for PDF documents
10
 
14
  Simply include the URL for a PDF document on it's own line, or wrapped in the embed tag like `[embed]http://example.com/file.pdf[/embed]` and the plugin will embed the PDF into the page using the Google Docs Viewer embed code.
15
  The url must end with `.pdf`
16
 
17
+ Supported attributes in the embed tag are `class` `id` `title` `height` and `width`
18
+
19
  == Installation ==
20
 
21
+ 1. Upload `dirtysuds-embed-pdf` to the `/wp-content/plugins/` directory
22
  2. Activate **DirtySuds - Embed PDF** through the 'Plugins' menu in WordPress
23
  3. That's it. Now when you embed a PDF using the Wordpress `[embed]` shortcode, the plugin will embed the document using the Google Docs viewer
24
 
28
  = I have an idea for a great way to improve this plugin =
29
 
30
  Great! I'd love to hear from you.
31
+ embedPDF@pathawks.com
32
 
33
 
34
  == Changelog ==
35
 
36
+ = 1.02 =
37
+ * Added support for `gdoc` shortcode for compatibility with older plugins
38
+
39
+ = 1.01 =
40
+ * Added support for `class` and `id` attributes (Thanks, _Robert_)
41
+
42
  = 1.00 =
43
  * First version
44
  * Works