示例#1
0
 /**
  * Ensures the provided WebPage is imported into WordPress.  $stubs_only will force the import to create a stub (only creates the page with a title, no content) or do a full import.  A record of the page being imported is stored in $html_post_lookup which is returned updated.  $media_lookup maintains a list of all local media files that have been imported, and it is updated during the course of this import and returned.  The HtmlImportSettings defines various settings to apply to the imported page.
  *
  * @param \html_import\indices\WebPage          $webPage
  * @param bool                                  $stubs_only
  * @param                                       $html_post_lookup
  * @param                                       $media_lookup
  * @param \html_import\admin\HtmlImportSettings $settings
  *
  * @return \html_import\WPMetaConfigs
  */
 private function importAndRecordWebPage(\html_import\indices\WebPage $webPage, $stubs_only = true, &$html_post_lookup, &$media_lookup, html_import\admin\HtmlImportSettings $settings)
 {
     $category = $settings->getCategories()->getValuesArray();
     $tag = array();
     // build up the categories from the settings;
     if (!is_null($category) && is_array($category)) {
         foreach ($category as $index => $cat) {
             $cat_id = get_cat_ID(trim($cat));
             $categoryIDs[$index] = intval($cat_id);
         }
     }
     // placeholder, in the future build up the tags
     if (!is_null($tag) && is_array($tag)) {
         foreach ($tag as $t) {
             //TODO: support tags
         }
     }
     $parent_page = new \html_import\WPMetaConfigs();
     // get the id of the parent selected in the settings page
     $hasParent = $parent_page->loadFromPostID($settings->getParentPage()->getValue());
     $parent_page_id = null;
     if ($hasParent) {
         $parent_page_id = $settings->getParentPage()->getValue();
     }
     // determine if the page itself was loaded from the index with a parent page, then override the id if so
     $parentWebPage = $webPage->getParent();
     if (!is_null($parentWebPage)) {
         if (!is_null($wp_id = $parentWebPage->getWPID())) {
             $parent_page_id = $wp_id;
         }
     }
     // create the appropriate importer and perform the import
     // TODO: this creation is a candidate to be replaced with a factory
     $stages = new \html_import\HTMLImportStages();
     $postMeta = $this->importAnHTML($webPage, $settings, $parent_page_id, $html_post_lookup);
     if (!$webPage->isFolder()) {
         if ($stubs_only) {
             $stubImport = new html_import\HTMLStubImporter($settings, $stages);
             $stubImport->import($webPage, $postMeta, $html_post_lookup, $media_lookup);
         } else {
             $fullImport = new html_import\HTMLFullImporter($settings, $stages);
             $fullImport->import($webPage, $postMeta, $html_post_lookup, $media_lookup);
         }
     } else {
         $folderImport = new html_import\FolderImporter($settings, $stages);
         $folderImport->import($webPage, $postMeta, $html_post_lookup, $media_lookup);
     }
     return $postMeta;
 }
示例#2
0
文件: admin.php 项目: katebron/DCA_wp
_e('Select the file import:', 'file-upload');
?>
</label>
			<input type="file" name="file-upload" id="file-upload" size="35" class="file-upload" />
		</p>

		<p>

		<h3>Select the parent page for the imported files</h3>
		<label for="parent_page"><?php 
_e('Parent Page:', 'import-html-pages');
?>
</label>
		<select name="parent_page">
			<?php 
echo '<option value="0" ' . selected($settings->getParentPage()->getValue() == 0, true, false) . '>None</option>';
$search_args = array('sort_order' => 'ASC', 'sort_column' => 'post_title', 'hierarchical' => 1, 'exclude' => '', 'include' => '', 'meta_key' => '', 'meta_value' => '', 'authors' => '', 'child_of' => 0, 'parent' => -1, 'exclude_tree' => '', 'number' => '', 'offset' => 0, 'post_type' => 'page', 'post_status' => 'publish');
$pages = get_pages($search_args);
if (isset($pages)) {
    foreach ($pages as $page) {
        $ancestors = get_ancestors($page->ID, 'page');
        $strlen = strlen($page->post_title) + 2 * sizeof($ancestors);
        $pageName = str_pad($page->post_title, $strlen, " ", STR_PAD_LEFT);
        $pageName = str_replace(" ", "&nbsp;", $pageName);
        echo '<option value="' . $page->ID . '" ' . selected($settings->getParentPage()->getValue() == $page->ID, true, false) . '>' . $pageName . '</option>';
    }
}
?>
		</select>
		</p>
		<p>