From 786cc4c0b66aa5a84981f0a32e782275111fbb4c Mon Sep 17 00:00:00 2001 From: Tobias Hintze Date: Wed, 18 Sep 2013 08:12:56 +0200 Subject: [PATCH] * fix clash with webodf wordpress plugin * update README / plugin-readme * bump version to 0.2.1 --- CMakeLists.txt | 2 +- README.md | 6 +-- viewerjs-plugin-README.txt | 26 +++++------- viewerjs-plugin.php.in | 85 +++++--------------------------------- 4 files changed, 25 insertions(+), 94 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e54829..45c0f06 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 ..'.") diff --git a/README.md b/README.md index 3049611..9599aaa 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/viewerjs-plugin-README.txt b/viewerjs-plugin-README.txt index 9ef68dd..cde713b 100644 --- a/viewerjs-plugin-README.txt +++ b/viewerjs-plugin-README.txt @@ -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/...) @@ -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. diff --git a/viewerjs-plugin.php.in b/viewerjs-plugin.php.in index e579cb1..0f9a0b9 100644 --- a/viewerjs-plugin.php.in +++ b/viewerjs-plugin.php.in @@ -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 @@ -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) { @@ -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; @@ -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" => '' - ); - } - 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 "