Skip to content

Commit 786cc4c

Browse files
author
Tobias Hintze
committed
* fix clash with webodf wordpress plugin
* update README / plugin-readme * bump version to 0.2.1
1 parent 9ad61f5 commit 786cc4c

4 files changed

Lines changed: 25 additions & 94 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ project (Viewer.js)
3636
cmake_minimum_required(VERSION 2.8.6)
3737

3838
# At this point, the version number that is used throughout is defined
39-
set(VIEWERJS_VERSION 0.2.0)
39+
set(VIEWERJS_VERSION 0.2.1)
4040

4141
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
4242
message(FATAL_ERROR "Compiling in the source directory is not supported. Use for example 'mkdir build; cd build; cmake ..'.")

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Viewer.js
1+
# Viewer.JS
22

3-
Viewer.js combines a number of excellent open source tools that are built on HTML and javascript. Viewer.js was funded by [NLnet foundation](http://nlnet.nl) and developed by [KO GmbH](http://kogmbh.com).
3+
Viewer.JS combines a number of excellent open source tools that are built on HTML and javascript. Viewer.JS was funded by [NLnet foundation](http://nlnet.nl) and developed by [KO GmbH](http://kogmbh.com).
44

5-
The heavy lifting in Viewer.js is done by these awesome projects:
5+
The heavy lifting in Viewer.JS is done by these awesome projects:
66

77
### WebODF
88

viewerjs-plugin-README.txt

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
=== WebODF Viewer ===
1+
=== ViewerJS WordPress Plugin ===
22
Contributors: Tobias Hintze
3-
Tags: ODF, open document, WebODF
3+
Tags: ODF, PDF, Documents, open document, WebODF
44
Requires at least: 3.2
5-
Tested up to: 3.5.1
5+
Tested up to: 3.6.1
66
Stable tag: 1.0
77

88

9-
This plugin embeds a WebODF Viewer into WordPress.
9+
This plugin embeds Viewer.JS into WordPress.
1010

1111
== Description ==
12-
13-
This plugin embeds a WebODF Viewer into WordPress. See www.webodf.org for more details on WebODF.
12+
This is a combination of WebODF and PDF.js.
13+
This plugin embeds Viewer.JS into WordPress. This is a combination of WebODF and PDF.js. See www.viewerjs.org for more details.
1414

1515
== Usage ==
1616

17-
Navigate to a Open Document file in your WP blog's media library and press the button "Insert WebODF Viewer".
18-
Alternatively you can manually insert the WordPress shortcode `[webodf_viewer /path-to-some-file.odt]` to embed
19-
any `*.odt`, `*.odp`, or `*.ods` documents at that location.
17+
Navigate to a Document file (ODF or PDF) in your WP blog's media library and press the button "Insert with Viewer.JS".
18+
Alternatively you can manually insert the WordPress shortcode `[viewerjs /path-to-some-file.pdf]` to embed
19+
any `*.pdf`, `*.odt`, `*.odp`, or `*.ods` documents at that location.
2020

2121
The plugin also provides a settings panel for adjusting the width and height of the embeded element (iframe).
2222

2323
== Installation ==
2424

25-
1. Upload the whole `webodf-viewer` directory and content to the `/wp-content/plugins/` directory
25+
1. Upload the whole `viewer.js-plugin` directory and content to the `/wp-content/plugins/` directory
2626
2. Activate the plugin through the 'Plugins' menu in WordPress
2727

2828
(or do the automatic stuff from the /wp-admin/...)
@@ -35,9 +35,5 @@ no screenshots available (yet)
3535

3636
= 0.1 =
3737

38-
* first version hacked together.
39-
40-
= 0.2 =
41-
42-
* made it work with recent 3.5.1 (which changed API around attachment-fields)
38+
* first version forked from the WebODF version.
4339

viewerjs-plugin.php.in

Lines changed: 10 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
Plugin Name: ViewerJS Plugin
55
Version: @VIEWERJS_VERSION@
66
Plugin URI: http://viewerjs.org/
7-
Description: Embed ODF and PDF in Wordpress
7+
Description: Embed ODF and PDF in WordPress
88
Author: Tobias Hintze
99
Author 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
1212
and/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
1414
the 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

2928
function ViewerJS_PluginAddPage() {
3029
add_options_page('ViewerJS-Plugin Options', 'ViewerJS-Plugin', '8', 'viewerjs-plugin.php', 'ViewerJS_PluginOptions');
3130
}
3231

3332
function 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
}
9997
add_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

116114
function 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
}
128126
add_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-
194129
function 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

Comments
 (0)