Created
December 24, 2020 19:31
-
-
Save PonomareVlad/4b2786f4bd2f2d56fff287be92faaa10 to your computer and use it in GitHub Desktop.
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 | |
/* | |
* Tool to parse disqus comments xml file. | |
* | |
* @author Prahlad Yeri<[email protected]> | |
* @date 2017-09-06 | |
* */ | |
function find_url($root, $thid) { | |
foreach($root->thread as $thread) { | |
$curr_id = $thread->attributes("dsq", true)[0]; | |
if (strcmp($thid,$curr_id) === 0) { | |
$url = $thread->id; | |
return $url; | |
} | |
} | |
return null; | |
} | |
function parse_disqus_file($filename) { | |
$xmlstr = file_get_contents($filename); | |
$root = new SimpleXMLElement($xmlstr); | |
$posts = $root->post; | |
$cnt = 0; | |
$result = []; | |
foreach($posts as $post) { | |
$thid = ""; | |
foreach($post->thread->attributes("dsq",true) as $a=>$b) { | |
$thid = $b; | |
break; | |
} | |
$url = find_url($root, $thid); | |
$values = array( | |
"body"=>strip_tags($post->message), | |
"name"=>$post->author->name, | |
"email"=>$post->author->email, | |
//"created_at"=>date("Y-m-dTH:i:sZ", $post->created_at), | |
//"created_at"=>date_create($post->createdAt), | |
"created_at"=>$post->createdAt, | |
"url"=>$url, | |
); | |
array_push($result, $values); | |
$cnt++; | |
} | |
return $result; | |
} | |
echo parse_disqus_file($_REQUEST['url']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment