If you don't have an account with Aspose Cloud, Click here to Sign Up.

>
>
>
>
>
>
current_action(); $allowed_actions = array("aspose_export_doc"); if(!in_array($action, $allowed_actions)) return; // security check check_admin_referer('bulk-posts'); // make sure ids are submitted. depending on the resource type, this may be 'media' or 'ids' if(isset($_REQUEST['post'])) { $post_ids = array_map('intval', $_REQUEST['post']); } if(empty($post_ids)) return; // this is based on wp-admin/edit.php $sendback = remove_query_arg( array('exported', 'untrashed', 'deleted', 'ids','file_name'), wp_get_referer() ); if ( ! $sendback ) $sendback = admin_url( "edit.php?post_type=$post_type" ); $pagenum = $wp_list_table->get_pagenum(); $sendback = add_query_arg( 'paged', $pagenum, $sendback ); switch($action) { case 'aspose_export_doc': $exported = count($post_ids); include_once('asposeDocConverter.php'); if(get_option('aspose_doc_exporter_archive_posts') == 'yes') { $zip_file_name = $upload_path . "exported-documents".time().".zip"; $zip = new ZipArchive(); // open archive if ($zip->open($zip_file_name, ZIPARCHIVE::CREATE) !== TRUE) { die ("Could not open archive"); } foreach($post_ids as $post_id) { $post_contents = aspose_doc_exporter_array_builder(array($post_id)); if ( is_array($post_contents) && count($post_contents) > 0 ) { $file_name = aspose_doc_exporter_array_to_html($post_contents); process($file_name); global $html_filename; $file_type = get_option('aspose_doc_exporter_file_type'); if(isset($file_type) && !empty($file_type)){ $file_type = $file_type; } else { $file_type = 'docx'; } $file_name = str_replace('.htm','.'.$file_type,$html_filename); $upload_dir = wp_upload_dir(); $upload_path = $upload_dir['path'] . '/'; $file_details = pathinfo($file_name); $file_name = $upload_path . $file_name; if($file_details['extension'] == $file_type && file_exists($file_name)) { $zip->addFile($file_name, basename($file_name)) or die ("ERROR: Could not add file: $file_name"); } else { echo "Invalid File!"; } } } $zip->close(); header ("Content-type: octet/stream"); header ("Content-disposition: attachment; filename=".basename($zip_file_name).";"); header("Content-Length: ".filesize($zip_file_name)); readfile($zip_file_name); exit; } else { $post_contents = aspose_doc_exporter_array_builder($post_ids); if ( is_array($post_contents) && count($post_contents) > 0 ) { $file_name = aspose_doc_exporter_array_to_html($post_contents); process($file_name); } else { wp_die( __('Error exporting post.') ); } global $html_filename; $file_type = get_option('aspose_doc_exporter_file_type'); if(isset($file_type) && !empty($file_type)){ $file_type = $file_type; } else { $file_type = 'docx'; } $file_name = str_replace('.htm','.'.$file_type,$html_filename); $upload_dir = wp_upload_dir(); $upload_path = $upload_dir['path'] . '/'; $file_name = $upload_path . $file_name; $file_details = pathinfo($file_name); if($file_details['extension'] == $file_type) { header ("Content-type: octet/stream"); header ("Content-disposition: attachment; filename=".basename($file_name).";"); header("Content-Length: ".filesize($file_name)); readfile($file_name); exit; } else { echo "Invalid File!"; } } $sendback = add_query_arg( array('exported' => $exported, 'ids' => join(',', $post_ids), 'file_name' => $file_name ), $sendback ); break; default: return; } $sendback = remove_query_arg( array('action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status', 'post', 'bulk_edit', 'post_view'), $sendback ); wp_redirect($sendback); exit(); } function aspose_doc_exporter_array_builder($post_ids) { foreach($post_ids as $post_id) { $post_data = get_post($post_id); $post_title = $post_data->post_title; $post_content = ''; if(get_option('aspose_doc_exporter_post_date') == 'yes') { $post_content .= 'Published Date : ' . get_the_date( '', $post_id ) . '
' ; } if(get_option('aspose_doc_exporter_post_author') == 'yes') { $post_content .= 'Author : ' . get_the_author_meta( 'user_nicename' , $post_data->post_author ) . '
' ; } if(get_option('aspose_doc_exporter_post_categories') == 'yes') { $post_content .= 'Categories : ' . get_the_category_list( ', ', '', $post_id ) . '
' ; } if(get_option('aspose_doc_exporter_post_content_filters') == 'no') { $post_content .= $post_data->post_content ; } else { if(class_exists('WPBMap') && method_exists( 'WPBMap', 'addAllMappedShortcodes' )) { WPBMap::addAllMappedShortcodes(); } $post_content .= apply_filters('the_content',$post_data->post_content) ; } //$post_content = $post_data->post_content; if(get_option('aspose_doc_exporter_post_comments') == 'yes') { if( get_option('aspose_doc_exporter_comments_text') !='' ) { $post_content .= '

'. get_option('aspose_doc_exporter_comments_text') .'

'; } else { $post_content .= '

Comments

'; } $defaults = array('post_id' => $post_id, 'status' => 'approve'); $post_comments = get_comments($defaults); foreach($post_comments as $comment) : $post_content .= ' ' . $comment->comment_author . '
' . $comment->comment_content . '
'; endforeach; } $post_contents[$post_title . ' ' . microtime()] = $post_content; } if(is_array($post_contents)) { return $post_contents; } else { return false; } } function aspose_doc_exporter_array_to_html($post_contents){ global $html_filename; $upload_dir = wp_upload_dir(); $upload_path = $upload_dir['path'] . '/'; $html_filename = 'output_'.time().'.htm'; $output_string = << EOD; foreach($post_contents as $key => $value) { $key = preg_replace('/[0-9\.\s]+$/','',$key); //$value = iconv("UTF-8", "ASCII//TRANSLIT", $value); $output_string .= << {$key}

{$value}


EOD; } $output_string .= << EOD; @unlink($upload_path . $html_filename); file_put_contents($upload_path . $html_filename,$output_string); return $upload_path . $html_filename; }