11<?php
22
33/*
4- Plugin Name: WebODF Viewer
5- Version: @WEBODF_VERSION @
6- Plugin URI: http://webodf .org/
7- Description: Embed ODF in Wordpress
4+ Plugin Name: ViewerJS Plugin
5+ Version: @VIEWERJS_VERSION @
6+ Plugin URI: http://viewerjs .org/
7+ Description: Embed ODF and PDF in Wordpress
88Author: Tobias Hintze
99Author URI: http://kogmbh.com
1010
@@ -26,14 +26,14 @@ through which recipients can access the Corresponding Source.
2626$site_url = site_url();
2727$this_plugin_url = plugins_url() .'/'. plugin_basename(dirname(__FILE__));
2828
29- function WebODF_ViewerAddPage () {
30- add_options_page('WebODF-Viewer Options', 'WebODF-Viewer ', '8', 'webodf-viewer .php', 'WebODF_ViewerOptions ');
29+ function ViewerJS_PluginAddPage () {
30+ add_options_page('ViewerJS-Plugin Options', 'ViewerJS-Plugin ', '8', 'viewerjs-plugin .php', 'ViewerJS_PluginOptions ');
3131}
3232
33- function WebODF_ViewerOptions () {
33+ function ViewerJS_PluginOptions () {
3434 global $site_url;
3535 $message = '';
36- $options = get_option('WebODF_ViewerSettings ');
36+ $options = get_option('ViewerJS_PluginSettings ');
3737 if ($_POST) {
3838 if (isset($_POST['width'])) {
3939 $options['width'] = $_POST['width'];
@@ -42,15 +42,15 @@ function WebODF_ViewerOptions() {
4242 $options['height'] = $_POST['height'];
4343 }
4444
45- update_option('WebODF_ViewerSettings ', $options);
45+ update_option('ViewerJS_PluginSettings ', $options);
4646 $message = '<div class="updated"><p>width=' . $options['width'] .
4747 ' height=' . $options['height'] .'<strong> Options saved.</strong></p></div>';
4848 }
4949 echo '<div class="wrap">';
50- echo '<h2>WebODF-Viewer Options</h2>';
50+ echo '<h2>ViewerJS-Plugin Options</h2>';
5151 echo $message;
52- echo '<form method="post" action="options-general.php?page=webodf-viewer .php">';
53- echo "<p>You can adjut the width and height of the WebODF Viewer iframe here. This is a global setting.</p>";
52+ echo '<form method="post" action="options-general.php?page=viewerjs-plugin .php">';
53+ echo "<p>You can adjut the width and height of the Viewer iframe here. This is a global setting.</p>";
5454 echo '<h4>Width-Height</h4>' . "\n";
5555 echo '<table class="form-table">' . "\n";
5656 echo '<tr><th scope="row">width</th><td>' . "\n";
@@ -67,35 +67,36 @@ function WebODF_ViewerOptions() {
6767 echo '</div>';
6868}
6969
70- function WebODF_ViewerLoadDefaults () {
70+ function ViewerJS_PluginLoadDefaults () {
7171 $ret = array();
7272 $ret['width'] = '450px';
7373 $ret['height'] = '380px';
7474 return $ret;
7575}
7676
77- function WebODF_Viewer_activate () {
78- update_option('WebODF_ViewerSettings ', WebODF_ViewerLoadDefaults ());
77+ function ViewerJS_Plugin_activate () {
78+ update_option('ViewerJS_PluginSettings ', ViewerJS_PluginLoadDefaults ());
7979}
8080
81- register_activation_hook(__FILE__,'WebODF_Viewer_activate ');
81+ register_activation_hook(__FILE__,'ViewerJS_Plugin_activate ');
8282
83- function WebODF_Viewer_deactivate () {
84- delete_option('WebODF_ViewerSettings ');
83+ function ViewerJS_Plugin_deactivate () {
84+ delete_option('ViewerJS_PluginSettings ');
8585}
8686
87- register_deactivation_hook(__FILE__,'WebODF_Viewer_deactivate ');
87+ register_deactivation_hook(__FILE__,'ViewerJS_Plugin_deactivate ');
8888
89- add_action('admin_menu', 'WebODF_ViewerAddPage ');
89+ add_action('admin_menu', 'ViewerJS_PluginAddPage ');
9090
9191
92- function mime_type_filter ($mime_types) {
92+ function viewerjs_mime_type_filter ($mime_types) {
9393 $mime_types['odt'] = 'application/vnd.oasis.opendocument.text';
9494 $mime_types['odp'] = 'application/vnd.oasis.opendocument.presentation';
9595 $mime_types['ods'] = 'application/vnd.oasis.opendocument.spreadsheet';
96+ $mime_types['pdf'] = 'application/pdf';
9697 return $mime_types;
9798}
98- add_filter( 'upload_mimes', 'mime_type_filter ');
99+ add_filter( 'upload_mimes', 'viewerjs_mime_type_filter ');
99100
100101function mime_type_icon($icon_uri, $mime_type, $post_id) {
101102 // this is bogus and not implemented
@@ -112,24 +113,24 @@ function mime_type_icon($icon_uri, $mime_type, $post_id) {
112113}
113114add_filter( 'wp_mime_type_icon', 'mime_type_icon', 10, 3);
114115
115- function webodf_media_send_to_editor ($html, $send_id, $attachment) {
116+ function viewerjs_media_send_to_editor ($html, $send_id, $attachment) {
116117 $pid = $attachment['id'];
117118
118119 $post = get_post($pid, ARRAY_A);
119120 if (preg_match('/^application\/vnd\.oasis\.opendocument/', $post['post_mime_type'])) {
120121 // place shortcode
121122 preg_match('/^http:\/\/[^\/]*(\/.*)$/', $attachment['url'], $matches);
122123 $document_url = $matches[1];
123- return "[webodf_viewer ".$document_url."]";
124+ return "[viewerjs_viewer ".$document_url."]";
124125 }
125126 return $html;
126127}
127- add_filter( 'media_send_to_editor', 'webodf_media_send_to_editor ', 10, 3);
128+ add_filter( 'media_send_to_editor', 'viewerjs_media_send_to_editor ', 10, 3);
128129
129130
130131/*
131132 TODO: introduce a smart switch on [post | attachment] scope
132- to skip webodf -embedding... (user might to simply link
133+ to skip viewerjs -embedding... (user might to simply link
133134 some documents)
134135 For now: always use webodf for embedding, if this plugin
135136 is enabled.
@@ -145,17 +146,17 @@ function field_filter($fields, $post_object) {
145146
146147 // insert document path
147148 preg_match('/^http:\/\/[^\/]*(\/.*)$/', $post_object->guid, $matches);
148- $fields["webodf_document_url "] = array(
149+ $fields["viewerjs_document_url "] = array(
149150 "label" => __("Document URL"),
150151 "input" => "text",
151152 "value" => $matches[1]
152153 );
153- $fields["webodf_embed "] = array(
154+ $fields["viewerjs_embed "] = array(
154155 "input" => "html",
155156 "label" => "Embed with WebODF",
156- "html" => '<label for="attachments-'.$post_object->ID.'-webodf_embed "> '.
157- '<input type="checkbox" id="attachments-"'.$post_object->ID.'-webodf_embed " '.
158- ' name="attachments['.$post_object->ID.'][webodf_embed ]" value="1" checked="checked"/>Use WebODF?</label>'
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>'
159160 );
160161 }
161162 return $fields;
@@ -172,10 +173,10 @@ function field_save( $post ) {
172173 $postid = $post;
173174
174175 if (! empty($_POST['attachments'])) {
175- if ($_POST['attachments'][$postid]['webodf_embed ']) {
176- update_post_meta($postid, 'webodf_embed ', "yes");
176+ if ($_POST['attachments'][$postid]['viewerjs_embed ']) {
177+ update_post_meta($postid, 'viewerjs_embed ', "yes");
177178 } else {
178- update_post_meta($postid, 'webodf_embed ', "no");
179+ update_post_meta($postid, 'viewerjs_embed ', "no");
179180 }
180181 }
181182 return $post;
@@ -190,20 +191,20 @@ add_filter('edit_attachment', 'field_save', 10, 1);
190191
191192*/
192193
193- function webodf_shortcode_handler ($args) {
194+ function viewerjs_shortcode_handler ($args) {
194195 global $this_plugin_url;
195196 $document_url = $args[0];
196- $options = get_option('WebODF_ViewerSettings ');
197+ $options = get_option('ViewerJS_PluginSettings ');
197198 $iframe_width = $options['width'];
198199 $iframe_height = $options['height'];
199- return "<iframe src=\"$this_plugin_url/wv/ " .
200+ return "<iframe src=\"$this_plugin_url" .
200201 '#' . $document_url .'" '.
201202 "width=\"$iframe_width\" ".
202203 "height=\"$iframe_height\" ".
203204 'style="border: 1px solid black; border-radius: 5px;" '.
204205 'webkitallowfullscreen="true" '.
205206 'mozallowfullscreen="true"></iframe>';
206207}
207- add_shortcode('webodf_viewer ', 'webodf_shortcode_handler ');
208+ add_shortcode('viewerjs ', 'viewerjs_shortcode_handler ');
208209
209210?>
0 commit comments