├── README.md ├── .gitignore ├── js └── tabs.js ├── html-import-styles.css ├── html-import.php ├── readme.txt ├── languages └── import-html-pages.pot ├── html-import-options.php └── html-importer.php /README.md: -------------------------------------------------------------------------------- 1 | HTML-Import-2 2 | ============= 3 | 4 | A WordPress plugin to import content from static HTML files. -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .htaccess 2 | wp-*.php 3 | xmlrpc.php 4 | wp-admin/ 5 | wp-includes/ 6 | wp-content/uploads/ 7 | wp-content/blogs.dir/ 8 | wp-content/upgrade/* 9 | wp-content/backup-db/* 10 | wp-content/advanced-cache.php 11 | wp-content/wp-cache-config.php 12 | wp-content/cache/* 13 | wp-content/cache/supercache/* 14 | sitemap.xml 15 | sitemap.xml.gz 16 | readme.html 17 | license.txt 18 | -------------------------------------------------------------------------------- /js/tabs.js: -------------------------------------------------------------------------------- 1 | jQuery(document).ready(function($) { 2 | // Set up jQuery UI tabs 3 | $('.ui-tabs').tabs(); 4 | 5 | // Show/hide table rows based on selected radio value 6 | $("input.showrow").click(function() { 7 | var tag = $(this).val(); 8 | var importing = $(this).attr('title'); 9 | var rowID = $(this).parents("tr").attr("id"); 10 | //console.log("#"+rowID+" tr#"+importing+"-"+tag); 11 | $("#"+rowID+" tr#"+importing+"-region").hide(); 12 | $("#"+rowID+" tr#"+importing+"-tag").hide(); 13 | $("#"+rowID+" tr#"+importing+"-"+tag).show(); 14 | }); 15 | 16 | // Show/hide table rows based on checkbox toggle 17 | $("input.toggle").click(function() { 18 | var tr = this.id; 19 | $("tr."+tr).toggle(); 20 | }); 21 | 22 | // Clone table rows 23 | $(".cloneTableRows").live('click', function(){ 24 | var thisTableId = $(this).parents("table").attr("id"); 25 | var lastRow = $('#'+thisTableId + " tbody tr.clone:last"); 26 | var oldID = lastRow.attr("id"); 27 | var newID = oldID.replace('customfield',''); 28 | var prevID = newID; // need oldID later 29 | newID = newID.valueOf(); // (int) 30 | newID++; 31 | var newRow = lastRow.clone(true); 32 | newRow.attr( "id", 'customfield'+newID ); 33 | newRow.find(':input') 34 | .attr('name', function(index, name) { 35 | return name.replace(prevID, newID) 36 | }); 37 | newRow.find('input[type=text]').val(''); 38 | newRow.find('a.delRow').removeClass('hidden'); 39 | $('#'+thisTableId).append(newRow); 40 | return false; 41 | }); 42 | 43 | // Delete a table row 44 | $(".delRow").click(function(){ 45 | $(this).parents("tr").remove(); 46 | return false; 47 | }); 48 | }); -------------------------------------------------------------------------------- /html-import-styles.css: -------------------------------------------------------------------------------- 1 | .clear, #html_import p.submit, #html_import .wrap p, #html_import .wrap h3, p.htmlimportfloat.clear, div#tips { clear: both; } 2 | .wrap h4 { margin: 1em 0 0; } 3 | kbd { display: inline; } 4 | p.htmlimportfloat { float: left; width: 15em; margin-right: 2em; clear: none; } 5 | p.widefloat { width: 31.4em; } 6 | input.widefloat { width: 48.5em; } 7 | #content-region, #title-region, #taxonomy { width: 100%; height: 8em; z-index: 10; } 8 | #content-switch, #title-switch, #type-switch { position: relative; height: 8em; } 9 | #content-region, #title-region, .clean-region { display: none; } 10 | div.taxochecklistbox { float: left; margin: 1em 1em 1em 0; } 11 | ul.taxochecklist { height: 15em; width: 20em; overflow-y: scroll; border: 1px solid #dfdfdf; padding: 0 1em; background: #fff; border-radius: 4px; -moz-border-radius: 4px; -webkit-border-radius: 4px; } 12 | ul.taxochecklist ul.children { margin-left: 1em; } 13 | p.taxoinput { float: left; margin: 1em 1em 1em 0; width: 22.2em; } 14 | p.taxoinput input { width: 100%; } 15 | td.taginput { width: 33%; vertical-align: top; } 16 | .clean-region th { text-indent: 2em; } 17 | #customfields th, #customfields td { vertical-align: top; } 18 | #customfields th { width: auto; } 19 | #customfields tbody th { text-align: center; } 20 | #customfields tbody th h4 { text-align: left; } 21 | tr.clone:nth-child(odd) th, tr.clone:nth-child(odd) td { background-color: #fff } 22 | body.settings_page_html-import #footer { display: none; } 23 | /* jQuery tabs */ 24 | .ui-tabs-nav { margin: 0; padding: 0; } 25 | .ui-tabs-nav li { display: inline; } 26 | .ui-tabs-nav li a { color: #aaa; } 27 | ul.ui-tabs-nav li.ui-tabs-active a.nav-tab { border-bottom: 1px solid #fff; color: #464646; } 28 | .ui-tabs-panel, .ui-tabs { clear: both; } 29 | .wrap h3, a.button-secondary.hidden { display: none; } 30 | -------------------------------------------------------------------------------- /html-import.php: -------------------------------------------------------------------------------- 1 | User Guide for details. 6 | Version: 2.6 7 | Author: Stephanie Leary 8 | Author URI: http://sillybean.net/ 9 | License: GPL 2 10 | */ 11 | 12 | require_once ( 'html-importer.php' ); 13 | require_once ( 'html-import-options.php' ); 14 | 15 | // plugin_activation_check() by Otto 16 | function html_import_activation_check() { 17 | if ( version_compare( PHP_VERSION, '5.0.0', '<' ) ) { 18 | deactivate_plugins( basename( __FILE__ ) ); // Deactivate myself 19 | wp_die( "Sorry, but you can't run this plugin, it requires PHP 5 or higher.", 'import-html-pages' ); 20 | } 21 | } 22 | register_activation_hook( __FILE__, 'html_import_activation_check' ); 23 | 24 | // Option page styles 25 | function html_import_css() { 26 | wp_register_style( 'html-import-css', plugins_url( 'html-import-styles.css', __FILE__ ) ); 27 | 28 | } 29 | function add_html_import_styles() { 30 | wp_enqueue_style( 'html-import-css' ); 31 | } 32 | add_action( 'admin_init', 'html_import_css' ); 33 | 34 | // Option page scripts 35 | function html_import_scripts() { 36 | wp_enqueue_script( 'jquery-ui-tabs' ); 37 | wp_enqueue_script( 'html-import-tabs', plugins_url( 'js/tabs.js', __FILE__ ), array( 'jquery', 'jquery-ui-tabs' ) ); 38 | } 39 | 40 | // set default options 41 | function html_import_set_defaults() { 42 | $options = html_import_get_options(); 43 | add_option( 'html_import', $options, '', 'no' ); 44 | } 45 | register_activation_hook( __FILE__, 'html_import_set_defaults' ); 46 | 47 | //register our settings 48 | function register_html_import_settings() { 49 | register_setting( 'html_import', 'html_import', 'html_import_validate_options' ); 50 | } 51 | 52 | // when uninstalled, remove option 53 | function html_import_remove_options() { 54 | delete_option( 'html_import' ); 55 | } 56 | register_uninstall_hook( __FILE__, 'html_import_remove_options' ); 57 | // for testing only 58 | // register_deactivation_hook( __FILE__, 'html_import_remove_options' ); 59 | 60 | function html_import_add_pages() { 61 | // Add option page to admin menu 62 | $pg = add_options_page( __( 'HTML Import', 'import-html-pages' ), __( 'HTML Import', 'import-html-pages' ), 'manage_options', basename( __FILE__ ), 'html_import_options_page' ); 63 | 64 | // Add styles and scripts 65 | add_action( 'admin_print_styles-'.$pg, 'add_html_import_styles' ); 66 | add_action( 'admin_print_scripts-'.$pg, 'html_import_scripts' ); 67 | 68 | // register setting 69 | add_action( 'admin_init', 'register_html_import_settings' ); 70 | 71 | // Help screen 72 | $text = '

'.sprintf( __( 'This is a complicated importer with lots of options. If you have never used this importer before, you should take a look at the User Guide.', 'import-html-pages' ), 'http://sillybean.net/downloads/html-import/user-guide.html' ).'

'; 73 | $text .= '

'.__( "You need to look through the first five tabs and save your settings before you run the importer. The sixth ( Tools ) contains links to some tools that are helpful after you've imported.", 'import-html-pages' ).'

'; 74 | 75 | $text .= '

'.__( 'Tips', 'html-import-pages' )."

76 |
    77 |
  1. " . __( "If there is already some content in this site, you should back up your database before you import.", 'import-html-pages' )."
  2. 78 |
  3. " . __( "Before you import, deactivate any crosspost or notification plugins.", 'import-html-pages' )."
  4. 79 |
  5. " . __( "Try uploading a single file before you run the importer on the whole directory. Check the imported page and see whether you need to adjust your content and/or title settings.", 'import-html-pages' )."
  6. 80 |
  7. " . __( "Need to import both posts and pages? Run the importer on a subdirectory ( e.g. 'news' ), then add the subdirectory name to the list of skipped directories and run the importer again on the parent directory.", 'import-html-pages' )."
  8. 81 |
"; 82 | $text .= '

' . __( 'More Help', 'import-html-pages' ) . '

'; 83 | 84 | $text .= ''; 89 | 90 | // add_contextual_help( $pg, $text ); 91 | } 92 | add_action( 'admin_menu', 'html_import_add_pages' ); 93 | 94 | // Add link to options page from plugin list 95 | add_action( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'html_import_plugin_actions' ); 96 | function html_import_plugin_actions( $links ) { 97 | $new_links = array(); 98 | $new_links[] = sprintf( '%s', __( 'Settings', 'html-import' ) ); 99 | return array_merge( $new_links, $links ); 100 | } -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | === HTML Import 2 === 2 | Contributors: sillybean 3 | Donate link: http://sillybean.net/code/wordpress/html-import-2/ 4 | Text Domain: html_import 5 | Domain Path: /languages 6 | Tags: import, pages, static files, taxonomies, taxonomy, dreamweaver, Word, FrontPage 7 | Requires at least: 3.0 8 | Tested up to: 4.6 9 | Stable tag: 2.6 10 | 11 | Imports well-formed HTML files into WordPress pages. 12 | 13 | == Description == 14 | 15 | Imports well-formed static HTML files into WordPress. Requires PHP 5. 16 | 17 | This plugin will import a directory of files as either pages or posts. You may specify the HTML tag (e.g. ``, `
`, or ``) or Dreamweaver template region (e.g. 'Main Content') containing the content you want to import. 18 | 19 | If importing pages, the directory hierarchy will be preserved. Directories containing the specified file types will be imported as empty parent pages (or, if an index file is present, its contents will be used for the parent page). Directories that do not contain the specified file types will be ignored. 20 | 21 | As files are imported, the resulting IDs, permalinks, and titles will be displayed. On completion, the importer will provide a list of Apache redirects that can be used in your `.htaccess` file to seamlessly transfer visitors from the old file locations to the new WordPress permalinks. As of 2.0, if you change your permalink structure after you've imported your files, you can regenerate the redirects—the file's old URL is stored as a custom field in the imported post. 22 | 23 | Options: 24 | 25 | * import files into any post type (posts, pages, or custom post types set to `public`) 26 | * import linked media files (images, documents, etc.) to the media library 27 | * select content, title, and custom fields by HTML tag or Dreamweaver template region 28 | * remove a common phrase (such as the site name) from imported titles 29 | * remove the imported title from within the content area 30 | * upload a single file or scan a directory for files to import 31 | * specify file extensions to import (e.g. html, htm, php) 32 | * specify directories to exclude (e.g. images, css) 33 | * if importing pages (or any hierarchical post type), specify whether your top-level files should become top-level pages or children of an existing page 34 | * specify index file names (e.g. index.html, default.htm) whose contents should be used for the directory parent pages 35 | * set tags, categories, and custom taxonomies 36 | * choose status, author, and timestamp 37 | * use meta descriptions as excerpts 38 | * clean up imported HTML and strip unwanted tags and attributes in content and custom fields 39 | * fix internal links in imported files to match new permalinks 40 | * import the entire file and generate the title from the filename 41 | * preserve the original filename as the imported page's slug 42 | * choose the date from an HTML tag or Dreamweaver region (uses strtotime(); results may vary) 43 | * import additional HTML tags or Dreamweaver regions as custom fields 44 | * option to remove imported title from within content area 45 | * fallbacks: if your chosen tag/area is empty or does not exist, the importer will select `` for content and `` for the title 46 | * use a custom field named 'post_tag' to import tags from a portion of the file 47 | 48 | See the <a href="http://stephanieleary.com/code/wordpress/html-import/html-import-2-user-guide/">User Guide</a> for details on all the options. 49 | 50 | == Installation == 51 | 52 | 1. Unzip the files and upload the plugin directory to `/wp-content/plugins/` 53 | 1. Activate the plugin through the 'Plugins' menu in WordPress 54 | 1. Go to Settings → HTML Import to begin. You must save the settings before proceeding to Tools → Import → HTML. 55 | 56 | == Frequently Asked Questions == 57 | 58 | = My title imported, but the content was empty! (Or vice versa.) = 59 | 60 | You didn't find the right HTML tag that surrounds the content you wanted to import. Open up one of your old files in a browser and use its inspector (or Firebug) to select the content you want. Look for the tag that surrounds that content and find something unique about it. (An ID attribute is best, but anything <em>unique</em> will work. If it's a table cell, a unique width will do just fine.) The enter the tag name, the attribute name, and the attribute's value into the separate boxes in the Content section of the importer's options page. 61 | 62 | See the <a href="http://stephanieleary.com/code/wordpress/html-import/html-import-2-user-guide/">User Guide</a> for details and examples. 63 | 64 | = Does this work on Windows servers? = 65 | 66 | Yes! Let me know if you encounter any problems. 67 | 68 | = Will the importer duplicate the design of my old site? = 69 | 70 | No. The importer simply extracts the relevant part of each HTML file and copies it into a WordPress post. You'll need to <a href="http://codex.wordpress.org/Theme_Development">create a custom theme</a> if you want to preserve the site's appearance as well as its content. 71 | 72 | = Will this work on large numbers of HTML files? = 73 | 74 | Yes, it has been used to import over a thousand pages, and did so in a couple of minutes. However, you might need to adjust PHP's `max_execution_time` setting as described below. 75 | 76 | = I import a few files and then the script times out. What can I do? = 77 | 78 | The importer will attempt to work around your server's `max_execution_time` setting for PHP (usually 30 seconds), but some servers don't allow this. You can try to increase it by adding a line to your `.htaccess` file: 79 | 80 | `php_value max_execution_time 160` 81 | 82 | If that gets you further but still doesn't finish, just increase the number (it's in seconds). However, note that your host might get irritated with you for hogging the server's resources. If you have a _lot_ of files to import, it's best to install WordPress on your desktop (XAMPP for Windows and MAMP for Macs make it pretty easy) and run the importer there instead of doing it on your live server. 83 | 84 | It's also quite possible that the script is trying to use more memory than your server allows. You can try to change that setting, too, in `.htaccess`: 85 | 86 | `php_value memory_limit 1024M` 87 | 88 | = Should I remove 'images' from the list of skipped directories if I want to import images? = 89 | 90 | The skipped directory setting just tells the importer where to look for HTML files. Linked images will be imported no matter where they're located. 91 | 92 | = Can I import files from another server? = 93 | 94 | No. The files must be on the same server as your WordPress installation. I have no intention of ever making this plugin import files from URLs. You are welcome to fork the code if you want to add this feature. 95 | 96 | == Changelog == 97 | 98 | = 2.6 = 99 | * Removed ancient magic runtime quotes call, wow. 100 | * Checking for empty string instead of empty() to allow for directories named '0' or similar 101 | * Bail out earlier if XML can't be loaded, to avoid fatal errors 102 | * More efficient link rewriting 103 | = 2.5.1 = 104 | * Fixed warnings and notices related to the custom category walker. 105 | * Fixed bug where the page parent option displayed incorrectly in sites with no published pages. 106 | = 2.5 = 107 | * Custom fields can now allow the same HTML tags as content 108 | * Fixed a problem with some image paths 109 | * Made image and link searches case-insensitive (props <a href="https://profiles.wordpress.org/noamcleanforestsolutionscom/">Clean Forest Solutions</a>) 110 | * Fixed some incorrectly escaped options that would trigger translations on things that shouldn't be translated 111 | * Page template selections are now pre-selected when returning to the options page (props <a href="https://profiles.wordpress.org/lee-fent/">Lee Fent</a>) 112 | = 2.4 = 113 | * You can now specify more than one index filename (e.g. 'index.php, default.htm') 114 | * New option to remove the imported title from within the content area 115 | * Fallbacks: if your chosen tag/area is empty or does not exist, the importer will select `<body>` for content and `<title>` for the title. As a last resort, if there is no title, the original file name will become the title. 116 | * You can now use a custom field named 'post_tag' to import tags from a portion of the file 117 | * UI fixes for the custom fields tab 118 | * Bug fix: the importer now correctly recognizes absolute links to images 119 | = 2.3 = 120 | * New option to import an entire file's contents instead of selecting a portion of it. (Props Shawn Zilbert.) 121 | * New option to generate the title from the filename. (Props Shawn Zilbert.) 122 | * New option to preserve the original filename (minus the extension) as the imported page slug. (Sponsored by <a href="http://www.nycinsiderguide.com">NYCinsiderguide.com</a>) 123 | * New option to choose the date from an HTML tag or Dreamweaver region. 124 | * New option to import custom fields. 125 | * UI cleanup. The tabs should work a bit better. 126 | * "asXML() on a non-object" errors should be less frequent now. 127 | * Fixed a problem with file types that would cause blank thumbnails and images. (Props <a href="http://wordpress.org/support/topic/plugin-html-import-2-importing-images-to-media-fix?replies=3">mchev2 and Carsten Bach</a>.) 128 | = 2.2 = 129 | * Now imports media files other than images. Uses `rawurldecode()` to remove junk like `%20` from file names, and thus should now handle situations where your link is something like `my%20file.doc` and your file is actually called `my file.doc`. 130 | * Now handles images with https srcs. 131 | * Removed a pointless security check that was preventing people from uploading valid image files. 132 | = 2.1 = 133 | * New option to fix internal links. Also, the importer now bakes you cookies. (Kidding about the cookies.) (August 23, 2011) 134 | = 2.0.2 = 135 | * Added some helpers to work around servers that do not support PHP's multibyte string functions. (August 12, 2011) 136 | = 2.0.1 = 137 | * Added option to set the page template for hierarchical post types. (August 2, 2011) 138 | = 2.0 = 139 | * New option to import images linked in the imported HTML files. It can handle most relative paths as well as absolute URLs. The report includes a list of the image paths that couldn't be found. 140 | * Now supports all public custom post types and taxonomies (including hierarchical ones). 141 | * Completely different, much better handling of special characters. 142 | * The import screen now lets you upload a single file. 143 | * New user interface. The options form is now broken up into several tabbed sections. Categories and other hierarchical taxonomies are selected with checkboxes. 144 | * The options form is now separate from the importer. It will now check your settings before the importer runs -- for example, you'll get a warning if your beginning directory isn't readable. 145 | * The importer itself is now based on the WordPress import class, which means it looks and works more like other importers. It is located under Tools→Import (but you should visit the settings screen first). 146 | * Files' old URLs are now stored as custom fields in the imported posts. There's now an option to regenerate the redirects for your imported files, which is handy if you changed your permalink structure after you finished importing. 147 | * When importing directories as hierarchical post types (like pages), the importer now uses the default directory file (like index.html) for the parent page's contents. 148 | * Now skips Dreamweaver `_notes` and Frontpage `_vti_cnf` directories automatically. 149 | * Now makes proper use of the Settings API for better security and data validation. 150 | * Help screen and <a href="http://sillybean.net/code/wordpress/html-import-2/user-guide/">user guide</a>. 151 | * Now requires at least WP 3.0. (July 15, 2011) 152 | = 1.30 = 153 | * The '.,..' directories are no longer optional, so you can't accidentally import hundreds of empty posts/pages by removing these from the skipped directories option. 154 | * The beginning directory default is now based on the path to your WordPress installation. There's also a hint shown below the field. This should help people locate their import directory correctly. 155 | * There's now an option to enter your old URL. If you enter it, your .htaccess redirects should work as displayed. If you leave it blank, you'll have to doctor the paths afterward, as before. 156 | * Character encoding is now optional. If your special characters did not import correctly before, try again with this option unchecked (which is now the default). 157 | * Options are now deleted on plugin uninstall instead of deactivate. (Sorry about that.) 158 | * Code cleanup in preparation for version 2.0. (June 24, 2011) 159 | = 1.21 = 160 | * same as 1.2; not sure why the plugin repository can't count 161 | = 1.2 = 162 | * Added custom taxonomy options 163 | * Better handling of mb encoding function and asXML 164 | * Better security checking 165 | * Added translation support (January 24, 2010) 166 | = 1.13 = 167 | * Fixed a bug in 1.11 when importing content specified by a tag (thanks, mjos) 168 | * Added an option to assign a category or tag to all imported posts 169 | * This is 1.12, only uncorrupted (September 13, 2009) 170 | = 1.12 = 171 | * Fixed a bug in 1.11 when importing content specified by a tag (thanks, mjos) 172 | * Added an option to assign a category or tag to all imported posts (September 13, 2009) 173 | = 1.11 = 174 | * Left some debugging code in 1.1, oops! (August 15, 2009) 175 | = 1.1 = 176 | * Added Word cleanup option (August 14, 2009) 177 | = 1.04 = 178 | * Better user capability check (August 3, 2009) 179 | = 1.03 = 180 | * Still better error handling 181 | * minor code cleanup (August 1, 2009) 182 | = 1.02 = 183 | * Better error handling for `fopen` and `file_get_contents` (July 31, 2009) 184 | = 1.01 = 185 | * jQuery bug fixed 186 | * better Windows compatibility (July 31, 2009) 187 | = 1.0 = 188 | * First release (July 26, 2009) 189 | 190 | == Other Notes == 191 | 192 | = Thanks = 193 | 194 | Thanks to... 195 | 196 | * Tom Dyson's <a href="http://wordoff.org/">Wordoff.org</a> for inspiring the Word cleanup option in 1.1. 197 | * Dion Hulse's <a href="http://wordpress.org/extend/plugins/add-from-server/">Add from Server</a> plugin and bbqiguana's <a href="http://wordpress.org/extend/plugins/add-linked-images-to-gallery-v01/">Add Linked Images To Gallery</a> plugin, from which I borrowed a lot of the logic behind the image import feature in 2.0 198 | 199 | == Screenshots == 200 | 201 | 1. Settings for files to import 202 | 2. Content settings 203 | 3. HTML cleanup options 204 | 4. Title and metadata settings 205 | 5. Alternative title specifications 206 | 6. Custom field settings 207 | 7. Category, tag, and taxonomy settings 208 | 8. Import screen (directory/file selection) 209 | 9. Completed import: pages, rewrite rules, and images 210 | 10. Sample directory and file structure 211 | 11. The same site, after the import (directory hierarchy preserved as parent/child pages) -------------------------------------------------------------------------------- /languages/import-html-pages.pot: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2010 2 | # This file is distributed under the same license as the package. 3 | msgid "" 4 | msgstr "" 5 | "Project-Id-Version: \n" 6 | "Report-Msgid-Bugs-To: http://wordpress.org/tag/import-html-pages\n" 7 | "POT-Creation-Date: 2011-07-23 15:49:38+00:00\n" 8 | "MIME-Version: 1.0\n" 9 | "Content-Type: text/plain; charset=UTF-8\n" 10 | "Content-Transfer-Encoding: 8bit\n" 11 | "PO-Revision-Date: 2010-MO-DA HO:MI+ZONE\n" 12 | "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" 13 | "Language-Team: LANGUAGE <LL@li.org>\n" 14 | 15 | #: html-import.php:64 16 | msgid "HTML Import" 17 | msgstr "" 18 | 19 | #: html-import.php:74 20 | msgid "" 21 | "This is a complicated importer with lots of options. If you have never used " 22 | "this importer before, you should take a look at the <a href=\"%s\">User " 23 | "Guide</a>." 24 | msgstr "" 25 | 26 | #: html-import.php:75 27 | msgid "" 28 | "You need to look through the first five tabs and save your settings before " 29 | "you run the importer. The sixth (Tools) contains links to some tools that " 30 | "are helpful after you've imported." 31 | msgstr "" 32 | 33 | #: html-import.php:77 34 | msgid "Tips" 35 | msgstr "" 36 | 37 | #: html-import.php:79 38 | msgid "" 39 | "If there is already some content in this site, you should back up your " 40 | "database before you import." 41 | msgstr "" 42 | 43 | #: html-import.php:80 44 | msgid "Before you import, deactivate any crosspost or notification plugins." 45 | msgstr "" 46 | 47 | #: html-import.php:81 48 | msgid "" 49 | "Try uploading a single file before you run the importer on the whole " 50 | "directory. Check the imported page and see whether you need to adjust your " 51 | "content and/or title settings." 52 | msgstr "" 53 | 54 | #: html-import.php:82 55 | msgid "" 56 | "Need to import both posts and pages? Run the importer on a subdirectory (e." 57 | "g. 'news'), then add the subdirectory name to the list of skipped " 58 | "directories and run the importer again on the parent directory." 59 | msgstr "" 60 | 61 | #: html-import.php:84 62 | msgid "More Help" 63 | msgstr "" 64 | 65 | #: html-import.php:87 66 | msgid "User Guide" 67 | msgstr "" 68 | 69 | #: html-import.php:88 70 | msgid "Plugin Home Page" 71 | msgstr "" 72 | 73 | #: html-import.php:89 74 | msgid "Support Forum" 75 | msgstr "" 76 | 77 | #: html-import-options.php:5 html-import-options.php:508 78 | msgid "html-files-to-import" 79 | msgstr "" 80 | 81 | #: html-import-options.php:9 82 | msgid "images,includes,Templates" 83 | msgstr "" 84 | 85 | #: html-import-options.php:16 86 | msgid "div" 87 | msgstr "" 88 | 89 | #: html-import-options.php:17 90 | msgid "id" 91 | msgstr "" 92 | 93 | #: html-import-options.php:18 94 | msgid "content" 95 | msgstr "" 96 | 97 | #: html-import-options.php:25 98 | msgid "title" 99 | msgstr "" 100 | 101 | #: html-import-options.php:40 102 | msgid "HTML Import Settings" 103 | msgstr "" 104 | 105 | #: html-import-options.php:50 106 | msgid "" 107 | "Welcome to HTML Import! This is a complicated importer with many options. " 108 | "Please look through all the tabs on this page before running your import." 109 | msgstr "" 110 | 111 | #: html-import-options.php:56 html-import-options.php:68 112 | msgid "Files" 113 | msgstr "" 114 | 115 | #: html-import-options.php:57 html-import-options.php:129 116 | msgid "Content" 117 | msgstr "" 118 | 119 | #: html-import-options.php:58 html-import-options.php:270 120 | #: html-importer.php:637 121 | msgid "Title" 122 | msgstr "" 123 | 124 | #: html-import-options.php:59 html-import-options.php:336 125 | msgid "Metadata" 126 | msgstr "" 127 | 128 | #: html-import-options.php:60 129 | msgid "Categories, Tags, Taxonomies" 130 | msgstr "" 131 | 132 | #: html-import-options.php:61 html-import-options.php:449 133 | msgid "Tools" 134 | msgstr "" 135 | 136 | #: html-import-options.php:71 137 | msgid "Directory to import" 138 | msgstr "" 139 | 140 | #: html-import-options.php:76 141 | msgid "The absolute path to the files you want to import." 142 | msgstr "" 143 | 144 | #: html-import-options.php:77 145 | msgid "Hint: the absolute path to this WordPress installation is: %s" 146 | msgstr "" 147 | 148 | #: html-import-options.php:83 149 | msgid "Old site URL" 150 | msgstr "" 151 | 152 | #: html-import-options.php:87 153 | msgid "" 154 | "This will be used only to generate accurate <kbd>.htaccess</kbd> redirects. " 155 | "The importer will not search for files here." 156 | msgstr "" 157 | 158 | #: html-import-options.php:93 159 | msgid "Default file" 160 | msgstr "" 161 | 162 | #: html-import-options.php:97 163 | msgid "" 164 | "Enter the name of the default file (index.html, default.htm) for directories " 165 | "on this server." 166 | msgstr "" 167 | 168 | #: html-import-options.php:103 169 | msgid "File extensions to include" 170 | msgstr "" 171 | 172 | #: html-import-options.php:107 173 | msgid "" 174 | "File extensions, without periods, separated by commas. All other file types " 175 | "will \n" 176 | "\t\t\t\t\t\t\tbe ignored." 177 | msgstr "" 178 | 179 | #: html-import-options.php:114 180 | msgid "Directories to exclude" 181 | msgstr "" 182 | 183 | #: html-import-options.php:118 184 | msgid "" 185 | "Directory names, without slashes, separated by commas. All files in these " 186 | "directories \n" 187 | "\t\t\t\t\t\t\twill be ignored." 188 | msgstr "" 189 | 190 | #: html-import-options.php:132 191 | msgid "Select content by" 192 | msgstr "" 193 | 194 | #: html-import-options.php:137 html-import-options.php:278 195 | msgid "HTML tag" 196 | msgstr "" 197 | 198 | #: html-import-options.php:143 html-import-options.php:176 199 | #: html-import-options.php:284 html-import-options.php:317 200 | msgid "Dreamweaver template region" 201 | msgstr "" 202 | 203 | #: html-import-options.php:150 html-import-options.php:291 204 | msgid "Tag" 205 | msgstr "" 206 | 207 | #: html-import-options.php:154 html-import-options.php:295 208 | msgid "The HTML tag, without brackets" 209 | msgstr "" 210 | 211 | #: html-import-options.php:157 html-import-options.php:298 212 | msgid "Attribute" 213 | msgstr "" 214 | 215 | #: html-import-options.php:161 216 | msgid "" 217 | "Leave blank to use a tag without an attribute, or when the attributes don't " 218 | "matter, such as <body>" 219 | msgstr "" 220 | 221 | #: html-import-options.php:164 html-import-options.php:305 222 | msgid "= Value" 223 | msgstr "" 224 | 225 | #: html-import-options.php:168 html-import-options.php:309 226 | msgid "" 227 | "Enter the attribute's value (such as width, ID, or class name) without quotes" 228 | msgstr "" 229 | 230 | #: html-import-options.php:179 231 | msgid "The name of the editable region (e.g. 'Main Content')" 232 | msgstr "" 233 | 234 | #: html-import-options.php:183 235 | msgid "More content options" 236 | msgstr "" 237 | 238 | #: html-import-options.php:186 239 | msgid "Import linked images" 240 | msgstr "" 241 | 242 | #: html-import-options.php:193 243 | msgid "Use meta description as excerpt" 244 | msgstr "" 245 | 246 | #: html-import-options.php:200 247 | msgid "Convert special characters (accents and symbols)" 248 | msgstr "" 249 | 250 | #: html-import-options.php:208 251 | msgid "Clean up bad (Word, Frontpage) HTML" 252 | msgstr "" 253 | 254 | #: html-import-options.php:213 255 | msgid "Allowed HTML" 256 | msgstr "" 257 | 258 | #: html-import-options.php:217 259 | msgid "" 260 | "Enter tags (with brackets) to be preserved. All tags not listed here will be " 261 | "removed. <br />Suggested: " 262 | msgstr "" 263 | 264 | #: html-import-options.php:242 265 | msgid "If you have data tables, also include:" 266 | msgstr "" 267 | 268 | #: html-import-options.php:256 269 | msgid "Allowed attributes" 270 | msgstr "" 271 | 272 | #: html-import-options.php:260 273 | msgid "" 274 | "Enter attributes separated by commas. All attributes not listed here will be " 275 | "removed. <br />Suggested: href,src,alt,title<br />\n" 276 | "\t\t\t \t\t\t<em>If you have data tables, also include:</em> summary," 277 | "rowspan,colspan,span" 278 | msgstr "" 279 | 280 | #: html-import-options.php:273 281 | msgid "Select title by" 282 | msgstr "" 283 | 284 | #: html-import-options.php:302 285 | msgid "" 286 | "Leave blank to use a tag without an attribute, or when the attributes don't " 287 | "matter, such as <title>" 288 | msgstr "" 289 | 290 | #: html-import-options.php:320 291 | msgid "The name of the editable region (e.g. 'Page Title')" 292 | msgstr "" 293 | 294 | #: html-import-options.php:324 295 | msgid "Phrase to remove from page title: " 296 | msgstr "" 297 | 298 | #: html-import-options.php:327 299 | msgid "" 300 | "Any common title phrase (such as the site name, which most themes will print " 301 | "automatically)" 302 | msgstr "" 303 | 304 | #: html-import-options.php:339 305 | msgid "Import files as" 306 | msgstr "" 307 | 308 | #: html-import-options.php:360 309 | msgid "Set status to" 310 | msgstr "" 311 | 312 | #: html-import-options.php:363 313 | msgid "publish" 314 | msgstr "" 315 | 316 | #: html-import-options.php:364 317 | msgid "draft" 318 | msgstr "" 319 | 320 | #: html-import-options.php:365 321 | msgid "private" 322 | msgstr "" 323 | 324 | #: html-import-options.php:366 325 | msgid "pending" 326 | msgstr "" 327 | 328 | #: html-import-options.php:371 329 | msgid "Set timestamps to" 330 | msgstr "" 331 | 332 | #: html-import-options.php:374 333 | msgid "now" 334 | msgstr "" 335 | 336 | #: html-import-options.php:376 337 | msgid "last time the file was modified" 338 | msgstr "" 339 | 340 | #: html-import-options.php:381 341 | msgid "Set author to" 342 | msgstr "" 343 | 344 | #: html-import-options.php:387 345 | msgid "Import pages as children of: " 346 | msgstr "" 347 | 348 | #: html-import-options.php:390 html-import-options.php:391 349 | msgid "None (top level)" 350 | msgstr "" 351 | 352 | #: html-import-options.php:402 353 | msgid "Taxonomies" 354 | msgstr "" 355 | 356 | #: html-import-options.php:410 357 | msgid "" 358 | "Assign categories, tags, and custom taxonomy terms to your imported posts:" 359 | msgstr "" 360 | 361 | #: html-import-options.php:452 362 | msgid "Regenerate <kbd>.htaccess</kbd> redirects" 363 | msgstr "" 364 | 365 | #: html-import-options.php:453 366 | msgid "" 367 | "If you <a href=\"%s\">changed your permalink structure</a> after you " 368 | "imported files, you can <a href=\"%s\">regenerate the redirects</a>." 369 | msgstr "" 370 | 371 | #: html-import-options.php:456 372 | msgid "Other helpful plugins" 373 | msgstr "" 374 | 375 | #: html-import-options.php:458 376 | msgid "" 377 | "<a href=\"%s\">Broken Link Checker</a> finds broken links and references to " 378 | "missing media files. Since the importer does not handle links or media files " 379 | "other than images, you should run this to see what else needs to be copied " 380 | "or updated from your old site." 381 | msgstr "" 382 | 383 | #: html-import-options.php:459 384 | msgid "" 385 | "<a href=\"%s\">Search and Replace</a> helps you fix many broken links at " 386 | "once, if you have many links to the same files or if there is a pattern " 387 | "(like <kbd><a href=\"../../files\"></kbd>) to your broken links." 388 | msgstr "" 389 | 390 | #: html-import-options.php:460 391 | msgid "" 392 | "<a href=\"%s\">Redirection</a> provides a nice admin interface for managing " 393 | "redirects. If you would rather not edit your <kbd>.htaccess</kbd> file, or " 394 | "if you just want to redirect one or two of your old pages, you can ignore " 395 | "the redirects generated by the importer. Instead, copy the post's old URL " 396 | "from the custom fields and paste it into Redirection's options." 397 | msgstr "" 398 | 399 | #: html-import-options.php:461 400 | msgid "" 401 | "<a href=\"%s\">Add from Server</a> lets you import media files that are on " 402 | "your server but not part of the WordPress media library." 403 | msgstr "" 404 | 405 | #: html-import-options.php:462 406 | msgid "" 407 | "<a href=\"%s\">Add Linked Images to Gallery</a> is helpful if you have " 408 | "imported data using other plugins and you would like to import linked " 409 | "images. However, it handles only images that are referenced with complete " 410 | "URLs; relative paths will not work." 411 | msgstr "" 412 | 413 | #: html-import-options.php:466 414 | msgid "Donate" 415 | msgstr "" 416 | 417 | #: html-import-options.php:468 418 | msgid "" 419 | "If this importer has saved you hours of copying and pasting, a <a href=\"%s" 420 | "\">donation toward future development</a> would be much appreciated!" 421 | msgstr "" 422 | 423 | #: html-import-options.php:475 424 | msgid "Save settings" 425 | msgstr "" 426 | 427 | #: html-import-options.php:507 html-importer.php:677 428 | msgid "" 429 | "The beginning directory you entered is not an absolute path. Relative paths " 430 | "are not allowed here." 431 | msgstr "" 432 | 433 | #: html-import-options.php:554 434 | msgid "You did not enter an HTML content tag to import." 435 | msgstr "" 436 | 437 | #: html-import-options.php:556 438 | msgid "You did not enter a Dreamweaver content template region to import." 439 | msgstr "" 440 | 441 | #: html-import-options.php:558 442 | msgid "You did not enter an HTML title tag to import." 443 | msgstr "" 444 | 445 | #: html-import-options.php:560 446 | msgid "You did not enter a Dreamweaver title template region to import." 447 | msgstr "" 448 | 449 | #: html-import-options.php:596 450 | msgid "" 451 | "If you intend to <a href=\"%s\">set a permalink structure</a>, you should do " 452 | "it \n" 453 | "\t\t\t\tbefore importing so the <kbd>.htaccess</kbd> redirects will be " 454 | "accurate." 455 | msgstr "" 456 | 457 | #: html-import-options.php:599 458 | msgid "Settings saved. %s <a href=\"%s\">Ready to import files?</a>" 459 | msgstr "" 460 | 461 | #: html-importer.php:24 462 | msgid "HTML Importer" 463 | msgstr "" 464 | 465 | #: html-importer.php:37 466 | msgid "" 467 | "It looks like you have not yet visited the <a href=\"%s\">HTML Import " 468 | "options page</a>. Please do so now! You need to specify which portions of " 469 | "your HTML files should be imported before you proceed." 470 | msgstr "" 471 | 472 | #: html-importer.php:40 473 | msgid "What are you importing today?" 474 | msgstr "" 475 | 476 | #: html-importer.php:45 477 | msgid "a directory of files" 478 | msgstr "" 479 | 480 | #: html-importer.php:48 481 | msgid "a single file" 482 | msgstr "" 483 | 484 | #: html-importer.php:52 485 | msgid "Choose an HTML file from your computer:" 486 | msgstr "" 487 | 488 | #: html-importer.php:58 489 | msgid "" 490 | "Your files will be imported from <kbd>%s</kbd>. <a href=\"%s\">Change " 491 | "directories</a>." 492 | msgstr "" 493 | 494 | #: html-importer.php:65 495 | msgid "Submit" 496 | msgstr "" 497 | 498 | #: html-importer.php:82 html-importer.php:644 499 | msgid ".htaccess Redirects" 500 | msgstr "" 501 | 502 | #: html-importer.php:83 503 | msgid "" 504 | "Copy these lines into your <kbd>.htaccess</kbd> <em>above</em> the WordPress " 505 | "section." 506 | msgstr "" 507 | 508 | #: html-importer.php:85 509 | msgid "" 510 | "All done! You can <a href=\"%s\">change your permalink structure</a> and <a " 511 | "href=\"%s\">regenerate the redirects again</a>, or <a href=\"%s\">start " 512 | "over</a>." 513 | msgstr "" 514 | 515 | #: html-importer.php:87 516 | msgid "" 517 | "No posts were found with the URL_before_HTML_Import custom field. Could not " 518 | "generate rewrite rules." 519 | msgstr "" 520 | 521 | #: html-importer.php:387 522 | msgid "the uploaded file" 523 | msgstr "" 524 | 525 | #: html-importer.php:393 526 | msgid "%s (%s) has already been imported" 527 | msgstr "" 528 | 529 | #: html-importer.php:413 530 | msgid "Could not import %s. You should copy its contents manually." 531 | msgstr "" 532 | 533 | #: html-importer.php:448 534 | msgid "Imported the file as %s." 535 | msgstr "" 536 | 537 | #: html-importer.php:471 538 | msgid "Sorry, this file type is not permitted for security reasons." 539 | msgstr "" 540 | 541 | #: html-importer.php:479 542 | msgid "" 543 | "Could not find the right path to %s (tried %s). It could not be imported. " 544 | "Please upload it manually." 545 | msgstr "" 546 | 547 | #: html-importer.php:562 548 | msgid "Found %d image in <a href=\"%s\">%s</a>. Importing... " 549 | msgid_plural "Found %d images in <a href=\"%s\">%s</a>. Importing... " 550 | msgstr[0] "" 551 | msgstr[1] "" 552 | 553 | #: html-importer.php:607 554 | msgid "done." 555 | msgstr "" 556 | 557 | #: html-importer.php:614 558 | msgid "Importing images..." 559 | msgstr "" 560 | 561 | #: html-importer.php:622 562 | msgid "All done. <a href=\"%s\">Go to the Media Library.</a>" 563 | msgstr "" 564 | 565 | #: html-importer.php:634 566 | msgid "ID" 567 | msgstr "" 568 | 569 | #: html-importer.php:635 570 | msgid "Old path" 571 | msgstr "" 572 | 573 | #: html-importer.php:636 574 | msgid "New path" 575 | msgstr "" 576 | 577 | #: html-importer.php:646 578 | msgid "" 579 | "If you need to <a href=\"%s\">change your permalink structure</a>, you can " 580 | "<a href=\"%s\">regenerate the redirects</a> (or do it later from the <a href=" 581 | "\"%s\">options screen</a> under Tools)." 582 | msgstr "" 583 | 584 | #: html-importer.php:650 585 | msgid "All done. <a href=\"%s\">Have fun!</a>" 586 | msgstr "" 587 | 588 | #: html-importer.php:666 589 | msgid "Importing HTML file..." 590 | msgstr "" 591 | 592 | #: html-importer.php:686 593 | msgid "Importing HTML files..." 594 | msgstr "" 595 | 596 | #: html-importer.php:693 597 | msgid "Your file upload didn't work. Try again?" 598 | msgstr "" 599 | 600 | #: html-importer.php:745 601 | msgid "HTML" 602 | msgstr "" 603 | 604 | #: html-importer.php:745 605 | msgid "" 606 | "Import the contents of HTML files as posts, pages, or any custom post type. " 607 | "Visit <a href=\"%s\">the options page</a> first to select which portions of " 608 | "your documents should be imported." 609 | msgstr "" 610 | -------------------------------------------------------------------------------- /html-import-options.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | function html_import_get_options() { 4 | $defaults = array( 5 | 'root_directory' => ABSPATH.__( 'html-files-to-import', 'import-html-pages' ), 6 | 'old_url' => '', 7 | 'index_file' => 'index.html', 8 | 'file_extensions' => 'html,htm,shtml', 9 | 'skipdirs' => __( 'images,includes,Templates', 'import-html-pages' ), 10 | 'preserve_slugs' => 0, 11 | 'status' => 'publish', 12 | 'root_parent' => 0, 13 | 'type' => 'page', 14 | 'timestamp' => 'filemtime', 15 | 'import_content' => 0, 16 | 'content_region' => '', 17 | 'content_tag' => __( 'div', 'import-html-pages' ), 18 | 'content_tagatt' => __( 'id', 'import-html-pages' ), 19 | 'content_attval' => __( 'content', 'import-html-pages' ), 20 | 'clean_html' => 0, 21 | 'encode' => 1, 22 | 'allow_tags' => '<p><br><img><a><ul><ol><li><dl><dt><dd><blockquote><cite><em><i><strong><b><h2><h3><h4><h5><h6><hr>', 23 | 'allow_attributes' => 'href,alt,title,src', 24 | 'import_images' => 0, 25 | 'remove_srcset' => 0, 26 | 'import_documents' => 0, 27 | 'document_mimes' => 'rtf,doc,docx,xls,xlsx,csv,ppt,pps,pptx,ppsx,pdf,zip,wmv,avi,flv,mov,mpeg,mp3,m4a,wav', 28 | 'fix_links' => 0, 29 | 'import_title' => 0, 30 | 'title_region' => '', 31 | 'title_tag' => __( 'title', 'import-html-pages' ), 32 | 'title_tagatt' => '', 33 | 'title_attval' => '', 34 | 'remove_from_title' => '', 35 | 'title_inside' => 0, 36 | 'meta_desc' => 1, 37 | 'user' => 0, 38 | 'page_template' => 0, 39 | 'firstrun' => true, 40 | 'import_date' => 0, 41 | 'date_region' => '', 42 | 'date_tag' => __( 'div', 'import-html-pages' ), 43 | 'date_tagatt' => __( 'id', 'import-html-pages' ), 44 | 'date_attval' => __( 'date', 'import-html-pages' ), 45 | 'import_field' => array( '0' ), 46 | 'customfield_name' => array( '' ), 47 | 'customfield_region' => array( '' ), 48 | 'customfield_tag' => array( __( 'div', 'import-html-pages' ) ), 49 | 'customfield_tagatt' => array( __( 'class', 'import-html-pages' ) ), 50 | 'customfield_attval' => array( __( 'fieldclass', 'import-html-pages' ) ), 51 | 'customfield_html' => array( '' ) 52 | ); 53 | $options = get_option( 'html_import' ); 54 | if ( !is_array( $options ) ) $options = array(); 55 | return array_merge( $defaults, $options ); 56 | } 57 | 58 | function html_import_options_page() { ?> 59 | <div class="wrap"> 60 | 61 | <form method="post" id="html_import" action="options.php"> 62 | <?php 63 | settings_fields( 'html_import' ); 64 | get_settings_errors( 'html_import' ); 65 | $options = html_import_get_options(); 66 | //$msg .= '<pre>'. print_r( $options, true ) .'</pre>'; 67 | //echo esc_html( $msg ); 68 | ?> 69 | 70 | <div class="ui-tabs"> 71 | 72 | 73 | <h2><?php _e( 'HTML Import Settings', 'import-html-pages' ); ?></h2> 74 | <?php 75 | if ( $options['firstrun'] === true ) { 76 | echo '<p>'.sprintf( __( 'Welcome to HTML Import! This is a complicated importer with many options. Please look through all the tabs on this page before running your import.', 'import-html-pages' ), 'options-general.php?page=html-import.php' ).'</p>'; 77 | } 78 | ?> 79 | <h2 class="nav-tab-wrapper"> 80 | <ul class="ui-tabs-nav"> 81 | <li><a class="nav-tab" href="#tabs-1"><?php _e( "Files", 'import-html-pages' ); ?></a></li> 82 | <li><a class="nav-tab" href="#tabs-2"><?php _e( "Content", 'import-html-pages' ); ?></a></li> 83 | <li><a class="nav-tab" href="#tabs-3"><?php _e( "Title & Metadata", 'import-html-pages' ); ?></a></li> 84 | <li><a class="nav-tab" href="#tabs-4"><?php _e( "Custom Fields", 'import-html-pages' ); ?></a></li> 85 | <li><a class="nav-tab" href="#tabs-5"><?php _e( "Categories & Tags", 'import-html-pages' ); ?></a></li> 86 | <li><a class="nav-tab" href="#tabs-6"><?php _e( "Tools", 'import-html-pages' ); ?></a></li> 87 | </ul> 88 | </h2> 89 | 90 | 91 | 92 | <!-- FILES --> 93 | <div id="tabs-1"> 94 | <h3><?php _e( "Files", 'import-html-pages' ); ?></h3> 95 | <table class="form-table ui-tabs-panel" id="files"> 96 | <tr valign="top"> 97 | <th scope="row"><?php _e( "Directory to import", 'import-html-pages' ); ?></th> 98 | <td><p><label><input type="text" name="html_import[root_directory]" id="root_directory" 99 | value="<?php echo esc_attr( $options['root_directory'] ); ?>" class="widefloat" /> 100 | </label><br /> 101 | <span class="description"> 102 | <?php _e( 'The absolute path to the files you want to import.', 'html-import-pages' ); ?><br /> 103 | <?php printf( __( 'Hint: the absolute path to this WordPress installation is: %s', 'html-import-pages' ), '<kbd>'.rtrim( ABSPATH, '/' ).'</kbd>' ); ?> 104 | </span> 105 | </p></td> 106 | </tr> 107 | 108 | <tr valign="top"> 109 | <th scope="row"><?php _e( "Old site URL", 'import-html-pages' ); ?></th> 110 | <td><p><label><input type="text" name="html_import[old_url]" id="old_url" 111 | value="<?php echo esc_attr( $options['old_url'] ); ?>" class="widefloat" /> </label><br /> 112 | <span class="description"> 113 | <?php _e( 'This will be used only to generate accurate <kbd>.htaccess</kbd> redirects. The importer will not search for files here.', 'html-import-pages' ); ?> 114 | </span> 115 | </p></td> 116 | </tr> 117 | 118 | <tr valign="top"> 119 | <th scope="row"><?php _e( "Default file", 'import-html-pages' ); ?></th> 120 | <td><p><label><input type="text" name="html_import[index_file]" id="index_file" 121 | value="<?php echo esc_attr( $options['index_file'] ); ?>" class="widefloat" /> </label><br /> 122 | <span class="description"> 123 | <?php _e( "Enter the name of the default file ( index.html, default.htm ) for directories on this server.", 'import-html-pages' ); ?> 124 | </span> 125 | </p></td> 126 | </tr> 127 | 128 | <tr valign="top"> 129 | <th scope="row"><?php _e( "File extensions to include", 'import-html-pages' ); ?></th> 130 | <td><p><label><input type="text" name="html_import[file_extensions]" id="file_extensions" 131 | value="<?php echo esc_attr( $options['file_extensions'] ); ?>" class="widefloat" /> </label><br /> 132 | <span class="description"> 133 | <?php _e( "File extensions, without periods, separated by commas. All other file types will 134 | be ignored.", 'import-html-pages' ); ?> 135 | </span> 136 | </p></td> 137 | </tr> 138 | 139 | <tr valign="top"> 140 | <th scope="row"><?php _e( "Directories to exclude", 'import-html-pages' ); ?></th> 141 | <td><p><label><input type="text" name="html_import[skipdirs]" id="skipdirs" 142 | value="<?php echo esc_attr( $options['skipdirs'] ); ?>" class="widefloat" /> </label><br /> 143 | <span class="description"> 144 | <?php _e( "Directory names, without slashes, separated by commas. All files in these directories 145 | will be ignored.", 'import-html-pages' ); ?> 146 | </span> 147 | </p></td> 148 | </tr> 149 | 150 | <tr valign="top"> 151 | <th scope="row"><?php _e( "Preserve file names", 'import-html-pages' ); ?></th> 152 | <td><p> 153 | 154 | <label><input name="html_import[preserve_slugs]" id="preserve_slugs" value="1" type="checkbox" <?php checked( $options['preserve_slugs'] ); ?> /> 155 | <?php _e( "Use the file's name as the imported page's slug", 'import-html-pages' ); ?></label> 156 | <br /> 157 | <span class="description"> 158 | <?php _e( "The slug will not include the file extension. To completely mimic your old URLs, add the extension to your permalink structure.", 'import-html-pages' ); ?> 159 | </span> 160 | </p></td> 161 | </tr> 162 | </table> 163 | 164 | </div> 165 | 166 | <!-- CONTENT --> 167 | <div id="tabs-2"> 168 | <h3><?php _e( "Content", 'import-html-pages' ); ?></h3> 169 | <table class="form-table ui-tabs-panel" id="content"> 170 | <tr valign="top" id="contentselect"> 171 | <th scope="row"><?php _e( "Select content by", 'import-html-pages' ); ?></th> 172 | <td><p><label> 173 | <input type="radio" name="html_import[import_content]" 174 | value="tag" <?php checked( $options['import_content'], 'tag' ); ?> class="showrow" title="content" /> 175 | <?php _e( 'HTML tag', 'import-html-pages' ); ?></label> 176 |    177 | <label> 178 | <input type="radio" name="html_import[import_content]" 179 | value="region" <?php checked( $options['import_content'], 'region' ); ?> class="showrow" title="content" /> 180 | <?php _e( 'Dreamweaver template region', 'import-html-pages' ); ?></label> 181 |    182 | <label> 183 | <input type="radio" name="html_import[import_content]" 184 | value="file" <?php checked( $options['import_content'], 'file' ); ?> class="showrow" title="content" /> 185 | <?php _e( 'Import entire file', 'import-html-pages' ); ?></label> 186 | </p> 187 | 188 | 189 | <table> 190 | <tr id="content-tag" <?php if ( $options['import_content'] != 'tag' ) echo 'style="display: none;"'; ?>> 191 | <td class="taginput"> 192 | <label><?php _e( "Tag", 'import-html-pages' ); ?><br /> 193 | <input type="text" name="html_import[content_tag]" id="content_tag" value="<?php echo esc_attr( $options['content_tag'] ); ?>" /> 194 | </label> 195 | <br /> 196 | <span class="description"><?php _e( "The HTML tag, without brackets", 'import-html-pages' ); ?></span> 197 | </td> 198 | <td class="taginput"> 199 | <label><?php _e( "Attribute", 'import-html-pages' ); ?><br /> 200 | <input type="text" name="html_import[content_tagatt]" id="content_tagatt" value="<?php echo esc_attr( $options['content_tagatt'] ); ?>" /> 201 | </label> 202 | <br /> 203 | <span class="description"><?php _e( "Leave blank to use a tag without an attribute, or when the attributes don't matter, such as <body>", 'import-html-pages' ); ?></span> 204 | </td> 205 | <td class="taginput"> 206 | <label><?php _e( "= Value", 'import-html-pages' ); ?><br /> 207 | <input type="text" name="html_import[content_attval]" id="content_attval" value="<?php echo esc_attr( $options['content_attval'] ); ?>" /> 208 | </label> 209 | <br /> 210 | <span class="description"><?php _e( "Enter the attribute's value ( such as width, ID, or class name ) without quotes", 'import-html-pages' ); ?></span> 211 | </td> 212 | </tr> 213 | <tr id="content-region" <?php if ( $options['import_content'] != 'region' ) echo 'style="display: none;"'; ?>> 214 | <td colspan="3"> 215 | <label><?php _e( "Dreamweaver template region", 'import-html-pages' ); ?><br /> 216 | <input type="text" name="html_import[content_region]" value="<?php echo esc_attr( $options['content_region'] ); ?>" /> 217 | </label><br /> 218 | <span class="description"><?php _e( "The name of the editable region ( e.g. 'Main Content' )", 'import-html-pages' ); ?></span> 219 | </td> 220 | </tr> 221 | </table> 222 | 223 | </td> 224 | </tr> 225 | 226 | <tr> 227 | <th><?php _e( "More content options", 'import-html-pages' ); ?></th> 228 | <td> 229 | <label><input name="html_import[import_images]" id="import_images" type="checkbox" value="1" 230 | <?php checked( $options['import_images'], '1' ); ?> /> <?php _e( "Import linked images", 'import-html-pages' ); ?></label> 231 | </td> 232 | </tr> 233 | <tr> 234 | <th></th> 235 | <td> 236 | <label><input name="html_import[remove_srcset]" id="remove_srcset" type="checkbox" value="1" 237 | <?php checked( $options['remove_srcset'], '1' ); ?> /> <?php _e( "Remove responsive image srcsets", 'import-html-pages' ); ?></label> 238 | </td> 239 | </tr> 240 | <tr> 241 | <th></th> 242 | <td> 243 | <label><input name="html_import[import_documents]" id="import_documents" value="1" type="checkbox" <?php checked( $options['import_documents'] ); ?> class="toggle" /> 244 | <?php _e( "Import linked documents", 'import-html-pages' ); ?></label> 245 | </td> 246 | </tr> 247 | <tr class="import_documents" 248 | <?php if ( isset( $options['import_documents'] ) && !$options['import_documents'] ) echo 'style="display:none;"'; ?>> 249 | <th><?php _e( "Allowed file types", 'import-html-pages' ); ?></th> 250 | <td><label> 251 | <input type="text" name="html_import[document_mimes]" id="document_mimes" 252 | value="<?php echo esc_attr( $options['document_mimes'] ); ?>" class="widefloat" /> </label><br /> 253 | <span class="description"><?php _e( "Enter file extensions without periods, separated by commas. File types not listed here will not be imported to the media library. <br /> 254 | Suggested: rtf, doc, docx, xls, xlsx, csv, ppt, pps, pptx, ppsx, pdf, zip, wmv, avi, flv, mov, mpeg, mp3, m4a, wav<br />", 'import-html-pages' ); ?></span> 255 | </td> 256 | </tr> 257 | <tr> 258 | <th></th> 259 | <td> 260 | <label><input name="html_import[fix_links]" id="fix_links" value="1" type="checkbox" <?php checked( $options['fix_links'] ); ?> /> 261 | <?php _e( "Update internal links", 'import-html-pages' ); ?></label> 262 | </td> 263 | </tr> 264 | <th></th> 265 | <td> 266 | <label><input name="html_import[meta_desc]" id="meta_desc" value="1" type="checkbox" <?php checked( $options['meta_desc'] ); ?> /> 267 | <?php _e( "Use meta description as excerpt", 'import-html-pages' ); ?></label> 268 | </td> 269 | </tr> 270 | <tr> 271 | <th></th> 272 | <td> 273 | <label><input name="html_import[encode]" id="encode" type="checkbox" value="1" 274 | <?php checked( $options['encode'], '1' ); ?> /> <?php _e( "Convert special characters ( accents and symbols )", 'import-html-pages' ); ?> </label> 275 | </td> 276 | </tr> 277 | <tr> 278 | <th></th> 279 | <td> 280 | <label><input name="html_import[clean_html]" id="clean_html" type="checkbox" value="1" 281 | <?php checked( $options['clean_html'], '1' ); ?> class="toggle" /> 282 | <?php _e( "Clean up bad ( Word, Frontpage ) HTML", 'import-html-pages' ); ?> </label> 283 | </td> 284 | </tr> 285 | <tr class="clean_html" <?php if ( !$options['clean_html'] ) echo 'style="display:none;"'; ?>> 286 | 287 | <th><?php _e( "Allowed HTML", 'import-html-pages' ); ?></th> 288 | <td> <label> 289 | <input type="text" name="html_import[allow_tags]" id="allow_tags" 290 | value="<?php echo esc_attr( $options['allow_tags'] ); ?>" class="widefloat" /> </label><br /> 291 | <span class="description"><?php _e( "Enter tags ( with brackets ) to be preserved. All tags not listed here will be removed. <br />Suggested: ", 'import-html-pages' ); ?> 292 | <p> 293 | <br> 294 | <img> 295 | <a> 296 | <ul> 297 | <ol> 298 | <li> 299 | <dl> 300 | <dt> 301 | <dd> 302 | <blockquote> 303 | <cite> 304 | <em> 305 | <i> 306 | <strong> 307 | <b> 308 | <h2> 309 | <h3> 310 | <h4> 311 | <h5> 312 | <h6> 313 | <hr> 314 | <br /> 315 | 316 | <em><?php _e( "If you have data tables, also include:", 'import-html-pages' ); ?></em> 317 | <table> 318 | <tbody> 319 | <thead> 320 | <tfoot> 321 | <tr> 322 | <td> 323 | <th> 324 | <caption> 325 | <colgroup> 326 | </span> 327 | </td> 328 | </tr> 329 | <tr class="clean_html" <?php if ( !$options['clean_html'] ) echo 'style="display:none;"'; ?>> 330 | <th><?php _e( "Allowed attributes", 'import-html-pages' ); ?></th> 331 | <td><label> 332 | <input type="text" name="html_import[allow_attributes]" id="allow_attributes" 333 | value="<?php echo esc_attr( $options['allow_attributes'] ); ?>" class="widefloat" /> </label><br /> 334 | <span class="description"><?php _e( "Enter attributes separated by commas. All attributes not listed here will be removed. <br />Suggested: href, src, alt, title<br /> 335 | <em>If you have data tables, also include:</em> summary, rowspan, colspan, span", 'import-html-pages' ); ?></span> 336 | </td> 337 | </tr> 338 | </table> 339 | 340 | </div> 341 | 342 | <!-- TITLE AND META --> 343 | <div id="tabs-3"> 344 | <h3><?php _e( "Title & Metadata", 'import-html-pages' ); ?></h3> 345 | <table class="form-table ui-tabs-panel" id="title"> 346 | <tr valign="top" id="titleselect"> 347 | <th scope="row"><?php _e( "Select title by", 'import-html-pages' ); ?></th> 348 | <td><p><label> 349 | <input type="radio" name="html_import[import_title]" 350 | value="tag" <?php checked( $options['import_title'], 'tag' ); ?> class="showrow" title="title" /> 351 | <?php _e( 'HTML tag', 'import-html-pages' ); ?></label> 352 |    353 | <label> 354 | <input type="radio" name="html_import[import_title]" 355 | value="region" <?php checked( $options['import_title'], 'region' ); ?> class="showrow" title="title" /> 356 | <?php _e( 'Dreamweaver template region', 'import-html-pages' ); ?></label> 357 |    358 | <label> 359 | <input type="radio" name="html_import[import_title]" 360 | value="filename" <?php checked( $options['import_title'], 'filename' ); ?> class="showrow" title="title" /> 361 | <?php _e( 'File name', 'import-html-pages' ); ?></label> 362 | </p> 363 | 364 | 365 | <table> 366 | <tr id="title-tag" <?php if ( $options['import_title'] !== 'tag' ) echo 'style="display:none;"'; ?> > 367 | <td class="taginput"> 368 | <label><?php _e( "Tag", 'import-html-pages' ); ?><br /> 369 | <input type="text" name="html_import[title_tag]" id="title_tag" value="<?php echo esc_attr( $options['title_tag'] ); ?>" /> 370 | </label> 371 | <br /> 372 | <span class="description"><?php _e( "The HTML tag, without brackets", 'import-html-pages' ); ?></span> 373 | </td> 374 | <td class="taginput"> 375 | <label><?php _e( "Attribute", 'import-html-pages' ); ?><br /> 376 | <input type="text" name="html_import[title_tagatt]" id="title_tagatt" value="<?php echo esc_attr( $options['title_tagatt'] ); ?>" /> 377 | </label> 378 | <br /> 379 | <span class="description"><?php _e( "Leave blank to use a tag without an attribute, or when the attributes don't matter, such as <title>", 'import-html-pages' ); ?></span> 380 | </td> 381 | <td class="taginput"> 382 | <label><?php _e( "= Value", 'import-html-pages' ); ?><br /> 383 | <input type="text" name="html_import[title_attval]" id="title_attval" value="<?php echo esc_attr( $options['title_attval'] ); ?>" /> 384 | </label> 385 | <br /> 386 | <span class="description"><?php _e( "Enter the attribute's value ( such as width, ID, or class name ) without quotes", 'import-html-pages' ); ?></span> 387 | </td> 388 | </tr> 389 | 390 | 391 | <tr id="title-region" <?php if ( $options['import_title'] !== 'region' ) echo 'style="display:none;"'; ?> > 392 | <td class="taginput"> 393 | <td colspan="3"> 394 | <label><?php _e( "Dreamweaver template region", 'import-html-pages' ); ?><br /> 395 | <input type="text" name="html_import[title_region]" id="title_region" value="<?php echo esc_attr( $options['title_region'] ); ?>" /> 396 | </label><br /> 397 | <span class="description"><?php _e( "The name of the editable region ( e.g. 'Page Title' )", 'import-html-pages' ); ?></span> 398 | </td> 399 | </tr> 400 | </table> 401 | 402 | 403 | </td> 404 | </tr> 405 | 406 | <tr valign="top"> 407 | <th><?php _e( "Phrase to remove from page title: ", 'import-html-pages' ); ?></th> 408 | <td> 409 | <label><input type="text" name="html_import[remove_from_title]" id="remove_from_title" value="<?php echo esc_attr( $options['remove_from_title'] ); ?>" class="widefloat" /> </label><br /> 410 | <span class="description"><?php _e( "Any common title phrase ( such as the site name, which most themes will print automatically )", 'import-html-pages' ); ?></span> 411 | </td> 412 | </tr> 413 | 414 | <tr> 415 | <th><?php _e( "Title position", 'import-html-pages' ); ?></th> 416 | <td> 417 | <label><input name="html_import[title_inside]" id="title_inside" type="checkbox" value="1" 418 | <?php checked( $options['title_inside'], '1' ); ?> /> <?php _e( "The title is inside the content area and should be removed from the post body", 'import-html-pages' ); ?></label> 419 | </td> 420 | </tr> 421 | <tr> 422 | 423 | <tr valign="top"> 424 | <th scope="row"><?php _e( "Import files as", 'import-html-pages' ); ?></th> 425 | <td> 426 | <?php 427 | // support all public post types 428 | $typeselect = ''; 429 | $post_types = get_post_types( array( 'public' => true ), 'objects' ); 430 | foreach ( $post_types as $post_type ) { 431 | if ( $post_type->name != 'attachment' ) { 432 | $typeselect .= '<label><input name="html_import[type]" type="radio" value="' . esc_attr( $post_type->name ) . '" '.checked( $options['type'], $post_type->name, false ); 433 | if ( is_post_type_hierarchical( $post_type->name ) ) 434 | $typeselect .= "onclick=\"javascript: jQuery( '#hierarchy' ).show( 'fast' );jQuery( '#page-template' ).show( 'fast' );\""; 435 | else 436 | $typeselect .= "onclick=\"javascript: jQuery( '#hierarchy' ).hide( 'fast' );jQuery( '#page-template' ).hide( 'fast' );\""; 437 | $typeselect .= '> '.esc_html( $post_type->labels->name ).'</label>   '; 438 | } 439 | } 440 | echo $typeselect; 441 | ?> 442 | </td> 443 | </tr> 444 | <tr> 445 | <th><?php _e( "Set status to", 'import-html-pages' ); ?></th> 446 | <td> 447 | <select name="html_import[status]" id="status"> 448 | <option value="publish" <?php selected( 'publish', $options['status'] ); ?>><?php _e( "publish", 'import-html-pages' ); ?></option> 449 | <option value="draft" <?php selected( 'draft', $options['status'] ); ?>><?php _e( "draft", 'import-html-pages' ); ?></option> 450 | <option value="private" <?php selected( 'private', $options['status'] ); ?>><?php _e( "private", 'import-html-pages' ); ?></option> 451 | <option value="pending" <?php selected( 'pending', $options['status'] ); ?>><?php _e( "pending", 'import-html-pages' ); ?></option> 452 | </select> 453 | </td> 454 | </tr> 455 | <tr> 456 | <th><?php _e( "Set timestamps to", 'import-html-pages' ); ?></th> 457 | <td> 458 | <select name="html_import[timestamp]" id="timestamp"> 459 | <option value="now" <?php if ( $options['timestamp'] == 'now' ) echo 'selected="selected"'; ?>><?php _e( "now", 'import-html-pages' ); ?></option> 460 | <option value="filemtime" <?php if ( $options['timestamp'] == 'filemtime' ) echo 'selected="selected"'; ?>> 461 | <?php _e( "last time the file was modified", 'import-html-pages' ); ?></option> 462 | <option value="customfield" <?php if ( $options['timestamp'] == 'customfield' ) echo 'selected="selected"'; ?>> 463 | <?php _e( "custom field", 'import-html-pages' ); ?></option> 464 | </select> 465 | </td> 466 | </tr> 467 | <tr> 468 | <th><?php _e( "Set author to", 'import-html-pages' ); ?></th> 469 | <td> 470 | <?php wp_dropdown_users( array( 'selected' => $options['user'], 'name' => 'html_import[user]', 'who' => 'authors' ) ); ?> 471 | </td> 472 | </tr> 473 | 474 | <tr id="hierarchy" <?php if ( !is_post_type_hierarchical( $options['type'] ) ) echo "style=display:none;"; ?>> 475 | <th><?php _e( "Import pages as children of: ", 'import-html-pages' ); ?></th> 476 | <td> 477 | <?php 478 | $pages = wp_dropdown_pages( array( 'echo' => 0, 'selected' => $options['root_parent'], 'name' => 'html_import[root_parent]', 'show_option_none' => __( 'None ( top level )', 'import-html-pages' ), 'sort_column'=> 'menu_order, post_title' ) ); 479 | if ( empty( $pages ) ) $pages = "<select name=\"root_parent\"><option value=\"0\">".__( 'None ( top level )', 'import-html-pages' )."</option></select>"; 480 | echo $pages; 481 | ?> 482 | </td> 483 | </tr> 484 | 485 | <tr id="page-template" <?php if ( !is_post_type_hierarchical( $options['type'] ) ) echo "style=display:none;"; ?>> 486 | <th><?php _e( "Template for imported pages: ", 'import-html-pages' ); ?></th> 487 | <td> 488 | <select name="html_import[page_template]" id="page_template"> 489 | <option value='0'><?php _e( 'Default Template' ); ?></option> 490 | <?php page_template_dropdown( $options['page_template'] ); ?> 491 | </select> 492 | </td> 493 | </tr> 494 | </table> 495 | </div> 496 | 497 | 498 | <!-- CUSTOM FIELDS --> 499 | <div id="tabs-4"> 500 | <h3><?php _e( "Custom Fields", 'import-html-pages' ); ?></h3> 501 | <table class="form-table ui-tabs-panel striped" id="customfields"> 502 | <tbody> 503 | <tr valign="top" id="customdatefield"> 504 | <th scope="row"><?php _e( "Select date by", 'import-html-pages' ); ?></th> 505 | <td colspan="2"><p><label> 506 | <input type="radio" name="html_import[import_date]" 507 | value="tag" <?php checked( $options['import_date'], 'tag' ); ?> class="showrow" title="date" /> 508 | <?php _e( 'HTML tag', 'import-html-pages' ); ?></label> 509 |    510 | <label> 511 | <input type="radio" name="html_import[import_date]" 512 | value="region" <?php checked( $options['import_date'], 'region' ); ?> class="showrow" title="date" /> 513 | <?php _e( 'Dreamweaver template region', 'import-html-pages' ); ?></label> 514 | </p> 515 | 516 | 517 | <table> 518 | <tr id="date-tag" <?php if ( $options['import_date'] !== 'tag' ) echo 'style="display: none;"'; ?>> 519 | <td class="taginput"> 520 | <label><?php _e( "Tag", 'import-html-pages' ); ?><br /> 521 | <input type="text" name="html_import[date_tag]" id="date_tag" value="<?php echo esc_attr( $options['date_tag'] ); ?>" /> 522 | </label> 523 | </td> 524 | <td class="taginput"> 525 | <label><?php _e( "Attribute", 'import-html-pages' ); ?><br /> 526 | <input type="text" name="html_import[date_tagatt]" id="date_tagatt" value="<?php echo esc_attr( $options['date_tagatt'] ); ?>" /> 527 | </label> 528 | </td> 529 | <td class="taginput"> 530 | <label><?php _e( "= Value", 'import-html-pages' ); ?><br /> 531 | <input type="text" name="html_import[date_attval]" id="date_attval" value="<?php echo esc_attr( $options['date_attval'] ); ?>" /> 532 | </label> 533 | </td> 534 | </tr> 535 | <tr id="date-region" <?php if ( $options['import_date'] !== 'region' ) echo 'style="display: none;"'; ?>> 536 | <td colspan="3"> 537 | <label><?php _e( "Dreamweaver template region", 'import-html-pages' ); ?><br /> 538 | <input type="text" name="html_import[date_region]" value="<?php echo esc_attr( $options['date_region'] ); ?>" /> 539 | </label> 540 | </td> 541 | </tr> 542 | </table> 543 | 544 | </td> 545 | </tr> 546 | 547 | <tr valign="top"> 548 | <th colspan="3"> 549 | <h4><?php _e( "Custom fields", 'import-html-pages' ); ?></h4> 550 | </th> 551 | </tr> 552 | 553 | <?php if ( !empty( $options['customfield_name'] ) && is_array( $options['customfield_name'] ) ) { 554 | foreach ( $options['customfield_name'] as $index => $fieldname ) : ?> 555 | <tr valign="top" class="clone" id="customfield<?php echo $index; ?>"> 556 | <th><a class="button-secondary delRow" title="Remove field">×</a></th> 557 | <td> 558 | <label><?php _e( 'Custom field name', 'import-html-pages' ); ?><br /> 559 | <input type="text" name="html_import[customfield_name][<?php echo $index; ?>]" 560 | value="<?php echo esc_attr( $options['customfield_name'][$index] ); ?>" /> 561 | </label><br /> 562 | <label> 563 | <input type="checkbox" name="html_import[customfield_html][<?php echo $index; ?>]" value="1" <?php checked( '1', $options['customfield_html'][$index] ) ?>> 564 | <?php _e( 'Allow HTML', 'import-html-pages' ); ?> 565 | </label> 566 | </td> 567 | <td> 568 | 569 | Select field by:<br /> 570 | <label> 571 | <input type="radio" name="html_import[import_field][<?php echo $index; ?>]" 572 | value="tag" class="showrow" title="customfield" <?php checked( $options['import_field'][$index], 'tag' ); ?> /> 573 | <?php _e( 'HTML tag', 'import-html-pages' ); ?></label> 574 |    575 | <label> 576 | <input type="radio" name="html_import[import_field][<?php echo $index; ?>]" 577 | value="region" class="showrow" title="customfield" <?php checked( $options['import_field'][$index], 'region' ); ?> /> 578 | <?php _e( 'Dreamweaver template region', 'import-html-pages' ); ?></label> 579 | </p> 580 | 581 | 582 | <table> 583 | <tr id="customfield-tag" <?php if ( $options['import_field'][$index] == 'region' ) echo 'style="display: none;"'; ?> > 584 | <td class="taginput"> 585 | <label><?php _e( "Tag", 'import-html-pages' ); ?><br /> 586 | <input type="text" name="html_import[customfield_tag][<?php echo $index; ?>]" 587 | value="<?php echo esc_attr( $options['customfield_tag'][$index] ); ?>" /> 588 | </label> 589 | 590 | </td> 591 | <td class="taginput"> 592 | <label><?php _e( "Attribute", 'import-html-pages' ); ?><br /> 593 | <input type="text" name="html_import[customfield_tagatt][<?php echo $index; ?>]" 594 | value="<?php echo esc_attr( $options['customfield_tagatt'][$index] ); ?>" /> 595 | </label> 596 | 597 | </td> 598 | <td class="taginput"> 599 | <label><?php _e( "= Value", 'import-html-pages' ); ?><br /> 600 | <input type="text" name="html_import[customfield_attval][<?php echo $index; ?>]" 601 | value="<?php echo esc_attr( $options['customfield_attval'][$index] ); ?>" /> 602 | </label> 603 | 604 | </td> 605 | </tr> 606 | <tr id="customfield-region" <?php if ( $options['import_field'][$index] == 'tag' ) echo 'style="display: none;"'; ?> > 607 | <td colspan="3"> 608 | <label><?php _e( "Dreamweaver template region", 'import-html-pages' ); ?><br /> 609 | <input type="text" name="html_import[customfield_region][<?php echo $index; ?>]" 610 | value="<?php echo esc_attr( $options['customfield_region'][$index] ); ?>" /> 611 | </label> 612 | </td> 613 | </tr> 614 | </table> 615 | 616 | </td> 617 | </tr> 618 | <?php endforeach; 619 | } else { ?> 620 | <tr valign="top" class="clone" id="customfield0"> 621 | <th> 622 | <a class="button-secondary delRow" title="Remove field">×</a></th> 623 | <td> 624 | <label><?php _e( 'Custom field name', 'import-html-pages' ); ?><br /> 625 | <input type="text" name="html_import[customfield_name][]" value="" /> 626 | </label><br /> 627 | <label> 628 | <input type="checkbox" name="html_import[customfield_html][<?php echo $index; ?>]" value="1" <?php checked( '1', $options['customfield_html'][$index] ) ?>> 629 | <?php _e( 'Allow HTML', 'import-html-pages' ); ?> 630 | </label> 631 | </td> 632 | <td> 633 | 634 | Select field by:<br /> 635 | <label> 636 | <input type="radio" name="html_import[import_field][]" 637 | value="tag" class="showrow" title="customfield" /> 638 | <?php _e( 'HTML tag', 'import-html-pages' ); ?></label> 639 |    640 | <label> 641 | <input type="radio" name="html_import[import_field][]" 642 | value="region" class="showrow" title="customfield" /> 643 | <?php _e( 'Dreamweaver template region', 'import-html-pages' ); ?></label> 644 | </p> 645 | 646 | 647 | <table> 648 | <tr id="customfield-tag"> 649 | <td class="taginput"> 650 | <label><?php _e( "Tag", 'import-html-pages' ); ?><br /> 651 | <input type="text" name="html_import[customfield_tag][]" value="" /> 652 | </label> 653 | 654 | </td> 655 | <td class="taginput"> 656 | <label><?php _e( "Attribute", 'import-html-pages' ); ?><br /> 657 | <input type="text" name="html_import[customfield_tagatt][]" value="" /> 658 | </label> 659 | 660 | </td> 661 | <td class="taginput"> 662 | <label><?php _e( "= Value", 'import-html-pages' ); ?><br /> 663 | <input type="text" name="html_import[customfield_attval][]" value="" /> 664 | </label> 665 | 666 | </td> 667 | </tr> 668 | <tr id="customfield-region" style="display: none;"> 669 | <td colspan="3"> 670 | <label><?php _e( "Dreamweaver template region", 'import-html-pages' ); ?><br /> 671 | <input type="text" name="html_import[customfield_region][]" value="" /> 672 | </label> 673 | </td> 674 | </tr> 675 | </table> 676 | 677 | </td> 678 | </tr> 679 | <?php } // else no custom fields ?> 680 | 681 | </tbody> 682 | <tfoot> 683 | <tr><td colspan="2"><a class="button-secondary cloneTableRows" href="#">Add a custom field</a></td> 684 | </tr> 685 | </tfoot> 686 | </table> 687 | </div> 688 | 689 | <!-- TAXONOMIES --> 690 | <div id="tabs-5"> 691 | <h3><?php _e( "Taxonomies", 'import-html-pages' ); ?></h3> 692 | <div class="ui-tabs-panel" id="taxonomies"> 693 | <?php 694 | // support all public taxonomies 695 | $nonhierarchical = ''; 696 | $taxonomies = get_taxonomies( array( 'public' => true ), 'objects', 'and' ); 697 | ?> 698 | <?php if ( is_array( $taxonomies ) ) : ?> 699 | <p><?php _e( 'Here, you may assign categories, tags, and custom taxonomy terms to all your imported posts.', 'import-html-pages' ); ?></p> 700 | <p><?php _e( 'To import tags from a region in each file, use a custom field with the name <kbd>post_tag</kbd>.', 'import-html-pages' ); ?></p> 701 | <?php foreach ( $taxonomies as $tax ) : 702 | if ( isset( $options[$tax->name] ) ) 703 | $value = esc_attr( $options[$tax->name] ); 704 | else 705 | $value = ''; 706 | if ( !is_taxonomy_hierarchical( $tax->name ) ) : 707 | // non-hierarchical 708 | $nonhierarchical .= '<p class="taxoinput"><label>'.esc_html( $tax->label ).'<br />'; 709 | $nonhierarchical .= '<input type="text" name="html_import['.esc_attr( $tax->name ).']" 710 | value="'.$value.'" /></label></p>'; 711 | else: 712 | // hierarchical 713 | ?> 714 | <div class="taxochecklistbox"> 715 | <?php echo esc_html( $tax->label ); ?><br /> 716 | <ul class="taxochecklist"> 717 | <?php 718 | if ( !isset( $options[$tax->name] ) ) $selected = ''; 719 | else $selected = $options[$tax->name]; 720 | wp_terms_checklist( 0, array( 721 | 'descendants_and_self' => 0, 722 | 'selected_cats' => $selected, 723 | 'popular_cats' => false, 724 | 'walker' => new HTML_Import_Walker_Category_Checklist, 725 | 'taxonomy' => $tax->name, 726 | 'checked_ontop' => false, 727 | ) 728 | ); 729 | ?> 730 | </ul> </div> 731 | <?php 732 | endif; 733 | endforeach; 734 | echo '<br class="clear" />'.$nonhierarchical; 735 | ?> 736 | </div> 737 | <?php endif; ?> 738 | </div> 739 | 740 | 741 | <!-- TOOLS --> 742 | <div id="tabs-6"> 743 | <h3><?php _e( "Tools", 'import-html-pages' ); ?></h3> 744 | <table class="form-table ui-tabs-panel" id="tools"> 745 | <tr valign="top"> 746 | <th scope="row"><?php _e( "Regenerate <kbd>.htaccess</kbd> redirects", 'import-html-pages' ); ?></th> 747 | <td><p><?php printf( __( 'If you <a href="%s">changed your permalink structure</a> after you imported files, you can <a href="%s">regenerate the redirects</a>.', 'import-html-pages' ), 'wp-admin/options-permalink.php', wp_nonce_url( 'admin.php?import=html&step=2', 'html_import_regenerate' ) ) ?></p></td> 748 | </tr> 749 | <tr valign="top"> 750 | <th scope="row"><?php _e( "Other helpful plugins", 'import-html-pages' ); ?></th> 751 | <td> 752 | <p><?php printf( __( '<a href="%s">Broken Link Checker</a> finds broken links and references to missing media files. Since the importer does not handle links or media files other than images, you should run this to see what else needs to be copied or updated from your old site.', 'import-html-pages' ), 'http://wordpress.org/extend/plugins/broken-link-checker/' ); ?></p> 753 | <p><?php printf( __( '<a href="%s">Search and Replace</a> helps you fix many broken links at once, if you have many links to the same files or if there is a pattern ( like <kbd><a href="../../files"></kbd> ) to your broken links.', 'import-html-pages' ), 'http://wordpress.org/extend/plugins/search-and-replace/' ); ?></p> 754 | <p><?php printf( __( '<a href="%s">Redirection</a> provides a nice admin interface for managing redirects. If you would rather not edit your <kbd>.htaccess</kbd> file, or if you just want to redirect one or two of your old pages, you can ignore the redirects generated by the importer. Instead, copy the post\'s old URL from the custom fields and paste it into Redirection\'s options.', 'import-html-pages' ), 'http://wordpress.org/extend/plugins/redirection/' ); ?></p> 755 | <p><?php printf( __( '<a href="%s">Add from Server</a> lets you import media files that are on your server but not part of the WordPress media library.', 'import-html-pages' ), 'http://wordpress.org/extend/plugins/add-from-server/' ); ?></p> 756 | <p><?php printf( __( '<a href="%s">Add Linked Images to Gallery</a> is helpful if you have imported data using other plugins and you would like to import linked images. However, it handles only images that are referenced with complete URLs; relative paths will not work.', 'import-html-pages' ), 'http://wordpress.org/extend/plugins/add-linked-images-to-gallery-v01/' ); ?></p> 757 | </td> 758 | </tr> 759 | <tr> 760 | <th><?php _e( 'Donate', 'import-html-pages' ) ?></th> 761 | <td> 762 | <p><?php printf( __( 'If this importer has saved you hours of copying and pasting, a <a href="%s">donation toward future development</a> would be much appreciated!', 'import-html-pages' ), 'http://stephanieleary.com/code/wordpress/html-import/' ); ?></p> 763 | </td> 764 | </table> 765 | </div> 766 | 767 | </div> <!-- UI tabs wrapper --> 768 | <p class="submit"> 769 | <input type="submit" class="button-primary" value="<?php _e( 'Save settings', 'import-html-pages' ) ?>" /> 770 | <?php if ( !$options['firstrun'] ) { ?> 771 | <a href="admin.php?import=html" class="button-secondary">Import files</a> 772 | <?php } ?> 773 | </p> 774 | </form> 775 | 776 | </div> <!-- .wrap --> 777 | <?php 778 | } 779 | 780 | function html_import_validate_options( $input ) { 781 | // Validation/sanitization. Add errors to $msg[]. 782 | $msg = array(); 783 | $linkmsg = ''; 784 | $msgtype = 'error'; 785 | 786 | // sanitize path for Win32 787 | $input['root_directory'] = str_replace( '\\' ,'/', $input['root_directory'] ); 788 | $input['root_directory'] = preg_replace( '|/+|', '/', $input['root_directory'] ); 789 | 790 | if ( validate_import_file( $input['root_directory'] ) > 0 ) { 791 | $msg[] = __( "The beginning directory you entered is not an absolute path. Relative paths are not allowed here.", 'import-html-pages' ); 792 | $input['root_directory'] = ABSPATH.__( 'html-files-to-import', 'import-html-pages' ); 793 | } 794 | 795 | $input['root_directory'] = rtrim( $input['root_directory'], '/' ); 796 | $input['old_url'] = esc_url( rtrim( $input['old_url'], '/' ) ); 797 | 798 | // trim the extensions, skipped dirs, allowed attributes. Invalid ones will not cause problems. 799 | $input['file_extensions'] = str_replace( '.', '', $input['file_extensions'] ); 800 | $input['file_extensions'] = str_replace( ' ', '', $input['file_extensions'] ); 801 | $input['file_extensions'] = strtolower( $input['file_extensions'] ); 802 | $input['document_mimes'] = str_replace( '.', '', $input['document_mimes'] ); 803 | $input['document_mimes'] = str_replace( ' ', '', $input['document_mimes'] ); 804 | $input['document_mimes'] = strtolower( $input['document_mimes'] ); 805 | $input['skipdirs'] = str_replace( ' ', '', $input['skipdirs'] ); 806 | $input['allow_tags'] = str_replace( '/', '', $input['allow_tags'] ); 807 | $input['allow_tags'] = str_replace( ' ', '', $input['allow_tags'] ); 808 | $input['allow_attributes'] = str_replace( ' ', '', $input['allow_attributes'] ); 809 | $input['index_files'] = str_replace( ' ', '', $input['index_files'] ); 810 | 811 | if ( !in_array( $input['status'], get_post_stati() ) ) 812 | $input['status'] = 'publish'; 813 | 814 | $post_types = get_post_types( array( 'public' => true ),'names' ); 815 | if ( !in_array( $input['type'], $post_types ) ) 816 | $input['type'] = 'page'; 817 | 818 | if ( !in_array( $input['timestamp'], array( 'now', 'filemtime', 'customfield' ) ) ) 819 | $input['timestamp'] = 'filemtime'; 820 | 821 | if ( !in_array( $input['import_content'], array( 'tag', 'region', 'file' ) ) ) 822 | $input['import_content'] = 'tag'; 823 | if ( !in_array( $input['import_title'], array( 'tag', 'region', 'filename' ) ) ) 824 | $input['import_title'] = 'tag'; 825 | 826 | // trim region/tag/attr/value 827 | if ( !empty( $input['content_region'] ) ) $input['content_region'] = sanitize_text_field( $input['content_region'] ); 828 | if ( !empty( $input['content_tag'] ) ) $input['content_tag'] = sanitize_text_field( $input['content_tag'] ); 829 | if ( !empty( $input['content_tagatt'] ) ) $input['content_tagatt'] = sanitize_text_field( $input['content_tagatt'] ); 830 | if ( !empty( $input['content_attval'] ) ) $input['content_attval'] = sanitize_text_field( $input['content_attval'] ); 831 | if ( !empty( $input['title_region'] ) ) $input['title_region'] = sanitize_text_field( $input['title_region'] ); 832 | if ( !empty( $input['title_tag'] ) ) $input['title_tag'] = sanitize_text_field( $input['title_tag'] ); 833 | if ( !empty( $input['title_tagatt'] ) ) $input['title_tagatt'] = sanitize_text_field( $input['title_tagatt'] ); 834 | if ( !empty( $input['title_attval'] ) ) $input['title_attval'] = sanitize_text_field( $input['title_attval'] ); 835 | if ( !empty( $input['date_region'] ) ) $input['date_region'] = sanitize_text_field( $input['date_region'] ); 836 | if ( !empty( $input['date_tag'] ) ) $input['date_tag'] = sanitize_text_field( $input['date_tag'] ); 837 | if ( !empty( $input['date_tagatt'] ) ) $input['date_tagatt'] = sanitize_text_field( $input['date_tagatt'] ); 838 | if ( !empty( $input['date_attval'] ) ) $input['date_attval'] = sanitize_text_field( $input['date_attval'] ); 839 | 840 | // We could have many custom fields. For now, let's just make it an array. Deal with it in the importer. 841 | if ( !is_array( $input['customfield_name'] ) ) 842 | $input['customfield_name'] = array( $input['customfield_name'] ); 843 | if ( !is_array( $input['import_field'] ) ) 844 | $input['import_field'] = array( $input['import_field'] ); 845 | if ( !is_array( $input['customfield_region'] ) ) 846 | $input['customfield_region'] = array( $input['customfield_region'] ); 847 | if ( !is_array( $input['customfield_tag'] ) ) 848 | $input['customfield_tag'] = array( $input['customfield_tag'] ); 849 | if ( !is_array( $input['customfield_tagatt'] ) ) 850 | $input['customfield_tagatt'] = array( $input['customfield_tagatt'] ); 851 | if ( !is_array( $input['customfield_attval'] ) ) 852 | $input['customfield_attval'] = array( $input['customfield_attval'] ); 853 | if ( !is_array( $input['customfield_html'] ) ) 854 | $input['customfield_html'] = array( $input['customfield_html'] ); 855 | 856 | // must have something to look for in the HTML 857 | if ( $input['import_content'] == 'tag' && empty( $input['content_tag'] ) ) 858 | $msg[] = __( "You did not enter an HTML content tag to import.", 'import-html-pages' ); 859 | if ( $input['import_content'] == 'region' && empty( $input['content_region'] ) ) 860 | $msg[] = __( "You did not enter a Dreamweaver content template region to import.", 'import-html-pages' ); 861 | if ( $input['import_title'] == 'tag' && empty( $input['title_tag'] ) ) 862 | $msg[] = __( "You did not enter an HTML title tag to import.", 'import-html-pages' ); 863 | if ( $input['import_title'] == 'region' && empty( $input['title_region'] ) ) 864 | $msg[] = __( "You did not enter a Dreamweaver title template region to import.", 'import-html-pages' ); 865 | 866 | if ( !isset( $input['root_parent'] ) ) 867 | $input['root_parent'] = 0; 868 | 869 | // $input['remove_from_title'] could be anything, including unencoded characters or HTML tags 870 | // it's a search pattern; leave it alone 871 | 872 | // these should all be zero or one 873 | $input['clean_html'] = absint( $input['clean_html'] ); 874 | if ( $input['clean_html'] > 1 ) $input['clean_html'] = 0; 875 | $input['encode'] = absint( $input['encode'] ); 876 | if ( $input['encode'] > 1 ) $input['encode'] = 0; 877 | $input['meta_desc'] = absint( $input['meta_desc'] ); 878 | if ( $input['meta_desc'] > 1 ) $input['meta_desc'] = 1; 879 | $input['title_inside'] = absint( $input['title_inside'] ); 880 | if ( $input['title_inside'] > 1 ) $input['title_inside'] = 0; 881 | 882 | 883 | // see if this is a real user 884 | $input['user'] = absint( $input['user'] ); 885 | $user_info = get_userdata( $input['user'] ); 886 | if ( $user_info === false ) { 887 | $msg[] = "The author you specified does not exist."; 888 | $currentuser = wp_get_current_user(); 889 | $input['user'] = $currentuser->ID; 890 | } 891 | 892 | // If settings have been saved at least once, we can turn this off. 893 | $input['firstrun'] = false; 894 | 895 | 896 | // Send custom updated message 897 | $msg = implode( '<br />', $msg ); 898 | 899 | if ( empty( $msg ) ) { 900 | 901 | $linkstructure = get_option( 'permalink_structure' ); 902 | if ( empty( $linkstructure ) ) 903 | $linkmsg = sprintf( __( 'If you intend to <a href="%s">set a permalink structure</a>, you should do it 904 | before importing so the <kbd>.htaccess</kbd> redirects will be accurate.', 'import-html-pages' ), 'options-permalink.php' ); 905 | 906 | $msg = sprintf( __( 'Settings saved. %s <a href="%s">Ready to import files?</a>', 'import-html-pages' ), 907 | $linkmsg, 'admin.php?import=html' ); 908 | // $msg .= '<pre>'. print_r( $input, false ) .'</pre>'; 909 | $msgtype = 'updated'; 910 | } 911 | 912 | add_settings_error( 'html_import', 'html_import', $msg, $msgtype ); 913 | return $input; 914 | } 915 | 916 | // custom file validator to accommodate Win32 paths starting with drive letter 917 | // based on WP's validate_file() 918 | function validate_import_file( $file, $allowed_files = '' ) { 919 | if ( false !== strpos( $file, '..' ) ) 920 | return 1; 921 | 922 | if ( false !== strpos( $file, './' ) ) 923 | return 1; 924 | 925 | if ( !empty ( $allowed_files ) && ( !in_array( $file, $allowed_files ) ) ) 926 | return 3; 927 | /* 928 | if ( ':' == substr( $file, 1, 1 ) ) 929 | return 2; 930 | */ 931 | return 0; 932 | } 933 | 934 | // custom walker so we can change the name attribute of the category checkboxes ( until #16437 is fixed ) 935 | // mostly a duplicate of Walker_Category_Checklist 936 | class HTML_Import_Walker_Category_Checklist extends Walker { 937 | var $tree_type = 'category'; 938 | var $db_fields = array ( 'parent' => 'parent', 'id' => 'term_id' ); 939 | 940 | function start_lvl( &$output, $depth = 0, $args = array() ) { 941 | $indent = str_repeat( "\t", $depth ); 942 | $output .= "$indent<ul class='children'>\n"; 943 | } 944 | 945 | function end_lvl( &$output, $depth = 0, $args = array() ) { 946 | $indent = str_repeat( "\t", $depth ); 947 | $output .= "$indent</ul>\n"; 948 | } 949 | 950 | function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) { 951 | extract( $args ); 952 | if ( empty( $taxonomy ) ) 953 | $taxonomy = 'category'; 954 | 955 | // This is the part we changed 956 | $name = 'html_import['.$taxonomy.']'; 957 | 958 | $class = in_array( $object->term_id, $popular_cats ) ? ' class="popular-category"' : ''; 959 | $output .= "\n<li id='{$taxonomy}-{$object->term_id}'$class>" . '<label class="selectit"><input value="' . $object->term_id . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $object->term_id . '"' . checked( in_array( $object->term_id, $selected_cats ), true, false ) . disabled( empty( $args['disabled'] ), false, false ) . ' /> ' . esc_html( apply_filters( 'the_category', $object->name ) ) . '</label>'; 960 | } 961 | 962 | function end_el( &$output, $category, $depth = 0, $args = array() ) { 963 | $output .= "</li>\n"; 964 | } 965 | } -------------------------------------------------------------------------------- /html-importer.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | if ( !defined( 'WP_LOAD_IMPORTERS' ) ) 4 | return; 5 | 6 | // Load Importer API 7 | require_once ABSPATH . 'wp-admin/includes/import.php'; 8 | 9 | if ( !class_exists( 'WP_Importer' ) ) { 10 | $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php'; 11 | if ( file_exists( $class_wp_importer ) ) 12 | require_once $class_wp_importer; 13 | } 14 | 15 | if ( class_exists( 'WP_Importer' ) ) { 16 | class HTML_Import extends WP_Importer { 17 | 18 | var $posts = array (); 19 | var $file; 20 | 21 | function header() { 22 | echo '<div class="wrap">'; 23 | screen_icon(); 24 | echo '<h2>'.__( 'HTML Importer', 'import-html-pages' ).'</h2>'; 25 | } 26 | 27 | function footer() { 28 | echo '</div>'; 29 | } 30 | 31 | function greet() { 32 | $options = get_option( 'html_import' ); 33 | ?> 34 | <div class="narrow"> 35 | <?php 36 | if ( $options['firstrun'] === true ) { 37 | echo '<p>'.sprintf( __( 'It looks like you have not yet visited the <a href="%s">HTML Import options page</a>. Please do so now! You need to specify which portions of your HTML files should be imported before you proceed.', 'import-html-pages' ), 'options-general.php?page=html-import.php' ).'</p>'; 38 | } 39 | else { ?> 40 | <h4><?php _e( 'What are you importing today?' ); ?></h4> 41 | <form enctype="multipart/form-data" method="post" action="admin.php?import=html&step=1"> 42 | <p> 43 | <label><input name="import_files" id="import_files" type="radio" value="directory" checked="checked" 44 | onclick="javascript: jQuery( '#single' ).hide( 'fast' ); jQuery( '#directory' ).show( 'fast' );" /> 45 | <?php _e( 'a directory of files', 'import-html-pages' ); ?></label>     46 | <label><input name="import_files" id="import_files" type="radio" value="file" 47 | onclick="javascript: jQuery( '#directory' ).hide( 'fast' ); jQuery( '#single' ).show( 'fast' );" /> 48 | <?php _e( 'a single file', 'import-html-pages' ); ?></label> 49 | </p> 50 | 51 | <p id="single"> 52 | <label for="import"><?php _e( 'Choose an HTML file from your computer:', 'import-html-pages' ); ?></label> 53 | <input type="file" id="import" name="import" size="25" /> 54 | </p> 55 | 56 | <p id="directory"> 57 | <?php 58 | printf( __( 'Your files will be imported from <kbd>%s</kbd>. <a href="%s">Change directories</a>.', 'import-html-pages' ), 59 | esc_html( $options['root_directory'] ), 'options-general.php?page=html-import.php' ); ?> 60 | </p> 61 | 62 | <input type="hidden" name="action" value="save" /> 63 | 64 | <p class="submit"> 65 | <input type="submit" name="submit" class="button" value="<?php echo esc_attr( __( 'Submit', 'import-html-pages' ) ); ?>" /> 66 | </p> 67 | <?php wp_nonce_field( 'html-import' ); ?> 68 | </form> 69 | </div> 70 | <?php } // else 71 | } 72 | 73 | function regenerate_redirects() { 74 | $newredirects = ''; 75 | $imported = get_posts( array( 'meta_key' => 'URL_before_HTML_Import', 'post_type' => 'any', 'post_status' => 'any', 'numberposts' => '-1' ) ); 76 | foreach( $imported as $post ) { 77 | $old = get_post_meta( $post->ID, 'URL_before_HTML_Import', true ); 78 | $newredirects .= "Redirect\t".$old."\t".get_permalink( $post->ID )."\t[R=301,NC,L]\n"; 79 | } 80 | if ( !empty( $newredirects ) ) { ?> 81 | <h3><?php _e( '.htaccess Redirects', 'import-html-pages' ); ?></h3> 82 | <p><?php _e( 'Copy these lines into your <kbd>.htaccess</kbd> <em>above</em> the WordPress section.', 'import-html-pages' ); ?></p> 83 | <textarea id="import-result"><?php echo $newredirects; ?></textarea> 84 | <h3><?php printf( __( 'All done! You can <a href="%s">change your permalink structure</a> and <a href="%s">regenerate the redirects again</a>, or <a href="%s">start over</a>.', 'import-html-pages' ), 'options-permalink.php', wp_nonce_url( 'admin.php?import=html&step=2', 'html_import_regenerate' ), 'admin.php?import=html' ) ?></h3> 85 | <?php } 86 | else _e( 'No posts were found with the URL_before_HTML_Import custom field. Could not generate rewrite rules.', 'import-html-pages' ); 87 | } 88 | 89 | function fix_hierarchy( $postid, $path ) { 90 | $options = get_option( 'html_import' ); 91 | $parentdir = rtrim( $this->parent_directory( $path ), '/' ); 92 | 93 | // create array of parent directories, starting with the index file's parent and moving up to the root directory 94 | while ( $parentdir != $options['root_directory'] ) { 95 | $parentarr[] = $parentdir; 96 | $parentdir = rtrim( $this->parent_directory( $parentdir ), '/' ); 97 | } 98 | // reverse the array so we start at the root -- this way the parents can be found when we search in $this->get_post 99 | $parentarr = array_reverse( $parentarr ); 100 | 101 | // DEBUG 102 | // echo '<pre>'.print_r( $parentarr, true ).'</pre>'; 103 | 104 | foreach ( $parentarr as $parentdir ) { 105 | $parentID = array_search( $parentdir, $this->filearr ); 106 | if ( $parentID === false ) 107 | $this->get_post( $parentdir, true ); 108 | } 109 | 110 | // now fix the parent ID of the original index file ( in $postid ) 111 | // it's the next to last element in the array we want. ( The last one is the index file. ) If this doesn't exist, we don't need to fix the parent. 112 | $grandparent = count( $parentarr )-2; 113 | if ( isset( $parentarr[$grandparent] ) ) { 114 | $parentdir = $parentarr[$grandparent]; 115 | $my_post['ID'] = $postid; 116 | $my_post['post_parent'] = array_search( $parentdir, $this->filearr ); 117 | 118 | //echo "\n<pre>The parent of $postid should be ".$my_post['post_parent']."</pre>"; 119 | 120 | if ( !empty( $my_post['post_parent'] ) ) 121 | wp_update_post( $my_post ); 122 | } 123 | } 124 | 125 | function parent_directory( $path ) { 126 | $win = false; 127 | if ( strpos( $path, '\\' ) !== FALSE ) { 128 | $win = true; 129 | $path = str_replace( '\\', '/', $path ); 130 | } 131 | if ( substr( $path, strlen( $path ) - 1 ) != '/' ) $path .= '/'; 132 | $path = substr( $path, 0, strlen( $path ) - 1 ); 133 | $path = substr( $path, 0, strrpos( $path, '/' ) ) . '/'; 134 | if ( $win ) $path = str_replace( '/', '\\', $path ); 135 | return $path; 136 | } 137 | 138 | function fix_internal_links( $content, $id ) { 139 | // find all href attributes 140 | preg_match_all( '/<a[^>]* href=[\'"]?([^>\'" ]+ )/i', $content, $matches ); 141 | for ( $i=0; $i<count( $matches[0] ); $i++ ) { 142 | $hrefs[] = $matches[1][$i]; 143 | } 144 | if ( !empty( $hrefs ) ) { 145 | //echo '<p>Looking in '.get_permalink( $id ).'</p>'; 146 | $options = get_option( 'html_import' ); 147 | $site = $options['old_url']; 148 | $rootdir = $options['root_directory']; 149 | foreach ( $hrefs as $href ) { 150 | if ( '#' != substr( $href, 0, 1 ) && 'mailto:' != substr( $href, 0, 7 ) ) { // skip anchors and mailtos 151 | if ( preg_match( '/^http:\/\//', $href ) || preg_match( '/^https:\/\//', $href ) ) { 152 | // if it's an internal link, let's get a local file path 153 | $linkpath = str_replace( $site, $rootdir, $href ); 154 | } 155 | // href="/images/foo" 156 | elseif ( '/' == substr( $href, 0, 1 ) ) { 157 | $linkpath = $rootdir . $href; 158 | $linkpath = $this->remove_dot_segments( $linkpath ); 159 | } 160 | // href="../../images/foo" or href="images/foo" 161 | else { 162 | // we need to know where we are in the hierarchy 163 | $oldpath = get_post_meta( $id, 'URL_before_HTML_Import', true ); 164 | $oldpath = str_replace( $site, $rootdir, $oldpath ); 165 | //echo '<p>Old path: '.$oldpath; 166 | $oldfile = strrchr( $oldpath, '/' ); 167 | $linkpath = str_replace( $oldfile, '/'.$href, $oldpath ); 168 | $linkpath = $this->remove_dot_segments( $linkpath ); 169 | //echo ' Link path: '.$linkpath . '</p>'; 170 | } 171 | 172 | $linkpath = rtrim( $linkpath, '/' ); 173 | // DEBUG 174 | //echo '<p>Old link: '.$href.' Full path: '.$linkpath; 175 | 176 | // now replace the old URL with the new permalink 177 | $postkey = array_search( $linkpath, $this->filearr ); 178 | 179 | // DEBUG 180 | //echo ' Post ID:'.$postkey.'.</p>'; 181 | if ( !empty( $postkey ) ) { 182 | 183 | // DEBUG 184 | //echo '<p>I think '.$linkpath.' has moved to '.get_permalink( $postkey ).'.</p>'; 185 | $content = str_replace( $href, get_permalink( $postkey ), $content ); 186 | } 187 | } // if #/mailto 188 | } // foreach 189 | } // if empty 190 | return $content; 191 | } 192 | 193 | function remove_dot_segments( $path ) { 194 | $inSegs = preg_split( '!/!u', $path ); 195 | $outSegs = array(); 196 | foreach ( $inSegs as $seg ) 197 | { 198 | if ( empty( $seg ) || $seg == '.' ) 199 | continue; 200 | if ( $seg == '..' ) 201 | array_pop( $outSegs ); 202 | else 203 | array_push( $outSegs, $seg ); 204 | } 205 | $outPath = implode( '/', $outSegs ); 206 | if ( isset( $path[0] ) && $path[0] == '/' ) 207 | $outPath = '/' . $outPath; 208 | if ( $outPath != '/' && 209 | ( mb_strlen( $path )-1 ) == mb_strrpos( $path, '/', 'UTF-8' ) ) 210 | $outPath .= '/'; 211 | $outPath = str_replace( 'http:/', 'http://', $outPath ); 212 | $outPath = str_replace( 'https:/', 'https://', $outPath ); 213 | $outPath = str_replace( ':///', '://', $outPath ); 214 | return rawurldecode( $outPath ); 215 | } 216 | 217 | function clean_html( $string, $allowtags = NULL, $allowattributes = NULL ) { 218 | // from: http://us3.php.net/manual/en/function.strip-tags.php#91498 219 | $string = strip_tags( $string,$allowtags ); 220 | if ( !is_null( $allowattributes ) ) { 221 | if( !is_array( $allowattributes ) ) 222 | $allowattributes = explode( ",",$allowattributes ); 223 | if( is_array( $allowattributes ) ) 224 | $allowattributes = implode( " )( ?<!",$allowattributes ); 225 | if ( strlen( $allowattributes ) > 0 ) 226 | $allowattributes = "( ?<!".$allowattributes." )"; 227 | $string = preg_replace_callback( "/<[^>]*>/i",create_function( 228 | '$matches', 229 | 'return preg_replace( "/ [^ =]*'.$allowattributes.'=( \"[^\"]*\"|\'[^\']*\' )/i", "", $matches[0] );' 230 | ),$string ); 231 | } 232 | // reduce line breaks and remove empty tags 233 | $string = str_replace( array( "\n", "\r", "\t" ), '', $string ); 234 | $string = preg_replace( "/<[^\/>]*>( [\s]? )*<\/[^>]*>/", ' ', $string ); 235 | // get rid of remaining newlines; basic HTML cleanup 236 | $string = str_replace( ' ', ' ', $string ); 237 | $string = preg_replace_callback( '|<( /?[A-Z]+ )|', create_function( '$match', 'return "<" . strtolower( $match[1] );' ), $string ); 238 | $string = str_replace( '<br>', '<br />', $string ); 239 | $string = str_replace( '<hr>', '<hr />', $string ); 240 | return $string; 241 | } 242 | 243 | function handle_accents() { 244 | // from: http://www.php.net/manual/en/domdocument.loadhtml.php#91513 245 | $content = $this->file; 246 | if ( !empty( $content ) && function_exists( 'mb_convert_encoding' ) ) { 247 | mb_detect_order( "ASCII,UTF-8,ISO-8859-1,windows-1252,iso-8859-15" ); 248 | if ( empty( $encod ) ) 249 | $encod = mb_detect_encoding( $content ); 250 | $headpos = mb_strpos( $content,'<head>' ); 251 | if ( FALSE === $headpos ) 252 | $headpos= mb_strpos( $content,'<HEAD>' ); 253 | if ( FALSE !== $headpos ) { 254 | $headpos+=6; 255 | $content = mb_substr( $content,0,$headpos ) . '<meta http-equiv="Content-Type" content="text/html; charset='.$encod.'">' .mb_substr( $content,$headpos ); 256 | } 257 | $content = mb_convert_encoding( $content, 'HTML-ENTITIES', $encod ); 258 | } 259 | return $content; 260 | } 261 | 262 | function get_single_file( $txt = false ) { 263 | $importfile = file( $this->file ); // Read the file into an array 264 | $importfile = implode( '', $importfile ); // squish it 265 | // this strips whitespace out of <pre>. Need to find a better way to handle that. For now, leave it alone. 266 | //$this->file = str_replace( array ( "\r\n", "\r" ), "\n", $importfile ); 267 | $this->file = $importfile; 268 | $this->get_post( '', false ); 269 | } 270 | 271 | function get_files_from_directory( $rootdir ) { 272 | $options = get_option( 'html_import' ); 273 | $dir_content = scandir( $rootdir ); 274 | foreach( $dir_content as $key => $val ) { 275 | set_time_limit( 30 ); 276 | $path = $rootdir.'/'.$val; 277 | if( is_file( $path ) && is_readable( $path ) ) { 278 | $filename_parts = pathinfo( $path ); 279 | $ext = ''; 280 | if ( isset( $filename_parts['extension'] ) ) 281 | $ext = strtolower( $filename_parts['extension'] ); 282 | // allowed extensions only, please 283 | if ( !empty( $ext ) && in_array( $ext, $this->allowed ) ) { 284 | if ( filesize( $path ) > 0 ) { // silently skip empty files 285 | // read the HTML file 286 | $contents = @fopen( $path ); // read entire file 287 | if ( empty( $contents ) ) 288 | $contents = @file_get_contents( $path ); 289 | if ( !empty( $contents ) ) { // silently skip files we can't open 290 | $this->file = $contents; 291 | $this->get_post( $path, false ); // import the post 292 | } 293 | } 294 | } 295 | } 296 | 297 | elseif( is_dir( $path ) && is_readable( $path ) ) { 298 | if( !in_array( $val, $this->skip ) ) { 299 | $createpage = array(); 300 | // get list of files in this directory only ( checking children ) 301 | $files = scandir( $path ); 302 | $exts = array(); 303 | foreach ( $files as $file ) { 304 | $ext = ''; 305 | $filename_parts = pathinfo( $file ); 306 | if ( isset( $filename_parts['extension'] ) ) 307 | $ext = strtolower( $filename_parts['extension'] ); 308 | $ext = trim( $ext,'.' ); // dratted double dots 309 | if ( !empty( $ext ) ) $exts[] .= $ext; 310 | } 311 | 312 | // allowed extensions only, please. If there are files of the proper type, we should create a placeholder page 313 | $createpage = @array_intersect( $exts, $this->allowed ); // suppress warnings about not being an array 314 | 315 | if ( !empty( $createpage ) && is_post_type_hierarchical( $options['type'] ) ) { 316 | $this->get_post( $path, true ); 317 | } 318 | 319 | // handle the files in this directory -- recurse! 320 | $this->get_files_from_directory( $path ); 321 | } 322 | } 323 | } // end foreach 324 | } 325 | 326 | function get_post( $path = '', $placeholder = false ) { 327 | // this gets the content AND imports the post because we have to build $this->filearr as we go so we can find the new post IDs of files' parent directories 328 | set_time_limit( 540 ); 329 | $options = get_option( 'html_import' ); 330 | $updatepost = false; 331 | 332 | if ( $placeholder ) { 333 | $title = trim( strrchr( $path,'/' ),'/' ); 334 | $title = str_replace( '_', ' ', $title ); 335 | $title = str_replace( '-', ' ', $title ); 336 | $my_post['post_title'] = ucwords( $title ); 337 | 338 | if ( isset( $options['preserve_slugs'] ) && '1' == $options['preserve_slugs'] ) { 339 | $filename = basename( $path ); 340 | $my_post['post_name'] = substr( $filename,0,strrpos( $filename,'.' ) ); 341 | } 342 | 343 | if ( $options['timestamp'] == 'filemtime' ) 344 | $date = filemtime( $path ); 345 | else $date = time(); 346 | $my_post['post_date'] = date( "Y-m-d H:i:s", $date ); 347 | $my_post['post_date_gmt'] = date( "Y-m-d H:i:s", $date ); 348 | 349 | $my_post['post_type'] = $options['type']; 350 | 351 | $parentdir = rtrim( $this->parent_directory( $path ), '/' ); 352 | 353 | $my_post['post_parent'] = array_search( $parentdir, $this->filearr ); 354 | if ( $my_post['post_parent'] === false ) 355 | $my_post['post_parent'] = $options['root_parent']; 356 | 357 | $my_post['post_content'] = '<!-- placeholder -->'; 358 | $my_post['post_status'] = $options['status']; 359 | $my_post['post_author'] = $options['user']; 360 | } 361 | else { 362 | $doc = new DOMDocument(); 363 | $doc->strictErrorChecking = false; // ignore invalid HTML, we hope 364 | $doc->preserveWhiteSpace = false; 365 | $doc->formatOutput = false; // speed this up 366 | if ( !empty( $options['encode'] ) ) { // we have to deal with character encoding BEFORE calling loadHTML() - eureka! 367 | $content = $this->handle_accents(); 368 | @$doc->loadHTML( $content ); 369 | } 370 | else 371 | @$doc->loadHTML( $this->file ); 372 | $xml = @simplexml_import_dom( $doc ); 373 | // bail out if we got no XML to work with 374 | if ( $xml === NULL ) 375 | return; 376 | // avoid asXML errors when it encounters character range issues 377 | libxml_clear_errors(); 378 | libxml_use_internal_errors( false ); 379 | 380 | // start building the WP post object to insert 381 | $my_post = array(); 382 | 383 | // title 384 | if ( $options['import_title'] == "region" ) { 385 | // appending strings unnecessarily so this plugin can be edited in Dreamweaver if needed 386 | $titlematch = '/<'.'!-- InstanceBeginEditable name="'.$options['title_region'].'" --'.'>( .* )<'.'!-- InstanceEndEditable --'.'>/isU'; 387 | preg_match( $titlematch, $this->file, $titlematches ); 388 | $my_post['post_title'] = strip_tags( trim( $titlematches[1] ) ); 389 | } 390 | else if ( $options['import_title'] == "filename" ) { 391 | $path_split = explode( '/',$path ); 392 | $file_name = trim( end( $path_split ) ); 393 | $file_name = preg_replace( '/\.[^.]*$/', '', $file_name ); // remove extension 394 | $parent_directory = trim( prev( $path_split ) ); 395 | 396 | if( basename( $path ) == $options['index_file'] ) { 397 | $title = $parent_directory; 398 | } else { 399 | $title = $file_name; 400 | } 401 | $title = str_replace( '_', ' ', $title ); 402 | $title = str_replace( '-', ' ', $title ); 403 | $my_post['post_title'] = ucwords( $title ); 404 | } 405 | else { // it's a tag 406 | $titletag = $options['title_tag']; 407 | $titletagatt = $options['title_tagatt']; 408 | $titleattval = $options['title_attval']; 409 | $titlequery = '//' . $titletag; 410 | if ( !empty( $titletagatt ) ) 411 | $titlequery .= '[@'.$titletagatt.'="'.$titleattval.'"]'; 412 | $title = $xml->xpath( $titlequery ); 413 | if ( isset( $title[0] ) && is_object( $title[0] ) ) 414 | $title = $title[0]->asXML(); // asXML() preserves HTML in content 415 | else { // fallback 416 | $title = $xml->xpath( '//title' ); 417 | if ( isset( $title[0] ) ) 418 | $title = $title[0]; 419 | if ( empty( $title ) ) 420 | $title = ''; 421 | else 422 | $title = ( string )$title; 423 | } 424 | // last resort: filename 425 | if ( empty( $title ) ) { 426 | $path_split = explode( '/',$path ); 427 | $title = trim( end( $path_split ) ); 428 | } 429 | // replace break tags with spaces before we strip tags, to avoid accidentally concatenating words 430 | $title = str_replace( '<br>', ' ', $title ); 431 | $my_post['post_title'] = trim( strip_tags( $title ) ); 432 | } 433 | 434 | $remove = $options['remove_from_title']; 435 | if ( !empty( $remove ) ) 436 | $my_post['post_title'] = str_replace( $remove, '', $my_post['post_title'] ); 437 | 438 | // DEBUG 439 | //echo '<pre>'.$my_post['post_title'].'</pre>'; exit; 440 | 441 | // slug 442 | if ( isset( $options['preserve_slugs'] ) && '1' == $options['preserve_slugs'] ) { 443 | // there is no path when we're working with a single uploaded file instead of a directory 444 | if ( '' == trim( $path ) ) 445 | $filename = $this->filename; 446 | else 447 | $filename = basename( $path ); 448 | $my_post['post_name'] = substr( $filename,0,strrpos( $filename,'.' ) ); 449 | } 450 | 451 | // post type 452 | $my_post['post_type'] = $options['type']; 453 | 454 | if ( is_post_type_hierarchical( $my_post['post_type'] ) ) { 455 | if ( '' == trim( $path ) ) 456 | $my_post['post_parent'] = $options['root_parent']; 457 | else { 458 | $parentdir = rtrim( $this->parent_directory( $path ), '/' ); 459 | $my_post['post_parent'] = array_search( $parentdir, $this->filearr ); 460 | if ( $my_post['post_parent'] === false ) 461 | $my_post['post_parent'] = $options['root_parent']; 462 | } 463 | } 464 | 465 | // date 466 | if ( $options['timestamp'] == 'filemtime' && !empty( $path ) ) { 467 | $date = filemtime( $path ); 468 | $my_post['post_date'] = date( "Y-m-d H:i:s", $date ); 469 | $my_post['post_date_gmt'] = date( "Y-m-d H:i:s", $date ); 470 | } 471 | else if ( $options['timestamp'] == 'customfield' ) { 472 | if ( $options['import_date'] == "region" ) { 473 | // appending strings unnecessarily so this plugin can be edited in Dreamweaver if needed 474 | $datematch = '/<'.'!-- InstanceBeginEditable name="'.$options['date_region'].'" --'.'>( .* )<'.'!-- InstanceEndEditable --'.'>/isU'; 475 | preg_match( $datematch, $this->file, $datematches ); 476 | $date = $datematches[1]; 477 | } 478 | else { // it's a tag 479 | $tag = $options['date_tag']; 480 | $tagatt = $options['date_tagatt']; 481 | $attval = $options['date_attval']; 482 | $xquery = '//'.$tag; 483 | if ( !empty( $tagatt ) ) 484 | $xquery .= '[@'.$tagatt.'="'.$attval.'"]'; 485 | $date = $xml->xpath( $xquery ); 486 | if ( is_array( $date ) && isset( $date[0] ) && is_object( $date[0] ) ) { 487 | if ( isset( $date[0] ) && is_object( $date[0] ) ) 488 | $stripdate = $date[0]->asXML(); // asXML() preserves HTML in content 489 | $date = strip_tags( $date[0] ); 490 | $date = strtotime( $date ); 491 | //echo $date; exit; 492 | } 493 | else { // fallback 494 | $date = time(); 495 | } 496 | 497 | } 498 | } 499 | else { 500 | $date = time(); 501 | } 502 | $my_post['post_date'] = date( "Y-m-d H:i:s", $date ); 503 | $my_post['post_date_gmt'] = date( "Y-m-d H:i:s", $date ); 504 | 505 | // content 506 | if ( $options['import_content'] == "region" ) { 507 | // appending strings unnecessarily so this plugin can be edited in Dreamweaver if needed 508 | $contentmatch = '/<'.'!-- InstanceBeginEditable name="'.$options['content_region'].'" --'.'>( .* )<'.'!-- InstanceEndEditable --'.'>/isU'; 509 | preg_match( $contentmatch, $this->file, $contentmatches ); 510 | $my_post['post_content'] = $contentmatches[1]; 511 | } 512 | else if ( $options['import_content'] == "file" ) { // import entire file 513 | $my_post['post_content'] = $this->file; 514 | } 515 | else { // it's a tag 516 | $tag = $options['content_tag']; 517 | $tagatt = $options['content_tagatt']; 518 | $attval = $options['content_attval']; 519 | $xquery = '//'.$tag; 520 | if ( !empty( $tagatt ) ) 521 | $xquery .= '[@'.$tagatt.'="'.$attval.'"]'; 522 | $content = $xml->xpath( $xquery ); 523 | if ( is_array( $content ) && isset( $content[0] ) && is_object( $content[0] ) ) { 524 | $my_post['post_content'] = $content[0]->asXML(); // asXML() preserves HTML in content 525 | } 526 | else { // fallback 527 | $content = $xml->xpath( '//body' ); 528 | if ( is_array( $content ) && isset( $content[0] ) && is_object( $content[0] ) ) 529 | $my_post['post_content'] = $content[0]->asXML(); 530 | else 531 | $my_post['post_content'] = ''; 532 | } 533 | } 534 | 535 | // $my_post['post_content'] = (string) $my_post['post_content']; 536 | 537 | if ( $options['title_inside'] ) 538 | $my_post['post_content'] = str_replace( $title, '', $my_post['post_content'] ); 539 | 540 | if ( !empty( $my_post['post_content'] ) ) { 541 | if ( !empty( $options['clean_html'] ) ) 542 | $my_post['post_content'] = $this->clean_html( $my_post['post_content'], $options['allow_tags'], $options['allow_attributes'] ); 543 | } 544 | 545 | // custom fields 546 | $customfields = array(); 547 | foreach ( $options['customfield_name'] as $index => $fieldname ) { 548 | if ( !empty( $fieldname ) ) { 549 | if ( $options['import_field'][$index] == "region" ) { 550 | // appending strings unnecessarily so this plugin can be edited in Dreamweaver if needed 551 | $custommatch = '/<'.'!-- InstanceBeginEditable name="'.$options['customfield_region'][$index].'" --'.'>( .* )<'.'!-- InstanceEndEditable --'.'>/isU'; 552 | preg_match( $custommatch, $this->file, $custommatches ); 553 | if ( isset( $custommatches[1] ) ) 554 | $customfields[$fieldname] = $custommatches[1]; 555 | } 556 | else { // it's a tag 557 | $tag = $options['customfield_tag'][$index]; 558 | $tagatt = $options['customfield_tagatt'][$index]; 559 | $attval = $options['customfield_attval'][$index]; 560 | $xquery = '//'.$tag; 561 | if ( !empty( $tagatt ) ) 562 | $xquery .= '[@'.$tagatt.'="'.$attval.'"]'; 563 | $content = $xml->xpath( $xquery ); 564 | 565 | if ( is_array( $content ) && isset( $content[0] ) && is_object( $content[0] ) ) { 566 | $fieldcontent = $content[0]->asXML(); 567 | if ( !empty( $options['customfield_html'][$index] ) && !empty( $options['clean_html'] ) ) { 568 | $fieldcontent = $content[0]->asXML(); 569 | $fieldcontent = $this->clean_html( $fieldcontent, $options['allow_tags'], $options['allow_attributes'] ); 570 | if ( !empty( $fieldcontent ) ) 571 | $customfields[$fieldname] = $fieldcontent; 572 | } 573 | else { 574 | $fieldcontent = trim( strip_tags( $fieldcontent ) ); 575 | if ( !empty( $fieldcontent ) ) 576 | $customfields[$fieldname] = $fieldcontent; 577 | } 578 | } 579 | } 580 | } 581 | } 582 | 583 | // excerpt 584 | $excerpt = $options['meta_desc']; 585 | if ( !empty( $excerpt ) ) { 586 | $my_post['post_excerpt'] = $xml->xpath( '//meta[@name="description"]' ); 587 | if ( isset( $my_post['post_excerpt'][0] ) ) 588 | $my_post['post_excerpt'] = $my_post['post_excerpt'][0]['content']; 589 | if ( is_array( $my_post['post_excerpt'] ) ) 590 | $my_post['post_excerpt'] = implode( '',$my_post['post_excerpt'] ); 591 | $my_post['post_excerpt'] = ( string )$my_post['post_excerpt']; 592 | } 593 | 594 | // status 595 | $my_post['post_status'] = $options['status']; 596 | 597 | // author 598 | $my_post['post_author'] = $options['user']; 599 | } 600 | 601 | // if it's a single file, we can use a substitute for $path from here on 602 | if ( '' == trim( $path ) ) 603 | $handle = __( "the uploaded file", 'import-html-pages' ); 604 | else 605 | $handle = $path; 606 | 607 | // see if the post already exists 608 | // but don't bother printing this message if we're doing an index file; we know its parent already exists 609 | if ( $post_id = post_exists( $my_post['post_title'], $my_post['post_content'], $my_post['post_date'] ) && basename( $path ) != $options['index_file'] ) 610 | $this->table[] = "<tr><th class='error'>--</th><td colspan='3' class='error'> " . sprintf( __( "%s ( %s ) has already been imported", 'html-import-pages' ), $my_post['post_title'], $handle ) . "</td></tr>"; 611 | 612 | // if we're doing hierarchicals and this is an index file of a subdirectory, instead of importing this as a separate page, update the content of the placeholder page we created for the directory 613 | $index_files = explode( ',',$options['index_file'] ); 614 | if ( is_post_type_hierarchical( $options['type'] ) && dirname( $path ) != $options['root_directory'] && in_array( basename( $path ), $index_files ) ) { 615 | $post_id = array_search( dirname( $path ), $this->filearr ); 616 | if ( $post_id !== 0 ) 617 | $updatepost = true; 618 | } 619 | 620 | // find old path 621 | if ( '' !== trim( $path ) && !$updatepost ) { 622 | $url = esc_url( $options['old_url'] ); 623 | $url = rtrim( $url, '/' ); 624 | if ( !empty( $url ) ) 625 | $old_path = str_replace( $options['root_directory'], $url, $path ); 626 | else $old_path = $path; 627 | } 628 | 629 | // see if this file has been previously imported based on path 630 | $previous_import = get_posts( 631 | array ( 632 | 'post_type' => $my_post['post_type'], 633 | 'meta_key' => 'URL_before_HTML_Import', 634 | 'meta_value' => $old_path, 635 | 'posts_per_page' => 1 636 | ) 637 | ); 638 | 639 | // if so, set to update instead of import 640 | if ( !is_wp_error( $previous_import ) && !empty( $previous_import ) 641 | && $previous_import->post_title = $my_post['post_title'] ) { 642 | $post_id = $previous_import->ID; 643 | $updatepost = true; 644 | } 645 | 646 | // insert or update post 647 | if ( $updatepost ) { 648 | $my_post['ID'] = $post_id; 649 | wp_update_post( $my_post ); 650 | } 651 | else 652 | $post_id = wp_insert_post( $my_post ); 653 | 654 | // handle errors 655 | if ( is_wp_error( $post_id ) ) 656 | $this->table[] = "<tr><th class='error'>--</th><td colspan='3' class='error'> " . $post_id /* error msg */ . "</td></tr>"; 657 | if ( !$post_id ) 658 | $this->table[] = "<tr><th class='error'>--</th><td colspan='3' class='error'> " . sprintf( __( "Could not import %s. You should copy its contents manually.", 'html-import-pages' ), $handle ) . "</td></tr>"; 659 | 660 | // if no errors, handle custom fields 661 | if ( isset( $customfields ) ) { 662 | foreach ( $customfields as $fieldname => $fieldvalue ) { 663 | // allow user to set tags via custom field named 'post_tag' 664 | if ( $fieldname == 'post_tag' ) 665 | $customfieldtags = $fieldvalue; 666 | else 667 | add_post_meta( $post_id, $fieldname, $fieldvalue, true ); 668 | } 669 | } 670 | 671 | // ... and all the taxonomies... 672 | $taxonomies = get_taxonomies( array( 'public' => true ), 'objects', 'and' ); 673 | foreach ( $taxonomies as $tax ) { 674 | if ( isset( $options[$tax->name] ) ) 675 | wp_set_post_terms( $post_id, $options[$tax->name], $tax->name, false ); 676 | } 677 | if ( isset( $customfieldtags ) ) 678 | wp_set_post_terms( $post_id, $customfieldtags, 'post_tag', false ); 679 | 680 | // ...and set the page template, if any 681 | if ( isset( $options['page_template'] ) && !empty( $options['page_template'] ) ) 682 | add_post_meta( $post_id, '_wp_page_template', $options['page_template'], true ); 683 | 684 | // add redirects from old to new path; store old path in custom field 685 | if ( '' !== trim( $old_path ) && !$updatepost ) { 686 | $this->redirects .= "Redirect\t".$old_path."\t".get_permalink( $post_id )."\t[R=301,NC,L]\n"; 687 | add_post_meta( $post_id, 'URL_before_HTML_Import', $old_path, true ); 688 | } 689 | 690 | // store path so we can check for parents later ( even if it's empty; need that info for image imports ). 691 | // Don't store the index file updates; they'll screw up the parent search, and they can use their parents' path anyway 692 | if ( !$updatepost ) 693 | $this->filearr[$post_id] = $path; 694 | else { // index files will have an incomplete hierarchy if there were empty directories in their path 695 | $this->fix_hierarchy( $post_id, $path ); 696 | } 697 | 698 | // create the results table row AFTER fixing hierarchy 699 | if ( '' !== trim($path ) ) { 700 | if ( empty( $my_post['post_title'] ) ) 701 | $my_post['post_title'] = __( '( no title )', 'html-import' ); 702 | $this->table[$post_id] = " <tr><th>".$post_id."</th><td>".$path."</td><td>".get_permalink( $post_id ).'</td><td> 703 | <a href="post.php?action=edit&post='.$post_id.'">'.esc_html( $my_post['post_title'] )."</a></td></tr>"; 704 | } 705 | else { 706 | $this->single_result = sprintf( __( 'Imported the file as %s.', 'import-html-pages' ), '<a href="post.php?action=edit&post='.$post_id.'">'.$my_post['post_title'].'</a>' ); 707 | } 708 | } 709 | 710 | //Handle an individual file import. Borrowed almost entirely from dd32's Add From Server plugin 711 | function handle_import_media_file( $file, $post_id = 0 ) { 712 | 713 | // Remove the query string from the file URL. 714 | $src_file = $file; 715 | $file = preg_replace( '|\?.+$|', '', $file ); 716 | 717 | // see if the attachment already exists 718 | $id = array_search( $file, $this->filearr ); 719 | if ( $id === false ) { 720 | 721 | set_time_limit( 120 ); 722 | $post = get_post( $post_id ); 723 | $time = $post->post_date_gmt; 724 | 725 | // A writable uploads dir will pass this test. Again, there's no point overriding this one. 726 | if ( ! ( ( $uploads = wp_upload_dir( $time ) ) && false === $uploads['error'] ) ) 727 | return new WP_Error( 'upload_error', $uploads['error'] ); 728 | 729 | $filename = wp_unique_filename( $uploads['path'], basename( $file ) ); 730 | 731 | // copy the file to the uploads dir 732 | $new_file = $uploads['path'] . '/' . $filename; 733 | if ( false === @copy( $src_file, $new_file ) ) 734 | return new WP_Error( 'upload_error', sprintf( __( 'Could not find the right path to %s ( tried %s ). It could not be imported. Please upload it manually.', 'html-import-pages' ), basename( $file ), $file ) ); 735 | // DEBUG 736 | // else 737 | // printf( __( '<br /><em>%s</em> is being copied to the uploads directory as <em>%s</em>.', 'html-import-pages' ), $file, $new_file ); 738 | 739 | // Set correct file permissions 740 | $stat = stat( dirname( $new_file ) ); 741 | $perms = $stat['mode'] & 0000666; 742 | @chmod( $new_file, $perms ); 743 | // Compute the URL 744 | $url = $uploads['url'] . '/' . $filename; 745 | 746 | //Apply upload filters 747 | $return = apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => wp_check_filetype( $file, null ) ) ); 748 | $new_file = $return['file']; 749 | $url = $return['url']; 750 | $type = $return['type']; 751 | 752 | $title = preg_replace( '!\.[^.]+$!', '', basename( $file ) ); 753 | $content = ''; 754 | 755 | // use image exif/iptc data for title and caption defaults if possible 756 | if ( $image_meta = @wp_read_image_metadata( $new_file ) ) { 757 | if ( '' != trim( $image_meta['title'] ) ) 758 | $title = trim( $image_meta['title'] ); 759 | if ( '' != trim( $image_meta['caption'] ) ) 760 | $content = trim( $image_meta['caption'] ); 761 | } 762 | 763 | if ( $time ) { 764 | $post_date_gmt = $time; 765 | $post_date = $time; 766 | } 767 | else { 768 | $post_date = current_time( 'mysql' ); 769 | $post_date_gmt = current_time( 'mysql', 1 ); 770 | } 771 | 772 | // Construct the attachment array 773 | $wp_filetype = wp_check_filetype( basename( $filename ), null ); 774 | $attachment = array( 775 | 'post_mime_type' => $wp_filetype['type'], 776 | 'guid' => $url, 777 | 'post_parent' => $post_id, 778 | 'post_title' => $title, 779 | 'post_name' => $title, 780 | 'post_content' => $content, 781 | 'post_date' => $post_date, 782 | 'post_date_gmt' => $post_date_gmt 783 | ); 784 | 785 | //Win32 fix: 786 | $new_file = str_replace( strtolower( str_replace( '\\', '/', $uploads['basedir'] ) ), $uploads['basedir'], $new_file ); 787 | 788 | 789 | // Insert attachment 790 | $id = wp_insert_attachment( $attachment, $new_file, $post_id ); 791 | if ( !is_wp_error( $id ) ) { 792 | $data = wp_generate_attachment_metadata( $id, $new_file ); 793 | wp_update_attachment_metadata( $id, $data ); 794 | $this->filearr[$id] = $file; // $file contains the original, absolute path to the file 795 | } 796 | 797 | } // if attachment already exists 798 | return $id; 799 | } 800 | 801 | // Remove responsive images srcsets. 802 | function remove_srcsets() { 803 | 804 | foreach ( $this->filearr as $id => $path ) { 805 | 806 | $post = get_post( $id ); 807 | $content = preg_replace( '/(<img[^>]* )srcset=[\'"][^>\'"]+[\'"]/i', '$1', $post->post_content ); 808 | 809 | wp_update_post( array( 810 | 'ID' => $id, 811 | 'post_content' => $content 812 | ) ); 813 | } 814 | } 815 | 816 | // largely borrowed from the Add Linked Images to Gallery plugin, except we do a simple str_replace at the end 817 | function import_images( $id, $path ) { 818 | $post = get_post( $id ); 819 | $options = get_option( 'html_import' ); 820 | $result = array(); 821 | $srcs = array(); 822 | $content = $post->post_content; 823 | $title = $post->post_title; 824 | if ( empty( $title ) ) $title = __( '( no title )', 'html-import' ); 825 | $update = false; 826 | 827 | // find all src attributes 828 | preg_match_all( '/<img[^>]* src=[\'"]?([^>\'" ]+)/i', $post->post_content, $matches ); 829 | for ( $i=0; $i<count( $matches[0] ); $i++ ) { 830 | $srcs[] = $matches[1][$i]; 831 | } 832 | 833 | // also check custom fields 834 | $custom = get_post_meta( $id, '_ise_old_sidebar', true ); 835 | preg_match_all( '/<img[^>]* src=[\'"]?([^>\'" ]+)[\'"]/i', $custom, $matches ); 836 | for ( $i=0; $i<count( $matches[0] ); $i++ ) { 837 | $srcs[] = $matches[1][$i]; 838 | } 839 | 840 | if ( !empty( $srcs ) ) { 841 | $count = count( $srcs ); 842 | 843 | echo "<p>"; 844 | printf( _n( 'Found %d image in <a href="%s">%s</a>. Importing... ', 'Found %d images in <a href="%s">%s</a>. Importing... ', $count, 'html-import-pages' ), $count, get_permalink( $post->ID ), $title ); 845 | foreach ( $srcs as $src ) { 846 | // src="http://foo.com/images/foo" 847 | 848 | if ( preg_match( '/^https?:\/\//', $src ) ) { 849 | $imgpath = $src; 850 | } 851 | // src="/images/foo" 852 | elseif ( '/' == substr( $src, 0, 1 ) ) { 853 | $imgpath = $options['root_directory'] . $src; 854 | } 855 | // src="../../images/foo" or src="images/foo" or no $path 856 | else { 857 | if ( empty( $path ) ) 858 | $imgpath = $options['root_directory']. '/' . $src; 859 | else 860 | $imgpath = ( is_file( $path ) ? dirname( $path ) : $path ) . '/' . $src; 861 | } 862 | // intersect base path and src, or just clean up junk 863 | $_imgpath = $this->remove_dot_segments( $imgpath ); 864 | 865 | // load the image from $imgpath 866 | $imgid = $this->handle_import_media_file( $_imgpath, $id ); 867 | if ( is_wp_error( $imgid ) ) 868 | echo '<span class="attachment_error">'.$imgid->get_error_message().'</span>'; 869 | else { 870 | $imgpath = wp_get_attachment_url( $imgid ); 871 | 872 | // replace paths in the content 873 | if ( !is_wp_error( $imgpath ) ) { 874 | 875 | $content = str_replace( $src, $imgpath, $content ); 876 | $custom = str_replace( $src, $imgpath, $custom ); 877 | $update = true; 878 | } 879 | 880 | } // is_wp_error else 881 | 882 | } // foreach 883 | 884 | // update the post only once 885 | if ( $update == true ) { 886 | $my_post = array(); 887 | $my_post['ID'] = $id; 888 | $my_post['post_content'] = $content; 889 | wp_update_post( $my_post ); 890 | } 891 | 892 | _e( 'done.', 'html-import-images' ); 893 | echo '</p>'; 894 | flush(); 895 | } // if empty 896 | } 897 | 898 | function import_documents( $id, $path ) { 899 | $post = get_post( $id ); 900 | $options = get_option( 'html_import' ); 901 | $result = $srcs = array(); 902 | $content = $post->post_content; 903 | $title = $post->post_title; 904 | if ( empty( $title ) ) $title = __( '( no title )', 'html-import' ); 905 | $update = false; 906 | $mimes = explode( ',', $options['document_mimes'] ); 907 | 908 | // find all href attributes 909 | preg_match_all( '/<a[^>]* href=[\'"]?([^>\'" ]+)/i', $content, $matches ); 910 | for ( $i=0; $i<count( $matches[0] ); $i++ ) { 911 | $hrefs[] = $matches[1][$i]; 912 | } 913 | if ( !empty( $hrefs ) ) { 914 | $count = count( $hrefs ); 915 | 916 | echo "<p>"; 917 | printf( _n( 'Found %d link in <a href="%s">%s</a>. Checking file types... ', 'Found %d links in <a href="%s">%s</a>. Checking file types... ', $count, 'html-import-pages' ), $count, get_permalink( $post->ID ), $title ); 918 | 919 | //echo '<p>Looking in '.get_permalink( $id ).'</p>'; 920 | $options = get_option( 'html_import' ); 921 | $site = $options['old_url']; 922 | $rootdir = $options['root_directory']; 923 | foreach ( $hrefs as $href ) { 924 | $linkpath = ''; 925 | if ( '#' != substr( $href, 0, 1 ) && 'mailto:' != substr( $href, 0, 7 ) ) { // skip anchors and mailtos 926 | if ( preg_match( '/^http:\/\//', $href ) || preg_match( '/^https:\/\//', $href ) ) { 927 | // is it a link to something on this server? 928 | if ( stripos( $site, $href ) !== false ) 929 | // if it's an internal link, let's get a local file path 930 | $linkpath = str_replace( $site, $rootdir, $href ); 931 | } 932 | // href="/images/foo" 933 | elseif ( '/' == substr( $href, 0, 1 ) ) { 934 | $linkpath = $rootdir . $href; 935 | $linkpath = $this->remove_dot_segments( $linkpath ); 936 | } 937 | // href="../../images/foo" or href="images/foo" 938 | else { 939 | // we need to know where we are in the hierarchy 940 | $oldpath = get_post_meta( $id, 'URL_before_HTML_Import', true ); 941 | $oldpath = str_replace( $site, $rootdir, $oldpath ); 942 | // DEBUG 943 | //echo '<p>Old path: '.$oldpath; 944 | $oldfile = strrchr( $oldpath, '/' ); 945 | $linkpath = str_replace( $oldfile, '/'.$href, $oldpath ); 946 | $linkpath = $this->remove_dot_segments( $linkpath ); 947 | // DEBUG 948 | //echo ' Link path: '.$linkpath . '</p>'; 949 | } 950 | 951 | if ( !empty( $linkpath ) ) { // then we found an internal link 952 | $linkpath = rtrim( $linkpath, '/' ); 953 | // DEBUG 954 | //echo '<p>Old link: '.$href.' Full path: '.$linkpath; 955 | 956 | $filename_parts = explode( ".",$linkpath ); 957 | $ext = strtolower( $filename_parts[count( $filename_parts ) - 1] ); 958 | 959 | if ( in_array( $ext, $mimes ) ) { // allowed upload types only 960 | echo '<br />Importing '.ltrim( strrchr( $linkpath, '/' ), '/' ).'... '; 961 | // load the file from $linkpath 962 | $fileid = $this->handle_import_media_file( $linkpath, $id ); 963 | if ( is_wp_error( $fileid ) ) 964 | echo '<span class="attachment_error">'.$fileid->get_error_message().'</span>'; 965 | else { 966 | $filepath = wp_get_attachment_url( $fileid ); 967 | 968 | // replace paths in the content 969 | if ( !is_wp_error( $filepath ) ) { 970 | $content = str_replace( $href, $filepath, $content ); 971 | $update = true; 972 | } 973 | 974 | } // is_wp_error $fileid 975 | } // if in array 976 | 977 | 978 | } // if empty linkpath 979 | } // if #/mailto 980 | } // foreach 981 | 982 | // update the post only once 983 | if ( $update == true ) { 984 | $my_post = array(); 985 | $my_post['ID'] = $id; 986 | $my_post['post_content'] = $content; 987 | wp_update_post( $my_post ); 988 | } 989 | 990 | _e( 'done.', 'html-import-images' ); 991 | echo '</p>'; 992 | flush(); 993 | } // if empty $hrefs 994 | } 995 | 996 | function find_internal_links() { 997 | echo '<h2>'.__( 'Fixing relative links...', 'import-html-pages' ).'</h2>'; 998 | echo '<p>'.__( 'The importer is searching your imported posts for links. This might take a few minutes.', 'import-html-pages' ).'</p>'; 999 | 1000 | $fixedlinks = array(); 1001 | foreach ( $this->filearr as $id => $path ) { 1002 | $new_post = array(); 1003 | $post = get_post( $id ); 1004 | $new_post['ID'] = $post->ID; 1005 | $new_post['post_content'] = $this->fix_internal_links( $post->post_content, $post->ID ); 1006 | 1007 | if ( !empty( $new_post['post_content'] ) ) 1008 | wp_update_post( $new_post ); 1009 | $fixedlinks[] .= $post->ID; 1010 | } 1011 | if ( !empty( $fixedlinks ) ) { ?> 1012 | <h3><?php _e( 'All done!', 'import-html-pages' ); ?></h3> 1013 | <?php } 1014 | else _e( 'No posts were found with the URL_before_HTML_Import custom field. Could not search for links.', 'import-html-pages' ); 1015 | // DEBUG 1016 | //echo '<pre>'.print_r( $this->filearr, true ).'</pre>'; 1017 | } 1018 | 1019 | function find_images() { 1020 | echo '<h2>'.__( 'Importing images...', 'import-html-pages' ).'</h2>'; 1021 | $results = ''; 1022 | foreach ( $this->filearr as $id => $path ) { 1023 | $results .= $this->import_images( $id, $path ); 1024 | } 1025 | if ( !empty( $results ) ) 1026 | echo $results; 1027 | echo '<h3>'; 1028 | printf( __( 'All done. <a href="%s">Go to the Media Library.</a>' ), 'media.php' ); 1029 | echo '</h3>'; 1030 | // DEBUG 1031 | //echo '<pre>'.print_r( $this->filearr, true ).'</pre>'; 1032 | } 1033 | 1034 | function find_documents() { 1035 | echo '<h2>'.__( 'Importing media files...', 'import-html-pages' ).'</h2>'; 1036 | echo '<p>'.__( 'The importer is searching your imported posts for links to media files. This might take a few minutes.', 'import-html-pages' ).'</p>'; 1037 | 1038 | $results = ''; 1039 | foreach ( $this->filearr as $id => $path ) { 1040 | $results .= $this->import_documents( $id, $path ); 1041 | } 1042 | if ( !empty( $results ) ) 1043 | echo $results; 1044 | echo '<h3>'; 1045 | printf( __( 'All done. <a href="%s">Go to the Media Library.</a>' ), 'media.php' ); 1046 | echo '</h3>'; 1047 | // DEBUG 1048 | //echo '<pre>'.print_r( $this->filearr, true ).'</pre>'; 1049 | } 1050 | 1051 | function print_results( $posttype ) { 1052 | if ( !empty( $this->single_result ) ) 1053 | echo $this->single_result; 1054 | else { 1055 | ?> 1056 | <table class="widefat page fixed" id="importing" cellspacing="0"> 1057 | <thead><tr> 1058 | <th id="id"><?php _e( 'ID', 'import-html-pages' ); ?></th> 1059 | <th><?php _e( 'Old path', 'import-html-pages' ); ?></th> 1060 | <th><?php _e( 'New path', 'import-html-pages' ); ?></th> 1061 | <th><?php _e( 'Title', 'import-html-pages' ); ?></th> 1062 | </tr></thead><tbody> <?php foreach ( $this->table as $row ) echo $row; ?> </tbody></table> 1063 | 1064 | <?php 1065 | flush(); 1066 | 1067 | if ( !empty( $this->redirects ) ) { ?> 1068 | <h3><?php _e( '.htaccess Redirects', 'import-html-pages' ); ?></h3> 1069 | <textarea id="import-result"><?php echo $this->redirects; ?></textarea> 1070 | <p><?php printf( __( 'If you need to <a href="%s">change your permalink structure</a>, you can <a href="%s">regenerate the redirects</a> ( or do it later from the <a href="%s">options screen</a> under Tools ).', 'import-html-pages' ), 'options-permalink.php', wp_nonce_url( 'admin.php?import=html&step=2', 'html_import_regenerate' ), 'options-general.php?page=html-import.php' ) ?></p> 1071 | <?php } 1072 | } 1073 | echo '<h3>'; 1074 | printf( __( 'All done. <a href="%s">Have fun!</a>', 'import-html-pages' ), 'edit.php?post_type='.$posttype ); 1075 | echo '</h3>'; 1076 | flush(); 1077 | // DEBUG 1078 | // echo '<pre>'.print_r( $this->filearr, true ).'</pre>'; 1079 | } 1080 | 1081 | function import() { 1082 | $options = get_option( 'html_import' ); 1083 | 1084 | if ( $_POST['import_files'] == 'file' ) { 1085 | // preserve original file name so we can use it for slugs later ( maybe ) 1086 | $this->filename = $_FILES['import']['name']; 1087 | 1088 | // upload the file 1089 | $file = wp_import_handle_upload(); 1090 | if ( isset( $file['error'] ) ) { 1091 | echo $file['error']; 1092 | return; 1093 | } 1094 | 1095 | echo '<h2>'.__( 'Importing HTML file...', 'import-html-pages' ).'</h2>'; 1096 | $this->file = $file['file']; 1097 | $this->get_single_file(); 1098 | $this->print_results( $options['type'] ); 1099 | wp_import_cleanup( $file['id'] ); 1100 | if ( $options['remove_srcset'] ) 1101 | $this->remove_srcsets(); 1102 | if ( $options['import_images'] ) 1103 | $this->find_images(); 1104 | if ( $options['import_documents'] ) 1105 | $this->find_documents(); 1106 | if ( $options['fix_links'] ) 1107 | $this->find_internal_links(); 1108 | } 1109 | elseif ( $_POST['import_files'] == 'directory' ) { 1110 | // in case they entered something dumb and didn't fix it when we showed an error on the options page... 1111 | if ( validate_import_file( $options['root_directory'] ) > 0 ) 1112 | wp_die( __( "The beginning directory you entered is not an absolute path. Relative paths are not allowed here.", 'import-html-pages' ) ); 1113 | 1114 | $this->table = ''; 1115 | $this->redirects = ''; 1116 | $this->filearr = array(); 1117 | $skipdirs = explode( ",", $options['skipdirs'] ); 1118 | $this->skip = array_merge( $skipdirs, array( '.', '..', '_vti_cnf', '_notes' ) ); 1119 | $this->allowed = explode( ",", $options['file_extensions'] ); 1120 | 1121 | echo '<h2>'.__( 'Importing HTML files...', 'import-html-pages' ).'</h2>'; 1122 | $this->get_files_from_directory( $options['root_directory'] ); 1123 | $this->print_results( $options['type'] ); 1124 | if ( isset( $options['remove_srcset'] ) && $options['remove_srcset'] ) 1125 | $this->remove_srcsets(); 1126 | if ( isset( $options['import_images'] ) && $options['import_images'] ) 1127 | $this->find_images(); 1128 | if ( isset( $options['import_documents'] ) && $options['import_documents'] ) 1129 | $this->find_documents(); 1130 | if ( isset( $options['fix_links'] ) && $options['fix_links'] ) 1131 | $this->find_internal_links(); 1132 | } 1133 | else { 1134 | _e( "Your file upload didn't work. Try again?", 'html-import-pages' ); 1135 | } 1136 | 1137 | do_action( 'import_done', 'html' ); 1138 | } 1139 | 1140 | function dispatch() { 1141 | if ( empty ( $_GET['step'] ) ) 1142 | $step = 0; 1143 | else 1144 | $step = ( int ) $_GET['step']; 1145 | 1146 | $this->header(); 1147 | 1148 | switch ( $step ) { 1149 | case 0 : 1150 | $this->greet(); 1151 | break; 1152 | case 1 : 1153 | check_admin_referer( 'html-import' ); 1154 | $result = $this->import(); 1155 | if ( is_wp_error( $result ) ) 1156 | echo $result->get_error_message(); 1157 | break; 1158 | case 2 : 1159 | $this->regenerate_redirects(); 1160 | break; 1161 | } 1162 | 1163 | $this->footer(); 1164 | } 1165 | 1166 | function importer_styles() { 1167 | ?> 1168 | <style type="text/css"> 1169 | textarea#import-result { height: 12em; width: 100%; } 1170 | #importing th { width: 32% } 1171 | #importing th#id { width: 4% } 1172 | #importing tbody tr:nth-child( odd ) { background: #f9f9f9; } 1173 | span.attachment_error { display: block; padding-left: 2em; color: #d54e21; /* WP orange */ } 1174 | </style> 1175 | <?php 1176 | } 1177 | 1178 | function __construct() { 1179 | add_action( 'admin_head', array( &$this, 'importer_styles' ) ); 1180 | } 1181 | } 1182 | 1183 | } // class_exists( 'WP_Importer' ) 1184 | 1185 | global $html_import; 1186 | $html_import = new HTML_Import(); 1187 | 1188 | register_importer( 'html', __( 'HTML', 'import-html-pages' ), sprintf( __( 'Import the contents of HTML files as posts, pages, or any custom post type. Visit <a href="%s">the options page</a> first to select which portions of your documents should be imported.', 'import-html-pages' ), 'options-general.php?page=html-import.php' ), array ( $html_import, 'dispatch' ) ); 1189 | 1190 | 1191 | // in case this server doesn't have php_mbstring enabled in php.ini... 1192 | if ( !function_exists( 'mb_strlen' ) ) { 1193 | function mb_strlen( $string ) { 1194 | return strlen( utf8_decode( $string ) ); 1195 | } 1196 | } 1197 | if ( !function_exists( 'mb_strrpos' ) ) { 1198 | function mb_strrpos( $haystack, $needle, $offset = 0 ) { 1199 | return strrpos( utf8_decode( $haystack ), $needle, $offset ); 1200 | } 1201 | } --------------------------------------------------------------------------------