Skip to content

Commit

Permalink
Should be all working, except that internal links no longer work, not…
Browse files Browse the repository at this point in the history
… sure how to fix that
  • Loading branch information
herent committed Aug 25, 2011
1 parent c430858 commit be476bd
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 24 deletions.
2 changes: 2 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ Not so great:
Would be nice:
- Option to import just posts or just pages.
- some kind of rudimentary support for image captions, like <div class="wp-import-image"> <img /> <span class="wp-import-caption">caption</span></div>
- Somehow keep post url structure, or update internal links in post content
- Better import of images, script as is tries to import flickr images that probably shouldn't be imported
3 changes: 3 additions & 0 deletions controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public function install() {

public function uninstall() {
$db = Loader::db();

$dashPage = Page::getByPath("/dashboard/wordpress_import");
$dashPage->delete();
$db->Execute('drop table WordpressItems');
parent::uninstall();
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/dashboard/wordpress_import/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function import_wordpress_xml() {
$opt = new SelectAttributeTypeOption(0, $tags[$i]['tag_name'], $i);
$opt = $opt->saveOrCreate($akt);
}

} else {
echo t("No file");
exit;
Expand Down
8 changes: 4 additions & 4 deletions controllers/dashboard/wordpress_import/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public function get_root_pages() {
$json = Loader::helper('json');
$data = array();
$pageRoot = Page::getByID($this->post('new-root-pages'));
$data['page-title'] = $pageRoot->getCollectionName();
$data['page-url'] = $pageRoot->getCollectionPath();
$data['page_title'] = $pageRoot->getCollectionName();
$data['page_url'] = $pageRoot->getCollectionPath();
$postRoot = Page::getByID($this->post('new-root-posts'));
$data['post-title'] = $postRoot->getCollectionName();
$data['post-url'] = $postRoot->getCollectionPath();
$data['post_title'] = $postRoot->getCollectionName();
$data['post_url'] = $postRoot->getCollectionPath();
echo $json->encode($data);
exit;
}
Expand Down
69 changes: 67 additions & 2 deletions libraries/wordpress_file_post_importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,68 @@ function importFile($fileUrl){
// itterate over each incoming URL adding if relevant
foreach($incoming_urls as $this_url) {
// try to D/L the provided file
$client = new Zend_Http_Client($this_url);
// This all sets up the CURL actions to check the page
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this_url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10); //follow up to 10 redirections - avoids loops
$data = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); // Get the HTTP Code
// Get final redirected URL, will be the same if URL is not redirected
$new_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
curl_close($ch);

// Array of HTTP status codes. Trim down if you would like to.
$codes = array(0=>'Domain Not Found',
100=>'Continue',
101=>'Switching Protocols',
200=>'OK',
201=>'Created',
202=>'Accepted',
203=>'Non-Authoritative Information',
204=>'No Content',
205=>'Reset Content',
206=>'Partial Content',
300=>'Multiple Choices',
301=>'Moved Permanently',
302=>'Found',
303=>'See Other',
304=>'Not Modified',
305=>'Use Proxy',
307=>'Temporary Redirect',
400=>'Bad Request',
401=>'Unauthorized',
402=>'Payment Required',
403=>'Forbidden',
404=>'Not Found',
405=>'Method Not Allowed',
406=>'Not Acceptable',
407=>'Proxy Authentication Required',
408=>'Request Timeout',
409=>'Conflict',
410=>'Gone',
411=>'Length Required',
412=>'Precondition Failed',
413=>'Request Entity Too Large',
414=>'Request-URI Too Long',
415=>'Unsupported Media Type',
416=>'Requested Range Not Satisfiable',
417=>'Expectation Failed',
500=>'Internal Server Error',
501=>'Not Implemented',
502=>'Bad Gateway',
503=>'Service Unavailable',
504=>'Gateway Timeout',
505=>'HTTP Version Not Supported');
if (isset($codes[$http_code])) {
if ($codes[$http_code] == "OK"){
$client = new Zend_Http_Client($this_url);


$response = $client->request();

if ($response->isSuccessful()) {
$uri = Zend_Uri_Http::fromString($this_url);
$fname = '';
Expand Down Expand Up @@ -106,6 +165,12 @@ function importFile($fileUrl){
// warn that we couldn't download the file
$errors[] = t('There was an error downloading ') . $this_url;
}
}
} else {
$errors[] = t("Error connecting to file's server, file skipped");
}


}
}
//print_r($errors);
Expand Down
2 changes: 2 additions & 0 deletions single_pages/dashboard/wordpress_import/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ function ok_submit() {
<div class="ccm-dashboard-inner">
<form id="import-wordpress-xml" method="post" action="<?php echo $this->action('import_wordpress_xml') ?>">
<div style="width:400px">
<?php if ($records == 0){?>
<h2> <?php echo t("Please Upload/Select your Wordpress export xml file.") ?></h2>
<?php echo $al->file('wordpress-file','wp-file',t('Choose Wordpress File')); ?>
<?php } ?>
<?php if ($records > 0) {
?><br/><h2>&nbsp;&nbsp;&nbsp;<?php echo t("Ready to import ").$records.t(" records.");?></h2>
<?php }?>
Expand Down
36 changes: 19 additions & 17 deletions single_pages/dashboard/wordpress_import/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,34 +52,34 @@
wpImport.continue_import(remain,done);
} else {
$("#progress h1").html("Import Finished.");
wpImport.importCategories();
$("#progress .titles").hide("slow");
wpImport.show_link();
}
},"json");
},
show_link: function() {
$.post('<?php echo $this->action('get_root_page') ?>', $("#import-wordpress-form").serialize(), function(data) {
if (data.post-url == data.page-url){
if(data.post-title && data.post-url) {
$("#progress .parent-page").html('<?php echo t("Visit your imported site: ") ?><a href="<?php echo BASE_URL . DIR_REL ?>'+data.url+'">'+data.title+'</a>');
$.post('<?php echo $this->action('get_root_pages') ?>', $("#import-wordpress-form").serialize(), function(data) {
if (data.post_url == data.page_url){
if(data.post_title && data.post_url) {
$("#progress .parent-page").html('<?php echo t("Visit your imported site: ") ?><a href="<?php echo BASE_URL . DIR_REL ?>'+data.page_url+'">'+data.page_title+'</a>');
$("#progress .parent-page").show("fast");
} else if(data.post-title) {
$("#progress .parent-page").html('<?php echo t("Visit your imported site: ") ?><a href="<?php echo BASE_URL . DIR_REL ?>">'+data.title+'</a>');
} else if(data.post_title) {
$("#progress .parent-page").html('<?php echo t("Visit your imported site: ") ?><a href="<?php echo BASE_URL . DIR_REL ?>">'+data.page_title+'</a>');
$("#progress .parent-page").show("fast");
}
} else {
if(data.post-title && data.post-url) {
$("#progress .parent-page").html('<?php echo t("Visit your imported posts: ") ?><a href="<?php echo BASE_URL . DIR_REL ?>'+data.url+'">'+data.title+'</a>');
$("#progress .parent-page").show("fast");
} else if(data.post-title) {
$("#progress .parent-page").html('<?php echo t("Visit your imported posts: ") ?><a href="<?php echo BASE_URL . DIR_REL ?>">'+data.title+'</a>');
$("#progress .parent-page").show("fast");
if(data.post_title && data.post_url) {
$("#progress .parent-post").html('<?php echo t("Visit your imported posts: ") ?><a href="<?php echo BASE_URL . DIR_REL ?>'+data.post_url+'">'+data.post_title+'</a>');
$("#progress .parent-post").show("fast");
} else if(data.post_title) {
$("#progress .parent-post").html('<?php echo t("Visit your imported posts: ") ?><a href="<?php echo BASE_URL . DIR_REL ?>">'+data.post_title+'</a>');
$("#progress .parent-post").show("fast");
}
if(data.post-title && data.post-url) {
$("#progress .parent-page").html('<?php echo t("Visit your imported posts: ") ?><a href="<?php echo BASE_URL . DIR_REL ?>'+data.url+'">'+data.title+'</a>');
if(data.page_title && data.page_url) {
$("#progress .parent-page").html('<?php echo t("Visit your imported pages: ") ?><a href="<?php echo BASE_URL . DIR_REL ?>'+data.page_url+'">'+data.page_title+'</a>');
$("#progress .parent-page").show("fast");
} else if(data.post-title) {
$("#progress .parent-page").html('<?php echo t("Visit your imported posts: ") ?><a href="<?php echo BASE_URL . DIR_REL ?>">'+data.title+'</a>');
} else if(data.page_title) {
$("#progress .parent-page").html('<?php echo t("Visit your imported pages: ") ?><a href="<?php echo BASE_URL . DIR_REL ?>">'+data.page_title+'</a>');
$("#progress .parent-page").show("fast");
}
}
Expand Down Expand Up @@ -120,6 +120,8 @@
</div>
<p class="parent-page">
</p>
<p class="parent-post">
</p>
<ul class="titles" >
</ul>
</div>
Expand Down

0 comments on commit be476bd

Please sign in to comment.