Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

JoomlaTune Support Forum    JComments component    Integration with third-party extensions    K2 JComments    Topic: K2 v.2.1 full integration with JComments
Pages: [1] 2   Go Down
  Print  
Author Topic: K2 v.2.1 full integration with JComments  (Read 27362 times)
0 Members and 1 Guest are viewing this topic.
Sulpher
Newbie
*

Karma: 3
Offline Offline

Gender: Male
Posts: 21



WWW Email
« on: May 21, 2009, 00:38:30 »

Do you want to enhance beautiful CCK extension called K2 and replace its standart comments functional on JComments?

Here is the instruction for K2 v2.1 (build 20090909):

1. Open components/com_k2/templates/item.php and remove next code from line 486 up to 560:

Code: (php)
<?php if(
 
$this->item->params->get('itemComments') && !JRequest::getInt('print') && ($this->item->params->get('comments') == '1' || ($this->item->params->get('comments') == '2'))):?>

  <!-- Item comments -->
  <a name="itemCommentsAnchor" id="itemCommentsAnchor"></a>
 
  <div class="itemComments">
 
  <?php if($this->item->params->get('commentsFormPosition')=='above' && $this->item->params->get('itemComments') && !JRequest::getInt('print') && ($this->item->params->get('comments') == '1' || ($this->item->params->get('comments') == '2' && K2HelperPermissions::canAddComment($this->item->catid)))): ?>
  <!-- Item comments form -->
  <div class="itemCommentsForm">
  <?php echo $this->loadTemplate('comments_form'); ?>
  </div>
  <?php endif; ?>

  <?php if($this->item->numOfComments>&& $this->item->params->get('itemComments') && !JRequest::getInt('print') && ($this->item->params->get('comments') == '1' || ($this->item->params->get('comments') == '2'))): ?>
  <!-- Item user comments -->
  <h3 class="itemCommentsCounter">
  <span><?php echo $this->item->numOfComments?></span> <?php echo ($this->item->numOfComments>1) ? JText::_('comments') : JText::_('comment'); ?>
  </h3>
 
  <ul class="itemCommentsList">
    <?php foreach ($this->item->comments as $key=>$comment): ?>
    <li class="<?php echo ($key%2) ? "odd" "even"?>">
   
    <span class="commentLink">
    <a href="<?php echo $this->item->link?>#comment<?php echo $comment->id?>" name="comment<?php echo $comment->id?>" id="comment<?php echo $comment->id?>">
    <?php echo JText::_('Comment Link'); ?>
    </a>
    </span>
   
<?php if($comment->userImage):?>
<img src="<?php echo $comment->userImage?>" alt="<?php echo $comment->userName?>" width="<?php echo $this->item->params->get('commenterImgWidth'); ?>" />
<?php endif; ?>

<span class="commentDate">
    <?php echo JHTML::_('date'$comment->commentDateJText::_('DATE_FORMAT_LC2')); ?>
    </span>
   
    <span class="commentAuthorName">
    <?php echo JText::_("posted by"); ?>
    <?php if(!empty($comment->userLink)): ?>
    <a href="<?php echo $comment->userLink?>" title="<?php echo $comment->userName?>">
    <?php echo $comment->userName?>
    </a>
    <?php else: ?>
    <?php echo $comment->userName?>
    <?php endif; ?>
    </span>
   
    <p><?php echo $comment->commentText?></p>
   
    <span class="commentAuthorEmail">
    <?php echo JHTML::_('Email.cloak'$comment->commentEmail0); ?>
    </span>
   
<br class="clr" />
    </li>
    <?php endforeach; ?>
  </ul>
 
  <div class="itemCommentsPagination">
  <?php echo $this->pagination->getPagesLinks(); ?>
  <div class="clr"></div>
  </div>
<?php endif; ?>

<?php if($this->item->params->get('commentsFormPosition')=='below' && $this->item->params->get('itemComments') && !JRequest::getInt('print') && ($this->item->params->get('comments') == '1' || ($this->item->params->get('comments') == '2' && K2HelperPermissions::canAddComment($this->item->catid)))): ?>
  <!-- Item comments form -->
  <div class="itemCommentsForm">
  <?php echo $this->loadTemplate('comments_form'); ?>
  </div>
  <?php endif; ?>
 
  </div>
  <?php endif; ?>

And add next code instead of previous one:

Code: (php)
<?php
  defined
'_JEXEC' ) or die( 'Restricted access' );
 
  
$comments JPATH_BASE DS 'components' DS 'com_jcomments' DS 'jcomments.php';
 
  if (
file_exists($comments)) {
    require_once(
$comments);
?>

<a name="itemCommentsAnchor" id="itemCommentsAnchor"></a>
<?php
    
echo JComments::showComments($this->item->id'com_k2'$this->item->title);
  }
?>

2. Open components/com_k2/models/item.php (line 777 up to 785) file and replace:

Code: (php)
function countItemComments($itemID){

$db = & JFactory::getDBO ();
$query="SELECT COUNT(*) FROM #__k2_comments WHERE published=1 AND itemID={$itemID}";
$db->setQuery($query);
$result = $db->loadResult();
return $result;

}

at:

Code: (php)
function countItemComments($itemID){
$comments = JPATH_BASE . DS . 'components' . DS . 'com_jcomments' . DS . 'jcomments.php';
if (file_exists($comments)) {
require_once($comments);
return JComments::getCommentsCount($itemID, 'com_k2');
}
return 0;
}

3. If you use old version of JComments (2.0), then download enclosed archive, unpack it and extract com_k2.plugin.php file to /components/com_jcomments/plugins/ directory. If you're using JComments 2.1 just skip this step.

Thanks to smart and Devil for this solution.

* com_k2.plugin.zip (0.92 KB - downloaded 1023 times.)
« Last Edit: December 14, 2009, 02:59:24 by Sulpher » Logged

mobilist41
Newbie
*

Karma: 0
Offline Offline

Posts: 14


« Reply #1 on: September 01, 2009, 07:55:43 »

There isn't "default_form.php" file in "components/com_k2/views/item/tpl/" path in K2 latest version. Also, no this code   
Code:
$row->numOfComments=$itemModel->getTotalComments($row->item_id);
in second file. Plesade update the instruction. Thanks.
Logged
trumpet
Newbie
*

Karma: 0
Offline Offline

Posts: 3


Email
« Reply #2 on: September 25, 2009, 06:04:29 »

Is there a way to fix this with K2 2.1 ?

I have jcomments appearing at the bottom of my K2 items, but I do not have the comments counter at the top of the items.

Any help, much appreciated!
Logged
Sulpher
Newbie
*

Karma: 3
Offline Offline

Gender: Male
Posts: 21



WWW Email
« Reply #3 on: September 25, 2009, 12:41:55 »

Is there a way to fix this with K2 2.1 ?

I have jcomments appearing at the bottom of my K2 items, but I do not have the comments counter at the top of the items.

Any help, much appreciated!
Sure, today I'll post it. Wink
Logged

trumpet
Newbie
*

Karma: 0
Offline Offline

Posts: 3


Email
« Reply #4 on: September 25, 2009, 14:49:46 »

Sure, today I'll post it. Wink

Great thanks Sulpher!
Logged
Sulpher
Newbie
*

Karma: 3
Offline Offline

Gender: Male
Posts: 21



WWW Email
« Reply #5 on: September 26, 2009, 02:17:17 »

trumpet, see topic first message - it has been updated and now there is step-by-step instruction how to implement JComments into K2 v.2.1. If any questions will follow, just feel free to ask. Good luck!
Logged

trumpet
Newbie
*

Karma: 0
Offline Offline

Posts: 3


Email
« Reply #6 on: September 27, 2009, 14:28:19 »

Thanks Sulpher, I seem to have it working now. The only problem is the itemCommentsAnchor does not seem to link properly. Any idea what the problem might be?
Logged
Sulpher
Newbie
*

Karma: 3
Offline Offline

Gender: Male
Posts: 21



WWW Email
« Reply #7 on: October 07, 2009, 19:14:41 »

trumpet, the first message just been updated by smart according your request. Please try once again. Does everything okay now with comments amount?
Logged

jkena
Newbie
*

Karma: 0
Offline Offline

Posts: 2


Email
« Reply #8 on: November 06, 2009, 03:34:03 »

This does not work for me, all is well until i edit the second file then after its edited and uploaded my site shows nothing but actual code in that second file, no pages just all code. Anyone else seen this or have a new fix. I did it about ten times to make sure I wasn't missing anything and every time it was the same.  Thanks in advance

 Huh
Logged
jkena
Newbie
*

Karma: 0
Offline Offline

Posts: 2


Email
« Reply #9 on: November 06, 2009, 22:34:32 »

No one , a lil help?
Logged
Terp
Newbie
*

Karma: 0
Offline Offline

Posts: 7


« Reply #10 on: November 24, 2009, 01:07:47 »

I discovered a js error when:

1.) user is logged in and
2.) trying to display the anchor 'comment' text in K2.

Guests and members can comment, however, and the anchor text does work fine! ...strange one. Doesn't seem to like the $('userName'), but still looking into this one. Smiley

PS...jComment absolutely rocks. I am still styling it up a bit and working out some kinks, but it has completely supplanted JomComments and I love it. Well-done!  I'll leave 5*s on the JED and will spread the word. Wink


Okay, the error only fires when you have the k2 comment dropdown set to 'enabled for everyone'...if set to 'enable for registered users,' it doesn't fire (but doesn't show guests the comment anchor, either). Wink


$("userName") is null error:

Code:
$('userName').setProperty('value','Terp');
$('userName').setProperty('disabled','disabled');
« Last Edit: November 24, 2009, 01:14:53 by Terp » Logged
Terp
Newbie
*

Karma: 0
Offline Offline

Posts: 7


« Reply #11 on: November 24, 2009, 01:29:50 »

Follow-up:

Tried to change the author display in jComment backend ( settings->layout->author name) from username (since firing js error) to "full name," but still fires so the same error, so that's not it. Wink
Logged
smart
Administrator
Hero Member
*****

Karma: 146
Offline Offline

Gender: Male
Posts: 2579



WWW
« Reply #12 on: November 24, 2009, 01:32:10 »

JComments' form doesn't contain element with id='userName', it has only 'comments-form-name'.
Logged

If you use JComments, please post a rating and a review at the Joomla! Extensions Directory
Terp
Newbie
*

Karma: 0
Offline Offline

Posts: 7


« Reply #13 on: November 24, 2009, 01:54:14 »

JComments' form doesn't contain element with id='userName', it has only 'comments-form-name'.

Thanks, sir. Looking at the whole block that is causing it, it does now seem k2 related.

If I remove the 'anchor text' for the comments, it doesn't fire the error. BUT, since the hack you posted above works flawlessly otherwise, I kind of wanted to leave the anchor text for comment count and "Be the first to comment!" showing...might have to ignore the js error, since everything is working fine otherwise. Smiley

Here's the section FF doesn't like and the userName does seem to be coming from k2:

Code:
<script type="text/javascript">

window.addEvent('domready', function() {

SqueezeBox.initialize({});

$$('a.modal').each(function(el) {
el.addEvent('click', function(e) {
new Event(e).stop();
SqueezeBox.fromElement(el);
});
});
});
var K2RatingURL = 'http://localhost/blt/';
window.addEvent('domready', function(){
$('userName').setProperty('value','Terp');
$('userName').setProperty('disabled','disabled');
$('commentEmail').setProperty('value','myemail@home.com');
$('commentEmail').setProperty('disabled','disabled');

})
  </script>

I saw the 'commentEmail' right under the problem lines, so started looking at jComment first...will keep working on it. Thanks for the reply.

Again, if I were to change the comment dropdown in k2 to enable only for registered, it doesn't fire the js and all works perfectly. But then guests won't see the anchor text, so needed to leave it set to 'enabled for everyone'. I'll fireup dreamweaver and look at all the k2 files and post a solution if anyone else is having problems...strange I am the only one, so perhaps I'll start again.
Logged
smart
Administrator
Hero Member
*****

Karma: 146
Offline Offline

Gender: Male
Posts: 2579



WWW
« Reply #14 on: November 24, 2009, 02:11:58 »

I think that you can remove code:

Code:
window.addEvent('domready', function(){
$('userName').setProperty('value','Terp');
$('userName').setProperty('disabled','disabled');
$('commentEmail').setProperty('value','myemail@home.com');
$('commentEmail').setProperty('disabled','disabled');

})
Because it isn't needed then you use JComments...
Logged

If you use JComments, please post a rating and a review at the Joomla! Extensions Directory
Pages: [1] 2   Go Up
  Print  
JoomlaTune Support Forum    JComments component    Integration with third-party extensions    K2 JComments    Topic: K2 v.2.1 full integration with JComments
 
Jump to: