Created
May 18, 2018 02:13
-
-
Save yasinkuyu/bb08a6f12922d30819e6a254d5b8dab6 to your computer and use it in GitHub Desktop.
T-Soft Blog migration Opencart Blog (Dreamvention)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting(E_ALL); | |
ini_set('display_errors', 1); | |
# T-Soft Blog migration Opencart Blog (Dreamvention) | |
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 = "[email protected]"; | |
$password = "xxx"; | |
$base_url = "http://domain.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'); | |
$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]; | |
$conn = new mysqli("localhost", "USER", "PASS", "DB"); | |
if ($conn->connect_error) { | |
die("Connection failed: " . $conn->connect_error); | |
} | |
$post_sql = $conn->query("INSERT INTO oc_bm_post (user_id, image) VALUES ('1', '".$image."')"); | |
if ($post_sql === TRUE) { | |
echo $pid . "-) Blog yazısı eklendi.<hr>"; | |
$post_id = $conn->insert_id; | |
$post_desc_sql = $conn->query("INSERT INTO oc_bm_post_description (post_id, language_id, short_description, description, title, meta_title, meta_keyword, meta_description, tag) VALUES ('".$post_id."', '1', '".addslashes($spot)."', '".addslashes($desc)."', '".addslashes($title)."', '".addslashes($seo_title)."', '".addslashes($seo_keyword)."', '".addslashes($seo_description)."', '".addslashes($seo_keyword)."')"); | |
if ($post_desc_sql === TRUE) { | |
echo "Yazı açıklaması eklendi.<br>"; | |
$post_cat_sql = $conn->query("INSERT INTO oc_bm_post_to_category (post_id, category_id) VALUES ('".$post_id."', '1')"); | |
if ($post_cat_sql === TRUE) { | |
echo "Yazı kategoriye eklendi.<br>"; | |
$post_store_sql = $conn->query("INSERT INTO oc_bm_post_to_store (post_id, store_id) VALUES ('".$post_id."', '0')"); | |
if ($post_store_sql === TRUE) { | |
echo "Yazı mağazaya eklendi.<br>"; | |
$post_layout_sql = $conn->query("INSERT INTO oc_bm_post_to_layout (post_id, store_id, layout_id) VALUES ('".$post_id."', '0', '0')"); | |
if ($post_layout_sql === TRUE) { | |
echo "Yazı layouta eklendi.<br>"; | |
} else { | |
echo "Error5: <br>" . $conn->error; | |
} | |
} else { | |
echo "Error1: <br>" . $conn->error; | |
} | |
} else { | |
echo "Error2: <br>" . $conn->error; | |
} | |
} else { | |
echo "Error3: <br>" . $conn->error; | |
} | |
} else { | |
echo "Error4: <br>" . $conn->error; | |
} | |
$conn->close(); | |
} | |
} | |
} | |
for ($i=1; $i < 245; $i++) { | |
get_blog_post($i); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment