Store
Community Documentation

v3 Knowledgebase

How to integrate Disqus.com comment system

**This tutorial requires a source edit if you are not using a custom template. Do so at your own risk as it will void support, be overwritten on upgrades, can cause issues with other modules that use the same file, can cause instability on the site and can cause the site to be less secure. It is recommended instead to use a custom template and do the template override method mentioned.

Follow this tutorial for add disqus.com on your site.

If you don't know disqus, check about page:
http://disqus.com/about/

The first step it's register your new account, here:
https://disqus.com/admin/signup/?utm_source=New-Site

When he ask which integration you want, then select Universal Code.

After registration, you will receive an URL similar like:
macagoraga.disqus.com and you can login on a wide admin dashboard for your comments. You can manage many settings, appearance, comments, users, language, ...

Download from here the addon which will quickly install disqus:
http://www.phpfox.com/addons/view/disqus-comment-system/

Installation:

1) Unzip folder
2) Upload to your server
3) Admincp > Extension > Import product and click install
4) Admincp > Setting > Disqus and add your disqus shortname
5) Move file from module/disqus/template/default/block/comment.html.php to module/feed/template/default/block/comment.html.php or if you are using custom theme you can move under module/feed/template/MY_THEME_NAME/block/comment.html.php
in this case replace MY_THEME_NAME with your theme name

How it work?

1) First of all we need a block with disqus code. You can find that block under module/disqus/template/default/block/display.html.php with this content:

PHP:
<div id="disqus_thread"></div>
<
script type="text/javascript">
(function() {
l}
    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);
{
r})();
</script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">Disqus.</a></noscript> 


2) We need a javascript file for reload disqus via ajax, this it's required for theater mode, we need change disqus thread via ajax. You can find the code into module/disqus/static/jscript/init.js, this are the code:

PHP:
$Behavior.macMainDisqusBehavior = function()
{
    $(
'a.thickbox.photo_holder_image').on('click', function(){
    
        
disqus_url = $(this).attr('href');
        
disqus_identifier = $(this).attr('rel');
        
        
setTimeout(macReLoadDisqus800); 
    });
};
function 
macReLoadDisqus() 
{
    
DISQUS.reset({
      
reloadtrue,
      
config: function () {  
        
this.page.identifier disqus_identifier;  
        
this.page.url disqus_url;
      }
    });


3) and in the last we need a plugin, which it's used for setup disqus. You can find that plugin under module/disqus/include/plugin/template_getheader.php, this are the content:

PHP:
if(Phpfox::isModule('disqus')) { // load only if module is enabled

    // disallowed modules - you can add more here
    
$disallowedModules = array('/''''about');
    
$requestedPostId Phpfox::getLib('request')->get('req2');
    
    
// requested module
    
$requestedModule Phpfox::getLib('request')->get('req1');
    
    
// site url
    
$sMacSiteUrl "http://".Phpfox::getParam('core.host').Phpfox::getParam('core.folder');
    
    
// check if guest and if module is allowed
    
if(!Phpfox::getUserId() && !in_array($requestedModule$disallowedModules)) {
    
        
// configuration info: http://help.disqus.com/customer/portal/articles/472098-javascript-configuration-variables
        // var disqus_developer = 1; 
        
$this->setHeader("head", array(
        
"<script>
        var disqus_shortname = '"
.Phpfox::getParam('disqus.disqus_shortname')."';
        var disqus_url = '"
.$sMacSiteUrl.Phpfox::getLib('url')->getUrl()."';
        var disqus_identifier = '"
.$requestedModule."_".$requestedPostId."';
        var disqus_category_id = '"
.$requestedModule."'; 
        </script>"
));
        
// end configuration
        
        // init disqus script
        
$this->setHeader(array(
            
'init.js' => 'module_disqus'
        
));
        
    }


4) In the last we need change view file of comment.
This file are module/feed/template/default/block/comment.html.php which can be also replaced by module/disus/template/default/block/comment.html.php
If you are running phpfox 3.7.4 then you can use that file
but if you are using another version, be sure that you are using correct comment file

The code which should be added it's:

PHP:
{if 
    
Phpfox::isModule('disqus') &&
    !
Phpfox::getUserId() && 
    isset(
$sFeedType) &&
    
$sFeedType == 'view'

{
template file='disqus.block.display'}
{else}

HERE GO all comment.html.php default file

{/if} 



if want disable disqus for some page, you can add more element on array $disallowedModules = array('/', '', 'about');

Example if you don't want load disqus for blog, you can do this:

$disallowedModules = array('/', '', 'about', 'blog');

More info on disqus:

http://help.disqus.com/

http://help.disqus.com/customer/portal/articles/472098-javascript-configuration-variables