コード例 #1
0
function comments_show($ref, $bcollection_mode = false, $bRecursive = true, $level = 1)
{
    # ref 				= the reference of the resource, collection or the comment (if called from itself recursively)
    # bcollection_mode	= boolean flag, false(default) == show comments for resources, true == show comments for collection
    # bRecursive		= flag to indicate whether to recursively show comments, defaults to true, will be set to false if depth limit reached
    # level				= used for recursion for display indentation etc.
    global $username, $anonymous_login, $lang, $comments_max_characters, $comments_flat_view, $regex_email, $comments_show_anonymous_email_address;
    $anonymous_mode = empty($username) || $username == $anonymous_login;
    // show extra fields if commenting anonymously
    if ($comments_flat_view) {
        $bRecursive = false;
    }
    $bRecursive = $bRecursive && $level < $GLOBALS['comments_responses_max_level'];
    // set 'name' to either user.fullname, comment.fullname or default 'Anonymous'
    $sql = "select c.ref thisref, c.ref_parent, c.hide, c.created, c.body, c.website_url, c.email, u.username, u.ref, parent.created 'responseToDateTime', " . "IFNULL(IFNULL(c.fullname, u.fullname), '" . $lang['comments_anonymous-user'] . "') 'name' ," . "IFNULL(IFNULL(parent.fullname, uparent.fullname), '" . $lang['comments_anonymous-user'] . "') 'responseToName' " . "from comment c left join (user u) on (c.user_ref = u.ref) left join (comment parent) on (c.ref_parent = parent.ref) left join (user uparent) on (parent.user_ref = uparent.ref) ";
    $collection_ref = $bcollection_mode ? $ref : "";
    $resource_ref = $bcollection_mode ? "" : $ref;
    $collection_mode = $bcollection_mode ? "collection_mode=true" : "";
    if ($level == 1) {
        // pass this JS function the "this" from the submit button in a form to post it via AJAX call, then refresh the "comments_container"
        echo <<<EOT

\t\t<script type="text/javascript">
\t\t
\t\t\tvar regexEmail = new RegExp ("{$regex_email}");
\t\t
\t\t\tfunction validateAnonymousComment(obj) {\t\t\t\t\t\t\t
\t\t\t\treturn (
\t\t\t\t\tregexEmail.test (String(obj.email.value).trim()) &&
\t\t\t\t\tString(obj.fullname.value).trim() != "" &&
\t\t\t\t\tvalidateComment(obj)
\t\t\t\t)\t\t\t\t
\t\t\t}
\t\t\t
\t\t\tfunction validateComment(obj) {
\t\t\t\treturn (String(obj.body.value).trim() != "");
\t\t\t}
\t\t\t
\t\t\tfunction validateAnonymousFlag(obj) {
\t\t\t\treturn (
\t\t\t\t\tregexEmail.test (String(obj.email.value).trim()) &&
\t\t\t\t\tString(obj.fullname.value).trim() != "" &&
\t\t\t\t\tvalidateFlag(obj)
\t\t\t\t)
\t\t\t}
\t\t\t
\t\t\tfunction validateFlag(obj) {
\t\t\t\treturn (String(obj.comment_flag_reason.value).trim() != "");\t\t\t\t
\t\t\t}
\t\t
\t\t\tfunction submitForm(obj) {\t\t\t\t
\t\t\t\tjQuery.post(
\t\t\t\t\t'ajax/comments_handler.php?ref={$ref}&collection_mode={$collection_mode}',
\t\t\t\t\tjQuery(obj).serialize(),
\t\t\t\t\tfunction(data)
\t\t\t\t\t{
\t\t\t\t\tjQuery('#comments_container').replaceWith(data);
\t\t\t\t\t}
\t\t\t\t);
\t\t\t}
\t\t</script>\t\t
\t\t
\t\t<div id="comments_container">\t\t\t\t
\t\t<div id="comment_form">
\t\t\t<form class="comment_form" action="javascript:void(0);" method="">
EOT;
        hook("beforecommentbody");
        echo <<<EOT
\t\t\t\t<input id="comment_form_collection_ref" type="hidden" name="collection_ref" value="{$collection_ref}"></input>
\t\t\t\t<input id="comment_form_resource_ref" type="hidden" name="resource_ref" value="{$resource_ref}"></input>\t\t\t\t
\t\t\t\t<textarea class="CommentFormBody" id="comment_form_body" name="body" maxlength="{$comments_max_characters}" placeholder="{$lang['comments_body-placeholder']}"></textarea>
EOT;
        if ($anonymous_mode) {
            echo <<<EOT
\t\t\t\t<br />
\t\t\t\t<input class="CommentFormFullname" id="comment_form_fullname" type="text" name="fullname" placeholder="{$lang['comments_fullname-placeholder']}"></input>
\t\t\t\t<input class="CommentFormEmail" id="comment_form_email" type="text" name="email" placeholder="{$lang['comments_email-placeholder']}"></input>
\t\t\t\t<input class="CommentFormWebsiteURL" id="comment_form_website_url" type="text" name="website_url" placeholder="{$lang['comments_website-url-placeholder']}"></input>
\t\t\t\t
EOT;
        }
        $validateFunction = $anonymous_mode ? "if (validateAnonymousComment(this.parentNode))" : "if (validateComment(this.parentNode))";
        echo <<<EOT
\t\t\t\t<br />\t\t\t\t
\t\t\t\t<input class="CommentFormSubmit" type="submit" value="{$lang['comments_submit-button-label']}" onClick="{$validateFunction} { submitForm(this.parentNode) } else { alert ('{$lang['comments_validation-fields-failed']}'); } ;"></input>
\t\t\t</form>\t
\t\t</div> \t<!-- end of comment_form -->\t
\t\t
EOT;
        $sql .= $bcollection_mode ? "where c.collection_ref={$ref}" : "where c.resource_ref={$ref}";
        // first level will look for either collection or resource comments
        if (!$comments_flat_view) {
            $sql .= " and c.ref_parent is null";
        }
    } else {
        $sql .= "where c.ref_parent={$ref}";
        // look for child comments, regardless of what type of comment
    }
    $sql .= " order by c.created desc";
    $found_comments = sql_query($sql);
    foreach ($found_comments as $comment) {
        $thisRef = $comment['thisref'];
        echo "<div class='CommentEntry' id='comment{$thisRef}' style='margin-left: " . ($level - 1) * 50 . "px;'>";
        // indent for levels - this will always be zero if config $comments_flat_view=true
        # ----- Information line
        hook("beforecommentinfo", "all", array("ref" => $comment["ref"]));
        echo "<div class='CommentEntryInfoContainer'>";
        echo "<div class='CommentEntryInfo'>";
        echo "<div class='CommentEntryInfoCommenter'>";
        if (empty($comment['name'])) {
            $comment['name'] = $comment['username'];
        }
        if (!hook("commentername", "all", array("ref" => $comment["ref"]))) {
            echo "<div class='CommentEntryInfoCommenterName'>" . htmlspecialchars($comment['name']) . "</div>";
        }
        if ($comments_show_anonymous_email_address && !empty($comment['email'])) {
            echo "<div class='CommentEntryInfoCommenterEmail'>" . htmlspecialchars($comment['email']) . "</div>";
        }
        if (!empty($comment['website_url'])) {
            echo "<div class='CommentEntryInfoCommenterWebsite'>" . htmlspecialchars($comment['website_url']) . "</div>";
        }
        echo "</div>";
        echo "<div class='CommentEntryInfoDetails'>" . strftime('%a', strtotime($comment["created"])) . " " . nicedate($comment["created"], true) . " ";
        if ($comment['responseToDateTime'] != "") {
            $responseToName = htmlspecialchars($comment['responseToName']);
            $responseToDateTime = strftime('%a', strtotime($comment["responseToDateTime"])) . " " . nicedate($comment['responseToDateTime'], true);
            $jumpAnchorID = "comment" . $comment['ref_parent'];
            echo $lang['comments_in-response-to'] . "<br /><a class='.smoothscroll' rel='' href='#{$jumpAnchorID}'>{$responseToName} " . $lang['comments_in-response-to-on'] . " {$responseToDateTime}</a>";
        }
        echo "</div>";
        // end of CommentEntryInfoDetails
        echo "<div class='CommentEntryInfoFlag'>";
        if (getval("comment{$thisRef}flagged", "") || $comment['hide']) {
            echo "<div class='CommentFlagged'>{$lang['comments_flag-has-been-flagged']}</div>";
        } else {
            echo <<<EOT
\t\t\t\t\t<div class="CommentFlag">
\t\t\t\t\t\t<a href="javascript:void(0)" onclick="jQuery('#CommentFlagContainer{$thisRef}').toggle('fast');">{$lang['comments_flag-this-comment']}</a>
\t\t\t\t\t</div>
EOT;
        }
        if (checkPerm("o")) {
            echo <<<EOT
\t\t\t\t
\t\t\t\t<form class="comment_removal_form" action="javascript:void(0);" method="">
\t\t\t\t\t<input type="hidden" name="comment_to_hide" value="{$thisRef}"></input>\t\t\t\t\t
\t\t\t\t\t<a href="javascript:void(0)" onclick="if (confirm ('{$lang['comments_hide-comment-text-confirm']}')) submitForm(this.parentNode);">&gt; {$lang['comments_hide-comment-text-link']}</a>\t\t\t\t\t
\t\t\t\t</form>
\t\t\t\t
EOT;
        }
        echo "</div>";
        // end of CommentEntryInfoFlag
        echo "</div>";
        // end of CommentEntryInfoLine
        echo "</div>";
        // end CommentEntryInfoContainer
        echo "<div class='CommentBody'>";
        if ($comment['hide']) {
            if (text("comments_removal_message") != "") {
                echo text("comments_removal_message");
            } else {
                echo $lang["hidden"];
            }
        } else {
            echo htmlspecialchars($comment['body']);
        }
        echo "</div>";
        # ----- Form area
        $validateFunction = $anonymous_mode ? "if (validateAnonymousFlag(this.parentNode))" : "if (validateFlag(this.parentNode))";
        if (!getval("comment{$thisRef}flagged", "")) {
            echo <<<EOT
\t\t\t\t\t
\t\t\t\t\t<div id="CommentFlagContainer{$thisRef}" style="display: none;">
\t\t\t\t\t\t<form class="comment_form" action="javascript:void(0);" method="">
\t\t\t\t\t\t\t<input type="hidden" name="comment_flag_ref" value="{$thisRef}"></input>\t\t\t\t\t\t\t\t\t\t\t\t\t\t
\t\t\t\t\t\t\t<input type="hidden" name="comment_flag_url" value=""></input>\t\t\t\t\t\t\t\t\t\t\t\t\t\t
\t\t\t\t\t\t\t\t\t\t\t\t\t
EOT;
            hook("beforecommentflagreason");
            echo <<<EOT
\t\t\t\t    <textarea class="CommentFlagReason" maxlength="{$comments_max_characters}" name="comment_flag_reason" placeholder="{$lang['comments_flag-reason-placeholder']}"></textarea><br />\t
EOT;
            if ($anonymous_mode) {
                echo <<<EOT
\t\t\t\t\t\t\t
\t\t\t\t\t\t\t<input class="CommentFlagFullname" id="comment_flag_fullname" type="text" name="fullname" placeholder="{$lang['comments_fullname-placeholder']}"></input>
\t\t\t\t\t\t\t<input class="CommentFlagEmail" id="comment_flag_email" type="text" name="email" placeholder="{$lang['comments_email-placeholder']}"></input><br />\t\t\t\t\t\t\t

EOT;
            }
            echo <<<EOT
\t\t\t\t\t\t\t<input class="CommentFlagSubmit" type="submit" value="{$lang['comments_submit-button-label']}" onClick="comment_flag_url.value=document.URL; {$validateFunction} { submitForm(this.parentNode); } else { alert ('{$lang['comments_validation-fields-failed']}') }"></input>
\t\t\t\t\t\t</form>
\t\t\t\t\t</div>\t\t\t\t
EOT;
        }
        $respond_div_id = "comment_respond_" . $thisRef;
        echo "<div id='{$respond_div_id}' class='CommentRespond'>";
        // start respond div
        echo "<a href='javascript:void(0)' onClick='\r\n\t\t\t\tjQuery(\"#{$respond_div_id}\").replaceWith(jQuery(\"#comment_form\").clone().attr(\"id\",\"{$respond_div_id}\")); \r\n\t\t\t\tjQuery(\"<input>\").attr({type: \"hidden\", name: \"ref_parent\", value: \"{$thisRef}\"}).appendTo(\"#{$respond_div_id} .comment_form\");\t\t\t\t\r\n\t\t\t'>&gt; " . $lang['comments_respond-to-this-comment'] . "</a>";
        echo "</div>";
        // end respond
        echo "</div>";
        // end of CommentEntry
        if ($bRecursive) {
            comments_show($thisRef, $bcollection_mode, true, $level + 1);
        }
    }
    if ($level == 1) {
        echo "</div>";
    }
    // end of comments_container
}
コード例 #2
0
#
# $Id: comments.php,v 1.1 2003/11/21 12:55:58 helix Exp $
#
######################################################################
require 'include/prepend.php3';
page_open(array('sess' => 'SourceAgency_Session'));
if (isset($auth) && !empty($auth->auth['perm'])) {
    page_close();
    page_open(array('sess' => 'SourceAgency_Session', 'auth' => 'SourceAgency_Auth', 'perm' => 'SourceAgency_Perm'));
}
require 'include/header.inc';
require 'include/commentslib.inc';
$bx = new box('100%', $th_box_frame_color, $th_box_frame_width, $th_box_title_bgcolor, $th_box_title_font_color, $th_box_title_align, $th_box_body_bgcolor, $th_box_body_font_color, $th_box_body_align);
start_content();
$page = 'comments';
if (check_permission($proid, $page)) {
    top_bar($proid, $page);
    if (is_not_set_or_empty($type)) {
        $type = 'General';
    }
    if (is_not_set_or_empty($ref)) {
        $ref = '';
    }
    htmlp_image('ic/c.png', 0, 60, 53, 'Summary');
    print $t->translate('General comments can be posted') . ' ' . $t->translate('by registered users of the system') . ".\n<br><p>\n";
    comments_show($proid, $type, $number, $cmt_id, $ref);
    lib_comment_it($proid, 'General', '0', '0', '', $t->translate('General Comments'));
}
end_content();
require 'include/footer.inc';
@page_close();
コード例 #3
0
<?php

include "../../include/db.php";
include "../../include/general.php";
include "../../include/authenticate.php";
include "../../include/comment_functions.php";
if ($_SERVER['REQUEST_METHOD'] == "POST") {
    if (!empty($username)) {
        comments_submit();
    }
}
$ref = !empty($_GET['ref']) ? $_GET['ref'] : "";
$collection_mode = !empty($_GET['collection_mode']);
comments_show($ref, $collection_mode);
コード例 #4
0
<?php

get_header();
?>

<div id='single'>

<?php 
$result = request_select('editpost', $page['id']);
if ($result) {
    foreach ($result as $rows) {
        echo $rows->post_title . "<br>";
        echo $rows->post_content . "<br>";
    }
}
// end foreach()
?>

<h3> comments : </h3>

<?php 
comments_show($page);
?>

</div>

<?php 
get_sidebar();
get_footer();