Created
May 16, 2012 14:32
-
-
Save pi3ch/2710799 to your computer and use it in GitHub Desktop.
Convert Joomla Chrono comments to Disqus XML format
This file contains hidden or 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 | |
| /* | |
| * A simple and dirty script to convert Joomla Chrono comments to Disqus (XML) format | |
| * Pi3cH | |
| * May 2012 | |
| * NOTE: You might need to modify the identifier it is now in the format of Y/m/d/slug | |
| * */ | |
| date_default_timezone_set('UTC'); | |
| define('LB', "\n"); | |
| error_reporting(E_ALL); | |
| $mysql_username=""; | |
| $mysql_password=""; | |
| $mysql_host="localhost"; | |
| $mysql_database="joomla"; | |
| $chrono_tablename="jos_chrono_comments"; | |
| $joomla_tablepost="jos_content"; | |
| $web_url="http://www.pedramhayati.com"; //link to your website | |
| $mysql_con=mysql_connect($mysql_host, $mysql_username, $mysql_password, $mysql_database); | |
| mysql_select_db($mysql_database,$mysql_con); | |
| $dump=mysql_query("SELECT name, email, url, datetime, $chrono_tablename.parentid, $chrono_tablename.id as commentid, text as comment, title, alias as slug, created FROM $chrono_tablename, $joomla_tablepost WHERE $chrono_tablename.pageid = $joomla_tablepost.id AND published = '1' ORDER BY $joomla_tablepost.id ASC"); | |
| $out= <<<EOF | |
| <?xml version="1.0" encoding="UTF-8"?> | |
| <rss version="2.0" | |
| xmlns:content="http://purl.org/rss/1.0/modules/content/" | |
| xmlns:dsq="http://www.disqus.com/" | |
| xmlns:dc="http://purl.org/dc/elements/1.1/" | |
| xmlns:wp="http://wordpress.org/export/1.0/" | |
| > | |
| <channel> | |
| EOF; | |
| echo $out; | |
| $new_title=''; | |
| while($r=mysql_fetch_array($dump)){ | |
| $title=str_replace('&', 'and', $r['title']); | |
| if($new_title!=$title){ | |
| if($new_title!='') | |
| echo "</item>".LB; | |
| $new_title=$title; | |
| $date=date("Y/m/d", strtotime($r['created'])); | |
| $identifier=$date.'/'.$r['slug']; | |
| $post_date=$r['created']; | |
| $link=$web_url.$identifier; | |
| echo "<item>".LB; | |
| echo "<title>$title</title>".LB; | |
| echo "<link>$link</link>".LB; | |
| echo "<content:encoded />".LB; | |
| echo "<dsq:thread_identifier>$identifier</dsq:thread_identifier>".LB; | |
| echo "<wp:post_date_gmt>$post_date</wp:post_date_gmt>".LB; | |
| echo "<wp:comment_status>open</wp:comment_status>".LB; | |
| } | |
| $comment_author=$r['name']; | |
| $comment_id=$r['commentid']; | |
| $comment_email=$r['email']; | |
| $comment_url=$r['url']; | |
| $comment_date=$r['datetime']; | |
| $comment_parent=$r['parentid']; | |
| $comment=str_replace('&', 'and', $r['comment']); | |
| #if($r['parentid']=='0') $comment_parent=''; | |
| echo "<wp:comment>".LB; | |
| echo "<wp:comment_id>$comment_id</wp:comment_id>".LB; | |
| echo "<wp:comment_author>$comment_author</wp:comment_author>".LB; | |
| echo "<wp:comment_author_email>$comment_email</wp:comment_author_email>".LB; | |
| echo "<wp:comment_author_url>$comment_url</wp:comment_author_url>".LB; | |
| echo "<wp:comment_author_IP />"; | |
| echo "<wp:comment_date_gmt>$comment_date</wp:comment_date_gmt>".LB; | |
| echo "<wp:comment_content><![CDATA[$comment]]></wp:comment_content>".LB; | |
| echo "<wp:comment_approved>1</wp:comment_approved>".LB; | |
| echo "<wp:comment_parent>$comment_parent</wp:comment_parent>".LB; | |
| echo "</wp:comment>".LB; | |
| } | |
| echo "</item>".LB; | |
| echo "</channel>".LB; | |
| echo "</rss>".LB; | |
| mysql_close(); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment