Skip to content

Instantly share code, notes, and snippets.

@yasinkuyu
Created May 18, 2018 02:17
Show Gist options
  • Save yasinkuyu/1912d2852be83e5aaae73c15df1b22c4 to your computer and use it in GitHub Desktop.
Save yasinkuyu/1912d2852be83e5aaae73c15df1b22c4 to your computer and use it in GitHub Desktop.
T-Soft Blog migration Wordpress
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
# T-Soft Blog migration Wordpress
function save_image($inPath,$outPath)
{
$in= fopen($inPath, "rb");
$out= fopen($outPath, "wb");
while ($chunk = fread($in,8192))
{
fwrite($out, $chunk, 8192);
}
fclose($in);
fclose($out);
}
function get_blog_post($pid) {
$username = "xxx@xxx.net";
$password = "xxx";
$base_url = "http://xxx.com";
$blog_url = $base_url."/Y/mod/Blog/Blog/editPostForm/". $pid;
//set the directory for the cookie using defined document root var
$path = "/temp";
//login form action url
$postinfo = "username=".$username."&password=".$password."&language=tr&imagecodet=";
$cookie_file_path = $path."/cookie.txt";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_URL, $base_url."/srv/service/admin/login");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIE, "cookiename=0");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo);
curl_exec($ch);
curl_setopt($ch, CURLOPT_URL, $blog_url);
$html = curl_exec($ch);
curl_close($ch);
if ($html != "") {
$dom = new DOMDocument();
$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$title = $xpath->query('//input[@name="OzetBaslik"]')[0]->getAttribute('value');
if($title != "") {
#$catid = $xpath->query('//select[@name="KategoriId"]/option')->getAttribute('value');
$image = $xpath->query('//img[@id="postResim"]')[0]->getAttribute('src');
$spot = $xpath->query('//textarea[@name="OzetAciklama"]')[0]->textContent;
$desc = $xpath->query('//textarea[@name="DetayAciklama"]')[0]->textContent;
$seo_url = $xpath->query('//input[@name="SeoLink"]')[0]->getAttribute('value');
$seo_title = $xpath->query('//input[@name="SeoTitle"]')[0]->getAttribute('value');
$seo_keyword = $xpath->query('//textarea[@name="SeoKeywords"]')[0]->textContent;
$seo_description = $xpath->query('//textarea[@name="SeoDescription"]')[0]->textContent;
# save_image($base_url.$image, str_replace("/Data/Blog/", "", "image/catalog/blog/".explode("?", $image)[0]));
#$image = str_replace("/Data/", "catalog/", $image);
#$image = explode("?", $image)[0];
$img_pid = $pid + 1000;
echo '<item>
<title>'.$title.'</title>
<link>http://domain.com/blog/'.$seo_url.'/</link>
<pubDate>Fri, 18 May 2018 00:20:55 +0000</pubDate>
<dc:creator><![CDATA[admin]]></dc:creator>
<guid isPermaLink="false">http://domain.com/blog/?p='.$pid.'</guid>
<description></description>
<content:encoded><![CDATA['.$desc.']]></content:encoded>
<excerpt:encoded><![CDATA[]]></excerpt:encoded>
<wp:post_id>'.$pid.'</wp:post_id>
<wp:post_date><![CDATA[2018-05-18 03:20:55]]></wp:post_date>
<wp:post_date_gmt><![CDATA[2018-05-18 00:20:55]]></wp:post_date_gmt>
<wp:comment_status><![CDATA[open]]></wp:comment_status>
<wp:ping_status><![CDATA[open]]></wp:ping_status>
<wp:post_name><![CDATA['.$seo_url.']]></wp:post_name>
<wp:status><![CDATA[publish]]></wp:status>
<wp:post_parent>0</wp:post_parent>
<wp:menu_order>0</wp:menu_order>
<wp:post_type><![CDATA[post]]></wp:post_type>
<wp:is_sticky>0</wp:is_sticky>
<category domain="category" nicename="genel"><![CDATA[Genel]]></category>
<wp:postmeta>
<wp:meta_key><![CDATA[_thumbnail_id]]></wp:meta_key>
<wp:meta_value><![CDATA['.$img_pid.']]></wp:meta_value>
</wp:postmeta>
</item>
<item>
<title>'. $image .'</title>
<link>http://domain.com/blog/?attachment_id='.$img_pid.'</link>
<pubDate>Fri, 18 May 2018 01:49:27 +0000</pubDate>
<dc:creator><![CDATA[admin]]></dc:creator>
<guid isPermaLink="false">'. $base_url.$image .'</guid>
<description></description>
<content:encoded><![CDATA[]]></content:encoded>
<excerpt:encoded><![CDATA[]]></excerpt:encoded>
<wp:post_id>'.$img_pid.'</wp:post_id>
<wp:post_date><![CDATA[2018-05-18 04:49:27]]></wp:post_date>
<wp:post_date_gmt><![CDATA[2018-05-18 01:49:27]]></wp:post_date_gmt>
<wp:comment_status><![CDATA[open]]></wp:comment_status>
<wp:ping_status><![CDATA[closed]]></wp:ping_status>
<wp:post_name><![CDATA['. $image .']]></wp:post_name>
<wp:status><![CDATA[inherit]]></wp:status>
<wp:post_parent>1</wp:post_parent>
<wp:menu_order>0</wp:menu_order>
<wp:post_type><![CDATA[attachment]]></wp:post_type>
<wp:post_password><![CDATA[]]></wp:post_password>
<wp:is_sticky>0</wp:is_sticky>
<wp:attachment_url><![CDATA['. $base_url.$image .']]></wp:attachment_url>
<wp:postmeta>
<wp:meta_key><![CDATA[_wp_attached_file]]></wp:meta_key>
<wp:meta_value><![CDATA['. $image .']]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[_wp_attachment_metadata]]></wp:meta_key>
<wp:meta_value><![CDATA[a:5:{s:5:"width";i:600;s:6:"height";i:924;s:4:"file";s:29:"'. $image .'";s:5:"sizes";a:3:{s:9:"thumbnail";a:4:{s:4:"file";s:29:"yigit-bulut-belly-150x150.jpg";s:5:"width";i:150;s:6:"height";i:150;s:9:"mime-type";s:10:"image/jpeg";}s:6:"medium";a:4:{s:4:"file";s:29:"'. $image .'";s:5:"width";i:195;s:6:"height";i:300;s:9:"mime-type";s:10:"image/jpeg";}s:32:"twentyseventeen-thumbnail-avatar";a:4:{s:4:"file";s:29:"'. $image .'";s:5:"width";i:100;s:6:"height";i:100;s:9:"mime-type";s:10:"image/jpeg";}}s:10:"image_meta";a:12:{s:8:"aperture";s:1:"0";s:6:"credit";s:0:"";s:6:"camera";s:0:"";s:7:"caption";s:0:"";s:17:"created_timestamp";s:1:"0";s:9:"copyright";s:0:"";s:12:"focal_length";s:1:"0";s:3:"iso";s:1:"0";s:13:"shutter_speed";s:1:"0";s:5:"title";s:0:"";s:11:"orientation";s:1:"0";s:8:"keywords";a:0:{}}}]]></wp:meta_value>
</wp:postmeta>
</item>
';
echo ' ';
}
}
}
echo '<?xml version="1.0" encoding="UTF-8" ?>
<!-- generator="WordPress/4.9.5" created="2018-05-18 00:30" -->
<rss version="2.0"
xmlns:excerpt="http://wordpress.org/export/1.2/excerpt/"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:wp="http://wordpress.org/export/1.2/"
>
<channel>
<title>Domain Blog</title>
<link>http://domain.com/blog</link>
<description>Domain Blog</description>
<pubDate>Fri, 18 May 2018 00:30:43 +0000</pubDate>
<language>tr-TR</language>
<wp:wxr_version>1.2</wp:wxr_version>
<wp:base_site_url>http://domain.com/blog</wp:base_site_url>
<wp:base_blog_url>http://domain.com/blog</wp:base_blog_url>
<wp:author><wp:author_id>1</wp:author_id><wp:author_login><![CDATA[admin]]></wp:author_login><wp:author_email><![CDATA[xxx@xxx.net]]></wp:author_email><wp:author_display_name><![CDATA[admin]]></wp:author_display_name><wp:author_first_name><![CDATA[]]></wp:author_first_name><wp:author_last_name><![CDATA[]]></wp:author_last_name></wp:author>
<generator>https://wordpress.org/?v=4.9.5</generator>';
for ($i=1; $i < 255; $i++) {
get_blog_post($i);
}
echo '</channel>
</rss>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment