Skip to content

Instantly share code, notes, and snippets.

@artpolikarpov
Forked from sapegin/cmnts.php
Created October 1, 2013 19:20
Show Gist options
  • Save artpolikarpov/6783667 to your computer and use it in GitHub Desktop.
Save artpolikarpov/6783667 to your computer and use it in GitHub Desktop.
<?php
// Aegea to Disqus comments converter
// http://help.disqus.com/customer/portal/articles/472150
$url_prefix = 'http://nano.sapegin.ru/all/';
$note_id = intval($_GET['id']);
if (empty($note_id)) exit('Empty note ID.');
$config = unserialize(file_get_contents('user/settings.psa'));
mysql_connect($config['db']['server'], $config['db']['user_name'], $config['db']['passw']);
mysql_select_db($config['db']['name']);
mysql_query("set character_set_client='utf8'");
mysql_query("set character_set_results='utf8'");
mysql_query("set collation_connection='utf8_general_ci'");
$result = mysql_query("SELECT * from e2BlogNotes WHERE ID=$note_id");
$note = mysql_fetch_assoc($result);
echo '<?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>
<item>
<title><?php echo $note['Title'] ?></title>
<link><?php echo $url_prefix . $note['OriginalAlias'] . '/' ?></link>
<?php // value used within disqus_identifier; usually internal identifier of article ?>
<dsq:thread_identifier><?php echo $note['OriginalAlias'] ?></dsq:thread_identifier>
<?php // creation date of thread (article), in GMT. Must be YYYY-MM-DD HH:MM:SS 24-hour format. ?>
<wp:post_date_gmt><?php echo date('Y-m-d H:i:s', $note['Stamp']) ?></wp:post_date_gmt>
<wp:comment_status>open</wp:comment_status>
<?php
$result = mysql_query("SELECT * from e2BlogComments WHERE isVisible=1 AND NoteID=$note_id ORDER BY Stamp DESC");
while ($comment = mysql_fetch_assoc($result)) {
?>
<wp:comment>
<wp:comment_id><?php echo $comment['ID'] ?></wp:comment_id>
<wp:comment_author><?php echo $comment['AuthorName'] ?></wp:comment_author>
<wp:comment_author_email><?php echo $comment['AuthorEmail'] ?></wp:comment_author_email>
<wp:comment_author_IP><?php echo $comment['IP'] ?></wp:comment_author_IP>
<wp:comment_date_gmt><?php echo date('Y-m-d H:i:s', $comment['Stamp']) ?></wp:comment_date_gmt>
<?php // comment body; use cdata; html allowed (though will be formatted to DISQUS specs) ?>
<wp:comment_content><![CDATA[<?php echo $comment['Text'] ?>]]></wp:comment_content>
<wp:comment_approved>1</wp:comment_approved>
<wp:comment_parent>0</wp:comment_parent>
</wp:comment>
<?php
}
?>
</item>
</channel>
</rss>
<?php
// Aegea to DocPad posts converter
$config = unserialize(file_get_contents('user/settings.psa'));
mysql_connect($config['db']['server'], $config['db']['user_name'], $config['db']['passw']);
mysql_select_db($config['db']['name']);
mysql_query("set character_set_client='utf8'");
mysql_query("set character_set_results='utf8'");
mysql_query("set collation_connection='utf8_general_ci'");
$tags_names = array(
'',
'mac', // ID=1
'tools',
'html', // ?
'reading',
'ui',
'wordpress',
'javascript',
'python',
'thoughts',
'windows',
'django',
'stylus'
);
$result = mysql_query("SELECT * from e2BlogNotes");
while ($post = mysql_fetch_assoc($result)) {
$result_tags = mysql_query("SELECT * from e2BlogNotesKeywords WHERE NoteId={$post[ID]}");
$tags = array();
while ($tag = mysql_fetch_assoc($result_tags)) {
$tags[] = $tags_names[$tag['KeywordID']];
}
$md = $post['Text'];
$md = preg_replace('/\[\[([^ ]+) ([^\]]+)\]\]/', '[$2]($1)', $md); // Links
$md = preg_replace('/<a href="([^"]+)"[^>]*>([^<]+)<\/a>/', '[$2]($1)', $md); // Links
$md = preg_replace('/\/\/([^\/]+)\/\//', '*$1*', $md); // Italic
$md = preg_replace('/<pre><code class="language-(\w+)">/', "```$1\n", $md); // Code
$md = preg_replace('/<\/code><\/pre>/', "\n```", $md); // Code
$md = str_replace(array('<p>', '</p>'), array('', ''), $md); // Clean up
$md = str_replace(array('&amp;', '&lt;', '&gt;', '&quot;'), array('&', '<', '>', '"'), $md); // Unescape
$md = "---
layout: post
title: '{$post[Title]}'
date: " . date('M j, Y', $post['Stamp']) . "
disqus_identifier: {$post[OriginalAlias]}
tags:
- " . implode("\n - ", $tags) . "
---
$md
";
file_put_contents("user/markdown/{$post[OriginalAlias]}.html.md", $md);
}
echo "Done.";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment