Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Basic Disqus integration

  • Loading branch information...
commit b9bec1117b0af28f1304f08e775f4c4b9668b117 1 parent daf3c0f
@Daniel15 authored
View
3  application/classes/controller/template.php
@@ -17,6 +17,7 @@ public function before()
$this->template->sidebar = null;
$this->template->meta = array();
$this->template->extraHead = '';
+ $this->template->extraFoot = '';
$this->template->menu = $this->get_menu();
$request = Request::current();
@@ -84,4 +85,4 @@ protected function get_menu()
->set('items', $menu_content);
}
}
-?>
+?>
View
4 application/config/blog.php
@@ -17,5 +17,7 @@
'summary_length' => 330,
// URL for the FeedBurner feed
'feedburner_url' => 'http://feeds.d15.biz/daniel15',
+
+ 'disqus_shortname' => 'daniel15',
);
-?>
+?>
View
26 js/blog.js
@@ -78,19 +78,19 @@ Page.Blog.View =
*/
init: function()
{
- $('comments').addDelegate('click', 'a', 'reply-to', this.replyToComment);
+ /*$('comments').addDelegate('click', 'a', 'reply-to', this.replyToComment);
$('cancel-reply').addEvent('click', this.cancelReply.bind(this));
this.initPlaceholders();
// Remember comment user details
this.loadCommentDetails();
- $('leave-comment-form').addEvent('submit', this.saveCommentDetails.bind(this));
- },
+ $('leave-comment-form').addEvent('submit', this.saveCommentDetails.bind(this));*/
+ }//,
/**
* Initialise placeholders for comment form, if the browser supports them
*/
- initPlaceholders: function()
+ /*initPlaceholders: function()
{
// Check if the browser supports placeholders
if (!('placeholder' in document.createElement('input')))
@@ -113,13 +113,13 @@ Page.Blog.View =
}
DOM.body.addClass('has-placeholders')
- },
+ },*/
/**
* Called when a reply link is clicked
* @param Event data
*/
- replyToComment: function(e)
+ /*replyToComment: function(e)
{
// Find the footer and stick the comments form in it
var footer = $(e.target).parent('footer');
@@ -128,24 +128,24 @@ Page.Blog.View =
$('cancel-reply').setStyle('display', 'block');
$('parent_comment_id').set('value', comment_id);
Events.stop(e);
- },
+ },*/
/**
* Called when the "cancel reply" link is clicked
*/
- cancelReply: function(e)
+ /*cancelReply: function(e)
{
// Put the comment form back where it belongs
$('content').appendChild($('leave-comment'));
$('cancel-reply').setStyle('display', 'none');
$('parent_comment_id').set('value', '');
Events.stop(e);
- },
+ },*/
/**
* Retrieve the commenter details from local storage
*/
- loadCommentDetails: function()
+ /*loadCommentDetails: function()
{
try
{
@@ -155,12 +155,12 @@ Page.Blog.View =
}
// Ignore any exceptions - This is not important functionality
catch (ex) {}
- },
+ },*/
/**
* Save details about the commenter (name, email, url) into local storage
*/
- saveCommentDetails: function()
+ /*saveCommentDetails: function()
{
try
{
@@ -170,7 +170,7 @@ Page.Blog.View =
}
// Ignore any exceptions - This is not important functionality
catch (ex) {}
- }
+ }*/
};
/**
View
8 modules/blog/classes/controller/blog.php
@@ -22,6 +22,8 @@ public function before()
$this->template->extraHead .= '
<link rel="alternate" type="application/rss+xml" title="' . $this->config->name . ' - RSS Feed" href="' . $this->config->feedburner_url . '" />
<link rel="index" title="' . $this->config->name . '" href="' . Url::site('blog', true) . '" />';
+
+ $this->template->extraFoot .= View::factory('blog/includes/disqus_count');
}
public function after()
@@ -178,14 +180,14 @@ public function action_view()
}
// If the page was POSTed, it's a comment
- if ($_POST)
+ /*if ($_POST)
{
$this->comment($post);
- }
+ }*/
$page = View::factory('blog/post')
->bind('post', $post)
- ->set('comments', $post->comments())
+ //->set('comments', $post->comments())
->set('categories', $post->categories->order_by('title')->find_all())
->set('tags', $post->tags->order_by('title')->find_all())
->set('share_links', Social::all_share_urls($post));
View
11 modules/blog/views/blog/includes/disqus_count.php
@@ -0,0 +1,11 @@
+<script type="text/javascript">
+var disqus_shortname = <?php echo json_encode($config->disqus_shortname); ?>;
+
+(function () {
+ var s = document.createElement('script'); s.async = true;
+ s.type = 'text/javascript';
+ s.src = 'http://' + disqus_shortname + '.disqus.com/count.js';
+ (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
+}());
+</script>
+
View
2  modules/blog/views/blog/post.php
@@ -8,5 +8,5 @@
echo View::factory('blog/post/comments')
->set('post', $post)
- ->set('comments', $comments);
+ //->set('comments', $comments);
?>
View
28 modules/blog/views/blog/post/comments.php
@@ -1,16 +1,26 @@
<?php defined('SYSPATH') or die('No direct script access.'); ?>
<div id="comments">
-<?php if ($post->comment_count == 0): ?>
- <h3>Comments</h3>
- <p>This post currently has no comments. You can be the first!</p>
-<?php else: ?>
- <h3><?php echo $post->comment_count, ' ', Inflector::plural('comment', $post->comment_count); ?></h3>
- <?php echo View::factory('blog/comments')->set('comments', $comments)->set('post', $post); ?>
-<?php endif; ?>
+ <div id="disqus_thread"></div>
</div>
-<div id="leave-comment">
+<script type="text/javascript">
+ var disqus_shortname = <?php echo json_encode($config->disqus_shortname); ?>,
+ disqus_title = <?php echo json_encode($post->title); ?>,
+ disqus_identifier = <?php echo $post->id; ?>,
+ disqus_url = <?php echo json_encode($post->url(true)); ?>;
+
+ (function() {
+ var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
+ dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
+ (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
+ })();
+</script>
+<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
+<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
+
+
+<!--<div id="leave-comment">
<h3>Leave a comment</h3>
<p id="cancel-reply"><a href="<?php echo $post->url(); ?>">Cancel reply</a></p>
<form id="leave-comment-form" method="post" action="<?php echo $post->url(); ?>">
@@ -49,4 +59,4 @@
<input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" />
</p>
</form>
-</div>
+</div>-->
View
2  modules/blog/views/blog/post/header.php
@@ -6,7 +6,7 @@
<ul class="postmetadata">
<li class="date"><time datetime="', date(DATE_W3C, $post->date), '" itemprop="datePublished">', date($config->date_format, $post->date), '</time></li>
<li class="category"><a href="', $post->maincategory->url(), '" itemprop="keywords">', $post->maincategory->title, '</a></li>
- <li class="comments"><a href="', $post->url(), '#comments">', Inflector::plural($post->comment_count . ' comment', $post->comment_count), '</a></li>
+ <li class="comments"><a href="', $post->url(), '#disqus_thread" data-disqus-identifier="', $post->id, '">Comments</a></li>
<li class="permalink">', $post->short_url(), '</li>
</ul>
</header>
View
48 tools/comments-to-disqus.php
@@ -0,0 +1,48 @@
+<?php
+$dbname = 'daniel15_new';
+$username = 'root';
+$password = 'password';
+$db = new PDO('mysql:host=localhost;dbname=' . $dbname, $username, $password);
+$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+$db->query('SET NAMES "UTF8"');
+
+// Start with a fresh WXR export XML
+$output = simplexml_load_string('<?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/" />');
+
+// Start the initial XML output
+$channel = $output->addChild('channel');
+
+// Get all the posts
+$posts_query = $db->query('SELECT * FROM blog_posts');
+$comments_query = $db->prepare('SELECT * FROM blog_comments WHERE post_id = :post_id AND status <> "spam"');
+
+while ($post = $posts_query->fetchObject())
+{
+ $item = $channel->addChild('item');
+ $item->addChild('title', $post->title);
+ $item->addChild('link', 'http://dan.cx/blog/' . date('Y/m', $post->date) . '/' . $post->slug);
+ $item->addChild('encoded', str_replace('&', '&amp;', $post->content), 'http://purl.org/rss/1.0/modules/content/');
+ $item->addChild('thread_identifier', $post->id, 'http://www.disqus.com/');
+ $item->addChild('post_date_gmt', gmdate('Y-m-d H:i:s', $post->date), 'http://wordpress.org/export/1.0/');
+ $item->addChild('comment_status', 'open', 'http://wordpress.org/export/1.0/');
+
+ $comments_query->execute([':post_id' => $post->id]);
+ while ($comment_row = $comments_query->fetchObject())
+ {
+ $comment = $item->addChild('comment', null, 'http://wordpress.org/export/1.0/');
+ $comment->addChild('comment_id', $comment_row->id, 'http://wordpress.org/export/1.0/');
+ $comment->addChild('comment_author', $comment_row->author, 'http://wordpress.org/export/1.0/');
+ $comment->addChild('comment_author_email', $comment_row->email, 'http://wordpress.org/export/1.0/');
+ $comment->addChild('comment_author_url', str_replace('&', '&amp;', $comment_row->url), 'http://wordpress.org/export/1.0/');
+ $comment->addChild('comment_author_IP', $comment_row->ip, 'http://wordpress.org/export/1.0/');
+ $comment->addChild('comment_date_gmt', gmdate('Y-m-d H:i:s', $comment_row->date), 'http://wordpress.org/export/1.0/');
+ $comment->addChild('comment_content', str_replace('&', '&amp;', $comment_row->content), 'http://wordpress.org/export/1.0/');
+ $comment->addChild('comment_approved', $comment_row->status === 'visible' ? 1 : 0, 'http://wordpress.org/export/1.0/');
+ $comment->addChild('comment_parent', $comment_row->parent_comment_id, 'http://wordpress.org/export/1.0/');
+ }
+}
+
+header('Content-Type: text/xml; charset=UTF-8');
+echo $output->asXML();
+
+?>
Please sign in to comment.
Something went wrong with that request. Please try again.