width=' . $options['width'] .
' height=' . $options['height'] .' Options saved.
';
}
echo '';
echo '
WebODF-Viewer Options
';
echo $message;
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');
?>