Ajax Profile Comments

Started by The Craw, March 06, 2012, 02:22:44 PM

Previous topic - Next topic

Matthew K.

* Labradoodle-360 likes live627's idea.

The Craw

Quote from: live627 on April 19, 2012, 01:06:33 AM
Quote from: The Craw on April 19, 2012, 12:00:02 AM
Just so everyone knows, I'm aware that when you first install the mod and go to view a profile, the comments section doesn't look... good. For some reason after installing the mod, the css file doesn't like to load right away. The solution is to leave the profile page and return to it. Or if that doens't work, try closing the browser and opening the profile page again. The problem should not return after that.
Why not put the extra styles in a separate file? That''ll beat the cache for sure :)

Might as well. Thanks for the suggestion. :D

live627

You're welcome. Always good to help out a fellow coder.

trabacho

#23
I've made an addon for this to notificate my users.

So I share it with you, to the Mod Creater I would be happy if you take it in.

Here the changes:

SQL:


ALTER TABLE `prefix_profile_comments` ADD `date` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ;



CREATE TABLE prefix_profile_visits (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`v_id` INT( 11 ) NOT NULL ,
`p_id` INT( 11 ) NOT NULL ,
`lastvisit` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE = InnoDB


Edits:

Profile-View.php:

INSERT BEFORE:


$q =$smcFunc['db_query']('', '
SELECT comment_id, comment_poster_id, comment_poster, comment_title, comment_body
FROM {db_prefix}profile_comments
WHERE comment_profile= {int:profile_id}
ORDER BY comment_id DESC
LIMIT 20',
array ('profile_id' => $memID)
);


-------------------


$q =$smcFunc['db_query']('', '
SELECT p_id
FROM {db_prefix}profile_visits
WHERE v_id= {int:visitor_id} AND p_id={int:profile_id}',
array ('visitor_id' => $user_info['id'], 'profile_id' => $memID)
);

if( $smcFunc['db_num_rows']($q) != 0 )
$smcFunc['db_query']('', '
UPDATE {db_prefix}profile_visits
SET lastvisit = CURRENT_TIMESTAMP
WHERE p_id= {int:profile_id} AND v_id= {int:visitor_id}',
array ('profile_id' => $memID, 'visitor_id' => $user_info['id'])
);
else
$smcFunc['db_insert']('insert',
            '{db_prefix}profile_visits',
            array(
                'v_id' => 'int', 'p_id' => 'int',
            ),
            array(
                $user_info['id'], $memID,
            ),
            array()
        );


Subs.php:

Replace:


function setupMenuContext()
{
global $context, $modSettings, $user_info, $txt, $scripturl;


---------------------


function setupMenuContext()
{
global $smcFunc, $context, $modSettings, $user_info, $txt, $scripturl;


:::::::::::::::::::::::::::::::

Replace:


if (!$user_info['is_guest'] && ($context['user']['unread_messages'] > 0) && isset($context['menu_buttons']['pm']))
{
$context['menu_buttons']['pm']['alttitle'] = $context['menu_buttons']['pm']['title'] . ' [' . $context['user']['unread_messages'] . ']';
$context['menu_buttons']['pm']['title'] .= ' [<strong>' . $context['user']['unread_messages'] . '</strong>]';
}


--------------------


$query =$smcFunc['db_query']('', '
SELECT lastvisit
FROM {db_prefix}profile_visits WHERE
p_id={int:visitor_id} AND v_id={int:visitor_id}',
array ('visitor_id' => $user_info['id'])
);

$lastvisited = $smcFunc['db_fetch_assoc']($query);

if($lastvisited != NULL)
$query =$smcFunc['db_query']('', '
SELECT *
FROM {db_prefix}profile_comments WHERE
comment_poster_id!={int:visitor_id} AND comment_profile={int:visitor_id} AND date > "'.$lastvisited['lastvisit'].'"',
array ('visitor_id' => $user_info['id'])
);
else
$query =$smcFunc['db_query']('', '
SELECT *
FROM {db_prefix}profile_comments WHERE
comment_poster_id!={int:visitor_id} AND comment_profile={int:visitor_id}',
array ('visitor_id' => $user_info['id'])
);

$commentscount = $smcFunc['db_num_rows']($query);

if (!$user_info['is_guest'] && ($context['user']['unread_messages'] > 0 || $commentscount > 0) && isset($context['menu_buttons']['pm']))
{
$context['menu_buttons']['pm']['alttitle'] = $context['menu_buttons']['pm']['title'] . ' [' . ($context['user']['unread_messages']+$commentscount) . ']';
$context['menu_buttons']['pm']['title'] .= ' [<strong>' . ($context['user']['unread_messages']+$commentscount) . '</strong>]';
if($context['user']['unread_messages'] != 0)
$context['menu_buttons']['pm']['sub_buttons']['pm_read']['title'] .= ' [<strong>' . $context['user']['unread_messages'] . '</strong>]';
$context['menu_buttons']['pm']['sub_buttons']['profile_read']['title'] .= ' [<strong>' . $commentscount . '</strong>]';
}


:::::::::::::::::::::::::::::::

Replace:

'pm' => array(
'title' => $txt['pm_short'],
'href' => $scripturl . '?action=pm',
'show' => $context['allow_pm'],
'sub_buttons' => array(
'pm_read' => array(
'title' => $txt['pm_menu_read'],
'href' => $scripturl . '?action=pm',
'show' => allowedTo('pm_read'),
),
'pm_send' => array(
'title' => $txt['pm_menu_send'],
'href' => $scripturl . '?action=pm;sa=send',
'show' => allowedTo('pm_send'),
'is_last' => true,
),
),
),


---------------------------


'pm' => array(
'title' => $txt['pm_short'],
'href' => $scripturl . '?action=pm',
'show' => $context['allow_pm'],
'sub_buttons' => array(
'pm_read' => array(
'title' => $txt['pm_menu_read'],
'href' => $scripturl . '?action=pm',
'show' => allowedTo('pm_read'),
),
'pm_send' => array(
'title' => $txt['pm_menu_send'],
'href' => $scripturl . '?action=pm;sa=send',
'show' => allowedTo('pm_send'),
),
'profile_read' => array(
'title' => $txt['profile_read'],
'href' => $scripturl . '?action=profile',
'show' => true,
'is_last' => true,
),
),
),


index.german.php:

Add:


$txt['profile_read'] = 'Profilkommentare';


index.english.php:

Add:


$txt['profile_read'] = 'Read your Comments';


The positive of the new profile_visits is, you can use it for a box on the Profile which is like the Who visited my Profile in vBulletin!

Matthew K.

Very nice! A suggestion would be to use $smcFunc['db_insert'] rather than $smcFunc['db_query'].

trabacho

Quote from: Labradoodle-360 on June 12, 2012, 12:48:24 PM
Very nice! A suggestion would be to use $smcFunc['db_insert'] rather than $smcFunc['db_query'].

Thanks, thats was my first look at the Code of SMF, I should have reviewed the docs -.-
I will edit it...

Matthew K.


trabacho

One addition to mod owner, if you release an update please integrate this little change too.

ProfileComments.template.php
Replace:

<h2>', $c['poster_name'], '</h2>
<img class="comment_avatar" src="', $c['poster_avatar'], '" alt="" />


With:

<h2><a href="'.$scripturl.'?action=profile;u='.$c['poster_id'].'">', $c['poster_name'], '</a></h2>
<a href="'.$scripturl.'?action=profile;u='.$c['poster_id'].'"><img class="comment_avatar" src="', $c['poster_avatar'], '" alt="" /></a>



It's  just much more beatiful, if you can answere on the opponent Profile by just clicking his Username  or Avatar on your Profile ;)

The Craw

Wow, I'm very glad to see that this mod is still attracting attention. And thank you for contributing, trabacho!

trabacho

Surely it does!

Out of one simple reason. The Profile Comments are builtin in vBulletins Systems, but I don't want to use this crappy code for my Boards...
So as the Profile Comments are one part of the Community that should not be underestimated, it should attract attention! As it does make a major part of the overall ambience. So thank you for your great work The Craw

The Craw

Quote from: trabacho on June 15, 2012, 12:44:32 PM
Surely it does!

Out of one simple reason. The Profile Comments are builtin in vBulletins Systems, but I don't want to use this crappy code for my Boards...
So as the Profile Comments are one part of the Community that should not be underestimated, it should attract attention! As it does make a major part of the overall ambience. So thank you for your great work The Craw

You're welcome. :) I'm glad you're getting some good use out of this mod.

Dylert

I have tried to install this mod, but it will not work for me. The installation went well and I got no errors. When I go into a profile page I got this error:

Unknown column 'comment_id' in 'field list'
Fil: /customers/d/7/7/hellasforum.net/httpd.www/Sources/Profile-View.php
Line: 256

I have tried to uninstall the mod and installed it again, but I get the same error in the profile pages.
What can I do to make it work?

live627

When you uninstall it again, check the box marked 'Remove all data...' and that will clear its db tables. My guess is that you had another comment mod earlier that you dumped.

Ashelia

Installed this manually (due to issues with the package manager) and it seemingly went fine, but whenever I go to profile pages I too get this error:

QuoteUnknown column 'comment_id' in 'field list'
Fil: ************/Sources/Profile-View.php
Line: 256

I did attempt to run the database_install.php via my browser, but nothing in particular seems to happen.

Any tips?

The Craw

Was the database_install.php file in the root directory of your forum when you ran it? If so, did it just output a blank page?

Matthew K.

There are almost positively conditions in the install file that kill the script with a die message if it's in the wrong directory and can't get SSI.php.

Try running the script again or run the query via phpMyAdmin.

Ashelia

Quote from: The Craw on June 24, 2012, 03:31:20 AM
Was the database_install.php file in the root directory of your forum when you ran it? If so, did it just output a blank page?

Yep and yep!

The Craw

Did you have another profile comments mod installed? It's sounding like maybe there is another table with the name "profile_comments" in your database.

Ashelia

My memory is a bit fuzzy, but it is definitely possible that I've attempted to install something similar before.

How can I fix this?

The Craw

You'll have to check if that table exists in your database, and if it does, drop it and run the install file again. Although you might check the contents of that table and make sure it's not important. Backing up would be smart, too. :)

Advertisement: