Advertisement:

Navigation

Readme

Current Version: Beta2

As the title suggests, Ajax Profile Comments makes it possible for users to leave comments on their profiles. It uses a nice sliding interface that doesn't require page loads for things like posting new comments, modifying, or deleting.

This mod uses a few icons from the LED icon set.

License:
I release this mod and all the code in it to anyone who wants to use it in hopes that it may be found useful. Attribution is not necessary, nor do you need to provide a link back to my website. You are free to use this mod for any purpose, including commercial works, redistribution and derivative works. The only contingency is that the link back to the LED icon set must remain, as this mod uses two icons from that set. Namely comment_delete.png and comment_edit.png. Both images are found in the root directory of the package. All other images are made by myself and can be used freely. Lastly, this mod comes with no guarantees that it will work well on all servers and configurations, and I will not be held responsible for damages, expenses or problems that may have been caused by the mod's use.

File Edits

./index.php

Find: [Select]

elseif (empty($_REQUEST['action']))
Replace With: [Select]

elseif (empty($_REQUEST['action']) && empty($_GET['profile_ajax']))

Find: [Select]

// Here's the monstrous $_REQUEST['action'] array - $_REQUEST['action'] => array($file, $function).
Add Before: [Select]

// <ChineseModifications mod="Ajax Profile Comments">
if (!empty($_GET['profile_ajax']))
{
require_once($sourcedir . '/ClassProfileComments.php');
}
// </ChineseModifications>

./Themes/default/languages/Profile.english.php

Find (at the end of the file): [Select]
?>
Add Before: [Select]

// <ChineseModifications mod="Ajax Profile Comments">
$txt['pc_title'] = 'Profile Comments';
$txt['pc_reply'] = 'Post Comment';
$txt['pc_submit'] = 'Submit';
$txt['pc_cancel'] = 'Cancel';
$txt['pc_show_more'] = 'Show More';
// </ChineseModifications>

./Themes/default/languages/ManagePermissions.english.php

Find (at the end of the file): [Select]
?>
Add Before: [Select]

$txt['permissiongroup_profile_comments'] = 'Ajax Profile Comments';
$txt['permissiongroup_simple_profile_comments'] = ' Ajax Profile Comments';
$txt['permissionname_pc_can_comment'] = 'Allowed to post new comments:';
$txt['permissionname_pc_can_modify'] = 'Allowed to modify:';
$txt['permissionname_pc_can_delete'] = 'Allowed to delete:';
$txt['permissionname_pc_can_modify_own'] = 'Own Comment';
$txt['permissionname_pc_can_modify_any'] = 'Any Comment';
$txt['permissionname_pc_can_delete_own'] = 'Own Comment';
$txt['permissionname_pc_can_delete_any'] = 'Any Comment';

./Sources/Profile-View.php

Find: [Select]

loadCustomFields($memID);
Add After: [Select]

// <ChineseModifications mod="Ajax Profile Comments">
loadTemplate('ProfileComments');

global $memberContext;
$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)
);

while ($row = $smcFunc['db_fetch_assoc']($q))
{
if (!isset($memberContext[$row['comment_poster_id']]))
{
loadMemberData(array($row['comment_poster_id']), false, 'normal');
loadMemberContext($row['comment_poster_id']);
}
$context['profile_comments'][] = array(
'id' => $row['comment_id'],
'poster_id' => $row['comment_poster_id'],
'poster_name' => $row['comment_poster'],
'poster_avatar' => !empty($memberContext[$row['comment_poster_id']]['avatar']['href']) ? $memberContext[$row['comment_poster_id']]['avatar']['href'] : 'http://www.gravatar.com/avatar/' . md5(strtolower($context['user']['email'])) . '?r=G&d=mm&s=85',
'title' => $row['comment_title'],
'body' => parse_bbc($row['comment_body']),
'can_modify' => allowedTo('pc_can_modify_any') || (($context['user']['id'] == $row['comment_poster_id']) && (allowedTo('pc_can_modify_own'))) ? true : false,
'can_delete' => allowedTo('pc_can_delete_any') || (($context['user']['id'] == $row['comment_poster_id']) && (allowedTo('pc_can_delete_own'))) ? true : false
);
}

$counting_query = $smcFunc['db_query']('', '
SELECT comment_id
FROM {db_prefix}profile_comments
WHERE comment_profile= {int:profile_id}',
array ('profile_id' => $memID)
);

$context['total_comments'] = $smcFunc['db_num_rows']($counting_query);
$context['most_recent'] = isset($context['profile_comments'][0]['id']) ? $context['profile_comments'][0]['id'] : 0;
$context['oldest_shown'] = !empty($context['profile_comments']) ? end($context['profile_comments']) : '';
$context['profile_id'] = $memID;
// </ChineseModifications>

./Sources/ManagePermissions.php

Find: [Select]

'simple' => array(
Add After: [Select]

'profile_comments',

Find: [Select]

'classic' => array(
Add After: [Select]

'profile_comments',

Find: [Select]

$permissionList = array(
'membergroup' => array(
Add After: [Select]

'pc_can_comment' => array(false, 'profile_comments', 'profile_comments'),
'pc_can_modify' => array(true, 'profile_comments', 'profile_comments'),
'pc_can_delete' => array(true, 'profile_comments', 'profile_comments'),

./Themes/default/Profile.template.php

Find: [Select]

echo '
<script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/profile.js"></script>';
Add After: [Select]

// <ChineseModifications mod="Ajax Profile Comments">
if (function_exists('template_include_javascript'))
template_include_javascript();
// </ChineseModifications>

Find: [Select]

// Show the users signature.
if ($context['signature_enabled'] && !empty($context['member']['signature']))
echo '
<div class="signature">
<h5>', $txt['signature'], ':</h5>
', $context['member']['signature'], '
</div>';

echo '
</div>
<span class="botslice"><span></span></span>
</div>
</div>
<div class="clear"></div>
</div>';
Replace With: [Select]

// Show the users signature.
if ($context['signature_enabled'] && !empty($context['member']['signature']))
echo '
<div class="signature">
<h5>', $txt['signature'], ':</h5>
', $context['member']['signature'], '
</div>';

echo '
</div>
<span class="botslice"><span></span></span>
</div>
</div>
<div class="clear"></div>';

// <ChineseModifications mod="Ajax Profile Comments">
if (function_exists('template_profile_comments'))
template_profile_comments();
// </ChineseModifications>

echo '
</div>';

./Themes/default/css/index.css

Find (at the end of the file): [Select]
?>
Add Before: [Select]

/* <ChineseModifications mod="Ajax Profile Comments"> */

.nodisplay_comment
{
display: none;
}

#comment_loader
{
display: none;
float: right;
margin: 6px 0 0 0;
}
#comment_success, #comment_error
{
float: right;
display: none;
margin: 6px 0 0 0;
}

#profile_comments
{
margin: 5px 0 0 0;
float: right;
width: 79.5%;
}
#main_admsection #profile_comments
{
width: 100%;
}
#form_container
{
display: none;
padding: 5px 0 0 0;
}
#show_reply_button
{
position: relative;
float: right;
padding: 6px;
margin: 3px;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
}
#show_reply_button img
{
position: relative;
top: 3px;
}

#input_title, .modify_title
{
display: block;
width: 98%;
margin: 2px auto;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
}
#input_body, .modify_body
{
display: block;
width: 98%;
height: 7em;
margin: 2px auto;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
}
#input_submit, #input_cancel, .modify_submit, .modify_cancel
{
display: block;
float: right;
padding: 6px;
margin: 5px;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
}
#show_more_button
{
position: relative;
float: right;
padding: 6px;
margin: 5px;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
}

.comment_container
{
margin: 5px 0 0 0;
}

.comment_user_info
{
width: 12em;
float: left;
text-align: center;
}
.comment_avatar
{
display: block;
margin: 6px auto 0 auto;
max-width: 55px;
max-height: 55px;
}

.comment_body
{
margin: 0 0 0 13em;
padding: 5px;
min-height: 80px;
-moz-border-radius: 8px;
-webkit-border-radius: 8px;
border-radius: 8px;
}
.comment_delete, .comment_modify
{
float: right;
margin: 0 2px;
}

/* </ChineseModifications> */

Code

database_install.php

This file should be able to execute standalone.

File Operations

Move the included file "ClassProfileComments.php" to "./Sources".
Move the included file "ProfileComments.template.php" to "./Themes/default".
Move the included file "profile_comments.js" to "./Themes/default/scripts".
Move the included file "comment_delete.png" to "./Themes/default/images".
Move the included file "comment_edit.png" to "./Themes/default/images".
Move the included file "comment_loader.gif" to "./Themes/default/images".
Move the included file "comment_success.png" to "./Themes/default/images".
Move the included file "comment_error.png" to "./Themes/default/images".