From 8e6d5ab658021d5b1c7d1b5ed412be17626b9e20 Mon Sep 17 00:00:00 2001 From: Aditya Bhatt Date: Tue, 17 Sep 2013 17:35:22 +0200 Subject: [PATCH 1/3] Initial commit of a wordpress plugin for viewerjs along with some cmake mechanism to create a zip bundle for it --- CMakeLists.txt | 23 ++++ viewerjs-plugin-README.txt | 43 ++++++++ viewerjs-plugin.php.in | 209 +++++++++++++++++++++++++++++++++++++ 3 files changed, 275 insertions(+) create mode 100644 viewerjs-plugin-README.txt create mode 100644 viewerjs-plugin.php.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 647347b..9e54829 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,6 +61,9 @@ FILE ( MAKE_DIRECTORY ${VIEWER_BUILD_DIR}) SET ( VIEWERZIP ${CMAKE_BINARY_DIR}/Viewer.js-${VIEWERJS_VERSION}.zip) SET ( WEBODF_SOURCE_DIR ${CMAKE_BINARY_DIR}/WebODF-source ) +SET ( WORDPRESS_ZIP_DIR ${CMAKE_CURRENT_BINARY_DIR}/viewerjs-wordpress-${VIEWERJS_VERSION}) +SET ( WORDPRESSZIP ${WORDPRESS_ZIP_DIR}.zip) + ExternalProject_Add( WebODF GIT_REPOSITORY https://git.gitorious.org/webodf/webodf.git @@ -100,3 +103,23 @@ add_custom_target(Viewer ALL WebODF PDFjs ) + +configure_file(viewerjs-plugin.php.in ${CMAKE_CURRENT_BINARY_DIR}/viewerjs-plugin.php) + +add_custom_command( + OUTPUT ${WORDPRESSZIP} + COMMAND ${CMAKE_COMMAND} -E remove_directory ${WORDPRESS_ZIP_DIR} + COMMAND ${CMAKE_COMMAND} -E copy_directory ${VIEWER_BUILD_DIR} ${WORDPRESS_ZIP_DIR} + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/viewerjs-plugin-README.txt ${WORDPRESS_ZIP_DIR} + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/viewerjs-plugin.php ${WORDPRESS_ZIP_DIR} + COMMAND node ARGS ${WEBODF_SOURCE_DIR}/webodf/lib/runtime.js ${WEBODF_SOURCE_DIR}/webodf/tools/zipdir.js + ${WORDPRESS_ZIP_DIR} + ${WORDPRESSZIP} +) + +add_custom_target(wordpress-plugin ALL + DEPENDS + ${WORDPRESSZIP} + Viewer +) + diff --git a/viewerjs-plugin-README.txt b/viewerjs-plugin-README.txt new file mode 100644 index 0000000..9ef68dd --- /dev/null +++ b/viewerjs-plugin-README.txt @@ -0,0 +1,43 @@ +=== WebODF Viewer === +Contributors: Tobias Hintze +Tags: ODF, open document, WebODF +Requires at least: 3.2 +Tested up to: 3.5.1 +Stable tag: 1.0 + + +This plugin embeds a WebODF Viewer into WordPress. + +== Description == + +This plugin embeds a WebODF Viewer into WordPress. See www.webodf.org for more details on WebODF. + +== 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. + +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 +2. Activate the plugin through the 'Plugins' menu in WordPress + +(or do the automatic stuff from the /wp-admin/...) + +== Screenshots == + +no screenshots available (yet) + +== Changelog == + += 0.1 = + +* first version hacked together. + += 0.2 = + +* made it work with recent 3.5.1 (which changed API around attachment-fields) + diff --git a/viewerjs-plugin.php.in b/viewerjs-plugin.php.in new file mode 100644 index 0000000..1e597e8 --- /dev/null +++ b/viewerjs-plugin.php.in @@ -0,0 +1,209 @@ +

width=' . $options['width'] . + ' height=' . $options['height'] .'  Options saved.

'; + } + echo '
'; + echo '

WebODF-Viewer Options

'; + echo $message; + echo '
'; + echo "

You can adjut the width and height of the WebODF Viewer iframe here. This is a global setting.

"; + echo '

Width-Height

' . "\n"; + echo '' . "\n"; + echo '' . "\n"; + echo '' . "\n"; + echo '
width' . "\n"; + echo ''; + echo '
height' . "\n"; + echo ''; + echo '
' . "\n"; + + echo '

'; + echo '
'; + + echo '
'; +} + +function WebODF_ViewerLoadDefaults() { + $ret = array(); + $ret['width'] = '450px'; + $ret['height'] = '380px'; + return $ret; +} + +function WebODF_Viewer_activate() { + update_option('WebODF_ViewerSettings', WebODF_ViewerLoadDefaults()); +} + +register_activation_hook(__FILE__,'WebODF_Viewer_activate'); + +function WebODF_Viewer_deactivate() { + delete_option('WebODF_ViewerSettings'); +} + +register_deactivation_hook(__FILE__,'WebODF_Viewer_deactivate'); + +add_action('admin_menu', 'WebODF_ViewerAddPage'); + + +function mime_type_filter($mime_types) { + $mime_types['odt'] = 'application/vnd.oasis.opendocument.text'; + $mime_types['odp'] = 'application/vnd.oasis.opendocument.presentation'; + $mime_types['ods'] = 'application/vnd.oasis.opendocument.spreadsheet'; + return $mime_types; +} +add_filter( 'upload_mimes', 'mime_type_filter'); + +function 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; + } else if ($mime_type === 'application/vnd.oasis.opendocument.presentation') { + return $icon_uri; + } else if ($mime_type === 'application/vnd.oasis.opendocument.spreadsheet') { + return $icon_uri; + } else { + return $icon_uri; + } + // return array($this_plugin_url . '/odf.png', 64, 64); +} +add_filter( 'wp_mime_type_icon', 'mime_type_icon', 10, 3); + +function webodf_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'])) { + // place shortcode + preg_match('/^http:\/\/[^\/]*(\/.*)$/', $attachment['url'], $matches); + $document_url = $matches[1]; + return "[webodf_viewer ".$document_url."]"; + } + return $html; +} +add_filter( 'media_send_to_editor', 'webodf_media_send_to_editor', 10, 3); + + +/* + TODO: introduce a smart switch on [post | attachment] scope + to skip webodf-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["webodf_document_url"] = array( + "label" => __("Document URL"), + "input" => "text", + "value" => $matches[1] + ); + $fields["webodf_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]['webodf_embed']) { + update_post_meta($postid, 'webodf_embed', "yes"); + } else { + update_post_meta($postid, 'webodf_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 webodf_shortcode_handler($args) { + global $this_plugin_url; + $document_url = $args[0]; + $options = get_option('WebODF_ViewerSettings'); + $iframe_width = $options['width']; + $iframe_height = $options['height']; + return "'; +} +add_shortcode('webodf_viewer', 'webodf_shortcode_handler'); + +?> From 9ad61f54ffcd80ef6ef9571db4d3a60ac0e382d7 Mon Sep 17 00:00:00 2001 From: Aditya Bhatt Date: Tue, 17 Sep 2013 19:26:31 +0200 Subject: [PATCH 2/3] Rebrand webodf plugin to ViewerJS Plugin, and change shortcode --- viewerjs-plugin.php.in | 77 +++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/viewerjs-plugin.php.in b/viewerjs-plugin.php.in index 1e597e8..e579cb1 100644 --- a/viewerjs-plugin.php.in +++ b/viewerjs-plugin.php.in @@ -1,10 +1,10 @@

width=' . $options['width'] . ' height=' . $options['height'] .'  Options saved.

'; } echo '
'; - echo '

WebODF-Viewer Options

'; + echo '

ViewerJS-Plugin Options

'; echo $message; - echo '
'; - echo "

You can adjut the width and height of the WebODF Viewer iframe here. This is a global setting.

"; + echo ''; + echo "

You can adjut the width and height of the Viewer iframe here. This is a global setting.

"; echo '

Width-Height

' . "\n"; echo '' . "\n"; echo '
width' . "\n"; @@ -67,35 +67,36 @@ function WebODF_ViewerOptions() { echo ''; } -function WebODF_ViewerLoadDefaults() { +function ViewerJS_PluginLoadDefaults() { $ret = array(); $ret['width'] = '450px'; $ret['height'] = '380px'; return $ret; } -function WebODF_Viewer_activate() { - update_option('WebODF_ViewerSettings', WebODF_ViewerLoadDefaults()); +function ViewerJS_Plugin_activate() { + update_option('ViewerJS_PluginSettings', ViewerJS_PluginLoadDefaults()); } -register_activation_hook(__FILE__,'WebODF_Viewer_activate'); +register_activation_hook(__FILE__,'ViewerJS_Plugin_activate'); -function WebODF_Viewer_deactivate() { - delete_option('WebODF_ViewerSettings'); +function ViewerJS_Plugin_deactivate() { + delete_option('ViewerJS_PluginSettings'); } -register_deactivation_hook(__FILE__,'WebODF_Viewer_deactivate'); +register_deactivation_hook(__FILE__,'ViewerJS_Plugin_deactivate'); -add_action('admin_menu', 'WebODF_ViewerAddPage'); +add_action('admin_menu', 'ViewerJS_PluginAddPage'); -function mime_type_filter($mime_types) { +function viewerjs_mime_type_filter($mime_types) { $mime_types['odt'] = 'application/vnd.oasis.opendocument.text'; $mime_types['odp'] = 'application/vnd.oasis.opendocument.presentation'; $mime_types['ods'] = 'application/vnd.oasis.opendocument.spreadsheet'; + $mime_types['pdf'] = 'application/pdf'; return $mime_types; } -add_filter( 'upload_mimes', 'mime_type_filter'); +add_filter( 'upload_mimes', 'viewerjs_mime_type_filter'); function mime_type_icon($icon_uri, $mime_type, $post_id) { // this is bogus and not implemented @@ -112,7 +113,7 @@ function mime_type_icon($icon_uri, $mime_type, $post_id) { } add_filter( 'wp_mime_type_icon', 'mime_type_icon', 10, 3); -function webodf_media_send_to_editor($html, $send_id, $attachment) { +function viewerjs_media_send_to_editor($html, $send_id, $attachment) { $pid = $attachment['id']; $post = get_post($pid, ARRAY_A); @@ -120,16 +121,16 @@ function webodf_media_send_to_editor($html, $send_id, $attachment) { // place shortcode preg_match('/^http:\/\/[^\/]*(\/.*)$/', $attachment['url'], $matches); $document_url = $matches[1]; - return "[webodf_viewer ".$document_url."]"; + return "[viewerjs_viewer ".$document_url."]"; } return $html; } -add_filter( 'media_send_to_editor', 'webodf_media_send_to_editor', 10, 3); +add_filter( 'media_send_to_editor', 'viewerjs_media_send_to_editor', 10, 3); /* TODO: introduce a smart switch on [post | attachment] scope - to skip webodf-embedding... (user might to simply link + to skip viewerjs-embedding... (user might to simply link some documents) For now: always use webodf for embedding, if this plugin is enabled. @@ -145,17 +146,17 @@ function field_filter($fields, $post_object) { // insert document path preg_match('/^http:\/\/[^\/]*(\/.*)$/', $post_object->guid, $matches); - $fields["webodf_document_url"] = array( + $fields["viewerjs_document_url"] = array( "label" => __("Document URL"), "input" => "text", "value" => $matches[1] ); - $fields["webodf_embed"] = array( + $fields["viewerjs_embed"] = array( "input" => "html", "label" => "Embed with WebODF", - "html" => '' + "html" => '' ); } return $fields; @@ -172,10 +173,10 @@ function field_save( $post ) { $postid = $post; if (! empty($_POST['attachments'])) { - if ($_POST['attachments'][$postid]['webodf_embed']) { - update_post_meta($postid, 'webodf_embed', "yes"); + if ($_POST['attachments'][$postid]['viewerjs_embed']) { + update_post_meta($postid, 'viewerjs_embed', "yes"); } else { - update_post_meta($postid, 'webodf_embed', "no"); + update_post_meta($postid, 'viewerjs_embed', "no"); } } return $post; @@ -190,13 +191,13 @@ add_filter('edit_attachment', 'field_save', 10, 1); */ -function webodf_shortcode_handler($args) { +function viewerjs_shortcode_handler($args) { global $this_plugin_url; $document_url = $args[0]; - $options = get_option('WebODF_ViewerSettings'); + $options = get_option('ViewerJS_PluginSettings'); $iframe_width = $options['width']; $iframe_height = $options['height']; - return "'; } -add_shortcode('webodf_viewer', 'webodf_shortcode_handler'); +add_shortcode('viewerjs', 'viewerjs_shortcode_handler'); ?> From 786cc4c0b66aa5a84981f0a32e782275111fbb4c Mon Sep 17 00:00:00 2001 From: Tobias Hintze Date: Wed, 18 Sep 2013 08:12:56 +0200 Subject: [PATCH 3/3] * 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 "