Skip to content

Instantly share code, notes, and snippets.

@vijaykhollam
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vijaykhollam/456168f52b8fe985adf0 to your computer and use it in GitHub Desktop.
Save vijaykhollam/456168f52b8fe985adf0 to your computer and use it in GitHub Desktop.
Integrate disqus comments with jomsocial
<?php
// Add thid method to any controller, say to com_community/disqusimport.php
// And run it as http://example.com/index.php?option=com_community&controller=disqusimport&task=export_comments
public function export_jom_video()
{
header('Content-disposition: attachment; filename="export.xml"');
header('Content-type: "text/xml"; charset="utf8"');
echo '<?xml version="1.0" encoding="' . 'UTF-8' ."\" ?>\n";
echo'<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/"
>'."\n";
echo'<channel>'."\n";
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('v.*');
$query->from('#__community_videos AS v');
$db->setQuery($query);
$vids = $db->loadObjectList();
foreach($vids as $vid)
{
if(!isset($vid->title) || $vid->title !== ''){
$sef_title = JFilterOutput::stringURLSafe($vid->title);
}
$sef_name = JFilterOutput::stringURLSafe(JFactory::getUser($vid->creator)->name);
$query = $db->getQuery(true);
$query->select('cw.*');
$query->from('#__community_wall AS cw');
$query->where('cw.type="videos" AND contentid="'.$vid->id.'"');
$db->setQuery($query);
$comments = $db->loadObjectList();
if(count($comments))
{
echo '<item>'."\n";
echo '<!-- title of article -->'."\n";
if(!isset($vid->title) || $vid->title !== '')
echo '<title>'.$vid->title.'</title>'."\n";
else echo '<title>'.'No Title'.'</title>'."\n";
$i=0;
foreach($comments as $comment)
{
if($i==0)
{
echo '<!-- absolute URI to article -->'."\n";
//Here match your URL format where you have old comments
$link=JURI::base().'index.php?option=com_community&view=videos&task=video&userid='.$vid->creator.'&videoid='.$comment->contentid;
echo '<link>'.$link.'</link>'."\n";
echo '<content:encoded><![CDATA['.$vid->description.']]></content:encoded>'."\n";
echo '<dsq:thread_identifier>video'.$vid->id.'</dsq:thread_identifier>'."\n";
echo '<wp:post_date_gmt>'.$vid->created.'</wp:post_date_gmt>'."\n";
echo '<wp:comment_status>open</wp:comment_status>'."\n";
}
if( strlen($comment->comment) >= 2){
echo '<wp:comment>'."\n";
echo '<wp:comment_id>'.$comment->id.'</wp:comment_id>'."\n";
echo '<wp:comment_author>'.JFactory::getUser($comment->post_by)->name.'</wp:comment_author>'."\n";
echo '<wp:comment_author_email>'.JFactory::getUser($comment->post_by)->email.'</wp:comment_author_email>'."\n";
echo '<wp:comment_author_url>'.JURI::base().'</wp:comment_author_url>'."\n";
echo '<wp:comment_author_IP>'.$comment->ip.'</wp:comment_author_IP>'."\n";
echo '<wp:comment_date_gmt>'.$comment->date.'</wp:comment_date_gmt>'."\n";
// here you should have non empty comments or character count greator equal 3
echo '<wp:comment_content><![CDATA['.$comment->comment.']]></wp:comment_content>'."\n";
echo '<wp:comment_approved>1</wp:comment_approved>'."\n";
echo '<wp:comment_parent>0</wp:comment_parent>'."\n";
echo '</wp:comment>'."\n";
}
$i++;
}//end foreach for comments list
echo'</item>'."\n";
}//end if comments
}
echo'</channel>'."\n";
echo '</rss>';
jexit();
}
<div id="disqus_thread"></div>
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'example'; // required: replace example with your forum shortname
var disqus_identifier = 'video.<?php echo $video->id; ?>';
var disqus_category_id = '3227814'; // ID of a pre-created DISQUS category
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + 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>
<?php
/**
* @copyright (C) 2013 iJoomla, Inc. - All rights reserved.
* @license GNU General Public License, version 2 (http://www.gnu.org/licenses/gpl-2.0.html)
* @author iJoomla.com <webmaster@ijoomla.com>
* @url https://www.jomsocial.com/license-agreement
* The PHP code portions are distributed under the GPL license. If not otherwise stated, all images, manuals, cascading style sheets, and included JavaScript *are NOT GPL, and are released under the IJOOMLA Proprietary Use License v1.0
* More info at https://www.jomsocial.com/license-agreement
*/
defined('_JEXEC') or die();
?>
<script type="text/javascript" language="javascript">
function wallRemove( id )
{
if(confirm('<?php echo JText::_('COM_COMMUNITY_WALL_CONFIRM_REMOVE'); ?>'))
{
joms.jQuery('#wall_'+id).fadeOut('normal').remove();
if(typeof getCacheId == 'function') {
cache_id = getCacheId();
}else{
cache_id = "";
}
jax.call('community','<?php echo $ajaxRemoveFunc; ?>', id, cache_id );
}
}
joms.jQuery(document).ready(function(){
//joms.utils.textAreaWidth('#wall-message');
joms.utils.autogrow('#wall-message');
});
</script>
<!--
<div class="cComment-Avatar cFloat-L">
<a href="<?php echo CRoute::_('index.php?option=com_community&view=profile&userid=' . $my->id );?>"><img class="avatar" alt="" src="<?php echo $my->getThumbAvatar()?>"></a>
</div>
<div class="cComment-Body">
<div class="cComment-Input">
<textarea id="wall-message" name="message" class="textarea input-block-level"></textarea>
</div>
<div class="cComment-Actions">
<button id="wall-submit" class="btn btn-primary" onclick="joms.walls.add('<?php //echo $uniqueId; ?>', '<?php //echo $ajaxAddFunction;?>');return false;" name="save">
<?php //echo JText::_('COM_COMMUNITY_WALL_ADD_COMMENT');?>
</button>
<div style="position:absolute; left:0; top:0; display:none;" id="wall-message-counter"></div>
<a name="app-walls" href="javascript:void(0);"></a>
</div>
</div>-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment