44Plugin Name: ViewerJS Plugin
55Version: @VIEWERJS_VERSION@
66Plugin URI: http://viewerjs.org/
7- Description: Embed ODF and PDF in Wordpress
7+ Description: Embed ODF and PDF in WordPress
88Author: Tobias Hintze
99Author URI: http://kogmbh.com
1010
11- This Wordpress plugin is free software: you can redistribute it
11+ This WordPress plugin is free software: you can redistribute it
1212and/or modify it under the terms of the GNU Affero General Public License
1313(GNU AGPL) as published by the Free Software Foundation, either version 3 of
1414the License, or (at your option) any later version. The code is distributed
@@ -23,15 +23,13 @@ through which recipients can access the Corresponding Source.
2323
2424*/
2525
26- $site_url = site_url();
27- $this_plugin_url = plugins_url() .'/'. plugin_basename(dirname(__FILE__));
26+ $viewerjs_plugin_url = plugins_url() .'/'. plugin_basename(dirname(__FILE__));
2827
2928function ViewerJS_PluginAddPage() {
3029 add_options_page('ViewerJS-Plugin Options', 'ViewerJS-Plugin', '8', 'viewerjs-plugin.php', 'ViewerJS_PluginOptions');
3130}
3231
3332function ViewerJS_PluginOptions() {
34- global $site_url;
3533 $message = '';
3634 $options = get_option('ViewerJS_PluginSettings');
3735 if ($_POST) {
@@ -98,7 +96,7 @@ function viewerjs_mime_type_filter($mime_types) {
9896}
9997add_filter( 'upload_mimes', 'viewerjs_mime_type_filter');
10098
101- function mime_type_icon ($icon_uri, $mime_type, $post_id) {
99+ function viewerjs_mime_type_icon ($icon_uri, $mime_type, $post_id) {
102100 // this is bogus and not implemented
103101 if ($mime_type === 'application/vnd.oasis.opendocument.text') {
104102 return $icon_uri;
@@ -109,95 +107,32 @@ function mime_type_icon($icon_uri, $mime_type, $post_id) {
109107 } else {
110108 return $icon_uri;
111109 }
112- // return array($this_plugin_url . '/odf.png', 64, 64);
110+ // return array($viewerjs_plugin_url . '/odf.png', 64, 64);
113111}
114- add_filter( 'wp_mime_type_icon', 'mime_type_icon ', 10, 3);
112+ add_filter( 'wp_mime_type_icon', 'viewerjs_mime_type_icon ', 10, 3);
115113
116114function viewerjs_media_send_to_editor($html, $send_id, $attachment) {
117115 $pid = $attachment['id'];
118116
119117 $post = get_post($pid, ARRAY_A);
120- if (preg_match('/^application\/vnd\.oasis\.opendocument/', $post['post_mime_type'])) {
118+ if (preg_match('/^application\/( vnd\.oasis\.opendocument|pdf) /', $post['post_mime_type'])) {
121119 // place shortcode
122120 preg_match('/^http:\/\/[^\/]*(\/.*)$/', $attachment['url'], $matches);
123121 $document_url = $matches[1];
124- return "[viewerjs_viewer ".$document_url."]";
122+ return "[viewerjs ".$document_url."]";
125123 }
126124 return $html;
127125}
128126add_filter( 'media_send_to_editor', 'viewerjs_media_send_to_editor', 10, 3);
129127
130128
131- /*
132- TODO: introduce a smart switch on [post | attachment] scope
133- to skip viewerjs-embedding... (user might to simply link
134- some documents)
135- For now: always use webodf for embedding, if this plugin
136- is enabled.
137-
138- function field_filter($fields, $post_object) {
139- if ($post_object->post_parent > 0) {
140- // inside a post
141- $use_webodf = get_post_meta($post_object['post_parent'], 'use_webodf');
142- }
143-
144- if (preg_match('/^application\/vnd\.oasis\.opendocument\.(text|presentation|spreadsheet)/',
145- $post_object->post_mime_type)) {
146-
147- // insert document path
148- preg_match('/^http:\/\/[^\/]*(\/.*)$/', $post_object->guid, $matches);
149- $fields["viewerjs_document_url"] = array(
150- "label" => __("Document URL"),
151- "input" => "text",
152- "value" => $matches[1]
153- );
154- $fields["viewerjs_embed"] = array(
155- "input" => "html",
156- "label" => "Embed with WebODF",
157- "html" => '<label for="attachments-'.$post_object->ID.'-viewerjs_embed"> '.
158- '<input type="checkbox" id="attachments-"'.$post_object->ID.'-viewerjs_embed" '.
159- ' name="attachments['.$post_object->ID.'][viewerjs_embed]" value="1" checked="checked"/>Use WebODF?</label>'
160- );
161- }
162- return $fields;
163- }
164- add_filter('attachment_fields_to_edit', 'field_filter', 10, 2);
165-
166- function field_save_legacy( $post, $attachment ) {
167- $postid = $post['post_ID'];
168- if (! $postid) $postid = $post['ID'];
169- return field_save($postid);
170- }
171-
172- function field_save( $post ) {
173- $postid = $post;
174-
175- if (! empty($_POST['attachments'])) {
176- if ($_POST['attachments'][$postid]['viewerjs_embed']) {
177- update_post_meta($postid, 'viewerjs_embed', "yes");
178- } else {
179- update_post_meta($postid, 'viewerjs_embed', "no");
180- }
181- }
182- return $post;
183- }
184-
185- // legacy (wp < 3.5.1):
186- add_filter('attachment_fields_to_save', 'field_save_legacy', 10, 2);
187-
188- // recent:
189- add_filter('add_attachment', 'field_save', 10, 1);
190- add_filter('edit_attachment', 'field_save', 10, 1);
191-
192- */
193-
194129function viewerjs_shortcode_handler($args) {
195- global $this_plugin_url ;
130+ global $viewerjs_plugin_url ;
196131 $document_url = $args[0];
197132 $options = get_option('ViewerJS_PluginSettings');
198133 $iframe_width = $options['width'];
199134 $iframe_height = $options['height'];
200- return "<iframe src=\"$this_plugin_url " .
135+ return "<iframe src=\"$viewerjs_plugin_url " .
201136 '#' . $document_url .'" '.
202137 "width=\"$iframe_width\" ".
203138 "height=\"$iframe_height\" ".
0 commit comments