assign('REPLYTO_PATH', REPLYTO_PATH); $location = null; // comment form has different id if ( (isset($_GET['action']) AND $_GET['action'] == 'edit_comment') OR (isset($page['body_id']) AND $page['body_id'] == 'theCommentsPage') ) { $template->assign('replyto_form_name', 'editComment'); } else { $template->assign('replyto_form_name', 'addComment'); } /* COMMENTS page */ if (script_basename() == 'comments') { if ( !is_a_guest() OR $conf['comments_forall'] ) { $comments = &$template->get_template_vars('comments'); if (!count($comments)) return; // generates urls to picture or albums with necessary url params foreach ($comments as $tpl_var) { $replyto_links[ $tpl_var['ID'] ] = get_absolute_root_url().$tpl_var['U_PICTURE'].'&rt='.$tpl_var['ID'].'&rta='.$tpl_var['AUTHOR'].'#commentform'; } $template->assign('replyto_links', $replyto_links); $template->set_prefilter('comments', 'replyto_add_link_comments_prefilter'); } } /* PICTURE page */ else if (script_basename() == 'picture') { $location = 'picture'; add_event_handler('user_comment_insertion', 'replyto_parse_picture_mail'); if ( !is_a_guest() OR $conf['comments_forall'] ) { $template->set_prefilter('picture', 'replyto_add_link_prefilter'); } } /* ALBUM page */ else if ( script_basename() == 'index' AND isset($page['section']) AND isset($pwg_loaded_plugins['Comments_on_Albums']) AND $page['section'] == 'categories' AND isset($page['category']) ) { $location = 'album'; add_event_handler('user_comment_insertion', 'replyto_parse_album_mail'); if ( !is_a_guest() OR $conf['comments_forall'] ) { $template->set_prefilter('comments_on_albums', 'replyto_add_link_prefilter'); } } /* we come from comments.php page */ if ( !empty($_GET['rt']) and !empty($_GET['rta']) ) { if ($location == 'picture') { $template->set_prefilter('picture', 'replyto_fillform_prefilter'); } else { $template->set_prefilter('comments_on_albums', 'replyto_fillform_prefilter'); } } } /** * add reply tag from values given in url */ function replyto_fillform_prefilter($content, &$smarty) { $search = '
'; $replace[0] = ' {html_head} {/html_head}' .$search[0]; // button $search[1] = '{$comment.DATE}'; $replace[1] = $search[1].'{\'Reply\'|@translate}'; return str_replace($search, $replace, $content); } /** * reply buttons on picture.php and index.php pages */ function replyto_add_link_prefilter($content, &$smarty) { // script & style $search[0] = '
'; $replace[0] = ' {combine_script id=\'insertAtCaret\' require=\'jquery\' path=$REPLYTO_PATH|@cat:\'insertAtCaret.js\'} {footer_script require=\'insertAtCaret\'} function replyTo(commentID, author) {ldelim} jQuery("#{$replyto_form_name} textarea").insertAtCaret("[reply=" + commentID + "]" + author + "[/reply] "); } {/footer_script} {html_head} {/html_head}' .$search[0]; // button $search[1] = '{$comment.DATE}'; $replace[1] = $search[1].'{\'Reply\'|@translate}'; // anchors $search[2] = '- '.$search[2];
$search[3] = '
';
$replace[3] = $search[3].'';
return str_replace($search, $replace, $content);
}
/**
* Replace BBcode tag by a link with absolute url
*/
function replyto_parse($comment, $in_album = false)
{
if (preg_match(REPLYTO_REGEX, $comment, $matches))
{
/* try to parse a ReplyTo tag link for picture page */
if (!$in_album)
{
// picture informations
$query = '
SELECT
img.id,
img.file,
cat.category_id
FROM ' . IMAGES_TABLE . ' AS img
INNER JOIN ' . IMAGE_CATEGORY_TABLE . ' AS cat
ON cat.image_id = img.id
INNER JOIN ' . COMMENTS_TABLE . ' AS com
ON com.image_id = img.id
WHERE com.id = ' . $matches[1] . '
;';
$result = pwg_query($query);
// make sure the target comment exists
if (pwg_db_num_rows($result))
{
$image = pwg_db_fetch_assoc($result);
// retrieving category informations
$query = '
SELECT
id,
name,
permalink,
uppercats
FROM ' . CATEGORIES_TABLE . '
WHERE id = ' . $image['category_id'] . '
;';
$image['cat'] = pwg_db_fetch_assoc(pwg_query($query));
// link to the full size picture
$image['url'] = make_picture_url(array(
'category' => $image['cat'],
'image_id' => $image['id'],
'image_file' => $image['file'],
));
$replace = '@ $2 :';
}
else
{
$replace = '';
}
}
/* try to parse a ReplyTo tag link for an album */
else if ( $in_album == 'album')
{
// retrieving category informations
$query = '
SELECT
cat.id,
cat.name,
cat.permalink,
cat.uppercats
FROM ' . COA_TABLE . ' AS com
INNER JOIN ' . CATEGORIES_TABLE . ' AS cat
ON cat.id = com.category_id
WHERE com.id = ' . $matches[1] . '
;';
$result = pwg_query($query);
// make sure the target comment exists
if (pwg_db_num_rows($result))
{
$category = pwg_db_fetch_assoc($result);
// link to the album
$category['url'] = make_index_url(array(
'category' => $category,
));
$replace = '@ $2 :';
}
else
{
$replace = '';
}
}
return preg_replace(REPLYTO_REGEX, $replace, $comment);
}
else
{
return $comment;
}
}
/**
* Replace BBcode tag by a link in notification mails
*/
function replyto_parse_picture_mail($comment)
{
$comment['content'] = replyto_parse($comment['content']);
return $comment;
}
function replyto_parse_album_mail($comment)
{
$comment['content'] = replyto_parse($comment['content'], 'album');
return $comment;
}
?>