Skip to content

Commit

Permalink
* fix clash with webodf wordpress plugin
Browse files Browse the repository at this point in the history
* update README / plugin-readme
* bump version to 0.2.1
  • Loading branch information
Tobias Hintze committed Sep 18, 2013
1 parent 9ad61f5 commit 786cc4c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 94 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ project (Viewer.js)
cmake_minimum_required(VERSION 2.8.6)

# At this point, the version number that is used throughout is defined
set(VIEWERJS_VERSION 0.2.0)
set(VIEWERJS_VERSION 0.2.1)

if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(FATAL_ERROR "Compiling in the source directory is not supported. Use for example 'mkdir build; cd build; cmake ..'.")
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Viewer.js
# Viewer.JS

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).
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).

The heavy lifting in Viewer.js is done by these awesome projects:
The heavy lifting in Viewer.JS is done by these awesome projects:

### WebODF

Expand Down
26 changes: 11 additions & 15 deletions viewerjs-plugin-README.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
=== WebODF Viewer ===
=== ViewerJS WordPress Plugin ===
Contributors: Tobias Hintze
Tags: ODF, open document, WebODF
Tags: ODF, PDF, Documents, open document, WebODF
Requires at least: 3.2
Tested up to: 3.5.1
Tested up to: 3.6.1
Stable tag: 1.0


This plugin embeds a WebODF Viewer into WordPress.
This plugin embeds Viewer.JS into WordPress.

== Description ==

This plugin embeds a WebODF Viewer into WordPress. See www.webodf.org for more details on WebODF.
This is a combination of WebODF and PDF.js.
This plugin embeds Viewer.JS into WordPress. This is a combination of WebODF and PDF.js. See www.viewerjs.org for more details.

== Usage ==

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

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

== Installation ==

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

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

= 0.1 =

* first version hacked together.

= 0.2 =

* made it work with recent 3.5.1 (which changed API around attachment-fields)
* first version forked from the WebODF version.

85 changes: 10 additions & 75 deletions viewerjs-plugin.php.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
Plugin Name: ViewerJS Plugin
Version: @VIEWERJS_VERSION@
Plugin URI: http://viewerjs.org/
Description: Embed ODF and PDF in Wordpress
Description: Embed ODF and PDF in WordPress
Author: Tobias Hintze
Author URI: http://kogmbh.com

This Wordpress plugin is free software: you can redistribute it
This WordPress plugin is free software: you can redistribute it
and/or modify it under the terms of the GNU Affero General Public License
(GNU AGPL) as published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version. The code is distributed
Expand All @@ -23,15 +23,13 @@ through which recipients can access the Corresponding Source.

*/

$site_url = site_url();
$this_plugin_url = plugins_url() .'/'. plugin_basename(dirname(__FILE__));
$viewerjs_plugin_url = plugins_url() .'/'. plugin_basename(dirname(__FILE__));

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

function ViewerJS_PluginOptions() {
global $site_url;
$message = '';
$options = get_option('ViewerJS_PluginSettings');
if ($_POST) {
Expand Down Expand Up @@ -98,7 +96,7 @@ function viewerjs_mime_type_filter($mime_types) {
}
add_filter( 'upload_mimes', 'viewerjs_mime_type_filter');

function mime_type_icon($icon_uri, $mime_type, $post_id) {
function viewerjs_mime_type_icon($icon_uri, $mime_type, $post_id) {
// this is bogus and not implemented
if ($mime_type === 'application/vnd.oasis.opendocument.text') {
return $icon_uri;
Expand All @@ -109,95 +107,32 @@ function mime_type_icon($icon_uri, $mime_type, $post_id) {
} else {
return $icon_uri;
}
// return array($this_plugin_url . '/odf.png', 64, 64);
// return array($viewerjs_plugin_url . '/odf.png', 64, 64);
}
add_filter( 'wp_mime_type_icon', 'mime_type_icon', 10, 3);
add_filter( 'wp_mime_type_icon', 'viewerjs_mime_type_icon', 10, 3);

function viewerjs_media_send_to_editor($html, $send_id, $attachment) {
$pid = $attachment['id'];

$post = get_post($pid, ARRAY_A);
if (preg_match('/^application\/vnd\.oasis\.opendocument/', $post['post_mime_type'])) {
if (preg_match('/^application\/(vnd\.oasis\.opendocument|pdf)/', $post['post_mime_type'])) {
// place shortcode
preg_match('/^http:\/\/[^\/]*(\/.*)$/', $attachment['url'], $matches);
$document_url = $matches[1];
return "[viewerjs_viewer ".$document_url."]";
return "[viewerjs ".$document_url."]";
}
return $html;
}
add_filter( 'media_send_to_editor', 'viewerjs_media_send_to_editor', 10, 3);


/*
TODO: introduce a smart switch on [post | attachment] scope
to skip viewerjs-embedding... (user might to simply link
some documents)
For now: always use webodf for embedding, if this plugin
is enabled.

function field_filter($fields, $post_object) {
if ($post_object->post_parent > 0) {
// inside a post
$use_webodf = get_post_meta($post_object['post_parent'], 'use_webodf');
}

if (preg_match('/^application\/vnd\.oasis\.opendocument\.(text|presentation|spreadsheet)/',
$post_object->post_mime_type)) {

// insert document path
preg_match('/^http:\/\/[^\/]*(\/.*)$/', $post_object->guid, $matches);
$fields["viewerjs_document_url"] = array(
"label" => __("Document URL"),
"input" => "text",
"value" => $matches[1]
);
$fields["viewerjs_embed"] = array(
"input" => "html",
"label" => "Embed with WebODF",
"html" => '<label for="attachments-'.$post_object->ID.'-viewerjs_embed"> '.
'<input type="checkbox" id="attachments-"'.$post_object->ID.'-viewerjs_embed" '.
' name="attachments['.$post_object->ID.'][viewerjs_embed]" value="1" checked="checked"/>Use WebODF?</label>'
);
}
return $fields;
}
add_filter('attachment_fields_to_edit', 'field_filter', 10, 2);

function field_save_legacy( $post, $attachment ) {
$postid = $post['post_ID'];
if (! $postid) $postid = $post['ID'];
return field_save($postid);
}

function field_save( $post ) {
$postid = $post;

if (! empty($_POST['attachments'])) {
if ($_POST['attachments'][$postid]['viewerjs_embed']) {
update_post_meta($postid, 'viewerjs_embed', "yes");
} else {
update_post_meta($postid, 'viewerjs_embed', "no");
}
}
return $post;
}

// legacy (wp < 3.5.1):
add_filter('attachment_fields_to_save', 'field_save_legacy', 10, 2);

// recent:
add_filter('add_attachment', 'field_save', 10, 1);
add_filter('edit_attachment', 'field_save', 10, 1);

*/

function viewerjs_shortcode_handler($args) {
global $this_plugin_url;
global $viewerjs_plugin_url;
$document_url = $args[0];
$options = get_option('ViewerJS_PluginSettings');
$iframe_width = $options['width'];
$iframe_height = $options['height'];
return "<iframe src=\"$this_plugin_url" .
return "<iframe src=\"$viewerjs_plugin_url" .
'#' . $document_url .'" '.
"width=\"$iframe_width\" ".
"height=\"$iframe_height\" ".
Expand Down

0 comments on commit 786cc4c

Please sign in to comment.