Version Description
- Added options page.
Download this release
Release Info
Developer | k3davis |
Plugin | Google Doc Embedder |
Version | 1.0 |
Comparing to | |
See all releases |
Code changes from version 0.3 to 1.0
- gviewer.php +65 -9
- options.php +73 -0
- readme.txt +9 -3
- screenshot-2.png +0 -0
- uninstall.php +11 -0
- wpframe.php +51 -0
gviewer.php
CHANGED
@@ -5,17 +5,38 @@ Plugin Name: Google Doc Embedder
|
|
5 |
Plugin URI: http://wordpress.org/extend/plugins/google-document-embedder/
|
6 |
Description: Lets you embed PDF files and PowerPoint presentations in a page or post using the Google Document Viewer.
|
7 |
Author: Kevin Davis
|
8 |
-
Version: 0
|
9 |
-
Author URI: http://www.davismetro.com/
|
10 |
*/
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
function gviewer_func($atts) {
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
extract(shortcode_atts(array(
|
15 |
'file' => '',
|
16 |
-
'save' =>
|
17 |
-
'width' =>
|
18 |
-
'height' =>
|
19 |
), $atts));
|
20 |
|
21 |
// supported file types - list acceptable extensions separated by |
|
@@ -23,9 +44,9 @@ function gviewer_func($atts) {
|
|
23 |
|
24 |
// check link for validity
|
25 |
if (!validLink($file)){
|
26 |
-
$code = "\n<!--
|
27 |
} elseif (!validType($file,$exts)) {
|
28 |
-
$code = "\n<!--
|
29 |
} else {
|
30 |
|
31 |
$code=<<<HERE
|
@@ -36,7 +57,7 @@ HERE;
|
|
36 |
$code = str_replace("%W%", $width, $code);
|
37 |
$code = str_replace("%H%", $height, $code);
|
38 |
if ($save == "1") {
|
39 |
-
$code .= "<p><a href=\"$file\" target=\"_blank\"
|
40 |
}
|
41 |
|
42 |
}
|
@@ -64,6 +85,41 @@ function validType($link, $exts) {
|
|
64 |
}
|
65 |
}
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
add_shortcode('gview', 'gviewer_func');
|
68 |
|
69 |
?>
|
5 |
Plugin URI: http://wordpress.org/extend/plugins/google-document-embedder/
|
6 |
Description: Lets you embed PDF files and PowerPoint presentations in a page or post using the Google Document Viewer.
|
7 |
Author: Kevin Davis
|
8 |
+
Version: 1.0
|
|
|
9 |
*/
|
10 |
|
11 |
+
/* Copyright 2009 Kevin Davis. E-mail: kev@tnw.org
|
12 |
+
This program is free software; you can redistribute it and/or modify
|
13 |
+
it under the terms of the GNU General Public License as published by
|
14 |
+
the Free Software Foundation; either version 2 of the License, or
|
15 |
+
(at your option) any later version.
|
16 |
+
|
17 |
+
This program is distributed in the hope that it will be useful,
|
18 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
20 |
+
GNU General Public License for more details.
|
21 |
+
|
22 |
+
You should have received a copy of the GNU General Public License
|
23 |
+
along with this program; if not, write to the Free Software
|
24 |
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
25 |
+
*/
|
26 |
+
|
27 |
+
// usage: [gview file="http://path.to/file.pdf" save="1" width="600" height="500"]
|
28 |
function gviewer_func($atts) {
|
29 |
+
|
30 |
+
// defaults
|
31 |
+
$dl = get_option('gde_show_dl');
|
32 |
+
$wd = get_option('gde_default_width');
|
33 |
+
$ht = get_option('gde_default_height');
|
34 |
+
$txt = get_option('gde_link_text');
|
35 |
extract(shortcode_atts(array(
|
36 |
'file' => '',
|
37 |
+
'save' => $dl,
|
38 |
+
'width' => $wd,
|
39 |
+
'height' => $ht
|
40 |
), $atts));
|
41 |
|
42 |
// supported file types - list acceptable extensions separated by |
|
44 |
|
45 |
// check link for validity
|
46 |
if (!validLink($file)){
|
47 |
+
$code = "\n<!-- GDE EMBED ERROR: invalid URL, please use fully qualified URL -->\n";
|
48 |
} elseif (!validType($file,$exts)) {
|
49 |
+
$code = "\n<!-- GDE EMBED ERROR: unsupported file type -->\n";
|
50 |
} else {
|
51 |
|
52 |
$code=<<<HERE
|
57 |
$code = str_replace("%W%", $width, $code);
|
58 |
$code = str_replace("%H%", $height, $code);
|
59 |
if ($save == "1") {
|
60 |
+
$code .= "<p class=\"gde-dl\"><a href=\"$file\" target=\"_blank\">$txt</a></p>";
|
61 |
}
|
62 |
|
63 |
}
|
85 |
}
|
86 |
}
|
87 |
|
88 |
+
// activate plugin
|
89 |
+
register_activation_hook( __FILE__, 'gde_activate');
|
90 |
+
function gde_activate() {
|
91 |
+
global $wpdb;
|
92 |
+
|
93 |
+
// initial options
|
94 |
+
add_option('gde_default_width', '600');
|
95 |
+
add_option('gde_default_height', '500');
|
96 |
+
add_option('gde_show_dl', 1);
|
97 |
+
add_option('gde_link_text', 'download file');
|
98 |
+
}
|
99 |
+
|
100 |
+
// add an option page
|
101 |
+
add_action('admin_menu', 'gde_option_page');
|
102 |
+
function gde_option_page() {
|
103 |
+
add_options_page(t('GDE Settings'), t('GDE Settings'), 'administrator', basename(__FILE__), 'gde_options');
|
104 |
+
}
|
105 |
+
function gde_options() {
|
106 |
+
if ( function_exists('current_user_can') && !current_user_can('manage_options') ) die(t('Cheatin’ uh?'));
|
107 |
+
if (! user_can_access_admin_page()) wp_die( t('You do not have sufficient permissions to access this page') );
|
108 |
+
|
109 |
+
require(ABSPATH. '/wp-content/plugins/google-document-embedder/options.php');
|
110 |
+
}
|
111 |
+
|
112 |
+
// add additional settings link, for convenience
|
113 |
+
$plugin = plugin_basename(__FILE__);
|
114 |
+
function my_plugin_actlinks( $links ) {
|
115 |
+
// Add a link to this plugin's settings page
|
116 |
+
$settings_link = '<a href="/wp-admin/options-general.php?page=gviewer.php">Settings</a>';
|
117 |
+
array_unshift( $links, $settings_link );
|
118 |
+
return $links;
|
119 |
+
}
|
120 |
+
add_filter("plugin_action_links_$plugin", 'my_plugin_actlinks' );
|
121 |
+
|
122 |
+
// activate shortcode
|
123 |
add_shortcode('gview', 'gviewer_func');
|
124 |
|
125 |
?>
|
options.php
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
include('wpframe.php');
|
3 |
+
|
4 |
+
if(isset($_REQUEST['submit']) and $_REQUEST['submit']) {
|
5 |
+
if(isset($_POST['gde_show_dl'])) {
|
6 |
+
update_option('gde_show_dl', 1);
|
7 |
+
} else {
|
8 |
+
update_option('gde_show_dl', 0);
|
9 |
+
}
|
10 |
+
if(isset($_POST['gde_default_width'])) {
|
11 |
+
update_option('gde_default_width', sanitizeOpt($_POST['gde_default_width']));
|
12 |
+
}
|
13 |
+
if(isset($_POST['gde_default_height'])) {
|
14 |
+
update_option('gde_default_height', sanitizeOpt($_POST['gde_default_height']));
|
15 |
+
}
|
16 |
+
if(isset($_POST['gde_link_text'])) update_option('gde_link_text', $_POST['gde_link_text']);
|
17 |
+
showMessage("Options updated");
|
18 |
+
}
|
19 |
+
?>
|
20 |
+
<div class="wrap">
|
21 |
+
<h2>Google Doc Embedder Settings</h2>
|
22 |
+
|
23 |
+
<form action="" method="post">
|
24 |
+
<?php wp_nonce_field('update-options'); ?>
|
25 |
+
|
26 |
+
<table class="form-table">
|
27 |
+
<tr valign="top">
|
28 |
+
<td colspan="2"><strong>Global Viewer Size</strong><br/>
|
29 |
+
<em>To override on individual posts, manually set height= and width= in the post shortcode.</td>
|
30 |
+
</tr>
|
31 |
+
<tr valign="top">
|
32 |
+
<th scope="row">Default Width</th>
|
33 |
+
<td><input type="text" size="5" name="gde_default_width" value="<?php echo get_option('gde_default_width'); ?>" /> px</td>
|
34 |
+
</tr>
|
35 |
+
<tr valign="top">
|
36 |
+
<th scope="row">Default Height</th>
|
37 |
+
<td><input type="text" size="5" name="gde_default_height" value="<?php echo get_option('gde_default_height'); ?>" /> px</td>
|
38 |
+
</tr>
|
39 |
+
<tr valign="top">
|
40 |
+
<td colspan="2"><strong>Download Link Options</strong><br/>
|
41 |
+
<em>To override the display setting on an individual post, use the save= attribute.</em></td>
|
42 |
+
</tr>
|
43 |
+
<tr valign="top">
|
44 |
+
<td colspan="2"><?php showOption('gde_show_dl', t('Show the download link by default')); ?></td>
|
45 |
+
</tr>
|
46 |
+
<tr valign="top">
|
47 |
+
<th scope="row">Link Text</th>
|
48 |
+
<td><input type="text" name="gde_link_text" value="<?php echo get_option('gde_link_text'); ?>" /></td>
|
49 |
+
</tr>
|
50 |
+
</table>
|
51 |
+
<p class="submit">
|
52 |
+
<input type="hidden" id="user-id" name="user_ID" value="<?php echo (int) $user_ID ?>" />
|
53 |
+
<span id="autosave"></span>
|
54 |
+
<input type="submit" name="submit" value="<?php e('Save Options') ?>" style="font-weight: bold;" />
|
55 |
+
</p>
|
56 |
+
|
57 |
+
</form>
|
58 |
+
|
59 |
+
</div>
|
60 |
+
|
61 |
+
<?php
|
62 |
+
function showOption($option, $title) {
|
63 |
+
?>
|
64 |
+
<input type="checkbox" name="<?php echo $option; ?>" value="1" id="<?php echo $option?>" <?php if(get_option($option)) print " checked='checked'"; ?> />
|
65 |
+
<label for="<?php echo $option?>"><?php e($title) ?></label><br />
|
66 |
+
|
67 |
+
<?php
|
68 |
+
}
|
69 |
+
|
70 |
+
function sanitizeOpt($value) {
|
71 |
+
$value = ereg_replace('[^0-9]+', '', $value);
|
72 |
+
return $value;
|
73 |
+
}
|
readme.txt
CHANGED
@@ -11,7 +11,7 @@ Lets you embed PDF files and PowerPoint presentations in a web page using the Go
|
|
11 |
|
12 |
Google Doc Embedder lets you embed PDF files and PowerPoint presentations in a web page using the Google Document Viewer.
|
13 |
|
14 |
-
Similar to services like
|
15 |
|
16 |
Note: This plugin utilizes an undocumented feature of the Google Document viewer, and as such it may be subject to hazards if their viewer unexpectedly changes drastically. In this unlikely event, the plugin should degrade nicely and not break your site.
|
17 |
|
@@ -21,7 +21,9 @@ Note: This plugin utilizes an undocumented feature of the Google Document viewer
|
|
21 |
2. Activate the plugin through the 'Plugins' menu in WordPress.
|
22 |
3. Done.
|
23 |
|
24 |
-
For basic usage, please see the
|
|
|
|
|
25 |
|
26 |
== Frequently Asked Questions ==
|
27 |
|
@@ -46,11 +48,15 @@ View the source on the web page where you've embedded the viewer. In order to de
|
|
46 |
== Screenshots ==
|
47 |
|
48 |
1. Appearance of embedded viewer (blank file)
|
|
|
49 |
|
50 |
== Changelog ==
|
51 |
|
|
|
|
|
|
|
52 |
= 0.3 =
|
53 |
-
* Error checking added
|
54 |
|
55 |
= 0.2 =
|
56 |
* Initial beta release. Fully functional, but no niceties...
|
11 |
|
12 |
Google Doc Embedder lets you embed PDF files and PowerPoint presentations in a web page using the Google Document Viewer.
|
13 |
|
14 |
+
Similar to services like Scribd, Google Doc Embedder will allow you to embed a PDF or PPT (PowerPoint) file directly into your page or post, not requiring the user to have Adobe Reader or PowerPoint installed to view the contents. Unlike Scribd, the files do not need to be uploaded to any service first - including Google Documents - but can exist anywhere accessible on your site or the internet.
|
15 |
|
16 |
Note: This plugin utilizes an undocumented feature of the Google Document viewer, and as such it may be subject to hazards if their viewer unexpectedly changes drastically. In this unlikely event, the plugin should degrade nicely and not break your site.
|
17 |
|
21 |
2. Activate the plugin through the 'Plugins' menu in WordPress.
|
22 |
3. Done.
|
23 |
|
24 |
+
For basic usage, please see the FAQ.
|
25 |
+
|
26 |
+
Go to "GDE Settings" (under "Settings") in the admin panel to change defaults, or override individually using the shortcode syntax in the FAQ.
|
27 |
|
28 |
== Frequently Asked Questions ==
|
29 |
|
48 |
== Screenshots ==
|
49 |
|
50 |
1. Appearance of embedded viewer (blank file)
|
51 |
+
2. Settings page
|
52 |
|
53 |
== Changelog ==
|
54 |
|
55 |
+
= 1.0 =
|
56 |
+
* Added options page.
|
57 |
+
|
58 |
= 0.3 =
|
59 |
+
* Error checking added.
|
60 |
|
61 |
= 0.2 =
|
62 |
* Initial beta release. Fully functional, but no niceties...
|
screenshot-2.png
ADDED
Binary file
|
uninstall.php
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
// perform cleanup, be a good citizen
|
4 |
+
|
5 |
+
$options = array('gde_default_width','gde_default_height','gde_show_dl','gde_link_text');
|
6 |
+
|
7 |
+
foreach ($options as $opt) {
|
8 |
+
delete_option($opt);
|
9 |
+
}
|
10 |
+
|
11 |
+
?>
|
wpframe.php
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WPFrame
|
4 |
+
* A simple framework to make WP Plugin development easier.
|
5 |
+
*/
|
6 |
+
|
7 |
+
$GLOBALS['wpframe_home'] = get_option('home');
|
8 |
+
$GLOBALS['wpframe_wordpress'] = $GLOBALS['wpframe_siteurl'] = get_option('siteurl');
|
9 |
+
if(!$GLOBALS['wpframe_wordpress']) $GLOBALS['wpframe_wordpress'] = $GLOBALS['wpframe_home'];
|
10 |
+
$GLOBALS['wpframe_plugin_name'] = basename(dirname(__FILE__));
|
11 |
+
$GLOBALS['wpframe_plugin_folder'] = $GLOBALS['wpframe_siteurl'] . '/wp-content/plugins/' . $GLOBALS['wpframe_plugin_name'];
|
12 |
+
//$GLOBALS['wpframe_plugin_data'] = get_plugin_data($GLOBALS['wpframe_plugin_name'] . '.php');
|
13 |
+
//* :DEBUG: */ $GLOBALS['wpdb']->show_errors();
|
14 |
+
|
15 |
+
if(!function_exists('stopDirectCall')) { //Make sure multiple plugins can be created using WPFrame
|
16 |
+
|
17 |
+
/// Need to register a page to use it in a plugin in WP2.8.1+. THIS IS A HACK.
|
18 |
+
function wpf_register_pages($pages, $folder) {
|
19 |
+
foreach($pages as $p) wpf_register_page($folder . DIRECTORY_SEPARATOR . $p);
|
20 |
+
}
|
21 |
+
function wpf_register_page($file) {
|
22 |
+
global $_registered_pages;
|
23 |
+
$hookname = get_plugin_page_hookname($file, '' );
|
24 |
+
$_registered_pages[$hookname] = true;
|
25 |
+
}
|
26 |
+
|
27 |
+
/// Make sure that the user don't call this file directly - forces the use of the WP interface
|
28 |
+
function stopDirectCall($file) {
|
29 |
+
if(preg_match('#' . basename($file) . '#', $_SERVER['PHP_SELF'])) die('Don\'t call this page directly.'); // Stop direct call
|
30 |
+
}
|
31 |
+
|
32 |
+
/// Shows a message in the admin interface of Wordpress
|
33 |
+
function showMessage($message, $type='updated') {
|
34 |
+
if($type == 'updated') $class = 'updated fade';
|
35 |
+
elseif($type == 'error') $class = 'updated error';
|
36 |
+
else $class = $type;
|
37 |
+
|
38 |
+
print '<div id="message" class="'.$class.'"><p>' . __($message, $GLOBALS['wpframe_plugin_name']) . '</p></div>';
|
39 |
+
}
|
40 |
+
|
41 |
+
/// Globalization function - Returns the transilated string
|
42 |
+
function t($message) {
|
43 |
+
return __($message, $GLOBALS['wpframe_plugin_name']);
|
44 |
+
}
|
45 |
+
|
46 |
+
/// Globalization function - prints the transilated string
|
47 |
+
function e($message) {
|
48 |
+
_e($message, $GLOBALS['wpframe_plugin_name']);
|
49 |
+
}
|
50 |
+
|
51 |
+
}
|